12 lines
5.0 KiB
JavaScript
12 lines
5.0 KiB
JavaScript
import{o as X,i as Z}from"./lifecycle.MLiOCzKC.js";import{l as R,k as $,f as ee,t as z,g as e,a as F,p as te,b as ae,s,i as o,e as q,d as g,h as f,r as c,u as b,j as M}from"./template.CyUWgh-J.js";import{s as re}from"./render.C4NccAY7.js";import{e as ie,i as se}from"./each.DMYtlFB3.js";import{I as w,h as ne}from"./Icon.DAqWeDJZ.js";import{r as j,s as C}from"./props.h8jPqBEd.js";import{e as I}from"./utils.DonxBMOE.js";import{b as K}from"./input.CM2Xh3yk.js";import{I as V}from"./zh_TW.CqrCsd4X.js";import{i as W}from"./translation.BRy61wHY.js";import{u as Y}from"./url-utils.CaIMLrxo.js";import{n as le}from"./navigation-utils.Cc6bKnia.js";/* empty css */import"./functions.LP-DBi81.js";import"./config.B4FKKqOZ.js";var oe=q(`<a class="transition first-of-type:mt-2 lg:first-of-type:mt-0 group block
|
|
rounded-xl text-lg px-3 py-2 hover:bg-[var(--btn-plain-bg-hover)] active:bg-[var(--btn-plain-bg-active)]"><div class="transition text-90 inline-flex font-bold group-hover:text-[var(--primary)]"> <!></div> <div class="transition text-sm text-50"></div></a>`),ce=q(`<div id="search-bar" class="hidden lg:flex transition-all items-center h-11 mr-2 rounded-lg
|
|
bg-black/[0.04] hover:bg-black/[0.06] focus-within:bg-black/[0.06]
|
|
dark:bg-white/5 dark:hover:bg-white/10 dark:focus-within:bg-white/10
|
|
"><!> <input class="transition-all pl-10 text-sm bg-transparent outline-0
|
|
h-full w-40 active:w-60 focus:w-60 text-black/50 dark:text-white/50 svelte-1wah7ro"/></div> <button aria-label="Search Panel" id="search-switch" class="btn-plain scale-animation lg:!hidden rounded-lg w-11 h-11 active:scale-90"><!></button> <div id="search-panel" class="float-panel float-panel-closed search-panel absolute md:w-[30rem]
|
|
top-20 left-4 md:left-[unset] right-4 shadow-2xl rounded-2xl p-2 svelte-1wah7ro"><div id="search-bar-inside" class="flex relative lg:hidden transition-all items-center h-11 rounded-xl
|
|
bg-black/[0.04] hover:bg-black/[0.06] focus-within:bg-black/[0.06]
|
|
dark:bg-white/5 dark:hover:bg-white/10 dark:focus-within:bg-white/10
|
|
"><!> <input placeholder="Search" class="pl-10 absolute inset-0 text-sm bg-transparent outline-0
|
|
focus:w-60 text-black/50 dark:text-white/50 svelte-1wah7ro"/></div> <!></div>`,1);function Se(A,D){ae(D,!1);let i=g(""),n=g(""),d=g([]),x=!1,l=g(!1);const de=[{url:Y("/"),meta:{title:"This Is a Fake Search Result"},excerpt:"Because the search cannot work in the <mark>dev</mark> environment."},{url:Y("/"),meta:{title:"If You Want to Test the Search"},excerpt:"Try running <mark>npm build && npm preview</mark> instead."}],G=()=>{document.getElementById("search-panel")?.classList.toggle("float-panel-closed")},k=(t,a)=>{const r=document.getElementById("search-panel");!r||!a||(t?r.classList.remove("float-panel-closed"):r.classList.add("float-panel-closed"))},H=()=>{const t=document.getElementById("search-panel");t&&t.classList.add("float-panel-closed"),s(i,""),s(n,""),s(d,[])},J=(t,a)=>{t.preventDefault(),H(),le(a)},p=async(t,a)=>{if(!t){k(!1,a),s(d,[]);return}if(e(l))try{let r=[];if(x&&window.pagefind){const m=await window.pagefind.search(t);r=await Promise.all(m.results.map(v=>v.data()))}else r=[],console.error("Pagefind is not available in production environment.");s(d,r),k(e(d).length>0,a)}catch(r){console.error("Search error:",r),s(d,[]),k(!1,a)}finally{}};X(()=>{const t=()=>{s(l,!0),x=typeof window<"u"&&!!window.pagefind&&typeof window.pagefind.search=="function",console.log("Pagefind status on init:",x),e(i)&&p(e(i),!0),e(n)&&p(e(n),!1)};document.addEventListener("pagefindready",()=>{console.log("Pagefind ready event received."),t()}),document.addEventListener("pagefindloaderror",()=>{console.warn("Pagefind load error event received. Search functionality will be limited."),t()}),setTimeout(()=>{e(l)||(console.log("Fallback: Initializing search after timeout."),t())},2e3)}),R(()=>(e(l),e(i)),()=>{e(l)&&e(i)&&(async()=>await p(e(i),!0))()}),R(()=>(e(l),e(n)),()=>{e(l)&&e(n)&&(async()=>await p(e(n),!1))()}),$(),Z();var P=ce(),y=ee(P),S=f(y);w(S,{icon:"material-symbols:search",class:"absolute text-[1.25rem] pointer-events-none ml-3 transition my-auto text-black/30 dark:text-white/30"});var u=o(S,2);j(u),c(y);var h=o(y,2),N=f(h);w(N,{icon:"material-symbols:search",class:"text-[1.25rem]"}),c(h);var L=o(h,2),_=f(L),E=f(_);w(E,{icon:"material-symbols:search",class:"absolute text-[1.25rem] pointer-events-none ml-3 transition my-auto text-black/30 dark:text-white/30"});var T=o(E,2);j(T),c(_);var O=o(_,2);ie(O,1,()=>e(d),se,(t,a)=>{var r=oe(),m=f(r),v=f(m,!0),Q=o(v);w(Q,{icon:"fa6-solid:chevron-right",class:"transition text-[0.75rem] translate-x-1 my-auto text-[var(--primary)]"}),c(m);var B=o(m,2);ne(B,()=>(e(a),b(()=>e(a).excerpt)),!0),c(B),c(r),z(()=>{C(r,"href",(e(a),b(()=>e(a).url))),re(v,(e(a),b(()=>e(a).meta.title)))}),I("click",r,U=>J(U,e(a).url)),F(t,r)}),c(L),z(t=>C(u,"placeholder",t),[()=>(M(W),M(V),b(()=>W(V.search)))]),K(u,()=>e(i),t=>s(i,t)),I("focus",u,()=>p(e(i),!0)),I("click",h,G),K(T,()=>e(n),t=>s(n,t)),F(A,P),te()}export{Se as default};
|