File tree 3 files changed +52
-2
lines changed
3 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,13 @@ export default function useHandleMessageEvent() {
14
14
) => {
15
15
if ( typeof obj !== 'object' || obj === null ) return obj ;
16
16
17
+ if ( obj && obj . constructor && obj . constructor . name === 'p5.Font' ) {
18
+ return {
19
+ _type : 'p5.Font' ,
20
+ name : obj . name || 'Font' ,
21
+ } ;
22
+ }
23
+
17
24
if ( depth >= maxDepth ) {
18
25
if ( seen . has ( obj ) ) return '[Circular Reference]' ;
19
26
}
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ function notifyListener(message) {
28
28
}
29
29
30
30
function notifyFrames ( message ) {
31
- const rawMessage = JSON . parse ( JSON . stringify ( message ) ) ;
31
+ const rawMessage = processMessage ( message ) ;
32
32
Object . keys ( frames ) . forEach ( ( frameId ) => {
33
33
const { frame, origin } = frames [ frameId ] ;
34
34
if ( frame && frame . postMessage ) {
@@ -37,6 +37,33 @@ function notifyFrames(message) {
37
37
} ) ;
38
38
}
39
39
40
+ // Helper function to handle p5.Font objects
41
+ const handleP5Font = ( obj ) => {
42
+ if ( obj && obj . constructor && obj . constructor . name === 'p5.Font' ) {
43
+ return {
44
+ _type : 'p5.Font' ,
45
+ name : obj . name || 'Font' ,
46
+ } ;
47
+ }
48
+ return obj ;
49
+ } ;
50
+
51
+ // Message processing logic to handle nested objects and arrays
52
+ const processMessage = ( message ) => {
53
+ if ( typeof message === 'object' && message !== null ) {
54
+ if ( Array . isArray ( message ) ) {
55
+ return message . map ( processMessage ) ;
56
+ }
57
+ return Object . fromEntries (
58
+ Object . entries ( message ) . map ( ( [ key , value ] ) => [
59
+ key ,
60
+ processMessage ( handleP5Font ( value ) )
61
+ ] )
62
+ ) ;
63
+ }
64
+ return message ;
65
+ } ;
66
+
40
67
export function dispatchMessage ( message ) {
41
68
if ( ! message ) return ;
42
69
Original file line number Diff line number Diff line change @@ -17,11 +17,27 @@ window.objectPaths[blobPath] = 'index.html';
17
17
18
18
window . loopProtect = loopProtect ;
19
19
20
+ // Helper function to handle p5.Font objects
21
+ const handleP5Font = ( obj ) => {
22
+ if ( obj && obj . constructor && obj . constructor . name === 'p5.Font' ) {
23
+ return {
24
+ _type : 'p5.Font' ,
25
+ name : obj . name || 'Font'
26
+ } ;
27
+ }
28
+ return obj ;
29
+ } ;
30
+
20
31
const consoleBuffer = [ ] ;
21
32
const LOGWAIT = 500 ;
22
33
Hook ( window . console , ( log ) => {
34
+ // Process p5.Font objects in logs
35
+ const processedLog = {
36
+ ...log ,
37
+ data : log . data ? log . data . map ( handleP5Font ) : log . data
38
+ } ;
23
39
consoleBuffer . push ( {
24
- log
40
+ log : processedLog
25
41
} ) ;
26
42
} ) ;
27
43
setInterval ( ( ) => {
You can’t perform that action at this time.
0 commit comments