| 137 | */ |
| 138 | @nodeName('CodeBlock') |
| 139 | export class Code extends Shape { |
| 140 | /** |
| 141 | * Create a standalone code signal. |
| 142 | * |
| 143 | * @param initial - The initial code. |
| 144 | * @param highlighter - Custom highlighter to use. |
| 145 | */ |
| 146 | public static createSignal( |
| 147 | initial: PossibleCodeScope, |
| 148 | highlighter?: SignalValue<CodeHighlighter>, |
| 149 | ): CodeSignal<void> { |
| 150 | return new CodeSignalContext<void>( |
| 151 | initial, |
| 152 | undefined, |
| 153 | highlighter, |
| 154 | ).toSignal(); |
| 155 | } |
| 156 | |
| 157 | public static defaultHighlighter: CodeHighlighter | null = null; |
| 158 | /** |
| 159 | * The code highlighter to use for this code node. |
| 160 | * |
| 161 | * @remarks |
| 162 | * Defaults to a shared {@link code.LezerHighlighter}. |
| 163 | */ |
| 164 | @initial(() => Code.defaultHighlighter) |
| 165 | @signal() |
| 166 | public declare readonly highlighter: SimpleSignal< |
| 167 | CodeHighlighter | null, |
| 168 | this |
| 169 | >; |
| 170 | |
| 171 | /** |
| 172 | * The code to display. |
| 173 | */ |
| 174 | @codeSignal() |
| 175 | public declare readonly code: CodeSignal<this>; |
| 176 | |
| 177 | /** |
| 178 | * Custom drawing logic for the code. |
| 179 | * |
| 180 | * @remarks |
| 181 | * Check out {@link DrawHooks} for available render hooks. |
| 182 | * |
| 183 | * @example |
| 184 | * Make the unselected code blurry and transparent: |
| 185 | * ```tsx |
| 186 | * <Code |
| 187 | * drawHooks={{ |
| 188 | * token(ctx, text, position, color, selection) { |
| 189 | * const blur = map(3, 0, selection); |
| 190 | * const alpha = map(0.5, 1, selection); |
| 191 | * ctx.globalAlpha *= alpha; |
| 192 | * ctx.filter = `blur(${blur}px)`; |
| 193 | * ctx.fillStyle = color; |
| 194 | * ctx.fillText(text, position.x, position.y); |
| 195 | * }, |
| 196 | * }} |
nothing calls this directly
no test coverage detected