Move globalThis polyfill to compatibility, add more compatibility (#16386)

This commit is contained in:
Bram Kragten 2023-05-04 15:49:28 +02:00 committed by GitHub
parent 060f6ce3d8
commit 8695bbc490
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 16 deletions

View File

@ -84,9 +84,6 @@
<%= renderTemplate("../../../src/html/_js_base.html.template") %>
<%= renderTemplate("../../../src/html/_preload_roboto.html.template") %>
<script>
if (!window.globalThis) {
window.globalThis = window;
}
// Safari 12 and below does not have a compliant ES2015 implementation of template literals, so we ship ES5
if (!isS11_12) {
<% for (const entry of latestEntryJS) { %>

View File

@ -88,8 +88,8 @@ export class HaIcon extends LitElement {
}
if (!MDI_PREFIXES.includes(iconPrefix)) {
if (iconPrefix in customIcons) {
const customIcon = customIcons[iconPrefix];
const customIcon = customIcons[iconPrefix];
if (customIcon) {
if (customIcon && typeof customIcon.getIcon === "function") {
this._setCustomPath(customIcon.getIcon(iconName), requestedIcon);
}

View File

@ -36,5 +36,4 @@ export const customIcons = new Proxy(customIconsWindow.customIcons!, {
getIcon: customIconsets[prop],
}
: undefined),
has: (obj, prop: string) => prop in obj || prop in customIconsets,
});

View File

@ -94,7 +94,7 @@ const connProm = async (auth) => {
}
};
if (__DEV__) {
if (__DEV__ && "performance" in window) {
// Remove adoptedStyleSheets so style inspector works on shadow DOM.
// @ts-ignore
delete Document.prototype.adoptedStyleSheets;

View File

@ -41,9 +41,6 @@
<%= renderTemplate("_js_base.html.template") %>
<%= renderTemplate("_preload_roboto.html.template") %>
<script crossorigin="use-credentials">
if (!window.globalThis) {
window.globalThis = window;
}
// Safari 12 and below does not have a compliant ES2015 implementation of template literals, so we ship ES5
if (!isS11_12) {
<% for (const entry of latestEntryJS) { %>

View File

@ -84,9 +84,6 @@
<%= renderTemplate("_js_base.html.template") %>
<%= renderTemplate("_preload_roboto.html.template") %>
<script <% if (!useWDS) { %>crossorigin="use-credentials"<% } %>>
if (!window.globalThis) {
window.globalThis = window;
}
// Safari 12 and below does not have a compliant ES2015 implementation of template literals, so we ship ES5
if (!isS11_12) {
<% for (const entry of latestEntryJS) { %>

View File

@ -71,9 +71,6 @@
<%= renderTemplate("_js_base.html.template") %>
<%= renderTemplate("_preload_roboto.html.template") %>
<script crossorigin="use-credentials">
if (!window.globalThis) {
window.globalThis = window;
}
// Safari 12 and below does not have a compliant ES2015 implementation of template literals, so we ship ES5
if (!isS11_12) {
<% for (const entry of latestEntryJS) { %>

View File

@ -66,3 +66,27 @@ if (Element.prototype.getAttributeNames === undefined) {
return result;
};
}
// Source: https://gist.github.com/rebelchris/365f26f95d7e9f432f64f21886d9b9ef
if (!Element.prototype.toggleAttribute) {
Element.prototype.toggleAttribute = function (name, force) {
if (force !== undefined) {
force = !!force;
}
if (this.hasAttribute(name)) {
if (force) {
return true;
}
this.removeAttribute(name);
return false;
}
if (force === false) {
return false;
}
this.setAttribute(name, "");
return true;
};
}