code
import {...} from "@motion-canvas/2d/lib/code";
Classes​
Interfaces​
CodeFragmentCodeFragmentDrawingInfoCodeHighlighterCodeScopeCodeSignalHelpersHighlightResultRawCodeFragment
Type Aliases​
CodeDiffer​
CodePoint​
type CodePoint = numbernumber
CodeRange​
CodeSelection​
type CodeSelection = CodeRange[]
CodeSignal​
Type Parameters
CodeTag​
type CodeTag = SignalValuePossibleCodeFragmentCodeScopeCodeTag[]
CodeTokenizer​
type CodeTokenizer = input: string => string[]
PossibleCodeFragment​
type PossibleCodeFragment = CodeFragmentCodeMetricsRawCodeFragmentstring
PossibleCodeScope​
PossibleCodeSelection​
Variables​
DefaultHighlightStyle​
const DefaultHighlightStyle: HighlightStyle = ...
Functions​
CODE​
Parameters
codeSignal​
public codeSignal(): PropertyDecorator
consolidateCodeRanges​
Parameters
defaultDiffer​
Default diffing function utilizing patienceDiff.
Parameters
from: CodeScopeThe original code scope.
to: CodeScopeThe new code scope.
tokenize: CodeTokenizerThe inherited tokenizer to use.
defaultTokenize​
public defaultTokenizeinput: string: string[]
Default tokenizer function used by ownerless code signals.
Parameters
input: stringThe code to tokenize.
extractRange​
Transform the fragments to isolate the given range into its own fragment.
This function will try to preserve the original fragments, resolving them only if they overlap with the range.
Parameters
findAllCodeRanges​
Find all code ranges that match the given pattern.
Parameters
code: stringThe code to search in.
pattern: stringRegExpEither a string or a regular expression to search for. When a string is passed, it looks for exact matches. When a RegExp object is passed, it will match against it.
limit: number = InfinityAn optional limit on the number of ranges to find.
insert​
public insertcode: string: RawCodeFragment
Create a code fragment that represents an insertion of code.
Can be used in conjunction with edit.
Parameters
code: stringThe code to insert.
inverseCodeRange​
Parameters
isCodeRange​
Parameters
value: unknown
isCodeScope​
Parameters
value: any
isPointInCodeRange​
Parameters
isPointInCodeSelection​
public isPointInCodeSelectionpoint: CodePointselection: CodeSelection: boolean
Parameters
lines​
Create a code range that spans the given lines.
Parameters
from: numberThe line from which the range starts.
to?: numberThe line at which the range ends. If omitted, the range will cover only one line.
metricsToFragment​
public metricsToFragmentvalue: CodeMetrics: CodeFragment
Parameters
value: CodeMetrics
parseCodeFragment​
public parseCodeFragmentvalue: PossibleCodeFragmentcontext: CanvasRenderingContext2DmonoWidth: number: CodeFragment
Parameters
parseCodeScope​
public parseCodeScopevalue: PossibleCodeScope: CodeScope
Parameters
parseCodeSelection​
public parseCodeSelectionvalue: PossibleCodeSelection: CodeSelection
Parameters
patienceDiff​
public patienceDiffaLines: string[]bLines: string[]: lineCountDeleted: numberlineCountInserted: numberlines: aIndex: numberbIndex: numberline: string[]
Performs a patience diff on two arrays of strings, returning an object containing the lines that were deleted, inserted, and potentially moved lines. The plus parameter can result in a significant performance hit due to additional Longest Common Substring searches.
Parameters
pointToPoint​
public pointToPointstartLine: numberstartColumn: numberendLine: numberendColumn: number: CodeRange
Create a custom selection range.
Parameters
startLine: numberThe line at which the selection starts.
startColumn: numberThe column at which the selection starts.
endLine: numberThe line at which the selection ends.
endColumn: numberThe column at which the selection ends.
remove​
public removecode: string: RawCodeFragment
Create a code fragment that represents a removal of code.
Can be used in conjunction with edit.
Parameters
code: stringThe code to remove.
replace​
public replacebefore: stringafter: string: RawCodeFragment
Create a code fragment that represents a change from one piece of code to another.
Can be used in conjunction with edit.
Parameters
resolveCodeTag​
Parameters
resolveScope​
Parameters
word​
Create a code range that highlights the given word.