@bevelo/dnd 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/a11y-BOpF8vx8.d.cts +30 -0
- package/dist/a11y-Bbm_a0mw.d.ts +30 -0
- package/dist/index-DDuIvuzA.d.cts +258 -0
- package/dist/index-kH3SGg1R.d.ts +258 -0
- package/dist/index.cjs +413 -0
- package/dist/index.d.cts +139 -0
- package/dist/index.d.ts +139 -0
- package/dist/index.js +357 -0
- package/dist/live/animate-settle.cjs +20 -0
- package/dist/live/animate-settle.d.cts +14 -0
- package/dist/live/animate-settle.d.ts +14 -0
- package/dist/live/animate-settle.js +19 -0
- package/dist/live/flip.cjs +39 -0
- package/dist/live/flip.d.cts +9 -0
- package/dist/live/flip.d.ts +9 -0
- package/dist/live/flip.js +38 -0
- package/dist/live/index.cjs +22 -0
- package/dist/live/index.d.cts +4 -0
- package/dist/live/index.d.ts +4 -0
- package/dist/live/index.js +4 -0
- package/dist/live-BUYwbSUp.cjs +899 -0
- package/dist/live-Clc3aswx.js +840 -0
- package/dist/pure/a11y.cjs +85 -0
- package/dist/pure/a11y.d.cts +2 -0
- package/dist/pure/a11y.d.ts +2 -0
- package/dist/pure/a11y.js +81 -0
- package/dist/pure/apply.cjs +130 -0
- package/dist/pure/apply.d.cts +29 -0
- package/dist/pure/apply.d.ts +29 -0
- package/dist/pure/apply.js +127 -0
- package/dist/pure/reorder.cjs +121 -0
- package/dist/pure/reorder.d.cts +77 -0
- package/dist/pure/reorder.d.ts +77 -0
- package/dist/pure/reorder.js +117 -0
- package/dist/pure/sensors.cjs +243 -0
- package/dist/pure/sensors.d.cts +2 -0
- package/dist/pure/sensors.d.ts +2 -0
- package/dist/pure/sensors.js +240 -0
- package/dist/pure/spatial.cjs +121 -0
- package/dist/pure/spatial.d.cts +64 -0
- package/dist/pure/spatial.d.ts +64 -0
- package/dist/pure/spatial.js +119 -0
- package/dist/pure/state.cjs +15 -0
- package/dist/pure/state.d.cts +2 -0
- package/dist/pure/state.d.ts +2 -0
- package/dist/pure/state.js +1 -0
- package/dist/pure/tree.cjs +164 -0
- package/dist/pure/tree.d.cts +36 -0
- package/dist/pure/tree.d.ts +36 -0
- package/dist/pure/tree.js +161 -0
- package/dist/rows-B2C7Yf94.cjs +56 -0
- package/dist/rows-BIT_Rkhr.js +45 -0
- package/dist/sensors-C9RnMr6P.d.cts +212 -0
- package/dist/sensors-C9RnMr6P.d.ts +212 -0
- package/dist/settle-BiwZ0ZDt.js +235 -0
- package/dist/settle-COFsW7ul.cjs +282 -0
- package/dist/settle-Dl5Y9uOw.d.ts +59 -0
- package/dist/settle-DzdqbH4S.d.cts +59 -0
- package/dist/state-BEKGNZY1.d.cts +323 -0
- package/dist/state-BEKGNZY1.d.ts +323 -0
- package/dist/state-BK9W_RZn.cjs +672 -0
- package/dist/state-CYXS6GIb.js +595 -0
- package/package.json +89 -3
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
const require_state = require("./state-BK9W_RZn.cjs");
|
|
2
|
+
// src/live/writer.ts
|
|
3
|
+
/** The attributes the writer sets; `reset` removes them from every element it flagged. */
|
|
4
|
+
const FLAGS = [
|
|
5
|
+
"data-dragging",
|
|
6
|
+
"data-drop-target",
|
|
7
|
+
"data-drag-over",
|
|
8
|
+
"data-drag-operation"
|
|
9
|
+
];
|
|
10
|
+
/** A translate as a transform string. */
|
|
11
|
+
function translate(by) {
|
|
12
|
+
return "translate3d(" + by.x + "px, " + by.y + "px, 0)";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Inline `transform` and `visibility`, each element's own value remembered at the first write
|
|
16
|
+
* and restored by `reset`. The default.
|
|
17
|
+
*/
|
|
18
|
+
const styleChannel = () => {
|
|
19
|
+
const originals = /* @__PURE__ */ new Map();
|
|
20
|
+
const put = (el, prop, value) => {
|
|
21
|
+
let own = originals.get(el);
|
|
22
|
+
if (own === void 0) {
|
|
23
|
+
if (value === null) return;
|
|
24
|
+
own = {
|
|
25
|
+
transform: el.style.transform,
|
|
26
|
+
transformOrigin: el.style.transformOrigin,
|
|
27
|
+
visibility: el.style.visibility
|
|
28
|
+
};
|
|
29
|
+
originals.set(el, own);
|
|
30
|
+
}
|
|
31
|
+
const next = value ?? own[prop];
|
|
32
|
+
if (el.style[prop] !== next) el.style[prop] = next;
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
move: (el, by) => put(el, "transform", by && translate(by)),
|
|
36
|
+
hide: (el, hidden) => put(el, "visibility", hidden ? "hidden" : null),
|
|
37
|
+
inverse(el, transform) {
|
|
38
|
+
put(el, "transformOrigin", "0 0");
|
|
39
|
+
put(el, "transform", transform);
|
|
40
|
+
},
|
|
41
|
+
reset() {
|
|
42
|
+
for (const [el, own] of originals) Object.assign(el.style, own);
|
|
43
|
+
originals.clear();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/** The custom properties `varsChannel` writes. */
|
|
48
|
+
const DRAG_X = "--bevelo-drag-x";
|
|
49
|
+
const DRAG_Y = "--bevelo-drag-y";
|
|
50
|
+
/** The attribute `varsChannel` sets on a hidden move source. */
|
|
51
|
+
const DRAG_HIDDEN = "data-drag-hidden";
|
|
52
|
+
/**
|
|
53
|
+
* The engine's own channel: `--bevelo-drag-x` and `--bevelo-drag-y` (px) for every translate,
|
|
54
|
+
* and `data-drag-hidden` on a hidden move source. It never writes `transform` or `visibility`,
|
|
55
|
+
* so a part whose `style` a framework renders keeps it; the stylesheet consumes the channel:
|
|
56
|
+
*
|
|
57
|
+
* ```css
|
|
58
|
+
* @property --bevelo-drag-x { syntax: "<length>"; inherits: false; initial-value: 0px; }
|
|
59
|
+
* @property --bevelo-drag-y { syntax: "<length>"; inherits: false; initial-value: 0px; }
|
|
60
|
+
* [data-part] { translate: var(--bevelo-drag-x) var(--bevelo-drag-y); }
|
|
61
|
+
* [data-drag-hidden] { visibility: hidden; }
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* A settle paints no inverse: `animateSettle` animates `transform` with the Web Animations
|
|
65
|
+
* API, which writes no inline style, and `springSettle` springs these same properties.
|
|
66
|
+
*/
|
|
67
|
+
const varsChannel = () => {
|
|
68
|
+
const touched = /* @__PURE__ */ new Set();
|
|
69
|
+
const clear = (el) => {
|
|
70
|
+
el.style.removeProperty(DRAG_X);
|
|
71
|
+
el.style.removeProperty(DRAG_Y);
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
move(el, by) {
|
|
75
|
+
if (by === null) return clear(el);
|
|
76
|
+
touched.add(el);
|
|
77
|
+
el.style.setProperty(DRAG_X, by.x + "px");
|
|
78
|
+
el.style.setProperty(DRAG_Y, by.y + "px");
|
|
79
|
+
},
|
|
80
|
+
hide(el, hidden) {
|
|
81
|
+
if (hidden) touched.add(el);
|
|
82
|
+
el.toggleAttribute(DRAG_HIDDEN, hidden);
|
|
83
|
+
},
|
|
84
|
+
painted(el) {
|
|
85
|
+
if (typeof el.getAnimations !== "function" || el.getAnimations().length === 0) return void 0;
|
|
86
|
+
const value = el.ownerDocument.defaultView?.getComputedStyle(el).translate ?? "";
|
|
87
|
+
if (value === "" || value === "none") return {
|
|
88
|
+
x: 0,
|
|
89
|
+
y: 0
|
|
90
|
+
};
|
|
91
|
+
const [x = "0", y = "0"] = value.split(" ");
|
|
92
|
+
return {
|
|
93
|
+
x: Number.parseFloat(x) || 0,
|
|
94
|
+
y: Number.parseFloat(y) || 0
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
reset() {
|
|
98
|
+
for (const el of touched) {
|
|
99
|
+
clear(el);
|
|
100
|
+
el.removeAttribute(DRAG_HIDDEN);
|
|
101
|
+
}
|
|
102
|
+
touched.clear();
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
function createWriter(base) {
|
|
107
|
+
const flagged = /* @__PURE__ */ new Set();
|
|
108
|
+
const offsets = /* @__PURE__ */ new Map();
|
|
109
|
+
const channel = {
|
|
110
|
+
...base,
|
|
111
|
+
move(el, by) {
|
|
112
|
+
if (by === null) offsets.delete(el);
|
|
113
|
+
else offsets.set(el, by);
|
|
114
|
+
base.move(el, by);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function flag(el, name, value) {
|
|
118
|
+
if (value === null) el.removeAttribute(name);
|
|
119
|
+
else if (el.getAttribute(name) !== value) {
|
|
120
|
+
el.setAttribute(name, value);
|
|
121
|
+
flagged.add(el);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
channel,
|
|
126
|
+
drag(state, items, zones, preview, full) {
|
|
127
|
+
if (state.phase !== "dragging") return;
|
|
128
|
+
if (full) {
|
|
129
|
+
const { operation, target } = state;
|
|
130
|
+
const marked = target?.kind === "item" ? target.key : null;
|
|
131
|
+
for (const [key, { el }] of items) {
|
|
132
|
+
const carried = require_state.isDragged(state, key);
|
|
133
|
+
if (el !== preview?.el) {
|
|
134
|
+
const shift = require_state.shiftOf(state, key);
|
|
135
|
+
channel.move(el, shift.x === 0 && shift.y === 0 ? null : shift);
|
|
136
|
+
channel.hide(el, carried && operation !== "copy");
|
|
137
|
+
}
|
|
138
|
+
flag(el, "data-dragging", carried ? "" : null);
|
|
139
|
+
flag(el, "data-drop-target", key === marked ? "" : null);
|
|
140
|
+
}
|
|
141
|
+
for (const [id, el] of zones) {
|
|
142
|
+
const over = state.hit?.zoneId === id;
|
|
143
|
+
flag(el, "data-drag-over", over ? "" : null);
|
|
144
|
+
flag(el, "data-drag-operation", over ? state.operation : null);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (preview !== null) channel.move(preview.el, preview.at);
|
|
148
|
+
},
|
|
149
|
+
rect(el) {
|
|
150
|
+
const { x, y, width, height } = el.getBoundingClientRect();
|
|
151
|
+
const by = base.painted?.(el) ?? offsets.get(el);
|
|
152
|
+
return by === void 0 ? {
|
|
153
|
+
x,
|
|
154
|
+
y,
|
|
155
|
+
width,
|
|
156
|
+
height
|
|
157
|
+
} : {
|
|
158
|
+
x: x - by.x,
|
|
159
|
+
y: y - by.y,
|
|
160
|
+
width,
|
|
161
|
+
height
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
reset() {
|
|
165
|
+
offsets.clear();
|
|
166
|
+
channel.reset();
|
|
167
|
+
for (const el of flagged) for (const name of FLAGS) el.removeAttribute(name);
|
|
168
|
+
flagged.clear();
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
// src/live/settle.ts
|
|
173
|
+
/** The transform that paints a move's element, laid out at `to`, back over `from`; its origin is the top-left corner. */
|
|
174
|
+
function inverseOf({ from, to }) {
|
|
175
|
+
const sx = to.width > 0 ? from.width / to.width : 1;
|
|
176
|
+
const sy = to.height > 0 ? from.height / to.height : 1;
|
|
177
|
+
return `${translate({
|
|
178
|
+
x: from.x - to.x,
|
|
179
|
+
y: from.y - to.y
|
|
180
|
+
})} scale(${sx}, ${sy})`;
|
|
181
|
+
}
|
|
182
|
+
const REDUCED_MOTION = "(prefers-reduced-motion: reduce)";
|
|
183
|
+
/**
|
|
184
|
+
* FLIP: shifted items and the carried ones (from the preview's painted rect, unless the drop
|
|
185
|
+
* copied) start where they were painted, and `animate` resolves once they are at rest.
|
|
186
|
+
* `animate` runs in the write pass, so it sees each element's own inline transform; the
|
|
187
|
+
* engine then paints each translate and scale inverse in that same pass, so no frame shows
|
|
188
|
+
* the new layout or a size jump, and restores the element's own transform when the drag ends.
|
|
189
|
+
*/
|
|
190
|
+
function flipSettle(animate) {
|
|
191
|
+
return (drop) => {
|
|
192
|
+
const { state, items, preview } = drop;
|
|
193
|
+
const from = /* @__PURE__ */ new Map();
|
|
194
|
+
for (const [key, { el }] of items) {
|
|
195
|
+
const shift = require_state.shiftOf(state, key);
|
|
196
|
+
if (shift.x !== 0 || shift.y !== 0) from.set(key, el.getBoundingClientRect());
|
|
197
|
+
}
|
|
198
|
+
if (drop.result?.operation !== "copy") {
|
|
199
|
+
const painted = preview.getBoundingClientRect();
|
|
200
|
+
for (const key of state.source.carried) from.set(key, painted);
|
|
201
|
+
}
|
|
202
|
+
const moves = [];
|
|
203
|
+
const abort = new AbortController();
|
|
204
|
+
return {
|
|
205
|
+
cancel: () => abort.abort(),
|
|
206
|
+
read() {
|
|
207
|
+
for (const [key, rect] of from) {
|
|
208
|
+
const el = items.get(key)?.el;
|
|
209
|
+
if (el?.isConnected) moves.push({
|
|
210
|
+
el,
|
|
211
|
+
from: rect,
|
|
212
|
+
to: drop.rect(el)
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
write() {
|
|
217
|
+
if (moves.length === 0) return void 0;
|
|
218
|
+
const view = preview.ownerDocument.defaultView;
|
|
219
|
+
const reducedMotion = typeof view?.matchMedia === "function" && view.matchMedia(REDUCED_MOTION).matches;
|
|
220
|
+
const { transform } = drop;
|
|
221
|
+
const done = animate({
|
|
222
|
+
moves,
|
|
223
|
+
reducedMotion,
|
|
224
|
+
frame: drop.frame,
|
|
225
|
+
signal: abort.signal,
|
|
226
|
+
translate: drop.translate,
|
|
227
|
+
inverse: transform !== void 0
|
|
228
|
+
});
|
|
229
|
+
if (transform !== void 0) for (const move of moves) transform(move.el, inverseOf(move));
|
|
230
|
+
return done;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
Object.defineProperty(exports, "DRAG_HIDDEN", {
|
|
236
|
+
enumerable: true,
|
|
237
|
+
get: function() {
|
|
238
|
+
return DRAG_HIDDEN;
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
Object.defineProperty(exports, "DRAG_X", {
|
|
242
|
+
enumerable: true,
|
|
243
|
+
get: function() {
|
|
244
|
+
return DRAG_X;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
Object.defineProperty(exports, "DRAG_Y", {
|
|
248
|
+
enumerable: true,
|
|
249
|
+
get: function() {
|
|
250
|
+
return DRAG_Y;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
Object.defineProperty(exports, "createWriter", {
|
|
254
|
+
enumerable: true,
|
|
255
|
+
get: function() {
|
|
256
|
+
return createWriter;
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
Object.defineProperty(exports, "flipSettle", {
|
|
260
|
+
enumerable: true,
|
|
261
|
+
get: function() {
|
|
262
|
+
return flipSettle;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
Object.defineProperty(exports, "inverseOf", {
|
|
266
|
+
enumerable: true,
|
|
267
|
+
get: function() {
|
|
268
|
+
return inverseOf;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
Object.defineProperty(exports, "styleChannel", {
|
|
272
|
+
enumerable: true,
|
|
273
|
+
get: function() {
|
|
274
|
+
return styleChannel;
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
Object.defineProperty(exports, "varsChannel", {
|
|
278
|
+
enumerable: true,
|
|
279
|
+
get: function() {
|
|
280
|
+
return varsChannel;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { c as DragState, d as DropResult } from "./state-BEKGNZY1.js";
|
|
2
|
+
import { FrameLoop, LayoutMove, Point, Rect } from "@bevelo/runtime";
|
|
3
|
+
/** What a settle strategy gets at the drop, before the app's `onDrop` runs. */
|
|
4
|
+
interface SettleDrop {
|
|
5
|
+
/** The drag as it was when it ended. */
|
|
6
|
+
readonly state: Extract<DragState, {
|
|
7
|
+
readonly phase: "dragging";
|
|
8
|
+
}>;
|
|
9
|
+
/** The drop's result; null for a cancel. */
|
|
10
|
+
readonly result: DropResult | null;
|
|
11
|
+
/** Registered items, live: after the commit a key may name a new element. */
|
|
12
|
+
readonly items: ReadonlyMap<string, {
|
|
13
|
+
readonly el: HTMLElement;
|
|
14
|
+
}>;
|
|
15
|
+
readonly preview: HTMLElement;
|
|
16
|
+
/** Writes a transform, from the element's top-left corner, that the engine restores when the drag ends. Absent on a channel that writes no inline transform. */
|
|
17
|
+
readonly transform?: ((el: HTMLElement, value: string) => void) | undefined;
|
|
18
|
+
/** Translates an element through the coordinator's channel; null puts it back. The engine restores it when the drag ends. */
|
|
19
|
+
translate(el: HTMLElement, by: Point | null): void;
|
|
20
|
+
/** Read pass: an element's layout rect, without the translate the engine wrote. */
|
|
21
|
+
rect(el: Element): Rect;
|
|
22
|
+
readonly frame: FrameLoop;
|
|
23
|
+
}
|
|
24
|
+
/** One drop's animation: `read` runs in the read pass after the commit, `write` in the write pass after it. */
|
|
25
|
+
interface SettleRun {
|
|
26
|
+
read(): void;
|
|
27
|
+
/** Starts the animation; the drag ends when it resolves, or at once for undefined. */
|
|
28
|
+
write(): Promise<unknown> | undefined;
|
|
29
|
+
/** Stops the animation at once: a new drag started, or the coordinator was disposed. */
|
|
30
|
+
cancel?(): void;
|
|
31
|
+
}
|
|
32
|
+
/** Animates a drop. Called at the drop, so it can read what is painted before the app commits. */
|
|
33
|
+
type SettleStrategy = (drop: SettleDrop) => SettleRun;
|
|
34
|
+
/** What a FLIP animation animates. */
|
|
35
|
+
interface SettleContext {
|
|
36
|
+
/** Carried, shifted and preview elements: the painted rect before the drop, the layout rect after. */
|
|
37
|
+
readonly moves: readonly LayoutMove[];
|
|
38
|
+
readonly reducedMotion: boolean;
|
|
39
|
+
readonly frame: FrameLoop;
|
|
40
|
+
/** Aborted when a new drag starts. */
|
|
41
|
+
readonly signal: AbortSignal;
|
|
42
|
+
/**
|
|
43
|
+
* Translates an element through the coordinator's channel, null putting it back. On a
|
|
44
|
+
* channel without inline transforms (`varsChannel`) no inverse is painted, so an animation
|
|
45
|
+
* that does not animate `transform` itself paints every frame, the first included, here.
|
|
46
|
+
*/
|
|
47
|
+
readonly translate: (el: HTMLElement, by: Point | null) => void;
|
|
48
|
+
/** Whether the engine painted each move's inverse as an inline transform in this write pass. */
|
|
49
|
+
readonly inverse: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* FLIP: shifted items and the carried ones (from the preview's painted rect, unless the drop
|
|
53
|
+
* copied) start where they were painted, and `animate` resolves once they are at rest.
|
|
54
|
+
* `animate` runs in the write pass, so it sees each element's own inline transform; the
|
|
55
|
+
* engine then paints each translate and scale inverse in that same pass, so no frame shows
|
|
56
|
+
* the new layout or a size jump, and restores the element's own transform when the drag ends.
|
|
57
|
+
*/
|
|
58
|
+
declare function flipSettle(animate: (ctx: SettleContext) => Promise<unknown>): SettleStrategy;
|
|
59
|
+
export { flipSettle as a, SettleStrategy as i, SettleDrop as n, SettleRun as r, SettleContext as t };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { c as DragState, d as DropResult } from "./state-BEKGNZY1.cjs";
|
|
2
|
+
import { FrameLoop, LayoutMove, Point, Rect } from "@bevelo/runtime";
|
|
3
|
+
/** What a settle strategy gets at the drop, before the app's `onDrop` runs. */
|
|
4
|
+
interface SettleDrop {
|
|
5
|
+
/** The drag as it was when it ended. */
|
|
6
|
+
readonly state: Extract<DragState, {
|
|
7
|
+
readonly phase: "dragging";
|
|
8
|
+
}>;
|
|
9
|
+
/** The drop's result; null for a cancel. */
|
|
10
|
+
readonly result: DropResult | null;
|
|
11
|
+
/** Registered items, live: after the commit a key may name a new element. */
|
|
12
|
+
readonly items: ReadonlyMap<string, {
|
|
13
|
+
readonly el: HTMLElement;
|
|
14
|
+
}>;
|
|
15
|
+
readonly preview: HTMLElement;
|
|
16
|
+
/** Writes a transform, from the element's top-left corner, that the engine restores when the drag ends. Absent on a channel that writes no inline transform. */
|
|
17
|
+
readonly transform?: ((el: HTMLElement, value: string) => void) | undefined;
|
|
18
|
+
/** Translates an element through the coordinator's channel; null puts it back. The engine restores it when the drag ends. */
|
|
19
|
+
translate(el: HTMLElement, by: Point | null): void;
|
|
20
|
+
/** Read pass: an element's layout rect, without the translate the engine wrote. */
|
|
21
|
+
rect(el: Element): Rect;
|
|
22
|
+
readonly frame: FrameLoop;
|
|
23
|
+
}
|
|
24
|
+
/** One drop's animation: `read` runs in the read pass after the commit, `write` in the write pass after it. */
|
|
25
|
+
interface SettleRun {
|
|
26
|
+
read(): void;
|
|
27
|
+
/** Starts the animation; the drag ends when it resolves, or at once for undefined. */
|
|
28
|
+
write(): Promise<unknown> | undefined;
|
|
29
|
+
/** Stops the animation at once: a new drag started, or the coordinator was disposed. */
|
|
30
|
+
cancel?(): void;
|
|
31
|
+
}
|
|
32
|
+
/** Animates a drop. Called at the drop, so it can read what is painted before the app commits. */
|
|
33
|
+
type SettleStrategy = (drop: SettleDrop) => SettleRun;
|
|
34
|
+
/** What a FLIP animation animates. */
|
|
35
|
+
interface SettleContext {
|
|
36
|
+
/** Carried, shifted and preview elements: the painted rect before the drop, the layout rect after. */
|
|
37
|
+
readonly moves: readonly LayoutMove[];
|
|
38
|
+
readonly reducedMotion: boolean;
|
|
39
|
+
readonly frame: FrameLoop;
|
|
40
|
+
/** Aborted when a new drag starts. */
|
|
41
|
+
readonly signal: AbortSignal;
|
|
42
|
+
/**
|
|
43
|
+
* Translates an element through the coordinator's channel, null putting it back. On a
|
|
44
|
+
* channel without inline transforms (`varsChannel`) no inverse is painted, so an animation
|
|
45
|
+
* that does not animate `transform` itself paints every frame, the first included, here.
|
|
46
|
+
*/
|
|
47
|
+
readonly translate: (el: HTMLElement, by: Point | null) => void;
|
|
48
|
+
/** Whether the engine painted each move's inverse as an inline transform in this write pass. */
|
|
49
|
+
readonly inverse: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* FLIP: shifted items and the carried ones (from the preview's painted rect, unless the drop
|
|
53
|
+
* copied) start where they were painted, and `animate` resolves once they are at rest.
|
|
54
|
+
* `animate` runs in the write pass, so it sees each element's own inline transform; the
|
|
55
|
+
* engine then paints each translate and scale inverse in that same pass, so no frame shows
|
|
56
|
+
* the new layout or a size jump, and restores the element's own transform when the drag ends.
|
|
57
|
+
*/
|
|
58
|
+
declare function flipSettle(animate: (ctx: SettleContext) => Promise<unknown>): SettleStrategy;
|
|
59
|
+
export { flipSettle as a, SettleStrategy as i, SettleDrop as n, SettleRun as r, SettleContext as t };
|