forked from mxx1111/mdlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolyfill.cjs
More file actions
54 lines (54 loc) · 1.73 KB
/
Copy pathpolyfill.cjs
File metadata and controls
54 lines (54 loc) · 1.73 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
// Preload polyfill for Node.js environment (CJS format for --require)
// Must be loaded via --require BEFORE the main entry point
'use strict'
function noop() {}
globalThis.MathJax = {
texReset() {},
tex2svg(latex) {
const svgStyle = {}
const styleProxy = new Proxy(svgStyle, {
set(_, prop, value) { svgStyle[prop] = value; return true },
get(_, prop) {
if (prop === 'setProperty')
return (p, v) => { svgStyle[p] = v }
if (prop === 'display')
return svgStyle[prop] || ''
return svgStyle[prop]
},
})
return {
firstChild: {
outerHTML: `<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>${latex.replace(/</g, '<')}</mi></math>`,
style: styleProxy,
getAttribute: () => null,
removeAttribute: noop,
},
}
},
}
globalThis.window = {
MathJax: globalThis.MathJax,
addEventListener: noop,
removeEventListener: noop,
dispatchEvent: () => true,
getComputedStyle: () => ({ getPropertyValue: () => '' }),
requestAnimationFrame: typeof requestAnimationFrame !== 'undefined' ? requestAnimationFrame : cb => setTimeout(cb, 16),
matchMedia: () => ({ matches: false, addEventListener: noop, removeEventListener: noop }),
}
globalThis.document = {
getElementById: () => null,
documentElement: { getAttribute: () => null, style: {} },
createDocumentFragment: () => ({ appendChild: noop, childNodes: [] }),
querySelectorAll: () => [],
querySelector: () => null,
createElement: tag => ({
tagName: tag.toUpperCase(),
setAttribute: noop,
appendChild: noop,
innerHTML: '',
style: {},
}),
createTextNode: text => ({ textContent: text, data: text }),
body: { appendChild: noop },
head: { appendChild: noop },
}