@web-applets/sdk 0.2.2 → 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.
Files changed (31) hide show
  1. package/dist/{sdk/src/applets → applets}/applet-scope.js +1 -1
  2. package/dist/elements/applet-frame.js +1 -1
  3. package/dist/{sdk/src/utils.d.ts → utils.d.ts} +1 -0
  4. package/dist/{sdk/src/utils.js → utils.js} +3 -0
  5. package/dist/web-applets.min.js +1 -1
  6. package/package.json +1 -1
  7. package/dist/sdk/src/elements/applet-frame.js +0 -111
  8. package/dist/utils/common-utils.d.mts +0 -1
  9. package/dist/utils/common-utils.mjs +0 -3
  10. /package/dist/{sdk/src/applets → applets}/actions.d.ts +0 -0
  11. /package/dist/{sdk/src/applets → applets}/actions.js +0 -0
  12. /package/dist/{sdk/src/applets → applets}/applet-factory.d.ts +0 -0
  13. /package/dist/{sdk/src/applets → applets}/applet-factory.js +0 -0
  14. /package/dist/{sdk/src/applets → applets}/applet-scope.d.ts +0 -0
  15. /package/dist/{sdk/src/applets → applets}/applet.d.ts +0 -0
  16. /package/dist/{sdk/src/applets → applets}/applet.js +0 -0
  17. /package/dist/{sdk/src/applets → applets}/errors.d.ts +0 -0
  18. /package/dist/{sdk/src/applets → applets}/errors.js +0 -0
  19. /package/dist/{sdk/src/applets → applets}/events.d.ts +0 -0
  20. /package/dist/{sdk/src/applets → applets}/events.js +0 -0
  21. /package/dist/{sdk/src/constants.d.ts → constants.d.ts} +0 -0
  22. /package/dist/{sdk/src/constants.js → constants.js} +0 -0
  23. /package/dist/{sdk/src/debug.d.ts → debug.d.ts} +0 -0
  24. /package/dist/{sdk/src/debug.js → debug.js} +0 -0
  25. /package/dist/{sdk/src/elements → elements}/applet-frame.d.ts +0 -0
  26. /package/dist/{sdk/src/index.d.ts → index.d.ts} +0 -0
  27. /package/dist/{sdk/src/index.js → index.js} +0 -0
  28. /package/dist/{sdk/src/messages.d.ts → messages.d.ts} +0 -0
  29. /package/dist/{sdk/src/messages.js → messages.js} +0 -0
  30. /package/dist/{sdk/src/polyfill.d.ts → polyfill.d.ts} +0 -0
  31. /package/dist/{sdk/src/polyfill.js → polyfill.js} +0 -0
@@ -13,7 +13,7 @@ var _AppletScope_instances, _AppletScope_actionHandlers, _AppletScope_manifest,
13
13
  import { debug } from '../debug.js';
14
14
  import { AppletEvent } from './events.js';
15
15
  import { dispatchEventAndHandler } from '../utils.js';
