@n-uf/placement 26.11.20 → 26.11.21

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.
@@ -5,7 +5,7 @@ import {
5
5
  formMain,
6
6
  formSetsCross,
7
7
  wrapLines
8
- } from "./chunk-RUITEOZ7.js";
8
+ } from "./chunk-RL3QB5SM.js";
9
9
  import {
10
10
  clampInto,
11
11
  rect
@@ -84,7 +84,12 @@ function solveEdge(scene, edge, ids, length, room, previous) {
84
84
  const axis = axisOf(edge.side);
85
85
  const column = axis === "column";
86
86
  const ordered = zoneSorted(scene, ids);
87
- const formsById = (id) => formsOf(scene.items[id], axis);
87
+ const priorityOf = (id) => finite(scene.items[id].priority ?? edge.priority ?? 0, 0);
88
+ const formsById = (id) => {
89
+ const forms = formsOf(scene.items[id], axis);
90
+ const p = priorityOf(id);
91
+ return p === 0 ? forms : forms.map((f) => ({ ...f, rank: finite(f.rank ?? 0, 0) + p }));
92
+ };
88
93
  const maxOf = Number.isNaN(edge.cross.max) ? Infinity : edge.cross.max;
89
94
  const cross = { min: Math.min(px(edge.cross.min), room), max: Math.min(maxOf, room), rail: Math.min(px(edge.cross.rail ?? 30), room) };
90
95
  const base = {
@@ -422,22 +427,26 @@ function solve(given, options = {}) {
422
427
  }
423
428
  }
424
429
  const g = evaluate(auto);
425
- const open2 = cols.filter((c) => c.edge.column === true && c.visible.length > 0).map((c) => c.min);
430
+ const openMin = (ids, least) => Math.max(
431
+ least,
432
+ ...ids.map((id) => {
433
+ const f = formsOf(scene.items[id], "column")[0];
434
+ return f && formSetsCross(f) ? formCrossMin(f) : 0;
435
+ })
436
+ );
437
+ const open2 = cols.filter((c) => c.edge.column === true && c.visible.length > 0).map((c) => c.hand ? openMin(c.visible, px(c.edge.cross.min)) : c.min);
426
438
  const templates = ["left", "right"].flatMap((s) => {
427
439
  const t = scene.columns?.[s];
428
440
  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)];
441
+ const takes = Object.values(scene.items).filter((it) => !it.fixed && !it.closed && t.accepts.includes(it.kind));
442
+ return [openMin(takes.map((it) => it.id), px(t.cross.min))];
435
443
  });
436
444
  const colMins = open2.length > 0 ? open2 : templates;
437
445
  if (cmin !== void 0 && colMins.length > 0) {
446
+ const width = area3.width - (scene.insetWhen === "docked" && !docked ? px(scene.inset?.left) + px(scene.inset?.right) : 0);
438
447
  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 });
448
+ columnRoom = width >= need - EPS;
449
+ if (!columnRoom) notes.push({ code: "no-column-room", width, need });
441
450
  }
442
451
  for (const c of shrinkOrder) {
443
452
  const w = g.widths.get(c);
@@ -1034,6 +1043,73 @@ function cutClear(hit, blockers, keep2) {
1034
1043
  }
1035
1044
  return area(h) > EPS2 ? h : null;
1036
1045
  }
