-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
734 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,43 @@ | ||
!function(window, document){ | ||
!function(window, document){ 'use strict'; | ||
|
||
var urls = { | ||
'cdn.jsdelivr.net/npm/[email protected]/fetch.js':{ | ||
'fetch':[window], | ||
'Headers':[window], | ||
'Request':[window], | ||
'Response':[window], | ||
//'Headers':[window], | ||
//'Request':[window], | ||
//'Response':[window], | ||
}, | ||
'cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js':{ | ||
'Promise':[window] | ||
}, | ||
'polyfill.io/v3/polyfill.min.js?features=IntersectionObserver':{ | ||
'IntersectionObserver':[window] | ||
}, | ||
'polyfill.io/v3/polyfill.min.js?features=ResizeObserver':{ | ||
'ResizeObserver':[window] | ||
}, | ||
'polyfill.io/v3/polyfill.min.js?features=AbortController':{ | ||
'AbortController':[window] | ||
'AbortController':[window], | ||
//'AbortSignal': [window] | ||
}, | ||
'polyfill.io/v3/polyfill.min.js?features=URL':{ | ||
'URL':[window], | ||
'URL':[window], // ie11: this will not work as it has "URL" but not as a constructor, what should we do? | ||
'URLSearchParams':[window] | ||
}, | ||
'polyfill.io/v3/polyfill.js?features=ResizeObserver':{ | ||
'ResizeObserver':[window] | ||
}, | ||
'unpkg.com/@ungap/weakset':{ | ||
'WeakSet':[window] | ||
}, | ||
'unpkg.com/@ungap/custom-elements/es.js':{ | ||
'customElements':[window] | ||
'unpkg.com/@ungap/custom-elements@0.1.15/es.js':{ | ||
'customElements':[document] | ||
}, | ||
'unpkg.com/@ungap/item':{ | ||
'item':[Array.prototype] | ||
} | ||
/* | ||
'polyfill.io/v3/polyfill.min.js?features=es2021':{ | ||
'keys':[Object], | ||
'flags':[RegExp.prototype], | ||
'Symbol':[window], | ||
//'replace':[Symbol], | ||
'Symbol':[window], | ||
'replaceAll':[String.prototype], | ||
} | ||
*/ | ||
}; | ||
|
||
/* | ||
They have internal depencies :( | ||
var ftPolyfills = { | ||
var lazyfills = { | ||
Array:{ | ||
from:1, | ||
of:1, | ||
prototype:{ | ||
at:1, | ||
copyWithin:1, | ||
entries:1, | ||
fill:1, | ||
|
@@ -63,17 +50,21 @@ var ftPolyfills = { | |
values:1, | ||
} | ||
}, | ||
Element:{ | ||
prototype:{ | ||
toggleAttribute:1, | ||
} | ||
}, | ||
String:{ | ||
fromCodePoint:1, | ||
prototype:{ | ||
at:1, | ||
codePointAt:1, | ||
endsWith:1, | ||
includes:1, | ||
padEnd:1, | ||
padStart:1, | ||
repeat:1, | ||
startsWith:1 | ||
} | ||
} | ||
}; | ||
function ftFill(obj, realObj, rootUrl){ | ||
function createUrls(obj, realObj, rootUrl){ | ||
var prop; | ||
for (prop in obj) { | ||
if (obj[prop] === 1) { | ||
|
@@ -82,12 +73,11 @@ function ftFill(obj, realObj, rootUrl){ | |
urls[url] = {}; | ||
urls[url][prop] = [realObj]; | ||
} else { | ||
ftFill(obj[prop], realObj[prop], rootUrl + prop + '/'); | ||
createUrls(obj[prop], realObj[prop], rootUrl + prop + '.js'); | ||
} | ||
} | ||
} | ||
ftFill(ftPolyfills, window, 'cdn.jsdelivr.net/gh/Financial-Times/polyfill-library@3/polyfills/'); | ||
*/ | ||
createUrls(lazyfills, window, 'cdn.jsdelivr.net/gh/nuxodin/[email protected]/polyfills/'); | ||
|
||
|
||
var url, props, prop, obj, objects, i; | ||
|
@@ -97,7 +87,7 @@ for (url in urls) { | |
objects = props[prop]; | ||
for (i=0; obj=objects[i++];) { | ||
if (prop in obj) { | ||
//console.log('not needed '+prop+' in '+url+'<br>') | ||
console.log('not needed '+prop+' in '+url+'<br>') | ||
continue; | ||
} | ||
//console.log('"'+prop+'" not supported, adding getter'); | ||
|
@@ -115,12 +105,11 @@ function addGetter(obj, prop, url) { | |
configurable: true, | ||
get: function() { | ||
delete obj[prop]; | ||
console.log(prop+' needed loading sync'); | ||
console.log(prop+' needed > loading sync, you may want to add the polyfill '+url); | ||
loadScriptSync('https://'+url); | ||
//return c1Use.call(this, prop); | ||
return this[prop]; | ||
}, | ||
set: function(v) { // needed? | ||
set: function(v) { | ||
delete obj[prop]; | ||
obj[prop] = v; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
if (!Array.from) { | ||
Array.from = (function () { | ||
var toStr = Object.prototype.toString; | ||
var isCallable = function (fn) { | ||
return typeof fn === 'function' || toStr.call(fn) === '[object Function]'; | ||
}; | ||
var toInteger = function (value) { | ||
var number = Number(value); | ||
if (isNaN(number)) { | ||
return 0; | ||
} | ||
if (number === 0 || !isFinite(number)) { | ||
return number; | ||
} | ||
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number)); | ||
}; | ||
var maxSafeInteger = Math.pow(2, 53) - 1; | ||
var toLength = function (value) { | ||
var len = toInteger(value); | ||
return Math.min(Math.max(len, 0), maxSafeInteger); | ||
}; | ||
|
||
// The length property of the from method is 1. | ||
return function from(arrayLike /*, mapFn, thisArg */) { | ||
// 1. Let C be the this value. | ||
var C = this; | ||
|
||
// 2. Let items be ToObject(arrayLike). | ||
var items = Object(arrayLike); | ||
|
||
// 3. ReturnIfAbrupt(items). | ||
if (arrayLike == null) { | ||
throw new TypeError( | ||
'Array.from requires an array-like object - not null or undefined' | ||
); | ||
} | ||
|
||
// 4. If mapfn is undefined, then let mapping be false. | ||
var mapFn = arguments.length > 1 ? arguments[1] : void undefined; | ||
var T; | ||
if (typeof mapFn !== 'undefined') { | ||
// 5. else | ||
// 5. a If IsCallable(mapfn) is false, throw a TypeError exception. | ||
if (!isCallable(mapFn)) { | ||
throw new TypeError( | ||
'Array.from: when provided, the second argument must be a function' | ||
); | ||
} | ||
|
||
// 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined. | ||
if (arguments.length > 2) { | ||
T = arguments[2]; | ||
} | ||
} | ||
|
||
// 10. Let lenValue be Get(items, "length"). | ||
// 11. Let len be ToLength(lenValue). | ||
var len = toLength(items.length); | ||
|
||
// 13. If IsConstructor(C) is true, then | ||
// 13. a. Let A be the result of calling the [[Construct]] internal method | ||
// of C with an argument list containing the single item len. | ||
// 14. a. Else, Let A be ArrayCreate(len). | ||
var A = isCallable(C) ? Object(new C(len)) : new Array(len); | ||
|
||
// 16. Let k be 0. | ||
var k = 0; | ||
// 17. Repeat, while k < len… (also steps a - h) | ||
var kValue; | ||
while (k < len) { | ||
kValue = items[k]; | ||
if (mapFn) { | ||
A[k] = | ||
typeof T === 'undefined' | ||
? mapFn(kValue, k) | ||
: mapFn.call(T, kValue, k); | ||
} else { | ||
A[k] = kValue; | ||
} | ||
k += 1; | ||
} | ||
// 18. Let putStatus be Put(A, "length", len, true). | ||
A.length = len; | ||
// 20. Return A. | ||
return A; | ||
}; | ||
})(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
if (!Array.of) { | ||
Array.of = function () { | ||
return Array.prototype.slice.call(arguments); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
if (!Array.prototype.at) { | ||
Array.prototype.at = function(n){ | ||
n = Math.trunc(n) || 0; | ||
if (n < 0) n += this.length; | ||
if (n < 0 || n >= this.length) return undefined; | ||
return this[n]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
if (!Array.prototype.copyWithin) { | ||
Object.defineProperty(Array.prototype, 'copyWithin', { | ||
configurable: true, | ||
writable: true, | ||
value: function (target, start /*, end*/) { | ||
// Steps 1-2. | ||
if (this == null) { | ||
throw new TypeError('this is null or not defined'); | ||
} | ||
|
||
var O = Object(this); | ||
|
||
// Steps 3-5. | ||
var len = O.length >>> 0; | ||
|
||
// Steps 6-8. | ||
var relativeTarget = target >> 0; | ||
|
||
var to = | ||
relativeTarget < 0 | ||
? Math.max(len + relativeTarget, 0) | ||
: Math.min(relativeTarget, len); | ||
|
||
// Steps 9-11. | ||
var relativeStart = start >> 0; | ||
|
||
var from = | ||
relativeStart < 0 | ||
? Math.max(len + relativeStart, 0) | ||
: Math.min(relativeStart, len); | ||
|
||
// Steps 12-14. | ||
var end = arguments[2]; | ||
var relativeEnd = end === undefined ? len : end >> 0; | ||
|
||
var final = | ||
relativeEnd < 0 | ||
? Math.max(len + relativeEnd, 0) | ||
: Math.min(relativeEnd, len); | ||
|
||
// Step 15. | ||
var count = Math.min(final - from, len - to); | ||
|
||
// Steps 16-17. | ||
var direction = 1; | ||
|
||
if (from < to && to < from + count) { | ||
direction = -1; | ||
from += count - 1; | ||
to += count - 1; | ||
} | ||
|
||
// Step 18. | ||
while (count > 0) { | ||
if (from in O) { | ||
O[to] = O[from]; | ||
} else { | ||
delete O[to]; | ||
} | ||
|
||
from += direction; | ||
to += direction; | ||
count--; | ||
} | ||
|
||
// Step 19. | ||
return O; | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
if (!Array.prototype.entries) { | ||
Array.prototype.entries = function () { | ||
function Iterator() { } | ||
|
||
Iterator.prototype.next = function () { | ||
if (index > selfThis.length - 1) { | ||
done = true; | ||
} | ||
if (done) { | ||
return { value: undefined, done: true }; | ||
} | ||
return { value: [index, selfThis[index++]], done: false }; | ||
}; | ||
|
||
var selfThis = this; | ||
var index = 0; | ||
var done; | ||
|
||
return new Iterator(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
if (!Array.prototype.fill) { | ||
Object.defineProperty(Array.prototype, 'fill', { | ||
configurable: true, | ||
writable: true, | ||
value: function (value) { | ||
// Steps 1-2. | ||
if (this == null) { | ||
throw new TypeError('this is null or not defined'); | ||
} | ||
|
||
var O = Object(this); | ||
|
||
// Steps 3-5. | ||
var len = O.length >>> 0; | ||
|
||
// Steps 6-7. | ||
var start = arguments[1]; | ||
var relativeStart = start >> 0; | ||
|
||
// Step 8. | ||
var k = | ||
relativeStart < 0 | ||
? Math.max(len + relativeStart, 0) | ||
: Math.min(relativeStart, len); | ||
|
||
// Steps 9-10. | ||
var end = arguments[2]; | ||
var relativeEnd = end === undefined ? len : end >> 0; | ||
|
||
// Step 11. | ||
var final = | ||
relativeEnd < 0 | ||
? Math.max(len + relativeEnd, 0) | ||
: Math.min(relativeEnd, len); | ||
|
||
// Step 12. | ||
while (k < final) { | ||
O[k] = value; | ||
k++; | ||
} | ||
|
||
// Step 13. | ||
return O; | ||
}, | ||
}); | ||
} |
Oops, something went wrong.