import{k as D,j as _,t as B,m as F,p as v,w as E,i as T,v as P,A as R,x as C,s as W}from"./web.Os7kOAdY.js";import{c as z}from"./clipboard.BNxbz_oK.js";import{g as S,t as A}from"./i18n-runtime._BAkvU05.js";var I=R(`<div class=panel style=display:flex;flex-direction:column;gap:12px><div class=tool-actions style=display:flex;gap:8px;flex-wrap:wrap;align-items:center><button class=tool-btn></button><button class=tool-btn></button><button class="tool-btn is-ghost"></button><button class="tool-btn is-ghost"></button></div><div class=mobile-stack-split style="display:grid;grid-template-columns:1fr 1fr;gap:0;border:1px solid var(--border);border-radius:12px;overflow:hidden;min-height:520px"><div style="display:flex;flex-direction:column;border-right:1px solid var(--border)"><div style="padding:8px 14px;background:var(--surface-soft);border-bottom:1px solid var(--border);font-size:12px;font-weight:600;color:var(--muted);letter-spacing:0.06em">EDITOR</div><textarea style="flex:1;resize:none;border:0;outline:none;padding:14px;font-family:'JetBrains Mono',ui-monospace,monospace;font-size:13px;line-height:1.6;background:var(--surface);color:var(--text);tab-size:2"></textarea></div><div style=display:flex;flex-direction:column;overflow:hidden><div style="padding:8px 14px;background:var(--surface-soft);border-bottom:1px solid var(--border);font-size:12px;font-weight:600;color:var(--muted);letter-spacing:0.06em">PREVIEW</div><div style="flex:1;padding:14px 18px;overflow-y:auto;font-size:14px;line-height:1.7;color:var(--text);background:var(--surface)"></div></div></div><div class=tool-hint style=font-size:12px;color:var(--muted)>`);function O(y){let t="";const r=y.split(`
`);let o=0,d=!1,h=[],n="";const b=l=>l.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),s=l=>{let e=b(l);return e=e.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,'<img src="$2" alt="$1" style="max-width:100%;border-radius:6px;" />'),e=e.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener">$1</a>'),e=e.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),e=e.replace(/__(.+?)__/g,"<strong>$1</strong>"),e=e.replace(/\*(.+?)\*/g,"<em>$1</em>"),e=e.replace(/_(.+?)_/g,"<em>$1</em>"),e=e.replace(/~~(.+?)~~/g,"<del>$1</del>"),e=e.replace(/`([^`]+)`/g,'<code style="background:var(--surface-soft);padding:2px 6px;border-radius:4px;font-size:0.9em;">$1</code>'),e},a=()=>{n&&(t+=n==="ul"?"</ul>":"</ol>",n="")};for(;o<r.length;){const l=r[o];if(l.trim().startsWith("```"))if(d){d=!1,t+=`<pre style="background:var(--surface-soft);border:1px solid var(--border);border-radius:8px;padding:14px;overflow-x:auto;font-size:13px;line-height:1.6;"><code>${b(h.join(`
`))}</code></pre>`,o++;continue}else{a(),d=!0,l.trim().slice(3).trim(),h=[],o++;continue}if(d){h.push(l),o++;continue}if(l.trim()===""){a(),o++;continue}const e=l.match(/^(#{1,6})\s+(.+)/);if(e){a();const i=e[1].length;t+=`<h${i} style="margin:18px 0 8px;font-weight:700;">${s(e[2])}</h${i}>`,o++;continue}if(/^(---|\*\*\*|___)/.test(l.trim())){a(),t+='<hr style="border:none;border-top:1px solid var(--border);margin:16px 0;" />',o++;continue}if(l.trim().startsWith(">")){a();const i=[];for(;o<r.length&&r[o].trim().startsWith(">");)i.push(r[o].replace(/^>\s?/,"")),o++;t+=`<blockquote style="border-left:3px solid var(--accent-strong);margin:12px 0;padding:8px 16px;color:var(--muted);background:var(--surface-soft);border-radius:0 8px 8px 0;">${i.map(f=>s(f)).join("<br/>")}</blockquote>`;continue}const p=l.match(/^(\s*)[*\-+]\s+(.+)/);if(p){n!=="ul"&&(a(),t+='<ul style="margin:8px 0;padding-left:24px;">',n="ul"),t+=`<li>${s(p[2])}</li>`,o++;continue}const m=l.match(/^(\s*)\d+\.\s+(.+)/);if(m){n!=="ol"&&(a(),t+='<ol style="margin:8px 0;padding-left:24px;">',n="ol"),t+=`<li>${s(m[2])}</li>`,o++;continue}const u=l.match(/^(\s*)[*\-+]\s+\[([ xX])\]\s+(.+)/);if(u){n!=="ul"&&(a(),t+='<ul style="margin:8px 0;padding-left:24px;list-style:none;">',n="ul");const i=u[2]!==" ";t+=`<li>${i?"&#9745;":"&#9744;"} ${s(u[3])}</li>`,o++;continue}if(l.includes("|")){a();const i=[];for(;o<r.length&&r[o].includes("|");)i.push(r[o]),o++;if(i.length>=2){const f=c=>c.split("|").map(g=>g.trim()).filter(g=>g!==""),$=f(i[0]),k=i.slice(2);t+='<table style="width:100%;border-collapse:collapse;margin:12px 0;font-size:13px;"><thead><tr>',$.forEach(c=>{t+=`<th style="border:1px solid var(--border);padding:8px 10px;background:var(--surface-soft);text-align:left;">${s(c)}</th>`}),t+="</tr></thead><tbody>",k.forEach(c=>{const g=f(c);t+="<tr>",g.forEach(w=>{t+=`<td style="border:1px solid var(--border);padding:8px 10px;">${s(w)}</td>`}),t+="</tr>"}),t+="</tbody></table>"}continue}a(),t+=`<p style="margin:8px 0;line-height:1.7;">${s(l)}</p>`,o++}return a(),d&&(t+=`<pre style="background:var(--surface-soft);border:1px solid var(--border);border-radius:8px;padding:14px;overflow-x:auto;font-size:13px;line-height:1.6;"><code>${b(h.join(`
`))}</code></pre>`),t}const q=`# Markdown Preview

