Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polyfill replaceChildren #81

Merged
merged 3 commits into from
Nov 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ const transform = require('gl-vec3/transformMat4');

const SVG_NS = 'http://www.w3.org/2000/svg';

// Taken from https://github.com/yuzhe-han/ParentNode-replaceChildren
// This is to support browsers that do not yet support `replaceChildren`
const replaceChildrenPonyfill = function (...addNodes) {
while (this.lastChild) {
this.removeChild(this.lastChild);
}

if (addNodes.length > 0) {
this.append(...addNodes);
}
};

module.exports = {
calculateSizingOptions,
createLogoViewer,
Expand Down Expand Up @@ -497,7 +509,15 @@ function createFaceUpdater(container, polygons, transformed) {
const newPolygons = toDraw.map((poly) => poly.svg);
const defs = container.getElementsByTagName('defs');
const maskChildren = container.getElementsByTagName('mask');
container.replaceChildren(...defs, ...maskChildren, ...newPolygons);
if (container.replaceChildren) {
container.replaceChildren(...defs, ...maskChildren, ...newPolygons);
} else {
replaceChildrenPonyfill.bind(container)(
...defs,
...maskChildren,
...newPolygons,
);
}
};
}

Expand Down