@gjermundgaraba/clankermux 0.5.0 → 0.7.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 (40) hide show
  1. package/README.md +1 -1
  2. package/dist/client/attachment.d.ts +9 -29
  3. package/dist/client/attachment.js +28 -41
  4. package/dist/client/client.d.ts +0 -2
  5. package/dist/client/client.js +6 -11
  6. package/dist/client/connection.d.ts +1 -19
  7. package/dist/client/connection.js +0 -17
  8. package/dist/client/copy.d.ts +0 -14
  9. package/dist/client/copy.js +4 -25
  10. package/dist/client/keyboard.d.ts +1 -27
  11. package/dist/client/keyboard.js +18 -34
  12. package/dist/client/link.d.ts +143 -0
  13. package/dist/client/link.js +205 -0
  14. package/dist/client/listeners.d.ts +3 -1
  15. package/dist/client/listeners.js +20 -4
  16. package/dist/client/mount.d.ts +0 -5
  17. package/dist/client/mount.js +20 -72
  18. package/dist/client/osc52.d.ts +1 -4
  19. package/dist/client/osc52.js +20 -17
  20. package/dist/client/profile.d.ts +0 -6
  21. package/dist/client/profile.js +0 -6
  22. package/dist/client/worker.d.ts +3 -44
  23. package/dist/client/worker.js +185 -332
  24. package/dist/engine/decoder.d.ts +0 -20
  25. package/dist/engine/decoder.js +8 -27
  26. package/dist/engine/index.d.ts +2 -49
  27. package/dist/engine/index.js +7 -48
  28. package/dist/engine/keys.d.ts +0 -7
  29. package/dist/engine/keys.js +9 -15
  30. package/dist/engine/render.d.ts +7 -18
  31. package/dist/engine/render.js +32 -32
  32. package/dist/engine/selection.d.ts +0 -17
  33. package/dist/engine/selection.js +8 -30
  34. package/dist/proto/frame.d.ts +2 -23
  35. package/dist/proto/frame.js +1 -21
  36. package/dist/proto/messages.d.ts +49 -9
  37. package/dist/proto/messages.js +42 -1
  38. package/dist/renderer/index.d.ts +3 -4
  39. package/dist/renderer/index.js +38 -42
  40. package/package.json +5 -6
@@ -1,10 +1,7 @@
1
- import { FLAG, NO_COLOR, PACKED_STRIDE, packedText } from "../engine/render.js";
1
+ import { FLAG, NO_COLOR, PACKED_BG, PACKED_FG, PACKED_FLAGS_MASK, PACKED_STRIDE, PACKED_STYLE, PACKED_UNDERLINE_SHIFT, packedText, } from "../engine/render.js";
2
2
  const hex = (color) => `#${color.toString(16).padStart(6, "0")}`;
3
- /** A cell or cursor colour, or `fallback` when it has none. */
4
3
  const css = (color, fallback) => (color === NO_COLOR ? fallback : hex(color));
5
- /** Width in CSS pixels of the mark at the right edge that shows the view
6
- * scrolled back, and where it is in the history. */
7
- const MARK_WIDTH = 3;
4
+ const SCROLLBACK_MARK_WIDTH_PX = 3;
8
5
  /**
9
6
  * Draws frames onto a 2D context: changed rows only, then the cursor, then
10
7
  * the scrollback mark. Rows are cached so the rows the cursor or the mark
@@ -16,8 +13,7 @@ export class CanvasRenderer {
16
13
  palette;
17
14
  rows = new Map();
18
15
  cursorRow;
19
- /** The scrollback mark drawn last, in pixels from the top. */
20
- mark;
16
+ lastScrollbackMark;
21
17
  cols = 0;
22
18
  background = "";
23
19
  foreground = "";
@@ -27,13 +23,12 @@ export class CanvasRenderer {
27
23
  this.palette = palette;
28
24
  }
