@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.js
CHANGED
|
@@ -350,12 +350,32 @@ 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
|
+
function ownTextNodes(el, view) {
|
|
354
|
+
const out = [];
|
|
355
|
+
const walker = el.ownerDocument.createTreeWalker(
|
|
356
|
+
el,
|
|
357
|
+
4
|
|
358
|
+
/* NodeFilter.SHOW_TEXT */
|
|
359
|
+
);
|
|
360
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
|
361
|
+
let offFlow = false;
|
|
362
|
+
for (let p = n.parentElement; p && p !== el; p = p.parentElement) {
|
|
363
|
+
const pcs = view.getComputedStyle(p);
|
|
364
|
+
if (pcs.position === "absolute" || pcs.position === "fixed" || pcs.display === "none") {
|
|
365
|
+
offFlow = true;
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (!offFlow) out.push(n);
|
|
370
|
+
}
|
|
371
|
+
return out;
|
|
372
|
+
}
|
|
353
373
|
function findPillViolation(el, maxWidth = PILL_MAX_WIDTH_PX) {
|
|
354
374
|
if (el.getAttribute("data-matrx-pill") === "off") return null;
|
|
355
|
-
const text = (el.textContent ?? "").trim();
|
|
356
|
-
if (!text) return null;
|
|
357
375
|
const view = el.ownerDocument.defaultView;
|
|
358
376
|
if (!view) return null;
|
|
377
|
+
const own = ownTextNodes(el, view);
|
|
378
|
+
if (!own.some((t) => (t.textContent ?? "").trim())) return null;
|
|
359
379
|
const rect = el.getBoundingClientRect();
|
|
360
380
|
if (rect.width === 0 || rect.height === 0) return null;
|
|
361
381
|
const cs = view.getComputedStyle(el);
|
|
@@ -363,17 +383,21 @@ function findPillViolation(el, maxWidth = PILL_MAX_WIDTH_PX) {
|
|
|
363
383
|
if (rect.width > maxWidth + 0.5) {
|
|
364
384
|
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
385
|
}
|
|
366
|
-
const lines = lineCount(el, cs, rect.height);
|
|
386
|
+
const lines = lineCount(el, own, cs, rect.height);
|
|
367
387
|
if (lines > 1) {
|
|
368
388
|
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
389
|
}
|
|
370
390
|
return null;
|
|
371
391
|
}
|
|
372
|
-
function lineCount(el, cs, height) {
|
|
392
|
+
function lineCount(el, own, cs, height) {
|
|
373
393
|
const range = el.ownerDocument.createRange?.();
|
|
374
394
|
if (range && typeof range.getClientRects === "function") {
|
|
375
|
-
|
|
376
|
-
const
|
|
395
|
+
const rects = [];
|
|
396
|
+
for (const node of own) {
|
|
397
|
+
if (!(node.textContent ?? "").trim()) continue;
|
|
398
|
+
range.selectNodeContents(node);
|
|
399
|
+
rects.push(...Array.from(range.getClientRects()).filter((r) => r.width > 0 && r.height > 0));
|
|
400
|
+
}
|
|
377
401
|
range.detach?.();
|
|
378
402
|
if (rects.length) {
|
|
379
403
|
const mids = [];
|