1046
+ var GAP_KEEP = 16;
1047
+ function homeOnlyOverItsPlace(out, now) {
1048
+ const dragged = out[0]?.item;
1049
+ const mine = dragged !== void 0 ? now.items[dragged] : void 0;
1050
+ const side = mine?.edge ? now.edges[mine.edge]?.side : void 0;
1051
+ if (!mine || !side) return;
1052
+ const column = side === "left" || side === "right";
1053
+ const r = mine.rect;
1054
+ const band = DEFAULT_HIT_BAND / 2;
1055
+ const edgeOf = (t) => t.id.startsWith("gap:") ? t.id.split(":")[1] : void 0;
1056
+ const zoneOfId = (t) => t.id.startsWith("gap:") ? t.id.split(":")[2] : void 0;
1057
+ const span = (x) => column ? [x.hit.y, x.hit.y + x.hit.height] : [x.hit.x, x.hit.x + x.hit.width];
1058
+ const cross = (x) => column ? [x.hit.x, x.hit.x + x.hit.width] : [x.hit.y, x.hit.y + x.hit.height];
1059
+ const make = (x, from, to, c) => {
1060
+ const [c02, c12] = c ?? cross(x);
1061
+ return { ...x, hit: column ? rect(c02, from, c12 - c02, to - from) : rect(from, c02, to - from, c12 - c02) };
1062
+ };
1063
+ const homes = out.filter((t) => t.place.kind === "home" && edgeOf(t) === mine.edge);
1064
+ const mid = column ? r.y + r.height / 2 : r.x + r.width / 2;
1065
+ let h0 = (column ? r.y : r.x) - band;
1066
+ let h1 = (column ? r.y + r.height : r.x + r.width) + band;
1067
+ const c0 = Math.min(...homes.map((h) => cross(h)[0]));
1068
+ const c1 = Math.max(...homes.map((h) => cross(h)[1]));
1069
+ const first = homes[0];
1070
+ for (const h of homes.slice(1)) out.splice(out.indexOf(h), 1);
1071
+ const at = first ? out.indexOf(first) : -1;
1072
+ if (first) out.splice(at, 1);
1073
+ for (let i = 0; i < out.length; i++) {
1074
+ const x = out[i];
1075
+ if (x.place.kind !== "gap" || edgeOf(x) !== mine.edge) continue;
1076
+ const [s0, s1] = span(x);
1077
+ if (s1 <= h0 + EPS2 || s0 >= h1 - EPS2) continue;
1078
+ const keep2 = Math.min(GAP_KEEP, s1 - s0);
1079
+ if (s0 < h0) {
1080
+ const e = Math.min(s1, Math.max(h0, s0 + keep2));
1081
+ out[i] = make(x, s0, e);
1082
+ h0 = Math.max(h0, e);
1083
+ } else if (s1 > h1) {
1084
+ const b = Math.max(s0, Math.min(h1, s1 - keep2));
1085
+ out[i] = make(x, b, s1);
1086
+ h1 = Math.min(h1, b);
1087
+ } else {
1088
+ const line = x.marker ? column ? x.marker.y : x.marker.x : (s0 + s1) / 2;
1089
+ let a = Math.min(Math.max(line - keep2 / 2, s0), s1 - keep2);
1090
+ if (a <= mid + 1 && a + keep2 >= mid - 1) a = (s0 + s1) / 2 < mid ? mid - 1 - keep2 : mid + 1;
1091
+ out[i] = make(x, a, a + keep2);
1092
+ if (a + keep2 <= mid + EPS2) h0 = Math.max(h0, a + keep2);
1093
+ else h1 = Math.min(h1, a);
1094
+ }
1095
+ }
1096
+ const others = (x) => out.filter((y) => y !== x && y.place.kind === "gap" && edgeOf(y) === mine.edge).map(span);
1097
+ for (const h of homes) {
1098
+ const [a0, a1] = span(h);
1099
+ const near = out.filter((x) => x.place.kind === "gap" && edgeOf(x) === mine.edge && zoneOfId(x) === zoneOfId(h));
1100
+ const before = near.find((x) => Math.abs(span(x)[1] - a0) < 1);
1101
+ const after = near.find((x) => Math.abs(span(x)[0] - a1) < 1);
1102
+ if (before && a0 < h0 - EPS2) {
1103
+ const stop = Math.min(a1, h0, ...others(before).filter(([b]) => b >= span(before)[1] - EPS2).map(([b]) => b));
1104
+ if (stop > span(before)[1]) out[out.indexOf(before)] = make(before, span(before)[0], stop);
1105
+ }
1106
+ if (after && a1 > h1 + EPS2) {
1107
+ const stop = Math.max(a0, h1, ...others(after).filter(([, e]) => e <= span(after)[0] + EPS2).map(([, e]) => e));
1108
+ if (stop < span(after)[0]) out[out.indexOf(after)] = make(after, stop, span(after)[1]);
1109
+ }
1110
+ }
1111
+ if (first && h1 - h0 > EPS2) out.splice(Math.min(at, out.length), 0, make(first, h0, h1, [c0, c1]));
1112
+ }
1037
1113
  function targets(scene, dragged, options = {}) {
1038
1114
  const item = Object.hasOwn(scene.items, dragged) ? scene.items[dragged] : void 0;
1039
1115
  if (!item || item.fixed || item.closed) return [];
@@ -1092,6 +1168,7 @@ function targets(scene, dragged, options = {}) {
1092
1168
  if (own2) out.push({ id: t.id, priority: t.priority, hit: t.hit, item: dragged, place: { kind: "home" }, after: () => ({ scene, layout: now }) });
1093
1169
  else if (sound(t.after({ x: 0, y: 0 }).layout)) out.push(t);
1094
1170
  }
1171
+ homeOnlyOverItsPlace(out, now);
1095
1172
  const edgeOfGap = (t) => t.place.kind === "gap" ? rest.edges.find((e) => e.id === t.place.edge) : void 0;
1096
1173
  const plainGapHits = out.filter((t) => t.id.startsWith("gap:") && !edgeOfGap(t)?.compact).map((t) => t.hit);
1097
1174
  for (let i = 0; i < out.length; i++) {
@@ -1114,6 +1191,8 @@ function targets(scene, dragged, options = {}) {
1114
1191
  const x1 = Math.min(t.hit.x + t.hit.width, c.x + c.width);
1115
1192
  const y1 = Math.min(t.hit.y + t.hit.height, c.y + c.height);
1116
1193
  const docks = [...Object.entries(base.edges), ...Object.entries(now.edges).filter(([id]) => id !== now.items[dragged]?.edge)].filter(([id, d]) => id !== e.id && area(d.rect) > EPS2).map(([, d]) => d.rect);
1194
+ const mineNow = now.items[dragged];
1195
+ if (mineNow?.edge && !mineNow.floating) docks.push(mineNow.rect);
1117
1196
  const h = e.compact ? t.hit : x1 - x0 > EPS2 && y1 - y0 > EPS2 ? cutAway(rect(x0, y0, x1 - x0, y1 - y0), docks) : null;
1118
1197
  if (!h) {
1119
1198
  out.splice(i, 1);
@@ -1255,6 +1334,35 @@ function railTargets(scene, rest, base, side, dragged, blockers, settle) {
1255
1334
  });
1256
1335
  return out;
1257
1336
  }
1337
+ function refusals(scene, dragged, options = {}) {
1338
+ const item = Object.hasOwn(scene.items, dragged) ? scene.items[dragged] : void 0;
1339
+ if (!item || item.fixed || item.closed) return [];
1340
+ const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
1341
+ const ts = targets(scene, dragged, options).filter((t) => !t.free);
1342
+ const base = solve(lift(scene, dragged), prev);
1343
+ const hits = ts.map((t) => t.hit);
1344
+ const out = [];
1345
+ const add = (edge, zone, hit, reason) => {
1346
+ const clear = cutAway(hit, hits);
1347
+ if (clear) out.push({ id: `refuse:${edge}:${zone}`, edge, zone, hit: clear, reason });
1348
+ };
1349
+ for (const e of scene.edges) {
1350
+ const r = base.edges[e.id]?.rect;
1351
+ if (!r || r.width <= EPS2 || r.height <= EPS2) continue;
1352
+ const bar = (e.side === "top" || e.side === "bottom") && !e.compact;
1353
+ if (!bar) {
1354
+ if (!e.accepts.includes(item.kind)) add(e.id, "start", r, "not-accepted");
1355
+ continue;
1356
+ }
1357
+ ZONES.forEach((zone, k) => {
1358
+ const third = rect(r.x + r.width * k / 3, r.y, r.width / 3, r.height);
1359
+ const mine = ts.some((t) => (t.place.kind === "gap" || t.place.kind === "home") && t.id.startsWith(`gap:${e.id}:`) && overlaps(t.hit, third));
1360
+ if (mine) return;
1361
+ add(e.id, zone, third, zoneTakes(e, zone, item.kind) ? "no-room" : "not-accepted");
1362
+ });
1363
+ }
1364
+ return out;
1365
+ }
1258
1366
  var SIDE_RANK = { left: 0, top: 1, bottom: 2, right: 3 };
1259
1367
  function stops(scene, dragged, options = {}) {
1260
1368
  const list = targets(scene, dragged, options).filter((t) => t.place.kind !== "home" && t.place.kind !== "none");
@@ -1482,6 +1590,7 @@ export {
1482
1590
  readScene,
1483
1591
  targets,
1484
1592
  reservedRect,
1593
+ refusals,
1485
1594
  stops
1486
1595
  };
1487
- //# sourceMappingURL=chunk-GCSVZGVX.js.map
1596
+ //# sourceMappingURL=chunk-TFM4S3L3.js.map