@loaders.gl/polyfills 3.3.0-alpha.7 → 3.3.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.min.js CHANGED
@@ -177,6 +177,15 @@
177
177
  serializeToString(this[i], buf, isHTML, nodeFilter);
178
178
  }
179
179
  return buf.join("");
180
+ },
181
+ find: function(predicate) {
182
+ return Array.prototype.find.call(this, predicate);
183
+ },
184
+ filter: function(predicate) {
185
+ return Array.prototype.filter.call(this, predicate);
186
+ },
187
+ indexOf: function(item) {
188
+ return Array.prototype.indexOf.call(this, item);
180
189
  }
181
190
  };
182
191
  function LiveNodeList(node, refresh) {
@@ -239,7 +248,7 @@
239
248
  }
240
249
  }
241
250
  } else {
242
- throw DOMException(NOT_FOUND_ERR, new Error(el.tagName + "@" + attr));
251
+ throw new DOMException(NOT_FOUND_ERR, new Error(el.tagName + "@" + attr));
243
252
  }
244
253
  }
245
254
  NamedNodeMap.prototype = {
@@ -478,41 +487,103 @@
478
487
  _onUpdateChild(parentNode.ownerDocument, parentNode);
479
488
  return child;
480
489
  }
481
- function _insertBefore(parentNode, newChild, nextChild) {
482
- var cp = newChild.parentNode;
490
+ function hasValidParentNodeType(node) {
491
+ return node && (node.nodeType === Node.DOCUMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE || node.nodeType === Node.ELEMENT_NODE);
492
+ }
493
+ function hasInsertableNodeType(node) {
494
+ return node && (isElementNode(node) || isTextNode(node) || isDocTypeNode(node) || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE || node.nodeType === Node.COMMENT_NODE || node.nodeType === Node.PROCESSING_INSTRUCTION_NODE);
495
+ }
496
+ function isDocTypeNode(node) {
497
+ return node && node.nodeType === Node.DOCUMENT_TYPE_NODE;
498
+ }
499
+ function isElementNode(node) {
500
+ return node && node.nodeType === Node.ELEMENT_NODE;
501
+ }
502
+ function isTextNode(node) {
503
+ return node && node.nodeType === Node.TEXT_NODE;
504
+ }
505
+ function isElementInsertionPossible(doc, child) {
506
+ var parentChildNodes = doc.childNodes || [];
507
+ if (parentChildNodes.find(isElementNode) || isDocTypeNode(child)) {
508
+ return false;
509
+ }
510
+ var docTypeNode = parentChildNodes.find(isDocTypeNode);
511
+ return !(child && docTypeNode && parentChildNodes.indexOf(docTypeNode) > parentChildNodes.indexOf(child));
512
+ }
513
+ function _insertBefore(parent, node, child) {
514
+ if (!hasValidParentNodeType(parent)) {
515
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Unexpected parent node type " + parent.nodeType);
516
+ }
517
+ if (child && child.parentNode !== parent) {
518
+ throw new DOMException(NOT_FOUND_ERR, "child not in parent");
519
+ }
520
+ if (!hasInsertableNodeType(node) || isDocTypeNode(node) && parent.nodeType !== Node.DOCUMENT_NODE) {
521
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Unexpected node type " + node.nodeType + " for parent node type " + parent.nodeType);
522
+ }
523
+ var parentChildNodes = parent.childNodes || [];
524
+ var nodeChildNodes = node.childNodes || [];
525
+ if (parent.nodeType === Node.DOCUMENT_NODE) {
526
+ if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
527
+ let nodeChildElements = nodeChildNodes.filter(isElementNode);
528
+ if (nodeChildElements.length > 1 || nodeChildNodes.find(isTextNode)) {
529
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "More than one element or text in fragment");
530
+ }
531
+ if (nodeChildElements.length === 1 && !isElementInsertionPossible(parent, child)) {
532
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Element in fragment can not be inserted before doctype");
533
+ }
534
+ }
535
+ if (isElementNode(node)) {
536
+ if (parentChildNodes.find(isElementNode) || !isElementInsertionPossible(parent, child)) {
537
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Only one element can be added and only after doctype");
538
+ }
539
+ }
540
+ if (isDocTypeNode(node)) {
541
+ if (parentChildNodes.find(isDocTypeNode)) {
542
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Only one doctype is allowed");
543
+ }
544
+ let parentElementChild = parentChildNodes.find(isElementNode);
545
+ if (child && parentChildNodes.indexOf(parentElementChild) < parentChildNodes.indexOf(child)) {
546
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Doctype can only be inserted before an element");
547
+ }
548
+ if (!child && parentElementChild) {
549
+ throw new DOMException(HIERARCHY_REQUEST_ERR, "Doctype can not be appended since element is present");
550
+ }
551
+ }
552
+ }
553
+ var cp = node.parentNode;
483
554
  if (cp) {
484
- cp.removeChild(newChild);
555
+ cp.removeChild(node);
485
556
  }
