@opentui/core 0.2.14 → 0.2.16

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.
@@ -183,7 +183,7 @@ import {
183
183
  white,
184
184
  wrapWithDelegates,
185
185
  yellow
186
- } from "./index-3fq5hq97.js";
186
+ } from "./index-qfwqv8y3.js";
187
187
 
188
188
  // src/index.ts
189
189
  var exports_src2 = {};
@@ -5782,17 +5782,23 @@ var InputRenderableEvents;
5782
5782
 
5783
5783
  class InputRenderable extends TextareaRenderable {
5784
5784
  _maxLength;
5785
+ _minLength;
5785
5786
  _lastCommittedValue = "";
5786
5787
  static defaultOptions = {
5787
5788
  placeholder: "",
5788
5789
  maxLength: 1000,
5790
+ minLength: 0,
5789
5791
  value: ""
5790
5792
  };
5791
5793
  constructor(ctx, options) {
5792
5794
  const defaults = InputRenderable.defaultOptions;
5793
5795
  const maxLength = options.maxLength ?? defaults.maxLength;
5796
+ const minLength = options.minLength ?? defaults.minLength;
5794
5797
  const rawValue = options.value ?? defaults.value;
5795
5798
  const initialValue = rawValue.replace(/[\n\r]/g, "").substring(0, maxLength);
5799
+ if (minLength > maxLength) {
5800
+ throw new Error(`InputRenderable: minLength (${minLength}) cannot be greater than maxLength (${maxLength})`);
5801
+ }
5796
5802
  super(ctx, {
5797
5803
  ...options,
5798
5804
  placeholder: options.placeholder ?? defaults.placeholder,
@@ -5807,6 +5813,7 @@ class InputRenderable extends TextareaRenderable {
5807
5813
  ]
5808
5814
  });
5809
5815
  this._maxLength = maxLength;
5816
+ this._minLength = minLength;
5810
5817
  this._lastCommittedValue = this.plainText;
5811
5818
  if (initialValue) {
5812
5819
  this.cursorOffset = initialValue.length;
@@ -5861,6 +5868,9 @@ class InputRenderable extends TextareaRenderable {
5861
5868
  }
5862
5869
  submit() {
5863
5870
  const currentValue = this.plainText;
5871
+ if (currentValue.length < this._minLength) {
5872
+ return false;
5873
+ }
5864
5874
  if (currentValue !== this._lastCommittedValue) {
5865
5875
  this._lastCommittedValue = currentValue;
5866
5876
  this.emit("change" /* CHANGE */, currentValue);
@@ -5930,6 +5940,15 @@ class InputRenderable extends TextareaRenderable {
5930
5940
  get maxLength() {
5931
5941
  return this._maxLength;
5932
5942
  }
5943
+ set minLength(minLength) {
5944
+ if (minLength > this._maxLength) {
5945
+ throw new Error(`InputRenderable: minLength (${minLength}) cannot be greater than maxLength (${this._maxLength})`);
5946
+ }
5947
+ this._minLength = minLength;
5948
+ }
5949
+ get minLength() {
5950
+ return this._minLength;
5951
+ }
5933
5952
  set placeholder(placeholder) {
5934
5953
  super.placeholder = placeholder;
5935
5954
  }
@@ -8758,10 +8777,8 @@ class MarkdownRenderable extends Renderable {
8758
8777
  const renderable = this.createListChildRenderable(child, `${input.id}-child-${index}`);
8759
8778
  if (!renderable)
8760
8779
  continue;
8761
- if (pendingMarginTop > 0) {
8762
- renderable.marginTop = pendingMarginTop;
8763
- pendingMarginTop = 0;
8764
- }
8780
+ renderable.marginTop = child.type === "list" ? 0 : pendingMarginTop;
8781
+ pendingMarginTop = 0;
8765
8782
  content.add(renderable);
8766
8783
  }
8767
8784
  return row;
@@ -8793,12 +8810,13 @@ class MarkdownRenderable extends Renderable {
8793
8810
  }
8794
8811
  const existing = children[childIndex];
8795
8812
  const childId = `${id}-child-${tokenIndex}`;
8813
+ const marginTop = token.type === "list" ? 0 : pendingMarginTop;
8814
+ pendingMarginTop = 0;
8796
8815
  if (!existing) {
8797
8816
  const renderable = this.createListChildRenderable(token, childId);
8798
8817
  if (!renderable)
8799
8818
  return false;
8800
- renderable.marginTop = pendingMarginTop;
8801
- pendingMarginTop = 0;
8819
+ renderable.marginTop = marginTop;
8802
8820
  content.add(renderable, childIndex);
8803
8821
  childIndex += 1;
8804
8822
  continue;
@@ -8806,8 +8824,7 @@ class MarkdownRenderable extends Renderable {
8806
8824
  if (!this.applyListChildRenderable(existing, token, previousTokens[childIndex], childId)) {
8807
8825
  return false;
8808
8826
  }
8809
- existing.marginTop = pendingMarginTop;
8810
- pendingMarginTop = 0;
8827
+ existing.marginTop = marginTop;
8811
8828
  childIndex += 1;
8812
8829
  }
8813
8830
  this.destroyListItemChildrenAfter(content, childIndex);
@@ -8824,7 +8841,7 @@ class MarkdownRenderable extends Renderable {
8824
8841
  }
8825
8842
  applyListChildRenderable(renderable, token, previousToken, id) {
8826
8843
  if ((token.type === "text" || token.type === "paragraph") && renderable instanceof CodeRenderable) {
8827
- this.applyMarkdownCodeRenderable(renderable, this.getListChildMarkdownRaw(token), 0);
8844
+ this.applyMarkdownCodeRenderable(renderable, this.normalizeScrollbackMarkdownBlockRaw(token.raw), 0);
8828
8845
  return true;
8829
8846
  }
8830
8847
  if (token.type === "list" && renderable instanceof BoxRenderable) {
@@ -8842,9 +8859,6 @@ class MarkdownRenderable extends Renderable {
8842
8859
  children[i]?.destroyRecursively();
8843
8860
  }
8844
8861
  }
8845
- getListChildMarkdownRaw(token) {
8846
- return token.type === "paragraph" ? this.normalizeScrollbackMarkdownBlockRaw(token.raw) : token.raw;
8847
- }
8848
8862
  applyListItemMarker(row, input) {
8849
8863
  const marker = row.getChildren()[0];
8850
8864
  if (!(marker instanceof TextRenderable))
@@ -8862,7 +8876,7 @@ class MarkdownRenderable extends Renderable {
8862
8876
  }
8863
8877
  createListChildRenderable(token, id) {
8864
8878
  if (token.type === "text" || token.type === "paragraph") {
8865
- return this.createMarkdownCodeRenderable(this.getListChildMarkdownRaw(token), id);
8879
+ return this.createMarkdownCodeRenderable(this.normalizeScrollbackMarkdownBlockRaw(token.raw), id);
8866
8880
  }
8867
8881
  if (token.type === "list")
8868
8882
  return this.createListRenderable(token, id);
@@ -8946,10 +8960,19 @@ class MarkdownRenderable extends Renderable {
8946
8960
  shouldRenderSeparately(token) {
8947
8961
  return token.type === "code" || token.type === "table" || token.type === "blockquote" || token.type === "hr";
8948
8962
  }
8949
- getInterBlockMargin(token, hasNextToken) {
8950
- if (!hasNextToken)
8963
+ getInterBlockMargin(token, nextToken) {
8964
+ if (!nextToken)
8965
+ return 0;
8966
+ if (this.shouldRenderSeparately(token))
8967
+ return 1;
8968
+ if (!this.shouldRenderSeparately(nextToken))
8951
8969
  return 0;
8952
- return this.shouldRenderSeparately(token) ? 1 : 0;
8970
+ return TRAILING_MARKDOWN_BLOCK_NEWLINES_RE.test(token.raw) ? 0 : 1;
8971
+ }
8972
+ applyInterBlockMargin(state, token, nextToken) {
8973
+ if (state.tracksInterBlockMargin === false)
8974
+ return;
8975
+ state.renderable.marginBottom = this.getInterBlockMargin(token, nextToken);
8953
8976
  }
8954
8977
  createMarkdownBlockToken(raw) {
8955
8978
  return {
@@ -9337,9 +9360,9 @@ class MarkdownRenderable extends Renderable {
9337
9360
  }
9338
9361
  return next ?? this.createTopLevelDefaultRenderable(block, index);
9339
9362
  }
9340
- createDefaultRenderable(token, index, hasNextToken = false) {
9363
+ createDefaultRenderable(token, index, nextToken) {
9341
9364
  const id = `${this.id}-block-${index}`;
9342
- const marginBottom = this.getInterBlockMargin(token, hasNextToken);
9365
+ const marginBottom = this.getInterBlockMargin(token, nextToken);
9343
9366
  if (token.type === "code") {
9344
9367
  return this.createCodeRenderable(token, id, marginBottom);
9345
9368
  }
@@ -9363,8 +9386,8 @@ class MarkdownRenderable extends Renderable {
9363
9386
  }
9364
9387
  return this.createMarkdownCodeRenderable(token.raw, id, marginBottom);
9365
9388
  }
9366
- updateBlockRenderable(state, token, index, hasNextToken, forceListRefresh = false) {
9367
- const marginBottom = this.getInterBlockMargin(token, hasNextToken);
9389
+ updateBlockRenderable(state, token, index, nextToken, forceListRefresh = false) {
9390
+ const marginBottom = this.getInterBlockMargin(token, nextToken);
9368
9391
  if (token.type === "code") {
9369
9392
  this.applyCodeBlockRenderable(state.renderable, token, marginBottom);
9370
9393
  return;
@@ -9423,7 +9446,7 @@ class MarkdownRenderable extends Renderable {
9423
9446
  }
9424
9447
  state.renderable.destroyRecursively();
9425
9448
  const markdownRenderable = this.createMarkdownCodeRenderable(this.getTopLevelBlockRaw(token) ?? token.raw, `${this.id}-block-${index}`, marginBottom);
9426
- this.add(markdownRenderable);
9449
+ this.add(markdownRenderable, index);
9427
9450
  state.renderable = markdownRenderable;
9428
9451
  }
9429
9452
  updateTopLevelBlocks(tokens, forceTableRefresh) {
@@ -9450,7 +9473,7 @@ class MarkdownRenderable extends Renderable {
9450
9473
  continue;
9451
9474
  }
9452
9475
  if (existing && !forceTableRefresh && !this._renderNode && existing.token.type === block.token.type && this.canUpdateBlockRenderable(existing.renderable, block.token)) {
9453
- this.updateBlockRenderable(existing, block.token, blockIndex, blockIndex < blocks.length - 1);
9476
+ this.updateBlockRenderable(existing, block.token, blockIndex, blocks[i + 1]?.token);
9454
9477
  existing.renderable.marginBottom = 0;
9455
9478
  if (existing.marginTop !== block.marginTop) {
9456
9479
  this.applyMargins(existing.renderable, block.marginTop, 0);
@@ -9464,7 +9487,7 @@ class MarkdownRenderable extends Renderable {
9464
9487
  }
9465
9488
  const next = this.createTopLevelRenderable(block, blockIndex);
9466
9489
  if (next.renderable) {
9467
- this.add(next.renderable);
9490
+ this.add(next.renderable, blockIndex);
9468
9491
  this._blockStates[blockIndex] = {
9469
9492
  token: block.token,
9470
9493
  tokenRaw: block.token.raw,
@@ -9515,7 +9538,8 @@ class MarkdownRenderable extends Renderable {
9515
9538
  token: { type: "text", raw: this._content, text: this._content },
9516
9539
  tokenRaw: this._content,
9517
9540
  marginTop: 0,
9518
- renderable: fallback
9541
+ renderable: fallback,
9542
+ tracksInterBlockMargin: true
9519
9543
  }
9520
9544
  ];
9521
9545
  return;
@@ -9526,17 +9550,18 @@ class MarkdownRenderable extends Renderable {
9526
9550
  }
9527
9551
  this._stableBlockCount = 0;
9528
9552
  const blockTokens = this.buildRenderableTokens(tokens);
9529
- const lastBlockIndex = blockTokens.length - 1;
9530
9553
  let blockIndex = 0;
9531
9554
  for (let i = 0;i < blockTokens.length; i++) {
9532
9555
  const token = blockTokens[i];
9533
- const hasNextToken = i < lastBlockIndex;
9556
+ const nextToken = blockTokens[i + 1];
9534
9557
  const existing = this._blockStates[blockIndex];
9535
9558
  const shouldForceRefresh = forceTableRefresh;
9536
9559
  if (existing && existing.token === token) {
9537
9560
  if (shouldForceRefresh) {
9538
- this.updateBlockRenderable(existing, token, blockIndex, hasNextToken);
9561
+ this.updateBlockRenderable(existing, token, blockIndex, nextToken);
9539
9562
  existing.tokenRaw = token.raw;
9563
+ } else {
9564
+ this.applyInterBlockMargin(existing, token, nextToken);
9540
9565
  }
9541
9566
  blockIndex++;
9542
9567
  continue;
@@ -9544,16 +9569,19 @@ class MarkdownRenderable extends Renderable {
9544
9569
  if (existing && existing.tokenRaw === token.raw && existing.token.type === token.type) {
9545
9570
  existing.token = token;
9546
9571
  if (shouldForceRefresh) {
9547
- this.updateBlockRenderable(existing, token, blockIndex, hasNextToken);
9572
+ this.updateBlockRenderable(existing, token, blockIndex, nextToken);
9548
9573
  existing.tokenRaw = token.raw;
9574
+ } else {
9575
+ this.applyInterBlockMargin(existing, token, nextToken);
9549
9576
  }
9550
9577
  blockIndex++;
9551
9578
  continue;
9552
9579
  }
9553
9580
  if (existing && existing.token.type === token.type) {
9554
- this.updateBlockRenderable(existing, token, blockIndex, hasNextToken);
9581
+ this.updateBlockRenderable(existing, token, blockIndex, nextToken);
9555
9582
  existing.token = token;
9556
9583
  existing.tokenRaw = token.raw;
9584
+ existing.tracksInterBlockMargin = true;
9557
9585
  blockIndex++;
9558
9586
  continue;
9559
9587
  }
@@ -9562,26 +9590,32 @@ class MarkdownRenderable extends Renderable {
9562
9590
  }
9563
9591
  let renderable;
9564
9592
  let tableContentCache;
9593
+ let tracksInterBlockMargin = true;
9565
9594
  if (this._renderNode) {
9595
+ let defaultRenderable;
9566
9596
  const context = {
9567
9597
  syntaxStyle: this._syntaxStyle,
9568
9598
  conceal: this._conceal,
9569
9599
  concealCode: this._concealCode,
9570
9600
  treeSitterClient: this._treeSitterClient,
9571
- defaultRender: () => this.createDefaultRenderable(token, blockIndex, hasNextToken)
9601
+ defaultRender: () => {
9602
+ defaultRenderable = this.createDefaultRenderable(token, blockIndex, nextToken);
9603
+ return defaultRenderable;
9604
+ }
9572
9605
  };
9573
9606
  const custom = this._renderNode(token, context);
9574
9607
  if (custom) {
9575
9608
  renderable = custom;
9609
+ tracksInterBlockMargin = custom === defaultRenderable;
9576
9610
  }
9577
9611
  }
9578
9612
  if (!renderable) {
9579
9613
  if (token.type === "table") {
9580
- const tableBlock = this.createTableBlock(token, `${this.id}-block-${blockIndex}`, this.getInterBlockMargin(token, hasNextToken));
9614
+ const tableBlock = this.createTableBlock(token, `${this.id}-block-${blockIndex}`, this.getInterBlockMargin(token, nextToken));
9581
9615
  renderable = tableBlock.renderable;
9582
9616
  tableContentCache = tableBlock.tableContentCache;
9583
9617
  } else {
9584
- renderable = this.createDefaultRenderable(token, blockIndex, hasNextToken) ?? undefined;
9618
+ renderable = this.createDefaultRenderable(token, blockIndex, nextToken) ?? undefined;
9585
9619
  }
9586
9620
  }
9587
9621
  if (token.type === "table" && !tableContentCache && renderable instanceof TextTableRenderable) {
@@ -9589,12 +9623,13 @@ class MarkdownRenderable extends Renderable {
9589
9623
  tableContentCache = cache ?? undefined;
9590
9624
  }
9591
9625
  if (renderable) {
9592
- this.add(renderable);
9626
+ this.add(renderable, blockIndex);
9593
9627
  this._blockStates[blockIndex] = {
9594
9628
  token,
9595
9629
  tokenRaw: token.raw,
9596
9630
  renderable,
9597
- tableContentCache
9631
+ tableContentCache,
9632
+ tracksInterBlockMargin
9598
9633
  };
9599
9634
  }
9600
9635
  blockIndex++;
@@ -9618,8 +9653,7 @@ class MarkdownRenderable extends Renderable {
9618
9653
  }
9619
9654
  for (let i = 0;i < this._blockStates.length; i++) {
9620
9655
  const state = this._blockStates[i];
9621
- const hasNextToken = i < this._blockStates.length - 1;
9622
- const marginBottom = this.getInterBlockMargin(state.token, hasNextToken);
9656
+ const marginBottom = this.getInterBlockMargin(state.token, this._blockStates[i + 1]?.token);
9623
9657
  if (state.token.type === "code") {
9624
9658
  this.applyCodeBlockRenderable(state.renderable, state.token, marginBottom);
9625
9659
  continue;
@@ -9629,7 +9663,7 @@ class MarkdownRenderable extends Renderable {
9629
9663
  continue;
9630
9664
  }
9631
9665
  if (state.token.type === "list") {
9632
- this.updateBlockRenderable(state, state.token, i, hasNextToken, true);
9666
+ this.updateBlockRenderable(state, state.token, i, this._blockStates[i + 1]?.token, true);
9633
9667
  continue;
9634
9668
  }
9635
9669
  if (state.token.type === "hr") {
@@ -9645,7 +9679,7 @@ class MarkdownRenderable extends Renderable {
9645
9679
  } else {
9646
9680
  state.renderable.destroyRecursively();
9647
9681
  const fallbackRenderable = this.createMarkdownCodeRenderable(tableToken.raw, `${this.id}-block-${i}`, marginBottom);
9648
- this.add(fallbackRenderable);
9682
+ this.add(fallbackRenderable, i);
9649
9683
  state.renderable = fallbackRenderable;
9650
9684
  }
9651
9685
  state.tableContentCache = undefined;
@@ -9660,7 +9694,7 @@ class MarkdownRenderable extends Renderable {
9660
9694
  }
9661
9695
  state.renderable.destroyRecursively();
9662
9696
  const tableRenderable = this.createTextTableRenderable(cache.content, `${this.id}-block-${i}`, marginBottom);
9663
- this.add(tableRenderable);
9697
+ this.add(tableRenderable, i);
9664
9698
  state.renderable = tableRenderable;
9665
9699
  state.tableContentCache = cache;
9666
9700
  continue;
@@ -9671,7 +9705,7 @@ class MarkdownRenderable extends Renderable {
9671
9705
  }
9672
9706
  state.renderable.destroyRecursively();
9673
9707
  const markdownRenderable = this.createMarkdownCodeRenderable(this.getTopLevelBlockRaw(state.token) ?? state.token.raw, `${this.id}-block-${i}`, marginBottom);
9674
- this.add(markdownRenderable);
9708
+ this.add(markdownRenderable, i);
9675
9709
  state.renderable = markdownRenderable;
9676
9710
  }
9677
9711
  }
@@ -10673,6 +10707,18 @@ class ScrollBoxRenderable extends BoxRenderable {
10673
10707
  return false;
10674
10708
  }
10675
10709
  }
10710
+ isAtStickyReengagePoint(stickyStart, maxScrollTop, maxScrollLeft) {
10711
+ switch (stickyStart) {
10712
+ case "top":
10713
+ return maxScrollTop > 0 && this.scrollTop <= 0;
10714
+ case "bottom":
10715
+ return maxScrollTop > 0 && this.scrollTop >= maxScrollTop - 1;
10716
+ case "left":
10717
+ return maxScrollLeft > 0 && this.scrollLeft <= 0;
10718
+ case "right":
10719
+ return maxScrollLeft > 0 && this.scrollLeft >= maxScrollLeft - 1;
10720
+ }
10721
+ }
10676
10722
  add(obj, index) {
10677
10723
  return this.content.add(obj, index);
10678
10724
  }
@@ -10871,9 +10917,13 @@ class ScrollBoxRenderable extends BoxRenderable {
10871
10917
  if (this._stickyScroll) {
10872
10918
  const newMaxScrollTop = Math.max(0, this.scrollHeight - this.viewport.height);
10873
10919
  const newMaxScrollLeft = Math.max(0, this.scrollWidth - this.viewport.width);
10874
- if (this._stickyStart && !this._hasManualScroll) {
10875
- this.applyStickyStart(this._stickyStart);
10876
- } else {
10920
+ const stickyStart = this._stickyStart;
10921
+ if (stickyStart && !this._hasManualScroll) {
10922
+ this.applyStickyStart(stickyStart);
10923
+ } else if (stickyStart && this._hasManualScroll && this.isAtStickyReengagePoint(stickyStart, newMaxScrollTop, newMaxScrollLeft)) {
10924
+ this._hasManualScroll = false;
10925
+ this.applyStickyStart(stickyStart);
10926
+ } else if (!this._hasManualScroll) {
10877
10927
  if (this._stickyScrollTop) {
10878
10928
  this.scrollTop = 0;
10879
10929
  } else if (this._stickyScrollBottom && newMaxScrollTop > 0) {
@@ -11735,5 +11785,5 @@ class TimeToFirstDrawRenderable extends Renderable {
11735
11785
  }
11736
11786
  export { DistortionEffect, VignetteEffect, CloudsEffect, FlamesEffect, CRTRollingBarEffect, RainbowTextEffect, applyScanlines, applyInvert, applyNoise, applyChromaticAberration, applyAsciiArt, applyBrightness, applyGain, applySaturation, BloomEffect, SEPIA_MATRIX, PROTANOPIA_SIM_MATRIX, DEUTERANOPIA_SIM_MATRIX, TRITANOPIA_SIM_MATRIX, ACHROMATOPSIA_MATRIX, PROTANOPIA_COMP_MATRIX, DEUTERANOPIA_COMP_MATRIX, TRITANOPIA_COMP_MATRIX, TECHNICOLOR_MATRIX, SOLARIZATION_MATRIX, SYNTHWAVE_MATRIX, GREENSCALE_MATRIX, GRAYSCALE_MATRIX, INVERT_MATRIX, Timeline, engine, createTimeline, SlotRegistry, createSlotRegistry, createCoreSlotRegistry, registerCorePlugin, resolveCoreSlot, SlotRenderable, NativeSpanFeed, Audio, setupAudio, FrameBufferRenderable, ASCIIFontRenderable, Generic, Box, Text, ASCIIFont, Input, Select, TabSelect, FrameBuffer, Code, ScrollBox, vstyles, VRenderable, LineNumberRenderable, DiffRenderable, defaultTextareaKeyBindings, TextareaRenderable, InputRenderableEvents, InputRenderable, TextTableRenderable, MarkdownRenderable, SliderRenderable, ScrollBarRenderable, ArrowRenderable, ScrollBoxRenderable, SelectRenderableEvents, SelectRenderable, TabSelectRenderableEvents, TabSelectRenderable, TimeToFirstDrawRenderable, exports_src2 as exports_src };
11737
11787
 
11738
- //# debugId=34EAE37A921CAC2964756E2164756E21
11739
- //# sourceMappingURL=index-nhyfhtvf.js.map
11788
+ //# debugId=811F02B84CBDC3E964756E2164756E21
11789
+ //# sourceMappingURL=index-hzcw4q21.js.map