@yoyaflow/yoya-ui 0.3.2 → 0.4.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.
Files changed (42) hide show
  1. package/README.md +407 -124
  2. package/README.zh-CN.md +375 -131
  3. package/dist/yoya.core.chunk.js +4275 -0
  4. package/dist/yoya.core.chunk.min.js +9 -0
  5. package/dist/yoya.core.js +3 -1779
  6. package/dist/yoya.core.min.js +1 -0
  7. package/dist/yoya.devtools.js +3 -0
  8. package/dist/yoya.devtools.min.js +1 -0
  9. package/dist/yoya.echart.js +182 -592
  10. package/dist/yoya.echart.min.js +1 -0
  11. package/dist/yoya.router.full.js +5271 -0
  12. package/dist/yoya.router.full.min.js +43 -0
  13. package/dist/yoya.router.js +1330 -0
  14. package/dist/yoya.router.min.js +35 -0
  15. package/dist/yoya.three.js +360 -0
  16. package/dist/yoya.three.min.js +1 -0
  17. package/dist/yoya.ui-router.full.js +21843 -0
  18. package/dist/yoya.ui-router.full.min.js +43 -0
  19. package/dist/yoya.ui-router.umd.js +43 -0
  20. package/dist/yoya.ui-router.umd.min.js +43 -0
  21. package/dist/yoya.ui.css +80 -0
  22. package/dist/yoya.ui.full.js +20169 -0
  23. package/dist/yoya.ui.full.min.js +1 -0
  24. package/dist/yoya.ui.js +12227 -9083
  25. package/dist/yoya.ui.min.js +1 -0
  26. package/package.json +27 -11
  27. package/types/core.d.ts +122 -1
  28. package/types/data-display.d.ts +44 -2
  29. package/types/devtools.d.ts +156 -0
  30. package/types/feedback.d.ts +13 -0
  31. package/types/form.d.ts +1 -1
  32. package/types/index.d.ts +1 -1
  33. package/types/ssr.d.ts +27 -7
  34. package/types/three.d.ts +77 -0
  35. package/types/yoya.devtools.d.ts +5 -0
  36. package/types/yoya.router.d.ts +7 -0
  37. package/types/yoya.three.d.ts +4 -0
  38. package/types/yoya.ui-router.d.ts +19 -0
  39. package/types/yoya.ui.d.ts +2 -7
  40. package/dist/yoya-ui.umd.js +0 -35
  41. package/dist/yoya.ssr.js +0 -2856
  42. package/types/yoya.ssr.d.ts +0 -9
