@n-uf/motion 26.11.48 → 26.11.50
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 +55 -0
- package/README.md +26 -424
- package/dist/drag.d.ts +96 -3
- package/dist/drag.js +139 -6
- package/dist/drag.js.map +1 -1
- package/package.json +2 -2
package/dist/drag.d.ts
CHANGED
|
@@ -495,12 +495,22 @@ declare function previewPlan<T extends DragTarget>(frame: Pick<DragFrame<T>, "sh
|
|
|
495
495
|
* held one too, once its own gate passes and only once the pointer came into it from outside since the lift. Within
|
|
496
496
|
* `margins.lift` of the lift point (`options.lift`, else the first point; fixed for the drag) an owning lane takes the
|
|
497
497
|
* pointer by no gate, so a pointer brought back there is in the item's own lane, not the strip. Elsewhere in the strip
|
|
498
|
-
* a slow slide along it can take the pointer before it is back at the lift point.
|
|
498
|
+
* a slow slide along it can take the pointer before it is back at the lift point. More generally, within
|
|
499
|
+
* `margins.lift` of the lift point the lane is the item's own (`home.lane`) whenever the pointer lies in it, whatever
|
|
500
|
+
* lane the pointer came through (a plain lane's band over the home lane's corner included), and its spot is the
|
|
501
|
+
* item's own (`home.spot`; a sliding one still lets the landing follow the hand and snap): away and back to where the
|
|
502
|
+
* item was lifted is home on every layout, so no nudge to a neighboring spot is reachable within `lift` of the press.
|
|
503
|
+
* The zone is a held state like a held lane: the drag starts in it, leaves it past `lift` and re-enters only within
|
|
504
|
+
* `lift - spot`, so a wobble at its edge never flips a cut near the press.
|
|
499
505
|
* - **Along a lane** the spot changes once the pointer is `spot` px past the boundary; where the change moves another
|
|
500
506
|
* item (the two spots' `others` keys differ), on a step of at most `step`, or once the held landing trails the
|
|
501
507
|
* pointer by more than `trail`: the item chases only as far as it must. A change that moves only the held item
|
|
502
508
|
* follows the hand at any speed. With `regionsFor`, a reflowing change is kept only if, in the new spot's own regions
|
|
503
509
|
* (its room open), the pointer still lies in that spot's stretch: the room shifting the boundary never bounces it.
|
|
510
|
+
* - **A sliding spot** (`slide`: a free stretch as one spot) lands where the hand is: its landing moved along the lane to
|
|
511
|
+
* the pointer less the grab (`grab`), clamped to its range, and snapped to its ends, the item's own place or a dock
|
|
512
|
+
* inside within `snapDistance`. Nothing reflows inside it, so there are no steps there; a step comes only where the
|
|
513
|
+
* order changes (passing a neighbor), as between any two spots. A release reads where it starts (`at`) once.
|
|
504
514
|
* - **Outside every lane:** a refused place, refused; open space (`"open"`: the content less what blocks it, the page),
|
|
505
515
|
* the float at its landing; outside the stage (past `edge`), nowhere; else (docked content that takes nothing and
|
|
506
516
|
* refuses nothing) refused.
|
|
@@ -525,7 +535,32 @@ interface LandingSpot {
|
|
|
525
535
|
* item. Absent: every change to or from it counts as moving others.
|
|
526
536
|
*/
|
|
527
537
|
readonly others?: string;
|
|
538
|
+
/**
|
|
539
|
+
* A sliding spot (a free stretch exposed as one spot): over it the landing follows the pointer, `landing` moved along
|
|
540
|
+
* the lane to the pointer less the grab, clamped to `[from, to]` and snapped to a point of `snaps` within
|
|
541
|
+
* `snapDistance`, else on whole pixels (`step`). Absent: the landing is `landing`.
|
|
542
|
+
*/
|
|
543
|
+
readonly slide?: LandingSlide;
|
|
544
|
+
}
|
|
545
|
+
/** A sliding spot's range: where its landing's start may lie along the lane, and the points it snaps to. */
|
|
546
|
+
interface LandingSlide {
|
|
547
|
+
/** The landing's start at the stretch's start (flush against the neighbor before it), px along the lane. */
|
|
548
|
+
readonly from: number;
|
|
549
|
+
/** The landing's start at the stretch's end (flush against the neighbor after it), px along the lane. */
|
|
550
|
+
readonly to: number;
|
|
551
|
+
/** The starts it snaps to: its two ends, the item's own place where it lies here, any discrete dock inside. */
|
|
552
|
+
readonly snaps: readonly number[];
|
|
553
|
+
/** How near a snap point the landing's start snaps to it, px (default `SNAP_DISTANCE`). */
|
|
554
|
+
readonly snapDistance?: number;
|
|
555
|
+
/**
|
|
556
|
+
* The grain of a start that snaps to nothing, px: a multiple of `step`, clamped to `[from, to]` (default 1, whole
|
|
557
|
+
* pixels; 0: wherever the pointer puts it). Give the step the spot's commit uses, so the frame, the release's `at`
|
|
558
|
+
* and the commit agree.
|
|
559
|
+
*/
|
|
560
|
+
readonly step?: number;
|
|
528
561
|
}
|
|
562
|
+
/** How near a sliding spot's snap point its landing snaps to it, px. */
|
|
563
|
+
declare const SNAP_DISTANCE = 8;
|
|
529
564
|
/**
|
|
530
565
|
* A place guide's mark, in the layout as drawn: a line between two items that touch, a box over free room the item
|
|
531
566
|
* lands in, a hatch over the part of a neighbor that gives way where the room is shorter than the item.
|
|
@@ -624,6 +659,13 @@ interface LandingOptions {
|
|
|
624
659
|
};
|
|
625
660
|
/** Where the item was lifted (the press), in the regions' space; default the first point `update` gets. */
|
|
626
661
|
readonly lift?: Point;
|
|
662
|
+
/**
|
|
663
|
+
* Where the pointer holds the item, from its top left corner as it is now, px (the press's, as `lanes()` takes it).
|
|
664
|
+
* Over a sliding spot the landing's start is the pointer less this, along the item's own length (its longer side; a
|
|
665
|
+
* landing of another length at the same share of it); across it, and in a lane across its length, the middle.
|
|
666
|
+
* Default: the middle of `regions.item`.
|
|
667
|
+
*/
|
|
668
|
+
readonly grab?: Point;
|
|
627
669
|
readonly margins?: Partial<LandingMargins>;
|
|
628
670
|
readonly gates?: Partial<LandingGates>;
|
|
629
671
|
readonly approach?: Partial<LandingApproach>;
|
|
@@ -659,12 +701,17 @@ interface LandingFrame {
|
|
|
659
701
|
*/
|
|
660
702
|
readonly pending?: string;
|
|
661
703
|
}
|
|
662
|
-
/**
|
|
704
|
+
/**
|
|
705
|
+
* What a release lands: a spot (`home` when it is the item's own place), the float at `rect`, or nothing. On a sliding
|
|
706
|
+
* spot, `at` is where the landing starts along the lane, as the frame shows it (read once, at the release: a snap
|
|
707
|
+
* point, else on the spot's `step`), and `home` holds only where that is the item's own place.
|
|
708
|
+
*/
|
|
663
709
|
type LandingRelease = {
|
|
664
710
|
readonly kind: "spot";
|
|
665
711
|
readonly lane: string;
|
|
666
712
|
readonly spot: string;
|
|
667
713
|
readonly home: boolean;
|
|
714
|
+
readonly at?: number;
|
|
668
715
|
} | {
|
|
669
716
|
readonly kind: "float";
|
|
670
717
|
readonly rect: Rect;
|
|
@@ -721,4 +768,50 @@ declare function createGripPress(options?: {
|
|
|
721
768
|
readonly double?: Partial<DoubleClick>;
|
|
722
769
|
}): GripPress;
|
|
723
770
|
|
|
724
|
-
|
|
771
|
+
/** A guide to place: any record with a `kind` and a `rect` (a landing model's `LandingGuide`, a lane's marks). */
|
|
772
|
+
interface PlacedGuide {
|
|
773
|
+
readonly kind: "line" | "box" | "hatch";
|
|
774
|
+
readonly rect: Rect;
|
|
775
|
+
}
|
|
776
|
+
/** A rect guides stay clear of, with a clearance of its own, px (0: guides may lie flush against it). */
|
|
777
|
+
interface ClearRect {
|
|
778
|
+
readonly rect: Rect;
|
|
779
|
+
readonly clearance: number;
|
|
780
|
+
/**
|
|
781
|
+
* The guide kinds this rect constrains (default: all). Content a thin guide keeps clear of, but an empty lane's
|
|
782
|
+
* real-size box lies over (it moves the content aside), is `kinds: ["line", "hatch"]`.
|
|
783
|
+
*/
|
|
784
|
+
readonly kinds?: readonly PlacedGuide["kind"][];
|
|
785
|
+
}
|
|
786
|
+
interface GuideRectsOptions {
|
|
787
|
+
/** The area guides are drawn in: the window's inside (inside its border), px. */
|
|
788
|
+
readonly inside: Rect;
|
|
789
|
+
/** How far inside `inside` every guide stays, px (default 2). */
|
|
790
|
+
readonly inset?: number;
|
|
791
|
+
/**
|
|
792
|
+
* Rects guides stay clear of. A plain `Rect` keeps `clearance` px (the default gap) for every kind: something guides
|
|
793
|
+
* must keep apart from, such as the held item's outline. `{ rect, clearance, kinds? }` keeps its own, for the kinds
|
|
794
|
+
* it names: `{ rect, clearance: 0, kinds: ["line", "hatch"] }` is a boundary a thin guide may run flush against (the
|
|
795
|
+
* content: a column's panels under an empty lane's thin edge) while a box may still lie over it.
|
|
796
|
+
*/
|
|
797
|
+
readonly clear?: readonly (Rect | ClearRect)[];
|
|
798
|
+
/** How far clear of a plain `clear` rect a guide stays, px (default 2): "clear of" means at least this far. */
|
|
799
|
+
readonly clearance?: number;
|
|
800
|
+
/** The least thickness a thin guide keeps, px (default 2); thinner, it is not drawn. */
|
|
801
|
+
readonly minThickness?: number;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Where to draw guides: every guide inside `inside` by `inset`, and at least `clearance` px clear of every `clear` rect
|
|
805
|
+
* ("clear of" means at least that far: a plain rect keeps the options' `clearance`, default 2; `{ rect, clearance }`
|
|
806
|
+
* keeps its own, so pass `{ rect, clearance: 0 }` for content a thin guide may run flush against, and `kinds` to
|
|
807
|
+
* constrain only some kinds of guide, default all). A box is clipped,
|
|
808
|
+
* then cut on the side that faces each clear rect (the clear rect grown by its clearance is taken out of it, and the
|
|
809
|
+
* largest remaining part, left, right, above or below, is kept). A thin guide (a line, a striped strip or end: its
|
|
810
|
+
* shorter side is its thickness) keeps its thickness and moves inside rather than being clipped, so a line at a lane's
|
|
811
|
+
* far end is as thick as at its head. Then it is thinned, from the content side, to stay that far clear of `clear`, so
|
|
812
|
+
* a thin strip at the window's side lies between the inset and the content, the same on both sides. A guide with nothing left (or a thin one under `minThickness`) is left out. Pure; the guides come
|
|
813
|
+
* back as given with their placed `rect`, the same object where nothing moved.
|
|
814
|
+
*/
|
|
815
|
+
declare function guideRects<G extends PlacedGuide>(guides: readonly G[], options: GuideRectsOptions): G[];
|
|
816
|
+
|
|
817
|
+
export { type ClearRect, DRAG_DEFAULTS, DRAG_PREVIEW_DEFAULT, DoubleClick, type DragFrame, type DragIntent, type DragIntentOptions, type DragIntentState, type DragKeys, type DragModifiers, type DragPreview, type DragTarget, type DragTuning, type DropPreviewMode, type EmptyLanes, type GripPress, type GripRelease, type GuideRectsOptions, LANDING_APPROACH, LANDING_GATES, LANDING_MARGINS, LANDING_TOUCH_MARGINS, type LandingApproach, type LandingFrame, type LandingGates, type LandingGuide, type LandingLane, type LandingMargins, type LandingMark, type LandingModel, type LandingOptions, type LandingRegion, type LandingRegions, type LandingRelease, type LandingSlide, type LandingSpot, type LiftDecision, type ModifierKey, PLACE_GUIDES_DEFAULT, type PlaceGuides, type PlacedGuide, type PreviewPlan, REFUSAL_RANK, SNAP_DISTANCE, createDragIntent, createGripPress, createLandingModel, guideRects, inRect, liftDecision, pickRank, previewPlan, targetAt };
|
package/dist/drag.js
CHANGED
|
@@ -279,6 +279,8 @@ function createDragIntent(options) {
|
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
// src/drag/landing.ts
|
|
282
|
+
var SLIDE_STEP = 1;
|
|
283
|
+
var SNAP_DISTANCE = 8;
|
|
282
284
|
var LANDING_MARGINS = { exit: 12, spot: 6, edge: 48, lift: 16 };
|
|
283
285
|
var LANDING_TOUCH_MARGINS = { exit: 16, spot: 8, edge: 48, lift: 16 };
|
|
284
286
|
var LANDING_GATES = { path: 40, depth: 8, still: 1.5, step: 3, trail: 40, rest: 22, pause: 60 };
|
|
@@ -322,6 +324,7 @@ function createLandingModel(options) {
|
|
|
322
324
|
let last = null;
|
|
323
325
|
let moved = null;
|
|
324
326
|
let liftAt = options.lift ?? null;
|
|
327
|
+
let inLiftZone = true;
|
|
325
328
|
let lastStep = 0;
|
|
326
329
|
const pathIn = /* @__PURE__ */ new Map();
|
|
327
330
|
const slide = /* @__PURE__ */ new Map();
|
|
@@ -329,6 +332,7 @@ function createLandingModel(options) {
|
|
|
329
332
|
let approached = null;
|
|
330
333
|
let previous = laneId ? "lane" : "open";
|
|
331
334
|
let frame = { region: previous, lane: laneId, spot: spotId, landing: null, room: !!spotId, guides: [], shift: false };
|
|
335
|
+
let landedOn = null;
|
|
332
336
|
const laneIn = (regions, id) => id ? regions.lanes.find((l) => l.id === id) : void 0;
|
|
333
337
|
const spotIn = (lane, id) => lane && id ? lane.spots.find((s) => s.id === id) : void 0;
|
|
334
338
|
function pick(lane, a) {
|
|
@@ -346,6 +350,32 @@ function createLandingModel(options) {
|
|
|
346
350
|
}
|
|
347
351
|
return best;
|
|
348
352
|
}
|
|
353
|
+
function landingAt(lane, spot, p, item) {
|
|
354
|
+
const s = spot.slide;
|
|
355
|
+
if (!s) return spot.landing;
|
|
356
|
+
const ax = lane.axis;
|
|
357
|
+
const long = item.width >= item.height ? "x" : "y";
|
|
358
|
+
const size = long === "x" ? item.width : item.height;
|
|
359
|
+
const g = options.grab ? long === "x" ? options.grab.x : options.grab.y : size / 2;
|
|
360
|
+
const share = ax === long && size > 0 && Number.isFinite(g) ? Math.min(1, Math.max(0, g / size)) : 0.5;
|
|
361
|
+
const length = ax === "x" ? spot.landing.width : spot.landing.height;
|
|
362
|
+
const lo = Math.min(s.from, s.to);
|
|
363
|
+
const hi = Math.max(s.from, s.to);
|
|
364
|
+
const free = Math.min(hi, Math.max(lo, alongOf(lane, p) - share * length));
|
|
365
|
+
const reach = s.snapDistance ?? SNAP_DISTANCE;
|
|
366
|
+
let at = free;
|
|
367
|
+
let best = Infinity;
|
|
368
|
+
for (const q of s.snaps) {
|
|
369
|
+
const d = Math.abs(q - free);
|
|
370
|
+
if (d <= reach && d < best) {
|
|
371
|
+
best = d;
|
|
372
|
+
at = q;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const step = s.step ?? SLIDE_STEP;
|
|
376
|
+
if (best === Infinity && step > 0) at = Math.min(hi, Math.max(lo, Math.round(free / step) * step));
|
|
377
|
+
return ax === "x" ? { ...spot.landing, x: at } : { ...spot.landing, y: at };
|
|
378
|
+
}
|
|
349
379
|
function along(lane, p, step) {
|
|
350
380
|
const regions = heldRegions(spotId);
|
|
351
381
|
const held2 = laneIn(regions, lane.id) ?? lane;
|
|
@@ -441,14 +471,30 @@ function createLandingModel(options) {
|
|
|
441
471
|
const touching = held2 ? regions.lanes.find((l) => l.id !== held2.id && strictlyIn(l.rect, p) && touches(l.rect, held2.rect) && !inside(held2.rect, p, margins.exit)) : void 0;
|
|
442
472
|
const sl = touching ? slide.get(touching.id) : void 0;
|
|
443
473
|
const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along;
|
|
444
|
-
const
|
|
474
|
+
const liftR = margins.lift ?? 16;
|
|
475
|
+
if (liftAt) {
|
|
476
|
+
const far = Math.hypot(p.x - liftAt.x, p.y - liftAt.y);
|
|
477
|
+
inLiftZone = far <= (inLiftZone ? liftR : Math.max(0, liftR - margins.spot));
|
|
478
|
+
}
|
|
479
|
+
const nearLift = !!liftAt && inLiftZone;
|
|
445
480
|
const owner = nearLift ? void 0 : regions.lanes.find((l) => l.owns && l.id !== held2?.id && cameIn.has(l.id) && strictlyIn(l.rect, p) && gate(l));
|
|
446
|
-
const
|
|
447
|
-
|
|
481
|
+
const ownLane = nearLift && options.home ? laneIn(regions, options.home.lane) : void 0;
|
|
482
|
+
const homeHere = ownLane && strictlyIn(ownLane.rect, p) ? ownLane : void 0;
|
|
483
|
+
const next = homeHere ? void 0 : owner ?? (touching && (gate(touching) || slid) ? touching : void 0);
|
|
484
|
+
if (homeHere) {
|
|
485
|
+
const s = spotIn(homeHere, options.home.spot) ?? pick(homeHere, alongOf(homeHere, p));
|
|
486
|
+
laneId = homeHere.id;
|
|
487
|
+
spotId = s?.id ?? null;
|
|
488
|
+
region = s ? "lane" : "refused";
|
|
489
|
+
} else if (held2 && !next && (touching || inside(held2.rect, p, margins.exit))) {
|
|
448
490
|
const s = along(held2, p, step);
|
|
449
491
|
spotId = s?.id ?? spotId;
|
|
450
492
|
region = s ? "lane" : "refused";
|
|
451
493
|
if (!s) spotId = null;
|
|
494
|
+
if (!s && !strictlyIn(held2.rect, p)) {
|
|
495
|
+
const others = regions.lanes.filter((l) => l.id !== held2.id && strictlyIn(l.rect, p));
|
|
496
|
+
if (others.length > 0) pending = others.reduce((a, b) => depthIn(b.rect, p, regions.stage) > depthIn(a.rect, p, regions.stage) ? b : a).id;
|
|
497
|
+
}
|
|
452
498
|
} else {
|
|
453
499
|
laneId = spotId = null;
|
|
454
500
|
const lanesHere = regions.lanes.filter((l) => strictlyIn(l.rect, p) && !(l.owns && nearLift));
|
|
@@ -475,8 +521,10 @@ function createLandingModel(options) {
|
|
|
475
521
|
previous = region;
|
|
476
522
|
const shown = shift && (region === "lane" || region === "open") ? "open" : region;
|
|
477
523
|
const r2 = heldRegions(spotId);
|
|
478
|
-
const
|
|
479
|
-
const
|
|
524
|
+
const heldLane = laneIn(r2, laneId);
|
|
525
|
+
const spot = spotIn(heldLane, spotId);
|
|
526
|
+
landedOn = shown === "lane" && spot && heldLane ? { spot, axis: heldLane.axis } : null;
|
|
527
|
+
const landing = shown === "lane" ? spot && heldLane ? landingAt(heldLane, spot, p, r2.item) : null : shown === "open" ? options.floatLanding?.(p) ?? null : null;
|
|
480
528
|
frame = {
|
|
481
529
|
region: shown,
|
|
482
530
|
lane: laneId,
|
|
@@ -492,7 +540,16 @@ function createLandingModel(options) {
|
|
|
492
540
|
return {
|
|
493
541
|
update,
|
|
494
542
|
release() {
|
|
495
|
-
if (frame.region === "lane" && frame.lane && frame.spot)
|
|
543
|
+
if (frame.region === "lane" && frame.lane && frame.spot) {
|
|
544
|
+
const ownSpot = !!options.home && options.home.spot === frame.spot && options.home.lane === frame.lane;
|
|
545
|
+
const on = landedOn;
|
|
546
|
+
if (on?.spot.slide && frame.landing) {
|
|
547
|
+
const start = (r) => on.axis === "x" ? r.x : r.y;
|
|
548
|
+
const at = start(frame.landing);
|
|
549
|
+
return { kind: "spot", lane: frame.lane, spot: frame.spot, home: ownSpot && Math.abs(at - start(on.spot.landing)) < 1e-6, at };
|
|
550
|
+
}
|
|
551
|
+
return { kind: "spot", lane: frame.lane, spot: frame.spot, home: ownSpot };
|
|
552
|
+
}
|
|
496
553
|
if (frame.region === "open" && frame.landing) return { kind: "float", rect: frame.landing };
|
|
497
554
|
return null;
|
|
498
555
|
},
|
|
@@ -578,6 +635,80 @@ function createGripPress(options = {}) {
|
|
|
578
635
|
}
|
|
579
636
|
};
|
|
580
637
|
}
|
|
638
|
+
|
|
639
|
+
// src/drag/guide-rects.ts
|
|
640
|
+
var EPS = 1e-6;
|
|
641
|
+
function guideRects(guides, options) {
|
|
642
|
+
const inset = Number.isFinite(options.inset) ? Math.max(0, options.inset) : 2;
|
|
643
|
+
const min = Number.isFinite(options.minThickness) ? Math.max(0, options.minThickness) : 2;
|
|
644
|
+
const same = (a, b) => Math.abs(a.x - b.x) < EPS && Math.abs(a.y - b.y) < EPS && Math.abs(a.width - b.width) < EPS && Math.abs(a.height - b.height) < EPS;
|
|
645
|
+
const place = (g, rect) => same(g.rect, rect) ? g : { ...g, rect };
|
|
646
|
+
const x0 = options.inside.x + inset;
|
|
647
|
+
const y0 = options.inside.y + inset;
|
|
648
|
+
const x1 = options.inside.x + options.inside.width - inset;
|
|
649
|
+
const y1 = options.inside.y + options.inside.height - inset;
|
|
650
|
+
const gap = Number.isFinite(options.clearance) ? Math.max(0, options.clearance) : 2;
|
|
651
|
+
const allClear = (options.clear ?? []).map(
|
|
652
|
+
(c) => "rect" in c ? { k: c.rect, gap: Number.isFinite(c.clearance) ? Math.max(0, c.clearance) : gap, ...c.kinds ? { kinds: c.kinds } : {} } : { k: c, gap }
|
|
653
|
+
);
|
|
654
|
+
const out = [];
|
|
655
|
+
for (const g of guides) {
|
|
656
|
+
const r = g.rect;
|
|
657
|
+
const clear = allClear.filter((c) => !c.kinds || c.kinds.includes(g.kind));
|
|
658
|
+
if (g.kind === "box") {
|
|
659
|
+
let a = Math.max(r.x, x0);
|
|
660
|
+
let b = Math.max(r.y, y0);
|
|
661
|
+
let c = Math.min(r.x + r.width, x1);
|
|
662
|
+
let d = Math.min(r.y + r.height, y1);
|
|
663
|
+
for (const { k, gap: gap2 } of clear) {
|
|
664
|
+
const k0 = k.x - gap2;
|
|
665
|
+
const k1 = k.x + k.width + gap2;
|
|
666
|
+
const l0 = k.y - gap2;
|
|
667
|
+
const l1 = k.y + k.height + gap2;
|
|
668
|
+
if (c - a <= EPS || d - b <= EPS) break;
|
|
669
|
+
if (k1 <= a + EPS || k0 >= c - EPS || l1 <= b + EPS || l0 >= d - EPS) continue;
|
|
670
|
+
const parts = [
|
|
671
|
+
{ a, b, c: Math.min(c, k0), d },
|
|
672
|
+
{ a: Math.max(a, k1), b, c, d },
|
|
673
|
+
{ a, b, c, d: Math.min(d, l0) },
|
|
674
|
+
{ a, b: Math.max(b, l1), c, d }
|
|
675
|
+
].filter((p) => p.c - p.a > EPS && p.d - p.b > EPS);
|
|
676
|
+
if (parts.length === 0) {
|
|
677
|
+
c = a;
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
const best = parts.reduce((p, q) => (q.c - q.a) * (q.d - q.b) > (p.c - p.a) * (p.d - p.b) ? q : p);
|
|
681
|
+
({ a, b, c, d } = best);
|
|
682
|
+
}
|
|
683
|
+
if (c - a > EPS && d - b > EPS) out.push(place(g, { x: a, y: b, width: c - a, height: d - b }));
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
const thinX = r.width <= r.height;
|
|
687
|
+
const t = thinX ? r.width : r.height;
|
|
688
|
+
let lo = thinX ? r.x : r.y;
|
|
689
|
+
const lim0 = thinX ? x0 : y0;
|
|
690
|
+
const lim1 = thinX ? x1 : y1;
|
|
691
|
+
if (lo + t > lim1) lo = lim1 - t;
|
|
692
|
+
if (lo < lim0) lo = lim0;
|
|
693
|
+
let hi = Math.min(lo + t, lim1);
|
|
694
|
+
const s0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);
|
|
695
|
+
const s1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);
|
|
696
|
+
if (s1 - s0 <= EPS) continue;
|
|
697
|
+
for (const { k: c, gap: gap2 } of clear) {
|
|
698
|
+
const cs0 = (thinX ? c.y : c.x) - gap2;
|
|
699
|
+
const cs1 = (thinX ? c.y + c.height : c.x + c.width) + gap2;
|
|
700
|
+
if (cs1 <= s0 + EPS || cs0 >= s1 - EPS) continue;
|
|
701
|
+
const c0 = (thinX ? c.x : c.y) - gap2;
|
|
702
|
+
const c1 = (thinX ? c.x + c.width : c.y + c.height) + gap2;
|
|
703
|
+
if (c1 <= lo + EPS || c0 >= hi - EPS) continue;
|
|
704
|
+
if ((c0 + c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, c0);
|
|
705
|
+
else lo = Math.max(lo, c1);
|
|
706
|
+
}
|
|
707
|
+
if (hi - lo < Math.max(EPS, min)) continue;
|
|
708
|
+
out.push(place(g, thinX ? { x: lo, y: s0, width: hi - lo, height: s1 - s0 } : { x: s0, y: lo, width: s1 - s0, height: hi - lo }));
|
|
709
|
+
}
|
|
710
|
+
return out;
|
|
711
|
+
}
|
|
581
712
|
export {
|
|
582
713
|
DOUBLE_CLICK,
|
|
583
714
|
DRAG_DEFAULTS,
|
|
@@ -588,9 +719,11 @@ export {
|
|
|
588
719
|
LANDING_TOUCH_MARGINS,
|
|
589
720
|
PLACE_GUIDES_DEFAULT,
|
|
590
721
|
REFUSAL_RANK,
|
|
722
|
+
SNAP_DISTANCE,
|
|
591
723
|
createDragIntent,
|
|
592
724
|
createGripPress,
|
|
593
725
|
createLandingModel,
|
|
726
|
+
guideRects,
|
|
594
727
|
inRect,
|
|
595
728
|
liftDecision,
|
|
596
729
|
pickRank,
|