Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1// @ts-ignore2try {3 self['workbox:window:7.4.0'] && _();4} catch (e) {}5 6/*7 Copyright 2019 Google LLC8 9 Use of this source code is governed by an MIT-style10 license that can be found in the LICENSE file or at11 https://opensource.org/licenses/MIT.12*/13/**14 * Sends a data object to a service worker via `postMessage` and resolves with15 * a response (if any).16 *17 * A response can be set in a message handler in the service worker by18 * calling `event.ports[0].postMessage(...)`, which will resolve the promise19 * returned by `messageSW()`. If no response is set, the promise will not20 * resolve.21 *22 * @param {ServiceWorker} sw The service worker to send the message to.23 * @param {Object} data An object to send to the service worker.24 * @return {Promise<Object|undefined>}25 * @memberof workbox-window26 */27// Better not change type of data.28// eslint-disable-next-line @typescript-eslint/ban-types29function messageSW(sw, data) {30 return new Promise(function (resolve) {31 var messageChannel = new MessageChannel();32 messageChannel.port1.onmessage = function (event) {33 resolve(event.data);34 };35 sw.postMessage(data, [messageChannel.port2]);36 });37}38 39function _arrayLikeToArray(r, a) {40 (null == a || a > r.length) && (a = r.length);41 for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];42 return n;43}44function _defineProperties(e, r) {45 for (var t = 0; t < r.length; t++) {46 var o = r[t];47 o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);48 }49}50function _createClass(e, r, t) {51 return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {52 writable: false53 }), e;54}55function _createForOfIteratorHelperLoose(r, e) {56 var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];57 if (t) return (t = t.call(r)).next.bind(t);58 if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {59 t && (r = t);60 var o = 0;61 return function () {62 return o >= r.length ? {63 done: true64 } : {65 done: false,66 value: r[o++]67 };68 };69 }70 throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");71}72function _inheritsLoose(t, o) {73 t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);74}75function _setPrototypeOf(t, e) {76 return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {77 return t.__proto__ = e, t;78 }, _setPrototypeOf(t, e);79}80function _toPrimitive(t, r) {81 if ("object" != typeof t || !t) return t;82 var e = t[Symbol.toPrimitive];83 if (void 0 !== e) {84 var i = e.call(t, r);85 if ("object" != typeof i) return i;86 throw new TypeError("@@toPrimitive must return a primitive value.");87 }88 return (String )(t);89}90function _toPropertyKey(t) {91 var i = _toPrimitive(t, "string");92 return "symbol" == typeof i ? i : i + "";93}94function _unsupportedIterableToArray(r, a) {95 if (r) {96 if ("string" == typeof r) return _arrayLikeToArray(r, a);97 var t = {}.toString.call(r).slice(8, -1);98 return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;99 }100}101 102// @ts-ignore103try {104 self['workbox:core:7.4.0'] && _();105} catch (e) {}106 107/*108 Copyright 2018 Google LLC109 110 Use of this source code is governed by an MIT-style111 license that can be found in the LICENSE file or at112 https://opensource.org/licenses/MIT.113*/114/**115 * The Deferred class composes Promises in a way that allows for them to be116 * resolved or rejected from outside the constructor. In most cases promises117 * should be used directly, but Deferreds can be necessary when the logic to118 * resolve a promise must be separate.119 *120 * @private121 */122var Deferred =123/**124 * Creates a promise and exposes its resolve and reject functions as methods.125 */126function Deferred() {127 var _this = this;128 this.promise = new Promise(function (resolve, reject) {129 _this.resolve = resolve;130 _this.reject = reject;131 });132};133 134/*135 Copyright 2019 Google LLC136 Use of this source code is governed by an MIT-style137 license that can be found in the LICENSE file or at138 https://opensource.org/licenses/MIT.139*/140/**141 * A helper function that prevents a promise from being flagged as unused.142 *143 * @private144 **/145function dontWaitFor(promise) {146 // Effective no-op.147 void promise.then(function () {});148}149 150/*151 Copyright 2019 Google LLC152 Use of this source code is governed by an MIT-style153 license that can be found in the LICENSE file or at154 https://opensource.org/licenses/MIT.155*/156var logger = function () {157 // Don't overwrite this value if it's already set.158 // See https://github.com/GoogleChrome/workbox/pull/2284#issuecomment-560470923159 if (!('__WB_DISABLE_DEV_LOGS' in globalThis)) {160 self.__WB_DISABLE_DEV_LOGS = false;161 }162 var inGroup = false;163 var methodToColorMap = {164 debug: "#7f8c8d",165 log: "#2ecc71",166 warn: "#f39c12",167 error: "#c0392b",168 groupCollapsed: "#3498db",169 groupEnd: null // No colored prefix on groupEnd170 };171 var print = function print(method, args) {172 var _console2;173 if (self.__WB_DISABLE_DEV_LOGS) {174 return;175 }176 if (method === 'groupCollapsed') {177 // Safari doesn't print all console.groupCollapsed() arguments:178 // https://bugs.webkit.org/show_bug.cgi?id=182754179 if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {180 var _console;181 (_console = console)[method].apply(_console, args);182 return;183 }184 }185 var styles = ["background: " + methodToColorMap[method], "border-radius: 0.5em", "color: white", "font-weight: bold", "padding: 2px 0.5em"];186 // When in a group, the workbox prefix is not displayed.187 var logPrefix = inGroup ? [] : ['%cworkbox', styles.join(';')];188 (_console2 = console)[method].apply(_console2, logPrefix.concat(args));189 if (method === 'groupCollapsed') {190 inGroup = true;191 }192 if (method === 'groupEnd') {193 inGroup = false;194 }195 };196 // eslint-disable-next-line @typescript-eslint/ban-types197 var api = {};198 var loggerMethods = Object.keys(methodToColorMap);199 var _loop = function _loop() {200 var key = _loggerMethods[_i];201 var method = key;202 api[method] = function () {203 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {204 args[_key] = arguments[_key];205 }206 print(method, args);207 };208 };209 for (var _i = 0, _loggerMethods = loggerMethods; _i < _loggerMethods.length; _i++) {210 _loop();211 }212 return api;213}();214 215/*216 Copyright 2019 Google LLC217 218 Use of this source code is governed by an MIT-style219 license that can be found in the LICENSE file or at220 https://opensource.org/licenses/MIT.221*/222/**223 * A minimal `EventTarget` shim.224 * This is necessary because not all browsers support constructable225 * `EventTarget`, so using a real `EventTarget` will error.226 * @private227 */228var WorkboxEventTarget = /*#__PURE__*/function () {229 function WorkboxEventTarget() {230 this._eventListenerRegistry = new Map();231 }232 /**233 * @param {string} type234 * @param {Function} listener235 * @private236 */237 var _proto = WorkboxEventTarget.prototype;238 _proto.addEventListener = function addEventListener(type, listener) {239 var foo = this._getEventListenersByType(type);240 foo.add(listener);241 }242 /**243 * @param {string} type244 * @param {Function} listener245 * @private246 */;247 _proto.removeEventListener = function removeEventListener(type, listener) {248 this._getEventListenersByType(type).delete(listener);249 }250 /**251 * @param {Object} event252 * @private253 */;254 _proto.dispatchEvent = function dispatchEvent(event) {255 event.target = this;256 var listeners = this._getEventListenersByType(event.type);257 for (var _iterator = _createForOfIteratorHelperLoose(listeners), _step; !(_step = _iterator()).done;) {258 var listener = _step.value;259 listener(event);260 }261 }262 /**263 * Returns a Set of listeners associated with the passed event type.264 * If no handlers have been registered, an empty Set is returned.265 *266 * @param {string} type The event type.267 * @return {Set<ListenerCallback>} An array of handler functions.268 * @private269 */;270 _proto._getEventListenersByType = function _getEventListenersByType(type) {271 if (!this._eventListenerRegistry.has(type)) {272 this._eventListenerRegistry.set(type, new Set());273 }274 return this._eventListenerRegistry.get(type);275 };276 return WorkboxEventTarget;277}();278 279/*280 Copyright 2019 Google LLC281 282 Use of this source code is governed by an MIT-style283 license that can be found in the LICENSE file or at284 https://opensource.org/licenses/MIT.285*/286/**287 * Returns true if two URLs have the same `.href` property. The URLS can be288 * relative, and if they are the current location href is used to resolve URLs.289 *290 * @private291 * @param {string} url1292 * @param {string} url2293 * @return {boolean}294 */295function urlsMatch(url1, url2) {296 var _location = location,297 href = _location.href;298 return new URL(url1, href).href === new URL(url2, href).href;299}300 301/*302 Copyright 2019 Google LLC303 304 Use of this source code is governed by an MIT-style305 license that can be found in the LICENSE file or at306 https://opensource.org/licenses/MIT.307*/308/**309 * A minimal `Event` subclass shim.310 * This doesn't *actually* subclass `Event` because not all browsers support311 * constructable `EventTarget`, and using a real `Event` will error.312 * @private313 */314var WorkboxEvent = function WorkboxEvent(type, props) {315 this.type = type;316 Object.assign(this, props);317};318 319// The time a SW must be in the waiting phase before we can conclude320// `skipWaiting()` wasn't called. This 200 amount wasn't scientifically321// chosen, but it seems to avoid false positives in my testing.322 323function _await(value, then, direct) {324 if (!value || !value.then) {325 value = Promise.resolve(value);326 }327 return then ? value.then(then) : value;328}329var WAITING_TIMEOUT_DURATION = 200;330// The amount of time after a registration that we can reasonably conclude331// that the registration didn't trigger an update.332 333function _async(f) {334 return function () {335 for (var args = [], i = 0; i < arguments.length; i++) {336 args[i] = arguments[i];337 }338 try {339 return Promise.resolve(f.apply(this, args));340 } catch (e) {341 return Promise.reject(e);342 }343 };344}345var REGISTRATION_TIMEOUT_DURATION = 60000;346// The de facto standard message that a service worker should be listening for347// to trigger a call to skipWaiting().348 349function _empty() {}350var SKIP_WAITING_MESSAGE = {351 type: 'SKIP_WAITING'352};353/**354 * A class to aid in handling service worker registration, updates, and355 * reacting to service worker lifecycle events.356 *357 * @fires {@link workbox-window.Workbox#message}358 * @fires {@link workbox-window.Workbox#installed}359 * @fires {@link workbox-window.Workbox#waiting}360 * @fires {@link workbox-window.Workbox#controlling}361 * @fires {@link workbox-window.Workbox#activated}362 * @fires {@link workbox-window.Workbox#redundant}363 * @memberof workbox-window364 */365 366function _awaitIgnored(value, direct) {367 {368 return value && value.then ? value.then(_empty) : Promise.resolve();369 }370}371var Workbox = /*#__PURE__*/function (_WorkboxEventTarget) {372 /**373 * Creates a new Workbox instance with a script URL and service worker374 * options. The script URL and options are the same as those used when375 * calling [navigator.serviceWorker.register(scriptURL, options)](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register).376 *377 * @param {string|TrustedScriptURL} scriptURL The service worker script378 * associated with this instance. Using a379 * [`TrustedScriptURL`](https://web.dev/trusted-types/) is supported.380 * @param {Object} [registerOptions] The service worker options associated381 * with this instance.382 */383 // eslint-disable-next-line @typescript-eslint/ban-types384 function Workbox(scriptURL, registerOptions) {385 var _this;386 if (registerOptions === void 0) {387 registerOptions = {};388 }389 _this = _WorkboxEventTarget.call(this) || this;390 _this._registerOptions = {};391 _this._updateFoundCount = 0;392 // Deferreds we can resolve later.393 _this._swDeferred = new Deferred();394 _this._activeDeferred = new Deferred();395 _this._controllingDeferred = new Deferred();396 _this._registrationTime = 0;397 _this._ownSWs = new Set();398 /**399 * @private400 */401 _this._onUpdateFound = function () {402 // `this._registration` will never be `undefined` after an update is found.403 var registration = _this._registration;404 var installingSW = registration.installing;405 // If the script URL passed to `navigator.serviceWorker.register()` is406 // different from the current controlling SW's script URL, we know any407 // successful registration calls will trigger an `updatefound` event.408 // But if the registered script URL is the same as the current controlling409 // SW's script URL, we'll only get an `updatefound` event if the file410 // changed since it was last registered. This can be a problem if the user411 // opens up the same page in a different tab, and that page registers412 // a SW that triggers an update. It's a problem because this page has no413 // good way of knowing whether the `updatefound` event came from the SW414 // script it registered or from a registration attempt made by a newer415 // version of the page running in another tab.416 // To minimize the possibility of a false positive, we use the logic here:417 var updateLikelyTriggeredExternally =418 // Since we enforce only calling `register()` once, and since we don't419 // add the `updatefound` event listener until the `register()` call, if420 // `_updateFoundCount` is > 0 then it means this method has already421 // been called, thus this SW must be external422 _this._updateFoundCount > 0 ||423 // If the script URL of the installing SW is different from this424 // instance's script URL, we know it's definitely not from our425 // registration.426 !urlsMatch(installingSW.scriptURL, _this._scriptURL.toString()) ||427 // If all of the above are false, then we use a time-based heuristic:428 // Any `updatefound` event that occurs long after our registration is429 // assumed to be external.430 performance.now() > _this._registrationTime + REGISTRATION_TIMEOUT_DURATION ?431 // If any of the above are not true, we assume the update was432 // triggered by this instance.433 true : false;434 if (updateLikelyTriggeredExternally) {435 _this._externalSW = installingSW;436 registration.removeEventListener('updatefound', _this._onUpdateFound);437 } else {438 // If the update was not triggered externally we know the installing439 // SW is the one we registered, so we set it.440 _this._sw = installingSW;441 _this._ownSWs.add(installingSW);442 _this._swDeferred.resolve(installingSW);443 // The `installing` state isn't something we have a dedicated444 // callback for, but we do log messages for it in development.445 {446 if (navigator.serviceWorker.controller) {447 logger.log('Updated service worker found. Installing now...');448 } else {449 logger.log('Service worker is installing...');450 }451 }452 }453 // Increment the `updatefound` count, so future invocations of this454 // method can be sure they were triggered externally.455 ++_this._updateFoundCount;456 // Add a `statechange` listener regardless of whether this update was457 // triggered externally, since we have callbacks for both.458 installingSW.addEventListener('statechange', _this._onStateChange);459 };460 /**461 * @private462 * @param {Event} originalEvent463 */464 _this._onStateChange = function (originalEvent) {465 // `this._registration` will never be `undefined` after an update is found.466 var registration = _this._registration;467 var sw = originalEvent.target;468 var state = sw.state;469 var isExternal = sw === _this._externalSW;470 var eventProps = {471 sw: sw,472 isExternal: isExternal,473 originalEvent: originalEvent474 };475 if (!isExternal && _this._isUpdate) {476 eventProps.isUpdate = true;477 }478 _this.dispatchEvent(new WorkboxEvent(state, eventProps));479 if (state === 'installed') {480 // This timeout is used to ignore cases where the service worker calls481 // `skipWaiting()` in the install event, thus moving it directly in the482 // activating state. (Since all service workers *must* go through the483 // waiting phase, the only way to detect `skipWaiting()` called in the484 // install event is to observe that the time spent in the waiting phase485 // is very short.)486 // NOTE: we don't need separate timeouts for the own and external SWs487 // since they can't go through these phases at the same time.488 _this._waitingTimeout = self.setTimeout(function () {489 // Ensure the SW is still waiting (it may now be redundant).490 if (state === 'installed' && registration.waiting === sw) {491 _this.dispatchEvent(new WorkboxEvent('waiting', eventProps));492 {493 if (isExternal) {494 logger.warn('An external service worker has installed but is ' + 'waiting for this client to close before activating...');495 } else {496 logger.warn('The service worker has installed but is waiting ' + 'for existing clients to close before activating...');497 }498 }499 }500 }, WAITING_TIMEOUT_DURATION);501 } else if (state === 'activating') {502 clearTimeout(_this._waitingTimeout);503 if (!isExternal) {504 _this._activeDeferred.resolve(sw);505 }506 }507 {508 switch (state) {509 case 'installed':510 if (isExternal) {511 logger.warn('An external service worker has installed. ' + 'You may want to suggest users reload this page.');512 } else {513 logger.log('Registered service worker installed.');514 }515 break;516 case 'activated':517 if (isExternal) {518 logger.warn('An external service worker has activated.');519 } else {520 logger.log('Registered service worker activated.');521 if (sw !== navigator.serviceWorker.controller) {522 logger.warn('The registered service worker is active but ' + 'not yet controlling the page. Reload or run ' + '`clients.claim()` in the service worker.');523 }524 }525 break;526 case 'redundant':527 if (sw === _this._compatibleControllingSW) {528 logger.log('Previously controlling service worker now redundant!');529 } else if (!isExternal) {530 logger.log('Registered service worker now redundant!');531 }532 break;533 }534 }535 };536 /**537 * @private538 * @param {Event} originalEvent539 */540 _this._onControllerChange = function (originalEvent) {541 var sw = _this._sw;542 var isExternal = sw !== navigator.serviceWorker.controller;543 // Unconditionally dispatch the controlling event, with isExternal set544 // to distinguish between controller changes due to the initial registration545 // vs. an update-check or other tab's registration.546 // See https://github.com/GoogleChrome/workbox/issues/2786547 _this.dispatchEvent(new WorkboxEvent('controlling', {548 isExternal: isExternal,549 originalEvent: originalEvent,550 sw: sw,551 isUpdate: _this._isUpdate552 }));553 if (!isExternal) {554 {555 logger.log('Registered service worker now controlling this page.');556 }557 _this._controllingDeferred.resolve(sw);558 }559 };560 /**561 * @private562 * @param {Event} originalEvent563 */564 _this._onMessage = _async(function (originalEvent) {565 // Can't change type 'any' of data.566 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment567 var data = originalEvent.data,568 ports = originalEvent.ports,569 source = originalEvent.source;570 // Wait until there's an "own" service worker. This is used to buffer571 // `message` events that may be received prior to calling `register()`.572 return _await(_this.getSW(), function () {573 if (_this._ownSWs.has(source)) {574 _this.dispatchEvent(new WorkboxEvent('message', {575 // Can't change type 'any' of data.576 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment577 data: data,578 originalEvent: originalEvent,579 ports: ports,580 sw: source581 }));582 }583 }); // If the service worker that sent the message is in the list of own584 // service workers for this instance, dispatch a `message` event.585 // NOTE: we check for all previously owned service workers rather than586 // just the current one because some messages (e.g. cache updates) use587 // a timeout when sent and may be delayed long enough for a service worker588 // update to be found.589 });590 _this._scriptURL = scriptURL;591 _this._registerOptions = registerOptions;592 // Add a message listener immediately since messages received during593 // page load are buffered only until the DOMContentLoaded event:594 // https://github.com/GoogleChrome/workbox/issues/2202595 navigator.serviceWorker.addEventListener('message', _this._onMessage);596 return _this;597 }598 /**599 * Registers a service worker for this instances script URL and service600 * worker options. By default this method delays registration until after601 * the window has loaded.602 *603 * @param {Object} [options]604 * @param {Function} [options.immediate=false] Setting this to true will605 * register the service worker immediately, even if the window has606 * not loaded (not recommended).607 */608 _inheritsLoose(Workbox, _WorkboxEventTarget);609 var _proto = Workbox.prototype;610 _proto.register = function register(_temp) {611 var _ref = _temp === void 0 ? {} : _temp,612 _ref$immediate = _ref.immediate,613 immediate = _ref$immediate === void 0 ? false : _ref$immediate;614 try {615 var _this2 = this;616 if ("dev" !== 'production') {617 if (_this2._registrationTime) {618 logger.error('Cannot re-register a Workbox instance after it has ' + 'been registered. Create a new instance instead.');619 return _await();620 }621 }622 return _await(_invoke(function () {623 if (!immediate && document.readyState !== 'complete') {624 return _awaitIgnored(new Promise(function (res) {625 return window.addEventListener('load', res);626 }));627 }628 }, function () {629 // Set this flag to true if any service worker was controlling the page630 // at registration time.631 _this2._isUpdate = Boolean(navigator.serviceWorker.controller);632 // Before registering, attempt to determine if a SW is already controlling633 // the page, and if that SW script (and version, if specified) matches this634 // instance's script.635 _this2._compatibleControllingSW = _this2._getControllingSWIfCompatible();636 return _await(_this2._registerScript(), function (_this2$_registerScrip) {637 _this2._registration = _this2$_registerScrip;638 // If we have a compatible controller, store the controller as the "own"639 // SW, resolve active/controlling deferreds and add necessary listeners.640 if (_this2._compatibleControllingSW) {641 _this2._sw = _this2._compatibleControllingSW;642 _this2._activeDeferred.resolve(_this2._compatibleControllingSW);643 _this2._controllingDeferred.resolve(_this2._compatibleControllingSW);644 _this2._compatibleControllingSW.addEventListener('statechange', _this2._onStateChange, {645 once: true646 });647 }648 // If there's a waiting service worker with a matching URL before the649 // `updatefound` event fires, it likely means that this site is open650 // in another tab, or the user refreshed the page (and thus the previous651 // page wasn't fully unloaded before this page started loading).652 // https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#waiting653 var waitingSW = _this2._registration.waiting;654 if (waitingSW && urlsMatch(waitingSW.scriptURL, _this2._scriptURL.toString())) {655 // Store the waiting SW as the "own" Sw, even if it means overwriting656 // a compatible controller.657 _this2._sw = waitingSW;658 // Run this in the next microtask, so any code that adds an event659 // listener after awaiting `register()` will get this event.660 dontWaitFor(Promise.resolve().then(function () {661 _this2.dispatchEvent(new WorkboxEvent('waiting', {662 sw: waitingSW,663 wasWaitingBeforeRegister: true664 }));665 if ("dev" !== 'production') {666 logger.warn('A service worker was already waiting to activate ' + 'before this script was registered...');667 }668 }));669 }670 // If an "own" SW is already set, resolve the deferred.671 if (_this2._sw) {672 _this2._swDeferred.resolve(_this2._sw);673 _this2._ownSWs.add(_this2._sw);674 }675 if ("dev" !== 'production') {676 logger.log('Successfully registered service worker.', _this2._scriptURL.toString());677 if (navigator.serviceWorker.controller) {678 if (_this2._compatibleControllingSW) {679 logger.debug('A service worker with the same script URL ' + 'is already controlling this page.');680 } else {681 logger.debug('A service worker with a different script URL is ' + 'currently controlling the page. The browser is now fetching ' + 'the new script now...');682 }683 }684 var currentPageIsOutOfScope = function currentPageIsOutOfScope() {685 var scopeURL = new URL(_this2._registerOptions.scope || _this2._scriptURL.toString(), document.baseURI);686 var scopeURLBasePath = new URL('./', scopeURL.href).pathname;687 return !location.pathname.startsWith(scopeURLBasePath);688 };689 if (currentPageIsOutOfScope()) {690 logger.warn('The current page is not in scope for the registered ' + 'service worker. Was this a mistake?');691 }692 }693 _this2._registration.addEventListener('updatefound', _this2._onUpdateFound);694 navigator.serviceWorker.addEventListener('controllerchange', _this2._onControllerChange);695 return _this2._registration;696 });697 }));698 } catch (e) {699 return Promise.reject(e);700 }701 }702 /**703 * Checks for updates of the registered service worker.704 */705 ;706 _proto.update = function update() {707 try {708 var _this3 = this;709 if (!_this3._registration) {710 if ("dev" !== 'production') {711 logger.error('Cannot update a Workbox instance without ' + 'being registered. Register the Workbox instance first.');712 }713 return _await();714 }715 // Try to update registration716 return _await(_awaitIgnored(_this3._registration.update()));717 } catch (e) {718 return Promise.reject(e);719 }720 }721 /**722 * Resolves to the service worker registered by this instance as soon as it723 * is active. If a service worker was already controlling at registration724 * time then it will resolve to that if the script URLs (and optionally725 * script versions) match, otherwise it will wait until an update is found726 * and activates.727 *728 * @return {Promise<ServiceWorker>}729 */730 ;731 /**732 * Resolves with a reference to a service worker that matches the script URL733 * of this instance, as soon as it's available.734 *735 * If, at registration time, there's already an active or waiting service736 * worker with a matching script URL, it will be used (with the waiting737 * service worker taking precedence over the active service worker if both738 * match, since the waiting service worker would have been registered more739 * recently).740 * If there's no matching active or waiting service worker at registration741 * time then the promise will not resolve until an update is found and starts742 * installing, at which point the installing service worker is used.743 *744 * @return {Promise<ServiceWorker>}745 */746 _proto.getSW = function getSW() {747 // If `this._sw` is set, resolve with that as we want `getSW()` to748 // return the correct (new) service worker if an update is found.749 return this._sw !== undefined ? Promise.resolve(this._sw) : this._swDeferred.promise;750 }751 /**752 * Sends the passed data object to the service worker registered by this753 * instance (via {@link workbox-window.Workbox#getSW}) and resolves754 * with a response (if any).755 *756 * A response can be set in a message handler in the service worker by757 * calling `event.ports[0].postMessage(...)`, which will resolve the promise758 * returned by `messageSW()`. If no response is set, the promise will never759 * resolve.760 *761 * @param {Object} data An object to send to the service worker762 * @return {Promise<Object>}763 */764 // We might be able to change the 'data' type to Record<string, unknown> in the future.765 // eslint-disable-next-line @typescript-eslint/ban-types766 ;767 _proto.messageSW = function messageSW$1(data) {768 try {769 var _this4 = this;770 return _await(_this4.getSW(), function (sw) {771 return messageSW(sw, data);772 });773 } catch (e) {774 return Promise.reject(e);775 }776 }777 /**778 * Sends a `{type: 'SKIP_WAITING'}` message to the service worker that's779 * currently in the `waiting` state associated with the current registration.780 *781 * If there is no current registration or no service worker is `waiting`,782 * calling this will have no effect.783 */784 ;785 _proto.messageSkipWaiting = function messageSkipWaiting() {786 if (this._registration && this._registration.waiting) {787 void messageSW(this._registration.waiting, SKIP_WAITING_MESSAGE);788 }789 }790 /**791 * Checks for a service worker already controlling the page and returns792 * it if its script URL matches.793 *794 * @private795 * @return {ServiceWorker|undefined}796 */;797 _proto._getControllingSWIfCompatible = function _getControllingSWIfCompatible() {798 var controller = navigator.serviceWorker.controller;799 if (controller && urlsMatch(controller.scriptURL, this._scriptURL.toString())) {800 return controller;801 } else {802 return undefined;803 }804 }805 /**806 * Registers a service worker for this instances script URL and register807 * options and tracks the time registration was complete.808 *809 * @private810 */;811 _proto._registerScript = function _registerScript() {812 try {813 var _this5 = this;814 return _await(_catch(function () {815 // this._scriptURL may be a TrustedScriptURL, but there's no support for816 // passing that to register() in lib.dom right now.817 // https://github.com/GoogleChrome/workbox/issues/2855818 return _await(navigator.serviceWorker.register(_this5._scriptURL, _this5._registerOptions), function (reg) {819 // Keep track of when registration happened, so it can be used in the820 // `this._onUpdateFound` heuristic. Also use the presence of this821 // property as a way to see if `.register()` has been called.822 _this5._registrationTime = performance.now();823 return reg;824 });825 }, function (error) {826 if ("dev" !== 'production') {827 logger.error(error);828 }829 // Re-throw the error.830 throw error;831 }));832 } catch (e) {833 return Promise.reject(e);834 }835 };836 return _createClass(Workbox, [{837 key: "active",838 get: function get() {839 return this._activeDeferred.promise;840 }841 /**842 * Resolves to the service worker registered by this instance as soon as it843 * is controlling the page. If a service worker was already controlling at844 * registration time then it will resolve to that if the script URLs (and845 * optionally script versions) match, otherwise it will wait until an update846 * is found and starts controlling the page.847 * Note: the first time a service worker is installed it will active but848 * not start controlling the page unless `clients.claim()` is called in the849 * service worker.850 *851 * @return {Promise<ServiceWorker>}852 */853 }, {854 key: "controlling",855 get: function get() {856 return this._controllingDeferred.promise;857 }858 }]);859}(WorkboxEventTarget);860function _invoke(body, then) {861 var result = body();862 if (result && result.then) {863 return result.then(then);864 }865 return then(result);866} // The jsdoc comments below outline the events this instance may dispatch:867// -----------------------------------------------------------------------868/**869 * The `message` event is dispatched any time a `postMessage` is received.870 *871 * @event workbox-window.Workbox#message872 * @type {WorkboxEvent}873 * @property {*} data The `data` property from the original `message` event.874 * @property {Event} originalEvent The original [`message`]{@link https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent}875 * event.876 * @property {string} type `message`.877 * @property {MessagePort[]} ports The `ports` value from `originalEvent`.878 * @property {Workbox} target The `Workbox` instance.879 */880/**881 * The `installed` event is dispatched if the state of a882 * {@link workbox-window.Workbox} instance's883 * {@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw|registered service worker}884 * changes to `installed`.885 *886 * Then can happen either the very first time a service worker is installed,887 * or after an update to the current service worker is found. In the case888 * of an update being found, the event's `isUpdate` property will be `true`.889 *890 * @event workbox-window.Workbox#installed891 * @type {WorkboxEvent}892 * @property {ServiceWorker} sw The service worker instance.893 * @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}894 * event.895 * @property {boolean|undefined} isUpdate True if a service worker was already896 * controlling when this `Workbox` instance called `register()`.897 * @property {boolean|undefined} isExternal True if this event is associated898 * with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.899 * @property {string} type `installed`.900 * @property {Workbox} target The `Workbox` instance.901 */902/**903 * The `waiting` event is dispatched if the state of a904 * {@link workbox-window.Workbox} instance's905 * [registered service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw}906 * changes to `installed` and then doesn't immediately change to `activating`.907 * It may also be dispatched if a service worker with the same908 * [`scriptURL`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/scriptURL}909 * was already waiting when the {@link workbox-window.Workbox#register}910 * method was called.911 *912 * @event workbox-window.Workbox#waiting913 * @type {WorkboxEvent}914 * @property {ServiceWorker} sw The service worker instance.915 * @property {Event|undefined} originalEvent The original916 * [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}917 * event, or `undefined` in the case where the service worker was waiting918 * to before `.register()` was called.919 * @property {boolean|undefined} isUpdate True if a service worker was already920 * controlling when this `Workbox` instance called `register()`.921 * @property {boolean|undefined} isExternal True if this event is associated922 * with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.923 * @property {boolean|undefined} wasWaitingBeforeRegister True if a service worker with924 * a matching `scriptURL` was already waiting when this `Workbox`925 * instance called `register()`.926 * @property {string} type `waiting`.927 * @property {Workbox} target The `Workbox` instance.928 */929/**930 * The `controlling` event is dispatched if a931 * [`controllerchange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/oncontrollerchange}932 * fires on the service worker [container]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer}933 * and the [`scriptURL`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/scriptURL}934 * of the new [controller]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/controller}935 * matches the `scriptURL` of the `Workbox` instance's936 * [registered service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw}.937 *938 * @event workbox-window.Workbox#controlling939 * @type {WorkboxEvent}940 * @property {ServiceWorker} sw The service worker instance.941 * @property {Event} originalEvent The original [`controllerchange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/oncontrollerchange}942 * event.943 * @property {boolean|undefined} isUpdate True if a service worker was already944 * controlling when this service worker was registered.945 * @property {boolean|undefined} isExternal True if this event is associated946 * with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.947 * @property {string} type `controlling`.948 * @property {Workbox} target The `Workbox` instance.949 */950/**951 * The `activated` event is dispatched if the state of a952 * {@link workbox-window.Workbox} instance's953 * {@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw|registered service worker}954 * changes to `activated`.955 *956 * @event workbox-window.Workbox#activated957 * @type {WorkboxEvent}958 * @property {ServiceWorker} sw The service worker instance.959 * @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}960 * event.961 * @property {boolean|undefined} isUpdate True if a service worker was already962 * controlling when this `Workbox` instance called `register()`.963 * @property {boolean|undefined} isExternal True if this event is associated964 * with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.965 * @property {string} type `activated`.966 * @property {Workbox} target The `Workbox` instance.967 */968/**969 * The `redundant` event is dispatched if the state of a970 * {@link workbox-window.Workbox} instance's971 * [registered service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw}972 * changes to `redundant`.973 *974 * @event workbox-window.Workbox#redundant975 * @type {WorkboxEvent}976 * @property {ServiceWorker} sw The service worker instance.977 * @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}978 * event.979 * @property {boolean|undefined} isUpdate True if a service worker was already980 * controlling when this `Workbox` instance called `register()`.981 * @property {string} type `redundant`.982 * @property {Workbox} target The `Workbox` instance.983 */984function _catch(body, recover) {985 try {986 var result = body();987 } catch (e) {988 return recover(e);989 }990 if (result && result.then) {991 return result.then(void 0, recover);992 }993 return result;994}995 996export { Workbox, WorkboxEvent, messageSW };997//# sourceMappingURL=workbox-window.dev.es5.mjs.map998 