@@ -0,0 +1,35 @@
1
+ import{A as e,Di as t,E as n,Ei as r,Mi as i,Pi as a,_i as o,a as s,b as c,c as l,i as u,j as d,ji as f,l as p,n as m,o as h,r as g,s as _,t as v,vi as y,wi as b,yi as x}from"./yoya.core.chunk.min.js";let S=null;function C(){S||=x(`.yoya-vrouter-views-titlebar,
2
+ .yoya-vrouter-views-popup {
3
+ -ms-overflow-style: none;
4
+ scrollbar-width: none;
5
+ }
6
+ .yoya-vrouter-views-titlebar::-webkit-scrollbar,
7
+ .yoya-vrouter-views-popup::-webkit-scrollbar {
8
+ display: none;
9
+ height: 0;
10
+ width: 0;
11
+ }
12
+ .yoya-vrouter-views-popup-item:hover {
13
+ background: var(--yoya-color-surface-hover, #eef3f9);
14
+ }
15
+ .yoya-vrouter-views-popup-item[aria-current='true'] {
16
+ background: var(--yoya-color-primary-subtle, #e8f0fe);
17
+ color: var(--yoya-color-primary, #1f6feb);
18
+ }
19
+ .yoya-vrouter-views-popup-close {
20
+ color: var(--yoya-color-text-secondary, #57606a);
21
+ opacity: 0.65;
22
+ }
23
+ .yoya-vrouter-views-popup-item:hover .yoya-vrouter-views-popup-close,
24
+ .yoya-vrouter-views-popup-close:hover {
25
+ color: var(--yoya-color-text-danger, #b91c1c);
26
+ opacity: 1;
27
+ }
28
+ .yoya-vrouter-views-context-item:hover {
29
+ background: var(--yoya-color-surface-hover, #f6f8fa);
30
+ }
31
+ .yoya-vrouter-views-context-separator {
32
+ background: var(--yoya-color-border, #d0d7de);
33
+ height: 1px;
34
+ margin: 4px 6px;
35
+ }`,`data-yoya-vrouter-views-popup-style`)}function w(e){let t=[e._defaultPath||`/`,e._routes.map(e=>e.pattern).join(`|`)].join(`::`),n=0;for(let e=0;e<t.length;e+=1)n=n*31+t.charCodeAt(e)|0;return`yoya-ui:router-views:${(n>>>0).toString(36)}`}function T(e){if(typeof localStorage>`u`)return null;try{let t=JSON.parse(localStorage.getItem(e)||`null`);return Array.isArray(t?.paths)?t:null}catch{return null}}var E=class extends b{constructor(e=null){super(`div`),this._routes=[],this._defaultPath=null,this._notFoundView=null,this._beforeEach=null,this._currentPath=`/`,this._currentParams={},this._currentQuery={},this._currentRoute=null,this._currentView=null,this._loadingView=null,this._errorView=null,this._navigationGeneration=0,this._outlet=this,this._subscribers=new Set,this._ignoreNextHashPath=null,this._mode=`hash`,this._started=!1,this._onHashChange=()=>this._handleHashChange(),this._onPopState=()=>this._handlePopState(),this.attr(`data-yoya-router`,``),e!==null&&this.setup(e)}setup(e){return typeof e==`function`?(e(this),this):super.setup(e)}default(e){return this._defaultPath=X(e),this}mode(e){if(e===void 0)return this._mode;let t=e===`history`?`history`:`hash`;if(t===this._mode)return this;let n=this._started;return n&&this.stop(),this._mode=t,n&&this.start(),this}route(e,t){let n=P(e,t);return this._routes.push(n),this}notFound(e){return this._notFoundView=e,this}loading(e){return this._loadingView=e,this}error(e){return this._errorView=e,this}beforeEach(e){return this._beforeEach=e,this}start(){this._started||=(this._stopListening=this._mode===`history`?y(`popstate`,this._onPopState):y(`hashchange`,this._onHashChange),!0);let e=Y(this._mode);return(this._mode===`history`?e===`/`||e===`/index.html`:!window.location.hash)&&this._defaultPath?this.navigate(this._defaultPath,{replace:!0}):this.refresh()}stop(){return this._started&&=(this._stopListening?.(),this._stopListening=null,!1),this}navigate(e,t={}){let n=X(e),r=this._resolve(n);return this._canEnter(r.context)?(ie(n,t,this._mode)&&!t.replace&&this._mode===`hash`&&(this._ignoreNextHashPath=n),this._renderResolved(r),this):this}refresh(){let e=Y(this._mode),t=this._resolve(e);return this._canEnter(t.context)&&this._renderResolved(t),this}renderPath(e){let t=this._resolve(e);return this._canEnter(t.context)&&this._renderResolved(t),this}currentPath(){return this._currentPath}currentParams(){return{...this._currentParams}}currentQuery(){return{...this._currentQuery}}currentRoute(){return this._currentRoute}currentView(){return this._currentView}outlet(e){if(e===void 0)return this._outlet;if(!(e instanceof b))throw TypeError(`Router outlet must be an ElementNode`);return this._outlet=e,this}subscribe(e){if(typeof e!=`function`)throw TypeError(`Router subscriber must be a function`);return this._subscribers.add(e),()=>this._subscribers.delete(e)}go(e){return window.history.go(e),this}back(){return this.go(-1)}forward(){return this.go(1)}destroy(){return this.stop(),this._navigationGeneration+=1,this._destroyCurrentView(),this._subscribers.clear(),super.destroy()}_resolve(e){let t=this._routes.map(t=>({route:t,match:ne(t.pattern,e)})).find(({match:e})=>e);if(t)return{context:q(this,e,t.route,t.match),route:t.route,view:t.route.view};let n=Z(e);return{context:q(this,e,null,{params:{},pathname:n.pathname,query:n.query}),route:null,view:this._notFoundView}}_handleHashChange(){let e=J();return this._ignoreNextHashPath===e?(this._ignoreNextHashPath=null,this):(this._ignoreNextHashPath=null,e===this._currentPath?this:this.refresh())}_handlePopState(){return this._ignoreNextHashPath=null,this.refresh()}_canEnter(e){let t={params:this.currentParams(),path:this._currentPath,query:this.currentQuery(),route:this._currentRoute};return!(this._beforeEach&&this._beforeEach(e,t,this)===!1||e.route?.beforeEnter&&e.route.beforeEnter(e,t,this)===!1)}_renderResolved(e){let{context:t,route:n,view:r}=e,i=typeof r==`function`?r(t):r;if(this._navigationGeneration+=1,!te(i)){this._commitView(e,U(i,t));return}let a=this._navigationGeneration;this._commitView(e,this._buildLoadingView(n,t)),Promise.resolve(i).then(r=>{if(a!==this._navigationGeneration||this._deleted)return r;let i;try{i=U(r,t)}catch(i){return this._commitView(e,this._buildErrorView(n,t,i)),r}return this._commitView(e,i),r},r=>(a!==this._navigationGeneration||this._deleted||this._commitView(e,this._buildErrorView(n,t,r)),r))}_commitView(e,t){let{context:n,route:r}=e,i=this._outlet;this._destroyCurrentView(),i._children=[],i._el&&i._el.replaceChildren(),i.child(t),this._currentPath=n.path,this._currentParams=n.params,this._currentQuery=n.query,this._currentRoute=r,this._currentView=t,this._subscribers.forEach(e=>e(n,this))}_buildLoadingView(e,t){return K(e?.loading??this._loadingView??W,[t])}_buildErrorView(e,t,n){return K(e?.error??this._errorView??G,[n,t])}_destroyCurrentView(){this._currentView?.destroy&&this._currentView.destroy(),this._currentView=null}};function D(e=null,n=null,r=null){let i=f(e,n,r),a=new E(i.first);return t(a,i.options),typeof i.callback==`function`&&i.callback(a),a}const O=D;function k(e,t){return{config:t,pattern:e}}function A(e=null,n=null,r=null){let i=f(e,n,r),a=new E;return a.vRoute=(e,t)=>(a.route(e,t),a),I(a,i.first),t(a,i.options),typeof i.callback==`function`&&i.callback(a),a}function j(e,t=null,r=null){F(e);let i=new b(`a`),a={exact:!0,label:null,params:{},query:{},replace:!1,to:`/`},o=new b(`span`).className(`yoya-vlink-label`);i.className(`yoya-vlink`),i.attr(`data-router-link`,`true`),i.child(o),i.to=e=>R(i,a,`to`,e),i.params=e=>R(i,a,`params`,e||{}),i.query=e=>R(i,a,`query`,e||{}),i.replace=e=>R(i,a,`replace`,!!e),i.exact=e=>R(i,a,`exact`,!!e),i.label=e=>e===void 0?a.label:(a.label=e,n(o,c(e)),i),L(i,a,t),z(i,a,e),i.on(`click`,t=>{H(t,i)&&(t.preventDefault(),e.navigate(B(a.to,a.params,a.query),{replace:a.replace}))});let s=e.subscribe(()=>z(i,a,e)),l=i.destroy.bind(i);return i.destroy=()=>(s(),l()),typeof r==`function`&&r(i),i}function M(e,t=null,n=null){F(e);let r=new b(`div`);r.className(`yoya-vrouter-view`),r.attr(`data-router-view`,`true`),typeof t==`function`?t(r):t&&r.setup(t),e.outlet(r);let i=r.destroy.bind(r);return r.destroy=()=>(e.outlet()===r&&e.outlet(e),i()),typeof n==`function`&&n(r),r}function N(t,n=null,r=null){F(t);let i=new b(`div`),s=new b(`header`).className(`yoya-vrouter-views-titlebar`).attr({role:`tablist`,"aria-label":`已打开页面`}),c=new b(`div`).className(`yoya-vrouter-views-content`),l=a(`⋯`),u=new b(`button`).className(`yoya-vrouter-views-expand`).attr({type:`button`,"aria-expanded":`false`,"aria-label":`展开全部标签`}).styles({alignItems:`center`,background:`transparent`,border:`0`,color:d(`color-text-secondary`,`#57606a`),cursor:`pointer`,display:`none`,flexShrink:`0`,font:`inherit`,gap:`6px`,height:`24px`,justifyContent:`center`,lineHeight:`1`,marginBottom:`0`,marginLeft:`auto`,minWidth:`24px`,padding:`0`,position:`sticky`,right:`8px`,zIndex:`2`}).child(l),f=new b(`div`).className(`yoya-vrouter-views-popup`).attr({role:`menu`,"aria-label":`已打开页面`}).styles({background:d(`color-surface`,`#ffffff`),border:e(`color-border`,`#d0d7de`),borderRadius:`8px`,boxShadow:`0 12px 28px rgba(15, 23, 42, 0.18)`,display:`none`,maxHeight:`280px`,maxWidth:`260px`,minWidth:`180px`,msOverflowStyle:`none`,overflowY:`auto`,padding:`6px`,position:`fixed`,scrollbarWidth:`none`,zIndex:`100`}),p={lockTitle:!1,overflow:!1,persist:!0,popupOpen:!1,storageKey:w(t),suppressPersist:!1,tabs:new Map,title:`工作区`,titleResolver:null,titlePosition:`top`};i.className(`yoya-vrouter-views`),i.styles({border:e(`color-border`,`#d0d7de`),boxSizing:`border-box`,overflow:`hidden`}),s.styles({background:d(`color-surface-hover`,`#f6f8fa`),borderBottom:e(`color-border`,`#d0d7de`),boxSizing:`border-box`,color:d(`color-text-secondary`,`#57606a`),display:`flex`,flexWrap:`nowrap`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, monospace`,fontSize:`13px`,gap:`0px`,msOverflowStyle:`none`,overflowX:`auto`,overflowY:`hidden`,padding:`0px 0px`,scrollbarWidth:`none`,width:`100%`}),c.className(`yoya-vrouter-views-content`),c.styles({minHeight:`120px`,padding:`16px`}),i.child(s,c,f);let m=()=>{let e=p.titlePosition!==`top`;if(p.lockTitle){i.styles({display:`flex`,flexDirection:e?`row`:`column`,height:`100%`,minHeight:`0`,overflow:`hidden`}),s.style(`flex`,`0 0 auto`),c.styles({flex:`1 1 auto`,minHeight:`0`,minWidth:`0`,overflow:`auto`});return}i.styles({flexDirection:null,height:null,minHeight:null,overflow:`hidden`}),s.style(`flex`,null),c.styles({flex:e?`1 1 auto`:null,minHeight:`120px`,minWidth:e?`0`:null,overflow:null})},h=t=>{let n=t!==`top`;i.styles({alignItems:n?`stretch`:null,display:n?`flex`:null}),s.styles({background:d(`color-surface-hover`,`#f6f8fa`),borderBottom:n?null:e(`color-border`,`#d0d7de`),borderLeft:t===`right`?`1px solid`:null,borderLeftColor:t===`right`?d(`color-border`,`#d0d7de`):null,borderLeftStyle:t===`right`?`solid`:null,borderLeftWidth:t===`right`?`1px`:null,borderRight:t===`left`?`1px solid`:null,borderRightColor:t===`left`?d(`color-border`,`#d0d7de`):null,borderRightStyle:t===`left`?`solid`:null,borderRightWidth:t===`left`?`1px`:null,boxSizing:`border-box`,color:d(`color-text-secondary`,`#57606a`),display:`flex`,flexDirection:n?`column`:`row`,flexShrink:n?`0`:null,flexWrap:`nowrap`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, monospace`,fontSize:`13px`,gap:`0px`,msOverflowStyle:`none`,overflowX:n?`hidden`:`auto`,overflowY:n?`auto`:`hidden`,padding:n?`10px 8px`:`0px 0px`,scrollbarWidth:`none`,width:n?null:`100%`}),c.styles({flex:n?`1 1 auto`:null,minWidth:n?`0`:null});let r=t===`right`?[c,s,f]:[s,c,f];i.clearChildren().child(r),i._el&&r.forEach(e=>{let t=e.renderDom();t&&i._el.appendChild(t)}),m()},g=(e={})=>{let t=p.title,n=e.route?.title;if(n!==void 0&&(t=typeof n==`function`?n(e):n),p.titleResolver){let n=p.titleResolver(e);n!=null&&(t=typeof n==`function`?n(e):n)}return t??``},_=(t,n)=>{let r=t.tab,i=p.titlePosition,a=i!==`top`;t.label.attr(`aria-selected`,String(n)),r.styles({background:n?d(`color-surface`,`#ffffff`):d(`color-surface-active`,`#eaeef2`),border:e(`color-border`,`#d0d7de`),borderBottomColor:i===`top`&&n?d(`color-surface`,`#ffffff`):d(`color-border`,`#d0d7de`),borderLeftColor:`transparent`,borderRightColor:i===`left`&&n?d(`color-surface`,`#ffffff`):d(`color-border`,`#d0d7de`),color:n?d(`color-text`,`#24292f`):d(`color-text-secondary`,`#57606a`),fontWeight:n?`600`:`400`,marginBottom:i===`top`?`-9px`:`0`,marginLeft:i===`right`?`-9px`:`0`,marginRight:i===`left`?`-9px`:`0`,padding:a?`8px 10px`:`7px 14px 8px`})},v=e=>{p.overflow=!!e,i.attr(`data-title-overflow`,p.overflow?`true`:null),u.style(`display`,p.overflow?`inline-flex`:`none`)},x=()=>{if(p.titlePosition!==`top`||p.tabs.size<=8){v(!1);return}v(!0)},S=()=>{let e=Array.from(p.tabs.entries()),t=e.slice(0,8).map(([,e])=>e.tab).filter(e=>e!==u);if(!(e.length>8&&p.titlePosition===`top`)){p.popupOpen&&O(),s._children=t,s._childrenDirty=!0,s._el?s._el.replaceChildren(...t.map(e=>e.renderDom()).filter(Boolean)):u._el?.remove(),v(!1);return}if(s._children=[...t,u],s._childrenDirty=!0,s._el){let e=t.map(e=>e.renderDom()).filter(Boolean);s._el.replaceChildren(...e,u.renderDom())}x()},E=()=>{if(!(!p.persist||p.suppressPersist||typeof localStorage>`u`))try{localStorage.setItem(p.storageKey,JSON.stringify({activePath:t.currentPath(),paths:Array.from(p.tabs.keys())}))}catch{}},D=null,O=()=>{p.popupOpen=!1,i.attr(`data-title-popup`,null),u.attr(`aria-expanded`,`false`),f.style(`display`,`none`),D&&=(D(),null)},k=()=>{f.clearChildren(),f._el&&f._el.replaceChildren(),Array.from(p.tabs.entries()).slice(8).forEach(([e,n])=>{let r=n.text.textContent(),i=new b(`div`).className(`yoya-vrouter-views-popup-item`).attr({role:`menuitem`,tabIndex:`0`,"data-router-view-path":e}).styles({alignItems:`center`,borderRadius:`6px`,color:d(`color-text`,`#24292f`),cursor:`pointer`,display:`flex`,fontSize:`13px`,gap:`8px`,padding:`7px 8px`,width:`100%`}),a=new b(`span`).className(`yoya-vrouter-views-popup-title`).styles({flex:`1`,minWidth:`0`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`}).text(r),o=new b(`button`).className(`yoya-vrouter-views-popup-close`).attr({type:`button`,"aria-label":`关闭 ${r}`}).styles({background:`transparent`,border:`0`,color:`inherit`,cursor:`pointer`,flexShrink:`0`,font:`inherit`,lineHeight:`1`,padding:`2px 4px`}).text(`×`);e===t.currentPath()&&(i.attr(`aria-current`,`true`),i.styles({background:d(`color-primary-subtle`,`#e8f0fe`),color:d(`color-primary`,`#1f6feb`)}));let s=()=>{O(),t.navigate(e)};i.on(`click`,s),i.on(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),s())}),o.on(`click`,t=>{t.stopPropagation(),M(e,t),p.popupOpen&&k()}),i.child(a,o),f.child(i)})},A=()=>{if(p.tabs.size===0)return;C(),k(),p.popupOpen=!0,i.attr(`data-title-popup`,`true`),u.attr(`aria-expanded`,`true`),f.styles({display:`block`}),d();let e=e=>{!f._el?.contains(e.target)&&!u._el?.contains(e.target)&&O()},t=e=>{e.key===`Escape`&&O()},n=()=>d(),r=()=>d(),a=o(`click`,e),s=o(`keydown`,t),c=y(`scroll`,n,!0),l=y(`resize`,r);D=()=>{a(),s(),c(),l()};function d(){let e=u._el?.getBoundingClientRect(),t=f._el?.getBoundingClientRect();if(!e||!t)return;let n=window.innerWidth||document.documentElement?.clientWidth||0,r=window.innerHeight||document.documentElement?.clientHeight||0,i=e.right-t.width;i=Math.max(8,Math.min(i,n-t.width-8));let a=e.bottom+4;a+t.height+8>r&&(a=Math.max(8,e.top-t.height-4)),f.styles({left:`${i}px`,top:`${a}px`})}};u.on(`click`,()=>{p.popupOpen?O():A()});let j=i.renderDom.bind(i);i.renderDom=()=>{C();let e=j();return x(),e},i.updateOverflow=x,i.titlePosition=e=>{if(e===void 0)return p.titlePosition;let n=ee(e);return p.titlePosition=n,n!==`top`&&p.popupOpen&&O(),i.attr(`data-title-position`,p.titlePosition),s.attr(`aria-orientation`,p.titlePosition===`top`?`horizontal`:`vertical`),h(p.titlePosition),S(),p.tabs.forEach((e,n)=>{_(e,n===t.currentPath())}),x(),i},i.titlePosition(p.titlePosition),i.lockTitle=(e=!0)=>e===void 0?p.lockTitle:(p.lockTitle=!!e,i.attr(`data-title-locked`,p.lockTitle?`true`:null),h(p.titlePosition),x(),i),i.titleLocked=i.lockTitle;let M=(e,n=null)=>{n&&n.stopPropagation();let r=Array.from(p.tabs.entries()).findIndex(([t])=>t===e),i=p.tabs.get(e);if(!i)return;let a=i.label.attr(`aria-selected`)===`true`;if(p.tabs.delete(e),s._children=s.children().filter(e=>e!==i.tab),s._childrenDirty=!0,i.tab.destroy(),S(),E(),!a)return;let o=Array.from(p.tabs.keys());if(o.length>0){let e=o[Math.min(r,o.length-1)];t.navigate(e,{replace:!0});return}c.clearChildren().commit(),t._navigationGeneration+=1,t._currentView=null},N=new b(`div`).className(`yoya-vrouter-views-context`).attr({role:`menu`,"aria-label":`标签页操作`}).styles({background:d(`color-surface`,`#ffffff`),border:e(`color-border`,`#d0d7de`),borderRadius:`8px`,boxShadow:`0 12px 28px rgba(15, 23, 42, 0.18)`,display:`none`,minWidth:`180px`,padding:`6px`,position:`fixed`,zIndex:`100`}),P=null,I=()=>{N.styles({display:`none`}),N.clearChildren(),N._el?.remove(),P&&=(P(),null)},L=(e,n=null)=>{let r=new Set(e),i=Array.from(p.tabs.entries()),a=i.findIndex(([e])=>r.has(e));if(i.forEach(([e,t])=>{r.has(e)&&(p.tabs.delete(e),s._children=s.children().filter(e=>e!==t.tab),s._childrenDirty=!0,t.tab.destroy())}),S(),E(),p.popupOpen&&k(),!r.has(t.currentPath()))return;let o=Array.from(p.tabs.keys());if(o.length===0){c.clearChildren().commit(),t._navigationGeneration+=1,t._currentView=null;return}let l=n&&p.tabs.has(n)?n:o[Math.min(Math.max(a,0),o.length-1)];t.navigate(l,{replace:!0})},R=e=>{if(typeof navigator>`u`||!navigator.clipboard)return;let n=typeof window>`u`?``:window.location.origin,r=typeof window>`u`?``:window.location.pathname,i=t.mode()===`history`?`${n}${r}${e}`:`${n}${r}#${e}`;navigator.clipboard.writeText(i).catch(()=>{})},z=(e,n)=>{p.popupOpen&&O(),I();let r=Array.from(p.tabs.entries()),i=r.findIndex(([t])=>t===e),a=()=>L(r.filter(([t])=>t!==e).map(([e])=>e),e),s=()=>L(r.slice(0,i).map(([e])=>e),e),c=()=>L(r.slice(i+1).map(([e])=>e),e),l=()=>L(r.map(([e])=>e)),u=(e,t,n=!1,r=!1)=>{let i=new b(`div`).className(`yoya-vrouter-views-context-item`).attr({role:`menuitem`,tabIndex:`0`}).text(e).styles({alignItems:`center`,borderRadius:`6px`,color:n?d(`color-text-danger`,`#b91c1c`):d(`color-text`,`#24292f`),cursor:r?`default`:`pointer`,display:`flex`,fontSize:`13px`,gap:`8px`,padding:`7px 10px`,width:`100%`});return r?(i.attr(`aria-disabled`,`true`),i.styles({opacity:`0.4`})):i.on(`click`,()=>{I(),t()}),N.child(i),i},f=()=>N.child(new b(`div`).className(`yoya-vrouter-views-context-separator`));u(`刷新`,()=>t.navigate(e,{replace:!0})),u(`复制链接`,()=>R(e)),f(),u(`关闭`,()=>M(e),!0),u(`关闭其他`,a,!1,r.length<=1),u(`关闭左侧`,s,!1,i<=0),u(`关闭右侧`,c,!1,i===r.length-1),f(),u(`关闭全部`,l,!0,r.length===0),N.bindTo(document.body),N.styles({display:`block`});let m=N._el.getBoundingClientRect(),h=typeof window>`u`?0:window.innerWidth||0,g=typeof window>`u`?0:window.innerHeight||0,_=Math.max(8,Math.min(n.clientX||0,h-m.width-8)),v=Math.max(8,Math.min(n.clientY||0,g-m.height-8));N.styles({left:`${_}px`,top:`${v}px`});let x=e=>{N._el?.contains(e.target)||I()},S=e=>{e.key===`Escape`&&I()},C=()=>I(),w=o(`mousedown`,x),T=o(`keydown`,S),E=y(`scroll`,C,!0),D=y(`resize`,C);P=()=>{w(),T(),E(),D()}},B=(e={})=>{let n=e.path||t.currentPath(),r=new Set(p.titlePosition===`top`?Array.from(p.tabs.keys()).slice(0,8):Array.from(p.tabs.keys())),i=p.tabs.get(n);if(i){let t=g(e);i.text.textContent(t),i.closeButton.attr(`aria-label`,`关闭 ${t}`)}else{let r=new b(`div`).className(`yoya-vrouter-views-title`),o=a(g(e)),c=new b(`button`).className(`yoya-vrouter-views-label`).child(o),l=new b(`button`).className(`yoya-vrouter-views-close`);r.attr({"data-router-view-path":n}),r.styles({alignItems:`center`,cursor:`pointer`,display:`inline-flex`,font:`inherit`,gap:`8px`,whiteSpace:`nowrap`}),c.attr({role:`tab`,type:`button`}),c.styles({background:`transparent`,border:`0`,color:`inherit`,cursor:`pointer`,font:`inherit`,padding:`0`}),c.on(`click`,()=>t.navigate(n)),l.attr({type:`button`,"aria-label":`关闭 ${g(e)}`}),l.styles({background:`transparent`,border:`0`,color:`inherit`,cursor:`pointer`,font:`inherit`,lineHeight:`1`,padding:`0`}),l.text(`×`),l.on(`click`,e=>M(n,e)),r.on(`contextmenu`,e=>{e.preventDefault(),e.stopPropagation(),z(n,e)}),r.child(c,l),s.child(r),i={closeButton:l,label:c,tab:r,text:o},p.tabs.set(n,i),_(i,!1)}r.has(n)||(p.tabs.delete(n),p.tabs=new Map([[n,i],...p.tabs])),p.tabs.forEach((e,t)=>_(e,t===n)),S(),p.popupOpen&&k(),E()},V=()=>{if(!p.persist)return;let e=T(p.storageKey);if(e){p.suppressPersist=!0;try{e.paths.slice().reverse().forEach(e=>{let n=t._resolve(e);B({...n.context,path:e})})}finally{p.suppressPersist=!1,E()}}};if(typeof n==`function`)n(i);else if(n&&typeof n==`object`){let{persist:e,storageKey:t,title:r,titlePosition:a,titleResolver:o,...s}=n;r!==void 0&&(p.title=r),e!==void 0&&(p.persist=!!e),t!==void 0&&(p.storageKey=t),a!==void 0&&i.titlePosition(a),typeof o==`function`&&(p.titleResolver=o),Object.keys(s).length>0&&i.setup(s)}t.outlet(c),V(),(t.currentRoute()||t.currentPath()!==`/`)&&B({params:t.currentParams(),path:t.currentPath(),query:t.currentQuery(),route:t.currentRoute(),router:t});let H=t.subscribe(e=>B(e)),U=y(`resize`,()=>x()),W=i.destroy.bind(i);return i.destroy=()=>(p.popupOpen&&O(),I(),U(),H(),t.outlet()===c&&t.outlet(t),W()),typeof r==`function`&&r(i),i}i(b,{vLink:j,vRouter:A,vRouterView:M,vRouterViews:N});function P(e,t){let n={beforeEnter:null,error:null,loading:null,pattern:ae(e),title:null,view:null};return typeof t==`function`||t instanceof r||$(t)?(n.view=t,n):(t&&typeof t==`object`&&(n.beforeEnter=t.beforeEnter||null,n.error=t.error??null,n.loading=t.loading??null,n.title=t.title??null,n.view=t.view||t.component||null),n)}function F(e){if(!(e instanceof E))throw TypeError(`vLink and vRouterView require a Router instance`)}function ee(e){return e===`left`||e===`right`?e:`top`}function I(e,t){if(typeof t==`function`)return t(e),e;if(!t||typeof t!=`object`)return e;let{beforeEach:n,default:r,error:i,loading:a,notFound:o,routes:s=[],...c}=t;return Object.keys(c).length&&e.setup(c),r!==void 0&&e.default(r),n&&e.beforeEach(n),a!==void 0&&e.loading(a),i!==void 0&&e.error(i),s.forEach(t=>{t?.pattern!==void 0&&e.vRoute(t.pattern,t.config)}),o!==void 0&&e.notFound(o),e}function L(e,t,n){if(typeof n==`function`){n(e);return}if(typeof n==`string`){e.to(n),e.label(n);return}if(!n)return;let{exact:r,label:i,params:a,query:o,replace:s,to:c,...l}=n;Object.keys(l).length&&e.setup(l),c!==void 0&&(t.to=c),a!==void 0&&(t.params=a||{}),o!==void 0&&(t.query=o||{}),s!==void 0&&(t.replace=!!s),r!==void 0&&(t.exact=!!r),t.label=i??t.to,e.label(t.label)}function R(e,t,r,i){if(i===void 0)return t[r];t[r]=i,r===`to`&&t.label===null&&n(e.children()[0],c(i));let a=e._routerInstance;return a&&z(e,t,a),e}function z(e,t,n){e._routerInstance=n;let r=B(t.to,t.params,t.query),i=V(n.currentPath(),r,t.exact),a=new Set(String(e.attr(`class`)||``).split(/\s+/).filter(Boolean));return a.add(`yoya-vlink`),i?a.add(`is-active`):a.delete(`is-active`),e.attr({"aria-current":i?`page`:null,class:[...a].join(` `),href:n.mode()===`history`?r:`#${r}`}),e}function B(e,t,n){let[r,i=``]=X(e).split(`?`),a=r.replace(/:([A-Za-z0-9_]+)/g,(e,n)=>t[n]===void 0?e:encodeURIComponent(t[n])),o=new URLSearchParams(i);Object.entries(n||{}).forEach(([e,t])=>{o.delete(e),Array.isArray(t)?t.forEach(t=>o.append(e,t)):t!=null&&o.set(e,t)});let s=o.toString();return s?`${a}?${s}`:a}function V(e,t,n){let r=X(e),i=X(t);if(n)return r===i;let a=Z(r).pathname,o=Z(i).pathname;return a===o||a.startsWith(`${o}/`)}function H(e,t){return!e.defaultPrevented&&e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey&&(!t.attr(`target`)||t.attr(`target`)===`_self`)}function U(e,t){if(e instanceof r)return e;if(e==null)return a(``);if($(e))return a(e);if(typeof e==`object`&&e&&e.default!==void 0&&typeof e.render!=`function`)return U(e.default,t);if(typeof e==`function`)return U(e(t),t);if(typeof e==`object`&&typeof e.render==`function`)return U(e.render(),t);throw TypeError(`Router route view must be a ViewNode, string, number, null, undefined, a render() component object, a factory returning one, or a module with a default export`)}const W=()=>`加载中…`,G=e=>`加载失败:${e?.message??String(e)}`;function te(e){return e!==null&&(typeof e==`object`||typeof e==`function`)&&typeof e.then==`function`}function K(e,t){return U(typeof e==`function`?e(...t):e,t[t.length-1])}function ne(e,t){let n=Z(e),r=Z(t),i=Q(n.pathname),a=Q(r.pathname);if(i.length!==a.length)return null;let o={};for(let e=0;e<i.length;e+=1){let t=i[e],n=a[e];if(t.startsWith(`:`)){o[t.slice(1)]=decodeURIComponent(n);continue}if(t!==n)return null}return{params:o,pathname:r.pathname,query:r.query}}function q(e,t,n,r){return{params:{...r.params},path:t,pathname:r.pathname,query:{...r.query},route:n,router:e}}function J(){return typeof window>`u`?`/`:X(window.location.hash.replace(/^#/,``)||`/`)}function Y(e=`hash`){return typeof window>`u`?`/`:e===`history`?X(`${window.location.pathname}${window.location.search}`):J()}function re(e,t={}){if(typeof window>`u`)return!1;let n=`#${e}`;return t.replace?(window.history.replaceState(null,``,n),!0):window.location.hash!==n&&(window.location.hash=n,!0)}function ie(e,t={},n=`hash`){if(typeof window>`u`)return!1;if(n!==`history`)return re(e,t);let r=X(e),i=Y(`history`);return!t.replace&&i===r?!1:(t.replace?window.history.replaceState(null,``,r):window.history.pushState(null,``,r),!0)}function ae(e){return X(e).split(`?`)[0]||`/`}function X(e){let[t,n=``]=String(e||`/`).replace(/^#/,``).split(`?`),r=t.startsWith(`/`)?t:`/${t}`,i=r.length>1?r.replace(/\/+$/,``):r;return n?`${i}?${n}`:i}function Z(e){let[t,n=``]=X(e).split(`?`);return{pathname:t,query:Object.fromEntries(new URLSearchParams(n))}}function Q(e){return e.split(`/`).filter(Boolean)}function $(e){return typeof e==`string`||typeof e==`number`}export{v as PageDocumentNode,E as Router,D as createRouter,m as hydrate,g as hydrateOrMount,u as mount,s as parseState,h as renderPage,_ as renderToString,l as resolveLocale,O as router,p as serializeState,j as vLink,k as vRoute,A as vRouter,M as vRouterView,N as vRouterViews};
@@ -0,0 +1,360 @@
1
+ import { Mi as registerChildFactories, Tt as HtmlElementNode, g as createComponentFactory, h as componentClass, v as isPlainObject, vi as bindWindowEvent } from "./yoya.core.chunk.js";
2
+
3
+ //#region src/three/three.js
4
+ const DEFAULT_RENDERER_OPTIONS = Object.freeze({ antialias: true });
5
+ /**
6
+ * VThree 是 Three.js 的生命周期胶水节点:
7
+ * 引擎创建一个真实容器,Three.js 渲染器在客户端挂进容器;
8
+ * 组件负责渲染循环、像素比/尺寸同步与销毁清理。
9
+ * Three.js 本体不打包,使用方通过 threeLib() 注入模块命名空间。
10
+ */
11
+ var VThree = class extends HtmlElementNode {
12
+ constructor(setup = null) {
13
+ super("div", null);
14
+ this._autoRender = true;
15
+ this._autoResize = true;
16
+ this._camera = null;
17
+ this._devicePixelRatio = null;
18
+ this._frameCallbacks = [];
19
+ this._frameId = null;
20
+ this._height = "400px";
21
+ this._initScheduled = false;
22
+ this._onReadyCallbacks = [];
23
+ this._onResizeCallbacks = [];
24
+ this._renderer = null;
25
+ this._rendererOptions = { ...DEFAULT_RENDERER_OPTIONS };
26
+ this._resizeHandler = null;
27
+ this._resizeObserver = null;
28
+ this._resizeUnbind = null;
29
+ this._running = false;
30
+ this._scene = null;
31
+ this._threeLib = null;
32
+ this._width = "100%";
33
+ this.className(componentClass, "yoya-vthree");
34
+ this.styles({
35
+ height: this._height,
36
+ overflow: "hidden",
37
+ position: "relative",
38
+ width: this._width
39
+ });
40
+ this._setupThree(setup);
41
+ }
42
+ threeLib(lib) {
43
+ if (lib) this._threeLib = lib;
44
+ else if (typeof window !== "undefined" && window.THREE) this._threeLib = window.THREE;
45
+ return this;
46
+ }
47
+ getThreeLib() {
48
+ return this._threeLib;
49
+ }
50
+ scene(value) {
51
+ if (value === void 0) return this._scene;
52
+ this._scene = value;
53
+ return this;
54
+ }
55
+ getScene() {
56
+ return this._scene;
57
+ }
58
+ camera(value) {
59
+ if (value === void 0) return this._camera;
60
+ this._camera = value;
61
+ return this;
62
+ }
63
+ getCamera() {
64
+ return this._camera;
65
+ }
66
+ rendererOptions(value) {
67
+ if (value === void 0) return { ...this._rendererOptions };
68
+ this._rendererOptions = {
69
+ ...DEFAULT_RENDERER_OPTIONS,
70
+ ...isPlainObject(value) ? value : {}
71
+ };
72
+ return this;
73
+ }
74
+ width(value) {
75
+ if (value === void 0) return this._width;
76
+ this._width = value;
77
+ this.style("width", value);
78
+ return this;
79
+ }
80
+ height(value) {
81
+ if (value === void 0) return this._height;
82
+ this._height = value;
83
+ this.style("height", value);
84
+ return this;
85
+ }
86
+ devicePixelRatio(value) {
87
+ if (value === void 0) return this._devicePixelRatio;
88
+ this._devicePixelRatio = value;
89
+ if (this._renderer) {
90
+ this._syncPixelRatio();
91
+ this._handleResize();
92
+ }
93
+ return this;
94
+ }
95
+ autoResize(value) {
96
+ if (value === void 0) return this._autoResize;
97
+ this._autoResize = Boolean(value);
98
+ if (this._renderer) {
99
+ if (this._autoResize) {
100
+ if (!this._resizeObserver && !this._resizeHandler) this._initResizeObserver();
101
+ } else this._disconnectResizeObserver();
102
+ }
103
+ return this;
104
+ }
105
+ autoRender(value) {
106
+ if (value === void 0) return this._autoRender;
107
+ this._autoRender = Boolean(value);
108
+ if (this._renderer) {
109
+ if (this._autoRender) this.start();
110
+ else this.stop();
111
+ }
112
+ return this;
113
+ }
114
+ onReady(callback) {
115
+ if (typeof callback === "function") {
116
+ if (this._renderer) callback(this._api());
117
+ else this._onReadyCallbacks.push(callback);
118
+ }
119
+ return this;
120
+ }
121
+ onResize(callback) {
122
+ if (typeof callback === "function") this._onResizeCallbacks.push(callback);
123
+ return this;
124
+ }
125
+ onFrame(callback) {
126
+ if (typeof callback === "function") this._frameCallbacks.push(callback);
127
+ return this;
128
+ }
129
+ getRenderer() {
130
+ return this._renderer;
131
+ }
132
+ start() {
133
+ if (this._renderer && !this._running) {
134
+ this._running = true;
135
+ this._frameId = requestAnimationFrame(() => this._frame());
136
+ }
137
+ return this;
138
+ }
139
+ stop() {
140
+ this._running = false;
141
+ if (this._frameId !== null) {
142
+ cancelAnimationFrame(this._frameId);
143
+ this._frameId = null;
144
+ }
145
+ return this;
146
+ }
147
+ render() {
148
+ if (this._renderer && this._scene && this._camera) this._renderer.render(this._scene, this._camera);
149
+ return this;
150
+ }
151
+ resize() {
152
+ this._handleResize();
153
+ return this;
154
+ }
155
+ dispose() {
156
+ this._disposeThree();
157
+ return this;
158
+ }
159
+ destroy() {
160
+ this._disposeThree();
161
+ return super.destroy();
162
+ }
163
+ renderDom() {
164
+ const element = super.renderDom();
165
+ if (element && !this._renderer && !this._initScheduled) {
166
+ this._initScheduled = true;
167
+ requestAnimationFrame(() => this._init());
168
+ }
169
+ return element;
170
+ }
171
+ _setupThree(setup) {
172
+ if (setup === null || setup === void 0) return;
173
+ if (typeof setup === "function") {
174
+ setup(this);
175
+ return;
176
+ }
177
+ if (isPlainObject(setup)) {
178
+ const { autoRender, autoResize, camera, devicePixelRatio, height, onFrame, onReady, onResize, rendererOptions, scene, threeLib, width, ...elementConfig } = setup;
179
+ if (Object.keys(elementConfig).length > 0) this.setup(elementConfig);
180
+ if (threeLib !== void 0) this.threeLib(threeLib);
181
+ if (scene !== void 0) this.scene(scene);
182
+ if (camera !== void 0) this.camera(camera);
183
+ if (width !== void 0) this.width(width);
184
+ if (height !== void 0) this.height(height);
185
+ if (rendererOptions !== void 0) this.rendererOptions(rendererOptions);
186
+ if (devicePixelRatio !== void 0) this.devicePixelRatio(devicePixelRatio);
187
+ if (autoResize !== void 0) this.autoResize(autoResize);
188
+ if (autoRender !== void 0) this.autoRender(autoRender);
189
+ if (onReady !== void 0) this.onReady(onReady);
190
+ if (onResize !== void 0) this.onResize(onResize);
191
+ if (onFrame !== void 0) this.onFrame(onFrame);
192
+ return;
193
+ }
194
+ this.child(setup);
195
+ }
196
+ _init() {
197
+ this._initScheduled = false;
198
+ if (this._deleted) return;
199
+ if (!this._threeLib) this.threeLib();
200
+ if (!this._threeLib) {
201
+ console.warn("[VThree] Three.js library not provided. Call threeLib() first.");
202
+ return;
203
+ }
204
+ if (this._renderer || !this._el) return;
205
+ try {
206
+ const lib = this._threeLib;
207
+ if (!this._scene) this._scene = new lib.Scene();
208
+ if (!this._camera) {
209
+ this._camera = new lib.PerspectiveCamera(75, 1, .1, 1e3);
210
+ if (typeof this._camera.position?.set === "function") this._camera.position.set(0, 0, 5);
211
+ }
212
+ this._renderer = new lib.WebGLRenderer(this._rendererOptions);
213
+ this._el.appendChild(this._renderer.domElement);
214
+ this._syncPixelRatio();
215
+ this._handleResize();
216
+ this._executeReadyCallbacks();
217
+ if (this._autoRender) this.start();
218
+ else this.render();
219
+ if (this._autoResize) this._initResizeObserver();
220
+ } catch (error) {
221
+ console.error("[VThree] Failed to initialize renderer:", error);
222
+ }
223
+ }
224
+ _frame() {
225
+ if (this._deleted || !this._running || !this._renderer) {
226
+ this._running = false;
227
+ this._frameId = null;
228
+ return;
229
+ }
230
+ const api = this._api();
231
+ this._frameCallbacks.forEach((callback) => {
232
+ try {
233
+ callback(api);
234
+ } catch (error) {
235
+ console.error("[VThree] Error in onFrame callback:", error);
236
+ }
237
+ });
238
+ this.render();
239
+ this._frameId = requestAnimationFrame(() => this._frame());
240
+ }
241
+ _api() {
242
+ return {
243
+ camera: this._camera,
244
+ renderer: this._renderer,
245
+ scene: this._scene,
246
+ threeLib: this._threeLib
247
+ };
248
+ }
249
+ _executeReadyCallbacks() {
250
+ if (!this._renderer) return;
251
+ const api = this._api();
252
+ this._onReadyCallbacks.forEach((callback) => {
253
+ try {
254
+ callback(api);
255
+ } catch (error) {
256
+ console.error("[VThree] Error in onReady callback:", error);
257
+ }
258
+ });
259
+ this._onReadyCallbacks = [];
260
+ }
261
+ _initResizeObserver() {
262
+ if (typeof ResizeObserver !== "undefined") {
263
+ this._resizeObserver = new ResizeObserver((entries) => {
264
+ for (const entry of entries) {
265
+ const { height, width } = entry.contentRect;
266
+ if (width > 0 || height > 0) this._handleResize();
267
+ }
268
+ });
269
+ if (this._el) this._resizeObserver.observe(this._el);
270
+ return;
271
+ }
272
+ this._resizeHandler = () => this._handleResize();
273
+ this._resizeUnbind = bindWindowEvent("resize", this._resizeHandler);
274
+ }
275
+ _disconnectResizeObserver() {
276
+ if (this._resizeObserver) {
277
+ this._resizeObserver.disconnect();
278
+ this._resizeObserver = null;
279
+ }
280
+ if (this._resizeHandler) {
281
+ this._resizeUnbind?.();
282
+ this._resizeHandler = null;
283
+ this._resizeUnbind = null;
284
+ }
285
+ }
286
+ _syncPixelRatio() {
287
+ if (!this._renderer) return;
288
+ const pixelRatio = this._devicePixelRatio ?? (typeof window !== "undefined" && window.devicePixelRatio || 1);
289
+ this._renderer.setPixelRatio(pixelRatio);
290
+ }
291
+ _handleResize() {
292
+ if (!this._renderer) return;
293
+ const { height, width } = this._measureSize();
294
+ this._renderer.setSize(width, height);
295
+ if (this._camera?.isPerspectiveCamera) {
296
+ this._camera.aspect = width / height;
297
+ if (typeof this._camera.updateProjectionMatrix === "function") this._camera.updateProjectionMatrix();
298
+ }
299
+ const size = {
300
+ height,
301
+ width
302
+ };
303
+ this._onResizeCallbacks.forEach((callback) => {
304
+ try {
305
+ callback(size);
306
+ } catch (error) {
307
+ console.error("[VThree] Error in onResize callback:", error);
308
+ }
309
+ });
310
+ this.render();
311
+ }
312
+ _measureSize() {
313
+ let height = 0;
314
+ let width = 0;
315
+ if (this._el) {
316
+ const rect = this._el.getBoundingClientRect();
317
+ width = this._el.clientWidth || rect.width || 0;
318
+ height = this._el.clientHeight || rect.height || 0;
319
+ }
320
+ width = width || this._parseLength(this._width);
321
+ height = height || this._parseLength(this._height);
322
+ return {
323
+ height: Math.max(1, Math.round(height)),
324
+ width: Math.max(1, Math.round(width))
325
+ };
326
+ }
327
+ _parseLength(value) {
328
+ if (typeof value === "number") return value;
329
+ if (typeof value === "string") {
330
+ const match = value.trim().match(/^([\d.]+)px$/);
331
+ return match ? Number(match[1]) : 0;
332
+ }
333
+ return 0;
334
+ }
335
+ _disposeThree() {
336
+ this.stop();
337
+ this._disconnectResizeObserver();
338
+ if (this._renderer) {
339
+ try {
340
+ this._renderer.dispose();
341
+ } catch (error) {
342
+ console.error("[VThree] Failed to dispose renderer:", error);
343
+ }
344
+ this._renderer = null;
345
+ }
346
+ this._camera = null;
347
+ this._frameCallbacks = [];
348
+ this._onReadyCallbacks = [];
349
+ this._onResizeCallbacks = [];
350
+ this._scene = null;
351
+ this._threeLib = null;
352
+ }
353
+ };
354
+ function vThree(first = null, second = null, third = null) {
355
+ return createComponentFactory(VThree, first, second, third);
356
+ }
357
+ registerChildFactories(HtmlElementNode, { vThree });
358
+
359
+ //#endregion
360
+ export { VThree, vThree };
@@ -0,0 +1 @@
1
+ import{Mi as e,Tt as t,g as n,h as r,v as i,vi as a}from"./yoya.core.chunk.min.js";const o=Object.freeze({antialias:!0});var s=class extends t{constructor(e=null){super(`div`,null),this._autoRender=!0,this._autoResize=!0,this._camera=null,this._devicePixelRatio=null,this._frameCallbacks=[],this._frameId=null,this._height=`400px`,this._initScheduled=!1,this._onReadyCallbacks=[],this._onResizeCallbacks=[],this._renderer=null,this._rendererOptions={...o},this._resizeHandler=null,this._resizeObserver=null,this._resizeUnbind=null,this._running=!1,this._scene=null,this._threeLib=null,this._width=`100%`,this.className(r,`yoya-vthree`),this.styles({height:this._height,overflow:`hidden`,position:`relative`,width:this._width}),this._setupThree(e)}threeLib(e){return e?this._threeLib=e:typeof window<`u`&&window.THREE&&(this._threeLib=window.THREE),this}getThreeLib(){return this._threeLib}scene(e){return e===void 0?this._scene:(this._scene=e,this)}getScene(){return this._scene}camera(e){return e===void 0?this._camera:(this._camera=e,this)}getCamera(){return this._camera}rendererOptions(e){return e===void 0?{...this._rendererOptions}:(this._rendererOptions={...o,...i(e)?e:{}},this)}width(e){return e===void 0?this._width:(this._width=e,this.style(`width`,e),this)}height(e){return e===void 0?this._height:(this._height=e,this.style(`height`,e),this)}devicePixelRatio(e){return e===void 0?this._devicePixelRatio:(this._devicePixelRatio=e,this._renderer&&(this._syncPixelRatio(),this._handleResize()),this)}autoResize(e){return e===void 0?this._autoResize:(this._autoResize=!!e,this._renderer&&(this._autoResize?!this._resizeObserver&&!this._resizeHandler&&this._initResizeObserver():this._disconnectResizeObserver()),this)}autoRender(e){return e===void 0?this._autoRender:(this._autoRender=!!e,this._renderer&&(this._autoRender?this.start():this.stop()),this)}onReady(e){return typeof e==`function`&&(this._renderer?e(this._api()):this._onReadyCallbacks.push(e)),this}onResize(e){return typeof e==`function`&&this._onResizeCallbacks.push(e),this}onFrame(e){return typeof e==`function`&&this._frameCallbacks.push(e),this}getRenderer(){return this._renderer}start(){return this._renderer&&!this._running&&(this._running=!0,this._frameId=requestAnimationFrame(()=>this._frame())),this}stop(){return this._running=!1,this._frameId!==null&&(cancelAnimationFrame(this._frameId),this._frameId=null),this}render(){return this._renderer&&this._scene&&this._camera&&this._renderer.render(this._scene,this._camera),this}resize(){return this._handleResize(),this}dispose(){return this._disposeThree(),this}destroy(){return this._disposeThree(),super.destroy()}renderDom(){let e=super.renderDom();return e&&!this._renderer&&!this._initScheduled&&(this._initScheduled=!0,requestAnimationFrame(()=>this._init())),e}_setupThree(e){if(e!=null){if(typeof e==`function`){e(this);return}if(i(e)){let{autoRender:t,autoResize:n,camera:r,devicePixelRatio:i,height:a,onFrame:o,onReady:s,onResize:c,rendererOptions:l,scene:u,threeLib:d,width:f,...p}=e;Object.keys(p).length>0&&this.setup(p),d!==void 0&&this.threeLib(d),u!==void 0&&this.scene(u),r!==void 0&&this.camera(r),f!==void 0&&this.width(f),a!==void 0&&this.height(a),l!==void 0&&this.rendererOptions(l),i!==void 0&&this.devicePixelRatio(i),n!==void 0&&this.autoResize(n),t!==void 0&&this.autoRender(t),s!==void 0&&this.onReady(s),c!==void 0&&this.onResize(c),o!==void 0&&this.onFrame(o);return}this.child(e)}}_init(){if(this._initScheduled=!1,!this._deleted){if(this._threeLib||this.threeLib(),!this._threeLib){console.warn(`[VThree] Three.js library not provided. Call threeLib() first.`);return}if(!(this._renderer||!this._el))try{let e=this._threeLib;this._scene||=new e.Scene,this._camera||(this._camera=new e.PerspectiveCamera(75,1,.1,1e3),typeof this._camera.position?.set==`function`&&this._camera.position.set(0,0,5)),this._renderer=new e.WebGLRenderer(this._rendererOptions),this._el.appendChild(this._renderer.domElement),this._syncPixelRatio(),this._handleResize(),this._executeReadyCallbacks(),this._autoRender?this.start():this.render(),this._autoResize&&this._initResizeObserver()}catch(e){console.error(`[VThree] Failed to initialize renderer:`,e)}}}_frame(){if(this._deleted||!this._running||!this._renderer){this._running=!1,this._frameId=null;return}let e=this._api();this._frameCallbacks.forEach(t=>{try{t(e)}catch(e){console.error(`[VThree] Error in onFrame callback:`,e)}}),this.render(),this._frameId=requestAnimationFrame(()=>this._frame())}_api(){return{camera:this._camera,renderer:this._renderer,scene:this._scene,threeLib:this._threeLib}}_executeReadyCallbacks(){if(!this._renderer)return;let e=this._api();this._onReadyCallbacks.forEach(t=>{try{t(e)}catch(e){console.error(`[VThree] Error in onReady callback:`,e)}}),this._onReadyCallbacks=[]}_initResizeObserver(){if(typeof ResizeObserver<`u`){this._resizeObserver=new ResizeObserver(e=>{for(let t of e){let{height:e,width:n}=t.contentRect;(n>0||e>0)&&this._handleResize()}}),this._el&&this._resizeObserver.observe(this._el);return}this._resizeHandler=()=>this._handleResize(),this._resizeUnbind=a(`resize`,this._resizeHandler)}_disconnectResizeObserver(){this._resizeObserver&&=(this._resizeObserver.disconnect(),null),this._resizeHandler&&(this._resizeUnbind?.(),this._resizeHandler=null,this._resizeUnbind=null)}_syncPixelRatio(){if(!this._renderer)return;let e=this._devicePixelRatio??(typeof window<`u`&&window.devicePixelRatio||1);this._renderer.setPixelRatio(e)}_handleResize(){if(!this._renderer)return;let{height:e,width:t}=this._measureSize();this._renderer.setSize(t,e),this._camera?.isPerspectiveCamera&&(this._camera.aspect=t/e,typeof this._camera.updateProjectionMatrix==`function`&&this._camera.updateProjectionMatrix());let n={height:e,width:t};this._onResizeCallbacks.forEach(e=>{try{e(n)}catch(e){console.error(`[VThree] Error in onResize callback:`,e)}}),this.render()}_measureSize(){let e=0,t=0;if(this._el){let n=this._el.getBoundingClientRect();t=this._el.clientWidth||n.width||0,e=this._el.clientHeight||n.height||0}return t||=this._parseLength(this._width),e||=this._parseLength(this._height),{height:Math.max(1,Math.round(e)),width:Math.max(1,Math.round(t))}}_parseLength(e){if(typeof e==`number`)return e;if(typeof e==`string`){let t=e.trim().match(/^([\d.]+)px$/);return t?Number(t[1]):0}return 0}_disposeThree(){if(this.stop(),this._disconnectResizeObserver(),this._renderer){try{this._renderer.dispose()}catch(e){console.error(`[VThree] Failed to dispose renderer:`,e)}this._renderer=null}this._camera=null,this._frameCallbacks=[],this._onReadyCallbacks=[],this._onResizeCallbacks=[],this._scene=null,this._threeLib=null}};function c(e=null,t=null,r=null){return n(s,e,t,r)}e(t,{vThree:c});export{s as VThree,c as vThree};