@pickaxeproject/react 6.12.2 → 6.13.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.
- package/dist/cjs/components/Pickaxe/Chat/History/Message.js +1 -1
- package/dist/cjs/components/Pickaxe/Chat/Input.js +1 -1
- package/dist/cjs/components/Pickaxe/Form/Questions/Input.js +1 -1
- package/dist/cjs/components/Pickaxe/common/PickaxeMessageActions.js +1 -1
- package/dist/cjs/hooks/pickaxe/useSpeechToText.js +1 -0
- package/dist/cjs/hooks/pickaxe/useTextToSpeech.js +1 -0
- package/dist/cjs/node_modules/.pnpm/cose-base@1.0.3/node_modules/cose-base/cose-base.js +1 -1
- package/dist/cjs/node_modules/.pnpm/cose-base@2.2.0/node_modules/cose-base/cose-base.js +1 -1
- package/dist/cjs/node_modules/.pnpm/layout-base@1.0.2/node_modules/layout-base/layout-base.js +1 -1
- package/dist/cjs/node_modules/.pnpm/layout-base@2.0.1/node_modules/layout-base/layout-base.js +1 -1
- package/dist/cjs/src/components/Pickaxe/common/PickaxeMessageActions.d.ts +2 -1
- package/dist/cjs/src/hooks/pickaxe/{useSpeech.d.ts → useSpeechToText.d.ts} +1 -1
- package/dist/cjs/src/hooks/pickaxe/useTextToSpeech.d.ts +6 -0
- package/dist/esm/components/Pickaxe/Chat/History/Message.js +1 -1
- package/dist/esm/components/Pickaxe/Chat/Input.js +1 -1
- package/dist/esm/components/Pickaxe/Form/Questions/Input.js +1 -1
- package/dist/esm/components/Pickaxe/common/PickaxeMessageActions.js +1 -1
- package/dist/esm/hooks/pickaxe/{useSpeech.js → useSpeechToText.js} +1 -1
- package/dist/esm/hooks/pickaxe/useTextToSpeech.js +1 -0
- package/dist/esm/node_modules/.pnpm/cose-base@1.0.3/node_modules/cose-base/cose-base.js +1 -1
- package/dist/esm/node_modules/.pnpm/cose-base@2.2.0/node_modules/cose-base/cose-base.js +1 -1
- package/dist/esm/node_modules/.pnpm/layout-base@1.0.2/node_modules/layout-base/layout-base.js +1 -1
- package/dist/esm/node_modules/.pnpm/layout-base@2.0.1/node_modules/layout-base/layout-base.js +1 -1
- package/dist/esm/src/components/Pickaxe/common/PickaxeMessageActions.d.ts +2 -1
- package/dist/esm/src/hooks/pickaxe/{useSpeech.d.ts → useSpeechToText.d.ts} +1 -1
- package/dist/esm/src/hooks/pickaxe/useTextToSpeech.d.ts +6 -0
- package/package.json +1 -1
- package/dist/cjs/hooks/pickaxe/useSpeech.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),t=require("../../../../hooks/pickaxe/usePickaxeContext.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),t=require("../../../../hooks/pickaxe/usePickaxeContext.js"),a=require("../../../../hooks/studio/useStyleFontSize.js"),i=require("../../../../hooks/pickaxe/useResponseContext.js"),r=require("../../Addons/Artifact/hooks/useArtifact.js"),o=require("../../common/PickaxeMarkdown/index.js"),l=require("../../common/PickaxeIcon.js"),n=require("./Document.js"),c=require("../../common/PickaxeMessageActions.js"),d=require("../../common/PickaxeMessageParts/index.js"),u=require("../../../../common/cn.js"),x=require("../../../../common/isoMap.js"),m=require("franc-min"),p=require("../../common/ComposioConnectView.js"),f=require("../../common/SmitheryConnectView.js"),j=require("../../../../hooks/pickaxe/useTextToSpeech.js");function h(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var g=h(require("remove-markdown"));exports.default=({index:h,message:b,smitheryData:v,resubmitPrompt:k,isLastMessage:y=!1})=>{var w,O;const{pickaxeId:q,pickaxe:N,styles:C,colors:I,misc:P,responsiveBy:A,disableHtml:R,disableJs:S,disableCss:M,isNewChat:T,isRtl:L}=t.usePickaxeContext(),{isGenerating:F}=i.useResponseContext(),{onLoadArtifact:H}=r.useArtifact(),J=a.useStyleFontSize(),V=null!==(w=null==N?void 0:N.chaticon)&&void 0!==w?w:`https://cdn.mail.studio/chaticons/${q}.png`,z=y&&F,B=null==N?void 0:N.enablereadout,{isLoading:D,isSpeaking:_,speak:E,stop:G}=j.useTextToSpeech(B&&"assistant"===b.role),U=()=>{if(D||_)return void G();const e=b.parts.filter((e=>"text"===e.type)).map((e=>e.content)).join(" ");if(!e)return;const s=g.default(e,{stripListLeaders:!0,listUnicodeChar:"",gfm:!0,useImgAltText:!1}),t=m.franc(s),a=x.convertToIso1(t);E(s,a)},$=!b.parts.some((e=>["text","reasoning","data-action-tool-caption"].includes(e.type)));return"assistant"===b.role?e.jsx("div",Object.assign({className:u.default("flex w-full",L?"justify-end":"justify-start")},{children:e.jsx("div",Object.assign({className:u.default("flex flex-col w-full",0===h&&T&&"viewport"===A&&"min-[767px]:max-w-[80%]",0===h&&T&&"container"===A&&"@[767px]/pickaxe-root:max-w-[80%]")},{children:e.jsxs("div",Object.assign({className:u.default("flex gap-x-3",L&&"flex-row-reverse")},{children:[P.isChatImage&&"NONE"!==V&&e.jsx(l.default,{src:V,alt:"Assistant",width:24,height:24,className:"my-3 h-6 w-6",textColor:I.text}),e.jsxs("div",Object.assign({className:u.default("flex flex-col flex-grow",L?"items-end":"items-start")},{children:[e.jsxs("div",Object.assign({className:u.default(J.b2,"chat-message pt-3 w-full",L?"text-right":"text-left")},{children:[e.jsx(o.PickaxeMarkdown,Object.assign({theme:C.theme,colors:I},L&&{rtl:!0},R&&{disableHtml:!0},S&&{disableJs:!0},M&&{disableCss:!0},{disableReasoning:null!==(O=null==N?void 0:N.enablereasoningdisplay)&&void 0!==O&&O,onArtifactClick:H},{children:e.jsx(d.default,{parts:b.parts})})),y&&v&&k&&("composio"===v.provider?e.jsx("div",Object.assign({className:"mt-4 px-1"},{children:e.jsx(p.default,{serverId:v.serverId,toolkitSlug:v.toolkitSlug||"",name:v.name,resubmitPrompt:()=>k()})})):e.jsx("div",Object.assign({className:"mt-4 px-1"},{children:e.jsx(f.default,{serverId:v.serverId,smitheryId:v.smitheryId||"",name:v.name||v.smitheryId,resubmitPrompt:()=>k()})})))]})),e.jsx("div",Object.assign({className:u.default("flex flex-col gap-6 my-4",$&&"mt-2")},{children:z?e.jsx("div",Object.assign({className:"flex items-center gap-x-2 rounded"},{children:Array.from({length:3}).map(((s,t)=>e.jsx("div",{className:u.default("h-1.5 w-1.5 animate-dot rounded-full",1===t&&"animate-dot-down"),style:{backgroundColor:I.secondaryText}},t)))})):e.jsx(c.default,Object.assign({content:b.parts.filter((e=>e.isVisible&&"text"===e.type)).map((e=>e.content)).join("\n"),index:h},"intromessage"===b.area&&{isHideFeedback:!0},{onReadOut:U,isReadOut:B||!1,isReadOutLoading:D,isReading:_}))}))]}))]}))}))})):"user"===b.role?e.jsx("div",Object.assign({className:u.default("flex w-full",L?"justify-start":"justify-end")},{children:e.jsx("div",Object.assign({className:u.default("flex gap-x-3 max-w-[80%]",L?"pr-9":"pl-9","viewport"===A?L?"min-[767px]:pr-0":"min-[767px]:pl-0":L?"@[767px]/pickaxe-root:pr-0":"@[767px]/pickaxe-root:pl-0")},{children:e.jsxs("div",Object.assign({className:u.default(J.b2,"overflow-x-auto overflow-y-hidden px-4 py-3 scrollbar-thin scrollbar-track-white scrollbar-thumb-[#4A4A4B] flex flex-col gap-y-3",L?"text-right":"text-left"),style:{backgroundColor:I.secondary+"80",color:I.secondaryText,borderRadius:C.cornerRadius}},{children:[b.documentIds&&b.documentIds.length>0&&e.jsx("div",Object.assign({className:u.default("flex flex-col gap-y-2",L?"items-start":"items-end")},{children:b.documentIds.map((t=>e.jsx(s.Fragment,{children:e.jsx(n.default,{documentId:t})},t)))})),e.jsx(o.PickaxeMarkdown,Object.assign({theme:C.theme,colors:I},L&&{rtl:!0},R&&{disableHtml:!0},S&&{disableJs:!0},M&&{disableCss:!0},{children:e.jsx(d.default,{parts:b.parts})}))]}))}))})):e.jsx("div",{})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),n=require("../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../hooks/pickaxe/useResponseContext.js"),r=require("../../../hooks/studio/useStyleInput.js"),o=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../hooks/pickaxe/useConversation.js"),l=require("../../../hooks/pickaxe/useDimensionContext.js"),d=require("../Addons/Auth/hooks/useAuthContext.js"),c=require("../Addons/Document/hooks/useDocument.js"),u=require("../Addons/Scroll/hooks/useScroll.js"),p=require("../Addons/Artifact/hooks/useArtifactContext.js"),m=require("../../../hooks/core/useHover.js"),f=require("../../../hooks/core/useMediaQuery.js"),g=require("../../../common/documents.js"),v=require("eventsource-parser"),h=require("../../Icons/attach-vertical.svg.js"),b=require("../../Icons/arrow-right.svg.js"),I=require("../../Icons/microphone.svg.js"),y=require("../../Icons/stop.svg.js"),x=require("../Addons/Document/List.js"),j=require("../../Core/Textarea.js"),S=require("../../Core/ErrorAlert.js"),O=require("../../../common/error.js"),w=require("../../../common/chatMessages.js"),N=require("../../../common/api/pickaxe.js"),_=require("../../../common/validation.js"),k=require("../../../common/cn.js"),E=require("../../../common/utils.js"),U=require("../../../common/pickaxeConfig.js"),C=require("../../../common/deploymentWebhooks.js"),T=require("../../../hooks/studio/useStudio.js"),A=require("../../../hooks/pickaxe/useSpeech.js"),D=require("../common/PickaxeCommon.js");const P=e=>"string"==typeof e&&e.trim().length>0,L=e=>e.map((e=>Object.assign({},e))),M=e=>e instanceof Error&&("AbortError"===e.name||"BodyStreamBuffer was aborted"===e.message),R=(e,t)=>{if(e&&"object"==typeof e)return e[t]},q=(e,t)=>{const s=R(e,t);return P(s)?s:null},F=e=>{const t=Number(e);return Number.isFinite(t)?t:void 0},V=({studioUser:e,deploymentId:t,portalId:s})=>{var n,i;const r=Array.isArray(R(e,"uses"))?R(e,"uses"):[],o=(({deploymentId:e,portalId:t})=>P(e)?{type:"deployment",id:e}:P(t)?{type:"portal",id:t}:null)({deploymentId:t,portalId:s});if(!o)return{scope:o,record:null};const a=null!==(i=null!==(n=r.find((e=>e.id===o.id&&e.type===o.type)))&&void 0!==n?n:r.find((e=>e.id===o.id)))&&void 0!==i?i:null;return{scope:o,record:a}},B=s.forwardRef((({resubmitPrompt:R,onFocus:B,onBlur:$,onInputHeightChange:X,initSmitheryAuthData:H},K)=>{var W,Y,z,G,J,Q,Z,ee,te,se,ne,ie;const{origin:re,pickaxeId:oe,sessionId:ae,sender:le,senderType:de,portalId:ce,deploymentId:ue,deploymentType:pe,pickaxe:me,styles:fe,colors:ge,translations:ve,locale:he,forceMobile:be,isNewChat:Ie,isRtl:ye,isShowFeedbackMessage:xe,accessGroup:je,setIsNewChat:Se,setIsShowIceBreaker:Oe,setValidationStatus:we,setValidationUpgradeGroups:Ne,setValidationUpgradeUrl:_e,setAccessGroup:ke,onGenerateComplete:Ee}=n.usePickaxeContext(),{token:Ue,isLoggedOut:Ce,isSent:Te,isPricingAuth:Ae}=d.useAuthContext(),{messages:De,isGenerating:Pe,setMessages:Le,setStatus:Me,setLimitData:Re,setError:qe}=i.useResponseContext(),{documents:Fe,isUploading:Ve,documentError:Be,onFileUpload:$e,setDocuments:Xe,setDocumentError:He}=c.useDocument(),{studio:Ke}=T.useStudio(),[We]=f.useMediaQuery("(max-width: 480px)"),{scrollStartSession:Ye,scrollEndSession:ze,scrollToBottom:Ge}=u.useScroll({auto:!0,smooth:!(be||We)}),{artifacts:Je,currentPopupType:Qe,setArtifacts:Ze,setCurrentArtifact:et}=p.useArtifactContext(),{height:tt}=l.useDimensionContext(),st=a.useConversation(),[nt,it]=s.useState(""),[rt,ot]=s.useState(!1),[at,lt]=s.useState(!1),[dt,ct]=s.useState(null),[ut,pt]=s.useState(null),[mt,ft]=s.useState(!1),[gt,vt]=s.useState(!1),[ht,bt]=s.useState(0),It=s.useRef(null),yt=s.useRef(""),xt=s.useRef(null),jt=s.useRef(null),St=s.useRef(null),Ot=s.useRef([]),wt=s.useRef(null),Nt=s.useRef(null),_t=s.useRef(null),kt=s.useRef(null),Et=s.useRef(new Set),Ut=s.useRef(null),Ct=Math.max(.4*tt,100),{speechTranscript:Tt,isSpeechListening:At,isSpeechProcessing:Dt,isSpeechSupported:Pt,onStartListening:Lt,onStopListening:Mt}=A.useSpeech(),Rt=m.useHover(),{isHover:qt}=Rt,Ft=e.__rest(Rt,["isHover"]),Vt=m.useHover(),{isHover:Bt}=Vt,$t=e.__rest(Vt,["isHover"]),Xt=m.useHover(),{isHover:Ht}=Xt,Kt=e.__rest(Xt,["isHover"]),Wt=o.useStyleFontSize(),Yt=r.useStyleInput(),zt="undefined"!=typeof window?window.location.hostname:"",Gt="undefined"!=typeof window?window.location.href:"",Jt="undefined"!=typeof window&&window.self!==window.top,Qt=zt.includes("pickaxe.co")&&!Gt.includes("https://studio.pickaxe.co/_embed")&&!Jt,Zt=null!==(Y=null===(W=null==me?void 0:me.documentuploadtype)||void 0===W?void 0:W.startsWith("enduserupload"))&&void 0!==Y&&Y,es=Pt&&(null==me?void 0:me.enablevoicetotext),ts=P(ue),ss="chat-input"===pe&&Ie&&!Te,ns="chat-input"===pe&&Ae&&Ce&&Te,is=s.useCallback((e=>{const t=_.getValidationFailure(e);return!!t&&(qe(""),Re(null),we(t.status),ke(t.accessGroup),Ne(t.upgradeGroups),_e(t.upgradeUrl),!0)}),[qe,Re,we,Ne,_e,ke]),rs=null!==(z=null==me?void 0:me.placeholdertext)&&void 0!==z?z:ye?"بماذا تريد أن تتحدث؟":(null==ve?void 0:ve["what-do-you-want-to-talk-about"])||"What do you want to talk about?",os=rt||at,as=s.useCallback((()=>e.__awaiter(void 0,void 0,void 0,(function*(){ft(!1);try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/user`,Object.assign(Object.assign({method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({studioId:null==me?void 0:me.studioid},Ue?{studioSessionToken:Ue}:le?{sender:le}:{sender:E.initializeEmbedUserId()}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"Content-Type":"application/json","x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),Qt&&{credentials:"include"})),t=yield e.json();(null==t?void 0:t.studioUser)&&(ct(t.studioUser),pt(t.url))}catch(e){console.error("Failed to fetch studio user:",e)}finally{ft(!0)}}))),[Qt,null==me?void 0:me.studioid,le,Ue]);s.useEffect((()=>{as()}),[as]);const ls=Number(null!==(G=null==je?void 0:je.limit)&&void 0!==G?G:0),ds="string"==typeof(null==je?void 0:je.limitInterval)?je.limitInterval:null,cs=!!(null==Ke?void 0:Ke.data.usage)&&Ke.data.usage.isCredits,us=s.useMemo((()=>{var e,t,s,n,i;return null!==(i=null!==(n=null!==(s=null!==(t=null!==(e=null!=ce?ce:q(dt,"portalId"))&&void 0!==e?e:q(dt,"portalid"))&&void 0!==t?t:q(je,"portalId"))&&void 0!==s?s:q(je,"portalid"))&&void 0!==n?n:q(me,"portalId"))&&void 0!==i?i:q(me,"portalid")}),[je,ce,me,dt]),ps=s.useMemo((()=>V({studioUser:dt,deploymentId:ue,portalId:us})),[ue,us,dt]);s.useEffect((()=>{ts&&Ie&&ae&&Et.current.add(ae)}),[Ie,ae,ts]);const ms=s.useCallback((()=>{var e,t,s;return{studioId:null==me?void 0:me.studioid,userEmail:q(dt,"email"),userId:null!==(e=q(dt,"userId"))&&void 0!==e?e:q(dt,"userid"),sessionId:ae,deploymentId:ue,deploymentType:pe,portalId:us,accessGroupId:null!==(t=null==je?void 0:je.accessGroupId)&&void 0!==t?t:null,pickaxeId:oe,sender:le,senderType:de,origin:re,metadata:null!==(s=U.getPickaxeConfigMetadata(ue))&&void 0!==s?s:null}}),[null==je?void 0:je.accessGroupId,ue,pe,re,null==me?void 0:me.studioid,oe,us,le,de,ae,dt]),fs=s.useCallback((()=>!!(ts&&mt&&ae)&&(!!Et.current.has(ae)&&(C.fireDeploymentSessionInitializedWebhook(ms()),Et.current.delete(ae),!0))),[ms,mt,ae,ts]);s.useEffect((()=>{if(!mt||!ae)return;fs();const e=Ut.current;(null==e?void 0:e.sessionId)===ae&&(C.fireDeploymentFirstMessageSubmittedWebhook(Object.assign(Object.assign(Object.assign({},e),ms()),{message:e.message,documentIds:e.documentIds,uploadedModelImages:e.uploadedModelImages,hasUploadedDocuments:e.hasUploadedDocuments,isHidden:e.isHidden})),Ut.current=null)}),[fs,ms,mt,ae]);const gs={currentUses:F(null==dt?void 0:dt.currentUses),extraUses:F(null==dt?void 0:dt.extraUses)},vs=ps.scope?{currentUses:null!==(Q=F(null===(J=ps.record)||void 0===J?void 0:J.currentUses))&&void 0!==Q?Q:0,extraUses:null!==(ee=F(null===(Z=ps.record)||void 0===Z?void 0:Z.extraUses))&&void 0!==ee?ee:0}:{currentUses:0,extraUses:0},hs=q(dt,"type"),bs="guest"===hs||!hs&&Ce?vs:gs;s.useEffect((()=>{let t=!0;return e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(cs&&(null===(e=null==Ke?void 0:Ke.data)||void 0===e?void 0:e.workspaceId))try{const e=yield N.pickaxeApi2.get(`/cost_per_run?workspaceId=${Ke.data.workspaceId}`,{withCredentials:!1});t&&bt(1e4*(Number(e.data.costPerRun)||0))}catch(e){console.error("Failed to fetch average cost per run:",e),t&&bt(0)}else t&&bt(0)})),()=>{t=!1}}),[cs,null===(te=null==Ke?void 0:Ke.data)||void 0===te?void 0:te.workspaceId]);const Is=(({currentUses:e,extraUses:t,limit:s,limitInterval:n})=>{const i=Number(null!=e?e:0),r=Number(null!=t?t:0);return s===D.STUDIO_INFINITY_VALUE||r===D.STUDIO_INFINITY_VALUE?D.STUDIO_INFINITY_VALUE:"one_time"===n?Math.max(0,r-i):Math.max(0,s-i)+r})({currentUses:bs.currentUses,extraUses:bs.extraUses,limit:ls,limitInterval:ds}),ys=Is===D.STUDIO_INFINITY_VALUE?D.STUDIO_INFINITY_VALUE:Math.max(0,Math.ceil(Is)),xs=(({extraUses:e,limit:t,limitInterval:s})=>{const n=Number(null!=e?e:0);return t===D.STUDIO_INFINITY_VALUE||n===D.STUDIO_INFINITY_VALUE?D.STUDIO_INFINITY_VALUE:"one_time"===s?Math.max(0,n):Math.max(0,t)+Math.max(0,n)})({extraUses:bs.extraUses,limit:ls,limitInterval:ds}),js=xs===D.STUDIO_INFINITY_VALUE?D.STUDIO_INFINITY_VALUE:Math.ceil(.05*xs),Ss=cs?Math.ceil(5*ht):5,Os=js===D.STUDIO_INFINITY_VALUE?D.STUDIO_INFINITY_VALUE:Math.max(js,Ss),ws=s.useMemo((()=>!!dt&&(!gt&&(ys!==D.STUDIO_INFINITY_VALUE&&(!(ys<=0)&&ys<=Os)))),[gt,Os,ys,dt]),Ns=Boolean(null==je?void 0:je.hideUpgradeOptions),_s=!Ns&&(null===(se=null==je?void 0:je.upgrade)||void 0===se?void 0:se.isLinkToCustomURL)&&"string"==typeof je.upgrade.limitLink&&je.upgrade.limitLink.trim().length>0?je.upgrade.limitLink.trim():null,ks=_s&&"string"==typeof(null===(ne=null==je?void 0:je.upgrade)||void 0===ne?void 0:ne.limitCTA)&&je.upgrade.limitCTA.trim().length>0?je.upgrade.limitCTA:(null==ve?void 0:ve["pricing.upgrade"])||(null==ve?void 0:ve.upgrade)||"Upgrade",Es=s.useMemo((()=>{var e,t,s;return!!Ie&&(!!me&&(!st.isLoading&&(!((null!==(t=null===(e=st.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=me.icebreakers)||void 0===s?void 0:s.length)&&(!xe&&!ss)))))}),[me,Ie,xe,ss,st.data,st.isLoading]),Us=s.useMemo((()=>{if(Pe||Ve)return!1;const e=Zt&&Fe.length>0&&Fe.every((e=>"finished"===e.status));return!(!nt.trim()&&!e)&&Fe.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[Zt,Pe,Ve,nt,Fe]);s.useImperativeHandle(K,(()=>({onSubmit:Cs}))),s.useEffect((()=>{Oe(Es)}),[Es]),s.useEffect((()=>{var e;if(R){const t=Array.from(De),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;Cs(s,!0)}}),[R]),s.useEffect((()=>{if(!_t.current||!X)return;const e=new ResizeObserver((e=>{for(const t of e)X(t.contentRect.height)}));return e.observe(_t.current),()=>{e.disconnect()}}),[X]),s.useEffect((()=>{if(!At)return;const e=yt.current?`${yt.current} `:"";it(`${e}${Tt}`)}),[Tt,At]),s.useEffect((()=>{if(!wt.current)return;(()=>{if(!wt.current)return;let e=wt.current.scrollHeight>52;nt.includes("\n")||Fe.length?e=!0:nt.trim()||(e=!1),ot(e)})()}),[nt,Fe]),s.useEffect((()=>{const e=wt.current,t=Nt.current;if(!e||!t||rt||nt.includes("\n"))return void lt(!1);const s=window.getComputedStyle(e),n=`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${s.fontSize} / ${s.lineHeight} ${s.fontFamily}`,i=document.createElement("span");Object.assign(i.style,{font:n,letterSpacing:s.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),i.textContent=nt||rs,document.body.appendChild(i);const r=i.offsetWidth;i.remove();const o=parseFloat(s.paddingLeft)||0,a=parseFloat(s.paddingRight)||0,l=e.clientWidth-o-a-t.offsetWidth;lt(r>l)}),[nt,rt,rs]);const Cs=(t,s=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,n,i,r,o,a;let l=null;try{if(Pe||Ve)return;const d=Fe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),c=d.map((e=>e.documentId)).filter(Boolean),u=d.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),p=null!=t?t:nt,m=null!==(n=null===(e=null==me?void 0:me.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==n&&n&&c.length>0;if(!p&&!m)return;qe(""),He(""),Re(null),it(""),Se(!1),Me("fetching"),Ye(),Ge();const f=null!==(r=null===(i=st.data)||void 0===i?void 0:i.messages)&&void 0!==r?r:[],g=w.getUnpersistedMemoryMessages(De,f),h=s?g.slice(0,g.length-1):g,b=(e=>e.reduce(((e,t)=>Math.max(e,t.id)),0)+1)(h),I=b+(s?0:1),y={id:I,role:"assistant",parts:[],documentIds:[]},x=[...h,...s?[]:[{id:b,role:"user",parts:[{type:"text",content:p,isVisible:!0}],documentIds:m?c:[]}],y];Le(x),Ge(),m&&Xe([]);const j=U.getPickaxeConfigMetadata(ue),S="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`submission-${Date.now()}-${Math.random().toString(36).slice(2)}`;l=S,jt.current=S,St.current=null,Ot.current=[];const O=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/submit`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:re,pickaxeId:oe,sessionId:ae,submissionId:S,senderType:de,value:p},m&&{documentIds:c}),le&&{sender:le}),Ue&&{studioSessionToken:Ue}),!Ue&&!le&&{sender:E.initializeEmbedUserId()}),us&&{portalId:us}),ue&&{deploymentId:ue}),j&&{metadata:j}),m&&u.length>0?{uploadedModelImages:u}:{})),headers:Object.assign(Object.assign({},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()})},Qt&&{credentials:"include"})),N=yield O.json();if(!N.success){if(N.limitData){const e=new Error(N.error||N.message||(null==ve?void 0:ve["failed-to-start-generation"])||"Failed to start generation");throw e.limitData=N.limitData,e}if(is(N))return;throw new Error(N.error||N.message||(null==ve?void 0:ve["failed-to-start-generation"])||"Failed to start generation")}const _=null!==(o=N.submissionId)&&void 0!==o?o:S;l=_,jt.current=_;const k=()=>St.current===_;if(k())return;ts&&Ie&&ae&&Et.current.add(ae);const T=Object.assign(Object.assign({},ms()),{message:p,documentIds:m?c:[],uploadedModelImages:m?u:[],hasUploadedDocuments:m,isHidden:s,metadata:null!=j?j:null});mt?(fs(),C.fireDeploymentFirstMessageSubmittedWebhook(T)):Ut.current=T,Me("streaming"),kt.current=new AbortController;const A=[];let D=[...null!=Je?Je:[]],P=0,R=!1,q="";for(;!R;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/stream/${_}?index=${P}`,{signal:null===(a=kt.current)||void 0===a?void 0:a.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();xt.current=t;const s=new TextDecoder,n=v.createParser({onEvent:e=>{var t,s;if(k())R=!0;else if(e.event&&"ping"!==e.event&&P++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return Re(t.limitData),qe(""),void(R=!0);const s=t.error||t.message||(null==ve?void 0:ve["something-went-wrong"])||"Something went wrong.";return is(t)||qe(s),void(R=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&H){const e=n.data.error;if("string"==typeof e){const t=/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e),s=/['"]type['"]\s*:\s*['"]unauthorized_composio['"]/.test(e);if(t){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);if(t&&t[1]&&s&&s[1]&&n&&n[1])throw R=!0,H({provider:"smithery",smitheryId:t[1],serverId:s[1],name:n[1]}),new Error("STOP_STREAM")}else if(s){const t=e.match(/['"]toolkitSlug['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);if(t&&t[1]&&s&&s[1]&&n&&n[1])throw R=!0,H({provider:"composio",toolkitSlug:t[1],serverId:s[1],name:n[1]}),new Error("STOP_STREAM")}}else if("object"==typeof e&&null!==e){const t=e;if("unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name)throw R=!0,H({provider:"smithery",smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM");if("unauthorized_composio"===t.type&&t.toolkitSlug&&t.serverId&&t.name)throw R=!0,H({provider:"composio",toolkitSlug:t.toolkitSlug,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===n.type)q="",A.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)q+=n.delta,A[A.length-1].content=q;else if("text-end"===n.type)q="";else if("reasoning-start"===n.type)q="",A.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)q+=n.delta,A[A.length-1].content=q;else if("reasoning-end"===n.type)q="";else if(n.type.startsWith("data-")){const e=n;A.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}Ot.current=L(A);const i=L(A);Le((e=>{const t=e.findIndex((e=>e.id===I)),s=Object.assign(Object.assign({},y),{parts:i});return-1===t?[...e,s]:e.map(((e,n)=>n===t?s:e))}))}else if("artifact_created"===e.event){const t=JSON.parse(e.data);D=D.filter((e=>!(e.id===t.id&&e.version===t.version))),D.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Ze([...D]),Qe.startsWith("inline")||et({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);D=D.filter((e=>!(e.id===t.id&&e.version===t.version))),D.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Ze(D),Qe.startsWith("inline")||et({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);D=D.filter((e=>!(e.id===t.id&&e.version===t.version))),D.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Ze(D),Qe.startsWith("inline")||et({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");D=D.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Ze(D)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Ze(D.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return Re(t.limitData),qe(""),void(R=!0);const s=t.error||t.message||(null==ve?void 0:ve["something-went-wrong-try-again"])||"Something went wrong, please try again.";if(is(t))return void(R=!0);qe(s)}else"stop"===e.event&&(R=!0)}else R=!0}});for(;;){if(k()){R=!0,t.cancel().catch((()=>{}));break}const{value:e,done:i}=yield t.read();if(k()){R=!0,t.cancel().catch((()=>{}));break}if(i)break;n.feed(s.decode(e))}R||k()||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||M(e)||k())return void(R=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==Ee||Ee(ae)}catch(e){if(M(e))return;if(e.limitData)Re(e.limitData),qe("");else{let t=O.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==ve?void 0:ve["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),is(t)||qe(t)}}finally{const e=!l||jt.current===l;Ge(),e&&(Me("idle"),ze(),xt.current=null),l&&e&&(jt.current=null,Ot.current=[]),yield as()}}));return ns?null:t.jsx("div",Object.assign({className:k.default("flex w-full flex-shrink-0 flex-col items-center",!ss&&"px-4 pb-8"),dir:ye?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[t.jsxs("div",Object.assign({ref:_t,className:k.default("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===fe.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},Yt),{maxHeight:`${Ct}px`,overflowY:"auto"})},{children:[ws&&t.jsxs("div",Object.assign({className:"sticky top-0 z-10 flex w-full items-center justify-between border-b px-4 py-2.5 shadow-sm backdrop-blur-md",style:{backgroundColor:Yt.backgroundColor?`${Yt.backgroundColor}E6`:void 0,borderColor:ge.text+"20",color:ge.text,borderTopRightRadius:fe.cornerRadius+"px",borderTopLeftRadius:fe.cornerRadius+"px"}},{children:[t.jsx("div",Object.assign({className:"flex items-center gap-2 text-sm font-medium"},{children:t.jsxs("span",{children:[ys.toLocaleString()," ",cs?(null==ve?void 0:ve.credits)||"Credits":(null==ve?void 0:ve.uses)||"Uses"," ",(null==ve?void 0:ve.remaining)||"remaining"]})})),t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[!Ns&&t.jsx("button",Object.assign({className:"rounded-md px-3 py-1.5 text-xs font-semibold transition-opacity hover:opacity-90",style:{backgroundColor:ge.accent,color:ge.accentText},onClick:e=>{if(e.preventDefault(),e.stopPropagation(),_s)return void window.open(_s,"_blank","noopener,noreferrer");const t=E.buildUpgradeUrl({baseUrl:ut,accessGroupId:null==je?void 0:je.accessGroupId,redirectUrl:document.URL});t&&(E.isInIframe()?window.open(t):location.href=t)}},{children:ks})),t.jsx("button",Object.assign({className:"flex h-6 w-6 items-center justify-center rounded-full opacity-60 transition-opacity hover:opacity-100",onClick:()=>vt(!0)},{children:t.jsx("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",className:"h-4 w-4"},{children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}))}))]}))]})),!Pe&&Fe.length>0&&t.jsx(x.default,{className:"p-4 pb-0",isDisabled:Pe}),t.jsxs("div",Object.assign({className:"relative flex w-full flex-col"},{children:[At&&t.jsxs("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(ie=ge.accent)&&void 0!==ie?ie:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:ge.text+"90"}},{children:(null==ve?void 0:ve.listening)||"Listening..."}))]})),t.jsx(j.default,Object.assign({ref:wt,className:k.default(Wt.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!nt.trim()&&!nt.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",ye?"text-right":"text-left",os&&"mb-12",At&&"text-transparent"),value:nt,placeholder:rs,onChange:e=>{it(e)},onKeyDown:e=>{be||We||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),Ve||Pe||Cs()))},onPaste:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Array.from(t.clipboardData.files||[]);if(e.length>0){if(!Zt)return;t.preventDefault(),Se(!1),yield $e(e)}}))},B&&{onFocus:B},$&&{onBlur:$},{dir:ye?"rtl":"ltr"})),t.jsx("div",Object.assign({ref:Nt,className:k.default("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",os?"bottom-0 mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!os&&Yt.backgroundColor&&{backgroundColor:Yt.backgroundColor}),{borderTopRightRadius:fe.cornerRadius+"px",borderBottomRightRadius:fe.cornerRadius+"px"})},{children:Pe?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{const t=jt.current;t&&(St.current=t,(t=>{e.__awaiter(void 0,void 0,void 0,(function*(){if(!(t=null!=t?t:jt.current))return;const e=L(Ot.current);try{yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/cancel/${t}`,Object.assign({method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()}),body:JSON.stringify({outputMessageParts:e})},Qt&&{credentials:"include"}))}catch(e){console.warn("Failed to cancel submission",e)}}))})(t)),kt.current&&(kt.current.abort(),kt.current=null),xt.current&&(xt.current.cancel().catch((()=>{})),xt.current=null),Me("idle")},style:{backgroundColor:ge.accent,color:ge.accentText}},{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):At?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:Mt,style:{backgroundColor:ge.accent,color:ge.accentText}},{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[Zt&&t.jsxs("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Bt?ge.accent+"10":void 0,color:Bt?ge.accent:ge.accent+"80"},disabled:Ve||Pe,onClick:()=>{var e;return null===(e=It.current)||void 0===e?void 0:e.click()}},$t,{children:[t.jsx("input",{id:"file-upload",ref:It,type:"file",accept:[...g.allowedFileMimeTypes,...g.allowedImageMimeTypes,...g.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){Se(!1),yield $e(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(h.default,{className:"h-6 w-6 shrink-0"})]})),es&&t.jsx("button",Object.assign({className:"disabled:cursor-default flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:At?ge.accent:Ht?ge.accent+"10":void 0,color:At?ge.accentText:Ht?ge.accent:ge.accent+"80"},disabled:Ve||Pe||Dt,onClick:()=>{At?Mt():(yt.current=nt,Lt(he||"en-US"))}},Kt,{children:t.jsx(I.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:qt||Us?ge.accent:ge.accent+"10",color:qt||Us?ge.accentText:ge.accent+"80"},disabled:!Us,onClick:()=>Cs()},Ft,{children:t.jsx(b.default,{className:k.default("h-6 w-6 shrink-0",ye&&"scale-x-[-1] transform")})}))]})}))]}))]})),Be&&t.jsx(S.default,{error:Be,className:"mt-3"})]}))}))}));B.displayName="Input",exports.default=B;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),n=require("../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../hooks/pickaxe/useResponseContext.js"),o=require("../../../hooks/studio/useStyleInput.js"),r=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../hooks/pickaxe/useConversation.js"),l=require("../../../hooks/pickaxe/useDimensionContext.js"),d=require("../Addons/Auth/hooks/useAuthContext.js"),c=require("../Addons/Document/hooks/useDocument.js"),u=require("../Addons/Scroll/hooks/useScroll.js"),p=require("../Addons/Artifact/hooks/useArtifactContext.js"),m=require("../../../hooks/core/useHover.js"),f=require("../../../hooks/core/useMediaQuery.js"),g=require("../../../common/documents.js"),v=require("eventsource-parser"),h=require("../../Icons/attach-vertical.svg.js"),b=require("../../Icons/arrow-right.svg.js"),I=require("../../Icons/microphone.svg.js"),y=require("../../Icons/stop.svg.js"),x=require("../Addons/Document/List.js"),j=require("../../Core/Textarea.js"),S=require("../../Core/ErrorAlert.js"),O=require("../../../common/error.js"),w=require("../../../common/chatMessages.js"),N=require("../../../common/api/pickaxe.js"),_=require("../../../common/validation.js"),k=require("../../../common/cn.js"),E=require("../../../common/utils.js"),T=require("../../../common/pickaxeConfig.js"),U=require("../../../common/deploymentWebhooks.js"),C=require("../../../hooks/studio/useStudio.js"),A=require("../../../hooks/pickaxe/useSpeechToText.js"),D=require("../common/PickaxeCommon.js");const P=e=>"string"==typeof e&&e.trim().length>0,L=e=>e.map((e=>Object.assign({},e))),M=e=>e instanceof Error&&("AbortError"===e.name||"BodyStreamBuffer was aborted"===e.message),R=(e,t)=>{if(e&&"object"==typeof e)return e[t]},q=(e,t)=>{const s=R(e,t);return P(s)?s:null},F=e=>{const t=Number(e);return Number.isFinite(t)?t:void 0},V=({studioUser:e,deploymentId:t,portalId:s})=>{var n,i;const o=Array.isArray(R(e,"uses"))?R(e,"uses"):[],r=(({deploymentId:e,portalId:t})=>P(e)?{type:"deployment",id:e}:P(t)?{type:"portal",id:t}:null)({deploymentId:t,portalId:s});if(!r)return{scope:r,record:null};const a=null!==(i=null!==(n=o.find((e=>e.id===r.id&&e.type===r.type)))&&void 0!==n?n:o.find((e=>e.id===r.id)))&&void 0!==i?i:null;return{scope:r,record:a}},B=s.forwardRef((({resubmitPrompt:R,onFocus:B,onBlur:$,onInputHeightChange:X,initSmitheryAuthData:H},K)=>{var W,Y,z,G,J,Q,Z,ee,te,se,ne,ie;const{origin:oe,pickaxeId:re,sessionId:ae,sender:le,senderType:de,portalId:ce,deploymentId:ue,deploymentType:pe,pickaxe:me,styles:fe,colors:ge,translations:ve,locale:he,forceMobile:be,isNewChat:Ie,isRtl:ye,isShowFeedbackMessage:xe,accessGroup:je,setIsNewChat:Se,setIsShowIceBreaker:Oe,setValidationStatus:we,setValidationUpgradeGroups:Ne,setValidationUpgradeUrl:_e,setAccessGroup:ke,onGenerateComplete:Ee}=n.usePickaxeContext(),{token:Te,isLoggedOut:Ue,isSent:Ce,isPricingAuth:Ae}=d.useAuthContext(),{messages:De,isGenerating:Pe,setMessages:Le,setStatus:Me,setLimitData:Re,setError:qe}=i.useResponseContext(),{documents:Fe,isUploading:Ve,documentError:Be,onFileUpload:$e,setDocuments:Xe,setDocumentError:He}=c.useDocument(),{studio:Ke}=C.useStudio(),[We]=f.useMediaQuery("(max-width: 480px)"),{scrollStartSession:Ye,scrollEndSession:ze,scrollToBottom:Ge}=u.useScroll({auto:!0,smooth:!(be||We)}),{artifacts:Je,currentPopupType:Qe,setArtifacts:Ze,setCurrentArtifact:et}=p.useArtifactContext(),{height:tt}=l.useDimensionContext(),st=a.useConversation(),[nt,it]=s.useState(""),[ot,rt]=s.useState(!1),[at,lt]=s.useState(!1),[dt,ct]=s.useState(null),[ut,pt]=s.useState(null),[mt,ft]=s.useState(!1),[gt,vt]=s.useState(!1),[ht,bt]=s.useState(0),It=s.useRef(null),yt=s.useRef(""),xt=s.useRef(null),jt=s.useRef(null),St=s.useRef(null),Ot=s.useRef([]),wt=s.useRef(null),Nt=s.useRef(null),_t=s.useRef(null),kt=s.useRef(null),Et=s.useRef(new Set),Tt=s.useRef(null),Ut=Math.max(.4*tt,100),{speechTranscript:Ct,isSpeechListening:At,isSpeechProcessing:Dt,isSpeechSupported:Pt,onStartListening:Lt,onStopListening:Mt}=A.useSpeechToText(),Rt=m.useHover(),{isHover:qt}=Rt,Ft=e.__rest(Rt,["isHover"]),Vt=m.useHover(),{isHover:Bt}=Vt,$t=e.__rest(Vt,["isHover"]),Xt=m.useHover(),{isHover:Ht}=Xt,Kt=e.__rest(Xt,["isHover"]),Wt=r.useStyleFontSize(),Yt=o.useStyleInput(),zt="undefined"!=typeof window?window.location.hostname:"",Gt="undefined"!=typeof window?window.location.href:"",Jt="undefined"!=typeof window&&window.self!==window.top,Qt=zt.includes("pickaxe.co")&&!Gt.includes("https://studio.pickaxe.co/_embed")&&!Jt,Zt=null!==(Y=null===(W=null==me?void 0:me.documentuploadtype)||void 0===W?void 0:W.startsWith("enduserupload"))&&void 0!==Y&&Y,es=Pt&&(null==me?void 0:me.enablevoicetotext),ts=P(ue),ss="chat-input"===pe&&Ie&&!Ce,ns="chat-input"===pe&&Ae&&Ue&&Ce,is=s.useCallback((e=>{const t=_.getValidationFailure(e);return!!t&&(qe(""),Re(null),we(t.status),ke(t.accessGroup),Ne(t.upgradeGroups),_e(t.upgradeUrl),!0)}),[qe,Re,we,Ne,_e,ke]),os=null!==(z=null==me?void 0:me.placeholdertext)&&void 0!==z?z:ye?"بماذا تريد أن تتحدث؟":(null==ve?void 0:ve["what-do-you-want-to-talk-about"])||"What do you want to talk about?",rs=ot||at,as=s.useCallback((()=>e.__awaiter(void 0,void 0,void 0,(function*(){ft(!1);try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/user`,Object.assign(Object.assign({method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({studioId:null==me?void 0:me.studioid},Te?{studioSessionToken:Te}:le?{sender:le}:{sender:E.initializeEmbedUserId()}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"Content-Type":"application/json","x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),Qt&&{credentials:"include"})),t=yield e.json();(null==t?void 0:t.studioUser)&&(ct(t.studioUser),pt(t.url))}catch(e){console.error("Failed to fetch studio user:",e)}finally{ft(!0)}}))),[Qt,null==me?void 0:me.studioid,le,Te]);s.useEffect((()=>{as()}),[as]);const ls=Number(null!==(G=null==je?void 0:je.limit)&&void 0!==G?G:0),ds="string"==typeof(null==je?void 0:je.limitInterval)?je.limitInterval:null,cs=!!(null==Ke?void 0:Ke.data.usage)&&Ke.data.usage.isCredits,us=s.useMemo((()=>{var e,t,s,n,i;return null!==(i=null!==(n=null!==(s=null!==(t=null!==(e=null!=ce?ce:q(dt,"portalId"))&&void 0!==e?e:q(dt,"portalid"))&&void 0!==t?t:q(je,"portalId"))&&void 0!==s?s:q(je,"portalid"))&&void 0!==n?n:q(me,"portalId"))&&void 0!==i?i:q(me,"portalid")}),[je,ce,me,dt]),ps=s.useMemo((()=>V({studioUser:dt,deploymentId:ue,portalId:us})),[ue,us,dt]);s.useEffect((()=>{ts&&Ie&&ae&&Et.current.add(ae)}),[Ie,ae,ts]);const ms=s.useCallback((()=>{var e,t,s;return{studioId:null==me?void 0:me.studioid,userEmail:q(dt,"email"),userId:null!==(e=q(dt,"userId"))&&void 0!==e?e:q(dt,"userid"),sessionId:ae,deploymentId:ue,deploymentType:pe,portalId:us,accessGroupId:null!==(t=null==je?void 0:je.accessGroupId)&&void 0!==t?t:null,pickaxeId:re,sender:le,senderType:de,origin:oe,metadata:null!==(s=T.getPickaxeConfigMetadata(ue))&&void 0!==s?s:null}}),[null==je?void 0:je.accessGroupId,ue,pe,oe,null==me?void 0:me.studioid,re,us,le,de,ae,dt]),fs=s.useCallback((()=>!!(ts&&mt&&ae)&&(!!Et.current.has(ae)&&(U.fireDeploymentSessionInitializedWebhook(ms()),Et.current.delete(ae),!0))),[ms,mt,ae,ts]);s.useEffect((()=>{if(!mt||!ae)return;fs();const e=Tt.current;(null==e?void 0:e.sessionId)===ae&&(U.fireDeploymentFirstMessageSubmittedWebhook(Object.assign(Object.assign(Object.assign({},e),ms()),{message:e.message,documentIds:e.documentIds,uploadedModelImages:e.uploadedModelImages,hasUploadedDocuments:e.hasUploadedDocuments,isHidden:e.isHidden})),Tt.current=null)}),[fs,ms,mt,ae]);const gs={currentUses:F(null==dt?void 0:dt.currentUses),extraUses:F(null==dt?void 0:dt.extraUses)},vs=ps.scope?{currentUses:null!==(Q=F(null===(J=ps.record)||void 0===J?void 0:J.currentUses))&&void 0!==Q?Q:0,extraUses:null!==(ee=F(null===(Z=ps.record)||void 0===Z?void 0:Z.extraUses))&&void 0!==ee?ee:0}:{currentUses:0,extraUses:0},hs=q(dt,"type"),bs="guest"===hs||!hs&&Ue?vs:gs;s.useEffect((()=>{let t=!0;return e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(cs&&(null===(e=null==Ke?void 0:Ke.data)||void 0===e?void 0:e.workspaceId))try{const e=yield N.pickaxeApi2.get(`/cost_per_run?workspaceId=${Ke.data.workspaceId}`,{withCredentials:!1});t&&bt(1e4*(Number(e.data.costPerRun)||0))}catch(e){console.error("Failed to fetch average cost per run:",e),t&&bt(0)}else t&&bt(0)})),()=>{t=!1}}),[cs,null===(te=null==Ke?void 0:Ke.data)||void 0===te?void 0:te.workspaceId]);const Is=(({currentUses:e,extraUses:t,limit:s,limitInterval:n})=>{const i=Number(null!=e?e:0),o=Number(null!=t?t:0);return s===D.STUDIO_INFINITY_VALUE||o===D.STUDIO_INFINITY_VALUE?D.STUDIO_INFINITY_VALUE:"one_time"===n?Math.max(0,o-i):Math.max(0,s-i)+o})({currentUses:bs.currentUses,extraUses:bs.extraUses,limit:ls,limitInterval:ds}),ys=Is===D.STUDIO_INFINITY_VALUE?D.STUDIO_INFINITY_VALUE:Math.max(0,Math.ceil(Is)),xs=(({extraUses:e,limit:t,limitInterval:s})=>{const n=Number(null!=e?e:0);return t===D.STUDIO_INFINITY_VALUE||n===D.STUDIO_INFINITY_VALUE?D.STUDIO_INFINITY_VALUE:"one_time"===s?Math.max(0,n):Math.max(0,t)+Math.max(0,n)})({extraUses:bs.extraUses,limit:ls,limitInterval:ds}),js=xs===D.STUDIO_INFINITY_VALUE?D.STUDIO_INFINITY_VALUE:Math.ceil(.05*xs),Ss=cs?Math.ceil(5*ht):5,Os=js===D.STUDIO_INFINITY_VALUE?D.STUDIO_INFINITY_VALUE:Math.max(js,Ss),ws=s.useMemo((()=>!!dt&&(!gt&&(ys!==D.STUDIO_INFINITY_VALUE&&(!(ys<=0)&&ys<=Os)))),[gt,Os,ys,dt]),Ns=Boolean(null==je?void 0:je.hideUpgradeOptions),_s=!Ns&&(null===(se=null==je?void 0:je.upgrade)||void 0===se?void 0:se.isLinkToCustomURL)&&"string"==typeof je.upgrade.limitLink&&je.upgrade.limitLink.trim().length>0?je.upgrade.limitLink.trim():null,ks=_s&&"string"==typeof(null===(ne=null==je?void 0:je.upgrade)||void 0===ne?void 0:ne.limitCTA)&&je.upgrade.limitCTA.trim().length>0?je.upgrade.limitCTA:(null==ve?void 0:ve["pricing.upgrade"])||(null==ve?void 0:ve.upgrade)||"Upgrade",Es=s.useMemo((()=>{var e,t,s;return!!Ie&&(!!me&&(!st.isLoading&&(!((null!==(t=null===(e=st.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=me.icebreakers)||void 0===s?void 0:s.length)&&(!xe&&!ss)))))}),[me,Ie,xe,ss,st.data,st.isLoading]),Ts=s.useMemo((()=>{if(Pe||Ve)return!1;const e=Zt&&Fe.length>0&&Fe.every((e=>"finished"===e.status));return!(!nt.trim()&&!e)&&Fe.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[Zt,Pe,Ve,nt,Fe]);s.useImperativeHandle(K,(()=>({onSubmit:Us}))),s.useEffect((()=>{Oe(Es)}),[Es]),s.useEffect((()=>{var e;if(R){const t=Array.from(De),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;Us(s,!0)}}),[R]),s.useEffect((()=>{if(!_t.current||!X)return;const e=new ResizeObserver((e=>{for(const t of e)X(t.contentRect.height)}));return e.observe(_t.current),()=>{e.disconnect()}}),[X]),s.useEffect((()=>{if(!At)return;const e=yt.current?`${yt.current} `:"";it(`${e}${Ct}`)}),[Ct,At]),s.useEffect((()=>{if(!wt.current)return;(()=>{if(!wt.current)return;let e=wt.current.scrollHeight>52;nt.includes("\n")||Fe.length?e=!0:nt.trim()||(e=!1),rt(e)})()}),[nt,Fe]),s.useEffect((()=>{const e=wt.current,t=Nt.current;if(!e||!t||ot||nt.includes("\n"))return void lt(!1);const s=window.getComputedStyle(e),n=`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${s.fontSize} / ${s.lineHeight} ${s.fontFamily}`,i=document.createElement("span");Object.assign(i.style,{font:n,letterSpacing:s.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),i.textContent=nt||os,document.body.appendChild(i);const o=i.offsetWidth;i.remove();const r=parseFloat(s.paddingLeft)||0,a=parseFloat(s.paddingRight)||0,l=e.clientWidth-r-a-t.offsetWidth;lt(o>l)}),[nt,ot,os]);const Us=(t,s=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,n,i,o,r,a;let l=null;try{if(Pe||Ve)return;const d=Fe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),c=d.map((e=>e.documentId)).filter(Boolean),u=d.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),p=null!=t?t:nt,m=null!==(n=null===(e=null==me?void 0:me.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==n&&n&&c.length>0;if(!p&&!m)return;qe(""),He(""),Re(null),it(""),Se(!1),Me("fetching"),Ye(),Ge();const f=null!==(o=null===(i=st.data)||void 0===i?void 0:i.messages)&&void 0!==o?o:[],g=w.getUnpersistedMemoryMessages(De,f),h=s?g.slice(0,g.length-1):g,b=(e=>e.reduce(((e,t)=>Math.max(e,t.id)),0)+1)(h),I=b+(s?0:1),y={id:I,role:"assistant",parts:[],documentIds:[]},x=[...h,...s?[]:[{id:b,role:"user",parts:[{type:"text",content:p,isVisible:!0}],documentIds:m?c:[]}],y];Le(x),Ge(),m&&Xe([]);const j=T.getPickaxeConfigMetadata(ue),S="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`submission-${Date.now()}-${Math.random().toString(36).slice(2)}`;l=S,jt.current=S,St.current=null,Ot.current=[];const O=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/submit`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:oe,pickaxeId:re,sessionId:ae,submissionId:S,senderType:de,value:p},m&&{documentIds:c}),le&&{sender:le}),Te&&{studioSessionToken:Te}),!Te&&!le&&{sender:E.initializeEmbedUserId()}),us&&{portalId:us}),ue&&{deploymentId:ue}),j&&{metadata:j}),m&&u.length>0?{uploadedModelImages:u}:{})),headers:Object.assign(Object.assign({},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()})},Qt&&{credentials:"include"})),N=yield O.json();if(!N.success){if(N.limitData){const e=new Error(N.error||N.message||(null==ve?void 0:ve["failed-to-start-generation"])||"Failed to start generation");throw e.limitData=N.limitData,e}if(is(N))return;throw new Error(N.error||N.message||(null==ve?void 0:ve["failed-to-start-generation"])||"Failed to start generation")}const _=null!==(r=N.submissionId)&&void 0!==r?r:S;l=_,jt.current=_;const k=()=>St.current===_;if(k())return;ts&&Ie&&ae&&Et.current.add(ae);const C=Object.assign(Object.assign({},ms()),{message:p,documentIds:m?c:[],uploadedModelImages:m?u:[],hasUploadedDocuments:m,isHidden:s,metadata:null!=j?j:null});mt?(fs(),U.fireDeploymentFirstMessageSubmittedWebhook(C)):Tt.current=C,Me("streaming"),kt.current=new AbortController;const A=[];let D=[...null!=Je?Je:[]],P=0,R=!1,q="";for(;!R;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/stream/${_}?index=${P}`,{signal:null===(a=kt.current)||void 0===a?void 0:a.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();xt.current=t;const s=new TextDecoder,n=v.createParser({onEvent:e=>{var t,s;if(k())R=!0;else if(e.event&&"ping"!==e.event&&P++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return Re(t.limitData),qe(""),void(R=!0);const s=t.error||t.message||(null==ve?void 0:ve["something-went-wrong"])||"Something went wrong.";return is(t)||qe(s),void(R=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&H){const e=n.data.error;if("string"==typeof e){const t=/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e),s=/['"]type['"]\s*:\s*['"]unauthorized_composio['"]/.test(e);if(t){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);if(t&&t[1]&&s&&s[1]&&n&&n[1])throw R=!0,H({provider:"smithery",smitheryId:t[1],serverId:s[1],name:n[1]}),new Error("STOP_STREAM")}else if(s){const t=e.match(/['"]toolkitSlug['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);if(t&&t[1]&&s&&s[1]&&n&&n[1])throw R=!0,H({provider:"composio",toolkitSlug:t[1],serverId:s[1],name:n[1]}),new Error("STOP_STREAM")}}else if("object"==typeof e&&null!==e){const t=e;if("unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name)throw R=!0,H({provider:"smithery",smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM");if("unauthorized_composio"===t.type&&t.toolkitSlug&&t.serverId&&t.name)throw R=!0,H({provider:"composio",toolkitSlug:t.toolkitSlug,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===n.type)q="",A.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)q+=n.delta,A[A.length-1].content=q;else if("text-end"===n.type)q="";else if("reasoning-start"===n.type)q="",A.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)q+=n.delta,A[A.length-1].content=q;else if("reasoning-end"===n.type)q="";else if(n.type.startsWith("data-")){const e=n;A.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}Ot.current=L(A);const i=L(A);Le((e=>{const t=e.findIndex((e=>e.id===I)),s=Object.assign(Object.assign({},y),{parts:i});return-1===t?[...e,s]:e.map(((e,n)=>n===t?s:e))}))}else if("artifact_created"===e.event){const t=JSON.parse(e.data);D=D.filter((e=>!(e.id===t.id&&e.version===t.version))),D.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Ze([...D]),Qe.startsWith("inline")||et({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);D=D.filter((e=>!(e.id===t.id&&e.version===t.version))),D.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Ze(D),Qe.startsWith("inline")||et({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);D=D.filter((e=>!(e.id===t.id&&e.version===t.version))),D.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Ze(D),Qe.startsWith("inline")||et({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");D=D.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Ze(D)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Ze(D.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return Re(t.limitData),qe(""),void(R=!0);const s=t.error||t.message||(null==ve?void 0:ve["something-went-wrong-try-again"])||"Something went wrong, please try again.";if(is(t))return void(R=!0);qe(s)}else"stop"===e.event&&(R=!0)}else R=!0}});for(;;){if(k()){R=!0,t.cancel().catch((()=>{}));break}const{value:e,done:i}=yield t.read();if(k()){R=!0,t.cancel().catch((()=>{}));break}if(i)break;n.feed(s.decode(e))}R||k()||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||M(e)||k())return void(R=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==Ee||Ee(ae)}catch(e){if(M(e))return;if(e.limitData)Re(e.limitData),qe("");else{let t=O.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==ve?void 0:ve["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),is(t)||qe(t)}}finally{const e=!l||jt.current===l;Ge(),e&&(Me("idle"),ze(),xt.current=null),l&&e&&(jt.current=null,Ot.current=[]),yield as()}}));return ns?null:t.jsx("div",Object.assign({className:k.default("flex w-full flex-shrink-0 flex-col items-center",!ss&&"px-4 pb-8"),dir:ye?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[t.jsxs("div",Object.assign({ref:_t,className:k.default("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===fe.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},Yt),{maxHeight:`${Ut}px`,overflowY:"auto"})},{children:[ws&&t.jsxs("div",Object.assign({className:"sticky top-0 z-10 flex w-full items-center justify-between border-b px-4 py-2.5 shadow-sm backdrop-blur-md",style:{backgroundColor:Yt.backgroundColor?`${Yt.backgroundColor}E6`:void 0,borderColor:ge.text+"20",color:ge.text,borderTopRightRadius:fe.cornerRadius+"px",borderTopLeftRadius:fe.cornerRadius+"px"}},{children:[t.jsx("div",Object.assign({className:"flex items-center gap-2 text-sm font-medium"},{children:t.jsxs("span",{children:[ys.toLocaleString()," ",cs?(null==ve?void 0:ve.credits)||"Credits":(null==ve?void 0:ve.uses)||"Uses"," ",(null==ve?void 0:ve.remaining)||"remaining"]})})),t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[!Ns&&t.jsx("button",Object.assign({className:"rounded-md px-3 py-1.5 text-xs font-semibold transition-opacity hover:opacity-90",style:{backgroundColor:ge.accent,color:ge.accentText},onClick:e=>{if(e.preventDefault(),e.stopPropagation(),_s)return void window.open(_s,"_blank","noopener,noreferrer");const t=E.buildUpgradeUrl({baseUrl:ut,accessGroupId:null==je?void 0:je.accessGroupId,redirectUrl:document.URL});t&&(E.isInIframe()?window.open(t):location.href=t)}},{children:ks})),t.jsx("button",Object.assign({className:"flex h-6 w-6 items-center justify-center rounded-full opacity-60 transition-opacity hover:opacity-100",onClick:()=>vt(!0)},{children:t.jsx("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",className:"h-4 w-4"},{children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}))}))]}))]})),!Pe&&Fe.length>0&&t.jsx(x.default,{className:"p-4 pb-0",isDisabled:Pe}),t.jsxs("div",Object.assign({className:"relative flex w-full flex-col"},{children:[At&&t.jsxs("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(ie=ge.accent)&&void 0!==ie?ie:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:ge.text+"90"}},{children:(null==ve?void 0:ve.listening)||"Listening..."}))]})),t.jsx(j.default,Object.assign({ref:wt,className:k.default(Wt.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!nt.trim()&&!nt.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",ye?"text-right":"text-left",rs&&"mb-12",At&&"text-transparent"),value:nt,placeholder:os,onChange:e=>{it(e)},onKeyDown:e=>{be||We||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),Ve||Pe||Us()))},onPaste:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Array.from(t.clipboardData.files||[]);if(e.length>0){if(!Zt)return;t.preventDefault(),Se(!1),yield $e(e)}}))},B&&{onFocus:B},$&&{onBlur:$},{dir:ye?"rtl":"ltr"})),t.jsx("div",Object.assign({ref:Nt,className:k.default("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",rs?"bottom-0 mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!rs&&Yt.backgroundColor&&{backgroundColor:Yt.backgroundColor}),{borderTopRightRadius:fe.cornerRadius+"px",borderBottomRightRadius:fe.cornerRadius+"px"})},{children:Pe?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{const t=jt.current;t&&(St.current=t,(t=>{e.__awaiter(void 0,void 0,void 0,(function*(){if(!(t=null!=t?t:jt.current))return;const e=L(Ot.current);try{yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/cancel/${t}`,Object.assign({method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()}),body:JSON.stringify({outputMessageParts:e})},Qt&&{credentials:"include"}))}catch(e){console.warn("Failed to cancel submission",e)}}))})(t)),kt.current&&(kt.current.abort(),kt.current=null),xt.current&&(xt.current.cancel().catch((()=>{})),xt.current=null),Me("idle")},style:{backgroundColor:ge.accent,color:ge.accentText}},{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):At?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:Mt,style:{backgroundColor:ge.accent,color:ge.accentText}},{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[Zt&&t.jsxs("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Bt?ge.accent+"10":void 0,color:Bt?ge.accent:ge.accent+"80"},disabled:Ve||Pe,onClick:()=>{var e;return null===(e=It.current)||void 0===e?void 0:e.click()}},$t,{children:[t.jsx("input",{id:"file-upload",ref:It,type:"file",accept:[...g.allowedFileMimeTypes,...g.allowedImageMimeTypes,...g.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){Se(!1),yield $e(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(h.default,{className:"h-6 w-6 shrink-0"})]})),es&&t.jsx("button",Object.assign({className:"disabled:cursor-default flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:At?ge.accent:Ht?ge.accent+"10":void 0,color:At?ge.accentText:Ht?ge.accent:ge.accent+"80"},disabled:Ve||Pe||Dt,onClick:()=>{At?Mt():(yt.current=nt,Lt(he||"en-US"))}},Kt,{children:t.jsx(I.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:qt||Ts?ge.accent:ge.accent+"10",color:qt||Ts?ge.accentText:ge.accent+"80"},disabled:!Ts,onClick:()=>Us()},Ft,{children:t.jsx(b.default,{className:k.default("h-6 w-6 shrink-0",ye&&"scale-x-[-1] transform")})}))]})}))]}))]})),Be&&t.jsx(S.default,{error:Be,className:"mt-3"})]}))}))}));B.displayName="Input",exports.default=B;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("react"),n=require("../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../../hooks/pickaxe/useResponseContext.js"),o=require("../../../../hooks/studio/useStyleInput.js"),a=require("../../../../hooks/studio/useStyleFontSize.js"),r=require("../../../../hooks/core/useHover.js"),l=require("../../../../hooks/pickaxe/
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("react"),n=require("../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../../hooks/pickaxe/useResponseContext.js"),o=require("../../../../hooks/studio/useStyleInput.js"),a=require("../../../../hooks/studio/useStyleFontSize.js"),r=require("../../../../hooks/core/useHover.js"),l=require("../../../../hooks/pickaxe/useSpeechToText.js"),c=require("../../../Core/Textarea.js"),u=require("../../../Icons/microphone.svg.js"),d=require("../../../Icons/stop.svg.js"),p=require("../../../../common/cn.js");exports.default=({field:x,update:h,activeVoiceId:g,setActiveVoiceId:j,onLongPaste:b})=>{var f;const{styles:m,colors:v,isRtl:y,pickaxe:k,locale:O,translations:S}=n.usePickaxeContext(),{setError:N}=i.useResponseContext(),[q,w]=t.useState(!1),C=a.useStyleFontSize(),L=o.useStyleInput(),{speechTranscript:_,isSpeechListening:I,isSpeechProcessing:T,isSpeechSupported:P,onStartListening:R,onStopListening:z}=l.useSpeechToText(),F=t.useRef(""),H=r.useHover(),{isHover:$}=H,D=e.__rest(H,["isHover"]),E=P&&(null==k?void 0:k.enablevoicetotext),V=I&&g===x.id,A=e=>{N("");const s=e.length;h(Object.assign(Object.assign({},x),{input:e,length:s}))};return t.useEffect((()=>{if(!I||g!==x.id)return;const e=F.current?`${F.current} `:"";A(`${e}${_}`)}),[_,I,g,x.id]),s.jsxs("div",Object.assign({className:"group relative flex flex-col gap-y-1",dir:y?"rtl":"ltr"},{children:[s.jsxs("div",Object.assign({className:"flex flex-col gap-y-2"},{children:[s.jsxs("div",Object.assign({className:"flex items-center gap-1"},{children:[s.jsx("p",Object.assign({className:p.default(C.b3,"font-semibold opacity-70")},{children:x.main})),x.isRequired&&s.jsx("span",Object.assign({className:"select-none font-semibold",style:{color:v.accent}},{children:"*"}))]})),s.jsxs("div",Object.assign({className:"relative w-full"},{children:[V&&s.jsxs("div",Object.assign({className:p.default("absolute top-3.5 z-10 flex select-none items-center gap-x-2 pointer-events-none",y?"right-4":"left-4")},{children:[s.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full",style:{backgroundColor:null!==(f=v.accent)&&void 0!==f?f:"#ff0000"}}),s.jsx("span",Object.assign({className:"text-sm font-semilight",style:{color:v.text+"90"}},{children:(null==S?void 0:S.listening)||"Listening..."}))]})),s.jsx(c.default,{className:p.default(C.i1,"rounded-sm border border-transparent py-3 duration-300 ease-in-out transition-all placeholder:font-semilight w-full",y?E?"pl-10 pr-4":"px-4":E?"pl-4 pr-10":"px-4",x.maxLength<10&&"max-w-[400px]","block"===m.formFieldStyle&&"shadow hover:shadow-none",V&&"caret-transparent"),style:Object.assign(Object.assign({},L),V&&{color:"transparent"}),placeholder:V?"":x.placeholder,rows:1,value:x.input,tabIndex:x.order,onChange:A,onFocus:()=>w(!0),onBlur:()=>w(!1),onPaste:e=>{e.clipboardData.getData("text").length<1e3||null==b||b()}}),E&&s.jsx("div",Object.assign({className:p.default("absolute top-2 z-20",y?"left-2":"right-2")},{children:s.jsx("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:V?v.accent:$?v.accent+"10":void 0,color:V?v.accentText:$?v.accent:v.accent+"80"},disabled:T,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){I?(yield z(),j(x.id)):(j(x.id),F.current=x.input||"",yield R(O||"en-US"),w(!0))}))},D,{type:"button"},{children:V?s.jsx(d.default,{className:"h-4 w-4 shrink-0"}):s.jsx(u.default,{className:"h-5 w-5 shrink-0"})}))}))]}))]})),s.jsx("div",Object.assign({className:"pointer-events-none absolute bottom-0 right-0 p-1 px-2"},{children:s.jsxs("p",Object.assign({className:p.default(C.b4,"font-semibold opacity-20 opacity-0 group-hover:opacity-100 group-hover:duration-200",x.length>x.maxLength&&"text-c-red opacity-100",q&&"opacity-100")},{children:[x.length,"/",x.maxLength]}))}))]}))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../hooks/studio/useStyleFontSize.js"),i=require("../../../hooks/pickaxe/usePickaxeContext.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../hooks/studio/useStyleFontSize.js"),i=require("../../../hooks/pickaxe/usePickaxeContext.js"),a=require("../../../hooks/pickaxe/useFeedback.js"),t=require("framer-motion"),l=require("../../Icons/message-square-notes.svg.js"),n=require("../../Icons/thumbs-down.svg.js"),c=require("../../Icons/speaker.svg.js"),o=require("../../Icons/stop.svg.js"),r=require("../../Icons/spinner-lines.svg.js"),u=require("../../Icons/thumbs-up.svg.js"),d=require("./PickaxeSimpleButton.js"),p=require("./PickaxeCopyButton.js"),x=require("./PickaxeFeedbackThumbsDownReasons.js"),b=require("../../../common/cn.js");exports.default=({content:m,sessionId:h,index:j=0,messagesCount:f,isHideFeedback:g,isReadOut:v,isReadOutLoading:k,isReading:y,onOpenChat:O,onReadOut:w})=>{var N,q,T,C;const{colors:I,translations:S,pickaxe:D,setIsShowFeedbackMessage:F}=i.usePickaxeContext(),P=s.useStyleFontSize(),{toggleThumb:R,submitThumbsDown:z,submitThumbsUp:U,isThumbsUpSelected:B,isThumbsDownSelected:A,showThumbsDownOptions:H,showThumbsUpOptions:M,showSuccess:W}=a.useFeedback({content:m,index:j,sessionId:h,successDuration:2e3,promptRate:1,onThumbsDownReasonOpen:()=>F(!0),onThumbsDownReasonClose:()=>F(!1)}),_="function"==typeof O&&((null==D?void 0:D.chatflag)||!!(null==D?void 0:D.enablechatresponses))&&void 0!==h&&void 0!==f,L=Boolean(((null==D?void 0:D.chatflag)||(null==D?void 0:D.enablechatresponses))&&!O||!(null==D?void 0:D.chatflag)&&!(null==D?void 0:D.enablechatresponses))&&!g;return e.jsxs("div",Object.assign({className:"flex w-full flex-col gap-4"},{children:[e.jsxs("div",Object.assign({className:"flex h-4 items-center gap-3"},{children:[_&&e.jsxs(d.default,Object.assign({color:I.accent,onClick:O},{children:[e.jsx(l.default,{className:"h-4 w-4 shrink-0"}),e.jsx("p",Object.assign({className:b.default(P.b3,"font-semibold")},{children:f}))]})),e.jsx(p.default,{color:I.accent,text:m}),L&&e.jsxs(e.Fragment,{children:[e.jsx(d.default,Object.assign({color:I.accent,onClick:()=>R("like"),className:"transition-all active:rotate-12 active:scale-90"},{children:e.jsx(u.default,{className:"size-4",style:{fill:I.text,fillOpacity:B?.3:0}})})),e.jsx(d.default,Object.assign({color:I.accent,onClick:()=>R("dislike"),className:"transition-all active:-rotate-12 active:scale-90"},{children:e.jsx(n.default,{className:"size-4",style:{fill:I.text,fillOpacity:A?.3:0}})})),v&&w&&e.jsx(d.default,Object.assign({color:I.accent,onClick:()=>w(),className:"transition-all active:-rotate-12 active:scale-90"},{children:k?e.jsx(r.default,{className:"size-4 animate-spin"}):y?e.jsx(o.default,{className:"size-4 rounded-full border p-[1.5px]",style:{borderColor:I.accent}}):e.jsx(c.default,{className:"size-4"})})),e.jsx(t.AnimatePresence,{children:W&&e.jsx(t.motion.div,Object.assign({initial:{opacity:0,x:-8,filter:"blur(4px)"},animate:{opacity:1,x:0,filter:"blur(0px)"},exit:{opacity:0,x:8,filter:"blur(4px)"},transition:{type:"spring",bounce:0,duration:.6}},{children:e.jsx("p",Object.assign({className:b.default(P.b4,I.secondary,"opacity-75")},{children:null!==(N=null==S?void 0:S["feedback-thanks"])&&void 0!==N?N:"Thanks for the feedback!"}))}))})]})]})),e.jsx(t.AnimatePresence,{children:(H||M)&&e.jsxs(t.motion.div,Object.assign({initial:{opacity:0,y:-4,filter:"blur(4px)"},animate:{opacity:1,y:0,filter:"blur(0px)"},exit:{opacity:0,y:-2,filter:"blur(4px)"},transition:{type:"spring",bounce:0,duration:.25},className:"flex flex-col gap-4"},{children:[e.jsxs("div",Object.assign({className:"space-y-0.5"},{children:[e.jsx("p",Object.assign({className:b.default(P.b3,I.text)},{children:M?null!==(q=null==S?void 0:S["feedback-like-title"])&&void 0!==q?q:"What went right?":null!==(T=null==S?void 0:S["feedback-dislike-title"])&&void 0!==T?T:"What went wrong?"})),e.jsx("p",Object.assign({className:b.default(P.b3,I.secondary,"opacity-75")},{children:null!==(C=null==S?void 0:S["feedback-dislike-message"])&&void 0!==C?C:"Help us improve our answers"}))]})),e.jsx(t.motion.div,Object.assign({initial:{opacity:0,y:-8,filter:"blur(4px)"},animate:{opacity:1,y:0,filter:"blur(0px)"},transition:{type:"spring",bounce:0,duration:.5,delay:.175},className:"flex flex-wrap items-center gap-2"},{children:e.jsx(x.default,{isUp:M,submitThumbsDown:z,submitThumbsUp:U})}))]}))})]}))};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js");require("../../node_modules/.pnpm/regenerator-runtime@0.14.1/node_modules/regenerator-runtime/runtime.js");var t=require("react-speech-recognition"),r=require("react"),i=require("../../common/api/pickaxe.js");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=n(t);exports.useSpeechToText=()=>{const{transcript:n,listening:a,resetTranscript:c}=t.useSpeechRecognition(),[u,l]=r.useState(!1),[p,d]=r.useState(!1);return{speechTranscript:n,isSpeechSupported:!0,isSpeechProcessing:u,isSpeechListening:a,onStartListening:t=>e.__awaiter(void 0,void 0,void 0,(function*(){try{l(!0),yield navigator.mediaDevices.getUserMedia({audio:!0});const e=(yield i.pickaxeApi2.post("/speech")).data;if(!p){const{createSpeechServicesPonyfill:t}=yield Promise.resolve().then((function(){return o(require("web-speech-cognitive-services"))})),{SpeechRecognition:r}=t({credentials:{region:"eastus",authorizationToken:e.token}});s.default.applyPolyfill(r),d(!0)}c();const r={ar:"ar-SA",ca:"ca-ES",cs:"cs-CZ",da:"da-DK",de:"de-DE",en:"en-US",es:"es-ES",fi:"fi-FI",fr:"fr-FR",hi:"hi-IN",it:"it-IT",iw:"he-IL",ja:"ja-JP",ko:"ko-KR",nb:"nb-NO",nl:"nl-NL",pl:"pl-PL",pt:"pt-PT","pt-BR":"pt-BR",ro:"ro-RO",ru:"ru-RU",sv:"sv-SE",th:"th-TH",tr:"tr-TR",vi:"vi-VN",zh:"zh-CN",zu:"zu-ZA"};yield s.default.startListening({continuous:!0,interimResults:!0,language:r[t]||"en-US"})}catch(e){console.error(e)}finally{l(!1)}})),onStopListening:()=>e.__awaiter(void 0,void 0,void 0,(function*(){try{l(!0),yield s.default.abortListening()}catch(e){console.error(e)}finally{l(!1)}}))}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),n=require("../../common/api/pickaxe.js"),t=require("react");function r(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}})),n.default=e,Object.freeze(n)}const s={ar:"ar-SA",ca:"ca-ES",cs:"cs-CZ",da:"da-DK",de:"de-DE",en:"en-US",es:"es-ES",fi:"fi-FI",fr:"fr-FR",he:"he-IL",hi:"hi-IN",it:"it-IT",ja:"ja-JP",ko:"ko-KR",nb:"nb-NO",nl:"nl-NL",pl:"pl-PL",pt:"pt-PT",ro:"ro-RO",ru:"ru-RU",sv:"sv-SE",th:"th-TH",tr:"tr-TR",vi:"vi-VN",zh:"zh-CN",zu:"zu-ZA"};let o=null;const i=new Map,c=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),l=({text:t,language:l,browserVoices:u=[],onLoading:a,onPlay:p,onEnd:d})=>{var h;null==o||o.cancel(),null===(h=window.speechSynthesis)||void 0===h||h.cancel();let f=null,w=null,v=!1,g=!1,S=!1;const y=()=>{g||(g=!0,null==f||f.close(),f=null,o===k&&(o=null),d())},m=()=>{v||g||p()},k={cancel:()=>{var e;v||g||(v=!0,null==w||w.close(),w=null,null==f||f.pause(),null==f||f.close(),f=null,null===(e=window.speechSynthesis)||void 0===e||e.cancel(),y())}};o=k,a();return e.__awaiter(void 0,void 0,void 0,(function*(){var e;try{const[{data:o},u]=yield Promise.all([n.pickaxeApi2.post("/speech"),Promise.resolve().then((function(){return r(require("microsoft-cognitiveservices-speech-sdk"))}))]);if(!o.success||!o.token)throw new Error(o.error||"Azure Speech token was not returned");if(v||g)return;const a=(e=>{if(!e)return"en-US";const n=e.toLowerCase();return"pt-br"===n?"pt-BR":s[n.split("-")[0]]||e})(l),p=u.SpeechConfig.fromAuthorizationToken(o.token,"eastus");p.speechSynthesisLanguage=a,p.speechSynthesisOutputFormat=u.SpeechSynthesisOutputFormat.Audio24Khz48KBitRateMonoMp3;const d=new u.SpeakerAudioDestination;d.onAudioStart=()=>{const e=d.internalAudio;e?e.addEventListener("playing",m,{once:!0}):m()},d.onAudioEnd=y,f=d;const h=u.AudioConfig.fromSpeakerOutput(d),S=new u.SpeechSynthesizer(p,h);w=S;let k=i.get(a);if(!k){const n=yield S.getVoicesAsync(a);if(v||g)return;if(k=null===(e=n.voices.find((e=>e.locale===a)))||void 0===e?void 0:e.shortName,!k)throw new Error(`No Azure voice is available for ${a}`);i.set(a,k)}const b=k,A=yield new Promise(((e,n)=>{const r=`<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="${a}"><voice name="${c(b)}"><break time="500ms"/>${c(t)}</voice></speak>`;S.speakSsmlAsync(r,e,n)}));if(S.close(),w=null,v||g)return;if(A.reason!==u.ResultReason.SynthesizingAudioCompleted)throw new Error(A.errorDetails||"Azure speech synthesis failed")}catch(e){if(null==w||w.close(),w=null,null==f||f.close(),f=null,v||g)return;console.warn("Azure text-to-speech failed; using browser speech",e),(()=>{if(v||g||S)return;if(S=!0,!("speechSynthesis"in window)||!("SpeechSynthesisUtterance"in window))return void y();const e=new SpeechSynthesisUtterance(t),n=l||"en",r=u.find((e=>e.lang.startsWith(n)&&e.name.includes("Google")))||u.find((e=>e.lang.startsWith(n)));r?(e.voice=r,e.lang=r.lang):e.lang=n,e.onstart=m,e.onend=y,e.onerror=y,window.speechSynthesis.speak(e)})()}})),k};exports.useTextToSpeech=(e=!0)=>{const[n,r]=t.useState(!1),[s,o]=t.useState(!1),[i,c]=t.useState([]),u=t.useRef(null),a=t.useRef(!0);t.useEffect((()=>(a.current=!0,()=>{var e;a.current=!1,null===(e=u.current)||void 0===e||e.cancel(),u.current=null})),[]),t.useEffect((()=>{if(!e||!("speechSynthesis"in window))return;const n=()=>{const e=window.speechSynthesis.getVoices();e.length>0&&c(e)};return n(),window.speechSynthesis.addEventListener("voiceschanged",n),()=>{window.speechSynthesis.removeEventListener("voiceschanged",n)}}),[e]);const p=t.useCallback((()=>{var e;null===(e=u.current)||void 0===e||e.cancel(),u.current=null}),[]);return{isLoading:n,isSpeaking:s,speak:t.useCallback(((e,n)=>{if(!e)return;const t=l({text:e,language:n,browserVoices:i,onLoading:()=>{a.current&&(r(!0),o(!1))},onPlay:()=>{a.current&&(r(!1),o(!0))},onEnd:()=>{u.current===t&&(u.current=null),a.current&&(r(!1),o(!1))}});u.current=t}),[i]),stop:p}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("../../../../../_virtual/_commonjsHelpers.js"),r=require("../../../../../_virtual/cose-base.js"),i=require("../../../layout-base@1.0.2/node_modules/layout-base/layout-base.js");r.__module.exports,exports.__require=function(){return t||(t=1,o=r.__module,r.__module.exports,e.commonjsGlobal,n=function(t){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(e,r){e.exports=t},function(t,e,r){var i=r(0).FDLayoutConstants;function o(){}for(var n in i)o[n]=i[n];o.DEFAULT_USE_MULTI_LEVEL_SCALING=!1,o.DEFAULT_RADIAL_SEPARATION=i.DEFAULT_EDGE_LENGTH,o.DEFAULT_COMPONENT_SEPERATION=60,o.TILE=!0,o.TILING_PADDING_VERTICAL=10,o.TILING_PADDING_HORIZONTAL=10,o.TREE_REDUCTION_ON_INCREMENTAL=!1,t.exports=o},function(t,e,r){var i=r(0).FDLayoutEdge;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraph;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraphManager;function o(t){i.call(this,t)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).FDLayoutNode,o=r(0).IMath;function n(t,e,r,o){i.call(this,t,e,r,o)}for(var a in n.prototype=Object.create(i.prototype),i)n[a]=i[a];n.prototype.move=function(){var t=this.graphManager.getLayout();this.displacementX=t.coolingFactor*(this.springForceX+this.repulsionForceX+this.gravitationForceX)/this.noOfChildren,this.displacementY=t.coolingFactor*(this.springForceY+this.repulsionForceY+this.gravitationForceY)/this.noOfChildren,Math.abs(this.displacementX)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementX=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementX)),Math.abs(this.displacementY)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementY=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementY)),null==this.child||0==this.child.getNodes().length?this.moveBy(this.displacementX,this.displacementY):this.propogateDisplacementToChildren(this.displacementX,this.displacementY),t.totalDisplacement+=Math.abs(this.displacementX)+Math.abs(this.displacementY),this.springForceX=0,this.springForceY=0,this.repulsionForceX=0,this.repulsionForceY=0,this.gravitationForceX=0,this.gravitationForceY=0,this.displacementX=0,this.displacementY=0},n.prototype.propogateDisplacementToChildren=function(t,e){for(var r,i=this.getChild().getNodes(),o=0;o<i.length;o++)null==(r=i[o]).getChild()?(r.moveBy(t,e),r.displacementX+=t,r.displacementY+=e):r.propogateDisplacementToChildren(t,e)},n.prototype.setPred1=function(t){this.pred1=t},n.prototype.getPred1=function(){return pred1},n.prototype.getPred2=function(){return pred2},n.prototype.setNext=function(t){this.next=t},n.prototype.getNext=function(){return next},n.prototype.setProcessed=function(t){this.processed=t},n.prototype.isProcessed=function(){return processed},t.exports=n},function(t,e,r){var i=r(0).FDLayout,o=r(4),n=r(3),a=r(5),s=r(2),h=r(1),d=r(0).FDLayoutConstants,g=r(0).LayoutConstants,l=r(0).Point,p=r(0).PointD,c=r(0).Layout,u=r(0).Integer,f=r(0).IGeometry,v=r(0).LGraph,T=r(0).Transform;function E(){i.call(this),this.toBeTiled={}}for(var m in E.prototype=Object.create(i.prototype),i)E[m]=i[m];E.prototype.newGraphManager=function(){var t=new o(this);return this.graphManager=t,t},E.prototype.newGraph=function(t){return new n(null,this.graphManager,t)},E.prototype.newNode=function(t){return new a(this.graphManager,t)},E.prototype.newEdge=function(t){return new s(null,null,t)},E.prototype.initParameters=function(){i.prototype.initParameters.call(this,arguments),this.isSubLayout||(h.DEFAULT_EDGE_LENGTH<10?this.idealEdgeLength=10:this.idealEdgeLength=h.DEFAULT_EDGE_LENGTH,this.useSmartIdealEdgeLengthCalculation=h.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION,this.springConstant=d.DEFAULT_SPRING_STRENGTH,this.repulsionConstant=d.DEFAULT_REPULSION_STRENGTH,this.gravityConstant=d.DEFAULT_GRAVITY_STRENGTH,this.compoundGravityConstant=d.DEFAULT_COMPOUND_GRAVITY_STRENGTH,this.gravityRangeFactor=d.DEFAULT_GRAVITY_RANGE_FACTOR,this.compoundGravityRangeFactor=d.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR,this.prunedNodesAll=[],this.growTreeIterations=0,this.afterGrowthIterations=0,this.isTreeGrowing=!1,this.isGrowthFinished=!1,this.coolingCycle=0,this.maxCoolingCycle=this.maxIterations/d.CONVERGENCE_CHECK_PERIOD,this.finalTemperature=d.CONVERGENCE_CHECK_PERIOD/this.maxIterations,this.coolingAdjuster=1)},E.prototype.layout=function(){return g.DEFAULT_CREATE_BENDS_AS_NEEDED&&(this.createBendpoints(),this.graphManager.resetAllEdges()),this.level=0,this.classicLayout()},E.prototype.classicLayout=function(){if(this.nodesWithGravity=this.calculateNodesToApplyGravitationTo(),this.graphManager.setAllNodesToApplyGravitation(this.nodesWithGravity),this.calcNoOfChildrenForAllNodes(),this.graphManager.calcLowestCommonAncestors(),this.graphManager.calcInclusionTreeDepths(),this.graphManager.getRoot().calcEstimatedSize(),this.calcIdealEdgeLengths(),this.incremental)h.TREE_REDUCTION_ON_INCREMENTAL&&(this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation(),e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)})),this.graphManager.setAllNodesToApplyGravitation(r));else{var t=this.getFlatForest();if(t.length>0)this.positionNodesRadially(t);else{this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation();var e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)}));this.graphManager.setAllNodesToApplyGravitation(r),this.positionNodesRandomly()}}return this.initSpringEmbedder(),this.runSpringEmbedder(),!0},E.prototype.tick=function(){if(this.totalIterations++,this.totalIterations===this.maxIterations&&!this.isTreeGrowing&&!this.isGrowthFinished){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}if(this.totalIterations%d.CONVERGENCE_CHECK_PERIOD==0&&!this.isTreeGrowing&&!this.isGrowthFinished){if(this.isConverged()){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}this.coolingCycle++,0==this.layoutQuality?this.coolingAdjuster=this.coolingCycle:1==this.layoutQuality&&(this.coolingAdjuster=this.coolingCycle/3),this.coolingFactor=Math.max(this.initialCoolingFactor-Math.pow(this.coolingCycle,Math.log(100*(this.initialCoolingFactor-this.finalTemperature))/Math.log(this.maxCoolingCycle))/100*this.coolingAdjuster,this.finalTemperature),this.animationPeriod=Math.ceil(this.initialAnimationPeriod*Math.sqrt(this.coolingFactor))}if(this.isTreeGrowing){if(this.growTreeIterations%10==0)if(this.prunedNodesAll.length>0){this.graphManager.updateBounds(),this.updateGrid(),this.growTree(this.prunedNodesAll),this.graphManager.resetAllNodesToApplyGravitation();var t=new Set(this.getAllNodes()),e=this.nodesWithGravity.filter((function(e){return t.has(e)}));this.graphManager.setAllNodesToApplyGravitation(e),this.graphManager.updateBounds(),this.updateGrid(),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL}else this.isTreeGrowing=!1,this.isGrowthFinished=!0;this.growTreeIterations++}if(this.isGrowthFinished){if(this.isConverged())return!0;this.afterGrowthIterations%10==0&&(this.graphManager.updateBounds(),this.updateGrid()),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL*((100-this.afterGrowthIterations)/100),this.afterGrowthIterations++}var r=!this.isTreeGrowing&&!this.isGrowthFinished,i=this.growTreeIterations%10==1&&this.isTreeGrowing||this.afterGrowthIterations%10==1&&this.isGrowthFinished;return this.totalDisplacement=0,this.graphManager.updateBounds(),this.calcSpringForces(),this.calcRepulsionForces(r,i),this.calcGravitationalForces(),this.moveNodes(),this.animate(),!1},E.prototype.getPositionsData=function(){for(var t=this.graphManager.getAllNodes(),e={},r=0;r<t.length;r++){var i=t[r].rect,o=t[r].id;e[o]={id:o,x:i.getCenterX(),y:i.getCenterY(),w:i.width,h:i.height}}return e},E.prototype.runSpringEmbedder=function(){this.initialAnimationPeriod=25,this.animationPeriod=this.initialAnimationPeriod;var t=!1;if("during"===d.ANIMATE)this.emit("layoutstarted");else{for(;!t;)t=this.tick();this.graphManager.updateBounds()}},E.prototype.calculateNodesToApplyGravitationTo=function(){var t,e,r=[],i=this.graphManager.getGraphs(),o=i.length;for(e=0;e<o;e++)(t=i[e]).updateConnected(),t.isConnected||(r=r.concat(t.getNodes()));return r},E.prototype.createBendpoints=function(){var t=[];t=t.concat(this.graphManager.getAllEdges());var e,r=new Set;for(e=0;e<t.length;e++){var i=t[e];if(!r.has(i)){var o=i.getSource(),n=i.getTarget();if(o==n)i.getBendpoints().push(new p),i.getBendpoints().push(new p),this.createDummyNodesForBendpoints(i),r.add(i);else{var a=[];if(a=(a=a.concat(o.getEdgeListToNode(n))).concat(n.getEdgeListToNode(o)),!r.has(a[0])){var s;if(a.length>1)for(s=0;s<a.length;s++){var h=a[s];h.getBendpoints().push(new p),this.createDummyNodesForBendpoints(h)}a.forEach((function(t){r.add(t)}))}}}if(r.size==t.length)break}},E.prototype.positionNodesRadially=function(t){for(var e=new l(0,0),r=Math.ceil(Math.sqrt(t.length)),i=0,o=0,n=0,a=new p(0,0),s=0;s<t.length;s++){s%r==0&&(n=0,o=i,0!=s&&(o+=h.DEFAULT_COMPONENT_SEPERATION),i=0);var d=t[s],u=c.findCenterOfTree(d);e.x=n,e.y=o,(a=E.radialLayout(d,u,e)).y>i&&(i=Math.floor(a.y)),n=Math.floor(a.x+h.DEFAULT_COMPONENT_SEPERATION)}this.transform(new p(g.WORLD_CENTER_X-a.x/2,g.WORLD_CENTER_Y-a.y/2))},E.radialLayout=function(t,e,r){var i=Math.max(this.maxDiagonalInTree(t),h.DEFAULT_RADIAL_SEPARATION);E.branchRadialLayout(e,null,0,359,0,i);var o=v.calculateBounds(t),n=new T;n.setDeviceOrgX(o.getMinX()),n.setDeviceOrgY(o.getMinY()),n.setWorldOrgX(r.x),n.setWorldOrgY(r.y);for(var a=0;a<t.length;a++)t[a].transform(n);var s=new p(o.getMaxX(),o.getMaxY());return n.inverseTransformPoint(s)},E.branchRadialLayout=function(t,e,r,i,o,n){var a=(i-r+1)/2;a<0&&(a+=180);var s=(a+r)%360*f.TWO_PI/360,h=o*Math.cos(s),d=o*Math.sin(s);t.setCenter(h,d);var g=[],l=(g=g.concat(t.getEdges())).length;null!=e&&l--;for(var p,c=0,u=g.length,v=t.getEdgesBetween(e);v.length>1;){var T=v[0];v.splice(0,1);var m=g.indexOf(T);m>=0&&g.splice(m,1),u--,l--}p=null!=e?(g.indexOf(v[0])+1)%u:0;for(var y=Math.abs(i-r)/l,N=p;c!=l;N=++N%u){var w=g[N].getOtherEnd(t);if(w!=e){var A=(r+c*y)%360,C=(A+y)%360;E.branchRadialLayout(w,t,A,C,o+n,n),c++}}},E.maxDiagonalInTree=function(t){for(var e=u.MIN_VALUE,r=0;r<t.length;r++){var i=t[r].getDiagonal();i>e&&(e=i)}return e},E.prototype.calcRepulsionRange=function(){return 2*(this.level+1)*this.idealEdgeLength},E.prototype.groupZeroDegreeMembers=function(){var t=this,e={};this.memberGroups={},this.idToDummyNode={};for(var r=[],i=this.graphManager.getAllNodes(),o=0;o<i.length;o++){var n=(s=i[o]).getParent();0!==this.getNodeDegreeWithChildren(s)||null!=n.id&&this.getToBeTiled(n)||r.push(s)}for(o=0;o<r.length;o++){var s,h=(s=r[o]).getParent().id;void 0===e[h]&&(e[h]=[]),e[h]=e[h].concat(s)}Object.keys(e).forEach((function(r){if(e[r].length>1){var i="DummyCompound_"+r;t.memberGroups[i]=e[r];var o=e[r][0].getParent(),n=new a(t.graphManager);n.id=i,n.paddingLeft=o.paddingLeft||0,n.paddingRight=o.paddingRight||0,n.paddingBottom=o.paddingBottom||0,n.paddingTop=o.paddingTop||0,t.idToDummyNode[i]=n;var s=t.getGraphManager().add(t.newGraph(),n),h=o.getChild();h.add(n);for(var d=0;d<e[r].length;d++){var g=e[r][d];h.remove(g),s.add(g)}}}))},E.prototype.clearCompounds=function(){var t={},e={};this.performDFSOnCompounds();for(var r=0;r<this.compoundOrder.length;r++)e[this.compoundOrder[r].id]=this.compoundOrder[r],t[this.compoundOrder[r].id]=[].concat(this.compoundOrder[r].getChild().getNodes()),this.graphManager.remove(this.compoundOrder[r].getChild()),this.compoundOrder[r].child=null;this.graphManager.resetAllNodes(),this.tileCompoundMembers(t,e)},E.prototype.clearZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack=[];Object.keys(this.memberGroups).forEach((function(r){var i=t.idToDummyNode[r];e[r]=t.tileNodes(t.memberGroups[r],i.paddingLeft+i.paddingRight),i.rect.width=e[r].width,i.rect.height=e[r].height}))},E.prototype.repopulateCompounds=function(){for(var t=this.compoundOrder.length-1;t>=0;t--){var e=this.compoundOrder[t],r=e.id,i=e.paddingLeft,o=e.paddingTop;this.adjustLocations(this.tiledMemberPack[r],e.rect.x,e.rect.y,i,o)}},E.prototype.repopulateZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack;Object.keys(e).forEach((function(r){var i=t.idToDummyNode[r],o=i.paddingLeft,n=i.paddingTop;t.adjustLocations(e[r],i.rect.x,i.rect.y,o,n)}))},E.prototype.getToBeTiled=function(t){var e=t.id;if(null!=this.toBeTiled[e])return this.toBeTiled[e];var r=t.getChild();if(null==r)return this.toBeTiled[e]=!1,!1;for(var i=r.getNodes(),o=0;o<i.length;o++){var n=i[o];if(this.getNodeDegree(n)>0)return this.toBeTiled[e]=!1,!1;if(null!=n.getChild()){if(!this.getToBeTiled(n))return this.toBeTiled[e]=!1,!1}else this.toBeTiled[n.id]=!1}return this.toBeTiled[e]=!0,!0},E.prototype.getNodeDegree=function(t){t.id;for(var e=t.getEdges(),r=0,i=0;i<e.length;i++){var o=e[i];o.getSource().id!==o.getTarget().id&&(r+=1)}return r},E.prototype.getNodeDegreeWithChildren=function(t){var e=this.getNodeDegree(t);if(null==t.getChild())return e;for(var r=t.getChild().getNodes(),i=0;i<r.length;i++){var o=r[i];e+=this.getNodeDegreeWithChildren(o)}return e},E.prototype.performDFSOnCompounds=function(){this.compoundOrder=[],this.fillCompexOrderByDFS(this.graphManager.getRoot().getNodes())},E.prototype.fillCompexOrderByDFS=function(t){for(var e=0;e<t.length;e++){var r=t[e];null!=r.getChild()&&this.fillCompexOrderByDFS(r.getChild().getNodes()),this.getToBeTiled(r)&&this.compoundOrder.push(r)}},E.prototype.adjustLocations=function(t,e,r,i,o){r+=o;for(var n=e+=i,a=0;a<t.rows.length;a++){var s=t.rows[a];e=n;for(var h=0,d=0;d<s.length;d++){var g=s[d];g.rect.x=e,g.rect.y=r,e+=g.rect.width+t.horizontalPadding,g.rect.height>h&&(h=g.rect.height)}r+=h+t.verticalPadding}},E.prototype.tileCompoundMembers=function(t,e){var r=this;this.tiledMemberPack=[],Object.keys(t).forEach((function(i){var o=e[i];r.tiledMemberPack[i]=r.tileNodes(t[i],o.paddingLeft+o.paddingRight),o.rect.width=r.tiledMemberPack[i].width,o.rect.height=r.tiledMemberPack[i].height}))},E.prototype.tileNodes=function(t,e){var r={rows:[],rowWidth:[],rowHeight:[],width:0,height:e,verticalPadding:h.TILING_PADDING_VERTICAL,horizontalPadding:h.TILING_PADDING_HORIZONTAL};t.sort((function(t,e){return t.rect.width*t.rect.height>e.rect.width*e.rect.height?-1:t.rect.width*t.rect.height<e.rect.width*e.rect.height?1:0}));for(var i=0;i<t.length;i++){var o=t[i];0==r.rows.length?this.insertNodeToRow(r,o,0,e):this.canAddHorizontal(r,o.rect.width,o.rect.height)?this.insertNodeToRow(r,o,this.getShortestRowIndex(r),e):this.insertNodeToRow(r,o,r.rows.length,e),this.shiftToLastRow(r)}return r},E.prototype.insertNodeToRow=function(t,e,r,i){var o=i;r==t.rows.length&&(t.rows.push([]),t.rowWidth.push(o),t.rowHeight.push(0));var n=t.rowWidth[r]+e.rect.width;t.rows[r].length>0&&(n+=t.horizontalPadding),t.rowWidth[r]=n,t.width<n&&(t.width=n);var a=e.rect.height;r>0&&(a+=t.verticalPadding);var s=0;a>t.rowHeight[r]&&(s=t.rowHeight[r],t.rowHeight[r]=a,s=t.rowHeight[r]-s),t.height+=s,t.rows[r].push(e)},E.prototype.getShortestRowIndex=function(t){for(var e=-1,r=Number.MAX_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]<r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.getLongestRowIndex=function(t){for(var e=-1,r=Number.MIN_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]>r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.canAddHorizontal=function(t,e,r){var i=this.getShortestRowIndex(t);if(i<0)return!0;var o=t.rowWidth[i];if(o+t.horizontalPadding+e<=t.width)return!0;var n,a,s=0;return t.rowHeight[i]<r&&i>0&&(s=r+t.verticalPadding-t.rowHeight[i]),n=t.width-o>=e+t.horizontalPadding?(t.height+s)/(o+e+t.horizontalPadding):(t.height+s)/t.width,s=r+t.verticalPadding,(a=t.width<e?(t.height+s)/e:(t.height+s)/t.width)<1&&(a=1/a),n<1&&(n=1/n),n<a},E.prototype.shiftToLastRow=function(t){var e=this.getLongestRowIndex(t),r=t.rowWidth.length-1,i=t.rows[e],o=i[i.length-1],n=o.width+t.horizontalPadding;if(t.width-t.rowWidth[r]>n&&e!=r){i.splice(-1,1),t.rows[r].push(o),t.rowWidth[e]=t.rowWidth[e]-n,t.rowWidth[r]=t.rowWidth[r]+n,t.width=t.rowWidth[instance.getLongestRowIndex(t)];for(var a=Number.MIN_VALUE,s=0;s<i.length;s++)i[s].height>a&&(a=i[s].height);e>0&&(a+=t.verticalPadding);var h=t.rowHeight[e]+t.rowHeight[r];t.rowHeight[e]=a,t.rowHeight[r]<o.height+t.verticalPadding&&(t.rowHeight[r]=o.height+t.verticalPadding);var d=t.rowHeight[e]+t.rowHeight[r];t.height+=d-h,this.shiftToLastRow(t)}},E.prototype.tilingPreLayout=function(){h.TILE&&(this.groupZeroDegreeMembers(),this.clearCompounds(),this.clearZeroDegreeMembers())},E.prototype.tilingPostLayout=function(){h.TILE&&(this.repopulateZeroDegreeMembers(),this.repopulateCompounds())},E.prototype.reduceTrees=function(){for(var t,e=[],r=!0;r;){var i=this.graphManager.getAllNodes(),o=[];r=!1;for(var n=0;n<i.length;n++)1!=(t=i[n]).getEdges().length||t.getEdges()[0].isInterGraph||null!=t.getChild()||(o.push([t,t.getEdges()[0],t.getOwner()]),r=!0);if(1==r){for(var a=[],s=0;s<o.length;s++)1==o[s][0].getEdges().length&&(a.push(o[s]),o[s][0].getOwner().remove(o[s][0]));e.push(a),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()}}this.prunedNodesAll=e},E.prototype.growTree=function(t){for(var e,r=t[t.length-1],i=0;i<r.length;i++)e=r[i],this.findPlaceforPrunedNode(e),e[2].add(e[0]),e[2].add(e[1],e[1].source,e[1].target);t.splice(t.length-1,1),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()},E.prototype.findPlaceforPrunedNode=function(t){var e,r,i=t[0],o=(r=i==t[1].source?t[1].target:t[1].source).startX,n=r.finishX,a=r.startY,s=r.finishY,h=[0,0,0,0];if(a>0)for(var g=o;g<=n;g++)h[0]+=this.grid[g][a-1].length+this.grid[g][a].length-1;if(n<this.grid.length-1)for(g=a;g<=s;g++)h[1]+=this.grid[n+1][g].length+this.grid[n][g].length-1;if(s<this.grid[0].length-1)for(g=o;g<=n;g++)h[2]+=this.grid[g][s+1].length+this.grid[g][s].length-1;if(o>0)for(g=a;g<=s;g++)h[3]+=this.grid[o-1][g].length+this.grid[o][g].length-1;for(var l,p,c=u.MAX_VALUE,f=0;f<h.length;f++)h[f]<c?(c=h[f],l=1,p=f):h[f]==c&&l++;if(3==l&&0==c)0==h[0]&&0==h[1]&&0==h[2]?e=1:0==h[0]&&0==h[1]&&0==h[3]?e=0:0==h[0]&&0==h[2]&&0==h[3]?e=3:0==h[1]&&0==h[2]&&0==h[3]&&(e=2);else if(2==l&&0==c){var v=Math.floor(2*Math.random());e=0==h[0]&&0==h[1]?0==v?0:1:0==h[0]&&0==h[2]?0==v?0:2:0==h[0]&&0==h[3]?0==v?0:3:0==h[1]&&0==h[2]?0==v?1:2:0==h[1]&&0==h[3]?0==v?1:3:0==v?2:3}else e=4==l&&0==c?v=Math.floor(4*Math.random()):p;0==e?i.setCenter(r.getCenterX(),r.getCenterY()-r.getHeight()/2-d.DEFAULT_EDGE_LENGTH-i.getHeight()/2):1==e?i.setCenter(r.getCenterX()+r.getWidth()/2+d.DEFAULT_EDGE_LENGTH+i.getWidth()/2,r.getCenterY()):2==e?i.setCenter(r.getCenterX(),r.getCenterY()+r.getHeight()/2+d.DEFAULT_EDGE_LENGTH+i.getHeight()/2):i.setCenter(r.getCenterX()-r.getWidth()/2-d.DEFAULT_EDGE_LENGTH-i.getWidth()/2,r.getCenterY())},t.exports=E},function(t,e,r){var i={};i.layoutBase=r(0),i.CoSEConstants=r(1),i.CoSEEdge=r(2),i.CoSEGraph=r(3),i.CoSEGraphManager=r(4),i.CoSELayout=r(6),i.CoSENode=r(5),t.exports=i}])},o.exports=n(i.__require())),r.__module.exports;var o,n};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("../../../../../_virtual/_commonjsHelpers.js"),r=require("../../../../../_virtual/cose-base2.js"),i=require("../../../layout-base@1.0.2/node_modules/layout-base/layout-base.js");r.__module.exports,exports.__require=function(){return t||(t=1,o=r.__module,r.__module.exports,e.commonjsGlobal,n=function(t){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(e,r){e.exports=t},function(t,e,r){var i=r(0).FDLayoutConstants;function o(){}for(var n in i)o[n]=i[n];o.DEFAULT_USE_MULTI_LEVEL_SCALING=!1,o.DEFAULT_RADIAL_SEPARATION=i.DEFAULT_EDGE_LENGTH,o.DEFAULT_COMPONENT_SEPERATION=60,o.TILE=!0,o.TILING_PADDING_VERTICAL=10,o.TILING_PADDING_HORIZONTAL=10,o.TREE_REDUCTION_ON_INCREMENTAL=!1,t.exports=o},function(t,e,r){var i=r(0).FDLayoutEdge;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraph;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraphManager;function o(t){i.call(this,t)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).FDLayoutNode,o=r(0).IMath;function n(t,e,r,o){i.call(this,t,e,r,o)}for(var a in n.prototype=Object.create(i.prototype),i)n[a]=i[a];n.prototype.move=function(){var t=this.graphManager.getLayout();this.displacementX=t.coolingFactor*(this.springForceX+this.repulsionForceX+this.gravitationForceX)/this.noOfChildren,this.displacementY=t.coolingFactor*(this.springForceY+this.repulsionForceY+this.gravitationForceY)/this.noOfChildren,Math.abs(this.displacementX)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementX=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementX)),Math.abs(this.displacementY)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementY=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementY)),null==this.child||0==this.child.getNodes().length?this.moveBy(this.displacementX,this.displacementY):this.propogateDisplacementToChildren(this.displacementX,this.displacementY),t.totalDisplacement+=Math.abs(this.displacementX)+Math.abs(this.displacementY),this.springForceX=0,this.springForceY=0,this.repulsionForceX=0,this.repulsionForceY=0,this.gravitationForceX=0,this.gravitationForceY=0,this.displacementX=0,this.displacementY=0},n.prototype.propogateDisplacementToChildren=function(t,e){for(var r,i=this.getChild().getNodes(),o=0;o<i.length;o++)null==(r=i[o]).getChild()?(r.moveBy(t,e),r.displacementX+=t,r.displacementY+=e):r.propogateDisplacementToChildren(t,e)},n.prototype.setPred1=function(t){this.pred1=t},n.prototype.getPred1=function(){return pred1},n.prototype.getPred2=function(){return pred2},n.prototype.setNext=function(t){this.next=t},n.prototype.getNext=function(){return next},n.prototype.setProcessed=function(t){this.processed=t},n.prototype.isProcessed=function(){return processed},t.exports=n},function(t,e,r){var i=r(0).FDLayout,o=r(4),n=r(3),a=r(5),s=r(2),h=r(1),d=r(0).FDLayoutConstants,g=r(0).LayoutConstants,l=r(0).Point,p=r(0).PointD,c=r(0).Layout,u=r(0).Integer,f=r(0).IGeometry,v=r(0).LGraph,T=r(0).Transform;function E(){i.call(this),this.toBeTiled={}}for(var m in E.prototype=Object.create(i.prototype),i)E[m]=i[m];E.prototype.newGraphManager=function(){var t=new o(this);return this.graphManager=t,t},E.prototype.newGraph=function(t){return new n(null,this.graphManager,t)},E.prototype.newNode=function(t){return new a(this.graphManager,t)},E.prototype.newEdge=function(t){return new s(null,null,t)},E.prototype.initParameters=function(){i.prototype.initParameters.call(this,arguments),this.isSubLayout||(h.DEFAULT_EDGE_LENGTH<10?this.idealEdgeLength=10:this.idealEdgeLength=h.DEFAULT_EDGE_LENGTH,this.useSmartIdealEdgeLengthCalculation=h.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION,this.springConstant=d.DEFAULT_SPRING_STRENGTH,this.repulsionConstant=d.DEFAULT_REPULSION_STRENGTH,this.gravityConstant=d.DEFAULT_GRAVITY_STRENGTH,this.compoundGravityConstant=d.DEFAULT_COMPOUND_GRAVITY_STRENGTH,this.gravityRangeFactor=d.DEFAULT_GRAVITY_RANGE_FACTOR,this.compoundGravityRangeFactor=d.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR,this.prunedNodesAll=[],this.growTreeIterations=0,this.afterGrowthIterations=0,this.isTreeGrowing=!1,this.isGrowthFinished=!1,this.coolingCycle=0,this.maxCoolingCycle=this.maxIterations/d.CONVERGENCE_CHECK_PERIOD,this.finalTemperature=d.CONVERGENCE_CHECK_PERIOD/this.maxIterations,this.coolingAdjuster=1)},E.prototype.layout=function(){return g.DEFAULT_CREATE_BENDS_AS_NEEDED&&(this.createBendpoints(),this.graphManager.resetAllEdges()),this.level=0,this.classicLayout()},E.prototype.classicLayout=function(){if(this.nodesWithGravity=this.calculateNodesToApplyGravitationTo(),this.graphManager.setAllNodesToApplyGravitation(this.nodesWithGravity),this.calcNoOfChildrenForAllNodes(),this.graphManager.calcLowestCommonAncestors(),this.graphManager.calcInclusionTreeDepths(),this.graphManager.getRoot().calcEstimatedSize(),this.calcIdealEdgeLengths(),this.incremental)h.TREE_REDUCTION_ON_INCREMENTAL&&(this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation(),e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)})),this.graphManager.setAllNodesToApplyGravitation(r));else{var t=this.getFlatForest();if(t.length>0)this.positionNodesRadially(t);else{this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation();var e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)}));this.graphManager.setAllNodesToApplyGravitation(r),this.positionNodesRandomly()}}return this.initSpringEmbedder(),this.runSpringEmbedder(),!0},E.prototype.tick=function(){if(this.totalIterations++,this.totalIterations===this.maxIterations&&!this.isTreeGrowing&&!this.isGrowthFinished){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}if(this.totalIterations%d.CONVERGENCE_CHECK_PERIOD==0&&!this.isTreeGrowing&&!this.isGrowthFinished){if(this.isConverged()){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}this.coolingCycle++,0==this.layoutQuality?this.coolingAdjuster=this.coolingCycle:1==this.layoutQuality&&(this.coolingAdjuster=this.coolingCycle/3),this.coolingFactor=Math.max(this.initialCoolingFactor-Math.pow(this.coolingCycle,Math.log(100*(this.initialCoolingFactor-this.finalTemperature))/Math.log(this.maxCoolingCycle))/100*this.coolingAdjuster,this.finalTemperature),this.animationPeriod=Math.ceil(this.initialAnimationPeriod*Math.sqrt(this.coolingFactor))}if(this.isTreeGrowing){if(this.growTreeIterations%10==0)if(this.prunedNodesAll.length>0){this.graphManager.updateBounds(),this.updateGrid(),this.growTree(this.prunedNodesAll),this.graphManager.resetAllNodesToApplyGravitation();var t=new Set(this.getAllNodes()),e=this.nodesWithGravity.filter((function(e){return t.has(e)}));this.graphManager.setAllNodesToApplyGravitation(e),this.graphManager.updateBounds(),this.updateGrid(),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL}else this.isTreeGrowing=!1,this.isGrowthFinished=!0;this.growTreeIterations++}if(this.isGrowthFinished){if(this.isConverged())return!0;this.afterGrowthIterations%10==0&&(this.graphManager.updateBounds(),this.updateGrid()),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL*((100-this.afterGrowthIterations)/100),this.afterGrowthIterations++}var r=!this.isTreeGrowing&&!this.isGrowthFinished,i=this.growTreeIterations%10==1&&this.isTreeGrowing||this.afterGrowthIterations%10==1&&this.isGrowthFinished;return this.totalDisplacement=0,this.graphManager.updateBounds(),this.calcSpringForces(),this.calcRepulsionForces(r,i),this.calcGravitationalForces(),this.moveNodes(),this.animate(),!1},E.prototype.getPositionsData=function(){for(var t=this.graphManager.getAllNodes(),e={},r=0;r<t.length;r++){var i=t[r].rect,o=t[r].id;e[o]={id:o,x:i.getCenterX(),y:i.getCenterY(),w:i.width,h:i.height}}return e},E.prototype.runSpringEmbedder=function(){this.initialAnimationPeriod=25,this.animationPeriod=this.initialAnimationPeriod;var t=!1;if("during"===d.ANIMATE)this.emit("layoutstarted");else{for(;!t;)t=this.tick();this.graphManager.updateBounds()}},E.prototype.calculateNodesToApplyGravitationTo=function(){var t,e,r=[],i=this.graphManager.getGraphs(),o=i.length;for(e=0;e<o;e++)(t=i[e]).updateConnected(),t.isConnected||(r=r.concat(t.getNodes()));return r},E.prototype.createBendpoints=function(){var t=[];t=t.concat(this.graphManager.getAllEdges());var e,r=new Set;for(e=0;e<t.length;e++){var i=t[e];if(!r.has(i)){var o=i.getSource(),n=i.getTarget();if(o==n)i.getBendpoints().push(new p),i.getBendpoints().push(new p),this.createDummyNodesForBendpoints(i),r.add(i);else{var a=[];if(a=(a=a.concat(o.getEdgeListToNode(n))).concat(n.getEdgeListToNode(o)),!r.has(a[0])){var s;if(a.length>1)for(s=0;s<a.length;s++){var h=a[s];h.getBendpoints().push(new p),this.createDummyNodesForBendpoints(h)}a.forEach((function(t){r.add(t)}))}}}if(r.size==t.length)break}},E.prototype.positionNodesRadially=function(t){for(var e=new l(0,0),r=Math.ceil(Math.sqrt(t.length)),i=0,o=0,n=0,a=new p(0,0),s=0;s<t.length;s++){s%r==0&&(n=0,o=i,0!=s&&(o+=h.DEFAULT_COMPONENT_SEPERATION),i=0);var d=t[s],u=c.findCenterOfTree(d);e.x=n,e.y=o,(a=E.radialLayout(d,u,e)).y>i&&(i=Math.floor(a.y)),n=Math.floor(a.x+h.DEFAULT_COMPONENT_SEPERATION)}this.transform(new p(g.WORLD_CENTER_X-a.x/2,g.WORLD_CENTER_Y-a.y/2))},E.radialLayout=function(t,e,r){var i=Math.max(this.maxDiagonalInTree(t),h.DEFAULT_RADIAL_SEPARATION);E.branchRadialLayout(e,null,0,359,0,i);var o=v.calculateBounds(t),n=new T;n.setDeviceOrgX(o.getMinX()),n.setDeviceOrgY(o.getMinY()),n.setWorldOrgX(r.x),n.setWorldOrgY(r.y);for(var a=0;a<t.length;a++)t[a].transform(n);var s=new p(o.getMaxX(),o.getMaxY());return n.inverseTransformPoint(s)},E.branchRadialLayout=function(t,e,r,i,o,n){var a=(i-r+1)/2;a<0&&(a+=180);var s=(a+r)%360*f.TWO_PI/360,h=o*Math.cos(s),d=o*Math.sin(s);t.setCenter(h,d);var g=[],l=(g=g.concat(t.getEdges())).length;null!=e&&l--;for(var p,c=0,u=g.length,v=t.getEdgesBetween(e);v.length>1;){var T=v[0];v.splice(0,1);var m=g.indexOf(T);m>=0&&g.splice(m,1),u--,l--}p=null!=e?(g.indexOf(v[0])+1)%u:0;for(var y=Math.abs(i-r)/l,N=p;c!=l;N=++N%u){var w=g[N].getOtherEnd(t);if(w!=e){var A=(r+c*y)%360,C=(A+y)%360;E.branchRadialLayout(w,t,A,C,o+n,n),c++}}},E.maxDiagonalInTree=function(t){for(var e=u.MIN_VALUE,r=0;r<t.length;r++){var i=t[r].getDiagonal();i>e&&(e=i)}return e},E.prototype.calcRepulsionRange=function(){return 2*(this.level+1)*this.idealEdgeLength},E.prototype.groupZeroDegreeMembers=function(){var t=this,e={};this.memberGroups={},this.idToDummyNode={};for(var r=[],i=this.graphManager.getAllNodes(),o=0;o<i.length;o++){var n=(s=i[o]).getParent();0!==this.getNodeDegreeWithChildren(s)||null!=n.id&&this.getToBeTiled(n)||r.push(s)}for(o=0;o<r.length;o++){var s,h=(s=r[o]).getParent().id;void 0===e[h]&&(e[h]=[]),e[h]=e[h].concat(s)}Object.keys(e).forEach((function(r){if(e[r].length>1){var i="DummyCompound_"+r;t.memberGroups[i]=e[r];var o=e[r][0].getParent(),n=new a(t.graphManager);n.id=i,n.paddingLeft=o.paddingLeft||0,n.paddingRight=o.paddingRight||0,n.paddingBottom=o.paddingBottom||0,n.paddingTop=o.paddingTop||0,t.idToDummyNode[i]=n;var s=t.getGraphManager().add(t.newGraph(),n),h=o.getChild();h.add(n);for(var d=0;d<e[r].length;d++){var g=e[r][d];h.remove(g),s.add(g)}}}))},E.prototype.clearCompounds=function(){var t={},e={};this.performDFSOnCompounds();for(var r=0;r<this.compoundOrder.length;r++)e[this.compoundOrder[r].id]=this.compoundOrder[r],t[this.compoundOrder[r].id]=[].concat(this.compoundOrder[r].getChild().getNodes()),this.graphManager.remove(this.compoundOrder[r].getChild()),this.compoundOrder[r].child=null;this.graphManager.resetAllNodes(),this.tileCompoundMembers(t,e)},E.prototype.clearZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack=[];Object.keys(this.memberGroups).forEach((function(r){var i=t.idToDummyNode[r];e[r]=t.tileNodes(t.memberGroups[r],i.paddingLeft+i.paddingRight),i.rect.width=e[r].width,i.rect.height=e[r].height}))},E.prototype.repopulateCompounds=function(){for(var t=this.compoundOrder.length-1;t>=0;t--){var e=this.compoundOrder[t],r=e.id,i=e.paddingLeft,o=e.paddingTop;this.adjustLocations(this.tiledMemberPack[r],e.rect.x,e.rect.y,i,o)}},E.prototype.repopulateZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack;Object.keys(e).forEach((function(r){var i=t.idToDummyNode[r],o=i.paddingLeft,n=i.paddingTop;t.adjustLocations(e[r],i.rect.x,i.rect.y,o,n)}))},E.prototype.getToBeTiled=function(t){var e=t.id;if(null!=this.toBeTiled[e])return this.toBeTiled[e];var r=t.getChild();if(null==r)return this.toBeTiled[e]=!1,!1;for(var i=r.getNodes(),o=0;o<i.length;o++){var n=i[o];if(this.getNodeDegree(n)>0)return this.toBeTiled[e]=!1,!1;if(null!=n.getChild()){if(!this.getToBeTiled(n))return this.toBeTiled[e]=!1,!1}else this.toBeTiled[n.id]=!1}return this.toBeTiled[e]=!0,!0},E.prototype.getNodeDegree=function(t){t.id;for(var e=t.getEdges(),r=0,i=0;i<e.length;i++){var o=e[i];o.getSource().id!==o.getTarget().id&&(r+=1)}return r},E.prototype.getNodeDegreeWithChildren=function(t){var e=this.getNodeDegree(t);if(null==t.getChild())return e;for(var r=t.getChild().getNodes(),i=0;i<r.length;i++){var o=r[i];e+=this.getNodeDegreeWithChildren(o)}return e},E.prototype.performDFSOnCompounds=function(){this.compoundOrder=[],this.fillCompexOrderByDFS(this.graphManager.getRoot().getNodes())},E.prototype.fillCompexOrderByDFS=function(t){for(var e=0;e<t.length;e++){var r=t[e];null!=r.getChild()&&this.fillCompexOrderByDFS(r.getChild().getNodes()),this.getToBeTiled(r)&&this.compoundOrder.push(r)}},E.prototype.adjustLocations=function(t,e,r,i,o){r+=o;for(var n=e+=i,a=0;a<t.rows.length;a++){var s=t.rows[a];e=n;for(var h=0,d=0;d<s.length;d++){var g=s[d];g.rect.x=e,g.rect.y=r,e+=g.rect.width+t.horizontalPadding,g.rect.height>h&&(h=g.rect.height)}r+=h+t.verticalPadding}},E.prototype.tileCompoundMembers=function(t,e){var r=this;this.tiledMemberPack=[],Object.keys(t).forEach((function(i){var o=e[i];r.tiledMemberPack[i]=r.tileNodes(t[i],o.paddingLeft+o.paddingRight),o.rect.width=r.tiledMemberPack[i].width,o.rect.height=r.tiledMemberPack[i].height}))},E.prototype.tileNodes=function(t,e){var r={rows:[],rowWidth:[],rowHeight:[],width:0,height:e,verticalPadding:h.TILING_PADDING_VERTICAL,horizontalPadding:h.TILING_PADDING_HORIZONTAL};t.sort((function(t,e){return t.rect.width*t.rect.height>e.rect.width*e.rect.height?-1:t.rect.width*t.rect.height<e.rect.width*e.rect.height?1:0}));for(var i=0;i<t.length;i++){var o=t[i];0==r.rows.length?this.insertNodeToRow(r,o,0,e):this.canAddHorizontal(r,o.rect.width,o.rect.height)?this.insertNodeToRow(r,o,this.getShortestRowIndex(r),e):this.insertNodeToRow(r,o,r.rows.length,e),this.shiftToLastRow(r)}return r},E.prototype.insertNodeToRow=function(t,e,r,i){var o=i;r==t.rows.length&&(t.rows.push([]),t.rowWidth.push(o),t.rowHeight.push(0));var n=t.rowWidth[r]+e.rect.width;t.rows[r].length>0&&(n+=t.horizontalPadding),t.rowWidth[r]=n,t.width<n&&(t.width=n);var a=e.rect.height;r>0&&(a+=t.verticalPadding);var s=0;a>t.rowHeight[r]&&(s=t.rowHeight[r],t.rowHeight[r]=a,s=t.rowHeight[r]-s),t.height+=s,t.rows[r].push(e)},E.prototype.getShortestRowIndex=function(t){for(var e=-1,r=Number.MAX_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]<r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.getLongestRowIndex=function(t){for(var e=-1,r=Number.MIN_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]>r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.canAddHorizontal=function(t,e,r){var i=this.getShortestRowIndex(t);if(i<0)return!0;var o=t.rowWidth[i];if(o+t.horizontalPadding+e<=t.width)return!0;var n,a,s=0;return t.rowHeight[i]<r&&i>0&&(s=r+t.verticalPadding-t.rowHeight[i]),n=t.width-o>=e+t.horizontalPadding?(t.height+s)/(o+e+t.horizontalPadding):(t.height+s)/t.width,s=r+t.verticalPadding,(a=t.width<e?(t.height+s)/e:(t.height+s)/t.width)<1&&(a=1/a),n<1&&(n=1/n),n<a},E.prototype.shiftToLastRow=function(t){var e=this.getLongestRowIndex(t),r=t.rowWidth.length-1,i=t.rows[e],o=i[i.length-1],n=o.width+t.horizontalPadding;if(t.width-t.rowWidth[r]>n&&e!=r){i.splice(-1,1),t.rows[r].push(o),t.rowWidth[e]=t.rowWidth[e]-n,t.rowWidth[r]=t.rowWidth[r]+n,t.width=t.rowWidth[instance.getLongestRowIndex(t)];for(var a=Number.MIN_VALUE,s=0;s<i.length;s++)i[s].height>a&&(a=i[s].height);e>0&&(a+=t.verticalPadding);var h=t.rowHeight[e]+t.rowHeight[r];t.rowHeight[e]=a,t.rowHeight[r]<o.height+t.verticalPadding&&(t.rowHeight[r]=o.height+t.verticalPadding);var d=t.rowHeight[e]+t.rowHeight[r];t.height+=d-h,this.shiftToLastRow(t)}},E.prototype.tilingPreLayout=function(){h.TILE&&(this.groupZeroDegreeMembers(),this.clearCompounds(),this.clearZeroDegreeMembers())},E.prototype.tilingPostLayout=function(){h.TILE&&(this.repopulateZeroDegreeMembers(),this.repopulateCompounds())},E.prototype.reduceTrees=function(){for(var t,e=[],r=!0;r;){var i=this.graphManager.getAllNodes(),o=[];r=!1;for(var n=0;n<i.length;n++)1!=(t=i[n]).getEdges().length||t.getEdges()[0].isInterGraph||null!=t.getChild()||(o.push([t,t.getEdges()[0],t.getOwner()]),r=!0);if(1==r){for(var a=[],s=0;s<o.length;s++)1==o[s][0].getEdges().length&&(a.push(o[s]),o[s][0].getOwner().remove(o[s][0]));e.push(a),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()}}this.prunedNodesAll=e},E.prototype.growTree=function(t){for(var e,r=t[t.length-1],i=0;i<r.length;i++)e=r[i],this.findPlaceforPrunedNode(e),e[2].add(e[0]),e[2].add(e[1],e[1].source,e[1].target);t.splice(t.length-1,1),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()},E.prototype.findPlaceforPrunedNode=function(t){var e,r,i=t[0],o=(r=i==t[1].source?t[1].target:t[1].source).startX,n=r.finishX,a=r.startY,s=r.finishY,h=[0,0,0,0];if(a>0)for(var g=o;g<=n;g++)h[0]+=this.grid[g][a-1].length+this.grid[g][a].length-1;if(n<this.grid.length-1)for(g=a;g<=s;g++)h[1]+=this.grid[n+1][g].length+this.grid[n][g].length-1;if(s<this.grid[0].length-1)for(g=o;g<=n;g++)h[2]+=this.grid[g][s+1].length+this.grid[g][s].length-1;if(o>0)for(g=a;g<=s;g++)h[3]+=this.grid[o-1][g].length+this.grid[o][g].length-1;for(var l,p,c=u.MAX_VALUE,f=0;f<h.length;f++)h[f]<c?(c=h[f],l=1,p=f):h[f]==c&&l++;if(3==l&&0==c)0==h[0]&&0==h[1]&&0==h[2]?e=1:0==h[0]&&0==h[1]&&0==h[3]?e=0:0==h[0]&&0==h[2]&&0==h[3]?e=3:0==h[1]&&0==h[2]&&0==h[3]&&(e=2);else if(2==l&&0==c){var v=Math.floor(2*Math.random());e=0==h[0]&&0==h[1]?0==v?0:1:0==h[0]&&0==h[2]?0==v?0:2:0==h[0]&&0==h[3]?0==v?0:3:0==h[1]&&0==h[2]?0==v?1:2:0==h[1]&&0==h[3]?0==v?1:3:0==v?2:3}else e=4==l&&0==c?v=Math.floor(4*Math.random()):p;0==e?i.setCenter(r.getCenterX(),r.getCenterY()-r.getHeight()/2-d.DEFAULT_EDGE_LENGTH-i.getHeight()/2):1==e?i.setCenter(r.getCenterX()+r.getWidth()/2+d.DEFAULT_EDGE_LENGTH+i.getWidth()/2,r.getCenterY()):2==e?i.setCenter(r.getCenterX(),r.getCenterY()+r.getHeight()/2+d.DEFAULT_EDGE_LENGTH+i.getHeight()/2):i.setCenter(r.getCenterX()-r.getWidth()/2-d.DEFAULT_EDGE_LENGTH-i.getWidth()/2,r.getCenterY())},t.exports=E},function(t,e,r){var i={};i.layoutBase=r(0),i.CoSEConstants=r(1),i.CoSEEdge=r(2),i.CoSEGraph=r(3),i.CoSEGraphManager=r(4),i.CoSELayout=r(6),i.CoSENode=r(5),t.exports=i}])},o.exports=n(i.__require())),r.__module.exports;var o,n};
|