// ==UserScript==
// @name Say, Pi
// @name:zh-CN 说,Pi
// @namespace http://www.saypi.ai/
// @version 1.4.8
// @description Speak to Pi with accurate, hands-free conversations powered by OpenAI's Whisper
// @description:zh-CN 使用OpenAI的Whisper与Pi对话
// @author Ross Cadogan
// @match https://pi.ai/talk
// @inject-into page
// @license MIT
// ==/UserScript==
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ 9136:
/***/ ((module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Z: () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7537);
/* harmony import */ var _node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3645);
/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__);
// Imports
var ___CSS_LOADER_EXPORT___ = _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default()((_node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default()));
// Module
___CSS_LOADER_EXPORT___.push([module.id, `@keyframes pulse_outermost {
0%,
100% {
transform: scale(1);
}
50% {
transform: scale(0.92);
}
}
.outermost {
animation: pulse_outermost 5s infinite;
transform-origin: center;
}
@keyframes pulse_second {
0%,
100% {
transform: scale(1);
}
50% {
transform: scale(0.856);
}
}
.second {
animation: pulse_second 5s infinite;
transform-origin: center;
}
@keyframes pulse_third {
0%,
100% {
transform: scale(1);
}
50% {
transform: scale(0.792);
}
}
.third {
animation: pulse_third 5s infinite;
transform-origin: center;
}
@keyframes pulse_fourth {
0%,
100% {
transform: scale(1);
}
50% {
transform: scale(0.728);
}
}
.fourth {
animation: pulse_fourth 5s infinite;
transform-origin: center;
}
@keyframes pulse_fifth {
0%,
100% {
transform: scale(1);
}
50% {
transform: scale(0.664);
}
}
.fifth {
animation: pulse_fifth 5s infinite;
transform-origin: center;
}
@keyframes pulse_innermost {
0%,
100% {
transform: scale(1);
}
50% {
transform: scale(0.6);
}
}
.innermost {
animation: pulse_innermost 5s infinite;
transform-origin: center;
}
/* playful animation to indicate Pi is speaking */
@keyframes speaking_outermost {
0%,
100% {
transform: scale(1) rotate(0deg);
}
25% {
transform: scale(0.995);
}
50% {
transform: scale(0.9);
}
75% {
transform: scale(0.895);
}
}
.outermost.piSpeaking {
animation: speaking_outermost 2s infinite;
transform-origin: center;
}
@keyframes speaking_second {
0%,
100% {
transform: scale(1) rotate(0deg);
}
25% {
transform: scale(0.98) rotate(-1deg);
}
50% {
transform: scale(0.87) rotate(0deg);
}
75% {
transform: scale(0.865) rotate(1deg);
}
}
.second.piSpeaking {
animation: speaking_second 2s infinite;
transform-origin: center;
}
@keyframes speaking_third {
0%,
100% {
transform: scale(1) rotate(0deg);
}
25% {
transform: scale(0.965) rotate(-2deg);
}
50% {
transform: scale(0.84) rotate(0deg);
}
75% {
transform: scale(0.835) rotate(2deg);
}
}
.third.piSpeaking {
animation: speaking_third 2s infinite;
transform-origin: center;
}
@keyframes speaking_fourth {
0%,
100% {
transform: scale(1) rotate(0deg);
}
25% {
transform: scale(0.95) rotate(-3deg);
}
50% {
transform: scale(0.81) rotate(0deg);
}
75% {
transform: scale(0.805) rotate(3deg);
}
}
.fourth.piSpeaking {
animation: speaking_fourth 2s infinite;
transform-origin: center;
}
@keyframes speaking_fifth {
0%,
100% {
transform: scale(1) rotate(0deg);
}
25% {
transform: scale(0.935) rotate(-4deg);
}
50% {
transform: scale(0.78) rotate(0deg);
}
75% {
transform: scale(0.775) rotate(4deg);
}
}
.fifth.piSpeaking {
animation: speaking_fifth 2s infinite;
transform-origin: center;
}
@keyframes speaking_innermost {
0%,
100% {
transform: scale(1) rotate(0deg);
}
25% {
transform: scale(0.92) rotate(-5deg);
}
50% {
transform: scale(0.75) rotate(0deg);
}
75% {
transform: scale(0.745) rotate(5deg);
}
}
.innermost.piSpeaking {
animation: speaking_innermost 2s infinite;
transform-origin: center;
}
/* wave animation to indicate user is speaking */
@keyframes userSpeakingAnimation {
50% {
transform: scaleY(0.05) scaleX(var(--width-factor))
translateX(calc(-50% + var(--spread-amount)));
}
100% {
transform: scaleY(1) scaleX(var(--width-factor))
translateX(calc(-50% + var(--spread-amount)));
}
}
/* user speaking oscillation animation */
@keyframes waveform_outermost {
0%,
100% {
transform: scaleY(1) scaleX(1);
}
25%,
75% {
transform: scaleY(0.9) scaleX(0.9);
}
}
@keyframes waveform_second {
0%,
100% {
transform: scaleY(0.9) scaleX(0.9);
}
25%,
75% {
transform: scaleY(0.8) scaleX(0.8);
}
}
@keyframes waveform_third {
0%,
100% {
transform: scaleY(0.8) scaleX(0.8);
}
25%,
75% {
transform: scaleY(0.7) scaleX(0.7);
}
}
@keyframes waveform_fourth {
0%,
100% {
transform: scaleY(0.7) scaleX(0.7);
}
25%,
75% {
transform: scaleY(0.6) scaleX(0.6);
}
}
@keyframes waveform_fifth {
0%,
100% {
transform: scaleY(0.6) scaleX(0.6);
}
25%,
75% {
transform: scaleY(0.5) scaleX(0.5);
}
}
@keyframes waveform_innermost {
0%,
100% {
transform: scaleY(0.5) scaleX(0.5);
}
25%,
75% {
transform: scaleY(0.4) scaleX(0.4);
}
}
.outermost.userSpeaking {
animation: waveform_outermost 0.7s infinite alternate;
}
.second.userSpeaking {
animation: waveform_second 0.65s infinite alternate;
}
.third.userSpeaking {
animation: waveform_third 0.6s infinite alternate;
}
.fourth.userSpeaking {
animation: waveform_fourth 0.55s infinite alternate;
}
.fifth.userSpeaking {
animation: waveform_fifth 0.5s infinite alternate;
}
.innermost.userSpeaking {
animation: waveform_innermost 0.45s infinite alternate;
}
/* flipcard animation to indicate Say, Pi is transcribing audio to text */
@keyframes transcribingFlip {
0%,
100% {
transform: rotateY(0deg);
fill: var(--original-color);
}
50% {
transform: rotateY(180deg);
fill: var(--transcribing-color);
}
}
.outermost.transcribing {
--original-color: #e4f2d1;
--transcribing-color: #b3e0fe;
animation: transcribingFlip 1.5s infinite;
}
.second.transcribing {
--original-color: #cce8b5;
--transcribing-color: #89c2ff;
animation: transcribingFlip 1.6s infinite;
}
.third.transcribing {
--original-color: #b3db95;
--transcribing-color: #5fa4ff;
animation: transcribingFlip 1.7s infinite;
}
.fourth.transcribing {
--original-color: #9bd078;
--transcribing-color: #3586ff;
animation: transcribingFlip 1.8s infinite;
}
.fifth.transcribing {
--original-color: #83c55c;
--transcribing-color: #0b69e3;
animation: transcribingFlip 1.9s infinite;
}
.innermost.transcribing {
--original-color: #428a2f;
--transcribing-color: #0053bf;
animation: transcribingFlip 2s infinite;
}
/* heartbeat animation to indicate Pi is preparing to speak */
@keyframes heartbeat {
0%,
100% {
opacity: 1;
fill: var(--original-color);
}
50% {
opacity: 0.5;
fill: rgb(245 238 223); /* bg-cream-550 */
}
}
/* toned-down dissary animation to indicate an error */
/* toned-down error animation with reduced opacity */
@keyframes errorAnimation {
0% {
transform: rotate(0deg) translate(0%, 0%);
}
25% {
transform: rotate(-5deg) translate(-5%, 5%);
}
50% {
transform: rotate(5deg) translate(5%, -5%);
}
75% {
transform: rotate(-5deg) translate(-5%, 5%);
}
100% {
transform: rotate(0deg) translate(0%, 0%);
}
}
.outermost.error {
animation: errorAnimation 25s 1;
fill: #ff0000;
fill-opacity: 0.7;
}
.second.error {
animation: errorAnimation 25s 1;
fill: #ff3300;
fill-opacity: 0.7;
}
.third.error {
animation: errorAnimation 25s 1;
fill: #ff6600;
fill-opacity: 0.7;
}
.fourth.error {
animation: errorAnimation 25s 1;
fill: #ff9900;
fill-opacity: 0.7;
}
.fifth.error {
animation: errorAnimation 25s 1;
fill: #ffcc00;
fill-opacity: 0.7;
}
.innermost.error {
animation: errorAnimation 25s 1;
fill: #ffff00;
fill-opacity: 0.7;
}
`, "",{"version":3,"sources":["webpack://./src/styles/rectangles.css"],"names":[],"mappings":"AAAA;EACE;;IAEE,mBAAmB;EACrB;EACA;IACE,sBAAsB;EACxB;AACF;AACA;EACE,sCAAsC;EACtC,wBAAwB;AAC1B;;AAEA;EACE;;IAEE,mBAAmB;EACrB;EACA;IACE,uBAAuB;EACzB;AACF;AACA;EACE,mCAAmC;EACnC,wBAAwB;AAC1B;;AAEA;EACE;;IAEE,mBAAmB;EACrB;EACA;IACE,uBAAuB;EACzB;AACF;AACA;EACE,kCAAkC;EAClC,wBAAwB;AAC1B;;AAEA;EACE;;IAEE,mBAAmB;EACrB;EACA;IACE,uBAAuB;EACzB;AACF;AACA;EACE,mCAAmC;EACnC,wBAAwB;AAC1B;;AAEA;EACE;;IAEE,mBAAmB;EACrB;EACA;IACE,uBAAuB;EACzB;AACF;AACA;EACE,kCAAkC;EAClC,wBAAwB;AAC1B;;AAEA;EACE;;IAEE,mBAAmB;EACrB;EACA;IACE,qBAAqB;EACvB;AACF;AACA;EACE,sCAAsC;EACtC,wBAAwB;AAC1B;;AAEA,iDAAiD;AACjD;EACE;;IAEE,gCAAgC;EAClC;EACA;IACE,uBAAuB;EACzB;EACA;IACE,qBAAqB;EACvB;EACA;IACE,uBAAuB;EACzB;AACF;AACA;EACE,yCAAyC;EACzC,wBAAwB;AAC1B;;AAEA;EACE;;IAEE,gCAAgC;EAClC;EACA;IACE,oCAAoC;EACtC;EACA;IACE,mCAAmC;EACrC;EACA;IACE,oCAAoC;EACtC;AACF;AACA;EACE,sCAAsC;EACtC,wBAAwB;AAC1B;;AAEA;EACE;;IAEE,gCAAgC;EAClC;EACA;IACE,qCAAqC;EACvC;EACA;IACE,mCAAmC;EACrC;EACA;IACE,oCAAoC;EACtC;AACF;AACA;EACE,qCAAqC;EACrC,wBAAwB;AAC1B;;AAEA;EACE;;IAEE,gCAAgC;EAClC;EACA;IACE,oCAAoC;EACtC;EACA;IACE,mCAAmC;EACrC;EACA;IACE,oCAAoC;EACtC;AACF;AACA;EACE,sCAAsC;EACtC,wBAAwB;AAC1B;;AAEA;EACE;;IAEE,gCAAgC;EAClC;EACA;IACE,qCAAqC;EACvC;EACA;IACE,mCAAmC;EACrC;EACA;IACE,oCAAoC;EACtC;AACF;AACA;EACE,qCAAqC;EACrC,wBAAwB;AAC1B;;AAEA;EACE;;IAEE,gCAAgC;EAClC;EACA;IACE,oCAAoC;EACtC;EACA;IACE,mCAAmC;EACrC;EACA;IACE,oCAAoC;EACtC;AACF;AACA;EACE,yCAAyC;EACzC,wBAAwB;AAC1B;;AAEA,gDAAgD;AAChD;EACE;IACE;mDAC+C;EACjD;EACA;IACE;mDAC+C;EACjD;AACF;AACA,wCAAwC;AACxC;EACE;;IAEE,8BAA8B;EAChC;EACA;;IAEE,kCAAkC;EACpC;AACF;;AAEA;EACE;;IAEE,kCAAkC;EACpC;EACA;;IAEE,kCAAkC;EACpC;AACF;;AAEA;EACE;;IAEE,kCAAkC;EACpC;EACA;;IAEE,kCAAkC;EACpC;AACF;;AAEA;EACE;;IAEE,kCAAkC;EACpC;EACA;;IAEE,kCAAkC;EACpC;AACF;;AAEA;EACE;;IAEE,kCAAkC;EACpC;EACA;;IAEE,kCAAkC;EACpC;AACF;;AAEA;EACE;;IAEE,kCAAkC;EACpC;EACA;;IAEE,kCAAkC;EACpC;AACF;;AAEA;EACE,qDAAqD;AACvD;;AAEA;EACE,mDAAmD;AACrD;;AAEA;EACE,iDAAiD;AACnD;;AAEA;EACE,mDAAmD;AACrD;;AAEA;EACE,iDAAiD;AACnD;;AAEA;EACE,sDAAsD;AACxD;;AAEA,yEAAyE;AACzE;EACE;;IAEE,wBAAwB;IACxB,2BAA2B;EAC7B;EACA;IACE,0BAA0B;IAC1B,+BAA+B;EACjC;AACF;;AAEA;EACE,yBAAyB;EACzB,6BAA6B;EAC7B,yCAAyC;AAC3C;;AAEA;EACE,yBAAyB;EACzB,6BAA6B;EAC7B,yCAAyC;AAC3C;;AAEA;EACE,yBAAyB;EACzB,6BAA6B;EAC7B,yCAAyC;AAC3C;;AAEA;EACE,yBAAyB;EACzB,6BAA6B;EAC7B,yCAAyC;AAC3C;;AAEA;EACE,yBAAyB;EACzB,6BAA6B;EAC7B,yCAAyC;AAC3C;;AAEA;EACE,yBAAyB;EACzB,6BAA6B;EAC7B,uCAAuC;AACzC;;AAEA,6DAA6D;AAC7D;EACE;;IAEE,UAAU;IACV,2BAA2B;EAC7B;EACA;IACE,YAAY;IACZ,sBAAsB,EAAE,iBAAiB;EAC3C;AACF;;AAEA,sDAAsD;AACtD,oDAAoD;AACpD;EACE;IACE,yCAAyC;EAC3C;EACA;IACE,2CAA2C;EAC7C;EACA;IACE,0CAA0C;EAC5C;EACA;IACE,2CAA2C;EAC7C;EACA;IACE,yCAAyC;EAC3C;AACF;;AAEA;EACE,+BAA+B;EAC/B,aAAa;EACb,iBAAiB;AACnB;;AAEA;EACE,+BAA+B;EAC/B,aAAa;EACb,iBAAiB;AACnB;;AAEA;EACE,+BAA+B;EAC/B,aAAa;EACb,iBAAiB;AACnB;;AAEA;EACE,+BAA+B;EAC/B,aAAa;EACb,iBAAiB;AACnB;;AAEA;EACE,+BAA+B;EAC/B,aAAa;EACb,iBAAiB;AACnB;;AAEA;EACE,+BAA+B;EAC/B,aAAa;EACb,iBAAiB;AACnB","sourcesContent":["@keyframes pulse_outermost {\n 0%,\n 100% {\n transform: scale(1);\n }\n 50% {\n transform: scale(0.92);\n }\n}\n.outermost {\n animation: pulse_outermost 5s infinite;\n transform-origin: center;\n}\n\n@keyframes pulse_second {\n 0%,\n 100% {\n transform: scale(1);\n }\n 50% {\n transform: scale(0.856);\n }\n}\n.second {\n animation: pulse_second 5s infinite;\n transform-origin: center;\n}\n\n@keyframes pulse_third {\n 0%,\n 100% {\n transform: scale(1);\n }\n 50% {\n transform: scale(0.792);\n }\n}\n.third {\n animation: pulse_third 5s infinite;\n transform-origin: center;\n}\n\n@keyframes pulse_fourth {\n 0%,\n 100% {\n transform: scale(1);\n }\n 50% {\n transform: scale(0.728);\n }\n}\n.fourth {\n animation: pulse_fourth 5s infinite;\n transform-origin: center;\n}\n\n@keyframes pulse_fifth {\n 0%,\n 100% {\n transform: scale(1);\n }\n 50% {\n transform: scale(0.664);\n }\n}\n.fifth {\n animation: pulse_fifth 5s infinite;\n transform-origin: center;\n}\n\n@keyframes pulse_innermost {\n 0%,\n 100% {\n transform: scale(1);\n }\n 50% {\n transform: scale(0.6);\n }\n}\n.innermost {\n animation: pulse_innermost 5s infinite;\n transform-origin: center;\n}\n\n/* playful animation to indicate Pi is speaking */\n@keyframes speaking_outermost {\n 0%,\n 100% {\n transform: scale(1) rotate(0deg);\n }\n 25% {\n transform: scale(0.995);\n }\n 50% {\n transform: scale(0.9);\n }\n 75% {\n transform: scale(0.895);\n }\n}\n.outermost.piSpeaking {\n animation: speaking_outermost 2s infinite;\n transform-origin: center;\n}\n\n@keyframes speaking_second {\n 0%,\n 100% {\n transform: scale(1) rotate(0deg);\n }\n 25% {\n transform: scale(0.98) rotate(-1deg);\n }\n 50% {\n transform: scale(0.87) rotate(0deg);\n }\n 75% {\n transform: scale(0.865) rotate(1deg);\n }\n}\n.second.piSpeaking {\n animation: speaking_second 2s infinite;\n transform-origin: center;\n}\n\n@keyframes speaking_third {\n 0%,\n 100% {\n transform: scale(1) rotate(0deg);\n }\n 25% {\n transform: scale(0.965) rotate(-2deg);\n }\n 50% {\n transform: scale(0.84) rotate(0deg);\n }\n 75% {\n transform: scale(0.835) rotate(2deg);\n }\n}\n.third.piSpeaking {\n animation: speaking_third 2s infinite;\n transform-origin: center;\n}\n\n@keyframes speaking_fourth {\n 0%,\n 100% {\n transform: scale(1) rotate(0deg);\n }\n 25% {\n transform: scale(0.95) rotate(-3deg);\n }\n 50% {\n transform: scale(0.81) rotate(0deg);\n }\n 75% {\n transform: scale(0.805) rotate(3deg);\n }\n}\n.fourth.piSpeaking {\n animation: speaking_fourth 2s infinite;\n transform-origin: center;\n}\n\n@keyframes speaking_fifth {\n 0%,\n 100% {\n transform: scale(1) rotate(0deg);\n }\n 25% {\n transform: scale(0.935) rotate(-4deg);\n }\n 50% {\n transform: scale(0.78) rotate(0deg);\n }\n 75% {\n transform: scale(0.775) rotate(4deg);\n }\n}\n.fifth.piSpeaking {\n animation: speaking_fifth 2s infinite;\n transform-origin: center;\n}\n\n@keyframes speaking_innermost {\n 0%,\n 100% {\n transform: scale(1) rotate(0deg);\n }\n 25% {\n transform: scale(0.92) rotate(-5deg);\n }\n 50% {\n transform: scale(0.75) rotate(0deg);\n }\n 75% {\n transform: scale(0.745) rotate(5deg);\n }\n}\n.innermost.piSpeaking {\n animation: speaking_innermost 2s infinite;\n transform-origin: center;\n}\n\n/* wave animation to indicate user is speaking */\n@keyframes userSpeakingAnimation {\n 50% {\n transform: scaleY(0.05) scaleX(var(--width-factor))\n translateX(calc(-50% + var(--spread-amount)));\n }\n 100% {\n transform: scaleY(1) scaleX(var(--width-factor))\n translateX(calc(-50% + var(--spread-amount)));\n }\n}\n/* user speaking oscillation animation */\n@keyframes waveform_outermost {\n 0%,\n 100% {\n transform: scaleY(1) scaleX(1);\n }\n 25%,\n 75% {\n transform: scaleY(0.9) scaleX(0.9);\n }\n}\n\n@keyframes waveform_second {\n 0%,\n 100% {\n transform: scaleY(0.9) scaleX(0.9);\n }\n 25%,\n 75% {\n transform: scaleY(0.8) scaleX(0.8);\n }\n}\n\n@keyframes waveform_third {\n 0%,\n 100% {\n transform: scaleY(0.8) scaleX(0.8);\n }\n 25%,\n 75% {\n transform: scaleY(0.7) scaleX(0.7);\n }\n}\n\n@keyframes waveform_fourth {\n 0%,\n 100% {\n transform: scaleY(0.7) scaleX(0.7);\n }\n 25%,\n 75% {\n transform: scaleY(0.6) scaleX(0.6);\n }\n}\n\n@keyframes waveform_fifth {\n 0%,\n 100% {\n transform: scaleY(0.6) scaleX(0.6);\n }\n 25%,\n 75% {\n transform: scaleY(0.5) scaleX(0.5);\n }\n}\n\n@keyframes waveform_innermost {\n 0%,\n 100% {\n transform: scaleY(0.5) scaleX(0.5);\n }\n 25%,\n 75% {\n transform: scaleY(0.4) scaleX(0.4);\n }\n}\n\n.outermost.userSpeaking {\n animation: waveform_outermost 0.7s infinite alternate;\n}\n\n.second.userSpeaking {\n animation: waveform_second 0.65s infinite alternate;\n}\n\n.third.userSpeaking {\n animation: waveform_third 0.6s infinite alternate;\n}\n\n.fourth.userSpeaking {\n animation: waveform_fourth 0.55s infinite alternate;\n}\n\n.fifth.userSpeaking {\n animation: waveform_fifth 0.5s infinite alternate;\n}\n\n.innermost.userSpeaking {\n animation: waveform_innermost 0.45s infinite alternate;\n}\n\n/* flipcard animation to indicate Say, Pi is transcribing audio to text */\n@keyframes transcribingFlip {\n 0%,\n 100% {\n transform: rotateY(0deg);\n fill: var(--original-color);\n }\n 50% {\n transform: rotateY(180deg);\n fill: var(--transcribing-color);\n }\n}\n\n.outermost.transcribing {\n --original-color: #e4f2d1;\n --transcribing-color: #b3e0fe;\n animation: transcribingFlip 1.5s infinite;\n}\n\n.second.transcribing {\n --original-color: #cce8b5;\n --transcribing-color: #89c2ff;\n animation: transcribingFlip 1.6s infinite;\n}\n\n.third.transcribing {\n --original-color: #b3db95;\n --transcribing-color: #5fa4ff;\n animation: transcribingFlip 1.7s infinite;\n}\n\n.fourth.transcribing {\n --original-color: #9bd078;\n --transcribing-color: #3586ff;\n animation: transcribingFlip 1.8s infinite;\n}\n\n.fifth.transcribing {\n --original-color: #83c55c;\n --transcribing-color: #0b69e3;\n animation: transcribingFlip 1.9s infinite;\n}\n\n.innermost.transcribing {\n --original-color: #428a2f;\n --transcribing-color: #0053bf;\n animation: transcribingFlip 2s infinite;\n}\n\n/* heartbeat animation to indicate Pi is preparing to speak */\n@keyframes heartbeat {\n 0%,\n 100% {\n opacity: 1;\n fill: var(--original-color);\n }\n 50% {\n opacity: 0.5;\n fill: rgb(245 238 223); /* bg-cream-550 */\n }\n}\n\n/* toned-down dissary animation to indicate an error */\n/* toned-down error animation with reduced opacity */\n@keyframes errorAnimation {\n 0% {\n transform: rotate(0deg) translate(0%, 0%);\n }\n 25% {\n transform: rotate(-5deg) translate(-5%, 5%);\n }\n 50% {\n transform: rotate(5deg) translate(5%, -5%);\n }\n 75% {\n transform: rotate(-5deg) translate(-5%, 5%);\n }\n 100% {\n transform: rotate(0deg) translate(0%, 0%);\n }\n}\n\n.outermost.error {\n animation: errorAnimation 25s 1;\n fill: #ff0000;\n fill-opacity: 0.7;\n}\n\n.second.error {\n animation: errorAnimation 25s 1;\n fill: #ff3300;\n fill-opacity: 0.7;\n}\n\n.third.error {\n animation: errorAnimation 25s 1;\n fill: #ff6600;\n fill-opacity: 0.7;\n}\n\n.fourth.error {\n animation: errorAnimation 25s 1;\n fill: #ff9900;\n fill-opacity: 0.7;\n}\n\n.fifth.error {\n animation: errorAnimation 25s 1;\n fill: #ffcc00;\n fill-opacity: 0.7;\n}\n\n.innermost.error {\n animation: errorAnimation 25s 1;\n fill: #ffff00;\n fill-opacity: 0.7;\n}\n"],"sourceRoot":""}]);
// Exports
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (___CSS_LOADER_EXPORT___);
/***/ }),
/***/ 8580:
/***/ ((module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Z: () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7537);
/* harmony import */ var _node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3645);
/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__);
// Imports
var ___CSS_LOADER_EXPORT___ = _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default()((_node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default()));
// Module
___CSS_LOADER_EXPORT___.push([module.id, `.hidden{display:none !important}#saypi-callButton.disabled svg path.circle{fill:#f5eedf}.mobile-device #saypi-enterButton,.mobile-device #saypi-exitButton{position:fixed;top:4rem;left:1.25rem;width:3rem;height:3rem;padding:6px;border:0;z-index:60}`, "",{"version":3,"sources":["webpack://./src/styles/common.scss"],"names":[],"mappings":"AAAA,QACE,uBAAA,CAGF,2CACE,YAAA,CAKA,mEAEE,cAAA,CACA,QAAA,CACA,YAAA,CACA,UAAA,CACA,WAAA,CACA,WAAA,CACA,QAAA,CACA,UAAA","sourcesContent":[".hidden {\n display: none !important;\n}\n\n#saypi-callButton.disabled svg path.circle {\n fill: rgb(245 238 223); /* bg-cream-550 */\n}\n\n.mobile-device {\n /* maximize (mobile view) button is only displayed on compatible devices */\n #saypi-enterButton,\n #saypi-exitButton {\n position: fixed;\n top: 4rem;\n left: 1.25rem;\n width: 3rem;\n height: 3rem;\n padding: 6px;\n border: 0;\n z-index: 60;\n }\n}\n"],"sourceRoot":""}]);
// Exports
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (___CSS_LOADER_EXPORT___);
/***/ }),
/***/ 1902:
/***/ ((module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Z: () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7537);
/* harmony import */ var _node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3645);
/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__);
// Imports
var ___CSS_LOADER_EXPORT___ = _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default()((_node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default()));
// Module
___CSS_LOADER_EXPORT___.push([module.id, `@keyframes pulse{0%{transform:scale(1)}50%{transform:scale(0.9)}100%{transform:scale(1)}}html.desktop-view #saypi-talkButton{display:none}html.desktop-view #saypi-callButton{height:2.25rem;width:2.25rem;position:relative;margin:.5rem 0 .5rem 0}html.desktop-view .saypi-prompt-container{padding-right:0}html.desktop-view #saypi-notification>svg{width:3rem;height:3rem;bottom:4rem;right:12rem;position:fixed}html.desktop-view #saypi-exitButton{display:none}`, "",{"version":3,"sources":["webpack://./src/styles/desktop.scss"],"names":[],"mappings":"AACE,iBACE,GACE,kBAAA,CAEF,IACE,oBAAA,CAEF,KACE,kBAAA,CAAA,CAIJ,oCAEE,YAAA,CAGF,oCACE,cAAA,CACA,aAAA,CACA,iBAAA,CACA,sBAAA,CAGF,0CAEE,eAAA,CAGF,0CACE,UAAA,CACA,WAAA,CACA,WAAA,CACA,WAAA,CACA,cAAA,CAGF,oCACE,YAAA","sourcesContent":["html.desktop-view {\n @keyframes pulse {\n 0% {\n transform: scale(1);\n }\n 50% {\n transform: scale(0.9);\n }\n 100% {\n transform: scale(1);\n }\n }\n\n #saypi-talkButton {\n /* not needed on desktop with call button */\n display: none;\n }\n\n #saypi-callButton {\n height: 2.25rem;\n width: 2.25rem;\n position: relative;\n margin: 0.5rem 0 0.5rem 0;\n }\n\n .saypi-prompt-container {\n /* make room in the prompt text area for the call button */\n padding-right: 0;\n }\n\n #saypi-notification > svg {\n width: 3rem;\n height: 3rem;\n bottom: 4rem;\n right: 12rem;\n position: fixed;\n }\n\n #saypi-exitButton {\n display: none;\n }\n}\n"],"sourceRoot":""}]);
// Exports
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (___CSS_LOADER_EXPORT___);
/***/ }),
/***/ 149:
/***/ ((module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Z: () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7537);
/* harmony import */ var _node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3645);
/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__);
// Imports
var ___CSS_LOADER_EXPORT___ = _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default()((_node_modules_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default()));
// Module
___CSS_LOADER_EXPORT___.push([module.id, `html.mobile-view #saypi-panel,html.mobile-view .notification{width:100%;position:fixed;left:0;background-color:rgba(245,238,223,.98);height:100svh;top:0}html.mobile-view #saypi-talkButton{background-color:rgba(0,0,0,0);border-radius:0;margin:0}html.mobile-view #saypi-talkButton svg{width:100vw;height:100svh}html.mobile-view #saypi-notification{z-index:100;background-color:rgba(0,0,0,0)}html.mobile-view #saypi-notification svg{width:75%;height:100%;margin:auto}html.mobile-view #__next>main>div>div>div.fixed.top-4.right-6>button,html.mobile-view #saypi-experiences-button{transform:scale(1.5)}html.mobile-view div.bg-gradient-to-b{display:none}html.mobile-view #saypi-audio-controls div.p-1{display:none}html.mobile-view #saypi-audio-controls button.group{transform:scale(2) !important;z-index:50}html.mobile-view #saypi-audio-controls button.group+button{display:none}html.mobile-view .text-body-chat-m{padding-top:0}html.mobile-view #saypi-enterButton{display:none}html.mobile-view #saypi-footer{display:none}html.mobile-view #saypi-prompt-ancestor{display:none}html.mobile-view #saypi-submitButton{display:none}html.mobile-view #saypi-callButton{position:fixed;bottom:4rem;left:0;right:0;margin:auto;width:4.5rem;height:4.5rem;padding:6px;border:0;z-index:80}`, "",{"version":3,"sources":["webpack://./src/styles/mobile.scss"],"names":[],"mappings":"AACE,6DAEE,UAAA,CACA,cAAA,CACA,MAAA,CACA,sCAAA,CAEA,aAAA,CACA,KAAA,CAGF,mCACE,8BAAA,CACA,eAAA,CACA,QAAA,CACA,uCACE,WAAA,CACA,aAAA,CAIJ,qCACE,WAAA,CACA,8BAAA,CACA,yCACE,SAAA,CACA,WAAA,CACA,WAAA,CAKJ,gHAEE,oBAAA,CAIF,sCACE,YAAA,CAMA,+CACE,YAAA,CAGF,oDACE,6BAAA,CACA,UAAA,CAEA,2DACE,YAAA,CAMN,mCACE,aAAA,CAGF,oCACE,YAAA,CAGF,+BACE,YAAA,CAGF,wCAGE,YAAA,CAIF,qCACE,YAAA,CAGF,mCACE,cAAA,CACA,WAAA,CACA,MAAA,CACA,OAAA,CACA,WAAA,CACA,YAAA,CACA,aAAA,CACA,WAAA,CACA,QAAA,CACA,UAAA","sourcesContent":["html.mobile-view {\n #saypi-panel,\n .notification {\n width: 100%;\n position: fixed;\n left: 0;\n background-color: rgba(245, 238, 223, 0.98);\n\n height: 100svh;\n top: 0;\n }\n\n #saypi-talkButton {\n background-color: transparent;\n border-radius: 0;\n margin: 0;\n svg {\n width: 100vw;\n height: 100svh;\n }\n }\n\n #saypi-notification {\n z-index: 100;\n background-color: transparent;\n svg {\n width: 75%;\n height: 100%;\n margin: auto;\n }\n }\n\n /* Pi controls: ellipsis, experiences */\n #__next > main > div > div > div.fixed.top-4.right-6 > button,\n #saypi-experiences-button {\n transform: scale(1.5);\n }\n\n /* hide an ugly artifact */\n div.bg-gradient-to-b {\n display: none;\n }\n\n /* Pi controls: mute/unmute */\n #saypi-audio-controls {\n /* hide the voice options */\n div.p-1 {\n display: none;\n }\n /* scale the mute button */\n button.group {\n transform: scale(2) !important;\n z-index: 50;\n /* hide the voice selector twisty */\n + button {\n display: none;\n }\n }\n }\n\n /* fix an alignment issue with the \"new ui layout\" */\n .text-body-chat-m {\n padding-top: 0;\n }\n\n #saypi-enterButton {\n display: none;\n }\n\n #saypi-footer {\n display: none;\n }\n\n #saypi-prompt-ancestor {\n /* hides the row containing the text area control */\n /* important: hides virtual keyboard on android */\n display: none;\n /* the call button, usually nested in the prompt, is detached while in mobile view */\n }\n\n #saypi-submitButton {\n display: none;\n }\n\n #saypi-callButton {\n position: fixed;\n bottom: 4rem;\n left: 0;\n right: 0;\n margin: auto;\n width: 4.5rem;\n height: 4.5rem;\n padding: 6px;\n border: 0;\n z-index: 80;\n }\n}\n"],"sourceRoot":""}]);
// Exports
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (___CSS_LOADER_EXPORT___);
/***/ }),
/***/ 3645:
/***/ ((module) => {
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
module.exports = function (cssWithMappingToString) {
var list = [];
// return the list of modules as css string
list.toString = function toString() {
return this.map(function (item) {
var content = "";
var needLayer = typeof item[5] !== "undefined";
if (item[4]) {
content += "@supports (".concat(item[4], ") {");
}
if (item[2]) {
content += "@media ".concat(item[2], " {");
}
if (needLayer) {
content += "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {");
}
content += cssWithMappingToString(item);
if (needLayer) {
content += "}";
}
if (item[2]) {
content += "}";
}
if (item[4]) {
content += "}";
}
return content;
}).join("");
};
// import a list of modules into the list
list.i = function i(modules, media, dedupe, supports, layer) {
if (typeof modules === "string") {
modules = [[null, modules, undefined]];
}
var alreadyImportedModules = {};
if (dedupe) {
for (var k = 0; k < this.length; k++) {
var id = this[k][0];
if (id != null) {
alreadyImportedModules[id] = true;
}
}
}
for (var _k = 0; _k < modules.length; _k++) {
var item = [].concat(modules[_k]);
if (dedupe && alreadyImportedModules[item[0]]) {
continue;
}
if (typeof layer !== "undefined") {
if (typeof item[5] === "undefined") {
item[5] = layer;
} else {
item[1] = "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {").concat(item[1], "}");
item[5] = layer;
}
}
if (media) {
if (!item[2]) {
item[2] = media;
} else {
item[1] = "@media ".concat(item[2], " {").concat(item[1], "}");
item[2] = media;
}
}
if (supports) {
if (!item[4]) {
item[4] = "".concat(supports);
} else {
item[1] = "@supports (".concat(item[4], ") {").concat(item[1], "}");
item[4] = supports;
}
}
list.push(item);
}
};
return list;
};
/***/ }),
/***/ 7537:
/***/ ((module) => {
module.exports = function (item) {
var content = item[1];
var cssMapping = item[3];
if (!cssMapping) {
return content;
}
if (typeof btoa === "function") {
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(cssMapping))));
var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64);
var sourceMapping = "/*# ".concat(data, " */");
return [content].concat([sourceMapping]).join("\n");
}
return [content].join("\n");
};
/***/ }),
/***/ 7187:
/***/ ((module) => {
// Copyright Joyent, Inc. and other Node contributors.
//
// 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.
var R = typeof Reflect === 'object' ? Reflect : null
var ReflectApply = R && typeof R.apply === 'function'
? R.apply
: function ReflectApply(target, receiver, args) {
return Function.prototype.apply.call(target, receiver, args);
}
var ReflectOwnKeys
if (R && typeof R.ownKeys === 'function') {
ReflectOwnKeys = R.ownKeys
} else if (Object.getOwnPropertySymbols) {
ReflectOwnKeys = function ReflectOwnKeys(target) {
return Object.getOwnPropertyNames(target)
.concat(Object.getOwnPropertySymbols(target));
};
} else {
ReflectOwnKeys = function ReflectOwnKeys(target) {
return Object.getOwnPropertyNames(target);
};
}
function ProcessEmitWarning(warning) {
if (console && console.warn) console.warn(warning);
}
var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
return value !== value;
}
function EventEmitter() {
EventEmitter.init.call(this);
}
module.exports = EventEmitter;
module.exports.once = once;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._eventsCount = 0;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
var defaultMaxListeners = 10;
function checkListener(listener) {
if (typeof listener !== 'function') {
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
}
}
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
enumerable: true,
get: function() {
return defaultMaxListeners;
},
set: function(arg) {
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
}
defaultMaxListeners = arg;
}
});
EventEmitter.init = function() {
if (this._events === undefined ||
this._events === Object.getPrototypeOf(this)._events) {
this._events = Object.create(null);
this._eventsCount = 0;
}
this._maxListeners = this._maxListeners || undefined;
};
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
}
this._maxListeners = n;
return this;
};
function _getMaxListeners(that) {
if (that._maxListeners === undefined)
return EventEmitter.defaultMaxListeners;
return that._maxListeners;
}
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
return _getMaxListeners(this);
};
EventEmitter.prototype.emit = function emit(type) {
var args = [];
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
var doError = (type === 'error');
var events = this._events;
if (events !== undefined)
doError = (doError && events.error === undefined);
else if (!doError)
return false;
// If there is no 'error' event listener then throw.
if (doError) {
var er;
if (args.length > 0)
er = args[0];
if (er instanceof Error) {
// Note: The comments on the `throw` lines are intentional, they show
// up in Node's output if this results in an unhandled exception.
throw er; // Unhandled 'error' event
}
// At least give some kind of context to the user
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
err.context = er;
throw err; // Unhandled 'error' event
}
var handler = events[type];
if (handler === undefined)
return false;
if (typeof handler === 'function') {
ReflectApply(handler, this, args);
} else {
var len = handler.length;
var listeners = arrayClone(handler, len);
for (var i = 0; i < len; ++i)
ReflectApply(listeners[i], this, args);
}
return true;
};
function _addListener(target, type, listener, prepend) {
var m;
var events;
var existing;
checkListener(listener);
events = target._events;
if (events === undefined) {
events = target._events = Object.create(null);
target._eventsCount = 0;
} else {
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (events.newListener !== undefined) {
target.emit('newListener', type,
listener.listener ? listener.listener : listener);
// Re-assign `events` because a newListener handler could have caused the
// this._events to be assigned to a new object
events = target._events;
}
existing = events[type];
}
if (existing === undefined) {
// Optimize the case of one listener. Don't need the extra array object.
existing = events[type] = listener;
++target._eventsCount;
} else {
if (typeof existing === 'function') {
// Adding the second element, need to change to array.
existing = events[type] =
prepend ? [listener, existing] : [existing, listener];
// If we've already got an array, just append.
} else if (prepend) {
existing.unshift(listener);
} else {
existing.push(listener);
}
// Check for listener leak
m = _getMaxListeners(target);
if (m > 0 && existing.length > m && !existing.warned) {
existing.warned = true;
// No error code for this since it is a Warning
// eslint-disable-next-line no-restricted-syntax
var w = new Error('Possible EventEmitter memory leak detected. ' +
existing.length + ' ' + String(type) + ' listeners ' +
'added. Use emitter.setMaxListeners() to ' +
'increase limit');
w.name = 'MaxListenersExceededWarning';
w.emitter = target;
w.type = type;
w.count = existing.length;
ProcessEmitWarning(w);
}
}
return target;
}
EventEmitter.prototype.addListener = function addListener(type, listener) {
return _addListener(this, type, listener, false);
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.prependListener =
function prependListener(type, listener) {
return _addListener(this, type, listener, true);
};
function onceWrapper() {
if (!this.fired) {
this.target.removeListener(this.type, this.wrapFn);
this.fired = true;
if (arguments.length === 0)
return this.listener.call(this.target);
return this.listener.apply(this.target, arguments);
}
}
function _onceWrap(target, type, listener) {
var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
var wrapped = onceWrapper.bind(state);
wrapped.listener = listener;
state.wrapFn = wrapped;
return wrapped;
}
EventEmitter.prototype.once = function once(type, listener) {
checkListener(listener);
this.on(type, _onceWrap(this, type, listener));
return this;
};
EventEmitter.prototype.prependOnceListener =
function prependOnceListener(type, listener) {
checkListener(listener);
this.prependListener(type, _onceWrap(this, type, listener));
return this;
};
// Emits a 'removeListener' event if and only if the listener was removed.
EventEmitter.prototype.removeListener =
function removeListener(type, listener) {
var list, events, position, i, originalListener;
checkListener(listener);
events = this._events;
if (events === undefined)
return this;
list = events[type];
if (list === undefined)
return this;
if (list === listener || list.listener === listener) {
if (--this._eventsCount === 0)
this._events = Object.create(null);
else {
delete events[type];
if (events.removeListener)
this.emit('removeListener', type, list.listener || listener);
}
} else if (typeof list !== 'function') {
position = -1;
for (i = list.length - 1; i >= 0; i--) {
if (list[i] === listener || list[i].listener === listener) {
originalListener = list[i].listener;
position = i;
break;
}
}
if (position < 0)
return this;
if (position === 0)
list.shift();
else {
spliceOne(list, position);
}
if (list.length === 1)
events[type] = list[0];
if (events.removeListener !== undefined)
this.emit('removeListener', type, originalListener || listener);
}
return this;
};
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.removeAllListeners =
function removeAllListeners(type) {
var listeners, events, i;
events = this._events;
if (events === undefined)
return this;
// not listening for removeListener, no need to emit
if (events.removeListener === undefined) {
if (arguments.length === 0) {
this._events = Object.create(null);
this._eventsCount = 0;
} else if (events[type] !== undefined) {
if (--this._eventsCount === 0)
this._events = Object.create(null);
else
delete events[type];
}
return this;
}
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
var keys = Object.keys(events);
var key;
for (i = 0; i < keys.length; ++i) {
key = keys[i];
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = Object.create(null);
this._eventsCount = 0;
return this;
}
listeners = events[type];
if (typeof listeners === 'function') {
this.removeListener(type, listeners);
} else if (listeners !== undefined) {
// LIFO order
for (i = listeners.length - 1; i >= 0; i--) {
this.removeListener(type, listeners[i]);
}
}
return this;
};
function _listeners(target, type, unwrap) {
var events = target._events;
if (events === undefined)
return [];
var evlistener = events[type];
if (evlistener === undefined)
return [];
if (typeof evlistener === 'function')
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
return unwrap ?
unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
}
EventEmitter.prototype.listeners = function listeners(type) {
return _listeners(this, type, true);
};
EventEmitter.prototype.rawListeners = function rawListeners(type) {
return _listeners(this, type, false);
};
EventEmitter.listenerCount = function(emitter, type) {
if (typeof emitter.listenerCount === 'function') {
return emitter.listenerCount(type);
} else {
return listenerCount.call(emitter, type);
}
};
EventEmitter.prototype.listenerCount = listenerCount;
function listenerCount(type) {
var events = this._events;
if (events !== undefined) {
var evlistener = events[type];
if (typeof evlistener === 'function') {
return 1;
} else if (evlistener !== undefined) {
return evlistener.length;
}
}
return 0;
}
EventEmitter.prototype.eventNames = function eventNames() {
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
};
function arrayClone(arr, n) {
var copy = new Array(n);
for (var i = 0; i < n; ++i)
copy[i] = arr[i];
return copy;
}
function spliceOne(list, index) {
for (; index + 1 < list.length; index++)
list[index] = list[index + 1];
list.pop();
}
function unwrapListeners(arr) {
var ret = new Array(arr.length);
for (var i = 0; i < ret.length; ++i) {
ret[i] = arr[i].listener || arr[i];
}
return ret;
}
function once(emitter, name) {
return new Promise(function (resolve, reject) {
function errorListener(err) {
emitter.removeListener(name, resolver);
reject(err);
}
function resolver() {
if (typeof emitter.removeListener === 'function') {
emitter.removeListener('error', errorListener);
}
resolve([].slice.call(arguments));
};
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
if (name !== 'error') {
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
}
});
}
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
if (typeof emitter.on === 'function') {
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
}
}
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
if (typeof emitter.on === 'function') {
if (flags.once) {
emitter.once(name, listener);
} else {
emitter.on(name, listener);
}
} else if (typeof emitter.addEventListener === 'function') {
// EventTarget does not have `error` event semantics like Node
// EventEmitters, we do not listen for `error` events here.
emitter.addEventListener(name, function wrapListener(arg) {
// IE does not have builtin `{ once: true }` support so we
// have to do it manually.
if (flags.once) {
emitter.removeEventListener(name, wrapListener);
}
listener(arg);
});
} else {
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
}
}
/***/ }),
/***/ 3379:
/***/ ((module) => {
var stylesInDOM = [];
function getIndexByIdentifier(identifier) {
var result = -1;
for (var i = 0; i < stylesInDOM.length; i++) {
if (stylesInDOM[i].identifier === identifier) {
result = i;
break;
}
}
return result;
}
function modulesToDom(list, options) {
var idCountMap = {};
var identifiers = [];
for (var i = 0; i < list.length; i++) {
var item = list[i];
var id = options.base ? item[0] + options.base : item[0];
var count = idCountMap[id] || 0;
var identifier = "".concat(id, " ").concat(count);
idCountMap[id] = count + 1;
var indexByIdentifier = getIndexByIdentifier(identifier);
var obj = {
css: item[1],
media: item[2],
sourceMap: item[3],
supports: item[4],
layer: item[5]
};
if (indexByIdentifier !== -1) {
stylesInDOM[indexByIdentifier].references++;
stylesInDOM[indexByIdentifier].updater(obj);
} else {
var updater = addElementStyle(obj, options);
options.byIndex = i;
stylesInDOM.splice(i, 0, {
identifier: identifier,
updater: updater,
references: 1
});
}
identifiers.push(identifier);
}
return identifiers;
}
function addElementStyle(obj, options) {
var api = options.domAPI(options);
api.update(obj);
var updater = function updater(newObj) {
if (newObj) {
if (newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap && newObj.supports === obj.supports && newObj.layer === obj.layer) {
return;
}
api.update(obj = newObj);
} else {
api.remove();
}
};
return updater;
}
module.exports = function (list, options) {
options = options || {};
list = list || [];
var lastIdentifiers = modulesToDom(list, options);
return function update(newList) {
newList = newList || [];
for (var i = 0; i < lastIdentifiers.length; i++) {
var identifier = lastIdentifiers[i];
var index = getIndexByIdentifier(identifier);
stylesInDOM[index].references--;
}
var newLastIdentifiers = modulesToDom(newList, options);
for (var _i = 0; _i < lastIdentifiers.length; _i++) {
var _identifier = lastIdentifiers[_i];
var _index = getIndexByIdentifier(_identifier);
if (stylesInDOM[_index].references === 0) {
stylesInDOM[_index].updater();
stylesInDOM.splice(_index, 1);
}
}
lastIdentifiers = newLastIdentifiers;
};
};
/***/ }),
/***/ 569:
/***/ ((module) => {
var memo = {};
/* istanbul ignore next */
function getTarget(target) {
if (typeof memo[target] === "undefined") {
var styleTarget = document.querySelector(target);
// Special case to return head of iframe instead of iframe itself
if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) {
try {
// This will throw an exception if access to iframe is blocked
// due to cross-origin restrictions
styleTarget = styleTarget.contentDocument.head;
} catch (e) {
// istanbul ignore next
styleTarget = null;
}
}
memo[target] = styleTarget;
}
return memo[target];
}
/* istanbul ignore next */
function insertBySelector(insert, style) {
var target = getTarget(insert);
if (!target) {
throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");
}
target.appendChild(style);
}
module.exports = insertBySelector;
/***/ }),
/***/ 9216:
/***/ ((module) => {
/* istanbul ignore next */
function insertStyleElement(options) {
var element = document.createElement("style");
options.setAttributes(element, options.attributes);
options.insert(element, options.options);
return element;
}
module.exports = insertStyleElement;
/***/ }),
/***/ 3565:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
/* istanbul ignore next */
function setAttributesWithoutAttributes(styleElement) {
var nonce = true ? __webpack_require__.nc : 0;
if (nonce) {
styleElement.setAttribute("nonce", nonce);
}
}
module.exports = setAttributesWithoutAttributes;
/***/ }),
/***/ 7795:
/***/ ((module) => {
/* istanbul ignore next */
function apply(styleElement, options, obj) {
var css = "";
if (obj.supports) {
css += "@supports (".concat(obj.supports, ") {");
}
if (obj.media) {
css += "@media ".concat(obj.media, " {");
}
var needLayer = typeof obj.layer !== "undefined";
if (needLayer) {
css += "@layer".concat(obj.layer.length > 0 ? " ".concat(obj.layer) : "", " {");
}
css += obj.css;
if (needLayer) {
css += "}";
}
if (obj.media) {
css += "}";
}
if (obj.supports) {
css += "}";
}
var sourceMap = obj.sourceMap;
if (sourceMap && typeof btoa !== "undefined") {
css += "\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))), " */");
}
// For old IE
/* istanbul ignore if */
options.styleTagTransform(css, styleElement, options.options);
}
function removeStyleElement(styleElement) {
// istanbul ignore if
if (styleElement.parentNode === null) {
return false;
}
styleElement.parentNode.removeChild(styleElement);
}
/* istanbul ignore next */
function domAPI(options) {
if (typeof document === "undefined") {
return {
update: function update() {},
remove: function remove() {}
};
}
var styleElement = options.insertStyleElement(options);
return {
update: function update(obj) {
apply(styleElement, options, obj);
},
remove: function remove() {
removeStyleElement(styleElement);
}
};
}
module.exports = domAPI;
/***/ }),
/***/ 4589:
/***/ ((module) => {
/* istanbul ignore next */
function styleTagTransform(css, styleElement) {
if (styleElement.styleSheet) {
styleElement.styleSheet.cssText = css;
} else {
while (styleElement.firstChild) {
styleElement.removeChild(styleElement.firstChild);
}
styleElement.appendChild(document.createTextNode(css));
}
}
module.exports = styleTagTransform;
/***/ }),
/***/ 8158:
/***/ ((__unused_webpack_module, exports) => {
var __webpack_unused_export__;
__webpack_unused_export__ = ({ value: true });
exports.j = void 0;
function appendChild(parent, child, position = 0) {
// Check if a container is provided.
if (parent) {
// If position is 0, simply append the button as the last child.
if (position === 0) {
parent.appendChild(child);
}
else {
// Calculate the index of the reference node for insertBefore().
const referenceIndex = parent.children.length + position;
const referenceNode = parent.children[referenceIndex];
// If a reference node exists, insert the button before it.
if (referenceNode) {
parent.insertBefore(child, referenceNode);
}
else {
// If not, append the button as the last child.
parent.appendChild(child);
}
}
}
else {
// If no container is provided, append the button to the body.
document.body.appendChild(child);
}
}
exports.j = appendChild;
/***/ }),
/***/ 9947:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
var __webpack_unused_export__;
__webpack_unused_export__ = ({ value: true });
exports.AP = void 0;
const TranscriptionModule_1 = __webpack_require__(8673);
class SubmitErrorHandler {
constructor() {
this.audioOutputStatus = false;
// Initialise properties if needed
this.restorePointKey = "restorePoint";
}
initAudioOutputListener() {
const audioOutputButton = document.getElementById("saypi-audio-output-button");
if (audioOutputButton) {
audioOutputButton.addEventListener("click", this.handleAudioOutputClick.bind(this));
}
}
// Event handler
handleAudioOutputClick() {
this.audioOutputStatus = !this.audioOutputStatus; // Toggle the state
}
// 1. Detect when a submit error occurs
detectSubmitError() {
const submitButton = document.getElementById("saypi-submitButton");
const textarea = document.getElementById("saypi-prompt");
if (submitButton && textarea) {
if (submitButton.disabled && textarea.value.length > 0) {
return true;
}
}
return false;
}
// 2. Create a "restore point" capturing application state
createRestorePoint({ prompt: message, audioInputEnabled: audioInputStatus, audioOutputEnabled: audioOutputStatus, }) {
const restorePoint = {
prompt: message,
audioInputEnabled: audioInputStatus,
audioOutputEnabled: audioOutputStatus,
creationTime: new Date().toISOString(),
};
localStorage.setItem(this.restorePointKey, JSON.stringify(restorePoint));
}
// 3. Programmatically reload the page
reloadPage() {
window.location.reload();
}
handleSubmitError() {
const textarea = document.getElementById("saypi-prompt");
const prompt = textarea ? textarea.value : "";
let audioInputStatus = true;
const callButton = document.getElementById("saypi-callButton");
if (callButton) {
audioInputStatus = callButton.classList.contains("active");
}
console.log("Creating restore point");
this.createRestorePoint({
prompt: prompt,
audioInputEnabled: audioInputStatus,
audioOutputEnabled: this.audioOutputStatus,
});
console.log("Reloading page");
this.reloadPage();
}
// 4. On load, check for a restore point
checkForRestorePoint() {
const storedData = localStorage.getItem(this.restorePointKey);
if (storedData) {
const restorePoint = JSON.parse(storedData);
const currentTime = new Date();
const restoreTime = new Date(restorePoint.creationTime);
const timeDifference = (currentTime.getTime() - restoreTime.getTime()) / (1000 * 60); // in minutes
if (timeDifference <= 5) {
console.log("Restoring application state", restorePoint);
(0, TranscriptionModule_1.setPromptText)(restorePoint.prompt);
this.activateAudioInput(restorePoint.audioInputEnabled);
this.activateAudioOutput(restorePoint.audioOutputEnabled);
// Delete the executed restore point
localStorage.removeItem(this.restorePointKey);
}
}
}
activateAudioInput(enable) {
if (enable) {
const callButton = document.getElementById("saypi-callButton");
if (callButton) {
callButton.click();
}
}
}
activateAudioOutput(enable) {
if (enable) {
const audioOutputButton = document.getElementById("saypi-audio-output-button");
if (audioOutputButton) {
audioOutputButton.click();
}
}
}
}
__webpack_unused_export__ = SubmitErrorHandler;
// Singleton
exports.AP = new SubmitErrorHandler();
/***/ }),
/***/ 8673:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.mergeTranscripts = exports.setPromptText = exports.uploadAudioWithRetry = exports.clearPendingTranscriptions = exports.isTranscriptionPending = void 0;
const ConfigModule_js_1 = __webpack_require__(8186);
const StateMachineService_js_1 = __importDefault(__webpack_require__(8615));
const UserAgentModule_js_1 = __webpack_require__(4008);
const EventBus_js_1 = __importDefault(__webpack_require__(7635));
const EventModule_js_1 = __importDefault(__webpack_require__(9940));
const LoggingModule_js_1 = __webpack_require__(484);
const knownNetworkErrorMessages = [
"Failed to fetch",
"Load failed",
"NetworkError when attempting to fetch resource.", // Firefox
// Add more known error messages here
];
// timeout for transcription requests
const TIMEOUT_MS = 30000; // 30 seconds
// track sequence numbers for in-flight transcription requests
let sequenceNum = 0;
const sequenceNumsPendingTranscription = new Set();
function checkForExpiredEntries() {
const now = Date.now();
sequenceNumsPendingTranscription.forEach((entry) => {
if (now - entry.timestamp > TIMEOUT_MS) {
sequenceNumsPendingTranscription.delete(entry);
LoggingModule_js_1.logger.info(`Transcription request ${entry.seq} timed out`);
}
});
}
function transcriptionSent() {
sequenceNum++;
sequenceNumsPendingTranscription.add({
seq: sequenceNum,
timestamp: Date.now(),
});
}
function transcriptionReceived(seq) {
// delete entry with matching sequence number
sequenceNumsPendingTranscription.forEach((entry) => {
if (entry.seq === seq) {
sequenceNumsPendingTranscription.delete(entry);
LoggingModule_js_1.logger.debug(`Transcription response ${seq} received after ${(Date.now() - entry.timestamp) / 1000}s`);
return;
}
});
}
function isTranscriptionPending() {
checkForExpiredEntries();
return sequenceNumsPendingTranscription.size > 0;
}
exports.isTranscriptionPending = isTranscriptionPending;
// call after completed user input is submitted
function clearPendingTranscriptions() {
sequenceNumsPendingTranscription.clear();
}
exports.clearPendingTranscriptions = clearPendingTranscriptions;
function uploadAudioWithRetry(audioBlob, audioDurationMillis, precedingTranscripts = {}, maxRetries = 3) {
return __awaiter(this, void 0, void 0, function* () {
let retryCount = 0;
let delay = 1000; // initial delay of 1 second
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
while (retryCount < maxRetries) {
try {
transcriptionSent();
yield uploadAudio(audioBlob, audioDurationMillis, precedingTranscripts);
return;
}
catch (error) {
// check for timeout errors (30s on Heroku)
if (error instanceof TypeError &&
knownNetworkErrorMessages.includes(error.message)) {
LoggingModule_js_1.logger.info(`Attempt ${retryCount + 1}/${maxRetries} failed. Retrying in ${delay / 1000} seconds...`);
yield sleep(delay);
// Exponential backoff
delay *= 2;
retryCount++;
}
else {
console.error("Unexpected error: ", error);
StateMachineService_js_1.default.actor.send("saypi:transcribeFailed", {
detail: error,
});
return;
}
}
}
console.error("Max retries reached. Giving up.");
StateMachineService_js_1.default.actor.send("saypi:transcribeFailed", {
detail: new Error("Max retries reached"),
});
});
}
exports.uploadAudioWithRetry = uploadAudioWithRetry;
function uploadAudio(audioBlob, audioDurationMillis, precedingTranscripts = {}) {
return __awaiter(this, void 0, void 0, function* () {
try {
const messages = Object.entries(precedingTranscripts).map(([seq, content]) => {
return {
role: "user",
content: content,
sequenceNumber: Number(seq), // Convert the string to a number
};
});
const formData = constructTranscriptionFormData(audioBlob, audioDurationMillis / 1000, messages);
const language = navigator.language;
const controller = new AbortController();
const { signal } = controller;
setTimeout(() => controller.abort(), TIMEOUT_MS);
const startTime = new Date().getTime();
const response = yield fetch(`${ConfigModule_js_1.config.apiServerUrl}/transcribe?language=${language}`, {
method: "POST",
body: formData,
signal,
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const responseJson = yield response.json();
const seq = responseJson.sequenceNumber;
if (seq !== undefined) {
transcriptionReceived(seq);
}
const endTime = new Date().getTime();
const transcriptionDurationMillis = endTime - startTime;
const transcript = responseJson.text;
const wc = transcript.split(" ").length;
const payload = {
text: transcript,
sequenceNumber: seq,
};
if (responseJson.hasOwnProperty("pFinishedSpeaking")) {
payload.pFinishedSpeaking = responseJson.pFinishedSpeaking;
}
if (responseJson.hasOwnProperty("tempo")) {
payload.tempo = responseJson.tempo;
}
LoggingModule_js_1.logger.info(`Transcribed ${Math.round(audioDurationMillis / 1000)}s of audio into ${wc} words in ${Math.round(transcriptionDurationMillis / 1000)}s`);
if (responseJson.text.length === 0) {
StateMachineService_js_1.default.actor.send("saypi:transcribedEmpty");
}
else {
StateMachineService_js_1.default.actor.send("saypi:transcribed", payload);
}
}
catch (error) {
if (error instanceof Error) {
if (error.name === "AbortError") {
console.error("Fetch aborted due to timeout", error);
}
else {
console.error("An unexpected error occurred:", error);
}
}
else {
console.error("Something thrown that is not an Error object:", error);
}
// re-throw the error if your logic requires it
throw error;
}
});
}
function constructTranscriptionFormData(audioBlob, audioDurationSeconds, messages) {
const formData = new FormData();
let audioFilename = "audio.webm";
if (audioBlob.type === "audio/mp4") {
audioFilename = "audio.mp4";
}
else if (audioBlob.type === "audio/wav") {
audioFilename = "audio.wav";
}
LoggingModule_js_1.logger.info(`Transcribing audio Blob with MIME type: ${audioBlob.type}, size: ${(audioBlob.size / 1024).toFixed(2)}kb`);
// Add the audio blob to the FormData object
formData.append("audio", audioBlob, audioFilename);
formData.append("duration", audioDurationSeconds.toString());
formData.append("sequenceNumber", sequenceNum.toString());
formData.append("messages", JSON.stringify(messages));
return formData;
}
function setPromptText(transcript) {
LoggingModule_js_1.logger.info(`Merged transcript: ${transcript}`);
const textarea = document.getElementById("saypi-prompt");
if ((0, UserAgentModule_js_1.isMobileView)()) {
// if transcript is > 1000 characters, truncate it to 999 characters plus an ellipsis
if (transcript.length > 1000) {
transcript = `${transcript.substring(0, 999)}…`;
console.warn(`Transcript was too long for Pi. Truncated to 999 characters, losing the following text: ... ${transcript.substring(999)}`);
}
EventModule_js_1.default.setNativeValue(textarea, transcript);
EventBus_js_1.default.emit("saypi:autoSubmit");
}
else {
EventModule_js_1.default.simulateTyping(textarea, `${transcript} `);
}
}
exports.setPromptText = setPromptText;
function mergeTranscripts(transcripts) {
const sortedKeys = Object.keys(transcripts)
.map(Number)
.sort((a, b) => a - b);
const sortedTranscripts = [];
for (const key of sortedKeys) {
sortedTranscripts.push(transcripts[key].trim());
}
return sortedTranscripts.join(" ");
}
exports.mergeTranscripts = mergeTranscripts;
/***/ }),
/***/ 6906:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.machine = exports.calculateDelay = void 0;
const ButtonModule_js_1 = __webpack_require__(6601);
const xstate_1 = __webpack_require__(4679);
const AnimationModule_js_1 = __importDefault(__webpack_require__(9744));
const UserAgentModule_js_1 = __webpack_require__(4008);
const TranscriptionModule_1 = __webpack_require__(8673);
const EventBus_1 = __importDefault(__webpack_require__(7635));
/* helper functions */
function calculateDelay(timeUserStoppedSpeaking, probabilityFinished, tempo, maxDelay) {
// Get the current time (in milliseconds)
const currentTime = new Date().getTime();
// Calculate the time elapsed since the user stopped speaking (in milliseconds)
const timeElapsed = currentTime - timeUserStoppedSpeaking;
// We invert the tempo because a faster speech (tempo approaching 1) should reduce the delay
let tempoFactor = 1 - tempo;
// Calculate the combined probability factor
let combinedProbability = probabilityFinished * tempoFactor;
// The combined factor influences the initial delay
const initialDelay = combinedProbability * maxDelay;
// Calculate the final delay after accounting for the time already elapsed
const finalDelay = Math.max(initialDelay - timeElapsed, 0);
return finalDelay;
}
exports.calculateDelay = calculateDelay;
/* external actions */
const clearTranscripts = (0, xstate_1.assign)({
transcriptions: () => ({}),
});
exports.machine = (0, xstate_1.createMachine)({
context: {
transcriptions: {},
lastState: "inactive",
timeUserStoppedSpeaking: 0,
},
id: "sayPi",
initial: "inactive",
states: {
inactive: {
description: "Idle state, not listening or speaking. Privacy mode.",
exit: (0, xstate_1.assign)({ lastState: "inactive" }),
on: {
"saypi:call": {
target: "#sayPi.listening.recording",
actions: [
{
type: "callStarted",
},
{
type: "startRecording",
},
],
description: 'Enable the VAD microphone.\nAka "call" Pi.\nStarts active listening.',
},
"saypi:piSpeaking": {
target: "#sayPi.responding.piSpeaking",
},
},
},
errors: {
description: "Error parent state.",
after: {
"10000": [
{
target: "#sayPi.listening",
actions: [],
description: "Reset to the idle state and clear errors.",
},
{
internal: false,
},
],
},
initial: "transcribeFailed",
states: {
transcribeFailed: {
description: "The /transcribe API responded with an error.",
entry: {
type: "startAnimation",
params: {
animation: "error",
},
},
exit: {
type: "stopAnimation",
params: {
animation: "error",
},
},
type: "final",
},
micError: {
description: "No audio input detected",
entry: {
type: "showNotification",
params: {
icon: "muted-microphone",
},
},
exit: {
type: "dismissNotification",
},
type: "final",
},
},
},
listening: {
description: "Actively listening for user input. Simultaneously recording and transcribing user speech. Gentle pulsing animation.",
entry: [
{
type: "stopAllAnimations",
},
{
type: "acquireMicrophone",
},
],
exit: (0, xstate_1.assign)({ lastState: "listening" }),
states: {
recording: {
description: "Microphone is on and VAD is actively listening for user speech.",
initial: "notSpeaking",
states: {
notSpeaking: {
description: "Microphone is recording but no speech is detected.",
on: {
"saypi:userFinishedSpeaking": {
target: "#sayPi.inactive",
},
"saypi:userSpeaking": {
target: "userSpeaking",
},
},
},
userSpeaking: {
description: "User is speaking and being recorded by the microphone.\nWaveform animation.",
entry: {
type: "startAnimation",
params: {
animation: "userSpeaking",
},
},
exit: {
type: "stopAnimation",
params: {
animation: "userSpeaking",
},
},
on: {
"saypi:userStoppedSpeaking": [
{
target: [
"notSpeaking",
"#sayPi.listening.converting.transcribing",
],
cond: "hasAudio",
actions: [
(0, xstate_1.assign)({
timeUserStoppedSpeaking: () => new Date().getTime(),
}),
{
type: "transcribeAudio",
},
],
},
{
target: "notSpeaking",
cond: "hasNoAudio",
},
],
},
},
},
on: {
"saypi:hangup": {
target: "#sayPi.inactive",
actions: [
{
type: "stopRecording",
},
{
type: "releaseMicrophone",
},
{
type: "callEnded",
},
],
description: 'Disable the VAD microphone.\n Aka "call" Pi.\n Stops active listening.',
},
},
},
converting: {
initial: "accumulating",
states: {
accumulating: {
description: "Accumulating and assembling audio transcriptions into a cohesive prompt.\nSubmits a prompt when a threshold is reached.",
after: {
submissionDelay: {
target: "submitting",
cond: "submissionConditionsMet",
description: "Submit combined transcript to Pi.",
},
},
on: {
"saypi:transcribed": {
target: "accumulating",
actions: {
type: "handleTranscriptionResponse",
},
description: "Transcribed speech to text (out of sequence response).",
},
"saypi:transcribeFailed": {
target: "#sayPi.errors.transcribeFailed",
description: "Out of sequence error response from the /transcribe API",
},
"saypi:transcribedEmpty": {
target: "#sayPi.errors.micError",
description: "Out of sequence empty response from the /transcribe API",
},
},
},
submitting: {
description: "Submitting prompt to Pi.",
entry: {
type: "mergeAndSubmitTranscript",
},
exit: [clearTranscripts, TranscriptionModule_1.clearPendingTranscriptions],
always: {
target: "accumulating",
},
},
transcribing: {
description: "Transcribing audio to text.\nCard flip animation.",
entry: {
type: "startAnimation",
params: {
animation: "transcribing",
},
},
exit: {
type: "stopAnimation",
params: {
animation: "transcribing",
},
},
on: {
"saypi:transcribed": {
target: "accumulating",
actions: {
type: "handleTranscriptionResponse",
},
description: "Successfully transcribed user audio to text.",
},
"saypi:transcribeFailed": {
target: "#sayPi.errors.transcribeFailed",
description: "Received an error response from the /transcribe API",
},
"saypi:transcribedEmpty": {
target: "#sayPi.errors.micError",
description: "Received an empty response from the /transcribe API (no speech detected)",
},
},
},
},
},
},
on: {
"saypi:piSpeaking": {
target: "#sayPi.responding.piSpeaking",
},
},
type: "parallel",
},
responding: {
description: "Pi is responding. Synthesised speech is playing or waiting to play.",
entry: {
type: "disableCallButton",
},
exit: {
type: "enableCallButton",
},
initial: "piSpeaking",
states: {
piSpeaking: {
description: "Pi's synthesised speech audio is playing.\nPlayful animation.",
entry: {
type: "startAnimation",
params: {
animation: "piSpeaking",
},
},
exit: {
type: "stopAnimation",
params: {
animation: "piSpeaking",
},
},
on: {
"saypi:piStoppedSpeaking": [
{
target: "#sayPi.listening",
cond: "wasListening",
},
{
target: "#sayPi.inactive",
cond: "wasInactive",
},
],
"saypi:userSpeaking": {
target: "#sayPi.listening.recording.userSpeaking",
},
"saypi:piFinishedSpeaking": {
target: "#sayPi.listening",
},
},
},
},
},
},
predictableActionArguments: true,
preserveActionOrder: true,
}, {
actions: {
stopAllAnimations: (context, event) => {
AnimationModule_js_1.default.stopAllAnimations();
},
startAnimation: (context, event, { action }) => {
AnimationModule_js_1.default.startAnimation(action.params.animation);
},
stopAnimation: (context, event, { action }) => {
AnimationModule_js_1.default.stopAnimation(action.params.animation);
},
transcribeAudio: (context, event) => {
const audioBlob = event.blob;
if (audioBlob) {
(0, TranscriptionModule_1.uploadAudioWithRetry)(audioBlob, event.duration, context.transcriptions);
}
},
handleTranscriptionResponse: (SayPiContext, event) => {
console.log("handleTranscriptionResponse", event);
const transcription = event.text;
const sequenceNumber = event.sequenceNumber;
SayPiContext.transcriptions[sequenceNumber] = transcription;
},
acquireMicrophone: (context, event) => {
// warmup the microphone on idle in mobile view,
// since there's no mouseover event to trigger it
if ((0, UserAgentModule_js_1.isMobileView)()) {
EventBus_1.default.emit("audio:setupRecording");
}
},
startRecording: (context, event) => {
EventBus_1.default.emit("audio:startRecording");
},
stopRecording: (context, event) => {
EventBus_1.default.emit("audio:stopRecording");
},
showNotification: (context, event, { action }) => {
const icon = action.params.icon;
const message = action.params.message;
ButtonModule_js_1.buttonModule.showNotification({ icon, message });
},
dismissNotification: () => {
ButtonModule_js_1.buttonModule.dismissNotification();
},
mergeAndSubmitTranscript: (context) => {
const prompt = (0, TranscriptionModule_1.mergeTranscripts)(context.transcriptions).trim();
if (prompt)
(0, TranscriptionModule_1.setPromptText)(prompt);
},
callStarted: () => {
ButtonModule_js_1.buttonModule.callActive();
},
callEnded: () => {
ButtonModule_js_1.buttonModule.callInactive();
},
disableCallButton: () => {
ButtonModule_js_1.buttonModule.disableCallButton();
},
enableCallButton: () => {
ButtonModule_js_1.buttonModule.enableCallButton();
},
},
services: {},
guards: {
hasAudio: (context, event) => {
if (event.type === "saypi:userStoppedSpeaking") {
event = event;
return event.blob !== undefined && event.duration > 0;
}
return false;
},
hasNoAudio: (context, event) => {
if (event.type === "saypi:userStoppedSpeaking") {
event = event;
return (event.blob === undefined ||
event.blob.size === 0 ||
event.duration === 0);
}
return false;
},
submissionConditionsMet: (context, event, meta) => {
const { state } = meta;
const allowedState = !(state.matches("listening.recording.userSpeaking") ||
state.matches("listening.converting.transcribing"));
const empty = Object.keys(context.transcriptions).length === 0;
const pending = (0, TranscriptionModule_1.isTranscriptionPending)();
const ready = allowedState && !empty && !pending;
return ready;
},
wasListening: (context) => {
return context.lastState === "listening";
},
wasInactive: (context) => {
return context.lastState === "inactive";
},
},
delays: {
submissionDelay: (context, event) => {
// check if the event is a transcription event
if (event.type !== "saypi:transcribed") {
return 0;
}
else {
event = event;
}
const maxDelay = 10000; // 10 seconds in milliseconds
// Calculate the initial delay based on pFinishedSpeaking
let probabilityFinished = 1;
if (event.pFinishedSpeaking !== undefined) {
probabilityFinished = event.pFinishedSpeaking;
}
// Incorporate the tempo into the delay, defaulting to 0.5 (average tempo) if undefined
let tempo = event.tempo !== undefined ? event.tempo : 0.5;
const finalDelay = calculateDelay(context.timeUserStoppedSpeaking, probabilityFinished, tempo, maxDelay);
console.log("Waiting for", (finalDelay / 1000).toFixed(1), "seconds before submitting");
return finalDelay;
},
},
});
/***/ }),
/***/ 8933:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Xg: () => (/* binding */ createDeferredActor),
/* harmony export */ f3: () => (/* binding */ isSpawnedActor),
/* harmony export */ mu: () => (/* binding */ createInvocableActor),
/* harmony export */ vk: () => (/* binding */ toActorRef)
/* harmony export */ });
/* unused harmony exports createNullActor, isActor */
/* harmony import */ var _virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3056);
/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9823);
/* harmony import */ var _serviceScope_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(797);
function createNullActor(id) {
var _a;
return _a = {
id: id,
send: function () {
return void 0;
},
subscribe: function () {
return {
unsubscribe: function () {
return void 0;
}
};
},
getSnapshot: function () {
return undefined;
},
toJSON: function () {
return {
id: id
};
}
}, _a[_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .symbolObservable */ .L$] = function () {
return this;
}, _a;
}
/**
* Creates a deferred actor that is able to be invoked given the provided
* invocation information in its `.meta` value.
*
* @param invokeDefinition The meta information needed to invoke the actor.
*/
function createInvocableActor(invokeDefinition, machine, context, _event) {
var _a;
var invokeSrc = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .toInvokeSource */ .j)(invokeDefinition.src);
var serviceCreator = (_a = machine === null || machine === void 0 ? void 0 : machine.options.services) === null || _a === void 0 ? void 0 : _a[invokeSrc.type];
var resolvedData = invokeDefinition.data ? (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .mapContext */ .QX)(invokeDefinition.data, context, _event) : undefined;
var tempActor = serviceCreator ? createDeferredActor(serviceCreator, invokeDefinition.id, resolvedData) : createNullActor(invokeDefinition.id); // @ts-ignore
tempActor.meta = invokeDefinition;
return tempActor;
}
function createDeferredActor(entity, id, data) {
var tempActor = createNullActor(id); // @ts-ignore
tempActor.deferred = true;
if ((0,_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .isMachine */ .O4)(entity)) {
// "mute" the existing service scope so potential spawned actors within the `.initialState` stay deferred here
var initialState_1 = tempActor.state = (0,_serviceScope_js__WEBPACK_IMPORTED_MODULE_1__/* .provide */ .J)(undefined, function () {
return (data ? entity.withContext(data) : entity).initialState;
});
tempActor.getSnapshot = function () {
return initialState_1;
};
}
return tempActor;
}
function isActor(item) {
try {
return typeof item.send === 'function';
} catch (e) {
return false;
}
}
function isSpawnedActor(item) {
return isActor(item) && 'id' in item;
} // TODO: refactor the return type, this could be written in a better way but it's best to avoid unneccessary breaking changes now
function toActorRef(actorRefLike) {
var _a;
return (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((_a = {
subscribe: function () {
return {
unsubscribe: function () {
return void 0;
}
};
},
id: 'anonymous',
getSnapshot: function () {
return undefined;
}
}, _a[_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .symbolObservable */ .L$] = function () {
return this;
}, _a), actorRefLike);
}
/***/ }),
/***/ 629:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ C: () => (/* binding */ createMachine),
/* harmony export */ J: () => (/* binding */ Machine)
/* harmony export */ });
/* harmony import */ var _StateNode_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8889);
/* harmony import */ var _environment_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4066);
var warned = false;
function Machine(config, options, initialContext) {
if (initialContext === void 0) {
initialContext = config.context;
}
return new _StateNode_js__WEBPACK_IMPORTED_MODULE_0__/* .StateNode */ .n(config, options, initialContext);
}
function createMachine(config, options) {
if (!_environment_js__WEBPACK_IMPORTED_MODULE_1__/* .IS_PRODUCTION */ .M && !('predictableActionArguments' in config) && !warned) {
warned = true;
console.warn('It is highly recommended to set `predictableActionArguments` to `true` when using `createMachine`. https://xstate.js.org/docs/guides/actions.html');
}
return new _StateNode_js__WEBPACK_IMPORTED_MODULE_0__/* .StateNode */ .n(config, options);
}
/***/ }),
/***/ 4911:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ TL: () => (/* binding */ isStateConfig),
/* harmony export */ ZM: () => (/* binding */ State),
/* harmony export */ j1: () => (/* binding */ bindActionToState),
/* harmony export */ j_: () => (/* binding */ stateValuesEqual)
/* harmony export */ });
/* unused harmony export isState */
/* harmony import */ var _virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3056);
/* harmony import */ var _constants_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(7353);
/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9823);
/* harmony import */ var _stateUtils_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6115);
/* harmony import */ var _actions_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(375);
/* harmony import */ var _environment_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(4066);
function stateValuesEqual(a, b) {
if (a === b) {
return true;
}
if (a === undefined || b === undefined) {
return false;
}
if ((0,_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .isString */ .HD)(a) || (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .isString */ .HD)(b)) {
return a === b;
}
var aKeys = Object.keys(a);
var bKeys = Object.keys(b);
return aKeys.length === bKeys.length && aKeys.every(function (key) {
return stateValuesEqual(a[key], b[key]);
});
}
function isStateConfig(state) {
if (typeof state !== 'object' || state === null) {
return false;
}
return 'value' in state && '_event' in state;
}
/**
* @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
*/
var isState = (/* unused pure expression or super */ null && (isStateConfig));
function bindActionToState(action, state) {
var exec = action.exec;
var boundAction = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__assign */ .pi)({}, action), {
exec: exec !== undefined ? function () {
return exec(state.context, state.event, {
action: action,
state: state,
_event: state._event
});
} : undefined
});
return boundAction;
}
var State =
/*#__PURE__*/
/** @class */
function () {
/**
* Creates a new State instance.
* @param value The state value
* @param context The extended state
* @param historyValue The tree representing historical values of the state nodes
* @param history The previous state
* @param actions An array of action objects to execute as side-effects
* @param activities A mapping of activities and whether they are started (`true`) or stopped (`false`).
* @param meta
* @param events Internal event queue. Should be empty with run-to-completion semantics.
* @param configuration
*/
function State(config) {
var _this = this;
var _a;
this.actions = [];
this.activities = _constants_js__WEBPACK_IMPORTED_MODULE_2__/* .EMPTY_ACTIVITY_MAP */ .qP;
this.meta = {};
this.events = [];
this.value = config.value;
this.context = config.context;
this._event = config._event;
this._sessionid = config._sessionid;
this.event = this._event.data;
this.historyValue = config.historyValue;
this.history = config.history;
this.actions = config.actions || [];
this.activities = config.activities || _constants_js__WEBPACK_IMPORTED_MODULE_2__/* .EMPTY_ACTIVITY_MAP */ .qP;
this.meta = (0,_stateUtils_js__WEBPACK_IMPORTED_MODULE_3__/* .getMeta */ .xZ)(config.configuration);
this.events = config.events || [];
this.matches = this.matches.bind(this);
this.toStrings = this.toStrings.bind(this);
this.configuration = config.configuration;
this.transitions = config.transitions;
this.children = config.children;
this.done = !!config.done;
this.tags = (_a = Array.isArray(config.tags) ? new Set(config.tags) : config.tags) !== null && _a !== void 0 ? _a : new Set();
this.machine = config.machine;
Object.defineProperty(this, 'nextEvents', {
get: function () {
return (0,_stateUtils_js__WEBPACK_IMPORTED_MODULE_3__/* .nextEvents */ .nJ)(_this.configuration);
}
});
}
/**
* Creates a new State instance for the given `stateValue` and `context`.
* @param stateValue
* @param context
*/
State.from = function (stateValue, context) {
if (stateValue instanceof State) {
if (stateValue.context !== context) {
return new State({
value: stateValue.value,
context: context,
_event: stateValue._event,
_sessionid: null,
historyValue: stateValue.historyValue,
history: stateValue.history,
actions: [],
activities: stateValue.activities,
meta: {},
events: [],
configuration: [],
transitions: [],
children: {}
});
}
return stateValue;
}
var _event = _actions_js__WEBPACK_IMPORTED_MODULE_4__.initEvent;
return new State({
value: stateValue,
context: context,
_event: _event,
_sessionid: null,
historyValue: undefined,
history: undefined,
actions: [],
activities: undefined,
meta: undefined,
events: [],
configuration: [],
transitions: [],
children: {}
});
};
/**
* Creates a new State instance for the given `config`.
* @param config The state config
*/
State.create = function (config) {
return new State(config);
};
/**
* Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).
* @param stateValue
* @param context
*/
State.inert = function (stateValue, context) {
if (stateValue instanceof State) {
if (!stateValue.actions.length) {
return stateValue;
}
var _event = _actions_js__WEBPACK_IMPORTED_MODULE_4__.initEvent;
return new State({
value: stateValue.value,
context: context,
_event: _event,
_sessionid: null,
historyValue: stateValue.historyValue,
history: stateValue.history,
activities: stateValue.activities,
configuration: stateValue.configuration,
transitions: [],
children: {}
});
}
return State.from(stateValue, context);
};
/**
* Returns an array of all the string leaf state node paths.
* @param stateValue
* @param delimiter The character(s) that separate each subpath in the string state node path.
*/
State.prototype.toStrings = function (stateValue, delimiter) {
var _this = this;
if (stateValue === void 0) {
stateValue = this.value;
}
if (delimiter === void 0) {
delimiter = '.';
}
if ((0,_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .isString */ .HD)(stateValue)) {
return [stateValue];
}
var valueKeys = Object.keys(stateValue);
return valueKeys.concat.apply(valueKeys, (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__spreadArray */ .ev)([], (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__read */ .CR)(valueKeys.map(function (key) {
return _this.toStrings(stateValue[key], delimiter).map(function (s) {
return key + delimiter + s;
});
})), false));
};
State.prototype.toJSON = function () {
var _a = this;
_a.configuration;
_a.transitions;
var tags = _a.tags;
_a.machine;
var jsonValues = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__rest */ ._T)(_a, ["configuration", "transitions", "tags", "machine"]);
return (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__assign */ .pi)({}, jsonValues), {
tags: Array.from(tags)
});
};
State.prototype.matches = function (parentStateValue) {
return (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .matchesState */ .W)(parentStateValue, this.value);
};
/**
* Whether the current state configuration has a state node with the specified `tag`.
* @param tag
*/
State.prototype.hasTag = function (tag) {
return this.tags.has(tag);
};
/**
* Determines whether sending the `event` will cause a non-forbidden transition
* to be selected, even if the transitions have no actions nor
* change the state value.
*
* @param event The event to test
* @returns Whether the event will cause a transition
*/
State.prototype.can = function (event) {
var _a;
if (_environment_js__WEBPACK_IMPORTED_MODULE_5__/* .IS_PRODUCTION */ .M) {
(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .warn */ .ZK)(!!this.machine, "state.can(...) used outside of a machine-created State object; this will always return false.");
}
var transitionData = (_a = this.machine) === null || _a === void 0 ? void 0 : _a.getTransitionData(this, event);
return !!(transitionData === null || transitionData === void 0 ? void 0 : transitionData.transitions.length) && // Check that at least one transition is not forbidden
transitionData.transitions.some(function (t) {
return t.target !== undefined || t.actions.length;
});
};
return State;
}();
/***/ }),
/***/ 8889:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
n: () => (/* binding */ StateNode)
});
// EXTERNAL MODULE: ./node_modules/xstate/es/_virtual/_tslib.js
var _tslib = __webpack_require__(3056);
// EXTERNAL MODULE: ./node_modules/xstate/es/utils.js
var utils = __webpack_require__(9823);
// EXTERNAL MODULE: ./node_modules/xstate/es/State.js
var State = __webpack_require__(4911);
// EXTERNAL MODULE: ./node_modules/xstate/es/actionTypes.js
var actionTypes = __webpack_require__(3884);
// EXTERNAL MODULE: ./node_modules/xstate/es/actions.js
var es_actions = __webpack_require__(375);
// EXTERNAL MODULE: ./node_modules/xstate/es/environment.js
var environment = __webpack_require__(4066);
// EXTERNAL MODULE: ./node_modules/xstate/es/constants.js
var constants = __webpack_require__(7353);
// EXTERNAL MODULE: ./node_modules/xstate/es/stateUtils.js
var stateUtils = __webpack_require__(6115);
// EXTERNAL MODULE: ./node_modules/xstate/es/Actor.js
var Actor = __webpack_require__(8933);
;// CONCATENATED MODULE: ./node_modules/xstate/es/invokeUtils.js
function toInvokeSource(src) {
if (typeof src === 'string') {
var simpleSrc = {
type: src
};
simpleSrc.toString = function () {
return src;
}; // v4 compat - TODO: remove in v5
return simpleSrc;
}
return src;
}
function toInvokeDefinition(invokeConfig) {
return (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({
type: actionTypes.invoke
}, invokeConfig), {
toJSON: function () {
invokeConfig.onDone;
invokeConfig.onError;
var invokeDef = (0,_tslib/* __rest */._T)(invokeConfig, ["onDone", "onError"]);
return (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, invokeDef), {
type: actionTypes.invoke,
src: toInvokeSource(invokeConfig.src)
});
}
});
}
;// CONCATENATED MODULE: ./node_modules/xstate/es/StateNode.js
var NULL_EVENT = '';
var STATE_IDENTIFIER = '#';
var WILDCARD = '*';
var EMPTY_OBJECT = {};
var isStateId = function (str) {
return str[0] === STATE_IDENTIFIER;
};
var createDefaultOptions = function () {
return {
actions: {},
guards: {},
services: {},
activities: {},
delays: {}
};
};
var validateArrayifiedTransitions = function (stateNode, event, transitions) {
var hasNonLastUnguardedTarget = transitions.slice(0, -1).some(function (transition) {
return !('cond' in transition) && !('in' in transition) && ((0,utils/* isString */.HD)(transition.target) || (0,utils/* isMachine */.O4)(transition.target));
});
var eventText = event === NULL_EVENT ? 'the transient event' : "event '".concat(event, "'");
(0,utils/* warn */.ZK)(!hasNonLastUnguardedTarget, "One or more transitions for ".concat(eventText, " on state '").concat(stateNode.id, "' are unreachable. ") + "Make sure that the default transition is the last one defined.");
};
var StateNode =
/*#__PURE__*/
/** @class */
function () {
function StateNode(
/**
* The raw config used to create the machine.
*/
config, options,
/**
* The initial extended state
*/
_context, // TODO: this is unsafe, but we're removing it in v5 anyway
_stateInfo) {
if (_context === void 0) {
_context = 'context' in config ? config.context : undefined;
}
var _this = this;
var _a;
this.config = config;
this._context = _context;
/**
* The order this state node appears. Corresponds to the implicit SCXML document order.
*/
this.order = -1;
this.__xstatenode = true;
this.__cache = {
events: undefined,
relativeValue: new Map(),
initialStateValue: undefined,
initialState: undefined,
on: undefined,
transitions: undefined,
candidates: {},
delayedTransitions: undefined
};
this.idMap = {};
this.tags = [];
this.options = Object.assign(createDefaultOptions(), options);
this.parent = _stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.parent;
this.key = this.config.key || (_stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.key) || this.config.id || '(machine)';
this.machine = this.parent ? this.parent.machine : this;
this.path = this.parent ? this.parent.path.concat(this.key) : [];
this.delimiter = this.config.delimiter || (this.parent ? this.parent.delimiter : constants/* STATE_DELIMITER */.iS);
this.id = this.config.id || (0,_tslib/* __spreadArray */.ev)([this.machine.key], (0,_tslib/* __read */.CR)(this.path), false).join(this.delimiter);
this.version = this.parent ? this.parent.version : this.config.version;
this.type = this.config.type || (this.config.parallel ? 'parallel' : this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
this.schema = this.parent ? this.machine.schema : (_a = this.config.schema) !== null && _a !== void 0 ? _a : {};
this.description = this.config.description;
if (!environment/* IS_PRODUCTION */.M) {
(0,utils/* warn */.ZK)(!('parallel' in this.config), "The \"parallel\" property is deprecated and will be removed in version 4.1. ".concat(this.config.parallel ? "Replace with `type: 'parallel'`" : "Use `type: '".concat(this.type, "'`"), " in the config for state node '").concat(this.id, "' instead."));
}
this.initial = this.config.initial;
this.states = this.config.states ? (0,utils/* mapValues */.Q8)(this.config.states, function (stateConfig, key) {
var _a;
var stateNode = new StateNode(stateConfig, {}, undefined, {
parent: _this,
key: key
});
Object.assign(_this.idMap, (0,_tslib/* __assign */.pi)((_a = {}, _a[stateNode.id] = stateNode, _a), stateNode.idMap));
return stateNode;
}) : EMPTY_OBJECT; // Document order
var order = 0;
function dfs(stateNode) {
var e_1, _a;
stateNode.order = order++;
try {
for (var _b = (0,_tslib/* __values */.XA)((0,stateUtils/* getAllChildren */.nI)(stateNode)), _c = _b.next(); !_c.done; _c = _b.next()) {
var child = _c.value;
dfs(child);
}
} catch (e_1_1) {
e_1 = {
error: e_1_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_1) throw e_1.error;
}
}
}
dfs(this); // History config
this.history = this.config.history === true ? 'shallow' : this.config.history || false;
this._transient = !!this.config.always || (!this.config.on ? false : Array.isArray(this.config.on) ? this.config.on.some(function (_a) {
var event = _a.event;
return event === NULL_EVENT;
}) : NULL_EVENT in this.config.on);
this.strict = !!this.config.strict; // TODO: deprecate (entry)
this.onEntry = (0,utils/* toArray */.qo)(this.config.entry || this.config.onEntry).map(function (action) {
return (0,es_actions.toActionObject)(action);
}); // TODO: deprecate (exit)
this.onExit = (0,utils/* toArray */.qo)(this.config.exit || this.config.onExit).map(function (action) {
return (0,es_actions.toActionObject)(action);
});
this.meta = this.config.meta;
this.doneData = this.type === 'final' ? this.config.data : undefined;
this.invoke = (0,utils/* toArray */.qo)(this.config.invoke).map(function (invokeConfig, i) {
var _a, _b;
if ((0,utils/* isMachine */.O4)(invokeConfig)) {
var invokeId = (0,utils/* createInvokeId */.bx)(_this.id, i);
_this.machine.options.services = (0,_tslib/* __assign */.pi)((_a = {}, _a[invokeId] = invokeConfig, _a), _this.machine.options.services);
return toInvokeDefinition({
src: invokeId,
id: invokeId
});
} else if ((0,utils/* isString */.HD)(invokeConfig.src)) {
var invokeId = invokeConfig.id || (0,utils/* createInvokeId */.bx)(_this.id, i);
return toInvokeDefinition((0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, invokeConfig), {
id: invokeId,
src: invokeConfig.src
}));
} else if ((0,utils/* isMachine */.O4)(invokeConfig.src) || (0,utils/* isFunction */.mf)(invokeConfig.src)) {
var invokeId = invokeConfig.id || (0,utils/* createInvokeId */.bx)(_this.id, i);
_this.machine.options.services = (0,_tslib/* __assign */.pi)((_b = {}, _b[invokeId] = invokeConfig.src, _b), _this.machine.options.services);
return toInvokeDefinition((0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({
id: invokeId
}, invokeConfig), {
src: invokeId
}));
} else {
var invokeSource = invokeConfig.src;
return toInvokeDefinition((0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({
id: (0,utils/* createInvokeId */.bx)(_this.id, i)
}, invokeConfig), {
src: invokeSource
}));
}
});
this.activities = (0,utils/* toArray */.qo)(this.config.activities).concat(this.invoke).map(function (activity) {
return (0,es_actions.toActivityDefinition)(activity);
});
this.transition = this.transition.bind(this);
this.tags = (0,utils/* toArray */.qo)(this.config.tags); // TODO: this is the real fix for initialization once
// state node getters are deprecated
// if (!this.parent) {
// this._init();
// }
}
StateNode.prototype._init = function () {
if (this.__cache.transitions) {
return;
}
(0,stateUtils/* getAllStateNodes */.ac)(this).forEach(function (stateNode) {
return stateNode.on;
});
};
/**
* Clones this state machine with custom options and context.
*
* @param options Options (actions, guards, activities, services) to recursively merge with the existing options.
* @param context Custom context (will override predefined context)
*/
StateNode.prototype.withConfig = function (options, context) {
var _a = this.options,
actions = _a.actions,
activities = _a.activities,
guards = _a.guards,
services = _a.services,
delays = _a.delays;
return new StateNode(this.config, {
actions: (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, actions), options.actions),
activities: (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, activities), options.activities),
guards: (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, guards), options.guards),
services: (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, services), options.services),
delays: (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, delays), options.delays)
}, context !== null && context !== void 0 ? context : this.context);
};
/**
* Clones this state machine with custom context.
*
* @param context Custom context (will override predefined context, not recursive)
*/
StateNode.prototype.withContext = function (context) {
return new StateNode(this.config, this.options, context);
};
Object.defineProperty(StateNode.prototype, "context", {
get: function () {
return (0,utils/* isFunction */.mf)(this._context) ? this._context() : this._context;
},
enumerable: false,
configurable: true
});
Object.defineProperty(StateNode.prototype, "definition", {
/**
* The well-structured state node definition.
*/
get: function () {
return {
id: this.id,
key: this.key,
version: this.version,
context: this.context,
type: this.type,
initial: this.initial,
history: this.history,
states: (0,utils/* mapValues */.Q8)(this.states, function (state) {
return state.definition;
}),
on: this.on,
transitions: this.transitions,
entry: this.onEntry,
exit: this.onExit,
activities: this.activities || [],
meta: this.meta,
order: this.order || -1,
data: this.doneData,
invoke: this.invoke,
description: this.description,
tags: this.tags
};
},
enumerable: false,
configurable: true
});
StateNode.prototype.toJSON = function () {
return this.definition;
};
Object.defineProperty(StateNode.prototype, "on", {
/**
* The mapping of events to transitions.
*/
get: function () {
if (this.__cache.on) {
return this.__cache.on;
}
var transitions = this.transitions;
return this.__cache.on = transitions.reduce(function (map, transition) {
map[transition.eventType] = map[transition.eventType] || [];
map[transition.eventType].push(transition);
return map;
}, {});
},
enumerable: false,
configurable: true
});
Object.defineProperty(StateNode.prototype, "after", {
get: function () {
return this.__cache.delayedTransitions || (this.__cache.delayedTransitions = this.getDelayedTransitions(), this.__cache.delayedTransitions);
},
enumerable: false,
configurable: true
});
Object.defineProperty(StateNode.prototype, "transitions", {
/**
* All the transitions that can be taken from this state node.
*/
get: function () {
return this.__cache.transitions || (this.__cache.transitions = this.formatTransitions(), this.__cache.transitions);
},
enumerable: false,
configurable: true
});
StateNode.prototype.getCandidates = function (eventName) {
if (this.__cache.candidates[eventName]) {
return this.__cache.candidates[eventName];
}
var transient = eventName === NULL_EVENT;
var candidates = this.transitions.filter(function (transition) {
var sameEventType = transition.eventType === eventName; // null events should only match against eventless transitions
return transient ? sameEventType : sameEventType || transition.eventType === WILDCARD;
});
this.__cache.candidates[eventName] = candidates;
return candidates;
};
/**
* All delayed transitions from the config.
*/
StateNode.prototype.getDelayedTransitions = function () {
var _this = this;
var afterConfig = this.config.after;
if (!afterConfig) {
return [];
}
var mutateEntryExit = function (delay, i) {
var delayRef = (0,utils/* isFunction */.mf)(delay) ? "".concat(_this.id, ":delay[").concat(i, "]") : delay;
var eventType = (0,es_actions.after)(delayRef, _this.id);
_this.onEntry.push((0,es_actions.send)(eventType, {
delay: delay
}));
_this.onExit.push((0,es_actions.cancel)(eventType));
return eventType;
};
var delayedTransitions = (0,utils/* isArray */.kJ)(afterConfig) ? afterConfig.map(function (transition, i) {
var eventType = mutateEntryExit(transition.delay, i);
return (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, transition), {
event: eventType
});
}) : (0,utils/* flatten */.xH)(Object.keys(afterConfig).map(function (delay, i) {
var configTransition = afterConfig[delay];
var resolvedTransition = (0,utils/* isString */.HD)(configTransition) ? {
target: configTransition
} : configTransition;
var resolvedDelay = !isNaN(+delay) ? +delay : delay;
var eventType = mutateEntryExit(resolvedDelay, i);
return (0,utils/* toArray */.qo)(resolvedTransition).map(function (transition) {
return (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, transition), {
event: eventType,
delay: resolvedDelay
});
});
}));
return delayedTransitions.map(function (delayedTransition) {
var delay = delayedTransition.delay;
return (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, _this.formatTransition(delayedTransition)), {
delay: delay
});
});
};
/**
* Returns the state nodes represented by the current state value.
*
* @param state The state value or State instance
*/
StateNode.prototype.getStateNodes = function (state) {
var _a;
var _this = this;
if (!state) {
return [];
}
var stateValue = state instanceof State/* State */.ZM ? state.value : (0,utils/* toStateValue */.WM)(state, this.delimiter);
if ((0,utils/* isString */.HD)(stateValue)) {
var initialStateValue = this.getStateNode(stateValue).initial;
return initialStateValue !== undefined ? this.getStateNodes((_a = {}, _a[stateValue] = initialStateValue, _a)) : [this, this.states[stateValue]];
}
var subStateKeys = Object.keys(stateValue);
var subStateNodes = [this];
subStateNodes.push.apply(subStateNodes, (0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)((0,utils/* flatten */.xH)(subStateKeys.map(function (subStateKey) {
return _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
}))), false));
return subStateNodes;
};
/**
* Returns `true` if this state node explicitly handles the given event.
*
* @param event The event in question
*/
StateNode.prototype.handles = function (event) {
var eventType = (0,utils/* getEventType */.x6)(event);
return this.events.includes(eventType);
};
/**
* Resolves the given `state` to a new `State` instance relative to this machine.
*
* This ensures that `.events` and `.nextEvents` represent the correct values.
*
* @param state The state to resolve
*/
StateNode.prototype.resolveState = function (state) {
var stateFromConfig = state instanceof State/* State */.ZM ? state : State/* State */.ZM.create(state);
var configuration = Array.from((0,stateUtils/* getConfiguration */.P_)([], this.getStateNodes(stateFromConfig.value)));
return new State/* State */.ZM((0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, stateFromConfig), {
value: this.resolve(stateFromConfig.value),
configuration: configuration,
done: (0,stateUtils/* isInFinalState */.Ij)(configuration, this),
tags: (0,stateUtils/* getTagsFromConfiguration */.Oe)(configuration),
machine: this.machine
}));
};
StateNode.prototype.transitionLeafNode = function (stateValue, state, _event) {
var stateNode = this.getStateNode(stateValue);
var next = stateNode.next(state, _event);
if (!next || !next.transitions.length) {
return this.next(state, _event);
}
return next;
};
StateNode.prototype.transitionCompoundNode = function (stateValue, state, _event) {
var subStateKeys = Object.keys(stateValue);
var stateNode = this.getStateNode(subStateKeys[0]);
var next = stateNode._transition(stateValue[subStateKeys[0]], state, _event);
if (!next || !next.transitions.length) {
return this.next(state, _event);
}
return next;
};
StateNode.prototype.transitionParallelNode = function (stateValue, state, _event) {
var e_2, _a;
var transitionMap = {};
try {
for (var _b = (0,_tslib/* __values */.XA)(Object.keys(stateValue)), _c = _b.next(); !_c.done; _c = _b.next()) {
var subStateKey = _c.value;
var subStateValue = stateValue[subStateKey];
if (!subStateValue) {
continue;
}
var subStateNode = this.getStateNode(subStateKey);
var next = subStateNode._transition(subStateValue, state, _event);
if (next) {
transitionMap[subStateKey] = next;
}
}
} catch (e_2_1) {
e_2 = {
error: e_2_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_2) throw e_2.error;
}
}
var stateTransitions = Object.keys(transitionMap).map(function (key) {
return transitionMap[key];
});
var enabledTransitions = (0,utils/* flatten */.xH)(stateTransitions.map(function (st) {
return st.transitions;
}));
var willTransition = stateTransitions.some(function (st) {
return st.transitions.length > 0;
});
if (!willTransition) {
return this.next(state, _event);
}
var configuration = (0,utils/* flatten */.xH)(Object.keys(transitionMap).map(function (key) {
return transitionMap[key].configuration;
}));
return {
transitions: enabledTransitions,
exitSet: (0,utils/* flatten */.xH)(stateTransitions.map(function (t) {
return t.exitSet;
})),
configuration: configuration,
source: state,
actions: (0,utils/* flatten */.xH)(Object.keys(transitionMap).map(function (key) {
return transitionMap[key].actions;
}))
};
};
StateNode.prototype._transition = function (stateValue, state, _event) {
// leaf node
if ((0,utils/* isString */.HD)(stateValue)) {
return this.transitionLeafNode(stateValue, state, _event);
} // hierarchical node
if (Object.keys(stateValue).length === 1) {
return this.transitionCompoundNode(stateValue, state, _event);
} // orthogonal node
return this.transitionParallelNode(stateValue, state, _event);
};
StateNode.prototype.getTransitionData = function (state, event) {
return this._transition(state.value, state, (0,utils/* toSCXMLEvent */.g5)(event));
};
StateNode.prototype.next = function (state, _event) {
var e_3, _a;
var _this = this;
var eventName = _event.name;
var actions = [];
var nextStateNodes = [];
var selectedTransition;
try {
for (var _b = (0,_tslib/* __values */.XA)(this.getCandidates(eventName)), _c = _b.next(); !_c.done; _c = _b.next()) {
var candidate = _c.value;
var cond = candidate.cond,
stateIn = candidate.in;
var resolvedContext = state.context;
var isInState = stateIn ? (0,utils/* isString */.HD)(stateIn) && isStateId(stateIn) ? // Check if in state by ID
state.matches((0,utils/* toStateValue */.WM)(this.getStateNodeById(stateIn).path, this.delimiter)) : // Check if in state by relative grandparent
(0,utils/* matchesState */.W)((0,utils/* toStateValue */.WM)(stateIn, this.delimiter), (0,utils/* path */.ET)(this.path.slice(0, -2))(state.value)) : true;
var guardPassed = false;
try {
guardPassed = !cond || (0,utils/* evaluateGuard */.vx)(this.machine, cond, resolvedContext, _event, state);
} catch (err) {
throw new Error("Unable to evaluate guard '".concat(cond.name || cond.type, "' in transition for event '").concat(eventName, "' in state node '").concat(this.id, "':\n").concat(err.message));
}
if (guardPassed && isInState) {
if (candidate.target !== undefined) {
nextStateNodes = candidate.target;
}
actions.push.apply(actions, (0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)(candidate.actions), false));
selectedTransition = candidate;
break;
}
}
} catch (e_3_1) {
e_3 = {
error: e_3_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_3) throw e_3.error;
}
}
if (!selectedTransition) {
return undefined;
}
if (!nextStateNodes.length) {
return {
transitions: [selectedTransition],
exitSet: [],
configuration: state.value ? [this] : [],
source: state,
actions: actions
};
}
var allNextStateNodes = (0,utils/* flatten */.xH)(nextStateNodes.map(function (stateNode) {
return _this.getRelativeStateNodes(stateNode, state.historyValue);
}));
var isInternal = !!selectedTransition.internal;
return {
transitions: [selectedTransition],
exitSet: isInternal ? [] : (0,utils/* flatten */.xH)(nextStateNodes.map(function (targetNode) {
return _this.getPotentiallyReenteringNodes(targetNode);
})),
configuration: allNextStateNodes,
source: state,
actions: actions
};
}; // even though the name of this function mentions reentry nodes
// we are pushing its result into `exitSet`
// that's because what we exit might be reentered (it's an invariant of reentrancy)
StateNode.prototype.getPotentiallyReenteringNodes = function (targetNode) {
if (this.order < targetNode.order) {
return [this];
}
var nodes = [];
var marker = this;
var possibleAncestor = targetNode;
while (marker && marker !== possibleAncestor) {
nodes.push(marker);
marker = marker.parent;
}
if (marker !== possibleAncestor) {
// we never got to `possibleAncestor`, therefore the initial `marker` "escapes" it
// it's in a different part of the tree so no states will be reentered for such an external transition
return [];
}
nodes.push(possibleAncestor);
return nodes;
};
StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState, predictableExec) {
var e_4, _a, e_5, _b;
var _this = this;
var prevConfig = prevState ? (0,stateUtils/* getConfiguration */.P_)([], this.getStateNodes(prevState.value)) : [];
var entrySet = new Set();
try {
for (var _c = (0,_tslib/* __values */.XA)(Array.from(resolvedConfig).sort(function (a, b) {
return a.order - b.order;
})), _d = _c.next(); !_d.done; _d = _c.next()) {
var sn = _d.value;
if (!(0,stateUtils/* has */.e$)(prevConfig, sn) || (0,stateUtils/* has */.e$)(transition.exitSet, sn) || sn.parent && entrySet.has(sn.parent)) {
entrySet.add(sn);
}
}
} catch (e_4_1) {
e_4 = {
error: e_4_1
};
} finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
} finally {
if (e_4) throw e_4.error;
}
}
try {
for (var prevConfig_1 = (0,_tslib/* __values */.XA)(prevConfig), prevConfig_1_1 = prevConfig_1.next(); !prevConfig_1_1.done; prevConfig_1_1 = prevConfig_1.next()) {
var sn = prevConfig_1_1.value;
if (!(0,stateUtils/* has */.e$)(resolvedConfig, sn) || (0,stateUtils/* has */.e$)(transition.exitSet, sn.parent)) {
transition.exitSet.push(sn);
}
}
} catch (e_5_1) {
e_5 = {
error: e_5_1
};
} finally {
try {
if (prevConfig_1_1 && !prevConfig_1_1.done && (_b = prevConfig_1.return)) _b.call(prevConfig_1);
} finally {
if (e_5) throw e_5.error;
}
}
transition.exitSet.sort(function (a, b) {
return b.order - a.order;
});
var entryStates = Array.from(entrySet).sort(function (a, b) {
return a.order - b.order;
});
var exitStates = new Set(transition.exitSet);
var doneEvents = (0,utils/* flatten */.xH)(entryStates.map(function (sn) {
var events = [];
if (sn.type !== 'final') {
return events;
}
var parent = sn.parent;
if (!parent.parent) {
return events;
}
events.push((0,es_actions.done)(sn.id, sn.doneData), // TODO: deprecate - final states should not emit done events for their own state.
(0,es_actions.done)(parent.id, sn.doneData ? (0,utils/* mapContext */.QX)(sn.doneData, currentContext, _event) : undefined));
var grandparent = parent.parent;
if (grandparent.type === 'parallel') {
if ((0,stateUtils/* getChildren */.G)(grandparent).every(function (parentNode) {
return (0,stateUtils/* isInFinalState */.Ij)(transition.configuration, parentNode);
})) {
events.push((0,es_actions.done)(grandparent.id));
}
}
return events;
}));
var entryActions = entryStates.map(function (stateNode) {
var entryActions = stateNode.onEntry;
var invokeActions = stateNode.activities.map(function (activity) {
return (0,es_actions.start)(activity);
});
return {
type: 'entry',
actions: (0,es_actions.toActionObjects)(predictableExec ? (0,_tslib/* __spreadArray */.ev)((0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)(entryActions), false), (0,_tslib/* __read */.CR)(invokeActions), false) : (0,_tslib/* __spreadArray */.ev)((0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)(invokeActions), false), (0,_tslib/* __read */.CR)(entryActions), false), _this.machine.options.actions)
};
}).concat({
type: 'state_done',
actions: doneEvents.map(function (event) {
return (0,es_actions.raise)(event);
})
});
var exitActions = Array.from(exitStates).map(function (stateNode) {
return {
type: 'exit',
actions: (0,es_actions.toActionObjects)((0,_tslib/* __spreadArray */.ev)((0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)(stateNode.onExit), false), (0,_tslib/* __read */.CR)(stateNode.activities.map(function (activity) {
return (0,es_actions.stop)(activity);
})), false), _this.machine.options.actions)
};
});
var actions = exitActions.concat({
type: 'transition',
actions: (0,es_actions.toActionObjects)(transition.actions, this.machine.options.actions)
}).concat(entryActions);
if (isDone) {
var stopActions = (0,es_actions.toActionObjects)((0,utils/* flatten */.xH)((0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)(resolvedConfig), false).sort(function (a, b) {
return b.order - a.order;
}).map(function (stateNode) {
return stateNode.onExit;
})), this.machine.options.actions).filter(function (action) {
return !(0,utils/* isRaisableAction */.vK)(action);
});
return actions.concat({
type: 'stop',
actions: stopActions
});
}
return actions;
};
/**
* Determines the next state given the current `state` and sent `event`.
*
* @param state The current State instance or state value
* @param event The event that was sent at the current state
* @param context The current context (extended state) of the current state
*/
StateNode.prototype.transition = function (state, event, context, exec) {
if (state === void 0) {
state = this.initialState;
}
var _event = (0,utils/* toSCXMLEvent */.g5)(event);
var currentState;
if (state instanceof State/* State */.ZM) {
currentState = context === undefined ? state : this.resolveState(State/* State */.ZM.from(state, context));
} else {
var resolvedStateValue = (0,utils/* isString */.HD)(state) ? this.resolve((0,utils/* pathToStateValue */.on)(this.getResolvedPath(state))) : this.resolve(state);
var resolvedContext = context !== null && context !== void 0 ? context : this.machine.context;
currentState = this.resolveState(State/* State */.ZM.from(resolvedStateValue, resolvedContext));
}
if (!environment/* IS_PRODUCTION */.M && _event.name === WILDCARD) {
throw new Error("An event cannot have the wildcard type ('".concat(WILDCARD, "')"));
}
if (this.strict) {
if (!this.events.includes(_event.name) && !(0,utils/* isBuiltInEvent */.JQ)(_event.name)) {
throw new Error("Machine '".concat(this.id, "' does not accept event '").concat(_event.name, "'"));
}
}
var stateTransition = this._transition(currentState.value, currentState, _event) || {
transitions: [],
configuration: [],
exitSet: [],
source: currentState,
actions: []
};
var prevConfig = (0,stateUtils/* getConfiguration */.P_)([], this.getStateNodes(currentState.value));
var resolvedConfig = stateTransition.configuration.length ? (0,stateUtils/* getConfiguration */.P_)(prevConfig, stateTransition.configuration) : prevConfig;
stateTransition.configuration = (0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)(resolvedConfig), false);
return this.resolveTransition(stateTransition, currentState, currentState.context, exec, _event);
};
StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent, predictableExec) {
var _a;
var currentActions = state.actions;
state = this.transition(state, _event, undefined, predictableExec); // Save original event to state
// TODO: this should be the raised event! Delete in V5 (breaking)
state._event = originalEvent;
state.event = originalEvent.data;
(_a = state.actions).unshift.apply(_a, (0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)(currentActions), false));
return state;
};
StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, predictableExec, _event) {
var e_6, _a, e_7, _b;
var _this = this;
if (_event === void 0) {
_event = es_actions.initEvent;
}
var configuration = stateTransition.configuration; // Transition will "apply" if:
// - this is the initial state (there is no current state)
// - OR there are transitions
var willTransition = !currentState || stateTransition.transitions.length > 0;
var resolvedConfiguration = willTransition ? stateTransition.configuration : currentState ? currentState.configuration : [];
var isDone = (0,stateUtils/* isInFinalState */.Ij)(resolvedConfiguration, this);
var resolvedStateValue = willTransition ? (0,stateUtils/* getValue */.NA)(this.machine, configuration) : undefined;
var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
var actionBlocks = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState, predictableExec);
var activities = currentState ? (0,_tslib/* __assign */.pi)({}, currentState.activities) : {};
try {
for (var actionBlocks_1 = (0,_tslib/* __values */.XA)(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
var block = actionBlocks_1_1.value;
try {
for (var _c = (e_7 = void 0, (0,_tslib/* __values */.XA)(block.actions)), _d = _c.next(); !_d.done; _d = _c.next()) {
var action = _d.value;
if (action.type === actionTypes.start) {
activities[action.activity.id || action.activity.type] = action;
} else if (action.type === actionTypes.stop) {
activities[action.activity.id || action.activity.type] = false;
}
}
} catch (e_7_1) {
e_7 = {
error: e_7_1
};
} finally {
try {
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
} finally {
if (e_7) throw e_7.error;
}
}
}
} catch (e_6_1) {
e_6 = {
error: e_6_1
};
} finally {
try {
if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
} finally {
if (e_6) throw e_6.error;
}
}
var _e = (0,_tslib/* __read */.CR)((0,es_actions.resolveActions)(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
resolvedActions = _e[0],
updatedContext = _e[1];
var _f = (0,_tslib/* __read */.CR)((0,utils/* partition */.uK)(resolvedActions, utils/* isRaisableAction */.vK), 2),
raisedEvents = _f[0],
nonRaisedActions = _f[1];
var invokeActions = resolvedActions.filter(function (action) {
var _a;
return action.type === actionTypes.start && ((_a = action.activity) === null || _a === void 0 ? void 0 : _a.type) === actionTypes.invoke;
});
var children = invokeActions.reduce(function (acc, action) {
acc[action.activity.id] = (0,Actor/* createInvocableActor */.mu)(action.activity, _this.machine, updatedContext, _event);
return acc;
}, currentState ? (0,_tslib/* __assign */.pi)({}, currentState.children) : {});
var nextState = new State/* State */.ZM({
value: resolvedStateValue || currentState.value,
context: updatedContext,
_event: _event,
// Persist _sessionid between states
_sessionid: currentState ? currentState._sessionid : null,
historyValue: resolvedStateValue ? historyValue ? (0,utils/* updateHistoryValue */.yv)(historyValue, resolvedStateValue) : undefined : currentState ? currentState.historyValue : undefined,
history: !resolvedStateValue || stateTransition.source ? currentState : undefined,
actions: resolvedStateValue ? nonRaisedActions : [],
activities: resolvedStateValue ? activities : currentState ? currentState.activities : {},
events: [],
configuration: resolvedConfiguration,
transitions: stateTransition.transitions,
children: children,
done: isDone,
tags: (0,stateUtils/* getTagsFromConfiguration */.Oe)(resolvedConfiguration),
machine: this
});
var didUpdateContext = context !== updatedContext;
nextState.changed = _event.name === actionTypes.update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
var history = nextState.history;
if (history) {
delete history.history;
} // There are transient transitions if the machine is not in a final state
// and if some of the state nodes have transient ("always") transitions.
var hasAlwaysTransitions = !isDone && (this._transient || configuration.some(function (stateNode) {
return stateNode._transient;
})); // If there are no enabled transitions, check if there are transient transitions.
// If there are transient transitions, continue checking for more transitions
// because an transient transition should be triggered even if there are no
// enabled transitions.
//
// If we're already working on an transient transition then stop to prevent an infinite loop.
//
// Otherwise, if there are no enabled nor transient transitions, we are done.
if (!willTransition && (!hasAlwaysTransitions || _event.name === NULL_EVENT)) {
return nextState;
}
var maybeNextState = nextState;
if (!isDone) {
if (hasAlwaysTransitions) {
maybeNextState = this.resolveRaisedTransition(maybeNextState, {
type: actionTypes.nullEvent
}, _event, predictableExec);
}
while (raisedEvents.length) {
var raisedEvent = raisedEvents.shift();
maybeNextState = this.resolveRaisedTransition(maybeNextState, raisedEvent._event, _event, predictableExec);
}
} // Detect if state changed
var changed = maybeNextState.changed || (history ? !!maybeNextState.actions.length || didUpdateContext || typeof history.value !== typeof maybeNextState.value || !(0,State/* stateValuesEqual */.j_)(maybeNextState.value, history.value) : undefined);
maybeNextState.changed = changed; // Preserve original history after raised events
maybeNextState.history = history;
return maybeNextState;
};
/**
* Returns the child state node from its relative `stateKey`, or throws.
*/
StateNode.prototype.getStateNode = function (stateKey) {
if (isStateId(stateKey)) {
return this.machine.getStateNodeById(stateKey);
}
if (!this.states) {
throw new Error("Unable to retrieve child state '".concat(stateKey, "' from '").concat(this.id, "'; no child states exist."));
}
var result = this.states[stateKey];
if (!result) {
throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
}
return result;
};
/**
* Returns the state node with the given `stateId`, or throws.
*
* @param stateId The state ID. The prefix "#" is removed.
*/
StateNode.prototype.getStateNodeById = function (stateId) {
var resolvedStateId = isStateId(stateId) ? stateId.slice(STATE_IDENTIFIER.length) : stateId;
if (resolvedStateId === this.id) {
return this;
}
var stateNode = this.machine.idMap[resolvedStateId];
if (!stateNode) {
throw new Error("Child state node '#".concat(resolvedStateId, "' does not exist on machine '").concat(this.id, "'"));
}
return stateNode;
};
/**
* Returns the relative state node from the given `statePath`, or throws.
*
* @param statePath The string or string array relative path to the state node.
*/
StateNode.prototype.getStateNodeByPath = function (statePath) {
if (typeof statePath === 'string' && isStateId(statePath)) {
try {
return this.getStateNodeById(statePath.slice(1));
} catch (e) {// try individual paths
// throw e;
}
}
var arrayStatePath = (0,utils/* toStatePath */.Q9)(statePath, this.delimiter).slice();
var currentStateNode = this;
while (arrayStatePath.length) {
var key = arrayStatePath.shift();
if (!key.length) {
break;
}
currentStateNode = currentStateNode.getStateNode(key);
}
return currentStateNode;
};
/**
* Resolves a partial state value with its full representation in this machine.
*
* @param stateValue The partial state value to resolve.
*/
StateNode.prototype.resolve = function (stateValue) {
var _a;
var _this = this;
if (!stateValue) {
return this.initialStateValue || EMPTY_OBJECT; // TODO: type-specific properties
}
switch (this.type) {
case 'parallel':
return (0,utils/* mapValues */.Q8)(this.initialStateValue, function (subStateValue, subStateKey) {
return subStateValue ? _this.getStateNode(subStateKey).resolve(stateValue[subStateKey] || subStateValue) : EMPTY_OBJECT;
});
case 'compound':
if ((0,utils/* isString */.HD)(stateValue)) {
var subStateNode = this.getStateNode(stateValue);
if (subStateNode.type === 'parallel' || subStateNode.type === 'compound') {
return _a = {}, _a[stateValue] = subStateNode.initialStateValue, _a;
}
return stateValue;
}
if (!Object.keys(stateValue).length) {
return this.initialStateValue || {};
}
return (0,utils/* mapValues */.Q8)(stateValue, function (subStateValue, subStateKey) {
return subStateValue ? _this.getStateNode(subStateKey).resolve(subStateValue) : EMPTY_OBJECT;
});
default:
return stateValue || EMPTY_OBJECT;
}
};
StateNode.prototype.getResolvedPath = function (stateIdentifier) {
if (isStateId(stateIdentifier)) {
var stateNode = this.machine.idMap[stateIdentifier.slice(STATE_IDENTIFIER.length)];
if (!stateNode) {
throw new Error("Unable to find state node '".concat(stateIdentifier, "'"));
}
return stateNode.path;
}
return (0,utils/* toStatePath */.Q9)(stateIdentifier, this.delimiter);
};
Object.defineProperty(StateNode.prototype, "initialStateValue", {
get: function () {
var _a;
if (this.__cache.initialStateValue) {
return this.__cache.initialStateValue;
}
var initialStateValue;
if (this.type === 'parallel') {
initialStateValue = (0,utils/* mapFilterValues */.ib)(this.states, function (state) {
return state.initialStateValue || EMPTY_OBJECT;
}, function (stateNode) {
return !(stateNode.type === 'history');
});
} else if (this.initial !== undefined) {
if (!this.states[this.initial]) {
throw new Error("Initial state '".concat(this.initial, "' not found on '").concat(this.key, "'"));
}
initialStateValue = (0,stateUtils/* isLeafNode */.N9)(this.states[this.initial]) ? this.initial : (_a = {}, _a[this.initial] = this.states[this.initial].initialStateValue, _a);
} else {
// The finite state value of a machine without child states is just an empty object
initialStateValue = {};
}
this.__cache.initialStateValue = initialStateValue;
return this.__cache.initialStateValue;
},
enumerable: false,
configurable: true
});
StateNode.prototype.getInitialState = function (stateValue, context) {
this._init(); // TODO: this should be in the constructor (see note in constructor)
var configuration = this.getStateNodes(stateValue);
return this.resolveTransition({
configuration: configuration,
exitSet: [],
transitions: [],
source: undefined,
actions: []
}, undefined, context !== null && context !== void 0 ? context : this.machine.context, undefined);
};
Object.defineProperty(StateNode.prototype, "initialState", {
/**
* The initial State instance, which includes all actions to be executed from
* entering the initial state.
*/
get: function () {
var initialStateValue = this.initialStateValue;
if (!initialStateValue) {
throw new Error("Cannot retrieve initial state from simple state '".concat(this.id, "'."));
}
return this.getInitialState(initialStateValue);
},
enumerable: false,
configurable: true
});
Object.defineProperty(StateNode.prototype, "target", {
/**
* The target state value of the history state node, if it exists. This represents the
* default state value to transition to if no history value exists yet.
*/
get: function () {
var target;
if (this.type === 'history') {
var historyConfig = this.config;
if ((0,utils/* isString */.HD)(historyConfig.target)) {
target = isStateId(historyConfig.target) ? (0,utils/* pathToStateValue */.on)(this.machine.getStateNodeById(historyConfig.target).path.slice(this.path.length - 1)) : historyConfig.target;
} else {
target = historyConfig.target;
}
}
return target;
},
enumerable: false,
configurable: true
});
/**
* Returns the leaf nodes from a state path relative to this state node.
*
* @param relativeStateId The relative state path to retrieve the state nodes
* @param history The previous state to retrieve history
* @param resolve Whether state nodes should resolve to initial child state nodes
*/
StateNode.prototype.getRelativeStateNodes = function (relativeStateId, historyValue, resolve) {
if (resolve === void 0) {
resolve = true;
}
return resolve ? relativeStateId.type === 'history' ? relativeStateId.resolveHistory(historyValue) : relativeStateId.initialStateNodes : [relativeStateId];
};
Object.defineProperty(StateNode.prototype, "initialStateNodes", {
get: function () {
var _this = this;
if ((0,stateUtils/* isLeafNode */.N9)(this)) {
return [this];
} // Case when state node is compound but no initial state is defined
if (this.type === 'compound' && !this.initial) {
if (!environment/* IS_PRODUCTION */.M) {
(0,utils/* warn */.ZK)(false, "Compound state node '".concat(this.id, "' has no initial state."));
}
return [this];
}
var initialStateNodePaths = (0,utils/* toStatePaths */.SA)(this.initialStateValue);
return (0,utils/* flatten */.xH)(initialStateNodePaths.map(function (initialPath) {
return _this.getFromRelativePath(initialPath);
}));
},
enumerable: false,
configurable: true
});
/**
* Retrieves state nodes from a relative path to this state node.
*
* @param relativePath The relative path from this state node
* @param historyValue
*/
StateNode.prototype.getFromRelativePath = function (relativePath) {
if (!relativePath.length) {
return [this];
}
var _a = (0,_tslib/* __read */.CR)(relativePath),
stateKey = _a[0],
childStatePath = _a.slice(1);
if (!this.states) {
throw new Error("Cannot retrieve subPath '".concat(stateKey, "' from node with no states"));
}
var childStateNode = this.getStateNode(stateKey);
if (childStateNode.type === 'history') {
return childStateNode.resolveHistory();
}
if (!this.states[stateKey]) {
throw new Error("Child state '".concat(stateKey, "' does not exist on '").concat(this.id, "'"));
}
return this.states[stateKey].getFromRelativePath(childStatePath);
};
StateNode.prototype.historyValue = function (relativeStateValue) {
if (!Object.keys(this.states).length) {
return undefined;
}
return {
current: relativeStateValue || this.initialStateValue,
states: (0,utils/* mapFilterValues */.ib)(this.states, function (stateNode, key) {
if (!relativeStateValue) {
return stateNode.historyValue();
}
var subStateValue = (0,utils/* isString */.HD)(relativeStateValue) ? undefined : relativeStateValue[key];
return stateNode.historyValue(subStateValue || stateNode.initialStateValue);
}, function (stateNode) {
return !stateNode.history;
})
};
};
/**
* Resolves to the historical value(s) of the parent state node,
* represented by state nodes.
*
* @param historyValue
*/
StateNode.prototype.resolveHistory = function (historyValue) {
var _this = this;
if (this.type !== 'history') {
return [this];
}
var parent = this.parent;
if (!historyValue) {
var historyTarget = this.target;
return historyTarget ? (0,utils/* flatten */.xH)((0,utils/* toStatePaths */.SA)(historyTarget).map(function (relativeChildPath) {
return parent.getFromRelativePath(relativeChildPath);
})) : parent.initialStateNodes;
}
var subHistoryValue = (0,utils/* nestedPath */.gk)(parent.path, 'states')(historyValue).current;
if ((0,utils/* isString */.HD)(subHistoryValue)) {
return [parent.getStateNode(subHistoryValue)];
}
return (0,utils/* flatten */.xH)((0,utils/* toStatePaths */.SA)(subHistoryValue).map(function (subStatePath) {
return _this.history === 'deep' ? parent.getFromRelativePath(subStatePath) : [parent.states[subStatePath[0]]];
}));
};
Object.defineProperty(StateNode.prototype, "stateIds", {
/**
* All the state node IDs of this state node and its descendant state nodes.
*/
get: function () {
var _this = this;
var childStateIds = (0,utils/* flatten */.xH)(Object.keys(this.states).map(function (stateKey) {
return _this.states[stateKey].stateIds;
}));
return [this.id].concat(childStateIds);
},
enumerable: false,
configurable: true
});
Object.defineProperty(StateNode.prototype, "events", {
/**
* All the event types accepted by this state node and its descendants.
*/
get: function () {
var e_8, _a, e_9, _b;
if (this.__cache.events) {
return this.__cache.events;
}
var states = this.states;
var events = new Set(this.ownEvents);
if (states) {
try {
for (var _c = (0,_tslib/* __values */.XA)(Object.keys(states)), _d = _c.next(); !_d.done; _d = _c.next()) {
var stateId = _d.value;
var state = states[stateId];
if (state.states) {
try {
for (var _e = (e_9 = void 0, (0,_tslib/* __values */.XA)(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
var event_1 = _f.value;
events.add("".concat(event_1));
}
} catch (e_9_1) {
e_9 = {
error: e_9_1
};
} finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
} finally {
if (e_9) throw e_9.error;
}
}
}
}
} catch (e_8_1) {
e_8 = {
error: e_8_1
};
} finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
} finally {
if (e_8) throw e_8.error;
}
}
}
return this.__cache.events = Array.from(events);
},
enumerable: false,
configurable: true
});
Object.defineProperty(StateNode.prototype, "ownEvents", {
/**
* All the events that have transitions directly from this state node.
*
* Excludes any inert events.
*/
get: function () {
var events = new Set(this.transitions.filter(function (transition) {
return !(!transition.target && !transition.actions.length && transition.internal);
}).map(function (transition) {
return transition.eventType;
}));
return Array.from(events);
},
enumerable: false,
configurable: true
});
StateNode.prototype.resolveTarget = function (_target) {
var _this = this;
if (_target === undefined) {
// an undefined target signals that the state node should not transition from that state when receiving that event
return undefined;
}
return _target.map(function (target) {
if (!(0,utils/* isString */.HD)(target)) {
return target;
}
var isInternalTarget = target[0] === _this.delimiter; // If internal target is defined on machine,
// do not include machine key on target
if (isInternalTarget && !_this.parent) {
return _this.getStateNodeByPath(target.slice(1));
}
var resolvedTarget = isInternalTarget ? _this.key + target : target;
if (_this.parent) {
try {
var targetStateNode = _this.parent.getStateNodeByPath(resolvedTarget);
return targetStateNode;
} catch (err) {
throw new Error("Invalid transition definition for state node '".concat(_this.id, "':\n").concat(err.message));
}
} else {
return _this.getStateNodeByPath(resolvedTarget);
}
});
};
StateNode.prototype.formatTransition = function (transitionConfig) {
var _this = this;
var normalizedTarget = (0,utils/* normalizeTarget */.rg)(transitionConfig.target);
var internal = 'internal' in transitionConfig ? transitionConfig.internal : normalizedTarget ? normalizedTarget.some(function (_target) {
return (0,utils/* isString */.HD)(_target) && _target[0] === _this.delimiter;
}) : true;
var guards = this.machine.options.guards;
var target = this.resolveTarget(normalizedTarget);
var transition = (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, transitionConfig), {
actions: (0,es_actions.toActionObjects)((0,utils/* toArray */.qo)(transitionConfig.actions)),
cond: (0,utils/* toGuard */.Qi)(transitionConfig.cond, guards),
target: target,
source: this,
internal: internal,
eventType: transitionConfig.event,
toJSON: function () {
return (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, transition), {
target: transition.target ? transition.target.map(function (t) {
return "#".concat(t.id);
}) : undefined,
source: "#".concat(_this.id)
});
}
});
return transition;
};
StateNode.prototype.formatTransitions = function () {
var e_10, _a;
var _this = this;
var onConfig;
if (!this.config.on) {
onConfig = [];
} else if (Array.isArray(this.config.on)) {
onConfig = this.config.on;
} else {
var _b = this.config.on,
_c = WILDCARD,
_d = _b[_c],
wildcardConfigs = _d === void 0 ? [] : _d,
strictTransitionConfigs_1 = (0,_tslib/* __rest */._T)(_b, [typeof _c === "symbol" ? _c : _c + ""]);
onConfig = (0,utils/* flatten */.xH)(Object.keys(strictTransitionConfigs_1).map(function (key) {
if (!environment/* IS_PRODUCTION */.M && key === NULL_EVENT) {
(0,utils/* warn */.ZK)(false, "Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. " + "Please check the `on` configuration for \"#".concat(_this.id, "\"."));
}
var transitionConfigArray = (0,utils/* toTransitionConfigArray */.jh)(key, strictTransitionConfigs_1[key]);
if (!environment/* IS_PRODUCTION */.M) {
validateArrayifiedTransitions(_this, key, transitionConfigArray);
}
return transitionConfigArray;
}).concat((0,utils/* toTransitionConfigArray */.jh)(WILDCARD, wildcardConfigs)));
}
var eventlessConfig = this.config.always ? (0,utils/* toTransitionConfigArray */.jh)('', this.config.always) : [];
var doneConfig = this.config.onDone ? (0,utils/* toTransitionConfigArray */.jh)(String((0,es_actions.done)(this.id)), this.config.onDone) : [];
if (!environment/* IS_PRODUCTION */.M) {
(0,utils/* warn */.ZK)(!(this.config.onDone && !this.parent), "Root nodes cannot have an \".onDone\" transition. Please check the config of \"".concat(this.id, "\"."));
}
var invokeConfig = (0,utils/* flatten */.xH)(this.invoke.map(function (invokeDef) {
var settleTransitions = [];
if (invokeDef.onDone) {
settleTransitions.push.apply(settleTransitions, (0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)((0,utils/* toTransitionConfigArray */.jh)(String((0,es_actions.doneInvoke)(invokeDef.id)), invokeDef.onDone)), false));
}
if (invokeDef.onError) {
settleTransitions.push.apply(settleTransitions, (0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)((0,utils/* toTransitionConfigArray */.jh)(String((0,es_actions.error)(invokeDef.id)), invokeDef.onError)), false));
}
return settleTransitions;
}));
var delayedTransitions = this.after;
var formattedTransitions = (0,utils/* flatten */.xH)((0,_tslib/* __spreadArray */.ev)((0,_tslib/* __spreadArray */.ev)((0,_tslib/* __spreadArray */.ev)((0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)(doneConfig), false), (0,_tslib/* __read */.CR)(invokeConfig), false), (0,_tslib/* __read */.CR)(onConfig), false), (0,_tslib/* __read */.CR)(eventlessConfig), false).map(function (transitionConfig) {
return (0,utils/* toArray */.qo)(transitionConfig).map(function (transition) {
return _this.formatTransition(transition);
});
}));
try {
for (var delayedTransitions_1 = (0,_tslib/* __values */.XA)(delayedTransitions), delayedTransitions_1_1 = delayedTransitions_1.next(); !delayedTransitions_1_1.done; delayedTransitions_1_1 = delayedTransitions_1.next()) {
var delayedTransition = delayedTransitions_1_1.value;
formattedTransitions.push(delayedTransition);
}
} catch (e_10_1) {
e_10 = {
error: e_10_1
};
} finally {
try {
if (delayedTransitions_1_1 && !delayedTransitions_1_1.done && (_a = delayedTransitions_1.return)) _a.call(delayedTransitions_1);
} finally {
if (e_10) throw e_10.error;
}
}
return formattedTransitions;
};
return StateNode;
}();
/***/ }),
/***/ 3056:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ CR: () => (/* binding */ __read),
/* harmony export */ XA: () => (/* binding */ __values),
/* harmony export */ _T: () => (/* binding */ __rest),
/* harmony export */ ev: () => (/* binding */ __spreadArray),
/* harmony export */ pi: () => (/* binding */ __assign)
/* harmony export */ });
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
/***/ }),
/***/ 3884:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ after: () => (/* binding */ after),
/* harmony export */ assign: () => (/* binding */ assign),
/* harmony export */ cancel: () => (/* binding */ cancel),
/* harmony export */ choose: () => (/* binding */ choose),
/* harmony export */ doneState: () => (/* binding */ doneState),
/* harmony export */ error: () => (/* binding */ error),
/* harmony export */ errorExecution: () => (/* binding */ errorExecution),
/* harmony export */ errorPlatform: () => (/* binding */ errorPlatform),
/* harmony export */ init: () => (/* binding */ init),
/* harmony export */ invoke: () => (/* binding */ invoke),
/* harmony export */ log: () => (/* binding */ log),
/* harmony export */ nullEvent: () => (/* binding */ nullEvent),
/* harmony export */ pure: () => (/* binding */ pure),
/* harmony export */ raise: () => (/* binding */ raise),
/* harmony export */ send: () => (/* binding */ send),
/* harmony export */ start: () => (/* binding */ start),
/* harmony export */ stop: () => (/* binding */ stop),
/* harmony export */ update: () => (/* binding */ update)
/* harmony export */ });
/* harmony import */ var _types_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9043);
var start = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.Start;
var stop = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.Stop;
var raise = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.Raise;
var send = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.Send;
var cancel = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.Cancel;
var nullEvent = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.NullEvent;
var assign = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.Assign;
var after = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.After;
var doneState = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.DoneState;
var log = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.Log;
var init = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.Init;
var invoke = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.Invoke;
var errorExecution = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.ErrorExecution;
var errorPlatform = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.ErrorPlatform;
var error = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.ErrorCustom;
var update = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.Update;
var choose = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.Choose;
var pure = _types_js__WEBPACK_IMPORTED_MODULE_0__/* .ActionTypes */ .M.Pure;
/***/ }),
/***/ 375:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ actionTypes: () => (/* reexport module object */ _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__),
/* harmony export */ after: () => (/* binding */ after),
/* harmony export */ assign: () => (/* binding */ assign),
/* harmony export */ cancel: () => (/* binding */ cancel),
/* harmony export */ choose: () => (/* binding */ choose),
/* harmony export */ done: () => (/* binding */ done),
/* harmony export */ doneInvoke: () => (/* binding */ doneInvoke),
/* harmony export */ error: () => (/* binding */ error),
/* harmony export */ escalate: () => (/* binding */ escalate),
/* harmony export */ forwardTo: () => (/* binding */ forwardTo),
/* harmony export */ getActionFunction: () => (/* binding */ getActionFunction),
/* harmony export */ initEvent: () => (/* binding */ initEvent),
/* harmony export */ isActionObject: () => (/* binding */ isActionObject),
/* harmony export */ log: () => (/* binding */ log),
/* harmony export */ pure: () => (/* binding */ pure),
/* harmony export */ raise: () => (/* binding */ raise),
/* harmony export */ resolveActions: () => (/* binding */ resolveActions),
/* harmony export */ resolveLog: () => (/* binding */ resolveLog),
/* harmony export */ resolveRaise: () => (/* binding */ resolveRaise),
/* harmony export */ resolveSend: () => (/* binding */ resolveSend),
/* harmony export */ resolveStop: () => (/* binding */ resolveStop),
/* harmony export */ respond: () => (/* binding */ respond),
/* harmony export */ send: () => (/* binding */ send),
/* harmony export */ sendParent: () => (/* binding */ sendParent),
/* harmony export */ sendTo: () => (/* binding */ sendTo),
/* harmony export */ sendUpdate: () => (/* binding */ sendUpdate),
/* harmony export */ start: () => (/* binding */ start),
/* harmony export */ stop: () => (/* binding */ stop),
/* harmony export */ toActionObject: () => (/* binding */ toActionObject),
/* harmony export */ toActionObjects: () => (/* binding */ toActionObjects),
/* harmony export */ toActivityDefinition: () => (/* binding */ toActivityDefinition)
/* harmony export */ });
/* harmony import */ var _virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3056);
/* harmony import */ var _types_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(9043);
/* harmony import */ var _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3884);
/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9823);
/* harmony import */ var _environment_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4066);
var initEvent = /*#__PURE__*/(0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .toSCXMLEvent */ .g5)({
type: _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.init
});
function getActionFunction(actionType, actionFunctionMap) {
return actionFunctionMap ? actionFunctionMap[actionType] || undefined : undefined;
}
function toActionObject(action, actionFunctionMap) {
var actionObject;
if ((0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isString */ .HD)(action) || typeof action === 'number') {
var exec = getActionFunction(action, actionFunctionMap);
if ((0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(exec)) {
actionObject = {
type: action,
exec: exec
};
} else if (exec) {
actionObject = exec;
} else {
actionObject = {
type: action,
exec: undefined
};
}
} else if ((0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(action)) {
actionObject = {
// Convert action to string if unnamed
type: action.name || action.toString(),
exec: action
};
} else {
var exec = getActionFunction(action.type, actionFunctionMap);
if ((0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(exec)) {
actionObject = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)({}, action), {
exec: exec
});
} else if (exec) {
var actionType = exec.type || action.type;
actionObject = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)({}, exec), action), {
type: actionType
});
} else {
actionObject = action;
}
}
return actionObject;
}
var toActionObjects = function (action, actionFunctionMap) {
if (!action) {
return [];
}
var actions = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isArray */ .kJ)(action) ? action : [action];
return actions.map(function (subAction) {
return toActionObject(subAction, actionFunctionMap);
});
};
function toActivityDefinition(action) {
var actionObject = toActionObject(action);
return (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)({
id: (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isString */ .HD)(action) ? action : actionObject.id
}, actionObject), {
type: actionObject.type
});
}
/**
* Raises an event. This places the event in the internal event queue, so that
* the event is immediately consumed by the machine in the current step.
*
* @param eventType The event to raise.
*/
function raise(event, options) {
return {
type: _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.raise,
event: typeof event === 'function' ? event : (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .toEventObject */ ._v)(event),
delay: options ? options.delay : undefined,
id: options === null || options === void 0 ? void 0 : options.id
};
}
function resolveRaise(action, ctx, _event, delaysMap) {
var meta = {
_event: _event
};
var resolvedEvent = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .toSCXMLEvent */ .g5)((0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(action.event) ? action.event(ctx, _event.data, meta) : action.event);
var resolvedDelay;
if ((0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isString */ .HD)(action.delay)) {
var configDelay = delaysMap && delaysMap[action.delay];
resolvedDelay = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(configDelay) ? configDelay(ctx, _event.data, meta) : configDelay;
} else {
resolvedDelay = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(action.delay) ? action.delay(ctx, _event.data, meta) : action.delay;
}
return (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)({}, action), {
type: _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.raise,
_event: resolvedEvent,
delay: resolvedDelay
});
}
/**
* Sends an event. This returns an action that will be read by an interpreter to
* send the event in the next step, after the current step is finished executing.
*
* @deprecated Use the `sendTo(...)` action creator instead.
*
* @param event The event to send.
* @param options Options to pass into the send event:
* - `id` - The unique send event identifier (used with `cancel()`).
* - `delay` - The number of milliseconds to delay the sending of the event.
* - `to` - The target of this event (by default, the machine the event was sent from).
*/
function send(event, options) {
return {
to: options ? options.to : undefined,
type: _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.send,
event: (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(event) ? event : (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .toEventObject */ ._v)(event),
delay: options ? options.delay : undefined,
// TODO: don't auto-generate IDs here like that
// there is too big chance of the ID collision
id: options && options.id !== undefined ? options.id : (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(event) ? event.name : (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .getEventType */ .x6)(event)
};
}
function resolveSend(action, ctx, _event, delaysMap) {
var meta = {
_event: _event
}; // TODO: helper function for resolving Expr
var resolvedEvent = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .toSCXMLEvent */ .g5)((0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(action.event) ? action.event(ctx, _event.data, meta) : action.event);
var resolvedDelay;
if ((0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isString */ .HD)(action.delay)) {
var configDelay = delaysMap && delaysMap[action.delay];
resolvedDelay = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(configDelay) ? configDelay(ctx, _event.data, meta) : configDelay;
} else {
resolvedDelay = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(action.delay) ? action.delay(ctx, _event.data, meta) : action.delay;
}
var resolvedTarget = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(action.to) ? action.to(ctx, _event.data, meta) : action.to;
return (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)({}, action), {
to: resolvedTarget,
_event: resolvedEvent,
event: resolvedEvent.data,
delay: resolvedDelay
});
}
/**
* Sends an event to this machine's parent.
*
* @param event The event to send to the parent machine.
* @param options Options to pass into the send event.
*/
function sendParent(event, options) {
return send(event, (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)({}, options), {
to: _types_js__WEBPACK_IMPORTED_MODULE_3__/* .SpecialTargets */ .K.Parent
}));
}
/**
* Sends an event to an actor.
*
* @param actor The `ActorRef` to send the event to.
* @param event The event to send, or an expression that evaluates to the event to send
* @param options Send action options
* @returns An XState send action object
*/
function sendTo(actor, event, options) {
return send(event, (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)({}, options), {
to: actor
}));
}
/**
* Sends an update event to this machine's parent.
*/
function sendUpdate() {
return sendParent(_actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.update);
}
/**
* Sends an event back to the sender of the original event.
*
* @param event The event to send back to the sender
* @param options Options to pass into the send event
*/
function respond(event, options) {
return send(event, (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)({}, options), {
to: function (_, __, _a) {
var _event = _a._event;
return _event.origin; // TODO: handle when _event.origin is undefined
}
}));
}
var defaultLogExpr = function (context, event) {
return {
context: context,
event: event
};
};
/**
*
* @param expr The expression function to evaluate which will be logged.
* Takes in 2 arguments:
* - `ctx` - the current state context
* - `event` - the event that caused this action to be executed.
* @param label The label to give to the logged expression.
*/
function log(expr, label) {
if (expr === void 0) {
expr = defaultLogExpr;
}
return {
type: _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.log,
label: label,
expr: expr
};
}
var resolveLog = function (action, ctx, _event) {
return (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)({}, action), {
value: (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isString */ .HD)(action.expr) ? action.expr : action.expr(ctx, _event.data, {
_event: _event
})
});
};
/**
* Cancels an in-flight `send(...)` action. A canceled sent action will not
* be executed, nor will its event be sent, unless it has already been sent
* (e.g., if `cancel(...)` is called after the `send(...)` action's `delay`).
*
* @param sendId The `id` of the `send(...)` action to cancel.
*/
var cancel = function (sendId) {
return {
type: _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.cancel,
sendId: sendId
};
};
/**
* Starts an activity.
*
* @param activity The activity to start.
*/
function start(activity) {
var activityDef = toActivityDefinition(activity);
return {
type: _types_js__WEBPACK_IMPORTED_MODULE_3__/* .ActionTypes */ .M.Start,
activity: activityDef,
exec: undefined
};
}
/**
* Stops an activity.
*
* @param actorRef The activity to stop.
*/
function stop(actorRef) {
var activity = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(actorRef) ? actorRef : toActivityDefinition(actorRef);
return {
type: _types_js__WEBPACK_IMPORTED_MODULE_3__/* .ActionTypes */ .M.Stop,
activity: activity,
exec: undefined
};
}
function resolveStop(action, context, _event) {
var actorRefOrString = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(action.activity) ? action.activity(context, _event.data) : action.activity;
var resolvedActorRef = typeof actorRefOrString === 'string' ? {
id: actorRefOrString
} : actorRefOrString;
var actionObject = {
type: _types_js__WEBPACK_IMPORTED_MODULE_3__/* .ActionTypes */ .M.Stop,
activity: resolvedActorRef
};
return actionObject;
}
/**
* Updates the current context of the machine.
*
* @param assignment An object that represents the partial context to update.
*/
var assign = function (assignment) {
return {
type: _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.assign,
assignment: assignment
};
};
function isActionObject(action) {
return typeof action === 'object' && 'type' in action;
}
/**
* Returns an event type that represents an implicit event that
* is sent after the specified `delay`.
*
* @param delayRef The delay in milliseconds
* @param id The state node ID where this event is handled
*/
function after(delayRef, id) {
var idSuffix = id ? "#".concat(id) : '';
return "".concat(_types_js__WEBPACK_IMPORTED_MODULE_3__/* .ActionTypes */ .M.After, "(").concat(delayRef, ")").concat(idSuffix);
}
/**
* Returns an event that represents that a final state node
* has been reached in the parent state node.
*
* @param id The final state node's parent state node `id`
* @param data The data to pass into the event
*/
function done(id, data) {
var type = "".concat(_types_js__WEBPACK_IMPORTED_MODULE_3__/* .ActionTypes */ .M.DoneState, ".").concat(id);
var eventObject = {
type: type,
data: data
};
eventObject.toString = function () {
return type;
};
return eventObject;
}
/**
* Returns an event that represents that an invoked service has terminated.
*
* An invoked service is terminated when it has reached a top-level final state node,
* but not when it is canceled.
*
* @param id The final state node ID
* @param data The data to pass into the event
*/
function doneInvoke(id, data) {
var type = "".concat(_types_js__WEBPACK_IMPORTED_MODULE_3__/* .ActionTypes */ .M.DoneInvoke, ".").concat(id);
var eventObject = {
type: type,
data: data
};
eventObject.toString = function () {
return type;
};
return eventObject;
}
function error(id, data) {
var type = "".concat(_types_js__WEBPACK_IMPORTED_MODULE_3__/* .ActionTypes */ .M.ErrorPlatform, ".").concat(id);
var eventObject = {
type: type,
data: data
};
eventObject.toString = function () {
return type;
};
return eventObject;
}
function pure(getActions) {
return {
type: _types_js__WEBPACK_IMPORTED_MODULE_3__/* .ActionTypes */ .M.Pure,
get: getActions
};
}
/**
* Forwards (sends) an event to a specified service.
*
* @param target The target service to forward the event to.
* @param options Options to pass into the send action creator.
*/
function forwardTo(target, options) {
if (!_environment_js__WEBPACK_IMPORTED_MODULE_4__/* .IS_PRODUCTION */ .M && (!target || typeof target === 'function')) {
var originalTarget_1 = target;
target = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var resolvedTarget = typeof originalTarget_1 === 'function' ? originalTarget_1.apply(void 0, (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__spreadArray */ .ev)([], (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__read */ .CR)(args), false)) : originalTarget_1;
if (!resolvedTarget) {
throw new Error("Attempted to forward event to undefined actor. This risks an infinite loop in the sender.");
}
return resolvedTarget;
};
}
return send(function (_, event) {
return event;
}, (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)({}, options), {
to: target
}));
}
/**
* Escalates an error by sending it as an event to this machine's parent.
*
* @param errorData The error data to send, or the expression function that
* takes in the `context`, `event`, and `meta`, and returns the error data to send.
* @param options Options to pass into the send action creator.
*/
function escalate(errorData, options) {
return sendParent(function (context, event, meta) {
return {
type: _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.error,
data: (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isFunction */ .mf)(errorData) ? errorData(context, event, meta) : errorData
};
}, (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)({}, options), {
to: _types_js__WEBPACK_IMPORTED_MODULE_3__/* .SpecialTargets */ .K.Parent
}));
}
function choose(conds) {
return {
type: _types_js__WEBPACK_IMPORTED_MODULE_3__/* .ActionTypes */ .M.Choose,
conds: conds
};
}
var pluckAssigns = function (actionBlocks) {
var e_1, _a;
var assignActions = [];
try {
for (var actionBlocks_1 = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__values */ .XA)(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
var block = actionBlocks_1_1.value;
var i = 0;
while (i < block.actions.length) {
if (block.actions[i].type === _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.assign) {
assignActions.push(block.actions[i]);
block.actions.splice(i, 1);
continue;
}
i++;
}
}
} catch (e_1_1) {
e_1 = {
error: e_1_1
};
} finally {
try {
if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
} finally {
if (e_1) throw e_1.error;
}
}
return assignActions;
};
function resolveActions(machine, currentState, currentContext, _event, actionBlocks, predictableExec, preserveActionOrder) {
if (preserveActionOrder === void 0) {
preserveActionOrder = false;
}
var assignActions = preserveActionOrder ? [] : pluckAssigns(actionBlocks);
var updatedContext = assignActions.length ? (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .updateContext */ .dt)(currentContext, _event, assignActions, currentState) : currentContext;
var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
var deferredToBlockEnd = [];
function handleAction(blockType, actionObject) {
var _a;
switch (actionObject.type) {
case _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.raise:
{
var raisedAction = resolveRaise(actionObject, updatedContext, _event, machine.options.delays);
if (predictableExec && typeof raisedAction.delay === 'number') {
predictableExec(raisedAction, updatedContext, _event);
}
return raisedAction;
}
case _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.send:
var sendAction = resolveSend(actionObject, updatedContext, _event, machine.options.delays); // TODO: fix ActionTypes.Init
if (!_environment_js__WEBPACK_IMPORTED_MODULE_4__/* .IS_PRODUCTION */ .M) {
var configuredDelay = actionObject.delay; // warn after resolving as we can create better contextual message here
(0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .warn */ .ZK)(!(0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .isString */ .HD)(configuredDelay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
"No delay reference for delay expression '".concat(configuredDelay, "' was found on machine '").concat(machine.id, "'"));
}
if (predictableExec && sendAction.to !== _types_js__WEBPACK_IMPORTED_MODULE_3__/* .SpecialTargets */ .K.Internal) {
if (blockType === 'entry') {
deferredToBlockEnd.push(sendAction);
} else {
predictableExec(sendAction, updatedContext, _event);
}
}
return sendAction;
case _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.log:
{
var resolved = resolveLog(actionObject, updatedContext, _event);
predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, updatedContext, _event);
return resolved;
}
case _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.choose:
{
var chooseAction = actionObject;
var matchedActions = (_a = chooseAction.conds.find(function (condition) {
var guard = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .toGuard */ .Qi)(condition.cond, machine.options.guards);
return !guard || (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .evaluateGuard */ .vx)(machine, guard, updatedContext, _event, !predictableExec ? currentState : undefined);
})) === null || _a === void 0 ? void 0 : _a.actions;
if (!matchedActions) {
return [];
}
var _b = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__read */ .CR)(resolveActions(machine, currentState, updatedContext, _event, [{
type: blockType,
actions: toActionObjects((0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .toArray */ .qo)(matchedActions), machine.options.actions)
}], predictableExec, preserveActionOrder), 2),
resolvedActionsFromChoose = _b[0],
resolvedContextFromChoose = _b[1];
updatedContext = resolvedContextFromChoose;
preservedContexts === null || preservedContexts === void 0 ? void 0 : preservedContexts.push(updatedContext);
return resolvedActionsFromChoose;
}
case _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.pure:
{
var matchedActions = actionObject.get(updatedContext, _event.data);
if (!matchedActions) {
return [];
}
var _c = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__read */ .CR)(resolveActions(machine, currentState, updatedContext, _event, [{
type: blockType,
actions: toActionObjects((0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .toArray */ .qo)(matchedActions), machine.options.actions)
}], predictableExec, preserveActionOrder), 2),
resolvedActionsFromPure = _c[0],
resolvedContext = _c[1];
updatedContext = resolvedContext;
preservedContexts === null || preservedContexts === void 0 ? void 0 : preservedContexts.push(updatedContext);
return resolvedActionsFromPure;
}
case _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.stop:
{
var resolved = resolveStop(actionObject, updatedContext, _event);
predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, currentContext, _event);
return resolved;
}
case _actionTypes_js__WEBPACK_IMPORTED_MODULE_0__.assign:
{
updatedContext = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .updateContext */ .dt)(updatedContext, _event, [actionObject], !predictableExec ? currentState : undefined);
preservedContexts === null || preservedContexts === void 0 ? void 0 : preservedContexts.push(updatedContext);
break;
}
default:
var resolvedActionObject = toActionObject(actionObject, machine.options.actions);
var exec_1 = resolvedActionObject.exec;
if (predictableExec) {
predictableExec(resolvedActionObject, updatedContext, _event);
} else if (exec_1 && preservedContexts) {
var contextIndex_1 = preservedContexts.length - 1;
var wrapped = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__assign */ .pi)({}, resolvedActionObject), {
exec: function (_ctx) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
exec_1.apply(void 0, (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__spreadArray */ .ev)([preservedContexts[contextIndex_1]], (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__read */ .CR)(args), false));
}
});
resolvedActionObject = wrapped;
}
return resolvedActionObject;
}
}
function processBlock(block) {
var e_2, _a;
var resolvedActions = [];
try {
for (var _b = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_2__/* .__values */ .XA)(block.actions), _c = _b.next(); !_c.done; _c = _b.next()) {
var action = _c.value;
var resolved = handleAction(block.type, action);
if (resolved) {
resolvedActions = resolvedActions.concat(resolved);
}
}
} catch (e_2_1) {
e_2 = {
error: e_2_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_2) throw e_2.error;
}
}
deferredToBlockEnd.forEach(function (action) {
predictableExec(action, updatedContext, _event);
});
deferredToBlockEnd.length = 0;
return resolvedActions;
}
var resolvedActions = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .flatten */ .xH)(actionBlocks.map(processBlock));
return [resolvedActions, updatedContext];
}
/***/ }),
/***/ 8199:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ YP: () => (/* binding */ spawnBehavior)
/* harmony export */ });
/* unused harmony exports fromPromise, fromReducer */
/* harmony import */ var _Actor_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8933);
/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9823);
/**
* Returns an actor behavior from a reducer and its initial state.
*
* @param transition The pure reducer that returns the next state given the current state and event.
* @param initialState The initial state of the reducer.
* @returns An actor behavior
*/
function fromReducer(transition, initialState) {
return {
transition: transition,
initialState: initialState
};
}
function fromPromise(promiseFn) {
var initialState = {
error: undefined,
data: undefined,
status: 'pending'
};
return {
transition: function (state, event, _a) {
var parent = _a.parent,
id = _a.id,
observers = _a.observers;
switch (event.type) {
case 'fulfill':
parent === null || parent === void 0 ? void 0 : parent.send(doneInvoke(id, event.data));
return {
error: undefined,
data: event.data,
status: 'fulfilled'
};
case 'reject':
parent === null || parent === void 0 ? void 0 : parent.send(error(id, event.error));
observers.forEach(function (observer) {
observer.error(event.error);
});
return {
error: event.error,
data: undefined,
status: 'rejected'
};
default:
return state;
}
},
initialState: initialState,
start: function (_a) {
var self = _a.self;
promiseFn().then(function (data) {
self.send({
type: 'fulfill',
data: data
});
}, function (reason) {
self.send({
type: 'reject',
error: reason
});
});
return initialState;
}
};
}
function spawnBehavior(behavior, options) {
if (options === void 0) {
options = {};
}
var state = behavior.initialState;
var observers = new Set();
var mailbox = [];
var flushing = false;
var flush = function () {
if (flushing) {
return;
}
flushing = true;
while (mailbox.length > 0) {
var event_1 = mailbox.shift();
state = behavior.transition(state, event_1, actorCtx);
observers.forEach(function (observer) {
return observer.next(state);
});
}
flushing = false;
};
var actor = (0,_Actor_js__WEBPACK_IMPORTED_MODULE_0__/* .toActorRef */ .vk)({
id: options.id,
send: function (event) {
mailbox.push(event);
flush();
},
getSnapshot: function () {
return state;
},
subscribe: function (next, handleError, complete) {
var observer = (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__/* .toObserver */ .zM)(next, handleError, complete);
observers.add(observer);
observer.next(state);
return {
unsubscribe: function () {
observers.delete(observer);
}
};
}
});
var actorCtx = {
parent: options.parent,
self: actor,
id: options.id || 'anonymous',
observers: observers
};
state = behavior.start ? behavior.start(actorCtx) : state;
return actor;
}
/***/ }),
/***/ 7353:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ TV: () => (/* binding */ DEFAULT_GUARD_TYPE),
/* harmony export */ iS: () => (/* binding */ STATE_DELIMITER),
/* harmony export */ qP: () => (/* binding */ EMPTY_ACTIVITY_MAP),
/* harmony export */ rt: () => (/* binding */ TARGETLESS_KEY)
/* harmony export */ });
var STATE_DELIMITER = '.';
var EMPTY_ACTIVITY_MAP = {};
var DEFAULT_GUARD_TYPE = 'xstate.guard';
var TARGETLESS_KEY = '';
/***/ }),
/***/ 4066:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ M: () => (/* binding */ IS_PRODUCTION)
/* harmony export */ });
var IS_PRODUCTION = "production" === 'production';
/***/ }),
/***/ 4679:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
ActionTypes: () => (/* reexport */ types/* ActionTypes */.M),
Interpreter: () => (/* reexport */ interpreter/* Interpreter */.Ng),
InterpreterStatus: () => (/* reexport */ interpreter/* InterpreterStatus */.TM),
Machine: () => (/* reexport */ Machine/* Machine */.J),
SpecialTargets: () => (/* reexport */ types/* SpecialTargets */.K),
State: () => (/* reexport */ State/* State */.ZM),
StateNode: () => (/* reexport */ StateNode/* StateNode */.n),
actions: () => (/* reexport */ actions),
assign: () => (/* binding */ es_assign),
cancel: () => (/* binding */ cancel),
choose: () => (/* binding */ choose),
createMachine: () => (/* reexport */ Machine/* createMachine */.C),
createSchema: () => (/* reexport */ createSchema),
doneInvoke: () => (/* binding */ doneInvoke),
forwardTo: () => (/* binding */ forwardTo),
interpret: () => (/* reexport */ interpreter/* interpret */.kJ),
log: () => (/* binding */ log),
mapState: () => (/* reexport */ mapState),
matchState: () => (/* reexport */ matchState),
matchesState: () => (/* reexport */ utils/* matchesState */.W),
pure: () => (/* binding */ pure),
raise: () => (/* binding */ raise),
send: () => (/* binding */ send),
sendParent: () => (/* binding */ sendParent),
sendTo: () => (/* binding */ sendTo),
sendUpdate: () => (/* binding */ sendUpdate),
spawn: () => (/* reexport */ interpreter/* spawn */.Cs),
spawnBehavior: () => (/* reexport */ behaviors/* spawnBehavior */.YP),
stop: () => (/* binding */ stop),
t: () => (/* reexport */ t),
toActorRef: () => (/* reexport */ Actor/* toActorRef */.vk),
toEventObject: () => (/* reexport */ utils/* toEventObject */._v),
toObserver: () => (/* reexport */ utils/* toObserver */.zM),
toSCXMLEvent: () => (/* reexport */ utils/* toSCXMLEvent */.g5)
});
// EXTERNAL MODULE: ./node_modules/xstate/es/actions.js
var actions = __webpack_require__(375);
// EXTERNAL MODULE: ./node_modules/xstate/es/Actor.js
var Actor = __webpack_require__(8933);
// EXTERNAL MODULE: ./node_modules/xstate/es/interpreter.js + 3 modules
var interpreter = __webpack_require__(9805);
// EXTERNAL MODULE: ./node_modules/xstate/es/Machine.js
var Machine = __webpack_require__(629);
// EXTERNAL MODULE: ./node_modules/xstate/es/_virtual/_tslib.js
var _tslib = __webpack_require__(3056);
// EXTERNAL MODULE: ./node_modules/xstate/es/utils.js
var utils = __webpack_require__(9823);
;// CONCATENATED MODULE: ./node_modules/xstate/es/mapState.js
function mapState(stateMap, stateId) {
var e_1, _a;
var foundStateId;
try {
for (var _b = (0,_tslib/* __values */.XA)(Object.keys(stateMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
var mappedStateId = _c.value;
if ((0,utils/* matchesState */.W)(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
foundStateId = mappedStateId;
}
}
} catch (e_1_1) {
e_1 = {
error: e_1_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_1) throw e_1.error;
}
}
return stateMap[foundStateId];
}
// EXTERNAL MODULE: ./node_modules/xstate/es/State.js
var State = __webpack_require__(4911);
;// CONCATENATED MODULE: ./node_modules/xstate/es/match.js
function matchState(state, patterns, defaultValue) {
var e_1, _a;
var resolvedState = State/* State */.ZM.from(state, state instanceof State/* State */.ZM ? state.context : undefined);
try {
for (var patterns_1 = (0,_tslib/* __values */.XA)(patterns), patterns_1_1 = patterns_1.next(); !patterns_1_1.done; patterns_1_1 = patterns_1.next()) {
var _b = (0,_tslib/* __read */.CR)(patterns_1_1.value, 2),
stateValue = _b[0],
getValue = _b[1];
if (resolvedState.matches(stateValue)) {
return getValue(resolvedState);
}
}
} catch (e_1_1) {
e_1 = {
error: e_1_1
};
} finally {
try {
if (patterns_1_1 && !patterns_1_1.done && (_a = patterns_1.return)) _a.call(patterns_1);
} finally {
if (e_1) throw e_1.error;
}
}
return defaultValue(resolvedState);
}
;// CONCATENATED MODULE: ./node_modules/xstate/es/schema.js
function createSchema(schema) {
return schema;
}
var t = createSchema;
// EXTERNAL MODULE: ./node_modules/xstate/es/StateNode.js + 1 modules
var StateNode = __webpack_require__(8889);
// EXTERNAL MODULE: ./node_modules/xstate/es/behaviors.js
var behaviors = __webpack_require__(8199);
// EXTERNAL MODULE: ./node_modules/xstate/es/types.js
var types = __webpack_require__(9043);
;// CONCATENATED MODULE: ./node_modules/xstate/es/index.js
var es_assign = actions.assign,
cancel = actions.cancel,
send = actions.send,
sendTo = actions.sendTo,
sendParent = actions.sendParent,
sendUpdate = actions.sendUpdate,
forwardTo = actions.forwardTo,
doneInvoke = actions.doneInvoke,
raise = actions.raise,
log = actions.log,
pure = actions.pure,
choose = actions.choose,
stop = actions.stop;
/***/ }),
/***/ 9805:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
Ng: () => (/* binding */ Interpreter),
TM: () => (/* binding */ InterpreterStatus),
kJ: () => (/* binding */ interpret),
Cs: () => (/* binding */ spawn)
});
// EXTERNAL MODULE: ./node_modules/xstate/es/_virtual/_tslib.js
var _tslib = __webpack_require__(3056);
// EXTERNAL MODULE: ./node_modules/xstate/es/types.js
var types = __webpack_require__(9043);
// EXTERNAL MODULE: ./node_modules/xstate/es/State.js
var State = __webpack_require__(4911);
// EXTERNAL MODULE: ./node_modules/xstate/es/actionTypes.js
var actionTypes = __webpack_require__(3884);
// EXTERNAL MODULE: ./node_modules/xstate/es/actions.js
var actions = __webpack_require__(375);
// EXTERNAL MODULE: ./node_modules/xstate/es/environment.js
var environment = __webpack_require__(4066);
// EXTERNAL MODULE: ./node_modules/xstate/es/utils.js
var utils = __webpack_require__(9823);
;// CONCATENATED MODULE: ./node_modules/xstate/es/scheduler.js
var defaultOptions = {
deferEvents: false
};
var Scheduler =
/*#__PURE__*/
/** @class */
function () {
function Scheduler(options) {
this.processingEvent = false;
this.queue = [];
this.initialized = false;
this.options = (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, defaultOptions), options);
}
Scheduler.prototype.initialize = function (callback) {
this.initialized = true;
if (callback) {
if (!this.options.deferEvents) {
this.schedule(callback);
return;
}
this.process(callback);
}
this.flushEvents();
};
Scheduler.prototype.schedule = function (task) {
if (!this.initialized || this.processingEvent) {
this.queue.push(task);
return;
}
if (this.queue.length !== 0) {
throw new Error('Event queue should be empty when it is not processing events');
}
this.process(task);
this.flushEvents();
};
Scheduler.prototype.clear = function () {
this.queue = [];
};
Scheduler.prototype.flushEvents = function () {
var nextCallback = this.queue.shift();
while (nextCallback) {
this.process(nextCallback);
nextCallback = this.queue.shift();
}
};
Scheduler.prototype.process = function (callback) {
this.processingEvent = true;
try {
callback();
} catch (e) {
// there is no use to keep the future events
// as the situation is not anymore the same
this.clear();
throw e;
} finally {
this.processingEvent = false;
}
};
return Scheduler;
}();
// EXTERNAL MODULE: ./node_modules/xstate/es/Actor.js
var Actor = __webpack_require__(8933);
;// CONCATENATED MODULE: ./node_modules/xstate/es/registry.js
var children = /*#__PURE__*/new Map();
var sessionIdIndex = 0;
var registry = {
bookId: function () {
return "x:".concat(sessionIdIndex++);
},
register: function (id, actor) {
children.set(id, actor);
return id;
},
get: function (id) {
return children.get(id);
},
free: function (id) {
children.delete(id);
}
};
;// CONCATENATED MODULE: ./node_modules/xstate/es/devTools.js
function getGlobal() {
if (typeof globalThis !== 'undefined') {
return globalThis;
}
if (typeof self !== 'undefined') {
return self;
}
if (typeof window !== 'undefined') {
return window;
}
if (typeof __webpack_require__.g !== 'undefined') {
return __webpack_require__.g;
}
if (!environment/* IS_PRODUCTION */.M) {
console.warn('XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues');
}
}
function getDevTools() {
var global = getGlobal();
if (global && '__xstate__' in global) {
return global.__xstate__;
}
return undefined;
}
function registerService(service) {
if (!getGlobal()) {
return;
}
var devTools = getDevTools();
if (devTools) {
devTools.register(service);
}
}
// EXTERNAL MODULE: ./node_modules/xstate/es/serviceScope.js
var serviceScope = __webpack_require__(797);
// EXTERNAL MODULE: ./node_modules/xstate/es/behaviors.js
var behaviors = __webpack_require__(8199);
;// CONCATENATED MODULE: ./node_modules/xstate/es/interpreter.js
var DEFAULT_SPAWN_OPTIONS = {
sync: false,
autoForward: false
};
var InterpreterStatus;
(function (InterpreterStatus) {
InterpreterStatus[InterpreterStatus["NotStarted"] = 0] = "NotStarted";
InterpreterStatus[InterpreterStatus["Running"] = 1] = "Running";
InterpreterStatus[InterpreterStatus["Stopped"] = 2] = "Stopped";
})(InterpreterStatus || (InterpreterStatus = {}));
var Interpreter =
/*#__PURE__*/
/** @class */
function () {
/**
* Creates a new Interpreter instance (i.e., service) for the given machine with the provided options, if any.
*
* @param machine The machine to be interpreted
* @param options Interpreter options
*/
function Interpreter(machine, options) {
if (options === void 0) {
options = Interpreter.defaultOptions;
}
var _this = this;
this.machine = machine;
this.delayedEventsMap = {};
this.listeners = new Set();
this.contextListeners = new Set();
this.stopListeners = new Set();
this.doneListeners = new Set();
this.eventListeners = new Set();
this.sendListeners = new Set();
/**
* Whether the service is started.
*/
this.initialized = false;
this.status = InterpreterStatus.NotStarted;
this.children = new Map();
this.forwardTo = new Set();
this._outgoingQueue = [];
/**
* Alias for Interpreter.prototype.start
*/
this.init = this.start;
/**
* Sends an event to the running interpreter to trigger a transition.
*
* An array of events (batched) can be sent as well, which will send all
* batched events to the running interpreter. The listeners will be
* notified only **once** when all events are processed.
*
* @param event The event(s) to send
*/
this.send = function (event, payload) {
if ((0,utils/* isArray */.kJ)(event)) {
_this.batch(event);
return _this.state;
}
var _event = (0,utils/* toSCXMLEvent */.g5)((0,utils/* toEventObject */._v)(event, payload));
if (_this.status === InterpreterStatus.Stopped) {
// do nothing
if (!environment/* IS_PRODUCTION */.M) {
(0,utils/* warn */.ZK)(false, "Event \"".concat(_event.name, "\" was sent to stopped service \"").concat(_this.machine.id, "\". This service has already reached its final state, and will not transition.\nEvent: ").concat(JSON.stringify(_event.data)));
}
return _this.state;
}
if (_this.status !== InterpreterStatus.Running && !_this.options.deferEvents) {
throw new Error("Event \"".concat(_event.name, "\" was sent to uninitialized service \"").concat(_this.machine.id // tslint:disable-next-line:max-line-length
, "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ").concat(JSON.stringify(_event.data)));
}
_this.scheduler.schedule(function () {
// Forward copy of event to child actors
_this.forward(_event);
var nextState = _this._nextState(_event);
_this.update(nextState, _event);
});
return _this._state; // TODO: deprecate (should return void)
// tslint:disable-next-line:semicolon
};
this.sendTo = function (event, to, immediate) {
var isParent = _this.parent && (to === types/* SpecialTargets */.K.Parent || _this.parent.id === to);
var target = isParent ? _this.parent : (0,utils/* isString */.HD)(to) ? to === types/* SpecialTargets */.K.Internal ? _this : _this.children.get(to) || registry.get(to) : (0,utils/* isActor */.Bc)(to) ? to : undefined;
if (!target) {
if (!isParent) {
throw new Error("Unable to send event to child '".concat(to, "' from service '").concat(_this.id, "'."));
} // tslint:disable-next-line:no-console
if (!environment/* IS_PRODUCTION */.M) {
(0,utils/* warn */.ZK)(false, "Service '".concat(_this.id, "' has no parent: unable to send event ").concat(event.type));
}
return;
}
if ('machine' in target) {
// perhaps those events should be rejected in the parent
// but atm it doesn't have easy access to all of the information that is required to do it reliably
if (_this.status !== InterpreterStatus.Stopped || _this.parent !== target || // we need to send events to the parent from exit handlers of a machine that reached its final state
_this.state.done) {
// Send SCXML events to machines
var scxmlEvent = (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, event), {
name: event.name === actionTypes.error ? "".concat((0,actions.error)(_this.id)) : event.name,
origin: _this.sessionId
});
if (!immediate && _this.machine.config.predictableActionArguments) {
_this._outgoingQueue.push([target, scxmlEvent]);
} else {
target.send(scxmlEvent);
}
}
} else {
// Send normal events to other targets
if (!immediate && _this.machine.config.predictableActionArguments) {
_this._outgoingQueue.push([target, event.data]);
} else {
target.send(event.data);
}
}
};
this._exec = function (action, context, _event, actionFunctionMap) {
if (actionFunctionMap === void 0) {
actionFunctionMap = _this.machine.options.actions;
}
var actionOrExec = action.exec || (0,actions.getActionFunction)(action.type, actionFunctionMap);
var exec = (0,utils/* isFunction */.mf)(actionOrExec) ? actionOrExec : actionOrExec ? actionOrExec.exec : action.exec;
if (exec) {
try {
return exec(context, _event.data, !_this.machine.config.predictableActionArguments ? {
action: action,
state: _this.state,
_event: _event
} : {
action: action,
_event: _event
});
} catch (err) {
if (_this.parent) {
_this.parent.send({
type: 'xstate.error',
data: err
});
}
throw err;
}
}
switch (action.type) {
case actionTypes.raise:
{
// if raise action reached the interpreter then it's a delayed one
var sendAction_1 = action;
_this.defer(sendAction_1);
break;
}
case actionTypes.send:
var sendAction = action;
if (typeof sendAction.delay === 'number') {
_this.defer(sendAction);
return;
} else {
if (sendAction.to) {
_this.sendTo(sendAction._event, sendAction.to, _event === actions.initEvent);
} else {
_this.send(sendAction._event);
}
}
break;
case actionTypes.cancel:
_this.cancel(action.sendId);
break;
case actionTypes.start:
{
if (_this.status !== InterpreterStatus.Running) {
return;
}
var activity = action.activity; // If the activity will be stopped right after it's started
// (such as in transient states)
// don't bother starting the activity.
if ( // in v4 with `predictableActionArguments` invokes are called eagerly when the `this.state` still points to the previous state
!_this.machine.config.predictableActionArguments && !_this.state.activities[activity.id || activity.type]) {
break;
} // Invoked services
if (activity.type === types/* ActionTypes */.M.Invoke) {
var invokeSource = (0,utils/* toInvokeSource */.j)(activity.src);
var serviceCreator = _this.machine.options.services ? _this.machine.options.services[invokeSource.type] : undefined;
var id = activity.id,
data = activity.data;
if (!environment/* IS_PRODUCTION */.M) {
(0,utils/* warn */.ZK)(!('forward' in activity), // tslint:disable-next-line:max-line-length
"`forward` property is deprecated (found in invocation of '".concat(activity.src, "' in in machine '").concat(_this.machine.id, "'). ") + "Please use `autoForward` instead.");
}
var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
if (!serviceCreator) {
// tslint:disable-next-line:no-console
if (!environment/* IS_PRODUCTION */.M) {
(0,utils/* warn */.ZK)(false, "No service found for invocation '".concat(activity.src, "' in machine '").concat(_this.machine.id, "'."));
}
return;
}
var resolvedData = data ? (0,utils/* mapContext */.QX)(data, context, _event) : undefined;
if (typeof serviceCreator === 'string') {
// TODO: warn
return;
}
var source = (0,utils/* isFunction */.mf)(serviceCreator) ? serviceCreator(context, _event.data, {
data: resolvedData,
src: invokeSource,
meta: activity.meta
}) : serviceCreator;
if (!source) {
// TODO: warn?
return;
}
var options = void 0;
if ((0,utils/* isMachine */.O4)(source)) {
source = resolvedData ? source.withContext(resolvedData) : source;
options = {
autoForward: autoForward
};
}
_this.spawn(source, id, options);
} else {
_this.spawnActivity(activity);
}
break;
}
case actionTypes.stop:
{
_this.stopChild(action.activity.id);
break;
}
case actionTypes.log:
var _a = action,
label = _a.label,
value = _a.value;
if (label) {
_this.logger(label, value);
} else {
_this.logger(value);
}
break;
default:
if (!environment/* IS_PRODUCTION */.M) {
(0,utils/* warn */.ZK)(false, "No implementation found for action type '".concat(action.type, "'"));
}
break;
}
};
var resolvedOptions = (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, Interpreter.defaultOptions), options);
var clock = resolvedOptions.clock,
logger = resolvedOptions.logger,
parent = resolvedOptions.parent,
id = resolvedOptions.id;
var resolvedId = id !== undefined ? id : machine.id;
this.id = resolvedId;
this.logger = logger;
this.clock = clock;
this.parent = parent;
this.options = resolvedOptions;
this.scheduler = new Scheduler({
deferEvents: this.options.deferEvents
});
this.sessionId = registry.bookId();
}
Object.defineProperty(Interpreter.prototype, "initialState", {
get: function () {
var _this = this;
if (this._initialState) {
return this._initialState;
}
return (0,serviceScope/* provide */.J)(this, function () {
_this._initialState = _this.machine.initialState;
return _this._initialState;
});
},
enumerable: false,
configurable: true
});
Object.defineProperty(Interpreter.prototype, "state", {
/**
* @deprecated Use `.getSnapshot()` instead.
*/
get: function () {
if (!environment/* IS_PRODUCTION */.M) {
(0,utils/* warn */.ZK)(this.status !== InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '".concat(this.id, "'. Make sure the service is started first."));
}
return this._state;
},
enumerable: false,
configurable: true
});
/**
* Executes the actions of the given state, with that state's `context` and `event`.
*
* @param state The state whose actions will be executed
* @param actionsConfig The action implementations to use
*/
Interpreter.prototype.execute = function (state, actionsConfig) {
var e_1, _a;
try {
for (var _b = (0,_tslib/* __values */.XA)(state.actions), _c = _b.next(); !_c.done; _c = _b.next()) {
var action = _c.value;
this.exec(action, state, actionsConfig);
}
} catch (e_1_1) {
e_1 = {
error: e_1_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_1) throw e_1.error;
}
}
};
Interpreter.prototype.update = function (state, _event) {
var e_2, _a, e_3, _b, e_4, _c, e_5, _d;
var _this = this; // Attach session ID to state
state._sessionid = this.sessionId; // Update state
this._state = state; // Execute actions
if ((!this.machine.config.predictableActionArguments || // this is currently required to execute initial actions as the `initialState` gets cached
// we can't just recompute it (and execute actions while doing so) because we try to preserve identity of actors created within initial assigns
_event === actions.initEvent) && this.options.execute) {
this.execute(this.state);
} else {
var item = void 0;
while (item = this._outgoingQueue.shift()) {
item[0].send(item[1]);
}
} // Update children
this.children.forEach(function (child) {
_this.state.children[child.id] = child;
}); // Dev tools
if (this.devTools) {
this.devTools.send(_event.data, state);
} // Execute listeners
if (state.event) {
try {
for (var _e = (0,_tslib/* __values */.XA)(this.eventListeners), _f = _e.next(); !_f.done; _f = _e.next()) {
var listener = _f.value;
listener(state.event);
}
} catch (e_2_1) {
e_2 = {
error: e_2_1
};
} finally {
try {
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
} finally {
if (e_2) throw e_2.error;
}
}
}
try {
for (var _g = (0,_tslib/* __values */.XA)(this.listeners), _h = _g.next(); !_h.done; _h = _g.next()) {
var listener = _h.value;
listener(state, state.event);
}
} catch (e_3_1) {
e_3 = {
error: e_3_1
};
} finally {
try {
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
} finally {
if (e_3) throw e_3.error;
}
}
try {
for (var _j = (0,_tslib/* __values */.XA)(this.contextListeners), _k = _j.next(); !_k.done; _k = _j.next()) {
var contextListener = _k.value;
contextListener(this.state.context, this.state.history ? this.state.history.context : undefined);
}
} catch (e_4_1) {
e_4 = {
error: e_4_1
};
} finally {
try {
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
} finally {
if (e_4) throw e_4.error;
}
}
if (this.state.done) {
// get final child state node
var finalChildStateNode = state.configuration.find(function (sn) {
return sn.type === 'final' && sn.parent === _this.machine;
});
var doneData = finalChildStateNode && finalChildStateNode.doneData ? (0,utils/* mapContext */.QX)(finalChildStateNode.doneData, state.context, _event) : undefined;
this._doneEvent = (0,actions.doneInvoke)(this.id, doneData);
try {
for (var _l = (0,_tslib/* __values */.XA)(this.doneListeners), _m = _l.next(); !_m.done; _m = _l.next()) {
var listener = _m.value;
listener(this._doneEvent);
}
} catch (e_5_1) {
e_5 = {
error: e_5_1
};
} finally {
try {
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
} finally {
if (e_5) throw e_5.error;
}
}
this._stop();
this._stopChildren();
registry.free(this.sessionId);
}
};
/*
* Adds a listener that is notified whenever a state transition happens. The listener is called with
* the next state and the event object that caused the state transition.
*
* @param listener The state listener
*/
Interpreter.prototype.onTransition = function (listener) {
this.listeners.add(listener); // Send current state to listener
if (this.status === InterpreterStatus.Running) {
listener(this.state, this.state.event);
}
return this;
};
Interpreter.prototype.subscribe = function (nextListenerOrObserver, _, // TODO: error listener
completeListener) {
var _this = this;
var observer = (0,utils/* toObserver */.zM)(nextListenerOrObserver, _, completeListener);
this.listeners.add(observer.next); // Send current state to listener
if (this.status !== InterpreterStatus.NotStarted) {
observer.next(this.state);
}
var completeOnce = function () {
_this.doneListeners.delete(completeOnce);
_this.stopListeners.delete(completeOnce);
observer.complete();
};
if (this.status === InterpreterStatus.Stopped) {
observer.complete();
} else {
this.onDone(completeOnce);
this.onStop(completeOnce);
}
return {
unsubscribe: function () {
_this.listeners.delete(observer.next);
_this.doneListeners.delete(completeOnce);
_this.stopListeners.delete(completeOnce);
}
};
};
/**
* Adds an event listener that is notified whenever an event is sent to the running interpreter.
* @param listener The event listener
*/
Interpreter.prototype.onEvent = function (listener) {
this.eventListeners.add(listener);
return this;
};
/**
* Adds an event listener that is notified whenever a `send` event occurs.
* @param listener The event listener
*/
Interpreter.prototype.onSend = function (listener) {
this.sendListeners.add(listener);
return this;
};
/**
* Adds a context listener that is notified whenever the state context changes.
* @param listener The context listener
*/
Interpreter.prototype.onChange = function (listener) {
this.contextListeners.add(listener);
return this;
};
/**
* Adds a listener that is notified when the machine is stopped.
* @param listener The listener
*/
Interpreter.prototype.onStop = function (listener) {
this.stopListeners.add(listener);
return this;
};
/**
* Adds a state listener that is notified when the statechart has reached its final state.
* @param listener The state listener
*/
Interpreter.prototype.onDone = function (listener) {
if (this.status === InterpreterStatus.Stopped && this._doneEvent) {
listener(this._doneEvent);
} else {
this.doneListeners.add(listener);
}
return this;
};
/**
* Removes a listener.
* @param listener The listener to remove
*/
Interpreter.prototype.off = function (listener) {
this.listeners.delete(listener);
this.eventListeners.delete(listener);
this.sendListeners.delete(listener);
this.stopListeners.delete(listener);
this.doneListeners.delete(listener);
this.contextListeners.delete(listener);
return this;
};
/**
* Starts the interpreter from the given state, or the initial state.
* @param initialState The state to start the statechart from
*/
Interpreter.prototype.start = function (initialState) {
var _this = this;
if (this.status === InterpreterStatus.Running) {
// Do not restart the service if it is already started
return this;
} // yes, it's a hack but we need the related cache to be populated for some things to work (like delayed transitions)
// this is usually called by `machine.getInitialState` but if we rehydrate from a state we might bypass this call
// we also don't want to call this method here as it resolves the full initial state which might involve calling assign actions
// and that could potentially lead to some unwanted side-effects (even such as creating some rogue actors)
this.machine._init();
registry.register(this.sessionId, this);
this.initialized = true;
this.status = InterpreterStatus.Running;
var resolvedState = initialState === undefined ? this.initialState : (0,serviceScope/* provide */.J)(this, function () {
return (0,State/* isStateConfig */.TL)(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State/* State */.ZM.from(initialState, _this.machine.context));
});
if (this.options.devTools) {
this.attachDev();
}
this.scheduler.initialize(function () {
_this.update(resolvedState, actions.initEvent);
});
return this;
};
Interpreter.prototype._stopChildren = function () {
// TODO: think about converting those to actions
this.children.forEach(function (child) {
if ((0,utils/* isFunction */.mf)(child.stop)) {
child.stop();
}
});
this.children.clear();
};
Interpreter.prototype._stop = function () {
var e_6, _a, e_7, _b, e_8, _c, e_9, _d, e_10, _e;
try {
for (var _f = (0,_tslib/* __values */.XA)(this.listeners), _g = _f.next(); !_g.done; _g = _f.next()) {
var listener = _g.value;
this.listeners.delete(listener);
}
} catch (e_6_1) {
e_6 = {
error: e_6_1
};
} finally {
try {
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
} finally {
if (e_6) throw e_6.error;
}
}
try {
for (var _h = (0,_tslib/* __values */.XA)(this.stopListeners), _j = _h.next(); !_j.done; _j = _h.next()) {
var listener = _j.value; // call listener, then remove
listener();
this.stopListeners.delete(listener);
}
} catch (e_7_1) {
e_7 = {
error: e_7_1
};
} finally {
try {
if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
} finally {
if (e_7) throw e_7.error;
}
}
try {
for (var _k = (0,_tslib/* __values */.XA)(this.contextListeners), _l = _k.next(); !_l.done; _l = _k.next()) {
var listener = _l.value;
this.contextListeners.delete(listener);
}
} catch (e_8_1) {
e_8 = {
error: e_8_1
};
} finally {
try {
if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
} finally {
if (e_8) throw e_8.error;
}
}
try {
for (var _m = (0,_tslib/* __values */.XA)(this.doneListeners), _o = _m.next(); !_o.done; _o = _m.next()) {
var listener = _o.value;
this.doneListeners.delete(listener);
}
} catch (e_9_1) {
e_9 = {
error: e_9_1
};
} finally {
try {
if (_o && !_o.done && (_d = _m.return)) _d.call(_m);
} finally {
if (e_9) throw e_9.error;
}
}
if (!this.initialized) {
// Interpreter already stopped; do nothing
return this;
}
this.initialized = false;
this.status = InterpreterStatus.Stopped;
this._initialState = undefined;
try {
// we are going to stop within the current sync frame
// so we can safely just cancel this here as nothing async should be fired anyway
for (var _p = (0,_tslib/* __values */.XA)(Object.keys(this.delayedEventsMap)), _q = _p.next(); !_q.done; _q = _p.next()) {
var key = _q.value;
this.clock.clearTimeout(this.delayedEventsMap[key]);
}
} catch (e_10_1) {
e_10 = {
error: e_10_1
};
} finally {
try {
if (_q && !_q.done && (_e = _p.return)) _e.call(_p);
} finally {
if (e_10) throw e_10.error;
}
} // clear everything that might be enqueued
this.scheduler.clear();
this.scheduler = new Scheduler({
deferEvents: this.options.deferEvents
});
};
/**
* Stops the interpreter and unsubscribe all listeners.
*
* This will also notify the `onStop` listeners.
*/
Interpreter.prototype.stop = function () {
// TODO: add warning for stopping non-root interpreters
var _this = this; // grab the current scheduler as it will be replaced in _stop
var scheduler = this.scheduler;
this._stop(); // let what is currently processed to be finished
scheduler.schedule(function () {
// it feels weird to handle this here but we need to handle this even slightly "out of band"
var _event = (0,utils/* toSCXMLEvent */.g5)({
type: 'xstate.stop'
});
var nextState = (0,serviceScope/* provide */.J)(_this, function () {
var exitActions = (0,utils/* flatten */.xH)((0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)(_this.state.configuration), false).sort(function (a, b) {
return b.order - a.order;
}).map(function (stateNode) {
return (0,actions.toActionObjects)(stateNode.onExit, _this.machine.options.actions);
}));
var _a = (0,_tslib/* __read */.CR)((0,actions.resolveActions)(_this.machine, _this.state, _this.state.context, _event, [{
type: 'exit',
actions: exitActions
}], _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
resolvedActions = _a[0],
updatedContext = _a[1];
var newState = new State/* State */.ZM({
value: _this.state.value,
context: updatedContext,
_event: _event,
_sessionid: _this.sessionId,
historyValue: undefined,
history: _this.state,
actions: resolvedActions.filter(function (action) {
return !(0,utils/* isRaisableAction */.vK)(action);
}),
activities: {},
events: [],
configuration: [],
transitions: [],
children: {},
done: _this.state.done,
tags: _this.state.tags,
machine: _this.machine
});
newState.changed = true;
return newState;
});
_this.update(nextState, _event);
_this._stopChildren();
registry.free(_this.sessionId);
});
return this;
};
Interpreter.prototype.batch = function (events) {
var _this = this;
if (this.status === InterpreterStatus.NotStarted && this.options.deferEvents) {
// tslint:disable-next-line:no-console
if (!environment/* IS_PRODUCTION */.M) {
(0,utils/* warn */.ZK)(false, "".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\" and are deferred. Make sure .start() is called for this service.\nEvent: ").concat(JSON.stringify(event)));
}
} else if (this.status !== InterpreterStatus.Running) {
throw new Error( // tslint:disable-next-line:max-line-length
"".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options."));
}
if (!events.length) {
return;
}
var exec = !!this.machine.config.predictableActionArguments && this._exec;
this.scheduler.schedule(function () {
var e_11, _a;
var nextState = _this.state;
var batchChanged = false;
var batchedActions = [];
var _loop_1 = function (event_1) {
var _event = (0,utils/* toSCXMLEvent */.g5)(event_1);
_this.forward(_event);
nextState = (0,serviceScope/* provide */.J)(_this, function () {
return _this.machine.transition(nextState, _event, undefined, exec || undefined);
});
batchedActions.push.apply(batchedActions, (0,_tslib/* __spreadArray */.ev)([], (0,_tslib/* __read */.CR)(_this.machine.config.predictableActionArguments ? nextState.actions : nextState.actions.map(function (a) {
return (0,State/* bindActionToState */.j1)(a, nextState);
})), false));
batchChanged = batchChanged || !!nextState.changed;
};
try {
for (var events_1 = (0,_tslib/* __values */.XA)(events), events_1_1 = events_1.next(); !events_1_1.done; events_1_1 = events_1.next()) {
var event_1 = events_1_1.value;
_loop_1(event_1);
}
} catch (e_11_1) {
e_11 = {
error: e_11_1
};
} finally {
try {
if (events_1_1 && !events_1_1.done && (_a = events_1.return)) _a.call(events_1);
} finally {
if (e_11) throw e_11.error;
}
}
nextState.changed = batchChanged;
nextState.actions = batchedActions;
_this.update(nextState, (0,utils/* toSCXMLEvent */.g5)(events[events.length - 1]));
});
};
/**
* Returns a send function bound to this interpreter instance.
*
* @param event The event to be sent by the sender.
*/
Interpreter.prototype.sender = function (event) {
return this.send.bind(this, event);
};
Interpreter.prototype._nextState = function (event, exec) {
var _this = this;
if (exec === void 0) {
exec = !!this.machine.config.predictableActionArguments && this._exec;
}
var _event = (0,utils/* toSCXMLEvent */.g5)(event);
if (_event.name.indexOf(actionTypes.errorPlatform) === 0 && !this.state.nextEvents.some(function (nextEvent) {
return nextEvent.indexOf(actionTypes.errorPlatform) === 0;
})) {
throw _event.data.data;
}
var nextState = (0,serviceScope/* provide */.J)(this, function () {
return _this.machine.transition(_this.state, _event, undefined, exec || undefined);
});
return nextState;
};
/**
* Returns the next state given the interpreter's current state and the event.
*
* This is a pure method that does _not_ update the interpreter's state.
*
* @param event The event to determine the next state
*/
Interpreter.prototype.nextState = function (event) {
return this._nextState(event, false);
};
Interpreter.prototype.forward = function (event) {
var e_12, _a;
try {
for (var _b = (0,_tslib/* __values */.XA)(this.forwardTo), _c = _b.next(); !_c.done; _c = _b.next()) {
var id = _c.value;
var child = this.children.get(id);
if (!child) {
throw new Error("Unable to forward event '".concat(event, "' from interpreter '").concat(this.id, "' to nonexistant child '").concat(id, "'."));
}
child.send(event);
}
} catch (e_12_1) {
e_12 = {
error: e_12_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_12) throw e_12.error;
}
}
};
Interpreter.prototype.defer = function (sendAction) {
var _this = this;
var timerId = this.clock.setTimeout(function () {
if ('to' in sendAction && sendAction.to) {
_this.sendTo(sendAction._event, sendAction.to, true);
} else {
_this.send(sendAction._event);
}
}, sendAction.delay);
if (sendAction.id) {
this.delayedEventsMap[sendAction.id] = timerId;
}
};
Interpreter.prototype.cancel = function (sendId) {
this.clock.clearTimeout(this.delayedEventsMap[sendId]);
delete this.delayedEventsMap[sendId];
};
Interpreter.prototype.exec = function (action, state, actionFunctionMap) {
if (actionFunctionMap === void 0) {
actionFunctionMap = this.machine.options.actions;
}
this._exec(action, state.context, state._event, actionFunctionMap);
};
Interpreter.prototype.removeChild = function (childId) {
var _a;
this.children.delete(childId);
this.forwardTo.delete(childId); // this.state might not exist at the time this is called,
// such as when a child is added then removed while initializing the state
(_a = this.state) === null || _a === void 0 ? true : delete _a.children[childId];
};
Interpreter.prototype.stopChild = function (childId) {
var child = this.children.get(childId);
if (!child) {
return;
}
this.removeChild(childId);
if ((0,utils/* isFunction */.mf)(child.stop)) {
child.stop();
}
};
Interpreter.prototype.spawn = function (entity, name, options) {
if (this.status !== InterpreterStatus.Running) {
return (0,Actor/* createDeferredActor */.Xg)(entity, name);
}
if ((0,utils/* isPromiseLike */.y8)(entity)) {
return this.spawnPromise(Promise.resolve(entity), name);
} else if ((0,utils/* isFunction */.mf)(entity)) {
return this.spawnCallback(entity, name);
} else if ((0,Actor/* isSpawnedActor */.f3)(entity)) {
return this.spawnActor(entity, name);
} else if ((0,utils/* isObservable */.bi)(entity)) {
return this.spawnObservable(entity, name);
} else if ((0,utils/* isMachine */.O4)(entity)) {
return this.spawnMachine(entity, (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, options), {
id: name
}));
} else if ((0,utils/* isBehavior */.HV)(entity)) {
return this.spawnBehavior(entity, name);
} else {
throw new Error("Unable to spawn entity \"".concat(name, "\" of type \"").concat(typeof entity, "\"."));
}
};
Interpreter.prototype.spawnMachine = function (machine, options) {
var _this = this;
if (options === void 0) {
options = {};
}
var childService = new Interpreter(machine, (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, this.options), {
parent: this,
id: options.id || machine.id
}));
var resolvedOptions = (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, DEFAULT_SPAWN_OPTIONS), options);
if (resolvedOptions.sync) {
childService.onTransition(function (state) {
_this.send(actionTypes.update, {
state: state,
id: childService.id
});
});
}
var actor = childService;
this.children.set(childService.id, actor);
if (resolvedOptions.autoForward) {
this.forwardTo.add(childService.id);
}
childService.onDone(function (doneEvent) {
_this.removeChild(childService.id);
_this.send((0,utils/* toSCXMLEvent */.g5)(doneEvent, {
origin: childService.id
}));
}).start();
return actor;
};
Interpreter.prototype.spawnBehavior = function (behavior, id) {
var actorRef = (0,behaviors/* spawnBehavior */.YP)(behavior, {
id: id,
parent: this
});
this.children.set(id, actorRef);
return actorRef;
};
Interpreter.prototype.spawnPromise = function (promise, id) {
var _a;
var _this = this;
var canceled = false;
var resolvedData;
promise.then(function (response) {
if (!canceled) {
resolvedData = response;
_this.removeChild(id);
_this.send((0,utils/* toSCXMLEvent */.g5)((0,actions.doneInvoke)(id, response), {
origin: id
}));
}
}, function (errorData) {
if (!canceled) {
_this.removeChild(id);
var errorEvent = (0,actions.error)(id, errorData);
try {
// Send "error.platform.id" to this (parent).
_this.send((0,utils/* toSCXMLEvent */.g5)(errorEvent, {
origin: id
}));
} catch (error) {
(0,utils/* reportUnhandledExceptionOnInvocation */.v4)(errorData, error, id);
if (_this.devTools) {
_this.devTools.send(errorEvent, _this.state);
}
if (_this.machine.strict) {
// it would be better to always stop the state machine if unhandled
// exception/promise rejection happens but because we don't want to
// break existing code so enforce it on strict mode only especially so
// because documentation says that onError is optional
_this.stop();
}
}
}
});
var actor = (_a = {
id: id,
send: function () {
return void 0;
},
subscribe: function (next, handleError, complete) {
var observer = (0,utils/* toObserver */.zM)(next, handleError, complete);
var unsubscribed = false;
promise.then(function (response) {
if (unsubscribed) {
return;
}
observer.next(response);
if (unsubscribed) {
return;
}
observer.complete();
}, function (err) {
if (unsubscribed) {
return;
}
observer.error(err);
});
return {
unsubscribe: function () {
return unsubscribed = true;
}
};
},
stop: function () {
canceled = true;
},
toJSON: function () {
return {
id: id
};
},
getSnapshot: function () {
return resolvedData;
}
}, _a[utils/* symbolObservable */.L$] = function () {
return this;
}, _a);
this.children.set(id, actor);
return actor;
};
Interpreter.prototype.spawnCallback = function (callback, id) {
var _a;
var _this = this;
var canceled = false;
var receivers = new Set();
var listeners = new Set();
var emitted;
var receive = function (e) {
emitted = e;
listeners.forEach(function (listener) {
return listener(e);
});
if (canceled) {
return;
}
_this.send((0,utils/* toSCXMLEvent */.g5)(e, {
origin: id
}));
};
var callbackStop;
try {
callbackStop = callback(receive, function (newListener) {
receivers.add(newListener);
});
} catch (err) {
this.send((0,actions.error)(id, err));
}
if ((0,utils/* isPromiseLike */.y8)(callbackStop)) {
// it turned out to be an async function, can't reliably check this before calling `callback`
// because transpiled async functions are not recognizable
return this.spawnPromise(callbackStop, id);
}
var actor = (_a = {
id: id,
send: function (event) {
return receivers.forEach(function (receiver) {
return receiver(event);
});
},
subscribe: function (next) {
var observer = (0,utils/* toObserver */.zM)(next);
listeners.add(observer.next);
return {
unsubscribe: function () {
listeners.delete(observer.next);
}
};
},
stop: function () {
canceled = true;
if ((0,utils/* isFunction */.mf)(callbackStop)) {
callbackStop();
}
},
toJSON: function () {
return {
id: id
};
},
getSnapshot: function () {
return emitted;
}
}, _a[utils/* symbolObservable */.L$] = function () {
return this;
}, _a);
this.children.set(id, actor);
return actor;
};
Interpreter.prototype.spawnObservable = function (source, id) {
var _a;
var _this = this;
var emitted;
var subscription = source.subscribe(function (value) {
emitted = value;
_this.send((0,utils/* toSCXMLEvent */.g5)(value, {
origin: id
}));
}, function (err) {
_this.removeChild(id);
_this.send((0,utils/* toSCXMLEvent */.g5)((0,actions.error)(id, err), {
origin: id
}));
}, function () {
_this.removeChild(id);
_this.send((0,utils/* toSCXMLEvent */.g5)((0,actions.doneInvoke)(id), {
origin: id
}));
});
var actor = (_a = {
id: id,
send: function () {
return void 0;
},
subscribe: function (next, handleError, complete) {
return source.subscribe(next, handleError, complete);
},
stop: function () {
return subscription.unsubscribe();
},
getSnapshot: function () {
return emitted;
},
toJSON: function () {
return {
id: id
};
}
}, _a[utils/* symbolObservable */.L$] = function () {
return this;
}, _a);
this.children.set(id, actor);
return actor;
};
Interpreter.prototype.spawnActor = function (actor, name) {
this.children.set(name, actor);
return actor;
};
Interpreter.prototype.spawnActivity = function (activity) {
var implementation = this.machine.options && this.machine.options.activities ? this.machine.options.activities[activity.type] : undefined;
if (!implementation) {
if (!environment/* IS_PRODUCTION */.M) {
(0,utils/* warn */.ZK)(false, "No implementation found for activity '".concat(activity.type, "'"));
} // tslint:disable-next-line:no-console
return;
} // Start implementation
var dispose = implementation(this.state.context, activity);
this.spawnEffect(activity.id, dispose);
};
Interpreter.prototype.spawnEffect = function (id, dispose) {
var _a;
this.children.set(id, (_a = {
id: id,
send: function () {
return void 0;
},
subscribe: function () {
return {
unsubscribe: function () {
return void 0;
}
};
},
stop: dispose || undefined,
getSnapshot: function () {
return undefined;
},
toJSON: function () {
return {
id: id
};
}
}, _a[utils/* symbolObservable */.L$] = function () {
return this;
}, _a));
};
Interpreter.prototype.attachDev = function () {
var global = getGlobal();
if (this.options.devTools && global) {
if (global.__REDUX_DEVTOOLS_EXTENSION__) {
var devToolsOptions = typeof this.options.devTools === 'object' ? this.options.devTools : undefined;
this.devTools = global.__REDUX_DEVTOOLS_EXTENSION__.connect((0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({
name: this.id,
autoPause: true,
stateSanitizer: function (state) {
return {
value: state.value,
context: state.context,
actions: state.actions
};
}
}, devToolsOptions), {
features: (0,_tslib/* __assign */.pi)({
jump: false,
skip: false
}, devToolsOptions ? devToolsOptions.features : undefined)
}), this.machine);
this.devTools.init(this.state);
} // add XState-specific dev tooling hook
registerService(this);
}
};
Interpreter.prototype.toJSON = function () {
return {
id: this.id
};
};
Interpreter.prototype[utils/* symbolObservable */.L$] = function () {
return this;
};
Interpreter.prototype.getSnapshot = function () {
if (this.status === InterpreterStatus.NotStarted) {
return this.initialState;
}
return this._state;
};
/**
* The default interpreter options:
*
* - `clock` uses the global `setTimeout` and `clearTimeout` functions
* - `logger` uses the global `console.log()` method
*/
Interpreter.defaultOptions = {
execute: true,
deferEvents: true,
clock: {
setTimeout: function (fn, ms) {
return setTimeout(fn, ms);
},
clearTimeout: function (id) {
return clearTimeout(id);
}
},
logger: /*#__PURE__*/console.log.bind(console),
devTools: false
};
Interpreter.interpret = interpret;
return Interpreter;
}();
var resolveSpawnOptions = function (nameOrOptions) {
if ((0,utils/* isString */.HD)(nameOrOptions)) {
return (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, DEFAULT_SPAWN_OPTIONS), {
name: nameOrOptions
});
}
return (0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)((0,_tslib/* __assign */.pi)({}, DEFAULT_SPAWN_OPTIONS), {
name: (0,utils/* uniqueId */.EL)()
}), nameOrOptions);
};
function spawn(entity, nameOrOptions) {
var resolvedOptions = resolveSpawnOptions(nameOrOptions);
return (0,serviceScope/* consume */.F)(function (service) {
if (!environment/* IS_PRODUCTION */.M) {
var isLazyEntity = (0,utils/* isMachine */.O4)(entity) || (0,utils/* isFunction */.mf)(entity);
(0,utils/* warn */.ZK)(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"".concat((0,utils/* isMachine */.O4)(entity) ? entity.id : 'undefined', "\") outside of a service. This will have no effect."));
}
if (service) {
return service.spawn(entity, resolvedOptions.name, resolvedOptions);
} else {
return (0,Actor/* createDeferredActor */.Xg)(entity, resolvedOptions.name);
}
});
}
/**
* Creates a new Interpreter instance for the given machine with the provided options, if any.
*
* @param machine The machine to interpret
* @param options Interpreter options
*/
function interpret(machine, options) {
var interpreter = new Interpreter(machine, options);
return interpreter;
}
/***/ }),
/***/ 797:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ F: () => (/* binding */ consume),
/* harmony export */ J: () => (/* binding */ provide)
/* harmony export */ });
/**
* Maintains a stack of the current service in scope.
* This is used to provide the correct service to spawn().
*/
var serviceStack = [];
var provide = function (service, fn) {
serviceStack.push(service);
var result = fn(service);
serviceStack.pop();
return result;
};
var consume = function (fn) {
return fn(serviceStack[serviceStack.length - 1]);
};
/***/ }),
/***/ 6115:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ G: () => (/* binding */ getChildren),
/* harmony export */ Ij: () => (/* binding */ isInFinalState),
/* harmony export */ N9: () => (/* binding */ isLeafNode),
/* harmony export */ NA: () => (/* binding */ getValue),
/* harmony export */ Oe: () => (/* binding */ getTagsFromConfiguration),
/* harmony export */ P_: () => (/* binding */ getConfiguration),
/* harmony export */ ac: () => (/* binding */ getAllStateNodes),
/* harmony export */ e$: () => (/* binding */ has),
/* harmony export */ nI: () => (/* binding */ getAllChildren),
/* harmony export */ nJ: () => (/* binding */ nextEvents),
/* harmony export */ xZ: () => (/* binding */ getMeta)
/* harmony export */ });
/* unused harmony export getAdjList */
/* harmony import */ var _virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3056);
/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9823);
var isLeafNode = function (stateNode) {
return stateNode.type === 'atomic' || stateNode.type === 'final';
};
function getAllChildren(stateNode) {
return Object.keys(stateNode.states).map(function (key) {
return stateNode.states[key];
});
}
function getChildren(stateNode) {
return getAllChildren(stateNode).filter(function (sn) {
return sn.type !== 'history';
});
}
function getAllStateNodes(stateNode) {
var stateNodes = [stateNode];
if (isLeafNode(stateNode)) {
return stateNodes;
}
return stateNodes.concat((0,_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .flatten */ .xH)(getChildren(stateNode).map(getAllStateNodes)));
}
function getConfiguration(prevStateNodes, stateNodes) {
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
var prevConfiguration = new Set(prevStateNodes);
var prevAdjList = getAdjList(prevConfiguration);
var configuration = new Set(stateNodes);
try {
// add all ancestors
for (var configuration_1 = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__values */ .XA)(configuration), configuration_1_1 = configuration_1.next(); !configuration_1_1.done; configuration_1_1 = configuration_1.next()) {
var s = configuration_1_1.value;
var m = s.parent;
while (m && !configuration.has(m)) {
configuration.add(m);
m = m.parent;
}
}
} catch (e_1_1) {
e_1 = {
error: e_1_1
};
} finally {
try {
if (configuration_1_1 && !configuration_1_1.done && (_a = configuration_1.return)) _a.call(configuration_1);
} finally {
if (e_1) throw e_1.error;
}
}
var adjList = getAdjList(configuration);
try {
// add descendants
for (var configuration_2 = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__values */ .XA)(configuration), configuration_2_1 = configuration_2.next(); !configuration_2_1.done; configuration_2_1 = configuration_2.next()) {
var s = configuration_2_1.value; // if previously active, add existing child nodes
if (s.type === 'compound' && (!adjList.get(s) || !adjList.get(s).length)) {
if (prevAdjList.get(s)) {
prevAdjList.get(s).forEach(function (sn) {
return configuration.add(sn);
});
} else {
s.initialStateNodes.forEach(function (sn) {
return configuration.add(sn);
});
}
} else {
if (s.type === 'parallel') {
try {
for (var _e = (e_3 = void 0, (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__values */ .XA)(getChildren(s))), _f = _e.next(); !_f.done; _f = _e.next()) {
var child = _f.value;
if (!configuration.has(child)) {
configuration.add(child);
if (prevAdjList.get(child)) {
prevAdjList.get(child).forEach(function (sn) {
return configuration.add(sn);
});
} else {
child.initialStateNodes.forEach(function (sn) {
return configuration.add(sn);
});
}
}
}
} catch (e_3_1) {
e_3 = {
error: e_3_1
};
} finally {
try {
if (_f && !_f.done && (_c = _e.return)) _c.call(_e);
} finally {
if (e_3) throw e_3.error;
}
}
}
}
}
} catch (e_2_1) {
e_2 = {
error: e_2_1
};
} finally {
try {
if (configuration_2_1 && !configuration_2_1.done && (_b = configuration_2.return)) _b.call(configuration_2);
} finally {
if (e_2) throw e_2.error;
}
}
try {
// add all ancestors
for (var configuration_3 = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__values */ .XA)(configuration), configuration_3_1 = configuration_3.next(); !configuration_3_1.done; configuration_3_1 = configuration_3.next()) {
var s = configuration_3_1.value;
var m = s.parent;
while (m && !configuration.has(m)) {
configuration.add(m);
m = m.parent;
}
}
} catch (e_4_1) {
e_4 = {
error: e_4_1
};
} finally {
try {
if (configuration_3_1 && !configuration_3_1.done && (_d = configuration_3.return)) _d.call(configuration_3);
} finally {
if (e_4) throw e_4.error;
}
}
return configuration;
}
function getValueFromAdj(baseNode, adjList) {
var childStateNodes = adjList.get(baseNode);
if (!childStateNodes) {
return {}; // todo: fix?
}
if (baseNode.type === 'compound') {
var childStateNode = childStateNodes[0];
if (childStateNode) {
if (isLeafNode(childStateNode)) {
return childStateNode.key;
}
} else {
return {};
}
}
var stateValue = {};
childStateNodes.forEach(function (csn) {
stateValue[csn.key] = getValueFromAdj(csn, adjList);
});
return stateValue;
}
function getAdjList(configuration) {
var e_5, _a;
var adjList = new Map();
try {
for (var configuration_4 = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__values */ .XA)(configuration), configuration_4_1 = configuration_4.next(); !configuration_4_1.done; configuration_4_1 = configuration_4.next()) {
var s = configuration_4_1.value;
if (!adjList.has(s)) {
adjList.set(s, []);
}
if (s.parent) {
if (!adjList.has(s.parent)) {
adjList.set(s.parent, []);
}
adjList.get(s.parent).push(s);
}
}
} catch (e_5_1) {
e_5 = {
error: e_5_1
};
} finally {
try {
if (configuration_4_1 && !configuration_4_1.done && (_a = configuration_4.return)) _a.call(configuration_4);
} finally {
if (e_5) throw e_5.error;
}
}
return adjList;
}
function getValue(rootNode, configuration) {
var config = getConfiguration([rootNode], configuration);
return getValueFromAdj(rootNode, getAdjList(config));
}
function has(iterable, item) {
if (Array.isArray(iterable)) {
return iterable.some(function (member) {
return member === item;
});
}
if (iterable instanceof Set) {
return iterable.has(item);
}
return false; // TODO: fix
}
function nextEvents(configuration) {
return (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__spreadArray */ .ev)([], (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__read */ .CR)(new Set((0,_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .flatten */ .xH)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__spreadArray */ .ev)([], (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__read */ .CR)(configuration.map(function (sn) {
return sn.ownEvents;
})), false)))), false);
}
function isInFinalState(configuration, stateNode) {
if (stateNode.type === 'compound') {
return getChildren(stateNode).some(function (s) {
return s.type === 'final' && has(configuration, s);
});
}
if (stateNode.type === 'parallel') {
return getChildren(stateNode).every(function (sn) {
return isInFinalState(configuration, sn);
});
}
return false;
}
function getMeta(configuration) {
if (configuration === void 0) {
configuration = [];
}
return configuration.reduce(function (acc, stateNode) {
if (stateNode.meta !== undefined) {
acc[stateNode.id] = stateNode.meta;
}
return acc;
}, {});
}
function getTagsFromConfiguration(configuration) {
return new Set((0,_utils_js__WEBPACK_IMPORTED_MODULE_0__/* .flatten */ .xH)(configuration.map(function (sn) {
return sn.tags;
})));
}
/***/ }),
/***/ 9043:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ K: () => (/* binding */ SpecialTargets),
/* harmony export */ M: () => (/* binding */ ActionTypes)
/* harmony export */ });
var ActionTypes;
(function (ActionTypes) {
ActionTypes["Start"] = "xstate.start";
ActionTypes["Stop"] = "xstate.stop";
ActionTypes["Raise"] = "xstate.raise";
ActionTypes["Send"] = "xstate.send";
ActionTypes["Cancel"] = "xstate.cancel";
ActionTypes["NullEvent"] = "";
ActionTypes["Assign"] = "xstate.assign";
ActionTypes["After"] = "xstate.after";
ActionTypes["DoneState"] = "done.state";
ActionTypes["DoneInvoke"] = "done.invoke";
ActionTypes["Log"] = "xstate.log";
ActionTypes["Init"] = "xstate.init";
ActionTypes["Invoke"] = "xstate.invoke";
ActionTypes["ErrorExecution"] = "error.execution";
ActionTypes["ErrorCommunication"] = "error.communication";
ActionTypes["ErrorPlatform"] = "error.platform";
ActionTypes["ErrorCustom"] = "xstate.error";
ActionTypes["Update"] = "xstate.update";
ActionTypes["Pure"] = "xstate.pure";
ActionTypes["Choose"] = "xstate.choose";
})(ActionTypes || (ActionTypes = {}));
var SpecialTargets;
(function (SpecialTargets) {
SpecialTargets["Parent"] = "#_parent";
SpecialTargets["Internal"] = "#_internal";
})(SpecialTargets || (SpecialTargets = {}));
/***/ }),
/***/ 9823:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Bc: () => (/* binding */ isActor),
/* harmony export */ EL: () => (/* binding */ uniqueId),
/* harmony export */ ET: () => (/* binding */ path),
/* harmony export */ HD: () => (/* binding */ isString),
/* harmony export */ HV: () => (/* binding */ isBehavior),
/* harmony export */ JQ: () => (/* binding */ isBuiltInEvent),
/* harmony export */ L$: () => (/* binding */ symbolObservable),
/* harmony export */ O4: () => (/* binding */ isMachine),
/* harmony export */ Q8: () => (/* binding */ mapValues),
/* harmony export */ Q9: () => (/* binding */ toStatePath),
/* harmony export */ QX: () => (/* binding */ mapContext),
/* harmony export */ Qi: () => (/* binding */ toGuard),
/* harmony export */ SA: () => (/* binding */ toStatePaths),
/* harmony export */ W: () => (/* binding */ matchesState),
/* harmony export */ WM: () => (/* binding */ toStateValue),
/* harmony export */ ZK: () => (/* binding */ warn),
/* harmony export */ _v: () => (/* binding */ toEventObject),
/* harmony export */ bi: () => (/* binding */ isObservable),
/* harmony export */ bx: () => (/* binding */ createInvokeId),
/* harmony export */ dt: () => (/* binding */ updateContext),
/* harmony export */ g5: () => (/* binding */ toSCXMLEvent),
/* harmony export */ gk: () => (/* binding */ nestedPath),
/* harmony export */ ib: () => (/* binding */ mapFilterValues),
/* harmony export */ j: () => (/* binding */ toInvokeSource),
/* harmony export */ jh: () => (/* binding */ toTransitionConfigArray),
/* harmony export */ kJ: () => (/* binding */ isArray),
/* harmony export */ mf: () => (/* binding */ isFunction),
/* harmony export */ on: () => (/* binding */ pathToStateValue),
/* harmony export */ qo: () => (/* binding */ toArray),
/* harmony export */ rg: () => (/* binding */ normalizeTarget),
/* harmony export */ uK: () => (/* binding */ partition),
/* harmony export */ v4: () => (/* binding */ reportUnhandledExceptionOnInvocation),
/* harmony export */ vK: () => (/* binding */ isRaisableAction),
/* harmony export */ vx: () => (/* binding */ evaluateGuard),
/* harmony export */ x6: () => (/* binding */ getEventType),
/* harmony export */ xH: () => (/* binding */ flatten),
/* harmony export */ y8: () => (/* binding */ isPromiseLike),
/* harmony export */ yv: () => (/* binding */ updateHistoryValue),
/* harmony export */ zM: () => (/* binding */ toObserver)
/* harmony export */ });
/* unused harmony exports getActionType, interopSymbols, isStateLike, keys, pathsToStateValue, toArrayStrict, updateHistoryStates */
/* harmony import */ var _virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3056);
/* harmony import */ var _types_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(9043);
/* harmony import */ var _actionTypes_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(3884);
/* harmony import */ var _constants_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7353);
/* harmony import */ var _environment_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4066);
var _a;
function keys(value) {
return Object.keys(value);
}
function matchesState(parentStateId, childStateId, delimiter) {
if (delimiter === void 0) {
delimiter = _constants_js__WEBPACK_IMPORTED_MODULE_0__/* .STATE_DELIMITER */ .iS;
}
var parentStateValue = toStateValue(parentStateId, delimiter);
var childStateValue = toStateValue(childStateId, delimiter);
if (isString(childStateValue)) {
if (isString(parentStateValue)) {
return childStateValue === parentStateValue;
} // Parent more specific than child
return false;
}
if (isString(parentStateValue)) {
return parentStateValue in childStateValue;
}
return Object.keys(parentStateValue).every(function (key) {
if (!(key in childStateValue)) {
return false;
}
return matchesState(parentStateValue[key], childStateValue[key]);
});
}
function getEventType(event) {
try {
return isString(event) || typeof event === 'number' ? "".concat(event) : event.type;
} catch (e) {
throw new Error('Events must be strings or objects with a string event.type property.');
}
}
function getActionType(action) {
try {
return isString(action) || typeof action === 'number' ? "".concat(action) : isFunction(action) ? action.name : action.type;
} catch (e) {
throw new Error('Actions must be strings or objects with a string action.type property.');
}
}
function toStatePath(stateId, delimiter) {
try {
if (isArray(stateId)) {
return stateId;
}
return stateId.toString().split(delimiter);
} catch (e) {
throw new Error("'".concat(stateId, "' is not a valid state path."));
}
}
function isStateLike(state) {
return typeof state === 'object' && 'value' in state && 'context' in state && 'event' in state && '_event' in state;
}
function toStateValue(stateValue, delimiter) {
if (isStateLike(stateValue)) {
return stateValue.value;
}
if (isArray(stateValue)) {
return pathToStateValue(stateValue);
}
if (typeof stateValue !== 'string') {
return stateValue;
}
var statePath = toStatePath(stateValue, delimiter);
return pathToStateValue(statePath);
}
function pathToStateValue(statePath) {
if (statePath.length === 1) {
return statePath[0];
}
var value = {};
var marker = value;
for (var i = 0; i < statePath.length - 1; i++) {
if (i === statePath.length - 2) {
marker[statePath[i]] = statePath[i + 1];
} else {
marker[statePath[i]] = {};
marker = marker[statePath[i]];
}
}
return value;
}
function mapValues(collection, iteratee) {
var result = {};
var collectionKeys = Object.keys(collection);
for (var i = 0; i < collectionKeys.length; i++) {
var key = collectionKeys[i];
result[key] = iteratee(collection[key], key, collection, i);
}
return result;
}
function mapFilterValues(collection, iteratee, predicate) {
var e_1, _a;
var result = {};
try {
for (var _b = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__values */ .XA)(Object.keys(collection)), _c = _b.next(); !_c.done; _c = _b.next()) {
var key = _c.value;
var item = collection[key];
if (!predicate(item)) {
continue;
}
result[key] = iteratee(item, key, collection);
}
} catch (e_1_1) {
e_1 = {
error: e_1_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_1) throw e_1.error;
}
}
return result;
}
/**
* Retrieves a value at the given path.
* @param props The deep path to the prop of the desired value
*/
var path = function (props) {
return function (object) {
var e_2, _a;
var result = object;
try {
for (var props_1 = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__values */ .XA)(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
var prop = props_1_1.value;
result = result[prop];
}
} catch (e_2_1) {
e_2 = {
error: e_2_1
};
} finally {
try {
if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
} finally {
if (e_2) throw e_2.error;
}
}
return result;
};
};
/**
* Retrieves a value at the given path via the nested accessor prop.
* @param props The deep path to the prop of the desired value
*/
function nestedPath(props, accessorProp) {
return function (object) {
var e_3, _a;
var result = object;
try {
for (var props_2 = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__values */ .XA)(props), props_2_1 = props_2.next(); !props_2_1.done; props_2_1 = props_2.next()) {
var prop = props_2_1.value;
result = result[accessorProp][prop];
}
} catch (e_3_1) {
e_3 = {
error: e_3_1
};
} finally {
try {
if (props_2_1 && !props_2_1.done && (_a = props_2.return)) _a.call(props_2);
} finally {
if (e_3) throw e_3.error;
}
}
return result;
};
}
function toStatePaths(stateValue) {
if (!stateValue) {
return [[]];
}
if (isString(stateValue)) {
return [[stateValue]];
}
var result = flatten(Object.keys(stateValue).map(function (key) {
var subStateValue = stateValue[key];
if (typeof subStateValue !== 'string' && (!subStateValue || !Object.keys(subStateValue).length)) {
return [[key]];
}
return toStatePaths(stateValue[key]).map(function (subPath) {
return [key].concat(subPath);
});
}));
return result;
}
function pathsToStateValue(paths) {
var e_4, _a;
var result = {};
if (paths && paths.length === 1 && paths[0].length === 1) {
return paths[0][0];
}
try {
for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
var currentPath = paths_1_1.value;
var marker = result; // tslint:disable-next-line:prefer-for-of
for (var i = 0; i < currentPath.length; i++) {
var subPath = currentPath[i];
if (i === currentPath.length - 2) {
marker[subPath] = currentPath[i + 1];
break;
}
marker[subPath] = marker[subPath] || {};
marker = marker[subPath];
}
}
} catch (e_4_1) {
e_4 = {
error: e_4_1
};
} finally {
try {
if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
} finally {
if (e_4) throw e_4.error;
}
}
return result;
}
function flatten(array) {
var _a;
return (_a = []).concat.apply(_a, (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__spreadArray */ .ev)([], (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__read */ .CR)(array), false));
}
function toArrayStrict(value) {
if (isArray(value)) {
return value;
}
return [value];
}
function toArray(value) {
if (value === undefined) {
return [];
}
return toArrayStrict(value);
}
function mapContext(mapper, context, _event) {
var e_5, _a;
if (isFunction(mapper)) {
return mapper(context, _event.data);
}
var result = {};
try {
for (var _b = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__values */ .XA)(Object.keys(mapper)), _c = _b.next(); !_c.done; _c = _b.next()) {
var key = _c.value;
var subMapper = mapper[key];
if (isFunction(subMapper)) {
result[key] = subMapper(context, _event.data);
} else {
result[key] = subMapper;
}
}
} catch (e_5_1) {
e_5 = {
error: e_5_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_5) throw e_5.error;
}
}
return result;
}
function isBuiltInEvent(eventType) {
return /^(done|error)\./.test(eventType);
}
function isPromiseLike(value) {
if (value instanceof Promise) {
return true;
} // Check if shape matches the Promise/A+ specification for a "thenable".
if (value !== null && (isFunction(value) || typeof value === 'object') && isFunction(value.then)) {
return true;
}
return false;
}
function isBehavior(value) {
return value !== null && typeof value === 'object' && 'transition' in value && typeof value.transition === 'function';
}
function partition(items, predicate) {
var e_6, _a;
var _b = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__read */ .CR)([[], []], 2),
truthy = _b[0],
falsy = _b[1];
try {
for (var items_1 = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__values */ .XA)(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
var item = items_1_1.value;
if (predicate(item)) {
truthy.push(item);
} else {
falsy.push(item);
}
}
} catch (e_6_1) {
e_6 = {
error: e_6_1
};
} finally {
try {
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
} finally {
if (e_6) throw e_6.error;
}
}
return [truthy, falsy];
}
function updateHistoryStates(hist, stateValue) {
return mapValues(hist.states, function (subHist, key) {
if (!subHist) {
return undefined;
}
var subStateValue = (isString(stateValue) ? undefined : stateValue[key]) || (subHist ? subHist.current : undefined);
if (!subStateValue) {
return undefined;
}
return {
current: subStateValue,
states: updateHistoryStates(subHist, subStateValue)
};
});
}
function updateHistoryValue(hist, stateValue) {
return {
current: stateValue,
states: updateHistoryStates(hist, stateValue)
};
}
function updateContext(context, _event, assignActions, state) {
if (!_environment_js__WEBPACK_IMPORTED_MODULE_2__/* .IS_PRODUCTION */ .M) {
warn(!!context, 'Attempting to update undefined context');
}
var updatedContext = context ? assignActions.reduce(function (acc, assignAction) {
var e_7, _a;
var assignment = assignAction.assignment;
var meta = {
state: state,
action: assignAction,
_event: _event
};
var partialUpdate = {};
if (isFunction(assignment)) {
partialUpdate = assignment(acc, _event.data, meta);
} else {
try {
for (var _b = (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__values */ .XA)(Object.keys(assignment)), _c = _b.next(); !_c.done; _c = _b.next()) {
var key = _c.value;
var propAssignment = assignment[key];
partialUpdate[key] = isFunction(propAssignment) ? propAssignment(acc, _event.data, meta) : propAssignment;
}
} catch (e_7_1) {
e_7 = {
error: e_7_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_7) throw e_7.error;
}
}
}
return Object.assign({}, acc, partialUpdate);
}, context) : context;
return updatedContext;
} // tslint:disable-next-line:no-empty
var warn = function () {};
if (!_environment_js__WEBPACK_IMPORTED_MODULE_2__/* .IS_PRODUCTION */ .M) {
warn = function (condition, message) {
var error = condition instanceof Error ? condition : undefined;
if (!error && condition) {
return;
}
if (console !== undefined) {
var args = ["Warning: ".concat(message)];
if (error) {
args.push(error);
} // tslint:disable-next-line:no-console
console.warn.apply(console, args);
}
};
}
function isArray(value) {
return Array.isArray(value);
} // tslint:disable-next-line:ban-types
function isFunction(value) {
return typeof value === 'function';
}
function isString(value) {
return typeof value === 'string';
}
function toGuard(condition, guardMap) {
if (!condition) {
return undefined;
}
if (isString(condition)) {
return {
type: _constants_js__WEBPACK_IMPORTED_MODULE_0__/* .DEFAULT_GUARD_TYPE */ .TV,
name: condition,
predicate: guardMap ? guardMap[condition] : undefined
};
}
if (isFunction(condition)) {
return {
type: _constants_js__WEBPACK_IMPORTED_MODULE_0__/* .DEFAULT_GUARD_TYPE */ .TV,
name: condition.name,
predicate: condition
};
}
return condition;
}
function isObservable(value) {
try {
return 'subscribe' in value && isFunction(value.subscribe);
} catch (e) {
return false;
}
}
var symbolObservable = /*#__PURE__*/function () {
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
}(); // TODO: to be removed in v5, left it out just to minimize the scope of the change and maintain compatibility with older versions of integration paackages
var interopSymbols = (_a = {}, _a[symbolObservable] = function () {
return this;
}, _a[Symbol.observable] = function () {
return this;
}, _a);
function isMachine(value) {
return !!value && '__xstatenode' in value;
}
function isActor(value) {
return !!value && typeof value.send === 'function';
}
var uniqueId = /*#__PURE__*/function () {
var currentId = 0;
return function () {
currentId++;
return currentId.toString(16);
};
}();
function toEventObject(event, payload // id?: TEvent['type']
) {
if (isString(event) || typeof event === 'number') {
return (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__assign */ .pi)({
type: event
}, payload);
}
return event;
}
function toSCXMLEvent(event, scxmlEvent) {
if (!isString(event) && '$$type' in event && event.$$type === 'scxml') {
return event;
}
var eventObject = toEventObject(event);
return (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__assign */ .pi)({
name: eventObject.type,
data: eventObject,
$$type: 'scxml',
type: 'external'
}, scxmlEvent);
}
function toTransitionConfigArray(event, configLike) {
var transitions = toArrayStrict(configLike).map(function (transitionLike) {
if (typeof transitionLike === 'undefined' || typeof transitionLike === 'string' || isMachine(transitionLike)) {
return {
target: transitionLike,
event: event
};
}
return (0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__assign */ .pi)((0,_virtual_tslib_js__WEBPACK_IMPORTED_MODULE_1__/* .__assign */ .pi)({}, transitionLike), {
event: event
});
});
return transitions;
}
function normalizeTarget(target) {
if (target === undefined || target === _constants_js__WEBPACK_IMPORTED_MODULE_0__/* .TARGETLESS_KEY */ .rt) {
return undefined;
}
return toArray(target);
}
function reportUnhandledExceptionOnInvocation(originalError, currentError, id) {
if (!_environment_js__WEBPACK_IMPORTED_MODULE_2__/* .IS_PRODUCTION */ .M) {
var originalStackTrace = originalError.stack ? " Stacktrace was '".concat(originalError.stack, "'") : '';
if (originalError === currentError) {
// tslint:disable-next-line:no-console
console.error("Missing onError handler for invocation '".concat(id, "', error was '").concat(originalError, "'.").concat(originalStackTrace));
} else {
var stackTrace = currentError.stack ? " Stacktrace was '".concat(currentError.stack, "'") : ''; // tslint:disable-next-line:no-console
console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '".concat(id, "'. ") + "Original error: '".concat(originalError, "'. ").concat(originalStackTrace, " Current error is '").concat(currentError, "'.").concat(stackTrace));
}
}
}
function evaluateGuard(machine, guard, context, _event, state) {
var guards = machine.options.guards;
var guardMeta = {
state: state,
cond: guard,
_event: _event
}; // TODO: do not hardcode!
if (guard.type === _constants_js__WEBPACK_IMPORTED_MODULE_0__/* .DEFAULT_GUARD_TYPE */ .TV) {
return ((guards === null || guards === void 0 ? void 0 : guards[guard.name]) || guard.predicate)(context, _event.data, guardMeta);
}
var condFn = guards === null || guards === void 0 ? void 0 : guards[guard.type];
if (!condFn) {
throw new Error("Guard '".concat(guard.type, "' is not implemented on machine '").concat(machine.id, "'."));
}
return condFn(context, _event.data, guardMeta);
}
function toInvokeSource(src) {
if (typeof src === 'string') {
return {
type: src
};
}
return src;
}
function toObserver(nextHandler, errorHandler, completionHandler) {
var noop = function () {};
var isObserver = typeof nextHandler === 'object';
var self = isObserver ? nextHandler : null;
return {
next: ((isObserver ? nextHandler.next : nextHandler) || noop).bind(self),
error: ((isObserver ? nextHandler.error : errorHandler) || noop).bind(self),
complete: ((isObserver ? nextHandler.complete : completionHandler) || noop).bind(self)
};
}
function createInvokeId(stateNodeId, index) {
return "".concat(stateNodeId, ":invocation[").concat(index, "]");
}
function isRaisableAction(action) {
return (action.type === _actionTypes_js__WEBPACK_IMPORTED_MODULE_3__.raise || action.type === _actionTypes_js__WEBPACK_IMPORTED_MODULE_3__.send && action.to === _types_js__WEBPACK_IMPORTED_MODULE_4__/* .SpecialTargets */ .K.Internal) && typeof action.delay !== 'number';
}
/***/ }),
/***/ 9744:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ AnimationModule)
/* harmony export */ });
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var AnimationModule = /*#__PURE__*/function () {
function AnimationModule() {
_classCallCheck(this, AnimationModule);
}
_createClass(AnimationModule, null, [{
key: "startAnimation",
value: function startAnimation(animation) {
this.stopOtherAnimations(animation);
var rectangles = document.querySelectorAll(this.rectanglesSelector);
rectangles.forEach(function (rect) {
return rect.classList.add(animation);
});
}
}, {
key: "stopAnimation",
value: function stopAnimation(animation) {
var rectangles = document.querySelectorAll(this.rectanglesSelector);
rectangles.forEach(function (rect) {
return rect.classList.remove(animation);
});
}
}, {
key: "stopAllAnimations",
value: function stopAllAnimations() {
var _this = this;
this.talkButtonAnimations.forEach(function (animation) {
return _this.stopAnimation(animation);
});
}
}, {
key: "stopOtherAnimations",
value: function stopOtherAnimations(keepAnimation) {
var _this2 = this;
this.talkButtonAnimations.forEach(function (animation) {
if (animation !== keepAnimation) {
_this2.stopAnimation(animation);
}
});
}
}]);
return AnimationModule;
}();
_defineProperty(AnimationModule, "rectanglesSelector", ".outermost, .second, .third, .fourth, .fifth, .innermost");
_defineProperty(AnimationModule, "talkButtonAnimations", ["piSpeaking", "userSpeaking", "transcribing"]);
/***/ }),
/***/ 6601:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
buttonModule: () => (/* binding */ buttonModule),
"default": () => (/* binding */ ButtonModule)
});
// EXTERNAL MODULE: ./src/UserAgentModule.js
var UserAgentModule = __webpack_require__(4008);
// EXTERNAL MODULE: ./src/DOMModule.ts
var DOMModule = __webpack_require__(8158);
// EXTERNAL MODULE: ./src/EventBus.js
var EventBus = __webpack_require__(7635);
// EXTERNAL MODULE: ./src/StateMachineService.js
var StateMachineService = __webpack_require__(8615);
// EXTERNAL MODULE: ./src/SubmitErrorHandler.ts
var SubmitErrorHandler = __webpack_require__(9947);
;// CONCATENATED MODULE: ./src/icons/exit.svg
/* harmony default export */ const exit = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg id=\"Layer_1\" data-name=\"Layer 1\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 64.06 64.33\">\n <defs>\n <style>\n .cls-1 {\n fill: #24381b;\n }\n\n .cls-1, .cls-2 {\n stroke-width: 0px;\n }\n\n .cls-2 {\n fill: #dfd7c2;\n }\n </style>\n </defs>\n <path class=\"cls-2\" d=\"m31.71,64.32C14.77,64.46-.44,49.93,0,31.33.41,14.47,14.29-.32,32.7,0c16.91.3,31.8,14.32,31.36,33.14-.39,16.76-14.49,31.55-32.34,31.18Zm10.67-23.19c.06-.7-.41-1.12-.84-1.55-2-2-3.94-4.07-6.02-5.97-1.14-1.04-1.32-1.68-.06-2.82,2.13-1.93,4.07-4.08,6.1-6.12.78-.79,1.31-1.64.34-2.56-.92-.87-1.72-.28-2.43.45-2.17,2.21-4.39,4.39-6.52,6.65-.72.77-1.16.7-1.84-.02-2.06-2.17-4.19-4.28-6.29-6.41-.76-.77-1.59-1.68-2.66-.63-1.14,1.12-.19,1.98.62,2.79,2.07,2.09,4.09,4.22,6.2,6.26.77.75.82,1.2.02,1.97-2.21,2.1-4.33,4.3-6.49,6.45-.79.78-1.3,1.65-.32,2.56.92.85,1.71.26,2.43-.47,2.11-2.12,4.28-4.19,6.33-6.38.88-.94,1.37-.86,2.21.03,2.13,2.26,4.37,4.41,6.57,6.6.51.51,1.09.78,1.8.48.56-.24.85-.68.87-1.3Z\"/>\n <path class=\"cls-1\" d=\"m42.47,41.27c-.02.62-.32,1.06-.87,1.3-.71.31-1.29.03-1.8-.48-2.2-2.2-4.44-4.35-6.57-6.6-.84-.89-1.33-.96-2.21-.03-2.04,2.19-4.22,4.25-6.33,6.38-.72.72-1.51,1.32-2.43.47-.98-.91-.47-1.78.32-2.56,2.16-2.15,4.28-4.35,6.49-6.45.81-.77.76-1.22-.02-1.97-2.11-2.04-4.13-4.17-6.2-6.26-.8-.81-1.75-1.67-.62-2.79,1.07-1.05,1.9-.14,2.66.63,2.1,2.13,4.23,4.24,6.29,6.41.69.73,1.12.79,1.84.02,2.13-2.26,4.35-4.43,6.52-6.65.72-.73,1.51-1.31,2.43-.45.97.92.44,1.78-.34,2.56-2.03,2.04-3.97,4.19-6.1,6.12-1.25,1.14-1.08,1.78.06,2.82,2.09,1.91,4.02,3.97,6.02,5.97.43.43.9.85.84,1.55Z\"/>\n</svg>");
;// CONCATENATED MODULE: ./src/icons/maximize.svg
/* harmony default export */ const maximize = ("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" zoomAndPan=\"magnify\" viewBox=\"0 0 768 767.999994\" preserveAspectRatio=\"xMidYMid meet\" version=\"1.0\"><path fill=\"#e4d8c1\" d=\"M 768.132812 379.535156 C 768.132812 169.089844 597.523438 -1.496094 387.050781 -1.496094 C 176.609375 -1.496094 5.996094 169.089844 5.996094 379.535156 C 5.996094 589.949219 176.609375 760.539062 387.050781 760.539062 C 597.523438 760.539062 768.132812 589.949219 768.132812 379.535156 \" fill-opacity=\"1\" fill-rule=\"nonzero\"/><path fill=\"#776d6d\" d=\"M 538.996094 223.152344 L 306.535156 229.855469 L 538.996094 455.695312 Z M 538.996094 223.152344 \" fill-opacity=\"1\" fill-rule=\"nonzero\"/><path fill=\"#776d6d\" d=\"M 235.105469 535.890625 L 467.597656 529.1875 L 235.105469 303.34375 Z M 235.105469 535.890625 \" fill-opacity=\"1\" fill-rule=\"nonzero\"/></svg>");
;// CONCATENATED MODULE: ./src/icons/rectangles.svg
/* harmony default export */ const rectangles = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg id=\"Layer_1\" data-name=\"Layer 1\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 307 640\">\n <defs>\n <style>\n .innermost, .second, .third, .fourth, .fifth, .outermost {\n stroke-width: 0px;\n }\n \n .outermost {\n fill: #e4f2d1;\n }\n\n .second {\n fill: #cce8b5;\n }\n\n .third {\n fill: #b3db95;\n }\n\n .fourth {\n fill: #9bd078;\n }\n\n .fifth {\n fill: #83c55c;\n }\n\n .innermost {\n fill: #428a2f;\n }\n </style>\n </defs>\n <path class=\"outermost\" d=\"m306.9,320c0,105.3-.02,210.6.1,315.91,0,3.42-.67,4.1-4.09,4.09-99.6-.12-199.21-.12-298.81,0C.67,640,0,639.33,0,635.91.11,425.3.11,214.7,0,4.09,0,.67.67,0,4.09,0,103.7.12,203.3.12,302.91,0c3.42,0,4.1.67,4.09,4.09-.12,105.3-.1,210.6-.1,315.91Z\"/>\n <path class=\"second\" d=\"m275.92,323c0,87.63,0,175.27,0,262.9,0,7.24-.55,7.93-7.86,7.98-14.66.09-29.31.03-43.97.03-60.96,0-121.92,0-182.88,0q-7.13,0-7.14-7.24c0-176.1,0-352.21,0-528.31q0-7.26,7.12-7.26c75.78,0,151.56,0,227.35,0q7.38,0,7.38,7.5c0,88.13,0,176.27,0,264.4Z\"/>\n <path class=\"third\" d=\"m68.06,322.24c0-69.47,0-138.94,0-208.41,0-8.99,1.33-10.13,10.49-9.12,1.98.22,3.98.32,5.97.32,46.13.02,92.26.02,138.39,0,3.48,0,6.92-.23,10.41-.67,5.5-.7,8.74.46,8.73,7.25-.18,138.94-.13,277.88-.13,416.81,0,.33,0,.67,0,1q-.14,10.51-10.39,10.51c-52.13,0-104.25,0-156.38,0q-7.09,0-7.09-7.28c0-70.14,0-140.27,0-210.41Z\"/>\n <path class=\"fourth\" d=\"m103.02,322.5c0-52.46,0-104.91,0-157.37,0-6.68.36-7.06,7.07-7.06,30.3-.01,60.6.07,90.9-.09,4.54-.02,6.08,1.33,6.07,5.98-.1,105.58-.1,211.16,0,316.74,0,4.18-1.27,5.37-5.38,5.35-29.3-.15-58.6-.08-87.9-.08q-10.76,0-10.76-11.09c0-50.79,0-101.58,0-152.37Z\"/>\n <path class=\"fifth\" d=\"m173,322.2c0,35.29,0,70.58,0,105.88q0,6.89-6.99,6.9c-8.15,0-16.31-.13-24.46.06-3.47.08-4.68-1.09-4.61-4.59.18-9.65.06-19.31.06-28.96,0-58.26-.01-116.53.02-174.79,0-4.76-1.12-9.46-.14-14.3.51-2.54,1.39-3.38,3.8-3.36,8.82.06,17.64.14,26.46-.02,4.59-.09,5.95,1.85,5.94,6.33-.14,35.62-.08,71.25-.08,106.87Z\"/>\n <path class=\"innermost\" d=\"m151.04,322.01c0-9.99.07-19.97-.05-29.96-.04-2.93.83-4.18,3.95-4.18,3.06,0,4.03,1.12,4.02,4.11-.09,19.97-.08,39.94.01,59.91.01,2.96-.84,4.16-3.96,4.14-3.03-.01-4.08-1.04-4.03-4.08.14-9.98.05-19.97.05-29.96Z\"/>\n</svg>");
;// CONCATENATED MODULE: ./src/icons/waveform.svg
/* harmony default export */ const waveform = ("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.0\" viewBox=\"0 0 56.25 30\" class=\"waveform\">\n <defs>\n <clipPath id=\"a\">\n <path d=\"M.54 12H3v5H.54Zm0 0\"/>\n </clipPath>\n <clipPath id=\"b\">\n <path d=\"M25 2.2h2v24.68h-2Zm0 0\"/>\n </clipPath>\n <clipPath id=\"c\">\n <path d=\"M53 12h1.98v5H53Zm0 0\"/>\n </clipPath>\n </defs>\n <g clip-path=\"url(#a)\">\n <path d=\"M1.48 12.71c-.5 0-.9.4-.9.9v1.85a.9.9 0 0 0 1.8 0v-1.84c0-.5-.4-.9-.9-.9Zm0 0\"/>\n </g>\n <path d=\"M4.98 6.63c-.5 0-.9.4-.9.9v14.01a.9.9 0 0 0 1.81 0v-14c0-.5-.4-.92-.9-.92Zm3.51 3.1a.9.9 0 0 0-.9.91v7.79a.9.9 0 0 0 1.8 0v-7.79c0-.5-.4-.9-.9-.9ZM12 3.83a.9.9 0 0 0-.91.9v19.6a.9.9 0 0 0 1.8 0V4.74c0-.5-.4-.9-.9-.9Zm3.5 8.29a.9.9 0 0 0-.91.9v3.03a.9.9 0 0 0 1.81 0v-3.03c0-.5-.4-.9-.9-.9ZM19 6.8c-.5 0-.9.4-.9.9v13.68a.9.9 0 0 0 1.8 0V7.7c0-.5-.4-.9-.9-.9Zm3.58-2.97h-.01c-.5 0-.9.4-.9.9l-.13 19.6c0 .5.4.9.9.91.5 0 .9-.4.9-.9l.14-19.6a.9.9 0 0 0-.9-.9Zm0 0\"/>\n <g clip-path=\"url(#b)\">\n <path d=\"M26 2.2c-.5 0-.9.4-.9.9v22.86a.9.9 0 1 0 1.81 0V3.11a.9.9 0 0 0-.9-.91Zm0 0\"/>\n </g>\n <path d=\"M29.52 7.71a.9.9 0 0 0-.91.9v11.85a.9.9 0 0 0 1.81 0V8.62c0-.5-.4-.9-.9-.9Zm3.5 2.93a.9.9 0 0 0-.9.91v5.97a.9.9 0 0 0 1.8 0v-5.97c0-.5-.4-.9-.9-.9Zm3.5-5.78c-.5 0-.9.4-.9.9v17.55a.9.9 0 0 0 1.81 0V5.76c0-.5-.4-.9-.9-.9Zm3.51 3.34c-.5 0-.9.4-.9.9v10.87a.9.9 0 0 0 1.8 0V9.1a.9.9 0 0 0-.9-.91Zm3.5 3.08c-.5 0-.9.4-.9.91v4.7a.9.9 0 1 0 1.8 0v-4.7a.9.9 0 0 0-.9-.9Zm3.51-7.45a.9.9 0 0 0-.91.9v19.6a.9.9 0 0 0 1.81 0V4.74c0-.5-.4-.9-.9-.9Zm3.5 5.57a.9.9 0 0 0-.9.91v8.45a.9.9 0 0 0 1.8 0v-8.45c0-.5-.4-.9-.9-.9Zm0 0\"/>\n <g clip-path=\"url(#c)\">\n <path d=\"M54.04 12.96a.9.9 0 0 0-.9.91v1.33a.9.9 0 1 0 1.8 0v-1.32a.9.9 0 0 0-.9-.92Zm0 0\"/>\n </g>\n</svg>");
;// CONCATENATED MODULE: ./src/icons/muted_microphone.svg
/* harmony default export */ const muted_microphone = ("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"500\" zoomAndPan=\"magnify\" viewBox=\"0 0 375 374.999991\" height=\"500\" preserveAspectRatio=\"xMidYMid meet\" version=\"1.0\"><path fill=\"#776d6d\" d=\"M 239.722656 126.441406 L 239.722656 122.300781 C 239.722656 93.507812 216.296875 70.078125 187.5 70.078125 C 158.703125 70.078125 135.277344 93.507812 135.277344 122.300781 L 135.277344 187.953125 C 135.277344 199.988281 139.410156 211.050781 146.273438 219.890625 Z M 239.722656 126.441406 \" fill-opacity=\"1\" fill-rule=\"nonzero\"/><path fill=\"#776d6d\" d=\"M 155.046875 228.792969 C 163.964844 235.898438 175.234375 240.175781 187.5 240.175781 C 216.296875 240.175781 239.722656 216.75 239.722656 187.953125 L 239.722656 144.113281 Z M 155.046875 228.792969 \" fill-opacity=\"1\" fill-rule=\"nonzero\"/><path fill=\"#776d6d\" d=\"M 187.5 0 C 83.945312 0 0 83.945312 0 187.5 C 0 291.054688 83.945312 375 187.5 375 C 291.054688 375 375 291.054688 375 187.5 C 375 83.945312 291.054688 0 187.5 0 Z M 287.484375 96.355469 L 254.640625 129.195312 L 254.640625 187.953125 C 254.640625 224.976562 224.523438 255.097656 187.5 255.097656 C 171.117188 255.097656 156.105469 249.183594 144.4375 239.402344 L 138.109375 245.730469 C 151.417969 257.121094 168.652344 264.046875 187.5 264.046875 C 229.457031 264.046875 263.59375 229.914062 263.59375 187.953125 C 263.59375 183.832031 266.933594 180.496094 271.054688 180.496094 C 275.175781 180.496094 278.515625 183.835938 278.515625 187.953125 C 278.515625 235.625 241.667969 274.828125 194.960938 278.640625 L 194.960938 304.921875 L 220.121094 304.921875 C 224.242188 304.921875 227.582031 308.261719 227.582031 312.382812 C 227.582031 316.5 224.242188 319.839844 220.121094 319.839844 L 154.875 319.839844 C 150.757812 319.839844 147.417969 316.5 147.417969 312.382812 C 147.417969 308.261719 150.757812 304.921875 154.875 304.921875 L 180.039062 304.921875 L 180.039062 278.636719 C 160.007812 277.003906 141.816406 268.824219 127.542969 256.296875 L 96.351562 287.484375 C 95.132812 288.703125 93.53125 289.316406 91.933594 289.316406 C 90.335938 289.316406 88.734375 288.703125 87.515625 287.484375 C 85.074219 285.042969 85.074219 281.085938 87.515625 278.644531 L 118.761719 247.398438 C 104.929688 231.4375 96.484375 210.6875 96.484375 187.953125 C 96.484375 183.832031 99.824219 180.496094 103.941406 180.496094 C 108.0625 180.496094 111.402344 183.835938 111.402344 187.953125 C 111.402344 206.574219 118.148438 223.628906 129.292969 236.867188 L 135.628906 230.53125 C 126.089844 218.9375 120.355469 204.105469 120.355469 187.953125 L 120.355469 122.300781 C 120.355469 85.28125 150.476562 55.160156 187.496094 55.160156 C 221.128906 55.160156 248.980469 80.039062 253.816406 112.34375 L 278.640625 87.515625 C 281.082031 85.078125 285.039062 85.078125 287.480469 87.515625 C 289.925781 89.957031 289.925781 93.914062 287.484375 96.355469 Z M 287.484375 96.355469 \" fill-opacity=\"1\" fill-rule=\"nonzero\"/></svg>");
;// CONCATENATED MODULE: ./src/icons/call.svg
/* harmony default export */ const call = ("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n zoomAndPan=\"magnify\" viewBox=\"0 0 768 767.999994\"\n preserveAspectRatio=\"xMidYMid meet\" version=\"1.0\">\n <path class=\"circle\" fill=\"#418a2f\"\n d=\"M 767.988281 383.984375 C 767.988281 596.058594 596.066406 767.980469 383.996094 767.980469 C 171.921875 767.980469 0 596.058594 0 383.984375 C 0 171.910156 171.921875 -0.0078125 383.996094 -0.0078125 C 596.066406 -0.0078125 767.988281 171.910156 767.988281 383.984375 \"\n fill-opacity=\"1\" fill-rule=\"nonzero\" />\n <path class=\"phone-receiver\" fill=\"#ffffff\"\n d=\"M 215.726562 199.773438 C 219.746094 194.835938 230.023438 183.625 243.644531 183.769531 C 244.40625 183.777344 245.300781 183.808594 246.34375 183.914062 C 246.34375 183.914062 248.492188 184.144531 250.613281 184.703125 C 268.292969 189.410156 299.921875 224.304688 299.921875 224.304688 C 326.925781 254.09375 334.722656 255.53125 334.636719 266.5 C 334.550781 276.777344 328.140625 284.71875 316.253906 296.566406 C 284.566406 328.148438 277.808594 330.53125 275.351562 340.421875 C 273.902344 346.234375 269.539062 357.511719 289.105469 379.355469 C 318.289062 411.929688 388.1875 478.4375 394.300781 482.515625 C 400.402344 486.585938 422.121094 500.832031 451.300781 474.371094 C 471.226562 456.304688 480.714844 435.066406 494.875 433.785156 C 502.363281 433.089844 507.878906 437.613281 519.167969 447.222656 C 585.886719 503.976562 586.871094 513.933594 586.3125 519.824219 C 585.355469 530.011719 580.75 539.210938 565.316406 550.382812 C 525.953125 578.878906 508.3125 603.992188 428.234375 570.742188 C 348.152344 537.484375 263.996094 453.335938 240.242188 417.359375 C 216.488281 381.390625 179.160156 326.421875 181.878906 288.414062 C 183.769531 261.980469 191.867188 238.863281 191.867188 238.863281 C 199.097656 220.882812 208.71875 207.878906 215.726562 199.773438 \"\n fill-opacity=\"1\" fill-rule=\"nonzero\" />\n</svg>");
;// CONCATENATED MODULE: ./src/icons/hangup.svg
/* harmony default export */ const hangup = ("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n zoomAndPan=\"magnify\" viewBox=\"0 0 768 767.999994\"\n preserveAspectRatio=\"xMidYMid meet\" version=\"1.0\">\n <path fill=\"#776d6d\"\n d=\"M 768 384 C 768 596.074219 596.074219 768 384 768 C 171.925781 768 0 596.074219 0 384 C 0 171.925781 171.925781 0 384 0 C 596.074219 0 768 171.925781 768 384 \"\n fill-opacity=\"1\" fill-rule=\"nonzero\" />\n <path fill=\"#ffffff\"\n d=\"M 153.695312 418.96875 C 153.71875 418.972656 167.773438 455.105469 183.636719 464.507812 C 193.925781 470.585938 202.523438 467.320312 213.625 462.085938 C 235.234375 451.890625 257.347656 442.476562 280.480469 435.953125 C 286.855469 434.152344 290.832031 427.890625 289.265625 421.722656 C 286.402344 410.6875 283.480469 399.660156 280.507812 388.644531 C 278.808594 382.511719 283.523438 375.988281 291.148438 374.363281 C 320.28125 368.128906 350.152344 364.921875 380.039062 364.769531 C 381.359375 364.769531 386.640625 364.769531 387.960938 364.769531 C 417.847656 364.921875 447.714844 368.128906 476.851562 374.363281 C 484.476562 375.988281 489.191406 382.511719 487.492188 388.644531 C 484.519531 399.660156 481.597656 410.6875 478.734375 421.722656 C 477.167969 427.890625 481.144531 434.152344 487.519531 435.953125 C 510.652344 442.476562 532.765625 451.890625 554.375 462.085938 C 565.476562 467.320312 574.074219 470.585938 584.363281 464.507812 C 600.226562 455.105469 614.28125 418.972656 614.304688 418.96875 C 627.664062 390.730469 619.042969 359.117188 582.167969 342.550781 C 519.960938 314.839844 457.320312 300.640625 388.140625 300.203125 C 386.765625 300.203125 381.238281 300.203125 379.855469 300.203125 C 310.679688 300.640625 248.039062 314.839844 185.832031 342.550781 C 148.949219 359.117188 140.335938 390.730469 153.695312 418.96875 \"\n fill-opacity=\"1\" fill-rule=\"nonzero\" />\n</svg>");
;// CONCATENATED MODULE: ./src/ButtonModule.js
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var ButtonModule = /*#__PURE__*/function () {
function ButtonModule() {
_classCallCheck(this, ButtonModule);
this.actor = StateMachineService["default"].actor;
// Binding methods to the current instance
this.registerOtherEvents();
// track the frequency of bug #26
this.submissionsWithoutAnError = 0;
}
_createClass(ButtonModule, [{
key: "registerOtherEvents",
value: function registerOtherEvents() {
var _this = this;
EventBus["default"].on("saypi:autoSubmit", function () {
_this.handleAutoSubmit();
});
}
// Function to create a new button
}, {
key: "createButton",
value: function createButton(label, callback) {
var button = document.createElement("button");
if (label) {
button.textContent = label;
}
if (callback) {
button.onclick = callback;
}
return button;
}
// Function to style a given button
}, {
key: "styleButton",
value: function styleButton(button, styles) {
for (var key in styles) {
if (styles.hasOwnProperty(key)) {
button.style[key] = styles[key];
}
}
}
}, {
key: "addTalkIcon",
value: function addTalkIcon(button) {
var _this2 = this;
this.updateIconContent(button);
window.matchMedia("(max-width: 768px)").addListener(function () {
_this2.updateIconContent(button);
});
this.setupClassObserver(button);
}
}, {
key: "updateIconContent",
value: function updateIconContent(iconContainer) {
if ((0,UserAgentModule.isMobileView)()) {
iconContainer.innerHTML = rectangles;
} else {
iconContainer.innerHTML = waveform;
}
}
}, {
key: "setupClassObserver",
value: function setupClassObserver(button) {
var _this3 = this;
var targetNode = document.documentElement; // The <html> element
var config = {
attributes: true,
attributeFilter: ["class"]
};
var callback = function callback(mutationsList, observer) {
var _iterator = _createForOfIteratorHelper(mutationsList),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var mutation = _step.value;
if (mutation.type === "attributes") {
if (mutation.attributeName === "class") {
if (document.documentElement.classList.contains("mobile-view")) {
// 'mobile-view' class was added
_this3.updateIconContent(button);
} else {
// 'mobile-view' class was removed
_this3.updateIconContent(button);
}
}
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
};
var observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
// Later, you can stop observing by calling:
// observer.disconnect();
}
// Simulate an "Enter" keypress event on a form
}, {
key: "simulateFormSubmit",
value: function simulateFormSubmit() {
var submitButton = document.getElementById("saypi-submitButton");
if (submitButton) {
if (SubmitErrorHandler/* submitErrorHandler */.AP.detectSubmitError()) {
// track how often this happens
console.error("Autosubmit failed after ".concat(this.submissionsWithoutAnError, " turns."));
this.submissionsWithoutAnError = 0;
SubmitErrorHandler/* submitErrorHandler */.AP.handleSubmitError();
} else {
this.submissionsWithoutAnError++;
submitButton.click();
}
} else {
/* hit enter key in the prompt textarea, might not work as expected on "new ui layout" */
var textarea = document.getElementById("saypi-prompt");
var enterEvent = new KeyboardEvent("keydown", {
bubbles: true,
key: "Enter",
keyCode: 13,
which: 13
});
textarea.dispatchEvent(enterEvent);
}
}
// Function to handle auto-submit based on the button's data attribute
}, {
key: "handleAutoSubmit",
value: function handleAutoSubmit() {
var talkButton = document.getElementById("saypi-talkButton");
if (talkButton.dataset.autosubmit === "false") {
console.log("Autosubmit is off");
} else {
this.simulateFormSubmit();
}
}
}, {
key: "createExitButton",
value: function createExitButton() {
var label = "Exit Voice-Controlled Mobile Mode";
var button = this.createButton("", function () {
(0,UserAgentModule.exitMobileMode)();
});
button.id = "saypi-exitButton";
button.type = "button";
button.className = "exit-button fixed rounded-full bg-cream-550 enabled:hover:bg-cream-650";
button.setAttribute("aria-label", label);
button.setAttribute("title", label);
button.innerHTML = exit;
document.body.appendChild(button);
return button;
}
}, {
key: "createEnterButton",
value: function createEnterButton() {
var label = "Enter Voice-Controlled Mobile Mode";
var button = this.createButton("", function () {
(0,UserAgentModule.enterMobileMode)();
});
button.id = "saypi-enterButton";
button.type = "button";
button.className = "enter-button fixed rounded-full bg-cream-550 enabled:hover:bg-cream-650";
button.setAttribute("aria-label", label);
button.setAttribute("title", label);
button.innerHTML = maximize;
document.body.appendChild(button);
return button;
}
}, {
key: "showNotification",
value: function showNotification(details) {
var icon = details.icon;
var iconSVG;
if (icon === "muted-microphone") {
iconSVG = muted_microphone;
}
var notification = document.getElementById("saypi-notification");
if (notification) {
notification.classList.remove("hidden");
notification.innerHTML = iconSVG;
} else {
var _notification = document.createElement("div");
_notification.id = "saypi-notification";
_notification.className = "notification";
_notification.innerHTML = iconSVG;
document.body.appendChild(_notification);
}
}
}, {
key: "dismissNotification",
value: function dismissNotification() {
var notification = document.getElementById("saypi-notification");
if (notification) {
notification.classList.add("hidden");
}
}
}, {
key: "createCallButton",
value: function createCallButton(container) {
var position = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var button = this.createButton();
button.id = "saypi-callButton";
button.type = "button";
button.className = "call-button fixed rounded-full bg-cream-550 enabled:hover:bg-cream-650";
this.callInactive(button); // mic is off by default
(0,DOMModule/* appendChild */.j)(container, button, position);
return button;
}
}, {
key: "callActive",
value: function callActive(callButton) {
var _this4 = this;
if (!callButton) {
callButton = document.getElementById("saypi-callButton");
}
if (callButton) {
var label = "Active continuous listening. Click to stop.";
callButton.innerHTML = hangup;
callButton.setAttribute("aria-label", label);
callButton.setAttribute("title", label);
callButton.onclick = function () {
_this4.actor.send("saypi:hangup");
};
callButton.classList.add("active");
}
}
}, {
key: "callInactive",
value: function callInactive(callButton) {
var _this5 = this;
if (!callButton) {
callButton = document.getElementById("saypi-callButton");
}
if (callButton) {
callButton.innerHTML = call;
callButton.setAttribute("aria-label", "Click to start continuous listening.");
callButton.setAttribute("title", "Not listening. Click to start.");
callButton.onclick = function () {
_this5.actor.send("saypi:call");
};
callButton.classList.remove("active");
}
}
}, {
key: "disableCallButton",
value: function disableCallButton() {
var callButton = document.getElementById("saypi-callButton");
if (callButton) {
callButton.classList.add("disabled");
// disable the call action, but always allow hangup
if (!callButton.classList.contains("active")) {
callButton.disabled = true;
}
}
}
}, {
key: "enableCallButton",
value: function enableCallButton() {
var callButton = document.getElementById("saypi-callButton");
if (callButton) {
callButton.classList.remove("disabled");
callButton.disabled = false;
}
}
}]);
return ButtonModule;
}(); // Singleton
var buttonModule = new ButtonModule();
/***/ }),
/***/ 8186:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ config: () => (/* binding */ config)
/* harmony export */ });
var config = {
appServerUrl: "https://app.saypi.ai",
apiServerUrl: "https://api.saypi.ai"
};
/***/ }),
/***/ 7635:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7187);
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (new events__WEBPACK_IMPORTED_MODULE_0__());
/***/ }),
/***/ 9940:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ EventModule)
/* harmony export */ });
/* harmony import */ var _EventBus_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7635);
/* harmony import */ var _StateMachineService_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8615);
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var USER_SPEAKING = "saypi:userSpeaking";
var USER_STOPPED_SPEAKING = "saypi:userStoppedSpeaking";
var USER_FINISHED_SPEAKING = "saypi:userFinishedSpeaking";
var PI_SPEAKING = "saypi:piSpeaking";
var PI_STOPPED_SPEAKING = "saypi:piStoppedSpeaking";
var PI_FINISHED_SPEAKING = "saypi:piFinishedSpeaking";
var EventModule = /*#__PURE__*/function () {
function EventModule() {
_classCallCheck(this, EventModule);
}
_createClass(EventModule, null, [{
key: "init",
value: function init() {
// All the event listeners can be added here
this.registerStateMachineEvents(_StateMachineService_js__WEBPACK_IMPORTED_MODULE_1__["default"].actor);
// Any other initializations...
}
}, {
key: "cleanup",
value: function cleanup() {
// Remove event listeners if needed, or any other cleanup operations
window.removeEventListener("saypi:transcribed", this.handleTranscriptionResponse);
}
}, {
key: "simulateTyping",
value: function simulateTyping(element, text) {
element.focus();
// Define a regular expression to match sentence terminators, capturing them
var sentenceRegex = /([.!?。?!]+)/g;
var tokens = text.split(sentenceRegex).filter(Boolean);
// Reassemble sentences with their terminators
var sentences = [];
for (var _i = 0; _i < tokens.length; _i += 2) {
var sentence = tokens[_i] + (tokens[_i + 1] || "");
sentences.push(sentence);
}
var i = 0;
var typeSentence = function typeSentence() {
if (i < sentences.length) {
// Type the sentence and its immediate following terminator
EventModule.setNativeValue(element, element.value + sentences[i++]);
requestAnimationFrame(typeSentence);
} else {
_EventBus_js__WEBPACK_IMPORTED_MODULE_0__["default"].emit("saypi:autoSubmit");
}
};
if (sentences.length > 1) {
// If there are multiple sentences, proceed with sentence-wise typing
typeSentence();
} else {
// If text does not contain recognisable sentence terminators, type it all at once
EventModule.setNativeValue(element, text);
_EventBus_js__WEBPACK_IMPORTED_MODULE_0__["default"].emit("saypi:autoSubmit");
}
}
}, {
key: "setNativeValue",
value: function setNativeValue(element, value) {
var lastValue = element.value;
element.value = value;
var event = new Event("input", {
target: element,
bubbles: true
});
// React 15
event.simulated = true;
// React 16-17
var tracker = element._valueTracker;
if (tracker) {
tracker.setValue(lastValue);
}
element.dispatchEvent(event);
}
}, {
key: "registerStateMachineEvents",
value: function registerStateMachineEvents(actor) {
_EventBus_js__WEBPACK_IMPORTED_MODULE_0__["default"].on(USER_SPEAKING, function () {
actor.send(USER_SPEAKING);
});
[USER_STOPPED_SPEAKING, USER_FINISHED_SPEAKING].forEach(function (eventName) {
_EventBus_js__WEBPACK_IMPORTED_MODULE_0__["default"].on(eventName, function (detail) {
if (detail) {
actor.send(_objectSpread({
type: eventName
}, detail));
} else {
console.warn("Received ".concat(eventName, " without details."));
}
});
});
[PI_SPEAKING, PI_STOPPED_SPEAKING, PI_FINISHED_SPEAKING].forEach(function (eventName) {
_EventBus_js__WEBPACK_IMPORTED_MODULE_0__["default"].on(eventName, function () {
actor.send(eventName);
});
});
}
}]);
return EventModule;
}();
/***/ }),
/***/ 484:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ logger: () => (/* binding */ logger),
/* harmony export */ serializeStateValue: () => (/* binding */ serializeStateValue)
/* harmony export */ });
function serializeStateValue(stateValue) {
if (typeof stateValue === "string") {
return stateValue;
}
return Object.keys(stateValue).map(function (key) {
return "".concat(key, ":").concat(serializeStateValue(stateValue[key]));
}).join(",");
}
var DEBUG = false; // Consider using config and .env to set the DEBUG flag
var logger = {
debug: function debug() {
if (DEBUG) {
var _console;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
(_console = console).log.apply(_console, ["DEBUG:"].concat(args));
}
},
info: function info() {
var _console2;
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
(_console2 = console).log.apply(_console2, ["INFO:"].concat(args));
},
error: function error() {
var _console3;
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
(_console3 = console).error.apply(_console3, ["ERROR:"].concat(args));
}
};
/***/ }),
/***/ 8615:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var xstate__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9805);
/* harmony import */ var _state_machines_SayPiMachine_ts__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6906);
/* harmony import */ var _LoggingModule_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(484);
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* A singleton service that manages the state machine.
*/
var StateMachineService = /*#__PURE__*/_createClass(function StateMachineService() {
_classCallCheck(this, StateMachineService);
this.actor = (0,xstate__WEBPACK_IMPORTED_MODULE_2__/* .interpret */ .kJ)(_state_machines_SayPiMachine_ts__WEBPACK_IMPORTED_MODULE_0__.machine).onTransition(function (state) {
if (state.changed) {
var fromState = state.history ? (0,_LoggingModule_js__WEBPACK_IMPORTED_MODULE_1__.serializeStateValue)(state.history.value) : "N/A";
var toState = (0,_LoggingModule_js__WEBPACK_IMPORTED_MODULE_1__.serializeStateValue)(state.value);
_LoggingModule_js__WEBPACK_IMPORTED_MODULE_1__.logger.debug("Say, Pi Machine transitioned from ".concat(fromState, " to ").concat(toState, " with ").concat(state.event.type));
}
});
this.actor.start();
}); // Singleton
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (new StateMachineService());
/***/ }),
/***/ 4008:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ addDeviceFlags: () => (/* binding */ addDeviceFlags),
/* harmony export */ addUserAgentFlags: () => (/* binding */ addUserAgentFlags),
/* harmony export */ addViewFlags: () => (/* binding */ addViewFlags),
/* harmony export */ enterMobileMode: () => (/* binding */ enterMobileMode),
/* harmony export */ exitMobileMode: () => (/* binding */ exitMobileMode),
/* harmony export */ initMode: () => (/* binding */ initMode),
/* harmony export */ isMobileDevice: () => (/* binding */ isMobileDevice),
/* harmony export */ isMobileView: () => (/* binding */ isMobileView)
/* harmony export */ });
/* harmony import */ var _DOMModule_ts__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8158);
function isMobileDevice() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.matchMedia("(max-width: 768px)").matches;
}
// this function determines whether to show the mobile view or not
function isMobileView() {
var userViewPreference = null;
try {
userViewPreference = localStorage.getItem("userViewPreference");
} catch (e) {
console.warn("Could not access localStorage: ", e);
}
var prefersMobile = false;
if (userViewPreference) {
prefersMobile = userViewPreference === "mobile";
}
// Make sure isMobileDevice is defined or imported
return isMobileDevice() && prefersMobile;
}
function exitMobileMode() {
localStorage.setItem("userViewPreference", "desktop"); // Save preference
var element = document.documentElement;
element.classList.remove("mobile-view");
element.classList.add("desktop-view");
attachCallButton();
}
function enterMobileMode() {
localStorage.setItem("userViewPreference", "mobile"); // Save preference
var element = document.documentElement;
element.classList.remove("desktop-view");
element.classList.add("mobile-view");
detachCallButton();
}
function attachCallButton() {
// move the call button back into the text prompt container for desktop view
var container = document.getElementById("saypi-prompt-controls-container");
var callButton = document.getElementById("saypi-callButton");
if (container && callButton) {
(0,_DOMModule_ts__WEBPACK_IMPORTED_MODULE_0__/* .appendChild */ .j)(container, callButton, -1);
}
}
function detachCallButton() {
// remove the call button from the text prompt container while in mobile view
var callButton = document.getElementById("saypi-callButton");
if (callButton) {
(0,_DOMModule_ts__WEBPACK_IMPORTED_MODULE_0__/* .appendChild */ .j)(document.body, callButton);
}
}
function addUserAgentFlags() {
var isFirefoxAndroid = /Firefox/.test(navigator.userAgent) && /Android/.test(navigator.userAgent);
var element = document.documentElement;
if (isFirefoxAndroid) {
element.classList.add("firefox-android");
}
addDeviceFlags(element);
addViewFlags(element);
}
function addDeviceFlags(element) {
if (isMobileDevice()) {
element.classList.add("mobile-device");
}
}
function addViewFlags(element) {
if (isMobileView()) {
element.classList.remove("desktop-view");
element.classList.add("mobile-view");
} else {
element.classList.remove("mobile-view");
element.classList.add("desktop-view");
}
}
/**
* Perform initial setup of the UI based on the user's device and view preferences
*/
function initMode() {
if (isMobileView()) {
enterMobileMode();
} else {
exitMobileMode();
}
}
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ id: moduleId,
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/global */
/******/ (() => {
/******/ __webpack_require__.g = (function() {
/******/ if (typeof globalThis === 'object') return globalThis;
/******/ try {
/******/ return this || new Function('return this')();
/******/ } catch (e) {
/******/ if (typeof window === 'object') return window;
/******/ }
/******/ })();
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/nonce */
/******/ (() => {
/******/ __webpack_require__.nc = undefined;
/******/ })();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
// EXTERNAL MODULE: ./src/ButtonModule.js + 7 modules
var ButtonModule = __webpack_require__(6601);
// EXTERNAL MODULE: ./src/EventBus.js
var EventBus = __webpack_require__(7635);
// EXTERNAL MODULE: ./src/EventModule.js
var EventModule = __webpack_require__(9940);
// EXTERNAL MODULE: ./src/UserAgentModule.js
var UserAgentModule = __webpack_require__(4008);
// EXTERNAL MODULE: ./src/SubmitErrorHandler.ts
var SubmitErrorHandler = __webpack_require__(9947);
// EXTERNAL MODULE: ./src/ConfigModule.js
var ConfigModule = __webpack_require__(8186);
// EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js
var injectStylesIntoStyleTag = __webpack_require__(3379);
var injectStylesIntoStyleTag_default = /*#__PURE__*/__webpack_require__.n(injectStylesIntoStyleTag);
// EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/styleDomAPI.js
var styleDomAPI = __webpack_require__(7795);
var styleDomAPI_default = /*#__PURE__*/__webpack_require__.n(styleDomAPI);
// EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/insertBySelector.js
var insertBySelector = __webpack_require__(569);
var insertBySelector_default = /*#__PURE__*/__webpack_require__.n(insertBySelector);
// EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/setAttributesWithoutAttributes.js
var setAttributesWithoutAttributes = __webpack_require__(3565);
var setAttributesWithoutAttributes_default = /*#__PURE__*/__webpack_require__.n(setAttributesWithoutAttributes);
// EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/insertStyleElement.js
var insertStyleElement = __webpack_require__(9216);
var insertStyleElement_default = /*#__PURE__*/__webpack_require__.n(insertStyleElement);
// EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/styleTagTransform.js
var styleTagTransform = __webpack_require__(4589);
var styleTagTransform_default = /*#__PURE__*/__webpack_require__.n(styleTagTransform);
// EXTERNAL MODULE: ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[3].use[1]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[3].use[2]!./src/styles/common.scss
var common = __webpack_require__(8580);
;// CONCATENATED MODULE: ./src/styles/common.scss
var options = {};
options.styleTagTransform = (styleTagTransform_default());
options.setAttributes = (setAttributesWithoutAttributes_default());
options.insert = insertBySelector_default().bind(null, "head");
options.domAPI = (styleDomAPI_default());
options.insertStyleElement = (insertStyleElement_default());
var update = injectStylesIntoStyleTag_default()(common/* default */.Z, options);
/* harmony default export */ const styles_common = (common/* default */.Z && common/* default */.Z.locals ? common/* default */.Z.locals : undefined);
// EXTERNAL MODULE: ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[3].use[1]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[3].use[2]!./src/styles/desktop.scss
var desktop = __webpack_require__(1902);
;// CONCATENATED MODULE: ./src/styles/desktop.scss
var desktop_options = {};
desktop_options.styleTagTransform = (styleTagTransform_default());
desktop_options.setAttributes = (setAttributesWithoutAttributes_default());
desktop_options.insert = insertBySelector_default().bind(null, "head");
desktop_options.domAPI = (styleDomAPI_default());
desktop_options.insertStyleElement = (insertStyleElement_default());
var desktop_update = injectStylesIntoStyleTag_default()(desktop/* default */.Z, desktop_options);
/* harmony default export */ const styles_desktop = (desktop/* default */.Z && desktop/* default */.Z.locals ? desktop/* default */.Z.locals : undefined);
// EXTERNAL MODULE: ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[3].use[1]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[3].use[2]!./src/styles/mobile.scss
var mobile = __webpack_require__(149);
;// CONCATENATED MODULE: ./src/styles/mobile.scss
var mobile_options = {};
mobile_options.styleTagTransform = (styleTagTransform_default());
mobile_options.setAttributes = (setAttributesWithoutAttributes_default());
mobile_options.insert = insertBySelector_default().bind(null, "head");
mobile_options.domAPI = (styleDomAPI_default());
mobile_options.insertStyleElement = (insertStyleElement_default());
var mobile_update = injectStylesIntoStyleTag_default()(mobile/* default */.Z, mobile_options);
/* harmony default export */ const styles_mobile = (mobile/* default */.Z && mobile/* default */.Z.locals ? mobile/* default */.Z.locals : undefined);
// EXTERNAL MODULE: ./node_modules/css-loader/dist/cjs.js!./src/styles/rectangles.css
var rectangles = __webpack_require__(9136);
;// CONCATENATED MODULE: ./src/styles/rectangles.css
var rectangles_options = {};
rectangles_options.styleTagTransform = (styleTagTransform_default());
rectangles_options.setAttributes = (setAttributesWithoutAttributes_default());
rectangles_options.insert = insertBySelector_default().bind(null, "head");
rectangles_options.domAPI = (styleDomAPI_default());
rectangles_options.insertStyleElement = (insertStyleElement_default());
var rectangles_update = injectStylesIntoStyleTag_default()(rectangles/* default */.Z, rectangles_options);
/* harmony default export */ const styles_rectangles = (rectangles/* default */.Z && rectangles/* default */.Z.locals ? rectangles/* default */.Z.locals : undefined);
;// CONCATENATED MODULE: ./src/saypi.index.js
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return { value: void 0, done: !0 }; } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable || "" === iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } throw new TypeError(_typeof(iterable) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
"use strict";
var audioModuleUrl, pageScript, response, injectScript, callback, config, observer, setupEventBus, annotateDOM, addIdPromptAncestor, addIdSubmitButton, addIdFooter, addIdAudioControls, addIdAudioOutputButton, addTalkButton;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
addTalkButton = function _addTalkButton(container) {
// Create a containing div
var panel = document.createElement("div");
panel.id = "saypi-panel";
if (container) {
container.appendChild(panel);
} else {
document.body.appendChild(panel);
}
// talk "button" is no longer a button, but a div
var button = document.createElement("div");
button.id = "saypi-talkButton";
var classNames = "relative flex mt-1 mb-1 rounded-full px-2 py-3 text-center bg-cream-550 hover:bg-cream-650 hover:text-brand-green-700 text-muted";
button.classList.add(classNames.split(" "));
// Enable autosubmit by default
button.dataset.autosubmit = "true";
button.classList.add("autoSubmit");
panel.appendChild(button);
ButtonModule.buttonModule.addTalkIcon(button);
// Call the function to inject the script after the button has been added
injectScript();
};
addIdAudioOutputButton = function _addIdAudioOutputButt() {
// audio button is the last button element in the audio controls container
var audioButton = document.querySelector("#saypi-audio-controls > div > div.relative.flex.items-center.justify-end.self-end.p-2 > button");
if (!audioButton) {
return false;
} else {
audioButton.id = "saypi-audio-output-button";
}
return true;
};
addIdAudioControls = function _addIdAudioControls() {
// Find all audio elements on the page
var audioElements = document.querySelectorAll("audio");
var found = false; // default to not found
audioElements.forEach(function (audio) {
var nextDiv = audio.nextElementSibling;
// If we've already found a div, we can skip further iterations
if (found) return;
// Check if the preceding element is a div
if (nextDiv && nextDiv.tagName.toLowerCase() === "div") {
// Assign an ID to the div
nextDiv.id = "saypi-audio-controls";
found = true; // set to found
}
});
return found;
};
addIdFooter = function _addIdFooter() {
// Find all audio elements on the page
var audioElements = document.querySelectorAll("audio");
var found = false; // default to not found
audioElements.forEach(function (audio) {
var precedingDiv = audio.previousElementSibling;
// If we've already found a div, we can skip further iterations
if (found) return;
// Check if the preceding element is a div
if (precedingDiv && precedingDiv.tagName.toLowerCase() === "div") {
// Assign an ID to the div
precedingDiv.lastElementChild.id = "saypi-footer";
found = true; // set to found
}
});
return found;
};
addIdSubmitButton = function _addIdSubmitButton(container) {
var submitButtons = container.querySelectorAll("button[type=button]");
if (submitButtons.length > 0) {
var lastSubmitButton = submitButtons[submitButtons.length - 1];
lastSubmitButton.id = "saypi-submitButton";
}
};
addIdPromptAncestor = function _addIdPromptAncestor(container) {
// climb up the DOM tree until we find a div with class 'w-full'
var parent = container.parentElement;
while (parent) {
if (parent.classList.contains("w-full")) {
parent.id = "saypi-prompt-ancestor";
return true;
}
parent = parent.parentElement;
}
return false;
};
annotateDOM = function _annotateDOM(prompt) {
// Add id attributes to important elements
prompt.id = "saypi-prompt";
prompt.parentElement.classList.add("saypi-prompt-container");
var foundFooter = addIdFooter();
var foundAudioControls = addIdAudioControls();
var promptControlsContainer = prompt.parentElement.parentElement;
promptControlsContainer.id = "saypi-prompt-controls-container";
var foundPromptAncestor = addIdPromptAncestor(promptControlsContainer);
var foundAudioOutputButton = addIdAudioOutputButton();
addIdSubmitButton(promptControlsContainer);
addTalkButton(document.body);
ButtonModule.buttonModule.createCallButton(promptControlsContainer, -1);
ButtonModule.buttonModule.createEnterButton();
ButtonModule.buttonModule.createExitButton();
(0,UserAgentModule.initMode)();
};
setupEventBus = function _setupEventBus() {
// Setting the correct context
var context = window;
if (GM_info.scriptHandler !== "Userscripts") {
context = unsafeWindow;
}
context.EventBus = EventBus["default"]; // Make the EventBus available to the page script
};
injectScript = function _injectScript(callback) {
var scriptElement = document.createElement("script");
scriptElement.type = "text/javascript";
scriptElement.id = "saypi-script";
scriptElement.textContent = pageScript;
document.body.appendChild(scriptElement);
// Call the callback function after the script is added
if (callback) {
callback();
}
};
audioModuleUrl = "".concat(ConfigModule.config.appServerUrl, "/audioModule.bundle.js");
_context.prev = 10;
_context.next = 13;
return fetch(audioModuleUrl);
case 13:
response = _context.sent;
if (response.ok) {
_context.next = 16;
break;
}
throw new Error("Network response was not ok " + response.statusText);
case 16:
_context.next = 18;
return response.text();
case 18:
pageScript = _context.sent;
_context.next = 25;
break;
case 21:
_context.prev = 21;
_context.t0 = _context["catch"](10);
console.error("There has been a problem with your fetch operation:", _context.t0);
return _context.abrupt("return");
case 25:
(0,UserAgentModule.addUserAgentFlags)();
EventModule["default"].init();
setupEventBus();
// Create a MutationObserver to listen for changes to the DOM
// textareas are added to the DOM after the page loads
callback = function callback(mutationsList, observer) {
var _iterator = _createForOfIteratorHelper(mutationsList),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var mutation = _step.value;
if (mutation.type === "childList") {
// Iterate through added nodes
mutation.addedNodes.forEach(function (node) {
// Check if added node is a textarea with 'enterkeyhint' attribute
if (node.nodeName === "TEXTAREA" && node.hasAttribute("enterkeyhint")) {
// Stop observing to avoid any potential infinite loops
observer.disconnect();
// Do something with the textarea, like add an event listener
annotateDOM(node);
return;
}
// Check if added node contains a textarea with 'enterkeyhint' attribute
if (node.querySelectorAll) {
var textareas = node.querySelectorAll("textarea[enterkeyhint]");
if (textareas.length > 0) {
// Stop observing
observer.disconnect();
// Do something with the first textarea that has 'enterkeyhint'
annotateDOM(textareas[0]);
SubmitErrorHandler/* submitErrorHandler */.AP.initAudioOutputListener();
SubmitErrorHandler/* submitErrorHandler */.AP.checkForRestorePoint();
return;
}
}
});
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}; // Options for the observer (which mutations to observe)
config = {
attributes: false,
childList: true,
subtree: true
}; // Create an observer instance linked to the callback function
observer = new MutationObserver(callback); // Start observing the target node for configured mutations
observer.observe(document.body, config);
// Start observing the entire document for changes to child nodes and subtree
observer.observe(document, {
childList: true,
subtree: true
});
case 33:
case "end":
return _context.stop();
}
}, _callee, null, [[10, 21]]);
}))();
})();
/******/ })()
;
//# sourceMappingURL=saypi.user.js.map