11import { useState , useEffect , useRef } from "preact/hooks" ;
2- import { useLiveRegion } from ' ../hooks/useLiveRegion' ;
2+ import { useLiveRegion } from " ../hooks/useLiveRegion" ;
33import CodeMirror , { EditorView } from "@uiw/react-codemirror" ;
44import { javascript } from "@codemirror/lang-javascript" ;
55import { cdnLibraryUrl , cdnSoundUrl } from "@/src/globals/globals" ;
@@ -38,14 +38,19 @@ export const CodeEmbed = (props) => {
3838 ) ;
3939
4040 let { previewWidth, previewHeight } = props ;
41- const canvasMatch = / c r e a t e C a n v a s \( \s * ( \d + ) , \s * ( \d + ) \s * (?: , \s * (?: P 2 D | W E B G L ) \s * ) ? \) / m. exec ( initialCode ) ;
41+ const canvasMatch =
42+ / c r e a t e C a n v a s \( \s * ( \d + ) , \s * ( \d + ) \s * (?: , \s * (?: P 2 D | W E B G L ) \s * ) ? \) / m. exec (
43+ initialCode ,
44+ ) ;
4245 if ( canvasMatch ) {
4346 previewWidth = previewWidth || parseFloat ( canvasMatch [ 1 ] ) ;
4447 previewHeight = previewHeight || parseFloat ( canvasMatch [ 2 ] ) ;
4548 }
4649
4750 // Quick hack to make room for DOM that gets added below the canvas by default
48- const domMatch = / c r e a t e ( B u t t o n | S e l e c t | P | D i v | I n p u t | C o l o r P i c k e r ) / . exec ( initialCode ) ;
51+ const domMatch = / c r e a t e ( B u t t o n | S e l e c t | P | D i v | I n p u t | C o l o r P i c k e r ) / . exec (
52+ initialCode ,
53+ ) ;
4954 if ( domMatch && previewHeight ) {
5055 previewHeight += 100 ;
5156 }
@@ -87,15 +92,15 @@ export const CodeEmbed = (props) => {
8792 }
8893 } , [ ] ) ;
8994
90- if ( ! rendered ) return < div className = "code-placeholder" /> ;
95+ if ( ! rendered ) return < div class = "code-placeholder" /> ;
9196
9297 return (
9398 < div
94- className = { `my-md flex w-full flex-col gap-[20px] overflow-hidden ${ props . allowSideBySide ? "lg:flex-row" : "" } ${ props . fullWidth ? "full-width" : "" } ` }
99+ class = { `my-md flex w-full flex-col gap-[20px] overflow-hidden ${ props . allowSideBySide ? "lg:flex-row" : "" } ${ props . fullWidth ? "full-width" : "" } ` }
95100 >
96101 { props . previewable ? (
97102 < div
98- className = { `ml-0 flex w-fit gap-[20px] ${ largeSketch ? "flex-col" : ( props . allowSideBySide ? "" : "flex-col lg:flex-row" ) } ` }
103+ class = { `ml-0 flex w-fit gap-[20px] ${ largeSketch ? "flex-col" : props . allowSideBySide ? "" : "flex-col lg:flex-row" } ` }
99104 >
100105 < div >
101106 < CodeFrame
@@ -105,19 +110,25 @@ export const CodeEmbed = (props) => {
105110 base = { props . base }
106111 frameRef = { codeFrameRef }
107112 lazyLoad = { props . lazyLoad }
108- scripts = { props . includeSound ? [ cdnLibraryUrl , cdnSoundUrl ] :[ cdnLibraryUrl ] }
113+ scripts = {
114+ props . includeSound
115+ ? [ cdnLibraryUrl , cdnSoundUrl ]
116+ : [ cdnLibraryUrl ]
117+ }
109118 />
110119 </ div >
111- < div className = { `flex gap-2.5 ${ largeSketch ? "flex-row" : "md:flex-row lg:flex-col" } ` } >
120+ < div
121+ class = { `flex gap-2.5 ${ largeSketch ? "flex-row" : "md:flex-row lg:flex-col" } ` }
122+ >
112123 < CircleButton
113- className = "bg-bg-gray-40"
124+ class = "bg-bg-gray-40"
114125 onClick = { updateOrReRun }
115126 ariaLabel = "Run sketch"
116127 >
117128 < Icon kind = "play" />
118129 </ CircleButton >
119130 < CircleButton
120- className = "bg-bg-gray-40"
131+ class = "bg-bg-gray-40"
121132 onClick = { ( ) => {
122133 setPreviewCodeString ( "" ) ;
123134 announce ( "Sketch stopped" ) ;
@@ -129,7 +140,7 @@ export const CodeEmbed = (props) => {
129140 </ div >
130141 </ div >
131142 ) : null }
132- < div className = "code-editor-container relative w-full" >
143+ < div class = "code-editor-container relative w-full" >
133144 < CodeMirror
134145 value = { codeString }
135146 theme = "light"
@@ -155,7 +166,7 @@ export const CodeEmbed = (props) => {
155166 ( editorView . contentDOM . ariaLabel = "Code Editor" )
156167 }
157168 />
158- < div className = "absolute right-0 top-0 flex flex-col gap-xs p-xs md:flex-row" >
169+ < div class = "absolute right-0 top-0 flex flex-col gap-xs p-xs md:flex-row" >
159170 < CopyCodeButton textToCopy = { codeString || initialCode } />
160171 < CircleButton
161172 onClick = { ( ) => {
@@ -164,7 +175,7 @@ export const CodeEmbed = (props) => {
164175 announce ( "Code reset to initial value." ) ;
165176 } }
166177 ariaLabel = "Reset code to initial value"
167- className = "bg-white text-black"
178+ class = "bg-white text-black"
168179 >
169180 < Icon kind = "refresh" />
170181 </ CircleButton >
0 commit comments