()
| 98 | } |
| 99 | |
| 100 | constructor() { |
| 101 | const encodingsModule = { |
| 102 | get encodings() { |
| 103 | return encodings; |
| 104 | }, |
| 105 | encode, |
| 106 | decode, |
| 107 | }; |
| 108 | |
| 109 | const themesModule = { |
| 110 | add: themes.add, |
| 111 | get: themes.get, |
| 112 | list: themes.list, |
| 113 | update: themes.update, |
| 114 | // Deprecated, not supported anymore |
| 115 | apply: () => {}, |
| 116 | }; |
| 117 | |
| 118 | // CodeMirror editor theme API for plugins |
| 119 | const normalizeThemeSpec = (spec) => { |
| 120 | if (!spec || typeof spec !== "object" || Array.isArray(spec)) { |
| 121 | console.warn( |
| 122 | "[editorThemes] register(spec) expects an object: { id, caption?, dark?, getExtension|extensions|extension|theme, config? }", |
| 123 | ); |
| 124 | return null; |
| 125 | } |
| 126 | |
| 127 | const id = spec.id || spec.name; |
| 128 | if (!id) { |
| 129 | console.warn("[editorThemes] register(spec) requires a valid `id`."); |
| 130 | return null; |
| 131 | } |
| 132 | |
| 133 | const extensionSource = |
| 134 | spec.getExtension || spec.extensions || spec.extension || spec.theme; |
| 135 | if (extensionSource === undefined || extensionSource === null) { |
| 136 | console.warn( |
| 137 | `[editorThemes] register('${id}') requires extensions via getExtension/extensions/extension/theme.`, |
| 138 | ); |
| 139 | return null; |
| 140 | } |
| 141 | |
| 142 | return { |
| 143 | id, |
| 144 | caption: spec.caption || spec.label || id, |
| 145 | isDark: spec.isDark ?? spec.dark ?? false, |
| 146 | getExtension: |
| 147 | typeof extensionSource === "function" |
| 148 | ? extensionSource |
| 149 | : () => extensionSource, |
| 150 | config: spec.config ?? null, |
| 151 | }; |
| 152 | }; |
| 153 | |
| 154 | const createHighlightStyle = (spec) => { |
| 155 | if (!spec) return null; |
| 156 | if (Array.isArray(spec)) return cmLanguage.HighlightStyle.define(spec); |
| 157 | return spec; |
nothing calls this directly
no test coverage detected