@n-uf/placement 26.11.53 → 26.11.54
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 +75 -1
- package/README.md +27 -58
- package/dist/{chunk-VLTYJHUA.js → chunk-2UVUFEBP.js} +4 -8
- package/dist/{chunk-VLTYJHUA.js.map → chunk-2UVUFEBP.js.map} +1 -1
- package/dist/{geometry-Bf37LbCT.d.ts → geometry-L5gCoiZV.d.ts} +2 -8
- package/dist/index.d.ts +64 -42
- package/dist/index.js +6 -66
- package/dist/index.js.map +1 -1
- package/dist/popup.d.ts +49 -0
- package/dist/popup.js +58 -0
- package/dist/popup.js.map +1 -0
- package/dist/stack.d.ts +529 -228
- package/dist/stack.js +701 -28
- package/dist/stack.js.map +1 -1
- package/dist/tiling.d.ts +48 -5
- package/dist/tiling.js +198 -19
- package/dist/tiling.js.map +1 -1
- package/package.json +9 -36
- package/dist/chunk-2GGJ4GVR.js +0 -9
- package/dist/chunk-2GGJ4GVR.js.map +0 -1
- package/dist/chunk-3ZICYLWL.js +0 -791
- package/dist/chunk-3ZICYLWL.js.map +0 -1
- package/dist/chunk-AE3BWTAE.js +0 -838
- package/dist/chunk-AE3BWTAE.js.map +0 -1
- package/dist/chunk-JVAR67OL.js +0 -172
- package/dist/chunk-JVAR67OL.js.map +0 -1
- package/dist/chunk-NF7RYK3U.js +0 -429
- package/dist/chunk-NF7RYK3U.js.map +0 -1
- package/dist/chunk-R3AAANRY.js +0 -220
- package/dist/chunk-R3AAANRY.js.map +0 -1
- package/dist/chunk-TWI644JK.js +0 -221
- package/dist/chunk-TWI644JK.js.map +0 -1
- package/dist/chunk-ZTH5FCUO.js +0 -4190
- package/dist/chunk-ZTH5FCUO.js.map +0 -1
- package/dist/constructions-Cbz7uEAZ.d.ts +0 -251
- package/dist/desk.d.ts +0 -51
- package/dist/desk.js +0 -111
- package/dist/desk.js.map +0 -1
- package/dist/dock.d.ts +0 -25
- package/dist/dock.js +0 -397
- package/dist/dock.js.map +0 -1
- package/dist/float-fit-DCYxRMru.d.ts +0 -37
- package/dist/lanes-DIwUqchd.d.ts +0 -1321
- package/dist/model-X7eUaKlA.d.ts +0 -337
- package/dist/panels.d.ts +0 -60
- package/dist/panels.js +0 -99
- package/dist/panels.js.map +0 -1
- package/dist/regions-Db_RyT4P.d.ts +0 -48
- package/dist/scene-cases.d.ts +0 -888
- package/dist/scene-cases.js +0 -3149
- package/dist/scene-cases.js.map +0 -1
- package/dist/scene.d.ts +0 -290
- package/dist/scene.js +0 -128
- package/dist/scene.js.map +0 -1
- package/dist/target-BBOCeez2.d.ts +0 -69
- package/dist/targets-C9ZVhmCl.d.ts +0 -621
- package/dist/targets.d.ts +0 -212
- package/dist/targets.js +0 -447
- package/dist/targets.js.map +0 -1
- package/dist/toolbar.d.ts +0 -167
- package/dist/toolbar.js +0 -55
- package/dist/toolbar.js.map +0 -1
package/dist/stack.js
CHANGED
|
@@ -1,41 +1,714 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
EPS,
|
|
3
|
+
clampInto,
|
|
4
|
+
overlap,
|
|
5
|
+
overlaps,
|
|
6
|
+
rect
|
|
7
|
+
} from "./chunk-2UVUFEBP.js";
|
|
8
|
+
|
|
9
|
+
// src/stack/cut.ts
|
|
10
|
+
var px = (x) => typeof x === "number" && Number.isFinite(x) ? Math.max(0, x) : 0;
|
|
11
|
+
function cutBand(area, band) {
|
|
12
|
+
const across = band.side === "top" || band.side === "bottom" ? area.height : area.width;
|
|
13
|
+
const room = Math.max(0, across);
|
|
14
|
+
const thick = Math.min(px(band.size), room);
|
|
15
|
+
const gap = thick > 0 ? Math.min(px(band.gap), room - thick) : 0;
|
|
16
|
+
const take = thick + gap;
|
|
17
|
+
switch (band.side) {
|
|
18
|
+
case "top":
|
|
19
|
+
return { rect: rect(area.x, area.y, area.width, thick), rest: rect(area.x, area.y + take, area.width, area.height - take) };
|
|
20
|
+
case "bottom":
|
|
21
|
+
return { rect: rect(area.x, area.y + area.height - thick, area.width, thick), rest: rect(area.x, area.y, area.width, area.height - take) };
|
|
22
|
+
case "left":
|
|
23
|
+
return { rect: rect(area.x, area.y, thick, area.height), rest: rect(area.x + take, area.y, area.width - take, area.height) };
|
|
24
|
+
case "right":
|
|
25
|
+
return { rect: rect(area.x + area.width - thick, area.y, thick, area.height), rest: rect(area.x, area.y, area.width - take, area.height) };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function cutEdges(stage, bands) {
|
|
29
|
+
const seen = /* @__PURE__ */ new Set();
|
|
30
|
+
for (const b of bands) {
|
|
31
|
+
if (seen.has(b.id)) throw new Error(`cutEdges: band id "${b.id}" is given twice`);
|
|
32
|
+
seen.add(b.id);
|
|
33
|
+
}
|
|
34
|
+
const out = {};
|
|
35
|
+
let rest = rect(stage.x, stage.y, px(stage.width), px(stage.height));
|
|
36
|
+
for (const b of bands) {
|
|
37
|
+
if (b.mode === "over") continue;
|
|
38
|
+
const c = cutBand(rest, b);
|
|
39
|
+
out[b.id] = c.rect;
|
|
40
|
+
rest = c.rest;
|
|
41
|
+
}
|
|
42
|
+
let over = rest;
|
|
43
|
+
for (const b of bands) {
|
|
44
|
+
if (b.mode !== "over") continue;
|
|
45
|
+
const c = cutBand(over, b);
|
|
46
|
+
out[b.id] = c.rect;
|
|
47
|
+
over = c.rest;
|
|
48
|
+
}
|
|
49
|
+
return { bands: out, rest };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/stack/model.ts
|
|
53
|
+
var nonNeg = (x) => typeof x === "number" && Number.isFinite(x) ? Math.max(0, x) : 0;
|
|
54
|
+
function formCrossMin(f) {
|
|
55
|
+
if (f.wrap) return wrapCross(f.wrap).min;
|
|
56
|
+
const v = f.cross.min ?? f.cross.natural;
|
|
57
|
+
return Number.isFinite(v) ? v : 0;
|
|
58
|
+
}
|
|
59
|
+
function formMain(f, which, cross) {
|
|
60
|
+
if (f.kind === "menu") return 0;
|
|
61
|
+
if (f.wrap) return wrapRows(f.wrap, cross).rows * nonNeg(f.wrap.row);
|
|
62
|
+
return nonNeg(f.main[which]);
|
|
63
|
+
}
|
|
64
|
+
function formFitsCross(f, cross) {
|
|
65
|
+
if (!f.wrap) return true;
|
|
66
|
+
const widest = Math.max(0, ...f.wrap.widths.map(nonNeg));
|
|
67
|
+
return cross + 1e-6 >= nonNeg(f.wrap.lead) + widest && wrapLines(f.wrap, cross).fits;
|
|
68
|
+
}
|
|
69
|
+
function rowWidths(spec) {
|
|
70
|
+
const gap = nonNeg(spec.gap);
|
|
71
|
+
const lead = nonNeg(spec.lead);
|
|
72
|
+
const widths = spec.widths.map(nonNeg);
|
|
73
|
+
const out = [];
|
|
74
|
+
for (let i = 0; i < widths.length; i++) {
|
|
75
|
+
let run = 0;
|
|
76
|
+
for (let j = i; j < widths.length; j++) {
|
|
77
|
+
run += widths[j] + (j > i ? gap : 0);
|
|
78
|
+
out.push(lead + run);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return out.sort((a, b) => a - b);
|
|
82
|
+
}
|
|
83
|
+
function wrapLines(spec, cross) {
|
|
84
|
+
const g = greedyLines(spec, cross);
|
|
85
|
+
if (g.fits) return g;
|
|
86
|
+
const narrower = rowWidths(spec).filter((c) => c <= cross + 1e-6);
|
|
87
|
+
for (let i = narrower.length - 1; i >= 0; i--) {
|
|
88
|
+
const h = greedyLines(spec, narrower[i]);
|
|
89
|
+
if (h.fits) return h;
|
|
90
|
+
}
|
|
91
|
+
return g;
|
|
92
|
+
}
|
|
93
|
+
function greedyLines(spec, cross) {
|
|
94
|
+
const gap = nonNeg(spec.gap);
|
|
95
|
+
const lead = nonNeg(spec.lead);
|
|
96
|
+
const widths = spec.widths.map(nonNeg);
|
|
97
|
+
if (widths.length === 0) return { lines: [], width: lead, fits: true };
|
|
98
|
+
const box = cross - lead;
|
|
99
|
+
const lines = [[]];
|
|
100
|
+
let x = 0;
|
|
101
|
+
let widest = 0;
|
|
102
|
+
widths.forEach((w, i) => {
|
|
103
|
+
const row = lines[lines.length - 1];
|
|
104
|
+
if (row.length > 0 && x + gap + w > box + 1e-6) {
|
|
105
|
+
widest = Math.max(widest, x);
|
|
106
|
+
lines.push([i]);
|
|
107
|
+
x = w;
|
|
108
|
+
} else {
|
|
109
|
+
x = row.length > 0 ? x + gap + w : w;
|
|
110
|
+
row.push(i);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
widest = Math.max(widest, x);
|
|
114
|
+
const fits = widths.length < 2 || lines.slice(0, -1).every((l) => l.length >= 2);
|
|
115
|
+
return { lines, width: lead + widest, fits };
|
|
116
|
+
}
|
|
117
|
+
function wrapRows(spec, cross) {
|
|
118
|
+
const w = wrapLines(spec, cross);
|
|
119
|
+
return { rows: Math.max(1, w.lines.length), width: w.width, fits: w.fits };
|
|
120
|
+
}
|
|
121
|
+
function wrapCross(spec) {
|
|
122
|
+
const gap = nonNeg(spec.gap);
|
|
123
|
+
const lead = nonNeg(spec.lead);
|
|
124
|
+
const widths = spec.widths.map(nonNeg);
|
|
125
|
+
const natural = lead + widths.reduce((s, w) => s + w, 0) + Math.max(0, widths.length - 1) * gap;
|
|
126
|
+
if (widths.length < 2) return { natural, min: natural };
|
|
127
|
+
const first = rowWidths(spec).find((c) => greedyLines(spec, c).fits) ?? natural;
|
|
128
|
+
const min = Math.max(lead + Math.max(...widths), first);
|
|
129
|
+
return { natural, min };
|
|
130
|
+
}
|
|
131
|
+
var DEFAULT_RAIL = 30;
|
|
132
|
+
var DEFAULT_MENU = 28;
|
|
133
|
+
var finite = (x, fallback) => Number.isFinite(x) ? x : fallback;
|
|
134
|
+
function limitsOf(input) {
|
|
135
|
+
const min = Math.max(0, finite(input.cross.min, 0));
|
|
136
|
+
const max = Number.isNaN(input.cross.max) ? Infinity : input.cross.max;
|
|
137
|
+
return { min, max: Math.max(min, max), rail: Math.max(0, finite(input.cross.rail ?? DEFAULT_RAIL, DEFAULT_RAIL)) };
|
|
138
|
+
}
|
|
139
|
+
var menuMain = (input) => Math.max(0, finite(input.menu?.main ?? DEFAULT_MENU, DEFAULT_MENU));
|
|
140
|
+
function spacingOf(input) {
|
|
141
|
+
const px2 = (x) => Math.max(0, finite(x ?? 0, 0));
|
|
142
|
+
return { gap: px2(input.gap), start: px2(input.pad?.start), end: px2(input.pad?.end) };
|
|
143
|
+
}
|
|
144
|
+
var formBody = (f) => f.body ?? f.kind === "open";
|
|
145
|
+
var formFolded = (f) => f.folded ?? (f.kind === "header" || f.kind === "fold");
|
|
146
|
+
var formCompact = (f) => f.compact ?? f.kind === "icons";
|
|
147
|
+
var formSetsCross = (f) => f.setsCross ?? formBody(f);
|
|
148
|
+
function withItem(input, item, at) {
|
|
149
|
+
const k = Math.min(Math.max(0, Math.floor(at)), input.items.length);
|
|
150
|
+
return { ...input, items: [...input.items.slice(0, k), item, ...input.items.slice(k)] };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/stack/layout.ts
|
|
154
|
+
var isMenu = (f) => f.kind === "menu";
|
|
155
|
+
var GROUP_KINDS = /* @__PURE__ */ new Set(["row", "stacked", "wrap", "icons", "fold"]);
|
|
156
|
+
var finite2 = (x, fallback = 0) => Number.isFinite(x) ? x : fallback;
|
|
157
|
+
var mainOf = formMain;
|
|
158
|
+
var crossMin = formCrossMin;
|
|
159
|
+
var crossNatural = (f) => f.wrap ? wrapCross(f.wrap).natural : finite2(f.cross.natural);
|
|
160
|
+
var rankOf = (f) => finite2(f.rank ?? 0);
|
|
161
|
+
function victim(items, to) {
|
|
162
|
+
let best = -1;
|
|
163
|
+
for (let i = 0; i < items.length; i++) {
|
|
164
|
+
if (to[i] < 0 || items[i].fixed) continue;
|
|
165
|
+
if (best < 0) {
|
|
166
|
+
best = i;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const a = items[i];
|
|
170
|
+
const b = items[best];
|
|
171
|
+
const ra = rankOf(a.forms[to[i]]);
|
|
172
|
+
const rb = rankOf(b.forms[to[best]]);
|
|
173
|
+
const ka = a.kept ? 1 : 0;
|
|
174
|
+
const kb = b.kept ? 1 : 0;
|
|
175
|
+
if (ra !== rb ? ra < rb : ka !== kb ? ka < kb : a.used !== b.used ? a.used < b.used : true) best = i;
|
|
176
|
+
}
|
|
177
|
+
return best;
|
|
178
|
+
}
|
|
179
|
+
function fitStack(input, options = {}) {
|
|
180
|
+
const fresh = solve(input);
|
|
181
|
+
const previous = options.previous;
|
|
182
|
+
if (!previous || previous.need === void 0) return fresh;
|
|
183
|
+
const seed = { need: 0 };
|
|
184
|
+
const kept = solve(input, previous, seed);
|
|
185
|
+
if (kept.cross > previous.cross + EPS) return fresh;
|
|
186
|
+
const moreLength = Math.max(0, kept.length) - seed.need > previous.length - previous.need + EPS;
|
|
187
|
+
if (!moreLength) return kept;
|
|
188
|
+
const gain = !previous.steps && fresh.items.every((p, i) => p.form <= kept.items[i].form) && fresh.items.some((p, i) => p.form < kept.items[i].form);
|
|
189
|
+
return gain ? fresh : solve(input, previous, { need: 0 }, true);
|
|
190
|
+
}
|
|
191
|
+
function solve(input, previous, seed, grow = false) {
|
|
192
|
+
const length = Math.max(0, finite2(input.length));
|
|
193
|
+
const lim = limitsOf(input);
|
|
194
|
+
const items = input.items.filter((it) => it.forms.length > 0);
|
|
195
|
+
const offered = (f) => f.title !== true || input.titles === true;
|
|
196
|
+
const offeredFrom = (it, j) => {
|
|
197
|
+
for (let k = j; k < it.forms.length; k++) if (offered(it.forms[k])) return k;
|
|
198
|
+
return j;
|
|
199
|
+
};
|
|
200
|
+
const start = items.map((it) => offeredFrom(it, Math.min(Math.max(0, Math.floor(finite2(it.from ?? 0))), it.forms.length - 1)));
|
|
201
|
+
const at = [...start];
|
|
202
|
+
if (previous) {
|
|
203
|
+
const had = new Map(previous.items.map((p) => [p.id, p]));
|
|
204
|
+
const began = /* @__PURE__ */ new Map();
|
|
205
|
+
for (const n of previous.notes) if (n.code === "form-down" && !began.has(n.id)) began.set(n.id, n.from);
|
|
206
|
+
items.forEach((it, i) => {
|
|
207
|
+
const p = had.get(it.id);
|
|
208
|
+
if (it.fixed || !p || p.form < start[i] || p.form >= it.forms.length || start[i] < (began.get(it.id) ?? p.form)) return;
|
|
209
|
+
const f = it.forms[p.form];
|
|
210
|
+
if (f.kind === p.kind && offered(f)) at[i] = p.form;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const form = (i) => items[i].forms[at[i]];
|
|
214
|
+
const idx = items.map((_, i) => i);
|
|
215
|
+
const hist = [];
|
|
216
|
+
const withHistory = /* @__PURE__ */ new Set();
|
|
217
|
+
let batches = 0;
|
|
218
|
+
if (previous?.steps) {
|
|
219
|
+
const byId = new Map(items.map((it, i) => [it.id, i]));
|
|
220
|
+
const ends = /* @__PURE__ */ new Map();
|
|
221
|
+
const good = new Set(items.map((it) => it.id));
|
|
222
|
+
for (const s of previous.steps) {
|
|
223
|
+
const i = byId.get(s.id);
|
|
224
|
+
if (i === void 0) continue;
|
|
225
|
+
if (s.from !== (ends.get(s.id) ?? start[i])) good.delete(s.id);
|
|
226
|
+
ends.set(s.id, s.to);
|
|
227
|
+
}
|
|
228
|
+
items.forEach((it, i) => {
|
|
229
|
+
if ((ends.get(it.id) ?? start[i]) !== at[i]) good.delete(it.id);
|
|
230
|
+
});
|
|
231
|
+
for (const s of previous.steps) if (good.has(s.id) && byId.has(s.id)) hist.push(s);
|
|
232
|
+
for (const s of hist) {
|
|
233
|
+
withHistory.add(s.id);
|
|
234
|
+
if (s.batch !== void 0) batches = Math.max(batches, s.batch + 1);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const firstStep = [];
|
|
238
|
+
const menuOrder = [];
|
|
239
|
+
const step = (i, j, batch) => {
|
|
240
|
+
if (!firstStep.includes(i)) firstStep.push(i);
|
|
241
|
+
hist.push({ id: items[i].id, from: at[i], to: j, ...batch !== void 0 ? { batch } : {} });
|
|
242
|
+
withHistory.add(items[i].id);
|
|
243
|
+
at[i] = j;
|
|
244
|
+
if (isMenu(form(i)) && !menuOrder.includes(i)) menuOrder.push(i);
|
|
245
|
+
};
|
|
246
|
+
const named = (code) => previous ? previous.notes.filter((n) => n.code === code).map((n) => items.findIndex((it) => it.id === n.id)) : [];
|
|
247
|
+
for (const i of [...named("form-down"), ...idx]) if (i >= 0 && at[i] > start[i] && !firstStep.includes(i)) firstStep.push(i);
|
|
248
|
+
for (const i of [...named("to-menu"), ...idx]) if (i >= 0 && isMenu(form(i)) && !menuOrder.includes(i)) menuOrder.push(i);
|
|
249
|
+
const crossOf = () => {
|
|
250
|
+
const setters = idx.filter((i) => !isMenu(form(i)) && formSetsCross(form(i)));
|
|
251
|
+
if (setters.length === 0) return lim.rail;
|
|
252
|
+
const want = Math.max(...setters.map((i) => crossNatural(form(i))));
|
|
253
|
+
return Math.min(Math.max(want, lim.min), lim.max);
|
|
254
|
+
};
|
|
255
|
+
const inMenu = () => idx.some((i) => isMenu(form(i)));
|
|
256
|
+
const sp = spacingOf(input);
|
|
257
|
+
const gapsOf = () => {
|
|
258
|
+
const slots = idx.filter((i) => !isMenu(form(i))).length + (inMenu() ? 1 : 0);
|
|
259
|
+
return slots > 1 ? (slots - 1) * sp.gap : 0;
|
|
260
|
+
};
|
|
261
|
+
const holds = (i) => items[i].fixed === true && form(i).main.grows === true;
|
|
262
|
+
let hold = idx.some(holds);
|
|
263
|
+
const minSumWith = (held) => {
|
|
264
|
+
const c = items.some((it) => it.forms.some((f) => f.wrap)) ? crossOf() : 0;
|
|
265
|
+
return idx.reduce((s, i) => s + mainOf(form(i), held && holds(i) ? "natural" : "min", c), 0) + (inMenu() ? menuMain(input) : 0) + gapsOf() + sp.start + sp.end;
|
|
266
|
+
};
|
|
267
|
+
const minSum = () => minSumWith(hold);
|
|
268
|
+
const sameKind = (i, j) => items[i].forms[j].kind === form(i).kind;
|
|
269
|
+
const stepTo = (i) => {
|
|
270
|
+
const from = at[i];
|
|
271
|
+
const base = minSum();
|
|
272
|
+
let found = -1;
|
|
273
|
+
for (let j = from + 1; j < items[i].forms.length && found < 0; j++) {
|
|
274
|
+
if (!offered(items[i].forms[j])) continue;
|
|
275
|
+
at[i] = j;
|
|
276
|
+
if (minSum() < base - EPS) found = j;
|
|
277
|
+
}
|
|
278
|
+
at[i] = from;
|
|
279
|
+
return found;
|
|
280
|
+
};
|
|
281
|
+
const menuFormAfter = (i) => {
|
|
282
|
+
for (let j = at[i] + 1; j < items[i].forms.length; j++) if (isMenu(items[i].forms[j])) return j;
|
|
283
|
+
return -1;
|
|
284
|
+
};
|
|
285
|
+
const menuBatch = (pool) => {
|
|
286
|
+
const saved = [...at];
|
|
287
|
+
const base = minSum();
|
|
288
|
+
const left = [...pool];
|
|
289
|
+
const batch = [];
|
|
290
|
+
let found = false;
|
|
291
|
+
for (let b = victim(items, left); b >= 0 && !found; b = victim(items, left)) {
|
|
292
|
+
batch.push([b, left[b]]);
|
|
293
|
+
at[b] = left[b];
|
|
294
|
+
left[b] = -1;
|
|
295
|
+
found = minSum() < base - EPS;
|
|
296
|
+
}
|
|
297
|
+
at.splice(0, at.length, ...saved);
|
|
298
|
+
return found ? batch : null;
|
|
299
|
+
};
|
|
300
|
+
const nextOffered = (i) => {
|
|
301
|
+
for (let j = at[i] + 1; j < items[i].forms.length; j++) if (offered(items[i].forms[j])) return j;
|
|
302
|
+
return -1;
|
|
303
|
+
};
|
|
304
|
+
const canStep = (i) => nextOffered(i) >= 0;
|
|
305
|
+
const tooWide = (i, cross2) => {
|
|
306
|
+
const f = form(i);
|
|
307
|
+
if (isMenu(f)) return false;
|
|
308
|
+
if (formSetsCross(f)) return input.strictCross === true && crossMin(f) > lim.max + EPS;
|
|
309
|
+
if (f.wrap) return !formFitsCross(f, cross2);
|
|
310
|
+
return crossMin(f) > cross2 + EPS;
|
|
311
|
+
};
|
|
312
|
+
if (seed) seed.need = minSumWith(false);
|
|
313
|
+
if (grow) {
|
|
314
|
+
const comesBefore = (a, b) => {
|
|
315
|
+
const ra = rankOf(items[a].forms[at[a]]);
|
|
316
|
+
const rb = rankOf(items[b].forms[at[b]]);
|
|
317
|
+
const ka = items[a].kept ? 1 : 0;
|
|
318
|
+
const kb = items[b].kept ? 1 : 0;
|
|
319
|
+
return ra !== rb ? ra > rb : ka !== kb ? ka > kb : items[a].used !== items[b].used ? items[a].used > items[b].used : a < b;
|
|
320
|
+
};
|
|
321
|
+
const index = new Map(items.map((it, i) => [it.id, i]));
|
|
322
|
+
let stuck = false;
|
|
323
|
+
const undoes = (n, c0) => {
|
|
324
|
+
const group = hist.slice(hist.length - n);
|
|
325
|
+
const changed = [...new Set(group.map((s) => index.get(s.id)))];
|
|
326
|
+
const was = changed.map((i) => at[i]);
|
|
327
|
+
const forms = (s) => items[index.get(s.id)].forms;
|
|
328
|
+
hold = group.every((s) => forms(s)[s.from].kind === forms(s)[s.to].kind) && idx.some(holds);
|
|
329
|
+
for (const s of [...group].reverse()) at[index.get(s.id)] = s.from;
|
|
330
|
+
if (minSum() <= length + EPS && crossOf() === c0 && changed.every((j) => !tooWide(j, c0))) return true;
|
|
331
|
+
changed.forEach((i, k) => at[i] = was[k]);
|
|
332
|
+
return false;
|
|
333
|
+
};
|
|
334
|
+
while (hist.length > 0) {
|
|
335
|
+
const c0 = crossOf();
|
|
336
|
+
const last = hist[hist.length - 1];
|
|
337
|
+
let n = 1;
|
|
338
|
+
if (last.batch !== void 0) while (n < hist.length && hist[hist.length - 1 - n].batch === last.batch) n++;
|
|
339
|
+
let took = 0;
|
|
340
|
+
for (let m = n; m <= hist.length && took === 0; m++) {
|
|
341
|
+
if (m > n && (last.batch !== void 0 || hist[hist.length - m].id !== last.id)) break;
|
|
342
|
+
if (undoes(m, c0)) took = m;
|
|
343
|
+
}
|
|
344
|
+
if (took === 0) {
|
|
345
|
+
stuck = true;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
hist.length -= took;
|
|
349
|
+
}
|
|
350
|
+
hold = false;
|
|
351
|
+
for (; ; ) {
|
|
352
|
+
if (stuck) break;
|
|
353
|
+
const c0 = crossOf();
|
|
354
|
+
const fitsWith = (changed) => minSum() <= length + EPS && crossOf() === c0 && changed.every((j) => !tooWide(j, c0));
|
|
355
|
+
const queue = idx.filter((i) => !items[i].fixed && at[i] > start[i] && !withHistory.has(items[i].id)).sort((a, b) => comesBefore(a, b) ? -1 : 1);
|
|
356
|
+
const next = queue[0];
|
|
357
|
+
if (next === void 0) break;
|
|
358
|
+
const cur = at[next];
|
|
359
|
+
let to = -1;
|
|
360
|
+
for (let k = cur - 1; k >= start[next] && to < 0; k--) {
|
|
361
|
+
if (!offered(items[next].forms[k])) continue;
|
|
362
|
+
at[next] = k;
|
|
363
|
+
if (fitsWith([next])) to = k;
|
|
364
|
+
}
|
|
365
|
+
at[next] = cur;
|
|
366
|
+
if (to >= 0) {
|
|
367
|
+
at[next] = to;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
const inside2 = [];
|
|
371
|
+
for (const [q, i] of queue.entries()) {
|
|
372
|
+
if (!isMenu(form(i))) continue;
|
|
373
|
+
const ahead = queue.slice(0, q);
|
|
374
|
+
if (!ahead.every((j) => isMenu(form(j)) || at[i] - 1 - start[i] >= at[j] - start[j] && rankOf(form(i)) >= rankOf(form(j)))) break;
|
|
375
|
+
inside2.push(i);
|
|
376
|
+
}
|
|
377
|
+
let out = false;
|
|
378
|
+
for (let n = 1; n <= inside2.length && !out; n++) {
|
|
379
|
+
const group = inside2.slice(0, n);
|
|
380
|
+
const was = group.map((i) => at[i]);
|
|
381
|
+
for (const i of group) at[i] = at[i] - 1;
|
|
382
|
+
if (fitsWith(group)) out = true;
|
|
383
|
+
else group.forEach((i, k) => at[i] = was[k]);
|
|
384
|
+
}
|
|
385
|
+
if (!out) break;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
hold = idx.some(holds);
|
|
389
|
+
let cross = crossOf();
|
|
390
|
+
let overflow = 0;
|
|
391
|
+
const guard = 2 * items.reduce((s, it) => s + it.forms.length, 0) + 2;
|
|
392
|
+
for (let n = 0; n <= guard; n++) {
|
|
393
|
+
cross = crossOf();
|
|
394
|
+
let stepped = false;
|
|
395
|
+
for (const i of idx) {
|
|
396
|
+
if (!items[i].fixed && tooWide(i, cross) && canStep(i) && !isMenu(items[i].forms[nextOffered(i)])) {
|
|
397
|
+
step(i, nextOffered(i));
|
|
398
|
+
stepped = true;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (stepped) continue;
|
|
402
|
+
const over = minSum() - length;
|
|
403
|
+
if (over <= EPS) break;
|
|
404
|
+
const to = idx.map((i) => items[i].fixed ? -1 : stepTo(i));
|
|
405
|
+
if (hold) {
|
|
406
|
+
const variant = victim(
|
|
407
|
+
items,
|
|
408
|
+
idx.map((i) => to[i] >= 0 && sameKind(i, to[i]) ? to[i] : -1)
|
|
409
|
+
);
|
|
410
|
+
if (variant >= 0) step(variant, to[variant]);
|
|
411
|
+
else hold = false;
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
const pool = idx.map((i) => to[i] < 0 && !inMenu() && !items[i].fixed ? menuFormAfter(i) : -1);
|
|
415
|
+
const v = victim(
|
|
416
|
+
items,
|
|
417
|
+
idx.map((i) => to[i] >= 0 ? to[i] : pool[i])
|
|
418
|
+
);
|
|
419
|
+
if (v >= 0 && to[v] < 0) {
|
|
420
|
+
const batch = menuBatch(pool);
|
|
421
|
+
if (batch) {
|
|
422
|
+
const id = batches++;
|
|
423
|
+
for (const [i, j] of batch) step(i, j, id);
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
const w = v >= 0 && to[v] >= 0 ? v : victim(items, to);
|
|
428
|
+
if (w < 0) {
|
|
429
|
+
overflow = items.length > 0 ? over : 0;
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
step(w, to[w]);
|
|
433
|
+
}
|
|
434
|
+
cross = crossOf();
|
|
435
|
+
const menuSize = inMenu() ? menuMain(input) : 0;
|
|
436
|
+
const avail = Math.max(0, length - sp.start - sp.end - gapsOf() - menuSize);
|
|
437
|
+
const drawn = idx.filter((i) => !isMenu(form(i)));
|
|
438
|
+
const min = (i) => mainOf(form(i), hold && holds(i) ? "natural" : "min", cross);
|
|
439
|
+
const nat = (i) => Math.max(min(i), mainOf(form(i), "natural", cross));
|
|
440
|
+
const sumMin = drawn.reduce((s, i) => s + min(i), 0);
|
|
441
|
+
const sumNat = drawn.reduce((s, i) => s + nat(i), 0);
|
|
442
|
+
const size = /* @__PURE__ */ new Map();
|
|
443
|
+
if (sumNat <= avail + EPS) {
|
|
444
|
+
const growers = drawn.filter((i) => form(i).main.grows);
|
|
445
|
+
const spare = Math.max(0, avail - sumNat);
|
|
446
|
+
const weight = growers.reduce((s, i) => s + nat(i), 0);
|
|
447
|
+
for (const i of drawn) {
|
|
448
|
+
const share = growers.includes(i) ? weight > EPS ? nat(i) / weight : 1 / growers.length : 0;
|
|
449
|
+
size.set(i, nat(i) + spare * share);
|
|
450
|
+
}
|
|
451
|
+
} else {
|
|
452
|
+
const t = avail > sumMin && sumNat > sumMin ? (avail - sumMin) / (sumNat - sumMin) : 0;
|
|
453
|
+
for (const i of drawn) size.set(i, min(i) + (nat(i) - min(i)) * t);
|
|
454
|
+
}
|
|
455
|
+
const rectAt = (from, main, across = cross) => input.axis === "column" ? { x: 0, y: from, width: across, height: main } : { x: from, y: 0, width: main, height: across };
|
|
456
|
+
const acrossOf = (i) => {
|
|
457
|
+
const f = form(i);
|
|
458
|
+
if (input.ownCross !== true || !GROUP_KINDS.has(f.kind)) return cross;
|
|
459
|
+
if (f.wrap) return Math.min(cross, wrapRows(f.wrap, cross).width);
|
|
460
|
+
return Math.min(cross, Math.max(0, finite2(f.cross.natural, cross)));
|
|
461
|
+
};
|
|
462
|
+
const rects = /* @__PURE__ */ new Map();
|
|
463
|
+
let cursor = sp.start;
|
|
464
|
+
for (const i of drawn) {
|
|
465
|
+
const s = size.get(i);
|
|
466
|
+
rects.set(i, rectAt(cursor, s, acrossOf(i)));
|
|
467
|
+
cursor += s + sp.gap;
|
|
468
|
+
}
|
|
469
|
+
const menuRect = rectAt(Math.max(drawn.length > 0 ? cursor : sp.start, length - sp.end - menuSize), menuSize);
|
|
470
|
+
const inside = idx.filter((i) => isMenu(form(i)));
|
|
471
|
+
const menu = inside.length > 0 ? { rect: menuRect, items: inside.map((i) => items[i].id) } : null;
|
|
472
|
+
const placed = idx.map((i) => ({ id: items[i].id, form: at[i], kind: form(i).kind, rect: isMenu(form(i)) ? menuRect : rects.get(i) }));
|
|
473
|
+
const notes = [];
|
|
474
|
+
for (const it of input.items) if (it.forms.length === 0) notes.push({ code: "no-forms", id: it.id });
|
|
475
|
+
for (const i of firstStep) if (at[i] > start[i]) notes.push({ code: "form-down", id: items[i].id, from: start[i], to: at[i] });
|
|
476
|
+
for (const i of menuOrder) if (isMenu(form(i))) notes.push({ code: "to-menu", id: items[i].id });
|
|
477
|
+
for (const i of idx) if (tooWide(i, cross)) notes.push({ code: "too-wide", id: items[i].id });
|
|
478
|
+
if (overflow > EPS) notes.push({ code: "overflow", over: overflow });
|
|
479
|
+
return { axis: input.axis, length, cross, items: placed, menu, notes, need: minSumWith(false), steps: hist };
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/stack/ladder.ts
|
|
483
|
+
var nonNeg2 = (x) => typeof x === "number" && Number.isFinite(x) ? Math.max(0, x) : 0;
|
|
484
|
+
var RANK_TIER = 100;
|
|
485
|
+
var RANK_KEEP = 1e3;
|
|
486
|
+
function controlLadder(spec) {
|
|
487
|
+
const keep = Math.max(0, Number.isFinite(spec.keep) ? spec.keep : 0) * RANK_KEEP;
|
|
488
|
+
const cross = nonNeg2(spec.cross);
|
|
489
|
+
const grip = nonNeg2(spec.grip);
|
|
490
|
+
const gap = nonNeg2(spec.gap);
|
|
491
|
+
const more = nonNeg2(spec.more);
|
|
492
|
+
const column = spec.column ? [
|
|
493
|
+
{ kind: "icons", main: { min: nonNeg2(spec.column.icons), natural: nonNeg2(spec.column.icons) }, cross: { natural: nonNeg2(spec.column.cross ?? spec.cross) }, ...grip > 0 ? { grip } : {} },
|
|
494
|
+
{ kind: "menu", main: { min: 0, natural: 0 }, cross: { natural: 0 }, ...keep > 0 ? { rank: keep } : {} }
|
|
495
|
+
] : void 0;
|
|
496
|
+
const controls = spec.controls;
|
|
497
|
+
const n = controls.length;
|
|
498
|
+
if (n === 0) return { row: [], ...column ? { column } : {} };
|
|
499
|
+
const tierCount = Math.max(1, ...controls.map((c) => c.tiers.length));
|
|
500
|
+
const length = (c, tier) => nonNeg2(c.tiers[Math.min(tier, c.tiers.length - 1)]);
|
|
501
|
+
const order = controls.map((c, index) => ({ index, key: typeof c.foldOrder === "number" && Number.isFinite(c.foldOrder) ? c.foldOrder : index })).sort((a, b) => b.key - a.key || b.index - a.index).map((o) => o.index);
|
|
502
|
+
const ids = (hidden) => controls.filter((_, i) => hidden.has(i)).map((c) => c.id);
|
|
503
|
+
const form = (main, extra) => ({ main: { min: main, natural: main }, cross: { natural: cross }, ...grip > 0 ? { grip } : {}, ...extra });
|
|
504
|
+
const tierRank = (t, i) => t <= 2 ? RANK_TIER * t + i / n : 3 * RANK_TIER + (t - 3 + i / n) / (tierCount - 3);
|
|
505
|
+
const row = [];
|
|
506
|
+
const at = controls.map(() => 0);
|
|
507
|
+
const rowLength = (shown, extra) => shown.reduce((s, i) => s + length(controls[i], at[i]), 0) + Math.max(0, shown.length - 1) * gap + grip + extra;
|
|
508
|
+
const all = controls.map((_, i) => i);
|
|
509
|
+
const tiersOf = (shown) => Object.fromEntries(shown.map((i) => [controls[i].id, Math.min(at[i], Math.max(0, controls[i].tiers.length - 1))]));
|
|
510
|
+
row.push(form(rowLength(all, 0), { kind: "row", tiers: tiersOf(all) }));
|
|
511
|
+
for (let t = 1; t < tierCount; t++) {
|
|
512
|
+
for (let i = 0; i < n; i++) {
|
|
513
|
+
at[order[i]] = t;
|
|
514
|
+
row.push(form(rowLength(all, 0), { kind: "row", rank: tierRank(t, i), tiers: tiersOf(all) }));
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
for (let k = 1; k < n; k++) {
|
|
518
|
+
const hidden = new Set(order.slice(0, k));
|
|
519
|
+
const shown = all.filter((i) => !hidden.has(i));
|
|
520
|
+
row.push(form(rowLength(shown, more), { kind: "row", rank: 4 * RANK_TIER + k / n + keep, hides: ids(hidden), tiers: tiersOf(shown) }));
|
|
521
|
+
}
|
|
522
|
+
row.push(form(grip + more, { kind: "fold", rank: 5 * RANK_TIER + keep, hides: ids(new Set(all)) }));
|
|
523
|
+
row.push({ kind: "menu", main: { min: 0, natural: 0 }, cross: { natural: 0 }, rank: 6 * RANK_TIER + keep });
|
|
524
|
+
return { row, ...column ? { column } : {} };
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// src/stack/gaps.ts
|
|
528
|
+
function refusalOf(base, fit, dragged, fixed, axis, tooWideBefore) {
|
|
529
|
+
if (dragged.kind === "menu") return "to-menu";
|
|
530
|
+
for (const n of fit.notes) {
|
|
531
|
+
if (n.code === "overflow") return "overflow";
|
|
532
|
+
if (n.code === "too-wide" && !tooWideBefore.has(n.id)) return "too-wide";
|
|
533
|
+
}
|
|
534
|
+
const main = (r) => axis === "column" ? r.height : r.width;
|
|
535
|
+
const across = (r) => axis === "column" ? r.width : r.height;
|
|
536
|
+
const was = new Map(base.items.map((p) => [p.id, p]));
|
|
537
|
+
for (const p of fit.items) {
|
|
538
|
+
const item = fixed.get(p.id);
|
|
539
|
+
const q = was.get(p.id);
|
|
540
|
+
if (!item || !q || p.kind === "menu" || q.kind === "menu") continue;
|
|
541
|
+
if (p.form !== q.form) return "squeezes-fixed";
|
|
542
|
+
if (main(p.rect) < formMain(item.forms[p.form], "min", fit.cross) - 1e-6) return "squeezes-fixed";
|
|
543
|
+
if (across(p.rect) < across(q.rect) - 1e-6) return "squeezes-fixed";
|
|
544
|
+
}
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
function stackGaps(input, item, options = {}) {
|
|
548
|
+
const rest = { ...input, items: input.items.filter((it) => it.id !== item.id) };
|
|
549
|
+
const ats = Array.from({ length: rest.items.length + 1 }, (_, k) => k);
|
|
550
|
+
const whole = item.forms.length === 0 ? "no-forms" : item.fixed ? "fixed" : input.accepts && !input.accepts(item) ? "not-accepted" : null;
|
|
551
|
+
if (whole) return ats.map((at) => ({ at, fits: false, reason: whole }));
|
|
552
|
+
const fitOptions = options.previous ? { previous: options.previous } : {};
|
|
553
|
+
const base = fitStack(rest, fitOptions);
|
|
554
|
+
const fixed = new Map(rest.items.filter((it) => it.fixed).map((it) => [it.id, it]));
|
|
555
|
+
const tooWideBefore = new Set(base.notes.flatMap((n) => n.code === "too-wide" ? [n.id] : []));
|
|
556
|
+
const newest = rest.items.reduce((m, it) => Math.max(m, it.used), item.used) + 1;
|
|
557
|
+
const held = { ...item, used: newest };
|
|
558
|
+
return ats.map((at) => {
|
|
559
|
+
if (options.allows && !options.allows(item, at)) return { at, fits: false, reason: "not-allowed" };
|
|
560
|
+
const solved = withItem(rest, held, at);
|
|
561
|
+
const fit = fitStack(solved, fitOptions);
|
|
562
|
+
const placed = fit.items.find((p) => p.id === item.id);
|
|
563
|
+
const reason = refusalOf(base, fit, placed, fixed, rest.axis, tooWideBefore);
|
|
564
|
+
return reason ? { at, fits: false, reason } : { at, fits: true, input: solved, fit, slot: placed.rect };
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// src/stack/float-fit.ts
|
|
569
|
+
var EPS2 = 1e-3;
|
|
570
|
+
var finite3 = (x, fallback) => Number.isFinite(x) ? x : fallback;
|
|
571
|
+
var clean = (r, at) => rect(finite3(r.x, at.x), finite3(r.y, at.y), Math.max(0, finite3(r.width, 0)), Math.max(0, finite3(r.height, 0)));
|
|
572
|
+
var WORK = 3e6;
|
|
573
|
+
var COVERED_PLACES = 2048;
|
|
574
|
+
var Nearest = class {
|
|
575
|
+
h = [];
|
|
576
|
+
less(a, b) {
|
|
577
|
+
return a[2] !== b[2] ? a[2] < b[2] : a[0] !== b[0] ? a[0] < b[0] : a[1] < b[1];
|
|
578
|
+
}
|
|
579
|
+
get size() {
|
|
580
|
+
return this.h.length;
|
|
581
|
+
}
|
|
582
|
+
push(t) {
|
|
583
|
+
const h = this.h;
|
|
584
|
+
let i = h.push(t) - 1;
|
|
585
|
+
while (i > 0) {
|
|
586
|
+
const p = i - 1 >> 1;
|
|
587
|
+
if (!this.less(h[i], h[p])) break;
|
|
588
|
+
[h[i], h[p]] = [h[p], h[i]];
|
|
589
|
+
i = p;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
pop() {
|
|
593
|
+
const h = this.h;
|
|
594
|
+
const top = h[0];
|
|
595
|
+
const last = h.pop();
|
|
596
|
+
if (h.length > 0) {
|
|
597
|
+
h[0] = last;
|
|
598
|
+
let i = 0;
|
|
599
|
+
for (; ; ) {
|
|
600
|
+
const l = 2 * i + 1;
|
|
601
|
+
const r = l + 1;
|
|
602
|
+
let m = i;
|
|
603
|
+
if (l < h.length && this.less(h[l], h[m])) m = l;
|
|
604
|
+
if (r < h.length && this.less(h[r], h[m])) m = r;
|
|
605
|
+
if (m === i) break;
|
|
606
|
+
[h[i], h[m]] = [h[m], h[i]];
|
|
607
|
+
i = m;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
return top;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
function* byDistance(xs, ys, fx, fy) {
|
|
614
|
+
const sx = [...xs].sort((a, b) => Math.abs(a - fx) - Math.abs(b - fx) || a - b);
|
|
615
|
+
const sy = [...ys].sort((a, b) => Math.abs(a - fy) - Math.abs(b - fy) || a - b);
|
|
616
|
+
const q = new Nearest();
|
|
617
|
+
const d = (i, j) => Math.hypot(sx[i] - fx, sy[j] - fy);
|
|
618
|
+
if (sy.length > 0) for (let i = 0; i < sx.length; i++) q.push([i, 0, d(i, 0)]);
|
|
619
|
+
while (q.size > 0) {
|
|
620
|
+
const [i, j, far] = q.pop();
|
|
621
|
+
yield { x: sx[i], y: sy[j], far };
|
|
622
|
+
if (j + 1 < sy.length) q.push([i, j + 1, d(i, j + 1)]);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
function fitFloat(want, stage, avoid = []) {
|
|
626
|
+
const area = clean(stage, rect(0, 0, 0, 0));
|
|
627
|
+
const r = clean(want, area);
|
|
628
|
+
const inside = clampInto(r, area);
|
|
629
|
+
const clamped = inside.x !== want.x || inside.y !== want.y;
|
|
630
|
+
const reach = rect(area.x, area.y, Math.max(area.width, r.width), Math.max(area.height, r.height));
|
|
631
|
+
const near = [];
|
|
632
|
+
avoid.forEach((a, index) => {
|
|
633
|
+
const at = clean(a, area);
|
|
634
|
+
if (at.width > EPS2 && at.height > EPS2 && overlaps(at, reach, EPS2)) near.push({ at, index });
|
|
635
|
+
});
|
|
636
|
+
const under = (cand) => near.filter((n) => overlaps(cand, n.at, EPS2)).map((n) => n.index);
|
|
637
|
+
const blocked = (cand) => near.some((n) => overlaps(cand, n.at, EPS2));
|
|
638
|
+
if (!blocked(inside)) return { rect: inside, clamped, snapped: false, covers: [], searchCapped: false };
|
|
639
|
+
const lo = (v, from, to) => Math.min(Math.max(v, from), Math.max(from, to));
|
|
640
|
+
const xs = [inside.x, area.x, area.x + area.width - r.width];
|
|
641
|
+
const ys = [inside.y, area.y, area.y + area.height - r.height];
|
|
642
|
+
for (const { at } of near) {
|
|
643
|
+
xs.push(at.x - r.width, at.x + at.width);
|
|
644
|
+
ys.push(at.y - r.height, at.y + at.height);
|
|
645
|
+
}
|
|
646
|
+
const places = (list, from, size, extent) => [...new Set(list.map((v) => lo(v, from, from + extent - size)))];
|
|
647
|
+
const px2 = places(xs, area.x, r.width, area.width);
|
|
648
|
+
const py = places(ys, area.y, r.height, area.height);
|
|
649
|
+
const ylo = area.y;
|
|
650
|
+
const yhi = Math.max(area.y, area.y + area.height - r.height);
|
|
651
|
+
const byX = [...px2].sort((a, b) => Math.abs(a - inside.x) - Math.abs(b - inside.x) || a - b);
|
|
652
|
+
let clear = null;
|
|
653
|
+
let work = 0;
|
|
654
|
+
let searchCapped = false;
|
|
655
|
+
for (const x of byX) {
|
|
656
|
+
const dx = Math.abs(x - inside.x);
|
|
657
|
+
if (clear && dx >= clear.far) break;
|
|
658
|
+
work += near.length + 1;
|
|
659
|
+
if (work > WORK) {
|
|
660
|
+
searchCapped = true;
|
|
661
|
+
break;
|
|
662
|
+
}
|
|
663
|
+
const stretches = [];
|
|
664
|
+
for (const { at } of near) {
|
|
665
|
+
if (Math.min(x + r.width, at.x + at.width) - Math.max(x, at.x) > EPS2) stretches.push([at.y - r.height, at.y + at.height]);
|
|
666
|
+
}
|
|
667
|
+
stretches.sort((a, b) => a[0] - b[0]);
|
|
668
|
+
let cursor = ylo;
|
|
669
|
+
let bestY = null;
|
|
670
|
+
const gap = (from, to) => {
|
|
671
|
+
if (from > to) return;
|
|
672
|
+
const y = Math.min(Math.max(inside.y, from), to);
|
|
673
|
+
if (bestY === null || Math.abs(y - inside.y) < Math.abs(bestY - inside.y)) bestY = y;
|
|
674
|
+
};
|
|
675
|
+
for (const [a, b] of stretches) {
|
|
676
|
+
gap(cursor, Math.min(a, yhi));
|
|
677
|
+
cursor = Math.max(cursor, b);
|
|
678
|
+
if (cursor > yhi) break;
|
|
679
|
+
}
|
|
680
|
+
if (cursor <= yhi) gap(cursor, yhi);
|
|
681
|
+
if (bestY === null) continue;
|
|
682
|
+
const far = Math.hypot(dx, bestY - inside.y);
|
|
683
|
+
if (!clear || far < clear.far) clear = { x, y: bestY, far };
|
|
684
|
+
}
|
|
685
|
+
if (clear) return { rect: rect(clear.x, clear.y, r.width, r.height), clamped, snapped: clear.far > EPS2, covers: [], searchCapped };
|
|
686
|
+
let best = null;
|
|
687
|
+
let tried = 0;
|
|
688
|
+
for (const p of byDistance(px2, py, inside.x, inside.y)) {
|
|
689
|
+
if (tried++ >= COVERED_PLACES) break;
|
|
690
|
+
const cand = rect(p.x, p.y, r.width, r.height);
|
|
691
|
+
const left = near.reduce((s, n) => s + overlap(cand, n.at), 0);
|
|
692
|
+
if (!best || left < best.left - EPS2) best = { rect: cand, left, far: p.far, hits: under(cand) };
|
|
693
|
+
}
|
|
694
|
+
const out = best ?? { rect: inside, far: 0, hits: under(inside) };
|
|
695
|
+
return { rect: out.rect, clamped, snapped: out.far > EPS2, covers: out.hits, searchCapped };
|
|
696
|
+
}
|
|
23
697
|
export {
|
|
24
698
|
DEFAULT_MENU,
|
|
25
699
|
DEFAULT_RAIL,
|
|
26
|
-
|
|
700
|
+
controlLadder,
|
|
701
|
+
cutEdges,
|
|
27
702
|
fitFloat,
|
|
28
703
|
fitStack,
|
|
704
|
+
formBody,
|
|
705
|
+
formCompact,
|
|
29
706
|
formCrossMin,
|
|
30
707
|
formFitsCross,
|
|
708
|
+
formFolded,
|
|
31
709
|
formMain,
|
|
32
710
|
formSetsCross,
|
|
33
|
-
|
|
34
|
-
readStack,
|
|
35
|
-
stackFloatTarget,
|
|
36
|
-
stackTargets,
|
|
37
|
-
storeFloats,
|
|
38
|
-
storeStack,
|
|
711
|
+
stackGaps,
|
|
39
712
|
withItem,
|
|
40
713
|
wrapCross,
|
|
41
714
|
wrapLines,
|