diff --git a/build-system/compile/bundles.config.js b/build-system/compile/bundles.config.js index 7f91aec79304..a18f91224f67 100644 --- a/build-system/compile/bundles.config.js +++ b/build-system/compile/bundles.config.js @@ -337,12 +337,6 @@ exports.extensionBundles = [ latestVersion: '0.1', type: TYPES.MISC, }, - { - name: 'amp-animation-polyfill', - version: '0.1', - latestVersion: '0.1', - type: TYPES.MISC, - }, { name: 'amp-apester-media', version: '0.1', diff --git a/build-system/tasks/presubmit-checks.js b/build-system/tasks/presubmit-checks.js index fadaa58158dc..b84489c303c5 100644 --- a/build-system/tasks/presubmit-checks.js +++ b/build-system/tasks/presubmit-checks.js @@ -1064,7 +1064,6 @@ const forbiddenTermsSrcInclusive = { 'extensions/amp-ad-network-adsense-impl/0.1/amp-ad-network-adsense-impl.js', // eslint-disable-line max-len 'extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js', // eslint-disable-line max-len 'extensions/amp-lightbox-gallery/0.1/amp-lightbox-gallery.js', - 'extensions/amp-animation/0.1/install-polyfill.js', ], }, 'loadElementClass': { diff --git a/extensions/amp-animation-polyfill/0.1/amp-animation-polyfill.js b/extensions/amp-animation-polyfill/0.1/amp-animation-polyfill.js deleted file mode 100644 index 05ed00f6fd80..000000000000 --- a/extensions/amp-animation-polyfill/0.1/amp-animation-polyfill.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright 2020 The AMP HTML Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {installWebAnimations} from 'web-animations-js/web-animations.install'; - -installWebAnimations(window); diff --git a/extensions/amp-animation-polyfill/OWNERS b/extensions/amp-animation-polyfill/OWNERS deleted file mode 100644 index 15f6db952f17..000000000000 --- a/extensions/amp-animation-polyfill/OWNERS +++ /dev/null @@ -1,13 +0,0 @@ -// For an explanation of the OWNERS rules and syntax, see: -// https://github.com/ampproject/amp-github-apps/blob/master/owners/OWNERS.example - -{ - rules: [ - { - owners: [ - {name: 'ampproject/wg-performance'}, - {name: 'ampproject/wg-runtime'}, - ], - }, - ], -} diff --git a/extensions/amp-animation/0.1/amp-animation.js b/extensions/amp-animation/0.1/amp-animation.js index d81aed466231..13019ffe5059 100644 --- a/extensions/amp-animation/0.1/amp-animation.js +++ b/extensions/amp-animation/0.1/amp-animation.js @@ -26,7 +26,7 @@ import {getChildJsonConfig} from '../../../src/json'; import {getDetail, listen} from '../../../src/event-helper'; import {getFriendlyIframeEmbedOptional} from '../../../src/iframe-helper'; import {getParentWindowFrameElement} from '../../../src/service'; -import {installWebAnimationsIfNecessary} from './install-polyfill'; +import {installWebAnimationsIfNecessary} from './web-animations-polyfill'; import {isFiniteNumber} from '../../../src/types'; import {setInitialDisplay, setStyles, toggle} from '../../../src/style'; @@ -479,14 +479,15 @@ export class AmpAnimation extends AMP.BaseElement { null); // Ensure polyfill is installed. - const polyfillPromise = installWebAnimationsIfNecessary(this.win); + installWebAnimationsIfNecessary(this.win); + const ampdoc = this.getAmpDoc(); const readyPromise = this.embed_ ? this.embed_.whenReady() : ampdoc.whenReady(); const hostWin = this.embed_ ? this.embed_.win : this.win; const baseUrl = this.embed_ ? this.embed_.getUrl() : ampdoc.getUrl(); - return Promise.all([polyfillPromise, readyPromise]).then(() => { + return readyPromise.then(() => { const builder = new Builder( hostWin, this.getRootNode_(), diff --git a/extensions/amp-animation/0.1/install-polyfill.js b/extensions/amp-animation/0.1/install-polyfill.js deleted file mode 100644 index 7001c119ff02..000000000000 --- a/extensions/amp-animation/0.1/install-polyfill.js +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2016 The AMP HTML Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import {Deferred} from '../../../src/utils/promise'; -import {Services} from '../../../src/services'; - -/** @type {!WeakMap} */ -const polyfillPromiseMap = new WeakMap(); - -/** - * @param {!Window} win - * @return {Promise} - */ -export function installWebAnimationsIfNecessary(win) { - if (polyfillPromiseMap.has(win)) { - return polyfillPromiseMap.get(win).promise; - } - - const polyfillPromise = new Deferred(); - polyfillPromiseMap.set(win, polyfillPromise); - - if (Services.platformFor(win).isSafari()) { - /* - Force Web Animations polyfill on Safari. - Native Web Animations on WebKit do not respect easing for individual - keyframes and break overall timing. See https://go.amp.dev/issue/27762 and - https://bugs.webkit.org/show_bug.cgi?id=210526 - */ - // Using string access syntax to bypass typecheck. - win.Element.prototype['animate'] = null; - } - - if (!!win.Element.prototype['animate']) { - // Native Support exists, there is no reason to load the polyfill. - polyfillPromise.resolve(); - return polyfillPromise.promise; - } - - Services.extensionsFor(win) - .preloadExtension('amp-animation-polyfill') - .then(() => polyfillPromise.resolve()); - - return polyfillPromise.promise; -} diff --git a/extensions/amp-animation/0.1/web-animation-service.js b/extensions/amp-animation/0.1/web-animation-service.js index 4fea70a49d1d..a83f095f77a5 100644 --- a/extensions/amp-animation/0.1/web-animation-service.js +++ b/extensions/amp-animation/0.1/web-animation-service.js @@ -16,7 +16,7 @@ import {Builder} from './web-animations'; import {Services} from '../../../src/services'; import {WebAnimationBuilderOptionsDef} from './web-animation-types'; -import {installWebAnimationsIfNecessary} from './install-polyfill'; +import {installWebAnimationsIfNecessary} from './web-animations-polyfill'; export class WebAnimationService { /** @@ -35,19 +35,18 @@ export class WebAnimationService { /** * @param {!WebAnimationBuilderOptionsDef} options - * @return {!Promise} + * @return {!Builder} */ createBuilder(options) { - return installWebAnimationsIfNecessary(this.ampdoc_.win).then( - () => - new Builder( - this.ampdoc_.win, - this.ampdoc_.getRootNode(), - this.ampdoc_.getUrl(), - this.vsync_, - this.owners_, - options - ) + installWebAnimationsIfNecessary(this.ampdoc_.win); + + return new Builder( + this.ampdoc_.win, + this.ampdoc_.getRootNode(), + this.ampdoc_.getUrl(), + this.vsync_, + this.owners_, + options ); } } diff --git a/extensions/amp-animation/0.1/web-animations-polyfill.js b/extensions/amp-animation/0.1/web-animations-polyfill.js new file mode 100644 index 000000000000..021bc0929a26 --- /dev/null +++ b/extensions/amp-animation/0.1/web-animations-polyfill.js @@ -0,0 +1,44 @@ +/** + * Copyright 2016 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {Services} from '../../../src/services'; +import {installWebAnimations} from 'web-animations-js/web-animations.install'; + +const POLYFILLED = '__AMP_WA'; + +/** + * Force Web Animations polyfill on Safari. + * Native Web Animations on WebKit do not respect easing for individual + * keyframes and break overall timing. See https://go.amp.dev/issue/27762 and + * https://bugs.webkit.org/show_bug.cgi?id=210526 + * @param {!Window} win + */ +function forceOnSafari(win) { + if (Services.platformFor(win).isSafari()) { + // Using string access syntax to bypass typecheck. + win.Element.prototype['animate'] = null; + } +} + +/** + * @param {!Window} win + */ +export function installWebAnimationsIfNecessary(win) { + if (!win[POLYFILLED]) { + forceOnSafari(win); + win[POLYFILLED] = true; + installWebAnimations(win); + } +}