tsquare 0.12.4 → 0.13.1
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 +13 -0
- package/README.md +1 -1
- package/dist/anchors.d.ts +13 -3
- package/dist/browser/index.js +307 -85
- package/dist/chunks/{chunk-XWGHLFRX.js → chunk-HVGRKWIV.js} +1 -1
- package/dist/chunks/{chunk-BSE346UI.js → chunk-K3Y2E2QA.js} +158 -69
- package/dist/cli.js +1 -1
- package/dist/compile.d.ts +2 -0
- package/dist/flows.d.ts +31 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +166 -3
- package/dist/measure.d.ts +97 -0
- package/dist/playground/index.js +2 -2
- package/dist/render.d.ts +24 -0
- package/dist/tsquare.min.js +68 -68
- package/package.json +2 -2
package/dist/browser/index.js
CHANGED
|
@@ -7675,16 +7675,16 @@ function FDEF(state) {
|
|
|
7675
7675
|
state.ip = ip;
|
|
7676
7676
|
state.funcs[fn] = prog.slice(ipBegin + 1, ip);
|
|
7677
7677
|
}
|
|
7678
|
-
function MDAP(
|
|
7678
|
+
function MDAP(round2, state) {
|
|
7679
7679
|
var pi = state.stack.pop();
|
|
7680
7680
|
var p = state.z0[pi];
|
|
7681
7681
|
var fv = state.fv;
|
|
7682
7682
|
var pv = state.pv;
|
|
7683
7683
|
if (exports.DEBUG) {
|
|
7684
|
-
console.log(state.step, "MDAP[" +
|
|
7684
|
+
console.log(state.step, "MDAP[" + round2 + "]", pi);
|
|
7685
7685
|
}
|
|
7686
7686
|
var d2 = pv.distance(p, HPZero);
|
|
7687
|
-
if (
|
|
7687
|
+
if (round2) {
|
|
7688
7688
|
d2 = state.round(d2);
|
|
7689
7689
|
}
|
|
7690
7690
|
fv.setRelative(p, HPZero, d2, pv);
|
|
@@ -7887,7 +7887,7 @@ function RTDG(state) {
|
|
|
7887
7887
|
}
|
|
7888
7888
|
state.round = roundToDoubleGrid;
|
|
7889
7889
|
}
|
|
7890
|
-
function MIAP(
|
|
7890
|
+
function MIAP(round2, state) {
|
|
7891
7891
|
var stack = state.stack;
|
|
7892
7892
|
var n = stack.pop();
|
|
7893
7893
|
var pi = stack.pop();
|
|
@@ -7898,7 +7898,7 @@ function MIAP(round, state) {
|
|
|
7898
7898
|
if (exports.DEBUG) {
|
|
7899
7899
|
console.log(
|
|
7900
7900
|
state.step,
|
|
7901
|
-
"MIAP[" +
|
|
7901
|
+
"MIAP[" + round2 + "]",
|
|
7902
7902
|
n,
|
|
7903
7903
|
"(",
|
|
7904
7904
|
cv,
|
|
@@ -7907,7 +7907,7 @@ function MIAP(round, state) {
|
|
|
7907
7907
|
);
|
|
7908
7908
|
}
|
|
7909
7909
|
var d2 = pv.distance(p, HPZero);
|
|
7910
|
-
if (
|
|
7910
|
+
if (round2) {
|
|
7911
7911
|
if (Math.abs(d2 - cv) < state.cvCutIn) {
|
|
7912
7912
|
d2 = cv;
|
|
7913
7913
|
}
|
|
@@ -20659,6 +20659,7 @@ function markRoot(root, color) {
|
|
|
20659
20659
|
const kids = Children.toArray(node.props.children);
|
|
20660
20660
|
return cloneElement(node, {}, ...kids, /* @__PURE__ */ jsx3(Marker, { color }, "__marker"));
|
|
20661
20661
|
}
|
|
20662
|
+
var MARKS_ITSELF = /* @__PURE__ */ new Set(["Screen", "Modal", "Drawer", "Toast"]);
|
|
20662
20663
|
function withMarkers(reg) {
|
|
20663
20664
|
return Object.fromEntries(
|
|
20664
20665
|
Object.entries(reg).map(([name, C]) => [
|
|
@@ -20666,7 +20667,7 @@ function withMarkers(reg) {
|
|
|
20666
20667
|
(props) => {
|
|
20667
20668
|
const root = C(props);
|
|
20668
20669
|
const color = props.element?.props?.__mark;
|
|
20669
|
-
return color && name
|
|
20670
|
+
return color && !MARKS_ITSELF.has(name) ? markRoot(root, color) : root;
|
|
20670
20671
|
}
|
|
20671
20672
|
])
|
|
20672
20673
|
);
|
|
@@ -20840,19 +20841,22 @@ function Screen({ element, children }) {
|
|
|
20840
20841
|
s.chrome && s.device === "desktop" ? /* @__PURE__ */ jsx3(BrowserBar, {}) : null,
|
|
20841
20842
|
/* @__PURE__ */ jsxs(Box, { style: { position: "relative", flexGrow: 1, flexBasis: "0px", flexDirection: "column", overflow: "hidden" }, children: [
|
|
20842
20843
|
top,
|
|
20843
|
-
/* @__PURE__ */
|
|
20844
|
-
|
|
20845
|
-
|
|
20846
|
-
|
|
20847
|
-
|
|
20848
|
-
|
|
20849
|
-
|
|
20850
|
-
|
|
20851
|
-
|
|
20852
|
-
|
|
20853
|
-
|
|
20854
|
-
|
|
20855
|
-
|
|
20844
|
+
/* @__PURE__ */ jsxs(Box, { style: { flexGrow: 1, flexBasis: "0px", flexDirection: "column", overflow: "hidden" }, children: [
|
|
20845
|
+
/* @__PURE__ */ jsx3(
|
|
20846
|
+
Box,
|
|
20847
|
+
{
|
|
20848
|
+
style: {
|
|
20849
|
+
flexGrow: 1,
|
|
20850
|
+
flexShrink: 0,
|
|
20851
|
+
flexDirection: "column",
|
|
20852
|
+
padding: s.padding,
|
|
20853
|
+
gap: p.gap ?? 14
|
|
20854
|
+
},
|
|
20855
|
+
children: withDir(body, "column")
|
|
20856
|
+
}
|
|
20857
|
+
),
|
|
20858
|
+
p.__markBody ? /* @__PURE__ */ jsx3(Marker, { color: p.__markBody }) : null
|
|
20859
|
+
] }),
|
|
20856
20860
|
bottom,
|
|
20857
20861
|
overlays.map((o2) => isValidElement(o2) ? cloneElement(o2, { aboveTabBar: bottom.length > 0 }) : o2),
|
|
20858
20862
|
p.__mark ? /* @__PURE__ */ jsx3(Marker, { color: p.__mark }) : null
|
|
@@ -21118,9 +21122,9 @@ function Chart({ element, dir }) {
|
|
|
21118
21122
|
const kind = p.kind ?? "line";
|
|
21119
21123
|
const h2 = p.height ?? 180;
|
|
21120
21124
|
const w2 = p.width ?? (dir === "row" ? void 0 : "100%");
|
|
21121
|
-
const
|
|
21125
|
+
const round2 = kind === "pie" || kind === "donut";
|
|
21122
21126
|
const plot = (() => {
|
|
21123
|
-
if (
|
|
21127
|
+
if (round2) {
|
|
21124
21128
|
const slice = (from, to2, fill, k) => {
|
|
21125
21129
|
const a0 = from / 100 * 2 * Math.PI - Math.PI / 2, a1 = to2 / 100 * 2 * Math.PI - Math.PI / 2;
|
|
21126
21130
|
const x0 = 50 + 46 * Math.cos(a0), y0 = 50 + 46 * Math.sin(a0), x1 = 50 + 46 * Math.cos(a1), y1 = 50 + 46 * Math.sin(a1);
|
|
@@ -21150,7 +21154,7 @@ function Chart({ element, dir }) {
|
|
|
21150
21154
|
})();
|
|
21151
21155
|
return /* @__PURE__ */ jsxs(Box, { style: { flexDirection: "column", gap: 10, width: w2, height: h2, flexShrink: 0, ...dir === "row" ? { flexGrow: 1, flexBasis: "0px" } : {} }, children: [
|
|
21152
21156
|
p.title ? /* @__PURE__ */ jsx3(Box, { style: { fontSize: 13, fontWeight: 600, color: theme.text }, children: p.title }) : null,
|
|
21153
|
-
/* @__PURE__ */ jsx3(Box, { style: { flexGrow: 1, borderBottom:
|
|
21157
|
+
/* @__PURE__ */ jsx3(Box, { style: { flexGrow: 1, borderBottom: round2 ? void 0 : `1.5px solid ${theme.line}`, justifyContent: round2 ? "center" : void 0, alignItems: round2 ? "center" : void 0 }, children: plot })
|
|
21154
21158
|
] });
|
|
21155
21159
|
}
|
|
21156
21160
|
function AvatarCircle({ initials, size = 40 }) {
|
|
@@ -21315,7 +21319,7 @@ function Select({ element, dir }) {
|
|
|
21315
21319
|
] })
|
|
21316
21320
|
] });
|
|
21317
21321
|
}
|
|
21318
|
-
function CheckMark({ checked, round = false, c: c2 = GRAY }) {
|
|
21322
|
+
function CheckMark({ checked, round: round2 = false, c: c2 = GRAY }) {
|
|
21319
21323
|
return /* @__PURE__ */ jsx3(
|
|
21320
21324
|
Box,
|
|
21321
21325
|
{
|
|
@@ -21323,13 +21327,13 @@ function CheckMark({ checked, round = false, c: c2 = GRAY }) {
|
|
|
21323
21327
|
width: 20,
|
|
21324
21328
|
height: 20,
|
|
21325
21329
|
flexShrink: 0,
|
|
21326
|
-
borderRadius:
|
|
21327
|
-
border: `1.5px solid ${checked && !
|
|
21328
|
-
backgroundColor: checked && !
|
|
21330
|
+
borderRadius: round2 ? 10 : 5,
|
|
21331
|
+
border: `1.5px solid ${checked && !round2 ? c2.accent : theme.lineStrong}`,
|
|
21332
|
+
backgroundColor: checked && !round2 ? c2.accent : theme.paper,
|
|
21329
21333
|
alignItems: "center",
|
|
21330
21334
|
justifyContent: "center"
|
|
21331
21335
|
},
|
|
21332
|
-
children: checked ?
|
|
21336
|
+
children: checked ? round2 ? /* @__PURE__ */ jsx3(Box, { style: { width: 10, height: 10, borderRadius: 5, backgroundColor: c2.accent } }) : /* @__PURE__ */ jsx3(IconGlyph, { name: "check", size: 14, color: c2.onAccent, strokeWidth: 3 }) : null
|
|
21333
21337
|
}
|
|
21334
21338
|
);
|
|
21335
21339
|
}
|
|
@@ -21469,7 +21473,7 @@ function Calendar({ element, dir, aligned, colors: c2 = GRAY }) {
|
|
|
21469
21473
|
/* @__PURE__ */ jsx3(Box, { children: ["S", "M", "T", "W", "T", "F", "S"].map((d2, i2) => /* @__PURE__ */ jsx3(Box, { style: { width: CELL, justifyContent: "center", fontSize: 12, color: theme.muted }, children: d2 }, i2)) }),
|
|
21470
21474
|
weeks.map((week, w2) => /* @__PURE__ */ jsx3(Box, { children: week.map((d2, i2) => {
|
|
21471
21475
|
const end = d2 != null && (d2 === from || d2 === to2) && from > 0;
|
|
21472
|
-
const
|
|
21476
|
+
const inside2 = d2 != null && from > 0 && d2 > from && d2 < to2;
|
|
21473
21477
|
const band = d2 != null && from > 0 && to2 > from && d2 >= from && d2 <= to2;
|
|
21474
21478
|
return /* @__PURE__ */ jsxs(Box, { style: { width: CELL, height: CELL, alignItems: "center", justifyContent: "center", position: "relative" }, children: [
|
|
21475
21479
|
band ? /* @__PURE__ */ jsx3(Box, { style: { position: "absolute", top: 4, bottom: 4, left: d2 === from ? CELL / 2 : 0, right: d2 === to2 ? CELL / 2 : 0, backgroundColor: theme.fill } }) : null,
|
|
@@ -21485,7 +21489,7 @@ function Calendar({ element, dir, aligned, colors: c2 = GRAY }) {
|
|
|
21485
21489
|
justifyContent: "center",
|
|
21486
21490
|
fontSize: 14,
|
|
21487
21491
|
backgroundColor: end ? c2.accent : void 0,
|
|
21488
|
-
color: end ? c2.onAccent :
|
|
21492
|
+
color: end ? c2.onAccent : inside2 ? theme.ink : theme.text,
|
|
21489
21493
|
fontWeight: end ? 600 : 400
|
|
21490
21494
|
},
|
|
21491
21495
|
children: [
|
|
@@ -21707,7 +21711,8 @@ function Modal({ element, children }) {
|
|
|
21707
21711
|
},
|
|
21708
21712
|
children: [
|
|
21709
21713
|
p.title ? /* @__PURE__ */ jsx3(Box, { style: { fontSize: 18, fontWeight: 600 }, children: p.title }) : null,
|
|
21710
|
-
withDir(children, "column")
|
|
21714
|
+
withDir(children, "column"),
|
|
21715
|
+
p.__mark ? /* @__PURE__ */ jsx3(Marker, { color: p.__mark }) : null
|
|
21711
21716
|
]
|
|
21712
21717
|
}
|
|
21713
21718
|
) });
|
|
@@ -21742,7 +21747,8 @@ function Drawer({ element, children }) {
|
|
|
21742
21747
|
/* @__PURE__ */ jsx3(Box, { style: { fontSize: 18, fontWeight: 600 }, children: p.title }),
|
|
21743
21748
|
/* @__PURE__ */ jsx3(IconGlyph, { name: "x", size: 22, color: theme.muted })
|
|
21744
21749
|
] }) : null,
|
|
21745
|
-
withDir(children, "column")
|
|
21750
|
+
withDir(children, "column"),
|
|
21751
|
+
p.__mark ? /* @__PURE__ */ jsx3(Marker, { color: p.__mark }) : null
|
|
21746
21752
|
]
|
|
21747
21753
|
}
|
|
21748
21754
|
) });
|
|
@@ -21755,7 +21761,8 @@ function Toast({ element, aboveTabBar }) {
|
|
|
21755
21761
|
return /* @__PURE__ */ jsx3(Box, { style: { position: "absolute", left: 16, right: 16, justifyContent: side, ...top ? { top: 16 } : { bottom: aboveTabBar ? 92 : 24 } }, children: /* @__PURE__ */ jsxs(Box, { style: { alignItems: "center", gap: 12, padding: "12px 16px", borderRadius: 12, backgroundColor: theme.ink, color: theme.onPrimary, fontSize: 14, boxShadow: "0 6px 20px rgba(0,0,0,0.22)", maxWidth: 420 }, children: [
|
|
21756
21762
|
p.icon ? /* @__PURE__ */ jsx3(IconGlyph, { name: p.icon, size: 18, color: theme.onPrimary }) : null,
|
|
21757
21763
|
/* @__PURE__ */ jsx3(Box, { style: { flexShrink: 1 }, children: p.text ?? "" }),
|
|
21758
|
-
p.action ? /* @__PURE__ */ jsx3(Box, { style: { fontWeight: 700, marginLeft: 8, flexShrink: 0 }, children: p.action }) : null
|
|
21764
|
+
p.action ? /* @__PURE__ */ jsx3(Box, { style: { fontWeight: 700, marginLeft: 8, flexShrink: 0 }, children: p.action }) : null,
|
|
21765
|
+
p.__mark ? /* @__PURE__ */ jsx3(Marker, { color: p.__mark }) : null
|
|
21759
21766
|
] }) });
|
|
21760
21767
|
}
|
|
21761
21768
|
function Flow() {
|
|
@@ -21832,22 +21839,23 @@ function findAnchors(spec) {
|
|
|
21832
21839
|
return [...out, ...tips];
|
|
21833
21840
|
}
|
|
21834
21841
|
var MARK = (i2) => `#fe${(i2 >> 8).toString(16).padStart(2, "0")}${(i2 & 255).toString(16).padStart(2, "0")}`;
|
|
21835
|
-
function tagForMeasuring(spec, anchors) {
|
|
21842
|
+
function tagForMeasuring(spec, anchors, bodies = []) {
|
|
21836
21843
|
const tagged = structuredClone(spec);
|
|
21837
21844
|
const colors = /* @__PURE__ */ new Map();
|
|
21838
21845
|
let n = 1;
|
|
21839
|
-
const tag = (id,
|
|
21840
|
-
const key =
|
|
21846
|
+
const tag = (id, part) => {
|
|
21847
|
+
const key = part ? `${id}#${part}` : id;
|
|
21841
21848
|
if (colors.has(key)) return;
|
|
21842
21849
|
const color = MARK(n++);
|
|
21843
21850
|
colors.set(key, color);
|
|
21844
21851
|
const el2 = tagged.elements[id];
|
|
21845
|
-
el2.props = { ...el2.props ?? {}, [field ? "__markField" : "__mark"]: color };
|
|
21852
|
+
el2.props = { ...el2.props ?? {}, [part === "field" ? "__markField" : part === "body" ? "__markBody" : "__mark"]: color };
|
|
21846
21853
|
};
|
|
21847
21854
|
for (const a of anchors) {
|
|
21848
|
-
tag(a.screen,
|
|
21849
|
-
tag(a.id, a.field);
|
|
21855
|
+
tag(a.screen, "");
|
|
21856
|
+
tag(a.id, a.field ? "field" : "");
|
|
21850
21857
|
}
|
|
21858
|
+
for (const id of bodies) tag(id, "body");
|
|
21851
21859
|
return { tagged, colors };
|
|
21852
21860
|
}
|
|
21853
21861
|
function readMarkers(svg, colors) {
|
|
@@ -21871,6 +21879,7 @@ function place(anchor, size, screen, opts) {
|
|
|
21871
21879
|
return { x: x3 - screen.x, y: y - screen.y, bottom: screen.y + screen.h - (anchor.y - opts.gap), side };
|
|
21872
21880
|
}
|
|
21873
21881
|
var ROW = 36;
|
|
21882
|
+
var listHeight = (rows) => rows * (ROW - 4) + 2 * 4 + 2 * 1.5;
|
|
21874
21883
|
function ListCard({ items, width, selected, c: c2 }) {
|
|
21875
21884
|
return /* @__PURE__ */ jsx4("div", { style: { display: "flex", flexDirection: "column", width, padding: 4, backgroundColor: theme.paper, border: `1.5px solid ${theme.lineStrong}`, borderRadius: 8, boxShadow: "0 8px 24px rgba(0,0,0,0.18)" }, children: items.map((item, i2) => {
|
|
21876
21885
|
const on2 = selected != null && item.label === selected;
|
|
@@ -21906,35 +21915,57 @@ function tooltipSize(text2) {
|
|
|
21906
21915
|
const lines = Math.max(1, Math.ceil(text2.length * 7.4 / 216));
|
|
21907
21916
|
return { w: width, h: lines * 18 + 12 + 6 };
|
|
21908
21917
|
}
|
|
21918
|
+
function placeOverlay(spec, a, boxes) {
|
|
21919
|
+
const screen = boxes[a.screen];
|
|
21920
|
+
const anchor = boxes[a.field ? `${a.id}#field` : a.id];
|
|
21921
|
+
if (!screen || !anchor) return null;
|
|
21922
|
+
const p = propsOf(spec.elements, a.id);
|
|
21923
|
+
if (a.kind === "options") {
|
|
21924
|
+
const options = p.options?.length ? p.options : [p.value ?? "Option 1", "Option 2", "Option 3"];
|
|
21925
|
+
const size2 = { w: anchor.w, h: options.length * ROW + 8 };
|
|
21926
|
+
return { screen, anchor, size: size2, drawnH: listHeight(options.length), pos: place(anchor, size2, screen, { prefer: "below", align: "start", gap: 4 }), options };
|
|
21927
|
+
}
|
|
21928
|
+
if (a.kind === "menu") {
|
|
21929
|
+
const items = p.menu.map((i2) => typeof i2 === "string" ? { label: i2 } : i2);
|
|
21930
|
+
const width = a.end ? 200 : Math.max(180, anchor.w);
|
|
21931
|
+
const inRightHalf = anchor.x + anchor.w / 2 > screen.x + screen.w / 2;
|
|
21932
|
+
const size2 = { w: width, h: items.length * ROW + 8 };
|
|
21933
|
+
return { screen, anchor, size: size2, drawnH: listHeight(items.length), pos: place(anchor, size2, screen, { prefer: "below", align: a.end || inRightHalf ? "end" : "start", gap: a.end ? -6 : 4 }), items };
|
|
21934
|
+
}
|
|
21935
|
+
if (a.kind === "calendar") {
|
|
21936
|
+
const date = parseDate(p.value);
|
|
21937
|
+
const { start, days } = monthGrid(date?.month);
|
|
21938
|
+
const weeks = Math.ceil((start + days) / 7);
|
|
21939
|
+
const size2 = { w: 296, h: 92 + weeks * 38 };
|
|
21940
|
+
return { screen, anchor, size: size2, pos: place(anchor, size2, screen, { prefer: "below", align: "start", gap: 4 }), date };
|
|
21941
|
+
}
|
|
21942
|
+
const size = tooltipSize(p.tooltip);
|
|
21943
|
+
return { screen, anchor, size, pos: place(anchor, size, screen, { prefer: "above", align: "center", gap: 4 }) };
|
|
21944
|
+
}
|
|
21945
|
+
function overlayBoxes(spec, anchors, boxes) {
|
|
21946
|
+
return anchors.flatMap((a) => {
|
|
21947
|
+
const o2 = placeOverlay(spec, a, boxes);
|
|
21948
|
+
if (!o2) return [];
|
|
21949
|
+
const h2 = "drawnH" in o2 && o2.drawnH != null ? o2.drawnH : o2.size.h;
|
|
21950
|
+
const top = o2.screen.y + o2.pos.y + (o2.pos.side === "above" ? o2.size.h - h2 : 0);
|
|
21951
|
+
return [{ id: a.id, box: { x: o2.screen.x + o2.pos.x, y: top, w: o2.size.w, h: h2 } }];
|
|
21952
|
+
});
|
|
21953
|
+
}
|
|
21909
21954
|
function overlayLayer(spec, anchors, boxes, c2, Calendar2) {
|
|
21910
21955
|
const byScreen = /* @__PURE__ */ new Map();
|
|
21911
21956
|
for (const a of anchors) {
|
|
21912
|
-
const
|
|
21913
|
-
|
|
21914
|
-
|
|
21957
|
+
const o2 = placeOverlay(spec, a, boxes);
|
|
21958
|
+
if (!o2) continue;
|
|
21959
|
+
const { screen, anchor, size, pos } = o2;
|
|
21915
21960
|
const p = propsOf(spec.elements, a.id);
|
|
21916
21961
|
let node = null;
|
|
21917
|
-
let pos = null;
|
|
21918
21962
|
if (a.kind === "options") {
|
|
21919
|
-
|
|
21920
|
-
const size = { w: anchor.w, h: options.length * ROW + 8 };
|
|
21921
|
-
pos = place(anchor, size, screen, { prefer: "below", align: "start", gap: 4 });
|
|
21922
|
-
node = /* @__PURE__ */ jsx4(ListCard, { items: options.map((label) => ({ label })), width: size.w, selected: p.value, c: c2 });
|
|
21963
|
+
node = /* @__PURE__ */ jsx4(ListCard, { items: o2.options.map((label) => ({ label })), width: size.w, selected: p.value, c: c2 });
|
|
21923
21964
|
} else if (a.kind === "menu") {
|
|
21924
|
-
|
|
21925
|
-
const width = a.end ? 200 : Math.max(180, anchor.w);
|
|
21926
|
-
const inRightHalf = anchor.x + anchor.w / 2 > screen.x + screen.w / 2;
|
|
21927
|
-
pos = place(anchor, { w: width, h: items.length * ROW + 8 }, screen, { prefer: "below", align: a.end || inRightHalf ? "end" : "start", gap: a.end ? -6 : 4 });
|
|
21928
|
-
node = /* @__PURE__ */ jsx4(ListCard, { items, width, c: c2 });
|
|
21965
|
+
node = /* @__PURE__ */ jsx4(ListCard, { items: o2.items, width: size.w, c: c2 });
|
|
21929
21966
|
} else if (a.kind === "calendar") {
|
|
21930
|
-
|
|
21931
|
-
const { start, days } = monthGrid(date?.month);
|
|
21932
|
-
const weeks = Math.ceil((start + days) / 7);
|
|
21933
|
-
pos = place(anchor, { w: 296, h: 92 + weeks * 38 }, screen, { prefer: "below", align: "start", gap: 4 });
|
|
21934
|
-
node = /* @__PURE__ */ jsx4("div", { style: { display: "flex", boxShadow: "0 8px 24px rgba(0,0,0,0.18)", borderRadius: 12 }, children: Calendar2({ element: { type: "Calendar", props: { month: date?.month ?? "Month", selected: date?.day } }, colors: c2 }) });
|
|
21967
|
+
node = /* @__PURE__ */ jsx4("div", { style: { display: "flex", boxShadow: "0 8px 24px rgba(0,0,0,0.18)", borderRadius: 12 }, children: Calendar2({ element: { type: "Calendar", props: { month: o2.date?.month ?? "Month", selected: o2.date?.day } }, colors: c2 }) });
|
|
21935
21968
|
} else {
|
|
21936
|
-
const size = tooltipSize(p.tooltip);
|
|
21937
|
-
pos = place(anchor, size, screen, { prefer: "above", align: "center", gap: 4 });
|
|
21938
21969
|
node = /* @__PURE__ */ jsx4(Tooltip, { text: p.tooltip, side: pos.side, width: size.w, arrowX: anchor.x + anchor.w / 2 - (screen.x + pos.x) });
|
|
21939
21970
|
}
|
|
21940
21971
|
const list = byScreen.get(a.screen) ?? [];
|
|
@@ -22076,9 +22107,7 @@ function flowColor(color, palette) {
|
|
|
22076
22107
|
const s = String(color);
|
|
22077
22108
|
return ACCENTS[s] ?? s;
|
|
22078
22109
|
}
|
|
22079
|
-
function
|
|
22080
|
-
const shapes = [];
|
|
22081
|
-
const labels = [];
|
|
22110
|
+
function layoutFlows(spec, flows, screens, gap, palette) {
|
|
22082
22111
|
const placed = [];
|
|
22083
22112
|
const drawn = [];
|
|
22084
22113
|
const tips = flows.flatMap(({ ends: ends2 }) => {
|
|
@@ -22097,20 +22126,16 @@ function flowLayer(spec, flows, screens, gap, palette, size) {
|
|
|
22097
22126
|
return r;
|
|
22098
22127
|
});
|
|
22099
22128
|
const ends = routes.flatMap((r) => [r.points[0], r.points[r.points.length - 1]]);
|
|
22100
|
-
flows.
|
|
22129
|
+
return flows.map(({ key }, i2) => {
|
|
22101
22130
|
const r = routes[i2];
|
|
22102
22131
|
const p = spec.elements[key].props ?? {};
|
|
22103
|
-
const color = flowColor(p.color, palette);
|
|
22104
22132
|
const start = p.start ?? "none", end = p.end ?? "arrow";
|
|
22105
22133
|
const pts = [...r.points];
|
|
22106
22134
|
pts[0] = add(pts[0], DIR[r.from], INSET[start]);
|
|
22107
22135
|
pts[pts.length - 1] = add(pts[pts.length - 1], DIR[r.to], INSET[end]);
|
|
22108
|
-
const
|
|
22109
|
-
|
|
22110
|
-
|
|
22111
|
-
marker(start, r.points[0], DIR[r.from], color, `${key}-start`),
|
|
22112
|
-
marker(end, r.points[r.points.length - 1], DIR[r.to], color, `${key}-end`)
|
|
22113
|
-
);
|
|
22136
|
+
const line = p.line ?? "rounded";
|
|
22137
|
+
const { d: d2, at } = linePath(r, pts, line);
|
|
22138
|
+
const out = { key, route: r, points: pts, d: d2, color: flowColor(p.color, palette), start, end, line, dashed: !!p.dashed };
|
|
22114
22139
|
if (p.label) {
|
|
22115
22140
|
const w2 = flowLabelWidth(String(p.label));
|
|
22116
22141
|
const covers = (c2) => placed.filter((q) => c2.x - w2 / 2 < q.x + q.w && q.x < c2.x + w2 / 2 && c2.y - 14 < q.y + q.h && q.y < c2.y + 14).length + ends.filter((q) => Math.abs(q.x - c2.x) < w2 / 2 + 12 && Math.abs(q.y - c2.y) < 24).length;
|
|
@@ -22120,13 +22145,58 @@ function flowLayer(spec, flows, screens, gap, palette, size) {
|
|
|
22120
22145
|
const c2 = at(t), n = covers(c2);
|
|
22121
22146
|
if (n < best) [mid, best] = [c2, n];
|
|
22122
22147
|
}
|
|
22123
|
-
const
|
|
22124
|
-
placed.push(
|
|
22148
|
+
const box = { x: mid.x - w2 / 2, y: mid.y - 12, w: w2, h: 24 };
|
|
22149
|
+
placed.push(box);
|
|
22150
|
+
out.label = { text: String(p.label), ...box };
|
|
22151
|
+
}
|
|
22152
|
+
return out;
|
|
22153
|
+
});
|
|
22154
|
+
}
|
|
22155
|
+
function flowPolyline(f) {
|
|
22156
|
+
const r = f.route, pts = f.points;
|
|
22157
|
+
const s0 = pts[0], e0 = pts[pts.length - 1];
|
|
22158
|
+
let out;
|
|
22159
|
+
if (r.lane == null && f.line === "straight") out = [s0, e0];
|
|
22160
|
+
else if (r.lane == null && f.line === "curved") {
|
|
22161
|
+
const { at } = linePath(r, pts, f.line);
|
|
22162
|
+
out = Array.from({ length: 25 }, (_, i2) => at(i2 / 24));
|
|
22163
|
+
} else {
|
|
22164
|
+
const radius = f.line === "curved" ? 40 : f.line === "rounded" ? 14 : 0;
|
|
22165
|
+
const q = simplify(pts);
|
|
22166
|
+
out = [q[0]];
|
|
22167
|
+
for (let i2 = 1; i2 < q.length; i2++) {
|
|
22168
|
+
const p = q[i2];
|
|
22169
|
+
if (radius > 0 && i2 < q.length - 1) {
|
|
22170
|
+
const prev = q[i2 - 1], next = q[i2 + 1];
|
|
22171
|
+
const rr2 = Math.min(radius, Math.hypot(p.x - prev.x, p.y - prev.y) / 2, Math.hypot(next.x - p.x, next.y - p.y) / 2);
|
|
22172
|
+
const into = { x: Math.sign(p.x - prev.x), y: Math.sign(p.y - prev.y) }, outd = { x: Math.sign(next.x - p.x), y: Math.sign(next.y - p.y) };
|
|
22173
|
+
const a = { x: p.x - into.x * rr2, y: p.y - into.y * rr2 }, b = { x: p.x + outd.x * rr2, y: p.y + outd.y * rr2 };
|
|
22174
|
+
for (let k = 0; k <= 6; k++) {
|
|
22175
|
+
const t = k / 6;
|
|
22176
|
+
out.push({ x: (1 - t) ** 2 * a.x + 2 * (1 - t) * t * p.x + t ** 2 * b.x, y: (1 - t) ** 2 * a.y + 2 * (1 - t) * t * p.y + t ** 2 * b.y });
|
|
22177
|
+
}
|
|
22178
|
+
} else out.push(p);
|
|
22179
|
+
}
|
|
22180
|
+
}
|
|
22181
|
+
const first = r.points[0], last = r.points[r.points.length - 1];
|
|
22182
|
+
return [first, ...out, last].filter((p, i2, all) => i2 === 0 || Math.hypot(p.x - all[i2 - 1].x, p.y - all[i2 - 1].y) >= 0.01);
|
|
22183
|
+
}
|
|
22184
|
+
function flowLayer(layout, size) {
|
|
22185
|
+
const shapes = [];
|
|
22186
|
+
const labels = [];
|
|
22187
|
+
for (const f of layout) {
|
|
22188
|
+
const r = f.route, { key, color } = f;
|
|
22189
|
+
shapes.push(
|
|
22190
|
+
/* @__PURE__ */ jsx5("path", { d: f.d, fill: "none", stroke: color, strokeWidth: 2, strokeLinejoin: "round", strokeLinecap: "round", ...f.dashed ? { strokeDasharray: "7 6" } : {} }, `${key}-line`),
|
|
22191
|
+
marker(f.start, r.points[0], DIR[r.from], color, `${key}-start`),
|
|
22192
|
+
marker(f.end, r.points[r.points.length - 1], DIR[r.to], color, `${key}-end`)
|
|
22193
|
+
);
|
|
22194
|
+
if (f.label) {
|
|
22125
22195
|
labels.push(
|
|
22126
|
-
/* @__PURE__ */ jsx5("div", { style: { position: "absolute", left:
|
|
22196
|
+
/* @__PURE__ */ jsx5("div", { style: { position: "absolute", left: f.label.x, top: f.label.y, width: f.label.w, height: 24, display: "flex", alignItems: "center", justifyContent: "center", borderRadius: 12, backgroundColor: theme.paper, border: `1.5px solid ${color}`, color, fontSize: 12, fontWeight: 600 }, children: f.label.text }, `${key}-label`)
|
|
22127
22197
|
);
|
|
22128
22198
|
}
|
|
22129
|
-
}
|
|
22199
|
+
}
|
|
22130
22200
|
return /* @__PURE__ */ jsxs3("div", { style: { position: "absolute", top: 0, left: 0, width: size.width, height: size.height, display: "flex" }, children: [
|
|
22131
22201
|
/* @__PURE__ */ jsx5("svg", { width: size.width, height: size.height, viewBox: `0 0 ${size.width} ${size.height}`, style: { position: "absolute", top: 0, left: 0 }, children: shapes }),
|
|
22132
22202
|
labels
|
|
@@ -22917,10 +22987,8 @@ async function renderWireframeSvg(spec, opts = {}) {
|
|
|
22917
22987
|
if (issues.length) throw new SpecError(issues);
|
|
22918
22988
|
}
|
|
22919
22989
|
const flowsOn = opts.flows !== false;
|
|
22920
|
-
const { width, height
|
|
22921
|
-
|
|
22922
|
-
if ((board.props ?? {}).gap == null && gap !== BOARD_GAP)
|
|
22923
|
-
spec = { ...spec, elements: { ...spec.elements, [spec.root]: { ...board, props: { ...board.props, gap } } } };
|
|
22990
|
+
const { width, height } = boardLayout(spec, { flows: opts.flows });
|
|
22991
|
+
spec = withBoardGap(spec, opts.flows);
|
|
22924
22992
|
const palette = paletteFor(spec.elements[spec.root]?.props?.accent);
|
|
22925
22993
|
const registry2 = withPalette(palette);
|
|
22926
22994
|
const draw = async (s, reg) => renderToSvg(s, { registry: reg, includeStandard: false, fonts: await loadFonts(), width, height });
|
|
@@ -22928,13 +22996,17 @@ async function renderWireframeSvg(spec, opts = {}) {
|
|
|
22928
22996
|
const { anchors, boxes } = await measureAnchors(spec, flows?.measure ?? []);
|
|
22929
22997
|
if (!anchors.length && !flows?.list.length) return draw(spec, registry2);
|
|
22930
22998
|
const layers = [];
|
|
22931
|
-
if (flows?.list.length) {
|
|
22932
|
-
const resolved = flows.list.map(({ key, from, to: to2 }) => ({ key, ends: { from: flows.box(from, boxes) ?? flows.screenBox(from), to: flows.box(to2, boxes) ?? flows.screenBox(to2), fromScreen: flows.screenBox(from), toScreen: flows.screenBox(to2) } })).filter((f) => !!(f.ends.from && f.ends.to && f.ends.fromScreen && f.ends.toScreen));
|
|
22933
|
-
layers.push(flowLayer(spec, resolved, flows.screens, flows.gap, palette, { width, height }));
|
|
22934
|
-
}
|
|
22999
|
+
if (flows?.list.length) layers.push(flowLayer(layoutFlows(spec, flows.resolve(boxes), flows.screens, flows.gap, palette), { width, height }));
|
|
22935
23000
|
if (anchors.length) layers.push(overlayLayer(spec, anchors, boxes, palette, registry2.Calendar));
|
|
22936
23001
|
return draw(spec, withTopLayer(registry2, layers));
|
|
22937
23002
|
}
|
|
23003
|
+
function withBoardGap(spec, flows) {
|
|
23004
|
+
const { gap } = boardLayout(spec, { flows });
|
|
23005
|
+
const board = spec.elements[spec.root];
|
|
23006
|
+
if ((board.props ?? {}).gap == null && gap !== BOARD_GAP)
|
|
23007
|
+
return { ...spec, elements: { ...spec.elements, [spec.root]: { ...board, props: { ...board.props, gap } } } };
|
|
23008
|
+
return spec;
|
|
23009
|
+
}
|
|
22938
23010
|
function flowEnds(spec) {
|
|
22939
23011
|
const els = spec.elements;
|
|
22940
23012
|
const byId = /* @__PURE__ */ new Map();
|
|
@@ -22962,9 +23034,12 @@ function flowEnds(spec) {
|
|
|
22962
23034
|
list,
|
|
22963
23035
|
measure,
|
|
22964
23036
|
screens: [...screenRects.values()],
|
|
22965
|
-
screenBox: (key) => screenRects.get(screenOf(key) ?? ""),
|
|
22966
23037
|
gap: (els[spec.root].props ?? {}).gap ?? BOARD_GAP,
|
|
22967
|
-
|
|
23038
|
+
resolve(boxes) {
|
|
23039
|
+
const box = (key) => els[key].type === "Screen" ? screenRects.get(key) : boxes[key];
|
|
23040
|
+
const screenBox = (key) => screenRects.get(screenOf(key) ?? "");
|
|
23041
|
+
return list.map(({ key, from, to: to2 }) => ({ key, ends: { from: box(from) ?? screenBox(from), to: box(to2) ?? screenBox(to2), fromScreen: screenBox(from), toScreen: screenBox(to2) } })).filter((f) => !!(f.ends.from && f.ends.to && f.ends.fromScreen && f.ends.toScreen));
|
|
23042
|
+
}
|
|
22968
23043
|
};
|
|
22969
23044
|
}
|
|
22970
23045
|
async function measureAnchors(spec, extra = []) {
|
|
@@ -23008,7 +23083,7 @@ function compileWireframe(source) {
|
|
|
23008
23083
|
return true;
|
|
23009
23084
|
});
|
|
23010
23085
|
unique.sort((a, b) => a.line - b.line);
|
|
23011
|
-
return { spec: parsed.spec, issues: unique };
|
|
23086
|
+
return { spec: parsed.spec, issues: unique, lines: parsed.lines };
|
|
23012
23087
|
}
|
|
23013
23088
|
function formatIssues(issues) {
|
|
23014
23089
|
return issues.map((i2) => `line ${i2.line}: ${i2.message}`).join("\n");
|
|
@@ -23471,6 +23546,150 @@ function addStyles(doc) {
|
|
|
23471
23546
|
doc.head.append(style);
|
|
23472
23547
|
}
|
|
23473
23548
|
|
|
23549
|
+
// src/measure.ts
|
|
23550
|
+
var isFlow = (e) => e.type === "Flow";
|
|
23551
|
+
var COVERS_SCREEN = /* @__PURE__ */ new Set(["Modal", "Drawer"]);
|
|
23552
|
+
var OVERLAYS = /* @__PURE__ */ new Set(["Modal", "Drawer", "Toast"]);
|
|
23553
|
+
var CONTAINERS = new Set(Object.entries(componentDefinitions).filter(([, d2]) => d2.slots.length).map(([name]) => name));
|
|
23554
|
+
var BARS = /* @__PURE__ */ new Set(["NavBar", "TabBar"]);
|
|
23555
|
+
var toBox = (r) => ({ x: round(r.x), y: round(r.y), width: round(r.w), height: round(r.h) });
|
|
23556
|
+
var round = (n) => Math.round(n * 100) / 100;
|
|
23557
|
+
function clip(r, to2) {
|
|
23558
|
+
if (!to2) return r;
|
|
23559
|
+
const x3 = Math.max(r.x, to2.x), y = Math.max(r.y, to2.y);
|
|
23560
|
+
const w2 = Math.min(r.x + r.w, to2.x + to2.w) - x3, h2 = Math.min(r.y + r.h, to2.y + to2.h) - y;
|
|
23561
|
+
return w2 >= 0 && h2 >= 0 && (w2 > 0 || r.w === 0) && (h2 > 0 || r.h === 0) ? { x: x3, y, w: w2, h: h2 } : null;
|
|
23562
|
+
}
|
|
23563
|
+
async function measureElements(spec, lines, opts = {}) {
|
|
23564
|
+
upgradeSpec(spec);
|
|
23565
|
+
if (!opts.skipValidation) {
|
|
23566
|
+
const issues = checkSpec(spec);
|
|
23567
|
+
if (issues.length) throw new SpecError(issues);
|
|
23568
|
+
}
|
|
23569
|
+
const { width, height } = boardLayout(spec, { flows: opts.flows });
|
|
23570
|
+
spec = withBoardGap(spec, opts.flows);
|
|
23571
|
+
const els = spec.elements;
|
|
23572
|
+
const anchors = findAnchors(spec);
|
|
23573
|
+
const every = Object.keys(els).filter((k) => !["Board", "Screen", "Flow"].includes(els[k].type)).map((id) => ({ id, screen: id, kind: "tooltip", field: false }));
|
|
23574
|
+
const screens = Object.keys(els).filter((k) => els[k].type === "Screen");
|
|
23575
|
+
const { tagged, colors } = tagForMeasuring(spec, [...anchors, ...every], screens);
|
|
23576
|
+
const svg = await renderToSvg(tagged, { registry: withMarkers(withPalette(paletteFor())), includeStandard: false, fonts: await loadFonts(), width, height });
|
|
23577
|
+
const boxes = readMarkers(svg, colors);
|
|
23578
|
+
const { items } = boardLayout(spec, { flows: opts.flows });
|
|
23579
|
+
const laidOut = (els[spec.root].children ?? []).filter((k) => els[k]?.type === "Screen" || els[k]?.type === "Note");
|
|
23580
|
+
const frames = /* @__PURE__ */ new Map(), bands = /* @__PURE__ */ new Map();
|
|
23581
|
+
laidOut.forEach((k, i2) => {
|
|
23582
|
+
const it = items[i2];
|
|
23583
|
+
if (!it || els[k].type !== "Screen") return;
|
|
23584
|
+
frames.set(k, { x: it.x, y: it.y + LABEL_H, w: it.width, h: it.height - LABEL_H });
|
|
23585
|
+
bands.set(k, { x: it.x, y: it.y, w: it.width, h: LABEL_H });
|
|
23586
|
+
});
|
|
23587
|
+
const overlays = /* @__PURE__ */ new Map();
|
|
23588
|
+
for (const o2 of overlayBoxes(spec, anchors, boxes)) overlays.set(o2.id, [...overlays.get(o2.id) ?? [], o2.box]);
|
|
23589
|
+
const lineOf = (k) => k == null ? null : lines[k] ?? 0;
|
|
23590
|
+
const endLine = (k) => Math.max(lines[k] ?? 0, ...(els[k].children ?? []).filter((c2) => els[c2]).map(endLine));
|
|
23591
|
+
const labelOf = (k) => {
|
|
23592
|
+
const p = els[k].props ?? {};
|
|
23593
|
+
const v2 = p[PRIMARY_PROP[els[k].type] ?? ""];
|
|
23594
|
+
return typeof v2 === "string" ? v2 : void 0;
|
|
23595
|
+
};
|
|
23596
|
+
const out = [];
|
|
23597
|
+
const visit = (k, parent, screen, cut) => {
|
|
23598
|
+
const el2 = els[k];
|
|
23599
|
+
if (!el2 || el2.type === "Flow") return;
|
|
23600
|
+
const p = el2.props ?? {};
|
|
23601
|
+
const base = { line: lineOf(k), endLine: endLine(k), ...typeof p.id === "string" ? { id: p.id } : {}, type: el2.type, ...labelOf(k) != null ? { label: labelOf(k) } : {}, screenLine: lineOf(screen), parentLine: lineOf(parent) };
|
|
23602
|
+
let entry = null;
|
|
23603
|
+
if (el2.type === "Board") entry = { ...base, box: { x: 0, y: 0, width, height } };
|
|
23604
|
+
else if (el2.type === "Screen") {
|
|
23605
|
+
const frame = frames.get(k);
|
|
23606
|
+
if (frame) entry = { ...base, box: toBox(frame), labelBox: toBox(bands.get(k)) };
|
|
23607
|
+
} else {
|
|
23608
|
+
const r = boxes[k];
|
|
23609
|
+
const seen = r && clip(r, cut);
|
|
23610
|
+
if (seen) {
|
|
23611
|
+
const view = screen ? boxes[screen] ?? frames.get(screen) : void 0;
|
|
23612
|
+
const os3 = (overlays.get(k) ?? []).map((o2) => clip(o2, view)).filter((o2) => !!o2 && o2.w > 0 && o2.h > 0);
|
|
23613
|
+
entry = { ...base, box: toBox(seen), ...os3.length ? { overlays: os3.map(toBox) } : {}, ...COVERS_SCREEN.has(el2.type) ? { scrim: p.scrim ?? true } : {} };
|
|
23614
|
+
}
|
|
23615
|
+
}
|
|
23616
|
+
if (entry) out.push(entry);
|
|
23617
|
+
const inScreen = el2.type === "Screen" ? k : screen;
|
|
23618
|
+
const kids = el2.children ?? [];
|
|
23619
|
+
if (el2.type === "Screen") {
|
|
23620
|
+
const frame = frames.get(k) ?? null;
|
|
23621
|
+
const body = clip(boxes[`${k}#body`] ?? frame, frame);
|
|
23622
|
+
const over = (c2) => OVERLAYS.has(els[c2]?.type);
|
|
23623
|
+
for (const c2 of [...kids.filter((c3) => !over(c3)), ...kids.filter(over)]) visit(c2, k, k, BARS.has(els[c2]?.type) || over(c2) ? frame : body);
|
|
23624
|
+
} else {
|
|
23625
|
+
const inner = el2.type === "Drawer" && boxes[k] ? clip(boxes[k], cut) : cut;
|
|
23626
|
+
for (const c2 of kids) visit(c2, k, inScreen, inner);
|
|
23627
|
+
}
|
|
23628
|
+
};
|
|
23629
|
+
visit(spec.root, null, null, null);
|
|
23630
|
+
if (opts.flows !== false) {
|
|
23631
|
+
const flows = flowEnds(spec);
|
|
23632
|
+
const resolved = flows.resolve(boxes);
|
|
23633
|
+
const ends = new Map(flows.list.map((f) => [f.key, f]));
|
|
23634
|
+
layoutFlows(spec, resolved, flows.screens, flows.gap, paletteFor()).forEach((f) => {
|
|
23635
|
+
const p = els[f.key].props ?? {};
|
|
23636
|
+
const e = ends.get(f.key);
|
|
23637
|
+
out.push({
|
|
23638
|
+
line: lineOf(f.key),
|
|
23639
|
+
endLine: lineOf(f.key),
|
|
23640
|
+
type: "Flow",
|
|
23641
|
+
...f.label ? { label: f.label.text } : {},
|
|
23642
|
+
from: String(p.from),
|
|
23643
|
+
to: String(p.to),
|
|
23644
|
+
fromLine: lineOf(e.from),
|
|
23645
|
+
toLine: lineOf(e.to),
|
|
23646
|
+
path: flowPolyline(f).map((q) => [round(q.x), round(q.y)]),
|
|
23647
|
+
...f.label ? { labelBox: toBox(f.label) } : {}
|
|
23648
|
+
});
|
|
23649
|
+
});
|
|
23650
|
+
}
|
|
23651
|
+
return out;
|
|
23652
|
+
}
|
|
23653
|
+
var inside = (b, x3, y) => !!b && b.width > 0 && b.height > 0 && x3 >= b.x && x3 <= b.x + b.width && y >= b.y && y <= b.y + b.height;
|
|
23654
|
+
var center = (b) => [b.x + b.width / 2, b.y + b.height / 2];
|
|
23655
|
+
function distanceToPath(path, x3, y) {
|
|
23656
|
+
let best = Infinity;
|
|
23657
|
+
for (let i2 = 1; i2 < path.length; i2++) {
|
|
23658
|
+
const [ax, ay] = path[i2 - 1], [bx, by] = path[i2];
|
|
23659
|
+
const dx = bx - ax, dy = by - ay, len = dx * dx + dy * dy;
|
|
23660
|
+
const t = len ? Math.max(0, Math.min(1, ((x3 - ax) * dx + (y - ay) * dy) / len)) : 0;
|
|
23661
|
+
best = Math.min(best, Math.hypot(x3 - ax - t * dx, y - ay - t * dy));
|
|
23662
|
+
}
|
|
23663
|
+
return best;
|
|
23664
|
+
}
|
|
23665
|
+
var isContainer = (e) => CONTAINERS.has(e.type);
|
|
23666
|
+
function elementsAt(elements, x3, y, opts = {}) {
|
|
23667
|
+
const tolerance = opts.tolerance ?? 6;
|
|
23668
|
+
const order = new Map(elements.map((e, i2) => [e, i2]));
|
|
23669
|
+
const topFirst = (a, b) => order.get(b) - order.get(a);
|
|
23670
|
+
const covered = /* @__PURE__ */ new Set();
|
|
23671
|
+
const screens = elements.filter((e) => e.type === "Screen");
|
|
23672
|
+
const screenAround = (b) => screens.find((s) => inside(s.box, ...center(b)));
|
|
23673
|
+
for (const [i2, m2] of elements.entries()) {
|
|
23674
|
+
if (isFlow(m2) || !OVERLAYS.has(m2.type)) continue;
|
|
23675
|
+
const screen = screenAround(m2.box);
|
|
23676
|
+
if (!screen || !inside(m2.box, x3, y) && !(m2.scrim && inside(screen.box, x3, y))) continue;
|
|
23677
|
+
for (const e of elements.slice(0, i2)) if (!isFlow(e) && e.type !== "Screen" && e.type !== "Board" && screenAround(e.box) === screen) covered.add(e);
|
|
23678
|
+
}
|
|
23679
|
+
const owners = [], labels = [], leaves = [], lines = [], containers = [];
|
|
23680
|
+
for (const e of elements) {
|
|
23681
|
+
if (isFlow(e)) {
|
|
23682
|
+
if (inside(e.labelBox, x3, y)) labels.push(e);
|
|
23683
|
+
else if (distanceToPath(e.path, x3, y) <= tolerance) lines.push(e);
|
|
23684
|
+
} else if (e.overlays?.some((o2) => inside(o2, x3, y))) owners.push(e);
|
|
23685
|
+
else if (!covered.has(e) && (inside(e.box, x3, y) || inside(e.labelBox, x3, y))) (isContainer(e) ? containers : leaves).push(e);
|
|
23686
|
+
}
|
|
23687
|
+
return [owners, labels, leaves, lines, containers].flatMap((g2) => g2.sort(topFirst));
|
|
23688
|
+
}
|
|
23689
|
+
function elementsAtLine(elements, line) {
|
|
23690
|
+
return elements.filter((e) => e.line > 0 && e.line <= line && line <= e.endLine).sort((a, b) => b.line - a.line);
|
|
23691
|
+
}
|
|
23692
|
+
|
|
23474
23693
|
// src/playground/language-data.ts
|
|
23475
23694
|
function unwrap4(t) {
|
|
23476
23695
|
let cur = t;
|
|
@@ -23539,11 +23758,14 @@ export {
|
|
|
23539
23758
|
compileWireframe,
|
|
23540
23759
|
componentDefinitions,
|
|
23541
23760
|
decodeWireframe,
|
|
23761
|
+
elementsAt,
|
|
23762
|
+
elementsAtLine,
|
|
23542
23763
|
encodeWireframe,
|
|
23543
23764
|
formatIssues,
|
|
23544
23765
|
printWireframeText as formatWireframe,
|
|
23545
23766
|
languageData,
|
|
23546
23767
|
mcpTools,
|
|
23768
|
+
measureElements,
|
|
23547
23769
|
parseWireframeText,
|
|
23548
23770
|
registry,
|
|
23549
23771
|
renderAll,
|