@myop/sdk 0.1.45 → 0.1.47

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 (42) hide show
  1. package/README.md +1 -1
  2. package/dist/bundled-declarations.d.ts +70 -1
  3. package/dist/cjs/_IframeSDK.7d51275f.min.js +1 -0
  4. package/dist/cjs/{_IframeSDK.6e68e329.js → _IframeSDK.cc82a827.js} +34 -6
  5. package/dist/cjs/_IframeSDK.cc82a827.js.map +7 -0
  6. package/dist/cjs/_MyopHelpers.a07c6289.js +2810 -0
  7. package/dist/cjs/_MyopHelpers.a07c6289.js.map +7 -0
  8. package/dist/cjs/_MyopHelpers.ac3e8038.min.js +1 -0
  9. package/dist/cjs/{_WebComponentSDK.1f50ec03.js → _WebComponentSDK.64c6a9c1.js} +34 -6
  10. package/dist/cjs/_WebComponentSDK.64c6a9c1.js.map +7 -0
  11. package/dist/cjs/_WebComponentSDK.6c4296d5.min.js +1 -0
  12. package/dist/cjs/{_hostSDK.3215ab07.js → _hostSDK.788bdb7f.js} +34 -6
  13. package/dist/cjs/_hostSDK.788bdb7f.js.map +7 -0
  14. package/dist/cjs/_hostSDK.e5552529.min.js +1 -0
  15. package/dist/cjs/myop_sdk.js +14 -14
  16. package/dist/cjs/myop_sdk.js.map +1 -1
  17. package/dist/cjs/myop_sdk.min.js +1 -1
  18. package/dist/module/Iframe/index.js +47 -19
  19. package/dist/module/Iframe/index.js.map +3 -3
  20. package/dist/module/SDK.js +136 -21
  21. package/dist/module/SDK.js.map +3 -3
  22. package/dist/module/common/index.d.ts +55 -1
  23. package/dist/module/common/index.js +3 -2
  24. package/dist/module/common/index.js.map +2 -2
  25. package/dist/module/helpers/EnableV2.d.ts +12 -0
  26. package/dist/module/helpers/index.d.ts +1 -0
  27. package/dist/module/helpers/index.js +2520 -4
  28. package/dist/module/helpers/index.js.map +4 -4
  29. package/dist/module/host/index.js +47 -19
  30. package/dist/module/host/index.js.map +3 -3
  31. package/dist/module/webcomponent/index.js +47 -19
  32. package/dist/module/webcomponent/index.js.map +3 -3
  33. package/package.json +1 -1
  34. package/dist/cjs/_IframeSDK.1993fad2.min.js +0 -1
  35. package/dist/cjs/_IframeSDK.6e68e329.js.map +0 -7
  36. package/dist/cjs/_MyopHelpers.98cae3f9.js +0 -417
  37. package/dist/cjs/_MyopHelpers.98cae3f9.js.map +0 -7
  38. package/dist/cjs/_MyopHelpers.f3e207e0.min.js +0 -1
  39. package/dist/cjs/_WebComponentSDK.1f50ec03.js.map +0 -7
  40. package/dist/cjs/_WebComponentSDK.c0dcea75.min.js +0 -1
  41. package/dist/cjs/_hostSDK.3215ab07.js.map +0 -7
  42. package/dist/cjs/_hostSDK.f697667b.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.1.47";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};
@@ -676,7 +676,8 @@ var BaseMyopSDK = class {
676
676
  var SkinLoaders = {
677
677
  "IframeLoader": "IframeLoader",
678
678
  "WebComponentLoader": "WebComponentLoader",
679
- "HTMLLoader": "HTMLLoader"
679
+ "HTMLLoader": "HTMLLoader",
680
+ "MinimizedLoader": "MinimizedLoader"
680
681
  };
681
682
  var ShadowRootModeType = {
682
683
  "open": "open",
@@ -1727,7 +1728,7 @@ var WebcomponentLoader = class extends BaseMyopLoader {
1727
1728
  };
1728
1729
 
1729
1730
  // version:myop-sdk-version
1730
- var myop_sdk_version_default = "0.1.45";
1731
+ var myop_sdk_version_default = "0.1.47";
1731
1732
 
1732
1733
  // src/host/loaders/HTMLComponentLoader.ts
1733
1734
  var seen2 = [];
@@ -1789,6 +1790,8 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
1789
1790
  if (options == null ? void 0 : options._inspection) {
1790
1791
  const parser = new DOMParser();
1791
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");
1792
1795
  const temp = _doc.implementation.createHTMLDocument();
1793
1796
  temp.body.innerHTML = "<script>\n const beforeKeysWindow = new Set(Object.keys(window));\n window.myopState = {\n beforeKeysWindow,\n };\n <\/script>";
1794
1797
  const node = temp.body.firstChild;
@@ -1798,10 +1801,7 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
1798
1801
  HTML2Render = _doc.documentElement.outerHTML;
1799
1802
  }
1800
1803
  doc.writeln(HTML2Render);
1801
- doc.writeln('<script src="'.concat(window.myop.__ROOT_SDK_PUBLIC_URL__, "\"><\/script>\n <script>\n window.__federation__ = \n { ...window.__federation__,\n //TODO : get from ENV at build time, \n // inject value to module at build time \n // today we doing so just for the CJS version \n __public_path__ :'https://cdn.myop.dev/sdk/next',\n ...").concat(JSON.stringify(
1802
- // @ts-ignore
1803
- window.__federation__
1804
- ), "};\n const __myop_init = async () => {\n const {IframeSDK} = (await window.myop.rootSDK.getIframeModule());\n const sdk = new IframeSDK()\n sdk.init();\n }\n __myop_init().then();\n <\/script>"));
1804
+ doc.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>'));
1805
1805
  doc.close();
1806
1806
  const comp = new MyopIframeComponent(componentDefinition, skin, container, IframeElement, options);
1807
1807
  if (loaderConfig.autoHeight) {
@@ -1899,6 +1899,34 @@ var _CloudRepository = class _CloudRepository {
1899
1899
  __publicField(_CloudRepository, "Main", new _CloudRepository());
1900
1900
  var CloudRepository = _CloudRepository;
1901
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
+
1902
1930
  // src/host/myopOverride.ts
1903
1931
  var checkMyopOverride = async (componentConfig) => {
1904
1932
  try {