PageSourceSearch

https://000.moe/_entry/Live2DChat.astro_astro_type_script_index_0_…Aa1_kkFl5KNCNx4DPHDZ6cBBWhzz-gmtnMFCXRkNq0E

js 000.moe collected 2026-10-08 21:38:13 UTC 12,601 bytes, 3 lines download raw bytes

1import{_ as le}from"../_astro/preload-helper.BlTxHScW.js";function X(){const e=window.location.pathname.slice(0,500),n=document.querySelector("main");if(!n)return{page:null,key:e,protected:!1,article:!1};if(n.querySelector("[data-encrypted-article], [data-decrypted-article]"))return{page:null,key:e,protected:!0,article:!0};const t=n.querySelector("#post-container");if(!t)return{page:null,key:e,protected:!1,article:!1};const o=(t.querySelector(".custom-md")??t).cloneNode(!0);for(const a of o.querySelectorAll("script, style, noscript, template, nav, aside, footer, form, input, textarea, button, [contenteditable], [hidden], [aria-hidden='true'], [data-pagefind-ignore], [data-encrypted-article], [data-decrypted-article], .waline-wrapper, [data-waline-root], #comments, .anchor, .copy-button, svg, canvas, iframe, video, audio"))a.remove();for(const a of o.querySelectorAll("h1,h2,h3,h4,p,li,pre,article,section,br"))a.append(`
2`);const p=(o.textContent??"").replace(/[\t\r ]+/g," ").replace(/\n\s*\n+/g,`
3`).trim().slice(0,4e3),h=(t.querySelector('[data-pagefind-meta="title"], h1')?.textContent?.trim()||document.title).slice(0,160);if(!p)return{page:null,key:e,protected:!1,article:!0};const l={title:h,path:e,text:p};return{page:l,key:JSON.stringify(l),protected:!1,article:!0}}const D=39,ee="live2d:anime-quotes";class de{constructor(n,t,r=Math.random){if(this.dataset=n,this.random=r,this.byId=new Map(n.quotes.map(o=>[o.id,o])),this.byId.size<D*2)throw new Error("The quote corpus must support two distinct 39-quote caches.");this.isValidState(t)?(this.cache=[...t.cache],this.remaining=[...t.remaining],this.last=t.last):this.refill()}byId;cache=[];remaining=[];last=null;next(){this.remaining.length||this.refill();const n=this.remaining.shift(),t=n?this.byId.get(n):void 0;if(!t)throw new Error("The quote cache contains an unknown ID.");return this.last=t.id,{id:t.id,text:`「${t.text}」——《${t.source}》`,emotion:t.emotion}}snapshot(){return{version:this.dataset.version,cache:[...this.cache],remaining:[...this.remaining],last:this.last}}refill(){const n=new Set(this.cache);this.cache=this.dataset.quotes.filter(t=>!n.has(t.id)).map(t=>({id:t.id,score:-Math.log(1-this.random())/t.weight})).sort((t,r)=>t.score-r.score).slice(0,D).map(t=>t.id),this.remaining=[...this.cache]}isValidState(n){if(!n||typeof n!="object")return!1;const t=n,{cache:r,remaining:o,last:p}=t;if(t.version!==this.dataset.version||!Array.isArray(r)||r.length!==D||new Set(r).size!==r.length||!r.every(l=>typeof l=="string"&&this.byId.has(l))||!Array.isArray(o)||o.length>r.length)return!1;const h=r.length-o.length;return o.every((l,a)=>l===r[h+a])&&p===(h?r[h-1]:null)}}const s=document.getElementById("live2d-chat"),z=document.getElementById("live2d-chat-form"),d=document.getElementById("live2d-chat-input"),M=document.getElementById("live2d-chat-send"),ue=document.getElementById("live2d-chat-close"),b=document.getElementById("live2d-chat-messages"),pe=s.dataset.autoTopics==="true",he=Number(s.dataset.rotationIntervalMs)||1e4,c=document.getElementById("live2d-speech"),O=document.getElementById("live2d-speech-text"),fe=s.dataset.endpoint,me=new Set(["idle","happy","sad","celebrate","proud","down"]),y=new Map,te=30*6e4,ne="live2d:recent-topics",x=ye();let V=X(),Y=document.querySelector("main"),i=oe(V),f=!1,q=!1,P=!1,S=!1,E=!1,N=!0,W=!1,m=0,_=-1,H=0,C=0,j=0,$;function ge(){return $??=le(async()=>{const{default:e}=await import("../_astro/anime-quotes.DQDiIx-c.js");return{default:e}},[]).then(({default:e})=>{let n;try{n=JSON.parse(sessionStorage.getItem(ee)??"null")}catch{}return new de(e,n)}).catch(()=>{$=void 0}),$}function k(){return S&&!E&&N&&!document.hidden&&innerWidth>=1024&&!q&&!P&&!(s.matches(":popover-open")&&d.value.trim())}function v(){return pe&&i.article&&!!i.page}function B(){clearTimeout(C),C=0}function u(){B(),!(!k()||v()&&f)&&(C=window.setTimeout(()=>{C=0,v()?(W=!0,w()):J()},he))}async function J(e=!1){if(!k()||v()&&!e)return;const n=i,t=m,r=j,o=await ge();if(i!==n||m!==t||r!==j||!k())return;if(!o){u();return}const p=o.next();try{sessionStorage.setItem(ee,JSON.stringify(o.snapshot()))}catch{}n.shownTopic={...p,kind:"quote"},R(p.text),window.dispatchEvent(new CustomEvent("live2d:emotion",{detail:p.emotion}))}function ie(){const e=i.shownTopic;if(e?.kind!=="article"||e.text!==O.textContent)return;const n=i.transcript.at(-1);(n?.role!=="model"||n.text!==e.text)&&L(i,{role:"model",text:e.text})}function ye(){try{const e=JSON.parse(sessionStorage.getItem(ne)??"{}");if(e&&typeof e=="object"&&!Array.isArray(e))return new Map(Object.entries(e).filter(n=>typeof n[1]=="string"&&n[1].length>0&&n[1].length<=60).slice(-10))}catch{}return new Map}function ve(e,n){x.delete(e),x.set(e,n);
3for(const t of x.keys()){if(x.size<=10)break;x.delete(t)}try{sessionStorage.setItem(ne,JSON.stringify(Object.fromEntries(x)))}catch{}}function oe(e){const n=Date.now();for(const[r,o]of y)n-o.touched>te&&y.delete(r);const t=y.get(e.key)??{key:e.key,page:e.page,article:e.article,history:[],transcript:[],draft:"",touched:n,previousTopic:x.get(e.page?.path??e.key)};for(t.touched=n,y.delete(e.key),y.set(e.key,t);y.size>10;)y.delete(y.keys().next().value);return t}function Q(){return document.querySelector('button[title="聊天"]')}function F(){return document.querySelector("canvas[data-live2d-canvas]")}function T(){H||(H=requestAnimationFrame(()=>{H=0;const e=F(),n=e?.getBoundingClientRect(),t=12,r=S&&!E&&n&&n.top<innerHeight-30&&e?.style.pointerEvents!=="none";if(c.hidden=!r||innerWidth<1024,!c.hidden&&n){c.style.setProperty("--speech-max-height",`${Math.max(64,n.top-t-16)}px`);const o=Math.max(t,Math.min(n.left+n.width/2-c.offsetWidth/2,innerWidth-c.offsetWidth-t));c.style.left=`${o}px`,c.style.top=`${Math.max(t,n.top-c.offsetHeight-16)}px`,c.style.setProperty("--speech-tail",`${Math.max(12,Math.min(c.offsetWidth-12,n.left+n.width/2-o))}px`)}if(s.matches(":popover-open")){let o=Math.max((n?.right??280)+t,c.hidden?0:c.getBoundingClientRect().right+t);o+s.offsetWidth>innerWidth-t&&(o=(n?.left??innerWidth)-s.offsetWidth-t),s.style.left=`${Math.max(t,Math.min(o,innerWidth-s.offsetWidth-t))}px`,s.style.top=`${Math.max(t,innerHeight-s.offsetHeight-t)}px`}}))}function R(e){j++,O.textContent=e,T(),u()}function I(){M.disabled=f||!d.value.trim(),M.dataset.busy=String(f),M.setAttribute("aria-label",f?"等待回复":"发送消息"),d.readOnly=q,z.setAttribute("aria-busy",String(f))}function A(){b.replaceChildren();const e=i.shownTopic?.kind==="article"?i.shownTopic.text:"主人,Roro 来陪你了喵 (。・ω・。)",n=i.transcript.length?i.transcript:[{role:"model",text:e}];for(const t of n){const r=document.createElement("p");r.className="chat-message",r.dataset.role=t.role,r.textContent=t.text,b.append(r)}s.matches(":popover-open")&&(b.scrollTop=b.scrollHeight)}function L(e,n){e.transcript.push(n),e.transcript.length>40&&e.transcript.splice(0,e.transcript.length-40),e.touched=Date.now(),i===e&&A()}function we(e){for(;e.history.length>6||e.history.reduce((n,t)=>n+t.text.length,0)>4e3;)e.history.splice(0,2)}function xe(e,n){const t=Number(n);return e==="rate_limited"?`主人,聊得有点快了,${Number.isFinite(t)&&t>0?Math.ceil(t):60} 秒后再来找 Roro 喵~`:e==="visitor_limit"||e==="site_limit"?t>60?"主人,今天的聊天额度用完了,明天再来找 Roro 喵。":"主人,Roro 正忙,稍后再试一下喵。":e==="origin_forbidden"?"主人,请从 arisaka.eth.limo 打开聊天,本地预览需要启动聊天服务喵。":["invalid_message","invalid_history","body_too_large"].includes(String(e))?"主人,消息有点长,缩短一点再告诉 Roro 喵。":e==="invalid_page"?"主人,这页暂时没法整理,换一页试试喵。":e==="upstream_timeout"?"主人,Roro 刚刚走神了,稍后再试一次喵。":"主人,聊天服务暂时不可用,稍后再来找 Roro 喵。"}async function K(e,n=!1){const t=i,r=m;if(f||e==="summary"&&!t.page)return;const o=e==="summary"?"聊聊这个页面有趣的地方吧。":d.value.trim();if(!o||o.length>1e3)return;e==="summary"&&(_=m),f=!0,q=e==="chat",W=!1,I(),u();const p={role:"user",text:o};e==="chat"&&(ie(),L(t,p));try{const h=e==="summary"?{intent:e,message:o,history:[],page:t.page,previousTopic:t.previousTopic}:{intent:e,message:o,history:t.history,...t.shownTopic?.kind==="article"?{context:{title:t.page?.title??"文章话题",path:t.page?.path??t.key,summary:t.shownTopic.text}}:{}},l=await fetch(fe,{method:"POST",credentials:"omit",redirect:"error",cache:"no-store",headers:{"Content-Type":"application/json"},body:JSON.stringify(h),signal:AbortSignal.timeout(45e3)}),a=await l.json();if(!l.ok)throw new Error(xe(a?.error,l.headers.get("Retry-After")));if(!a||typeof a.text!="string"||!a.text.trim()||a.text.length>1e3)throw new Error("主人,回复有点乱,我们重新试一次喵。");const g={text:a.text,emotion:me.has(a.emotion)?a.emotion:"idle"};if(e==="summary"){if(i!==t||r!==m||g.text.length>60||(t.topic=g,t.previousTopic=g.text,t.page&&ve(t.page.path,g.text),!k()))return;re(t,g);return}t.history.push({role:"user",text:o},{role:"model",text:g.text}),we(t),t.draft="",i===t&&(d.value=""),L(t,{role:"model",text:g.text}),i===t&&(R(g.text),t.transcript.length||A(),window.dispatchEvent(new CustomEvent("live2d:emotion",{detail:g.emotion})))}catch(h){const l=t.transcript.indexOf(p);if(l>=0&&t.transcript.splice(l,1),i===t&&(A(),n&&e==="summary"&&t.shownTopic?.kind!=="article"&&J(!0),!n)){const a=h instanceof Error&&h.name==="Error"?h.message:"主人,连接中断了,消息已经帮你保留,稍后再试喵。";L(t,{role:"model",text:a}),R(a)}}finally{f=!1,q=!1,I(),u(),!n&&s.matches(":popover-open")&&d.focus({preventScroll:!0}),w()}}function re(e,n){e.shownTopic={...n,kind:"article"},i===e&&(R(n.text),e.transcript.length||A(),window.dispatchEvent(new CustomEvent("live2d:emotion",{detail:n.emotion})))}function se(){S||f||i.topic||_===m||!v()||!N||document.hidden||innerWidth<1024||K("summary",!0)}function Ee(){const e=i,n=m;setTimeout(()=>{i!==e||m!==n||e.shownTopic||E||R("主人,Roro 正在想这篇文章的话题,稍等一下喵。")},800)}function w(){!W||!v()||!k()||f||K("summary",!0)}function U(){const e=X(),n=document.querySelector("main");
3if((e.key!==V.key||n!==Y||Date.now()-i.touched>te)&&(i.draft=d.value,V=e,Y=n,m++,i=oe(e),i.topic=void 0,i.shownTopic=void 0,d.value=i.draft,_=-1,A()),I(),!S){se();return}W=v()&&!i.topic&&_!==m,i.shownTopic||(v()&&i.topic&&k()?re(i,i.topic):v()&&(f||_!==m)?Ee():J(!0)),u(),w()}function ae(){ie(),s.matches(":popover-open")||s.showPopover(),T(),d.focus({preventScroll:!0})}function G(){s.hidePopover(),Q()?.focus({preventScroll:!0})}z.addEventListener("submit",e=>{e.preventDefault(),K("chat")});d.addEventListener("input",()=>{i.draft=d.value,i.touched=Date.now(),I(),u(),w()});d.addEventListener("compositionstart",()=>{P=!0,B()});d.addEventListener("compositionend",()=>{setTimeout(()=>{P=!1,u(),w()},0)});d.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&!e.isComposing&&!P&&(e.preventDefault(),M.disabled||z.requestSubmit())});ue.addEventListener("click",G);c.addEventListener("click",ae);s.addEventListener("keydown",e=>{e.key==="Escape"&&(e.preventDefault(),G())});window.addEventListener("live2d:chat-toggle",()=>{s.matches(":popover-open")?G():ae()});window.addEventListener("live2d:sleep",()=>{E=!0,c.hidden=!0,s.hidePopover(),B()});s.addEventListener("toggle",()=>{const e=s.matches(":popover-open");e&&(b.scrollTop=b.scrollHeight),Q()?.setAttribute("aria-expanded",String(e)),O.setAttribute("aria-live",e?"off":"polite"),u()});document.addEventListener("pointerdown",e=>{!(e.target instanceof Node)||!s.matches(":popover-open")||!s.contains(e.target)&&!c.contains(e.target)&&!Q()?.contains(e.target)&&s.hidePopover()});window.addEventListener("resize",()=>{T(),u()});window.addEventListener("pagehide",()=>{N=!1,B()});window.addEventListener("pageshow",()=>{N=!0,u(),w()});document.addEventListener("visibilitychange",()=>{u(),w()});new ResizeObserver(T).observe(O);function ce(){if(S)return;S=!0;const e=F();E=e?.style.pointerEvents==="none",e?.parentElement?.addEventListener("transitionend",T),e&&new MutationObserver(()=>{const n=e.style.pointerEvents==="none";E!==n&&(E=n,u(),w()),T()}).observe(e,{attributes:!0,attributeFilter:["style"]}),T(),setTimeout(U,1600)}window.addEventListener("live2d:ready",ce);F()?.dataset.live2dReady==="true"&&ce();const Z=()=>
3{window.swup?.hooks.on("page:view",U)};document.addEventListener("astro:page-load",U);window.swup?.hooks?Z():document.addEventListener("swup:enable",Z,{once:!0});A();I();se();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.