livecode-static/docs/assets/js/8bdd886c.787f7ca6.js
2025-06-11 22:23:49 +08:00

52 lines
16 KiB
JavaScript

"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["3746"],{8560:function(e,t,s){s.r(t),s.d(t,{default:()=>p,frontMatter:()=>a,htmlOnlyConfig:()=>c,assets:()=>d,metadata:()=>n,toc:()=>h,contentTitle:()=>l});var n=JSON.parse('{"id":"languages/html","title":"HTML","description":"HTML (HyperText Markup Language) is the standard markup language for creating web pages and web applications. It defines the structure and content of web pages.","source":"@site/docs/languages/html.mdx","sourceDirName":"languages","slug":"/languages/html","permalink":"/docs/languages/html","draft":false,"unlisted":false,"editUrl":"https://github.com/live-codes/livecodes/tree/develop/docs/docs/languages/html.mdx","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"Handlebars","permalink":"/docs/languages/handlebars"},"next":{"title":"Imba","permalink":"/docs/languages/imba"}}'),r=s("5893"),o=s("65"),i=s("3365");let a={},l="HTML",d={},c={markup:{language:"html",content:`<h1>Hello, LiveCodes!</h1>
<p>This is a paragraph in HTML.</p>
<ul>
<li>Simple</li>
<li>Structured</li>
<li>Semantic</li>
</ul>
`}},h=[{value:"Usage",id:"usage",level:2},{value:"Demo",id:"demo",level:3},{value:"Styles and JavaScript",id:"styles-and-javascript",level:3},{value:"Language Info",id:"language-info",level:2},{value:"Name",id:"name",level:3},{value:"Extensions",id:"extensions",level:3},{value:"Editor",id:"editor",level:3},{value:"Compiler",id:"compiler",level:2},{value:"Code Formatting",id:"code-formatting",level:2},{value:"Links",id:"links",level:2}];function u(e){let t={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",li:"li",p:"p",ul:"ul",...(0,o.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.header,{children:(0,r.jsx)(t.h1,{id:"html",children:"HTML"})}),"\n","\n",(0,r.jsx)(t.p,{children:"HTML (HyperText Markup Language) is the standard markup language for creating web pages and web applications. It defines the structure and content of web pages."}),"\n",(0,r.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsxs)(t.p,{children:["HTML code in the ",(0,r.jsx)(t.a,{href:"/docs/features/projects#markup-editor",children:"markup editor"})," is added as is without compilation or processing to the body of the ",(0,r.jsx)(t.a,{href:"/docs/features/result",children:"result page"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:["There is no need to add a full page structure (e.g. ",(0,r.jsx)(t.code,{children:"<html>"}),", ",(0,r.jsx)(t.code,{children:"<head>"}),", ",(0,r.jsx)(t.code,{children:"<body>"})," tags). This is already handled by LiveCodes.\n(See ",(0,r.jsx)(t.a,{href:"/docs/features/result#result-page-structure",children:"Result Page Structure"})," for more details.)"]}),"\n",(0,r.jsxs)(t.p,{children:["If you need to add content to the ",(0,r.jsx)(t.code,{children:"<head>"})," section or ",(0,r.jsx)(t.code,{children:"<html>"})," attributes of the result page, you can add it in the ",(0,r.jsx)(t.a,{href:"https://livecodes.io/?screen=info",children:"project info screen"}),"."]}),"\n",(0,r.jsx)(t.h3,{id:"demo",children:"Demo"}),"\n","\n",(0,r.jsx)(i.Z,{config:c}),"\n",(0,r.jsx)(t.h3,{id:"styles-and-javascript",children:"Styles and JavaScript"}),"\n",(0,r.jsxs)(t.p,{children:["Most of the time, you will want to add styles and scripts in the ",(0,r.jsx)(t.a,{href:"/docs/features/projects",children:"respective editors"}),".\nHowever, you can of course still add them in ",(0,r.jsx)(t.code,{children:"<link>"}),", ",(0,r.jsx)(t.code,{children:"<style>"})," and ",(0,r.jsx)(t.code,{children:"<script>"})," tags in HTML.\nThis can be useful in different scenarios, such as adding global variables that are then used in the script editor,\nor adding JavaScript together with a different script editor language (e.g. see ",(0,r.jsx)(t.a,{href:"https://livecodes.io/?template=sql&activeEditor=markup",children:"SQL starter template"}),")"]}),"\n",(0,r.jsx)(t.h2,{id:"language-info",children:"Language Info"}),"\n",(0,r.jsx)(t.h3,{id:"name",children:"Name"}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.code,{children:"html"})}),"\n",(0,r.jsx)(t.h3,{id:"extensions",children:"Extensions"}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:".html"}),", ",(0,r.jsx)(t.code,{children:".htm"})]}),"\n",(0,r.jsx)(t.h3,{id:"editor",children:"Editor"}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.code,{children:"markup"})}),"\n",(0,r.jsx)(t.h2,{id:"compiler",children:"Compiler"}),"\n",(0,r.jsx)(t.p,{children:"None."}),"\n",(0,r.jsx)(t.h2,{id:"code-formatting",children:"Code Formatting"}),"\n",(0,r.jsxs)(t.p,{children:["Using ",(0,r.jsx)(t.a,{href:"https://prettier.io/",children:"Prettier"}),"."]}),"\n",(0,r.jsx)(t.h2,{id:"links",children:"Links"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/HTML",children:"HTML: HyperText Markup Language (MDN)"})}),"\n",(0,r.jsx)(t.li,{children:(0,r.jsx)(t.a,{href:"https://www.w3schools.com/html/",children:"HTML Tutorial (W3Schools)"})}),"\n"]})]})}function p(e={}){let{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(u,{...e})}):u(e)}},3365:function(e,t,s){s.d(t,{Z:()=>f});var n=s("5893"),r=s("4200"),o=s("7294"),i=s("8294");function a(e){let t=(0,o.useRef)(null),[s,r]=(0,o.useState)(e.className||""),[a,l]=(0,o.useState)(e.style||{}),[d,c]=(0,o.useState)(e.height),[h,u]=(0,o.useState)(),[p,g]=(0,o.useState)(JSON.stringify(e.config||"")),[m,f]=(0,o.useState)("");return(0,o.useEffect)(()=>{if(!t.current)return;let{className:s,style:n,height:o,sdkReady:a,config:d,...v}=e;if(r(s||""),l(n||{}),c(o),h&&m===JSON.stringify(v)){if(p===JSON.stringify(d))return;g(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=>{u(e),"function"==typeof a&&a(e)})},[e]),(0,o.useEffect)(()=>()=>{h?.destroy()},[]),(0,n.jsx)("div",{ref:t,className:s,style:a,"data-height":d})}var l=s("1858"),d=s("3262"),c=s("1705"),h=s("7645"),u=s("8168"),p=s("8228"),g=s("5050");function m(e){let[t,s]=(0,o.useState)(e.js),[r,i]=(0,o.useState)(e.ts),[a,l]=(0,o.useState)(e.react),[m,f]=(0,o.useState)(e.vue),[v,y]=(0,o.useState)(e.svelte),j="3.7rem",[x,b]=(0,o.useState)(!0),[w,S]=(0,o.useState)(j),L=(0,o.useRef)(null),C=()=>{setTimeout(()=>{S(`calc(${L.current.offsetHeight}px + ${j})`)},5),setTimeout(()=>{S(`calc(${L.current.offsetHeight}px + ${j})`)},255)};return(0,o.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}};s(e(t,"js")),i(e(r,"ts")),l(e(a,"jsx")),f(e(m,"html")),y(e(v,"html"))}},[]),(0,n.jsxs)("details",{className:`alert alert--info ${g.Z.details} ${p.Z.details}`,"data-collapsed":x,style:{height:x?j:w,overflow:"hidden",willChange:"height",transition:`height ${x?"250ms":"265ms"} ease-in-out 0s`,margin:"1em 0"},children:[(0,n.jsx)("summary",{onClick:()=>{b(!x),C()},children:"show code"}),(0,n.jsx)("div",{ref:L,style:{display:"block",overflow:"hidden"},children:(0,n.jsx)("div",{className:g.Z.collapsibleContent,children:(0,n.jsxs)(u.Z,{groupId:"sdk-code",children:[(0,n.jsx)(h.Z,{value:"js",label:"JS",attributes:{onMouseDown:C},children:(0,n.jsx)(c.Z,{language:"js",children:t})}),(0,n.jsx)(h.Z,{value:"ts",label:"TS",attributes:{onMouseDown:C},children:(0,n.jsx)(c.Z,{language:"ts",children:r})}),(0,n.jsx)(h.Z,{value:"react",label:"React",attributes:{onMouseDown:C},children:(0,n.jsx)(c.Z,{language:"jsx",children:a})}),(0,n.jsx)(h.Z,{value:"vue",label:"Vue",attributes:{onMouseDown:C},children:(0,n.jsx)(c.Z,{language:"html",children:m})}),(0,n.jsx)(h.Z,{value:"svelte",label:"Svelte",attributes:{onMouseDown:C},children:(0,n.jsx)(c.Z,{language:"html",children:v})})]})})})]})}function f(e){let{className:t,style:s,showCode:o,height:i,...d}=e,{colorMode:c}=(0,r.I)(),h=e=>JSON.stringify(e,null,2),u=`
import { createPlayground } from 'livecodes';
const options = ${h(d)};
createPlayground('#container', options);
`.trimStart(),p=`
import { createPlayground, type EmbedOptions } from 'livecodes';
const options: EmbedOptions = ${h(d)};
createPlayground('#container', options);
`.trimStart(),g=`
import LiveCodes from 'livecodes/react';
export default function App() {
const options = ${h(d)};
return (<LiveCodes {...options}></LiveCodes>);
}
`.trimStart(),f=`
<script setup>
import LiveCodes from "livecodes/vue";
const options = ${h(d)};
</script>
<template>
<LiveCodes v-bind="options" />
</template>
`,v=`
<script>
import { onMount } from 'svelte';
import { createPlayground } from 'livecodes';
let options = $state(${h(d)});
let container = $state(null);
onMount(() => {
createPlayground(container, options);
});
</script>
<div bind:this="{container}"></div>
`.trimStart();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(a,{className:`container_Egsj ${e.className}`,style:{height:i||"50vh",...e.style},appUrl:l.G,...e,config:{theme:c,themeColor:"hsl(215, 8%, 60%)",..."object"==typeof e.config?e.config:{}}}),!1!==e.showCode&&(0,n.jsx)(m,{js:u,ts:p,react:g,vue:f,svelte:v})]})}},8294:function(e,t,s){s.d(t,{T:function(){return r},r:function(){return o}});var n=s(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:s={},headless:n,loading:r="lazy",view:i}=t,a=n||"headless"===i,l=null,d=null;if("string"==typeof e)l=document.querySelector(e);else if(e instanceof HTMLElement)l=e;else if(!(a&&"object"==typeof e))throw Error("A valid container element is required.");if(!l){if(a)C(l=document.createElement("div")),document.body.appendChild(l);else throw Error(`Cannot find element: "${e}"`)}let c=new URL(o(t)),h=c.origin;c.searchParams.set("embed","true"),c.searchParams.set("loading",a?"eager":r);let u=globalThis.process;c.searchParams.set("sdkVersion",u?.env?.SDK_VERSION||"latest"),"object"==typeof s&&Object.keys(s).length>0&&c.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=>{c.searchParams.set(e,encodeURIComponent(String(p[e])))});let g=!1,m="Cannot call API methods after calling `destroy()`.",f=await new Promise(e=>{if(!l)return;let t=l.dataset.height||l.style.height;if(t&&!a){let e=isNaN(Number(t))?t:t+"px";l.style.height=e}"false"===l.dataset.defaultStyles||a||(l.style.backgroundColor||="#fff",l.style.border||="1px solid black",l.style.borderRadius||="8px",l.style.boxSizing||="border-box",l.style.padding||="0",l.style.width||="100%",l.style.height||=l.style.height||"300px",l.style.minHeight="200px",l.style.flexGrow="1",l.style.overflow||="hidden",l.style.resize||="vertical");let n="livecodes",o=l.querySelector(`iframe.${n}`),i=o||document.createElement("iframe");i.classList.add(n),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"===r?"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=l.style.borderRadius),addEventListener("message",function e(t){t.source===i.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===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=c.href,o||l.appendChild(i)}),v=new Promise(e=>{addEventListener("message",function t(s){s.source===f.contentWindow&&s.origin===h&&s.data?.type==="livecodes-ready"&&(removeEventListener("message",t),e(),v.settled=!0)})}),y=()=>g?Promise.reject(m):new Promise(async e=>{v.settled&&e(),f.contentWindow?.postMessage({type:"livecodes-load"},h),await v,e()}),j=(e,t)=>new Promise(async(s,n)=>{if(g)return n(m);await y();let r=E();addEventListener("message",function t(o){if(o.source===f.contentWindow&&o.origin===h&&o.data?.type==="livecodes-api-response"&&o.data?.id===r&&o.data.method===e){removeEventListener("message",t);let e=o.data.payload;e?.error?n(e.error):s(e)}}),f.contentWindow?.postMessage({method:e,id:r,args:t},h)}),x={},b=["load","ready","code","console","tests","destroy"],w=(e,t)=>{if(g)throw Error(m);return b.includes(e)?(j("watch",[e]),x[e]||(x[e]=[]),x[e]?.push(t),{remove:()=>{x[e]=x[e]?.filter(e=>e!==t),x[e]?.length===0&&j("watch",[e,"unsubscribe"])}}):{remove:()=>void 0}},S=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=S(e.data?.type??"");if(e.source!==f.contentWindow||e.origin!==h||!t||!x[t])return;let s=e.data?.payload;x[t]?.forEach(e=>{e(s)})});let L=()=>{Object.values(x).forEach(e=>{e.length=0}),f?.remove?.(),g=!0};function C(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 y(),t.unobserve(l))})},{rootMargin:"150px"}).observe(l);let E=()=>(String(Math.random())+Date.now().toFixed()).replace("0.","");return{load:()=>y(),run:()=>j("run"),format:e=>j("format",[e]),getShareUrl:e=>j("getShareUrl",[e]),getConfig:e=>j("getConfig",[e]),setConfig:e=>j("setConfig",[e]),getCode:()=>j("getCode"),show:(e,t)=>j("show",[e,t]),runTests:()=>j("runTests"),onChange:e=>w("code",e),watch:w,exec:function(e){for(var t=arguments.length,s=Array(t>1?t-1:0),n=1;n<t;n++)s[n-1]=arguments[n];return j("exec",[e,...s])},destroy:()=>v.settled?j("destroy").then(L):g?Promise.reject(m):(L(),Promise.resolve())}}function o(){let e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{appUrl:s="https://livecodes.io",params:r={},config:o={},headless:i,import:a,lite:l,view:d,...c}=t;try{e=new URL(s)}catch{throw Error(`${s} is not a valid URL.`)}let h=new URLSearchParams;Object.entries(c).forEach(t=>{let[s,n]=t;void 0!==n&&e.searchParams.set(s,String(n))});let u="headless"===t.view||i;if(l&&(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")),d&&(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"!==d?o.view=d:e.searchParams.set("view",d)),"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,n.compressToEncodedURIComponent)(JSON.stringify(o))));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,s){s.d(t,{Z:function(){return a},a:function(){return i}});var n=s(7294);let r={},o=n.createContext(r);function i(e){let t=n.useContext(o);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:i(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]);