29
25
  draw(frame) {
30
- // The frame always carries the default colours.
31
26
  this.background = hex(frame.background);
32
27
  this.foreground = hex(frame.foreground);
33
28
  if (frame.full || frame.cols !== this.cols) {
34
29
  this.cols = frame.cols;
35
30
  this.rows.clear();
36
- this.mark = undefined;
31
+ this.lastScrollbackMark = undefined;
37
32
  this.ctx.globalAlpha = 1;
38
33
  this.ctx.fillStyle = this.background;
39
34
  this.ctx.fillRect(0, 0, frame.cols * this.metrics.cellWidth, frame.rows * this.metrics.cellHeight);
@@ -44,28 +39,10 @@ export class CanvasRenderer {
44
39
  this.drawRow(row);
45
40
  drawn.add(row.y);
46
41
  }
47
- // The last mark is erased with the rows under it, every frame: it is
48
- // translucent, so one drawn over itself would darken.
49
42
  const mark = this.markOf(frame);
50
- if (this.mark) {
51
- const { cellHeight } = this.metrics;
52
- const last = Math.ceil((this.mark.top + this.mark.height) / cellHeight);
53
- for (let y = Math.floor(this.mark.top / cellHeight); y < last; y++) {
54
- const row = this.rows.get(y);
55
- if (row && !drawn.has(y)) {
56
- this.drawRow(row);
57
- drawn.add(y);
58
- }
59
- }
60
- }
61
- // The cursor's old row is redrawn from the cache when the cursor
62
- // moved or went away; the engine marks no row dirty for either.
43
+ this.eraseLastMark(drawn);
63
44
  const cursor = frame.cursor?.visible ? frame.cursor : undefined;
64
- if (this.cursorRow !== undefined && this.cursorRow !== cursor?.y && !drawn.has(this.cursorRow)) {
65
- const row = this.rows.get(this.cursorRow);
66
- if (row)
67
- this.drawRow(row);
68
- }
45
+ this.redrawVacatedCursorRow(cursor, drawn);
69
46
  this.cursorRow = undefined;
70
47
  if (cursor) {
71
48
  if (!drawn.has(cursor.y)) {
@@ -76,17 +53,36 @@ export class CanvasRenderer {
76
53
  this.drawCursor(cursor);
77
54
  this.cursorRow = cursor.y;
78
55
  }
79
- // Over everything, on rows just drawn.
80
- this.mark = mark;
56
+ this.lastScrollbackMark = mark;
81
57
  if (mark) {
82
58
  this.ctx.globalAlpha = 0.5;
83
59
  this.ctx.fillStyle = this.foreground;
84
- this.ctx.fillRect(this.cols * this.metrics.cellWidth - MARK_WIDTH, mark.top, MARK_WIDTH, mark.height);
60
+ this.ctx.fillRect(this.cols * this.metrics.cellWidth - SCROLLBACK_MARK_WIDTH_PX, mark.top, SCROLLBACK_MARK_WIDTH_PX, mark.height);
85
61
  this.ctx.globalAlpha = 1;
86
62
  }
87
63
  }
88
- /** The scrollback mark for `frame`: the viewport's share of the history
89
- * at the right edge, while the view is scrolled back. */
64
+ eraseLastMark(drawn) {
65
+ const last = this.lastScrollbackMark;
66
+ if (!last)
67
+ return;
68
+ const { cellHeight } = this.metrics;
69
+ const end = Math.ceil((last.top + last.height) / cellHeight);
70
+ for (let y = Math.floor(last.top / cellHeight); y < end; y++) {
71
+ const row = this.rows.get(y);
72
+ if (row && !drawn.has(y)) {
73
+ this.drawRow(row);
74
+ drawn.add(y);
75
+ }
76
+ }
77
+ }
78
+ redrawVacatedCursorRow(cursor, drawn) {
79
+ const vacated = this.cursorRow;
80
+ if (vacated === undefined || vacated === cursor?.y || drawn.has(vacated))
81
+ return;
82
+ const row = this.rows.get(vacated);
83
+ if (row)
84
+ this.drawRow(row);
85
+ }
90
86
  markOf(frame) {
91
87
  const { total, offset, len } = frame.scrollbar;
92
88
  if (offset + len >= total)
@@ -111,19 +107,20 @@ export class CanvasRenderer {
111
107
  else {
112
108
  const at = x * PACKED_STRIDE;
113
109
  text = packedText(cells, x);
114
- foreground = cells.data[at + 1];
115
- background = cells.data[at + 2];
116
- flags = cells.data[at + 3] & 0xffff;
117
- underline = cells.data[at + 3] >>> 16;
110
+ const style = cells.data[at + PACKED_STYLE];
111
+ foreground = cells.data[at + PACKED_FG];
112
+ background = cells.data[at + PACKED_BG];
113
+ flags = style & PACKED_FLAGS_MASK;
114
+ underline = style >>> PACKED_UNDERLINE_SHIFT;
118
115
  }
119
116
  if (flags & FLAG.SPACER)
120
117
  continue;
121
118
  const width = flags & FLAG.WIDE ? 2 : 1;
122
119
  let fg = css(foreground, this.foreground);
123
120
  let bg = css(background, this.background);
124
- // A selected cell is drawn inverted, an inverse one the other way.
125
121
  const selected = row.selection !== undefined && x >= row.selection[0] && x <= row.selection[1];
126
- if (((flags & FLAG.INVERSE) !== 0) !== selected)
122
+ const inverted = ((flags & FLAG.INVERSE) !== 0) !== selected;
123
+ if (inverted)
127
124
  [fg, bg] = [bg, fg];
128
125
  if (bg !== this.background) {
129
126
  this.ctx.fillStyle = bg;
@@ -179,7 +176,6 @@ export class CanvasRenderer {
179
176
  return;
180
177
  default: {
181
178
  this.ctx.fillRect(x, y, cellWidth, cellHeight);
182
- // The cell's text in the background colour, over the block.
183
179
  const cells = this.rows.get(cursor.y)?.cells;
184
180
  let text = "", flags = 0;
185
181
  if (Array.isArray(cells)) {
@@ -189,7 +185,7 @@ export class CanvasRenderer {
189
185
  }
190
186
  else if (cells && cursor.x < cells.data.length / PACKED_STRIDE) {
191
187
  text = packedText(cells, cursor.x);
192
- flags = cells.data[cursor.x * PACKED_STRIDE + 3] & 0xffff;
188
+ flags = cells.data[cursor.x * PACKED_STRIDE + PACKED_STYLE] & PACKED_FLAGS_MASK;
193
189
  }
194
190
  if (text !== "" && text !== " ") {
195
191
  this.ctx.fillStyle = this.background;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjermundgaraba/clankermux",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,10 +22,6 @@
22
22
  "types": "./dist/proto/index.d.ts",
23
23
  "default": "./dist/proto/index.js"
24
24
  },
25
- "./engine": {
26
- "types": "./dist/engine/index.d.ts",
27
- "default": "./dist/engine/index.js"
28
- },
29
25
  "./renderer": {
30
26
  "types": "./dist/renderer/index.d.ts",
31
27
  "default": "./dist/renderer/index.js"
@@ -39,10 +35,13 @@
39
35
  "publishConfig": {
40
36
  "access": "public"
41
37
  },
38
+ "dependencies": {
39
+ "xstate": "6.0.0-alpha.71"
40
+ },
42
41
  "devDependencies": {
43
42
  "@types/ws": "^8.18.0",
44
43
  "ajv": "^8.20.0",
45
- "ws": "^8.18.0"
44
+ "ws": "^8.22.2"
46
45
  },
47
46
  "scripts": {
48
47
  "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.worker.json",