File tree 2 files changed +50
-2
lines changed
2 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -3,13 +3,37 @@ import { Decode } from 'console-feed';
3
3
import { dispatchConsoleEvent } from '../actions/console' ;
4
4
import { stopSketch , expandConsole } from '../actions/ide' ;
5
5
6
+ // Helper function to restore p5.Font objects
7
+ function restoreP5Font ( obj ) {
8
+ if ( obj && obj . _isP5Font ) {
9
+ // Return a simplified font-like object for console display
10
+ return {
11
+ _isP5Font : true ,
12
+ name : obj . name ,
13
+ path : obj . path ,
14
+ face : {
15
+ family : obj . face ?. family ,
16
+ style : obj . face ?. style ,
17
+ weight : obj . face ?. weight
18
+ }
19
+ } ;
20
+ }
21
+ return obj ;
22
+ }
23
+
6
24
export default function useHandleMessageEvent ( ) {
7
25
const dispatch = useDispatch ( ) ;
8
26
9
27
const handleMessageEvent = ( data ) => {
10
28
const { source, messages } = data ;
11
29
if ( source === 'sketch' && Array . isArray ( messages ) ) {
12
- const decodedMessages = messages . map ( ( message ) => Decode ( message . log ) ) ;
30
+ const decodedMessages = messages . map ( ( message ) => {
31
+ const decoded = Decode ( message . log ) ;
32
+ if ( decoded . data ) {
33
+ decoded . data = decoded . data . map ( restoreP5Font ) ;
34
+ }
35
+ return decoded ;
36
+ } ) ;
13
37
decodedMessages . every ( ( message , index , arr ) => {
14
38
const { data : args } = message ;
15
39
let hasInfiniteLoop = false ;
Original file line number Diff line number Diff line change @@ -35,6 +35,30 @@ setInterval(() => {
35
35
}
36
36
} , LOGWAIT ) ;
37
37
38
+ // Helper function to handle p5.Font objects
39
+ function handleP5Font ( obj ) {
40
+ // Check for p5.Font instances in multiple ways
41
+ if (
42
+ ( obj &&
43
+ obj . constructor &&
44
+ ( obj . constructor . name === 'Font' ||
45
+ obj . constructor . name === 'p5.Font' ) ) ||
46
+ ( window . p5 && obj instanceof window . p5 . Font )
47
+ ) {
48
+ return {
49
+ _isP5Font : true ,
50
+ name : obj . name ,
51
+ path : obj . path ,
52
+ face : {
53
+ family : obj . face ?. family ,
54
+ style : obj . face ?. style ,
55
+ weight : obj . face ?. weight
56
+ }
57
+ } ;
58
+ }
59
+ return obj ;
60
+ }
61
+
38
62
function handleMessageEvent ( e ) {
39
63
// maybe don't need this?? idk!
40
64
if ( window . origin !== e . origin ) return ;
@@ -44,7 +68,7 @@ function handleMessageEvent(e) {
44
68
const decodedMessages = messages . map ( ( message ) => Decode ( message . log ) ) ;
45
69
decodedMessages . forEach ( ( message ) => {
46
70
const { data : args } = message ;
47
- const { result, error } = evaluateExpression ( args ) ;
71
+ const { result, error } = evaluateExpression ( args . map ( handleP5Font ) ) ;
48
72
const resultMessages = [
49
73
{ log : Encode ( { method : error ? 'error' : 'result' , data : [ result ] } ) }
50
74
] ;
You can’t perform that action at this time.
0 commit comments