weifuwu 0.70.0 → 0.71.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 +8 -8
- package/dist/client/diff.d.ts +7 -6
- package/dist/client/index.js +5 -5
- package/dist/client/registry.d.ts +17 -2
- package/dist/client/render.d.ts +12 -5
- package/dist/client/router.d.ts +3 -2
- package/dist/client/types.d.ts +41 -18
- package/dist/client/ui.d.ts +7 -1
- package/dist/client/vnode.d.ts +12 -5
- package/dist/components/ApprovalCard/ApprovalCard.d.ts +2 -0
- package/dist/components/Badge/Badge.d.ts +6 -0
- package/dist/components/Cascader/Cascader.d.ts +6 -2
- package/dist/components/EmptyState/EmptyState.d.ts +3 -2
- package/dist/components/InputNumber/InputNumber.d.ts +2 -2
- package/dist/components/Layout/Layout.d.ts +2 -0
- package/dist/components/Markdown/parser.d.ts +11 -5
- package/dist/components/Menu/Menu.d.ts +1 -1
- package/dist/components/ProgressBar/ProgressBar.d.ts +5 -0
- package/dist/components/Rate/Rate.d.ts +2 -0
- package/dist/components/Sparkline/Sparkline.d.ts +2 -0
- package/dist/components/StatCard/StatCard.d.ts +5 -3
- package/dist/components/Timeline/Timeline.d.ts +5 -4
- package/dist/components/Transfer/Transfer.d.ts +6 -2
- package/dist/components/Tree/Tree.d.ts +3 -1
- package/dist/components/VirtualTable/VirtualTable.d.ts +9 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +13 -13
- package/dist/components/style.css +803 -320
- package/dist/index.js +8 -1
- package/dist/layout/weifuwu-layout.css +133 -15
- package/docs/components.md +2 -2
- package/docs/layout.md +37 -9
- 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 + 109 组件 + CSS 设计系统 + SaaS 地基(认证 / 消息 / 队列 / AI)。全自研、零构建、消灭样板。
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install weifuwu # 一个依赖,完整应用栈
|
|
@@ -24,8 +24,8 @@ npm install weifuwu # 一个依赖,完整应用栈
|
|
|
24
24
|
|----|------|------|
|
|
25
25
|
| 后端 | `weifuwu` | Trie 路由 / 中间件链 / serve / 自研 PG+Redis / SSR / GraphQL / WebSocket |
|
|
26
26
|
| 前端 | `weifuwu/client` | 两阶段组件 / Proxy 渲染 / 数据管道 / 路由 / api·auth·ws·i18n / 移动端原语 / **ctx.browser 环境抽象**(组件零 window/document) |
|
|
27
|
-
| 组件 | `weifuwu/components` |
|
|
28
|
-
| 样式 | `weifuwu/layout` |
|
|
27
|
+
| 组件 | `weifuwu/components` | 109 个 HTML 原语组件(表单/表格/弹层/AiChat…),引用 `--wf-*` 主题变量 |
|
|
28
|
+
| 样式 | `weifuwu/layout` | 57 布局原语 + 136 工具类 + 167 主题 Token,零自定义 CSS 文件 |
|
|
29
29
|
| SaaS 地基 | 随包内置 | rateLimit / email / userSystem / messager / queue / ai → `ctx.*` 一行接入 |
|
|
30
30
|
|
|
31
31
|
> ⚠️ **注意:前后端都有 `ctx.ui`,但用途完全不同**
|
|
@@ -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(109 组件)/ 数据管道(ctx.api)零自研替代。框架哲学(中间件注入、诚实裁剪、机制与策略分离)经受住了真实复杂应用的检验——这也是我们确定「哪些进框架、哪些留应用层」的依据。
|
|
113
113
|
|
|
114
114
|
---
|
|
115
115
|
|
|
@@ -305,7 +305,7 @@ cd apps/agent-platform && npm run seed && npm run dev
|
|
|
305
305
|
|------|---------|------|
|
|
306
306
|
| `weifuwu/client` | `https://unpkg.com/weifuwu@latest/dist/client/index.js` | 客户端核心(createApp, h, 路由, 状态管理等) |
|
|
307
307
|
| `weifuwu/components` | `https://unpkg.com/weifuwu@latest/dist/components/index.js` | 102 个 UI 组件(Button, Card, Table, Modal, Icon 等) |
|
|
308
|
-
| `weifuwu/components` | `https://unpkg.com/weifuwu@latest/dist/components/style.css` | 组件 CSS +
|
|
308
|
+
| `weifuwu/components` | `https://unpkg.com/weifuwu@latest/dist/components/style.css` | 组件 CSS + 167 个主题 Token + 57 个布局原语 + 136 个工具类 |
|
|
309
309
|
| 独立布局系统 | `https://unpkg.com/weifuwu@latest/dist/layout/weifuwu-layout.css` | 仅 CSS 布局,不依赖 JS |
|
|
310
310
|
|
|
311
311
|
|
|
@@ -347,7 +347,7 @@ cd apps/agent-platform && npm run seed && npm run dev
|
|
|
347
347
|
| `weifuwu/client` | **popup** | 弹层 fixed 定位工具(`computeFixedPos` / `computeFixedPosRect` / `clampToViewport`) | — |
|
|
348
348
|
| `weifuwu/client` | **事件原语** | `usePopup` / `useDialog` / `usePresence` / `useInView` / `useScrollPosition` / `useGlobalKey` / `useDrag` / `useDragDrop` / `useAnimationEnd` / `useTween` / `useReducedMotion`(浏览器事件/动画统一入口,见 [docs/mobile.md](docs/mobile.md)) | — |
|
|
349
349
|
| `weifuwu/components` | **113 个组件** | Button/Table/Modal/Confirm/Toast/... + `confirm()` / `toast()` 命令式中间件 | weifuwu/client |
|
|
350
|
-
| `weifuwu/layout` | **CSS 布局** |
|
|
350
|
+
| `weifuwu/layout` | **CSS 布局** | 57 个布局原语 + 136 个工具类 + 167 个主题 Token(也支持 `weifuwu/layout/style.css`) | — |
|
|
351
351
|
|
|
352
352
|
---
|
|
353
353
|
|
|
@@ -369,7 +369,7 @@ cd apps/agent-platform && npm run seed && npm run dev
|
|
|
369
369
|
| AI 对话 / Agent / HITL 审批 | `ai()` → `ctx.ai` + `ctx.ui.useChat()` + `AiChat` | [docs/saas.md](docs/saas.md) |
|
|
370
370
|
| GraphQL / WebSocket | `app.graphql(handler)` · `app.ws(path, handler)` | [docs/realtime.md](docs/realtime.md) |
|
|
371
371
|
| 前端 UI 组件 | `weifuwu/components`(102 个:Button/Table/Modal/AiChat/...) | [docs/components.md](docs/components.md) |
|
|
372
|
-
| 布局/主题/暗色 | `weifuwu/layout`(
|
|
372
|
+
| 布局/主题/暗色 | `weifuwu/layout`(57 原语 + 136 工具类 + 167 Token) | [docs/layout.md](docs/layout.md) |
|
|
373
373
|
| 样式定制(零自定义 CSS) | `--wf-*` 变量覆盖 + 组件定制钩子 | [docs/styling.md](docs/styling.md) |
|
|
374
374
|
| 移动端适配(tap/长按/键盘/弹层) | `usePopup` / `useHoverCapable` / `useLongPress` / `useVisualViewport` | [docs/mobile.md](docs/mobile.md) |
|
|
375
375
|
| 前后端类型安全中间件 | `createMiddleware`(声明注入即类型化) | [docs/server.md](docs/server.md) |
|
|
@@ -491,7 +491,7 @@ README 只保留入门内容(设计理念 / 快速开始 / 核心概念 / 模
|
|
|
491
491
|
| [docs/frontend.md](docs/frontend.md) | 前端核心:createApp / 组件模型 / 状态管理 / 条件与列表 / ref / 类型 |
|
|
492
492
|
| [docs/frontend-middleware.md](docs/frontend-middleware.md) | 前端中间件:router / api / auth / ws / i18n / ErrorBoundary / confirm / toast / ScrollLock / extendCtx |
|
|
493
493
|
| [docs/components.md](docs/components.md) | 组件库(113 个组件 + 使用示例 + 组件列表) |
|
|
494
|
-
| [docs/layout.md](docs/layout.md) | 布局系统:
|
|
494
|
+
| [docs/layout.md](docs/layout.md) | 布局系统:57 个布局原语 + 136 个工具类 + 167 个主题 Token |
|
|
495
495
|
| [docs/styling.md](docs/styling.md) | 样式定制指南:零自定义 CSS 模式 / 暗色 / 组件级覆盖 / 作用域主题 |
|
|
496
496
|
|
|
497
497
|
### 通用
|
package/dist/client/diff.d.ts
CHANGED
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
* diff.ts → registry.ts(callRefCleanup)
|
|
7
7
|
* render.ts 不依赖 diff.ts(单向,无环)
|
|
8
8
|
*/
|
|
9
|
+
import type { VNodeChild } from './vnode.ts';
|
|
9
10
|
import type { WfuiContext } from './types.ts';
|
|
10
|
-
export declare function patchValue(parent: Node, oldNode: Node | null, oldInput:
|
|
11
|
-
export declare function patchProps(el: Element, oldProps:
|
|
11
|
+
export declare function patchValue(parent: Node, oldNode: Node | null, oldInput: VNodeChild, newInput: VNodeChild, ctx: WfuiContext): Node | null;
|
|
12
|
+
export declare function patchProps(el: Element, oldProps: Record<string, unknown> | null, newProps: Record<string, unknown>): void;
|
|
12
13
|
/** 为无 key 的子节点自动分配位置 key,确保 keyed diff 正确性 */
|
|
13
|
-
export declare function ensureKeys(oldChildren:
|
|
14
|
+
export declare function ensureKeys(oldChildren: VNodeChild[], newChildren: VNodeChild[]): void;
|
|
14
15
|
/**
|
|
15
16
|
* 将 children 映射到它们实际产生的 DOM 节点(每个 child 一个 Node[])。
|
|
16
17
|
*
|
|
@@ -18,10 +19,10 @@ export declare function ensureKeys(oldChildren: any[], newChildren: any[]): void
|
|
|
18
19
|
* null/boolean/Portal 产生 0 个。explicitNodes 提供限定范围(Fragment 子项
|
|
19
20
|
* 用其自身 _childNodes),否则从 source(parent.childNodes 或给定快照)按计数游标分配。
|
|
20
21
|
*/
|
|
21
|
-
export declare function mapChildDomNodes(source: Node[], children:
|
|
22
|
-
export declare function normalize(children:
|
|
22
|
+
export declare function mapChildDomNodes(source: Node[], children: VNodeChild[]): (Node[] | null)[];
|
|
23
|
+
export declare function normalize(children: VNodeChild): VNodeChild[];
|
|
23
24
|
/**
|
|
24
25
|
* keyed 子节点 diff。返回每个 new child 的 DOM 节点范围(newNodes,可为空)。
|
|
25
26
|
* oldNodes:old children → 实际 DOM 节点(mapChildDomNodes 结果)。
|
|
26
27
|
*/
|
|
27
|
-
export declare function patchKeyedChildren(parent: Node, oldChildren:
|
|
28
|
+
export declare function patchKeyedChildren(parent: Node, oldChildren: VNodeChild[], newChildren: VNodeChild[], ctx: WfuiContext, oldNodes?: (Node[] | null)[], rangeStart?: Node | null): (Node[] | null)[];
|
package/dist/client/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var Fe="__wfAsyncComponent";function xn(e){let n=e;return n[Fe]=!0,n}function J(e){return typeof e=="function"&&e?.[Fe]===!0}var K=Symbol("Fragment"),F=Symbol("Portal");function Pe(e,n,t){return{type:e,props:Be(n),key:t??void 0}}var Tn=Pe;function En(e,n,t){return Pe(e,n,t)}function Pn(e,n,...t){let o=Be(n??{});return t.length>0&&(o.children=t.length===1?t[0]:t),{type:e,props:o,key:n?.key??void 0}}function Be(e){if(!e)return{};let n={};for(let t of Object.keys(e))t!=="key"&&(n[t]=e[t]);return n}function Se(e,n){return{type:F,props:{children:e,portalKey:n},key:n??void 0,_placement:"remote"}}var Sn=0,V=new Map,ae=[];function B(e){ae.push(e)}var le=new WeakMap;function Q(){le=new WeakMap}function _e(e,n){let t=le.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}),le.set(e,o),o}async function Ke(e,n){return _e(e,n).promise}function $e(e){return le.get(e)?.resolved}function _n(e){let n=e._child;if(n!=null)if(Array.isArray(n))for(let t of n)t&&typeof t=="object"&&W(t);else typeof n=="object"&&W(n)}function W(e){if(e==null||typeof e!="object")return;let n=e;if(n._id){if(n._customId&&V.delete(n._customId),V.delete(n._id),ae.length>0){for(let t of ae)t(n._id);if(n._customId)for(let t of ae)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"&&W(t);else W(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"&&W(o)}typeof n.props?.ref=="function"&&n.props.ref(null),n._remoteEl&&(_n(n),n._remoteEl.remove(),n._remoteEl=void 0)}function Z(){return`_wf_${Sn++}`}var ze=new WeakMap;function An(e){let n=ze.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 })")),ze.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?(W(t),n.remove()):W(t),null;let s=Ye(t),a=Ye(o);if(s!==a){W(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 d=o,l=t;if(typeof d.type=="function"){let c=d.type;l._render&&l.type===d.type&&(d._render=l._render,d._id=l._id,d._id&&V.set(d._id,d)),d._parentNode=e,d._refNode=n;let m=Object.create(i);if(m.ui=Object.create(i.ui),m.ui._selfId=d._id,m.ui._selfVNode=d,d._ctxVersion=l._ctxVersion??m.ui._ctxVersion??0,l._render&&l.type===d.type&&Mn(l.props,d.props)&&!m.ui._dirtySet?.has(l._id)&&d._ctxVersion===m.ui._ctxVersion)return d._child=l._child,n;m.ui._dirtySet?.delete(l._id);let g;try{typeof d._render=="function"?g=d._render(d.props):g=Re(c,d.props,d,m)}catch(h){let v=i.ui?._errorHandler;v?(v(h),g=null):(console.error(`[weifuwu] Component render error in <${c?.name||"anonymous"}> (id: ${l._id??"?"}, phase: update)`,h),g=null)}let P=l._child;d._child=g;let C=z(e,n,P,g,m);return C||(d._refNode=null),C}if(d.type===K){let c=l._childNodes,m=Je(e,l,d,i,c);return d._childNodes=m,n}if(typeof d.type=="string"){if(n&&n.nodeType===1){let c=l.props?.ref,m=d.props?.ref;c!==m&&(typeof m=="function"&&m(n),typeof c=="function"&&typeof m=="function"&&An(n)),ke(n,l.props,d.props),Je(n,l,d,i)}else if(n){W(t);let c=U(o,i);return c==null?null:(n.parentNode?.replaceChild(c,n),c)}return n}if(d.type===F)return te(l,d,i),null;if(Array.isArray(o)){let c=Array.isArray(t)?t:[];ue(c,o);let m=Array.from(e.childNodes),g=n?m.indexOf(n):-1,P=g>=0?ee(m.slice(g),c):ee(m,c);return ce(e,c,o,i,P,n),n}return n}var Ge=new Map;function kn(e){let n=Ge.get(e);return n||(n=`fn:${e.name||"anon"}`,Ge.set(e,n)),n}function Ye(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"?kn(n.type):n.type===K?"fragment":n.type===F?"portal":typeof n.type=="string"?"tag:"+n.type:"unknown"}function ke(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 d=n?.[a],l=t?.[a];if(a==="innerHTML")l!==d&&(e.innerHTML=String(l??""));else if(l!==d)if(a==="class"||a==="className")e instanceof SVGElement?e.setAttribute("class",Xe(l)):e.className=Xe(l);else if(a==="style"&&typeof l=="object"){let c=e.style;for(let m of Object.keys(l)){let g=l[m];g==null?m.startsWith("--")?c.removeProperty(m):c[m]="":m.startsWith("--")?c.setProperty(m,String(g)):c[m]=typeof g=="number"?g+"px":String(g)}}else if(a.startsWith("on")&&typeof l=="function"){let c=a.slice(2).toLowerCase();typeof d=="function"&&e.removeEventListener(c,d),e.addEventListener(c,l)}else a==="draggable"?e.setAttribute("draggable",l?"true":"false"):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 Xe(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 Ae(e){if(!(e==null||typeof e!="object"))return e.key}function ue(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 ee(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===F){t.push(null);continue}if(s.type===K){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 if(typeof s.type=="function")if(s._render){let a=s._childNodes??s._refNode;a==null?t.push(null):Array.isArray(a)?(t.push(a.slice()),o+=a.length):(t.push([a]),o+=1)}else 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 Je(e,n,t,o,i){let s=ne(n.props?.children),a=ne(t.props?.children);ue(s,a);let d=i??Array.from(e.childNodes),l=ee(d,s),c=ce(e,s,a,o,l,i?.[0]??null),m=[];for(let g of c)g&&g.length>0&&m.push(...g);return m}function ne(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 ce(e,n,t,o,i=[],s=null){if(!t.some(h=>h&&typeof h=="object"&&h.key!==void 0&&h._placement!=="remote")){let h=Math.max(n.length,t.length);for(let v=0;v<h;v++){let r=v<n.length?n[v]:null,u=v<t.length?t[v]:null;if(u==null){if(r!=null){W(r);for(let f of i[v]??[])f.remove()}}else if(r==null){let f=U(u,o);if(f!=null){let p=null;for(let y=v+1;y<i.length;y++){let w=i[y]?.[0];if(w&&w.parentNode===e){p=w;break}}p?e.insertBefore(f,p):e.appendChild(f)}}else{let f=i[v]?.[0]??null;z(e,f,r,u,o)}}return[]}for(let h=0;h<n.length;h++){let v=n[h];if(!(v==null||typeof v=="boolean")&&Ae(v)===void 0)for(let r of i[h]??[])r.remove()}let d=new Map,l=0;for(let h=0;h<n.length;h++){let v=Ae(n[h]);v!==void 0&&d.set(v,{vnode:n[h],nodes:i[h]??[],index:l++})}let c=t.map(h=>Ae(h)),m=new Set(c);for(let h of[...d.keys()])if(!m.has(h)){let v=d.get(h);W(v.vnode);for(let r of v.nodes)r?.remove();d.delete(h)}let g=new Array(t.length).fill(null),P=-1,C=s&&s.parentNode===e?s:e.firstChild;for(let h=0;h<t.length;h++){let v=c[h],r=t[h],u=v!==void 0?d.get(v):void 0,f=r&&typeof r=="object"&&r._placement==="remote";if(u)if(u.nodes.length>0){if(u.index<P)for(let y of u.nodes)e.insertBefore(y,C);P=Math.max(P,u.index),z(e,u.nodes[0],u.vnode,r,o),g[h]=r._childNodes??u.nodes.filter(y=>y.parentNode===e),C=g[h][g[h].length-1]?.nextSibling??null}else if(f)te(u.vnode,r,o),g[h]=[];else{let p=z(e,null,u.vnode,r,o);g[h]=Qe(p);for(let w of g[h])e.insertBefore(w,C);C=g[h][g[h].length-1]?.nextSibling??null}else if(f)Y(r,o),g[h]=[];else{let p=U(r,o);g[h]=Qe(p);for(let w of g[h])e.insertBefore(w,C);C=g[h][g[h].length-1]?.nextSibling??null}}return g}function Rn(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 Mn(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(!Rn(e[o],n[o]))return!1}else if(e[o]!==n[o])return!1}return!0}var Me="http://www.w3.org/2000/svg",Ne=new Set(["svg","path","circle","line","rect","text","g","polyline","polygon","ellipse","defs","use","clipPath","mask","linearGradient","radialGradient","stop","tspan"]);function en(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 On(e,n);let t=e;if(t.type===F)return Y(t,n),null;if(t.type===K){let a=document.createDocumentFragment(),d=t.props?.children==null?[]:Array.isArray(t.props.children)?t.props.children:[t.props.children];for(let l of d){let c=U(l,n);c!=null&&a.appendChild(c)}return t._childNodes=Array.from(a.childNodes),a}if(typeof t.type=="function")return Ln(t.type,t.props,t,n);let o=t.type,i=Ne.has(o)?document.createElementNS(Me,o):document.createElement(o);t.el=i;let s;for(let[a,d]of Object.entries(t.props??{}))a==="children"||a==="key"||a==="value"||a==="innerHTML"||Ze(i,a,d);if("value"in(t.props??{})&&i instanceof HTMLSelectElement?s=t.props.value:"value"in(t.props??{})&&Ze(i,"value",t.props.value),"innerHTML"in(t.props??{}))i.innerHTML=String(t.props.innerHTML??"");else{let a=Le(t.props?.children);for(let d of a){let l=U(d,n);if(l!=null&&(i.appendChild(l),d&&typeof d=="object"&&typeof d.type=="function")){let c=d;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 Nn(e){let n=e.ui;n&&typeof n.render=="function"&&n.render(["_wf_root"])}function Re(e,n,t,o){let i;if(J(e)){if(i=$e(e),!i)return _e(e,o).promise.then(()=>Nn(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 Ln(e,n,t,o){o.ui=o.ui??{},t._id||(t._id=Z(),V.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=Re(e,n,t,i)}catch(d){let l=o.ui?._errorHandler;l?(l(d),s=null):(console.error(`[weifuwu] Component render error in <${e.name||"anonymous"}> (id: ${t._id??"?"}, phase: mount)`,d),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 On(e,n){let t=document.createDocumentFragment();for(let o of e){let i=U(o,n);i!=null&&t.appendChild(i)}return t}function Wn(){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 Y(e,n){let t=Wn(),o=document.createElement("div");o.style.pointerEvents="auto",t.appendChild(o),e._remoteEl=o;let i=ne(e.props?.children);e._child=i;for(let s of i){let a=U(s,n);a!=null&&o.appendChild(a)}}function te(e,n,t){let o=e?._remoteEl;if(n._remoteEl=o,!o){Y(n,t);return}let i=ne(n.props?.children),s=e._child||[];n._child=i,ue(s,i);let a=ee(Array.from(o.childNodes),s);ce(o,s,i,t,a,a[0]?.[0]??null)}function Le(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,n,t){if(n!=="ref")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&&(i.startsWith("--")?o.setProperty(i,String(s)):o[i]=typeof s=="number"?s+"px":String(s))}}else n.startsWith("on")&&typeof t=="function"?e.addEventListener(n.slice(2).toLowerCase(),t):n==="draggable"?e.setAttribute("draggable",t?"true":"false"):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 Vn(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 Oe(e){e.node=e.node?e.node.nextSibling:null}function Hn(e,n){e.node&&e.node.parentNode?e.node.parentNode.insertBefore(n,e.node):e.parent.appendChild(n)}function In(e,n){e.node&&e.node.parentNode?(e.node.parentNode.replaceChild(n,e.node),Oe(e)):e.parent.appendChild(n)}async function oe(e,n,t){if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number"){let d=String(e);if(t.node&&t.node.nodeType===3)return t.node.textContent!==d&&(t.node.textContent=d),Oe(t),t.node;let l=document.createTextNode(d);return Hn(t,l),l}if(Array.isArray(e)){let d=null;for(let l of e){let c=await oe(l,n,t);c!=null&&!d&&(d=c)}return d}let o=e;if(o.type===F||o.type===K){let d=o.props?.children,l=d==null?[]:Array.isArray(d)?d:[d],c=null;for(let m of l){let g=await oe(m,n,t);g!=null&&!c&&(c=g)}return c}if(typeof o.type=="function")return Dn(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,Oe(t)):(a=Ne.has(i)?document.createElementNS(Me,i):document.createElement(i),In(t,a)),o.el=a,ke(a,null,s),!("innerHTML"in s)){let d={parent:a,node:a.firstChild},l=Le(s.children);for(let c of l){let m=await oe(c,n,d);if(m!=null&&m.parentNode!==a&&a.appendChild(m),c&&typeof c=="object"&&typeof c.type=="function"){let g=c;g._parentNode||(g._parentNode=a,g._refNode=m)}}for(;d.node;){let c=d.node;d.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 Dn(e,n,t){n.ui=n.ui??{},e._id||(e._id=Z(),V.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 d;J(i)?d=await Ke(i,o):d=i;let l=d(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(d){let l=n.ui?._errorHandler;l?(l(d),s=null):(console.error(`[weifuwu] Component hydration error in <${i.name||"anonymous"}> (id: ${e._id??"?"})`,d),s=null)}if(s==null)return e._child=null,null;e._child=s;let a=await oe(s,o,t);return e._refNode||(e._refNode=a),a}async function We(e,n,t){let o={parent:e,node:e.firstChild};for(await oe(n,t,o);o.node;){let i=o.node;o.node=i.nextSibling,i.parentNode?.removeChild(i)}}var de=0,nn="",tn="",on="",rn="",fe=0;function sn(){return typeof window<"u"&&typeof document<"u"}function Ve(){if(de++,de>1||!sn())return;fe=window.scrollY;let e=document.body;nn=e.style.overflow,tn=e.style.position,on=e.style.top,rn=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=`-${fe}px`,e.style.width="100%")}function He(){if(de--,de>0||!sn())return;let e=document.body;e.style.overflow=nn,e.style.position=tn,e.style.top=on,e.style.width=rn,fe>0&&window.scrollTo(0,fe)}var Un='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function pe(e){let n=e.querySelectorAll(Un);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 me(e){let n=new WeakMap,t=new Set,o=s=>{if(s===null||typeof s!="object")return s;if(s instanceof Set||s instanceof Map){if(n.has(s))return n.get(s);let d=s instanceof Set?new Set(["add","delete","clear"]):new Set(["set","delete","clear"]),l=new Proxy(s,{get(c,m){let g=Reflect.get(c,m);return typeof g=="function"?d.has(String(m))?(...P)=>{let C=g.apply(c,P);e();for(let h of t)h();return C}:g.bind(c):g},set(c,m,g){Reflect.set(c,m,g),e();for(let P of t)P();return!0}});return n.set(s,l),l}if(s instanceof Date||s instanceof RegExp)return s;if(n.has(s))return n.get(s);let a=new Proxy(s,{set(d,l,c){if(Reflect.get(d,l)===c)return!0;Reflect.set(d,l,c),e();for(let g of t)g();return!0},get(d,l){let c=Reflect.get(d,l);return typeof c=="object"&&c!==null?o(c):c},deleteProperty(d,l){if(Reflect.has(d,l)){Reflect.deleteProperty(d,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 Ie(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??Kn(),a=t?.record!==!1,d=[],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(m){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:m instanceof Error?m.message:String(m)});return}if(!c.ok){t?.onError?.({code:Bn(c.status),message:`HTTP ${c.status} ${c.statusText}`});return}try{for await(let{name:m,data:g}of qn(c.body)){if(o.signal.aborted)return;Fn(d,{name:m,data:g},a),jn(m,g,t??{})}}catch(m){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:m instanceof Error?m.message:String(m)})}})();return{abort:()=>o.abort(),done:l,traceId:s,events:d}}function jn(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*qn(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(`
|
|
1
|
+
var $e="__wfAsyncComponent";function Tn(e){let n=e;return n[$e]=!0,n}function J(e){return typeof e=="function"&&e?.[$e]===!0}var $=Symbol("Fragment"),B=Symbol("Portal");function Ne(e,n,t){return{type:e,props:Ke(n),key:t??void 0}}var En=Ne;function Pn(e,n,t){return Ne(e,n,t)}function Nn(e,n,...t){let o=Ke(n??{});return t.length>0&&(o.children=t.length===1?t[0]:t),{type:e,props:o,key:n?.key??void 0}}function Ke(e){if(!e)return{};let n={};for(let t of Object.keys(e))t!=="key"&&(n[t]=e[t]);return n}function _e(e,n){return{type:B,props:{children:e,portalKey:n},key:n??void 0,_placement:"remote"}}var _n=0,H=new Map,Q=[];function F(e){return Q.push(e),()=>{let n=Q.indexOf(e);n>=0&&Q.splice(n,1)}}var de=new WeakMap;function Z(){de=new WeakMap}function Ae(e,n){let t=de.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}),de.set(e,o),o}async function ze(e,n){return Ae(e,n).promise}function Ge(e){return de.get(e)?.resolved}function ke(e,n,t,o){try{e(n)}catch(i){console.error(`[weifuwu] ref ${t} error in <${o??"anonymous"}>`,i)}}function An(e){let n=e._child;if(n!=null)if(Array.isArray(n))for(let t of n)t&&typeof t=="object"&&W(t);else typeof n=="object"&&W(n)}function W(e){if(e==null||typeof e!="object")return;let n=e;if(n._id){if(n._customId&&H.delete(n._customId),H.delete(n._id),Q.length>0){let t=[...Q];for(let o of t)o(n._id);if(n._customId)for(let o of t)o(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"&&W(t);else W(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"&&W(o)}typeof n.props?.ref=="function"&&ke(n.props.ref,null,"cleanup"),n._remoteEl&&(An(n),n._remoteEl.remove(),n._remoteEl=void 0)}function ee(){return`_wf_${_n++}`}var Ye=new WeakMap;function kn(e){let n=Ye.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 })")),Ye.set(e,n)}function z(e,n,t,o,i){if(t==null){if(o==null)return null;let a=D(o,i);return a==null?null:(n&&n.parentNode?n.parentNode.insertBefore(a,n):e.appendChild(a),a)}if(o==null)return n?(W(t),n.remove()):W(t),null;let l=Je(t),s=Je(o);if(l!==s){W(t);let a=D(o,i);return a==null?null:(n?.parentNode&&n.parentNode.replaceChild(a,n),a)}if(s==="text")return n&&n.textContent!==String(o)&&(n.textContent=String(o)),n;let c=o,d=t;if(typeof c.type=="function"){let a=c.type;d._render&&d.type===c.type&&(c._render=d._render,c._id=d._id,c._id&&H.set(c._id,c)),c._parentNode=e,c._refNode=n;let g=Object.create(i);g.ui=Object.create(i.ui);let m=g.ui;if(m._selfId=c._id,m._selfVNode=c,c._ctxVersion=d._ctxVersion??m._ctxVersion??0,d._render&&d.type===c.type&&Mn(d.props,c.props)&&!m._dirtySet?.has(d._id)&&c._ctxVersion===m._ctxVersion)return c._child=d._child,n;m._dirtySet?.delete(d._id);let b;try{typeof c._render=="function"?b=c._render(c.props):b=Me(a,c.props,c,g)}catch(w){let r=i.ui?._errorHandler;r?(r(w),b=null):(console.error(`[weifuwu] Component render error in <${a?.name||"anonymous"}> (id: ${d._id??"?"}, phase: update)`,w),b=null)}let C=d._child;c._child=b;let h=z(e,n,C,b,g);return h||(c._refNode=null),h}if(c.type===$){let a=d._childNodes,g=Ze(e,d,c,i,a);return c._childNodes=g,n}if(typeof c.type=="string"){if(n&&n.nodeType===1){let a=d.props?.ref,g=c.props?.ref;a!==g&&(typeof g=="function"&&g(n),typeof a=="function"&&typeof g=="function"&&kn(n)),Re(n,d.props,c.props),Ze(n,d,c,i)}else if(n){W(t);let a=D(o,i);return a==null?null:(n.parentNode?.replaceChild(a,n),a)}return n}if(c.type===B)return oe(d,c,i),null;if(Array.isArray(o)){let a=Array.isArray(t)?t:[];ce(a,o);let g=Array.from(e.childNodes),m=n?g.indexOf(n):-1,b=m>=0?ne(g.slice(m),a):ne(g,a);return fe(e,a,o,i,b,n),n}return n}var Xe=new Map;function Sn(e){let n=Xe.get(e);return n||(n=`fn:${e.name||"anon"}`,Xe.set(e,n)),n}function Je(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"?Sn(n.type):n.type===$?"fragment":n.type===B?"portal":typeof n.type=="string"?"tag:"+n.type:"unknown"}function Re(e,n,t){let o=n?Object.keys(n).filter(s=>s!=="children"&&s!=="key"&&s!=="innerHTML"):[],i=t?Object.keys(t).filter(s=>s!=="children"&&s!=="key"&&s!=="innerHTML"):[],l=new Set(i);for(let s of o){if(!n)break;if(!l.has(s)){if(s==="ref")continue;s.startsWith("on")&&typeof n[s]=="function"?e.removeEventListener(s.slice(2).toLowerCase(),n[s]):s==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value="":e.removeAttribute(s==="className"?"class":s)}}for(let s of i){if(s==="ref")continue;let c=n?.[s],d=t?.[s];if(s==="innerHTML")d!==c&&(e.innerHTML=String(d??""));else if(d!==c)if(s==="class"||s==="className")e instanceof SVGElement?e.setAttribute("class",Qe(d)):e.className=Qe(d);else if(s==="style"&&typeof d=="object"&&d!==null){let a=e.style,g=d;for(let m of Object.keys(g)){let b=g[m];b==null?m.startsWith("--")?a.removeProperty(m):a[m]="":m.startsWith("--")?a.setProperty(m,String(b)):a[m]=typeof b=="number"?b+"px":String(b)}}else if(s.startsWith("on")&&typeof d=="function"){let a=s.slice(2).toLowerCase();typeof c=="function"&&e.removeEventListener(a,c),e.addEventListener(a,d)}else s==="draggable"?e.setAttribute("draggable",d?"true":"false"):s==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value=String(d??""):d===!0?e.setAttribute(s,""):d!=null&&d!==!1?e.setAttribute(s,String(d)):s==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value="":e.removeAttribute(s)}}function Qe(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 Se(e){if(!(e==null||typeof e!="object"))return Array.isArray(e)?void 0:e.key}function ce(e,n){if(!n.some(o=>o&&typeof o=="object"&&!Array.isArray(o)&&o.key!==void 0)){for(let o=0;o<n.length;o++){let i=n[o];i&&typeof i=="object"&&!Array.isArray(i)&&(i.key=String(o))}for(let o=0;o<e.length;o++){let i=e[o];i&&typeof i=="object"&&!Array.isArray(i)&&(i.key=String(o))}}}function ne(e,n){let t=[],o=0;for(let i of n){if(i==null||typeof i=="boolean"){t.push(null);continue}let l=i;if(l.type===B){t.push(null);continue}if(l.type===$){let s=l._childNodes;Array.isArray(s)&&s.length>0?(t.push(s.slice()),o+=s.length):(t.push(e[o]?[e[o]]:null),o+=1)}else if(typeof l.type=="function")if(l._render){let s=l._childNodes??l._refNode;s==null?t.push(null):Array.isArray(s)?(t.push(s.slice()),o+=s.length):(t.push([s]),o+=1)}else 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 Ze(e,n,t,o,i){let l=te(n.props?.children),s=te(t.props?.children);ce(l,s);let c=i??Array.from(e.childNodes),d=ne(c,l),a=fe(e,l,s,o,d,i?.[0]??null),g=[];for(let m of a)m&&m.length>0&&g.push(...m);return g}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 en(e){return e==null?[]:e instanceof DocumentFragment?Array.from(e.childNodes):[e]}function fe(e,n,t,o,i=[],l=null){if(!t.some(h=>h&&typeof h=="object"&&!Array.isArray(h)&&h.key!==void 0&&h._placement!=="remote")){let h=Math.max(n.length,t.length);for(let w=0;w<h;w++){let r=w<n.length?n[w]:null,u=w<t.length?t[w]:null;if(u==null){if(r!=null){W(r);for(let f of i[w]??[])f.remove()}}else if(r==null){let f=D(u,o);if(f!=null){let p=null;for(let y=w+1;y<i.length;y++){let v=i[y]?.[0];if(v&&v.parentNode===e){p=v;break}}p?e.insertBefore(f,p):e.appendChild(f)}}else{let f=i[w]?.[0]??null;z(e,f,r,u,o)}}return[]}for(let h=0;h<n.length;h++){let w=n[h];if(!(w==null||typeof w=="boolean")&&Se(w)===void 0)for(let r of i[h]??[])r.remove()}let c=new Map,d=0;for(let h=0;h<n.length;h++){let w=Se(n[h]);w!==void 0&&c.set(w,{vnode:n[h],nodes:i[h]??[],index:d++})}let a=t.map(h=>Se(h)),g=new Set(a);for(let h of[...c.keys()])if(!g.has(h)){let w=c.get(h);W(w.vnode);for(let r of w.nodes)r?.remove();c.delete(h)}let m=new Array(t.length).fill(null),b=-1,C=l&&l.parentNode===e?l:e.firstChild;for(let h=0;h<t.length;h++){let w=a[h],r=t[h],u=w!==void 0?c.get(w):void 0,f=r&&typeof r=="object"&&r._placement==="remote";if(u)if(u.nodes.length>0){if(u.index<b)for(let y of u.nodes)e.insertBefore(y,C);b=Math.max(b,u.index),z(e,u.nodes[0],u.vnode,r,o),m[h]=r._childNodes??u.nodes.filter(y=>y.parentNode===e),C=m[h][m[h].length-1]?.nextSibling??null}else if(f)oe(u.vnode,r,o),m[h]=[];else{let p=z(e,null,u.vnode,r,o);m[h]=en(p);for(let v of m[h])e.insertBefore(v,C);C=m[h][m[h].length-1]?.nextSibling??null}else if(f)Y(r,o),m[h]=[];else{let p=D(r,o);m[h]=en(p);for(let v of m[h])e.insertBefore(v,C);C=m[h][m[h].length-1]?.nextSibling??null}}return m}function Rn(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 Mn(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(!Rn(e[o],n[o]))return!1}else if(e[o]!==n[o])return!1}return!0}var Le="http://www.w3.org/2000/svg",Ve=new Set(["svg","path","circle","line","rect","text","g","polyline","polygon","ellipse","defs","use","clipPath","mask","linearGradient","radialGradient","stop","tspan"]);function tn(e,n){return D(e,n)}function D(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 On(e,n);let t=e;if(t.type===B)return Y(t,n),null;if(t.type===$){let s=document.createDocumentFragment(),c=t.props?.children==null?[]:Array.isArray(t.props.children)?t.props.children:[t.props.children];for(let d of c){let a=D(d,n);a!=null&&s.appendChild(a)}return t._childNodes=Array.from(s.childNodes),s}if(typeof t.type=="function")return Vn(t.type,t.props,t,n);let o=t.type,i=Ve.has(o)?document.createElementNS(Le,o):document.createElement(o);t.el=i;let l;for(let[s,c]of Object.entries(t.props??{}))s==="children"||s==="key"||s==="value"||s==="innerHTML"||nn(i,s,c);if("value"in(t.props??{})&&i instanceof HTMLSelectElement?l=t.props.value:"value"in(t.props??{})&&nn(i,"value",t.props.value),"innerHTML"in(t.props??{}))i.innerHTML=String(t.props.innerHTML??"");else{let s=Oe(t.props?.children);for(let c of s){let d=D(c,n);if(d!=null&&(i.appendChild(d),c&&typeof c=="object"&&typeof c.type=="function")){let a=c;a._parentNode||(a._parentNode=i,a._refNode=d)}}}return l!==void 0&&(i.value=String(l)),typeof t.props?.ref=="function"&&ke(t.props.ref,i,"mount",o),i}function Ln(e){let n=e.ui;n&&typeof n.render=="function"&&n.render(["_wf_root"])}function Me(e,n,t,o){let i;if(J(e)){if(i=Ge(e),!i)return Ae(e,o).promise.then(()=>Ln(o),()=>{}),null}else i=e;o.ui?.setMounting?.(!0);let l;try{l=i(n,o)}finally{o.ui?.endMounting?.()}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 Vn(e,n,t,o){t._id||(t._id=ee(),H.set(t._id,t));let i=Object.create(o);i.ui=Object.create(o.ui);let l=i.ui;l._selfId=t._id,l._selfVNode=t,t._ctxVersion=l._ctxVersion??0;let s;try{s=Me(e,n,t,i)}catch(d){let a=o.ui?._errorHandler;a?(a(d),s=null):(console.error(`[weifuwu] Component render error in <${e.name||"anonymous"}> (id: ${t._id??"?"}, phase: mount)`,d),s=null)}if(s==null){if(t._child=null,i.ui?._errorHandler){let a=document.createComment("wf-empty");return t._refNode=a,a}return null}t._child=s;let c=D(s,i);return t._refNode||(t._refNode=c),c}function On(e,n){let t=document.createDocumentFragment();for(let o of e){let i=D(o,n);i!=null&&t.appendChild(i)}return t}function Wn(){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 Y(e,n){let t=Wn(),o=document.createElement("div");o.style.pointerEvents="auto",t.appendChild(o),e._remoteEl=o;let i=te(e.props?.children);e._child=i;for(let l of i){let s=D(l,n);s!=null&&o.appendChild(s)}}function oe(e,n,t){let o=e?._remoteEl;if(n._remoteEl=o,!o){Y(n,t);return}let i=te(n.props?.children),l=e._child||[];n._child=i,ce(l,i);let s=ne(Array.from(o.childNodes),l);fe(o,l,i,t,s,s[0]?.[0]??null)}function Oe(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 nn(e,n,t){if(n!=="ref")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 l=t[i];l!=null&&(i.startsWith("--")?o.setProperty(i,String(l)):o[i]=typeof l=="number"?l+"px":String(l))}}else n.startsWith("on")&&typeof t=="function"?e.addEventListener(n.slice(2).toLowerCase(),t):n==="draggable"?e.setAttribute("draggable",t?"true":"false"):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 In(e,n,t){e.innerHTML="";let o=D(n,t);o instanceof Node&&e.appendChild(o)}function We(e){e.node=e.node?e.node.nextSibling:null}function Hn(e,n){e.node&&e.node.parentNode?e.node.parentNode.insertBefore(n,e.node):e.parent.appendChild(n)}function Un(e,n){e.node&&e.node.parentNode?(e.node.parentNode.replaceChild(n,e.node),We(e)):e.parent.appendChild(n)}async function re(e,n,t){if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number"){let c=String(e);if(t.node&&t.node.nodeType===3)return t.node.textContent!==c&&(t.node.textContent=c),We(t),t.node;let d=document.createTextNode(c);return Hn(t,d),d}if(Array.isArray(e)){let c=null;for(let d of e){let a=await re(d,n,t);a!=null&&!c&&(c=a)}return c}let o=e;if(o.type===B||o.type===$){let c=o.props?.children,d=c==null?[]:Array.isArray(c)?c:[c],a=null;for(let g of d){let m=await re(g,n,t);m!=null&&!a&&(a=m)}return a}if(typeof o.type=="function")return Dn(o,n,t);let i=o.type,l=o.props??{},s;if(t.node&&t.node.nodeType===1&&t.node.tagName.toLowerCase()===i.toLowerCase()?(s=t.node,We(t)):(s=Ve.has(i)?document.createElementNS(Le,i):document.createElement(i),Un(t,s)),o.el=s,Re(s,null,l),!("innerHTML"in l)){let c={parent:s,node:s.firstChild},d=Oe(l.children);for(let a of d){let g=await re(a,n,c);if(g!=null&&g.parentNode!==s&&s.appendChild(g),a&&typeof a=="object"&&typeof a.type=="function"){let m=a;m._parentNode||(m._parentNode=s,m._refNode=g)}}for(;c.node;){let a=c.node;c.node=a.nextSibling,a.parentNode?.removeChild(a)}}return"value"in l&&s instanceof HTMLSelectElement&&(s.value=String(l.value??"")),typeof l.ref=="function"&&l.ref(s),s}async function Dn(e,n,t){e._id||(e._id=ee(),H.set(e._id,e));let o=Object.create(n);o.ui=Object.create(n.ui);let i=o.ui;i._selfId=e._id,i._selfVNode=e,e._ctxVersion=i._ctxVersion??0;let l=e.type,s;try{let d;J(l)?d=await ze(l,o):d=l;let a=d(e.props??{},o);if(typeof a!="function")throw new Error(`Component ${l.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);e._render=a,s=a(e.props??{})}catch(d){let a=n.ui?._errorHandler;a?(a(d),s=null):(console.error(`[weifuwu] Component hydration error in <${l.name||"anonymous"}> (id: ${e._id??"?"})`,d),s=null)}if(s==null)return e._child=null,null;e._child=s;let c=await re(s,o,t);return e._refNode||(e._refNode=c),c}async function Ie(e,n,t){let o={parent:e,node:e.firstChild};for(await re(n,t,o);o.node;){let i=o.node;o.node=i.nextSibling,i.parentNode?.removeChild(i)}}var ie=0,on="",rn="",sn="",ln="",pe=0;function an(){return typeof window<"u"&&typeof document<"u"}function He(){if(ie++,ie>1||!an())return;pe=window.scrollY;let e=document.body;on=e.style.overflow,rn=e.style.position,sn=e.style.top,ln=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=`-${pe}px`,e.style.width="100%")}function Ue(){if(ie===0||(ie--,ie>0)||!an())return;let e=document.body;e.style.overflow=on,e.style.position=rn,e.style.top=sn,e.style.width=ln,pe>0&&window.scrollTo(0,pe)}var jn='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function me(e){let n=e.querySelectorAll(jn);if(n.length===0)return()=>{};let t=n[0],o=n[n.length-1],i=s=>{s.key==="Tab"&&(s.shiftKey&&document.activeElement===t?(s.preventDefault(),o.focus()):!s.shiftKey&&document.activeElement===o&&(s.preventDefault(),t.focus()))},l=document.activeElement;return queueMicrotask(()=>{t.focus()}),e.addEventListener("keydown",i),()=>{e.removeEventListener("keydown",i),l?.focus()}}function ge(e){let n=new WeakMap,t=new Set,o=l=>{if(l===null||typeof l!="object")return l;if(l instanceof Set||l instanceof Map){if(n.has(l))return n.get(l);let c=l instanceof Set?new Set(["add","delete","clear"]):new Set(["set","delete","clear"]),d=new Proxy(l,{get(a,g){let m=Reflect.get(a,g);return typeof m=="function"?c.has(String(g))?(...b)=>{let C=m.apply(a,b);e();for(let h of t)h();return C}:m.bind(a):m},set(a,g,m){Reflect.set(a,g,m),e();for(let b of t)b();return!0}});return n.set(l,d),d}if(l instanceof Date||l instanceof RegExp)return l;if(n.has(l))return n.get(l);let s=new Proxy(l,{set(c,d,a){if(Reflect.get(c,d)===a)return!0;Reflect.set(c,d,a),e();for(let m of t)m();return!0},get(c,d){let a=Reflect.get(c,d);return typeof a=="object"&&a!==null?o(a):a},deleteProperty(c,d){if(Reflect.has(c,d)){Reflect.deleteProperty(c,d),e();for(let a of t)a()}return!0}});return n.set(l,s),s},i=o({});return Object.defineProperty(i,"__watch",{value:l=>(t.add(l),()=>{t.delete(l)}),writable:!1,enumerable:!1}),i}function De(e,n,t){let o=new AbortController,i=t?.signal;i&&(i.aborted?o.abort():i.addEventListener("abort",()=>o.abort(),{once:!0}));let l=t?.traceId??Kn(),s=t?.record!==!1,c=[],d=(async()=>{let a;try{a=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(g){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:g instanceof Error?g.message:String(g)});return}if(!a.ok){t?.onError?.({code:$n(a.status),message:`HTTP ${a.status} ${a.statusText}`});return}try{for await(let{name:g,data:m}of Fn(a.body)){if(o.signal.aborted)return;Bn(c,{name:g,data:m},s),qn(g,m,t??{})}}catch(g){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:g instanceof Error?g.message:String(g)})}})();return{abort:()=>o.abort(),done:d,traceId:l,events:c}}function qn(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*Fn(e){let n=e.getReader(),t=new TextDecoder,o="";try{for(;;){let{done:i,value:l}=await n.read();if(i)break;o+=t.decode(l,{stream:!0});let s=o.split(`
|
|
2
2
|
|
|
3
|
-
`);o=
|
|
4
|
-
`))m.startsWith("event: ")?l=m.slice(7):m.startsWith("data: ")&&(c+=m.slice(6));if(c)try{yield{name:l,data:JSON.parse(c)}}catch{}}}}finally{n.releaseLock()}}function Fn(e,n,t){t&&(e.length>=1e3&&e.shift(),e.push(n))}function Bn(e){return e===401||e===403?"auth_failed":e===429?"rate_limited":e>=500?"provider_error":"invalid_request"}function Kn(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`trace-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function an(e){return e.map(n=>({role:n.role,content:n.content}))}function De(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`msg-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function ln(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,h,v){let r=i();switch(C){case"wf:token":r&&(r.content+=h.text);break;case"wf:tool_call":{r&&(r.toolCalls||(r.toolCalls=[]),r.toolCalls.push({call:h,status:"running"}));break}case"wf:tool_progress":{let u=h,f=r?.toolCalls?.find(p=>p.call.id===u.toolCallId);f&&(f.progress=u);break}case"wf:tool_result":{let u=h,f=r?.toolCalls?.find(p=>p.call.id===u.id);f&&(f.result=u,f.status=u.ok?"ok":"error");break}case"wf:approval_request":r&&(r.approval=h);break;case"wf:usage":r&&(r.usage=h);break;case"wf:step":e.step=h;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=h,r.approval=void 0),e.error=h,e.streaming=!1,e.step=null;break;default:v?.(C,h);break}}function a(){let C=t.body?t.body(e.messages):{messages:an(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 h=i();h&&o?.traceId&&(h.id=o.traceId)}function d(){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:De(),role:"user",content:C,status:"done"},{id:De(),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 h=e.messages.length-1;h>=0;h--)if(e.messages[h].role==="user"){C=h;break}C!==-1&&(e.messages.splice(C+1),e.error=null,e.usage=null,e.step=null,e.messages.push({id:De(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),a())}function m(){o?.abort(),e.messages=[],e.input="",e.streaming=!1,e.error=null,e.usage=null,e.step=null}async function g(C,h){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:h}),signal:t.signal})}catch(u){if(t.signal?.aborted)return;e.error={code:"provider_error",message:u instanceof Error?u.message:String(u)}}}function P(){o?.abort(),o=null}return{send:d,stop:l,retry:c,clear:m,approve:g,dispose:P}}function ye(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 $n(e,n="bottom",t=6,o=!0){return ye(e.getBoundingClientRect(),n,t,o)}function ge(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,d=e.left-s,l={top:o.top+a,bottom:o.bottom+a,left:o.left+d,right:o.right+d},c=window.innerWidth,m=window.innerHeight,g=e.top,P=e.left;return l.bottom>m-t&&(g=Math.max(t,g-(l.bottom-(m-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 he=new Set,re=new Map,ve=new Map,ie=new Map;function un(e){let{ctx:n,renderByIds:t,getSelfId:o,dirtyBatch:i,dirtySet:s,mediaRegistry:a,popupTrackers:d,scrollTrackers:l,schedulePopupRecompute:c,ensurePopupListeners:m,isRendering:g,isMounting:P,setMounting:C,endMounting:h}=e;return{_selfId:"_wf_root",_ctxVersion:0,_dirtySet:s,setMounting:C,endMounting:h,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 u=o(this);if(u)r=[u];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 u=o(this);if(u)r=[u];else return}for(let u of r)u&&(i.add(u),s.add(u));this._dirtyScheduled||(this._dirtyScheduled=!0,queueMicrotask(()=>{this._dirtyScheduled=!1;let u=[...i];i.clear(),u.length>0&&t(u)}))}},$:function(){let r=this;return Object.prototype.hasOwnProperty.call(r,"_$cache")||(r._$cache=me(()=>{let u=r._selfVNode?._id??o(r);u&&n.ui.dirty([u])})),r._$cache},useChat:function(r){let u=this.$(),f=ln(u,Ie,r);return Object.assign(u,{send:f.send,stop:f.stop,retry:f.retry,clear:f.clear,approve:f.approve,dispose:f.dispose}),u},useMedia:function(r,u){let p=`media:${o(this)}:${r}`;if(!a.has(p)){let y=window.matchMedia(r);u(y.matches);let w=T=>u(T.matches);y.addEventListener("change",w),a.set(p,{mql:y,handler:w})}},useBreakpoint:function(r,u){let f=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:u,w=`bp:${o(this)}`;function T(){for(let[x,M]of Object.entries(f))if(window.matchMedia(M).matches)return x;return Object.keys(f)[0]??""}if(!a.has(w)){p(T());let x=[];for(let M of Object.values(f)){let S=window.matchMedia(M),_=()=>p(T());S.addEventListener("change",_),x.push({mql:S,handler:_})}a.set(w,{mqls:x})}},usePopupPosition:function(r){let u=o(this),f={top:0,left:0,refresh:()=>{}};if(!u)return f;let p={pos:f,getEl:r.el,isOpen:r.isOpen,compute:r.compute,panel:r.panel,margin:r.margin??8};return d.set(u,p),m(),f.refresh=()=>{let y=p.getEl();if(!y)return;let w=y.getBoundingClientRect();if(w.width===0&&w.height===0)return;let T=p.compute(w);Object.assign(f,ge(T,p.panel?.(),p.margin))},f},useHoverCapable:function(){return typeof window<"u"&&!!window.matchMedia?.("(hover: hover)").matches},useStableRef:function(r,u){return p=>{p?r(p):u?.()}},useVisualViewport:function(){let r=o(this),u={height:window.innerHeight,offsetTop:0,keyboardOpen:!1},f=()=>{n.ui&&n.ui.dirty(r?[r]:void 0)},p=()=>{let w=window.visualViewport;u.height=w?.height??window.innerHeight,u.offsetTop=w?.offsetTop??0,u.keyboardOpen=u.height<window.innerHeight*.9,f()},y=window.visualViewport;return y?.addEventListener?(y.addEventListener("resize",p),y.addEventListener("scroll",p)):window.addEventListener("resize",p),r&&B(w=>{w===r&&(y?.removeEventListener?(y.removeEventListener("resize",p),y.removeEventListener("scroll",p)):window.removeEventListener("resize",p))}),u},usePopup:function(r){let u=o(this),f=this.useHoverCapable(),p=()=>typeof r.trigger=="function"?r.trigger():r.trigger,y=r.open!==void 0,w=()=>!!r.disabled?.(),T=()=>y?typeof r.open=="function"?!!r.open():!!r.open:r.isOpen(),x=E=>{w()||(y?r.onOpenChange?.(E):r.setOpen(E))},M=()=>{let E=r.placement;return typeof E=="function"?E():E??"bottom"},S=null,_=!1,b=n.ui.usePopupPosition({el:r.el,isOpen:()=>T(),compute:E=>{if(r.position){let L=r.position();return{top:L.y,left:L.x}}return ye(E,M(),r.gap??6,r.center!==!1)},panel:()=>S,margin:r.margin??8}),k=E=>{if(r.closeOnOutside===!1||!T())return;let L=E.target;if(!(L instanceof Node))return;let j=r.el();j&&j.contains(L)||S&&S.contains(L)||x(!1)},R=E=>{r.closeOnEscape!==!1&&(E.key!=="Escape"||!T()||x(!1))};document.addEventListener("mousedown",k),document.addEventListener("keydown",R),u&&B(E=>{E===u&&(document.removeEventListener("mousedown",k),document.removeEventListener("keydown",R))});let A={},q=E=>typeof E=="function"?E():E??0,N=()=>q(r.openDelay),I=()=>q(r.closeDelay),O,D,se=()=>{clearTimeout(O),clearTimeout(D),O=void 0,D=void 0},yn=E=>{if(w())return;let L=E.currentTarget,j=E.relatedTarget;L.contains(j)||(clearTimeout(D),D=void 0,O=setTimeout(()=>{O=void 0,x(!0)},N()))},gn=E=>{if(w())return;let L=E.currentTarget,j=E.relatedTarget;L.contains(j)||(clearTimeout(O),O=void 0,D=setTimeout(()=>{D=void 0,x(!1)},I()))},hn=()=>{w()||(clearTimeout(D),D=void 0,O=setTimeout(()=>{O=void 0,x(!0)},N()))},vn=()=>{w()||(clearTimeout(O),O=void 0,D=setTimeout(()=>{D=void 0,x(!1)},I()))},X=()=>p()==="hover";if(A.onMouseOver=E=>{X()&&yn(E)},A.onMouseOut=E=>{X()&&gn(E)},A.onClick=()=>{X()?f||x(!T()):p()==="click"&&x(!0)},A.onFocus=()=>{X()&&hn()},A.onBlur=()=>{X()&&vn()},p()==="longpress"){let E,L=0,j=0,$=()=>{clearTimeout(E),E=void 0};A.onPointerDown=H=>{w()||(L=H.clientX??0,j=H.clientY??0,$(),E=setTimeout(()=>{E=void 0,r.onTrigger?.({clientX:L,clientY:j}),x(!0)},r.longPressDuration??500))},A.onPointerUp=$,A.onPointerLeave=$,A.onPointerMove=H=>{let Te=Math.abs((H.clientX??0)-L),Ee=Math.abs((H.clientY??0)-j);(Te>10||Ee>10)&&$()},A.onContextMenu=H=>{H.preventDefault(),r.onTrigger?.({clientX:H.clientX??0,clientY:H.clientY??0}),x(!0)}}A.onKeyDown=E=>{E.key==="Escape"&&r.closeOnEscape!==!1&&x(!1)},u&&B(E=>{E===u&&se()});let wn=E=>{if(E){S=E;let L=()=>b.refresh();E.addEventListener("animationend",L,{once:!0})}else S=null},Ce=null,xe=null,bn=E=>{wn(E),xe&&xe(E)};return{get open(){return T()},setOpen:x,wrapProps:A,portal:(E,L="popover")=>{if(w())return null;if(!T())return _=!1,Ce=null,null;let $=r.el();(!_||$!==Ce)&&($?b.refresh():queueMicrotask(()=>{T()&&b.refresh()}),_=!0,Ce=$);let H=E.props??{};xe=H.ref??null;let Te=["wf-popup",H.class].filter(Boolean).join(" "),Ee={...H.style??{},position:"fixed",top:`${b.top}px`,left:`${b.left}px`,maxWidth:r.width!==void 0?`min(${r.width}px, calc(100vw - 32px))`:"calc(100vw - 32px)"},Cn={...E,props:{...H,class:Te,style:Ee,ref:bn}};return Se(Cn,L)},refresh:()=>b.refresh()}},useLongPress:function(r){let{onLongPress:u,duration:f=500}=r,p,y=0,w=0,T=null,x=()=>{clearTimeout(p),p=void 0};return{onPointerDown:M=>{y=M.clientX??0,w=M.clientY??0,T=M,x(),p=setTimeout(()=>{p=void 0,u(T)},f)},onPointerUp:x,onPointerLeave:x,onPointerMove:M=>{let S=Math.abs((M.clientX??0)-y),_=Math.abs((M.clientY??0)-w);(S>10||_>10)&&x()},onContextMenu:M=>{M.preventDefault(),u(M)}}},useInView:function(r){let u=o(this),f={isIn:!1,ready:!1,observe:x,refresh:M,disconnect:S},p=null,y=null,w=()=>{n.ui&&n.ui.dirty(u?[u]:void 0)};function T(){if(y?.disconnect(),y=null,!p)return;let _=typeof r.rootMargin=="function"?r.rootMargin():r.rootMargin,b=typeof r.threshold=="function"?r.threshold():r.threshold;y=new IntersectionObserver(k=>{let R=k[k.length-1];if(!R)return;let A=R.isIntersecting,q=A!==f.isIn,N=!f.ready;f.isIn=A,f.ready=!0,r.onChange?.(R,A),(q||N)&&w()},{root:r.root?r.root():null,rootMargin:_??"0px",threshold:b??0}),y.observe(p)}function x(_){p=_,_?T():(y?.disconnect(),y=null,f.isIn=!1)}function M(){T()}function S(){y?.disconnect(),y=null}return f},useScrollPosition:function(r){let u=o(this),f={y:0,refresh(){let y=p.getScroller();f.y=y instanceof Window?document.scrollingElement?.scrollTop??y.scrollY??0:y.scrollTop??0}},p={handle:f,getScroller:r.getScroller??(()=>window)};return u?(l.set(u,p),m(),f.refresh(),f):(f.refresh(),f)},useAsync:function(r){let u=o(this),f=me(()=>{n.ui&&n.ui.dirty(u?[u]:void 0)});f.loading=!0;let p=0,y=()=>{let w=++p;f.loading=!0,f.error=null,Promise.resolve().then(()=>r()).then(T=>{p===w&&(f.data=T,f.loading=!1)}).catch(T=>{p===w&&(f.error=T,f.loading=!1)})};return y(),f.reload=y,f},useControlled:function(r){let u=o(this),f=r.value!==void 0;f&&!r.onChange&&r.name&&(he.has(r.name)||(he.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)}`))),!f&&u&&!
|
|
6
|
-
\u975E\u53D7\u63A7\uFF1A\u53BB\u6389 open\uFF1B\u53D7\u63A7\uFF1A\u4F20\u5165 onOpenChange={(o) => setOpen(o)}`));let p=()=>f?!!r.open:u?ie.get(u)??!1:!1,y=()=>{u?n.ui?.dirty([u]):n.ui?.render()},w=T=>{if(f){r.onOpenChange?.(T);return}u&&ie.set(u,T),y()};return{get open(){return p()},setOpen:w,triggerProps:{onClick:()=>w(!0),onFocus:()=>{r.openOnFocus&&w(!0)}}}},usePresence:function(r){let u=o(this),f="closed",p,y=()=>{f="closed",n.ui&&(u?n.ui.dirty([u]):n.ui.render())};return{get phase(){return f},ref:T=>{T?p||(p=()=>{f==="exit"&&y()},T.addEventListener("animationend",p)):(T?.removeEventListener("animationend",p),p=void 0)},sync:T=>(T?f="open":f==="open"&&(f="exit"),f)}},useDialog:function(r){let u=o(this),f,p=null,y=this.usePresence(r);return{get phase(){return y.phase},rootRef:x=>{x?(Ve(),p&&(f=pe(p)),y.ref(x)):(He(),f?.(),y.ref(null))},panelRef:x=>{p=x,x&&!f&&(f=pe(x))},sync:x=>y.sync(x)}},useGlobalKey:function(r){let u=o(this);return typeof window>"u"?()=>{}:(window.addEventListener("keydown",r),u&&B(f=>{f===u&&window.removeEventListener("keydown",r)}),()=>window.removeEventListener("keydown",r))},useDrag:function(r){let u=0,f=0,p=!1,y=x=>{p&&r.onMove(x,{x:x.clientX-u,y:x.clientY-f})},w=x=>{p&&(p=!1,window.removeEventListener("pointermove",y),window.removeEventListener("pointerup",w),r.onEnd?.(x))};return{onPointerDown:x=>{p||(x.preventDefault(),p=!0,u=x.clientX,f=x.clientY,window.addEventListener("pointermove",y),window.addEventListener("pointerup",w),r.onStart?.(x))}}},useDragDrop:function(r){let u={};r.onDrop&&(u.onDrop=p=>{p.preventDefault(),r.onDrop(p)}),r.onDragOver&&(u.onDragOver=p=>{p.preventDefault(),r.onDragOver(p)}),r.onDragLeave&&(u.onDragLeave=p=>r.onDragLeave(p));let f={draggable:!0};if(r.onDragStart){let p=r.onDragStart;f.onDragStart=y=>{typeof document<"u"&&document.body.classList.add("wf-dragging"),p(y)}}if(r.onDragEnd){let p=r.onDragEnd;f.onDragEnd=y=>{typeof document<"u"&&document.body.classList.remove("wf-dragging"),p(y)}}return{dropProps:u,dragProps:f}},useReducedMotion:function(){return typeof window<"u"&&!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches},useAnimationEnd:function(r,u){let f=null,p=()=>{r(),u?.once&&f&&f.removeEventListener("animationend",p)};return w=>{w?(f=w,w.addEventListener("animationend",p)):f&&(f.removeEventListener("animationend",p),f=null)}},useTween:function(r,u){let f=o(this),p=this.useReducedMotion(),y=u?.duration??400,w=u?.ease==="linear"?b=>b:b=>1-Math.pow(1-b,3),T,x=r,M={value:p?r:0,reset:()=>{}},S=()=>{n.ui&&(f?n.ui.dirty([f]):n.ui.render())},_=b=>{if(x=b,p){M.value=b,S();return}if(b===M.value)return;T&&cancelAnimationFrame(T);let k=M.value,R=performance.now(),A=q=>{let N=Math.min(1,(q-R)/y);M.value=Math.round(k+(b-k)*w(N)),N<1?(T=requestAnimationFrame(A),S()):(T=void 0,S())};T=requestAnimationFrame(A)};return M.reset=b=>{b===x&&T||_(b)},queueMicrotask(()=>_(r)),M},selfId:function(r){if(typeof r!="string"||!r)throw new Error(`[weifuwu] selfId requires a non-empty string, got ${typeof r}`);if(V.has(r))throw new Error(`[weifuwu] Duplicate component ID: "${r}". Each component must have a unique custom ID.`);let u=this._selfVNode;u&&(u._customId=r,V.set(r,u))}}}function cn(){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,queryCommandState:e=>typeof document<"u"?document.queryCommandState(e):!1,queryCommandValue:e=>typeof document<"u"?document.queryCommandValue(e):"",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 zn(){let e=[],n={},t=null,o=null,i=null,s=!1,a=!1,d=[];function l(S){d.push(a),a=S}function c(){a=d.pop()??!1}let m=new Set,g=!1,P=new Map;function C(S){let _=P.get(S);_&&(_.mql&&_.handler&&_.mql.removeEventListener("change",_.handler),_.mqls?.forEach(({mql:b,handler:k})=>b.removeEventListener("change",k)),P.delete(S))}let h=new Map,v=!1,r=0;function u(){v||(v=!0,window.addEventListener("scroll",y,{capture:!0,passive:!0}),window.addEventListener("resize",y))}function f(){v&&(window.removeEventListener("scroll",y,{capture:!0}),window.removeEventListener("resize",y),v=!1)}let p=new Map;function y(){r||(r=requestAnimationFrame(()=>{r=0;let S=[];for(let[_,b]of h){if(!b.isOpen())continue;let k=b.getEl();if(!k)continue;let R=k.getBoundingClientRect();if(R.width===0&&R.height===0)continue;let A=b.compute(R);Object.assign(b.pos,ge(A,b.panel?.(),b.margin)),S.push(_)}for(let[_,b]of p){let k=b.getScroller(),R=k instanceof Window?document.scrollingElement?.scrollTop??k.scrollY??0:k.scrollTop??0;R!==b.handle.y&&(b.handle.y=R,S.push(_))}S.length>0&&n.ui.render(S)}))}function w(S){if(!s){s=!0;for(let _ of S){let b=V.get(_);if(!b||!b._render)continue;n.ui._dirtySet?.delete(_);let k=b._child,R=b._render(b.props);if(b._child=R,k&&k._placement==="remote"||R&&R._placement==="remote"){k&&R?te(k,R,n):R?Y(R,n):k&&W(k);continue}if(!b._parentNode&&b._refNode&&(b._parentNode=b._refNode.parentNode),b._parentNode){let A=z(b._parentNode,b._refNode??null,k,R,n);A&&A!==b._refNode?b._refNode=A:A||(b._refNode=null)}}s=!1,T()}}function T(){let S=n.ui;m.size>0&&!S._dirtyScheduled&&(S._dirtyScheduled=!0,queueMicrotask(()=>{S._dirtyScheduled=!1;let _=[...m];m.clear(),_.length>0&&w(_)}))}function x(S){return S?._selfId??n.ui?._selfId}let M={get ctx(){return n},use(S){return e.push(S),M},async mount(S,_,b){o=_;for(let N of e)n=await N(n);let k=typeof S=="string"?document.querySelector(S):S;if(!k)throw new Error(`mount target not found: ${S}`);t=k;let R=!!b?.hydrate;R||(t.innerHTML="");let A=new Map,q=globalThis.__DATA__;if(q&&typeof q=="object")for(let[N,I]of Object.entries(q))A.set(N,{value:I});if(n.data={async get(N,I){let O=A.get(N);if(O&&"value"in O)return O.value;if(O?.promise)return O.promise;if(!I)return;let D=Promise.resolve().then(()=>I()).then(se=>(A.set(N,{value:se}),se));return A.set(N,{promise:D}),D},set(N,I){A.set(N,{value:I})},has(N){return A.has(N)}},B(N=>{for(let I of[...P.keys()])(I.startsWith(`media:${N}:`)||I===`bp:${N}`)&&C(I);h.delete(N),p.delete(N)}),n.browser=cn(),n.ui=un({ctx:n,renderByIds:w,getSelfId:x,dirtyBatch:m,dirtySet:new Set,mediaRegistry:P,popupTrackers:h,scrollTrackers:p,schedulePopupRecompute:y,ensurePopupListeners:u,destroyPopupListeners:f,isRendering:()=>s,isMounting:()=>a,setMounting:l,endMounting:c}),s=!0,i=Gn(_,n),i._id="_wf_root",i._parentNode=t,i._refNode=R?t.firstChild:null,V.set("_wf_root",i),R)await We(t,i,n);else{let N=en(i,n);N instanceof Node&&t.appendChild(N)}i._refNode=t.firstChild,s=!1,T()},destroy(){f(),h.clear(),p.clear();for(let S of[...P.keys()])C(S);V.clear(),t&&(t.innerHTML=""),t=null,n={}}};return M}function Gn(e,n){return{type:e,props:{},key:void 0}}function Yn(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 Xn(e){let n=[],t=e.replace(/:(\w+)/g,(o,i)=>(n.push(i),"([^/]+)")).replace(/\*/g,".*");return{re:new RegExp(`^${t}$`),keys:n}}function Ue(e,n="",t=[]){let o=[];for(let i of e){let s=Yn(n,i.path),{re:a,keys:d}=Xn(s),l=[...t,i];o.push({re:a,keys:d,def:i,chain:l}),i.children&&o.push(...Ue(i.children,s,l))}return o}function dn(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 fn(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 Jn(e){let n=Ue(e.routes),t=e.mode||"history";function o(){return t==="hash"?window.location.hash.replace(/^#/,"")||"/":window.location.pathname}function i(s){let a=dn(s,n);if(a){let d=a.chain[a.chain.length-1];return{path:a.def.path,params:fn(s,a),query:Object.fromEntries(new URLSearchParams(window.location.search)),chain:a.chain,title:d?.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(Q(),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 d=()=>{Q();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",d),t==="hash"&&window.addEventListener("hashchange",d),s}}function Qn(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 G(e,n){return Object.assign(Object.create(e),n)}function Zn(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 d=new Set,l=null,c=0,m=null,g=null,P=null,C=!1,h={isConnected:!1,onMessage:p=>(d.add(p),()=>{d.delete(p)}),send:p=>{l?.readyState===WebSocket.OPEN&&l.send(JSON.stringify(p))},_connect:v,close:()=>{C=!0,f(),l?.close(),l=null,h.isConnected=!1}};async function v(){if(!C)try{l=new WebSocket(n),l.onopen=()=>{h.isConnected=!0,c=0,r()},l.onmessage=p=>{try{let y=JSON.parse(p.data);for(let w of d)w(y)}catch{}u()},l.onclose=()=>{h.isConnected=!1,f(),!C&&c<o&&(c++,m=setTimeout(v,t*Math.min(c,5)))},l.onerror=()=>{l?.close()}}catch{C||(m=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 u(){clearTimeout(P)}function f(){clearInterval(g),clearTimeout(P),clearTimeout(m)}return v(),G(a,{ws:h})}}function et(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,d,l,c){let m=n.baseURL+d,g={method:a,headers:{...n.headers,...c?.headers}},P=e?.token?.();P&&!g.headers.Authorization&&(g.headers.Authorization=`Bearer ${P}`);let C=i>0,h=!!c?.signal,v=null,r=null;(C||h)&&(v=new AbortController,g.signal=v.signal,C&&(r=setTimeout(()=>v.abort(new Error("Request timed out")),i)),h&&c.signal.addEventListener("abort",()=>v.abort())),l!==void 0&&a!=="GET"&&a!=="HEAD"&&(g.body=JSON.stringify(l));let u={url:m,init:g};t&&(u=t(u));try{let f=await fetch(u.url,u.init);if(o)return o(f);if(!f.ok){let w=await f.text().catch(()=>"");throw new we(f.status,w||f.statusText)}let p=f.headers.get("content-length");if(f.status===204||p==="0")return;let y=(f.headers.get("content-type")||"").toLowerCase();return y.includes("application/json")||y.includes("json")?f.json():f.text()}finally{r&&clearTimeout(r)}}return a=>G(a,{api:{get:(l,c)=>s("GET",l,void 0,c),post:(l,c,m)=>s("POST",l,c,m),put:(l,c,m)=>s("PUT",l,c,m),patch:(l,c,m)=>s("PATCH",l,c,m),delete:(l,c)=>s("DELETE",l,void 0,c)}})}var we=class extends Error{status;body;constructor(n,t){super(`API Error ${n}: ${t}`),this.name="ApiError",this.status=n,this.body=t}};function nt(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 tt(e){let n=nt(e);return n?.exp?n.exp*1e3-3e4<Date.now():!0}function ot(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 d=n.getItem(t),l=n.getItem(o),c={token:d,user:l?JSON.parse(l):null,get isLoggedIn(){return this.token!==null},login(m,g,P){c.token=m,c.user=g,n.setItem(t,m),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(m){c.user=m,n.setItem(o,JSON.stringify(m))},async refresh(){let m=n.getItem(i);if(!m)return!1;try{let g=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:m})});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 d&&tt(d)&&c.refresh().catch(()=>{}),G(a,{auth:c})}}function rt(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 je={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 qe={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 be={"zh-CN":je,"en-US":qe};function pn(e){if(be[e])return e;let n=e.split("-")[0];return Object.keys(be).find(o=>o.startsWith(n))??"zh-CN"}function it(e={}){let{locale:n="zh-CN",messages:t={},components:o={}}=e,i=pn(n),s=be[i],a=mn(s,t,o),d={locale:i,t:(l,c)=>a.messages?.[l]??c??l,setLocale:()=>{},components:a.components};return l=>(l.i18n=d,d.setLocale=c=>{let m=pn(c),g=be[m];g&&(a=mn(g,t,o),d.locale=m,d.components=a.components,l?.ui?.bumpCtxVersion?.(),l?.ui?.render())},l)}function mn(e,n,t){return{messages:{...e?.messages,...n},components:st(e?.components??{},t)}}function st(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 at(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{we as ApiError,rt as ErrorBoundary,K as Fragment,F as Portal,Qn as RouteView,Ie as aiStream,at as animateOut,et as api,xn as asyncComponent,ot as auth,W as callRefCleanup,Q as clearAsyncComponentCache,$n as computeFixedPos,ye as computeFixedPosRect,zn as createApp,Se as createPortal,me as createReactiveState,qe as enUS,G as extendCtx,Pn as h,We as hydrateVNode,it as i18n,J as isAsyncComponent,Pe as jsx,En as jsxDEV,Tn as jsxs,Ve as lockScroll,Vn as mountVNode,z as patchValue,Jn as router,an as toChatMessages,pe as trapFocus,He as unlockScroll,Zn as ws,je as zhCN};
|
|
3
|
+
`);o=s.pop()??"";for(let c of s){let d="message",a="";for(let g of c.split(`
|
|
4
|
+
`))g.startsWith("event: ")?d=g.slice(7):g.startsWith("data: ")&&(a+=g.slice(6));if(a)try{yield{name:d,data:JSON.parse(a)}}catch{}}}}finally{n.releaseLock()}}function Bn(e,n,t){t&&(e.length>=1e3&&e.shift(),e.push(n))}function $n(e){return e===401||e===403?"auth_failed":e===429?"rate_limited":e>=500?"provider_error":"invalid_request"}function Kn(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`trace-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function un(e){return e.map(n=>({role:n.role,content:n.content}))}function je(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`msg-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function dn(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 l(C,h,w){let r=i();switch(C){case"wf:token":r&&(r.content+=h.text);break;case"wf:tool_call":{r&&(r.toolCalls||(r.toolCalls=[]),r.toolCalls.push({call:h,status:"running"}));break}case"wf:tool_progress":{let u=h,f=r?.toolCalls?.find(p=>p.call.id===u.toolCallId);f&&(f.progress=u);break}case"wf:tool_result":{let u=h,f=r?.toolCalls?.find(p=>p.call.id===u.id);f&&(f.result=u,f.status=u.ok?"ok":"error");break}case"wf:approval_request":r&&(r.approval=h);break;case"wf:usage":r&&(r.usage=h);break;case"wf:step":e.step=h;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=h,r.approval=void 0),e.error=h,e.streaming=!1,e.step=null;break;default:w?.(C,h);break}}function s(){let C=t.body?t.body(e.messages):{messages:un(e.messages)};o=n(t.url,C,{onToken:w=>l("wf:token",{text:w}),onToolCall:w=>l("wf:tool_call",w),onToolProgress:w=>l("wf:tool_progress",w),onToolResult:w=>l("wf:tool_result",w),onApproval:w=>l("wf:approval_request",w),onUsage:w=>l("wf:usage",w),onStep:w=>l("wf:step",w),onDone:w=>l("wf:done",w),onError:w=>l("wf:error",w),onEvent:(w,r)=>l(w,r,t.onEvent)},{signal:t.signal,headers:t.headers}),e.streaming=!0;let h=i();h&&o?.traceId&&(h.id=o.traceId)}function c(){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:je(),role:"user",content:C,status:"done"},{id:je(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),s())}function d(){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 a(){if(e.streaming)return;let C=-1;for(let h=e.messages.length-1;h>=0;h--)if(e.messages[h].role==="user"){C=h;break}C!==-1&&(e.messages.splice(C+1),e.error=null,e.usage=null,e.step=null,e.messages.push({id:je(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),s())}function g(){o?.abort(),e.messages=[],e.input="",e.streaming=!1,e.error=null,e.usage=null,e.step=null}async function m(C,h){let w=e.messages[e.messages.length-1],r=w?.role==="assistant"?w.approval:void 0;if(r&&(w.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:h}),signal:t.signal})}catch(u){if(t.signal?.aborted)return;e.error={code:"provider_error",message:u instanceof Error?u.message:String(u)}}}function b(){o?.abort(),o=null}return{send:c,stop:d,retry:a,clear:g,approve:m,dispose:b}}function ye(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 zn(e,n="bottom",t=6,o=!0){return ye(e.getBoundingClientRect(),n,t,o)}function he(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,l=Number.parseFloat(n.style.left)||o.left,s=e.top-i,c=e.left-l,d={top:o.top+s,bottom:o.bottom+s,left:o.left+c,right:o.right+c},a=window.innerWidth,g=window.innerHeight,m=e.top,b=e.left;return d.bottom>g-t&&(m=Math.max(t,m-(d.bottom-(g-t)))),d.top<t&&(m=Math.max(t,m+(t-d.top))),d.right>a-t&&(b=Math.max(t,b-(d.right-(a-t)))),d.left<t&&(b=Math.max(t,b+(t-d.left))),{top:m,left:b,width:e.width}}var ve=new Set,se=new Map,we=new Map,le=new Map;function cn(e){let{ctx:n,renderByIds:t,getSelfId:o,dirtyBatch:i,dirtySet:l,mediaRegistry:s,popupTrackers:c,scrollTrackers:d,schedulePopupRecompute:a,ensurePopupListeners:g,isRendering:m,isMounting:b,setMounting:C,endMounting:h}=e;return{_selfId:"_wf_root",_ctxVersion:0,_dirtySet:l,setMounting:C,endMounting:h,bumpCtxVersion:function(){this._ctxVersion++},render:function(r){if(m()){if(b())return;this._pendingRender||(this._pendingRender=!0,queueMicrotask(()=>{this._pendingRender=!1,this.render(r)}));return}if(!r||r.length===0){let u=o(this);if(u)r=[u];else return}t(r)},dirty:function(r){if(!b()){if(m()){this._pendingDirty||(this._pendingDirty=!0,queueMicrotask(()=>{this._pendingDirty=!1,this.dirty(r)}));return}if(!r||r.length===0){let u=o(this);if(u)r=[u];else return}for(let u of r)u&&(i.add(u),l.add(u));this._dirtyScheduled||(this._dirtyScheduled=!0,queueMicrotask(()=>{this._dirtyScheduled=!1;let u=[...i];i.clear(),u.length>0&&t(u)}))}},$:function(){let r=this;if(!Object.prototype.hasOwnProperty.call(r,"_$cache")){let u=ge(()=>{let f=r._selfVNode?._id??o(r);f&&n.ui.dirty([f])});r._$cache=u}return r._$cache},useChat:function(r){let u=this.$(),f=dn(u,De,r);Object.assign(u,{send:f.send,stop:f.stop,retry:f.retry,clear:f.clear,approve:f.approve,dispose:f.dispose});let p=o(this);if(p){let y=F(v=>{v===p&&(f.dispose(),y())})}return u},useMedia:function(r,u){let p=`media:${o(this)}:${r}`;if(!s.has(p)){let y=window.matchMedia(r);u(y.matches);let v=T=>u(T.matches);y.addEventListener("change",v),s.set(p,{mql:y,handler:v})}},useBreakpoint:function(r,u){let f=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:u,v=`bp:${o(this)}`;function T(){for(let[x,S]of Object.entries(f))if(window.matchMedia(S).matches)return x;return Object.keys(f)[0]??""}if(!s.has(v)){p(T());let x=[];for(let S of Object.values(f)){let O=window.matchMedia(S),P=()=>p(T());O.addEventListener("change",P),x.push({mql:O,handler:P})}s.set(v,{mqls:x})}},usePopupPosition:function(r){let u=o(this),f={top:0,left:0,refresh:()=>{}};if(!u)return f;let p={pos:f,getEl:r.el,isOpen:r.isOpen,compute:r.compute,panel:r.panel,margin:r.margin??8};return c.set(u,p),g(),f.refresh=()=>{let y=p.getEl();if(!y)return;let v=y.getBoundingClientRect();if(v.width===0&&v.height===0)return;let T=p.compute(v);Object.assign(f,he(T,p.panel?.(),p.margin))},f},useHoverCapable:function(){return typeof window<"u"&&!!window.matchMedia?.("(hover: hover)").matches},useStableRef:function(r,u){return p=>{p?r(p):u?.()}},useVisualViewport:function(){let r=o(this),u={height:window.innerHeight,offsetTop:0,keyboardOpen:!1},f=()=>{n.ui&&n.ui.dirty(r?[r]:void 0)},p=()=>{let v=window.visualViewport;u.height=v?.height??window.innerHeight,u.offsetTop=v?.offsetTop??0,u.keyboardOpen=u.height<window.innerHeight*.9,f()},y=window.visualViewport;if(y?.addEventListener?(y.addEventListener("resize",p),y.addEventListener("scroll",p)):window.addEventListener("resize",p),r){let v=F(T=>{T===r&&(y?.removeEventListener?(y.removeEventListener("resize",p),y.removeEventListener("scroll",p)):window.removeEventListener("resize",p),v())})}return u},usePopup:function(r){let u=o(this),f=this.useHoverCapable(),p=()=>typeof r.trigger=="function"?r.trigger():r.trigger,y=r.open!==void 0,v=()=>!!r.disabled?.(),T=()=>y?typeof r.open=="function"?!!r.open():!!r.open:r.isOpen(),x=E=>{v()||(y?r.onOpenChange?.(E):r.setOpen(E))},S=()=>{let E=r.placement;return typeof E=="function"?E():E??"bottom"},O=null,P=!1,N=n.ui.usePopupPosition({el:r.el,isOpen:()=>T(),compute:E=>{if(r.position){let L=r.position();return{top:L.y,left:L.x}}return ye(E,S(),r.gap??6,r.center!==!1)},panel:()=>O,margin:r.margin??8}),_=E=>{if(r.closeOnOutside===!1||!T())return;let L=E.target;if(!(L instanceof Node))return;let q=r.el();q&&q.contains(L)||O&&O.contains(L)||x(!1)},k=E=>{r.closeOnEscape!==!1&&(E.key!=="Escape"||!T()||x(!1))};if(document.addEventListener("mousedown",_),document.addEventListener("keydown",k),u){let E=F(L=>{L===u&&(document.removeEventListener("mousedown",_),document.removeEventListener("keydown",k),E())})}let A={},R=E=>typeof E=="function"?E():E??0,j=()=>R(r.openDelay),M=()=>R(r.closeDelay),V,I,ae=()=>{clearTimeout(V),clearTimeout(I),V=void 0,I=void 0},ue=E=>{if(v())return;let L=E.currentTarget,q=E.relatedTarget;L.contains(q)||(clearTimeout(I),I=void 0,V=setTimeout(()=>{V=void 0,x(!0)},j()))},hn=E=>{if(v())return;let L=E.currentTarget,q=E.relatedTarget;L.contains(q)||(clearTimeout(V),V=void 0,I=setTimeout(()=>{I=void 0,x(!1)},M()))},vn=()=>{v()||(clearTimeout(I),I=void 0,V=setTimeout(()=>{V=void 0,x(!0)},j()))},wn=()=>{v()||(clearTimeout(V),V=void 0,I=setTimeout(()=>{I=void 0,x(!1)},M()))},X=()=>p()==="hover";if(A.onMouseOver=E=>{X()&&ue(E)},A.onMouseOut=E=>{X()&&hn(E)},A.onClick=()=>{X()?f||x(!T()):p()==="click"&&x(!0)},A.onFocus=()=>{X()&&vn()},A.onBlur=()=>{X()&&wn()},p()==="longpress"){let E,L=0,q=0,K=()=>{clearTimeout(E),E=void 0};A.onPointerDown=U=>{v()||(L=U.clientX??0,q=U.clientY??0,K(),E=setTimeout(()=>{E=void 0,r.onTrigger?.({clientX:L,clientY:q}),x(!0)},r.longPressDuration??500))},A.onPointerUp=K,A.onPointerLeave=K,A.onPointerMove=U=>{let Ee=Math.abs((U.clientX??0)-L),Pe=Math.abs((U.clientY??0)-q);(Ee>10||Pe>10)&&K()},A.onContextMenu=U=>{U.preventDefault(),r.onTrigger?.({clientX:U.clientX??0,clientY:U.clientY??0}),x(!0)}}if(A.onKeyDown=E=>{E.key==="Escape"&&r.closeOnEscape!==!1&&x(!1)},u){let E=F(L=>{L===u&&(ae(),E())})}let Cn=E=>{if(E){O=E;let L=()=>N.refresh();E.addEventListener("animationend",L,{once:!0})}else O=null},xe=null,Te=null,bn=E=>{Cn(E),Te&&Te(E)};return{get open(){return T()},setOpen:x,wrapProps:A,portal:(E,L="popover")=>{if(v())return null;if(!T())return P=!1,xe=null,null;let K=r.el();(!P||K!==xe)&&(K?N.refresh():queueMicrotask(()=>{T()&&N.refresh()}),P=!0,xe=K);let U=E.props??{};Te=U.ref??null;let Ee=["wf-popup",U.class].filter(Boolean).join(" "),Pe={...U.style??{},position:"fixed",top:`${N.top}px`,left:`${N.left}px`,maxWidth:r.width!==void 0?`min(${r.width}px, calc(100vw - 32px))`:"calc(100vw - 32px)"},xn={...E,props:{...U,class:Ee,style:Pe,ref:bn}};return _e(xn,L)},refresh:()=>N.refresh()}},useLongPress:function(r){let{onLongPress:u,duration:f=500}=r,p,y=0,v=0,T=null,x=()=>{clearTimeout(p),p=void 0};return{onPointerDown:S=>{y=S.clientX??0,v=S.clientY??0,T=S,x(),p=setTimeout(()=>{p=void 0,T&&u(T)},f)},onPointerUp:x,onPointerLeave:x,onPointerMove:S=>{let O=Math.abs((S.clientX??0)-y),P=Math.abs((S.clientY??0)-v);(O>10||P>10)&&x()},onContextMenu:S=>{S.preventDefault(),u(S)}}},useInView:function(r){let u=o(this),f={isIn:!1,ready:!1,observe:x,refresh:S,disconnect:O},p=null,y=null,v=()=>{n.ui&&n.ui.dirty(u?[u]:void 0)};function T(){if(y?.disconnect(),y=null,!p)return;let P=typeof r.rootMargin=="function"?r.rootMargin():r.rootMargin,N=typeof r.threshold=="function"?r.threshold():r.threshold;y=new IntersectionObserver(_=>{let k=_[_.length-1];if(!k)return;let A=k.isIntersecting,R=A!==f.isIn,j=!f.ready;f.isIn=A,f.ready=!0,r.onChange?.(k,A),(R||j)&&v()},{root:r.root?r.root():null,rootMargin:P??"0px",threshold:N??0}),y.observe(p)}function x(P){p=P,P?T():(y?.disconnect(),y=null,f.isIn=!1)}function S(){T()}function O(){y?.disconnect(),y=null}return f},useScrollPosition:function(r){let u=o(this),f={y:0,refresh(){let y=p.getScroller();f.y=y instanceof Window?document.scrollingElement?.scrollTop??y.scrollY??0:y.scrollTop??0}},p={handle:f,getScroller:r.getScroller??(()=>window)};return u?(d.set(u,p),g(),f.refresh(),f):(f.refresh(),f)},useAsync:function(r){let u=o(this),f=ge(()=>{n.ui&&n.ui.dirty(u?[u]:void 0)});f.loading=!0;let p=0,y=()=>{let v=++p;f.loading=!0,f.error=null,Promise.resolve().then(()=>r()).then(T=>{p===v&&(f.data=T,f.loading=!1)}).catch(T=>{p===v&&(f.error=T,f.loading=!1)})};return y(),f.reload=y,f},useControlled:function(r){let u=o(this),f=r.value!==void 0;if(f&&!r.onChange&&r.name&&(ve.has(r.name)||(ve.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)}`))),!f&&u&&!se.has(u)){se.set(u,r.value);let y=F(v=>{v===u&&(se.delete(u),y())})}let p=y=>{if(f){r.onChange?.(y);return}u&&se.set(u,y),n.ui&&(u?n.ui.dirty([u]):n.ui.render())};return{value:f?r.value:u?se.get(u):r.value,setValue:p,controlled:f}},useControlledInput:function(r){let u=o(this),f=this.useControlled({value:r.value,onChange:r.onChange,name:r.name});if(u&&!we.has(u)){we.set(u,{keyword:"",selectedLabel:""});let v=F(T=>{T===u&&(we.delete(u),v())})}let p=u?we.get(u):{keyword:"",selectedLabel:""},y=()=>{u?n.ui?.dirty([u]):n.ui?.render()};return{...f,get keyword(){return p.keyword},setKeyword(v){p.keyword=v,y()},get selectedLabel(){return p.selectedLabel},setSelectedLabel(v){p.selectedLabel=v,y()}}},useOpen:function(r){let u=o(this);if(u&&!le.has(u)){le.set(u,!1);let T=F(x=>{x===u&&(le.delete(u),T())})}let f=r.open!==void 0;f&&!r.onOpenChange&&r.name&&!ve.has(r.name)&&(ve.add(r.name),console.warn(`[weifuwu/${r.name}] \u53D7\u63A7\u6A21\u5F0F\uFF08open \u5DF2\u4F20\uFF09\u4F46\u672A\u63D0\u4F9B onOpenChange\uFF0C\u4EA4\u4E92\u65E0\u6CD5\u751F\u6548\u3002
|
|
6
|
+
\u975E\u53D7\u63A7\uFF1A\u53BB\u6389 open\uFF1B\u53D7\u63A7\uFF1A\u4F20\u5165 onOpenChange={(o) => setOpen(o)}`));let p=()=>f?!!r.open:u?le.get(u)??!1:!1,y=()=>{u?n.ui?.dirty([u]):n.ui?.render()},v=T=>{if(f){r.onOpenChange?.(T);return}u&&le.set(u,T),y()};return{get open(){return p()},setOpen:v,triggerProps:{onClick:()=>v(!0),onFocus:()=>{r.openOnFocus&&v(!0)}}}},usePresence:function(r){let u=o(this),f="closed",p,y=()=>{f="closed",n.ui&&(u?n.ui.dirty([u]):n.ui.render())};return{get phase(){return f},ref:T=>{T?p||(p=()=>{f==="exit"&&y()},T.addEventListener("animationend",p)):p=void 0},sync:T=>(T?f="open":f==="open"&&(f="exit"),f)}},useDialog:function(r){let u=o(this),f,p=null,y=this.usePresence(r);return{get phase(){return y.phase},rootRef:x=>{x?(He(),p&&(f=me(p)),y.ref(x)):(Ue(),f?.(),y.ref(null))},panelRef:x=>{p=x,x&&!f&&(f=me(x))},sync:x=>y.sync(x)}},useGlobalKey:function(r){let u=o(this);if(typeof window>"u")return()=>{};if(window.addEventListener("keydown",r),u){let f=F(p=>{p===u&&(window.removeEventListener("keydown",r),f())})}return()=>window.removeEventListener("keydown",r)},useDrag:function(r){let u=0,f=0,p=!1,y=x=>{p&&r.onMove(x,{x:x.clientX-u,y:x.clientY-f})},v=x=>{p&&(p=!1,window.removeEventListener("pointermove",y),window.removeEventListener("pointerup",v),r.onEnd?.(x))};return{onPointerDown:x=>{p||(x.preventDefault(),p=!0,u=x.clientX,f=x.clientY,window.addEventListener("pointermove",y),window.addEventListener("pointerup",v),r.onStart?.(x))}}},useDragDrop:function(r){let u={};r.onDrop&&(u.onDrop=p=>{p.preventDefault(),r.onDrop(p)}),r.onDragOver&&(u.onDragOver=p=>{p.preventDefault(),r.onDragOver(p)}),r.onDragLeave&&(u.onDragLeave=p=>r.onDragLeave(p));let f={draggable:!0};if(r.onDragStart){let p=r.onDragStart;f.onDragStart=y=>{typeof document<"u"&&document.body.classList.add("wf-dragging"),p(y)}}if(r.onDragEnd){let p=r.onDragEnd;f.onDragEnd=y=>{typeof document<"u"&&document.body.classList.remove("wf-dragging"),p(y)}}return{dropProps:u,dragProps:f}},useReducedMotion:function(){return typeof window<"u"&&!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches},useAnimationEnd:function(r,u){let f=null,p=()=>{r(),u?.once&&f&&f.removeEventListener("animationend",p)};return v=>{v?(f=v,v.addEventListener("animationend",p)):f&&(f.removeEventListener("animationend",p),f=null)}},useTween:function(r,u){let f=o(this),p=this.useReducedMotion(),y=u?.duration??400,v=u?.ease==="linear"?N=>N:N=>1-Math.pow(1-N,3),T,x=r,S={value:p?r:0,reset:()=>{}},O=()=>{n.ui&&(f?n.ui.dirty([f]):n.ui.render())},P=N=>{if(x=N,p){S.value=N,O();return}if(N===S.value)return;T&&cancelAnimationFrame(T);let _=S.value,k=performance.now(),A=R=>{let j=Math.min(1,(R-k)/y);S.value=Math.round(_+(N-_)*v(j)),j<1?(T=requestAnimationFrame(A),O()):(T=void 0,O())};T=requestAnimationFrame(A)};return S.reset=N=>{N===x&&T||P(N)},queueMicrotask(()=>P(r)),S},selfId:function(r){if(typeof r!="string"||!r)throw new Error(`[weifuwu] selfId requires a non-empty string, got ${typeof r}`);if(H.has(r))throw new Error(`[weifuwu] Duplicate component ID: "${r}". Each component must have a unique custom ID.`);let u=this._selfVNode;u&&(u._customId=r,H.set(r,u))}}}function fn(){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,queryCommandState:e=>typeof document<"u"?document.queryCommandState(e):!1,queryCommandValue:e=>typeof document<"u"?document.queryCommandValue(e):"",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 Gn(){let e=[],n={},t=null,o=null,i=null,l=!1,s=null,c=!1,d=[];function a(P){d.push(c),c=P}function g(){c=d.pop()??!1}let m=new Set,b=!1,C=new Map;function h(P){let N=C.get(P);N&&(N.mql&&N.handler&&N.mql.removeEventListener("change",N.handler),N.mqls?.forEach(({mql:_,handler:k})=>_.removeEventListener("change",k)),C.delete(P))}let w=new Map,r=!1,u=0;function f(){r||(r=!0,window.addEventListener("scroll",v,{capture:!0,passive:!0}),window.addEventListener("resize",v))}function p(){r&&(window.removeEventListener("scroll",v,{capture:!0}),window.removeEventListener("resize",v),r=!1)}let y=new Map;function v(){u||(u=requestAnimationFrame(()=>{u=0;let P=[];for(let[N,_]of w){if(!_.isOpen())continue;let k=_.getEl();if(!k)continue;let A=k.getBoundingClientRect();if(A.width===0&&A.height===0)continue;let R=_.compute(A);Object.assign(_.pos,he(R,_.panel?.(),_.margin)),P.push(N)}for(let[N,_]of y){let k=_.getScroller(),A=k instanceof Window?document.scrollingElement?.scrollTop??k.scrollY??0:k.scrollTop??0;A!==_.handle.y&&(_.handle.y=A,P.push(N))}P.length>0&&n.ui.render(P)}))}function T(P){if(!l){l=!0;for(let N of P){let _=H.get(N);if(!_||!_._render)continue;n.ui._dirtySet?.delete(N);let k=_._child,A=_._render(_.props);if(_._child=A,k&&k._placement==="remote"||A&&A._placement==="remote"){k&&A?oe(k,A,n):A?Y(A,n):k&&W(k);continue}if(!_._parentNode&&_._refNode){let R=_._refNode.parentNode;R&&(_._parentNode=R)}if(_._parentNode){let R=z(_._parentNode,_._refNode??null,k,A,n);R&&R!==_._refNode?_._refNode=R:R||(_._refNode=null)}}l=!1,x()}}function x(){let P=n.ui;P&&m.size>0&&!P._dirtyScheduled&&(P._dirtyScheduled=!0,queueMicrotask(()=>{P._dirtyScheduled=!1;let N=[...m];m.clear(),N.length>0&&T(N)}))}function S(P){return P?._selfId??n.ui?._selfId}let O={get ctx(){return n},use(P){return e.push(P),O},async mount(P,N,_){o=N;for(let M of e)n=await M(n);let k=typeof P=="string"?document.querySelector(P):P;if(!k)throw new Error(`mount target not found: ${P}`);t=k;let A=!!_?.hydrate;A||(t.innerHTML="");let R=new Map,j=globalThis.__DATA__??window.__DATA__;if(j&&typeof j=="object")for(let[M,V]of Object.entries(j))R.set(M,{value:V});if(n.data={async get(M,V){let I=R.get(M);if(I&&"value"in I)return I.value;if(I?.promise)return I.promise;if(!V)return;let ae=Promise.resolve().then(()=>V()).then(ue=>(R.set(M,{value:ue}),ue));return R.set(M,{promise:ae}),ae},set(M,V){R.set(M,{value:V})},has(M){return R.has(M)}},s=F(M=>{for(let V of[...C.keys()])(V.startsWith(`media:${M}:`)||V===`bp:${M}`)&&h(V);w.delete(M),y.delete(M)}),n.browser=fn(),n.ui=cn({ctx:n,renderByIds:T,getSelfId:S,dirtyBatch:m,dirtySet:new Set,mediaRegistry:C,popupTrackers:w,scrollTrackers:y,schedulePopupRecompute:v,ensurePopupListeners:f,destroyPopupListeners:p,isRendering:()=>l,isMounting:()=>c,setMounting:a,endMounting:g}),l=!0,i=Yn(N,n),i._id="_wf_root",i._parentNode=t,i._refNode=A?t.firstChild:null,H.set("_wf_root",i),A)await Ie(t,i,n);else{let M=tn(i,n);M instanceof Node&&t.appendChild(M)}i._refNode=t.firstChild,l=!1,x()},destroy(){u&&(cancelAnimationFrame(u),u=0),p(),i&&W(i),s&&(s(),s=null),w.clear(),y.clear();for(let P of[...C.keys()])h(P);H.clear(),t&&(t.innerHTML=""),t=null,i=null,n={}}};return O}function Yn(e,n){return{type:e,props:{},key:void 0}}function Xn(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 Jn(e){let n=[],t=e.replace(/:(\w+)/g,(o,i)=>(n.push(i),"([^/]+)")).replace(/\*/g,".*");return{re:new RegExp(`^${t}$`),keys:n}}function qe(e,n="",t=[]){let o=[];for(let i of e){let l=Xn(n,i.path),{re:s,keys:c}=Jn(l),d=[...t,i];o.push({re:s,keys:c,def:i,chain:d}),i.children&&o.push(...qe(i.children,l,d))}return o}function pn(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 mn(e,n){let t={},o=e.match(n.re);if(o)for(let i=0;i<n.keys.length;i++)t[n.keys[i]]=Qn(o[i+1]);return t}function Qn(e){try{return decodeURIComponent(e)}catch{return e}}function Zn(e){let n=qe(e.routes),t=e.mode||"history";function o(){return t==="hash"?window.location.hash.replace(/^#/,"")||"/":window.location.pathname}function i(l){let s=pn(l,n);if(s){let c=s.chain[s.chain.length-1];return{path:s.def.path,params:mn(l,s),query:Object.fromEntries(new URLSearchParams(window.location.search)),chain:s.chain,title:c?.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 s=a=>{a.ui?.bumpCtxVersion?.()},c=a=>{Z(),t==="hash"?(window.location.hash="#"+a,l.route=i(a)):(window.history.pushState({},"",a),l.route=i(a)),l.route?.title&&(document.title=l.route.title),s(l),l.ui?.render()};l.route=i(o()),l.route.title&&(document.title=l.route.title),l.app={navigate:c};let d=()=>{Z(),l.route=i(o()),l.route?.title&&(document.title=l.route.title),s(l),l.ui?.render()};return window.addEventListener("popstate",d),t==="hash"&&window.addEventListener("hashchange",d),l}}function et(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],l=i.layout??i.component;return l?(i.layout&&(o._rvDepth=t+1),{type:l,props:{},key:void 0}):null}}function G(e,n){return Object.assign(Object.create(e),n)}function nt(e={}){let n=e.url??"/ws",t=e.reconnectInterval??3e3,o=e.maxReconnect??10,i=e.pingInterval??3e4,l=e.pingTimeout??1e4;return s=>{let c=new Set,d=null,a=0,g=null,m=null,b=null,C=!1,h={isConnected:!1,onMessage:p=>(c.add(p),()=>{c.delete(p)}),send:p=>{d?.readyState===WebSocket.OPEN&&d.send(JSON.stringify(p))},_connect:w,close:()=>{C=!0,f(),d?.close(),d=null,h.isConnected=!1}};async function w(){if(!C)try{d=new WebSocket(n),d.onopen=()=>{h.isConnected=!0,a=0,r()},d.onmessage=p=>{try{let y=JSON.parse(p.data);for(let v of c)v(y)}catch{}u()},d.onclose=()=>{h.isConnected=!1,f(),!C&&a<o&&(a++,g=setTimeout(w,t*Math.min(a,5)))},d.onerror=()=>{d?.close()}}catch{C||(g=setTimeout(w,t))}}function r(){i<=0||(m=setInterval(()=>{d?.readyState===WebSocket.OPEN&&d.send(JSON.stringify({type:"ping"})),b=setTimeout(()=>{d?.close()},l)},i))}function u(){clearTimeout(b)}function f(){clearInterval(m),clearTimeout(b),clearTimeout(g)}return w(),G(s,{ws:h})}}function tt(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 l(s,c,d,a){let g=n.baseURL+c,m={method:s,headers:{...n.headers,...a?.headers}},b=e?.token?.();b&&!m.headers.Authorization&&(m.headers.Authorization=`Bearer ${b}`);let C=i>0,h=!!a?.signal,w=null,r=null;(C||h)&&(w=new AbortController,m.signal=w.signal,C&&(r=setTimeout(()=>w.abort(new Error("Request timed out")),i)),h&&a.signal.addEventListener("abort",()=>w.abort())),d!==void 0&&s!=="GET"&&s!=="HEAD"&&(m.body=JSON.stringify(d));let u={url:g,init:m};t&&(u=t(u));try{let f=await fetch(u.url,u.init);if(o)return o(f);if(!f.ok){let v=await f.text().catch(()=>"");throw new Ce(f.status,v||f.statusText)}let p=f.headers.get("content-length");if(f.status===204||p==="0")return;let y=(f.headers.get("content-type")||"").toLowerCase();return y.includes("application/json")||y.includes("json")?f.json():f.text()}finally{r&&clearTimeout(r)}}return s=>G(s,{api:{get:(d,a)=>l("GET",d,void 0,a),post:(d,a,g)=>l("POST",d,a,g),put:(d,a,g)=>l("PUT",d,a,g),patch:(d,a,g)=>l("PATCH",d,a,g),delete:(d,a)=>l("DELETE",d,void 0,a)}})}var Ce=class extends Error{status;body;constructor(n,t){super(`API Error ${n}: ${t}`),this.name="ApiError",this.status=n,this.body=t}};function ot(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 rt(e){let n=ot(e);return n?.exp?n.exp*1e3-3e4<Date.now():!0}function it(e){let n=e?.storage??localStorage,t=e?.tokenKey??"weifuwu_token",o=e?.userKey??"weifuwu_user",i=e?.refreshTokenKey??"weifuwu_refresh",l=e?.refreshEndpoint??"/api/auth/refresh";return s=>{let c=n.getItem(t),d=n.getItem(o),a={token:c,user:d?JSON.parse(d):null,get isLoggedIn(){return this.token!==null},login(g,m,b){a.token=g,a.user=m,n.setItem(t,g),n.setItem(o,JSON.stringify(m)),b&&n.setItem(i,b)},logout(){a.token=null,a.user=null,n.removeItem(t),n.removeItem(o),n.removeItem(i)},setUser(g){a.user=g,n.setItem(o,JSON.stringify(g))},async refresh(){let g=n.getItem(i);if(!g)return!1;try{let m=await fetch(l,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:g})});if(!m.ok)return a.logout(),!1;let b=await m.json();return a.token=b.token,n.setItem(t,b.token),b.refreshToken&&n.setItem(i,b.refreshToken),!0}catch{return!1}}};return c&&rt(c)&&a.refresh().catch(()=>{}),G(s,{auth:a})}}function st(e,n){let t=n.ui.$();return t.error=null,o=>{if(t.error){let s=o.fallback;return typeof s=="function"?s({error:t.error}):s??null}let i=n.ui;i._errorHandler=s=>{t.error=s};let l=o.children;try{return l??null}catch(s){t.error=s;let c=o.fallback;return typeof c=="function"?c({error:s}):c??null}}}var Fe={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 Be={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 be={"zh-CN":Fe,"en-US":Be};function gn(e){if(be[e])return e;let n=e.split("-")[0];return Object.keys(be).find(o=>o.startsWith(n))??"zh-CN"}function lt(e={}){let{locale:n="zh-CN",messages:t={},components:o={}}=e,i=gn(n),l=be[i],s=yn(l,t,o),c={locale:i,t:(d,a)=>s.messages?.[d]??a??d,setLocale:()=>{},components:s.components};return d=>{let a=d;return a.i18n=c,c.setLocale=g=>{let m=gn(g),b=be[m];b&&(s=yn(b,t,o),c.locale=m,c.components=s.components,a.ui?.bumpCtxVersion?.(),a.ui?.render())},d}}function yn(e,n,t){return{messages:{...e?.messages,...n},components:at(e?.components??{},t)}}function at(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 ut(e,n,t=400){let o=!1,i=()=>{o||(o=!0,e.removeEventListener("animationend",i),clearTimeout(l),n())};e.addEventListener("animationend",i);let l=setTimeout(i,t)}export{Ce as ApiError,st as ErrorBoundary,$ as Fragment,B as Portal,et as RouteView,De as aiStream,ut as animateOut,tt as api,Tn as asyncComponent,it as auth,W as callRefCleanup,Z as clearAsyncComponentCache,zn as computeFixedPos,ye as computeFixedPosRect,Gn as createApp,_e as createPortal,ge as createReactiveState,Be as enUS,G as extendCtx,Nn as h,Ie as hydrateVNode,lt as i18n,J as isAsyncComponent,Ne as jsx,Pn as jsxDEV,En as jsxs,He as lockScroll,In as mountVNode,z as patchValue,Zn as router,un as toChatMessages,me as trapFocus,Ue as unlockScroll,nt as ws,Fe as zhCN};
|
|
@@ -9,8 +9,16 @@ import type { VNode, Component, AsyncComponent } from './vnode.ts';
|
|
|
9
9
|
import type { WfuiContext } from './types.ts';
|
|
10
10
|
export declare const idRegistry: Map<string, VNode>;
|
|
11
11
|
type UnmountHook = (id: string) => void;
|
|
12
|
-
/**
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* 注册组件卸载钩子(组件从 idRegistry 注销时触发,含 _customId)。
|
|
14
|
+
*
|
|
15
|
+
* 返回退订函数——组件级钩子(use* 原语)应在触发后自退订,
|
|
16
|
+
* 避免 _unmountHooks 数组随 mount 累积导致长期 SPA 内存增长 + unmount O(n) 退化。
|
|
17
|
+
* app 生命周期级钩子(app.mount 注册的 media/popup/scroll 清理)不退订(随 app 消亡)。
|
|
18
|
+
*/
|
|
19
|
+
export declare function onComponentUnmount(hook: UnmountHook): () => void;
|
|
20
|
+
/** test-only:返回当前注册的卸载钩子数(回归护栏——验证组件级钩子自退订不累积) */
|
|
21
|
+
export declare function __testHookCount(): number;
|
|
14
22
|
interface FactoryEntry {
|
|
15
23
|
promise: Promise<Component<any, any>>;
|
|
16
24
|
resolved?: Component<any, any>;
|
|
@@ -27,6 +35,13 @@ export declare function startAsyncFactory(Comp: AsyncComponent, ctx: WfuiContext
|
|
|
27
35
|
export declare function resolveAsyncFactory(Comp: AsyncComponent, ctx: WfuiContext): Promise<Component>;
|
|
28
36
|
/** sync 模式:工厂已解析 → 定义;未解析 → undefined(占位 + 完成后整树重渲染) */
|
|
29
37
|
export declare function resolveAsyncFactorySync(Comp: AsyncComponent): Component | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* 包裹 ref 回调调用——用户 ref 逻辑抛错时不中断渲染/卸载管线。
|
|
40
|
+
*
|
|
41
|
+
* ref 在渲染期外执行(mount 后/卸载时),语义上属用户逻辑 bug,不接 _errorHandler
|
|
42
|
+
* (ErrorBoundary 只覆盖渲染期错误)。console.error 暴露问题即可。
|
|
43
|
+
*/
|
|
44
|
+
export declare function safeCallRef(ref: Function, arg: any, phase: 'mount' | 'cleanup', name?: string): void;
|
|
30
45
|
/** 通知 ref 清理 + Portal 子容器清理 */
|
|
31
46
|
export declare function callRefCleanup(input: any): void;
|
|
32
47
|
/** 供 hydration/mount 路径生成新组件 ID(保持与 idRegistry 同源递增) */
|
package/dist/client/render.d.ts
CHANGED
|
@@ -10,25 +10,32 @@
|
|
|
10
10
|
*
|
|
11
11
|
* 状态管理:组件使用闭包变量 + ctx.ui.render() 手动触发重渲染。
|
|
12
12
|
*/
|
|
13
|
-
import type { VNode, Component, AsyncComponent } from './vnode.ts';
|
|
13
|
+
import type { VNode, VNodeChild, Component, AsyncComponent } from './vnode.ts';
|
|
14
14
|
import type { WfuiContext } from './types.ts';
|
|
15
15
|
export declare const SVG_NS = "http://www.w3.org/2000/svg";
|
|
16
16
|
export declare const SVG_TAGS: Set<string>;
|
|
17
|
-
export declare function render(input:
|
|
18
|
-
export declare function renderValue(v:
|
|
17
|
+
export declare function render(input: VNodeChild, ctx: WfuiContext): Node | null;
|
|
18
|
+
export declare function renderValue(v: VNodeChild, ctx: WfuiContext): Node | null;
|
|
19
|
+
/**
|
|
20
|
+
* 异步组件工厂缓存:同一工厂只执行一次,多实例/多渲染共享。
|
|
21
|
+
* resolved 记录已解析的定义(同步快速路径用)。
|
|
22
|
+
* (缓存本体在 registry.ts,本文件仅保留依赖 render 的调度函数)
|
|
23
|
+
*/
|
|
24
|
+
/** 占位完成后整树重渲染(async 工厂已解析,diff 收敛到目标位置) */
|
|
25
|
+
export declare function scheduleFullReRender(ctx: WfuiContext): void;
|
|
19
26
|
/**
|
|
20
27
|
* 同步 mount 组件(async 工厂占位策略):
|
|
21
28
|
* - 同步组件 → def(props, ctx) → render fn → 输出 VNode
|
|
22
29
|
* - async 工厂已解析 → 同同步组件
|
|
23
30
|
* - async 工厂未解析 → 占位(返回 null)+ 启动工厂 + 完成后整树重渲染
|
|
24
31
|
*/
|
|
25
|
-
export declare function mountComponent(Comp: Component | AsyncComponent, props:
|
|
32
|
+
export declare function mountComponent(Comp: Component | AsyncComponent, props: VNode['props'], vnode: VNode, ctx: WfuiContext): VNode | null;
|
|
26
33
|
/** 首次渲染 Portal:创建远程容器、渲染子节点(不返回占位节点) */
|
|
27
34
|
export declare function renderPortal(vnode: VNode, ctx: WfuiContext): void;
|
|
28
35
|
/** 更新 Portal:复用远程容器,patch 子节点(不操作父 DOM) */
|
|
29
36
|
export declare function patchPortal(oldV: VNode | null, newV: VNode, ctx: WfuiContext): void;
|
|
30
37
|
/** 展平嵌套数组 */
|
|
31
|
-
export declare function flattenChildren(children:
|
|
38
|
+
export declare function flattenChildren(children: VNodeChild): VNodeChild[];
|
|
32
39
|
export declare function mountVNode(container: Element, vnode: VNode, ctx: WfuiContext): void;
|
|
33
40
|
export { callRefCleanup, idRegistry, clearAsyncComponentCache, nextComponentId } from './registry.ts';
|
|
34
41
|
export { patchValue } from './diff.ts';
|
package/dist/client/router.d.ts
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
* 路由变化时调用 ctx.ui.render() 触发重渲染。
|
|
5
5
|
*/
|
|
6
6
|
import type { WfuiContext, AppMiddleware, RouteDef } from './types.ts';
|
|
7
|
+
import type { VNode } from './vnode.ts';
|
|
7
8
|
export interface RouterOptions {
|
|
8
9
|
mode?: 'hash' | 'history';
|
|
9
10
|
routes: RouteDef[];
|
|
10
|
-
notFound?: (props:
|
|
11
|
+
notFound?: (props: Record<string, unknown>, ctx: WfuiContext) => VNode | null;
|
|
11
12
|
}
|
|
12
13
|
/** router 中间件注入到 ctx 的字段 */
|
|
13
14
|
export interface RouteInjected {
|
|
@@ -23,4 +24,4 @@ export interface RouteInjected {
|
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
export declare function router(opts: RouterOptions): AppMiddleware<{}, RouteInjected>;
|
|
26
|
-
export declare function RouteView(_props: {}, ctx: WfuiContext): () =>
|
|
27
|
+
export declare function RouteView(_props: {}, ctx: WfuiContext): () => VNode | null;
|
package/dist/client/types.d.ts
CHANGED
|
@@ -108,16 +108,16 @@ export interface UseLongPressOptions {
|
|
|
108
108
|
/** 长按时长(ms,默认 500) */
|
|
109
109
|
duration?: number;
|
|
110
110
|
/** 长按触发回调(接收触发事件,含 clientX/clientY) */
|
|
111
|
-
onLongPress: (e
|
|
111
|
+
onLongPress: (e: PointerEvent | MouseEvent) => void;
|
|
112
112
|
}
|
|
113
113
|
/** 长按返回的触发 props — spread 到目标元素 */
|
|
114
114
|
export interface UseLongPressHandle {
|
|
115
|
-
onPointerDown: (e:
|
|
116
|
-
onPointerUp: (e:
|
|
117
|
-
onPointerLeave: (e:
|
|
118
|
-
onPointerMove: (e:
|
|
115
|
+
onPointerDown: (e: PointerEvent) => void;
|
|
116
|
+
onPointerUp: (e: PointerEvent) => void;
|
|
117
|
+
onPointerLeave: (e: PointerEvent) => void;
|
|
118
|
+
onPointerMove: (e: PointerEvent) => void;
|
|
119
119
|
/** 桌面右键兼容(移动端浏览器 contextmenu 也会触发) */
|
|
120
|
-
onContextMenu: (e:
|
|
120
|
+
onContextMenu: (e: MouseEvent) => void;
|
|
121
121
|
}
|
|
122
122
|
/** 可视视口(visualViewport)状态 — useVisualViewport 返回值 */
|
|
123
123
|
export interface VisualViewportHandle {
|
|
@@ -271,7 +271,7 @@ export interface WfuiContext {
|
|
|
271
271
|
* return () => h('div', { ref: listRef })
|
|
272
272
|
* ```
|
|
273
273
|
*/
|
|
274
|
-
useStableRef: (init: (el: HTMLElement | null) => void, cleanup?: () => void) => (el:
|
|
274
|
+
useStableRef: (init: (el: HTMLElement | null) => void, cleanup?: () => void) => (el: HTMLElement | null) => void;
|
|
275
275
|
/**
|
|
276
276
|
* 全局键盘监听(window keydown):mount 注册、组件卸载自动清理;返回退订函数。
|
|
277
277
|
* 覆盖 Command 全局快捷键 / Img preview Escape 等 document/window 级键盘场景。
|
|
@@ -436,7 +436,7 @@ export interface WfuiContext {
|
|
|
436
436
|
}) => {
|
|
437
437
|
phase: 'closed' | 'open' | 'exit';
|
|
438
438
|
/** 挂到根元素(animationend 监听:exit 结束才真正卸载) */
|
|
439
|
-
ref: (el:
|
|
439
|
+
ref: (el: HTMLElement | null) => void;
|
|
440
440
|
/** render 阶段同步 open → 返回当前 phase */
|
|
441
441
|
sync: (open: boolean) => 'closed' | 'open' | 'exit';
|
|
442
442
|
};
|
|
@@ -445,9 +445,9 @@ export interface WfuiContext {
|
|
|
445
445
|
}) => {
|
|
446
446
|
phase: 'closed' | 'open' | 'exit';
|
|
447
447
|
/** 挂到 portal 根(lockScroll + animationend 退场监听) */
|
|
448
|
-
rootRef: (el:
|
|
448
|
+
rootRef: (el: HTMLElement | null) => void;
|
|
449
449
|
/** 挂到焦点 trap 目标(对话框面板) */
|
|
450
|
-
panelRef: (el:
|
|
450
|
+
panelRef: (el: HTMLElement | null) => void;
|
|
451
451
|
/** render 阶段同步 open → 返回当前 phase */
|
|
452
452
|
sync: (open: boolean) => 'closed' | 'open' | 'exit';
|
|
453
453
|
};
|
|
@@ -465,7 +465,7 @@ export interface WfuiContext {
|
|
|
465
465
|
*/
|
|
466
466
|
useAnimationEnd: (cb: () => void, opts?: {
|
|
467
467
|
once?: boolean;
|
|
468
|
-
}) => (el:
|
|
468
|
+
}) => (el: HTMLElement | null) => void;
|
|
469
469
|
/** 数值补间(rAF + ease + reduced-motion 直落终值):count-up / 进度 / 指示器。
|
|
470
470
|
* 目标值变化自动补间;返回 `{ value }`(当前值,render 读)。 */
|
|
471
471
|
useTween: (target: number, opts?: {
|
|
@@ -481,7 +481,7 @@ export interface WfuiContext {
|
|
|
481
481
|
/** 当前组件实例 ID(仅供内部使用,通过 ctx 扩展注入) */
|
|
482
482
|
_selfId?: string;
|
|
483
483
|
/** 当前组件 VNode 引用(仅供内部使用,通过 ctx 扩展注入) */
|
|
484
|
-
_selfVNode?:
|
|
484
|
+
_selfVNode?: VNode;
|
|
485
485
|
};
|
|
486
486
|
/** 路由(由 router 中间件注入) */
|
|
487
487
|
route?: {
|
|
@@ -502,13 +502,28 @@ export interface WfuiContext {
|
|
|
502
502
|
isConnected: boolean;
|
|
503
503
|
[key: string]: any;
|
|
504
504
|
};
|
|
505
|
-
/** API 客户端(由 api
|
|
505
|
+
/** API 客户端(由 api 中间件注入);options 为 ApiRequestOptions 形状(headers/signal) */
|
|
506
506
|
api?: {
|
|
507
|
-
get: <T =
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
507
|
+
get: <T = unknown>(url: string, options?: {
|
|
508
|
+
headers?: Record<string, string>;
|
|
509
|
+
signal?: AbortSignal;
|
|
510
|
+
}) => Promise<T>;
|
|
511
|
+
post: <T = unknown>(url: string, body?: unknown, options?: {
|
|
512
|
+
headers?: Record<string, string>;
|
|
513
|
+
signal?: AbortSignal;
|
|
514
|
+
}) => Promise<T>;
|
|
515
|
+
put: <T = unknown>(url: string, body?: unknown, options?: {
|
|
516
|
+
headers?: Record<string, string>;
|
|
517
|
+
signal?: AbortSignal;
|
|
518
|
+
}) => Promise<T>;
|
|
519
|
+
patch: <T = unknown>(url: string, body?: unknown, options?: {
|
|
520
|
+
headers?: Record<string, string>;
|
|
521
|
+
signal?: AbortSignal;
|
|
522
|
+
}) => Promise<T>;
|
|
523
|
+
delete: <T = unknown>(url: string, options?: {
|
|
524
|
+
headers?: Record<string, string>;
|
|
525
|
+
signal?: AbortSignal;
|
|
526
|
+
}) => Promise<T>;
|
|
512
527
|
[key: string]: any;
|
|
513
528
|
};
|
|
514
529
|
/** 数据管道(由 createApp 注入):ctx.data.get(key, fetcher) */
|
|
@@ -564,3 +579,11 @@ export interface RouteDef {
|
|
|
564
579
|
}
|
|
565
580
|
/** 扩展 ctx — 创建新对象,原 ctx 的 getter 通过原型链继承 */
|
|
566
581
|
export declare function extendCtx<T extends Record<string, unknown>>(ctx: WfuiContext, fields: T): WfuiContext & T;
|
|
582
|
+
/** SSR 数据种子(ssr.ts 序列化进 window.__DATA__ 脚本,hydration 时客户端读取) */
|
|
583
|
+
declare global {
|
|
584
|
+
interface Window {
|
|
585
|
+
__DATA__?: Record<string, unknown>;
|
|
586
|
+
}
|
|
587
|
+
var __DATA__: Record<string, unknown> | undefined;
|
|
588
|
+
}
|
|
589
|
+
export {};
|