"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["5839"],{3943:function(e,s,t){t.r(s),t.d(s,{default:()=>u,frontMatter:()=>l,metadata:()=>r,assets:()=>d,toc:()=>c,contentTitle:()=>a});var r=JSON.parse('{"id":"features/css","title":"CSS","description":"The result page can be styled with CSS using various methods, including:","source":"@site/docs/features/css.mdx","sourceDirName":"features","slug":"/features/css","permalink":"/docs/features/css","draft":false,"unlisted":false,"editUrl":"https://github.com/live-codes/livecodes/tree/develop/docs/docs/features/css.mdx","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"Templates","permalink":"/docs/features/templates"},"next":{"title":"Result Page","permalink":"/docs/features/result"}}'),n=t("5893"),o=t("65"),i=t("3365");let l={},a="CSS",d={},c=[{value:"Style Editor",id:"style-editor",level:2},{value:"Languages",id:"languages",level:3},{value:"CSS Processors",id:"css-processors",level:3},{value:"Style Imports",id:"style-imports",level:3},{value:"Example",id:"example",level:4},{value:"Compiled CSS",id:"compiled-css",level:3},{value:"Auto-update",id:"auto-update",level:3},{value:"External Resources",id:"external-resources",level:2},{value:"CSS Presets",id:"css-presets",level:2},{value:"Stylesheets Imported in Script Editor",id:"stylesheets-imported-in-script-editor",level:2},{value:"External Stylesheets",id:"external-stylesheets",level:3},{value:"./style.css",id:"stylecss",level:3},{value:"CSS Modules",id:"css-modules",level:2},{value:"CSS Frameworks",id:"css-frameworks",level:2},{value:"Styles in Markup & Script",id:"styles-in-markup--script",level:2},{value:"Related",id:"related",level:2}];function h(e){let s={a:"a",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",img:"img",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.header,{children:(0,n.jsx)(s.h1,{id:"css",children:"CSS"})}),"\n","\n",(0,n.jsxs)(s.p,{children:["The ",(0,n.jsx)(s.a,{href:"/docs/features/result",children:"result page"})," can be styled with CSS using various methods, including:"]}),"\n",(0,n.jsx)(s.h2,{id:"style-editor",children:"Style Editor"}),"\n",(0,n.jsxs)(s.p,{children:["Code added to ",(0,n.jsx)(s.a,{href:"/docs/features/projects#style-editor",children:"style editor"})," is ",(0,n.jsx)(s.a,{href:"#languages",children:"compiled"})," and ",(0,n.jsx)(s.a,{href:"#css-processors",children:"processed"}),", then added as CSS to the ",(0,n.jsx)(s.a,{href:"/docs/features/result",children:"result page"})," ",(0,n.jsx)(s.code,{children:"head"})," element."]}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.img,{alt:"LiveCodes styles",src:t(2441).Z+"",width:"2240",height:"1400"})," "]}),"\n",(0,n.jsx)(s.h3,{id:"languages",children:"Languages"}),"\n",(0,n.jsxs)(s.p,{children:["LiveCodes supports multiple languages that compile to CSS, including ",(0,n.jsx)(s.a,{href:"/docs/languages/scss",children:"SCSS"}),", ",(0,n.jsx)(s.a,{href:"/docs/languages/sass",children:"Sass"}),", ",(0,n.jsx)(s.a,{href:"/docs/languages/less",children:"Less"})," and ",(0,n.jsx)(s.a,{href:"/docs/languages/stylus",children:"Stylus"}),". Code authored in any of these languages is compiled to CSS before being added to the ",(0,n.jsx)(s.a,{href:"/docs/features/result",children:"result page"}),"."]}),"\n",(0,n.jsxs)(s.p,{children:["The style language can be selected from the style editor menu. In embedded playgrounds, the language can be configured via the configuration object property ",(0,n.jsx)(s.a,{href:"/docs/configuration/configuration-object#style",children:(0,n.jsx)(s.code,{children:"style.language"})})]}),"\n",(0,n.jsx)(s.h3,{id:"css-processors",children:"CSS Processors"}),"\n",(0,n.jsxs)(s.p,{children:["The (compiled) CSS code can be processed by one or more of the supported CSS processors. Examples of these include: ",(0,n.jsx)(s.a,{href:"/docs/languages/autoprefixer",children:"Autoprefixer"}),", ",(0,n.jsx)(s.a,{href:"/docs/languages/postcssPresetEnv",children:"postcss-preset-env"}),", ",(0,n.jsx)(s.a,{href:"/docs/languages/lightningcss",children:"Lightning CSS"}),", ",(0,n.jsx)(s.a,{href:"/docs/languages/cssmodules",children:"CSS Modules"}),", ",(0,n.jsx)(s.a,{href:"/docs/languages/cssnano",children:"cssnano"}),", ...etc."]}),"\n",(0,n.jsx)(s.p,{children:"Multiple CSS processors can be enabled at the same time. The code is processed in the order of processors placed in the style editor menu of the app."}),"\n",(0,n.jsxs)(s.p,{children:["Processors are enabled in the ",(0,n.jsx)(s.a,{href:"/docs/getting-started#standalone-app",children:"standalone app"})," from the style editor menu, by switching on the toggles of the required processors."]}),"\n",(0,n.jsxs)(s.p,{children:["In embedded playgrounds, processors are enabled via the ",(0,n.jsx)(s.a,{href:"/docs/configuration/configuration-object#processors",children:(0,n.jsx)(s.code,{children:"processors"})})," property of the ",(0,n.jsx)(s.a,{href:"/docs/configuration/configuration-object",children:"configuration object"}),"."]}),"\n",(0,n.jsx)(s.h3,{id:"style-imports",children:"Style Imports"}),"\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.a,{href:"/docs/features/module-resolution#bare-module-imports",children:"Bare modules"})," used with ",(0,n.jsx)(s.code,{children:"@import"})," rules are supposed to be npm modules. These are converted to ",(0,n.jsx)(s.a,{href:"/docs/features/module-resolution#cdn-providers",children:"full URLs from CDN"}),"."]}),"\n",(0,n.jsx)(s.h4,{id:"example",children:"Example"}),"\n",(0,n.jsx)(s.p,{children:"This code:"}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-css",children:"@import 'github-markdown-css/github-markdown.css';\n"})}),"\n",(0,n.jsx)(s.p,{children:"becomes:"}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-css",children:"@import 'https://unpkg.com/github-markdown-css/github-markdown.css';\n"})}),"\n",(0,n.jsx)(s.p,{children:"Packages that specify a stylesheet as the main module can be imported like that:"}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-css",children:"@import 'github-markdown-css';\n"})}),"\n",(0,n.jsx)(s.p,{children:"demo:"}),"\n",(0,n.jsx)(i.Z,{template:"markdown",params:{activeEditor:"style",compiled:"open"}}),"\n",(0,n.jsxs)(s.p,{children:["The content can be inlined in the compiled CSS by enabling the processor ",(0,n.jsx)(s.a,{href:"/docs/languages/postcssImportUrl",children:"postcss-import-url"}),"."]}),"\n",(0,n.jsx)(s.h3,{id:"compiled-css",children:"Compiled CSS"}),"\n",(0,n.jsxs)(s.p,{children:["Compiled CSS (following compilation of style language, and all enabled processors) is added to the ",(0,n.jsx)(s.a,{href:"/docs/features/result",children:"result page"})," ",(0,n.jsx)(s.code,{children:"head"})," element."]}),"\n",(0,n.jsxs)(s.p,{children:["The compiled code can be inspected in the ",(0,n.jsx)(s.a,{href:"/docs/features/compiled-code",children:"compiled code viewer"})," in the ",(0,n.jsx)(s.a,{href:"/docs/features/tools-pane",children:"tools pane"}),"."]}),"\n",(0,n.jsx)(s.h3,{id:"auto-update",children:"Auto-update"}),"\n",(0,n.jsxs)(s.p,{children:["When ",(0,n.jsx)(s.a,{href:"/docs/configuration/configuration-object#autoupdate",children:(0,n.jsx)(s.code,{children:"autoupdate"})})," is enabled (default), in contrast to ",(0,n.jsx)(s.a,{href:"/docs/features/projects#markup-editor",children:"markup editor"})," and ",(0,n.jsx)(s.a,{href:"/docs/features/projects#script-editor",children:"script editor"}),", changes in style editor code does NOT trigger a full reload of the ",(0,n.jsx)(s.a,{href:"/docs/features/result",children:"result page"}),". The updated CSS code is sent to the page and applied without a reload."]}),"\n",(0,n.jsxs)(s.p,{children:["The page can be force-reloaded by clicking the run button or using the keyboard shortcut: ",(0,n.jsx)("kbd",{children:"Shift"}),"\xa0+\xa0",(0,n.jsx)("kbd",{children:"Enter"}),"."]}),"\n",(0,n.jsx)(s.h2,{id:"external-resources",children:"External Resources"}),"\n",(0,n.jsxs)(s.p,{children:["External stylesheets can be added in ",(0,n.jsx)(s.a,{href:"/docs/features/external-resources",children:"external resources"})," screen. These are added to the ",(0,n.jsx)(s.a,{href:"/docs/features/result",children:"result page"})," before the compiled style editor code. This allows code in style editor to override CSS properties in external stylesheets."]}),"\n",(0,n.jsxs)(s.p,{children:["External stylesheets can be added to embedded playgrounds using the ",(0,n.jsx)(s.a,{href:"/docs/configuration/configuration-object",children:"configuration object"})," property ",(0,n.jsx)(s.a,{href:"/docs/configuration/configuration-object#stylesheets",children:(0,n.jsx)(s.code,{children:"stylesheets"})}),"."]}),"\n",(0,n.jsx)(s.h2,{id:"css-presets",children:"CSS Presets"}),"\n",(0,n.jsxs)(s.p,{children:["CSS presets like ",(0,n.jsx)(s.a,{href:"https://necolas.github.io/normalize.css/",children:"Normalize.css"})," and ",(0,n.jsx)(s.a,{href:"https://meyerweb.com/eric/tools/css/reset/",children:"Reset CSS"})," can be selected in ",(0,n.jsx)(s.a,{href:"/docs/features/external-resources#css-presets",children:"external resources"})," screen."]}),"\n",(0,n.jsx)(s.h2,{id:"stylesheets-imported-in-script-editor",children:"Stylesheets Imported in Script Editor"}),"\n",(0,n.jsx)(s.h3,{id:"external-stylesheets",children:"External Stylesheets"}),"\n",(0,n.jsxs)(s.p,{children:["CSS stylesheets imported in the script editor are added to the ",(0,n.jsx)(s.a,{href:"/docs/features/result",children:"result page"})," ",(0,n.jsx)(s.code,{children:"head"})," element. ",(0,n.jsxs)(s.em,{children:["The URL has to end with ",(0,n.jsxs)(s.strong,{children:[(0,n.jsx)(s.code,{children:".css"})," extension"]})]}),"."]}),"\n",(0,n.jsx)(s.p,{children:"For example, adding this in the script editor (JavaScript):"}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",children:"import 'https://unpkg.com/github-markdown-css/github-markdown.css';\n"})}),"\n",(0,n.jsxs)(s.p,{children:["adds this to the page ",(0,n.jsx)(s.code,{children:"head"}),":"]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-html",children:'\n'})}),"\n",(0,n.jsx)(s.p,{children:"Currently, compiling imported stylesheets (e.g. SCSS) is not supported."}),"\n",(0,n.jsxs)(s.p,{children:["Similar to ",(0,n.jsx)(s.a,{href:"#style-imports",children:"imports in style editor"}),", bare imports are converted to full URLs from CDN."]}),"\n",(0,n.jsx)(s.p,{children:"For example:"}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",children:"import 'github-markdown-css/github-markdown.css';\n"})}),"\n",(0,n.jsx)(s.p,{children:"becomes:"}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-html",children:'\n'})}),"\n",(0,n.jsx)(s.h3,{id:"stylecss",children:(0,n.jsx)(s.code,{children:"./style.css"})}),"\n",(0,n.jsxs)(s.p,{children:["Importing the URLs (",(0,n.jsx)(s.code,{children:"./style.css"})," or ",(0,n.jsx)(s.code,{children:"./styles.css"}),") gets the style editor compiled/processed CSS ",(0,n.jsx)(s.strong,{children:"string"})," as the module's default export."]}),"\n",(0,n.jsx)(s.p,{children:"Example:"}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",children:"import styles from './style.css';\n\nconsole.log(styles); // => compiled CSS as string\n"})}),"\n",(0,n.jsx)(s.h2,{id:"css-modules",children:"CSS Modules"}),"\n",(0,n.jsxs)(s.p,{children:["CSS modules are supported and are ",(0,n.jsx)(s.a,{href:"/docs/languages/cssmodules",children:"documented separately"}),"."]}),"\n",(0,n.jsx)(s.h2,{id:"css-frameworks",children:"CSS Frameworks"}),"\n",(0,n.jsxs)(s.p,{children:["Multiple CSS frameworks are supported including ",(0,n.jsx)(s.a,{href:"/docs/languages/tailwindcss",children:"Tailwind CSS"}),", ",(0,n.jsx)(s.a,{href:"/docs/languages/unocss",children:"UnoCSS"})," and ",(0,n.jsx)(s.a,{href:"/docs/languages/windicss",children:"WindiCSS"}),"."]}),"\n",(0,n.jsx)(s.h2,{id:"styles-in-markup--script",children:"Styles in Markup & Script"}),"\n",(0,n.jsx)(s.p,{children:"Of course, styles and stylesheets can still be added as usual in markup and script editors (via HTML elements and/or DOM)."}),"\n",(0,n.jsx)(s.h2,{id:"related",children:"Related"}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsx)(s.li,{children:(0,n.jsx)(s.a,{href:"/docs/features/projects",children:"Projects"})}),"\n",(0,n.jsx)(s.li,{children:(0,n.jsx)(s.a,{href:"/docs/features/external-resources",children:"External resources"})}),"\n",(0,n.jsx)(s.li,{children:(0,n.jsx)(s.a,{href:"/docs/features/module-resolution",children:"Module resolution"})}),"\n"]})]})}function u(e={}){let{wrapper:s}={...(0,o.a)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},2441:function(e,s,t){t.d(s,{Z:function(){return r}});let r=t.p+"assets/images/css-processors-832dad3e4809409f2d12e9d8109f0962.jpg"},3365:function(e,s,t){t.d(s,{Z:()=>f});var r=t("5893"),n=t("4200"),o=t("7294"),i=t("8294");function l(e){let s=(0,o.useRef)(null),[t,n]=(0,o.useState)(e.className||""),[l,a]=(0,o.useState)(e.style||{}),[d,c]=(0,o.useState)(e.height),[h,u]=(0,o.useState)(),[p,m]=(0,o.useState)(JSON.stringify(e.config||"")),[g,f]=(0,o.useState)("");return(0,o.useEffect)(()=>{if(!s.current)return;let{className:t,style:r,height:o,sdkReady:l,config:d,...x}=e;if(n(t||""),a(r||{}),c(o),h&&g===JSON.stringify(x)){if(p===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(x)),h?.destroy(),(0,i.T)(s.current,{config:d,...x}).then(e=>{u(e),"function"==typeof l&&l(e)})},[e]),(0,o.useEffect)(()=>()=>{h?.destroy()},[]),(0,r.jsx)("div",{ref:s,className:t,style:l,"data-height":d})}var a=t("1858"),d=t("3262"),c=t("1705"),h=t("7645"),u=t("8168"),p=t("8228"),m=t("5050");function g(e){let[s,t]=(0,o.useState)(e.js),[n,i]=(0,o.useState)(e.ts),[l,a]=(0,o.useState)(e.react),[g,f]=(0,o.useState)(e.vue),[x,j]=(0,o.useState)(e.svelte),y="3.7rem",[v,S]=(0,o.useState)(!0),[b,w]=(0,o.useState)(y),C=(0,o.useRef)(null),k=()=>{setTimeout(()=>{w(`calc(${C.current.offsetHeight}px + ${y})`)},5),setTimeout(()=>{w(`calc(${C.current.offsetHeight}px + ${y})`)},255)};return(0,o.useEffect)(()=>{if(d.Z.canUseDOM){let e=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"js";try{return window.prettier?.format(e,{parser:"html"===s?"html":"babel",plugins:window.prettierPlugins})}catch{return e}};t(e(s,"js")),i(e(n,"ts")),a(e(l,"jsx")),f(e(g,"html")),j(e(x,"html"))}},[]),(0,r.jsxs)("details",{className:`alert alert--info ${m.Z.details} ${p.Z.details}`,"data-collapsed":v,style:{height:v?y:b,overflow:"hidden",willChange:"height",transition:`height ${v?"250ms":"265ms"} ease-in-out 0s`,margin:"1em 0"},children:[(0,r.jsx)("summary",{onClick:()=>{S(!v),k()},children:"show code"}),(0,r.jsx)("div",{ref:C,style:{display:"block",overflow:"hidden"},children:(0,r.jsx)("div",{className:m.Z.collapsibleContent,children:(0,r.jsxs)(u.Z,{groupId:"sdk-code",children:[(0,r.jsx)(h.Z,{value:"js",label:"JS",attributes:{onMouseDown:k},children:(0,r.jsx)(c.Z,{language:"js",children:s})}),(0,r.jsx)(h.Z,{value:"ts",label:"TS",attributes:{onMouseDown:k},children:(0,r.jsx)(c.Z,{language:"ts",children:n})}),(0,r.jsx)(h.Z,{value:"react",label:"React",attributes:{onMouseDown:k},children:(0,r.jsx)(c.Z,{language:"jsx",children:l})}),(0,r.jsx)(h.Z,{value:"vue",label:"Vue",attributes:{onMouseDown:k},children:(0,r.jsx)(c.Z,{language:"html",children:g})}),(0,r.jsx)(h.Z,{value:"svelte",label:"Svelte",attributes:{onMouseDown:k},children:(0,r.jsx)(c.Z,{language:"html",children:x})})]})})})]})}function f(e){let{className:s,style:t,showCode:o,height:i,...d}=e,{colorMode:c}=(0,n.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(),m=`
import LiveCodes from 'livecodes/react';
export default function App() {
const options = ${h(d)};
return (