(function () { 'use strict'; const WIDGET_STYLE_ID = 'usageWidgetStyles'; const ROOT_ID = 'usageWidgetRoot'; function escapeHtml(text) { return String(text) .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); } function slugify(text) { return String(text) .trim() .toLowerCase() .replace(/[\u4e00-\u9fa5]/g, (m) => m) // keep CJK .replace(/[^\w\u4e00-\u9fa5\-\s]/g, '') .replace(/\s+/g, '-') .replace(/-+/g, '-') .replace(/^\-+|\-+$/g, ''); } function ensureStyles() { if (document.getElementById(WIDGET_STYLE_ID)) return; const style = document.createElement('style'); style.id = WIDGET_STYLE_ID; style.textContent = ` #${ROOT_ID} { position: fixed; z-index: 9999; left: 16px; bottom: 16px; font-family: inherit; } #${ROOT_ID} .uw-fab { display: inline-flex; align-items: center; gap: 8px; padding: 12px 18px; border-radius: 999px; border: 1px solid rgba(0,0,0,0.10); background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #ffffff; font-weight: 800; font-size: 14px; box-shadow: 0 14px 34px rgba(0,0,0,0.26); cursor: pointer; user-select: none; } #${ROOT_ID} .uw-fab:hover { transform: translateY(-1px); } #${ROOT_ID} .uw-fab:active { transform: translateY(0px); } #${ROOT_ID} .uw-fab .uw-dot { width: 10px; height: 10px; border-radius: 999px; background: rgba(255,255,255,0.95); box-shadow: 0 0 0 3px rgba(255,255,255,0.18); } #${ROOT_ID} .uw-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 10000; opacity: 0; pointer-events: none; transition: opacity 180ms ease; } #${ROOT_ID}.open .uw-overlay { opacity: 1; pointer-events: auto; } #${ROOT_ID} .uw-drawer { position: fixed; left: 50%; top: 50%; z-index: 10001; width: min(980px, calc(100vw - 48px)); height: min(86vh, 920px); background: #ffffff; border-radius: 14px; border: 1px solid rgba(0,0,0,0.10); box-shadow: 0 20px 60px rgba(0,0,0,0.25); overflow: hidden; transform: translate(-50%, -50%) translateY(12px) scale(0.98); opacity: 0; pointer-events: none; transition: transform 220ms ease, opacity 220ms ease; } #${ROOT_ID}.open .uw-drawer { transform: translate(-50%, -50%) translateY(0px) scale(1); opacity: 1; pointer-events: auto; } #${ROOT_ID} .uw-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #fff; } #${ROOT_ID} .uw-header .uw-title { font-size: 14px; font-weight: 700; letter-spacing: .2px; } #${ROOT_ID} .uw-header .uw-actions { display: flex; gap: 8px; align-items: center; } #${ROOT_ID} .uw-header button { border: 1px solid rgba(255,255,255,0.35); background: rgba(255,255,255,0.12); color: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer; } #${ROOT_ID} .uw-header button:hover { background: rgba(255,255,255,0.18); } #${ROOT_ID} .uw-body { display: grid; grid-template-columns: 240px 1fr; height: calc(100% - 48px); } #${ROOT_ID} .uw-sidebar { border-right: 1px solid rgba(0,0,0,0.08); background: #f5f7fa; padding: 10px; overflow: auto; } #${ROOT_ID} .uw-content { padding: 12px 14px; overflow: auto; background: #fff; } #${ROOT_ID} .uw-search { width: 100%; padding: 8px 10px; border-radius: 10px; border: 1px solid rgba(0,0,0,0.14); outline: none; margin-bottom: 10px; } #${ROOT_ID} .uw-search:focus { border-color: rgba(102,126,234,0.6); box-shadow: 0 0 0 3px rgba(102,126,234,0.18); } #${ROOT_ID} .uw-toc { display: flex; flex-direction: column; gap: 6px; } #${ROOT_ID} .uw-toc a { display: block; text-decoration: none; color: #2c3e50; padding: 6px 8px; border-radius: 10px; border: 1px solid transparent; font-size: 13px; line-height: 1.2; } #${ROOT_ID} .uw-toc a:hover { background: #ffffff; border-color: rgba(0,0,0,0.08); } #${ROOT_ID} .uw-toc .uw-toc-section { display: block; } #${ROOT_ID} .uw-toc .uw-toc-h1 { display: flex; align-items: center; justify-content: space-between; font-weight: 800; } #${ROOT_ID} .uw-toc .uw-toc-h1::after { content: '▸'; color: rgba(102,126,234,0.95); font-size: 12px; margin-left: 8px; } #${ROOT_ID} .uw-toc .uw-toc-section.expanded .uw-toc-h1::after { content: '▾'; } #${ROOT_ID} .uw-toc .uw-toc-children { display: none; margin-top: 4px; } #${ROOT_ID} .uw-toc .uw-toc-section.expanded .uw-toc-children { display: block; } #${ROOT_ID} .uw-toc a.level-2 { padding-left: 16px; font-size: 12.5px; opacity: 0.95; } #${ROOT_ID} .uw-toc a.level-3 { padding-left: 24px; font-size: 12px; opacity: 0.9; } #${ROOT_ID} .uw-md h1 { font-size: 18px; margin: 14px 0 10px; color: #2c3e50; } #${ROOT_ID} .uw-md h2 { font-size: 16px; margin: 14px 0 10px; color: #2c3e50; } #${ROOT_ID} .uw-md h3 { font-size: 14px; margin: 12px 0 8px; color: #2c3e50; } #${ROOT_ID} .uw-md p { margin: 8px 0; color: #333; } #${ROOT_ID} .uw-md ul { margin: 8px 0 8px 20px; } #${ROOT_ID} .uw-md li { margin: 4px 0; } #${ROOT_ID} .uw-md code { background: #f0f0f0; padding: 2px 6px; border-radius: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; } #${ROOT_ID} .uw-md pre { background: #1e1e1e; color: #f8f8f2; padding: 12px; border-radius: 12px; overflow: auto; margin: 10px 0; } #${ROOT_ID} .uw-md pre code { background: transparent; padding: 0; color: inherit; } #${ROOT_ID} .uw-muted { color: #6c757d; font-size: 13px; } `; document.head.appendChild(style); } function buildMarkdownHtml(markdown) { // Minimal markdown rendering: headings (#..###), fenced code blocks, inline code, unordered lists, paragraphs. // This is intentionally lightweight (no external deps). const lines = String(markdown || '').replace(/\r\n/g, '\n').split('\n'); const toc = []; const usedIds = new Map(); function uniqueId(base) { const raw = base || 'section'; let id = raw; let i = 2; while (usedIds.has(id)) { id = `${raw}-${i++}`; } usedIds.set(id, true); return id; } let html = ''; let inCode = false; let codeLang = ''; let codeBuf = []; let inUl = false; function closeUl() { if (inUl) { html += ''; inUl = false; } } function flushParagraph(text) { closeUl(); if (!text) return; const withInline = escapeHtml(text).replace(/`([^`]+)`/g, '$1'); html += `

${withInline}

`; } for (const line of lines) { const fence = line.match(/^```\s*(.*)\s*$/); if (fence) { if (!inCode) { closeUl(); inCode = true; codeLang = fence[1] || ''; codeBuf = []; } else { const code = codeBuf.join('\n'); html += `
${escapeHtml(code)}
`; inCode = false; codeLang = ''; codeBuf = []; } continue; } if (inCode) { codeBuf.push(line); continue; } const h = line.match(/^(#{1,3})\s+(.*)$/); if (h) { closeUl(); const level = h[1].length; const text = h[2].trim(); const id = uniqueId(slugify(text) || `h${level}`); toc.push({ level, text, id }); html += `${escapeHtml(text)}`; continue; } const ul = line.match(/^\s*[-*]\s+(.*)$/); if (ul) { if (!inUl) { closeUl(); html += '