1 line
22 KiB
JavaScript
1 line
22 KiB
JavaScript
(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["5621"],{8315:function(e,t,o){"use strict";o.r(t),o.d(t,{default:()=>u,frontMatter:()=>a,metadata:()=>n,assets:()=>d,toc:()=>l,contentTitle:()=>c});var n=JSON.parse('{"id":"features/editor-settings","title":"Editor Settings","description":"LiveCodes allows a lot of flexibility for configuring which code editor to use and its settings.","source":"@site/docs/features/editor-settings.mdx","sourceDirName":"features","slug":"/features/editor-settings","permalink":"/docs/features/editor-settings","draft":false,"unlisted":false,"editUrl":"https://github.com/live-codes/livecodes/tree/develop/docs/docs/features/editor-settings.mdx","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"User Settings","permalink":"/docs/features/user-settings"},"next":{"title":"Internationalization (i18n)","permalink":"/docs/features/i18n"}}'),r=o("5893"),i=o("65"),s=o("8500");let a={},c="Editor Settings",d={},l=[{value:"Enable AI Code Assistant",id:"enable-ai-code-assistant",level:3},{value:"Code Editor",id:"code-editor",level:3},{value:"Editor Options",id:"editor-options",level:3},{value:"Emmet",id:"emmet",level:3},{value:"Editor Modes",id:"editor-modes",level:3},{value:"Format Options",id:"format-options",level:3}];function h(e){let t={a:"a",code:"code",h1:"h1",h3:"h3",header:"header",img:"img",li:"li",p:"p",strong:"strong",ul:"ul",...(0,i.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.header,{children:(0,r.jsx)(t.h1,{id:"editor-settings",children:"Editor Settings"})}),"\n",(0,r.jsx)(t.p,{children:"LiveCodes allows a lot of flexibility for configuring which code editor to use and its settings."}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"Editor Settings"})," screen can be accessed from Settings menu \u2192 Editor Settings."]}),"\n","\n",(0,r.jsx)(s.Z,{params:{screen:"editor-settings"},linkText:"direct link"}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.img,{alt:"LiveCodes Editor Settings",src:o(9947).Z+"",width:"2240",height:"1400"})}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.img,{alt:"LiveCodes Editor Settings",src:o(516).Z+"",width:"2240",height:"1400"})}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.img,{alt:"LiveCodes Editor Settings",src:o(8423).Z+"",width:"2240",height:"1400"})}),"\n",(0,r.jsx)(t.p,{children:"A preview code editor is displayed to preview the settings in real time."}),"\n",(0,r.jsxs)(t.p,{children:["The settings selected in the ",(0,r.jsx)(t.code,{children:"Editor Settings"})," screen are saved locally to ",(0,r.jsx)(t.a,{href:"/docs/features/user-settings",children:"user settings"})," and are used subsequently. These include:"]}),"\n",(0,r.jsx)(t.h3,{id:"enable-ai-code-assistant",children:"Enable AI Code Assistant"}),"\n",(0,r.jsxs)(t.p,{children:["Enables the ",(0,r.jsx)(t.a,{href:"/docs/features/ai",children:"AI code assistant"}),". (Free and no account required)"]}),"\n",(0,r.jsx)(t.h3,{id:"code-editor",children:"Code Editor"}),"\n",(0,r.jsx)(t.p,{children:"The following code editors are supported:"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://microsoft.github.io/monaco-editor/",children:(0,r.jsx)(t.strong,{children:"Monaco Editor"})}),": This is the code editor that powers ",(0,r.jsx)(t.a,{href:"https://code.visualstudio.com/",children:(0,r.jsx)(t.strong,{children:"VS Code"})}),". It is ",(0,r.jsx)(t.a,{href:"https://code.visualstudio.com/docs/editor/codebasics",children:"feature-rich"})," and supports autocomplete with ",(0,r.jsx)(t.a,{href:"https://code.visualstudio.com/docs/editor/intellisense",children:(0,r.jsx)(t.strong,{children:"IntelliSense"})})," (including ",(0,r.jsx)(t.a,{href:"/docs/features/intellisense",children:"types for custom libraries"}),"). However, it requires a relatively large download and is not supported in mobile browsers."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://codemirror.net/",children:(0,r.jsx)(t.strong,{children:"CodeMirror"})}),": Has ",(0,r.jsx)(t.a,{href:"https://codemirror.net/docs/extensions/",children:"many editing features"}),", including autocomplete, with good ",(0,r.jsx)(t.strong,{children:"mobile support"}),"."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://medv.io/codejar/",children:(0,r.jsx)(t.strong,{children:"CodeJar"})}),": A ",(0,r.jsx)(t.strong,{children:"lightweight"})," code editor with very basic editing features. ",(0,r.jsx)(t.a,{href:"https://prismjs.com/",children:"PrismJs"})," is used for syntax highlighting. Please note that some editor settings are not supported in CodeJar (see below)."]}),"\n"]}),"\n",(0,r.jsxs)(t.p,{children:["This can be configured using the ",(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#editor",children:(0,r.jsx)(t.code,{children:"editor"})})," configuration option."]}),"\n",(0,r.jsxs)(t.p,{children:["By default, Monaco editor is used on desktop, CodeMirror is used on mobile and CodeJar is used in ",(0,r.jsx)(t.a,{href:"/docs/features/display-modes#codeblock",children:"codeblocks"}),", in ",(0,r.jsx)(t.a,{href:"/docs/features/lite",children:"lite mode"})," and in ",(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#readonly",children:"readonly"})," playgrounds."]}),"\n",(0,r.jsx)(t.h3,{id:"editor-options",children:"Editor Options"}),"\n",(0,r.jsx)(t.p,{children:"These include:"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#editortheme",children:"Editor theme"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#fontfamily",children:"Font family"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#fontsize",children:"Font size"})}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#usetabs",children:"Indentation"})," (Spaces/Tabs)"]}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#tabsize",children:"Tab size"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#linenumbers",children:"Line numbers"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#wordwrap",children:"Word-wrap"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#closebrackets",children:"Auto-close brackets and quotes"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#foldregions",children:"Fold (collapse) regions"})}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"emmet",children:"Emmet"}),"\n",(0,r.jsxs)(t.p,{children:["Allows using ",(0,r.jsx)(t.a,{href:"https://emmet.io/",children:(0,r.jsx)(t.strong,{children:"Emmet"})})," ",(0,r.jsx)(t.a,{href:"https://docs.emmet.io/",children:"abbreviations and actions"}),". See ",(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#emmet",children:(0,r.jsx)(t.code,{children:"emmet"})})," configuration option."]}),"\n",(0,r.jsx)(t.p,{children:"(Not supported in CodeJar)"}),"\n",(0,r.jsx)(t.h3,{id:"editor-modes",children:"Editor Modes"}),"\n",(0,r.jsxs)(t.p,{children:["Allows using ",(0,r.jsx)(t.a,{href:"https://vimhelp.org/",children:(0,r.jsx)(t.strong,{children:"Vim"})})," and ",(0,r.jsx)(t.a,{href:"https://www.gnu.org/software/emacs/manual/html_node/emacs/Basic.html",children:(0,r.jsx)(t.strong,{children:"Emacs"})})," keyboard bindings. See ",(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#editormode",children:(0,r.jsx)(t.code,{children:"editorMode"})})," configuration option."]}),"\n",(0,r.jsx)(t.p,{children:"(Not supported in CodeJar)"}),"\n",(0,r.jsx)(t.h3,{id:"format-options",children:"Format Options"}),"\n",(0,r.jsxs)(t.p,{children:["These are ",(0,r.jsx)(t.a,{href:"https://prettier.io/",children:(0,r.jsx)(t.strong,{children:"Prettier"})})," ",(0,r.jsx)(t.a,{href:"https://prettier.io/docs/en/options.html",children:"configuration options"})," used for code formatting."]}),"\n",(0,r.jsxs)(t.p,{children:["In addition to those specified in ",(0,r.jsx)(t.a,{href:"#editor-options",children:"Editor Options"}),", the following options are available:"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#semicolons",children:"Use Semicolons"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#singlequote",children:"Use Single Quotes"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"/docs/configuration/configuration-object#trailingcomma",children:"Use Trailing Commas"})}),"\n"]})]})}function u(e={}){let{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},9947:function(e,t,o){"use strict";o.d(t,{Z:function(){return n}});let n=o.p+"assets/images/editor-settings-1-f401ae77e35e8e11b6427b4f1eb67bb9.jpg"},516:function(e,t,o){"use strict";o.d(t,{Z:function(){return n}});let n=o.p+"assets/images/editor-settings-2-dcbfd00bb00d3759e59daec48d1dc905.jpg"},8423:function(e,t,o){"use strict";o.d(t,{Z:function(){return n}});let n=o.p+"assets/images/editor-settings-3-33c11e13b5bd21a710703dc0dd6bebb6.jpg"},7728:function(e,t,o){e=o.nmd(e);var n=function(){var e=String.fromCharCode,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",n={};function r(e,t){if(!n[e]){n[e]={};for(var o=0;o<e.length;o++)n[e][e.charAt(o)]=o}return n[e][t]}var i={compressToBase64:function(e){if(null==e)return"";var o=i._compress(e,6,function(e){return t.charAt(e)});switch(o.length%4){default:case 0:return o;case 1:return o+"===";case 2:return o+"==";case 3:return o+"="}},decompressFromBase64:function(e){return null==e?"":""==e?null:i._decompress(e.length,32,function(o){return r(t,e.charAt(o))})},compressToUTF16:function(t){return null==t?"":i._compress(t,15,function(t){return e(t+32)})+" "},decompressFromUTF16:function(e){return null==e?"":""==e?null:i._decompress(e.length,16384,function(t){return e.charCodeAt(t)-32})},compressToUint8Array:function(e){for(var t=i.compress(e),o=new Uint8Array(2*t.length),n=0,r=t.length;n<r;n++){var s=t.charCodeAt(n);o[2*n]=s>>>8,o[2*n+1]=s%256}return o},decompressFromUint8Array:function(t){if(null==t)return i.decompress(t);for(var o=Array(t.length/2),n=0,r=o.length;n<r;n++)o[n]=256*t[2*n]+t[2*n+1];var s=[];return o.forEach(function(t){s.push(e(t))}),i.decompress(s.join(""))},compressToEncodedURIComponent:function(e){return null==e?"":i._compress(e,6,function(e){return o.charAt(e)})},decompressFromEncodedURIComponent:function(e){return null==e?"":""==e?null:(e=e.replace(/ /g,"+"),i._decompress(e.length,32,function(t){return r(o,e.charAt(t))}))},compress:function(t){return i._compress(t,16,function(t){return e(t)})},_compress:function(e,t,o){if(null==e)return"";var n,r,i,s={},a={},c="",d="",l="",h=2,u=3,f=2,p=[],g=0,m=0;for(i=0;i<e.length;i+=1)if(c=e.charAt(i),Object.prototype.hasOwnProperty.call(s,c)||(s[c]=u++,a[c]=!0),d=l+c,Object.prototype.hasOwnProperty.call(s,d))l=d;else{if(Object.prototype.hasOwnProperty.call(a,l)){if(256>l.charCodeAt(0)){for(n=0;n<f;n++)g<<=1,m==t-1?(m=0,p.push(o(g)),g=0):m++;for(n=0,r=l.charCodeAt(0);n<8;n++)g=g<<1|1&r,m==t-1?(m=0,p.push(o(g)),g=0):m++,r>>=1}else{for(n=0,r=1;n<f;n++)g=g<<1|r,m==t-1?(m=0,p.push(o(g)),g=0):m++,r=0;for(n=0,r=l.charCodeAt(0);n<16;n++)g=g<<1|1&r,m==t-1?(m=0,p.push(o(g)),g=0):m++,r>>=1}0==--h&&(h=Math.pow(2,f),f++),delete a[l]}else for(n=0,r=s[l];n<f;n++)g=g<<1|1&r,m==t-1?(m=0,p.push(o(g)),g=0):m++,r>>=1;0==--h&&(h=Math.pow(2,f),f++),s[d]=u++,l=String(c)}if(""!==l){if(Object.prototype.hasOwnProperty.call(a,l)){if(256>l.charCodeAt(0)){for(n=0;n<f;n++)g<<=1,m==t-1?(m=0,p.push(o(g)),g=0):m++;for(n=0,r=l.charCodeAt(0);n<8;n++)g=g<<1|1&r,m==t-1?(m=0,p.push(o(g)),g=0):m++,r>>=1}else{for(n=0,r=1;n<f;n++)g=g<<1|r,m==t-1?(m=0,p.push(o(g)),g=0):m++,r=0;for(n=0,r=l.charCodeAt(0);n<16;n++)g=g<<1|1&r,m==t-1?(m=0,p.push(o(g)),g=0):m++,r>>=1}0==--h&&(h=Math.pow(2,f),f++),delete a[l]}else for(n=0,r=s[l];n<f;n++)g=g<<1|1&r,m==t-1?(m=0,p.push(o(g)),g=0):m++,r>>=1;0==--h&&(h=Math.pow(2,f),f++)}for(n=0,r=2;n<f;n++)g=g<<1|1&r,m==t-1?(m=0,p.push(o(g)),g=0):m++,r>>=1;for(;;){if(g<<=1,m==t-1){p.push(o(g));break}m++}return p.join("")},decompress:function(e){return null==e?"":""==e?null:i._decompress(e.length,32768,function(t){return e.charCodeAt(t)})},_decompress:function(t,o,n){var r,i,s,a,c,d,l,h=[],u=4,f=4,p=3,g="",m=[],j={val:n(0),position:o,index:1};for(r=0;r<3;r+=1)h[r]=r;for(s=0,c=4,d=1;d!=c;)a=j.val&j.position,j.position>>=1,0==j.position&&(j.position=o,j.val=n(j.index++)),s|=(a>0?1:0)*d,d<<=1;switch(s){case 0:for(s=0,c=256,d=1;d!=c;)a=j.val&j.position,j.position>>=1,0==j.position&&(j.position=o,j.val=n(j.index++)),s|=(a>0?1:0)*d,d<<=1;l=e(s);break;case 1:for(s=0,c=65536,d=1;d!=c;)a=j.val&j.position,j.position>>=1,0==j.position&&(j.position=o,j.val=n(j.index++)),s|=(a>0?1:0)*d,d<<=1;l=e(s);break;case 2:return""}for(h[3]=l,i=l,m.push(l);;){if(j.index>t)return"";for(s=0,c=Math.pow(2,p),d=1;d!=c;)a=j.val&j.position,j.position>>=1,0==j.position&&(j.position=o,j.val=n(j.index++)),s|=(a>0?1:0)*d,d<<=1;switch(l=s){case 0:for(s=0,c=256,d=1;d!=c;)a=j.val&j.position,j.position>>=1,0==j.position&&(j.position=o,j.val=n(j.index++)),s|=(a>0?1:0)*d,d<<=1;h[f++]=e(s),l=f-1,u--;break;case 1:for(s=0,c=65536,d=1;d!=c;)a=j.val&j.position,j.position>>=1,0==j.position&&(j.position=o,j.val=n(j.index++)),s|=(a>0?1:0)*d,d<<=1;h[f++]=e(s),l=f-1,u--;break;case 2:return m.join("")}if(0==u&&(u=Math.pow(2,p),p++),h[l])g=h[l];else{if(l!==f)return null;g=i+i.charAt(0)}m.push(g),h[f++]=i+g.charAt(0),u--,i=g,0==u&&(u=Math.pow(2,p),p++)}}};return i}();"function"==typeof define&&define.amd?define(function(){return n}):null!=e&&(e.exports=n)},8500:function(e,t,o){"use strict";o.d(t,{Z:()=>d});var n=o("5893");o("7294");var r=o("6735");function i(e){let{children:t,fallback:o}=e;return(0,r.Z)()?(0,n.jsx)(n.Fragment,{children:t?.()}):o??null}var s=o("1705"),a=o("8294"),c=o("1858");function d(e){let{params:t,config:o,code:r,language:d="js",codeTitle:l="",showLineNumbers:h=!1,formatCode:u=!0,linkText:f="Run in LiveCodes",style:p={},className:g=""}=e,m=(0,a.r)({appUrl:c.G,params:t,config:o});return(0,n.jsxs)("div",{style:{marginBottom:"30px",...p},className:g,children:[r&&(0,n.jsx)(i,{children:()=>(0,n.jsx)(s.Z,{language:d,title:l,showLineNumbers:h,children:u?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})}(r,d):r})}),(0,n.jsxs)("a",{href:m,target:"_blank",rel:"noreferrer",children:[f,(0,n.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,n.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,o){"use strict";o.d(t,{T:function(){return r},r:function(){return i}});var n=o(7728);async function r(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:o={},headless:n,loading:r="lazy",view:s}=t,a=n||"headless"===s,c=null,d=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)A(c=document.createElement("div")),document.body.appendChild(c);else throw Error(`Cannot find element: "${e}"`)}let l=new URL(i(t)),h=l.origin;l.searchParams.set("embed","true"),l.searchParams.set("loading",a?"eager":r);let u=globalThis.process;l.searchParams.set("sdkVersion",u?.env?.SDK_VERSION||"latest"),"object"==typeof o&&Object.keys(o).length>0&&l.searchParams.set("config","sdk");let f=t.params;"object"==typeof f&&Object.keys(f).length>0&&JSON.stringify(f).length<1800&&Object.keys(f).forEach(e=>{l.searchParams.set(e,encodeURIComponent(String(f[e])))});let p=!1,g="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 n="livecodes",i=c.querySelector(`iframe.${n}`),s=i||document.createElement("iframe");s.classList.add(n),s.setAttribute("allow","accelerometer; camera; encrypted-media; display-capture; geolocation; gyroscope; microphone; midi; clipboard-read; clipboard-write; web-share"),s.setAttribute("allowtransparency","true"),s.setAttribute("allowpaymentrequest","true"),s.setAttribute("allowfullscreen","true"),s.setAttribute("sandbox","allow-same-origin allow-downloads allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-presentation allow-scripts"),s.setAttribute("loading","eager"===r?"eager":"lazy"),a?A(s):(s.style.height="100%",s.style.minHeight="200px",s.style.width="100%",s.style.margin="0",s.style.border="0",s.style.borderRadius=c.style.borderRadius),addEventListener("message",function e(t){t.source===s.contentWindow&&t.origin===h&&t.data?.type==="livecodes-init"&&(removeEventListener("message",e),d=Number(t.data.payload.appVersion.replace(/^v/,"")))}),(!d||d<46)&&addEventListener("message",function e(t){t.source===s.contentWindow&&t.origin===h&&t.data?.type==="livecodes-get-config"&&(removeEventListener("message",e),s.contentWindow?.postMessage({type:"livecodes-config",payload:o},h))}),s.onload=()=>{e(s)},s.src=l.href,i||c.appendChild(s)}),j=new Promise(e=>{addEventListener("message",function t(o){o.source===m.contentWindow&&o.origin===h&&o.data?.type==="livecodes-ready"&&(removeEventListener("message",t),e(),j.settled=!0)})}),x=()=>p?Promise.reject(g):new Promise(async e=>{j.settled&&e(),m.contentWindow?.postMessage({type:"livecodes-load"},h),await j,e()}),v=(e,t)=>new Promise(async(o,n)=>{if(p)return n(g);await x();let r=S();addEventListener("message",function t(i){if(i.source===m.contentWindow&&i.origin===h&&i.data?.type==="livecodes-api-response"&&i.data?.id===r&&i.data.method===e){removeEventListener("message",t);let e=i.data.payload;e?.error?n(e.error):o(e)}}),m.contentWindow?.postMessage({method:e,id:r,args:t},h)}),b={},y=["load","ready","code","console","tests","destroy"],w=(e,t)=>{if(p)throw Error(g);return y.includes(e)?(v("watch",[e]),b[e]||(b[e]=[]),b[e]?.push(t),{remove:()=>{b[e]=b[e]?.filter(e=>e!==t),b[e]?.length===0&&v("watch",[e,"unsubscribe"])}}):{remove:()=>void 0}},E=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=E(e.data?.type??"");if(e.source!==m.contentWindow||e.origin!==h||!t||!b[t])return;let o=e.data?.payload;b[t]?.forEach(e=>{e(o)})});let C=()=>{Object.values(b).forEach(e=>{e.length=0}),m?.remove?.(),p=!0};function A(e){e.style.position="absolute",e.style.top="0",e.style.visibility="hidden",e.style.opacity="0"}"lazy"===r&&"IntersectionObserver"in window&&new IntersectionObserver((e,t)=>{e.forEach(async e=>{e.isIntersecting&&(await x(),t.unobserve(c))})},{rootMargin:"150px"}).observe(c);let S=()=>(String(Math.random())+Date.now().toFixed()).replace("0.","");return{load:()=>x(),run:()=>v("run"),format:e=>v("format",[e]),getShareUrl:e=>v("getShareUrl",[e]),getConfig:e=>v("getConfig",[e]),setConfig:e=>v("setConfig",[e]),getCode:()=>v("getCode"),show:(e,t)=>v("show",[e,t]),runTests:()=>v("runTests"),onChange:e=>w("code",e),watch:w,exec:function(e){for(var t=arguments.length,o=Array(t>1?t-1:0),n=1;n<t;n++)o[n-1]=arguments[n];return v("exec",[e,...o])},destroy:()=>j.settled?v("destroy").then(C):p?Promise.reject(g):(C(),Promise.resolve())}}function i(){let e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{appUrl:o="https://livecodes.io",params:r={},config:i={},headless:s,import:a,lite:c,view:d,...l}=t;try{e=new URL(o)}catch{throw Error(`${o} is not a valid URL.`)}let h=new URLSearchParams;Object.entries(l).forEach(t=>{let[o,n]=t;void 0!==n&&e.searchParams.set(o,String(n))});let u="headless"===t.view||s;if(c&&(console.warn('Deprecation notice: "lite" option is deprecated. Use "config: { mode: \'lite\' }" instead.'),"object"==typeof i&&null==i.mode?i.mode="lite":e.searchParams.set("lite","true")),d&&(console.warn('Deprecation notice: The "view" option has been moved to "config.view". For headless mode use "headless: true".'),"object"==typeof i&&null==i.view&&"headless"!==d?i.view=d:e.searchParams.set("view",d)),"string"==typeof i)try{new URL(i),e.searchParams.set("config",encodeURIComponent(i))}catch{throw Error('"config" is not a valid URL or configuration object.')}else i&&"object"==typeof i&&Object.keys(i).length>0&&(i.title&&"Untitled Project"!==i.title&&e.searchParams.set("title",i.title),i.description&&i.description.length>0&&e.searchParams.set("description",i.description),h.set("config","code/"+(0,n.compressToEncodedURIComponent)(JSON.stringify(i))));if(r&&"object"==typeof r&&Object.keys(r).length>0)try{h.set("params",(0,n.compressToEncodedURIComponent)(JSON.stringify(r)))}catch{Object.keys(r).forEach(t=>{e.searchParams.set(t,encodeURIComponent(String(r[t])))})}return a&&e.searchParams.set("x",encodeURIComponent(a)),u&&e.searchParams.set("headless","true"),e.hash=h.toString(),e.href}},65:function(e,t,o){"use strict";o.d(t,{Z:function(){return a},a:function(){return s}});var n=o(7294);let r={},i=n.createContext(r);function s(e){let t=n.useContext(i);return n.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(r):e.components||r:s(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); |