forked from NativeScript/canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
112 lines (98 loc) · 2.95 KB
/
index.ts
File metadata and controls
112 lines (98 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require('@nativescript/core/globals');
if (__ANDROID__ && !(global as any).__canvasLoaded) {
try {
// load canvas lib if polyfill is called before
java.lang.System.loadLibrary('canvasnative');
(global as any).__canvasLoaded = true;
} catch (e) {}
}
import { TNSXMLHttpRequest, FileReader, Blob } from './async/async';
import { Element } from './DOM/Element';
import { Document } from './DOM/Document';
import './window';
import './resize';
import './process';
import './localStorage';
import { TextDecoder, TextEncoder, ImageBitmap } from '@nativescript/canvas';
import './workerPatch';
import { FontFaceSet } from '@nativescript/canvas';
if (!global.Document) {
Object.defineProperty(global, 'Document', {
value: Document,
configurable: true,
writable: true,
});
}
(global as any).document = (global as any).window.document = (global as any).document || new Document();
if (!global.document.fonts) {
(global as any).document.fonts = global.fonts || new FontFaceSet();
}
(global as any).window.createImageBitmap = (global as any).createImageBitmap = (...args) => {
const image = args[0];
const sx_or_options = args[1];
const sy = args[2];
const sw = args[3];
const sh = args[4];
if ((typeof sw === 'number' && sw === 0) || (typeof sh === 'number' && sh === 0)) {
return Promise.reject(new RangeError(`Failed to execute 'createImageBitmap' : The crop rect width is 0`));
}
if (args.length === 1) {
//@ts-ignore
return ImageBitmap.createFrom(image);
} else if (args.length === 2) {
//@ts-ignore
return ImageBitmap.createFrom(image, sx_or_options);
} else if (args.length === 5) {
//@ts-ignore
return ImageBitmap.createFromRect(image, sx_or_options, sy, sw, sh);
} else if (args.length === 6) {
//@ts-ignore
return ImageBitmap.createFromRect(image, sx_or_options, sy, sw, sh, args[5]);
}
};
if (!(global as any).Intl || (global as any).window.Intl) {
(global as any).Intl = (global as any).window.Intl = (global as any).Intl || {}; // pixijs
}
import { MutationObserver } from './MutationObserver';
if (!global.MutationObserver) {
Object.defineProperty(global, 'MutationObserver', {
value: MutationObserver,
configurable: true,
writable: true,
});
}
Object.defineProperty(global, 'Element', {
value: Element,
configurable: true,
writable: true,
});
Object.defineProperty(global, 'XMLHttpRequest', {
value: TNSXMLHttpRequest,
configurable: true,
writable: true,
});
Object.defineProperty(global, 'Blob', {
value: Blob,
configurable: true,
writable: true,
});
Object.defineProperty(global, 'FileReader', {
value: FileReader,
configurable: true,
writable: true,
});
if (!((global as any).TextDecoder instanceof TextDecoder)) {
Object.defineProperty(global, 'TextDecoder', {
value: TextDecoder,
configurable: true,
writable: true,
});
}
if (!((global as any).TextEncoder instanceof TextEncoder)) {
Object.defineProperty(global, 'TextEncoder', {
value: TextEncoder,
configurable: true,
writable: true,
});
}
import './urlBlobPatch';