"use strict";exports.__esModule=!0,exports.default=exports.EventType=void 0;var _extension=require("../../core/extension"),_tacosSdk=_interopRequireWildcard(require("@tslfe/tacos-sdk"));function _getRequireWildcardCache(a){if("function"!=typeof WeakMap)return null;var b=new WeakMap,c=new WeakMap;return(_getRequireWildcardCache=function(a){return a?c:b})(a)}function _interopRequireWildcard(b,c){if(!c&&b&&b.__esModule)return b;if(null===b||"object"!=typeof b&&"function"!=typeof b)return{default:b};var d=_getRequireWildcardCache(c);if(d&&d.has(b))return d.get(b);var e={__proto__:null},f=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in b)if("default"!=a&&{}.hasOwnProperty.call(b,a)){var g=f?Object.getOwnPropertyDescriptor(b,a):null;g&&(g.get||g.set)?Object.defineProperty(e,a,g):e[a]=b[a]}return e.default=b,d&&d.set(b,e),e}let EventType=exports.EventType=function(a){return a.device="device",a.space="space",a.spaceEvent="spaceEvent",a.scene="scene",a["*"]="*",a}({});var _default=exports.default=(0,_extension.definePlugin)("os-animation",{setup(a,b){let c,d=new _tacosSdk.EventEmitter;const e=async()=>{var a;let b=await(null===(a=c)||void 0===a?void 0:a.createInstance(_tacosSdk.Root));null===b||void 0===b?void 0:b.addListener("*",a=>{let{data:c=[],messageType:b}=a;c.forEach(a=>{let e;e=b===_tacosSdk.SocketResponseType.deviceProperty?EventType.device:b===_tacosSdk.SocketResponseType.spaceProperty?EventType.space:b===_tacosSdk.SocketResponseType.spaceEvent?EventType.spaceEvent:b,d.emit(e,c),d.emit("*",c)})})},f=async a=>{let b=await c.createInstance(_tacosSdk.Root);return b.search(a).then(b=>{const c=[];if(b.map(a=>{a.layouts.map(a=>{"glb"===a.data.type&&a.data.url&&c.push(a.data.url)})}),0===c.length)throw Error(`${a}路径不存在`);else if(1<c.length);let d=c[0];return d})},g=async(a,c)=>/^\//.test(a)?f(a).then(a=>("function"==typeof c&&(a=c(a)),b.render(a,!0))):("function"==typeof c&&(a=c(a)),b.render(a,!0));return{loadModelUrl:f,enter:(a,b)=>g(a,b),compile:(a,c)=>f(a).then(a=>("function"==typeof c&&(a=c(a)),b.compile(a))),event:d,connect:async a=>_tacosSdk.default.connect(a).then(async a=>(c=a,await e(),a)),dispose:()=>{c&&c.destroy(),d.removeAllListener()}}},destroyed(){this.dispose()}});