1 line
21 KiB
JavaScript
1 line
21 KiB
JavaScript
(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["6111"],{2982:function(e,t,s){"use strict";s.r(t),s.d(t,{default:()=>p,frontMatter:()=>a,metadata:()=>r,assets:()=>l,toc:()=>d,contentTitle:()=>c});var r=JSON.parse('{"id":"features/broadcast","title":"Broadcast","description":"Overview","source":"@site/docs/features/broadcast.mdx","sourceDirName":"features","slug":"/features/broadcast","permalink":"/docs/features/broadcast","draft":false,"unlisted":false,"editUrl":"https://github.com/live-codes/livecodes/tree/develop/docs/docs/features/broadcast.mdx","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"Sync","permalink":"/docs/features/sync"},"next":{"title":"Backup / Restore","permalink":"/docs/features/backup-restore"}}'),n=s("5893"),o=s("65"),i=s("8500");let a={},c="Broadcast",l={},d=[{value:"Overview",id:"overview",level:2},{value:"Technical Details",id:"technical-details",level:2}];function h(e){let t={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",header:"header",img:"img",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.header,{children:(0,n.jsx)(t.h1,{id:"broadcast",children:"Broadcast"})}),"\n",(0,n.jsx)(t.h2,{id:"overview",children:"Overview"}),"\n",(0,n.jsxs)(t.p,{children:["LiveCodes Broadcast allows sending the ",(0,n.jsx)(t.a,{href:"/docs/features/result",children:"result page"})," (and optionally source & compiled code and project configuration) to custom API. This can be used to live-view result page updates on different browsers/devices in real-time or broadcast live-coding sessions."]}),"\n",(0,n.jsx)(t.admonition,{type:"note",children:(0,n.jsx)(t.p,{children:"Broadcast can only be performed from the full app, and not from embedded playgrounds."})}),"\n",(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"Broadcast"})," screen can be accessed from the Broadcast icon in the ",(0,n.jsx)(t.a,{href:"/docs/features/tools-pane",children:"tools pane"})," (below the result page), or from the Project menu \u2192 Broadcast."]}),"\n","\n",(0,n.jsx)(i.Z,{params:{screen:"broadcast"},linkText:"direct link"}),"\n",(0,n.jsx)(t.p,{children:(0,n.jsx)(t.img,{alt:"Broadcast UI",src:s(3127).Z+"",width:"2240",height:"1400"})}),"\n",(0,n.jsx)(t.p,{children:"On connecting to the server, the channel URL returned by the server is displayed. The channel URL can be shared to different clients (browsers on same or different devices) to view result page or code updates in real-time."}),"\n",(0,n.jsxs)(t.p,{children:["If the option ",(0,n.jsx)(t.code,{children:"Include source code"})," is enabled, the source and compiled code together with the current project configuration are also posted to the server with each update."]}),"\n",(0,n.jsx)(t.p,{children:(0,n.jsx)(t.img,{alt:"Broadcast UI - broadcasting",src:s(2728).Z+"",width:"2240",height:"1400"})}),"\n",(0,n.jsx)(t.p,{children:"The Broadcast icon (in tools pane), shows the broadcast status. Clicking the icon, opens the broadcast UI, where the channel URL is displayed and the broadcast can be stopped."}),"\n",(0,n.jsx)(t.p,{children:(0,n.jsx)(t.img,{alt:"Broadcast icon - broadcasting",src:s(6933).Z+"",width:"2240",height:"1400"})}),"\n",(0,n.jsxs)(t.admonition,{title:"Server",type:"info",children:[(0,n.jsxs)(t.p,{children:["An open-source example implementation of an API server is available on: ",(0,n.jsx)(t.a,{href:"https://github.com/live-codes/broadcast",children:"live-codes/broadcast"}),"."]}),(0,n.jsxs)(t.p,{children:["It is a ",(0,n.jsx)(t.a,{href:"https://github.com/live-codes/broadcast/blob/main/index.js",children:"simple implementation"}),", which you can use or extend. It makes use of LiveCodes ",(0,n.jsx)(t.a,{href:"/docs/features/embeds",children:"Embeds"})," and ",(0,n.jsx)(t.a,{href:"/docs/sdk/",children:"SDK"})," for code broadcasting."]}),(0,n.jsxs)(t.p,{children:["A demo, free-to-test, instance is hosted on:\n",(0,n.jsx)(t.a,{href:"https://livecodes-broadcast.onrender.com/",children:"https://livecodes-broadcast.onrender.com/"})," (low resources - sleeps after 15 minutes of inactivity)"]}),(0,n.jsx)(t.p,{children:"You can use one of these links to self-host it:"}),(0,n.jsx)("a",{href:"https://render.com/deploy?repo=https://github.com/live-codes/broadcast",children:(0,n.jsx)("img",{src:"https://render.com/images/deploy-to-render-button.svg",alt:"Deploy to Render",width:"150"})}),(0,n.jsx)(t.p,{children:"\xa0\xa0\xa0"}),(0,n.jsx)("a",{href:"https://heroku.com/deploy?template=https://github.com/live-codes/broadcast/tree/main",children:(0,n.jsx)("img",{src:"https://www.herokucdn.com/deploy/button.svg",alt:"Deploy to Heroku",width:"150"})})]}),"\n",(0,n.jsx)(t.admonition,{title:"Hosted API",type:"tip",children:(0,n.jsxs)(t.p,{children:[(0,n.jsx)(t.a,{href:"/docs/sponsor",children:"LiveCodes sponsors"})," (bronze sponsors and above) get access to a hosted (always-on) API, which they can use without having to manage their own server."]})}),"\n",(0,n.jsx)(t.p,{children:"These are screenshots for the live-updated result page and code:"}),"\n",(0,n.jsx)(t.p,{children:(0,n.jsx)(t.img,{alt:"Broadcasting result",src:s(6798).Z+"",width:"2240",height:"1400"})}),"\n",(0,n.jsx)(t.p,{children:(0,n.jsx)(t.img,{alt:"Broadcasting code",src:s(8257).Z+"",width:"2240",height:"1400"})}),"\n",(0,n.jsx)(t.h2,{id:"technical-details",children:"Technical Details"}),"\n",(0,n.jsxs)(t.p,{children:["When starting a broadcast, the app sends a ",(0,n.jsx)(t.code,{children:"POST"})," request to the specified server with a body that has the following properties:"]}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"result"}),": a string with the result page html."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"data"})," (Only if ",(0,n.jsx)(t.code,{children:"Include source code"})," option is enabled): an object containing source and compiled code together with the current project configuration."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"userToken"})," (Optional): Can be used by the server to authorize users who can broadcast (see below how to set it)."]}),"\n"]}),"\n",(0,n.jsx)(t.p,{children:"When the server successfully creates a channel, it should respond by sending a JSON object with the following properties:"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"channel"}),": a string representing the channel Id."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"channelUrl"}),": a string with the URL of the channel that can be shared to the clients who want to connect to it."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"channelToken"}),": a string representing a secret token for this channel, to prevent others from sending to the same channel. This is only sent once (in response to the request that created the channel)."]}),"\n"]}),"\n",(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"channel"})," and ",(0,n.jsx)(t.code,{children:"channelToken"})," are remembered by the app, and are sent in subsequent requests for the same channel (with every result page update). They are deleted when stopping broadcast or when the app reloads."]}),"\n",(0,n.jsxs)(t.admonition,{type:"note",children:[(0,n.jsxs)(t.p,{children:["To set a ",(0,n.jsx)(t.code,{children:"userToken"})," for authorization with a broadcast server, run the following in the browser console:"]}),(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",children:"await livecodes.exec('setBroadcastToken', 'my-token');\n"})}),(0,n.jsxs)(t.p,{children:["The supplied value (in this case ",(0,n.jsx)(t.code,{children:"my-token"}),") will be posted to the server with every update as the value for the property ",(0,n.jsx)(t.code,{children:"userToken"}),"."]}),(0,n.jsx)(t.p,{children:"This value is saved for the current user across app reloads."})]})]})}function p(e={}){let{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},3127:function(e,t,s){"use strict";s.d(t,{Z:function(){return r}});let r=s.p+"assets/images/broadcast-1-c4cbf92ea7dd67ebf5f2bde4a69260e7.jpg"},2728:function(e,t,s){"use strict";s.d(t,{Z:function(){return r}});let r=s.p+"assets/images/broadcast-2-63b02f7fb51c653fe0282c80fad19f34.jpg"},6933:function(e,t,s){"use strict";s.d(t,{Z:function(){return r}});let r=s.p+"assets/images/broadcast-3-5307656200f0ffc75d10763429e470e8.jpg"},6798:function(e,t,s){"use strict";s.d(t,{Z:function(){return r}});let r=s.p+"assets/images/broadcast-4-1b7f8cf8a70b6eec75eb706db2adfe5d.jpg"},8257:function(e,t,s){"use strict";s.d(t,{Z:function(){return r}});let r=s.p+"assets/images/broadcast-5-48f5b56e3638aac1b9d5774aacb9037c.jpg"},7728:function(e,t,s){e=s.nmd(e);var r=function(){var e=String.fromCharCode,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",r={};function n(e,t){if(!r[e]){r[e]={};for(var s=0;s<e.length;s++)r[e][e.charAt(s)]=s}return r[e][t]}var o={compressToBase64:function(e){if(null==e)return"";var s=o._compress(e,6,function(e){return t.charAt(e)});switch(s.length%4){default:case 0:return s;case 1:return s+"===";case 2:return s+"==";case 3:return s+"="}},decompressFromBase64:function(e){return null==e?"":""==e?null:o._decompress(e.length,32,function(s){return n(t,e.charAt(s))})},compressToUTF16:function(t){return null==t?"":o._compress(t,15,function(t){return e(t+32)})+" "},decompressFromUTF16:function(e){return null==e?"":""==e?null:o._decompress(e.length,16384,function(t){return e.charCodeAt(t)-32})},compressToUint8Array:function(e){for(var t=o.compress(e),s=new Uint8Array(2*t.length),r=0,n=t.length;r<n;r++){var i=t.charCodeAt(r);s[2*r]=i>>>8,s[2*r+1]=i%256}return s},decompressFromUint8Array:function(t){if(null==t)return o.decompress(t);for(var s=Array(t.length/2),r=0,n=s.length;r<n;r++)s[r]=256*t[2*r]+t[2*r+1];var i=[];return s.forEach(function(t){i.push(e(t))}),o.decompress(i.join(""))},compressToEncodedURIComponent:function(e){return null==e?"":o._compress(e,6,function(e){return s.charAt(e)})},decompressFromEncodedURIComponent:function(e){return null==e?"":""==e?null:(e=e.replace(/ /g,"+"),o._decompress(e.length,32,function(t){return n(s,e.charAt(t))}))},compress:function(t){return o._compress(t,16,function(t){return e(t)})},_compress:function(e,t,s){if(null==e)return"";var r,n,o,i={},a={},c="",l="",d="",h=2,p=3,u=2,f=[],m=0,g=0;for(o=0;o<e.length;o+=1)if(c=e.charAt(o),Object.prototype.hasOwnProperty.call(i,c)||(i[c]=p++,a[c]=!0),l=d+c,Object.prototype.hasOwnProperty.call(i,l))d=l;else{if(Object.prototype.hasOwnProperty.call(a,d)){if(256>d.charCodeAt(0)){for(r=0;r<u;r++)m<<=1,g==t-1?(g=0,f.push(s(m)),m=0):g++;for(r=0,n=d.charCodeAt(0);r<8;r++)m=m<<1|1&n,g==t-1?(g=0,f.push(s(m)),m=0):g++,n>>=1}else{for(r=0,n=1;r<u;r++)m=m<<1|n,g==t-1?(g=0,f.push(s(m)),m=0):g++,n=0;for(r=0,n=d.charCodeAt(0);r<16;r++)m=m<<1|1&n,g==t-1?(g=0,f.push(s(m)),m=0):g++,n>>=1}0==--h&&(h=Math.pow(2,u),u++),delete a[d]}else for(r=0,n=i[d];r<u;r++)m=m<<1|1&n,g==t-1?(g=0,f.push(s(m)),m=0):g++,n>>=1;0==--h&&(h=Math.pow(2,u),u++),i[l]=p++,d=String(c)}if(""!==d){if(Object.prototype.hasOwnProperty.call(a,d)){if(256>d.charCodeAt(0)){for(r=0;r<u;r++)m<<=1,g==t-1?(g=0,f.push(s(m)),m=0):g++;for(r=0,n=d.charCodeAt(0);r<8;r++)m=m<<1|1&n,g==t-1?(g=0,f.push(s(m)),m=0):g++,n>>=1}else{for(r=0,n=1;r<u;r++)m=m<<1|n,g==t-1?(g=0,f.push(s(m)),m=0):g++,n=0;for(r=0,n=d.charCodeAt(0);r<16;r++)m=m<<1|1&n,g==t-1?(g=0,f.push(s(m)),m=0):g++,n>>=1}0==--h&&(h=Math.pow(2,u),u++),delete a[d]}else for(r=0,n=i[d];r<u;r++)m=m<<1|1&n,g==t-1?(g=0,f.push(s(m)),m=0):g++,n>>=1;0==--h&&(h=Math.pow(2,u),u++)}for(r=0,n=2;r<u;r++)m=m<<1|1&n,g==t-1?(g=0,f.push(s(m)),m=0):g++,n>>=1;for(;;){if(m<<=1,g==t-1){f.push(s(m));break}g++}return f.join("")},decompress:function(e){return null==e?"":""==e?null:o._decompress(e.length,32768,function(t){return e.charCodeAt(t)})},_decompress:function(t,s,r){var n,o,i,a,c,l,d,h=[],p=4,u=4,f=3,m="",g=[],v={val:r(0),position:s,index:1};for(n=0;n<3;n+=1)h[n]=n;for(i=0,c=4,l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=s,v.val=r(v.index++)),i|=(a>0?1:0)*l,l<<=1;switch(i){case 0:for(i=0,c=256,l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=s,v.val=r(v.index++)),i|=(a>0?1:0)*l,l<<=1;d=e(i);break;case 1:for(i=0,c=65536,l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=s,v.val=r(v.index++)),i|=(a>0?1:0)*l,l<<=1;d=e(i);break;case 2:return""}for(h[3]=d,o=d,g.push(d);;){if(v.index>t)return"";for(i=0,c=Math.pow(2,f),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=s,v.val=r(v.index++)),i|=(a>0?1:0)*l,l<<=1;switch(d=i){case 0:for(i=0,c=256,l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=s,v.val=r(v.index++)),i|=(a>0?1:0)*l,l<<=1;h[u++]=e(i),d=u-1,p--;break;case 1:for(i=0,c=65536,l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=s,v.val=r(v.index++)),i|=(a>0?1:0)*l,l<<=1;h[u++]=e(i),d=u-1,p--;break;case 2:return g.join("")}if(0==p&&(p=Math.pow(2,f),f++),h[d])m=h[d];else{if(d!==u)return null;m=o+o.charAt(0)}g.push(m),h[u++]=o+m.charAt(0),p--,o=m,0==p&&(p=Math.pow(2,f),f++)}}};return o}();"function"==typeof define&&define.amd?define(function(){return r}):null!=e&&(e.exports=r)},8500:function(e,t,s){"use strict";s.d(t,{Z:()=>l});var r=s("5893");s("7294");var n=s("6735");function o(e){let{children:t,fallback:s}=e;return(0,n.Z)()?(0,r.jsx)(r.Fragment,{children:t?.()}):s??null}var i=s("1705"),a=s("8294"),c=s("1858");function l(e){let{params:t,config:s,code:n,language:l="js",codeTitle:d="",showLineNumbers:h=!1,formatCode:p=!0,linkText:u="Run in LiveCodes",style:f={},className:m=""}=e,g=(0,a.r)({appUrl:c.G,params:t,config:s});return(0,r.jsxs)("div",{style:{marginBottom:"30px",...f},className:m,children:[n&&(0,r.jsx)(o,{children:()=>(0,r.jsx)(i.Z,{language:l,title:d,showLineNumbers:h,children:p?function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"js";return window.prettier?.format(e,{parser:"html"===t?"html":"babel",plugins:window.prettierPlugins})}(n,l):n})}),(0,r.jsxs)("a",{href:g,target:"_blank",rel:"noreferrer",children:[u,(0,r.jsx)("svg",{width:"12",height:"12","aria-hidden":"true",viewBox:"0 0 24 24",className:"iconExternalLink_node_modules-@docusaurus-theme-classic-lib-theme-Icon-ExternalLink-styles-module",style:{marginLeft:"4px"},children:(0,r.jsx)("path",{fill:"currentColor",d:"M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"})})]})]})}},8294:function(e,t,s){"use strict";s.d(t,{T:function(){return n},r:function(){return o}});var r=s(7728);async function n(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"object"!=typeof e||e instanceof HTMLElement||!e.headless&&"headless"!==e.view||(t=e,e=null);let{config:s={},headless:r,loading:n="lazy",view:i}=t,a=r||"headless"===i,c=null,l=null;if("string"==typeof e)c=document.querySelector(e);else if(e instanceof HTMLElement)c=e;else if(!(a&&"object"==typeof e))throw Error("A valid container element is required.");if(!c){if(a)C(c=document.createElement("div")),document.body.appendChild(c);else throw Error(`Cannot find element: "${e}"`)}let d=new URL(o(t)),h=d.origin;d.searchParams.set("embed","true"),d.searchParams.set("loading",a?"eager":n),d.searchParams.set("sdkVersion",process.env.SDK_VERSION||"latest"),"object"==typeof s&&Object.keys(s).length>0&&d.searchParams.set("config","sdk");let p=t.params;"object"==typeof p&&Object.keys(p).length>0&&JSON.stringify(p).length<1800&&Object.keys(p).forEach(e=>{d.searchParams.set(e,encodeURIComponent(String(p[e])))});let u=!1,f="Cannot call API methods after calling `destroy()`.",m=await new Promise(e=>{if(!c)return;let t=c.dataset.height||c.style.height;if(t&&!a){let e=isNaN(Number(t))?t:t+"px";c.style.height=e}"false"===c.dataset.defaultStyles||a||(c.style.backgroundColor||="#fff",c.style.border||="1px solid black",c.style.borderRadius||="8px",c.style.boxSizing||="border-box",c.style.padding||="0",c.style.width||="100%",c.style.height||=c.style.height||"300px",c.style.minHeight="200px",c.style.flexGrow="1",c.style.overflow||="hidden",c.style.resize||="vertical");let r="livecodes",o=c.querySelector(`iframe.${r}`),i=o||document.createElement("iframe");i.classList.add(r),i.setAttribute("allow","accelerometer; camera; encrypted-media; display-capture; geolocation; gyroscope; microphone; midi; clipboard-read; clipboard-write; web-share"),i.setAttribute("allowtransparency","true"),i.setAttribute("allowpaymentrequest","true"),i.setAttribute("allowfullscreen","true"),i.setAttribute("sandbox","allow-same-origin allow-downloads allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-presentation allow-scripts"),i.setAttribute("loading","eager"===n?"eager":"lazy"),a?C(i):(i.style.height="100%",i.style.minHeight="200px",i.style.width="100%",i.style.margin="0",i.style.border="0",i.style.borderRadius=c.style.borderRadius),addEventListener("message",function e(t){t.source===i.contentWindow&&t.origin===h&&t.data?.type==="livecodes-init"&&(removeEventListener("message",e),l=Number(t.data.payload.appVersion.replace(/^v/,"")))}),(!l||l<46)&&addEventListener("message",function e(t){t.source===i.contentWindow&&t.origin===h&&t.data?.type==="livecodes-get-config"&&(removeEventListener("message",e),i.contentWindow?.postMessage({type:"livecodes-config",payload:s},h))}),i.onload=()=>{e(i)},i.src=d.href,o||c.appendChild(i)}),g=new Promise(e=>{addEventListener("message",function t(s){s.source===m.contentWindow&&s.origin===h&&s.data?.type==="livecodes-ready"&&(removeEventListener("message",t),e(),g.settled=!0)})}),v=()=>u?Promise.reject(f):new Promise(async e=>{g.settled&&e(),m.contentWindow?.postMessage({type:"livecodes-load"},h),await g,e()}),b=(e,t)=>new Promise(async(s,r)=>{if(u)return r(f);await v();let n=P();addEventListener("message",function t(o){if(o.source===m.contentWindow&&o.origin===h&&o.data?.type==="livecodes-api-response"&&o.data?.id===n&&o.data.method===e){removeEventListener("message",t);let e=o.data.payload;e?.error?r(e.error):s(e)}}),m.contentWindow?.postMessage({method:e,id:n,args:t},h)}),y={},w=["load","ready","code","console","tests","destroy"],j=(e,t)=>{if(u)throw Error(f);return w.includes(e)?(b("watch",[e]),y[e]||(y[e]=[]),y[e]?.push(t),{remove:()=>{y[e]=y[e]?.filter(e=>e!==t),y[e]?.length===0&&b("watch",[e,"unsubscribe"])}}):{remove:()=>void 0}},x=e=>({"livecodes-app-loaded":"load","livecodes-ready":"ready","livecodes-change":"code","livecodes-console":"console","livecodes-test-results":"tests","livecodes-destroy":"destroy"})[e];addEventListener("message",async e=>{let t=x(e.data?.type??"");if(e.source!==m.contentWindow||e.origin!==h||!t||!y[t])return;let s=e.data?.payload;y[t]?.forEach(e=>{e(s)})});let k=()=>{Object.values(y).forEach(e=>{e.length=0}),m?.remove?.(),u=!0};function C(e){e.style.position="absolute",e.style.top="0",e.style.visibility="hidden",e.style.opacity="0"}"lazy"===n&&"IntersectionObserver"in window&&new IntersectionObserver((e,t)=>{e.forEach(async e=>{e.isIntersecting&&(await v(),t.unobserve(c))})},{rootMargin:"150px"}).observe(c);let P=()=>(String(Math.random())+Date.now().toFixed()).replace("0.","");return{load:()=>v(),run:()=>b("run"),format:e=>b("format",[e]),getShareUrl:e=>b("getShareUrl",[e]),getConfig:e=>b("getConfig",[e]),setConfig:e=>b("setConfig",[e]),getCode:()=>b("getCode"),show:(e,t)=>b("show",[e,t]),runTests:()=>b("runTests"),onChange:e=>j("code",e),watch:j,exec:function(e){for(var t=arguments.length,s=Array(t>1?t-1:0),r=1;r<t;r++)s[r-1]=arguments[r];return b("exec",[e,...s])},destroy:()=>g.settled?b("destroy").then(k):u?Promise.reject(f):(k(),Promise.resolve())}}function o(){let e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{appUrl:s="https://livecodes.io",params:n={},config:o={},headless:i,import:a,lite:c,view:l,...d}=t;try{e=new URL(s)}catch{throw Error(`${s} is not a valid URL.`)}let h=new URLSearchParams;Object.entries(d).forEach(t=>{let[s,r]=t;void 0!==r&&e.searchParams.set(s,String(r))});let p="headless"===t.view||i;if(c&&(console.warn('Deprecation notice: "lite" option is deprecated. Use "config: { mode: \'lite\' }" instead.'),"object"==typeof o&&null==o.mode?o.mode="lite":e.searchParams.set("lite","true")),l&&(console.warn('Deprecation notice: The "view" option has been moved to "config.view". For headless mode use "headless: true".'),"object"==typeof o&&null==o.view&&"headless"!==l?o.view=l:e.searchParams.set("view",l)),"string"==typeof o)try{new URL(o),e.searchParams.set("config",encodeURIComponent(o))}catch{throw Error('"config" is not a valid URL or configuration object.')}else o&&"object"==typeof o&&Object.keys(o).length>0&&(o.title&&"Untitled Project"!==o.title&&e.searchParams.set("title",o.title),o.description&&o.description.length>0&&e.searchParams.set("description",o.description),h.set("config","code/"+(0,r.compressToEncodedURIComponent)(JSON.stringify(o))));if(n&&"object"==typeof n&&Object.keys(n).length>0)try{h.set("params",(0,r.compressToEncodedURIComponent)(JSON.stringify(n)))}catch{Object.keys(n).forEach(t=>{e.searchParams.set(t,encodeURIComponent(String(n[t])))})}return a&&e.searchParams.set("x",encodeURIComponent(a)),p&&e.searchParams.set("headless","true"),e.hash=h.toString(),e.href}},65:function(e,t,s){"use strict";s.d(t,{Z:function(){return a},a:function(){return i}});var r=s(7294);let n={},o=r.createContext(n);function i(e){let t=r.useContext(o);return r.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),r.createElement(o.Provider,{value:t},e.children)}}}]); |