Files
tabby-web/frontend/src/ssr-polyfills.ts

42 lines
944 B
TypeScript
Raw Normal View History

2021-10-24 21:50:55 +02:00
import * as domino from 'domino'
import * as fs from 'fs'
import * as path from 'path'
2021-07-24 20:25:09 +02:00
2021-10-24 21:50:55 +02:00
const template = fs.readFileSync(path.join(process.cwd(), 'build', 'index.html')).toString()
const win = domino.createWindow(template)
2021-07-24 20:25:09 +02:00
2021-10-24 21:50:55 +02:00
global['window'] = win
2021-07-24 20:25:09 +02:00
Object.defineProperty(win.document.body.style, 'transform', {
value: () => {
return {
enumerable: true,
2021-10-24 21:50:55 +02:00
configurable: true,
}
2021-07-24 20:25:09 +02:00
},
2021-10-24 21:50:55 +02:00
})
2021-07-24 20:25:09 +02:00
Object.defineProperty(win.document.body.style, 'z-index', {
value: () => {
2021-10-24 21:50:55 +02:00
return {
enumerable: true,
configurable: true,
}
2021-07-24 20:25:09 +02:00
},
2021-10-24 21:50:55 +02:00
})
2021-07-24 20:25:09 +02:00
2021-10-24 21:50:55 +02:00
global['document'] = win.document
global['CSS'] = null
2021-07-24 20:25:09 +02:00
// global['atob'] = win.atob;
global['atob'] = (base64: string) => {
2021-10-24 21:50:55 +02:00
return Buffer.from(base64, 'base64').toString()
}
2021-07-24 20:25:09 +02:00
2021-10-24 21:50:55 +02:00
function setDomTypes () {
2021-07-24 20:25:09 +02:00
// Make all Domino types available as types in the global env.
Object.assign(global, domino['impl']);
2021-10-24 21:50:55 +02:00
(global as any)['KeyboardEvent'] = domino['impl'].Event
2021-07-24 20:25:09 +02:00
}
2021-10-24 21:50:55 +02:00
setDomTypes()