!function(){var e={32746:function(e,n,o){const t=["onDataColumnsChanged","onDataTablesChanged","onDocumentChanged","onDocumentClosed","onMarkingChanged"],r=["removeOnDataColumnsChanged","removeOnDataTablesChanged","removeOnDocumentChanged","removeOnDocumentClosed","removeOnMarkingChanged"],s={onDataColumnsChanged:"removeOnDataColumnsChanged",onDataTablesChanged:"removeOnDataTablesChanged",onDocumentChanged:"removeOnDocumentChanged",onDocumentClosed:"removeOnDocumentClosed",onMarkingChanged:"removeOnMarkingChanged"};function SpotfireMessageHandler(e,n="*",o=!1){if(!(this instanceof SpotfireMessageHandler))return new SpotfireMessageHandler(e,n);if(!e)throw new Error("An instance of SpotfireDocument is required to run the MessageHandler.");const a=e,i=n;let c=[];function d(e,n,o){throw o.source.postMessage(JSON.stringify({messageId:n,error:e.message||e.toString()}),o.origin),e}function g(e){"*"!==i&&e.origin!==i||async function(e){let n=null;try{const s=function(e){const n=JSON.parse(e),{target:o,method:t,messageId:r}=n;if(!o)return new Error('Missing message event "target" param.');if(!t)return new Error('Missing message event "method" param.');if(!r)return new Error('Missing message event "messageId" param.');return n}(e.data);if(s instanceof Error)return void(o&&console.log("Received message not matching.",s));const{method:i,messageId:g}=s;n=g;null===u(s)&&d(new Error("Unable to find object to call. Did you pass an instance of SpotfireDocument to the SpotfireMessageHandler?"),g,e),t.includes(i)?function(e,n){const{method:o,args:t=[],cbMessageId:r,target:s}=n;if("spotfireDocument"!==s)throw new Error("Event based methods only exist on SpotfireDocument object.");if("function"!=typeof a[o])throw new Error(`Unknown method "${o}" on object "${s}"`);const i=a[o].length,d=[...t];if(d.length!==i-1)throw new Error(`Invalid number of arguments provided for method "${o}". Expected ${i}, found ${d.length+1}`);const g=function(e,n,o,t){const r=n=>{e.source.postMessage(JSON.stringify({messageId:t,result:n}),e.origin)};return c.push({callback:r,method:n,messageId:t,args:[...o]}),r}(e,o,d,r);d.push(g),f(e,{...n,args:d})}(e,s):r.includes(i)?function(e,n){const{method:o,messageId:t,target:r}=n;if("spotfireDocument"!==r)throw new Error("Event based methods only exist on SpotfireDocument object.");if("function"!=typeof a[o])throw new Error(`Unknown method "${o}" on object "${r}"`);const s=c.find((e=>e.messageId===t));if(!s)return;const{callback:i,args:d}=s,g=[...d];g.push(i),a[o].call(a,g),c=c.filter((e=>e.messageId!==t))}(0,s):await f(e,s)}catch(s){d(s,n,e)}}(e)}function u(e){const{target:n}=e;return"spotfireDocument"===n?a:"spotfireDocumentEditor"===n?a.editor:null}async function f(e,n){const{method:o,args:t=[],messageId:r,target:s}=n,a=u(n);if(null===a)throw new Error("Unable to find object to call. Did you pass an instance of SpotfireDocument in the constructor?");if("function"!=typeof a[o])throw new Error(`Unknown method "${o}" on object "${s}"`);const i=await a[o].call(a,...t);let c=null==i?null:i;"spotfireDocumentEditor"===s&&(c=null),i===a&&(c=null),e.source.postMessage(JSON.stringify({messageId:r,result:c}),e.origin)}window.addEventListener("message",g),this.disposeEventHandlers=function(){window.removeEventListener("message",g),c.forEach((({callback:e,method:n,args:o})=>{const t=s[n];if("function"==typeof a[t]){const n=[...o];n.push(e),a[t].call(a,n)}})),c.length=0}}e.exports=SpotfireMessageHandler,o.g.SpotfireMessageHandler=SpotfireMessageHandler}},n={};function o(t){var r=n[t];if(void 0!==r)return r.exports;var s=n[t]={exports:{}};return e[t](s,s.exports,o),s.exports}o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}();o(32746)}();