@n-uf/placement 26.11.47 → 26.11.49

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.
@@ -2145,7 +2145,7 @@ function context(scene, dragged, options, others = []) {
2145
2145
  const item = Object.hasOwn(scene.items, dragged) ? scene.items[dragged] : void 0;
2146
2146
  if (!item || item.fixed || item.closed) return null;
2147
2147
  const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
2148
- const settle = (s) => ({ scene: s, layout: solve(s, prev) });
2148
+ const settle2 = (s) => ({ scene: s, layout: solve(s, prev) });
2149
2149
  const now = solve(scene, prev);
2150
2150
  const rest = lift(scene, dragged);
2151
2151
  const base = solve(rest, prev);
@@ -2159,7 +2159,7 @@ function context(scene, dragged, options, others = []) {
2159
2159
  dragged,
2160
2160
  kind: item.kind,
2161
2161
  reach: Math.max(0, Number.isFinite(options.endReach) ? options.endReach : 0),
2162
- settle,
2162
+ settle: settle2,
2163
2163
  isHome: (r) => placeKey(r.scene, dragged) === here,
2164
2164
  sound: soundness(scene, base, dragged),
2165
2165
  lay: layKeys(scene)
@@ -3323,8 +3323,14 @@ function lanes(scene, dragged, options = {}) {
3323
3323
  if (!found) return { ...base.regions, lanes: base.lanes };
3324
3324
  const [heldLane, list] = found;
3325
3325
  const held = list.find((r) => r.id === options.spot);
3326
- const lane = laneFrom(heldLane, list, held.layout, base.seen, dragged, base.refusals, base.halves.has(heldLane), base.share);
3327
- return { ...base.regions, lanes: base.lanes.map((l) => l.id === heldLane && lane ? lane : l) };
3326
+ const rebuilt = base.lanes.map((l) => {
3327
+ const raws = base.raws.get(l.id);
3328
+ if (!raws) return l;
3329
+ const again = laneFrom(l.id, raws, held.layout, base.seen, dragged, base.refusals, base.halves.has(l.id), base.share, base.marking, l.id === heldLane);
3330
+ if (!again) return l;
3331
+ return l.id === heldLane ? again : { ...l, marks: again.marks };
3332
+ });
3333
+ return { ...base.regions, lanes: rebuilt.map((l) => settle(l, held.layout, scene, dragged, rebuilt, options.emptyLanes)) };
3328
3334
  }
3329
3335
  function build(scene, dragged, options) {
3330
3336
  const seen = solve(scene, options.previous ? { previous: options.previous } : {});
@@ -3356,18 +3362,28 @@ function build(scene, dragged, options) {
3356
3362
  const landing = layout.items[dragged]?.rect;
3357
3363
  if (!landing) continue;
3358
3364
  const lane = p.kind === "column" ? `column:${p.side}:${columnKey(p.side, p.ring)}` : `rail:${p.side}`;
3359
- raws.push({ lane, edge: null, axis: "y", id: `${lane}/${p.kind === "rail" ? "end" : "line"}`, before: "^", next: "$", landing, layout, target: t, hit: t.hit });
3365
+ const strip = p.kind === "rail" && t.strip ? t.strip : void 0;
3366
+ raws.push({ lane, edge: null, axis: "y", id: `${lane}/${p.kind === "rail" ? "end" : "line"}`, before: "^", next: "$", landing, layout, target: t, hit: strip ?? t.hit, ...strip ? { strip: true } : {} });
3360
3367
  }
3361
3368
  }
3362
3369
  if (pitch > 0) raws.push(...pitchedSpots(scene, dragged, options, seen, raws, pitch));
3363
3370
  const byLane = /* @__PURE__ */ new Map();
3364
3371
  for (const r of raws) byLane.set(r.lane, [...byLane.get(r.lane) ?? [], r]);
3365
3372
  const halves = new Set(scene.edges.filter((e) => (e.side === "left" || e.side === "right") && !e.compact).map((e) => e.id));
3373
+ const marking = {
3374
+ pitch,
3375
+ natural: (id, axis) => {
3376
+ const main = scene.items[id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main;
3377
+ return main?.grows ? main.natural : void 0;
3378
+ },
3379
+ gap: (edge) => nonNeg(scene.edges.find((e) => e.id === edge)?.gap)
3380
+ };
3366
3381
  const shareOf = (g, size) => g === void 0 || !Number.isFinite(g) || size <= EPS ? 0.5 : clamp(g / size, 0, 1);
3367
3382
  const w = own?.rect.width ?? 0;
3368
3383
  const h = own?.rect.height ?? 0;
3369
3384
  const share = { x: w >= h ? shareOf(options.grab?.x, w) : 0.5, y: h > w ? shareOf(options.grab?.y, h) : 0.5 };
3370
- const laneList = [...byLane].map(([id, list]) => laneFrom(id, list, seen, seen, dragged, rs, halves.has(id), share)).filter((l) => !!l);
3385
+ const built = [...byLane].map(([id, list]) => laneFrom(id, list, seen, seen, dragged, rs, halves.has(id), share, marking)).filter((l) => !!l);
3386
+ const laneList = built.map((l) => settle(l, seen, scene, dragged, built, options.emptyLanes));
3371
3387
  const onLanes = new Set(laneList.map((l) => l.id));
3372
3388
  const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width > EPS && r.rect.height > EPS ? [r.rect] : []);
3373
3389
  const blocked = [
@@ -3385,9 +3401,10 @@ function build(scene, dragged, options) {
3385
3401
  refusals: rs,
3386
3402
  halves,
3387
3403
  share,
3404
+ marking,
3388
3405
  regions: {
3389
3406
  refused: rs.filter((f) => !onLanes.has(f.edge)).flatMap((f) => f.hits ?? [f.hit]),
3390
- content: seen.content,
3407
+ content: floatRegion(scene, dragged),
3391
3408
  blocked,
3392
3409
  stage: scene.stage,
3393
3410
  floatRegion: floatRegion(scene, dragged),
@@ -3397,7 +3414,7 @@ function build(scene, dragged, options) {
3397
3414
  }
3398
3415
  };
3399
3416
  }
3400
- function laneFrom(id, list, drawn, seen, dragged, rs, halves, share) {
3417
+ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, heldHere = false) {
3401
3418
  if (list.length === 0) return null;
3402
3419
  const first = list[0];
3403
3420
  const axis = first.axis;
@@ -3406,9 +3423,12 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share) {
3406
3423
  let laneRect;
3407
3424
  if (edgeLayout && edgeLayout.cross > EPS) laneRect = edgeLayout.rect;
3408
3425
  else if (edgeLayout) laneRect = axis === "x" ? rect(edgeLayout.rect.x, band.y, edgeLayout.rect.width, band.height) : rect(band.x, edgeLayout.rect.y, band.width, edgeLayout.rect.height);
3426
+ else if (list.every((r) => r.strip)) laneRect = list.map((r) => r.hit).reduce(hull2);
3409
3427
  else laneRect = list.map((r) => r.hit).reduce(hull2, band);
3410
3428
  const sorted = [...list].sort((a, b) => mid(a.landing, axis) - mid(b.landing, axis) || (a.home ? -1 : b.home ? 1 : 0));
3411
- const unique = sorted.filter((x, i) => !sorted.slice(0, i).some((y) => sameRect(y.landing, x.landing) || y.id === x.id));
3429
+ const homeAt = halves ? void 0 : list.find((r) => r.home)?.landing;
3430
+ const nearHome = (r) => !!homeAt && !r.home && Math.abs(lo(r.landing, axis) - lo(homeAt, axis)) < Math.max(0, marking.pitch) / 2;
3431
+ const unique = sorted.filter((x, i) => !nearHome(x) && !sorted.slice(0, i).some((y) => sameRect(y.landing, x.landing) || y.id === x.id));
3412
3432
  const start = lo(laneRect, axis);
3413
3433
  const end = start + len(laneRect, axis);
3414
3434
  const drawnItems = first.edge && halves ? new Map(onEdge(drawn, first.edge, dragged, axis).map((o) => [o.id, o.r])) : /* @__PURE__ */ new Map();
@@ -3418,7 +3438,12 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share) {
3418
3438
  const a = unique[i];
3419
3439
  const b = unique[i + 1];
3420
3440
  const shared = a.next === b.before && a.next !== "$" ? drawnItems.get(a.next) : void 0;
3421
- const raw = shared ? mid(shared, axis) : (lo(a.landing, axis) + len(a.landing, axis) + lo(b.landing, axis)) / 2 + (held - 0.5) * (len(a.landing, axis) + len(b.landing, axis)) / 2;
3441
+ const aEnd = lo(a.landing, axis) + len(a.landing, axis);
3442
+ const across2 = (aEnd + lo(b.landing, axis)) / 2;
3443
+ const overlap = lo(b.landing, axis) < aEnd - EPS;
3444
+ const slack = Math.max(0, marking.pitch) / 2;
3445
+ const atGrab = clamp(across2 + (held - 0.5) * (len(a.landing, axis) + len(b.landing, axis)) / 2, lo(b.landing, axis) - slack, aEnd + slack);
3446
+ const raw = shared ? mid(shared, axis) : overlap ? atGrab : across2;
3422
3447
  cuts.push(clamp(Math.max(raw, cuts[i - 1] ?? start), start, end));
3423
3448
  }
3424
3449
  const spots = unique.map((x, i) => ({
@@ -3433,12 +3458,37 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share) {
3433
3458
  const itemLen = Math.min(...unique.map((x) => len(x.landing, axis)));
3434
3459
  const refused = first.edge ? rs.filter((f) => f.edge === first.edge).flatMap((f) => (f.hits ?? [f.hit]).map((h) => ({ along: [clamp(lo(h, axis), start, end), clamp(lo(h, axis) + len(h, axis), start, end)], reason: f.reason }))).filter((f) => f.along[1] - f.along[0] >= itemLen - EPS) : [];
3435
3460
  const places = new Set(unique.map((x) => `${x.before}|${x.next}`));
3436
- const marks = first.edge ? edgeMarks(id, laneRect, axis, onEdge(drawn, first.edge, "", axis), refused, itemLen, (pair) => places.has(pair) || pair.split("|").includes(dragged), dragged) : virtualMarks(id, unique, drawn.items[dragged]);
3437
- return { id, rect: laneRect, axis, spots, refused, marks };
3461
+ const drawnEdge = first.edge ? drawn.edges[first.edge] : void 0;
3462
+ const markRect = drawnEdge && drawnEdge.cross > EPS ? drawnEdge.rect : laneRect;
3463
+ const marked = first.edge ? onEdge(drawn, first.edge, heldHere ? "" : dragged, axis).map((o) => {
3464
+ const n = o.id === dragged || halves ? void 0 : marking.natural(o.id, axis);
3465
+ return n !== void 0 && n < len(o.r, axis) ? { ...o, r: along(o.r, axis, lo(o.r, axis), lo(o.r, axis) + n) } : o;
3466
+ }) : [];
3467
+ const landings = /* @__PURE__ */ new Map();
3468
+ if (!halves) {
3469
+ for (const x of unique) if (!x.pitched && !x.home && !landings.has(`${x.before}|${x.next}`)) landings.set(`${x.before}|${x.next}`, { landing: x.landing, layout: x.layout });
3470
+ }
3471
+ const extent = (iid, r) => {
3472
+ const n = halves ? void 0 : marking.natural(iid, axis);
3473
+ return [lo(r, axis), lo(r, axis) + (n !== void 0 && n < len(r, axis) ? n : len(r, axis))];
3474
+ };
3475
+ const marks = first.edge ? edgeMarks(id, markRect, axis, marked, refused, itemLen, (pair) => places.has(pair) || pair.split("|").includes(dragged), dragged, {
3476
+ besideMin: halves || marking.pitch <= 0 ? itemLen : marking.pitch,
3477
+ gap: marking.gap(first.edge),
3478
+ landingOf: (pair) => landings.get(pair),
3479
+ extent
3480
+ }) : virtualMarks(id, unique, drawn.items[dragged]);
3481
+ return { id, rect: laneRect, axis, spots, refused, marks, ...list.every((r) => r.strip) ? { owns: true } : {} };
3438
3482
  }
3439
3483
  var along = (r, axis, a, b) => axis === "x" ? rect(a, r.y, b - a, r.height) : rect(r.x, a, r.width, b - a);
3440
3484
  var LINE2 = 2;
3441
- function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held) {
3485
+ var MIN_BOX = 8;
3486
+ var HATCH_END = 8;
3487
+ var HATCH_EDGE = 8;
3488
+ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, more) {
3489
+ const { besideMin } = more;
3490
+ const heldAt = items.find((o) => o.id === held);
3491
+ const heldSpan = heldAt ? [lo(heldAt.r, axis), lo(heldAt.r, axis) + len(heldAt.r, axis)] : null;
3442
3492
  const out = [];
3443
3493
  const start = lo(laneRect, axis);
3444
3494
  const end = start + len(laneRect, axis);
@@ -3452,7 +3502,38 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held) {
3452
3502
  const left = ends[i].id === held ? ends[i - 1]?.id ?? "^" : ends[i].id;
3453
3503
  const right = ends[i + 1].id === held ? ends[i + 2]?.id ?? "$" : ends[i + 1].id;
3454
3504
  const named = `${left}|${right}`;
3455
- if (b - a < itemLen - EPS) {
3505
+ const beside = ends[i + 1].id === held ? "before" : ends[i].id === held ? "after" : null;
3506
+ const min = beside ? Math.min(itemLen, besideMin) : itemLen;
3507
+ if (b - a < min - EPS) {
3508
+ const spot = !beside && named === pair && items.length > 0 && !isRefused2((a + b) / 2) && b - a >= besideMin - EPS ? more.landingOf(pair) : void 0;
3509
+ if (spot) {
3510
+ const own = (iid) => {
3511
+ const it = spot.layout.items[iid];
3512
+ return it && !it.inMenu && !it.floating && it.edge === lane ? more.extent(iid, it.rect) : null;
3513
+ };
3514
+ let gl = left !== "^" && (() => {
3515
+ const o = own(left);
3516
+ return !o || a - o[1] > 0.5;
3517
+ })();
3518
+ let gr = right !== "$" && (() => {
3519
+ const o = own(right);
3520
+ return !o || o[0] - b > 0.5;
3521
+ })();
3522
+ if (!gl && !gr) {
3523
+ if (right !== "$") gr = true;
3524
+ else if (left !== "^") gl = true;
3525
+ }
3526
+ let ps = [[a, b]];
3527
+ for (const f of refused) ps = ps.flatMap(([p, q]) => [[p, Math.min(q, f.along[0])], [Math.max(p, f.along[1]), q]]);
3528
+ if (heldSpan) ps = ps.flatMap(([p, q]) => [[p, Math.min(q, heldSpan[0])], [Math.max(p, heldSpan[1]), q]]);
3529
+ ps = ps.filter(([p, q]) => q - p >= MIN_BOX - EPS);
3530
+ ps.forEach(([p, q], k2) => {
3531
+ out.push({ id: `${lane}/box/${pair}${k2 ? `#${k2}` : ""}`, kind: "box", rect: along(laneRect, axis, p, q) });
3532
+ if (gl && Math.abs(p - a) < EPS) out.push({ id: `${lane}/hatch/${pair}:before`, kind: "hatch", rect: along(laneRect, axis, p, p + Math.min(HATCH_END, (q - p) / 2)) });
3533
+ if (gr && Math.abs(q - b) < EPS) out.push({ id: `${lane}/hatch/${pair}:after`, kind: "hatch", rect: along(laneRect, axis, q - Math.min(HATCH_END, (q - p) / 2), q) });
3534
+ });
3535
+ if (ps.length > 0) continue;
3536
+ }
3456
3537
  const t = Math.max(0, Math.min(LINE2, b - a)) / 2;
3457
3538
  if (items.length > 0 && named === pair && !isRefused2((a + b) / 2)) out.push({ id: `${lane}/line/${pair}`, kind: "line", rect: along(laneRect, axis, (a + b) / 2 - t, (a + b) / 2 + t) });
3458
3539
  continue;
@@ -3461,8 +3542,8 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held) {
3461
3542
  for (const f of refused) pieces = pieces.flatMap(([p, q]) => [[p, Math.min(q, f.along[0])], [Math.max(p, f.along[1]), q]]).filter(([p, q]) => q - p > EPS);
3462
3543
  let k = 0;
3463
3544
  for (const [p, q] of pieces) {
3464
- if (q - p < itemLen - EPS) continue;
3465
- const base = `${lane}/box/${named}${k++ ? `#${k - 1}` : ""}`;
3545
+ if (q - p < min - EPS) continue;
3546
+ const base = `${lane}/box/${named}${beside ? `:${beside}` : ""}${k++ ? `#${k - 1}` : ""}`;
3466
3547
  out.push({ id: out.some((m) => m.id === base) ? `${base}~2` : base, kind: "box", rect: along(laneRect, axis, p, q) });
3467
3548
  }
3468
3549
  }
@@ -3476,6 +3557,66 @@ function virtualMarks(lane, spots, held) {
3476
3557
  return { id: `${lane}/line/${s.id}`, kind: "line", rect: rect(x, l.y, 0, l.height) };
3477
3558
  });
3478
3559
  }
3560
+ function settle(l, drawn, scene, dragged, all, emptyLanes = "real") {
3561
+ const edgeOf = (id) => scene.edges.find((e) => e.id === id);
3562
+ const isDrawn = (id) => !!edgeOf(id) && (drawn.edges[id]?.cross ?? 0) > EPS;
3563
+ const across2 = (side) => side === "top" || side === "bottom" ? "x" : "y";
3564
+ const cuts = [];
3565
+ if (!isDrawn(l.id)) {
3566
+ for (const e of scene.edges) {
3567
+ const de = drawn.edges[e.id];
3568
+ if (e.id !== l.id && de && de.cross > EPS && across2(e.side) !== l.axis) cuts.push(de.rect);
3569
+ }
3570
+ if (l.axis === "y") {
3571
+ for (const o of all) if (o.id !== l.id && o.axis === "x" && !isDrawn(o.id)) cuts.push(o.rect);
3572
+ }
3573
+ }
3574
+ const empty = !isDrawn(l.id);
3575
+ const barOrRail = (edge) => {
3576
+ const e = edge ? edgeOf(edge) : void 0;
3577
+ return !!e && (e.side === "top" || e.side === "bottom" || !!e.compact);
3578
+ };
3579
+ const stays = empty ? Object.entries(drawn.items).filter(([id, it]) => id !== dragged && it.edge !== l.id && barOrRail(it.edge) && !it.floating && !it.inMenu && it.rect.width > EPS && it.rect.height > EPS).map(([, it]) => it.rect) : [];
3580
+ if (cuts.length === 0 && !(empty && (emptyLanes === "edge" || l.marks.some((m) => m.kind === "box" && stays.some((s) => overlaps3(m.rect, s)))))) return l;
3581
+ const span = (r) => [lo(r, l.axis), lo(r, l.axis) + len(r, l.axis)];
3582
+ const crosses = (r, c) => l.axis === "x" ? c.y < r.y + r.height - EPS && r.y < c.y + c.height - EPS : c.x < r.x + r.width - EPS && r.x < c.x + c.width - EPS;
3583
+ const cut2 = (r, cs) => {
3584
+ let ps = [span(r)];
3585
+ for (const c of cs) {
3586
+ if (!crosses(r, c)) continue;
3587
+ const [c0, c1] = span(c);
3588
+ ps = ps.flatMap(([p, q]) => [[p, Math.min(q, c0)], [Math.max(p, c1), q]]).filter(([p, q]) => q - p > EPS);
3589
+ }
3590
+ return ps;
3591
+ };
3592
+ const marks = [];
3593
+ for (const m of l.marks) {
3594
+ const kept = cut2(m.rect, m.kind === "box" ? [...cuts, ...stays] : cuts);
3595
+ if (m.kind === "line") {
3596
+ if (kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, l.axis)) < EPS) marks.push(m);
3597
+ continue;
3598
+ }
3599
+ kept.forEach(([p, q], i) => {
3600
+ const piece = along(m.rect, l.axis, p, q);
3601
+ const id = i ? `${m.id}~c${i}` : m.id;
3602
+ if (m.kind !== "box" || !empty || emptyLanes === "real") return void marks.push({ ...m, id, rect: piece });
3603
+ const side = edgeOf(l.id)?.side ?? (/^(rail|column):/.test(l.id) ? l.id.split(":")[1] : void 0);
3604
+ const st = scene.stage;
3605
+ let r;
3606
+ if (l.axis === "y") {
3607
+ const outerRight = side === "right" ? true : side === "left" ? false : Math.abs(piece.x + piece.width - (st.x + st.width)) <= Math.abs(piece.x - st.x);
3608
+ const t = Math.min(HATCH_EDGE, piece.width);
3609
+ r = rect(outerRight ? piece.x + piece.width - t : piece.x, piece.y, t, piece.height);
3610
+ } else {
3611
+ const outerBottom = side === "bottom" ? true : side === "top" ? false : Math.abs(piece.y + piece.height - (st.y + st.height)) <= Math.abs(piece.y - st.y);
3612
+ const t = Math.min(HATCH_EDGE, piece.height);
3613
+ r = rect(piece.x, outerBottom ? piece.y + piece.height - t : piece.y, piece.width, t);
3614
+ }
3615
+ marks.push({ id: id.replace("/box/", "/hatch/"), kind: "hatch", rect: r });
3616
+ });
3617
+ }
3618
+ return { ...l, marks };
3619
+ }
3479
3620
  var overlaps3 = (a, b) => a.x < b.x + b.width - EPS && b.x < a.x + a.width - EPS && a.y < b.y + b.height - EPS && b.y < a.y + a.height - EPS;
3480
3621
  function pitchedSpots(scene, dragged, options, seen, raws, pitch) {
3481
3622
  const out = [];
@@ -3598,6 +3739,8 @@ export {
3598
3739
  refusalTargets,
3599
3740
  stops,
3600
3741
  SPOT_PITCH,
3601
- lanes
3742
+ lanes,
3743
+ HATCH_END,
3744
+ HATCH_EDGE
3602
3745
  };
3603
- //# sourceMappingURL=chunk-VNOEEI4L.js.map
3746
+ //# sourceMappingURL=chunk-FJ5R6PMB.js.map