Procházet zdrojové kódy

fix: remove TS trusted types shims

Sv443 před 7 měsíci
rodič
revize
e00d4d9
3 změnil soubory, kde provedl 8 přidání a 18 odebrání
  1. 5 0
      .changeset/slow-ants-rush.md
  2. 3 3
      lib/dom.ts
  3. 0 15
      lib/types.ts

+ 5 - 0
.changeset/slow-ants-rush.md

@@ -0,0 +1,5 @@
+---
+"@sv443-network/userutils": patch
+---
+
+Fixed dev-only TypeScript shims being included in the final bundle

+ 3 - 3
lib/dom.ts

@@ -1,5 +1,3 @@
-import type { TrustedTypesPolicy } from "./types.js";
-
 /**
  * Returns `unsafeWindow` if the `@grant unsafeWindow` is given, otherwise falls back to the regular `window`
  */
@@ -235,7 +233,7 @@ export function getSiblingsFrame<
   return [] as TSibling[];
 }
 
-let ttPolicy: TrustedTypesPolicy | undefined;
+let ttPolicy: { createHTML: (html: string) => string } | undefined;
 
 /**
  * Sets the innerHTML property of the provided element without any sanitation or validation.  
@@ -245,7 +243,9 @@ let ttPolicy: TrustedTypesPolicy | undefined;
  * ⚠️ This function does not perform any sanitization and should thus be used with utmost caution, as it can easily lead to XSS vulnerabilities!
  */
 export function setInnerHtmlUnsafe<TElement extends Element = HTMLElement>(element: TElement, html: string): TElement {
+  // @ts-ignore
   if(!ttPolicy && typeof window?.trustedTypes?.createPolicy === "function") {
+    // @ts-ignore
     ttPolicy = window.trustedTypes.createPolicy("_uu_set_innerhtml_unsafe", {
       createHTML: (unsafeHtml: string) => unsafeHtml,
     });

+ 0 - 15
lib/types.ts

@@ -1,18 +1,3 @@
-//#region shims
-
-export type TrustedTypesPolicy = {
-  createHTML?: (dirty: string) => string;
-};
-
-declare global {
-  interface Window {
-    // poly-shim for the new Trusted Types API
-    trustedTypes: {
-      createPolicy(name: string, policy: TrustedTypesPolicy): TrustedTypesPolicy;
-    };
-  }
-}
-
 //#region UU types
 
 /** Represents any value that is either a string itself or can be converted to one (implicitly and explicitly) because it has a toString() method */