@interopio/browser
Version:
IOConnect Browser client application package
1 lines • 261 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).browser=e.browser||{},e.browser.min=t())}(this,(function(){"use strict";const e={logger:"info",gateway:{webPlatform:{}},libraries:[],exposeAPI:!0},t={awaitFactory:!0,timeout:5e3},n={name:"platformUnload"},i={name:"transportSwitchRequest"},s={name:"transportSwitchResponse"},r={name:"getCurrentTransport"},o={name:"getCurrentTransportResponse"},a={name:"checkPreferredLogic"},c={name:"checkPreferredConnection"},d={name:"checkPreferredLogicResponse"},l={name:"checkPreferredConnectionResponse"},h="web-platform",u="latest_fdc3_type",p=new MessageChannel,g=e=>"string"==typeof e?e:e?.message?"string"==typeof e.message?e.message:JSON.stringify(e.message):JSON.stringify(e),m=(e,t)=>{try{return e.runWithException(t)}catch(e){return f.raiseError(e,!0)}};const f=new class{raiseError(e,t){const n=g(e);if(p.port1.postMessage(n),t)throw e;throw new Error(n)}};var w=function(e){return{ok:!0,result:e}},b=function(e){return{ok:!1,error:e}},y=function(e,t,n){return!1===t.ok?t:!1===n.ok?n:w(e(t.result,n.result))},v=function(e,t){return!0===t.ok?t:b(e(t.error))},C=function(){return C=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var s in t=arguments[n])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e},C.apply(this,arguments)};function I(e,t){if(e===t)return!0;if(null===e&&null===t)return!0;if(typeof e!=typeof t)return!1;if("object"==typeof e){if(Array.isArray(e)){if(!Array.isArray(t))return!1;if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(!I(e[n],t[n]))return!1;return!0}var i=Object.keys(e);if(i.length!==Object.keys(t).length)return!1;for(n=0;n<i.length;n++){if(!t.hasOwnProperty(i[n]))return!1;if(!I(e[i[n]],t[i[n]]))return!1}return!0}}var S=function(e){return Array.isArray(e)},_=function(e){return"object"==typeof e&&null!==e&&!S(e)},x=function(e,t){return"expected "+e+", got "+function(e){switch(typeof e){case"string":return"a string";case"number":return"a number";case"boolean":return"a boolean";case"undefined":return"undefined";case"object":return e instanceof Array?"an array":null===e?"null":"an object";default:return JSON.stringify(e)}}(t)},k=function(e){return e.map((function(e){return"string"==typeof e?"."+e:"["+e+"]"})).join("")},T=function(e,t){var n=t.at,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(i=Object.getOwnPropertySymbols(e);s<i.length;s++)t.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(e,i[s])&&(n[i[s]]=e[i[s]])}return n}(t,["at"]);return C({at:e+(n||"")},i)},R=function(){function e(t){var n=this;this.decode=t,this.run=function(e){return v((function(t){return{kind:"DecoderError",input:e,at:"input"+(t.at||""),message:t.message||""}}),n.decode(e))},this.runPromise=function(e){return!0===(t=n.run(e)).ok?Promise.resolve(t.result):Promise.reject(t.error);var t},this.runWithException=function(e){return function(e){if(!0===e.ok)return e.result;throw e.error}(n.run(e))},this.map=function(t){return new e((function(e){return function(e,t){return!0===t.ok?w(e(t.result)):t}(t,n.decode(e))}))},this.andThen=function(t){return new e((function(e){return function(e,t){return!0===t.ok?e(t.result):t}((function(n){return t(n).decode(e)}),n.decode(e))}))},this.where=function(t,i){return n.andThen((function(n){return t(n)?e.succeed(n):e.fail(i)}))}}return e.string=function(){return new e((function(e){return"string"==typeof e?w(e):b({message:x("a string",e)})}))},e.number=function(){return new e((function(e){return"number"==typeof e?w(e):b({message:x("a number",e)})}))},e.boolean=function(){return new e((function(e){return"boolean"==typeof e?w(e):b({message:x("a boolean",e)})}))},e.constant=function(t){return new e((function(e){return I(e,t)?w(t):b({message:"expected "+JSON.stringify(t)+", got "+JSON.stringify(e)})}))},e.object=function(t){return new e((function(e){if(_(e)&&t){var n={};for(var i in t)if(t.hasOwnProperty(i)){var s=t[i].decode(e[i]);if(!0!==s.ok)return void 0===e[i]?b({message:"the key '"+i+"' is required but was not present"}):b(T("."+i,s.error));void 0!==s.result&&(n[i]=s.result)}return w(n)}return _(e)?w(e):b({message:x("an object",e)})}))},e.array=function(t){return new e((function(e){if(S(e)&&t){return e.reduce((function(e,n,i){return y((function(e,t){return e.concat([t])}),e,function(e,n){return v((function(e){return T("["+n+"]",e)}),t.decode(e))}(n,i))}),w([]))}return S(e)?w(e):b({message:x("an array",e)})}))},e.tuple=function(t){return new e((function(e){if(S(e)){if(e.length!==t.length)return b({message:"expected a tuple of length "+t.length+", got one of length "+e.length});for(var n=[],i=0;i<t.length;i++){var s=t[i].decode(e[i]);if(!s.ok)return b(T("["+i+"]",s.error));n[i]=s.result}return w(n)}return b({message:x("a tuple of length "+t.length,e)})}))},e.union=function(t,n){for(var i=[],s=2;s<arguments.length;s++)i[s-2]=arguments[s];return e.oneOf.apply(e,[t,n].concat(i))},e.intersection=function(t,n){for(var i=[],s=2;s<arguments.length;s++)i[s-2]=arguments[s];return new e((function(e){return[t,n].concat(i).reduce((function(t,n){return y(Object.assign,t,n.decode(e))}),w({}))}))},e.anyJson=function(){return new e((function(e){return w(e)}))},e.unknownJson=function(){return new e((function(e){return w(e)}))},e.dict=function(t){return new e((function(e){if(_(e)){var n={};for(var i in e)if(e.hasOwnProperty(i)){var s=t.decode(e[i]);if(!0!==s.ok)return b(T("."+i,s.error));n[i]=s.result}return w(n)}return b({message:x("an object",e)})}))},e.optional=function(t){return new e((function(e){return null==e?w(void 0):t.decode(e)}))},e.oneOf=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return new e((function(e){for(var n=[],i=0;i<t.length;i++){var s=t[i].decode(e);if(!0===s.ok)return s;n[i]=s.error}var r=n.map((function(e){return"at error"+(e.at||"")+": "+e.message})).join('", "');return b({message:'expected a value matching one of the decoders, got the errors ["'+r+'"]'})}))},e.withDefault=function(t,n){return new e((function(e){return w(function(e,t){return!0===t.ok?t.result:e}(t,n.decode(e)))}))},e.valueAt=function(t,n){return new e((function(e){for(var i=e,s=0;s<t.length;s++){if(void 0===i)return b({at:k(t.slice(0,s+1)),message:"path does not exist"});if("string"==typeof t[s]&&!_(i))return b({at:k(t.slice(0,s+1)),message:x("an object",i)});if("number"==typeof t[s]&&!S(i))return b({at:k(t.slice(0,s+1)),message:x("an array",i)});i=i[t[s]]}return v((function(e){return void 0===i?{at:k(t),message:"path does not exist"}:T(k(t),e)}),n.decode(i))}))},e.succeed=function(t){return new e((function(e){return w(t)}))},e.fail=function(t){return new e((function(e){return b({message:t})}))},e.lazy=function(t){return new e((function(e){return t().decode(e)}))},e}(),A=R.string,P=R.number,M=R.boolean,O=R.anyJson;R.unknownJson;var E=R.constant,D=R.object,j=R.array;R.tuple,R.dict;var N=R.optional,$=R.oneOf;R.union,R.intersection,R.withDefault,R.valueAt,R.succeed,R.fail;var F=R.lazy;const W=["name","title","version","customProperties","icon","caption","type"],L=["appId","name","type","details","version","title","tooltip","lang","description","categories","icons","screenshots","contactEmail","moreInfo","publisher","customConfig","hostManifests","interop","localizedVersions"];var q=function(e){return{ok:!0,result:e}},G=function(e){return{ok:!1,error:e}},B=function(e,t,n){return!1===t.ok?t:!1===n.ok?n:q(e(t.result,n.result))},U=function(e,t){return!0===t.ok?t:G(e(t.error))},H=function(){return H=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var s in t=arguments[n])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e},H.apply(this,arguments)};function J(e,t){if(e===t)return!0;if(null===e&&null===t)return!0;if(typeof e!=typeof t)return!1;if("object"==typeof e){if(Array.isArray(e)){if(!Array.isArray(t))return!1;if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(!J(e[n],t[n]))return!1;return!0}var i=Object.keys(e);if(i.length!==Object.keys(t).length)return!1;for(n=0;n<i.length;n++){if(!t.hasOwnProperty(i[n]))return!1;if(!J(e[i[n]],t[i[n]]))return!1}return!0}}var K=function(e){return Array.isArray(e)},z=function(e){return"object"==typeof e&&null!==e&&!K(e)},V=function(e,t){return"expected "+e+", got "+function(e){switch(typeof e){case"string":return"a string";case"number":return"a number";case"boolean":return"a boolean";case"undefined":return"undefined";case"object":return e instanceof Array?"an array":null===e?"null":"an object";default:return JSON.stringify(e)}}(t)},Q=function(e){return e.map((function(e){return"string"==typeof e?"."+e:"["+e+"]"})).join("")},X=function(e,t){var n=t.at,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(i=Object.getOwnPropertySymbols(e);s<i.length;s++)t.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(e,i[s])&&(n[i[s]]=e[i[s]])}return n}(t,["at"]);return H({at:e+(n||"")},i)},Y=function(){function e(t){var n=this;this.decode=t,this.run=function(e){return U((function(t){return{kind:"DecoderError",input:e,at:"input"+(t.at||""),message:t.message||""}}),n.decode(e))},this.runPromise=function(e){return!0===(t=n.run(e)).ok?Promise.resolve(t.result):Promise.reject(t.error);var t},this.runWithException=function(e){return function(e){if(!0===e.ok)return e.result;throw e.error}(n.run(e))},this.map=function(t){return new e((function(e){return function(e,t){return!0===t.ok?q(e(t.result)):t}(t,n.decode(e))}))},this.andThen=function(t){return new e((function(e){return function(e,t){return!0===t.ok?e(t.result):t}((function(n){return t(n).decode(e)}),n.decode(e))}))},this.where=function(t,i){return n.andThen((function(n){return t(n)?e.succeed(n):e.fail(i)}))}}return e.string=function(){return new e((function(e){return"string"==typeof e?q(e):G({message:V("a string",e)})}))},e.number=function(){return new e((function(e){return"number"==typeof e?q(e):G({message:V("a number",e)})}))},e.boolean=function(){return new e((function(e){return"boolean"==typeof e?q(e):G({message:V("a boolean",e)})}))},e.constant=function(t){return new e((function(e){return J(e,t)?q(t):G({message:"expected "+JSON.stringify(t)+", got "+JSON.stringify(e)})}))},e.object=function(t){return new e((function(e){if(z(e)&&t){var n={};for(var i in t)if(t.hasOwnProperty(i)){var s=t[i].decode(e[i]);if(!0!==s.ok)return void 0===e[i]?G({message:"the key '"+i+"' is required but was not present"}):G(X("."+i,s.error));void 0!==s.result&&(n[i]=s.result)}return q(n)}return z(e)?q(e):G({message:V("an object",e)})}))},e.array=function(t){return new e((function(e){if(K(e)&&t){return e.reduce((function(e,n,i){return B((function(e,t){return e.concat([t])}),e,function(e,n){return U((function(e){return X("["+n+"]",e)}),t.decode(e))}(n,i))}),q([]))}return K(e)?q(e):G({message:V("an array",e)})}))},e.tuple=function(t){return new e((function(e){if(K(e)){if(e.length!==t.length)return G({message:"expected a tuple of length "+t.length+", got one of length "+e.length});for(var n=[],i=0;i<t.length;i++){var s=t[i].decode(e[i]);if(!s.ok)return G(X("["+i+"]",s.error));n[i]=s.result}return q(n)}return G({message:V("a tuple of length "+t.length,e)})}))},e.union=function(t,n){for(var i=[],s=2;s<arguments.length;s++)i[s-2]=arguments[s];return e.oneOf.apply(e,[t,n].concat(i))},e.intersection=function(t,n){for(var i=[],s=2;s<arguments.length;s++)i[s-2]=arguments[s];return new e((function(e){return[t,n].concat(i).reduce((function(t,n){return B(Object.assign,t,n.decode(e))}),q({}))}))},e.anyJson=function(){return new e((function(e){return q(e)}))},e.unknownJson=function(){return new e((function(e){return q(e)}))},e.dict=function(t){return new e((function(e){if(z(e)){var n={};for(var i in e)if(e.hasOwnProperty(i)){var s=t.decode(e[i]);if(!0!==s.ok)return G(X("."+i,s.error));n[i]=s.result}return q(n)}return G({message:V("an object",e)})}))},e.optional=function(t){return new e((function(e){return null==e?q(void 0):t.decode(e)}))},e.oneOf=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return new e((function(e){for(var n=[],i=0;i<t.length;i++){var s=t[i].decode(e);if(!0===s.ok)return s;n[i]=s.error}var r=n.map((function(e){return"at error"+(e.at||"")+": "+e.message})).join('", "');return G({message:'expected a value matching one of the decoders, got the errors ["'+r+'"]'})}))},e.withDefault=function(t,n){return new e((function(e){return q(function(e,t){return!0===t.ok?t.result:e}(t,n.decode(e)))}))},e.valueAt=function(t,n){return new e((function(e){for(var i=e,s=0;s<t.length;s++){if(void 0===i)return G({at:Q(t.slice(0,s+1)),message:"path does not exist"});if("string"==typeof t[s]&&!z(i))return G({at:Q(t.slice(0,s+1)),message:V("an object",i)});if("number"==typeof t[s]&&!K(i))return G({at:Q(t.slice(0,s+1)),message:V("an array",i)});i=i[t[s]]}return U((function(e){return void 0===i?{at:Q(t),message:"path does not exist"}:X(Q(t),e)}),n.decode(i))}))},e.succeed=function(t){return new e((function(e){return q(t)}))},e.fail=function(t){return new e((function(e){return G({message:t})}))},e.lazy=function(t){return new e((function(e){return t().decode(e)}))},e}(),Z=Y.string,ee=Y.number,te=Y.boolean,ne=Y.anyJson;Y.unknownJson;var ie=Y.constant,se=Y.object,re=Y.array;Y.tuple;var oe=Y.dict,ae=Y.optional,ce=Y.oneOf;Y.union,Y.intersection,Y.withDefault,Y.valueAt,Y.succeed,Y.fail,Y.lazy;const de=Z().where((e=>e.length>0),"Expected a non-empty string"),le=ee().where((e=>e>=0),"Expected a non-negative number"),he=se({name:de,displayName:ae(Z()),contexts:ae(re(Z())),customConfig:ae(se())}),ue=ce(ie("web"),ie("native"),ie("citrix"),ie("onlineNative"),ie("other")),pe=se({url:de}),ge=se({src:de,size:ae(de),type:ae(de)}),me=se({src:de,size:ae(de),type:ae(de),label:ae(de)}),fe=se({contexts:re(de),displayName:ae(de),resultType:ae(de),customConfig:ae(ne())}),we=se({listensFor:ae(oe(fe)),raises:ae(oe(re(de)))}),be=se({broadcasts:ae(re(de)),listensFor:ae(re(de))}),ye=se({name:de,description:ae(de),broadcasts:ae(re(de)),listensFor:ae(re(de))}),ve=se({intents:ae(we),userChannels:ae(be),appChannels:ae(re(ye))}),Ce=se({url:ae(de),top:ae(ee()),left:ae(ee()),width:ae(le),height:ae(le)}),Ie=se({name:ae(de),type:ae(de.where((e=>"window"===e),"Expected a value of window")),title:ae(de),version:ae(de),customProperties:ae(ne()),icon:ae(Z()),caption:ae(Z()),details:ae(Ce),intents:ae(re(he)),hidden:ae(te())}),Se=se({name:de,appId:de,title:ae(de),version:ae(de),manifest:de,manifestType:de,tooltip:ae(de),description:ae(de),contactEmail:ae(de),supportEmail:ae(de),publisher:ae(de),images:ae(re(se({url:ae(de)}))),icons:ae(re(se({icon:ae(de)}))),customConfig:ne(),intents:ae(re(he))}),_e=se({appId:ae(de),name:ae(de),details:ae(pe),version:ae(de),title:ae(de),tooltip:ae(de),lang:ae(de),description:ae(de),categories:ae(re(de)),icons:ae(re(ge)),screenshots:ae(re(me)),contactEmail:ae(de),supportEmail:ae(de),moreInfo:ae(de),publisher:ae(de),customConfig:ae(re(ne())),hostManifests:ae(ne()),interop:ae(ve)}),xe=se({appId:de,name:de,type:ue,details:pe,version:ae(de),title:ae(de),tooltip:ae(de),lang:ae(de),description:ae(de),categories:ae(re(de)),icons:ae(re(ge)),screenshots:ae(re(me)),contactEmail:ae(de),supportEmail:ae(de),moreInfo:ae(de),publisher:ae(de),customConfig:ae(re(ne())),hostManifests:ae(ne()),interop:ae(ve),localizedVersions:ae(oe(_e))}),ke=ce(Se,xe),Te=e=>`${e.kind} at ${e.at}: ${JSON.stringify(e.input)}. Reason - ${e.message}`;class Re{fdc3ToDesktopDefinitionType={web:"window",native:"exe",citrix:"citrix",onlineNative:"clickonce",other:"window"};toApi(){return{isFdc3Definition:this.isFdc3Definition.bind(this),parseToBrowserBaseAppData:this.parseToBrowserBaseAppData.bind(this),parseToDesktopAppConfig:this.parseToDesktopAppConfig.bind(this)}}isFdc3Definition(e){const t=ke.run(e);return t.ok?e.appId&&e.details?{isFdc3:!0,version:"2.0"}:e.manifest?{isFdc3:!0,version:"1.2"}:{isFdc3:!1,reason:"The passed definition is not FDC3"}:{isFdc3:!1,reason:Te(t.error)}}parseToBrowserBaseAppData(e){const{isFdc3:t,version:n}=this.isFdc3Definition(e);if(!t)throw new Error("The passed definition is not FDC3");const i=ke.run(e);if(!i.ok)throw new Error(`Invalid FDC3 ${n} definition. Error: ${Te(i.error)}`);const s=this.getUserPropertiesFromDefinition(e,n),r={url:this.getUrl(e,n)},o={name:e.appId,type:"window",createOptions:r,userProperties:{...s,intents:"1.2"===n?s.intents:this.getIntentsFromV2AppDefinition(e),details:r},title:e.title,version:e.version,icon:this.getIconFromDefinition(e,n),caption:e.description,fdc3:"2.0"===n?{...e,definitionVersion:"2.0"}:void 0},a=e.hostManifests?.ioConnect||e.hostManifests?.Glue42;if(!a)return o;const c=Ie.run(a);if(!c.ok)throw new Error(`Invalid FDC3 ${n} definition. Error: ${Te(c.error)}`);return Object.keys(c.result).length?this.mergeBaseAppDataWithGlueManifest(o,c.result):o}parseToDesktopAppConfig(e){const{isFdc3:t,version:n}=this.isFdc3Definition(e);if(!t)throw new Error("The passed definition is not FDC3");const i=ke.run(e);if(!i.ok)throw new Error(`Invalid FDC3 ${n} definition. Error: ${Te(i.error)}`);if("1.2"===n){const t=e;return{name:t.appId,type:"window",details:{url:this.getUrl(e,n)},version:t.version,title:t.title,tooltip:t.tooltip,caption:t.description,icon:t.icons?.[0].icon,intents:t.intents,customProperties:{manifestType:t.manifestType,images:t.images,contactEmail:t.contactEmail,supportEmail:t.supportEmail,publisher:t.publisher,icons:t.icons,customConfig:t.customConfig}}}const s=e,r={name:s.appId,type:this.fdc3ToDesktopDefinitionType[s.type],details:s.details,version:s.version,title:s.title,tooltip:s.tooltip,caption:s.description,icon:this.getIconFromDefinition(s,"2.0"),intents:this.getIntentsFromV2AppDefinition(s),fdc3:{...s,definitionVersion:"2.0"}},o=e.hostManifests?.ioConnect||e.hostManifests?.Glue42;if(!o)return r;if("object"!=typeof o||Array.isArray(o))throw new Error(`Invalid '${e.hostManifests.ioConnect?"hostManifests.ioConnect":"hostManifests['Glue42']"}' key`);return this.mergeDesktopConfigWithGlueManifest(r,o)}getUserPropertiesFromDefinition(e,t){return"1.2"===t?Object.fromEntries(Object.entries(e).filter((([e])=>!W.includes(e)))):Object.fromEntries(Object.entries(e).filter((([e])=>!W.includes(e)&&!L.includes(e))))}getUrl(e,t){let n;if("1.2"===t){const t=JSON.parse(e.manifest);n=t.details?.url||t.url}else n=e.details?.url;if(!n||"string"!=typeof n)throw new Error(`Invalid FDC3 ${t} definition. Provide valid 'url' under '${"1.2"===t?"manifest":"details"}' key`);return n}getIntentsFromV2AppDefinition(e){const t=e.interop?.intents?.listensFor;if(!t)return;return Object.entries(t).map((e=>{const[t,n]=e;return{name:t,...n}}))}getIconFromDefinition(e,t){return"1.2"===t?e.icons?.find((e=>e.icon))?.icon||void 0:e.icons?.find((e=>e.src))?.src||void 0}mergeBaseAppDataWithGlueManifest(e,t){let n=e;if(t.details){const i={...e.createOptions,...t.details};n.createOptions=i,n.userProperties.details=i}return Array.isArray(t.intents)&&(n.userProperties.intents=(n.userProperties.intents||[]).concat(t.intents)),n={...n,...t},delete n.details,delete n.intents,n}mergeDesktopConfigWithGlueManifest(e,t){const n=Object.assign({},e,t,{details:{...e.details,...t.details}});return Array.isArray(t.intents)&&(n.intents=(e.intents||[]).concat(t.intents)),n}}const Ae={common:{nonEmptyStringDecoder:de,nonNegativeNumberDecoder:le},fdc3:{allDefinitionsDecoder:ke,v1DefinitionDecoder:Se,v2DefinitionDecoder:xe}};var Pe;!function(e){e.USER_CANCELLED="User Closed Intents Resolver UI without choosing a handler",e.CALLER_NOT_DEFINED="Caller Id is not defined",e.TIMEOUT_HIT="Timeout hit",e.INTENT_NOT_FOUND="Cannot find Intent",e.HANDLER_NOT_FOUND="Cannot find Intent Handler",e.TARGET_INSTANCE_UNAVAILABLE="Cannot start Target Instance",e.INTENT_DELIVERY_FAILED="Target Instance did not add a listener",e.RESOLVER_UNAVAILABLE="Intents Resolver UI unavailable",e.RESOLVER_TIMEOUT="User did not choose a handler",e.INVALID_RESOLVER_RESPONSE="Intents Resolver UI returned invalid response",e.INTENT_HANDLER_REJECTION="Intent Handler function processing the raised intent threw an error or rejected the promise it returned"}(Pe||(Pe={}));const Me=new class{_fdc3;_decoders=Ae;_errors={intents:Pe};get fdc3(){return this._fdc3||(this._fdc3=(new Re).toApi()),this._fdc3}get decoders(){return this._decoders}get errors(){return this._errors}};Me.fdc3;const Oe=Me.decoders;Me.errors;const Ee=A().where((e=>e.length>0),"Expected a non-empty string"),De=P().where((e=>e>=0),"Expected a non-negative number"),je=N(Ee),Ne=$(E("system"),E("windows"),E("appManager"),E("layouts"),E("intents"),E("notifications"),E("channels"),E("extension"),E("themes"),E("prefs"),E("ui")),$e=$(E("openWindow"),E("windowHello"),E("windowAdded"),E("windowRemoved"),E("getBounds"),E("getFrameBounds"),E("getUrl"),E("moveResize"),E("focus"),E("close"),E("getTitle"),E("setTitle"),E("focusChange"),E("getChannel"),E("notifyChannelsChanged")),Fe=$(E("appHello"),E("appDirectoryStateChange"),E("instanceStarted"),E("instanceStopped"),E("applicationStart"),E("instanceStop"),E("clear")),We=$(E("layoutAdded"),E("layoutChanged"),E("layoutRemoved"),E("layoutRenamed"),E("get"),E("getAll"),E("export"),E("import"),E("remove"),E("rename"),E("clientSaveRequest"),E("getGlobalPermissionState"),E("checkGlobalActivated"),E("requestGlobalPermission"),E("getDefaultGlobal"),E("setDefaultGlobal"),E("clearDefaultGlobal"),E("updateMetadata")),Le=$(E("raiseNotification"),E("requestPermission"),E("notificationShow"),E("notificationClick"),E("getPermission"),E("list"),E("notificationRaised"),E("notificationClosed"),E("click"),E("clear"),E("clearAll"),E("configure"),E("getConfiguration"),E("configurationChanged"),E("setState"),E("clearOld"),E("activeCountChange"),E("stateChange")),qe=$(E("getEnvironment"),E("getBase"),E("platformShutdown"),E("isFdc3DataWrappingSupported"),E("clientError"),E("systemHello")),Ge=$(E("top"),E("left"),E("right"),E("bottom")),Be=D({top:P(),left:P(),width:De,height:De}),Ue=N(D({top:N(P()),left:N(P()),width:N(De),height:N(De),context:N(O()),relativeTo:N(Ee),relativeDirection:N(Ge),windowId:N(Ee),layoutComponentId:N(Ee)})),He=D({name:Ee,url:Ee,options:Ue}),Je=D({windowId:N(Ee)}),Ke=D({windowId:Ee,name:Ee}),ze=D({windowId:Ee}),Ve=D({windows:j(Ke),isWorkspaceFrame:M()}),Qe=D({windowId:Ee,title:A()}),Xe=D({windowId:Ee,hasFocus:M()}),Ye=D({windowId:Ee,top:N(P()),left:N(P()),width:N(De),height:N(De),relative:N(M())}),Ze=D({windowId:Ee,bounds:D({top:P(),left:P(),width:De,height:De})}),et=D({bounds:D({top:P(),left:P(),width:De,height:De})}),tt=D({windowId:Ee,url:Ee}),nt=O(),it=D({top:N(P()),left:N(P()),width:N(De),height:N(De)}),st=D({id:Ee,applicationName:Ee}),rt=D({flags:A()}),ot=D({flags:A()}),at=D({windowId:Ee,channelsNames:j(Ee)}),ct=D({enabled:M()}),dt=D({url:Ee,top:N(P()),left:N(P()),width:N(De),height:N(De),workspacesSandbox:N(ot),channelSelector:N(ct),iframePermissionsPolicy:N(rt)}),lt=D({name:Ee,displayName:N(A()),contexts:N(j(A())),customConfig:N(D())});D({name:Ee,title:N(Ee),version:N(Ee),appId:N(Ee),manifest:Ee,manifestType:Ee,tooltip:N(Ee),description:N(Ee),contactEmail:N(Ee),supportEmail:N(Ee),publisher:N(Ee),images:N(j(D({url:N(Ee)}))),icons:N(j(D({icon:N(Ee)}))),customConfig:O(),intents:N(j(lt))});const ht=D({name:Ee,type:Ee.where((e=>"window"===e),"Expected a value of window"),title:N(Ee),version:N(Ee),customProperties:N(O()),icon:N(A()),caption:N(A()),details:dt,intents:N(j(lt)),hidden:N(M()),fdc3:N(Oe.fdc3.v2DefinitionDecoder)}),ut=$(ht,Oe.fdc3.v2DefinitionDecoder,Oe.fdc3.v1DefinitionDecoder);D({definitions:j(ut),mode:$(E("replace"),E("merge"))});const pt=D({name:Ee}),gt=D({definitions:j(ht)}),mt=D({name:Ee,type:Ee.where((e=>"window"===e),"Expected a value of window"),instances:j(st),userProperties:N(O()),title:N(Ee),version:N(Ee),icon:N(Ee),caption:N(Ee)}),ft=D({name:Ee,type:Ee.where((e=>"window"===e),"Expected a value of window"),userProperties:O(),title:N(Ee),version:N(Ee),icon:N(Ee),caption:N(Ee)}),wt=D({appsAdded:j(ft),appsChanged:j(ft),appsRemoved:j(ft)}),bt=D({apps:j(mt),initialChannelId:N(Ee)}),yt=D({id:Ee}),vt=$(E("Global"),E("Activity"),E("ApplicationDefault"),E("Swimlane"),E("Workspace")),Ct=$(E("application"),E("activity")),It=D({context:N(O()),bounds:Be,createArgs:D({name:N(Ee),url:N(Ee),context:N(O())}),windowState:N(Ee),restoreState:N(Ee),instanceId:Ee,isCollapsed:N(M()),isSticky:N(M()),restoreSettings:D({groupId:N(Ee),groupZOrder:N(P())})}),St=D({type:E("window"),componentType:N(Ct),application:Ee,state:It}),_t=D({type:E("window"),config:D({appName:Ee,url:N(Ee),title:N(A()),allowExtract:N(M()),allowReorder:N(M()),showCloseButton:N(M()),isMaximized:N(M())})}),xt=D({type:E("group"),config:O(),children:j($(_t))}),kt=D({type:E("column"),config:O(),children:j($(xt,_t,F((()=>kt)),F((()=>Tt))))}),Tt=D({type:E("row"),config:O(),children:j($(kt,xt,_t,F((()=>Tt))))}),Rt=D({config:O(),context:O(),children:j($(Tt,kt,xt,_t))}),At=D({type:E("Workspace"),application:N(Ee),state:Rt}),Pt=D({bounds:Be,instanceId:Ee,selectedWorkspace:De,workspaces:j(Rt),windowState:N(Ee),restoreState:N(Ee),context:N(O())}),Mt=D({type:E("workspaceFrame"),application:Ee,componentType:N(Ct),state:Pt}),Ot=D({name:Ee,type:vt,token:N(Ee),components:j($(St,At,Mt)),context:N(O()),metadata:N(O()),version:N(P())}),Et=D({name:Ee,context:N(O()),metadata:N(O()),instances:N(j(Ee)),ignoreInstances:N(j(Ee))}),Dt=D({name:Ee,context:N(O()),closeRunningInstance:N(M()),closeMe:N(M()),timeout:N(De)}),jt=D({name:Ee,type:vt,context:N(O()),metadata:N(O())}),Nt=D({name:Ee,type:vt}),$t=D({layout:Et}),Ft=D({layout:Ot,newName:Ee}),Wt=D({status:Ee}),Lt=D({layout:Ot}),qt=D({layout:Dt}),Gt=D({type:vt}),Bt=D({layouts:j(Ot)}),Ut=$(E("replace"),E("merge")),Ht=D({layouts:j(Ot),mode:Ut,skipManagerRequest:N(M())}),Jt=D({summaries:j(jt)}),Kt=D({layout:Ot}),zt=D({layout:N(Ot)}),Vt=D({name:Ee}),Qt=$(E("findIntent"),E("getIntents"),E("raiseIntent"),E("raise"),E("filterHandlers")),Xt=D({applicationName:Ee,applicationTitle:N(A()),applicationDescription:N(A()),applicationIcon:N(A()),type:$(E("app"),E("instance")),displayName:N(A()),contextTypes:N(j(Ee)),instanceId:N(A()),instanceTitle:N(A()),resultType:N(A())});D({applicationName:A(),applicationIcon:N(A()),instanceId:N(A())});const Yt=D({intent:Ee,handler:Xt}),Zt=D({name:Ee,handlers:j(Xt)}),en=$(E("startNew"),E("reuse"),D({app:N(Ee),instance:N(Ee)})),tn=D({type:N(Ee),data:N(O())}),nn=j(Zt),sn=D({intents:nn}),rn=D({name:N(Ee),contextType:N(Ee),resultType:N(Ee)}),on=$(Ee,rn),an=D({filter:N(rn)}),cn=D({intent:Ee,target:N(en),context:N(tn),options:N(Ue),handlers:N(j(Xt)),timeout:N(De),waitUserResponseIndefinitely:N(M()),clearSavedHandler:N(M())}),dn=D({interopInstance:Ee,name:N(Ee)}),ln=D({originApp:dn,intentRequest:N(cn)}),hn=D({name:Ee,waitForAGMReady:M(),id:N(Ee),context:N(O()),top:N(P()),left:N(P()),width:N(De),height:N(De),relativeTo:N(Ee),relativeDirection:N(Ge),forceChromeTab:N(M()),layoutComponentId:N(Ee),channelId:N(Ee),startReason:ln}),un=$(Ee,cn),pn=D({enabled:M(),appName:Ee,waitResponseTimeout:P()}),gn=D({intentRequest:cn,resolverConfig:pn}),mn=D({request:cn,handler:Xt,result:O()}),fn=D({title:N(Ee),openResolver:N(M()),timeout:N(De),intent:N(Ee),contextTypes:N(j(Ee)),resultType:N(Ee),applicationNames:N(j(Ee))}),wn=D({handlers:j(Xt)}),bn=D({filterHandlersRequest:fn,resolverConfig:pn}),yn=D({intent:Ee,contextTypes:N(j(Ee)),displayName:N(A()),icon:N(A()),description:N(A()),resultType:N(A())}),vn=$(Ee,yn),Cn=D({intent:Ee,contextTypes:N(j(Ee)),description:N(Ee),displayName:N(Ee),icon:N(Ee),resultType:N(Ee)}),In=D({intents:j(Cn)}),Sn=e=>Ee.where((t=>e.includes(t)),"Expected a valid channel name"),_n=D({contextType:N(Ee)}),xn=N($(Ee,D({name:N(Ee),fdc3:N(M())}))),kn=D({windowId:je,channel:je}),Tn=O().where((e=>"string"==typeof e.type),"Expected a valid FDC3 Context with compulsory 'type' field"),Rn=D({method:Ee,arguments:N(O()),target:N($(E("all"),E("best")))}),An=D({action:A(),title:Ee,icon:N(A()),interop:N(Rn)}),Pn=$(E("Active"),E("Acknowledged"),E("Seen"),E("Closed"),E("Stale"),E("Snoozed"),E("Processing")),Mn=D({count:P()}),On=D({badge:N(A()),body:N(A()),data:N(O()),dir:N($(E("auto"),E("ltr"),E("rtl"))),icon:N(A()),image:N(A()),lang:N(A()),renotify:N(M()),requireInteraction:N(M()),silent:N(M()),tag:N(A()),timestamp:N(De),vibrate:N(j(P()))}),En=D({title:Ee,clickInterop:N(Rn),actions:N(j(An)),focusPlatformOnDefaultClick:N(M()),badge:N(A()),body:N(A()),data:N(O()),dir:N($(E("auto"),E("ltr"),E("rtl"))),icon:N(A()),image:N(A()),lang:N(A()),renotify:N(M()),requireInteraction:N(M()),silent:N(M()),tag:N(A()),timestamp:N(De),vibrate:N(j(P())),severity:N($(E("Low"),E("None"),E("Medium"),E("High"),E("Critical"))),showToast:N(M()),showInPanel:N(M()),state:N(Pn)}),Dn=D({id:Ee,state:Pn});D().where((e=>!e.fdc3||"string"==typeof e.fdc3.type),"Expected a valid FDC3 Context with compulsory 'type' field");const jn=D({color:N(Ee),icon:N(Ee),name:N(Ee),glyph:N(Ee)}),Nn=D({id:Ee,displayMetadata:N(jn)}),$n=D({color:Ee,fdc3:N(Nn)}),Fn=D({name:Ee,meta:$n,data:N(D())}),Wn=D({name:Ee}),Ln=D({name:Ee,read:M(),write:M(),windowId:N(Ee)}),qn=D({name:Ee,read:M(),write:M(),windowId:Ee}),Gn=D({config:qn}),Bn=D({channels:j(Ln)}),Un=D({windowId:Ee}),Hn=D({read:M(),write:M(),windowId:N(Ee)}),Jn=D({restrictions:Hn}),Kn=D({settings:En,id:Ee}),zn=D({settings:En}),Vn=D({permissionGranted:M()}),Qn=D({permission:$(E("default"),E("granted"),E("denied"))}),Xn=D({definition:On,action:N(A()),id:N(Ee)}),Yn=D({allowed:N(j(Ee)),blocked:N(j(Ee))}),Zn=D({enable:N(M()),enableToasts:N(M()),sourceFilter:N(Yn)}),ei=D({configuration:Zn}),ti=D({configuration:D({enable:M(),enableToasts:M(),sourceFilter:D({allowed:j(Ee),blocked:j(Ee)})})}),ni=D({layoutType:$(E("Global"),E("Workspace")),layoutName:Ee,context:N(O())}),ii=D({windowContext:N(O())}),si=D({state:$(E("prompt"),E("denied"),E("granted"))}),ri=D({isAvailable:M()}),oi=D({itemId:Ee}),ai=D({isSupported:M()}),ci=D({operation:Ee}),di=D({bounds:Be}),li=D({displayName:Ee,name:Ee}),hi=D({theme:li}),ui=D({themes:j(li)}),pi=D({name:Ee}),gi=D({id:Ee,title:Ee,clickInterop:N(Rn),actions:N(j(An)),focusPlatformOnDefaultClick:N(M()),badge:N(A()),body:N(A()),data:N(O()),dir:N($(E("auto"),E("ltr"),E("rtl"))),icon:N(A()),image:N(A()),lang:N(A()),renotify:N(M()),requireInteraction:N(M()),silent:N(M()),tag:N(A()),timestamp:N(De),vibrate:N(j(P())),severity:N($(E("Low"),E("None"),E("Medium"),E("High"),E("Critical"))),showToast:N(M()),showInPanel:N(M()),state:N(Pn)}),mi=D({notification:gi}),fi=D({notifications:j(gi)}),wi=D({id:Ee}),bi=D({channel:Ee}),yi=D({windowIds:j(Ee)}),vi=$(E("addChannel"),E("getMyChannel"),E("getWindowIdsOnChannel"),E("getWindowIdsWithChannels"),E("joinChannel"),E("restrict"),E("getRestrictions"),E("restrictAll"),E("notifyChannelsChanged"),E("leaveChannel"),E("getMode")),Ci=D({mode:$(E("single"),E("multi"))}),Ii=D({channel:N(Ee)}),Si=D({application:N(Ee),channels:N(j(Ee)),windowIds:N(j(Ee))}),_i=D({filter:N(Si)}),xi=D({windowIdsWithChannels:j(D({application:Ee,channel:N(Ee),windowId:Ee}))}),ki=N(O()),Ti=N(D({top:N(P()),left:N(P()),width:N(De),height:N(De),relativeTo:N(Ee),relativeDirection:N(Ge),waitForAGMReady:N(M()),channelId:N(Ee),reuseId:N(Ee),originIntentRequest:N(cn)})),Ri=D({channel:Ee,windowId:Ee}),Ai=D({windowId:Ee,channelName:N(Ee)}),Pi=D({windowId:Ee,channelNames:j(Ee)}),Mi=D({channel:N(Ee)}),Oi=$(E("clear"),E("clearAll"),E("get"),E("getAll"),E("set"),E("update"),E("prefsChanged"),E("prefsHello")),Ei=D({app:Ee,data:D(),lastUpdate:N(Ee)}),Di=D({app:Ee}),ji=D({prefs:Ei}),Ni=D({all:j(Ei)}),$i=D({interopId:Ee}),Fi=D({app:Ee,data:D()}),Wi=D({platform:D({app:Ee}),validNonExistentApps:N(j(Ee))}),Li=D({message:Ee}),qi=D({isClientErrorOperationSupported:M()}),Gi={openWindow:{name:"openWindow",dataDecoder:He,resultDecoder:Ke},windowHello:{name:"windowHello",dataDecoder:Je,resultDecoder:Ve},windowAdded:{name:"windowAdded",dataDecoder:Ke},windowRemoved:{name:"windowRemoved",dataDecoder:ze},getBounds:{name:"getBounds",dataDecoder:ze,resultDecoder:Ze},getFrameBounds:{name:"getFrameBounds",dataDecoder:ze,resultDecoder:et},getUrl:{name:"getUrl",dataDecoder:ze,resultDecoder:tt},moveResize:{name:"moveResize",dataDecoder:Ye},focus:{name:"focus",dataDecoder:ze},close:{name:"close",dataDecoder:ze},getTitle:{name:"getTitle",dataDecoder:ze,resultDecoder:Qe},setTitle:{name:"setTitle",dataDecoder:Qe},focusChange:{name:"focusChange",dataDecoder:Xe},getChannel:{name:"getChannel",dataDecoder:ze,resultDecoder:Mi},notifyChannelsChanged:{name:"notifyChannelsChanged",dataDecoder:Pi}};function Bi(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Ui(e){if(e&&e.errorHandling&&"function"!=typeof e.errorHandling&&"log"!==e.errorHandling&&"silent"!==e.errorHandling&&"throw"!==e.errorHandling)throw new Error('Invalid options passed to createRegistry. Prop errorHandling should be ["log" | "silent" | "throw" | (err) => void], but '+typeof e.errorHandling+" was passed");var t=e&&"function"==typeof e.errorHandling&&e.errorHandling,n={};function i(n,i){var s=n instanceof Error?n:new Error(n);if(t)t(s);else{var r='[ERROR] callback-registry: User callback for key "'+i+'" failed: '+s.stack;if(e)switch(e.errorHandling){case"log":return console.error(r);case"silent":return;case"throw":throw new Error(r)}console.error(r)}}return{add:function(e,t,s){var r=n[e];return r||(r=[],n[e]=r),r.push(t),s&&setTimeout((function(){s.forEach((function(s){var r;if(null===(r=n[e])||void 0===r?void 0:r.includes(t))try{Array.isArray(s)?t.apply(void 0,s):t.apply(void 0,[s])}catch(t){i(t,e)}}))}),0),function(){var i=n[e];i&&(0===(i=i.reduce((function(e,n,i){return n===t&&e.length===i||e.push(n),e}),[])).length?delete n[e]:n[e]=i)}},execute:function(e){for(var t=[],s=1;s<arguments.length;s++)t[s-1]=arguments[s];var r=n[e];if(!r||0===r.length)return[];var o=[];return r.forEach((function(n){try{var s=n.apply(void 0,t);o.push(s)}catch(t){o.push(void 0),i(t,e)}})),o},clear:function(){n={}},clearKey:function(e){n[e]&&delete n[e]}}}Ui.default=Ui;var Hi=Bi(Ui);class Ji{_id;_name;_bridge;registry=Hi();myCtxKey;ctxUnsubscribe;me;constructor(e,t,n){this._id=e,this._name=t,this._bridge=n,this.myCtxKey=`___window___${this.id}`}get id(){return this._id.slice()}get name(){return this._name.slice()}clean(){this.ctxUnsubscribe&&this.ctxUnsubscribe()}processSelfFocusEvent(e){this.me.isFocused=e,this.registry.execute("focus-change",this.me)}processChannelsChangedEvent(e){this.registry.execute("channels-changed",e)}async toApi(){return this.ctxUnsubscribe=await this._bridge.contextLib.subscribe(this.myCtxKey,(e=>this.registry.execute("context-updated",e))),this.me={id:this.id,name:this.name,isFocused:!1,getURL:this.getURL.bind(this),moveResize:this.moveResize.bind(this),resizeTo:this.resizeTo.bind(this),moveTo:this.moveTo.bind(this),focus:this.focus.bind(this),close:this.close.bind(this),getTitle:this.getTitle.bind(this),setTitle:this.setTitle.bind(this),getBounds:this.getBounds.bind(this),getContext:this.getContext.bind(this),updateContext:this.updateContext.bind(this),setContext:this.setContext.bind(this),onContextUpdated:this.onContextUpdated.bind(this),onFocusChanged:this.onFocusChanged.bind(this),getChannel:this.getChannel.bind(this),onChannelsChanged:this.onChannelsChanged.bind(this)},this.me}async getURL(){return(await this._bridge.send("windows",Gi.getUrl,{windowId:this.id})).url}onFocusChanged(e){return"function"!=typeof e?f.raiseError("Cannot subscribe to context changes, because the provided callback is not a function!"):this.registry.add("focus-change",e)}async moveResize(e){const t=m(it,e),n=Object.assign({},t,{windowId:this.id,relative:!1});return await this._bridge.send("windows",Gi.moveResize,n),this.me}async resizeTo(e,t){if(void 0===e&&void 0===t)return this.me;void 0!==e&&m(De,e),void 0!==t&&m(De,t);const n=Object.assign({},{width:e,height:t},{windowId:this.id,relative:!0});return await this._bridge.send("windows",Gi.moveResize,n),this.me}async moveTo(e,t){if(void 0===e&&void 0===t)return this.me;void 0!==e&&m(P(),e),void 0!==t&&m(P(),t);const n=Object.assign({},{top:e,left:t},{windowId:this.id,relative:!0});return await this._bridge.send("windows",Gi.moveResize,n),this.me}async focus(){return"Platform"===this.name?window.open(void 0,this.id):await this._bridge.send("windows",Gi.focus,{windowId:this.id}),this.me}async close(){return await this._bridge.send("windows",Gi.close,{windowId:this.id}),this.me}async getTitle(){return(await this._bridge.send("windows",Gi.getTitle,{windowId:this.id})).title}async setTitle(e){const t=m(Ee,e);return await this._bridge.send("windows",Gi.setTitle,{windowId:this.id,title:t}),this.me}async getBounds(){return(await this._bridge.send("windows",Gi.getBounds,{windowId:this.id})).bounds}async getContext(){const e=await this._bridge.contextLib.get(this.myCtxKey),{___io___:t,...n}=e;return n}async updateContext(e){const t=m(nt,e);return await this._bridge.contextLib.update(this.myCtxKey,t),this.me}async setContext(e){const t=m(nt,e),n=await this._bridge.contextLib.get(this.myCtxKey),i=n.___io___?{...t,___io___:n.___io___}:t;return await this._bridge.contextLib.set(this.myCtxKey,i),this.me}onContextUpdated(e){if("function"!=typeof e)return f.raiseError("Cannot subscribe to context changes, because the provided callback is not a function!");return this.registry.add("context-updated",(t=>{const{___io___:n,...i}=t;e(i,this.me)}))}async getChannel(){return(await this._bridge.send("windows",Gi.getChannel,{windowId:this.id},void 0,{includeOperationCheck:!0})).channel}onChannelsChanged(e){return this.registry.add("channels-changed",e)}}const Ki={operationCheck:{name:"operationCheck",dataDecoder:ci,resultDecoder:ai},getWorkspaceWindowFrameBounds:{name:"getWorkspaceWindowFrameBounds",resultDecoder:di,dataDecoder:oi}},zi=(e,t,n)=>new Promise(((i,s)=>{let r=!0;const o=setTimeout((()=>{if(!r)return;r=!1;s(n||`Promise timeout hit: ${t}`)}),t);e().then((e=>{r&&(r=!1,clearTimeout(o),i(e))})).catch((e=>{r&&(r=!1,clearTimeout(o),s(e))}))})),Vi=(e,t,n)=>new Promise(((i,s)=>{const r=setTimeout((()=>{s(n||`Promise timeout hit: ${t}`)}),t);new Promise(e).then((e=>{clearTimeout(r),i(e)})).catch((e=>{clearTimeout(r),s(e)}))}));class Qi{focusEventHandler;registry=Hi();platformRegistration;ioc;bridge;publicWindowId;allWindowProjections=[];me;logger;isWorkspaceFrame;instanceId;channelsController;async start(e,t){this.logger=e.logger.subLogger("windows.controller.web"),this.logger.trace("starting the web windows controller"),this.publicWindowId=t.publicWindowId,this.addWindowOperationExecutors(),this.ioc=t,this.bridge=t.bridge,this.instanceId=e.interop.instance.instance,this.channelsController=t.channelsController,this.logger.trace(`set the public window id: ${this.publicWindowId}, set the bridge operations and ioc, registering with the platform now`),this.platformRegistration=this.registerWithPlatform(),await this.platformRegistration,await this.initializeFocusTracking(),this.logger.trace("registration with the platform successful, attaching the windows property to glue and returning");const n=this.toApi();e.windows=n}handlePlatformShutdown(){this.registry.clear(),this.allWindowProjections=[],this.focusEventHandler&&(document.removeEventListener("visibilityChange",this.focusEventHandler),window.removeEventListener("focus",this.focusEventHandler),window.removeEventListener("blur",this.focusEventHandler))}async handleBridgeMessage(e){await this.platformRegistration;const t=m($e,e.operation),n=Gi[t];if(!n.execute)return;let i=e.data;return n.dataDecoder&&(i=m(n.dataDecoder,e.data)),await n.execute(i)}async open(e,t,n){m(Ee,e),m(Ee,t);const i=m(Ue,n),s=await this.bridge.send("windows",Gi.openWindow,{name:e,url:t,options:i});return this.waitForWindowAdded(s.windowId)}list(){return this.allWindowProjections.map((e=>e.api))}findById(e){return m(Ee,e),this.allWindowProjections.find((t=>t.id===e))?.api}toApi(){return{open:this.open.bind(this),my:this.my.bind(this),list:this.list.bind(this),findById:this.findById.bind(this),onWindowAdded:this.onWindowAdded.bind(this),onWindowRemoved:this.onWindowRemoved.bind(this),onWindowGotFocus:this.onWindowGotFocus.bind(this),onWindowLostFocus:this.onWindowLostFocus.bind(this)}}addWindowOperationExecutors(){Gi.focusChange.execute=this.handleFocusChangeEvent.bind(this),Gi.windowAdded.execute=this.handleWindowAdded.bind(this),Gi.windowRemoved.execute=this.handleWindowRemoved.bind(this),Gi.getBounds.execute=this.handleGetBounds.bind(this),Gi.getFrameBounds.execute=this.handleGetBounds.bind(this),Gi.getTitle.execute=this.handleGetTitle.bind(this),Gi.getUrl.execute=this.handleGetUrl.bind(this),Gi.moveResize.execute=this.handleMoveResize.bind(this),Gi.setTitle.execute=this.handleSetTitle.bind(this),Gi.getChannel.execute=this.handleGetChannel.bind(this),Gi.notifyChannelsChanged.execute=this.handleChannelsChanged.bind(this)}my(){return Object.assign({},this.me)}onWindowAdded(e){return"function"!=typeof e?f.raiseError("Cannot subscribe to window added, because the provided callback is not a function!"):this.registry.add("window-added",e)}onWindowRemoved(e){return"function"!=typeof e?f.raiseError("Cannot subscribe to window removed, because the provided callback is not a function!"):this.registry.add("window-removed",e)}onWindowGotFocus(e){return"function"!=typeof e?f.raiseError("Cannot subscribe to onWindowGotFocus, because the provided callback is not a function!"):this.registry.add("window-got-focus",e)}onWindowLostFocus(e){return"function"!=typeof e?f.raiseError("Cannot subscribe to onWindowLostFocus, because the provided callback is not a function!"):this.registry.add("window-lost-focus",e)}async sayHello(){return await this.bridge.send("windows",Gi.windowHello,{windowId:this.publicWindowId})}async registerWithPlatform(){const{windows:e,isWorkspaceFrame:t}=await this.sayHello();if(this.isWorkspaceFrame=t,this.logger.trace("the platform responded to the hello message"),!this.isWorkspaceFrame&&this.publicWindowId){this.logger.trace("i am not treated as a workspace frame, setting my window");const t=e.find((e=>e.windowId===this.publicWindowId));if(!t)return f.raiseError("Cannot initialize the window library, because I received no information about me from the platform");const n=await this.ioc.buildWebWindow(this.publicWindowId,t.name);this.me=n.api,this.allWindowProjections.push(n)}const n=await Promise.all(e.filter((e=>e.windowId!==this.publicWindowId)).map((e=>this.ioc.buildWebWindow(e.windowId,e.name))));this.logger.trace("all windows projections are completed, building the list collection"),this.allWindowProjections.push(...n)}async handleFocusChangeEvent(e){const t=this.allWindowProjections.find((t=>t.id===e.windowId));if(!t)return;t.model.processSelfFocusEvent(e.hasFocus);const n=e.hasFocus?"window-got-focus":"window-lost-focus";this.registry.execute(n,t.api)}async handleWindowAdded(e){if(this.allWindowProjections.some((t=>t.id===e.windowId)))return;const t=await this.ioc.buildWebWindow(e.windowId,e.name);this.allWindowProjections.push(t),this.registry.execute("window-added",t.api)}async handleWindowRemoved(e){const t=this.allWindowProjections.find((t=>t.id===e.windowId));t&&(this.allWindowProjections=this.allWindowProjections.filter((t=>t.id!==e.windowId)),t.model.clean(),this.registry.execute("window-removed",t.api))}async handleGetBounds(){return this.me||this.isWorkspaceFrame?{windowId:this.isWorkspaceFrame?"noop":this.me.id,bounds:{top:window.screenTop,left:window.screenLeft,width:window.innerWidth,height:window.innerHeight}}:f.raiseError("This window cannot report it's bounds, because it is not a Glue Window, most likely because it is an iframe")}async handleGetTitle(){return this.me?{windowId:this.me.id,title:document.title}:f.raiseError("This window cannot report it's title, because it is not a Glue Window, most likely because it is an iframe")}async handleGetUrl(){return this.me?{windowId:this.me.id,url:window.location.href}:f.raiseError("This window cannot report it's url, because it is not a Glue Window, most likely because it is an iframe")}async handleMoveResize(e){const t="number"==typeof e.top?e.top:e.relative?0:window.screenTop,n="number"==typeof e.left?e.left:e.relative?0:window.screenLeft,i="number"==typeof e.height?e.height:e.relative?0:window.innerHeight,s="number"==typeof e.width?e.width:e.relative?0:window.innerWidth,r=e.relative?window.moveBy:window.moveTo,o=e.relative?window.resizeBy:window.resizeTo;r(n,t),o(s,i)}async handleSetTitle(e){document.title=e.title}async initializeFocusTracking(){if(this.isWorkspaceFrame)return void this.logger.trace("Ignoring the focus tracking, because this client is a workspace frame");try{await this.bridge.send("windows",Ki.operationCheck,{operation:"focusChange"})}catch(e){return void this.logger.warn("The platform of this client is outdated and does not support focus tracking, disabling focus events for this client.")}const e=document.hasFocus();await this.transmitFocusChange(!0),e||await this.transmitFocusChange(!1),this.defineEventListeners()}processFocusEvent(){const e=document.hasFocus();this.transmitFocusChange(e)}waitForWindowAdded(e){const t=this.allWindowProjections.find((t=>t.id===e));return t?Promise.resolve(t.api):Vi((t=>{const n=this.onWindowAdded((i=>{i.id===e&&(n(),t(i))}))}),3e4,`Timed out waiting for ${e} to be announced`)}async transmitFocusChange(e){const t={windowId:this.me?.id||`iframe-${this.instanceId}`,hasFocus:e};this.me&&(this.me.isFocused=e),await this.bridge.send("windows",Gi.focusChange,t)}defineEventListeners(){this.focusEventHandler=this.processFocusEvent.bind(this),document.addEventListener("visibilityChange",this.focusEventHandler),window.addEventListener("focus",this.focusEventHandler),window.addEventListener("blur",this.focusEventHandler)}async handleGetChannel(){if(!this.me)return f.raiseError("This window cannot report it's channel, because it is not a Glue Window, most likely because it is an iframe");const e=this.channelsController.my();return{...e?{channel:e}:{}}}async handleChannelsChanged(e){const t=this.allWindowProjections.find((t=>t.id===e.windowId));t?.model.processChannelsChangedEvent(e.channelNames)}}const Xi="T42.Web.Platform.Control",Yi="T42.Web.Platform.Stream",Zi="T42.Web.Client.Control",es="T42.Core.Plus.Themes.Stream";class ts{coreGlue;communicationId;platformMethodTimeoutMs=1e4;controllers;sub;running;constructor(e,t){this.coreGlue=e,this.communicationId=t}get contextLib(){return this.coreGlue.contexts}get interopInstance(){return this.coreGlue.interop.instance.instance}async stop(){this.running=!1,this.sub.close(),await this.coreGlue.interop.unregister(Zi)}async start(e){this.running=!0,this.controllers=e,await Promise.all([this.checkWaitMethod(Xi),this.checkWaitMethod(Yi)]);const t=this.communicationId,[n]=await Promise.all([this.coreGlue.interop.subscribe(Yi,t?{target:{instance:this.communicationId}}:void 0),this.coreGlue.interop.registerAsync(Zi,((e,t,n,i)=>this.passMessageController(e,n,i)))]);this.sub=n,this.sub.onData((e=>this.passMessageController(e.data)))}getInteropInstance(e){const t=this.coreGlue.interop.servers().find((t=>t.windowId&&t.windowId===e));return{application:t?.application,applicationName:t?.applicationName,peerId:t?.peerId,instance:t?.instance,windowId:t?.windowId}}async send(e,t,n,i,s){if(t.dataDecoder)try{t.dataDecoder.runWithException(n)}catch(e){return f.raiseError(`Unexpected Web->Platform outgoing validation error: ${e.message}, for operation: ${t.name} and input: ${JSON.stringify(e.input)}`)}if(!(!s?.includeOperationCheck||(await this.checkOperationSupported(e,t)).isSupported))return f.raiseError(`Cannot complete operation: ${t.name} for domain: ${e} because this client is connected to a platform which does not support it`);try{const s=await this.transmitMessage(e,t,n,i);return t.resultDecoder&&t.resultDecoder.runWithException(s),s}catch(e){return e?.kind?f.raiseError(`Unexpected Web<-Platform incoming validation error: ${e.message}, for operation: ${t.name} and input: ${JSON.stringify(e.input)}`):f.raiseError(e)}}async createNotificationsSteam(){return this.coreGlue.interop.methods().some((e=>e.name===es))?this.coreGlue.interop.subscribe(es,this.communicationId?{target:{instance:this.communicationId}}:void 0):f.raiseError("Cannot subscribe to theme changes, because the underlying interop stream does not exist. Most likely this is the case when this client is not connected to Core Plus.")}async checkOperationSupported(e,t){try{return await this.send(e,Ki.operationCheck,{operation:t.name})}catch(e){return{isSupported:!1}}}checkWaitMethod(e){return Vi((t=>{if(this.coreGlue.interop.methods().some((t=>{const n=t.name===e,i=!this.communicationId||t.getServers().some((e=>e.instance===this.communicationId));return n&&i})))return t();const n=this.coreGlue.interop.serverMethodAdded((i=>{const s=i.method,r=i.server,o=!this.communicationId||r.instance===this.communicationId;s.name===e&&o&&(n(),t())}))}),this.platformMethodTimeoutMs,`Cannot initiate Glue Web, because a system method's discovery timed out: ${e}`)}passMessageController(e,t,n){const i=Ne.run(e.domain);if(!i.ok)return void(n&&n(`Cannot execute this client control, because of domain validation error: ${JSON.stringify(i.error)}`));const s=i.result;this.controllers[s].handleBridgeMessage(e).then((e=>{t&&t(e)})).catch((e=>{n&&n(e),console.warn(e)}))}async transmitMessage(e,t,n,i){const s={domain:e,data:n,operation:t.name};let r;const o=`Internal Platform Communication Error. Attempted operation: ${JSON.stringify(t.name)} with data: ${JSON.stringify(n)}. `,a=this.communicationId;try{if(!this.running)throw new Error("Cannot send a control message, because the platform shut down");if(r=await this.coreGlue.interop.invoke(Xi,s,a?{instance:this.communicationId}:void 0,i),!r)throw new Error("Received unsupported r