-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
25,688 additions
and
28,690 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
import './src/env/browser'; | ||
|
||
export * as default from './fabric'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './src/env/node'; | ||
|
||
export * as default from './fabric'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable no-restricted-globals */ | ||
import { setEnv } from '.'; | ||
import { config } from '../config'; | ||
import { TCopyPasteData, TFabricEnv } from './types'; | ||
|
||
const copyPasteData: TCopyPasteData = {}; | ||
|
||
const fabricDocument = | ||
document instanceof | ||
(typeof HTMLDocument !== 'undefined' ? HTMLDocument : Document) | ||
? document | ||
: document.implementation.createHTMLDocument(''); | ||
|
||
config.configure({ | ||
devicePixelRatio: window.devicePixelRatio || 1, | ||
}); | ||
|
||
export const getEnv = (): TFabricEnv => { | ||
return { | ||
document: fabricDocument, | ||
window, | ||
isTouchSupported: | ||
'ontouchstart' in window || | ||
'ontouchstart' in fabricDocument || | ||
(window && window.navigator && window.navigator.maxTouchPoints > 0), | ||
isLikelyNode: false, | ||
copyPasteData, | ||
}; | ||
}; | ||
|
||
setEnv(getEnv()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { TFabricEnv } from './types'; | ||
|
||
let env: TFabricEnv; | ||
|
||
export const setEnv = (value: TFabricEnv) => { | ||
env = value; | ||
}; | ||
|
||
export const getEnv = () => env; | ||
|
||
export const getDocument = (): Document => env.document; | ||
|
||
export const getWindow = (): Window => env.window; | ||
|
||
export const setEnvForTests = (window: Window) => { | ||
env.document = window.document; | ||
env.window = window; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* eslint-disable no-restricted-globals */ | ||
import { JSDOM } from 'jsdom'; | ||
import { implForWrapper as jsdomImplForWrapper } from 'jsdom/lib/jsdom/living/generated/utils'; | ||
import { Canvas as nodeCanvas } from 'jsdom/lib/jsdom/utils'; | ||
import { config } from '../config'; | ||
import { setEnv } from './index'; | ||
import { TCopyPasteData, TFabricEnv } from './types'; | ||
|
||
const copyPasteData: TCopyPasteData = {}; | ||
|
||
const virtualWindow = new JSDOM( | ||
decodeURIComponent( | ||
'%3C!DOCTYPE%20html%3E%3Chtml%3E%3Chead%3E%3C%2Fhead%3E%3Cbody%3E%3C%2Fbody%3E%3C%2Fhtml%3E' | ||
), | ||
{ | ||
features: { | ||
FetchExternalResources: ['img'], | ||
}, | ||
resources: 'usable', | ||
} | ||
).window; | ||
|
||
const fabricDocument = virtualWindow.document; | ||
const fabricWindow = virtualWindow; | ||
|
||
const isTouchSupported = | ||
'ontouchstart' in fabricWindow || | ||
'ontouchstart' in fabricDocument || | ||
(fabricWindow && | ||
fabricWindow.navigator && | ||
fabricWindow.navigator.maxTouchPoints > 0); | ||
|
||
config.configure({ | ||
devicePixelRatio: fabricWindow.devicePixelRatio || 1, | ||
}); | ||
|
||
export const getEnv = (): TFabricEnv => { | ||
return { | ||
document: fabricDocument, | ||
window: fabricWindow, | ||
isTouchSupported, | ||
isLikelyNode: true, | ||
nodeCanvas, | ||
jsdomImplForWrapper, | ||
copyPasteData, | ||
}; | ||
}; | ||
|
||
setEnv(getEnv()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Canvas } from 'canvas'; | ||
|
||
export type TCopyPasteData = { | ||
copiedText?: string; | ||
copiedStyle?: Record<string, string>; | ||
}; | ||
export type TFabricEnv = { | ||
document: Document; | ||
window: Window; | ||
isTouchSupported: boolean; | ||
isLikelyNode: boolean; | ||
nodeCanvas?: Canvas; | ||
jsdomImplForWrapper?: any; | ||
copyPasteData: TCopyPasteData; | ||
}; |
Oops, something went wrong.