MCPcopy
hub / github.com/midrender/revideo / Code

Class Code

packages/2d/src/lib/components/Code.ts:139–526  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137 */
138@nodeName('CodeBlock')
139export 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 * }}

Callers

nothing calls this directly

Calls 7

initialFunction · 0.90
signalFunction · 0.90
codeSignalFunction · 0.90
linesFunction · 0.90
parserFunction · 0.90
createSignalFunction · 0.90
computedFunction · 0.90

Tested by

no test coverage detected