@n-uf/placement 26.11.18 → 26.11.20
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 +66 -0
- package/README.md +74 -2
- package/dist/{chunk-HQE2DOWA.js → chunk-GCSVZGVX.js} +183 -49
- package/dist/chunk-GCSVZGVX.js.map +1 -0
- package/dist/{model-irGEua8T.d.ts → model-DU7MovDa.d.ts} +1 -1
- package/dist/scene-cases.d.ts +35 -3
- package/dist/scene-cases.js +89 -40
- package/dist/scene-cases.js.map +1 -1
- package/dist/scene.d.ts +3 -3
- package/dist/scene.js +3 -1
- package/dist/stack.d.ts +2 -2
- package/dist/{targets-CZOYu8mG.d.ts → targets-CYJN0Hba.d.ts} +62 -7
- package/package.json +1 -1
- package/dist/chunk-HQE2DOWA.js.map +0 -1
|
@@ -172,37 +172,53 @@ function solveEdge(scene, edge, ids, length, room, previous) {
|
|
|
172
172
|
function zoneStarts(scene, fit, input) {
|
|
173
173
|
const column = fit.axis === "column";
|
|
174
174
|
const at = (r) => column ? r.y : r.x;
|
|
175
|
-
const len = (r) => column ? r.height : r.width;
|
|
176
175
|
const out = /* @__PURE__ */ new Map();
|
|
176
|
+
const lengths = /* @__PURE__ */ new Map();
|
|
177
177
|
const drawn = fit.items.filter((p) => p.kind !== "menu");
|
|
178
|
-
for (const p of drawn)
|
|
178
|
+
for (const p of drawn) {
|
|
179
|
+
out.set(p.id, at(p.rect));
|
|
180
|
+
lengths.set(p.id, column ? p.rect.height : p.rect.width);
|
|
181
|
+
}
|
|
182
|
+
const len = (p) => lengths.get(p.id);
|
|
179
183
|
const gap = px(input.gap);
|
|
180
184
|
const start = px(input.pad?.start);
|
|
181
185
|
const end = px(input.pad?.end);
|
|
182
|
-
const menu = fit.menu ?
|
|
183
|
-
const used = drawn.reduce((s2, p) => s2 + len(p.rect), 0) + Math.max(0, drawn.length - 1) * gap;
|
|
184
|
-
const spare = fit.length - start - end - menu - used;
|
|
185
|
-
if (spare <= EPS) return out;
|
|
186
|
+
const menu = fit.menu ? (column ? fit.menu.rect.height : fit.menu.rect.width) + (drawn.length > 0 ? gap : 0) : 0;
|
|
186
187
|
const zone = (z) => drawn.filter((p) => zoneOf(scene.items[p.id]) === z);
|
|
187
|
-
const
|
|
188
|
+
const s = zone("start");
|
|
189
|
+
const c = zone("center");
|
|
190
|
+
const e = zone("end");
|
|
191
|
+
const title = column ? void 0 : s.find((p) => {
|
|
192
|
+
const it = scene.items[p.id];
|
|
193
|
+
const f = formsOf(it, "row")[p.form];
|
|
194
|
+
return it.fixed && f?.main.grows && len(p) > formMain(f, "natural", fit.cross) + EPS;
|
|
195
|
+
});
|
|
196
|
+
if (title) lengths.set(title.id, formMain(formsOf(scene.items[title.id], "row")[title.form], "natural", fit.cross));
|
|
197
|
+
const used = drawn.reduce((sum, p) => sum + len(p), 0) + Math.max(0, drawn.length - 1) * gap;
|
|
198
|
+
const spare = fit.length - start - end - menu - used;
|
|
199
|
+
if (spare <= EPS) return { starts: out, lengths };
|
|
200
|
+
const total = (ps) => ps.reduce((sum, p) => sum + len(p), 0) + Math.max(0, ps.length - 1) * gap;
|
|
188
201
|
const lay = (ps, from) => {
|
|
189
|
-
let
|
|
202
|
+
let x = from;
|
|
190
203
|
for (const p of ps) {
|
|
191
|
-
out.set(p.id,
|
|
192
|
-
|
|
204
|
+
out.set(p.id, x);
|
|
205
|
+
x += len(p) + gap;
|
|
193
206
|
}
|
|
194
207
|
};
|
|
195
|
-
const s = zone("start");
|
|
196
|
-
const c = zone("center");
|
|
197
|
-
const e = zone("end");
|
|
198
208
|
lay(s, start);
|
|
199
209
|
const endStart = fit.length - end - menu - total(e);
|
|
200
210
|
lay(e, endStart);
|
|
201
211
|
const lo = start + total(s) + (s.length > 0 ? gap : 0);
|
|
202
212
|
const hi = endStart - (e.length > 0 ? gap : 0);
|
|
203
213
|
const mid = (fit.length - total(c)) / 2;
|
|
204
|
-
|
|
205
|
-
|
|
214
|
+
const clear = mid >= lo - EPS && mid + total(c) <= hi + EPS;
|
|
215
|
+
lay(c, title && !clear ? Math.max(lo, (lo + hi - total(c)) / 2) : Math.max(lo, Math.min(mid, hi - total(c))));
|
|
216
|
+
if (title && s[s.length - 1] === title) {
|
|
217
|
+
const next = [...c, ...e].map((p) => out.get(p.id));
|
|
218
|
+
const until = next.length ? Math.min(...next) - gap : fit.length - end - menu;
|
|
219
|
+
lengths.set(title.id, Math.max(len(title), until - out.get(title.id)));
|
|
220
|
+
}
|
|
221
|
+
return { starts: out, lengths };
|
|
206
222
|
}
|
|
207
223
|
function anchored(content, w, h, anchor) {
|
|
208
224
|
const left = content.x;
|
|
@@ -264,12 +280,13 @@ function solve(given, options = {}) {
|
|
|
264
280
|
const column = axisOf(edge.side) === "column";
|
|
265
281
|
const { stack } = solved;
|
|
266
282
|
const thick = column ? r.width : r.height;
|
|
267
|
-
const starts = zoneStarts(scene, stack, solved.input);
|
|
283
|
+
const { starts, lengths } = zoneStarts(scene, stack, solved.input);
|
|
268
284
|
const toStage = (l, id) => {
|
|
269
285
|
const s = id !== void 0 ? starts.get(id) : void 0;
|
|
286
|
+
const n = id !== void 0 ? lengths.get(id) : void 0;
|
|
270
287
|
const x = column ? l.x : s ?? l.x;
|
|
271
288
|
const y = column ? s ?? l.y : l.y;
|
|
272
|
-
return rect(r.x + x, r.y + y, l.width, l.height);
|
|
289
|
+
return rect(r.x + x, r.y + y, column ? l.width : n ?? l.width, column ? n ?? l.height : l.height);
|
|
273
290
|
};
|
|
274
291
|
const tabs = new Set(solved.tabs);
|
|
275
292
|
for (const id of solved.leftOut ?? []) notes.push({ code: "no-vertical-form", edge: edge.id, id });
|
|
@@ -319,16 +336,22 @@ function solve(given, options = {}) {
|
|
|
319
336
|
};
|
|
320
337
|
const rails = {};
|
|
321
338
|
const gutter = px(scene.gutter);
|
|
339
|
+
let columnRoom;
|
|
322
340
|
const isSide = (e) => e.side === "left" || e.side === "right";
|
|
341
|
+
const docked = order.some((e) => isSide(e) && e.accepts.length > 0 && owned.get(e).some((id) => !scene.items[id].closed));
|
|
342
|
+
const inset = scene.insetWhen === "docked" && !docked ? {} : scene.inset ?? {};
|
|
323
343
|
const laySides = (sideEdges, area3) => {
|
|
324
344
|
const H = area3.height;
|
|
325
345
|
const ride = scene.handFold === "ride";
|
|
346
|
+
const upInset = area3.y <= stage.y + px(inset.top) + EPS ? px(inset.top) : 0;
|
|
347
|
+
const downInset = area3.y + area3.height >= stage.y + stage.height - px(inset.bottom) - EPS ? px(inset.bottom) : 0;
|
|
348
|
+
const tall = (edge) => H + (edge.outsideInset === true ? upInset + downInset : 0);
|
|
326
349
|
const cols = sideEdges.map((edge) => {
|
|
327
350
|
const side = edge.side;
|
|
328
|
-
const solved = solveEdge(scene, edge, owned.get(edge),
|
|
351
|
+
const solved = solveEdge(scene, edge, owned.get(edge), tall(edge), Math.max(0, area3.width), prevEdge(edge));
|
|
329
352
|
const width = solved.stack.items.length === 0 ? 0 : Math.min(solved.stack.cross, area3.width);
|
|
330
353
|
const visible = owned.get(edge).filter((id) => !scene.items[id].closed);
|
|
331
|
-
const dyn = edge.column === true && scene.rails?.[side] !== void 0 && visible.length > 0;
|
|
354
|
+
const dyn = (edge.column === true || edge.giveWay === true) && scene.rails?.[side] !== void 0 && visible.length > 0;
|
|
332
355
|
const forms = (id) => formsOf(scene.items[id], "column");
|
|
333
356
|
const setters = solved.free.items.filter((p) => p.kind !== "menu" && formSetsCross(forms(p.id)[p.form]));
|
|
334
357
|
const min = setters.length > 0 ? Math.min(width, Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin(forms(p.id)[p.form])))) : width;
|
|
@@ -340,7 +363,7 @@ function solve(given, options = {}) {
|
|
|
340
363
|
min,
|
|
341
364
|
visible,
|
|
342
365
|
dyn,
|
|
343
|
-
hand: dyn && visible.every((id) => finite(scene.items[id].from, 0) >= 1),
|
|
366
|
+
hand: dyn && edge.column === true && visible.every((id) => finite(scene.items[id].from, 0) >= 1),
|
|
344
367
|
kept: visible.some((id) => scene.items[id].kept === true),
|
|
345
368
|
age: Math.max(-Infinity, ...visible.map((id) => finite(scene.items[id].used, 0)))
|
|
346
369
|
};
|
|
@@ -352,13 +375,13 @@ function solve(given, options = {}) {
|
|
|
352
375
|
const shrinkOrder = order2.map((c, i) => ({ c, i })).sort((a, b) => rankOf(a.c) === rankOf(b.c) ? a.i - b.i : rankOf(a.c) < rankOf(b.c) ? -1 : 1).map((x) => x.c);
|
|
353
376
|
const railW = (side) => px(scene.rails?.[side]?.width);
|
|
354
377
|
const evaluate = (auto2) => {
|
|
355
|
-
const openOn = (side) => cols.some((c) => c.side === side && c.dyn && !c.hand && !auto2.has(c) && c.width > 0);
|
|
356
|
-
const riding = (c) => ride && c.hand &&
|
|
378
|
+
const openOn = (side) => cols.some((c) => c.side === side && c.dyn && c.edge.column === true && !c.hand && !auto2.has(c) && c.width > 0);
|
|
379
|
+
const riding = (c) => ride && c.hand && openOn(c.side);
|
|
357
380
|
const railed = (c) => c.dyn && (auto2.has(c) || c.hand && !riding(c));
|
|
358
381
|
const widths = new Map(cols.filter((c) => !railed(c) && !riding(c)).map((c) => [c, c.width]));
|
|
359
382
|
const railSides = ["left", "right"].filter((s) => cols.some((c) => c.side === s && railed(c)));
|
|
360
383
|
let used = 0;
|
|
361
|
-
for (const w of widths
|
|
384
|
+
for (const [c, w] of widths) used += w > 0 ? w + (c.edge.outsideInset === true ? 0 : gutter) : 0;
|
|
362
385
|
for (const s of railSides) used += railW(s) + gutter;
|
|
363
386
|
let excess = cmin === void 0 ? -Infinity : used + cmin - area3.width;
|
|
364
387
|
for (const c of shrinkOrder) {
|
|
@@ -399,6 +422,23 @@ function solve(given, options = {}) {
|
|
|
399
422
|
}
|
|
400
423
|
}
|
|
401
424
|
const g = evaluate(auto);
|
|
425
|
+
const open2 = cols.filter((c) => c.edge.column === true && c.visible.length > 0).map((c) => c.min);
|
|
426
|
+
const templates = ["left", "right"].flatMap((s) => {
|
|
427
|
+
const t = scene.columns?.[s];
|
|
428
|
+
if (!t) return [];
|
|
429
|
+
const needs = Object.values(scene.items).filter((it) => !it.fixed && !it.closed && t.accepts.includes(it.kind)).map((it) => {
|
|
430
|
+
const forms = formsOf(it, "column");
|
|
431
|
+
const f = forms[Math.min(Math.max(0, Math.floor(finite(it.from, 0))), Math.max(0, forms.length - 1))];
|
|
432
|
+
return f && formSetsCross(f) ? formCrossMin(f) : 0;
|
|
433
|
+
});
|
|
434
|
+
return [Math.max(px(t.cross.min), ...needs)];
|
|
435
|
+
});
|
|
436
|
+
const colMins = open2.length > 0 ? open2 : templates;
|
|
437
|
+
if (cmin !== void 0 && colMins.length > 0) {
|
|
438
|
+
const need = cmin + Math.min(...colMins) + gutter;
|
|
439
|
+
columnRoom = area3.width >= need - EPS;
|
|
440
|
+
if (!columnRoom) notes.push({ code: "no-column-room", width: area3.width, need });
|
|
441
|
+
}
|
|
402
442
|
for (const c of shrinkOrder) {
|
|
403
443
|
const w = g.widths.get(c);
|
|
404
444
|
if (w !== void 0 && w < c.width - EPS) notes.push({ code: "column-shrunk", edge: c.edge.id, from: c.width, to: w });
|
|
@@ -410,17 +450,17 @@ function solve(given, options = {}) {
|
|
|
410
450
|
const mine = cols.filter((c) => c.side === side);
|
|
411
451
|
const railed = mine.filter((c) => g.railed(c));
|
|
412
452
|
const riders = mine.filter((c) => g.riding(c));
|
|
413
|
-
const host = mine.find((c) => c.dyn && !c.hand && !g.auto.has(c) && c.width > 0);
|
|
414
|
-
const
|
|
415
|
-
const id = c.visible[0];
|
|
453
|
+
const host = mine.find((c) => c.dyn && c.edge.column === true && !c.hand && !g.auto.has(c) && c.width > 0);
|
|
454
|
+
const riderBars = (c) => zoneSorted(scene, c.visible).map((id) => {
|
|
416
455
|
const forms = formsOf(scene.items[id], "column");
|
|
417
456
|
const form = forms.length === 0 ? 0 : Math.min(Math.max(0, Math.floor(finite(scene.items[id].from, 0))), forms.length - 1);
|
|
418
457
|
return { id, form, f: forms[form], h: px(forms[form]?.main.natural) };
|
|
419
|
-
};
|
|
420
|
-
const ridersTop = riders.reduce((s, c) => s +
|
|
458
|
+
});
|
|
459
|
+
const ridersTop = riders.reduce((s, c) => s + riderBars(c).reduce((t, b) => t + b.h, 0), 0);
|
|
421
460
|
let railRect = null;
|
|
461
|
+
let gap = px(side === "left" ? inset.left : inset.right);
|
|
422
462
|
for (const c of mine) {
|
|
423
|
-
if (!railRect && railed.length > 0
|
|
463
|
+
if (!railRect && railed.length > 0) {
|
|
424
464
|
const w2 = railW(side);
|
|
425
465
|
if (side === "left") {
|
|
426
466
|
railRect = rect(x0, area3.y, w2, H);
|
|
@@ -430,6 +470,7 @@ function solve(given, options = {}) {
|
|
|
430
470
|
railRect = rect(x1, area3.y, w2, H);
|
|
431
471
|
x1 -= gutter;
|
|
432
472
|
}
|
|
473
|
+
gap = gutter;
|
|
433
474
|
}
|
|
434
475
|
const base = { side: c.edge.side, ring: finite(c.edge.ring, 0), cross: 0, menu: null, tabs: [], stack: c.solved.stack, free: c.solved.free };
|
|
435
476
|
if (g.railed(c)) {
|
|
@@ -446,13 +487,30 @@ function solve(given, options = {}) {
|
|
|
446
487
|
solved = solveEdge(scene, plain, owned.get(c.edge), H - top, w, prevEdge(c.edge));
|
|
447
488
|
}
|
|
448
489
|
let r;
|
|
449
|
-
if (
|
|
490
|
+
if (c.edge.outsideInset === true) {
|
|
491
|
+
const y0 = area3.y - upInset;
|
|
492
|
+
const h = tall(c.edge);
|
|
493
|
+
if (side === "left") {
|
|
494
|
+
r = rect(x0 - gap, y0, w, h);
|
|
495
|
+
x0 += w;
|
|
496
|
+
} else {
|
|
497
|
+
r = rect(x1 + gap - w, y0, w, h);
|
|
498
|
+
x1 -= w;
|
|
499
|
+
}
|
|
500
|
+
if (Math.abs(h - H) > EPS || Math.abs(w - c.width) > EPS) {
|
|
501
|
+
const forced = { ...c.edge, cross: { ...c.edge.cross, min: w, max: w } };
|
|
502
|
+
const { size: _s, ...plain } = forced;
|
|
503
|
+
solved = solveEdge(scene, plain, owned.get(c.edge), h, w, prevEdge(c.edge));
|
|
504
|
+
}
|
|
505
|
+
} else if (side === "left") {
|
|
450
506
|
r = rect(x0, area3.y + top, w, H - top);
|
|
451
507
|
x0 += w > 0 ? w + gutter : 0;
|
|
508
|
+
if (w > 0) gap = gutter;
|
|
452
509
|
} else {
|
|
453
510
|
x1 -= w;
|
|
454
511
|
r = rect(x1, area3.y + top, w, H - top);
|
|
455
512
|
x1 -= w > 0 ? gutter : 0;
|
|
513
|
+
if (w > 0) gap = gutter;
|
|
456
514
|
}
|
|
457
515
|
emit(c.edge, r, solved, w < c.width - EPS ? { shrunk: true } : {});
|
|
458
516
|
}
|
|
@@ -460,12 +518,15 @@ function solve(given, options = {}) {
|
|
|
460
518
|
const hr = edges[host.edge.id].rect;
|
|
461
519
|
let y = area3.y;
|
|
462
520
|
for (const c of riders) {
|
|
463
|
-
const
|
|
464
|
-
const
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
521
|
+
const bars = riderBars(c);
|
|
522
|
+
const y0 = y;
|
|
523
|
+
for (const b of bars) {
|
|
524
|
+
const at = rect(hr.x, y, hr.width, b.h);
|
|
525
|
+
const it = scene.items[b.id];
|
|
526
|
+
items[b.id] = { rect: at, kind: it.kind, form: b.form, formKind: b.f?.kind ?? "header", edge: c.edge.id, zone: zoneOf(it), rides: host.edge.id, folded: "hand" };
|
|
527
|
+
y += b.h;
|
|
528
|
+
}
|
|
529
|
+
edges[c.edge.id] = { side: c.edge.side, ring: finite(c.edge.ring, 0), rect: rect(hr.x, y0, hr.width, y - y0), cross: 0, menu: null, tabs: [], stack: c.solved.stack, free: c.solved.free, rides: host.edge.id, folded: "hand" };
|
|
469
530
|
}
|
|
470
531
|
}
|
|
471
532
|
if (railRect) {
|
|
@@ -489,7 +550,6 @@ function solve(given, options = {}) {
|
|
|
489
550
|
}
|
|
490
551
|
return rect(x0, area3.y, Math.max(0, x1 - x0), H);
|
|
491
552
|
};
|
|
492
|
-
const inset = scene.inset ?? {};
|
|
493
553
|
let area2 = rect(stage.x + px(inset.left), stage.y + px(inset.top), Math.max(0, stage.width - px(inset.left) - px(inset.right)), Math.max(0, stage.height - px(inset.top) - px(inset.bottom)));
|
|
494
554
|
const reserved = order.filter((e) => e.mode !== "overlay");
|
|
495
555
|
for (const e of reserved) if (!isSide(e) && e.span !== "between") area2 = lay(e, area2, true);
|
|
@@ -517,6 +577,7 @@ function solve(given, options = {}) {
|
|
|
517
577
|
if (e.menu) avoid.push(e.menu.rect);
|
|
518
578
|
}
|
|
519
579
|
for (const c of scene.chrome ?? []) avoid.push(c);
|
|
580
|
+
const floatRegion = rect(stage.x + px(inset.left), stage.y, Math.max(0, stage.width - px(inset.left) - px(inset.right)), stage.height);
|
|
520
581
|
const floats = [];
|
|
521
582
|
for (const f of scene.floats) {
|
|
522
583
|
if (!claim(f.id)) continue;
|
|
@@ -529,17 +590,24 @@ function solve(given, options = {}) {
|
|
|
529
590
|
}
|
|
530
591
|
const from = shape.form;
|
|
531
592
|
const form = formsOf(it, f.orient === "row" ? "row" : "column")[from];
|
|
532
|
-
const
|
|
533
|
-
const
|
|
593
|
+
const row = f.orient === "row";
|
|
594
|
+
const floor = {
|
|
595
|
+
width: it.floatMin ? px(it.floatMin.width) : Math.min(shape.width, px(row ? form?.main.min : form?.cross.min)),
|
|
596
|
+
height: it.floatMin ? px(it.floatMin.height) : Math.min(shape.height, px(row ? form?.cross.min : form?.main.min))
|
|
597
|
+
};
|
|
598
|
+
const w = Math.max(floor.width, Math.min(shape.width, floatRegion.width));
|
|
599
|
+
const folded = form?.kind === "header";
|
|
600
|
+
const h = folded ? shape.height : Math.max(floor.height, Math.min(shape.height, floatRegion.height));
|
|
534
601
|
const want = f.anchor ? anchored(content, w, h, f.anchor) : rect(finite(f.rect.x, stage.x), finite(f.rect.y, stage.y), w, h);
|
|
535
|
-
const
|
|
602
|
+
const fit0 = fitFloat(want, floatRegion, avoid);
|
|
603
|
+
const fit = w > floatRegion.width + EPS ? { ...fit0, rect: rect(floatRegion.x, fit0.rect.y, w, fit0.rect.height) } : fit0;
|
|
536
604
|
if (fit.clamped) notes.push({ code: "float-clamped", id: f.id });
|
|
537
605
|
if (fit.snapped) notes.push({ code: "float-moved", id: f.id });
|
|
538
606
|
if (fit.covers.length > 0) notes.push({ code: "float-covers", id: f.id });
|
|
539
607
|
items[f.id] = { ...shapeOf(form, fit.rect, f.orient === "row" ? "row" : "column", fit.rect.width), rect: fit.rect, kind: it.kind, form: from, formKind: form?.kind ?? "open", floating: true };
|
|
540
608
|
floats.push(f.id);
|
|
541
609
|
}
|
|
542
|
-
return { items, edges, content, floats, rails, notes };
|
|
610
|
+
return { items, edges, content, floats, rails, ...columnRoom !== void 0 ? { columnRoom } : {}, notes };
|
|
543
611
|
}
|
|
544
612
|
|
|
545
613
|
// src/scene/changes.ts
|
|
@@ -599,8 +667,10 @@ function insertColumn(scene, id, side, ring) {
|
|
|
599
667
|
const col = newColumn(scene, side, kind, r, [id]);
|
|
600
668
|
if (!col) return null;
|
|
601
669
|
if (!zoneTakes(col, "start", kind)) return null;
|
|
602
|
-
const
|
|
603
|
-
const
|
|
670
|
+
const item = scene.items[id];
|
|
671
|
+
const zone = zoneTakes(col, zoneOf(item), kind) ? zoneOf(item) : zonesTaking(col, kind)[0] ?? "start";
|
|
672
|
+
const { align: _a, ...plain } = item;
|
|
673
|
+
const placed = withItem(scene, zone === "start" ? plain : { ...plain, align: zone });
|
|
604
674
|
const shifted = placed.edges.map((e) => e.side === side && e.ring >= r ? { ...e, ring: e.ring + 1 } : e);
|
|
605
675
|
return { ...placed, edges: closeRings([...shifted, col], /* @__PURE__ */ new Set([side])) };
|
|
606
676
|
}
|
|
@@ -627,8 +697,7 @@ function moveTo(scene, id, place) {
|
|
|
627
697
|
}
|
|
628
698
|
if (place.kind === "column" || place.kind === "rail") {
|
|
629
699
|
if (place.kind === "rail" && !scene.rails?.[place.side]?.accepts.includes(item.kind)) return scene;
|
|
630
|
-
const {
|
|
631
|
-
const folded = place.kind === "rail" ? { ...plain, from: Math.max(1, plain.from ?? 0) } : plain;
|
|
700
|
+
const folded = place.kind === "rail" ? { ...item, from: Math.max(1, item.from ?? 0) } : item;
|
|
632
701
|
const made = insertColumn(withItem(lift(scene, id), folded), id, place.side, place.ring);
|
|
633
702
|
return made ?? scene;
|
|
634
703
|
}
|
|
@@ -707,12 +776,20 @@ function resize(scene, edgeId, size) {
|
|
|
707
776
|
}
|
|
708
777
|
return { ...scene, edges: scene.edges.map((e) => e === edge ? { ...e, size } : e) };
|
|
709
778
|
}
|
|
779
|
+
function setSide(scene, edgeId, side) {
|
|
780
|
+
const edge = scene.edges.find((e) => e.id === edgeId);
|
|
781
|
+
if (!edge || edge.side === side || axisOf(edge.side) !== axisOf(side)) return scene;
|
|
782
|
+
const moved = { ...edge, side, ring: 0 };
|
|
783
|
+
const others = scene.edges.filter((e) => e !== edge).map((e) => e.side === side ? { ...e, ring: e.ring + 1 } : e);
|
|
784
|
+
return { ...scene, edges: closeRings([moved, ...others], /* @__PURE__ */ new Set([edge.side, side])) };
|
|
785
|
+
}
|
|
710
786
|
function homeFor(scene, id, start) {
|
|
711
787
|
for (const e of start.edges) {
|
|
712
788
|
const k = e.items.indexOf(id);
|
|
713
789
|
if (k < 0) continue;
|
|
714
790
|
const zone = zoneOf(itemOf(start, id) ?? itemOf(scene, id));
|
|
715
|
-
const
|
|
791
|
+
const found = scene.edges.find((x) => x.id === e.id);
|
|
792
|
+
const here = found && (e.column !== true || found.items.some((x) => e.items.includes(x))) ? found : void 0;
|
|
716
793
|
if (here) {
|
|
717
794
|
const now = here.items.filter((x) => x !== id && zoneOf(itemOf(scene, x)) === zone);
|
|
718
795
|
const next = e.items.slice(k + 1).find((x) => now.includes(x));
|
|
@@ -835,6 +912,7 @@ function read(data, base) {
|
|
|
835
912
|
const sizes = /* @__PURE__ */ new Map();
|
|
836
913
|
const made = [];
|
|
837
914
|
const rings = /* @__PURE__ */ new Map();
|
|
915
|
+
const moves = /* @__PURE__ */ new Map();
|
|
838
916
|
if (data.edges !== void 0 && !Array.isArray(data.edges)) drop("edges");
|
|
839
917
|
for (const e of Array.isArray(data.edges) ? data.edges : []) {
|
|
840
918
|
if (!isObject(e) || typeof e.id !== "string") {
|
|
@@ -853,6 +931,7 @@ function read(data, base) {
|
|
|
853
931
|
}
|
|
854
932
|
if (edge.column === true && isNum(e.ring)) rings.set(edge.id, e.ring);
|
|
855
933
|
if (e.side !== void 0 && !SIDES.includes(e.side)) drop(`edge:${e.id}:side`);
|
|
934
|
+
else if (edge.column !== true && typeof e.side === "string" && e.side !== edge.side && axisOf(e.side) === axisOf(edge.side)) moves.set(edge.id, e.side);
|
|
856
935
|
const ids = [];
|
|
857
936
|
for (const id of Array.isArray(e.items) ? e.items : []) {
|
|
858
937
|
if (!known(id) || placed.has(id)) drop(`edge:${edge.id}:${String(id)}`);
|
|
@@ -908,11 +987,13 @@ function read(data, base) {
|
|
|
908
987
|
return { ...plain, ring: rings.get(edge.id) ?? edge.ring, items: items1, ...size !== void 0 ? { size } : {} };
|
|
909
988
|
});
|
|
910
989
|
for (const f of base.floats) if (!placed.has(f.id)) floats.push(f);
|
|
911
|
-
|
|
990
|
+
let scene = prune({ ...base, items, edges: closeRings(edges, new Set(made.length > 0 || rings.size > 0 ? ["left", "right"] : [])), floats });
|
|
991
|
+
for (const [id, side] of moves) scene = setSide(scene, id, side);
|
|
912
992
|
return { scene, dropped };
|
|
913
993
|
}
|
|
914
994
|
|
|
915
995
|
// src/scene/targets.ts
|
|
996
|
+
var ZONE_ORDER = { start: 0, center: 1, end: 2 };
|
|
916
997
|
var EPS2 = 1e-6;
|
|
917
998
|
var PLANE = rect(-1e9, -1e9, 2e9, 2e9);
|
|
918
999
|
var area = (r) => Math.max(0, r.width) * Math.max(0, r.height);
|
|
@@ -1201,6 +1282,13 @@ function edgeTargets(scene, rest, now, base, edge, dragged, reach, blockers, chr
|
|
|
1201
1282
|
const restEdge = rest.edges.find((e) => e.id === edge.id);
|
|
1202
1283
|
const fixedIds = restEdge.items.filter((id) => rest.items[id]?.fixed && base.items[id]?.edge === edge.id);
|
|
1203
1284
|
const tooWideBefore = new Set(base.notes.flatMap((n) => "edge" in n && n.edge === edge.id && n.code === "too-wide" ? [n.id] : []));
|
|
1285
|
+
const thirds = !column && !edge.compact;
|
|
1286
|
+
const natural = (id, form) => {
|
|
1287
|
+
const f = formsOf(scene.items[id], "row")[form];
|
|
1288
|
+
return f ? formMain(f, "natural", el.cross) : 0;
|
|
1289
|
+
};
|
|
1290
|
+
const titles = thirds ? fixedIds.filter((id) => !!formsOf(scene.items[id], "row")[base.items[id].form]?.main.grows) : [];
|
|
1291
|
+
const titled = titles.length > 0;
|
|
1204
1292
|
const fits = (after) => {
|
|
1205
1293
|
const me = after.items[dragged];
|
|
1206
1294
|
if (!me || me.edge !== edge.id || me.inMenu) return false;
|
|
@@ -1214,6 +1302,15 @@ function edgeTargets(scene, rest, now, base, edge, dragged, reach, blockers, chr
|
|
|
1214
1302
|
const b = base.items[id];
|
|
1215
1303
|
if (!a || a.form !== b.form || a.formKind !== b.formKind || Math.abs(a.rect.x - b.rect.x) > 0.5 || Math.abs(a.rect.y - b.rect.y) > 0.5) return false;
|
|
1216
1304
|
}
|
|
1305
|
+
if (titled) {
|
|
1306
|
+
if (me.form !== 0) return false;
|
|
1307
|
+
for (const id of restEdge.items) {
|
|
1308
|
+
const a = after.items[id];
|
|
1309
|
+
const b = base.items[id];
|
|
1310
|
+
if (!a || !b || b.edge !== edge.id) continue;
|
|
1311
|
+
if (titles.includes(id) ? a.rect.width < natural(id, a.form) - 0.5 : a.form !== b.form || !!a.inMenu !== !!b.inMenu) return false;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1217
1314
|
return !chrome.some((c) => overlaps(me.rect, c));
|
|
1218
1315
|
};
|
|
1219
1316
|
const markerOf = (after) => {
|
|
@@ -1258,6 +1355,21 @@ function edgeTargets(scene, rest, now, base, edge, dragged, reach, blockers, chr
|
|
|
1258
1355
|
const r = el.rect;
|
|
1259
1356
|
const hit = edge.side === "left" ? rect(r.x, r.y, depth, r.height) : edge.side === "right" ? rect(r.x + r.width - depth, r.y, depth, r.height) : edge.side === "top" ? rect(r.x, r.y, r.width, depth) : rect(r.x, r.y + r.height - depth, r.width, depth);
|
|
1260
1357
|
const keep2 = { x: hit.x + hit.width / 2, y: hit.y + hit.height / 2 };
|
|
1358
|
+
if (thirds) {
|
|
1359
|
+
const c = base.content;
|
|
1360
|
+
const x0 = Math.max(hit.x, c.x);
|
|
1361
|
+
const x1 = Math.min(hit.x + hit.width, c.x + c.width);
|
|
1362
|
+
if (x1 - x0 <= EPS2) return [];
|
|
1363
|
+
const w = (x1 - x0) / 3;
|
|
1364
|
+
const out2 = [];
|
|
1365
|
+
ZONES.forEach((zone, k) => {
|
|
1366
|
+
if (!zoneTakes(edge, zone, scene.items[dragged].kind)) return;
|
|
1367
|
+
const part = rect(x0 + k * w, hit.y, w, hit.height);
|
|
1368
|
+
const t2 = target(`strip:${edge.id}:${zone}`, { kind: "gap", edge: edge.id, zone, at: 0 }, part, { x: part.x + part.width / 2, y: part.y + part.height / 2 });
|
|
1369
|
+
if (t2) out2.push(t2);
|
|
1370
|
+
});
|
|
1371
|
+
return out2;
|
|
1372
|
+
}
|
|
1261
1373
|
if (!zoneTakes(edge, "start", scene.items[dragged].kind)) return [];
|
|
1262
1374
|
const t = target(`strip:${edge.id}`, { kind: "gap", edge: edge.id, zone: "start", at: 0 }, hit, keep2);
|
|
1263
1375
|
return t ? [t] : [];
|
|
@@ -1289,7 +1401,7 @@ function edgeTargets(scene, rest, now, base, edge, dragged, reach, blockers, chr
|
|
|
1289
1401
|
gaps.push({ zone, at: k, line });
|
|
1290
1402
|
}
|
|
1291
1403
|
}
|
|
1292
|
-
const sorted = gaps.map((g, i) => ({ ...g, i })).sort((a, b) => a.line - b.line || a.i - b.i).filter((g, i, all) => i === 0 || Math.abs(g.line - all[i - 1].line) > EPS2);
|
|
1404
|
+
const sorted = gaps.map((g, i) => ({ ...g, i })).sort((a, b) => (thirds ? ZONE_ORDER[a.zone] - ZONE_ORDER[b.zone] : 0) || a.line - b.line || a.i - b.i).filter((g, i, all) => i === 0 || thirds && g.zone !== all[i - 1].zone || Math.abs(g.line - all[i - 1].line) > EPS2);
|
|
1293
1405
|
const out = [];
|
|
1294
1406
|
const live = sorted.map((g) => {
|
|
1295
1407
|
const place = { kind: "gap", edge: edge.id, zone: g.zone, at: g.at };
|
|
@@ -1299,9 +1411,30 @@ function edgeTargets(scene, rest, now, base, edge, dragged, reach, blockers, chr
|
|
|
1299
1411
|
const band = bandOpt === "middle" ? Infinity : Math.max(0, Number.isFinite(bandOpt) ? bandOpt : DEFAULT_HIT_BAND);
|
|
1300
1412
|
const bodies = Number.isFinite(band) ? Object.values(base.items).filter((p) => p.edge === edge.id && p.formKind === "open").map((p) => ({ a: at(p.rect), b: at(p.rect) + len(p.rect) })) : [];
|
|
1301
1413
|
const inward = edge.compact ? RAIL_REACH : 0;
|
|
1414
|
+
const solidSpans = fixedIds.filter((id) => !formsOf(scene.items[id], axisOf(edge.side))[base.items[id].form]?.main.grows).map((id) => ({ a: at(base.items[id].rect), b: at(base.items[id].rect) + len(base.items[id].rect) }));
|
|
1302
1415
|
live.forEach((g, i) => {
|
|
1303
1416
|
let from = i === 0 ? -Infinity : (live[i - 1].line + g.line) / 2;
|
|
1304
1417
|
let to = i === live.length - 1 ? Infinity : (g.line + live[i + 1].line) / 2;
|
|
1418
|
+
if (thirds) {
|
|
1419
|
+
const k = ZONE_ORDER[g.zone];
|
|
1420
|
+
const prev = live[i - 1]?.zone === g.zone ? live[i - 1] : void 0;
|
|
1421
|
+
const next = live[i + 1]?.zone === g.zone ? live[i + 1] : void 0;
|
|
1422
|
+
const a0 = main0 + length * k / 3;
|
|
1423
|
+
const b0 = main0 + length * (k + 1) / 3;
|
|
1424
|
+
const lines = live.filter((x) => x.zone === g.zone).map((x) => x.line);
|
|
1425
|
+
const first = Math.min(...lines);
|
|
1426
|
+
const last = Math.max(...lines);
|
|
1427
|
+
const a1 = Math.max(a0, ...solidSpans.filter((s) => s.b <= first + EPS2).map((s) => s.b));
|
|
1428
|
+
const b1 = Math.min(b0, ...solidSpans.filter((s) => s.a >= last - EPS2).map((s) => s.a));
|
|
1429
|
+
const [a, b] = b1 - a1 > EPS2 ? [a1, b1] : [a0, b0];
|
|
1430
|
+
const span0 = Math.min(a, ...lines);
|
|
1431
|
+
const span1 = Math.max(b, ...lines);
|
|
1432
|
+
const inThird = (x) => span1 - span0 > EPS2 ? a + (x - span0) / (span1 - span0) * (b - a) : x;
|
|
1433
|
+
const lo = k === 0 ? -Infinity : a0;
|
|
1434
|
+
const hi = k === 2 ? Infinity : b0;
|
|
1435
|
+
from = Math.max(lo, prev ? (inThird(prev.line) + inThird(g.line)) / 2 : lo);
|
|
1436
|
+
to = Math.min(hi, next ? (inThird(g.line) + inThird(next.line)) / 2 : hi);
|
|
1437
|
+
}
|
|
1305
1438
|
for (const p of bodies) {
|
|
1306
1439
|
if (p.b <= g.line + EPS2 && p.b > from) from = Math.max(from, p.b - band / 2);
|
|
1307
1440
|
if (p.a >= g.line - EPS2 && p.a < to) to = Math.min(to, p.a + band / 2);
|
|
@@ -1342,6 +1475,7 @@ export {
|
|
|
1342
1475
|
raise,
|
|
1343
1476
|
orient,
|
|
1344
1477
|
resize,
|
|
1478
|
+
setSide,
|
|
1345
1479
|
homeFor,
|
|
1346
1480
|
dockHome,
|
|
1347
1481
|
storeScene,
|
|
@@ -1350,4 +1484,4 @@ export {
|
|
|
1350
1484
|
reservedRect,
|
|
1351
1485
|
stops
|
|
1352
1486
|
};
|
|
1353
|
-
//# sourceMappingURL=chunk-
|
|
1487
|
+
//# sourceMappingURL=chunk-GCSVZGVX.js.map
|