UNPKG

@microsoft/office-js

Version:
1,032 lines (1,023 loc) • 498 kB
/* Office JavaScript API library - Custom Functions */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* This file incorporates the "whatwg-fetch" implementation, version 2.0.3, licensed under MIT with the following licensing notice: (See github.com/github/fetch/blob/master/LICENSE) Copyright (c) 2014-2016 GitHub, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* Your use of this file is governed by the Microsoft Services Agreement http://go.microsoft.com/fwlink/?LinkId=266419. This file also contains the following Promise implementation (with a few small modifications): * @overview es6-promise - a tiny implementation of Promises/A+. * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald) * @license Licensed under MIT license * See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE * @version 2.3.0 */ var OSF = OSF || {}; OSF.ConstantNames = { FileVersion: "0.0.0.0", OfficeJS: "custom-functions-runtime.js", OfficeDebugJS: "custom-functions-runtime.debug.js", HostFileScriptSuffix: "core", IsCustomFunctionsRuntime: true }; var OSF = OSF || {}; OSF.HostSpecificFileVersionDefault = "16.00"; OSF.HostSpecificFileVersionMap = { "access": { "web": "16.00" }, "agavito": { "winrt": "16.00" }, "excel": { "ios": "16.00", "mac": "16.00", "web": "16.00", "win32": "16.01", "winrt": "16.00" }, "onenote": { "android": "16.00", "web": "16.00", "win32": "16.00", "winrt": "16.00" }, "outlook": { "ios": "16.00", "mac": "16.00", "web": "16.01", "win32": "16.02" }, "powerpoint": { "ios": "16.00", "mac": "16.00", "web": "16.00", "win32": "16.01", "winrt": "16.00" }, "project": { "win32": "16.00" }, "sway": { "web": "16.00" }, "word": { "ios": "16.00", "mac": "16.00", "web": "16.00", "win32": "16.01", "winrt": "16.00" }, "visio": { "web": "16.00", "win32": "16.00" } }; OSF.SupportedLocales = { "ar-sa": true, "bg-bg": true, "bn-in": true, "ca-es": true, "cs-cz": true, "da-dk": true, "de-de": true, "el-gr": true, "en-us": true, "es-es": true, "et-ee": true, "eu-es": true, "fa-ir": true, "fi-fi": true, "fr-fr": true, "gl-es": true, "he-il": true, "hi-in": true, "hr-hr": true, "hu-hu": true, "id-id": true, "it-it": true, "ja-jp": true, "kk-kz": true, "ko-kr": true, "lo-la": true, "lt-lt": true, "lv-lv": true, "ms-my": true, "nb-no": true, "nl-nl": true, "nn-no": true, "pl-pl": true, "pt-br": true, "pt-pt": true, "ro-ro": true, "ru-ru": true, "sk-sk": true, "sl-si": true, "sr-cyrl-cs": true, "sr-cyrl-rs": true, "sr-latn-cs": true, "sr-latn-rs": true, "sv-se": true, "th-th": true, "tr-tr": true, "uk-ua": true, "ur-pk": true, "vi-vn": true, "zh-cn": true, "zh-tw": true }; OSF.AssociatedLocales = { ar: "ar-sa", bg: "bg-bg", bn: "bn-in", ca: "ca-es", cs: "cs-cz", da: "da-dk", de: "de-de", el: "el-gr", en: "en-us", es: "es-es", et: "et-ee", eu: "eu-es", fa: "fa-ir", fi: "fi-fi", fr: "fr-fr", gl: "gl-es", he: "he-il", hi: "hi-in", hr: "hr-hr", hu: "hu-hu", id: "id-id", it: "it-it", ja: "ja-jp", kk: "kk-kz", ko: "ko-kr", lo: "lo-la", lt: "lt-lt", lv: "lv-lv", ms: "ms-my", nb: "nb-no", nl: "nl-nl", nn: "nn-no", pl: "pl-pl", pt: "pt-br", ro: "ro-ro", ru: "ru-ru", sk: "sk-sk", sl: "sl-si", sr: "sr-cyrl-cs", sv: "sv-se", th: "th-th", tr: "tr-tr", uk: "uk-ua", ur: "ur-pk", vi: "vi-vn", zh: "zh-cn" }; OSF.getSupportedLocale = function OSF$getSupportedLocale(locale, defaultLocale) { if (defaultLocale === void 0) { defaultLocale = "en-us"; } if (!locale) { return defaultLocale; } var supportedLocale; locale = locale.toLowerCase(); if (locale in OSF.SupportedLocales) { supportedLocale = locale; } else { var localeParts = locale.split('-', 1); if (localeParts && localeParts.length > 0) { supportedLocale = OSF.AssociatedLocales[localeParts[0]]; } } if (!supportedLocale) { supportedLocale = defaultLocale; } return supportedLocale; }; var ScriptLoading; (function (ScriptLoading) { var ScriptInfo = (function () { function ScriptInfo(url, isReady, hasStarted, timer, pendingCallback) { this.url = url; this.isReady = isReady; this.hasStarted = hasStarted; this.timer = timer; this.hasError = false; this.pendingCallbacks = []; this.pendingCallbacks.push(pendingCallback); } return ScriptInfo; }()); var ScriptTelemetry = (function () { function ScriptTelemetry(scriptId, startTime, msResponseTime) { this.scriptId = scriptId; this.startTime = startTime; this.msResponseTime = msResponseTime; } return ScriptTelemetry; }()); var LoadScriptHelper = (function () { function LoadScriptHelper(constantNames) { if (constantNames === void 0) { constantNames = { OfficeJS: "office.js", OfficeDebugJS: "office.debug.js" }; } this.constantNames = constantNames; this.defaultScriptLoadingTimeout = 10000; this.loadedScriptByIds = {}; this.scriptTelemetryBuffer = []; this.osfControlAppCorrelationId = ""; this.basePath = null; this.getUseAssociatedActionsOnly = null; } LoadScriptHelper.prototype.isScriptLoading = function (id) { return !!(this.loadedScriptByIds[id] && this.loadedScriptByIds[id].hasStarted); }; LoadScriptHelper.prototype.getOfficeJsBasePath = function () { if (this.basePath) { return this.basePath; } else { var getScriptBase = function (scriptSrc, scriptNameToCheck) { var scriptBase, indexOfJS, scriptSrcLowerCase; scriptSrcLowerCase = scriptSrc.toLowerCase(); indexOfJS = scriptSrcLowerCase.indexOf(scriptNameToCheck); if (indexOfJS >= 0 && indexOfJS === (scriptSrc.length - scriptNameToCheck.length) && (indexOfJS === 0 || scriptSrc.charAt(indexOfJS - 1) === '/' || scriptSrc.charAt(indexOfJS - 1) === '\\')) { scriptBase = scriptSrc.substring(0, indexOfJS); } else if (indexOfJS >= 0 && indexOfJS < (scriptSrc.length - scriptNameToCheck.length) && scriptSrc.charAt(indexOfJS + scriptNameToCheck.length) === '?' && (indexOfJS === 0 || scriptSrc.charAt(indexOfJS - 1) === '/' || scriptSrc.charAt(indexOfJS - 1) === '\\')) { scriptBase = scriptSrc.substring(0, indexOfJS); } return scriptBase; }; var scripts = document.getElementsByTagName("script"); var scriptsCount = scripts.length; var officeScripts = [this.constantNames.OfficeJS, this.constantNames.OfficeDebugJS]; var officeScriptsCount = officeScripts.length; this.getUseAssociatedActionsOnly = false; var i, j; for (i = 0; !this.basePath && i < scriptsCount; i++) { if (scripts[i].src) { for (j = 0; !this.basePath && j < officeScriptsCount; j++) { this.basePath = getScriptBase(scripts[i].src, officeScripts[j]); if (this.basePath) { try { var attr = scripts[i].getAttribute("data-use-associated-actions-only"); this.getUseAssociatedActionsOnly = attr === "1"; } catch (ex) { } } } } } return this.basePath; } }; LoadScriptHelper.prototype.getUseAssociatedActionsOnlyDefined = function () { this.getOfficeJsBasePath(); return this.getUseAssociatedActionsOnly; }; LoadScriptHelper.prototype.loadScript = function (url, scriptId, callback, highPriority, timeoutInMs) { this.loadScriptInternal(url, scriptId, callback, highPriority, timeoutInMs); }; LoadScriptHelper.prototype.loadScriptParallel = function (url, scriptId, timeoutInMs) { this.loadScriptInternal(url, scriptId, null, false, timeoutInMs); }; LoadScriptHelper.prototype.waitForFunction = function (scriptLoadTest, callback, numberOfTries, delay) { var attemptsRemaining = numberOfTries; var timerId; var validateFunction = function () { attemptsRemaining--; if (scriptLoadTest()) { callback(true); return; } else if (attemptsRemaining > 0) { timerId = window.setTimeout(validateFunction, delay); attemptsRemaining--; } else { window.clearTimeout(timerId); callback(false); } }; validateFunction(); }; LoadScriptHelper.prototype.waitForScripts = function (ids, callback) { var _this = this; if (this.invokeCallbackIfScriptsReady(ids, callback) == false) { for (var i = 0; i < ids.length; i++) { var id = ids[i]; var loadedScriptEntry = this.loadedScriptByIds[id]; if (loadedScriptEntry) { loadedScriptEntry.pendingCallbacks.push(function () { _this.invokeCallbackIfScriptsReady(ids, callback); }); } } } }; LoadScriptHelper.prototype.logScriptLoading = function (scriptId, startTime, msResponseTime) { startTime = Math.floor(startTime); if (OSF.AppTelemetry && OSF.AppTelemetry.onScriptDone) { if (OSF.AppTelemetry.onScriptDone.length == 3) { OSF.AppTelemetry.onScriptDone(scriptId, startTime, msResponseTime); } else { OSF.AppTelemetry.onScriptDone(scriptId, startTime, msResponseTime, this.osfControlAppCorrelationId); } } else { var scriptTelemetry = new ScriptTelemetry(scriptId, startTime, msResponseTime); this.scriptTelemetryBuffer.push(scriptTelemetry); } }; LoadScriptHelper.prototype.setAppCorrelationId = function (appCorrelationId) { this.osfControlAppCorrelationId = appCorrelationId; }; LoadScriptHelper.prototype.invokeCallbackIfScriptsReady = function (ids, callback) { var hasError = false; for (var i = 0; i < ids.length; i++) { var id = ids[i]; var loadedScriptEntry = this.loadedScriptByIds[id]; if (!loadedScriptEntry) { loadedScriptEntry = new ScriptInfo("", false, false, null, null); this.loadedScriptByIds[id] = loadedScriptEntry; } if (loadedScriptEntry.isReady == false) { return false; } else if (loadedScriptEntry.hasError) { hasError = true; } } callback(!hasError); return true; }; LoadScriptHelper.prototype.getScriptEntryByUrl = function (url) { for (var key in this.loadedScriptByIds) { var scriptEntry = this.loadedScriptByIds[key]; if (this.loadedScriptByIds.hasOwnProperty(key) && scriptEntry.url === url) { return scriptEntry; } } return null; }; LoadScriptHelper.prototype.loadScriptInternal = function (url, scriptId, callback, highPriority, timeoutInMs) { if (url) { var self = this; var doc = window.document; var loadedScriptEntry = (scriptId && this.loadedScriptByIds[scriptId]) ? this.loadedScriptByIds[scriptId] : this.getScriptEntryByUrl(url); if (!loadedScriptEntry || loadedScriptEntry.hasError || loadedScriptEntry.url.toLowerCase() != url.toLowerCase()) { var script = doc.createElement("script"); script.type = "text/javascript"; if (scriptId) { script.id = scriptId; } if (!loadedScriptEntry) { loadedScriptEntry = new ScriptInfo(url, false, false, null, null); this.loadedScriptByIds[(scriptId ? scriptId : url)] = loadedScriptEntry; } else { loadedScriptEntry.url = url; loadedScriptEntry.hasError = false; loadedScriptEntry.isReady = false; } if (callback) { if (highPriority) { loadedScriptEntry.pendingCallbacks.unshift(callback); } else { loadedScriptEntry.pendingCallbacks.push(callback); } } var timeFromPageInit = -1; if (window.performance && window.performance.now) { timeFromPageInit = window.performance.now(); } var startTime = (new Date()).getTime(); var logTelemetry = function (succeeded) { if (scriptId) { var totalTime = (new Date()).getTime() - startTime; if (!succeeded) { totalTime = -totalTime; } self.logScriptLoading(scriptId, timeFromPageInit, totalTime); } self.flushTelemetryBuffer(); }; var onLoadCallback = function OSF_OUtil_loadScript$onLoadCallback() { if (!OSF._OfficeAppFactory.getLoggingAllowed() && (typeof OSF.AppTelemetry !== 'undefined')) { OSF.AppTelemetry.enableTelemetry = false; } logTelemetry(true); loadedScriptEntry.isReady = true; if (loadedScriptEntry.timer != null) { clearTimeout(loadedScriptEntry.timer); delete loadedScriptEntry.timer; } var pendingCallbackCount = loadedScriptEntry.pendingCallbacks.length; for (var i = 0; i < pendingCallbackCount; i++) { var currentCallback = loadedScriptEntry.pendingCallbacks.shift(); if (currentCallback) { var result = currentCallback(true); if (result === false) { break; } } } }; var onLoadError = function () { logTelemetry(false); loadedScriptEntry.hasError = true; loadedScriptEntry.isReady = true; if (loadedScriptEntry.timer != null) { clearTimeout(loadedScriptEntry.timer); delete loadedScriptEntry.timer; } var pendingCallbackCount = loadedScriptEntry.pendingCallbacks.length; for (var i = 0; i < pendingCallbackCount; i++) { var currentCallback = loadedScriptEntry.pendingCallbacks.shift(); if (currentCallback) { var result = currentCallback(false); if (result === false) { break; } } } }; if (script.readyState) { script.onreadystatechange = function () { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; onLoadCallback(); } }; } else { script.onload = onLoadCallback; } script.onerror = onLoadError; timeoutInMs = timeoutInMs || this.defaultScriptLoadingTimeout; loadedScriptEntry.timer = setTimeout(onLoadError, timeoutInMs); loadedScriptEntry.hasStarted = true; script.setAttribute("crossOrigin", "anonymous"); script.src = url; doc.getElementsByTagName("head")[0].appendChild(script); } else if (loadedScriptEntry.isReady) { callback(true); } else { if (highPriority) { loadedScriptEntry.pendingCallbacks.unshift(callback); } else { loadedScriptEntry.pendingCallbacks.push(callback); } } } }; LoadScriptHelper.prototype.flushTelemetryBuffer = function () { if (OSF.AppTelemetry && OSF.AppTelemetry.onScriptDone) { for (var i = 0; i < this.scriptTelemetryBuffer.length; i++) { var scriptTelemetry = this.scriptTelemetryBuffer[i]; if (OSF.AppTelemetry.onScriptDone.length == 3) { OSF.AppTelemetry.onScriptDone(scriptTelemetry.scriptId, scriptTelemetry.startTime, scriptTelemetry.msResponseTime); } else { OSF.AppTelemetry.onScriptDone(scriptTelemetry.scriptId, scriptTelemetry.startTime, scriptTelemetry.msResponseTime, this.osfControlAppCorrelationId); } } this.scriptTelemetryBuffer = []; } }; return LoadScriptHelper; }()); ScriptLoading.LoadScriptHelper = LoadScriptHelper; })(ScriptLoading || (ScriptLoading = {})); var OfficeExt; (function (OfficeExt) { var HostName; (function (HostName) { var Host = (function () { function Host() { this.getDiagnostics = function _getDiagnostics(version) { var diagnostics = { host: this.getHost(), version: (version || this.getDefaultVersion()), platform: this.getPlatform() }; return diagnostics; }; this.platformRemappings = { web: Microsoft.Office.WebExtension.PlatformType.OfficeOnline, winrt: Microsoft.Office.WebExtension.PlatformType.Universal, win32: Microsoft.Office.WebExtension.PlatformType.PC, mac: Microsoft.Office.WebExtension.PlatformType.Mac, ios: Microsoft.Office.WebExtension.PlatformType.iOS, android: Microsoft.Office.WebExtension.PlatformType.Android }; this.camelCaseMappings = { powerpoint: Microsoft.Office.WebExtension.HostType.PowerPoint, onenote: Microsoft.Office.WebExtension.HostType.OneNote }; this.hostInfo = OSF._OfficeAppFactory.getHostInfo(); this.getHost = this.getHost.bind(this); this.getPlatform = this.getPlatform.bind(this); this.getDiagnostics = this.getDiagnostics.bind(this); } Host.prototype.capitalizeFirstLetter = function (input) { if (input) { return (input[0].toUpperCase() + input.slice(1).toLowerCase()); } return input; }; Host.getInstance = function () { if (Host.hostObj === undefined) { Host.hostObj = new Host(); } return Host.hostObj; }; Host.prototype.getPlatform = function (appNumber) { if (this.hostInfo.hostPlatform) { var hostPlatform = this.hostInfo.hostPlatform.toLowerCase(); if (this.platformRemappings[hostPlatform]) { return this.platformRemappings[hostPlatform]; } } return null; }; Host.prototype.getHost = function (appNumber) { if (this.hostInfo.hostType) { var hostType = this.hostInfo.hostType.toLowerCase(); if (this.camelCaseMappings[hostType]) { return this.camelCaseMappings[hostType]; } hostType = this.capitalizeFirstLetter(this.hostInfo.hostType); if (Microsoft.Office.WebExtension.HostType[hostType]) { return Microsoft.Office.WebExtension.HostType[hostType]; } } return null; }; Host.prototype.getDefaultVersion = function () { if (this.getHost()) { return "16.0.0000.0000"; } return null; }; return Host; }()); HostName.Host = Host; })(HostName = OfficeExt.HostName || (OfficeExt.HostName = {})); })(OfficeExt || (OfficeExt = {})); var Office; (function (Office) { var _Internal; (function (_Internal) { var PromiseImpl; (function (PromiseImpl) { function Init() { return (function () { "use strict"; function lib$es6$promise$utils$$objectOrFunction(x) { return typeof x === 'function' || (typeof x === 'object' && x !== null); } function lib$es6$promise$utils$$isFunction(x) { return typeof x === 'function'; } function lib$es6$promise$utils$$isMaybeThenable(x) { return typeof x === 'object' && x !== null; } var lib$es6$promise$utils$$_isArray; if (!Array.isArray) { lib$es6$promise$utils$$_isArray = function (x) { return Object.prototype.toString.call(x) === '[object Array]'; }; } else { lib$es6$promise$utils$$_isArray = Array.isArray; } var lib$es6$promise$utils$$isArray = lib$es6$promise$utils$$_isArray; var lib$es6$promise$asap$$len = 0; var lib$es6$promise$asap$$toString = {}.toString; var lib$es6$promise$asap$$vertxNext; var lib$es6$promise$asap$$customSchedulerFn; var lib$es6$promise$asap$$asap = function asap(callback, arg) { lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len] = callback; lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len + 1] = arg; lib$es6$promise$asap$$len += 2; if (lib$es6$promise$asap$$len === 2) { if (lib$es6$promise$asap$$customSchedulerFn) { lib$es6$promise$asap$$customSchedulerFn(lib$es6$promise$asap$$flush); } else { lib$es6$promise$asap$$scheduleFlush(); } } }; function lib$es6$promise$asap$$setScheduler(scheduleFn) { lib$es6$promise$asap$$customSchedulerFn = scheduleFn; } function lib$es6$promise$asap$$setAsap(asapFn) { lib$es6$promise$asap$$asap = asapFn; } var lib$es6$promise$asap$$browserWindow = (typeof window !== 'undefined') ? window : undefined; var lib$es6$promise$asap$$browserGlobal = lib$es6$promise$asap$$browserWindow || {}; var lib$es6$promise$asap$$BrowserMutationObserver = lib$es6$promise$asap$$browserGlobal.MutationObserver || lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver; var lib$es6$promise$asap$$isNode = typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; var lib$es6$promise$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; function lib$es6$promise$asap$$useNextTick() { var nextTick = process.nextTick; var version = process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/); if (Array.isArray(version) && version[1] === '0' && version[2] === '10') { nextTick = setImmediate; } return function () { nextTick(lib$es6$promise$asap$$flush); }; } function lib$es6$promise$asap$$useVertxTimer() { return function () { lib$es6$promise$asap$$vertxNext(lib$es6$promise$asap$$flush); }; } function lib$es6$promise$asap$$useMutationObserver() { var iterations = 0; var observer = new lib$es6$promise$asap$$BrowserMutationObserver(lib$es6$promise$asap$$flush); var node = document.createTextNode(''); observer.observe(node, { characterData: true }); return function () { node.data = (iterations = ++iterations % 2); }; } function lib$es6$promise$asap$$useMessageChannel() { var channel = new MessageChannel(); channel.port1.onmessage = lib$es6$promise$asap$$flush; return function () { channel.port2.postMessage(0); }; } function lib$es6$promise$asap$$useSetTimeout() { return function () { setTimeout(lib$es6$promise$asap$$flush, 1); }; } var lib$es6$promise$asap$$queue = new Array(1000); function lib$es6$promise$asap$$flush() { for (var i = 0; i < lib$es6$promise$asap$$len; i += 2) { var callback = lib$es6$promise$asap$$queue[i]; var arg = lib$es6$promise$asap$$queue[i + 1]; callback(arg); lib$es6$promise$asap$$queue[i] = undefined; lib$es6$promise$asap$$queue[i + 1] = undefined; } lib$es6$promise$asap$$len = 0; } var lib$es6$promise$asap$$scheduleFlush; if (lib$es6$promise$asap$$isNode) { lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useNextTick(); } else if (lib$es6$promise$asap$$isWorker) { lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMessageChannel(); } else { lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useSetTimeout(); } function lib$es6$promise$$internal$$noop() { } var lib$es6$promise$$internal$$PENDING = void 0; var lib$es6$promise$$internal$$FULFILLED = 1; var lib$es6$promise$$internal$$REJECTED = 2; var lib$es6$promise$$internal$$GET_THEN_ERROR = new lib$es6$promise$$internal$$ErrorObject(); function lib$es6$promise$$internal$$selfFullfillment() { return new TypeError("You cannot resolve a promise with itself"); } function lib$es6$promise$$internal$$cannotReturnOwn() { return new TypeError('A promises callback cannot return that same promise.'); } function lib$es6$promise$$internal$$getThen(promise) { try { return promise.then; } catch (error) { lib$es6$promise$$internal$$GET_THEN_ERROR.error = error; return lib$es6$promise$$internal$$GET_THEN_ERROR; } } function lib$es6$promise$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) { try { then.call(value, fulfillmentHandler, rejectionHandler); } catch (e) { return e; } } function lib$es6$promise$$internal$$handleForeignThenable(promise, thenable, then) { lib$es6$promise$asap$$asap(function (promise) { var sealed = false; var error = lib$es6$promise$$internal$$tryThen(then, thenable, function (value) { if (sealed) { return; } sealed = true; if (thenable !== value) { lib$es6$promise$$internal$$resolve(promise, value); } else { lib$es6$promise$$internal$$fulfill(promise, value); } }, function (reason) { if (sealed) { return; } sealed = true; lib$es6$promise$$internal$$reject(promise, reason); }, 'Settle: ' + (promise._label || ' unknown promise')); if (!sealed && error) { sealed = true; lib$es6$promise$$internal$$reject(promise, error); } }, promise); } function lib$es6$promise$$internal$$handleOwnThenable(promise, thenable) { if (thenable._state === lib$es6$promise$$internal$$FULFILLED) { lib$es6$promise$$internal$$fulfill(promise, thenable._result); } else if (thenable._state === lib$es6$promise$$internal$$REJECTED) { lib$es6$promise$$internal$$reject(promise, thenable._result); } else { lib$es6$promise$$internal$$subscribe(thenable, undefined, function (value) { lib$es6$promise$$internal$$resolve(promise, value); }, function (reason) { lib$es6$promise$$internal$$reject(promise, reason); }); } } function lib$es6$promise$$internal$$handleMaybeThenable(promise, maybeThenable) { if (maybeThenable.constructor === promise.constructor) { lib$es6$promise$$internal$$handleOwnThenable(promise, maybeThenable); } else { var then = lib$es6$promise$$internal$$getThen(maybeThenable); if (then === lib$es6$promise$$internal$$GET_THEN_ERROR) { lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$GET_THEN_ERROR.error); } else if (then === undefined) { lib$es6$promise$$internal$$fulfill(promise, maybeThenable); } else if (lib$es6$promise$utils$$isFunction(then)) { lib$es6$promise$$internal$$handleForeignThenable(promise, maybeThenable, then); } else { lib$es6$promise$$internal$$fulfill(promise, maybeThenable); } } } function lib$es6$promise$$internal$$resolve(promise, value) { if (promise === value) { lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$selfFullfillment()); } else if (lib$es6$promise$utils$$objectOrFunction(value)) { lib$es6$promise$$internal$$handleMaybeThenable(promise, value); } else { lib$es6$promise$$internal$$fulfill(promise, value); } } function lib$es6$promise$$internal$$publishRejection(promise) { if (promise._onerror) { promise._onerror(promise._result); } lib$es6$promise$$internal$$publish(promise); } function lib$es6$promise$$internal$$fulfill(promise, value) { if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; } promise._result = value; promise._state = lib$es6$promise$$internal$$FULFILLED; if (promise._subscribers.length !== 0) { lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, promise); } } function lib$es6$promise$$internal$$reject(promise, reason) { if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; } promise._state = lib$es6$promise$$internal$$REJECTED; promise._result = reason; lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publishRejection, promise); } function lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection) { var subscribers = parent._subscribers; var length = subscribers.length; parent._onerror = null; subscribers[length] = child; subscribers[length + lib$es6$promise$$internal$$FULFILLED] = onFulfillment; subscribers[length + lib$es6$promise$$internal$$REJECTED] = onRejection; if (length === 0 && parent._state) { lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, parent); } } function lib$es6$promise$$internal$$publish(promise) { var subscribers = promise._subscribers; var settled = promise._state; if (subscribers.length === 0) { return; } var child, callback, detail = promise._result; for (var i = 0; i < subscribers.length; i += 3) { child = subscribers[i]; callback = subscribers[i + settled]; if (child) { lib$es6$promise$$internal$$invokeCallback(settled, child, callback, detail); } else { callback(detail); } } promise._subscribers.length = 0; } function lib$es6$promise$$internal$$ErrorObject() { this.error = null; } var lib$es6$promise$$internal$$TRY_CATCH_ERROR = new lib$es6$promise$$internal$$ErrorObject(); function lib$es6$promise$$internal$$tryCatch(callback, detail) { try { return callback(detail); } catch (e) { lib$es6$promise$$internal$$TRY_CATCH_ERROR.error = e; return lib$es6$promise$$internal$$TRY_CATCH_ERROR; } } function lib$es6$promise$$internal$$invokeCallback(settled, promise, callback, detail) { var hasCallback = lib$es6$promise$utils$$isFunction(callback), value, error, succeeded, failed; if (hasCallback) { value = lib$es6$promise$$internal$$tryCatch(callback, detail); if (value === lib$es6$promise$$internal$$TRY_CATCH_ERROR) { failed = true; error = value.error; value = null; } else { succeeded = true; } if (promise === value) { lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$cannotReturnOwn()); return; } } else { value = detail; succeeded = true; } if (promise._state !== lib$es6$promise$$internal$$PENDING) { } else if (hasCallback && succeeded) { lib$es6$promise$$internal$$resolve(promise, value); } else if (failed) { lib$es6$promise$$internal$$reject(promise, error); } else if (settled === lib$es6$promise$$internal$$FULFILLED) { lib$es6$promise$$internal$$fulfill(promise, value); } else if (settled === lib$es6$promise$$internal$$REJECTED) { lib$es6$promise$$internal$$reject(promise, value); } } function lib$es6$promise$$internal$$initializePromise(promise, resolver) { try { resolver(function resolvePromise(value) { lib$es6$promise$$internal$$resolve(promise, value); }, function rejectPromise(reason) { lib$es6$promise$$internal$$reject(promise, reason); }); } catch (e) { lib$es6$promise$$internal$$reject(promise, e); } } function lib$es6$promise$enumerator$$Enumerator(Constructor, input) { var enumerator = this; enumerator._instanceConstructor = Constructor; enumerator.promise = new Constructor(lib$es6$promise$$internal$$noop); if (enumerator._validateInput(input)) { enumerator._input = input; enumerator.length = input.length; enumerator._remaining = input.length; enumerator._init(); if (enumerator.length === 0) { lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result); } else { enumerator.length = enumerator.length || 0; enumerator._enumerate(); if (enumerator._remaining === 0) { lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result); } } } else { lib$es6$promise$$internal$$reject(enumerator.promise, enumerator._validationError()); } } lib$es6$promise$enumerator$$Enumerator.prototype._validateInput = function (input) { return lib$es6$promise$utils$$isArray(input); }; lib$es6$promise$enumerator$$Enumerator.prototype._validationError = function () { return new Error('Array Methods must be provided an Array'); }; lib$es6$promise$enumerator$$Enumerator.prototype._init = function () { this._result = new Array(this.length); }; var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator; lib$es6$promise$enumerator$$Enumerator.prototype._enumerate = function () { var enumerator = this; var length = enumerator.length; var promise = enumerator.promise; var input = enumerator._input; for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) { enumerator._eachEntry(input[i], i); } }; lib$es6$promise$enumerator$$Enumerator.prototype._eachEntry = function (entry, i) { var enumerator = this; var c = enumerator._instanceConstructor; if (lib$es6$promise$utils$$isMaybeThenable(entry)) { if (entry.constructor === c && entry._state !== lib$es6$promise$$internal$$PENDING) { entry._onerror = null; enumerator._settledAt(entry._state, i, entry._result); } else { enumerator._willSettleAt(c.resolve(entry), i); } } else { enumerator._remaining--; enumerator._result[i] = entry; } }; lib$es6$promise$enumerator$$Enumerator.prototype._settledAt = function (state, i, value) { var enumerator = this; var promise = enumerator.promise; if (promise._state === lib$es6$promise$$internal$$PENDING) { enumerator._remaining--; if (state === lib$es6$promise$$internal$$REJECTED) { lib$es6$promise$$internal$$reject(promise, value); } else { enumerator._result[i] = value; } } if (enumerator._remaining === 0) { lib$es6$promise$$internal$$fulfill(promise, enumerator._result); } }; lib$es6$promise$enumerator$$Enumerator.prototype._willSettleAt = function (promise, i) { var enumerator = this; lib$es6$promise$$internal$$subscribe(promise, undefined, function (value) { enumerator._settledAt(lib$es6$promise$$internal$$FULFILLED, i, value); }, function (reason) { enumerator._settledAt(lib$es6$promise$$internal$$REJECTED, i, reason); }); }; function lib$es6$promise$promise$all$$all(entries) { return new lib$es6$promise$enumerator$$default(this, entries).promise; } var lib$es6$promise$promise$all$$default = lib$es6$promise$promise$all$$all; function lib$es6$promise$promise$race$$race(entries) { var Constructor = this; var promise = new Constructor(lib$es6$promise$$internal$$noop); if (!lib$es6$promise$utils$$isArray(entries)) { lib$es6$promise$$internal$$reject(promise, n