@jsenv/dom 0.14.0 → 0.14.2
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/jsenv_dom.js +39 -5
- package/package.json +1 -1
package/dist/jsenv_dom.js
CHANGED
|
@@ -226,6 +226,7 @@ const dispatchPublicCustomEvent = (
|
|
|
226
226
|
const customEvent = new CustomEvent(customEventName, {
|
|
227
227
|
detail: resolveEventDetail(customEventDetail),
|
|
228
228
|
bubbles: true,
|
|
229
|
+
cancelable: true,
|
|
229
230
|
});
|
|
230
231
|
return el.dispatchEvent(customEvent);
|
|
231
232
|
};
|
|
@@ -357,7 +358,7 @@ const createEventGroupLogger = () => {
|
|
|
357
358
|
}, 0);
|
|
358
359
|
};
|
|
359
360
|
|
|
360
|
-
return (eOrMessage, sideEffect) => {
|
|
361
|
+
return (eOrMessage, sideEffect, ...args) => {
|
|
361
362
|
if (!(eOrMessage instanceof Event)) {
|
|
362
363
|
console.debug(eOrMessage);
|
|
363
364
|
return;
|
|
@@ -378,7 +379,7 @@ const createEventGroupLogger = () => {
|
|
|
378
379
|
currentInitiator = initiator;
|
|
379
380
|
}
|
|
380
381
|
const line = formatSideEffectLine(e, sideEffect);
|
|
381
|
-
console.debug(line);
|
|
382
|
+
console.debug(line, ...args);
|
|
382
383
|
scheduleGroupEnd();
|
|
383
384
|
};
|
|
384
385
|
};
|
|
@@ -11055,12 +11056,17 @@ const MIN_CONTENT_VISIBILITY_RATIO = 0.6;
|
|
|
11055
11056
|
const visibleRectEffect = (
|
|
11056
11057
|
element,
|
|
11057
11058
|
update,
|
|
11058
|
-
{
|
|
11059
|
+
{
|
|
11060
|
+
event: initialEvent = new CustomEvent("initialization"),
|
|
11061
|
+
skipElementResize,
|
|
11062
|
+
} = {},
|
|
11059
11063
|
) => {
|
|
11060
11064
|
const [teardown, addTeardown] = createPubSub();
|
|
11061
11065
|
const scrollContainer = getScrollContainer(element);
|
|
11062
11066
|
const scrollContainerIsDocument =
|
|
11063
11067
|
scrollContainer === document.documentElement;
|
|
11068
|
+
let lastMeasuredWidth;
|
|
11069
|
+
let lastMeasuredHeight;
|
|
11064
11070
|
let ancestorClosedCount = 0;
|
|
11065
11071
|
const check = (event) => {
|
|
11066
11072
|
|
|
@@ -11107,6 +11113,8 @@ const visibleRectEffect = (
|
|
|
11107
11113
|
|
|
11108
11114
|
// 2. Calculate element visible width/height
|
|
11109
11115
|
const { width, height } = element.getBoundingClientRect();
|
|
11116
|
+
lastMeasuredWidth = width;
|
|
11117
|
+
lastMeasuredHeight = height;
|
|
11110
11118
|
const visibleAreaWidth = scrollContainer.clientWidth;
|
|
11111
11119
|
const visibleAreaHeight = scrollContainer.clientHeight;
|
|
11112
11120
|
const visibleAreaRight = visibleAreaLeft + visibleAreaWidth;
|
|
@@ -11293,11 +11301,37 @@ const visibleRectEffect = (
|
|
|
11293
11301
|
});
|
|
11294
11302
|
}
|
|
11295
11303
|
}
|
|
11296
|
-
{
|
|
11304
|
+
on_element_resize: {
|
|
11305
|
+
if (skipElementResize) {
|
|
11306
|
+
break on_element_resize;
|
|
11307
|
+
}
|
|
11308
|
+
|
|
11309
|
+
let isFirst = true;
|
|
11310
|
+
let handlingResize = false;
|
|
11297
11311
|
const resizeObserver = new ResizeObserver(() => {
|
|
11298
|
-
{
|
|
11312
|
+
if (isFirst) {
|
|
11313
|
+
isFirst = false;
|
|
11314
|
+
return;
|
|
11315
|
+
}
|
|
11316
|
+
if (handlingResize) {
|
|
11299
11317
|
return;
|
|
11300
11318
|
}
|
|
11319
|
+
// we use directly the result of getBoundingClientRect() instead of the resizeEntry.contentRect or resizeEntry.borderBoxSize
|
|
11320
|
+
// so that:
|
|
11321
|
+
// - We can compare the dimensions measure in the last check and the current one
|
|
11322
|
+
// - We don't have to check element boz-sizing to know what to compare
|
|
11323
|
+
// - resizeEntry.borderBoxSize browser support is not that great
|
|
11324
|
+
const { width, height } = element.getBoundingClientRect();
|
|
11325
|
+
const widthDiff = Math.abs(width - lastMeasuredWidth);
|
|
11326
|
+
const heightDiff = Math.abs(height - lastMeasuredHeight);
|
|
11327
|
+
if (widthDiff === 0 && heightDiff === 0) {
|
|
11328
|
+
return;
|
|
11329
|
+
}
|
|
11330
|
+
handlingResize = true;
|
|
11331
|
+
autoCheck(
|
|
11332
|
+
new CustomEvent("element_size_change", { detail: { width, height } }),
|
|
11333
|
+
);
|
|
11334
|
+
handlingResize = false;
|
|
11301
11335
|
});
|
|
11302
11336
|
resizeObserver.observe(element);
|
|
11303
11337
|
// Temporarily disconnect ResizeObserver to prevent feedback loops eventually caused by update function
|