@wiris/mathtype-html-integration-devkit
Version:
Allows to integrate MathType Web into any JavaScript HTML WYSIWYG rich text editor.
163 lines (145 loc) • 4.63 kB
JavaScript
/* eslint-disable */
var polyfills;
export default polyfills;
// Polyfills.
/*! http://mths.be/codepointat v0.1.0 by @mathias */
if (!String.prototype.codePointAt) {
(function () {
"use strict"; // needed to support `apply`/`call` with `undefined`/`null`
var codePointAt = function (position) {
if (this == null) {
throw TypeError();
}
var string = String(this);
var size = string.length;
// `ToInteger`
var index = position ? Number(position) : 0;
if (index != index) {
// better `isNaN`
index = 0;
}
// Account for out-of-bounds indices:
if (index < 0 || index >= size) {
return undefined;
}
// Get the first code unit
var first = string.charCodeAt(index);
var second;
if (
// check if it’s the start of a surrogate pair
first >= 0xd800 &&
first <= 0xdbff && // high surrogate
size > index + 1 // there is a next code unit
) {
second = string.charCodeAt(index + 1);
if (second >= 0xdc00 && second <= 0xdfff) {
// low surrogate
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
return (first - 0xd800) * 0x400 + second - 0xdc00 + 0x10000;
}
}
return first;
};
if (Object.defineProperty) {
Object.defineProperty(String.prototype, "codePointAt", {
value: codePointAt,
configurable: true,
writable: true,
});
} else {
String.prototype.codePointAt = codePointAt;
}
})();
}
// Object.assign polyfill.
if (typeof Object.assign != "function") {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) {
// .length of function is 2
"use strict";
if (target == null) {
// TypeError if undefined or null
throw new TypeError("Cannot convert undefined or null to object");
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) {
// Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true,
});
}
// https://tc39.github.io/ecma262/#sec-array.prototype.includes
if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, "includes", {
value: function (searchElement, fromIndex) {
if (this == null) {
throw new TypeError('"this" s null or is not defined');
}
// 1. Let O be ? ToObject(this value).
var o = Object(this);
// 2. Let len be ? ToLength(? Get(O, "length")).
var len = o.length >>> 0;
// 3. if len is 0, return false.
if (len === 0) {
return false;
}
// 4. Let n be ? ToInteger(fromIndex).
// (if fromIndex is undefinedo, this step generates the value 0.)
var n = fromIndex | 0;
// 5. if n ≥ 0, then
// a. Let k be n.
// 6. Else n < 0,
// a. Let k be len + n.
// b. if k < 0, let k be 0.
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
function sameValueZero(x, y) {
return x === y || (typeof x === "number" && typeof y === "number" && isNaN(x) && isNaN(y));
}
// 7. Repeat while k < len
while (k < len) {
// a. let element k be the result of ? Get(O, ! ToString(k)).
// b. if SameValueZero(searchElement, elementK) is true, return true.
if (sameValueZero(o[k], searchElement)) {
return true;
}
// c. Increase k by 1.
k++;
}
// 8. Return false
return false;
},
});
}
if (!String.prototype.includes) {
String.prototype.includes = function (search, start) {
"use strict";
if (search instanceof RegExp) {
throw TypeError("first argument must not be a RegExp");
}
if (start === undefined) {
start = 0;
}
return this.indexOf(search, start) !== -1;
};
}
if (!String.prototype.startsWith) {
Object.defineProperty(String.prototype, "startsWith", {
value: function (search, rawPos) {
var pos = rawPos > 0 ? rawPos | 0 : 0;
return this.substring(pos, pos + search.length) === search;
},
});
}