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

9 lines
25 KiB
JavaScript
Raw Normal View History

(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}:root{--bim-toolbar-bg: rgba(17, 17, 17, .88);--bim-btn-bg: transparent;--bim-btn-hover-bg: #444;--bim-btn-active-bg: rgba(255, 255, 255, .15);--bim-icon-color: #ccc;--bim-icon-active-color: #fff;--bim-btn-text-color: #ccc;--bim-btn-text-active-color: #fff}.toolbar-container{display:flex;align-items:center;max-width:100%;overflow-x:auto;scrollbar-width:none;-ms-overflow-style:none}.toolbar-container::-webkit-scrollbar{display:none}.opt-btn-group{overflow:hidden;display:flex;align-items:center;flex-shrink:0;background-color:var(--bim-toolbar-bg);border-radius:4px;padding:4px 8px}.has-divider{margin-right:16px}.opt-btn-wrapper{position:relative}.opt-btn{display:flex;flex-direction:column;align-items:center;justify-content:center;width:50px;min-height:50px;padding:4px;cursor:pointer;background-color:var(--bim-btn-bg);color:var(--bim-icon-color);transition:all .2s;border-bottom:2px solid transparent}.opt-btn:hover{background-color:var(--bim-btn-hover-bg);color:var(--bim-icon-active-color)}.opt-btn.active{background-color:var(--bim-btn-active-bg);color:var(--bim-icon-active-color);border-bottom:2px solid #fff}.opt-btn.disabled{opacity:.5;cursor:not-allowed}.opt-btn-icon{width:32px;height:32px;display:flex;align-items:center;justify-content:center;flex-shrink:0}.opt-btn-icon svg{width:100%;height:100%}.opt-btn-label{font-size:10px;margin-top:2px;color:var(--bim-btn-text-color)}.opt-btn:hover .opt-btn-label,.opt-btn.active .opt-btn-label{color:var(--bim-btn-text-active-color)}.opt-btn-arrow{font-size:8px;position:absolute;top:2px;right:2px;opacity:.6;transition:transform .2s ease}.opt-btn-arrow.rotated{transform:rotate(180deg)}.opt-btn.no-label .opt-btn-arrow{top:2px;right:2px}.opt-btn-dropdown{position:fixed;transform:translate(-50%,-100%);background-color:var(--bim-toolbar-bg);border-radius:4px;overflow:hidden;box-shadow:0 4px 12px #0000004d;min-width:50px;z-index:9999;display:flex;flex-direction:column}.opt-btn-dropdown-item{display:flex;flex-direction:column;align-items:center;justify-content:center;color:var(--bim-icon-color);cursor:pointer;transition:background .2s;white-space:nowrap;min-width:50px;min-height:50px;padding:4px;background-color:var(--bim-btn-bg)}.opt-btn-dropdown-item:hover{background-color:var(--bim-btn-hover-bg);color:var(--bim-icon-active-color)}.opt-btn-dropdown-item .opt-btn-icon.small{width:30px;height:30px;margin-right:0;margin-bottom:4px}.opt-btn-dropdown-item span{font-size:10px;color:var(--bim-btn-text-color)}.opt-btn-dropdown-item:hover span{color:var(--bim-btn-text-active-color)}.opt-btn.no-label .opt-btn-icon{width:32px;height:32px}: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
(function(d,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(d=typeof globalThis<"u"?globalThis:d||self,h(d.LyzBimEngineSDK={}))})(this,(function(d){"use strict";class h{container;options;groups=[];activeBtnIds=new Set;btnRefs=new Map;dropdownElement=null;hoverTimeout=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 o=typeof t.container=="string"?document.getElementById(t.container):t.container;if(!o)throw new Error("Container not found");this.container=o,this.options={showLabel:!0,visibility:{},...t},this.initContainer(),this.applyStyles()}initContainer(){this.container.innerHTML="",this.container.classList.add("toolbar-root")}applyStyles(){const t=this.container.style;this.options.backgroundColor&&t.setProperty("--bim-toolbar-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)}setColors(t){this.options={...this.options,...t},this.applyStyles()}addGroup(t,o){if(this.groups.some(i=>i.id===t)){console.warn("Group "+t+" already exists");return}const e={id:t,buttons:[]};if(o){const i=this.groups.findIndex(n=>n.id===o);i!==-1?this.groups.splice(i,0,e):(console.warn(`Target group ${o} not found, appending ${t} to end.`),this.groups.push(e))}else this.groups.push(e)}addButton(t){const{groupId:o,parentId:e}=t;if(!o)throw new Error(`Button ${t.id} config must contain 'groupId'`);const i=this.groups.find(s=>s.id===o);if(!i)throw new Error(`Group ${o} not found. Please call addGroup first.`);const n={...t,children:t.children||[]};if(e){const s=this.findButton(i.buttons,e);if(!s)throw new Error(`Parent button ${e} not found in group ${o}`);s.children||(s.children=[]),s.children.push(n)}else i.buttons.push(n)}findButton(t,o){for(const e of t){if(e.id===o)return e;if(e.children){const i=this.findButton(e.children,o);if(i)return i}}}async init(){const{homeButton:t}=await Promise.resolve().then(()=>y),{locationButton:o}=await Promise.resolve().then(()=>B),{walkMenuButton:e}=await Promise.resolve().then(()=>T),{walkPersonButton:i}=await Promise.resolve().then(()=>E),{walkBirdButton:n}=await Promise.resolve().then(()=>x),{settingButton:s}=await Promise.resolve().then(()=>L),{infoButton:r}=await Promise.resolve().then(()=>k);this.addGroup("group-1"),this.addButton(t),this.addButton(e),this.addButton(i),this.addButton(n),this.addButton(o),this.addGroup("group-2"),this.addButton(s),this.addButton(r),this.render()}render(){this.container.innerHTML="",this.btnRefs.clear();const t=document.createElement("div");t.className="toolbar-container",this.groups.forEach((o,e)=>{const i=this.renderGroup(o,e,this.groups.length);t.appendChild(i)}),this.container.appendChild(t)}renderGroup(t,o,e){const i=document.createElement("div");return i.className="opt-btn-group",o<e-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 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),t
<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!")},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:'<div style="padding: 10px;">这是一个 <b>可拖拽</b> 且 <b>可缩放</b> 的弹窗。<br><br>你可以尝试拖动标题栏,或者拖动右下角改变大小。</div>',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:'<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"})),B=Object.freeze(Object.defineProperty({__proto__:null,locationButton:{id:"location",groupId:"group-1",type:"button",label:"定位",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"})),T=Object.freeze(Object.defineProperty({__proto__:null,walkMenuButton:{id:"walk",groupId:"group-1",type:"menu",label:"漫游",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"})),E=Object.freeze(Object.defineProperty({__proto__:null,walkPersonButton:{id:"walk-person",groupId:"group-1",parentId:"walk",type:"button",label:"人视漫游",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"})),x=Object.freeze(Object.defineProperty({__proto__:
2025-12-03 12:00:46 +08:00
//# sourceMappingURL=bim-engine-sdk.umd.js.map