@motionscript/code 0.0.0-stage → 0.1.0-alpha.10
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 +101 -0
- package/LICENSE +201 -0
- package/NOTICE +49 -0
- package/README.md +174 -3
- package/dist/browser/THIRD_PARTY_LICENSES.txt +431 -0
- package/dist/browser/chunks/chunk-HET2RCSD.js +2 -0
- package/dist/browser/chunks/chunk-HET2RCSD.js.map +7 -0
- package/dist/browser/chunks/chunk-SYZUZB3M.js +2 -0
- package/dist/browser/chunks/chunk-SYZUZB3M.js.map +7 -0
- package/dist/browser/chunks/dist-3F5TQHM6.js +2 -0
- package/dist/browser/chunks/dist-3F5TQHM6.js.map +7 -0
- package/dist/browser/chunks/dist-3SIR23P4.js +2 -0
- package/dist/browser/chunks/dist-3SIR23P4.js.map +7 -0
- package/dist/browser/chunks/dist-AQRNACF3.js +2 -0
- package/dist/browser/chunks/dist-AQRNACF3.js.map +7 -0
- package/dist/browser/chunks/dist-B46VH2YP.js +2 -0
- package/dist/browser/chunks/dist-B46VH2YP.js.map +7 -0
- package/dist/browser/chunks/dist-FH6BHJ6A.js +7 -0
- package/dist/browser/chunks/dist-FH6BHJ6A.js.map +7 -0
- package/dist/browser/chunks/dist-FQDUBZKU.js +2 -0
- package/dist/browser/chunks/dist-FQDUBZKU.js.map +7 -0
- package/dist/browser/chunks/dist-GPNEVCJI.js +2 -0
- package/dist/browser/chunks/dist-GPNEVCJI.js.map +7 -0
- package/dist/browser/chunks/dist-LRSXSDHT.js +2 -0
- package/dist/browser/chunks/dist-LRSXSDHT.js.map +7 -0
- package/dist/browser/chunks/dist-N4CNBNHL.js +2 -0
- package/dist/browser/chunks/dist-N4CNBNHL.js.map +7 -0
- package/dist/browser/chunks/dist-OXJDTPQ6.js +2 -0
- package/dist/browser/chunks/dist-OXJDTPQ6.js.map +7 -0
- package/dist/browser/chunks/dist-SH7H4MRK.js +2 -0
- package/dist/browser/chunks/dist-SH7H4MRK.js.map +7 -0
- package/dist/browser/chunks/dist-UG3NTKWL.js +2 -0
- package/dist/browser/chunks/dist-UG3NTKWL.js.map +7 -0
- package/dist/browser/chunks/dist-W5ZXIMV7.js +2 -0
- package/dist/browser/chunks/dist-W5ZXIMV7.js.map +7 -0
- package/dist/browser/index.js +11 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/manifest.json +93 -0
- package/dist/code-range.d.ts +75 -0
- package/dist/code-range.d.ts.map +1 -0
- package/dist/code-range.js +132 -0
- package/dist/code-range.js.map +1 -0
- package/dist/diff.d.ts +56 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +311 -0
- package/dist/diff.js.map +1 -0
- package/dist/engine.d.ts +15 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +17 -0
- package/dist/engine.js.map +1 -0
- package/dist/highlight.d.ts +51 -0
- package/dist/highlight.d.ts.map +1 -0
- package/dist/highlight.js +277 -0
- package/dist/highlight.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +77 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +74 -0
- package/dist/layout.js.map +1 -0
- package/dist/measure-cache.d.ts +38 -0
- package/dist/measure-cache.d.ts.map +1 -0
- package/dist/measure-cache.js +0 -0
- package/dist/measure-cache.js.map +1 -0
- package/dist/node.d.ts +287 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +667 -0
- package/dist/node.js.map +1 -0
- package/dist/nodes.d.ts +15 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +16 -0
- package/dist/nodes.js.map +1 -0
- package/dist/render.d.ts +35 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +282 -0
- package/dist/render.js.map +1 -0
- package/dist/style.d.ts +88 -0
- package/dist/style.d.ts.map +1 -0
- package/dist/style.js +207 -0
- package/dist/style.js.map +1 -0
- package/dist/tokens.d.ts +24 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +54 -0
- package/dist/tokens.js.map +1 -0
- package/dist/transitions.d.ts +133 -0
- package/dist/transitions.d.ts.map +1 -0
- package/dist/transitions.js +85 -0
- package/dist/transitions.js.map +1 -0
- package/package.json +85 -3
- package/registry.json +6 -0
- package/src/code-range.ts +165 -0
- package/src/diff.ts +351 -0
- package/src/engine.ts +21 -0
- package/src/highlight.ts +340 -0
- package/src/index.ts +3 -0
- package/src/layout.ts +157 -0
- package/src/measure-cache.ts +0 -0
- package/src/node.ts +854 -0
- package/src/nodes.ts +16 -0
- package/src/render.ts +315 -0
- package/src/style.ts +255 -0
- package/src/tokens.ts +79 -0
- package/src/transitions.ts +204 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a range that spans `length` characters starting at (line, col).
|
|
3
|
+
* If `length` is omitted, the range extends to the end of the line.
|
|
4
|
+
*
|
|
5
|
+
* Example:
|
|
6
|
+
* word(1, 3, 3) // line 1, column 3, spans 3 characters
|
|
7
|
+
* word(1, 3) // line 1, column 3, to end of line
|
|
8
|
+
*/
|
|
9
|
+
export function word(line, col, length) {
|
|
10
|
+
return {
|
|
11
|
+
startLine: line,
|
|
12
|
+
startCol: col,
|
|
13
|
+
endLine: line,
|
|
14
|
+
endCol: length === undefined ? Infinity : col + length,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a range that covers entire lines from `from` to `to` (inclusive).
|
|
19
|
+
* If `to` is omitted, only line `from` is covered.
|
|
20
|
+
*
|
|
21
|
+
* Example:
|
|
22
|
+
* lines(1, 3) // lines 1 through 3
|
|
23
|
+
* lines(2) // line 2 only
|
|
24
|
+
*/
|
|
25
|
+
export function lines(from, to) {
|
|
26
|
+
return {
|
|
27
|
+
startLine: from,
|
|
28
|
+
startCol: 1,
|
|
29
|
+
endLine: to ?? from,
|
|
30
|
+
endCol: Infinity,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Immutable, chainable, iterable builder over multiple ranges — mirrors
|
|
35
|
+
* {@link FillChain}/`Fills` in `@motionscript/sdk`. Every method returns a
|
|
36
|
+
* *new* chain with one more range appended, so the next range-kind method is
|
|
37
|
+
* called directly rather than through a separate combinator:
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* CodeRanges.lines(2).word(5, 1, 3) // a 2-range selection, one expression
|
|
41
|
+
*/
|
|
42
|
+
export class CodeRangeChain {
|
|
43
|
+
list;
|
|
44
|
+
constructor(list = []) {
|
|
45
|
+
this.list = list;
|
|
46
|
+
}
|
|
47
|
+
lines(from, to) {
|
|
48
|
+
return new CodeRangeChain([...this.list, lines(from, to)]);
|
|
49
|
+
}
|
|
50
|
+
word(line, col, length) {
|
|
51
|
+
return new CodeRangeChain([...this.list, word(line, col, length)]);
|
|
52
|
+
}
|
|
53
|
+
*[Symbol.iterator]() {
|
|
54
|
+
yield* this.list;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A chain is stored as its ranges. Without this it serialises as
|
|
58
|
+
* `{ "list": [...] }`, which has no iterator once read back and so selects
|
|
59
|
+
* nothing; a plain array of ranges reads back as the selection it was.
|
|
60
|
+
*/
|
|
61
|
+
toJSON() {
|
|
62
|
+
return this.list;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Entry point for building multi-range selections fluently — an empty
|
|
67
|
+
* {@link CodeRangeChain}, so `CodeRanges.lines(2)` *is* `new
|
|
68
|
+
* CodeRangeChain().lines(2)`. `word`/`lines` stay directly importable and
|
|
69
|
+
* usable standalone for a single range; reach for `CodeRanges` when a call
|
|
70
|
+
* needs more than one.
|
|
71
|
+
*/
|
|
72
|
+
export const CodeRanges = new CodeRangeChain();
|
|
73
|
+
/**
|
|
74
|
+
* Convert a CodeRange to absolute character offsets [start, end) in the joined
|
|
75
|
+
* source text, given the per-line lengths of that source. Lines/columns are
|
|
76
|
+
* clamped into the document so out-of-bounds inputs produce a valid range.
|
|
77
|
+
*/
|
|
78
|
+
export function rangeToCharOffsets(r, lineLengths) {
|
|
79
|
+
if (lineLengths.length === 0)
|
|
80
|
+
return { start: 0, end: 0 };
|
|
81
|
+
// Cumulative line starts in the joined string (lines joined with '\n').
|
|
82
|
+
const lineStart = new Array(lineLengths.length);
|
|
83
|
+
let acc = 0;
|
|
84
|
+
for (let i = 0; i < lineLengths.length; i++) {
|
|
85
|
+
lineStart[i] = acc;
|
|
86
|
+
acc += lineLengths[i] + 1; // +1 for the joining newline
|
|
87
|
+
}
|
|
88
|
+
const docEnd = acc > 0 ? acc - 1 : 0; // strip trailing newline
|
|
89
|
+
const clampLine = (n) => Math.max(0, Math.min(lineLengths.length - 1, n - 1)); // to 0-indexed
|
|
90
|
+
// A range read back from JSON holds `Infinity` as `null`; both mean "to the end".
|
|
91
|
+
const endLine = r.endLine ?? Infinity;
|
|
92
|
+
const endCol = r.endCol ?? Infinity;
|
|
93
|
+
const sLine = clampLine(r.startLine);
|
|
94
|
+
const eLine = clampLine(endLine);
|
|
95
|
+
const sColMax = lineLengths[sLine];
|
|
96
|
+
const eColMax = lineLengths[eLine];
|
|
97
|
+
// Columns are 1-indexed; clamp to [1, lineLength+1] so endCol can sit past
|
|
98
|
+
// the last char (one-past-end).
|
|
99
|
+
const sCol = Math.max(0, Math.min(sColMax, r.startCol - 1));
|
|
100
|
+
const eCol = endCol === Infinity
|
|
101
|
+
? eColMax
|
|
102
|
+
: Math.max(0, Math.min(eColMax, endCol - 1));
|
|
103
|
+
const start = Math.min(docEnd, lineStart[sLine] + sCol);
|
|
104
|
+
const end = Math.min(docEnd, lineStart[eLine] + eCol);
|
|
105
|
+
return { start: Math.min(start, end), end: Math.max(start, end) };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Convert [start, end) character offsets in joined source to a CodeRange.
|
|
109
|
+
* Lines/cols in the returned range are 1-indexed.
|
|
110
|
+
*/
|
|
111
|
+
export function charOffsetsToRange(start, end, lineLengths) {
|
|
112
|
+
let off = 0;
|
|
113
|
+
let startLine = 1, startCol = 1, endLine = 1, endCol = 1;
|
|
114
|
+
let foundStart = false;
|
|
115
|
+
for (let li = 0; li < lineLengths.length; li++) {
|
|
116
|
+
const lineStart = off;
|
|
117
|
+
const lineEnd = off + lineLengths[li];
|
|
118
|
+
if (!foundStart && start >= lineStart && start <= lineEnd) {
|
|
119
|
+
startLine = li + 1;
|
|
120
|
+
startCol = (start - lineStart) + 1;
|
|
121
|
+
foundStart = true;
|
|
122
|
+
}
|
|
123
|
+
if (end >= lineStart && end <= lineEnd) {
|
|
124
|
+
endLine = li + 1;
|
|
125
|
+
endCol = (end - lineStart) + 1;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
off = lineEnd + 1;
|
|
129
|
+
}
|
|
130
|
+
return { startLine, startCol, endLine, endCol };
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=code-range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-range.js","sourceRoot":"","sources":["../src/code-range.ts"],"names":[],"mappings":"AAaA;;;;;;;GAOG;AACH,MAAM,UAAU,IAAI,CAAC,IAAY,EAAE,GAAW,EAAE,MAAe;IAC3D,OAAO;QACH,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,GAAG;QACb,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM;KACzD,CAAC;AACN,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,KAAK,CAAC,IAAY,EAAE,EAAW;IAC3C,OAAO;QACH,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,CAAC;QACX,OAAO,EAAE,EAAE,IAAI,IAAI;QACnB,MAAM,EAAE,QAAQ;KACnB,CAAC;AACN,CAAC;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AAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACpD,CAAC","sourcesContent":["/**\n * A range over a code document. Lines and columns are 1-indexed.\n *\n * `endLine`/`endCol` may be `Infinity` to mean \"to the end of the line\" or\n * \"to the end of the document\".\n */\nexport interface CodeRange {\n startLine: number;\n startCol: number;\n endLine: number;\n endCol: number;\n}\n\n/**\n * Create a range that spans `length` characters starting at (line, col).\n * If `length` is omitted, the range extends to the end of the line.\n *\n * Example:\n * word(1, 3, 3) // line 1, column 3, spans 3 characters\n * word(1, 3) // line 1, column 3, to end of line\n */\nexport function word(line: number, col: number, length?: number): CodeRange {\n return {\n startLine: line,\n startCol: col,\n endLine: line,\n endCol: length === undefined ? Infinity : col + length,\n };\n}\n\n/**\n * Create a range that covers entire lines from `from` to `to` (inclusive).\n * If `to` is omitted, only line `from` is covered.\n *\n * Example:\n * lines(1, 3) // lines 1 through 3\n * lines(2) // line 2 only\n */\nexport function lines(from: number, to?: number): CodeRange {\n return {\n startLine: from,\n startCol: 1,\n endLine: to ?? from,\n endCol: Infinity,\n };\n}\n\n\n\n/**\n * Immutable, chainable, iterable builder over multiple ranges — mirrors\n * {@link FillChain}/`Fills` in `@motionscript/sdk`. Every method returns a\n * *new* chain with one more range appended, so the next range-kind method is\n * called directly rather than through a separate combinator:\n *\n * @example\n * CodeRanges.lines(2).word(5, 1, 3) // a 2-range selection, one expression\n */\nexport class CodeRangeChain {\n constructor(public readonly list: CodeRange[] = []) { }\n\n lines(from: number, to?: number): CodeRangeChain {\n return new CodeRangeChain([...this.list, lines(from, to)]);\n }\n\n word(line: number, col: number, length?: number): CodeRangeChain {\n return new CodeRangeChain([...this.list, word(line, col, length)]);\n }\n\n *[Symbol.iterator](): Iterator<CodeRange> {\n yield* this.list;\n }\n\n /**\n * A chain is stored as its ranges. Without this it serialises as\n * `{ \"list\": [...] }`, which has no iterator once read back and so selects\n * nothing; a plain array of ranges reads back as the selection it was.\n */\n toJSON(): CodeRange[] {\n return this.list;\n }\n}\n\n/**\n * Entry point for building multi-range selections fluently — an empty\n * {@link CodeRangeChain}, so `CodeRanges.lines(2)` *is* `new\n * CodeRangeChain().lines(2)`. `word`/`lines` stay directly importable and\n * usable standalone for a single range; reach for `CodeRanges` when a call\n * needs more than one.\n */\nexport const CodeRanges = new CodeRangeChain();\n\n/**\n * Convert a CodeRange to absolute character offsets [start, end) in the joined\n * source text, given the per-line lengths of that source. Lines/columns are\n * clamped into the document so out-of-bounds inputs produce a valid range.\n */\nexport function rangeToCharOffsets(\n r: CodeRange,\n lineLengths: number[],\n): { start: number; end: number } {\n if (lineLengths.length === 0) return { start: 0, end: 0 };\n\n // Cumulative line starts in the joined string (lines joined with '\\n').\n const lineStart: number[] = new Array(lineLengths.length);\n let acc = 0;\n for (let i = 0; i < lineLengths.length; i++) {\n lineStart[i] = acc;\n acc += lineLengths[i] + 1; // +1 for the joining newline\n }\n const docEnd = acc > 0 ? acc - 1 : 0; // strip trailing newline\n\n const clampLine = (n: number) =>\n Math.max(0, Math.min(lineLengths.length - 1, n - 1)); // to 0-indexed\n\n // A range read back from JSON holds `Infinity` as `null`; both mean \"to the end\".\n const endLine = r.endLine ?? Infinity;\n const endCol = r.endCol ?? Infinity;\n\n const sLine = clampLine(r.startLine);\n const eLine = clampLine(endLine);\n const sColMax = lineLengths[sLine];\n const eColMax = lineLengths[eLine];\n\n // Columns are 1-indexed; clamp to [1, lineLength+1] so endCol can sit past\n // the last char (one-past-end).\n const sCol = Math.max(0, Math.min(sColMax, r.startCol - 1));\n const eCol = endCol === Infinity\n ? eColMax\n : Math.max(0, Math.min(eColMax, endCol - 1));\n\n const start = Math.min(docEnd, lineStart[sLine] + sCol);\n const end = Math.min(docEnd, lineStart[eLine] + eCol);\n return { start: Math.min(start, end), end: Math.max(start, end) };\n}\n\n/**\n * Convert [start, end) character offsets in joined source to a CodeRange.\n * Lines/cols in the returned range are 1-indexed.\n */\nexport function charOffsetsToRange(\n start: number,\n end: number,\n lineLengths: number[],\n): CodeRange {\n let off = 0;\n let startLine = 1, startCol = 1, endLine = 1, endCol = 1;\n let foundStart = false;\n for (let li = 0; li < lineLengths.length; li++) {\n const lineStart = off;\n const lineEnd = off + lineLengths[li];\n if (!foundStart && start >= lineStart && start <= lineEnd) {\n startLine = li + 1;\n startCol = (start - lineStart) + 1;\n foundStart = true;\n }\n if (end >= lineStart && end <= lineEnd) {\n endLine = li + 1;\n endCol = (end - lineStart) + 1;\n break;\n }\n off = lineEnd + 1;\n }\n return { startLine, startCol, endLine, endCol };\n}\n"]}
|
package/dist/diff.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { IdLine } from "./tokens.js";
|
|
2
|
+
/**
|
|
3
|
+
* The result of diffing one listing structure against another: the *next*
|
|
4
|
+
* structure, with token and line ids carried over from the previous one
|
|
5
|
+
* wherever the content survived, plus the three sets a transition needs to know
|
|
6
|
+
* which role each token plays.
|
|
7
|
+
*
|
|
8
|
+
* Identity is the whole product here. `const variable = 3` becoming
|
|
9
|
+
* `const number = 3` should move `const` and `= 3` rather than dissolve and
|
|
10
|
+
* rebuild them, and a token can only *move* if the frame after the edit still
|
|
11
|
+
* knows it is the same token.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* How a `Code` node decides which token became which across an edit. Given
|
|
15
|
+
* the old and new tokenized structures, return the carried-over structure
|
|
16
|
+
* plus the added/removed/renamed-line bookkeeping a transition needs.
|
|
17
|
+
* `diffCode` below is the default implementation (exported as
|
|
18
|
+
* `defaultCodeDiff`) — pass a `diffStrategy` of this shape to `<Code>` to
|
|
19
|
+
* replace it with your own.
|
|
20
|
+
*/
|
|
21
|
+
export type CodeDiffStrategy = (from: IdLine[], to: IdLine[]) => CodeEdit;
|
|
22
|
+
export interface CodeEdit {
|
|
23
|
+
/** The new structure. Ids are rewritten in place onto the tokens handed in. */
|
|
24
|
+
lines: IdLine[];
|
|
25
|
+
/** Ids present only in the old structure — these fade out. */
|
|
26
|
+
removedIds: Set<number>;
|
|
27
|
+
/** Ids present only in the new structure — these fade in. */
|
|
28
|
+
addedIds: Set<number>;
|
|
29
|
+
/** Ids of {@link lines} that did not exist before — these enter as a whole row. */
|
|
30
|
+
newLineIds: Set<number>;
|
|
31
|
+
/** Previous colour of a surviving token whose highlighting changed, for the cross-fade. */
|
|
32
|
+
fromColorById: Map<number, string | undefined>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The most line pairs one run of changed lines is scored against each other, and
|
|
36
|
+
* the most across a whole edit.
|
|
37
|
+
*
|
|
38
|
+
* Scoring every pair is quadratic: with 50-character lines it took 31 ms at 200
|
|
39
|
+
* lines and 741 ms at 1,000, paid again for each edit command when it is built.
|
|
40
|
+
* So the lines are first paired where they cannot be in doubt (see
|
|
41
|
+
* {@link alignLines}), and only a run left between two such anchors is scored.
|
|
42
|
+
* A run past the first limit, or what is left of the second, is not compared: its
|
|
43
|
+
* lines leave and enter as whole rows. That is the budget, and an edit that stays
|
|
44
|
+
* inside it is diffed exactly as before.
|
|
45
|
+
*/
|
|
46
|
+
export declare const LINE_ALIGN_CELLS = 40000;
|
|
47
|
+
export declare const EDIT_ALIGN_CELLS = 160000;
|
|
48
|
+
/**
|
|
49
|
+
* Carry `from`'s identities onto `to`, and report what changed.
|
|
50
|
+
*
|
|
51
|
+
* `to` is freshly tokenized and owns ids nobody has seen yet, so rewriting them
|
|
52
|
+
* in place is safe and is what makes the transition cheap: after this, the two
|
|
53
|
+
* structures share an id for every token that survived the edit.
|
|
54
|
+
*/
|
|
55
|
+
export declare function diffCode(from: IdLine[], to: IdLine[]): CodeEdit;
|
|
56
|
+
//# sourceMappingURL=diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAW,MAAM,UAAU,CAAC;AAEhD;;;;;;;;;;GAUG;AACH;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,QAAQ,CAAC;AAE1E,MAAM,WAAW,QAAQ;IACrB,+EAA+E;IAC/E,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,8DAA8D;IAC9D,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,6DAA6D;IAC7D,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACtB,mFAAmF;IACnF,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,2FAA2F;IAC3F,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAClD;AAYD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,QAAS,CAAC;AACvC,eAAO,MAAM,gBAAgB,SAAU,CAAC;AA0OxC;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,QAAQ,CAkD/D"}
|
package/dist/diff.js
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How similar two lines must be before they are treated as *one line that was
|
|
3
|
+
* edited* rather than as one line deleted and another inserted.
|
|
4
|
+
*
|
|
5
|
+
* Below this, a row's tokens have so little in common that carrying ids across
|
|
6
|
+
* would animate glyphs sliding between unrelated words. Above it, the edit reads
|
|
7
|
+
* the way it was made.
|
|
8
|
+
*/
|
|
9
|
+
const LINE_MATCH_FLOOR = 0.45;
|
|
10
|
+
/**
|
|
11
|
+
* The most line pairs one run of changed lines is scored against each other, and
|
|
12
|
+
* the most across a whole edit.
|
|
13
|
+
*
|
|
14
|
+
* Scoring every pair is quadratic: with 50-character lines it took 31 ms at 200
|
|
15
|
+
* lines and 741 ms at 1,000, paid again for each edit command when it is built.
|
|
16
|
+
* So the lines are first paired where they cannot be in doubt (see
|
|
17
|
+
* {@link alignLines}), and only a run left between two such anchors is scored.
|
|
18
|
+
* A run past the first limit, or what is left of the second, is not compared: its
|
|
19
|
+
* lines leave and enter as whole rows. That is the budget, and an edit that stays
|
|
20
|
+
* inside it is diffed exactly as before.
|
|
21
|
+
*/
|
|
22
|
+
export const LINE_ALIGN_CELLS = 40_000;
|
|
23
|
+
export const EDIT_ALIGN_CELLS = 160_000;
|
|
24
|
+
/** Weight a token carries when judging similarity: its visible characters. */
|
|
25
|
+
function tokenWeight(tok) {
|
|
26
|
+
return tok.content.trim().length;
|
|
27
|
+
}
|
|
28
|
+
function lineWeight(line) {
|
|
29
|
+
let sum = 0;
|
|
30
|
+
for (const tok of line.tokens)
|
|
31
|
+
sum += tokenWeight(tok);
|
|
32
|
+
return sum;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Dice coefficient over the two lines' token multisets, weighted by visible
|
|
36
|
+
* characters so `variable` counts for far more than a run of spaces.
|
|
37
|
+
*
|
|
38
|
+
* Two blank lines are identical (1); a blank line against a non-blank one shares
|
|
39
|
+
* nothing (0), which keeps the blank rows a reformat introduces from anchoring
|
|
40
|
+
* themselves onto real code.
|
|
41
|
+
*/
|
|
42
|
+
function similarity(a, b) {
|
|
43
|
+
const wa = lineWeight(a);
|
|
44
|
+
const wb = lineWeight(b);
|
|
45
|
+
if (wa === 0 && wb === 0)
|
|
46
|
+
return 1;
|
|
47
|
+
if (wa === 0 || wb === 0)
|
|
48
|
+
return 0;
|
|
49
|
+
const bag = new Map();
|
|
50
|
+
for (const tok of a.tokens) {
|
|
51
|
+
if (tokenWeight(tok) === 0)
|
|
52
|
+
continue;
|
|
53
|
+
bag.set(tok.content, (bag.get(tok.content) ?? 0) + 1);
|
|
54
|
+
}
|
|
55
|
+
let common = 0;
|
|
56
|
+
for (const tok of b.tokens) {
|
|
57
|
+
const w = tokenWeight(tok);
|
|
58
|
+
if (w === 0)
|
|
59
|
+
continue;
|
|
60
|
+
const left = bag.get(tok.content) ?? 0;
|
|
61
|
+
if (left > 0) {
|
|
62
|
+
bag.set(tok.content, left - 1);
|
|
63
|
+
common += w;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return (2 * common) / (wa + wb);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Align two sequences by maximising total `score`, skipping is free.
|
|
70
|
+
*
|
|
71
|
+
* A plain LCS would only ever pair *identical* elements, which is the wrong tool
|
|
72
|
+
* twice over: two lines that differ by one word are the same line, and two
|
|
73
|
+
* tokens that differ only in colour are the same token. Scoring the pairing and
|
|
74
|
+
* letting anything that scores ≤ 0 fall out expresses that directly, and because
|
|
75
|
+
* skips cost nothing the alignment stays in order.
|
|
76
|
+
*
|
|
77
|
+
* Returns the matched index pairs, in order.
|
|
78
|
+
*/
|
|
79
|
+
function align(aLength, bLength, score) {
|
|
80
|
+
// dp[i][j] = best score aligning a[0..i) with b[0..j).
|
|
81
|
+
const width = bLength + 1;
|
|
82
|
+
const dp = new Float64Array((aLength + 1) * width);
|
|
83
|
+
const pairScore = new Float64Array(aLength * bLength);
|
|
84
|
+
for (let i = 1; i <= aLength; i++) {
|
|
85
|
+
for (let j = 1; j <= bLength; j++) {
|
|
86
|
+
const s = score(i - 1, j - 1);
|
|
87
|
+
pairScore[(i - 1) * bLength + (j - 1)] = s;
|
|
88
|
+
const skipA = dp[(i - 1) * width + j];
|
|
89
|
+
const skipB = dp[i * width + (j - 1)];
|
|
90
|
+
let best = skipA > skipB ? skipA : skipB;
|
|
91
|
+
if (s > 0) {
|
|
92
|
+
const paired = dp[(i - 1) * width + (j - 1)] + s;
|
|
93
|
+
if (paired > best)
|
|
94
|
+
best = paired;
|
|
95
|
+
}
|
|
96
|
+
dp[i * width + j] = best;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const pairs = [];
|
|
100
|
+
let i = aLength;
|
|
101
|
+
let j = bLength;
|
|
102
|
+
while (i > 0 && j > 0) {
|
|
103
|
+
const s = pairScore[(i - 1) * bLength + (j - 1)];
|
|
104
|
+
if (s > 0 && dp[i * width + j] === dp[(i - 1) * width + (j - 1)] + s) {
|
|
105
|
+
pairs.push([i - 1, j - 1]);
|
|
106
|
+
i--;
|
|
107
|
+
j--;
|
|
108
|
+
}
|
|
109
|
+
else if (dp[(i - 1) * width + j] >= dp[i * width + (j - 1)]) {
|
|
110
|
+
i--;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
j--;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
pairs.reverse();
|
|
117
|
+
return pairs;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Match the tokens of one line against another's.
|
|
121
|
+
*
|
|
122
|
+
* Scored by visible characters rather than token count, so an alignment that
|
|
123
|
+
* keeps `items.reduce` together beats one that keeps four more spaces. A token
|
|
124
|
+
* pairs only when its content is unchanged — a changed word is a different word,
|
|
125
|
+
* and should be seen to be replaced.
|
|
126
|
+
*/
|
|
127
|
+
function alignTokens(from, to) {
|
|
128
|
+
return align(from.length, to.length, (i, j) => {
|
|
129
|
+
if (from[i].content !== to[j].content)
|
|
130
|
+
return 0;
|
|
131
|
+
// Whitespace still pairs (it holds indentation together), just weakly
|
|
132
|
+
// enough that it never outranks real content.
|
|
133
|
+
return tokenWeight(to[j]) || 0.25;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function sameTokens(a, b) {
|
|
137
|
+
if (a.tokens.length !== b.tokens.length)
|
|
138
|
+
return false;
|
|
139
|
+
for (let k = 0; k < a.tokens.length; k++)
|
|
140
|
+
if (a.tokens[k].content !== b.tokens[k].content)
|
|
141
|
+
return false;
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
/** A line's text, token boundaries included, for telling identical lines apart from similar ones. */
|
|
145
|
+
function signature(line) {
|
|
146
|
+
let out = "";
|
|
147
|
+
for (const tok of line.tokens)
|
|
148
|
+
out += tok.content + "\u0001";
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Pair the lines of two listings, in order.
|
|
153
|
+
*
|
|
154
|
+
* Lines that are the same at the start and at the end are paired outright. In
|
|
155
|
+
* what is left, a line that occurs exactly once on each side is an anchor, and
|
|
156
|
+
* the longest run of anchors that keeps their order splits the rest into runs of
|
|
157
|
+
* changed lines, each scored against itself within the budget (see
|
|
158
|
+
* {@link LINE_ALIGN_CELLS}). A one-line edit to a long listing therefore never
|
|
159
|
+
* builds a table bigger than the lines around it.
|
|
160
|
+
*/
|
|
161
|
+
function alignLines(from, to) {
|
|
162
|
+
const fromSig = from.map(signature);
|
|
163
|
+
const toSig = to.map(signature);
|
|
164
|
+
const pairs = [];
|
|
165
|
+
let head = 0;
|
|
166
|
+
while (head < from.length && head < to.length && fromSig[head] === toSig[head]) {
|
|
167
|
+
pairs.push([head, head]);
|
|
168
|
+
head++;
|
|
169
|
+
}
|
|
170
|
+
let tail = 0;
|
|
171
|
+
while (tail < from.length - head && tail < to.length - head
|
|
172
|
+
&& fromSig[from.length - 1 - tail] === toSig[to.length - 1 - tail])
|
|
173
|
+
tail++;
|
|
174
|
+
const anchors = anchorLines(fromSig, toSig, head, from.length - tail, head, to.length - tail);
|
|
175
|
+
let budget = EDIT_ALIGN_CELLS;
|
|
176
|
+
let fi = head;
|
|
177
|
+
let ti = head;
|
|
178
|
+
for (const [af, at] of [...anchors, [from.length - tail, to.length - tail]]) {
|
|
179
|
+
const rows = af - fi;
|
|
180
|
+
const cols = at - ti;
|
|
181
|
+
const cells = rows * cols;
|
|
182
|
+
if (cells > 0 && cells <= LINE_ALIGN_CELLS && cells <= budget) {
|
|
183
|
+
budget -= cells;
|
|
184
|
+
for (const [i, j] of align(rows, cols, (a, b) => similarity(from[fi + a], to[ti + b]) - LINE_MATCH_FLOOR)) {
|
|
185
|
+
pairs.push([fi + i, ti + j]);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (af < from.length - tail)
|
|
189
|
+
pairs.push([af, at]);
|
|
190
|
+
fi = af + 1;
|
|
191
|
+
ti = at + 1;
|
|
192
|
+
}
|
|
193
|
+
for (let k = tail; k > 0; k--)
|
|
194
|
+
pairs.push([from.length - k, to.length - k]);
|
|
195
|
+
return pairs;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The lines that occur once in `from[fa, fb)` and once in `to[ta, tb)`, reduced to
|
|
199
|
+
* the longest subsequence that is increasing on both sides (patience sorting).
|
|
200
|
+
* Blank lines are never anchors: they say nothing about where they belong.
|
|
201
|
+
*/
|
|
202
|
+
function anchorLines(fromSig, toSig, fa, fb, ta, tb) {
|
|
203
|
+
const fromAt = new Map();
|
|
204
|
+
const seen = new Set();
|
|
205
|
+
for (let i = fa; i < fb; i++) {
|
|
206
|
+
const sig = fromSig[i];
|
|
207
|
+
if (seen.has(sig))
|
|
208
|
+
fromAt.delete(sig);
|
|
209
|
+
else
|
|
210
|
+
fromAt.set(sig, i);
|
|
211
|
+
seen.add(sig);
|
|
212
|
+
}
|
|
213
|
+
const toAt = new Map();
|
|
214
|
+
const seenTo = new Set();
|
|
215
|
+
for (let j = ta; j < tb; j++) {
|
|
216
|
+
const sig = toSig[j];
|
|
217
|
+
if (seenTo.has(sig))
|
|
218
|
+
toAt.delete(sig);
|
|
219
|
+
else
|
|
220
|
+
toAt.set(sig, j);
|
|
221
|
+
seenTo.add(sig);
|
|
222
|
+
}
|
|
223
|
+
// In `to` order, each candidate carries its `from` position.
|
|
224
|
+
const candidates = [];
|
|
225
|
+
for (let j = ta; j < tb; j++) {
|
|
226
|
+
const i = fromAt.get(toSig[j]);
|
|
227
|
+
if (i !== undefined && toAt.get(toSig[j]) === j && toSig[j].replaceAll("\u0001", "").trim() !== "") {
|
|
228
|
+
candidates.push([i, j]);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const tails = [];
|
|
232
|
+
const previous = new Array(candidates.length).fill(-1);
|
|
233
|
+
for (let c = 0; c < candidates.length; c++) {
|
|
234
|
+
let lo = 0;
|
|
235
|
+
let hi = tails.length;
|
|
236
|
+
while (lo < hi) {
|
|
237
|
+
const mid = (lo + hi) >> 1;
|
|
238
|
+
if (candidates[tails[mid]][0] < candidates[c][0])
|
|
239
|
+
lo = mid + 1;
|
|
240
|
+
else
|
|
241
|
+
hi = mid;
|
|
242
|
+
}
|
|
243
|
+
if (lo > 0)
|
|
244
|
+
previous[c] = tails[lo - 1];
|
|
245
|
+
tails[lo] = c;
|
|
246
|
+
}
|
|
247
|
+
const chain = [];
|
|
248
|
+
for (let c = tails.length > 0 ? tails[tails.length - 1] : -1; c >= 0; c = previous[c])
|
|
249
|
+
chain.push(candidates[c]);
|
|
250
|
+
return chain.reverse();
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Carry `from`'s identities onto `to`, and report what changed.
|
|
254
|
+
*
|
|
255
|
+
* `to` is freshly tokenized and owns ids nobody has seen yet, so rewriting them
|
|
256
|
+
* in place is safe and is what makes the transition cheap: after this, the two
|
|
257
|
+
* structures share an id for every token that survived the edit.
|
|
258
|
+
*/
|
|
259
|
+
export function diffCode(from, to) {
|
|
260
|
+
const removedIds = new Set();
|
|
261
|
+
const addedIds = new Set();
|
|
262
|
+
const newLineIds = new Set();
|
|
263
|
+
const fromColorById = new Map();
|
|
264
|
+
const linePairs = alignLines(from, to);
|
|
265
|
+
const pairedTo = new Set();
|
|
266
|
+
const pairedFrom = new Set();
|
|
267
|
+
for (const [fi, ti] of linePairs) {
|
|
268
|
+
pairedFrom.add(fi);
|
|
269
|
+
pairedTo.add(ti);
|
|
270
|
+
const fromLine = from[fi];
|
|
271
|
+
const toLine = to[ti];
|
|
272
|
+
toLine.id = fromLine.id;
|
|
273
|
+
const matched = sameTokens(fromLine, toLine)
|
|
274
|
+
? fromLine.tokens.map((_, k) => [k, k])
|
|
275
|
+
: alignTokens(fromLine.tokens, toLine.tokens);
|
|
276
|
+
const keptFrom = new Set();
|
|
277
|
+
const keptTo = new Set();
|
|
278
|
+
for (const [a, b] of matched) {
|
|
279
|
+
keptFrom.add(a);
|
|
280
|
+
keptTo.add(b);
|
|
281
|
+
const oldTok = fromLine.tokens[a];
|
|
282
|
+
const newTok = toLine.tokens[b];
|
|
283
|
+
newTok.id = oldTok.id;
|
|
284
|
+
if (oldTok.color !== newTok.color)
|
|
285
|
+
fromColorById.set(oldTok.id, oldTok.color);
|
|
286
|
+
}
|
|
287
|
+
for (let a = 0; a < fromLine.tokens.length; a++) {
|
|
288
|
+
if (!keptFrom.has(a))
|
|
289
|
+
removedIds.add(fromLine.tokens[a].id);
|
|
290
|
+
}
|
|
291
|
+
for (let b = 0; b < toLine.tokens.length; b++) {
|
|
292
|
+
if (!keptTo.has(b))
|
|
293
|
+
addedIds.add(toLine.tokens[b].id);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
for (let i = 0; i < from.length; i++) {
|
|
297
|
+
if (pairedFrom.has(i))
|
|
298
|
+
continue;
|
|
299
|
+
for (const tok of from[i].tokens)
|
|
300
|
+
removedIds.add(tok.id);
|
|
301
|
+
}
|
|
302
|
+
for (let j = 0; j < to.length; j++) {
|
|
303
|
+
if (pairedTo.has(j))
|
|
304
|
+
continue;
|
|
305
|
+
newLineIds.add(to[j].id);
|
|
306
|
+
for (const tok of to[j].tokens)
|
|
307
|
+
addedIds.add(tok.id);
|
|
308
|
+
}
|
|
309
|
+
return { lines: to, removedIds, addedIds, newLineIds, fromColorById };
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=diff.js.map
|
package/dist/diff.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAoCA;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AACvC,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC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K,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;YAAE,SAAS;QAChC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM;YAAE,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACjC,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;YAAE,SAAS;QAC9B,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACzB,KAAK,MAAM,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM;YAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["import type { IdLine, IdToken } from \"./tokens\";\n\n/**\n * The result of diffing one listing structure against another: the *next*\n * structure, with token and line ids carried over from the previous one\n * wherever the content survived, plus the three sets a transition needs to know\n * which role each token plays.\n *\n * Identity is the whole product here. `const variable = 3` becoming\n * `const number = 3` should move `const` and `= 3` rather than dissolve and\n * rebuild them, and a token can only *move* if the frame after the edit still\n * knows it is the same token.\n */\n/**\n * How a `Code` node decides which token became which across an edit. Given\n * the old and new tokenized structures, return the carried-over structure\n * plus the added/removed/renamed-line bookkeeping a transition needs.\n * `diffCode` below is the default implementation (exported as\n * `defaultCodeDiff`) — pass a `diffStrategy` of this shape to `<Code>` to\n * replace it with your own.\n */\nexport type CodeDiffStrategy = (from: IdLine[], to: IdLine[]) => CodeEdit;\n\nexport interface CodeEdit {\n /** The new structure. Ids are rewritten in place onto the tokens handed in. */\n lines: IdLine[];\n /** Ids present only in the old structure — these fade out. */\n removedIds: Set<number>;\n /** Ids present only in the new structure — these fade in. */\n addedIds: Set<number>;\n /** Ids of {@link lines} that did not exist before — these enter as a whole row. */\n newLineIds: Set<number>;\n /** Previous colour of a surviving token whose highlighting changed, for the cross-fade. */\n fromColorById: Map<number, string | undefined>;\n}\n\n/**\n * How similar two lines must be before they are treated as *one line that was\n * edited* rather than as one line deleted and another inserted.\n *\n * Below this, a row's tokens have so little in common that carrying ids across\n * would animate glyphs sliding between unrelated words. Above it, the edit reads\n * the way it was made.\n */\nconst LINE_MATCH_FLOOR = 0.45;\n\n/**\n * The most line pairs one run of changed lines is scored against each other, and\n * the most across a whole edit.\n *\n * Scoring every pair is quadratic: with 50-character lines it took 31 ms at 200\n * lines and 741 ms at 1,000, paid again for each edit command when it is built.\n * So the lines are first paired where they cannot be in doubt (see\n * {@link alignLines}), and only a run left between two such anchors is scored.\n * A run past the first limit, or what is left of the second, is not compared: its\n * lines leave and enter as whole rows. That is the budget, and an edit that stays\n * inside it is diffed exactly as before.\n */\nexport const LINE_ALIGN_CELLS = 40_000;\nexport const EDIT_ALIGN_CELLS = 160_000;\n\n/** Weight a token carries when judging similarity: its visible characters. */\nfunction tokenWeight(tok: IdToken): number {\n return tok.content.trim().length;\n}\n\nfunction lineWeight(line: IdLine): number {\n let sum = 0;\n for (const tok of line.tokens) sum += tokenWeight(tok);\n return sum;\n}\n\n/**\n * Dice coefficient over the two lines' token multisets, weighted by visible\n * characters so `variable` counts for far more than a run of spaces.\n *\n * Two blank lines are identical (1); a blank line against a non-blank one shares\n * nothing (0), which keeps the blank rows a reformat introduces from anchoring\n * themselves onto real code.\n */\nfunction similarity(a: IdLine, b: IdLine): number {\n const wa = lineWeight(a);\n const wb = lineWeight(b);\n if (wa === 0 && wb === 0) return 1;\n if (wa === 0 || wb === 0) return 0;\n\n const bag = new Map<string, number>();\n for (const tok of a.tokens) {\n if (tokenWeight(tok) === 0) continue;\n bag.set(tok.content, (bag.get(tok.content) ?? 0) + 1);\n }\n let common = 0;\n for (const tok of b.tokens) {\n const w = tokenWeight(tok);\n if (w === 0) continue;\n const left = bag.get(tok.content) ?? 0;\n if (left > 0) {\n bag.set(tok.content, left - 1);\n common += w;\n }\n }\n return (2 * common) / (wa + wb);\n}\n\n/**\n * Align two sequences by maximising total `score`, skipping is free.\n *\n * A plain LCS would only ever pair *identical* elements, which is the wrong tool\n * twice over: two lines that differ by one word are the same line, and two\n * tokens that differ only in colour are the same token. Scoring the pairing and\n * letting anything that scores ≤ 0 fall out expresses that directly, and because\n * skips cost nothing the alignment stays in order.\n *\n * Returns the matched index pairs, in order.\n */\nfunction align(\n aLength: number,\n bLength: number,\n score: (i: number, j: number) => number,\n): Array<[number, number]> {\n // dp[i][j] = best score aligning a[0..i) with b[0..j).\n const width = bLength + 1;\n const dp = new Float64Array((aLength + 1) * width);\n const pairScore = new Float64Array(aLength * bLength);\n\n for (let i = 1; i <= aLength; i++) {\n for (let j = 1; j <= bLength; j++) {\n const s = score(i - 1, j - 1);\n pairScore[(i - 1) * bLength + (j - 1)] = s;\n const skipA = dp[(i - 1) * width + j];\n const skipB = dp[i * width + (j - 1)];\n let best = skipA > skipB ? skipA : skipB;\n if (s > 0) {\n const paired = dp[(i - 1) * width + (j - 1)] + s;\n if (paired > best) best = paired;\n }\n dp[i * width + j] = best;\n }\n }\n\n const pairs: Array<[number, number]> = [];\n let i = aLength;\n let j = bLength;\n while (i > 0 && j > 0) {\n const s = pairScore[(i - 1) * bLength + (j - 1)];\n if (s > 0 && dp[i * width + j] === dp[(i - 1) * width + (j - 1)] + s) {\n pairs.push([i - 1, j - 1]);\n i--; j--;\n } else if (dp[(i - 1) * width + j] >= dp[i * width + (j - 1)]) {\n i--;\n } else {\n j--;\n }\n }\n pairs.reverse();\n return pairs;\n}\n\n/**\n * Match the tokens of one line against another's.\n *\n * Scored by visible characters rather than token count, so an alignment that\n * keeps `items.reduce` together beats one that keeps four more spaces. A token\n * pairs only when its content is unchanged — a changed word is a different word,\n * and should be seen to be replaced.\n */\nfunction alignTokens(from: IdToken[], to: IdToken[]): Array<[number, number]> {\n return align(from.length, to.length, (i, j) => {\n if (from[i].content !== to[j].content) return 0;\n // Whitespace still pairs (it holds indentation together), just weakly\n // enough that it never outranks real content.\n return tokenWeight(to[j]) || 0.25;\n });\n}\n\nfunction sameTokens(a: IdLine, b: IdLine): boolean {\n if (a.tokens.length !== b.tokens.length) return false;\n for (let k = 0; k < a.tokens.length; k++) if (a.tokens[k].content !== b.tokens[k].content) return false;\n return true;\n}\n\n/** A line's text, token boundaries included, for telling identical lines apart from similar ones. */\nfunction signature(line: IdLine): string {\n let out = \"\";\n for (const tok of line.tokens) out += tok.content + \"\\u0001\";\n return out;\n}\n\n/**\n * Pair the lines of two listings, in order.\n *\n * Lines that are the same at the start and at the end are paired outright. In\n * what is left, a line that occurs exactly once on each side is an anchor, and\n * the longest run of anchors that keeps their order splits the rest into runs of\n * changed lines, each scored against itself within the budget (see\n * {@link LINE_ALIGN_CELLS}). A one-line edit to a long listing therefore never\n * builds a table bigger than the lines around it.\n */\nfunction alignLines(from: IdLine[], to: IdLine[]): Array<[number, number]> {\n const fromSig = from.map(signature);\n const toSig = to.map(signature);\n const pairs: Array<[number, number]> = [];\n\n let head = 0;\n while (head < from.length && head < to.length && fromSig[head] === toSig[head]) {\n pairs.push([head, head]);\n head++;\n }\n let tail = 0;\n while (\n tail < from.length - head && tail < to.length - head\n && fromSig[from.length - 1 - tail] === toSig[to.length - 1 - tail]\n ) tail++;\n\n const anchors = anchorLines(fromSig, toSig, head, from.length - tail, head, to.length - tail);\n let budget = EDIT_ALIGN_CELLS;\n let fi = head;\n let ti = head;\n for (const [af, at] of [...anchors, [from.length - tail, to.length - tail] as [number, number]]) {\n const rows = af - fi;\n const cols = at - ti;\n const cells = rows * cols;\n if (cells > 0 && cells <= LINE_ALIGN_CELLS && cells <= budget) {\n budget -= cells;\n for (const [i, j] of align(rows, cols, (a, b) => similarity(from[fi + a], to[ti + b]) - LINE_MATCH_FLOOR)) {\n pairs.push([fi + i, ti + j]);\n }\n }\n if (af < from.length - tail) pairs.push([af, at]);\n fi = af + 1;\n ti = at + 1;\n }\n for (let k = tail; k > 0; k--) pairs.push([from.length - k, to.length - k]);\n return pairs;\n}\n\n/**\n * The lines that occur once in `from[fa, fb)` and once in `to[ta, tb)`, reduced to\n * the longest subsequence that is increasing on both sides (patience sorting).\n * Blank lines are never anchors: they say nothing about where they belong.\n */\nfunction anchorLines(\n fromSig: string[],\n toSig: string[],\n fa: number,\n fb: number,\n ta: number,\n tb: number,\n): Array<[number, number]> {\n const fromAt = new Map<string, number>();\n const seen = new Set<string>();\n for (let i = fa; i < fb; i++) {\n const sig = fromSig[i];\n if (seen.has(sig)) fromAt.delete(sig);\n else fromAt.set(sig, i);\n seen.add(sig);\n }\n const toAt = new Map<string, number>();\n const seenTo = new Set<string>();\n for (let j = ta; j < tb; j++) {\n const sig = toSig[j];\n if (seenTo.has(sig)) toAt.delete(sig);\n else toAt.set(sig, j);\n seenTo.add(sig);\n }\n\n // In `to` order, each candidate carries its `from` position.\n const candidates: Array<[number, number]> = [];\n for (let j = ta; j < tb; j++) {\n const i = fromAt.get(toSig[j]);\n if (i !== undefined && toAt.get(toSig[j]) === j && toSig[j].replaceAll(\"\\u0001\", \"\").trim() !== \"\") {\n candidates.push([i, j]);\n }\n }\n\n const tails: number[] = [];\n const previous: number[] = new Array(candidates.length).fill(-1);\n for (let c = 0; c < candidates.length; c++) {\n let lo = 0;\n let hi = tails.length;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (candidates[tails[mid]][0] < candidates[c][0]) lo = mid + 1;\n else hi = mid;\n }\n if (lo > 0) previous[c] = tails[lo - 1];\n tails[lo] = c;\n }\n const chain: Array<[number, number]> = [];\n for (let c = tails.length > 0 ? tails[tails.length - 1] : -1; c >= 0; c = previous[c]) chain.push(candidates[c]);\n return chain.reverse();\n}\n\n/**\n * Carry `from`'s identities onto `to`, and report what changed.\n *\n * `to` is freshly tokenized and owns ids nobody has seen yet, so rewriting them\n * in place is safe and is what makes the transition cheap: after this, the two\n * structures share an id for every token that survived the edit.\n */\nexport function diffCode(from: IdLine[], to: IdLine[]): CodeEdit {\n const removedIds = new Set<number>();\n const addedIds = new Set<number>();\n const newLineIds = new Set<number>();\n const fromColorById = new Map<number, string | undefined>();\n\n const linePairs = alignLines(from, to);\n\n const pairedTo = new Set<number>();\n const pairedFrom = new Set<number>();\n\n for (const [fi, ti] of linePairs) {\n pairedFrom.add(fi);\n pairedTo.add(ti);\n const fromLine = from[fi];\n const toLine = to[ti];\n toLine.id = fromLine.id;\n\n const matched = sameTokens(fromLine, toLine)\n ? fromLine.tokens.map((_, k): [number, number] => [k, k])\n : alignTokens(fromLine.tokens, toLine.tokens);\n const keptFrom = new Set<number>();\n const keptTo = new Set<number>();\n for (const [a, b] of matched) {\n keptFrom.add(a);\n keptTo.add(b);\n const oldTok = fromLine.tokens[a];\n const newTok = toLine.tokens[b];\n newTok.id = oldTok.id;\n if (oldTok.color !== newTok.color) fromColorById.set(oldTok.id, oldTok.color);\n }\n for (let a = 0; a < fromLine.tokens.length; a++) {\n if (!keptFrom.has(a)) removedIds.add(fromLine.tokens[a].id);\n }\n for (let b = 0; b < toLine.tokens.length; b++) {\n if (!keptTo.has(b)) addedIds.add(toLine.tokens[b].id);\n }\n }\n\n for (let i = 0; i < from.length; i++) {\n if (pairedFrom.has(i)) continue;\n for (const tok of from[i].tokens) removedIds.add(tok.id);\n }\n for (let j = 0; j < to.length; j++) {\n if (pairedTo.has(j)) continue;\n newLineIds.add(to[j].id);\n for (const tok of to[j].tokens) addedIds.add(tok.id);\n }\n\n return { lines: to, removedIds, addedIds, newLineIds, fromColorById };\n}\n"]}
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './transitions.js';
|
|
2
|
+
export * from './layout.js';
|
|
3
|
+
export { drawCode } from './render.js';
|
|
4
|
+
export type { CodeCanvas, DrawCodeState } from './render.js';
|
|
5
|
+
export { diffCode as defaultCodeDiff } from './diff.js';
|
|
6
|
+
export type { CodeDiffStrategy, CodeEdit } from './diff.js';
|
|
7
|
+
export { loadCodeLanguage, initSyntaxHighlighter, ensureHighlighter, registerCodeTheme, resolveTheme, canHighlight, normalizeSource } from './highlight.js';
|
|
8
|
+
export { tokenizeCodeToIdLines } from './tokens.js';
|
|
9
|
+
export type { IdLine, IdToken } from './tokens.js';
|
|
10
|
+
export { DefaultHighlightStyle, GithubDarkStyle, GithubLightStyle, VscodeDarkStyle, VscodeLightStyle, BUILTIN_THEMES, compileStyle } from './style.js';
|
|
11
|
+
export type { CodeHighlightStyle, CodeStyleRule, CodeTheme, CodeThemeName } from './style.js';
|
|
12
|
+
export { TokenAdvanceCache } from './measure-cache.js';
|
|
13
|
+
export { word, lines, rangeToCharOffsets, charOffsetsToRange, CodeRanges, CodeRangeChain } from './code-range.js';
|
|
14
|
+
export type { CodeRange } from './code-range.js';
|
|
15
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAOA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,QAAQ,CAAC;AACrD,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzJ,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACpJ,YAAY,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/G,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The Code "engine": syntax highlighting, tokenizing, layout, diffing, and
|
|
2
|
+
// transition/phase scheduling — kept separate from node.ts so a copy of the node
|
|
3
|
+
// can take just its declaration and import this behind
|
|
4
|
+
// `@motionscript/code` instead. What gets copied is whatever this
|
|
5
|
+
// package's registry.json declares, which for this component is node.ts;
|
|
6
|
+
// src/tests/registry.test.ts checks that anything it
|
|
7
|
+
// reaches for is either copied alongside it or re-exported from here.
|
|
8
|
+
export * from './transitions.js';
|
|
9
|
+
export * from './layout.js';
|
|
10
|
+
export { drawCode } from './render.js';
|
|
11
|
+
export { diffCode as defaultCodeDiff } from './diff.js';
|
|
12
|
+
export { loadCodeLanguage, initSyntaxHighlighter, ensureHighlighter, registerCodeTheme, resolveTheme, canHighlight, normalizeSource } from './highlight.js';
|
|
13
|
+
export { tokenizeCodeToIdLines } from './tokens.js';
|
|
14
|
+
export { DefaultHighlightStyle, GithubDarkStyle, GithubLightStyle, VscodeDarkStyle, VscodeLightStyle, BUILTIN_THEMES, compileStyle } from './style.js';
|
|
15
|
+
export { TokenAdvanceCache } from './measure-cache.js';
|
|
16
|
+
export { word, lines, rangeToCharOffsets, charOffsetsToRange, CodeRanges, CodeRangeChain } from './code-range.js';
|
|
17
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,iFAAiF;AACjF,uDAAuD;AACvD,kEAAkE;AAClE,yEAAyE;AACzE,qDAAqD;AACrD,sEAAsE;AACtE,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,QAAQ,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzJ,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEpJ,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC","sourcesContent":["// The Code \"engine\": syntax highlighting, tokenizing, layout, diffing, and\n// transition/phase scheduling — kept separate from node.ts so a copy of the node\n// can take just its declaration and import this behind\n// `@motionscript/code` instead. What gets copied is whatever this\n// package's registry.json declares, which for this component is node.ts;\n// src/tests/registry.test.ts checks that anything it\n// reaches for is either copied alongside it or re-exported from here.\nexport * from './transitions';\nexport * from './layout';\nexport { drawCode } from './render';\nexport type { CodeCanvas, DrawCodeState } from './render';\nexport { diffCode as defaultCodeDiff } from './diff';\nexport type { CodeDiffStrategy, CodeEdit } from './diff';\nexport { loadCodeLanguage, initSyntaxHighlighter, ensureHighlighter, registerCodeTheme, resolveTheme, canHighlight, normalizeSource } from './highlight';\nexport { tokenizeCodeToIdLines } from './tokens';\nexport type { IdLine, IdToken } from './tokens';\nexport { DefaultHighlightStyle, GithubDarkStyle, GithubLightStyle, VscodeDarkStyle, VscodeLightStyle, BUILTIN_THEMES, compileStyle } from './style';\nexport type { CodeHighlightStyle, CodeStyleRule, CodeTheme, CodeThemeName } from './style';\nexport { TokenAdvanceCache } from './measure-cache';\nexport { word, lines, rangeToCharOffsets, charOffsetsToRange, CodeRanges, CodeRangeChain } from './code-range';\nexport type { CodeRange } from './code-range';\n"]}
|