@tanay-wispr/webflow-package 5.1.1 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
- "use strict";(()=>{async function he(){let C=()=>document.querySelector('.w--tab-active [demo-element="input"]'),n=C(),p=document.querySelector('[demo-element="gradient"]'),b=()=>document.querySelector(".wd_pill-wrap"),x=()=>document.querySelector(".wd_pill"),v=()=>x()?.querySelector(".wd_pill-lottie-wrap"),ee=document.querySelectorAll('[demo-element="start-recording"]'),te=document.querySelectorAll('[demo-element="stop-recording"]'),le=new Audio("https://dl.dropbox.com/scl/fi/zv8278qh9ovwq0r89rch1/dictation-start.wav?rlkey=pk241hf4c8qv7780qsq2m4cgv&st=wgpy7vop&dl=0"),ge=new Audio("https://dl.dropbox.com/scl/fi/4mkbgr7om46imcp0l86yd/dictation-stop.wav?rlkey=4t5uwvg9kufphlu58natjn43t&st=9or4oqr0&dl=0");function we(e){let r=document.getSelection();return r.rangeCount>0&&e.contains(r.focusNode)?r.getRangeAt(0):null}function be(e,r,s){s.deleteContents();let t=document.createElement("div");t.innerHTML=r;let o=document.createDocumentFragment();for(;t.firstChild;)o.appendChild(t.firstChild);s.insertNode(o),s.collapse(!1);let u=document.getSelection();u.removeAllRanges(),u.addRange(s)}function $(e){e.dataset.isPlaceholder==="true"?(e.classList.remove("cursor-after"),e.classList.add("cursor-before"),e.style.color="#1a1a1a80"):(e.classList.remove("cursor-before"),e.classList.add("cursor-after"),e.style.color="#1a1a1a")}let J=()=>{ee.forEach(e=>{e&&(e.style.display="flex")}),document.querySelectorAll('[demo-element="start-recording-text"]').forEach(e=>{e&&(e.style.display="block")})},G=()=>{ee.forEach(e=>{e&&(e.style.display="none")}),document.querySelectorAll('[demo-element="start-recording-text"]').forEach(e=>{e&&(e.style.display="none")})},ve=()=>{te.forEach(e=>{e&&(e.style.display="flex")}),document.querySelectorAll('[demo-element="stop-recording-text"]').forEach(e=>{e&&(e.style.display="block")})},j=()=>{te.forEach(e=>{e&&(e.style.display="none")}),document.querySelectorAll('[demo-element="stop-recording-text"]').forEach(e=>{e&&(e.style.display="none")})},z=window.matchMedia("(min-width: 992px)").matches,y=null,d=null,ce=[],_=!1,W=!1,K=!0,V=!0,l=null,I=null,Y=null,Z=null,a=null,B=null,S=null,P=0,k=[],oe=1024,Q=16e3,R=[],F=!1,M=null,re=!1,L=null,T=!1;navigator.mediaDevices.getUserMedia({audio:!0}).then(e=>{y=e,e.getAudioTracks().forEach(r=>r.enabled=!1),V=!1}).catch(e=>{console.error("Initial microphone permission denied:",e),V=!1,alert("Please enable microphone access in your browser settings to continue."),G()}),p&&(p.style.opacity="0",p.style.transition="opacity 0.3s ease"),j(),navigator.userAgent.toLowerCase().includes("firefox")&&(document.querySelectorAll("[wd-para-div]").forEach(e=>{e.style.display="none"}),document.querySelectorAll("[wd-start-stop-button-div]").forEach(e=>{e.style.display="block"})),z&&n&&n.focus({preventScroll:!0}),document.querySelectorAll('[demo-element="input"]').forEach((e,r)=>{e.classList.add("cursor-before"),e.dataset.isFirstRecording="true",e.dataset.placeholderText=e.textContent.trim(),e.dataset.placeholderHtml=e.innerHTML,e.dataset.isPlaceholder="true",e.addEventListener("beforeinput",()=>{e.dataset.isPlaceholder==="true"&&(e.innerHTML=""),e.dataset.isPlaceholder="false",$(e)}),e.addEventListener("input",()=>{if(e.textContent.trim()===""){e.innerHTML=e.dataset.placeholderHtml,e.dataset.isPlaceholder="true";let s=document.createRange();s.setStart(e,0),s.collapse(!0);let t=window.getSelection();t.removeAllRanges(),t.addRange(s)}$(e)}),e.addEventListener("focus",()=>{}),e.addEventListener("blur",()=>{e.textContent.trim()===""&&(e.innerHTML=e.dataset.placeholderHtml,e.dataset.isPlaceholder="true",e.dataset.isFirstRecording="true",$(e))}),e.addEventListener("mousedown",s=>{if(e.dataset.isPlaceholder==="true"){s.preventDefault();let t=document.createRange();t.setStart(e,0),t.collapse(!0);let o=window.getSelection();o.removeAllRanges(),o.addRange(t)}}),e.addEventListener("keydown",s=>{if(e.dataset.isPlaceholder==="true"&&["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(s.key)){s.preventDefault();let t=document.createRange();t.setStart(e,0),t.collapse(!0);let o=window.getSelection();o.removeAllRanges(),o.addRange(t)}})});let se=new MutationObserver(()=>{de()});se.observe(n,{childList:!0,subtree:!0,characterData:!0}),ue().catch(e=>{console.error("Initial token generation failed:",e)});let ne,Se=e=>new Promise((r,s)=>{let t=new FileReader;t.onloadend=()=>{typeof t.result=="string"?r(t.result.split(",")[1]):s(new Error("Failed to convert blob to base64"))},t.onerror=s,t.readAsDataURL(e)}),ke=async()=>{let r=k.length*1*2+44,s=new ArrayBuffer(r),t=new DataView(s),o=0,u=(f,g,h)=>{for(let m=0;m<h.length;m++)f.setUint8(g+m,h.charCodeAt(m))};u(t,0,"RIFF"),o+=4,t.setUint32(o,36+k.length*1*2,!0),o+=4,u(t,o,"WAVE"),o+=4,u(t,o,"fmt "),o+=4,t.setUint32(o,16,!0),o+=4,t.setUint16(o,1,!0),o+=2,t.setUint16(o,1,!0),o+=2,t.setUint32(o,Q,!0),o+=4,t.setUint32(o,Q*1*2,!0),o+=4,t.setUint16(o,1*2,!0),o+=2,t.setUint16(o,16,!0),o+=2,u(t,o,"data"),o+=4,t.setUint32(o,k.length*1*2,!0),o+=4;for(let f=0;f<k.length;f++)t.setInt16(o,k[f],!0),o+=2;return new Blob([t],{type:"audio/wav"})};function Le(){if(!F||R.length===0)return;console.log(`Flushing ${R.length} buffered audio chunks...`),R.forEach(r=>{try{a&&a.readyState===WebSocket.OPEN&&a.send(JSON.stringify(r))}catch(s){console.error(`Error sending buffered chunk ${r.position}:`,s)}});let e=M?Date.now()-M:0;console.log(`Buffer flushed! Buffering lasted ${e}ms`),R=[],F=!1,M=null}let de=()=>{n&&(n.scrollHeight>n.clientHeight?n.style.overflowY="auto":n.style.overflowY="visible")};async function ue(){try{let e=await fetch("https://api.wisprflow.ai/api/v1/dash/webflow_demo/generate_token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:"webflow_demo"})});if(!e.ok)throw new Error(`Token generation failed with status: ${e.status}`);let r=await e.json();return localStorage.setItem("accessToken",r.access_token),localStorage.setItem("tokenExpiration",(Date.now()+r.expires_in*1e3).toString()),r.access_token}catch(e){if(console.error("Token generation failed:",e),n||(n=C()),!n)return;throw document.querySelectorAll('[demo-element="input"]').forEach(r=>{r.innerHTML='Our servers are busy processing requests right now. <a href="/get-started" class="text-color-primary text-weight-medium">Try our desktop app instead.</a>',r.removeAttribute("contenteditable")}),n.classList.remove("cursor-before","cursor-after"),G(),K=!1,e}}async function fe(){let e=localStorage.getItem("tokenExpiration");return!e||Date.now()>=parseInt(e)?await ue():localStorage.getItem("accessToken")}async function Te(){a&&a.readyState===WebSocket.CLOSED&&(a=null),a&&(a.readyState===WebSocket.OPEN||a.readyState===WebSocket.CONNECTING)&&(a.onclose=null,a.close(),a=null);let e=await fe(),r=`wss://api.wisprflow.ai/api/v1/dash/client_ws?client_key=Bearer ${e}`;console.log("Connecting to WebSocket"),a=new WebSocket(r),a.onopen=()=>{let t=new URLSearchParams(window.location.search).get("type")==="email"?"email":"other";a.send(JSON.stringify({type:"auth",access_token:`Bearer ${e}`,context:{app:{type:t}}}))},a.onmessage=s=>{try{let t=JSON.parse(s.data);if(t.status==="error"||t.status==="auth_error"){console.error("WebSocket error:",t),N();return}if(t.status==="text"&&t.final){if(re=!0,L&&(clearTimeout(L),L=null),t.body&&t.body.text===null)console.log("Empty recording detected, skipping text display");else{let o="No speech detected.";t.body&&t.body.text?o=t.body.text:t.body.status==="formatted"?o=t.body.llm_text:t.body.status==="raw_transcript"&&(o=t.body.asr_text),me(o+"\xA0")}J(),j(),v()?.classList.remove("show"),b()?.style.setProperty("opacity","0")}}catch(t){console.error("WebSocket message parsing error:",t),N()}},a.onclose=s=>{console.log("WebSocket closed:",s.code,s.reason),a=null,T=!1},a.onerror=s=>{console.error("WebSocket error:",s)}}async function Ae(){if(a&&a.readyState===WebSocket.CONNECTING){console.log("\u23F3 WebSocket already connecting, skipping duplicate call");return}try{T=!1,await Te();let e=0,r=50;for(;(!a||a.readyState!==WebSocket.OPEN)&&e<r;)await new Promise(s=>setTimeout(s,100)),e++;a&&a.readyState===WebSocket.OPEN?(T=!0,console.log("\u2705 WebSocket marked as ready for streaming")):(console.log("WebSocket connection failed, will use fallback"),T=!1)}catch(e){console.error("WebSocket background connection failed:",e),T=!1}}function N(){L&&(clearTimeout(L),L=null),Ee()}async function Ee(){try{console.log("Using Fetch API fallback with collected samples");let e=await ke(),r=await Se(e),s=await fe(),t=await fetch("https://api.wisprflow.ai/api/v1/dash/client_api",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:JSON.stringify({audio:r,properties:{language:""}})});if(!t.ok)throw new Error("Fallback server error");let o=await t.json();if(o.text===null){console.log("Empty fallback recording detected, skipping text display"),v()?.classList.remove("show"),b()?.style.setProperty("opacity","0"),J(),j();return}me(o.text+"\xA0"),v()?.classList.remove("show"),b()?.style.setProperty("opacity","0"),J(),j()}catch(e){if(console.error("Fallback also failed:",e),n||(n=C()),!n)return;document.querySelectorAll('[demo-element="input"]').forEach(r=>{r.innerHTML='Our servers are busy processing requests right now. <a href="/get-started" class="text-color-primary text-weight-medium">Try our desktop app instead.</a>',r.removeAttribute("contenteditable")}),n.classList.remove("cursor-before","cursor-after"),G(),K=!1,x()?.classList.remove("is-speaking"),v()?.classList.remove("show"),b()?.style.setProperty("opacity","0")}}async function Ce(){try{return y&&y.getAudioTracks().length>0?y.getAudioTracks().forEach(e=>e.enabled=!0):y=await navigator.mediaDevices.getUserMedia({audio:!0}),d=new MediaRecorder(y),d.ondataavailable=e=>{ce.push(e.data)},d.onstop=async()=>{y.getTracks().forEach(e=>{e.enabled=!1}),d=null},!0}catch(e){return console.error("Microphone access error:",e),(e.name==="NotAllowedError"||e.name==="PermissionDeniedError")&&alert("Please enable microphone access in your browser settings to continue."),!1}}function me(e,r=!1){if(e=e.replace(/\n/g,"<br>"),e=e.replace(/<br>(?=\s*<\/?(?:ul|ol|li))|(?<=<\/?(?:ul|ol|li)>\s*)<br>/gi,""),!n)return;n.dataset.isPlaceholder==="true"&&(n.innerHTML=""),n.dataset.isPlaceholder="false",n.classList.remove("no-cursor");let s=we(n);if(s?be(n,e,s):n.textContent.trim()===""?n.innerHTML=e:n.innerHTML+=e,de(),n.dataset.previousText=n.textContent,n.dataset.isFirstRecording==="true"&&(n.classList.remove("cursor-before"),n.classList.add("cursor-after"),n.dataset.isFirstRecording="false"),typeof posthog<"u"){let o=document.querySelector(".w-tab-link.w--current"),u=o?o.textContent.trim().toLowerCase().replace(/\s+/g,"_"):"Unknown";posthog.capture("demo_transcription_completed",{transcribed_text:e,tab_name:u})}document.querySelectorAll(".wd-tab-content-bottom").forEach(o=>{o.style.display="flex"}),$(n),J()}async function pe(e=!1){if(n||(n=C()),!n)return;document.querySelectorAll(".wd-tab-link").forEach(o=>{o.classList.contains("w--current")||o.classList.add("pointer-events-none")}),R=[],F=!1,M=null,P=0,Ae();let s=n.innerHTML||"";s&&!s.includes("Flow is listening")&&!s.includes("Converting...")&&!s.includes("Error")&&(n.dataset.previousText=s);let t=n.dataset.isFirstRecording==="true";n.classList.add("no-cursor");try{le.currentTime=0,le.play()}catch(o){console.error("Error playing start dictation sound:",o)}if(!d&&!await Ce()){n.dataset.previousText?n.innerHTML=n.dataset.previousText:n.innerHTML="",n.classList.remove("no-cursor");return}if(d.state==="inactive"){ce=[],d.start(),_=!0,k=[],P=0,l||(l=new AudioContext),B=l.createMediaStreamSource(y),S=l.createScriptProcessor(oe,1,1),S.onaudioprocess=async f=>{let g=f.inputBuffer.getChannelData(0),h=Math.ceil(oe*Q/l.sampleRate),m=new OfflineAudioContext(1,h,Q),q=l.createBuffer(1,g.length,l.sampleRate);q.copyToChannel(g,0);let D=m.createBufferSource();D.buffer=q,D.connect(m.destination),D.start();let c=(await m.startRendering()).getChannelData(0),E=new Int16Array(c.length),O=0;for(let i=0;i<c.length;i++){let ie=Math.max(-1,Math.min(1,c[i]));E[i]=ie<0?ie*32768:ie*32767,k.push(E[i]),O+=c[i]*c[i]}let H=Math.sqrt(O/c.length),X=new Uint8Array(E.buffer),w="";for(let i=0;i<X.length;i++)w+=String.fromCharCode(X[i]);let Re=btoa(w);try{let i={type:"append",position:P,final:!1,audio_packets:{packets:[Re],volumes:[H],packet_duration:oe/l.sampleRate,audio_encoding:"wav",byte_encoding:"base64"}};T&&a&&a.readyState===WebSocket.OPEN?(F&&Le(),a.send(JSON.stringify(i))):(R.push(i),F=!0,M||(M=Date.now()),P===0&&console.log("WebSocket not ready yet, buffering audio chunks")),P++}catch(i){console.error("Error processing audio chunk:",i)}},B.connect(S),S.connect(l.destination),p&&(p.style.opacity="1"),b()?.style.setProperty("opacity","1"),x()?.classList.remove("is-speaking"),v()?.classList.remove("show");let o=document.querySelector(".wave-svg");o&&(o.style.opacity="1"),ne=p.animate([{transform:"scale(1)"},{transform:"scale(1.3)"},{transform:"scale(1)"}],{duration:1500,iterations:1/0}),G(),ve(),I=l.createAnalyser(),l.createMediaStreamSource(y).connect(I),I.fftSize=32,Y=new Uint8Array(I.frequencyBinCount),Z=setInterval(()=>{I.getByteFrequencyData(Y);let f=Y.reduce((A,c)=>A+c,0)/Y.length,g=8,h=0;f>g&&(h=Math.pow((f-g)/(255-g),1.5));let m=1+h*2,q=x();q&&(h>.06?q.classList.add("is-speaking"):q.classList.remove("is-speaking")),p.animate([{transform:`scale(${m})`}],{duration:300,fill:"forwards"});let D=document.querySelector(".wave-path");if(D){let A=40+h*300,c=Date.now()/1e3,E=w=>A*.3*Math.sin(w/1440*Math.PI*2+c*.8),O=w=>A*.2*Math.sin(w/720*Math.PI*2+c*1.2),H=w=>A*.1*Math.sin(w/360*Math.PI*2+c*1.8),X=`
1
+ "use strict";(()=>{async function ge(){let h=()=>document.querySelector('.w--tab-active [demo-element="input"]'),n=h(),p=document.querySelector('[demo-element="gradient"]'),v=()=>document.querySelector(".wd_pill-wrap"),x=()=>document.querySelector(".wd_pill"),S=()=>x()?.querySelector(".wd_pill-lottie-wrap"),ee=document.querySelectorAll('[demo-element="start-recording"]'),te=document.querySelectorAll('[demo-element="stop-recording"]'),le=new Audio("https://dl.dropbox.com/scl/fi/zv8278qh9ovwq0r89rch1/dictation-start.wav?rlkey=pk241hf4c8qv7780qsq2m4cgv&st=wgpy7vop&dl=0"),he=new Audio("https://dl.dropbox.com/scl/fi/4mkbgr7om46imcp0l86yd/dictation-stop.wav?rlkey=4t5uwvg9kufphlu58natjn43t&st=9or4oqr0&dl=0");function we(e){let r=document.getSelection();return r.rangeCount>0&&e.contains(r.focusNode)?r.getRangeAt(0):null}function be(e,r,s){s.deleteContents();let t=document.createElement("div");t.innerHTML=r;let o=document.createDocumentFragment();for(;t.firstChild;)o.appendChild(t.firstChild);s.insertNode(o),s.collapse(!1);let u=document.getSelection();u.removeAllRanges(),u.addRange(s)}function $(e){e.dataset.isPlaceholder==="true"?(e.classList.remove("cursor-after"),e.classList.add("cursor-before"),e.style.color="#1a1a1a80"):(e.classList.remove("cursor-before"),e.classList.add("cursor-after"),e.style.color="#1a1a1a")}let J=()=>{ee.forEach(e=>{e&&(e.style.display="flex")}),document.querySelectorAll('[demo-element="start-recording-text"]').forEach(e=>{e&&(e.style.display="block")})},G=()=>{ee.forEach(e=>{e&&(e.style.display="none")}),document.querySelectorAll('[demo-element="start-recording-text"]').forEach(e=>{e&&(e.style.display="none")})},ve=()=>{te.forEach(e=>{e&&(e.style.display="flex")}),document.querySelectorAll('[demo-element="stop-recording-text"]').forEach(e=>{e&&(e.style.display="block")})},j=()=>{te.forEach(e=>{e&&(e.style.display="none")}),document.querySelectorAll('[demo-element="stop-recording-text"]').forEach(e=>{e&&(e.style.display="none")})},z=window.matchMedia("(min-width: 992px)").matches,y=null,d=null,ce=[],_=!1,W=!1,K=!0,V=!0,l=null,I=null,Y=null,Z=null,a=null,B=null,k=null,P=0,L=[],oe=1024,Q=16e3,R=[],F=!1,M=null,re=!1,T=null,E=!1;navigator.mediaDevices.getUserMedia({audio:!0}).then(e=>{y=e,e.getAudioTracks().forEach(r=>r.enabled=!1),V=!1}).catch(e=>{console.error("Initial microphone permission denied:",e),V=!1,alert("Please enable microphone access in your browser settings to continue."),G()}),p&&(p.style.opacity="0",p.style.transition="opacity 0.3s ease"),j(),navigator.userAgent.toLowerCase().includes("firefox")&&(document.querySelectorAll("[wd-para-div]").forEach(e=>{e.style.display="none"}),document.querySelectorAll("[wd-start-stop-button-div]").forEach(e=>{e.style.display="block"})),z&&n&&n.focus({preventScroll:!0}),document.querySelectorAll('[demo-element="input"]').forEach((e,r)=>{e.classList.add("cursor-before"),e.dataset.isFirstRecording="true",e.dataset.placeholderText=e.textContent.trim(),e.dataset.placeholderHtml=e.innerHTML,e.dataset.isPlaceholder="true",e.addEventListener("beforeinput",()=>{e.dataset.isPlaceholder==="true"&&(e.innerHTML=""),e.dataset.isPlaceholder="false",$(e)}),e.addEventListener("input",()=>{if(e.textContent.trim()===""){e.innerHTML=e.dataset.placeholderHtml,e.dataset.isPlaceholder="true";let s=document.createRange();s.setStart(e,0),s.collapse(!0);let t=window.getSelection();t.removeAllRanges(),t.addRange(s)}$(e)}),e.addEventListener("focus",()=>{}),e.addEventListener("blur",()=>{e.textContent.trim()===""&&(e.innerHTML=e.dataset.placeholderHtml,e.dataset.isPlaceholder="true",e.dataset.isFirstRecording="true",$(e))}),e.addEventListener("mousedown",s=>{if(e.dataset.isPlaceholder==="true"){s.preventDefault();let t=document.createRange();t.setStart(e,0),t.collapse(!0);let o=window.getSelection();o.removeAllRanges(),o.addRange(t)}}),e.addEventListener("keydown",s=>{if(e.dataset.isPlaceholder==="true"&&["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(s.key)){s.preventDefault();let t=document.createRange();t.setStart(e,0),t.collapse(!0);let o=window.getSelection();o.removeAllRanges(),o.addRange(t)}})});let se=new MutationObserver(()=>{de()});se.observe(n,{childList:!0,subtree:!0,characterData:!0}),ue().catch(e=>{console.error("Initial token generation failed:",e)});let ne,Se=e=>new Promise((r,s)=>{let t=new FileReader;t.onloadend=()=>{typeof t.result=="string"?r(t.result.split(",")[1]):s(new Error("Failed to convert blob to base64"))},t.onerror=s,t.readAsDataURL(e)}),ke=async()=>{let r=L.length*1*2+44,s=new ArrayBuffer(r),t=new DataView(s),o=0,u=(f,w,g)=>{for(let m=0;m<g.length;m++)f.setUint8(w+m,g.charCodeAt(m))};u(t,0,"RIFF"),o+=4,t.setUint32(o,36+L.length*1*2,!0),o+=4,u(t,o,"WAVE"),o+=4,u(t,o,"fmt "),o+=4,t.setUint32(o,16,!0),o+=4,t.setUint16(o,1,!0),o+=2,t.setUint16(o,1,!0),o+=2,t.setUint32(o,Q,!0),o+=4,t.setUint32(o,Q*1*2,!0),o+=4,t.setUint16(o,1*2,!0),o+=2,t.setUint16(o,16,!0),o+=2,u(t,o,"data"),o+=4,t.setUint32(o,L.length*1*2,!0),o+=4;for(let f=0;f<L.length;f++)t.setInt16(o,L[f],!0),o+=2;return new Blob([t],{type:"audio/wav"})};function Le(){if(!F||R.length===0)return;console.log(`Flushing ${R.length} buffered audio chunks...`),R.forEach(r=>{try{a&&a.readyState===WebSocket.OPEN&&a.send(JSON.stringify(r))}catch(s){console.error(`Error sending buffered chunk ${r.position}:`,s)}});let e=M?Date.now()-M:0;console.log(`Buffer flushed! Buffering lasted ${e}ms`),R=[],F=!1,M=null}let de=()=>{n&&(n.scrollHeight>n.clientHeight?n.style.overflowY="auto":n.style.overflowY="visible")};async function ue(){try{let e=await fetch("https://api.wisprflow.ai/api/v1/dash/webflow_demo/generate_token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:"webflow_demo"})});if(!e.ok)throw new Error(`Token generation failed with status: ${e.status}`);let r=await e.json();return localStorage.setItem("accessToken",r.access_token),localStorage.setItem("tokenExpiration",(Date.now()+r.expires_in*1e3).toString()),r.access_token}catch(e){if(console.error("Token generation failed:",e),n||(n=h()),!n)return;throw document.querySelectorAll('[demo-element="input"]').forEach(r=>{r.innerHTML='Our servers are busy processing requests right now. <a href="/get-started" class="text-color-primary text-weight-medium">Try our desktop app instead.</a>',r.removeAttribute("contenteditable")}),n.classList.remove("cursor-before","cursor-after"),G(),K=!1,e}}async function fe(){let e=localStorage.getItem("tokenExpiration");return!e||Date.now()>=parseInt(e)?await ue():localStorage.getItem("accessToken")}async function Te(){a&&a.readyState===WebSocket.CLOSED&&(a=null),a&&(a.readyState===WebSocket.OPEN||a.readyState===WebSocket.CONNECTING)&&(a.onclose=null,a.close(),a=null);let e=await fe(),r=`wss://api.wisprflow.ai/api/v1/dash/client_ws?client_key=Bearer ${e}`;console.log("Connecting to WebSocket"),a=new WebSocket(r),a.onopen=()=>{let t=new URLSearchParams(window.location.search).get("type")==="email"?"email":"other";a.send(JSON.stringify({type:"auth",access_token:`Bearer ${e}`,context:{app:{type:t}}}))},a.onmessage=s=>{try{let t=JSON.parse(s.data);if(t.status==="error"||t.status==="auth_error"){console.error("WebSocket error:",t),N();return}if(t.status==="text"&&t.final){if(re=!0,T&&(clearTimeout(T),T=null),t.body&&t.body.text===null)console.log("Empty recording detected, skipping text display");else{let o="No speech detected.";t.body&&t.body.text?o=t.body.text:t.body.status==="formatted"?o=t.body.llm_text:t.body.status==="raw_transcript"&&(o=t.body.asr_text),me(o+"\xA0")}J(),j(),S()?.classList.remove("show"),v()?.style.setProperty("opacity","0")}}catch(t){console.error("WebSocket message parsing error:",t),N()}},a.onclose=s=>{console.log("WebSocket closed:",s.code,s.reason),a=null,E=!1},a.onerror=s=>{console.error("WebSocket error:",s)}}async function Ee(){if(a&&a.readyState===WebSocket.CONNECTING){console.log("\u23F3 WebSocket already connecting, skipping duplicate call");return}try{E=!1,await Te();let e=0,r=50;for(;(!a||a.readyState!==WebSocket.OPEN)&&e<r;)await new Promise(s=>setTimeout(s,100)),e++;a&&a.readyState===WebSocket.OPEN?(E=!0,console.log("\u2705 WebSocket marked as ready for streaming")):(console.log("WebSocket connection failed, will use fallback"),E=!1)}catch(e){console.error("WebSocket background connection failed:",e),E=!1}}function N(){T&&(clearTimeout(T),T=null),Ae()}async function Ae(){try{console.log("Using Fetch API fallback with collected samples");let e=await ke(),r=await Se(e),s=await fe(),t=await fetch("https://api.wisprflow.ai/api/v1/dash/client_api",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:JSON.stringify({audio:r,properties:{language:""}})});if(!t.ok)throw new Error("Fallback server error");let o=await t.json();if(o.text===null){console.log("Empty fallback recording detected, skipping text display"),S()?.classList.remove("show"),v()?.style.setProperty("opacity","0"),J(),j();return}me(o.text+"\xA0"),S()?.classList.remove("show"),v()?.style.setProperty("opacity","0"),J(),j()}catch(e){if(console.error("Fallback also failed:",e),n||(n=h()),!n)return;document.querySelectorAll('[demo-element="input"]').forEach(r=>{r.innerHTML='Our servers are busy processing requests right now. <a href="/get-started" class="text-color-primary text-weight-medium">Try our desktop app instead.</a>',r.removeAttribute("contenteditable")}),n.classList.remove("cursor-before","cursor-after"),G(),K=!1,x()?.classList.remove("is-speaking"),S()?.classList.remove("show"),v()?.style.setProperty("opacity","0")}}async function Ce(){try{return y&&y.getAudioTracks().length>0?y.getAudioTracks().forEach(e=>e.enabled=!0):y=await navigator.mediaDevices.getUserMedia({audio:!0}),d=new MediaRecorder(y),d.ondataavailable=e=>{ce.push(e.data)},d.onstop=async()=>{y.getTracks().forEach(e=>{e.enabled=!1}),d=null},!0}catch(e){return console.error("Microphone access error:",e),(e.name==="NotAllowedError"||e.name==="PermissionDeniedError")&&alert("Please enable microphone access in your browser settings to continue."),!1}}function me(e,r=!1){if(e=e.replace(/\n/g,"<br>"),e=e.replace(/<br>(?=\s*<\/?(?:ul|ol|li))|(?<=<\/?(?:ul|ol|li)>\s*)<br>/gi,""),!n)return;n.dataset.isPlaceholder==="true"&&(n.innerHTML=""),n.dataset.isPlaceholder="false",n.classList.remove("no-cursor");let s=we(n);if(s?be(n,e,s):n.textContent.trim()===""?n.innerHTML=e:n.innerHTML+=e,de(),n.dataset.previousText=n.textContent,n.dataset.isFirstRecording==="true"&&(n.classList.remove("cursor-before"),n.classList.add("cursor-after"),n.dataset.isFirstRecording="false"),typeof posthog<"u"){let o=document.querySelector(".w-tab-link.w--current"),u=o?o.textContent.trim().toLowerCase().replace(/\s+/g,"_"):"Unknown";posthog.capture("demo_transcription_completed",{transcribed_text:e,tab_name:u})}document.querySelectorAll(".wd-tab-content-bottom").forEach(o=>{o.style.display="flex"}),$(n),J()}async function pe(e=!1){if(n||(n=h()),!n)return;document.querySelectorAll(".wd-tab-link").forEach(o=>{o.classList.contains("w--current")||o.classList.add("pointer-events-none")}),R=[],F=!1,M=null,P=0,Ee();let s=n.innerHTML||"";s&&!s.includes("Flow is listening")&&!s.includes("Converting...")&&!s.includes("Error")&&(n.dataset.previousText=s);let t=n.dataset.isFirstRecording==="true";n.classList.add("no-cursor");try{le.currentTime=0,le.play()}catch(o){console.error("Error playing start dictation sound:",o)}if(!d&&!await Ce()){n.dataset.previousText?n.innerHTML=n.dataset.previousText:n.innerHTML="",n.classList.remove("no-cursor");return}if(d.state==="inactive"){ce=[],d.start(),_=!0,L=[],P=0,l||(l=new AudioContext),B=l.createMediaStreamSource(y),k=l.createScriptProcessor(oe,1,1),k.onaudioprocess=async f=>{let w=f.inputBuffer.getChannelData(0),g=Math.ceil(oe*Q/l.sampleRate),m=new OfflineAudioContext(1,g,Q),q=l.createBuffer(1,w.length,l.sampleRate);q.copyToChannel(w,0);let D=m.createBufferSource();D.buffer=q,D.connect(m.destination),D.start();let c=(await m.startRendering()).getChannelData(0),C=new Int16Array(c.length),O=0;for(let i=0;i<c.length;i++){let ie=Math.max(-1,Math.min(1,c[i]));C[i]=ie<0?ie*32768:ie*32767,L.push(C[i]),O+=c[i]*c[i]}let H=Math.sqrt(O/c.length),X=new Uint8Array(C.buffer),b="";for(let i=0;i<X.length;i++)b+=String.fromCharCode(X[i]);let Re=btoa(b);try{let i={type:"append",position:P,final:!1,audio_packets:{packets:[Re],volumes:[H],packet_duration:oe/l.sampleRate,audio_encoding:"wav",byte_encoding:"base64"}};E&&a&&a.readyState===WebSocket.OPEN?(F&&Le(),a.send(JSON.stringify(i))):(R.push(i),F=!0,M||(M=Date.now()),P===0&&console.log("WebSocket not ready yet, buffering audio chunks")),P++}catch(i){console.error("Error processing audio chunk:",i)}},B.connect(k),k.connect(l.destination),p&&(p.style.opacity="1"),v()?.style.setProperty("opacity","1"),x()?.classList.remove("is-speaking"),S()?.classList.remove("show");let o=document.querySelector(".wave-svg");o&&(o.style.opacity="1"),ne=p.animate([{transform:"scale(1)"},{transform:"scale(1.3)"},{transform:"scale(1)"}],{duration:1500,iterations:1/0}),G(),ve(),I=l.createAnalyser(),l.createMediaStreamSource(y).connect(I),I.fftSize=32,Y=new Uint8Array(I.frequencyBinCount),Z=setInterval(()=>{I.getByteFrequencyData(Y);let f=Y.reduce((A,c)=>A+c,0)/Y.length,w=8,g=0;f>w&&(g=Math.pow((f-w)/(255-w),1.5));let m=1+g*2,q=x();q&&(g>.06?q.classList.add("is-speaking"):q.classList.remove("is-speaking")),p.animate([{transform:`scale(${m})`}],{duration:300,fill:"forwards"});let D=document.querySelector(".wave-path");if(D){let A=40+g*300,c=Date.now()/1e3,C=b=>A*.3*Math.sin(b/1440*Math.PI*2+c*.8),O=b=>A*.2*Math.sin(b/720*Math.PI*2+c*1.2),H=b=>A*.1*Math.sin(b/360*Math.PI*2+c*1.8),X=`
2
2
  M0,160
3
- C120,${100+E(120)}
3
+ C120,${100+C(120)}
4
4
  240,${220+O(240)}
5
5
  480,${160+H(480)}
6
- C720,${100+E(720)}
6
+ C720,${100+C(720)}
7
7
  900,${220+O(900)}
8
8
  1080,${160+H(1080)}
9
- C1260,${100+E(1260)}
9
+ C1260,${100+C(1260)}
10
10
  1440,${220+O(1440)}
11
11
  1440,${160+H(1440)}
12
12
  L1440,320 L0,320 Z
13
- `;D.setAttribute("d",X)}},50)}}async function ae(){try{ge.play()}catch(r){console.error("Error playing stop dictation sound:",r)}if(d&&d.state==="recording"){d.stop(),_=!1,p&&(p.style.opacity="0"),x()?.classList.remove("is-speaking"),b()?.style.setProperty("opacity","1"),v()?.classList.add("show");let r=document.querySelector(".wave-svg");r&&(r.style.opacity="0"),ne&&ne.cancel()}if(Z&&(clearInterval(Z),Z=null),l&&(l.close().catch(console.error),l=null),S&&(S.disconnect(),S=null),B&&(B.disconnect(),B=null),re=!1,T&&a&&a.readyState===WebSocket.OPEN)try{a.send(JSON.stringify({type:"commit",total_packets:P})),L=setTimeout(()=>{re||(console.log("WebSocket timeout, falling back to Fetch"),N())},4e3)}catch(r){console.error("WebSocket commit failed:",r),N()}else console.log("WebSocket not available, using Fetch fallback"),N();document.querySelectorAll(".wd-tab-link").forEach(r=>{r.classList.remove("pointer-events-none")})}let xe=100,U=null;document.addEventListener("keydown",e=>{console.log("Key pressed:",e.key),z&&e.key==="Control"&&!W&&K&&!_&&(e.preventDefault(),W=!0,U=setTimeout(()=>{W&&pe(!0)},xe))}),document.addEventListener("keyup",async e=>{z&&e.key==="Control"&&(W=!1,clearTimeout(U),_&&await ae())}),ee.forEach(e=>{e&&e.addEventListener("click",r=>{r.preventDefault(),!V&&K&&pe()})}),te.forEach(e=>{e&&e.addEventListener("click",async r=>{r.preventDefault(),!V&&await ae()})});async function ye(){W=!1,U&&(clearTimeout(U),U=null),_&&await ae(),x()?.classList.remove("is-speaking"),v()?.classList.remove("show"),b()?.style.setProperty("opacity","0")}function Pe(){let e=document.querySelector(".wd-tab-link.w--current");if(e){let r=new URL(window.location);e.getAttribute("app-type")==="email"?r.searchParams.set("type","email"):r.searchParams.delete("type"),window.history.replaceState({},"",r)}}document.addEventListener("click",e=>{e.target.closest(".wd-tab-link")&&(z&&setTimeout(()=>{let s=C();if(s&&(s.focus(),s.dataset.isPlaceholder==="false")){let t=document.createRange(),o=window.getSelection();t.selectNodeContents(s),t.collapse(!1),o.removeAllRanges(),o.addRange(t)}},250),setTimeout(()=>{let s=C();s&&s!==n&&(n=s,se.disconnect(),se.observe(n,{childList:!0,subtree:!0,characterData:!0}))},320),setTimeout(()=>{Pe()},100))}),window.addEventListener("blur",ye),document.addEventListener("visibilitychange",()=>{document.hidden&&ye()})}document.addEventListener("DOMContentLoaded",async function(){await he(),console.log("Web demo initialized successfully")});})();
13
+ `;D.setAttribute("d",X)}},50)}}async function ae(){try{he.play()}catch(r){console.error("Error playing stop dictation sound:",r)}if(d&&d.state==="recording"){d.stop(),_=!1,p&&(p.style.opacity="0"),x()?.classList.remove("is-speaking"),v()?.style.setProperty("opacity","1"),S()?.classList.add("show");let r=document.querySelector(".wave-svg");r&&(r.style.opacity="0"),ne&&ne.cancel()}if(Z&&(clearInterval(Z),Z=null),l&&(l.close().catch(console.error),l=null),k&&(k.disconnect(),k=null),B&&(B.disconnect(),B=null),re=!1,E&&a&&a.readyState===WebSocket.OPEN)try{a.send(JSON.stringify({type:"commit",total_packets:P})),T=setTimeout(()=>{re||(console.log("WebSocket timeout, falling back to Fetch"),N())},4e3)}catch(r){console.error("WebSocket commit failed:",r),N()}else console.log("WebSocket not available, using Fetch fallback"),N();document.querySelectorAll(".wd-tab-link").forEach(r=>{r.classList.remove("pointer-events-none")})}let xe=100,U=null;document.addEventListener("keydown",e=>{console.log("Key pressed:",e.key),z&&e.key==="Control"&&!W&&K&&!_&&(e.preventDefault(),W=!0,U=setTimeout(()=>{W&&pe(!0)},xe))}),document.addEventListener("keyup",async e=>{z&&e.key==="Control"&&(W=!1,clearTimeout(U),_&&await ae())}),ee.forEach(e=>{e&&e.addEventListener("click",r=>{r.preventDefault(),!V&&K&&pe()})}),te.forEach(e=>{e&&e.addEventListener("click",async r=>{r.preventDefault(),!V&&await ae()})});async function ye(){W=!1,U&&(clearTimeout(U),U=null),_&&await ae(),x()?.classList.remove("is-speaking"),S()?.classList.remove("show"),v()?.style.setProperty("opacity","0")}function Pe(){let e=document.querySelector(".wd-tab-link.w--current");if(e){let r=new URL(window.location);e.getAttribute("app-type")==="email"?r.searchParams.set("type","email"):r.searchParams.delete("type"),window.history.replaceState({},"",r)}}document.addEventListener("click",e=>{e.target.closest(".wd-tab-link")&&(z&&setTimeout(()=>{let s=h();if(s&&(s.focus(),s.dataset.isPlaceholder==="false")){let t=document.createRange(),o=window.getSelection();t.selectNodeContents(s),t.collapse(!1),o.removeAllRanges(),o.addRange(t)}},250),setTimeout(()=>{let s=h();s&&s!==n&&(n=s,se.disconnect(),se.observe(n,{childList:!0,subtree:!0,characterData:!0}))},320),setTimeout(()=>{Pe()},100))}),window.addEventListener("blur",ye),document.addEventListener("visibilitychange",()=>{document.hidden&&ye()})}document.addEventListener("DOMContentLoaded",async function(){await ge(),console.log("Web demo initialized successfully")});window.addEventListener("pageshow",h=>{h.persisted&&(console.log("Page restored from bfcache - reloading..."),location.reload())});})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanay-wispr/webflow-package",
3
- "version": "5.1.1",
3
+ "version": "5.1.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },