-
Notifications
You must be signed in to change notification settings - Fork 237
/
Copy pathindex.js
70 lines (56 loc) · 1.58 KB
/
index.js
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
import {atob as _atob} from 'abab';
import _XMLHttpRequest from './XMLHttpRequest'
import copyProperties from './copyProperties'
import EventTarget from "./EventTarget"
export function createScopedThreejs(canvas) {
// adapt canvas
// canvas.style = {width: canvas.width + 'px', height: canvas.height + 'px'}
// canvas.clientHeight = canvas.height
// canvas.clientWidth = canvas.width
Object.defineProperty(canvas, 'style', {
get() {
return {
width: this.width + 'px',
height: this.height + 'px'
}
}
})
Object.defineProperty(canvas, 'clientHeight', {
get() {
return this.height
}
})
Object.defineProperty(canvas, 'clientWidth', {
get() {
return this.width
}
})
copyProperties(canvas.constructor.prototype, EventTarget.prototype)
// eslint-disable-next-line
const document = {
createElementNS(_, type) {
if (type === 'canvas') return canvas
if (type === 'img') return canvas.createImage()
}
}
copyProperties(document.constructor.prototype, EventTarget.prototype)
// eslint-disable-next-line
const window = {
AudioContext: function() {},
URL: {},
}
copyProperties(window.constructor.prototype, EventTarget.prototype)
// eslint-disable-next-line
const atob = (a) => {
return _atob(a)
}
// eslint-disable-next-line
const XMLHttpRequest = _XMLHttpRequest
const exports = {};
// eslint-disable-next-line
const HTMLCanvasElement = undefined;
// three.js source code will be injected here
// eslint-disable-next-line
__INJECT_THREE__
return exports
}