@motionscript/code 0.1.0 → 0.1.1-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.
Files changed (65) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +2 -2
  3. package/dist/browser/index.js +8 -8
  4. package/dist/browser/index.js.map +3 -3
  5. package/dist/browser/manifest.json +1 -1
  6. package/dist/code-range.d.ts +7 -47
  7. package/dist/code-range.d.ts.map +1 -1
  8. package/dist/code-range.js +8 -45
  9. package/dist/code-range.js.map +1 -1
  10. package/dist/diff.d.ts +5 -44
  11. package/dist/diff.d.ts.map +1 -1
  12. package/dist/diff.js +22 -69
  13. package/dist/diff.js.map +1 -1
  14. package/dist/engine.d.ts.map +1 -1
  15. package/dist/engine.js +3 -7
  16. package/dist/engine.js.map +1 -1
  17. package/dist/highlight.d.ts +13 -31
  18. package/dist/highlight.d.ts.map +1 -1
  19. package/dist/highlight.js +25 -87
  20. package/dist/highlight.js.map +1 -1
  21. package/dist/layout.d.ts +7 -26
  22. package/dist/layout.d.ts.map +1 -1
  23. package/dist/layout.js +5 -20
  24. package/dist/layout.js.map +1 -1
  25. package/dist/measure-cache.d.ts +5 -27
  26. package/dist/measure-cache.d.ts.map +1 -1
  27. package/dist/measure-cache.js +0 -0
  28. package/dist/measure-cache.js.map +1 -1
  29. package/dist/node.d.ts +4 -11
  30. package/dist/node.d.ts.map +1 -1
  31. package/dist/node.js +18 -41
  32. package/dist/node.js.map +1 -1
  33. package/dist/nodes.d.ts +0 -12
  34. package/dist/nodes.d.ts.map +1 -1
  35. package/dist/nodes.js +0 -12
  36. package/dist/nodes.js.map +1 -1
  37. package/dist/render.d.ts +5 -14
  38. package/dist/render.d.ts.map +1 -1
  39. package/dist/render.js +13 -54
  40. package/dist/render.js.map +1 -1
  41. package/dist/style.d.ts +6 -61
  42. package/dist/style.d.ts.map +1 -1
  43. package/dist/style.js +4 -40
  44. package/dist/style.js.map +1 -1
  45. package/dist/tokens.d.ts +1 -10
  46. package/dist/tokens.d.ts.map +1 -1
  47. package/dist/tokens.js +3 -38
  48. package/dist/tokens.js.map +1 -1
  49. package/dist/transitions.d.ts +16 -68
  50. package/dist/transitions.d.ts.map +1 -1
  51. package/dist/transitions.js +5 -17
  52. package/dist/transitions.js.map +1 -1
  53. package/package.json +4 -4
  54. package/src/code-range.ts +9 -53
  55. package/src/diff.ts +26 -92
  56. package/src/engine.ts +3 -7
  57. package/src/highlight.ts +25 -98
  58. package/src/layout.ts +10 -35
  59. package/src/measure-cache.ts +0 -0
  60. package/src/node.ts +21 -57
  61. package/src/nodes.ts +0 -12
  62. package/src/render.ts +17 -61
  63. package/src/style.ts +9 -64
  64. package/src/tokens.ts +4 -46
  65. package/src/transitions.ts +16 -72
