@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/chunk-AE3BWTAE.js
DELETED
|
@@ -1,838 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EPS,
|
|
3
|
-
PLANE,
|
|
4
|
-
clampInto,
|
|
5
|
-
overlap,
|
|
6
|
-
overlaps,
|
|
7
|
-
rect
|
|
8
|
-
} from "./chunk-VLTYJHUA.js";
|
|
9
|
-
|
|
10
|
-
// src/stack/model.ts
|
|
11
|
-
var nonNeg = (x) => typeof x === "number" && Number.isFinite(x) ? Math.max(0, x) : 0;
|
|
12
|
-
function formCrossMin(f) {
|
|
13
|
-
if (f.wrap) return wrapCross(f.wrap).min;
|
|
14
|
-
const v = f.cross.min ?? f.cross.natural;
|
|
15
|
-
return Number.isFinite(v) ? v : 0;
|
|
16
|
-
}
|
|
17
|
-
function formMain(f, which, cross) {
|
|
18
|
-
if (f.kind === "menu") return 0;
|
|
19
|
-
if (f.wrap) return wrapRows(f.wrap, cross).rows * nonNeg(f.wrap.row);
|
|
20
|
-
return nonNeg(f.main[which]);
|
|
21
|
-
}
|
|
22
|
-
function formFitsCross(f, cross) {
|
|
23
|
-
if (!f.wrap) return true;
|
|
24
|
-
const widest = Math.max(0, ...f.wrap.widths.map(nonNeg));
|
|
25
|
-
return cross + 1e-6 >= nonNeg(f.wrap.lead) + widest && wrapLines(f.wrap, cross).fits;
|
|
26
|
-
}
|
|
27
|
-
function rowWidths(spec) {
|
|
28
|
-
const gap = nonNeg(spec.gap);
|
|
29
|
-
const lead = nonNeg(spec.lead);
|
|
30
|
-
const widths = spec.widths.map(nonNeg);
|
|
31
|
-
const out = [];
|
|
32
|
-
for (let i = 0; i < widths.length; i++) {
|
|
33
|
-
let run = 0;
|
|
34
|
-
for (let j = i; j < widths.length; j++) {
|
|
35
|
-
run += widths[j] + (j > i ? gap : 0);
|
|
36
|
-
out.push(lead + run);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return out.sort((a, b) => a - b);
|
|
40
|
-
}
|
|
41
|
-
function wrapLines(spec, cross) {
|
|
42
|
-
const g = greedyLines(spec, cross);
|
|
43
|
-
if (g.fits) return g;
|
|
44
|
-
const narrower = rowWidths(spec).filter((c) => c <= cross + 1e-6);
|
|
45
|
-
for (let i = narrower.length - 1; i >= 0; i--) {
|
|
46
|
-
const h = greedyLines(spec, narrower[i]);
|
|
47
|
-
if (h.fits) return h;
|
|
48
|
-
}
|
|
49
|
-
return g;
|
|
50
|
-
}
|
|
51
|
-
function greedyLines(spec, cross) {
|
|
52
|
-
const gap = nonNeg(spec.gap);
|
|
53
|
-
const lead = nonNeg(spec.lead);
|
|
54
|
-
const widths = spec.widths.map(nonNeg);
|
|
55
|
-
if (widths.length === 0) return { lines: [], width: lead, fits: true };
|
|
56
|
-
const box = cross - lead;
|
|
57
|
-
const lines = [[]];
|
|
58
|
-
let x = 0;
|
|
59
|
-
let widest = 0;
|
|
60
|
-
widths.forEach((w, i) => {
|
|
61
|
-
const row = lines[lines.length - 1];
|
|
62
|
-
if (row.length > 0 && x + gap + w > box + 1e-6) {
|
|
63
|
-
widest = Math.max(widest, x);
|
|
64
|
-
lines.push([i]);
|
|
65
|
-
x = w;
|
|
66
|
-
} else {
|
|
67
|
-
x = row.length > 0 ? x + gap + w : w;
|
|
68
|
-
row.push(i);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
widest = Math.max(widest, x);
|
|
72
|
-
const fits = widths.length < 2 || lines.slice(0, -1).every((l) => l.length >= 2);
|
|
73
|
-
return { lines, width: lead + widest, fits };
|
|
74
|
-
}
|
|
75
|
-
function wrapRows(spec, cross) {
|
|
76
|
-
const w = wrapLines(spec, cross);
|
|
77
|
-
return { rows: Math.max(1, w.lines.length), width: w.width, fits: w.fits };
|
|
78
|
-
}
|
|
79
|
-
function wrapCross(spec) {
|
|
80
|
-
const gap = nonNeg(spec.gap);
|
|
81
|
-
const lead = nonNeg(spec.lead);
|
|
82
|
-
const widths = spec.widths.map(nonNeg);
|
|
83
|
-
const natural = lead + widths.reduce((s, w) => s + w, 0) + Math.max(0, widths.length - 1) * gap;
|
|
84
|
-
if (widths.length < 2) return { natural, min: natural };
|
|
85
|
-
const first = rowWidths(spec).find((c) => greedyLines(spec, c).fits) ?? natural;
|
|
86
|
-
const min = Math.max(lead + Math.max(...widths), first);
|
|
87
|
-
return { natural, min };
|
|
88
|
-
}
|
|
89
|
-
var DEFAULT_RAIL = 30;
|
|
90
|
-
var DEFAULT_MENU = 28;
|
|
91
|
-
var finite = (x, fallback) => Number.isFinite(x) ? x : fallback;
|
|
92
|
-
function limitsOf(input) {
|
|
93
|
-
const min = Math.max(0, finite(input.cross.min, 0));
|
|
94
|
-
const max = Number.isNaN(input.cross.max) ? Infinity : input.cross.max;
|
|
95
|
-
return { min, max: Math.max(min, max), rail: Math.max(0, finite(input.cross.rail ?? DEFAULT_RAIL, DEFAULT_RAIL)) };
|
|
96
|
-
}
|
|
97
|
-
var menuMain = (input) => Math.max(0, finite(input.menu?.main ?? DEFAULT_MENU, DEFAULT_MENU));
|
|
98
|
-
function spacingOf(input) {
|
|
99
|
-
const px = (x) => Math.max(0, finite(x ?? 0, 0));
|
|
100
|
-
return { gap: px(input.gap), start: px(input.pad?.start), end: px(input.pad?.end) };
|
|
101
|
-
}
|
|
102
|
-
var formSetsCross = (f) => f.setsCross ?? f.kind === "open";
|
|
103
|
-
function withItem(input, item, at) {
|
|
104
|
-
const k = Math.min(Math.max(0, Math.floor(at)), input.items.length);
|
|
105
|
-
return { ...input, items: [...input.items.slice(0, k), item, ...input.items.slice(k)] };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// src/stack/layout.ts
|
|
109
|
-
var isMenu = (f) => f.kind === "menu";
|
|
110
|
-
var GROUP_KINDS = /* @__PURE__ */ new Set(["row", "stacked", "wrap", "icons", "fold"]);
|
|
111
|
-
var finite2 = (x, fallback = 0) => Number.isFinite(x) ? x : fallback;
|
|
112
|
-
var mainOf = formMain;
|
|
113
|
-
var crossMin = formCrossMin;
|
|
114
|
-
var crossNatural = (f) => f.wrap ? wrapCross(f.wrap).natural : finite2(f.cross.natural);
|
|
115
|
-
var rankOf = (f) => finite2(f.rank ?? 0);
|
|
116
|
-
function victim(items, to) {
|
|
117
|
-
let best = -1;
|
|
118
|
-
for (let i = 0; i < items.length; i++) {
|
|
119
|
-
if (to[i] < 0 || items[i].fixed) continue;
|
|
120
|
-
if (best < 0) {
|
|
121
|
-
best = i;
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
const a = items[i];
|
|
125
|
-
const b = items[best];
|
|
126
|
-
const ra = rankOf(a.forms[to[i]]);
|
|
127
|
-
const rb = rankOf(b.forms[to[best]]);
|
|
128
|
-
const ka = a.kept ? 1 : 0;
|
|
129
|
-
const kb = b.kept ? 1 : 0;
|
|
130
|
-
if (ra !== rb ? ra < rb : ka !== kb ? ka < kb : a.used !== b.used ? a.used < b.used : true) best = i;
|
|
131
|
-
}
|
|
132
|
-
return best;
|
|
133
|
-
}
|
|
134
|
-
function fitStack(input, options = {}) {
|
|
135
|
-
const fresh = solve(input);
|
|
136
|
-
const previous = options.previous;
|
|
137
|
-
if (!previous || previous.need === void 0) return fresh;
|
|
138
|
-
const seed = { need: 0 };
|
|
139
|
-
const kept = solve(input, previous, seed);
|
|
140
|
-
if (kept.cross > previous.cross + EPS) return fresh;
|
|
141
|
-
const moreLength = Math.max(0, kept.length) - seed.need > previous.length - previous.need + EPS;
|
|
142
|
-
if (!moreLength) return kept;
|
|
143
|
-
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);
|
|
144
|
-
return gain ? fresh : solve(input, previous, { need: 0 }, true);
|
|
145
|
-
}
|
|
146
|
-
function solve(input, previous, seed, grow = false) {
|
|
147
|
-
const length = Math.max(0, finite2(input.length));
|
|
148
|
-
const lim = limitsOf(input);
|
|
149
|
-
const items = input.items.filter((it) => it.forms.length > 0);
|
|
150
|
-
const offered = (f) => f.title !== true || input.titles === true;
|
|
151
|
-
const offeredFrom = (it, j) => {
|
|
152
|
-
for (let k = j; k < it.forms.length; k++) if (offered(it.forms[k])) return k;
|
|
153
|
-
return j;
|
|
154
|
-
};
|
|
155
|
-
const start = items.map((it) => offeredFrom(it, Math.min(Math.max(0, Math.floor(finite2(it.from ?? 0))), it.forms.length - 1)));
|
|
156
|
-
const at = [...start];
|
|
157
|
-
if (previous) {
|
|
158
|
-
const had = new Map(previous.items.map((p) => [p.id, p]));
|
|
159
|
-
const began = /* @__PURE__ */ new Map();
|
|
160
|
-
for (const n of previous.notes) if (n.code === "form-down" && !began.has(n.id)) began.set(n.id, n.from);
|
|
161
|
-
items.forEach((it, i) => {
|
|
162
|
-
const p = had.get(it.id);
|
|
163
|
-
if (it.fixed || !p || p.form < start[i] || p.form >= it.forms.length || start[i] < (began.get(it.id) ?? p.form)) return;
|
|
164
|
-
const f = it.forms[p.form];
|
|
165
|
-
if (f.kind === p.kind && offered(f)) at[i] = p.form;
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
const form = (i) => items[i].forms[at[i]];
|
|
169
|
-
const idx = items.map((_, i) => i);
|
|
170
|
-
const hist = [];
|
|
171
|
-
const withHistory = /* @__PURE__ */ new Set();
|
|
172
|
-
let batches = 0;
|
|
173
|
-
if (previous?.steps) {
|
|
174
|
-
const byId = new Map(items.map((it, i) => [it.id, i]));
|
|
175
|
-
const ends = /* @__PURE__ */ new Map();
|
|
176
|
-
const good = new Set(items.map((it) => it.id));
|
|
177
|
-
for (const s of previous.steps) {
|
|
178
|
-
const i = byId.get(s.id);
|
|
179
|
-
if (i === void 0) continue;
|
|
180
|
-
if (s.from !== (ends.get(s.id) ?? start[i])) good.delete(s.id);
|
|
181
|
-
ends.set(s.id, s.to);
|
|
182
|
-
}
|
|
183
|
-
items.forEach((it, i) => {
|
|
184
|
-
if ((ends.get(it.id) ?? start[i]) !== at[i]) good.delete(it.id);
|
|
185
|
-
});
|
|
186
|
-
for (const s of previous.steps) if (good.has(s.id) && byId.has(s.id)) hist.push(s);
|
|
187
|
-
for (const s of hist) {
|
|
188
|
-
withHistory.add(s.id);
|
|
189
|
-
if (s.batch !== void 0) batches = Math.max(batches, s.batch + 1);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
const firstStep = [];
|
|
193
|
-
const menuOrder = [];
|
|
194
|
-
const step = (i, j, batch) => {
|
|
195
|
-
if (!firstStep.includes(i)) firstStep.push(i);
|
|
196
|
-
hist.push({ id: items[i].id, from: at[i], to: j, ...batch !== void 0 ? { batch } : {} });
|
|
197
|
-
withHistory.add(items[i].id);
|
|
198
|
-
at[i] = j;
|
|
199
|
-
if (isMenu(form(i)) && !menuOrder.includes(i)) menuOrder.push(i);
|
|
200
|
-
};
|
|
201
|
-
const named = (code) => previous ? previous.notes.filter((n) => n.code === code).map((n) => items.findIndex((it) => it.id === n.id)) : [];
|
|
202
|
-
for (const i of [...named("form-down"), ...idx]) if (i >= 0 && at[i] > start[i] && !firstStep.includes(i)) firstStep.push(i);
|
|
203
|
-
for (const i of [...named("to-menu"), ...idx]) if (i >= 0 && isMenu(form(i)) && !menuOrder.includes(i)) menuOrder.push(i);
|
|
204
|
-
const crossOf = () => {
|
|
205
|
-
const setters = idx.filter((i) => !isMenu(form(i)) && formSetsCross(form(i)));
|
|
206
|
-
if (setters.length === 0) return lim.rail;
|
|
207
|
-
const want = Math.max(...setters.map((i) => crossNatural(form(i))));
|
|
208
|
-
return Math.min(Math.max(want, lim.min), lim.max);
|
|
209
|
-
};
|
|
210
|
-
const inMenu = () => idx.some((i) => isMenu(form(i)));
|
|
211
|
-
const sp = spacingOf(input);
|
|
212
|
-
const gapsOf = () => {
|
|
213
|
-
const slots = idx.filter((i) => !isMenu(form(i))).length + (inMenu() ? 1 : 0);
|
|
214
|
-
return slots > 1 ? (slots - 1) * sp.gap : 0;
|
|
215
|
-
};
|
|
216
|
-
const holds = (i) => items[i].fixed === true && form(i).main.grows === true;
|
|
217
|
-
let hold = idx.some(holds);
|
|
218
|
-
const minSumWith = (held) => {
|
|
219
|
-
const c = items.some((it) => it.forms.some((f) => f.wrap)) ? crossOf() : 0;
|
|
220
|
-
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;
|
|
221
|
-
};
|
|
222
|
-
const minSum = () => minSumWith(hold);
|
|
223
|
-
const sameKind = (i, j) => items[i].forms[j].kind === form(i).kind;
|
|
224
|
-
const stepTo = (i) => {
|
|
225
|
-
const from = at[i];
|
|
226
|
-
const base = minSum();
|
|
227
|
-
let found = -1;
|
|
228
|
-
for (let j = from + 1; j < items[i].forms.length && found < 0; j++) {
|
|
229
|
-
if (!offered(items[i].forms[j])) continue;
|
|
230
|
-
at[i] = j;
|
|
231
|
-
if (minSum() < base - EPS) found = j;
|
|
232
|
-
}
|
|
233
|
-
at[i] = from;
|
|
234
|
-
return found;
|
|
235
|
-
};
|
|
236
|
-
const menuFormAfter = (i) => {
|
|
237
|
-
for (let j = at[i] + 1; j < items[i].forms.length; j++) if (isMenu(items[i].forms[j])) return j;
|
|
238
|
-
return -1;
|
|
239
|
-
};
|
|
240
|
-
const menuBatch = (pool) => {
|
|
241
|
-
const saved = [...at];
|
|
242
|
-
const base = minSum();
|
|
243
|
-
const left = [...pool];
|
|
244
|
-
const batch = [];
|
|
245
|
-
let found = false;
|
|
246
|
-
for (let b = victim(items, left); b >= 0 && !found; b = victim(items, left)) {
|
|
247
|
-
batch.push([b, left[b]]);
|
|
248
|
-
at[b] = left[b];
|
|
249
|
-
left[b] = -1;
|
|
250
|
-
found = minSum() < base - EPS;
|
|
251
|
-
}
|
|
252
|
-
at.splice(0, at.length, ...saved);
|
|
253
|
-
return found ? batch : null;
|
|
254
|
-
};
|
|
255
|
-
const nextOffered = (i) => {
|
|
256
|
-
for (let j = at[i] + 1; j < items[i].forms.length; j++) if (offered(items[i].forms[j])) return j;
|
|
257
|
-
return -1;
|
|
258
|
-
};
|
|
259
|
-
const canStep = (i) => nextOffered(i) >= 0;
|
|
260
|
-
const tooWide = (i, cross2) => {
|
|
261
|
-
const f = form(i);
|
|
262
|
-
if (isMenu(f)) return false;
|
|
263
|
-
if (formSetsCross(f)) return input.strictCross === true && crossMin(f) > lim.max + EPS;
|
|
264
|
-
if (f.wrap) return !formFitsCross(f, cross2);
|
|
265
|
-
return crossMin(f) > cross2 + EPS;
|
|
266
|
-
};
|
|
267
|
-
if (seed) seed.need = minSumWith(false);
|
|
268
|
-
if (grow) {
|
|
269
|
-
const comesBefore = (a, b) => {
|
|
270
|
-
const ra = rankOf(items[a].forms[at[a]]);
|
|
271
|
-
const rb = rankOf(items[b].forms[at[b]]);
|
|
272
|
-
const ka = items[a].kept ? 1 : 0;
|
|
273
|
-
const kb = items[b].kept ? 1 : 0;
|
|
274
|
-
return ra !== rb ? ra > rb : ka !== kb ? ka > kb : items[a].used !== items[b].used ? items[a].used > items[b].used : a < b;
|
|
275
|
-
};
|
|
276
|
-
const index = new Map(items.map((it, i) => [it.id, i]));
|
|
277
|
-
let stuck = false;
|
|
278
|
-
const undoes = (n, c0) => {
|
|
279
|
-
const group = hist.slice(hist.length - n);
|
|
280
|
-
const changed = [...new Set(group.map((s) => index.get(s.id)))];
|
|
281
|
-
const was = changed.map((i) => at[i]);
|
|
282
|
-
const forms = (s) => items[index.get(s.id)].forms;
|
|
283
|
-
hold = group.every((s) => forms(s)[s.from].kind === forms(s)[s.to].kind) && idx.some(holds);
|
|
284
|
-
for (const s of [...group].reverse()) at[index.get(s.id)] = s.from;
|
|
285
|
-
if (minSum() <= length + EPS && crossOf() === c0 && changed.every((j) => !tooWide(j, c0))) return true;
|
|
286
|
-
changed.forEach((i, k) => at[i] = was[k]);
|
|
287
|
-
return false;
|
|
288
|
-
};
|
|
289
|
-
while (hist.length > 0) {
|
|
290
|
-
const c0 = crossOf();
|
|
291
|
-
const last = hist[hist.length - 1];
|
|
292
|
-
let n = 1;
|
|
293
|
-
if (last.batch !== void 0) while (n < hist.length && hist[hist.length - 1 - n].batch === last.batch) n++;
|
|
294
|
-
let took = 0;
|
|
295
|
-
for (let m = n; m <= hist.length && took === 0; m++) {
|
|
296
|
-
if (m > n && (last.batch !== void 0 || hist[hist.length - m].id !== last.id)) break;
|
|
297
|
-
if (undoes(m, c0)) took = m;
|
|
298
|
-
}
|
|
299
|
-
if (took === 0) {
|
|
300
|
-
stuck = true;
|
|
301
|
-
break;
|
|
302
|
-
}
|
|
303
|
-
hist.length -= took;
|
|
304
|
-
}
|
|
305
|
-
hold = false;
|
|
306
|
-
for (; ; ) {
|
|
307
|
-
if (stuck) break;
|
|
308
|
-
const c0 = crossOf();
|
|
309
|
-
const fitsWith = (changed) => minSum() <= length + EPS && crossOf() === c0 && changed.every((j) => !tooWide(j, c0));
|
|
310
|
-
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);
|
|
311
|
-
const next = queue[0];
|
|
312
|
-
if (next === void 0) break;
|
|
313
|
-
const cur = at[next];
|
|
314
|
-
let to = -1;
|
|
315
|
-
for (let k = cur - 1; k >= start[next] && to < 0; k--) {
|
|
316
|
-
if (!offered(items[next].forms[k])) continue;
|
|
317
|
-
at[next] = k;
|
|
318
|
-
if (fitsWith([next])) to = k;
|
|
319
|
-
}
|
|
320
|
-
at[next] = cur;
|
|
321
|
-
if (to >= 0) {
|
|
322
|
-
at[next] = to;
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
const inside2 = [];
|
|
326
|
-
for (const [q, i] of queue.entries()) {
|
|
327
|
-
if (!isMenu(form(i))) continue;
|
|
328
|
-
const ahead = queue.slice(0, q);
|
|
329
|
-
if (!ahead.every((j) => isMenu(form(j)) || at[i] - 1 - start[i] >= at[j] - start[j] && rankOf(form(i)) >= rankOf(form(j)))) break;
|
|
330
|
-
inside2.push(i);
|
|
331
|
-
}
|
|
332
|
-
let out = false;
|
|
333
|
-
for (let n = 1; n <= inside2.length && !out; n++) {
|
|
334
|
-
const group = inside2.slice(0, n);
|
|
335
|
-
const was = group.map((i) => at[i]);
|
|
336
|
-
for (const i of group) at[i] = at[i] - 1;
|
|
337
|
-
if (fitsWith(group)) out = true;
|
|
338
|
-
else group.forEach((i, k) => at[i] = was[k]);
|
|
339
|
-
}
|
|
340
|
-
if (!out) break;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
hold = idx.some(holds);
|
|
344
|
-
let cross = crossOf();
|
|
345
|
-
let overflow = 0;
|
|
346
|
-
const guard = 2 * items.reduce((s, it) => s + it.forms.length, 0) + 2;
|
|
347
|
-
for (let n = 0; n <= guard; n++) {
|
|
348
|
-
cross = crossOf();
|
|
349
|
-
let stepped = false;
|
|
350
|
-
for (const i of idx) {
|
|
351
|
-
if (!items[i].fixed && tooWide(i, cross) && canStep(i) && !isMenu(items[i].forms[nextOffered(i)])) {
|
|
352
|
-
step(i, nextOffered(i));
|
|
353
|
-
stepped = true;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (stepped) continue;
|
|
357
|
-
const over = minSum() - length;
|
|
358
|
-
if (over <= EPS) break;
|
|
359
|
-
const to = idx.map((i) => items[i].fixed ? -1 : stepTo(i));
|
|
360
|
-
if (hold) {
|
|
361
|
-
const variant = victim(
|
|
362
|
-
items,
|
|
363
|
-
idx.map((i) => to[i] >= 0 && sameKind(i, to[i]) ? to[i] : -1)
|
|
364
|
-
);
|
|
365
|
-
if (variant >= 0) step(variant, to[variant]);
|
|
366
|
-
else hold = false;
|
|
367
|
-
continue;
|
|
368
|
-
}
|
|
369
|
-
const pool = idx.map((i) => to[i] < 0 && !inMenu() && !items[i].fixed ? menuFormAfter(i) : -1);
|
|
370
|
-
const v = victim(
|
|
371
|
-
items,
|
|
372
|
-
idx.map((i) => to[i] >= 0 ? to[i] : pool[i])
|
|
373
|
-
);
|
|
374
|
-
if (v >= 0 && to[v] < 0) {
|
|
375
|
-
const batch = menuBatch(pool);
|
|
376
|
-
if (batch) {
|
|
377
|
-
const id = batches++;
|
|
378
|
-
for (const [i, j] of batch) step(i, j, id);
|
|
379
|
-
continue;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
const w = v >= 0 && to[v] >= 0 ? v : victim(items, to);
|
|
383
|
-
if (w < 0) {
|
|
384
|
-
overflow = items.length > 0 ? over : 0;
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
step(w, to[w]);
|
|
388
|
-
}
|
|
389
|
-
cross = crossOf();
|
|
390
|
-
const menuSize = inMenu() ? menuMain(input) : 0;
|
|
391
|
-
const avail = Math.max(0, length - sp.start - sp.end - gapsOf() - menuSize);
|
|
392
|
-
const drawn = idx.filter((i) => !isMenu(form(i)));
|
|
393
|
-
const min = (i) => mainOf(form(i), hold && holds(i) ? "natural" : "min", cross);
|
|
394
|
-
const nat = (i) => Math.max(min(i), mainOf(form(i), "natural", cross));
|
|
395
|
-
const sumMin = drawn.reduce((s, i) => s + min(i), 0);
|
|
396
|
-
const sumNat = drawn.reduce((s, i) => s + nat(i), 0);
|
|
397
|
-
const size = /* @__PURE__ */ new Map();
|
|
398
|
-
if (sumNat <= avail + EPS) {
|
|
399
|
-
const growers = drawn.filter((i) => form(i).main.grows);
|
|
400
|
-
const spare = Math.max(0, avail - sumNat);
|
|
401
|
-
const weight = growers.reduce((s, i) => s + nat(i), 0);
|
|
402
|
-
for (const i of drawn) {
|
|
403
|
-
const share = growers.includes(i) ? weight > EPS ? nat(i) / weight : 1 / growers.length : 0;
|
|
404
|
-
size.set(i, nat(i) + spare * share);
|
|
405
|
-
}
|
|
406
|
-
} else {
|
|
407
|
-
const t = avail > sumMin && sumNat > sumMin ? (avail - sumMin) / (sumNat - sumMin) : 0;
|
|
408
|
-
for (const i of drawn) size.set(i, min(i) + (nat(i) - min(i)) * t);
|
|
409
|
-
}
|
|
410
|
-
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 };
|
|
411
|
-
const acrossOf = (i) => {
|
|
412
|
-
const f = form(i);
|
|
413
|
-
if (input.ownCross !== true || !GROUP_KINDS.has(f.kind)) return cross;
|
|
414
|
-
if (f.wrap) return Math.min(cross, wrapRows(f.wrap, cross).width);
|
|
415
|
-
return Math.min(cross, Math.max(0, finite2(f.cross.natural, cross)));
|
|
416
|
-
};
|
|
417
|
-
const rects = /* @__PURE__ */ new Map();
|
|
418
|
-
let cursor = sp.start;
|
|
419
|
-
for (const i of drawn) {
|
|
420
|
-
const s = size.get(i);
|
|
421
|
-
rects.set(i, rectAt(cursor, s, acrossOf(i)));
|
|
422
|
-
cursor += s + sp.gap;
|
|
423
|
-
}
|
|
424
|
-
const menuRect = rectAt(Math.max(drawn.length > 0 ? cursor : sp.start, length - sp.end - menuSize), menuSize);
|
|
425
|
-
const inside = idx.filter((i) => isMenu(form(i)));
|
|
426
|
-
const menu = inside.length > 0 ? { rect: menuRect, items: inside.map((i) => items[i].id) } : null;
|
|
427
|
-
const placed = idx.map((i) => ({ id: items[i].id, form: at[i], kind: form(i).kind, rect: isMenu(form(i)) ? menuRect : rects.get(i) }));
|
|
428
|
-
const notes = [];
|
|
429
|
-
for (const it of input.items) if (it.forms.length === 0) notes.push({ code: "no-forms", id: it.id });
|
|
430
|
-
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] });
|
|
431
|
-
for (const i of menuOrder) if (isMenu(form(i))) notes.push({ code: "to-menu", id: items[i].id });
|
|
432
|
-
for (const i of idx) if (tooWide(i, cross)) notes.push({ code: "too-wide", id: items[i].id });
|
|
433
|
-
if (overflow > EPS) notes.push({ code: "overflow", over: overflow });
|
|
434
|
-
return { axis: input.axis, length, cross, items: placed, menu, notes, need: minSumWith(false), steps: hist };
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// src/stack/targets.ts
|
|
438
|
-
function bounds(input, fit, reach) {
|
|
439
|
-
const column = input.axis === "column";
|
|
440
|
-
const start = (r) => column ? r.y : r.x;
|
|
441
|
-
const size = (r) => column ? r.height : r.width;
|
|
442
|
-
const placed = new Map(fit.items.map((p) => [p.id, p]));
|
|
443
|
-
const c = [0];
|
|
444
|
-
let end = 0;
|
|
445
|
-
let cap = fit.length;
|
|
446
|
-
for (const it of input.items) {
|
|
447
|
-
const p = placed.get(it.id);
|
|
448
|
-
if (!p || p.kind === "menu") {
|
|
449
|
-
c.push(end, end);
|
|
450
|
-
continue;
|
|
451
|
-
}
|
|
452
|
-
const s = start(p.rect);
|
|
453
|
-
const mid = s + size(p.rect) / 2;
|
|
454
|
-
c.push(it.fixed ? s : mid, it.fixed ? s + size(p.rect) : mid);
|
|
455
|
-
end = s + size(p.rect);
|
|
456
|
-
if (it.fixed) cap = Math.max(cap, end);
|
|
457
|
-
}
|
|
458
|
-
c.push(fit.length);
|
|
459
|
-
for (let i = 1; i < c.length; i++) c[i] = Math.min(Math.max(c[i], c[i - 1]), cap);
|
|
460
|
-
c[0] = 0 - reach;
|
|
461
|
-
c[c.length - 1] = Math.max(fit.length + reach, c[c.length - 2]);
|
|
462
|
-
const from = [];
|
|
463
|
-
const to = [];
|
|
464
|
-
for (let k = 0; k <= input.items.length; k++) {
|
|
465
|
-
from.push(c[2 * k]);
|
|
466
|
-
to.push(c[2 * k + 1]);
|
|
467
|
-
}
|
|
468
|
-
return { from, to };
|
|
469
|
-
}
|
|
470
|
-
function fitsBeside(base, fit, dragged, fixed, axis, tooWideBefore) {
|
|
471
|
-
if (dragged.kind === "menu") return false;
|
|
472
|
-
for (const n of fit.notes) {
|
|
473
|
-
if (n.code === "overflow") return false;
|
|
474
|
-
if (n.code === "too-wide" && !tooWideBefore.has(n.id)) return false;
|
|
475
|
-
}
|
|
476
|
-
const main = (r) => axis === "column" ? r.height : r.width;
|
|
477
|
-
const across = (r) => axis === "column" ? r.width : r.height;
|
|
478
|
-
const was = new Map(base.items.map((p) => [p.id, p]));
|
|
479
|
-
for (const p of fit.items) {
|
|
480
|
-
const item = fixed.get(p.id);
|
|
481
|
-
const q = was.get(p.id);
|
|
482
|
-
if (!item || !q || p.kind === "menu" || q.kind === "menu") continue;
|
|
483
|
-
if (p.form !== q.form) return false;
|
|
484
|
-
if (main(p.rect) < formMain(item.forms[p.form], "min", fit.cross) - 1e-6) return false;
|
|
485
|
-
if (across(p.rect) < across(q.rect) - 1e-6) return false;
|
|
486
|
-
}
|
|
487
|
-
return true;
|
|
488
|
-
}
|
|
489
|
-
function stackTargets(input, dragged, options = {}) {
|
|
490
|
-
if (dragged.forms.length === 0) return [];
|
|
491
|
-
if (dragged.fixed) return [];
|
|
492
|
-
if (input.accepts && !input.accepts(dragged)) return [];
|
|
493
|
-
const rest = { ...input, items: input.items.filter((it) => it.id !== dragged.id) };
|
|
494
|
-
const fitOptions = options.previous ? { previous: options.previous } : {};
|
|
495
|
-
const base = fitStack(rest, fitOptions);
|
|
496
|
-
const reach = Math.max(0, Number.isFinite(options.endReach) ? options.endReach : 0);
|
|
497
|
-
const b = bounds(rest, base, reach);
|
|
498
|
-
const column = rest.axis === "column";
|
|
499
|
-
const fixedItems = new Map(rest.items.filter((it) => it.fixed).map((it) => [it.id, it]));
|
|
500
|
-
const tooWideBefore = new Set(base.notes.flatMap((n) => n.code === "too-wide" ? [n.id] : []));
|
|
501
|
-
const newest = rest.items.reduce((m, it) => Math.max(m, it.used), dragged.used) + 1;
|
|
502
|
-
const item = { ...dragged, used: newest };
|
|
503
|
-
const out = [];
|
|
504
|
-
for (let k = 0; k <= rest.items.length; k++) {
|
|
505
|
-
if (options.allows && !options.allows(dragged, k)) continue;
|
|
506
|
-
const solved = withItem(rest, item, k);
|
|
507
|
-
const fit = fitStack(solved, fitOptions);
|
|
508
|
-
const placed = fit.items.find((p) => p.id === dragged.id);
|
|
509
|
-
const slot = placed.rect;
|
|
510
|
-
if (options.onlyFits && !fitsBeside(base, fit, placed, fixedItems, rest.axis, tooWideBefore)) continue;
|
|
511
|
-
const from = b.from[k];
|
|
512
|
-
const to = b.to[k];
|
|
513
|
-
const across = Math.max(base.cross, fit.cross);
|
|
514
|
-
out.push({
|
|
515
|
-
id: `gap:${k}`,
|
|
516
|
-
priority: 2,
|
|
517
|
-
item: dragged.id,
|
|
518
|
-
place: { kind: "gap", at: k },
|
|
519
|
-
hit: column ? rect(0, from, across, to - from) : rect(from, 0, to - from, across),
|
|
520
|
-
slot,
|
|
521
|
-
// The line spans the stack's cross size (the drop's fit: the bar's height, the column's width).
|
|
522
|
-
marker: column ? rect(0, slot.y, fit.cross, 0) : rect(slot.x, 0, 0, fit.cross),
|
|
523
|
-
input: solved,
|
|
524
|
-
fit
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
return out;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// src/stack/store.ts
|
|
531
|
-
var createStack = (order) => ({ order: [...order], kept: [], closed: [], used: [...order], forms: {} });
|
|
532
|
-
var isForm = (f) => typeof f === "number" && Number.isInteger(f) && f >= 1;
|
|
533
|
-
var uniq = (ids, order) => [...new Set(ids)].filter((id) => order.includes(id));
|
|
534
|
-
var uniqLast = (ids, order) => ids.filter((id, i) => order.includes(id) && ids.lastIndexOf(id) === i);
|
|
535
|
-
var noForms = () => /* @__PURE__ */ Object.create(null);
|
|
536
|
-
function storeStack(state) {
|
|
537
|
-
const forms = noForms();
|
|
538
|
-
for (const id of state.order) {
|
|
539
|
-
const f = state.forms[id];
|
|
540
|
-
if (id !== "__proto__" && Object.hasOwn(state.forms, id) && isForm(f)) forms[id] = f;
|
|
541
|
-
}
|
|
542
|
-
return { v: 1, order: [...state.order], kept: uniq(state.kept, state.order), closed: uniq(state.closed, state.order), used: uniqLast(state.used, state.order), forms };
|
|
543
|
-
}
|
|
544
|
-
var isObject = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
545
|
-
function readStack(data, known) {
|
|
546
|
-
try {
|
|
547
|
-
return read(data, known);
|
|
548
|
-
} catch (e) {
|
|
549
|
-
return { ok: false, error: `unreadable: ${e instanceof Error ? e.message : typeof e}` };
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
var versionWords = (v) => typeof v === "number" ? String(v) : typeof v === "string" ? JSON.stringify(v.length > 24 ? `${v.slice(0, 24)}\u2026` : v) : typeof v;
|
|
553
|
-
function read(data, known) {
|
|
554
|
-
if (!isObject(data)) return { ok: false, error: "not an object" };
|
|
555
|
-
if (data.v !== 1) return { ok: false, error: `unknown version ${versionWords(data.v)} (this reads version 1)` };
|
|
556
|
-
if (!Array.isArray(data.order)) return { ok: false, error: "order is missing" };
|
|
557
|
-
const dropped = [];
|
|
558
|
-
const drop = (what) => {
|
|
559
|
-
if (!dropped.includes(what)) dropped.push(what);
|
|
560
|
-
};
|
|
561
|
-
for (const k of Object.keys(data)) if (!["v", "order", "kept", "closed", "used", "forms"].includes(k)) drop(k);
|
|
562
|
-
const order = [];
|
|
563
|
-
for (const x of data.order) {
|
|
564
|
-
if (typeof x !== "string") drop(`a ${typeof x} where an id goes`);
|
|
565
|
-
else if (known && !known.includes(x) || order.includes(x)) drop(x);
|
|
566
|
-
else order.push(x);
|
|
567
|
-
}
|
|
568
|
-
const list = (key) => {
|
|
569
|
-
const out = [];
|
|
570
|
-
const x = data[key];
|
|
571
|
-
if (x === void 0) return out;
|
|
572
|
-
if (!Array.isArray(x)) {
|
|
573
|
-
drop(key);
|
|
574
|
-
return out;
|
|
575
|
-
}
|
|
576
|
-
for (const id of x) {
|
|
577
|
-
if (typeof id === "string" && order.includes(id)) {
|
|
578
|
-
if (key === "used" && out.includes(id)) out.splice(out.indexOf(id), 1);
|
|
579
|
-
if (!out.includes(id)) out.push(id);
|
|
580
|
-
} else drop(typeof id === "string" ? `${key}:${id}` : `a ${typeof id} in ${key}`);
|
|
581
|
-
}
|
|
582
|
-
return out;
|
|
583
|
-
};
|
|
584
|
-
const kept = list("kept");
|
|
585
|
-
const closed = list("closed");
|
|
586
|
-
const used = list("used");
|
|
587
|
-
const forms = noForms();
|
|
588
|
-
if (data.forms !== void 0) {
|
|
589
|
-
if (!isObject(data.forms)) drop("forms");
|
|
590
|
-
else {
|
|
591
|
-
for (const id of Object.keys(data.forms)) {
|
|
592
|
-
const f = data.forms[id];
|
|
593
|
-
if (id === "__proto__" || !Object.hasOwn(data.forms, id) || !order.includes(id) || !isForm(f)) drop(`forms:${id}`);
|
|
594
|
-
else forms[id] = f;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
return { ok: true, state: { order, kept, closed, used, forms }, dropped };
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
// src/float-fit.ts
|
|
602
|
-
var EPS2 = 1e-3;
|
|
603
|
-
var finite3 = (x, fallback) => Number.isFinite(x) ? x : fallback;
|
|
604
|
-
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)));
|
|
605
|
-
var WORK = 3e6;
|
|
606
|
-
var COVERED_PLACES = 2048;
|
|
607
|
-
var Nearest = class {
|
|
608
|
-
h = [];
|
|
609
|
-
less(a, b) {
|
|
610
|
-
return a[2] !== b[2] ? a[2] < b[2] : a[0] !== b[0] ? a[0] < b[0] : a[1] < b[1];
|
|
611
|
-
}
|
|
612
|
-
get size() {
|
|
613
|
-
return this.h.length;
|
|
614
|
-
}
|
|
615
|
-
push(t) {
|
|
616
|
-
const h = this.h;
|
|
617
|
-
let i = h.push(t) - 1;
|
|
618
|
-
while (i > 0) {
|
|
619
|
-
const p = i - 1 >> 1;
|
|
620
|
-
if (!this.less(h[i], h[p])) break;
|
|
621
|
-
[h[i], h[p]] = [h[p], h[i]];
|
|
622
|
-
i = p;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
pop() {
|
|
626
|
-
const h = this.h;
|
|
627
|
-
const top = h[0];
|
|
628
|
-
const last = h.pop();
|
|
629
|
-
if (h.length > 0) {
|
|
630
|
-
h[0] = last;
|
|
631
|
-
let i = 0;
|
|
632
|
-
for (; ; ) {
|
|
633
|
-
const l = 2 * i + 1;
|
|
634
|
-
const r = l + 1;
|
|
635
|
-
let m = i;
|
|
636
|
-
if (l < h.length && this.less(h[l], h[m])) m = l;
|
|
637
|
-
if (r < h.length && this.less(h[r], h[m])) m = r;
|
|
638
|
-
if (m === i) break;
|
|
639
|
-
[h[i], h[m]] = [h[m], h[i]];
|
|
640
|
-
i = m;
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
return top;
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
function* byDistance(xs, ys, fx, fy) {
|
|
647
|
-
const sx = [...xs].sort((a, b) => Math.abs(a - fx) - Math.abs(b - fx) || a - b);
|
|
648
|
-
const sy = [...ys].sort((a, b) => Math.abs(a - fy) - Math.abs(b - fy) || a - b);
|
|
649
|
-
const q = new Nearest();
|
|
650
|
-
const d = (i, j) => Math.hypot(sx[i] - fx, sy[j] - fy);
|
|
651
|
-
if (sy.length > 0) for (let i = 0; i < sx.length; i++) q.push([i, 0, d(i, 0)]);
|
|
652
|
-
while (q.size > 0) {
|
|
653
|
-
const [i, j, far] = q.pop();
|
|
654
|
-
yield { x: sx[i], y: sy[j], far };
|
|
655
|
-
if (j + 1 < sy.length) q.push([i, j + 1, d(i, j + 1)]);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
function fitFloat(want, stage, avoid = []) {
|
|
659
|
-
const area = clean(stage, rect(0, 0, 0, 0));
|
|
660
|
-
const r = clean(want, area);
|
|
661
|
-
const inside = clampInto(r, area);
|
|
662
|
-
const clamped = inside.x !== want.x || inside.y !== want.y;
|
|
663
|
-
const reach = rect(area.x, area.y, Math.max(area.width, r.width), Math.max(area.height, r.height));
|
|
664
|
-
const near = [];
|
|
665
|
-
avoid.forEach((a, index) => {
|
|
666
|
-
const at = clean(a, area);
|
|
667
|
-
if (at.width > EPS2 && at.height > EPS2 && overlaps(at, reach, EPS2)) near.push({ at, index });
|
|
668
|
-
});
|
|
669
|
-
const under = (cand) => near.filter((n) => overlaps(cand, n.at, EPS2)).map((n) => n.index);
|
|
670
|
-
const blocked = (cand) => near.some((n) => overlaps(cand, n.at, EPS2));
|
|
671
|
-
if (!blocked(inside)) return { rect: inside, clamped, snapped: false, covers: [], searchCapped: false };
|
|
672
|
-
const lo = (v, from, to) => Math.min(Math.max(v, from), Math.max(from, to));
|
|
673
|
-
const xs = [inside.x, area.x, area.x + area.width - r.width];
|
|
674
|
-
const ys = [inside.y, area.y, area.y + area.height - r.height];
|
|
675
|
-
for (const { at } of near) {
|
|
676
|
-
xs.push(at.x - r.width, at.x + at.width);
|
|
677
|
-
ys.push(at.y - r.height, at.y + at.height);
|
|
678
|
-
}
|
|
679
|
-
const places = (list, from, size, extent) => [...new Set(list.map((v) => lo(v, from, from + extent - size)))];
|
|
680
|
-
const px = places(xs, area.x, r.width, area.width);
|
|
681
|
-
const py = places(ys, area.y, r.height, area.height);
|
|
682
|
-
const ylo = area.y;
|
|
683
|
-
const yhi = Math.max(area.y, area.y + area.height - r.height);
|
|
684
|
-
const byX = [...px].sort((a, b) => Math.abs(a - inside.x) - Math.abs(b - inside.x) || a - b);
|
|
685
|
-
let clear = null;
|
|
686
|
-
let work = 0;
|
|
687
|
-
let searchCapped = false;
|
|
688
|
-
for (const x of byX) {
|
|
689
|
-
const dx = Math.abs(x - inside.x);
|
|
690
|
-
if (clear && dx >= clear.far) break;
|
|
691
|
-
work += near.length + 1;
|
|
692
|
-
if (work > WORK) {
|
|
693
|
-
searchCapped = true;
|
|
694
|
-
break;
|
|
695
|
-
}
|
|
696
|
-
const stretches = [];
|
|
697
|
-
for (const { at } of near) {
|
|
698
|
-
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]);
|
|
699
|
-
}
|
|
700
|
-
stretches.sort((a, b) => a[0] - b[0]);
|
|
701
|
-
let cursor = ylo;
|
|
702
|
-
let bestY = null;
|
|
703
|
-
const gap = (from, to) => {
|
|
704
|
-
if (from > to) return;
|
|
705
|
-
const y = Math.min(Math.max(inside.y, from), to);
|
|
706
|
-
if (bestY === null || Math.abs(y - inside.y) < Math.abs(bestY - inside.y)) bestY = y;
|
|
707
|
-
};
|
|
708
|
-
for (const [a, b] of stretches) {
|
|
709
|
-
gap(cursor, Math.min(a, yhi));
|
|
710
|
-
cursor = Math.max(cursor, b);
|
|
711
|
-
if (cursor > yhi) break;
|
|
712
|
-
}
|
|
713
|
-
if (cursor <= yhi) gap(cursor, yhi);
|
|
714
|
-
if (bestY === null) continue;
|
|
715
|
-
const far = Math.hypot(dx, bestY - inside.y);
|
|
716
|
-
if (!clear || far < clear.far) clear = { x, y: bestY, far };
|
|
717
|
-
}
|
|
718
|
-
if (clear) return { rect: rect(clear.x, clear.y, r.width, r.height), clamped, snapped: clear.far > EPS2, covers: [], searchCapped };
|
|
719
|
-
let best = null;
|
|
720
|
-
let tried = 0;
|
|
721
|
-
for (const p of byDistance(px, py, inside.x, inside.y)) {
|
|
722
|
-
if (tried++ >= COVERED_PLACES) break;
|
|
723
|
-
const cand = rect(p.x, p.y, r.width, r.height);
|
|
724
|
-
const left = near.reduce((s, n) => s + overlap(cand, n.at), 0);
|
|
725
|
-
if (!best || left < best.left - EPS2) best = { rect: cand, left, far: p.far, hits: under(cand) };
|
|
726
|
-
}
|
|
727
|
-
const out = best ?? { rect: inside, far: 0, hits: under(inside) };
|
|
728
|
-
return { rect: out.rect, clamped, snapped: out.far > EPS2, covers: out.hits, searchCapped };
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
// src/stack/floats.ts
|
|
732
|
-
var fitFloat2 = fitFloat;
|
|
733
|
-
var finite4 = (x, fallback) => Number.isFinite(x) ? x : fallback;
|
|
734
|
-
function stackFloatTarget(input) {
|
|
735
|
-
const { stage, size } = input;
|
|
736
|
-
const avoid = input.avoid ?? [];
|
|
737
|
-
const w = Math.max(0, finite4(size.width, 0));
|
|
738
|
-
const h = Math.max(0, finite4(size.height, 0));
|
|
739
|
-
return {
|
|
740
|
-
// Not "float": `./desk` has a target of that id, and a consumer may hold both.
|
|
741
|
-
id: `float:${input.id}`,
|
|
742
|
-
kind: "float",
|
|
743
|
-
priority: 3,
|
|
744
|
-
free: true,
|
|
745
|
-
hit: PLANE,
|
|
746
|
-
label: input.label ?? "Float here",
|
|
747
|
-
item: input.id,
|
|
748
|
-
make(point, grab) {
|
|
749
|
-
const g = grab ?? { x: w / 2, y: h / 2 };
|
|
750
|
-
const fit = fitFloat2(rect(point.x - g.x, point.y - g.y, w, h), stage, avoid);
|
|
751
|
-
return { rect: fit.rect, fit };
|
|
752
|
-
}
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
var isSize = (n) => typeof n === "number" && Number.isFinite(n) && n > 0;
|
|
756
|
-
var isAt = (n) => typeof n === "number" && Number.isFinite(n);
|
|
757
|
-
function storeFloats(floats) {
|
|
758
|
-
const last = /* @__PURE__ */ new Map();
|
|
759
|
-
floats.forEach((f, i) => {
|
|
760
|
-
const r = f.rect;
|
|
761
|
-
if (isAt(r.x) && isAt(r.y) && isSize(r.width) && isSize(r.height)) last.set(f.id, i);
|
|
762
|
-
});
|
|
763
|
-
const out = [];
|
|
764
|
-
floats.forEach((f, i) => {
|
|
765
|
-
if (last.get(f.id) === i) out.push({ id: f.id, x: f.rect.x, y: f.rect.y, width: f.rect.width, height: f.rect.height });
|
|
766
|
-
});
|
|
767
|
-
return { v: 1, floats: out };
|
|
768
|
-
}
|
|
769
|
-
var isObject2 = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
770
|
-
var FIELDS = ["id", "x", "y", "width", "height"];
|
|
771
|
-
function readFloats(data, known) {
|
|
772
|
-
try {
|
|
773
|
-
return read2(data, known);
|
|
774
|
-
} catch (e) {
|
|
775
|
-
return { ok: false, error: `unreadable: ${e instanceof Error ? e.message : typeof e}` };
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
function read2(data, known) {
|
|
779
|
-
if (!isObject2(data)) return { ok: false, error: "not an object" };
|
|
780
|
-
if (data.v !== 1) return { ok: false, error: `unknown version ${versionWords(data.v)} (this reads version 1)` };
|
|
781
|
-
if (!Array.isArray(data.floats)) return { ok: false, error: "floats is missing" };
|
|
782
|
-
const dropped = [];
|
|
783
|
-
const drop = (what) => {
|
|
784
|
-
if (!dropped.includes(what)) dropped.push(what);
|
|
785
|
-
};
|
|
786
|
-
for (const k of Object.keys(data)) if (k !== "v" && k !== "floats") drop(k);
|
|
787
|
-
const floats = [];
|
|
788
|
-
for (const x of data.floats) {
|
|
789
|
-
if (!isObject2(x)) {
|
|
790
|
-
drop(`a ${x === null ? "null" : Array.isArray(x) ? "list" : typeof x} where a float goes`);
|
|
791
|
-
continue;
|
|
792
|
-
}
|
|
793
|
-
const id = x.id;
|
|
794
|
-
if (typeof id !== "string") {
|
|
795
|
-
drop("a float with no id");
|
|
796
|
-
continue;
|
|
797
|
-
}
|
|
798
|
-
if (known && !known.includes(id) || !isAt(x.x) || !isAt(x.y) || !isSize(x.width) || !isSize(x.height)) {
|
|
799
|
-
drop(`float:${id}`);
|
|
800
|
-
continue;
|
|
801
|
-
}
|
|
802
|
-
for (const k of Object.keys(x)) {
|
|
803
|
-
if (k === "pinned") drop(`pinned:${id}`);
|
|
804
|
-
else if (!FIELDS.includes(k)) drop(`float:${id}:${k}`);
|
|
805
|
-
}
|
|
806
|
-
const before = floats.findIndex((f) => f.id === id);
|
|
807
|
-
if (before >= 0) {
|
|
808
|
-
floats.splice(before, 1);
|
|
809
|
-
drop(`float:${id}`);
|
|
810
|
-
}
|
|
811
|
-
floats.push({ id, rect: rect(x.x, x.y, x.width, x.height) });
|
|
812
|
-
}
|
|
813
|
-
return { ok: true, floats, dropped };
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
export {
|
|
817
|
-
formCrossMin,
|
|
818
|
-
formMain,
|
|
819
|
-
formFitsCross,
|
|
820
|
-
wrapLines,
|
|
821
|
-
wrapRows,
|
|
822
|
-
wrapCross,
|
|
823
|
-
DEFAULT_RAIL,
|
|
824
|
-
DEFAULT_MENU,
|
|
825
|
-
formSetsCross,
|
|
826
|
-
withItem,
|
|
827
|
-
fitStack,
|
|
828
|
-
stackTargets,
|
|
829
|
-
createStack,
|
|
830
|
-
storeStack,
|
|
831
|
-
readStack,
|
|
832
|
-
fitFloat,
|
|
833
|
-
fitFloat2,
|
|
834
|
-
stackFloatTarget,
|
|
835
|
-
storeFloats,
|
|
836
|
-
readFloats
|
|
837
|
-
};
|
|
838
|
-
//# sourceMappingURL=chunk-AE3BWTAE.js.map
|