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,19 +38,14 @@ export const CodeEmbed = (props) => {
3838 ) ;
3939
4040 let { previewWidth, previewHeight } = props ;
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- ) ;
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 ) ;
4542 if ( canvasMatch ) {
4643 previewWidth = previewWidth || parseFloat ( canvasMatch [ 1 ] ) ;
4744 previewHeight = previewHeight || parseFloat ( canvasMatch [ 2 ] ) ;
4845 }
4946
5047 // Quick hack to make room for DOM that gets added below the canvas by default
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- ) ;
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 ) ;
5449 if ( domMatch && previewHeight ) {
5550 previewHeight += 100 ;
5651 }
@@ -59,9 +54,9 @@ export const CodeEmbed = (props) => {
5954 // Ensures DOM-based examples (e.g., createCapture with noCanvas) are visible.
6055 const DEFAULT_PREVIEW_WIDTH = 400 ;
6156 const DEFAULT_PREVIEW_HEIGHT = 300 ;
62- if ( previewWidth === undefined && previewHeight === undefined ) {
63- previewWidth = DEFAULT_PREVIEW_WIDTH ;
64- previewHeight = DEFAULT_PREVIEW_HEIGHT ;
57+ if ( previewWidth === undefined || previewHeight === undefined ) {
58+ previewWidth = previewWidth ?? DEFAULT_PREVIEW_WIDTH ;
59+ previewHeight = previewHeight ?? DEFAULT_PREVIEW_HEIGHT ;
6560 }
6661
6762 const largeSketch = previewWidth && previewWidth > 770 - 60 ;
@@ -100,7 +95,7 @@ export const CodeEmbed = (props) => {
10095 >
10196 { props . previewable ? (
10297 < div
103- className = { `ml-0 flex w-fit gap-[20px] ${ largeSketch ? "flex-col" : props . allowSideBySide ? "" : "flex-col lg:flex-row" } ` }
98+ className = { `ml-0 flex w-fit gap-[20px] ${ largeSketch ? "flex-col" : ( props . allowSideBySide ? "" : "flex-col lg:flex-row" ) } ` }
10499 >
105100 < div >
106101 < CodeFrame
@@ -110,16 +105,10 @@ export const CodeEmbed = (props) => {
110105 base = { props . base }
111106 frameRef = { codeFrameRef }
112107 lazyLoad = { props . lazyLoad }
113- scripts = {
114- props . includeSound
115- ? [ cdnLibraryUrl , cdnSoundUrl ]
116- : [ cdnLibraryUrl ]
117- }
108+ scripts = { props . includeSound ? [ cdnLibraryUrl , cdnSoundUrl ] :[ cdnLibraryUrl ] }
118109 />
119110 </ div >
120- < div
121- className = { `flex gap-2.5 ${ largeSketch ? "flex-row" : "md:flex-row lg:flex-col" } ` }
122- >
111+ < div className = { `flex gap-2.5 ${ largeSketch ? "flex-row" : "md:flex-row lg:flex-col" } ` } >
123112 < CircleButton
124113 className = "bg-bg-gray-40"
125114 onClick = { updateOrReRun }
0 commit comments