text: /*! For license information please see 1a423617.js.LICENSE.txt */
  (self.webpackChunkhome_assistant_frontend=self.webpackChunkhome_assistant_frontend||[]).push([[2420],{28417:(e,t,r)=>{"use strict";r(50808);var i=r(33367),o=r(93592),n=r(87156);const s={getTabbableNodes:function(e){const t=[];return this._collectTabbableNodes(e,t)?o.H._sortByTabIndex(t):t},_collectTabbableNodes:function(e,t){if(e.nodeType!==Node.ELEMENT_NODE||!o.H._isVisible(e))return!1;const r=e,i=o.H._normalizedTabIndex(r);let s,a=i>0;i>=0&&t.push(r),s="content"===r.localName||"slot"===r.localName?(0,n.vz)(r).getDistributedNodes():(0,n.vz)(r.shadowRoot||r.root||r).children;for(let e=0;e<s.length;e++)a=this._collectTabbableNodes(s[e],t)||a;return a}},a=customElements.get("paper-dialog"),l={get _focusableNodes(){return s.getTabbableNodes(this)}};class c extends((0,i.P)([l],a)){}customElements.define("ha-paper-dialog",c)},72420:(e,t,r)=>{"use strict";r.r(t),r.d(t,{HaVoiceCommandDialog:()=>k});r(22626),r(30879);var i=r(50424),o=r(55358),n=r(76666),s=r(47181);const a=window.SpeechRecognition||window.webkitSpeechRecognition;window.SpeechGrammarList||window.webkitSpeechGrammarList,window.SpeechRecognitionEvent||window.webkitSpeechRecognitionEvent;function l(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}r(28417),r(10983);var c=r(11654);function d(){d=function(){return e};var e={elementsDefinitionOrder:[["method"],["field"]],initializeInstanceElements:function(e,t){["method","field"].forEach((function(r){t.forEach((function(t){t.kind===r&&"own"===t.placement&&this.defineClassElement(e,t)}),this)}),this)},initializeClassElements:function(e,t){var r=e.prototype;["method","field"].forEach((function(i){t.forEach((function(t){var o=t.placement;if(t.kind===i&&("static"===o||"prototype"===o)){var n="static"===o?e:r;this.defineClassElement(n,t)}}),this)}),this)},defineClassElement:function(e,t){var r=t.descriptor;if("field"===t.kind){var i=t.initializer;r={enumerable:r.enumerable,writable:r.writable,configurable:r.configurable,value:void 0===i?void 0:i.call(e)}}Object.defineProperty(e,t.key,r)},decorateClass:function(e,t){var r=[],i=[],o={static:[],prototype:[],own:[]};if(e.forEach((function(e){this.addElementPlacement(e,o)}),this),e.forEach((function(e){if(!p(e))return r.push(e);var t=this.decorateElement(e,o);r.push(t.element),r.push.apply(r,t.extras),i.push.apply(i,t.finishers)}),this),!t)return{elements:r,finishers:i};var n=this.decorateConstructor(r,t);return i.push.apply(i,n.finishers),n.finishers=i,n},addElementPlacement:function(e,t,r){var i=t[e.placement];if(!r&&-1!==i.indexOf(e.key))throw new TypeError("Duplicated element ("+e.key+")");i.push(e.key)},decorateElement:function(e,t){for(var r=[],i=[],o=e.decorators,n=o.length-1;n>=0;n--){var s=t[e.placement];s.splice(s.indexOf(e.key),1);var a=this.fromElementDescriptor(e),l=this.toElementFinisherExtras((0,o[n])(a)||a);e=l.element,this.addElementPlacement(e,t),l.finisher&&i.push(l.finisher);var c=l.extras;if(c){for(var d=0;d<c.length;d++)this.addElementPlacement(c[d],t);r.push.apply(r,c)}}return{element:e,finishers:i,extras:r}},decorateConstructor:function(e,t){for(var r=[],i=t.length-1;i>=0;i--){var o=this.fromClassDescriptor(e),n=this.toClassDescriptor((0,t[i])(o)||o);if(void 0!==n.finisher&&r.push(n.finisher),void 0!==n.elements){e=n.elements;for(var s=0;s<e.length-1;s++)for(var a=s+1;a<e.length;a++)if(e[s].key===e[a].key&&e[s].placement===e[a].placement)throw new TypeError("Duplicated element ("+e[s].key+")")}}return{elements:e,finishers:r}},fromElementDescriptor:function(e){var t={kind:e.kind,key:e.key,placement:e.placement,descriptor:e.descriptor};return Object.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),"field"===e.kind&&(t.initializer=e.initializer),t},toElementDescriptors:function(e){var t;if(void 0!==e)return(t=e,function(e){if(Array.isArray(e))return e}(t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||function(e,t){if(e){if("string"==typeof e)return v(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(e,t):void 0}}(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map((function(e){var t=this.toElementDescriptor(e);return this.disallowProperty(e,"finisher","An element descriptor"),this.disallowProperty(e,"extras","An element descriptor"),t}),this)},toElementDescriptor:function(e){var t=String(e.kind);if("method"!==t&&"field"!==t)throw new TypeError('An element descriptor\'s .kind property must be either "method" or "field", but a decorator created an element descriptor with .kind "'+t+'"');var r=g(e.key),i=String(e.placement);if("static"!==i&&"prototype"!==i&&"own"!==i)throw new TypeError('An element descriptor\'s .placement property must be one of "static", "prototype" or "own", but a decorator created an element descriptor with .placement "'+i+'"');var o=e.descriptor;this.disallowProperty(e,"elements","An element descriptor");var n={kind:t,key:r,placement:i,descriptor:Object.assign({},o)};return"field"!==t?this.disallowProperty(e,"initializer","A method descriptor"):(this.disallowProperty(o,"get","The property descriptor of a field descriptor"),this.disallowProperty(o,"set","The property descriptor of a field descriptor"),this.disallowProperty(o,"value","The property descriptor of a field descriptor"),n.initializer=e.initializer),n},toElementFinisherExtras:function(e){return{element:this.toElementDescriptor(e),finisher:m(e,"finisher"),extras:this.toElementDescriptors(e.extras)}},fromClassDescriptor:function(e){var t={kind:"class",elements:e.map(this.fromElementDescriptor,this)};return Object.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),t},toClassDescriptor:function(e){var t=String(e.kind);if("class"!==t)throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator created a class descriptor with .kind "'+t+'"');this.disallowProperty(e,"key","A class descriptor"),this.disallowProperty(e,"placement","A class descriptor"),this.disallowProperty(e,"descriptor","A class descriptor"),this.disallowProperty(e,"initializer","A class descriptor"),this.disallowProperty(e,"extras","A class descriptor");var r=m(e,"finisher");return{elements:this.toElementDescriptors(e.elements),finisher:r}},runClassFinishers:function(e,t){for(var r=0;r<t.length;r++){var i=(0,t[r])(e);if(void 0!==i){if("function"!=typeof i)throw new TypeError("Finishers must return a constructor.");e=i}}return e},disallowProperty:function(e,t,r){if(void 0!==e[t])throw new TypeError(r+" can't have a ."+t+" property.")}};return e}function h(e){var t,r=g(e.key);"method"===e.kind?t={value:e.value,writable:!0,configurable:!0,enumerable:!1}:"get"===e.kind?t={get:e.value,configurable:!0,enumerable:!1}:"set"===e.kind?t={set:e.value,configurable:!0,enumerable:!1}:"field"===e.kind&&(t={configurable:!0,writable:!0,enumerable:!0});var i={kind:"field"===e.kind?"field":"method",key:r,placement:e.static?"static":"field"===e.kind?"own":"prototype",descriptor:t};return e.decorators&&(i.decorators=e.decorators),"field"===e.kind&&(i.initializer=e.value),i}function u(e,t){void 0!==e.descriptor.get?t.descriptor.get=e.descriptor.get:t.descriptor.set=e.descriptor.set}function p(e){return e.decorators&&e.decorators.length}function f(e){return void 0!==e&&!(void 0===e.value&&void 0===e.writable)}function m(e,t){var r=e[t];if(void 0!==r&&"function"!=typeof r)throw new TypeError("Expected '"+t+"' to be a function");return r}function g(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,i=new Array(t);r<t;r++)i[r]=e[r];return i}function b(e,t,r){return(b="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,r){var i=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=y(e)););return e}(e,t);if(i){var o=Object.getOwnPropertyDescriptor(i,t);return o.get?o.get.call(r):o.value}})(e,t,r||e)}function y(e){return(y=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}let k=function(e,t,r,i){var o=d();if(i)for(var n=0;n<i.length;n++)o=i[n](o);var s=t((function(e){o.initializeInstanceElements(e,a.elements)}),r),a=o.decorateClass(function(e){for(var t=[],r=function(e){return"method"===e.kind&&e.key===n.key&&e.placement===n.placement},i=0;i<e.length;i++){var o,n=e[i];if("method"===n.kind&&(o=t.find(r)))if(f(n.descriptor)||f(o.descriptor)){if(p(n)||p(o))throw new ReferenceError("Duplicated methods ("+n.key+") can't be decorated.");o.descriptor=n.descriptor}else{if(p(n)){if(p(o))throw new ReferenceError("Decorators can't be placed on different accessors with for the same property ("+n.key+").");o.decorators=n.decorators}u(n,o)}else t.push(n)}return t}(s.d.map(h)),e);return o.initializeClassElements(s.F,a.elements),o.runClassFinishers(s.F,a.finishers)}([(0,o.Mo)("ha-voice-command-dialog")],(function(e,t){class r extends t{constructor(...t){super(...t),e(this)}}return{F:r,d:[{kind:"field",decorators:[(0,o.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,o.Cb)()],key:"results",value:()=>null},{kind:"field",decorators:[(0,o.SB)()],key:"_conversation",value:()=>[{who:"hass",text:""}]},{kind:"field",decorators:[(0,o.SB)()],key:"_opened",value:()=>!1},{kind:"field",decorators:[(0,o.SB)()],key:"_agentInfo",value:void 0},{kind:"field",decorators:[(0,o.IO)("#messages",!0)],key:"messages",value:void 0},{kind:"field",key:"recognition",value:void 0},{kind:"field",key:"_conversationId",value:void 0},{kind:"method",key:"showDialog",value:async function(){var e;this._opened=!0,a&&this._startListening(),this._agentInfo=await(e=this.hass,e.callWS({type:"conversation/agent/info"}))}},{kind:"method",key:"render",value:function(){return i.dy`
        <style>
          paper-dialog-scrollable {
            --paper-dialog-scrollable: {
              -webkit-overflow-scrolling: auto;
              max-height: 50vh !important;
            }
          }
  
          paper-dialog-scrollable.can-scroll {
            --paper-dialog-scrollable: {
              -webkit-overflow-scrolling: touch;
              max-height: 50vh !important;
            }
          }
  
          @media all and (max-width: 450px), all and (max-height: 500px) {
            paper-dialog-scrollable {
              --paper-dialog-scrollable: {
                -webkit-overflow-scrolling: auto;
                max-height: calc(100vh - 175px) !important;
              }
            }
  
            paper-dialog-scrollable.can-scroll {
              --paper-dialog-scrollable: {
                -webkit-overflow-scrolling: touch;
                max-height: calc(100vh - 175px) !important;
              }
            }
          }
        </style>
        <ha-paper-dialog
          with-backdrop
          .opened=${this._opened}
          @opened-changed=${this._openedChanged}
        >
          ${this._agentInfo&&this._agentInfo.onboarding?i.dy`
                <div class="onboarding">
                  ${this._agentInfo.onboarding.text}
                  <div class="side-by-side" @click=${this._completeOnboarding}>
                    <a
                      class="button"
                      href="${this._agentInfo.onboarding.url}"
                      target="_blank"
                      rel="noreferrer"
                      ><mwc-button unelevated
                        >${this.hass.localize("ui.common.yes")}!</mwc-button
                      ></a
                    >
                    <mwc-button outlined
                      >${this.hass.localize("ui.common.no")}</mwc-button
                    >
                  </div>
                </div>
              `:""}
          <paper-dialog-scrollable
            id="messages"
            class=${(0,n.$)({"top-border":Boolean(this._agentInfo&&this._agentInfo.onboarding)})}
          >
            ${this._conversation.map((e=>i.dy`
                <div class="${this._computeMessageClasses(e)}">
                  ${e.text}
                </div>
              `))}
            ${this.results?i.dy`
                  <div class="message user">
                    <span
                      class=${(0,n.$)({interimTranscript:!this.results.final})}
                      >${this.results.transcript}</span
                    >${this.results.final?"":"…"}
                  </div>
                `:""}
          </paper-dialog-scrollable>
          <div class="input">
            <paper-input
              @keyup=${this._handleKeyUp}
              .label="${this.hass.localize("ui.dialogs.voice_command."+(a?"label_voice":"label"))}"
              autofocus
            >
              ${a?i.dy`
                    <span suffix="" slot="suffix">
                      ${this.results?i.dy`
                            <div class="bouncer">
                              <div class="double-bounce1"></div>
                              <div class="double-bounce2"></div>
                            </div>
                          `:""}
                      <ha-icon-button
                        icon="hass:microphone"
                        @click=${this._toggleListening}
                      >
                      </ha-icon-button>
                    </span>
                  `:""}
            </paper-input>
            ${this._agentInfo&&this._agentInfo.attribution?i.dy`
                  <a
                    href=${this._agentInfo.attribution.url}
                    class="attribution"
                    target="_blank"
                    rel="noreferrer"
                    >${this._agentInfo.attribution.name}</a
                  >
                `:""}
          </div>
        </ha-paper-dialog>
      `}},{kind:"method",key:"firstUpdated",value:function(e){b(y(r.prototype),"updated",this).call(this,e),this._conversationId=l()+l()+l()+l()+l(),this._conversation=[{who:"hass",text:this.hass.localize("ui.dialogs.voice_command.how_can_i_help")}]}},{kind:"method",key:"updated",value:function(e){b(y(r.prototype),"updated",this).call(this,e),(e.has("_conversation")||e.has("results"))&&this._scrollMessagesBottom()}},{kind:"method",key:"_addMessage",value:function(e){this._conversation=[...this._conversation,e]}},{kind:"method",key:"_handleKeyUp",value:function(e){const t=e.target;13===e.keyCode&&t.value&&(this._processText(t.value),t.value="")}},{kind:"method",key:"_completeOnboarding",value:function(){var e,t;e=this.hass,t=!0,e.callWS({type:"conversation/onboarding/set",shown:t}),this._agentInfo={...this._agentInfo,onboarding:void 0}}},{kind:"method",key:"_initRecognition",value:function(){this.recognition=new a,this.recognition.interimResults=!0,this.recognition.lang="en-US",this.recognition.onstart=()=>{this.results={final:!1,transcript:""}},this.recognition.onerror=e=>{if(this.recognition.abort(),"aborted"!==e.error){const e=this.results&&this.results.transcript?this.results.transcript:`<${this.hass.localize("ui.dialogs.voice_command.did_not_hear")}>`;this._addMessage({who:"user",text:e,error:!0})}this.results=null},this.recognition.onend=()=>{if(null==this.results)return;const e=this.results.transcript;this.results=null,e?this._processText(e):this._addMessage({who:"user",text:`<${this.hass.localize("ui.dialogs.voice_command.did_not_hear")}>`,error:!0})},this.recognition.onresult=e=>{const t=e.results[0];this.results={transcript:t[0].transcript,final:t.isFinal}}}},{kind:"method",key:"_processText",value:async function(e){this.recognition&&this.recognition.abort(),this._addMessage({who:"user",text:e});const t={who:"hass",text:"…"};this._addMessage(t);try{const r=(await((e,t,r)=>e.callWS({type:"conversation/process",text:t,conversation_id:r}))(this.hass,e,this._conversationId)).speech.plain;t.text=r.speech,this.requestUpdate("_conversation")}catch{t.text=this.hass.localize("ui.dialogs.voice_command.error"),t.error=!0,this.requestUpdate("_conversation")}}},{kind:"method",key:"_toggleListening",value:function(){this.results?this.recognition.stop():this._startListening()}},{kind:"method",key:"_startListening",value:function(){this.recognition||this._initRecognition(),this.results||(this.results={transcript:"",final:!1},this.recognition.start())}},{kind:"method",key:"_scrollMessagesBottom",value:function(){this.messages.scrollTarget.scrollTop=this.messages.scrollTarget.scrollHeight,0===this.messages.scrollTarget.scrollTop&&(0,s.B)(this.messages,"iron-resize")}},{kind:"method",key:"_openedChanged",value:function(e){this._opened=e.detail.value,!this._opened&&this.recognition&&this.recognition.abort()}},{kind:"method",key:"_computeMessageClasses",value:function(e){return`message ${e.who} ${e.error?" error":""}`}},{kind:"get",static:!0,key:"styles",value:function(){return[c.yu,i.iv`
          :host {
            z-index: 103;
          }
  
          ha-icon-button {
            color: var(--secondary-text-color);
          }
  
          ha-icon-button[active] {
            color: var(--primary-color);
          }
  
          .input {
            margin: 0 0 16px 0;
          }
  
          ha-paper-dialog {
            width: 450px;
          }
          a.button {
            text-decoration: none;
          }
          a.button > mwc-button {
            width: 100%;
          }
          .onboarding {
            padding: 0 24px;
          }
          paper-dialog-scrollable.top-border::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 1px;
            background: var(--divider-color);
          }
          .side-by-side {
            display: flex;
            margin: 8px 0;
          }
          .side-by-side > * {
            flex: 1 0;
            padding: 4px;
          }
          .attribution {
            color: var(--secondary-text-color);
          }
          .message {
            font-size: 18px;
            clear: both;
            margin: 8px 0;
            padding: 8px;
            border-radius: 15px;
          }
  
          .message.user {
            margin-left: 24px;
            float: right;
            text-align: right;
            border-bottom-right-radius: 0px;
            background-color: var(--light-primary-color);
            color: var(--text-light-primary-color, var(--primary-text-color));
          }
  
          .message.hass {
            margin-right: 24px;
            float: left;
            border-bottom-left-radius: 0px;
            background-color: var(--primary-color);
            color: var(--text-primary-color);
          }
  
          .message a {
            color: var(--text-primary-color);
          }
  
          .message img {
            width: 100%;
            border-radius: 10px;
          }
  
          .message.error {
            background-color: var(--error-color);
            color: var(--text-primary-color);
          }
  
          .interimTranscript {
            color: var(--secondary-text-color);
          }
  
          .bouncer {
            width: 48px;
            height: 48px;
            position: absolute;
            top: 0;
          }
          .double-bounce1,
          .double-bounce2 {
            width: 48px;
            height: 48px;
            border-radius: 50%;
            background-color: var(--primary-color);
            opacity: 0.2;
            position: absolute;
            top: 0;
            left: 0;
            -webkit-animation: sk-bounce 2s infinite ease-in-out;
            animation: sk-bounce 2s infinite ease-in-out;
          }
          .double-bounce2 {
            -webkit-animation-delay: -1s;
            animation-delay: -1s;
          }
          @-webkit-keyframes sk-bounce {
            0%,
            100% {
              -webkit-transform: scale(0);
            }
            50% {
              -webkit-transform: scale(1);
            }
          }
          @keyframes sk-bounce {
            0%,
            100% {
              transform: scale(0);
              -webkit-transform: scale(0);
            }
            50% {
              transform: scale(1);
              -webkit-transform: scale(1);
            }
          }
  
          @media all and (max-width: 450px), all and (max-height: 500px) {
            .message {
              font-size: 16px;
            }
          }
        `]}}]}}),i.oi)}}]);
  //# sourceMappingURL=1a423617.js.map