Skip to content

Commit

Permalink
chore(TS): Correct typings for window and DOMParser (fabricjs#8871)
Browse files Browse the repository at this point in the history
  • Loading branch information
tushuhei authored Apr 30, 2023
1 parent 04f63df commit 577085a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- chore(TS): Fix typing for DOMParser [#8871](https://github.com/fabricjs/fabric.js/pull/8871)
- fix(Path, polyline): fix for SVG import [#8879](https://github.com/fabricjs/fabric.js/pull/8879)
- chore(TS) add types for loadSVGFromURl, parseSVGDocument, loadSVGFromString [#8869](https://github.com/fabricjs/fabric.js/pull/8869)
- chore(TS): finalize Path migration [#8438](https://github.com/fabricjs/fabric.js/pull/8438)
Expand Down
3 changes: 2 additions & 1 deletion src/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export const getEnv = () => env || getBrowserEnv();

export const getDocument = (): Document => getEnv().document;

export const getWindow = (): Window | DOMWindow => getEnv().window;
export const getWindow = (): (Window & typeof globalThis) | DOMWindow =>
getEnv().window;
2 changes: 1 addition & 1 deletion src/env/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type TCopyPasteData = {
};
export type TFabricEnv = {
document: Document;
window: Window | DOMWindow;
window: (Window & typeof globalThis) | DOMWindow;
isTouchSupported: boolean;
WebGLProbe: GLProbe;
dispose(element: Element): void;
Expand Down
2 changes: 1 addition & 1 deletion src/parser/loadSVGFromString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function loadSVGFromString(
reviver?: TSvgReviverCallback,
options?: LoadImageOptions
) {
const parser = new (getWindow() as any).DOMParser(),
const parser = new (getWindow().DOMParser)(),
// should we use `image/svg+xml` here?
doc = parser.parseFromString(string.trim(), 'text/xml');
parseSVGDocument(doc.documentElement, callback, reviver, options);
Expand Down

0 comments on commit 577085a

Please sign in to comment.