{if(this.isVisible(n.id)){const s=this.renderButton(n);i.appendChild(s)}}),i}renderButton(t){const o=document.createElement("div");o.className="opt-btn-wrapper";const e=document.createElement("div");e.className="opt-btn",this.activeBtnIds.has(t.id)&&e.classList.add("active"),t.disabled&&e.classList.add("disabled"),this.options.showLabel||(e.classList.add("no-label"),t.label&&(e.title=t.label));const i=document.createElement("div");if(i.className="opt-btn-icon",i.innerHTML=this.getIcon(t.icon),e.appendChild(i),this.options.showLabel&&t.label){const n=document.createElement("span");n.className="opt-btn-label",n.textContent=t.label,e.appendChild(n)}if(t.children&&t.children.length>0){const n=document.createElement("span");n.className="opt-btn-arrow",n.textContent="▼",e.appendChild(n)}return e.addEventListener("click",()=>this.handleClick(t)),e.addEventListener("mouseenter",()=>this.handleMouseEnter(t,e)),e.addEventListener("mouseleave",()=>this.handleMouseLeave()),this.btnRefs.set(t.id,e),o.appendChild(e),o}handleClick(t){t.disabled||(!t.children||t.children.length===0)&&(t.keepActive&&(this.activeBtnIds.has(t.id)?this.activeBtnIds.delete(t.id):this.activeBtnIds.add(t.id),this.updateButtonState(t.id)),this.closeDropdown(),t.onClick&&t.onClick(t))}handleSubClick(t){t.keepActive&&(this.activeBtnIds.has(t.id)?this.activeBtnIds.delete(t.id):this.activeBtnIds.add(t.id),this.updateButtonState(t.id)),this.closeDropdown(),t.onClick&&t.onClick(t)}handleMouseEnter(t,o){if(this.hoverTimeout&&(clearTimeout(this.hoverTimeout),this.hoverTimeout=null),t.children&&t.children.length>0){this.showDropdown(t,o);const e=o.querySelector(".opt-btn-arrow");e&&e.classList.add("rotated")}else this.closeDropdown()}handleMouseLeave(){this.hoverTimeout=window.setTimeout(()=>{this.closeDropdown()},200)}showDropdown(t,o){if(this.closeDropdown(),!t.children)return;const e=document.createElement("div");e.className="opt-btn-dropdown";const i=e.style;this.options.backgroundColor&&i.setProperty("--bim-toolbar-bg",this.options.backgroundColor),this.options.btnBackgroundColor&&i.setProperty("--bim-btn-bg",this.options.btnBackgroundColor),this.options.btnHoverColor&&i.setProperty("--bim-btn-hover-bg",this.options.btnHoverColor),this.options.btnActiveColor&&i.setProperty("--bim-btn-active-bg",this.options.btnActiveColor),this.options.iconColor&&i.setProperty("--bim-icon-color",this.options.iconColor),this.options.iconActiveColor&&i.setProperty("--bim-icon-active-color",this.options.iconActiveColor),this.options.textColor&&i.setProperty("--bim-btn-text-color",this.options.textColor),this.options.textActiveColor&&i.setProperty("--bim-btn-text-active-color",this.options.textActiveColor);const n=o.getBoundingClientRect(),s=n.left+n.width/2;e.style.top=n.top-8+"px",e.style.left=s+"px",t.children.forEach(r=>{if(this.isVisible(r.id)){const l=this.renderDropdownItem(r);e.appendChild(l)}}),e.addEventListener("mouseenter",()=>{this.hoverTimeout&&(clearTimeout(this.hoverTimeout),this.hoverTimeout=null)}),e.addEventListener("mouseleave",()=>this.handleMouseLeave()),document.body.appendChild(e),this.dropdownElement=e}renderDropdownItem(t){const o=document.createElement("div");o.className="opt-btn-dropdown-item";const e=document.createElement("div");if(e.className="opt-btn-icon small",e.innerHTML=this.getIcon(t.icon),o.appendChild(e),this.options.showLabel){const i=document.createElement("span");i.textContent=t.label,o.appendChild(i)}return o.addEventListener("click",i=>{i.stopPropagation(),this.handleSubClick(t)}),o}closeDropdown(){this.dropdownElement&&(this.dropdownElement.remove(),this.dropdownElement=null),this.btnRefs.forEach(t=>{const o=t.querySelector(".opt-btn-arrow");o&&o.classList.remove("rotated")})}updateButtonState(t){const o=this.btnRefs.get(t);o&&(this.activeBtnIds.has(t)?o.classList.add("active"):o.classList.remove("active"))}getIcon(t){return t||this.DEFAULT_ICON}updateButtonVisibility(t,o){this.options.visibility||(this.options.visibility={}),this.options.visibility[t]=o,this.render()}setShowLabel(t){this.options.showLabel=t,this.render()}setBackgroundColor(t){this.setColors({backgroundColor:t})}isVisible(t){return this.options.visibility?.[t]!==!1}destroy(){this.closeDropdown(),this.hoverTimeout&&clearTimeout(this.hoverTimeout),this.container.innerHTML="",this.btnRefs.clear(),this.activeBtnIds.clear(),this.groups=[]}}class f{optBtnGroups=null;container;constructor(t){this.container=t,this.init()}init(){this.optBtnGroups=new h({container:this.container,showLabel:!0}),this.optBtnGroups.init().catch(t=>{console.error("Failed to initialize OptBtnGroups:",t)})}addGroup(t,o){this.optBtnGroups?(this.optBtnGroups.addGroup(t,o),this.optBtnGroups.render()):console.warn("Toolbar not initialized yet.")}addButton(t){this.optBtnGroups?(this.optBtnGroups.addButton(t),this.optBtnGroups.render()):console.warn("Toolbar not initialized yet.")}setButtonVisibility(t,o){this.optBtnGroups?this.optBtnGroups.updateButtonVisibility(t,o):console.warn("Toolbar not initialized yet.")}setShowLabel(t){this.optBtnGroups?this.optBtnGroups.setShowLabel(t):console.warn("Toolbar not initialized yet.")}setVisible(t){this.container.style.display=t?"block":"none"}setBackgroundColor(t){this.optBtnGroups?this.optBtnGroups.setBackgroundColor(t):console.warn("Toolbar not initialized yet.")}setColors(t){this.optBtnGroups?this.optBtnGroups.setColors(t):console.warn("Toolbar not initialized yet.")}destroy(){this.optBtnGroups&&(this.optBtnGroups.destroy(),this.optBtnGroups=null)}}class b{element;options;container;header;contentArea;_isDestroyed=!1;constructor(t){this.options={title:"Dialog",width:300,height:"auto",position:"center",draggable:!0,resizable:!1,minWidth:200,minHeight:100,...t},this.container=t.container,this.element=this.createDom(),this.header=this.element.querySelector(".bim-dialog-header"),this.contentArea=this.element.querySelector(".bim-dialog-content"),this.init()}createDom(){const t=document.createElement("div");t.className="bim-dialog",this.options.id&&(t.id=this.options.id);const o=t.style;this.options.backgroundColor&&o.setProperty("--bim-dialog-bg",this.options.backgroundColor),this.options.headerBackgroundColor&&o.setProperty("--bim-dialog-header-bg",this.options.headerBackgroundColor),this.options.titleColor&&o.setProperty("--bim-dialog-title-color",this.options.titleColor),this.options.textColor&&o.setProperty("--bim-dialog-text-color",this.options.textColor),this.options.borderColor&&o.setProperty("--bim-dialog-border-color",this.options.borderColor),this.setSize(t,this.options.width,this.options.height);const e=document.createElement("div");e.className="bim-dialog-header",this.options.draggable&&e.classList.add("draggable");const i=document.createElement("span");i.className="bim-dialog-title",i.textContent=this.options.title||"";const n=document.createElement("span");n.className="bim-dialog-close",n.innerHTML="×",n.onclick=()=>this.close(),e.appendChild(i),e.appendChild(n);const s=document.createElement("div");if(s.className="bim-dialog-content",typeof this.options.content=="string"?s.innerHTML=this.options.content:this.options.content instanceof HTMLElement&&s.appendChild(this.options.content),t.appendChild(e),t.appendChild(s),this.options.resizable){const r=document.createElement("div");r.className="bim-dialog-resize-handle",t.appendChild(r)}return t}setSize(t,o,e){o!==void 0&&(t.style.width=typeof o=="number"?`${o}px`:o),e!==void 0&&(t.style.height=typeof e=="number"?`${e}px`:e)}init(){this.container.appendChild(this.element),this.initPosition(),this.options.draggable&&this.initDrag(),this.options.resizable&&this.initResize()}initPosition(){const t=this.options.position,o=this.element.getBoundingClientRect();let e=0,i=0;const n=this.container.clientWidth,s=this.container.clientHeight,r=o.width,l=o.height;if(typeof t=="object"&&"x"in t)e=t.x,i=t.y;else switch(t){case"center":e=(n-r)/2,i=(s-l)/2;break;case"top-left":e=0,i=0;break;case"top-center":e=(n-r)/2,i=0;break;case"top-right":e=n-r,i=0;break;case"left-center":e=0,i=(s-l)/2;break;case"right-center":e=n-r,i=(s-l)/2;break;case"bottom-left":e=0,i=s-l;break;case"bottom-center":e=(n-r)/2,i=s-l;break;case"bottom-right":e=n-r,i=s-l;break;default:e=(n-r)/2,i=(s-l)/2}e=Math.max(0,Math.min(e,n-r)),i=Math.max(0,Math.min(i,s-l)),this.element.style.left=`${e}px`,this.element.style.top=`${i}px`}initDrag(){let t=0,o=0,e=0,i=0;const n=l=>{l.preventDefault(),t=l.clientX,o=l.clientY,e=this.element.offsetLeft,i=this.element.offsetTop,document.addEventListener("mousemove",s),document.addEventListener("mouseup",r)},s=l=>{const c=l.clientX-t,m=l.clientY-o;let p=e+c,u=i+m;const g=this.container.clientWidth-this.element.offsetWidth,M=this.container.clientHeight-this.element.offsetHeight;p=Math.max(0,Math.min(p,g)),u=Math.max(0,Math.min(u,M)),this.element.style.left=`${p}px`,this.element.style.top=`${u}px`},r=()=>{document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",r)};this.header.addEventListener("mousedown",n)}initResize(){const t=this.element.querySelector(".bim-dialog-resize-handle");if(!t)return;let o=0,e=0,i=0,n=0;const s=c=>{c.preventDefault(),c.stopPropagation(),o=c.clientX,e=c.clientY,i=this.element.offsetWidth,n=this.element.offsetHeight,document.addEventListener("mousemove",r),document.addEventListener("mouseup",l)},r=c=>{const m=c.clientX-o,p=c.clientY-e,u=Math.max(this.options.minWidth||100,i+m),g=Math.max(this.options.minHeight||50,n+p);this.element.style.width=`${u}px`,this.element.style.height=`${g}px`},l=()=>{document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",l)};t.addEventListener("mousedown",s)}setContent(t){this.contentArea.innerHTML="",typeof t=="string"?this.contentArea.innerHTML=t:this.contentArea.appendChild(t)}close(){this._isDestroyed||(this.element.remove(),this._isDestroyed=!0,this.options.onClose&&this.options.onClose())}}class v{dialog;constructor(t){const o=document.createElement("div");o.className="bim-info-dialog-content";const e=document.createElement("h3");e.textContent="Model Information";const i=document.createElement("ul");i.innerHTML=`
Name: Sample Project
Version: 1.0.0
Date: ${new Date().toLocaleDateString()}
Status: Active
`;const n=document.createElement("button");n.textContent="Update Status",n.style.marginTop="10px",n.onclick=()=>{alert("Status updated!")},o.appendChild(e),o.appendChild(i),o.appendChild(n),this.dialog=new b({container:t,title:"Project Info (Wrapped)",content:o,width:320,height:"auto",position:"center",resizable:!0,draggable:!0})}close(){this.dialog.close()}}class w{container;constructor(t){this.container=t}create(t){return new b({container:this.container,...t})}showInfoDialog(){new v(this.container)}}class C{container;wrapper=null;toolbar=null;dialog=null;constructor(t){const o=typeof t=="string"?document.getElementById(t):t;if(!o)throw new Error("Container not found");this.container=o,this.init()}init(){this.container.innerHTML="",this.wrapper=document.createElement("div"),this.wrapper.className="bim-engine-wrapper";const t=document.createElement("h1");t.textContent="BimEngine",t.className="bim-engine-title";const o=document.createElement("p");o.textContent="这是一个使用BIM-ENGINE。",o.className="bim-engine-desc";const e=document.createElement("div");e.id="opt-btn-groups",e.className="bim-engine-opt-btn-container",this.wrapper.appendChild(t),this.wrapper.appendChild(o),this.dialog=new w(this.wrapper),this.toolbar=new f(e);const i=document.createElement("button");i.textContent="打开测试弹窗",i.className="bim-engine-btn",i.onclick=()=>{this.dialog?.create({title:"测试弹窗",content:'这是一个 可拖拽 且 可缩放 的弹窗。
你可以尝试拖动标题栏,或者拖动右下角改变大小。
',width:300,height:400,position:"top-left",draggable:!0,resizable:!0})};const n=document.createElement("button");n.textContent="打开信息弹窗 (封装版)",n.className="bim-engine-btn",n.style.marginLeft="10px",n.onclick=()=>{this.dialog?.showInfoDialog()},this.wrapper.appendChild(i),this.wrapper.appendChild(n),this.wrapper.appendChild(e),this.container.appendChild(this.wrapper)}destroy(){this.toolbar&&(this.toolbar.destroy(),this.toolbar=null),this.dialog=null,this.container.innerHTML=""}}const y=Object.freeze(Object.defineProperty({__proto__:null,homeButton:{id:"home",groupId:"group-1",type:"button",label:"首页",icon:'',keepActive:!0,onClick:a=>{console.log("首页按钮被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"})),B=Object.freeze(Object.defineProperty({__proto__:null,locationButton:{id:"location",groupId:"group-1",type:"button",label:"定位",icon:'',keepActive:!1,onClick:a=>{console.log("定位按钮被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"})),T=Object.freeze(Object.defineProperty({__proto__:null,walkMenuButton:{id:"walk",groupId:"group-1",type:"menu",label:"漫游",icon:'',keepActive:!0,onClick:a=>{console.log("漫游按钮被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"})),E=Object.freeze(Object.defineProperty({__proto__:null,walkPersonButton:{id:"walk-person",groupId:"group-1",parentId:"walk",type:"button",label:"人视漫游",icon:'',onClick:a=>{console.log("人视漫游被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"})),x=Object.freeze(Object.defineProperty({__proto__:null,walkBirdButton:{id:"walk-bird",groupId:"group-1",parentId:"walk",type:"button",label:"鸟瞰漫游",icon:'',onClick:a=>{console.log("鸟瞰漫游被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"})),L=Object.freeze(Object.defineProperty({__proto__:null,settingButton:{id:"setting",groupId:"group-2",type:"button",label:"设置",icon:'',keepActive:!1,onClick:a=>{console.log("设置按钮被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"})),k=Object.freeze(Object.defineProperty({__proto__:null,infoButton:{id:"info",groupId:"group-2",type:"button",label:"信息",icon:'',keepActive:!1,onClick:a=>{console.log("信息按钮被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"}));d.BimEngine=C,d.OptBtnGroups=h,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
//# sourceMappingURL=bim-engine-sdk.umd.js.map