486
- if (newChild.nodeType === DOCUMENT_FRAGMENT_NODE) {
487
- var newFirst = newChild.firstChild;
557
+ if (node.nodeType === DOCUMENT_FRAGMENT_NODE) {
558
+ var newFirst = node.firstChild;
488
559
  if (newFirst == null) {
489
- return newChild;
560
+ return node;
490
561
  }
491
- var newLast = newChild.lastChild;
562
+ var newLast = node.lastChild;
492
563
  } else {
493
- newFirst = newLast = newChild;
564
+ newFirst = newLast = node;
494
565
  }
495
- var pre = nextChild ? nextChild.previousSibling : parentNode.lastChild;
566
+ var pre = child ? child.previousSibling : parent.lastChild;
496
567
  newFirst.previousSibling = pre;
497
- newLast.nextSibling = nextChild;
568
+ newLast.nextSibling = child;
498
569
  if (pre) {
499
570
  pre.nextSibling = newFirst;
500
571
  } else {
501
- parentNode.firstChild = newFirst;
572
+ parent.firstChild = newFirst;
502
573
  }
503
- if (nextChild == null) {
504
- parentNode.lastChild = newLast;
574
+ if (child == null) {
575
+ parent.lastChild = newLast;
505
576
  } else {
506
- nextChild.previousSibling = newLast;
577
+ child.previousSibling = newLast;
507
578
  }
508
579
  do {
509
- newFirst.parentNode = parentNode;
580
+ newFirst.parentNode = parent;
510
581
  } while (newFirst !== newLast && (newFirst = newFirst.nextSibling));
511
- _onUpdateChild(parentNode.ownerDocument || parentNode, parentNode);
512
- if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) {
513
- newChild.firstChild = newChild.lastChild = null;
582
+ _onUpdateChild(parent.ownerDocument || parent, parent);
583
+ if (node.nodeType == DOCUMENT_FRAGMENT_NODE) {
584
+ node.firstChild = node.lastChild = null;
514
585
  }
515
- return newChild;
586
+ return node;
516
587
  }
517
588
  function _appendSingleChild(parentNode, newChild) {
518
589
  var cp = newChild.parentNode;
@@ -550,10 +621,12 @@
550
621
  }
551
622
  return newChild;
552
623
  }
553
- if (this.documentElement == null && newChild.nodeType == ELEMENT_NODE) {
624
+ _insertBefore(this, newChild, refChild);
625
+ newChild.ownerDocument = this;
626
+ if (this.documentElement === null && newChild.nodeType === ELEMENT_NODE) {
554
627
  this.documentElement = newChild;
555
628
  }
556
- return _insertBefore(this, newChild, refChild), newChild.ownerDocument = this, newChild;
629
+ return newChild;
557
630
  },
558
631
  removeChild: function(oldChild) {
559
632
  if (this.documentElement == oldChild) {
@@ -1,4 +1,4 @@
1
- declare type NDArray = {
1
+ type NDArray = {
2
2
  shape: number[];
3
3
  data: Uint8Array;
4
4
  width: number;
@@ -1 +1 @@
1
- {"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../../src/node/images/parse-image.node.ts"],"names":[],"mappings":"AAKA,aAAK,OAAO,GAAG;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,wBAAsB,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAwBjG"}
1
+ {"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../../src/node/images/parse-image.node.ts"],"names":[],"mappings":"AAKA,KAAK,OAAO,GAAG;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,wBAAsB,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAwBjG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/polyfills",
3
- "version": "3.3.0-alpha.7",
3
+ "version": "3.3.0-alpha.8",
4
4
  "description": "Polyfills for TextEncoder/TextDecoder",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -105,5 +105,5 @@
105
105
  "through": "^2.3.8",
106
106
  "web-streams-polyfill": "^3.0.0"
107
107
  },
108
- "gitHead": "29b08f3519c50984e84bf4234e607cab7c7d1c3e"
108
+ "gitHead": "69cfde0340328dd800c7c90151b56b406f47e9ae"
109
109
  }