weifuwu 0.77.0 → 0.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/components/List/List.d.ts +3 -0
- package/dist/components/index.js +1 -1
- package/dist/index.js +56 -3
- package/dist/ui-dom/index.js +11 -11
- package/dist/ui-dom/testing.js +1 -1
- package/dist/ui-dom/types.d.ts +2 -0
- package/dist/ui-dom/vdom/audit.d.ts +20 -0
- package/dist/ui-dom/vdom/diff.d.ts +1 -1
- package/dist/ui-dom/vdom/render.d.ts +4 -2
- package/dist/ui-dom/vdom/transform.d.ts +32 -0
- package/dist/ui-dom/vnode.d.ts +3 -0
- package/docs/components.md +1 -1
- package/docs/custom-components.md +8 -0
- package/docs/frontend-ui-dom.md +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,6 +93,8 @@ npm install weifuwu # 一个依赖,完整应用栈
|
|
|
93
93
|
|
|
94
94
|
**render-only 确定性渲染** — 渲染唯一触发 `ctx.ui.render()`(闭包绑定组件),状态是普通对象(`let` + `render()`);跨组件共享用 `createStore` + `ctx.ui.useExternal()`。行为可静态推导,无隐式触发(详见[组件库](docs/components.md))。
|
|
95
95
|
|
|
96
|
+
**VDOM 输出透明(写 JSX,看 DOM 即真相)** — VDOM 对用户输入零 magic:条件渲染的 false 在 DOM 里是诊断占位注释(`<!--wf-hole: false-->`),数组项 key 与组件实例 id 直接落 DOM(`data-wf-key` / `data-wf-id`)——devtools 看到的 DOM 就是引擎决策的可读输出;非法输入占位 + warn,不崩溃不静默。转化契约唯一清晰(design/vdom-transform-rules.md):用户写什么,vnode 就是什么,DOM 就长什么样。
|
|
97
|
+
|
|
96
98
|
**中间件注入一切** — 后端和前端共用同一理念:中间件向 `ctx` 注入能力(`ctx.sql` / `ctx.redis` / `ctx.api` / `ctx.auth` / `ctx.i18n` / `ctx.limit` / `ctx.email` / `ctx.queue` / `ctx.ai` / `ctx.msg` 等),Handler/组件从 `ctx` 读取。
|
|
97
99
|
|
|
98
100
|
**async 工厂组件** — `async (initProps, ctx) => (props) => Promise<VNode>`(weifuwu **唯一组件形态**——同步组件已不支持):工厂层声明数据(`await ctx.data.get`)、mount 初始化状态(`let` + `render()`)、render 输出视图。异步在工厂边界与 renderFn,数据经闭包注入,写数据像写同步代码。三条纪律见[核心概念 · async 组件](#核心概念)。
|
|
@@ -396,7 +398,7 @@ cd apps/agent-platform && npm run seed && npm run dev
|
|
|
396
398
|
| **UIHandler**(路由) | `async (location, ctx) => VNode` | ✅ 整体 | 每次路由变化执行 |
|
|
397
399
|
| **Component**(唯一形态) | `async (initProps, ctx) => (props) => Promise<VNode>` | ✅ 工厂 + renderFn | mount 一次 + render 每次;同步组件已不支持(类型强制 Promise) |
|
|
398
400
|
|
|
399
|
-
异步只在两个边界——路由 handler(整页)和组件工厂(数据声明)+ renderFn(强制异步)。渲染器按「返回值 instanceof Promise」统一判别:主路径 `buildVNode` async 预构建(await 全部工厂,兄弟并行)→
|
|
401
|
+
异步只在两个边界——路由 handler(整页)和组件工厂(数据声明)+ renderFn(强制异步)。渲染器按「返回值 instanceof Promise」统一判别:主路径 `buildVNode` async 预构建(await 全部工厂,兄弟并行)→ 原子落地(无**中间态**占位、无补全回调——注意:数组内 false/null 的静态诊断占位 `<!--wf-hole-->` 是另一回事,见「VDOM 输出透明」);运行时首次挂载的 async 组件同样在 buildVNode 阶段 await;骨架屏 `uiServe({ loading })` + `handle.ready`。
|
|
400
402
|
### 两阶段组件(新手必读:为什么是两层)
|
|
401
403
|
|
|
402
404
|
组件 = `async (initProps, ctx) => (props) => Promise<VNode>`——**外层 = 初始化(只执行一次,可 await 数据),内层 = 渲染(每次状态/props 变化时执行,强制异步)**。类比:外层是对象的构造函数,内层是它的 render 方法。
|
|
@@ -8,6 +8,9 @@ import type { Component } from '../../ui-dom/vnode.ts';
|
|
|
8
8
|
export interface ListProps<T = any> {
|
|
9
9
|
items: T[];
|
|
10
10
|
renderItem: (item: T, index: number) => any;
|
|
11
|
+
/** 自定义项 key(可选,默认数组下标)——renderItem 渲染有内部状态的组件且列表动态增删/重排时传
|
|
12
|
+
* 身份跟随内容的 key(如项 id),否则默认下标 = 位置身份,增删后项状态会继承错位(规则表 §3) */
|
|
13
|
+
keyBy?: (item: T, index: number) => string | number;
|
|
11
14
|
divided?: boolean;
|
|
12
15
|
header?: any;
|
|
13
16
|
footer?: any;
|
package/dist/components/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import{h as Un}from"weifuwu/ui-dom";var sr={"chevron-down":["M6 9l6 6 6-6"],"che
|
|
|
5
5
|
`)+(g.length?`
|
|
6
6
|
`:"")});continue}let r=a.match(/^(#{1,4})\s+(.+)$/);if(r){o({type:"heading",level:r[1].length,inline:ge(r[2])}),e++;continue}if(/^\s*-{3,}\s*$/.test(a)){o({type:"hr"}),e++;continue}if(/^\s*>/.test(a)){let p=[];for(;e<n.length&&/^\s*>/.test(n[e]);)p.push(n[e].replace(/^\s*>\s?/,"")),e++;o({type:"quote",inline:ge(p.join(`
|
|
7
7
|
`))});continue}if(a.match(/^\|(.+)\|\s*$/)&&e+1<n.length&&/^\|?[\s:|-]+\|?[\s:|-]*$/.test(n[e+1])&&n[e+1].includes("-")){let p=b=>b.replace(/^\|/,"").replace(/\|\s*$/,"").split("|").map(x=>x.trim()),g=p(a),m=p(n[e+1]).map(b=>{let x=b.startsWith(":"),y=b.endsWith(":");return x&&y?"center":y?"right":"left"});e+=2;let h=[];for(;e<n.length&&/^\|(.+)\|\s*$/.test(n[e]);)h.push(p(n[e])),e++;o({type:"table",headers:g,rows:h,aligns:m});continue}let l=a.match(/^\s*[-*+]\s+(.+)$/),c=/^\s*[-*+]\s+\[([ xX])]\s+(.+)$/;if(a.match(c)||l){let p=[],g=[],m=h=>{let b=h.match(c);if(b)p.push(ge(b[2])),g.push(b[1].toLowerCase()==="x");else{let x=h.match(/^\s*[-*+]\s+(.+)$/);p.push(ge(x?x[1]:h)),g.push(null)}};for(m(a),e++;e<n.length;)if(n[e].match(c)||n[e].match(/^\s*[-*+]\s+(.+)$/))m(n[e]),e++;else if(/^\s*$/.test(n[e])){e++;break}else if(/^\s{2,}/.test(n[e]))p[p.length-1].push({type:"text",text:" "+n[e].trim()}),e++;else break;o({type:"list",ordered:!1,items:p,checks:g});continue}let d=a.match(/^\s*\d+\.\s+(.+)$/);if(d){let p=[ge(d[1])];for(e++;e<n.length;){let g=n[e].match(/^\s*\d+\.\s+(.+)$/);if(g)p.push(ge(g[1])),e++;else if(/^\s*$/.test(n[e])){e++;break}else break}o({type:"list",ordered:!0,items:p});continue}let f=[a];for(e++;e<n.length&&!/^\s*$/.test(n[e])&&!/^\s*```/.test(n[e])&&!/^\s*#/.test(n[e])&&!/^\s*>/.test(n[e])&&!/^\s*[-*+]\s+/.test(n[e])&&!/^\s*\d+\.\s+/.test(n[e])&&!/^\s*-{3,}\s*$/.test(n[e])&&!/^\|(.+)\|\s*$/.test(n[e]);)f.push(n[e]),e++;o({type:"paragraph",inline:ge(f.join(`
|
|
8
|
-
`))})}return t}import{h as Ce}from"weifuwu/ui-dom";var Po=/\b(?:const|let|var|function|return|if|else|for|while|do|switch|case|break|continue|import|export|from|default|async|await|class|new|extends|implements|type|interface|public|private|protected|readonly|static|this|super|true|false|null|undefined|of|in|typeof|instanceof|void|throw|try|catch|finally|yield|as|satisfies)\b/,Ds=/\b(?:if|then|else|fi|for|do|done|while|case|esac|function|echo|cd|ls|mkdir|rm|cp|mv|export|source|sudo|npm|node|docker)\b/;var Lp=new RegExp(["(/\\*[\\s\\S]*?\\*/|//[^\\n]*|#[^\\n]*)","(\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'|`(?:[^`\\\\]|\\\\.)*`)","("+Po.source+")","(\\b\\d+(?:\\.\\d+)?(?:px|%|em|rem|vh|vw|fr|ms|s)?\\b)","([A-Za-z_$][\\w$]*(?=\\s*\\())","(<\\/?[A-Za-z][\\w.-]*)","(<=|>=|===|!==|==|!=|=>|\\+\\+|--|&&|\\|\\||\\?\\?|\\??\\.|[{}()\\[\\];,.:=+\\-*/<>!?&|^~%])"].join("|"),"g");function Os(i){return i==="bash"||i==="sh"||i==="shell"?Ds:Po}function To(i,n){let t=[],e=Os(n??""),o=n==="tsx"||n==="jsx"||n==="html"||!n,a=new RegExp(["(/\\*[\\s\\S]*?\\*/|//[^\\n]*|#[^\\n]*)","(\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'|`(?:[^`\\\\]|\\\\.)*`)","("+e.source+")","(\\b\\d+(?:\\.\\d+)?(?:px|%|em|rem|vh|vw|fr|ms|s)?\\b)","([A-Za-z_$][\\w$]*(?=\\s*\\())",o?"(<\\/?[A-Za-z][\\w.-]*)":"(?!x)x","(<=|>=|===|!==|==|!=|=>|\\+\\+|--|&&|\\|\\||\\?\\?|\\??\\.|[{}()\\[\\];,.:=+\\-*/<>!?&|^~%])"].join("|"),"g"),r=0,s;for(;(s=a.exec(i))!==null;){s.index>r&&t.push({type:"text",text:i.slice(r,s.index)});let l="operator";for(let c=1;c<=7;c++)if(s[c]!==void 0){l=["comment","string","keyword","number","function","jsx-tag","operator"][c-1];break}t.push({type:l,text:s[0]}),r=s.index+s[0].length,s[0].length===0&&(r++,a.lastIndex=r)}return r<i.length&&t.push({type:"text",text:i.slice(r)}),t}var Ln=async(i,n)=>{let t=!1,e,o="",a=async()=>{await n.browser?.copyText(o),t=!0,n.ui.render(),clearTimeout(e),e=setTimeout(()=>{t=!1,n.ui.render()},1600)};return async r=>{let{code:s,lang:l,title:c}=r;o=s;let u=l?Ce("span",{class:"wf-codeblock-lang"},[Ce("span",{class:"wf-codeblock-dot"}),l]):null,d=Ce("button",{class:"wf-codeblock-copy",type:"button","aria-label":"\u590D\u5236",title:"\u590D\u5236\u4EE3\u7801",onClick:a},t?Ce(T,{name:"check",size:14}):Ce(T,{name:"copy",size:14})),f=Ce("div",{class:"wf-codeblock-header"},[Ce("span",{class:"wf-codeblock-title"},c??u??"\u4EE3\u7801"),d].filter(Boolean)),p=s&&To(s,l).map((m,h)=>m.type==="text"?m.text:Ce("span",{class:`wf-hl-${m.type}`},m.text)),g=Ce("pre",{class:"wf-codeblock-pre"},Ce("code",{class:"wf-codeblock-code"},p));return Ce("div",{class:"wf-codeblock"},[f,g])}};var Bs=async(i,n)=>async t=>{let{content:e="",className:o}=t,a=En(e);return a.length===0?null:ee("div",{class:`wf-md${o?` ${o}`:""}`},a.map((r,s)=>Hs(r,s)))};function Hs(i,n){switch(i.type){case"heading":return ee(`h${i.level}`,{class:`wf-md-h wf-md-h${i.level}`,key:n},ke(i.inline));case"paragraph":return ee("p",{class:"wf-md-p",key:n},ke(i.inline));case"list":{let t=i.checks?.some(o=>o!==null),e=i.ordered?"ol":"ul";return ee(e,{class:`wf-md-${i.ordered?"ol":"ul"}${t?" wf-md-task-list":""}`,key:n},i.items.map((o,a)=>{let r=i.checks?.[a];return ee("li",{class:`wf-md-li${r!=null?" wf-md-task":""}`,key:a},r!=null?[ee("input",{type:"checkbox",class:"wf-md-task-check",checked:!!r,disabled:!0,key:"c"}),...ke(o)]:ke(o))}))}case"code":return ee(Ln,{key:n,code:i.code??"",lang:i.lang});case"quote":return ee("blockquote",{class:"wf-md-quote",key:n},ke(i.inline));case"hr":return ee("hr",{class:"wf-md-hr",key:n});case"table":{let t=e=>i.aligns?.[e]?{textAlign:i.aligns[e]}:void 0;return ee("div",{class:"wf-md-table-wrap",key:n},ee("table",{class:"wf-md-table"},[ee("thead",{key:"h"},ee("tr",{key:"r"},i.headers.map((e,o)=>ee("th",{class:"wf-md-th",style:t(o),key:o},ke(ge(e)))))),ee("tbody",{key:"b"},i.rows.map((e,o)=>ee("tr",{class:"wf-md-tr",key:o},e.map((a,r)=>ee("td",{class:"wf-md-td",style:t(r),key:r},ke(ge(a)))))))]))}default:return null}}function ke(i){return i.map((n,t)=>{switch(n.type){case"code":return ee("code",{class:"wf-md-code",key:t},n.text??"");case"bold":return ee("strong",{class:"wf-md-strong",key:t},ke(n.children??[]));case"italic":return ee("em",{class:"wf-md-em",key:t},ke(n.children??[]));case"del":return ee("del",{class:"wf-md-del",key:t},ke(n.children??[]));case"link":return ee("a",{class:"wf-md-link",key:t,href:n.href,target:"_blank",rel:"noopener noreferrer"},ke(n.children??[]));default:return ee(Rs,{key:t},n.text??"")}})}import{h as Be}from"weifuwu/ui-dom";var Ns=async(i,n)=>async t=>{let{items:e,mode:o="left",reverse:a}=t,s=(a?[...e].reverse():e).map((l,c)=>{let{key:u,title:d,time:f,content:p,status:g="default",dot:m,onClick:h}=l,b=Be("div",{class:`wf-timeline-node wf-timeline-node--${g}`},m??null),x=Be("div",{class:"wf-timeline-head"},[Be("span",{class:"wf-timeline-title"},d),f?Be("span",{class:"wf-timeline-time"},f):null].filter(Boolean)),y=p!=null?Be("div",{class:"wf-timeline-content"},p):null,w=Be("div",{class:"wf-timeline-col"},[x,y].filter(Boolean));if(o==="horizontal")return Be("li",{key:u,class:`wf-timeline-item wf-timeline-item--h${h?" wf-timeline-item--clickable":""}`,role:h?"button":void 0,tabIndex:h?0:void 0,onClick:h,onKeyDown:h?k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),h())}:void 0},[b,w]);let v=o==="alternate"?c%2===0?" wf-timeline-item--alt-left":" wf-timeline-item--alt-right":"";return Be("li",{key:u,class:`wf-timeline-item${h?" wf-timeline-item--clickable":""}${v}`,role:h?"button":void 0,tabIndex:h?0:void 0,onClick:h,onKeyDown:h?k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),h())}:void 0},[b,w])});return Be("ul",{class:`wf-timeline${o==="horizontal"?" wf-timeline--h":""}`},s)};import{h as Jt}from"weifuwu/ui-dom";var zs=async(i,n)=>async t=>{let{items:e,column:o=1,bordered:a,size:r="md",className:s}=t,l=e.map((c,u)=>Jt("div",{key:u,class:"wf-descriptions-item",style:c.span&&c.span>1?{gridColumn:`span ${c.span}`}:void 0},[Jt("dt",{class:"wf-descriptions-label"},c.label),Jt("dd",{class:"wf-descriptions-value"},c.value)]));return Jt("dl",{class:`wf-descriptions wf-descriptions--${o} wf-descriptions--${r}${a?" wf-descriptions--bordered":""}${s?` ${s}`:""}`},l)};import{h as Yt}from"weifuwu/ui-dom";var _s=async(i,n)=>async t=>{let{items:e,max:o,size:a,className:r}=t;if(!e||e.length===0)return null;let s=o&&e.length>o?e.slice(0,o):e,l=o?Math.max(0,e.length-o):0,c=s.map((d,f)=>Yt("span",{key:f,class:"wf-avatar-group-item"},Yt(fn,{name:d.name,src:d.src,color:d.color,size:a}))),u=l>0?Yt("span",{class:"wf-avatar-group-more",role:"img","aria-label":`\u8FD8\u6709 ${l} \u4EBA`},`+${l}`):null;return Yt("div",{class:`wf-avatar-group${r?` ${r}`:""}`},[...c,u].filter(Boolean))};import{h as Qt}from"weifuwu/ui-dom";var js=async(i,n)=>async t=>{let{content:e,role:o,status:a="complete",actions:r,className:s}=t,l=o==="user"?"wf-bubble--own":"wf-bubble--ai",c=a==="error"?" wf-bubble--error":a==="streaming"?" wf-bubble--streaming":"",u=r?Qt("div",{class:"wf-bubble-body"},[Qt("div",{class:"wf-bubble-text"},e),Qt("div",{class:"wf-bubble-actions"},r)]):e;return Qt("div",{class:`wf-bubble ${l}${c}${s?` ${s}`:""}`,role:a==="error"?"alert":void 0},u)};import{createClientBrowser as Ks}from"weifuwu/ui-dom";import{h as ae}from"weifuwu/ui-dom";var Ws=async(i,n)=>{let t=n.browser??Ks(),e=null,o=[],a=!1,r=null,s=null,l=n.ui.usePopup({trigger:"click",placement:"right",gap:6,el:()=>s,isOpen:()=>r!==null,setOpen:d=>{d||(r=null),n.ui.render()}}),c=d=>{d&&(e=d)},u=d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;let f=e?Array.from(e.querySelectorAll(".wf-menu-item, .wf-menu-submenu-title")):[],p=f.indexOf(t?.activeElement()??null);if(p<0)return;d.preventDefault();let g=p;d.key==="ArrowDown"?g=(p+1)%f.length:d.key==="ArrowUp"?g=(p-1+f.length)%f.length:d.key==="Home"?g=0:d.key==="End"&&(g=f.length-1),f[g].focus()};return async d=>{let{items:f,onSelect:p,activeKey:g,className:m,openKeys:h,onOpenChange:b,collapsible:x,collapsed:y,onCollapseChange:w}=d,v=h!==void 0,k=y!==void 0,S=new Set(v?h:o),P=k?!!y:a,E=C=>{v?b?.(C):(o=C,n.ui.render())},A=(C,I)=>{let B=I!=null?I?[...S,C]:[...S].filter(_=>_!==C):S.has(C)?[...S].filter(_=>_!==C):[...S,C];E([...new Set(B)])},L=()=>{let C=!P;k?w?.(C):(a=C,n.ui.render())},$=C=>{let I=S.has(C.key)&&!P,B=C.active??(g!=null&&C.key===g);if(P){let J=r===C.key,ve=ae("div",{"data-key":C.key,class:`wf-menu-submenu-title wf-menu-submenu-title--collapsed${B?" wf-menu-submenu-title--active":""}`,role:"menuitem",tabIndex:B?0:-1,"aria-haspopup":"menu","aria-expanded":J?"true":"false",onClick:F=>{J?(r=null,n.ui.render()):(s=F.currentTarget,r=C.key,n.ui.render())},onKeyDown:F=>{F.key==="Enter"||F.key===" "||F.key==="ArrowRight"?(F.preventDefault(),J||(s=F.currentTarget,r=C.key,n.ui.render())):F.key==="Escape"&&(F.preventDefault(),r=null,n.ui.render())}},[C.icon?ae("span",{class:"wf-menu-icon"},C.icon):null].filter(Boolean)),ue=l.portal(ae("div",{class:"wf-menu-popup"},(C.children??[]).map(F=>H(F,!0,!0))),"menu-popup");return ae("div",{key:C.key,"data-key":C.key,class:"wf-menu-submenu wf-menu-submenu--collapsed"},[ve,J?ue:null])}let _=[C.icon?ae("span",{class:"wf-menu-icon"},C.icon):null,P?null:ae("span",{class:"wf-menu-label"},C.label),P?null:ae("span",{class:"wf-menu-arrow"},ae(T,{name:"chevron-right",size:12}))].filter(Boolean),G=ae("div",{"data-key":C.key,class:`wf-menu-submenu-title${B?" wf-menu-submenu-title--active":""}`,role:"menuitem",tabIndex:B?0:-1,"aria-expanded":I?"true":"false",onClick:()=>A(C.key),onKeyDown:J=>{J.key==="Enter"||J.key===" "||J.key==="ArrowRight"?(J.preventDefault(),I||A(C.key,!0)):(J.key==="ArrowLeft"||J.key==="Escape")&&I&&(J.preventDefault(),A(C.key,!1))}},_),Q=ae("div",{class:"wf-menu-submenu-content",role:"group"},(C.children??[]).map(J=>H(J,!0)));return ae("div",{key:C.key,"data-key":C.key,class:`wf-menu-submenu${I?" wf-menu-submenu--open":""}`},[G,Q])},H=(C,I=!1,B=!1)=>{if(C.children&&C.children.length>0&&!P)return $(C);let _=C.active??(g!=null&&C.key===g);return ae("div",{key:C.key,"data-key":C.key,class:`wf-menu-item${_?" wf-menu-item--active":""}${C.danger?" wf-menu-item--danger":""}${I?" wf-menu-item--child":""}`,role:"menuitem",tabIndex:_?0:-1,"aria-current":_?"page":void 0,onClick:()=>{C.onClick?C.onClick():p?.(C.key)},onKeyDown:G=>{if(G.key==="Enter"||G.key===" ")G.preventDefault(),C.onClick?C.onClick():p?.(C.key);else if((G.key==="ArrowLeft"||G.key==="Escape")&&I){G.preventDefault();let Q=C._parentKey;Q&&S.has(Q)&&A(Q,!1)}}},[C.icon?ae("span",{class:"wf-menu-icon"},C.icon):null,P&&!B?null:ae("span",{class:"wf-menu-label"},C.label)].filter(Boolean))},R=[],N;for(let C of f)if(C.group!==N&&(R.push(ae("div",{class:"wf-menu-group",key:`g-${C.group}`},C.group)),N=C.group),C.children&&C.children.length>0){let I=$(C);!P&&I.props.children[1]&&(I.props.children[1].props.children=I.props.children[1].props.children.map(B=>B?.props?{...B,props:{...B.props,_parentKey:C.key}}:B)),R.push(I)}else R.push(H(C));let D=["wf-menu",P?"wf-menu--collapsed":"",m??""].filter(Boolean).join(" "),M=[...R,x?ae("div",{class:"wf-menu-collapse-btn",role:"button",tabIndex:0,"aria-label":P?"\u5C55\u5F00\u83DC\u5355":"\u6298\u53E0\u83DC\u5355",onClick:L,onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),L())}},P?ae(T,{name:"chevron-right",size:14}):ae(T,{name:"chevron-left",size:14})):null].filter(Boolean);return ae("nav",{class:D,role:"menu",ref:c,onKeyDown:u},M)}};import{h as He}from"weifuwu/ui-dom";var Vs=async(i,n)=>{let t=!1;return async e=>{let{value:o,onInput:a,onChange:r,label:s,name:l,placeholder:c,disabled:u,error:d,hint:f,required:p,autoComplete:g,className:m}=e,h=()=>{u||(t=!t,n.ui.render())},b=s?He("label",{class:"wf-input-label"},[s,p?He("span",{class:"wf-input-req"},"*"):null].filter(Boolean)):null,x=He("input",{class:"wf-input",type:t?"text":"password",value:o,name:l,placeholder:c,disabled:u,autoComplete:g,onInput:a,onChange:r}),y=He("button",{class:"wf-password-eye",type:"button","aria-label":t?"\u9690\u85CF\u5BC6\u7801":"\u663E\u793A\u5BC6\u7801",tabIndex:-1,onClick:h},He(T,{name:t?"eye-off":"eye",size:16})),w=He("div",{class:"wf-input-wrap wf-password"},[x,y]),v=[];return b&&v.push(b),v.push(w),d&&v.push(He("div",{class:"wf-input-err"},d)),f&&!d&&v.push(He("div",{class:"wf-input-hint"},f)),He("div",{class:`wf-field${m?` ${m}`:""}`},v)}};import{h as Ee}from"weifuwu/ui-dom";var Fs=async(i,n)=>{let t=!1;return async e=>{let{placeholder:o,maxTags:a,allowDuplicates:r,disabled:s,label:l,error:c,hint:u,className:d}=e,f=n?.ui?.useControlled({value:e.value,onChange:e.onChange,name:"TagsInput"}),p=f?.value??[],g=S=>{let P=f?.controlled;f?.setValue(S),P||e.onChange?.(S)},m=S=>{if(s)return;let P=S.trim().replace(/,$/,"");P&&(a!=null&&p.length>=a||!r&&p.includes(P)||g([...p,P]))},h=S=>{s||g(p.filter(P=>P!==S))},b=S=>{let P=S.target;if(S.key==="Enter"||S.key===","){if(S.preventDefault(),t)return;m(P.value),P.value=""}else S.key==="Backspace"&&!P.value&&p.length>0&&h(p[p.length-1])},x=l?Ee("label",{class:"wf-input-label"},l):null,y=p.map(S=>Ee("span",{key:S,class:"wf-tags-tag"},[Ee("span",{class:"wf-tags-text"},S),Ee("button",{class:"wf-tags-remove",type:"button","aria-label":`\u79FB\u9664 ${S}`,onClick:()=>h(S)},Ee(T,{name:"close",size:12}))])),w=Ee("input",{class:"wf-tags-input",type:"text",placeholder:p.length===0?o:void 0,disabled:s,onKeyDown:b,onCompositionStart:()=>{t=!0},onCompositionEnd:()=>{t=!1}}),v=Ee("div",{class:`wf-tags${s?" wf-tags--disabled":""}${c?" wf-tags--err":""}${d?` ${d}`:""}`},[...y,w]),k=[];return x&&k.push(x),k.push(v),c&&k.push(Ee("div",{class:"wf-input-err"},c)),u&&!c&&k.push(Ee("div",{class:"wf-input-hint"},u)),Ee("div",{class:"wf-field"},k)}};import{h as In}from"weifuwu/ui-dom";var Gs=async(i,n)=>async t=>{let{text:e,query:o,className:a}=t,r=(Array.isArray(o)?o:o?[o]:[]).filter(Boolean).map(u=>u.toLowerCase());if(r.length===0)return In("span",{class:`wf-highlight${a?` ${a}`:""}`},e);let s=[],l=0,c=e.toLowerCase();for(;l<e.length;){let u=null;for(let d of r){let f=c.indexOf(d,l);f>=0&&(!u||f<u.start)&&(u={start:f,end:f+d.length})}if(!u){s.push(e.slice(l));break}u.start>l&&s.push(e.slice(l,u.start)),s.push(In("mark",{class:"wf-highlight-mark"},e.slice(u.start,u.end))),l=u.end}return In("span",{class:`wf-highlight${a?` ${a}`:""}`},s)};import{h as Ze}from"weifuwu/ui-dom";var qs=async(i,n)=>async t=>{let{items:e,renderItem:o,divided:a,header:r,footer:s,emptyText:l="\u6682\u65E0\u6570\u636E",emptyIcon:c,className:u}=t,d=e.length===0?Ze("div",{class:"wf-list-empty"},[c??null,Ze("span",{},l)].filter(Boolean)):e.map((f,p)=>Ze("li",{key:p,class:"wf-list-item"},o(f,p)));return Ze("div",{class:`wf-list${a?" wf-list--divided":""}${u?` ${u}`:""}`},[r?Ze("div",{class:"wf-list-header"},r):null,Ze("ul",{class:"wf-list-body"},d),s?Ze("div",{class:"wf-list-footer"},s):null].filter(Boolean))};import{h as ft}from"weifuwu/ui-dom";var Us={success:"check",error:"close",warning:"alert",info:"info"},Js=async(i,n)=>async t=>{let{status:e="info",title:o,desc:a,extra:r,className:s}=t;return ft("div",{class:`wf-result wf-result--${e}${s?` ${s}`:""}`},[ft("div",{class:"wf-result-icon","aria-hidden":"true"},ft(T,{name:Us[e],size:40})),ft("div",{class:"wf-result-title"},o),a?ft("div",{class:"wf-result-desc"},a):null,r?ft("div",{class:"wf-result-extra"},r):null].filter(Boolean))};import{h as et}from"weifuwu/ui-dom";var Ys=async(i,n)=>{let t=-1,e=o=>{t!==o&&(t=o,n.ui.render())};return async o=>{let{count:a=5,size:r="md",readOnly:s,disabled:l,allowClear:c,allowHalf:u,"aria-label":d}=o,f=s||l,p=n?.ui?.useControlled({value:o.value,onChange:o.onChange,name:f?void 0:"Rate"}),g=p?.value??0,m=v=>{let k=p?.controlled;p?.setValue(v),k||o.onChange?.(v)},h=!s&&!l,b=t>=0?t+1:g,x=u?.5:1,y=v=>{if(!h)return;let k=v.key;k==="ArrowRight"?(v.preventDefault(),m(Math.min(g+x,a))):k==="ArrowLeft"?(v.preventDefault(),m(Math.max(g-x,0))):k==="Home"?(v.preventDefault(),m(x)):k==="End"&&(v.preventDefault(),m(a))},w=[];for(let v=0;v<a;v++){let k=v<Math.floor(b),S=u&&v===Math.floor(b)&&b%1>=.5,E={class:`wf-rate-star${k?" wf-rate-star--on":""}${S?" wf-rate-star--half":""}`,"aria-label":`${v+1} \u661F`,key:v};h&&(E.type="button",E.onClick=$=>{if(u){let R=$.currentTarget.getBoundingClientRect(),N=$.clientX-R.left<R.width/2;m(N?v+.5:v+1)}else c&&g===v+1?m(0):m(v+1)},E.onMouseEnter=u?$=>{let R=$.currentTarget.getBoundingClientRect();e($.clientX-R.left<R.width/2?v+.5-1:v)}:()=>e(v),E.onMouseMove=u?$=>{let R=$.currentTarget.getBoundingClientRect();e($.clientX-R.left<R.width/2?v+.5-1:v)}:void 0,E.onMouseLeave=()=>e(-1),E.onFocus=()=>e(v),E.onBlur=()=>e(-1));let A=et(T,{name:"star",className:"wf-rate-star-icon"}),L=S?et("span",{class:"wf-rate-star-half"},[et("span",{class:"wf-rate-star-half-bg"},A),et("span",{class:"wf-rate-star-half-fg"},et(T,{name:"star",className:"wf-rate-star-icon"}))]):A;w.push(et(h?"button":"span",E,L))}return et("div",{class:`wf-rate wf-rate--${r}${l?" wf-rate--disabled":""}`,role:h?"radiogroup":void 0,"aria-label":d??"\u8BC4\u5206",onKeyDown:h?y:void 0},w)}};import{h as An}from"weifuwu/ui-dom";var Qs=async i=>async n=>{let{level:t=1,children:e,className:o,style:a,...r}=n;return An(`h${t}`,{class:["wf-title",`wf-title--${t}`,o].filter(Boolean).join(" "),style:a,...r},e)},Xs=async i=>async n=>{let{type:t,strong:e,underline:o,strikethrough:a,mark:r,code:s,size:l,children:c,className:u,...d}=n,f=["wf-text"];return t&&f.push(`wf-text--${t}`),e&&f.push("wf-text--strong"),o&&f.push("wf-text--underline"),a&&f.push("wf-text--strike"),r&&f.push("wf-text--mark"),s&&f.push("wf-text--code"),l&&l!=="md"&&f.push(`wf-text--${l}`),u&&f.push(u),An("span",{class:f.join(" "),...d},c)},Zs=async i=>async n=>{let{type:t,ellipsis:e,children:o,className:a,...r}=n,s=["wf-paragraph"];return t&&s.push(`wf-text--${t}`),e&&s.push("wf-paragraph--ellipsis"),a&&s.push(a),An("p",{class:s.join(" "),...r},o)};import{h as So}from"weifuwu/ui-dom";var ea=async i=>async n=>{let{htmlFor:t,required:e,children:o,className:a,...r}=n,s=e?[o,So("span",{class:"wf-label-req"},"*")]:o;return So("label",{class:["wf-label",a].filter(Boolean).join(" "),htmlFor:t||void 0,...r},s)};import{h as ta}from"weifuwu/ui-dom";var na=async i=>async n=>{let{ratio:t,children:e,className:o,...a}=n;return ta("div",{class:["wf-aspect-ratio",o].filter(Boolean).join(" "),style:{"--wf-aspect-ratio":t===void 0?"16 / 9":String(t)},...a},e)};import{h as Dn}from"weifuwu/ui-dom";var $o=async i=>async n=>{let{pressed:t,onPressedChange:e,variant:o="default",size:a="md",disabled:r,"aria-label":s,children:l,className:c,...u}=n;return Dn("button",{type:"button",class:["wf-toggle",`wf-toggle--${o}`,`wf-toggle--${a}`,t?"wf-toggle--pressed":"",c].filter(Boolean).join(" "),"aria-pressed":t?"true":"false","aria-label":s||void 0,disabled:r||void 0,onClick:r?void 0:()=>e?.(!t),...u},l)},oa=async(i,n)=>async t=>{let{type:e="single",options:o=[],size:a="md",disabled:r,"aria-label":s,className:l}=t,c=n?.ui?.useControlled({value:t.value,onChange:t.onChange,name:"ToggleGroup"}),u=c?.value,d=m=>e==="multiple"?Array.isArray(u)&&u.includes(m):u===m,f=m=>{let h;if(e==="multiple"){let x=Array.isArray(u)?[...u]:[],y=x.indexOf(m);y>=0?x.splice(y,1):x.push(m),h=x}else h=m;let b=c?.controlled;c?.setValue(h),b||t.onChange?.(h)},p=m=>{if(r||e!=="single")return;let h=o.findIndex(y=>y.value===u);if(h<0)return;let b=h;if(m.key==="ArrowRight")m.preventDefault(),b=Math.min(h+1,o.length-1);else if(m.key==="ArrowLeft")m.preventDefault(),b=Math.max(h-1,0);else return;let x=o[b];x&&!x.disabled&&f(x.value)},g=o.map(m=>Dn($o,{key:m.value,pressed:d(m.value),size:a,disabled:r||m.disabled,"aria-label":m.value,onClick:r||m.disabled?void 0:()=>f(m.value)},m.label??m.value));return Dn("div",{class:["wf-toggle-group",`wf-toggle-group--${a}`,l].filter(Boolean).join(" "),role:e==="single"?"radiogroup":"group","aria-label":s||void 0,onKeyDown:p},g)};import{h as On}from"weifuwu/ui-dom";var ra=async(i,n)=>async t=>{let{options:e=[],columns:o,size:a="md",disabled:r,label:s,"aria-label":l,className:c}=t,u=n?.ui?.useControlled({value:t.value,onChange:t.onChange,name:"CheckboxGroup"}),d=u?.value??[],f=(h,b)=>{let x=b?[...new Set([...d,h])]:d.filter(w=>w!==h),y=u?.controlled;u?.setValue(x),y||t.onChange?.(x)},p=e.map(h=>On(ln,{key:h.value,label:h.desc?`${h.label}\uFF08${h.desc}\uFF09`:h.label,checked:d.includes(h.value),disabled:r||h.disabled,onChange:b=>f(h.value,b)})),g=[];s&&g.push(On("div",{class:"wf-checkbox-group-label"},s)),g.push(...p);let m=["wf-checkbox-group",`wf-checkbox-group--${a}`];return o&&m.push(`wf-checkbox-group--cols-${o}`),c&&m.push(c),On("div",{class:m.join(" "),role:"group","aria-label":l||s||void 0},g)};import{h as Eo}from"weifuwu/ui-dom";var sa=async(i,n)=>{let t=[],e=r=>{let s=t[r];s&&(s.focus(),s.select())},o=new Map,a=r=>{let s=o.get(r);return s||(s=l=>{l&&(t[r]=l)},o.set(r,s)),s};return async r=>{let{length:s=6,value:l="",onChange:c,type:u="number",size:d="md",disabled:f,"aria-label":p}=r,g=u==="number",m=(y,w)=>{if(f||!c)return;let v=w.slice(-1);if(g&&!/^\d$/.test(v))return;let k=l.split("");for(;k.length<s;)k.push("");k[y]=v,c(k.join("").slice(0,s)),y+1<s&&e(y+1)},h=(y,w)=>{if(f)return;let v=w.key;if(v==="Backspace")if(w.preventDefault(),l[y]){let k=l.split("");k[y]="",c?.(k.join(""))}else y>0&&e(y-1);else v==="ArrowLeft"?(w.preventDefault(),y>0&&e(y-1)):v==="ArrowRight"?(w.preventDefault(),y+1<s&&e(y+1)):v==="Home"?(w.preventDefault(),e(0)):v==="End"&&(w.preventDefault(),e(s-1))},b=y=>{if(f||!c)return;let w=y.clipboardData?.getData("text")??"";if(y.preventDefault(),!w)return;let v=w.slice(0,s);g&&(v=v.replace(/\D/g,"").slice(0,s)),v&&(c(v),e(Math.min(v.length,s-1)))},x=[];for(let y=0;y<s;y++)x.push(Eo("input",{key:y,type:"text",class:"wf-pin-input-cell",value:l[y]??"",maxLength:1,inputMode:g?"numeric":void 0,pattern:g?"[0-9]":void 0,"aria-label":`${p??"\u9A8C\u8BC1\u7801"}\u7B2C ${y+1} \u4F4D`,disabled:f||void 0,ref:a(y),onInput:w=>m(y,w.target.value),onKeyDown:w=>h(y,w),onPaste:b}));return Eo("div",{class:["wf-pin-input",`wf-pin-input--${d}`].join(" "),role:"group","aria-label":p},x)}};import{h as At}from"weifuwu/ui-dom";var aa=async(i,n)=>{let t=!1,e;return async o=>{let{value:a,label:r,size:s="md",variant:l="secondary",iconOnly:c,successText:u="\u5DF2\u590D\u5236",onCopied:d,className:f,...p}=o,g=async()=>{await n.browser?.copyText(a),t=!0,d?.(),n.ui.render(),clearTimeout(e),e=setTimeout(()=>{t=!1,n.ui.render()},2e3)},m=[];return t?(m.push(At(T,{name:"check",size:14})),c||m.push(At("span",{class:"wf-copy-btn-text"},u))):(m.push(At(T,{name:"copy",size:14})),!c&&r&&m.push(At("span",{class:"wf-copy-btn-text"},r))),At("button",{type:"button",class:["wf-copy-btn",`wf-copy-btn--${s}`,`wf-copy-btn--${l}`,t?"wf-copy-btn--copied":"",f].filter(Boolean).join(" "),"aria-label":r||"\u590D\u5236",onClick:g,...p},m)}};import{h as Ne}from"weifuwu/ui-dom";var ia=["#4f6ef7","#8b5cf6","#ec4899","#ef4444","#f59e0b","#22c55e","#14b8a6","#06b6d4","#64748b","#1e293b"],la=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,ca=async(i,n)=>async t=>{let{colors:e=ia,size:o="md",disabled:a,showInput:r,"aria-label":s}=t,l=n?.ui?.useControlled({value:t.value,onChange:t.onChange,name:"ColorPicker"}),c=m=>{let h=l?.controlled;l?.setValue(m),h||t.onChange?.(m)},u=l?.value??"",d=e.map(m=>{let h=m.toLowerCase()===u.toLowerCase();return Ne("button",{type:"button",class:`wf-color-picker-swatch${h?" wf-color-picker-swatch--sel":""}`,style:{background:m},"aria-label":m,"aria-pressed":h?"true":"false",onClick:()=>c(m)},h?Ne(T,{name:"check",size:14,className:"wf-color-picker-check"}):null)}),f=[Ne("div",{class:"wf-color-picker-grid"},d)];r&&f.push(Ne("input",{class:"wf-color-picker-input",type:"text",value:u,placeholder:"#4f6ef7",spellcheck:"false",onInput:m=>{let h=m.target.value.trim();la.test(h)&&c(h)}}));let p=Ne("div",{class:"wf-color-picker-panel"},f),g=Ne("button",{type:"button",class:`wf-color-picker-trigger wf-color-picker-trigger--${o}${a?" wf-color-picker-trigger--disabled":""}`,disabled:a,"aria-label":s??"\u9009\u62E9\u989C\u8272","aria-disabled":a?"true":void 0},[Ne("span",{class:"wf-color-picker-swatch",style:{background:u||"#fff"}}),Ne("span",{class:"wf-color-picker-value"},u||"\u989C\u8272")]);return Ne(Tt,{content:p,position:"bottom",disabled:a},g)};import{h as Xt}from"weifuwu/ui-dom";var pa=async(i,n)=>{let t=null,e={},o=n.ui.useInView({root:()=>e.target?e.target():null,rootMargin:()=>`${e.visibilityHeight??400}px 0px 0px 0px`}),a=r=>{r?(t=r,o.observe(r)):(t=null,o.disconnect())};return async r=>{Object.assign(e,r);let{visibilityHeight:s=400,smooth:l=!0,"aria-label":c,children:u,className:d}=r,f=o.ready&&!o.isIn;return Xt("div",{class:"wf-backtop-host"},[Xt("div",{class:"wf-backtop-sentinel",style:{position:"absolute",top:0,left:0,width:"1px",height:"1px",opacity:0,pointerEvents:"none"},ref:a}),Xt("button",{type:"button",class:["wf-backtop",f?"":"wf-backtop--hidden",d].filter(Boolean).join(" "),"aria-label":c??"\u56DE\u5230\u9876\u90E8",onClick:()=>{let p=e.target?e.target():window;l&&"scrollTo"in p?p.scrollTo({top:0,behavior:"smooth"}):"scrollTo"in p?p.scrollTo({top:0,behavior:"smooth"}):p.scrollTop=0}},u??Xt(T,{name:"arrow-up",size:16}))])}};import{h as Rn}from"weifuwu/ui-dom";var ua=async(i,n)=>{let t=null,e=0,o=1/0,a,r={...i},s=()=>r.target?r.target():window,l=n.ui.useScrollPosition({getScroller:s}),c=n.ui.usePopupPosition({el:()=>t,isOpen:()=>!0,compute:d=>{let f=s(),p=f instanceof Window?n.browser?.scrollTop()??0:f.scrollTop??0;return o=d.top+p-(r.offsetTop??0),e=d.width,{top:0,left:0}}}),u=d=>{d?(t=d,queueMicrotask(()=>{c.refresh(),l.refresh()})):t=null};return async d=>{Object.assign(r,d);let{offsetTop:f=0,children:p,className:g,...m}=d;f!==a&&(a=f,t&&c.refresh());let h=l.y>=o;return Rn("div",{class:["wf-affix",g].filter(Boolean).join(" "),...m},[Rn("div",{ref:u,class:["wf-affix-sentinel",h?"wf-affix-sentinel--active":""].join(" ")}),Rn("div",{class:["wf-affix-content",h?"wf-affix-content--fixed":""].filter(Boolean).join(" "),style:h?{position:"fixed",top:`${f}px`,width:`${e}px`}:void 0},p)])}};import{h as Lo}from"weifuwu/ui-dom";var da=async(i,n)=>{let t="top",e=!1,o={open:150,close:0},a=null,r=c=>{c&&(a=c)},s=null,l=n.ui.usePopup({trigger:"hover",placement:()=>t,gap:8,el:()=>a,isOpen:()=>s?.open??!1,setOpen:c=>s?.setOpen(c),disabled:()=>e,openDelay:()=>o.open,closeDelay:()=>o.close});return async c=>{let{content:u,position:d="top",children:f}=c;s=n.ui.useOpen({name:"HoverCard"}),t=d,e=!!c.disabled,o={open:c.openDelay??150,close:c.closeDelay??0};let p=Lo("div",{class:`wf-hover-card wf-hover-card--${d}`,role:"tooltip"},u);return Lo("div",{class:"wf-hover-card-wrap",ref:r,"aria-haspopup":"dialog","aria-expanded":String(!!s?.open),...l.wrapProps},[f,l.portal(p,"popover")].filter(Boolean))}};import{createClientBrowser as fa}from"weifuwu/ui-dom";import{h as ye}from"weifuwu/ui-dom";import{mountCommand as ma}from"weifuwu/ui-dom";var Io=fa();function ga(i){return{"top-right":"wf-notification--tr","top-left":"wf-notification--tl","bottom-right":"wf-notification--br","bottom-left":"wf-notification--bl"}[i]??"wf-notification--tr"}function ha(i){switch(i){case"success":return"check";case"error":return"close";case"warning":return"alert";case"info":return"info"}}var Ao=async(i,n)=>{let t=n.ui.usePopup?.({positioning:"none",closeOnOutside:!1,closeOnEscape:!1,isOpen:()=>!0,setOpen:()=>{}});return async e=>{let{items:o=[],onRemove:a,position:r="top-right",duration:s=4500,max:l=0}=e,c=l>0&&o.length>l?o.slice(-l):o;if(c.length===0)return null;let u=c.map(d=>ye("div",{class:`wf-notification wf-notification--${d.type}`,key:d.id,role:d.type==="error"?"alert":"status","aria-live":d.type==="error"?"assertive":"polite","data-id":d.id,"data-duration":(d.duration??s)||void 0},[ye("span",{class:"wf-notification-icon"},ye(T,{name:ha(d.type)})),ye("div",{class:"wf-notification-body"},[ye("div",{class:"wf-notification-title"},d.title),d.description?ye("div",{class:"wf-notification-desc"},d.description):null,d.action?ye("button",{class:"wf-notification-action",type:"button",onClick:f=>{f.stopPropagation(),d.action.onClick()}},d.action.label):null].filter(Boolean)),ye("button",{type:"button",class:"wf-notification-close","aria-label":"\u5173\u95ED\u901A\u77E5",onClick:()=>a?.(d.id)},ye(T,{name:"close",size:12}))].filter(Boolean)));return t.portal(ye("div",{class:`wf-notification-container ${ga(r)}`,"data-max":l||void 0},u),"notification")}};function ya(i){let n={position:i?.position??"top-right",duration:i?.duration??4500,max:i?.max??5},t=null,e=null,o=0,a=async(l,c)=>{let u=[],d=()=>c.ui.render();return t={add:f=>{u=[...u,f],d()},remove:f=>{u=u.filter(p=>p.id!==f),d()}},async()=>ye("div",{class:"wf-notification-host"},[ye(Ao,{items:u,position:n.position,duration:n.duration,max:n.max,onRemove:f=>t?.remove(f)})])},r=()=>{if(t||!e)return;let l=Io.createElement("div");l&&(Io.bodyAppend(l),ma(l,ye(a,{}),e))},s=l=>{r();let c=String(++o);t?.add({...l,id:c}),l.duration&&l.duration>0&&setTimeout(()=>t?.remove(c),l.duration)};return l=>{e=l;let c=Object.assign((u,d)=>s({type:d?.type??"info",title:u,description:d?.description,duration:d?.duration??n.duration,action:d?.action}),{open:u=>s({type:u.type??"info",title:u.title,description:u.description,duration:u.duration??n.duration,action:u.action}),success:u=>s({type:"success",title:u.title,description:u.description,duration:u.duration??n.duration}),error:u=>s({type:"error",title:u.title,description:u.description,duration:u.duration??n.duration}),info:u=>s({type:"info",title:u.title,description:u.description,duration:u.duration??n.duration}),warning:u=>s({type:"warning",title:u.title,description:u.description,duration:u.duration??n.duration})});return l.notification=c,l}}import{h as Zt}from"weifuwu/ui-dom";var ba=async(i,n)=>{let t=!1,e=0,o=null,a=[],r=0,s=0,l=n.ui.usePopup({trigger:"longpress",el:()=>o,isOpen:()=>t,setOpen:f=>{t=f,n.ui.render()},position:()=>({x:r,y:s}),closeOnOutside:!0,closeOnEscape:!0,onTrigger:f=>{r=f.clientX,s=f.clientY,e=a.findIndex(p=>!p.disabled)}}),c=()=>l.setOpen(!1),u=f=>{o=f},d=f=>{if(f.key==="ArrowDown"){f.preventDefault();for(let p=1;p<=a.length;p++){let g=(e+p)%a.length;if(!a[g].disabled){e=g,n.ui.render();break}}}else if(f.key==="ArrowUp"){f.preventDefault();for(let p=1;p<=a.length;p++){let g=(e-p+a.length)%a.length;if(!a[g].disabled){e=g,n.ui.render();break}}}else if(f.key==="Enter"){f.preventDefault();let p=a[e];p&&!p.disabled&&(p.onClick?.(),c())}else f.key==="Escape"&&c()};return async f=>{let{items:p=[],children:g,"aria-label":m,className:h}=f;a=p;let b=a.map((y,w)=>Zt("button",{type:"button",class:["wf-context-menu-item",y.variant==="danger"?"wf-context-menu-item--danger":"",y.disabled?"wf-context-menu-item--dis":"",e===w?"wf-context-menu-item--hl":""].filter(Boolean).join(" "),key:y.key,role:"menuitem",disabled:y.disabled||void 0,onClick:y.disabled?void 0:()=>{y.onClick?.(),c()},onMouseEnter:()=>{y.disabled||(e=w)}},y.icon?[y.icon,Zt("span",{},y.label)]:y.label)),x=Zt("div",{class:"wf-context-menu",role:"menu","aria-label":m,onKeyDown:d},b);return Zt("div",{class:["wf-context-menu-trigger",h].filter(Boolean).join(" "),ref:u,...l.wrapProps},[g,l.portal(x,"context-menu")].filter(Boolean))}};import{h as en}from"weifuwu/ui-dom";var wa=async(i,n)=>{let t=!1,e="",o=-1,a=0,r=!1,s=null,l=f=>{s=f},c=null,u=n.ui.usePopup({trigger:"click",placement:"bottom",center:!1,gap:4,el:()=>s,isOpen:()=>t,setOpen:f=>{f||d()}}),d=()=>{t&&(t=!1,n.ui.render())};return async f=>{let{options:p=[],prefix:g="@",placeholder:m,rows:h=3,disabled:b,size:x="md"}=f;c=n.ui.useControlledInput({value:f.value,onChange:f.onChange,name:"Mentions"});let y=c.value??"",w=(L,$)=>{if(r){d();return}let H=L.slice(0,$),R=H.lastIndexOf(g);if(R===-1){d();return}let N=H.slice(R+1);if(N.includes(" ")){d();return}if(N.length>0&&N.includes(`
|
|
8
|
+
`))})}return t}import{h as Ce}from"weifuwu/ui-dom";var Po=/\b(?:const|let|var|function|return|if|else|for|while|do|switch|case|break|continue|import|export|from|default|async|await|class|new|extends|implements|type|interface|public|private|protected|readonly|static|this|super|true|false|null|undefined|of|in|typeof|instanceof|void|throw|try|catch|finally|yield|as|satisfies)\b/,Ds=/\b(?:if|then|else|fi|for|do|done|while|case|esac|function|echo|cd|ls|mkdir|rm|cp|mv|export|source|sudo|npm|node|docker)\b/;var Lp=new RegExp(["(/\\*[\\s\\S]*?\\*/|//[^\\n]*|#[^\\n]*)","(\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'|`(?:[^`\\\\]|\\\\.)*`)","("+Po.source+")","(\\b\\d+(?:\\.\\d+)?(?:px|%|em|rem|vh|vw|fr|ms|s)?\\b)","([A-Za-z_$][\\w$]*(?=\\s*\\())","(<\\/?[A-Za-z][\\w.-]*)","(<=|>=|===|!==|==|!=|=>|\\+\\+|--|&&|\\|\\||\\?\\?|\\??\\.|[{}()\\[\\];,.:=+\\-*/<>!?&|^~%])"].join("|"),"g");function Os(i){return i==="bash"||i==="sh"||i==="shell"?Ds:Po}function To(i,n){let t=[],e=Os(n??""),o=n==="tsx"||n==="jsx"||n==="html"||!n,a=new RegExp(["(/\\*[\\s\\S]*?\\*/|//[^\\n]*|#[^\\n]*)","(\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'|`(?:[^`\\\\]|\\\\.)*`)","("+e.source+")","(\\b\\d+(?:\\.\\d+)?(?:px|%|em|rem|vh|vw|fr|ms|s)?\\b)","([A-Za-z_$][\\w$]*(?=\\s*\\())",o?"(<\\/?[A-Za-z][\\w.-]*)":"(?!x)x","(<=|>=|===|!==|==|!=|=>|\\+\\+|--|&&|\\|\\||\\?\\?|\\??\\.|[{}()\\[\\];,.:=+\\-*/<>!?&|^~%])"].join("|"),"g"),r=0,s;for(;(s=a.exec(i))!==null;){s.index>r&&t.push({type:"text",text:i.slice(r,s.index)});let l="operator";for(let c=1;c<=7;c++)if(s[c]!==void 0){l=["comment","string","keyword","number","function","jsx-tag","operator"][c-1];break}t.push({type:l,text:s[0]}),r=s.index+s[0].length,s[0].length===0&&(r++,a.lastIndex=r)}return r<i.length&&t.push({type:"text",text:i.slice(r)}),t}var Ln=async(i,n)=>{let t=!1,e,o="",a=async()=>{await n.browser?.copyText(o),t=!0,n.ui.render(),clearTimeout(e),e=setTimeout(()=>{t=!1,n.ui.render()},1600)};return async r=>{let{code:s,lang:l,title:c}=r;o=s;let u=l?Ce("span",{class:"wf-codeblock-lang"},[Ce("span",{class:"wf-codeblock-dot"}),l]):null,d=Ce("button",{class:"wf-codeblock-copy",type:"button","aria-label":"\u590D\u5236",title:"\u590D\u5236\u4EE3\u7801",onClick:a},t?Ce(T,{name:"check",size:14}):Ce(T,{name:"copy",size:14})),f=Ce("div",{class:"wf-codeblock-header"},[Ce("span",{class:"wf-codeblock-title"},c??u??"\u4EE3\u7801"),d].filter(Boolean)),p=s&&To(s,l).map((m,h)=>m.type==="text"?m.text:Ce("span",{class:`wf-hl-${m.type}`},m.text)),g=Ce("pre",{class:"wf-codeblock-pre"},Ce("code",{class:"wf-codeblock-code"},p));return Ce("div",{class:"wf-codeblock"},[f,g])}};var Bs=async(i,n)=>async t=>{let{content:e="",className:o}=t,a=En(e);return a.length===0?null:ee("div",{class:`wf-md${o?` ${o}`:""}`},a.map((r,s)=>Hs(r,s)))};function Hs(i,n){switch(i.type){case"heading":return ee(`h${i.level}`,{class:`wf-md-h wf-md-h${i.level}`,key:n},ke(i.inline));case"paragraph":return ee("p",{class:"wf-md-p",key:n},ke(i.inline));case"list":{let t=i.checks?.some(o=>o!==null),e=i.ordered?"ol":"ul";return ee(e,{class:`wf-md-${i.ordered?"ol":"ul"}${t?" wf-md-task-list":""}`,key:n},i.items.map((o,a)=>{let r=i.checks?.[a];return ee("li",{class:`wf-md-li${r!=null?" wf-md-task":""}`,key:a},r!=null?[ee("input",{type:"checkbox",class:"wf-md-task-check",checked:!!r,disabled:!0,key:"c"}),...ke(o)]:ke(o))}))}case"code":return ee(Ln,{key:n,code:i.code??"",lang:i.lang});case"quote":return ee("blockquote",{class:"wf-md-quote",key:n},ke(i.inline));case"hr":return ee("hr",{class:"wf-md-hr",key:n});case"table":{let t=e=>i.aligns?.[e]?{textAlign:i.aligns[e]}:void 0;return ee("div",{class:"wf-md-table-wrap",key:n},ee("table",{class:"wf-md-table"},[ee("thead",{key:"h"},ee("tr",{key:"r"},i.headers.map((e,o)=>ee("th",{class:"wf-md-th",style:t(o),key:o},ke(ge(e)))))),ee("tbody",{key:"b"},i.rows.map((e,o)=>ee("tr",{class:"wf-md-tr",key:o},e.map((a,r)=>ee("td",{class:"wf-md-td",style:t(r),key:r},ke(ge(a)))))))]))}default:return null}}function ke(i){return i.map((n,t)=>{switch(n.type){case"code":return ee("code",{class:"wf-md-code",key:t},n.text??"");case"bold":return ee("strong",{class:"wf-md-strong",key:t},ke(n.children??[]));case"italic":return ee("em",{class:"wf-md-em",key:t},ke(n.children??[]));case"del":return ee("del",{class:"wf-md-del",key:t},ke(n.children??[]));case"link":return ee("a",{class:"wf-md-link",key:t,href:n.href,target:"_blank",rel:"noopener noreferrer"},ke(n.children??[]));default:return ee(Rs,{key:t},n.text??"")}})}import{h as Be}from"weifuwu/ui-dom";var Ns=async(i,n)=>async t=>{let{items:e,mode:o="left",reverse:a}=t,s=(a?[...e].reverse():e).map((l,c)=>{let{key:u,title:d,time:f,content:p,status:g="default",dot:m,onClick:h}=l,b=Be("div",{class:`wf-timeline-node wf-timeline-node--${g}`},m??null),x=Be("div",{class:"wf-timeline-head"},[Be("span",{class:"wf-timeline-title"},d),f?Be("span",{class:"wf-timeline-time"},f):null].filter(Boolean)),y=p!=null?Be("div",{class:"wf-timeline-content"},p):null,w=Be("div",{class:"wf-timeline-col"},[x,y].filter(Boolean));if(o==="horizontal")return Be("li",{key:u,class:`wf-timeline-item wf-timeline-item--h${h?" wf-timeline-item--clickable":""}`,role:h?"button":void 0,tabIndex:h?0:void 0,onClick:h,onKeyDown:h?k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),h())}:void 0},[b,w]);let v=o==="alternate"?c%2===0?" wf-timeline-item--alt-left":" wf-timeline-item--alt-right":"";return Be("li",{key:u,class:`wf-timeline-item${h?" wf-timeline-item--clickable":""}${v}`,role:h?"button":void 0,tabIndex:h?0:void 0,onClick:h,onKeyDown:h?k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),h())}:void 0},[b,w])});return Be("ul",{class:`wf-timeline${o==="horizontal"?" wf-timeline--h":""}`},s)};import{h as Jt}from"weifuwu/ui-dom";var zs=async(i,n)=>async t=>{let{items:e,column:o=1,bordered:a,size:r="md",className:s}=t,l=e.map((c,u)=>Jt("div",{key:u,class:"wf-descriptions-item",style:c.span&&c.span>1?{gridColumn:`span ${c.span}`}:void 0},[Jt("dt",{class:"wf-descriptions-label"},c.label),Jt("dd",{class:"wf-descriptions-value"},c.value)]));return Jt("dl",{class:`wf-descriptions wf-descriptions--${o} wf-descriptions--${r}${a?" wf-descriptions--bordered":""}${s?` ${s}`:""}`},l)};import{h as Yt}from"weifuwu/ui-dom";var _s=async(i,n)=>async t=>{let{items:e,max:o,size:a,className:r}=t;if(!e||e.length===0)return null;let s=o&&e.length>o?e.slice(0,o):e,l=o?Math.max(0,e.length-o):0,c=s.map((d,f)=>Yt("span",{key:f,class:"wf-avatar-group-item"},Yt(fn,{name:d.name,src:d.src,color:d.color,size:a}))),u=l>0?Yt("span",{class:"wf-avatar-group-more",role:"img","aria-label":`\u8FD8\u6709 ${l} \u4EBA`},`+${l}`):null;return Yt("div",{class:`wf-avatar-group${r?` ${r}`:""}`},[...c,u].filter(Boolean))};import{h as Qt}from"weifuwu/ui-dom";var js=async(i,n)=>async t=>{let{content:e,role:o,status:a="complete",actions:r,className:s}=t,l=o==="user"?"wf-bubble--own":"wf-bubble--ai",c=a==="error"?" wf-bubble--error":a==="streaming"?" wf-bubble--streaming":"",u=r?Qt("div",{class:"wf-bubble-body"},[Qt("div",{class:"wf-bubble-text"},e),Qt("div",{class:"wf-bubble-actions"},r)]):e;return Qt("div",{class:`wf-bubble ${l}${c}${s?` ${s}`:""}`,role:a==="error"?"alert":void 0},u)};import{createClientBrowser as Ks}from"weifuwu/ui-dom";import{h as ae}from"weifuwu/ui-dom";var Ws=async(i,n)=>{let t=n.browser??Ks(),e=null,o=[],a=!1,r=null,s=null,l=n.ui.usePopup({trigger:"click",placement:"right",gap:6,el:()=>s,isOpen:()=>r!==null,setOpen:d=>{d||(r=null),n.ui.render()}}),c=d=>{d&&(e=d)},u=d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;let f=e?Array.from(e.querySelectorAll(".wf-menu-item, .wf-menu-submenu-title")):[],p=f.indexOf(t?.activeElement()??null);if(p<0)return;d.preventDefault();let g=p;d.key==="ArrowDown"?g=(p+1)%f.length:d.key==="ArrowUp"?g=(p-1+f.length)%f.length:d.key==="Home"?g=0:d.key==="End"&&(g=f.length-1),f[g].focus()};return async d=>{let{items:f,onSelect:p,activeKey:g,className:m,openKeys:h,onOpenChange:b,collapsible:x,collapsed:y,onCollapseChange:w}=d,v=h!==void 0,k=y!==void 0,S=new Set(v?h:o),P=k?!!y:a,E=C=>{v?b?.(C):(o=C,n.ui.render())},A=(C,I)=>{let B=I!=null?I?[...S,C]:[...S].filter(_=>_!==C):S.has(C)?[...S].filter(_=>_!==C):[...S,C];E([...new Set(B)])},L=()=>{let C=!P;k?w?.(C):(a=C,n.ui.render())},$=C=>{let I=S.has(C.key)&&!P,B=C.active??(g!=null&&C.key===g);if(P){let J=r===C.key,ve=ae("div",{"data-key":C.key,class:`wf-menu-submenu-title wf-menu-submenu-title--collapsed${B?" wf-menu-submenu-title--active":""}`,role:"menuitem",tabIndex:B?0:-1,"aria-haspopup":"menu","aria-expanded":J?"true":"false",onClick:F=>{J?(r=null,n.ui.render()):(s=F.currentTarget,r=C.key,n.ui.render())},onKeyDown:F=>{F.key==="Enter"||F.key===" "||F.key==="ArrowRight"?(F.preventDefault(),J||(s=F.currentTarget,r=C.key,n.ui.render())):F.key==="Escape"&&(F.preventDefault(),r=null,n.ui.render())}},[C.icon?ae("span",{class:"wf-menu-icon"},C.icon):null].filter(Boolean)),ue=l.portal(ae("div",{class:"wf-menu-popup"},(C.children??[]).map(F=>H(F,!0,!0))),"menu-popup");return ae("div",{key:C.key,"data-key":C.key,class:"wf-menu-submenu wf-menu-submenu--collapsed"},[ve,J?ue:null])}let _=[C.icon?ae("span",{class:"wf-menu-icon"},C.icon):null,P?null:ae("span",{class:"wf-menu-label"},C.label),P?null:ae("span",{class:"wf-menu-arrow"},ae(T,{name:"chevron-right",size:12}))].filter(Boolean),G=ae("div",{"data-key":C.key,class:`wf-menu-submenu-title${B?" wf-menu-submenu-title--active":""}`,role:"menuitem",tabIndex:B?0:-1,"aria-expanded":I?"true":"false",onClick:()=>A(C.key),onKeyDown:J=>{J.key==="Enter"||J.key===" "||J.key==="ArrowRight"?(J.preventDefault(),I||A(C.key,!0)):(J.key==="ArrowLeft"||J.key==="Escape")&&I&&(J.preventDefault(),A(C.key,!1))}},_),Q=ae("div",{class:"wf-menu-submenu-content",role:"group"},(C.children??[]).map(J=>H(J,!0)));return ae("div",{key:C.key,"data-key":C.key,class:`wf-menu-submenu${I?" wf-menu-submenu--open":""}`},[G,Q])},H=(C,I=!1,B=!1)=>{if(C.children&&C.children.length>0&&!P)return $(C);let _=C.active??(g!=null&&C.key===g);return ae("div",{key:C.key,"data-key":C.key,class:`wf-menu-item${_?" wf-menu-item--active":""}${C.danger?" wf-menu-item--danger":""}${I?" wf-menu-item--child":""}`,role:"menuitem",tabIndex:_?0:-1,"aria-current":_?"page":void 0,onClick:()=>{C.onClick?C.onClick():p?.(C.key)},onKeyDown:G=>{if(G.key==="Enter"||G.key===" ")G.preventDefault(),C.onClick?C.onClick():p?.(C.key);else if((G.key==="ArrowLeft"||G.key==="Escape")&&I){G.preventDefault();let Q=C._parentKey;Q&&S.has(Q)&&A(Q,!1)}}},[C.icon?ae("span",{class:"wf-menu-icon"},C.icon):null,P&&!B?null:ae("span",{class:"wf-menu-label"},C.label)].filter(Boolean))},R=[],N;for(let C of f)if(C.group!==N&&(R.push(ae("div",{class:"wf-menu-group",key:`g-${C.group}`},C.group)),N=C.group),C.children&&C.children.length>0){let I=$(C);!P&&I.props.children[1]&&(I.props.children[1].props.children=I.props.children[1].props.children.map(B=>B?.props?{...B,props:{...B.props,_parentKey:C.key}}:B)),R.push(I)}else R.push(H(C));let D=["wf-menu",P?"wf-menu--collapsed":"",m??""].filter(Boolean).join(" "),M=[...R,x?ae("div",{class:"wf-menu-collapse-btn",role:"button",tabIndex:0,"aria-label":P?"\u5C55\u5F00\u83DC\u5355":"\u6298\u53E0\u83DC\u5355",onClick:L,onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),L())}},P?ae(T,{name:"chevron-right",size:14}):ae(T,{name:"chevron-left",size:14})):null].filter(Boolean);return ae("nav",{class:D,role:"menu",ref:c,onKeyDown:u},M)}};import{h as He}from"weifuwu/ui-dom";var Vs=async(i,n)=>{let t=!1;return async e=>{let{value:o,onInput:a,onChange:r,label:s,name:l,placeholder:c,disabled:u,error:d,hint:f,required:p,autoComplete:g,className:m}=e,h=()=>{u||(t=!t,n.ui.render())},b=s?He("label",{class:"wf-input-label"},[s,p?He("span",{class:"wf-input-req"},"*"):null].filter(Boolean)):null,x=He("input",{class:"wf-input",type:t?"text":"password",value:o,name:l,placeholder:c,disabled:u,autoComplete:g,onInput:a,onChange:r}),y=He("button",{class:"wf-password-eye",type:"button","aria-label":t?"\u9690\u85CF\u5BC6\u7801":"\u663E\u793A\u5BC6\u7801",tabIndex:-1,onClick:h},He(T,{name:t?"eye-off":"eye",size:16})),w=He("div",{class:"wf-input-wrap wf-password"},[x,y]),v=[];return b&&v.push(b),v.push(w),d&&v.push(He("div",{class:"wf-input-err"},d)),f&&!d&&v.push(He("div",{class:"wf-input-hint"},f)),He("div",{class:`wf-field${m?` ${m}`:""}`},v)}};import{h as Ee}from"weifuwu/ui-dom";var Fs=async(i,n)=>{let t=!1;return async e=>{let{placeholder:o,maxTags:a,allowDuplicates:r,disabled:s,label:l,error:c,hint:u,className:d}=e,f=n?.ui?.useControlled({value:e.value,onChange:e.onChange,name:"TagsInput"}),p=f?.value??[],g=S=>{let P=f?.controlled;f?.setValue(S),P||e.onChange?.(S)},m=S=>{if(s)return;let P=S.trim().replace(/,$/,"");P&&(a!=null&&p.length>=a||!r&&p.includes(P)||g([...p,P]))},h=S=>{s||g(p.filter(P=>P!==S))},b=S=>{let P=S.target;if(S.key==="Enter"||S.key===","){if(S.preventDefault(),t)return;m(P.value),P.value=""}else S.key==="Backspace"&&!P.value&&p.length>0&&h(p[p.length-1])},x=l?Ee("label",{class:"wf-input-label"},l):null,y=p.map(S=>Ee("span",{key:S,class:"wf-tags-tag"},[Ee("span",{class:"wf-tags-text"},S),Ee("button",{class:"wf-tags-remove",type:"button","aria-label":`\u79FB\u9664 ${S}`,onClick:()=>h(S)},Ee(T,{name:"close",size:12}))])),w=Ee("input",{class:"wf-tags-input",type:"text",placeholder:p.length===0?o:void 0,disabled:s,onKeyDown:b,onCompositionStart:()=>{t=!0},onCompositionEnd:()=>{t=!1}}),v=Ee("div",{class:`wf-tags${s?" wf-tags--disabled":""}${c?" wf-tags--err":""}${d?` ${d}`:""}`},[...y,w]),k=[];return x&&k.push(x),k.push(v),c&&k.push(Ee("div",{class:"wf-input-err"},c)),u&&!c&&k.push(Ee("div",{class:"wf-input-hint"},u)),Ee("div",{class:"wf-field"},k)}};import{h as In}from"weifuwu/ui-dom";var Gs=async(i,n)=>async t=>{let{text:e,query:o,className:a}=t,r=(Array.isArray(o)?o:o?[o]:[]).filter(Boolean).map(u=>u.toLowerCase());if(r.length===0)return In("span",{class:`wf-highlight${a?` ${a}`:""}`},e);let s=[],l=0,c=e.toLowerCase();for(;l<e.length;){let u=null;for(let d of r){let f=c.indexOf(d,l);f>=0&&(!u||f<u.start)&&(u={start:f,end:f+d.length})}if(!u){s.push(e.slice(l));break}u.start>l&&s.push(e.slice(l,u.start)),s.push(In("mark",{class:"wf-highlight-mark"},e.slice(u.start,u.end))),l=u.end}return In("span",{class:`wf-highlight${a?` ${a}`:""}`},s)};import{h as Ze}from"weifuwu/ui-dom";var qs=async(i,n)=>async t=>{let{items:e,renderItem:o,divided:a,header:r,footer:s,emptyText:l="\u6682\u65E0\u6570\u636E",emptyIcon:c,className:u,keyBy:d}=t,f=e.length===0?Ze("div",{class:"wf-list-empty"},[c??null,Ze("span",{},l)].filter(Boolean)):e.map((p,g)=>Ze("li",{key:d?d(p,g):g,class:"wf-list-item"},o(p,g)));return Ze("div",{class:`wf-list${a?" wf-list--divided":""}${u?` ${u}`:""}`},[r?Ze("div",{class:"wf-list-header"},r):null,Ze("ul",{class:"wf-list-body"},f),s?Ze("div",{class:"wf-list-footer"},s):null].filter(Boolean))};import{h as ft}from"weifuwu/ui-dom";var Us={success:"check",error:"close",warning:"alert",info:"info"},Js=async(i,n)=>async t=>{let{status:e="info",title:o,desc:a,extra:r,className:s}=t;return ft("div",{class:`wf-result wf-result--${e}${s?` ${s}`:""}`},[ft("div",{class:"wf-result-icon","aria-hidden":"true"},ft(T,{name:Us[e],size:40})),ft("div",{class:"wf-result-title"},o),a?ft("div",{class:"wf-result-desc"},a):null,r?ft("div",{class:"wf-result-extra"},r):null].filter(Boolean))};import{h as et}from"weifuwu/ui-dom";var Ys=async(i,n)=>{let t=-1,e=o=>{t!==o&&(t=o,n.ui.render())};return async o=>{let{count:a=5,size:r="md",readOnly:s,disabled:l,allowClear:c,allowHalf:u,"aria-label":d}=o,f=s||l,p=n?.ui?.useControlled({value:o.value,onChange:o.onChange,name:f?void 0:"Rate"}),g=p?.value??0,m=v=>{let k=p?.controlled;p?.setValue(v),k||o.onChange?.(v)},h=!s&&!l,b=t>=0?t+1:g,x=u?.5:1,y=v=>{if(!h)return;let k=v.key;k==="ArrowRight"?(v.preventDefault(),m(Math.min(g+x,a))):k==="ArrowLeft"?(v.preventDefault(),m(Math.max(g-x,0))):k==="Home"?(v.preventDefault(),m(x)):k==="End"&&(v.preventDefault(),m(a))},w=[];for(let v=0;v<a;v++){let k=v<Math.floor(b),S=u&&v===Math.floor(b)&&b%1>=.5,E={class:`wf-rate-star${k?" wf-rate-star--on":""}${S?" wf-rate-star--half":""}`,"aria-label":`${v+1} \u661F`,key:v};h&&(E.type="button",E.onClick=$=>{if(u){let R=$.currentTarget.getBoundingClientRect(),N=$.clientX-R.left<R.width/2;m(N?v+.5:v+1)}else c&&g===v+1?m(0):m(v+1)},E.onMouseEnter=u?$=>{let R=$.currentTarget.getBoundingClientRect();e($.clientX-R.left<R.width/2?v+.5-1:v)}:()=>e(v),E.onMouseMove=u?$=>{let R=$.currentTarget.getBoundingClientRect();e($.clientX-R.left<R.width/2?v+.5-1:v)}:void 0,E.onMouseLeave=()=>e(-1),E.onFocus=()=>e(v),E.onBlur=()=>e(-1));let A=et(T,{name:"star",className:"wf-rate-star-icon"}),L=S?et("span",{class:"wf-rate-star-half"},[et("span",{class:"wf-rate-star-half-bg"},A),et("span",{class:"wf-rate-star-half-fg"},et(T,{name:"star",className:"wf-rate-star-icon"}))]):A;w.push(et(h?"button":"span",E,L))}return et("div",{class:`wf-rate wf-rate--${r}${l?" wf-rate--disabled":""}`,role:h?"radiogroup":void 0,"aria-label":d??"\u8BC4\u5206",onKeyDown:h?y:void 0},w)}};import{h as An}from"weifuwu/ui-dom";var Qs=async i=>async n=>{let{level:t=1,children:e,className:o,style:a,...r}=n;return An(`h${t}`,{class:["wf-title",`wf-title--${t}`,o].filter(Boolean).join(" "),style:a,...r},e)},Xs=async i=>async n=>{let{type:t,strong:e,underline:o,strikethrough:a,mark:r,code:s,size:l,children:c,className:u,...d}=n,f=["wf-text"];return t&&f.push(`wf-text--${t}`),e&&f.push("wf-text--strong"),o&&f.push("wf-text--underline"),a&&f.push("wf-text--strike"),r&&f.push("wf-text--mark"),s&&f.push("wf-text--code"),l&&l!=="md"&&f.push(`wf-text--${l}`),u&&f.push(u),An("span",{class:f.join(" "),...d},c)},Zs=async i=>async n=>{let{type:t,ellipsis:e,children:o,className:a,...r}=n,s=["wf-paragraph"];return t&&s.push(`wf-text--${t}`),e&&s.push("wf-paragraph--ellipsis"),a&&s.push(a),An("p",{class:s.join(" "),...r},o)};import{h as So}from"weifuwu/ui-dom";var ea=async i=>async n=>{let{htmlFor:t,required:e,children:o,className:a,...r}=n,s=e?[o,So("span",{class:"wf-label-req"},"*")]:o;return So("label",{class:["wf-label",a].filter(Boolean).join(" "),htmlFor:t||void 0,...r},s)};import{h as ta}from"weifuwu/ui-dom";var na=async i=>async n=>{let{ratio:t,children:e,className:o,...a}=n;return ta("div",{class:["wf-aspect-ratio",o].filter(Boolean).join(" "),style:{"--wf-aspect-ratio":t===void 0?"16 / 9":String(t)},...a},e)};import{h as Dn}from"weifuwu/ui-dom";var $o=async i=>async n=>{let{pressed:t,onPressedChange:e,variant:o="default",size:a="md",disabled:r,"aria-label":s,children:l,className:c,...u}=n;return Dn("button",{type:"button",class:["wf-toggle",`wf-toggle--${o}`,`wf-toggle--${a}`,t?"wf-toggle--pressed":"",c].filter(Boolean).join(" "),"aria-pressed":t?"true":"false","aria-label":s||void 0,disabled:r||void 0,onClick:r?void 0:()=>e?.(!t),...u},l)},oa=async(i,n)=>async t=>{let{type:e="single",options:o=[],size:a="md",disabled:r,"aria-label":s,className:l}=t,c=n?.ui?.useControlled({value:t.value,onChange:t.onChange,name:"ToggleGroup"}),u=c?.value,d=m=>e==="multiple"?Array.isArray(u)&&u.includes(m):u===m,f=m=>{let h;if(e==="multiple"){let x=Array.isArray(u)?[...u]:[],y=x.indexOf(m);y>=0?x.splice(y,1):x.push(m),h=x}else h=m;let b=c?.controlled;c?.setValue(h),b||t.onChange?.(h)},p=m=>{if(r||e!=="single")return;let h=o.findIndex(y=>y.value===u);if(h<0)return;let b=h;if(m.key==="ArrowRight")m.preventDefault(),b=Math.min(h+1,o.length-1);else if(m.key==="ArrowLeft")m.preventDefault(),b=Math.max(h-1,0);else return;let x=o[b];x&&!x.disabled&&f(x.value)},g=o.map(m=>Dn($o,{key:m.value,pressed:d(m.value),size:a,disabled:r||m.disabled,"aria-label":m.value,onClick:r||m.disabled?void 0:()=>f(m.value)},m.label??m.value));return Dn("div",{class:["wf-toggle-group",`wf-toggle-group--${a}`,l].filter(Boolean).join(" "),role:e==="single"?"radiogroup":"group","aria-label":s||void 0,onKeyDown:p},g)};import{h as On}from"weifuwu/ui-dom";var ra=async(i,n)=>async t=>{let{options:e=[],columns:o,size:a="md",disabled:r,label:s,"aria-label":l,className:c}=t,u=n?.ui?.useControlled({value:t.value,onChange:t.onChange,name:"CheckboxGroup"}),d=u?.value??[],f=(h,b)=>{let x=b?[...new Set([...d,h])]:d.filter(w=>w!==h),y=u?.controlled;u?.setValue(x),y||t.onChange?.(x)},p=e.map(h=>On(ln,{key:h.value,label:h.desc?`${h.label}\uFF08${h.desc}\uFF09`:h.label,checked:d.includes(h.value),disabled:r||h.disabled,onChange:b=>f(h.value,b)})),g=[];s&&g.push(On("div",{class:"wf-checkbox-group-label"},s)),g.push(...p);let m=["wf-checkbox-group",`wf-checkbox-group--${a}`];return o&&m.push(`wf-checkbox-group--cols-${o}`),c&&m.push(c),On("div",{class:m.join(" "),role:"group","aria-label":l||s||void 0},g)};import{h as Eo}from"weifuwu/ui-dom";var sa=async(i,n)=>{let t=[],e=r=>{let s=t[r];s&&(s.focus(),s.select())},o=new Map,a=r=>{let s=o.get(r);return s||(s=l=>{l&&(t[r]=l)},o.set(r,s)),s};return async r=>{let{length:s=6,value:l="",onChange:c,type:u="number",size:d="md",disabled:f,"aria-label":p}=r,g=u==="number",m=(y,w)=>{if(f||!c)return;let v=w.slice(-1);if(g&&!/^\d$/.test(v))return;let k=l.split("");for(;k.length<s;)k.push("");k[y]=v,c(k.join("").slice(0,s)),y+1<s&&e(y+1)},h=(y,w)=>{if(f)return;let v=w.key;if(v==="Backspace")if(w.preventDefault(),l[y]){let k=l.split("");k[y]="",c?.(k.join(""))}else y>0&&e(y-1);else v==="ArrowLeft"?(w.preventDefault(),y>0&&e(y-1)):v==="ArrowRight"?(w.preventDefault(),y+1<s&&e(y+1)):v==="Home"?(w.preventDefault(),e(0)):v==="End"&&(w.preventDefault(),e(s-1))},b=y=>{if(f||!c)return;let w=y.clipboardData?.getData("text")??"";if(y.preventDefault(),!w)return;let v=w.slice(0,s);g&&(v=v.replace(/\D/g,"").slice(0,s)),v&&(c(v),e(Math.min(v.length,s-1)))},x=[];for(let y=0;y<s;y++)x.push(Eo("input",{key:y,type:"text",class:"wf-pin-input-cell",value:l[y]??"",maxLength:1,inputMode:g?"numeric":void 0,pattern:g?"[0-9]":void 0,"aria-label":`${p??"\u9A8C\u8BC1\u7801"}\u7B2C ${y+1} \u4F4D`,disabled:f||void 0,ref:a(y),onInput:w=>m(y,w.target.value),onKeyDown:w=>h(y,w),onPaste:b}));return Eo("div",{class:["wf-pin-input",`wf-pin-input--${d}`].join(" "),role:"group","aria-label":p},x)}};import{h as At}from"weifuwu/ui-dom";var aa=async(i,n)=>{let t=!1,e;return async o=>{let{value:a,label:r,size:s="md",variant:l="secondary",iconOnly:c,successText:u="\u5DF2\u590D\u5236",onCopied:d,className:f,...p}=o,g=async()=>{await n.browser?.copyText(a),t=!0,d?.(),n.ui.render(),clearTimeout(e),e=setTimeout(()=>{t=!1,n.ui.render()},2e3)},m=[];return t?(m.push(At(T,{name:"check",size:14})),c||m.push(At("span",{class:"wf-copy-btn-text"},u))):(m.push(At(T,{name:"copy",size:14})),!c&&r&&m.push(At("span",{class:"wf-copy-btn-text"},r))),At("button",{type:"button",class:["wf-copy-btn",`wf-copy-btn--${s}`,`wf-copy-btn--${l}`,t?"wf-copy-btn--copied":"",f].filter(Boolean).join(" "),"aria-label":r||"\u590D\u5236",onClick:g,...p},m)}};import{h as Ne}from"weifuwu/ui-dom";var ia=["#4f6ef7","#8b5cf6","#ec4899","#ef4444","#f59e0b","#22c55e","#14b8a6","#06b6d4","#64748b","#1e293b"],la=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,ca=async(i,n)=>async t=>{let{colors:e=ia,size:o="md",disabled:a,showInput:r,"aria-label":s}=t,l=n?.ui?.useControlled({value:t.value,onChange:t.onChange,name:"ColorPicker"}),c=m=>{let h=l?.controlled;l?.setValue(m),h||t.onChange?.(m)},u=l?.value??"",d=e.map(m=>{let h=m.toLowerCase()===u.toLowerCase();return Ne("button",{type:"button",class:`wf-color-picker-swatch${h?" wf-color-picker-swatch--sel":""}`,style:{background:m},"aria-label":m,"aria-pressed":h?"true":"false",onClick:()=>c(m)},h?Ne(T,{name:"check",size:14,className:"wf-color-picker-check"}):null)}),f=[Ne("div",{class:"wf-color-picker-grid"},d)];r&&f.push(Ne("input",{class:"wf-color-picker-input",type:"text",value:u,placeholder:"#4f6ef7",spellcheck:"false",onInput:m=>{let h=m.target.value.trim();la.test(h)&&c(h)}}));let p=Ne("div",{class:"wf-color-picker-panel"},f),g=Ne("button",{type:"button",class:`wf-color-picker-trigger wf-color-picker-trigger--${o}${a?" wf-color-picker-trigger--disabled":""}`,disabled:a,"aria-label":s??"\u9009\u62E9\u989C\u8272","aria-disabled":a?"true":void 0},[Ne("span",{class:"wf-color-picker-swatch",style:{background:u||"#fff"}}),Ne("span",{class:"wf-color-picker-value"},u||"\u989C\u8272")]);return Ne(Tt,{content:p,position:"bottom",disabled:a},g)};import{h as Xt}from"weifuwu/ui-dom";var pa=async(i,n)=>{let t=null,e={},o=n.ui.useInView({root:()=>e.target?e.target():null,rootMargin:()=>`${e.visibilityHeight??400}px 0px 0px 0px`}),a=r=>{r?(t=r,o.observe(r)):(t=null,o.disconnect())};return async r=>{Object.assign(e,r);let{visibilityHeight:s=400,smooth:l=!0,"aria-label":c,children:u,className:d}=r,f=o.ready&&!o.isIn;return Xt("div",{class:"wf-backtop-host"},[Xt("div",{class:"wf-backtop-sentinel",style:{position:"absolute",top:0,left:0,width:"1px",height:"1px",opacity:0,pointerEvents:"none"},ref:a}),Xt("button",{type:"button",class:["wf-backtop",f?"":"wf-backtop--hidden",d].filter(Boolean).join(" "),"aria-label":c??"\u56DE\u5230\u9876\u90E8",onClick:()=>{let p=e.target?e.target():window;l&&"scrollTo"in p?p.scrollTo({top:0,behavior:"smooth"}):"scrollTo"in p?p.scrollTo({top:0,behavior:"smooth"}):p.scrollTop=0}},u??Xt(T,{name:"arrow-up",size:16}))])}};import{h as Rn}from"weifuwu/ui-dom";var ua=async(i,n)=>{let t=null,e=0,o=1/0,a,r={...i},s=()=>r.target?r.target():window,l=n.ui.useScrollPosition({getScroller:s}),c=n.ui.usePopupPosition({el:()=>t,isOpen:()=>!0,compute:d=>{let f=s(),p=f instanceof Window?n.browser?.scrollTop()??0:f.scrollTop??0;return o=d.top+p-(r.offsetTop??0),e=d.width,{top:0,left:0}}}),u=d=>{d?(t=d,queueMicrotask(()=>{c.refresh(),l.refresh()})):t=null};return async d=>{Object.assign(r,d);let{offsetTop:f=0,children:p,className:g,...m}=d;f!==a&&(a=f,t&&c.refresh());let h=l.y>=o;return Rn("div",{class:["wf-affix",g].filter(Boolean).join(" "),...m},[Rn("div",{ref:u,class:["wf-affix-sentinel",h?"wf-affix-sentinel--active":""].join(" ")}),Rn("div",{class:["wf-affix-content",h?"wf-affix-content--fixed":""].filter(Boolean).join(" "),style:h?{position:"fixed",top:`${f}px`,width:`${e}px`}:void 0},p)])}};import{h as Lo}from"weifuwu/ui-dom";var da=async(i,n)=>{let t="top",e=!1,o={open:150,close:0},a=null,r=c=>{c&&(a=c)},s=null,l=n.ui.usePopup({trigger:"hover",placement:()=>t,gap:8,el:()=>a,isOpen:()=>s?.open??!1,setOpen:c=>s?.setOpen(c),disabled:()=>e,openDelay:()=>o.open,closeDelay:()=>o.close});return async c=>{let{content:u,position:d="top",children:f}=c;s=n.ui.useOpen({name:"HoverCard"}),t=d,e=!!c.disabled,o={open:c.openDelay??150,close:c.closeDelay??0};let p=Lo("div",{class:`wf-hover-card wf-hover-card--${d}`,role:"tooltip"},u);return Lo("div",{class:"wf-hover-card-wrap",ref:r,"aria-haspopup":"dialog","aria-expanded":String(!!s?.open),...l.wrapProps},[f,l.portal(p,"popover")].filter(Boolean))}};import{createClientBrowser as fa}from"weifuwu/ui-dom";import{h as ye}from"weifuwu/ui-dom";import{mountCommand as ma}from"weifuwu/ui-dom";var Io=fa();function ga(i){return{"top-right":"wf-notification--tr","top-left":"wf-notification--tl","bottom-right":"wf-notification--br","bottom-left":"wf-notification--bl"}[i]??"wf-notification--tr"}function ha(i){switch(i){case"success":return"check";case"error":return"close";case"warning":return"alert";case"info":return"info"}}var Ao=async(i,n)=>{let t=n.ui.usePopup?.({positioning:"none",closeOnOutside:!1,closeOnEscape:!1,isOpen:()=>!0,setOpen:()=>{}});return async e=>{let{items:o=[],onRemove:a,position:r="top-right",duration:s=4500,max:l=0}=e,c=l>0&&o.length>l?o.slice(-l):o;if(c.length===0)return null;let u=c.map(d=>ye("div",{class:`wf-notification wf-notification--${d.type}`,key:d.id,role:d.type==="error"?"alert":"status","aria-live":d.type==="error"?"assertive":"polite","data-id":d.id,"data-duration":(d.duration??s)||void 0},[ye("span",{class:"wf-notification-icon"},ye(T,{name:ha(d.type)})),ye("div",{class:"wf-notification-body"},[ye("div",{class:"wf-notification-title"},d.title),d.description?ye("div",{class:"wf-notification-desc"},d.description):null,d.action?ye("button",{class:"wf-notification-action",type:"button",onClick:f=>{f.stopPropagation(),d.action.onClick()}},d.action.label):null].filter(Boolean)),ye("button",{type:"button",class:"wf-notification-close","aria-label":"\u5173\u95ED\u901A\u77E5",onClick:()=>a?.(d.id)},ye(T,{name:"close",size:12}))].filter(Boolean)));return t.portal(ye("div",{class:`wf-notification-container ${ga(r)}`,"data-max":l||void 0},u),"notification")}};function ya(i){let n={position:i?.position??"top-right",duration:i?.duration??4500,max:i?.max??5},t=null,e=null,o=0,a=async(l,c)=>{let u=[],d=()=>c.ui.render();return t={add:f=>{u=[...u,f],d()},remove:f=>{u=u.filter(p=>p.id!==f),d()}},async()=>ye("div",{class:"wf-notification-host"},[ye(Ao,{items:u,position:n.position,duration:n.duration,max:n.max,onRemove:f=>t?.remove(f)})])},r=()=>{if(t||!e)return;let l=Io.createElement("div");l&&(Io.bodyAppend(l),ma(l,ye(a,{}),e))},s=l=>{r();let c=String(++o);t?.add({...l,id:c}),l.duration&&l.duration>0&&setTimeout(()=>t?.remove(c),l.duration)};return l=>{e=l;let c=Object.assign((u,d)=>s({type:d?.type??"info",title:u,description:d?.description,duration:d?.duration??n.duration,action:d?.action}),{open:u=>s({type:u.type??"info",title:u.title,description:u.description,duration:u.duration??n.duration,action:u.action}),success:u=>s({type:"success",title:u.title,description:u.description,duration:u.duration??n.duration}),error:u=>s({type:"error",title:u.title,description:u.description,duration:u.duration??n.duration}),info:u=>s({type:"info",title:u.title,description:u.description,duration:u.duration??n.duration}),warning:u=>s({type:"warning",title:u.title,description:u.description,duration:u.duration??n.duration})});return l.notification=c,l}}import{h as Zt}from"weifuwu/ui-dom";var ba=async(i,n)=>{let t=!1,e=0,o=null,a=[],r=0,s=0,l=n.ui.usePopup({trigger:"longpress",el:()=>o,isOpen:()=>t,setOpen:f=>{t=f,n.ui.render()},position:()=>({x:r,y:s}),closeOnOutside:!0,closeOnEscape:!0,onTrigger:f=>{r=f.clientX,s=f.clientY,e=a.findIndex(p=>!p.disabled)}}),c=()=>l.setOpen(!1),u=f=>{o=f},d=f=>{if(f.key==="ArrowDown"){f.preventDefault();for(let p=1;p<=a.length;p++){let g=(e+p)%a.length;if(!a[g].disabled){e=g,n.ui.render();break}}}else if(f.key==="ArrowUp"){f.preventDefault();for(let p=1;p<=a.length;p++){let g=(e-p+a.length)%a.length;if(!a[g].disabled){e=g,n.ui.render();break}}}else if(f.key==="Enter"){f.preventDefault();let p=a[e];p&&!p.disabled&&(p.onClick?.(),c())}else f.key==="Escape"&&c()};return async f=>{let{items:p=[],children:g,"aria-label":m,className:h}=f;a=p;let b=a.map((y,w)=>Zt("button",{type:"button",class:["wf-context-menu-item",y.variant==="danger"?"wf-context-menu-item--danger":"",y.disabled?"wf-context-menu-item--dis":"",e===w?"wf-context-menu-item--hl":""].filter(Boolean).join(" "),key:y.key,role:"menuitem",disabled:y.disabled||void 0,onClick:y.disabled?void 0:()=>{y.onClick?.(),c()},onMouseEnter:()=>{y.disabled||(e=w)}},y.icon?[y.icon,Zt("span",{},y.label)]:y.label)),x=Zt("div",{class:"wf-context-menu",role:"menu","aria-label":m,onKeyDown:d},b);return Zt("div",{class:["wf-context-menu-trigger",h].filter(Boolean).join(" "),ref:u,...l.wrapProps},[g,l.portal(x,"context-menu")].filter(Boolean))}};import{h as en}from"weifuwu/ui-dom";var wa=async(i,n)=>{let t=!1,e="",o=-1,a=0,r=!1,s=null,l=f=>{s=f},c=null,u=n.ui.usePopup({trigger:"click",placement:"bottom",center:!1,gap:4,el:()=>s,isOpen:()=>t,setOpen:f=>{f||d()}}),d=()=>{t&&(t=!1,n.ui.render())};return async f=>{let{options:p=[],prefix:g="@",placeholder:m,rows:h=3,disabled:b,size:x="md"}=f;c=n.ui.useControlledInput({value:f.value,onChange:f.onChange,name:"Mentions"});let y=c.value??"",w=(L,$)=>{if(r){d();return}let H=L.slice(0,$),R=H.lastIndexOf(g);if(R===-1){d();return}let N=H.slice(R+1);if(N.includes(" ")){d();return}if(N.length>0&&N.includes(`
|
|
9
9
|
`)){d();return}e=N,o=R,a=0,t=!0,n.ui.render()},v=e?p.filter(L=>L.value.toLowerCase().includes(e.toLowerCase())):p,k=L=>{let $=y.slice(0,o),H=y.slice(o+1+e.length),R=`${$}${g}${L.value} ${H}`;t=!1;let N=c?.controlled;c?.setValue(R),N||f.onChange?.(R)},S=L=>{let $=L.target.value;c?.setValue($),w($,L.target.selectionStart??$.length)},P=L=>{if(t)if(L.key==="ArrowDown")L.preventDefault(),a=Math.min(a+1,Math.max(v.length-1,0)),n.ui.render();else if(L.key==="ArrowUp")L.preventDefault(),a=Math.max(a-1,0),n.ui.render();else if(L.key==="Enter"){L.preventDefault();let $=v[a];$&&k($)}else L.key==="Escape"&&d()},E=t&&v.length>0?u.portal(en("div",{class:"wf-mentions-panel",role:"listbox"},v.map((L,$)=>en("button",{type:"button",class:`wf-mentions-option${a===$?" wf-mentions-option--hl":""}`,key:L.value,role:"option",onClick:()=>k(L),onMouseEnter:()=>{a=$}},L.label??L.value))),"popover"):null,A=en("textarea",{class:`wf-mentions-input wf-mentions-input--${x}`,rows:h,placeholder:m,value:y,disabled:b||void 0,ref:l,onInput:S,onKeyDown:P,onCompositionStart:()=>{r=!0,d()},onCompositionEnd:()=>{r=!1}});return en("div",{class:"wf-mentions"},[A,E].filter(Boolean))}};import{createClientBrowser as va}from"weifuwu/ui-dom";import{h as Le}from"weifuwu/ui-dom";var xa=async(i,n)=>{let t=n.browser??va(),e=[],o=new Map,a=r=>{let s=o.get(r);return s||(s=l=>{l&&(e[r]=l)},o.set(r,s)),s};return async r=>{let{items:s=[],multiple:l=!0,className:c}=r,u=n.ui.useControlled({value:r.active,onChange:r.onChange,name:"Collapse"}),d=u.value??[],f=h=>d.includes(h),p=h=>{u.controlled&&!r.onChange||(f(h)?u.setValue(d.filter(b=>b!==h)):u.setValue(l?[...d,h]:[h]))},g=h=>{let b=t?.activeElement()??null,x=e.indexOf(b);if(x<0)return;let y=x;if(h.key==="ArrowDown"||h.key==="ArrowRight")y=(x+1)%s.length;else if(h.key==="ArrowUp"||h.key==="ArrowLeft")y=(x-1+s.length)%s.length;else return;h.preventDefault(),e[y]?.focus()},m=s.map((h,b)=>{let x=f(h.key),y=[Le("span",{class:`wf-collapse-chevron${x?" wf-collapse-chevron--open":""}`},Le(T,{name:"chevron-down",size:14})),h.icon,Le("span",{class:"wf-collapse-title"},h.title)];h.extra&&y.push(Le("span",{class:"wf-collapse-extra"},h.extra));let w=x?Le("div",{class:"wf-collapse-content"},h.loading?Le("div",{class:"wf-collapse-loading"},Le(T,{name:"retry",size:14})):h.content??null):null;return Le("div",{class:`wf-collapse-item${x?" wf-collapse-item--open":""}`,key:h.key},[Le("button",{type:"button",class:"wf-collapse-header",ref:a(b),"aria-expanded":x?"true":"false",onClick:()=>p(h.key)},y),w].filter(Boolean))});return Le("div",{class:["wf-collapse",c].filter(Boolean).join(" "),onKeyDown:g},m)}};import{createClientBrowser as Ca}from"weifuwu/ui-dom";import{h as Me}from"weifuwu/ui-dom";function Do(i){return[i.key,...(i.children??[]).flatMap(Do)]}function Oo(i,n){let t=[];for(let e of i){let o=e.label.toLowerCase().includes(n),a=e.children?Oo(e.children,n):[];(o||a.length)&&t.push({...e,children:a.length?a:e.children})}return t}function Ro(i){let n=[];for(let t of i)t.children?.length&&(n.push(t.key),n.push(...Ro(t.children)));return n}function ka(i,n){if(!n)return i;let e=i.toLowerCase().indexOf(n);return e<0?i:[i.slice(0,e),Me("mark",{class:"wf-tree-match"},i.slice(e,e+n.length)),i.slice(e+n.length)]}function Bo(i,n,t=null){for(let e of i)n.set(e.key,t),e.children&&Bo(e.children,n,e)}var Bn=async(i,n)=>{let t=n.browser??Ca(),e=[],o=[],a=[];return async r=>{let{data:s=[],expandedKeys:l,onExpand:c,expandOnClick:u,checkable:d,className:f,searchValue:p}=r,g=(p??"").trim().toLowerCase(),m=g?Oo(s,g):s,h=g?new Set(Ro(m)):null,b=n?.ui?.useControlled({value:r.selectedKeys,onChange:r.onSelect,name:"Tree"}),x=n?.ui?.useControlled({value:r.checkedKeys,onChange:r.onCheck,name:"Tree"}),y=new Map;Bo(s,y);let w=l!==void 0,v=w?l:e,k=M=>h?h.has(M):v.includes(M),S=M=>{if(w&&!c){console.warn(`[weifuwu/Tree] \u53D7\u63A7\u6A21\u5F0F\uFF08expandedKeys \u5DF2\u4F20\uFF09\u4F46\u672A\u63D0\u4F9B onExpand\uFF0C\u5C55\u5F00/\u6298\u53E0\u65E0\u6CD5\u751F\u6548\u3002
|
|
10
10
|
\u975E\u53D7\u63A7\uFF1A\u53BB\u6389 expandedKeys\uFF1B\u53D7\u63A7\uFF1A\u4F20\u5165 onExpand={(keys) => setExpanded(keys)}`);return}let C=k(M)?v.filter(I=>I!==M):[...v,M];w?c?.(C):(e=C,n.ui.render())},P=M=>{let I=(b?.value??[]).includes(M)?[]:[M],B=b?.controlled;b?.setValue(I),B||r.onSelect?.(I)},E=M=>{let C=new Set(x?.value??[]),I=Do(M);if(C.has(M.key)){for(let _ of I)C.delete(_);let B=y.get(M.key);for(;B;)(B.children??[]).some(Q=>C.has(Q.key))||C.delete(B.key),B=y.get(B.key)}else{for(let _ of I)C.add(_);let B=y.get(M.key);for(;B;)(B.children??[]).some(G=>C.has(G.key))&&C.add(B.key),B=y.get(B.key)}x?.setValue(Array.from(C))},A=M=>{let C=M.children??[],I=x?.value??[];if(!C.length)return I.includes(M.key)?"checked":"unchecked";let B=C.map(A);return B.every(_=>_==="checked")?"checked":B.some(_=>_!=="unchecked")?"half":"unchecked"},L=M=>A(M)==="half",$=[],H=(M,C)=>{$.push(M);let I=$.length-1;a[I]||(a[I]=F=>{o[I]=F});let B=!!M.children?.length,_=k(M.key),G=(b?.value??[]).includes(M.key),Q=A(M)==="checked",J=B?Me("button",{type:"button",class:`wf-tree-switcher${_?" wf-tree-switcher--open":""}`,"aria-label":_?"\u6298\u53E0":"\u5C55\u5F00",onClick:F=>{F.stopPropagation(),S(M.key)}},Me(T,{name:"chevron-down",size:12})):Me("span",{class:"wf-tree-switcher-placeholder"}),ve=d?Me("button",{type:"button",class:["wf-tree-checkbox",Q?"wf-tree-checkbox--checked":"",L(M)?"wf-tree-checkbox--half":""].filter(Boolean).join(" "),role:"checkbox","aria-checked":L(M)?"mixed":Q?"true":"false",onClick:F=>{F.stopPropagation(),E(M)}}):null,ue=[J,ve,M.icon,Me("span",{class:"wf-tree-label"},ka(M.label,g))].filter(Boolean);return Me("div",{class:"wf-tree-node",key:M.key},[Me("div",{class:["wf-tree-row",G?"wf-tree-row--selected":"",M.disabled?"wf-tree-row--disabled":""].filter(Boolean).join(" "),style:{paddingLeft:`${C*20}px`},ref:a[I],tabIndex:M.disabled?void 0:0,"aria-selected":G?"true":"false",onClick:M.disabled?void 0:()=>{B&&u?S(M.key):P(M.key)},onKeyDown:M.disabled?void 0:F=>{F.key==="Enter"?(F.preventDefault(),P(M.key)):F.key===" "&&d?(F.preventDefault(),E(M)):F.key==="ArrowRight"&&B?(F.preventDefault(),_||S(M.key)):F.key==="ArrowLeft"&&B&&(F.preventDefault(),_&&S(M.key))}},ue),_&&B?Me("div",{class:"wf-tree-children"},M.children.map(F=>H(F,C+1))):null].filter(Boolean))},R=g&&m.length===0?Me("div",{class:"wf-tree-empty"},"\u65E0\u5339\u914D\u8282\u70B9"):null,N=M=>{if(M.key!=="ArrowDown"&&M.key!=="ArrowUp")return;let C=t?.activeElement()??null,I=o.indexOf(C);if(I<0)return;M.preventDefault();let B=M.key==="ArrowDown"?Math.min(I+1,o.length-1):Math.max(I-1,0);o[B]?.focus()};$=[];let D=m.map(M=>H(M,0));return Me("div",{class:["wf-tree",f].filter(Boolean).join(" "),role:"tree",onKeyDown:N},[R,...D].filter(Boolean))}};import{h as pe}from"weifuwu/ui-dom";function Ma(i,n,t=" / "){let e=i,o=[];for(let a of n){let r=e?.find(s=>s.value===a);if(!r)break;o.push(r.label),e=r.children}return o.join(t)}function Ho(i,n=[],t=[]){let e=[];for(let o of i){let a=[...n,o.value],r=[...t,o.label];o.children?.length?e.push(...Ho(o.children,a,r)):e.push({path:a,labels:r})}return e}var Pa=async(i,n)=>{let t=!1,e=[],o="",a=null,r=l=>{a=l},s=n.ui.usePopup({trigger:"click",placement:"bottom",center:!1,gap:6,el:()=>a,isOpen:()=>t,setOpen:l=>{t=l,n.ui.render()}});return async l=>{let{options:c=[],value:u,onChange:d,placeholder:f="\u8BF7\u9009\u62E9",disabled:p,error:g,label:m,showSearch:h,searchPlaceholder:b="\u641C\u7D22\u2026","aria-label":x}=l,y=t?e:[],w=()=>{p||(t=!t,e=Array.isArray(u)?[...u]:[],n.ui.render())},v=M=>{let C=c;for(let I of M){let B=C.find(_=>_.value===I);if(!B?.children)return C;C=B.children}return C},k=(M,C)=>{if(M.disabled)return;let I=[...C,M.value];M.children?.length?(e=I,n.ui.render()):(Array.isArray(u)&&!d&&console.warn(`[weifuwu/Cascader] \u53D7\u63A7\u6A21\u5F0F\uFF08value \u5DF2\u4F20\uFF09\u4F46\u672A\u63D0\u4F9B onChange\uFF0C\u9009\u62E9\u65E0\u6CD5\u751F\u6548\u3002
|
|
11
11
|
\u975E\u53D7\u63A7\uFF1A\u53BB\u6389 value\uFF1B\u53D7\u63A7\uFF1A\u4F20\u5165 onChange={(path) => setPath(path)}`),t=!1,n.ui.render(),d?.(I))},S=[],P=[],E=0;for(;;){let M=v(P),C=y[E]?M.find(B=>B.value===y[E]):void 0,I=[...P];if(S.push(pe("div",{class:"wf-cascader-col",key:E},M.map(B=>{let _=C?.value===B.value;return pe("button",{type:"button",class:["wf-cascader-opt",_?"wf-cascader-opt--active":"",B.disabled?"wf-cascader-opt--dis":""].filter(Boolean).join(" "),key:B.value,onClick:()=>k(B,I)},[pe("span",{class:"wf-cascader-opt-label"},B.label),B.children?.length?pe("span",{class:"wf-cascader-opt-arrow"},pe(T,{name:"chevron-right",size:12})):null].filter(Boolean))}))),!C?.children?.length)break;P=[...P,C.value],E++}let A=o.trim().toLowerCase(),L;if(h&&A){let C=Ho(c).filter(I=>I.labels.some(B=>B.toLowerCase().includes(A)));L=C.length===0?pe("div",{class:"wf-cascader-empty"},"\u65E0\u5339\u914D"):pe("div",{class:"wf-cascader-search-results"},C.map(I=>pe("button",{type:"button",class:"wf-cascader-search-item",key:I.path.join("/"),onClick:()=>{Array.isArray(u)&&!d&&console.warn("[weifuwu/Cascader] \u53D7\u63A7\u6A21\u5F0F\uFF08value \u5DF2\u4F20\uFF09\u4F46\u672A\u63D0\u4F9B onChange\uFF0C\u9009\u62E9\u65E0\u6CD5\u751F\u6548\u3002"),t=!1,o="",n.ui.render(),d?.(I.path)}},I.labels.join(" / "))))}else L=S;let $=h?pe("input",{class:"wf-cascader-search wf-input",type:"text",placeholder:b,value:o,onInput:M=>{o=M.target.value,n.ui.render()}}):null,H=s.portal(pe("div",{class:"wf-cascader-panel",role:"listbox"},h?[$,L].filter(Boolean):L),"popover"),R=Array.isArray(u)&&u.length?Ma(c,u):f,N=[];m&&N.push(pe("label",{class:"wf-cascader-label"},m));let D=pe("button",{type:"button",class:`wf-cascader-trigger${p?" wf-cascader-trigger--dis":""}${g?" wf-cascader-trigger--err":""}`,"aria-label":x,"aria-haspopup":"listbox","aria-expanded":String(t),ref:r,onClick:p?void 0:w},[pe("span",{class:`wf-cascader-value${u?.length?"":" wf-cascader-value--placeholder"}`},R),pe("span",{class:`wf-cascader-arrow${t?" wf-cascader-arrow--open":""}`},pe(T,{name:"chevron-down",size:12}))]);return N.push(pe("div",{class:"wf-cascader"},[D,H].filter(Boolean))),g&&N.push(pe("div",{class:"wf-cascader-err"},g)),pe("div",{class:"wf-cascader-wrap"},N)}};import{h as we}from"weifuwu/ui-dom";var Ta=async(i,n)=>{let t=[],e=[],o="",a="";return async r=>{let{data:s=[],targetKeys:l=[],onChange:c,titles:u=["\u6E90\u5217\u8868","\u76EE\u6807\u5217\u8868"],size:d="md",disabled:f,showSearch:p,searchPlaceholder:g="\u641C\u7D22\u2026"}=r,m=s.filter(P=>!l.includes(P.key)),h=s.filter(P=>l.includes(P.key)),b=(P,E)=>{if(f)return;let A=P==="left"?t:e,L=A.includes(E)?A.filter($=>$!==E):[...A,E];P==="left"?t=L:e=L,n.ui.render()},x=()=>{if(!c||t.length===0)return;let P=[...l,...t];t=[],n.ui.render(),c(P)},y=()=>{if(!c||e.length===0)return;let P=l.filter(E=>!e.includes(E));e=[],n.ui.render(),c(P)},w=(P,E)=>{let A=P==="left"?t:e,L=(P==="left"?o:a).toLowerCase(),$=L?E.filter(R=>R.label.toLowerCase().includes(L)):E,H=p?we("input",{class:"wf-transfer-search wf-input",type:"text",placeholder:g,value:P==="left"?o:a,onInput:R=>{P==="left"?o=R.target.value:a=R.target.value,n.ui.render()}}):null;return we("div",{class:`wf-transfer-list wf-transfer-list--${P}`},[we("div",{class:"wf-transfer-title"},u[P==="left"?0:1]),H,we("div",{class:"wf-transfer-body"},$.length===0?[we("div",{class:"wf-transfer-empty"},L?"\u65E0\u5339\u914D":"\u6682\u65E0\u6570\u636E")]:$.map(R=>we("button",{type:"button",class:["wf-transfer-item",A.includes(R.key)?"wf-transfer-item--sel":"",R.disabled?"wf-transfer-item--dis":""].filter(Boolean).join(" "),key:R.key,disabled:R.disabled||void 0,onClick:R.disabled?void 0:()=>b(P,R.key)},R.label)))].filter(Boolean))},v=t.length===0||f,k=e.length===0||f,S=we("div",{class:"wf-transfer-actions"},[we("button",{type:"button",class:"wf-transfer-btn",disabled:k||void 0,"aria-label":"\u79FB\u56DE\u5DE6\u4FA7",onClick:k?void 0:y},we(T,{name:"arrow-left",size:14})),we("button",{type:"button",class:"wf-transfer-btn",disabled:v||void 0,"aria-label":"\u79FB\u81F3\u53F3\u4FA7",onClick:v?void 0:x},we(T,{name:"arrow-right",size:14}))]);return we("div",{class:`wf-transfer wf-transfer--${d}`},[w("left",m),S,w("right",h)])}};import{h as Ie}from"weifuwu/ui-dom";var Sa=async(i,n)=>{let t="",e=0,o={},a=l=>{l&&queueMicrotask(()=>l.focus())};n.ui.useGlobalKey(l=>{let c=o.shortcut;if(!c)return;let u=c.split("+"),d=u.includes("mod"),f=u[u.length-1].toLowerCase();(!d||l.ctrlKey||l.metaKey)&&l.key.toLowerCase()===f&&(l.preventDefault(),o.onOpenChange?.(!o.open))});let r=l=>{},s=n.ui.usePopup?.({trigger:"click",placement:"bottom",el:()=>null,isOpen:()=>!!o.open,setOpen:l=>{l||o.onOpenChange?.(!1)},open:()=>!!o.open,onOpenChange:l=>{o.onOpenChange?.(l)},mask:!0,maskCentered:!0})??{open:!1,setOpen:()=>{},wrapProps:{},portal:()=>null,refresh:()=>{}};return async l=>{let{open:c,onOpenChange:u,items:d=[],placeholder:f="\u8F93\u5165\u547D\u4EE4\u6216\u641C\u7D22...",emptyText:p="\u65E0\u5339\u914D\u7ED3\u679C",globalShortcut:g="mod+k"}=l;if(o={open:c,onOpenChange:u,shortcut:g},!c)return null;let m=t?d.filter(w=>{let v=t.toLowerCase();return w.label.toLowerCase().includes(v)||(w.keywords??[]).some(k=>k.toLowerCase().includes(v))}):d;e>=m.length&&(e=Math.max(0,m.length-1));let h=()=>u?.(!1),b=w=>{if(w.key==="ArrowDown")w.preventDefault(),e=Math.min(e+1,Math.max(m.length-1,0)),n.ui.render();else if(w.key==="ArrowUp")w.preventDefault(),e=Math.max(e-1,0),n.ui.render();else if(w.key==="Enter"){w.preventDefault();let v=m[e];v&&(v.onSelect?.(),h())}else w.key==="Escape"&&h()},x=m.length>0?m.map((w,v)=>Ie("button",{type:"button",class:`wf-command-item${e===v?" wf-command-item--hl":""}`,key:w.key,onClick:()=>{w.onSelect?.(),h()},onMouseEnter:()=>{e=v}},[w.icon??Ie(T,{name:"search",size:14}),Ie("span",{class:"wf-command-item-label"},w.label),w.shortcut?Ie("kbd",{class:"wf-command-shortcut"},w.shortcut):null].filter(Boolean))):[Ie("div",{class:"wf-command-empty"},p)],y=Ie("div",{class:"wf-command-panel",role:"dialog","aria-label":"\u547D\u4EE4\u9762\u677F"},[Ie("div",{class:"wf-command-input-wrap"},[Ie(T,{name:"search",size:14}),Ie("input",{class:"wf-command-input",type:"text",placeholder:f,value:t,onInput:w=>{t=w.target.value,e=0,n.ui.render()},onKeyDown:b,ref:a})]),Ie("div",{class:"wf-command-list"},x)]);return s.portal(y,"command")}};import{createClientBrowser as $a}from"weifuwu/ui-dom";import{h as mt}from"weifuwu/ui-dom";var Ea=async(i,n)=>{let t=n.browser??$a(),e=null,o=0,a=[],r=new Map,s=f=>{let p=r.get(f);return p||(p=g=>{g&&(a[f]=g)},r.set(f,p)),p},l=[],c=n.ui.usePopup({trigger:"click",placement:"bottom",center:!1,gap:4,el:()=>{let f=l.findIndex(p=>p.key===e);return f>=0?a[f]:null},isOpen:()=>e!==null,setOpen:f=>{f||u()}}),u=()=>{e!==null&&(e=null,n.ui.render())},d=f=>{e=e===f?null:f,o=0,n.ui.render()};return async f=>{let{menus:p=[],"aria-label":g}=f;l=p;let m=y=>{if(y.key==="Escape"){u();return}if(y.key!=="ArrowRight"&&y.key!=="ArrowLeft")return;if(e){u();return}let w=t?.activeElement()??null,v=a.indexOf(w);if(v<0)return;y.preventDefault();let k=y.key==="ArrowRight"?(v+1)%l.length:(v-1+l.length)%l.length;a[k]?.focus()},h=l.map((y,w)=>{let v=e===y.key;return mt("button",{type:"button",class:["wf-menubar-trigger",v?"wf-menubar-trigger--open":"",y.disabled?"wf-menubar-trigger--dis":""].filter(Boolean).join(" "),key:y.key,ref:s(w),"aria-haspopup":"menu","aria-expanded":v?"true":"false",onClick:y.disabled?void 0:()=>d(y.key),onKeyDown:k=>{(k.key==="ArrowDown"||k.key==="Enter")&&(k.preventDefault(),y.disabled||d(y.key))}},y.label)}),b=l.find(y=>y.key===e),x=b?c.portal(mt("div",{class:"wf-menubar-panel",role:"menu"},(b.items??[]).map((y,w)=>mt("button",{type:"button",class:["wf-menubar-item",o===w?"wf-menubar-item--hl":"",y.disabled?"wf-menubar-item--dis":""].filter(Boolean).join(" "),key:y.key,role:"menuitem",onClick:y.disabled?void 0:()=>{y.onSelect?.(),u()},onMouseEnter:()=>{y.disabled||(o=w)}},[mt("span",{class:"wf-menubar-item-label"},y.label),y.shortcut?mt("kbd",{class:"wf-menubar-shortcut"},y.shortcut):null].filter(Boolean)))),"popover"):null;return mt("div",{class:"wf-menubar",role:"menubar","aria-label":g,onKeyDown:m},[...h,x].filter(Boolean))}};import{h as ze}from"weifuwu/ui-dom";var La=async(i,n)=>{let t=0,e,o=0,a=()=>{},r=!1,s=3e3,l=c=>{c?r&&(clearInterval(e),e=setInterval(()=>a(t+1),s)):(clearInterval(e),e=void 0)};return async c=>{let{children:u=[],autoplay:d,interval:f=3e3,showArrows:p=!0,showDots:g=!0,loop:m=!0,"aria-label":h,className:b}=c,x=u.length;if(x===0)return null;let y=A=>{let L=m?(A+x)%x:Math.max(0,Math.min(A,x-1));L!==t&&(t=L,n.ui.render())};a=y,r=!!d,s=f;let w=()=>y(t+1),v=()=>y(t-1),k={onTouchStart:A=>{o=A.touches[0].clientX},onTouchEnd:A=>{let L=A.changedTouches[0].clientX-o;Math.abs(L)>40&&(L<0?w():v())}},S=ze("div",{class:"wf-carousel-track",style:{transform:`translateX(-${t*100}%)`}},u),P=p?[ze("button",{type:"button",class:"wf-carousel-arrow wf-carousel-arrow--prev","aria-label":"\u4E0A\u4E00\u5F20",onClick:v},ze(T,{name:"chevron-left",size:18})),ze("button",{type:"button",class:"wf-carousel-arrow wf-carousel-arrow--next","aria-label":"\u4E0B\u4E00\u5F20",onClick:w},ze(T,{name:"chevron-right",size:18}))]:[],E=g?ze("div",{class:"wf-carousel-dots"},u.map((A,L)=>ze("button",{type:"button",class:`wf-carousel-dot${L===t?" wf-carousel-dot--active":""}`,key:L,"aria-label":`\u7B2C ${L+1} \u5F20`,onClick:()=>y(L)}))):null;return ze("div",{class:["wf-carousel",b].filter(Boolean).join(" "),"aria-label":h,ref:l,...k},[ze("div",{class:"wf-carousel-viewport"},S),...P,E].filter(Boolean))}};import{h as tn}from"weifuwu/ui-dom";var Ia=async(i,n)=>{let t=0,e={...i},o=l=>Math.max(e.min??80,Math.min(l,e.max??600)),a=l=>{let c=o(l);c!==t&&(t=c,e.onResize?.(c),n.ui.render())},r=0,s=n.ui.useDrag({onStart:()=>{r=t},onMove:(l,c)=>{let u=e.direction==="horizontal"?c.x:c.y;a(r+u)}});return async l=>{let{direction:c="horizontal",defaultSize:u=300,min:d=80,max:f=600,step:p=20,children:g,onResize:m,className:h}=l;Object.assign(e,l,{direction:c,min:d,max:f,step:p,onResize:m}),t===0&&(t=u);let x=tn("div",{class:"wf-resizable-handle",role:"separator","aria-orientation":c==="horizontal"?"vertical":"horizontal",tabIndex:0,...s,onKeyDown:y=>{let w=c==="horizontal"?y.key==="ArrowRight"?p:y.key==="ArrowLeft"?-p:0:y.key==="ArrowDown"?p:y.key==="ArrowUp"?-p:0;w!==0&&(y.preventDefault(),a(t+w))}});return tn("div",{class:["wf-resizable",`wf-resizable--${c}`,h].filter(Boolean).join(" ")},[tn("div",{class:"wf-resizable-panel",style:{flexBasis:`${t}px`}},g[0]),x,tn("div",{class:"wf-resizable-panel wf-resizable-panel--fill"},g[1])])}};import{h as de}from"weifuwu/ui-dom";var Aa=["1 \u6708","2 \u6708","3 \u6708","4 \u6708","5 \u6708","6 \u6708","7 \u6708","8 \u6708","9 \u6708","10 \u6708","11 \u6708","12 \u6708"],Da=async(i,n)=>{let t=new Date,e=t.getMonth(),o=t.getFullYear();return async a=>{let{events:r=[],month:s,year:l,onMonthChange:c,onSelectDate:u,selectedDate:d,"aria-label":f}=a,p=s!==void 0&&l!==void 0,g=p?s:e,m=p?l:o,h=S=>{if(p&&!c){console.warn(`[weifuwu/Calendar] \u53D7\u63A7\u6A21\u5F0F\uFF08month/year \u5DF2\u4F20\uFF09\u4F46\u672A\u63D0\u4F9B onMonthChange\uFF0C\u6708\u4EFD\u5207\u6362\u65E0\u6CD5\u751F\u6548\u3002
|
package/dist/index.js
CHANGED
|
@@ -3078,6 +3078,38 @@ var HtmlSafe = class {
|
|
|
3078
3078
|
var Fragment = /* @__PURE__ */ Symbol("Fragment");
|
|
3079
3079
|
var Portal = /* @__PURE__ */ Symbol("Portal");
|
|
3080
3080
|
|
|
3081
|
+
// src/ui-dom/vdom/transform.ts
|
|
3082
|
+
function holeDetail(v) {
|
|
3083
|
+
if (v === false) return "false";
|
|
3084
|
+
if (v === null) return "null";
|
|
3085
|
+
if (v === void 0) return "undefined";
|
|
3086
|
+
if (v === true) return "true";
|
|
3087
|
+
if (typeof v === "object") {
|
|
3088
|
+
try {
|
|
3089
|
+
const s = JSON.stringify(v);
|
|
3090
|
+
const d = s != null && s.length > 80 ? s.slice(0, 80) + "\u2026" : s ?? "";
|
|
3091
|
+
return `object ${d}`;
|
|
3092
|
+
} catch {
|
|
3093
|
+
return `object ${Object.prototype.toString.call(v)}`;
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
return `bad-vnode type=${typeof v}`;
|
|
3097
|
+
}
|
|
3098
|
+
function isInvalidVNodeType(t) {
|
|
3099
|
+
return typeof t !== "string" && typeof t !== "function" && t !== Fragment && t !== Portal;
|
|
3100
|
+
}
|
|
3101
|
+
function ensureArrayKeys(children) {
|
|
3102
|
+
for (let i = 0; i < children.length; i++) {
|
|
3103
|
+
const c = children[i];
|
|
3104
|
+
if (c != null && typeof c === "object" && !Array.isArray(c)) {
|
|
3105
|
+
const v = c;
|
|
3106
|
+
if (v.key === void 0) v.key = String(i);
|
|
3107
|
+
else v.key = String(v.key);
|
|
3108
|
+
}
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
var ENUMERATED_VALUE_BASED = /* @__PURE__ */ new Set(["draggable", "contenteditable", "spellcheck", "translate"]);
|
|
3112
|
+
|
|
3081
3113
|
// src/ui-dom/vdom/ssr.ts
|
|
3082
3114
|
var VOID_TAGS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
|
|
3083
3115
|
var SVG_TAGS = /* @__PURE__ */ new Set(["svg", "path", "circle", "rect", "line", "polyline", "polygon", "g", "text", "defs", "use", "clipPath"]);
|
|
@@ -3101,10 +3133,18 @@ async function renderSsr(input, ctx) {
|
|
|
3101
3133
|
if (input == null || typeof input === "boolean") return "";
|
|
3102
3134
|
if (typeof input === "string" || typeof input === "number") return escape(String(input));
|
|
3103
3135
|
if (Array.isArray(input)) {
|
|
3104
|
-
|
|
3136
|
+
ensureArrayKeys(input);
|
|
3137
|
+
const parts = await Promise.all(input.map((c) => {
|
|
3138
|
+
if (c == null || typeof c === "boolean") return Promise.resolve(`<!--wf-hole: ${holeDetail(c)}-->`);
|
|
3139
|
+
return renderSsr(c, ctx);
|
|
3140
|
+
}));
|
|
3105
3141
|
return parts.join("");
|
|
3106
3142
|
}
|
|
3107
3143
|
const vnode = input;
|
|
3144
|
+
if (isInvalidVNodeType(vnode.type)) {
|
|
3145
|
+
console.warn(`[weifuwu] children \u9879\u975E\u6CD5\uFF1Atype=${String(vnode.type)}\uFF08${typeof vnode.type}\uFF09\u2014\u2014\u5DF2\u5360\u4F4D\uFF08wf-hole\uFF09`);
|
|
3146
|
+
return `<!--wf-hole: ${holeDetail(input)}-->`;
|
|
3147
|
+
}
|
|
3108
3148
|
if (vnode.type === Portal || vnode.type === Fragment) return renderSsr(vnode.props?.children, ctx);
|
|
3109
3149
|
if (typeof vnode.type === "function") {
|
|
3110
3150
|
const childCtx = Object.create(ctx);
|
|
@@ -3114,12 +3154,24 @@ async function renderSsr(input, ctx) {
|
|
|
3114
3154
|
`Component ${vnode.type.name || "anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`
|
|
3115
3155
|
);
|
|
3116
3156
|
}
|
|
3117
|
-
|
|
3157
|
+
const out = await renderFn(vnode.props ?? {});
|
|
3158
|
+
if (vnode.key != null && out != null && typeof out === "object") {
|
|
3159
|
+
if (Array.isArray(out)) {
|
|
3160
|
+
for (const c of out) {
|
|
3161
|
+
if (c != null && typeof c === "object" && !Array.isArray(c)) c.key = vnode.key;
|
|
3162
|
+
}
|
|
3163
|
+
} else {
|
|
3164
|
+
;
|
|
3165
|
+
out.key = vnode.key;
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
return renderSsr(out, childCtx);
|
|
3118
3169
|
}
|
|
3119
3170
|
const tag = vnode.type;
|
|
3120
3171
|
const props = vnode.props ?? {};
|
|
3121
3172
|
const attrs = [];
|
|
3122
3173
|
let innerHTML;
|
|
3174
|
+
if (vnode.key != null) attrs.push(` data-wf-key="${escape(String(vnode.key))}"`);
|
|
3123
3175
|
for (const [key, value] of Object.entries(props)) {
|
|
3124
3176
|
if (key === "children" || key === "key") continue;
|
|
3125
3177
|
if (key === "ref") continue;
|
|
@@ -3137,7 +3189,7 @@ async function renderSsr(input, ctx) {
|
|
|
3137
3189
|
attrs.push(` style="${escape(styleToString(value))}"`);
|
|
3138
3190
|
continue;
|
|
3139
3191
|
}
|
|
3140
|
-
if (key
|
|
3192
|
+
if (ENUMERATED_VALUE_BASED.has(key)) {
|
|
3141
3193
|
attrs.push(` ${key}="${value ? "true" : "false"}"`);
|
|
3142
3194
|
continue;
|
|
3143
3195
|
}
|
|
@@ -3172,6 +3224,7 @@ function createSsrUi() {
|
|
|
3172
3224
|
},
|
|
3173
3225
|
endMounting: () => {
|
|
3174
3226
|
},
|
|
3227
|
+
onUnmount: () => void 0,
|
|
3175
3228
|
// hooks no-op(组件 SSR 安全——不注册监听/定时器)
|
|
3176
3229
|
useChat: () => ({ messages: [], input: "", streaming: false, error: null, usage: null, step: null, send: () => {
|
|
3177
3230
|
}, stop: () => {
|
package/dist/ui-dom/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
function yn(e){let n=[],t=(e||"/").replace(/:(\w+)/g,(r,o)=>(n.push(o),"([^/]+)")).replace(/\*/g,".*");return{re:new RegExp(`^${t}$`),keys:n}}var be=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 r=this,o=n,s=async(i,l,u)=>{let d=l.__routePath??r.getPath(),a=null;return d===o?a="/":(o==="/"?d!=="/"&&d.startsWith("/"):d.startsWith(o+"/"))&&(a=d.slice(o.length)),a===null?u:async(c,p)=>{let w=await t._handle(a,c,p);return w===null?u(c,p):w}};return this._middlewares.push(s),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 r=await t(n);r&&r!==n&&Object.assign(n,r)}}}get(n,t,r){return this._routes.push({path:n,handler:t,title:r?.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 r of this._routes){let{re:o,keys:s}=yn(r.path),i=n.match(o);if(!i)continue;let l={};for(let u=0;u<s.length;u++)l[s[u]]=decodeURIComponent(i[u+1]);t={handler:r.handler,params:l,title:r.title};break}return t||(t={handler:this._notFound??(()=>null),params:{}}),t}async _handle(n,t,r){await this._ensureInjected(r);let o=this.match(n);o.title&&typeof document<"u"&&(document.title=o.title),r.params=o.params,r.route&&(r.route.params=o.params);let i=o.handler,l=r.__routePath;r.__routePath=n;try{for(let u=this._middlewares.length-1;u>=0;u--){let d=this._middlewares[u],a=i;i=await d(t,r,a)??a}return await i(t,r)}finally{r.__routePath=l}}async execute(n,t,r){await this._ensureInjected(t);let o=this.match(r);o.title&&typeof document<"u"&&(document.title=o.title),t.params=o.params,t.route&&(t.route.params=o.params);let i=o.handler;for(let l=this._middlewares.length-1;l>=0;l--){let u=this._middlewares[l],d=i;i=await u(n,t,d)??d}return await i(n,t)}};var L=Symbol("Fragment"),H=Symbol("Portal");function ve(e,n,t){return{type:e,props:Ge(n),key:t??void 0}}var gn=ve;function hn(e,n,t){return ve(e,n,t)}function j(e,n,...t){let r=Ge(n??{});return t.length>0&&(r.children=t.length===1?t[0]:t),{type:e,props:r,key:n?.key??void 0}}function Ge(e){if(!e)return{};let n={};for(let t of Object.keys(e))t!=="key"&&(n[t]=e[t]);return n}function F(e){if(e==null||typeof e=="boolean")return[];if(Array.isArray(e)){let n=!1;for(let o=0;o<e.length;o++)if(Array.isArray(e[o])){n=!0;break}if(!n)return e;let t=[],r=[...e].reverse();for(;r.length>0;){let o=r.pop();if(Array.isArray(o))for(let s=o.length-1;s>=0;s--)r.push(o[s]);else t.push(o)}return t}return[e]}function te(e,n){return{type:H,props:{children:e,portalKey:n},key:n??void 0,_placement:"remote"}}function _(){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,r=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[r](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 r=document.execCommand("copy");return document.body.removeChild(t),r}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{}}}}function wn(e,n,t=400){let r=!1,o=()=>{r||(r=!0,e.removeEventListener("animationend",o),clearTimeout(s),n())};e.addEventListener("animationend",o);let s=setTimeout(o,t)}function B(e,n){return Object.assign(Object.create(e),n)}function bn(e){let n={baseURL:e?.baseURL??"",headers:{"Content-Type":"application/json",...e?.headers}},t=e?.onRequest,r=e?.onResponse,o=e?.timeout??0;async function s(i,l,u,d){let a=n.baseURL+l,c={method:i,headers:{...n.headers,...d?.headers}},p=e?.token?.();p&&!c.headers.Authorization&&(c.headers.Authorization=`Bearer ${p}`);let w=o>0,b=!!d?.signal,m=null,g=null;(w||b)&&(m=new AbortController,c.signal=m.signal,w&&(g=setTimeout(()=>m.abort(new Error("Request timed out")),o)),b&&d.signal.addEventListener("abort",()=>m.abort())),u!==void 0&&i!=="GET"&&i!=="HEAD"&&(c.body=JSON.stringify(u));let y={url:a,init:c};t&&(y=t(y));try{let f=await fetch(y.url,y.init);if(r)return r(f);if(!f.ok){let P=await f.text().catch(()=>"");throw new Ce(f.status,P||f.statusText)}let h=f.headers.get("content-length");if(f.status===204||h==="0")return;let x=(f.headers.get("content-type")||"").toLowerCase();return x.includes("application/json")||x.includes("json")?f.json():f.text()}finally{g&&clearTimeout(g)}}return i=>B(i,{api:{get:(u,d)=>s("GET",u,void 0,d),post:(u,d,a)=>s("POST",u,d,a),put:(u,d,a)=>s("PUT",u,d,a),patch:(u,d,a)=>s("PATCH",u,d,a),delete:(u,d)=>s("DELETE",u,void 0,d)}})}var Ce=class extends Error{status;body;constructor(n,t){super(`API Error ${n}: ${t}`),this.name="ApiError",this.status=n,this.body=t}};function vn(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 Cn(e){let n=vn(e);return n?.exp?n.exp*1e3-3e4<Date.now():!0}function xn(e){let n=e?.storage??localStorage,t=e?.tokenKey??"weifuwu_token",r=e?.userKey??"weifuwu_user",o=e?.refreshTokenKey??"weifuwu_refresh",s=e?.refreshEndpoint??"/api/auth/refresh";return i=>{let l=n.getItem(t),u=n.getItem(r),d={token:l,user:u?JSON.parse(u):null,get isLoggedIn(){return this.token!==null},login(a,c,p){d.token=a,d.user=c,n.setItem(t,a),n.setItem(r,JSON.stringify(c)),p&&n.setItem(o,p)},logout(){d.token=null,d.user=null,n.removeItem(t),n.removeItem(r),n.removeItem(o)},setUser(a){d.user=a,n.setItem(r,JSON.stringify(a))},async refresh(){let a=n.getItem(o);if(!a)return!1;try{let c=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:a})});if(!c.ok)return d.logout(),!1;let p=await c.json();return d.token=p.token,n.setItem(t,p.token),p.refreshToken&&n.setItem(o,p.refreshToken),!0}catch{return!1}}};return l&&Cn(l)&&d.refresh().catch(()=>{}),B(i,{auth:d})}}function En(e={}){let n=e.url??"/ws",t=e.reconnectInterval??3e3,r=e.maxReconnect??10,o=e.pingInterval??3e4,s=e.pingTimeout??1e4;return i=>{let l=new Set,u=null,d=0,a=null,c=null,p=null,w=!1,b={isConnected:!1,onMessage:h=>(l.add(h),()=>{l.delete(h)}),send:h=>{u?.readyState===WebSocket.OPEN&&u.send(JSON.stringify(h))},_connect:m,close:()=>{w=!0,f(),u?.close(),u=null,b.isConnected=!1}};async function m(){if(!w)try{u=new WebSocket(n),u.onopen=()=>{b.isConnected=!0,d=0,g()},u.onmessage=h=>{try{let x=JSON.parse(h.data);for(let P of l)P(x)}catch{}y()},u.onclose=()=>{b.isConnected=!1,f(),!w&&d<r&&(d++,a=setTimeout(m,t*Math.min(d,5)))},u.onerror=()=>{u?.close()}}catch{w||(a=setTimeout(m,t))}}function g(){o<=0||(c=setInterval(()=>{u?.readyState===WebSocket.OPEN&&u.send(JSON.stringify({type:"ping"})),p=setTimeout(()=>{u?.close()},s)},o))}function y(){clearTimeout(p)}function f(){clearInterval(c),clearTimeout(p),clearTimeout(a)}return m(),B(i,{ws:b})}}function Tn(e,n){if(e===n)return!0;let t=Object.keys(e),r=Object.keys(n);if(t.length!==r.length)return!1;for(let o of t)if(e[o]!==n[o])return!1;return!0}async function Ye(e,n,t,r){e._id||(r?.reuse?._id?e._id=r.reuse._id:e._id=t.nextId(),t.idRegistry.set(e._id,e)),r?.reuse&&(r.reuse._parentNode&&(e._parentNode=r.reuse._parentNode),r.reuse._refNode&&(e._refNode=r.reuse._refNode),r.reuse._ctxVersion!=null&&(e._ctxVersion=r.reuse._ctxVersion));let o=Object.create(n);o.ui=Object.create(n.ui);let s=o.ui;if(s._selfId=e._id,s._selfVNode=e,s.render=function(i){return i==null&&e._id?n.ui.render([e._id]):n.ui.render(i)},typeof e._render!="function"&&typeof r?.reuse?._render=="function"&&(e._render=r.reuse._render),typeof e._render!="function"){n.ui?.setMounting?.(!0);let i;try{i=await e.type(e.props??{},o)}finally{n.ui?.endMounting?.()}if(typeof i!="function")throw new Error(`Component ${e.type.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);e._render=i}return{renderFn:e._render,childCtx:o}}function xe(e){return!!e&&typeof e.then=="function"}function M(e,n,t,r,o){if(e==null||typeof e=="boolean"||typeof e=="string"||typeof e=="number")return e;if(Array.isArray(e)){let u=Array.isArray(t)?t:[],d=e.map((c,p)=>M(c,n,u[p],r,o)),a=!1;for(let c=0;c<d.length;c++)if(xe(d[c])){a=!0;break}return a?Promise.all(d).then(()=>e):e}let s=e,i=r??n.__registry,l=t!=null&&typeof t=="object"&&!Array.isArray(t)&&t.type===s.type?t:null;if(typeof s.type=="function"){s._id||(s._id=l?._id??i.nextId(),i.idRegistry.set(s._id,s)),l&&(l._parentNode&&(s._parentNode=l._parentNode),l._refNode&&(s._refNode=l._refNode),l._ctxVersion!=null&&(s._ctxVersion=l._ctxVersion),typeof l._render=="function"&&(s._render=l._render));let u=Tn(l?.props??{},s.props??{}),d=n?.ui?._ctxVersion??0,a=(l?._ctxVersion??-1)===d;return!o?.force&&u&&a&&l?._child!=null?(s._child=l._child,s._ctxVersion=l._ctxVersion,s):(async()=>{let{childCtx:c}=await Ye(s,n,i,{reuse:l??void 0}),p=await M(await s._render(s.props),c,l?._child,i);return s._child=p??null,s._ctxVersion=d,s})()}if(s.type===L){let u=M(s.props?.children??null,n,l?._child??l?.props?.children,i);return xe(u)?u.then(d=>(s._child=d??null,s)):(s._child=u??null,s)}if(typeof s.type=="string"||typeof s.type=="symbol"){let u=M(s.props?.children??null,n,l?.props?.children,i);return xe(u)?u.then(d=>(s._child=d??null,s)):(s._child=u??null,s)}return s}var Ee=new Set(["svg","path","circle","rect","line","polyline","polygon","g","text","defs","use","clipPath"]),re=/^on[A-Z]/,Nn=new Set(["zIndex","opacity","lineHeight","fontWeight","fontSizeAdjust","flex","flexGrow","flexShrink","order","zoom","aspectRatio","gridRow","gridColumn","scale","rotate","animationIterationCount","columnCount","fillOpacity","strokeOpacity","stopOpacity","floodOpacity"]);function Y(e,n,t){if(t==null||t===!1)return;let r=e.ownerDocument?.defaultView;if(n==="class"||n==="className"){if(typeof t=="object")for(let[o,s]of Object.entries(t))s&&e.classList.add(o);else e.setAttribute("class",String(t));return}if(n==="style"){if(typeof t=="string")e.setAttribute("style",t);else{let o=e.style;for(let[s,i]of Object.entries(t))i==null?o[s]="":s.startsWith("--")?o.setProperty(s,String(i)):typeof i=="number"&&!Nn.has(s)?o[s]=`${i}px`:o[s]=String(i)}return}if(n==="ref"){if(typeof t=="function")try{t(e)}catch(o){console.error("[weifuwu] ref error",o)}return}if(re.test(n)){let o=n.slice(2).toLowerCase();if(typeof t!="function"){console.warn(`[weifuwu] event prop ${n} expects a function, got ${typeof t} \u2014 ignored`);return}e.addEventListener(o,t);return}if(n==="value"){e.value=t;return}if(n==="indeterminate"){e.indeterminate=!!t;return}if(n==="innerHTML"){e.innerHTML=String(t??"");return}if(n==="draggable"||n==="contenteditable"||n==="spellcheck"){e.setAttribute(n,t?"true":"false");return}if(n.startsWith("aria-")&&typeof t=="boolean"){e.setAttribute(n,t?"true":"false");return}if(t===!0){e.setAttribute(n,"");return}try{e[n]=t,e.getAttribute(n)!==String(t)&&e.setAttribute(n,String(t))}catch{e.setAttribute(n,String(t))}}function S(e,n,t){let r=n?.browser??t;if(!r)throw new Error("[vdom] renderValue requires browser env (ctx.browser)");if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number")return r.createTextNode(String(e));if(Array.isArray(e)){let u=r.createDocumentFragment();if(!u)return null;for(let d of e){let a=S(d,n,r);a!=null&&u.appendChild(a)}return u}let o=e;if(o.type===H){let u=r.bodyElement();if(!u)return null;let d=u.querySelector("#__wf_portal");d||(d=r.createElement("div"),d&&(d.id="__wf_portal",u.appendChild(d)));let a=r.createElement("div");if(a){a.setAttribute("data-portal",String(o.props?.portalKey??"wf"));let c=S(o.props?.children??null,n,r);c!=null&&a.appendChild(c),d&&d.appendChild(a),o._remoteEl=a}return null}if(o.type===L){let u=r.createDocumentFragment();if(!u)return null;for(let d of F(o.props?.children)){let a=S(d,n,r);a!=null&&u.appendChild(a)}return o._childNodes=Array.from(u.childNodes),u}if(typeof o.type=="function"){if(typeof o._render!="function")throw new Error(`[vdom] component ${o.type.name||"anonymous"} not built (missing _render) \u2014 buildVNode must run before renderValue`);if(o._child===void 0)throw new Error(`[vdom] component ${o.type.name||"anonymous"} not built (missing _child) \u2014 buildVNode must run before renderValue`);let u=o._child;if(u==null)return o._child=null,null;let d=(Array.isArray(u)||typeof u=="object"&&typeof u.type=="function",u);o._child=d,typeof d=="object"&&!Array.isArray(d)&&(d._parentVNode=o);let a=S(d,n,r);return a&&(o._refNode=a),a}let s=o.type,i=Ee.has(s)?r.createElementNS("http://www.w3.org/2000/svg",s):r.createElement(s);if(!i)return null;o.el=i;let l;for(let[u,d]of Object.entries(o.props??{}))if(!(u==="children"||u==="key")){if(u==="value"&&i instanceof HTMLSelectElement){l=d;continue}Y(i,u,d)}if(!("innerHTML"in(o.props??{})))for(let u of F(o.props?.children)){let d=S(u,n,r);if(d!=null&&(i.appendChild(d),u&&typeof u=="object"&&!Array.isArray(u)&&typeof u.type=="function")){let a=u;a._parentNode||(a._parentNode=i,a._refNode=d)}}return l!==void 0&&(i.value=String(l)),i}var Pn=0;function Te(){return{idRegistry:new Map,unmountHooks:[],nextId:()=>`_wf_${Pn++}`}}function Ne(e,n){return e.unmountHooks.push(n),()=>{let t=e.unmountHooks.indexOf(n);t>=0&&e.unmountHooks.splice(t,1)}}function oe(e,n){for(let t of[...e.unmountHooks])t(n);e.idRegistry.delete(n),e.idRegistry.delete(`custom:${n}`)}function Vn(e,n,t,r){try{e(n)}catch(o){console.error(`[weifuwu] ref ${t} error in <${r??"anonymous"}>`,o)}}function R(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 r=[...n.unmountHooks];for(let o of r)o(t._id);if(t._customId)for(let o of r)o(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 r of t._child)r&&typeof r=="object"&&R(r,n);else R(t._child,n);t._child=void 0}if(t.props?.children&&typeof t.type=="string"){let r=Array.isArray(t.props.children)?t.props.children:[t.props.children];for(let o of r)o&&typeof o=="object"&&R(o,n)}if(typeof t.props?.ref=="function"&&Vn(t.props.ref,null,"cleanup"),t._remoteEl){let r=t._child;if(r!=null)if(Array.isArray(r))for(let o of r)o&&typeof o=="object"&&R(o,n);else typeof r=="object"&&R(r,n);t._remoteEl.remove(),t._remoteEl=void 0}}function ie(e,n){if(n&&typeof e.type=="function"&&e._id){try{R(e,n)}catch(t){console.error("[weifuwu] ref cleanup error",t)}oe(n,e._id)}}function X(e){if(e==null||typeof e!="object"||Array.isArray(e))return;let n=e;return n._placement==="remote"?n.props?.portalKey:n.key}function Pe(e,n){if(n&&e&&typeof e=="object"&&!Array.isArray(e)&&e.type===L){let t=e._childNodes;if(t&&t.length)return t}return[n]}function O(e,n,t,r,o){if(typeof r=="string"||typeof r=="number"){if(typeof t=="string"||typeof t=="number"){if(String(t)!==String(r)){if(n&&n.nodeType===3)return n.nodeValue=String(r),n;let c=e.ownerDocument.createTextNode(String(r));return n?.parentNode?n.parentNode.replaceChild(c,n):e.appendChild(c),c}return n}let a=e.ownerDocument.createTextNode(String(r));return n?.parentNode?n.parentNode.replaceChild(a,n):e.appendChild(a),a}if(r==null||typeof r=="boolean"){if(t&&typeof t=="object"&&!Array.isArray(t)&&t.type===H){let a=t._remoteEl;try{R(t.props?.children,o.registry)}catch(c){console.error("[weifuwu] portal ref cleanup error",c)}return a?.parentNode?.removeChild(a),null}if(t&&typeof t=="object"&&!Array.isArray(t))if(typeof t.type=="function")ie(t,o.registry);else try{R(t,o.registry)}catch(a){console.error("[weifuwu] ref cleanup error",a)}return n?.parentNode&&n.parentNode.removeChild(n),null}if(Array.isArray(r)){if(t===r&&n?.parentNode)return n;let a=e.ownerDocument.createDocumentFragment(),c=se(e,t,r,o,n?[n]:void 0);for(let p of c)p&&a.appendChild(p);return n?.parentNode?a.contains(n)?e.appendChild(a):n.parentNode.replaceChild(a,n):e.appendChild(a),a}let s=r;if(s.type===H){let a=t&&typeof t=="object"&&!Array.isArray(t)?t:null;if(a?.type===H){let c=a._remoteEl;if(c){let p=a.props?.children??null,w=s.props?.children??null;se(c,p,w,o)}return s._remoteEl=a._remoteEl,null}return S(s,o,o.browser??_()),null}if(s.type===L){let a=t&&typeof t=="object"&&!Array.isArray(t)?t:null,c=a?._childNodes,p=se(e,a?.props?.children??t,s.props?.children??null,o,c);return s._childNodes=p.filter(Boolean),n?.parentNode&&n.nodeType===8&&n.parentNode.removeChild(n),n&&n.nodeType===1?n:p[0]??null}if(typeof s.type=="function"){if(typeof s._render!="function")throw new Error(`[vdom] component ${s.type.name||"anonymous"} not built in diff \u2014 buildVNode must run before patchValue`);let a=t&&typeof t=="object"&&!Array.isArray(t)?t:null,c=a?.type===s.type;if(!o.force&&a&&c&&a._child!==void 0&&s._child===a._child)return n;a?.type===s.type&&a._id&&(s._id=a._id,o.registry.idRegistry.set(s._id,s)),s._parentNode=e,n&&(s._refNode=n);let p;if(s._child===void 0)throw new Error(`[vdom] component ${s.type.name||"anonymous"} not built (missing _child) \u2014 buildVNode must run before patchValue`);p=s._child;let w=O(e,n,a?._child,p,o);return w&&(s._refNode=w),w}let i=t&&typeof t=="object"&&!Array.isArray(t)?t:null,l=i?.type??null,u=s.type;if(n&&n.nodeType===1&&l===u){let a=n;return s.el=a,_n(a,i?.props??{},s.props??{}),se(a,i?.props?.children??null,s.props?.children??null,o),a}let d=S(s,o,o.browser??_());if(d==null)return null;if(n?.parentNode)if(t!=null&&typeof t!="boolean"){if(typeof t=="object"&&!Array.isArray(t))try{R(t,o.registry)}catch(a){console.error("[weifuwu] ref cleanup error",a)}n.parentNode.replaceChild(d,n)}else n.parentNode.insertBefore(d,n);else e.appendChild(d);return d}function _n(e,n,t){let r=Object.keys(n),o=Object.keys(t);if(r.length===o.length){let i=!0;for(let l=0;l<r.length;l++)if(r[l]!==o[l]||n[r[l]]!==t[r[l]]){i=!1;break}if(i)return}let s=new Set([...r,...o]);for(let i of s){if(i==="children"||i==="key")continue;let l=n[i],u=t[i];if(l!==u){if(re.test(i)){typeof l=="function"&&e.removeEventListener(i.slice(2).toLowerCase(),l),u!=null&&u!==!1&&(typeof u!="function"?console.warn(`[weifuwu] event prop ${i} expects a function, got ${typeof u} \u2014 ignored`):e.addEventListener(i.slice(2).toLowerCase(),u));continue}if(u==null||u===!1){if(i==="class"||i==="className")e.removeAttribute("class");else if(re.test(i))e.removeEventListener(i.slice(2).toLowerCase(),l);else if(i==="ref"){if(typeof l=="function")try{l(null)}catch(d){console.error("[weifuwu] ref cleanup error",d)}}else if(i==="value")e.value="";else if(i==="indeterminate")e.indeterminate=!1;else{e.removeAttribute(i);try{delete e[i]}catch{}}continue}Y(e,i,u)}}}function se(e,n,t,r,o){let s=F(n),i=F(t),l=o??Array.from(e.childNodes);if(i.some(m=>{if(m==null||typeof m!="object"||Array.isArray(m))return!1;let g=m;return g._placement!=="remote"&&g.key!==void 0})){for(let m=0;m<i.length;m++){let g=i[m];g&&typeof g=="object"&&!Array.isArray(g)&&X(g)===void 0&&(g.key=`pos:${m}`)}for(let m=0;m<s.length;m++){let g=s[m];g&&typeof g=="object"&&!Array.isArray(g)&&X(g)===void 0&&(g.key=`pos:${m}`)}}let d=s.map((m,g)=>{if(m==null||typeof m!="object"||Array.isArray(m))return l[g]??null;let y=m;return y._placement==="remote"?y._remoteEl??null:y.type===L?y._childNodes?.[0]??null:y._refNode??y.el??null});if(!i.some(m=>{if(m==null||typeof m!="object"||Array.isArray(m))return!1;let g=m;return g._placement!=="remote"&&g.key!==void 0})){let m=Math.max(s.length,i.length),g=[];for(let y=0;y<m;y++){let f=y<s.length?s[y]:null,h=y<i.length?i[y]:null;if(h==null||typeof h=="boolean"){if(f&&typeof f=="object"&&!Array.isArray(f))if(typeof f.type=="function")ie(f,r.registry);else try{R(f,r.registry)}catch(C){console.error("[weifuwu] ref cleanup error",C)}let P=d[y];P?.parentNode&&P.parentNode.removeChild(P),g.push(null);continue}if(f!=null&&typeof f=="object"&&!Array.isArray(f)&&h!=null&&typeof h=="object"&&!Array.isArray(h)&&h===f){g.push(d[y]);continue}if(f==null||typeof f=="boolean"){let P=S(h,r,r.browser??_());if(P==null){g.push(null);continue}let C=null;for(let T=y+1;T<d.length;T++){let E=d[T];if(E&&E.parentNode===e){C=E;break}}if(!C){let T=null;for(let E=g.length-1;E>=0;E--)if(g[E]){T=g[E];break}if(T&&T.parentNode===e&&(C=T.nextSibling),!C){let E=d[d.length-1];E&&E.parentNode===e&&(C=E.nextSibling)}}C&&C.parentNode===e?e.insertBefore(P,C):e.appendChild(P),g.push(P);continue}let x=O(e,d[y],f,h,r);g.push(...Pe(h,x))}return g}let c=new Map;s.forEach((m,g)=>{let y=X(m);y!==void 0&&m&&typeof m=="object"&&!Array.isArray(m)&&c.set(y,{vnode:m,nodes:[d[g]??null].filter(Boolean),index:g})});let p=[],w=new Set,b=null;return i.forEach((m,g)=>{let y=X(m),f=m;if(y!==void 0&&c.has(y)){let h=c.get(y),x=h.nodes[0]??null;w.add(y);let P=O(e,x,h.vnode,f,r),C=Pe(f,P),T=C[C.length-1]??P;T&&T.parentNode===e&&b&&T.previousSibling!==b&&e.insertBefore(T,b.nextSibling),p.push(...C),T&&(b=T)}else if(f?._placement==="remote"){let h=s[g]??null,x=O(e,d[g]??null,h,f,r),P=Pe(f,x);p.push(...P);let C=P[P.length-1]??x;C&&(b=C)}else{let h=S(f,r,r.browser??_());p.push(h),h!=null&&(b?e.insertBefore(h,b.nextSibling):e.insertBefore(h,e.firstChild),b=h)}}),s.forEach((m,g)=>{let y=X(m),f=m&&typeof m=="object"&&!Array.isArray(m)&&typeof m.type=="function";if(y!==void 0&&!w.has(y)){if(m&&typeof m=="object"&&!Array.isArray(m))if(f)ie(m,r.registry);else try{R(m,r.registry)}catch(x){console.error("[weifuwu] ref cleanup error",x)}let h=d[g];h?.parentNode&&h.parentNode.removeChild(h)}else if(y===void 0){if(m&&typeof m=="object"&&!Array.isArray(m))if(f)ie(m,r.registry);else try{R(m,r.registry)}catch(x){console.error("[weifuwu] ref cleanup error",x)}let h=d[g];h?.parentNode&&h.parentNode.removeChild(h)}}),p}var Xe=_();function Je(e,n="bottom",t=6,r=!0){switch(n){case"bottom":return{top:e.bottom+t,left:r?e.left+e.width/2:e.left};case"top":return{top:e.top-t,left:r?e.left+e.width/2:e.left};case"left":return{top:r?e.top+e.height/2:e.top,left:e.left-t};case"right":return{top:r?e.top+e.height/2:e.top,left:e.right+t}}}function ae(e,n,t=8){if(!n)return e;let r=n.getBoundingClientRect();if(r.width===0&&r.height===0)return e;let o=Number.parseFloat(n.style.top)||r.top,s=Number.parseFloat(n.style.left)||r.left,i=e.top-o,l=e.left-s,u={top:r.top+i,bottom:r.bottom+i,left:r.left+l,right:r.right+l},d=Xe.viewportWidth(),a=Xe.viewportHeight(),c=e.top,p=e.left;return u.bottom>a-t&&(c=Math.max(t,c-(u.bottom-(a-t)))),u.top<t&&(c=Math.max(t,c+(t-u.top))),u.right>d-t&&(p=Math.max(t,p-(u.right-(d-t)))),u.left<t&&(p=Math.max(t,p+(t-u.left))),{top:c,left:p,width:e.width}}var K=_();function Qe(e){let n=new Map,t=new Map,r=!1,o=0;function s(){o||(o=requestAnimationFrame(()=>{o=0;let a=[];for(let[c,p]of n){if(!p.isOpen())continue;let w=p.getEl();if(!w)continue;let b=w.getBoundingClientRect();if(b.width===0&&b.height===0)continue;let m=p.compute(b);Object.assign(p.pos,ae(m,p.panel?.(),p.margin)),a.push(c)}for(let[c,p]of t){let w=p.getScroller(),b=w instanceof Window?K.scrollingElement()?.scrollTop??K.scrollTop():w.scrollTop??0;b!==p.handle.y&&(p.handle.y=b,a.push(c))}a.length>0&&e(a)}))}function i(){r||(r=!0,K.addEventListener("scroll",s,{capture:!0,passive:!0}),K.addEventListener("resize",s))}function l(){r&&(K.removeEventListener("scroll",s,{capture:!0}),K.removeEventListener("resize",s),r=!1)}function u(a){for(let c of[...n.keys()])(c.startsWith(`popup:${a}:`)||c===`popup:${a}`||c===a)&&n.delete(c);t.delete(a)}function d(){l(),o&&(cancelAnimationFrame(o),o=0),n.clear(),t.clear()}return{popupTrackers:n,scrollTrackers:t,schedulePopupRecompute:s,ensurePopupListeners:i,destroyPopupListeners:l,cleanupTrackers:u,destroy:d}}function Ve(e,n,t){return o=>{o?n(o):t?.()}}function J(e){return typeof window<"u"&&!!window.matchMedia?.("(hover: hover)").matches}function le(e){return typeof window<"u"&&!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches}function _e(e,n,t){let r=null,o=()=>{n(),t?.once&&r&&r.removeEventListener("animationend",o)};return i=>{i?(r=i,i.addEventListener("animationend",o)):r&&(r.removeEventListener("animationend",o),r=null)}}function ke(e,n){let{onLongPress:t,duration:r=500}=n,o,s=0,i=0,l=null,u=()=>{clearTimeout(o),o=void 0},d=e.selfId();if(d){let a=e.onUnmount(c=>{c===d&&(u(),a())})}return{onPointerDown:a=>{s=a.clientX??0,i=a.clientY??0,l=a,u(),o=setTimeout(()=>{o=void 0,l&&t(l)},r)},onPointerUp:u,onPointerLeave:u,onPointerMove:a=>{let c=Math.abs((a.clientX??0)-s),p=Math.abs((a.clientY??0)-i);(c>10||p>10)&&u()},onContextMenu:a=>{a.preventDefault(),t(a)}}}function Q(e,n){let t=e.selfId(),r="closed",o,s=()=>{r="closed",t?e.render([t]):e.render()};return{get phase(){return r},ref:l=>{l?o||(o=()=>{r==="exit"&&s()},l.addEventListener("animationend",o)):o=void 0},sync:l=>(l?r="open":r==="open"&&(r="exit"),r)}}function Se(e,n,t){let r=e.selfId(),o=le(e),s=t?.duration??400,i=t?.ease==="linear"?p=>p:p=>1-Math.pow(1-p,3),l,u=n,d={value:o?n:0,reset:()=>{}},a=()=>{r?e.render([r]):e.render()},c=p=>{if(u=p,o){d.value=p,a();return}if(p===d.value)return;l&&cancelAnimationFrame(l);let w=d.value,b=performance.now(),m=g=>{let y=Math.min(1,(g-b)/s);d.value=Math.round(w+(p-w)*i(y)),y<1?(l=requestAnimationFrame(m),a()):(l=void 0,a())};l=requestAnimationFrame(m)};if(d.reset=p=>{p===u&&l||c(p)},r){let p=e.onUnmount(w=>{w===r&&(l&&(cancelAnimationFrame(l),l=void 0),p())})}return queueMicrotask(()=>c(n)),d}function Re(e,n,t){let r=e.selfId(),o=e.browser,s=`media:${r}:${n}`;if(!e.mediaRegistry.has(s)){let i=o.matchMedia(n);t(i.matches);let l=d=>t(d.matches);i.addEventListener("change",l),e.mediaRegistry.set(s,{mql:i,handler:l});let u=e.onUnmount(d=>{if(d!==r)return;let a=e.mediaRegistry.get(s);if(a?.mql&&a.handler)try{a.mql.removeEventListener("change",a.handler)}catch{}e.mediaRegistry.delete(s),u()})}}function Ae(e,n,t){let r=e.browser,o=typeof n=="function"?{mobile:"(max-width: 639px)",tablet:"(min-width: 640px) and (max-width: 1023px)",desktop:"(min-width: 1024px)"}:n,s=typeof n=="function"?n:t,i=e.selfId(),l=`bp:${i}`;function u(){for(let[d,a]of Object.entries(o))if(r.matchMedia(a).matches)return d;return Object.keys(o)[0]??""}if(!e.mediaRegistry.has(l)){s(u());let d=[];for(let c of Object.values(o)){let p=r.matchMedia(c),w=()=>s(u());p.addEventListener("change",w),d.push({mql:p,handler:w})}e.mediaRegistry.set(l,{mqls:d});let a=e.onUnmount(c=>{if(c!==i)return;let p=e.mediaRegistry.get(l);if(p?.mqls)for(let w of p.mqls)try{w.mql.removeEventListener("change",w.handler)}catch{}e.mediaRegistry.delete(l),a()})}}function Me(e){let n=e.selfId(),t=e.browser,r={height:t.viewportHeight(),offsetTop:0,keyboardOpen:!1},o=()=>{n?e.render([n]):e.render()},s=()=>{let l=t.visualViewport();r.height=l?.height??t.viewportHeight(),r.offsetTop=l?.offsetTop??0,r.keyboardOpen=r.height<t.viewportHeight()*.9,o()},i=t.visualViewport();if(i?.addEventListener?(i.addEventListener("resize",s),i.addEventListener("scroll",s)):t.addEventListener("resize",s),n){let l=e.onUnmount(u=>{u===n&&(i?.removeEventListener?(i.removeEventListener("resize",s),i.removeEventListener("scroll",s)):t.removeEventListener("resize",s),l())})}return r}function Le(e,n){let t=e.selfId(),r={isIn:!1,ready:!1,observe:u,refresh:d,disconnect:a},o=null,s=null,i=()=>{t?e.render([t]):e.render()};function l(){if(s?.disconnect(),s=null,!o)return;let c=typeof n.rootMargin=="function"?n.rootMargin():n.rootMargin,p=typeof n.threshold=="function"?n.threshold():n.threshold;s=new IntersectionObserver(w=>{let b=w[w.length-1];if(!b)return;let m=b.isIntersecting,g=m!==r.isIn,y=!r.ready;r.isIn=m,r.ready=!0,n.onChange?.(b,m),(g||y)&&i()},{root:n.root?n.root():null,rootMargin:c??"0px",threshold:p??0}),s.observe(o)}function u(c){o=c,c?l():(s?.disconnect(),s=null,r.isIn=!1)}function d(){l()}function a(){s?.disconnect(),s=null}if(t){let c=e.onUnmount(p=>{p===t&&(a(),c())})}return r}function He(e,n){let t=e.selfId(),r=e.browser,o={y:0,refresh(){let l=s.getScroller();o.y=l instanceof Window?r.scrollingElement()?.scrollTop??r.scrollTop():l.scrollTop??0}},s={handle:o,getScroller:n.getScroller??(()=>window)};if(!t)return o.refresh(),o;e.scrollTrackers.set(t,s),e.ensurePopupListeners(),o.refresh();let i=e.onUnmount(l=>{l===t&&(e.scrollTrackers.delete(t),i())});return o}function ue(e,n){let t=e.selfId(),r=n.value!==void 0;if(r&&!n.onChange&&n.name&&(e.warned.has(n.name)||(e.warned.add(n.name),console.warn(`[weifuwu/${n.name}] \u53D7\u63A7\u6A21\u5F0F\uFF08value \u5DF2\u4F20\uFF09\u4F46\u672A\u63D0\u4F9B onChange\uFF0C\u4EA4\u4E92\u65E0\u6CD5\u751F\u6548\u3002
|
|
2
|
-
\u975E\u53D7\u63A7\uFF1A\u53BB\u6389 value\uFF1B\u53D7\u63A7\uFF1A\u4F20\u5165 onChange={(v) => setValue(v)}`))),!
|
|
3
|
-
\u975E\u53D7\u63A7\uFF1A\u53BB\u6389 open\uFF1B\u53D7\u63A7\uFF1A\u4F20\u5165 onOpenChange={(o) => setOpen(o)}`));let
|
|
1
|
+
function Nn(e){let n=[],t=(e||"/").replace(/:(\w+)/g,(o,r)=>(n.push(r),"([^/]+)")).replace(/\*/g,".*");return{re:new RegExp(`^${t}$`),keys:n}}var ke=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,s=async(a,l,d)=>{let c=l.__routePath??o.getPath(),i=null;return c===r?i="/":(r==="/"?c!=="/"&&c.startsWith("/"):c.startsWith(r+"/"))&&(i=c.slice(r.length)),i===null?d:async(u,p)=>{let g=await t._handle(i,u,p);return g===null?d(u,p):g}};return this._middlewares.push(s),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:s}=Nn(o.path),a=n.match(r);if(!a)continue;let l={};for(let d=0;d<s.length;d++)l[s[d]]=decodeURIComponent(a[d+1]);t={handler:o.handler,params:l,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 a=r.handler,l=o.__routePath;o.__routePath=n;try{for(let d=this._middlewares.length-1;d>=0;d--){let c=this._middlewares[d],i=a;a=await c(t,o,i)??i}return await a(t,o)}finally{o.__routePath=l}}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 a=r.handler;for(let l=this._middlewares.length-1;l>=0;l--){let d=this._middlewares[l],c=a;a=await d(n,t,c)??c}return await a(n,t)}};var S=Symbol("Fragment"),R=Symbol("Portal");function Pe(e,n,t){return{type:e,props:on(n),key:t??void 0}}var Vn=Pe;function _n(e,n,t){return Pe(e,n,t)}function F(e,n,...t){let o=on(n??{});return t.length>0&&(o.children=t.length===1?t[0]:t),{type:e,props:o,key:n?.key??void 0}}function on(e){if(!e)return{};let n={};for(let t of Object.keys(e))t!=="key"&&(n[t]=e[t]);return n}function j(e){if(e==null||typeof e=="boolean")return[];if(Array.isArray(e)){let n=!1;for(let r=0;r<e.length;r++)if(Array.isArray(e[r])){n=!0;break}if(!n)return e;let t=[],o=[...e].reverse();for(;o.length>0;){let r=o.pop();if(Array.isArray(r))for(let s=r.length-1;s>=0;s--)o.push(r[s]);else t.push(r)}return t}return[e]}function fe(e,n){return{type:R,props:{children:e,portalKey:n},key:n??void 0,_placement:"remote"}}function A(){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{}}}}function kn(e,n,t=400){let o=!1,r=()=>{o||(o=!0,e.removeEventListener("animationend",r),clearTimeout(s),n())};e.addEventListener("animationend",r);let s=setTimeout(r,t)}function Y(e,n){return Object.assign(Object.create(e),n)}function Pn(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 s(a,l,d,c){let i=n.baseURL+l,u={method:a,headers:{...n.headers,...c?.headers}},p=e?.token?.();p&&!u.headers.Authorization&&(u.headers.Authorization=`Bearer ${p}`);let g=r>0,h=!!c?.signal,w=null,x=null;(g||h)&&(w=new AbortController,u.signal=w.signal,g&&(x=setTimeout(()=>w.abort(new Error("Request timed out")),r)),h&&c.signal.addEventListener("abort",()=>w.abort())),d!==void 0&&a!=="GET"&&a!=="HEAD"&&(u.body=JSON.stringify(d));let y={url:i,init:u};t&&(y=t(y));try{let f=await fetch(y.url,y.init);if(o)return o(f);if(!f.ok){let _=await f.text().catch(()=>"");throw new Ae(f.status,_||f.statusText)}let m=f.headers.get("content-length");if(f.status===204||m==="0")return;let T=(f.headers.get("content-type")||"").toLowerCase();return T.includes("application/json")||T.includes("json")?f.json():f.text()}finally{x&&clearTimeout(x)}}return a=>Y(a,{api:{get:(d,c)=>s("GET",d,void 0,c),post:(d,c,i)=>s("POST",d,c,i),put:(d,c,i)=>s("PUT",d,c,i),patch:(d,c,i)=>s("PATCH",d,c,i),delete:(d,c)=>s("DELETE",d,void 0,c)}})}var Ae=class extends Error{status;body;constructor(n,t){super(`API Error ${n}: ${t}`),this.name="ApiError",this.status=n,this.body=t}};function An(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 Sn(e){let n=An(e);return n?.exp?n.exp*1e3-3e4<Date.now():!0}function Rn(e){let n=e?.storage??localStorage,t=e?.tokenKey??"weifuwu_token",o=e?.userKey??"weifuwu_user",r=e?.refreshTokenKey??"weifuwu_refresh",s=e?.refreshEndpoint??"/api/auth/refresh";return a=>{let l=n.getItem(t),d=n.getItem(o),c={token:l,user:d?JSON.parse(d):null,get isLoggedIn(){return this.token!==null},login(i,u,p){c.token=i,c.user=u,n.setItem(t,i),n.setItem(o,JSON.stringify(u)),p&&n.setItem(r,p)},logout(){c.token=null,c.user=null,n.removeItem(t),n.removeItem(o),n.removeItem(r)},setUser(i){c.user=i,n.setItem(o,JSON.stringify(i))},async refresh(){let i=n.getItem(r);if(!i)return!1;try{let u=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:i})});if(!u.ok)return c.logout(),!1;let p=await u.json();return c.token=p.token,n.setItem(t,p.token),p.refreshToken&&n.setItem(r,p.refreshToken),!0}catch{return!1}}};return l&&Sn(l)&&c.refresh().catch(()=>{}),Y(a,{auth:c})}}function Mn(e={}){let n=e.url??"/ws",t=e.reconnectInterval??3e3,o=e.maxReconnect??10,r=e.pingInterval??3e4,s=e.pingTimeout??1e4;return a=>{let l=new Set,d=null,c=0,i=null,u=null,p=null,g=!1,h={isConnected:!1,onMessage:m=>(l.add(m),()=>{l.delete(m)}),send:m=>{d?.readyState===WebSocket.OPEN&&d.send(JSON.stringify(m))},_connect:w,close:()=>{g=!0,f(),d?.close(),d=null,h.isConnected=!1}};async function w(){if(!g)try{d=new WebSocket(n),d.onopen=()=>{h.isConnected=!0,c=0,x()},d.onmessage=m=>{try{let T=JSON.parse(m.data);for(let _ of l)_(T)}catch{}y()},d.onclose=()=>{h.isConnected=!1,f(),!g&&c<o&&(c++,i=setTimeout(w,t*Math.min(c,5)))},d.onerror=()=>{d?.close()}}catch{g||(i=setTimeout(w,t))}}function x(){r<=0||(u=setInterval(()=>{d?.readyState===WebSocket.OPEN&&d.send(JSON.stringify({type:"ping"})),p=setTimeout(()=>{d?.close()},s)},r))}function y(){clearTimeout(p)}function f(){clearInterval(u),clearTimeout(p),clearTimeout(i)}return w(),Y(a,{ws:h})}}function Ln(e,n){if(e===n)return!0;let t=Object.keys(e),o=Object.keys(n);if(t.length!==o.length)return!1;for(let r of t)if(e[r]!==n[r])return!1;return!0}async function rn(e,n,t,o){e._id||(o?.reuse?._id?e._id=o.reuse._id:e._id=t.nextId(),t.idRegistry.set(e._id,e)),o?.reuse&&(o.reuse._parentNode&&(e._parentNode=o.reuse._parentNode),o.reuse._refNode&&(e._refNode=o.reuse._refNode),o.reuse._ctxVersion!=null&&(e._ctxVersion=o.reuse._ctxVersion));let r=Object.create(n);r.ui=Object.create(n.ui);let s=r.ui;if(s._selfId=e._id,s._selfVNode=e,s.render=function(a){return a==null&&e._id?n.ui.render([e._id]):n.ui.render(a)},typeof e._render!="function"&&typeof o?.reuse?._render=="function"&&(e._render=o.reuse._render),typeof e._render!="function"){n.ui?.setMounting?.(!0);let a;try{a=await e.type(e.props??{},r)}finally{n.ui?.endMounting?.()}if(typeof a!="function")throw new Error(`Component ${e.type.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);e._render=a}return{renderFn:e._render,childCtx:r}}function Se(e){return!!e&&typeof e.then=="function"}function D(e,n,t,o,r){if(e==null||typeof e=="boolean"||typeof e=="string"||typeof e=="number")return e;if(Array.isArray(e)){let d=Array.isArray(t)?t:[];for(let u=0;u<e.length;u++){let p=e[u];if(p!=null&&typeof p=="object"&&!Array.isArray(p)){let g=p;g.key===void 0?g.key=String(u):g.key=String(g.key)}}let c=e.map((u,p)=>D(u,n,d[p],o,r)),i=!1;for(let u=0;u<c.length;u++)if(Se(c[u])){i=!0;break}return i?Promise.all(c).then(()=>e):e}let s=e,a=o??n.__registry,l=t!=null&&typeof t=="object"&&!Array.isArray(t)&&t.type===s.type?t:null;if(typeof s.type=="function"){s._id||(s._id=l?._id??a.nextId(),a.idRegistry.set(s._id,s)),l&&(l._parentNode&&(s._parentNode=l._parentNode),l._refNode&&(s._refNode=l._refNode),l._ctxVersion!=null&&(s._ctxVersion=l._ctxVersion),typeof l._render=="function"&&(s._render=l._render));let d=Ln(l?.props??{},s.props??{}),c=n?.ui?._ctxVersion??0,i=(l?._ctxVersion??-1)===c;return!r?.force&&d&&i&&l?._child!=null?(s._child=l._child,s._ctxVersion=l._ctxVersion,s):(async()=>{let{childCtx:u}=await rn(s,n,a,{reuse:l??void 0}),p=await D(await s._render(s.props),u,l?._child,a);return s._child=p??null,s._ctxVersion=c,s})()}if(s.type===S){let d=D(s.props?.children??null,n,l?._child??l?.props?.children,a);return Se(d)?d.then(c=>(s._child=c??null,s)):(s._child=d??null,s)}if(typeof s.type=="string"||typeof s.type=="symbol"){let d=D(s.props?.children??null,n,l?.props?.children,a);return Se(d)?d.then(c=>(s._child=c??null,s)):(s._child=d??null,s)}return s}function B(e){if(e===!1)return"false";if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0)return"true";if(typeof e=="object")try{let n=JSON.stringify(e);return`object ${n!=null&&n.length>80?n.slice(0,80)+"\u2026":n??""}`}catch{return`object ${Object.prototype.toString.call(e)}`}return`bad-vnode type=${typeof e}`}function pe(e){return typeof e!="string"&&typeof e!="function"&&e!==S&&e!==R}function sn(e){for(let n=0;n<e.length;n++){let t=e[n];if(t!=null&&typeof t=="object"&&!Array.isArray(t)){let o=t;o.key===void 0?o.key=String(n):o.key=String(o.key)}}}var J=/^on[A-Z]/,Hn=/^on[A-Z].*Capture$/;function te(e){let n=Hn.test(e);return{type:(n?e.slice(2,-7):e.slice(2)).toLowerCase(),capture:n}}var oe=new Set(["draggable","contenteditable","spellcheck","translate"]),an=new Set(["zIndex","opacity","lineHeight","fontWeight","fontSizeAdjust","flex","flexGrow","flexShrink","order","zoom","aspectRatio","gridRow","gridColumn","scale","rotate","animationIterationCount","columnCount","fillOpacity","strokeOpacity","stopOpacity","floodOpacity"]);var Re=new Set(["svg","path","circle","rect","line","polyline","polygon","g","text","defs","use","clipPath"]);function X(e,n,t){if(t==null)return;let o=e.ownerDocument?.defaultView;if(oe.has(n)){e.setAttribute(n,t?"true":"false");return}if(t!==!1){if(n==="class"||n==="className"){if(typeof t=="object")for(let[r,s]of Object.entries(t))s&&e.classList.add(r);else e.setAttribute("class",String(t));return}if(n==="style"){if(typeof t=="string")e.setAttribute("style",t);else{let r=e.style;for(let[s,a]of Object.entries(t))a==null?r[s]="":s.startsWith("--")?r.setProperty(s,String(a)):typeof a=="number"&&!an.has(s)?r[s]=`${a}px`:r[s]=String(a)}return}if(n==="ref"){if(typeof t=="function")try{t(e)}catch(r){console.error("[weifuwu] ref error",r)}return}if(J.test(n)){let{type:r,capture:s}=te(n);if(typeof t!="function"){console.warn(`[weifuwu] event prop ${n} expects a function, got ${typeof t} \u2014 ignored`);return}e.addEventListener(r,t,s?{capture:!0}:void 0);return}if(n==="value"){e.value=t;return}if(n==="indeterminate"){e.indeterminate=!!t;return}if(n==="innerHTML"){e.innerHTML=String(t??"");return}if(n.startsWith("aria-")&&typeof t=="boolean"){e.setAttribute(n,t?"true":"false");return}if(t===!0){e.setAttribute(n,"");return}try{e[n]=t,e.getAttribute(n)!==String(t)&&e.setAttribute(n,String(t))}catch{e.setAttribute(n,String(t))}}}function K(e,n){return e.createComment(`wf-hole: ${B(n)}`)}function U(e,n,t){let o=n?.browser??t;if(!o)throw new Error("[vdom] renderValue requires browser env (ctx.browser)");if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number")return o.createTextNode(String(e));if(Array.isArray(e)){let c=o.createDocumentFragment();if(!c)return null;for(let i of e){let u=i==null||typeof i=="boolean"?K(o,i):U(i,n,o);u!=null&&c.appendChild(u)}return c}let r=e,s=r.type;if(typeof s!="string"&&typeof s!="function"&&s!==S&&s!==R)return console.warn(`[weifuwu] children \u9879\u975E\u6CD5\uFF1Atype=${String(s)}\uFF08${typeof s}\uFF09\uFF0C\u503C=${B(e)}\u2014\u2014\u5DF2\u5360\u4F4D\uFF08wf-hole\uFF09\uFF0C\u68C0\u67E5\u4F20\u5165\u7684 children`),K(o,e);if(r.type===R){let c=o.bodyElement();if(!c)return null;let i=c.querySelector("#__wf_portal");i||(i=o.createElement("div"),i&&(i.id="__wf_portal",c.appendChild(i)));let u=o.createElement("div");if(u){u.setAttribute("data-portal",String(r.props?.portalKey??"wf"));let p=U(r.props?.children??null,n,o);p!=null&&u.appendChild(p),i&&i.appendChild(u),r._remoteEl=u}return null}if(r.type===S){let c=o.createDocumentFragment();if(!c)return null;for(let i of j(r.props?.children)){let u=i==null||typeof i=="boolean"?K(o,i):U(i,n,o);u!=null&&c.appendChild(u)}return r._childNodes=Array.from(c.childNodes),c}if(typeof r.type=="function"){if(typeof r._render!="function")throw new Error(`[vdom] component ${r.type.name||"anonymous"} not built (missing _render) \u2014 buildVNode must run before renderValue`);if(r._child===void 0)throw new Error(`[vdom] component ${r.type.name||"anonymous"} not built (missing _child) \u2014 buildVNode must run before renderValue`);let c=r._child;if(c==null)return r._child=null,null;let i=(Array.isArray(c)||typeof c=="object"&&typeof c.type=="function",c);r._child=i,typeof i=="object"&&!Array.isArray(i)&&(i._parentVNode=r);let u=U(i,n,o);if(u){if(r._refNode=u,r._id)if(u.nodeType===11)for(let p of Array.from(u.childNodes))p.nodeType===1&&p.setAttribute("data-wf-id",r._id);else u.nodeType===1&&u.setAttribute("data-wf-id",r._id);if(r.key!=null)if(u.nodeType===11)for(let p of Array.from(u.childNodes))p.nodeType===1&&p.setAttribute("data-wf-key",r.key);else u.nodeType===1&&u.setAttribute("data-wf-key",r.key)}return u}let a=r.type,l=Re.has(a)?o.createElementNS("http://www.w3.org/2000/svg",a):o.createElement(a);if(!l)return null;r.el=l,r.key!=null&&l.setAttribute("data-wf-key",r.key);let d;for(let[c,i]of Object.entries(r.props??{}))if(!(c==="children"||c==="key")){if(c==="value"&&l instanceof HTMLSelectElement){d=i;continue}X(l,c,i)}if(!("innerHTML"in(r.props??{}))){let c=[];for(let i of j(r.props?.children)){let u=i==null||typeof i=="boolean"?K(o,i):U(i,n,o);if(u==null){c.push(null);continue}if(l.appendChild(u),c.push(u.nodeType===11?u.firstChild:u),i&&typeof i=="object"&&!Array.isArray(i)&&typeof i.type=="function"){let p=i;p._parentNode||(p._parentNode=l,p._refNode=u)}}r._childAnchors=c}return d!==void 0&&(l.value=String(d)),l}var Un=0;function Me(){return{idRegistry:new Map,unmountHooks:[],nextId:()=>`_wf_${Un++}`}}function me(e,n){return e.unmountHooks.push(n),()=>{let t=e.unmountHooks.indexOf(n);t>=0&&e.unmountHooks.splice(t,1)}}function ye(e,n){for(let t of[...e.unmountHooks])t(n);e.idRegistry.delete(n),e.idRegistry.delete(`custom:${n}`)}function In(e,n,t,o){try{e(n)}catch(r){console.error(`[weifuwu] ref ${t} error in <${o??"anonymous"}>`,r)}}function H(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"&&H(o,n);else H(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"&&H(r,n)}if(typeof t.props?.ref=="function"&&In(t.props.ref,null,"cleanup"),t._remoteEl){let o=t._child;if(o!=null)if(Array.isArray(o))for(let r of o)r&&typeof r=="object"&&H(r,n);else typeof o=="object"&&H(o,n);t._remoteEl.remove(),t._remoteEl=void 0}}function se(e,n){if(n&&typeof e.type=="function"&&e._id){try{H(e,n)}catch(t){console.error("[weifuwu] ref cleanup error",t)}ye(n,e._id)}}function re(e){if(e==null||typeof e!="object"||Array.isArray(e))return;let n=e;return n._placement==="remote"?n.props?.portalKey:n.key}function Le(e,n){if(n&&e&&typeof e=="object"&&!Array.isArray(e)&&e.type===S){let t=e._childNodes;if(t&&t.length)return t}return[n]}function $(e,n,t,o,r){if(typeof o=="string"||typeof o=="number"){if(typeof t=="string"||typeof t=="number"){if(String(t)!==String(o)){if(n&&n.nodeType===3)return n.nodeValue=String(o),n;let u=e.ownerDocument.createTextNode(String(o));return n?.parentNode?n.parentNode.replaceChild(u,n):e.appendChild(u),u}return n}let i=e.ownerDocument.createTextNode(String(o));return n?.parentNode?n.parentNode.replaceChild(i,n):e.appendChild(i),i}if(o==null||typeof o=="boolean"){if(t&&typeof t=="object"&&!Array.isArray(t)&&t.type===R){let i=t._remoteEl;try{H(t.props?.children,r.registry)}catch(u){console.error("[weifuwu] portal ref cleanup error",u)}return i?.parentNode?.removeChild(i),null}if(t&&typeof t=="object"&&!Array.isArray(t))if(typeof t.type=="function")se(t,r.registry);else try{H(t,r.registry)}catch(i){console.error("[weifuwu] ref cleanup error",i)}return n?.parentNode&&n.parentNode.removeChild(n),null}if(Array.isArray(o)){if(t===o&&n?.parentNode)return n;let i=e.ownerDocument.createDocumentFragment(),u=ge(e,t,o,r,n?[n]:void 0);for(let p of u)p&&i.appendChild(p);return n?.parentNode?i.contains(n)?e.appendChild(i):n.parentNode.replaceChild(i,n):e.appendChild(i),i}let s=o;if(s.type===R){let i=t&&typeof t=="object"&&!Array.isArray(t)?t:null;if(i?.type===R){let u=i._remoteEl;if(u){let p=i.props?.children??null,g=s.props?.children??null;ge(u,p,g,r)}return s._remoteEl=i._remoteEl,null}return U(s,r,r.browser??A()),null}if(s.type===S){let i=t&&typeof t=="object"&&!Array.isArray(t)?t:null,u=i?._childNodes,p=ge(e,i?.props?.children??t,s.props?.children??null,r,u);return s._childNodes=p.filter(Boolean),n?.parentNode&&n.nodeType===8&&n.parentNode.removeChild(n),n&&n.nodeType===1?n:p[0]??null}if(typeof s.type=="function"){if(typeof s._render!="function")throw new Error(`[vdom] component ${s.type.name||"anonymous"} not built in diff \u2014 buildVNode must run before patchValue`);let i=t&&typeof t=="object"&&!Array.isArray(t)?t:null,u=i?.type===s.type;if(!r.force&&i&&u&&i._child!==void 0&&s._child===i._child)return n;i?.type===s.type&&i._id&&(s._id=i._id,r.registry.idRegistry.set(s._id,s)),s._parentNode=e,n&&(s._refNode=n);let p;if(s._child===void 0)throw new Error(`[vdom] component ${s.type.name||"anonymous"} not built (missing _child) \u2014 buildVNode must run before patchValue`);p=s._child;let g=$(e,n,i?._child,p,r);return g&&(s._refNode=g),g}let a=t&&typeof t=="object"&&!Array.isArray(t)?t:null,l=a?.type??null,d=s.type;if(n&&n.nodeType===1&&l===d){let i=n;if(s.el=i,On(i,a?.props??{},s.props??{}),!("innerHTML"in(s.props??{}))){let u=[];ge(i,a?.props?.children??null,s.props?.children??null,r,void 0,a?._childAnchors,u),s._childAnchors=u}return i}let c=U(s,r,r.browser??A());if(c==null)return null;if(n?.parentNode)if(t!=null&&typeof t!="boolean"){if(typeof t=="object"&&!Array.isArray(t))try{H(t,r.registry)}catch(i){console.error("[weifuwu] ref cleanup error",i)}n.parentNode.replaceChild(c,n)}else n.parentNode.insertBefore(c,n);else e.appendChild(c);return c}function On(e,n,t){let o=Object.keys(n),r=Object.keys(t);if(o.length===r.length){let a=!0;for(let l=0;l<o.length;l++)if(o[l]!==r[l]||n[o[l]]!==t[o[l]]){a=!1;break}if(a)return}let s=new Set([...o,...r]);for(let a of s){if(a==="children"||a==="key")continue;let l=n[a],d=t[a];if(l!==d){if(J.test(a)){let{type:c,capture:i}=te(a);typeof l=="function"&&e.removeEventListener(c,l,i?{capture:!0}:void 0),d!=null&&d!==!1&&(typeof d!="function"?console.warn(`[weifuwu] event prop ${a} expects a function, got ${typeof d} \u2014 ignored`):e.addEventListener(c,d,i?{capture:!0}:void 0));continue}if(a==="class"||a==="className"){d==null||d===!1?e.removeAttribute("class"):(e.className="",X(e,a,d));continue}if(d==null||d===!1){if(a==="class"||a==="className")e.removeAttribute("class");else if(J.test(a))e.removeEventListener(a.slice(2).toLowerCase(),l);else if(a==="ref"){if(typeof l=="function")try{l(null)}catch(c){console.error("[weifuwu] ref cleanup error",c)}}else if(a==="value")e.value="";else if(a==="indeterminate")e.indeterminate=!1;else{e.removeAttribute(a);try{delete e[a]}catch{}}continue}X(e,a,d)}}}function ge(e,n,t,o,r,s,a){let l=j(n),d=j(t),c=s??r??Array.from(e.childNodes);if(d.some(f=>{if(f==null||typeof f!="object"||Array.isArray(f))return!1;let m=f;return m._placement!=="remote"&&m.key!==void 0})){for(let f=0;f<d.length;f++){let m=d[f];m&&typeof m=="object"&&!Array.isArray(m)&&re(m)===void 0&&(m.key=`pos:${f}`)}for(let f=0;f<l.length;f++){let m=l[f];m&&typeof m=="object"&&!Array.isArray(m)&&re(m)===void 0&&(m.key=`pos:${f}`)}}let u=s?s.map((f,m)=>f??(m<l.length?l[m]?._refNode??null:null)):l.map((f,m)=>{if(f==null||typeof f!="object"||Array.isArray(f))return c[m]??null;let T=f;return T._placement==="remote"?T._remoteEl??null:T.type===S?T._childNodes?.[0]??null:T._refNode??T.el??null});if(!d.some(f=>{if(f==null||typeof f!="object"||Array.isArray(f))return!1;let m=f;return m._placement!=="remote"&&m.key!==void 0})){let f=Math.max(l.length,d.length),m=[],T=_=>{a&&a.push(_)};for(let _=0;_<f;_++){let b=_<l.length?l[_]:null,v=_<d.length?d[_]:null;if(v==null||typeof v=="boolean"){let V=u[_],M=o.browser??A(),N=K(M,v);if(b==null||typeof b=="boolean"){V?.nodeType===8?(N&&V.nodeValue!==N.nodeValue&&(V.nodeValue=N.nodeValue),m.push(V),T(V)):(N&&V?.parentNode?V.parentNode.replaceChild(N,V):N&&e.appendChild(N),m.push(N),T(N));continue}if(b&&typeof b=="object"&&!Array.isArray(b))if(typeof b.type=="function")se(b,o.registry);else try{H(b,o.registry)}catch(I){console.error("[weifuwu] ref cleanup error",I)}N&&V?.parentNode?V.parentNode.replaceChild(N,V):N&&e.appendChild(N),m.push(N),T(N);continue}if(b!=null&&typeof b=="object"&&!Array.isArray(b)&&v!=null&&typeof v=="object"&&!Array.isArray(v)&&v===b){m.push(u[_]),T(u[_]);continue}if(b==null||typeof b=="boolean"){let V=U(v,o,o.browser??A());if(V==null){m.push(null),T(null);continue}let M=u[_];if(M&&M.nodeType===8&&M.nodeValue?.startsWith("wf-hole:")){M.parentNode?.replaceChild(V,M),m.push(V),T(V);continue}let N=null;for(let I=_+1;I<u.length;I++){let O=u[I];if(O&&O.parentNode===e){N=O;break}}if(!N){let I=null;for(let O=m.length-1;O>=0;O--)if(m[O]){I=m[O];break}if(I&&I.parentNode===e&&(N=I.nextSibling),!N){let O=u[u.length-1];O&&O.parentNode===e&&(N=O.nextSibling)}}N&&N.parentNode===e?e.insertBefore(V,N):e.appendChild(V),m.push(V),T(V);continue}let C=$(e,u[_],b,v,o),k=Le(v,C);m.push(...k),T(k[0]??C??null)}return m}let g=new Map;l.forEach((f,m)=>{let T=re(f);T!==void 0&&f&&typeof f=="object"&&!Array.isArray(f)&&g.set(T,{vnode:f,nodes:[u[m]??null].filter(Boolean),index:m})});let h=[],w=new Set,x=f=>{a&&a.push(f)},y=null;return d.forEach((f,m)=>{let T=re(f),_=f;if(T!==void 0&&g.has(T)){let b=g.get(T),v=b.nodes[0]??null;w.add(T);let C=$(e,v,b.vnode,_,o),k=Le(_,C),V=k[k.length-1]??C;V&&V.parentNode===e&&y&&V.previousSibling!==y&&e.insertBefore(V,y.nextSibling),h.push(...k),x(k[0]??C??null),V&&(y=V)}else{if(f==null||typeof f=="boolean"){let b=l[m]??null,v=u[m]??null,C=K(o.browser??A(),f);if(b==null||typeof b=="boolean")v?.nodeType===8?(C&&v.nodeValue!==C.nodeValue&&(v.nodeValue=C.nodeValue),h.push(v),x(v),v&&(y=v)):(C&&v?.parentNode?v.parentNode.replaceChild(C,v):C&&e.appendChild(C),h.push(C),x(C),C&&(y=C));else{if(typeof b=="object"&&!Array.isArray(b))if(typeof b.type=="function")se(b,o.registry);else try{H(b,o.registry)}catch(k){console.error("[weifuwu] ref cleanup error",k)}C&&v?.parentNode?v.parentNode.replaceChild(C,v):C&&e.appendChild(C),h.push(C),x(C),C&&(y=C)}return}if(_?._placement==="remote"){let b=l[m]??null,v=$(e,u[m]??null,b,_,o),C=Le(_,v);h.push(...C),x(C[0]??v??null);let k=C[C.length-1]??v;k&&(y=k)}else{let b=U(_,o,o.browser??A());if(h.push(b),x(b??null),b!=null){let v=u[m];v&&v.nodeType===8&&v.nodeValue?.startsWith("wf-hole:")?(v.parentNode?.replaceChild(b,v),y=b):(y?e.insertBefore(b,y.nextSibling):e.insertBefore(b,e.firstChild),y=b)}}}}),l.forEach((f,m)=>{let T=re(f),_=f&&typeof f=="object"&&!Array.isArray(f)&&typeof f.type=="function";if(T!==void 0&&!w.has(T)){if(f&&typeof f=="object"&&!Array.isArray(f))if(_)se(f,o.registry);else try{H(f,o.registry)}catch(v){console.error("[weifuwu] ref cleanup error",v)}let b=u[m];b?.parentNode&&b.parentNode.removeChild(b)}else if(T===void 0){let b=m<d.length?d[m]:null,v=u[m];if(!(v?.nodeType===8&&v.nodeValue?.startsWith("wf-hole:"))||b==null){if(f&&typeof f=="object"&&!Array.isArray(f))if(_)se(f,o.registry);else try{H(f,o.registry)}catch(k){console.error("[weifuwu] ref cleanup error",k)}v?.parentNode&&v.parentNode.removeChild(v)}}}),h}function He(){return!!globalThis?.__WF_VDOM_AUDIT}function he(e,n,t){if(n==null||n.length===0)return;let o=Array.from(e.childNodes);n.some(s=>{if(s==null||typeof s!="object"||Array.isArray(s))return!1;let a=s.type;return a===S||a===R})||o.length!==n.length&&t(`[audit] \u6570\u7EC4\u6570\u91CF\u9519\u4F4D\uFF1A${e.nodeName} \u671F\u671B ${n.length} \u4E2A childNodes\uFF0C\u5B9E\u9645 ${o.length}\uFF08vnode/DOM \u4E0D\u540C\u6784\uFF09`);for(let s=0;s<n.length;s++){let a=n[s];if(a==null||typeof a=="boolean"){let l=o[s];(!l||l.nodeType!==8||!l.nodeValue?.startsWith("wf-hole:"))&&t(`[audit] \u5360\u4F4D\u9519\u4F4D\uFF1A\u4F4D\u7F6E ${s} \u671F\u671B\u6CE8\u91CA(wf-hole)\uFF0C\u5B9E\u9645 ${l?.nodeName??"null"}\uFF08${e.nodeName}\uFF09`)}else if(typeof a=="string"||typeof a=="number"){let l=o[s];l&&l.nodeType!==3&&t(`[audit] \u6587\u672C\u9519\u4F4D\uFF1A\u4F4D\u7F6E ${s} \u671F\u671B\u6587\u672C\u8282\u70B9\uFF0C\u5B9E\u9645 ${l.nodeName}\uFF08${e.nodeName}\uFF09`)}}}function Q(e,n,t){if(n==null||typeof n=="boolean"||typeof n=="string"||typeof n=="number")return;if(Array.isArray(n)){he(e,n,t);for(let s of n)if(s!=null&&typeof s=="object"&&Array.isArray(s))for(let a of s)Q(e,a,t);else s!=null&&typeof s=="object"&&!Array.isArray(s)&&s.type===S&&he(e,j(s.props?.children),t);return}let o=n;if(o.type===R)return;if(o.type===S){he(e,j(o.props?.children),t);return}if(pe(o.type))return;if(typeof o.type=="function"){let s=o._refNode;s&&s.parentNode!==e&&t(`[audit] \u7EC4\u4EF6\u951A\u70B9\u9519\u4F4D\uFF1A${o.type.name||"anonymous"} _refNode \u4E0D\u5728\u7236\u8282\u70B9\u5185`),o._child!=null&&Q(e,o._child,t);return}let r=o.el??o._refNode;if(r&&r.nodeType===1&&r.tagName.toLowerCase()!==String(o.type)&&t(`[audit] \u5143\u7D20\u7C7B\u578B\u9519\u4F4D\uFF1A\u671F\u671B <${String(o.type)}>\uFF0C\u5B9E\u9645 ${r.tagName}`),r&&r.nodeType===1&&!("innerHTML"in(o.props??{}))){he(r,j(o.props?.children),t);for(let s of j(o.props?.children))s!=null&&typeof s=="object"&&!Array.isArray(s)&&typeof s.type=="function"&&Q(r,s,t)}}var ln=A();function un(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 be(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,s=Number.parseFloat(n.style.left)||o.left,a=e.top-r,l=e.left-s,d={top:o.top+a,bottom:o.bottom+a,left:o.left+l,right:o.right+l},c=ln.viewportWidth(),i=ln.viewportHeight(),u=e.top,p=e.left;return d.bottom>i-t&&(u=Math.max(t,u-(d.bottom-(i-t)))),d.top<t&&(u=Math.max(t,u+(t-d.top))),d.right>c-t&&(p=Math.max(t,p-(d.right-(c-t)))),d.left<t&&(p=Math.max(t,p+(t-d.left))),{top:u,left:p,width:e.width}}var Z=A();function dn(e){let n=new Map,t=new Map,o=!1,r=0;function s(){r||(r=requestAnimationFrame(()=>{r=0;let i=[];for(let[u,p]of n){if(!p.isOpen())continue;let g=p.getEl();if(!g)continue;let h=g.getBoundingClientRect();if(h.width===0&&h.height===0)continue;let w=p.compute(h);Object.assign(p.pos,be(w,p.panel?.(),p.margin)),i.push(u)}for(let[u,p]of t){let g=p.getScroller(),h=g instanceof Window?Z.scrollingElement()?.scrollTop??Z.scrollTop():g.scrollTop??0;h!==p.handle.y&&(p.handle.y=h,i.push(u))}i.length>0&&e(i)}))}function a(){o||(o=!0,Z.addEventListener("scroll",s,{capture:!0,passive:!0}),Z.addEventListener("resize",s))}function l(){o&&(Z.removeEventListener("scroll",s,{capture:!0}),Z.removeEventListener("resize",s),o=!1)}function d(i){for(let u of[...n.keys()])(u.startsWith(`popup:${i}:`)||u===`popup:${i}`||u===i)&&n.delete(u);t.delete(i)}function c(){l(),r&&(cancelAnimationFrame(r),r=0),n.clear(),t.clear()}return{popupTrackers:n,scrollTrackers:t,schedulePopupRecompute:s,ensurePopupListeners:a,destroyPopupListeners:l,cleanupTrackers:d,destroy:c}}function Ue(e,n,t){return r=>{r?n(r):t?.()}}function ie(e){return typeof window<"u"&&!!window.matchMedia?.("(hover: hover)").matches}function we(e){return typeof window<"u"&&!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches}function Ie(e,n,t){let o=null,r=()=>{n(),t?.once&&o&&o.removeEventListener("animationend",r)};return a=>{a?(o=a,a.addEventListener("animationend",r)):o&&(o.removeEventListener("animationend",r),o=null)}}function Oe(e,n){let{onLongPress:t,duration:o=500}=n,r,s=0,a=0,l=null,d=()=>{clearTimeout(r),r=void 0},c=e.selfId();if(c){let i=e.onUnmount(u=>{u===c&&(d(),i())})}return{onPointerDown:i=>{s=i.clientX??0,a=i.clientY??0,l=i,d(),r=setTimeout(()=>{r=void 0,l&&t(l)},o)},onPointerUp:d,onPointerLeave:d,onPointerMove:i=>{let u=Math.abs((i.clientX??0)-s),p=Math.abs((i.clientY??0)-a);(u>10||p>10)&&d()},onContextMenu:i=>{i.preventDefault(),t(i)}}}function ae(e,n){let t=e.selfId(),o="closed",r,s=()=>{o="closed",t?e.render([t]):e.render()};return{get phase(){return o},ref:l=>{l?r||(r=()=>{o==="exit"&&s()},l.addEventListener("animationend",r)):r=void 0},sync:l=>(l?o="open":o==="open"&&(o="exit"),o)}}function De(e,n,t){let o=e.selfId(),r=we(e),s=t?.duration??400,a=t?.ease==="linear"?p=>p:p=>1-Math.pow(1-p,3),l,d=n,c={value:r?n:0,reset:()=>{}},i=()=>{o?e.render([o]):e.render()},u=p=>{if(d=p,r){c.value=p,i();return}if(p===c.value)return;l&&cancelAnimationFrame(l);let g=c.value,h=performance.now(),w=x=>{let y=Math.min(1,(x-h)/s);c.value=Math.round(g+(p-g)*a(y)),y<1?(l=requestAnimationFrame(w),i()):(l=void 0,i())};l=requestAnimationFrame(w)};if(c.reset=p=>{p===d&&l||u(p)},o){let p=e.onUnmount(g=>{g===o&&(l&&(cancelAnimationFrame(l),l=void 0),p())})}return queueMicrotask(()=>u(n)),c}function We(e,n,t){let o=e.selfId(),r=e.browser,s=`media:${o}:${n}`;if(!e.mediaRegistry.has(s)){let a=r.matchMedia(n);t(a.matches);let l=c=>t(c.matches);a.addEventListener("change",l),e.mediaRegistry.set(s,{mql:a,handler:l});let d=e.onUnmount(c=>{if(c!==o)return;let i=e.mediaRegistry.get(s);if(i?.mql&&i.handler)try{i.mql.removeEventListener("change",i.handler)}catch{}e.mediaRegistry.delete(s),d()})}}function je(e,n,t){let o=e.browser,r=typeof n=="function"?{mobile:"(max-width: 639px)",tablet:"(min-width: 640px) and (max-width: 1023px)",desktop:"(min-width: 1024px)"}:n,s=typeof n=="function"?n:t,a=e.selfId(),l=`bp:${a}`;function d(){for(let[c,i]of Object.entries(r))if(o.matchMedia(i).matches)return c;return Object.keys(r)[0]??""}if(!e.mediaRegistry.has(l)){s(d());let c=[];for(let u of Object.values(r)){let p=o.matchMedia(u),g=()=>s(d());p.addEventListener("change",g),c.push({mql:p,handler:g})}e.mediaRegistry.set(l,{mqls:c});let i=e.onUnmount(u=>{if(u!==a)return;let p=e.mediaRegistry.get(l);if(p?.mqls)for(let g of p.mqls)try{g.mql.removeEventListener("change",g.handler)}catch{}e.mediaRegistry.delete(l),i()})}}function $e(e){let n=e.selfId(),t=e.browser,o={height:t.viewportHeight(),offsetTop:0,keyboardOpen:!1},r=()=>{n?e.render([n]):e.render()},s=()=>{let l=t.visualViewport();o.height=l?.height??t.viewportHeight(),o.offsetTop=l?.offsetTop??0,o.keyboardOpen=o.height<t.viewportHeight()*.9,r()},a=t.visualViewport();if(a?.addEventListener?(a.addEventListener("resize",s),a.addEventListener("scroll",s)):t.addEventListener("resize",s),n){let l=e.onUnmount(d=>{d===n&&(a?.removeEventListener?(a.removeEventListener("resize",s),a.removeEventListener("scroll",s)):t.removeEventListener("resize",s),l())})}return o}function qe(e,n){let t=e.selfId(),o={isIn:!1,ready:!1,observe:d,refresh:c,disconnect:i},r=null,s=null,a=()=>{t?e.render([t]):e.render()};function l(){if(s?.disconnect(),s=null,!r)return;let u=typeof n.rootMargin=="function"?n.rootMargin():n.rootMargin,p=typeof n.threshold=="function"?n.threshold():n.threshold;s=new IntersectionObserver(g=>{let h=g[g.length-1];if(!h)return;let w=h.isIntersecting,x=w!==o.isIn,y=!o.ready;o.isIn=w,o.ready=!0,n.onChange?.(h,w),(x||y)&&a()},{root:n.root?n.root():null,rootMargin:u??"0px",threshold:p??0}),s.observe(r)}function d(u){r=u,u?l():(s?.disconnect(),s=null,o.isIn=!1)}function c(){l()}function i(){s?.disconnect(),s=null}if(t){let u=e.onUnmount(p=>{p===t&&(i(),u())})}return o}function Fe(e,n){let t=e.selfId(),o=e.browser,r={y:0,refresh(){let l=s.getScroller();r.y=l instanceof Window?o.scrollingElement()?.scrollTop??o.scrollTop():l.scrollTop??0}},s={handle:r,getScroller:n.getScroller??(()=>window)};if(!t)return r.refresh(),r;e.scrollTrackers.set(t,s),e.ensurePopupListeners(),r.refresh();let a=e.onUnmount(l=>{l===t&&(e.scrollTrackers.delete(t),a())});return r}function ve(e,n){let t=e.selfId(),o=n.value!==void 0;if(o&&!n.onChange&&n.name&&(e.warned.has(n.name)||(e.warned.add(n.name),console.warn(`[weifuwu/${n.name}] \u53D7\u63A7\u6A21\u5F0F\uFF08value \u5DF2\u4F20\uFF09\u4F46\u672A\u63D0\u4F9B onChange\uFF0C\u4EA4\u4E92\u65E0\u6CD5\u751F\u6548\u3002
|
|
2
|
+
\u975E\u53D7\u63A7\uFF1A\u53BB\u6389 value\uFF1B\u53D7\u63A7\uFF1A\u4F20\u5165 onChange={(v) => setValue(v)}`))),!o&&t&&!e.uncontrolledValues.has(t)){e.uncontrolledValues.set(t,n.value);let s=e.onUnmount(a=>{a===t&&(e.uncontrolledValues.delete(t),s())})}let r=s=>{if(o){n.onChange?.(s);return}t&&e.uncontrolledValues.set(t,s),t?e.render([t]):e.render()};return{value:o?n.value:t?e.uncontrolledValues.get(t):n.value,setValue:r,controlled:o}}function Be(e,n){let t=e.selfId(),o=ve(e,{value:n.value,onChange:n.onChange,name:n.name});if(t&&!e.inputStates.has(t)){e.inputStates.set(t,{keyword:"",selectedLabel:""});let a=e.onUnmount(l=>{l===t&&(e.inputStates.delete(t),a())})}let r=t?e.inputStates.get(t):{keyword:"",selectedLabel:""},s=()=>{t?e.render([t]):e.render()};return{...o,get keyword(){return r.keyword},setKeyword(a){r.keyword=a,s()},get selectedLabel(){return r.selectedLabel},setSelectedLabel(a){r.selectedLabel=a,s()}}}function Ke(e,n){let t=e.selfId(),o=!1;if(t){let d=e.onUnmount(c=>{c===t&&(o=!0,d())})}let r=()=>{o||(t?e.render([t]):e.render())},s={data:void 0,loading:!1,error:void 0},a=0,l=()=>{let d=++a;s.loading=!0,s.error=null,r(),Promise.resolve().then(()=>n()).then(c=>{a===d&&(s.data=c,s.loading=!1,r())}).catch(c=>{a===d&&(s.error=c,s.loading=!1,r())})};return l(),s.reload=l,s}function ze(e,n){let t=e.selfId(),o=e.browser;if(typeof window>"u")return()=>{};if(o.addEventListener("keydown",n),t){let r=e.onUnmount(s=>{s===t&&(o.removeEventListener("keydown",n),r())})}return()=>o.removeEventListener("keydown",n)}function Ge(e,n){let t=e.browser,o=0,r=0,s=!1,a=i=>{s&&n.onMove(i,{x:i.clientX-o,y:i.clientY-r})},l=i=>{s&&(s=!1,t.removeEventListener("pointermove",a),t.removeEventListener("pointerup",l),n.onEnd?.(i))},d=i=>{s||(i.preventDefault(),s=!0,o=i.clientX,r=i.clientY,t.addEventListener("pointermove",a),t.addEventListener("pointerup",l),n.onStart?.(i))},c=e.selfId();if(c){let i=e.onUnmount(u=>{u===c&&(s&&(t.removeEventListener("pointermove",a),t.removeEventListener("pointerup",l),s=!1),i())})}return{onPointerDown:d}}function Ye(e,n){let t={};n.onDrop&&(t.onDrop=r=>{r.preventDefault(),n.onDrop(r)}),n.onDragOver&&(t.onDragOver=r=>{r.preventDefault(),n.onDragOver(r)}),n.onDragLeave&&(t.onDragLeave=r=>n.onDragLeave(r));let o={draggable:!0};if(n.onDragStart){let r=n.onDragStart;o.onDragStart=s=>{typeof document<"u"&&document.body.classList.add("wf-dragging"),r(s)}}if(n.onDragEnd){let r=n.onDragEnd;o.onDragEnd=s=>{typeof document<"u"&&document.body.classList.remove("wf-dragging"),r(s)}}return{dropProps:t,dragProps:o}}function Ce(e,n){let t=e.selfId(),o={top:0,left:0,refresh:()=>{}};if(!t)return o;let r={pos:o,getEl:n.el,isOpen:n.isOpen,compute:n.compute,panel:n.panel,margin:n.margin??8};e.popupTrackers.set(t,r),e.ensurePopupListeners();let s=e.onUnmount(a=>{a===t&&(e.popupTrackers.delete(t),s())});return o.refresh=()=>{let a=r.getEl();if(!a)return;let l=a.getBoundingClientRect();if(l.width===0&&l.height===0)return;let d=r.compute(l);Object.assign(o,be(d,r.panel?.(),r.margin))},o}function Je(e,n){let t=e.selfId(),o=e.browser,r=ie(e),s=()=>typeof n.trigger=="function"?n.trigger():n.trigger??"manual",a=n.open!==void 0,l=()=>!!n.disabled?.(),d=()=>a?typeof n.open=="function"?!!n.open():!!n.open:n.isOpen(),c=n.presence?ae(e,{name:n.name}):null,i,u=!1,p=E=>{if(!c)return E?"open":"closed";let P=c.sync(E);return E&&n.lockScroll&&!u&&(Dn(),u=!0),P},g=E=>{l()||(a?n.onOpenChange?.(E):c?E?p(!0):d()&&p(!1):n.setOpen(E))},h=()=>{let E=n.placement;return typeof E=="function"?E():E??"bottom"},w=null,x=!1,y=Ce(e,{el:n.el??(()=>null),isOpen:()=>d(),compute:E=>{if(n.position){let P=n.position();return{top:P.y,left:P.x,width:P.width}}return un(E,h(),n.gap??6,n.center!==!1)},panel:()=>w,margin:n.margin??8}),f=E=>{if(n.closeOnOutside===!1||n.mask||!d())return;let P=E.target;if(!(P instanceof Node))return;let W=n.el?.()??null;W&&W.contains(P)||w&&w.contains(P)||g(!1)},m=E=>{n.closeOnEscape!==!1&&(E.key!=="Escape"||!d()||g(!1))};if(o.addEventListener("mousedown",f),o.addEventListener("keydown",m),t){let E=e.onUnmount(P=>{P===t&&(o.removeEventListener("mousedown",f),o.removeEventListener("keydown",m),E())})}let T={},_=E=>typeof E=="function"?E():E??0,b=()=>_(n.openDelay),v=()=>_(n.closeDelay),C,k,V=()=>{clearTimeout(C),clearTimeout(k),C=void 0,k=void 0},M=E=>{if(l())return;let P=E.currentTarget,W=E.relatedTarget;P.contains(W)||(clearTimeout(k),k=void 0,C=setTimeout(()=>{C=void 0,g(!0)},b()))},N=E=>{if(l())return;let P=E.currentTarget,W=E.relatedTarget;P.contains(W)||(clearTimeout(C),C=void 0,k=setTimeout(()=>{k=void 0,g(!1)},v()))},I=()=>{l()||(clearTimeout(k),k=void 0,C=setTimeout(()=>{C=void 0,g(!0)},b()))},O=()=>{l()||(clearTimeout(C),C=void 0,k=setTimeout(()=>{k=void 0,g(!1)},v()))},ne=()=>s()==="hover";if(T.onMouseOver=E=>{ne()&&M(E)},T.onMouseOut=E=>{ne()&&N(E)},T.onClick=()=>{ne()?r||g(!d()):s()==="click"&&g(!0)},T.onFocus=()=>{ne()?I():s()==="focus"&&(clearTimeout(k),k=void 0,g(!0))},T.onBlur=()=>{ne()?O():s()==="focus"&&(clearTimeout(C),C=void 0,k=setTimeout(()=>{k=void 0,g(!1)},v()))},s()==="longpress"){let E,P=0,W=0,q=()=>{clearTimeout(E),E=void 0};T.onPointerDown=L=>{l()||(P=L.clientX??0,W=L.clientY??0,q(),E=setTimeout(()=>{E=void 0,n.onTrigger?.({clientX:P,clientY:W}),g(!0)},n.longPressDuration??500))},T.onPointerUp=q,T.onPointerLeave=q,T.onPointerMove=L=>{let Ve=Math.abs((L.clientX??0)-P),_e=Math.abs((L.clientY??0)-W);(Ve>10||_e>10)&&q()},T.onContextMenu=L=>{L.preventDefault(),n.onTrigger?.({clientX:L.clientX??0,clientY:L.clientY??0}),g(!0)}}if(T.onKeyDown=E=>{E.key==="Escape"&&n.closeOnEscape!==!1&&g(!1)},t){let E=e.onUnmount(P=>{P===t&&(V(),E())})}let En=E=>{if(E){w=E;let P=()=>y.refresh();E.addEventListener("animationend",P,{once:!0})}else w=null},xe=null,Ne=null,tn=E=>{En(E),Ne&&Ne(E),c?.ref(E),n.trapFocus&&(E?i=$n(E):(i?.(),i=void 0)),n.lockScroll&&!E&&u&&(Wn(),u=!1)};return{get open(){return d()},setOpen:g,get phase(){return c?c.phase:d()?"open":"closed"},sync:p,wrapProps:T,portal:(E,P="popover")=>{if(l())return null;if(!(c?c.phase!=="closed":d()))return x=!1,xe=null,null;let q=n.el?.()??null;(!x||q!==xe)&&(q?y.refresh():queueMicrotask(()=>{d()&&y.refresh()}),x=!0,xe=q);let L=E.props??{};Ne=L.ref??null;let Ve=n.positioning==="none"?L.class??"":["wf-popup",L.class].filter(Boolean).join(" "),_e=n.positioning==="none"?{...L.style??{},position:"fixed"}:{...L.style??{},position:"fixed",top:`${y.top}px`,left:`${y.left}px`,...y.width!==void 0?{width:`${y.width}px`}:{},maxWidth:(()=>{let ce=typeof n.width=="function"?n.width():n.width;return ce!==void 0?`min(${ce}px, calc(100vw - 32px))`:"calc(100vw - 32px)"})()},G={...E,props:{...L,class:Ve,style:_e,ref:tn}};if(n.mask){let ce=typeof n.mask=="object"?n.mask:F("div",{class:"wf-popup-mask","data-portal-mask":P,onClick:n.maskClosable===!1?void 0:()=>g(!1)}),Cn=n.maskCentered?F("div",{class:"wf-cover",style:{"--wf-z":"var(--wf-z-popover)",pointerEvents:"none"}},{...G,props:{...G.props,style:{...L.style??{},pointerEvents:"auto"},ref:tn}}):null,Tn=n.maskCentered?void 0:{...G.props?.style??{},zIndex:"var(--wf-z-popover)"},xn=n.maskCentered?Cn:{...G,props:{...G.props,style:Tn}};return fe([ce,xn],P)}return fe(G,P)},refresh:()=>y.refresh()}}function Xe(e,n){let t=e.selfId();if(t&&!e.openStates.has(t)){e.openStates.set(t,!1);let l=e.onUnmount(d=>{d===t&&(e.openStates.delete(t),l())})}let o=n.open!==void 0;o&&!n.onOpenChange&&n.name&&!e.warned.has(n.name)&&(e.warned.add(n.name),console.warn(`[weifuwu/${n.name}] \u53D7\u63A7\u6A21\u5F0F\uFF08open \u5DF2\u4F20\uFF09\u4F46\u672A\u63D0\u4F9B onOpenChange\uFF0C\u4EA4\u4E92\u65E0\u6CD5\u751F\u6548\u3002
|
|
3
|
+
\u975E\u53D7\u63A7\uFF1A\u53BB\u6389 open\uFF1B\u53D7\u63A7\uFF1A\u4F20\u5165 onOpenChange={(o) => setOpen(o)}`));let r=()=>o?!!n.open:t?e.openStates.get(t)??!1:!1,s=()=>{t?e.render([t]):e.render()},a=l=>{if(o){n.onOpenChange?.(l);return}t&&e.openStates.set(t,l),s()};return{get open(){return r()},setOpen:a,triggerProps:{onClick:()=>a(!0),onFocus:()=>{n.openOnFocus&&a(!0)}}}}var z=A(),le=0,cn="",fn="",pn="",mn="",Ee=0;function yn(){return typeof window<"u"&&typeof document<"u"}function Dn(){if(le++,le>1||!yn())return;Ee=z.scrollTop();let e=z.bodyElement();cn=e.style.overflow,fn=e.style.position,pn=e.style.top,mn=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=`-${Ee}px`,e.style.width="100%")}function Wn(){if(le===0||(le--,le>0)||!yn())return;let e=z.bodyElement();e.style.overflow=cn,e.style.position=fn,e.style.top=pn,e.style.width=mn,Ee>0&&z.scrollTo(Ee)}var jn='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function $n(e){let n;return queueMicrotask(()=>{let t=e.querySelectorAll(jn);if(t.length===0)return;let o=t[0],r=t[t.length-1],s=l=>{l.key==="Tab"&&(l.shiftKey&&z.activeElement()===o?(l.preventDefault(),r.focus()):!l.shiftKey&&z.activeElement()===r&&(l.preventDefault(),o.focus()))},a=z.activeElement();o.focus(),e.addEventListener("keydown",s),n=()=>{e.removeEventListener("keydown",s),a?.focus()}}),()=>n?.()}function qn(e){return e.map(n=>{let t={role:n.role,content:n.content};return n.reasoning&&(t.reasoning_content=n.reasoning),t})}function Qe(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`msg-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function gn(e,n,t,o){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 r=null;function s(){if(!e.streaming)return;let h=e.messages[e.messages.length-1];return h&&h.role==="assistant"&&h.status==="streaming"?h:void 0}function a(h,w,x){let y=s();switch(h){case"wf:token":y&&(y.content+=w.text);break;case"wf:tool_call":{y&&(y.toolCalls||(y.toolCalls=[]),y.toolCalls.push({call:w,status:"running"}));break}case"wf:tool_progress":{let f=w,m=y?.toolCalls?.find(T=>T.call.id===f.toolCallId);m&&(m.progress=f);break}case"wf:tool_result":{let f=w,m=y?.toolCalls?.find(T=>T.call.id===f.id);m&&(m.result=f,m.status=f.ok?"ok":"error");break}case"wf:approval_request":y&&(y.approval=w);break;case"wf:usage":y&&(y.usage=w);break;case"wf:step":e.step=w;break;case"wf:done":if(y){y.status="done",y.approval=void 0;let f=w;f.reasoning&&(y.reasoning=f.reasoning)}e.streaming=!1,e.step=null;break;case"wf:error":y&&(y.status="error",y.error=w,y.approval=void 0),e.error=w,e.streaming=!1,e.step=null;break;default:x?.(h,w);break}o?.()}function l(){let h=t.body?t.body(e.messages):{messages:qn(e.messages)};r=n(t.url,h,{onToken:x=>a("wf:token",{text:x}),onToolCall:x=>a("wf:tool_call",x),onToolProgress:x=>a("wf:tool_progress",x),onToolResult:x=>a("wf:tool_result",x),onApproval:x=>a("wf:approval_request",x),onUsage:x=>a("wf:usage",x),onStep:x=>a("wf:step",x),onDone:x=>a("wf:done",x),onError:x=>a("wf:error",x),onEvent:(x,y)=>a(x,y,t.onEvent)},{signal:t.signal,headers:t.headers}),e.streaming=!0;let w=s();w&&r?.traceId&&(w.id=r.traceId)}function d(){if(e.streaming)return;let h=String(e.input??"").trim();h&&(e.input="",e.error=null,e.usage=null,e.step=null,e.messages.push({id:Qe(),role:"user",content:h,status:"done"},{id:Qe(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),l(),o?.())}function c(){r?.abort(),e.streaming=!1,e.step=null;let h=e.messages[e.messages.length-1];h&&h.role==="assistant"&&h.status==="streaming"&&(!h.content&&(!h.toolCalls||h.toolCalls.length===0)?e.messages.pop():h.status="done"),o?.()}function i(){if(e.streaming)return;let h=-1;for(let w=e.messages.length-1;w>=0;w--)if(e.messages[w].role==="user"){h=w;break}h!==-1&&(e.messages.splice(h+1),e.error=null,e.usage=null,e.step=null,e.messages.push({id:Qe(),role:"assistant",content:"",status:"streaming",toolCalls:[]}),l(),o?.())}function u(){r?.abort(),e.messages=[],e.input="",e.streaming=!1,e.error=null,e.usage=null,e.step=null,o?.()}async function p(h,w,x){let y=e.messages[e.messages.length-1],f=y?.role==="assistant"?y.approval:void 0;if(f&&(y.approval=void 0,o?.(),!!t.approveUrl))try{await fetch(t.approveUrl,{method:"POST",headers:{"Content-Type":"application/json",...t.headers},body:JSON.stringify(x?{id:f.id,decision:h,note:w,modifiedArgs:x}:{id:f.id,decision:h,note:w}),signal:t.signal})}catch(m){if(t.signal?.aborted)return;e.error={code:"provider_error",message:m instanceof Error?m.message:String(m)},o?.()}}function g(){r?.abort(),r=null}return{send:d,stop:c,retry:i,clear:u,approve:p,dispose:g}}function hn(e,n,t){let o=new AbortController,r=t?.signal;r&&(r.aborted?o.abort():r.addEventListener("abort",()=>o.abort(),{once:!0}));let s=t?.traceId??Gn(),a=t?.record!==!1,l=[],d=(async()=>{let c;try{c=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Trace-Id":s,Accept:"text/event-stream",...t?.headers},body:JSON.stringify(n),signal:o.signal})}catch(i){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:i instanceof Error?i.message:String(i)});return}if(!c.ok){t?.onError?.({code:zn(c.status),message:`HTTP ${c.status} ${c.statusText}`});return}try{for await(let{name:i,data:u}of Bn(c.body)){if(o.signal.aborted)return;Kn(l,{name:i,data:u},a),Fn(i,u,t??{})}}catch(i){if(o.signal.aborted)return;t?.onError?.({code:"provider_error",message:i instanceof Error?i.message:String(i)})}})();return{abort:()=>o.abort(),done:d,traceId:s,events:l}}function Fn(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*Bn(e){let n=e.getReader(),t=new TextDecoder,o="";try{for(;;){let{done:r,value:s}=await n.read();if(r)break;o+=t.decode(s,{stream:!0});let a=o.split(`
|
|
4
4
|
|
|
5
|
-
`);
|
|
6
|
-
`))a.startsWith("event: ")?u=a.slice(7):a.startsWith("data: ")&&(d+=a.slice(6));if(d)try{yield{name:u,data:JSON.parse(d)}}catch{}}}}finally{n.releaseLock()}}function In(e,n,t){t&&(e.length>=1e3&&e.shift(),e.push(n))}function On(e){return e===401||e===403?"auth_failed":e===429?"rate_limited":e>=500?"provider_error":"invalid_request"}function Un(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`trace-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function Fe(e,n){let t={messages:[],input:"",streaming:!1,error:null,usage:null,step:null},r=new Set,s=on(t,sn,n,()=>{for(let l of[...r])l()});Object.assign(t,s),t.subscribe=l=>(r.add(l),()=>{r.delete(l)});let i=e.selfId();if(i){let l=e.onUnmount(u=>{u===i&&(s.dispose(),l())})}return t}function Be(e,n){let t=e.selfId(),r;return t&&(r=n.subscribe(()=>e.render([t])),e.onUnmount(()=>r?.())),n}function an(e){let n=new Map;async function t(s){let i=n.get(s);if(i)return await i,n.has(s)?void 0:t(s);let l=r(s);n.set(s,l);try{await l}finally{n.delete(s)}}async function r(s){let i=e.registry.idRegistry.get(s);if(!(!i||typeof i._render!="function"))try{let l={browser:e.ctx.browser,registry:e.registry,ctxVersion:e.ctx?.ui?._ctxVersion??0},u=await i._render(i.props),d=await M(u,e.ctx,i._child,e.registry)??null,a=i._child;i._child=d;let c=i._parentNode??i._refNode?.parentNode??e.rootEl??null;if(c){let p=O(c,i._refNode??null,a,d,l);p?i._refNode=p:i._refNode=null}}catch(l){e.onError?e.onError(l):console.error("[weifuwu] render error:",l?.stack??l)}}function o(s){if(s==null){let i=e.ctx.ui?._selfId;return i?t(i):Promise.resolve()}return Promise.all(s.map(i=>t(i))).then(()=>{})}return{render:o}}function fe(e){let n=e.registry??Te(),t={_selfId:"_wf_root",_mounting:!1,_ctxVersion:0,_rootVNodeId:void 0},r={browser:e.browser,__registry:n},o=e.renderer??an({registry:n,ctx:r,rootEl:e.root}),s=!1;t.render=function(f){if(f==null){let h=this._selfId!=="_wf_root"&&this._selfId?this._selfId:t._rootVNodeId;return h?o.render([h]):(s||(s=!0,console.warn("[weifuwu] render() \u65E0\u53C2\u4F46\u65E0\u6E32\u67D3\u76EE\u6807\uFF1A\u9875\u9762\u6839\u662F native vnode\uFF08UIHandler \u76F4\u63A5\u8FD4\u56DE vnode \u7684\u9875\u9762\u5F62\u6001\uFF09\uFF0C\u5185\u90E8\u72B6\u6001\u6E32\u67D3\u65E0\u6548\u3002\u6539\u7528 async \u7EC4\u4EF6\u5F62\u6001\uFF08const Page: Component = async ... => (props) => ...\uFF09\u6216 createStore + useExternal \u5171\u4EAB\u72B6\u6001\u3002")),Promise.resolve())}return o.render(f)},t.setMounting=f=>{t._mounting=f},t.endMounting=()=>{t._mounting=!1},r.ui=t;let i=Qe(f=>{for(let h of f)o.render([h])}),{mediaRegistry:l,popupTrackers:u,scrollTrackers:d,ensurePopupListeners:a,destroyPopupListeners:c,cleanupTrackers:p}=i;Ne(n,f=>{p(f),u.has(f)&&u.delete(f)});let w=new Set,b=new Map,m=new Map,g=new Map,y=f=>({selfId:()=>{let h=f?._selfVNode?._id??f?._selfId;return typeof h=="string"?h:void 0},render:h=>o.render(h),browser:e.browser,onUnmount:h=>Ne(n,h),registry:n,mediaRegistry:l,popupTrackers:u,scrollTrackers:d,isMounting:()=>t._mounting===!0,warned:w,uncontrolledValues:b,inputStates:m,openStates:g,ensurePopupListeners:a});return t.bumpCtxVersion=()=>{t._ctxVersion=(t._ctxVersion??0)+1},t.selfId=function(f){if(typeof f!="string"||!f)throw new Error(`[weifuwu] selfId requires a non-empty string, got ${typeof f}`);if(n.idRegistry.has(f))throw new Error(`[weifuwu] Duplicate component ID: "${f}". Each component must have a unique custom ID.`);let h=this._selfVNode;h&&(h._customId=f,n.idRegistry.set(f,h))},t.useChat=function(f){return Fe(y(this),f)},t.useMedia=function(f,h){return Re(y(this),f,h)},t.useBreakpoint=function(f,h){return Ae(y(this),f,h)},t.usePopupPosition=function(f){return ce(y(this),f)},t.useHoverCapable=function(){return J(y(this))},t.useStableRef=function(f,h){return Ve(y(this),f,h)},t.useVisualViewport=function(){return Me(y(this))},t.usePopup=function(f){return je(y(this),f)},t.useLongPress=function(f){return ke(y(this),f)},t.useInView=function(f){return Le(y(this),f)},t.useScrollPosition=function(f){return He(y(this),f)},t.useAsync=function(f){return Oe(y(this),f)},t.useControlled=function(f){return ue(y(this),f)},t.useControlledInput=function(f){return Ie(y(this),f)},t.useOpen=function(f){return $e(y(this),f)},t.usePresence=function(f){return Q(y(this),f)},t.useGlobalKey=function(f){return Ue(y(this),f)},t.useDrag=function(f){return We(y(this),f)},t.useDragDrop=function(f){return De(y(this),f)},t.useExternal=function(f){return Be(y(this),f)},t.useReducedMotion=function(){return le(y(this))},t.useAnimationEnd=function(f,h){return _e(y(this),f,h)},t.useTween=function(f,h){return Se(y(this),f,h)},t.destroyPopupListeners=c,{ctx:r,registry:n,renderer:o,rootUi:t,destroyPopupListeners:c}}function Wn(e){let{ctx:n,registry:t,renderer:r,rootUi:o,destroyPopupListeners:s}=fe(e),i=null,l=null;return{ctx:n,registry:t,renderer:r,async mount(d){i=d;let a=await M(d,n,void 0,t);e.root.innerHTML="";let c=S(a,n,e.browser);c!=null&&e.root.appendChild(c),l=a?._child??a,o._rootVNodeId=a?._id},async rerender(){if(i==null)return;let d=await M(i,n,i,t,{force:!0}),a=i,c=l,p=a._child,w=e.root.firstChild;O(e.root,w,c,p,{browser:e.browser,registry:t,ctxVersion:n?.ui?._ctxVersion??0,force:!0}),l=p},unmount(){for(let[,d]of t.idRegistry)try{R(d,t)}catch(a){console.error("[weifuwu] unmount ref error",a)}e.root.innerHTML="",t.idRegistry.clear(),s()}}}function Dn(e){return e.__registry??(e.__registry=Te())}function jn(e,n,t,r){let o=Dn(t),s=t.browser??_();return Promise.resolve(M(n,t,void 0,o)).then(()=>{let i=S(n,t,s);if(i!=null&&e.appendChild(i),n._id&&o){let l=o.idRegistry.get(n._id);l&&(l._parentNode=e)}r?.onMounted?.()}).catch(i=>console.error("[weifuwu] command mount error",i)),{id:n._id??""}}function $n(e,n,t){let r=t.__registry;n&&r&&(R(n,r),n._id&&oe(r,n._id)),e.remove()}function qn(){let e=_(),n=e.createElement("div");return n?(e.bodyAppend(n),n):null}function Fn(e,n){let t=_(),r=typeof n.root=="string"?t.query(n.root):n.root;if(!r)throw new Error(`uiServe: root not found: ${n.root}`);let o=r;!n.hydrate&&!n.loading&&(o.innerHTML="");let{ctx:i,registry:l,renderer:u,rootUi:d,destroyPopupListeners:a}=fe({browser:t,root:o}),c=new Map,p=globalThis.__DATA__??window.__DATA__;if(p&&typeof p=="object")for(let[C,T]of Object.entries(p))c.set(C,{value:T});i.data={async get(C,T){let E=c.get(C);if(E&&"value"in E)return E.value;if(E?.promise)return E.promise;if(!T)return;let V=Promise.resolve().then(()=>T()).then(W=>(c.set(C,{value:W}),W));return c.set(C,{promise:V}),V},set(C,T){c.set(C,{value:T})},has(C){return c.has(C)}},i.route={params:{},query:{},path:""};let w=null,b="",m=0,g,y=new Promise(C=>{g=C}),f=!1;async function h(C,T){let E=++m,V={pathname:C,search:""};i.route.path=C;let W;try{W=await e.execute(V,i,C)}catch(A){W=j("div",{class:"ui-dom-error"},`\u9875\u9762\u6E32\u67D3\u5931\u8D25: ${A?.message??String(A)}`)}if(f||E!==m)return;let U;try{U=await M(W,i,w,l)}catch(A){U=j("div",{class:"ui-dom-error"},`\u7EC4\u4EF6\u6E32\u67D3\u5931\u8D25: ${A?.message??String(A)}`)}if(!(f||E!==m)){if(T){o.innerHTML="";let A=S(U,i,t);A!=null&&o.appendChild(A)}else if(w!==void 0){let A=w;w=U;let me=A?.el??A?._refNode??null;O(o,me,A,U,{browser:t,registry:l,ctxVersion:i?.ui?._ctxVersion??0})}w=U,b=C,d._rootVNodeId=U?._id}}let x=t.pathname();h(x,!0).finally(()=>{f||g()});let P=()=>{let C=t.pathname();C!==b&&h(C,!1)};return t.addEventListener("popstate",P),{close(){f=!0,t.removeEventListener("popstate",P),a(),l.idRegistry.clear()},ready:y,ctx:i}}function Ke(e){e.node=e.node?e.node.nextSibling:null}function Bn(e,n){e.node&&e.node.parentNode?e.node.parentNode.insertBefore(n,e.node):e.parent.appendChild(n)}function Kn(e,n){e.node&&e.node.parentNode?(e.node.parentNode.replaceChild(n,e.node),Ke(e)):e.parent.appendChild(n)}function zn(e,n){for(let[t,r]of Object.entries(n))t==="children"||t==="key"||t==="innerHTML"||Y(e,t,r)}function ee(e,n,t){let r=n.browser??_();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),Ke(t),t.node;let d=r.createTextNode(u);return Bn(t,d),d}if(Array.isArray(e)){let u=null;for(let d of e){let a=ee(d,n,t);a!=null&&!u&&(u=a)}return u}let o=e;if(o.type===H||o.type===L){let u=o.props?.children,d=u==null?[]:Array.isArray(u)?u:[u],a=null;for(let c of d){let p=ee(c,n,t);p!=null&&!a&&(a=p)}return a}if(typeof o.type=="function"){let u=o._child;if(u==null){if(typeof o._render!="function")throw new Error(`[vdom] component ${o.type.name||"anonymous"} not built before hydration`);return o._child=null,null}let d=ee(u,n,t);return o._refNode||(o._refNode=d),d}let s=o.type,i=o.props??{},l;if(t.node&&t.node.nodeType===1&&t.node.tagName.toLowerCase()===s.toLowerCase()?(l=t.node,Ke(t)):(l=Ee.has(s)?r.createElementNS("http://www.w3.org/2000/svg",s):r.createElement(s),Kn(t,l)),o.el=l,zn(l,i),!("innerHTML"in i)){let u={parent:l,node:l.firstChild},d=(Array.isArray(i.children)?i.children:[i.children]).flat(1/0);for(let a of d){let c=ee(a,n,u);if(c!=null&&c.parentNode!==l&&l.appendChild(c),a&&typeof a=="object"&&!Array.isArray(a)&&typeof a.type=="function"){let p=a;p._parentNode||(p._parentNode=l,p._refNode=c)}}for(;u.node;){let a=u.node;u.node=a.nextSibling,a.parentNode?.removeChild(a)}}return"value"in i&&l instanceof HTMLSelectElement&&(l.value=String(i.value??"")),l}async function Gn(e,n,t){let r=t.__registry;await M(n,t,void 0,r);let o={parent:e,node:e.firstChild};for(ee(n,t,o);o.node;){let s=o.node;o.node=s.nextSibling,s.parentNode?.removeChild(s)}}var Yn=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Xn=new Set(["svg","path","circle","rect","line","polyline","polygon","g","text","defs","use","clipPath"]);function pe(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Jn(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 Qn(e){return Object.entries(e).filter(([,n])=>n!=null).map(([n,t])=>{let r=n.replace(/[A-Z]/g,s=>"-"+s.toLowerCase()),o=typeof t=="number"&&t!==0?`${t}px`:String(t);return`${r}:${o}`}).join(";")}async function z(e,n){if(e==null||typeof e=="boolean")return"";if(typeof e=="string"||typeof e=="number")return pe(String(e));if(Array.isArray(e))return(await Promise.all(e.map(c=>z(c,n)))).join("");let t=e;if(t.type===H||t.type===L)return z(t.props?.children,n);if(typeof t.type=="function"){let a=Object.create(n),c=await t.type(t.props??{},a);if(typeof c!="function")throw new Error(`Component ${t.type.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);return z(await c(t.props??{}),a)}let r=t.type,o=t.props??{},s=[],i;for(let[a,c]of Object.entries(o))if(!(a==="children"||a==="key")&&a!=="ref"&&!(a.startsWith("on")&&typeof c=="function")){if(a==="innerHTML"){i=String(c??"");continue}if(a==="class"||a==="className"){let p=Jn(c);p&&s.push(` class="${pe(p)}"`);continue}if(a==="style"&&c&&typeof c=="object"){s.push(` style="${pe(Qn(c))}"`);continue}if(a==="draggable"||a==="contenteditable"||a==="spellcheck"){s.push(` ${a}="${c?"true":"false"}"`);continue}if(c===!0){s.push(` ${a}`);continue}c===!1||c==null||s.push(` ${a}="${pe(String(c))}"`)}let l=s.join(""),u=Xn.has(r);if(Yn.has(r))return`<${r}${l}>`;if(i!==void 0)return`<${r}${l}>${i}</${r}>`;let d=await z(o.children,n);return u?`<${r}${l}>${d}</${r}>`:`<${r}${l}>${d}</${r}>`}function Zn(){let e=()=>()=>{},n=()=>({});return{_selfId:"_wf_root",render:()=>{},selfId:()=>{},bumpCtxVersion:()=>{},setMounting:()=>{},endMounting:()=>{},useChat:()=>({messages:[],input:"",streaming:!1,error:null,usage:null,step:null,send:()=>{},stop:()=>{},retry:()=>{},clear:()=>{},approve:()=>{},subscribe:()=>()=>{}}),useExternal:t=>t,useMedia:e,useBreakpoint:e,usePopupPosition:()=>({top:0,left:0,refresh:()=>{}}),useHoverCapable:()=>!1,useStableRef:t=>r=>{r&&t?.(r)},useVisualViewport:()=>({height:0,offsetTop:0,keyboardOpen:!1}),usePopup:()=>({open:!1,setOpen:()=>{},phase:"closed",sync:t=>t?"open":"closed",wrapProps:{},portal:t=>t,refresh:()=>{}}),useLongPress:n,useInView:()=>({isIn:!1,ready:!1,observe:()=>{},refresh:()=>{},disconnect:()=>{}}),useScrollPosition:()=>({y:0,refresh:()=>{}}),useAsync:()=>({data:void 0,loading:!0,error:void 0,reload:()=>{}}),useControlled:()=>({value:void 0,setValue:()=>{},controlled:!1}),useControlledInput:()=>({value:void 0,setValue:()=>{},keyword:"",setKeyword:()=>{},selectedLabel:"",setSelectedLabel:()=>{},controlled:!1}),useOpen:()=>({open:!1,setOpen:()=>{},triggerProps:{}}),usePresence:()=>({phase:"closed",ref:()=>{},sync:()=>"closed"}),useGlobalKey:()=>()=>{},useDrag:n,useDragDrop:()=>({dropProps:{},dragProps:{}}),useReducedMotion:()=>!0,useAnimationEnd:()=>()=>{},useTween:t=>{let r=t;return{get value(){return r},set value(o){r=o},reset:o=>(o!==void 0&&(r=o),r)}}}}function ln(e,n){let t={...e,ui:Zn(),browser:void 0},r=new Map;return t.data={async get(o,s){let i=r.get(o);if(i&&"value"in i)return i.value;if(i?.promise)return i.promise;if(!s)return;let l=Promise.resolve().then(()=>s()).then(u=>(r.set(o,{value:u}),n.set(o,u),u));return r.set(o,{promise:l}),l},set(o,s){r.set(o,{value:s}),n.set(o,s)},has(o){return r.has(o)}},t}function un(e){return`<script>window.__DATA__=${JSON.stringify(Object.fromEntries(e)).replace(/</g,"\\u003c")};<\/script>`}async function et(e,n){let t=new Map,o=ln({params:{},query:{}},t),s=n.url.split("?")[0].split("#")[0],i=e.match(s);o.params=i.params,o.query=Object.fromEntries(new URLSearchParams(n.url.split("?")[1]??""));let l=new URL(n.url.startsWith("http")?n.url:`http://localhost${n.url.startsWith("/")?n.url:"/"+n.url}`),u=await e.execute(l,o,s),d=await z(u,o),a=un(t),c=i.title??n.title??"",p=n.rootId??"root",w=(n.styles??[]).map(m=>` <link rel="stylesheet" href="${m}">`).join(`
|
|
7
|
-
`),
|
|
5
|
+
`);o=a.pop()??"";for(let l of a){let d="message",c="";for(let i of l.split(`
|
|
6
|
+
`))i.startsWith("event: ")?d=i.slice(7):i.startsWith("data: ")&&(c+=i.slice(6));if(c)try{yield{name:d,data:JSON.parse(c)}}catch{}}}}finally{n.releaseLock()}}function Kn(e,n,t){t&&(e.length>=1e3&&e.shift(),e.push(n))}function zn(e){return e===401||e===403?"auth_failed":e===429?"rate_limited":e>=500?"provider_error":"invalid_request"}function Gn(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`trace-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function Ze(e,n){let t={messages:[],input:"",streaming:!1,error:null,usage:null,step:null},o=new Set,s=gn(t,hn,n,()=>{for(let l of[...o])l()});Object.assign(t,s),t.subscribe=l=>(o.add(l),()=>{o.delete(l)});let a=e.selfId();if(a){let l=e.onUnmount(d=>{d===a&&(s.dispose(),l())})}return t}function en(e,n){let t=e.selfId(),o;return t&&(o=n.subscribe(()=>e.render([t])),e.onUnmount(()=>o?.())),n}function bn(e){let n=new Map;async function t(s){let a=n.get(s);if(a)return await a,n.has(s)?void 0:t(s);let l=o(s);n.set(s,l);try{await l}finally{n.delete(s)}}async function o(s){let a=e.registry.idRegistry.get(s);if(!a||typeof a._render!="function")return;let l=!!globalThis?.__WF_VDOM_DEBUG;try{let d={browser:e.ctx.browser,registry:e.registry,ctxVersion:e.ctx?.ui?._ctxVersion??0};l&&console.log(`[vdom/trace] render id=${s} comp=${a.type?.name||"?"}`);let c=await a._render(a.props),i=await D(c,e.ctx,a._child,e.registry)??null,u=a._child;a._child=i;let p=a._parentNode??a._refNode?.parentNode??e.rootEl??null;if(p){let g=$(p,a._refNode??null,u,i,d);if(g?a._refNode=g:a._refNode=null,l&&console.log(`[vdom/trace] patch parent=${p.nodeName} ref=${a._refNode?.nodeName??"null"}`),He())try{let h=[];Q(p,i,w=>h.push(w)),h.length?console.error("[weifuwu/audit] "+h.join(" | ")):l&&console.log("[vdom/trace] audit \u2713 \u4E00\u81F4")}catch(h){console.error("[weifuwu/audit] \u6821\u9A8C\u5F02\u5E38:",h)}}}catch(d){e.onError?e.onError(d):console.error("[weifuwu] render error:",d?.stack??d)}}function r(s){if(s==null){let a=e.ctx.ui?._selfId;return a?t(a):Promise.resolve()}return Promise.all(s.map(a=>t(a))).then(()=>{})}return{render:r}}function Te(e){let n=e.registry??Me(),t={_selfId:"_wf_root",_mounting:!1,_ctxVersion:0,_rootVNodeId:void 0},o={browser:e.browser,__registry:n};o.app={navigate:f=>e.browser.navigate(f)};let r=e.renderer??bn({registry:n,ctx:o,rootEl:e.root}),s=!1;t.render=function(f){if(f==null){let m=this._selfId!=="_wf_root"&&this._selfId?this._selfId:t._rootVNodeId;return m?r.render([m]):(s||(s=!0,console.warn("[weifuwu] render() \u65E0\u53C2\u4F46\u65E0\u6E32\u67D3\u76EE\u6807\uFF1A\u9875\u9762\u6839\u662F native vnode\uFF08UIHandler \u76F4\u63A5\u8FD4\u56DE vnode \u7684\u9875\u9762\u5F62\u6001\uFF09\uFF0C\u5185\u90E8\u72B6\u6001\u6E32\u67D3\u65E0\u6548\u3002\u6539\u7528 async \u7EC4\u4EF6\u5F62\u6001\uFF08const Page: Component = async ... => (props) => ...\uFF09\u6216 createStore + useExternal \u5171\u4EAB\u72B6\u6001\u3002")),Promise.resolve())}return r.render(f)},t.setMounting=f=>{t._mounting=f},t.endMounting=()=>{t._mounting=!1},t.onUnmount=function(f){let m=this?._selfVNode?._id??this?._selfId;if(m)return me(n,T=>{T===m&&f()})},o.ui=t;let a=dn(f=>{for(let m of f)r.render([m])}),l=new Map,{popupTrackers:d,scrollTrackers:c,ensurePopupListeners:i,destroyPopupListeners:u,cleanupTrackers:p}=a;me(n,f=>{p(f),d.has(f)&&d.delete(f)});let g=new Set,h=new Map,w=new Map,x=new Map,y=f=>({selfId:()=>{let m=f?._selfVNode?._id??f?._selfId;return typeof m=="string"?m:void 0},render:m=>r.render(m),browser:e.browser,onUnmount:m=>me(n,m),registry:n,mediaRegistry:l,popupTrackers:d,scrollTrackers:c,isMounting:()=>t._mounting===!0,warned:g,uncontrolledValues:h,inputStates:w,openStates:x,ensurePopupListeners:i});return t.bumpCtxVersion=()=>{t._ctxVersion=(t._ctxVersion??0)+1},t.selfId=function(f){if(typeof f!="string"||!f)throw new Error(`[weifuwu] selfId requires a non-empty string, got ${typeof f}`);if(n.idRegistry.has(f))throw new Error(`[weifuwu] Duplicate component ID: "${f}". Each component must have a unique custom ID.`);let m=this._selfVNode;m&&(m._customId=f,n.idRegistry.set(f,m))},t.useChat=function(f){return Ze(y(this),f)},t.useMedia=function(f,m){return We(y(this),f,m)},t.useBreakpoint=function(f,m){return je(y(this),f,m)},t.usePopupPosition=function(f){return Ce(y(this),f)},t.useHoverCapable=function(){return ie(y(this))},t.useStableRef=function(f,m){return Ue(y(this),f,m)},t.useVisualViewport=function(){return $e(y(this))},t.usePopup=function(f){return Je(y(this),f)},t.useLongPress=function(f){return Oe(y(this),f)},t.useInView=function(f){return qe(y(this),f)},t.useScrollPosition=function(f){return Fe(y(this),f)},t.useAsync=function(f){return Ke(y(this),f)},t.useControlled=function(f){return ve(y(this),f)},t.useControlledInput=function(f){return Be(y(this),f)},t.useOpen=function(f){return Xe(y(this),f)},t.usePresence=function(f){return ae(y(this),f)},t.useGlobalKey=function(f){return ze(y(this),f)},t.useDrag=function(f){return Ge(y(this),f)},t.useDragDrop=function(f){return Ye(y(this),f)},t.useExternal=function(f){return en(y(this),f)},t.useReducedMotion=function(){return we(y(this))},t.useAnimationEnd=function(f,m){return Ie(y(this),f,m)},t.useTween=function(f,m){return De(y(this),f,m)},t.destroyPopupListeners=u,{ctx:o,registry:n,renderer:r,rootUi:t,destroyPopupListeners:u}}function Yn(e){let{ctx:n,registry:t,renderer:o,rootUi:r,destroyPopupListeners:s}=Te(e),a=null,l=null;return{ctx:n,registry:t,renderer:o,async mount(c){a=c;let i=await D(c,n,void 0,t);e.root.innerHTML="";let u=U(i,n,e.browser);if(u!=null&&e.root.appendChild(u),He())try{let p=[];Q(e.root,i,g=>p.push(g)),p.length&&console.error("[weifuwu/audit] "+p.join(" | "))}catch(p){console.error("[weifuwu/audit] \u6821\u9A8C\u5F02\u5E38:",p)}l=i?._child??i,r._rootVNodeId=i?._id},async rerender(){if(a==null)return;let c=await D(a,n,a,t,{force:!0}),i=a,u=l,p=i._child,g=e.root.firstChild;$(e.root,g,u,p,{browser:e.browser,registry:t,ctxVersion:n?.ui?._ctxVersion??0,force:!0}),l=p},unmount(){for(let[,c]of t.idRegistry)try{H(c,t)}catch(i){console.error("[weifuwu] unmount ref error",i)}e.root.innerHTML="",t.idRegistry.clear(),s()}}}function Jn(e){return e.__registry??(e.__registry=Me())}function Xn(e,n,t,o){let r=Jn(t),s=t.browser??A();return Promise.resolve(D(n,t,void 0,r)).then(()=>{let a=U(n,t,s);if(a!=null&&e.appendChild(a),n._id&&r){let l=r.idRegistry.get(n._id);l&&(l._parentNode=e)}o?.onMounted?.()}).catch(a=>console.error("[weifuwu] command mount error",a)),{id:n._id??""}}function Qn(e,n,t){let o=t.__registry;n&&o&&(H(n,o),n._id&&ye(o,n._id)),e.remove()}function Zn(){let e=A(),n=e.createElement("div");return n?(e.bodyAppend(n),n):null}function et(e,n){let t=A(),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;!n.hydrate&&!n.loading&&(r.innerHTML="");try{(new URLSearchParams(globalThis?.location?.search??"").get("vdom_debug")==="1"||globalThis?.localStorage?.getItem?.("__WF_VDOM_DEBUG")==="1")&&(globalThis.__WF_VDOM_DEBUG=!0,globalThis.__WF_VDOM_AUDIT=!0,console.log("[weifuwu] vdom debug + audit \u5DF2\u5F00\u542F\uFF08?vdom_debug=1\uFF09"))}catch{}let{ctx:a,registry:l,renderer:d,rootUi:c,destroyPopupListeners:i}=Te({browser:t,root:r}),u=new Map,p=globalThis.__DATA__??window.__DATA__;if(p&&typeof p=="object")for(let[b,v]of Object.entries(p))u.set(b,{value:v});a.data={async get(b,v){let C=u.get(b);if(C&&"value"in C)return C.value;if(C?.promise)return C.promise;if(!v)return;let k=Promise.resolve().then(()=>v()).then(V=>(u.set(b,{value:V}),V));return u.set(b,{promise:k}),k},set(b,v){u.set(b,{value:v})},has(b){return u.has(b)}},a.route={params:{},query:{},path:""};let g=null,h="",w=0,x,y=new Promise(b=>{x=b}),f=!1;async function m(b,v){let C=++w,k={pathname:b,search:""};a.route.path=b;let V;try{V=await e.execute(k,a,b)}catch(N){V=F("div",{class:"ui-dom-error"},`\u9875\u9762\u6E32\u67D3\u5931\u8D25: ${N?.message??String(N)}`)}if(f||C!==w)return;let M;try{M=await D(V,a,g,l)}catch(N){M=F("div",{class:"ui-dom-error"},`\u7EC4\u4EF6\u6E32\u67D3\u5931\u8D25: ${N?.message??String(N)}`)}if(!(f||C!==w)){if(v){r.innerHTML="";let N=U(M,a,t);N!=null&&r.appendChild(N)}else if(g!==void 0){let N=g;g=M;let I=N?.el??N?._refNode??null;$(r,I,N,M,{browser:t,registry:l,ctxVersion:a?.ui?._ctxVersion??0})}g=M,h=b,c._rootVNodeId=M?._id}}let T=t.pathname();m(T,!0).finally(()=>{f||x()});let _=()=>{let b=t.pathname();b!==h&&m(b,!1)};return t.addEventListener("popstate",_),{close(){f=!0,t.removeEventListener("popstate",_),i(),l.idRegistry.clear()},ready:y,ctx:a}}function nn(e){e.node=e.node?e.node.nextSibling:null}function nt(e,n){e.node&&e.node.parentNode?e.node.parentNode.insertBefore(n,e.node):e.parent.appendChild(n)}function tt(e,n){e.node&&e.node.parentNode?(e.node.parentNode.replaceChild(n,e.node),nn(e)):e.parent.appendChild(n)}function ot(e,n){for(let[t,o]of Object.entries(n))t==="children"||t==="key"||t==="innerHTML"||X(e,t,o)}function ue(e,n,t){let o=n.browser??A();if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number"){let d=String(e);if(t.node&&t.node.nodeType===3)return t.node.textContent!==d&&(t.node.textContent=d),nn(t),t.node;let c=o.createTextNode(d);return nt(t,c),c}if(Array.isArray(e)){let d=null;for(let c of e){let i=ue(c,n,t);i!=null&&!d&&(d=i)}return d}let r=e;if(r.type===R||r.type===S){let d=r.props?.children,c=d==null?[]:Array.isArray(d)?d:[d],i=null;for(let u of c){let p=ue(u,n,t);p!=null&&!i&&(i=p)}return i}if(typeof r.type=="function"){let d=r._child;if(d==null){if(typeof r._render!="function")throw new Error(`[vdom] component ${r.type.name||"anonymous"} not built before hydration`);return r._child=null,null}let c=ue(d,n,t);return r._refNode||(r._refNode=c),c}let s=r.type,a=r.props??{},l;if(t.node&&t.node.nodeType===1&&t.node.tagName.toLowerCase()===s.toLowerCase()?(l=t.node,nn(t)):(l=Re.has(s)?o.createElementNS("http://www.w3.org/2000/svg",s):o.createElement(s),tt(t,l)),r.el=l,ot(l,a),!("innerHTML"in a)){let d={parent:l,node:l.firstChild},c=(Array.isArray(a.children)?a.children:[a.children]).flat(1/0);for(let i of c){let u=ue(i,n,d);if(u!=null&&u.parentNode!==l&&l.appendChild(u),i&&typeof i=="object"&&!Array.isArray(i)&&typeof i.type=="function"){let p=i;p._parentNode||(p._parentNode=l,p._refNode=u)}}for(;d.node;){let i=d.node;d.node=i.nextSibling,i.parentNode?.removeChild(i)}}return"value"in a&&l instanceof HTMLSelectElement&&(l.value=String(a.value??"")),l}async function rt(e,n,t){let o=t.__registry;await D(n,t,void 0,o);let r={parent:e,node:e.firstChild};for(ue(n,t,r);r.node;){let s=r.node;r.node=s.nextSibling,s.parentNode?.removeChild(s)}}var st=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),it=new Set(["svg","path","circle","rect","line","polyline","polygon","g","text","defs","use","clipPath"]);function de(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}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 lt(e){return Object.entries(e).filter(([,n])=>n!=null).map(([n,t])=>{let o=n.replace(/[A-Z]/g,s=>"-"+s.toLowerCase()),r=typeof t=="number"&&t!==0?`${t}px`:String(t);return`${o}:${r}`}).join(";")}async function ee(e,n){if(e==null||typeof e=="boolean")return"";if(typeof e=="string"||typeof e=="number")return de(String(e));if(Array.isArray(e))return sn(e),(await Promise.all(e.map(u=>u==null||typeof u=="boolean"?Promise.resolve(`<!--wf-hole: ${B(u)}-->`):ee(u,n)))).join("");let t=e;if(pe(t.type))return console.warn(`[weifuwu] children \u9879\u975E\u6CD5\uFF1Atype=${String(t.type)}\uFF08${typeof t.type}\uFF09\u2014\u2014\u5DF2\u5360\u4F4D\uFF08wf-hole\uFF09`),`<!--wf-hole: ${B(e)}-->`;if(t.type===R||t.type===S)return ee(t.props?.children,n);if(typeof t.type=="function"){let i=Object.create(n),u=await t.type(t.props??{},i);if(typeof u!="function")throw new Error(`Component ${t.type.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);let p=await u(t.props??{});if(t.key!=null&&p!=null&&typeof p=="object")if(Array.isArray(p))for(let g of p)g!=null&&typeof g=="object"&&!Array.isArray(g)&&(g.key=t.key);else p.key=t.key;return ee(p,i)}let o=t.type,r=t.props??{},s=[],a;t.key!=null&&s.push(` data-wf-key="${de(String(t.key))}"`);for(let[i,u]of Object.entries(r))if(!(i==="children"||i==="key")&&i!=="ref"&&!(i.startsWith("on")&&typeof u=="function")){if(i==="innerHTML"){a=String(u??"");continue}if(i==="class"||i==="className"){let p=at(u);p&&s.push(` class="${de(p)}"`);continue}if(i==="style"&&u&&typeof u=="object"){s.push(` style="${de(lt(u))}"`);continue}if(oe.has(i)){s.push(` ${i}="${u?"true":"false"}"`);continue}if(u===!0){s.push(` ${i}`);continue}u===!1||u==null||s.push(` ${i}="${de(String(u))}"`)}let l=s.join(""),d=it.has(o);if(st.has(o))return`<${o}${l}>`;if(a!==void 0)return`<${o}${l}>${a}</${o}>`;let c=await ee(r.children,n);return d?`<${o}${l}>${c}</${o}>`:`<${o}${l}>${c}</${o}>`}function ut(){let e=()=>()=>{},n=()=>({});return{_selfId:"_wf_root",render:()=>{},selfId:()=>{},bumpCtxVersion:()=>{},setMounting:()=>{},endMounting:()=>{},onUnmount:()=>{},useChat:()=>({messages:[],input:"",streaming:!1,error:null,usage:null,step:null,send:()=>{},stop:()=>{},retry:()=>{},clear:()=>{},approve:()=>{},subscribe:()=>()=>{}}),useExternal:t=>t,useMedia:e,useBreakpoint:e,usePopupPosition:()=>({top:0,left:0,refresh:()=>{}}),useHoverCapable:()=>!1,useStableRef:t=>o=>{o&&t?.(o)},useVisualViewport:()=>({height:0,offsetTop:0,keyboardOpen:!1}),usePopup:()=>({open:!1,setOpen:()=>{},phase:"closed",sync:t=>t?"open":"closed",wrapProps:{},portal:t=>t,refresh:()=>{}}),useLongPress:n,useInView:()=>({isIn:!1,ready:!1,observe:()=>{},refresh:()=>{},disconnect:()=>{}}),useScrollPosition:()=>({y:0,refresh:()=>{}}),useAsync:()=>({data:void 0,loading:!0,error:void 0,reload:()=>{}}),useControlled:()=>({value:void 0,setValue:()=>{},controlled:!1}),useControlledInput:()=>({value:void 0,setValue:()=>{},keyword:"",setKeyword:()=>{},selectedLabel:"",setSelectedLabel:()=>{},controlled:!1}),useOpen:()=>({open:!1,setOpen:()=>{},triggerProps:{}}),usePresence:()=>({phase:"closed",ref:()=>{},sync:()=>"closed"}),useGlobalKey:()=>()=>{},useDrag:n,useDragDrop:()=>({dropProps:{},dragProps:{}}),useReducedMotion:()=>!0,useAnimationEnd:()=>()=>{},useTween:t=>{let o=t;return{get value(){return o},set value(r){o=r},reset:r=>(r!==void 0&&(o=r),o)}}}}function wn(e,n){let t={...e,ui:ut(),browser:void 0},o=new Map;return t.data={async get(r,s){let a=o.get(r);if(a&&"value"in a)return a.value;if(a?.promise)return a.promise;if(!s)return;let l=Promise.resolve().then(()=>s()).then(d=>(o.set(r,{value:d}),n.set(r,d),d));return o.set(r,{promise:l}),l},set(r,s){o.set(r,{value:s}),n.set(r,s)},has(r){return o.has(r)}},t}function vn(e){return`<script>window.__DATA__=${JSON.stringify(Object.fromEntries(e)).replace(/</g,"\\u003c")};<\/script>`}async function dt(e,n){let t=new Map,r=wn({params:{},query:{}},t),s=n.url.split("?")[0].split("#")[0],a=e.match(s);r.params=a.params,r.query=Object.fromEntries(new URLSearchParams(n.url.split("?")[1]??""));let l=new URL(n.url.startsWith("http")?n.url:`http://localhost${n.url.startsWith("/")?n.url:"/"+n.url}`),d=await e.execute(l,r,s),c=await ee(d,r),i=vn(t),u=a.title??n.title??"",p=n.rootId??"root",g=(n.styles??[]).map(w=>` <link rel="stylesheet" href="${w}">`).join(`
|
|
7
|
+
`),h=`<!DOCTYPE html>
|
|
8
8
|
<html lang="${n.lang??"zh-CN"}">
|
|
9
9
|
<head>
|
|
10
10
|
<meta charset="UTF-8">
|
|
11
11
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
12
|
-
${
|
|
13
|
-
${
|
|
12
|
+
${u?`<title>${u}</title>`:""}
|
|
13
|
+
${g}
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
|
-
<div id="${p}">${
|
|
17
|
-
${
|
|
16
|
+
<div id="${p}">${c}</div>
|
|
17
|
+
${i}
|
|
18
18
|
<script src="/app.js"><\/script>
|
|
19
19
|
</body>
|
|
20
|
-
</html>`;return{html:
|
|
20
|
+
</html>`;return{html:c,dataScript:i,page:h}}async function ct(e,n,t,o={}){let r=o.data??new Map,s=wn(t,r);return ee({type:e,props:n??{},key:void 0},s)}function ft(e){let n={...e},t=new Set,o=()=>{for(let r of[...t])r()};return{state:n,subscribe(r){return t.add(r),()=>{t.delete(r)}},set(r){Object.assign(n,r),o()},update(r){r(n),o()},notify:o}}export{S as Fragment,R as Portal,ke as UIRouter,kn as animateOut,Pn as api,Rn as auth,D as buildVNode,A as createClientBrowser,Zn as createCommandContainer,fe as createPortal,bn as createRenderer,ft as createStore,Te as createVdomContext,F as h,rt as hydrateVNode,Pe as jsx,_n as jsxDEV,Vn as jsxs,Xn as mountCommand,Yn as mountRoot,$ as patchValue,U as renderValue,vn as serializeData,dt as ssrPage,ct as ssrToString,et as uiServe,Qn as unmountCommand,Mn as ws};
|
package/dist/ui-dom/testing.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var P=Symbol("Fragment"),T=Symbol("Portal");function S(e){if(e==null||typeof e=="boolean")return[];if(Array.isArray(e)){let n=!1;for(let o=0;o<e.length;o++)if(Array.isArray(e[o])){n=!0;break}if(!n)return e;let t=[],r=[...e].reverse();for(;r.length>0;){let o=r.pop();if(Array.isArray(o))for(let i=o.length-1;i>=0;i--)r.push(o[i]);else t.push(o)}return t}return[e]}function q(e,n){if(e===n)return!0;let t=Object.keys(e),r=Object.keys(n);if(t.length!==r.length)return!1;for(let o of t)if(e[o]!==n[o])return!1;return!0}async function K(e,n,t,r){e._id||(r?.reuse?._id?e._id=r.reuse._id:e._id=t.nextId(),t.idRegistry.set(e._id,e)),r?.reuse&&(r.reuse._parentNode&&(e._parentNode=r.reuse._parentNode),r.reuse._refNode&&(e._refNode=r.reuse._refNode),r.reuse._ctxVersion!=null&&(e._ctxVersion=r.reuse._ctxVersion));let o=Object.create(n);o.ui=Object.create(n.ui);let i=o.ui;if(i._selfId=e._id,i._selfVNode=e,i.render=function(s){return s==null&&e._id?n.ui.render([e._id]):n.ui.render(s)},typeof e._render!="function"&&typeof r?.reuse?._render=="function"&&(e._render=r.reuse._render),typeof e._render!="function"){n.ui?.setMounting?.(!0);let s;try{s=await e.type(e.props??{},o)}finally{n.ui?.endMounting?.()}if(typeof s!="function")throw new Error(`Component ${e.type.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);e._render=s}return{renderFn:e._render,childCtx:o}}function O(e){return!!e&&typeof e.then=="function"}function E(e,n,t,r,o){if(e==null||typeof e=="boolean"||typeof e=="string"||typeof e=="number")return e;if(Array.isArray(e)){let u=Array.isArray(t)?t:[],l=e.map((y,g)=>E(y,n,u[g],r,o)),d=!1;for(let y=0;y<l.length;y++)if(O(l[y])){d=!0;break}return d?Promise.all(l).then(()=>e):e}let i=e,s=r??n.__registry,f=t!=null&&typeof t=="object"&&!Array.isArray(t)&&t.type===i.type?t:null;if(typeof i.type=="function"){i._id||(i._id=f?._id??s.nextId(),s.idRegistry.set(i._id,i)),f&&(f._parentNode&&(i._parentNode=f._parentNode),f._refNode&&(i._refNode=f._refNode),f._ctxVersion!=null&&(i._ctxVersion=f._ctxVersion),typeof f._render=="function"&&(i._render=f._render));let u=q(f?.props??{},i.props??{}),l=n?.ui?._ctxVersion??0,d=(f?._ctxVersion??-1)===l;return!o?.force&&u&&d&&f?._child!=null?(i._child=f._child,i._ctxVersion=f._ctxVersion,i):(async()=>{let{childCtx:y}=await K(i,n,s,{reuse:f??void 0}),g=await E(await i._render(i.props),y,f?._child,s);return i._child=g??null,i._ctxVersion=l,i})()}if(i.type===P){let u=E(i.props?.children??null,n,f?._child??f?.props?.children,s);return O(u)?u.then(l=>(i._child=l??null,i)):(i._child=u??null,i)}if(typeof i.type=="string"||typeof i.type=="symbol"){let u=E(i.props?.children??null,n,f?.props?.children,s);return O(u)?u.then(l=>(i._child=l??null,i)):(i._child=u??null,i)}return i}var z=new Set(["svg","path","circle","rect","line","polyline","polygon","g","text","defs","use","clipPath"]),j=/^on[A-Z]/,G=new Set(["zIndex","opacity","lineHeight","fontWeight","fontSizeAdjust","flex","flexGrow","flexShrink","order","zoom","aspectRatio","gridRow","gridColumn","scale","rotate","animationIterationCount","columnCount","fillOpacity","strokeOpacity","stopOpacity","floodOpacity"]);function D(e,n,t){if(t==null||t===!1)return;let r=e.ownerDocument?.defaultView;if(n==="class"||n==="className"){if(typeof t=="object")for(let[o,i]of Object.entries(t))i&&e.classList.add(o);else e.setAttribute("class",String(t));return}if(n==="style"){if(typeof t=="string")e.setAttribute("style",t);else{let o=e.style;for(let[i,s]of Object.entries(t))s==null?o[i]="":i.startsWith("--")?o.setProperty(i,String(s)):typeof s=="number"&&!G.has(i)?o[i]=`${s}px`:o[i]=String(s)}return}if(n==="ref"){if(typeof t=="function")try{t(e)}catch(o){console.error("[weifuwu] ref error",o)}return}if(j.test(n)){let o=n.slice(2).toLowerCase();if(typeof t!="function"){console.warn(`[weifuwu] event prop ${n} expects a function, got ${typeof t} \u2014 ignored`);return}e.addEventListener(o,t);return}if(n==="value"){e.value=t;return}if(n==="indeterminate"){e.indeterminate=!!t;return}if(n==="innerHTML"){e.innerHTML=String(t??"");return}if(n==="draggable"||n==="contenteditable"||n==="spellcheck"){e.setAttribute(n,t?"true":"false");return}if(n.startsWith("aria-")&&typeof t=="boolean"){e.setAttribute(n,t?"true":"false");return}if(t===!0){e.setAttribute(n,"");return}try{e[n]=t,e.getAttribute(n)!==String(t)&&e.setAttribute(n,String(t))}catch{e.setAttribute(n,String(t))}}function C(e,n,t){let r=n?.browser??t;if(!r)throw new Error("[vdom] renderValue requires browser env (ctx.browser)");if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number")return r.createTextNode(String(e));if(Array.isArray(e)){let u=r.createDocumentFragment();if(!u)return null;for(let l of e){let d=C(l,n,r);d!=null&&u.appendChild(d)}return u}let o=e;if(o.type===T){let u=r.bodyElement();if(!u)return null;let l=u.querySelector("#__wf_portal");l||(l=r.createElement("div"),l&&(l.id="__wf_portal",u.appendChild(l)));let d=r.createElement("div");if(d){d.setAttribute("data-portal",String(o.props?.portalKey??"wf"));let y=C(o.props?.children??null,n,r);y!=null&&d.appendChild(y),l&&l.appendChild(d),o._remoteEl=d}return null}if(o.type===P){let u=r.createDocumentFragment();if(!u)return null;for(let l of S(o.props?.children)){let d=C(l,n,r);d!=null&&u.appendChild(d)}return o._childNodes=Array.from(u.childNodes),u}if(typeof o.type=="function"){if(typeof o._render!="function")throw new Error(`[vdom] component ${o.type.name||"anonymous"} not built (missing _render) \u2014 buildVNode must run before renderValue`);if(o._child===void 0)throw new Error(`[vdom] component ${o.type.name||"anonymous"} not built (missing _child) \u2014 buildVNode must run before renderValue`);let u=o._child;if(u==null)return o._child=null,null;let l=(Array.isArray(u)||typeof u=="object"&&typeof u.type=="function",u);o._child=l,typeof l=="object"&&!Array.isArray(l)&&(l._parentVNode=o);let d=C(l,n,r);return d&&(o._refNode=d),d}let i=o.type,s=z.has(i)?r.createElementNS("http://www.w3.org/2000/svg",i):r.createElement(i);if(!s)return null;o.el=s;let f;for(let[u,l]of Object.entries(o.props??{}))if(!(u==="children"||u==="key")){if(u==="value"&&s instanceof HTMLSelectElement){f=l;continue}D(s,u,l)}if(!("innerHTML"in(o.props??{})))for(let u of S(o.props?.children)){let l=C(u,n,r);if(l!=null&&(s.appendChild(l),u&&typeof u=="object"&&!Array.isArray(u)&&typeof u.type=="function")){let d=u;d._parentNode||(d._parentNode=s,d._refNode=l)}}return f!==void 0&&(s.value=String(f)),s}function v(){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,r=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[r](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 r=document.execCommand("copy");return document.body.removeChild(t),r}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 X=0;function L(){return{idRegistry:new Map,unmountHooks:[],nextId:()=>`_wf_${X++}`}}function B(e,n){for(let t of[...e.unmountHooks])t(n);e.idRegistry.delete(n),e.idRegistry.delete(`custom:${n}`)}function Y(e,n,t,r){try{e(n)}catch(o){console.error(`[weifuwu] ref ${t} error in <${r??"anonymous"}>`,o)}}function _(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 r=[...n.unmountHooks];for(let o of r)o(t._id);if(t._customId)for(let o of r)o(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 r of t._child)r&&typeof r=="object"&&_(r,n);else _(t._child,n);t._child=void 0}if(t.props?.children&&typeof t.type=="string"){let r=Array.isArray(t.props.children)?t.props.children:[t.props.children];for(let o of r)o&&typeof o=="object"&&_(o,n)}if(typeof t.props?.ref=="function"&&Y(t.props.ref,null,"cleanup"),t._remoteEl){let r=t._child;if(r!=null)if(Array.isArray(r))for(let o of r)o&&typeof o=="object"&&_(o,n);else typeof r=="object"&&_(r,n);t._remoteEl.remove(),t._remoteEl=void 0}}function W(e,n){if(n&&typeof e.type=="function"&&e._id){try{_(e,n)}catch(t){console.error("[weifuwu] ref cleanup error",t)}B(n,e._id)}}function M(e){if(e==null||typeof e!="object"||Array.isArray(e))return;let n=e;return n._placement==="remote"?n.props?.portalKey:n.key}function $(e,n){if(n&&e&&typeof e=="object"&&!Array.isArray(e)&&e.type===P){let t=e._childNodes;if(t&&t.length)return t}return[n]}function k(e,n,t,r,o){if(typeof r=="string"||typeof r=="number"){if(typeof t=="string"||typeof t=="number"){if(String(t)!==String(r)){if(n&&n.nodeType===3)return n.nodeValue=String(r),n;let y=e.ownerDocument.createTextNode(String(r));return n?.parentNode?n.parentNode.replaceChild(y,n):e.appendChild(y),y}return n}let d=e.ownerDocument.createTextNode(String(r));return n?.parentNode?n.parentNode.replaceChild(d,n):e.appendChild(d),d}if(r==null||typeof r=="boolean"){if(t&&typeof t=="object"&&!Array.isArray(t)&&t.type===T){let d=t._remoteEl;try{_(t.props?.children,o.registry)}catch(y){console.error("[weifuwu] portal ref cleanup error",y)}return d?.parentNode?.removeChild(d),null}if(t&&typeof t=="object"&&!Array.isArray(t))if(typeof t.type=="function")W(t,o.registry);else try{_(t,o.registry)}catch(d){console.error("[weifuwu] ref cleanup error",d)}return n?.parentNode&&n.parentNode.removeChild(n),null}if(Array.isArray(r)){if(t===r&&n?.parentNode)return n;let d=e.ownerDocument.createDocumentFragment(),y=H(e,t,r,o,n?[n]:void 0);for(let g of y)g&&d.appendChild(g);return n?.parentNode?d.contains(n)?e.appendChild(d):n.parentNode.replaceChild(d,n):e.appendChild(d),d}let i=r;if(i.type===T){let d=t&&typeof t=="object"&&!Array.isArray(t)?t:null;if(d?.type===T){let y=d._remoteEl;if(y){let g=d.props?.children??null,A=i.props?.children??null;H(y,g,A,o)}return i._remoteEl=d._remoteEl,null}return C(i,o,o.browser??v()),null}if(i.type===P){let d=t&&typeof t=="object"&&!Array.isArray(t)?t:null,y=d?._childNodes,g=H(e,d?.props?.children??t,i.props?.children??null,o,y);return i._childNodes=g.filter(Boolean),n?.parentNode&&n.nodeType===8&&n.parentNode.removeChild(n),n&&n.nodeType===1?n:g[0]??null}if(typeof i.type=="function"){if(typeof i._render!="function")throw new Error(`[vdom] component ${i.type.name||"anonymous"} not built in diff \u2014 buildVNode must run before patchValue`);let d=t&&typeof t=="object"&&!Array.isArray(t)?t:null,y=d?.type===i.type;if(!o.force&&d&&y&&d._child!==void 0&&i._child===d._child)return n;d?.type===i.type&&d._id&&(i._id=d._id,o.registry.idRegistry.set(i._id,i)),i._parentNode=e,n&&(i._refNode=n);let g;if(i._child===void 0)throw new Error(`[vdom] component ${i.type.name||"anonymous"} not built (missing _child) \u2014 buildVNode must run before patchValue`);g=i._child;let A=k(e,n,d?._child,g,o);return A&&(i._refNode=A),A}let s=t&&typeof t=="object"&&!Array.isArray(t)?t:null,f=s?.type??null,u=i.type;if(n&&n.nodeType===1&&f===u){let d=n;return i.el=d,J(d,s?.props??{},i.props??{}),H(d,s?.props?.children??null,i.props?.children??null,o),d}let l=C(i,o,o.browser??v());if(l==null)return null;if(n?.parentNode)if(t!=null&&typeof t!="boolean"){if(typeof t=="object"&&!Array.isArray(t))try{_(t,o.registry)}catch(d){console.error("[weifuwu] ref cleanup error",d)}n.parentNode.replaceChild(l,n)}else n.parentNode.insertBefore(l,n);else e.appendChild(l);return l}function J(e,n,t){let r=Object.keys(n),o=Object.keys(t);if(r.length===o.length){let s=!0;for(let f=0;f<r.length;f++)if(r[f]!==o[f]||n[r[f]]!==t[r[f]]){s=!1;break}if(s)return}let i=new Set([...r,...o]);for(let s of i){if(s==="children"||s==="key")continue;let f=n[s],u=t[s];if(f!==u){if(j.test(s)){typeof f=="function"&&e.removeEventListener(s.slice(2).toLowerCase(),f),u!=null&&u!==!1&&(typeof u!="function"?console.warn(`[weifuwu] event prop ${s} expects a function, got ${typeof u} \u2014 ignored`):e.addEventListener(s.slice(2).toLowerCase(),u));continue}if(u==null||u===!1){if(s==="class"||s==="className")e.removeAttribute("class");else if(j.test(s))e.removeEventListener(s.slice(2).toLowerCase(),f);else if(s==="ref"){if(typeof f=="function")try{f(null)}catch(l){console.error("[weifuwu] ref cleanup error",l)}}else if(s==="value")e.value="";else if(s==="indeterminate")e.indeterminate=!1;else{e.removeAttribute(s);try{delete e[s]}catch{}}continue}D(e,s,u)}}}function H(e,n,t,r,o){let i=S(n),s=S(t),f=o??Array.from(e.childNodes);if(s.some(a=>{if(a==null||typeof a!="object"||Array.isArray(a))return!1;let c=a;return c._placement!=="remote"&&c.key!==void 0})){for(let a=0;a<s.length;a++){let c=s[a];c&&typeof c=="object"&&!Array.isArray(c)&&M(c)===void 0&&(c.key=`pos:${a}`)}for(let a=0;a<i.length;a++){let c=i[a];c&&typeof c=="object"&&!Array.isArray(c)&&M(c)===void 0&&(c.key=`pos:${a}`)}}let l=i.map((a,c)=>{if(a==null||typeof a!="object"||Array.isArray(a))return f[c]??null;let p=a;return p._placement==="remote"?p._remoteEl??null:p.type===P?p._childNodes?.[0]??null:p._refNode??p.el??null});if(!s.some(a=>{if(a==null||typeof a!="object"||Array.isArray(a))return!1;let c=a;return c._placement!=="remote"&&c.key!==void 0})){let a=Math.max(i.length,s.length),c=[];for(let p=0;p<a;p++){let h=p<i.length?i[p]:null,m=p<s.length?s[p]:null;if(m==null||typeof m=="boolean"){if(h&&typeof h=="object"&&!Array.isArray(h))if(typeof h.type=="function")W(h,r.registry);else try{_(h,r.registry)}catch(w){console.error("[weifuwu] ref cleanup error",w)}let N=l[p];N?.parentNode&&N.parentNode.removeChild(N),c.push(null);continue}if(h!=null&&typeof h=="object"&&!Array.isArray(h)&&m!=null&&typeof m=="object"&&!Array.isArray(m)&&m===h){c.push(l[p]);continue}if(h==null||typeof h=="boolean"){let N=C(m,r,r.browser??v());if(N==null){c.push(null);continue}let w=null;for(let V=p+1;V<l.length;V++){let b=l[V];if(b&&b.parentNode===e){w=b;break}}if(!w){let V=null;for(let b=c.length-1;b>=0;b--)if(c[b]){V=c[b];break}if(V&&V.parentNode===e&&(w=V.nextSibling),!w){let b=l[l.length-1];b&&b.parentNode===e&&(w=b.nextSibling)}}w&&w.parentNode===e?e.insertBefore(N,w):e.appendChild(N),c.push(N);continue}let x=k(e,l[p],h,m,r);c.push(...$(m,x))}return c}let y=new Map;i.forEach((a,c)=>{let p=M(a);p!==void 0&&a&&typeof a=="object"&&!Array.isArray(a)&&y.set(p,{vnode:a,nodes:[l[c]??null].filter(Boolean),index:c})});let g=[],A=new Set,R=null;return s.forEach((a,c)=>{let p=M(a),h=a;if(p!==void 0&&y.has(p)){let m=y.get(p),x=m.nodes[0]??null;A.add(p);let N=k(e,x,m.vnode,h,r),w=$(h,N),V=w[w.length-1]??N;V&&V.parentNode===e&&R&&V.previousSibling!==R&&e.insertBefore(V,R.nextSibling),g.push(...w),V&&(R=V)}else if(h?._placement==="remote"){let m=i[c]??null,x=k(e,l[c]??null,m,h,r),N=$(h,x);g.push(...N);let w=N[N.length-1]??x;w&&(R=w)}else{let m=C(h,r,r.browser??v());g.push(m),m!=null&&(R?e.insertBefore(m,R.nextSibling):e.insertBefore(m,e.firstChild),R=m)}}),i.forEach((a,c)=>{let p=M(a),h=a&&typeof a=="object"&&!Array.isArray(a)&&typeof a.type=="function";if(p!==void 0&&!A.has(p)){if(a&&typeof a=="object"&&!Array.isArray(a))if(h)W(a,r.registry);else try{_(a,r.registry)}catch(x){console.error("[weifuwu] ref cleanup error",x)}let m=l[c];m?.parentNode&&m.parentNode.removeChild(m)}else if(p===void 0){if(a&&typeof a=="object"&&!Array.isArray(a))if(h)W(a,r.registry);else try{_(a,r.registry)}catch(x){console.error("[weifuwu] ref cleanup error",x)}let m=l[c];m?.parentNode&&m.parentNode.removeChild(m)}}),g}function Z(e){return e.__registry??(e.__registry=L())}function U(e,n,t,r){let o=Z(t),i=t.browser??v();return Promise.resolve(E(n,t,void 0,o)).then(()=>{let s=C(n,t,i);if(s!=null&&e.appendChild(s),n._id&&o){let f=o.idRegistry.get(n._id);f&&(f._parentNode=e)}r?.onMounted?.()}).catch(s=>console.error("[weifuwu] command mount error",s)),{id:n._id??""}}function _e(e,n,t){return new Promise(r=>{U(e,n,t,{onMounted:r})})}async function be(e,n,t,r,o){return await E(r,o,t,o.__registry),k(e,n,t,r,{browser:o.browser??o.__browser,registry:o.__registry})}function Ce(e,n){let t=n.__registry??(n.__registry=L());return Promise.resolve(E(e,n,void 0,t))}async function xe(e,n,t){let r=await e(n,t);return typeof r=="function"?r(n):r}async function Ee(e,n,t){let r=await e(n,t);return()=>typeof r=="function"?r(n):r}function F(e,n){if(e==null||typeof e!="object")return;if(Array.isArray(e)){for(let r of e)F(r,n);return}n(e);let t=e?.props?.children;t!=null&&F(t,n)}function Ae(e,n){let t;return F(e,r=>{!t&&n(r)&&(t=r)}),t}function Re(e,n){let t=[];return F(e,r=>{typeof r?.props?.class=="string"&&r.props.class.split(" ").includes(n)&&t.push(r)}),t}function Pe(e){let n={ui:{render:()=>{},ready:!0,useExternal:()=>{}}};return e?{ui:{...n.ui,...e.ui??{}},...e.browser?{browser:e.browser}:{}}:n}function ve(e=()=>!1,n){return{get open(){return e()},setOpen:n??(t=>{}),refresh:()=>{},portal:(t,r)=>e()?t:null,wrapProps:{}}}export{Ce as buildToDom,ve as createPopupMock,Pe as createTestCtx,Re as findByClass,Ae as findVNode,Ee as mountComponent,_e as mountToDom,be as patchToDom,xe as renderVNode,F as walkVNode};
|
|
1
|
+
var R=Symbol("Fragment"),j=Symbol("Portal");function W(e){if(e==null||typeof e=="boolean")return[];if(Array.isArray(e)){let n=!1;for(let o=0;o<e.length;o++)if(Array.isArray(e[o])){n=!0;break}if(!n)return e;let t=[],r=[...e].reverse();for(;r.length>0;){let o=r.pop();if(Array.isArray(o))for(let i=o.length-1;i>=0;i--)r.push(o[i]);else t.push(o)}return t}return[e]}function ne(e,n){if(e===n)return!0;let t=Object.keys(e),r=Object.keys(n);if(t.length!==r.length)return!1;for(let o of t)if(e[o]!==n[o])return!1;return!0}async function te(e,n,t,r){e._id||(r?.reuse?._id?e._id=r.reuse._id:e._id=t.nextId(),t.idRegistry.set(e._id,e)),r?.reuse&&(r.reuse._parentNode&&(e._parentNode=r.reuse._parentNode),r.reuse._refNode&&(e._refNode=r.reuse._refNode),r.reuse._ctxVersion!=null&&(e._ctxVersion=r.reuse._ctxVersion));let o=Object.create(n);o.ui=Object.create(n.ui);let i=o.ui;if(i._selfId=e._id,i._selfVNode=e,i.render=function(d){return d==null&&e._id?n.ui.render([e._id]):n.ui.render(d)},typeof e._render!="function"&&typeof r?.reuse?._render=="function"&&(e._render=r.reuse._render),typeof e._render!="function"){n.ui?.setMounting?.(!0);let d;try{d=await e.type(e.props??{},o)}finally{n.ui?.endMounting?.()}if(typeof d!="function")throw new Error(`Component ${e.type.name||"anonymous"} must return a render function. Use (init_props, ctx) => (props) => VNode pattern.`);e._render=d}return{renderFn:e._render,childCtx:o}}function J(e){return!!e&&typeof e.then=="function"}function P(e,n,t,r,o){if(e==null||typeof e=="boolean"||typeof e=="string"||typeof e=="number")return e;if(Array.isArray(e)){let m=Array.isArray(t)?t:[];for(let l=0;l<e.length;l++){let h=e[l];if(h!=null&&typeof h=="object"&&!Array.isArray(h)){let b=h;b.key===void 0?b.key=String(l):b.key=String(b.key)}}let f=e.map((l,h)=>P(l,n,m[h],r,o)),s=!1;for(let l=0;l<f.length;l++)if(J(f[l])){s=!0;break}return s?Promise.all(f).then(()=>e):e}let i=e,d=r??n.__registry,u=t!=null&&typeof t=="object"&&!Array.isArray(t)&&t.type===i.type?t:null;if(typeof i.type=="function"){i._id||(i._id=u?._id??d.nextId(),d.idRegistry.set(i._id,i)),u&&(u._parentNode&&(i._parentNode=u._parentNode),u._refNode&&(i._refNode=u._refNode),u._ctxVersion!=null&&(i._ctxVersion=u._ctxVersion),typeof u._render=="function"&&(i._render=u._render));let m=ne(u?.props??{},i.props??{}),f=n?.ui?._ctxVersion??0,s=(u?._ctxVersion??-1)===f;return!o?.force&&m&&s&&u?._child!=null?(i._child=u._child,i._ctxVersion=u._ctxVersion,i):(async()=>{let{childCtx:l}=await te(i,n,d,{reuse:u??void 0}),h=await P(await i._render(i.props),l,u?._child,d);return i._child=h??null,i._ctxVersion=f,i})()}if(i.type===R){let m=P(i.props?.children??null,n,u?._child??u?.props?.children,d);return J(m)?m.then(f=>(i._child=f??null,i)):(i._child=m??null,i)}if(typeof i.type=="string"||typeof i.type=="symbol"){let m=P(i.props?.children??null,n,u?.props?.children,d);return J(m)?m.then(f=>(i._child=f??null,i)):(i._child=m??null,i)}return i}function U(e){if(e===!1)return"false";if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0)return"true";if(typeof e=="object")try{let n=JSON.stringify(e);return`object ${n!=null&&n.length>80?n.slice(0,80)+"\u2026":n??""}`}catch{return`object ${Object.prototype.toString.call(e)}`}return`bad-vnode type=${typeof e}`}var D=/^on[A-Z]/,re=/^on[A-Z].*Capture$/;function B(e){let n=re.test(e);return{type:(n?e.slice(2,-7):e.slice(2)).toLowerCase(),capture:n}}var X=new Set(["draggable","contenteditable","spellcheck","translate"]),I=new Set(["zIndex","opacity","lineHeight","fontWeight","fontSizeAdjust","flex","flexGrow","flexShrink","order","zoom","aspectRatio","gridRow","gridColumn","scale","rotate","animationIterationCount","columnCount","fillOpacity","strokeOpacity","stopOpacity","floodOpacity"]);var oe=new Set(["svg","path","circle","rect","line","polyline","polygon","g","text","defs","use","clipPath"]);function q(e,n,t){if(t==null)return;let r=e.ownerDocument?.defaultView;if(X.has(n)){e.setAttribute(n,t?"true":"false");return}if(t!==!1){if(n==="class"||n==="className"){if(typeof t=="object")for(let[o,i]of Object.entries(t))i&&e.classList.add(o);else e.setAttribute("class",String(t));return}if(n==="style"){if(typeof t=="string")e.setAttribute("style",t);else{let o=e.style;for(let[i,d]of Object.entries(t))d==null?o[i]="":i.startsWith("--")?o.setProperty(i,String(d)):typeof d=="number"&&!I.has(i)?o[i]=`${d}px`:o[i]=String(d)}return}if(n==="ref"){if(typeof t=="function")try{t(e)}catch(o){console.error("[weifuwu] ref error",o)}return}if(D.test(n)){let{type:o,capture:i}=B(n);if(typeof t!="function"){console.warn(`[weifuwu] event prop ${n} expects a function, got ${typeof t} \u2014 ignored`);return}e.addEventListener(o,t,i?{capture:!0}:void 0);return}if(n==="value"){e.value=t;return}if(n==="indeterminate"){e.indeterminate=!!t;return}if(n==="innerHTML"){e.innerHTML=String(t??"");return}if(n.startsWith("aria-")&&typeof t=="boolean"){e.setAttribute(n,t?"true":"false");return}if(t===!0){e.setAttribute(n,"");return}try{e[n]=t,e.getAttribute(n)!==String(t)&&e.setAttribute(n,String(t))}catch{e.setAttribute(n,String(t))}}}function H(e,n){return e.createComment(`wf-hole: ${U(n)}`)}function T(e,n,t){let r=n?.browser??t;if(!r)throw new Error("[vdom] renderValue requires browser env (ctx.browser)");if(e==null||typeof e=="boolean")return null;if(typeof e=="string"||typeof e=="number")return r.createTextNode(String(e));if(Array.isArray(e)){let f=r.createDocumentFragment();if(!f)return null;for(let s of e){let l=s==null||typeof s=="boolean"?H(r,s):T(s,n,r);l!=null&&f.appendChild(l)}return f}let o=e,i=o.type;if(typeof i!="string"&&typeof i!="function"&&i!==R&&i!==j)return console.warn(`[weifuwu] children \u9879\u975E\u6CD5\uFF1Atype=${String(i)}\uFF08${typeof i}\uFF09\uFF0C\u503C=${U(e)}\u2014\u2014\u5DF2\u5360\u4F4D\uFF08wf-hole\uFF09\uFF0C\u68C0\u67E5\u4F20\u5165\u7684 children`),H(r,e);if(o.type===j){let f=r.bodyElement();if(!f)return null;let s=f.querySelector("#__wf_portal");s||(s=r.createElement("div"),s&&(s.id="__wf_portal",f.appendChild(s)));let l=r.createElement("div");if(l){l.setAttribute("data-portal",String(o.props?.portalKey??"wf"));let h=T(o.props?.children??null,n,r);h!=null&&l.appendChild(h),s&&s.appendChild(l),o._remoteEl=l}return null}if(o.type===R){let f=r.createDocumentFragment();if(!f)return null;for(let s of W(o.props?.children)){let l=s==null||typeof s=="boolean"?H(r,s):T(s,n,r);l!=null&&f.appendChild(l)}return o._childNodes=Array.from(f.childNodes),f}if(typeof o.type=="function"){if(typeof o._render!="function")throw new Error(`[vdom] component ${o.type.name||"anonymous"} not built (missing _render) \u2014 buildVNode must run before renderValue`);if(o._child===void 0)throw new Error(`[vdom] component ${o.type.name||"anonymous"} not built (missing _child) \u2014 buildVNode must run before renderValue`);let f=o._child;if(f==null)return o._child=null,null;let s=(Array.isArray(f)||typeof f=="object"&&typeof f.type=="function",f);o._child=s,typeof s=="object"&&!Array.isArray(s)&&(s._parentVNode=o);let l=T(s,n,r);if(l){if(o._refNode=l,o._id)if(l.nodeType===11)for(let h of Array.from(l.childNodes))h.nodeType===1&&h.setAttribute("data-wf-id",o._id);else l.nodeType===1&&l.setAttribute("data-wf-id",o._id);if(o.key!=null)if(l.nodeType===11)for(let h of Array.from(l.childNodes))h.nodeType===1&&h.setAttribute("data-wf-key",o.key);else l.nodeType===1&&l.setAttribute("data-wf-key",o.key)}return l}let d=o.type,u=oe.has(d)?r.createElementNS("http://www.w3.org/2000/svg",d):r.createElement(d);if(!u)return null;o.el=u,o.key!=null&&u.setAttribute("data-wf-key",o.key);let m;for(let[f,s]of Object.entries(o.props??{}))if(!(f==="children"||f==="key")){if(f==="value"&&u instanceof HTMLSelectElement){m=s;continue}q(u,f,s)}if(!("innerHTML"in(o.props??{}))){let f=[];for(let s of W(o.props?.children)){let l=s==null||typeof s=="boolean"?H(r,s):T(s,n,r);if(l==null){f.push(null);continue}if(u.appendChild(l),f.push(l.nodeType===11?l.firstChild:l),s&&typeof s=="object"&&!Array.isArray(s)&&typeof s.type=="function"){let h=s;h._parentNode||(h._parentNode=u,h._refNode=l)}}o._childAnchors=f}return m!==void 0&&(u.value=String(m)),u}function k(){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,r=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[r](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 r=document.execCommand("copy");return document.body.removeChild(t),r}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 ie=0;function K(){return{idRegistry:new Map,unmountHooks:[],nextId:()=>`_wf_${ie++}`}}function Y(e,n){for(let t of[...e.unmountHooks])t(n);e.idRegistry.delete(n),e.idRegistry.delete(`custom:${n}`)}function se(e,n,t,r){try{e(n)}catch(o){console.error(`[weifuwu] ref ${t} error in <${r??"anonymous"}>`,o)}}function E(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 r=[...n.unmountHooks];for(let o of r)o(t._id);if(t._customId)for(let o of r)o(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 r of t._child)r&&typeof r=="object"&&E(r,n);else E(t._child,n);t._child=void 0}if(t.props?.children&&typeof t.type=="string"){let r=Array.isArray(t.props.children)?t.props.children:[t.props.children];for(let o of r)o&&typeof o=="object"&&E(o,n)}if(typeof t.props?.ref=="function"&&se(t.props.ref,null,"cleanup"),t._remoteEl){let r=t._child;if(r!=null)if(Array.isArray(r))for(let o of r)o&&typeof o=="object"&&E(o,n);else typeof r=="object"&&E(r,n);t._remoteEl.remove(),t._remoteEl=void 0}}function O(e,n){if(n&&typeof e.type=="function"&&e._id){try{E(e,n)}catch(t){console.error("[weifuwu] ref cleanup error",t)}Y(n,e._id)}}function F(e){if(e==null||typeof e!="object"||Array.isArray(e))return;let n=e;return n._placement==="remote"?n.props?.portalKey:n.key}function Z(e,n){if(n&&e&&typeof e=="object"&&!Array.isArray(e)&&e.type===R){let t=e._childNodes;if(t&&t.length)return t}return[n]}function $(e,n,t,r,o){if(typeof r=="string"||typeof r=="number"){if(typeof t=="string"||typeof t=="number"){if(String(t)!==String(r)){if(n&&n.nodeType===3)return n.nodeValue=String(r),n;let l=e.ownerDocument.createTextNode(String(r));return n?.parentNode?n.parentNode.replaceChild(l,n):e.appendChild(l),l}return n}let s=e.ownerDocument.createTextNode(String(r));return n?.parentNode?n.parentNode.replaceChild(s,n):e.appendChild(s),s}if(r==null||typeof r=="boolean"){if(t&&typeof t=="object"&&!Array.isArray(t)&&t.type===j){let s=t._remoteEl;try{E(t.props?.children,o.registry)}catch(l){console.error("[weifuwu] portal ref cleanup error",l)}return s?.parentNode?.removeChild(s),null}if(t&&typeof t=="object"&&!Array.isArray(t))if(typeof t.type=="function")O(t,o.registry);else try{E(t,o.registry)}catch(s){console.error("[weifuwu] ref cleanup error",s)}return n?.parentNode&&n.parentNode.removeChild(n),null}if(Array.isArray(r)){if(t===r&&n?.parentNode)return n;let s=e.ownerDocument.createDocumentFragment(),l=z(e,t,r,o,n?[n]:void 0);for(let h of l)h&&s.appendChild(h);return n?.parentNode?s.contains(n)?e.appendChild(s):n.parentNode.replaceChild(s,n):e.appendChild(s),s}let i=r;if(i.type===j){let s=t&&typeof t=="object"&&!Array.isArray(t)?t:null;if(s?.type===j){let l=s._remoteEl;if(l){let h=s.props?.children??null,b=i.props?.children??null;z(l,h,b,o)}return i._remoteEl=s._remoteEl,null}return T(i,o,o.browser??k()),null}if(i.type===R){let s=t&&typeof t=="object"&&!Array.isArray(t)?t:null,l=s?._childNodes,h=z(e,s?.props?.children??t,i.props?.children??null,o,l);return i._childNodes=h.filter(Boolean),n?.parentNode&&n.nodeType===8&&n.parentNode.removeChild(n),n&&n.nodeType===1?n:h[0]??null}if(typeof i.type=="function"){if(typeof i._render!="function")throw new Error(`[vdom] component ${i.type.name||"anonymous"} not built in diff \u2014 buildVNode must run before patchValue`);let s=t&&typeof t=="object"&&!Array.isArray(t)?t:null,l=s?.type===i.type;if(!o.force&&s&&l&&s._child!==void 0&&i._child===s._child)return n;s?.type===i.type&&s._id&&(i._id=s._id,o.registry.idRegistry.set(i._id,i)),i._parentNode=e,n&&(i._refNode=n);let h;if(i._child===void 0)throw new Error(`[vdom] component ${i.type.name||"anonymous"} not built (missing _child) \u2014 buildVNode must run before patchValue`);h=i._child;let b=$(e,n,s?._child,h,o);return b&&(i._refNode=b),b}let d=t&&typeof t=="object"&&!Array.isArray(t)?t:null,u=d?.type??null,m=i.type;if(n&&n.nodeType===1&&u===m){let s=n;if(i.el=s,le(s,d?.props??{},i.props??{}),!("innerHTML"in(i.props??{}))){let l=[];z(s,d?.props?.children??null,i.props?.children??null,o,void 0,d?._childAnchors,l),i._childAnchors=l}return s}let f=T(i,o,o.browser??k());if(f==null)return null;if(n?.parentNode)if(t!=null&&typeof t!="boolean"){if(typeof t=="object"&&!Array.isArray(t))try{E(t,o.registry)}catch(s){console.error("[weifuwu] ref cleanup error",s)}n.parentNode.replaceChild(f,n)}else n.parentNode.insertBefore(f,n);else e.appendChild(f);return f}function le(e,n,t){let r=Object.keys(n),o=Object.keys(t);if(r.length===o.length){let d=!0;for(let u=0;u<r.length;u++)if(r[u]!==o[u]||n[r[u]]!==t[r[u]]){d=!1;break}if(d)return}let i=new Set([...r,...o]);for(let d of i){if(d==="children"||d==="key")continue;let u=n[d],m=t[d];if(u!==m){if(D.test(d)){let{type:f,capture:s}=B(d);typeof u=="function"&&e.removeEventListener(f,u,s?{capture:!0}:void 0),m!=null&&m!==!1&&(typeof m!="function"?console.warn(`[weifuwu] event prop ${d} expects a function, got ${typeof m} \u2014 ignored`):e.addEventListener(f,m,s?{capture:!0}:void 0));continue}if(d==="class"||d==="className"){m==null||m===!1?e.removeAttribute("class"):(e.className="",q(e,d,m));continue}if(m==null||m===!1){if(d==="class"||d==="className")e.removeAttribute("class");else if(D.test(d))e.removeEventListener(d.slice(2).toLowerCase(),u);else if(d==="ref"){if(typeof u=="function")try{u(null)}catch(f){console.error("[weifuwu] ref cleanup error",f)}}else if(d==="value")e.value="";else if(d==="indeterminate")e.indeterminate=!1;else{e.removeAttribute(d);try{delete e[d]}catch{}}continue}q(e,d,m)}}}function z(e,n,t,r,o,i,d){let u=W(n),m=W(t),f=i??o??Array.from(e.childNodes);if(m.some(a=>{if(a==null||typeof a!="object"||Array.isArray(a))return!1;let c=a;return c._placement!=="remote"&&c.key!==void 0})){for(let a=0;a<m.length;a++){let c=m[a];c&&typeof c=="object"&&!Array.isArray(c)&&F(c)===void 0&&(c.key=`pos:${a}`)}for(let a=0;a<u.length;a++){let c=u[a];c&&typeof c=="object"&&!Array.isArray(c)&&F(c)===void 0&&(c.key=`pos:${a}`)}}let l=i?i.map((a,c)=>a??(c<u.length?u[c]?._refNode??null:null)):u.map((a,c)=>{if(a==null||typeof a!="object"||Array.isArray(a))return f[c]??null;let N=a;return N._placement==="remote"?N._remoteEl??null:N.type===R?N._childNodes?.[0]??null:N._refNode??N.el??null});if(!m.some(a=>{if(a==null||typeof a!="object"||Array.isArray(a))return!1;let c=a;return c._placement!=="remote"&&c.key!==void 0})){let a=Math.max(u.length,m.length),c=[],N=V=>{d&&d.push(V)};for(let V=0;V<a;V++){let p=V<u.length?u[V]:null,y=V<m.length?m[V]:null;if(y==null||typeof y=="boolean"){let w=l[V],M=r.browser??k(),_=H(M,y);if(p==null||typeof p=="boolean"){w?.nodeType===8?(_&&w.nodeValue!==_.nodeValue&&(w.nodeValue=_.nodeValue),c.push(w),N(w)):(_&&w?.parentNode?w.parentNode.replaceChild(_,w):_&&e.appendChild(_),c.push(_),N(_));continue}if(p&&typeof p=="object"&&!Array.isArray(p))if(typeof p.type=="function")O(p,r.registry);else try{E(p,r.registry)}catch(v){console.error("[weifuwu] ref cleanup error",v)}_&&w?.parentNode?w.parentNode.replaceChild(_,w):_&&e.appendChild(_),c.push(_),N(_);continue}if(p!=null&&typeof p=="object"&&!Array.isArray(p)&&y!=null&&typeof y=="object"&&!Array.isArray(y)&&y===p){c.push(l[V]),N(l[V]);continue}if(p==null||typeof p=="boolean"){let w=T(y,r,r.browser??k());if(w==null){c.push(null),N(null);continue}let M=l[V];if(M&&M.nodeType===8&&M.nodeValue?.startsWith("wf-hole:")){M.parentNode?.replaceChild(w,M),c.push(w),N(w);continue}let _=null;for(let v=V+1;v<l.length;v++){let x=l[v];if(x&&x.parentNode===e){_=x;break}}if(!_){let v=null;for(let x=c.length-1;x>=0;x--)if(c[x]){v=c[x];break}if(v&&v.parentNode===e&&(_=v.nextSibling),!_){let x=l[l.length-1];x&&x.parentNode===e&&(_=x.nextSibling)}}_&&_.parentNode===e?e.insertBefore(w,_):e.appendChild(w),c.push(w),N(w);continue}let g=$(e,l[V],p,y,r),C=Z(y,g);c.push(...C),N(C[0]??g??null)}return c}let b=new Map;u.forEach((a,c)=>{let N=F(a);N!==void 0&&a&&typeof a=="object"&&!Array.isArray(a)&&b.set(N,{vnode:a,nodes:[l[c]??null].filter(Boolean),index:c})});let S=[],Q=new Set,L=a=>{d&&d.push(a)},A=null;return m.forEach((a,c)=>{let N=F(a),V=a;if(N!==void 0&&b.has(N)){let p=b.get(N),y=p.nodes[0]??null;Q.add(N);let g=$(e,y,p.vnode,V,r),C=Z(V,g),w=C[C.length-1]??g;w&&w.parentNode===e&&A&&w.previousSibling!==A&&e.insertBefore(w,A.nextSibling),S.push(...C),L(C[0]??g??null),w&&(A=w)}else{if(a==null||typeof a=="boolean"){let p=u[c]??null,y=l[c]??null,g=H(r.browser??k(),a);if(p==null||typeof p=="boolean")y?.nodeType===8?(g&&y.nodeValue!==g.nodeValue&&(y.nodeValue=g.nodeValue),S.push(y),L(y),y&&(A=y)):(g&&y?.parentNode?y.parentNode.replaceChild(g,y):g&&e.appendChild(g),S.push(g),L(g),g&&(A=g));else{if(typeof p=="object"&&!Array.isArray(p))if(typeof p.type=="function")O(p,r.registry);else try{E(p,r.registry)}catch(C){console.error("[weifuwu] ref cleanup error",C)}g&&y?.parentNode?y.parentNode.replaceChild(g,y):g&&e.appendChild(g),S.push(g),L(g),g&&(A=g)}return}if(V?._placement==="remote"){let p=u[c]??null,y=$(e,l[c]??null,p,V,r),g=Z(V,y);S.push(...g),L(g[0]??y??null);let C=g[g.length-1]??y;C&&(A=C)}else{let p=T(V,r,r.browser??k());if(S.push(p),L(p??null),p!=null){let y=l[c];y&&y.nodeType===8&&y.nodeValue?.startsWith("wf-hole:")?(y.parentNode?.replaceChild(p,y),A=p):(A?e.insertBefore(p,A.nextSibling):e.insertBefore(p,e.firstChild),A=p)}}}}),u.forEach((a,c)=>{let N=F(a),V=a&&typeof a=="object"&&!Array.isArray(a)&&typeof a.type=="function";if(N!==void 0&&!Q.has(N)){if(a&&typeof a=="object"&&!Array.isArray(a))if(V)O(a,r.registry);else try{E(a,r.registry)}catch(y){console.error("[weifuwu] ref cleanup error",y)}let p=l[c];p?.parentNode&&p.parentNode.removeChild(p)}else if(N===void 0){let p=c<m.length?m[c]:null,y=l[c];if(!(y?.nodeType===8&&y.nodeValue?.startsWith("wf-hole:"))||p==null){if(a&&typeof a=="object"&&!Array.isArray(a))if(V)O(a,r.registry);else try{E(a,r.registry)}catch(C){console.error("[weifuwu] ref cleanup error",C)}y?.parentNode&&y.parentNode.removeChild(y)}}}),S}function de(e){return e.__registry??(e.__registry=K())}function ee(e,n,t,r){let o=de(t),i=t.browser??k();return Promise.resolve(P(n,t,void 0,o)).then(()=>{let d=T(n,t,i);if(d!=null&&e.appendChild(d),n._id&&o){let u=o.idRegistry.get(n._id);u&&(u._parentNode=e)}r?.onMounted?.()}).catch(d=>console.error("[weifuwu] command mount error",d)),{id:n._id??""}}function Le(e,n,t){return new Promise(r=>{ee(e,n,t,{onMounted:r})})}async function We(e,n,t,r,o){return await P(r,o,t,o.__registry),$(e,n,t,r,{browser:o.browser??o.__browser,registry:o.__registry})}function De(e,n){let t=n.__registry??(n.__registry=K());return Promise.resolve(P(e,n,void 0,t))}async function $e(e,n,t){let r=await e(n,t);return typeof r=="function"?r(n):r}async function Be(e,n,t){let r=await e(n,t);return()=>typeof r=="function"?r(n):r}function G(e,n){if(e==null||typeof e!="object")return;if(Array.isArray(e)){for(let r of e)G(r,n);return}n(e);let t=e?.props?.children;t!=null&&G(t,n)}function Fe(e,n){let t;return G(e,r=>{!t&&n(r)&&(t=r)}),t}function Oe(e,n){let t=[];return G(e,r=>{typeof r?.props?.class=="string"&&r.props.class.split(" ").includes(n)&&t.push(r)}),t}function Ue(e){let n={ui:{render:()=>{},ready:!0,useExternal:()=>{}}};return e?{ui:{...n.ui,...e.ui??{}},...e.browser?{browser:e.browser}:{}}:n}function qe(e=()=>!1,n){return{get open(){return e()},setOpen:n??(t=>{}),refresh:()=>{},portal:(t,r)=>e()?t:null,wrapProps:{}}}export{De as buildToDom,qe as createPopupMock,Ue as createTestCtx,Oe as findByClass,Fe as findVNode,Be as mountComponent,Le as mountToDom,We as patchToDom,$e as renderVNode,G as walkVNode};
|
package/dist/ui-dom/types.d.ts
CHANGED
|
@@ -280,6 +280,8 @@ export interface WfuiContext {
|
|
|
280
280
|
ui: {
|
|
281
281
|
/** 触发组件重渲染(同步,无参 = 当前组件) */
|
|
282
282
|
render: (ids?: string[]) => Promise<void>;
|
|
283
|
+
/** 组件卸载钩子(mount 阶段注册——组件卸载时调用 fn;SSR no-op;返回退订) */
|
|
284
|
+
onUnmount?: (fn: () => void) => (() => void) | undefined;
|
|
283
285
|
/**
|
|
284
286
|
* AI 对话会话:$ 超集(会话语义 + 工具调用内嵌 + HITL 审批)
|
|
285
287
|
*
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vdom/audit — 结构一致性运行时校验(design/vdom-consistency-plan.md 阶段 C)
|
|
3
|
+
*
|
|
4
|
+
* 规则表(design/vdom-transform-rules.md)的运行时保证:把「用户的想法 = vnode = DOM」从
|
|
5
|
+
* 设计承诺变成每次 patch 的断言——错位即报错(dev),不静默传播(提交按钮消失事故的根治)。
|
|
6
|
+
*
|
|
7
|
+
* 开关:`__WF_VDOM_AUDIT`(dev/测试全开,生产默认关——O(n) 递归零生产开销)。
|
|
8
|
+
* 校验项:
|
|
9
|
+
* A1 数组数量:childNodes.length === children 数组长度(无 fragment/数组项展开时)
|
|
10
|
+
* A2 占位位置:数组占位项(false/null)⟷ childNodes 对应位置是注释(wf-hole)
|
|
11
|
+
* A3 元素类型:native vnode.type === DOM tagName
|
|
12
|
+
* A4 锚点:组件 _refNode 指向的节点仍在父 DOM 中
|
|
13
|
+
*/
|
|
14
|
+
import type { VNodeChild } from '../vnode.ts';
|
|
15
|
+
/** audit 开关(dev/测试注入;生产默认关) */
|
|
16
|
+
export declare function auditEnabled(): boolean;
|
|
17
|
+
/** 数组级校验:childNodes 与 children 数组对齐(A1/A2——占位错位/数量错位,本次事故类别) */
|
|
18
|
+
export declare function auditChildren(parent: Node, children: VNodeChild[] | null | undefined, report: (msg: string) => void): void;
|
|
19
|
+
/** 树级校验:vnode 树 ↔ DOM 树递归对照(A3/A4)——入口调用一次 */
|
|
20
|
+
export declare function auditTree(parent: Node, child: VNodeChild, report: (msg: string) => void): void;
|
|
@@ -30,4 +30,4 @@ export declare function patchProps(el: Element, oldProps: Record<string, any>, n
|
|
|
30
30
|
* patchChildren — 数组 diff。
|
|
31
31
|
* @returns 每个新子项的 DOM 范围(Fragment 展开对齐)
|
|
32
32
|
*/
|
|
33
|
-
export declare function patchChildren(parent: Node, oldInput: VNodeChild | null | undefined, newInput: VNodeChild | null | undefined, ctx: PatchCtx, oldRange?: Node[]): (Node | null)[];
|
|
33
|
+
export declare function patchChildren(parent: Node, oldInput: VNodeChild | null | undefined, newInput: VNodeChild | null | undefined, ctx: PatchCtx, oldRange?: Node[], oldAnchors?: (Node | null)[], anchorOut?: (Node | null)[]): (Node | null)[];
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { VNodeChild } from '../vnode.ts';
|
|
9
9
|
import type { BrowserEnv } from '../types.ts';
|
|
10
|
+
export { EVENT_RE, eventTarget, ENUMERATED_VALUE_BASED, holeDetail } from './transform.ts';
|
|
10
11
|
export declare const SVG_TAGS: Set<string>;
|
|
11
|
-
/** 事件 prop 判定:on + 大写字母(React 约定)——排除 once/only 等 on 开头非事件属性 */
|
|
12
|
-
export declare const EVENT_RE: RegExp;
|
|
13
12
|
export declare function setProp(el: Element, key: string, value: any): void;
|
|
13
|
+
/** 占位内容(规则表 §1——wf-hole 内容可见可审计:false/null/undefined/true/对象摘要/bad-vnode) */
|
|
14
|
+
/** 创建占位节点(数组上下文的无渲染值 → 注释节点,childNodes 与数组同构——规则表 §1) */
|
|
15
|
+
export declare function createHole(browser: BrowserEnv, v: unknown): Node | null;
|
|
14
16
|
/** 递归渲染(同步——组件必须已构建) */
|
|
15
17
|
export declare function renderValue(v: VNodeChild, ctx: any, browser?: BrowserEnv): Node | null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transform — children/属性转化规则单一源(design/vdom-consistency-plan.md 阶段 0)
|
|
3
|
+
*
|
|
4
|
+
* 可推导性 by construction(design/vdom-transform-rules.md):所有 children 形态判定与
|
|
5
|
+
* 属性通道判定收敛到此单一模块——buildVNode / renderValue / patchChildren / renderSsr /
|
|
6
|
+
* hydrateVNode 全部调用,禁止各路径各自实现形态判定(同一语义多套实现 = 漂移 = 转化分叉)。
|
|
7
|
+
*/
|
|
8
|
+
import type { VNodeChild } from '../vnode.ts';
|
|
9
|
+
/** 占位内容(规则表 §1——wf-hole 内容可见可审计:false/null/undefined/true/对象摘要/bad-vnode) */
|
|
10
|
+
export declare function holeDetail(v: unknown): string;
|
|
11
|
+
/** children 项分类(规则表 §1)——唯一判定,消费方只调函数不写判定 */
|
|
12
|
+
export type ChildKind = 'text' | 'hole' | 'native' | 'component' | 'fragment' | 'portal' | 'array' | 'invalid';
|
|
13
|
+
export declare function classifyChild(c: VNodeChild): ChildKind;
|
|
14
|
+
/** 非法 type 判定(组件/原生/Fragment/Portal 之外——数字/未知 Symbol/缺失 → 诊断占位) */
|
|
15
|
+
export declare function isInvalidVNodeType(t: unknown): boolean;
|
|
16
|
+
/** 数组上下文:无渲染值(false/null/true)→ 占位(规则表 §1——childNodes 与数组同构) */
|
|
17
|
+
export declare function isHoleChild(c: VNodeChild): boolean;
|
|
18
|
+
/** 数组项必有 key(规则表 §3):无显式 key 的元素/组件项赋默认下标 key(数组原始下标含占位位置,
|
|
19
|
+
* 统一字符串);文本/占位值豁免。原地写入 vnode.key(声明规则,非隐藏 magic) */
|
|
20
|
+
export declare function ensureArrayKeys(children: VNodeChild[]): void;
|
|
21
|
+
/** 事件 prop 判定:on + 大写字母(React 约定)——排除 once/only 等 on 开头非事件属性 */
|
|
22
|
+
export declare const EVENT_RE: RegExp;
|
|
23
|
+
/** 事件类型 + 捕获标志(onClick → click;onClickCapture → click + capture)——单一实现 */
|
|
24
|
+
export declare function eventTarget(key: string): {
|
|
25
|
+
type: string;
|
|
26
|
+
capture: boolean;
|
|
27
|
+
};
|
|
28
|
+
/** enumerated value-based 白名单(规则表 §2):空字符串解析为 false——必须显式 'true'/'false'。
|
|
29
|
+
* 对照 HTML 规范 enumerated 属性表:value-based 类(draggable/contenteditable/spellcheck/translate) */
|
|
30
|
+
export declare const ENUMERATED_VALUE_BASED: Set<string>;
|
|
31
|
+
/** CSS 无单位属性(数字不加 px)——其余数字样式属性必须加 px(规则表 §2 UNITLESS 白名单) */
|
|
32
|
+
export declare const UNITLESS_PROPS: Set<string>;
|
package/dist/ui-dom/vnode.d.ts
CHANGED
|
@@ -36,6 +36,9 @@ export interface VNode {
|
|
|
36
36
|
_parentVNode?: VNode;
|
|
37
37
|
/** 组件输出的第一个 DOM 节点 */
|
|
38
38
|
_refNode?: Node | null;
|
|
39
|
+
/** 阶段 B:children 每位置的首 DOM 节点(规则表 §5 锚点优先——替代 source[i] 下标猜测,
|
|
40
|
+
* fragment/数组项多节点展开后相邻项不错位)。renderValue 记录,patchChildren 读取 + 回写 */
|
|
41
|
+
_childAnchors?: (Node | null)[];
|
|
39
42
|
/** Fragment 展开后的多个直属 DOM 节点范围(diff 对齐用,见 diff.ts) */
|
|
40
43
|
_childNodes?: Node[];
|
|
41
44
|
/** 组件 renderFn 上次执行时的 ctx 版本号(buildVNode 剪枝 + diff 三态 skip 的版本比较——
|
package/docs/components.md
CHANGED
|
@@ -558,7 +558,7 @@ props 变化 ──────────────────────
|
|
|
558
558
|
| Markdown | `Markdown` | `content` | AI 回复渲染(安全子集 parser) |
|
|
559
559
|
| CodeBlock | `CodeBlock` | `code`, `lang`, `title` | 代码块(语言标签 + 复制) |
|
|
560
560
|
| Highlight | `Highlight` | `text`, `query: string \| string[]` | 搜索词高亮(mark) |
|
|
561
|
-
| List | `List` | `items`, `renderItem`, `divided`, `header/footer/empty` |
|
|
561
|
+
| List | `List` | `items`, `renderItem`, `keyBy?`, `divided`, `header/footer/empty` | 通用列表——`keyBy`(可选)自定义项 key:renderItem 渲染有内部状态的组件且列表动态增删/重排时传身份跟随内容的 key(默认数组下标 = 位置身份) |
|
|
562
562
|
| Result | `Result` | `status`, `title`, `desc`, `extra` | 结果页(成功/失败/警告/信息) |
|
|
563
563
|
| Icon | `Icon` | `name: IconName`, `size` | 图标(内置 25 个 stroke 图标,currentColor 随字号) |
|
|
564
564
|
| StatCard | `StatCard` | `label`, `value`, `trend: 'up'\|'down'`, `trendLabel`, `icon`, `animate` | 统计卡片 |
|
|
@@ -291,6 +291,14 @@ const MyComp: Component = async (_init, ctx) => {
|
|
|
291
291
|
|
|
292
292
|
## 已知边界(诚实裁剪)
|
|
293
293
|
|
|
294
|
+
- **引擎自动写入的 DOM 属性(开发者不需要处理,但写自定义组件时会在 DOM 里看到)**:
|
|
295
|
+
- `data-wf-id`——组件实例 id,写到组件输出**每个顶层节点**(多根全部写)——渲染定位/audit/debug 用;存在性可预期,值不可预期(`_wf_N` 引擎分配)
|
|
296
|
+
- `data-wf-key`——数组项 key(显式或默认下标),写到元素项自身 / **组件项穿透到输出每个顶层节点**——列表项身份可见,动态增删重排建议显式 key(默认下标 = 位置复用 + 状态继承)
|
|
297
|
+
- `<!--wf-hole: xxx-->` 占位注释——条件渲染 false/null/true/非法输入的占位节点(`{cond && <X/>}`=false 时 DOM 里有注释而非消失)——不是 bug,是引擎的透明占位
|
|
298
|
+
- SSR 不输出 `data-wf-id`(id 客户端运行时分配);`data-wf-key` SSR 同步输出
|
|
299
|
+
- 断言/快照测试注意:`outerHTML` 包含这些属性与占位注释;按类选择器/子项数量断言不受影响
|
|
300
|
+
- **列表 key 纪律**:渲染的列表是**有内部状态的组件实例 + 动态增删/重排**(如可输入的卡片)→ 必须显式 key(项 id),否则默认下标位置复用会让后续项继承被删项的内部状态;纯元素列表(格子/行/节点 div)默认下标即可——通用列表组件对外提供 `keyBy`(如 `List`)
|
|
301
|
+
|
|
294
302
|
- `usePopup` 是**统一弹窗能力层**:锚定浮层(Tooltip/Popover/Dropdown/Select/AutoComplete/Mentions/Cascader/ContextMenu/NavMenu/Popconfirm/TreeSelect)+ 会话级模态(Modal/Drawer/Confirm——presence/trapFocus/lockScroll/positioning 'none',Escape 语义留组件层)+ mask 模式(Command/Img preview/Tour——mask/maskCentered/自定义 mask VNode)+ focus 触发(DatePicker)+ positioning 'none' 常驻容器(Toast/Notification)——**全部弹窗单一入口**
|
|
295
303
|
- **事件监听纪律**:组件库内部浏览器事件监听**统一走 `ctx.ui.useXXX`**——滚动/观察/弹层/对话框/快捷键/拖拽/DnD 全覆盖:
|
|
296
304
|
`useInView`(InfiniteScroll)、`useScrollPosition`(AiChat/Affix/BackTop/VirtualList)、`usePopupPosition`(Affix 阈值重算)、`usePopup`(弹窗统一——ContextMenu 自由定位 + Modal/Drawer 模态模式 + mask 遮罩)、`useGlobalKey`(Command 快捷键/Img preview Escape)、`useDrag`(Resizable)、`useDragDrop`(FileUpload)、`useControlled`/`useStableRef`(状态/ref)
|
package/docs/frontend-ui-dom.md
CHANGED
|
@@ -42,6 +42,7 @@ const Counter = async (initProps, ctx) => {
|
|
|
42
42
|
|
|
43
43
|
- **零 npm 运行时依赖**(对比 React + react-dom + react-router + 状态库 + SSR 工具 5+ 依赖)。
|
|
44
44
|
- **自研 VDOM/diff**(keyed children、style diff、CSS 变量、Portal、hydration 游标收养)——每个算法都有对应测试与纪律条目(真实事故沉淀)。**读源码即可完全理解框架行为**。
|
|
45
|
+
- **VDOM 对开发者透明(占位法 + 单一规则源)**:写 JSX → 看 DOM 即真相——`data-wf-key`(数组项身份,元素/组件一致)、`data-wf-id`(组件实例身份)、`<!--wf-hole: xxx-->`(条件渲染 false 的占位注释)直接在 DOM 可见;非法输入(对象/数字 type)→ 诊断占位 + warn,不崩溃不静默;`?vdom_debug=1` 开启 patch trace + 结构 audit。**转化路径唯一清晰、无 magic、可推导**(规则表:design/vdom-transform-rules.md)
|
|
45
46
|
- **零构建步骤**:`weifuwu/dev` loader + `ctx.ui.js/css` 动态编译,服务端直接跑 `.tsx`,改组件刷新即生效。
|
|
46
47
|
|
|
47
48
|
### 弹层/浮层体系:最难的 UI 类别变成复用的原语
|