@maas/vue-equipment 1.0.0-beta.71 → 1.0.0-beta.73
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/dist/nuxt/module.json
CHANGED
|
@@ -28,10 +28,6 @@ export function useTrayMagnetism(args) {
|
|
|
28
28
|
const easing = computed(() => easings[magnetism.value.easing]);
|
|
29
29
|
const disabled = computed(() => state.options.disabled);
|
|
30
30
|
const animation = computed(() => state.options.animation);
|
|
31
|
-
function sideConfig(side) {
|
|
32
|
-
const { sides } = magnetism.value;
|
|
33
|
-
return sides ? sides[side] : void 0;
|
|
34
|
-
}
|
|
35
31
|
const magneticSides = computed(() => {
|
|
36
32
|
return SIDES.filter((side) => {
|
|
37
33
|
const draggable = (state.options.snapPoints[side]?.length ?? 0) > 0;
|
|
@@ -109,6 +105,10 @@ export function useTrayMagnetism(args) {
|
|
|
109
105
|
let lastX = 0;
|
|
110
106
|
let lastY = 0;
|
|
111
107
|
let cancelPointermove = void 0;
|
|
108
|
+
function sideConfig(side) {
|
|
109
|
+
const { sides } = magnetism.value;
|
|
110
|
+
return sides ? sides[side] : void 0;
|
|
111
|
+
}
|
|
112
112
|
function coercePoint(key) {
|
|
113
113
|
return key.endsWith("px") ? key : Number(key);
|
|
114
114
|
}
|
|
@@ -136,14 +136,9 @@ export function useTrayMagnetism(args) {
|
|
|
136
136
|
);
|
|
137
137
|
return match ? match.direction : null;
|
|
138
138
|
}
|
|
139
|
-
function
|
|
139
|
+
function handleRect(side) {
|
|
140
140
|
const handle = unrefElement(handleRefs[side].value?.[0]);
|
|
141
|
-
|
|
142
|
-
return 0;
|
|
143
|
-
}
|
|
144
|
-
const rect = handle.getBoundingClientRect();
|
|
145
|
-
const size = side === "top" || side === "bottom" ? rect.height : rect.width;
|
|
146
|
-
return size / 2;
|
|
141
|
+
return handle ? handle.getBoundingClientRect() : null;
|
|
147
142
|
}
|
|
148
143
|
function cancelSettle(side) {
|
|
149
144
|
if (settleId[side] !== void 0) {
|
|
@@ -158,6 +153,11 @@ export function useTrayMagnetism(args) {
|
|
|
158
153
|
state.magnetic[side] = 0;
|
|
159
154
|
}
|
|
160
155
|
}
|
|
156
|
+
function disarm(side) {
|
|
157
|
+
armedDir[side] = null;
|
|
158
|
+
latched[side] = false;
|
|
159
|
+
resetSide(side);
|
|
160
|
+
}
|
|
161
161
|
function settleSide(side) {
|
|
162
162
|
if (settling[side]) {
|
|
163
163
|
return;
|
|
@@ -185,9 +185,7 @@ export function useTrayMagnetism(args) {
|
|
|
185
185
|
}
|
|
186
186
|
function resetAll() {
|
|
187
187
|
for (const side of SIDES) {
|
|
188
|
-
|
|
189
|
-
latched[side] = false;
|
|
190
|
-
resetSide(side);
|
|
188
|
+
disarm(side);
|
|
191
189
|
}
|
|
192
190
|
}
|
|
193
191
|
function axisOverflow(value, min, max) {
|
|
@@ -200,6 +198,147 @@ export function useTrayMagnetism(args) {
|
|
|
200
198
|
return 0;
|
|
201
199
|
}
|
|
202
200
|
}
|
|
201
|
+
function normalizeRadius(radius) {
|
|
202
|
+
if (typeof radius === "number") {
|
|
203
|
+
return radius > 0 ? { start: radius, stop: 0, configured: true } : { start: void 0, stop: void 0, configured: false };
|
|
204
|
+
}
|
|
205
|
+
const { start, stop } = radius;
|
|
206
|
+
return { start, stop, configured: start !== void 0 || stop !== void 0 };
|
|
207
|
+
}
|
|
208
|
+
function measureAxis(side, x, y, rect, hRect) {
|
|
209
|
+
let perp = 0;
|
|
210
|
+
let overflow = 0;
|
|
211
|
+
let center = 0;
|
|
212
|
+
switch (side) {
|
|
213
|
+
case "top": {
|
|
214
|
+
const edge = rect.top + state.snapped.top;
|
|
215
|
+
perp = y - edge;
|
|
216
|
+
overflow = axisOverflow(x, rect.left, rect.right);
|
|
217
|
+
if (hRect) {
|
|
218
|
+
center = hRect.top + hRect.height / 2 - edge - state.magnetic.top;
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
case "bottom": {
|
|
223
|
+
const edge = rect.bottom - state.snapped.bottom;
|
|
224
|
+
perp = edge - y;
|
|
225
|
+
overflow = axisOverflow(x, rect.left, rect.right);
|
|
226
|
+
if (hRect) {
|
|
227
|
+
center = edge - (hRect.top + hRect.height / 2) - state.magnetic.bottom;
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
case "left": {
|
|
232
|
+
const edge = rect.left + state.snapped.left;
|
|
233
|
+
perp = x - edge;
|
|
234
|
+
overflow = axisOverflow(y, rect.top, rect.bottom);
|
|
235
|
+
if (hRect) {
|
|
236
|
+
center = hRect.left + hRect.width / 2 - edge - state.magnetic.left;
|
|
237
|
+
}
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case "right": {
|
|
241
|
+
const edge = rect.right - state.snapped.right;
|
|
242
|
+
perp = edge - x;
|
|
243
|
+
overflow = axisOverflow(y, rect.top, rect.bottom);
|
|
244
|
+
if (hRect) {
|
|
245
|
+
center = edge - (hRect.left + hRect.width / 2) - state.magnetic.right;
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return { perp, overflow, center };
|
|
251
|
+
}
|
|
252
|
+
function resolveBand(band, geo) {
|
|
253
|
+
const { pull, thickness, center } = geo;
|
|
254
|
+
if (band.configured) {
|
|
255
|
+
const stop = band.stop ?? pull;
|
|
256
|
+
const start = band.start ?? stop + (thickness || pull);
|
|
257
|
+
return { innerEdge: start, outerEdge: -start, span: start - stop };
|
|
258
|
+
}
|
|
259
|
+
const anchorHalf = thickness / 2;
|
|
260
|
+
return {
|
|
261
|
+
innerEdge: center + anchorHalf,
|
|
262
|
+
outerEdge: center - anchorHalf,
|
|
263
|
+
span: anchorHalf / 2
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function updateSide(side, x, y, rect, band) {
|
|
267
|
+
const direction = restDirection(side);
|
|
268
|
+
if (!direction) {
|
|
269
|
+
disarm(side);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const allowInner = direction === "inner" || direction === "both";
|
|
273
|
+
const allowOuter = direction === "outer" || direction === "both";
|
|
274
|
+
const hRect = handleRect(side);
|
|
275
|
+
const thickness = hRect ? side === "top" || side === "bottom" ? hRect.height : hRect.width : 0;
|
|
276
|
+
const pull = magnetism.value.pull > 0 ? magnetism.value.pull : thickness / 4;
|
|
277
|
+
pullPx[side] = pull;
|
|
278
|
+
if (pull <= 0) {
|
|
279
|
+
disarm(side);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const { perp, overflow, center } = measureAxis(side, x, y, rect, hRect);
|
|
283
|
+
const { innerEdge, outerEdge, span } = resolveBand(band, {
|
|
284
|
+
pull,
|
|
285
|
+
thickness,
|
|
286
|
+
center
|
|
287
|
+
});
|
|
288
|
+
if (span <= 0) {
|
|
289
|
+
disarm(side);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (overflow === 0) {
|
|
293
|
+
switch (true) {
|
|
294
|
+
case (allowInner && perp >= innerEdge):
|
|
295
|
+
armedDir[side] = "inner";
|
|
296
|
+
break;
|
|
297
|
+
case (allowOuter && perp <= outerEdge):
|
|
298
|
+
armedDir[side] = "outer";
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const dir = armedDir[side];
|
|
303
|
+
if (!dir) {
|
|
304
|
+
resetSide(side);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
let t = 0;
|
|
308
|
+
let sign = 0;
|
|
309
|
+
switch (dir) {
|
|
310
|
+
case "inner":
|
|
311
|
+
t = clampValue((innerEdge - perp) / span, 0, 1);
|
|
312
|
+
sign = 1;
|
|
313
|
+
break;
|
|
314
|
+
case "outer":
|
|
315
|
+
t = clampValue((perp - outerEdge) / span, 0, 1);
|
|
316
|
+
sign = -1;
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
switch (true) {
|
|
320
|
+
case overflow === 0:
|
|
321
|
+
latched[side] = t >= 1;
|
|
322
|
+
break;
|
|
323
|
+
case !latched[side]:
|
|
324
|
+
armedDir[side] = null;
|
|
325
|
+
resetSide(side);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const magnitude = overflow === 0 ? easing.value(t) : 1;
|
|
329
|
+
const offset = sign * pull * magnitude;
|
|
330
|
+
const target = clampValue(
|
|
331
|
+
offset,
|
|
332
|
+
-state.dragged[side],
|
|
333
|
+
maxInset(side) - state.dragged[side]
|
|
334
|
+
);
|
|
335
|
+
if (Math.abs(target) > EPSILON) {
|
|
336
|
+
cancelSettle(side);
|
|
337
|
+
state.magnetic[side] = target;
|
|
338
|
+
} else {
|
|
339
|
+
settleSide(side);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
203
342
|
function update(x, y) {
|
|
204
343
|
if (state.dragging || disabled.value) {
|
|
205
344
|
resetAll();
|
|
@@ -210,99 +349,10 @@ export function useTrayMagnetism(args) {
|
|
|
210
349
|
resetAll();
|
|
211
350
|
return;
|
|
212
351
|
}
|
|
213
|
-
const
|
|
352
|
+
const band = normalizeRadius(magnetism.value.radius);
|
|
214
353
|
const rect = el.getBoundingClientRect();
|
|
215
354
|
for (const side of magneticSides.value) {
|
|
216
|
-
|
|
217
|
-
if (!direction) {
|
|
218
|
-
armedDir[side] = null;
|
|
219
|
-
latched[side] = false;
|
|
220
|
-
resetSide(side);
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
const allowInner = direction === "inner" || direction === "both";
|
|
224
|
-
const allowOuter = direction === "outer" || direction === "both";
|
|
225
|
-
const anchorHalf = handleHalfThickness(side);
|
|
226
|
-
const radius = configuredRadius > 0 ? configuredRadius : anchorHalf / 2;
|
|
227
|
-
const pull = configuredPull > 0 ? configuredPull : anchorHalf / 2;
|
|
228
|
-
pullPx[side] = pull;
|
|
229
|
-
if (radius <= 0) {
|
|
230
|
-
armedDir[side] = null;
|
|
231
|
-
latched[side] = false;
|
|
232
|
-
resetSide(side);
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
let perp = 0;
|
|
236
|
-
let overflow = 0;
|
|
237
|
-
switch (side) {
|
|
238
|
-
case "top":
|
|
239
|
-
perp = y - (rect.top + state.snapped.top);
|
|
240
|
-
overflow = axisOverflow(x, rect.left, rect.right);
|
|
241
|
-
break;
|
|
242
|
-
case "bottom":
|
|
243
|
-
perp = rect.bottom - state.snapped.bottom - y;
|
|
244
|
-
overflow = axisOverflow(x, rect.left, rect.right);
|
|
245
|
-
break;
|
|
246
|
-
case "left":
|
|
247
|
-
perp = x - (rect.left + state.snapped.left);
|
|
248
|
-
overflow = axisOverflow(y, rect.top, rect.bottom);
|
|
249
|
-
break;
|
|
250
|
-
case "right":
|
|
251
|
-
perp = rect.right - state.snapped.right - x;
|
|
252
|
-
overflow = axisOverflow(y, rect.top, rect.bottom);
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
if (overflow === 0) {
|
|
256
|
-
switch (true) {
|
|
257
|
-
case (allowInner && perp >= anchorHalf):
|
|
258
|
-
armedDir[side] = "inner";
|
|
259
|
-
break;
|
|
260
|
-
case (allowOuter && perp <= -anchorHalf):
|
|
261
|
-
armedDir[side] = "outer";
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
const dir = armedDir[side];
|
|
266
|
-
if (!dir) {
|
|
267
|
-
resetSide(side);
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
let t = 0;
|
|
271
|
-
let sign = 0;
|
|
272
|
-
switch (dir) {
|
|
273
|
-
case "inner":
|
|
274
|
-
t = clampValue((anchorHalf - perp) / radius, 0, 1);
|
|
275
|
-
sign = 1;
|
|
276
|
-
break;
|
|
277
|
-
case "outer":
|
|
278
|
-
t = clampValue((anchorHalf + perp) / radius, 0, 1);
|
|
279
|
-
sign = -1;
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
switch (true) {
|
|
283
|
-
case overflow === 0:
|
|
284
|
-
latched[side] = t >= 1;
|
|
285
|
-
break;
|
|
286
|
-
case !latched[side]:
|
|
287
|
-
armedDir[side] = null;
|
|
288
|
-
resetSide(side);
|
|
289
|
-
continue;
|
|
290
|
-
}
|
|
291
|
-
const magnitude = overflow === 0 ? easing.value(t) : 1;
|
|
292
|
-
const offset = sign * pull * magnitude;
|
|
293
|
-
const target = clampValue(
|
|
294
|
-
offset,
|
|
295
|
-
-state.dragged[side],
|
|
296
|
-
maxInset(side) - state.dragged[side]
|
|
297
|
-
);
|
|
298
|
-
switch (true) {
|
|
299
|
-
case Math.abs(target) > EPSILON:
|
|
300
|
-
cancelSettle(side);
|
|
301
|
-
state.magnetic[side] = target;
|
|
302
|
-
break;
|
|
303
|
-
default:
|
|
304
|
-
settleSide(side);
|
|
305
|
-
}
|
|
355
|
+
updateSide(side, x, y, rect, band);
|
|
306
356
|
}
|
|
307
357
|
}
|
|
308
358
|
function onPointermove(e) {
|
|
@@ -342,6 +392,18 @@ export function useTrayMagnetism(args) {
|
|
|
342
392
|
},
|
|
343
393
|
{ deep: true }
|
|
344
394
|
);
|
|
395
|
+
watch(
|
|
396
|
+
() => ({ ...state.snapped }),
|
|
397
|
+
(next, prev) => {
|
|
398
|
+
for (const side of SIDES) {
|
|
399
|
+
if (next[side] !== prev[side]) {
|
|
400
|
+
armedDir[side] = null;
|
|
401
|
+
latched[side] = false;
|
|
402
|
+
settleSide(side);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
);
|
|
345
407
|
watch(
|
|
346
408
|
() => [enabled.value, magnetism.value.sides, state.options.snapPoints],
|
|
347
409
|
() => {
|
|
@@ -15,9 +15,13 @@ export type TraySnapPoints = Partial<Record<TraySide, TraySnapPoint[]>>;
|
|
|
15
15
|
export type TrayMagneticDirection = 'inner' | 'outer' | 'both';
|
|
16
16
|
export type TrayMagneticSide = Partial<Record<TraySnapPoint, TrayMagneticDirection>>;
|
|
17
17
|
export type TrayMagneticSides = false | Partial<Record<TraySide, TrayMagneticSide>>;
|
|
18
|
+
export type TrayMagneticRadius = number | {
|
|
19
|
+
start?: number;
|
|
20
|
+
stop?: number;
|
|
21
|
+
};
|
|
18
22
|
export interface TrayMagnetism {
|
|
19
23
|
sides?: TrayMagneticSides;
|
|
20
|
-
radius?:
|
|
24
|
+
radius?: TrayMagneticRadius;
|
|
21
25
|
pull?: number;
|
|
22
26
|
easing?: EasingKey;
|
|
23
27
|
}
|