@@ -204,7 +204,8 @@ function addLoopProtect(sketchDoc) {
204204 } ) ;
205205}
206206
207- function injectLocalFiles ( files , htmlFile , basePath ) {
207+ function injectLocalFiles ( files , htmlFile , options ) {
208+ const { basePath, gridOutput, textOutput } = options ;
208209 let scriptOffs = [ ] ;
209210 objectUrls = { } ;
210211 objectPaths = { } ;
@@ -223,6 +224,29 @@ function injectLocalFiles(files, htmlFile, basePath) {
223224 resolveScripts ( sketchDoc , resolvedFiles ) ;
224225 resolveStyles ( sketchDoc , resolvedFiles ) ;
225226
227+ const accessiblelib = sketchDoc . createElement ( 'script' ) ;
228+ accessiblelib . setAttribute (
229+ 'src' ,
230+ 'https://cdn.jsdelivr.net/gh/processing/p5.accessibility@v0.1.1/dist/p5.accessibility.js'
231+ ) ;
232+ const accessibleOutputs = sketchDoc . createElement ( 'section' ) ;
233+ accessibleOutputs . setAttribute ( 'id' , 'accessible-outputs' ) ;
234+ accessibleOutputs . setAttribute ( 'aria-label' , 'accessible-output' ) ;
235+ if ( textOutput || gridOutput ) {
236+ sketchDoc . body . appendChild ( accessibleOutputs ) ;
237+ sketchDoc . body . appendChild ( accessiblelib ) ;
238+ if ( textOutput ) {
239+ const textSection = sketchDoc . createElement ( 'section' ) ;
240+ textSection . setAttribute ( 'id' , 'textOutput-content' ) ;
241+ sketchDoc . getElementById ( 'accessible-outputs' ) . appendChild ( textSection ) ;
242+ }
243+ if ( gridOutput ) {
244+ const gridSection = sketchDoc . createElement ( 'section' ) ;
245+ gridSection . setAttribute ( 'id' , 'tableOutput-content' ) ;
246+ sketchDoc . getElementById ( 'accessible-outputs' ) . appendChild ( gridSection ) ;
247+ }
248+ }
249+
226250 const previewScripts = sketchDoc . createElement ( 'script' ) ;
227251 previewScripts . src = `${ window . location . origin } ${ getConfig (
228252 'PREVIEW_SCRIPTS_URL'
@@ -249,7 +273,7 @@ function getHtmlFile(files) {
249273 return files . filter ( ( file ) => file . name . match ( / .* \. h t m l $ / i) ) [ 0 ] ;
250274}
251275
252- function EmbedFrame ( { files, isPlaying, basePath } ) {
276+ function EmbedFrame ( { files, isPlaying, basePath, gridOutput , textOutput } ) {
253277 const iframe = useRef ( ) ;
254278 const htmlFile = useMemo ( ( ) => getHtmlFile ( files ) , [ files ] ) ;
255279
@@ -266,23 +290,22 @@ function EmbedFrame({ files, isPlaying, basePath }) {
266290 function renderSketch ( ) {
267291 const doc = iframe . current ;
268292 if ( isPlaying ) {
269- const htmlDoc = injectLocalFiles ( files , htmlFile , basePath ) ;
293+ const htmlDoc = injectLocalFiles ( files , htmlFile , {
294+ basePath,
295+ gridOutput,
296+ textOutput
297+ } ) ;
270298 const generatedHtmlFile = {
271299 name : 'index.html' ,
272300 content : htmlDoc
273301 } ;
274302 const htmlUrl = createBlobUrl ( generatedHtmlFile ) ;
303+ // BRO FOR SOME REASON YOU HAVE TO DO THIS TO GET IT TO WORK ON SAFARI
275304 setTimeout ( ( ) => {
276305 doc . src = htmlUrl ;
277306 } , 0 ) ;
278- // BRO FOR SOME REASON YOU HAVE TO DO THIS TO GET IT TO WORK ON SAFARI
279- // setTimeout(() => {
280- // srcDoc.set(doc, htmlDoc);
281- // }, 0);
282307 } else {
283308 doc . src = '' ;
284- // doc.srcdoc = '';
285- // srcDoc.set(doc, ' ');
286309 }
287310 }
288311
@@ -306,7 +329,9 @@ EmbedFrame.propTypes = {
306329 } )
307330 ) . isRequired ,
308331 isPlaying : PropTypes . bool . isRequired ,
309- basePath : PropTypes . string . isRequired
332+ basePath : PropTypes . string . isRequired ,
333+ gridOutput : PropTypes . bool . isRequired ,
334+ textOutput : PropTypes . bool . isRequired
310335} ;
311336
312337export default EmbedFrame ;
0 commit comments