* Patches Web Animations polyfill by wrapping its body into `install` function. * This gives us an option to call polyfill directly on the main window * or a friendly iframe.
()
| 31 | * or a friendly iframe. |
| 32 | */ |
| 33 | function patchWebAnimations() { |
| 34 | // Copies web-animations-js into a new file that has an export. |
| 35 | const patchedName = |
| 36 | 'node_modules/web-animations-js/web-animations.install.js'; |
| 37 | let file = fs |
| 38 | .readFileSync('node_modules/web-animations-js/web-animations.min.js') |
| 39 | .toString(); |
| 40 | // Replace |requestAnimationFrame| with |window|. |
| 41 | file = file.replace(/requestAnimationFrame/g, function (a, b) { |
| 42 | if (file.charAt(b - 1) == '.') { |
| 43 | return a; |
| 44 | } |
| 45 | return 'window.' + a; |
| 46 | }); |
| 47 | // Wrap the contents inside the install function. |
| 48 | file = |
| 49 | 'export function installWebAnimations(window) {\n' + |
| 50 | 'var document = window.document;\n' + |
| 51 | file + |
| 52 | '\n' + |
| 53 | '}\n'; |
| 54 | writeIfUpdated(patchedName, file); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Patches Intersection Observer polyfill by wrapping its body into `install` |
no test coverage detected