livecode-static/docs/assets/js/31219cfd.634dcc6a.js
2025-06-11 22:23:49 +08:00

1 line
16 KiB
JavaScript

(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["7306"],{5140:function(e,t,n){"use strict";n.r(t),n.d(t,{default:()=>u,frontMatter:()=>a,metadata:()=>r,assets:()=>l,toc:()=>d,contentTitle:()=>c});var r=JSON.parse('{"id":"features/snippets","title":"Code Snippets","description":"LiveCodes supports saving and organizing code snippets in different languages.","source":"@site/docs/features/snippets.mdx","sourceDirName":"features","slug":"/features/snippets","permalink":"/docs/features/snippets","draft":false,"unlisted":false,"editUrl":"https://github.com/live-codes/livecodes/tree/develop/docs/docs/features/snippets.mdx","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"Assets","permalink":"/docs/features/assets"},"next":{"title":"Import","permalink":"/docs/features/import"}}'),s=n("5893"),o=n("65"),i=n("8500");let a={},c="Code Snippets",l={},d=[{value:"Related",id:"related",level:2}];function p(e){let t={a:"a",h1:"h1",h2:"h2",header:"header",img:"img",li:"li",p:"p",ul:"ul",...(0,o.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.header,{children:(0,s.jsx)(t.h1,{id:"code-snippets",children:"Code Snippets"})}),"\n",(0,s.jsx)(t.p,{children:"LiveCodes supports saving and organizing code snippets in different languages."}),"\n",(0,s.jsxs)(t.p,{children:["Code snippets are saved locally on user's device. However, they are supported in ",(0,s.jsx)(t.a,{href:"/docs/features/sync",children:"sync"}),", ",(0,s.jsx)(t.a,{href:"/docs/features/backup-restore#backup",children:"backup"})," and ",(0,s.jsx)(t.a,{href:"/docs/features/backup-restore#restore",children:"restore"}),"."]}),"\n",(0,s.jsx)(t.p,{children:"Code snippets screen can be accessed from Settings menu \u2192 Code Snippets."}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.img,{alt:"Code Snippets",src:n(4989).Z+"",width:"2240",height:"1400"})}),"\n","\n",(0,s.jsx)(i.Z,{params:{screen:"snippets"},linkText:"direct link"}),"\n",(0,s.jsx)(t.p,{children:"Each snippet has a title, description, language and code."}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.img,{alt:"Code Snippets",src:n(8794).Z+"",width:"2240",height:"1400"})}),"\n",(0,s.jsx)(t.p,{children:"After adding snippets they can be sorted (by date modified or title), filtered (by language) or searched."}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.img,{alt:"Code Snippets",src:n(8418).Z+"",width:"2240",height:"1400"})}),"\n",(0,s.jsx)(t.p,{children:"Code snippets can then be copied to clipboard and pasted in projects."}),"\n",(0,s.jsx)(t.h2,{id:"related",children:"Related"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"/docs/features/projects",children:"Projects"})}),"\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"/docs/features/assets",children:"Assets"})}),"\n"]})]})}function u(e={}){let{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(p,{...e})}):p(e)}},4989:function(e,t,n){"use strict";n.d(t,{Z:function(){return r}});let r=n.p+"assets/images/snippets-1-d0ec1b73d1effe6e3a8f71e1de7974f2.jpg"},8794:function(e,t,n){"use strict";n.d(t,{Z:function(){return r}});let r=n.p+"assets/images/snippets-add-cbb29a5991e12bc4e64f65d0a3f08b17.jpg"},8418:function(e,t,n){"use strict";n.d(t,{Z:function(){return r}});let r=n.p+"assets/images/snippets-list-533f9ab8a9a39913fc9c91bf92570635.jpg"},7728:function(e,t,n){e=n.nmd(e);var r=function(){var e=String.fromCharCode,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",r={};function s(e,t){if(!r[e]){r[e]={};for(var n=0;n<e.length;n++)r[e][e.charAt(n)]=n}return r[e][t]}var o={compressToBase64:function(e){if(null==e)return"";var n=o._compress(e,6,function(e){return t.charAt(e)});switch(n.length%4){default:case 0:return n;case 1:return n+"===";case 2:return n+"==";case 3:return n+"="}},decompressFromBase64:function(e){return null==e?"":""==e?null:o._decompress(e.length,32,function(n){return s(t,e.charAt(n))})},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),n=new Uint8Array(2*t.length),r=0,s=t.length;r<s;r++){var i=t.charCodeAt(r);n[2*r]=i>>>8,n[2*r+1]=i%256}return n},decompressFromUint8Array:function(t){if(null==t)return o.decompress(t);for(var n=Array(t.length/2),r=0,s=n.length;r<s;r++)n[r]=256*t[2*r]+t[2*r+1];var i=[];return n.forEach(function(t){i.push(e(t))}),o.decompress(i.join(""))},compressToEncodedURIComponent:function(e){return null==e?"":o._compress(e,6,function(e){return n.charAt(e)})},decompressFromEncodedURIComponent:function(e){return null==e?"":""==e?null:(e=e.replace(/ /g,"+"),o._decompress(e.length,32,function(t){return s(n,e.charAt(t))}))},compress:function(t){return o._compress(t,16,function(t){return e(t)})},_compress:function(e,t,n){if(null==e)return"";var r,s,o,i={},a={},c="",l="",d="",p=2,u=3,h=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]=u++,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<h;r++)m<<=1,g==t-1?(g=0,f.push(n(m)),m=0):g++;for(r=0,s=d.charCodeAt(0);r<8;r++)m=m<<1|1&s,g==t-1?(g=0,f.push(n(m)),m=0):g++,s>>=1}else{for(r=0,s=1;r<h;r++)m=m<<1|s,g==t-1?(g=0,f.push(n(m)),m=0):g++,s=0;for(r=0,s=d.charCodeAt(0);r<16;r++)m=m<<1|1&s,g==t-1?(g=0,f.push(n(m)),m=0):g++,s>>=1}0==--p&&(p=Math.pow(2,h),h++),delete a[d]}else for(r=0,s=i[d];r<h;r++)m=m<<1|1&s,g==t-1?(g=0,f.push(n(m)),m=0):g++,s>>=1;0==--p&&(p=Math.pow(2,h),h++),i[l]=u++,d=String(c)}if(""!==d){if(Object.prototype.hasOwnProperty.call(a,d)){if(256>d.charCodeAt(0)){for(r=0;r<h;r++)m<<=1,g==t-1?(g=0,f.push(n(m)),m=0):g++;for(r=0,s=d.charCodeAt(0);r<8;r++)m=m<<1|1&s,g==t-1?(g=0,f.push(n(m)),m=0):g++,s>>=1}else{for(r=0,s=1;r<h;r++)m=m<<1|s,g==t-1?(g=0,f.push(n(m)),m=0):g++,s=0;for(r=0,s=d.charCodeAt(0);r<16;r++)m=m<<1|1&s,g==t-1?(g=0,f.push(n(m)),m=0):g++,s>>=1}0==--p&&(p=Math.pow(2,h),h++),delete a[d]}else for(r=0,s=i[d];r<h;r++)m=m<<1|1&s,g==t-1?(g=0,f.push(n(m)),m=0):g++,s>>=1;0==--p&&(p=Math.pow(2,h),h++)}for(r=0,s=2;r<h;r++)m=m<<1|1&s,g==t-1?(g=0,f.push(n(m)),m=0):g++,s>>=1;for(;;){if(m<<=1,g==t-1){f.push(n(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,n,r){var s,o,i,a,c,l,d,p=[],u=4,h=4,f=3,m="",g=[],v={val:r(0),position:n,index:1};for(s=0;s<3;s+=1)p[s]=s;for(i=0,c=4,l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=n,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=n,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=n,v.val=r(v.index++)),i|=(a>0?1:0)*l,l<<=1;d=e(i);break;case 2:return""}for(p[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=n,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=n,v.val=r(v.index++)),i|=(a>0?1:0)*l,l<<=1;p[h++]=e(i),d=h-1,u--;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=n,v.val=r(v.index++)),i|=(a>0?1:0)*l,l<<=1;p[h++]=e(i),d=h-1,u--;break;case 2:return g.join("")}if(0==u&&(u=Math.pow(2,f),f++),p[d])m=p[d];else{if(d!==h)return null;m=o+o.charAt(0)}g.push(m),p[h++]=o+m.charAt(0),u--,o=m,0==u&&(u=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,n){"use strict";n.d(t,{Z:()=>l});var r=n("5893");n("7294");var s=n("6735");function o(e){let{children:t,fallback:n}=e;return(0,s.Z)()?(0,r.jsx)(r.Fragment,{children:t?.()}):n??null}var i=n("1705"),a=n("8294"),c=n("1858");function l(e){let{params:t,config:n,code:s,language:l="js",codeTitle:d="",showLineNumbers:p=!1,formatCode:u=!0,linkText:h="Run in LiveCodes",style:f={},className:m=""}=e,g=(0,a.r)({appUrl:c.G,params:t,config:n});return(0,r.jsxs)("div",{style:{marginBottom:"30px",...f},className:m,children:[s&&(0,r.jsx)(o,{children:()=>(0,r.jsx)(i.Z,{language:l,title:d,showLineNumbers:p,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})}(s,l):s})}),(0,r.jsxs)("a",{href:g,target:"_blank",rel:"noreferrer",children:[h,(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,n){"use strict";n.d(t,{T:function(){return s},r:function(){return o}});var r=n(7728);async function s(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:n={},headless:r,loading:s="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)k(c=document.createElement("div")),document.body.appendChild(c);else throw Error(`Cannot find element: "${e}"`)}let d=new URL(o(t)),p=d.origin;d.searchParams.set("embed","true"),d.searchParams.set("loading",a?"eager":s);let u=globalThis.process;d.searchParams.set("sdkVersion",u?.env?.SDK_VERSION||"latest"),"object"==typeof n&&Object.keys(n).length>0&&d.searchParams.set("config","sdk");let h=t.params;"object"==typeof h&&Object.keys(h).length>0&&JSON.stringify(h).length<1800&&Object.keys(h).forEach(e=>{d.searchParams.set(e,encodeURIComponent(String(h[e])))});let f=!1,m="Cannot call API methods after calling `destroy()`.",g=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"===s?"eager":"lazy"),a?k(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===p&&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===p&&t.data?.type==="livecodes-get-config"&&(removeEventListener("message",e),i.contentWindow?.postMessage({type:"livecodes-config",payload:n},p))}),i.onload=()=>{e(i)},i.src=d.href,o||c.appendChild(i)}),v=new Promise(e=>{addEventListener("message",function t(n){n.source===g.contentWindow&&n.origin===p&&n.data?.type==="livecodes-ready"&&(removeEventListener("message",t),e(),v.settled=!0)})}),y=()=>f?Promise.reject(m):new Promise(async e=>{v.settled&&e(),g.contentWindow?.postMessage({type:"livecodes-load"},p),await v,e()}),w=(e,t)=>new Promise(async(n,r)=>{if(f)return r(m);await y();let s=A();addEventListener("message",function t(o){if(o.source===g.contentWindow&&o.origin===p&&o.data?.type==="livecodes-api-response"&&o.data?.id===s&&o.data.method===e){removeEventListener("message",t);let e=o.data.payload;e?.error?r(e.error):n(e)}}),g.contentWindow?.postMessage({method:e,id:s,args:t},p)}),b={},x=["load","ready","code","console","tests","destroy"],j=(e,t)=>{if(f)throw Error(m);return x.includes(e)?(w("watch",[e]),b[e]||(b[e]=[]),b[e]?.push(t),{remove:()=>{b[e]=b[e]?.filter(e=>e!==t),b[e]?.length===0&&w("watch",[e,"unsubscribe"])}}):{remove:()=>void 0}},C=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=C(e.data?.type??"");if(e.source!==g.contentWindow||e.origin!==p||!t||!b[t])return;let n=e.data?.payload;b[t]?.forEach(e=>{e(n)})});let E=()=>{Object.values(b).forEach(e=>{e.length=0}),g?.remove?.(),f=!0};function k(e){e.style.position="absolute",e.style.top="0",e.style.visibility="hidden",e.style.opacity="0"}"lazy"===s&&"IntersectionObserver"in window&&new IntersectionObserver((e,t)=>{e.forEach(async e=>{e.isIntersecting&&(await y(),t.unobserve(c))})},{rootMargin:"150px"}).observe(c);let A=()=>(String(Math.random())+Date.now().toFixed()).replace("0.","");return{load:()=>y(),run:()=>w("run"),format:e=>w("format",[e]),getShareUrl:e=>w("getShareUrl",[e]),getConfig:e=>w("getConfig",[e]),setConfig:e=>w("setConfig",[e]),getCode:()=>w("getCode"),show:(e,t)=>w("show",[e,t]),runTests:()=>w("runTests"),onChange:e=>j("code",e),watch:j,exec:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return w("exec",[e,...n])},destroy:()=>v.settled?w("destroy").then(E):f?Promise.reject(m):(E(),Promise.resolve())}}function o(){let e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{appUrl:n="https://livecodes.io",params:s={},config:o={},headless:i,import:a,lite:c,view:l,...d}=t;try{e=new URL(n)}catch{throw Error(`${n} is not a valid URL.`)}let p=new URLSearchParams;Object.entries(d).forEach(t=>{let[n,r]=t;void 0!==r&&e.searchParams.set(n,String(r))});let u="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),p.set("config","code/"+(0,r.compressToEncodedURIComponent)(JSON.stringify(o))));if(s&&"object"==typeof s&&Object.keys(s).length>0)try{p.set("params",(0,r.compressToEncodedURIComponent)(JSON.stringify(s)))}catch{Object.keys(s).forEach(t=>{e.searchParams.set(t,encodeURIComponent(String(s[t])))})}return a&&e.searchParams.set("x",encodeURIComponent(a)),u&&e.searchParams.set("headless","true"),e.hash=p.toString(),e.href}},65:function(e,t,n){"use strict";n.d(t,{Z:function(){return a},a:function(){return i}});var r=n(7294);let s={},o=r.createContext(s);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(s):e.components||s:i(e.components),r.createElement(o.Provider,{value:t},e.children)}}}]);