@myop/sdk 0.1.46 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/bundled-declarations.d.ts +61 -0
  2. package/dist/cjs/{_IframeSDK.b1e6c181.js → _IframeSDK.561df75d.js} +31 -1
  3. package/dist/cjs/_IframeSDK.561df75d.js.map +7 -0
  4. package/dist/cjs/_IframeSDK.66415fd2.min.js +1 -0
  5. package/dist/cjs/_MyopHelpers.70503082.js +2810 -0
  6. package/dist/cjs/_MyopHelpers.70503082.js.map +7 -0
  7. package/dist/cjs/_MyopHelpers.7c81005e.min.js +1 -0
  8. package/dist/cjs/_WebComponentSDK.dabe5cd1.min.js +1 -0
  9. package/dist/cjs/{_WebComponentSDK.bf4ad0dd.js → _WebComponentSDK.fd6435d3.js} +31 -1
  10. package/dist/cjs/_WebComponentSDK.fd6435d3.js.map +7 -0
  11. package/dist/cjs/_hostSDK.9b7c3010.min.js +1 -0
  12. package/dist/cjs/{_hostSDK.7c59d1ae.js → _hostSDK.b1330e44.js} +31 -1
  13. package/dist/cjs/_hostSDK.b1330e44.js.map +7 -0
  14. package/dist/cjs/myop_sdk.js +14 -14
  15. package/dist/cjs/myop_sdk.js.map +1 -1
  16. package/dist/cjs/myop_sdk.min.js +1 -1
  17. package/dist/module/Iframe/index.js +34 -2
  18. package/dist/module/Iframe/index.js.map +3 -3
  19. package/dist/module/SDK.js +123 -4
  20. package/dist/module/SDK.js.map +3 -3
  21. package/dist/module/common/index.d.ts +46 -0
  22. package/dist/module/common/index.js +1 -1
  23. package/dist/module/common/index.js.map +2 -2
  24. package/dist/module/helpers/EnableV2.d.ts +12 -0
  25. package/dist/module/helpers/index.d.ts +1 -0
  26. package/dist/module/helpers/index.js +2520 -4
  27. package/dist/module/helpers/index.js.map +4 -4
  28. package/dist/module/host/index.js +34 -2
  29. package/dist/module/host/index.js.map +3 -3
  30. package/dist/module/webcomponent/index.js +34 -2
  31. package/dist/module/webcomponent/index.js.map +3 -3
  32. package/package.json +1 -1
  33. package/dist/cjs/_IframeSDK.71663203.min.js +0 -1
  34. package/dist/cjs/_IframeSDK.b1e6c181.js.map +0 -7
  35. package/dist/cjs/_MyopHelpers.98cae3f9.js +0 -417
  36. package/dist/cjs/_MyopHelpers.98cae3f9.js.map +0 -7
  37. package/dist/cjs/_MyopHelpers.f3e207e0.min.js +0 -1
  38. package/dist/cjs/_WebComponentSDK.3474ea7a.min.js +0 -1
  39. package/dist/cjs/_WebComponentSDK.bf4ad0dd.js.map +0 -7
  40. package/dist/cjs/_hostSDK.7c59d1ae.js.map +0 -7
  41. package/dist/cjs/_hostSDK.8b543e61.min.js +0 -1
