@zakmandhro/bunti 0.1.2 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zakmandhro/bunti",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "A Bun-native terminal layout engine with zero dependencies, 60fps rendering, and an agent-optimized functional API.",
5
5
  "module": "src/index.ts",
6
6
  "exports": {
package/src/colors.ts CHANGED
@@ -95,9 +95,9 @@ export function hexToRGB(hex: string): RGB {
95
95
  const h = hex.replace('#', '');
96
96
  if (h.length === 3) {
97
97
  return {
98
- r: parseInt(h[0] + h[0], 16),
99
- g: parseInt(h[1] + h[1], 16),
100
- b: parseInt(h[2] + h[2], 16),
98
+ r: parseInt(h[0]! + h[0]!, 16),
99
+ g: parseInt(h[1]! + h[1]!, 16),
100
+ b: parseInt(h[2]! + h[2]!, 16),
101
101
  };
102
102
  }
103
103
  return {
@@ -166,9 +166,9 @@ export function createGradient(
166
166
  const t = globalT * segmentCount - segmentIdx;
167
167
 
168
168
  result.push({
169
- r: Math.round(start.r + (end.r - start.r) * t),
170
- g: Math.round(start.g + (end.g - start.g) * t),
171
- b: Math.round(start.b + (end.b - start.b) * t),
169
+ r: Math.round(start!.r + (end!.r - start!.r) * t),
170
+ g: Math.round(start!.g + (end!.g - start!.g) * t),
171
+ b: Math.round(start!.b + (end!.b - start!.b) * t),
172
172
  });
173
173
  }
174
174
 
package/src/dsl.ts CHANGED
@@ -194,7 +194,7 @@ function createDSLContext(
194
194
  get cursorX() {
195
195
  const currentFlow = dslState.activeContents.join('');
196
196
  const lines = currentFlow.split('\n');
197
- return visibleWidth(lines[lines.length - 1]);
197
+ return visibleWidth(lines[lines.length - 1]!);
198
198
  },
199
199
  get cursorY() {
200
200
  const currentFlow = dslState.activeContents.join('');
@@ -219,7 +219,7 @@ function createDSLContext(
219
219
  ) {
220
220
  const now = Date.now();
221
221
  const start = options.id
222
- ? this.useState(`${options.id}_start`, now)[0]
222
+ ? ctx.useState(`${options.id}_start`, now)[0]
223
223
  : state.startTime;
224
224
  const elapsed = now - start - (options.delay || 0);
225
225
  if (elapsed < 0) return 0;
@@ -316,8 +316,8 @@ function createDSLContext(
316
316
  },
317
317
 
318
318
  list(id: string, items: string[], options: ListOptions = {}) {
319
- const [selectedIndex, setSelectedIndex] = this.useState(`${id}_index`, 0);
320
- const isFocused = this.focusable(id);
319
+ const [selectedIndex, setSelectedIndex] = ctx.useState(`${id}_index`, 0);
320
+ const isFocused = ctx.focusable(id);
321
321
 
322
322
  if (isFocused && options.interactive !== false) {
323
323
  if (state.lastKey === KEYS.UP)
@@ -468,7 +468,7 @@ function createDSLContext(
468
468
  } else if (Array.isArray(input)) {
469
469
  layoutGradient(state, input);
470
470
  } else if (typeof input === 'object' && 'color' in input) {
471
- this.wallpaper(input.color);
471
+ ctx.wallpaper(input.color);
472
472
  } else {
473
473
  layoutWallpaper(state, { bg: input });
474
474
  }
package/src/layout.ts CHANGED
@@ -18,16 +18,16 @@ export function setCell(
18
18
  ) {
19
19
  if (x >= 0 && x < state.width && y >= 0 && y < state.height) {
20
20
  const target = state.backBuffer[y * state.width + x];
21
- if (cell.char !== undefined) target.char = replaceEmojis(cell.char);
21
+ if (cell.char !== undefined) target!.char = replaceEmojis(cell.char);
22
22
  if (cell.fg !== undefined) {
23
- target.fg = cell.fg;
24
- target.fgCode = resolveColor(cell.fg);
23
+ target!.fg = cell.fg;
24
+ target!.fgCode = resolveColor(cell.fg);
25
25
  }
26
26
  if (cell.bg !== undefined) {
27
- target.bg = cell.bg;
28
- target.bgCode = resolveColor(cell.bg);
27
+ target!.bg = cell.bg;
28
+ target!.bgCode = resolveColor(cell.bg);
29
29
  }
30
- if (cell.bold !== undefined) target.bold = cell.bold;
30
+ if (cell.bold !== undefined) target!.bold = cell.bold;
31
31
  }
32
32
  }
33
33
 
@@ -78,7 +78,7 @@ export function rect(
78
78
  if (style.char) cell.char = style.char;
79
79
  if (style.fg) cell.fg = resolveColor(style.fg) as any;
80
80
 
81
- const existing = state.backBuffer[row * state.width + col];
81
+ const existing = state.backBuffer[row * state.width + col]!;
82
82
  if (existing.char !== ' ' && !style.char) {
83
83
  // Keep existing char/fg if drawing a pure background
84
84
  cell.char = existing.char;
@@ -105,7 +105,7 @@ export function blit(
105
105
  let currentBold = false;
106
106
  const regex = /\x1B\[([0-9;]*)m|([^\x1B]+)/g;
107
107
  let match: RegExpExecArray | null = null;
108
- while ((match = regex.exec(line)) !== null) {
108
+ while ((match = regex.exec(line!)) !== null) {
109
109
  if (match[1] !== undefined) {
110
110
  const codes = match[1].split(';');
111
111
  for (let i = 0; i < codes.length; i++) {
@@ -123,23 +123,23 @@ export function blit(
123
123
  else if (code >= 100 && code <= 107)
124
124
  currentBg = (code - 100 + 8).toString();
125
125
  else if (code === 38 && codes[i + 1] === '5') {
126
- currentFg = parseInt(codes[i + 2], 10);
126
+ currentFg = parseInt(codes[i + 2]!, 10);
127
127
  i += 2;
128
128
  } else if (code === 38 && codes[i + 1] === '2') {
129
129
  currentFg = {
130
- r: parseInt(codes[i + 2], 10),
131
- g: parseInt(codes[i + 3], 10),
132
- b: parseInt(codes[i + 4], 10),
130
+ r: parseInt(codes[i + 2]!, 10),
131
+ g: parseInt(codes[i + 3]!, 10),
132
+ b: parseInt(codes[i + 4]!, 10),
133
133
  };
134
134
  i += 4;
135
135
  } else if (code === 48 && codes[i + 1] === '5') {
136
- currentBg = parseInt(codes[i + 2], 10);
136
+ currentBg = parseInt(codes[i + 2]!, 10);
137
137
  i += 2;
138
138
  } else if (code === 48 && codes[i + 1] === '2') {
139
139
  currentBg = {
140
- r: parseInt(codes[i + 2], 10),
141
- g: parseInt(codes[i + 3], 10),
142
- b: parseInt(codes[i + 4], 10),
140
+ r: parseInt(codes[i + 2]!, 10),
141
+ g: parseInt(codes[i + 3]!, 10),
142
+ b: parseInt(codes[i + 4]!, 10),
143
143
  };
144
144
  i += 4;
145
145
  } else if (code === 39) currentFg = undefined;
@@ -387,7 +387,7 @@ export function box(
387
387
 
388
388
  // Content Lines
389
389
  for (let i = 0; i < lines.length; i++) {
390
- const line = lines[i].trim();
390
+ const line = lines[i]!.trim();
391
391
  const lineW = visibleWidth(line);
392
392
  const extra = Math.max(0, targetInnerW - lineW - px * 2);
393
393
  let left = 0,
@@ -448,7 +448,8 @@ export function joinHorizontal(...blocks: string[]): string {
448
448
  const targetW = widths[j]!;
449
449
  if (block[i] !== undefined) {
450
450
  row +=
451
- block[i] + ' '.repeat(Math.max(0, targetW - visibleWidth(block[i])));
451
+ block[i]! +
452
+ ' '.repeat(Math.max(0, targetW - visibleWidth(block[i]!)));
452
453
  } else {
453
454
  row += ' '.repeat(targetW);
454
455
  }
package/src/render.ts CHANGED
@@ -27,10 +27,10 @@ export function flush(state: ScreenState) {
27
27
  const b = state.backBuffer[idx];
28
28
  const f = state.frontBuffer[idx];
29
29
  if (
30
- b.char !== f.char ||
31
- b.fg !== f.fg ||
32
- b.bg !== f.bg ||
33
- !!b.bold !== !!f.bold
30
+ b!.char !== f!.char ||
31
+ b!.fg !== f!.fg ||
32
+ b!.bg !== f!.bg ||
33
+ !!b!.bold !== !!f!.bold
34
34
  ) {
35
35
  if (firstDirty === -1) firstDirty = x;
36
36
  lastDirty = x;
@@ -45,19 +45,19 @@ export function flush(state: ScreenState) {
45
45
  const cell = state.backBuffer[idx];
46
46
  const front = state.frontBuffer[idx];
47
47
 
48
- if (cell.char === '') {
49
- front.char = '';
50
- front.fg = cell.fg;
51
- front.bg = cell.bg;
52
- front.fgCode = cell.fgCode;
53
- front.bgCode = cell.bgCode;
54
- front.bold = cell.bold;
48
+ if (cell!.char === '') {
49
+ front!.char = '';
50
+ front!.fg = cell!.fg;
51
+ front!.bg = cell!.bg;
52
+ front!.fgCode = cell!.fgCode;
53
+ front!.bgCode = cell!.bgCode;
54
+ front!.bold = cell!.bold;
55
55
  continue;
56
56
  }
57
57
 
58
- const fg = cell.fgCode;
59
- const bg = cell.bgCode;
60
- const bold = !!cell.bold;
58
+ const fg = cell!.fgCode;
59
+ const bg = cell!.bgCode;
60
+ const bold = !!cell!.bold;
61
61
 
62
62
  if (bold !== lastBold) {
63
63
  renderString += bold ? '\x1b[1m' : '\x1b[22m';
@@ -102,13 +102,13 @@ export function flush(state: ScreenState) {
102
102
  lastBg = bg;
103
103
  }
104
104
 
105
- renderString += cell.char;
106
- front.char = cell.char;
107
- front.fg = cell.fg;
108
- front.bg = cell.bg;
109
- front.fgCode = cell.fgCode;
110
- front.bgCode = cell.bgCode;
111
- front.bold = cell.bold;
105
+ renderString += cell!.char;
106
+ front!.char = cell!.char;
107
+ front!.fg = cell!.fg;
108
+ front!.bg = cell!.bg;
109
+ front!.fgCode = cell!.fgCode;
110
+ front!.bgCode = cell!.bgCode;
111
+ front!.bold = cell!.bold;
112
112
  }
113
113
  }
114
114
  }
package/src/state.ts CHANGED
@@ -121,7 +121,7 @@ export function resizeScreen(state: ScreenState) {
121
121
  */
122
122
  export function clearBackBuffer(state: ScreenState) {
123
123
  for (let i = 0; i < state.backBuffer.length; i++) {
124
- const cell = state.backBuffer[i];
124
+ const cell = state.backBuffer[i]!;
125
125
  cell.char = ' ';
126
126
  cell.fg = undefined;
127
127
  cell.bg = undefined;