MCPcopy Index your code
hub / github.com/midrender/revideo / parseCodeFragment

Function parseCodeFragment

packages/2d/src/lib/code/CodeFragment.ts:26–50  ·  view source on GitHub ↗
(
  value: PossibleCodeFragment,
  context: CanvasRenderingContext2D,
  monoWidth: number,
)

Source from the content-addressed store, hash-verified

24}
25
26export function parseCodeFragment(
27 value: PossibleCodeFragment,
28 context: CanvasRenderingContext2D,
29 monoWidth: number,
30): CodeFragment {
31 let fragment: CodeFragment;
32 if (typeof value === 'string') {
33 fragment = metricsToFragment(measureString(context, monoWidth, value));
34 } else if (isCodeMetrics(value)) {
35 fragment = metricsToFragment(value);
36 } else {
37 fragment = {
38 before:
39 typeof value.before === 'string'
40 ? measureString(context, monoWidth, value.before)
41 : value.before,
42 after:
43 typeof value.after === 'string'
44 ? measureString(context, monoWidth, value.after)
45 : value.after,
46 };
47 }
48
49 return fragment;
50}
51
52/**
53 * Create a code fragment that represents an insertion of code.

Callers 2

measureSizeMethod · 0.90
drawScopeMethod · 0.90

Calls 3

measureStringFunction · 0.90
isCodeMetricsFunction · 0.90
metricsToFragmentFunction · 0.85

Tested by

no test coverage detected