@motionscript/code 0.1.0-alpha.3 → 0.1.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +48 -0
  4. package/README.md +176 -108
  5. package/dist/browser/THIRD_PARTY_LICENSES.txt +431 -0
  6. package/dist/browser/index.js +10 -6
  7. package/dist/browser/index.js.map +3 -3
  8. package/dist/browser/manifest.json +84 -2
  9. package/dist/code-range.d.ts +6 -0
  10. package/dist/code-range.d.ts.map +1 -1
  11. package/dist/code-range.js +8 -0
  12. package/dist/code-range.js.map +1 -1
  13. package/dist/diff.d.ts +14 -0
  14. package/dist/diff.d.ts.map +1 -1
  15. package/dist/diff.js +134 -2
  16. package/dist/diff.js.map +1 -1
  17. package/dist/engine.d.ts +2 -2
  18. package/dist/engine.d.ts.map +1 -1
  19. package/dist/engine.js +1 -1
  20. package/dist/engine.js.map +1 -1
  21. package/dist/highlight.d.ts +10 -2
  22. package/dist/highlight.d.ts.map +1 -1
  23. package/dist/highlight.js +40 -6
  24. package/dist/highlight.js.map +1 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/layout.js.map +1 -1
  27. package/dist/node.d.ts +187 -301
  28. package/dist/node.d.ts.map +1 -1
  29. package/dist/node.js +633 -754
  30. package/dist/node.js.map +1 -1
  31. package/dist/nodes.d.ts +6 -9
  32. package/dist/nodes.d.ts.map +1 -1
  33. package/dist/nodes.js +7 -9
  34. package/dist/nodes.js.map +1 -1
  35. package/dist/render.d.ts +9 -2
  36. package/dist/render.d.ts.map +1 -1
  37. package/dist/render.js +59 -0
  38. package/dist/render.js.map +1 -1
  39. package/dist/style.d.ts +3 -3
  40. package/dist/style.d.ts.map +1 -1
  41. package/dist/style.js +10 -6
  42. package/dist/style.js.map +1 -1
  43. package/dist/tokens.d.ts.map +1 -1
  44. package/dist/tokens.js +5 -1
  45. package/dist/tokens.js.map +1 -1
  46. package/dist/transitions.d.ts +19 -1
  47. package/dist/transitions.d.ts.map +1 -1
  48. package/dist/transitions.js.map +1 -1
  49. package/package.json +7 -5
  50. package/registry.json +6 -6
  51. package/src/code-range.ts +165 -156
  52. package/src/diff.ts +351 -216
  53. package/src/engine.ts +21 -21
  54. package/src/highlight.ts +340 -291
  55. package/src/index.ts +3 -3
  56. package/src/layout.ts +157 -157
  57. package/src/node.ts +854 -904
  58. package/src/nodes.ts +16 -18
  59. package/src/render.ts +315 -247
  60. package/src/style.ts +255 -251
  61. package/src/tokens.ts +79 -75
  62. package/src/transitions.ts +204 -184
