1export function editorBackendFor({2 search = globalThis.location?.search ?? '',3 coarsePointer = globalThis.matchMedia?.('(pointer: coarse)').matches ?? false,4} = {}) {5 const requested = new URLSearchParams(search).get('editor')6 if (requested === 'textarea' || requested === 'monaco') return requested7 return coarsePointer ? 'textarea' : 'monaco'8}910export async function createSourceEditor(options) {11 const preferredBackend = editorBackendFor()12 try {13 return await createBackend(preferredBackend, options)14 } catch (error) {15 if (preferredBackend === 'textarea') throw error16 console.warn('Monaco Editor is unavailable; using the basic text editor.', error)17 return createBackend('textarea', options)18 }19}2021async function createBackend(backend, options) {22 const module = backend === 'textarea'23 ? await import('./editors/textarea-editor.js')24 : await import('./editors/monaco-editor.js')25 const editor = await module.createEditor(options)26 options.element.dataset.editorBackend = backend27 return editor28}