@antv/x6
Version:
JavaScript diagramming library that uses SVG and HTML for rendering
36 lines • 1.29 kB
JavaScript
export function forEachPolyfill(arr) {
arr.forEach((item) => {
if (Object.hasOwn(item, 'append')) {
return;
}
Object.defineProperty(item, 'append', {
configurable: true,
enumerable: true,
writable: true,
value(...args) {
const docFrag = document.createDocumentFragment();
args.forEach((arg) => {
const isNode = arg instanceof Node;
docFrag.appendChild(isNode ? arg : document.createTextNode(String(arg)));
});
this.appendChild(docFrag);
},
});
});
}
// compatible with NodeList.prototype.forEach() before chrome 51
// https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach
if (typeof window === 'object' &&
window.NodeList &&
!NodeList.prototype.forEach) {
NodeList.prototype.forEach = Array.prototype.forEach;
}
// compatible with ParentNode.append() before chrome 54
// https://github.com/jserz/js_piece/blob/master/DOM/ParentNode/append()/append().md
if (typeof window !== 'undefined') {
;
((arr) => {
forEachPolyfill(arr);
})([Element.prototype, Document.prototype, DocumentFragment.prototype]);
}
//# sourceMappingURL=index.js.map