const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["chunks/MonacoCodeEditor-C0N7R_L7.js","chunks/userWordsDB-DsejeZBm.js"])))=>i.map(i=>d[i]);
import{L as T,C as A,a as $,_ as Q}from"./options-5ptWd5XQ.js";import{i as Y,j as P,b as E,s as Z,k as ee,h as D}from"./advancedPicker-DV-udjsq.js";import{c as v,r as o,j as e}from"./userWordsDB-DsejeZBm.js";import{P as te}from"./plus-Cn8TrgvA.js";import{S as re}from"./save-DJlKelt-.js";import{T as ae}from"./trash-2-BAv7X652.js";const se=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]],oe=v("external-link",se);const ne=[["path",{d:"M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35",key:"1wthlu"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m5 16-3 3 3 3",key:"331omg"}],["path",{d:"m9 22 3-3-3-3",key:"lsp7cz"}]],z=v("file-code-corner",ne);const ie=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],de=v("maximize-2",ie);const ce=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],le=v("minimize-2",ce);const me=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],pe=v("play",me),ue=o.lazy(()=>Q(()=>import("./MonacoCodeEditor-C0N7R_L7.js"),__vite__mapDeps([0,1])).then(a=>({default:a.MonacoCodeEditor}))),xe=`<!doctype html>
<html>
  <head>
    <title>Word Picker Test Page</title>
  </head>
  <body>
    <main data-course-id="course-123" data-lesson-id="lesson-7">
      <h1>Hidden route demo</h1>
      <button data-target="lesson-7">Target</button>
    </main>
  </body>
</html>`;function g(a){return{...a}}async function we(){const a=globalThis.chrome;if(!a?.userScripts?.getScripts)return"disabled";try{return await a.userScripts.getScripts(),"enabled"}catch{return"disabled"}}function fe(){E.tabs.create({url:`chrome://extensions/?id=${E.runtime.id}`})}function Se(){const[a,n]=o.useState([]),[i,d]=o.useState(null),[r,c]=o.useState(null),[l,m]=o.useState(xe),[u,w]=o.useState("Hidden route demo"),[p,I]=o.useState("{}"),[H,y]=o.useState({state:"idle",message:"尚未执行"}),[U,j]=o.useState({state:"idle",message:"尚未执行"}),[f,h]=o.useState("idle"),[b,k]=o.useState(!1),[O,q]=o.useState("checking");o.useEffect(()=>{Y().then(t=>{if(n(t),t[0])d(t[0].id),c(g(t[0]));else{const s=P();d(s.id),c(s)}})},[]),o.useEffect(()=>{we().then(q)},[]),o.useEffect(()=>{if(!b)return;const t=document.body.style.overflow;document.body.style.overflow="hidden";const s=x=>{x.key==="Escape"&&k(!1)};return window.addEventListener("keydown",s),()=>{document.body.style.overflow=t,window.removeEventListener("keydown",s)}},[b]);const N=o.useMemo(()=>a.find(t=>t.id===i),[a,i]),V=o.useMemo(()=>r?N?JSON.stringify(r)!==JSON.stringify(N):!0:!1,[r,N]),S=t=>{c(s=>s&&{...s,...t})},W=t=>{d(t.id),c(g(t)),h("idle")},M=()=>{const t=P();d(t.id),c(t),h("idle")},F=async()=>{if(!r||!r.domainContains.trim())return;h("loading");const t=await Z(r);n(t),d(r.id),c(g(t.find(s=>s.id===r.id))),h("success")},J=async()=>{if(!r||!a.some(G=>G.id===r.id)){M();return}if(!window.confirm(`确定要删除 Picker「${r.domainContains||"未填写域名"}」吗？

已记录的单词来源不会被删除，但对应的高级跳转按钮会失效，直到重新添加匹配的 Picker。`))return;const s=await ee(r.id);n(s);const x=s[0]??P();d(x.id),c(g(x)),h("idle")},B=async()=>{if(r){y({state:"loading",message:"执行中"});try{const{result:t}=await L({kind:"parameter",html:l,script:r.parameterScript,params:{selectedText:u}}),s=D(t);I(s),y({state:"success",message:s})}catch(t){y({state:"error",message:t instanceof Error?t.message:String(t)})}}},K=async()=>{if(r){j({state:"loading",message:"执行中"});try{const t=JSON.parse(p||"{}"),{result:s,logs:x}=await L({kind:"route",html:l,script:r.routeScript,params:t});j({state:"success",message:ve(s,x)})}catch(t){j({state:"error",message:t instanceof Error?t.message:String(t)})}}},X=f==="loading"?T:f==="success"?A:f==="error"?$:re;return e.jsxs("div",{className:"min-w-0 w-full",children:[e.jsxs("header",{className:"mb-5 flex flex-wrap items-center justify-between gap-3 border-b border-[var(--wp-border-soft)] pb-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-3",children:[e.jsx("h1",{className:"font-mono text-xl font-bold tracking-tight",children:"高级 Picker"}),O==="disabled"&&e.jsxs("div",{className:"flex min-w-0 items-center gap-2 rounded-md border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-xs text-[var(--wp-text-secondary)]",children:[e.jsx("span",{className:"min-w-0",children:"必须在扩展详情页开启 Allow User Scripts / 允许用户脚本，才可以使用"}),e.jsxs("button",{type:"button",onClick:fe,className:"inline-flex h-7 flex-shrink-0 items-center gap-1.5 rounded-md border border-amber-500/30 bg-[var(--wp-surface)] px-2.5 text-xs font-medium text-[var(--wp-text-secondary)] transition-colors hover:border-amber-500/60 hover:bg-[var(--wp-surface-hover)] hover:text-[var(--wp-text-primary)]",children:[e.jsx(oe,{className:"h-3.5 w-3.5"}),"打开详情页"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>k(!0),disabled:!r,className:"flex h-9 w-9 items-center justify-center rounded-md border border-[var(--wp-border)] bg-[var(--wp-surface)] text-[var(--wp-text-secondary)] transition-colors hover:border-[var(--wp-text-faint)] hover:bg-[var(--wp-surface-hover)] hover:text-[var(--wp-text-primary)] disabled:cursor-not-allowed disabled:opacity-50",title:"全屏编辑","aria-label":"全屏编辑",children:e.jsx(de,{className:"h-4 w-4"})}),e.jsxs("button",{type:"button",onClick:M,className:"flex h-9 items-center gap-2 rounded-md border border-[var(--wp-border)] bg-[var(--wp-surface)] px-3 text-xs font-medium text-[var(--wp-text-secondary)] transition-colors hover:border-[var(--wp-text-faint)] hover:bg-[var(--wp-surface-hover)] hover:text-[var(--wp-text-primary)]",children:[e.jsx(te,{className:"h-4 w-4"}),"新增 Picker"]})]})]}),e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-4 xl:grid-cols-[280px_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"min-w-0 rounded-xl border border-[var(--wp-border-soft)] bg-[var(--wp-surface)] p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 font-mono text-xs font-bold uppercase tracking-widest text-[var(--wp-text-secondary)]",children:[e.jsx(z,{className:"h-4 w-4"}),"Pickers"]}),e.jsx("div",{className:"custom-scrollbar flex max-h-[640px] flex-col gap-2 overflow-y-auto",children:a.length===0?e.jsx("div",{className:"rounded-lg border border-[var(--wp-border-soft)] bg-[var(--wp-surface-muted)] px-3 py-4 text-center text-xs text-[var(--wp-text-muted)]",children:"暂无配置"}):a.map(t=>{const s=r?.id===t.id;return e.jsxs("button",{type:"button",onClick:()=>W(t),className:`rounded-lg border px-3 py-2 text-left transition-colors ${s?"border-[var(--wp-accent)] bg-[var(--wp-surface-muted)]":"border-[var(--wp-border-soft)] hover:bg-[var(--wp-surface-hover)]"}`,children:[e.jsx("div",{className:"truncate text-xs font-medium text-[var(--wp-text-primary)]",children:t.domainContains||"未填写域名"}),e.jsx("div",{className:"mt-1 font-mono text-[10px] uppercase tracking-widest text-[var(--wp-text-muted)]",children:"contain"})]},t.id)})})]}),r&&e.jsxs("section",{className:b?"fixed inset-0 z-50 min-w-0 space-y-4 overflow-y-auto bg-[var(--wp-bg)] p-4 sm:p-5 lg:p-6":"min-w-0 space-y-4",children:[b&&e.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between gap-3 border-b border-[var(--wp-border-soft)] bg-[var(--wp-bg)] py-3",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"truncate font-mono text-xs font-bold uppercase tracking-widest text-[var(--wp-text-secondary)]",children:"Picker 编辑"})}),e.jsx("button",{type:"button",onClick:()=>k(!1),className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-md border border-[var(--wp-border)] bg-[var(--wp-surface)] text-[var(--wp-text-secondary)] transition-colors hover:border-[var(--wp-text-faint)] hover:bg-[var(--wp-surface-hover)] hover:text-[var(--wp-text-primary)]",title:"退出全屏","aria-label":"退出全屏",children:e.jsx(le,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"min-w-0 rounded-xl border border-[var(--wp-border-soft)] bg-[var(--wp-surface)] p-4",children:e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-4 lg:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsxs("label",{className:"flex min-w-0 flex-col gap-1.5",children:[e.jsx("span",{className:"font-mono text-[11px] uppercase tracking-widest text-[var(--wp-text-muted)]",children:"域名 contain"}),e.jsx("input",{className:"h-10 min-w-0 rounded-md border border-[var(--wp-border)] bg-[var(--wp-bg)] px-3 text-sm text-[var(--wp-text-primary)] outline-none transition-colors placeholder:text-[var(--wp-text-faint)] focus:border-[var(--wp-accent)]",value:r.domainContains,onChange:t=>S({domainContains:t.target.value}),placeholder:"example.com 或 /app/course"})]}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("button",{type:"button",onClick:F,disabled:!r.domainContains.trim()||f==="loading",className:"flex h-10 items-center gap-2 rounded-md bg-[var(--wp-accent)] px-3 text-xs font-medium text-white transition-colors hover:bg-[var(--wp-accent-hover)] disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(X,{className:`h-4 w-4 ${f==="loading"?"animate-spin":""}`}),V?"保存":"已保存"]}),e.jsx("button",{type:"button",onClick:J,className:"flex h-10 w-10 items-center justify-center rounded-md border border-[var(--wp-border)] bg-[var(--wp-surface)] text-[var(--wp-text-muted)] transition-colors hover:border-[var(--wp-danger)] hover:text-[var(--wp-danger)]",title:"删除","aria-label":"删除 Picker",children:e.jsx(ae,{className:"h-4 w-4"})})]})]})}),e.jsxs("div",{className:"min-w-0 rounded-xl border border-[var(--wp-border-soft)] bg-[var(--wp-surface)] p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-mono text-xs font-bold uppercase tracking-widest text-[var(--wp-text-secondary)]",children:"测试 HTML"}),e.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"flex-shrink-0 font-mono text-[11px] uppercase tracking-widest text-[var(--wp-text-muted)]",children:"Selected"}),e.jsx("input",{value:u,onChange:t=>w(t.target.value),className:"h-8 min-w-0 rounded-md border border-[var(--wp-border)] bg-[var(--wp-bg)] px-2 font-mono text-xs text-[var(--wp-text-secondary)] outline-none transition-colors placeholder:text-[var(--wp-text-faint)] focus:border-[var(--wp-accent)]"})]})]}),e.jsx(C,{language:"html",value:l,height:"260px",onChange:m,loadDelay:500})]}),e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]",children:[e.jsx(_,{title:"Parameter Script",resultTitle:"Parameter Result",result:H,onRun:B,runLabel:"测试 Parameter",children:e.jsx(C,{language:"javascript",value:r.parameterScript,height:"360px",onChange:t=>S({parameterScript:t}),loadDelay:0})}),e.jsx(_,{title:"Route Script",resultTitle:"Route Log",result:U,onRun:K,runLabel:"测试 Route",primaryAction:!0,children:e.jsx(C,{language:"javascript",value:r.routeScript,height:"360px",onChange:t=>S({routeScript:t}),loadDelay:250})})]})]})]})]})}function _({title:a,resultTitle:n,result:i,onRun:d,runLabel:r,primaryAction:c=!1,children:l}){return e.jsxs("div",{className:"min-w-0 space-y-4 rounded-xl border border-[var(--wp-border-soft)] bg-[var(--wp-surface)] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h2",{className:"font-mono text-xs font-bold uppercase tracking-widest text-[var(--wp-text-secondary)]",children:a}),e.jsxs("button",{type:"button",onClick:d,className:`flex h-9 items-center gap-2 rounded-md px-3 text-xs font-medium transition-colors ${c?"bg-[var(--wp-accent)] text-white hover:bg-[var(--wp-accent-hover)]":"border border-[var(--wp-border)] bg-[var(--wp-surface)] text-[var(--wp-text-secondary)] hover:border-[var(--wp-text-faint)] hover:bg-[var(--wp-surface-hover)] hover:text-[var(--wp-text-primary)]"}`,children:[e.jsx(pe,{className:"h-4 w-4"}),r]})]}),l,e.jsx(he,{title:n,result:i})]})}function C({language:a,value:n,height:i,onChange:d,loadDelay:r=0}){const[c,l]=o.useState(!1);return o.useEffect(()=>{const m=window.setTimeout(()=>l(!0),r);return()=>window.clearTimeout(m)},[r]),c?e.jsx(o.Suspense,{fallback:e.jsx(R,{height:i}),children:e.jsx(ue,{language:a,value:n,height:i,onChange:d})}):e.jsx(R,{height:i})}function R({height:a}){return e.jsxs("div",{className:"flex items-center justify-center rounded-lg border border-[var(--wp-border-soft)] bg-[var(--wp-surface-muted)] font-mono text-[11px] uppercase tracking-widest text-[var(--wp-text-muted)]",style:{height:a},children:[e.jsx(T,{className:"mr-2 h-4 w-4 animate-spin"}),"Editor"]})}function he({title:a,result:n}){const i=n.state==="loading"?T:n.state==="success"?A:n.state==="error"?$:z;return e.jsxs("div",{className:"rounded-lg border border-[var(--wp-border-soft)] bg-[var(--wp-surface-muted)] p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2 font-mono text-[11px] uppercase tracking-widest text-[var(--wp-text-muted)]",children:[e.jsx(i,{className:`h-3.5 w-3.5 ${n.state==="loading"?"animate-spin":""}`}),a]}),e.jsx("pre",{className:`custom-scrollbar max-h-[170px] overflow-auto whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed ${n.state==="error"?"text-[var(--wp-danger)]":"text-[var(--wp-text-secondary)]"}`,children:n.message})]})}function ve(a,n){const i=[];for(const d of n??[])i.push(`${d.args.length>0?d.args.join(" "):""}`);return typeof a<"u"&&i.push(D(a)),i.length>0?i.join(`
`):"执行完成"}async function L({kind:a,html:n,script:i,params:d}){const r=document.createElement("iframe");r.style.position="fixed",r.style.left="-10000px",r.style.top="-10000px",r.style.width="1px",r.style.height="1px",r.src=E.runtime.getURL("/advanced-picker-runner.html");const c=crypto.randomUUID();await new Promise((l,m)=>{const u=window.setTimeout(()=>{m(new Error("脚本测试环境加载超时"))},5e3);r.addEventListener("load",()=>{window.clearTimeout(u),l()},{once:!0}),document.body.appendChild(r)});try{return await new Promise((l,m)=>{const u=window.setTimeout(()=>{window.removeEventListener("message",w),m(new Error("脚本测试执行超时"))},5e3);function w(p){if(p.source===r.contentWindow&&p.data?.source==="word-picker-advanced-runner"&&p.data.id===c){if(window.clearTimeout(u),window.removeEventListener("message",w),!p.data.ok){m(new Error(p.data.error||"脚本测试失败"));return}l(p.data)}}window.addEventListener("message",w),r.contentWindow?.postMessage({source:"word-picker-advanced-tester",id:c,kind:a,html:n,script:i,params:d},"*")})}finally{r.remove()}}export{Se as AdvancedPickerPanel};
