{"version":3,"file":"SearchInit.Ai_2IEir.mjs","names":["useState","useRef","_Fragment","Spin"],"sources":["https:/framerusercontent.com/modules/kxPqisrvjTtklaoRt4Ke/PBlUETFihdfqAQPFjvJa/SearchInit.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{useEffect,useRef,useState}from\"react\";import{createPortal}from\"react-dom\";import{addPropertyControls,ControlType,useIsOnFramerCanvas}from\"framer\";import{Spin}from\"antd\";import{getSearchStore}from\"https://framerusercontent.com/modules/DWzP1Es6eLVEhr2Evhku/sDsDtG2um40fog9Q1zCA/SearchStore.js\";export default function SearchInit(props){const{storeId=\"docs\",paramName=\"q\",simulateLoading=false,progressColor=\"#000000\",trackColor=\"rgba(0, 0, 0, 0.1)\",backgroundColor=\"rgba(255, 255, 255, 0.6)\",tipText=\"努力搜索中...\",tipColor=\"#666666\"}=props;if(typeof window===\"undefined\"){return null;}const isOnCanvas=useIsOnFramerCanvas();const[loading,setLoading]=useState(false);const[percent,setPercent]=useState(\"auto\");const[mounted,setMounted]=useState(false);// ✅ 记录上一次处理过的 query，避免重复触发\nconst lastHandledQueryRef=useRef(null);useEffect(()=>{setMounted(true);},[]);const checkAndSearch=()=>{console.log(\"[SearchInit] checkAndSearch url =\",window.location.href);if(isOnCanvas){console.log(\"[SearchInit] isOnCanvas -> skip\");setLoading(false);return;}if(simulateLoading){console.log(\"[SearchInit] simulateLoading -> show spin\");setLoading(true);setPercent(\"auto\");document.body.style.overflow=\"hidden\";return;}const params=new URLSearchParams(window.location.search);const query=params.get(paramName);console.log(\"[SearchInit] url param query =\",query);if(!query){console.log(\"[SearchInit] no query in URL -> setLoading(false)\");// ✅ URL 没 query 了，清空 lastHandled，避免后续相同关键词被误判重复\nlastHandledQueryRef.current=null;setLoading(false);return;}const store=getSearchStore(storeId);const storeQuery=store.getQuery?.();console.log(\"[SearchInit] store.getQuery() =\",storeQuery);console.log(\"[SearchInit] lastHandledQueryRef =\",lastHandledQueryRef.current);// ��� 去重：只避免“同一个 URL query 在短时间内重复处理”\nif(lastHandledQueryRef.current===query){console.log(\"[SearchInit] dedup hit -> return (no spin, no setQuery)\");return;}lastHandledQueryRef.current=query;console.log(\"[SearchInit] trigger spin + store.setQuery from URL =\",query);setLoading(true);setPercent(\"auto\");document.body.style.overflow=\"hidden\";store.setQuery(query);setTimeout(()=>{console.log(\"[SearchInit] timeout done -> setLoading(false)\");setLoading(false);document.body.style.overflow=\"\";},500);};useEffect(()=>{console.log(\"[SearchInit] useEffect init deps changed -> checkAndSearch()\");checkAndSearch();},[storeId,paramName,simulateLoading,isOnCanvas]);useEffect(()=>{if(isOnCanvas)return;const handlePopState=()=>{console.log(\"[SearchInit] popstate event\");checkAndSearch();};const originalPushState=history.pushState;const originalReplaceState=history.replaceState;history.pushState=function(...args){console.log(\"[SearchInit] history.pushState called\",args);originalPushState.apply(this,args);setTimeout(checkAndSearch,100);};history.replaceState=function(...args){console.log(\"[SearchInit] history.replaceState called\",args);originalReplaceState.apply(this,args);setTimeout(checkAndSearch,100);};window.addEventListener(\"popstate\",handlePopState);return()=>{window.removeEventListener(\"popstate\",handlePopState);history.pushState=originalPushState;history.replaceState=originalReplaceState;};},[storeId,paramName,isOnCanvas]);if(!loading||!mounted)return null;const spinContent=/*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(\"style\",{children:`\n                .search-init-overlay {\n                    position: fixed !important;\n                    inset: 0 !important;\n                    z-index: 9999 !important;\n                    backdrop-filter: blur(9px);\n                    background: ${backgroundColor} !important;\n                    display: flex !important;\n                    align-items: center !important;\n                    justify-content: center !important;\n                }\n                .search-init-overlay .ant-spin {\n                    position: static !important;\n                    transform: none !important;\n                }\n                .search-init-overlay .ant-spin-dot-holder svg circle.ant-spin-dot-circle-bg {\n                    stroke: ${trackColor} !important;\n                }\n                .search-init-overlay .ant-spin-dot-holder svg circle.ant-spin-dot-circle:not(.ant-spin-dot-circle-bg) {\n                    stroke: ${progressColor} !important;\n                }\n            `}),/*#__PURE__*/_jsx(\"div\",{className:\"search-init-overlay\",children:/*#__PURE__*/_jsx(Spin,{spinning:loading,percent:percent,tip:/*#__PURE__*/_jsx(\"span\",{style:{color:tipColor,marginTop:24,display:\"block\"},children:tipText})})})]});return /*#__PURE__*/createPortal(spinContent,document.body);}SearchInit.defaultProps={storeId:\"docs\",paramName:\"q\",simulateLoading:false,progressColor:\"#1890ff\",trackColor:\"rgba(0, 0, 0, 0.1)\",backgroundColor:\"rgba(255, 255, 255, 0.6)\",tipText:\"努力搜索中...\",tipColor:\"#666666\"};addPropertyControls(SearchInit,{storeId:{type:ControlType.String,title:\"Store ID\",defaultValue:\"docs\"},paramName:{type:ControlType.String,title:\"URL 参数名\",defaultValue:\"q\"},simulateLoading:{type:ControlType.Boolean,title:\"模拟加载\",defaultValue:false},progressColor:{type:ControlType.Color,title:\"进度条颜色\",defaultValue:\"#000000\"},trackColor:{type:ControlType.Color,title:\"轨道颜色\",defaultValue:\"rgba(0, 0, 0, 0.1)\"},backgroundColor:{type:ControlType.Color,title:\"背景色\",defaultValue:\"rgba(255, 255, 255, 0.6)\"},tipText:{type:ControlType.String,title:\"提示文字\",defaultValue:\"努力搜索中...\"},tipColor:{type:ControlType.Color,title:\"文字颜色\",defaultValue:\"#666666\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"SearchInit\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SearchInit.map"],"mappings":"qVAA0X,SAAwB,EAAW,EAAM,CAAC,GAAK,CAAC,UAAQ,OAAO,YAAU,IAAI,kBAAgB,GAAM,gBAAc,UAAU,aAAW,qBAAqB,kBAAgB,2BAA2B,UAAQ,WAAW,WAAS,WAAW,EAAM,GAAU,IAAS,OAAa,OAAO,KAAM,IAAM,EAAW,GAAqB,CAAM,CAAC,EAAQ,GAAYA,EAAS,G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