16
- import { isEmpty } from '../../../utils/common-utils.mjs';
16
+ import { isEmpty } from '../utils.js';
17
17
  export class AppletScope extends EventTarget {
18
18
  constructor(manifest) {
19
19
  super();
@@ -1,4 +1,4 @@
1
- (()=>{var d=class extends Error{constructor(t){super(t),this.name="AppletExecutionError"}},m=class extends Error{constructor(t){super(t),this.name="AppletConnectionError"}};function c(o){typeof this[`on${o.type}`]=="function"&&this[`on${o.type}`](o),this.dispatchEvent(o)}var r=class extends Event{constructor(t,e){super(t,{bubbles:e?.bubbles,composed:e?.composed,cancelable:e?.cancelable}),this.data=e?.data,this.actions=e?.actions}};function T(o,...t){}var a={log:T};var A=class extends EventTarget{#s;#o={};#t;#i;#n;#e;#a;#r;#p;constructor(t){super(),a.log("Applet","Constructor called"),this.#s=t,this.#n=c.bind(this),this.#c();let e=s=>{s.source===this.#s&&"type"in s.data&&s.data.type==="appletconnect"&&(a.log("Applet","Recieved message",s.data),this.#c(),this.removeEventListener("message",e))};window.addEventListener("message",e)}#c(){this.#e&&this.#e.close();let t=new MessageChannel,e={type:"appletconnect"};a.log("Applet","Send message",e),this.#e=t.port1,this.#e.onmessage=this.#h.bind(this),this.#s.postMessage(e,"*",[t.port2]),this.#a=this.#e.postMessage.bind(this.#e)}#h(t){let e=t.data;switch(a.log("Applet","Recieved message",e),e.type){case"register":let s=e;this.#t=s.manifest;let n=new r("connect");this.#n(n),this.#o=s.actions,this.#d(s.actions),this.#i=s.data,this.#l(s.data);break;case"data":let i=e;this.#i=i.data,this.#l(i.data);break;case"resize":let p=e;this.#r=p.width,this.#p=p.height;let h=new r("resize");this.#n(h);break;case"actions":let g=e;this.#o=g.actions,this.#d(g.actions);break}}#l(t){let e=new r("data",{data:t});this.#n(e)}#d(t){let e=new r("actions",{actions:t});this.#n(e)}async sendAction(t,e){let s={id:crypto.randomUUID(),type:"action",actionId:t,arguments:e};return new Promise((n,i)=>{this.#a(s);let p=setTimeout(()=>{i(new d(`Applet action handler failed to complete before timeout (${1e4}ms)`))},1e4),h=g=>{let l=g.data;if(["actioncomplete","actionerror"].includes(l.type)&&"id"in l&&l.id===s.id)if(this.#e.removeEventListener("message",h),clearTimeout(p),l.type==="actionerror"){let w=l;i(new d(w.message))}else n()};this.#e.addEventListener("message",h)})}get data(){return this.#i}set data(t){this.#i=t;let e={type:"data",data:t};this.#a(e)}get window(){return this.#s}get manifest(){return this.#t}get actions(){return this.#o}get width(){return this.#r}get height(){return this.#p}};function v(o){return Object.keys(o).length===0}var u=class extends EventTarget{#s={};#o;#t;#i;#n;#e;#a;#r;constructor(t){super(),a.log("AppletScope","Constructor called"),this.#n=c.bind(this),t&&(this.#o=t);let e=n=>{if(n.source===window.parent&&n.data.type==="appletconnect"&&n.ports&&n.ports.length>0){a.log("AppletScope","Recieved message",n.data);let i=n.ports[0];this.#e=i.postMessage.bind(i),i.onmessage=this.#c.bind(this),this.removeEventListener("message",e),this.#p()}};window.addEventListener("message",e);let s={type:"appletconnect"};window.parent.postMessage(s,"*"),a.log("AppletScope","Send message",s)}async#p(){let t=this.manifest??await this.#g();this.#o=t||{},this.#t=this.#t||t?.actions||{};let e={type:"register",manifest:this.#o,actions:this.#t,data:this.#i};this.#e(e),a.log("AppletScope","Send message",e);let s=new r("connect");this.#n(s),this.#l()}#c(t){let e=t.data;switch(a.log("AppletScope","Recieved message",e),e.type){case"data":"data"in e&&(this.data=e.data);break;case"action":"type"in e&&e.type==="action"&&"id"in e&&typeof e.id=="string"&&"actionId"in e&&typeof e.actionId=="string"&&"arguments"in e&&this.#h(e);break}}async#h(t){let{actionId:e,arguments:s,id:n}=t;if(Object.keys(this.#s).includes(e))try{await this.#s[e](s);let i={type:"actioncomplete",id:n};this.#e(i)}catch(i){let p={type:"actionerror",id:n,message:i.message};this.#e(p),console.error(i)}}#l(){new ResizeObserver(e=>{for(let s of e)this.#d({width:s.contentRect.width,height:s.contentRect.height})}).observe(document.querySelector("html"))}#d({width:t,height:e}){this.#a=t,this.#r=e;let s={type:"resize",width:t,height:e};a.log("AppletScope","Send message",s),this.#e(s)}async#g(){let t=document.querySelector('link[rel="manifest"]');if(!t){console.warn("No manifest link found");return}try{let s=await(await fetch(t.href)).json();for(let n in s.actions){let i=s.actions[n];i.params_schema&&!v(this.#t.params_schema)&&(i.params_schema=void 0)}return s}catch{return}}setActionHandler(t,e){this.#s[t]=e}defineAction(t,e){let{handler:s,...n}=e;s&&(this.#s[t]=s),this.actions={...this.actions,[t]:n}}set actions(t){if(!t)return;this.#t=t;let e={type:"actions",actions:this.#t};a.log("AppletScope","Send message",e),this.#e&&this.#e(e);let s=new r("actions",{actions:t});setTimeout(()=>this.#n(s),1)}get actions(){return this.#t}get manifest(){return this.#o}get actionHandlers(){return this.#s}set actionHandlers(t){this.#s=t}set data(t){this.#i=t;let e={type:"data",data:t};a.log("AppletScope","Send message",e),this.#e&&this.#e(e);let s=new r("data",{data:t});setTimeout(()=>this.#n(s),1)}get data(){return this.#i}get width(){return this.#a}get height(){return this.#r}};var f=class{async connect(t){return new Promise((e,s)=>{let n=new A(t),i=setTimeout(()=>{s(new m(`Applet failed to connect before the timeout was reached (${1e4}ms)`))},1e4),p=()=>{e(n),n.removeEventListener("connect",p),clearTimeout(i)};n.addEventListener("connect",p)})}register(t){return new u(t)}};var b=new f;var E=class extends HTMLElement{#s;#o;#t;#i=c.bind(this);#n=document.createElement("iframe");static{this.observedAttributes=["src"]}connectedCallback(){this.#s=this.attachShadow({mode:"closed"}),this.#s.appendChild(this.#n);let t=document.createElement("style");t.textContent=this.styles,this.#s.appendChild(t),this.src=this.getAttribute("src")}get contentWindow(){return this.#n.contentWindow}set src(t){this.#o=t,this.#t=void 0,this.#e(t)}get src(){return this.#o||""}attributeChangedCallback(t,e,s){t==="src"&&(this.src=s)}async#e(t){this.#n.src=t;let e=this.#n.contentWindow;e&&(this.#t=await b.connect(e),this.#t.ondata=s=>{this.#i(s)},this.#t.onresize=s=>{this.#a({width:this.#t.width,height:this.#t.height})},this.#t.onactions=s=>{this.#i(s)},this.#i(new Event("load")),this.load&&typeof this.load=="function"&&this.onload(new Event("load")))}get applet(){return this.#t}set data(t){if(this.applet)this.applet.data=t;else{let e=()=>{this.applet&&(this.applet.data=t),this.removeEventListener("load",e)};this.addEventListener("load",e)}}#a(t){this.style.height=`${t.height}px`}get styles(){return`
1
+ (()=>{var d=class extends Error{constructor(t){super(t),this.name="AppletExecutionError"}},m=class extends Error{constructor(t){super(t),this.name="AppletConnectionError"}};function c(o){typeof this[`on${o.type}`]=="function"&&this[`on${o.type}`](o),this.dispatchEvent(o)}function y(o){return Object.keys(o).length===0}var r=class extends Event{constructor(t,e){super(t,{bubbles:e?.bubbles,composed:e?.composed,cancelable:e?.cancelable}),this.data=e?.data,this.actions=e?.actions}};function T(o,...t){}var a={log:T};var A=class extends EventTarget{#s;#o={};#t;#i;#n;#e;#a;#r;#p;constructor(t){super(),a.log("Applet","Constructor called"),this.#s=t,this.#n=c.bind(this),this.#c();let e=s=>{s.source===this.#s&&"type"in s.data&&s.data.type==="appletconnect"&&(a.log("Applet","Recieved message",s.data),this.#c(),this.removeEventListener("message",e))};window.addEventListener("message",e)}#c(){this.#e&&this.#e.close();let t=new MessageChannel,e={type:"appletconnect"};a.log("Applet","Send message",e),this.#e=t.port1,this.#e.onmessage=this.#h.bind(this),this.#s.postMessage(e,"*",[t.port2]),this.#a=this.#e.postMessage.bind(this.#e)}#h(t){let e=t.data;switch(a.log("Applet","Recieved message",e),e.type){case"register":let s=e;this.#t=s.manifest;let n=new r("connect");this.#n(n),this.#o=s.actions,this.#d(s.actions),this.#i=s.data,this.#l(s.data);break;case"data":let i=e;this.#i=i.data,this.#l(i.data);break;case"resize":let p=e;this.#r=p.width,this.#p=p.height;let h=new r("resize");this.#n(h);break;case"actions":let g=e;this.#o=g.actions,this.#d(g.actions);break}}#l(t){let e=new r("data",{data:t});this.#n(e)}#d(t){let e=new r("actions",{actions:t});this.#n(e)}async sendAction(t,e){let s={id:crypto.randomUUID(),type:"action",actionId:t,arguments:e};return new Promise((n,i)=>{this.#a(s);let p=setTimeout(()=>{i(new d(`Applet action handler failed to complete before timeout (${1e4}ms)`))},1e4),h=g=>{let l=g.data;if(["actioncomplete","actionerror"].includes(l.type)&&"id"in l&&l.id===s.id)if(this.#e.removeEventListener("message",h),clearTimeout(p),l.type==="actionerror"){let w=l;i(new d(w.message))}else n()};this.#e.addEventListener("message",h)})}get data(){return this.#i}set data(t){this.#i=t;let e={type:"data",data:t};this.#a(e)}get window(){return this.#s}get manifest(){return this.#t}get actions(){return this.#o}get width(){return this.#r}get height(){return this.#p}};var u=class extends EventTarget{#s={};#o;#t;#i;#n;#e;#a;#r;constructor(t){super(),a.log("AppletScope","Constructor called"),this.#n=c.bind(this),t&&(this.#o=t);let e=n=>{if(n.source===window.parent&&n.data.type==="appletconnect"&&n.ports&&n.ports.length>0){a.log("AppletScope","Recieved message",n.data);let i=n.ports[0];this.#e=i.postMessage.bind(i),i.onmessage=this.#c.bind(this),this.removeEventListener("message",e),this.#p()}};window.addEventListener("message",e);let s={type:"appletconnect"};window.parent.postMessage(s,"*"),a.log("AppletScope","Send message",s)}async#p(){let t=this.manifest??await this.#g();this.#o=t||{},this.#t=this.#t||t?.actions||{};let e={type:"register",manifest:this.#o,actions:this.#t,data:this.#i};this.#e(e),a.log("AppletScope","Send message",e);let s=new r("connect");this.#n(s),this.#l()}#c(t){let e=t.data;switch(a.log("AppletScope","Recieved message",e),e.type){case"data":"data"in e&&(this.data=e.data);break;case"action":"type"in e&&e.type==="action"&&"id"in e&&typeof e.id=="string"&&"actionId"in e&&typeof e.actionId=="string"&&"arguments"in e&&this.#h(e);break}}async#h(t){let{actionId:e,arguments:s,id:n}=t;if(Object.keys(this.#s).includes(e))try{await this.#s[e](s);let i={type:"actioncomplete",id:n};this.#e(i)}catch(i){let p={type:"actionerror",id:n,message:i.message};this.#e(p),console.error(i)}}#l(){new ResizeObserver(e=>{for(let s of e)this.#d({width:s.contentRect.width,height:s.contentRect.height})}).observe(document.querySelector("html"))}#d({width:t,height:e}){this.#a=t,this.#r=e;let s={type:"resize",width:t,height:e};a.log("AppletScope","Send message",s),this.#e(s)}async#g(){let t=document.querySelector('link[rel="manifest"]');if(!t){console.warn("No manifest link found");return}try{let s=await(await fetch(t.href)).json();for(let n in s.actions){let i=s.actions[n];i.params_schema&&!y(this.#t.params_schema)&&(i.params_schema=void 0)}return s}catch{return}}setActionHandler(t,e){this.#s[t]=e}defineAction(t,e){let{handler:s,...n}=e;s&&(this.#s[t]=s),this.actions={...this.actions,[t]:n}}set actions(t){if(!t)return;this.#t=t;let e={type:"actions",actions:this.#t};a.log("AppletScope","Send message",e),this.#e&&this.#e(e);let s=new r("actions",{actions:t});setTimeout(()=>this.#n(s),1)}get actions(){return this.#t}get manifest(){return this.#o}get actionHandlers(){return this.#s}set actionHandlers(t){this.#s=t}set data(t){this.#i=t;let e={type:"data",data:t};a.log("AppletScope","Send message",e),this.#e&&this.#e(e);let s=new r("data",{data:t});setTimeout(()=>this.#n(s),1)}get data(){return this.#i}get width(){return this.#a}get height(){return this.#r}};var f=class{async connect(t){return new Promise((e,s)=>{let n=new A(t),i=setTimeout(()=>{s(new m(`Applet failed to connect before the timeout was reached (${1e4}ms)`))},1e4),p=()=>{e(n),n.removeEventListener("connect",p),clearTimeout(i)};n.addEventListener("connect",p)})}register(t){return new u(t)}};var b=new f;var E=class extends HTMLElement{#s;#o;#t;#i=c.bind(this);#n=document.createElement("iframe");static{this.observedAttributes=["src"]}connectedCallback(){this.#s=this.attachShadow({mode:"closed"}),this.#s.appendChild(this.#n);let t=document.createElement("style");t.textContent=this.styles,this.#s.appendChild(t),this.src=this.getAttribute("src")}get contentWindow(){return this.#n.contentWindow}set src(t){this.#o=t,this.#t=void 0,this.#e(t)}get src(){return this.#o||""}attributeChangedCallback(t,e,s){t==="src"&&(this.src=s)}async#e(t){this.#n.src=t;let e=this.#n.contentWindow;e&&(this.#t=await b.connect(e),this.#t.ondata=s=>{this.#i(s)},this.#t.onresize=s=>{this.#a({width:this.#t.width,height:this.#t.height})},this.#t.onactions=s=>{this.#i(s)},this.#i(new Event("load")),this.load&&typeof this.load=="function"&&this.onload(new Event("load")))}get applet(){return this.#t}set data(t){if(this.applet)this.applet.data=t;else{let e=()=>{this.applet&&(this.applet.data=t),this.removeEventListener("load",e)};this.addEventListener("load",e)}}#a(t){this.style.height=`${t.height}px`}get styles(){return`
2
2
  :host {
3
3
  background: white;
4
4
  display: flex;
@@ -26,3 +26,4 @@ export interface JSONSchemaObject {
26
26
  required?: string[];
27
27
  additionalProperties?: boolean;
28
28
  }
29
+ export declare function isEmpty(obj: object): boolean;
@@ -4,3 +4,6 @@ export function dispatchEventAndHandler(event) {
4
4
  }
5
5
  this.dispatchEvent(event);
6
6
  }
7
+ export function isEmpty(obj) {
8
+ return Object.keys(obj).length === 0;
9
+ }
@@ -1,4 +1,4 @@
1
- (()=>{var h=class extends Error{constructor(t){super(t),this.name="AppletExecutionError"}},A=class extends Error{constructor(t){super(t),this.name="AppletConnectionError"}};function c(o){typeof this[`on${o.type}`]=="function"&&this[`on${o.type}`](o),this.dispatchEvent(o)}var a=class extends Event{constructor(t,e){super(t,{bubbles:e?.bubbles,composed:e?.composed,cancelable:e?.cancelable}),this.data=e?.data,this.actions=e?.actions}};function T(o,...t){}var p={log:T};var f=class extends EventTarget{#s;#o={};#t;#i;#n;#e;#a;#p;#r;constructor(t){super(),p.log("Applet","Constructor called"),this.#s=t,this.#n=c.bind(this),this.#c();let e=s=>{s.source===this.#s&&"type"in s.data&&s.data.type==="appletconnect"&&(p.log("Applet","Recieved message",s.data),this.#c(),this.removeEventListener("message",e))};window.addEventListener("message",e)}#c(){this.#e&&this.#e.close();let t=new MessageChannel,e={type:"appletconnect"};p.log("Applet","Send message",e),this.#e=t.port1,this.#e.onmessage=this.#h.bind(this),this.#s.postMessage(e,"*",[t.port2]),this.#a=this.#e.postMessage.bind(this.#e)}#h(t){let e=t.data;switch(p.log("Applet","Recieved message",e),e.type){case"register":let s=e;this.#t=s.manifest;let n=new a("connect");this.#n(n),this.#o=s.actions,this.#d(s.actions),this.#i=s.data,this.#l(s.data);break;case"data":let i=e;this.#i=i.data,this.#l(i.data);break;case"resize":let r=e;this.#p=r.width,this.#r=r.height;let g=new a("resize");this.#n(g);break;case"actions":let m=e;this.#o=m.actions,this.#d(m.actions);break}}#l(t){let e=new a("data",{data:t});this.#n(e)}#d(t){let e=new a("actions",{actions:t});this.#n(e)}async sendAction(t,e){let s={id:crypto.randomUUID(),type:"action",actionId:t,arguments:e};return new Promise((n,i)=>{this.#a(s);let r=setTimeout(()=>{i(new h(`Applet action handler failed to complete before timeout (${1e4}ms)`))},1e4),g=m=>{let d=m.data;if(["actioncomplete","actionerror"].includes(d.type)&&"id"in d&&d.id===s.id)if(this.#e.removeEventListener("message",g),clearTimeout(r),d.type==="actionerror"){let b=d;i(new h(b.message))}else n()};this.#e.addEventListener("message",g)})}get data(){return this.#i}set data(t){this.#i=t;let e={type:"data",data:t};this.#a(e)}get window(){return this.#s}get manifest(){return this.#t}get actions(){return this.#o}get width(){return this.#p}get height(){return this.#r}};function M(o){return Object.keys(o).length===0}var E=class extends EventTarget{#s={};#o;#t;#i;#n;#e;#a;#p;constructor(t){super(),p.log("AppletScope","Constructor called"),this.#n=c.bind(this),t&&(this.#o=t);let e=n=>{if(n.source===window.parent&&n.data.type==="appletconnect"&&n.ports&&n.ports.length>0){p.log("AppletScope","Recieved message",n.data);let i=n.ports[0];this.#e=i.postMessage.bind(i),i.onmessage=this.#c.bind(this),this.removeEventListener("message",e),this.#r()}};window.addEventListener("message",e);let s={type:"appletconnect"};window.parent.postMessage(s,"*"),p.log("AppletScope","Send message",s)}async#r(){let t=this.manifest??await this.#g();this.#o=t||{},this.#t=this.#t||t?.actions||{};let e={type:"register",manifest:this.#o,actions:this.#t,data:this.#i};this.#e(e),p.log("AppletScope","Send message",e);let s=new a("connect");this.#n(s),this.#l()}#c(t){let e=t.data;switch(p.log("AppletScope","Recieved message",e),e.type){case"data":"data"in e&&(this.data=e.data);break;case"action":"type"in e&&e.type==="action"&&"id"in e&&typeof e.id=="string"&&"actionId"in e&&typeof e.actionId=="string"&&"arguments"in e&&this.#h(e);break}}async#h(t){let{actionId:e,arguments:s,id:n}=t;if(Object.keys(this.#s).includes(e))try{await this.#s[e](s);let i={type:"actioncomplete",id:n};this.#e(i)}catch(i){let r={type:"actionerror",id:n,message:i.message};this.#e(r),console.error(i)}}#l(){new ResizeObserver(e=>{for(let s of e)this.#d({width:s.contentRect.width,height:s.contentRect.height})}).observe(document.querySelector("html"))}#d({width:t,height:e}){this.#a=t,this.#p=e;let s={type:"resize",width:t,height:e};p.log("AppletScope","Send message",s),this.#e(s)}async#g(){let t=document.querySelector('link[rel="manifest"]');if(!t){console.warn("No manifest link found");return}try{let s=await(await fetch(t.href)).json();for(let n in s.actions){let i=s.actions[n];i.params_schema&&!M(this.#t.params_schema)&&(i.params_schema=void 0)}return s}catch{return}}setActionHandler(t,e){this.#s[t]=e}defineAction(t,e){let{handler:s,...n}=e;s&&(this.#s[t]=s),this.actions={...this.actions,[t]:n}}set actions(t){if(!t)return;this.#t=t;let e={type:"actions",actions:this.#t};p.log("AppletScope","Send message",e),this.#e&&this.#e(e);let s=new a("actions",{actions:t});setTimeout(()=>this.#n(s),1)}get actions(){return this.#t}get manifest(){return this.#o}get actionHandlers(){return this.#s}set actionHandlers(t){this.#s=t}set data(t){this.#i=t;let e={type:"data",data:t};p.log("AppletScope","Send message",e),this.#e&&this.#e(e);let s=new a("data",{data:t});setTimeout(()=>this.#n(s),1)}get data(){return this.#i}get width(){return this.#a}get height(){return this.#p}};var u=class{async connect(t){return new Promise((e,s)=>{let n=new f(t),i=setTimeout(()=>{s(new A(`Applet failed to connect before the timeout was reached (${1e4}ms)`))},1e4),r=()=>{e(n),n.removeEventListener("connect",r),clearTimeout(i)};n.addEventListener("connect",r)})}register(t){return new E(t)}};var l=class extends HTMLElement{#s;#o;#t;#i=c.bind(this);#n=document.createElement("iframe");static{this.observedAttributes=["src"]}connectedCallback(){this.#s=this.attachShadow({mode:"closed"}),this.#s.appendChild(this.#n);let t=document.createElement("style");t.textContent=this.styles,this.#s.appendChild(t),this.src=this.getAttribute("src")}get contentWindow(){return this.#n.contentWindow}set src(t){this.#o=t,this.#t=void 0,this.#e(t)}get src(){return this.#o||""}attributeChangedCallback(t,e,s){t==="src"&&(this.src=s)}async#e(t){this.#n.src=t;let e=this.#n.contentWindow;e&&(this.#t=await y.connect(e),this.#t.ondata=s=>{this.#i(s)},this.#t.onresize=s=>{this.#a({width:this.#t.width,height:this.#t.height})},this.#t.onactions=s=>{this.#i(s)},this.#i(new Event("load")),this.load&&typeof this.load=="function"&&this.onload(new Event("load")))}get applet(){return this.#t}set data(t){if(this.applet)this.applet.data=t;else{let e=()=>{this.applet&&(this.applet.data=t),this.removeEventListener("load",e)};this.addEventListener("load",e)}}#a(t){this.style.height=`${t.height}px`}get styles(){return`
1
+ (()=>{var h=class extends Error{constructor(t){super(t),this.name="AppletExecutionError"}},A=class extends Error{constructor(t){super(t),this.name="AppletConnectionError"}};function c(o){typeof this[`on${o.type}`]=="function"&&this[`on${o.type}`](o),this.dispatchEvent(o)}function v(o){return Object.keys(o).length===0}var a=class extends Event{constructor(t,e){super(t,{bubbles:e?.bubbles,composed:e?.composed,cancelable:e?.cancelable}),this.data=e?.data,this.actions=e?.actions}};function T(o,...t){}var p={log:T};var f=class extends EventTarget{#s;#o={};#t;#i;#n;#e;#a;#p;#r;constructor(t){super(),p.log("Applet","Constructor called"),this.#s=t,this.#n=c.bind(this),this.#c();let e=s=>{s.source===this.#s&&"type"in s.data&&s.data.type==="appletconnect"&&(p.log("Applet","Recieved message",s.data),this.#c(),this.removeEventListener("message",e))};window.addEventListener("message",e)}#c(){this.#e&&this.#e.close();let t=new MessageChannel,e={type:"appletconnect"};p.log("Applet","Send message",e),this.#e=t.port1,this.#e.onmessage=this.#h.bind(this),this.#s.postMessage(e,"*",[t.port2]),this.#a=this.#e.postMessage.bind(this.#e)}#h(t){let e=t.data;switch(p.log("Applet","Recieved message",e),e.type){case"register":let s=e;this.#t=s.manifest;let n=new a("connect");this.#n(n),this.#o=s.actions,this.#d(s.actions),this.#i=s.data,this.#l(s.data);break;case"data":let i=e;this.#i=i.data,this.#l(i.data);break;case"resize":let r=e;this.#p=r.width,this.#r=r.height;let g=new a("resize");this.#n(g);break;case"actions":let m=e;this.#o=m.actions,this.#d(m.actions);break}}#l(t){let e=new a("data",{data:t});this.#n(e)}#d(t){let e=new a("actions",{actions:t});this.#n(e)}async sendAction(t,e){let s={id:crypto.randomUUID(),type:"action",actionId:t,arguments:e};return new Promise((n,i)=>{this.#a(s);let r=setTimeout(()=>{i(new h(`Applet action handler failed to complete before timeout (${1e4}ms)`))},1e4),g=m=>{let d=m.data;if(["actioncomplete","actionerror"].includes(d.type)&&"id"in d&&d.id===s.id)if(this.#e.removeEventListener("message",g),clearTimeout(r),d.type==="actionerror"){let b=d;i(new h(b.message))}else n()};this.#e.addEventListener("message",g)})}get data(){return this.#i}set data(t){this.#i=t;let e={type:"data",data:t};this.#a(e)}get window(){return this.#s}get manifest(){return this.#t}get actions(){return this.#o}get width(){return this.#p}get height(){return this.#r}};var E=class extends EventTarget{#s={};#o;#t;#i;#n;#e;#a;#p;constructor(t){super(),p.log("AppletScope","Constructor called"),this.#n=c.bind(this),t&&(this.#o=t);let e=n=>{if(n.source===window.parent&&n.data.type==="appletconnect"&&n.ports&&n.ports.length>0){p.log("AppletScope","Recieved message",n.data);let i=n.ports[0];this.#e=i.postMessage.bind(i),i.onmessage=this.#c.bind(this),this.removeEventListener("message",e),this.#r()}};window.addEventListener("message",e);let s={type:"appletconnect"};window.parent.postMessage(s,"*"),p.log("AppletScope","Send message",s)}async#r(){let t=this.manifest??await this.#g();this.#o=t||{},this.#t=this.#t||t?.actions||{};let e={type:"register",manifest:this.#o,actions:this.#t,data:this.#i};this.#e(e),p.log("AppletScope","Send message",e);let s=new a("connect");this.#n(s),this.#l()}#c(t){let e=t.data;switch(p.log("AppletScope","Recieved message",e),e.type){case"data":"data"in e&&(this.data=e.data);break;case"action":"type"in e&&e.type==="action"&&"id"in e&&typeof e.id=="string"&&"actionId"in e&&typeof e.actionId=="string"&&"arguments"in e&&this.#h(e);break}}async#h(t){let{actionId:e,arguments:s,id:n}=t;if(Object.keys(this.#s).includes(e))try{await this.#s[e](s);let i={type:"actioncomplete",id:n};this.#e(i)}catch(i){let r={type:"actionerror",id:n,message:i.message};this.#e(r),console.error(i)}}#l(){new ResizeObserver(e=>{for(let s of e)this.#d({width:s.contentRect.width,height:s.contentRect.height})}).observe(document.querySelector("html"))}#d({width:t,height:e}){this.#a=t,this.#p=e;let s={type:"resize",width:t,height:e};p.log("AppletScope","Send message",s),this.#e(s)}async#g(){let t=document.querySelector('link[rel="manifest"]');if(!t){console.warn("No manifest link found");return}try{let s=await(await fetch(t.href)).json();for(let n in s.actions){let i=s.actions[n];i.params_schema&&!v(this.#t.params_schema)&&(i.params_schema=void 0)}return s}catch{return}}setActionHandler(t,e){this.#s[t]=e}defineAction(t,e){let{handler:s,...n}=e;s&&(this.#s[t]=s),this.actions={...this.actions,[t]:n}}set actions(t){if(!t)return;this.#t=t;let e={type:"actions",actions:this.#t};p.log("AppletScope","Send message",e),this.#e&&this.#e(e);let s=new a("actions",{actions:t});setTimeout(()=>this.#n(s),1)}get actions(){return this.#t}get manifest(){return this.#o}get actionHandlers(){return this.#s}set actionHandlers(t){this.#s=t}set data(t){this.#i=t;let e={type:"data",data:t};p.log("AppletScope","Send message",e),this.#e&&this.#e(e);let s=new a("data",{data:t});setTimeout(()=>this.#n(s),1)}get data(){return this.#i}get width(){return this.#a}get height(){return this.#p}};var u=class{async connect(t){return new Promise((e,s)=>{let n=new f(t),i=setTimeout(()=>{s(new A(`Applet failed to connect before the timeout was reached (${1e4}ms)`))},1e4),r=()=>{e(n),n.removeEventListener("connect",r),clearTimeout(i)};n.addEventListener("connect",r)})}register(t){return new E(t)}};var l=class extends HTMLElement{#s;#o;#t;#i=c.bind(this);#n=document.createElement("iframe");static{this.observedAttributes=["src"]}connectedCallback(){this.#s=this.attachShadow({mode:"closed"}),this.#s.appendChild(this.#n);let t=document.createElement("style");t.textContent=this.styles,this.#s.appendChild(t),this.src=this.getAttribute("src")}get contentWindow(){return this.#n.contentWindow}set src(t){this.#o=t,this.#t=void 0,this.#e(t)}get src(){return this.#o||""}attributeChangedCallback(t,e,s){t==="src"&&(this.src=s)}async#e(t){this.#n.src=t;let e=this.#n.contentWindow;e&&(this.#t=await y.connect(e),this.#t.ondata=s=>{this.#i(s)},this.#t.onresize=s=>{this.#a({width:this.#t.width,height:this.#t.height})},this.#t.onactions=s=>{this.#i(s)},this.#i(new Event("load")),this.load&&typeof this.load=="function"&&this.onload(new Event("load")))}get applet(){return this.#t}set data(t){if(this.applet)this.applet.data=t;else{let e=()=>{this.applet&&(this.applet.data=t),this.removeEventListener("load",e)};this.addEventListener("load",e)}}#a(t){this.style.height=`${t.height}px`}get styles(){return`
2
2
  :host {
3
3
  background: white;
4
4
  display: flex;
package/package.json CHANGED
@@ -30,5 +30,5 @@
30
30
  "esbuild": "^0.25.0",
31
31
  "typescript": "^5.6.2"
32
32
  },
33
- "version": "0.2.2"
33
+ "version": "0.2.4"
34
34
  }
@@ -1,111 +0,0 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _AppletFrameElement_instances, _AppletFrameElement_root, _AppletFrameElement_src, _AppletFrameElement_applet, _AppletFrameElement_dispatchEventAndHandler, _AppletFrameElement_iframe, _AppletFrameElement_loadApplet, _AppletFrameElement_resizeContainer;
13
- import { applets } from '../index.js';
14
- import { dispatchEventAndHandler } from '../utils.js';
15
- export class AppletFrameElement extends HTMLElement {
16
- constructor() {
17
- super(...arguments);
18
- _AppletFrameElement_instances.add(this);
19
- _AppletFrameElement_root.set(this, void 0);
20
- _AppletFrameElement_src.set(this, void 0);
21
- _AppletFrameElement_applet.set(this, void 0);
22
- _AppletFrameElement_dispatchEventAndHandler.set(this, dispatchEventAndHandler.bind(this));
23
- _AppletFrameElement_iframe.set(this, document.createElement('iframe'));
24
- }
25
- connectedCallback() {
26
- __classPrivateFieldSet(this, _AppletFrameElement_root, this.attachShadow({ mode: 'closed' }), "f");
27
- __classPrivateFieldGet(this, _AppletFrameElement_root, "f").appendChild(__classPrivateFieldGet(this, _AppletFrameElement_iframe, "f"));
28
- const styles = document.createElement('style');
29
- styles.textContent = this.styles;
30
- __classPrivateFieldGet(this, _AppletFrameElement_root, "f").appendChild(styles);
31
- this.src = this.getAttribute('src');
32
- }
33
- get contentWindow() {
34
- return __classPrivateFieldGet(this, _AppletFrameElement_iframe, "f").contentWindow;
35
- }
36
- set src(value) {
37
- __classPrivateFieldSet(this, _AppletFrameElement_src, value, "f");
38
- __classPrivateFieldSet(this, _AppletFrameElement_applet, undefined, "f");
39
- __classPrivateFieldGet(this, _AppletFrameElement_instances, "m", _AppletFrameElement_loadApplet).call(this, value);
40
- }
41
- get src() {
42
- return __classPrivateFieldGet(this, _AppletFrameElement_src, "f") || '';
43
- }
44
- attributeChangedCallback(name, oldValue, newValue) {
45
- if (name === 'src') {
46
- this.src = newValue;
47
- }
48
- }
49
- get applet() {
50
- return __classPrivateFieldGet(this, _AppletFrameElement_applet, "f");
51
- }
52
- set data(data) {
53
- if (this.applet) {
54
- this.applet.data = data;
55
- }
56
- else {
57
- const listener = () => {
58
- if (this.applet)
59
- this.applet.data = data;
60
- this.removeEventListener('load', listener);
61
- };
62
- this.addEventListener('load', listener);
63
- }
64
- }
65
- get styles() {
66
- return /*css*/ `
67
- :host {
68
- background: white;
69
- display: flex;
70
- flex-direction: column;
71
- height: 350px;
72
- }
73
-
74
- iframe {
75
- border: none;
76
- height: 100%;
77
- width: 100%;
78
- }
79
- `;
80
- }
81
- }
82
- _AppletFrameElement_root = new WeakMap(), _AppletFrameElement_src = new WeakMap(), _AppletFrameElement_applet = new WeakMap(), _AppletFrameElement_dispatchEventAndHandler = new WeakMap(), _AppletFrameElement_iframe = new WeakMap(), _AppletFrameElement_instances = new WeakSet(), _AppletFrameElement_loadApplet = async function _AppletFrameElement_loadApplet(url) {
83
- __classPrivateFieldGet(this, _AppletFrameElement_iframe, "f").src = url;
84
- const window = __classPrivateFieldGet(this, _AppletFrameElement_iframe, "f").contentWindow;
85
- if (!window)
86
- return;
87
- __classPrivateFieldSet(this, _AppletFrameElement_applet, await applets.connect(window), "f");
88
- // When data received, bubble the event up
89
- __classPrivateFieldGet(this, _AppletFrameElement_applet, "f").ondata = (event) => {
90
- __classPrivateFieldGet(this, _AppletFrameElement_dispatchEventAndHandler, "f").call(this, event);
91
- };
92
- // Resize
93
- __classPrivateFieldGet(this, _AppletFrameElement_applet, "f").onresize = (event) => {
94
- __classPrivateFieldGet(this, _AppletFrameElement_instances, "m", _AppletFrameElement_resizeContainer).call(this, {
95
- width: __classPrivateFieldGet(this, _AppletFrameElement_applet, "f").width,
96
- height: __classPrivateFieldGet(this, _AppletFrameElement_applet, "f").height,
97
- });
98
- };
99
- __classPrivateFieldGet(this, _AppletFrameElement_applet, "f").onactions = (event) => {
100
- __classPrivateFieldGet(this, _AppletFrameElement_dispatchEventAndHandler, "f").call(this, event);
101
- };
102
- // Emit load event when setup & connection complete
103
- __classPrivateFieldGet(this, _AppletFrameElement_dispatchEventAndHandler, "f").call(this, new Event('load'));
104
- if (this['load'] && typeof this['load'] === 'function') {
105
- this.onload(new Event('load'));
106
- }
107
- }, _AppletFrameElement_resizeContainer = function _AppletFrameElement_resizeContainer(dimensions) {
108
- this.style.height = `${dimensions.height}px`;
109
- };
110
- AppletFrameElement.observedAttributes = ['src'];
111
- customElements.define('applet-frame', AppletFrameElement);
@@ -1 +0,0 @@
1
- export declare function isEmpty(obj: object): boolean;
@@ -1,3 +0,0 @@
1
- export function isEmpty(obj) {
2
- return Object.keys(obj).length === 0;
3
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes