@motionscript/code 0.1.0-alpha.5 → 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.
package/src/nodes.ts CHANGED
@@ -4,15 +4,13 @@ import { Code } from "./node";
4
4
  * Every node type this package publishes.
5
5
  *
6
6
  * A host registers these by handing the array to an engine —
7
- * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`
8
- * key. The decorator only *declares* that key: nothing is registered by the mere
9
- * act of importing a module, so a registry holds exactly what its owner asked
10
- * for and two engines in one process can differ about it.
7
+ * `new Engine(platform, { nodes: NODES })` — which reads each component's key.
8
+ * Defining a component only *declares* that key: nothing is registered by
9
+ * importing a module, so a registry holds exactly what its owner asked for.
11
10
  *
12
- * Listing class **values** is also what survives bundling. This package declares
13
- * `sideEffects: false`, which licenses a bundler to drop a module nothing
14
- * imports a value from, and a document names a node type by string — so
15
- * `import "./node"` for its side effect is exactly what gets shaken out, where an
16
- * array of bindings is a data dependency that cannot be.
11
+ * Listing the component **values** is also what survives bundling: this package
12
+ * declares `sideEffects: false`, and a document names a node type by string, so
13
+ * an import kept only for its side effect is exactly what gets shaken out.
17
14
  */
18
- export const NODES = [Code];
15
+ // Typed by name, so the declaration names each component rather than spelling out its type through core.
16
+ export const NODES: (typeof Code)[] = [Code];
package/src/render.ts CHANGED
@@ -70,6 +70,9 @@ export interface DrawCodeState {
70
70
  boxW?: number;
71
71
  }
72
72
 
73
+ /** What a frame is drawn onto: somewhere to draw, and the face's measurements. A render context is one. */
74
+ export type CodeCanvas = Pick<RenderContext2D, "draw" | "measureText">;
75
+
73
76
  /**
74
77
  * Draw one frame of a code listing: the settled structure, or — mid
75
78
  * structural edit — the two structures it is interpolating between (what
@@ -77,7 +80,7 @@ export interface DrawCodeState {
77
80
  * fades/slides in where it lands). Pure over `state`; touches nothing but
78
81
  * `draw`.
79
82
  */
80
- export function drawCode(draw: RenderContext2D, state: DrawCodeState): void {
83
+ export function drawCode(draw: CodeCanvas, state: DrawCodeState): void {
81
84
  const { tokenLines, metrics, advanceCache, from, to, edit, tokenStates: dim } = state;
82
85
 
83
86
  const progress = edit ? edit.progress : 1;
@@ -230,7 +233,7 @@ function bandEdges(band: RowBand, state: DrawCodeState, pMove: number): { top: n
230
233
  * its rows through a structural edit; between two sets, bands paired by position
231
234
  * slide and recolour while an unpaired one fades.
232
235
  */
233
- function drawRowBands(draw: RenderContext2D, state: DrawCodeState, width: number, pMove: number): void {
236
+ function drawRowBands(draw: CodeCanvas, state: DrawCodeState, width: number, pMove: number): void {
234
237
  const { rowBands = [], rowsEdit = null } = state;
235
238
  const paint = (top: number, bottom: number, color: NormalizedColor, radius: number, opacity: number): void => {
236
239
  if (opacity <= 0 || top <= bottom) return;