MCPcopy
hub / github.com/ampproject/amphtml / patchWebAnimations

Function patchWebAnimations

build-system/common/update-packages.js:33–55  ·  view source on GitHub ↗

* 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.

()

Source from the content-addressed store, hash-verified

31 * or a friendly iframe.
32 */
33function 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`

Callers 1

updatePackagesFunction · 0.85

Calls 3

writeIfUpdatedFunction · 0.85
toStringMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected