kollapsminoriteten/wp-includes/js/dist/vendor/wp-polyfill-dom-rect.js

102 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2021-07-23 11:58:50 +02:00
// DOMRect
2020-05-06 17:23:38 +02:00
(function (global) {
function number(v) {
return v === undefined ? 0 : Number(v);
}
2022-06-16 14:03:35 +02:00
2021-07-23 11:58:50 +02:00
function different(u, v) {
2020-05-06 17:23:38 +02:00
return u !== v && !(isNaN(u) && isNaN(v));
}
2021-07-23 11:58:50 +02:00
function DOMRect(xArg, yArg, wArg, hArg) {
2020-05-06 17:23:38 +02:00
var x, y, width, height, left, right, top, bottom;
2021-07-23 11:58:50 +02:00
x = number(xArg);
2020-05-06 17:23:38 +02:00
y = number(yArg);
width = number(wArg);
height = number(hArg);
2021-07-23 11:58:50 +02:00
Object.defineProperties(this, {
2020-05-06 17:23:38 +02:00
x: {
get: function () { return x; },
set: function (newX) {
if (different(x, newX)) {
x = newX;
left = right = undefined;
}
},
enumerable: true
},
y: {
get: function () { return y; },
set: function (newY) {
if (different(y, newY)) {
y = newY;
top = bottom = undefined;
}
},
enumerable: true
},
width: {
get: function () { return width; },
set: function (newWidth) {
if (different(width, newWidth)) {
width = newWidth;
left = right = undefined;
}
},
enumerable: true
},
height: {
get: function () { return height; },
set: function (newHeight) {
if (different(height, newHeight)) {
height = newHeight;
top = bottom = undefined;
}
},
enumerable: true
},
left: {
get: function () {
if (left === undefined) {
left = x + Math.min(0, width);
}
return left;
},
enumerable: true
},
right: {
get: function () {
if (right === undefined) {
right = x + Math.max(0, width);
}
return right;
},
enumerable: true
},
top: {
get: function () {
if (top === undefined) {
top = y + Math.min(0, height);
}
return top;
},
enumerable: true
},
bottom: {
get: function () {
if (bottom === undefined) {
bottom = y + Math.max(0, height);
}
return bottom;
},
enumerable: true
}
});
}
2022-06-16 14:03:35 +02:00
2021-07-23 11:58:50 +02:00
global.DOMRect = DOMRect;
}(self));