@@ -224,27 +224,23 @@ function injectLocalFiles(files, htmlFile, options) {
224224 resolveScripts ( sketchDoc , resolvedFiles ) ;
225225 resolveStyles ( sketchDoc , resolvedFiles ) ;
226226
227- const accessiblelib = sketchDoc . createElement ( 'script' ) ;
228- accessiblelib . setAttribute (
229- 'src' ,
230- 'https://cdn.jsdelivr.net/gh/processing/p5.accessibility@0.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' ) ;
235227 if ( textOutput || gridOutput ) {
236- sketchDoc . body . appendChild ( accessibleOutputs ) ;
237- sketchDoc . body . appendChild ( accessiblelib ) ;
228+ const scriptElement = sketchDoc . createElement ( 'script' ) ;
229+ let textCode = '' ;
238230 if ( textOutput ) {
239- const textSection = sketchDoc . createElement ( 'section' ) ;
240- textSection . setAttribute ( 'id' , 'textOutput-content' ) ;
241- sketchDoc . getElementById ( 'accessible-outputs' ) . appendChild ( textSection ) ;
231+ textCode = 'if (!this._accessibleOutputs.text) this.textOutput();' ;
242232 }
233+ let gridCode = '' ;
243234 if ( gridOutput ) {
244- const gridSection = sketchDoc . createElement ( 'section' ) ;
245- gridSection . setAttribute ( 'id' , 'tableOutput-content' ) ;
246- sketchDoc . getElementById ( 'accessible-outputs' ) . appendChild ( gridSection ) ;
235+ gridCode = 'if (!this._accessibleOutputs.grid) this.gridOutput();' ;
247236 }
237+ const fxn = `p5.prototype.ensureAccessibleCanvas = function _ensureAccessibleCanvas() {
238+ ${ textCode }
239+ ${ gridCode }
240+ };
241+ p5.prototype.registerMethod('afterSetup', p5.prototype.ensureAccessibleCanvas);` ;
242+ scriptElement . innerHTML = fxn ;
243+ sketchDoc . head . appendChild ( scriptElement ) ;
248244 }
249245
250246 const previewScripts = sketchDoc . createElement ( 'script' ) ;
0 commit comments