Files
bim_engine/dist/bim-engine-sdk.umd.js

9 lines
33 KiB
JavaScript

(function(){"use strict";try{if(typeof document<"u"){var o=document.createElement("style");o.appendChild(document.createTextNode('.bim-engine-wrapper{position:relative;width:100%;height:100%;font-family:sans-serif;color:#333;padding:20px;background-color:#e16969;border-radius:8px;border:1px solid #e0e0e0;box-sizing:border-box}.bim-engine-opt-btn-container{position:absolute;bottom:20px;left:50%;transform:translate(-50%);z-index:100}.bim-btn-group-root{display:flex;gap:8px;z-index:1000;position:absolute;pointer-events:auto}.bim-btn-group-root.static{position:relative;inset:auto;transform:none}.bim-btn-group-root.dir-row{flex-direction:row;align-items:center}.bim-btn-group-root.dir-column{flex-direction:column;align-items:stretch}.bim-btn-group-section{display:flex;gap:4px;background-color:var(--bim-btn-group-section-bg, rgba(17, 17, 17, .88));border-radius:6px;padding:4px}.bim-btn-group-root.dir-row .bim-btn-group-section{flex-direction:row;align-items:center}.bim-btn-group-root.dir-column .bim-btn-group-section{flex-direction:column}.opt-btn-wrapper{position:relative}.opt-btn{display:flex;cursor:pointer;border-radius:4px;transition:background-color .2s,color .2s;color:var(--bim-btn-text-color, #ccc);background-color:var(--bim-btn-bg, transparent);padding:6px;align-items:center;position:relative;justify-content:center}.opt-btn:hover{background-color:var(--bim-btn-hover-bg, #444)}.opt-btn.active{background-color:var(--bim-btn-active-bg, rgba(255, 255, 255, .15));color:var(--bim-btn-text-active-color, #fff)}.opt-btn.active .opt-btn-icon{color:var(--bim-icon-active-color, #fff)}.opt-btn.disabled{opacity:.5;cursor:not-allowed}.opt-btn-icon{width:var(--bim-icon-size, 24px);height:var(--bim-icon-size, 24px);display:flex;align-items:center;justify-content:center;color:var(--bim-icon-color, #ccc);flex-shrink:0}.opt-btn-icon svg{width:100%;height:100%;fill:currentColor}.opt-btn-arrow{font-size:10px;opacity:.6;transition:transform .2s;display:inline-block;margin-left:4px}.opt-btn-arrow.rotated{transform:rotate(180deg)}.opt-btn-text-wrapper{display:flex;align-items:center;justify-content:center;pointer-events:none}.opt-btn-label{display:inline}.opt-btn.no-label .opt-btn-label{display:none}.opt-btn.align-vertical:not(.no-label){flex-direction:column;text-align:center}.opt-btn.align-vertical:not(.no-label) .opt-btn-text-wrapper{margin-top:4px}.opt-btn.align-vertical:not(.no-label) .opt-btn-label{font-size:12px;line-height:1.2}.opt-btn.align-horizontal:not(.no-label){flex-direction:row}.opt-btn.align-horizontal:not(.no-label) .opt-btn-text-wrapper{margin-left:8px}.opt-btn.align-horizontal:not(.no-label) .opt-btn-label{font-size:14px}.opt-btn.no-label .opt-btn-text-wrapper{width:0;height:0;margin:0;padding:0;overflow:visible;position:absolute;top:0;right:0}.opt-btn.no-label .opt-btn-arrow{position:absolute;top:2px;right:2px;margin:0;font-size:8px}.opt-btn-dropdown{position:absolute;background-color:var(--bim-toolbar-bg, rgba(17, 17, 17, .95));border-radius:4px;padding:4px;box-shadow:0 4px 12px #0003;z-index:1001;display:flex;flex-direction:column;border:1px solid rgba(255,255,255,.1);opacity:0;visibility:hidden;transform:translateY(-10px);transition:opacity .2s ease,transform .2s cubic-bezier(.2,0,.2,1),visibility .2s}@keyframes dropdown-fade-in{0%{opacity:0;transform:translateY(-8px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}.opt-btn-dropdown{animation:dropdown-fade-in .2s cubic-bezier(.2,0,.2,1) forwards;opacity:1;visibility:visible;transform:none}.opt-btn-dropdown-item{display:flex;align-items:center;padding:8px 12px;cursor:pointer;border-radius:4px;color:var(--bim-btn-text-color, #ccc);transition:background .2s;box-sizing:border-box}.opt-btn-dropdown-item:hover{background-color:var(--bim-btn-hover-bg, #444);color:#fff}.opt-btn-dropdown-item.align-horizontal{flex-direction:row}.opt-btn-dropdown-item.align-horizontal .opt-btn-icon{width:18px;height:18px;margin-right:8px}.opt-btn-dropdown-item.align-vertical{flex-direction:column;text-align:center}.opt-btn-dropdown-item.align-vertical .opt-btn-icon{width:24px;height:24px;margin-bottom:4px}.opt-btn-dropdown-item.align-vertical .opt-btn-dropdown-label{font-size:12px}.bim-btn-group-root.is-bottom-toolbar .opt-btn-icon{width:32px;height:32px}.bim-btn-group-root.is-bottom-toolbar .opt-btn{padding:8px}:root{--bim-dialog-bg: rgba(17, 17, 17, .95);--bim-dialog-header-bg: #2a2a2a;--bim-dialog-title-color: #fff;--bim-dialog-text-color: #ccc;--bim-dialog-border-color: #444}.bim-dialog{position:absolute;background-color:var(--bim-dialog-bg);border:1px solid var(--bim-dialog-border-color);border-radius:6px;box-shadow:0 4px 12px #0000004d;display:flex;flex-direction:column;z-index:1000;color:var(--bim-dialog-title-color);overflow:hidden;min-width:200px;min-height:100px}.bim-dialog-header{height:32px;background-color:var(--bim-dialog-header-bg);display:flex;align-items:center;justify-content:space-between;padding:0 10px;cursor:default;-webkit-user-select:none;user-select:none;border-bottom:1px solid var(--bim-dialog-border-color);flex-shrink:0}.bim-dialog-header.draggable{cursor:move}.bim-dialog-title{font-size:14px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--bim-dialog-title-color)}.bim-dialog-close{cursor:pointer;font-size:18px;color:#999;line-height:1;margin-left:8px}.bim-dialog-close:hover{color:#fff}.bim-dialog-content{flex:1;padding:10px;overflow:auto;font-size:14px;color:var(--bim-dialog-text-color)}.bim-dialog-resize-handle{position:absolute;width:10px;height:10px;bottom:0;right:0;cursor:se-resize;z-index:10}.bim-dialog-resize-handle:after{content:"";position:absolute;bottom:3px;right:3px;width:6px;height:6px;border-right:2px solid #666;border-bottom:2px solid #666}.bim-dialog-resize-handle:hover:after{border-color:#fff}.bim-info-dialog-content{padding:16px;font-family:sans-serif;color:#333}.bim-info-dialog-content h3{margin-top:0;margin-bottom:12px;border-bottom:1px solid #eee;padding-bottom:8px;color:#0078d4}.bim-info-dialog-content ul{list-style:none;padding:0;margin:0}.bim-info-dialog-content li{margin-bottom:8px;font-size:14px;display:flex}.bim-info-dialog-content li strong{width:80px;color:#555}')),document.head.appendChild(o)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
(function(p,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(p=typeof globalThis<"u"?globalThis:p||self,m(p.LyzBimEngineSDK={}))})(this,(function(p){"use strict";const m={common:{title:"BimEngine",description:"这是一个使用 BIM-ENGINE。",openTestDialog:"打开测试弹窗",openInfoDialog:"打开信息弹窗 (封装版)"},toolbar:{home:"首页",info:"信息",location:"定位",setting:"设置",walk:"漫游",walkPerson:"人视",walkBird:"鸟瞰",walkMenu:"菜单"},dialog:{testTitle:"测试弹窗",testContent:'<div style="padding: 10px;">这是一个 <b>可拖拽</b> 且 <b>可缩放</b> 的弹窗。<br><br>你可以尝试拖动标题栏,或者拖动右下角改变大小。</div>'}},L={common:{title:"BimEngine",description:"This is a BIM-ENGINE demo.",openTestDialog:"Open Test Dialog",openInfoDialog:"Open Info Dialog (Wrapped)"},toolbar:{home:"Home",info:"Info",location:"Location",setting:"Settings",walk:"Walk",walkPerson:"Person",walkBird:"Bird Eye",walkMenu:"Menu"},dialog:{testTitle:"Test Dialog",testContent:'<div style="padding: 10px;">This is a <b>draggable</b> and <b>resizable</b> dialog.<br><br>Try dragging the title bar or resizing from the bottom-right corner.</div>'}};class B{currentLocale="zh-CN";messages={"zh-CN":m,"en-US":L};listeners=[];constructor(){}getLocale(){return this.currentLocale}setLocale(t){this.currentLocale!==t&&(this.currentLocale=t,this.notifyListeners())}t(t){if(!t)return"";const e=t.split(".");let o=this.messages[this.currentLocale];for(const i of e)if(o&&typeof o=="object"&&i in o)o=o[i];else return t;return o}subscribe(t){return this.listeners.push(t),()=>{this.listeners=this.listeners.filter(e=>e!==t)}}notifyListeners(){this.listeners.forEach(t=>t(this.currentLocale))}}const u=new B,g=a=>u.t(a),w={name:"dark",primary:"#0078d4",primaryHover:"#0063b1",background:"#f5f5f5",panelBackground:"rgba(30, 30, 30, 0.9)",textPrimary:"#ffffff",textSecondary:"#cccccc",border:"#444444",icon:"#cccccc",iconActive:"#ffffff",componentBackground:"transparent",componentHover:"#333333",componentActive:"rgba(255, 255, 255, 0.1)"},k={name:"light",primary:"#0078d4",primaryHover:"#106ebe",background:"#f5f5f5",panelBackground:"#ffffff",textPrimary:"#333333",textSecondary:"#666666",border:"#e0e0e0",icon:"#555555",iconActive:"#0078d4",componentBackground:"transparent",componentHover:"#f0f0f0",componentActive:"#e0e0e0"};class x{currentTheme=w;listeners=[];constructor(){}getTheme(){return this.currentTheme}setTheme(t){t==="light"?this.applyTheme(k):this.applyTheme(w)}setCustomTheme(t){this.applyTheme(t)}applyTheme(t){this.currentTheme=t,this.notifyListeners()}subscribe(t){return this.listeners.push(t),t(this.currentTheme),()=>{this.listeners=this.listeners.filter(e=>e!==t)}}notifyListeners(){this.listeners.forEach(t=>t(this.currentTheme))}}const d=new x;class v{container;options;groups=[];activeBtnIds=new Set;btnRefs=new Map;dropdownElement=null;hoverTimeout=null;customColors=new Set;unsubscribeLocale=null;unsubscribeTheme=null;DEFAULT_ICON='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect></svg>';constructor(t){const e=typeof t.container=="string"?document.getElementById(t.container):t.container;if(!e)throw new Error("Container not found");this.container=e,this.options={showLabel:!0,visibility:{},direction:"row",position:"static",align:"vertical",expand:"down",...t},["backgroundColor","btnBackgroundColor","btnHoverColor","btnActiveColor","iconColor","iconActiveColor","textColor","textActiveColor"].forEach(i=>{t[i]&&this.customColors.add(i)}),this.initContainer(),this.applyStyles()}initContainer(){this.container.innerHTML="",this.container.classList.add("bim-btn-group-root"),this.options.direction==="column"?this.container.classList.add("dir-column"):this.container.classList.add("dir-row"),this.options.className&&this.container.classList.add(this.options.className),this.updatePosition()}updatePosition(){const t=this.options.position,e=this.container.style;if(e.top="",e.bottom="",e.left="",e.right="",e.transform="",t==="static"){this.container.classList.add("static");return}if(this.container.classList.remove("static"),this.container.style.position="absolute",typeof t=="object"&&"x"in t)e.left=`${t.x}px`,e.top=`${t.y}px`;else{const o="20px";switch(t){case"top-left":e.top=o,e.left=o;break;case"top-center":e.top=o,e.left="50%",e.transform="translateX(-50%)";break;case"top-right":e.top=o,e.right=o;break;case"bottom-left":e.bottom=o,e.left=o;break;case"bottom-center":e.bottom=o,e.left="50%",e.transform="translateX(-50%)";break;case"bottom-right":e.bottom=o,e.right=o;break;case"left-center":e.left=o,e.top="50%",e.transform="translateY(-50%)";break;case"right-center":e.right=o,e.top="50%",e.transform="translateY(-50%)";break;case"center":e.top="50%",e.left="50%",e.transform="translate(-50%, -50%)";break}}}applyStyles(){const t=this.container.style;this.options.backgroundColor&&t.setProperty("--bim-btn-group-section-bg",this.options.backgroundColor),this.options.btnBackgroundColor&&t.setProperty("--bim-btn-bg",this.options.btnBackgroundColor),this.options.btnHoverColor&&t.setProperty("--bim-btn-hover-bg",this.options.btnHoverColor),this.options.btnActiveColor&&t.setProperty("--bim-btn-active-bg",this.options.btnActiveColor),this.options.iconColor&&t.setProperty("--bim-icon-color",this.options.iconColor),this.options.iconActiveColor&&t.setProperty("--bim-icon-active-color",this.options.iconActiveColor),this.options.textColor&&t.setProperty("--bim-btn-text-color",this.options.textColor),this.options.textActiveColor&&t.setProperty("--bim-btn-text-active-color",this.options.textActiveColor)}setTheme(t){const e={backgroundColor:t.panelBackground,btnBackgroundColor:t.componentBackground,btnHoverColor:t.componentHover,btnActiveColor:t.componentActive,iconColor:t.icon,iconActiveColor:t.iconActive,textColor:t.textSecondary,textActiveColor:t.textPrimary};Object.entries(e).forEach(([o,i])=>{const n=o;this.customColors.has(n)||(this.options[n]=i)}),this.applyStyles()}setColors(t){this.options={...this.options,...t},Object.keys(t).forEach(e=>{this.customColors.add(e)}),this.applyStyles()}async init(){this.render(),this.unsubscribeLocale=u.subscribe(()=>{this.setLocales()}),this.unsubscribeTheme=d.subscribe(t=>{this.setTheme(t)})}setLocales(){this.render()}addGroup(t,e){if(this.groups.some(i=>i.id===t))return;const o={id:t,buttons:[]};if(e){const i=this.groups.findIndex(n=>n.id===e);i!==-1?this.groups.splice(i,0,o):this.groups.push(o)}else this.groups.push(o)}addButton(t){const{groupId:e,parentId:o}=t,i=this.groups.find(s=>s.id===e);if(!i)return;const n={...t,children:t.children||[]};if(o){const s=this.findButton(i.buttons,o);s&&(s.children||(s.children=[]),s.children.push(n))}else i.buttons.push(n)}findButton(t,e){for(const o of t){if(o.id===e)return o;if(o.children){const i=this.findButton(o.children,e);if(i)return i}}}render(){this.container.innerHTML="",this.btnRefs.clear(),this.groups.forEach((t,e)=>{const o=this.renderGroup(t,e,this.groups.length);this.container.appendChild(o)})}renderGroup(t,e,o){const i=document.createElement("div");return i.className="bim-btn-group-section",e<o-1&&i.classList.add("has-divider"),t.buttons.forEach(n=>{if(this.isVisible(n.id)){const s=this.renderButton(n);i.appendChild(s)}}),i}renderButton(t){const e=document.createElement("div");e.className="opt-btn-wrapper";const o=document.createElement("div");o.className="opt-btn",(t.align||this.options.align||"vertical")==="horizontal"?o.classList.add("align-horizontal"):o.classList.add("align-vertical"),this.activeBtnIds.has(t.id)&&o.classList.add("active"),t.disabled&&o.classList.add("disabled"),this.options.showLabel&&t.label||o.classList.add("no-label");const s=t.iconSize||32,r=t.minWidth||50;o.style.minWidth=`${r}px`;const l=document.createElement("div");l.className="opt-btn-icon",l.style.width=`${s}px`,l.style.height=`${s}px`,l.innerHTML=this.getIcon(t.icon),o.appendChild(l);const c=document.createElement("div");if(c.className="opt-btn-text-wrapper",this.options.showLabel&&t.label){const h=document.createElement("span");h.className="opt-btn-label",h.textContent=g(t.label),c.appendChild(h)}if(t.children&&t.children.length>0){const h=document.createElement("span");h.className="opt-btn-arrow",h.textContent="▼",c.appendChild(h)}return c.hasChildNodes()&&o.appendChild(c),o.addEventListener("click",()=>this.handleClick(t)),o.addEventListener("mouseenter",()=>this.handleMouseEnter(t,o)),o.addEventListener("mouseleave",()=>this.handleMouseLeave()),this.btnRefs.set(t.id,o),e.appendChild(o),e}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))}handleMouseEnter(t,e){this.hoverTimeout&&clearTimeout(this.hoverTimeout),t.children&&t.children.length>0?this.showDropdown(t,e):this.closeDropdown()}handleMouseLeave(){this.hoverTimeout=window.setTimeout(()=>this.closeDropdown(),200)}showDropdown(t,e){if(this.closeDropdown(),!t.children)return;const o=document.createElement("div");o.className="opt-btn-dropdown",this.options.backgroundColor&&o.style.setProperty("--bim-toolbar-bg",this.options.backgroundColor);const i=e.getBoundingClientRect(),n=this.options.expand||"down";this.options.direction==="row"?o.style.flexDirection="column":o.style.flexDirection="row",document.body.appendChild(o),t.children.forEach(r=>{if(this.isVisible(r.id)){const l=this.renderDropdownItem(r);o.appendChild(l)}});const s=o.getBoundingClientRect();n==="up"?(o.style.bottom=window.innerHeight-i.top+8+"px",o.style.left=i.left+(i.width-s.width)/2+"px"):n==="down"?(o.style.top=i.bottom+8+"px",o.style.left=i.left+(i.width-s.width)/2+"px"):n==="right"?(o.style.top=i.top+(i.height-s.height)/2+"px",o.style.left=i.right+8+"px"):n==="left"&&(o.style.top=i.top+(i.height-s.height)/2+"px",o.style.right=window.innerWidth-i.left+8+"px"),o.addEventListener("mouseenter",()=>{this.hoverTimeout&&clearTimeout(this.hoverTimeout)}),o.addEventListener("mouseleave",()=>this.handleMouseLeave()),this.dropdownElement=o}renderDropdownItem(t){const e=document.createElement("div");e.className="opt-btn-dropdown-item",(t.align||"horizontal")==="horizontal"?e.classList.add("align-horizontal"):e.classList.add("align-vertical");const i=t.iconSize||32,n=t.minWidth;n&&(e.style.minWidth=`${n}px`);const s=document.createElement("div");if(s.className="opt-btn-icon",s.style.width=`${i}px`,s.style.height=`${i}px`,s.innerHTML=this.getIcon(t.icon),e.appendChild(s),this.options.showLabel&&t.label){const r=document.createElement("span");r.className="opt-btn-dropdown-label",r.textContent=g(t.label),e.appendChild(r)}return e.addEventListener("click",r=>{r.stopPropagation(),this.handleClick(t)}),e}closeDropdown(){this.dropdownElement&&(this.dropdownElement.remove(),this.dropdownElement=null),this.btnRefs.forEach(t=>{const e=t.querySelector(".opt-btn-arrow");e&&e.classList.remove("rotated")})}updateButtonState(t){const e=this.btnRefs.get(t);e&&(this.activeBtnIds.has(t)?e.classList.add("active"):e.classList.remove("active"))}getIcon(t){return t||this.DEFAULT_ICON}updateButtonVisibility(t,e){this.options.visibility||(this.options.visibility={}),this.options.visibility[t]=e,this.render()}setShowLabel(t){this.options.showLabel=t,this.updateLabelsVisibility()}updateLabelsVisibility(){this.btnRefs.forEach((t,e)=>{const o=this.findButtonById(e);if(!o)return;this.options.showLabel&&o.label?t.classList.remove("no-label"):t.classList.add("no-label")})}findButtonById(t){for(const e of this.groups){const o=this.findButton(e.buttons,t);if(o)return o}}setBackgroundColor(t){this.setColors({backgroundColor:t})}isVisible(t){return this.options.visibility?.[t]!==!1}destroy(){this.unsubscribeLocale&&(this.unsubscribeLocale(),this.unsubscribeLocale=null),this.unsubscribeTheme&&(this.unsubscribeTheme(),this.unsubscribeTheme=null),this.closeDropdown(),this.container.innerHTML="",this.btnRefs.clear()}}class C extends v{async init(){await super.init();const{homeButton:t}=await Promise.resolve().then(()=>D),{locationButton:e}=await Promise.resolve().then(()=>q),{walkMenuButton:o}=await Promise.resolve().then(()=>I),{walkPersonButton:i}=await Promise.resolve().then(()=>H),{walkBirdButton:n}=await Promise.resolve().then(()=>_),{settingButton:s}=await Promise.resolve().then(()=>A),{infoButton:r}=await Promise.resolve().then(()=>G);this.addGroup("group-1"),this.addButton(t),this.addButton(o),this.addButton(i),this.addButton(n),this.addButton(e),this.addGroup("group-2"),this.addButton(s),this.addButton(r),this.render()}}class E{toolbar=null;toolbarContainer=null;container;constructor(t){this.container=t,this.init()}init(){this.toolbarContainer=document.createElement("div"),this.toolbarContainer.id="opt-btn-groups",this.toolbarContainer.className="bim-engine-opt-btn-container is-bottom-toolbar",this.container.appendChild(this.toolbarContainer),this.toolbar=new C({container:this.toolbarContainer,showLabel:!0,direction:"row",position:"bottom-center",align:"vertical",expand:"up"}),this.toolbar.init()}updateTheme(t){this.toolbar?.setTheme(t)}refresh(){this.toolbar?.render()}destroy(){this.toolbar?.destroy(),this.toolbar=null}addGroup(t,e){this.toolbar?.addGroup(t,e),this.toolbar?.render()}addButton(t){this.toolbar?.addButton(t),this.toolbar?.render()}setButtonVisibility(t,e){this.toolbar?.updateButtonVisibility(t,e)}setShowLabel(t){this.toolbar?.setShowLabel(t)}setVisible(t){this.toolbarContainer&&(this.toolbarContainer.style.visibility=t?"visible":"hidden")}setBackgroundColor(t){this.toolbar?.setBackgroundColor(t)}setColors(t){this.toolbar?.setColors(t)}}class M{activeGroups=[];container;constructor(t){this.container=t}create(t){const e=document.createElement("div");this.container.appendChild(e);const o=new v({container:e,...t});return o.init(),this.activeGroups.push(o),o}updateTheme(t){this.activeGroups.forEach(e=>e.setTheme(t))}refresh(){this.activeGroups.forEach(t=>t.render())}destroy(){this.activeGroups.forEach(t=>t.destroy()),this.activeGroups=[]}}class T{element;options;container;header;contentArea;_isDestroyed=!1;_isInitialized=!1;unsubscribeTheme=null;unsubscribeLocale=null;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()}setTheme(t){const e=this.element.style;this.options.backgroundColor||e.setProperty("--bim-dialog-bg",t.panelBackground),this.options.headerBackgroundColor||e.setProperty("--bim-dialog-header-bg",t.componentHover),this.options.titleColor||e.setProperty("--bim-dialog-title-color",t.textPrimary),this.options.textColor||e.setProperty("--bim-dialog-text-color",t.textPrimary),this.options.borderColor||e.setProperty("--bim-dialog-border-color",t.border)}init(){this._isInitialized||(this.container.appendChild(this.element),this.initPosition(),this.options.draggable&&this.initDrag(),this.options.resizable&&this.initResize(),this._isInitialized=!0,this.options.onOpen&&this.options.onOpen(),this.unsubscribeTheme=d.subscribe(t=>{this.setTheme(t)}),this.unsubscribeLocale=u.subscribe(()=>{this.setLocales()}))}setLocales(){if(this.options.title){const t=this.header.querySelector(".bim-dialog-title");t&&(t.textContent=g(this.options.title))}}createDom(){const t=document.createElement("div");t.className="bim-dialog",this.options.id&&(t.id=this.options.id);const e=t.style;this.options.backgroundColor&&e.setProperty("--bim-dialog-bg",this.options.backgroundColor),this.options.headerBackgroundColor&&e.setProperty("--bim-dialog-header-bg",this.options.headerBackgroundColor),this.options.titleColor&&e.setProperty("--bim-dialog-title-color",this.options.titleColor),this.options.textColor&&e.setProperty("--bim-dialog-text-color",this.options.textColor),this.options.borderColor&&e.setProperty("--bim-dialog-border-color",this.options.borderColor),this.setSize(t,this.options.width,this.options.height);const o=document.createElement("div");o.className="bim-dialog-header",this.options.draggable&&o.classList.add("draggable");const i=document.createElement("span");i.className="bim-dialog-title",i.textContent=this.options.title?g(this.options.title):"";const n=document.createElement("span");n.className="bim-dialog-close",n.innerHTML="&times;",n.onclick=()=>this.close(),o.appendChild(i),o.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(o),t.appendChild(s),this.options.resizable){const r=document.createElement("div");r.className="bim-dialog-resize-handle",t.appendChild(r)}return t}setSize(t,e,o){e!==void 0&&(t.style.width=typeof e=="number"?`${e}px`:e),o!==void 0&&(t.style.height=typeof o=="number"?`${o}px`:o)}initPosition(){const t=this.options.position,e=this.element.getBoundingClientRect();let o=0,i=0;const n=this.container.clientWidth,s=this.container.clientHeight,r=e.width,l=e.height;if(typeof t=="object"&&"x"in t)o=t.x,i=t.y;else switch(t){case"center":o=(n-r)/2,i=(s-l)/2;break;case"top-left":o=0,i=0;break;case"top-center":o=(n-r)/2,i=0;break;case"top-right":o=n-r,i=0;break;case"left-center":o=0,i=(s-l)/2;break;case"right-center":o=n-r,i=(s-l)/2;break;case"bottom-left":o=0,i=s-l;break;case"bottom-center":o=(n-r)/2,i=s-l;break;case"bottom-right":o=n-r,i=s-l;break;default:o=(n-r)/2,i=(s-l)/2}o=Math.max(0,Math.min(o,n-r)),i=Math.max(0,Math.min(i,s-l)),this.element.style.left=`${o}px`,this.element.style.top=`${i}px`}initDrag(){let t=0,e=0,o=0,i=0;const n=l=>{l.preventDefault(),t=l.clientX,e=l.clientY,o=this.element.offsetLeft,i=this.element.offsetTop,document.addEventListener("mousemove",s),document.addEventListener("mouseup",r)},s=l=>{const c=l.clientX-t,h=l.clientY-e;let b=o+c,f=i+h;const y=this.container.clientWidth-this.element.offsetWidth,N=this.container.clientHeight-this.element.offsetHeight;b=Math.max(0,Math.min(b,y)),f=Math.max(0,Math.min(f,N)),this.element.style.left=`${b}px`,this.element.style.top=`${f}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 e=0,o=0,i=0,n=0;const s=c=>{c.preventDefault(),c.stopPropagation(),e=c.clientX,o=c.clientY,i=this.element.offsetWidth,n=this.element.offsetHeight,document.addEventListener("mousemove",r),document.addEventListener("mouseup",l)},r=c=>{const h=c.clientX-e,b=c.clientY-o,f=Math.max(this.options.minWidth||100,i+h),y=Math.max(this.options.minHeight||50,n+b);this.element.style.width=`${f}px`,this.element.style.height=`${y}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.unsubscribeTheme&&(this.unsubscribeTheme(),this.unsubscribeTheme=null),this.unsubscribeLocale&&(this.unsubscribeLocale(),this.unsubscribeLocale=null),this.element.remove(),this._isDestroyed=!0,this.options.onClose&&this.options.onClose())}destroy(){this.close()}}class P extends T{constructor(t){const e=document.createElement("div");e.className="bim-info-dialog-content";const o=document.createElement("h3");o.textContent="Model Information";const i=document.createElement("ul");i.innerHTML=`
<li><strong>Name:</strong> Sample Project</li>
<li><strong>Version:</strong> 1.0.0</li>
<li><strong>Date:</strong> ${new Date().toLocaleDateString()}</li>
<li><strong>Status:</strong> <span style="color: green;">Active</span></li>
`;const n=document.createElement("button");n.textContent="Update Status",n.style.marginTop="10px",n.onclick=()=>{alert("Status updated!")},e.appendChild(o),e.appendChild(i),e.appendChild(n),super({container:t,title:"dialog.testTitle",content:e,width:320,height:"auto",position:"center",resizable:!0,draggable:!0,onClose:()=>{console.log("Info dialog closed")},onOpen:()=>{console.log("Info dialog opened")}})}}class S{container;activeDialogs=[];constructor(t){this.container=t}create(t){const e=new T({container:this.container,...t,onClose:()=>{this.activeDialogs=this.activeDialogs.filter(o=>o!==e),t.onClose&&t.onClose()}});return e.setTheme(d.getTheme()),this.activeDialogs.push(e),e}showInfoDialog(){new P(this.container)}updateTheme(t){this.activeDialogs.forEach(e=>{e.setTheme&&e.setTheme(t)})}}class z{container;wrapper=null;topLeftGroup=null;toolbar=null;buttonGroup=null;dialog=null;get localeManager(){return u}get themeManager(){return d}constructor(t,e){const o=typeof t=="string"?document.getElementById(t):t;if(!o)throw new Error("Container not found");this.container=o,e?.locale&&u.setLocale(e.locale),e?.theme&&(e.theme==="custom"?console.warn("Custom theme should be set via setCustomTheme()."):d.setTheme(e.theme)),this.init()}setLocale(t){u.setLocale(t)}getLocale(){return u.getLocale()}setTheme(t){d.setTheme(t)}setCustomTheme(t){d.setCustomTheme(t)}init(){this.container.innerHTML="",this.wrapper=document.createElement("div"),this.wrapper.className="bim-engine-wrapper",this.container.appendChild(this.wrapper),this.dialog=new S(this.wrapper),this.toolbar=new E(this.wrapper),this.buttonGroup=new M(this.wrapper),this.createTopLeftGroup(),this.updateTheme(d.getTheme()),this.topLeftGroup&&this.topLeftGroup.setColors({backgroundColor:"#ff00ff"}),d.subscribe(t=>{this.updateTheme(t)})}createTopLeftGroup(){this.buttonGroup&&(this.topLeftGroup=this.buttonGroup.create({position:"top-left",direction:"column",align:"vertical",backgroundColor:"#ff00ff",showLabel:!1}),this.topLeftGroup.addGroup("main"),this.topLeftGroup.addButton({id:"menu-btn",groupId:"main",type:"button",label:"Menu",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"/></svg>',onClick:()=>{alert("点击按钮")}}),this.topLeftGroup.render())}updateTheme(t){this.wrapper&&(this.wrapper.style.backgroundColor=t.background,this.wrapper.style.color=t.textPrimary)}destroy(){this.toolbar?.destroy(),this.buttonGroup?.destroy(),this.dialog=null,this.container.innerHTML=""}}const D=Object.freeze(Object.defineProperty({__proto__:null,homeButton:{id:"home",groupId:"group-1",type:"button",label:"toolbar.home",icon:'<svg width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M4 21V9l8-6l8 6v12h-6v-7h-4v7z"/></svg>',keepActive:!0,onClick:a=>{console.log("首页按钮被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"})),q=Object.freeze(Object.defineProperty({__proto__:null,locationButton:{id:"location",groupId:"group-1",type:"button",label:"toolbar.location",icon:'<svg width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M9 13h2v-2.75h2V13h2V8.25l-3-2l-3 2zm3 9q-4.025-3.425-6.012-6.362T4 10.2q0-3.75 2.413-5.975T12 2t5.588 2.225T20 10.2q0 2.5-1.987 5.438T12 22"/></svg>',keepActive:!1,onClick:a=>{console.log("定位按钮被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"})),I=Object.freeze(Object.defineProperty({__proto__:null,walkMenuButton:{id:"walk",groupId:"group-1",type:"menu",label:"toolbar.walk",align:"vertical",icon:'<svg width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M9 22V8.775q-2.275-.6-3.637-2.512T4 2h2q0 2.075 1.338 3.538T10.75 7h2.5q.75 0 1.4.275t1.175.8L20.35 12.6l-1.4 1.4L15 10.05V22h-2v-6h-2v6zm3-16q-.825 0-1.412-.587T10 4t.588-1.412T12 2t1.413.588T14 4t-.587 1.413T12 6"/></svg>',keepActive:!0,onClick:a=>{console.log("漫游按钮被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"})),H=Object.freeze(Object.defineProperty({__proto__:null,walkPersonButton:{id:"walk-person",groupId:"group-1",parentId:"walk",type:"button",align:"vertical",label:"toolbar.walkPerson",icon:'<svg width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M9 22V8.775q-2.275-.6-3.637-2.512T4 2h2q0 2.075 1.338 3.538T10.75 7h2.5q.75 0 1.4.275t1.175.8L20.35 12.6l-1.4 1.4L15 10.05V22h-2v-6h-2v6zm3-16q-.825 0-1.412-.587T10 4t.588-1.412T12 2t1.413.588T14 4t-.587 1.413T12 6"/></svg>',onClick:a=>{console.log("人视漫游被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"})),_=Object.freeze(Object.defineProperty({__proto__:null,walkBirdButton:{id:"walk-bird",groupId:"group-1",parentId:"walk",align:"vertical",type:"button",label:"toolbar.walkBird",icon:'<svg width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M9 22V8.775q-2.275-.6-3.637-2.512T4 2h2q0 2.075 1.338 3.538T10.75 7h2.5q.75 0 1.4.275t1.175.8L20.35 12.6l-1.4 1.4L15 10.05V22h-2v-6h-2v6zm3-16q-.825 0-1.412-.587T10 4t.588-1.412T12 2t1.413.588T14 4t-.587 1.413T12 6"/></svg>',onClick:a=>{console.log("鸟瞰漫游被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"})),A=Object.freeze(Object.defineProperty({__proto__:null,settingButton:{id:"setting",groupId:"group-2",type:"button",label:"toolbar.setting",icon:'<svg width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="m9.25 22l-.4-3.2q-.325-.125-.612-.3t-.563-.375L4.7 19.375l-2.75-4.75l2.575-1.95Q4.5 12.5 4.5 12.338v-.675q0-.163.025-.338L1.95 9.375l2.75-4.75l2.975 1.25q.275-.2.575-.375t.6-.3l.4-3.2h5.5l.4 3.2q.325.125.613.3t.562.375l2.975-1.25l2.75 4.75l-2.575 1.95q.025.175.025.338v.674q0 .163-.05.338l2.575 1.95l-2.75 4.75l-2.95-1.25q-.275.2-.575.375t-.6.3l-.4 3.2zM11 20h1.975l.35-2.65q.775-.2 1.438-.587t1.212-.938l2.475 1.025l.975-1.7l-2.15-1.625q.125-.35.175-.737T17.5 12t-.05-.787t-.175-.738l2.15-1.625l-.975-1.7l-2.475 1.05q-.55-.575-1.212-.962t-1.438-.588L13 4h-1.975l-.35 2.65q-.775.2-1.437.588t-1.213.937L5.55 7.15l-.975 1.7l2.15 1.6q-.125.375-.175.75t-.05.8q0 .4.05.775t.175.75l-2.15 1.625l.975 1.7l2.475-1.05q.55.575 1.213.963t1.437.587zm1.05-4.5q1.45 0 2.475-1.025T15.55 12t-1.025-2.475T12.05 8.5q-1.475 0-2.488 1.025T8.55 12t1.013 2.475T12.05 15.5M12 12"/></svg>',keepActive:!1,onClick:a=>{console.log("设置按钮被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"})),G=Object.freeze(Object.defineProperty({__proto__:null,infoButton:{id:"info",groupId:"group-2",type:"button",label:"toolbar.info",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M12 7q.425 0 .713-.288T13 6t-.288-.712T12 5t-.712.288T11 6t.288.713T12 7m0 8q.425 0 .713-.288T13 14v-4q0-.425-.288-.712T12 9t-.712.288T11 10v4q0 .425.288.713T12 15m-6 3l-2.3 2.3q-.475.475-1.088.213T2 19.575V4q0-.825.588-1.412T4 2h16q.825 0 1.413.588T22 4v12q0 .825-.587 1.413T20 18z"/></svg>',keepActive:!1,onClick:a=>{console.log("信息按钮被点击:",a.id)}}},Symbol.toStringTag,{value:"Module"}));p.BimButtonGroup=v,p.BimEngine=z,p.Toolbar=C,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
//# sourceMappingURL=bim-engine-sdk.umd.js.map