@@ -0,0 +1 @@
1
+ var lt=Object.defineProperty,$t=Object.defineProperties;var At=Object.getOwnPropertyDescriptors;var mt=Object.getOwnPropertySymbols;var Ut=Object.prototype.hasOwnProperty,zt=Object.prototype.propertyIsEnumerable;var Ke=(o,e,t)=>e in o?lt(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,h=(o,e)=>{for(var t in e||(e={}))Ut.call(e,t)&&Ke(o,t,e[t]);if(mt)for(var t of mt(e))zt.call(e,t)&&Ke(o,t,e[t]);return o},E=(o,e)=>$t(o,At(e));var ft=(o,e)=>{for(var t in e)lt(o,t,{get:e[t],enumerable:!0})};var s=(o,e,t)=>Ke(o,typeof e!="symbol"?e+"":e,t);var ae="__federation__",gt="onLoad";var $=(o,e)=>{window[ae]&&window[ae][o]&&window[ae][o][gt]&&window[ae][o][gt]({[o]:e})};var pt={};ft(pt,{CloudRepository:()=>z,ComponentConfig:()=>et,SkinConfig:()=>Ye,addClass:()=>Qt,applyStylesheet:()=>jt,applyStylesheetLink:()=>Gt,changeSkinUrlByTokenizer:()=>Xt,createIframeSkinByTokenizer:()=>St,enableV2:()=>dn,exec:()=>Yt,removeClass:()=>Zt,v2_CloudRepository:()=>_e});var M=()=>"10000000-1000-4000-8000-100000000000".replace(/[018]/g,o=>(+o^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+o/4).toString(16));var Nt=o=>{let e=[...o].map(t=>t.toString(16).padStart(2,"0")).join("");return[e.slice(0,8),e.slice(8,12),e.slice(12,16),e.slice(16,20),e.slice(20)].join("-")};var Wt=o=>{let e=o.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4;)e+="=";let t=atob(e);return Uint8Array.from(t,n=>n.charCodeAt(0))};var Fe=o=>{let e=Wt(o);if(e.length%16!==0)throw new Error("Invalid input length");let t=[];for(let n=0;n<e.length;n+=16)t.push(Nt(e.slice(n,n+16)));return t};var ut=o=>new Promise(e=>setTimeout(e,o));var pe={};ft(pe,{AddEventListenerMessage:()=>ze,BaseMyopMessage:()=>y,BindClickMessage:()=>Ae,ChangeTextMessage:()=>Ue,CleanupMessage:()=>ne,CleanupReplayMessage:()=>oe,ClickReplayMessage:()=>j,CreateRefComponentMessage:()=>Y,CustomRefMessage:()=>v,DetectMyopRefsMessage:()=>qe,DetectedMyopRefsMessage:()=>te,DisposeMessage:()=>se,ElementValueReplayMessage:()=>X,EnvelopedMessage:()=>ee,EventListenerCallbackMessage:()=>J,ExecuteComponentMethod:()=>S,ExecuteScriptMessage:()=>T,ExecuteScriptReplyMessage:()=>G,GetAttributeMessage:()=>je,GetAttributeReplayMessage:()=>Ge,GetElementValueMessage:()=>We,InitMessage:()=>A,InitRequest:()=>Z,InitResponse:()=>Q,MessageDirection:()=>w,MutationObserverMessage:()=>Xe,MyopBindMessage:()=>b,MyopBindReplayMessage:()=>x,MyopElementMessage:()=>$e,Ref:()=>B,RefComponentCreatedMessage:()=>U,ResizeObserverMessage:()=>Ze,SetAttributeMessage:()=>Ne,SetInnerHtml:()=>Ve,SetMutationObserverMessage:()=>Je,SetResizeObserverMessage:()=>Qe,stripFunction:()=>Mt});var w=class{};s(w,"down","down"),s(w,"up","up");var y=class{constructor(){s(this,"id",M());s(this,"myop",!0);s(this,"content");s(this,"source");s(this,"destination");s(this,"route");s(this,"ref");s(this,"direction");s(this,"cleanable",!1)}static create(...e){return new this(...e)}isTypeof(e){return e.messageType===this.messageType}},$e=class extends y{constructor(t){super();this.ref=t}},x=class extends y{constructor(t){super();this.replayToHandler=t}},b=class extends y{constructor(t){super();this.handler=t;s(this,"handlerUniqueId",M())}},B=class o{constructor(e,t){this.refConfig=e;this.component=t;s(this,"myop",!0);s(this,"__nonProxied");this.__nonProxied=E(h({},this),{component:null})}static create(e,t,n){let r=t;return r||(r={id:"",name:"",description:"",selectorType:"id-attribute",selector:e,behavior:{type:"code"}}),new o(r,n)}};var yt="ClickReplayMessage",Ae=class extends b{constructor(t,n){super(n);this.ref=t;s(this,"replyMessageKey",yt);s(this,"messageType","BindClickMessage");s(this,"cleanable",!0)}},j=class extends x{constructor(){super(...arguments);s(this,"messageType",yt)}};var Ue=class extends y{constructor(t,n){super();this.ref=t;s(this,"messageType","ChangeTextMessage");this.content=n}};var ht="ExecuteScriptReplyMessage",Vt=/(?:function\s*\w*\s*\([^)]*\)\s*\{([\s\S]*?)\}|(\([^)]*\)\s*=>\s*\{([\s\S]*?)\}))\s*$/,qt=/\(\s*[^)]+\s*\)\s*=>\s*(.+)/,Mt=o=>{let e=o.match(Vt);if(e)return e[1]||e[3];{let t=o.match(qt);if(t)return t[1].trim()}},T=class extends b{constructor(t,n=()=>{},r){super(n);this.scriptInputs=r;s(this,"replyMessageKey",ht);s(this,"messageType","ExecuteScriptMessage");s(this,"script","");this.script=t.toString(),this.content=t.toString(),this.content=Mt(this.content)}};s(T,"replierKey","send"),s(T,"completeStreamKey","completeStream");var G=class extends x{constructor(t,n){super(t);this.replayToHandler=t;this.content=n;s(this,"messageType",ht)}};var v=class extends T{constructor(t,n,r=()=>{}){super(({rootRef:i,elementId:a,_script:p,__scriptInputs:d})=>{let c=(i.shadowRoot||i.container).querySelectorAll("[myop-id='".concat(a,"']"));return c.length?(d.ref=c[0],new Function("return (".concat(p,")(...arguments)"))(d)):null},r);this.scriptInputs=n;this.scriptInputs=E(h({},n),{_script:t.toString()})}};var It="EventListenerCallbackMessage",ze=class extends b{constructor(t,n,r){super(r);this.ref=t;this.type=n;this.handler=r;s(this,"replyMessageKey",It);s(this,"messageType","AddEventListenerMessage");s(this,"cleanable",!0);s(this,"serializableSkeleton",!1)}withSerializableSkeleton(t){return this.serializableSkeleton=t,this}},J=class extends x{constructor(t,n){super(t);this.replayToHandler=t;this.e=n;s(this,"messageType",It);this.content={e:n}}};var Ne=class extends y{constructor(t,n,r){super();this.ref=t;this.name=n;this.value=r;s(this,"messageType","SetAttributeMessage")}};var Ct="ElementValueReplayMessage",We=class extends b{constructor(t,n){super(n);this.ref=t;s(this,"replyMessageKey",Ct);s(this,"messageType","GetElementValueMessage")}},X=class extends x{constructor(t){super();this.content=t;s(this,"messageType",Ct)}};var Ve=class extends y{constructor(t,n){super();this.ref=t;s(this,"messageType","SetInnerHtml");this.content=n}};var A=class extends y{constructor(t){super();s(this,"messageType","InitMessage");this.content={id:t}}isTypeof(t){return t.messageType===this.messageType}},Q=class extends A{constructor(){super(...arguments);s(this,"messageType","InitResponse")}},Z=class extends y{constructor(){super(...arguments);s(this,"messageType","InitRequest")}};var xt="RefComponentCreatedMessage",Y=class extends b{constructor(t,n,r,i){super(i);this.refConfig=t;this.nestedComponentConfig=n;this.options=r;s(this,"replyMessageKey",xt);s(this,"messageType","CreateRefComponentMessage")}},U=class extends x{constructor(t,n,r){super(t);this.replayToHandler=t;this.nestedRefs=n;this.failed=r;s(this,"messageType",xt)}};var ee=class extends y{constructor(t,n){super();this.destination=t;this.message=n;s(this,"messageType","EnvelopedMessage");let r=n;this.route=[t,...r.route?r.route:[]]}};var bt="DetectedMyopRefsMessage",qe=class extends b{constructor(){super(...arguments);s(this,"messageType","DetectMyopRefsMessage");s(this,"replyMessageKey",bt)}},te=class extends x{constructor(t,n){super(t);this.replayToHandler=t;s(this,"messageType",bt);this.content=n}isTypeof(t){return t.messageType===this.messageType}};var wt="GetAttributeReplayMessage",je=class extends b{constructor(t,n,r){super(r);this.ref=t;this.name=n;s(this,"replyMessageKey",wt);s(this,"messageType","GetAttributeMessage")}},Ge=class extends x{constructor(t){super();this.content=t;s(this,"messageType",wt)}};var S=class extends y{constructor(t){super();this.method=t;s(this,"messageType","ExecuteComponentMethod")}};var Je=class extends y{constructor(){super(...arguments);s(this,"messageType","SetMutationObserverMessage")}},Xe=class extends y{constructor(){super(...arguments);s(this,"messageType","MutationObserverMessage")}};var Tt="CleanupReplayMessage",ne=class extends b{constructor(t,n){super(n);this.cleanupForMessageId=t;s(this,"replyMessageKey",Tt);s(this,"messageType","CleanupMessage")}},oe=class extends x{constructor(t){super();this.customCleanup=t;s(this,"messageType",Tt)}};var se=class extends y{constructor(){super(...arguments);s(this,"messageType","DisposeMessage")}};var Qe=class extends y{constructor(){super(...arguments);s(this,"cleanable",!0);s(this,"messageType","SetResizeObserverMessage")}},Ze=class extends y{constructor(){super(...arguments);s(this,"messageType","ResizeObserverMessage")}};var jt=(o,e,t)=>{let n="myop-css-".concat(M());return o.send(new T(({rootRef:r,_stylesheet:i,_tagId:a,_css:p})=>{let d=document.createElement("style");d.type="text/css";let c=p;for(let m in i){c+="".concat(m," { ");let l=i[m];for(let f in l)c+="".concat(f,": ").concat(l[f],"; ");c+="} "}d.appendChild(document.createTextNode(c)),d.id=a,(r.shadowRoot||r.container).appendChild(d)},()=>{},{_stylesheet:e,_css:t||"",_tagId:n})),()=>{o.send(new T(({rootRef:r,_tagId:i})=>{let a=(r.shadowRoot||document).getElementById(i);a&&a.remove()},()=>{},{_tagId:n}))}},Gt=(o,e)=>{let t="myop-css-".concat(M());return o.send(new T(({rootRef:n,_tagId:r,_link:i})=>{let a=document.createElement("link");a.id=r,a.rel="stylesheet",a.href=i,document.head.appendChild(a),(n.shadowRoot||n.container).appendChild(a)},()=>{},{_link:e,_tagId:t})),()=>{o.send(new T(({rootRef:n,_tagId:r})=>{let i=(n.shadowRoot||document).getElementById(r);i&&i.remove()},()=>{},{_tagId:t}))}};var Jt=(o,e)=>{let t=new RegExp(Object.keys(e).join("|"),"g");return o.replace(t,n=>(e[n]||n).toString())},St=(o,e)=>{let t=o.loader;if(t.type!=="IframeLoader")throw new Error('iframeSkinUrlTokenizer received skin with loader type "'.concat(t.type,'", currently only "IframeLoader" is supported'));return o.loader=h({},o.loader),o.loader.url=Jt(o.loader.url,e),o},Xt=o=>async e=>St(e,o);var Qt=(o,e,t)=>{o.send(new v(({ref:n,_className:r})=>{n==null||n.classList.add(r)},{elementId:t,_className:e}))},Zt=(o,e,t)=>{o.send(new v(({ref:n,_className:r})=>{n==null||n.classList.remove(r)},{elementId:t,_className:e}))};var de=class de{constructor(){s(this,"_runTimeInstanceId","runtime-instance-id-"+M());s(this,"_runTimeId","runtime-id-"+M());s(this,"_runTimeName","runtime-name-"+M());s(this,"id",this._runTimeId);s(this,"name",this._runTimeName);s(this,"description","");s(this,"loader",null);s(this,"withLoader",e=>(this.loader=e,this));s(this,"withHTMLLoader",e=>(e.type="HTMLLoader",this.loader=e,this));s(this,"build",()=>this)}};s(de,"create",()=>new de);var Ye=de,ce=class ce{constructor(){s(this,"_runTimeInstanceId","runtime-instance-id-"+M());s(this,"_runTimeId","runtime-id-"+M());s(this,"_runTimeName","runtime-name-"+M());s(this,"instance",{id:this._runTimeInstanceId,componentId:this._runTimeId,componentName:this._runTimeName,skinSelector:null});s(this,"name",this._runTimeName);s(this,"type",{id:this._runTimeId,name:this._runTimeName,description:"",props:[],refs:[],skins:[],defaultSkin:0});s(this,"withInstance",e=>(this.instance=e,this));s(this,"withType",e=>(this.type=e,this));s(this,"withName",e=>(this.name=e,this));s(this,"withDefaultSkin",e=>(this.type.skins.push(e),this.type.defaultSkin=this.type.skins.length-1,this.instance.skinSelector={type:"Dedicated",skin:{id:e.id}},this));s(this,"withRef",e=>(this.type.refs.push(e),this));s(this,"withBasicRef",e=>{let t={id:"",name:e,description:"",selectorType:"id-attribute",selector:e,behavior:{type:"code"}};return this.type.refs.push(t),this});s(this,"build",()=>JSON.parse(JSON.stringify(this)))}};s(ce,"create",()=>new ce);var et=ce;var me=class me{constructor(e="https://cloud.myop.dev"){this._baseUrl=e;s(this,"userFlows",{})}async fetchComponent(e,t){return t?(await this.fetchFlow(t)).components.find(r=>r.type.id===e):(await this.fetchAutoFlow(e)).components[0]}async fetchAutoFlow(e){return this.userFlows[e]||(this.userFlows[e]=new Promise(async(t,n)=>{try{let i=await(await fetch("".concat(this._baseUrl,"/flow?id=").concat(e,"&auto=true"))).json();t(i.item)}catch(r){n(r)}})),await this.userFlows[e]}async fetchFlow(e){return this.userFlows[e]||(this.userFlows[e]=new Promise(async(t,n)=>{try{let i=await(await fetch("".concat(this._baseUrl,"/flow?id=").concat(e,"&resolve=components"))).json();t(i.item)}catch(r){n(r)}})),await this.userFlows[e]}};s(me,"Main",new me);var z=me;var Yt=async o=>await o();var g={InitRequest:"InitRequest",InitResponse:"InitResponse",InitMessage:"InitMessage",DisposeMessage:"DisposeMessage",ChangeTextMessage:"ChangeTextMessage",BindClickMessage:"BindClickMessage",DetectMyopRefsMessage:"DetectMyopRefsMessage",ExecuteScriptMessage:"ExecuteScriptMessage",AddEventListenerMessage:"AddEventListenerMessage",SetAttributeMessage:"SetAttributeMessage",CreateRefComponentMessage:"CreateRefComponentMessage",EnvelopedMessage:"EnvelopedMessage",GetElementValueMessage:"GetElementValueMessage",GetAttributeMessage:"GetAttributeMessage",SetInnerHtml:"SetInnerHtml",ExecuteComponentMethod:"ExecuteComponentMethod",SetMutationObserverMessage:"SetMutationObserverMessage",SetResizeObserverMessage:"SetResizeObserverMessage",CleanupMessage:"CleanupMessage",In:{DetectedMyopRefsMessage:"DetectedMyopRefsMessage",ClickReplayMessage:"ClickReplayMessage",ExecuteScriptReplyMessage:"ExecuteScriptReplyMessage",EventListenerCallbackMessage:"EventListenerCallbackMessage",ElementValueReplayMessage:"ElementValueReplayMessage",GetAttributeReplayMessage:"GetAttributeReplayMessage",RefComponentCreatedMessage:"RefComponentCreatedMessage",EnvelopedMessage:"EnvelopedMessage",MutationObserverMessage:"MutationObserverMessage",CleanupReplayMessage:"CleanupReplayMessage",ResizeObserverMessage:"ResizeObserverMessage"}};var L=class{constructor(e,t,n){this.componentDefinition=e;this.container=t;s(this,"id","");s(this,"messageHandlers",{});s(this,"element");s(this,"_markedForDisposed",!1);s(this,"bind",(e,t)=>{this.messageHandlers[e]||(this.messageHandlers[e]=[]),this.messageHandlers[e].includes(t)||this.messageHandlers[e].push(t)});s(this,"bindWhen",(e,t,n)=>{if(!n)throw new Error("can't use component.bindWhen without an handler");this.messageHandlers[e]||(this.messageHandlers[e]=[]);let r=this.messageHandlers[e],i=a=>t(a)?(n(a),!0):!1;return r.push(i),()=>{let a=r.indexOf(i);a>-1&&r.splice(a,1)}});s(this,"setInitiated",()=>{this.isInitiated=!0,this._whenInitiatedResolve&&this._whenInitiatedResolve()});s(this,"isInitiated",!1);s(this,"_whenInitiatedResolve");s(this,"_whenInitiatedReject");s(this,"_whenInitiated",new Promise((e,t)=>{this._whenInitiatedResolve=e,this._whenInitiatedReject=t}));s(this,"initiated",()=>this._whenInitiated);s(this,"props",{});s(this,"refs",{});this.id=(n==null?void 0:n.id)||_.Instance().assignId(e);let r=n!=null&&n.timeout?n==null?void 0:n.timeout:5*1e3;setTimeout(()=>{!this.isInitiated&&this._whenInitiatedReject&&!this._markedForDisposed&&this._whenInitiatedReject("timeout_".concat(r," ").concat(this.id))},r),this.initiated().then(()=>{window.myop.hostSDK.inspected&&this.inspect()})}get markedForDisposed(){return this._markedForDisposed}set markedForDisposed(e){if(this._markedForDisposed)throw new Error("InvalidOperationException: The component is already in the process of being disposed. Dispose operation cannot be performed again until the current disposal process is complete.");this._markedForDisposed=e}onMessageReceived(e){if(e.messageType===g.ExecuteComponentMethod){let n=e;return this[n.method]?this[n.method](n.content):console.log("method not found ".concat(n.method," on component"),this),!0}let t=this.messageHandlers[e.messageType];if(t&&t.length){let n=!1;return t.forEach(r=>{n=n||r(e)}),n}return!1}sendCleanupMessage(e){e.source=this.id,e.destination=this.id,e.direction=w.down;let t=this.bindWhen(e.replyMessageKey,r=>r.replayToHandler===e.handlerUniqueId,r=>{e.handler(r),t()}),n=e.handler;delete e.handler,this.send(e),e.handler=n}send(e){e.source||(e.source=this.id),e.destination||(e.destination=this.id),e.direction=w.down;let t;if(e.handler){let n=e;t=this.bindWhen(n.replyMessageKey,r=>r.replayToHandler===n.handlerUniqueId,n.handler),delete e.handler}return e.ref&&(e.ref=e.ref.__nonProxied||e.ref),e.cleanable?()=>{this.sendCleanupMessage(new ne(e.id,n=>{})),t&&t()}:()=>{}}dispose(){if(this.markedForDisposed=!0,!this.isInitiated)return;console.log("disposing component",this.id),this.send(new se);let e=this.messageHandlers.onDispose;e&&e.forEach(t=>{t(null)}),this.messageHandlers={},this.id+="_disposed",this.isInitiated=!1}};var le=class{constructor(e,t,n,r,i){this.myopId=e;this.htmlTagName=t;this.BoundingRect=n;this.offsetTop=r;this.offsetLeft=i;s(this,"type","MyopElementRef")}};var Rt=async o=>{if(typeof o=="function")o();else if(o instanceof Promise){let e=await o;typeof e=="function"&&e()}},tt=class{constructor(e){this.messageToHost=e}},fe=class extends tt{constructor(t,n){super(t);this.messageToHost=t;this.context=n}};var nt=class{constructor(e,t){this.id=e;this.context=t;s(this,"send",e=>{})}},ge=class{constructor(){s(this,"messageToHandleAfterInit",[]);s(this,"components",{});s(this,"alwaysPassEnvelopesToHost",!1);s(this,"messageCleanupCache",{})}handleIncomeMessages(e){let t=e.data?e.data:e.detail;if(!(!t||!t.myop)){let n=t;if(n.direction!==w.down)return;if(n.messageType===g.DisposeMessage){n.destination&&delete this.components[n.destination];return}if(n.messageType===g.InitMessage){let r=n.content.id;if(this.components[r])return;this.components[r]=new nt(r),this.messageToHost(new Q(r));return}if(n.messageType===g.EnvelopedMessage){let r=n,i=r.message;if(n=i,this.alwaysPassEnvelopesToHost||this.components[n.destination]){let a=myop.hostSDK.components.find(d=>d.id===i.destination);if(a){a.send(i);return}let p=myop.hostSDK.components.find(d=>d.id===r.destination);if(p){p.send(i);return}}else return}if(n.messageType){if(n.messageType===g.CleanupMessage){let i=n,a=this.messageCleanupCache[i.cleanupForMessageId],p=new oe(!!a);p.destination=n.destination,a?(delete this.messageCleanupCache[i.cleanupForMessageId],Rt(a).then(()=>{this.messageToHost(p,i)}).catch(()=>{})):this.messageToHost(p,i);return}let r=!1;this.supportedHandlers.forEach(i=>{if(i.messageType===n.messageType){r=!0;let a=i.executor(n);if(n.cleanable&&a&&(this.messageCleanupCache[n.id]=a),a&&!n.cleanable)throw new Error("Cleanup handler generated for non-cleanable message. \nmessageType - ".concat(n.messageType,", handler executor was - ").concat(i.executor,"\n\nPlease review the message definition object & message handler.\nTo ensure cleanup properly set 'cleanable' true at message definition and return IMessageExecutorCleanup from your handlers."));if(!a&&n.cleanable)throw new Error("No cleanup handler generated for a cleanable message. \nmessageType - ".concat(n.messageType,", handler executor was - ").concat(i.executor,"\n\nPlease review the message definition object & message handler.\nTo ensure cleanup properly set 'cleanable' true at message definition and return IMessageExecutorCleanup from your handlers."))}})}else console.log("unsupported message type")}}};var k={IframeLoader:"IframeLoader",WebComponentLoader:"WebComponentLoader",HTMLLoader:"HTMLLoader",MinimizedLoader:"MinimizedLoader"};var K={open:"open",closed:"closed",none:"none",localFrame:"localFrame"};var W={message:"message",code:"code"},N=class{};s(N,"code","code"),s(N,"component","component");var F={Segmented:"Segmented",Dedicated:"Dedicated",Default:"Default"},ye={Segment:"Segment",Promo:"Promo",AB:"AB"},ue=class{constructor(e,t){this.container=e;this.shadowRoot=t;s(this,"getRootDiv",()=>(this.shadowRoot||this.container).querySelector("div"));s(this,"getRoot",()=>this.shadowRoot||this.container)}};var ot=o=>o!==Object(o),en=o=>typeof o=="function",st=o=>{if(ot(o))return!0;if(en(o)||Object.getPrototypeOf(o))return!1;for(let e in o){let t=o[e];if(typeof t=="object"){if(!st(t))return!1}else{if(ot(t))continue;return!1}}return!0},H=(o,e={},t=!0,n=new WeakMap)=>{if(ot(o))return o;if(Array.isArray(o)){if(n.has(o))return n.get(o);let r=[];n.set(o,r);for(let i=0;i<o.length;i++){let a=o[i];r[i]=H(a,e,t,n)}return r}if(o!==null&&typeof o=="object"){if(n.has(o))return n.get(o);let r={};n.set(o,r);for(let i in o){let a=typeof e=="boolean"?e:e[i];a&&(a===!0?(t?o[i]!==void 0:o[i])&&(r[i]=H(o[i],!0,t,n)):typeof a=="object"&&(r[i]=H(o[i],a,t,n)))}return r}return{}};var Et={notSerializableRefCall:(o,e)=>{throw new Error("\nThe input provided to '".concat(o.toString(),"' is not serializable. Serialization is required to ensure that the data can be safely transferred to the skin implementation. \nThe following types of data are considered non-serializable and cannot be processed:\n\n- Functions\n- DOM elements\n- Class instances\n- Circular references\n- Symbols\n- BigInt values\n\nIn the following execution we detected :\n~~~~~~~~\n").concat(e," \n~~~~~~~~\nas not serializable.\n\nTo resolve this issue, please ensure that all inputs passed to '").concat(o.toString(),"' are in a serializable format.\nThis typically includes primitive types (strings, numbers, booleans), arrays, and plain objects. \nIf you need to include complex data types, consider converting them to a serializable structure before passing them to the function.\nOr use Myop message that support it: CustomRefMessage, AddEventListenerMessage or ExecuteScriptMessage.\n\nSuggested Fix:\n1. Remove or replace non-serializable values from your input.\n2. If using objects, ensure they do not contain any functions or circular references.\n3. Convert any class instances to plain objects or JSON-compatible formats.\n4. Use dedicated Myop message.\n\nFor more details on serialization and Myop message examples, refer to https://docs.myop.dev.\n\n"))}};var re=class extends L{constructor(t,n,r){super(t,n.container,r);this.componentDefinition=t;this.parent=n;s(this,"send",t=>{let n=t.handler,r=super.send(t);return this.parent.send(new ee(this.id,t)),t.handler=n,r});s(this,"dispose",()=>{this.isInitiated&&this.send(new S("dispose")),super.dispose()})}hide(){this.send(new S("hide"))}show(){this.send(new S("show"))}inspect(){return this.send(new S("inspect"))}setHeightBasedOnDocumentElement(){this.send(new S("setHeightBasedOnDocumentElement"))}setHeightBasedOnScrollHeight(){this.send(new S("setHeightBasedOnScrollHeight"))}onMessageReceived(t){return super.onMessageReceived(t)}};var tn=(o,e,t)=>{let n=document.createElement("a");return n.textContent=o,n.style.position="relative",n.style.padding="0 5px",n.style.fontSize="14px",n.style.top="0",n.style.top="".concat(e,"px"),n.style.transform="translateX(-50%)",n.target="_blank",n.href="https://dashboard.myop.dev/dashboard/component/".concat(t.id),n},he=(o,e,t,n,r,i)=>{let a=tn("".concat(i.name," : ").concat(e),t,i);return n.insertBefore(a,r),r.style.border="1px solid #007BFF",r.style.display="block",()=>{r.style.border="unset",n.removeChild(a)}},vt=(o,e,t)=>o?!1:(console.error("Error: Undefined Prop\n\nIt looks like you've tried to use a prop that hasn't been defined.\nPlease check the prop name for any typos or ensure that it is properly defined in the component's prop list.\n\n"+"Prop Name: ".concat(e,"\n")+"Component: ".concat(t.componentDefinition.name,", ID: ").concat(t.componentDefinition.id,"\n\n")+"For more information, refer to the component page https://dashboard.myop.dev/dashboard/component/".concat(t.componentDefinition.id," or consult the developer guide.")),!0),kt=(o,e,t)=>{console.error("Error: Code Prop Not Supported\n\nCurrently, code props are only supported in local frame components.\n\u26A0\uFE0F This is a work in progress feature \u2014 code props will be supported in upcoming versions.\n\nIn the meantime, you can use message props.\n\n"+"Prop Name: ".concat(e,"\n")+"Component: ".concat(t.componentDefinition.name,", ID: ").concat(t.componentDefinition.id,"\n\n")+"For more information, refer to the component page https://dashboard.myop.dev/dashboard/component/".concat(t.componentDefinition.id," or consult the developer guide."))},Ht=(o,e,t)=>{let n=e.reduce((i,a)=>E(h({},i),{[a.name]:h({},a)}),{}),r={get:(i,a)=>{let p=n[a];if(vt(p,a,o))return!1;if(p.behavior.type===W.code){if(t.loader.type===k.HTMLLoader&&t.loader.shadowRootMode===K.localFrame){let c=p.behavior;return o.element.contentWindow[c.remap||a]}return kt(p,a,o),!1}return p.mode==="output"?new Promise(d=>{let c=[];p.behavior.ref&&c.push(B.create(p.behavior.ref)),c.push(l=>{d(l)}),p.behavior.params&&c.push(...p.behavior.params);let m=pe[p.behavior.message];o.send(new m(...c))}):null},set:(i,a,p)=>{let d=n[a];if(vt(d,a,o))return!1;if(d.behavior.type===W.code){if(t.loader.type===k.HTMLLoader&&t.loader.shadowRootMode===K.localFrame){let m=d.behavior;return o.element.contentWindow[m.remap||a]=p,!0}return kt(d,a,o),!1}else if(d.mode==="input")if(d.behavior.type==="message"){let c=[];d.behavior.ref&&c.push(B.create(d.behavior.ref)),c.push(p),d.behavior.params&&c.push(...d.behavior.params);let m=pe[d.behavior.message];return o.send(new m(...c)),!0}else throw new Error("Error: Unsupported Behavior\n\nThe 'behavior' field provided is not supported.\n"+"Component: ".concat(o.componentDefinition.name,", ID: ").concat(o.componentDefinition.id,"\n\n")+"Prop Name: ".concat(a,"\n")+"Behavior Field: ".concat(d.behavior.type,"\n\n")+"Check the documentation for valid behavior options.");return!1}};return o.props={},o.props=new Proxy(o.props,r),o},nn=(o,e)=>new Proxy(o,{get(t,n){return t[n]?t[n]:(...i)=>new Promise(a=>{i.forEach(p=>{st(p)||Et.notSerializableRefCall(n,p)}),e.send(new v(({ref:p,propName:d,functionArgs:c,makeSerializable:m})=>{if(p){let l=p[d];return m(typeof l=="function"?p[d](...c):l,!0)}return null},{elementId:t.refConfig.selector,propName:n,functionArgs:i},p=>{a(p.content)}))})},set(t,n,r){return e.send(new v(({ref:i,propName:a,propValue:p})=>{i&&(i[a]=p)},{elementId:t.refConfig.selector,propValue:r,propName:n},i=>{})),!0}}),rt=async(o,e,t,n)=>{let r=o.component;if(!r)throw new Error("cant createRefComponent with detached ref");return new Promise(async(i,a)=>{let p=new re(e.type,r,n);t.push(p),await r.initiated();let d=setTimeout(()=>{a("timeout")},5e3);r.send(new Y(o.refConfig,e,E(h({},n||{}),{id:p.id,_hasParent:!0}),async c=>{if(clearTimeout(d),c.failed){a("CreateRefComponentMessage failed");return}let m=t.find(l=>l.id==p.id);if(m!==p){r.refs[o.refConfig.name]=m,i(m);return}else p.setInitiated(),r.refs[o.refConfig.name]=p;c.nestedRefs.forEach(l=>{let f=e.instance.resolvedNestedComponents.find(C=>C.type.id===l.componentDefinitionId).type,u=new re(f,p);u.setInitiated(),p.refs[l.refName]=u,t.push(u)});try{await it(p,e,t,!0),r.setHeightBasedOnScrollHeight&&r.setHeightBasedOnScrollHeight(),i(p)}catch(l){a(l)}}))})},it=async(o,e,t,n=!1)=>{o.refs||(o.refs={});let r=Object.values(o.componentDefinition.refs).map(i=>new Promise(async(a,p)=>{var d;if(i.behavior.type==N.component){if(n){a();return}let c=i.behavior.componentId;c||(c=i.behavior.instance.componentId);let m=(d=e.instance.resolvedNestedComponents)==null?void 0:d.find(f=>f.type.id===c);if(!m)throw new Error("componentConfig provided without nestedComponentConfig check the config object");let l=B.create("",i,o);try{let f=await rt(l,m,t);o.refs[i.name]=f,a()}catch(f){p(f)}}else try{let c=B.create("",i,o);o.refs[i.name]=nn(c,o),a()}catch(c){}}));try{await Promise.all(r)}catch(i){throw i}};var V=class extends L{constructor(t,n,r,i,a){super(t,r,a);this.componentConfig=t;this.container=r;this.IframeElement=i;s(this,"cleanupInspect");s(this,"setHeightBasedOnDocumentElement",()=>{let t=this.send(new T(()=>window.document.documentElement.scrollHeight,n=>{this.IframeElement.style.height="".concat(n.content,"px"),t()}))});s(this,"observeSizeBasedOnDocumentElement",()=>this.send(new T(({send:n})=>{let{height:r,width:i}=document.documentElement.getBoundingClientRect(),a=new ResizeObserver(()=>{let{height:p,width:d}=document.documentElement.getBoundingClientRect();n({height:p,width:d})});return a.observe(document.documentElement),a.observe(document.body),{height:r,width:i}},n=>{this.IframeElement.style.width="".concat(n.content.width,"px"),this.IframeElement.style.height="".concat(n.content.height,"px")})));s(this,"setSizeBasedOnDocumentElement",()=>{let t=this.send(new T(()=>{let{height:n,width:r}=document.documentElement.getBoundingClientRect();return{height:n,width:r}},n=>{this.IframeElement.style.width="".concat(n.content.width,"px"),this.IframeElement.style.height="".concat(n.content.height,"px"),t()}))});s(this,"setHeightBasedOnScrollHeight",()=>{let t=this.send(new T(()=>{let r=0;return r++,r--,Math.max(Math.max(window.document.body.clientHeight,window.document.body.scrollHeight),window.document.body.offsetHeight)+r+"px"},n=>{this.IframeElement.style.height=n.content,t()}))});s(this,"send",t=>{var i,a;let n=h({},t);if(n.messageType===g.ExecuteComponentMethod)return this[n.method](),()=>{};n.direction=w.down;let r=super.send(n);return(a=(i=this.IframeElement)==null?void 0:i.contentWindow)==null||a.postMessage(n,"*"),r});s(this,"dispose",()=>{this.cleanupInspect&&this.cleanupInspect(),super.dispose(),this.IframeElement.parentNode.removeChild(this.IframeElement)});n.loader.autoHeight&&this.initiated().then(()=>{this.setHeightBasedOnScrollHeight()}),this.element=this.IframeElement}inspect(){return this.cleanupInspect?this.cleanupInspect:(this.cleanupInspect=he(this.id,"MyopIframeComponent",10,this.container,this.IframeElement,this.componentDefinition),()=>{this.cleanupInspect(),this.cleanupInspect=void 0})}hide(){this.IframeElement.style.opacity="0",this.IframeElement.style.position="absolute",this.IframeElement.style.pointerEvents="none",this.IframeElement.style.visibility="hidden"}show(){this.IframeElement.style.opacity="1",this.IframeElement.style.position="unset",this.IframeElement.style.pointerEvents="all",this.IframeElement.style.visibility="visible"}onMessageReceived(t){return t.messageType===g.In.MutationObserverMessage||t.messageType===g.In.ResizeObserverMessage?(this.setHeightBasedOnScrollHeight(),!0):super.onMessageReceived(t)}};var P=class{constructor(){s(this,"appendChild",(e,t,n)=>{var r;if(n!=null&&n.relative){if(n.relative.direction==="before")return e.insertBefore(t,n.relative.child);if(n.relative.direction==="after"){let i=(r=n.relative.child)==null?void 0:r.nextSibling;return e.insertBefore(t,i||null)}}else return e.appendChild(t)})}};var on=(o,e,t)=>{let n=new URL(o);return n.searchParams.append(e,t),n.toString()},Me=class extends P{constructor(){super(...arguments);s(this,"type",k.IframeLoader);s(this,"load",async(t,n,r,i)=>{let a,p=n.loader;if((r==null?void 0:r.nodeName)==="IFRAME")console.log("needs to load into an exsisting Iframe...",p.url,r),a=r,a.src=p.url;else{let d=M(),c="myop-comp-".concat(d);a=document.createElement("iframe"),r.querySelector('[id^="myop-comp-"]')||(r.innerHTML=""),i!=null&&i.hidden&&(a.style.visibility="hidden"),a=this.appendChild(r,a,i);let m=n.loader.url;i!=null&&i._hasParent&&(m=on(m,"_myop-comp",d));let l="";i!=null&&i.elementAttributes&&(l=Object.entries(i==null?void 0:i.elementAttributes).map(([f,u])=>u===""||u===null||u===void 0?f:"".concat(f,'="').concat(String(u),'"')).join(" ")),a.outerHTML='<iframe \n id="'.concat(c,'"\n style="\n padding: 0;\n margin: 0;\n height: ').concat(p.autoHeight||!p.height?"":p.height,"; \n width : 100%;\n overflow: hidden;\n border: none;\n opacity: ").concat(i!=null&&i.hidden?"0":"1",";\n position: ").concat(i!=null&&i.hidden?"absolute":"static",";\n pointer-events: ").concat(i!=null&&i.hidden?"none":"all",';\n "\n src="').concat(m,'"\n ').concat(l,"\n ></iframe>"),a=r.querySelector("#".concat(c))}return new V(t,n,r,a,i)})}};var Ie={webcomponent_message_key:"myop_webcomponent_message"};var q=class extends L{constructor(t,n,r,i,a){super(t,r,a);this.container=r;this.customElement=i;s(this,"cleanupInspect",()=>{});s(this,"send",t=>{let n=h({},t),r=super.send(n),i=new CustomEvent(Ie.webcomponent_message_key,{detail:n});try{this.customElement.dispatchEvent(i)}catch(a){console.log("error while trying to dispatchEvent",a)}return r});s(this,"dispose",()=>{var t;super.dispose(),(t=this.customElement.parentNode)==null||t.removeChild(this.customElement)});this.element=i}inspect(){return this.cleanupInspect=he(this.id,"MyopWebComponent",0,this.container,this.customElement,this.componentDefinition),this.cleanupInspect}hide(){this.customElement.style.opacity="0",this.customElement.style.position="absolute",this.customElement.style.pointerEvents="none",this.customElement.style.visibility="hidden",this.customElement.style.height="0",this.customElement.style.width="0"}show(){this.customElement.style.opacity="1",this.customElement.style.position="unset",this.customElement.style.pointerEvents="all",this.customElement.style.visibility="visible",this.customElement.style.height="",this.customElement.style.width=""}};var at={},Ce=class extends P{constructor(){super(...arguments);s(this,"type",k.WebComponentLoader);s(this,"load",async(t,n,r,i)=>{let a=n.loader;at[a.url]?console.log("Module alreday loaded or in loading process"):at[a.url]=new Promise((c,m)=>{let l=a.url,f=document.createElement("script");f.type="module",f.src=l,f.onload=()=>{c()},f.onerror=()=>{m()},document.head.appendChild(f)}),await at[a.url],await ut(1);let p="myop-comp-".concat(M()),d=document.createElement(a.tag);return r.querySelector('[id^="myop-comp-"]')||(r.innerHTML=""),d.id=p,i!=null&&i.hidden&&(d.style.opacity="0",d.style.position="absolute",d.style.height="0",d.style.width="0",d.style.pointerEvents="none",d.style.visibility="hidden"),i!=null&&i._environment&&(d._myopEnvironment=i==null?void 0:i._environment),this.appendChild(r,d,i),new q(t,n,r,d,i)})}};var Dt="0.2.1";var I=class extends fe{constructor(t,n){super(t);this.context=n;s(this,"executor",t=>{if(t.destination){let n=t.destination;if(this.context[n].context){let r=(i,a)=>{this.messageToHost(E(h({},i),{source:t.destination?t.destination:t.source,destination:t.source?t.source:t.destination}),a)};return this.innerExecutor(t,this.context[n].context,r)}else debugger}else debugger})}};var D={id:"myop-id"};var R=(o,e)=>e.querySelectorAll("[".concat(D.id,"='").concat(o.refConfig.selector,"']"));var xe=class extends I{constructor(){super(...arguments);s(this,"messageType",g.BindClickMessage);s(this,"innerExecutor",(t,n,r)=>{let i=R(t.ref,n.shadowRoot),a=[];return i.forEach(p=>{let d=()=>{r(new j(t.handlerUniqueId))};p.addEventListener("click",d),a.push(()=>{p.removeEventListener("click",d)})}),()=>{a.forEach(p=>p())}})}};var be=class extends I{constructor(){super(...arguments);s(this,"messageType",g.ChangeTextMessage);s(this,"innerExecutor",(t,n)=>{R(t.ref,n.shadowRoot).forEach(i=>{i.textContent=t.content})})}};var we=class extends ue{constructor(t,n){super(t,n);this.container=t;this.shadowRoot=n}};var Te=class extends I{constructor(){super(...arguments);s(this,"innerExecutor",(t,n)=>{let r=n.shadowRoot.querySelectorAll("[".concat(D.id,"]")),i=[];r.forEach(a=>{let p=a.getAttribute(D.id);p&&i.push(new le(p,a.tagName,a.getBoundingClientRect(),a.offsetTop,a.offsetLeft))}),this.messageToHost(new te(t.handlerUniqueId,i))});s(this,"messageType",g.DetectMyopRefsMessage)}};var Se=class extends I{constructor(){super(...arguments);s(this,"messageType",g.SetAttributeMessage);s(this,"innerExecutor",(t,n)=>{R(t.ref,n.shadowRoot).forEach(i=>{i.setAttribute(t.name,t.value)})})}};var Re=class extends I{constructor(){super(...arguments);s(this,"messageType",g.AddEventListenerMessage);s(this,"innerExecutor",(t,n,r)=>{let i=R(t.ref,n.shadowRoot),a=[];return i.forEach(p=>{let d=c=>{r(new J(t.handlerUniqueId,H(c,t.serializableSkeleton)))};p.addEventListener(t.type,d),a.push(()=>{p.removeEventListener(t.type,d)})}),()=>{a.forEach(p=>p())}})}};var Ee=class extends I{constructor(){super(...arguments);s(this,"messageType",g.CreateRefComponentMessage);s(this,"innerExecutor",(t,n,r)=>{(async()=>{let a=n.shadowRoot.querySelectorAll("[".concat(D.id,"='").concat(t.refConfig.selector,"']"));if(a.length===1){let p=_.Instance(),d=p.components.find(f=>f.id===t.options.id);d&&d.dispose();let c=p.components.indexOf(d);c!==-1&&p.components.splice(c,1);let m=await p.loadComponent(t.nestedComponentConfig,a.item(0),t.options),l=[];Object.keys(m.refs).forEach(f=>{let u=m.refs[f];u=u.__nonProxied||u,u.componentDefinition&&l.push({refName:f,componentDefinitionId:u.componentDefinition.id})}),r(new U(t.handlerUniqueId,l))}else{console.error("CreateRefComponentMessageHandler - DOM element not found"),this.messageToHost(new U(t.handlerUniqueId,[],!0));debugger}})().then()})}};var Bt=(o,e,t)=>{let n=o.scriptInputs?o.scriptInputs:{};n.makeSerializable=H,n.send=e,n.rootRef=t,n.__scriptInputs=n;let i=new Function("return (".concat(o.script,")(...arguments)"))(n);e(i)};var ve=class extends I{constructor(){super(...arguments);s(this,"messageType",g.ExecuteScriptMessage);s(this,"innerExecutor",(t,n,r)=>{Bt(t,a=>{r(new G(t.handlerUniqueId,a))},n)})}};var Lt=o=>{if(!o)return null;if(o.tagName==="FORM"){let e=new FormData(o),t={formData:{},unmappedData:[]},n=o.querySelectorAll("input, select, textarea"),r=-1;return n.forEach(i=>{if(typeof i.value=="string"){let a=i.getAttribute(D.id),p=i.getAttribute("name"),d={id:i.id,name:p,value:Lt(i),required:i.required,validity:H(i.validity,!0),myopId:a};p?t.formData[p]?t.formData[p].value?t.unmappedData.push(d):(t.unmappedData.push(t.formData[p]),t.formData[p]=d):t.formData[p]=d:t.unmappedData.push(d)}}),t}return o.type==="checkbox"||o.type==="radio"?o.checked?o.value:null:o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.tagName==="SELECT"?o.value:o.isContentEditable?o.innerText||o.textContent:null},ke=class extends I{constructor(){super(...arguments);s(this,"messageType",g.GetElementValueMessage);s(this,"innerExecutor",(t,n,r)=>{R(t.ref,n.shadowRoot).forEach(a=>{r(new X(Lt(a)),t)})})}};var He=class extends I{constructor(){super(...arguments);s(this,"messageType",g.SetInnerHtml);s(this,"innerExecutor",(t,n)=>{R(t.ref,n.shadowRoot).forEach(i=>{i.innerHTML=t.content})})}};var ie=class extends ge{constructor(){super(...arguments);s(this,"alwaysPassEnvelopesToHost",!0);s(this,"connectedCallback",(t,n)=>{t.addEventListener(Ie.webcomponent_message_key,r=>{let i=r.data?r.data:r.detail;if(!i||!i.myop){debugger;throw new Error("recvied webcomponent_message with wrong type")}else{let a=i;if(this.handleIncomeMessages(r),a.messageType===g.InitMessage){let p=a.content.id;this.components[p].context=new we(t,n)}}}),setTimeout(()=>{this.messageToHost(new Z)},1)});s(this,"messageToHost",(t,n)=>{t.direction=w.up,!t.replayToHandler&&(n!=null&&n.handlerUniqueId)&&(t.replayToHandler=n.handlerUniqueId),window.myop.hostSDK.send(t)});s(this,"supportedHandlers",[new be(this.messageToHost,this.components),new He(this.messageToHost,this.components),new xe(this.messageToHost,this.components),new Te(this.messageToHost,this.components),new Se(this.messageToHost,this.components),new Re(this.messageToHost,this.components),new ve(this.messageToHost,this.components),new ke(this.messageToHost,this.components),new Ee(this.messageToHost,this.components)]);s(this,"init",()=>{})}};$("WebComponentSDK",ie);var _t=[],De,Pt=async()=>(De||(De=new ie,De.init()),De);function sn(o,e){return class extends HTMLElement{connectedCallback(){let t=e===K.open?"open":"closed",n=this.attachShadow({mode:t});Pt().then(r=>{r.connectedCallback(this,n),n.innerHTML=o})}}}var rn=(o,e,t)=>{customElements.define(o,sn(e,t)),console.log("define('".concat(o,"') was called, web component ready to use"))},an=o=>o.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/(\d+)/g,"-$1").toLowerCase(),pn=o=>(o=an(o),o.replace(/_/g,"-"));var Be=class extends P{constructor(){super(...arguments);s(this,"type",k.HTMLLoader);s(this,"load",async(t,n,r,i)=>{let a=n.loader,p="myop-comp-".concat(M()),d;if(a.shadowRootMode===K.localFrame){let c=M(),m="myop-comp-".concat(c),l=document.createElement("iframe");r.querySelector('[id^="myop-comp-"]')||(r.innerHTML=""),i!=null&&i.hidden&&(l.style.visibility="hidden"),l=this.appendChild(r,l,i),l.id=m,l.setAttribute("style","\n padding: 0;\n margin: 0;\n overflow: hidden;\n border: none;\n opacity: ".concat(i!=null&&i.hidden?"0":"1",";\n width: 100%;\n height: 100%;\n position: ").concat(i!=null&&i.hidden?"absolute":"static",";\n pointer-events: ").concat(i!=null&&i.hidden?"none":"all",";\n ")),r.appendChild(l);let f=l.contentDocument||l.contentWindow.document;f.open();let u=a.HTML;if(i!=null&&i._inspection){let O=new DOMParser().parseFromString(a.HTML,"text/html"),Oe=O.getElementById("myop_preview");Oe==null||Oe.removeAttribute("type");let dt=O.implementation.createHTMLDocument();dt.body.innerHTML="<script>\n const beforeKeysWindow = new Set(Object.keys(window));\n window.myopState = {\n beforeKeysWindow,\n };\n <\/script>";let ct=dt.body.firstChild;ct&&O.head&&O.head.insertBefore(O.importNode(ct,!0),O.head.firstChild),u=O.documentElement.outerHTML}f.writeln(u),f.writeln('<script src="'.concat(window.myop.__ROOT_SDK_PUBLIC_URL__,'"><\/script>\n <script>\n \n window.__federation__.__public_path__ = window.__federation__.__public_path__;\n \n const __myop_init = async () => {\n const {IframeSDK} = (await window.myop.rootSDK.getIframeModule());\n const sdk = new IframeSDK()\n sdk.init();\n }\n \n __myop_init().then();\n \n <\/script>')),f.close();let C=new V(t,n,r,l,i);return a.autoHeight&&(l.onload=()=>{C.observeSizeBasedOnDocumentElement()}),C}if(a.shadowRootMode===K.none){let c=document.createElement("template");c.innerHTML=a.HTML,d=c.content.firstElementChild,Pt().then(m=>{m.connectedCallback(d,d)})}else{let c=pn(t.name+n.id);_t.includes(c)||(rn(c,a.HTML,a.shadowRootMode),_t.push(c)),d=document.createElement(c)}return r.querySelector('[id^="myop-comp-"]')||(r.innerHTML=""),d.id=p,i!=null&&i.hidden&&(d.style.opacity="0",d.style.position="absolute",d.style.height="0",d.style.width="0",d.style.pointerEvents="none",d.style.visibility="hidden"),this.appendChild(r,d,i),new q(t,n,r,d,i)})}};var Ot=async o=>{try{let e=new URL(window.location.href),n=new URLSearchParams(e.search).get("myopOverride");if(n){let[r,...i]=Fe(n);switch(r){case"component":{let[a,p]=i,d=await z.Main.fetchComponent(a);if(d&&d.type.skins.find(m=>m.id===p))return d.instance.skinSelector={type:F.Dedicated,skin:{id:p}},d}break;default:{let[a,p]=Fe(n),c=(await z.Main.fetchFlow(a)).components.find(m=>m.type.id===o.type.id);if(c&&c.instance.skinSelector.type===F.Segmented&&c.instance.resolvedExperiences){let m=c.instance.resolvedExperiences.find(l=>l.id===p);if((m==null?void 0:m.type)===ye.Segment){let l=m,u=c.instance.skinSelector.segments.find(C=>C.segmentId===l.segment.id);if(u)return c.instance.skinSelector=u==null?void 0:u.skinSelector,c}}}break}}}finally{return null}};var Kt="https://cdn.myop.dev/sdk/next/myop_sdk.min.js",_=class{constructor(){s(this,"components2init",[]);s(this,"components",[]);s(this,"componentsLoaders",[]);s(this,"initiated",!1);s(this,"version",Dt);s(this,"type2InstanceCount",{});s(this,"assignId",e=>(this.type2InstanceCount[e.id]||(this.type2InstanceCount[e.id]=0),"".concat(e.id,"_").concat(++this.type2InstanceCount[e.id])));s(this,"inspected",!1);s(this,"inspect",()=>{this.inspected||(this.inspected=!0,this.components.forEach(e=>{e.inspect&&e.inspect()}))});s(this,"incomingMessageHandler",e=>{if(e.origin,document.location.origin,e.data.myop){if(e.data.direction!==w.up&&e.data.messageType!==g.EnvelopedMessage)return;let t=e.data;if(t.messageType===g.InitRequest){this.components2init.forEach(r=>{r.send(new A(r.id))});return}if(t.messageType===g.InitResponse){this.components2init=this.components2init.filter(i=>i.id!==t.content.id);let r=this.components.find(i=>{var a;return i.id===((a=t.content)==null?void 0:a.id)});r==null||r.setInitiated();return}if(t.messageType===g.EnvelopedMessage){let r=t,i=this.components.find(a=>a.id===r.destination);if(i){if(r.direction===w.down){r.message.messageType===S.name?i.onMessageReceived(r.message):(r.message.route=r.route,i.send(r.message));return}}else{let a=this.components.find(p=>p.id===r.message.destination);a&&a.send(r.message)}return}let n=this.components.find(r=>r.id===t.destination);if(!n){window.myop.IframeSDK&&window.myop.IframeSDK.messageToHost(t);return}if(n){if(n.onMessageReceived(t))return;window.myop.IframeSDK&&window.myop.IframeSDK.messageToHost(t)}}});s(this,"send",e=>{let t=new MessageEvent("",{data:e});this.incomingMessageHandler(t)});s(this,"init",e=>{if(this.initiated)throw new Error("hostSDK already initiated");let t=[new Me,new Ce,new Be];if(this.componentsLoaders=[...t],e){let n={};e.forEach(r=>{let i=new r(this.componentsLoaders);n[i.type]=i}),this.componentsLoaders.forEach(r=>{n[r.type]||(n[r.type]=r)}),this.componentsLoaders=Object.values(n)}window.addEventListener("message",this.incomingMessageHandler,!1),console.log("myop hostSDK initiated",document.location.href),this.initiated=!0});s(this,"_getSkinIdBySkinSelector",async(e,t=[],n)=>{var i;async function r(a,p){for(let d of a)if(await p(d))return d}switch(e.type){case"DedicatedSkin":case F.Dedicated:return((i=e.skin)==null?void 0:i.id)||e.skins[0].id;case F.Segmented:{let p=await r(e.segments,async d=>{if(d.segmentId==="Default")return!0;let c=t.find(u=>u.type===ye.Segment?u.segment.id===d.segmentId:!1);if(!c)throw new Error("experience not found");let l=c.segment,f=(n||{})[l.function];return f?await f():(console.warn("segmentId:".concat(d.segmentId,", ").concat(l.function," function not provided !")),!1)});if(p)return this._getSkinIdBySkinSelector(p.skinSelector,t);debugger}break;default:debugger}return""});s(this,"runSkinSelector",async(e,t)=>{let n=await this._getSkinIdBySkinSelector(e.instance.skinSelector,e.instance.resolvedExperiences,t);return e.type.skins.find(r=>r.id===n)});s(this,"loaderHooks");s(this,"loadComponent",async(e,t,n)=>{var m,l,f,u;if(!t){debugger;throw new Error("no container was found for this component")}let r=await Ot(e);r&&(e=r);let i=h(h({},(m=this.loaderHooks)!=null?m:{}),(l=n==null?void 0:n.hooks)!=null?l:{}),a=t;if(a.myop)if(a.component){e=h({},e),e.instance=h({},e.instance);let C=await this.runSkinSelector(e,i);if(!C)throw new Error("runSkinSelector failed to choose skin, check the provided config");return(f=n==null?void 0:n.hooks)!=null&&f.afterSkinSelected&&(C=await n.hooks.afterSkinSelected(h({},C))),e.instance.skinSelector={type:F.Dedicated,skin:C},n&&(n=h({},n),delete n.hooks),await rt(a,e,this.components,n)}else throw new Error("load component got a detached ref.");t=t;let p=await this.runSkinSelector(e,i);if(!p)throw new Error("runSkinSelector failed to choose skin, check the provided config");(u=n==null?void 0:n.hooks)!=null&&u.afterSkinSelected&&(p=await n.hooks.afterSkinSelected(h({},p)));let d=this.componentsLoaders.find(C=>C.type===p.loader.type);if(!d){debugger;throw new Error('no loader "'.concat(p.loader.type,'" was found for component'))}let c=await d.load(e.type,p,t,n);c.isInitiated||this.components2init.push(c),c.bind("onDispose",()=>(this.components=this.components.filter(C=>C!==c),this.components2init=this.components2init.filter(C=>C!==c),!0)),this.components.push(c),(!n||n.connectProps!==!1)&&(c=Ht(c,e.type.props,p));try{await it(c,e,this.components)}catch(C){throw C}return n!=null&&n.skipInit||await c.initiated(),c});s(this,"navigate",async(e,t,n)=>{if(e.parent)throw new Error("Navigating on remote ref components is not implemented yet");if(n!=null&&n.staged){let r=await this.loadComponent(t,e.container,h({hidden:!0,relative:{direction:"after",child:e.element}},n));return n.init&&await n.init(r),r.show(),e.dispose(),r}else{let r=e.element.nextSibling;return e.dispose(),this.loadComponent(t,e.container,h({relative:{direction:"before",child:r}},n))}})}};s(_,"Instance",()=>window.myop.hostSDK);window.myop||(window.myop={__ROOT_SDK_PUBLIC_URL__:Kt});if(!window.myop.hostSDK){let o=new _;o.init(),window.myop||(window.myop={__ROOT_SDK_PUBLIC_URL__:Kt}),window.myop.hostSDK=o}var Le=window.myop.hostSDK;$("hostSDK",Le);var Pe=class Pe{constructor(e="https://cloud.myop.dev"){this._baseUrl=e;s(this,"variants",{})}async fetchComponent(e,t){return this.variants[e]||(this.variants[e]=new Promise(async(n,r)=>{try{let a=await(await fetch("".concat(this._baseUrl,"/consume?id=").concat(e,"&env=").concat(t))).json();n(a.item)}catch(i){r(i)}})),await this.variants[e]}};s(Pe,"Main",new Pe);var _e=Pe,dn=(o,e)=>{let t=e||new _e;return{loadComponent:async(n,r,i)=>{let a=await t.fetchComponent(n,o);(!a.consume_variant||!a.consume_variant.length)&&console.warn('[Myop Warning] Component "'.concat(n,'" has no implementation for environment "').concat(o,'".'));let p={instance:{id:"auto",componentId:a.componentId,componentName:a.name,skinSelector:{type:"Dedicated",skin:{id:"skin_auto_v2_converted"}}},type:{id:a.id,name:a.name,description:a.description,props:[{id:"in_auto_v2_converted",name:"myop_init_interface",type:"any",behavior:{type:W.code}},{id:"out_auto_v2_converted",name:"myop_cta_handler",type:"any",behavior:{type:W.code}}],refs:[],skins:[{id:"skin_auto_v2_converted",name:"auto_v2_converted",description:"",loader:a.consume_variant[0].loader}],defaultSkin:0},name:a.name};return await Le.loadComponent(p,r,i)}}};$("MyopHelpers",pt);export{z as CloudRepository,et as ComponentConfig,Ye as SkinConfig,Qt as addClass,jt as applyStylesheet,Gt as applyStylesheetLink,Xt as changeSkinUrlByTokenizer,St as createIframeSkinByTokenizer,dn as enableV2,Yt as exec,Zt as removeClass,_e as v2_CloudRepository};
@@ -0,0 +1 @@
1
+ var it=Object.defineProperty,Bt=Object.defineProperties;var Lt=Object.getOwnPropertyDescriptors;var rt=Object.getOwnPropertySymbols;var _t=Object.prototype.hasOwnProperty,Pt=Object.prototype.propertyIsEnumerable;var Le=(o,n,e)=>n in o?it(o,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[n]=e,h=(o,n)=>{for(var e in n||(n={}))_t.call(n,e)&&Le(o,e,n[e]);if(rt)for(var e of rt(n))Pt.call(n,e)&&Le(o,e,n[e]);return o},E=(o,n)=>Bt(o,Lt(n));var Ot=(o,n)=>{for(var e in n)it(o,e,{get:n[e],enumerable:!0})};var i=(o,n,e)=>Le(o,typeof n!="symbol"?n+"":n,e);var re=class{constructor(n,e,t,s,r){this.myopId=n;this.htmlTagName=e;this.BoundingRect=t;this.offsetTop=s;this.offsetLeft=r;i(this,"type","MyopElementRef")}};var at=async o=>{if(typeof o=="function")o();else if(o instanceof Promise){let n=await o;typeof n=="function"&&n()}},_e=class{constructor(n){this.messageToHost=n}},ie=class extends _e{constructor(e,t){super(e);this.messageToHost=e;this.context=t}};var f={InitRequest:"InitRequest",InitResponse:"InitResponse",InitMessage:"InitMessage",DisposeMessage:"DisposeMessage",ChangeTextMessage:"ChangeTextMessage",BindClickMessage:"BindClickMessage",DetectMyopRefsMessage:"DetectMyopRefsMessage",ExecuteScriptMessage:"ExecuteScriptMessage",AddEventListenerMessage:"AddEventListenerMessage",SetAttributeMessage:"SetAttributeMessage",CreateRefComponentMessage:"CreateRefComponentMessage",EnvelopedMessage:"EnvelopedMessage",GetElementValueMessage:"GetElementValueMessage",GetAttributeMessage:"GetAttributeMessage",SetInnerHtml:"SetInnerHtml",ExecuteComponentMethod:"ExecuteComponentMethod",SetMutationObserverMessage:"SetMutationObserverMessage",SetResizeObserverMessage:"SetResizeObserverMessage",CleanupMessage:"CleanupMessage",In:{DetectedMyopRefsMessage:"DetectedMyopRefsMessage",ClickReplayMessage:"ClickReplayMessage",ExecuteScriptReplyMessage:"ExecuteScriptReplyMessage",EventListenerCallbackMessage:"EventListenerCallbackMessage",ElementValueReplayMessage:"ElementValueReplayMessage",GetAttributeReplayMessage:"GetAttributeReplayMessage",RefComponentCreatedMessage:"RefComponentCreatedMessage",EnvelopedMessage:"EnvelopedMessage",MutationObserverMessage:"MutationObserverMessage",CleanupReplayMessage:"CleanupReplayMessage",ResizeObserverMessage:"ResizeObserverMessage"}};var ae={};Ot(ae,{AddEventListenerMessage:()=>$e,BaseMyopMessage:()=>y,BindClickMessage:()=>Ke,ChangeTextMessage:()=>Fe,CleanupMessage:()=>Y,CleanupReplayMessage:()=>ee,ClickReplayMessage:()=>W,CreateRefComponentMessage:()=>X,CustomRefMessage:()=>O,DetectMyopRefsMessage:()=>Ne,DetectedMyopRefsMessage:()=>Z,DisposeMessage:()=>te,ElementValueReplayMessage:()=>j,EnvelopedMessage:()=>Q,EventListenerCallbackMessage:()=>q,ExecuteComponentMethod:()=>S,ExecuteScriptMessage:()=>w,ExecuteScriptReplyMessage:()=>V,GetAttributeMessage:()=>We,GetAttributeReplayMessage:()=>Ve,GetElementValueMessage:()=>Ue,InitMessage:()=>$,InitRequest:()=>J,InitResponse:()=>G,MessageDirection:()=>b,MutationObserverMessage:()=>je,MyopBindMessage:()=>x,MyopBindReplayMessage:()=>C,MyopElementMessage:()=>Oe,Ref:()=>D,RefComponentCreatedMessage:()=>A,ResizeObserverMessage:()=>Je,SetAttributeMessage:()=>Ae,SetInnerHtml:()=>ze,SetMutationObserverMessage:()=>qe,SetResizeObserverMessage:()=>Ge,stripFunction:()=>mt});var T=()=>"10000000-1000-4000-8000-100000000000".replace(/[018]/g,o=>(+o^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+o/4).toString(16));var Kt=o=>{let n=[...o].map(e=>e.toString(16).padStart(2,"0")).join("");return[n.slice(0,8),n.slice(8,12),n.slice(12,16),n.slice(16,20),n.slice(20)].join("-")};var Ft=o=>{let n=o.replace(/-/g,"+").replace(/_/g,"/");for(;n.length%4;)n+="=";let e=atob(n);return Uint8Array.from(e,t=>t.charCodeAt(0))};var Pe=o=>{let n=Ft(o);if(n.length%16!==0)throw new Error("Invalid input length");let e=[];for(let t=0;t<n.length;t+=16)e.push(Kt(n.slice(t,t+16)));return e};var pt=o=>new Promise(n=>setTimeout(n,o));var b=class{};i(b,"down","down"),i(b,"up","up");var y=class{constructor(){i(this,"id",T());i(this,"myop",!0);i(this,"content");i(this,"source");i(this,"destination");i(this,"route");i(this,"ref");i(this,"direction");i(this,"cleanable",!1)}static create(...n){return new this(...n)}isTypeof(n){return n.messageType===this.messageType}},Oe=class extends y{constructor(e){super();this.ref=e}},C=class extends y{constructor(e){super();this.replayToHandler=e}},x=class extends y{constructor(e){super();this.handler=e;i(this,"handlerUniqueId",T())}},D=class o{constructor(n,e){this.refConfig=n;this.component=e;i(this,"myop",!0);i(this,"__nonProxied");this.__nonProxied=E(h({},this),{component:null})}static create(n,e,t){let s=e;return s||(s={id:"",name:"",description:"",selectorType:"id-attribute",selector:n,behavior:{type:"code"}}),new o(s,t)}};var dt="ClickReplayMessage",Ke=class extends x{constructor(e,t){super(t);this.ref=e;i(this,"replyMessageKey",dt);i(this,"messageType","BindClickMessage");i(this,"cleanable",!0)}},W=class extends C{constructor(){super(...arguments);i(this,"messageType",dt)}};var Fe=class extends y{constructor(e,t){super();this.ref=e;i(this,"messageType","ChangeTextMessage");this.content=t}};var ct="ExecuteScriptReplyMessage",$t=/(?:function\s*\w*\s*\([^)]*\)\s*\{([\s\S]*?)\}|(\([^)]*\)\s*=>\s*\{([\s\S]*?)\}))\s*$/,At=/\(\s*[^)]+\s*\)\s*=>\s*(.+)/,mt=o=>{let n=o.match($t);if(n)return n[1]||n[3];{let e=o.match(At);if(e)return e[1].trim()}},w=class extends x{constructor(e,t=()=>{},s){super(t);this.scriptInputs=s;i(this,"replyMessageKey",ct);i(this,"messageType","ExecuteScriptMessage");i(this,"script","");this.script=e.toString(),this.content=e.toString(),this.content=mt(this.content)}};i(w,"replierKey","send"),i(w,"completeStreamKey","completeStream");var V=class extends C{constructor(e,t){super(e);this.replayToHandler=e;this.content=t;i(this,"messageType",ct)}};var O=class extends w{constructor(e,t,s=()=>{}){super(({rootRef:r,elementId:a,_script:p,__scriptInputs:d})=>{let c=(r.shadowRoot||r.container).querySelectorAll("[myop-id='".concat(a,"']"));return c.length?(d.ref=c[0],new Function("return (".concat(p,")(...arguments)"))(d)):null},s);this.scriptInputs=t;this.scriptInputs=E(h({},t),{_script:e.toString()})}};var lt="EventListenerCallbackMessage",$e=class extends x{constructor(e,t,s){super(s);this.ref=e;this.type=t;this.handler=s;i(this,"replyMessageKey",lt);i(this,"messageType","AddEventListenerMessage");i(this,"cleanable",!0);i(this,"serializableSkeleton",!1)}withSerializableSkeleton(e){return this.serializableSkeleton=e,this}},q=class extends C{constructor(e,t){super(e);this.replayToHandler=e;this.e=t;i(this,"messageType",lt);this.content={e:t}}};var Ae=class extends y{constructor(e,t,s){super();this.ref=e;this.name=t;this.value=s;i(this,"messageType","SetAttributeMessage")}};var ft="ElementValueReplayMessage",Ue=class extends x{constructor(e,t){super(t);this.ref=e;i(this,"replyMessageKey",ft);i(this,"messageType","GetElementValueMessage")}},j=class extends C{constructor(e){super();this.content=e;i(this,"messageType",ft)}};var ze=class extends y{constructor(e,t){super();this.ref=e;i(this,"messageType","SetInnerHtml");this.content=t}};var $=class extends y{constructor(e){super();i(this,"messageType","InitMessage");this.content={id:e}}isTypeof(e){return e.messageType===this.messageType}},G=class extends ${constructor(){super(...arguments);i(this,"messageType","InitResponse")}},J=class extends y{constructor(){super(...arguments);i(this,"messageType","InitRequest")}};var gt="RefComponentCreatedMessage",X=class extends x{constructor(e,t,s,r){super(r);this.refConfig=e;this.nestedComponentConfig=t;this.options=s;i(this,"replyMessageKey",gt);i(this,"messageType","CreateRefComponentMessage")}},A=class extends C{constructor(e,t,s){super(e);this.replayToHandler=e;this.nestedRefs=t;this.failed=s;i(this,"messageType",gt)}};var Q=class extends y{constructor(e,t){super();this.destination=e;this.message=t;i(this,"messageType","EnvelopedMessage");let s=t;this.route=[e,...s.route?s.route:[]]}};var ut="DetectedMyopRefsMessage",Ne=class extends x{constructor(){super(...arguments);i(this,"messageType","DetectMyopRefsMessage");i(this,"replyMessageKey",ut)}},Z=class extends C{constructor(e,t){super(e);this.replayToHandler=e;i(this,"messageType",ut);this.content=t}isTypeof(e){return e.messageType===this.messageType}};var yt="GetAttributeReplayMessage",We=class extends x{constructor(e,t,s){super(s);this.ref=e;this.name=t;i(this,"replyMessageKey",yt);i(this,"messageType","GetAttributeMessage")}},Ve=class extends C{constructor(e){super();this.content=e;i(this,"messageType",yt)}};var S=class extends y{constructor(e){super();this.method=e;i(this,"messageType","ExecuteComponentMethod")}};var qe=class extends y{constructor(){super(...arguments);i(this,"messageType","SetMutationObserverMessage")}},je=class extends y{constructor(){super(...arguments);i(this,"messageType","MutationObserverMessage")}};var ht="CleanupReplayMessage",Y=class extends x{constructor(e,t){super(t);this.cleanupForMessageId=e;i(this,"replyMessageKey",ht);i(this,"messageType","CleanupMessage")}},ee=class extends C{constructor(e){super();this.customCleanup=e;i(this,"messageType",ht)}};var te=class extends y{constructor(){super(...arguments);i(this,"messageType","DisposeMessage")}};var Ge=class extends y{constructor(){super(...arguments);i(this,"cleanable",!0);i(this,"messageType","SetResizeObserverMessage")}},Je=class extends y{constructor(){super(...arguments);i(this,"messageType","ResizeObserverMessage")}};var Xe=class{constructor(n,e){this.id=n;this.context=e;i(this,"send",n=>{})}},pe=class{constructor(){i(this,"messageToHandleAfterInit",[]);i(this,"components",{});i(this,"alwaysPassEnvelopesToHost",!1);i(this,"messageCleanupCache",{})}handleIncomeMessages(n){let e=n.data?n.data:n.detail;if(!(!e||!e.myop)){let t=e;if(t.direction!==b.down)return;if(t.messageType===f.DisposeMessage){t.destination&&delete this.components[t.destination];return}if(t.messageType===f.InitMessage){let s=t.content.id;if(this.components[s])return;this.components[s]=new Xe(s),this.messageToHost(new G(s));return}if(t.messageType===f.EnvelopedMessage){let s=t,r=s.message;if(t=r,this.alwaysPassEnvelopesToHost||this.components[t.destination]){let a=myop.hostSDK.components.find(d=>d.id===r.destination);if(a){a.send(r);return}let p=myop.hostSDK.components.find(d=>d.id===s.destination);if(p){p.send(r);return}}else return}if(t.messageType){if(t.messageType===f.CleanupMessage){let r=t,a=this.messageCleanupCache[r.cleanupForMessageId],p=new ee(!!a);p.destination=t.destination,a?(delete this.messageCleanupCache[r.cleanupForMessageId],at(a).then(()=>{this.messageToHost(p,r)}).catch(()=>{})):this.messageToHost(p,r);return}let s=!1;this.supportedHandlers.forEach(r=>{if(r.messageType===t.messageType){s=!0;let a=r.executor(t);if(t.cleanable&&a&&(this.messageCleanupCache[t.id]=a),a&&!t.cleanable)throw new Error("Cleanup handler generated for non-cleanable message. \nmessageType - ".concat(t.messageType,", handler executor was - ").concat(r.executor,"\n\nPlease review the message definition object & message handler.\nTo ensure cleanup properly set 'cleanable' true at message definition and return IMessageExecutorCleanup from your handlers."));if(!a&&t.cleanable)throw new Error("No cleanup handler generated for a cleanable message. \nmessageType - ".concat(t.messageType,", handler executor was - ").concat(r.executor,"\n\nPlease review the message definition object & message handler.\nTo ensure cleanup properly set 'cleanable' true at message definition and return IMessageExecutorCleanup from your handlers."))}})}else console.log("unsupported message type")}}};var v={IframeLoader:"IframeLoader",WebComponentLoader:"WebComponentLoader",HTMLLoader:"HTMLLoader",MinimizedLoader:"MinimizedLoader"};var K={open:"open",closed:"closed",none:"none",localFrame:"localFrame"};var ce={message:"message",code:"code"},U=class{};i(U,"code","code"),i(U,"component","component");var F={Segmented:"Segmented",Dedicated:"Dedicated",Default:"Default"},me={Segment:"Segment",Promo:"Promo",AB:"AB"},de=class{constructor(n,e){this.container=n;this.shadowRoot=e;i(this,"getRootDiv",()=>(this.shadowRoot||this.container).querySelector("div"));i(this,"getRoot",()=>this.shadowRoot||this.container)}};var le={webcomponent_message_key:"myop_webcomponent_message"};var M=class extends ie{constructor(e,t){super(e);this.context=t;i(this,"executor",e=>{if(e.destination){let t=e.destination;if(this.context[t].context){let s=(r,a)=>{this.messageToHost(E(h({},r),{source:e.destination?e.destination:e.source,destination:e.source?e.source:e.destination}),a)};return this.innerExecutor(e,this.context[t].context,s)}else debugger}else debugger})}};var k={id:"myop-id"};var R=(o,n)=>n.querySelectorAll("[".concat(k.id,"='").concat(o.refConfig.selector,"']"));var fe=class extends M{constructor(){super(...arguments);i(this,"messageType",f.BindClickMessage);i(this,"innerExecutor",(e,t,s)=>{let r=R(e.ref,t.shadowRoot),a=[];return r.forEach(p=>{let d=()=>{s(new W(e.handlerUniqueId))};p.addEventListener("click",d),a.push(()=>{p.removeEventListener("click",d)})}),()=>{a.forEach(p=>p())}})}};var ge=class extends M{constructor(){super(...arguments);i(this,"messageType",f.ChangeTextMessage);i(this,"innerExecutor",(e,t)=>{R(e.ref,t.shadowRoot).forEach(r=>{r.textContent=e.content})})}};var ue=class extends de{constructor(e,t){super(e,t);this.container=e;this.shadowRoot=t}};var ye=class extends M{constructor(){super(...arguments);i(this,"innerExecutor",(e,t)=>{let s=t.shadowRoot.querySelectorAll("[".concat(k.id,"]")),r=[];s.forEach(a=>{let p=a.getAttribute(k.id);p&&r.push(new re(p,a.tagName,a.getBoundingClientRect(),a.offsetTop,a.offsetLeft))}),this.messageToHost(new Z(e.handlerUniqueId,r))});i(this,"messageType",f.DetectMyopRefsMessage)}};var he="__federation__",Mt="onLoad";var Me=(o,n)=>{window[he]&&window[he][o]&&window[he][o][Mt]&&window[he][o][Mt]({[o]:n})};var Ie=class extends M{constructor(){super(...arguments);i(this,"messageType",f.SetAttributeMessage);i(this,"innerExecutor",(e,t)=>{R(e.ref,t.shadowRoot).forEach(r=>{r.setAttribute(e.name,e.value)})})}};var Qe=o=>o!==Object(o),Ut=o=>typeof o=="function",Ze=o=>{if(Qe(o))return!0;if(Ut(o)||Object.getPrototypeOf(o))return!1;for(let n in o){let e=o[n];if(typeof e=="object"){if(!Ze(e))return!1}else{if(Qe(e))continue;return!1}}return!0},H=(o,n={},e=!0,t=new WeakMap)=>{if(Qe(o))return o;if(Array.isArray(o)){if(t.has(o))return t.get(o);let s=[];t.set(o,s);for(let r=0;r<o.length;r++){let a=o[r];s[r]=H(a,n,e,t)}return s}if(o!==null&&typeof o=="object"){if(t.has(o))return t.get(o);let s={};t.set(o,s);for(let r in o){let a=typeof n=="boolean"?n:n[r];a&&(a===!0?(e?o[r]!==void 0:o[r])&&(s[r]=H(o[r],!0,e,t)):typeof a=="object"&&(s[r]=H(o[r],a,e,t)))}return s}return{}};var Ce=class extends M{constructor(){super(...arguments);i(this,"messageType",f.AddEventListenerMessage);i(this,"innerExecutor",(e,t,s)=>{let r=R(e.ref,t.shadowRoot),a=[];return r.forEach(p=>{let d=c=>{s(new q(e.handlerUniqueId,H(c,e.serializableSkeleton)))};p.addEventListener(e.type,d),a.push(()=>{p.removeEventListener(e.type,d)})}),()=>{a.forEach(p=>p())}})}};var B=class{constructor(n,e,t){this.componentDefinition=n;this.container=e;i(this,"id","");i(this,"messageHandlers",{});i(this,"element");i(this,"_markedForDisposed",!1);i(this,"bind",(n,e)=>{this.messageHandlers[n]||(this.messageHandlers[n]=[]),this.messageHandlers[n].includes(e)||this.messageHandlers[n].push(e)});i(this,"bindWhen",(n,e,t)=>{if(!t)throw new Error("can't use component.bindWhen without an handler");this.messageHandlers[n]||(this.messageHandlers[n]=[]);let s=this.messageHandlers[n],r=a=>e(a)?(t(a),!0):!1;return s.push(r),()=>{let a=s.indexOf(r);a>-1&&s.splice(a,1)}});i(this,"setInitiated",()=>{this.isInitiated=!0,this._whenInitiatedResolve&&this._whenInitiatedResolve()});i(this,"isInitiated",!1);i(this,"_whenInitiatedResolve");i(this,"_whenInitiatedReject");i(this,"_whenInitiated",new Promise((n,e)=>{this._whenInitiatedResolve=n,this._whenInitiatedReject=e}));i(this,"initiated",()=>this._whenInitiated);i(this,"props",{});i(this,"refs",{});this.id=(t==null?void 0:t.id)||L.Instance().assignId(n);let s=t!=null&&t.timeout?t==null?void 0:t.timeout:5*1e3;setTimeout(()=>{!this.isInitiated&&this._whenInitiatedReject&&!this._markedForDisposed&&this._whenInitiatedReject("timeout_".concat(s," ").concat(this.id))},s),this.initiated().then(()=>{window.myop.hostSDK.inspected&&this.inspect()})}get markedForDisposed(){return this._markedForDisposed}set markedForDisposed(n){if(this._markedForDisposed)throw new Error("InvalidOperationException: The component is already in the process of being disposed. Dispose operation cannot be performed again until the current disposal process is complete.");this._markedForDisposed=n}onMessageReceived(n){if(n.messageType===f.ExecuteComponentMethod){let t=n;return this[t.method]?this[t.method](t.content):console.log("method not found ".concat(t.method," on component"),this),!0}let e=this.messageHandlers[n.messageType];if(e&&e.length){let t=!1;return e.forEach(s=>{t=t||s(n)}),t}return!1}sendCleanupMessage(n){n.source=this.id,n.destination=this.id,n.direction=b.down;let e=this.bindWhen(n.replyMessageKey,s=>s.replayToHandler===n.handlerUniqueId,s=>{n.handler(s),e()}),t=n.handler;delete n.handler,this.send(n),n.handler=t}send(n){n.source||(n.source=this.id),n.destination||(n.destination=this.id),n.direction=b.down;let e;if(n.handler){let t=n;e=this.bindWhen(t.replyMessageKey,s=>s.replayToHandler===t.handlerUniqueId,t.handler),delete n.handler}return n.ref&&(n.ref=n.ref.__nonProxied||n.ref),n.cleanable?()=>{this.sendCleanupMessage(new Y(n.id,t=>{})),e&&e()}:()=>{}}dispose(){if(this.markedForDisposed=!0,!this.isInitiated)return;console.log("disposing component",this.id),this.send(new te);let n=this.messageHandlers.onDispose;n&&n.forEach(e=>{e(null)}),this.messageHandlers={},this.id+="_disposed",this.isInitiated=!1}};var It={notSerializableRefCall:(o,n)=>{throw new Error("\nThe input provided to '".concat(o.toString(),"' is not serializable. Serialization is required to ensure that the data can be safely transferred to the skin implementation. \nThe following types of data are considered non-serializable and cannot be processed:\n\n- Functions\n- DOM elements\n- Class instances\n- Circular references\n- Symbols\n- BigInt values\n\nIn the following execution we detected :\n~~~~~~~~\n").concat(n," \n~~~~~~~~\nas not serializable.\n\nTo resolve this issue, please ensure that all inputs passed to '").concat(o.toString(),"' are in a serializable format.\nThis typically includes primitive types (strings, numbers, booleans), arrays, and plain objects. \nIf you need to include complex data types, consider converting them to a serializable structure before passing them to the function.\nOr use Myop message that support it: CustomRefMessage, AddEventListenerMessage or ExecuteScriptMessage.\n\nSuggested Fix:\n1. Remove or replace non-serializable values from your input.\n2. If using objects, ensure they do not contain any functions or circular references.\n3. Convert any class instances to plain objects or JSON-compatible formats.\n4. Use dedicated Myop message.\n\nFor more details on serialization and Myop message examples, refer to https://docs.myop.dev.\n\n"))}};var ne=class extends B{constructor(e,t,s){super(e,t.container,s);this.componentDefinition=e;this.parent=t;i(this,"send",e=>{let t=e.handler,s=super.send(e);return this.parent.send(new Q(this.id,e)),e.handler=t,s});i(this,"dispose",()=>{this.isInitiated&&this.send(new S("dispose")),super.dispose()})}hide(){this.send(new S("hide"))}show(){this.send(new S("show"))}inspect(){return this.send(new S("inspect"))}setHeightBasedOnDocumentElement(){this.send(new S("setHeightBasedOnDocumentElement"))}setHeightBasedOnScrollHeight(){this.send(new S("setHeightBasedOnScrollHeight"))}onMessageReceived(e){return super.onMessageReceived(e)}};var zt=(o,n,e)=>{let t=document.createElement("a");return t.textContent=o,t.style.position="relative",t.style.padding="0 5px",t.style.fontSize="14px",t.style.top="0",t.style.top="".concat(n,"px"),t.style.transform="translateX(-50%)",t.target="_blank",t.href="https://dashboard.myop.dev/dashboard/component/".concat(e.id),t},xe=(o,n,e,t,s,r)=>{let a=zt("".concat(r.name," : ").concat(n),e,r);return t.insertBefore(a,s),s.style.border="1px solid #007BFF",s.style.display="block",()=>{s.style.border="unset",t.removeChild(a)}},Ct=(o,n,e)=>o?!1:(console.error("Error: Undefined Prop\n\nIt looks like you've tried to use a prop that hasn't been defined.\nPlease check the prop name for any typos or ensure that it is properly defined in the component's prop list.\n\n"+"Prop Name: ".concat(n,"\n")+"Component: ".concat(e.componentDefinition.name,", ID: ").concat(e.componentDefinition.id,"\n\n")+"For more information, refer to the component page https://dashboard.myop.dev/dashboard/component/".concat(e.componentDefinition.id," or consult the developer guide.")),!0),xt=(o,n,e)=>{console.error("Error: Code Prop Not Supported\n\nCurrently, code props are only supported in local frame components.\n\u26A0\uFE0F This is a work in progress feature \u2014 code props will be supported in upcoming versions.\n\nIn the meantime, you can use message props.\n\n"+"Prop Name: ".concat(n,"\n")+"Component: ".concat(e.componentDefinition.name,", ID: ").concat(e.componentDefinition.id,"\n\n")+"For more information, refer to the component page https://dashboard.myop.dev/dashboard/component/".concat(e.componentDefinition.id," or consult the developer guide."))},bt=(o,n,e)=>{let t=n.reduce((r,a)=>E(h({},r),{[a.name]:h({},a)}),{}),s={get:(r,a)=>{let p=t[a];if(Ct(p,a,o))return!1;if(p.behavior.type===ce.code){if(e.loader.type===v.HTMLLoader&&e.loader.shadowRootMode===K.localFrame){let c=p.behavior;return o.element.contentWindow[c.remap||a]}return xt(p,a,o),!1}return p.mode==="output"?new Promise(d=>{let c=[];p.behavior.ref&&c.push(D.create(p.behavior.ref)),c.push(l=>{d(l)}),p.behavior.params&&c.push(...p.behavior.params);let m=ae[p.behavior.message];o.send(new m(...c))}):null},set:(r,a,p)=>{let d=t[a];if(Ct(d,a,o))return!1;if(d.behavior.type===ce.code){if(e.loader.type===v.HTMLLoader&&e.loader.shadowRootMode===K.localFrame){let m=d.behavior;return o.element.contentWindow[m.remap||a]=p,!0}return xt(d,a,o),!1}else if(d.mode==="input")if(d.behavior.type==="message"){let c=[];d.behavior.ref&&c.push(D.create(d.behavior.ref)),c.push(p),d.behavior.params&&c.push(...d.behavior.params);let m=ae[d.behavior.message];return o.send(new m(...c)),!0}else throw new Error("Error: Unsupported Behavior\n\nThe 'behavior' field provided is not supported.\n"+"Component: ".concat(o.componentDefinition.name,", ID: ").concat(o.componentDefinition.id,"\n\n")+"Prop Name: ".concat(a,"\n")+"Behavior Field: ".concat(d.behavior.type,"\n\n")+"Check the documentation for valid behavior options.");return!1}};return o.props={},o.props=new Proxy(o.props,s),o},Nt=(o,n)=>new Proxy(o,{get(e,t){return e[t]?e[t]:(...r)=>new Promise(a=>{r.forEach(p=>{Ze(p)||It.notSerializableRefCall(t,p)}),n.send(new O(({ref:p,propName:d,functionArgs:c,makeSerializable:m})=>{if(p){let l=p[d];return m(typeof l=="function"?p[d](...c):l,!0)}return null},{elementId:e.refConfig.selector,propName:t,functionArgs:r},p=>{a(p.content)}))})},set(e,t,s){return n.send(new O(({ref:r,propName:a,propValue:p})=>{r&&(r[a]=p)},{elementId:e.refConfig.selector,propValue:s,propName:t},r=>{})),!0}}),Ye=async(o,n,e,t)=>{let s=o.component;if(!s)throw new Error("cant createRefComponent with detached ref");return new Promise(async(r,a)=>{let p=new ne(n.type,s,t);e.push(p),await s.initiated();let d=setTimeout(()=>{a("timeout")},5e3);s.send(new X(o.refConfig,n,E(h({},t||{}),{id:p.id,_hasParent:!0}),async c=>{if(clearTimeout(d),c.failed){a("CreateRefComponentMessage failed");return}let m=e.find(l=>l.id==p.id);if(m!==p){s.refs[o.refConfig.name]=m,r(m);return}else p.setInitiated(),s.refs[o.refConfig.name]=p;c.nestedRefs.forEach(l=>{let g=n.instance.resolvedNestedComponents.find(I=>I.type.id===l.componentDefinitionId).type,u=new ne(g,p);u.setInitiated(),p.refs[l.refName]=u,e.push(u)});try{await et(p,n,e,!0),s.setHeightBasedOnScrollHeight&&s.setHeightBasedOnScrollHeight(),r(p)}catch(l){a(l)}}))})},et=async(o,n,e,t=!1)=>{o.refs||(o.refs={});let s=Object.values(o.componentDefinition.refs).map(r=>new Promise(async(a,p)=>{var d;if(r.behavior.type==U.component){if(t){a();return}let c=r.behavior.componentId;c||(c=r.behavior.instance.componentId);let m=(d=n.instance.resolvedNestedComponents)==null?void 0:d.find(g=>g.type.id===c);if(!m)throw new Error("componentConfig provided without nestedComponentConfig check the config object");let l=D.create("",r,o);try{let g=await Ye(l,m,e);o.refs[r.name]=g,a()}catch(g){p(g)}}else try{let c=D.create("",r,o);o.refs[r.name]=Nt(c,o),a()}catch(c){}}));try{await Promise.all(s)}catch(r){throw r}};var z=class extends B{constructor(e,t,s,r,a){super(e,s,a);this.componentConfig=e;this.container=s;this.IframeElement=r;i(this,"cleanupInspect");i(this,"setHeightBasedOnDocumentElement",()=>{let e=this.send(new w(()=>window.document.documentElement.scrollHeight,t=>{this.IframeElement.style.height="".concat(t.content,"px"),e()}))});i(this,"observeSizeBasedOnDocumentElement",()=>this.send(new w(({send:t})=>{let{height:s,width:r}=document.documentElement.getBoundingClientRect(),a=new ResizeObserver(()=>{let{height:p,width:d}=document.documentElement.getBoundingClientRect();t({height:p,width:d})});return a.observe(document.documentElement),a.observe(document.body),{height:s,width:r}},t=>{this.IframeElement.style.width="".concat(t.content.width,"px"),this.IframeElement.style.height="".concat(t.content.height,"px")})));i(this,"setSizeBasedOnDocumentElement",()=>{let e=this.send(new w(()=>{let{height:t,width:s}=document.documentElement.getBoundingClientRect();return{height:t,width:s}},t=>{this.IframeElement.style.width="".concat(t.content.width,"px"),this.IframeElement.style.height="".concat(t.content.height,"px"),e()}))});i(this,"setHeightBasedOnScrollHeight",()=>{let e=this.send(new w(()=>{let s=0;return s++,s--,Math.max(Math.max(window.document.body.clientHeight,window.document.body.scrollHeight),window.document.body.offsetHeight)+s+"px"},t=>{this.IframeElement.style.height=t.content,e()}))});i(this,"send",e=>{var r,a;let t=h({},e);if(t.messageType===f.ExecuteComponentMethod)return this[t.method](),()=>{};t.direction=b.down;let s=super.send(t);return(a=(r=this.IframeElement)==null?void 0:r.contentWindow)==null||a.postMessage(t,"*"),s});i(this,"dispose",()=>{this.cleanupInspect&&this.cleanupInspect(),super.dispose(),this.IframeElement.parentNode.removeChild(this.IframeElement)});t.loader.autoHeight&&this.initiated().then(()=>{this.setHeightBasedOnScrollHeight()}),this.element=this.IframeElement}inspect(){return this.cleanupInspect?this.cleanupInspect:(this.cleanupInspect=xe(this.id,"MyopIframeComponent",10,this.container,this.IframeElement,this.componentDefinition),()=>{this.cleanupInspect(),this.cleanupInspect=void 0})}hide(){this.IframeElement.style.opacity="0",this.IframeElement.style.position="absolute",this.IframeElement.style.pointerEvents="none",this.IframeElement.style.visibility="hidden"}show(){this.IframeElement.style.opacity="1",this.IframeElement.style.position="unset",this.IframeElement.style.pointerEvents="all",this.IframeElement.style.visibility="visible"}onMessageReceived(e){return e.messageType===f.In.MutationObserverMessage||e.messageType===f.In.ResizeObserverMessage?(this.setHeightBasedOnScrollHeight(),!0):super.onMessageReceived(e)}};var _=class{constructor(){i(this,"appendChild",(n,e,t)=>{var s;if(t!=null&&t.relative){if(t.relative.direction==="before")return n.insertBefore(e,t.relative.child);if(t.relative.direction==="after"){let r=(s=t.relative.child)==null?void 0:s.nextSibling;return n.insertBefore(e,r||null)}}else return n.appendChild(e)})}};var Wt=(o,n,e)=>{let t=new URL(o);return t.searchParams.append(n,e),t.toString()},be=class extends _{constructor(){super(...arguments);i(this,"type",v.IframeLoader);i(this,"load",async(e,t,s,r)=>{let a,p=t.loader;if((s==null?void 0:s.nodeName)==="IFRAME")console.log("needs to load into an exsisting Iframe...",p.url,s),a=s,a.src=p.url;else{let d=T(),c="myop-comp-".concat(d);a=document.createElement("iframe"),s.querySelector('[id^="myop-comp-"]')||(s.innerHTML=""),r!=null&&r.hidden&&(a.style.visibility="hidden"),a=this.appendChild(s,a,r);let m=t.loader.url;r!=null&&r._hasParent&&(m=Wt(m,"_myop-comp",d));let l="";r!=null&&r.elementAttributes&&(l=Object.entries(r==null?void 0:r.elementAttributes).map(([g,u])=>u===""||u===null||u===void 0?g:"".concat(g,'="').concat(String(u),'"')).join(" ")),a.outerHTML='<iframe \n id="'.concat(c,'"\n style="\n padding: 0;\n margin: 0;\n height: ').concat(p.autoHeight||!p.height?"":p.height,"; \n width : 100%;\n overflow: hidden;\n border: none;\n opacity: ").concat(r!=null&&r.hidden?"0":"1",";\n position: ").concat(r!=null&&r.hidden?"absolute":"static",";\n pointer-events: ").concat(r!=null&&r.hidden?"none":"all",';\n "\n src="').concat(m,'"\n ').concat(l,"\n ></iframe>"),a=s.querySelector("#".concat(c))}return new z(e,t,s,a,r)})}};var N=class extends B{constructor(e,t,s,r,a){super(e,s,a);this.container=s;this.customElement=r;i(this,"cleanupInspect",()=>{});i(this,"send",e=>{let t=h({},e),s=super.send(t),r=new CustomEvent(le.webcomponent_message_key,{detail:t});try{this.customElement.dispatchEvent(r)}catch(a){console.log("error while trying to dispatchEvent",a)}return s});i(this,"dispose",()=>{var e;super.dispose(),(e=this.customElement.parentNode)==null||e.removeChild(this.customElement)});this.element=r}inspect(){return this.cleanupInspect=xe(this.id,"MyopWebComponent",0,this.container,this.customElement,this.componentDefinition),this.cleanupInspect}hide(){this.customElement.style.opacity="0",this.customElement.style.position="absolute",this.customElement.style.pointerEvents="none",this.customElement.style.visibility="hidden",this.customElement.style.height="0",this.customElement.style.width="0"}show(){this.customElement.style.opacity="1",this.customElement.style.position="unset",this.customElement.style.pointerEvents="all",this.customElement.style.visibility="visible",this.customElement.style.height="",this.customElement.style.width=""}};var tt={},we=class extends _{constructor(){super(...arguments);i(this,"type",v.WebComponentLoader);i(this,"load",async(e,t,s,r)=>{let a=t.loader;tt[a.url]?console.log("Module alreday loaded or in loading process"):tt[a.url]=new Promise((c,m)=>{let l=a.url,g=document.createElement("script");g.type="module",g.src=l,g.onload=()=>{c()},g.onerror=()=>{m()},document.head.appendChild(g)}),await tt[a.url],await pt(1);let p="myop-comp-".concat(T()),d=document.createElement(a.tag);return s.querySelector('[id^="myop-comp-"]')||(s.innerHTML=""),d.id=p,r!=null&&r.hidden&&(d.style.opacity="0",d.style.position="absolute",d.style.height="0",d.style.width="0",d.style.pointerEvents="none",d.style.visibility="hidden"),r!=null&&r._environment&&(d._myopEnvironment=r==null?void 0:r._environment),this.appendChild(s,d,r),new N(e,t,s,d,r)})}};var wt="0.2.1";var Tt=[],Te,St=async()=>(Te||(Te=new oe,Te.init()),Te);function Vt(o,n){return class extends HTMLElement{connectedCallback(){let e=n===K.open?"open":"closed",t=this.attachShadow({mode:e});St().then(s=>{s.connectedCallback(this,t),t.innerHTML=o})}}}var qt=(o,n,e)=>{customElements.define(o,Vt(n,e)),console.log("define('".concat(o,"') was called, web component ready to use"))},jt=o=>o.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/(\d+)/g,"-$1").toLowerCase(),Gt=o=>(o=jt(o),o.replace(/_/g,"-"));var Se=class extends _{constructor(){super(...arguments);i(this,"type",v.HTMLLoader);i(this,"load",async(e,t,s,r)=>{let a=t.loader,p="myop-comp-".concat(T()),d;if(a.shadowRootMode===K.localFrame){let c=T(),m="myop-comp-".concat(c),l=document.createElement("iframe");s.querySelector('[id^="myop-comp-"]')||(s.innerHTML=""),r!=null&&r.hidden&&(l.style.visibility="hidden"),l=this.appendChild(s,l,r),l.id=m,l.setAttribute("style","\n padding: 0;\n margin: 0;\n overflow: hidden;\n border: none;\n opacity: ".concat(r!=null&&r.hidden?"0":"1",";\n width: 100%;\n height: 100%;\n position: ").concat(r!=null&&r.hidden?"absolute":"static",";\n pointer-events: ").concat(r!=null&&r.hidden?"none":"all",";\n ")),s.appendChild(l);let g=l.contentDocument||l.contentWindow.document;g.open();let u=a.HTML;if(r!=null&&r._inspection){let P=new DOMParser().parseFromString(a.HTML,"text/html"),Be=P.getElementById("myop_preview");Be==null||Be.removeAttribute("type");let ot=P.implementation.createHTMLDocument();ot.body.innerHTML="<script>\n const beforeKeysWindow = new Set(Object.keys(window));\n window.myopState = {\n beforeKeysWindow,\n };\n <\/script>";let st=ot.body.firstChild;st&&P.head&&P.head.insertBefore(P.importNode(st,!0),P.head.firstChild),u=P.documentElement.outerHTML}g.writeln(u),g.writeln('<script src="'.concat(window.myop.__ROOT_SDK_PUBLIC_URL__,'"><\/script>\n <script>\n \n window.__federation__.__public_path__ = window.__federation__.__public_path__;\n \n const __myop_init = async () => {\n const {IframeSDK} = (await window.myop.rootSDK.getIframeModule());\n const sdk = new IframeSDK()\n sdk.init();\n }\n \n __myop_init().then();\n \n <\/script>')),g.close();let I=new z(e,t,s,l,r);return a.autoHeight&&(l.onload=()=>{I.observeSizeBasedOnDocumentElement()}),I}if(a.shadowRootMode===K.none){let c=document.createElement("template");c.innerHTML=a.HTML,d=c.content.firstElementChild,St().then(m=>{m.connectedCallback(d,d)})}else{let c=Gt(e.name+t.id);Tt.includes(c)||(qt(c,a.HTML,a.shadowRootMode),Tt.push(c)),d=document.createElement(c)}return s.querySelector('[id^="myop-comp-"]')||(s.innerHTML=""),d.id=p,r!=null&&r.hidden&&(d.style.opacity="0",d.style.position="absolute",d.style.height="0",d.style.width="0",d.style.pointerEvents="none",d.style.visibility="hidden"),this.appendChild(s,d,r),new N(e,t,s,d,r)})}};var Re=class Re{constructor(n="https://cloud.myop.dev"){this._baseUrl=n;i(this,"userFlows",{})}async fetchComponent(n,e){return e?(await this.fetchFlow(e)).components.find(s=>s.type.id===n):(await this.fetchAutoFlow(n)).components[0]}async fetchAutoFlow(n){return this.userFlows[n]||(this.userFlows[n]=new Promise(async(e,t)=>{try{let r=await(await fetch("".concat(this._baseUrl,"/flow?id=").concat(n,"&auto=true"))).json();e(r.item)}catch(s){t(s)}})),await this.userFlows[n]}async fetchFlow(n){return this.userFlows[n]||(this.userFlows[n]=new Promise(async(e,t)=>{try{let r=await(await fetch("".concat(this._baseUrl,"/flow?id=").concat(n,"&resolve=components"))).json();e(r.item)}catch(s){t(s)}})),await this.userFlows[n]}};i(Re,"Main",new Re);var se=Re;var Ee=class Ee{constructor(n="https://cloud.myop.dev"){this._baseUrl=n;i(this,"variants",{})}async fetchComponent(n,e){return this.variants[n]||(this.variants[n]=new Promise(async(t,s)=>{try{let a=await(await fetch("".concat(this._baseUrl,"/consume?id=").concat(n,"&env=").concat(e))).json();t(a.item)}catch(r){s(r)}})),await this.variants[n]}};i(Ee,"Main",new Ee);var Rt=Ee;var Et=async o=>{try{let n=new URL(window.location.href),t=new URLSearchParams(n.search).get("myopOverride");if(t){let[s,...r]=Pe(t);switch(s){case"component":{let[a,p]=r,d=await se.Main.fetchComponent(a);if(d&&d.type.skins.find(m=>m.id===p))return d.instance.skinSelector={type:F.Dedicated,skin:{id:p}},d}break;default:{let[a,p]=Pe(t),c=(await se.Main.fetchFlow(a)).components.find(m=>m.type.id===o.type.id);if(c&&c.instance.skinSelector.type===F.Segmented&&c.instance.resolvedExperiences){let m=c.instance.resolvedExperiences.find(l=>l.id===p);if((m==null?void 0:m.type)===me.Segment){let l=m,u=c.instance.skinSelector.segments.find(I=>I.segmentId===l.segment.id);if(u)return c.instance.skinSelector=u==null?void 0:u.skinSelector,c}}}break}}}finally{return null}};var vt="https://cdn.myop.dev/sdk/next/myop_sdk.min.js",L=class{constructor(){i(this,"components2init",[]);i(this,"components",[]);i(this,"componentsLoaders",[]);i(this,"initiated",!1);i(this,"version",wt);i(this,"type2InstanceCount",{});i(this,"assignId",n=>(this.type2InstanceCount[n.id]||(this.type2InstanceCount[n.id]=0),"".concat(n.id,"_").concat(++this.type2InstanceCount[n.id])));i(this,"inspected",!1);i(this,"inspect",()=>{this.inspected||(this.inspected=!0,this.components.forEach(n=>{n.inspect&&n.inspect()}))});i(this,"incomingMessageHandler",n=>{if(n.origin,document.location.origin,n.data.myop){if(n.data.direction!==b.up&&n.data.messageType!==f.EnvelopedMessage)return;let e=n.data;if(e.messageType===f.InitRequest){this.components2init.forEach(s=>{s.send(new $(s.id))});return}if(e.messageType===f.InitResponse){this.components2init=this.components2init.filter(r=>r.id!==e.content.id);let s=this.components.find(r=>{var a;return r.id===((a=e.content)==null?void 0:a.id)});s==null||s.setInitiated();return}if(e.messageType===f.EnvelopedMessage){let s=e,r=this.components.find(a=>a.id===s.destination);if(r){if(s.direction===b.down){s.message.messageType===S.name?r.onMessageReceived(s.message):(s.message.route=s.route,r.send(s.message));return}}else{let a=this.components.find(p=>p.id===s.message.destination);a&&a.send(s.message)}return}let t=this.components.find(s=>s.id===e.destination);if(!t){window.myop.IframeSDK&&window.myop.IframeSDK.messageToHost(e);return}if(t){if(t.onMessageReceived(e))return;window.myop.IframeSDK&&window.myop.IframeSDK.messageToHost(e)}}});i(this,"send",n=>{let e=new MessageEvent("",{data:n});this.incomingMessageHandler(e)});i(this,"init",n=>{if(this.initiated)throw new Error("hostSDK already initiated");let e=[new be,new we,new Se];if(this.componentsLoaders=[...e],n){let t={};n.forEach(s=>{let r=new s(this.componentsLoaders);t[r.type]=r}),this.componentsLoaders.forEach(s=>{t[s.type]||(t[s.type]=s)}),this.componentsLoaders=Object.values(t)}window.addEventListener("message",this.incomingMessageHandler,!1),console.log("myop hostSDK initiated",document.location.href),this.initiated=!0});i(this,"_getSkinIdBySkinSelector",async(n,e=[],t)=>{var r;async function s(a,p){for(let d of a)if(await p(d))return d}switch(n.type){case"DedicatedSkin":case F.Dedicated:return((r=n.skin)==null?void 0:r.id)||n.skins[0].id;case F.Segmented:{let p=await s(n.segments,async d=>{if(d.segmentId==="Default")return!0;let c=e.find(u=>u.type===me.Segment?u.segment.id===d.segmentId:!1);if(!c)throw new Error("experience not found");let l=c.segment,g=(t||{})[l.function];return g?await g():(console.warn("segmentId:".concat(d.segmentId,", ").concat(l.function," function not provided !")),!1)});if(p)return this._getSkinIdBySkinSelector(p.skinSelector,e);debugger}break;default:debugger}return""});i(this,"runSkinSelector",async(n,e)=>{let t=await this._getSkinIdBySkinSelector(n.instance.skinSelector,n.instance.resolvedExperiences,e);return n.type.skins.find(s=>s.id===t)});i(this,"loaderHooks");i(this,"loadComponent",async(n,e,t)=>{var m,l,g,u;if(!e){debugger;throw new Error("no container was found for this component")}let s=await Et(n);s&&(n=s);let r=h(h({},(m=this.loaderHooks)!=null?m:{}),(l=t==null?void 0:t.hooks)!=null?l:{}),a=e;if(a.myop)if(a.component){n=h({},n),n.instance=h({},n.instance);let I=await this.runSkinSelector(n,r);if(!I)throw new Error("runSkinSelector failed to choose skin, check the provided config");return(g=t==null?void 0:t.hooks)!=null&&g.afterSkinSelected&&(I=await t.hooks.afterSkinSelected(h({},I))),n.instance.skinSelector={type:F.Dedicated,skin:I},t&&(t=h({},t),delete t.hooks),await Ye(a,n,this.components,t)}else throw new Error("load component got a detached ref.");e=e;let p=await this.runSkinSelector(n,r);if(!p)throw new Error("runSkinSelector failed to choose skin, check the provided config");(u=t==null?void 0:t.hooks)!=null&&u.afterSkinSelected&&(p=await t.hooks.afterSkinSelected(h({},p)));let d=this.componentsLoaders.find(I=>I.type===p.loader.type);if(!d){debugger;throw new Error('no loader "'.concat(p.loader.type,'" was found for component'))}let c=await d.load(n.type,p,e,t);c.isInitiated||this.components2init.push(c),c.bind("onDispose",()=>(this.components=this.components.filter(I=>I!==c),this.components2init=this.components2init.filter(I=>I!==c),!0)),this.components.push(c),(!t||t.connectProps!==!1)&&(c=bt(c,n.type.props,p));try{await et(c,n,this.components)}catch(I){throw I}return t!=null&&t.skipInit||await c.initiated(),c});i(this,"navigate",async(n,e,t)=>{if(n.parent)throw new Error("Navigating on remote ref components is not implemented yet");if(t!=null&&t.staged){let s=await this.loadComponent(e,n.container,h({hidden:!0,relative:{direction:"after",child:n.element}},t));return t.init&&await t.init(s),s.show(),n.dispose(),s}else{let s=n.element.nextSibling;return n.dispose(),this.loadComponent(e,n.container,h({relative:{direction:"before",child:s}},t))}})}};i(L,"Instance",()=>window.myop.hostSDK);window.myop||(window.myop={__ROOT_SDK_PUBLIC_URL__:vt});if(!window.myop.hostSDK){let o=new L;o.init(),window.myop||(window.myop={__ROOT_SDK_PUBLIC_URL__:vt}),window.myop.hostSDK=o}var nt=window.myop.hostSDK;Me("hostSDK",nt);var ve=class extends M{constructor(){super(...arguments);i(this,"messageType",f.CreateRefComponentMessage);i(this,"innerExecutor",(e,t,s)=>{(async()=>{let a=t.shadowRoot.querySelectorAll("[".concat(k.id,"='").concat(e.refConfig.selector,"']"));if(a.length===1){let p=L.Instance(),d=p.components.find(g=>g.id===e.options.id);d&&d.dispose();let c=p.components.indexOf(d);c!==-1&&p.components.splice(c,1);let m=await p.loadComponent(e.nestedComponentConfig,a.item(0),e.options),l=[];Object.keys(m.refs).forEach(g=>{let u=m.refs[g];u=u.__nonProxied||u,u.componentDefinition&&l.push({refName:g,componentDefinitionId:u.componentDefinition.id})}),s(new A(e.handlerUniqueId,l))}else{console.error("CreateRefComponentMessageHandler - DOM element not found"),this.messageToHost(new A(e.handlerUniqueId,[],!0));debugger}})().then()})}};var kt=(o,n,e)=>{let t=o.scriptInputs?o.scriptInputs:{};t.makeSerializable=H,t.send=n,t.rootRef=e,t.__scriptInputs=t;let r=new Function("return (".concat(o.script,")(...arguments)"))(t);n(r)};var ke=class extends M{constructor(){super(...arguments);i(this,"messageType",f.ExecuteScriptMessage);i(this,"innerExecutor",(e,t,s)=>{kt(e,a=>{s(new V(e.handlerUniqueId,a))},t)})}};var Ht=o=>{if(!o)return null;if(o.tagName==="FORM"){let n=new FormData(o),e={formData:{},unmappedData:[]},t=o.querySelectorAll("input, select, textarea"),s=-1;return t.forEach(r=>{if(typeof r.value=="string"){let a=r.getAttribute(k.id),p=r.getAttribute("name"),d={id:r.id,name:p,value:Ht(r),required:r.required,validity:H(r.validity,!0),myopId:a};p?e.formData[p]?e.formData[p].value?e.unmappedData.push(d):(e.unmappedData.push(e.formData[p]),e.formData[p]=d):e.formData[p]=d:e.unmappedData.push(d)}}),e}return o.type==="checkbox"||o.type==="radio"?o.checked?o.value:null:o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.tagName==="SELECT"?o.value:o.isContentEditable?o.innerText||o.textContent:null},He=class extends M{constructor(){super(...arguments);i(this,"messageType",f.GetElementValueMessage);i(this,"innerExecutor",(e,t,s)=>{R(e.ref,t.shadowRoot).forEach(a=>{s(new j(Ht(a)),e)})})}};var De=class extends M{constructor(){super(...arguments);i(this,"messageType",f.SetInnerHtml);i(this,"innerExecutor",(e,t)=>{R(e.ref,t.shadowRoot).forEach(r=>{r.innerHTML=e.content})})}};var oe=class extends pe{constructor(){super(...arguments);i(this,"alwaysPassEnvelopesToHost",!0);i(this,"connectedCallback",(e,t)=>{e.addEventListener(le.webcomponent_message_key,s=>{let r=s.data?s.data:s.detail;if(!r||!r.myop){debugger;throw new Error("recvied webcomponent_message with wrong type")}else{let a=r;if(this.handleIncomeMessages(s),a.messageType===f.InitMessage){let p=a.content.id;this.components[p].context=new ue(e,t)}}}),setTimeout(()=>{this.messageToHost(new J)},1)});i(this,"messageToHost",(e,t)=>{e.direction=b.up,!e.replayToHandler&&(t!=null&&t.handlerUniqueId)&&(e.replayToHandler=t.handlerUniqueId),window.myop.hostSDK.send(e)});i(this,"supportedHandlers",[new ge(this.messageToHost,this.components),new De(this.messageToHost,this.components),new fe(this.messageToHost,this.components),new ye(this.messageToHost,this.components),new Ie(this.messageToHost,this.components),new Ce(this.messageToHost,this.components),new ke(this.messageToHost,this.components),new He(this.messageToHost,this.components),new ve(this.messageToHost,this.components)]);i(this,"init",()=>{})}};Me("WebComponentSDK",oe);export{oe as WebComponentSDK};
@@ -1728,7 +1728,7 @@ var WebcomponentLoader = class extends BaseMyopLoader {
1728
1728
  };
