@opentui/core 0.2.8 → 0.2.10

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.
@@ -8677,6 +8677,204 @@ class MarkdownRenderable extends Renderable {
8677
8677
  renderable.add(this.createMarkdownCodeRenderable(this.getBlockquoteContent(token), `${id}-content`, 0, this._linkifyMarkdownChunks, "markup.quote"));
8678
8678
  return renderable;
8679
8679
  }
8680
+ createListRenderable(token, id, marginBottom = 0) {
8681
+ const list = new BoxRenderable(this.ctx, {
8682
+ id,
8683
+ width: "100%",
8684
+ flexDirection: "column",
8685
+ flexShrink: 0,
8686
+ marginBottom
8687
+ });
8688
+ for (const item of this.getListItemInputs(token, id)) {
8689
+ list.add(this.createListItemRenderable(item));
8690
+ }
8691
+ return list;
8692
+ }
8693
+ getListItemInputs(token, id) {
8694
+ const items = token.items ?? [];
8695
+ const start = token.start === "" || token.start === undefined || token.start === null ? 1 : Number(token.start);
8696
+ const markerWidth = Math.max(1, ...items.map((_2, index) => (token.ordered ? `${start + index}.` : "-").length));
8697
+ return items.map((item, index) => ({
8698
+ item,
8699
+ marker: token.ordered ? `${start + index}.` : "-",
8700
+ markerWidth,
8701
+ id: `${id}-item-${index}`
8702
+ }));
8703
+ }
8704
+ applyListRenderable(renderable, token, previousToken, id, marginBottom = 0) {
8705
+ if (!(renderable instanceof BoxRenderable))
8706
+ return false;
8707
+ renderable.marginBottom = marginBottom;
8708
+ const inputs = this.getListItemInputs(token, id);
8709
+ const previousItems = previousToken?.items ?? [];
8710
+ const rows = renderable.getChildren();
8711
+ for (let index = 0;index < inputs.length; index += 1) {
8712
+ const input = inputs[index];
8713
+ const existing = rows[index];
8714
+ if (existing instanceof BoxRenderable && this.applyListItemRenderable(existing, input, previousItems[index])) {
8715
+ continue;
8716
+ }
8717
+ existing?.destroyRecursively();
8718
+ renderable.add(this.createListItemRenderable(input), index);
8719
+ }
8720
+ for (let index = rows.length - 1;index >= inputs.length; index -= 1) {
8721
+ rows[index]?.destroyRecursively();
8722
+ }
8723
+ return true;
8724
+ }
8725
+ createListItemRenderable(input) {
8726
+ const row = new BoxRenderable(this.ctx, {
8727
+ id: input.id,
8728
+ width: "100%",
8729
+ flexDirection: "row",
8730
+ flexShrink: 0,
8731
+ marginBottom: /\n[ \t]*\n$/.test(input.item.raw) ? 1 : 0
8732
+ });
8733
+ row.add(new TextRenderable(this.ctx, {
8734
+ id: `${input.id}-marker`,
8735
+ content: new StyledText([this.createChunk(input.marker.padStart(input.markerWidth) + " ", "markup.list")]),
8736
+ width: input.markerWidth + 1,
8737
+ flexShrink: 0
8738
+ }));
8739
+ const content = new BoxRenderable(this.ctx, {
8740
+ id: `${input.id}-content`,
8741
+ flexDirection: "column",
8742
+ flexGrow: 1,
8743
+ flexShrink: 1
8744
+ });
8745
+ row.add(content);
8746
+ let pendingMarginTop = 0;
8747
+ for (let index = 0;index < input.item.tokens.length; index += 1) {
8748
+ const child = input.item.tokens[index];
8749
+ if (!child)
8750
+ continue;
8751
+ if (child.type === "checkbox")
8752
+ continue;
8753
+ if (child.type === "space") {
8754
+ pendingMarginTop = Math.max(pendingMarginTop, 1);
8755
+ continue;
8756
+ }
8757
+ const renderable = this.createListChildRenderable(child, `${input.id}-child-${index}`);
8758
+ if (!renderable)
8759
+ continue;
8760
+ if (pendingMarginTop > 0) {
8761
+ renderable.marginTop = pendingMarginTop;
8762
+ pendingMarginTop = 0;
8763
+ }
8764
+ content.add(renderable);
8765
+ }
8766
+ return row;
8767
+ }
8768
+ applyListItemRenderable(row, input, previousItem) {
8769
+ this.applyListItemMarker(row, input);
8770
+ const content = row.getChildren()[1];
8771
+ if (!(content instanceof BoxRenderable))
8772
+ return false;
8773
+ if (previousItem && previousItem.raw === input.item.raw) {
8774
+ return true;
8775
+ }
8776
+ return this.applyListItemChildren(content, input.item, previousItem, input.id);
8777
+ }
8778
+ applyListItemChildren(content, item, previousItem, id) {
8779
+ const previousTokens = previousItem ? this.getRenderableListItemTokens(previousItem) : [];
8780
+ const children = content.getChildren();
8781
+ let childIndex = 0;
8782
+ let pendingMarginTop = 0;
8783
+ for (let tokenIndex = 0;tokenIndex < item.tokens.length; tokenIndex += 1) {
8784
+ const token = item.tokens[tokenIndex];
8785
+ if (!token)
8786
+ continue;
8787
+ if (token.type === "checkbox")
8788
+ continue;
8789
+ if (token.type === "space") {
8790
+ pendingMarginTop = Math.max(pendingMarginTop, 1);
8791
+ continue;
8792
+ }
8793
+ const existing = children[childIndex];
8794
+ const childId = `${id}-child-${tokenIndex}`;
8795
+ if (!existing) {
8796
+ const renderable = this.createListChildRenderable(token, childId);
8797
+ if (!renderable)
8798
+ return false;
8799
+ renderable.marginTop = pendingMarginTop;
8800
+ pendingMarginTop = 0;
8801
+ content.add(renderable, childIndex);
8802
+ childIndex += 1;
8803
+ continue;
8804
+ }
8805
+ if (!this.applyListChildRenderable(existing, token, previousTokens[childIndex], childId)) {
8806
+ return false;
8807
+ }
8808
+ existing.marginTop = pendingMarginTop;
8809
+ pendingMarginTop = 0;
8810
+ childIndex += 1;
8811
+ }
8812
+ this.destroyListItemChildrenAfter(content, childIndex);
8813
+ return true;
8814
+ }
8815
+ getRenderableListItemTokens(item) {
8816
+ const tokens = [];
8817
+ for (const token of item.tokens) {
8818
+ if (token.type === "checkbox" || token.type === "space")
8819
+ continue;
8820
+ tokens.push(token);
8821
+ }
8822
+ return tokens;
8823
+ }
8824
+ applyListChildRenderable(renderable, token, previousToken, id) {
8825
+ if ((token.type === "text" || token.type === "paragraph") && renderable instanceof CodeRenderable) {
8826
+ this.applyMarkdownCodeRenderable(renderable, this.getListChildMarkdownRaw(token), 0);
8827
+ return true;
8828
+ }
8829
+ if (token.type === "list" && renderable instanceof BoxRenderable) {
8830
+ return this.applyListRenderable(renderable, token, previousToken, id);
8831
+ }
8832
+ if (token.type === "code" && renderable instanceof CodeRenderable) {
8833
+ this.applyCodeBlockRenderable(renderable, token, 0);
8834
+ return true;
8835
+ }
8836
+ return previousToken?.raw === token.raw;
8837
+ }
8838
+ destroyListItemChildrenAfter(content, index) {
8839
+ const children = content.getChildren();
8840
+ for (let i = children.length - 1;i >= index; i -= 1) {
8841
+ children[i]?.destroyRecursively();
8842
+ }
8843
+ }
8844
+ getListChildMarkdownRaw(token) {
8845
+ return token.type === "paragraph" ? this.normalizeScrollbackMarkdownBlockRaw(token.raw) : token.raw;
8846
+ }
8847
+ applyListItemMarker(row, input) {
8848
+ const marker = row.getChildren()[0];
8849
+ if (!(marker instanceof TextRenderable))
8850
+ return;
8851
+ const marginBottom = /\n[ \t]*\n$/.test(input.item.raw) ? 1 : 0;
8852
+ const markerWidth = input.markerWidth + 1;
8853
+ const markerText = input.marker.padStart(input.markerWidth) + " ";
8854
+ if (row.marginBottom !== marginBottom)
8855
+ row.marginBottom = marginBottom;
8856
+ if (marker.width !== markerWidth)
8857
+ marker.width = markerWidth;
8858
+ if (marker.chunks[0]?.text !== markerText) {
8859
+ marker.content = new StyledText([this.createChunk(markerText, "markup.list")]);
8860
+ }
8861
+ }
8862
+ createListChildRenderable(token, id) {
8863
+ if (token.type === "text" || token.type === "paragraph") {
8864
+ return this.createMarkdownCodeRenderable(this.getListChildMarkdownRaw(token), id);
8865
+ }
8866
+ if (token.type === "list")
8867
+ return this.createListRenderable(token, id);
8868
+ if (token.type === "code")
8869
+ return this.createCodeRenderable(token, id);
8870
+ if (token.type === "blockquote")
8871
+ return this.createBlockquoteRenderable(token, id);
8872
+ if (token.type === "hr")
8873
+ return this.createHorizontalRuleRenderable(id);
8874
+ if (token.type === "table")
8875
+ return this.createTableBlock(token, id).renderable;
8876
+ return token.raw ? this.createMarkdownCodeRenderable(token.raw, id) : null;
8877
+ }
8680
8878
  createHorizontalRuleRenderable(id, marginBottom = 0) {
8681
8879
  return new BoxRenderable(this.ctx, {
8682
8880
  id,
@@ -9097,6 +9295,11 @@ class MarkdownRenderable extends Renderable {
9097
9295
  renderable2.marginTop = marginTop;
9098
9296
  return { renderable: renderable2 };
9099
9297
  }
9298
+ if (token.type === "list") {
9299
+ const renderable2 = this.createListRenderable(token, id);
9300
+ renderable2.marginTop = marginTop;
9301
+ return { renderable: renderable2 };
9302
+ }
9100
9303
  if (token.type === "hr") {
9101
9304
  const renderable2 = this.createHorizontalRuleRenderable(id);
9102
9305
  renderable2.marginTop = marginTop;
@@ -9142,6 +9345,9 @@ class MarkdownRenderable extends Renderable {
9142
9345
  if (token.type === "blockquote") {
9143
9346
  return this.createBlockquoteRenderable(token, id, marginBottom);
9144
9347
  }
9348
+ if (token.type === "list") {
9349
+ return this.createListRenderable(token, id, marginBottom);
9350
+ }
9145
9351
  if (token.type === "hr") {
9146
9352
  return this.createHorizontalRuleRenderable(id, marginBottom);
9147
9353
  }
@@ -9156,7 +9362,7 @@ class MarkdownRenderable extends Renderable {
9156
9362
  }
9157
9363
  return this.createMarkdownCodeRenderable(token.raw, id, marginBottom);
9158
9364
  }
9159
- updateBlockRenderable(state, token, index, hasNextToken) {
9365
+ updateBlockRenderable(state, token, index, hasNextToken, forceListRefresh = false) {
9160
9366
  const marginBottom = this.getInterBlockMargin(token, hasNextToken);
9161
9367
  if (token.type === "code") {
9162
9368
  this.applyCodeBlockRenderable(state.renderable, token, marginBottom);
@@ -9166,6 +9372,14 @@ class MarkdownRenderable extends Renderable {
9166
9372
  this.applyBlockquoteRenderable(state.renderable, token, marginBottom);
9167
9373
  return;
9168
9374
  }
9375
+ if (token.type === "list") {
9376
+ if (!this.applyListRenderable(state.renderable, token, forceListRefresh ? undefined : state.token, `${this.id}-block-${index}`, marginBottom)) {
9377
+ state.renderable.destroyRecursively();
9378
+ state.renderable = this.createListRenderable(token, `${this.id}-block-${index}`, marginBottom);
9379
+ this.add(state.renderable, index);
9380
+ }
9381
+ return;
9382
+ }
9169
9383
  if (token.type === "hr") {
9170
9384
  state.renderable.marginBottom = marginBottom;
9171
9385
  return;
@@ -9181,7 +9395,7 @@ class MarkdownRenderable extends Renderable {
9181
9395
  }
9182
9396
  state.renderable.destroyRecursively();
9183
9397
  const fallbackRenderable = this.createMarkdownCodeRenderable(tableToken.raw, `${this.id}-block-${index}`, marginBottom);
9184
- this.add(fallbackRenderable);
9398
+ this.add(fallbackRenderable, index);
9185
9399
  state.renderable = fallbackRenderable;
9186
9400
  state.tableContentCache = undefined;
9187
9401
  return;
@@ -9197,7 +9411,7 @@ class MarkdownRenderable extends Renderable {
9197
9411
  }
9198
9412
  state.renderable.destroyRecursively();
9199
9413
  const tableRenderable = this.createTextTableRenderable(cache.content, `${this.id}-block-${index}`, marginBottom);
9200
- this.add(tableRenderable);
9414
+ this.add(tableRenderable, index);
9201
9415
  state.renderable = tableRenderable;
9202
9416
  state.tableContentCache = cache;
9203
9417
  return;
@@ -9272,6 +9486,8 @@ class MarkdownRenderable extends Renderable {
9272
9486
  return renderable instanceof TextTableRenderable;
9273
9487
  if (token.type === "blockquote")
9274
9488
  return renderable instanceof BoxRenderable;
9489
+ if (token.type === "list")
9490
+ return renderable instanceof BoxRenderable;
9275
9491
  if (token.type === "hr")
9276
9492
  return renderable instanceof BoxRenderable;
9277
9493
  return renderable instanceof CodeRenderable;
@@ -9411,6 +9627,10 @@ class MarkdownRenderable extends Renderable {
9411
9627
  this.applyBlockquoteRenderable(state.renderable, state.token, marginBottom);
9412
9628
  continue;
9413
9629
  }
9630
+ if (state.token.type === "list") {
9631
+ this.updateBlockRenderable(state, state.token, i, hasNextToken, true);
9632
+ continue;
9633
+ }
9414
9634
  if (state.token.type === "hr") {
9415
9635
  state.renderable.marginBottom = marginBottom;
9416
9636
  continue;
@@ -11514,5 +11734,5 @@ class TimeToFirstDrawRenderable extends Renderable {
11514
11734
  }
11515
11735
  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 };
11516
11736
 
11517
- //# debugId=38C52BEFC4FA5FFE64756E2164756E21
11518
- //# sourceMappingURL=index-tx8a4862.js.map
11737
+ //# debugId=8F2E8A6BC348D97764756E2164756E21
11738
+ //# sourceMappingURL=index-691sybgy.js.map