weifuwu 0.74.0 → 0.75.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/dist/index.js CHANGED
@@ -3638,10 +3638,6 @@ var HtmlSafe = class {
3638
3638
  };
3639
3639
 
3640
3640
  // src/ui-dom/vnode.ts
3641
- var ASYNC_MARK = "__wfAsyncComponent";
3642
- function isAsyncComponent(type) {
3643
- return typeof type === "function" && type?.[ASYNC_MARK] === true;
3644
- }
3645
3641
  var Fragment = /* @__PURE__ */ Symbol("Fragment");
3646
3642
  var Portal = /* @__PURE__ */ Symbol("Portal");
3647
3643
 
@@ -3963,34 +3959,17 @@ async function renderSsr(input, ctx) {
3963
3959
  if (vnode.type === Portal) return renderSsr(vnode.props?.children, ctx);
3964
3960
  if (vnode.type === Fragment) return renderSsr(vnode.props?.children, ctx);
3965
3961
  if (typeof vnode.type === "function") {
3966
- const Comp = vnode.type;
3967
- if (isAsyncComponent(vnode.type)) {
3968
- const def = await vnode.type({}, ctx);
3969
- if (typeof def !== "function") {
3970
- throw new Error(
3971
- `asyncComponent factory <${vnode.type.name || "anonymous"}> must return a Component (initProps, ctx) => (props) => VNode.`
3972
- );
3973
- }
3974
- const childCtx2 = Object.create(ctx);
3975
- const renderFn2 = def(vnode.props ?? {}, childCtx2);
3976
- if (typeof renderFn2 !== "function") {
3977
- throw new Error(
3978
- `Component ${Comp.name || "anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`
3979
- );
3980
- }
3981
- return renderSsr(renderFn2(vnode.props ?? {}), childCtx2);
3982
- }
3983
3962
  const childCtx = Object.create(ctx);
3984
3963
  let renderFn;
3985
3964
  try {
3986
- renderFn = Comp(vnode.props ?? {}, childCtx);
3965
+ renderFn = vnode.type(vnode.props ?? {}, childCtx);
3987
3966
  } catch (e) {
3988
3967
  throw e;
3989
3968
  }
3990
3969
  if (renderFn instanceof Promise) renderFn = await renderFn;
3991
3970
  if (typeof renderFn !== "function") {
3992
3971
  throw new Error(
3993
- `Component ${Comp.name || "anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`
3972
+ `Component ${vnode.type.name || "anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`
3994
3973
  );
3995
3974
  }
3996
3975
  return renderSsr(renderFn(vnode.props ?? {}), childCtx);
@@ -4186,105 +4165,6 @@ function ui() {
4186
4165
  };
4187
4166
  }
4188
4167
 
4189
- // src/ui-dom/route-match.ts
4190
- function joinPaths(a, b) {
4191
- if (!b || b === "/") return a || "/";
4192
- const left = a.endsWith("/") ? a.slice(0, -1) : a;
4193
- const right = b.startsWith("/") ? b : "/" + b;
4194
- return left + right;
4195
- }
4196
- function compilePath(path) {
4197
- const keys = [];
4198
- const reStr = path.replace(/:(\w+)/g, (_, key) => {
4199
- keys.push(key);
4200
- return "([^/]+)";
4201
- }).replace(/\*/g, ".*");
4202
- return { re: new RegExp(`^${reStr}$`), keys };
4203
- }
4204
- function flattenRoutes(routes, basePath = "", chain = []) {
4205
- const result = [];
4206
- for (const route of routes) {
4207
- const fullPath = joinPaths(basePath, route.path);
4208
- const { re, keys } = compilePath(fullPath);
4209
- const fullChain = [...chain, route];
4210
- result.push({ re, keys, def: route, chain: fullChain });
4211
- if (route.children) {
4212
- result.push(...flattenRoutes(route.children, fullPath, fullChain));
4213
- }
4214
- }
4215
- return result;
4216
- }
4217
- function matchRoute(path, routes) {
4218
- let best = null;
4219
- for (const fr of routes) {
4220
- if (path.match(fr.re)) {
4221
- if (!best || fr.chain.length > best.chain.length) best = fr;
4222
- }
4223
- }
4224
- return best;
4225
- }
4226
- function extractParams(path, match) {
4227
- const params = {};
4228
- const m = path.match(match.re);
4229
- if (m) {
4230
- for (let i = 0; i < match.keys.length; i++) {
4231
- params[match.keys[i]] = safeDecode(m[i + 1]);
4232
- }
4233
- }
4234
- return params;
4235
- }
4236
- function safeDecode(s) {
4237
- try {
4238
- return decodeURIComponent(s);
4239
- } catch {
4240
- return s;
4241
- }
4242
- }
4243
-
4244
- // src/ui/ssr-page.ts
4245
- var DEFAULT_TEMPLATE = (p) => `<!DOCTYPE html>
4246
- <html lang="zh-CN">
4247
- <head>
4248
- <meta charset="UTF-8">
4249
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
4250
- <title>${escapeHtml(p.title)}</title>
4251
- ${(p.styles ?? []).map((s) => `<link rel="stylesheet" href="${escapeHtml(s)}">`).join("\n ")}
4252
- </head>
4253
- <body>
4254
- <div id="root">${p.html}</div>
4255
- ${p.dataScript}
4256
- ${p.bundle ? `<script src="${escapeHtml(p.bundle)}"></script>` : ""}
4257
- </body>
4258
- </html>`;
4259
- function escapeHtml(s) {
4260
- return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
4261
- }
4262
- function uiSsr(opts) {
4263
- const flatRoutes = flattenRoutes(opts.routes);
4264
- const template = opts.template ?? DEFAULT_TEMPLATE;
4265
- return async (req, ctx, next) => {
4266
- if (req.method !== "GET") return next(req, ctx);
4267
- const url = new URL(req.url);
4268
- const match = matchRoute(url.pathname, flatRoutes);
4269
- if (!match) return next(req, ctx);
4270
- const params = extractParams(url.pathname, match);
4271
- const def = match.chain[match.chain.length - 1] ?? match.def;
4272
- const pageCtx = Object.assign(Object.create(ctx), {
4273
- params,
4274
- route: { path: url.pathname, params, query: Object.fromEntries(url.searchParams) }
4275
- });
4276
- if (!def.component) return next(req, ctx);
4277
- const data = /* @__PURE__ */ new Map();
4278
- const html = await ssrToString(def.component, {}, pageCtx, { data });
4279
- const title = opts.title ? opts.title({ params, def }) : def.title || "weifuwu";
4280
- const dataScript = new HtmlSafe(serializeData(data)).toString();
4281
- const body = template({ html: html.toString(), dataScript, title, bundle: opts.bundle, styles: opts.styles });
4282
- return new Response(body, {
4283
- headers: { "Content-Type": "text/html; charset=utf-8" }
4284
- });
4285
- };
4286
- }
4287
-
4288
4168
  // src/db/postgres/connection.ts
4289
4169
  import net3 from "node:net";
4290
4170
  import crypto2 from "node:crypto";
@@ -8341,7 +8221,6 @@ export {
8341
8221
  serverError,
8342
8222
  tooManyRequests,
8343
8223
  ui,
8344
- uiSsr,
8345
8224
  unauthorized,
8346
8225
  unprocessable,
8347
8226
  userSystem,
@@ -32,7 +32,7 @@ declare module '../types.ts' {
32
32
  ui: {
33
33
  /** Tagged template → HTML Response */
34
34
  html: UiHtmlTag;
35
- /** 编译 TSX → JS bundle Response(支持包名 weifuwu/client 或文件路径) */
35
+ /** 编译 TSX → JS bundle Response(支持包名 weifuwu/ui-dom 或文件路径) */
36
36
  js: (entryPath: string) => Promise<Response>;
37
37
  /** 读取 CSS → CSS Response(支持包名 weifuwu/layout、weifuwu/components/style.css 或文件路径) */
38
38
  css: (entryPath: string) => Promise<Response>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * weifuwu/client AI 解码器 — 消费 wf: 协议(design/ai-contract.md)
2
+ * weifuwu/ui-dom AI 解码器 — 消费 wf: 协议(design/ai-contract.md)
3
3
  *
4
4
  * 协议的前端参考实现:POST → 解析 SSE → 按事件名分发回调。
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * weifuwu/client — 浏览器环境抽象(ctx.browser 的客户端实现)
2
+ * weifuwu/ui-dom — 浏览器环境抽象(ctx.browser 的客户端实现)
3
3
  *
4
4
  * 组件不直接引用 window/document——统一经 ctx.browser:
5
5
  * ① SSR 安全(createSsrContext 注入安全默认)② 测试可 mock
@@ -1,5 +1,5 @@
1
1
  /**
2
- * weifuwu/client 增量 diff — patchValue 及全部 diff 辅助
2
+ * weifuwu/ui-dom 增量 diff — patchValue 及全部 diff 辅助
3
3
  *
4
4
  * 从 render.ts 拆出(P2 结构拆分)。依赖方向:
5
5
  * diff.ts → render.ts(renderValue/mountComponent/patchPortal/renderPortal)
@@ -1,4 +1,4 @@
1
1
  /**
2
- * weifuwu/client — FocusTrap
2
+ * weifuwu/ui-dom — FocusTrap
3
3
  */
4
4
  export declare function trapFocus(container: HTMLElement): () => void;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * weifuwu/client Hydration(游标收养)— 收养服务端 HTML,不重建 DOM
2
+ * weifuwu/ui-dom Hydration(游标收养)— 收养服务端 HTML,不重建 DOM
3
3
  *
4
4
  * 从 render.ts 拆出(P2 结构拆分)。依赖:render.ts(flattenChildren/SVG 常量)、
5
5
  * diff.ts(patchProps)、registry.ts(idRegistry/nextComponentId/resolveAsyncFactory)。
@@ -22,7 +22,7 @@ export { callRefCleanup } from './render.ts';
22
22
  export { animateOut } from './motion.ts';
23
23
  export { patchValue } from './diff.ts';
24
24
  export { hydrateVNode } from './hydration.ts';
25
- export { isAsyncComponent, asyncComponent } from './vnode.ts';
25
+ export type { AsyncComponent } from './vnode.ts';
26
26
  export { api } from './middleware/api.ts';
27
27
  export type { ApiClient, ApiOptions, ApiRequestOptions, ApiInjected } from './middleware/api.ts';
28
28
  export { auth } from './middleware/auth.ts';
@@ -1,18 +1,20 @@
1
- function Un(e){let n=[],t=(e||"/").replace(/:(\w+)/g,(o,r)=>(n.push(r),"([^/]+)")).replace(/\*/g,".*");return{re:new RegExp(`^${t}$`),keys:n}}var Ae=class{_routes=[];_middlewares=[];_injections=[];_injected=!1;_mode;_notFound;constructor(n={}){this._mode=n.mode??"history"}get mode(){return this._mode}use(n,t){if(typeof n=="string"&&t){let o=this,r=n,c=async(i,s,l)=>{let u=s.__routePath??o.getPath(),d=null;return u===r?d="/":(r==="/"?u!=="/"&&u.startsWith("/"):u.startsWith(r+"/"))&&(d=u.slice(r.length)),d===null?l:async(p,v)=>{let b=await t._handle(d,p,v);return b===null?l(p,v):b}};return this._middlewares.push(c),this}return n.length<=1?(this._injections.push(n),this):(this._middlewares.push(n),this)}async _ensureInjected(n){if(!this._injected){this._injected=!0;for(let t of this._injections){let o=await t(n);o&&o!==n&&Object.assign(n,o)}}}get(n,t,o){return this._routes.push({path:n,handler:t,title:o?.title}),this}notFound(n){return this._notFound=n,this}getPath(){return this._getPath(void 0)}_getPath(n){let t=n?.location??(typeof window<"u"?window.location:null);return this._mode==="hash"?(t?.hash??"").replace(/^#/,"")||"/":t?.pathname??"/"}match(n){let t=null;for(let o of this._routes){let{re:r,keys:c}=Un(o.path),i=n.match(r);if(!i)continue;let s={};for(let l=0;l<c.length;l++)s[c[l]]=decodeURIComponent(i[l+1]);t={handler:o.handler,params:s,title:o.title};break}return t||(t={handler:this._notFound??(()=>null),params:{}}),t}async _handle(n,t,o){await this._ensureInjected(o);let r=this.match(n);r.title&&typeof document<"u"&&(document.title=r.title),o.params=r.params,o.route&&(o.route.params=r.params);let i=r.handler,s=o.__routePath;o.__routePath=n;try{for(let l=this._middlewares.length-1;l>=0;l--){let u=this._middlewares[l],d=i;i=await u(t,o,d)??d}return await i(t,o)}finally{o.__routePath=s}}async execute(n,t,o){await this._ensureInjected(t);let r=this.match(o);r.title&&typeof document<"u"&&(document.title=r.title),t.params=r.params,t.route&&(t.route.params=r.params);let i=r.handler;for(let s=this._middlewares.length-1;s>=0;s--){let l=this._middlewares[s],u=i;i=await l(n,t,u)??u}return await i(n,t)}};function ae(){return{idCounter:0,idRegistry:new Map,unmountHooks:[],asyncFactoryCache:new WeakMap}}function D(e){return e?.__registry??ae()}function he(e){return`_wf_${e.idCounter++}`}function ve(e,n){return e.unmountHooks.push(n),()=>{let t=e.unmountHooks.indexOf(n);t>=0&&e.unmountHooks.splice(t,1)}}function Ve(e,n,t){let o=e.asyncFactoryCache.get(n);if(o)return o;let r={promise:null};return r.promise=Promise.resolve().then(()=>n(void 0,t)).then(c=>{if(typeof c!="function")throw new Error(`asyncComponent factory <${n.name||"anonymous"}> must return a Component (initProps, ctx) => (props) => VNode.`);return r.resolved=c,c}),e.asyncFactoryCache.set(n,r),r}async function Qe(e,n,t){return Ve(e,n,t).promise}function Ze(e,n){return e.asyncFactoryCache.get(n)?.resolved}function Ie(e,n,t,o){try{e(n)}catch(r){console.error(`[weifuwu] ref ${t} error in <${o??"anonymous"}>`,r)}}function Hn(e,n){let t=e._child;if(t!=null)if(Array.isArray(t))for(let o of t)o&&typeof o=="object"&&O(o,n);else typeof t=="object"&&O(t,n)}function O(e,n){if(e==null||typeof e!="object")return;let t=e;if(t._id){if(t._customId&&n.idRegistry.delete(t._customId),n.idRegistry.delete(t._id),n.unmountHooks.length>0){let o=[...n.unmountHooks];for(let r of o)r(t._id);if(t._customId)for(let r of o)r(t._customId)}t._id=void 0,t._customId=void 0,t._render=void 0,t._parentNode=void 0,t._refNode=void 0}if(t._child!=null){if(Array.isArray(t._child))for(let o of t._child)o&&typeof o=="object"&&O(o,n);else O(t._child,n);t._child=void 0}if(t.props?.children&&typeof t.type=="string"){let o=Array.isArray(t.props.children)?t.props.children:[t.props.children];for(let r of o)r&&typeof r=="object"&&O(r,n)}typeof t.props?.ref=="function"&&Ie(t.props.ref,null,"cleanup"),t._remoteEl&&(Hn(t,n),t._remoteEl.remove(),t._remoteEl=void 0)}function j(){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,queryAll:e=>typeof document<"u"?document.querySelectorAll(e):null,createElement:e=>typeof document<"u"?document.createElement(e):null,createElementNS:(e,n)=>typeof document<"u"?document.createElementNS(e,n):null,createDocumentFragment:()=>typeof document<"u"?document.createDocumentFragment():null,createComment:e=>typeof document<"u"?document.createComment(e):null,createTextNode:e=>typeof document<"u"?document.createTextNode(e):null,addEventListener:(e,n,t)=>{typeof window<"u"&&window.addEventListener(e,n,t)},removeEventListener:(e,n,t)=>{typeof window<"u"&&window.removeEventListener(e,n,t)},scrollTo:e=>{typeof window<"u"&&window.scrollTo(0,e)},matchMedia:e=>typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(e):null,visualViewport:()=>(typeof window<"u"?window:null)?.visualViewport??null,scrollingElement:()=>typeof document<"u"?document.scrollingElement:null,bodyElement:()=>typeof document<"u"?document.body:null,bodyAppend:e=>{typeof document<"u"&&document.body.appendChild(e)},bodyRemove:e=>{typeof document<"u"&&e.parentNode&&document.body.removeChild(e)},clearBody:()=>{typeof document<"u"&&(document.body.innerHTML="")},event:(e,n)=>{let t=typeof window<"u"?window:null,o=n&&(n.key||n.code)?"KeyboardEvent":n&&(n.clientX!==void 0||n.clientY!==void 0||n.pointerId!==void 0)?"PointerEvent":"Event";try{return new t[o](e,n)}catch{return new t.Event(e,n)}},dispatchEvent:(e,n)=>typeof e<"u"?e.dispatchEvent(n):!1,navigate:e=>{typeof window>"u"||(window.history.pushState(null,"",e),window.dispatchEvent(new PopStateEvent("popstate",{state:null})))},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,viewportWidth:()=>typeof window<"u"?window.innerWidth:0,pathname:()=>typeof window<"u"?window.location.pathname:"",createTreeWalker:(e,n)=>typeof document<"u"?document.createTreeWalker(e,n??NodeFilter.SHOW_ALL):null,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{}}}}var en=j();function nn(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 we(e,n,t=8){if(!n)return e;let o=n.getBoundingClientRect();if(o.width===0&&o.height===0)return e;let r=Number.parseFloat(n.style.top)||o.top,c=Number.parseFloat(n.style.left)||o.left,i=e.top-r,s=e.left-c,l={top:o.top+i,bottom:o.bottom+i,left:o.left+s,right:o.right+s},u=en.viewportWidth(),d=en.viewportHeight(),p=e.top,v=e.left;return l.bottom>d-t&&(p=Math.max(t,p-(l.bottom-(d-t)))),l.top<t&&(p=Math.max(t,p+(t-l.top))),l.right>u-t&&(v=Math.max(t,v-(l.right-(u-t)))),l.left<t&&(v=Math.max(t,v+(t-l.left))),{top:p,left:v,width:e.width}}var oe=j();function tn(e){let n=new Map,t=new Map,o=!1,r=0;function c(){r||(r=requestAnimationFrame(()=>{r=0;let d=[];for(let[p,v]of n){if(!v.isOpen())continue;let b=v.getEl();if(!b)continue;let g=b.getBoundingClientRect();if(g.width===0&&g.height===0)continue;let h=v.compute(g);Object.assign(v.pos,we(h,v.panel?.(),v.margin)),d.push(p)}for(let[p,v]of t){let b=v.getScroller(),g=b instanceof Window?oe.scrollingElement()?.scrollTop??oe.scrollTop():b.scrollTop??0;g!==v.handle.y&&(v.handle.y=g,d.push(p))}d.length>0&&e(d)}))}function i(){o||(o=!0,oe.addEventListener("scroll",c,{capture:!0,passive:!0}),oe.addEventListener("resize",c))}function s(){o&&(oe.removeEventListener("scroll",c,{capture:!0}),oe.removeEventListener("resize",c),o=!1)}function l(d){for(let p of[...n.keys()])(p.startsWith(`popup:${d}:`)||p===`popup:${d}`)&&n.delete(p);t.delete(d)}function u(){s(),r&&(cancelAnimationFrame(r),r=0),n.clear(),t.clear()}return{popupTrackers:n,scrollTrackers:t,schedulePopupRecompute:c,ensurePopupListeners:i,destroyPopupListeners:s,cleanupTrackers:l,destroy:u}}var be=j(),le=0,on="",rn="",sn="",an="",Ce=0;function ln(){return typeof window<"u"&&typeof document<"u"}function un(){if(le++,le>1||!ln())return;Ce=be.scrollTop();let e=be.bodyElement();on=e.style.overflow,rn=e.style.position,sn=e.style.top,an=e.style.width,e.style.overflow="hidden",(/iPhone|iPad|iPod/.test(navigator.platform)||/Mac/.test(navigator.platform)&&"ontouchend"in document)&&(e.style.position="fixed",e.style.top=`-${Ce}px`,e.style.width="100%")}function dn(){if(le===0||(le--,le>0)||!ln())return;let e=be.bodyElement();e.style.overflow=on,e.style.position=rn,e.style.top=sn,e.style.width=an,Ce>0&&be.scrollTo(Ce)}var On='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])',Ue=j();function He(e){let n=e.querySelectorAll(On);if(n.length===0)return()=>{};let t=n[0],o=n[n.length-1],r=i=>{i.key==="Tab"&&(i.shiftKey&&Ue.activeElement()===t?(i.preventDefault(),o.focus()):!i.shiftKey&&Ue.activeElement()===o&&(i.preventDefault(),t.focus()))},c=Ue.activeElement();return queueMicrotask(()=>{t.focus()}),e.addEventListener("keydown",r),()=>{e.removeEventListener("keydown",r),c?.focus()}}var Te=null;function q(){return Te!==null||(Te=typeof process<"u"&&process.env?.UI_DEBUG==="1"||globalThis.__UI_DEBUG===!0||typeof localStorage<"u"&&localStorage.getItem("__UI_DEBUG")==="1"),Te}var Oe=0;function fn(){return++Oe}function Ee(){return--Oe}var cn=new Map;function W(e,n,t){if(!q())return;let o=(cn.get(e)??0)+1;cn.set(e,o);let r=10,c=t?.throttle??100;if(o>r&&o%c!==0)return;let i=t?.depth!==void 0?t.depth:Oe,s=" ".repeat(Math.min(i,30));console.log(`[ui-debug] ${s}${e}#${o} ${n}`)}function Q(e){let n=new Map,t=(s,l)=>{let u=(n.get(s)??0)+1;n.set(s,u),(u<=5||u%100===0)&&W(l,s+" count="+u,{throttle:100})},o=new WeakMap,r=new Set,c=s=>{if(s===null||typeof s!="object")return s;if(s instanceof Set||s instanceof Map){if(o.has(s))return o.get(s);let u=s instanceof Set?new Set(["add","delete","clear"]):new Set(["set","delete","clear"]),d=new Proxy(s,{get(p,v){let b=Reflect.get(p,v);return typeof b=="function"?u.has(String(v))?(...g)=>{let h=b.apply(p,g);e();for(let w of r)w();return h}:b.bind(p):b},set(p,v,b){Reflect.set(p,v,b),t(String(v),"set"),e();for(let g of r)g();return!0}});return o.set(s,d),d}if(s instanceof Date||s instanceof RegExp)return s;if(o.has(s))return o.get(s);let l=new Proxy(s,{set(u,d,p){if(Reflect.get(u,d)===p)return!0;Reflect.set(u,d,p),e();for(let b of r)b();return!0},get(u,d){let p=Reflect.get(u,d);return typeof p=="object"&&p!==null?c(p):p},deleteProperty(u,d){if(Reflect.has(u,d)){Reflect.deleteProperty(u,d),e();for(let p of r)p()}return!0}});return o.set(s,l),l},i=c({});return Object.defineProperty(i,"__watch",{value:s=>(r.add(s),()=>{r.delete(s)}),writable:!1,enumerable:!1}),i}function pn(e,n,t){let o=new AbortController,r=t?.signal;r&&(r.aborted?o.abort():r.addEventListener("abort",()=>o.abort(),{once:!0}));let c=t?.traceId??Fn(),i=t?.record!==!1,s=[],l=(async()=>{let u;try{u=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Trace-Id":c,Accept:"text/event-stream",...t?.headers},body:JSON.stringify(n),signal:o.signal})}catch(d){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:d instanceof Error?d.message:String(d)});return}if(!u.ok){t?.onError?.({code:qn(u.status),message:`HTTP ${u.status} ${u.statusText}`});return}try{for await(let{name:d,data:p}of Wn(u.body)){if(o.signal.aborted)return;jn(s,{name:d,data:p},i),Dn(d,p,t??{})}}catch(d){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:d instanceof Error?d.message:String(d)})}})();return{abort:()=>o.abort(),done:l,traceId:c,events:s}}function Dn(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*Wn(e){let n=e.getReader(),t=new TextDecoder,o="";try{for(;;){let{done:r,value:c}=await n.read();if(r)break;o+=t.decode(c,{stream:!0});let i=o.split(`
1
+ function Rn(e){let n=[],t=(e||"/").replace(/:(\w+)/g,(o,r)=>(n.push(r),"([^/]+)")).replace(/\*/g,".*");return{re:new RegExp(`^${t}$`),keys:n}}var Le=class{_routes=[];_middlewares=[];_injections=[];_injected=!1;_mode;_notFound;constructor(n={}){this._mode=n.mode??"history"}get mode(){return this._mode}use(n,t){if(typeof n=="string"&&t){let o=this,r=n,c=async(i,s,u)=>{let a=s.__routePath??o.getPath(),d=null;return a===r?d="/":(r==="/"?a!=="/"&&a.startsWith("/"):a.startsWith(r+"/"))&&(d=a.slice(r.length)),d===null?u:async(m,w)=>{let C=await t._handle(d,m,w);return C===null?u(m,w):C}};return this._middlewares.push(c),this}return n.length<=1?(this._injections.push(n),this):(this._middlewares.push(n),this)}async _ensureInjected(n){if(!this._injected){this._injected=!0;for(let t of this._injections){let o=await t(n);o&&o!==n&&Object.assign(n,o)}}}get(n,t,o){return this._routes.push({path:n,handler:t,title:o?.title}),this}notFound(n){return this._notFound=n,this}getPath(){return this._getPath(void 0)}_getPath(n){let t=n?.location??(typeof window<"u"?window.location:null);return this._mode==="hash"?(t?.hash??"").replace(/^#/,"")||"/":t?.pathname??"/"}match(n){let t=null;for(let o of this._routes){let{re:r,keys:c}=Rn(o.path),i=n.match(r);if(!i)continue;let s={};for(let u=0;u<c.length;u++)s[c[u]]=decodeURIComponent(i[u+1]);t={handler:o.handler,params:s,title:o.title};break}return t||(t={handler:this._notFound??(()=>null),params:{}}),t}async _handle(n,t,o){await this._ensureInjected(o);let r=this.match(n);r.title&&typeof document<"u"&&(document.title=r.title),o.params=r.params,o.route&&(o.route.params=r.params);let i=r.handler,s=o.__routePath;o.__routePath=n;try{for(let u=this._middlewares.length-1;u>=0;u--){let a=this._middlewares[u],d=i;i=await a(t,o,d)??d}return await i(t,o)}finally{o.__routePath=s}}async execute(n,t,o){await this._ensureInjected(t);let r=this.match(o);r.title&&typeof document<"u"&&(document.title=r.title),t.params=r.params,t.route&&(t.route.params=r.params);let i=r.handler;for(let s=this._middlewares.length-1;s>=0;s--){let u=this._middlewares[s],a=i;i=await u(n,t,a)??a}return await i(n,t)}};function ie(){return{idCounter:0,idRegistry:new Map,unmountHooks:[]}}function j(e){return e?.__registry??ie()}function me(e){return`_wf_${e.idCounter++}`}function ye(e,n){return e.unmountHooks.push(n),()=>{let t=e.unmountHooks.indexOf(n);t>=0&&e.unmountHooks.splice(t,1)}}function Ve(e,n,t,o){try{e(n)}catch(r){console.error(`[weifuwu] ref ${t} error in <${o??"anonymous"}>`,r)}}function Mn(e,n){let t=e._child;if(t!=null)if(Array.isArray(t))for(let o of t)o&&typeof o=="object"&&O(o,n);else typeof t=="object"&&O(t,n)}function O(e,n){if(e==null||typeof e!="object")return;let t=e;if(t._id){if(t._customId&&n.idRegistry.delete(t._customId),n.idRegistry.delete(t._id),n.unmountHooks.length>0){let o=[...n.unmountHooks];for(let r of o)r(t._id);if(t._customId)for(let r of o)r(t._customId)}t._id=void 0,t._customId=void 0,t._render=void 0,t._parentNode=void 0,t._refNode=void 0}if(t._child!=null){if(Array.isArray(t._child))for(let o of t._child)o&&typeof o=="object"&&O(o,n);else O(t._child,n);t._child=void 0}if(t.props?.children&&typeof t.type=="string"){let o=Array.isArray(t.props.children)?t.props.children:[t.props.children];for(let r of o)r&&typeof r=="object"&&O(r,n)}typeof t.props?.ref=="function"&&Ve(t.props.ref,null,"cleanup"),t._remoteEl&&(Mn(t,n),t._remoteEl.remove(),t._remoteEl=void 0)}function W(){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,queryAll:e=>typeof document<"u"?document.querySelectorAll(e):null,createElement:e=>typeof document<"u"?document.createElement(e):null,createElementNS:(e,n)=>typeof document<"u"?document.createElementNS(e,n):null,createDocumentFragment:()=>typeof document<"u"?document.createDocumentFragment():null,createComment:e=>typeof document<"u"?document.createComment(e):null,createTextNode:e=>typeof document<"u"?document.createTextNode(e):null,addEventListener:(e,n,t)=>{typeof window<"u"&&window.addEventListener(e,n,t)},removeEventListener:(e,n,t)=>{typeof window<"u"&&window.removeEventListener(e,n,t)},scrollTo:e=>{typeof window<"u"&&window.scrollTo(0,e)},matchMedia:e=>typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(e):null,visualViewport:()=>(typeof window<"u"?window:null)?.visualViewport??null,scrollingElement:()=>typeof document<"u"?document.scrollingElement:null,bodyElement:()=>typeof document<"u"?document.body:null,bodyAppend:e=>{typeof document<"u"&&document.body.appendChild(e)},bodyRemove:e=>{typeof document<"u"&&e.parentNode&&document.body.removeChild(e)},clearBody:()=>{typeof document<"u"&&(document.body.innerHTML="")},event:(e,n)=>{let t=typeof window<"u"?window:null,o=n&&(n.key||n.code)?"KeyboardEvent":n&&(n.clientX!==void 0||n.clientY!==void 0||n.pointerId!==void 0)?"PointerEvent":"Event";try{return new t[o](e,n)}catch{return new t.Event(e,n)}},dispatchEvent:(e,n)=>typeof e<"u"?e.dispatchEvent(n):!1,navigate:e=>{typeof window>"u"||(window.history.pushState(null,"",e),window.dispatchEvent(new PopStateEvent("popstate",{state:null})))},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,viewportWidth:()=>typeof window<"u"?window.innerWidth:0,pathname:()=>typeof window<"u"?window.location.pathname:"",createTreeWalker:(e,n)=>typeof document<"u"?document.createTreeWalker(e,n??NodeFilter.SHOW_ALL):null,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{}}}}var ze=W();function Xe(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 ge(e,n,t=8){if(!n)return e;let o=n.getBoundingClientRect();if(o.width===0&&o.height===0)return e;let r=Number.parseFloat(n.style.top)||o.top,c=Number.parseFloat(n.style.left)||o.left,i=e.top-r,s=e.left-c,u={top:o.top+i,bottom:o.bottom+i,left:o.left+s,right:o.right+s},a=ze.viewportWidth(),d=ze.viewportHeight(),m=e.top,w=e.left;return u.bottom>d-t&&(m=Math.max(t,m-(u.bottom-(d-t)))),u.top<t&&(m=Math.max(t,m+(t-u.top))),u.right>a-t&&(w=Math.max(t,w-(u.right-(a-t)))),u.left<t&&(w=Math.max(t,w+(t-u.left))),{top:m,left:w,width:e.width}}var te=W();function Qe(e){let n=new Map,t=new Map,o=!1,r=0;function c(){r||(r=requestAnimationFrame(()=>{r=0;let d=[];for(let[m,w]of n){if(!w.isOpen())continue;let C=w.getEl();if(!C)continue;let h=C.getBoundingClientRect();if(h.width===0&&h.height===0)continue;let g=w.compute(h);Object.assign(w.pos,ge(g,w.panel?.(),w.margin)),d.push(m)}for(let[m,w]of t){let C=w.getScroller(),h=C instanceof Window?te.scrollingElement()?.scrollTop??te.scrollTop():C.scrollTop??0;h!==w.handle.y&&(w.handle.y=h,d.push(m))}d.length>0&&e(d)}))}function i(){o||(o=!0,te.addEventListener("scroll",c,{capture:!0,passive:!0}),te.addEventListener("resize",c))}function s(){o&&(te.removeEventListener("scroll",c,{capture:!0}),te.removeEventListener("resize",c),o=!1)}function u(d){for(let m of[...n.keys()])(m.startsWith(`popup:${d}:`)||m===`popup:${d}`)&&n.delete(m);t.delete(d)}function a(){s(),r&&(cancelAnimationFrame(r),r=0),n.clear(),t.clear()}return{popupTrackers:n,scrollTrackers:t,schedulePopupRecompute:c,ensurePopupListeners:i,destroyPopupListeners:s,cleanupTrackers:u,destroy:a}}var he=W(),le=0,Ze="",en="",nn="",tn="",ve=0;function on(){return typeof window<"u"&&typeof document<"u"}function rn(){if(le++,le>1||!on())return;ve=he.scrollTop();let e=he.bodyElement();Ze=e.style.overflow,en=e.style.position,nn=e.style.top,tn=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=`-${ve}px`,e.style.width="100%")}function sn(){if(le===0||(le--,le>0)||!on())return;let e=he.bodyElement();e.style.overflow=Ze,e.style.position=en,e.style.top=nn,e.style.width=tn,ve>0&&he.scrollTo(ve)}var Ln='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])',Ie=W();function Ae(e){let n=e.querySelectorAll(Ln);if(n.length===0)return()=>{};let t=n[0],o=n[n.length-1],r=i=>{i.key==="Tab"&&(i.shiftKey&&Ie.activeElement()===t?(i.preventDefault(),o.focus()):!i.shiftKey&&Ie.activeElement()===o&&(i.preventDefault(),t.focus()))},c=Ie.activeElement();return queueMicrotask(()=>{t.focus()}),e.addEventListener("keydown",r),()=>{e.removeEventListener("keydown",r),c?.focus()}}var we=null;function q(){return we!==null||(we=typeof process<"u"&&process.env?.UI_DEBUG==="1"||globalThis.__UI_DEBUG===!0||typeof localStorage<"u"&&localStorage.getItem("__UI_DEBUG")==="1"),we}var Ue=0;function an(){return++Ue}function be(){return--Ue}var ln=new Map;function D(e,n,t){if(!q())return;let o=(ln.get(e)??0)+1;ln.set(e,o);let r=10,c=t?.throttle??100;if(o>r&&o%c!==0)return;let i=t?.depth!==void 0?t.depth:Ue,s=" ".repeat(Math.min(i,30));console.log(`[ui-debug] ${s}${e}#${o} ${n}`)}function Q(e){let n=new Map,t=(s,u)=>{let a=(n.get(s)??0)+1;n.set(s,a),(a<=5||a%100===0)&&D(u,s+" count="+a,{throttle:100})},o=new WeakMap,r=new Set,c=s=>{if(s===null||typeof s!="object")return s;if(s instanceof Set||s instanceof Map){if(o.has(s))return o.get(s);let a=s instanceof Set?new Set(["add","delete","clear"]):new Set(["set","delete","clear"]),d=new Proxy(s,{get(m,w){let C=Reflect.get(m,w);return typeof C=="function"?a.has(String(w))?(...h)=>{let g=C.apply(m,h);e();for(let v of r)v();return g}:C.bind(m):C},set(m,w,C){Reflect.set(m,w,C),t(String(w),"set"),e();for(let h of r)h();return!0}});return o.set(s,d),d}if(s instanceof Date||s instanceof RegExp)return s;if(o.has(s))return o.get(s);let u=new Proxy(s,{set(a,d,m){if(Reflect.get(a,d)===m)return!0;Reflect.set(a,d,m),e();for(let C of r)C();return!0},get(a,d){let m=Reflect.get(a,d);return typeof m=="object"&&m!==null?c(m):m},deleteProperty(a,d){if(Reflect.has(a,d)){Reflect.deleteProperty(a,d),e();for(let m of r)m()}return!0}});return o.set(s,u),u},i=c({});return Object.defineProperty(i,"__watch",{value:s=>(r.add(s),()=>{r.delete(s)}),writable:!1,enumerable:!1}),i}function un(e,n,t){let o=new AbortController,r=t?.signal;r&&(r.aborted?o.abort():r.addEventListener("abort",()=>o.abort(),{once:!0}));let c=t?.traceId??Hn(),i=t?.record!==!1,s=[],u=(async()=>{let a;try{a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Trace-Id":c,Accept:"text/event-stream",...t?.headers},body:JSON.stringify(n),signal:o.signal})}catch(d){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:d instanceof Error?d.message:String(d)});return}if(!a.ok){t?.onError?.({code:Un(a.status),message:`HTTP ${a.status} ${a.statusText}`});return}try{for await(let{name:d,data:m}of In(a.body)){if(o.signal.aborted)return;An(s,{name:d,data:m},i),Vn(d,m,t??{})}}catch(d){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:d instanceof Error?d.message:String(d)})}})();return{abort:()=>o.abort(),done:u,traceId:c,events:s}}function Vn(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*In(e){let n=e.getReader(),t=new TextDecoder,o="";try{for(;;){let{done:r,value:c}=await n.read();if(r)break;o+=t.decode(c,{stream:!0});let i=o.split(`
2
2
 
3
- `);o=i.pop()??"";for(let s of i){let l="message",u="";for(let d of s.split(`
4
- `))d.startsWith("event: ")?l=d.slice(7):d.startsWith("data: ")&&(u+=d.slice(6));if(u)try{yield{name:l,data:JSON.parse(u)}}catch{}}}}finally{n.releaseLock()}}function jn(e,n,t){t&&(e.length>=1e3&&e.shift(),e.push(n))}function qn(e){return e===401||e===403?"auth_failed":e===429?"rate_limited":e>=500?"provider_error":"invalid_request"}function Fn(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`trace-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function $n(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 mn(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 r(){if(!e.streaming)return;let b=e.messages[e.messages.length-1];return b&&b.role==="assistant"&&b.status==="streaming"?b:void 0}function c(b,g,h){let w=r();switch(b){case"wf:token":w&&(w.content+=g.text);break;case"wf:tool_call":{w&&(w.toolCalls||(w.toolCalls=[]),w.toolCalls.push({call:g,status:"running"}));break}case"wf:tool_progress":{let x=g,S=w?.toolCalls?.find(a=>a.call.id===x.toolCallId);S&&(S.progress=x);break}case"wf:tool_result":{let x=g,S=w?.toolCalls?.find(a=>a.call.id===x.id);S&&(S.result=x,S.status=x.ok?"ok":"error");break}case"wf:approval_request":w&&(w.approval=g);break;case"wf:usage":w&&(w.usage=g);break;case"wf:step":e.step=g;break;case"wf:done":w&&(w.status="done",w.approval=void 0),e.streaming=!1,e.step=null;break;case"wf:error":w&&(w.status="error",w.error=g,w.approval=void 0),e.error=g,e.streaming=!1,e.step=null;break;default:h?.(b,g);break}}function i(){let b=t.body?t.body(e.messages):{messages:$n(e.messages)};o=n(t.url,b,{onToken:h=>c("wf:token",{text:h}),onToolCall:h=>c("wf:tool_call",h),onToolProgress:h=>c("wf:tool_progress",h),onToolResult:h=>c("wf:tool_result",h),onApproval:h=>c("wf:approval_request",h),onUsage:h=>c("wf:usage",h),onStep:h=>c("wf:step",h),onDone:h=>c("wf:done",h),onError:h=>c("wf:error",h),onEvent:(h,w)=>c(h,w,t.onEvent)},{signal:t.signal,headers:t.headers}),e.streaming=!0;let g=r();g&&o?.traceId&&(g.id=o.traceId)}function s(){if(e.streaming)return;let b=String(e.input??"").trim();b&&(e.input="",e.error=null,e.usage=null,e.step=null,e.messages.push({id:De(),role:"user",content:b,status:"done"},{id:De(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),i())}function l(){o?.abort(),e.streaming=!1,e.step=null;let b=e.messages[e.messages.length-1];b&&b.role==="assistant"&&b.status==="streaming"&&(!b.content&&(!b.toolCalls||b.toolCalls.length===0)?e.messages.pop():b.status="done")}function u(){if(e.streaming)return;let b=-1;for(let g=e.messages.length-1;g>=0;g--)if(e.messages[g].role==="user"){b=g;break}b!==-1&&(e.messages.splice(b+1),e.error=null,e.usage=null,e.step=null,e.messages.push({id:De(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),i())}function d(){o?.abort(),e.messages=[],e.input="",e.streaming=!1,e.error=null,e.usage=null,e.step=null}async function p(b,g){let h=e.messages[e.messages.length-1],w=h?.role==="assistant"?h.approval:void 0;if(w&&(h.approval=void 0,!!t.approveUrl))try{await fetch(t.approveUrl,{method:"POST",headers:{"Content-Type":"application/json",...t.headers},body:JSON.stringify({id:w.id,decision:b,note:g}),signal:t.signal})}catch(x){if(t.signal?.aborted)return;e.error={code:"provider_error",message:x instanceof Error?x.message:String(x)}}}function v(){o?.abort(),o=null}return{send:s,stop:l,retry:u,clear:d,approve:p,dispose:v}}var yn="__wfAsyncComponent";function Bn(e){let n=(async(t,o)=>e(o));return n[yn]=!0,n}function ne(e){return typeof e=="function"&&e?.[yn]===!0}var G=Symbol("Fragment"),B=Symbol("Portal"),ue=(e,n)=>{let t=n._suspense;return()=>t?.fallback??null},We=(e,n)=>t=>t.children;function je(e,n,t){return{type:e,props:gn(n),key:t??void 0}}var Kn=je;function Gn(e,n,t){return je(e,n,t)}function de(e,n,...t){let o=gn(n??{});return t.length>0&&(o.children=t.length===1?t[0]:t),{type:e,props:o,key:n?.key??void 0}}function gn(e){if(!e)return{};let n={};for(let t of Object.keys(e))t!=="key"&&(n[t]=e[t]);return n}function qe(e,n){return{type:B,props:{children:e,portalKey:n},key:n??void 0,_placement:"remote"}}var xe=new Set,ce=new Map,_e=new Map,fe=new Map;function hn(e){let{ctx:n,renderByIds:t,getSelfId:o,dirtyBatch:r,dirtySet:c,mediaRegistry:i,popupTrackers:s,scrollTrackers:l,schedulePopupRecompute:u,ensurePopupListeners:d,isRendering:p,isMounting:v,setMounting:b,endMounting:g}=e,h=n.browser??j(),w=e.registry??D(n),x=a=>ve(w,a);return{_selfId:"_wf_root",_ctxVersion:0,_dirtySet:c,setMounting:b,endMounting:g,bumpCtxVersion:function(){this._ctxVersion++},render:function(a){if(p()){if(v())return;this._pendingRender||(this._pendingRender=!0,queueMicrotask(()=>{this._pendingRender=!1,this.render(a)}));return}if(!a||a.length===0){let f=o(this);if(f)a=[f];else return}t(a)},dirty:function(a){let f=this._selfId??"",m=this._debugDirty=(this._debugDirty??0)+1;if(W("dirty","self="+String(f).slice(0,20)+" ids="+JSON.stringify(a)+" n="+m+" mounting="+v()+" rendering="+p(),{throttle:200}),m<=3&&q()&&console.trace("[ui-debug]","dirty-trace",String(f).slice(0,20)),!v()){if(p()){this._pendingDirty||(this._pendingDirty=!0,queueMicrotask(()=>{this._pendingDirty=!1,this.dirty(a)}));return}if(!a||a.length===0){let y=o(this);if(y)a=[y];else return}for(let y of a)y&&(r.add(y),c.add(y));this._dirtyScheduled||(this._dirtyScheduled=!0,queueMicrotask(()=>{this._dirtyScheduled=!1;let y=[...r];r.clear(),y.length>0&&t(y)}))}},$:function(){let a=this;if(!Object.prototype.hasOwnProperty.call(a,"_$cache")){let f=Q(()=>{let m=a._selfVNode?._id??o(a);m&&n.ui.dirty([m])});a._$cache=f}return a._$cache},useChat:function(a){let f=this.$(),m=mn(f,pn,a);Object.assign(f,{send:m.send,stop:m.stop,retry:m.retry,clear:m.clear,approve:m.approve,dispose:m.dispose});let y=o(this);if(y){let C=x(T=>{T===y&&(m.dispose(),C())})}return f},useMedia:function(a,f){let y=`media:${o(this)}:${a}`;if(!i.has(y)){let C=h.matchMedia(a);f(C.matches);let T=_=>f(_.matches);C.addEventListener("change",T),i.set(y,{mql:C,handler:T})}},useBreakpoint:function(a,f){let m=typeof a=="function"?{mobile:"(max-width: 639px)",tablet:"(min-width: 640px) and (max-width: 1023px)",desktop:"(min-width: 1024px)"}:a,y=typeof a=="function"?a:f,T=`bp:${o(this)}`;function _(){for(let[P,M]of Object.entries(m))if(h.matchMedia(M).matches)return P;return Object.keys(m)[0]??""}if(!i.has(T)){y(_());let P=[];for(let M of Object.values(m)){let H=h.matchMedia(M),U=()=>y(_());H.addEventListener("change",U),P.push({mql:H,handler:U})}i.set(T,{mqls:P})}},usePopupPosition:function(a){let f=o(this),m={top:0,left:0,refresh:()=>{}};if(!f)return m;let y={pos:m,getEl:a.el,isOpen:a.isOpen,compute:a.compute,panel:a.panel,margin:a.margin??8};return s.set(f,y),d(),m.refresh=()=>{let C=y.getEl();if(!C)return;let T=C.getBoundingClientRect();if(T.width===0&&T.height===0)return;let _=y.compute(T);Object.assign(m,we(_,y.panel?.(),y.margin))},m},useHoverCapable:function(){return typeof window<"u"&&!!window.matchMedia?.("(hover: hover)").matches},useStableRef:function(a,f){return y=>{y?a(y):f?.()}},useVisualViewport:function(){let a=o(this),f={height:h.viewportHeight(),offsetTop:0,keyboardOpen:!1},m=()=>{n.ui&&n.ui.dirty(a?[a]:void 0)},y=()=>{let T=h.visualViewport();f.height=T?.height??h.viewportHeight(),f.offsetTop=T?.offsetTop??0,f.keyboardOpen=f.height<h.viewportHeight()*.9,m()},C=h.visualViewport();if(C?.addEventListener?(C.addEventListener("resize",y),C.addEventListener("scroll",y)):h.addEventListener("resize",y),a){let T=x(_=>{_===a&&(C?.removeEventListener?(C.removeEventListener("resize",y),C.removeEventListener("scroll",y)):h.removeEventListener("resize",y),T())})}return f},usePopup:function(a){let f=o(this),m=this.useHoverCapable(),y=()=>typeof a.trigger=="function"?a.trigger():a.trigger,C=a.open!==void 0,T=()=>!!a.disabled?.(),_=()=>C?typeof a.open=="function"?!!a.open():!!a.open:a.isOpen(),P=N=>{T()||(C?a.onOpenChange?.(N):a.setOpen(N))},M=()=>{let N=a.placement;return typeof N=="function"?N():N??"bottom"},H=null,U=!1,L=n.ui.usePopupPosition({el:a.el,isOpen:()=>_(),compute:N=>{if(a.position){let A=a.position();return{top:A.y,left:A.x}}return nn(N,M(),a.gap??6,a.center!==!1)},panel:()=>H,margin:a.margin??8}),k=N=>{if(a.closeOnOutside===!1||!_())return;let A=N.target;if(!(A instanceof Node))return;let K=a.el();K&&K.contains(A)||H&&H.contains(A)||P(!1)},R=N=>{a.closeOnEscape!==!1&&(N.key!=="Escape"||!_()||P(!1))};if(h.addEventListener("mousedown",k),h.addEventListener("keydown",R),f){let N=x(A=>{A===f&&(h.removeEventListener("mousedown",k),h.removeEventListener("keydown",R),N())})}let E={},V=N=>typeof N=="function"?N():N??0,I=()=>V(a.openDelay),Y=()=>V(a.closeDelay),J,z,kn=()=>{clearTimeout(J),clearTimeout(z),J=void 0,z=void 0},Sn=N=>{if(T())return;let A=N.currentTarget,K=N.relatedTarget;A.contains(K)||(clearTimeout(z),z=void 0,J=setTimeout(()=>{J=void 0,P(!0)},I()))},Rn=N=>{if(T())return;let A=N.currentTarget,K=N.relatedTarget;A.contains(K)||(clearTimeout(J),J=void 0,z=setTimeout(()=>{z=void 0,P(!1)},Y()))},Mn=()=>{T()||(clearTimeout(z),z=void 0,J=setTimeout(()=>{J=void 0,P(!0)},I()))},Ln=()=>{T()||(clearTimeout(J),J=void 0,z=setTimeout(()=>{z=void 0,P(!1)},Y()))},ie=()=>y()==="hover";if(E.onMouseOver=N=>{ie()&&Sn(N)},E.onMouseOut=N=>{ie()&&Rn(N)},E.onClick=()=>{ie()?m||P(!_()):y()==="click"&&P(!0)},E.onFocus=()=>{ie()&&Mn()},E.onBlur=()=>{ie()&&Ln()},y()==="longpress"){let N,A=0,K=0,X=()=>{clearTimeout(N),N=void 0};E.onPointerDown=$=>{T()||(A=$.clientX??0,K=$.clientY??0,X(),N=setTimeout(()=>{N=void 0,a.onTrigger?.({clientX:A,clientY:K}),P(!0)},a.longPressDuration??500))},E.onPointerUp=X,E.onPointerLeave=X,E.onPointerMove=$=>{let Me=Math.abs(($.clientX??0)-A),Le=Math.abs(($.clientY??0)-K);(Me>10||Le>10)&&X()},E.onContextMenu=$=>{$.preventDefault(),a.onTrigger?.({clientX:$.clientX??0,clientY:$.clientY??0}),P(!0)}}if(E.onKeyDown=N=>{N.key==="Escape"&&a.closeOnEscape!==!1&&P(!1)},f){let N=x(A=>{A===f&&(kn(),N())})}let An=N=>{if(N){H=N;let A=()=>L.refresh();N.addEventListener("animationend",A,{once:!0})}else H=null},Se=null,Re=null,Vn=N=>{An(N),Re&&Re(N)};return{get open(){return _()},setOpen:P,wrapProps:E,portal:(N,A="popover")=>{if(T())return null;if(!_())return U=!1,Se=null,null;let X=a.el();(!U||X!==Se)&&(X?L.refresh():queueMicrotask(()=>{_()&&L.refresh()}),U=!0,Se=X);let $=N.props??{};Re=$.ref??null;let Me=["wf-popup",$.class].filter(Boolean).join(" "),Le={...$.style??{},position:"fixed",top:`${L.top}px`,left:`${L.left}px`,maxWidth:a.width!==void 0?`min(${a.width}px, calc(100vw - 32px))`:"calc(100vw - 32px)"},In={...N,props:{...$,class:Me,style:Le,ref:Vn}};return qe(In,A)},refresh:()=>L.refresh()}},useLongPress:function(a){let{onLongPress:f,duration:m=500}=a,y,C=0,T=0,_=null,P=()=>{clearTimeout(y),y=void 0};return{onPointerDown:M=>{C=M.clientX??0,T=M.clientY??0,_=M,P(),y=setTimeout(()=>{y=void 0,_&&f(_)},m)},onPointerUp:P,onPointerLeave:P,onPointerMove:M=>{let H=Math.abs((M.clientX??0)-C),U=Math.abs((M.clientY??0)-T);(H>10||U>10)&&P()},onContextMenu:M=>{M.preventDefault(),f(M)}}},useInView:function(a){let f=o(this),m={isIn:!1,ready:!1,observe:P,refresh:M,disconnect:H},y=null,C=null,T=()=>{n.ui&&n.ui.dirty(f?[f]:void 0)};function _(){if(C?.disconnect(),C=null,!y)return;let U=typeof a.rootMargin=="function"?a.rootMargin():a.rootMargin,L=typeof a.threshold=="function"?a.threshold():a.threshold;C=new IntersectionObserver(k=>{let R=k[k.length-1];if(!R)return;let E=R.isIntersecting,V=E!==m.isIn,I=!m.ready;m.isIn=E,m.ready=!0,a.onChange?.(R,E),(V||I)&&T()},{root:a.root?a.root():null,rootMargin:U??"0px",threshold:L??0}),C.observe(y)}function P(U){y=U,U?_():(C?.disconnect(),C=null,m.isIn=!1)}function M(){_()}function H(){C?.disconnect(),C=null}return m},useScrollPosition:function(a){let f=o(this),m={y:0,refresh(){let C=y.getScroller();m.y=C instanceof Window?h.scrollingElement()?.scrollTop??h.scrollTop():C.scrollTop??0}},y={handle:m,getScroller:a.getScroller??(()=>window)};return f?(l.set(f,y),d(),m.refresh(),m):(m.refresh(),m)},useAsync:function(a){let f=o(this),m=Q(()=>{n.ui&&n.ui.dirty(f?[f]:void 0)});m.loading=!0;let y=0,C=()=>{let T=++y;m.loading=!0,m.error=null,Promise.resolve().then(()=>a()).then(_=>{y===T&&(m.data=_,m.loading=!1)}).catch(_=>{y===T&&(m.error=_,m.loading=!1)})};return C(),m.reload=C,m},useControlled:function(a){let f=o(this),m=a.value!==void 0;if(m&&!a.onChange&&a.name&&(xe.has(a.name)||(xe.add(a.name),console.warn(`[weifuwu/${a.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)}`))),!m&&f&&!ce.has(f)){ce.set(f,a.value);let C=x(T=>{T===f&&(ce.delete(f),C())})}let y=C=>{if(m){a.onChange?.(C);return}f&&ce.set(f,C),n.ui&&(f?n.ui.dirty([f]):n.ui.render())};return{value:m?a.value:f?ce.get(f):a.value,setValue:y,controlled:m}},useControlledInput:function(a){let f=o(this),m=this.useControlled({value:a.value,onChange:a.onChange,name:a.name});if(f&&!_e.has(f)){_e.set(f,{keyword:"",selectedLabel:""});let T=x(_=>{_===f&&(_e.delete(f),T())})}let y=f?_e.get(f):{keyword:"",selectedLabel:""},C=()=>{f?n.ui?.dirty([f]):n.ui?.render()};return{...m,get keyword(){return y.keyword},setKeyword(T){y.keyword=T,C()},get selectedLabel(){return y.selectedLabel},setSelectedLabel(T){y.selectedLabel=T,C()}}},useOpen:function(a){let f=o(this);if(f&&!fe.has(f)){fe.set(f,!1);let _=x(P=>{P===f&&(fe.delete(f),_())})}let m=a.open!==void 0;m&&!a.onOpenChange&&a.name&&!xe.has(a.name)&&(xe.add(a.name),console.warn(`[weifuwu/${a.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 y=()=>m?!!a.open:f?fe.get(f)??!1:!1,C=()=>{f?n.ui?.dirty([f]):n.ui?.render()},T=_=>{if(m){a.onOpenChange?.(_);return}f&&fe.set(f,_),C()};return{get open(){return y()},setOpen:T,triggerProps:{onClick:()=>T(!0),onFocus:()=>{a.openOnFocus&&T(!0)}}}},usePresence:function(a){let f=o(this),m="closed",y,C=()=>{m="closed",n.ui&&(f?n.ui.dirty([f]):n.ui.render())};return{get phase(){return m},ref:_=>{_?y||(y=()=>{m==="exit"&&C()},_.addEventListener("animationend",y)):y=void 0},sync:_=>(_?m="open":m==="open"&&(m="exit"),m)}},useDialog:function(a){let f=o(this),m,y=null,C=this.usePresence(a);return{get phase(){return C.phase},rootRef:P=>{P?(un(),y&&(m=He(y)),C.ref(P)):(dn(),m?.(),C.ref(null))},panelRef:P=>{y=P,P&&!m&&(m=He(P))},sync:P=>C.sync(P)}},useGlobalKey:function(a){let f=o(this);if(typeof window>"u")return()=>{};if(h.addEventListener("keydown",a),f){let m=x(y=>{y===f&&(h.removeEventListener("keydown",a),m())})}return()=>h.removeEventListener("keydown",a)},useDrag:function(a){let f=0,m=0,y=!1,C=P=>{y&&a.onMove(P,{x:P.clientX-f,y:P.clientY-m})},T=P=>{y&&(y=!1,h.removeEventListener("pointermove",C),h.removeEventListener("pointerup",T),a.onEnd?.(P))};return{onPointerDown:P=>{y||(P.preventDefault(),y=!0,f=P.clientX,m=P.clientY,h.addEventListener("pointermove",C),h.addEventListener("pointerup",T),a.onStart?.(P))}}},useDragDrop:function(a){let f={};a.onDrop&&(f.onDrop=y=>{y.preventDefault(),a.onDrop(y)}),a.onDragOver&&(f.onDragOver=y=>{y.preventDefault(),a.onDragOver(y)}),a.onDragLeave&&(f.onDragLeave=y=>a.onDragLeave(y));let m={draggable:!0};if(a.onDragStart){let y=a.onDragStart;m.onDragStart=C=>{typeof document<"u"&&document.body.classList.add("wf-dragging"),y(C)}}if(a.onDragEnd){let y=a.onDragEnd;m.onDragEnd=C=>{typeof document<"u"&&document.body.classList.remove("wf-dragging"),y(C)}}return{dropProps:f,dragProps:m}},useReducedMotion:function(){return typeof window<"u"&&!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches},useAnimationEnd:function(a,f){let m=null,y=()=>{a(),f?.once&&m&&m.removeEventListener("animationend",y)};return T=>{T?(m=T,T.addEventListener("animationend",y)):m&&(m.removeEventListener("animationend",y),m=null)}},useTween:function(a,f){let m=o(this),y=this.useReducedMotion(),C=f?.duration??400,T=f?.ease==="linear"?L=>L:L=>1-Math.pow(1-L,3),_,P=a,M={value:y?a:0,reset:()=>{}},H=()=>{n.ui&&(m?n.ui.dirty([m]):n.ui.render())},U=L=>{if(P=L,y){M.value=L,H();return}if(L===M.value)return;_&&cancelAnimationFrame(_);let k=M.value,R=performance.now(),E=V=>{let I=Math.min(1,(V-R)/C);M.value=Math.round(k+(L-k)*T(I)),I<1?(_=requestAnimationFrame(E),H()):(_=void 0,H())};_=requestAnimationFrame(E)};return M.reset=L=>{L===P&&_||U(L)},queueMicrotask(()=>U(a)),M},selfId:function(a){if(typeof a!="string"||!a)throw new Error(`[weifuwu] selfId requires a non-empty string, got ${typeof a}`);if(w.idRegistry.has(a))throw new Error(`[weifuwu] Duplicate component ID: "${a}". Each component must have a unique custom ID.`);let f=this._selfVNode;f&&(f._customId=a,w.idRegistry.set(a,f))}}}var vn=new WeakMap;function Yn(e){let n=vn.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 })")),vn.set(e,n)}function Z(e,n,t,o,r){if(q()){let u=t!=null&&typeof t=="object"?t.type?.name??String(t.type).slice(0,20):typeof t,d=o!=null&&typeof o=="object"?o.type?.name??String(o.type).slice(0,20):typeof o;W("patchValue","old="+u+" new="+d)}if(t==null){if(o==null)return null;let u=F(o,r);return u==null?null:(n&&n.parentNode?n.parentNode.insertBefore(u,n):e.appendChild(u),u)}if(o==null)return n?(O(t,D(r)),n.remove()):O(t,D(r)),null;let c=bn(t),i=bn(o);if(c!==i){O(t,D(r));let u=F(o,r);return u==null?null:(n?.parentNode&&n.parentNode.replaceChild(u,n),u)}if(i==="text")return n&&n.textContent!==String(o)&&(n.textContent=String(o)),n;let s=o,l=t;if(typeof s.type=="function"){let u=s.type;l.type===s.type&&(l._render||l._asyncDef)&&(l._render&&(s._render=l._render),s._id=l._id,s._id&&D(r).idRegistry.set(s._id,s)),l.type===s.type&&l._asyncDef&&(s._asyncDef=l._asyncDef),s._parentNode=e,n&&(s._refNode=n);let d=Object.create(r);d.ui=Object.create(r.ui);let p=d.ui;p._selfId=s._id,p._selfVNode=s,s._ctxVersion=l._ctxVersion??p._ctxVersion??0;let v=l._render&&l.type===s.type,b=Xn(l.props,s.props),g=!p._dirtySet?.has(l._id),h=s._ctxVersion===p._ctxVersion,w=u?.name??"anon";if(q()){let f=u?.name??"anon";W("tri-state-skip",f+" type="+v+" props="+b+" dirty="+g+" ver="+h)}if(v&&b&&g&&h)return s._child=l._child,n;p._dirtySet?.delete(l._id);let x;try{typeof s._render=="function"?x=s._render(s.props):x=Be(u,s.props,s,d)}catch(f){let m=r.ui?._errorHandler;m?(m(f),x=null):(console.error(`[weifuwu] Component render error in <${u?.name||"anonymous"}> (id: ${l._id??"?"}, phase: update)`,f),x=null)}let S=l._child;s._child=x;let a=Z(e,n,S,x,d);return a&&!s._refNode?s._refNode=a:a||(s._refNode=null),a}if(s.type===G){let u=l._childNodes,d=Tn(e,l,s,r,u);return s._childNodes=d,n}if(typeof s.type=="string"){if(n&&n.nodeType===1){let u=l.props?.ref,d=s.props?.ref;u!==d&&(typeof d=="function"&&d(n),typeof u=="function"&&typeof d=="function"&&Yn(n)),$e(n,l.props,s.props),Tn(n,l,s,r)}else if(n){O(t,D(r));let u=F(o,r);return u==null?null:(n.parentNode?.replaceChild(u,n),u)}else{let u=t.el??t._refNode;O(t,D(r)),u&&u.parentNode&&u.remove();let d=F(o,r);return d==null?null:(e.appendChild(d),d)}return n}if(s.type===B)return ye(l,s,r),null;if(Array.isArray(o)){let u=Array.isArray(t)?t:[];Pe(u,o);let d=Array.from(e.childNodes),p=n?d.indexOf(n):-1,v=p>=0?pe(d.slice(p),u):pe(d,u);return Ne(e,u,o,r,v,n),n}return n}var wn=new Map;function Jn(e){let n=wn.get(e);return n||(n=`fn:${e.name||"anon"}`,wn.set(e,n)),n}function bn(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"?Jn(n.type):n.type===G?"fragment":n.type===B?"portal":typeof n.type=="string"?"tag:"+n.type:"unknown"}function $e(e,n,t){q()&&W("patchProps","oldKeys="+(n?Object.keys(n).length:0)+" newKeys="+Object.keys(t).length);let o=n?Object.keys(n).filter(i=>i!=="children"&&i!=="key"&&i!=="innerHTML"):[],r=t?Object.keys(t).filter(i=>i!=="children"&&i!=="key"&&i!=="innerHTML"):[],c=new Set(r);for(let i of o){if(!n)break;if(!c.has(i)){if(i==="ref")continue;i.startsWith("on")&&typeof n[i]=="function"?e.removeEventListener(i.slice(2).toLowerCase(),n[i]):i==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value="":e.removeAttribute(i==="className"?"class":i)}}for(let i of r){if(i==="ref")continue;let s=n?.[i],l=t?.[i];if(i==="innerHTML")l!==s&&(e.innerHTML=String(l??""));else if(l!==s)if(i==="class"||i==="className")e instanceof SVGElement?e.setAttribute("class",Cn(l)):e.className=Cn(l);else if(i==="style"&&typeof l=="object"&&l!==null){let u=e.style,d=l;for(let p of Object.keys(d)){let v=d[p];v==null?p.startsWith("--")?u.removeProperty(p):u[p]="":p.startsWith("--")?u.setProperty(p,String(v)):u[p]=typeof v=="number"?v+"px":String(v)}}else if(i.startsWith("on")&&typeof l=="function"){let u=i.slice(2).toLowerCase();typeof s=="function"&&e.removeEventListener(u,s),e.addEventListener(u,l)}else i==="draggable"?e.setAttribute("draggable",l?"true":"false"):i==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value=String(l??""):l===!0?e.setAttribute(i,""):l!=null&&l!==!1?e.setAttribute(i,String(l)):i==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value="":e.removeAttribute(i)}}function Cn(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 Fe(e){if(!(e==null||typeof e!="object"))return Array.isArray(e)?void 0:e.key}function Pe(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 r=n[o];r&&typeof r=="object"&&!Array.isArray(r)&&(r.key=String(o))}for(let o=0;o<e.length;o++){let r=e[o];r&&typeof r=="object"&&!Array.isArray(r)&&(r.key=String(o))}}}function pe(e,n){let t=[],o=0;for(let r of n){if(r==null||typeof r=="boolean"){t.push(null);continue}let c=r;if(c.type===B){t.push(null);continue}if(c.type===G){let i=c._childNodes;Array.isArray(i)&&i.length>0?(t.push(i.slice()),o+=i.length):(t.push(e[o]?[e[o]]:null),o+=1)}else if(typeof c.type=="function")if(c._render){let i=c._childNodes??c._refNode;i==null?t.push(null):Array.isArray(i)?(t.push(i.slice()),o+=i.length):(t.push([i]),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=",c.type,"sourceLen=",e.length,"hit=",!!e[o]),t.push(e[o]?[e[o]]:null),o+=1}return t}function Tn(e,n,t,o,r){q()&&W("patchChildren","old="+n.props?.children?.length+" new="+t.props?.children?.length);let c=me(n.props?.children),i=me(t.props?.children);Pe(c,i);let s=r??Array.from(e.childNodes),l=pe(s,c),u=Ne(e,c,i,o,l,r?.[0]??null),d=[];for(let p of u)p&&p.length>0&&d.push(...p);return d}function me(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 Ne(e,n,t,o,r=[],c=null){if(q()&&W("patchKeyedChildren","old="+n.length+" new="+t.length),!t.some(g=>g&&typeof g=="object"&&!Array.isArray(g)&&g.key!==void 0&&g._placement!=="remote")){let g=Math.max(n.length,t.length);for(let h=0;h<g;h++){let w=h<n.length?n[h]:null,x=h<t.length?t[h]:null;if(x==null){if(w!=null){O(w,D(o));for(let S of r[h]??[])S.remove()}}else if(w==null){let S=F(x,o);if(S!=null){let a=null;for(let f=h+1;f<r.length;f++){let m=r[f]?.[0];if(m&&m.parentNode===e){a=m;break}}a?e.insertBefore(S,a):e.appendChild(S)}}else{let S=r[h]?.[0]??null;Z(e,S,w,x,o)}}return[]}for(let g=0;g<n.length;g++){let h=n[g];if(!(h==null||typeof h=="boolean")&&Fe(h)===void 0)for(let w of r[g]??[])w.remove()}let s=new Map,l=0;for(let g=0;g<n.length;g++){let h=Fe(n[g]);h!==void 0&&s.set(h,{vnode:n[g],nodes:r[g]??[],index:l++})}let u=t.map(g=>Fe(g)),d=new Set(u);for(let g of[...s.keys()])if(!d.has(g)){let h=s.get(g);O(h.vnode,D(o));for(let w of h.nodes)w?.remove();s.delete(g)}let p=new Array(t.length).fill(null),v=-1,b=c&&c.parentNode===e?c:e.firstChild;for(let g=0;g<t.length;g++){let h=u[g],w=t[g],x=h!==void 0?s.get(h):void 0,S=w&&typeof w=="object"&&w._placement==="remote";if(x)if(x.nodes.length>0){if(x.index<v)for(let f of x.nodes)e.insertBefore(f,b);v=Math.max(v,x.index),Z(e,x.nodes[0],x.vnode,w,o),p[g]=w._childNodes??x.nodes.filter(f=>f.parentNode===e),b=p[g][p[g].length-1]?.nextSibling??null}else if(S)ye(x.vnode,w,o),p[g]=[];else{let a=Z(e,null,x.vnode,w,o);p[g]=En(a);for(let m of p[g])e.insertBefore(m,b);b=p[g][p[g].length-1]?.nextSibling??null}else if(S)re(w,o),p[g]=[];else{let a=F(w,o);p[g]=En(a);for(let m of p[g])e.insertBefore(m,b);b=p[g][p[g].length-1]?.nextSibling??null}}return p}function zn(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 Xn(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(!zn(e[o],n[o]))return!1}else if(e[o]!==n[o])return!1}return!0}var te=j(),Ke="http://www.w3.org/2000/svg",Ge=new Set(["svg","path","circle","line","rect","text","g","polyline","polygon","ellipse","defs","use","clipPath","mask","linearGradient","radialGradient","stop","tspan"]);function F(e,n){let t=n.browser??te;if(q()){let s=e!=null&&typeof e=="object"?e.type?.name??String(e.type).slice(0,20):typeof e;W("renderValue","type="+s,{depth:fn()})}if(e==null||typeof e=="boolean")return q()&&Ee(),null;if(typeof e=="string"||typeof e=="number")return q()&&Ee(),t.createTextNode(String(e));if(Array.isArray(e)){let s=Zn(e,n);return q()&&Ee(),s}let o=e;if(o.type===B)return re(o,n),null;if(o.type===G){let s=t.createDocumentFragment(),l=o.props?.children==null?[]:Array.isArray(o.props.children)?o.props.children:[o.props.children];for(let u of l){let d=F(u,n);d!=null&&s.appendChild(d)}return o._childNodes=Array.from(s.childNodes),s}if(typeof o.type=="function")return Qn(o.type,o.props,o,n);let r=o.type,c=Ge.has(r)?t.createElementNS(Ke,r):t.createElement(r);if(!c)return null;o.el=c;let i;for(let[s,l]of Object.entries(o.props??{}))s==="children"||s==="key"||s==="value"||s==="innerHTML"||_n(c,s,l);if("value"in(o.props??{})&&c instanceof HTMLSelectElement?i=o.props.value:"value"in(o.props??{})&&_n(c,"value",o.props.value),"innerHTML"in(o.props??{}))c.innerHTML=String(o.props.innerHTML??"");else{let s=Ye(o.props?.children);for(let l of s){let u=F(l,n);if(u!=null&&(c.appendChild(u),l&&typeof l=="object"&&typeof l.type=="function")){let d=l;d._parentNode||(d._parentNode=c,d._refNode=u)}}}return i!==void 0&&(c.value=String(i)),typeof o.props?.ref=="function"&&Ie(o.props.ref,c,"mount",r),c}function xn(e){let n=e.__scheduleRender;if(typeof n=="function"){n();return}let t=e.ui;t&&typeof t.render=="function"&&t.render(["_wf_root"])}function Be(e,n,t,o){if(q()){let l=e?.name??(typeof e=="function"?"fn":typeof e);W("mountComponent",l+" id="+String(t.id??"").slice(0,10))}let r=globalThis;if(r.__wf_mountCount===void 0&&(r.__wf_mountCount=0),++r.__wf_mountCount>500)throw r.__wf_mountCount=0,new Error("[wf-render] mountComponent \u8D85\u8FC7 500 \u6B21\u2014\u2014\u6E32\u67D3\u6B7B\u5FAA\u73AF\uFF08\u65E0\u9650\u6302\u8F7D\uFF09");let c=o.browser??te,i;if(ne(e)){if(i=Ze(D(o),e),!i)return Ve(D(o),e,o).promise.then(()=>xn(o),()=>{}),de(ue,{})}else{let l=t._asyncDef;if(l instanceof Promise)return de(ue,{});if(typeof l=="function")return t._render=l,l(n);o.ui?.setMounting?.(!0);let u;try{u=e(n,o)}finally{o.ui?.endMounting?.()}if(u instanceof Promise){let p=u;return t._asyncDef=p,p.then(v=>{if(typeof v!="function")throw new Error(`Component ${e.name||"anonymous"} async factory must return a render function. (props) => VNode pattern.`);t._asyncDef=v,xn(o)},()=>{}),de(ue,{})}if(typeof u!="function")throw new Error(`Component ${e.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);let d=u;return t._render=d,d(n)}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 Qn(e,n,t,o){let r=o.browser??te;if(!t._id){let u=D(o);t._id=he(u),u.idRegistry.set(t._id,t)}let c=Object.create(o);t.type===We&&(c._suspense={fallback:t.props?.fallback}),c.ui=Object.create(o.ui);let i=c.ui;i._selfId=t._id,i._selfVNode=t,t._ctxVersion=i._ctxVersion??0;let s;try{s=Be(e,n,t,c)}catch(u){let d=o.ui?._errorHandler;d?(d(u),s=null):(console.error(`[weifuwu] Component render error in <${e.name||"anonymous"}> (id: ${t._id??"?"}, phase: mount)`,u),s=null)}if(s==null){if(t._child=null,c.ui?._errorHandler){let d=r.createComment("wf-empty");return t._refNode=d,d}return null}t._child=s;let l=F(s,c);return t._refNode||(t._refNode=l),l}function Zn(e,n){let o=(n.browser??te).createDocumentFragment();for(let r of e){let c=F(r,n);c!=null&&o.appendChild(c)}return o}function et(){let e=te,n=e.byId("__wf_portal");if(!n){if(n=e.createElement("div"),!n)throw new Error("[ui-dom] portal container creation failed");n.id="__wf_portal",n.style.cssText="position:fixed;inset:0;pointer-events:none;z-index:9999",e.bodyAppend(n)}return n}function re(e,n){let t=n.browser??te,o=et(),r=t.createElement("div");r.style.pointerEvents="auto",o.appendChild(r),e._remoteEl=r;let c=me(e.props?.children);e._child=c;for(let i of c){let s=F(i,n);s!=null&&r.appendChild(s)}}function ye(e,n,t){let o=t.browser??te,r=e?._remoteEl;if(n._remoteEl=r,!r){re(n,t);return}let c=me(n.props?.children),i=e._child||[];n._child=c,Pe(i,c);let s=pe(Array.from(r.childNodes),i);Ne(r,i,c,t,s,s[0]?.[0]??null)}function Ye(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 _n(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 r of Object.keys(t)){let c=t[r];c!=null&&(r.startsWith("--")?o.setProperty(r,String(c)):o[r]=typeof c=="number"?c+"px":String(c))}}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 nt(e,n,t){e.innerHTML="";let o=F(n,t);o instanceof Node&&e.appendChild(o)}function tt(e){O(e,ae())}function Je(e){e.node=e.node?e.node.nextSibling:null}function ot(e,n){e.node&&e.node.parentNode?e.node.parentNode.insertBefore(n,e.node):e.parent.appendChild(n)}function rt(e,n){e.node&&e.node.parentNode?(e.node.parentNode.replaceChild(n,e.node),Je(e)):e.parent.appendChild(n)}async function ge(e,n,t){let o=n.browser??j();if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number"){let l=String(e);if(t.node&&t.node.nodeType===3)return t.node.textContent!==l&&(t.node.textContent=l),Je(t),t.node;let u=o.createTextNode(l);return ot(t,u),u}if(Array.isArray(e)){let l=null;for(let u of e){let d=await ge(u,n,t);d!=null&&!l&&(l=d)}return l}let r=e;if(r.type===B||r.type===G){let l=r.props?.children,u=l==null?[]:Array.isArray(l)?l:[l],d=null;for(let p of u){let v=await ge(p,n,t);v!=null&&!d&&(d=v)}return d}if(typeof r.type=="function")return st(r,n,t);let c=r.type,i=r.props??{},s;if(t.node&&t.node.nodeType===1&&t.node.tagName.toLowerCase()===c.toLowerCase()?(s=t.node,Je(t)):(s=Ge.has(c)?o.createElementNS(Ke,c):o.createElement(c),rt(t,s)),r.el=s,$e(s,null,i),!("innerHTML"in i)){let l={parent:s,node:s.firstChild},u=Ye(i.children);for(let d of u){let p=await ge(d,n,l);if(p!=null&&p.parentNode!==s&&s.appendChild(p),d&&typeof d=="object"&&typeof d.type=="function"){let v=d;v._parentNode||(v._parentNode=s,v._refNode=p)}}for(;l.node;){let d=l.node;l.node=d.nextSibling,d.parentNode?.removeChild(d)}}return"value"in i&&s instanceof HTMLSelectElement&&(s.value=String(i.value??"")),typeof i.ref=="function"&&i.ref(s),s}async function st(e,n,t){if(!e._id){let l=D(n);e._id=he(l),l.idRegistry.set(e._id,e)}let o=Object.create(n);o.ui=Object.create(n.ui);let r=o.ui;r._selfId=e._id,r._selfVNode=e,e._ctxVersion=r._ctxVersion??0;let c=e.type,i;try{let l;if(ne(c)?l=(await Qe(D(n),c,o))(e.props??{},o):(l=c(e.props??{},o),l instanceof Promise&&(l=await l)),typeof l!="function")throw new Error(`Component ${c.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);e._render=l,i=l(e.props??{})}catch(l){let u=n.ui?._errorHandler;u?(u(l),i=null):(console.error(`[weifuwu] Component hydration error in <${c.name||"anonymous"}> (id: ${e._id??"?"})`,l),i=null)}if(i==null)return e._child=null,null;e._child=i;let s=await ge(i,o,t);return e._refNode||(e._refNode=s),s}async function ze(e,n,t){let o={parent:e,node:e.firstChild};for(await ge(n,t,o);o.node;){let r=o.node;o.node=r.nextSibling,r.parentNode?.removeChild(r)}}function it(e,n){let t=j(),o=typeof n.root=="string"?t.query(n.root):n.root;if(!o)throw new Error(`uiServe: root not found: ${n.root}`);let r=o,c=!!n.hydrate;c||(r.innerHTML="");let i=ae(),s=new Set,l=0,u=new Set,d=new Map,p=!1,v=!1,b=[];function g(k){b.push(v),v=k}function h(){v=b.pop()??!1}let w={params:{},query:{}};w.__scheduleRender=M;let x=new Map,S=globalThis.__DATA__??window.__DATA__;if(S&&typeof S=="object")for(let[k,R]of Object.entries(S))x.set(k,{value:R});w.data={async get(k,R){let E=x.get(k);if(E&&"value"in E)return E.value;if(E?.promise)return E.promise;if(!R)return;let V=Promise.resolve().then(()=>R()).then(I=>(x.set(k,{value:I}),I));return x.set(k,{promise:V}),V},set(k,R){x.set(k,{value:R})},has(k){return x.has(k)}};let a=!1;function f(){s.size>0&&!a&&(a=!0,queueMicrotask(()=>{a=!1;let k=[...s];s.clear(),k.length>0&&(W("flushDirty","ids="+JSON.stringify(k)),m(k))}))}function m(k){if(!p){p=!0;for(let R of k){let E=i.idRegistry.get(R);if(!E||!E._render)continue;W("renderByIds-start",R+" render="+String(E._render.name).slice(0,30)),w.ui._dirtySet?.delete(R);let V=E._child,I=E._render(E.props);if(E._child=I,V&&V._placement==="remote"||I&&I._placement==="remote"){V&&I?ye(V,I,w):I?re(I,w):V&&O(V,i);continue}if(!E._parentNode&&E._refNode){let Y=E._refNode.parentNode;Y&&(E._parentNode=Y)}if(E._parentNode){let Y=Z(E._parentNode,E._refNode??null,V,I,w);Y&&Y!==E._refNode?E._refNode=Y:Y||(E._refNode=null)}W("renderByIds-done",R)}p=!1,f()}}let y=null;function C(){return y||(y=tn(k=>w.ui.render(k))),y}w.browser=t,w.__registry=i,w.ui=hn({ctx:w,renderByIds:m,getSelfId:k=>k?._selfId??w.ui?._selfId,dirtyBatch:s,dirtySet:u,mediaRegistry:d,popupTrackers:C().popupTrackers,scrollTrackers:C().scrollTrackers,schedulePopupRecompute:C().schedulePopupRecompute,ensurePopupListeners:C().ensurePopupListeners,destroyPopupListeners:C().destroyPopupListeners,isRendering:()=>p,isMounting:()=>v,setMounting:g,endMounting:h,registry:i}),ve(i,k=>{for(let R of[...d.keys()])if(R.startsWith(`media:${k}:`)||R===`bp:${k}`){let E=d.get(R);E?.mql&&E.handler&&E.mql.removeEventListener("change",E.handler),E?.mqls?.forEach(({mql:V,handler:I})=>V.removeEventListener("change",I)),d.delete(R)}C().cleanupTrackers(k)}),w.__rerender=()=>M(),w.app={navigate:k=>{e.mode==="hash"?t.setHash("#"+k):t.navigate(k),M()}};let T=null,_=!1,P=!1;function M(){P||(P=!0,queueMicrotask(()=>{P=!1,H()}))}async function H(){if(!_){W("doRender","path="+e.getPath()),_=!0;try{let k=e.getPath();if(w.route={path:k,params:w.params,query:w.query},!w.__state){let E=Q(()=>{_||M()});w.__state=E;let V=w.ui.$;w.ui.$=function(){return this&&this._selfVNode?V.call(this):E}}let R=await e.execute(window.location,w,k);if(T==null){if(R){let E=c&&r.firstElementChild?(ze(r,R,w),r.firstChild):F(R,w);E&&E.parentNode!==r&&r.appendChild(E)}}else{let E=Z(r,r.firstChild,T,R,w);E&&E.parentNode!==r&&r.appendChild(E)}T=R}catch(k){if(console.error("[ui-dom] render error:",k),T==null){let R=t.createElement("div");R.className="ui-dom-error",R.textContent=`\u6E32\u67D3\u9519\u8BEF: ${k?.message??String(k)}`,r.appendChild(R)}}finally{_=!1}}}let U=()=>M();t.addEventListener("popstate",U);let L=()=>M();return e.mode==="hash"&&t.addEventListener("hashchange",L),M(),{get ctx(){return w},close(){t.removeEventListener("popstate",U),e.mode==="hash"&&t.removeEventListener("hashchange",L),T&&O(T,i),C().destroy(),i.idRegistry.clear(),r.innerHTML="",T=null}}}function at(e,n,t=400){let o=!1,r=()=>{o||(o=!0,e.removeEventListener("animationend",r),clearTimeout(c),n())};e.addEventListener("animationend",r);let c=setTimeout(r,t)}function se(e,n){return Object.assign(Object.create(e),n)}function lt(e){let n={baseURL:e?.baseURL??"",headers:{"Content-Type":"application/json",...e?.headers}},t=e?.onRequest,o=e?.onResponse,r=e?.timeout??0;async function c(i,s,l,u){let d=n.baseURL+s,p={method:i,headers:{...n.headers,...u?.headers}},v=e?.token?.();v&&!p.headers.Authorization&&(p.headers.Authorization=`Bearer ${v}`);let b=r>0,g=!!u?.signal,h=null,w=null;(b||g)&&(h=new AbortController,p.signal=h.signal,b&&(w=setTimeout(()=>h.abort(new Error("Request timed out")),r)),g&&u.signal.addEventListener("abort",()=>h.abort())),l!==void 0&&i!=="GET"&&i!=="HEAD"&&(p.body=JSON.stringify(l));let x={url:d,init:p};t&&(x=t(x));try{let S=await fetch(x.url,x.init);if(o)return o(S);if(!S.ok){let m=await S.text().catch(()=>"");throw new Xe(S.status,m||S.statusText)}let a=S.headers.get("content-length");if(S.status===204||a==="0")return;let f=(S.headers.get("content-type")||"").toLowerCase();return f.includes("application/json")||f.includes("json")?S.json():S.text()}finally{w&&clearTimeout(w)}}return i=>se(i,{api:{get:(l,u)=>c("GET",l,void 0,u),post:(l,u,d)=>c("POST",l,u,d),put:(l,u,d)=>c("PUT",l,u,d),patch:(l,u,d)=>c("PATCH",l,u,d),delete:(l,u)=>c("DELETE",l,void 0,u)}})}var Xe=class extends Error{status;body;constructor(n,t){super(`API Error ${n}: ${t}`),this.name="ApiError",this.status=n,this.body=t}};function ut(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 dt(e){let n=ut(e);return n?.exp?n.exp*1e3-3e4<Date.now():!0}function ct(e){let n=e?.storage??localStorage,t=e?.tokenKey??"weifuwu_token",o=e?.userKey??"weifuwu_user",r=e?.refreshTokenKey??"weifuwu_refresh",c=e?.refreshEndpoint??"/api/auth/refresh";return i=>{let s=n.getItem(t),l=n.getItem(o),u={token:s,user:l?JSON.parse(l):null,get isLoggedIn(){return this.token!==null},login(d,p,v){u.token=d,u.user=p,n.setItem(t,d),n.setItem(o,JSON.stringify(p)),v&&n.setItem(r,v)},logout(){u.token=null,u.user=null,n.removeItem(t),n.removeItem(o),n.removeItem(r)},setUser(d){u.user=d,n.setItem(o,JSON.stringify(d))},async refresh(){let d=n.getItem(r);if(!d)return!1;try{let p=await fetch(c,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:d})});if(!p.ok)return u.logout(),!1;let v=await p.json();return u.token=v.token,n.setItem(t,v.token),v.refreshToken&&n.setItem(r,v.refreshToken),!0}catch{return!1}}};return s&&dt(s)&&u.refresh().catch(()=>{}),se(i,{auth:u})}}function ft(e={}){let n=e.url??"/ws",t=e.reconnectInterval??3e3,o=e.maxReconnect??10,r=e.pingInterval??3e4,c=e.pingTimeout??1e4;return i=>{let s=new Set,l=null,u=0,d=null,p=null,v=null,b=!1,g={isConnected:!1,onMessage:a=>(s.add(a),()=>{s.delete(a)}),send:a=>{l?.readyState===WebSocket.OPEN&&l.send(JSON.stringify(a))},_connect:h,close:()=>{b=!0,S(),l?.close(),l=null,g.isConnected=!1}};async function h(){if(!b)try{l=new WebSocket(n),l.onopen=()=>{g.isConnected=!0,u=0,w()},l.onmessage=a=>{try{let f=JSON.parse(a.data);for(let m of s)m(f)}catch{}x()},l.onclose=()=>{g.isConnected=!1,S(),!b&&u<o&&(u++,d=setTimeout(h,t*Math.min(u,5)))},l.onerror=()=>{l?.close()}}catch{b||(d=setTimeout(h,t))}}function w(){r<=0||(p=setInterval(()=>{l?.readyState===WebSocket.OPEN&&l.send(JSON.stringify({type:"ping"})),v=setTimeout(()=>{l?.close()},c)},r))}function x(){clearTimeout(v)}function S(){clearInterval(p),clearTimeout(v),clearTimeout(d)}return h(),se(i,{ws:g})}}function ke(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}var pt=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function mt(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 yt(e){return typeof e=="string"?e:e&&typeof e=="object"?Object.entries(e).filter(([,n])=>n!=null).map(([n,t])=>`${n}:${typeof t=="number"?t+"px":String(t)}`).join(";"):""}function Pn(e,n){let t=new Set,o={$:()=>Q(()=>{}),dirty:()=>{},render:()=>{},selfId:i=>{if(t.has(i))throw new Error(`[weifuwu] Duplicate component ID: "${i}"`);t.add(i)},useMedia:()=>{},useBreakpoint:()=>{},usePopupPosition:()=>({top:0,left:0,refresh:()=>{}}),useHoverCapable:()=>!1,useVisualViewport:()=>({height:0,offsetTop:0,keyboardOpen:!1}),useLongPress:()=>({}),useInView:()=>({isIn:!1,ready:!1,observe:()=>{},refresh:()=>{},disconnect:()=>{}}),useScrollPosition:()=>({y:0,refresh:()=>{}}),useStableRef:i=>s=>{s&&i?.(s)},useGlobalKey:()=>()=>{},useReducedMotion:()=>!1,useAnimationEnd:()=>()=>{},useTween:i=>{let s={value:i,reset:l=>{s.value=l}};return s},useDrag:()=>({onPointerDown:()=>{}}),useDragDrop:()=>({dropProps:{},dragProps:{}}),useControlled:i=>({value:i.value,setValue:s=>{i.onChange?.(s)},controlled:i.value!==void 0}),useControlledInput:i=>({value:i.value,setValue:s=>{i.onChange?.(s)},controlled:i.value!==void 0,keyword:"",setKeyword:()=>{},selectedLabel:"",setSelectedLabel:()=>{}}),useOpen:i=>({get open(){return!!i.open},setOpen:s=>{i.onOpenChange?.(s)},triggerProps:{}}),useAsync:()=>({data:void 0,loading:!0,error:void 0,reload:()=>{}}),usePopup:()=>({open:!1,setOpen:()=>{},wrapProps:{},portal:()=>null,refresh:()=>{}}),usePresence:()=>({phase:"closed",ref:()=>{},sync:i=>i?"open":"closed"}),useDialog:()=>({phase:"closed",rootRef:()=>{},panelRef:()=>{},sync:i=>i?"open":"closed"}),useChat:()=>({messages:[],input:"",streaming:!1,error:null,usage:null,step:null,send:()=>{},stop:()=>{},retry:()=>{},clear:()=>{},approve:async()=>{},dispose:()=>{}})},r={activeElement:()=>null,byId:()=>null,query:()=>null,queryAll:()=>null,createElement:()=>null,createElementNS:()=>null,createDocumentFragment:()=>null,createComment:()=>null,createTextNode:()=>null,addEventListener:()=>{},removeEventListener:()=>{},scrollTo:()=>{},matchMedia:()=>null,visualViewport:()=>null,scrollingElement:()=>null,bodyElement:()=>null,bodyAppend:()=>{},bodyRemove:()=>{},clearBody:()=>{},event:()=>new Event("wf-ssr"),dispatchEvent:()=>!1,navigate:()=>{},createTreeWalker:()=>null,copyText:async()=>!1,execCommand:()=>!1,selectionText:()=>null,getSelection:()=>null,queryCommandState:()=>!1,queryCommandValue:()=>"",viewportHeight:()=>0,viewportWidth:()=>0,pathname:()=>"",scrollTop:()=>0,hash:()=>"",setHash:()=>{},timeout:()=>0,rootElement:()=>null,storageGet:()=>null,storageSet:()=>{}},c=Object.create(e??{});return c.ui=o,c.browser=r,c.data={async get(i,s){if(n.has(i))return n.get(i);if(!s)return;let l=await s();return n.set(i,l),l},set(i,s){n.set(i,s)},has(i){return n.has(i)}},c}async function ee(e,n){if(e==null||typeof e=="boolean")return"";if(typeof e=="string"||typeof e=="number")return ke(String(e));if(Array.isArray(e)){let u="";for(let d of e)u+=await ee(d,n);return u}let t=e;if(t.type===B||t.type===G)return ee(t.props?.children,n);if(typeof t.type=="function"){let u=t.type;if(ne(t.type)){let v=await t.type({},n);if(typeof v!="function")throw new Error(`asyncComponent factory <${t.type.name||"anonymous"}> must return a Component (initProps, ctx) => (props) => VNode.`);let b=Object.create(n),g=v(t.props??{},b);if(typeof g!="function")throw new Error(`Component ${u.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);return ee(g(t.props??{}),b)}let d=Object.create(n),p;try{p=u(t.props??{},d)}catch(v){throw v}if(p instanceof Promise&&(p=await p),typeof p!="function")throw new Error(`Component ${u.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);return ee(p(t.props??{}),d)}let o=t.type,r=t.props??{},c=[],i;for(let[u,d]of Object.entries(r))if(!(u==="children"||u==="key")&&u!=="ref"&&!(u.startsWith("on")&&typeof d=="function")){if(u==="innerHTML"){i=String(d??"");continue}if(u==="class"||u==="className"){let p=mt(d);p&&c.push(` class="${ke(p)}"`);continue}if(u==="style"&&d&&typeof d=="object"){c.push(` style="${ke(yt(d))}"`);continue}if(d===!0){c.push(` ${u}`);continue}d===!1||d==null||c.push(` ${u}="${ke(String(d))}"`)}let s=c.join("");if(pt.has(o))return`<${o}${s}>`;if(i!==void 0)return`<${o}${s}>${i}</${o}>`;let l=await ee(r.children,n);return`<${o}${s}>${l}</${o}>`}async function gt(e,n,t,o={}){let r=o.data??new Map,c=Pn(t,r);return await ee({type:e,props:n??{},key:void 0},c)}function Nn(e){return`<script>window.__DATA__=${JSON.stringify(Object.fromEntries(e)).replace(/</g,"\\u003c")};<\/script>`}async function ht(e,n){let t=new Map,r=Pn({params:{},query:{}},t),c=n.url.split("?")[0].split("#")[0],i=e.match(c);r.params=i.params,r.query=Object.fromEntries(new URLSearchParams(n.url.split("?")[1]??""));let s=new URL(n.url.startsWith("http")?n.url:`http://localhost${n.url.startsWith("/")?n.url:"/"+n.url}`),l=await e.execute(s,r,c),u=await ee(l,r),d=Nn(t),p=i.title??n.title??"",v=n.rootId??"root",b=`<!DOCTYPE html>
3
+ `);o=i.pop()??"";for(let s of i){let u="message",a="";for(let d of s.split(`
4
+ `))d.startsWith("event: ")?u=d.slice(7):d.startsWith("data: ")&&(a+=d.slice(6));if(a)try{yield{name:u,data:JSON.parse(a)}}catch{}}}}finally{n.releaseLock()}}function An(e,n,t){t&&(e.length>=1e3&&e.shift(),e.push(n))}function Un(e){return e===401||e===403?"auth_failed":e===429?"rate_limited":e>=500?"provider_error":"invalid_request"}function Hn(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`trace-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function On(e){return e.map(n=>({role:n.role,content:n.content}))}function He(){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 r(){if(!e.streaming)return;let C=e.messages[e.messages.length-1];return C&&C.role==="assistant"&&C.status==="streaming"?C:void 0}function c(C,h,g){let v=r();switch(C){case"wf:token":v&&(v.content+=h.text);break;case"wf:tool_call":{v&&(v.toolCalls||(v.toolCalls=[]),v.toolCalls.push({call:h,status:"running"}));break}case"wf:tool_progress":{let x=h,S=v?.toolCalls?.find(l=>l.call.id===x.toolCallId);S&&(S.progress=x);break}case"wf:tool_result":{let x=h,S=v?.toolCalls?.find(l=>l.call.id===x.id);S&&(S.result=x,S.status=x.ok?"ok":"error");break}case"wf:approval_request":v&&(v.approval=h);break;case"wf:usage":v&&(v.usage=h);break;case"wf:step":e.step=h;break;case"wf:done":v&&(v.status="done",v.approval=void 0),e.streaming=!1,e.step=null;break;case"wf:error":v&&(v.status="error",v.error=h,v.approval=void 0),e.error=h,e.streaming=!1,e.step=null;break;default:g?.(C,h);break}}function i(){let C=t.body?t.body(e.messages):{messages:On(e.messages)};o=n(t.url,C,{onToken:g=>c("wf:token",{text:g}),onToolCall:g=>c("wf:tool_call",g),onToolProgress:g=>c("wf:tool_progress",g),onToolResult:g=>c("wf:tool_result",g),onApproval:g=>c("wf:approval_request",g),onUsage:g=>c("wf:usage",g),onStep:g=>c("wf:step",g),onDone:g=>c("wf:done",g),onError:g=>c("wf:error",g),onEvent:(g,v)=>c(g,v,t.onEvent)},{signal:t.signal,headers:t.headers}),e.streaming=!0;let h=r();h&&o?.traceId&&(h.id=o.traceId)}function s(){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:He(),role:"user",content:C,status:"done"},{id:He(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),i())}function u(){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:He(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),i())}function d(){o?.abort(),e.messages=[],e.input="",e.streaming=!1,e.error=null,e.usage=null,e.step=null}async function m(C,h){let g=e.messages[e.messages.length-1],v=g?.role==="assistant"?g.approval:void 0;if(v&&(g.approval=void 0,!!t.approveUrl))try{await fetch(t.approveUrl,{method:"POST",headers:{"Content-Type":"application/json",...t.headers},body:JSON.stringify({id:v.id,decision:C,note:h}),signal:t.signal})}catch(x){if(t.signal?.aborted)return;e.error={code:"provider_error",message:x instanceof Error?x.message:String(x)}}}function w(){o?.abort(),o=null}return{send:s,stop:u,retry:a,clear:d,approve:m,dispose:w}}var G=Symbol("Fragment"),B=Symbol("Portal"),Ce=(e,n)=>{let t=n._suspense;return()=>t?.fallback??null},Oe=(e,n)=>t=>t.children;function De(e,n,t){return{type:e,props:cn(n),key:t??void 0}}var Dn=De;function Wn(e,n,t){return De(e,n,t)}function Te(e,n,...t){let o=cn(n??{});return t.length>0&&(o.children=t.length===1?t[0]:t),{type:e,props:o,key:n?.key??void 0}}function cn(e){if(!e)return{};let n={};for(let t of Object.keys(e))t!=="key"&&(n[t]=e[t]);return n}function We(e,n){return{type:B,props:{children:e,portalKey:n},key:n??void 0,_placement:"remote"}}var Ee=new Set,ae=new Map,xe=new Map,ue=new Map;function fn(e){let{ctx:n,renderByIds:t,getSelfId:o,dirtyBatch:r,dirtySet:c,mediaRegistry:i,popupTrackers:s,scrollTrackers:u,schedulePopupRecompute:a,ensurePopupListeners:d,isRendering:m,isMounting:w,setMounting:C,endMounting:h}=e,g=n.browser??W(),v=e.registry??j(n),x=l=>ye(v,l);return{_selfId:"_wf_root",_ctxVersion:0,_dirtySet:c,setMounting:C,endMounting:h,bumpCtxVersion:function(){this._ctxVersion++},render:function(l){if(m()){if(w())return;this._pendingRender||(this._pendingRender=!0,queueMicrotask(()=>{this._pendingRender=!1,this.render(l)}));return}if(!l||l.length===0){let f=o(this);if(f)l=[f];else return}t(l)},dirty:function(l){let f=this._selfId??"",p=this._debugDirty=(this._debugDirty??0)+1;if(D("dirty","self="+String(f).slice(0,20)+" ids="+JSON.stringify(l)+" n="+p+" mounting="+w()+" rendering="+m(),{throttle:200}),p<=3&&q()&&console.trace("[ui-debug]","dirty-trace",String(f).slice(0,20)),!w()){if(m()){this._pendingDirty||(this._pendingDirty=!0,queueMicrotask(()=>{this._pendingDirty=!1,this.dirty(l)}));return}if(!l||l.length===0){let y=o(this);if(y)l=[y];else return}for(let y of l)y&&(r.add(y),c.add(y));this._dirtyScheduled||(this._dirtyScheduled=!0,queueMicrotask(()=>{this._dirtyScheduled=!1;let y=[...r];r.clear(),y.length>0&&t(y)}))}},$:function(){let l=this;if(!Object.prototype.hasOwnProperty.call(l,"_$cache")){let f=Q(()=>{let p=l._selfVNode?._id??o(l);p&&n.ui.dirty([p])});l._$cache=f}return l._$cache},useChat:function(l){let f=this.$(),p=dn(f,un,l);Object.assign(f,{send:p.send,stop:p.stop,retry:p.retry,clear:p.clear,approve:p.approve,dispose:p.dispose});let y=o(this);if(y){let b=x(T=>{T===y&&(p.dispose(),b())})}return f},useMedia:function(l,f){let y=`media:${o(this)}:${l}`;if(!i.has(y)){let b=g.matchMedia(l);f(b.matches);let T=_=>f(_.matches);b.addEventListener("change",T),i.set(y,{mql:b,handler:T})}},useBreakpoint:function(l,f){let p=typeof l=="function"?{mobile:"(max-width: 639px)",tablet:"(min-width: 640px) and (max-width: 1023px)",desktop:"(min-width: 1024px)"}:l,y=typeof l=="function"?l:f,T=`bp:${o(this)}`;function _(){for(let[P,M]of Object.entries(p))if(g.matchMedia(M).matches)return P;return Object.keys(p)[0]??""}if(!i.has(T)){y(_());let P=[];for(let M of Object.values(p)){let H=g.matchMedia(M),U=()=>y(_());H.addEventListener("change",U),P.push({mql:H,handler:U})}i.set(T,{mqls:P})}},usePopupPosition:function(l){let f=o(this),p={top:0,left:0,refresh:()=>{}};if(!f)return p;let y={pos:p,getEl:l.el,isOpen:l.isOpen,compute:l.compute,panel:l.panel,margin:l.margin??8};return s.set(f,y),d(),p.refresh=()=>{let b=y.getEl();if(!b)return;let T=b.getBoundingClientRect();if(T.width===0&&T.height===0)return;let _=y.compute(T);Object.assign(p,ge(_,y.panel?.(),y.margin))},p},useHoverCapable:function(){return typeof window<"u"&&!!window.matchMedia?.("(hover: hover)").matches},useStableRef:function(l,f){return y=>{y?l(y):f?.()}},useVisualViewport:function(){let l=o(this),f={height:g.viewportHeight(),offsetTop:0,keyboardOpen:!1},p=()=>{n.ui&&n.ui.dirty(l?[l]:void 0)},y=()=>{let T=g.visualViewport();f.height=T?.height??g.viewportHeight(),f.offsetTop=T?.offsetTop??0,f.keyboardOpen=f.height<g.viewportHeight()*.9,p()},b=g.visualViewport();if(b?.addEventListener?(b.addEventListener("resize",y),b.addEventListener("scroll",y)):g.addEventListener("resize",y),l){let T=x(_=>{_===l&&(b?.removeEventListener?(b.removeEventListener("resize",y),b.removeEventListener("scroll",y)):g.removeEventListener("resize",y),T())})}return f},usePopup:function(l){let f=o(this),p=this.useHoverCapable(),y=()=>typeof l.trigger=="function"?l.trigger():l.trigger,b=l.open!==void 0,T=()=>!!l.disabled?.(),_=()=>b?typeof l.open=="function"?!!l.open():!!l.open:l.isOpen(),P=N=>{T()||(b?l.onOpenChange?.(N):l.setOpen(N))},M=()=>{let N=l.placement;return typeof N=="function"?N():N??"bottom"},H=null,U=!1,L=n.ui.usePopupPosition({el:l.el,isOpen:()=>_(),compute:N=>{if(l.position){let V=l.position();return{top:V.y,left:V.x}}return Xe(N,M(),l.gap??6,l.center!==!1)},panel:()=>H,margin:l.margin??8}),k=N=>{if(l.closeOnOutside===!1||!_())return;let V=N.target;if(!(V instanceof Node))return;let K=l.el();K&&K.contains(V)||H&&H.contains(V)||P(!1)},R=N=>{l.closeOnEscape!==!1&&(N.key!=="Escape"||!_()||P(!1))};if(g.addEventListener("mousedown",k),g.addEventListener("keydown",R),f){let N=x(V=>{V===f&&(g.removeEventListener("mousedown",k),g.removeEventListener("keydown",R),N())})}let E={},I=N=>typeof N=="function"?N():N??0,A=()=>I(l.openDelay),J=()=>I(l.closeDelay),Y,z,Tn=()=>{clearTimeout(Y),clearTimeout(z),Y=void 0,z=void 0},En=N=>{if(T())return;let V=N.currentTarget,K=N.relatedTarget;V.contains(K)||(clearTimeout(z),z=void 0,Y=setTimeout(()=>{Y=void 0,P(!0)},A()))},xn=N=>{if(T())return;let V=N.currentTarget,K=N.relatedTarget;V.contains(K)||(clearTimeout(Y),Y=void 0,z=setTimeout(()=>{z=void 0,P(!1)},J()))},_n=()=>{T()||(clearTimeout(z),z=void 0,Y=setTimeout(()=>{Y=void 0,P(!0)},A()))},Pn=()=>{T()||(clearTimeout(Y),Y=void 0,z=setTimeout(()=>{z=void 0,P(!1)},J()))},se=()=>y()==="hover";if(E.onMouseOver=N=>{se()&&En(N)},E.onMouseOut=N=>{se()&&xn(N)},E.onClick=()=>{se()?p||P(!_()):y()==="click"&&P(!0)},E.onFocus=()=>{se()&&_n()},E.onBlur=()=>{se()&&Pn()},y()==="longpress"){let N,V=0,K=0,X=()=>{clearTimeout(N),N=void 0};E.onPointerDown=F=>{T()||(V=F.clientX??0,K=F.clientY??0,X(),N=setTimeout(()=>{N=void 0,l.onTrigger?.({clientX:V,clientY:K}),P(!0)},l.longPressDuration??500))},E.onPointerUp=X,E.onPointerLeave=X,E.onPointerMove=F=>{let Re=Math.abs((F.clientX??0)-V),Me=Math.abs((F.clientY??0)-K);(Re>10||Me>10)&&X()},E.onContextMenu=F=>{F.preventDefault(),l.onTrigger?.({clientX:F.clientX??0,clientY:F.clientY??0}),P(!0)}}if(E.onKeyDown=N=>{N.key==="Escape"&&l.closeOnEscape!==!1&&P(!1)},f){let N=x(V=>{V===f&&(Tn(),N())})}let Nn=N=>{if(N){H=N;let V=()=>L.refresh();N.addEventListener("animationend",V,{once:!0})}else H=null},ke=null,Se=null,kn=N=>{Nn(N),Se&&Se(N)};return{get open(){return _()},setOpen:P,wrapProps:E,portal:(N,V="popover")=>{if(T())return null;if(!_())return U=!1,ke=null,null;let X=l.el();(!U||X!==ke)&&(X?L.refresh():queueMicrotask(()=>{_()&&L.refresh()}),U=!0,ke=X);let F=N.props??{};Se=F.ref??null;let Re=["wf-popup",F.class].filter(Boolean).join(" "),Me={...F.style??{},position:"fixed",top:`${L.top}px`,left:`${L.left}px`,maxWidth:l.width!==void 0?`min(${l.width}px, calc(100vw - 32px))`:"calc(100vw - 32px)"},Sn={...N,props:{...F,class:Re,style:Me,ref:kn}};return We(Sn,V)},refresh:()=>L.refresh()}},useLongPress:function(l){let{onLongPress:f,duration:p=500}=l,y,b=0,T=0,_=null,P=()=>{clearTimeout(y),y=void 0};return{onPointerDown:M=>{b=M.clientX??0,T=M.clientY??0,_=M,P(),y=setTimeout(()=>{y=void 0,_&&f(_)},p)},onPointerUp:P,onPointerLeave:P,onPointerMove:M=>{let H=Math.abs((M.clientX??0)-b),U=Math.abs((M.clientY??0)-T);(H>10||U>10)&&P()},onContextMenu:M=>{M.preventDefault(),f(M)}}},useInView:function(l){let f=o(this),p={isIn:!1,ready:!1,observe:P,refresh:M,disconnect:H},y=null,b=null,T=()=>{n.ui&&n.ui.dirty(f?[f]:void 0)};function _(){if(b?.disconnect(),b=null,!y)return;let U=typeof l.rootMargin=="function"?l.rootMargin():l.rootMargin,L=typeof l.threshold=="function"?l.threshold():l.threshold;b=new IntersectionObserver(k=>{let R=k[k.length-1];if(!R)return;let E=R.isIntersecting,I=E!==p.isIn,A=!p.ready;p.isIn=E,p.ready=!0,l.onChange?.(R,E),(I||A)&&T()},{root:l.root?l.root():null,rootMargin:U??"0px",threshold:L??0}),b.observe(y)}function P(U){y=U,U?_():(b?.disconnect(),b=null,p.isIn=!1)}function M(){_()}function H(){b?.disconnect(),b=null}return p},useScrollPosition:function(l){let f=o(this),p={y:0,refresh(){let b=y.getScroller();p.y=b instanceof Window?g.scrollingElement()?.scrollTop??g.scrollTop():b.scrollTop??0}},y={handle:p,getScroller:l.getScroller??(()=>window)};return f?(u.set(f,y),d(),p.refresh(),p):(p.refresh(),p)},useAsync:function(l){let f=o(this),p=Q(()=>{n.ui&&n.ui.dirty(f?[f]:void 0)});p.loading=!0;let y=0,b=()=>{let T=++y;p.loading=!0,p.error=null,Promise.resolve().then(()=>l()).then(_=>{y===T&&(p.data=_,p.loading=!1)}).catch(_=>{y===T&&(p.error=_,p.loading=!1)})};return b(),p.reload=b,p},useControlled:function(l){let f=o(this),p=l.value!==void 0;if(p&&!l.onChange&&l.name&&(Ee.has(l.name)||(Ee.add(l.name),console.warn(`[weifuwu/${l.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)}`))),!p&&f&&!ae.has(f)){ae.set(f,l.value);let b=x(T=>{T===f&&(ae.delete(f),b())})}let y=b=>{if(p){l.onChange?.(b);return}f&&ae.set(f,b),n.ui&&(f?n.ui.dirty([f]):n.ui.render())};return{value:p?l.value:f?ae.get(f):l.value,setValue:y,controlled:p}},useControlledInput:function(l){let f=o(this),p=this.useControlled({value:l.value,onChange:l.onChange,name:l.name});if(f&&!xe.has(f)){xe.set(f,{keyword:"",selectedLabel:""});let T=x(_=>{_===f&&(xe.delete(f),T())})}let y=f?xe.get(f):{keyword:"",selectedLabel:""},b=()=>{f?n.ui?.dirty([f]):n.ui?.render()};return{...p,get keyword(){return y.keyword},setKeyword(T){y.keyword=T,b()},get selectedLabel(){return y.selectedLabel},setSelectedLabel(T){y.selectedLabel=T,b()}}},useOpen:function(l){let f=o(this);if(f&&!ue.has(f)){ue.set(f,!1);let _=x(P=>{P===f&&(ue.delete(f),_())})}let p=l.open!==void 0;p&&!l.onOpenChange&&l.name&&!Ee.has(l.name)&&(Ee.add(l.name),console.warn(`[weifuwu/${l.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 y=()=>p?!!l.open:f?ue.get(f)??!1:!1,b=()=>{f?n.ui?.dirty([f]):n.ui?.render()},T=_=>{if(p){l.onOpenChange?.(_);return}f&&ue.set(f,_),b()};return{get open(){return y()},setOpen:T,triggerProps:{onClick:()=>T(!0),onFocus:()=>{l.openOnFocus&&T(!0)}}}},usePresence:function(l){let f=o(this),p="closed",y,b=()=>{p="closed",n.ui&&(f?n.ui.dirty([f]):n.ui.render())};return{get phase(){return p},ref:_=>{_?y||(y=()=>{p==="exit"&&b()},_.addEventListener("animationend",y)):y=void 0},sync:_=>(_?p="open":p==="open"&&(p="exit"),p)}},useDialog:function(l){let f=o(this),p,y=null,b=this.usePresence(l);return{get phase(){return b.phase},rootRef:P=>{P?(rn(),y&&(p=Ae(y)),b.ref(P)):(sn(),p?.(),b.ref(null))},panelRef:P=>{y=P,P&&!p&&(p=Ae(P))},sync:P=>b.sync(P)}},useGlobalKey:function(l){let f=o(this);if(typeof window>"u")return()=>{};if(g.addEventListener("keydown",l),f){let p=x(y=>{y===f&&(g.removeEventListener("keydown",l),p())})}return()=>g.removeEventListener("keydown",l)},useDrag:function(l){let f=0,p=0,y=!1,b=P=>{y&&l.onMove(P,{x:P.clientX-f,y:P.clientY-p})},T=P=>{y&&(y=!1,g.removeEventListener("pointermove",b),g.removeEventListener("pointerup",T),l.onEnd?.(P))};return{onPointerDown:P=>{y||(P.preventDefault(),y=!0,f=P.clientX,p=P.clientY,g.addEventListener("pointermove",b),g.addEventListener("pointerup",T),l.onStart?.(P))}}},useDragDrop:function(l){let f={};l.onDrop&&(f.onDrop=y=>{y.preventDefault(),l.onDrop(y)}),l.onDragOver&&(f.onDragOver=y=>{y.preventDefault(),l.onDragOver(y)}),l.onDragLeave&&(f.onDragLeave=y=>l.onDragLeave(y));let p={draggable:!0};if(l.onDragStart){let y=l.onDragStart;p.onDragStart=b=>{typeof document<"u"&&document.body.classList.add("wf-dragging"),y(b)}}if(l.onDragEnd){let y=l.onDragEnd;p.onDragEnd=b=>{typeof document<"u"&&document.body.classList.remove("wf-dragging"),y(b)}}return{dropProps:f,dragProps:p}},useReducedMotion:function(){return typeof window<"u"&&!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches},useAnimationEnd:function(l,f){let p=null,y=()=>{l(),f?.once&&p&&p.removeEventListener("animationend",y)};return T=>{T?(p=T,T.addEventListener("animationend",y)):p&&(p.removeEventListener("animationend",y),p=null)}},useTween:function(l,f){let p=o(this),y=this.useReducedMotion(),b=f?.duration??400,T=f?.ease==="linear"?L=>L:L=>1-Math.pow(1-L,3),_,P=l,M={value:y?l:0,reset:()=>{}},H=()=>{n.ui&&(p?n.ui.dirty([p]):n.ui.render())},U=L=>{if(P=L,y){M.value=L,H();return}if(L===M.value)return;_&&cancelAnimationFrame(_);let k=M.value,R=performance.now(),E=I=>{let A=Math.min(1,(I-R)/b);M.value=Math.round(k+(L-k)*T(A)),A<1?(_=requestAnimationFrame(E),H()):(_=void 0,H())};_=requestAnimationFrame(E)};return M.reset=L=>{L===P&&_||U(L)},queueMicrotask(()=>U(l)),M},selfId:function(l){if(typeof l!="string"||!l)throw new Error(`[weifuwu] selfId requires a non-empty string, got ${typeof l}`);if(v.idRegistry.has(l))throw new Error(`[weifuwu] Duplicate component ID: "${l}". Each component must have a unique custom ID.`);let f=this._selfVNode;f&&(f._customId=l,v.idRegistry.set(l,f))}}}var pn=new WeakMap;function jn(e){let n=pn.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 })")),pn.set(e,n)}function Z(e,n,t,o,r){if(q()){let a=t!=null&&typeof t=="object"?t.type?.name??String(t.type).slice(0,20):typeof t,d=o!=null&&typeof o=="object"?o.type?.name??String(o.type).slice(0,20):typeof o;D("patchValue","old="+a+" new="+d)}if(t==null){if(o==null)return null;let a=$(o,r);return a==null?null:(n&&n.parentNode?n.parentNode.insertBefore(a,n):e.appendChild(a),a)}if(o==null)return n?(O(t,j(r)),n.remove()):O(t,j(r)),null;let c=yn(t),i=yn(o);if(c!==i){O(t,j(r));let a=$(o,r);return a==null?null:(n?.parentNode?n.parentNode.replaceChild(a,n):a.parentNode||e.appendChild(a),a)}if(i==="text")return n&&n.textContent!==String(o)&&(n.textContent=String(o)),n;let s=o,u=t;if(typeof s.type=="function"){let a=s.type;u.type===s.type&&(u._render||u._asyncDef)&&(u._render&&(s._render=u._render),s._id=u._id,s._id&&j(r).idRegistry.set(s._id,s)),u.type===s.type&&u._asyncDef&&(s._asyncDef=u._asyncDef),s._parentNode=e,n&&(s._refNode=n);let d=Object.create(r);d.ui=Object.create(r.ui);let m=d.ui;m._selfId=s._id,m._selfVNode=s,s._ctxVersion=u._ctxVersion??m._ctxVersion??0;let w=u._render&&u.type===s.type,C=Fn(u.props,s.props),h=!m._dirtySet?.has(u._id),g=s._ctxVersion===m._ctxVersion,v=a?.name??"anon";if(q()){let f=a?.name??"anon";D("tri-state-skip",f+" type="+w+" props="+C+" dirty="+h+" ver="+g)}if(w&&C&&h&&g)return s._child=u._child,n;m._dirtySet?.delete(u._id);let x;try{typeof s._render=="function"?x=s._render(s.props):x=$e(a,s.props,s,d)}catch(f){let p=r.ui?._errorHandler;p?(p(f),x=null):(console.error(`[weifuwu] Component render error in <${a?.name||"anonymous"}> (id: ${u._id??"?"}, phase: update)`,f),x=null)}let S=u._child;s._child=x;let l=Z(e,n,S,x,d);return l?s._refNode=l:s._refNode=null,l}if(s.type===G){let a=u._childNodes,d=hn(e,u,s,r,a);return s._childNodes=d,n}if(typeof s.type=="string"){if(n&&n.nodeType===1){let a=u.props?.ref,d=s.props?.ref;a!==d&&(typeof d=="function"&&d(n),typeof a=="function"&&typeof d=="function"&&jn(n)),qe(n,u.props,s.props),hn(n,u,s,r)}else if(n){O(t,j(r));let a=$(o,r);return a==null?null:(n.parentNode?.replaceChild(a,n),a)}else{let a=t.el??t._refNode;O(t,j(r)),a&&a.parentNode&&a.remove();let d=$(o,r);return d==null?null:(e.appendChild(d),d)}return n}if(s.type===B)return fe(u,s,r),null;if(Array.isArray(o)){let a=Array.isArray(t)?t:[];_e(a,o);let d=Array.from(e.childNodes),m=n?d.indexOf(n):-1,w=m>=0?de(d.slice(m),a):de(d,a);return Pe(e,a,o,r,w,n),n}return n}var mn=new Map;function qn(e){let n=mn.get(e);return n||(n=`fn:${e.name||"anon"}`,mn.set(e,n)),n}function yn(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"?qn(n.type):n.type===G?"fragment":n.type===B?"portal":typeof n.type=="string"?"tag:"+n.type:"unknown"}function qe(e,n,t){q()&&D("patchProps","oldKeys="+(n?Object.keys(n).length:0)+" newKeys="+Object.keys(t).length);let o=n?Object.keys(n).filter(i=>i!=="children"&&i!=="key"&&i!=="innerHTML"):[],r=t?Object.keys(t).filter(i=>i!=="children"&&i!=="key"&&i!=="innerHTML"):[],c=new Set(r);for(let i of o){if(!n)break;if(!c.has(i)){if(i==="ref")continue;i.startsWith("on")&&typeof n[i]=="function"?e.removeEventListener(i.slice(2).toLowerCase(),n[i]):i==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value="":e.removeAttribute(i==="className"?"class":i)}}for(let i of r){if(i==="ref")continue;let s=n?.[i],u=t?.[i];if(i==="innerHTML")u!==s&&(e.innerHTML=String(u??""));else if(u!==s)if(i==="class"||i==="className")e instanceof SVGElement?e.setAttribute("class",gn(u)):e.className=gn(u);else if(i==="style"&&typeof u=="object"&&u!==null){let a=e.style,d=u;for(let m of Object.keys(d)){let w=d[m];w==null?m.startsWith("--")?a.removeProperty(m):a[m]="":m.startsWith("--")?a.setProperty(m,String(w)):a[m]=typeof w=="number"?w+"px":String(w)}}else if(i.startsWith("on")&&typeof u=="function"){let a=i.slice(2).toLowerCase();typeof s=="function"&&e.removeEventListener(a,s),e.addEventListener(a,u)}else i==="draggable"?e.setAttribute("draggable",u?"true":"false"):i==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value=String(u??""):u===!0?e.setAttribute(i,""):u!=null&&u!==!1?e.setAttribute(i,String(u)):i==="value"&&(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)?e.value="":e.removeAttribute(i)}}function gn(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 je(e){if(!(e==null||typeof e!="object"))return Array.isArray(e)?void 0:e.key}function _e(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 r=n[o];r&&typeof r=="object"&&!Array.isArray(r)&&(r.key=String(o))}for(let o=0;o<e.length;o++){let r=e[o];r&&typeof r=="object"&&!Array.isArray(r)&&(r.key=String(o))}}}function de(e,n){let t=[],o=0;for(let r of n){if(r==null||typeof r=="boolean"){t.push(null);continue}let c=r;if(c.type===B){t.push(null);continue}if(c.type===G){let i=c._childNodes;Array.isArray(i)&&i.length>0?(t.push(i.slice()),o+=i.length):(t.push(e[o]?[e[o]]:null),o+=1)}else if(typeof c.type=="function")if(c._render){let i=c._childNodes??c._refNode;i==null?t.push(null):Array.isArray(i)?(t.push(i.slice()),o+=i.length):(t.push([i]),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=",c.type,"sourceLen=",e.length,"hit=",!!e[o]),t.push(e[o]?[e[o]]:null),o+=1}return t}function hn(e,n,t,o,r){q()&&D("patchChildren","old="+n.props?.children?.length+" new="+t.props?.children?.length);let c=ce(n.props?.children),i=ce(t.props?.children);_e(c,i);let s=r??Array.from(e.childNodes),u=de(s,c),a=Pe(e,c,i,o,u,r?.[0]??null),d=[];for(let m of a)m&&m.length>0&&d.push(...m);return d}function ce(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 vn(e){return e==null?[]:e instanceof DocumentFragment?Array.from(e.childNodes):[e]}function Pe(e,n,t,o,r=[],c=null){if(q()&&D("patchKeyedChildren","old="+n.length+" new="+t.length),!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 g=0;g<h;g++){let v=g<n.length?n[g]:null,x=g<t.length?t[g]:null;if(x==null){if(v!=null){O(v,j(o));for(let S of r[g]??[])S.remove()}}else if(v==null){let S=$(x,o);if(S!=null){let l=null;for(let f=g+1;f<r.length;f++){let p=r[f]?.[0];if(p&&p.parentNode===e){l=p;break}}l?e.insertBefore(S,l):e.appendChild(S)}}else{let S=r[g]?.[0]??null;Z(e,S,v,x,o)}}return[]}for(let h=0;h<n.length;h++){let g=n[h];if(!(g==null||typeof g=="boolean")&&je(g)===void 0)for(let v of r[h]??[])v.remove()}let s=new Map,u=0;for(let h=0;h<n.length;h++){let g=je(n[h]);g!==void 0&&s.set(g,{vnode:n[h],nodes:r[h]??[],index:u++})}let a=t.map(h=>je(h)),d=new Set(a);for(let h of[...s.keys()])if(!d.has(h)){let g=s.get(h);O(g.vnode,j(o));for(let v of g.nodes)v?.remove();s.delete(h)}let m=new Array(t.length).fill(null),w=-1,C=c&&c.parentNode===e?c:e.firstChild;for(let h=0;h<t.length;h++){let g=a[h],v=t[h],x=g!==void 0?s.get(g):void 0,S=v&&typeof v=="object"&&v._placement==="remote";if(x)if(x.nodes.length>0){if(x.index<w)for(let f of x.nodes)e.insertBefore(f,C);w=Math.max(w,x.index),Z(e,x.nodes[0],x.vnode,v,o),m[h]=v._childNodes??x.nodes.filter(f=>f.parentNode===e),C=m[h][m[h].length-1]?.nextSibling??null}else if(S)fe(x.vnode,v,o),m[h]=[];else{let l=Z(e,null,x.vnode,v,o);m[h]=vn(l);for(let p of m[h])e.insertBefore(p,C);C=m[h][m[h].length-1]?.nextSibling??null}else if(S)oe(v,o),m[h]=[];else{let l=$(v,o);m[h]=vn(l);for(let p of m[h])e.insertBefore(p,C);C=m[h][m[h].length-1]?.nextSibling??null}}return m}function $n(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 Fn(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(!$n(e[o],n[o]))return!1}else if(e[o]!==n[o])return!1}return!0}var ee=W(),Fe="http://www.w3.org/2000/svg",Be=new Set(["svg","path","circle","line","rect","text","g","polyline","polygon","ellipse","defs","use","clipPath","mask","linearGradient","radialGradient","stop","tspan"]);function $(e,n){let t=n.browser??ee;if(q()){let s=e!=null&&typeof e=="object"?e.type?.name??String(e.type).slice(0,20):typeof e;D("renderValue","type="+s,{depth:an()})}if(e==null||typeof e=="boolean")return q()&&be(),null;if(typeof e=="string"||typeof e=="number")return q()&&be(),t.createTextNode(String(e));if(Array.isArray(e)){let s=Gn(e,n);return q()&&be(),s}let o=e;if(o.type===B)return oe(o,n),null;if(o.type===G){let s=t.createDocumentFragment(),u=o.props?.children==null?[]:Array.isArray(o.props.children)?o.props.children:[o.props.children];for(let a of u){let d=$(a,n);d!=null&&s.appendChild(d)}return o._childNodes=Array.from(s.childNodes),s}if(typeof o.type=="function")return Kn(o.type,o.props,o,n);let r=o.type,c=Be.has(r)?t.createElementNS(Fe,r):t.createElement(r);if(!c)return null;o.el=c;let i;for(let[s,u]of Object.entries(o.props??{}))s==="children"||s==="key"||s==="value"||s==="innerHTML"||wn(c,s,u);if("value"in(o.props??{})&&c instanceof HTMLSelectElement?i=o.props.value:"value"in(o.props??{})&&wn(c,"value",o.props.value),"innerHTML"in(o.props??{}))c.innerHTML=String(o.props.innerHTML??"");else{let s=Ke(o.props?.children);for(let u of s){let a=$(u,n);if(a!=null&&(c.appendChild(a),u&&typeof u=="object"&&typeof u.type=="function")){let d=u;d._parentNode||(d._parentNode=c,d._refNode=a)}}}return i!==void 0&&(c.value=String(i)),typeof o.props?.ref=="function"&&Ve(o.props.ref,c,"mount",r),c}function Bn(e){let n=e.__scheduleRender;if(typeof n=="function"){n();return}let t=e.ui;t&&typeof t.render=="function"&&t.render(["_wf_root"])}function $e(e,n,t,o){if(q()){let a=e?.name??(typeof e=="function"?"fn":typeof e);D("mountComponent",a+" id="+String(t.id??"").slice(0,10))}let r=globalThis;if(r.__wf_mountCount===void 0&&(r.__wf_mountCount=0),++r.__wf_mountCount>500)throw r.__wf_mountCount=0,new Error("[wf-render] mountComponent \u8D85\u8FC7 500 \u6B21\u2014\u2014\u6E32\u67D3\u6B7B\u5FAA\u73AF\uFF08\u65E0\u9650\u6302\u8F7D\uFF09");let c=o.browser??ee,i=t._asyncDef;if(i instanceof Promise)return Te(Ce,{});if(typeof i=="function")return t._render=i,i(n);o.ui?.setMounting?.(!0);let s;try{s=e(n,o)}finally{o.ui?.endMounting?.()}if(s instanceof Promise){let a=s;return t._asyncDef=a,a.then(d=>{if(typeof d!="function")throw new Error(`Component ${e.name||"anonymous"} async factory must return a render function. (props) => VNode pattern.`);t._asyncDef=d,Bn(o)},()=>{}),Te(Ce,{})}if(typeof s!="function")throw new Error(`Component ${e.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);let u=s;return t._render=u,u(n)}function Kn(e,n,t,o){let r=o.browser??ee;if(!t._id){let a=j(o);t._id=me(a),a.idRegistry.set(t._id,t)}let c=Object.create(o);t.type===Oe&&(c._suspense={fallback:t.props?.fallback}),c.ui=Object.create(o.ui);let i=c.ui;i._selfId=t._id,i._selfVNode=t,t._ctxVersion=i._ctxVersion??0;let s;try{s=$e(e,n,t,c)}catch(a){let d=o.ui?._errorHandler;d?(d(a),s=null):(console.error(`[weifuwu] Component render error in <${e.name||"anonymous"}> (id: ${t._id??"?"}, phase: mount)`,a),s=null)}if(s==null){if(t._child=null,c.ui?._errorHandler){let d=r.createComment("wf-empty");return t._refNode=d,d}return null}t._child=s;let u=$(s,c);return t._refNode||(t._refNode=u),u}function Gn(e,n){let o=(n.browser??ee).createDocumentFragment();for(let r of e){let c=$(r,n);c!=null&&o.appendChild(c)}return o}function Jn(){let e=ee,n=e.byId("__wf_portal");if(!n){if(n=e.createElement("div"),!n)throw new Error("[ui-dom] portal container creation failed");n.id="__wf_portal",n.style.cssText="position:fixed;inset:0;pointer-events:none;z-index:9999",e.bodyAppend(n)}return n}function oe(e,n){let t=n.browser??ee,o=Jn(),r=t.createElement("div");r.style.pointerEvents="auto",o.appendChild(r),e._remoteEl=r;let c=ce(e.props?.children);e._child=c;for(let i of c){let s=$(i,n);s!=null&&r.appendChild(s)}}function fe(e,n,t){let o=t.browser??ee,r=e?._remoteEl;if(n._remoteEl=r,!r){oe(n,t);return}let c=ce(n.props?.children),i=e._child||[];n._child=c,_e(i,c);let s=de(Array.from(r.childNodes),i);Pe(r,i,c,t,s,s[0]?.[0]??null)}function Ke(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 wn(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 r of Object.keys(t)){let c=t[r];c!=null&&(r.startsWith("--")?o.setProperty(r,String(c)):o[r]=typeof c=="number"?c+"px":String(c))}}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 Yn(e,n,t){e.innerHTML="";let o=$(n,t);o instanceof Node&&e.appendChild(o)}function zn(e){O(e,ie())}function Ge(e){e.node=e.node?e.node.nextSibling:null}function Xn(e,n){e.node&&e.node.parentNode?e.node.parentNode.insertBefore(n,e.node):e.parent.appendChild(n)}function Qn(e,n){e.node&&e.node.parentNode?(e.node.parentNode.replaceChild(n,e.node),Ge(e)):e.parent.appendChild(n)}async function pe(e,n,t){let o=n.browser??W();if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number"){let u=String(e);if(t.node&&t.node.nodeType===3)return t.node.textContent!==u&&(t.node.textContent=u),Ge(t),t.node;let a=o.createTextNode(u);return Xn(t,a),a}if(Array.isArray(e)){let u=null;for(let a of e){let d=await pe(a,n,t);d!=null&&!u&&(u=d)}return u}let r=e;if(r.type===B||r.type===G){let u=r.props?.children,a=u==null?[]:Array.isArray(u)?u:[u],d=null;for(let m of a){let w=await pe(m,n,t);w!=null&&!d&&(d=w)}return d}if(typeof r.type=="function")return Zn(r,n,t);let c=r.type,i=r.props??{},s;if(t.node&&t.node.nodeType===1&&t.node.tagName.toLowerCase()===c.toLowerCase()?(s=t.node,Ge(t)):(s=Be.has(c)?o.createElementNS(Fe,c):o.createElement(c),Qn(t,s)),r.el=s,qe(s,null,i),!("innerHTML"in i)){let u={parent:s,node:s.firstChild},a=Ke(i.children);for(let d of a){let m=await pe(d,n,u);if(m!=null&&m.parentNode!==s&&s.appendChild(m),d&&typeof d=="object"&&typeof d.type=="function"){let w=d;w._parentNode||(w._parentNode=s,w._refNode=m)}}for(;u.node;){let d=u.node;u.node=d.nextSibling,d.parentNode?.removeChild(d)}}return"value"in i&&s instanceof HTMLSelectElement&&(s.value=String(i.value??"")),typeof i.ref=="function"&&i.ref(s),s}async function Zn(e,n,t){if(!e._id){let u=j(n);e._id=me(u),u.idRegistry.set(e._id,e)}let o=Object.create(n);o.ui=Object.create(n.ui);let r=o.ui;r._selfId=e._id,r._selfVNode=e,e._ctxVersion=r._ctxVersion??0;let c=e.type,i;try{let u=c(e.props??{},o);if(u instanceof Promise&&(u=await u),typeof u!="function")throw new Error(`Component ${c.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);e._render=u,i=u(e.props??{})}catch(u){let a=n.ui?._errorHandler;a?(a(u),i=null):(console.error(`[weifuwu] Component hydration error in <${c.name||"anonymous"}> (id: ${e._id??"?"})`,u),i=null)}if(i==null)return e._child=null,null;e._child=i;let s=await pe(i,o,t);return e._refNode||(e._refNode=s),s}async function Je(e,n,t){let o={parent:e,node:e.firstChild};for(await pe(n,t,o);o.node;){let r=o.node;o.node=r.nextSibling,r.parentNode?.removeChild(r)}}function et(e,n){let t=W(),o=typeof n.root=="string"?t.query(n.root):n.root;if(!o)throw new Error(`uiServe: root not found: ${n.root}`);let r=o,c=!!n.hydrate;c||(r.innerHTML="");let i=ie(),s=new Set,u=0,a=new Set,d=new Map,m=!1,w=!1,C=[];function h(k){C.push(w),w=k}function g(){w=C.pop()??!1}let v={params:{},query:{}};v.__scheduleRender=M;let x=new Map,S=globalThis.__DATA__??window.__DATA__;if(S&&typeof S=="object")for(let[k,R]of Object.entries(S))x.set(k,{value:R});v.data={async get(k,R){let E=x.get(k);if(E&&"value"in E)return E.value;if(E?.promise)return E.promise;if(!R)return;let I=Promise.resolve().then(()=>R()).then(A=>(x.set(k,{value:A}),A));return x.set(k,{promise:I}),I},set(k,R){x.set(k,{value:R})},has(k){return x.has(k)}};let l=!1;function f(){s.size>0&&!l&&(l=!0,queueMicrotask(()=>{l=!1;let k=[...s];s.clear(),k.length>0&&(D("flushDirty","ids="+JSON.stringify(k)),p(k))}))}function p(k){if(!m){m=!0;for(let R of k){let E=i.idRegistry.get(R);if(!E||!E._render)continue;D("renderByIds-start",R+" render="+String(E._render.name).slice(0,30)),v.ui._dirtySet?.delete(R);let I=E._child,A=E._render(E.props);if(E._child=A,I&&I._placement==="remote"||A&&A._placement==="remote"){I&&A?fe(I,A,v):A?oe(A,v):I&&O(I,i);continue}if(!E._parentNode&&E._refNode){let J=E._refNode.parentNode;J&&(E._parentNode=J)}if(E._parentNode){let J=Z(E._parentNode,E._refNode??null,I,A,v);J&&J!==E._refNode?E._refNode=J:J||(E._refNode=null)}D("renderByIds-done",R)}m=!1,f()}}let y=null;function b(){return y||(y=Qe(k=>v.ui.render(k))),y}v.browser=t,v.__registry=i,v.ui=fn({ctx:v,renderByIds:p,getSelfId:k=>k?._selfId??v.ui?._selfId,dirtyBatch:s,dirtySet:a,mediaRegistry:d,popupTrackers:b().popupTrackers,scrollTrackers:b().scrollTrackers,schedulePopupRecompute:b().schedulePopupRecompute,ensurePopupListeners:b().ensurePopupListeners,destroyPopupListeners:b().destroyPopupListeners,isRendering:()=>m,isMounting:()=>w,setMounting:h,endMounting:g,registry:i}),ye(i,k=>{for(let R of[...d.keys()])if(R.startsWith(`media:${k}:`)||R===`bp:${k}`){let E=d.get(R);E?.mql&&E.handler&&E.mql.removeEventListener("change",E.handler),E?.mqls?.forEach(({mql:I,handler:A})=>I.removeEventListener("change",A)),d.delete(R)}b().cleanupTrackers(k)}),v.__rerender=()=>M(),v.app={navigate:k=>{e.mode==="hash"?t.setHash("#"+k):t.navigate(k),M()}};let T=null,_=!1,P=!1;function M(){P||(P=!0,queueMicrotask(()=>{P=!1,H()}))}async function H(){if(!_){D("doRender","path="+e.getPath()),_=!0;try{let k=e.getPath();if(v.route={path:k,params:v.params,query:v.query},!v.__state){let E=Q(()=>{_||M()});v.__state=E;let I=v.ui.$;v.ui.$=function(){return this&&this._selfVNode?I.call(this):E}}let R=await e.execute(window.location,v,k);if(T==null){if(R){let E=c&&r.firstElementChild?(Je(r,R,v),r.firstChild):$(R,v);E&&E.parentNode!==r&&r.appendChild(E)}}else{let E=Z(r,r.firstChild,T,R,v);E&&E.parentNode!==r&&r.appendChild(E)}T=R}catch(k){if(console.error("[ui-dom] render error:",k),T==null){let R=t.createElement("div");R.className="ui-dom-error",R.textContent=`\u6E32\u67D3\u9519\u8BEF: ${k?.message??String(k)}`,r.appendChild(R)}}finally{_=!1}}}let U=()=>M();t.addEventListener("popstate",U);let L=()=>M();return e.mode==="hash"&&t.addEventListener("hashchange",L),M(),{get ctx(){return v},close(){t.removeEventListener("popstate",U),e.mode==="hash"&&t.removeEventListener("hashchange",L),T&&O(T,i),b().destroy(),i.idRegistry.clear(),r.innerHTML="",T=null}}}function nt(e,n,t=400){let o=!1,r=()=>{o||(o=!0,e.removeEventListener("animationend",r),clearTimeout(c),n())};e.addEventListener("animationend",r);let c=setTimeout(r,t)}function re(e,n){return Object.assign(Object.create(e),n)}function tt(e){let n={baseURL:e?.baseURL??"",headers:{"Content-Type":"application/json",...e?.headers}},t=e?.onRequest,o=e?.onResponse,r=e?.timeout??0;async function c(i,s,u,a){let d=n.baseURL+s,m={method:i,headers:{...n.headers,...a?.headers}},w=e?.token?.();w&&!m.headers.Authorization&&(m.headers.Authorization=`Bearer ${w}`);let C=r>0,h=!!a?.signal,g=null,v=null;(C||h)&&(g=new AbortController,m.signal=g.signal,C&&(v=setTimeout(()=>g.abort(new Error("Request timed out")),r)),h&&a.signal.addEventListener("abort",()=>g.abort())),u!==void 0&&i!=="GET"&&i!=="HEAD"&&(m.body=JSON.stringify(u));let x={url:d,init:m};t&&(x=t(x));try{let S=await fetch(x.url,x.init);if(o)return o(S);if(!S.ok){let p=await S.text().catch(()=>"");throw new Ye(S.status,p||S.statusText)}let l=S.headers.get("content-length");if(S.status===204||l==="0")return;let f=(S.headers.get("content-type")||"").toLowerCase();return f.includes("application/json")||f.includes("json")?S.json():S.text()}finally{v&&clearTimeout(v)}}return i=>re(i,{api:{get:(u,a)=>c("GET",u,void 0,a),post:(u,a,d)=>c("POST",u,a,d),put:(u,a,d)=>c("PUT",u,a,d),patch:(u,a,d)=>c("PATCH",u,a,d),delete:(u,a)=>c("DELETE",u,void 0,a)}})}var Ye=class extends Error{status;body;constructor(n,t){super(`API Error ${n}: ${t}`),this.name="ApiError",this.status=n,this.body=t}};function 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 st(e){let n=e?.storage??localStorage,t=e?.tokenKey??"weifuwu_token",o=e?.userKey??"weifuwu_user",r=e?.refreshTokenKey??"weifuwu_refresh",c=e?.refreshEndpoint??"/api/auth/refresh";return i=>{let s=n.getItem(t),u=n.getItem(o),a={token:s,user:u?JSON.parse(u):null,get isLoggedIn(){return this.token!==null},login(d,m,w){a.token=d,a.user=m,n.setItem(t,d),n.setItem(o,JSON.stringify(m)),w&&n.setItem(r,w)},logout(){a.token=null,a.user=null,n.removeItem(t),n.removeItem(o),n.removeItem(r)},setUser(d){a.user=d,n.setItem(o,JSON.stringify(d))},async refresh(){let d=n.getItem(r);if(!d)return!1;try{let m=await fetch(c,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:d})});if(!m.ok)return a.logout(),!1;let w=await m.json();return a.token=w.token,n.setItem(t,w.token),w.refreshToken&&n.setItem(r,w.refreshToken),!0}catch{return!1}}};return s&&rt(s)&&a.refresh().catch(()=>{}),re(i,{auth:a})}}function it(e={}){let n=e.url??"/ws",t=e.reconnectInterval??3e3,o=e.maxReconnect??10,r=e.pingInterval??3e4,c=e.pingTimeout??1e4;return i=>{let s=new Set,u=null,a=0,d=null,m=null,w=null,C=!1,h={isConnected:!1,onMessage:l=>(s.add(l),()=>{s.delete(l)}),send:l=>{u?.readyState===WebSocket.OPEN&&u.send(JSON.stringify(l))},_connect:g,close:()=>{C=!0,S(),u?.close(),u=null,h.isConnected=!1}};async function g(){if(!C)try{u=new WebSocket(n),u.onopen=()=>{h.isConnected=!0,a=0,v()},u.onmessage=l=>{try{let f=JSON.parse(l.data);for(let p of s)p(f)}catch{}x()},u.onclose=()=>{h.isConnected=!1,S(),!C&&a<o&&(a++,d=setTimeout(g,t*Math.min(a,5)))},u.onerror=()=>{u?.close()}}catch{C||(d=setTimeout(g,t))}}function v(){r<=0||(m=setInterval(()=>{u?.readyState===WebSocket.OPEN&&u.send(JSON.stringify({type:"ping"})),w=setTimeout(()=>{u?.close()},c)},r))}function x(){clearTimeout(w)}function S(){clearInterval(m),clearTimeout(w),clearTimeout(d)}return g(),re(i,{ws:h})}}function Ne(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}var lt=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function at(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 ut(e){return typeof e=="string"?e:e&&typeof e=="object"?Object.entries(e).filter(([,n])=>n!=null).map(([n,t])=>`${n}:${typeof t=="number"?t+"px":String(t)}`).join(";"):""}function bn(e,n){let t=new Set,o={$:()=>Q(()=>{}),dirty:()=>{},render:()=>{},selfId:i=>{if(t.has(i))throw new Error(`[weifuwu] Duplicate component ID: "${i}"`);t.add(i)},useMedia:()=>{},useBreakpoint:()=>{},usePopupPosition:()=>({top:0,left:0,refresh:()=>{}}),useHoverCapable:()=>!1,useVisualViewport:()=>({height:0,offsetTop:0,keyboardOpen:!1}),useLongPress:()=>({}),useInView:()=>({isIn:!1,ready:!1,observe:()=>{},refresh:()=>{},disconnect:()=>{}}),useScrollPosition:()=>({y:0,refresh:()=>{}}),useStableRef:i=>s=>{s&&i?.(s)},useGlobalKey:()=>()=>{},useReducedMotion:()=>!1,useAnimationEnd:()=>()=>{},useTween:i=>{let s={value:i,reset:u=>{s.value=u}};return s},useDrag:()=>({onPointerDown:()=>{}}),useDragDrop:()=>({dropProps:{},dragProps:{}}),useControlled:i=>({value:i.value,setValue:s=>{i.onChange?.(s)},controlled:i.value!==void 0}),useControlledInput:i=>({value:i.value,setValue:s=>{i.onChange?.(s)},controlled:i.value!==void 0,keyword:"",setKeyword:()=>{},selectedLabel:"",setSelectedLabel:()=>{}}),useOpen:i=>({get open(){return!!i.open},setOpen:s=>{i.onOpenChange?.(s)},triggerProps:{}}),useAsync:()=>({data:void 0,loading:!0,error:void 0,reload:()=>{}}),usePopup:()=>({open:!1,setOpen:()=>{},wrapProps:{},portal:()=>null,refresh:()=>{}}),usePresence:()=>({phase:"closed",ref:()=>{},sync:i=>i?"open":"closed"}),useDialog:()=>({phase:"closed",rootRef:()=>{},panelRef:()=>{},sync:i=>i?"open":"closed"}),useChat:()=>({messages:[],input:"",streaming:!1,error:null,usage:null,step:null,send:()=>{},stop:()=>{},retry:()=>{},clear:()=>{},approve:async()=>{},dispose:()=>{}})},r={activeElement:()=>null,byId:()=>null,query:()=>null,queryAll:()=>null,createElement:()=>null,createElementNS:()=>null,createDocumentFragment:()=>null,createComment:()=>null,createTextNode:()=>null,addEventListener:()=>{},removeEventListener:()=>{},scrollTo:()=>{},matchMedia:()=>null,visualViewport:()=>null,scrollingElement:()=>null,bodyElement:()=>null,bodyAppend:()=>{},bodyRemove:()=>{},clearBody:()=>{},event:()=>new Event("wf-ssr"),dispatchEvent:()=>!1,navigate:()=>{},createTreeWalker:()=>null,copyText:async()=>!1,execCommand:()=>!1,selectionText:()=>null,getSelection:()=>null,queryCommandState:()=>!1,queryCommandValue:()=>"",viewportHeight:()=>0,viewportWidth:()=>0,pathname:()=>"",scrollTop:()=>0,hash:()=>"",setHash:()=>{},timeout:()=>0,rootElement:()=>null,storageGet:()=>null,storageSet:()=>{}},c=Object.create(e??{});return c.ui=o,c.browser=r,c.data={async get(i,s){if(n.has(i))return n.get(i);if(!s)return;let u=await s();return n.set(i,u),u},set(i,s){n.set(i,s)},has(i){return n.has(i)}},c}async function ne(e,n){if(e==null||typeof e=="boolean")return"";if(typeof e=="string"||typeof e=="number")return Ne(String(e));if(Array.isArray(e)){let a="";for(let d of e)a+=await ne(d,n);return a}let t=e;if(t.type===B||t.type===G)return ne(t.props?.children,n);if(typeof t.type=="function"){let a=Object.create(n),d;try{d=t.type(t.props??{},a)}catch(m){throw m}if(d instanceof Promise&&(d=await d),typeof d!="function")throw new Error(`Component ${t.type.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);return ne(d(t.props??{}),a)}let o=t.type,r=t.props??{},c=[],i;for(let[a,d]of Object.entries(r))if(!(a==="children"||a==="key")&&a!=="ref"&&!(a.startsWith("on")&&typeof d=="function")){if(a==="innerHTML"){i=String(d??"");continue}if(a==="class"||a==="className"){let m=at(d);m&&c.push(` class="${Ne(m)}"`);continue}if(a==="style"&&d&&typeof d=="object"){c.push(` style="${Ne(ut(d))}"`);continue}if(d===!0){c.push(` ${a}`);continue}d===!1||d==null||c.push(` ${a}="${Ne(String(d))}"`)}let s=c.join("");if(lt.has(o))return`<${o}${s}>`;if(i!==void 0)return`<${o}${s}>${i}</${o}>`;let u=await ne(r.children,n);return`<${o}${s}>${u}</${o}>`}async function dt(e,n,t,o={}){let r=o.data??new Map,c=bn(t,r);return await ne({type:e,props:n??{},key:void 0},c)}function Cn(e){return`<script>window.__DATA__=${JSON.stringify(Object.fromEntries(e)).replace(/</g,"\\u003c")};<\/script>`}async function ct(e,n){let t=new Map,r=bn({params:{},query:{}},t),c=n.url.split("?")[0].split("#")[0],i=e.match(c);r.params=i.params,r.query=Object.fromEntries(new URLSearchParams(n.url.split("?")[1]??""));let s=new URL(n.url.startsWith("http")?n.url:`http://localhost${n.url.startsWith("/")?n.url:"/"+n.url}`),u=await e.execute(s,r,c),a=await ne(u,r),d=Cn(t),m=i.title??n.title??"",w=n.rootId??"root",C=(n.styles??[]).map(g=>` <link rel="stylesheet" href="${g}">`).join(`
7
+ `),h=`<!DOCTYPE html>
7
8
  <html lang="${n.lang??"zh-CN"}">
8
9
  <head>
9
10
  <meta charset="UTF-8">
10
11
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
11
- ${p?`<title>${p}</title>`:""}
12
+ ${m?`<title>${m}</title>`:""}
13
+ ${C}
12
14
  </head>
13
15
  <body>
14
- <div id="${v}">${u}</div>
16
+ <div id="${w}">${a}</div>
15
17
  ${d}
16
18
  <script src="/app.js"><\/script>
17
19
  </body>
18
- </html>`;return{html:u,dataScript:d,page:b}}export{G as Fragment,ue as Placeholder,B as Portal,We as Suspense,Ae as UIRouter,at as animateOut,lt as api,Bn as asyncComponent,ct as auth,tt as callRefCleanup,j as createClientBrowser,qe as createPortal,Q as createReactiveState,de as h,ze as hydrateVNode,ne as isAsyncComponent,je as jsx,Gn as jsxDEV,Kn as jsxs,nt as mountVNode,Z as patchValue,Nn as serializeData,ht as ssrPage,gt as ssrToString,it as uiServe,ft as ws};
20
+ </html>`;return{html:a,dataScript:d,page:h}}export{G as Fragment,Ce as Placeholder,B as Portal,Oe as Suspense,Le as UIRouter,nt as animateOut,tt as api,st as auth,zn as callRefCleanup,W as createClientBrowser,We as createPortal,Q as createReactiveState,Te as h,Je as hydrateVNode,De as jsx,Wn as jsxDEV,Dn as jsxs,Yn as mountVNode,Z as patchValue,Cn as serializeData,ct as ssrPage,dt as ssrToString,et as uiServe,it as ws};
@@ -1,13 +1,13 @@
1
1
  /**
2
- * weifuwu/client api — HTTP 客户端中间件
2
+ * weifuwu/ui-dom api — HTTP 客户端中间件
3
3
  *
4
4
  * 注入 ctx.api,提供类型友好的 fetch 封装。
5
5
  * 支持 baseURL、默认 headers、请求/响应拦截器。
6
6
  *
7
7
  * ```ts
8
- * import { createApp, api } from 'weifuwu/client'
8
+ * import { UIRouter, api } from 'weifuwu/ui-dom'
9
9
  *
10
- * const app = createApp()
10
+ * const app = new UIRouter()
11
11
  * app.use(api({ baseURL: '/api' }))
12
12
  *
13
13
  * // 在组件中:
@@ -1,5 +1,5 @@
1
1
  /**
2
- * weifuwu/client auth — 认证状态管理中间件
2
+ * weifuwu/ui-dom auth — 认证状态管理中间件
3
3
  *
4
4
  * 管理 token 存储、登录/登出、当前用户信息。
5
5
  * 不依赖 signal,状态为普通对象,组件通过 ctx.ui.render() 刷新。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * weifuwu/client — 动效工具
2
+ * weifuwu/ui-dom — 动效工具
3
3
  *
4
4
  * animateOut:挂 --exit 类播退场动画,animationend 后回调。
5
5
  * - reduced-motion 下动画时长被 _base.css 降为 0.01ms,animationend 立即触发,等效瞬时关闭
@@ -1,5 +1,5 @@
1
1
  /**
2
- * weifuwu/client — 弹出层定位工具
2
+ * weifuwu/ui-dom — 弹出层定位工具
3
3
  *
4
4
  * 基于 position: fixed 的坐标计算,替代 CSS absolute 定位。
5
5
  * 配合 createPortal 使用,让弹出层不受父级 overflow/transform 影响。