@visualli/core 0.2.17 → 0.2.18
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 +35 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +35 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/generated/geometry/container.ts +42 -13
package/dist/index.cjs
CHANGED
|
@@ -2696,23 +2696,49 @@ var PILL = {
|
|
|
2696
2696
|
maxGrow: 1.3
|
|
2697
2697
|
};
|
|
2698
2698
|
var PILL_CHROME = { w: 2 * PILL.padX + 2 * PILL.border, h: PILL.padTop + PILL.padBottom + 2 * PILL.border };
|
|
2699
|
+
function graphemes(text) {
|
|
2700
|
+
const out = [], joins = /^[\p{M}\u200d\ufe00-\ufe0f\u{1f3fb}-\u{1f3ff}\u{e0020}-\u{e007f}]$/u, flag = /^[\u{1f1e6}-\u{1f1ff}]$/u;
|
|
2701
|
+
for (const c of Array.from(text)) {
|
|
2702
|
+
const last = out.length - 1;
|
|
2703
|
+
if (last >= 0 && (joins.test(c) || out[last].endsWith("\u200D") || flag.test(c) && Array.from(out[last]).every((x) => flag.test(x)) && Array.from(out[last]).length % 2 === 1)) out[last] += c;
|
|
2704
|
+
else out.push(c);
|
|
2705
|
+
}
|
|
2706
|
+
return out;
|
|
2707
|
+
}
|
|
2699
2708
|
function pillLayout(name, measure, scale = 1) {
|
|
2700
2709
|
const px = PILL.fontPx * scale, room = PILL.maxWidth - PILL_CHROME.w, m = (s) => measure(s, px);
|
|
2701
|
-
const
|
|
2702
|
-
let
|
|
2703
|
-
for (const w of
|
|
2710
|
+
const rows = [];
|
|
2711
|
+
let cur = "";
|
|
2712
|
+
for (const w of name.split(/\s+/).filter(Boolean)) {
|
|
2713
|
+
if (m(w) > room) {
|
|
2714
|
+
if (cur) rows.push({ text: cur, mid: false });
|
|
2715
|
+
let part = "";
|
|
2716
|
+
for (const g of graphemes(w)) {
|
|
2717
|
+
if (part && m(part + g) > room) {
|
|
2718
|
+
rows.push({ text: part, mid: true });
|
|
2719
|
+
part = g;
|
|
2720
|
+
} else part += g;
|
|
2721
|
+
}
|
|
2722
|
+
cur = part;
|
|
2723
|
+
continue;
|
|
2724
|
+
}
|
|
2704
2725
|
const next = cur ? `${cur} ${w}` : w;
|
|
2705
2726
|
if (cur && m(next) > room) {
|
|
2706
|
-
|
|
2727
|
+
rows.push({ text: cur, mid: false });
|
|
2707
2728
|
cur = w;
|
|
2708
2729
|
} else cur = next;
|
|
2709
2730
|
}
|
|
2710
|
-
if (cur)
|
|
2731
|
+
if (cur) rows.push({ text: cur, mid: false });
|
|
2732
|
+
let lines = rows.map((r) => r.text);
|
|
2711
2733
|
if (!lines.length) lines = [""];
|
|
2712
|
-
if (
|
|
2713
|
-
let
|
|
2714
|
-
|
|
2715
|
-
|
|
2734
|
+
if (rows.length > PILL.maxLines) {
|
|
2735
|
+
let rest = "";
|
|
2736
|
+
rows.slice(PILL.maxLines - 1).forEach((r, i, a) => {
|
|
2737
|
+
rest += r.text + (i < a.length - 1 && !r.mid ? " " : "");
|
|
2738
|
+
});
|
|
2739
|
+
const gs = graphemes(rest);
|
|
2740
|
+
while (gs.length > 1 && m(gs.join("") + "\u2026") > room) gs.pop();
|
|
2741
|
+
lines = [...lines.slice(0, PILL.maxLines - 1), gs.join("").replace(/\s+$/, "") + "\u2026"];
|
|
2716
2742
|
}
|
|
2717
2743
|
const widest = Math.max(...lines.map(m));
|
|
2718
2744
|
return { lines, w: Math.min(PILL.maxWidth, widest + PILL_CHROME.w), h: lines.length * px * PILL.lineHeight + PILL_CHROME.h };
|