@motionscript/code 0.0.0-stage → 0.1.0-alpha.0
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 +5 -0
- package/LICENSE +201 -0
- package/README.md +76 -3
- 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 +8 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/manifest.json +11 -0
- package/dist/code-range.d.ts +69 -0
- package/dist/code-range.d.ts.map +1 -0
- package/dist/code-range.js +124 -0
- package/dist/code-range.js.map +1 -0
- package/dist/diff.d.ts +42 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +179 -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 +43 -0
- package/dist/highlight.d.ts.map +1 -0
- package/dist/highlight.js +243 -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 +293 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +733 -0
- package/dist/node.js.map +1 -0
- package/dist/nodes.d.ts +18 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +18 -0
- package/dist/nodes.js.map +1 -0
- package/dist/render.d.ts +28 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +223 -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 +203 -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 +50 -0
- package/dist/tokens.js.map +1 -0
- package/dist/transitions.d.ts +115 -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 +82 -3
- package/registry.json +6 -0
- package/src/code-range.ts +156 -0
- package/src/diff.ts +216 -0
- package/src/engine.ts +21 -0
- package/src/highlight.ts +291 -0
- package/src/index.ts +3 -0
- package/src/layout.ts +157 -0
- package/src/measure-cache.ts +0 -0
- package/src/node.ts +834 -0
- package/src/nodes.ts +18 -0
- package/src/render.ts +247 -0
- package/src/style.ts +251 -0
- package/src/tokens.ts +75 -0
- package/src/transitions.ts +184 -0
package/dist/style.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { tagHighlighter, tags as t } from "@lezer/highlight";
|
|
2
|
+
/**
|
|
3
|
+
* Motion Canvas's default highlight palette (a Nord-derived theme), ported from
|
|
4
|
+
* `@motion-canvas/2d`'s DefaultHighlightStyle so highlighting matches Motion
|
|
5
|
+
* Canvas token-for-token. Colors and tag groupings are kept identical; only the
|
|
6
|
+
* shape changes (color strings in place of CSS rules).
|
|
7
|
+
*/
|
|
8
|
+
export const DefaultHighlightStyle = {
|
|
9
|
+
name: "motion-canvas-default",
|
|
10
|
+
defaultColor: "#d8dee9",
|
|
11
|
+
rules: [
|
|
12
|
+
{ tag: t.keyword, color: "#5e81ac" },
|
|
13
|
+
{ tag: [t.name, t.deleted, t.character, t.propertyName, t.macroName], color: "#88c0d0" },
|
|
14
|
+
{ tag: [t.variableName], color: "#8fbcbb" },
|
|
15
|
+
{ tag: [t.function(t.variableName)], color: "#8fbcbb" },
|
|
16
|
+
{ tag: [t.labelName], color: "#81a1c1" },
|
|
17
|
+
{ tag: [t.color, t.constant(t.name), t.standard(t.name)], color: "#5e81ac" },
|
|
18
|
+
{ tag: [t.definition(t.name), t.separator], color: "#a3be8c" },
|
|
19
|
+
{ tag: [t.brace], color: "#8fbcbb" },
|
|
20
|
+
{ tag: [t.annotation], color: "#d30102" },
|
|
21
|
+
{ tag: [t.number, t.changed, t.annotation, t.modifier, t.self, t.namespace], color: "#b48ead" },
|
|
22
|
+
{ tag: [t.typeName, t.className], color: "#ECEFF4" },
|
|
23
|
+
{ tag: [t.operator, t.operatorKeyword], color: "#a3be8c" },
|
|
24
|
+
{ tag: [t.tagName], color: "#b48ead" },
|
|
25
|
+
{ tag: [t.squareBracket], color: "#ECEFF4" },
|
|
26
|
+
{ tag: [t.angleBracket], color: "#ECEFF4" },
|
|
27
|
+
{ tag: [t.attributeName], color: "#eceff4" },
|
|
28
|
+
{ tag: [t.regexp], color: "#5e81ac" },
|
|
29
|
+
{ tag: [t.quote], color: "#b48ead" },
|
|
30
|
+
{ tag: [t.string], color: "#a3be8c" },
|
|
31
|
+
{ tag: t.link, color: "#a3be8c" },
|
|
32
|
+
{ tag: [t.url, t.escape, t.special(t.string)], color: "#8fbcbb" },
|
|
33
|
+
{ tag: [t.meta], color: "#88c0d0" },
|
|
34
|
+
{ tag: [t.monospace], color: "#d8dee9" },
|
|
35
|
+
{ tag: [t.comment], color: "#4c566a" },
|
|
36
|
+
{ tag: t.strong, color: "#5e81ac" },
|
|
37
|
+
{ tag: t.emphasis, color: "#5e81ac" },
|
|
38
|
+
{ tag: t.heading, color: "#5e81ac" },
|
|
39
|
+
{ tag: t.special(t.heading1), color: "#5e81ac" },
|
|
40
|
+
{ tag: t.heading1, color: "#5e81ac" },
|
|
41
|
+
{ tag: [t.heading2, t.heading3, t.heading4], color: "#5e81ac" },
|
|
42
|
+
{ tag: [t.heading5, t.heading6], color: "#5e81ac" },
|
|
43
|
+
{ tag: [t.atom, t.bool, t.special(t.variableName)], color: "#d08770" },
|
|
44
|
+
{ tag: [t.processingInstruction, t.inserted], color: "#8fbcbb" },
|
|
45
|
+
{ tag: [t.contentSeparator], color: "#ebcb8b" },
|
|
46
|
+
{ tag: t.invalid, color: "#434c5e" },
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* GitHub Dark highlight palette, adapted from `@uiw/codemirror-theme-github`.
|
|
51
|
+
* `defaultColor` is GitHub's editor foreground (`#c9d1d9`), used for any text the
|
|
52
|
+
* parser tags don't cover. DOM-only style props (backgroundColor, textDecoration,
|
|
53
|
+
* fontWeight, fontStyle) are dropped — we only color tokens on the canvas.
|
|
54
|
+
*/
|
|
55
|
+
export const GithubDarkStyle = {
|
|
56
|
+
name: "github-dark",
|
|
57
|
+
defaultColor: "#c9d1d9",
|
|
58
|
+
rules: [
|
|
59
|
+
{ tag: [t.standard(t.tagName), t.tagName], color: "#7ee787" },
|
|
60
|
+
{ tag: [t.comment, t.bracket], color: "#8b949e" },
|
|
61
|
+
{ tag: [t.className, t.propertyName], color: "#d2a8ff" },
|
|
62
|
+
{ tag: [t.variableName, t.attributeName, t.number, t.operator], color: "#79c0ff" },
|
|
63
|
+
{ tag: [t.keyword, t.typeName, t.typeOperator], color: "#ff7b72" },
|
|
64
|
+
{ tag: [t.string, t.meta, t.regexp], color: "#a5d6ff" },
|
|
65
|
+
{ tag: [t.name, t.quote], color: "#7ee787" },
|
|
66
|
+
{ tag: [t.heading, t.strong], color: "#d2a8ff" },
|
|
67
|
+
{ tag: [t.emphasis], color: "#d2a8ff" },
|
|
68
|
+
{ tag: [t.deleted], color: "#ffdcd7" },
|
|
69
|
+
{ tag: [t.atom, t.bool, t.special(t.variableName)], color: "#ffab70" },
|
|
70
|
+
{ tag: t.invalid, color: "#f97583" },
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* GitHub Light highlight palette, adapted from `@uiw/codemirror-theme-github`.
|
|
75
|
+
* `defaultColor` is GitHub's editor foreground (`#24292e`). See {@link GithubDarkStyle}
|
|
76
|
+
* for the note on dropped DOM-only style props.
|
|
77
|
+
*/
|
|
78
|
+
export const GithubLightStyle = {
|
|
79
|
+
name: "github-light",
|
|
80
|
+
defaultColor: "#24292e",
|
|
81
|
+
rules: [
|
|
82
|
+
{ tag: [t.standard(t.tagName), t.tagName], color: "#116329" },
|
|
83
|
+
{ tag: [t.comment, t.bracket], color: "#6a737d" },
|
|
84
|
+
{ tag: [t.className, t.propertyName], color: "#6f42c1" },
|
|
85
|
+
{ tag: [t.variableName, t.attributeName, t.number, t.operator], color: "#005cc5" },
|
|
86
|
+
{ tag: [t.keyword, t.typeName, t.typeOperator], color: "#d73a49" },
|
|
87
|
+
{ tag: [t.string, t.meta, t.regexp], color: "#032f62" },
|
|
88
|
+
{ tag: [t.name, t.quote], color: "#22863a" },
|
|
89
|
+
{ tag: [t.heading, t.strong], color: "#24292e" },
|
|
90
|
+
{ tag: [t.emphasis], color: "#24292e" },
|
|
91
|
+
{ tag: [t.deleted], color: "#b31d28" },
|
|
92
|
+
{ tag: [t.atom, t.bool, t.special(t.variableName)], color: "#e36209" },
|
|
93
|
+
{ tag: [t.url, t.escape, t.regexp, t.link], color: "#032f62" },
|
|
94
|
+
{ tag: t.invalid, color: "#cb2431" },
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* VS Code Dark+ highlight palette, adapted from the `@uiw/codemirror-theme-vscode`
|
|
99
|
+
* snippet. `defaultColor` is VS Code's editor foreground (`#9cdcfe`). DOM-only
|
|
100
|
+
* style props are dropped; later rules win, matching {@link tagHighlighter}.
|
|
101
|
+
*/
|
|
102
|
+
export const VscodeDarkStyle = {
|
|
103
|
+
name: "vscode-dark",
|
|
104
|
+
defaultColor: "#9cdcfe",
|
|
105
|
+
rules: [
|
|
106
|
+
{
|
|
107
|
+
tag: [
|
|
108
|
+
t.keyword, t.operatorKeyword, t.modifier, t.color,
|
|
109
|
+
t.constant(t.name), t.standard(t.name), t.standard(t.tagName),
|
|
110
|
+
t.special(t.brace), t.atom, t.bool, t.special(t.variableName),
|
|
111
|
+
],
|
|
112
|
+
color: "#569cd6",
|
|
113
|
+
},
|
|
114
|
+
{ tag: [t.controlKeyword, t.moduleKeyword], color: "#c586c0" },
|
|
115
|
+
{
|
|
116
|
+
tag: [
|
|
117
|
+
t.name, t.deleted, t.character, t.macroName, t.propertyName,
|
|
118
|
+
t.variableName, t.labelName, t.definition(t.name),
|
|
119
|
+
],
|
|
120
|
+
color: "#9cdcfe",
|
|
121
|
+
},
|
|
122
|
+
{ tag: t.heading, color: "#9cdcfe" },
|
|
123
|
+
{ tag: [t.typeName, t.className, t.tagName, t.changed, t.annotation, t.self, t.namespace], color: "#4ec9b0" },
|
|
124
|
+
{ tag: [t.function(t.variableName), t.function(t.propertyName)], color: "#dcdcaa" },
|
|
125
|
+
{ tag: [t.number], color: "#b5cea8" },
|
|
126
|
+
{ tag: [t.operator, t.punctuation, t.separator, t.url, t.escape], color: "#d4d4d4" },
|
|
127
|
+
{ tag: [t.regexp], color: "#d16969" },
|
|
128
|
+
{ tag: [t.special(t.string), t.processingInstruction, t.string, t.inserted], color: "#ce9178" },
|
|
129
|
+
{ tag: [t.angleBracket], color: "#808080" },
|
|
130
|
+
{ tag: [t.meta, t.comment], color: "#6a9955" },
|
|
131
|
+
{ tag: t.link, color: "#6a9955" },
|
|
132
|
+
{ tag: t.invalid, color: "#ff0000" },
|
|
133
|
+
],
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* VS Code Light+ highlight palette, adapted from the `@uiw/codemirror-theme-vscode`
|
|
137
|
+
* snippet. `defaultColor` is VS Code's editor foreground (`#383a42`). See
|
|
138
|
+
* {@link VscodeDarkStyle} for the note on dropped DOM-only style props.
|
|
139
|
+
*/
|
|
140
|
+
export const VscodeLightStyle = {
|
|
141
|
+
name: "vscode-light",
|
|
142
|
+
defaultColor: "#383a42",
|
|
143
|
+
rules: [
|
|
144
|
+
{
|
|
145
|
+
tag: [
|
|
146
|
+
t.keyword, t.operatorKeyword, t.modifier, t.color,
|
|
147
|
+
t.constant(t.name), t.standard(t.name), t.standard(t.tagName),
|
|
148
|
+
t.special(t.brace), t.atom, t.bool, t.special(t.variableName),
|
|
149
|
+
],
|
|
150
|
+
color: "#0000ff",
|
|
151
|
+
},
|
|
152
|
+
{ tag: [t.moduleKeyword, t.controlKeyword], color: "#af00db" },
|
|
153
|
+
{
|
|
154
|
+
tag: [
|
|
155
|
+
t.name, t.deleted, t.character, t.macroName, t.propertyName,
|
|
156
|
+
t.variableName, t.labelName, t.definition(t.name),
|
|
157
|
+
],
|
|
158
|
+
color: "#0070c1",
|
|
159
|
+
},
|
|
160
|
+
{ tag: t.heading, color: "#0070c1" },
|
|
161
|
+
{ tag: [t.typeName, t.className, t.tagName, t.changed, t.annotation, t.self, t.namespace], color: "#267f99" },
|
|
162
|
+
{ tag: [t.function(t.variableName), t.function(t.propertyName)], color: "#795e26" },
|
|
163
|
+
{ tag: [t.number], color: "#098658" },
|
|
164
|
+
{ tag: [t.operator, t.punctuation, t.separator, t.url, t.escape], color: "#383a42" },
|
|
165
|
+
{ tag: [t.regexp], color: "#af00db" },
|
|
166
|
+
{ tag: [t.special(t.string), t.processingInstruction, t.string, t.inserted], color: "#a31515" },
|
|
167
|
+
{ tag: [t.angleBracket], color: "#383a42" },
|
|
168
|
+
{ tag: [t.meta, t.comment], color: "#008000" },
|
|
169
|
+
{ tag: t.link, color: "#4078f2" },
|
|
170
|
+
{ tag: t.invalid, color: "#e45649" },
|
|
171
|
+
],
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* The built-in themes, keyed by their string name. {@link CodeThemeName} is the
|
|
175
|
+
* union of these keys — pass one of those strings (or any {@link CodeHighlightStyle}
|
|
176
|
+
* object) to a Code node's `theme` prop.
|
|
177
|
+
*/
|
|
178
|
+
export const BUILTIN_THEMES = {
|
|
179
|
+
// Literal keys (not computed from `.name`) so `keyof` yields a string-literal
|
|
180
|
+
// union for CodeThemeName; these must stay in sync with each style's `name`.
|
|
181
|
+
"motion-canvas-default": DefaultHighlightStyle,
|
|
182
|
+
"github-dark": GithubDarkStyle,
|
|
183
|
+
"github-light": GithubLightStyle,
|
|
184
|
+
"vscode-dark": VscodeDarkStyle,
|
|
185
|
+
"vscode-light": VscodeLightStyle,
|
|
186
|
+
};
|
|
187
|
+
// Cache one compiled Highlighter per style name. Compiling builds a tag-rule
|
|
188
|
+
// matcher; the parsed result is pure data so it's safe to share across Code nodes.
|
|
189
|
+
const compiledByName = new Map();
|
|
190
|
+
/**
|
|
191
|
+
* Compile a {@link CodeHighlightStyle} into a `@lezer/highlight` {@link Highlighter}
|
|
192
|
+
* whose "class" output is the literal color string for each tag. Cached by style
|
|
193
|
+
* name so repeated lookups (every tokenize) don't rebuild the matcher.
|
|
194
|
+
*/
|
|
195
|
+
export function compileStyle(style) {
|
|
196
|
+
const cached = compiledByName.get(style.name);
|
|
197
|
+
if (cached)
|
|
198
|
+
return cached;
|
|
199
|
+
const highlighter = tagHighlighter(style.rules.map(rule => ({ tag: rule.tag, class: rule.color })));
|
|
200
|
+
compiledByName.set(style.name, highlighter);
|
|
201
|
+
return highlighter;
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.js","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,cAAc,EAAE,IAAI,IAAI,CAAC,EAAE,MAAM,kBAAkB,CAAC;AA+B/E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAuB;IACrD,IAAI,EAAE,uBAAuB;IAC7B,YAAY,EAAE,SAAS;IACvB,KAAK,EAAE;QACH,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE;QACpC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE;QACxF,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,EA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AC,OAAO,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE;QAC9C,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE;QACjC,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE;KACvC;CACJ,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC1B,8EAA8E;IAC9E,6EAA6E;IAC7E,uBAAuB,EAAE,qBAAqB;IAC9C,aAAa,EAAE,eAAe;IAC9B,cAAc,EAAE,gBAAgB;IAChC,aAAa,EAAE,eAAe;IAC9B,cAAc,EAAE,gBAAgB;CACU,CAAC;AAa/C,6EAA6E;AAC7E,mFAAmF;AACnF,MAAM,cAAc,GAAG,IAAI,GAAG,EAAuB,CAAC;AAEtD;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,KAAyB;IAClD,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAC1B,MAAM,WAAW,GAAG,cAAc,CAC9B,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAClE,CAAC;IACF,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAC5C,OAAO,WAAW,CAAC;AACvB,CAAC","sourcesContent":["import { Highlighter, Tag, tagHighlighter, tags as t } from \"@lezer/highlight\";\n\n/**\n * A single style rule: map one or more Lezer highlight {@link Tag}s to a color.\n * This mirrors a `@codemirror/language` HighlightStyle entry, but instead of\n * emitting CSS class names it carries the color directly — we render to a canvas,\n * not the DOM, so there is no stylesheet to resolve against.\n */\nexport interface CodeStyleRule {\n tag: Tag | readonly Tag[];\n color: string;\n}\n\n/**\n * A code theme: an ordered list of tag→color rules plus a fallback color for any\n * text the parser produces no highlight tag for (operators, punctuation, plain\n * identifiers in some grammars, etc.). Pass a custom one via the Code node's\n * `theme` prop to recolor highlighting without touching the highlighter wiring.\n *\n * @remarks\n * Later rules win when several match the same tag, matching how\n * `@lezer/highlight`'s {@link tagHighlighter} resolves precedence.\n */\nexport interface CodeHighlightStyle {\n /** Stable name, used as the highlighter cache key. */\n name: string;\n /** Color applied to text with no matching tag. */\n defaultColor: string;\n rules: CodeStyleRule[];\n}\n\n/**\n * Motion Canvas's default highlight palette (a Nord-derived theme), ported from\n * `@motion-canvas/2d`'s DefaultHighlightStyle so highlighting matches Motion\n * Canvas token-for-token. Colors and tag groupings are kept identical; only the\n * shape changes (color strings in place of CSS rules).\n */\nexport const DefaultHighlightStyle: CodeHighlightStyle = {\n name: \"motion-canvas-default\",\n defaultColor: \"#d8dee9\",\n rules: [\n { tag: t.keyword, color: \"#5e81ac\" },\n { tag: [t.name, t.deleted, t.character, t.propertyName, t.macroName], color: \"#88c0d0\" },\n { tag: [t.variableName], color: \"#8fbcbb\" },\n { tag: [t.function(t.variableName)], color: \"#8fbcbb\" },\n { tag: [t.labelName], color: \"#81a1c1\" },\n { tag: [t.color, t.constant(t.name), t.standard(t.name)], color: \"#5e81ac\" },\n { tag: [t.definition(t.name), t.separator], color: \"#a3be8c\" },\n { tag: [t.brace], color: \"#8fbcbb\" },\n { tag: [t.annotation], color: \"#d30102\" },\n { tag: [t.number, t.changed, t.annotation, t.modifier, t.self, t.namespace], color: \"#b48ead\" },\n { tag: [t.typeName, t.className], color: \"#ECEFF4\" },\n { tag: [t.operator, t.operatorKeyword], color: \"#a3be8c\" },\n { tag: [t.tagName], color: \"#b48ead\" },\n { tag: [t.squareBracket], color: \"#ECEFF4\" },\n { tag: [t.angleBracket], color: \"#ECEFF4\" },\n { tag: [t.attributeName], color: \"#eceff4\" },\n { tag: [t.regexp], color: \"#5e81ac\" },\n { tag: [t.quote], color: \"#b48ead\" },\n { tag: [t.string], color: \"#a3be8c\" },\n { tag: t.link, color: \"#a3be8c\" },\n { tag: [t.url, t.escape, t.special(t.string)], color: \"#8fbcbb\" },\n { tag: [t.meta], color: \"#88c0d0\" },\n { tag: [t.monospace], color: \"#d8dee9\" },\n { tag: [t.comment], color: \"#4c566a\" },\n { tag: t.strong, color: \"#5e81ac\" },\n { tag: t.emphasis, color: \"#5e81ac\" },\n { tag: t.heading, color: \"#5e81ac\" },\n { tag: t.special(t.heading1), color: \"#5e81ac\" },\n { tag: t.heading1, color: \"#5e81ac\" },\n { tag: [t.heading2, t.heading3, t.heading4], color: \"#5e81ac\" },\n { tag: [t.heading5, t.heading6], color: \"#5e81ac\" },\n { tag: [t.atom, t.bool, t.special(t.variableName)], color: \"#d08770\" },\n { tag: [t.processingInstruction, t.inserted], color: \"#8fbcbb\" },\n { tag: [t.contentSeparator], color: \"#ebcb8b\" },\n { tag: t.invalid, color: \"#434c5e\" },\n ],\n};\n\n/**\n * GitHub Dark highlight palette, adapted from `@uiw/codemirror-theme-github`.\n * `defaultColor` is GitHub's editor foreground (`#c9d1d9`), used for any text the\n * parser tags don't cover. DOM-only style props (backgroundColor, textDecoration,\n * fontWeight, fontStyle) are dropped — we only color tokens on the canvas.\n */\nexport const GithubDarkStyle: CodeHighlightStyle = {\n name: \"github-dark\",\n defaultColor: \"#c9d1d9\",\n rules: [\n { tag: [t.standard(t.tagName), t.tagName], color: \"#7ee787\" },\n { tag: [t.comment, t.bracket], color: \"#8b949e\" },\n { tag: [t.className, t.propertyName], color: \"#d2a8ff\" },\n { tag: [t.variableName, t.attributeName, t.number, t.operator], color: \"#79c0ff\" },\n { tag: [t.keyword, t.typeName, t.typeOperator], color: \"#ff7b72\" },\n { tag: [t.string, t.meta, t.regexp], color: \"#a5d6ff\" },\n { tag: [t.name, t.quote], color: \"#7ee787\" },\n { tag: [t.heading, t.strong], color: \"#d2a8ff\" },\n { tag: [t.emphasis], color: \"#d2a8ff\" },\n { tag: [t.deleted], color: \"#ffdcd7\" },\n { tag: [t.atom, t.bool, t.special(t.variableName)], color: \"#ffab70\" },\n { tag: t.invalid, color: \"#f97583\" },\n ],\n};\n\n/**\n * GitHub Light highlight palette, adapted from `@uiw/codemirror-theme-github`.\n * `defaultColor` is GitHub's editor foreground (`#24292e`). See {@link GithubDarkStyle}\n * for the note on dropped DOM-only style props.\n */\nexport const GithubLightStyle: CodeHighlightStyle = {\n name: \"github-light\",\n defaultColor: \"#24292e\",\n rules: [\n { tag: [t.standard(t.tagName), t.tagName], color: \"#116329\" },\n { tag: [t.comment, t.bracket], color: \"#6a737d\" },\n { tag: [t.className, t.propertyName], color: \"#6f42c1\" },\n { tag: [t.variableName, t.attributeName, t.number, t.operator], color: \"#005cc5\" },\n { tag: [t.keyword, t.typeName, t.typeOperator], color: \"#d73a49\" },\n { tag: [t.string, t.meta, t.regexp], color: \"#032f62\" },\n { tag: [t.name, t.quote], color: \"#22863a\" },\n { tag: [t.heading, t.strong], color: \"#24292e\" },\n { tag: [t.emphasis], color: \"#24292e\" },\n { tag: [t.deleted], color: \"#b31d28\" },\n { tag: [t.atom, t.bool, t.special(t.variableName)], color: \"#e36209\" },\n { tag: [t.url, t.escape, t.regexp, t.link], color: \"#032f62\" },\n { tag: t.invalid, color: \"#cb2431\" },\n ],\n};\n\n/**\n * VS Code Dark+ highlight palette, adapted from the `@uiw/codemirror-theme-vscode`\n * snippet. `defaultColor` is VS Code's editor foreground (`#9cdcfe`). DOM-only\n * style props are dropped; later rules win, matching {@link tagHighlighter}.\n */\nexport const VscodeDarkStyle: CodeHighlightStyle = {\n name: \"vscode-dark\",\n defaultColor: \"#9cdcfe\",\n rules: [\n {\n tag: [\n t.keyword, t.operatorKeyword, t.modifier, t.color,\n t.constant(t.name), t.standard(t.name), t.standard(t.tagName),\n t.special(t.brace), t.atom, t.bool, t.special(t.variableName),\n ],\n color: \"#569cd6\",\n },\n { tag: [t.controlKeyword, t.moduleKeyword], color: \"#c586c0\" },\n {\n tag: [\n t.name, t.deleted, t.character, t.macroName, t.propertyName,\n t.variableName, t.labelName, t.definition(t.name),\n ],\n color: \"#9cdcfe\",\n },\n { tag: t.heading, color: \"#9cdcfe\" },\n { tag: [t.typeName, t.className, t.tagName, t.changed, t.annotation, t.self, t.namespace], color: \"#4ec9b0\" },\n { tag: [t.function(t.variableName), t.function(t.propertyName)], color: \"#dcdcaa\" },\n { tag: [t.number], color: \"#b5cea8\" },\n { tag: [t.operator, t.punctuation, t.separator, t.url, t.escape], color: \"#d4d4d4\" },\n { tag: [t.regexp], color: \"#d16969\" },\n { tag: [t.special(t.string), t.processingInstruction, t.string, t.inserted], color: \"#ce9178\" },\n { tag: [t.angleBracket], color: \"#808080\" },\n { tag: [t.meta, t.comment], color: \"#6a9955\" },\n { tag: t.link, color: \"#6a9955\" },\n { tag: t.invalid, color: \"#ff0000\" },\n ],\n};\n\n/**\n * VS Code Light+ highlight palette, adapted from the `@uiw/codemirror-theme-vscode`\n * snippet. `defaultColor` is VS Code's editor foreground (`#383a42`). See\n * {@link VscodeDarkStyle} for the note on dropped DOM-only style props.\n */\nexport const VscodeLightStyle: CodeHighlightStyle = {\n name: \"vscode-light\",\n defaultColor: \"#383a42\",\n rules: [\n {\n tag: [\n t.keyword, t.operatorKeyword, t.modifier, t.color,\n t.constant(t.name), t.standard(t.name), t.standard(t.tagName),\n t.special(t.brace), t.atom, t.bool, t.special(t.variableName),\n ],\n color: \"#0000ff\",\n },\n { tag: [t.moduleKeyword, t.controlKeyword], color: \"#af00db\" },\n {\n tag: [\n t.name, t.deleted, t.character, t.macroName, t.propertyName,\n t.variableName, t.labelName, t.definition(t.name),\n ],\n color: \"#0070c1\",\n },\n { tag: t.heading, color: \"#0070c1\" },\n { tag: [t.typeName, t.className, t.tagName, t.changed, t.annotation, t.self, t.namespace], color: \"#267f99\" },\n { tag: [t.function(t.variableName), t.function(t.propertyName)], color: \"#795e26\" },\n { tag: [t.number], color: \"#098658\" },\n { tag: [t.operator, t.punctuation, t.separator, t.url, t.escape], color: \"#383a42\" },\n { tag: [t.regexp], color: \"#af00db\" },\n { tag: [t.special(t.string), t.processingInstruction, t.string, t.inserted], color: \"#a31515\" },\n { tag: [t.angleBracket], color: \"#383a42\" },\n { tag: [t.meta, t.comment], color: \"#008000\" },\n { tag: t.link, color: \"#4078f2\" },\n { tag: t.invalid, color: \"#e45649\" },\n ],\n};\n\n/**\n * The built-in themes, keyed by their string name. {@link CodeThemeName} is the\n * union of these keys — pass one of those strings (or any {@link CodeHighlightStyle}\n * object) to a Code node's `theme` prop.\n */\nexport const BUILTIN_THEMES = {\n // Literal keys (not computed from `.name`) so `keyof` yields a string-literal\n // union for CodeThemeName; these must stay in sync with each style's `name`.\n \"motion-canvas-default\": DefaultHighlightStyle,\n \"github-dark\": GithubDarkStyle,\n \"github-light\": GithubLightStyle,\n \"vscode-dark\": VscodeDarkStyle,\n \"vscode-light\": VscodeLightStyle,\n} satisfies Record<string, CodeHighlightStyle>;\n\n/** Names of the built-in themes, e.g. `'github-dark' | 'github-light'`. */\nexport type CodeThemeName = keyof typeof BUILTIN_THEMES;\n\n/**\n * What a Code node's `theme` prop accepts: a built-in theme name (with\n * autocomplete), any other registered theme name, or a {@link CodeHighlightStyle}\n * object passed inline. The `string & {}` keeps the literal-name suggestions while\n * still allowing arbitrary registered names.\n */\nexport type CodeTheme = CodeThemeName | (string & {}) | CodeHighlightStyle;\n\n// Cache one compiled Highlighter per style name. Compiling builds a tag-rule\n// matcher; the parsed result is pure data so it's safe to share across Code nodes.\nconst compiledByName = new Map<string, Highlighter>();\n\n/**\n * Compile a {@link CodeHighlightStyle} into a `@lezer/highlight` {@link Highlighter}\n * whose \"class\" output is the literal color string for each tag. Cached by style\n * name so repeated lookups (every tokenize) don't rebuild the matcher.\n */\nexport function compileStyle(style: CodeHighlightStyle): Highlighter {\n const cached = compiledByName.get(style.name);\n if (cached) return cached;\n const highlighter = tagHighlighter(\n style.rules.map(rule => ({ tag: rule.tag, class: rule.color })),\n );\n compiledByName.set(style.name, highlighter);\n return highlighter;\n}\n"]}
|
package/dist/tokens.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CodeTheme } from "./style.js";
|
|
2
|
+
export interface IdToken {
|
|
3
|
+
id: number;
|
|
4
|
+
content: string;
|
|
5
|
+
color?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IdLine {
|
|
8
|
+
id: number;
|
|
9
|
+
tokens: IdToken[];
|
|
10
|
+
}
|
|
11
|
+
export declare function makeIdToken(content: string, color?: string): IdToken;
|
|
12
|
+
export declare function makeIdLine(tokens: IdToken[]): IdLine;
|
|
13
|
+
export declare function tokenizeCodeToIdLines(code: string, language: string, theme: CodeTheme): IdLine[];
|
|
14
|
+
/**
|
|
15
|
+
* Split `tokens` at character offset `col` (relative to the joined content of
|
|
16
|
+
* the tokens). If `col` falls inside a token, that token is split into two new
|
|
17
|
+
* tokens with fresh ids (the original id is discarded — it didn't exist as a
|
|
18
|
+
* single unit on either side of the cut).
|
|
19
|
+
*/
|
|
20
|
+
export declare function splitTokensAt(tokens: IdToken[], col: number): {
|
|
21
|
+
before: IdToken[];
|
|
22
|
+
after: IdToken[];
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAMpC,MAAM,WAAW,OAAO;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAID,MAAM,WAAW,MAAM;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,EAAE,CAAC;CACrB;AAQD,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAEpE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAEpD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,EAAE,CAUhG;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CACzB,MAAM,EAAE,OAAO,EAAE,EACjB,GAAG,EAAE,MAAM,GACZ;IAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAAC,KAAK,EAAE,OAAO,EAAE,CAAA;CAAE,CAmBzC"}
|
package/dist/tokens.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { canHighlight, highlightToTokens } from "./highlight.js";
|
|
2
|
+
// Module-global, monotonic id counters shared across all Code nodes — ids only
|
|
3
|
+
// need to be unique within a node, but a global counter is the simplest way to
|
|
4
|
+
// guarantee that and never collides.
|
|
5
|
+
let nextTokenId = 1;
|
|
6
|
+
let nextLineId = 1;
|
|
7
|
+
export function makeIdToken(content, color) {
|
|
8
|
+
return { id: nextTokenId++, content, color };
|
|
9
|
+
}
|
|
10
|
+
export function makeIdLine(tokens) {
|
|
11
|
+
return { id: nextLineId++, tokens };
|
|
12
|
+
}
|
|
13
|
+
export function tokenizeCodeToIdLines(code, language, theme) {
|
|
14
|
+
// Until the language parser has loaded (it streams in via the asset loader),
|
|
15
|
+
// fall back to flat, uncolored lines instead of throwing on an unloaded
|
|
16
|
+
// grammar. The node re-tokenizes once the load completes.
|
|
17
|
+
if (!canHighlight(language, theme)) {
|
|
18
|
+
return code.split('\n').map(line => makeIdLine([makeIdToken(line, '#d1d5db')]));
|
|
19
|
+
}
|
|
20
|
+
return highlightToTokens(code, language, theme).map(line => makeIdLine(line.map(tok => makeIdToken(tok.content, tok.color))));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Split `tokens` at character offset `col` (relative to the joined content of
|
|
24
|
+
* the tokens). If `col` falls inside a token, that token is split into two new
|
|
25
|
+
* tokens with fresh ids (the original id is discarded — it didn't exist as a
|
|
26
|
+
* single unit on either side of the cut).
|
|
27
|
+
*/
|
|
28
|
+
export function splitTokensAt(tokens, col) {
|
|
29
|
+
const before = [];
|
|
30
|
+
const after = [];
|
|
31
|
+
let off = 0;
|
|
32
|
+
for (const tok of tokens) {
|
|
33
|
+
const tStart = off;
|
|
34
|
+
const tEnd = off + tok.content.length;
|
|
35
|
+
if (tEnd <= col) {
|
|
36
|
+
before.push(tok);
|
|
37
|
+
}
|
|
38
|
+
else if (tStart >= col) {
|
|
39
|
+
after.push(tok);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const cut = col - tStart;
|
|
43
|
+
before.push(makeIdToken(tok.content.slice(0, cut), tok.color));
|
|
44
|
+
after.push(makeIdToken(tok.content.slice(cut), tok.color));
|
|
45
|
+
}
|
|
46
|
+
off = tEnd;
|
|
47
|
+
}
|
|
48
|
+
return { before, after };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAoB9D,+EAA+E;AAC/E,+EAA+E;AAC/E,qCAAqC;AACrC,IAAI,WAAW,GAAG,CAAC,CAAC;AACpB,IAAI,UAAU,GAAG,CAAC,CAAC;AAEnB,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,KAAc;IACvD,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAiB;IACxC,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,CAAC;AACxC,CAAC;AAED,MA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C,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YAC/D,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/D,CAAC;QACD,GAAG,GAAG,IAAI,CAAC;IACf,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["import { canHighlight, highlightToTokens } from \"./highlight\";\nimport { CodeTheme } from \"./style\";\n\n// IdToken is our internal wrapper around a highlighter token that gives every\n// token a stable identity across line insertions/removals. All animation state\n// is keyed by `id`, so concurrent edits at different positions don't clobber\n// each other while one is mid-animation.\nexport interface IdToken {\n id: number;\n content: string;\n color?: string;\n}\n\n// IdLine wraps a row of tokens with its own stable id, so per-line animations\n// (heightScale during insert/remove) survive line insertions/removals.\nexport interface IdLine {\n id: number;\n tokens: IdToken[];\n}\n\n// Module-global, monotonic id counters shared across all Code nodes — ids only\n// need to be unique within a node, but a global counter is the simplest way to\n// guarantee that and never collides.\nlet nextTokenId = 1;\nlet nextLineId = 1;\n\nexport function makeIdToken(content: string, color?: string): IdToken {\n return { id: nextTokenId++, content, color };\n}\n\nexport function makeIdLine(tokens: IdToken[]): IdLine {\n return { id: nextLineId++, tokens };\n}\n\nexport function tokenizeCodeToIdLines(code: string, language: string, theme: CodeTheme): IdLine[] {\n // Until the language parser has loaded (it streams in via the asset loader),\n // fall back to flat, uncolored lines instead of throwing on an unloaded\n // grammar. The node re-tokenizes once the load completes.\n if (!canHighlight(language, theme)) {\n return code.split('\\n').map(line => makeIdLine([makeIdToken(line, '#d1d5db')]));\n }\n return highlightToTokens(code, language, theme).map(line =>\n makeIdLine(line.map(tok => makeIdToken(tok.content, tok.color))),\n );\n}\n\n/**\n * Split `tokens` at character offset `col` (relative to the joined content of\n * the tokens). If `col` falls inside a token, that token is split into two new\n * tokens with fresh ids (the original id is discarded — it didn't exist as a\n * single unit on either side of the cut).\n */\nexport function splitTokensAt(\n tokens: IdToken[],\n col: number,\n): { before: IdToken[]; after: IdToken[] } {\n const before: IdToken[] = [];\n const after: IdToken[] = [];\n let off = 0;\n for (const tok of tokens) {\n const tStart = off;\n const tEnd = off + tok.content.length;\n if (tEnd <= col) {\n before.push(tok);\n } else if (tStart >= col) {\n after.push(tok);\n } else {\n const cut = col - tStart;\n before.push(makeIdToken(tok.content.slice(0, cut), tok.color));\n after.push(makeIdToken(tok.content.slice(cut), tok.color));\n }\n off = tEnd;\n }\n return { before, after };\n}\n"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { CodeLayout } from "./layout.js";
|
|
2
|
+
import { IdLine } from "./tokens.js";
|
|
3
|
+
export interface AnimToken {
|
|
4
|
+
id: number;
|
|
5
|
+
opacity: number[];
|
|
6
|
+
opacityKeys: number[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A highlight cross-fade: opacity, and nothing else.
|
|
10
|
+
*
|
|
11
|
+
* Structure is untouched, so several of these stack happily and a listing held
|
|
12
|
+
* under a highlight still hits the static-layout cache.
|
|
13
|
+
*/
|
|
14
|
+
export interface DimTransition {
|
|
15
|
+
kind: "dim";
|
|
16
|
+
tokens: AnimToken[];
|
|
17
|
+
progress: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* When each part of a structural edit happens, in normalized transition time.
|
|
21
|
+
*
|
|
22
|
+
* The order is what an edit *looks like* being made: what is going away leaves
|
|
23
|
+
* first, what stays reflows into its new place, and only then does what is new
|
|
24
|
+
* appear. Running them together is what made a replacement look like a
|
|
25
|
+
* cross-dissolve of two unrelated listings.
|
|
26
|
+
*/
|
|
27
|
+
export interface Phases {
|
|
28
|
+
/** Removed tokens fade out. Null when the edit removes nothing. */
|
|
29
|
+
out: [number, number] | null;
|
|
30
|
+
/** Surviving tokens travel, and the block resizes. Always present. */
|
|
31
|
+
move: [number, number];
|
|
32
|
+
/** Added tokens fade (and slide) in. Null when the edit adds nothing. */
|
|
33
|
+
in: [number, number] | null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* One edit in flight: the structure before, the structure after, and who is
|
|
37
|
+
* doing what.
|
|
38
|
+
*
|
|
39
|
+
* Both endpoints are fixed for the transition's whole life, which is why the
|
|
40
|
+
* two resolved layouts hang off it — they are computed once and reused for
|
|
41
|
+
* every frame the edit spans, rather than rebuilt per frame from a structure
|
|
42
|
+
* that is being mutated underneath.
|
|
43
|
+
*/
|
|
44
|
+
export interface StructuralTransition {
|
|
45
|
+
kind: "structural";
|
|
46
|
+
from: IdLine[];
|
|
47
|
+
to: IdLine[];
|
|
48
|
+
removedIds: Set<number>;
|
|
49
|
+
addedIds: Set<number>;
|
|
50
|
+
/**
|
|
51
|
+
* Ids of rows in `to` that did not exist before, and so enter as a whole
|
|
52
|
+
* row rather than as tokens spliced into one.
|
|
53
|
+
*
|
|
54
|
+
* They enter by fading in place, and that is the *only* thing they do. An
|
|
55
|
+
* earlier version slid each one in from the edge the block had just grown
|
|
56
|
+
* along — appended rows rising from below, prepended ones descending, ones
|
|
57
|
+
* spliced into the middle arriving from the left. Every one of those is a
|
|
58
|
+
* claim about where the line came from, and a listing has no such story to
|
|
59
|
+
* tell: text is written where it belongs, it does not travel there. Sliding
|
|
60
|
+
* also puts the row under the neighbours it is meant to sit between for the
|
|
61
|
+
* length of its entrance, which reads as the listing redrawing itself.
|
|
62
|
+
*/
|
|
63
|
+
enteringLineIds: Set<number>;
|
|
64
|
+
fromColorById: Map<number, string | undefined>;
|
|
65
|
+
phases: Phases;
|
|
66
|
+
progress: number;
|
|
67
|
+
/** @internal Layout cache — see {@link StructuralTransition}. */
|
|
68
|
+
layoutKey: string | null;
|
|
69
|
+
fromLayout: CodeLayout | null;
|
|
70
|
+
toLayout: CodeLayout | null;
|
|
71
|
+
}
|
|
72
|
+
export type CodeTransition = DimTransition | StructuralTransition;
|
|
73
|
+
/**
|
|
74
|
+
* Decides *when* (in normalized transition time) each part of a structural
|
|
75
|
+
* edit happens, given only whether the edit removes/adds anything.
|
|
76
|
+
* `phasesFor` below is the default implementation (exported as
|
|
77
|
+
* `defaultCodePhases`) — pass a `phaseStrategy` of this shape to `<Code>` to
|
|
78
|
+
* replace it with your own timing.
|
|
79
|
+
*/
|
|
80
|
+
export type CodePhaseStrategy = (hasRemoved: boolean, hasAdded: boolean) => Phases;
|
|
81
|
+
export interface TokenState {
|
|
82
|
+
opacity: number;
|
|
83
|
+
}
|
|
84
|
+
/** Sample a piecewise-linear curve (keys → values) at progress `p` in [0, 1]. */
|
|
85
|
+
export declare function sampleCurve(keys: number[], values: number[], p: number): number;
|
|
86
|
+
/** Progress *within* a phase window, clamped to [0, 1]. A null window is complete. */
|
|
87
|
+
export declare function windowProgress(w: [number, number] | null, p: number): number;
|
|
88
|
+
/** Smooth start and end, so a phase never begins or ends with a velocity step. */
|
|
89
|
+
export declare function smoothstep(t: number): number;
|
|
90
|
+
export declare function makeAnim(id: number, curve: {
|
|
91
|
+
keys: number[];
|
|
92
|
+
values: number[];
|
|
93
|
+
}): AnimToken;
|
|
94
|
+
/**
|
|
95
|
+
* The phase schedule for an edit, shaped by what the edit actually contains.
|
|
96
|
+
*
|
|
97
|
+
* A fixed schedule wastes time it does not need: a pure append has nothing to
|
|
98
|
+
* fade out, so holding the first 40% of the duration empty just makes the
|
|
99
|
+
* animation feel late. Each shape gets the whole duration spent on the parts
|
|
100
|
+
* that exist, with adjacent phases overlapping enough to read as one movement.
|
|
101
|
+
*/
|
|
102
|
+
export declare function phasesFor(hasRemoved: boolean, hasAdded: boolean): Phases;
|
|
103
|
+
/** {@link phasesFor} under the name a `phaseStrategy` default is looked up by. */
|
|
104
|
+
export declare const defaultCodePhases: CodePhaseStrategy;
|
|
105
|
+
/** How far through the "everything reflows" phase a frame is, eased. A settled frame (no edit) is always fully moved. */
|
|
106
|
+
export declare function moveProgress(edit: {
|
|
107
|
+
phases: Phases;
|
|
108
|
+
progress: number;
|
|
109
|
+
} | null): number;
|
|
110
|
+
/**
|
|
111
|
+
* Resolve the per-token opacity multiplier for the current frame from the
|
|
112
|
+
* persistent highlight dim plus every active dim transition.
|
|
113
|
+
*/
|
|
114
|
+
export declare function resolveTokenStates(tokenLines: IdLine[], transitions: CodeTransition[], highlightDimOpacity: number | null, highlightedIds: Set<number>): Map<number, TokenState>;
|
|
115
|
+
//# sourceMappingURL=transitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transitions.d.ts","sourceRoot":"","sources":["../src/transitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKlC,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,KAAK,CAAC;IACZ,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,MAAM;IACnB,mEAAmE;IACnE,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAC7B,sEAAsE;IACtE,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvB,yEAAyE;IACzE,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAoB;IACjC,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,EAAE,EA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GAOG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAUxE;AAED,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,EAAE,iBAA6B,CAAC;AAE9D,yHAAyH;AACzH,wBAAgB,YAAY,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GAAG,MAAM,CAEtF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAC9B,UAAU,EAAE,MAAM,EAAE,EACpB,WAAW,EAAE,cAAc,EAAE,EAC7B,mBAAmB,EAAE,MAAM,GAAG,IAAI,EAClC,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,GAC5B,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAoBzB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Sample a piecewise-linear curve (keys → values) at progress `p` in [0, 1]. */
|
|
2
|
+
export function sampleCurve(keys, values, p) {
|
|
3
|
+
if (p <= keys[0])
|
|
4
|
+
return values[0];
|
|
5
|
+
if (p >= keys[keys.length - 1])
|
|
6
|
+
return values[values.length - 1];
|
|
7
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
8
|
+
if (p <= keys[i + 1]) {
|
|
9
|
+
const span = keys[i + 1] - keys[i];
|
|
10
|
+
const local = span === 0 ? 0 : (p - keys[i]) / span;
|
|
11
|
+
return values[i] + (values[i + 1] - values[i]) * local;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return values[values.length - 1];
|
|
15
|
+
}
|
|
16
|
+
/** Progress *within* a phase window, clamped to [0, 1]. A null window is complete. */
|
|
17
|
+
export function windowProgress(w, p) {
|
|
18
|
+
if (!w)
|
|
19
|
+
return 1;
|
|
20
|
+
const [a, b] = w;
|
|
21
|
+
if (p <= a)
|
|
22
|
+
return 0;
|
|
23
|
+
if (p >= b)
|
|
24
|
+
return 1;
|
|
25
|
+
return b === a ? 1 : (p - a) / (b - a);
|
|
26
|
+
}
|
|
27
|
+
/** Smooth start and end, so a phase never begins or ends with a velocity step. */
|
|
28
|
+
export function smoothstep(t) {
|
|
29
|
+
return t * t * (3 - 2 * t);
|
|
30
|
+
}
|
|
31
|
+
export function makeAnim(id, curve) {
|
|
32
|
+
return { id, opacity: curve.values, opacityKeys: curve.keys };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The phase schedule for an edit, shaped by what the edit actually contains.
|
|
36
|
+
*
|
|
37
|
+
* A fixed schedule wastes time it does not need: a pure append has nothing to
|
|
38
|
+
* fade out, so holding the first 40% of the duration empty just makes the
|
|
39
|
+
* animation feel late. Each shape gets the whole duration spent on the parts
|
|
40
|
+
* that exist, with adjacent phases overlapping enough to read as one movement.
|
|
41
|
+
*/
|
|
42
|
+
export function phasesFor(hasRemoved, hasAdded) {
|
|
43
|
+
// The overlaps are deliberate and small. Butt-joining the phases leaves the
|
|
44
|
+
// block sitting empty at its new size for a beat between the old content
|
|
45
|
+
// leaving and the new content arriving; letting the arrival start while the
|
|
46
|
+
// reflow's eased tail is still running closes that gap without blurring the
|
|
47
|
+
// order the edit reads in.
|
|
48
|
+
if (hasRemoved && hasAdded)
|
|
49
|
+
return { out: [0, 0.38], move: [0.10, 0.68], in: [0.52, 1] };
|
|
50
|
+
if (hasRemoved)
|
|
51
|
+
return { out: [0, 0.45], move: [0.22, 1], in: null };
|
|
52
|
+
if (hasAdded)
|
|
53
|
+
return { out: null, move: [0, 0.55], in: [0.38, 1] };
|
|
54
|
+
return { out: null, move: [0, 1], in: null };
|
|
55
|
+
}
|
|
56
|
+
/** {@link phasesFor} under the name a `phaseStrategy` default is looked up by. */
|
|
57
|
+
export const defaultCodePhases = phasesFor;
|
|
58
|
+
/** How far through the "everything reflows" phase a frame is, eased. A settled frame (no edit) is always fully moved. */
|
|
59
|
+
export function moveProgress(edit) {
|
|
60
|
+
return edit ? smoothstep(windowProgress(edit.phases.move, edit.progress)) : 1;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Resolve the per-token opacity multiplier for the current frame from the
|
|
64
|
+
* persistent highlight dim plus every active dim transition.
|
|
65
|
+
*/
|
|
66
|
+
export function resolveTokenStates(tokenLines, transitions, highlightDimOpacity, highlightedIds) {
|
|
67
|
+
const out = new Map();
|
|
68
|
+
if (highlightDimOpacity !== null) {
|
|
69
|
+
const dim = highlightDimOpacity;
|
|
70
|
+
for (const line of tokenLines) {
|
|
71
|
+
for (const tok of line.tokens) {
|
|
72
|
+
out.set(tok.id, { opacity: highlightedIds.has(tok.id) ? 1 : dim });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const tr of transitions) {
|
|
77
|
+
if (tr.kind !== "dim")
|
|
78
|
+
continue;
|
|
79
|
+
for (const at of tr.tokens) {
|
|
80
|
+
out.set(at.id, { opacity: sampleCurve(at.opacityKeys, at.opacity, tr.progress) });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=transitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transitions.js","sourceRoot":"","sources":["../src/transitions.ts"],"names":[],"mappings":"AA8FA,iFAAiF;AACjF,MAAM,UAAU,WAAW,CAAC,IAAc,EAAE,MAAgB,EAAE,CAAS;IACnE,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IACnC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACjE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,I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EAC7B,mBAAkC,EAClC,cAA2B;IAE3B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAsB,CAAC;IAE1C,IAAI,mBAAmB,KAAK,IAAI,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,mBAAmB,CAAC;QAChC,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;YAC5B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAC5B,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;YACvE,CAAC;QACL,CAAC;IACL,CAAC;IAED,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE,CAAC;QAC3B,IAAI,EAAE,CAAC,IAAI,KAAK,KAAK;YAAE,SAAS;QAChC,KAAK,MAAM,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;YACzB,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACtF,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import type { CodeLayout } from \"./layout\";\nimport { IdLine } from \"./tokens\";\n\n// A single animated token entry owned by one dim transition. Keyed by stable\n// token id rather than (line, tokenIndex) so concurrent animations don't clobber\n// each other when one shifts the indices of tokens the other is animating.\nexport interface AnimToken {\n id: number;\n opacity: number[];\n opacityKeys: number[];\n}\n\n/**\n * A highlight cross-fade: opacity, and nothing else.\n *\n * Structure is untouched, so several of these stack happily and a listing held\n * under a highlight still hits the static-layout cache.\n */\nexport interface DimTransition {\n kind: \"dim\";\n tokens: AnimToken[];\n progress: number;\n}\n\n/**\n * When each part of a structural edit happens, in normalized transition time.\n *\n * The order is what an edit *looks like* being made: what is going away leaves\n * first, what stays reflows into its new place, and only then does what is new\n * appear. Running them together is what made a replacement look like a\n * cross-dissolve of two unrelated listings.\n */\nexport interface Phases {\n /** Removed tokens fade out. Null when the edit removes nothing. */\n out: [number, number] | null;\n /** Surviving tokens travel, and the block resizes. Always present. */\n move: [number, number];\n /** Added tokens fade (and slide) in. Null when the edit adds nothing. */\n in: [number, number] | null;\n}\n\n/**\n * One edit in flight: the structure before, the structure after, and who is\n * doing what.\n *\n * Both endpoints are fixed for the transition's whole life, which is why the\n * two resolved layouts hang off it — they are computed once and reused for\n * every frame the edit spans, rather than rebuilt per frame from a structure\n * that is being mutated underneath.\n */\nexport interface StructuralTransition {\n kind: \"structural\";\n from: IdLine[];\n to: IdLine[];\n removedIds: Set<number>;\n addedIds: Set<number>;\n /**\n * Ids of rows in `to` that did not exist before, and so enter as a whole\n * row rather than as tokens spliced into one.\n *\n * They enter by fading in place, and that is the *only* thing they do. An\n * earlier version slid each one in from the edge the block had just grown\n * along — appended rows rising from below, prepended ones descending, ones\n * spliced into the middle arriving from the left. Every one of those is a\n * claim about where the line came from, and a listing has no such story to\n * tell: text is written where it belongs, it does not travel there. Sliding\n * also puts the row under the neighbours it is meant to sit between for the\n * length of its entrance, which reads as the listing redrawing itself.\n */\n enteringLineIds: Set<number>;\n fromColorById: Map<number, string | undefined>;\n phases: Phases;\n progress: number;\n /** @internal Layout cache — see {@link StructuralTransition}. */\n layoutKey: string | null;\n fromLayout: CodeLayout | null;\n toLayout: CodeLayout | null;\n}\n\nexport type CodeTransition = DimTransition | StructuralTransition;\n\n/**\n * Decides *when* (in normalized transition time) each part of a structural\n * edit happens, given only whether the edit removes/adds anything.\n * `phasesFor` below is the default implementation (exported as\n * `defaultCodePhases`) — pass a `phaseStrategy` of this shape to `<Code>` to\n * replace it with your own timing.\n */\nexport type CodePhaseStrategy = (hasRemoved: boolean, hasAdded: boolean) => Phases;\n\nexport interface TokenState {\n opacity: number;\n}\n\n/** Sample a piecewise-linear curve (keys → values) at progress `p` in [0, 1]. */\nexport function sampleCurve(keys: number[], values: number[], p: number): number {\n if (p <= keys[0]) return values[0];\n if (p >= keys[keys.length - 1]) return values[values.length - 1];\n for (let i = 0; i < keys.length - 1; i++) {\n if (p <= keys[i + 1]) {\n const span = keys[i + 1] - keys[i];\n const local = span === 0 ? 0 : (p - keys[i]) / span;\n return values[i] + (values[i + 1] - values[i]) * local;\n }\n }\n return values[values.length - 1];\n}\n\n/** Progress *within* a phase window, clamped to [0, 1]. A null window is complete. */\nexport function windowProgress(w: [number, number] | null, p: number): number {\n if (!w) return 1;\n const [a, b] = w;\n if (p <= a) return 0;\n if (p >= b) return 1;\n return b === a ? 1 : (p - a) / (b - a);\n}\n\n/** Smooth start and end, so a phase never begins or ends with a velocity step. */\nexport function smoothstep(t: number): number {\n return t * t * (3 - 2 * t);\n}\n\nexport function makeAnim(id: number, curve: { keys: number[]; values: number[] }): AnimToken {\n return { id, opacity: curve.values, opacityKeys: curve.keys };\n}\n\n/**\n * The phase schedule for an edit, shaped by what the edit actually contains.\n *\n * A fixed schedule wastes time it does not need: a pure append has nothing to\n * fade out, so holding the first 40% of the duration empty just makes the\n * animation feel late. Each shape gets the whole duration spent on the parts\n * that exist, with adjacent phases overlapping enough to read as one movement.\n */\nexport function phasesFor(hasRemoved: boolean, hasAdded: boolean): Phases {\n // The overlaps are deliberate and small. Butt-joining the phases leaves the\n // block sitting empty at its new size for a beat between the old content\n // leaving and the new content arriving; letting the arrival start while the\n // reflow's eased tail is still running closes that gap without blurring the\n // order the edit reads in.\n if (hasRemoved && hasAdded) return { out: [0, 0.38], move: [0.10, 0.68], in: [0.52, 1] };\n if (hasRemoved) return { out: [0, 0.45], move: [0.22, 1], in: null };\n if (hasAdded) return { out: null, move: [0, 0.55], in: [0.38, 1] };\n return { out: null, move: [0, 1], in: null };\n}\n\n/** {@link phasesFor} under the name a `phaseStrategy` default is looked up by. */\nexport const defaultCodePhases: CodePhaseStrategy = phasesFor;\n\n/** How far through the \"everything reflows\" phase a frame is, eased. A settled frame (no edit) is always fully moved. */\nexport function moveProgress(edit: { phases: Phases; progress: number } | null): number {\n return edit ? smoothstep(windowProgress(edit.phases.move, edit.progress)) : 1;\n}\n\n/**\n * Resolve the per-token opacity multiplier for the current frame from the\n * persistent highlight dim plus every active dim transition.\n */\nexport function resolveTokenStates(\n tokenLines: IdLine[],\n transitions: CodeTransition[],\n highlightDimOpacity: number | null,\n highlightedIds: Set<number>,\n): Map<number, TokenState> {\n const out = new Map<number, TokenState>();\n\n if (highlightDimOpacity !== null) {\n const dim = highlightDimOpacity;\n for (const line of tokenLines) {\n for (const tok of line.tokens) {\n out.set(tok.id, { opacity: highlightedIds.has(tok.id) ? 1 : dim });\n }\n }\n }\n\n for (const tr of transitions) {\n if (tr.kind !== \"dim\") continue;\n for (const at of tr.tokens) {\n out.set(at.id, { opacity: sampleCurve(at.opacityKeys, at.opacity, tr.progress) });\n }\n }\n\n return out;\n}\n"]}
|