cotomy 0.3.15 → 0.3.16
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/README.md +2 -0
- package/dist/browser/cotomy.js +30 -0
- package/dist/browser/cotomy.js.map +1 -1
- package/dist/browser/cotomy.min.js +1 -1
- package/dist/browser/cotomy.min.js.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/view.js +30 -0
- package/dist/esm/view.js.map +1 -1
- package/dist/types/view.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -94,6 +94,8 @@ The View layer provides thin wrappers around DOM elements and window events.
|
|
|
94
94
|
- `screenPosition(): { top, left }`
|
|
95
95
|
- `rect(): { top, left, width, height }`
|
|
96
96
|
- `innerRect()` — Subtracts padding
|
|
97
|
+
- `overlaps(target: CotomyElement): boolean` — True if the two elements' `rect` values overlap (AABB)
|
|
98
|
+
- `overlapElements: CotomyElement[]` — Returns other CotomyElements (by `data-cotomy-instance`) that overlap this element
|
|
97
99
|
- Events
|
|
98
100
|
- Generic: `on(eventOrEvents, handler, options?)`, `off(eventOrEvents, handler?, options?)`, `once(eventOrEvents, handler, options?)`, `trigger(event[, Event])` — `eventOrEvents` accepts either a single event name or an array for batch registration/removal. `trigger` emits bubbling events by default and can be customized by passing an `Event`.
|
|
99
101
|
- Delegation: `onSubTree(eventOrEvents, selector, handler, options?)` — `eventOrEvents` can also be an array for listening to multiple delegated events at once.
|
package/dist/browser/cotomy.js
CHANGED
|
@@ -1278,6 +1278,36 @@ class CotomyElement {
|
|
|
1278
1278
|
height: rect.height + margin.top + margin.bottom
|
|
1279
1279
|
};
|
|
1280
1280
|
}
|
|
1281
|
+
static overlapsRect(left, right) {
|
|
1282
|
+
if (left.width <= 0 || left.height <= 0 || right.width <= 0 || right.height <= 0) {
|
|
1283
|
+
return false;
|
|
1284
|
+
}
|
|
1285
|
+
const leftRight = left.left + left.width;
|
|
1286
|
+
const leftBottom = left.top + left.height;
|
|
1287
|
+
const rightRight = right.left + right.width;
|
|
1288
|
+
const rightBottom = right.top + right.height;
|
|
1289
|
+
return left.left < rightRight
|
|
1290
|
+
&& leftRight > right.left
|
|
1291
|
+
&& left.top < rightBottom
|
|
1292
|
+
&& leftBottom > right.top;
|
|
1293
|
+
}
|
|
1294
|
+
overlaps(target) {
|
|
1295
|
+
if (!this.attached || !target.attached) {
|
|
1296
|
+
return false;
|
|
1297
|
+
}
|
|
1298
|
+
if (this.element === target.element) {
|
|
1299
|
+
return false;
|
|
1300
|
+
}
|
|
1301
|
+
return CotomyElement.overlapsRect(this.rect, target.rect);
|
|
1302
|
+
}
|
|
1303
|
+
get overlapElements() {
|
|
1304
|
+
if (!this.attached) {
|
|
1305
|
+
return [];
|
|
1306
|
+
}
|
|
1307
|
+
return CotomyElement.find("[data-cotomy-instance]")
|
|
1308
|
+
.filter(e => e.element !== this.element)
|
|
1309
|
+
.filter(e => this.overlaps(e));
|
|
1310
|
+
}
|
|
1281
1311
|
get padding() {
|
|
1282
1312
|
const style = this.getComputedStyle();
|
|
1283
1313
|
return {
|