@@ -1 +1 @@
1
- {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAuD,MAAM,mBAAmB,CAAC;AACzG,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AA+CzD,gFAAgF;AAChF,MAAM,WAAW,aAAa;IAC1B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,WAAW,CAAC;IACrB,YAAY,EAAE,iBAAiB,CAAC;IAChC,uFAAuF;IACvF,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,UAAU,CAAC;IACf,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAClC,sGAAsG;IACtG,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACrC,+GAA+G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,CAAC;IACjC,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,8EAA8E;AAC9E,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC;AAEvE,mGAAmG;AACnG,wBAAgB,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI,CAuHrE"}
package/dist/render.js CHANGED
@@ -1,12 +1,8 @@
1
1
  import { Graphics2D, parseColor, lerpNumber } from "@motionscript/sdk";
2
2
  import { windowProgress, moveProgress } from "./transitions.js";
3
- /** Colour of a token the grammar had no opinion about. */
4
3
  const DEFAULT_TOKEN_COLOR = [0.82, 0.84, 0.86, 1];
5
- /** Gutter line-number colour: a muted version of the standard text colour. */
6
4
  const LINE_NUMBER_COLOR = [0.45, 0.5, 0.55, 1];
7
- // `parseColor` walks a CSS string; a listing asks for the same handful of theme
8
- // colours on every token of every frame, so the parse is memoized. Module-level,
9
- // because the answer depends only on the string.
5
+ // A listing asks for the same few theme colours on every token of every frame.
10
6
  const colorCache = new Map();
11
7
  function tokenColor(css) {
12
8
  if (!css)
@@ -30,10 +26,7 @@ function lerpColor(from, to, t) {
30
26
  from[3] + (to[3] - from[3]) * t,
31
27
  ];
32
28
  }
33
- // Opacity multiplier for a line's number under the active highlight. The
34
- // number stays bright only when the WHOLE line is highlighted, so we take the
35
- // min token opacity on the line. Returns 1 (no dimming) when no highlight is
36
- // active, so an edit's entries don't drag the number down.
29
+ // A number stays bright only when the whole line is highlighted, so it takes the line's minimum token opacity.
37
30
  function lineHighlightOpacity(line, stateById, highlightActive) {
38
31
  if (!highlightActive)
39
32
  return 1;
@@ -47,13 +40,7 @@ function lineHighlightOpacity(line, stateById, highlightActive) {
47
40
  }
48
41
  return min;
49
42
  }
50
- /**
51
- * Draw one frame of a code listing: the settled structure, or — mid
52
- * structural edit — the two structures it is interpolating between (what
53
- * stays reflows, what is leaving fades out where it was, what is arriving
54
- * fades/slides in where it lands). Pure over `state`; touches nothing but
55
- * `draw`.
56
- */
43
+ /** Draws the settled structure, or mid-edit the two it interpolates between. Pure over `state`. */
57
44
  export function drawCode(draw, state) {
58
45
  const { tokenLines, metrics, advanceCache, from, to, edit, tokenStates: dim } = state;
59
46
  const progress = edit ? edit.progress : 1;
@@ -63,8 +50,6 @@ export function drawCode(draw, state) {
63
50
  const blockW = edit ? lerpNumber(from.blockW, to.blockW, pMove) : to.blockW;
64
51
  const gutter = edit ? lerpNumber(from.gutter, to.gutter, pMove) : to.gutter;
65
52
  const gutterGap = to.gutterGap || from.gutterGap;
66
- // Right edge of the line-number column: one gap to the left of where the
67
- // code text begins.
68
53
  const numberRight = -blockW / 2 + metrics.padding.left + gutter - gutterGap;
69
54
  drawRowBands(draw, state, Math.max(blockW, state.boxW ?? 0), pMove);
70
55
  const drawNumber = (label, y, opacity) => {
@@ -106,8 +91,7 @@ export function drawCode(draw, state) {
106
91
  })
107
92
  .fill([{ type: "solid", color, opacity }]));
108
93
  };
109
- // What survived the edit, and what it brought with it — drawn from the
110
- // structure the edit lands on.
94
+ // Survivors and arrivals, from the structure the edit lands on.
111
95
  for (let i = 0; i < tokenLines.length; i++) {
112
96
  const line = tokenLines[i];
113
97
  const toIndex = to.lineIndex.get(line.id);
@@ -118,10 +102,7 @@ export function drawCode(draw, state) {
118
102
  let rowY = toY;
119
103
  let rowAlpha = 1;
120
104
  if (edit && entering) {
121
- // A wholly new row fades as one piece, in the place it lands — the
122
- // line arrives, it does not travel to get there, and it is not a
123
- // spray of glyphs each finding its own way in. See
124
- // `StructuralTransition.enteringLineIds`.
105
+ // A new row fades as one piece where it lands (see `enteringLineIds`).
125
106
  rowAlpha = pIn;
126
107
  }
127
108
  else if (edit) {
@@ -138,8 +119,7 @@ export function drawCode(draw, state) {
138
119
  let color = tokenColor(token.color);
139
120
  if (edit && !entering) {
140
121
  if (edit.addedIds.has(token.id)) {
141
- // Spliced into a row that already existed: the reflow
142
- // already opened the space, so this only has to appear.
122
+ // Spliced into an existing row: the reflow opened the space already.
143
123
  alpha = pIn;
144
124
  }
145
125
  else {
@@ -154,8 +134,7 @@ export function drawCode(draw, state) {
154
134
  drawToken(token.content, x, rowY, color, alpha * (dim.get(token.id)?.opacity ?? 1));
155
135
  }
156
136
  }
157
- // What the edit takes away, drawn from the structure it is leaving — it
158
- // has no place in the new one, which is the whole reason it is fading.
137
+ // What the edit takes away, from the structure it is leaving.
159
138
  if (edit && pOut < 1) {
160
139
  for (let i = 0; i < edit.from.length; i++) {
161
140
  const line = edit.from[i];
@@ -163,9 +142,7 @@ export function drawCode(draw, state) {
163
142
  if (fromIndex === undefined)
164
143
  continue;
165
144
  const toIndex = to.lineIndex.get(line.id);
166
- // A row that survived the edit is still moving, so its outgoing
167
- // tokens travel with it; a deleted row stays where it was and
168
- // dissolves while the rows below close over it.
145
+ // A surviving row's outgoing tokens travel with it; a deleted row dissolves in place.
169
146
  const y = toIndex === undefined
170
147
  ? from.lineY[fromIndex]
171
148
  : lerpNumber(from.lineY[fromIndex], to.lineY[toIndex], pMove);
@@ -201,11 +178,7 @@ function bandEdges(band, state, pMove) {
201
178
  return null;
202
179
  return { top: (first ?? last) + half, bottom: (last ?? first) - half };
203
180
  }
204
- /**
205
- * Draw the row bands, under the text and across the whole block. A band rides
206
- * its rows through a structural edit; between two sets, bands paired by position
207
- * slide and recolour while an unpaired one fades.
208
- */
181
+ /** Bands ride their rows through an edit; between two sets, those paired by position slide and recolour and an unpaired one fades. */
209
182
  function drawRowBands(draw, state, width, pMove) {
210
183
  const { rowBands = [], rowsEdit = null } = state;
211
184
  const paint = (top, bottom, color, radius, opacity) => {
@@ -241,22 +214,9 @@ function drawRowBands(draw, state, width, pMove) {
241
214
  }
242
215
  }
243
216
  /**
244
- * Draw the gutter — one number per *slot*, not one per row.
245
- *
246
- * That distinction is the whole of it. A line number is an ordinal of the
247
- * block: "3" means the third line, and it is there for exactly as long as the
248
- * listing has a third line. Drawing it alongside the row it labels — the
249
- * obvious thing, since that is where it appears — tied it to the row's identity
250
- * instead, so a line rewritten past the point the diff could pair it took its
251
- * number down with it and brought an identical one back up. The number blinked
252
- * although it had never gone away, and every substantially rewritten line did
253
- * it at once.
254
- *
255
- * Numbering the slots means only the numbers at the end move at all: those the
256
- * block grew to reach fade in, those it shrank past fade out, and every number
257
- * both structures have simply travels to its new row height. Which is also the
258
- * honest reading of the edit — inserting a line in the middle does not make a
259
- * new number appear there, it makes the block one line longer.
217
+ * One number per slot, not per row: "3" lasts as long as the listing has a third
218
+ * line. Tied to a row's identity, a line rewritten past what the diff could pair
219
+ * would take its number down and bring an identical one back up (a blink).
260
220
  */
261
221
  function drawLineNumbers(state, drawNumber, pMove, pIn, pOut) {
262
222
  const { tokenLines, from, to, edit, tokenStates: dim, highlightActive } = state;
@@ -265,8 +225,7 @@ function drawLineNumbers(state, drawNumber, pMove, pIn, pOut) {
265
225
  for (let i = 0; i < Math.max(fromCount, toCount); i++) {
266
226
  const inFrom = i < fromCount;
267
227
  const inTo = i < toCount;
268
- // Highlight dimming follows whatever content occupies the slot, which
269
- // is the new listing wherever there is one.
228
+ // Dimming follows the content in the slot: the new listing where there is one.
270
229
  const line = inTo ? tokenLines[i] : edit?.from[i];
271
230
  const dimming = line ? lineHighlightOpacity(line, dim, highlightActive) : 1;
272
231
  if (!edit)
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,UAAU,EAAmB,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGzG,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAI7D,0DAA0D;AAC1D,MAAM,mBAAmB,GAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACnE,8EAA8E;AAC9E,MAAM,iBAAiB,GAAoB,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,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,GAAG,CAAC,GAAG,SAAS,CAAC;QAC7B,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC;QACzB,sEAAsE;QACtE,4CAA4C;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC,IAAI,EAAE,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAE5E,IAAI,CAAC,IAAI;YAAE,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;aACtD,IAAI,MAAM,IAAI,IAAI;YAAE,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;aACtG,IAAI,IAAI;YAAE,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC;;YAChE,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;IACxE,CAAC;AACL,CAAC","sourcesContent":["import { RenderContext2D, Graphics2D, NormalizedColor, parseColor, lerpNumber } from \"@motionscript/sdk\";\nimport type { CodeLayout, CodeMetrics } from \"./layout\";\nimport type { IdLine } from \"./tokens\";\nimport { windowProgress, moveProgress } from \"./transitions\";\nimport type { TokenState, StructuralTransition, RowBand, RowsTransition } from \"./transitions\";\nimport type { TokenAdvanceCache } from \"./measure-cache\";\n\n/** Colour of a token the grammar had no opinion about. */\nconst DEFAULT_TOKEN_COLOR: NormalizedColor = [0.82, 0.84, 0.86, 1];\n/** Gutter line-number colour: a muted version of the standard text colour. */\nconst LINE_NUMBER_COLOR: NormalizedColor = [0.45, 0.5, 0.55, 1];\n\n// `parseColor` walks a CSS string; a listing asks for the same handful of theme\n// colours on every token of every frame, so the parse is memoized. Module-level,\n// because the answer depends only on the string.\nconst colorCache = new Map<string, NormalizedColor>();\nfunction tokenColor(css: string | undefined): NormalizedColor {\n if (!css) return DEFAULT_TOKEN_COLOR;\n let hit = colorCache.get(css);\n if (!hit) {\n hit = parseColor(css);\n colorCache.set(css, hit);\n }\n return hit;\n}\n\nfunction lerpColor(from: NormalizedColor, to: NormalizedColor, t: number): NormalizedColor {\n if (t <= 0) return from;\n if (t >= 1) return to;\n return [\n from[0] + (to[0] - from[0]) * t,\n from[1] + (to[1] - from[1]) * t,\n from[2] + (to[2] - from[2]) * t,\n from[3] + (to[3] - from[3]) * t,\n ];\n}\n\n// Opacity multiplier for a line's number under the active highlight. The\n// number stays bright only when the WHOLE line is highlighted, so we take the\n// min token opacity on the line. Returns 1 (no dimming) when no highlight is\n// active, so an edit's entries don't drag the number down.\nfunction lineHighlightOpacity(line: IdLine, stateById: Map<number, TokenState>, highlightActive: boolean): number {\n if (!highlightActive) return 1;\n let min = 1;\n for (const tok of line.tokens) {\n if (tok.content.length === 0) continue;\n const op = stateById.get(tok.id)?.opacity ?? 1;\n if (op < min) min = op;\n }\n return min;\n}\n\n/** Everything a `Code` node's own instance state supplies to draw one frame. */\nexport interface DrawCodeState {\n tokenLines: IdLine[];\n metrics: CodeMetrics;\n advanceCache: TokenAdvanceCache;\n /** The one or two layouts this frame draws from — see `frameLayout` in `layout.ts`. */\n from: CodeLayout;\n to: CodeLayout;\n edit: StructuralTransition | null;\n /** Per-token opacity from `resolveTokenStates` (persistent highlight + any active dim transition). */\n tokenStates: Map<number, TokenState>;\n /** Whether a highlight (persistent dim, or a highlight()/resetHighlight() cross-fade) is currently engaged. */\n highlightActive: boolean;\n /** The settled row bands, and the change between two sets of them in flight, if any. */\n rowBands?: RowBand[];\n rowsEdit?: RowsTransition | null;\n /** The node's laid-out width, which a band spans when it is wider than the block. */\n boxW?: number;\n}\n\n/** What a frame is drawn onto: somewhere to draw, and the face's measurements. A render context is one. */\nexport type CodeCanvas = Pick<RenderContext2D, \"draw\" | \"measureText\">;\n\n/**\n * Draw one frame of a code listing: the settled structure, or — mid\n * structural edit — the two structures it is interpolating between (what\n * stays reflows, what is leaving fades out where it was, what is arriving\n * fades/slides in where it lands). Pure over `state`; touches nothing but\n * `draw`.\n */\nexport function drawCode(draw: CodeCanvas, state: DrawCodeState): void {\n const { tokenLines, metrics, advanceCache, from, to, edit, tokenStates: dim } = state;\n\n const progress = edit ? edit.progress : 1;\n const pOut = edit ? windowProgress(edit.phases.out, progress) : 1;\n const pMove = moveProgress(edit);\n const pIn = edit ? windowProgress(edit.phases.in, progress) : 1;\n\n const blockW = edit ? lerpNumber(from.blockW, to.blockW, pMove) : to.blockW;\n const gutter = edit ? lerpNumber(from.gutter, to.gutter, pMove) : to.gutter;\n const gutterGap = to.gutterGap || from.gutterGap;\n // Right edge of the line-number column: one gap to the left of where the\n // code text begins.\n const numberRight = -blockW / 2 + metrics.padding.left + gutter - gutterGap;\n\n drawRowBands(draw, state, Math.max(blockW, state.boxW ?? 0), pMove);\n\n const drawNumber = (label: string, y: number, opacity: number): void => {\n if (opacity <= 0) return;\n const labelW = advanceCache.advance(draw, label, metrics.fontSize, metrics.fontFamily, 0);\n draw.draw(new Graphics2D()\n .text({\n text: label,\n fontSize: metrics.fontSize,\n fontFamily: metrics.fontFamily,\n lineHeight: metrics.lineHeight,\n x: numberRight - labelW / 2,\n y,\n textAlign: 'left',\n })\n .fill([{ type: \"solid\", color: LINE_NUMBER_COLOR, opacity }]));\n };\n\n const drawToken = (text: string, x: number, y: number, color: NormalizedColor, opacity: number): void => {\n if (opacity <= 0 || text.length === 0) return;\n const width = advanceCache.advance(draw, text, metrics.fontSize, metrics.fontFamily, metrics.letterSpacing);\n draw.draw(new Graphics2D()\n .text({\n text,\n fontSize: metrics.fontSize,\n fontFamily: metrics.fontFamily,\n lineHeight: metrics.lineHeight,\n letterSpacing: metrics.letterSpacing,\n // The renderer centres a single-token block on the (x, y) it is\n // given, so every token is anchored at the centre of its cell\n // rather than at its left edge. Passing lineHeight makes the\n // block's height deterministic (fontSize × lineHeight) rather\n // than the font's natural metrics, so the vertical centre\n // lands exactly on the slot centre.\n x: x + width / 2,\n y,\n textAlign: 'left',\n })\n .fill([{ type: \"solid\", color, opacity }]));\n };\n\n // What survived the edit, and what it brought with it — drawn from the\n // structure the edit lands on.\n for (let i = 0; i < tokenLines.length; i++) {\n const line = tokenLines[i];\n const toIndex = to.lineIndex.get(line.id);\n if (toIndex === undefined) continue;\n const toY = to.lineY[toIndex];\n\n const entering = edit?.enteringLineIds.has(line.id) ?? false;\n let rowY = toY;\n let rowAlpha = 1;\n if (edit && entering) {\n // A wholly new row fades as one piece, in the place it lands — the\n // line arrives, it does not travel to get there, and it is not a\n // spray of glyphs each finding its own way in. See\n // `StructuralTransition.enteringLineIds`.\n rowAlpha = pIn;\n } else if (edit) {\n const fromIndex = from.lineIndex.get(line.id);\n if (fromIndex !== undefined) rowY = lerpNumber(from.lineY[fromIndex], toY, pMove);\n }\n\n for (const token of line.tokens) {\n const box = to.tokens.get(token.id);\n if (!box) continue;\n\n let x = box.x;\n let alpha = rowAlpha;\n let color = tokenColor(token.color);\n\n if (edit && !entering) {\n if (edit.addedIds.has(token.id)) {\n // Spliced into a row that already existed: the reflow\n // already opened the space, so this only has to appear.\n alpha = pIn;\n } else {\n const was = from.tokens.get(token.id);\n if (was) x = lerpNumber(was.x, box.x, pMove);\n if (edit.fromColorById.has(token.id)) {\n color = lerpColor(tokenColor(edit.fromColorById.get(token.id)), color, pMove);\n }\n }\n }\n\n drawToken(token.content, x, rowY, color, alpha * (dim.get(token.id)?.opacity ?? 1));\n }\n }\n\n // What the edit takes away, drawn from the structure it is leaving — it\n // has no place in the new one, which is the whole reason it is fading.\n if (edit && pOut < 1) {\n for (let i = 0; i < edit.from.length; i++) {\n const line = edit.from[i];\n const fromIndex = from.lineIndex.get(line.id);\n if (fromIndex === undefined) continue;\n const toIndex = to.lineIndex.get(line.id);\n // A row that survived the edit is still moving, so its outgoing\n // tokens travel with it; a deleted row stays where it was and\n // dissolves while the rows below close over it.\n const y = toIndex === undefined\n ? from.lineY[fromIndex]\n : lerpNumber(from.lineY[fromIndex], to.lineY[toIndex], pMove);\n\n for (const token of line.tokens) {\n if (!edit.removedIds.has(token.id)) continue;\n const box = from.tokens.get(token.id);\n if (!box) continue;\n drawToken(token.content, box.x, y, tokenColor(token.color), 1 - pOut);\n }\n }\n }\n\n if (metrics.showLineNumbers) drawLineNumbers(state, drawNumber, pMove, pIn, pOut);\n}\n\n/** A band's top and bottom edge this frame, or `null` when neither of its rows is in the listing any more. */\nfunction bandEdges(band: RowBand, state: DrawCodeState, pMove: number): { top: number; bottom: number } | null {\n const { from, to, metrics } = state;\n const half = (metrics.fontSize * metrics.lineHeight) / 2;\n const centre = (id: number): number | null => {\n const toIndex = to.lineIndex.get(id);\n const fromIndex = from.lineIndex.get(id);\n if (toIndex !== undefined && fromIndex !== undefined) return lerpNumber(from.lineY[fromIndex], to.lineY[toIndex], pMove);\n if (toIndex !== undefined) return to.lineY[toIndex];\n return fromIndex === undefined ? null : from.lineY[fromIndex];\n };\n const first = centre(band.startId);\n const last = centre(band.endId);\n if (first === null && last === null) return null;\n return { top: (first ?? last as number) + half, bottom: (last ?? first as number) - half };\n}\n\n/**\n * Draw the row bands, under the text and across the whole block. A band rides\n * its rows through a structural edit; between two sets, bands paired by position\n * slide and recolour while an unpaired one fades.\n */\nfunction drawRowBands(draw: CodeCanvas, state: DrawCodeState, width: number, pMove: number): void {\n const { rowBands = [], rowsEdit = null } = state;\n const paint = (top: number, bottom: number, color: NormalizedColor, radius: number, opacity: number): void => {\n if (opacity <= 0 || top <= bottom) return;\n draw.draw(new Graphics2D()\n .rect({ x: 0, y: (top + bottom) / 2, width, height: top - bottom, cornerRadius: radius })\n .fill([{ type: \"solid\", color, opacity }]));\n };\n\n if (!rowsEdit) {\n for (const band of rowBands) {\n const edges = bandEdges(band, state, pMove);\n if (edges) paint(edges.top, edges.bottom, band.color, band.radius, 1);\n }\n return;\n }\n\n const p = rowsEdit.progress;\n for (let i = 0; i < Math.max(rowsEdit.from.length, rowsEdit.to.length); i++) {\n const was = rowsEdit.from[i];\n const next = rowsEdit.to[i];\n const a = was ? bandEdges(was, state, pMove) : null;\n const b = next ? bandEdges(next, state, pMove) : null;\n if (a && b) {\n paint(\n lerpNumber(a.top, b.top, p), lerpNumber(a.bottom, b.bottom, p),\n lerpColor(was.color, next.color, p), lerpNumber(was.radius, next.radius, p), 1,\n );\n } else if (a) {\n paint(a.top, a.bottom, was.color, was.radius, 1 - p);\n } else if (b) {\n paint(b.top, b.bottom, next.color, next.radius, p);\n }\n }\n}\n\n/**\n * Draw the gutter — one number per *slot*, not one per row.\n *\n * That distinction is the whole of it. A line number is an ordinal of the\n * block: \"3\" means the third line, and it is there for exactly as long as the\n * listing has a third line. Drawing it alongside the row it labels — the\n * obvious thing, since that is where it appears — tied it to the row's identity\n * instead, so a line rewritten past the point the diff could pair it took its\n * number down with it and brought an identical one back up. The number blinked\n * although it had never gone away, and every substantially rewritten line did\n * it at once.\n *\n * Numbering the slots means only the numbers at the end move at all: those the\n * block grew to reach fade in, those it shrank past fade out, and every number\n * both structures have simply travels to its new row height. Which is also the\n * honest reading of the edit — inserting a line in the middle does not make a\n * new number appear there, it makes the block one line longer.\n */\nfunction drawLineNumbers(\n state: DrawCodeState,\n drawNumber: (label: string, y: number, opacity: number) => void,\n pMove: number,\n pIn: number,\n pOut: number,\n): void {\n const { tokenLines, from, to, edit, tokenStates: dim, highlightActive } = state;\n\n const toCount = tokenLines.length;\n const fromCount = edit ? edit.from.length : toCount;\n\n for (let i = 0; i < Math.max(fromCount, toCount); i++) {\n const inFrom = i < fromCount;\n const inTo = i < toCount;\n // Highlight dimming follows whatever content occupies the slot, which\n // is the new listing wherever there is one.\n const line = inTo ? tokenLines[i] : edit?.from[i];\n const dimming = line ? lineHighlightOpacity(line, dim, highlightActive) : 1;\n\n if (!edit) drawNumber(String(i + 1), to.lineY[i], dimming);\n else if (inFrom && inTo) drawNumber(String(i + 1), lerpNumber(from.lineY[i], to.lineY[i], pMove), dimming);\n else if (inTo) drawNumber(String(i + 1), to.lineY[i], pIn * dimming);\n else drawNumber(String(i + 1), from.lineY[i], (1 - pOut) * dimming);\n }\n}\n"]}
1
+ {"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,UAAU,EAAmB,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGzG,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAI7D,MAAM,mBAAmB,GAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACnE,MAAM,iBAAiB,GAAoB,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAEhE,+EAA+E;AAC/E,MAAM,UAAU,GAAG,IAAI,GAAG,EAA2B,CAAC;AACtD,SAAS,UAAU,CAAC,GAAuB;IACvC,IAAI,CAAC,GAAG;QAAE,OAAO,mBAAmB,CAAC;IACrC,IAAI,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QACtB,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC7B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CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;aACtG,IAAI,IAAI;YAAE,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC;;YAChE,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;IACxE,CAAC;AACL,CAAC","sourcesContent":["import { RenderContext2D, Graphics2D, NormalizedColor, parseColor, lerpNumber } from \"@motionscript/sdk\";\nimport type { CodeLayout, CodeMetrics } from \"./layout\";\nimport type { IdLine } from \"./tokens\";\nimport { windowProgress, moveProgress } from \"./transitions\";\nimport type { TokenState, StructuralTransition, RowBand, RowsTransition } from \"./transitions\";\nimport type { TokenAdvanceCache } from \"./measure-cache\";\n\nconst DEFAULT_TOKEN_COLOR: NormalizedColor = [0.82, 0.84, 0.86, 1];\nconst LINE_NUMBER_COLOR: NormalizedColor = [0.45, 0.5, 0.55, 1];\n\n// A listing asks for the same few theme colours on every token of every frame.\nconst colorCache = new Map<string, NormalizedColor>();\nfunction tokenColor(css: string | undefined): NormalizedColor {\n if (!css) return DEFAULT_TOKEN_COLOR;\n let hit = colorCache.get(css);\n if (!hit) {\n hit = parseColor(css);\n colorCache.set(css, hit);\n }\n return hit;\n}\n\nfunction lerpColor(from: NormalizedColor, to: NormalizedColor, t: number): NormalizedColor {\n if (t <= 0) return from;\n if (t >= 1) return to;\n return [\n from[0] + (to[0] - from[0]) * t,\n from[1] + (to[1] - from[1]) * t,\n from[2] + (to[2] - from[2]) * t,\n from[3] + (to[3] - from[3]) * t,\n ];\n}\n\n// A number stays bright only when the whole line is highlighted, so it takes the line's minimum token opacity.\nfunction lineHighlightOpacity(line: IdLine, stateById: Map<number, TokenState>, highlightActive: boolean): number {\n if (!highlightActive) return 1;\n let min = 1;\n for (const tok of line.tokens) {\n if (tok.content.length === 0) continue;\n const op = stateById.get(tok.id)?.opacity ?? 1;\n if (op < min) min = op;\n }\n return min;\n}\n\n/** What a `Code` node supplies to draw one frame. */\nexport interface DrawCodeState {\n tokenLines: IdLine[];\n metrics: CodeMetrics;\n advanceCache: TokenAdvanceCache;\n from: CodeLayout;\n to: CodeLayout;\n edit: StructuralTransition | null;\n tokenStates: Map<number, TokenState>;\n /** A persistent dim or a highlight cross-fade is engaged. */\n highlightActive: boolean;\n rowBands?: RowBand[];\n rowsEdit?: RowsTransition | null;\n /** A band spans this when it is wider than the block. */\n boxW?: number;\n}\n\n/** Somewhere to draw and the face's measurements; a render context is one. */\nexport type CodeCanvas = Pick<RenderContext2D, \"draw\" | \"measureText\">;\n\n/** Draws the settled structure, or mid-edit the two it interpolates between. Pure over `state`. */\nexport function drawCode(draw: CodeCanvas, state: DrawCodeState): void {\n const { tokenLines, metrics, advanceCache, from, to, edit, tokenStates: dim } = state;\n\n const progress = edit ? edit.progress : 1;\n const pOut = edit ? windowProgress(edit.phases.out, progress) : 1;\n const pMove = moveProgress(edit);\n const pIn = edit ? windowProgress(edit.phases.in, progress) : 1;\n\n const blockW = edit ? lerpNumber(from.blockW, to.blockW, pMove) : to.blockW;\n const gutter = edit ? lerpNumber(from.gutter, to.gutter, pMove) : to.gutter;\n const gutterGap = to.gutterGap || from.gutterGap;\n const numberRight = -blockW / 2 + metrics.padding.left + gutter - gutterGap;\n\n drawRowBands(draw, state, Math.max(blockW, state.boxW ?? 0), pMove);\n\n const drawNumber = (label: string, y: number, opacity: number): void => {\n if (opacity <= 0) return;\n const labelW = advanceCache.advance(draw, label, metrics.fontSize, metrics.fontFamily, 0);\n draw.draw(new Graphics2D()\n .text({\n text: label,\n fontSize: metrics.fontSize,\n fontFamily: metrics.fontFamily,\n lineHeight: metrics.lineHeight,\n x: numberRight - labelW / 2,\n y,\n textAlign: 'left',\n })\n .fill([{ type: \"solid\", color: LINE_NUMBER_COLOR, opacity }]));\n };\n\n const drawToken = (text: string, x: number, y: number, color: NormalizedColor, opacity: number): void => {\n if (opacity <= 0 || text.length === 0) return;\n const width = advanceCache.advance(draw, text, metrics.fontSize, metrics.fontFamily, metrics.letterSpacing);\n draw.draw(new Graphics2D()\n .text({\n text,\n fontSize: metrics.fontSize,\n fontFamily: metrics.fontFamily,\n lineHeight: metrics.lineHeight,\n letterSpacing: metrics.letterSpacing,\n // The renderer centres a single-token block on the (x, y) it is\n // given, so every token is anchored at the centre of its cell\n // rather than at its left edge. Passing lineHeight makes the\n // block's height deterministic (fontSize × lineHeight) rather\n // than the font's natural metrics, so the vertical centre\n // lands exactly on the slot centre.\n x: x + width / 2,\n y,\n textAlign: 'left',\n })\n .fill([{ type: \"solid\", color, opacity }]));\n };\n\n // Survivors and arrivals, from the structure the edit lands on.\n for (let i = 0; i < tokenLines.length; i++) {\n const line = tokenLines[i];\n const toIndex = to.lineIndex.get(line.id);\n if (toIndex === undefined) continue;\n const toY = to.lineY[toIndex];\n\n const entering = edit?.enteringLineIds.has(line.id) ?? false;\n let rowY = toY;\n let rowAlpha = 1;\n if (edit && entering) {\n // A new row fades as one piece where it lands (see `enteringLineIds`).\n rowAlpha = pIn;\n } else if (edit) {\n const fromIndex = from.lineIndex.get(line.id);\n if (fromIndex !== undefined) rowY = lerpNumber(from.lineY[fromIndex], toY, pMove);\n }\n\n for (const token of line.tokens) {\n const box = to.tokens.get(token.id);\n if (!box) continue;\n\n let x = box.x;\n let alpha = rowAlpha;\n let color = tokenColor(token.color);\n\n if (edit && !entering) {\n if (edit.addedIds.has(token.id)) {\n // Spliced into an existing row: the reflow opened the space already.\n alpha = pIn;\n } else {\n const was = from.tokens.get(token.id);\n if (was) x = lerpNumber(was.x, box.x, pMove);\n if (edit.fromColorById.has(token.id)) {\n color = lerpColor(tokenColor(edit.fromColorById.get(token.id)), color, pMove);\n }\n }\n }\n\n drawToken(token.content, x, rowY, color, alpha * (dim.get(token.id)?.opacity ?? 1));\n }\n }\n\n // What the edit takes away, from the structure it is leaving.\n if (edit && pOut < 1) {\n for (let i = 0; i < edit.from.length; i++) {\n const line = edit.from[i];\n const fromIndex = from.lineIndex.get(line.id);\n if (fromIndex === undefined) continue;\n const toIndex = to.lineIndex.get(line.id);\n // A surviving row's outgoing tokens travel with it; a deleted row dissolves in place.\n const y = toIndex === undefined\n ? from.lineY[fromIndex]\n : lerpNumber(from.lineY[fromIndex], to.lineY[toIndex], pMove);\n\n for (const token of line.tokens) {\n if (!edit.removedIds.has(token.id)) continue;\n const box = from.tokens.get(token.id);\n if (!box) continue;\n drawToken(token.content, box.x, y, tokenColor(token.color), 1 - pOut);\n }\n }\n }\n\n if (metrics.showLineNumbers) drawLineNumbers(state, drawNumber, pMove, pIn, pOut);\n}\n\n/** A band's top and bottom edge this frame, or `null` when neither of its rows is in the listing any more. */\nfunction bandEdges(band: RowBand, state: DrawCodeState, pMove: number): { top: number; bottom: number } | null {\n const { from, to, metrics } = state;\n const half = (metrics.fontSize * metrics.lineHeight) / 2;\n const centre = (id: number): number | null => {\n const toIndex = to.lineIndex.get(id);\n const fromIndex = from.lineIndex.get(id);\n if (toIndex !== undefined && fromIndex !== undefined) return lerpNumber(from.lineY[fromIndex], to.lineY[toIndex], pMove);\n if (toIndex !== undefined) return to.lineY[toIndex];\n return fromIndex === undefined ? null : from.lineY[fromIndex];\n };\n const first = centre(band.startId);\n const last = centre(band.endId);\n if (first === null && last === null) return null;\n return { top: (first ?? last as number) + half, bottom: (last ?? first as number) - half };\n}\n\n/** Bands ride their rows through an edit; between two sets, those paired by position slide and recolour and an unpaired one fades. */\nfunction drawRowBands(draw: CodeCanvas, state: DrawCodeState, width: number, pMove: number): void {\n const { rowBands = [], rowsEdit = null } = state;\n const paint = (top: number, bottom: number, color: NormalizedColor, radius: number, opacity: number): void => {\n if (opacity <= 0 || top <= bottom) return;\n draw.draw(new Graphics2D()\n .rect({ x: 0, y: (top + bottom) / 2, width, height: top - bottom, cornerRadius: radius })\n .fill([{ type: \"solid\", color, opacity }]));\n };\n\n if (!rowsEdit) {\n for (const band of rowBands) {\n const edges = bandEdges(band, state, pMove);\n if (edges) paint(edges.top, edges.bottom, band.color, band.radius, 1);\n }\n return;\n }\n\n const p = rowsEdit.progress;\n for (let i = 0; i < Math.max(rowsEdit.from.length, rowsEdit.to.length); i++) {\n const was = rowsEdit.from[i];\n const next = rowsEdit.to[i];\n const a = was ? bandEdges(was, state, pMove) : null;\n const b = next ? bandEdges(next, state, pMove) : null;\n if (a && b) {\n paint(\n lerpNumber(a.top, b.top, p), lerpNumber(a.bottom, b.bottom, p),\n lerpColor(was.color, next.color, p), lerpNumber(was.radius, next.radius, p), 1,\n );\n } else if (a) {\n paint(a.top, a.bottom, was.color, was.radius, 1 - p);\n } else if (b) {\n paint(b.top, b.bottom, next.color, next.radius, p);\n }\n }\n}\n\n/**\n * One number per slot, not per row: \"3\" lasts as long as the listing has a third\n * line. Tied to a row's identity, a line rewritten past what the diff could pair\n * would take its number down and bring an identical one back up (a blink).\n */\nfunction drawLineNumbers(\n state: DrawCodeState,\n drawNumber: (label: string, y: number, opacity: number) => void,\n pMove: number,\n pIn: number,\n pOut: number,\n): void {\n const { tokenLines, from, to, edit, tokenStates: dim, highlightActive } = state;\n\n const toCount = tokenLines.length;\n const fromCount = edit ? edit.from.length : toCount;\n\n for (let i = 0; i < Math.max(fromCount, toCount); i++) {\n const inFrom = i < fromCount;\n const inTo = i < toCount;\n // Dimming follows the content in the slot: the new listing where there is one.\n const line = inTo ? tokenLines[i] : edit?.from[i];\n const dimming = line ? lineHighlightOpacity(line, dim, highlightActive) : 1;\n\n if (!edit) drawNumber(String(i + 1), to.lineY[i], dimming);\n else if (inFrom && inTo) drawNumber(String(i + 1), lerpNumber(from.lineY[i], to.lineY[i], pMove), dimming);\n else if (inTo) drawNumber(String(i + 1), to.lineY[i], pIn * dimming);\n else drawNumber(String(i + 1), from.lineY[i], (1 - pOut) * dimming);\n }\n}\n"]}
package/dist/style.d.ts CHANGED
@@ -1,68 +1,22 @@
1
1
  import { Highlighter, Tag } from "@lezer/highlight";
2
- /**
3
- * A single style rule: map one or more Lezer highlight {@link Tag}s to a color.
4
- * This mirrors a `@codemirror/language` HighlightStyle entry, but instead of
5
- * emitting CSS class names it carries the color directly — we render to a canvas,
6
- * not the DOM, so there is no stylesheet to resolve against.
7
- */
2
+ /** Lezer highlight {@link Tag}s mapped to a color; a canvas has no stylesheet, so the color is carried directly. */
8
3
  export interface CodeStyleRule {
9
4
  tag: Tag | readonly Tag[];
10
5
  color: string;
11
6
  }
12
- /**
13
- * A code theme: an ordered list of tag→color rules plus a fallback color for any
14
- * text the parser produces no highlight tag for (operators, punctuation, plain
15
- * identifiers in some grammars, etc.). Pass a custom one via the Code node's
16
- * `theme` prop to recolor highlighting without touching the highlighter wiring.
17
- *
18
- * @remarks
19
- * Later rules win when several match the same tag, matching how
20
- * `@lezer/highlight`'s {@link tagHighlighter} resolves precedence.
21
- */
7
+ /** Ordered tag rules plus a fallback color; later rules win when several match a tag, as in {@link tagHighlighter}. */
22
8
  export interface CodeHighlightStyle {
23
- /** Stable name, used to register the style and to refer to it from a `theme` prop. */
9
+ /** Registers the style and names it in a `theme` prop. */
24
10
  name: string;
25
- /** Color applied to text with no matching tag. */
11
+ /** For text with no matching tag. */
26
12
  defaultColor: string;
27
13
  rules: CodeStyleRule[];
28
14
  }
29
- /**
30
- * Motion Canvas's default highlight palette (a Nord-derived theme), ported from
31
- * `@motion-canvas/2d`'s DefaultHighlightStyle so highlighting matches Motion
32
- * Canvas token-for-token. Colors and tag groupings are kept identical; only the
33
- * shape changes (color strings in place of CSS rules).
34
- */
35
15
  export declare const DefaultHighlightStyle: CodeHighlightStyle;
36
- /**
37
- * GitHub Dark highlight palette, adapted from `@uiw/codemirror-theme-github`.
38
- * `defaultColor` is GitHub's editor foreground (`#c9d1d9`), used for any text the
39
- * parser tags don't cover. DOM-only style props (backgroundColor, textDecoration,
40
- * fontWeight, fontStyle) are dropped — we only color tokens on the canvas.
41
- */
42
16
  export declare const GithubDarkStyle: CodeHighlightStyle;
43
- /**
44
- * GitHub Light highlight palette, adapted from `@uiw/codemirror-theme-github`.
45
- * `defaultColor` is GitHub's editor foreground (`#24292e`). See {@link GithubDarkStyle}
46
- * for the note on dropped DOM-only style props.
47
- */
48
17
  export declare const GithubLightStyle: CodeHighlightStyle;
49
- /**
50
- * VS Code Dark+ highlight palette, adapted from the `@uiw/codemirror-theme-vscode`
51
- * snippet. `defaultColor` is VS Code's editor foreground (`#9cdcfe`). DOM-only
52
- * style props are dropped; later rules win, matching {@link tagHighlighter}.
53
- */
54
18
  export declare const VscodeDarkStyle: CodeHighlightStyle;
55
- /**
56
- * VS Code Light+ highlight palette, adapted from the `@uiw/codemirror-theme-vscode`
57
- * snippet. `defaultColor` is VS Code's editor foreground (`#383a42`). See
58
- * {@link VscodeDarkStyle} for the note on dropped DOM-only style props.
59
- */
60
19
  export declare const VscodeLightStyle: CodeHighlightStyle;
61
- /**
62
- * The built-in themes, keyed by their string name. {@link CodeThemeName} is the
63
- * union of these keys — pass one of those strings (or any {@link CodeHighlightStyle}
64
- * object) to a Code node's `theme` prop.
65
- */
66
20
  export declare const BUILTIN_THEMES: {
67
21
  "motion-canvas-default": CodeHighlightStyle;
68
22
  "github-dark": CodeHighlightStyle;
@@ -72,17 +26,8 @@ export declare const BUILTIN_THEMES: {
72
26
  };
73
27
  /** Names of the built-in themes, e.g. `'github-dark' | 'github-light'`. */
74
28
  export type CodeThemeName = keyof typeof BUILTIN_THEMES;
75
- /**
76
- * What a Code node's `theme` prop accepts: a built-in theme name (with
77
- * autocomplete), any other registered theme name, or a {@link CodeHighlightStyle}
78
- * object passed inline. The `string & {}` keeps the literal-name suggestions while
79
- * still allowing arbitrary registered names.
80
- */
29
+ /** A built-in name, any registered name, or a style inline; `string & {}` keeps the autocomplete for the built-in names. */
81
30
  export type CodeTheme = CodeThemeName | (string & {}) | CodeHighlightStyle;
82
- /**
83
- * Compile a {@link CodeHighlightStyle} into a `@lezer/highlight` {@link Highlighter}
84
- * whose "class" output is the literal color string for each tag. Cached per style
85
- * object so repeated lookups (every tokenize) don't rebuild the matcher.
86
- */
31
+ /** A {@link Highlighter} whose "class" output is the color string for each tag. */
87
32
  export declare function compileStyle(style: CodeHighlightStyle): Highlighter;
88
33
  //# sourceMappingURL=style.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,GAAG,EAA6B,MAAM,kBAAkB,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC1B,GAAG,EAAE,GAAG,GAAG,SAAS,GAAG,EAAE,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,kBAAkB;IAC/B,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,EAAE,kBAwCnC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,kBAiB7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,kBAkB9B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,kBAgC7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,kBAgC9B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc;;;;;;CAQmB,CAAC;AAE/C,2EAA2E;AAC3E,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,cAAc,CAAC;AAExD;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,kBAAkB,CAAC;AAU3E;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,kBAAkB,GAAG,WAAW,CAQnE"}
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,GAAG,EAA6B,MAAM,kBAAkB,CAAC;AAE/E,oHAAoH;AACpH,MAAM,WAAW,aAAa;IAC1B,GAAG,EAAE,GAAG,GAAG,SAAS,GAAG,EAAE,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,uHAAuH;AACvH,MAAM,WAAW,kBAAkB;IAC/B,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,aAAa,EAAE,CAAC;CAC1B;AAID,eAAO,MAAM,qBAAqB,EAAE,kBAwCnC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,kBAiB7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,kBAkB9B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,kBAgC7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,kBAgC9B,CAAC;AAEF,eAAO,MAAM,cAAc;;;;;;CAQmB,CAAC;AAE/C,2EAA2E;AAC3E,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,cAAc,CAAC;AAExD,4HAA4H;AAC5H,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,kBAAkB,CAAC;AAQ3E,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,KAAK,EAAE,kBAAkB,GAAG,WAAW,CAQnE"}
package/dist/style.js CHANGED
@@ -1,10 +1,6 @@
1
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
- */
2
+ // The default palette is ported from `@motion-canvas/2d`; the GitHub and VS Code ones are adapted from
3
+ // `@uiw/codemirror-theme-github` and `-vscode`, with their DOM-only style props dropped.
8
4
  export const DefaultHighlightStyle = {
9
5
  name: "motion-canvas-default",
10
6
  defaultColor: "#d8dee9",
@@ -46,12 +42,6 @@ export const DefaultHighlightStyle = {
46
42
  { tag: t.invalid, color: "#434c5e" },
47
43
  ],
48
44
  };
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
45
  export const GithubDarkStyle = {
56
46
  name: "github-dark",
57
47
  defaultColor: "#c9d1d9",
@@ -70,11 +60,6 @@ export const GithubDarkStyle = {
70
60
  { tag: t.invalid, color: "#f97583" },
71
61
  ],
72
62
  };
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
63
  export const GithubLightStyle = {
79
64
  name: "github-light",
80
65
  defaultColor: "#24292e",
@@ -94,11 +79,6 @@ export const GithubLightStyle = {
94
79
  { tag: t.invalid, color: "#cb2431" },
95
80
  ],
96
81
  };
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
82
  export const VscodeDarkStyle = {
103
83
  name: "vscode-dark",
104
84
  defaultColor: "#9cdcfe",
@@ -132,11 +112,6 @@ export const VscodeDarkStyle = {
132
112
  { tag: t.invalid, color: "#ff0000" },
133
113
  ],
134
114
  };
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
115
  export const VscodeLightStyle = {
141
116
  name: "vscode-light",
142
117
  defaultColor: "#383a42",
@@ -170,11 +145,6 @@ export const VscodeLightStyle = {
170
145
  { tag: t.invalid, color: "#e45649" },
171
146
  ],
172
147
  };
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
148
  export const BUILTIN_THEMES = {
179
149
  // Literal keys (not computed from `.name`) so `keyof` yields a string-literal
180
150
  // union for CodeThemeName; these must stay in sync with each style's `name`.
@@ -184,18 +154,12 @@ export const BUILTIN_THEMES = {
184
154
  "vscode-dark": VscodeDarkStyle,
185
155
  "vscode-light": VscodeLightStyle,
186
156
  };
187
- // Cache one compiled Highlighter per style *object*. Compiling builds a tag-rule
188
- // matcher; the parsed result is pure data so it's safe to share across Code nodes.
189
- // Keyed by the object rather than its `name`: two styles may share a name (an
157
+ // One compiled Highlighter per style *object*, keyed by the object rather than its `name`: two styles may share a name (an
190
158
  // inline theme, or one re-registered under the same name with new colours), and
191
159
  // the second must not colour with the first one's rules. A WeakMap, so a style
192
160
  // nothing refers to any more takes its matcher with it.
193
161
  const compiledByStyle = new WeakMap();
194
- /**
195
- * Compile a {@link CodeHighlightStyle} into a `@lezer/highlight` {@link Highlighter}
196
- * whose "class" output is the literal color string for each tag. Cached per style
197
- * object so repeated lookups (every tokenize) don't rebuild the matcher.
198
- */
162
+ /** A {@link Highlighter} whose "class" output is the color string for each tag. */
199
163
  export function compileStyle(style) {
200
164
  const cached = compiledByStyle.get(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YAAY,CAAC,KAAyB;IAClD,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC1C,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,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IACxC,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 to register the style and to refer to it from a `theme` prop. */\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 *object*. Compiling builds a tag-rule\n// matcher; the parsed result is pure data so it's safe to share across Code nodes.\n// Keyed by the object rather than its `name`: two styles may share a name (an\n// inline theme, or one re-registered under the same name with new colours), and\n// the second must not colour with the first one's rules. A WeakMap, so a style\n// nothing refers to any more takes its matcher with it.\nconst compiledByStyle = new WeakMap<CodeHighlightStyle, 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 per style\n * object so repeated lookups (every tokenize) don't rebuild the matcher.\n */\nexport function compileStyle(style: CodeHighlightStyle): Highlighter {\n const cached = compiledByStyle.get(style);\n if (cached) return cached;\n const highlighter = tagHighlighter(\n style.rules.map(rule => ({ tag: rule.tag, class: rule.color })),\n );\n compiledByStyle.set(style, highlighter);\n return highlighter;\n}\n"]}
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;AAiB/E,uGAAuG;AACvG,yFAAyF;AACzF,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,E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Lezer highlight {@link Tag}s mapped to a color; a canvas has no stylesheet, so the color is carried directly. */\nexport interface CodeStyleRule {\n tag: Tag | readonly Tag[];\n color: string;\n}\n\n/** Ordered tag rules plus a fallback color; later rules win when several match a tag, as in {@link tagHighlighter}. */\nexport interface CodeHighlightStyle {\n /** Registers the style and names it in a `theme` prop. */\n name: string;\n /** For text with no matching tag. */\n defaultColor: string;\n rules: CodeStyleRule[];\n}\n\n// The default palette is ported from `@motion-canvas/2d`; the GitHub and VS Code ones are adapted from\n// `@uiw/codemirror-theme-github` and `-vscode`, with their DOM-only style props dropped.\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\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\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\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\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\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/** A built-in name, any registered name, or a style inline; `string & {}` keeps the autocomplete for the built-in names. */\nexport type CodeTheme = CodeThemeName | (string & {}) | CodeHighlightStyle;\n\n// One compiled Highlighter per style *object*, keyed by the object rather than its `name`: two styles may share a name (an\n// inline theme, or one re-registered under the same name with new colours), and\n// the second must not colour with the first one's rules. A WeakMap, so a style\n// nothing refers to any more takes its matcher with it.\nconst compiledByStyle = new WeakMap<CodeHighlightStyle, Highlighter>();\n\n/** A {@link Highlighter} whose \"class\" output is the color string for each tag. */\nexport function compileStyle(style: CodeHighlightStyle): Highlighter {\n const cached = compiledByStyle.get(style);\n if (cached) return cached;\n const highlighter = tagHighlighter(\n style.rules.map(rule => ({ tag: rule.tag, class: rule.color })),\n );\n compiledByStyle.set(style, highlighter);\n return highlighter;\n}\n"]}
package/dist/tokens.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { CodeTheme } from "./style.js";
2
+ /** A highlighter token with a stable identity: animation state is keyed by `id`, so concurrent edits at different positions don't clobber each other. */
2
3
  export interface IdToken {
3
4
  id: number;
4
5
  content: string;
@@ -11,14 +12,4 @@ export interface IdLine {
11
12
  export declare function makeIdToken(content: string, color?: string): IdToken;
12
13
  export declare function makeIdLine(tokens: IdToken[]): IdLine;
13
14
  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
15
  //# sourceMappingURL=tokens.d.ts.map
@@ -1 +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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