1729
1729
 
1730
1730
  // version:myop-sdk-version
1731
- var myop_sdk_version_default = "0.1.46";
1731
+ var myop_sdk_version_default = "0.2.1";
1732
1732
 
1733
1733
  // src/host/loaders/HTMLComponentLoader.ts
1734
1734
  var seen2 = [];
@@ -1790,6 +1790,8 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
1790
1790
  if (options == null ? void 0 : options._inspection) {
1791
1791
  const parser = new DOMParser();
1792
1792
  const _doc = parser.parseFromString(loaderConfig.HTML, "text/html");
1793
+ const myop_preview_script = _doc.getElementById("myop_preview");
1794
+ myop_preview_script == null ? void 0 : myop_preview_script.removeAttribute("type");
1793
1795
  const temp = _doc.implementation.createHTMLDocument();
1794
1796
  temp.body.innerHTML = "<script>\n const beforeKeysWindow = new Set(Object.keys(window));\n window.myopState = {\n beforeKeysWindow,\n };\n <\/script>";
1795
1797
  const node = temp.body.firstChild;
@@ -1897,6 +1899,34 @@ var _CloudRepository = class _CloudRepository {
1897
1899
  __publicField(_CloudRepository, "Main", new _CloudRepository());
1898
1900
  var CloudRepository = _CloudRepository;
1899
1901
 
1902
+ // src/helpers/EnableV2.ts
1903
+ var _v2_CloudRepository = class _v2_CloudRepository {
1904
+ constructor(_baseUrl = "https://cloud.myop.dev") {
1905
+ this._baseUrl = _baseUrl;
1906
+ __publicField(this, "variants", {});
1907
+ }
1908
+ async fetchComponent(componentId, environmentIdentifier) {
1909
+ if (!this.variants[componentId]) {
1910
+ this.variants[componentId] = new Promise(
1911
+ async (resolve, reject) => {
1912
+ try {
1913
+ const res = await fetch(
1914
+ "".concat(this._baseUrl, "/consume?id=").concat(componentId, "&env=").concat(environmentIdentifier)
1915
+ );
1916
+ const json = await res.json();
1917
+ resolve(json.item);
1918
+ } catch (e) {
1919
+ reject(e);
1920
+ }
1921
+ }
1922
+ );
1923
+ }
1924
+ return await this.variants[componentId];
1925
+ }
1926
+ };
1927
+ __publicField(_v2_CloudRepository, "Main", new _v2_CloudRepository());
1928
+ var v2_CloudRepository = _v2_CloudRepository;
1929
+
1900
1930
  // src/host/myopOverride.ts
1901
1931
  var checkMyopOverride = async (componentConfig) => {
1902
1932
  try {