@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/CHANGELOG.md +22 -0
- package/README.md +24 -9
- package/dist/browser/index.js +10 -7
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/manifest.json +1 -1
- package/dist/engine.d.ts +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js.map +1 -1
- package/dist/node.d.ts +187 -336
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +616 -864
- package/dist/node.js.map +1 -1
- package/dist/nodes.d.ts +6 -9
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +7 -9
- package/dist/nodes.js.map +1 -1
- package/dist/render.d.ts +3 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js.map +1 -1
- package/package.json +4 -4
- package/src/engine.ts +1 -1
- package/src/node.ts +744 -928
- package/src/nodes.ts +8 -10
- package/src/render.ts +5 -2
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
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
13
|
-
* `sideEffects: false`,
|
|
14
|
-
*
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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;
|