code
import
{
...
}
from
"@motion-canvas/2d/lib/code"
;
Classes
-
CodeSignalContext -
LezerHighlighter
Interfaces
-
CodeFragment -
CodeFragmentDrawingInfo -
CodeHighlighter -
CodeScope -
CodeSignalHelpers -
HighlightResult -
RawCodeFragment
Type Aliases
CodeDiffer
type
CodeDiffer
=
from
:
CodeScope
to
:
CodeScope
tokenize
:
CodeTokenizer
=>
CodeTag
[]
CodePoint
type
CodePoint
=
number
number
CodeRange
CodeSelection
type
CodeSelection
=
CodeRange
[]
CodeSignal
type
CodeSignal
TOwner
=
Signal
PossibleCodeScope
CodeScope
TOwner
CodeSignalContext
TOwner
CodeSignalHelpers
TOwner
Type Parameters
CodeTag
type
CodeTag
=
SignalValue
PossibleCodeFragment
CodeScope
CodeTag
[]
CodeTokenizer
type
CodeTokenizer
=
input
:
string
=>
string
[]
PossibleCodeFragment
type
PossibleCodeFragment
=
CodeFragment
CodeMetrics
RawCodeFragment
string
PossibleCodeScope
type
PossibleCodeScope
=
CodeScope
CodeTag
[]
string
PossibleCodeSelection
Variables
DefaultHighlightStyle
const
DefaultHighlightStyle
:
HighlightStyle
=
...
Functions
CODE
Parameters
codeSignal
public
codeSignal
():
PropertyDecorator
consolidateCodeRanges
Parameters
defaultDiffer
public
defaultDiffer
from
:
CodeScope
to
:
CodeScope
tokenize
:
CodeTokenizer
:
CodeTag
[]
Default diffing function utilizing
patienceDiff
.
Parameters
-
from : CodeScopeThe original code scope.
-
to : CodeScopeThe new code scope.
-
tokenize : CodeTokenizerThe inherited tokenizer to use.
defaultTokenize
public
defaultTokenize
input
:
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 themonly 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 : string RegExpEither a string or a regular expression to search for.
-
limit : number = InfinityAn optional limit on the number of ranges to find.
insert
public
insert
code
:
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
public
isCodeScope
value
:
any
:
value
is
CodeScope
Parameters
-
value : any
isPointInCodeRange
Parameters
isPointInCodeSelection
public
isPointInCodeSelection
point
:
CodePoint
selection
:
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 willcover only one line.
metricsToFragment
public
metricsToFragment
value
:
CodeMetrics
:
CodeFragment
Parameters
-
value : CodeMetrics
parseCodeFragment
public
parseCodeFragment
value
:
PossibleCodeFragment
context
:
CanvasRenderingContext2D
monoWidth
:
number
:
CodeFragment
Parameters
-
value : PossibleCodeFragment -
context : CanvasRenderingContext2D -
monoWidth : number
parseCodeScope
public
parseCodeScope
value
:
PossibleCodeScope
:
CodeScope
Parameters
parseCodeSelection
public
parseCodeSelection
value
:
PossibleCodeSelection
:
CodeSelection
Parameters
patienceDiff
public
patienceDiff
aLines
:
string
[]
bLines
:
string
[]
:
lineCountDeleted
:
number
lineCountInserted
:
number
lines
:
aIndex
:
number
bIndex
:
number
line
:
string
[]
Performs a patience diff on two arrays of strings, returning an objectcontaining the lines that were deleted, inserted, and potentially movedlines. The plus parameter can result in a significant performance hit dueto additional Longest Common Substring searches.
Parameters
pointToPoint
public
pointToPoint
startLine
:
number
startColumn
:
number
endLine
:
number
endColumn
:
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
remove
code
:
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
Create a code fragment that represents a change from one piece of code toanother.
Can be used in conjunction with
edit
.
Parameters
resolveCodeTag
Parameters
resolveScope
Parameters
word
Create a code range that highlights the given word.