polyfill-library 4.2.0 → 4.3.0
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/CHANGELOG.md +4 -4
- package/package.json +10 -11
- package/polyfills/__dist/Array.prototype.@@iterator/meta.json +1 -1
- package/polyfills/__dist/ArrayBuffer.prototype.@@toStringTag/meta.json +1 -0
- package/polyfills/__dist/ArrayBuffer.prototype.@@toStringTag/min.js +1 -0
- package/polyfills/__dist/ArrayBuffer.prototype.@@toStringTag/raw.js +19 -0
- package/polyfills/__dist/HTMLTemplateElement/meta.json +1 -1
- package/polyfills/__dist/HTMLTemplateElement/min.js +1 -1
- package/polyfills/__dist/HTMLTemplateElement/raw.js +25 -598
- package/polyfills/__dist/Map/meta.json +1 -1
- package/polyfills/__dist/Map/min.js +1 -1
- package/polyfills/__dist/Map/raw.js +12 -0
- package/polyfills/__dist/Promise/meta.json +1 -1
- package/polyfills/__dist/Promise/min.js +1 -1
- package/polyfills/__dist/Promise/raw.js +10 -0
- package/polyfills/__dist/Set/meta.json +1 -1
- package/polyfills/__dist/Set/min.js +1 -1
- package/polyfills/__dist/Set/raw.js +12 -0
- package/polyfills/__dist/String.prototype.@@iterator/meta.json +1 -1
- package/polyfills/__dist/Symbol.toStringTag/meta.json +1 -1
- package/polyfills/__dist/TypedArray.prototype.@@iterator/meta.json +1 -0
- package/polyfills/__dist/TypedArray.prototype.@@iterator/min.js +1 -0
- package/polyfills/__dist/TypedArray.prototype.@@iterator/raw.js +22 -0
- package/polyfills/__dist/TypedArray.prototype.@@toStringTag/meta.json +1 -0
- package/polyfills/__dist/TypedArray.prototype.@@toStringTag/min.js +1 -0
- package/polyfills/__dist/TypedArray.prototype.@@toStringTag/raw.js +91 -0
- package/polyfills/__dist/TypedArray.prototype.entries/meta.json +1 -0
- package/polyfills/__dist/TypedArray.prototype.entries/min.js +1 -0
- package/polyfills/__dist/TypedArray.prototype.entries/raw.js +38 -0
- package/polyfills/__dist/TypedArray.prototype.keys/meta.json +1 -0
- package/polyfills/__dist/TypedArray.prototype.keys/min.js +1 -0
- package/polyfills/__dist/TypedArray.prototype.keys/raw.js +38 -0
- package/polyfills/__dist/TypedArray.prototype.toLocaleString/meta.json +1 -0
- package/polyfills/__dist/TypedArray.prototype.toLocaleString/min.js +1 -0
- package/polyfills/__dist/TypedArray.prototype.toLocaleString/raw.js +31 -0
- package/polyfills/__dist/TypedArray.prototype.toString/meta.json +1 -0
- package/polyfills/__dist/TypedArray.prototype.toString/min.js +1 -0
- package/polyfills/__dist/TypedArray.prototype.toString/raw.js +29 -0
- package/polyfills/__dist/TypedArray.prototype.values/meta.json +1 -0
- package/polyfills/__dist/TypedArray.prototype.values/min.js +1 -0
- package/polyfills/__dist/TypedArray.prototype.values/raw.js +43 -0
- package/polyfills/__dist/WeakMap/meta.json +1 -1
- package/polyfills/__dist/WeakSet/meta.json +1 -1
- package/polyfills/__dist/WeakSet/min.js +1 -1
- package/polyfills/__dist/WeakSet/raw.js +6 -0
- package/polyfills/__dist/_ArrayIterator/meta.json +1 -1
- package/polyfills/__dist/_ArrayIterator/min.js +1 -1
- package/polyfills/__dist/_ArrayIterator/raw.js +8 -1
- package/polyfills/__dist/_StringIterator/meta.json +1 -1
- package/polyfills/__dist/_StringIterator/min.js +1 -1
- package/polyfills/__dist/_StringIterator/raw.js +8 -1
- package/polyfills/__dist/aliases.json +1 -1
|
@@ -1,602 +1,29 @@
|
|
|
1
1
|
|
|
2
2
|
// HTMLTemplateElement
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
(function(){
|
|
4
|
+
/*
|
|
5
|
+
|
|
6
|
+
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
|
|
7
|
+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
8
|
+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
9
|
+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
10
|
+
Code distributed by Google as part of the polymer project is also
|
|
11
|
+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
12
|
+
*/
|
|
13
|
+
'use strict';(function(){function f(){}function p(a,b){if(!a.childNodes.length)return[];switch(a.nodeType){case Node.DOCUMENT_NODE:return J.call(a,b);case Node.DOCUMENT_FRAGMENT_NODE:return K.call(a,b);default:return L.call(a,b)}}var q="undefined"===typeof HTMLTemplateElement,A=!(document.createDocumentFragment().cloneNode()instanceof DocumentFragment),B=!1;/Trident/.test(navigator.userAgent)&&function(){function a(c,g){if(c instanceof DocumentFragment)for(var r;r=c.firstChild;)d.call(this,r,g);else d.call(this,
|
|
14
|
+
c,g);return c}B=!0;var b=Node.prototype.cloneNode;Node.prototype.cloneNode=function(c){c=b.call(this,c);this instanceof DocumentFragment&&(c.__proto__=DocumentFragment.prototype);return c};DocumentFragment.prototype.querySelectorAll=HTMLElement.prototype.querySelectorAll;DocumentFragment.prototype.querySelector=HTMLElement.prototype.querySelector;Object.defineProperties(DocumentFragment.prototype,{nodeType:{get:function(){return Node.DOCUMENT_FRAGMENT_NODE},configurable:!0},localName:{get:function(){},
|
|
15
|
+
configurable:!0},nodeName:{get:function(){return"#document-fragment"},configurable:!0}});var d=Node.prototype.insertBefore;Node.prototype.insertBefore=a;var e=Node.prototype.appendChild;Node.prototype.appendChild=function(c){c instanceof DocumentFragment?a.call(this,c,null):e.call(this,c);return c};var h=Node.prototype.removeChild,k=Node.prototype.replaceChild;Node.prototype.replaceChild=function(c,g){c instanceof DocumentFragment?(a.call(this,c,g),h.call(this,g)):k.call(this,c,g);return g};Document.prototype.createDocumentFragment=
|
|
16
|
+
function(){var c=this.createElement("df");c.__proto__=DocumentFragment.prototype;return c};var l=Document.prototype.importNode;Document.prototype.importNode=function(c,g){g=l.call(this,c,g||!1);c instanceof DocumentFragment&&(g.__proto__=DocumentFragment.prototype);return g}}();var v=Node.prototype.cloneNode,C=Document.prototype.createElement,M=Document.prototype.importNode,N=Node.prototype.removeChild,t=Node.prototype.appendChild,w=Node.prototype.replaceChild,O=DOMParser.prototype.parseFromString,
|
|
17
|
+
P=Object.getOwnPropertyDescriptor(window.HTMLElement.prototype,"innerHTML")||{get:function(){return this.innerHTML},set:function(a){this.innerHTML=a}},Q=Object.getOwnPropertyDescriptor(window.Node.prototype,"childNodes")||{get:function(){return this.childNodes}},L=Element.prototype.querySelectorAll,J=Document.prototype.querySelectorAll,K=DocumentFragment.prototype.querySelectorAll,R=function(){if(!q){var a=document.createElement("template"),b=document.createElement("template");b.content.appendChild(document.createElement("div"));
|
|
18
|
+
a.content.appendChild(b);a=a.cloneNode(!0);return 0===a.content.childNodes.length||0===a.content.firstChild.content.childNodes.length||A}}();if(q){var m=document.implementation.createHTMLDocument("template"),D=!0,n=document.createElement("style");n.textContent="template{display:none;}";var E=document.head;E.insertBefore(n,E.firstElementChild);f.prototype=Object.create(HTMLElement.prototype);var S=!document.createElement("div").hasOwnProperty("innerHTML");f.g=function(a){if(!a.content&&a.namespaceURI===
|
|
19
|
+
document.documentElement.namespaceURI){a.content=m.createDocumentFragment();for(var b;b=a.firstChild;)t.call(a.content,b);if(S)a.__proto__=f.prototype;else if(a.cloneNode=function(d){return f.i(this,d)},D)try{F(a),G(a)}catch(d){D=!1}f.h(a.content)}};var T={option:["select"],thead:["table"],col:["colgroup","table"],tr:["tbody","table"],th:["tr","tbody","table"],td:["tr","tbody","table"]},F=function(a){Object.defineProperty(a,"innerHTML",{get:function(){return x(this)},set:function(b){var d=T[(/<([a-z][^/\0>\x20\t\r\n\f]+)/i.exec(b)||
|
|
20
|
+
["",""])[1].toLowerCase()];if(d)for(var e=0;e<d.length;e++)b="<"+d[e]+">"+b+"</"+d[e]+">";m.body.innerHTML=b;for(f.h(m);this.content.firstChild;)N.call(this.content,this.content.firstChild);b=m.body;if(d)for(e=0;e<d.length;e++)b=b.lastChild;for(;b.firstChild;)t.call(this.content,b.firstChild)},configurable:!0})},G=function(a){Object.defineProperty(a,"outerHTML",{get:function(){return"<template>"+this.innerHTML+"</template>"},set:function(b){if(this.parentNode){m.body.innerHTML=b;for(b=this.ownerDocument.createDocumentFragment();m.body.firstChild;)t.call(b,
|
|
21
|
+
m.body.firstChild);w.call(this.parentNode,b,this)}else throw Error("Failed to set the 'outerHTML' property on 'Element': This element has no parent node.");},configurable:!0})};F(f.prototype);G(f.prototype);f.h=function(a){a=p(a,"template");for(var b=0,d=a.length,e;b<d&&(e=a[b]);b++)f.g(e)};document.addEventListener("DOMContentLoaded",function(){f.h(document)});Document.prototype.createElement=function(){var a=C.apply(this,arguments);"template"===a.localName&&f.g(a);return a};DOMParser.prototype.parseFromString=
|
|
22
|
+
function(){var a=O.apply(this,arguments);f.h(a);return a};Object.defineProperty(HTMLElement.prototype,"innerHTML",{get:function(){return x(this)},set:function(a){P.set.call(this,a);f.h(this)},configurable:!0,enumerable:!0});var U=/[&\u00A0"]/g,V=/[&\u00A0<>]/g,H=function(a){switch(a){case "&":return"&";case "<":return"<";case ">":return">";case '"':return""";case "\u00a0":return" "}};n=function(a){for(var b={},d=0;d<a.length;d++)b[a[d]]=!0;return b};var W=n("area base br col command embed hr img input keygen link meta param source track wbr".split(" ")),
|
|
23
|
+
X=n("style script xmp iframe noembed noframes plaintext noscript".split(" ")),x=function(a,b){"template"===a.localName&&(a=a.content);for(var d="",e=b?b(a):Q.get.call(a),h=0,k=e.length,l;h<k&&(l=e[h]);h++){a:{var c=l;var g=a;var r=b;switch(c.nodeType){case Node.ELEMENT_NODE:for(var y=c.localName,u="<"+y,Y=c.attributes,I=0;g=Y[I];I++)u+=" "+g.name+'="'+g.value.replace(U,H)+'"';u+=">";c=W[y]?u:u+x(c,r)+"</"+y+">";break a;case Node.TEXT_NODE:c=c.data;c=g&&X[g.localName]?c:c.replace(V,H);break a;case Node.COMMENT_NODE:c=
|
|
24
|
+
"\x3c!--"+c.data+"--\x3e";break a;default:throw window.console.error(c),Error("not implemented");}}d+=c}return d}}if(q||R){f.i=function(a,b){var d=v.call(a,!1);this.g&&this.g(d);b&&(t.call(d.content,v.call(a.content,!0)),z(d.content,a.content));return d};var z=function(a,b){if(b.querySelectorAll&&(b=p(b,"template"),0!==b.length)){a=p(a,"template");for(var d=0,e=a.length,h,k;d<e;d++)k=b[d],h=a[d],f&&f.g&&f.g(k),w.call(h.parentNode,Z.call(k,!0),h)}},Z=Node.prototype.cloneNode=function(a){if(!B&&A&&
|
|
25
|
+
this instanceof DocumentFragment)if(a)var b=aa.call(this.ownerDocument,this,!0);else return this.ownerDocument.createDocumentFragment();else this.nodeType===Node.ELEMENT_NODE&&"template"===this.localName&&this.namespaceURI==document.documentElement.namespaceURI?b=f.i(this,a):b=v.call(this,a);a&&z(b,this);return b},aa=Document.prototype.importNode=function(a,b){b=b||!1;if("template"===a.localName)return f.i(a,b);var d=M.call(this,a,b);if(b){z(d,a);a=p(d,'script:not([type]),script[type="application/javascript"],script[type="text/javascript"]');
|
|
26
|
+
for(var e,h=0;h<a.length;h++){e=a[h];b=C.call(document,"script");b.textContent=e.textContent;for(var k=e.attributes,l=0,c;l<k.length;l++)c=k[l],b.setAttribute(c.name,c.value);w.call(e.parentNode,b,e)}}return d}}q&&(window.HTMLTemplateElement=f)})();
|
|
27
|
+
}).call(self);
|
|
12
28
|
|
|
13
|
-
// minimal template polyfill
|
|
14
|
-
(function() {
|
|
15
|
-
'use strict';
|
|
16
29
|
|
|
17
|
-
var needsTemplate = (typeof HTMLTemplateElement === 'undefined');
|
|
18
|
-
var brokenDocFragment = !(document.createDocumentFragment().cloneNode() instanceof DocumentFragment);
|
|
19
|
-
var needsDocFrag = false;
|
|
20
|
-
|
|
21
|
-
// NOTE: Replace DocumentFragment to work around IE11 bug that
|
|
22
|
-
// causes children of a document fragment modified while
|
|
23
|
-
// there is a mutation observer to not have a parentNode, or
|
|
24
|
-
// have a broken parentNode (!?!)
|
|
25
|
-
if (/Trident/.test(navigator.userAgent)) {
|
|
26
|
-
(function() {
|
|
27
|
-
|
|
28
|
-
needsDocFrag = true;
|
|
29
|
-
|
|
30
|
-
var origCloneNode = Node.prototype.cloneNode;
|
|
31
|
-
Node.prototype.cloneNode = function cloneNode(deep) {
|
|
32
|
-
var newDom = origCloneNode.call(this, deep);
|
|
33
|
-
if (this instanceof DocumentFragment) {
|
|
34
|
-
newDom.__proto__ = DocumentFragment.prototype;
|
|
35
|
-
}
|
|
36
|
-
return newDom;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// IE's DocumentFragment querySelector code doesn't work when
|
|
40
|
-
// called on an element instance
|
|
41
|
-
DocumentFragment.prototype.querySelectorAll = HTMLElement.prototype.querySelectorAll;
|
|
42
|
-
DocumentFragment.prototype.querySelector = HTMLElement.prototype.querySelector;
|
|
43
|
-
|
|
44
|
-
Object.defineProperties(DocumentFragment.prototype, {
|
|
45
|
-
'nodeType': {
|
|
46
|
-
get: function () {
|
|
47
|
-
return Node.DOCUMENT_FRAGMENT_NODE;
|
|
48
|
-
},
|
|
49
|
-
configurable: true
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
'localName': {
|
|
53
|
-
get: function () {
|
|
54
|
-
return undefined;
|
|
55
|
-
},
|
|
56
|
-
configurable: true
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
'nodeName': {
|
|
60
|
-
get: function () {
|
|
61
|
-
return '#document-fragment';
|
|
62
|
-
},
|
|
63
|
-
configurable: true
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
var origInsertBefore = Node.prototype.insertBefore;
|
|
68
|
-
function insertBefore(newNode, refNode) {
|
|
69
|
-
if (newNode instanceof DocumentFragment) {
|
|
70
|
-
var child;
|
|
71
|
-
while ((child = newNode.firstChild)) {
|
|
72
|
-
origInsertBefore.call(this, child, refNode);
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
origInsertBefore.call(this, newNode, refNode);
|
|
76
|
-
}
|
|
77
|
-
return newNode;
|
|
78
|
-
}
|
|
79
|
-
Node.prototype.insertBefore = insertBefore;
|
|
80
|
-
|
|
81
|
-
var origAppendChild = Node.prototype.appendChild;
|
|
82
|
-
Node.prototype.appendChild = function appendChild(child) {
|
|
83
|
-
if (child instanceof DocumentFragment) {
|
|
84
|
-
insertBefore.call(this, child, null);
|
|
85
|
-
} else {
|
|
86
|
-
origAppendChild.call(this, child);
|
|
87
|
-
}
|
|
88
|
-
return child;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
var origRemoveChild = Node.prototype.removeChild;
|
|
92
|
-
var origReplaceChild = Node.prototype.replaceChild;
|
|
93
|
-
Node.prototype.replaceChild = function replaceChild(newChild, oldChild) {
|
|
94
|
-
if (newChild instanceof DocumentFragment) {
|
|
95
|
-
insertBefore.call(this, newChild, oldChild);
|
|
96
|
-
origRemoveChild.call(this, oldChild);
|
|
97
|
-
} else {
|
|
98
|
-
origReplaceChild.call(this, newChild, oldChild);
|
|
99
|
-
}
|
|
100
|
-
return oldChild;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
Document.prototype.createDocumentFragment = function createDocumentFragment() {
|
|
104
|
-
var frag = this.createElement('df');
|
|
105
|
-
frag.__proto__ = DocumentFragment.prototype;
|
|
106
|
-
return frag;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
var origImportNode = Document.prototype.importNode;
|
|
110
|
-
Document.prototype.importNode = function importNode(impNode, deep) {
|
|
111
|
-
deep = deep || false;
|
|
112
|
-
var newNode = origImportNode.call(this, impNode, deep);
|
|
113
|
-
if (impNode instanceof DocumentFragment) {
|
|
114
|
-
newNode.__proto__ = DocumentFragment.prototype;
|
|
115
|
-
}
|
|
116
|
-
return newNode;
|
|
117
|
-
};
|
|
118
|
-
})();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// NOTE: we rely on this cloneNode not causing element upgrade.
|
|
122
|
-
// This means this polyfill must load before the CE polyfill and
|
|
123
|
-
// this would need to be re-worked if a browser supports native CE
|
|
124
|
-
// but not <template>.
|
|
125
|
-
var capturedCloneNode = Node.prototype.cloneNode;
|
|
126
|
-
var capturedCreateElement = Document.prototype.createElement;
|
|
127
|
-
var capturedImportNode = Document.prototype.importNode;
|
|
128
|
-
var capturedRemoveChild = Node.prototype.removeChild;
|
|
129
|
-
var capturedAppendChild = Node.prototype.appendChild;
|
|
130
|
-
var capturedReplaceChild = Node.prototype.replaceChild;
|
|
131
|
-
var capturedParseFromString = DOMParser.prototype.parseFromString;
|
|
132
|
-
var capturedHTMLElementInnerHTML = Object.getOwnPropertyDescriptor(window.HTMLElement.prototype, 'innerHTML') || {
|
|
133
|
-
/**
|
|
134
|
-
* @this {!HTMLElement}
|
|
135
|
-
* @return {string}
|
|
136
|
-
*/
|
|
137
|
-
get: function() {
|
|
138
|
-
return this.innerHTML;
|
|
139
|
-
},
|
|
140
|
-
/**
|
|
141
|
-
* @this {!HTMLElement}
|
|
142
|
-
* @param {string}
|
|
143
|
-
*/
|
|
144
|
-
set: function(text) {
|
|
145
|
-
this.innerHTML = text;
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
var capturedChildNodes = Object.getOwnPropertyDescriptor(window.Node.prototype, 'childNodes') || {
|
|
149
|
-
/**
|
|
150
|
-
* @this {!Node}
|
|
151
|
-
* @return {!NodeList}
|
|
152
|
-
*/
|
|
153
|
-
get: function() {
|
|
154
|
-
return this.childNodes;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
var elementQuerySelectorAll = Element.prototype.querySelectorAll;
|
|
159
|
-
var docQuerySelectorAll = Document.prototype.querySelectorAll;
|
|
160
|
-
var fragQuerySelectorAll = DocumentFragment.prototype.querySelectorAll;
|
|
161
|
-
|
|
162
|
-
var scriptSelector = 'script:not([type]),script[type="application/javascript"],script[type="text/javascript"]';
|
|
163
|
-
|
|
164
|
-
function QSA(node, selector) {
|
|
165
|
-
// IE 11 throws a SyntaxError with `scriptSelector` if the node has no children due to the `:not([type])` syntax
|
|
166
|
-
if (!node.childNodes.length) {
|
|
167
|
-
return [];
|
|
168
|
-
}
|
|
169
|
-
switch (node.nodeType) {
|
|
170
|
-
case Node.DOCUMENT_NODE:
|
|
171
|
-
return docQuerySelectorAll.call(node, selector);
|
|
172
|
-
case Node.DOCUMENT_FRAGMENT_NODE:
|
|
173
|
-
return fragQuerySelectorAll.call(node, selector);
|
|
174
|
-
default:
|
|
175
|
-
return elementQuerySelectorAll.call(node, selector);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// returns true if nested templates cannot be cloned (they cannot be on
|
|
180
|
-
// some impl's like Safari 8 and Edge)
|
|
181
|
-
// OR if cloning a document fragment does not result in a document fragment
|
|
182
|
-
var needsCloning = (function() {
|
|
183
|
-
if (!needsTemplate) {
|
|
184
|
-
var t = document.createElement('template');
|
|
185
|
-
var t2 = document.createElement('template');
|
|
186
|
-
t2.content.appendChild(document.createElement('div'));
|
|
187
|
-
t.content.appendChild(t2);
|
|
188
|
-
var clone = t.cloneNode(true);
|
|
189
|
-
return (clone.content.childNodes.length === 0 || clone.content.firstChild.content.childNodes.length === 0
|
|
190
|
-
|| brokenDocFragment);
|
|
191
|
-
}
|
|
192
|
-
})();
|
|
193
|
-
|
|
194
|
-
var TEMPLATE_TAG = 'template';
|
|
195
|
-
var PolyfilledHTMLTemplateElement = function() {};
|
|
196
|
-
|
|
197
|
-
if (needsTemplate) {
|
|
198
|
-
|
|
199
|
-
var contentDoc = document.implementation.createHTMLDocument('template');
|
|
200
|
-
var canDecorate = true;
|
|
201
|
-
|
|
202
|
-
var templateStyle = document.createElement('style');
|
|
203
|
-
templateStyle.textContent = TEMPLATE_TAG + '{display:none;}';
|
|
204
|
-
|
|
205
|
-
var head = document.head;
|
|
206
|
-
head.insertBefore(templateStyle, head.firstElementChild);
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
Provides a minimal shim for the <template> element.
|
|
210
|
-
*/
|
|
211
|
-
PolyfilledHTMLTemplateElement.prototype = Object.create(HTMLElement.prototype);
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
// if elements do not have `innerHTML` on instances, then
|
|
215
|
-
// templates can be patched by swizzling their prototypes.
|
|
216
|
-
var canProtoPatch =
|
|
217
|
-
!(document.createElement('div').hasOwnProperty('innerHTML'));
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
The `decorate` method moves element children to the template's `content`.
|
|
221
|
-
NOTE: there is no support for dynamically adding elements to templates.
|
|
222
|
-
*/
|
|
223
|
-
PolyfilledHTMLTemplateElement.decorate = function(template) {
|
|
224
|
-
// if the template is decorated or not in HTML namespace, return fast
|
|
225
|
-
if (template.content ||
|
|
226
|
-
template.namespaceURI !== document.documentElement.namespaceURI) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
template.content = contentDoc.createDocumentFragment();
|
|
230
|
-
var child;
|
|
231
|
-
while ((child = template.firstChild)) {
|
|
232
|
-
capturedAppendChild.call(template.content, child);
|
|
233
|
-
}
|
|
234
|
-
// NOTE: prefer prototype patching for performance and
|
|
235
|
-
// because on some browsers (IE11), re-defining `innerHTML`
|
|
236
|
-
// can result in intermittent errors.
|
|
237
|
-
if (canProtoPatch) {
|
|
238
|
-
template.__proto__ = PolyfilledHTMLTemplateElement.prototype;
|
|
239
|
-
} else {
|
|
240
|
-
template.cloneNode = function(deep) {
|
|
241
|
-
return PolyfilledHTMLTemplateElement._cloneNode(this, deep);
|
|
242
|
-
};
|
|
243
|
-
// add innerHTML to template, if possible
|
|
244
|
-
// Note: this throws on Safari 7
|
|
245
|
-
if (canDecorate) {
|
|
246
|
-
try {
|
|
247
|
-
defineInnerHTML(template);
|
|
248
|
-
defineOuterHTML(template);
|
|
249
|
-
} catch (err) {
|
|
250
|
-
canDecorate = false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
// bootstrap recursively
|
|
255
|
-
PolyfilledHTMLTemplateElement.bootstrap(template.content);
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
// Taken from https://github.com/jquery/jquery/blob/73d7e6259c63ac45f42c6593da8c2796c6ce9281/src/manipulation/wrapMap.js
|
|
259
|
-
var topLevelWrappingMap = {
|
|
260
|
-
'option': ['select'],
|
|
261
|
-
'thead': ['table'],
|
|
262
|
-
'col': ['colgroup', 'table'],
|
|
263
|
-
'tr': ['tbody', 'table'],
|
|
264
|
-
'th': ['tr', 'tbody', 'table'],
|
|
265
|
-
'td': ['tr', 'tbody', 'table']
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
var getTagName = function(text) {
|
|
269
|
-
// Taken from https://github.com/jquery/jquery/blob/73d7e6259c63ac45f42c6593da8c2796c6ce9281/src/manipulation/var/rtagName.js
|
|
270
|
-
return ( /<([a-z][^/\0>\x20\t\r\n\f]+)/i.exec(text) || ['', ''])[1].toLowerCase();
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
var defineInnerHTML = function defineInnerHTML(obj) {
|
|
274
|
-
Object.defineProperty(obj, 'innerHTML', {
|
|
275
|
-
get: function() {
|
|
276
|
-
return getInnerHTML(this);
|
|
277
|
-
},
|
|
278
|
-
set: function(text) {
|
|
279
|
-
// For IE11, wrap the text in the correct (table) context
|
|
280
|
-
var wrap = topLevelWrappingMap[getTagName(text)];
|
|
281
|
-
if (wrap) {
|
|
282
|
-
for (var i = 0; i < wrap.length; i++) {
|
|
283
|
-
text = '<' + wrap[i] + '>' + text + '</' + wrap[i] + '>';
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
contentDoc.body.innerHTML = text;
|
|
287
|
-
PolyfilledHTMLTemplateElement.bootstrap(contentDoc);
|
|
288
|
-
while (this.content.firstChild) {
|
|
289
|
-
capturedRemoveChild.call(this.content, this.content.firstChild);
|
|
290
|
-
}
|
|
291
|
-
var body = contentDoc.body;
|
|
292
|
-
// If we had wrapped, get back to the original node
|
|
293
|
-
if (wrap) {
|
|
294
|
-
for (var j = 0; j < wrap.length; j++) {
|
|
295
|
-
body = body.lastChild;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
while (body.firstChild) {
|
|
299
|
-
capturedAppendChild.call(this.content, body.firstChild);
|
|
300
|
-
}
|
|
301
|
-
},
|
|
302
|
-
configurable: true
|
|
303
|
-
});
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
var defineOuterHTML = function defineOuterHTML(obj) {
|
|
307
|
-
Object.defineProperty(obj, 'outerHTML', {
|
|
308
|
-
get: function() {
|
|
309
|
-
return '<' + TEMPLATE_TAG + '>' + this.innerHTML + '</' + TEMPLATE_TAG + '>';
|
|
310
|
-
},
|
|
311
|
-
set: function(innerHTML) {
|
|
312
|
-
if (this.parentNode) {
|
|
313
|
-
contentDoc.body.innerHTML = innerHTML;
|
|
314
|
-
var docFrag = this.ownerDocument.createDocumentFragment();
|
|
315
|
-
while (contentDoc.body.firstChild) {
|
|
316
|
-
capturedAppendChild.call(docFrag, contentDoc.body.firstChild);
|
|
317
|
-
}
|
|
318
|
-
capturedReplaceChild.call(this.parentNode, docFrag, this);
|
|
319
|
-
} else {
|
|
320
|
-
throw new Error("Failed to set the 'outerHTML' property on 'Element': This element has no parent node.");
|
|
321
|
-
}
|
|
322
|
-
},
|
|
323
|
-
configurable: true
|
|
324
|
-
});
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
defineInnerHTML(PolyfilledHTMLTemplateElement.prototype);
|
|
328
|
-
defineOuterHTML(PolyfilledHTMLTemplateElement.prototype);
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
The `bootstrap` method is called automatically and "fixes" all
|
|
332
|
-
<template> elements in the document referenced by the `doc` argument.
|
|
333
|
-
*/
|
|
334
|
-
PolyfilledHTMLTemplateElement.bootstrap = function bootstrap(doc) {
|
|
335
|
-
var templates = QSA(doc, TEMPLATE_TAG);
|
|
336
|
-
for (var i=0, l=templates.length, t; (i<l) && (t=templates[i]); i++) {
|
|
337
|
-
PolyfilledHTMLTemplateElement.decorate(t);
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
// auto-bootstrapping for main document
|
|
342
|
-
document.addEventListener('DOMContentLoaded', function() {
|
|
343
|
-
PolyfilledHTMLTemplateElement.bootstrap(document);
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
// Patch document.createElement to ensure newly created templates have content
|
|
347
|
-
Document.prototype.createElement = function createElement() {
|
|
348
|
-
var el = capturedCreateElement.apply(this, arguments);
|
|
349
|
-
if (el.localName === 'template') {
|
|
350
|
-
PolyfilledHTMLTemplateElement.decorate(el);
|
|
351
|
-
}
|
|
352
|
-
return el;
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
DOMParser.prototype.parseFromString = function() {
|
|
356
|
-
var el = capturedParseFromString.apply(this, arguments);
|
|
357
|
-
PolyfilledHTMLTemplateElement.bootstrap(el);
|
|
358
|
-
return el;
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
Object.defineProperty(HTMLElement.prototype, 'innerHTML', {
|
|
362
|
-
get: function() {
|
|
363
|
-
return getInnerHTML(this);
|
|
364
|
-
},
|
|
365
|
-
set: function(text) {
|
|
366
|
-
capturedHTMLElementInnerHTML.set.call(this, text);
|
|
367
|
-
PolyfilledHTMLTemplateElement.bootstrap(this);
|
|
368
|
-
},
|
|
369
|
-
configurable: true,
|
|
370
|
-
enumerable: true
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#escapingString
|
|
374
|
-
var escapeAttrRegExp = /[&\u00A0"]/g;
|
|
375
|
-
var escapeDataRegExp = /[&\u00A0<>]/g;
|
|
376
|
-
|
|
377
|
-
var escapeReplace = function(c) {
|
|
378
|
-
switch (c) {
|
|
379
|
-
case '&':
|
|
380
|
-
return '&';
|
|
381
|
-
case '<':
|
|
382
|
-
return '<';
|
|
383
|
-
case '>':
|
|
384
|
-
return '>';
|
|
385
|
-
case '"':
|
|
386
|
-
return '"';
|
|
387
|
-
case '\u00A0':
|
|
388
|
-
return ' ';
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
var escapeAttr = function(s) {
|
|
393
|
-
return s.replace(escapeAttrRegExp, escapeReplace);
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
var escapeData = function(s) {
|
|
397
|
-
return s.replace(escapeDataRegExp, escapeReplace);
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
var makeSet = function(arr) {
|
|
401
|
-
var set = {};
|
|
402
|
-
for (var i = 0; i < arr.length; i++) {
|
|
403
|
-
set[arr[i]] = true;
|
|
404
|
-
}
|
|
405
|
-
return set;
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
// http://www.whatwg.org/specs/web-apps/current-work/#void-elements
|
|
409
|
-
var voidElements = makeSet([
|
|
410
|
-
'area',
|
|
411
|
-
'base',
|
|
412
|
-
'br',
|
|
413
|
-
'col',
|
|
414
|
-
'command',
|
|
415
|
-
'embed',
|
|
416
|
-
'hr',
|
|
417
|
-
'img',
|
|
418
|
-
'input',
|
|
419
|
-
'keygen',
|
|
420
|
-
'link',
|
|
421
|
-
'meta',
|
|
422
|
-
'param',
|
|
423
|
-
'source',
|
|
424
|
-
'track',
|
|
425
|
-
'wbr'
|
|
426
|
-
]);
|
|
427
|
-
|
|
428
|
-
var plaintextParents = makeSet([
|
|
429
|
-
'style',
|
|
430
|
-
'script',
|
|
431
|
-
'xmp',
|
|
432
|
-
'iframe',
|
|
433
|
-
'noembed',
|
|
434
|
-
'noframes',
|
|
435
|
-
'plaintext',
|
|
436
|
-
'noscript'
|
|
437
|
-
]);
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* @param {Node} node
|
|
441
|
-
* @param {Node} parentNode
|
|
442
|
-
* @param {Function=} callback
|
|
443
|
-
*/
|
|
444
|
-
var getOuterHTML = function(node, parentNode, callback) {
|
|
445
|
-
switch (node.nodeType) {
|
|
446
|
-
case Node.ELEMENT_NODE: {
|
|
447
|
-
var tagName = node.localName;
|
|
448
|
-
var s = '<' + tagName;
|
|
449
|
-
var attrs = node.attributes;
|
|
450
|
-
for (var i = 0, attr; (attr = attrs[i]); i++) {
|
|
451
|
-
s += ' ' + attr.name + '="' + escapeAttr(attr.value) + '"';
|
|
452
|
-
}
|
|
453
|
-
s += '>';
|
|
454
|
-
if (voidElements[tagName]) {
|
|
455
|
-
return s;
|
|
456
|
-
}
|
|
457
|
-
return s + getInnerHTML(node, callback) + '</' + tagName + '>';
|
|
458
|
-
}
|
|
459
|
-
case Node.TEXT_NODE: {
|
|
460
|
-
var data = /** @type {Text} */ (node).data;
|
|
461
|
-
if (parentNode && plaintextParents[parentNode.localName]) {
|
|
462
|
-
return data;
|
|
463
|
-
}
|
|
464
|
-
return escapeData(data);
|
|
465
|
-
}
|
|
466
|
-
case Node.COMMENT_NODE: {
|
|
467
|
-
return '<!--' + /** @type {Comment} */ (node).data + '-->';
|
|
468
|
-
}
|
|
469
|
-
default: {
|
|
470
|
-
window.console.error(node);
|
|
471
|
-
throw new Error('not implemented');
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
* @param {Node} node
|
|
478
|
-
* @param {Function=} callback
|
|
479
|
-
*/
|
|
480
|
-
var getInnerHTML = function(node, callback) {
|
|
481
|
-
if (node.localName === 'template') {
|
|
482
|
-
node = /** @type {HTMLTemplateElement} */ (node).content;
|
|
483
|
-
}
|
|
484
|
-
var s = '';
|
|
485
|
-
var c$ = callback ? callback(node) : capturedChildNodes.get.call(node);
|
|
486
|
-
for (var i=0, l=c$.length, child; (i<l) && (child=c$[i]); i++) {
|
|
487
|
-
s += getOuterHTML(child, node, callback);
|
|
488
|
-
}
|
|
489
|
-
return s;
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
// make cloning/importing work!
|
|
495
|
-
if (needsTemplate || needsCloning) {
|
|
496
|
-
|
|
497
|
-
PolyfilledHTMLTemplateElement._cloneNode = function _cloneNode(template, deep) {
|
|
498
|
-
var clone = capturedCloneNode.call(template, false);
|
|
499
|
-
// NOTE: decorate doesn't auto-fix children because they are already
|
|
500
|
-
// decorated so they need special clone fixup.
|
|
501
|
-
if (this.decorate) {
|
|
502
|
-
this.decorate(clone);
|
|
503
|
-
}
|
|
504
|
-
if (deep) {
|
|
505
|
-
// NOTE: use native clone node to make sure CE's wrapped
|
|
506
|
-
// cloneNode does not cause elements to upgrade.
|
|
507
|
-
capturedAppendChild.call(clone.content, capturedCloneNode.call(template.content, true));
|
|
508
|
-
// now ensure nested templates are cloned correctly.
|
|
509
|
-
fixClonedDom(clone.content, template.content);
|
|
510
|
-
}
|
|
511
|
-
return clone;
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
// Given a source and cloned subtree, find <template>'s in the cloned
|
|
515
|
-
// subtree and replace them with cloned <template>'s from source.
|
|
516
|
-
// We must do this because only the source templates have proper .content.
|
|
517
|
-
var fixClonedDom = function fixClonedDom(clone, source) {
|
|
518
|
-
// do nothing if cloned node is not an element
|
|
519
|
-
if (!source.querySelectorAll) return;
|
|
520
|
-
// these two lists should be coincident
|
|
521
|
-
var s$ = QSA(source, TEMPLATE_TAG);
|
|
522
|
-
if (s$.length === 0) {
|
|
523
|
-
return;
|
|
524
|
-
}
|
|
525
|
-
var t$ = QSA(clone, TEMPLATE_TAG);
|
|
526
|
-
for (var i=0, l=t$.length, t, s; i<l; i++) {
|
|
527
|
-
s = s$[i];
|
|
528
|
-
t = t$[i];
|
|
529
|
-
if (PolyfilledHTMLTemplateElement && PolyfilledHTMLTemplateElement.decorate) {
|
|
530
|
-
PolyfilledHTMLTemplateElement.decorate(s);
|
|
531
|
-
}
|
|
532
|
-
capturedReplaceChild.call(t.parentNode, cloneNode.call(s, true), t);
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
// make sure scripts inside of a cloned template are executable
|
|
537
|
-
var fixClonedScripts = function fixClonedScripts(fragment) {
|
|
538
|
-
var scripts = QSA(fragment, scriptSelector);
|
|
539
|
-
for (var ns, s, i = 0; i < scripts.length; i++) {
|
|
540
|
-
s = scripts[i];
|
|
541
|
-
ns = capturedCreateElement.call(document, 'script');
|
|
542
|
-
ns.textContent = s.textContent;
|
|
543
|
-
var attrs = s.attributes;
|
|
544
|
-
for (var ai = 0, a; ai < attrs.length; ai++) {
|
|
545
|
-
a = attrs[ai];
|
|
546
|
-
ns.setAttribute(a.name, a.value);
|
|
547
|
-
}
|
|
548
|
-
capturedReplaceChild.call(s.parentNode, ns, s);
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
|
|
552
|
-
// override all cloning to fix the cloned subtree to contain properly
|
|
553
|
-
// cloned templates.
|
|
554
|
-
var cloneNode = Node.prototype.cloneNode = function cloneNode(deep) {
|
|
555
|
-
var dom;
|
|
556
|
-
// workaround for Edge bug cloning documentFragments
|
|
557
|
-
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8619646/
|
|
558
|
-
if (!needsDocFrag && brokenDocFragment && this instanceof DocumentFragment) {
|
|
559
|
-
if (!deep) {
|
|
560
|
-
return this.ownerDocument.createDocumentFragment();
|
|
561
|
-
} else {
|
|
562
|
-
dom = importNode.call(this.ownerDocument, this, true);
|
|
563
|
-
}
|
|
564
|
-
} else if (this.nodeType === Node.ELEMENT_NODE &&
|
|
565
|
-
this.localName === TEMPLATE_TAG &&
|
|
566
|
-
this.namespaceURI == document.documentElement.namespaceURI) {
|
|
567
|
-
dom = PolyfilledHTMLTemplateElement._cloneNode(this, deep);
|
|
568
|
-
} else {
|
|
569
|
-
dom = capturedCloneNode.call(this, deep);
|
|
570
|
-
}
|
|
571
|
-
// template.content is cloned iff `deep`.
|
|
572
|
-
if (deep) {
|
|
573
|
-
fixClonedDom(dom, this);
|
|
574
|
-
}
|
|
575
|
-
return dom;
|
|
576
|
-
};
|
|
577
|
-
|
|
578
|
-
// NOTE: we are cloning instead of importing <template>'s.
|
|
579
|
-
// However, the ownerDocument of the cloned template will be correct!
|
|
580
|
-
// This is because the native import node creates the right document owned
|
|
581
|
-
// subtree and `fixClonedDom` inserts cloned templates into this subtree,
|
|
582
|
-
// thus updating the owner doc.
|
|
583
|
-
var importNode = Document.prototype.importNode = function importNode(element, deep) {
|
|
584
|
-
deep = deep || false;
|
|
585
|
-
if (element.localName === TEMPLATE_TAG) {
|
|
586
|
-
return PolyfilledHTMLTemplateElement._cloneNode(element, deep);
|
|
587
|
-
} else {
|
|
588
|
-
var dom = capturedImportNode.call(this, element, deep);
|
|
589
|
-
if (deep) {
|
|
590
|
-
fixClonedDom(dom, element);
|
|
591
|
-
fixClonedScripts(dom);
|
|
592
|
-
}
|
|
593
|
-
return dom;
|
|
594
|
-
}
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
if (needsTemplate) {
|
|
599
|
-
window.HTMLTemplateElement = PolyfilledHTMLTemplateElement;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"aliases":["es6","es2015","default-3.6","default"],"dependencies":["_ESAbstract.CreateMethodProperty","_ESAbstract.CreateIterResultObject","_ESAbstract.GetMethod","_ESAbstract.GetIterator","_ESAbstract.IsCallable","_ESAbstract.IteratorClose","_ESAbstract.IteratorComplete","_ESAbstract.IteratorNext","_ESAbstract.IteratorStep","_ESAbstract.IteratorValue","_ESAbstract.OrdinaryCreateFromConstructor","_ESAbstract.SameValueZero","_ESAbstract.Type","Symbol","Symbol.iterator","Symbol.species","Object.isExtensible"],"notes":["The test suite for this polyfill is derived from work of Andrea Giammarchi which is [published under an MIT licence](https://github.com/WebReflection/es6-collections)"],"docs":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map","browsers":{"android":"<5.1","bb":"10 - *","chrome":"<49","edge":"<
|
|
1
|
+
{"aliases":["es6","es2015","default-3.6","default"],"dependencies":["_ESAbstract.CreateMethodProperty","_ESAbstract.CreateIterResultObject","_ESAbstract.GetMethod","_ESAbstract.GetIterator","_ESAbstract.IsCallable","_ESAbstract.IteratorClose","_ESAbstract.IteratorComplete","_ESAbstract.IteratorNext","_ESAbstract.IteratorStep","_ESAbstract.IteratorValue","_ESAbstract.OrdinaryCreateFromConstructor","_ESAbstract.SameValueZero","_ESAbstract.Type","Symbol","Symbol.iterator","Symbol.species","Symbol.toStringTag","Object.isExtensible"],"notes":["The test suite for this polyfill is derived from work of Andrea Giammarchi which is [published under an MIT licence](https://github.com/WebReflection/es6-collections)"],"docs":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map","browsers":{"android":"<5.1","bb":"10 - *","chrome":"<49","edge":"<15","firefox":"<51","firefox_mob":"<51","ie":"*","ie_mob":"*","opera":"<36","op_mob":"<36","op_mini":"*","safari":"<10.0","ios_saf":"<10.0","samsung_mob":"<5"},"detectSource":"\"Map\"in self&&function(t){try{var n=new t.Map([[1,1],[2,2]])\nreturn 0===t.Map.length&&2===n.size&&\"Symbol\"in t&&\"iterator\"in t.Symbol&&\"function\"==typeof n[t.Symbol.iterator]&&\"toStringTag\"in t.Symbol&&void 0!==n[t.Symbol.toStringTag]}catch(t){return!1}}(self)\n","baseDir":"Map","hasTests":true,"isTestable":true,"isPublic":true,"size":7438}
|