## Features

- **Bold**, *italic*, ~~strikethrough~~
- [Links](https://example.com) and \`inline code\`
- Task lists, tables, blockquotes

> This is a blockquote with **rich** formatting.

### Code Block

\`\`\`javascript
function hello(name) {
  return \`Hello, \${name}!\`;
}
\`\`\`

### Table

| Feature | Status |
|---------|--------|
| Headers | Done |
| Lists   | Done |
| Tables  | Done |

### Task List

- [x] Implement parser
- [x] Live preview
- [ ] Export HTML
`;function N(){const[y,t]=_(S(),{equals:!1}),r=l=>A(l,y());B(()=>{const l=e=>{const p=e.detail?.locale;p&&t(p)};window.addEventListener("taitan:locale-change",l),t(S()),W(()=>window.removeEventListener("taitan:locale-change",l))});const[o,d]=_(q),[h,n]=_(!1),b=()=>O(o()),s=async()=>{await z(b()),n(!0),setTimeout(()=>n(!1),1500)},a=async()=>{await z(o()),n(!0),setTimeout(()=>n(!1),1500)};return(()=>{var l=F(I),e=l.firstChild,p=e.firstChild,m=p.nextSibling,u=m.nextSibling,i=u.nextSibling,f=e.nextSibling,$=f.firstChild,k=$.firstChild,c=k.nextSibling,g=$.nextSibling,w=g.firstChild,H=w.nextSibling,j=f.nextSibling;return p.$$click=a,v(p,()=>h()?"已复制":"复制 Markdown"),m.$$click=s,v(m,()=>r("复制 HTML")),u.$$click=()=>d(""),v(u,()=>r("清空")),i.$$click=()=>d(q),v(i,()=>r("示例")),c.$$input=x=>d(x.currentTarget.value),E(c,"spellcheck",!1),v(j,()=>r("支持 GFM 语法：标题、粗体、斜体、删除线、代码块、列表、任务列表、表格、引用、链接、图片、水平线")),T(x=>{var M=r("输入 Markdown..."),L=b();return M!==x.e&&E(c,"placeholder",x.e=M),L!==x.t&&C(H,"innerHTML",x.t=L),x},{e:void 0,t:void 0}),T(()=>C(c,"value",o())),P(),l})()}D(["click","input"]);export{N as default};
