Prevent style changes to wrapper divs (#2646)

Prevent style changes to wrapper divs
This commit is contained in:
Sami Vänttinen 2025-08-24 07:47:54 +03:00 committed by GitHub
parent 991bdb8c95
commit 5d6c4834fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 0 deletions

View file

@ -117,6 +117,7 @@ class Autocomplete {
this.container.append(this.list);
this.shadowRoot.append(this.container);
document.body.append(this.wrapper);
kpxcUI.observeWrapper(this.wrapper);
// Add a footer message for auto-submit
if (this.autoSubmit) {

View file

@ -165,6 +165,7 @@ kpxcBanner.create = async function(credentials = {}) {
if (window.self === window.top && !kpxcBanner.created) {
window.parent.document.body.appendChild(wrapper);
kpxcUI.observeWrapper(wrapper);
kpxcBanner.created = true;
}
};

View file

@ -159,6 +159,7 @@ kpxcCustomLoginFieldsBanner.create = async function() {
if (!kpxcCustomLoginFieldsBanner.created) {
window.self.document.body.appendChild(wrapper);
kpxcUI.observeWrapper(wrapper);
kpxcCustomLoginFieldsBanner.created = true;
}

View file

@ -69,6 +69,7 @@ class Icon {
this.shadowRoot.append(styleSheet);
this.shadowRoot.append(this.icon);
document.body.append(wrapper);
kpxcUI.observeWrapper(wrapper);
}
switchIcon(state, uuid) {
@ -394,6 +395,22 @@ kpxcUI.createButton = function(color, textContent, callback) {
return button;
};
// Observe and prevent style changes to wrapper div elements
kpxcUI.createWrapperObserver = function() {
kpxcUI.wrapperObserver = new MutationObserver(function(mutations, obs) {
for (const mut of mutations) {
if (mut?.target && mut.target.style?.cssText !== 'all: unset;') {
mut.target.removeAttribute('style');
mut.target.style.all = 'unset';
}
}
});
};
kpxcUI.observeWrapper = function(elem) {
kpxcUI.wrapperObserver.observe(elem, { attributes: true, attributeFilter: [ 'style' ] });
};
const DOMRectToArray = function(domRect) {
return [ domRect.bottom, domRect.height, domRect.left, domRect.right, domRect.top, domRect.width, domRect.x, domRect.y ];
};
@ -439,6 +456,8 @@ document.addEventListener('mouseup', function(e) {
kpxcUI.mouseDown = false;
});
document.addEventListener('DOMContentLoaded', kpxcUI.createWrapperObserver());
HTMLDivElement.prototype.appendMultiple = function(...args) {
for (const a of args) {
this.append(a);