@planjs/utils
Version:
🔧 Common tools collection
63 lines (61 loc) • 1.29 kB
JavaScript
import global from '../global';
export var ssrDocument = {
body: {},
addEventListener: function addEventListener() {},
removeEventListener: function removeEventListener() {},
activeElement: {
blur: function blur() {},
nodeName: ''
},
querySelector: function querySelector() {
return null;
},
querySelectorAll: function querySelectorAll() {
return [];
},
getElementById: function getElementById() {
return null;
},
createEvent: function createEvent() {
return {
initEvent: function initEvent() {}
};
},
createElement: function createElement() {
return {
children: [],
childNodes: [],
style: {},
setAttribute: function setAttribute() {},
getElementsByTagName: function getElementsByTagName() {
return [];
}
};
},
createElementNS: function createElementNS() {
return {};
},
importNode: function importNode() {
return null;
},
location: {
hash: '',
host: '',
hostname: '',
href: '',
origin: '',
pathname: '',
protocol: '',
search: ''
}
};
/**
* 程序入口处调用
* 使用global.document代替document
*/
export function shim() {
if (!global.document) {
global.document = ssrDocument;
}
return global.document;
}