"use strict";var e=require("../ssr-RXknEJpO.js");require("../observable-BXDJFaLN.js"),require("../i18n-CP31jeWH.js"),require("../empty_html-hFq4zm9t.js"),require("@kdcloudjs/kwc");let s=1;const n={},t=[],r={isMessageEventHandled:!1};function i(e){try{const s=e.data?JSON.parse(e.data):{},t=s.arguments?s.arguments.cmpId:null;t&&n[t]&&n[t](s)}catch(e){}}exports.clearDomains=function(){t.splice(0,t.length)},exports.createMessage=function(e,s,n){return n.cmpId=e,{event:s,arguments:n}},exports.dispatchEvent=i,exports.getDomains=function(){return t.map(e=>e.domain)},exports.postMessage=function(e,s,n,t){e&&e(t?s:JSON.stringify(s||{}),n)},exports.registerDomain=function(e){if(!e||""===e)return;const s=t.find(s=>s.domain===e);s?s.ref+=1:t.push({domain:e,ref:1})},exports.registerMessageHandler=function(t){const a="kingdeeIframeMessage-"+s++;return n[a]=t,e.isCSR&&!r.isMessageEventHandled&&(r.isMessageEventHandled=!0,window.addEventListener("message",e=>{i(e)})),a},exports.setMessageEventHandled=function(){r.isMessageEventHandled=!0},exports.unregisterDomain=function(e){if(!e||""===e)return;const s=t.findIndex(s=>s.domain===e);if(s>=0){const e=t[s];e.ref-=1,0===e.ref&&t.splice(s,1)}},exports.unregisterMessageHandler=function(e){delete n[e]};
