🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@chili-publish/publisher-interface

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chili-publish/publisher-interface - npm Package Compare versions

Comparing version

to
0.3.6

2

dist/chiliInternalWrapper.min.js

@@ -1,2 +0,2 @@

(()=>{var e,t,r,n,o,i,c,a;(t=e||(e={})).Call="call",t.Reply="reply",t.Syn="syn",t.SynAck="synAck",t.Ack="ack",(n=r||(r={})).Fulfilled="fulfilled",n.Rejected="rejected",(i=o||(o={})).ConnectionDestroyed="ConnectionDestroyed",i.ConnectionTimeout="ConnectionTimeout",i.NoIframeSrc="NoIframeSrc",(c||(c={})).DataCloneError="DataCloneError",(a||(a={})).Message="message";var s=(e,t)=>{const r=[];let n=!1;return{destroy(o){n||(n=!0,t(`${e}: Destroying connection`),r.forEach((e=>{e(o)})))},onDestroy(e){n?e():r.push(e)}}},d=e=>(...t)=>{e&&console.log("[Penpal]",...t)};const u=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),l=e=>{const t=new Error;return Object.keys(e).forEach((r=>t[r]=e[r])),t};var g=(t,n,o)=>{const{localName:i,local:s,remote:d,originForSending:l,originForReceiving:g}=t;let w=!1;const S=t=>{if(t.source!==d||t.data.penpal!==e.Call)return;if("*"!==g&&t.origin!==g)return void o(`${i} received message from origin ${t.origin} which did not match expected origin ${g}`);const a=t.data,{methodName:s,args:S,id:h}=a;o(`${i}: Received ${s}() call`);const m=t=>n=>{if(o(`${i}: Sending ${s}() reply`),w)return void o(`${i}: Unable to send ${s}() reply due to destroyed connection`);const a={penpal:e.Reply,id:h,resolution:t,returnValue:n};t===r.Rejected&&n instanceof Error&&(a.returnValue=u(n),a.returnValueIsError=!0);try{d.postMessage(a,l)}catch(t){if(t.name===c.DataCloneError){const n={penpal:e.Reply,id:h,resolution:r.Rejected,returnValue:u(t),returnValueIsError:!0};d.postMessage(n,l)}throw t}};new Promise((e=>e(n[s].apply(n,S)))).then(m(r.Fulfilled),m(r.Rejected))};return s.addEventListener(a.Message,S),()=>{w=!0,s.removeEventListener(a.Message,S)}};let w=0;const S=e=>e?e.split("."):[],h=(e,t,r)=>{const n=S(t);return n.reduce(((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===n.length-1&&(e[t]=r),e[t])),e),e},m=(e,t)=>{const r={};return Object.keys(e).forEach((n=>{const o=e[n],i=((e,t)=>{const r=S(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof o&&Object.assign(r,m(o,i)),"function"==typeof o&&(r[i]=o)})),r},y=e=>{const t={};for(const r in e)h(t,r,e[r]);return t};var p=(t,n,i,c,s)=>{const{localName:d,local:u,remote:g,originForSending:S,originForReceiving:h}=n;let m=!1;s(`${d}: Connecting call sender`);const p=t=>(...n)=>{let i;s(`${d}: Sending ${t}() call`);try{g.closed&&(i=!0)}catch(e){i=!0}if(i&&c(),m){const e=new Error(`Unable to send ${t}() call due to destroyed connection`);throw e.code=o.ConnectionDestroyed,e}return new Promise(((o,i)=>{const c=++w,m=n=>{if(n.source!==g||n.data.penpal!==e.Reply||n.data.id!==c)return;if("*"!==h&&n.origin!==h)return void s(`${d} received message from origin ${n.origin} which did not match expected origin ${h}`);const w=n.data;s(`${d}: Received ${t}() reply`),u.removeEventListener(a.Message,m);let S=w.returnValue;w.returnValueIsError&&(S=l(S)),(w.resolution===r.Fulfilled?o:i)(S)};u.addEventListener(a.Message,m);const y={penpal:e.Call,id:c,methodName:t,args:n};g.postMessage(y,S)}))},v=i.reduce(((e,t)=>(e[t]=p(t),e)),{});return Object.assign(t,y(v)),()=>{m=!0}};var v=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout((()=>{const r=new Error(`Connection timed out after ${e}ms`);r.code=o.ConnectionTimeout,t(r)}),e)),()=>{clearTimeout(r)}},j=(t,r,n,o)=>{const{destroy:i,onDestroy:c}=n;return n=>{if(!(t instanceof RegExp?t.test(n.origin):"*"===t||t===n.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${n.origin} which did not match expected origin ${t}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");const a="null"===n.origin?"*":n.origin,s={penpal:e.Ack,methodNames:Object.keys(r)};window.parent.postMessage(s,a);const d={localName:"Child",local:window,remote:window.parent,originForSending:a,originForReceiving:n.origin},u=g(d,r,o);c(u);const l={},w=p(l,d,n.data.methodNames,i,o);return c(w),l}};var b,f,O=(t={})=>{const{parentOrigin:r="*",methods:n={},timeout:o,debug:i=!1}=t,c=d(i),u=s("Child",c),{destroy:l,onDestroy:g}=u,w=m(n),S=j(r,w,u,c);return{promise:new Promise(((t,n)=>{const i=v(o,l),s=r=>{if((()=>{try{clearTimeout()}catch(e){return!1}return!0})()&&r.source===parent&&r.data&&r.data.penpal===e.SynAck){const e=S(r);e&&(window.removeEventListener(a.Message,s),i(),t(e))}};window.addEventListener(a.Message,s),(()=>{c("Child: Handshake - Sending SYN");const t={penpal:e.Syn},n=r instanceof RegExp?"*":r;window.parent.postMessage(t,n)})(),g((e=>{window.removeEventListener(a.Message,s),e&&n(e)}))})),destroy(){l()}}};function E(e){return{isOk:!0,isError:!1,ok:e,error:void 0}}function C(e){return{isOk:!1,isError:!0,ok:void 0,error:e}}(f=b||(b={}))[f.error=0]="error",f[f.ok=1]="ok";const k=setInterval((()=>{null!=window.editorObject&&null!=window.OnEditorEvent&&$()}),500);let A;const $=()=>{clearInterval(k),A=O({methods:{alert:P,getDirtyState:F,nextPage:R,previousPage:N,setSelectedPage:I,getSelectedPage:L,getSelectedPageName:M,getNumPages:D,removeListener:x,addListener:G,setProperty:T,getObject:V,executeFunction:H,getPageSnapshot:K,getFrameSnapshot:Y,getFrameSubjectArea:U,setFrameSubjectArea:q,clearFrameSubjectArea:z,getAssetSubjectInfo:B,setAssetSubjectInfo:J,clearAssetSubjectInfo:Q,setVariableIsLocked:W}}),window.OnEditorEvent=(e,t)=>{A.promise.then((r=>{r.handleEvents(e,t)}))}},P=(e,t)=>{try{return window.editorObject.Alert(e,t),E(void 0)}catch(e){return C(e.toString())}},F=()=>{try{return E(window.editorObject.GetDirtyState())}catch(e){return C(e.toString())}},R=()=>{try{return window.editorObject.NextPage(),E(void 0)}catch(e){return C(e.toString())}},N=()=>{try{return window.editorObject.PreviousPage(),E(void 0)}catch(e){return C(e.toString())}},I=e=>{try{return window.editorObject.SetSelectedPage(e),E(void 0)}catch(e){return C(e.toString())}},L=()=>{try{return E(window.editorObject.GetSelectedPage())}catch(e){return C(e.toString())}},M=()=>{try{return E(window.editorObject.GetSelectedPageName())}catch(e){return C(e.toString())}},D=()=>{try{return E(window.editorObject.GetNumPages())}catch(e){return C(e.toString())}},x=e=>{try{return window.editorObject.RemoveListener(e),E(void 0)}catch(e){return C(e.toString())}},G=e=>{try{return window.editorObject.AddListener(e),E(void 0)}catch(e){return C(e.toString())}},V=e=>{try{return E(window.editorObject.GetObject(e))}catch(e){return C(e.toString())}},T=(e,t,r)=>{try{return window.editorObject.SetProperty(e,t,r),E(void 0)}catch(e){return C(e.toString())}},H=(e,t,r)=>{try{return E(window.editorObject.ExecuteFunction(e,t,...r))}catch(e){return C(e.toString())}},K=(e,t,r,n,o,i)=>{try{return E(window.editorObject.GetPageSnapshot(e,t,r,n,o,i))}catch(e){return C(e.toString())}},Y=(e,t,r)=>{try{return E(window.editorObject.GetFrameSnapshot(e,t,r))}catch(e){return C(e.toString())}},U=e=>{try{return E(window.editorObject.GetFrameSubjectArea(e))}catch(e){return C(e.toString())}},q=(e,t,r,n,o)=>{try{return window.editorObject.SetFrameSubjectArea(e,t,r,n,o),E(void 0)}catch(e){return C(e.toString())}},z=e=>{try{return window.editorObject.ClearFrameSubjectArea(e),E(void 0)}catch(e){return C(e.toString())}},B=e=>{try{return E(window.editorObject.GetAssetSubjectInfo(e))}catch(e){return C(e.toString())}},J=(e,t,r,n,o,i,c)=>{try{return window.editorObject.SetAssetSubjectInfo(e,t,r,n,o,i,c),E(void 0)}catch(e){return C(e.toString())}},Q=e=>{try{return window.editorObject.ClearAssetSubjectInfo(e),E(void 0)}catch(e){return C(e.toString())}},W=(e,t)=>{try{return window.editorObject.SetVariableIsLocked(e,t),E(void 0)}catch(e){return C(e.toString())}}})();
(()=>{var e,t,r,n,o,i,c,d;(t=e||(e={})).Call="call",t.Reply="reply",t.Syn="syn",t.SynAck="synAck",t.Ack="ack",(n=r||(r={})).Fulfilled="fulfilled",n.Rejected="rejected",(i=o||(o={})).ConnectionDestroyed="ConnectionDestroyed",i.ConnectionTimeout="ConnectionTimeout",i.NoIframeSrc="NoIframeSrc",(c||(c={})).DataCloneError="DataCloneError",(d||(d={})).Message="message";var a=(e,t)=>{const r=[];let n=!1;return{destroy(o){n||(n=!0,t(`${e}: Destroying connection`),r.forEach((e=>{e(o)})))},onDestroy(e){n?e():r.push(e)}}},s=e=>(...t)=>{e&&console.log("[Penpal]",...t)};const u=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),w=e=>{const t=new Error;return Object.keys(e).forEach((r=>t[r]=e[r])),t};var g=(t,n,o)=>{const{localName:i,local:a,remote:s,originForSending:w,originForReceiving:g}=t;let l=!1;const S=t=>{if(t.source!==s||t.data.penpal!==e.Call)return;if("*"!==g&&t.origin!==g)return void o(`${i} received message from origin ${t.origin} which did not match expected origin ${g}`);const d=t.data,{methodName:a,args:S,id:b}=d;o(`${i}: Received ${a}() call`);const j=t=>n=>{if(o(`${i}: Sending ${a}() reply`),l)return void o(`${i}: Unable to send ${a}() reply due to destroyed connection`);const d={penpal:e.Reply,id:b,resolution:t,returnValue:n};t===r.Rejected&&n instanceof Error&&(d.returnValue=u(n),d.returnValueIsError=!0);try{s.postMessage(d,w)}catch(t){if(t.name===c.DataCloneError){const n={penpal:e.Reply,id:b,resolution:r.Rejected,returnValue:u(t),returnValueIsError:!0};s.postMessage(n,w)}throw t}};new Promise((e=>e(n[a].apply(n,S)))).then(j(r.Fulfilled),j(r.Rejected))};return a.addEventListener(d.Message,S),()=>{l=!0,a.removeEventListener(d.Message,S)}};let l=0;const S=e=>e?e.split("."):[],b=(e,t,r)=>{const n=S(t);return n.reduce(((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===n.length-1&&(e[t]=r),e[t])),e),e},j=(e,t)=>{const r={};return Object.keys(e).forEach((n=>{const o=e[n],i=((e,t)=>{const r=S(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof o&&Object.assign(r,j(o,i)),"function"==typeof o&&(r[i]=o)})),r},h=e=>{const t={};for(const r in e)b(t,r,e[r]);return t};var m=(t,n,i,c,a)=>{const{localName:s,local:u,remote:g,originForSending:S,originForReceiving:b}=n;let j=!1;a(`${s}: Connecting call sender`);const m=t=>(...n)=>{let i;a(`${s}: Sending ${t}() call`);try{g.closed&&(i=!0)}catch(e){i=!0}if(i&&c(),j){const e=new Error(`Unable to send ${t}() call due to destroyed connection`);throw e.code=o.ConnectionDestroyed,e}return new Promise(((o,i)=>{const c=++l,j=n=>{if(n.source!==g||n.data.penpal!==e.Reply||n.data.id!==c)return;if("*"!==b&&n.origin!==b)return void a(`${s} received message from origin ${n.origin} which did not match expected origin ${b}`);const l=n.data;a(`${s}: Received ${t}() reply`),u.removeEventListener(d.Message,j);let S=l.returnValue;l.returnValueIsError&&(S=w(S)),(l.resolution===r.Fulfilled?o:i)(S)};u.addEventListener(d.Message,j);const h={penpal:e.Call,id:c,methodName:t,args:n};g.postMessage(h,S)}))},p=i.reduce(((e,t)=>(e[t]=m(t),e)),{});return Object.assign(t,h(p)),()=>{j=!0}};var p=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout((()=>{const r=new Error(`Connection timed out after ${e}ms`);r.code=o.ConnectionTimeout,t(r)}),e)),()=>{clearTimeout(r)}},y=(t,r,n,o)=>{const{destroy:i,onDestroy:c}=n;return n=>{if(!(t instanceof RegExp?t.test(n.origin):"*"===t||t===n.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${n.origin} which did not match expected origin ${t}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");const d="null"===n.origin?"*":n.origin,a={penpal:e.Ack,methodNames:Object.keys(r)};window.parent.postMessage(a,d);const s={localName:"Child",local:window,remote:window.parent,originForSending:d,originForReceiving:n.origin},u=g(s,r,o);c(u);const w={},l=m(w,s,n.data.methodNames,i,o);return c(l),w}};var v,O,f=(t={})=>{const{parentOrigin:r="*",methods:n={},timeout:o,debug:i=!1}=t,c=s(i),u=a("Child",c),{destroy:w,onDestroy:g}=u,l=j(n),S=y(r,l,u,c);return{promise:new Promise(((t,n)=>{const i=p(o,w),a=r=>{if((()=>{try{clearTimeout()}catch(e){return!1}return!0})()&&r.source===parent&&r.data&&r.data.penpal===e.SynAck){const e=S(r);e&&(window.removeEventListener(d.Message,a),i(),t(e))}};window.addEventListener(d.Message,a),(()=>{c("Child: Handshake - Sending SYN");const t={penpal:e.Syn},n=r instanceof RegExp?"*":r;window.parent.postMessage(t,n)})(),g((e=>{window.removeEventListener(d.Message,a),e&&n(e)}))})),destroy(){w()}}};function F(e){return{isOk:!0,isError:!1,ok:e,error:void 0}}function E(e){return{isOk:!1,isError:!0,ok:void 0,error:e}}(O=v||(v={}))[O.error=0]="error",O[O.ok=1]="ok",window.registeredFunctions=new Map,window.registeredEventFunctions=new Map;const P=setInterval((()=>{null!=window.editorObject&&null!=window.OnEditorEvent&&Z()}),500),A=(e,t)=>{try{return window.registeredFunctions.set(e,new Function("publisher","id",t)),F(void 0)}catch(e){return E(e.toString())}},k=(e,t)=>{try{return window.editorObject.AddListener(e),window.registeredEventFunctions.set(e,new Function("publisher","id",t)),F(void 0)}catch(e){return E(e.toString())}},C=e=>{try{const t=window.registeredFunctions.get(e);return null!=t?(t(window.publisher),F(void 0)):E(`Function ${e} not found`)}catch(e){return E(e.toString())}},I=(e,t)=>{try{return window.editorObject.Alert(e,t),F(void 0)}catch(e){return E(e.toString())}},$=()=>{try{return F(window.editorObject.GetDirtyState())}catch(e){return E(e.toString())}},N=()=>{try{return window.editorObject.NextPage(),F(void 0)}catch(e){return E(e.toString())}},R=()=>{try{return window.editorObject.PreviousPage(),F(void 0)}catch(e){return E(e.toString())}},L=e=>{try{return window.editorObject.SetSelectedPage(e),F(void 0)}catch(e){return E(e.toString())}},G=()=>{try{return F(window.editorObject.GetSelectedPage())}catch(e){return E(e.toString())}},M=()=>{try{return F(window.editorObject.GetSelectedPageName())}catch(e){return E(e.toString())}},D=()=>{try{return F(window.editorObject.GetNumPages())}catch(e){return E(e.toString())}},x=e=>{try{return window.editorObject.RemoveListener(e),F(void 0)}catch(e){return E(e.toString())}},V=e=>{try{return window.editorObject.AddListener(e),F(void 0)}catch(e){return E(e.toString())}},T=e=>{try{return F(window.editorObject.GetObject(e))}catch(e){return E(e.toString())}},H=(e,t,r)=>{try{return window.editorObject.SetProperty(e,t,r),F(void 0)}catch(e){return E(e.toString())}},K=(e,t,r)=>{try{return F(window.editorObject.ExecuteFunction(e,t,...r))}catch(e){return E(e.toString())}},Y=(e,t,r,n,o,i)=>{try{return F(window.editorObject.GetPageSnapshot(e,t,r,n,o,i))}catch(e){return E(e.toString())}},U=(e,t,r)=>{try{return F(window.editorObject.GetFrameSnapshot(e,t,r))}catch(e){return E(e.toString())}},q=e=>{try{return F(window.editorObject.GetFrameSubjectArea(e))}catch(e){return E(e.toString())}},z=(e,t,r,n,o)=>{try{return window.editorObject.SetFrameSubjectArea(e,t,r,n,o),F(void 0)}catch(e){return E(e.toString())}},B=e=>{try{return window.editorObject.ClearFrameSubjectArea(e),F(void 0)}catch(e){return E(e.toString())}},J=e=>{try{return F(window.editorObject.GetAssetSubjectInfo(e))}catch(e){return E(e.toString())}},Q=(e,t,r,n,o,i,c)=>{try{return window.editorObject.SetAssetSubjectInfo(e,t,r,n,o,i,c),F(void 0)}catch(e){return E(e.toString())}},W=e=>{try{return window.editorObject.ClearAssetSubjectInfo(e),F(void 0)}catch(e){return E(e.toString())}},X=(e,t)=>{try{return window.editorObject.SetVariableIsLocked(e,t),F(void 0)}catch(e){return E(e.toString())}},Z=()=>{clearInterval(P);const e=f({methods:{registerFunction:A,registerFunctionOnEvent:k,runRegisteredFunction:C,alert:I,getDirtyState:$,nextPage:N,previousPage:R,setSelectedPage:L,getSelectedPage:G,getSelectedPageName:M,getNumPages:D,removeListener:x,addListener:V,setProperty:H,getObject:T,executeFunction:K,getPageSnapshot:Y,getFrameSnapshot:U,getFrameSubjectArea:q,setFrameSubjectArea:z,clearFrameSubjectArea:B,getAssetSubjectInfo:J,setAssetSubjectInfo:Q,clearAssetSubjectInfo:W,setVariableIsLocked:X}});window.publisher={registerFunction:(e,t)=>{const r=A(e,t);if(r.isError)throw new Error(r.error);return r.ok},registerFunctionOnEvent:(e,t)=>{const r=k(e,t);if(r.isError)throw new Error(r.error);return r.ok},runRegisteredFunction:e=>{const t=C(e);if(t.isError)throw new Error(t.error);return t.ok},alert:window.editorObject.Alert,getDirtyState:window.editorObject.GetDirtyState,nextPage:window.editorObject.NextPage,previousPage:window.editorObject.PreviousPage,setSelectedPage:window.editorObject.SetSelectedPage,getSelectedPage:window.editorObject.GetSelectedPage,getSelectedPageName:window.editorObject.GetSelectedPageName,getNumPages:window.editorObject.GetNumPages,removeListener:window.editorObject.RemoveListener,addListener:window.editorObject.AddListener,getObject:window.editorObject.GetObject,setProperty:window.editorObject.SetProperty,executeFunction:window.editorObject.ExecuteFunction,getPageSnapshot:window.editorObject.GetPageSnapshot,getFrameSnapshot:window.editorObject.GetFrameSnapshot,getFrameSubjectArea:window.editorObject.GetFrameSubjectArea,setFrameSubjectArea:window.editorObject.SetFrameSubjectArea,clearFrameSubjectArea:window.editorObject.ClearFrameSubjectArea,getAssetSubjectInfo:window.editorObject.GetAssetSubjectInfo,setAssetSubjectInfo:window.editorObject.SetAssetSubjectInfo,clearAssetSubjectInfo:window.editorObject.ClearAssetSubjectInfo,setVariableIsLocked:window.editorObject.SetVariableIsLocked,editorObject:window.editorObject},window.OnEditorEvent=(t,r)=>{const n=window.registeredEventFunctions.get(t);null!=n&&n(window.publisher,r),e.promise.then((e=>{e.handleEvents(t,r)}))}}})();
//# sourceMappingURL=chiliInternalWrapper.min.js.map

@@ -1,2 +0,2 @@

var e,t,r,i,o,n,s,a,c,d,h,l,u={};e=u,t="PublisherInterface",r=()=>T,i=e=>T=e,Object.defineProperty(e,t,{get:r,set:i,enumerable:!0,configurable:!0}),(n=o||(o={})).Call="call",n.Reply="reply",n.Syn="syn",n.SynAck="synAck",n.Ack="ack",(a=s||(s={})).Fulfilled="fulfilled",a.Rejected="rejected",(d=c||(c={})).ConnectionDestroyed="ConnectionDestroyed",d.ConnectionTimeout="ConnectionTimeout",d.NoIframeSrc="NoIframeSrc",(h||(h={})).DataCloneError="DataCloneError",(l||(l={})).Message="message";var g=(e,t)=>{const r=[];let i=!1;return{destroy(o){i||(i=!0,t(`${e}: Destroying connection`),r.forEach((e=>{e(o)})))},onDestroy(e){i?e():r.push(e)}}},f=e=>(...t)=>{e&&console.log("[Penpal]",...t)};const b={"http:":"80","https:":"443"},v=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,m=["file:","data:"];var w=e=>{if(e&&m.find((t=>e.startsWith(t))))return"null";const t=document.location,r=v.exec(e);let i,o,n;r?(i=r[1]?r[1]:t.protocol,o=r[2],n=r[4]):(i=t.protocol,o=t.hostname,n=t.port);return`${i}//${o}${n&&n!==b[i]?`:${n}`:""}`};const p=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),y=e=>{const t=new Error;return Object.keys(e).forEach((r=>t[r]=e[r])),t};var E=(e,t,r)=>{const{localName:i,local:n,remote:a,originForSending:c,originForReceiving:d}=e;let u=!1;const g=e=>{if(e.source!==a||e.data.penpal!==o.Call)return;if("*"!==d&&e.origin!==d)return void r(`${i} received message from origin ${e.origin} which did not match expected origin ${d}`);const n=e.data,{methodName:l,args:g,id:f}=n;r(`${i}: Received ${l}() call`);const b=e=>t=>{if(r(`${i}: Sending ${l}() reply`),u)return void r(`${i}: Unable to send ${l}() reply due to destroyed connection`);const n={penpal:o.Reply,id:f,resolution:e,returnValue:t};e===s.Rejected&&t instanceof Error&&(n.returnValue=p(t),n.returnValueIsError=!0);try{a.postMessage(n,c)}catch(e){if(e.name===h.DataCloneError){const t={penpal:o.Reply,id:f,resolution:s.Rejected,returnValue:p(e),returnValueIsError:!0};a.postMessage(t,c)}throw e}};new Promise((e=>e(t[l].apply(t,g)))).then(b(s.Fulfilled),b(s.Rejected))};return n.addEventListener(l.Message,g),()=>{u=!0,n.removeEventListener(l.Message,g)}};let S=0;const P=e=>e?e.split("."):[],L=(e,t,r)=>{const i=P(t);return i.reduce(((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===i.length-1&&(e[t]=r),e[t])),e),e},j=(e,t)=>{const r={};return Object.keys(e).forEach((i=>{const o=e[i],n=((e,t)=>{const r=P(t||"");return r.push(e),(e=>e.join("."))(r)})(i,t);"object"==typeof o&&Object.assign(r,j(o,n)),"function"==typeof o&&(r[n]=o)})),r},D=e=>{const t={};for(const r in e)L(t,r,e[r]);return t};var A=(e,t,r,i,n)=>{const{localName:a,local:d,remote:h,originForSending:u,originForReceiving:g}=t;let f=!1;n(`${a}: Connecting call sender`);const b=e=>(...t)=>{let r;n(`${a}: Sending ${e}() call`);try{h.closed&&(r=!0)}catch(e){r=!0}if(r&&i(),f){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=c.ConnectionDestroyed,t}return new Promise(((r,i)=>{const c=++S,f=t=>{if(t.source!==h||t.data.penpal!==o.Reply||t.data.id!==c)return;if("*"!==g&&t.origin!==g)return void n(`${a} received message from origin ${t.origin} which did not match expected origin ${g}`);const u=t.data;n(`${a}: Received ${e}() reply`),d.removeEventListener(l.Message,f);let b=u.returnValue;u.returnValueIsError&&(b=y(b)),(u.resolution===s.Fulfilled?r:i)(b)};d.addEventListener(l.Message,f);const b={penpal:o.Call,id:c,methodName:e,args:t};h.postMessage(b,u)}))},v=r.reduce(((e,t)=>(e[t]=b(t),e)),{});return Object.assign(e,D(v)),()=>{f=!0}},k=(e,t,r,i,o)=>{const{destroy:n,onDestroy:s}=i;let a,c;const d={};return i=>{if("*"!==t&&i.origin!==t)return void o(`Parent: Handshake - Received ACK message from origin ${i.origin} which did not match expected origin ${t}`);o("Parent: Handshake - Received ACK");const h={localName:"Parent",local:window,remote:i.source,originForSending:r,originForReceiving:t};a&&a(),a=E(h,e,o),s(a),c&&c.forEach((e=>{delete d[e]})),c=i.data.methodNames;const l=A(d,h,c,n,o);return s(l),d}},F=(e,t,r,i)=>n=>{if(!n.source)return;if("*"!==r&&n.origin!==r)return void e(`Parent: Handshake - Received SYN message from origin ${n.origin} which did not match expected origin ${r}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:o.SynAck,methodNames:Object.keys(t)};n.source.postMessage(s,i)};var I=(e,t)=>{const{destroy:r,onDestroy:i}=t,o=setInterval((()=>{e.isConnected||(clearInterval(o),r())}),6e4);i((()=>{clearInterval(o)}))},$=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout((()=>{const r=new Error(`Connection timed out after ${e}ms`);r.code=c.ConnectionTimeout,t(r)}),e)),()=>{clearTimeout(r)}},C=e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");throw e.code=c.NoIframeSrc,e}},N=e=>{let{iframe:t,methods:r={},childOrigin:i,timeout:n,debug:s=!1}=e;const a=f(s),c=g("Parent",a),{onDestroy:d,destroy:h}=c;i||(C(t),i=w(t.src));const u="null"===i?"*":i,b=j(r),v=F(a,b,i,u),m=k(b,i,u,c,a);return{promise:new Promise(((e,r)=>{const i=$(n,h),s=r=>{if(r.source===t.contentWindow&&r.data)if(r.data.penpal!==o.Syn)if(r.data.penpal!==o.Ack);else{const t=m(r);t&&(i(),e(t))}else v(r)};window.addEventListener(l.Message,s),a("Parent: Awaiting handshake"),I(t,c),d((e=>{window.removeEventListener(l.Message,s),e&&r(e)}))})),destroy(){h()}}};var x,R=function(e,t,r,i){return new(r||(r=Promise))((function(o,n){function s(e){try{c(i.next(e))}catch(e){n(e)}}function a(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}c((i=i.apply(e,t||[])).next())}))},O=function(e,t,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(e):i?i.value:t.get(e)},M=function(e,t,r,i,o){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?o.call(e,r):o?o.value=r:t.set(e,r),r};class T{constructor(){this.chiliEventListenerCallbacks=new Map,this.debug=!1,this.creationTime="",x.set(this,null),this.getProperty=this.getObject}static build(e,t={}){var r;return R(this,void 0,void 0,(function*(){const i=new T;i.child=yield N({iframe:e,methods:{handleEvents:i.handleEvents.bind(i)},timeout:t.timeout,debug:t.penpalDebug}).promise,i.debug=null!==(r=t.penpalDebug)&&void 0!==r&&r,i.creationTime=(new Date).toLocaleString(),i.createDebugLog("build()");const o=t.events;if(null!=o&&o.length>0)for(const e of o)"string"==typeof e?i.addListener(e):i.addListener(e.name,e.func);return i}))}handleEvents(e,t){var r;return this.chiliEventListenerCallbacks.has(e)&&(null===(r=this.chiliEventListenerCallbacks.get(e))||void 0===r||r(t)),e}createDebugLog(e){this.debug&&console.log(`[PublisherInterface - ${this.creationTime}]`,`Creating ${e} call request`)}get editorObject(){return null==O(this,x,"f")&&M(this,x,{Alert:this.alert.bind(this),GetDirtyState:this.getDirtyState.bind(this),NextPage:this.nextPage.bind(this),PreviousPage:this.previousPage.bind(this),SetSelectedPage:this.setSelectedPage.bind(this),GetSelectedPage:this.getSelectedPage.bind(this),GetSelectedPageName:this.getSelectedPageName.bind(this),GetNumPages:this.getNumPages.bind(this),RemoveListener:this.removeListener.bind(this),AddListener:this.addListener.bind(this),GetObject:this.getObject.bind(this),SetProperty:this.setProperty.bind(this),ExecuteFunction:this.executeFunction.bind(this),GetPageSnapshot:this.getPageSnapshot.bind(this),GetFrameSnapshot:this.getFrameSnapshot.bind(this),GetFrameSubjectArea:this.getFrameSubjectArea.bind(this),SetFrameSubjectArea:this.setFrameSubjectArea.bind(this),ClearFrameSubjectArea:this.clearFrameSubjectArea.bind(this),GetAssetSubjectInfo:this.getAssetSubjectInfo.bind(this),SetAssetSubjectInfo:this.setAssetSubjectInfo.bind(this),ClearAssetSubjectInfo:this.clearAssetSubjectInfo.bind(this),SetVariableIsLocked:this.setVariableIsLocked.bind(this)},"f"),O(this,x,"f")}alert(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog("alert()");const r=yield this.child.alert(e,t);if(r.isError)throw new Error(r.error)}))}getDirtyState(){return R(this,void 0,void 0,(function*(){this.createDebugLog("getDirtyState()");const e=yield this.child.getDirtyState();if(e.isError)throw new Error(e.error);return e.ok}))}nextPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog("nextPage()");const e=yield this.child.nextPage();if(e.isError)throw new Error(e.error)}))}previousPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog("previousPage()");const e=yield this.child.previousPage();if(e.isError)throw new Error(e.error)}))}setSelectedPage(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("setSelectedPage()");const t=yield this.child.setSelectedPage(e);if(t.isError)throw new Error(t.error)}))}getSelectedPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog("getSelectedPage()");const e=yield this.child.getSelectedPage();if(e.isError)throw new Error(e.error);return e.ok}))}getSelectedPageName(){return R(this,void 0,void 0,(function*(){this.createDebugLog("getSelectedPageName()");const e=yield this.child.getSelectedPageName();if(e.isError)throw new Error(e.error);return e.ok}))}getNumPages(){return R(this,void 0,void 0,(function*(){this.createDebugLog("getNumPages()");const e=yield this.child.getNumPages();if(e.isError)throw new Error(e.error);return e.ok}))}removeListener(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("removeListener()"),this.chiliEventListenerCallbacks.delete(e);const t=yield this.child.removeListener(e);if(t.isError)throw new Error(t.error)}))}addListener(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog("addListener()"),this.chiliEventListenerCallbacks.set(e,null==t?t=>{null!=window.OnEditorEvent&&window.OnEditorEvent(e,t)}:t);const r=yield this.child.addListener(e);if(r.isError)throw new Error(r.error)}))}getObject(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("getObject()");const t=yield this.child.getObject(e);if(t.isError)throw new Error(t.error);return t.ok}))}setProperty(e,t,r){return R(this,void 0,void 0,(function*(){this.createDebugLog("setProperty()");const i=yield this.child.setProperty(e,t,r);if(i.isError)throw new Error(i.error)}))}executeFunction(e,t,...r){return R(this,void 0,void 0,(function*(){this.createDebugLog("executeFunction()");const i=yield this.child.executeFunction(e,t,r);if(i.isError)throw new Error(i.error);return i.ok}))}getPageSnapshot(e,t,r,i,o,n){return R(this,void 0,void 0,(function*(){this.createDebugLog("getPageSnapshot()");const s=yield this.child.getPageSnapshot(e,t,r,i,o,n);if(s.isError)throw new Error(s.error);return s.ok}))}getFrameSnapshot(e,t,r){return R(this,void 0,void 0,(function*(){this.createDebugLog("getFrameSnapshot()");const i=yield this.child.getFrameSnapshot(e,t,r);if(i.isError)throw new Error(i.error);return i.ok}))}getFrameSubjectArea(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("getFrameSubjectArea()");const t=yield this.child.getFrameSubjectArea(e);if(t.isError)throw new Error(t.error);return t.ok}))}setFrameSubjectArea(e,t,r,i,o){return R(this,void 0,void 0,(function*(){this.createDebugLog("setFrameSubjectArea()");const n=yield this.child.setFrameSubjectArea(e,t,r,i,o);if(n.isError)throw new Error(n.error)}))}clearFrameSubjectArea(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("clearFrameSubjectArea()");const t=yield this.child.clearFrameSubjectArea(e);if(t.isError)throw new Error(t.error)}))}getAssetSubjectInfo(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("getAssetSubjectInfo()");const t=yield this.child.getAssetSubjectInfo(e);if(t.isError)throw new Error(t.error);return t.ok}))}setAssetSubjectInfo(e,t,r,i,o,n,s){return R(this,void 0,void 0,(function*(){this.createDebugLog("setAssetSubjectInfo()");const a=yield this.child.setAssetSubjectInfo(e,t,r,i,o,n,s);if(a.isError)throw new Error(a.error)}))}clearAssetSubjectInfo(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("clearAssetSubjectInfo()");const t=yield this.child.clearAssetSubjectInfo(e);if(t.isError)throw new Error(t.error)}))}setVariableIsLocked(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog("setVariableIsLocked()");const r=yield this.child.setVariableIsLocked(e,t);if(r.isError)throw new Error(r.error)}))}}x=new WeakMap;export{T as PublisherInterface,u as default};
var e,t,r,i,o,n,s,c,a,d,h,u,l={};e=l,t="PublisherInterface",r=()=>T,i=e=>T=e,Object.defineProperty(e,t,{get:r,set:i,enumerable:!0,configurable:!0}),(n=o||(o={})).Call="call",n.Reply="reply",n.Syn="syn",n.SynAck="synAck",n.Ack="ack",(c=s||(s={})).Fulfilled="fulfilled",c.Rejected="rejected",(d=a||(a={})).ConnectionDestroyed="ConnectionDestroyed",d.ConnectionTimeout="ConnectionTimeout",d.NoIframeSrc="NoIframeSrc",(h||(h={})).DataCloneError="DataCloneError",(u||(u={})).Message="message";var g=(e,t)=>{const r=[];let i=!1;return{destroy(o){i||(i=!0,t(`${e}: Destroying connection`),r.forEach((e=>{e(o)})))},onDestroy(e){i?e():r.push(e)}}},f=e=>(...t)=>{e&&console.log("[Penpal]",...t)};const v={"http:":"80","https:":"443"},b=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,m=["file:","data:"];var w=e=>{if(e&&m.find((t=>e.startsWith(t))))return"null";const t=document.location,r=b.exec(e);let i,o,n;r?(i=r[1]?r[1]:t.protocol,o=r[2],n=r[4]):(i=t.protocol,o=t.hostname,n=t.port);return`${i}//${o}${n&&n!==v[i]?`:${n}`:""}`};const p=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),E=e=>{const t=new Error;return Object.keys(e).forEach((r=>t[r]=e[r])),t};var y=(e,t,r)=>{const{localName:i,local:n,remote:c,originForSending:a,originForReceiving:d}=e;let l=!1;const g=e=>{if(e.source!==c||e.data.penpal!==o.Call)return;if("*"!==d&&e.origin!==d)return void r(`${i} received message from origin ${e.origin} which did not match expected origin ${d}`);const n=e.data,{methodName:u,args:g,id:f}=n;r(`${i}: Received ${u}() call`);const v=e=>t=>{if(r(`${i}: Sending ${u}() reply`),l)return void r(`${i}: Unable to send ${u}() reply due to destroyed connection`);const n={penpal:o.Reply,id:f,resolution:e,returnValue:t};e===s.Rejected&&t instanceof Error&&(n.returnValue=p(t),n.returnValueIsError=!0);try{c.postMessage(n,a)}catch(e){if(e.name===h.DataCloneError){const t={penpal:o.Reply,id:f,resolution:s.Rejected,returnValue:p(e),returnValueIsError:!0};c.postMessage(t,a)}throw e}};new Promise((e=>e(t[u].apply(t,g)))).then(v(s.Fulfilled),v(s.Rejected))};return n.addEventListener(u.Message,g),()=>{l=!0,n.removeEventListener(u.Message,g)}};let S=0;const P=e=>e?e.split("."):[],L=(e,t,r)=>{const i=P(t);return i.reduce(((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===i.length-1&&(e[t]=r),e[t])),e),e},j=(e,t)=>{const r={};return Object.keys(e).forEach((i=>{const o=e[i],n=((e,t)=>{const r=P(t||"");return r.push(e),(e=>e.join("."))(r)})(i,t);"object"==typeof o&&Object.assign(r,j(o,n)),"function"==typeof o&&(r[n]=o)})),r},D=e=>{const t={};for(const r in e)L(t,r,e[r]);return t};var F=(e,t,r,i,n)=>{const{localName:c,local:d,remote:h,originForSending:l,originForReceiving:g}=t;let f=!1;n(`${c}: Connecting call sender`);const v=e=>(...t)=>{let r;n(`${c}: Sending ${e}() call`);try{h.closed&&(r=!0)}catch(e){r=!0}if(r&&i(),f){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=a.ConnectionDestroyed,t}return new Promise(((r,i)=>{const a=++S,f=t=>{if(t.source!==h||t.data.penpal!==o.Reply||t.data.id!==a)return;if("*"!==g&&t.origin!==g)return void n(`${c} received message from origin ${t.origin} which did not match expected origin ${g}`);const l=t.data;n(`${c}: Received ${e}() reply`),d.removeEventListener(u.Message,f);let v=l.returnValue;l.returnValueIsError&&(v=E(v)),(l.resolution===s.Fulfilled?r:i)(v)};d.addEventListener(u.Message,f);const v={penpal:o.Call,id:a,methodName:e,args:t};h.postMessage(v,l)}))},b=r.reduce(((e,t)=>(e[t]=v(t),e)),{});return Object.assign(e,D(b)),()=>{f=!0}},A=(e,t,r,i,o)=>{const{destroy:n,onDestroy:s}=i;let c,a;const d={};return i=>{if("*"!==t&&i.origin!==t)return void o(`Parent: Handshake - Received ACK message from origin ${i.origin} which did not match expected origin ${t}`);o("Parent: Handshake - Received ACK");const h={localName:"Parent",local:window,remote:i.source,originForSending:r,originForReceiving:t};c&&c(),c=y(h,e,o),s(c),a&&a.forEach((e=>{delete d[e]})),a=i.data.methodNames;const u=F(d,h,a,n,o);return s(u),d}},k=(e,t,r,i)=>n=>{if(!n.source)return;if("*"!==r&&n.origin!==r)return void e(`Parent: Handshake - Received SYN message from origin ${n.origin} which did not match expected origin ${r}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:o.SynAck,methodNames:Object.keys(t)};n.source.postMessage(s,i)};var I=(e,t)=>{const{destroy:r,onDestroy:i}=t,o=setInterval((()=>{e.isConnected||(clearInterval(o),r())}),6e4);i((()=>{clearInterval(o)}))},$=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout((()=>{const r=new Error(`Connection timed out after ${e}ms`);r.code=a.ConnectionTimeout,t(r)}),e)),()=>{clearTimeout(r)}},C=e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");throw e.code=a.NoIframeSrc,e}},N=e=>{let{iframe:t,methods:r={},childOrigin:i,timeout:n,debug:s=!1}=e;const c=f(s),a=g("Parent",c),{onDestroy:d,destroy:h}=a;i||(C(t),i=w(t.src));const l="null"===i?"*":i,v=j(r),b=k(c,v,i,l),m=A(v,i,l,a,c);return{promise:new Promise(((e,r)=>{const i=$(n,h),s=r=>{if(r.source===t.contentWindow&&r.data)if(r.data.penpal!==o.Syn)if(r.data.penpal!==o.Ack);else{const t=m(r);t&&(i(),e(t))}else b(r)};window.addEventListener(u.Message,s),c("Parent: Awaiting handshake"),I(t,a),d((e=>{window.removeEventListener(u.Message,s),e&&r(e)}))})),destroy(){h()}}};var R,x=function(e,t,r,i){return new(r||(r=Promise))((function(o,n){function s(e){try{a(i.next(e))}catch(e){n(e)}}function c(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,c)}a((i=i.apply(e,t||[])).next())}))},O=function(e,t,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(e):i?i.value:t.get(e)},M=function(e,t,r,i,o){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?o.call(e,r):o?o.value=r:t.set(e,r),r};class T{constructor(){this.chiliEventListenerCallbacks=new Map,this.debug=!1,this.creationTime="",R.set(this,null),this.getProperty=this.getObject}static build(e,t={}){var r;return x(this,void 0,void 0,(function*(){const i=new T;i.child=yield N({iframe:e,methods:{handleEvents:i.handleEvents.bind(i)},timeout:t.timeout,debug:t.penpalDebug}).promise,i.debug=null!==(r=t.penpalDebug)&&void 0!==r&&r,i.creationTime=(new Date).toLocaleString(),i.createDebugLog("build()");const o=t.events;if(null!=o&&o.length>0)for(const e of o)"string"==typeof e?i.addListener(e):i.addListener(e.name,e.func);return i}))}handleEvents(e,t){var r;return this.chiliEventListenerCallbacks.has(e)&&(null===(r=this.chiliEventListenerCallbacks.get(e))||void 0===r||r(t)),e}createDebugLog(e){this.debug&&console.log(`[PublisherInterface - ${this.creationTime}]`,`Creating ${e} call request`)}get editorObject(){return null==O(this,R,"f")&&M(this,R,{Alert:this.alert.bind(this),GetDirtyState:this.getDirtyState.bind(this),NextPage:this.nextPage.bind(this),PreviousPage:this.previousPage.bind(this),SetSelectedPage:this.setSelectedPage.bind(this),GetSelectedPage:this.getSelectedPage.bind(this),GetSelectedPageName:this.getSelectedPageName.bind(this),GetNumPages:this.getNumPages.bind(this),RemoveListener:this.removeListener.bind(this),AddListener:this.addListener.bind(this),GetObject:this.getObject.bind(this),SetProperty:this.setProperty.bind(this),ExecuteFunction:this.executeFunction.bind(this),GetPageSnapshot:this.getPageSnapshot.bind(this),GetFrameSnapshot:this.getFrameSnapshot.bind(this),GetFrameSubjectArea:this.getFrameSubjectArea.bind(this),SetFrameSubjectArea:this.setFrameSubjectArea.bind(this),ClearFrameSubjectArea:this.clearFrameSubjectArea.bind(this),GetAssetSubjectInfo:this.getAssetSubjectInfo.bind(this),SetAssetSubjectInfo:this.setAssetSubjectInfo.bind(this),ClearAssetSubjectInfo:this.clearAssetSubjectInfo.bind(this),SetVariableIsLocked:this.setVariableIsLocked.bind(this)},"f"),O(this,R,"f")}registerFunction(e,t){return x(this,void 0,void 0,(function*(){this.createDebugLog("registerFunction()");const r=yield this.child.registerFunction(e,t);if(r.isError)throw new Error(r.error)}))}registerFunctionOnEvent(e,t){return x(this,void 0,void 0,(function*(){this.createDebugLog("registerFunction()");const r=yield this.child.registerFunctionOnEvent(e,t);if(r.isError)throw new Error(r.error)}))}runRegisteredFunction(e){return x(this,void 0,void 0,(function*(){this.createDebugLog("runReisteredFunction()");const t=yield this.child.runRegisteredFunction(e);if(t.isError)throw new Error(t.error);return t.ok}))}alert(e,t){return x(this,void 0,void 0,(function*(){this.createDebugLog("alert()");const r=yield this.child.alert(e,t);if(r.isError)throw new Error(r.error)}))}getDirtyState(){return x(this,void 0,void 0,(function*(){this.createDebugLog("getDirtyState()");const e=yield this.child.getDirtyState();if(e.isError)throw new Error(e.error);return e.ok}))}nextPage(){return x(this,void 0,void 0,(function*(){this.createDebugLog("nextPage()");const e=yield this.child.nextPage();if(e.isError)throw new Error(e.error)}))}previousPage(){return x(this,void 0,void 0,(function*(){this.createDebugLog("previousPage()");const e=yield this.child.previousPage();if(e.isError)throw new Error(e.error)}))}setSelectedPage(e){return x(this,void 0,void 0,(function*(){this.createDebugLog("setSelectedPage()");const t=yield this.child.setSelectedPage(e);if(t.isError)throw new Error(t.error)}))}getSelectedPage(){return x(this,void 0,void 0,(function*(){this.createDebugLog("getSelectedPage()");const e=yield this.child.getSelectedPage();if(e.isError)throw new Error(e.error);return e.ok}))}getSelectedPageName(){return x(this,void 0,void 0,(function*(){this.createDebugLog("getSelectedPageName()");const e=yield this.child.getSelectedPageName();if(e.isError)throw new Error(e.error);return e.ok}))}getNumPages(){return x(this,void 0,void 0,(function*(){this.createDebugLog("getNumPages()");const e=yield this.child.getNumPages();if(e.isError)throw new Error(e.error);return e.ok}))}removeListener(e){return x(this,void 0,void 0,(function*(){this.createDebugLog("removeListener()"),this.chiliEventListenerCallbacks.delete(e);const t=yield this.child.removeListener(e);if(t.isError)throw new Error(t.error)}))}addListener(e,t){return x(this,void 0,void 0,(function*(){this.createDebugLog("addListener()"),this.chiliEventListenerCallbacks.set(e,null==t?t=>{null!=window.OnEditorEvent&&window.OnEditorEvent(e,t)}:t);const r=yield this.child.addListener(e);if(r.isError)throw new Error(r.error)}))}getObject(e){return x(this,void 0,void 0,(function*(){this.createDebugLog("getObject()");const t=yield this.child.getObject(e);if(t.isError)throw new Error(t.error);return t.ok}))}setProperty(e,t,r){return x(this,void 0,void 0,(function*(){this.createDebugLog("setProperty()");const i=yield this.child.setProperty(e,t,r);if(i.isError)throw new Error(i.error)}))}executeFunction(e,t,...r){return x(this,void 0,void 0,(function*(){this.createDebugLog("executeFunction()");const i=yield this.child.executeFunction(e,t,r);if(i.isError)throw new Error(i.error);return i.ok}))}getPageSnapshot(e,t,r,i,o,n){return x(this,void 0,void 0,(function*(){this.createDebugLog("getPageSnapshot()");const s=yield this.child.getPageSnapshot(e,t,r,i,o,n);if(s.isError)throw new Error(s.error);return s.ok}))}getFrameSnapshot(e,t,r){return x(this,void 0,void 0,(function*(){this.createDebugLog("getFrameSnapshot()");const i=yield this.child.getFrameSnapshot(e,t,r);if(i.isError)throw new Error(i.error);return i.ok}))}getFrameSubjectArea(e){return x(this,void 0,void 0,(function*(){this.createDebugLog("getFrameSubjectArea()");const t=yield this.child.getFrameSubjectArea(e);if(t.isError)throw new Error(t.error);return t.ok}))}setFrameSubjectArea(e,t,r,i,o){return x(this,void 0,void 0,(function*(){this.createDebugLog("setFrameSubjectArea()");const n=yield this.child.setFrameSubjectArea(e,t,r,i,o);if(n.isError)throw new Error(n.error)}))}clearFrameSubjectArea(e){return x(this,void 0,void 0,(function*(){this.createDebugLog("clearFrameSubjectArea()");const t=yield this.child.clearFrameSubjectArea(e);if(t.isError)throw new Error(t.error)}))}getAssetSubjectInfo(e){return x(this,void 0,void 0,(function*(){this.createDebugLog("getAssetSubjectInfo()");const t=yield this.child.getAssetSubjectInfo(e);if(t.isError)throw new Error(t.error);return t.ok}))}setAssetSubjectInfo(e,t,r,i,o,n,s){return x(this,void 0,void 0,(function*(){this.createDebugLog("setAssetSubjectInfo()");const c=yield this.child.setAssetSubjectInfo(e,t,r,i,o,n,s);if(c.isError)throw new Error(c.error)}))}clearAssetSubjectInfo(e){return x(this,void 0,void 0,(function*(){this.createDebugLog("clearAssetSubjectInfo()");const t=yield this.child.clearAssetSubjectInfo(e);if(t.isError)throw new Error(t.error)}))}setVariableIsLocked(e,t){return x(this,void 0,void 0,(function*(){this.createDebugLog("setVariableIsLocked()");const r=yield this.child.setVariableIsLocked(e,t);if(r.isError)throw new Error(r.error)}))}}R=new WeakMap;export{T as PublisherInterface,l as default};
//# sourceMappingURL=PublisherInterface.min.js.map

@@ -34,2 +34,22 @@ export type buildOptions = {

/**
* Register a custom function on the iframe side. The function takes one parameter: publisher. This function has access to the window. You can access other custom functions registered using window.registeredFunctions, which is a Map.
*
* @param name - The name of the function to register.
* @param body - The body of the function.
*/
registerFunction(name: string, body: string): Promise<void>;
/**
* Register a custom function on the iframe side that runs when an event is called. The function takes two parameters: publisher and id. This function has access to the window. You can access other custom functions registered using window.registeredFunctions, which is a Map.
*
* @param eventName - The name of the event to trigger the function.
* @param body - The body of the function.
*/
registerFunctionOnEvent(eventName: string, body: string): Promise<void>;
/**
* Runs function that was registered originally by reisterFunction on the iframe side.
*
* @param name - The name of the functin to run.
*/
runRegisteredFunction(name: string): Promise<string | number | boolean | object | null | undefined>;
/**
* Displays a modal box within the editor UI containing a title with a message.

@@ -36,0 +56,0 @@ *

@@ -131,2 +131,38 @@ var $7i1sb$penpal = require("penpal");

/**
* Register a custom function on the iframe side. The function takes one parameter: publisher. This function has access to the window. You can access other custom functions registered using window.registeredFunctions, which is a Map.
*
* @param name - The name of the function to register.
* @param body - The body of the function.
*/ registerFunction(name, body) {
return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("registerFunction()");
const response = yield this.child.registerFunction(name, body);
if (response.isError) throw new Error(response.error);
});
}
/**
* Register a custom function on the iframe side that runs when an event is called. The function takes two parameters: publisher and id. This function has access to the window. You can access other custom functions registered using window.registeredFunctions, which is a Map.
*
* @param eventName - The name of the event to trigger the function.
* @param body - The body of the function.
*/ registerFunctionOnEvent(eventName, body) {
return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("registerFunction()");
const response = yield this.child.registerFunctionOnEvent(eventName, body);
if (response.isError) throw new Error(response.error);
});
}
/**
* Runs function that was registered originally by reisterFunction on the iframe side.
*
* @param name - The name of the functin to run.
*/ runRegisteredFunction(name) {
return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("runReisteredFunction()");
const response = yield this.child.runRegisteredFunction(name);
if (response.isError) throw new Error(response.error);
return response.ok;
});
}
/**
* Displays a modal box within the editor UI containing a title with a message.

@@ -133,0 +169,0 @@ *

{
"name": "@chili-publish/publisher-interface",
"version": "0.3.5",
"version": "0.3.6",
"author": "chili-publish",

@@ -5,0 +5,0 @@ "description": "PublisherInterface is a class object that allows you to interact with the CHILI Publisher editorObject via postMessage without the complexity of postMessage.",

@@ -15,6 +15,6 @@ # Publisher Interface

## Documentation
You can find complete documentation on the [wiki](https://github.com/chili-publish/publisher-interface/wiki/Converting-To-Publisher-Interface)
You can find complete documentation on the [wiki](https://github.com/chili-publish/publisher-interface/wiki)
* [Installation](#installation) - Easy npm install.
* [Getting Started](#getting-started) - A very quick tutorial to get you started.
* [Debugging](#debugging) - Things gone wrong, check this out.
* [Integrating Publisher](https://github.com/chili-publish/publisher-interface/wiki/Integrating-Publisher) - A much longer tutorial for those starting a new project with Publisher.

@@ -89,7 +89,7 @@ * [Why I Cannot Use editorObject](https://github.com/chili-publish/publisher-interface/wiki/Why-I-Cannot-Use-editorObject) - A description of why `editorObject` can no longer be used when communicating with an `<iframe>`.

Here is a complete example:
In simple use cases, the below example will work well.
```html
<body>
<iframe id="editor-iframe" style="width:1200px; height:800px"
src="https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G07gMFMq07X+SG2o8KlW8oAeZGvqoB1a0YvkbeZU1wJK15aIhANgZmhg+13NQlxpBEq7Q=="></iframe>
src="https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G07gMFMq07X+SG2o8KlW8oAeZGqoB1a0YkbeZU1wJK15aIhANgZmhg+13NQlxpBEq7Q=="></iframe>
<script type="module">

@@ -110,3 +110,46 @@ import {PublisherInterface} from 'https://unpkg.com/@chili-publish/publisher-interface@latest/dist/PublisherInterface.min.js';

<br/>
When dealing with larger applications, it's important to ensure that the `iframe` and the `PublisherInterface` build method are called in the same JavaScript event loop. To do this, follow these steps:
1. Create the `iframe` element and set its `src` attribute.
2. Pass the `iframe` element to the `build` method of `PublisherInterface` and capture the promise returned from the method.
3. Append the `iframe` element to the DOM.
4. Await the promise captured in step 2 and assign it to a variable that can be used throughout your application.
Example Code:
```html
<body>
<script type="module">
import {PublisherInterface} from 'https://unpkg.com/@chili-publish/publisher-interface@latest/dist/PublisherInterface.min.js';
document.addEventListener("DOMContentLoaded", async () => {
(async () => {
const iframe = document.createElement("iframe");
iframe.src = "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G07gMFMq07X+SG2o8KlW8oAeZGqoB1a0YkbeZU1wJK15aIhANgZmhg+13NQlxpBEq7Q==";
const publisherPromise = PublisherInterface.build(iframe);
document.body.appendChild(iframe);
const publisher = await publisherPromise;
const documentName = await publisher.getObject("document.name");
console.log(documentName);
})();
});
</script>
</body>
```
## Debugging
To enable debugging for the underlying library, pass {penpalDebug: true} as the buildOptions in your build function.
```javascript
PublisherInterface.build(iframe, {penpalDebug: true});
```
This will display messages in the console from Penpal about the communication between the iframe and the main page.
If there's a possibility of a failure to connect, you can set a timeout. If the connection is not established before the timeout, an exception will be thrown. In the example below, the build method will throw a timeout after 10 seconds if no connection is established.
```javascript
PublisherInterface.build(iframe, {penpalDebug: true, timeout: 10000});
```
<br/>
To read more, check out our [documentation](#documentation).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet