@@ -224,27 +224,23 @@ function injectLocalFiles(files, htmlFile, options) {
224
224
resolveScripts ( sketchDoc , resolvedFiles ) ;
225
225
resolveStyles ( sketchDoc , resolvedFiles ) ;
226
226
227
- const accessiblelib = sketchDoc . createElement ( 'script' ) ;
228
- accessiblelib . setAttribute (
229
- 'src' ,
230
- 'https://cdn.jsdelivr.net/gh/processing/[email protected] /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
227
if ( textOutput || gridOutput ) {
236
- sketchDoc . body . appendChild ( accessibleOutputs ) ;
237
- sketchDoc . body . appendChild ( accessiblelib ) ;
228
+ const scriptElement = sketchDoc . createElement ( 'script' ) ;
229
+ let textCode = '' ;
238
230
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();' ;
242
232
}
233
+ let gridCode = '' ;
243
234
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();' ;
247
236
}
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 ) ;
248
244
}
249
245
250
246
const previewScripts = sketchDoc . createElement ( 'script' ) ;
0 commit comments