package/dist/node.d.ts CHANGED
@@ -1,37 +1,9 @@
1
- import { RenderContext2D, RenderPass2D, Clip, EasingFunction, NodeConfig, Size2D, SizeConstraints, Node2D, Node2DProps, MeasureContext2D, InsetsResolved, InsetsProps, type AssetScope, type Command, type CommandArgs, type Node, type TweenStepper, type Vector2 } from "@motionscript/sdk";
2
- import { CodeRange, type CodeDiffStrategy, type CodePhaseStrategy, CodeTheme } from "./engine.js";
1
+ import { type NodeOf, type NormalizedColor, type Color as _Color, type Node2D as _Node2D, type Node2DProps as _Node2DProps } from "@motionscript/sdk";
2
+ import { type CodeDiffStrategy, type CodePhaseStrategy, type CodeRange, type CodeTheme, type DimTransition, type IdLine, type RowBand, type RowsTransition, type StructuralTransition } from "./engine.js";
3
3
  /**
4
- * A listing and nothing else — no paint slots, and no box behind the tokens.
5
- *
6
- * It did carry a `fill`/`overlay`/`stroke`/`shadow` set and the corner radius
7
- * that shaped them, so a block could draw its own panel. That was one node doing
8
- * two jobs, and the second one is a `Rect`'s: a listing set on a card is a `Code`
9
- * inside a hugging `Rect`, which tracks the block's size for the same reason
10
- * every other hugging container tracks its child's. What is left here is the
11
- * listing — its source, how it is coloured, the face it is set in, and the space
12
- * it keeps around itself.
13
- */
14
- export interface CodeProps extends Node2DProps {
15
- code: string;
16
- language: string;
17
- fontSize: number;
18
- fontFamily: string;
19
- /** A built-in/registered theme name (e.g. `'github-dark'`), or a {@link CodeHighlightStyle} object. */
20
- theme: CodeTheme;
21
- lineHeight: number;
22
- letterSpacing: number;
23
- showLineNumbers: boolean;
24
- lineNumberGap: number;
25
- padding: InsetsProps;
26
- }
27
- /**
28
- * Construction-time-only options: pluggable engine behavior, set once when
29
- * the node is created. Deliberately *not* part of {@link CodeProps} — every
30
- * `@property` field accepts either a value or a zero-arg reactive binding
31
- * (`value | (() => value)`, see `PropInputs`), and the node's own reactive
32
- * write path (`_writeProp`) treats any function value as the latter. A
33
- * strategy *is* a function, so it can't be told apart from a binding that
34
- * computes one — it has to stay outside the reactive prop system entirely.
4
+ * Which token became which across an edit, and when each part of it happens.
5
+ * Arguments of {@link defineCode}: a strategy is a function, which a prop would
6
+ * take for a binding, so it is part of the component's definition instead.
35
7
  */
