@tanay-wispr/webflow-package 4.8.14 → 4.8.16
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.
- package/dist/global.js +1 -1
- package/dist/web-demo/index.js +8 -8
- package/package.json +1 -1
package/dist/global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{document.addEventListener("DOMContentLoaded",async()=>{let a=async()=>{try{let t=await navigator.userAgentData.getHighEntropyValues(["architecture","platform"]);return t.platform==="macOS"?t.architecture==="arm"?"mac_m1":"mac_intel":t.platform}catch{let{userAgent:t}=navigator;return t.includes("Macintosh")?"mac_intel":t.includes("Windows")?"Windows":t.includes("Linux")?"Linux":/iPhone|iPad|iPod/.test(t)?"iOS":/Android/.test(t)?"Android":"Unknown"}},l=(t,e,o=30)=>{let n="";if(o){let s=new Date;s.setTime(s.getTime()+o*24*60*60*1e3),n="; expires="+s.toUTCString()}let{hostname:r}=window.location,c;r.includes("wisprflow.ai")?c=".wisprflow.ai":c=r,document.cookie=t+"="+encodeURIComponent(e)+n+"; path=/; domain="+c+"; SameSite=Lax"},u=()=>{let e=document.cookie.split(";").find(o=>o.trim().startsWith("trial_promo="));return e&&e.trim().split("=")[1]==="3mo"},d=()=>new Promise(t=>{let e=0,o=50;function n(){if(e>=o){console.warn("PostHog not fully ready after max attempts, proceeding with limited functionality"),t(!1);return}if(e++,typeof posthog<"u"&&typeof posthog.getFeatureFlag=="function"&&posthog.get_distinct_id&&typeof posthog.get_distinct_id=="function")try{setTimeout(()=>t(!0),50)}catch(r){console.error("Error getting distinct ID:",r),setTimeout(n,100)}else setTimeout(n,100)}n()});window.wisprUtils={waitForPostHog:d,setCookie:l};let i=await a();console.log("Platform: "+i),window.userPlatform=i;let m=u();console.log("Next Play User:",m),document.querySelectorAll("[nav-link]").forEach(function(t){t.addEventListener("click",()=>(posthog.capture("nav_click",{nav_item:t.getAttribute("nav-link")}),!0))}),document.querySelectorAll("[cta]").forEach(function(t){t.addEventListener("click",()=>(posthog.capture("cta_click",{title:t.innerText,cta_location:t.getAttribute("cta_location"),cta_type:t.getAttribute("cta_type"),device_type:i}),!0))}),document.querySelectorAll("[web-demo-open]").forEach(function(t){t.addEventListener("click",()=>(posthog.capture("web_demo_open",{title:t.innerText,device_type:window.userPlatform,source:t.getAttribute("cta_location")}),!0))}),document.querySelectorAll("[web-demo-close]").forEach(function(t){t.addEventListener("click",()=>(posthog.capture("web_demo_close",{device_type:window.userPlatform}),!0))}),document.querySelectorAll("[app-download]").forEach(function(t){let e=t.id,o=e==="nav-download"?"nav":e==="footer-download"?"footer":t.getAttribute("cta_location")||"pricing";t.href="https://wisprflow.onelink.me/PguH/lw5h199m",t.addEventListener("click",()=>(posthog.capture("download_page_redirect",{source:o,device_type:i}),!0))})});})();
|
|
1
|
+
"use strict";(()=>{document.addEventListener("DOMContentLoaded",async()=>{let a=async()=>{try{let t=await navigator.userAgentData.getHighEntropyValues(["architecture","platform"]);return t.platform==="macOS"?t.architecture==="arm"?"mac_m1":"mac_intel":t.platform}catch{let{userAgent:t}=navigator;return t.includes("Macintosh")?"mac_intel":t.includes("Windows")?"Windows":t.includes("Linux")?"Linux":/iPhone|iPad|iPod/.test(t)?"iOS":/Android/.test(t)?"Android":"Unknown"}},l=(t,e,o=30)=>{let n="";if(o){let s=new Date;s.setTime(s.getTime()+o*24*60*60*1e3),n="; expires="+s.toUTCString()}let{hostname:r}=window.location,c;r.includes("wisprflow.ai")?c=".wisprflow.ai":c=r,document.cookie=t+"="+encodeURIComponent(e)+n+"; path=/; domain="+c+"; SameSite=Lax"},u=()=>{let e=document.cookie.split(";").find(o=>o.trim().startsWith("trial_promo="));return e&&e.trim().split("=")[1]==="3mo"},d=()=>new Promise(t=>{let e=0,o=50;function n(){if(e>=o){console.warn("PostHog not fully ready after max attempts, proceeding with limited functionality"),t(!1);return}if(e++,typeof posthog<"u"&&typeof posthog.getFeatureFlag=="function"&&posthog.get_distinct_id&&typeof posthog.get_distinct_id=="function")try{setTimeout(()=>t(!0),50)}catch(r){console.error("Error getting distinct ID:",r),setTimeout(n,100)}else setTimeout(n,100)}n()});window.wisprUtils={waitForPostHog:d,setCookie:l};let i=await a();console.log("Platform: "+i),window.userPlatform=i;let m=u();console.log("Next Play User:",m),document.querySelectorAll("[nav-link]").forEach(function(t){t.addEventListener("click",()=>(posthog.capture("nav_click",{nav_item:t.getAttribute("nav-link")}),!0))}),document.querySelectorAll("[cta]").forEach(function(t){t.addEventListener("click",()=>(posthog.capture("cta_click",{title:t.innerText,cta_location:t.getAttribute("cta_location"),cta_type:t.getAttribute("cta_type"),href:t.getAttribute("href")||"NO_HREF_FOUND",device_type:i}),!0))}),document.querySelectorAll("[web-demo-open]").forEach(function(t){t.addEventListener("click",()=>(posthog.capture("web_demo_open",{title:t.innerText,device_type:window.userPlatform,source:t.getAttribute("cta_location")}),!0))}),document.querySelectorAll("[web-demo-close]").forEach(function(t){t.addEventListener("click",()=>(posthog.capture("web_demo_close",{device_type:window.userPlatform}),!0))}),document.querySelectorAll("[app-download]").forEach(function(t){let e=t.id,o=e==="nav-download"?"nav":e==="footer-download"?"footer":t.getAttribute("cta_location")||"pricing";t.href="https://wisprflow.onelink.me/PguH/lw5h199m",t.addEventListener("click",()=>(posthog.capture("download_page_redirect",{source:o,device_type:i}),!0))})});})();
|
package/dist/web-demo/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";(()=>{async function re(){let P=document.querySelector('[demo-element="wrapper"]'),t=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]"),H=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,_=[],A=!1,Q=null,X="",O=!1,q=!0,z=!0,U=!0,E=null,$=null,J=null,I=null,ee=!1;navigator.mediaDevices.getUserMedia({audio:!0}).then(e=>{e.getTracks().forEach(n=>n.stop()),U=!1,ye()}).catch(e=>{console.error("Initial microphone permission denied:",e),U=!1;try{navigator.permissions.query({name:"microphone"}).then(n=>{n.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:",n.state)}).catch(n=>{console.error("Permissions API error:",n),ne(e)})}catch(n){console.error("Permissions API not supported:",n),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(n=>{n.style.visibility="visible",n.style.pointerEvents="auto"}))}T.style.opacity="0",T.style.transition="opacity 0.3s ease",t.classList.add("muted"),h.style.display="none",t.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(t,{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((n,i)=>{let l=new FileReader;l.onloadend=()=>{typeof l.result=="string"?n(l.result.split(",")[1]):i(new Error("Failed to convert blob to base64"))},l.onerror=i,l.readAsDataURL(e)}),de=async e=>{let n=new AudioContext,i=await e.arrayBuffer(),l=await n.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,N=w.length*y*2+44,W=new ArrayBuffer(N),m=new DataView(W),r=0,k=(V,j,Z)=>{for(let G=0;G<Z.length;G++)V.setUint8(j+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 V=0;V<w.length;V++){let j=ge[V],Z=j<0?j*32768:j*32767;m.setInt16(r,Z,!0),r+=2}return new Blob([m],{type:"audio/wav"})},oe=()=>{t&&(t.scrollHeight>t.clientHeight?t.style.overflowY="auto":t.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 n=await e.json();return localStorage.setItem("accessToken",n.access_token),localStorage.setItem("tokenExpiration",(Date.now()+n.expires_in*1e3).toString()),n.access_token}catch(e){throw console.error("Token generation failed:",e),t.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=>{_.push(e.data)},p.onstop=async()=>{try{let e=new Blob(_,{type:"audio/webm"});Q=await de(e),X=await ce(Q),await pe(),_=[],v.getTracks().forEach(n=>{n.stop()}),v=null,p=null}catch(e){console.error("Audio processing error:",e),v&&(v.getTracks().forEach(n=>n.stop()),v=null,p=null)}},!0}catch(e){return console.error("Microphone access error:",e),(e.name==="NotAllowedError"||e.name==="PermissionDeniedError")&&g&&(t.style.display="none",g.style.display="block"),!1}}async function pe(){try{let e=document.querySelector('[demo-element="spinner"]'),n=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(n&&(n.style.display="none"),i&&(i.style.display="flex"),l&&(l.style.display="none"),d&&(d.style.display="none"),x&&(x.style.display="flex"),z){if(t.innerHTML="",e){let y=e.cloneNode(!0);y.style.display="inline-block",y.style.verticalAlign="middle",y.classList.add("no-cursor"),t.appendChild(y)}t.classList.add("no-cursor")}else{if(t.dataset.previousText&&(t.innerHTML=t.dataset.previousText,t.appendChild(document.createTextNode(" ")),e)){let y=e.cloneNode(!0);y.style.display="inline-block",y.style.verticalAlign="middle",y.classList.add("no-cursor"),t.appendChild(y)}t.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=!z;me(B.text,w),z=!1,n&&(n.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),t.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(n=>{n.style.visibility="visible",n.style.pointerEvents="auto"}),p&&p.state==="recording"&&p.stop(),v&&(v.getTracks().forEach(n=>n.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,n=!1){t.style.display="block",t.classList.remove("muted"),t.classList.remove("no-cursor");let i=t.dataset.previousText||"",l=n&&i?`${i} ${e}`:e;t.innerHTML=l,oe(),t.dataset.previousText=l,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{H.currentTime=0,await H.play()}catch(i){console.error("Error playing start dictation sound:",i)}a&&(a.style.display="none"),t.style.display="block";let n=t.innerHTML||"";if(n&&!n.includes("Flow is listening")&&!n.includes("Converting...")&&!n.includes("Error")&&(t.dataset.previousText=n),t.dataset.previousText?(t.innerHTML=t.dataset.previousText,t.classList.add("no-cursor")):(t.innerHTML='Flow is listening<span class="typing-dots"></span>',t.classList.add("no-cursor")),!p&&!await fe()){t.dataset.previousText?t.innerHTML=t.dataset.previousText:t.innerHTML="",t.classList.remove("no-cursor");return}if(p.state==="inactive"){_=[],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,$=E.createAnalyser(),E.createMediaStreamSource(v).connect($),$.fftSize=32,J=new Uint8Array($.frequencyBinCount),I=setInterval(()=>{$.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,N=k=>w*.3*Math.sin(k/1440*Math.PI*2+y*.8),W=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 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=`
|
|
2
2
|
M0,160
|
|
3
|
-
C120,${100+
|
|
4
|
-
240,${220+
|
|
3
|
+
C120,${100+W(120)}
|
|
4
|
+
240,${220+V(240)}
|
|
5
5
|
480,${160+m(480)}
|
|
6
|
-
C720,${100+
|
|
7
|
-
900,${220+
|
|
6
|
+
C720,${100+W(720)}
|
|
7
|
+
900,${220+V(900)}
|
|
8
8
|
1080,${160+m(1080)}
|
|
9
|
-
C1260,${100+
|
|
10
|
-
1440,${220+
|
|
9
|
+
C1260,${100+W(1260)}
|
|
10
|
+
1440,${220+V(1440)}
|
|
11
11
|
1440,${160+m(1440)}
|
|
12
12
|
L1440,320 L0,320 Z
|
|
13
|
-
`;B.setAttribute("d",r)}},50)}}function
|
|
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")});})();
|