Safari executes the resize observer asynchronously, causing the offset to be not calculated when the dialog was just added to the DOM.
In addition the `contentBoxSize` was observed to report the width of the element without any borders. We are able to simplify the code by querying the client rect instead which reports the proper width.
Fixes #5519
// elements to be squished together. The actual value for
// `transform` must not use percent values, because this
// causes blurry text rendering in Chromium.
- const resizeObserver = new ResizeObserver((entries) => {
+ const resizeObserver = new ResizeObserver(() => {
if (dialog.getAttribute("aria-hidden") === "false") {
- for (const entry of entries) {
- let width: number;
- if (entry.contentBoxSize) {
- const contentBoxSize: ResizeObserverSize = Array.isArray(entry.contentBoxSize)
- ? entry.contentBoxSize[0]
- : entry.contentBoxSize;
- width = contentBoxSize.inlineSize;
- } else {
- // Safari < 15.4 supports only the older spec.
- width = entry.contentRect.width;
- }
-
- const offset = Math.floor(width / 2);
- dialog.style.setProperty("--translate-x", `-${offset}px`);
- }
+ const offset = Math.floor(dialog.getBoundingClientRect().width / 2);
+ dialog.style.setProperty("--translate-x", `-${offset}px`);
}
});
resizeObserver.observe(dialog);
const maximumHeight = window.innerHeight * (_dialogFullHeight ? 1 : 0.8) - unavailableHeight;
contentContainer.style.setProperty("max-height", `${~~maximumHeight}px`, "");
+ const offset = Math.floor(data.dialog.getBoundingClientRect().width / 2);
+ data.dialog.style.setProperty("--translate-x", `-${offset}px`);
+
const callbackObject = _dialogToObject.get(id);
//noinspection JSUnresolvedVariable
if (callbackObject !== undefined && typeof callbackObject._dialogSubmit === "function") {
// elements to be squished together. The actual value for
// `transform` must not use percent values, because this
// causes blurry text rendering in Chromium.
- const resizeObserver = new ResizeObserver((entries) => {
+ const resizeObserver = new ResizeObserver(() => {
if (dialog.getAttribute("aria-hidden") === "false") {
- for (const entry of entries) {
- let width;
- if (entry.contentBoxSize) {
- const contentBoxSize = Array.isArray(entry.contentBoxSize)
- ? entry.contentBoxSize[0]
- : entry.contentBoxSize;
- width = contentBoxSize.inlineSize;
- }
- else {
- // Safari < 15.4 supports only the older spec.
- width = entry.contentRect.width;
- }
- const offset = Math.floor(width / 2);
- dialog.style.setProperty("--translate-x", `-${offset}px`);
- }
+ const offset = Math.floor(dialog.getBoundingClientRect().width / 2);
+ dialog.style.setProperty("--translate-x", `-${offset}px`);
}
});
resizeObserver.observe(dialog);
unavailableHeight += Util_1.default.outerHeight(data.header);
const maximumHeight = window.innerHeight * (_dialogFullHeight ? 1 : 0.8) - unavailableHeight;
contentContainer.style.setProperty("max-height", `${~~maximumHeight}px`, "");
+ const offset = Math.floor(data.dialog.getBoundingClientRect().width / 2);
+ data.dialog.style.setProperty("--translate-x", `-${offset}px`);
const callbackObject = _dialogToObject.get(id);
//noinspection JSUnresolvedVariable
if (callbackObject !== undefined && typeof callbackObject._dialogSubmit === "function") {
@keyframes wcfDialog {
0% {
visibility: visible;
- transform: translateX(var(--translate-x, 0)) translateY(calc(-50% - 20px));
- //top: 8%;
+ transform: translateX(var(--translate-x)) translateY(calc(-50% - 20px));
}
100% {
visibility: visible;
- //top: 10%;
+ transform: translateX(var(--translate-x)) translateY(-50%);
}
}
// this causes a blurry text rendering in Chromium.
// The offset is calculated using a `ResizeObserver`.
left: 50%;
- transform: translateX(var(--translate-x, 0)) translateY(-50%);
+ transform: translateX(var(--translate-x)) translateY(-50%);
&[aria-hidden="false"] {
animation: wcfDialog 0.24s;