36
8
  export interface CodeStrategies {
37
9
  /** Decides which token became which across an edit. Defaults to `defaultCodeDiff`. */
@@ -39,275 +11,189 @@ export interface CodeStrategies {
39
11
  /** Decides when (in normalized transition time) each part of an edit happens. Defaults to `defaultCodePhases`. */
40
12
  phaseStrategy?: CodePhaseStrategy;
41
13
  }
42
- export declare class Code extends Node2D<CodeProps> {
43
- readonly code: string;
14
+ /** `code` part-way through a `to({ code })`: the source it leaves, the one it lands on, and how far along it is, eased. */
15
+ export interface CodeBlend {
16
+ readonly from: string;
17
+ readonly to: string;
18
+ readonly t: number;
19
+ }
20
+ /** What `code` holds: a source, or a {@link CodeBlend} while a `to({ code })` runs. */
21
+ export type CodeSource = string | CodeBlend;
22
+ /** A range argument: one range, several, or a chain that went through JSON as `{ list }`. */
23
+ export type CodeTarget = CodeRange | Iterable<CodeRange> | {
24
+ readonly list: CodeRange[];
25
+ };
26
+ /** What a structure was tokenized with: the grammar, the theme and whether the grammar had landed. */
27
+ export interface CodeTokenBasis {
44
28
  readonly language: string;
45
- readonly fontFamily: string;
46
29
  readonly theme: CodeTheme;
47
- readonly fontSize: number;
48
- readonly lineHeight: number;
49
- readonly letterSpacing: number;
50
- readonly showLineNumbers: boolean;
51
- readonly lineNumberGap: number;
52
- readonly padding: InsetsResolved;
53
- /** The settled structure. During an edit, the structure the edit lands on. */
54
- private tokenLines;
55
- private tokenized;
56
- /** The source `tokenLines` spells, so a frame compares it with `code` without joining every token. */
57
- private _linesSource;
58
- private transitions;
59
- private advanceCache;
60
- private structureVersion;
61
- private layoutCacheKey;
62
- private layoutCache;
63
- private highlightDimOpacity;
64
- private highlightedIds;
65
- /**
66
- * Which token became which across an edit, and when each part of that
67
- * edit happens. Construction-time-only (see {@link CodeStrategies}) —
68
- * resolved once here rather than left as `?? defaultX` at every call site.
69
- */
70
- private readonly diffStrategy;
71
- private readonly phaseStrategy;
72
- constructor(props: NodeConfig<Code, CodeProps> & CodeStrategies);
73
- set(props: {
74
- [K in keyof CodeProps]?: CodeProps[K] | (() => CodeProps[K]);
75
- }): void;
76
- private tokenize;
77
- /**
78
- * Swap in a new settled structure, invalidating the layout cache.
79
- *
80
- * The one place `tokenLines` is written, because the cache key is a version
81
- * counter rather than a hash of the content — a write that skipped the bump
82
- * would keep serving the previous frame's geometry for the new listing.
83
- */
84
- private setLines;
85
- /**
86
- * The monospaced face this block measures and draws with, and the syntax
87
- * grammar it tokenizes with.
88
- *
89
- * Both belong to *layout*: token x positions are measured against the face,
90
- * and how many tokens there are depends on the grammar. Declared here, the
91
- * grammar goes on the timeline as an ordinary asset: `AssetManager.loadAt`
92
- * waits for it before the frame is laid out, so the first measurement is the
93
- * right one. Nothing is freed on eviction — parsers are cheap to keep
94
- * resident. The loader touches no node: `renderContent` re-tokenizes once
95
- * the grammar is there.
96
- */
97
- declareAssets(assets: AssetScope): void;
98
- private metrics;
99
- /** The structural edit currently in flight, if any. */
100
- private activeEdit;
101
- private settledLayout;
102
- /**
103
- * The one or two layouts this frame is drawn from.
104
- *
105
- * A settled frame has one. A frame inside an edit has two — where every
106
- * token was, and where it is going — and the frame is a point between them.
107
- * That is the whole reason an insert no longer piles its glyphs at the left
108
- * margin: a token's destination is *computed*, not approximated by collapsing
109
- * the advance of everything around it.
110
- *
111
- * Both endpoints are fixed for the edit's duration, so they are built once
112
- * and cached on the transition rather than rebuilt per frame.
113
- */
114
- private frameLayout;
115
- measure(constraints: SizeConstraints, scope: MeasureContext2D): Partial<Size2D>;
116
- protected renderContent(ctx: RenderPass2D): void;
117
- protected renderSelf(ctx: RenderContext2D): void;
118
- /** A listing holds a listing — `append`/`insert`/`erase` are how it grows. */
119
- protected acceptsChild(_child: Node): boolean;
120
- /**
121
- * The node's laid-out rect as a clip outline, so `clip` and any backdrop
122
- * effect are confined to the block rather than to nothing — a listing set on
123
- * a card is exactly where a backdrop blur is asked for.
124
- */
125
- protected clipSelf(): Clip;
126
- /**
127
- * A listing is grabbed by its **text**, line by ragged line, rather than by
128
- * the rectangle the lines were laid out in.
129
- *
130
- * The default narrows a node's grab region to the outline it declares, and
131
- * this node's outline is a box it no longer paints anything into. Code is
132
- * mostly whitespace: a ten-line snippet with one long line is a rectangle
133
- * that is largely empty, and in an editor every one of those empty pixels
134
- * swallows a click meant for whatever sits behind or beneath it. Short of the
135
- * text itself there is nothing there to have clicked.
136
- *
137
- * So the region is the union of the lines' own extents — each a line-height
138
- * slot as wide as that line's ink — plus the gutter where line numbers are
139
- * showing, since those are drawn glyphs too.
140
- *
141
- * Answered from the **cached** layout, which is what the last frame drew
142
- * from, because a hit test arrives with no measurement scope and text cannot
143
- * be measured without one. Where there is no usable cache — before the first
144
- * frame, or mid-edit, when the geometry is an interpolation of two structures
145
- * held on the transition — the box is the honest answer rather than a
146
- * silhouette measured against stale metrics.
147
- */
148
- protected hitTestSelf(local: Vector2, tolerance: number): boolean;
149
- /**
150
- * The layout a hit test may be answered from: the settled cache, and only
151
- * while it still matches the node's current metrics.
152
- *
153
- * The key is the one {@link settledLayout} writes minus its scope-dependent
154
- * half — every input to it (`metricsSignature`, the advance cache's own
155
- * signature) is readable without a measurer, which is precisely what makes
156
- * the check possible here.
157
- */
158
- private hitLayout;
159
- /**
160
- * Append `code` to the end of the listing.
161
- *
162
- * Stated as *what the source becomes*; {@link editTo} works out the rest —
163
- * which is why appending a line that closes a block re-highlights the lines
164
- * above it, instead of colouring the new text as its own program.
165
- */
166
- append(args: CommandArgs<{
167
- code: string;
168
- }> & {
169
- duration: number;
170
- }): Command<Record<string, never>>;
171
- /** Insert `code` above the listing. */
172
- prepend(args: CommandArgs<{
173
- code: string;
174
- }> & {
175
- duration: number;
176
- }): Command<Record<string, never>>;
177
- /**
178
- * Insert `code` at the given (line, col). Both are 1-indexed; col is the
179
- * column BEFORE which the new content is inserted (col=1 means start of
180
- * line). If `code` contains newlines, new lines are created in the middle
181
- * of the existing line.
182
- */
183
- insert(args: CommandArgs<{
184
- position: [number, number];
185
- code: string;
186
- }> & {
187
- duration: number;
188
- }): Command<Record<string, never>>;
189
- /**
190
- * Erase the code in `codeRange`.
191
- *
192
- * Named `erase` rather than `remove` because a `Code` is also a node, and
193
- * `Node.remove(child)` takes a child out of the tree. Two methods spelled
194
- * the same on one object, doing entirely different things, is worse than one
195
- * of them having a slightly less obvious name.
196
- *
197
- * A range that covers whole lines takes their line breaks with it, so the
198
- * rows below close up; a range inside a line takes only the characters, and
199
- * the rest of the line reflows around the hole.
200
- */
201
- erase(args: CommandArgs<{
202
- target: CodeRange;
203
- }> & {
204
- duration: number;
205
- }): Command<Record<string, never>>;
206
- /** Replace the code in `codeRange` with `replacement`. */
207
- replace(args: CommandArgs<{
208
- target: CodeRange;
209
- replacement: string;
210
- }> & {
211
- duration: number;
212
- }): Command<Record<string, never>>;
213
- /**
214
- * Highlight a range of code — or several at once (e.g.
215
- * `CodeRanges.lines(2).word(5, 1, 3)`) — highlighted as one set: tokens
216
- * within any of the ranges stay at opacity 1, tokens outside dim to
217
- * `dim`. Persistent — call resetHighlight() to undo, or call highlight()
218
- * again with a different range to cross-fade.
219
- */
220
- highlight(args: CommandArgs<{
221
- target: CodeRange | Iterable<CodeRange>;
222
- dim?: number;
223
- }> & {
224
- duration: number;
225
- }): Command<Record<string, never>>;
226
- /**
227
- * Fade all dimmed tokens back to opacity 1 and clear the persistent
228
- * highlight state.
229
- */
230
- resetHighlight(args: CommandArgs<Record<string, never>> & {
231
- duration: number;
232
- }): Command<Record<string, never>>;
233
- /**
234
- * Animate the listing to a new source.
235
- *
236
- * The engine behind every editing command, and behind `to({ code })`. Every
237
- * edit is expressed as the source it produces, tokenized, and then *diffed*
238
- * against what is on screen — so a token that survived the edit keeps its
239
- * identity and simply travels to its new column, and only what genuinely
240
- * changed is faded.
241
- *
242
- * The result runs in three phases (see `phaseStrategy`): what is leaving
243
- * fades out, what stays reflows, and only then does what is new arrive.
244
- * Playing them together is what made a replacement read as a cross-dissolve
245
- * of two unrelated listings rather than as an edit being made.
246
- */
247
- private editTo;
248
- /**
249
- * Put a dim transition on the stack, drive its progress, take it off and
250
- * commit at the end.
251
- *
252
- * A {@link Command} rather than a generator, which is what makes a listing
253
- * scrubbable: membership is a function of `t` (on the stack for `0 < t < 1`,
254
- * off it outside), `settle(done)` replaces the `finally` and takes *which
255
- * way*, and `progress` is assigned from `t` rather than accumulated.
256
- */
257
- private runDim;
258
- /**
259
- * Route a tweened `code` through the diff engine.
260
- *
261
- * `to({ code })` is the form an author reaches for first — it is how every
262
- * other prop is animated — and a bare string prop would otherwise land in the
263
- * generic tween's discrete-snap bucket and simply cut at the end. Intercepted
264
- * here it becomes the same three-phase edit the named commands produce, while
265
- * the rest of the step's props tween alongside it untouched.
266
- */
267
- _prepareStep(to: Partial<CodeProps>, duration: number, easing?: EasingFunction): TweenStepper;
268
- /**
269
- * Find every range matching the literal string `text` in the current
270
- * source. Multi-line matches are supported.
271
- */
272
- findAllRanges(text: string): CodeRange[];
273
- /** Find the `index`th range matching `text`. Returns null if not found. */
274
- findRangeAt(text: string, index: number): CodeRange | null;
275
- /** Find the first range matching `text`. Returns null if not found. */
276
- findFirstRange(text: string): CodeRange | null;
277
- private joinedSource;
278
- private lineLengths;
279
- /** Character offset of a 1-indexed (line, col), clamped into the document. */
280
- private offsetAt;
281
- /**
282
- * Resolve one or more CodeRanges to the set of token ids whose content
283
- * overlaps any of them. Tokens that partially overlap are included.
284
- */
285
- private tokenIdsInRanges;
286
- /**
287
- * Thin delegator: everything about *how* a frame is painted (settled or
288
- * mid structural-edit, entry/exit motion, colour cross-fade) lives in
289
- * `drawCode` (the engine's `render.ts`) as a pure function over plain
290
- * state — this just gathers that state from the node's own instance
291
- * fields and caches.
292
- */
293
- protected drawSelf(draw: RenderContext2D): void;
294
- /**
295
- * Whether a listing command has applied since the timeline last restored the
296
- * props.
297
- *
298
- * A slot rather than a field because slots are all a restore puts back. The
299
- * structure, highlight and transitions live outside the props, and only a
300
- * command that has started writes them, so before the first one starts (or
301
- * after a seek back past it) they still hold whatever the last evaluation
302
- * left — the end of every command, after compile. This reads false again
303
- * there, and `_sync` derives them from the props instead.
304
- */
305
- private readonly _driven;
306
- /** Each source the props have named, tokenized once, so a listing derived again keeps the ids a highlight selected. */
307
- private readonly _derived;
308
- /** The first command to apply after a restore starts from the props' listing. */
309
- private _drive;
310
- private _sync;
311
- private _structureFor;
30
+ readonly highlighted: boolean;
31
+ }
32
+ /** A listing a command left behind: its source, its tokens, and the basis they were made on. */
33
+ export interface CodeListing {
34
+ readonly source: string;
35
+ readonly lines: IdLine[];
36
+ readonly basis: CodeTokenBasis;
37
+ }
38
+ export interface CodeEditFrame {
39
+ readonly transition: StructuralTransition;
40
+ readonly progress: number;
312
41
  }
42
+ /** The dim `highlight` leaves: what stays bright, what the rest dims to, and the cross-fade in flight. */
43
+ export interface CodeFocus {
44
+ readonly dim: number | null;
45
+ readonly ids: Set<number>;
46
+ readonly fade: DimTransition | null;
47
+ }
48
+ export interface CodeBanding {
49
+ readonly bands: RowBand[];
50
+ readonly fade: RowsTransition | null;
51
+ }
52
+ /**
53
+ * A `Code` whose edits are paired and timed by `strategies`. {@link Code} is
54
+ * the one with the defaults; a project wanting another hands its own to the
55
+ * engine in its place (the key is the same).
56
+ *
57
+ * A listing and nothing else: no paint slots, and no box behind the tokens. A
58
+ * listing set on a card is a `Code` inside a hugging `Rect`.
59
+ */
60
+ export declare function defineCode(strategies?: CodeStrategies): import("@motionscript/sdk").Component<"code", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
61
+ readonly code: import("@motionscript/sdk").Type<string, CodeSource, false>;
62
+ readonly language: "typescript";
63
+ readonly fontFamily: "Fira Mono";
64
+ /** A built-in or registered theme name (e.g. `'github-dark'`), or a `CodeHighlightStyle` object. */
65
+ readonly theme: import("@motionscript/sdk").Type<CodeTheme, CodeTheme, false>;
66
+ readonly fontSize: 16;
67
+ readonly lineHeight: 1.6;
68
+ readonly letterSpacing: 1.1;
69
+ readonly showLineNumbers: false;
70
+ readonly lineNumberGap: 2;
71
+ readonly listing: import("@motionscript/sdk").Type<CodeListing | null, CodeListing | null, true>;
72
+ readonly edit: import("@motionscript/sdk").Type<CodeEditFrame | null, CodeEditFrame | null, true>;
73
+ readonly focus: import("@motionscript/sdk").Type<CodeFocus, CodeFocus, true>;
74
+ readonly banding: import("@motionscript/sdk").Type<CodeBanding, CodeBanding, true>;
75
+ }>, {
76
+ readonly append: {
77
+ readonly code: import("@motionscript/sdk").Type<string, string, false>;
78
+ };
79
+ readonly prepend: {
80
+ readonly code: import("@motionscript/sdk").Type<string, string, false>;
81
+ };
82
+ readonly insert: {
83
+ readonly position: import("@motionscript/sdk").Type<[number, number] | undefined, [number, number] | undefined, false>;
84
+ readonly code: import("@motionscript/sdk").Type<string, string, false>;
85
+ };
86
+ readonly remove: {
87
+ readonly target: import("@motionscript/sdk").Type<CodeTarget | undefined, CodeTarget | undefined, false>;
88
+ };
89
+ readonly replace: {
90
+ readonly target: import("@motionscript/sdk").Type<CodeTarget | undefined, CodeTarget | undefined, false>;
91
+ readonly replacement: import("@motionscript/sdk").Type<string, string, false>;
92
+ };
93
+ readonly highlight: {
94
+ readonly target: import("@motionscript/sdk").Type<CodeTarget | undefined, CodeTarget | undefined, false>;
95
+ readonly dim: import("@motionscript/sdk").Type<number, number, false>;
96
+ };
97
+ readonly resetHighlight: unknown;
98
+ readonly highlightRows: {
99
+ readonly target: import("@motionscript/sdk").Type<CodeTarget | undefined, CodeTarget | undefined, false>;
100
+ readonly color: import("@motionscript/sdk").Type<_Color, NormalizedColor, false>;
101
+ readonly radius: import("@motionscript/sdk").Type<number, number, false>;
102
+ };
103
+ readonly resetRowHighlight: unknown;
104
+ }, readonly [], _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
105
+ readonly code: import("@motionscript/sdk").Type<string, CodeSource, false>;
106
+ readonly language: "typescript";
107
+ readonly fontFamily: "Fira Mono";
108
+ /** A built-in or registered theme name (e.g. `'github-dark'`), or a `CodeHighlightStyle` object. */
109
+ readonly theme: import("@motionscript/sdk").Type<CodeTheme, CodeTheme, false>;
110
+ readonly fontSize: 16;
111
+ readonly lineHeight: 1.6;
112
+ readonly letterSpacing: 1.1;
113
+ readonly showLineNumbers: false;
114
+ readonly lineNumberGap: 2;
115
+ readonly listing: import("@motionscript/sdk").Type<CodeListing | null, CodeListing | null, true>;
116
+ readonly edit: import("@motionscript/sdk").Type<CodeEditFrame | null, CodeEditFrame | null, true>;
117
+ readonly focus: import("@motionscript/sdk").Type<CodeFocus, CodeFocus, true>;
118
+ readonly banding: import("@motionscript/sdk").Type<CodeBanding, CodeBanding, true>;
119
+ }>, readonly []>>;
120
+ /**
121
+ * A syntax-highlighted listing whose edits animate token by token: each edit
122
+ * is diffed against what is on screen, so a token that survives travels to
123
+ * its new column and only what changed fades.
124
+ */
125
+ export declare const Code: import("@motionscript/sdk").Component<"code", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
126
+ readonly code: import("@motionscript/sdk").Type<string, CodeSource, false>;
127
+ readonly language: "typescript";
128
+ readonly fontFamily: "Fira Mono";
129
+ /** A built-in or registered theme name (e.g. `'github-dark'`), or a `CodeHighlightStyle` object. */
130
+ readonly theme: import("@motionscript/sdk").Type<CodeTheme, CodeTheme, false>;
131
+ readonly fontSize: 16;
132
+ readonly lineHeight: 1.6;
133
+ readonly letterSpacing: 1.1;
134
+ readonly showLineNumbers: false;
135
+ readonly lineNumberGap: 2;
136
+ readonly listing: import("@motionscript/sdk").Type<CodeListing | null, CodeListing | null, true>;
137
+ readonly edit: import("@motionscript/sdk").Type<CodeEditFrame | null, CodeEditFrame | null, true>;
138
+ readonly focus: import("@motionscript/sdk").Type<CodeFocus, CodeFocus, true>;
139
+ readonly banding: import("@motionscript/sdk").Type<CodeBanding, CodeBanding, true>;
140
+ }>, {
141
+ readonly append: {
142
+ readonly code: import("@motionscript/sdk").Type<string, string, false>;
143
+ };
144
+ readonly prepend: {
145
+ readonly code: import("@motionscript/sdk").Type<string, string, false>;
146
+ };
147
+ readonly insert: {
148
+ readonly position: import("@motionscript/sdk").Type<[number, number] | undefined, [number, number] | undefined, false>;
149
+ readonly code: import("@motionscript/sdk").Type<string, string, false>;
150
+ };
151
+ readonly remove: {
152
+ readonly target: import("@motionscript/sdk").Type<CodeTarget | undefined, CodeTarget | undefined, false>;
153
+ };
154
+ readonly replace: {
155
+ readonly target: import("@motionscript/sdk").Type<CodeTarget | undefined, CodeTarget | undefined, false>;
156
+ readonly replacement: import("@motionscript/sdk").Type<string, string, false>;
157
+ };
158
+ readonly highlight: {
159
+ readonly target: import("@motionscript/sdk").Type<CodeTarget | undefined, CodeTarget | undefined, false>;
160
+ readonly dim: import("@motionscript/sdk").Type<number, number, false>;
161
+ };
162
+ readonly resetHighlight: unknown;
163
+ readonly highlightRows: {
164
+ readonly target: import("@motionscript/sdk").Type<CodeTarget | undefined, CodeTarget | undefined, false>;
165
+ readonly color: import("@motionscript/sdk").Type<_Color, NormalizedColor, false>;
166
+ readonly radius: import("@motionscript/sdk").Type<number, number, false>;
167
+ };
168
+ readonly resetRowHighlight: unknown;
169
+ }, readonly [], _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
170
+ readonly code: import("@motionscript/sdk").Type<string, CodeSource, false>;
171
+ readonly language: "typescript";
172
+ readonly fontFamily: "Fira Mono";
173
+ /** A built-in or registered theme name (e.g. `'github-dark'`), or a `CodeHighlightStyle` object. */
174
+ readonly theme: import("@motionscript/sdk").Type<CodeTheme, CodeTheme, false>;
175
+ readonly fontSize: 16;
176
+ readonly lineHeight: 1.6;
177
+ readonly letterSpacing: 1.1;
178
+ readonly showLineNumbers: false;
179
+ readonly lineNumberGap: 2;
180
+ readonly listing: import("@motionscript/sdk").Type<CodeListing | null, CodeListing | null, true>;
181
+ readonly edit: import("@motionscript/sdk").Type<CodeEditFrame | null, CodeEditFrame | null, true>;
182
+ readonly focus: import("@motionscript/sdk").Type<CodeFocus, CodeFocus, true>;
183
+ readonly banding: import("@motionscript/sdk").Type<CodeBanding, CodeBanding, true>;
184
+ }>, readonly []>>;
185
+ export type Code = NodeOf<typeof Code>;
186
+ export type CodeProps = NonNullable<Parameters<typeof Code>[0]>;
187
+ /** What a listing shows now: its source, its token rows, and the edit in flight, if any. */
188
+ export declare function listingOf(code: Code): {
189
+ readonly source: string;
190
+ readonly lines: readonly IdLine[];
191
+ readonly edit: StructuralTransition | null;
192
+ };
193
+ /** Every range matching the literal `text` in `source`, in order and not overlapping. Multi-line matches are found too. */
194
+ export declare function findAllRanges(source: CodeSource, text: string): CodeRange[];
195
+ /** The `index`th range matching `text`, or `null`. */
196
+ export declare function findRangeAt(source: CodeSource, text: string, index: number): CodeRange | null;
197
+ /** The first range matching `text`, or `null`. */
198
+ export declare function findFirstRange(source: CodeSource, text: string): CodeRange | null;
313
199
  //# sourceMappingURL=node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,M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