Only polyfill ResizeObserver for UMD builds (#7208)

This commit is contained in:
Ben McCann 2020-03-22 10:40:26 -07:00 committed by GitHub
parent e46420e595
commit 7051410d4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 2 deletions

9
package-lock.json generated
View File

@ -15505,6 +15505,15 @@
"rollup-pluginutils": "^2.3.3"
}
},
"rollup-plugin-polyfill": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-polyfill/-/rollup-plugin-polyfill-3.0.0.tgz",
"integrity": "sha512-LfJ1OR/wJrJdNDVNrdhVm7CgENfaNoQlFYMaQ0vlQH3zO+BMVrBMWDX9k6HVcr9gHsKbthrkiBzWRfFU9fr0hQ==",
"dev": true,
"requires": {
"magic-string": "^0.25.3"
}
},
"rollup-plugin-terser": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-5.2.0.tgz",

View File

@ -75,6 +75,7 @@
"rollup": "^1.31.1",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-cleanup": "^3.1.1",
"rollup-plugin-polyfill": "^3.0.0",
"rollup-plugin-terser": "^5.2.0",
"rollup-plugin-web-worker-loader": "^0.8.1",
"typedoc": "^0.16.10",

View File

@ -3,6 +3,7 @@
const babel = require('rollup-plugin-babel');
const cleanup = require('rollup-plugin-cleanup');
const polyfill = require('rollup-plugin-polyfill')
const json = require('@rollup/plugin-json');
const resolve = require('@rollup/plugin-node-resolve');
const terser = require('rollup-plugin-terser').terser;
@ -24,6 +25,7 @@ module.exports = [
{
input,
plugins: [
polyfill(['resize-observer-polyfill', './platform/platform.dom.js']),
json(),
resolve(),
babel(),
@ -42,6 +44,7 @@ module.exports = [
{
input,
plugins: [
polyfill(['resize-observer-polyfill', './platform/platform.dom.js']),
json(),
resolve(),
babel(),

View File

@ -5,7 +5,6 @@
import helpers from '../helpers/index';
import BasePlatform from './platform.base';
import {_getParentNode} from '../helpers/helpers.dom';
import ResizeObserver from 'resize-observer-polyfill';
/**
* @typedef { import("../core/core.controller").default } Chart
@ -178,7 +177,6 @@ function throttled(fn, thisArg) {
* Calling `fn` is limited to once per animation frame
* @param {Element} element - The element to monitor
* @param {function} fn - Callback function to call when resized
* @return {ResizeObserver}
*/
function watchForResize(element, fn) {
const resize = throttled((width, height) => {
@ -196,6 +194,7 @@ function watchForResize(element, fn) {
}
}, window);
// @ts-ignore until https://github.com/Microsoft/TypeScript/issues/28502 implemented
const observer = new ResizeObserver(entries => {
const entry = entries[0];
resize(entry.contentRect.width, entry.contentRect.height);