@tanay-wispr/webflow-package 5.0.17 → 5.1.0

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 re(){let P=document.querySelector('[demo-element="wrapper"]'),n=document.querySelector('[demo-element="input"]'),T=document.querySelector('[demo-element="gradient"]'),b=document.querySelectorAll('[demo-element="try-again"]'),h=document.querySelector('[demo-element="error-state"]'),g=document.querySelector('[demo-element="enable-microphone"]'),u=document.querySelector('[demo-element="start-recording"]'),S=document.querySelector('[demo-element="stop-recording"]'),D=document.querySelector('[demo-element="help-text-start"]'),o=document.querySelector('[demo-element="help-text-finish"]'),c=document.querySelector('[demo-element="help-text-processing"]'),f=document.querySelector('[data-form="next-btn"]'),s=document.querySelector('[demo-element="bottom-wrap"]'),a=document.querySelector('[demo-element="prompt-wrapper"]'),K=document.querySelector("[web-demo-close]"),U=new Audio("https://dl.dropbox.com/scl/fi/zv8278qh9ovwq0r89rch1/dictation-start.wav?rlkey=pk241hf4c8qv7780qsq2m4cgv&st=wgpy7vop&dl=0"),le=new Audio("https://dl.dropbox.com/scl/fi/4mkbgr7om46imcp0l86yd/dictation-stop.wav?rlkey=4t5uwvg9kufphlu58natjn43t&st=9or4oqr0&dl=0"),te=window.matchMedia("(min-width: 992px)").matches,v=null,p=null,H=[],A=!1,Q=null,X="",O=!1,q=!0,$=!0,_=!0,E=null,F=null,J=null,I=null,ee=!1;navigator.mediaDevices.getUserMedia({audio:!0}).then(e=>{e.getTracks().forEach(t=>t.stop()),_=!1,ye()}).catch(e=>{console.error("Initial microphone permission denied:",e),_=!1;try{navigator.permissions.query({name:"microphone"}).then(t=>{t.state==="denied"?(g&&(h.style.display="none",g.style.display="block"),s&&(s.style.display="none"),a&&(a.style.display="none"),u&&(u.style.display="none"),b.forEach(i=>{i.style.visibility="visible",i.style.pointerEvents="auto"})):console.log("Not showing microphone enablement UI, permission state is:",t.state)}).catch(t=>{console.error("Permissions API error:",t),ne(e)})}catch(t){console.error("Permissions API not supported:",t),ne(e)}});function ne(e){(e.name==="NotAllowedError"||e.name==="PermissionDeniedError")&&(g&&(h.style.display="none",g.style.display="block"),s&&(s.style.display="none"),a&&(a.style.display="none"),u&&(u.style.display="none"),b.forEach(t=>{t.style.visibility="visible",t.style.pointerEvents="auto"}))}T.style.opacity="0",T.style.transition="opacity 0.3s ease",n.classList.add("muted"),h.style.display="none",n.style.display="none",S&&(S.style.display="none"),o&&(o.style.display="none"),c&&(c.style.display="none"),f&&f.classList.add("animated"),g&&(g.style.display="none"),new MutationObserver(()=>{oe()}).observe(n,{childList:!0,subtree:!0,characterData:!0}),b.forEach(e=>{e.style.visibility="hidden",e.style.pointerEvents="none"}),setTimeout(()=>{s&&(s.style.opacity="1"),a&&(a.style.opacity="1")},1500),se().catch(e=>{console.error("Initial token generation failed:",e)});let L,ce=e=>new Promise((t,i)=>{let l=new FileReader;l.onloadend=()=>{typeof l.result=="string"?t(l.result.split(",")[1]):i(new Error("Failed to convert blob to base64"))},l.onerror=i,l.readAsDataURL(e)}),de=async e=>{let t=new AudioContext,i=await e.arrayBuffer(),l=await t.decodeAudioData(i),d=16e3,x=d/l.sampleRate,R=Math.floor(l.length*x),C=new OfflineAudioContext(1,R,d),B=C.createBufferSource();B.buffer=l,B.connect(C.destination),B.start(0);let w=await C.startRendering(),y=1,W=w.length*y*2+44,V=new ArrayBuffer(W),m=new DataView(V),r=0,k=(j,z,Z)=>{for(let G=0;G<Z.length;G++)j.setUint8(z+G,Z.charCodeAt(G))};k(m,0,"RIFF"),r+=4,m.setUint32(r,36+w.length*y*2,!0),r+=4,k(m,r,"WAVE"),r+=4,k(m,r,"fmt "),r+=4,m.setUint32(r,16,!0),r+=4,m.setUint16(r,1,!0),r+=2,m.setUint16(r,y,!0),r+=2,m.setUint32(r,d,!0),r+=4,m.setUint32(r,d*y*2,!0),r+=4,m.setUint16(r,y*2,!0),r+=2,m.setUint16(r,16,!0),r+=2,k(m,r,"data"),r+=4,m.setUint32(r,w.length*y*2,!0),r+=4;let ge=w.getChannelData(0);for(let j=0;j<w.length;j++){let z=ge[j],Z=z<0?z*32768:z*32767;m.setInt16(r,Z,!0),r+=2}return new Blob([m],{type:"audio/wav"})},oe=()=>{n&&(n.scrollHeight>n.clientHeight?n.style.overflowY="auto":n.style.overflowY="visible")};function ye(){s&&(s.style.opacity="1"),a&&(a.style.opacity="1")}async function se(){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 t=await e.json();return localStorage.setItem("accessToken",t.access_token),localStorage.setItem("tokenExpiration",(Date.now()+t.expires_in*1e3).toString()),t.access_token}catch(e){throw console.error("Token generation failed:",e),n.style.display="none",h.style.display="block",s&&(s.style.display="none"),a&&(a.style.display="none"),u&&(u.style.display="none"),q=!1,e}}async function ue(){let e=localStorage.getItem("tokenExpiration");return!e||Date.now()>=parseInt(e)?await se():localStorage.getItem("accessToken")}async function fe(){try{return v=await navigator.mediaDevices.getUserMedia({audio:!0}),p=new MediaRecorder(v),p.ondataavailable=e=>{H.push(e.data)},p.onstop=async()=>{try{let e=new Blob(H,{type:"audio/webm"});Q=await de(e),X=await ce(Q),await pe(),H=[],v.getTracks().forEach(t=>{t.stop()}),v=null,p=null}catch(e){console.error("Audio processing error:",e),v&&(v.getTracks().forEach(t=>t.stop()),v=null,p=null)}},!0}catch(e){return console.error("Microphone access error:",e),(e.name==="NotAllowedError"||e.name==="PermissionDeniedError")&&g&&(n.style.display="none",g.style.display="block"),!1}}async function pe(){try{let e=document.querySelector('[demo-element="spinner"]'),t=document.querySelector('[demo-element="start-recording"]'),i=document.querySelector('[demo-element="stop-recording"]'),l=document.querySelector('[demo-element="help-text-start"]'),d=document.querySelector('[demo-element="help-text-finish"]'),x=document.querySelector('[demo-element="help-text-processing"]');if(t&&(t.style.display="none"),i&&(i.style.display="flex"),l&&(l.style.display="none"),d&&(d.style.display="none"),x&&(x.style.display="flex"),$){if(n.innerHTML="",e){let y=e.cloneNode(!0);y.style.display="inline-block",y.style.verticalAlign="middle",y.classList.add("no-cursor"),n.appendChild(y)}n.classList.add("no-cursor")}else{if(n.dataset.previousText&&(n.innerHTML=n.dataset.previousText,n.appendChild(document.createTextNode(" ")),e)){let y=e.cloneNode(!0);y.style.display="inline-block",y.style.verticalAlign="middle",y.classList.add("no-cursor"),n.appendChild(y)}n.classList.add("no-cursor")}T.style.opacity="0",L&&L.cancel(),s&&(s.classList.add("pointer-events-none"),s.style.opacity="0.4");let R=await ue(),C=await fetch("https://api.wisprflow.ai/api/v1/dash/client_api",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${R}`},body:JSON.stringify({audio:X,properties:{language:""}})});if(!C.ok)throw new Error("Server error");let B=await C.json(),w=!$;me(B.text,w),$=!1,t&&(t.style.display="flex"),i&&(i.style.display="none"),l&&(l.style.display="block"),d&&(d.style.display="none"),x&&(x.style.display="none")}catch(e){console.error("Server error:",e),n.style.display="none",h.style.display="block",s&&(s.classList.remove("pointer-events-none"),s.style.opacity="",s.style.display="none"),a&&(a.style.display="none"),u&&(u.style.display="none"),q=!1,b.forEach(t=>{t.style.visibility="visible",t.style.pointerEvents="auto"}),p&&p.state==="recording"&&p.stop(),v&&(v.getTracks().forEach(t=>t.stop()),v=null,p=null),T.style.opacity="0",L&&L.cancel(),S&&(S.style.display="none"),o&&(o.style.display="none"),c&&(c.style.display="none")}}function me(e,t=!1){n.style.display="block",n.classList.remove("muted"),n.classList.remove("no-cursor");let i=n.dataset.previousText||"",l=t&&i?`${i} ${e}`:e;n.innerHTML=l,oe(),n.dataset.previousText=l,!t&&$&&typeof posthog<"u"&&posthog.capture("demo_transcription_completed",{transcribed_text:e}),a&&(a.style.display="none"),s&&(s.classList.remove("pointer-events-none"),s.style.opacity="1"),f&&(ee?f.classList.remove("animated"):setTimeout(()=>{f.classList.remove("animated"),ee=!0},1e3)),b.forEach(d=>{d.style.visibility="visible",d.style.pointerEvents="auto"}),u&&(u.style.display="flex"),D&&(D.style.display="block")}async function Y(e=!1){if(h.style.display==="block")return;try{U.currentTime=0,await U.play()}catch(i){console.error("Error playing start dictation sound:",i)}a&&(a.style.display="none"),n.style.display="block";let t=n.innerHTML||"";if(t&&!t.includes("Flow is listening")&&!t.includes("Converting...")&&!t.includes("Error")&&(n.dataset.previousText=t),n.dataset.previousText?(n.innerHTML=n.dataset.previousText,n.classList.add("no-cursor")):(n.innerHTML='Flow is listening<span class="typing-dots"></span>',n.classList.add("no-cursor")),!p&&!await fe()){n.dataset.previousText?n.innerHTML=n.dataset.previousText:n.innerHTML="",n.classList.remove("no-cursor");return}if(p.state==="inactive"){H=[],p.start(),A=!0,T.style.opacity="1";let i=document.querySelector(".wave-svg");i&&(i.style.opacity="1"),L=T.animate([{transform:"scale(1)"},{transform:"scale(1.3)"},{transform:"scale(1)"}],{duration:1500,iterations:1/0}),u&&(u.style.display="none"),S&&(S.style.display="flex"),D&&(D.style.display="none"),o&&(e?o.innerHTML='Release <span class="key-style">control</span> to see the output':o.innerHTML='<div class="pad-ver-4px">Press Finish to see the output<div>',o.style.display="block"),f&&f.classList.add("animated"),b.forEach(d=>{d.style.visibility="hidden",d.style.pointerEvents="none"}),E=new AudioContext,F=E.createAnalyser(),E.createMediaStreamSource(v).connect(F),F.fftSize=32,J=new Uint8Array(F.frequencyBinCount),I=setInterval(()=>{F.getByteFrequencyData(J);let d=J.reduce((w,y)=>w+y,0)/J.length,x=8,R=0;d>x&&(R=Math.pow((d-x)/(255-x),1.5));let C=1+R*2;T.animate([{transform:`scale(${C})`}],{duration:300,fill:"forwards"});let B=document.querySelector(".wave-path");if(B){let w=40+R*300,y=Date.now()/1e3,W=k=>w*.3*Math.sin(k/1440*Math.PI*2+y*.8),V=k=>w*.2*Math.sin(k/720*Math.PI*2+y*1.2),m=k=>w*.1*Math.sin(k/360*Math.PI*2+y*1.8),r=`
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=`
2
2
  M0,160
3
- C120,${100+W(120)}
4
- 240,${220+V(240)}
5
- 480,${160+m(480)}
6
- C720,${100+W(720)}
7
- 900,${220+V(900)}
8
- 1080,${160+m(1080)}
9
- C1260,${100+W(1260)}
10
- 1440,${220+V(1440)}
11
- 1440,${160+m(1440)}
3
+ C120,${100+E(120)}
4
+ 240,${220+O(240)}
5
+ 480,${160+H(480)}
6
+ C720,${100+E(720)}
7
+ 900,${220+O(900)}
8
+ 1080,${160+H(1080)}
9
+ C1260,${100+E(1260)}
10
+ 1440,${220+O(1440)}
11
+ 1440,${160+H(1440)}
12
12
  L1440,320 L0,320 Z
13
- `;B.setAttribute("d",r)}},50)}}function N(){try{le.play()}catch(e){console.error("Error playing stop dictation sound:",e)}if(p&&p.state==="recording"){p.stop(),A=!1,T.style.opacity="0";let e=document.querySelector(".wave-svg");e&&(e.style.opacity="0"),L&&L.cancel()}I&&(clearInterval(I),I=null),E&&(E.close().catch(console.error),E=null),o&&(o.style.display="none"),c&&(c.style.display="flex"),s&&(s.classList.add("pointer-events-none"),s.style.opacity="0.4")}let he=100,M=null;document.addEventListener("keydown",e=>{te&&e.key==="Control"&&!O&&q&&!A&&h.style.display!=="block"&&window.getComputedStyle(P).display!=="none"&&(a&&(a.style.display="none"),e.preventDefault(),O=!0,M=setTimeout(()=>{O&&Y(!0)},he))}),document.addEventListener("keyup",e=>{te&&e.key==="Control"&&(O=!1,clearTimeout(M),A&&N())}),u&&u.addEventListener("click",e=>{e.preventDefault(),!_&&h.style.display!=="block"&&q&&Y()}),S&&S.addEventListener("click",e=>{e.preventDefault(),!_&&N()}),a&&a.addEventListener("click",e=>{e.preventDefault(),!_&&h.style.display!=="block"&&q&&(A?N():Y())}),n&&n.addEventListener("click",e=>{e.preventDefault(),!_&&h.style.display!=="block"&&q&&(A?N():Y())}),f&&f.addEventListener("click",()=>{q=!1});function ie(){O=!1,M&&(clearTimeout(M),M=null),A&&N()}window.addEventListener("blur",ie),document.addEventListener("visibilitychange",()=>{document.hidden&&ie()});function ve(){let e=document.querySelector('[data-form="step"]:not([style*="display: none"])'),t=e?e.querySelector(".demo_container"):null;t&&(t.style.opacity="0"),g&&(g.style.display="none"),ee=!1,$=!0,A=!1,O=!1,H=[],Q=null,X="",q=!0,M&&(clearTimeout(M),M=null),p&&p.state==="recording"&&p.stop(),v&&(v.getTracks().forEach(i=>i.stop()),v=null,p=null),I&&(clearInterval(I),I=null),E&&(E.close().catch(console.error),E=null),T.style.opacity="0",L&&L.cancel(),n.classList.add("muted"),n.classList.remove("no-cursor"),h.style.display="none",n.style.display="none",n.innerHTML="",n.removeAttribute("data-previous-text"),a&&(a.style.display="block",a.style.opacity="0"),s&&(s.style.display="grid",s.style.opacity="0",s.classList.remove("pointer-events-none")),u&&(u.style.display="flex"),S&&(S.style.display="none"),D&&(D.style.display="block"),o&&(o.style.display="none"),c&&(c.style.display="none"),f&&f.classList.add("animated"),b.forEach(i=>{i.style.visibility="hidden",i.style.pointerEvents="none"}),setTimeout(()=>{s&&(s.style.opacity="1"),a&&(a.style.opacity="1");let i=document.querySelector('[demo-element="speech-div"]'),l=i?i.querySelector(".demo_container"):null;l&&(l.style.opacity="1",l.style.transition="opacity 0.3s ease")},750)}b.length>0&&b.forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),ve()})}),K&&document.addEventListener("keydown",function(e){e.key==="Escape"&&(e.preventDefault(),K.click())}),document.addEventListener("keydown",function(e){if(e.key==="Enter"){let t=document.querySelector('[data-form="step"]:not([style*="display: none"])');if(!t)return;let i=document.querySelector('[data-form="next-btn"]');if(!i)return;t.getAttribute("demo-element")==="speech-div"&&i.classList.contains("animated")||(i.click(),e.preventDefault())}}),document.querySelectorAll('[data-form="next-btn"]').forEach(e=>{e.addEventListener("click",()=>{let t=document.querySelector('[data-form="step"]:not([style*="display: none"])'),i=t?t.querySelector(".demo_container"):null;i&&(i.style.opacity="0",setTimeout(()=>{let l=document.querySelector('[data-form="step"]:not([style*="display: none"])'),d=l?l.querySelector(".demo_container"):null;d&&(d.style.opacity="1",d.style.transition="opacity 0.3s ease")},100))},!0)})}function ae(){Splitting();let P=new Set,n=new Map,T=()=>{P.clear(),n.forEach((o,c)=>{clearTimeout(o),n.delete(c)})},b=o=>{if(!o)return!1;let c=window.getComputedStyle(o);return c.display!=="none"&&c.visibility!=="hidden"&&o.offsetParent!==null},h=o=>{if(P.has(o))return;let c=parseInt(o.getAttribute("data-fade-delay"))||0;if(c>0){o.style.opacity="0";let f=setTimeout(()=>{n.delete(o),b(o)&&g(o)},c);n.set(o,f);return}g(o)},g=o=>{let c=[...o.querySelectorAll(".word")];gsap.fromTo(c,{"will-change":"transform, filter",transformOrigin:"0% 100%",x:-20,rotation:0,scale:.8,opacity:0,filter:"blur(8px)"},{ease:"power2.inOut",x:0,y:0,rotation:0,scale:1,opacity:1,filter:"blur(0px)",duration:1.2,stagger:{each:.08,from:"start"},onComplete:()=>{let f=o.getAttribute("data-triggers-elements");f&&document.querySelectorAll(f).forEach(s=>{P.has(s)||h(s)})}}),P.add(o),o.style.opacity="1"},u=()=>{T();let o=[...document.querySelectorAll("[data-fade-in]")].filter(s=>b(s)),c=o.filter(s=>!s.getAttribute("data-fade-delay")),f=o.filter(s=>s.getAttribute("data-fade-delay"));requestAnimationFrame(()=>{c.forEach(h),f.forEach(h)})},S=()=>{document.querySelectorAll('[data-form="step"]').forEach(c=>{new MutationObserver(s=>{s.forEach(a=>{a.attributeName==="style"&&a.target.style.display!=="none"&&setTimeout(()=>{c.querySelectorAll("[data-fade-in]").forEach(U=>{Splitting({target:U,by:"words"}),h(U)})},100)})}).observe(c,{attributes:!0,attributeFilter:["style"]})})};u(),S(),document.querySelectorAll('[data-form="next-btn"]').forEach(o=>{o.addEventListener("click",()=>{setTimeout(u,100)})}),document.addEventListener("click",o=>{o.target.matches('[data-form="next-btn"], [data-form="back-btn"], [data-edit-step]')&&setTimeout(u,100)})}document.addEventListener("DOMContentLoaded",async function(){ae(),await re(),console.log("Web demo initialized successfully")});})();
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")});})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanay-wispr/webflow-package",
3
- "version": "5.0.17",
3
+ "version": "5.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },