From c20fd05e64bfe237ef3f671ffc156be6c906ed19 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Tue, 23 Nov 2021 14:17:39 -0330 Subject: [PATCH 1/3] Polyfill replaceChildren --- util.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/util.js b/util.js index 185a7834..5866c8b5 100644 --- a/util.js +++ b/util.js @@ -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 replaceChildrenPolyfill = function (...addNodes) { + while (this.lastChild) { + this.removeChild(this.lastChild); + } + + if (addNodes !== undefined) { + this.append(...addNodes); + } +}; + module.exports = { calculateSizingOptions, createLogoViewer, @@ -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 { + replaceChildrenPolyfill.bind(container)( + ...defs, + ...maskChildren, + ...newPolygons, + ); + } }; } From 9ca2e3f04f7531e0636ffd1e461fe61423fe3dc5 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Tue, 23 Nov 2021 17:46:52 -0330 Subject: [PATCH 2/3] Update util.js Co-authored-by: Mark Stacey --- util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util.js b/util.js index 5866c8b5..e8b35f88 100644 --- a/util.js +++ b/util.js @@ -14,7 +14,7 @@ const replaceChildrenPolyfill = function (...addNodes) { this.removeChild(this.lastChild); } - if (addNodes !== undefined) { + if (addNodes.length > 0) { this.append(...addNodes); } }; From 1b0a00b877a667ef84d13259ad64756f9afcf891 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Tue, 23 Nov 2021 17:48:43 -0330 Subject: [PATCH 3/3] Rename replaceChildrenPolyfill to replaceChildrenPonyfill --- util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util.js b/util.js index e8b35f88..dbbf9adc 100644 --- a/util.js +++ b/util.js @@ -9,7 +9,7 @@ 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 replaceChildrenPolyfill = function (...addNodes) { +const replaceChildrenPonyfill = function (...addNodes) { while (this.lastChild) { this.removeChild(this.lastChild); } @@ -512,7 +512,7 @@ function createFaceUpdater(container, polygons, transformed) { if (container.replaceChildren) { container.replaceChildren(...defs, ...maskChildren, ...newPolygons); } else { - replaceChildrenPolyfill.bind(container)( + replaceChildrenPonyfill.bind(container)( ...defs, ...maskChildren, ...newPolygons,