@opentui/core 0.1.36 → 0.1.38

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/index.js CHANGED
@@ -33,6 +33,7 @@ import {
33
33
  StdinBuffer,
34
34
  StyledText,
35
35
  TerminalConsole,
36
+ TerminalPalette,
36
37
  TextAttributes,
37
38
  TextBuffer,
38
39
  TreeSitterClient,
@@ -65,6 +66,7 @@ import {
65
66
  coordinateToCharacterIndex,
66
67
  createCliRenderer,
67
68
  createExtmarksController,
69
+ createTerminalPalette,
68
70
  createTextAttributes,
69
71
  cyan,
70
72
  delegate,
@@ -134,7 +136,7 @@ import {
134
136
  white,
135
137
  wrapWithDelegates,
136
138
  yellow
137
- } from "./index-n8nbvvhk.js";
139
+ } from "./index-7bav3fax.js";
138
140
  // src/text-buffer-view.ts
139
141
  class TextBufferView {
140
142
  lib;
@@ -2774,20 +2776,27 @@ class CodeRenderable extends TextBufferRenderable {
2774
2776
  this._hadInitialContent = true;
2775
2777
  }
2776
2778
  const shouldDrawUnstyledNow = this._streaming ? isInitialContent && this._drawUnstyledText : this._drawUnstyledText;
2777
- this.fallback(content);
2778
2779
  if (!shouldDrawUnstyledNow) {
2779
2780
  this._shouldRenderTextBuffer = false;
2780
- }
2781
- if (this._streaming && !isInitialContent && this._lastHighlights.length > 0) {
2782
- const chunks = treeSitterToTextChunks(content, this._lastHighlights, this._syntaxStyle, {
2783
- enabled: this._conceal
2784
- });
2785
- const partialStyledText = new StyledText(chunks);
2786
- if (this.isDestroyed)
2787
- return;
2788
- this.textBuffer.setStyledText(partialStyledText);
2781
+ } else {
2789
2782
  this._shouldRenderTextBuffer = true;
2790
- this.updateTextInfo();
2783
+ this.fallback(content);
2784
+ }
2785
+ if (this._streaming && !isInitialContent) {
2786
+ if (this._lastHighlights.length > 0) {
2787
+ const chunks = treeSitterToTextChunks(content, this._lastHighlights, this._syntaxStyle, {
2788
+ enabled: this._conceal
2789
+ });
2790
+ const partialStyledText = new StyledText(chunks);
2791
+ if (this.isDestroyed)
2792
+ return;
2793
+ this.textBuffer.setStyledText(partialStyledText);
2794
+ this._shouldRenderTextBuffer = true;
2795
+ this.updateTextInfo();
2796
+ } else {
2797
+ this.fallback(content);
2798
+ this._shouldRenderTextBuffer = true;
2799
+ }
2791
2800
  }
2792
2801
  this._isHighlighting = true;
2793
2802
  this._pendingRehighlight = false;
@@ -4044,11 +4053,11 @@ class ContentRenderable extends BoxRenderable {
4044
4053
  set viewportCulling(value) {
4045
4054
  this._viewportCulling = value;
4046
4055
  }
4047
- _getChildren() {
4056
+ _getVisibleChildren() {
4048
4057
  if (this._viewportCulling) {
4049
- return getObjectsInViewport(this.viewport, this.getChildrenSortedByPrimaryAxis(), this.primaryAxis);
4058
+ return getObjectsInViewport(this.viewport, this.getChildrenSortedByPrimaryAxis(), this.primaryAxis).map((child) => child.num);
4050
4059
  }
4051
- return this.getChildrenSortedByPrimaryAxis();
4060
+ return this.getChildrenSortedByPrimaryAxis().map((child) => child.num);
4052
4061
  }
4053
4062
  }
4054
4063
 
@@ -4080,6 +4089,7 @@ class ScrollBoxRenderable extends BoxRenderable {
4080
4089
  _stickyScrollRight = false;
4081
4090
  _stickyStart;
4082
4091
  _hasManualScroll = false;
4092
+ _isApplyingStickyScroll = false;
4083
4093
  scrollAccel;
4084
4094
  get stickyScroll() {
4085
4095
  return this._stickyScroll;
@@ -4100,7 +4110,12 @@ class ScrollBoxRenderable extends BoxRenderable {
4100
4110
  }
4101
4111
  set scrollTop(value) {
4102
4112
  this.verticalScrollBar.scrollPosition = value;
4103
- this._hasManualScroll = true;
4113
+ if (!this._isApplyingStickyScroll) {
4114
+ const maxScrollTop = Math.max(0, this.scrollHeight - this.viewport.height);
4115
+ if (!this.isAtStickyPosition() && maxScrollTop > 1) {
4116
+ this._hasManualScroll = true;
4117
+ }
4118
+ }
4104
4119
  this.updateStickyState();
4105
4120
  }
4106
4121
  get scrollLeft() {
@@ -4108,7 +4123,12 @@ class ScrollBoxRenderable extends BoxRenderable {
4108
4123
  }
4109
4124
  set scrollLeft(value) {
4110
4125
  this.horizontalScrollBar.scrollPosition = value;
4111
- this._hasManualScroll = true;
4126
+ if (!this._isApplyingStickyScroll) {
4127
+ const maxScrollLeft = Math.max(0, this.scrollWidth - this.viewport.width);
4128
+ if (!this.isAtStickyPosition() && maxScrollLeft > 1) {
4129
+ this._hasManualScroll = true;
4130
+ }
4131
+ }
4112
4132
  this.updateStickyState();
4113
4133
  }
4114
4134
  get scrollWidth() {
@@ -4144,6 +4164,7 @@ class ScrollBoxRenderable extends BoxRenderable {
4144
4164
  }
4145
4165
  }
4146
4166
  applyStickyStart(stickyStart) {
4167
+ this._isApplyingStickyScroll = true;
4147
4168
  switch (stickyStart) {
4148
4169
  case "top":
4149
4170
  this._stickyScrollTop = true;
@@ -4166,6 +4187,7 @@ class ScrollBoxRenderable extends BoxRenderable {
4166
4187
  this.horizontalScrollBar.scrollPosition = Math.max(0, this.scrollWidth - this.viewport.width);
4167
4188
  break;
4168
4189
  }
4190
+ this._isApplyingStickyScroll = false;
4169
4191
  }
4170
4192
  constructor(ctx, {
4171
4193
  wrapperOptions,
@@ -4239,7 +4261,12 @@ class ScrollBoxRenderable extends BoxRenderable {
4239
4261
  orientation: "vertical",
4240
4262
  onChange: (position) => {
4241
4263
  this.content.translateY = -position;
4242
- this._hasManualScroll = true;
4264
+ if (!this._isApplyingStickyScroll) {
4265
+ const maxScrollTop = Math.max(0, this.scrollHeight - this.viewport.height);
4266
+ if (!this.isAtStickyPosition() && maxScrollTop > 1) {
4267
+ this._hasManualScroll = true;
4268
+ }
4269
+ }
4243
4270
  this.updateStickyState();
4244
4271
  }
4245
4272
  });
@@ -4255,7 +4282,12 @@ class ScrollBoxRenderable extends BoxRenderable {
4255
4282
  orientation: "horizontal",
4256
4283
  onChange: (position) => {
4257
4284
  this.content.translateX = -position;
4258
- this._hasManualScroll = true;
4285
+ if (!this._isApplyingStickyScroll) {
4286
+ const maxScrollLeft = Math.max(0, this.scrollWidth - this.viewport.width);
4287
+ if (!this.isAtStickyPosition() && maxScrollLeft > 1) {
4288
+ this._hasManualScroll = true;
4289
+ }
4290
+ }
4259
4291
  this.updateStickyState();
4260
4292
  }
4261
4293
  });
@@ -4282,7 +4314,6 @@ class ScrollBoxRenderable extends BoxRenderable {
4282
4314
  this.verticalScrollBar.scrollBy(delta.y, unit);
4283
4315
  this.horizontalScrollBar.scrollBy(delta.x, unit);
4284
4316
  }
4285
- this._hasManualScroll = true;
4286
4317
  }
4287
4318
  scrollTo(position) {
4288
4319
  if (typeof position === "number") {
@@ -4292,6 +4323,25 @@ class ScrollBoxRenderable extends BoxRenderable {
4292
4323
  this.scrollLeft = position.x;
4293
4324
  }
4294
4325
  }
4326
+ isAtStickyPosition() {
4327
+ if (!this._stickyScroll || !this._stickyStart) {
4328
+ return false;
4329
+ }
4330
+ const maxScrollTop = Math.max(0, this.scrollHeight - this.viewport.height);
4331
+ const maxScrollLeft = Math.max(0, this.scrollWidth - this.viewport.width);
4332
+ switch (this._stickyStart) {
4333
+ case "top":
4334
+ return this.scrollTop === 0;
4335
+ case "bottom":
4336
+ return this.scrollTop >= maxScrollTop;
4337
+ case "left":
4338
+ return this.scrollLeft === 0;
4339
+ case "right":
4340
+ return this.scrollLeft >= maxScrollLeft;
4341
+ default:
4342
+ return false;
4343
+ }
4344
+ }
4295
4345
  add(obj, index) {
4296
4346
  return this.content.add(obj, index);
4297
4347
  }
@@ -4321,7 +4371,11 @@ class ScrollBoxRenderable extends BoxRenderable {
4321
4371
  } else if (dir === "right") {
4322
4372
  this.scrollLeft += baseDelta * multiplier;
4323
4373
  }
4324
- this._hasManualScroll = true;
4374
+ const maxScrollTop = Math.max(0, this.scrollHeight - this.viewport.height);
4375
+ const maxScrollLeft = Math.max(0, this.scrollWidth - this.viewport.width);
4376
+ if (maxScrollTop > 1 || maxScrollLeft > 1) {
4377
+ this._hasManualScroll = true;
4378
+ }
4325
4379
  }
4326
4380
  if (event.type === "drag" && event.isSelecting) {
4327
4381
  this.updateAutoScroll(event.x, event.y);
@@ -4449,6 +4503,8 @@ class ScrollBoxRenderable extends BoxRenderable {
4449
4503
  }
4450
4504
  }
4451
4505
  recalculateBarProps() {
4506
+ const wasApplyingStickyScroll = this._isApplyingStickyScroll;
4507
+ this._isApplyingStickyScroll = true;
4452
4508
  this.verticalScrollBar.scrollSize = this.content.height;
4453
4509
  this.verticalScrollBar.viewportSize = this.viewport.height;
4454
4510
  this.horizontalScrollBar.scrollSize = this.content.width;
@@ -4471,6 +4527,7 @@ class ScrollBoxRenderable extends BoxRenderable {
4471
4527
  }
4472
4528
  }
4473
4529
  }
4530
+ this._isApplyingStickyScroll = wasApplyingStickyScroll;
4474
4531
  process.nextTick(() => {
4475
4532
  this.requestRender();
4476
4533
  });
@@ -6222,6 +6279,7 @@ export {
6222
6279
  cyan,
6223
6280
  createTimeline,
6224
6281
  createTextAttributes,
6282
+ createTerminalPalette,
6225
6283
  createExtmarksController,
6226
6284
  createCliRenderer,
6227
6285
  coordinateToCharacterIndex,
@@ -6272,6 +6330,7 @@ export {
6272
6330
  TextBuffer,
6273
6331
  TextAttributes,
6274
6332
  Text,
6333
+ TerminalPalette,
6275
6334
  TerminalConsole,
6276
6335
  TabSelectRenderableEvents,
6277
6336
  TabSelectRenderable,
@@ -6334,5 +6393,5 @@ export {
6334
6393
  ASCIIFont
6335
6394
  };
6336
6395
 
6337
- //# debugId=44707EEC392262B964756E2164756E21
6396
+ //# debugId=5DEE20591CE7786764756E2164756E21
6338
6397
  //# sourceMappingURL=index.js.map