import{Jt as e,Ut as t,Vt as n,Wt as r,bt as o,nn as i,yt as s}from"./630ba094.L_X-5TXi.js";import{o as c}from"./f1384cc2.BX1JbjgR.js";import{N as a}from"./53feb4a7.Cc6JRiPi.js";function l(e){return"string"==typeof e?e:null==e?"":"object"==typeof e||"function"==typeof e?Object.prototype.toString.call(e):String(e)}function u(e){if(null!=e)return l(e)}function p(e){if("string"!=typeof e||"__proto__"===e)throw new Error(`Remote property name is not allowed: ${String(e)}`)}function d(e){const t=new Set,n=[e];for(;n.length>0;){const e=n.pop();if("object"==typeof e&&null!==e&&!t.has(e)){if(t.add(e),void 0===e.constructor)throw new Error("Remote property value is not allowed: object masquerades as a framework node");if(e instanceof Map)for(const[t,r]of e)n.push(t,r);else if(e instanceof Set)for(const t of e)n.push(t);e instanceof Error&&n.push(e.cause),n.push(Object.getPrototypeOf(e));for(const t of Object.keys(e))n.push(e[t])}}}function f(e){if(null!=e&&"function"!=typeof e)throw new Error("Remote event listener is not a function")}var m=class{root={id:"~",type:9,properties:t({}),attributes:t({}),eventListeners:t({}),children:t([])};attached=new Map([["~",this.root]]);parents=new Map;implementations=new Map;constructor({retain:e,release:r}={}){const{attached:o,parents:i}=this,s=function({call:e,insertChild:t,removeChild:n,updateText:r,updateProperty:o}){const i={0:t,1:n,2:r,3:o};return{call:e,mutate(e){for(const[t,...n]of e)i[t](...n)}}}({call:(e,t,...n)=>{const r=this.implementations.get(e)?.[t];if("function"!=typeof r)throw new Error(`Node ${e} does not implement the ${t}() method`);return r(...n)},insertChild:(e,t,n)=>{const r=o.get(e);if(!r)return;const i=[...r.children.peek()],s=c(t,r);n===i.length?i.push(s):i.splice(n,0,s),r.children.value=i},removeChild:(e,t)=>{const n=o.get(e);if(!n)return;const r=[...n.children.peek()],[i]=r.splice(t,1);i&&(n.children.value=r,a(i))},updateProperty:(t,n,i,s=1)=>{const c=o.get(t);if(!c)return;let a;switch(i=function(e,t,n){switch(p(e),n){case 1:return d(t),t;case 2:return u(t);case 3:return f(t),t;default:throw new Error(`Remote property update type is not allowed: ${n}`)}}(n,i,s),s){case 1:a=c.properties;break;case 2:a=c.attributes;break;case 3:a=c.eventListeners}const l=a.peek(),m=l[n];if(Object.is(m,i))return;e?.(i);const h={...l};if(2===s&&void 0===i?delete h[n]:h[n]=i,a.value=h,"slot"===n){const e=this.parents.get(t),n=null==e?e:o.get(e);n&&(n.children.value=[...n.children.peek()])}r?.(m)},updateText:(e,t)=>{const n=o.get(e);n&&(n.data.value=l(t))}});function c(n,r){let s;switch(n.type){case 3:case 8:{const{id:e,type:r,data:o}=n;s={id:e,type:r,data:t(l(o))};break}case 1:{const{id:r,type:o,element:i,children:a,properties:l,attributes:m,eventListeners:h}=n;!function(e){if("string"!=typeof e)throw new Error(`Remote element name is not allowed: ${String(e)}`)}(i),function(e){if(null!=e)for(const t of Object.keys(e))p(t),d(e[t])}(l),function(e){if(null!=e)for(const t of Object.keys(e))p(t),f(e[t])}(h);const y=function(e){const t={};if(null==e)return t;for(const n of Object.keys(e)){p(n);const r=u(e[n]);void 0!==r&&(t[n]=r)}return t}(m);e?.(l),e?.(h);const g=[];s={id:r,type:o,element:i,children:t(g),properties:t({...l}),attributes:t(y),eventListeners:t({...h})};for(const e of a)g.push(c(e,s));break}default:throw new Error(`Unknown node type: ${JSON.stringify(n)}`)}return o.set(s.id,s),i.set(s.id,r.id),s}function a(e){if(o.delete(e.id),i.delete(e.id),r&&"properties"in e&&r(e.properties.peek()),"children"in e)for(const t of e.children.peek())a(t)}this.connection={call:s.call,mutate(e){n(()=>{s.mutate(e)})}}}implement({id:e},t){null==t?this.implementations.delete(e):this.implementations.set(e,t)}get({id:e}){return this.attached.get(e)}};function h(e,{receiver:t,components:n}){switch(e.type){case 1:{const r=n.get(e.element);if(null==r)throw new Error(`No component found for remote element: ${e.element}`);return s(r,{element:e,receiver:t,components:n},e.id)}case 3:return e.data;case 8:return null;default:throw new Error(`Unknown remote node type: ${String(e)}`)}}var y=Symbol.for("remote-dom.element"),g=new Set(["children","ref","key","dangerouslySetInnerHTML","innerHTML","outerHTML","__proto__"]);function v(e){return function(...t){if(1===t.length&&t[0]instanceof Event){const n=t[0];if(n.target!==n.currentTarget)return;return"detail"in n?e(n.detail):e()}return e(...t)}}var w=function(e){const{receiver:t}=e,n=t.root.children.value;return s(i,{children:n.map(t=>h(t,e))})},b=function(t,{name:n,eventProps:c}={}){const a=o(function({element:n,receiver:o,components:a}){const l=e(),{id:u}=n,p=function(e,t){if(!e)return;const{children:n,properties:r,attributes:o,eventListeners:c}=e,a=c.value,l=[],u={},p=r.value;for(const i of Object.keys(p))g.has(i)||(u[i]=p[i]);const d=o.value;for(const i of Object.keys(d)){const e=d[i];g.has(i)||"string"!=typeof e||(u[i]=e)}if(t.eventProps)for(const[i,s]of Object.entries(t.eventProps)){const e=s?.event;if(null==e)continue;const t=a[e];t&&(u[i]=v(t))}else for(const[i,s]of Object.entries(a))u[`on${i[0].toUpperCase()}${i.slice(1)}`]=v(s);for(const f of n.value){let e=1===f.type?f.attributes.peek().slot:void 0;if(("string"!=typeof e||g.has(e))&&(e=void 0),e){const n=h(f,t);u[e]=u[e]?s(i,{children:[u[e],n]}):n}else l.push(h(f,t))}return{...u,children:l}}(n,{receiver:o,components:a,eventProps:c});if(p[y]=n,null==l.current){const e={id:u,receiver:o};e.instanceRef=function(e){let t=null;return{get current(){return t},set current(n){t=n,e.receiver.implement(e,n)}}}(e),l.current=e}return l.current.id=u,l.current.receiver=o,r(()=>{const e={id:u};return o.implement(e,l.current?.instanceRef.current),()=>{o.implement(e,null)}},[u,o]),s(t,{ref:l.current.instanceRef,...p})});return a.displayName=n??`RemoteComponentRenderer(${t.displayName??t.name??"Component"})`,a},k=function({element:e,receiver:t,components:n}){const r={receiver:t,components:n};return s(i,{children:e.children.value.map(e=>h(e,r))})},j=class extends m{#e=new Set;constructor(e){super({retain:c,release:()=>{}});const t=this.connection.call;this.connection.call=(n,r,...o)=>{try{return t(n,r,...o)}catch(i){if(i instanceof Error&&i.message.includes("does not implement the")){if("hideOverlay"===r&&!this.#e.has(String(n)))return;const t=this.get({id:String(n)}),o=t&&"element"in t?t.element:void 0;throw new a(`${o?`Node ${n} (${o})`:`Node ${n}`} does not implement the ${r}() method. `,{metadata:{nodeId:n,method:r,nodeType:o,extensionId:e?.id,extensionName:e?.name,extensionTarget:e?.extensionPoint.target,appId:e?.appId,appName:e?.appName,apiVersion:e?.apiVersion}})}throw i}}}implement(e,t){null==t?this.#e.delete(String(e.id)):this.#e.add(String(e.id)),super.implement(e,t)}};function O(e,t){const n=new Map;function r(t){for(const e of t){const[t,n]=e;switch(t){case 0:o(n,e[2],e[3]);break;case 1:i(n,e[2])}}e.mutate(t)}function o(e,t,r){if(n.has(e)||n.set(e,[]),n.get(e).splice(r,0,{id:t.id,slot:"attributes"in t?t.attributes?.slot:void 0}),"children"in t&&t.children)for(const[n,i]of t.children.entries())o(t.id,i,n)}function i(e,t){const r=n.get(e);if(!r?.[t])return;const o=r[t].id;r.splice(t,1),s(o)}function s(e){const t=n.get(e);if(t){for(const e of t)s(e.id);n.delete(e)}}return function(e,...o){switch(e){case 0:{const[e]=o;r(e.map((e,n)=>[0,"~",$(e,t),n]));break}case 1:{const[e="~",i,s]=o,c=[],a=n.get(e);if(a){const t=a.findIndex(({id:e})=>e===s.id);t>=0&&c.push([1,e,t])}c.push([0,e,$(s,t),i]),r(c);break}case 2:{const[e,t]=o;r([[1,e??"~",t]]);break}case 3:{const[e,t]=o;r([[2,e,t]]);break}case 4:{const[e,i]=o,s=n.get(e),c=[];for(const[r,o]of Object.entries(i)){const i=s?.findIndex(({slot:e})=>e===r)??-1;S(o)?(i>=0&&c.push([1,e,i]),c.push([0,e,I(r,o,t),n.get(e)?.length??0])):i>=0?c.push([1,e,i]):c.push([3,e,r,o])}r(c);break}default:throw new Error(`Unsupported action type: ${e}`)}}}function $(e,t){switch(e.kind){case 2:return function({id:e,text:t}){return{id:e,type:3,data:t}}(e);case 1:return function({id:e,type:t,props:n,children:r},o){const i=o?.elements?.[t]??t,[s,c]=function(e){const t={},n={};for(const[r,o]of Object.entries(e))S(o)?t[r]=o:n[r]=o;return[t,n]}(n);return{id:e,type:1,element:i,properties:c,children:[...r.map(e=>$(e,o)),...E(s,o)]}}(e,t);default:return{id:e.id,type:8,data:"added by remote-ui legacy adaptor to replace a fragment rendered as a child"}}}function S(e){return null!=e&&"object"==typeof e&&"kind"in e&&3===e.kind}function E(e,t){return Object.entries(e).map(([e,n])=>I(e,n,t))}function I(e,t,n){return{id:t.id,element:n?.slotProps?.wrapper??"remote-fragment",attributes:{slot:e},type:1,children:t.children.map(e=>$(e,n))}}export{b as a,w as i,j as n,h as o,k as r,O as t};