@untemps/react-vocal
Version:
React component and hook to initiate a SpeechRecognition session
2 lines • 308 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("prop-types");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=n(t),i=n(e);function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function s(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function c(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?s(Object(n),!0).forEach((function(e){o(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function a(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],r=!0,i=!1,o=void 0;try{for(var s,c=t[Symbol.iterator]();!(r=(s=c.next()).done)&&(n.push(s.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{r||null==c.return||c.return()}finally{if(i)throw o}}return n}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return u(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(t,e)}(t,e)||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.")}()}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var l=function(t,e,n){return function(t){var e=function(t){var e=Object.prototype,n=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",o=r.asyncIterator||"@@asyncIterator",s=r.toStringTag||"@@toStringTag";function c(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,n){return t[e]=n}}function a(t,e,n,r){var i=e&&e.prototype instanceof h?e:h,o=Object.create(i.prototype),s=new _(r||[]);return o._invoke=function(t,e,n){var r="suspendedStart";return function(i,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw o;return L()}for(n.method=i,n.arg=o;;){var s=n.delegate;if(s){var c=w(s,n);if(c){if(c===l)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var a=u(t,e,n);if("normal"===a.type){if(r=n.done?"completed":"suspendedYield",a.arg===l)continue;return{value:a.arg,done:n.done}}"throw"===a.type&&(r="completed",n.method="throw",n.arg=a.arg)}}}(t,n,s),o}function u(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=a;var l={};function h(){}function f(){}function d(){}var p={};p[i]=function(){return this};var g=Object.getPrototypeOf,v=g&&g(g(E([])));v&&v!==e&&n.call(v,i)&&(p=v);var y=d.prototype=h.prototype=Object.create(p);function m(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var r;this._invoke=function(i,o){function s(){return new e((function(r,s){!function r(i,o,s,c){var a=u(t[i],t,o);if("throw"!==a.type){var l=a.arg,h=l.value;return h&&"object"==typeof h&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,s,c)}),(function(t){r("throw",t,s,c)})):e.resolve(h).then((function(t){l.value=t,s(l)}),(function(t){return r("throw",t,s,c)}))}c(a.arg)}(i,o,r,s)}))}return r=r?r.then(s,s):s()}}function w(t,e){var n=t.iterator[e.method];if(void 0===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,w(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var r=u(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,l;var i=r.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function x(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function S(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function E(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:L}}function L(){return{value:void 0,done:!0}}return f.prototype=y.constructor=d,d.constructor=f,f.displayName=c(d,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===f||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,c(t,s,"GeneratorFunction")),t.prototype=Object.create(y),t},t.awrap=function(t){return{__await:t}},m(b.prototype),b.prototype[o]=function(){return this},t.AsyncIterator=b,t.async=function(e,n,r,i,o){void 0===o&&(o=Promise);var s=new b(a(e,n,r,i),o);return t.isGeneratorFunction(n)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},m(y),c(y,s,"Generator"),y[i]=function(){return this},y.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=E,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(S),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(n,r){return s.type="throw",s.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var c=n.call(o,"catchLoc"),a=n.call(o,"finallyLoc");if(c&&a){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!a)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=t,s.arg=e,o?(this.method="next",this.next=o.finallyLoc,l):this.complete(s)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),S(n),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;S(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:E(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}(n={path:void 0,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&n.path)}},n.exports),n.exports}();function h(t,e,n,r,i,o,s){try{var c=t[o](s),a=c.value}catch(t){return void n(t)}c.done?e(a):Promise.resolve(a).then(r,i)}var f=function(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var o=t.apply(e,n);function s(t){h(o,r,i,s,c,"next",t)}function c(t){h(o,r,i,s,c,"throw",t)}s(void 0)}))}},d=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r},p=function(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var n=[],r=!0,i=!1,o=void 0;try{for(var s,c=t[Symbol.iterator]();!(r=(s=c.next()).done)&&(n.push(s.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{r||null==c.return||c.return()}finally{if(i)throw o}}return n}}(t,e)||function(t,e){if(t){if("string"==typeof t)return d(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(t,e):void 0}}(t,e)||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.")}()};function g(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}var v=function(t,e,n){return e&&g(t.prototype,e),n&&g(t,n),t},y=function(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t},m=function(){return!!navigator.permissions},b=function(){return!!navigator.mediaDevices};function w(t,e,n,r,i,o,s){try{var c=t[o](s),a=c.value}catch(t){return void n(t)}c.done?e(a):Promise.resolve(a).then(r,i)}function x(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var o=t.apply(e,n);function s(t){w(o,r,i,s,c,"next",t)}function c(t){w(o,r,i,s,c,"throw",t)}s(void 0)}))}}function S(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var n=[],r=!0,i=!1,o=void 0;try{for(var s,c=t[Symbol.iterator]();!(r=(s=c.next()).done)&&(n.push(s.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{r||null==c.return||c.return()}finally{if(i)throw o}}return n}}(t,e)||function(t,e){if(t){if("string"==typeof t)return _(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_(t,e):void 0}}(t,e)||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.")}()}function _(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var E=function(){var t=x(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(){var t=x(regeneratorRuntime.mark((function t(n,r){var i,o;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return m()||r(new DOMException("Navigator API: permissions not supported","NOT_SUPPORTED_ERR")),t.prev=1,t.next=4,navigator.permissions.query({name:e});case 4:i=t.sent,o=function t(e){i.removeEventListener("change",t),L(e.target.state,n,r)},i.addEventListener("change",o),L(i.state,n,r),t.next=13;break;case 10:t.prev=10,t.t0=t.catch(1),r(t.t0);case 13:case"end":return t.stop()}}),t,null,[[1,10]])})));return function(e,n){return t.apply(this,arguments)}}()));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),L=function(t,e,n){if("denied"===t)n(new DOMException("Permission denied","NOT_ALLOWED_ERR"));else e(t)},M=function(){var t=x(regeneratorRuntime.mark((function t(e,n){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(){var t=x(regeneratorRuntime.mark((function t(r,i){var o,s,c;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return m()&&b()||i(new DOMException("Navigator API: permissions or Navigator API: mediaDevices not supported","NOT_SUPPORTED_ERR")),t.prev=1,t.t0=Promise,t.next=5,E(e);case 5:return t.t1=t.sent,t.next=8,navigator.mediaDevices.getUserMedia(n);case 8:return t.t2=t.sent,t.t3=[t.t1,t.t2],t.next=12,t.t0.all.call(t.t0,t.t3);case 12:o=t.sent,s=S(o,2),c=s[1],r(c),t.next=21;break;case 18:t.prev=18,t.t4=t.catch(1),i(t.t4);case 21:case"end":return t.stop()}}),t,null,[[1,18]])})));return function(e,n){return t.apply(this,arguments)}}()));case 1:case"end":return t.stop()}}),t)})));return function(e,n){return t.apply(this,arguments)}}();function O(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function k(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?O(Object(n),!0).forEach((function(e){y(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):O(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var j=function(){function t(e){var n=this;(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,t),y(this,"_instance",null),y(this,"_listeners",null);var r=t._resolveSpeechRecognition();if(!r)throw new DOMException("SpeechRecognition not supported","NOT_SUPPORTED_ERR");this._instance=new r,this._listeners={},Object.entries(k(k({},t.defaultOptions),e||{})).forEach((function(e){var r=p(e,2),i=r[0],o=r[1];if("grammars"===i&&!o){var s=t._resolveSpeechGrammarList();s&&(o=new s)}n._instance[i]=o}))}var e;return v(t,null,[{key:"isSupported",get:function(){return!!t._resolveSpeechRecognition()&&!!m()&&!!b()},set:function(t){throw new Error("You cannot set isSupported directly.")}}]),v(t,[{key:"start",value:(e=f(l.mark((function t(){var e;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this._instance){t.next=14;break}return t.prev=1,t.next=4,M("microphone",{audio:!0});case 4:if(t.sent){t.next=7;break}throw new Error("Unable to retrieve the stream from media device");case 7:this._instance.start(),t.next=14;break;case 10:t.prev=10,t.t0=t.catch(1),(e=this._listeners.error)&&e(t.t0);case 14:return t.abrupt("return",this);case 15:case"end":return t.stop()}}),t,this,[[1,10]])}))),function(){return e.apply(this,arguments)})},{key:"stop",value:function(){return this._instance&&this._instance.stop(),this}},{key:"abort",value:function(){return this._instance&&this._instance.abort(),this}},{key:"addEventListener",value:function(e,n){var r=this;if(this._instance&&this._includesEventType(e)){this._listeners[e]&&this.removeEventListener(e);var i=function(i){var o=[];e===t.eventTypes.RESULT&&i.results&&i.results.length>0&&o.push(i.results[0][0].transcript),n&&n.apply(r,[i].concat(o))};this._instance.addEventListener(e,i),this._listeners[e]=i}return this}},{key:"removeEventListener",value:function(t){var e=this._listeners[t];return this._instance.removeEventListener(t,e),delete this._listeners[t],this}},{key:"cleanup",value:function(){var t=this;return this.stop(),Object.keys(this._listeners).forEach((function(e){return t.removeEventListener(e)})),this._instance=null,this}},{key:"_includesEventType",value:function(e){return!!Object.values(t.eventTypes).find((function(t){return t===e}))}},{key:"instance",get:function(){return this._instance},set:function(t){throw new Error("You cannot set instance directly.")}}],[{key:"_resolveSpeechRecognition",value:function(){return window.SpeechRecognition||window.webkitSpeechRecognition||window.mozSpeechRecognition||window.msSpeechRecognition}},{key:"_resolveSpeechGrammarList",value:function(){return window.SpeechGrammarList||window.webkitSpeechGrammarList||window.mozSpeechGrammarList||window.msSpeechGrammarList}}]),t}();y(j,"defaultOptions",{grammars:null,lang:"en-US",continuous:!1,interimResults:!1,maxAlternatives:1,serviceURI:null}),y(j,"eventTypes",{AUDIO_END:"audioend",AUDIO_START:"audiostart",END:"end",ERROR:"error",NO_MATCH:"nomatch",RESULT:"result",SOUND_END:"soundend",SOUND_START:"soundstart",SPEECH_END:"speechend",SPEECH_START:"speechstart",START:"start"});var A=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"en-US",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=t.useRef(null);t.useEffect((function(){if(j.isSupported)return i.current=r||new j({lang:e,grammars:n}),function(){i.current.abort(),i.current.cleanup()}}),[e,n,r]);var o=t.useCallback((function(){i.current&&i.current.start()}),[]),s=t.useCallback((function(){i.current&&i.current.stop()}),[]),c=t.useCallback((function(){i.current&&i.current.abort()}),[]),a=t.useCallback((function(t,e){i.current&&i.current.addEventListener(t,e)}),[]),u=t.useCallback((function(t,e){i.current&&i.current.removeEventListener(t,e)}),[]),l=t.useCallback((function(){i.current&&i.current.cleanup()}),[]);return[i,{start:o,stop:s,abort:c,subscribe:a,unsubscribe:u,clean:l}]};function R(t){return Array.isArray?Array.isArray(t):"[object Array]"===F(t)}function C(t){return"string"==typeof t}function I(t){return"number"==typeof t}function P(t){return!0===t||!1===t||function(t){return N(t)&&null!==t}(t)&&"[object Boolean]"==F(t)}function N(t){return"object"==typeof t}function $(t){return null!=t}function T(t){return!t.trim().length}function F(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const D=Object.prototype.hasOwnProperty;class U{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach((t=>{let n=G(t);e+=n.weight,this._keys.push(n),this._keyMap[n.id]=n,e+=n.weight})),this._keys.forEach((t=>{t.weight/=e}))}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function G(t){let e=null,n=null,r=null,i=1;if(C(t)||R(t))r=t,e=q(t),n=z(t);else{if(!D.call(t,"name"))throw new Error((t=>`Missing ${t} property in key`)("name"));const o=t.name;if(r=o,D.call(t,"weight")&&(i=t.weight,i<=0))throw new Error((t=>`Property 'weight' in key '${t}' must be a positive integer`)(o));e=q(o),n=z(o)}return{path:e,id:n,weight:i,src:r}}function q(t){return R(t)?t:t.split(".")}function z(t){return R(t)?t.join("."):t}const K={useExtendedSearch:!1,getFn:function(t,e){let n=[],r=!1;const i=(t,e,o)=>{if($(t))if(e[o]){const s=t[e[o]];if(!$(s))return;if(o===e.length-1&&(C(s)||I(s)||P(s)))n.push(function(t){return null==t?"":function(t){if("string"==typeof t)return t;let e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(t)}(s));else if(R(s)){r=!0;for(let t=0,n=s.length;t<n;t+=1)i(s[t],e,o+1)}else e.length&&i(s,e,o+1)}else n.push(t)};return i(t,C(e)?e.split("."):e,0),r?n:n[0]},ignoreLocation:!1,ignoreFieldNorm:!1};var V={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1,includeMatches:!1,findAllMatches:!1,minMatchCharLength:1,location:0,threshold:.6,distance:100,...K};const W=/[^ ]+/g;class H{constructor({getFn:t=V.getFn}={}){this.norm=function(t=3){const e=new Map,n=Math.pow(10,t);return{get(t){const r=t.match(W).length;if(e.has(r))return e.get(r);const i=1/Math.sqrt(r),o=parseFloat(Math.round(i*n)/n);return e.set(r,o),o},clear(){e.clear()}}}(3),this.getFn=t,this.isCreated=!1,this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach(((t,e)=>{this._keysMap[t.id]=e}))}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,C(this.docs[0])?this.docs.forEach(((t,e)=>{this._addString(t,e)})):this.docs.forEach(((t,e)=>{this._addObject(t,e)})),this.norm.clear())}add(t){const e=this.size();C(t)?this._addString(t,e):this._addObject(t,e)}removeAt(t){this.records.splice(t,1);for(let e=t,n=this.size();e<n;e+=1)this.records[e].i-=1}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_addString(t,e){if(!$(t)||T(t))return;let n={v:t,i:e,n:this.norm.get(t)};this.records.push(n)}_addObject(t,e){let n={i:e,$:{}};this.keys.forEach(((e,r)=>{let i=this.getFn(t,e.path);if($(i))if(R(i)){let t=[];const e=[{nestedArrIndex:-1,value:i}];for(;e.length;){const{nestedArrIndex:n,value:r}=e.pop();if($(r))if(C(r)&&!T(r)){let e={v:r,i:n,n:this.norm.get(r)};t.push(e)}else R(r)&&r.forEach(((t,n)=>{e.push({nestedArrIndex:n,value:t})}))}n.$[r]=t}else if(!T(i)){let t={v:i,n:this.norm.get(i)};n.$[r]=t}})),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function Y(t,e,{getFn:n=V.getFn}={}){const r=new H({getFn:n});return r.setKeys(t.map(G)),r.setSources(e),r.create(),r}function B(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:i=V.distance,ignoreLocation:o=V.ignoreLocation}={}){const s=e/t.length;if(o)return s;const c=Math.abs(r-n);return i?s+c/i:c?1:s}function J(t,e,n,{location:r=V.location,distance:i=V.distance,threshold:o=V.threshold,findAllMatches:s=V.findAllMatches,minMatchCharLength:c=V.minMatchCharLength,includeMatches:a=V.includeMatches,ignoreLocation:u=V.ignoreLocation}={}){if(e.length>32)throw new Error(`Pattern length exceeds max of ${32}.`);const l=e.length,h=t.length,f=Math.max(0,Math.min(r,h));let d=o,p=f;const g=c>1||a,v=g?Array(h):[];let y;for(;(y=t.indexOf(e,p))>-1;){let t=B(e,{currentLocation:y,expectedLocation:f,distance:i,ignoreLocation:u});if(d=Math.min(t,d),p=y+l,g){let t=0;for(;t<l;)v[y+t]=1,t+=1}}p=-1;let m=[],b=1,w=l+h;const x=1<<l-1;for(let r=0;r<l;r+=1){let o=0,c=w;for(;o<c;){B(e,{errors:r,currentLocation:f+c,expectedLocation:f,distance:i,ignoreLocation:u})<=d?o=c:w=c,c=Math.floor((w-o)/2+o)}w=c;let a=Math.max(1,f-c+1),y=s?h:Math.min(f+c,h)+l,S=Array(y+2);S[y+1]=(1<<r)-1;for(let o=y;o>=a;o-=1){let s=o-1,c=n[t.charAt(s)];if(g&&(v[s]=+!!c),S[o]=(S[o+1]<<1|1)&c,r&&(S[o]|=(m[o+1]|m[o])<<1|1|m[o+1]),S[o]&x&&(b=B(e,{errors:r,currentLocation:s,expectedLocation:f,distance:i,ignoreLocation:u}),b<=d)){if(d=b,p=s,p<=f)break;a=Math.max(1,2*f-p)}}if(B(e,{errors:r+1,currentLocation:f,expectedLocation:f,distance:i,ignoreLocation:u})>d)break;m=S}const S={isMatch:p>=0,score:Math.max(.001,b)};if(g){const t=function(t=[],e=V.minMatchCharLength){let n=[],r=-1,i=-1,o=0;for(let s=t.length;o<s;o+=1){let s=t[o];s&&-1===r?r=o:s||-1===r||(i=o-1,i-r+1>=e&&n.push([r,i]),r=-1)}return t[o-1]&&o-r>=e&&n.push([r,o-1]),n}(v,c);t.length?a&&(S.indices=t):S.isMatch=!1}return S}function Q(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const i=t.charAt(n);e[i]=(e[i]||0)|1<<r-n-1}return e}class X{constructor(t,{location:e=V.location,threshold:n=V.threshold,distance:r=V.distance,includeMatches:i=V.includeMatches,findAllMatches:o=V.findAllMatches,minMatchCharLength:s=V.minMatchCharLength,isCaseSensitive:c=V.isCaseSensitive,ignoreLocation:a=V.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:r,includeMatches:i,findAllMatches:o,minMatchCharLength:s,isCaseSensitive:c,ignoreLocation:a},this.pattern=c?t:t.toLowerCase(),this.chunks=[],!this.pattern.length)return;const u=(t,e)=>{this.chunks.push({pattern:t,alphabet:Q(t),startIndex:e})},l=this.pattern.length;if(l>32){let t=0;const e=l%32,n=l-e;for(;t<n;)u(this.pattern.substr(t,32),t),t+=32;if(e){const t=l-32;u(this.pattern.substr(t),t)}}else u(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,includeMatches:n}=this.options;if(e||(t=t.toLowerCase()),this.pattern===t){let e={isMatch:!0,score:0};return n&&(e.indices=[[0,t.length-1]]),e}const{location:r,distance:i,threshold:o,findAllMatches:s,minMatchCharLength:c,ignoreLocation:a}=this.options;let u=[],l=0,h=!1;this.chunks.forEach((({pattern:e,alphabet:f,startIndex:d})=>{const{isMatch:p,score:g,indices:v}=J(t,e,f,{location:r+d,distance:i,threshold:o,findAllMatches:s,minMatchCharLength:c,includeMatches:n,ignoreLocation:a});p&&(h=!0),l+=g,p&&v&&(u=[...u,...v])}));let f={isMatch:h,score:h?l/this.chunks.length:1};return h&&n&&(f.indices=u),f}}class Z{constructor(t){this.pattern=t}static isMultiMatch(t){return tt(t,this.multiRegex)}static isSingleMatch(t){return tt(t,this.singleRegex)}search(){}}function tt(t,e){const n=t.match(e);return n?n[1]:null}class et extends Z{constructor(t,{location:e=V.location,threshold:n=V.threshold,distance:r=V.distance,includeMatches:i=V.includeMatches,findAllMatches:o=V.findAllMatches,minMatchCharLength:s=V.minMatchCharLength,isCaseSensitive:c=V.isCaseSensitive,ignoreLocation:a=V.ignoreLocation}={}){super(t),this._bitapSearch=new X(t,{location:e,threshold:n,distance:r,includeMatches:i,findAllMatches:o,minMatchCharLength:s,isCaseSensitive:c,ignoreLocation:a})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(t){return this._bitapSearch.searchIn(t)}}class nt extends Z{constructor(t){super(t)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(t){let e,n=0;const r=[],i=this.pattern.length;for(;(e=t.indexOf(this.pattern,n))>-1;)n=e+i,r.push([e,n-1]);const o=!!r.length;return{isMatch:o,score:o?0:1,indices:r}}}const rt=[class extends Z{constructor(t){super(t)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(t){const e=t===this.pattern;return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}},nt,class extends Z{constructor(t){super(t)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(t){const e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}},class extends Z{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(t){const e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends Z{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(t){const e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends Z{constructor(t){super(t)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(t){const e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[t.length-this.pattern.length,t.length-1]}}},class extends Z{constructor(t){super(t)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(t){const e=-1===t.indexOf(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},et],it=rt.length,ot=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;const st=new Set([et.type,nt.type]);class ct{constructor(t,{isCaseSensitive:e=V.isCaseSensitive,includeMatches:n=V.includeMatches,minMatchCharLength:r=V.minMatchCharLength,ignoreLocation:i=V.ignoreLocation,findAllMatches:o=V.findAllMatches,location:s=V.location,threshold:c=V.threshold,distance:a=V.distance}={}){this.query=null,this.options={isCaseSensitive:e,includeMatches:n,minMatchCharLength:r,findAllMatches:o,ignoreLocation:i,location:s,threshold:c,distance:a},this.pattern=e?t:t.toLowerCase(),this.query=function(t,e={}){return t.split("|").map((t=>{let n=t.trim().split(ot).filter((t=>t&&!!t.trim())),r=[];for(let t=0,i=n.length;t<i;t+=1){const i=n[t];let o=!1,s=-1;for(;!o&&++s<it;){const t=rt[s];let n=t.isMultiMatch(i);n&&(r.push(new t(n,e)),o=!0)}if(!o)for(s=-1;++s<it;){const t=rt[s];let n=t.isSingleMatch(i);if(n){r.push(new t(n,e));break}}}return r}))}(this.pattern,this.options)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:r}=this.options;t=r?t:t.toLowerCase();let i=0,o=[],s=0;for(let r=0,c=e.length;r<c;r+=1){const c=e[r];o.length=0,i=0;for(let e=0,r=c.length;e<r;e+=1){const r=c[e],{isMatch:a,indices:u,score:l}=r.search(t);if(!a){s=0,i=0,o.length=0;break}if(i+=1,s+=l,n){const t=r.constructor.type;st.has(t)?o=[...o,...u]:o.push(u)}}if(i){let t={isMatch:!0,score:s/i};return n&&(t.indices=o),t}}return{isMatch:!1,score:1}}}const at=[];function ut(t,e){for(let n=0,r=at.length;n<r;n+=1){let r=at[n];if(r.condition(t,e))return new r(t,e)}return new X(t,e)}const lt="$and",ht="$or",ft="$path",dt="$val",pt=t=>!(!t[lt]&&!t[ht]),gt=t=>({[lt]:Object.keys(t).map((e=>({[e]:t[e]})))});function vt(t,e,{auto:n=!0}={}){const r=t=>{let i=Object.keys(t);const o=(t=>!!t[ft])(t);if(!o&&i.length>1&&!pt(t))return r(gt(t));if((t=>!R(t)&&N(t)&&!pt(t))(t)){const r=o?t[ft]:i[0],s=o?t[dt]:t[r];if(!C(s))throw new Error((t=>`Invalid value for key ${t}`)(r));const c={keyId:z(r),pattern:s};return n&&(c.searcher=ut(s,e)),c}let s={children:[],operator:i[0]};return i.forEach((e=>{const n=t[e];R(n)&&n.forEach((t=>{s.children.push(r(t))}))})),s};return pt(t)||(t=gt(t)),r(t)}function yt(t,e){const n=t.matches;e.matches=[],$(n)&&n.forEach((t=>{if(!$(t.indices)||!t.indices.length)return;const{indices:n,value:r}=t;let i={indices:n,value:r};t.key&&(i.key=t.key.src),t.idx>-1&&(i.refIndex=t.idx),e.matches.push(i)}))}function mt(t,e){e.score=t.score}class bt{constructor(t,e={},n){this.options={...V,...e},this.options.useExtendedSearch,this._keyStore=new U(this.options.keys),this.setCollection(t,n)}setCollection(t,e){if(this._docs=t,e&&!(e instanceof H))throw new Error("Incorrect 'index' type");this._myIndex=e||Y(this.options.keys,this._docs,{getFn:this.options.getFn})}add(t){$(t)&&(this._docs.push(t),this._myIndex.add(t))}remove(t=(()=>!1)){const e=[];for(let n=0,r=this._docs.length;n<r;n+=1){const i=this._docs[n];t(i,n)&&(this.removeAt(n),n-=1,r-=1,e.push(i))}return e}removeAt(t){this._docs.splice(t,1),this._myIndex.removeAt(t)}getIndex(){return this._myIndex}search(t,{limit:e=-1}={}){const{includeMatches:n,includeScore:r,shouldSort:i,sortFn:o,ignoreFieldNorm:s}=this.options;let c=C(t)?C(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t);return function(t,{ignoreFieldNorm:e=V.ignoreFieldNorm}){t.forEach((t=>{let n=1;t.matches.forEach((({key:t,norm:r,score:i})=>{const o=t?t.weight:null;n*=Math.pow(0===i&&o?Number.EPSILON:i,(o||1)*(e?1:r))})),t.score=n}))}(c,{ignoreFieldNorm:s}),i&&c.sort(o),I(e)&&e>-1&&(c=c.slice(0,e)),function(t,e,{includeMatches:n=V.includeMatches,includeScore:r=V.includeScore}={}){const i=[];return n&&i.push(yt),r&&i.push(mt),t.map((t=>{const{idx:n}=t,r={item:e[n],refIndex:n};return i.length&&i.forEach((e=>{e(t,r)})),r}))}(c,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(t){const e=ut(t,this.options),{records:n}=this._myIndex,r=[];return n.forEach((({v:t,i:n,n:i})=>{if(!$(t))return;const{isMatch:o,score:s,indices:c}=e.searchIn(t);o&&r.push({item:t,idx:n,matches:[{score:s,value:t,norm:i,indices:c}]})})),r}_searchLogical(t){const e=vt(t,this.options),n=(t,e,r)=>{if(!t.children){const{keyId:n,searcher:i}=t,o=this._findMatches({key:this._keyStore.get(n),value:this._myIndex.getValueForItemAtKeyId(e,n),searcher:i});return o&&o.length?[{idx:r,item:e,matches:o}]:[]}switch(t.operator){case lt:{const i=[];for(let o=0,s=t.children.length;o<s;o+=1){const s=t.children[o],c=n(s,e,r);if(!c.length)return[];i.push(...c)}return i}case ht:{const i=[];for(let o=0,s=t.children.length;o<s;o+=1){const s=t.children[o],c=n(s,e,r);if(c.length){i.push(...c);break}}return i}}},r=this._myIndex.records,i={},o=[];return r.forEach((({$:t,i:r})=>{if($(t)){let s=n(e,t,r);s.length&&(i[r]||(i[r]={idx:r,item:t,matches:[]},o.push(i[r])),s.forEach((({matches:t})=>{i[r].matches.push(...t)})))}})),o}_searchObjectList(t){const e=ut(t,this.options),{keys:n,records:r}=this._myIndex,i=[];return r.forEach((({$:t,i:r})=>{if(!$(t))return;let o=[];n.forEach(((n,r)=>{o.push(...this._findMatches({key:n,value:t[r],searcher:e}))})),o.length&&i.push({idx:r,item:t,matches:o})})),i}_findMatches({key:t,value:e,searcher:n}){if(!$(e))return[];let r=[];if(R(e))e.forEach((({v:e,i:i,n:o})=>{if(!$(e))return;const{isMatch:s,score:c,indices:a}=n.searchIn(e);s&&r.push({score:c,key:t,value:e,idx:i,norm:o,indices:a})}));else{const{v:i,n:o}=e,{isMatch:s,score:c,indices:a}=n.searchIn(i);s&&r.push({score:c,key:t,value:i,norm:o,indices:a})}return r}}bt.version="6.4.6",bt.createIndex=Y,bt.parseIndex=function(t,{getFn:e=V.getFn}={}){const{keys:n,records:r}=t,i=new H({getFn:e});return i.setKeys(n),i.setIndexRecords(r),i},bt.config=V,bt.parseQuery=vt,function(...t){at.push(...t)}(ct);var wt=function(t){var e=t.color,n=t.activeColor,i=t.isActive;return r.default.createElement("svg",{"data-testid":"__icon-root__",xmlns:"http://www.w3.org/2000/svg",width:"100%",height:"100%",viewBox:"0 0 24 24"},r.default.createElement("g",null,r.default.createElement("path",{"data-testid":"__icon-path__",fill:e,d:"M12 14c1.66 0 2.99-1.34 2.99-3L15 5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5.3-3c0 3-2.54 5.1-5.3 5.1S6.7 14 6.7 11H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c3.28-.48 6-3.3 6-6.72h-1.7z"}),i&&r.default.createElement("circle",{"data-testid":"__icon-active__",fill:n,cx:"16",cy:"4",r:"4"})))};wt.propTypes={color:i.default.string,activeColor:i.default.string,isActive:i.default.bool},wt.defaultProps={color:"black",activeColor:"red",isActive:!1};var xt=function(e){var n=e.children,i=e.commands,s=e.lang,u=e.grammars,l=e.timeout,h=e.ariaLabel,f=e.style,d=e.className,p=e.outlineStyle,g=e.onStart,v=e.onEnd,y=e.onSpeechStart,m=e.onSpeechEnd,b=e.onResult,w=e.onError,x=e.onNoMatch,S=e.__rsInstance,_=t.useRef(null),E=a(t.useState(!1),2),L=E[0],M=E[1],O=a(A(s,u,S),2)[1],k=O.start,R=O.stop,C=O.subscribe,I=O.unsubscribe,P=function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.4;t=t?null===(e=Object.entries(t))||void 0===e?void 0:e.reduce((function(t,e){var n=a(e,2),r=n[0],i=n[1];return o({},r.toLowerCase(),i)}),{}):{};var r=function(e){var r=new bt(Object.keys(t),{includeScore:!0,ignoreLocation:!0}).search(e).filter((function(t){return t.score<n}));if(null!=r&&r.length){var i,o,s=r[0].item.toLowerCase();return null===(i=(o=t)[s])||void 0===i?void 0:i.call(o,e)}return null};return r}(i),N=function t(e){D(),G(),I("start",V),I("end",t),I("speechstart",W),I("speechend",H),I("result",Y),I("error",B),I("nomatch",J),v&&v(e)},$=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=t.useRef(-1),i=t.useCallback((function(){clearTimeout(r.current),r.current=-1}),[]),o=t.useCallback((function(){i(),r.current=setTimeout(e,n)}),[e,n,i]);return t.useEffect((function(){return i}),[i]),[o,i]}(N,l),T=a($,2),F=T[0],D=T[1],U=function(){try{M(!0),C("start",V),C("end",N),C("speechstart",W),C("speechend",H),C("result",Y),C("error",B),C("nomatch",J),k()}catch(t){B(t)}},G=function(){try{M(!1),R()}catch(t){w&&w(t)}},q=function(){U()},z=function(){!d&&p&&(_.current.style.outline=p)},K=function(){!d&&p&&(_.current.style.outline="none")},V=function(t){F(),g&&g(t)},W=function(t){D(),y&&y(t)},H=function(t){F(),m&&m(t)},Y=function(t,e){D(),G(),P(e),b&&b(e,t)},B=function(t){G(),w&&w(t)},J=function(t){D(),G(),x&&x(t)};return function(e){return j.isSupported?function(t){return"function"==typeof t}(e)?e(U,G,L):t.isValidElement(e)?t.cloneElement(e,c({},!L&&{onClick:q})):r.default.createElement("button",{"data-testid":"__vocal-root__",ref:_,role:"button","aria-label":h,style:d?null:c({width:24,height:24,background:"none",border:"none",padding:0,cursor:L?"default":"pointer"},f),className:d,onFocus:z,onBlur:K,onClick:q},r.default.createElement(wt,{isActive:L,iconColor:"#aaa"})):null}(n)};xt.propTypes={commands:i.default.objectOf(i.default.func),lang:i.default.string,grammars:i.default.object,timeout:i.default.number,ariaLabel:i.default.string,style:i.default.object,className:i.default.string,outlineStyle:i.default.string,onStart:i.default.func,onEnd:i.default.func,onSpeechStart:i.default.func,onSpeechEnd:i.default.func,onResult:i.default.func,onError:i.default.func,onNoMatch:i.default.func},xt.defaultProps={commands:null,lang:"en-US",grammars:null,timeout:3e3,ariaLabel:"start recognition",style:null,className:null,outlineStyle:"2px solid",onStart:null,onEnd:null,onSpeechStart:null,onSpeechEnd:null,onResult:null,onError:null,onNoMatch:null};var St=j.isSupported;exports.default=xt,exports.isSupported=St,exports.useVocal=A;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbIi4uL25vZGVfbW9kdWxlcy9AdW50ZW1wcy92b2NhbC9kaXN0L2luZGV4LmVzLmpzIiwiLi4vbm9kZV9tb2R1bGVzL0B1bnRlbXBzL3V0aWxzL2Rpc3QvZXNtL2Z1bmN0aW9uL2lzRnVuY3Rpb24uanMiLCIuLi9zcmMvaG9va3MvdXNlVm9jYWwuanMiLCIuLi9ub2RlX21vZHVsZXMvZnVzZS5qcy9kaXN0L2Z1c2UuZXNtLmpzIiwiLi4vc3JjL2hvb2tzL3VzZUNvbW1hbmRzLmpzIiwiLi4vc3JjL2NvbXBvbmVudHMvSWNvbi5qcyIsIi4uL3NyYy9jb21wb25lbnRzL1ZvY2FsLmpzIiwiLi4vc3JjL2hvb2tzL3VzZVRpbWVvdXQuanMiLCIuLi9zcmMvaW5kZXguanMiXSwic291cmNlc0NvbnRlbnQiOlsidmFyIHQ9ZnVuY3Rpb24odCxlLHIpe3JldHVybiB0KHI9e3BhdGg6ZSxleHBvcnRzOnt9LHJlcXVpcmU6ZnVuY3Rpb24odCxlKXtyZXR1cm4gZnVuY3Rpb24oKXt0aHJvdyBuZXcgRXJyb3IoXCJEeW5hbWljIHJlcXVpcmVzIGFyZSBub3QgY3VycmVudG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