@myop/sdk 0.2.3 → 0.2.4
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.
- package/dist/bundled-declarations.d.ts +27 -200
- package/dist/cjs/{_IframeSDK.012474c1.min.js → _IframeSDK.2f50c32c.min.js} +1 -1
- package/dist/cjs/{_IframeSDK.c7f71dba.js → _IframeSDK.b80455bf.js} +45 -31
- package/dist/cjs/{_IframeSDK.c7f71dba.js.map → _IframeSDK.b80455bf.js.map} +3 -3
- package/dist/cjs/_MyopHelpers.3d50ac48.min.js +1 -0
- package/dist/cjs/_MyopHelpers.7baba8b8.js +462 -0
- package/dist/cjs/_MyopHelpers.7baba8b8.js.map +7 -0
- package/dist/cjs/{_WebComponentSDK.15ffefb6.min.js → _WebComponentSDK.37374c87.min.js} +1 -1
- package/dist/cjs/{_WebComponentSDK.93d3959a.js → _WebComponentSDK.687ea8cb.js} +45 -31
- package/dist/cjs/{_WebComponentSDK.93d3959a.js.map → _WebComponentSDK.687ea8cb.js.map} +3 -3
- package/dist/cjs/{_hostSDK.a852b7b7.min.js → _hostSDK.48a55f66.min.js} +1 -1
- package/dist/cjs/{_hostSDK.eeb98d7f.js → _hostSDK.e09022f6.js} +45 -31
- package/dist/cjs/{_hostSDK.eeb98d7f.js.map → _hostSDK.e09022f6.js.map} +3 -3
- package/dist/cjs/myop_sdk.js +14 -14
- package/dist/cjs/myop_sdk.js.map +1 -1
- package/dist/cjs/myop_sdk.min.js +1 -1
- package/dist/cjs-bundled/myop_sdk.bundled.js +3947 -0
- package/dist/cjs-bundled/myop_sdk.bundled.js.map +7 -0
- package/dist/cjs-bundled/myop_sdk.bundled.min.js +1 -0
- package/dist/module/Iframe/index.js +49 -33
- package/dist/module/Iframe/index.js.map +3 -3
- package/dist/module/SDK.js +52 -120
- package/dist/module/SDK.js.map +3 -3
- package/dist/module/helpers/CloudRepository.d.ts +27 -185
- package/dist/module/helpers/index.d.ts +0 -1
- package/dist/module/helpers/index.js +52 -2521
- package/dist/module/helpers/index.js.map +4 -4
- package/dist/module/host/index.js +49 -33
- package/dist/module/host/index.js.map +3 -3
- package/dist/module/webcomponent/index.js +49 -33
- package/dist/module/webcomponent/index.js.map +3 -3
- package/package.json +1 -1
- package/dist/cjs/_MyopHelpers.75e0fd8d.js +0 -2810
- package/dist/cjs/_MyopHelpers.75e0fd8d.js.map +0 -7
- package/dist/cjs/_MyopHelpers.ecfd80d9.min.js +0 -1
- package/dist/module/helpers/enableV2.d.ts +0 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
var it=Object.defineProperty,Dt=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)=>Dt(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:()=>T,ExecuteScriptMessage:()=>S,ExecuteScriptReplyMessage:()=>V,GetAttributeMessage:()=>We,GetAttributeReplayMessage:()=>Ve,GetElementValueMessage:()=>Ue,InitMessage:()=>$,InitRequest:()=>J,InitResponse:()=>G,MessageDirection:()=>b,MutationObserverMessage:()=>je,MyopBindMessage:()=>x,MyopBindReplayMessage:()=>C,MyopElementMessage:()=>Oe,Ref:()=>B,RefComponentCreatedMessage:()=>A,ResizeObserverMessage:()=>Je,SetAttributeMessage:()=>Ae,SetInnerHtml:()=>ze,SetMutationObserverMessage:()=>qe,SetResizeObserverMessage:()=>Ge,stripFunction:()=>mt});var w=()=>"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",w());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",w())}},B=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()}},S=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(S,"replierKey","send"),i(S,"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 S{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 T=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 D=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 D{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 T("dispose")),super.dispose()})}hide(){this.send(new T("hide"))}show(){this.send(new T("show"))}inspect(){return this.send(new T("inspect"))}setHeightBasedOnDocumentElement(){this.send(new T("setHeightBasedOnDocumentElement"))}setHeightBasedOnScrollHeight(){this.send(new T("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(B.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(B.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=B.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=B.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 D{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 S(()=>window.document.documentElement.scrollHeight,t=>{this.IframeElement.style.height="".concat(t.content,"px"),e()}))});i(this,"observeSizeBasedOnDocumentElement",()=>this.send(new S(({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 S(()=>{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 S(()=>{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=w(),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 D{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={},Se=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(w()),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 St="0.2.3";var wt=[],we,Tt=async()=>(we||(we=new oe,we.init()),we);function Vt(o,n){return class extends HTMLElement{connectedCallback(){let e=n===K.open?"open":"closed",t=this.attachShadow({mode:e});Tt().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 Te=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(w()),d;if(a.shadowRootMode===K.localFrame){let c=w(),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 display: block;\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"),De=P.getElementById("myop_preview");De==null||De.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,Tt().then(m=>{m.connectedCallback(d,d)})}else{let c=Gt(e.name+t.id);wt.includes(c)||(qt(c,a.HTML,a.shadowRootMode),wt.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",St);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===T.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 Se,new Te];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 Be=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 Be(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};
|
|
1
|
+
var st=Object.defineProperty,kt=Object.defineProperties;var Ht=Object.getOwnPropertyDescriptors;var ot=Object.getOwnPropertySymbols;var Bt=Object.prototype.hasOwnProperty,Dt=Object.prototype.propertyIsEnumerable;var Be=(o,n,e)=>n in o?st(o,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[n]=e,h=(o,n)=>{for(var e in n||(n={}))Bt.call(n,e)&&Be(o,e,n[e]);if(ot)for(var e of ot(n))Dt.call(n,e)&&Be(o,e,n[e]);return o},E=(o,n)=>kt(o,Ht(n));var Lt=(o,n)=>{for(var e in n)st(o,e,{get:n[e],enumerable:!0})};var i=(o,n,e)=>Be(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 rt=async o=>{if(typeof o=="function")o();else if(o instanceof Promise){let n=await o;typeof n=="function"&&n()}},De=class{constructor(n){this.messageToHost=n}},ie=class extends De{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={};Lt(ae,{AddEventListenerMessage:()=>Ke,BaseMyopMessage:()=>y,BindClickMessage:()=>Pe,ChangeTextMessage:()=>Oe,CleanupMessage:()=>Y,CleanupReplayMessage:()=>ee,ClickReplayMessage:()=>V,CreateRefComponentMessage:()=>X,CustomRefMessage:()=>O,DetectMyopRefsMessage:()=>Ue,DetectedMyopRefsMessage:()=>Z,DisposeMessage:()=>te,ElementValueReplayMessage:()=>j,EnvelopedMessage:()=>Q,EventListenerCallbackMessage:()=>q,ExecuteComponentMethod:()=>S,ExecuteScriptMessage:()=>T,ExecuteScriptReplyMessage:()=>W,GetAttributeMessage:()=>ze,GetAttributeReplayMessage:()=>Ne,GetElementValueMessage:()=>$e,InitMessage:()=>$,InitRequest:()=>J,InitResponse:()=>G,MessageDirection:()=>b,MutationObserverMessage:()=>We,MyopBindMessage:()=>x,MyopBindReplayMessage:()=>C,MyopElementMessage:()=>_e,Ref:()=>B,RefComponentCreatedMessage:()=>A,ResizeObserverMessage:()=>je,SetAttributeMessage:()=>Fe,SetInnerHtml:()=>Ae,SetMutationObserverMessage:()=>Ve,SetResizeObserverMessage:()=>qe,stripFunction:()=>dt});var w=()=>"10000000-1000-4000-8000-100000000000".replace(/[018]/g,o=>(+o^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+o/4).toString(16));var _t=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 Pt=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 Le=o=>{let n=Pt(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(_t(n.slice(t,t+16)));return e};var it=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",w());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}},_e=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",w())}},B=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 at="ClickReplayMessage",Pe=class extends x{constructor(e,t){super(t);this.ref=e;i(this,"replyMessageKey",at);i(this,"messageType","BindClickMessage");i(this,"cleanable",!0)}},V=class extends C{constructor(){super(...arguments);i(this,"messageType",at)}};var Oe=class extends y{constructor(e,t){super();this.ref=e;i(this,"messageType","ChangeTextMessage");this.content=t}};var pt="ExecuteScriptReplyMessage",Ot=/(?:function\s*\w*\s*\([^)]*\)\s*\{([\s\S]*?)\}|(\([^)]*\)\s*=>\s*\{([\s\S]*?)\}))\s*$/,Kt=/\(\s*[^)]+\s*\)\s*=>\s*(.+)/,dt=o=>{let n=o.match(Ot);if(n)return n[1]||n[3];{let e=o.match(Kt);if(e)return e[1].trim()}},T=class extends x{constructor(e,t=()=>{},s){super(t);this.scriptInputs=s;i(this,"replyMessageKey",pt);i(this,"messageType","ExecuteScriptMessage");i(this,"script","");this.script=e.toString(),this.content=e.toString(),this.content=dt(this.content)}};i(T,"replierKey","send"),i(T,"completeStreamKey","completeStream");var W=class extends C{constructor(e,t){super(e);this.replayToHandler=e;this.content=t;i(this,"messageType",pt)}};var O=class extends T{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 ct="EventListenerCallbackMessage",Ke=class extends x{constructor(e,t,s){super(s);this.ref=e;this.type=t;this.handler=s;i(this,"replyMessageKey",ct);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",ct);this.content={e:t}}};var Fe=class extends y{constructor(e,t,s){super();this.ref=e;this.name=t;this.value=s;i(this,"messageType","SetAttributeMessage")}};var mt="ElementValueReplayMessage",$e=class extends x{constructor(e,t){super(t);this.ref=e;i(this,"replyMessageKey",mt);i(this,"messageType","GetElementValueMessage")}},j=class extends C{constructor(e){super();this.content=e;i(this,"messageType",mt)}};var Ae=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 lt="RefComponentCreatedMessage",X=class extends x{constructor(e,t,s,r){super(r);this.refConfig=e;this.nestedComponentConfig=t;this.options=s;i(this,"replyMessageKey",lt);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",lt)}};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 ft="DetectedMyopRefsMessage",Ue=class extends x{constructor(){super(...arguments);i(this,"messageType","DetectMyopRefsMessage");i(this,"replyMessageKey",ft)}},Z=class extends C{constructor(e,t){super(e);this.replayToHandler=e;i(this,"messageType",ft);this.content=t}isTypeof(e){return e.messageType===this.messageType}};var gt="GetAttributeReplayMessage",ze=class extends x{constructor(e,t,s){super(s);this.ref=e;this.name=t;i(this,"replyMessageKey",gt);i(this,"messageType","GetAttributeMessage")}},Ne=class extends C{constructor(e){super();this.content=e;i(this,"messageType",gt)}};var S=class extends y{constructor(e){super();this.method=e;i(this,"messageType","ExecuteComponentMethod")}};var Ve=class extends y{constructor(){super(...arguments);i(this,"messageType","SetMutationObserverMessage")}},We=class extends y{constructor(){super(...arguments);i(this,"messageType","MutationObserverMessage")}};var ut="CleanupReplayMessage",Y=class extends x{constructor(e,t){super(t);this.cleanupForMessageId=e;i(this,"replyMessageKey",ut);i(this,"messageType","CleanupMessage")}},ee=class extends C{constructor(e){super();this.customCleanup=e;i(this,"messageType",ut)}};var te=class extends y{constructor(){super(...arguments);i(this,"messageType","DisposeMessage")}};var qe=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 Ge=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 Ge(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],rt(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 Je={message:"message",code:"code"},U=class{};i(U,"code","code"),i(U,"component","component");var F={Segmented:"Segmented",Dedicated:"Dedicated",Default:"Default"},ce={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 me={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 le=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 V(e.handlerUniqueId))};p.addEventListener("click",d),a.push(()=>{p.removeEventListener("click",d)})}),()=>{a.forEach(p=>p())}})}};var fe=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 ge=class extends de{constructor(e,t){super(e,t);this.container=e;this.shadowRoot=t}};var ue=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 ye="__federation__",yt="onLoad";var he=(o,n)=>{window[ye]&&window[ye][o]&&window[ye][o][yt]&&window[ye][o][yt]({[o]:n})};var Me=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 Xe=o=>o!==Object(o),Ft=o=>typeof o=="function",Qe=o=>{if(Xe(o))return!0;if(Ft(o)||Object.getPrototypeOf(o))return!1;for(let n in o){let e=o[n];if(typeof e=="object"){if(!Qe(e))return!1}else{if(Xe(e))continue;return!1}}return!0},H=(o,n={},e=!0,t=new WeakMap)=>{if(Xe(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 Ie=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 D=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 ht={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 D{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 $t=(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},Ce=(o,n,e,t,s,r)=>{let a=$t("".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)}},Mt=(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),It=(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."))},Ct=(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(Mt(p,a,o))return!1;if(p.behavior.type===Je.code){if(e.loader.type===v.HTMLLoader&&e.loader.shadowRootMode===K.localFrame){let c=p.behavior;return o.element.contentWindow[c.remap||a]}return It(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=ae[p.behavior.message];o.send(new m(...c))}):null},set:(r,a,p)=>{let d=t[a];if(Mt(d,a,o))return!1;if(d.behavior.type===Je.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 It(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=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},At=(o,n)=>new Proxy(o,{get(e,t){return e[t]?e[t]:(...r)=>new Promise(a=>{r.forEach(p=>{Qe(p)||ht.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}}),Ze=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 Ye(p,n,e,!0),s.setHeightBasedOnScrollHeight&&s.setHeightBasedOnScrollHeight(),r(p)}catch(l){a(l)}}))})},Ye=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=B.create("",r,o);try{let g=await Ze(l,m,e);o.refs[r.name]=g,a()}catch(g){p(g)}}else try{let c=B.create("",r,o);o.refs[r.name]=At(c,o),a()}catch(c){}}));try{await Promise.all(s)}catch(r){throw r}};var z=class extends D{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 T(()=>window.document.documentElement.scrollHeight,t=>{this.IframeElement.style.height="".concat(t.content,"px"),e()}))});i(this,"observeSizeBasedOnDocumentElement",()=>this.send(new T(({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 T(()=>{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 T(()=>{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=Ce(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 Ut=(o,n,e)=>{let t=new URL(o);return t.searchParams.append(n,e),t.toString()},xe=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=w(),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=Ut(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 D{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(me.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=Ce(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 et={},be=class extends _{constructor(){super(...arguments);i(this,"type",v.WebComponentLoader);i(this,"load",async(e,t,s,r)=>{let a=t.loader;et[a.url]?console.log("Module alreday loaded or in loading process"):et[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 et[a.url],await it(1);let p="myop-comp-".concat(w()),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 xt="0.2.4";var bt=[],Te,Tt=async()=>(Te||(Te=new oe,Te.init()),Te);function zt(o,n){return class extends HTMLElement{connectedCallback(){let e=n===K.open?"open":"closed",t=this.attachShadow({mode:e});Tt().then(s=>{s.connectedCallback(this,t),t.innerHTML=o})}}}var Nt=(o,n,e)=>{customElements.define(o,zt(n,e)),console.log("define('".concat(o,"') was called, web component ready to use"))},Vt=o=>o.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/(\d+)/g,"-$1").toLowerCase(),Wt=o=>(o=Vt(o),o.replace(/_/g,"-"));var we=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(w()),d;if(a.shadowRootMode===K.localFrame){let c=w(),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 display: block;\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"),He=P.getElementById("myop_preview");He==null||He.removeAttribute("type");let tt=P.implementation.createHTMLDocument();tt.body.innerHTML="<script>\n const beforeKeysWindow = new Set(Object.keys(window));\n window.myopState = {\n beforeKeysWindow,\n };\n <\/script>";let nt=tt.body.firstChild;nt&&P.head&&P.head.insertBefore(P.importNode(nt,!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,Tt().then(m=>{m.connectedCallback(d,d)})}else{let c=Wt(e.name+t.id);bt.includes(c)||(Nt(c,a.HTML,a.shadowRootMode),bt.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 Se=class Se{constructor(n="https://cloud.myop.dev"){this._baseUrl=n;i(this,"variants",{});i(this,"userFlows",{})}isPreloaded(n){return n in this.variants}async fetchComponentV2(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]}async fetchComponentV1(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]}async fetchComponent(n,e){return this.fetchComponentV1(n,e)}};i(Se,"Main",new Se);var se=Se;var wt=async o=>{try{let n=new URL(window.location.href),t=new URLSearchParams(n.search).get("myopOverride");if(t){let[s,...r]=Le(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]=Le(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)===ce.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 St="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",xt);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 xe,new be,new we];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===ce.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 wt(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 Ze(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=Ct(c,n.type.props,p));try{await Ye(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__:St});if(!window.myop.hostSDK){let o=new L;o.init(),window.myop||(window.myop={__ROOT_SDK_PUBLIC_URL__:St}),window.myop.hostSDK=o}var qt=window.myop.hostSDK;he("hostSDK",qt);var Re=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 Rt=(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 Ee=class extends M{constructor(){super(...arguments);i(this,"messageType",f.ExecuteScriptMessage);i(this,"innerExecutor",(e,t,s)=>{Rt(e,a=>{s(new W(e.handlerUniqueId,a))},t)})}};var Et=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:Et(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},ve=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(Et(a)),e)})})}};var ke=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(me.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 ge(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 fe(this.messageToHost,this.components),new ke(this.messageToHost,this.components),new le(this.messageToHost,this.components),new ue(this.messageToHost,this.components),new Me(this.messageToHost,this.components),new Ie(this.messageToHost,this.components),new Ee(this.messageToHost,this.components),new ve(this.messageToHost,this.components),new Re(this.messageToHost,this.components)]);i(this,"init",()=>{})}};he("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.2.
|
|
1731
|
+
var myop_sdk_version_default = "0.2.4";
|
|
1732
1732
|
|
|
1733
1733
|
// src/host/loaders/HTMLComponentLoader.ts
|
|
1734
1734
|
var seen2 = [];
|
|
@@ -1845,12 +1845,46 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
|
|
|
1845
1845
|
|
|
1846
1846
|
// src/helpers/CloudRepository.ts
|
|
1847
1847
|
var _CloudRepository = class _CloudRepository {
|
|
1848
|
-
// private components: Record<string, Promise<IUserFlow>> = {};
|
|
1849
1848
|
constructor(_baseUrl = "https://cloud.myop.dev") {
|
|
1850
1849
|
this._baseUrl = _baseUrl;
|
|
1850
|
+
// v2 cache
|
|
1851
|
+
__publicField(this, "variants", {});
|
|
1852
|
+
// v1 cache
|
|
1851
1853
|
__publicField(this, "userFlows", {});
|
|
1852
1854
|
}
|
|
1853
|
-
|
|
1855
|
+
// ============ V2 Methods (Default) ============
|
|
1856
|
+
/**
|
|
1857
|
+
* Check if a component is already cached/preloaded (v2)
|
|
1858
|
+
*/
|
|
1859
|
+
isPreloaded(componentId) {
|
|
1860
|
+
return componentId in this.variants;
|
|
1861
|
+
}
|
|
1862
|
+
/**
|
|
1863
|
+
* Fetch a v2 component variant
|
|
1864
|
+
*/
|
|
1865
|
+
async fetchComponentV2(componentId, environmentIdentifier) {
|
|
1866
|
+
if (!this.variants[componentId]) {
|
|
1867
|
+
this.variants[componentId] = new Promise(
|
|
1868
|
+
async (resolve, reject) => {
|
|
1869
|
+
try {
|
|
1870
|
+
const res = await fetch(
|
|
1871
|
+
"".concat(this._baseUrl, "/consume?id=").concat(componentId, "&env=").concat(environmentIdentifier)
|
|
1872
|
+
);
|
|
1873
|
+
const json = await res.json();
|
|
1874
|
+
resolve(json.item);
|
|
1875
|
+
} catch (e) {
|
|
1876
|
+
reject(e);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
);
|
|
1880
|
+
}
|
|
1881
|
+
return await this.variants[componentId];
|
|
1882
|
+
}
|
|
1883
|
+
// ============ V1 Methods (Legacy) ============
|
|
1884
|
+
/**
|
|
1885
|
+
* Fetch a v1 component from a flow
|
|
1886
|
+
*/
|
|
1887
|
+
async fetchComponentV1(componentId, flowId) {
|
|
1854
1888
|
if (flowId) {
|
|
1855
1889
|
const flow = await this.fetchFlow(flowId);
|
|
1856
1890
|
return flow.components.find((c) => c.type.id === componentId);
|
|
@@ -1895,38 +1929,18 @@ var _CloudRepository = class _CloudRepository {
|
|
|
1895
1929
|
}
|
|
1896
1930
|
return await this.userFlows[flowId];
|
|
1897
1931
|
}
|
|
1932
|
+
// ============ Backward Compatibility ============
|
|
1933
|
+
/**
|
|
1934
|
+
* @deprecated Use fetchComponentV2 or fetchComponentV1 explicitly
|
|
1935
|
+
* Defaults to v1 behavior for backward compatibility with existing code
|
|
1936
|
+
*/
|
|
1937
|
+
async fetchComponent(componentId, flowId) {
|
|
1938
|
+
return this.fetchComponentV1(componentId, flowId);
|
|
1939
|
+
}
|
|
1898
1940
|
};
|
|
1899
1941
|
__publicField(_CloudRepository, "Main", new _CloudRepository());
|
|
1900
1942
|
var CloudRepository = _CloudRepository;
|
|
1901
1943
|
|
|
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
|
-
|
|
1930
1944
|
// src/host/myopOverride.ts
|
|
1931
1945
|
var checkMyopOverride = async (componentConfig) => {
|
|
1932
1946
|
try {
|