source: trip-planner-front/node_modules/@angular/cdk/esm2015/drag-drop/client-rect.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 7.9 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8/** Gets a mutable version of an element's bounding `ClientRect`. */
9export function getMutableClientRect(element) {
10 const clientRect = element.getBoundingClientRect();
11 // We need to clone the `clientRect` here, because all the values on it are readonly
12 // and we need to be able to update them. Also we can't use a spread here, because
13 // the values on a `ClientRect` aren't own properties. See:
14 // https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Notes
15 return {
16 top: clientRect.top,
17 right: clientRect.right,
18 bottom: clientRect.bottom,
19 left: clientRect.left,
20 width: clientRect.width,
21 height: clientRect.height
22 };
23}
24/**
25 * Checks whether some coordinates are within a `ClientRect`.
26 * @param clientRect ClientRect that is being checked.
27 * @param x Coordinates along the X axis.
28 * @param y Coordinates along the Y axis.
29 */
30export function isInsideClientRect(clientRect, x, y) {
31 const { top, bottom, left, right } = clientRect;
32 return y >= top && y <= bottom && x >= left && x <= right;
33}
34/**
35 * Updates the top/left positions of a `ClientRect`, as well as their bottom/right counterparts.
36 * @param clientRect `ClientRect` that should be updated.
37 * @param top Amount to add to the `top` position.
38 * @param left Amount to add to the `left` position.
39 */
40export function adjustClientRect(clientRect, top, left) {
41 clientRect.top += top;
42 clientRect.bottom = clientRect.top + clientRect.height;
43 clientRect.left += left;
44 clientRect.right = clientRect.left + clientRect.width;
45}
46/**
47 * Checks whether the pointer coordinates are close to a ClientRect.
48 * @param rect ClientRect to check against.
49 * @param threshold Threshold around the ClientRect.
50 * @param pointerX Coordinates along the X axis.
51 * @param pointerY Coordinates along the Y axis.
52 */
53export function isPointerNearClientRect(rect, threshold, pointerX, pointerY) {
54 const { top, right, bottom, left, width, height } = rect;
55 const xThreshold = width * threshold;
56 const yThreshold = height * threshold;
57 return pointerY > top - yThreshold && pointerY < bottom + yThreshold &&
58 pointerX > left - xThreshold && pointerX < right + xThreshold;
59}
60//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpZW50LXJlY3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL2RyYWctZHJvcC9jbGllbnQtcmVjdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxvRUFBb0U7QUFDcEUsTUFBTSxVQUFVLG9CQUFvQixDQUFDLE9BQWdCO0lBQ25ELE1BQU0sVUFBVSxHQUFHLE9BQU8sQ0FBQyxxQkFBcUIsRUFBRSxDQUFDO0lBRW5ELG9GQUFvRjtJQUNwRixrRkFBa0Y7SUFDbEYsMkRBQTJEO0lBQzNELHVGQUF1RjtJQUN2RixPQUFPO1FBQ0wsR0FBRyxFQUFFLFVBQVUsQ0FBQyxHQUFHO1FBQ25CLEtBQUssRUFBRSxVQUFVLENBQUMsS0FBSztRQUN2QixNQUFNLEVBQUUsVUFBVSxDQUFDLE1BQU07UUFDekIsSUFBSSxFQUFFLFVBQVUsQ0FBQyxJQUFJO1FBQ3JCLEtBQUssRUFBRSxVQUFVLENBQUMsS0FBSztRQUN2QixNQUFNLEVBQUUsVUFBVSxDQUFDLE1BQU07S0FDMUIsQ0FBQztBQUNKLENBQUM7QUFFRDs7Ozs7R0FLRztBQUNILE1BQU0sVUFBVSxrQkFBa0IsQ0FBQyxVQUFzQixFQUFFLENBQVMsRUFBRSxDQUFTO0lBQzdFLE1BQU0sRUFBQyxHQUFHLEVBQUUsTUFBTSxFQUFFLElBQUksRUFBRSxLQUFLLEVBQUMsR0FBRyxVQUFVLENBQUM7SUFDOUMsT0FBTyxDQUFDLElBQUksR0FBRyxJQUFJLENBQUMsSUFBSSx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aHR9ID0gcmVjdDtcbiAgY29uc3QgeFRocmVzaG9sZCA9IHdpZHRoICogdGhyZXNob2xkO1xuICBjb25zdCB5VGhyZXNob2xkID0gaGVpZ2h0ICogdGhyZXNob2xkO1xuXG4gIHJldHVybiBwb2ludGVyWSA+IHRvcCAtIHlUaHJlc2hvbGQgJiYgcG9pbnRlclkgPCBib3R0b20gKyB5VGhyZXNob2xkICYmXG4gICAgICAgICBwb2ludGVyWCA+IGxlZnQgLSB4VGhyZXNob2xkICYmIHBvaW50ZXJYIDwgcmlnaHQgKyB4VGhyZXNob2xkO1xufVxuIl19
Note: See TracBrowser for help on using the repository browser.