@maas/vue-equipment 1.0.0-beta.72 → 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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maas/vue-equipment/nuxt",
3
3
  "configKey": "vueEquipment",
4
- "version": "1.0.0-beta.71",
4
+ "version": "1.0.0-beta.72",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
@@ -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
  }
@@ -153,6 +153,11 @@ export function useTrayMagnetism(args) {
153
153
  state.magnetic[side] = 0;
154
154
  }
155
155
  }
156
+ function disarm(side) {
157
+ armedDir[side] = null;
158
+ latched[side] = false;
159
+ resetSide(side);
160
+ }
156
161
  function settleSide(side) {
157
162
  if (settling[side]) {
158
163
  return;
@@ -180,9 +185,7 @@ export function useTrayMagnetism(args) {
180
185
  }
181
186
  function resetAll() {
182
187
  for (const side of SIDES) {
183
- armedDir[side] = null;
184
- latched[side] = false;
185
- resetSide(side);
188
+ disarm(side);
186
189
  }
187
190
  }
188
191
  function axisOverflow(value, min, max) {
@@ -195,6 +198,147 @@ export function useTrayMagnetism(args) {
195
198
  return 0;
196
199
  }
197
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
+ }
198
342
  function update(x, y) {
199
343
  if (state.dragging || disabled.value) {
200
344
  resetAll();
@@ -205,124 +349,10 @@ export function useTrayMagnetism(args) {
205
349
  resetAll();
206
350
  return;
207
351
  }
208
- const { pull: configuredPull, radius: configuredRadius } = magnetism.value;
352
+ const band = normalizeRadius(magnetism.value.radius);
209
353
  const rect = el.getBoundingClientRect();
210
354
  for (const side of magneticSides.value) {
211
- const direction = restDirection(side);
212
- if (!direction) {
213
- armedDir[side] = null;
214
- latched[side] = false;
215
- resetSide(side);
216
- continue;
217
- }
218
- const allowInner = direction === "inner" || direction === "both";
219
- const allowOuter = direction === "outer" || direction === "both";
220
- const hRect = handleRect(side);
221
- const thickness = hRect ? side === "top" || side === "bottom" ? hRect.height : hRect.width : 0;
222
- const anchorHalf = thickness / 2;
223
- const radius = configuredRadius > 0 ? configuredRadius : anchorHalf / 2;
224
- const pull = configuredPull > 0 ? configuredPull : anchorHalf / 2;
225
- pullPx[side] = pull;
226
- if (radius <= 0) {
227
- armedDir[side] = null;
228
- latched[side] = false;
229
- resetSide(side);
230
- continue;
231
- }
232
- let perp = 0;
233
- let overflow = 0;
234
- let center = 0;
235
- switch (side) {
236
- case "top": {
237
- const edge = rect.top + state.snapped.top;
238
- perp = y - edge;
239
- overflow = axisOverflow(x, rect.left, rect.right);
240
- if (hRect) {
241
- center = hRect.top + hRect.height / 2 - edge - state.magnetic.top;
242
- }
243
- break;
244
- }
245
- case "bottom": {
246
- const edge = rect.bottom - state.snapped.bottom;
247
- perp = edge - y;
248
- overflow = axisOverflow(x, rect.left, rect.right);
249
- if (hRect) {
250
- center = edge - (hRect.top + hRect.height / 2) - state.magnetic.bottom;
251
- }
252
- break;
253
- }
254
- case "left": {
255
- const edge = rect.left + state.snapped.left;
256
- perp = x - edge;
257
- overflow = axisOverflow(y, rect.top, rect.bottom);
258
- if (hRect) {
259
- center = hRect.left + hRect.width / 2 - edge - state.magnetic.left;
260
- }
261
- break;
262
- }
263
- case "right": {
264
- const edge = rect.right - state.snapped.right;
265
- perp = edge - x;
266
- overflow = axisOverflow(y, rect.top, rect.bottom);
267
- if (hRect) {
268
- center = edge - (hRect.left + hRect.width / 2) - state.magnetic.right;
269
- }
270
- break;
271
- }
272
- }
273
- const innerEdge = center + anchorHalf;
274
- const outerEdge = center - anchorHalf;
275
- if (overflow === 0) {
276
- switch (true) {
277
- case (allowInner && perp >= innerEdge):
278
- armedDir[side] = "inner";
279
- break;
280
- case (allowOuter && perp <= outerEdge):
281
- armedDir[side] = "outer";
282
- break;
283
- }
284
- }
285
- const dir = armedDir[side];
286
- if (!dir) {
287
- resetSide(side);
288
- continue;
289
- }
290
- let t = 0;
291
- let sign = 0;
292
- switch (dir) {
293
- case "inner":
294
- t = clampValue((innerEdge - perp) / radius, 0, 1);
295
- sign = 1;
296
- break;
297
- case "outer":
298
- t = clampValue((perp - outerEdge) / radius, 0, 1);
299
- sign = -1;
300
- break;
301
- }
302
- switch (true) {
303
- case overflow === 0:
304
- latched[side] = t >= 1;
305
- break;
306
- case !latched[side]:
307
- armedDir[side] = null;
308
- resetSide(side);
309
- continue;
310
- }
311
- const magnitude = overflow === 0 ? easing.value(t) : 1;
312
- const offset = sign * pull * magnitude;
313
- const target = clampValue(
314
- offset,
315
- -state.dragged[side],
316
- maxInset(side) - state.dragged[side]
317
- );
318
- switch (true) {
319
- case Math.abs(target) > EPSILON:
320
- cancelSettle(side);
321
- state.magnetic[side] = target;
322
- break;
323
- default:
324
- settleSide(side);
325
- }
355
+ updateSide(side, x, y, rect, band);
326
356
  }
327
357
  }
328
358
  function onPointermove(e) {
@@ -362,6 +392,18 @@ export function useTrayMagnetism(args) {
362
392
  },
363
393
  { deep: true }
364
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
+ );
365
407
  watch(
366
408
  () => [enabled.value, magnetism.value.sides, state.options.snapPoints],
367
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?: number;
24
+ radius?: TrayMagneticRadius;
21
25
  pull?: number;
22
26
  easing?: EasingKey;
23
27
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maas/vue-equipment",
3
3
  "description": "Our Frontend Toolkit, Free and Open Source",
4
- "version": "1.0.0-beta.72",
4
+ "version": "1.0.0-beta.73",
5
5
  "contributors": [
6
6
  {
7
7
  "name": "Robin Scholz",