"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["804"],{4791:function(e,t,n){n.r(t),n.d(t,{config:()=>f,UMDCode:()=>g,default:()=>b,frontMatter:()=>h,metadata:()=>s,assets:()=>u,ESMCode:()=>m,toc:()=>v,contentTitle:()=>p});var s=JSON.parse('{"id":"getting-started","title":"Getting Started","description":"There are multiple options:","source":"@site/docs/getting-started.mdx","sourceDirName":".","slug":"/getting-started","permalink":"/docs/getting-started","draft":false,"unlisted":false,"editUrl":"https://github.com/live-codes/livecodes/tree/develop/docs/docs/getting-started.mdx","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"Why Another Playground?","permalink":"/docs/why"},"next":{"title":"Features","permalink":"/docs/features/"}}'),o=n("5893"),r=n("65"),i=n("8168"),a=n("7645"),l=n("3365"),d=n("7262"),c=n("1705");let h={},p="Getting Started",u={},m=()=>{let{siteConfig:e}=(0,d.Z)();return(0,o.jsx)(c.Z,{title:"index.html",language:"html",children:`
`})},g=()=>{let{siteConfig:e}=(0,d.Z)();return(0,o.jsx)(c.Z,{title:"index.html",language:"html",children:` `})},f={markup:{language:"markdown",content:"# Hello LiveCodes!"},style:{language:"css",content:"body { color: blue; }"},script:{language:"javascript",content:'console.log("hello from JavaScript!");'},activeEditor:"script"},v=[{value:"Standalone App",id:"standalone-app",level:2},{value:"Embedded Playgrounds",id:"embedded-playgrounds",level:2},{value:"App Embed Screen",id:"app-embed-screen",level:3},{value:"SDK",id:"sdk",level:3},{value:"Option 1: Using a bundler",id:"option-1-using-a-bundler",level:4},{value:"Option 2: Load from CDN",id:"option-2-load-from-cdn",level:4},{value:"Add your own content",id:"add-your-own-content",level:4},{value:"Self-Hosting",id:"self-hosting",level:2}];function y(e){let t={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",p:"p",pre:"pre",...(0,r.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.header,{children:(0,o.jsx)(t.h1,{id:"getting-started",children:"Getting Started"})}),"\n","\n",(0,o.jsx)(t.p,{children:"There are multiple options:"}),"\n",(0,o.jsx)(t.h2,{id:"standalone-app",children:"Standalone App"}),"\n",(0,o.jsxs)(t.p,{children:["The easiest way to get started with LiveCodes is to just use the app (",(0,o.jsx)(t.a,{href:"https://livecodes.io",children:"https://livecodes.io"}),")."]}),"\n",(0,o.jsxs)(t.p,{children:["It is packed with ",(0,o.jsx)(t.a,{href:"/docs/features/",children:"features"})," and offers various ways to ",(0,o.jsx)(t.a,{href:"/docs/features/import",children:"import code"}),"."]}),"\n",(0,o.jsx)(t.h2,{id:"embedded-playgrounds",children:"Embedded Playgrounds"}),"\n",(0,o.jsxs)(t.p,{children:["LiveCodes playgrounds can be easily ",(0,o.jsx)(t.a,{href:"/docs/features/embeds",children:"embedded"})," into any web page. This can be achieved using:"]}),"\n",(0,o.jsx)(t.h3,{id:"app-embed-screen",children:"App Embed Screen"}),"\n",(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.a,{href:"#standalone-app",children:"standalone app"})," allows you to embed any project from the ",(0,o.jsx)(t.a,{href:"/docs/features/embeds",children:"embed screen"}),". The UI allows setting embed options and shows a preview of the embedded playground.\nCopy the generated code snippet (at the bottom of the screen) and add it to the web page that you want to embed the playground in."]}),"\n",(0,o.jsx)(t.h3,{id:"sdk",children:"SDK"}),"\n",(0,o.jsxs)(t.p,{children:["LiveCodes ",(0,o.jsx)(t.a,{href:"/docs/sdk/",children:(0,o.jsx)("abbr",{title:"Software Development Kit",children:"SDK"})})," is available as ",(0,o.jsx)(t.a,{href:"https://www.npmjs.com/package/livecodes",children:"npm package"})," to allow easy embedding and communication with playgrounds."]}),"\n",(0,o.jsx)(t.h4,{id:"option-1-using-a-bundler",children:"Option 1: Using a bundler"}),"\n",(0,o.jsx)(t.p,{children:"Install from npm."}),"\n",(0,o.jsxs)(i.Z,{groupId:"npm2yarn",children:[(0,o.jsx)(a.Z,{value:"npm",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-bash",children:"npm install livecodes\n"})})}),(0,o.jsx)(a.Z,{value:"yarn",label:"Yarn",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-bash",children:"yarn add livecodes\n"})})}),(0,o.jsx)(a.Z,{value:"pnpm",label:"pnpm",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-bash",children:"pnpm add livecodes\n"})})}),(0,o.jsx)(a.Z,{value:"bun",label:"Bun",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-bash",children:"bun add livecodes\n"})})})]}),"\n",(0,o.jsx)(t.p,{children:"then you can use it like that:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:'title="index.js"',children:"import { createPlayground } from 'livecodes';\n\ncreatePlayground('#container', {\n template: 'react',\n // other embed options\n});\n"})}),"\n",(0,o.jsx)(t.h4,{id:"option-2-load-from-cdn",children:"Option 2: Load from CDN"}),"\n",(0,o.jsx)(t.p,{children:"ESM:"}),"\n","\n","\n",(0,o.jsx)(m,{}),"\n",(0,o.jsx)(t.p,{children:"UMD:"}),"\n","\n",(0,o.jsx)(g,{}),"\n",(0,o.jsx)(t.h4,{id:"add-your-own-content",children:"Add your own content"}),"\n",(0,o.jsxs)(t.p,{children:["You may use any of the methods to ",(0,o.jsx)(t.a,{href:"/docs/features/code-prefill",children:"prefill the playground"})," with your own code."]}),"\n",(0,o.jsx)(t.p,{children:"Example:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-js",metastring:'title="index.js"',children:"import { createPlayground } from 'livecodes';\n\nconst config = {\n markup: {\n language: 'markdown',\n content: '# Hello LiveCodes!',\n },\n style: {\n language: 'css',\n content: 'body { color: blue; }',\n },\n script: {\n language: 'javascript',\n content: 'console.log(\"hello from JavaScript!\");',\n },\n activeEditor: 'script',\n};\n\ncreatePlayground('#container', { config, params: { console: 'open' } });\n"})}),"\n","\n",(0,o.jsx)(t.p,{children:"Live demo:\n(this is an interactive playground - try editing the code!)"}),"\n",(0,o.jsx)(l.Z,{config:f,params:{console:"open"}}),"\n",(0,o.jsxs)(t.p,{children:["Please refer to the section on ",(0,o.jsx)(t.a,{href:"/docs/features/embeds",children:"Embedded Playgrounds"})," for more details."]}),"\n",(0,o.jsx)(t.h2,{id:"self-hosting",children:"Self-Hosting"}),"\n",(0,o.jsx)(t.p,{children:"LiveCodes can be hosted on any static file server or CDN."}),"\n",(0,o.jsxs)(t.p,{children:["The easiest way is to download the app from ",(0,o.jsx)(t.a,{href:"https://github.com/live-codes/livecodes/releases",children:"releases"}),", extract the folder and add it to your website."]}),"\n",(0,o.jsxs)(t.p,{children:["Please check the section on ",(0,o.jsx)(t.a,{href:"/docs/features/self-hosting",children:"self-hosting"})," for other methods of self-hosting, including the built-in setup to deploy to GitHub pages and how to use the SDK with the self-hosted app."]})]})}function b(e={}){let{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(y,{...e})}):y(e)}},3365:function(e,t,n){n.d(t,{Z:()=>f});var s=n("5893"),o=n("4200"),r=n("7294"),i=n("8294");function a(e){let t=(0,r.useRef)(null),[n,o]=(0,r.useState)(e.className||""),[a,l]=(0,r.useState)(e.style||{}),[d,c]=(0,r.useState)(e.height),[h,p]=(0,r.useState)(),[u,m]=(0,r.useState)(JSON.stringify(e.config||"")),[g,f]=(0,r.useState)("");return(0,r.useEffect)(()=>{if(!t.current)return;let{className:n,style:s,height:r,sdkReady:a,config:d,...v}=e;if(o(n||""),l(s||{}),c(r),h&&g===JSON.stringify(v)){if(u===JSON.stringify(d))return;m(JSON.stringify(d)),"string"==typeof d?fetch(d).then(e=>e.json()).then(e=>{h?.setConfig(e)}):d&&h.setConfig(d)}else f(JSON.stringify(v)),h?.destroy(),(0,i.T)(t.current,{config:d,...v}).then(e=>{p(e),"function"==typeof a&&a(e)})},[e]),(0,r.useEffect)(()=>()=>{h?.destroy()},[]),(0,s.jsx)("div",{ref:t,className:n,style:a,"data-height":d})}var l=n("1858"),d=n("3262"),c=n("1705"),h=n("7645"),p=n("8168"),u=n("8228"),m=n("5050");function g(e){let[t,n]=(0,r.useState)(e.js),[o,i]=(0,r.useState)(e.ts),[a,l]=(0,r.useState)(e.react),[g,f]=(0,r.useState)(e.vue),[v,y]=(0,r.useState)(e.svelte),b="3.7rem",[j,x]=(0,r.useState)(!0),[w,S]=(0,r.useState)(b),C=(0,r.useRef)(null),P=()=>{setTimeout(()=>{S(`calc(${C.current.offsetHeight}px + ${b})`)},5),setTimeout(()=>{S(`calc(${C.current.offsetHeight}px + ${b})`)},255)};return(0,r.useEffect)(()=>{if(d.Z.canUseDOM){let e=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"js";try{return window.prettier?.format(e,{parser:"html"===t?"html":"babel",plugins:window.prettierPlugins})}catch{return e}};n(e(t,"js")),i(e(o,"ts")),l(e(a,"jsx")),f(e(g,"html")),y(e(v,"html"))}},[]),(0,s.jsxs)("details",{className:`alert alert--info ${m.Z.details} ${u.Z.details}`,"data-collapsed":j,style:{height:j?b:w,overflow:"hidden",willChange:"height",transition:`height ${j?"250ms":"265ms"} ease-in-out 0s`,margin:"1em 0"},children:[(0,s.jsx)("summary",{onClick:()=>{x(!j),P()},children:"show code"}),(0,s.jsx)("div",{ref:C,style:{display:"block",overflow:"hidden"},children:(0,s.jsx)("div",{className:m.Z.collapsibleContent,children:(0,s.jsxs)(p.Z,{groupId:"sdk-code",children:[(0,s.jsx)(h.Z,{value:"js",label:"JS",attributes:{onMouseDown:P},children:(0,s.jsx)(c.Z,{language:"js",children:t})}),(0,s.jsx)(h.Z,{value:"ts",label:"TS",attributes:{onMouseDown:P},children:(0,s.jsx)(c.Z,{language:"ts",children:o})}),(0,s.jsx)(h.Z,{value:"react",label:"React",attributes:{onMouseDown:P},children:(0,s.jsx)(c.Z,{language:"jsx",children:a})}),(0,s.jsx)(h.Z,{value:"vue",label:"Vue",attributes:{onMouseDown:P},children:(0,s.jsx)(c.Z,{language:"html",children:g})}),(0,s.jsx)(h.Z,{value:"svelte",label:"Svelte",attributes:{onMouseDown:P},children:(0,s.jsx)(c.Z,{language:"html",children:v})})]})})})]})}function f(e){let{className:t,style:n,showCode:r,height:i,...d}=e,{colorMode:c}=(0,o.I)(),h=e=>JSON.stringify(e,null,2),p=` import { createPlayground } from 'livecodes'; const options = ${h(d)}; createPlayground('#container', options); `.trimStart(),u=` import { createPlayground, type EmbedOptions } from 'livecodes'; const options: EmbedOptions = ${h(d)}; createPlayground('#container', options); `.trimStart(),m=` import LiveCodes from 'livecodes/react'; export default function App() { const options = ${h(d)}; return (