weifuwu 0.65.1 → 0.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/client/browser.d.ts +10 -0
- package/dist/client/index.js +4 -4
- package/dist/client/types.d.ts +43 -0
- package/dist/client/ui.d.ts +8 -0
- package/dist/components/Anchor/Anchor.d.ts +27 -0
- package/dist/components/Editor/Editor.d.ts +1 -1
- package/dist/components/FileUpload/FileUpload.d.ts +4 -0
- package/dist/components/JSONViewer/JSONViewer.d.ts +21 -0
- package/dist/components/LogViewer/LogViewer.d.ts +29 -0
- package/dist/components/Menu/Menu.d.ts +11 -2
- package/dist/components/VirtualTable/VirtualTable.d.ts +32 -0
- package/dist/components/index.d.ts +8 -0
- package/dist/components/index.js +13 -11
- package/dist/components/style.css +531 -11
- package/dist/index.js +25 -0
- package/docs/components-map.md +11 -7
- package/docs/custom-components.md +26 -0
- package/docs/frontend.md +28 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# weifuwu
|
|
2
2
|
|
|
3
|
-
**自托管全栈框架** — 一个 npm 包 = 后端 HTTP + 前端 VDOM +
|
|
3
|
+
**自托管全栈框架** — 一个 npm 包 = 后端 HTTP + 前端 VDOM + 96 组件 + CSS 设计系统 + SaaS 地基(认证 / 消息 / 队列 / AI)。全自研、零构建、消灭样板。
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install weifuwu # 一个依赖,完整应用栈
|
|
@@ -23,8 +23,8 @@ npm install weifuwu # 一个依赖,完整应用栈
|
|
|
23
23
|
| 层 | 入口 | 能力 |
|
|
24
24
|
|----|------|------|
|
|
25
25
|
| 后端 | `weifuwu` | Trie 路由 / 中间件链 / serve / 自研 PG+Redis / SSR / GraphQL / WebSocket |
|
|
26
|
-
| 前端 | `weifuwu/client` | 两阶段组件 / Proxy 渲染 / 数据管道 / 路由 / api·auth·ws·i18n / 移动端原语 |
|
|
27
|
-
| 组件 | `weifuwu/components` |
|
|
26
|
+
| 前端 | `weifuwu/client` | 两阶段组件 / Proxy 渲染 / 数据管道 / 路由 / api·auth·ws·i18n / 移动端原语 / **ctx.browser 环境抽象**(组件零 window/document) |
|
|
27
|
+
| 组件 | `weifuwu/components` | 96 个 HTML 原语组件(表单/表格/弹层/AiChat…),引用 `--wf-*` 主题变量 |
|
|
28
28
|
| 样式 | `weifuwu/layout` | 70 布局原语 + 141 主题 Token,零自定义 CSS 文件 |
|
|
29
29
|
| SaaS 地基 | 随包内置 | rateLimit / email / userSystem / messager / queue / ai → `ctx.*` 一行接入 |
|
|
30
30
|
|
|
@@ -109,7 +109,7 @@ npm install weifuwu # 一个依赖,完整应用栈
|
|
|
109
109
|
|
|
110
110
|
**自研数据层** — `ctx.sql`(PG v3 协议)与 `ctx.redis`(RESP2 协议)为**自研客户端**:确定性输出、行为可预测、统一错误模型。jsonb 自动解码、TTL 安全 API、schema 写前校验——高频痛点(双重编码/parseRow 样板/`'EX'` 参数顺序)从根上消除。
|
|
111
111
|
|
|
112
|
-
> **实践验证**:多租户 AI 平台(`apps/agent-platform`——14 页 + 部门聊天 + 知识库 + HITL 审批)已完全运行在框架上:auth(userSystem)/ AI 引擎(ai)/ 实时消息(messager)/ UI(
|
|
112
|
+
> **实践验证**:多租户 AI 平台(`apps/agent-platform`——14 页 + 部门聊天 + 知识库 + HITL 审批)已完全运行在框架上:auth(userSystem)/ AI 引擎(ai)/ 实时消息(messager)/ UI(96 组件)/ 数据管道(ctx.api)零自研替代。框架哲学(中间件注入、诚实裁剪、机制与策略分离)经受住了真实复杂应用的检验——这也是我们确定「哪些进框架、哪些留应用层」的依据。
|
|
113
113
|
|
|
114
114
|
---
|
|
115
115
|
|
|
@@ -218,7 +218,7 @@ createApp().use(router({ routes })).mount('#root', RouteView, { hydrate: true })
|
|
|
218
218
|
### 30 秒体验(跑现有 demo)
|
|
219
219
|
|
|
220
220
|
```bash
|
|
221
|
-
# ① 组件 cheatsheet——
|
|
221
|
+
# ① 组件 cheatsheet——96 组件全部可交互预览(零依赖,5 秒起)
|
|
222
222
|
cd apps/components-demo && node server.ts
|
|
223
223
|
# 打开 http://localhost:3000
|
|
224
224
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* weifuwu/client — 浏览器环境抽象(ctx.browser 的客户端实现)
|
|
3
|
+
*
|
|
4
|
+
* 组件不直接引用 window/document——统一经 ctx.browser:
|
|
5
|
+
* ① SSR 安全(createSsrContext 注入安全默认)② 测试可 mock
|
|
6
|
+
* ③ 复制等重复模式单点实现。
|
|
7
|
+
* 内部对 window/document 做 typeof 防御(SSR/无 DOM 环境不崩)。
|
|
8
|
+
*/
|
|
9
|
+
import type { BrowserEnv } from './types.ts';
|
|
10
|
+
export declare function createClientBrowser(): BrowserEnv;
|
package/dist/client/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var Oe="__wfAsyncComponent";function cn(e){let n=e;return n[Oe]=!0,n}function z(e){return typeof e=="function"&&e?.[Oe]===!0}var D=Symbol("Fragment"),H=Symbol("Portal");function ye(e,n,t){return{type:e,props:We(n),key:t??void 0}}var fn=ye;function dn(e,n,t){return ye(e,n,t)}function pn(e,n,...t){let o=We(n??{});return t.length>0&&(o.children=t.length===1?t[0]:t),{type:e,props:o,key:n?.key??void 0}}function We(e){if(!e)return{};let n={};for(let t of Object.keys(e))t!=="key"&&(n[t]=e[t]);return n}function ge(e,n){return{type:H,props:{children:e,portalKey:n},key:n??void 0,_placement:"remote"}}var mn=0,L=new Map,ne=[];function F(e){ne.push(e)}var te=new WeakMap;function Y(){te=new WeakMap}function he(e,n){let t=te.get(e);if(t)return t;let o={promise:null};return o.promise=Promise.resolve().then(()=>e(n)).then(s=>{if(typeof s!="function")throw new Error(`asyncComponent factory <${e.name||"anonymous"}> must return a Component (initProps, ctx) => (props) => VNode.`);return o.resolved=s,s}),te.set(e,o),o}async function Ve(e,n){return he(e,n).promise}function Ie(e){return te.get(e)?.resolved}function yn(e){let n=e._child;if(n!=null)if(Array.isArray(n))for(let t of n)t&&typeof t=="object"&&N(t);else typeof n=="object"&&N(n)}function N(e){if(e==null||typeof e!="object")return;let n=e;if(n._id){if(n._customId&&L.delete(n._customId),L.delete(n._id),ne.length>0){for(let t of ne)t(n._id);if(n._customId)for(let t of ne)t(n._customId)}n._id=void 0,n._customId=void 0,n._render=void 0,n._parentNode=void 0,n._refNode=void 0}if(n._child!=null){if(Array.isArray(n._child))for(let t of n._child)t&&typeof t=="object"&&N(t);else N(n._child);n._child=void 0}if(n.props?.children&&typeof n.type=="string"){let t=Array.isArray(n.props.children)?n.props.children:[n.props.children];for(let o of t)o&&typeof o=="object"&&N(o)}typeof n.props?.ref=="function"&&n.props.ref(null),n._remoteEl&&(yn(n),n._remoteEl.remove(),n._remoteEl=void 0)}function G(){return`_wf_${mn++}`}var He=new WeakMap;function gn(e){let n=He.get(e)??{count:0,warned:!1};n.count++,n.count>=3&&!n.warned&&(n.warned=!0,console.warn("[weifuwu] ref \u51FD\u6570\u6BCF\u6B21\u6E32\u67D3\u90FD\u53D8\u5316\uFF08\u5185\u8054 ref\uFF09\u2014\u2014ref \u56DE\u8C03\u5728\u6BCF\u6B21\u6E32\u67D3\u540E\u91CD\u65B0\u6267\u884C\uFF08\u6027\u80FD\u635F\u8017\uFF09\u3002\u628A ref \u5B9A\u4E49\u5230 mount \u4F5C\u7528\u57DF\uFF08\u7A33\u5B9A\u5F15\u7528\uFF09\uFF1Aconst listRef = (el) => {...}; return h('div', { ref: listRef })")),He.set(e,n)}function $(e,n,t,o,s){if(t==null){if(o==null)return null;let d=V(o,s);return d==null?null:(n&&n.parentNode?n.parentNode.insertBefore(d,n):e.appendChild(d),d)}if(o==null)return n?(N(t),n.remove()):N(t),null;let l=De(t),u=De(o);if(l!==u){N(t);let d=V(o,s);return d==null?null:(n?.parentNode&&n.parentNode.replaceChild(d,n),d)}if(u==="text")return n&&n.textContent!==String(o)&&(n.textContent=String(o)),n;let f=o,c=t;if(typeof f.type=="function"){let d=f.type;c._render&&(f._render=c._render,f._id=c._id,f._id&&L.set(f._id,f)),f._parentNode=e,f._refNode=n;let y=Object.create(s);if(y.ui=Object.create(s.ui),y.ui._selfId=f._id,y.ui._selfVNode=f,f._ctxVersion=c._ctxVersion??y.ui._ctxVersion??0,c._render&&wn(c.props,f.props)&&!y.ui._dirtySet?.has(c._id)&&f._ctxVersion===y.ui._ctxVersion)return f._child=c._child,n;y.ui._dirtySet?.delete(c._id);let g;try{typeof f._render=="function"?g=f._render(f.props):g=be(d,f.props,f,y)}catch(i){let a=s.ui?._errorHandler;a?(a(i),g=null):(console.error(`[weifuwu] Component render error in <${d?.name||"anonymous"}> (id: ${c._id??"?"}, phase: update)`,i),g=null)}let E=c._child;f._child=g;let r=$(e,n,E,g,y);return r||(f._refNode=null),r}if(f.type===D){let d=c._childNodes,y=Fe(e,c,f,s,d);return f._childNodes=y,n}if(typeof f.type=="string"){if(n&&n.nodeType===1){let d=c.props?.ref,y=f.props?.ref;d!==y&&(typeof y=="function"&&y(n),typeof d=="function"&&typeof y=="function"&&gn(n)),we(n,c.props,f.props),Fe(n,c,f,s)}else if(n){N(t);let d=V(o,s);return d==null?null:(n.parentNode?.replaceChild(d,n),d)}return n}if(f.type===H)return Q(c,f,s),null;if(Array.isArray(o)){let d=Array.isArray(t)?t:[];oe(d,o);let y=Array.from(e.childNodes),g=n?y.indexOf(n):-1,E=g>=0?X(y.slice(g),d):X(y,d);return re(e,d,o,s,E,n),n}return n}var Ue=new Map;function hn(e){let n=Ue.get(e);return n||(n=`fn:${e.name||"anon"}`,Ue.set(e,n)),n}function De(e){if(e==null||typeof e=="boolean")return"null";if(typeof e=="string"||typeof e=="number")return"text";if(Array.isArray(e))return"array";let n=e;return typeof n.type=="function"?hn(n.type):n.type===D?"fragment":n.type===H?"portal":typeof n.type=="string"?"tag:"+n.type:"unknown"}function we(e,n,t){let o=n?Object.keys(n).filter(u=>u!=="children"&&u!=="key"&&u!=="innerHTML"):[],s=t?Object.keys(t).filter(u=>u!=="children"&&u!=="key"&&u!=="innerHTML"):[],l=new Set(s);for(let u of o)if(!l.has(u)){if(u==="ref")continue;u.startsWith("on")&&typeof n[u]=="function"?e.removeEventListener(u.slice(2).toLowerCase(),n[u]):u==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value="":e.removeAttribute(u==="className"?"class":u)}for(let u of s){if(u==="ref")continue;let f=n?.[u],c=t?.[u];if(u==="innerHTML")c!==f&&(e.innerHTML=String(c??""));else if(c!==f)if(u==="class"||u==="className")e instanceof SVGElement?e.setAttribute("class",je(c)):e.className=je(c);else if(u==="style"&&typeof c=="object"){let d=e.style;for(let y of Object.keys(c)){let g=c[y];g!=null&&(d[y]=typeof g=="number"?g+"px":String(g))}}else if(u.startsWith("on")&&typeof c=="function"){let d=u.slice(2).toLowerCase();typeof f=="function"&&e.removeEventListener(d,f),e.addEventListener(d,c)}else u==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value=String(c??""):c===!0?e.setAttribute(u,""):c!=null&&c!==!1?e.setAttribute(u,String(c)):u==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value="":e.removeAttribute(u)}}function je(e){return typeof e=="string"?e:Array.isArray(e)?e.filter(Boolean).join(" "):e&&typeof e=="object"?Object.entries(e).filter(([,n])=>n).map(([n])=>n).join(" "):""}function ve(e){if(!(e==null||typeof e!="object"))return e.key}function oe(e,n){if(!n.some(o=>o&&typeof o=="object"&&o.key!==void 0)){for(let o=0;o<n.length;o++){let s=n[o];s&&typeof s=="object"&&(s.key=o)}for(let o=0;o<e.length;o++){let s=e[o];s&&typeof s=="object"&&(s.key=o)}}}function X(e,n){let t=[],o=0;for(let s of n){if(s==null||typeof s=="boolean"){t.push(null);continue}let l=s;if(l.type===H){t.push(null);continue}if(l.type===D){let u=l._childNodes;Array.isArray(u)&&u.length>0?(t.push(u.slice()),o+=u.length):(t.push(e[o]?[e[o]]:null),o+=1)}else typeof process<"u"&&process.env.DBG&&console.error("[map] idx=",o,"type=",l.type,"sourceLen=",e.length,"hit=",!!e[o]),t.push(e[o]?[e[o]]:null),o+=1}return t}function Fe(e,n,t,o,s){let l=J(n.props?.children),u=J(t.props?.children);oe(l,u);let f=s??Array.from(e.childNodes),c=X(f,l),d=re(e,l,u,o,c,s?.[0]??null),y=[];for(let g of d)g&&g.length>0&&y.push(...g);return y}function J(e){if(e==null)return[];if(!Array.isArray(e))return[e];let n=[];for(let t of e)Array.isArray(t)?n.push(...t):n.push(t);return n}function qe(e){return e==null?[]:e instanceof DocumentFragment?Array.from(e.childNodes):[e]}function re(e,n,t,o,s=[],l=null){if(!t.some(i=>i&&typeof i=="object"&&i.key!==void 0)){let i=Math.max(n.length,t.length);for(let a=0;a<i;a++){let p=a<n.length?n[a]:null,m=a<t.length?t[a]:null;if(m==null){if(p!=null){N(p);for(let h of s[a]??[])h.remove()}}else if(p==null){let h=V(m,o);h!=null&&e.appendChild(h)}else{let h=s[a]?.[0]??null;$(e,h,p,m,o)}}return[]}for(let i=0;i<n.length;i++){let a=n[i];if(!(a==null||typeof a=="boolean")&&ve(a)===void 0)for(let p of s[i]??[])p.remove()}let f=new Map,c=0;for(let i=0;i<n.length;i++){let a=ve(n[i]);a!==void 0&&f.set(a,{vnode:n[i],nodes:s[i]??[],index:c++})}let d=t.map(i=>ve(i)),y=new Set(d);for(let i of[...f.keys()])if(!y.has(i)){let a=f.get(i);N(a.vnode);for(let p of a.nodes)p?.remove();f.delete(i)}let g=new Array(t.length).fill(null),E=-1,r=l&&l.parentNode===e?l:e.firstChild;for(let i=0;i<t.length;i++){let a=d[i],p=t[i],m=a!==void 0?f.get(a):void 0,h=p&&typeof p=="object"&&p._placement==="remote";if(m)if(m.nodes.length>0){if(m.index<E)for(let v of m.nodes)e.insertBefore(v,r);E=Math.max(E,m.index),$(e,m.nodes[0],m.vnode,p,o),g[i]=p._childNodes??m.nodes.filter(v=>v.parentNode===e),r=g[i][g[i].length-1]?.nextSibling??null}else if(h)Q(m.vnode,p,o),g[i]=[];else{let w=$(e,null,m.vnode,p,o);g[i]=qe(w);for(let b of g[i])e.insertBefore(b,r);r=g[i][g[i].length-1]?.nextSibling??null}else if(h)B(p,o),g[i]=[];else{let w=V(p,o);g[i]=qe(w);for(let b of g[i])e.insertBefore(b,r);r=g[i][g[i].length-1]?.nextSibling??null}}return g}function vn(e,n){if(e===n)return!0;if(Array.isArray(e)&&Array.isArray(n)){if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}return e===n}function wn(e,n){if(e===n)return!0;if(!e||!n)return!1;let t=new Set([...Object.keys(e),...Object.keys(n)]);for(let o of t)if(o!=="key"){if(o==="children"){if(!vn(e[o],n[o]))return!1}else if(e[o]!==n[o])return!1}return!0}var Ce="http://www.w3.org/2000/svg",xe=new Set(["svg","path","circle","line","rect","text","g","polyline","polygon","ellipse","defs","use","clipPath","mask","linearGradient","radialGradient","stop","tspan"]);function Ke(e,n){return V(e,n)}function V(e,n){if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number")return document.createTextNode(String(e));if(Array.isArray(e))return xn(e,n);let t=e;if(t.type===H)return B(t,n),null;if(t.type===D){let u=document.createDocumentFragment(),f=t.props?.children==null?[]:Array.isArray(t.props.children)?t.props.children:[t.props.children];for(let c of f){let d=V(c,n);d!=null&&u.appendChild(d)}return t._childNodes=Array.from(u.childNodes),u}if(typeof t.type=="function")return Cn(t.type,t.props,t,n);let o=t.type,s=xe.has(o)?document.createElementNS(Ce,o):document.createElement(o);t.el=s;let l;for(let[u,f]of Object.entries(t.props??{}))u==="children"||u==="key"||u==="value"||u==="innerHTML"||$e(s,u,f);if("value"in(t.props??{})&&s instanceof HTMLSelectElement?l=t.props.value:"value"in(t.props??{})&&$e(s,"value",t.props.value),"innerHTML"in(t.props??{}))s.innerHTML=String(t.props.innerHTML??"");else{let u=Te(t.props?.children);for(let f of u){let c=V(f,n);if(c!=null&&(s.appendChild(c),f&&typeof f=="object"&&typeof f.type=="function")){let d=f;d._parentNode||(d._parentNode=s,d._refNode=c)}}}return l!==void 0&&(s.value=String(l)),typeof t.props?.ref=="function"&&t.props.ref(s),s}function bn(e){let n=e.ui;n&&typeof n.render=="function"&&n.render(["_wf_root"])}function be(e,n,t,o){let s;if(z(e)){if(s=Ie(e),!s)return he(e,o).promise.then(()=>bn(o),()=>{}),null}else s=e;let l=s(n,o);if(typeof l!="function")throw new Error(`Component ${e.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);return t._render=l,l(n)}function Cn(e,n,t,o){o.ui=o.ui??{},t._id||(t._id=G(),L.set(t._id,t));let s=Object.create(o);s.ui=Object.create(o.ui),s.ui._selfId=t._id,s.ui._selfVNode=t,t._ctxVersion=s.ui._ctxVersion??0;let l;try{l=be(e,n,t,s)}catch(f){let c=o.ui?._errorHandler;c?(c(f),l=null):(console.error(`[weifuwu] Component render error in <${e.name||"anonymous"}> (id: ${t._id??"?"}, phase: mount)`,f),l=null)}if(l==null)return t._child=null,null;t._child=l;let u=V(l,s);return t._refNode||(t._refNode=u),u}function xn(e,n){let t=document.createDocumentFragment();for(let o of e){let s=V(o,n);s!=null&&t.appendChild(s)}return t}function Tn(){let e=document.getElementById("__wf_portal");return e||(e=document.createElement("div"),e.id="__wf_portal",e.style.cssText="position:fixed;inset:0;pointer-events:none;z-index:9999",document.body.appendChild(e)),e}function B(e,n){let t=Tn(),o=document.createElement("div");o.style.pointerEvents="auto",t.appendChild(o),e._remoteEl=o;let s=J(e.props?.children);e._child=s;for(let l of s){let u=V(l,n);u!=null&&o.appendChild(u)}}function Q(e,n,t){let o=e?._remoteEl;if(n._remoteEl=o,!o){B(n,t);return}let s=J(n.props?.children),l=e._child||[];n._child=s,oe(l,s);let u=X(Array.from(o.childNodes),l);re(o,l,s,t,u,u[0]?.[0]??null)}function Te(e){if(e==null)return[];if(!Array.isArray(e))return[e];let n=[];for(let t of e)Array.isArray(t)?n.push(...t):n.push(t);return n}function $e(e,n,t){if(n==="class"||n==="className")e instanceof SVGElement?e.setAttribute("class",String(t??"")):e.className=String(t??"");else if(n==="style"&&typeof t=="object"&&t!==null){let o=e.style;for(let s of Object.keys(t)){let l=t[s];l!=null&&(o[s]=typeof l=="number"?l+"px":String(l))}}else n.startsWith("on")&&typeof t=="function"?e.addEventListener(n.slice(2).toLowerCase(),t):n==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value=String(t??""):t===!0?e.setAttribute(n,""):t!=null&&t!==!1&&e.setAttribute(n,String(t))}function En(e,n,t){e.innerHTML="";let o=V(n,t);o instanceof Node?e.appendChild(o):Array.isArray(o)&&o.forEach(s=>e.appendChild(s))}function Ee(e){e.node=e.node?e.node.nextSibling:null}function Pn(e,n){e.node&&e.node.parentNode?e.node.parentNode.insertBefore(n,e.node):e.parent.appendChild(n)}function An(e,n){e.node&&e.node.parentNode?(e.node.parentNode.replaceChild(n,e.node),Ee(e)):e.parent.appendChild(n)}async function Z(e,n,t){if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number"){let f=String(e);if(t.node&&t.node.nodeType===3)return t.node.textContent!==f&&(t.node.textContent=f),Ee(t),t.node;let c=document.createTextNode(f);return Pn(t,c),c}if(Array.isArray(e)){let f=null;for(let c of e){let d=await Z(c,n,t);d!=null&&!f&&(f=d)}return f}let o=e;if(o.type===H||o.type===D){let f=o.props?.children,c=f==null?[]:Array.isArray(f)?f:[f],d=null;for(let y of c){let g=await Z(y,n,t);g!=null&&!d&&(d=g)}return d}if(typeof o.type=="function")return _n(o,n,t);let s=o.type,l=o.props??{},u;if(t.node&&t.node.nodeType===1&&t.node.tagName.toLowerCase()===s.toLowerCase()?(u=t.node,Ee(t)):(u=xe.has(s)?document.createElementNS(Ce,s):document.createElement(s),An(t,u)),o.el=u,we(u,null,l),!("innerHTML"in l)){let f={parent:u,node:u.firstChild},c=Te(l.children);for(let d of c){let y=await Z(d,n,f);if(y!=null&&y.parentNode!==u&&u.appendChild(y),d&&typeof d=="object"&&typeof d.type=="function"){let g=d;g._parentNode||(g._parentNode=u,g._refNode=y)}}for(;f.node;){let d=f.node;f.node=d.nextSibling,d.parentNode?.removeChild(d)}}return"value"in l&&u instanceof HTMLSelectElement&&(u.value=String(l.value??"")),typeof l.ref=="function"&&l.ref(u),u}async function _n(e,n,t){n.ui=n.ui??{},e._id||(e._id=G(),L.set(e._id,e));let o=Object.create(n);o.ui=Object.create(n.ui),o.ui._selfId=e._id,o.ui._selfVNode=e,e._ctxVersion=o.ui._ctxVersion??0;let s=e.type,l;try{let f;z(s)?f=await Ve(s,o):f=s;let c=f(e.props??{},o);if(typeof c!="function")throw new Error(`Component ${s.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);e._render=c,l=c(e.props??{})}catch(f){let c=n.ui?._errorHandler;c?(c(f),l=null):(console.error(`[weifuwu] Component hydration error in <${s.name||"anonymous"}> (id: ${e._id??"?"})`,f),l=null)}if(l==null)return e._child=null,null;e._child=l;let u=await Z(l,o,t);return e._refNode||(e._refNode=u),u}async function Pe(e,n,t){let o={parent:e,node:e.firstChild};for(await Z(n,t,o);o.node;){let s=o.node;o.node=s.nextSibling,s.parentNode?.removeChild(s)}}var se=0,Be="",ze="",Ye="",Ge="",ie=0;function Xe(){return typeof window<"u"&&typeof document<"u"}function Ae(){if(se++,se>1||!Xe())return;ie=window.scrollY;let e=document.body;Be=e.style.overflow,ze=e.style.position,Ye=e.style.top,Ge=e.style.width,e.style.overflow="hidden",(/iPhone|iPad|iPod/.test(navigator.platform)||/Mac/.test(navigator.platform)&&"ontouchend"in document)&&(e.style.position="fixed",e.style.top=`-${ie}px`,e.style.width="100%")}function _e(){if(se--,se>0||!Xe())return;let e=document.body;e.style.overflow=Be,e.style.position=ze,e.style.top=Ye,e.style.width=Ge,ie>0&&window.scrollTo(0,ie)}var Rn='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function ae(e){let n=e.querySelectorAll(Rn);if(n.length===0)return()=>{};let t=n[0],o=n[n.length-1],s=u=>{u.key==="Tab"&&(u.shiftKey&&document.activeElement===t?(u.preventDefault(),o.focus()):!u.shiftKey&&document.activeElement===o&&(u.preventDefault(),t.focus()))},l=document.activeElement;return queueMicrotask(()=>{t.focus()}),e.addEventListener("keydown",s),()=>{e.removeEventListener("keydown",s),l?.focus()}}function le(e){let n=new WeakMap,t=new Set,o=l=>{if(l===null||typeof l!="object")return l;if(n.has(l))return n.get(l);let u=new Proxy(l,{set(f,c,d){if(Reflect.get(f,c)===d)return!0;Reflect.set(f,c,d),e();for(let g of t)g();return!0},get(f,c){let d=Reflect.get(f,c);return typeof d=="object"&&d!==null?o(d):d},deleteProperty(f,c){if(Reflect.has(f,c)){Reflect.deleteProperty(f,c),e();for(let d of t)d()}return!0}});return n.set(l,u),u},s=o({});return Object.defineProperty(s,"__watch",{value:l=>(t.add(l),()=>{t.delete(l)}),writable:!1,enumerable:!1}),s}function Re(e,n,t){let o=new AbortController,s=t?.signal;s&&(s.aborted?o.abort():s.addEventListener("abort",()=>o.abort(),{once:!0}));let l=t?.traceId??Mn(),u=t?.record!==!1,f=[],c=(async()=>{let d;try{d=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Trace-Id":l,Accept:"text/event-stream",...t?.headers},body:JSON.stringify(n),signal:o.signal})}catch(y){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:y instanceof Error?y.message:String(y)});return}if(!d.ok){t?.onError?.({code:Ln(d.status),message:`HTTP ${d.status} ${d.statusText}`});return}try{for await(let{name:y,data:g}of kn(d.body)){if(o.signal.aborted)return;Nn(f,{name:y,data:g},u),Sn(y,g,t??{})}}catch(y){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:y instanceof Error?y.message:String(y)})}})();return{abort:()=>o.abort(),done:c,traceId:l,events:f}}function Sn(e,n,t){switch(e){case"wf:token":return t.onToken?.(n.text);case"wf:tool_call":return t.onToolCall?.(n);case"wf:tool_result":return t.onToolResult?.(n);case"wf:tool_progress":return t.onToolProgress?.(n);case"wf:step":return t.onStep?.(n);case"wf:approval_request":return t.onApproval?.(n);case"wf:usage":return t.onUsage?.(n);case"wf:done":return t.onDone?.(n);case"wf:error":return t.onError?.(n);default:return t.onEvent?.(e,n)}}async function*kn(e){let n=e.getReader(),t=new TextDecoder,o="";try{for(;;){let{done:s,value:l}=await n.read();if(s)break;o+=t.decode(l,{stream:!0});let u=o.split(`
|
|
1
|
+
var Ie="__wfAsyncComponent";function mn(e){let n=e;return n[Ie]=!0,n}function X(e){return typeof e=="function"&&e?.[Ie]===!0}var B=Symbol("Fragment"),q=Symbol("Portal");function we(e,n,t){return{type:e,props:Ue(n),key:t??void 0}}var yn=we;function gn(e,n,t){return we(e,n,t)}function hn(e,n,...t){let o=Ue(n??{});return t.length>0&&(o.children=t.length===1?t[0]:t),{type:e,props:o,key:n?.key??void 0}}function Ue(e){if(!e)return{};let n={};for(let t of Object.keys(e))t!=="key"&&(n[t]=e[t]);return n}function be(e,n){return{type:q,props:{children:e,portalKey:n},key:n??void 0,_placement:"remote"}}var vn=0,W=new Map,ie=[];function K(e){ie.push(e)}var se=new WeakMap;function J(){se=new WeakMap}function Ce(e,n){let t=se.get(e);if(t)return t;let o={promise:null};return o.promise=Promise.resolve().then(()=>e(n)).then(i=>{if(typeof i!="function")throw new Error(`asyncComponent factory <${e.name||"anonymous"}> must return a Component (initProps, ctx) => (props) => VNode.`);return o.resolved=i,i}),se.set(e,o),o}async function De(e,n){return Ce(e,n).promise}function je(e){return se.get(e)?.resolved}function wn(e){let n=e._child;if(n!=null)if(Array.isArray(n))for(let t of n)t&&typeof t=="object"&&O(t);else typeof n=="object"&&O(n)}function O(e){if(e==null||typeof e!="object")return;let n=e;if(n._id){if(n._customId&&W.delete(n._customId),W.delete(n._id),ie.length>0){for(let t of ie)t(n._id);if(n._customId)for(let t of ie)t(n._customId)}n._id=void 0,n._customId=void 0,n._render=void 0,n._parentNode=void 0,n._refNode=void 0}if(n._child!=null){if(Array.isArray(n._child))for(let t of n._child)t&&typeof t=="object"&&O(t);else O(n._child);n._child=void 0}if(n.props?.children&&typeof n.type=="string"){let t=Array.isArray(n.props.children)?n.props.children:[n.props.children];for(let o of t)o&&typeof o=="object"&&O(o)}typeof n.props?.ref=="function"&&n.props.ref(null),n._remoteEl&&(wn(n),n._remoteEl.remove(),n._remoteEl=void 0)}function Q(){return`_wf_${vn++}`}var qe=new WeakMap;function bn(e){let n=qe.get(e)??{count:0,warned:!1};n.count++,n.count>=3&&!n.warned&&(n.warned=!0,console.warn("[weifuwu] ref \u51FD\u6570\u6BCF\u6B21\u6E32\u67D3\u90FD\u53D8\u5316\uFF08\u5185\u8054 ref\uFF09\u2014\u2014ref \u56DE\u8C03\u5728\u6BCF\u6B21\u6E32\u67D3\u540E\u91CD\u65B0\u6267\u884C\uFF08\u6027\u80FD\u635F\u8017\uFF09\u3002\u628A ref \u5B9A\u4E49\u5230 mount \u4F5C\u7528\u57DF\uFF08\u7A33\u5B9A\u5F15\u7528\uFF09\uFF1Aconst listRef = (el) => {...}; return h('div', { ref: listRef })")),qe.set(e,n)}function z(e,n,t,o,i){if(t==null){if(o==null)return null;let c=U(o,i);return c==null?null:(n&&n.parentNode?n.parentNode.insertBefore(c,n):e.appendChild(c),c)}if(o==null)return n?(O(t),n.remove()):O(t),null;let s=Be(t),a=Be(o);if(s!==a){O(t);let c=U(o,i);return c==null?null:(n?.parentNode&&n.parentNode.replaceChild(c,n),c)}if(a==="text")return n&&n.textContent!==String(o)&&(n.textContent=String(o)),n;let u=o,l=t;if(typeof u.type=="function"){let c=u.type;l._render&&(u._render=l._render,u._id=l._id,u._id&&W.set(u._id,u)),u._parentNode=e,u._refNode=n;let p=Object.create(i);if(p.ui=Object.create(i.ui),p.ui._selfId=u._id,p.ui._selfVNode=u,u._ctxVersion=l._ctxVersion??p.ui._ctxVersion??0,l._render&&Tn(l.props,u.props)&&!p.ui._dirtySet?.has(l._id)&&u._ctxVersion===p.ui._ctxVersion)return u._child=l._child,n;p.ui._dirtySet?.delete(l._id);let g;try{typeof u._render=="function"?g=u._render(u.props):g=Ee(c,u.props,u,p)}catch(y){let v=i.ui?._errorHandler;v?(v(y),g=null):(console.error(`[weifuwu] Component render error in <${c?.name||"anonymous"}> (id: ${l._id??"?"}, phase: update)`,y),g=null)}let P=l._child;u._child=g;let C=z(e,n,P,g,p);return C||(u._refNode=null),C}if(u.type===B){let c=l._childNodes,p=$e(e,l,u,i,c);return u._childNodes=p,n}if(typeof u.type=="string"){if(n&&n.nodeType===1){let c=l.props?.ref,p=u.props?.ref;c!==p&&(typeof p=="function"&&p(n),typeof c=="function"&&typeof p=="function"&&bn(n)),Te(n,l.props,u.props),$e(n,l,u,i)}else if(n){O(t);let c=U(o,i);return c==null?null:(n.parentNode?.replaceChild(c,n),c)}return n}if(u.type===q)return ne(l,u,i),null;if(Array.isArray(o)){let c=Array.isArray(t)?t:[];ae(c,o);let p=Array.from(e.childNodes),g=n?p.indexOf(n):-1,P=g>=0?Z(p.slice(g),c):Z(p,c);return le(e,c,o,i,P,n),n}return n}var Fe=new Map;function Cn(e){let n=Fe.get(e);return n||(n=`fn:${e.name||"anon"}`,Fe.set(e,n)),n}function Be(e){if(e==null||typeof e=="boolean")return"null";if(typeof e=="string"||typeof e=="number")return"text";if(Array.isArray(e))return"array";let n=e;return typeof n.type=="function"?Cn(n.type):n.type===B?"fragment":n.type===q?"portal":typeof n.type=="string"?"tag:"+n.type:"unknown"}function Te(e,n,t){let o=n?Object.keys(n).filter(a=>a!=="children"&&a!=="key"&&a!=="innerHTML"):[],i=t?Object.keys(t).filter(a=>a!=="children"&&a!=="key"&&a!=="innerHTML"):[],s=new Set(i);for(let a of o)if(!s.has(a)){if(a==="ref")continue;a.startsWith("on")&&typeof n[a]=="function"?e.removeEventListener(a.slice(2).toLowerCase(),n[a]):a==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value="":e.removeAttribute(a==="className"?"class":a)}for(let a of i){if(a==="ref")continue;let u=n?.[a],l=t?.[a];if(a==="innerHTML")l!==u&&(e.innerHTML=String(l??""));else if(l!==u)if(a==="class"||a==="className")e instanceof SVGElement?e.setAttribute("class",Ke(l)):e.className=Ke(l);else if(a==="style"&&typeof l=="object"){let c=e.style;for(let p of Object.keys(l)){let g=l[p];g!=null&&(c[p]=typeof g=="number"?g+"px":String(g))}}else if(a.startsWith("on")&&typeof l=="function"){let c=a.slice(2).toLowerCase();typeof u=="function"&&e.removeEventListener(c,u),e.addEventListener(c,l)}else a==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value=String(l??""):l===!0?e.setAttribute(a,""):l!=null&&l!==!1?e.setAttribute(a,String(l)):a==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value="":e.removeAttribute(a)}}function Ke(e){return typeof e=="string"?e:Array.isArray(e)?e.filter(Boolean).join(" "):e&&typeof e=="object"?Object.entries(e).filter(([,n])=>n).map(([n])=>n).join(" "):""}function xe(e){if(!(e==null||typeof e!="object"))return e.key}function ae(e,n){if(!n.some(o=>o&&typeof o=="object"&&o.key!==void 0)){for(let o=0;o<n.length;o++){let i=n[o];i&&typeof i=="object"&&(i.key=o)}for(let o=0;o<e.length;o++){let i=e[o];i&&typeof i=="object"&&(i.key=o)}}}function Z(e,n){let t=[],o=0;for(let i of n){if(i==null||typeof i=="boolean"){t.push(null);continue}let s=i;if(s.type===q){t.push(null);continue}if(s.type===B){let a=s._childNodes;Array.isArray(a)&&a.length>0?(t.push(a.slice()),o+=a.length):(t.push(e[o]?[e[o]]:null),o+=1)}else typeof process<"u"&&process.env.DBG&&console.error("[map] idx=",o,"type=",s.type,"sourceLen=",e.length,"hit=",!!e[o]),t.push(e[o]?[e[o]]:null),o+=1}return t}function $e(e,n,t,o,i){let s=ee(n.props?.children),a=ee(t.props?.children);ae(s,a);let u=i??Array.from(e.childNodes),l=Z(u,s),c=le(e,s,a,o,l,i?.[0]??null),p=[];for(let g of c)g&&g.length>0&&p.push(...g);return p}function ee(e){if(e==null)return[];if(!Array.isArray(e))return[e];let n=[];for(let t of e)Array.isArray(t)?n.push(...t):n.push(t);return n}function ze(e){return e==null?[]:e instanceof DocumentFragment?Array.from(e.childNodes):[e]}function le(e,n,t,o,i=[],s=null){if(!t.some(y=>y&&typeof y=="object"&&y.key!==void 0)){let y=Math.max(n.length,t.length);for(let v=0;v<y;v++){let r=v<n.length?n[v]:null,f=v<t.length?t[v]:null;if(f==null){if(r!=null){O(r);for(let d of i[v]??[])d.remove()}}else if(r==null){let d=U(f,o);d!=null&&e.appendChild(d)}else{let d=i[v]?.[0]??null;z(e,d,r,f,o)}}return[]}for(let y=0;y<n.length;y++){let v=n[y];if(!(v==null||typeof v=="boolean")&&xe(v)===void 0)for(let r of i[y]??[])r.remove()}let u=new Map,l=0;for(let y=0;y<n.length;y++){let v=xe(n[y]);v!==void 0&&u.set(v,{vnode:n[y],nodes:i[y]??[],index:l++})}let c=t.map(y=>xe(y)),p=new Set(c);for(let y of[...u.keys()])if(!p.has(y)){let v=u.get(y);O(v.vnode);for(let r of v.nodes)r?.remove();u.delete(y)}let g=new Array(t.length).fill(null),P=-1,C=s&&s.parentNode===e?s:e.firstChild;for(let y=0;y<t.length;y++){let v=c[y],r=t[y],f=v!==void 0?u.get(v):void 0,d=r&&typeof r=="object"&&r._placement==="remote";if(f)if(f.nodes.length>0){if(f.index<P)for(let h of f.nodes)e.insertBefore(h,C);P=Math.max(P,f.index),z(e,f.nodes[0],f.vnode,r,o),g[y]=r._childNodes??f.nodes.filter(h=>h.parentNode===e),C=g[y][g[y].length-1]?.nextSibling??null}else if(d)ne(f.vnode,r,o),g[y]=[];else{let m=z(e,null,f.vnode,r,o);g[y]=ze(m);for(let b of g[y])e.insertBefore(b,C);C=g[y][g[y].length-1]?.nextSibling??null}else if(d)G(r,o),g[y]=[];else{let m=U(r,o);g[y]=ze(m);for(let b of g[y])e.insertBefore(b,C);C=g[y][g[y].length-1]?.nextSibling??null}}return g}function xn(e,n){if(e===n)return!0;if(Array.isArray(e)&&Array.isArray(n)){if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}return e===n}function Tn(e,n){if(e===n)return!0;if(!e||!n)return!1;let t=new Set([...Object.keys(e),...Object.keys(n)]);for(let o of t)if(o!=="key"){if(o==="children"){if(!xn(e[o],n[o]))return!1}else if(e[o]!==n[o])return!1}return!0}var Pe="http://www.w3.org/2000/svg",_e=new Set(["svg","path","circle","line","rect","text","g","polyline","polygon","ellipse","defs","use","clipPath","mask","linearGradient","radialGradient","stop","tspan"]);function Ge(e,n){return U(e,n)}function U(e,n){if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number")return document.createTextNode(String(e));if(Array.isArray(e))return _n(e,n);let t=e;if(t.type===q)return G(t,n),null;if(t.type===B){let a=document.createDocumentFragment(),u=t.props?.children==null?[]:Array.isArray(t.props.children)?t.props.children:[t.props.children];for(let l of u){let c=U(l,n);c!=null&&a.appendChild(c)}return t._childNodes=Array.from(a.childNodes),a}if(typeof t.type=="function")return Pn(t.type,t.props,t,n);let o=t.type,i=_e.has(o)?document.createElementNS(Pe,o):document.createElement(o);t.el=i;let s;for(let[a,u]of Object.entries(t.props??{}))a==="children"||a==="key"||a==="value"||a==="innerHTML"||Ye(i,a,u);if("value"in(t.props??{})&&i instanceof HTMLSelectElement?s=t.props.value:"value"in(t.props??{})&&Ye(i,"value",t.props.value),"innerHTML"in(t.props??{}))i.innerHTML=String(t.props.innerHTML??"");else{let a=Ae(t.props?.children);for(let u of a){let l=U(u,n);if(l!=null&&(i.appendChild(l),u&&typeof u=="object"&&typeof u.type=="function")){let c=u;c._parentNode||(c._parentNode=i,c._refNode=l)}}}return s!==void 0&&(i.value=String(s)),typeof t.props?.ref=="function"&&t.props.ref(i),i}function En(e){let n=e.ui;n&&typeof n.render=="function"&&n.render(["_wf_root"])}function Ee(e,n,t,o){let i;if(X(e)){if(i=je(e),!i)return Ce(e,o).promise.then(()=>En(o),()=>{}),null}else i=e;o.ui?.setMounting?.(!0);let s;try{s=i(n,o)}finally{o.ui?.endMounting?.()}if(typeof s!="function")throw new Error(`Component ${e.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);return t._render=s,s(n)}function Pn(e,n,t,o){o.ui=o.ui??{},t._id||(t._id=Q(),W.set(t._id,t));let i=Object.create(o);i.ui=Object.create(o.ui),i.ui._selfId=t._id,i.ui._selfVNode=t,t._ctxVersion=i.ui._ctxVersion??0;let s;try{s=Ee(e,n,t,i)}catch(u){let l=o.ui?._errorHandler;l?(l(u),s=null):(console.error(`[weifuwu] Component render error in <${e.name||"anonymous"}> (id: ${t._id??"?"}, phase: mount)`,u),s=null)}if(s==null)return t._child=null,null;t._child=s;let a=U(s,i);return t._refNode||(t._refNode=a),a}function _n(e,n){let t=document.createDocumentFragment();for(let o of e){let i=U(o,n);i!=null&&t.appendChild(i)}return t}function An(){let e=document.getElementById("__wf_portal");return e||(e=document.createElement("div"),e.id="__wf_portal",e.style.cssText="position:fixed;inset:0;pointer-events:none;z-index:9999",document.body.appendChild(e)),e}function G(e,n){let t=An(),o=document.createElement("div");o.style.pointerEvents="auto",t.appendChild(o),e._remoteEl=o;let i=ee(e.props?.children);e._child=i;for(let s of i){let a=U(s,n);a!=null&&o.appendChild(a)}}function ne(e,n,t){let o=e?._remoteEl;if(n._remoteEl=o,!o){G(n,t);return}let i=ee(n.props?.children),s=e._child||[];n._child=i,ae(s,i);let a=Z(Array.from(o.childNodes),s);le(o,s,i,t,a,a[0]?.[0]??null)}function Ae(e){if(e==null)return[];if(!Array.isArray(e))return[e];let n=[];for(let t of e)Array.isArray(t)?n.push(...t):n.push(t);return n}function Ye(e,n,t){if(n==="class"||n==="className")e instanceof SVGElement?e.setAttribute("class",String(t??"")):e.className=String(t??"");else if(n==="style"&&typeof t=="object"&&t!==null){let o=e.style;for(let i of Object.keys(t)){let s=t[i];s!=null&&(o[i]=typeof s=="number"?s+"px":String(s))}}else n.startsWith("on")&&typeof t=="function"?e.addEventListener(n.slice(2).toLowerCase(),t):n==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value=String(t??""):t===!0?e.setAttribute(n,""):t!=null&&t!==!1&&e.setAttribute(n,String(t))}function Sn(e,n,t){e.innerHTML="";let o=U(n,t);o instanceof Node?e.appendChild(o):Array.isArray(o)&&o.forEach(i=>e.appendChild(i))}function Se(e){e.node=e.node?e.node.nextSibling:null}function Rn(e,n){e.node&&e.node.parentNode?e.node.parentNode.insertBefore(n,e.node):e.parent.appendChild(n)}function kn(e,n){e.node&&e.node.parentNode?(e.node.parentNode.replaceChild(n,e.node),Se(e)):e.parent.appendChild(n)}async function te(e,n,t){if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number"){let u=String(e);if(t.node&&t.node.nodeType===3)return t.node.textContent!==u&&(t.node.textContent=u),Se(t),t.node;let l=document.createTextNode(u);return Rn(t,l),l}if(Array.isArray(e)){let u=null;for(let l of e){let c=await te(l,n,t);c!=null&&!u&&(u=c)}return u}let o=e;if(o.type===q||o.type===B){let u=o.props?.children,l=u==null?[]:Array.isArray(u)?u:[u],c=null;for(let p of l){let g=await te(p,n,t);g!=null&&!c&&(c=g)}return c}if(typeof o.type=="function")return Nn(o,n,t);let i=o.type,s=o.props??{},a;if(t.node&&t.node.nodeType===1&&t.node.tagName.toLowerCase()===i.toLowerCase()?(a=t.node,Se(t)):(a=_e.has(i)?document.createElementNS(Pe,i):document.createElement(i),kn(t,a)),o.el=a,Te(a,null,s),!("innerHTML"in s)){let u={parent:a,node:a.firstChild},l=Ae(s.children);for(let c of l){let p=await te(c,n,u);if(p!=null&&p.parentNode!==a&&a.appendChild(p),c&&typeof c=="object"&&typeof c.type=="function"){let g=c;g._parentNode||(g._parentNode=a,g._refNode=p)}}for(;u.node;){let c=u.node;u.node=c.nextSibling,c.parentNode?.removeChild(c)}}return"value"in s&&a instanceof HTMLSelectElement&&(a.value=String(s.value??"")),typeof s.ref=="function"&&s.ref(a),a}async function Nn(e,n,t){n.ui=n.ui??{},e._id||(e._id=Q(),W.set(e._id,e));let o=Object.create(n);o.ui=Object.create(n.ui),o.ui._selfId=e._id,o.ui._selfVNode=e,e._ctxVersion=o.ui._ctxVersion??0;let i=e.type,s;try{let u;X(i)?u=await De(i,o):u=i;let l=u(e.props??{},o);if(typeof l!="function")throw new Error(`Component ${i.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);e._render=l,s=l(e.props??{})}catch(u){let l=n.ui?._errorHandler;l?(l(u),s=null):(console.error(`[weifuwu] Component hydration error in <${i.name||"anonymous"}> (id: ${e._id??"?"})`,u),s=null)}if(s==null)return e._child=null,null;e._child=s;let a=await te(s,o,t);return e._refNode||(e._refNode=a),a}async function Re(e,n,t){let o={parent:e,node:e.firstChild};for(await te(n,t,o);o.node;){let i=o.node;o.node=i.nextSibling,i.parentNode?.removeChild(i)}}var ue=0,Xe="",Je="",Qe="",Ze="",ce=0;function en(){return typeof window<"u"&&typeof document<"u"}function ke(){if(ue++,ue>1||!en())return;ce=window.scrollY;let e=document.body;Xe=e.style.overflow,Je=e.style.position,Qe=e.style.top,Ze=e.style.width,e.style.overflow="hidden",(/iPhone|iPad|iPod/.test(navigator.platform)||/Mac/.test(navigator.platform)&&"ontouchend"in document)&&(e.style.position="fixed",e.style.top=`-${ce}px`,e.style.width="100%")}function Ne(){if(ue--,ue>0||!en())return;let e=document.body;e.style.overflow=Xe,e.style.position=Je,e.style.top=Qe,e.style.width=Ze,ce>0&&window.scrollTo(0,ce)}var Mn='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function de(e){let n=e.querySelectorAll(Mn);if(n.length===0)return()=>{};let t=n[0],o=n[n.length-1],i=a=>{a.key==="Tab"&&(a.shiftKey&&document.activeElement===t?(a.preventDefault(),o.focus()):!a.shiftKey&&document.activeElement===o&&(a.preventDefault(),t.focus()))},s=document.activeElement;return queueMicrotask(()=>{t.focus()}),e.addEventListener("keydown",i),()=>{e.removeEventListener("keydown",i),s?.focus()}}function fe(e){let n=new WeakMap,t=new Set,o=s=>{if(s===null||typeof s!="object")return s;if(n.has(s))return n.get(s);let a=new Proxy(s,{set(u,l,c){if(Reflect.get(u,l)===c)return!0;Reflect.set(u,l,c),e();for(let g of t)g();return!0},get(u,l){let c=Reflect.get(u,l);return typeof c=="object"&&c!==null?o(c):c},deleteProperty(u,l){if(Reflect.has(u,l)){Reflect.deleteProperty(u,l),e();for(let c of t)c()}return!0}});return n.set(s,a),a},i=o({});return Object.defineProperty(i,"__watch",{value:s=>(t.add(s),()=>{t.delete(s)}),writable:!1,enumerable:!1}),i}function Me(e,n,t){let o=new AbortController,i=t?.signal;i&&(i.aborted?o.abort():i.addEventListener("abort",()=>o.abort(),{once:!0}));let s=t?.traceId??Hn(),a=t?.record!==!1,u=[],l=(async()=>{let c;try{c=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Trace-Id":s,Accept:"text/event-stream",...t?.headers},body:JSON.stringify(n),signal:o.signal})}catch(p){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:p instanceof Error?p.message:String(p)});return}if(!c.ok){t?.onError?.({code:Vn(c.status),message:`HTTP ${c.status} ${c.statusText}`});return}try{for await(let{name:p,data:g}of On(c.body)){if(o.signal.aborted)return;Wn(u,{name:p,data:g},a),Ln(p,g,t??{})}}catch(p){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:p instanceof Error?p.message:String(p)})}})();return{abort:()=>o.abort(),done:l,traceId:s,events:u}}function Ln(e,n,t){switch(e){case"wf:token":return t.onToken?.(n.text);case"wf:tool_call":return t.onToolCall?.(n);case"wf:tool_result":return t.onToolResult?.(n);case"wf:tool_progress":return t.onToolProgress?.(n);case"wf:step":return t.onStep?.(n);case"wf:approval_request":return t.onApproval?.(n);case"wf:usage":return t.onUsage?.(n);case"wf:done":return t.onDone?.(n);case"wf:error":return t.onError?.(n);default:return t.onEvent?.(e,n)}}async function*On(e){let n=e.getReader(),t=new TextDecoder,o="";try{for(;;){let{done:i,value:s}=await n.read();if(i)break;o+=t.decode(s,{stream:!0});let a=o.split(`
|
|
2
2
|
|
|
3
|
-
`);o=
|
|
4
|
-
`))y.startsWith("event: ")?c=y.slice(7):y.startsWith("data: ")&&(d+=y.slice(6));if(d)try{yield{name:c,data:JSON.parse(d)}}catch{}}}}finally{n.releaseLock()}}function Nn(e,n,t){t&&(e.length>=1e3&&e.shift(),e.push(n))}function Ln(e){return e===401||e===403?"auth_failed":e===429?"rate_limited":e>=500?"provider_error":"invalid_request"}function Mn(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`trace-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function Je(e){return e.map(n=>({role:n.role,content:n.content}))}function Se(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`msg-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function Qe(e,n,t){t.initialMessages?e.messages=structuredClone(t.initialMessages):e.messages===void 0&&(e.messages=[]),e.input===void 0&&(e.input=""),e.streaming===void 0&&(e.streaming=!1),e.error===void 0&&(e.error=null),e.usage===void 0&&(e.usage=null),e.step===void 0&&(e.step=null);let o=null;function s(){if(!e.streaming)return;let r=e.messages[e.messages.length-1];return r&&r.role==="assistant"&&r.status==="streaming"?r:void 0}function l(r,i,a){let p=s();switch(r){case"wf:token":p&&(p.content+=i.text);break;case"wf:tool_call":{p&&(p.toolCalls||(p.toolCalls=[]),p.toolCalls.push({call:i,status:"running"}));break}case"wf:tool_progress":{let m=i,h=p?.toolCalls?.find(w=>w.call.id===m.toolCallId);h&&(h.progress=m);break}case"wf:tool_result":{let m=i,h=p?.toolCalls?.find(w=>w.call.id===m.id);h&&(h.result=m,h.status=m.ok?"ok":"error");break}case"wf:approval_request":p&&(p.approval=i);break;case"wf:usage":p&&(p.usage=i);break;case"wf:step":e.step=i;break;case"wf:done":p&&(p.status="done",p.approval=void 0),e.streaming=!1,e.step=null;break;case"wf:error":p&&(p.status="error",p.error=i,p.approval=void 0),e.error=i,e.streaming=!1,e.step=null;break;default:a?.(r,i);break}}function u(){let r=t.body?t.body(e.messages):{messages:Je(e.messages)};o=n(t.url,r,{onToken:a=>l("wf:token",{text:a}),onToolCall:a=>l("wf:tool_call",a),onToolProgress:a=>l("wf:tool_progress",a),onToolResult:a=>l("wf:tool_result",a),onApproval:a=>l("wf:approval_request",a),onUsage:a=>l("wf:usage",a),onStep:a=>l("wf:step",a),onDone:a=>l("wf:done",a),onError:a=>l("wf:error",a),onEvent:(a,p)=>l(a,p,t.onEvent)},{signal:t.signal,headers:t.headers}),e.streaming=!0;let i=s();i&&o?.traceId&&(i.id=o.traceId)}function f(){if(e.streaming)return;let r=String(e.input??"").trim();r&&(e.input="",e.error=null,e.usage=null,e.step=null,e.messages.push({id:Se(),role:"user",content:r,status:"done"},{id:Se(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),u())}function c(){o?.abort(),e.streaming=!1,e.step=null;let r=e.messages[e.messages.length-1];r&&r.role==="assistant"&&r.status==="streaming"&&(!r.content&&(!r.toolCalls||r.toolCalls.length===0)?e.messages.pop():r.status="done")}function d(){if(e.streaming)return;let r=-1;for(let i=e.messages.length-1;i>=0;i--)if(e.messages[i].role==="user"){r=i;break}r!==-1&&(e.messages.splice(r+1),e.error=null,e.usage=null,e.step=null,e.messages.push({id:Se(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),u())}function y(){o?.abort(),e.messages=[],e.input="",e.streaming=!1,e.error=null,e.usage=null,e.step=null}async function g(r,i){let a=e.messages[e.messages.length-1],p=a?.role==="assistant"?a.approval:void 0;if(p&&(a.approval=void 0,!!t.approveUrl))try{await fetch(t.approveUrl,{method:"POST",headers:{"Content-Type":"application/json",...t.headers},body:JSON.stringify({id:p.id,decision:r,note:i}),signal:t.signal})}catch(m){if(t.signal?.aborted)return;e.error={code:"provider_error",message:m instanceof Error?m.message:String(m)}}}function E(){o?.abort(),o=null}return{send:f,stop:c,retry:d,clear:y,approve:g,dispose:E}}function ue(e,n="bottom",t=6,o=!0){switch(n){case"bottom":return{top:e.bottom+t,left:o?e.left+e.width/2:e.left};case"top":return{top:e.top-t,left:o?e.left+e.width/2:e.left};case"left":return{top:o?e.top+e.height/2:e.top,left:e.left-t};case"right":return{top:o?e.top+e.height/2:e.top,left:e.right+t}}}function On(e,n="bottom",t=6,o=!0){return ue(e.getBoundingClientRect(),n,t,o)}function ce(e,n,t=8){if(!n)return e;let o=n.getBoundingClientRect();if(o.width===0&&o.height===0)return e;let s=Number.parseFloat(n.style.top)||o.top,l=Number.parseFloat(n.style.left)||o.left,u=e.top-s,f=e.left-l,c={top:o.top+u,bottom:o.bottom+u,left:o.left+f,right:o.right+f},d=window.innerWidth,y=window.innerHeight,g=e.top,E=e.left;return c.bottom>y-t&&(g=Math.max(t,g-(c.bottom-(y-t)))),c.top<t&&(g=Math.max(t,g+(t-c.top))),c.right>d-t&&(E=Math.max(t,E-(c.right-(d-t)))),c.left<t&&(E=Math.max(t,E+(t-c.left))),{top:g,left:E,width:e.width}}var Ze=new Set,ee=new Map;function en(e){let{ctx:n,renderByIds:t,getSelfId:o,dirtyBatch:s,dirtySet:l,mediaRegistry:u,popupTrackers:f,scrollTrackers:c,schedulePopupRecompute:d,ensurePopupListeners:y,isRendering:g}=e;return{_selfId:"_wf_root",_ctxVersion:0,_dirtySet:l,bumpCtxVersion:function(){this._ctxVersion++},render:function(r){if(!r||r.length===0){let i=o(this);if(i)r=[i];else return}t(r)},dirty:function(r){if(!g()){if(!r||r.length===0){let i=o(this);if(i)r=[i];else return}for(let i of r)i&&(s.add(i),l.add(i));this._dirtyScheduled||(this._dirtyScheduled=!0,queueMicrotask(()=>{this._dirtyScheduled=!1;let i=[...s];s.clear(),i.length>0&&t(i)}))}},$:function(){let r=this;if(!r._$cache){let i=o(this);r._$cache=le(()=>n.ui.dirty(i?[i]:void 0))}return r._$cache},useChat:function(r){let i=this.$(),a=Qe(i,Re,r);return Object.assign(i,{send:a.send,stop:a.stop,retry:a.retry,clear:a.clear,approve:a.approve,dispose:a.dispose}),i},useMedia:function(r,i){let p=`media:${o(this)}:${r}`;if(!u.has(p)){let m=window.matchMedia(r);i(m.matches);let h=w=>i(w.matches);m.addEventListener("change",h),u.set(p,{mql:m,handler:h})}},useBreakpoint:function(r,i){let a=typeof r=="function"?{mobile:"(max-width: 639px)",tablet:"(min-width: 640px) and (max-width: 1023px)",desktop:"(min-width: 1024px)"}:r,p=typeof r=="function"?r:i,h=`bp:${o(this)}`;function w(){for(let[v,b]of Object.entries(a))if(window.matchMedia(b).matches)return v;return Object.keys(a)[0]??""}if(!u.has(h)){p(w());let v=[];for(let b of Object.values(a)){let T=window.matchMedia(b),C=()=>p(w());T.addEventListener("change",C),v.push({mql:T,handler:C})}u.set(h,{mqls:v})}},usePopupPosition:function(r){let i=o(this),a={top:0,left:0,refresh:()=>{}};if(!i)return a;let p={pos:a,getEl:r.el,isOpen:r.isOpen,compute:r.compute,panel:r.panel,margin:r.margin??8};return f.set(i,p),y(),a.refresh=()=>{let m=p.getEl();if(!m)return;let h=p.compute(m.getBoundingClientRect());Object.assign(a,ce(h,p.panel?.(),p.margin))},a},useHoverCapable:function(){return typeof window<"u"&&!!window.matchMedia?.("(hover: hover)").matches},useStableRef:function(r,i){return p=>{p?r(p):i?.()}},useVisualViewport:function(){let r=o(this),i={height:window.innerHeight,offsetTop:0,keyboardOpen:!1},a=()=>{n.ui&&n.ui.dirty(r?[r]:void 0)},p=()=>{let h=window.visualViewport;i.height=h?.height??window.innerHeight,i.offsetTop=h?.offsetTop??0,i.keyboardOpen=i.height<window.innerHeight*.9,a()},m=window.visualViewport;return m?.addEventListener?(m.addEventListener("resize",p),m.addEventListener("scroll",p)):window.addEventListener("resize",p),r&&F(h=>{h===r&&(m?.removeEventListener?(m.removeEventListener("resize",p),m.removeEventListener("scroll",p)):window.removeEventListener("resize",p))}),i},usePopup:function(r){let i=o(this),a=this.useHoverCapable(),p=()=>typeof r.trigger=="function"?r.trigger():r.trigger,m=r.open!==void 0,h=()=>!!r.disabled?.(),w=()=>m?typeof r.open=="function"?!!r.open():!!r.open:r.isOpen(),v=P=>{h()||(m?r.onOpenChange?.(P):r.setOpen(P))},b=()=>{let P=r.placement;return typeof P=="function"?P():P??"bottom"},T=null,C=!1,x=n.ui.usePopupPosition({el:r.el,isOpen:()=>w(),compute:P=>{if(r.position){let M=r.position();return{top:M.y,left:M.x}}return ue(P,b(),r.gap??6,r.center!==!1)},panel:()=>T,margin:r.margin??8}),A=P=>{if(r.closeOnOutside===!1||!w())return;let M=P.target;if(!(M instanceof Node))return;let q=r.el();q&&q.contains(M)||T&&T.contains(M)||v(!1)},S=P=>{r.closeOnEscape!==!1&&(P.key!=="Escape"||!w()||v(!1))};document.addEventListener("mousedown",A),document.addEventListener("keydown",S),i&&F(P=>{P===i&&(document.removeEventListener("mousedown",A),document.removeEventListener("keydown",S))});let R={},_=P=>typeof P=="function"?P():P??0,k=()=>_(r.openDelay),j=()=>_(r.closeDelay),O,W,sn=()=>{clearTimeout(O),clearTimeout(W),O=void 0,W=void 0};if(p()==="hover")a?(R.onMouseEnter=()=>{h()||(clearTimeout(W),W=void 0,O=setTimeout(()=>{O=void 0,v(!0)},k()))},R.onMouseLeave=()=>{h()||(clearTimeout(O),O=void 0,W=setTimeout(()=>{W=void 0,v(!1)},j()))}):R.onClick=()=>v(!w()),R.onFocus=()=>{h()||(clearTimeout(W),W=void 0,O=setTimeout(()=>{O=void 0,v(!0)},k()))},R.onBlur=()=>{h()||(clearTimeout(O),O=void 0,W=setTimeout(()=>{W=void 0,v(!1)},j()))};else if(p()==="click")R.onClick=()=>v(!w());else if(p()==="longpress"){let P,M=0,q=0,U=()=>{clearTimeout(P),P=void 0};R.onPointerDown=I=>{h()||(M=I.clientX??0,q=I.clientY??0,U(),P=setTimeout(()=>{P=void 0,r.onTrigger?.({clientX:M,clientY:q}),v(!0)},r.longPressDuration??500))},R.onPointerUp=U,R.onPointerLeave=U,R.onPointerMove=I=>{let pe=Math.abs((I.clientX??0)-M),me=Math.abs((I.clientY??0)-q);(pe>10||me>10)&&U()},R.onContextMenu=I=>{I.preventDefault(),r.onTrigger?.({clientX:I.clientX??0,clientY:I.clientY??0}),v(!0)}}R.onKeyDown=P=>{P.key==="Escape"&&r.closeOnEscape!==!1&&v(!1)},i&&F(P=>{P===i&&sn()});let an=P=>{if(P){T=P;let M=()=>x.refresh();P.addEventListener("animationend",M,{once:!0})}else T=null},ln=(P,M="popover")=>{if(h())return null;if(!w())return C=!1,null;C||(x.refresh(),C=!0);let U=P.props??{},I=U.ref,pe=["wf-popup",U.class].filter(Boolean).join(" "),me={...U.style??{},position:"fixed",top:`${x.top}px`,left:`${x.left}px`,maxWidth:r.width!==void 0?`min(${r.width}px, calc(100vw - 32px))`:"calc(100vw - 32px)"},un={...P,props:{...U,class:pe,style:me,ref:Me=>{an(Me),I&&I(Me)}}};return ge(un,M)};return{open:w(),setOpen:v,wrapProps:R,portal:ln,refresh:()=>x.refresh()}},useLongPress:function(r){let{onLongPress:i,duration:a=500}=r,p,m=0,h=0,w=null,v=()=>{clearTimeout(p),p=void 0};return{onPointerDown:b=>{m=b.clientX??0,h=b.clientY??0,w=b,v(),p=setTimeout(()=>{p=void 0,i(w)},a)},onPointerUp:v,onPointerLeave:v,onPointerMove:b=>{let T=Math.abs((b.clientX??0)-m),C=Math.abs((b.clientY??0)-h);(T>10||C>10)&&v()},onContextMenu:b=>{b.preventDefault(),i(b)}}},useInView:function(r){let i=o(this),a={isIn:!1,ready:!1,observe:v,refresh:b,disconnect:T},p=null,m=null,h=()=>{n.ui&&n.ui.dirty(i?[i]:void 0)};function w(){if(m?.disconnect(),m=null,!p)return;let C=typeof r.rootMargin=="function"?r.rootMargin():r.rootMargin,x=typeof r.threshold=="function"?r.threshold():r.threshold;m=new IntersectionObserver(A=>{let S=A[A.length-1];if(!S)return;let R=S.isIntersecting,_=R!==a.isIn,k=!a.ready;a.isIn=R,a.ready=!0,r.onChange?.(S,R),(_||k)&&h()},{root:r.root?r.root():null,rootMargin:C??"0px",threshold:x??0}),m.observe(p)}function v(C){p=C,C?w():(m?.disconnect(),m=null,a.isIn=!1)}function b(){w()}function T(){m?.disconnect(),m=null}return a},useScrollPosition:function(r){let i=o(this),a={y:0,refresh(){let m=p.getScroller();a.y=m instanceof Window?document.scrollingElement?.scrollTop??m.scrollY??0:m.scrollTop??0}},p={handle:a,getScroller:r.getScroller??(()=>window)};return i?(c.set(i,p),y(),a.refresh(),a):(a.refresh(),a)},useAsync:function(r){let i=o(this),a=le(()=>{n.ui&&n.ui.dirty(i?[i]:void 0)});a.loading=!0;let p=0,m=()=>{let h=++p;a.loading=!0,a.error=null,Promise.resolve().then(()=>r()).then(w=>{p===h&&(a.data=w,a.loading=!1)}).catch(w=>{p===h&&(a.error=w,a.loading=!1)})};return m(),a.reload=m,a},useControlled:function(r){let i=o(this),a=r.value!==void 0;a&&!r.onChange&&r.name&&(Ze.has(r.name)||(Ze.add(r.name),console.warn(`[weifuwu/${r.name}] \u53D7\u63A7\u6A21\u5F0F\uFF08value \u5DF2\u4F20\uFF09\u4F46\u672A\u63D0\u4F9B onChange\uFF0C\u4EA4\u4E92\u65E0\u6CD5\u751F\u6548\u3002
|
|
5
|
-
\u975E\u53D7\u63A7\uFF1A\u53BB\u6389 value\uFF1B\u53D7\u63A7\uFF1A\u4F20\u5165 onChange={(v) => setValue(v)}`))),!a&&i&&!ee.has(i)&&(ee.set(i,r.value),F(m=>{ee.delete(m)}));let p=m=>{if(a){r.onChange?.(m);return}i&&ee.set(i,m),n.ui&&(i?n.ui.dirty([i]):n.ui.render())};return{value:a?r.value:i?ee.get(i):r.value,setValue:p,controlled:a}},usePresence:function(r){let i=o(this),a="closed",p,m=()=>{a="closed",n.ui&&(i?n.ui.dirty([i]):n.ui.render())};return{get phase(){return a},ref:w=>{w?p||(p=()=>{a==="exit"&&m()},w.addEventListener("animationend",p)):(w?.removeEventListener("animationend",p),p=void 0)},sync:w=>(w?a="open":a==="open"&&(a="exit"),a)}},useDialog:function(r){let i=o(this),a,p=null,m=this.usePresence(r);return{get phase(){return m.phase},rootRef:v=>{v?(Ae(),p&&(a=ae(p)),m.ref(v)):(_e(),a?.(),m.ref(null))},panelRef:v=>{p=v,v&&!a&&(a=ae(v))},sync:v=>m.sync(v)}},useGlobalKey:function(r){let i=o(this);return typeof window>"u"?()=>{}:(window.addEventListener("keydown",r),i&&F(a=>{a===i&&window.removeEventListener("keydown",r)}),()=>window.removeEventListener("keydown",r))},useDrag:function(r){let i=0,a=0,p=!1,m=v=>{p&&r.onMove(v,{x:v.clientX-i,y:v.clientY-a})},h=v=>{p&&(p=!1,window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",h),r.onEnd?.(v))};return{onPointerDown:v=>{p||(v.preventDefault(),p=!0,i=v.clientX,a=v.clientY,window.addEventListener("pointermove",m),window.addEventListener("pointerup",h),r.onStart?.(v))}}},useDragDrop:function(r){let i={};return r.onDrop&&(i.onDrop=a=>{a.preventDefault(),r.onDrop(a)}),r.onDragOver&&(i.onDragOver=a=>{a.preventDefault(),r.onDragOver(a)}),r.onDragLeave&&(i.onDragLeave=a=>r.onDragLeave(a)),{dropProps:i}},useReducedMotion:function(){return typeof window<"u"&&!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches},useAnimationEnd:function(r,i){let a=null,p=()=>{r(),i?.once&&a&&a.removeEventListener("animationend",p)};return h=>{h?(a=h,h.addEventListener("animationend",p)):a&&(a.removeEventListener("animationend",p),a=null)}},useTween:function(r,i){let a=o(this),p=this.useReducedMotion(),m=i?.duration??400,h=i?.ease==="linear"?x=>x:x=>1-Math.pow(1-x,3),w,v=r,b={value:p?r:0,reset:()=>{}},T=()=>{n.ui&&(a?n.ui.dirty([a]):n.ui.render())},C=x=>{if(v=x,p){b.value=x,T();return}if(x===b.value)return;w&&cancelAnimationFrame(w);let A=b.value,S=performance.now(),R=_=>{let k=Math.min(1,(_-S)/m);b.value=Math.round(A+(x-A)*h(k)),k<1?(w=requestAnimationFrame(R),T()):(w=void 0,T())};w=requestAnimationFrame(R)};return b.reset=x=>{x===v&&w||C(x)},queueMicrotask(()=>C(r)),b},selfId:function(r){if(typeof r!="string"||!r)throw new Error(`[weifuwu] selfId requires a non-empty string, got ${typeof r}`);if(L.has(r))throw new Error(`[weifuwu] Duplicate component ID: "${r}". Each component must have a unique custom ID.`);let i=this._selfVNode;i&&(i._customId=r,L.set(r,i))}}}function Wn(){let e=[],n={},t=null,o=null,s=null,l=!1,u=new Set,f=!1,c=new Map;function d(b){let T=c.get(b);T&&(T.mql&&T.handler&&T.mql.removeEventListener("change",T.handler),T.mqls?.forEach(({mql:C,handler:x})=>C.removeEventListener("change",x)),c.delete(b))}let y=new Map,g=!1,E=0;function r(){g||(g=!0,window.addEventListener("scroll",p,{capture:!0,passive:!0}),window.addEventListener("resize",p))}function i(){g&&(window.removeEventListener("scroll",p,{capture:!0}),window.removeEventListener("resize",p),g=!1)}let a=new Map;function p(){E||(E=requestAnimationFrame(()=>{E=0;let b=[];for(let[T,C]of y){if(!C.isOpen())continue;let x=C.getEl();if(!x)continue;let A=C.compute(x.getBoundingClientRect());Object.assign(C.pos,ce(A,C.panel?.(),C.margin)),b.push(T)}for(let[T,C]of a){let x=C.getScroller(),A=x instanceof Window?document.scrollingElement?.scrollTop??x.scrollY??0:x.scrollTop??0;A!==C.handle.y&&(C.handle.y=A,b.push(T))}b.length>0&&n.ui.render(b)}))}function m(b){if(!l){l=!0;for(let T of b){let C=L.get(T);if(!C||!C._render)continue;n.ui._dirtySet?.delete(T);let x=C._child,A=C._render(C.props);if(C._child=A,x&&x._placement==="remote"||A&&A._placement==="remote"){x&&A?Q(x,A,n):A?B(A,n):x&&N(x);continue}if(!C._parentNode&&C._refNode&&(C._parentNode=C._refNode.parentNode),C._parentNode){let S=$(C._parentNode,C._refNode??null,x,A,n);S&&S!==C._refNode?C._refNode=S:S||(C._refNode=null)}}l=!1,h()}}function h(){let b=n.ui;u.size>0&&!b._dirtyScheduled&&(b._dirtyScheduled=!0,queueMicrotask(()=>{b._dirtyScheduled=!1;let T=[...u];u.clear(),T.length>0&&m(T)}))}function w(b){return b?._selfId??n.ui?._selfId}let v={get ctx(){return n},use(b){return e.push(b),v},async mount(b,T,C){o=T;for(let _ of e)n=await _(n);let x=typeof b=="string"?document.querySelector(b):b;if(!x)throw new Error(`mount target not found: ${b}`);t=x;let A=!!C?.hydrate;A||(t.innerHTML="");let S=new Map,R=globalThis.__DATA__;if(R&&typeof R=="object")for(let[_,k]of Object.entries(R))S.set(_,{value:k});if(n.data={async get(_,k){let j=S.get(_);if(j&&"value"in j)return j.value;if(j?.promise)return j.promise;if(!k)return;let O=Promise.resolve().then(()=>k()).then(W=>(S.set(_,{value:W}),W));return S.set(_,{promise:O}),O},set(_,k){S.set(_,{value:k})},has(_){return S.has(_)}},F(_=>{for(let k of[...c.keys()])(k.startsWith(`media:${_}:`)||k===`bp:${_}`)&&d(k);y.delete(_),a.delete(_)}),n.ui=en({ctx:n,renderByIds:m,getSelfId:w,dirtyBatch:u,dirtySet:new Set,mediaRegistry:c,popupTrackers:y,scrollTrackers:a,schedulePopupRecompute:p,ensurePopupListeners:r,destroyPopupListeners:i,isRendering:()=>l}),l=!0,s=Vn(T,n),s._id="_wf_root",s._parentNode=t,s._refNode=A?t.firstChild:null,L.set("_wf_root",s),A)await Pe(t,s,n);else{let _=Ke(s,n);_ instanceof Node&&t.appendChild(_)}s._refNode=t.firstChild,l=!1,h()},destroy(){i(),y.clear(),a.clear();for(let b of[...c.keys()])d(b);L.clear(),t&&(t.innerHTML=""),t=null,n={}}};return v}function Vn(e,n){return{type:e,props:{},key:void 0}}function In(e,n){if(!n||n==="/")return e||"/";let t=e.endsWith("/")?e.slice(0,-1):e,o=n.startsWith("/")?n:"/"+n;return t+o}function Hn(e){let n=[],t=e.replace(/:(\w+)/g,(o,s)=>(n.push(s),"([^/]+)")).replace(/\*/g,".*");return{re:new RegExp(`^${t}$`),keys:n}}function ke(e,n="",t=[]){let o=[];for(let s of e){let l=In(n,s.path),{re:u,keys:f}=Hn(l),c=[...t,s];o.push({re:u,keys:f,def:s,chain:c}),s.children&&o.push(...ke(s.children,l,c))}return o}function nn(e,n){let t=null;for(let o of n)e.match(o.re)&&(!t||o.chain.length>t.chain.length)&&(t=o);return t}function tn(e,n){let t={},o=e.match(n.re);if(o)for(let s=0;s<n.keys.length;s++)t[n.keys[s]]=decodeURIComponent(o[s+1]);return t}function Un(e){let n=ke(e.routes),t=e.mode||"history";function o(){return t==="hash"?window.location.hash.replace(/^#/,"")||"/":window.location.pathname}function s(l){let u=nn(l,n);if(u){let f=u.chain[u.chain.length-1];return{path:u.def.path,params:tn(l,u),query:Object.fromEntries(new URLSearchParams(window.location.search)),chain:u.chain,title:f?.title??""}}return{path:l,params:{},query:Object.fromEntries(new URLSearchParams(window.location.search)),chain:e.notFound?[{component:e.notFound,title:"Not Found"}]:[],title:""}}return l=>{let u=s(o());l.route=u,u.title&&(document.title=u.title),l.app||(l.app={}),l.app.navigate=c=>{if(Y(),t==="hash"){window.location.hash="#"+c;let d=s(c);l.route=d}else{window.history.pushState({},"",c);let d=s(c);l.route=d}l.route?.title&&(document.title=l.route.title),l.ui?.bumpCtxVersion?.(),l.ui?.render()};let f=()=>{Y();let c=s(o());l.route=c,l.route?.title&&(document.title=l.route.title),l.ui?.bumpCtxVersion?.(),l.ui?.render()};return window.addEventListener("popstate",f),t==="hash"&&window.addEventListener("hashchange",f),l}}function Dn(e,n){let t=n.route?._rvDepth??0;return()=>{let o=n.route;if(!o?.chain?.length||t>=o.chain.length)return null;let s=o.chain[t],l=s.layout??s.component;return l?(s.layout&&(o._rvDepth=t+1),{type:l,props:{},key:void 0}):null}}function K(e,n){return Object.assign(Object.create(e),n)}function jn(e={}){let n=e.url??"/ws",t=e.reconnectInterval??3e3,o=e.maxReconnect??10,s=e.pingInterval??3e4,l=e.pingTimeout??1e4;return u=>{let f=new Set,c=null,d=0,y=null,g=null,E=null,r=!1,i={isConnected:!1,onMessage:w=>(f.add(w),()=>{f.delete(w)}),send:w=>{c?.readyState===WebSocket.OPEN&&c.send(JSON.stringify(w))},_connect:a,close:()=>{r=!0,h(),c?.close(),c=null,i.isConnected=!1}};async function a(){if(!r)try{c=new WebSocket(n),c.onopen=()=>{i.isConnected=!0,d=0,p()},c.onmessage=w=>{try{let v=JSON.parse(w.data);for(let b of f)b(v)}catch{}m()},c.onclose=()=>{i.isConnected=!1,h(),!r&&d<o&&(d++,y=setTimeout(a,t*Math.min(d,5)))},c.onerror=()=>{c?.close()}}catch{r||(y=setTimeout(a,t))}}function p(){s<=0||(g=setInterval(()=>{c?.readyState===WebSocket.OPEN&&c.send(JSON.stringify({type:"ping"})),E=setTimeout(()=>{c?.close()},l)},s))}function m(){clearTimeout(E)}function h(){clearInterval(g),clearTimeout(E),clearTimeout(y)}return a(),K(u,{ws:i})}}function Fn(e){let n={baseURL:e?.baseURL??"",headers:{"Content-Type":"application/json",...e?.headers}},t=e?.onRequest,o=e?.onResponse,s=e?.timeout??0;async function l(u,f,c,d){let y=n.baseURL+f,g={method:u,headers:{...n.headers,...d?.headers}},E=e?.token?.();E&&!g.headers.Authorization&&(g.headers.Authorization=`Bearer ${E}`);let r=s>0,i=!!d?.signal,a=null,p=null;(r||i)&&(a=new AbortController,g.signal=a.signal,r&&(p=setTimeout(()=>a.abort(new Error("Request timed out")),s)),i&&d.signal.addEventListener("abort",()=>a.abort())),c!==void 0&&u!=="GET"&&u!=="HEAD"&&(g.body=JSON.stringify(c));let m={url:y,init:g};t&&(m=t(m));try{let h=await fetch(m.url,m.init);if(o)return o(h);if(!h.ok){let b=await h.text().catch(()=>"");throw new fe(h.status,b||h.statusText)}let w=h.headers.get("content-length");if(h.status===204||w==="0")return;let v=(h.headers.get("content-type")||"").toLowerCase();return v.includes("application/json")||v.includes("json")?h.json():h.text()}finally{p&&clearTimeout(p)}}return u=>K(u,{api:{get:(c,d)=>l("GET",c,void 0,d),post:(c,d,y)=>l("POST",c,d,y),put:(c,d,y)=>l("PUT",c,d,y),patch:(c,d,y)=>l("PATCH",c,d,y),delete:(c,d)=>l("DELETE",c,void 0,d)}})}var fe=class extends Error{status;body;constructor(n,t){super(`API Error ${n}: ${t}`),this.name="ApiError",this.status=n,this.body=t}};function qn(e){try{let n=e.split(".");if(n.length!==3)return null;let t=n[1].replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(atob(t))}catch{return null}}function $n(e){let n=qn(e);return n?.exp?n.exp*1e3-3e4<Date.now():!0}function Kn(e){let n=e?.storage??localStorage,t=e?.tokenKey??"weifuwu_token",o=e?.userKey??"weifuwu_user",s=e?.refreshTokenKey??"weifuwu_refresh",l=e?.refreshEndpoint??"/api/auth/refresh";return u=>{let f=n.getItem(t),c=n.getItem(o),d={token:f,user:c?JSON.parse(c):null,get isLoggedIn(){return this.token!==null},login(y,g,E){d.token=y,d.user=g,n.setItem(t,y),n.setItem(o,JSON.stringify(g)),E&&n.setItem(s,E)},logout(){d.token=null,d.user=null,n.removeItem(t),n.removeItem(o),n.removeItem(s)},setUser(y){d.user=y,n.setItem(o,JSON.stringify(y))},async refresh(){let y=n.getItem(s);if(!y)return!1;try{let g=await fetch(l,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:y})});if(!g.ok)return d.logout(),!1;let E=await g.json();return d.token=E.token,n.setItem(t,E.token),E.refreshToken&&n.setItem(s,E.refreshToken),!0}catch{return!1}}};return f&&$n(f)&&d.refresh().catch(()=>{}),K(u,{auth:d})}}function Bn(e,n){let t=null;return o=>{if(t){let l=o.fallback;return typeof l=="function"?l({error:t}):l??null}n.ui._errorHandler=l=>{t=l,n.ui.render()};let s=o.children;try{return s??null}catch(l){t=l;let u=o.fallback;return typeof u=="function"?u({error:l}):u??null}}}var Ne={components:{Button:{loading:"\u52A0\u8F7D\u4E2D..."},FileUpload:{placeholder:"\u70B9\u51FB\u6216\u62D6\u62FD\u4E0A\u4F20\u6587\u4EF6",supportedFormats:"\u652F\u6301\u683C\u5F0F: ",maxSize:"\u6700\u5927 ",remove:"\u5220\u9664"},Pagination:{ariaLabel:"\u5206\u9875"},ProgressBar:{ariaLabel:"\u8FDB\u5EA6"},Switch:{ariaLabel:"\u5207\u6362"},Breadcrumb:{ariaLabel:"\u9762\u5305\u5C51"},Modal:{ariaLabel:"\u5F39\u7A97",closeAria:"\u5173\u95ED"},Confirm:{confirmText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88"},Drawer:{ariaLabel:"\u4FA7\u8FB9\u9762\u677F",closeAria:"\u5173\u95ED"},DatePicker:{w0:"\u65E5",w1:"\u4E00",w2:"\u4E8C",w3:"\u4E09",w4:"\u56DB",w5:"\u4E94",w6:"\u516D",hour:"\u65F6",minute:"\u5206",time:"\u65F6\u95F4",confirm:"\u786E\u5B9A",cancel:"\u53D6\u6D88",placeholder:"\u9009\u62E9\u65E5\u671F"}}};var Le={components:{Button:{loading:"Loading..."},FileUpload:{placeholder:"Click or drag to upload",supportedFormats:"Supported formats: ",maxSize:"Max size: ",remove:"Remove"},Pagination:{ariaLabel:"Pagination"},ProgressBar:{ariaLabel:"Progress"},Switch:{ariaLabel:"Toggle"},Breadcrumb:{ariaLabel:"Breadcrumb"},Modal:{ariaLabel:"Dialog",closeAria:"Close"},Confirm:{confirmText:"OK",cancelText:"Cancel"},Drawer:{ariaLabel:"Panel",closeAria:"Close"},DatePicker:{w0:"Su",w1:"Mo",w2:"Tu",w3:"We",w4:"Th",w5:"Fr",w6:"Sa",hour:"Hour",minute:"Min",time:"Time",confirm:"OK",cancel:"Cancel",placeholder:"Pick a date"}}};var de={"zh-CN":Ne,"en-US":Le};function on(e){if(de[e])return e;let n=e.split("-")[0];return Object.keys(de).find(o=>o.startsWith(n))??"zh-CN"}function zn(e={}){let{locale:n="zh-CN",messages:t={},components:o={}}=e,s=on(n),l=de[s],u=rn(l,t,o),f={locale:s,t:(c,d)=>u.messages?.[c]??d??c,setLocale:()=>{},components:u.components};return c=>(c.i18n=f,f.setLocale=d=>{let y=on(d),g=de[y];g&&(u=rn(g,t,o),f.locale=y,f.components=u.components,c?.ui?.bumpCtxVersion?.(),c?.ui?.render())},c)}function rn(e,n,t){return{messages:{...e?.messages,...n},components:Yn(e?.components??{},t)}}function Yn(e,n){let t={...e};for(let o of Object.keys(n))typeof n[o]=="object"&&n[o]!==null&&typeof t[o]=="object"?t[o]={...t[o],...n[o]}:t[o]=n[o];return t}function Gn(e,n,t=400){let o=!1,s=()=>{o||(o=!0,e.removeEventListener("animationend",s),clearTimeout(l),n())};e.addEventListener("animationend",s);let l=setTimeout(s,t)}export{fe as ApiError,Bn as ErrorBoundary,D as Fragment,H as Portal,Dn as RouteView,Re as aiStream,Gn as animateOut,Fn as api,cn as asyncComponent,Kn as auth,N as callRefCleanup,Y as clearAsyncComponentCache,On as computeFixedPos,ue as computeFixedPosRect,Wn as createApp,ge as createPortal,le as createReactiveState,Le as enUS,K as extendCtx,pn as h,Pe as hydrateVNode,zn as i18n,z as isAsyncComponent,ye as jsx,dn as jsxDEV,fn as jsxs,Ae as lockScroll,En as mountVNode,$ as patchValue,Un as router,Je as toChatMessages,ae as trapFocus,_e as unlockScroll,jn as ws,Ne as zhCN};
|
|
3
|
+
`);o=a.pop()??"";for(let u of a){let l="message",c="";for(let p of u.split(`
|
|
4
|
+
`))p.startsWith("event: ")?l=p.slice(7):p.startsWith("data: ")&&(c+=p.slice(6));if(c)try{yield{name:l,data:JSON.parse(c)}}catch{}}}}finally{n.releaseLock()}}function Wn(e,n,t){t&&(e.length>=1e3&&e.shift(),e.push(n))}function Vn(e){return e===401||e===403?"auth_failed":e===429?"rate_limited":e>=500?"provider_error":"invalid_request"}function Hn(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`trace-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function nn(e){return e.map(n=>({role:n.role,content:n.content}))}function Le(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`msg-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function tn(e,n,t){t.initialMessages?e.messages=structuredClone(t.initialMessages):e.messages===void 0&&(e.messages=[]),e.input===void 0&&(e.input=""),e.streaming===void 0&&(e.streaming=!1),e.error===void 0&&(e.error=null),e.usage===void 0&&(e.usage=null),e.step===void 0&&(e.step=null);let o=null;function i(){if(!e.streaming)return;let C=e.messages[e.messages.length-1];return C&&C.role==="assistant"&&C.status==="streaming"?C:void 0}function s(C,y,v){let r=i();switch(C){case"wf:token":r&&(r.content+=y.text);break;case"wf:tool_call":{r&&(r.toolCalls||(r.toolCalls=[]),r.toolCalls.push({call:y,status:"running"}));break}case"wf:tool_progress":{let f=y,d=r?.toolCalls?.find(m=>m.call.id===f.toolCallId);d&&(d.progress=f);break}case"wf:tool_result":{let f=y,d=r?.toolCalls?.find(m=>m.call.id===f.id);d&&(d.result=f,d.status=f.ok?"ok":"error");break}case"wf:approval_request":r&&(r.approval=y);break;case"wf:usage":r&&(r.usage=y);break;case"wf:step":e.step=y;break;case"wf:done":r&&(r.status="done",r.approval=void 0),e.streaming=!1,e.step=null;break;case"wf:error":r&&(r.status="error",r.error=y,r.approval=void 0),e.error=y,e.streaming=!1,e.step=null;break;default:v?.(C,y);break}}function a(){let C=t.body?t.body(e.messages):{messages:nn(e.messages)};o=n(t.url,C,{onToken:v=>s("wf:token",{text:v}),onToolCall:v=>s("wf:tool_call",v),onToolProgress:v=>s("wf:tool_progress",v),onToolResult:v=>s("wf:tool_result",v),onApproval:v=>s("wf:approval_request",v),onUsage:v=>s("wf:usage",v),onStep:v=>s("wf:step",v),onDone:v=>s("wf:done",v),onError:v=>s("wf:error",v),onEvent:(v,r)=>s(v,r,t.onEvent)},{signal:t.signal,headers:t.headers}),e.streaming=!0;let y=i();y&&o?.traceId&&(y.id=o.traceId)}function u(){if(e.streaming)return;let C=String(e.input??"").trim();C&&(e.input="",e.error=null,e.usage=null,e.step=null,e.messages.push({id:Le(),role:"user",content:C,status:"done"},{id:Le(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),a())}function l(){o?.abort(),e.streaming=!1,e.step=null;let C=e.messages[e.messages.length-1];C&&C.role==="assistant"&&C.status==="streaming"&&(!C.content&&(!C.toolCalls||C.toolCalls.length===0)?e.messages.pop():C.status="done")}function c(){if(e.streaming)return;let C=-1;for(let y=e.messages.length-1;y>=0;y--)if(e.messages[y].role==="user"){C=y;break}C!==-1&&(e.messages.splice(C+1),e.error=null,e.usage=null,e.step=null,e.messages.push({id:Le(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),a())}function p(){o?.abort(),e.messages=[],e.input="",e.streaming=!1,e.error=null,e.usage=null,e.step=null}async function g(C,y){let v=e.messages[e.messages.length-1],r=v?.role==="assistant"?v.approval:void 0;if(r&&(v.approval=void 0,!!t.approveUrl))try{await fetch(t.approveUrl,{method:"POST",headers:{"Content-Type":"application/json",...t.headers},body:JSON.stringify({id:r.id,decision:C,note:y}),signal:t.signal})}catch(f){if(t.signal?.aborted)return;e.error={code:"provider_error",message:f instanceof Error?f.message:String(f)}}}function P(){o?.abort(),o=null}return{send:u,stop:l,retry:c,clear:p,approve:g,dispose:P}}function pe(e,n="bottom",t=6,o=!0){switch(n){case"bottom":return{top:e.bottom+t,left:o?e.left+e.width/2:e.left};case"top":return{top:e.top-t,left:o?e.left+e.width/2:e.left};case"left":return{top:o?e.top+e.height/2:e.top,left:e.left-t};case"right":return{top:o?e.top+e.height/2:e.top,left:e.right+t}}}function In(e,n="bottom",t=6,o=!0){return pe(e.getBoundingClientRect(),n,t,o)}function me(e,n,t=8){if(!n)return e;let o=n.getBoundingClientRect();if(o.width===0&&o.height===0)return e;let i=Number.parseFloat(n.style.top)||o.top,s=Number.parseFloat(n.style.left)||o.left,a=e.top-i,u=e.left-s,l={top:o.top+a,bottom:o.bottom+a,left:o.left+u,right:o.right+u},c=window.innerWidth,p=window.innerHeight,g=e.top,P=e.left;return l.bottom>p-t&&(g=Math.max(t,g-(l.bottom-(p-t)))),l.top<t&&(g=Math.max(t,g+(t-l.top))),l.right>c-t&&(P=Math.max(t,P-(l.right-(c-t)))),l.left<t&&(P=Math.max(t,P+(t-l.left))),{top:g,left:P,width:e.width}}var on=new Set,oe=new Map;function rn(e){let{ctx:n,renderByIds:t,getSelfId:o,dirtyBatch:i,dirtySet:s,mediaRegistry:a,popupTrackers:u,scrollTrackers:l,schedulePopupRecompute:c,ensurePopupListeners:p,isRendering:g,isMounting:P,setMounting:C,endMounting:y}=e;return{_selfId:"_wf_root",_ctxVersion:0,_dirtySet:s,setMounting:C,endMounting:y,bumpCtxVersion:function(){this._ctxVersion++},render:function(r){if(g()){if(P())return;this._pendingRender||(this._pendingRender=!0,queueMicrotask(()=>{this._pendingRender=!1,this.render(r)}));return}if(!r||r.length===0){let f=o(this);if(f)r=[f];else return}t(r)},dirty:function(r){if(!P()){if(g()){this._pendingDirty||(this._pendingDirty=!0,queueMicrotask(()=>{this._pendingDirty=!1,this.dirty(r)}));return}if(!r||r.length===0){let f=o(this);if(f)r=[f];else return}for(let f of r)f&&(i.add(f),s.add(f));this._dirtyScheduled||(this._dirtyScheduled=!0,queueMicrotask(()=>{this._dirtyScheduled=!1;let f=[...i];i.clear(),f.length>0&&t(f)}))}},$:function(){let r=this;return r._$cache||(r._$cache=fe(()=>{let f=r._selfVNode?._id??o(r);f&&n.ui.dirty([f])})),r._$cache},useChat:function(r){let f=this.$(),d=tn(f,Me,r);return Object.assign(f,{send:d.send,stop:d.stop,retry:d.retry,clear:d.clear,approve:d.approve,dispose:d.dispose}),f},useMedia:function(r,f){let m=`media:${o(this)}:${r}`;if(!a.has(m)){let h=window.matchMedia(r);f(h.matches);let b=E=>f(E.matches);h.addEventListener("change",b),a.set(m,{mql:h,handler:b})}},useBreakpoint:function(r,f){let d=typeof r=="function"?{mobile:"(max-width: 639px)",tablet:"(min-width: 640px) and (max-width: 1023px)",desktop:"(min-width: 1024px)"}:r,m=typeof r=="function"?r:f,b=`bp:${o(this)}`;function E(){for(let[x,k]of Object.entries(d))if(window.matchMedia(k).matches)return x;return Object.keys(d)[0]??""}if(!a.has(b)){m(E());let x=[];for(let k of Object.values(d)){let T=window.matchMedia(k),_=()=>m(E());T.addEventListener("change",_),x.push({mql:T,handler:_})}a.set(b,{mqls:x})}},usePopupPosition:function(r){let f=o(this),d={top:0,left:0,refresh:()=>{}};if(!f)return d;let m={pos:d,getEl:r.el,isOpen:r.isOpen,compute:r.compute,panel:r.panel,margin:r.margin??8};return u.set(f,m),p(),d.refresh=()=>{let h=m.getEl();if(!h)return;let b=m.compute(h.getBoundingClientRect());Object.assign(d,me(b,m.panel?.(),m.margin))},d},useHoverCapable:function(){return typeof window<"u"&&!!window.matchMedia?.("(hover: hover)").matches},useStableRef:function(r,f){return m=>{m?r(m):f?.()}},useVisualViewport:function(){let r=o(this),f={height:window.innerHeight,offsetTop:0,keyboardOpen:!1},d=()=>{n.ui&&n.ui.dirty(r?[r]:void 0)},m=()=>{let b=window.visualViewport;f.height=b?.height??window.innerHeight,f.offsetTop=b?.offsetTop??0,f.keyboardOpen=f.height<window.innerHeight*.9,d()},h=window.visualViewport;return h?.addEventListener?(h.addEventListener("resize",m),h.addEventListener("scroll",m)):window.addEventListener("resize",m),r&&K(b=>{b===r&&(h?.removeEventListener?(h.removeEventListener("resize",m),h.removeEventListener("scroll",m)):window.removeEventListener("resize",m))}),f},usePopup:function(r){let f=o(this),d=this.useHoverCapable(),m=()=>typeof r.trigger=="function"?r.trigger():r.trigger,h=r.open!==void 0,b=()=>!!r.disabled?.(),E=()=>h?typeof r.open=="function"?!!r.open():!!r.open:r.isOpen(),x=A=>{b()||(h?r.onOpenChange?.(A):r.setOpen(A))},k=()=>{let A=r.placement;return typeof A=="function"?A():A??"bottom"},T=null,_=!1,w=n.ui.usePopupPosition({el:r.el,isOpen:()=>E(),compute:A=>{if(r.position){let V=r.position();return{top:V.y,left:V.x}}return pe(A,k(),r.gap??6,r.center!==!1)},panel:()=>T,margin:r.margin??8}),R=A=>{if(r.closeOnOutside===!1||!E())return;let V=A.target;if(!(V instanceof Node))return;let $=r.el();$&&$.contains(V)||T&&T.contains(V)||x(!1)},M=A=>{r.closeOnEscape!==!1&&(A.key!=="Escape"||!E()||x(!1))};document.addEventListener("mousedown",R),document.addEventListener("keydown",M),f&&K(A=>{A===f&&(document.removeEventListener("mousedown",R),document.removeEventListener("keydown",M))});let S={},j=A=>typeof A=="function"?A():A??0,N=()=>j(r.openDelay),H=()=>j(r.closeDelay),L,I,re=()=>{clearTimeout(L),clearTimeout(I),L=void 0,I=void 0};if(m()==="hover")d?(S.onMouseEnter=()=>{b()||(clearTimeout(I),I=void 0,L=setTimeout(()=>{L=void 0,x(!0)},N()))},S.onMouseLeave=()=>{b()||(clearTimeout(L),L=void 0,I=setTimeout(()=>{I=void 0,x(!1)},H()))}):S.onClick=()=>x(!E()),S.onFocus=()=>{b()||(clearTimeout(I),I=void 0,L=setTimeout(()=>{L=void 0,x(!0)},N()))},S.onBlur=()=>{b()||(clearTimeout(L),L=void 0,I=setTimeout(()=>{I=void 0,x(!1)},H()))};else if(m()==="click")S.onClick=()=>x(!E());else if(m()==="longpress"){let A,V=0,$=0,F=()=>{clearTimeout(A),A=void 0};S.onPointerDown=D=>{b()||(V=D.clientX??0,$=D.clientY??0,F(),A=setTimeout(()=>{A=void 0,r.onTrigger?.({clientX:V,clientY:$}),x(!0)},r.longPressDuration??500))},S.onPointerUp=F,S.onPointerLeave=F,S.onPointerMove=D=>{let he=Math.abs((D.clientX??0)-V),ve=Math.abs((D.clientY??0)-$);(he>10||ve>10)&&F()},S.onContextMenu=D=>{D.preventDefault(),r.onTrigger?.({clientX:D.clientX??0,clientY:D.clientY??0}),x(!0)}}S.onKeyDown=A=>{A.key==="Escape"&&r.closeOnEscape!==!1&&x(!1)},f&&K(A=>{A===f&&re()});let dn=A=>{if(A){T=A;let V=()=>w.refresh();A.addEventListener("animationend",V,{once:!0})}else T=null},fn=(A,V="popover")=>{if(b())return null;if(!E())return _=!1,null;_||(w.refresh(),_=!0);let F=A.props??{},D=F.ref,he=["wf-popup",F.class].filter(Boolean).join(" "),ve={...F.style??{},position:"fixed",top:`${w.top}px`,left:`${w.left}px`,maxWidth:r.width!==void 0?`min(${r.width}px, calc(100vw - 32px))`:"calc(100vw - 32px)"},pn={...A,props:{...F,class:he,style:ve,ref:He=>{dn(He),D&&D(He)}}};return be(pn,V)};return{open:E(),setOpen:x,wrapProps:S,portal:fn,refresh:()=>w.refresh()}},useLongPress:function(r){let{onLongPress:f,duration:d=500}=r,m,h=0,b=0,E=null,x=()=>{clearTimeout(m),m=void 0};return{onPointerDown:k=>{h=k.clientX??0,b=k.clientY??0,E=k,x(),m=setTimeout(()=>{m=void 0,f(E)},d)},onPointerUp:x,onPointerLeave:x,onPointerMove:k=>{let T=Math.abs((k.clientX??0)-h),_=Math.abs((k.clientY??0)-b);(T>10||_>10)&&x()},onContextMenu:k=>{k.preventDefault(),f(k)}}},useInView:function(r){let f=o(this),d={isIn:!1,ready:!1,observe:x,refresh:k,disconnect:T},m=null,h=null,b=()=>{n.ui&&n.ui.dirty(f?[f]:void 0)};function E(){if(h?.disconnect(),h=null,!m)return;let _=typeof r.rootMargin=="function"?r.rootMargin():r.rootMargin,w=typeof r.threshold=="function"?r.threshold():r.threshold;h=new IntersectionObserver(R=>{let M=R[R.length-1];if(!M)return;let S=M.isIntersecting,j=S!==d.isIn,N=!d.ready;d.isIn=S,d.ready=!0,r.onChange?.(M,S),(j||N)&&b()},{root:r.root?r.root():null,rootMargin:_??"0px",threshold:w??0}),h.observe(m)}function x(_){m=_,_?E():(h?.disconnect(),h=null,d.isIn=!1)}function k(){E()}function T(){h?.disconnect(),h=null}return d},useScrollPosition:function(r){let f=o(this),d={y:0,refresh(){let h=m.getScroller();d.y=h instanceof Window?document.scrollingElement?.scrollTop??h.scrollY??0:h.scrollTop??0}},m={handle:d,getScroller:r.getScroller??(()=>window)};return f?(l.set(f,m),p(),d.refresh(),d):(d.refresh(),d)},useAsync:function(r){let f=o(this),d=fe(()=>{n.ui&&n.ui.dirty(f?[f]:void 0)});d.loading=!0;let m=0,h=()=>{let b=++m;d.loading=!0,d.error=null,Promise.resolve().then(()=>r()).then(E=>{m===b&&(d.data=E,d.loading=!1)}).catch(E=>{m===b&&(d.error=E,d.loading=!1)})};return h(),d.reload=h,d},useControlled:function(r){let f=o(this),d=r.value!==void 0;d&&!r.onChange&&r.name&&(on.has(r.name)||(on.add(r.name),console.warn(`[weifuwu/${r.name}] \u53D7\u63A7\u6A21\u5F0F\uFF08value \u5DF2\u4F20\uFF09\u4F46\u672A\u63D0\u4F9B onChange\uFF0C\u4EA4\u4E92\u65E0\u6CD5\u751F\u6548\u3002
|
|
5
|
+
\u975E\u53D7\u63A7\uFF1A\u53BB\u6389 value\uFF1B\u53D7\u63A7\uFF1A\u4F20\u5165 onChange={(v) => setValue(v)}`))),!d&&f&&!oe.has(f)&&(oe.set(f,r.value),K(h=>{oe.delete(h)}));let m=h=>{if(d){r.onChange?.(h);return}f&&oe.set(f,h),n.ui&&(f?n.ui.dirty([f]):n.ui.render())};return{value:d?r.value:f?oe.get(f):r.value,setValue:m,controlled:d}},usePresence:function(r){let f=o(this),d="closed",m,h=()=>{d="closed",n.ui&&(f?n.ui.dirty([f]):n.ui.render())};return{get phase(){return d},ref:E=>{E?m||(m=()=>{d==="exit"&&h()},E.addEventListener("animationend",m)):(E?.removeEventListener("animationend",m),m=void 0)},sync:E=>(E?d="open":d==="open"&&(d="exit"),d)}},useDialog:function(r){let f=o(this),d,m=null,h=this.usePresence(r);return{get phase(){return h.phase},rootRef:x=>{x?(ke(),m&&(d=de(m)),h.ref(x)):(Ne(),d?.(),h.ref(null))},panelRef:x=>{m=x,x&&!d&&(d=de(x))},sync:x=>h.sync(x)}},useGlobalKey:function(r){let f=o(this);return typeof window>"u"?()=>{}:(window.addEventListener("keydown",r),f&&K(d=>{d===f&&window.removeEventListener("keydown",r)}),()=>window.removeEventListener("keydown",r))},useDrag:function(r){let f=0,d=0,m=!1,h=x=>{m&&r.onMove(x,{x:x.clientX-f,y:x.clientY-d})},b=x=>{m&&(m=!1,window.removeEventListener("pointermove",h),window.removeEventListener("pointerup",b),r.onEnd?.(x))};return{onPointerDown:x=>{m||(x.preventDefault(),m=!0,f=x.clientX,d=x.clientY,window.addEventListener("pointermove",h),window.addEventListener("pointerup",b),r.onStart?.(x))}}},useDragDrop:function(r){let f={};return r.onDrop&&(f.onDrop=d=>{d.preventDefault(),r.onDrop(d)}),r.onDragOver&&(f.onDragOver=d=>{d.preventDefault(),r.onDragOver(d)}),r.onDragLeave&&(f.onDragLeave=d=>r.onDragLeave(d)),{dropProps:f}},useReducedMotion:function(){return typeof window<"u"&&!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches},useAnimationEnd:function(r,f){let d=null,m=()=>{r(),f?.once&&d&&d.removeEventListener("animationend",m)};return b=>{b?(d=b,b.addEventListener("animationend",m)):d&&(d.removeEventListener("animationend",m),d=null)}},useTween:function(r,f){let d=o(this),m=this.useReducedMotion(),h=f?.duration??400,b=f?.ease==="linear"?w=>w:w=>1-Math.pow(1-w,3),E,x=r,k={value:m?r:0,reset:()=>{}},T=()=>{n.ui&&(d?n.ui.dirty([d]):n.ui.render())},_=w=>{if(x=w,m){k.value=w,T();return}if(w===k.value)return;E&&cancelAnimationFrame(E);let R=k.value,M=performance.now(),S=j=>{let N=Math.min(1,(j-M)/h);k.value=Math.round(R+(w-R)*b(N)),N<1?(E=requestAnimationFrame(S),T()):(E=void 0,T())};E=requestAnimationFrame(S)};return k.reset=w=>{w===x&&E||_(w)},queueMicrotask(()=>_(r)),k},selfId:function(r){if(typeof r!="string"||!r)throw new Error(`[weifuwu] selfId requires a non-empty string, got ${typeof r}`);if(W.has(r))throw new Error(`[weifuwu] Duplicate component ID: "${r}". Each component must have a unique custom ID.`);let f=this._selfVNode;f&&(f._customId=r,W.set(r,f))}}}function sn(){return{activeElement:()=>typeof document<"u"?document.activeElement:null,byId:e=>typeof document<"u"?document.getElementById(e):null,query:e=>typeof document<"u"?document.querySelector(e):null,createElement:e=>typeof document<"u"?document.createElement(e):null,bodyAppend:e=>{typeof document<"u"&&document.body.appendChild(e)},bodyRemove:e=>{typeof document<"u"&&e.parentNode&&document.body.removeChild(e)},copyText:async e=>{let n=typeof window<"u"?window:null;if(n?.navigator?.clipboard?.writeText)try{return await n.navigator.clipboard.writeText(e),!0}catch{}try{if(typeof document>"u")return!1;let t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();let o=document.execCommand("copy");return document.body.removeChild(t),o}catch{return!1}},execCommand:(e,n)=>typeof document<"u"?document.execCommand(e,!1,n):!1,selectionText:()=>typeof window<"u"?window.getSelection?.()?.toString()??null:null,getSelection:()=>typeof window<"u"?window.getSelection():null,viewportHeight:()=>typeof window<"u"?window.innerHeight:0,scrollTop:()=>{let e=typeof document<"u"?document:null,n=typeof window<"u"?window:null;return e?.scrollingElement?.scrollTop??n?.scrollY??0},hash:()=>typeof window<"u"?window.location?.hash??"":"",setHash:e=>{typeof window<"u"&&(window.location.hash=e)},timeout:(e,n)=>typeof window<"u"?window.setTimeout(e,n):0,rootElement:()=>typeof document<"u"?document.documentElement:null,storageGet:e=>{try{return typeof window<"u"?window.localStorage?.getItem(e)??null:null}catch{return null}},storageSet:(e,n)=>{try{typeof window<"u"&&window.localStorage?.setItem(e,n)}catch{}}}}function Un(){let e=[],n={},t=null,o=null,i=null,s=!1,a=!1,u=[];function l(T){u.push(a),a=T}function c(){a=u.pop()??!1}let p=new Set,g=!1,P=new Map;function C(T){let _=P.get(T);_&&(_.mql&&_.handler&&_.mql.removeEventListener("change",_.handler),_.mqls?.forEach(({mql:w,handler:R})=>w.removeEventListener("change",R)),P.delete(T))}let y=new Map,v=!1,r=0;function f(){v||(v=!0,window.addEventListener("scroll",h,{capture:!0,passive:!0}),window.addEventListener("resize",h))}function d(){v&&(window.removeEventListener("scroll",h,{capture:!0}),window.removeEventListener("resize",h),v=!1)}let m=new Map;function h(){r||(r=requestAnimationFrame(()=>{r=0;let T=[];for(let[_,w]of y){if(!w.isOpen())continue;let R=w.getEl();if(!R)continue;let M=w.compute(R.getBoundingClientRect());Object.assign(w.pos,me(M,w.panel?.(),w.margin)),T.push(_)}for(let[_,w]of m){let R=w.getScroller(),M=R instanceof Window?document.scrollingElement?.scrollTop??R.scrollY??0:R.scrollTop??0;M!==w.handle.y&&(w.handle.y=M,T.push(_))}T.length>0&&n.ui.render(T)}))}function b(T){if(!s){s=!0;for(let _ of T){let w=W.get(_);if(!w||!w._render)continue;n.ui._dirtySet?.delete(_);let R=w._child,M=w._render(w.props);if(w._child=M,R&&R._placement==="remote"||M&&M._placement==="remote"){R&&M?ne(R,M,n):M?G(M,n):R&&O(R);continue}if(!w._parentNode&&w._refNode&&(w._parentNode=w._refNode.parentNode),w._parentNode){let S=z(w._parentNode,w._refNode??null,R,M,n);S&&S!==w._refNode?w._refNode=S:S||(w._refNode=null)}}s=!1,E()}}function E(){let T=n.ui;p.size>0&&!T._dirtyScheduled&&(T._dirtyScheduled=!0,queueMicrotask(()=>{T._dirtyScheduled=!1;let _=[...p];p.clear(),_.length>0&&b(_)}))}function x(T){return T?._selfId??n.ui?._selfId}let k={get ctx(){return n},use(T){return e.push(T),k},async mount(T,_,w){o=_;for(let N of e)n=await N(n);let R=typeof T=="string"?document.querySelector(T):T;if(!R)throw new Error(`mount target not found: ${T}`);t=R;let M=!!w?.hydrate;M||(t.innerHTML="");let S=new Map,j=globalThis.__DATA__;if(j&&typeof j=="object")for(let[N,H]of Object.entries(j))S.set(N,{value:H});if(n.data={async get(N,H){let L=S.get(N);if(L&&"value"in L)return L.value;if(L?.promise)return L.promise;if(!H)return;let I=Promise.resolve().then(()=>H()).then(re=>(S.set(N,{value:re}),re));return S.set(N,{promise:I}),I},set(N,H){S.set(N,{value:H})},has(N){return S.has(N)}},K(N=>{for(let H of[...P.keys()])(H.startsWith(`media:${N}:`)||H===`bp:${N}`)&&C(H);y.delete(N),m.delete(N)}),n.browser=sn(),n.ui=rn({ctx:n,renderByIds:b,getSelfId:x,dirtyBatch:p,dirtySet:new Set,mediaRegistry:P,popupTrackers:y,scrollTrackers:m,schedulePopupRecompute:h,ensurePopupListeners:f,destroyPopupListeners:d,isRendering:()=>s,isMounting:()=>a,setMounting:l,endMounting:c}),s=!0,i=Dn(_,n),i._id="_wf_root",i._parentNode=t,i._refNode=M?t.firstChild:null,W.set("_wf_root",i),M)await Re(t,i,n);else{let N=Ge(i,n);N instanceof Node&&t.appendChild(N)}i._refNode=t.firstChild,s=!1,E()},destroy(){d(),y.clear(),m.clear();for(let T of[...P.keys()])C(T);W.clear(),t&&(t.innerHTML=""),t=null,n={}}};return k}function Dn(e,n){return{type:e,props:{},key:void 0}}function jn(e,n){if(!n||n==="/")return e||"/";let t=e.endsWith("/")?e.slice(0,-1):e,o=n.startsWith("/")?n:"/"+n;return t+o}function qn(e){let n=[],t=e.replace(/:(\w+)/g,(o,i)=>(n.push(i),"([^/]+)")).replace(/\*/g,".*");return{re:new RegExp(`^${t}$`),keys:n}}function Oe(e,n="",t=[]){let o=[];for(let i of e){let s=jn(n,i.path),{re:a,keys:u}=qn(s),l=[...t,i];o.push({re:a,keys:u,def:i,chain:l}),i.children&&o.push(...Oe(i.children,s,l))}return o}function an(e,n){let t=null;for(let o of n)e.match(o.re)&&(!t||o.chain.length>t.chain.length)&&(t=o);return t}function ln(e,n){let t={},o=e.match(n.re);if(o)for(let i=0;i<n.keys.length;i++)t[n.keys[i]]=decodeURIComponent(o[i+1]);return t}function Fn(e){let n=Oe(e.routes),t=e.mode||"history";function o(){return t==="hash"?window.location.hash.replace(/^#/,"")||"/":window.location.pathname}function i(s){let a=an(s,n);if(a){let u=a.chain[a.chain.length-1];return{path:a.def.path,params:ln(s,a),query:Object.fromEntries(new URLSearchParams(window.location.search)),chain:a.chain,title:u?.title??""}}return{path:s,params:{},query:Object.fromEntries(new URLSearchParams(window.location.search)),chain:e.notFound?[{component:e.notFound,title:"Not Found"}]:[],title:""}}return s=>{let a=i(o());s.route=a,a.title&&(document.title=a.title),s.app||(s.app={}),s.app.navigate=l=>{if(J(),t==="hash"){window.location.hash="#"+l;let c=i(l);s.route=c}else{window.history.pushState({},"",l);let c=i(l);s.route=c}s.route?.title&&(document.title=s.route.title),s.ui?.bumpCtxVersion?.(),s.ui?.render()};let u=()=>{J();let l=i(o());s.route=l,s.route?.title&&(document.title=s.route.title),s.ui?.bumpCtxVersion?.(),s.ui?.render()};return window.addEventListener("popstate",u),t==="hash"&&window.addEventListener("hashchange",u),s}}function Bn(e,n){let t=n.route?._rvDepth??0;return()=>{let o=n.route;if(!o?.chain?.length||t>=o.chain.length)return null;let i=o.chain[t],s=i.layout??i.component;return s?(i.layout&&(o._rvDepth=t+1),{type:s,props:{},key:void 0}):null}}function Y(e,n){return Object.assign(Object.create(e),n)}function Kn(e={}){let n=e.url??"/ws",t=e.reconnectInterval??3e3,o=e.maxReconnect??10,i=e.pingInterval??3e4,s=e.pingTimeout??1e4;return a=>{let u=new Set,l=null,c=0,p=null,g=null,P=null,C=!1,y={isConnected:!1,onMessage:m=>(u.add(m),()=>{u.delete(m)}),send:m=>{l?.readyState===WebSocket.OPEN&&l.send(JSON.stringify(m))},_connect:v,close:()=>{C=!0,d(),l?.close(),l=null,y.isConnected=!1}};async function v(){if(!C)try{l=new WebSocket(n),l.onopen=()=>{y.isConnected=!0,c=0,r()},l.onmessage=m=>{try{let h=JSON.parse(m.data);for(let b of u)b(h)}catch{}f()},l.onclose=()=>{y.isConnected=!1,d(),!C&&c<o&&(c++,p=setTimeout(v,t*Math.min(c,5)))},l.onerror=()=>{l?.close()}}catch{C||(p=setTimeout(v,t))}}function r(){i<=0||(g=setInterval(()=>{l?.readyState===WebSocket.OPEN&&l.send(JSON.stringify({type:"ping"})),P=setTimeout(()=>{l?.close()},s)},i))}function f(){clearTimeout(P)}function d(){clearInterval(g),clearTimeout(P),clearTimeout(p)}return v(),Y(a,{ws:y})}}function $n(e){let n={baseURL:e?.baseURL??"",headers:{"Content-Type":"application/json",...e?.headers}},t=e?.onRequest,o=e?.onResponse,i=e?.timeout??0;async function s(a,u,l,c){let p=n.baseURL+u,g={method:a,headers:{...n.headers,...c?.headers}},P=e?.token?.();P&&!g.headers.Authorization&&(g.headers.Authorization=`Bearer ${P}`);let C=i>0,y=!!c?.signal,v=null,r=null;(C||y)&&(v=new AbortController,g.signal=v.signal,C&&(r=setTimeout(()=>v.abort(new Error("Request timed out")),i)),y&&c.signal.addEventListener("abort",()=>v.abort())),l!==void 0&&a!=="GET"&&a!=="HEAD"&&(g.body=JSON.stringify(l));let f={url:p,init:g};t&&(f=t(f));try{let d=await fetch(f.url,f.init);if(o)return o(d);if(!d.ok){let b=await d.text().catch(()=>"");throw new ye(d.status,b||d.statusText)}let m=d.headers.get("content-length");if(d.status===204||m==="0")return;let h=(d.headers.get("content-type")||"").toLowerCase();return h.includes("application/json")||h.includes("json")?d.json():d.text()}finally{r&&clearTimeout(r)}}return a=>Y(a,{api:{get:(l,c)=>s("GET",l,void 0,c),post:(l,c,p)=>s("POST",l,c,p),put:(l,c,p)=>s("PUT",l,c,p),patch:(l,c,p)=>s("PATCH",l,c,p),delete:(l,c)=>s("DELETE",l,void 0,c)}})}var ye=class extends Error{status;body;constructor(n,t){super(`API Error ${n}: ${t}`),this.name="ApiError",this.status=n,this.body=t}};function zn(e){try{let n=e.split(".");if(n.length!==3)return null;let t=n[1].replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(atob(t))}catch{return null}}function Yn(e){let n=zn(e);return n?.exp?n.exp*1e3-3e4<Date.now():!0}function Gn(e){let n=e?.storage??localStorage,t=e?.tokenKey??"weifuwu_token",o=e?.userKey??"weifuwu_user",i=e?.refreshTokenKey??"weifuwu_refresh",s=e?.refreshEndpoint??"/api/auth/refresh";return a=>{let u=n.getItem(t),l=n.getItem(o),c={token:u,user:l?JSON.parse(l):null,get isLoggedIn(){return this.token!==null},login(p,g,P){c.token=p,c.user=g,n.setItem(t,p),n.setItem(o,JSON.stringify(g)),P&&n.setItem(i,P)},logout(){c.token=null,c.user=null,n.removeItem(t),n.removeItem(o),n.removeItem(i)},setUser(p){c.user=p,n.setItem(o,JSON.stringify(p))},async refresh(){let p=n.getItem(i);if(!p)return!1;try{let g=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:p})});if(!g.ok)return c.logout(),!1;let P=await g.json();return c.token=P.token,n.setItem(t,P.token),P.refreshToken&&n.setItem(i,P.refreshToken),!0}catch{return!1}}};return u&&Yn(u)&&c.refresh().catch(()=>{}),Y(a,{auth:c})}}function Xn(e,n){let t=null;return o=>{if(t){let s=o.fallback;return typeof s=="function"?s({error:t}):s??null}n.ui._errorHandler=s=>{t=s,n.ui.render()};let i=o.children;try{return i??null}catch(s){t=s;let a=o.fallback;return typeof a=="function"?a({error:s}):a??null}}}var We={components:{Button:{loading:"\u52A0\u8F7D\u4E2D..."},FileUpload:{placeholder:"\u70B9\u51FB\u6216\u62D6\u62FD\u4E0A\u4F20\u6587\u4EF6",supportedFormats:"\u652F\u6301\u683C\u5F0F: ",maxSize:"\u6700\u5927 ",remove:"\u5220\u9664"},Pagination:{ariaLabel:"\u5206\u9875"},ProgressBar:{ariaLabel:"\u8FDB\u5EA6"},Switch:{ariaLabel:"\u5207\u6362"},Breadcrumb:{ariaLabel:"\u9762\u5305\u5C51"},Modal:{ariaLabel:"\u5F39\u7A97",closeAria:"\u5173\u95ED"},Confirm:{confirmText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88"},Drawer:{ariaLabel:"\u4FA7\u8FB9\u9762\u677F",closeAria:"\u5173\u95ED"},DatePicker:{w0:"\u65E5",w1:"\u4E00",w2:"\u4E8C",w3:"\u4E09",w4:"\u56DB",w5:"\u4E94",w6:"\u516D",hour:"\u65F6",minute:"\u5206",time:"\u65F6\u95F4",confirm:"\u786E\u5B9A",cancel:"\u53D6\u6D88",placeholder:"\u9009\u62E9\u65E5\u671F"}}};var Ve={components:{Button:{loading:"Loading..."},FileUpload:{placeholder:"Click or drag to upload",supportedFormats:"Supported formats: ",maxSize:"Max size: ",remove:"Remove"},Pagination:{ariaLabel:"Pagination"},ProgressBar:{ariaLabel:"Progress"},Switch:{ariaLabel:"Toggle"},Breadcrumb:{ariaLabel:"Breadcrumb"},Modal:{ariaLabel:"Dialog",closeAria:"Close"},Confirm:{confirmText:"OK",cancelText:"Cancel"},Drawer:{ariaLabel:"Panel",closeAria:"Close"},DatePicker:{w0:"Su",w1:"Mo",w2:"Tu",w3:"We",w4:"Th",w5:"Fr",w6:"Sa",hour:"Hour",minute:"Min",time:"Time",confirm:"OK",cancel:"Cancel",placeholder:"Pick a date"}}};var ge={"zh-CN":We,"en-US":Ve};function un(e){if(ge[e])return e;let n=e.split("-")[0];return Object.keys(ge).find(o=>o.startsWith(n))??"zh-CN"}function Jn(e={}){let{locale:n="zh-CN",messages:t={},components:o={}}=e,i=un(n),s=ge[i],a=cn(s,t,o),u={locale:i,t:(l,c)=>a.messages?.[l]??c??l,setLocale:()=>{},components:a.components};return l=>(l.i18n=u,u.setLocale=c=>{let p=un(c),g=ge[p];g&&(a=cn(g,t,o),u.locale=p,u.components=a.components,l?.ui?.bumpCtxVersion?.(),l?.ui?.render())},l)}function cn(e,n,t){return{messages:{...e?.messages,...n},components:Qn(e?.components??{},t)}}function Qn(e,n){let t={...e};for(let o of Object.keys(n))typeof n[o]=="object"&&n[o]!==null&&typeof t[o]=="object"?t[o]={...t[o],...n[o]}:t[o]=n[o];return t}function Zn(e,n,t=400){let o=!1,i=()=>{o||(o=!0,e.removeEventListener("animationend",i),clearTimeout(s),n())};e.addEventListener("animationend",i);let s=setTimeout(i,t)}export{ye as ApiError,Xn as ErrorBoundary,B as Fragment,q as Portal,Bn as RouteView,Me as aiStream,Zn as animateOut,$n as api,mn as asyncComponent,Gn as auth,O as callRefCleanup,J as clearAsyncComponentCache,In as computeFixedPos,pe as computeFixedPosRect,Un as createApp,be as createPortal,fe as createReactiveState,Ve as enUS,Y as extendCtx,hn as h,Re as hydrateVNode,Jn as i18n,X as isAsyncComponent,we as jsx,gn as jsxDEV,yn as jsxs,ke as lockScroll,Sn as mountVNode,z as patchValue,Fn as router,nn as toChatMessages,de as trapFocus,Ne as unlockScroll,Kn as ws,We as zhCN};
|
package/dist/client/types.d.ts
CHANGED
|
@@ -165,8 +165,51 @@ export interface UseScrollPositionHandle {
|
|
|
165
165
|
refresh(): void;
|
|
166
166
|
}
|
|
167
167
|
/** 应用上下文 */
|
|
168
|
+
/**
|
|
169
|
+
* 浏览器环境抽象(ctx.browser)——组件不直接引用 window/document:
|
|
170
|
+
* ① SSR 安全(shim 返回安全默认)② 测试可 mock(jsdom 无关)③ 复制等
|
|
171
|
+
* 重复模式统一。客户端由 createClientBrowser 实现,SSR 由 createSsrContext 注入。
|
|
172
|
+
*/
|
|
173
|
+
export interface BrowserEnv {
|
|
174
|
+
/** 当前焦点元素(键盘导航) */
|
|
175
|
+
activeElement(): HTMLElement | null;
|
|
176
|
+
/** 按 id 查询元素 */
|
|
177
|
+
byId(id: string): HTMLElement | null;
|
|
178
|
+
/** CSS 选择器查询元素 */
|
|
179
|
+
query(sel: string): HTMLElement | null;
|
|
180
|
+
/** 创建元素 */
|
|
181
|
+
createElement<K extends keyof HTMLElementTagNameMap>(tag: K): HTMLElementTagNameMap[K] | null;
|
|
182
|
+
/** body 追加/移除 */
|
|
183
|
+
bodyAppend(el: Node): void;
|
|
184
|
+
bodyRemove(el: Node): void;
|
|
185
|
+
/** 复制文本(clipboard API + execCommand 降级,统一组件重复实现) */
|
|
186
|
+
copyText(text: string): Promise<boolean>;
|
|
187
|
+
/** execCommand(富文本编辑器) */
|
|
188
|
+
execCommand(cmd: string, value?: string): boolean;
|
|
189
|
+
/** 编辑器选区文本 */
|
|
190
|
+
selectionText(): string | null;
|
|
191
|
+
/** 编辑器选区对象(完整 Selection——Editor 需要 range 操作) */
|
|
192
|
+
getSelection(): Selection | null;
|
|
193
|
+
/** 视口高度 */
|
|
194
|
+
viewportHeight(): number;
|
|
195
|
+
/** 滚动量(scrollingElement 优先) */
|
|
196
|
+
scrollTop(): number;
|
|
197
|
+
/** location.hash */
|
|
198
|
+
hash(): string;
|
|
199
|
+
setHash(h: string): void;
|
|
200
|
+
/** 定时器(SSR no-op) */
|
|
201
|
+
timeout(fn: () => void, ms: number): number;
|
|
202
|
+
/** document.documentElement(主题应用) */
|
|
203
|
+
rootElement(): HTMLElement | null;
|
|
204
|
+
/** localStorage 读取(SSR/隐私模式返回 null) */
|
|
205
|
+
storageGet(key: string): string | null;
|
|
206
|
+
/** localStorage 写入(SSR/隐私模式 no-op) */
|
|
207
|
+
storageSet(key: string, value: string): void;
|
|
208
|
+
}
|
|
168
209
|
export interface WfuiContext {
|
|
169
210
|
[key: string]: unknown;
|
|
211
|
+
/** 浏览器环境抽象(SSR shim 安全默认)——组件禁直接 window/document */
|
|
212
|
+
browser?: BrowserEnv;
|
|
170
213
|
/** UI 框架能力(由 createApp.mount 注入) */
|
|
171
214
|
ui: {
|
|
172
215
|
/** 触发组件重渲染(同步,无参 = 当前组件) */
|
package/dist/client/ui.d.ts
CHANGED
|
@@ -20,6 +20,9 @@ export interface UiInternal {
|
|
|
20
20
|
_dirtyScheduled?: boolean;
|
|
21
21
|
/** ctx.ui.$() 的 WeakMap 缓存(每组件一个 $ 容器) */
|
|
22
22
|
_$cache?: Record<string, any>;
|
|
23
|
+
/** mount 阶段标记(内部——mountComponent 包裹) */
|
|
24
|
+
setMounting: (v: boolean) => void;
|
|
25
|
+
endMounting: () => void;
|
|
23
26
|
}
|
|
24
27
|
/** createUi 依赖(由 createApp 注入 app 级闭包状态) */
|
|
25
28
|
export interface UiDeps {
|
|
@@ -58,5 +61,10 @@ export interface UiDeps {
|
|
|
58
61
|
destroyPopupListeners: () => void;
|
|
59
62
|
/** 渲染保护期(dirty 被忽略) */
|
|
60
63
|
isRendering: () => boolean;
|
|
64
|
+
/** mount 阶段(组件工厂执行——$ 初始化赋值丢弃) */
|
|
65
|
+
isMounting: () => boolean;
|
|
66
|
+
/** mount 阶段标记置位/恢复(mountComponent 包裹) */
|
|
67
|
+
setMounting: (v: boolean) => void;
|
|
68
|
+
endMounting: () => void;
|
|
61
69
|
}
|
|
62
70
|
export declare function createUi(deps: UiDeps): WfuiContext['ui'] & UiInternal;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* weifuwu/components — Anchor
|
|
3
|
+
*
|
|
4
|
+
* 锚点导航(长文页):items 列表 + 滚动高亮跟随 + 点击平滑滚动。
|
|
5
|
+
* 滚动侦听:ctx.ui.useScrollPosition(全局/容器 scroll 监听 + rAF 节流,内置方案)。
|
|
6
|
+
* 裁剪:嵌套滚动容器、滚动容器非视口(container 未提供时仅视口)、自动生成标题锚点。
|
|
7
|
+
*/
|
|
8
|
+
import type { Component } from '../../client/vnode.ts';
|
|
9
|
+
export interface AnchorItem {
|
|
10
|
+
href: string;
|
|
11
|
+
title: any;
|
|
12
|
+
}
|
|
13
|
+
export interface AnchorProps {
|
|
14
|
+
items: AnchorItem[];
|
|
15
|
+
/** 当前激活锚点(受控可选;省略时滚动自动跟随) */
|
|
16
|
+
activeKey?: string;
|
|
17
|
+
/** 激活锚点变化回调(受控或观察) */
|
|
18
|
+
onAnchorChange?: (href: string) => void;
|
|
19
|
+
/** 点击是否更新 location.hash(默认 false——回调 + 滚动) */
|
|
20
|
+
useHash?: boolean;
|
|
21
|
+
/** 滚动容器(默认 window) */
|
|
22
|
+
container?: () => HTMLElement | Window;
|
|
23
|
+
/** 高亮阈值:锚点进入视口该偏移内视为激活(px),默认 80 */
|
|
24
|
+
offsetTop?: number;
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare const Anchor: Component<AnchorProps>;
|
|
@@ -11,6 +11,10 @@ export interface FileUploadProps {
|
|
|
11
11
|
hint?: string;
|
|
12
12
|
value?: File[];
|
|
13
13
|
onChange?: (files: File[]) => void;
|
|
14
|
+
/** 上传中状态(父层驱动——组件不做 xhr,诚实裁剪) */
|
|
15
|
+
uploading?: boolean;
|
|
16
|
+
/** 上传进度 0-100(父层驱动) */
|
|
17
|
+
progress?: number;
|
|
14
18
|
children?: any;
|
|
15
19
|
}
|
|
16
20
|
export declare const FileUpload: Component<FileUploadProps>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* weifuwu/components — JSONViewer
|
|
3
|
+
*
|
|
4
|
+
* 结构化 JSON 浏览(工具调用 args / API 响应):递归树 + 折叠 + 类型色 + 路径复制 + 懒展开。
|
|
5
|
+
* 零依赖(无 raw JSON.parse 展示——VNode 渲染天然转义)。
|
|
6
|
+
* 裁剪:JSON 编辑、超大对象流式渲染(懒展开覆盖 100 键级)。
|
|
7
|
+
*/
|
|
8
|
+
import type { Component } from '../../client/vnode.ts';
|
|
9
|
+
export interface JSONViewerProps {
|
|
10
|
+
data: unknown;
|
|
11
|
+
/** 默认展开深度(默认 2)——更深折叠为摘要 */
|
|
12
|
+
defaultExpandDepth?: number;
|
|
13
|
+
/** 对象键数超过该值时懒展开(只渲染前 N 个 + "+N 项",默认 100) */
|
|
14
|
+
maxKeys?: number;
|
|
15
|
+
/** 根键名(默认 'root')——复制路径前缀 */
|
|
16
|
+
rootName?: string;
|
|
17
|
+
/** 复制路径回调(默认 navigator.clipboard 写入 JSON 路径) */
|
|
18
|
+
onCopy?: (path: string, value: unknown) => void;
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const JSONViewer: Component<JSONViewerProps>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* weifuwu/components — LogViewer
|
|
3
|
+
*
|
|
4
|
+
* 日志流查看器(Agent 执行日志 / CI 输出):ANSI 着色 + 虚拟滚动 + 自动跟随。
|
|
5
|
+
* 复用 VirtualList 滚动基座(useScrollPosition + rAF 节流)。
|
|
6
|
+
* 裁剪:正则高亮、多日志源合并、搜索定位。
|
|
7
|
+
*/
|
|
8
|
+
import type { Component } from '../../client/vnode.ts';
|
|
9
|
+
export interface LogViewerProps {
|
|
10
|
+
lines: string[];
|
|
11
|
+
/** 视口高度(px),默认 400 */
|
|
12
|
+
height?: number;
|
|
13
|
+
/** 行高(px),默认 24 */
|
|
14
|
+
lineHeight?: number;
|
|
15
|
+
/** 可见区外额外渲染行数 */
|
|
16
|
+
overscan?: number;
|
|
17
|
+
/** 自动跟随:新行到达时若已在底部则滚到底(默认 true) */
|
|
18
|
+
follow?: boolean;
|
|
19
|
+
/** 只显示尾部 N 行(内存保护,默认不限) */
|
|
20
|
+
maxLines?: number;
|
|
21
|
+
/** 显示复制按钮(默认 true) */
|
|
22
|
+
showCopy?: boolean;
|
|
23
|
+
/** 显示行号(默认 true) */
|
|
24
|
+
showLineNumbers?: boolean;
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
/** ANSI 转义解析(16 色 + 粗体 + 背景 8 色):累积样式到 reset 为止,零依赖 */
|
|
28
|
+
export declare function parseAnsi(text: string): any[];
|
|
29
|
+
export declare const LogViewer: Component<LogViewerProps>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* weifuwu/components — Menu
|
|
3
3
|
*
|
|
4
|
-
* 导航菜单(侧栏导航):分组项 + 图标 + 选中态 + 方向键导航 + Enter
|
|
4
|
+
* 导航菜单(侧栏导航):分组项 + 图标 + 选中态 + 方向键导航 + Enter 激活 + 子菜单 + 折叠。
|
|
5
5
|
* 用于 SaaS 应用侧边导航(替代手写 nav-item 循环)。
|
|
6
|
-
*
|
|
6
|
+
* 裁剪:水平菜单栏(Menubar)、折叠时子菜单浮层(popup,见 roadmap)、子菜单自动互斥。
|
|
7
7
|
*/
|
|
8
8
|
import type { Component } from '../../client/vnode.ts';
|
|
9
9
|
export interface MenuItem {
|
|
@@ -15,11 +15,20 @@ export interface MenuItem {
|
|
|
15
15
|
active?: boolean;
|
|
16
16
|
danger?: boolean;
|
|
17
17
|
onClick?: () => void;
|
|
18
|
+
/** 子菜单项(有 children 即渲染为可展开子菜单) */
|
|
19
|
+
children?: MenuItem[];
|
|
18
20
|
}
|
|
19
21
|
export interface MenuProps {
|
|
20
22
|
items: MenuItem[];
|
|
21
23
|
onSelect?: (key: string) => void;
|
|
22
24
|
activeKey?: string;
|
|
23
25
|
className?: string;
|
|
26
|
+
/** 受控展开 key 列表(子菜单) */
|
|
27
|
+
openKeys?: string[];
|
|
28
|
+
onOpenChange?: (keys: string[]) => void;
|
|
29
|
+
/** 可折叠侧栏(宽度收窄 + label 隐藏) */
|
|
30
|
+
collapsible?: boolean;
|
|
31
|
+
collapsed?: boolean;
|
|
32
|
+
onCollapseChange?: (collapsed: boolean) => void;
|
|
24
33
|
}
|
|
25
34
|
export declare const Menu: Component<MenuProps>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* weifuwu/components — VirtualTable
|
|
3
|
+
*
|
|
4
|
+
* 虚拟表格(数据密集场景):固定表头 + 虚拟滚动表体,10k+ 行只渲染可见窗口。
|
|
5
|
+
* 复用 VirtualList 滚动基座(useScrollPosition 像素级 scrollTop + rAF 节流)。
|
|
6
|
+
* 排序:受控 sortKey/sortOrder + onSort(与 Table 同款模式)。
|
|
7
|
+
* 裁剪:行选择(rowSelection)、列虚拟化(横向)、行编辑、单元格合并、树形表格。
|
|
8
|
+
*/
|
|
9
|
+
import type { Component } from '../../client/vnode.ts';
|
|
10
|
+
import type { TableColumn } from '../Table/Table.ts';
|
|
11
|
+
export interface VirtualTableProps {
|
|
12
|
+
columns: TableColumn[];
|
|
13
|
+
data?: any[];
|
|
14
|
+
/** 视口高度(px),默认 400 */
|
|
15
|
+
height?: number;
|
|
16
|
+
/** 行高(px),默认 40 */
|
|
17
|
+
rowHeight?: number;
|
|
18
|
+
/** 可见区外额外渲染行数 */
|
|
19
|
+
overscan?: number;
|
|
20
|
+
/** 当前排序列 key */
|
|
21
|
+
sortKey?: string;
|
|
22
|
+
/** 当前排序方向 */
|
|
23
|
+
sortOrder?: 'asc' | 'desc';
|
|
24
|
+
/** 排序变化回调 */
|
|
25
|
+
onSort?: (key: string, order: 'asc' | 'desc') => void;
|
|
26
|
+
/** 数据为空时显示的文本 */
|
|
27
|
+
emptyText?: string;
|
|
28
|
+
/** 行点击 */
|
|
29
|
+
onRowClick?: (row: any, index: number) => void;
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare const VirtualTable: Component<VirtualTableProps>;
|
|
@@ -183,6 +183,14 @@ export { InfiniteScroll } from './InfiniteScroll/InfiniteScroll.ts';
|
|
|
183
183
|
export type { InfiniteScrollProps } from './InfiniteScroll/InfiniteScroll.ts';
|
|
184
184
|
export { VirtualList } from './VirtualList/VirtualList.ts';
|
|
185
185
|
export type { VirtualListProps } from './VirtualList/VirtualList.ts';
|
|
186
|
+
export { VirtualTable } from './VirtualTable/VirtualTable.ts';
|
|
187
|
+
export type { VirtualTableProps } from './VirtualTable/VirtualTable.ts';
|
|
188
|
+
export { Anchor } from './Anchor/Anchor.ts';
|
|
189
|
+
export type { AnchorProps, AnchorItem } from './Anchor/Anchor.ts';
|
|
190
|
+
export { LogViewer, parseAnsi } from './LogViewer/LogViewer.ts';
|
|
191
|
+
export type { LogViewerProps } from './LogViewer/LogViewer.ts';
|
|
192
|
+
export { JSONViewer } from './JSONViewer/JSONViewer.ts';
|
|
193
|
+
export type { JSONViewerProps } from './JSONViewer/JSONViewer.ts';
|
|
186
194
|
export { QRCode } from './QRCode/QRCode.ts';
|
|
187
195
|
export type { QRCodeProps } from './QRCode/QRCode.ts';
|
|
188
196
|
export { generateQr } from './QRCode/qr.ts';
|