@fairyhunter13/opentui-core 0.1.88 → 0.1.90
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/dev/keypress-debug-renderer.ts +148 -0
- package/dev/keypress-debug.ts +43 -0
- package/dev/print-env-vars.ts +32 -0
- package/dev/test-tmux-graphics-334.sh +68 -0
- package/dev/thai-debug-test.ts +68 -0
- package/docs/development.md +141 -0
- package/docs/env-vars.md +140 -0
- package/docs/getting-started.md +353 -0
- package/docs/renderables-vs-constructs.md +159 -0
- package/docs/tree-sitter.md +311 -0
- package/package.json +61 -52
- package/scripts/build.ts +400 -0
- package/scripts/publish.ts +60 -0
- package/src/3d/SpriteResourceManager.ts +286 -0
- package/src/3d/SpriteUtils.ts +71 -0
- package/src/3d/TextureUtils.ts +196 -0
- package/src/3d/ThreeRenderable.ts +197 -0
- package/src/3d/WGPURenderer.ts +294 -0
- package/src/3d/animation/ExplodingSpriteEffect.ts +513 -0
- package/src/3d/animation/PhysicsExplodingSpriteEffect.ts +429 -0
- package/src/3d/animation/SpriteAnimator.ts +633 -0
- package/src/3d/animation/SpriteParticleGenerator.ts +435 -0
- package/src/3d/canvas.ts +464 -0
- package/src/3d/index.ts +12 -0
- package/src/3d/physics/PlanckPhysicsAdapter.ts +72 -0
- package/src/3d/physics/RapierPhysicsAdapter.ts +66 -0
- package/src/3d/physics/physics-interface.ts +31 -0
- package/src/3d/shaders/supersampling.wgsl +201 -0
- package/src/3d.ts +3 -0
- package/src/NativeSpanFeed.ts +300 -0
- package/src/Renderable.ts +1698 -0
- package/src/__snapshots__/buffer.test.ts.snap +28 -0
- package/src/animation/Timeline.test.ts +2709 -0
- package/src/animation/Timeline.ts +598 -0
- package/src/ansi.ts +18 -0
- package/src/benchmark/latest-all-bench-run.json +707 -0
- package/src/benchmark/latest-async-bench-run.json +336 -0
- package/src/benchmark/latest-default-bench-run.json +657 -0
- package/src/benchmark/latest-large-bench-run.json +707 -0
- package/src/benchmark/latest-quick-bench-run.json +207 -0
- package/src/benchmark/markdown-benchmark.ts +1804 -0
- package/src/benchmark/native-span-feed-async-benchmark.ts +355 -0
- package/src/benchmark/native-span-feed-benchmark.md +56 -0
- package/src/benchmark/native-span-feed-benchmark.ts +596 -0
- package/src/benchmark/native-span-feed-compare.ts +280 -0
- package/src/benchmark/renderer-benchmark.ts +754 -0
- package/src/benchmark/text-table-benchmark.ts +947 -0
- package/src/buffer.test.ts +291 -0
- package/src/buffer.ts +519 -0
- package/src/console.test.ts +612 -0
- package/src/console.ts +1255 -0
- package/src/edit-buffer.test.ts +1769 -0
- package/src/edit-buffer.ts +411 -0
- package/src/editor-view.test.ts +1032 -0
- package/src/editor-view.ts +284 -0
- package/src/examples/ascii-font-selection-demo.ts +245 -0
- package/src/examples/assets/Water_2_M_Normal.jpg +0 -0
- package/src/examples/assets/concrete.png +0 -0
- package/src/examples/assets/crate.png +0 -0
- package/src/examples/assets/crate_emissive.png +0 -0
- package/src/examples/assets/forrest_background.png +0 -0
- package/src/examples/assets/hast-example.json +1018 -0
- package/src/examples/assets/heart.png +0 -0
- package/src/examples/assets/main_char_heavy_attack.png +0 -0
- package/src/examples/assets/main_char_idle.png +0 -0
- package/src/examples/assets/main_char_jump_end.png +0 -0
- package/src/examples/assets/main_char_jump_landing.png +0 -0
- package/src/examples/assets/main_char_jump_start.png +0 -0
- package/src/examples/assets/main_char_run_loop.png +0 -0
- package/src/examples/assets/roughness_map.jpg +0 -0
- package/src/examples/build.ts +115 -0
- package/src/examples/code-demo.ts +584 -0
- package/src/examples/console-demo.ts +358 -0
- package/src/examples/core-plugin-slots-demo.ts +759 -0
- package/src/examples/diff-demo.ts +699 -0
- package/src/examples/draggable-three-demo.ts +259 -0
- package/src/examples/editor-demo.ts +322 -0
- package/src/examples/extmarks-demo.ts +204 -0
- package/src/examples/focus-restore-demo.ts +310 -0
- package/src/examples/fonts.ts +245 -0
- package/src/examples/fractal-shader-demo.ts +268 -0
- package/src/examples/framebuffer-demo.ts +674 -0
- package/src/examples/full-unicode-demo.ts +181 -0
- package/src/examples/golden-star-demo.ts +933 -0
- package/src/examples/grayscale-buffer-demo.ts +249 -0
- package/src/examples/hast-syntax-highlighting-demo.ts +129 -0
- package/src/examples/index.ts +925 -0
- package/src/examples/input-demo.ts +377 -0
- package/src/examples/input-select-layout-demo.ts +425 -0
- package/src/examples/install.sh +143 -0
- package/src/examples/keypress-debug-demo.ts +452 -0
- package/src/examples/lib/HexList.ts +122 -0
- package/src/examples/lib/PaletteGrid.ts +125 -0
- package/src/examples/lib/standalone-keys.ts +25 -0
- package/src/examples/lib/tab-controller.ts +243 -0
- package/src/examples/lights-phong-demo.ts +290 -0
- package/src/examples/link-demo.ts +220 -0
- package/src/examples/live-state-demo.ts +480 -0
- package/src/examples/markdown-demo.ts +620 -0
- package/src/examples/mouse-interaction-demo.ts +428 -0
- package/src/examples/nested-zindex-demo.ts +357 -0
- package/src/examples/opacity-example.ts +235 -0
- package/src/examples/opentui-demo.ts +1057 -0
- package/src/examples/physx-planck-2d-demo.ts +507 -0
- package/src/examples/physx-rapier-2d-demo.ts +526 -0
- package/src/examples/relative-positioning-demo.ts +323 -0
- package/src/examples/scroll-example.ts +214 -0
- package/src/examples/scrollbox-mouse-test.ts +112 -0
- package/src/examples/scrollbox-overlay-hit-test.ts +206 -0
- package/src/examples/select-demo.ts +237 -0
- package/src/examples/shader-cube-demo.ts +772 -0
- package/src/examples/simple-layout-example.ts +591 -0
- package/src/examples/slider-demo.ts +617 -0
- package/src/examples/split-mode-demo.ts +445 -0
- package/src/examples/sprite-animation-demo.ts +443 -0
- package/src/examples/sprite-particle-generator-demo.ts +486 -0
- package/src/examples/static-sprite-demo.ts +193 -0
- package/src/examples/sticky-scroll-example.ts +308 -0
- package/src/examples/styled-text-demo.ts +282 -0
- package/src/examples/tab-select-demo.ts +219 -0
- package/src/examples/terminal-title.ts +29 -0
- package/src/examples/terminal.ts +305 -0
- package/src/examples/text-node-demo.ts +416 -0
- package/src/examples/text-selection-demo.ts +377 -0
- package/src/examples/text-table-demo.ts +503 -0
- package/src/examples/text-truncation-demo.ts +481 -0
- package/src/examples/text-wrap.ts +757 -0
- package/src/examples/texture-loading-demo.ts +259 -0
- package/src/examples/timeline-example.ts +670 -0
- package/src/examples/transparency-demo.ts +241 -0
- package/src/examples/vnode-composition-demo.ts +404 -0
- package/src/index.ts +22 -0
- package/src/lib/KeyHandler.integration.test.ts +292 -0
- package/src/lib/KeyHandler.stopPropagation.test.ts +289 -0
- package/src/lib/KeyHandler.test.ts +662 -0
- package/src/lib/KeyHandler.ts +222 -0
- package/src/lib/RGBA.test.ts +984 -0
- package/src/lib/RGBA.ts +204 -0
- package/src/lib/ascii.font.ts +330 -0
- package/src/lib/border.test.ts +83 -0
- package/src/lib/border.ts +168 -0
- package/src/lib/bunfs.test.ts +27 -0
- package/src/lib/bunfs.ts +18 -0
- package/src/lib/clipboard.test.ts +41 -0
- package/src/lib/clipboard.ts +47 -0
- package/src/lib/clock.ts +31 -0
- package/src/lib/data-paths.test.ts +133 -0
- package/src/lib/data-paths.ts +109 -0
- package/src/lib/debounce.ts +106 -0
- package/src/lib/detect-links.test.ts +98 -0
- package/src/lib/detect-links.ts +56 -0
- package/src/lib/env.test.ts +228 -0
- package/src/lib/env.ts +209 -0
- package/src/lib/extmarks-history.ts +51 -0
- package/src/lib/extmarks-multiwidth.test.ts +322 -0
- package/src/lib/extmarks.test.ts +3457 -0
- package/src/lib/extmarks.ts +843 -0
- package/src/lib/fonts/block.json +405 -0
- package/src/lib/fonts/grid.json +265 -0
- package/src/lib/fonts/huge.json +741 -0
- package/src/lib/fonts/pallet.json +314 -0
- package/src/lib/fonts/shade.json +591 -0
- package/src/lib/fonts/slick.json +321 -0
- package/src/lib/fonts/tiny.json +69 -0
- package/src/lib/hast-styled-text.ts +59 -0
- package/src/lib/index.ts +21 -0
- package/src/lib/keymapping.test.ts +280 -0
- package/src/lib/keymapping.ts +87 -0
- package/src/lib/objects-in-viewport.test.ts +787 -0
- package/src/lib/objects-in-viewport.ts +153 -0
- package/src/lib/output.capture.ts +58 -0
- package/src/lib/parse.keypress-kitty.protocol.test.ts +340 -0
- package/src/lib/parse.keypress-kitty.test.ts +663 -0
- package/src/lib/parse.keypress-kitty.ts +439 -0
- package/src/lib/parse.keypress.test.ts +1849 -0
- package/src/lib/parse.keypress.ts +397 -0
- package/src/lib/parse.mouse.test.ts +552 -0
- package/src/lib/parse.mouse.ts +232 -0
- package/src/lib/paste.ts +16 -0
- package/src/lib/queue.ts +65 -0
- package/src/lib/renderable.validations.test.ts +87 -0
- package/src/lib/renderable.validations.ts +83 -0
- package/src/lib/scroll-acceleration.ts +98 -0
- package/src/lib/selection.ts +240 -0
- package/src/lib/singleton.ts +28 -0
- package/src/lib/stdin-parser.test.ts +1676 -0
- package/src/lib/stdin-parser.ts +1248 -0
- package/src/lib/styled-text.ts +178 -0
- package/src/lib/terminal-capability-detection.test.ts +202 -0
- package/src/lib/terminal-capability-detection.ts +79 -0
- package/src/lib/terminal-palette.test.ts +878 -0
- package/src/lib/terminal-palette.ts +383 -0
- package/src/lib/tree-sitter/assets/README.md +118 -0
- package/src/lib/tree-sitter/assets/update.ts +331 -0
- package/src/lib/tree-sitter/assets.d.ts +9 -0
- package/src/lib/tree-sitter/cache.test.ts +270 -0
- package/src/lib/tree-sitter/client.test.ts +1061 -0
- package/src/lib/tree-sitter/client.ts +615 -0
- package/src/lib/tree-sitter/default-parsers.ts +80 -0
- package/src/lib/tree-sitter/download-utils.ts +148 -0
- package/src/lib/tree-sitter/index.ts +28 -0
- package/src/lib/tree-sitter/parser.worker.ts +1001 -0
- package/src/lib/tree-sitter/parsers-config.ts +75 -0
- package/src/lib/tree-sitter/resolve-ft.ts +62 -0
- package/src/lib/tree-sitter/types.ts +81 -0
- package/src/lib/tree-sitter-styled-text.test.ts +1253 -0
- package/src/lib/tree-sitter-styled-text.ts +306 -0
- package/src/lib/validate-dir-name.ts +55 -0
- package/src/lib/yoga.options.test.ts +628 -0
- package/src/lib/yoga.options.ts +346 -0
- package/src/plugins/core-slot.ts +579 -0
- package/src/plugins/registry.ts +377 -0
- package/src/plugins/types.ts +46 -0
- package/src/post/filters.ts +888 -0
- package/src/renderables/ASCIIFont.ts +219 -0
- package/src/renderables/Box.test.ts +160 -0
- package/src/renderables/Box.ts +295 -0
- package/src/renderables/Code.test.ts +2062 -0
- package/src/renderables/Code.ts +357 -0
- package/src/renderables/Diff.regression.test.ts +226 -0
- package/src/renderables/Diff.test.ts +3027 -0
- package/src/renderables/Diff.ts +1209 -0
- package/src/renderables/EditBufferRenderable.ts +764 -0
- package/src/renderables/FrameBuffer.ts +47 -0
- package/src/renderables/Input.test.ts +1228 -0
- package/src/renderables/Input.ts +245 -0
- package/src/renderables/LineNumberRenderable.ts +675 -0
- package/src/renderables/Markdown.ts +1106 -0
- package/src/renderables/ScrollBar.ts +422 -0
- package/src/renderables/ScrollBox.ts +883 -0
- package/src/renderables/Select.test.ts +1010 -0
- package/src/renderables/Select.ts +523 -0
- package/src/renderables/Slider.test.ts +456 -0
- package/src/renderables/Slider.ts +347 -0
- package/src/renderables/TabSelect.test.ts +197 -0
- package/src/renderables/TabSelect.ts +455 -0
- package/src/renderables/Text.selection-buffer.test.ts +123 -0
- package/src/renderables/Text.test.ts +2660 -0
- package/src/renderables/Text.ts +147 -0
- package/src/renderables/TextBufferRenderable.ts +518 -0
- package/src/renderables/TextNode.test.ts +1058 -0
- package/src/renderables/TextNode.ts +325 -0
- package/src/renderables/TextTable.test.ts +1421 -0
- package/src/renderables/TextTable.ts +1344 -0
- package/src/renderables/Textarea.ts +732 -0
- package/src/renderables/TimeToFirstDraw.ts +89 -0
- package/src/renderables/__snapshots__/Code.test.ts.snap +13 -0
- package/src/renderables/__snapshots__/Diff.test.ts.snap +785 -0
- package/src/renderables/__snapshots__/Text.test.ts.snap +421 -0
- package/src/renderables/__snapshots__/TextTable.test.ts.snap +215 -0
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +144 -0
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +816 -0
- package/src/renderables/__tests__/LineNumberRenderable.test.ts +1787 -0
- package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +85 -0
- package/src/renderables/__tests__/Markdown.test.ts +2287 -0
- package/src/renderables/__tests__/MultiRenderable.selection.test.ts +87 -0
- package/src/renderables/__tests__/Textarea.buffer.test.ts +682 -0
- package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +675 -0
- package/src/renderables/__tests__/Textarea.editing.test.ts +2041 -0
- package/src/renderables/__tests__/Textarea.error-handling.test.ts +35 -0
- package/src/renderables/__tests__/Textarea.events.test.ts +738 -0
- package/src/renderables/__tests__/Textarea.highlights.test.ts +590 -0
- package/src/renderables/__tests__/Textarea.keybinding.test.ts +3149 -0
- package/src/renderables/__tests__/Textarea.paste.test.ts +357 -0
- package/src/renderables/__tests__/Textarea.rendering.test.ts +1864 -0
- package/src/renderables/__tests__/Textarea.scroll.test.ts +733 -0
- package/src/renderables/__tests__/Textarea.selection.test.ts +1590 -0
- package/src/renderables/__tests__/Textarea.stress.test.ts +670 -0
- package/src/renderables/__tests__/Textarea.undo-redo.test.ts +383 -0
- package/src/renderables/__tests__/Textarea.visual-lines.test.ts +310 -0
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +221 -0
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +89 -0
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +457 -0
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +158 -0
- package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +387 -0
- package/src/renderables/__tests__/markdown-parser.test.ts +217 -0
- package/src/renderables/__tests__/renderable-test-utils.ts +60 -0
- package/src/renderables/composition/README.md +8 -0
- package/src/renderables/composition/VRenderable.ts +32 -0
- package/src/renderables/composition/constructs.ts +127 -0
- package/src/renderables/composition/vnode.ts +289 -0
- package/src/renderables/index.ts +22 -0
- package/src/renderables/markdown-parser.ts +66 -0
- package/src/renderer.ts +2363 -0
- package/src/runtime-plugin-support.ts +39 -0
- package/src/runtime-plugin.ts +144 -0
- package/src/syntax-style.test.ts +841 -0
- package/src/syntax-style.ts +264 -0
- package/src/testing/README.md +210 -0
- package/src/testing/capture-spans.test.ts +194 -0
- package/src/testing/integration.test.ts +276 -0
- package/src/testing/manual-clock.ts +106 -0
- package/src/testing/mock-keys.test.ts +1356 -0
- package/src/testing/mock-keys.ts +449 -0
- package/src/testing/mock-mouse.test.ts +218 -0
- package/src/testing/mock-mouse.ts +247 -0
- package/src/testing/mock-tree-sitter-client.ts +73 -0
- package/src/testing/spy.ts +13 -0
- package/src/testing/test-recorder.test.ts +415 -0
- package/src/testing/test-recorder.ts +145 -0
- package/src/testing/test-renderer.ts +116 -0
- package/src/testing.ts +7 -0
- package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +481 -0
- package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +19 -0
- package/src/tests/__snapshots__/scrollbox.test.ts.snap +29 -0
- package/src/tests/absolute-positioning.snapshot.test.ts +638 -0
- package/src/tests/allocator-stats.test.ts +38 -0
- package/src/tests/destroy-during-render.test.ts +200 -0
- package/src/tests/hover-cursor.test.ts +98 -0
- package/src/tests/native-span-feed-async.test.ts +173 -0
- package/src/tests/native-span-feed-close.test.ts +120 -0
- package/src/tests/native-span-feed-coverage.test.ts +227 -0
- package/src/tests/native-span-feed-edge-cases.test.ts +352 -0
- package/src/tests/native-span-feed-use-after-free.test.ts +45 -0
- package/src/tests/opacity.test.ts +123 -0
- package/src/tests/renderable.snapshot.test.ts +524 -0
- package/src/tests/renderable.test.ts +1281 -0
- package/src/tests/renderer.console-startup.test.ts +65 -0
- package/src/tests/renderer.control.test.ts +364 -0
- package/src/tests/renderer.core-slot-binding.test.ts +952 -0
- package/src/tests/renderer.cursor.test.ts +26 -0
- package/src/tests/renderer.destroy-during-render.test.ts +110 -0
- package/src/tests/renderer.focus-restore.test.ts +228 -0
- package/src/tests/renderer.focus.test.ts +251 -0
- package/src/tests/renderer.idle.test.ts +219 -0
- package/src/tests/renderer.input.test.ts +2145 -0
- package/src/tests/renderer.kitty-flags.test.ts +195 -0
- package/src/tests/renderer.mouse.test.ts +1269 -0
- package/src/tests/renderer.palette.test.ts +629 -0
- package/src/tests/renderer.selection.test.ts +49 -0
- package/src/tests/renderer.slot-registry.test.ts +649 -0
- package/src/tests/renderer.useMouse.test.ts +50 -0
- package/src/tests/runtime-plugin-support.fixture.ts +11 -0
- package/src/tests/runtime-plugin-support.test.ts +28 -0
- package/src/tests/runtime-plugin.fixture.ts +40 -0
- package/src/tests/runtime-plugin.test.ts +190 -0
- package/src/tests/scrollbox-culling-bug.test.ts +114 -0
- package/src/tests/scrollbox-hitgrid-resize.test.ts +136 -0
- package/src/tests/scrollbox-hitgrid.test.ts +909 -0
- package/src/tests/scrollbox.test.ts +1530 -0
- package/src/tests/wrap-resize-perf.test.ts +229 -0
- package/src/tests/yoga-setters.test.ts +921 -0
- package/src/text-buffer-view.test.ts +705 -0
- package/src/text-buffer-view.ts +189 -0
- package/src/text-buffer.test.ts +347 -0
- package/src/text-buffer.ts +250 -0
- package/src/types.ts +152 -0
- package/src/utils.ts +88 -0
- package/src/zig/ansi.zig +268 -0
- package/src/zig/bench/README.md +50 -0
- package/src/zig/bench/buffer-draw-text-buffer_bench.zig +887 -0
- package/src/zig/bench/edit-buffer_bench.zig +476 -0
- package/src/zig/bench/native-span-feed_bench.zig +100 -0
- package/src/zig/bench/rope-markers_bench.zig +713 -0
- package/src/zig/bench/rope_bench.zig +514 -0
- package/src/zig/bench/styled-text_bench.zig +470 -0
- package/src/zig/bench/text-buffer-coords_bench.zig +362 -0
- package/src/zig/bench/text-buffer-view_bench.zig +459 -0
- package/src/zig/bench/text-chunk-graphemes_bench.zig +273 -0
- package/src/zig/bench/utf8_bench.zig +799 -0
- package/src/zig/bench-utils.zig +431 -0
- package/src/zig/bench.zig +217 -0
- package/src/zig/buffer.zig +2223 -0
- package/src/zig/build.zig +289 -0
- package/src/zig/build.zig.zon +16 -0
- package/src/zig/edit-buffer.zig +825 -0
- package/src/zig/editor-view.zig +802 -0
- package/src/zig/event-bus.zig +13 -0
- package/src/zig/event-emitter.zig +65 -0
- package/src/zig/file-logger.zig +92 -0
- package/src/zig/grapheme.zig +599 -0
- package/src/zig/lib.zig +1834 -0
- package/src/zig/link.zig +333 -0
- package/src/zig/logger.zig +43 -0
- package/src/zig/mem-registry.zig +125 -0
- package/src/zig/native-span-feed-bench-lib.zig +7 -0
- package/src/zig/native-span-feed.zig +708 -0
- package/src/zig/renderer.zig +1386 -0
- package/src/zig/rope.zig +1220 -0
- package/src/zig/syntax-style.zig +161 -0
- package/src/zig/terminal.zig +975 -0
- package/src/zig/test.zig +70 -0
- package/src/zig/tests/README.md +18 -0
- package/src/zig/tests/buffer_test.zig +2526 -0
- package/src/zig/tests/edit-buffer-history_test.zig +271 -0
- package/src/zig/tests/edit-buffer_test.zig +1689 -0
- package/src/zig/tests/editor-view_test.zig +3299 -0
- package/src/zig/tests/event-emitter_test.zig +249 -0
- package/src/zig/tests/grapheme_test.zig +1304 -0
- package/src/zig/tests/link_test.zig +190 -0
- package/src/zig/tests/mem-registry_test.zig +473 -0
- package/src/zig/tests/memory_leak_regression_test.zig +159 -0
- package/src/zig/tests/native-span-feed_test.zig +1264 -0
- package/src/zig/tests/renderer_test.zig +1010 -0
- package/src/zig/tests/rope-nested_test.zig +712 -0
- package/src/zig/tests/rope_fuzz_test.zig +238 -0
- package/src/zig/tests/rope_test.zig +2362 -0
- package/src/zig/tests/segment-merge.test.zig +148 -0
- package/src/zig/tests/syntax-style_test.zig +557 -0
- package/src/zig/tests/terminal_test.zig +719 -0
- package/src/zig/tests/text-buffer-drawing_test.zig +3237 -0
- package/src/zig/tests/text-buffer-highlights_test.zig +666 -0
- package/src/zig/tests/text-buffer-iterators_test.zig +776 -0
- package/src/zig/tests/text-buffer-segment_test.zig +320 -0
- package/src/zig/tests/text-buffer-selection_test.zig +1035 -0
- package/src/zig/tests/text-buffer-selection_viewport_test.zig +358 -0
- package/src/zig/tests/text-buffer-view_test.zig +3649 -0
- package/src/zig/tests/text-buffer_test.zig +2191 -0
- package/src/zig/tests/unicode-width-map.zon +3909 -0
- package/src/zig/tests/utf8_no_zwj_test.zig +260 -0
- package/src/zig/tests/utf8_test.zig +4057 -0
- package/src/zig/tests/utf8_wcwidth_cursor_test.zig +267 -0
- package/src/zig/tests/utf8_wcwidth_test.zig +357 -0
- package/src/zig/tests/word-wrap-editing_test.zig +498 -0
- package/src/zig/tests/wrap-cache-perf_test.zig +113 -0
- package/src/zig/text-buffer-iterators.zig +499 -0
- package/src/zig/text-buffer-segment.zig +404 -0
- package/src/zig/text-buffer-view.zig +1371 -0
- package/src/zig/text-buffer.zig +1180 -0
- package/src/zig/utf8.zig +1948 -0
- package/src/zig/utils.zig +9 -0
- package/src/zig-structs.ts +261 -0
- package/src/zig.ts +3843 -0
- package/tsconfig.build.json +22 -0
- package/tsconfig.json +28 -0
- package/3d/SpriteResourceManager.d.ts +0 -74
- package/3d/SpriteUtils.d.ts +0 -13
- package/3d/TextureUtils.d.ts +0 -24
- package/3d/ThreeRenderable.d.ts +0 -40
- package/3d/WGPURenderer.d.ts +0 -61
- package/3d/animation/ExplodingSpriteEffect.d.ts +0 -71
- package/3d/animation/PhysicsExplodingSpriteEffect.d.ts +0 -76
- package/3d/animation/SpriteAnimator.d.ts +0 -124
- package/3d/animation/SpriteParticleGenerator.d.ts +0 -62
- package/3d/canvas.d.ts +0 -44
- package/3d/index.d.ts +0 -12
- package/3d/physics/PlanckPhysicsAdapter.d.ts +0 -19
- package/3d/physics/RapierPhysicsAdapter.d.ts +0 -19
- package/3d/physics/physics-interface.d.ts +0 -27
- package/3d.d.ts +0 -2
- package/3d.js +0 -34042
- package/3d.js.map +0 -155
- package/LICENSE +0 -21
- package/NativeSpanFeed.d.ts +0 -41
- package/Renderable.d.ts +0 -334
- package/animation/Timeline.d.ts +0 -126
- package/ansi.d.ts +0 -13
- package/buffer.d.ts +0 -107
- package/console.d.ts +0 -143
- package/edit-buffer.d.ts +0 -98
- package/editor-view.d.ts +0 -73
- package/index-e4hzc2j2.js +0 -113
- package/index-e4hzc2j2.js.map +0 -10
- package/index-nkrr8a4c.js +0 -18415
- package/index-nkrr8a4c.js.map +0 -64
- package/index-nyw5p3ep.js +0 -12619
- package/index-nyw5p3ep.js.map +0 -43
- package/index.d.ts +0 -21
- package/index.js +0 -430
- package/index.js.map +0 -9
- package/lib/KeyHandler.d.ts +0 -61
- package/lib/RGBA.d.ts +0 -25
- package/lib/ascii.font.d.ts +0 -508
- package/lib/border.d.ts +0 -49
- package/lib/bunfs.d.ts +0 -7
- package/lib/clipboard.d.ts +0 -17
- package/lib/clock.d.ts +0 -15
- package/lib/data-paths.d.ts +0 -26
- package/lib/debounce.d.ts +0 -42
- package/lib/detect-links.d.ts +0 -6
- package/lib/env.d.ts +0 -42
- package/lib/extmarks-history.d.ts +0 -17
- package/lib/extmarks.d.ts +0 -89
- package/lib/hast-styled-text.d.ts +0 -17
- package/lib/index.d.ts +0 -21
- package/lib/keymapping.d.ts +0 -25
- package/lib/objects-in-viewport.d.ts +0 -24
- package/lib/output.capture.d.ts +0 -24
- package/lib/parse.keypress-kitty.d.ts +0 -2
- package/lib/parse.keypress.d.ts +0 -26
- package/lib/parse.mouse.d.ts +0 -30
- package/lib/paste.d.ts +0 -7
- package/lib/queue.d.ts +0 -15
- package/lib/renderable.validations.d.ts +0 -12
- package/lib/scroll-acceleration.d.ts +0 -43
- package/lib/selection.d.ts +0 -63
- package/lib/singleton.d.ts +0 -7
- package/lib/stdin-parser.d.ts +0 -76
- package/lib/styled-text.d.ts +0 -63
- package/lib/terminal-capability-detection.d.ts +0 -30
- package/lib/terminal-palette.d.ts +0 -50
- package/lib/tree-sitter/assets/update.d.ts +0 -11
- package/lib/tree-sitter/client.d.ts +0 -47
- package/lib/tree-sitter/default-parsers.d.ts +0 -2
- package/lib/tree-sitter/download-utils.d.ts +0 -21
- package/lib/tree-sitter/index.d.ts +0 -8
- package/lib/tree-sitter/parser.worker.d.ts +0 -1
- package/lib/tree-sitter/parsers-config.d.ts +0 -38
- package/lib/tree-sitter/resolve-ft.d.ts +0 -2
- package/lib/tree-sitter/types.d.ts +0 -81
- package/lib/tree-sitter-styled-text.d.ts +0 -14
- package/lib/validate-dir-name.d.ts +0 -1
- package/lib/yoga.options.d.ts +0 -32
- package/parser.worker.js +0 -869
- package/parser.worker.js.map +0 -12
- package/plugins/core-slot.d.ts +0 -72
- package/plugins/registry.d.ts +0 -38
- package/plugins/types.d.ts +0 -34
- package/post/filters.d.ts +0 -105
- package/renderables/ASCIIFont.d.ts +0 -52
- package/renderables/Box.d.ts +0 -72
- package/renderables/Code.d.ts +0 -78
- package/renderables/Diff.d.ts +0 -142
- package/renderables/EditBufferRenderable.d.ts +0 -162
- package/renderables/FrameBuffer.d.ts +0 -16
- package/renderables/Input.d.ts +0 -67
- package/renderables/LineNumberRenderable.d.ts +0 -74
- package/renderables/Markdown.d.ts +0 -173
- package/renderables/ScrollBar.d.ts +0 -77
- package/renderables/ScrollBox.d.ts +0 -124
- package/renderables/Select.d.ts +0 -115
- package/renderables/Slider.d.ts +0 -44
- package/renderables/TabSelect.d.ts +0 -96
- package/renderables/Text.d.ts +0 -36
- package/renderables/TextBufferRenderable.d.ts +0 -105
- package/renderables/TextNode.d.ts +0 -91
- package/renderables/TextTable.d.ts +0 -140
- package/renderables/Textarea.d.ts +0 -114
- package/renderables/TimeToFirstDraw.d.ts +0 -24
- package/renderables/__tests__/renderable-test-utils.d.ts +0 -12
- package/renderables/composition/VRenderable.d.ts +0 -16
- package/renderables/composition/constructs.d.ts +0 -35
- package/renderables/composition/vnode.d.ts +0 -46
- package/renderables/index.d.ts +0 -22
- package/renderables/markdown-parser.d.ts +0 -10
- package/renderer.d.ts +0 -388
- package/runtime-plugin-support.d.ts +0 -3
- package/runtime-plugin-support.js +0 -29
- package/runtime-plugin-support.js.map +0 -10
- package/runtime-plugin.d.ts +0 -11
- package/runtime-plugin.js +0 -16
- package/runtime-plugin.js.map +0 -9
- package/syntax-style.d.ts +0 -54
- package/testing/manual-clock.d.ts +0 -16
- package/testing/mock-keys.d.ts +0 -81
- package/testing/mock-mouse.d.ts +0 -38
- package/testing/mock-tree-sitter-client.d.ts +0 -23
- package/testing/spy.d.ts +0 -7
- package/testing/test-recorder.d.ts +0 -61
- package/testing/test-renderer.d.ts +0 -23
- package/testing.d.ts +0 -6
- package/testing.js +0 -675
- package/testing.js.map +0 -15
- package/text-buffer-view.d.ts +0 -42
- package/text-buffer.d.ts +0 -67
- package/types.d.ts +0 -131
- package/utils.d.ts +0 -14
- package/zig-structs.d.ts +0 -155
- package/zig.d.ts +0 -351
- /package/{assets → src/lib/tree-sitter/assets}/javascript/highlights.scm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/javascript/tree-sitter-javascript.wasm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/markdown/highlights.scm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/markdown/injections.scm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/markdown/tree-sitter-markdown.wasm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/markdown_inline/highlights.scm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/typescript/highlights.scm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/typescript/tree-sitter-typescript.wasm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/zig/highlights.scm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/zig/tree-sitter-zig.wasm +0 -0
|
@@ -0,0 +1,1106 @@
|
|
|
1
|
+
import { Renderable, type RenderableOptions } from "../Renderable.js"
|
|
2
|
+
import { type RenderContext } from "../types.js"
|
|
3
|
+
import { SyntaxStyle, type StyleDefinition } from "../syntax-style.js"
|
|
4
|
+
import type { TextChunk } from "../text-buffer.js"
|
|
5
|
+
import { createTextAttributes } from "../utils.js"
|
|
6
|
+
import type { BorderStyle } from "../lib/border.js"
|
|
7
|
+
import type { ColorInput } from "../lib/RGBA.js"
|
|
8
|
+
import { type MarkedToken, type Token, type Tokens } from "marked"
|
|
9
|
+
import { CodeRenderable, type OnChunksCallback } from "./Code.js"
|
|
10
|
+
import {
|
|
11
|
+
TextTableRenderable,
|
|
12
|
+
type TextTableCellContent,
|
|
13
|
+
type TextTableColumnFitter,
|
|
14
|
+
type TextTableColumnWidthMode,
|
|
15
|
+
type TextTableContent,
|
|
16
|
+
} from "./TextTable.js"
|
|
17
|
+
import type { TreeSitterClient } from "../lib/tree-sitter/index.js"
|
|
18
|
+
import { parseMarkdownIncremental, type ParseState } from "./markdown-parser.js"
|
|
19
|
+
import type { OptimizedBuffer } from "../buffer.js"
|
|
20
|
+
import { detectLinks } from "../lib/detect-links.js"
|
|
21
|
+
|
|
22
|
+
export interface MarkdownTableOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Strategy for sizing table columns.
|
|
25
|
+
* - "content": columns fit to intrinsic content width.
|
|
26
|
+
* - "full": columns expand to fill available width.
|
|
27
|
+
*/
|
|
28
|
+
widthMode?: TextTableColumnWidthMode
|
|
29
|
+
/**
|
|
30
|
+
* Column fitting method when shrinking constrained tables.
|
|
31
|
+
*/
|
|
32
|
+
columnFitter?: TextTableColumnFitter
|
|
33
|
+
/**
|
|
34
|
+
* Wrapping strategy for table cell content.
|
|
35
|
+
*/
|
|
36
|
+
wrapMode?: "none" | "char" | "word"
|
|
37
|
+
/**
|
|
38
|
+
* Padding applied on all sides of each table cell.
|
|
39
|
+
*/
|
|
40
|
+
cellPadding?: number
|
|
41
|
+
/**
|
|
42
|
+
* Enables/disables table border rendering.
|
|
43
|
+
*/
|
|
44
|
+
borders?: boolean
|
|
45
|
+
/**
|
|
46
|
+
* Overrides outer border visibility. Defaults to `borders`.
|
|
47
|
+
*/
|
|
48
|
+
outerBorder?: boolean
|
|
49
|
+
/**
|
|
50
|
+
* Border style for markdown tables.
|
|
51
|
+
*/
|
|
52
|
+
borderStyle?: BorderStyle
|
|
53
|
+
/**
|
|
54
|
+
* Border color for markdown tables. Defaults to conceal style color.
|
|
55
|
+
*/
|
|
56
|
+
borderColor?: ColorInput
|
|
57
|
+
/**
|
|
58
|
+
* Enables/disables selection support on markdown tables.
|
|
59
|
+
*/
|
|
60
|
+
selectable?: boolean
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface MarkdownOptions extends RenderableOptions<MarkdownRenderable> {
|
|
64
|
+
content?: string
|
|
65
|
+
syntaxStyle: SyntaxStyle
|
|
66
|
+
/** Controls concealment for markdown syntax markers in markdown text blocks. */
|
|
67
|
+
conceal?: boolean
|
|
68
|
+
/** Controls concealment inside fenced code blocks rendered by CodeRenderable. */
|
|
69
|
+
concealCode?: boolean
|
|
70
|
+
treeSitterClient?: TreeSitterClient
|
|
71
|
+
/**
|
|
72
|
+
* Enable streaming mode for incremental content updates.
|
|
73
|
+
*
|
|
74
|
+
* Semantics:
|
|
75
|
+
* - The trailing markdown block stays unstable while streaming is enabled.
|
|
76
|
+
* - Tables render all rows produced by the markdown parser (including trailing rows).
|
|
77
|
+
* - Incomplete table rows are normalized by the parser and rendered with empty cells
|
|
78
|
+
* where data is missing.
|
|
79
|
+
*
|
|
80
|
+
* Expectations:
|
|
81
|
+
* - Keep this true while chunks are still being appended.
|
|
82
|
+
* - Set this to false once streaming is complete to finalize trailing token parsing.
|
|
83
|
+
*/
|
|
84
|
+
streaming?: boolean
|
|
85
|
+
/**
|
|
86
|
+
* Options for internally rendered markdown tables.
|
|
87
|
+
*/
|
|
88
|
+
tableOptions?: MarkdownTableOptions
|
|
89
|
+
/**
|
|
90
|
+
* Custom node renderer. Return a Renderable to override default rendering,
|
|
91
|
+
* or undefined/null to use default rendering.
|
|
92
|
+
*/
|
|
93
|
+
renderNode?: (token: Token, context: RenderNodeContext) => Renderable | undefined | null
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface RenderNodeContext {
|
|
97
|
+
syntaxStyle: SyntaxStyle
|
|
98
|
+
conceal: boolean
|
|
99
|
+
concealCode: boolean
|
|
100
|
+
treeSitterClient?: TreeSitterClient
|
|
101
|
+
/** Creates default renderable for this token */
|
|
102
|
+
defaultRender: () => Renderable | null
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface TableContentCache {
|
|
106
|
+
content: TextTableContent
|
|
107
|
+
cellKeys: Uint32Array[]
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
interface ResolvedTableRenderableOptions {
|
|
111
|
+
columnWidthMode: TextTableColumnWidthMode
|
|
112
|
+
columnFitter: TextTableColumnFitter
|
|
113
|
+
wrapMode: "none" | "char" | "word"
|
|
114
|
+
cellPadding: number
|
|
115
|
+
border: boolean
|
|
116
|
+
outerBorder: boolean
|
|
117
|
+
showBorders: boolean
|
|
118
|
+
borderStyle: BorderStyle
|
|
119
|
+
borderColor: ColorInput
|
|
120
|
+
selectable: boolean
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const TRAILING_MARKDOWN_BLOCK_BREAKS_RE = /(?:\r?\n){2,}$/
|
|
124
|
+
|
|
125
|
+
export interface BlockState {
|
|
126
|
+
token: MarkedToken
|
|
127
|
+
tokenRaw: string // Cache raw for comparison
|
|
128
|
+
renderable: Renderable
|
|
129
|
+
tableContentCache?: TableContentCache
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export type { ParseState }
|
|
133
|
+
|
|
134
|
+
export class MarkdownRenderable extends Renderable {
|
|
135
|
+
private _content: string = ""
|
|
136
|
+
private _syntaxStyle: SyntaxStyle
|
|
137
|
+
private _conceal: boolean
|
|
138
|
+
private _concealCode: boolean
|
|
139
|
+
private _treeSitterClient?: TreeSitterClient
|
|
140
|
+
private _tableOptions?: MarkdownTableOptions
|
|
141
|
+
private _renderNode?: MarkdownOptions["renderNode"]
|
|
142
|
+
|
|
143
|
+
_parseState: ParseState | null = null
|
|
144
|
+
private _streaming: boolean = false
|
|
145
|
+
_blockStates: BlockState[] = []
|
|
146
|
+
private _styleDirty: boolean = false
|
|
147
|
+
private _linkifyMarkdownChunks: OnChunksCallback = (chunks, context) =>
|
|
148
|
+
detectLinks(chunks, {
|
|
149
|
+
content: context.content,
|
|
150
|
+
highlights: context.highlights,
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
protected _contentDefaultOptions = {
|
|
154
|
+
content: "",
|
|
155
|
+
conceal: true,
|
|
156
|
+
concealCode: false,
|
|
157
|
+
streaming: false,
|
|
158
|
+
} satisfies Partial<MarkdownOptions>
|
|
159
|
+
|
|
160
|
+
constructor(ctx: RenderContext, options: MarkdownOptions) {
|
|
161
|
+
super(ctx, {
|
|
162
|
+
...options,
|
|
163
|
+
flexDirection: "column",
|
|
164
|
+
flexShrink: options.flexShrink ?? 0,
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
this._syntaxStyle = options.syntaxStyle
|
|
168
|
+
this._conceal = options.conceal ?? this._contentDefaultOptions.conceal
|
|
169
|
+
this._concealCode = options.concealCode ?? this._contentDefaultOptions.concealCode
|
|
170
|
+
this._content = options.content ?? this._contentDefaultOptions.content
|
|
171
|
+
this._treeSitterClient = options.treeSitterClient
|
|
172
|
+
this._tableOptions = options.tableOptions
|
|
173
|
+
this._renderNode = options.renderNode
|
|
174
|
+
this._streaming = options.streaming ?? this._contentDefaultOptions.streaming
|
|
175
|
+
|
|
176
|
+
this.updateBlocks()
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
get content(): string {
|
|
180
|
+
return this._content
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
set content(value: string) {
|
|
184
|
+
if (this.isDestroyed) return
|
|
185
|
+
if (this._content !== value) {
|
|
186
|
+
this._content = value
|
|
187
|
+
this.updateBlocks()
|
|
188
|
+
this.requestRender()
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
get syntaxStyle(): SyntaxStyle {
|
|
193
|
+
return this._syntaxStyle
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
set syntaxStyle(value: SyntaxStyle) {
|
|
197
|
+
if (this._syntaxStyle !== value) {
|
|
198
|
+
this._syntaxStyle = value
|
|
199
|
+
// Mark dirty - actual re-render happens in renderSelf
|
|
200
|
+
this._styleDirty = true
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
get conceal(): boolean {
|
|
205
|
+
return this._conceal
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
set conceal(value: boolean) {
|
|
209
|
+
if (this._conceal !== value) {
|
|
210
|
+
this._conceal = value
|
|
211
|
+
// Mark dirty - actual re-render happens in renderSelf
|
|
212
|
+
this._styleDirty = true
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
get concealCode(): boolean {
|
|
217
|
+
return this._concealCode
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
set concealCode(value: boolean) {
|
|
221
|
+
if (this._concealCode !== value) {
|
|
222
|
+
this._concealCode = value
|
|
223
|
+
// Mark dirty - actual re-render happens in renderSelf
|
|
224
|
+
this._styleDirty = true
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
get streaming(): boolean {
|
|
229
|
+
return this._streaming
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
set streaming(value: boolean) {
|
|
233
|
+
if (this.isDestroyed) return
|
|
234
|
+
if (this._streaming !== value) {
|
|
235
|
+
this._streaming = value
|
|
236
|
+
this.updateBlocks(true)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
get tableOptions(): MarkdownTableOptions | undefined {
|
|
241
|
+
return this._tableOptions
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
set tableOptions(value: MarkdownTableOptions | undefined) {
|
|
245
|
+
this._tableOptions = value
|
|
246
|
+
this.applyTableOptionsToBlocks()
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private getStyle(group: string): StyleDefinition | undefined {
|
|
250
|
+
// The solid reconciler applies props via setters in JSX declaration order.
|
|
251
|
+
// If `content` is set before `syntaxStyle`, updateBlocks() runs before
|
|
252
|
+
// _syntaxStyle is initialized.
|
|
253
|
+
if (!this._syntaxStyle) return undefined
|
|
254
|
+
let style = this._syntaxStyle.getStyle(group)
|
|
255
|
+
if (!style && group.includes(".")) {
|
|
256
|
+
const baseName = group.split(".")[0]
|
|
257
|
+
style = this._syntaxStyle.getStyle(baseName)
|
|
258
|
+
}
|
|
259
|
+
return style
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
private createChunk(text: string, group: string, link?: { url: string }): TextChunk {
|
|
263
|
+
const style = this.getStyle(group) || this.getStyle("default")
|
|
264
|
+
return {
|
|
265
|
+
__isChunk: true,
|
|
266
|
+
text,
|
|
267
|
+
fg: style?.fg,
|
|
268
|
+
bg: style?.bg,
|
|
269
|
+
attributes: style
|
|
270
|
+
? createTextAttributes({
|
|
271
|
+
bold: style.bold,
|
|
272
|
+
italic: style.italic,
|
|
273
|
+
underline: style.underline,
|
|
274
|
+
dim: style.dim,
|
|
275
|
+
})
|
|
276
|
+
: 0,
|
|
277
|
+
link,
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
private createDefaultChunk(text: string): TextChunk {
|
|
282
|
+
return this.createChunk(text, "default")
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private renderInlineContent(tokens: Token[], chunks: TextChunk[]): void {
|
|
286
|
+
for (const token of tokens) {
|
|
287
|
+
this.renderInlineToken(token as MarkedToken, chunks)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private renderInlineToken(token: MarkedToken, chunks: TextChunk[]): void {
|
|
292
|
+
switch (token.type) {
|
|
293
|
+
case "text":
|
|
294
|
+
chunks.push(this.createDefaultChunk(token.text))
|
|
295
|
+
break
|
|
296
|
+
|
|
297
|
+
case "escape":
|
|
298
|
+
chunks.push(this.createDefaultChunk(token.text))
|
|
299
|
+
break
|
|
300
|
+
|
|
301
|
+
case "codespan":
|
|
302
|
+
if (this._conceal) {
|
|
303
|
+
chunks.push(this.createChunk(token.text, "markup.raw"))
|
|
304
|
+
} else {
|
|
305
|
+
chunks.push(this.createChunk("`", "markup.raw"))
|
|
306
|
+
chunks.push(this.createChunk(token.text, "markup.raw"))
|
|
307
|
+
chunks.push(this.createChunk("`", "markup.raw"))
|
|
308
|
+
}
|
|
309
|
+
break
|
|
310
|
+
|
|
311
|
+
case "strong":
|
|
312
|
+
if (!this._conceal) {
|
|
313
|
+
chunks.push(this.createChunk("**", "markup.strong"))
|
|
314
|
+
}
|
|
315
|
+
for (const child of token.tokens) {
|
|
316
|
+
this.renderInlineTokenWithStyle(child as MarkedToken, chunks, "markup.strong")
|
|
317
|
+
}
|
|
318
|
+
if (!this._conceal) {
|
|
319
|
+
chunks.push(this.createChunk("**", "markup.strong"))
|
|
320
|
+
}
|
|
321
|
+
break
|
|
322
|
+
|
|
323
|
+
case "em":
|
|
324
|
+
if (!this._conceal) {
|
|
325
|
+
chunks.push(this.createChunk("*", "markup.italic"))
|
|
326
|
+
}
|
|
327
|
+
for (const child of token.tokens) {
|
|
328
|
+
this.renderInlineTokenWithStyle(child as MarkedToken, chunks, "markup.italic")
|
|
329
|
+
}
|
|
330
|
+
if (!this._conceal) {
|
|
331
|
+
chunks.push(this.createChunk("*", "markup.italic"))
|
|
332
|
+
}
|
|
333
|
+
break
|
|
334
|
+
|
|
335
|
+
case "del":
|
|
336
|
+
if (!this._conceal) {
|
|
337
|
+
chunks.push(this.createChunk("~~", "markup.strikethrough"))
|
|
338
|
+
}
|
|
339
|
+
for (const child of token.tokens) {
|
|
340
|
+
this.renderInlineTokenWithStyle(child as MarkedToken, chunks, "markup.strikethrough")
|
|
341
|
+
}
|
|
342
|
+
if (!this._conceal) {
|
|
343
|
+
chunks.push(this.createChunk("~~", "markup.strikethrough"))
|
|
344
|
+
}
|
|
345
|
+
break
|
|
346
|
+
|
|
347
|
+
case "link": {
|
|
348
|
+
const linkHref = { url: token.href }
|
|
349
|
+
if (this._conceal) {
|
|
350
|
+
for (const child of token.tokens) {
|
|
351
|
+
this.renderInlineTokenWithStyle(child as MarkedToken, chunks, "markup.link.label", linkHref)
|
|
352
|
+
}
|
|
353
|
+
chunks.push(this.createChunk(" (", "markup.link", linkHref))
|
|
354
|
+
chunks.push(this.createChunk(token.href, "markup.link.url", linkHref))
|
|
355
|
+
chunks.push(this.createChunk(")", "markup.link", linkHref))
|
|
356
|
+
} else {
|
|
357
|
+
chunks.push(this.createChunk("[", "markup.link", linkHref))
|
|
358
|
+
for (const child of token.tokens) {
|
|
359
|
+
this.renderInlineTokenWithStyle(child as MarkedToken, chunks, "markup.link.label", linkHref)
|
|
360
|
+
}
|
|
361
|
+
chunks.push(this.createChunk("](", "markup.link", linkHref))
|
|
362
|
+
chunks.push(this.createChunk(token.href, "markup.link.url", linkHref))
|
|
363
|
+
chunks.push(this.createChunk(")", "markup.link", linkHref))
|
|
364
|
+
}
|
|
365
|
+
break
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
case "image": {
|
|
369
|
+
const imageHref = { url: token.href }
|
|
370
|
+
if (this._conceal) {
|
|
371
|
+
chunks.push(this.createChunk(token.text || "image", "markup.link.label", imageHref))
|
|
372
|
+
} else {
|
|
373
|
+
chunks.push(this.createChunk(")
|
|
376
|
+
chunks.push(this.createChunk(token.href, "markup.link.url", imageHref))
|
|
377
|
+
chunks.push(this.createChunk(")", "markup.link", imageHref))
|
|
378
|
+
}
|
|
379
|
+
break
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
case "br":
|
|
383
|
+
chunks.push(this.createDefaultChunk("\n"))
|
|
384
|
+
break
|
|
385
|
+
|
|
386
|
+
default:
|
|
387
|
+
if ("tokens" in token && Array.isArray(token.tokens)) {
|
|
388
|
+
this.renderInlineContent(token.tokens, chunks)
|
|
389
|
+
} else if ("text" in token && typeof token.text === "string") {
|
|
390
|
+
chunks.push(this.createDefaultChunk(token.text))
|
|
391
|
+
}
|
|
392
|
+
break
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
private renderInlineTokenWithStyle(
|
|
397
|
+
token: MarkedToken,
|
|
398
|
+
chunks: TextChunk[],
|
|
399
|
+
styleGroup: string,
|
|
400
|
+
link?: { url: string },
|
|
401
|
+
): void {
|
|
402
|
+
switch (token.type) {
|
|
403
|
+
case "text":
|
|
404
|
+
chunks.push(this.createChunk(token.text, styleGroup, link))
|
|
405
|
+
break
|
|
406
|
+
|
|
407
|
+
case "escape":
|
|
408
|
+
chunks.push(this.createChunk(token.text, styleGroup, link))
|
|
409
|
+
break
|
|
410
|
+
|
|
411
|
+
case "codespan":
|
|
412
|
+
if (this._conceal) {
|
|
413
|
+
chunks.push(this.createChunk(token.text, "markup.raw", link))
|
|
414
|
+
} else {
|
|
415
|
+
chunks.push(this.createChunk("`", "markup.raw", link))
|
|
416
|
+
chunks.push(this.createChunk(token.text, "markup.raw", link))
|
|
417
|
+
chunks.push(this.createChunk("`", "markup.raw", link))
|
|
418
|
+
}
|
|
419
|
+
break
|
|
420
|
+
|
|
421
|
+
default:
|
|
422
|
+
this.renderInlineToken(token, chunks)
|
|
423
|
+
break
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
private createMarkdownCodeRenderable(content: string, id: string, marginBottom: number = 0): CodeRenderable {
|
|
428
|
+
return new CodeRenderable(this.ctx, {
|
|
429
|
+
id,
|
|
430
|
+
content,
|
|
431
|
+
filetype: "markdown",
|
|
432
|
+
syntaxStyle: this._syntaxStyle,
|
|
433
|
+
conceal: this._conceal,
|
|
434
|
+
drawUnstyledText: false,
|
|
435
|
+
streaming: true,
|
|
436
|
+
onChunks: this._linkifyMarkdownChunks,
|
|
437
|
+
treeSitterClient: this._treeSitterClient,
|
|
438
|
+
width: "100%",
|
|
439
|
+
marginBottom,
|
|
440
|
+
})
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
private createCodeRenderable(token: Tokens.Code, id: string, marginBottom: number = 0): Renderable {
|
|
444
|
+
return new CodeRenderable(this.ctx, {
|
|
445
|
+
id,
|
|
446
|
+
content: token.text,
|
|
447
|
+
filetype: token.lang || undefined,
|
|
448
|
+
syntaxStyle: this._syntaxStyle,
|
|
449
|
+
conceal: this._concealCode,
|
|
450
|
+
drawUnstyledText: !(this._streaming && this._concealCode),
|
|
451
|
+
streaming: this._streaming,
|
|
452
|
+
treeSitterClient: this._treeSitterClient,
|
|
453
|
+
width: "100%",
|
|
454
|
+
marginBottom,
|
|
455
|
+
})
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
private applyMarkdownCodeRenderable(renderable: CodeRenderable, content: string, marginBottom: number): void {
|
|
459
|
+
renderable.content = content
|
|
460
|
+
renderable.filetype = "markdown"
|
|
461
|
+
renderable.syntaxStyle = this._syntaxStyle
|
|
462
|
+
renderable.conceal = this._conceal
|
|
463
|
+
renderable.drawUnstyledText = false
|
|
464
|
+
renderable.streaming = true
|
|
465
|
+
renderable.marginBottom = marginBottom
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
private applyCodeBlockRenderable(renderable: CodeRenderable, token: Tokens.Code, marginBottom: number): void {
|
|
469
|
+
renderable.content = token.text
|
|
470
|
+
renderable.filetype = token.lang || undefined
|
|
471
|
+
renderable.syntaxStyle = this._syntaxStyle
|
|
472
|
+
renderable.conceal = this._concealCode
|
|
473
|
+
renderable.drawUnstyledText = !(this._streaming && this._concealCode)
|
|
474
|
+
renderable.streaming = this._streaming
|
|
475
|
+
renderable.marginBottom = marginBottom
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
private shouldRenderSeparately(token: MarkedToken): boolean {
|
|
479
|
+
return token.type === "code" || token.type === "table" || token.type === "blockquote"
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
private getInterBlockMargin(token: MarkedToken, hasNextToken: boolean): number {
|
|
483
|
+
if (!hasNextToken) return 0
|
|
484
|
+
return this.shouldRenderSeparately(token) ? 1 : 0
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
private createMarkdownBlockToken(raw: string): MarkedToken {
|
|
488
|
+
return {
|
|
489
|
+
type: "paragraph",
|
|
490
|
+
raw,
|
|
491
|
+
text: raw,
|
|
492
|
+
tokens: [],
|
|
493
|
+
} as MarkedToken
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
private normalizeMarkdownBlockRaw(raw: string): string {
|
|
497
|
+
return raw.replace(TRAILING_MARKDOWN_BLOCK_BREAKS_RE, "\n")
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
private buildRenderableTokens(tokens: MarkedToken[]): MarkedToken[] {
|
|
501
|
+
if (this._renderNode) {
|
|
502
|
+
return tokens.filter((token) => token.type !== "space")
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const renderTokens: MarkedToken[] = []
|
|
506
|
+
let markdownRaw = ""
|
|
507
|
+
|
|
508
|
+
const flushMarkdownRaw = (): void => {
|
|
509
|
+
if (markdownRaw.length === 0) return
|
|
510
|
+
const normalizedRaw = this.normalizeMarkdownBlockRaw(markdownRaw)
|
|
511
|
+
if (normalizedRaw.length > 0) {
|
|
512
|
+
renderTokens.push(this.createMarkdownBlockToken(normalizedRaw))
|
|
513
|
+
}
|
|
514
|
+
markdownRaw = ""
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
518
|
+
const token = tokens[i]
|
|
519
|
+
|
|
520
|
+
if (token.type === "space") {
|
|
521
|
+
if (markdownRaw.length === 0) {
|
|
522
|
+
continue
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
let nextIndex = i + 1
|
|
526
|
+
while (nextIndex < tokens.length && tokens[nextIndex].type === "space") {
|
|
527
|
+
nextIndex += 1
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const nextToken = tokens[nextIndex]
|
|
531
|
+
if (nextToken && !this.shouldRenderSeparately(nextToken)) {
|
|
532
|
+
markdownRaw += token.raw
|
|
533
|
+
}
|
|
534
|
+
continue
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
if (this.shouldRenderSeparately(token)) {
|
|
538
|
+
flushMarkdownRaw()
|
|
539
|
+
renderTokens.push(token)
|
|
540
|
+
continue
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
markdownRaw += token.raw
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
flushMarkdownRaw()
|
|
547
|
+
|
|
548
|
+
return renderTokens
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
private getTableRowsToRender(table: Tokens.Table): Tokens.TableCell[][] {
|
|
552
|
+
return table.rows
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
private hashString(value: string, seed: number): number {
|
|
556
|
+
let hash = seed >>> 0
|
|
557
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
558
|
+
hash ^= value.charCodeAt(i)
|
|
559
|
+
hash = Math.imul(hash, 16777619)
|
|
560
|
+
}
|
|
561
|
+
return hash >>> 0
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
private hashTableToken(token: MarkedToken, seed: number, depth: number = 0): number {
|
|
565
|
+
let hash = this.hashString(token.type, seed)
|
|
566
|
+
|
|
567
|
+
if ("raw" in token && typeof token.raw === "string") {
|
|
568
|
+
return this.hashString(token.raw, hash)
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if ("text" in token && typeof token.text === "string") {
|
|
572
|
+
hash = this.hashString(token.text, hash)
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (depth < 2 && "tokens" in token && Array.isArray(token.tokens)) {
|
|
576
|
+
for (const child of token.tokens) {
|
|
577
|
+
hash = this.hashTableToken(child as MarkedToken, hash, depth + 1)
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
return hash >>> 0
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
private getTableCellKey(cell: Tokens.TableCell | undefined, isHeader: boolean): number {
|
|
585
|
+
const seed = isHeader ? 2902232141 : 1371922141
|
|
586
|
+
if (!cell) {
|
|
587
|
+
return seed
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
if (typeof cell.text === "string") {
|
|
591
|
+
return this.hashString(cell.text, seed)
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (Array.isArray(cell.tokens) && cell.tokens.length > 0) {
|
|
595
|
+
let hash = seed ^ cell.tokens.length
|
|
596
|
+
for (const token of cell.tokens) {
|
|
597
|
+
hash = this.hashTableToken(token as MarkedToken, hash)
|
|
598
|
+
}
|
|
599
|
+
return hash >>> 0
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
return (seed ^ 2654435769) >>> 0
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
private createTableDataCellChunks(cell: Tokens.TableCell | undefined): TextChunk[] {
|
|
606
|
+
const chunks: TextChunk[] = []
|
|
607
|
+
if (cell) {
|
|
608
|
+
this.renderInlineContent(cell.tokens, chunks)
|
|
609
|
+
}
|
|
610
|
+
return chunks.length > 0 ? chunks : [this.createDefaultChunk(" ")]
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
private createTableHeaderCellChunks(cell: Tokens.TableCell): TextChunk[] {
|
|
614
|
+
const chunks: TextChunk[] = []
|
|
615
|
+
this.renderInlineContent(cell.tokens, chunks)
|
|
616
|
+
|
|
617
|
+
const baseChunks = chunks.length > 0 ? chunks : [this.createDefaultChunk(" ")]
|
|
618
|
+
const headingStyle = this.getStyle("markup.heading") || this.getStyle("default")
|
|
619
|
+
if (!headingStyle) {
|
|
620
|
+
return baseChunks
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
const headingAttributes = createTextAttributes({
|
|
624
|
+
bold: headingStyle.bold,
|
|
625
|
+
italic: headingStyle.italic,
|
|
626
|
+
underline: headingStyle.underline,
|
|
627
|
+
dim: headingStyle.dim,
|
|
628
|
+
})
|
|
629
|
+
|
|
630
|
+
return baseChunks.map((chunk) => ({
|
|
631
|
+
...chunk,
|
|
632
|
+
fg: headingStyle.fg ?? chunk.fg,
|
|
633
|
+
bg: headingStyle.bg ?? chunk.bg,
|
|
634
|
+
attributes: headingAttributes,
|
|
635
|
+
}))
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
private buildTableContentCache(
|
|
639
|
+
table: Tokens.Table,
|
|
640
|
+
previous?: TableContentCache,
|
|
641
|
+
forceRegenerate: boolean = false,
|
|
642
|
+
): { cache: TableContentCache | null; changed: boolean } {
|
|
643
|
+
const colCount = table.header.length
|
|
644
|
+
const rowsToRender = this.getTableRowsToRender(table)
|
|
645
|
+
if (colCount === 0 || rowsToRender.length === 0) {
|
|
646
|
+
return { cache: null, changed: previous !== undefined }
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
const content: TextTableContent = []
|
|
650
|
+
const cellKeys: Uint32Array[] = []
|
|
651
|
+
const totalRows = rowsToRender.length + 1
|
|
652
|
+
|
|
653
|
+
let changed = forceRegenerate || !previous
|
|
654
|
+
|
|
655
|
+
for (let rowIndex = 0; rowIndex < totalRows; rowIndex += 1) {
|
|
656
|
+
const rowContent: TextTableCellContent[] = []
|
|
657
|
+
const rowKeys = new Uint32Array(colCount)
|
|
658
|
+
|
|
659
|
+
for (let colIndex = 0; colIndex < colCount; colIndex += 1) {
|
|
660
|
+
const isHeader = rowIndex === 0
|
|
661
|
+
const cell = isHeader ? table.header[colIndex] : rowsToRender[rowIndex - 1]?.[colIndex]
|
|
662
|
+
const cellKey = this.getTableCellKey(cell, isHeader)
|
|
663
|
+
rowKeys[colIndex] = cellKey
|
|
664
|
+
|
|
665
|
+
const previousCellKey = previous?.cellKeys[rowIndex]?.[colIndex]
|
|
666
|
+
const previousCellContent = previous?.content[rowIndex]?.[colIndex]
|
|
667
|
+
|
|
668
|
+
if (!forceRegenerate && previousCellKey === cellKey && Array.isArray(previousCellContent)) {
|
|
669
|
+
rowContent.push(previousCellContent)
|
|
670
|
+
continue
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
changed = true
|
|
674
|
+
rowContent.push(
|
|
675
|
+
isHeader ? this.createTableHeaderCellChunks(table.header[colIndex]) : this.createTableDataCellChunks(cell),
|
|
676
|
+
)
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
content.push(rowContent)
|
|
680
|
+
cellKeys.push(rowKeys)
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
if (previous && !changed) {
|
|
684
|
+
if (previous.content.length !== content.length) {
|
|
685
|
+
changed = true
|
|
686
|
+
} else {
|
|
687
|
+
for (let rowIndex = 0; rowIndex < content.length; rowIndex += 1) {
|
|
688
|
+
if ((previous.content[rowIndex]?.length ?? 0) !== content[rowIndex].length) {
|
|
689
|
+
changed = true
|
|
690
|
+
break
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
return {
|
|
697
|
+
cache: {
|
|
698
|
+
content,
|
|
699
|
+
cellKeys,
|
|
700
|
+
},
|
|
701
|
+
changed,
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
private resolveTableRenderableOptions(): ResolvedTableRenderableOptions {
|
|
706
|
+
const borders = this._tableOptions?.borders ?? true
|
|
707
|
+
|
|
708
|
+
return {
|
|
709
|
+
columnWidthMode: this._tableOptions?.widthMode ?? "full",
|
|
710
|
+
columnFitter: this._tableOptions?.columnFitter ?? "proportional",
|
|
711
|
+
wrapMode: this._tableOptions?.wrapMode ?? "word",
|
|
712
|
+
cellPadding: this._tableOptions?.cellPadding ?? 0,
|
|
713
|
+
border: borders,
|
|
714
|
+
outerBorder: this._tableOptions?.outerBorder ?? borders,
|
|
715
|
+
showBorders: borders,
|
|
716
|
+
borderStyle: this._tableOptions?.borderStyle ?? "single",
|
|
717
|
+
borderColor: this._tableOptions?.borderColor ?? this.getStyle("conceal")?.fg ?? "#888888",
|
|
718
|
+
selectable: this._tableOptions?.selectable ?? true,
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
private applyTableRenderableOptions(
|
|
723
|
+
tableRenderable: TextTableRenderable,
|
|
724
|
+
options: ResolvedTableRenderableOptions,
|
|
725
|
+
): void {
|
|
726
|
+
tableRenderable.columnWidthMode = options.columnWidthMode
|
|
727
|
+
tableRenderable.columnFitter = options.columnFitter
|
|
728
|
+
tableRenderable.wrapMode = options.wrapMode
|
|
729
|
+
tableRenderable.cellPadding = options.cellPadding
|
|
730
|
+
tableRenderable.border = options.border
|
|
731
|
+
tableRenderable.outerBorder = options.outerBorder
|
|
732
|
+
tableRenderable.showBorders = options.showBorders
|
|
733
|
+
tableRenderable.borderStyle = options.borderStyle
|
|
734
|
+
tableRenderable.borderColor = options.borderColor
|
|
735
|
+
tableRenderable.selectable = options.selectable
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
private applyTableOptionsToBlocks(): void {
|
|
739
|
+
const options = this.resolveTableRenderableOptions()
|
|
740
|
+
let updated = false
|
|
741
|
+
|
|
742
|
+
for (const state of this._blockStates) {
|
|
743
|
+
if (state.renderable instanceof TextTableRenderable) {
|
|
744
|
+
this.applyTableRenderableOptions(state.renderable, options)
|
|
745
|
+
updated = true
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
if (updated) {
|
|
750
|
+
this.requestRender()
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
private createTextTableRenderable(
|
|
755
|
+
content: TextTableContent,
|
|
756
|
+
id: string,
|
|
757
|
+
marginBottom: number = 0,
|
|
758
|
+
): TextTableRenderable {
|
|
759
|
+
const options = this.resolveTableRenderableOptions()
|
|
760
|
+
return new TextTableRenderable(this.ctx, {
|
|
761
|
+
id,
|
|
762
|
+
content,
|
|
763
|
+
width: "100%",
|
|
764
|
+
marginBottom,
|
|
765
|
+
columnWidthMode: options.columnWidthMode,
|
|
766
|
+
columnFitter: options.columnFitter,
|
|
767
|
+
wrapMode: options.wrapMode,
|
|
768
|
+
cellPadding: options.cellPadding,
|
|
769
|
+
border: options.border,
|
|
770
|
+
outerBorder: options.outerBorder,
|
|
771
|
+
showBorders: options.showBorders,
|
|
772
|
+
borderStyle: options.borderStyle,
|
|
773
|
+
borderColor: options.borderColor,
|
|
774
|
+
selectable: options.selectable,
|
|
775
|
+
})
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
private createTableBlock(
|
|
779
|
+
table: Tokens.Table,
|
|
780
|
+
id: string,
|
|
781
|
+
marginBottom: number = 0,
|
|
782
|
+
previousCache?: TableContentCache,
|
|
783
|
+
forceRegenerate: boolean = false,
|
|
784
|
+
): { renderable: Renderable; tableContentCache?: TableContentCache } {
|
|
785
|
+
const { cache } = this.buildTableContentCache(table, previousCache, forceRegenerate)
|
|
786
|
+
|
|
787
|
+
if (!cache) {
|
|
788
|
+
return {
|
|
789
|
+
renderable: this.createMarkdownCodeRenderable(table.raw, id, marginBottom),
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
return {
|
|
794
|
+
renderable: this.createTextTableRenderable(cache.content, id, marginBottom),
|
|
795
|
+
tableContentCache: cache,
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
private createDefaultRenderable(token: MarkedToken, index: number, hasNextToken: boolean = false): Renderable | null {
|
|
800
|
+
const id = `${this.id}-block-${index}`
|
|
801
|
+
const marginBottom = this.getInterBlockMargin(token, hasNextToken)
|
|
802
|
+
|
|
803
|
+
if (token.type === "code") {
|
|
804
|
+
return this.createCodeRenderable(token, id, marginBottom)
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
if (token.type === "table") {
|
|
808
|
+
return this.createTableBlock(token, id, marginBottom).renderable
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
if (token.type === "space") {
|
|
812
|
+
return null
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
if (!token.raw) {
|
|
816
|
+
return null
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
return this.createMarkdownCodeRenderable(token.raw, id, marginBottom)
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
private updateBlockRenderable(state: BlockState, token: MarkedToken, index: number, hasNextToken: boolean): void {
|
|
823
|
+
const marginBottom = this.getInterBlockMargin(token, hasNextToken)
|
|
824
|
+
|
|
825
|
+
if (token.type === "code") {
|
|
826
|
+
this.applyCodeBlockRenderable(state.renderable as CodeRenderable, token as Tokens.Code, marginBottom)
|
|
827
|
+
return
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
if (token.type === "table") {
|
|
831
|
+
const tableToken = token as Tokens.Table
|
|
832
|
+
const { cache, changed } = this.buildTableContentCache(tableToken, state.tableContentCache)
|
|
833
|
+
|
|
834
|
+
if (!cache) {
|
|
835
|
+
if (state.renderable instanceof CodeRenderable) {
|
|
836
|
+
this.applyMarkdownCodeRenderable(state.renderable, tableToken.raw, marginBottom)
|
|
837
|
+
state.tableContentCache = undefined
|
|
838
|
+
return
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
state.renderable.destroyRecursively()
|
|
842
|
+
const fallbackRenderable = this.createMarkdownCodeRenderable(
|
|
843
|
+
tableToken.raw,
|
|
844
|
+
`${this.id}-block-${index}`,
|
|
845
|
+
marginBottom,
|
|
846
|
+
)
|
|
847
|
+
this.add(fallbackRenderable)
|
|
848
|
+
state.renderable = fallbackRenderable
|
|
849
|
+
state.tableContentCache = undefined
|
|
850
|
+
return
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
if (state.renderable instanceof TextTableRenderable) {
|
|
854
|
+
if (changed) {
|
|
855
|
+
state.renderable.content = cache.content
|
|
856
|
+
}
|
|
857
|
+
this.applyTableRenderableOptions(state.renderable, this.resolveTableRenderableOptions())
|
|
858
|
+
state.renderable.marginBottom = marginBottom
|
|
859
|
+
state.tableContentCache = cache
|
|
860
|
+
return
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
state.renderable.destroyRecursively()
|
|
864
|
+
const tableRenderable = this.createTextTableRenderable(cache.content, `${this.id}-block-${index}`, marginBottom)
|
|
865
|
+
this.add(tableRenderable)
|
|
866
|
+
state.renderable = tableRenderable
|
|
867
|
+
state.tableContentCache = cache
|
|
868
|
+
return
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
if (state.renderable instanceof CodeRenderable) {
|
|
872
|
+
this.applyMarkdownCodeRenderable(state.renderable, token.raw, marginBottom)
|
|
873
|
+
return
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
state.renderable.destroyRecursively()
|
|
877
|
+
const markdownRenderable = this.createMarkdownCodeRenderable(token.raw, `${this.id}-block-${index}`, marginBottom)
|
|
878
|
+
this.add(markdownRenderable)
|
|
879
|
+
state.renderable = markdownRenderable
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
private updateBlocks(forceTableRefresh: boolean = false): void {
|
|
883
|
+
if (this.isDestroyed) return
|
|
884
|
+
if (!this._content) {
|
|
885
|
+
this.clearBlockStates()
|
|
886
|
+
this._parseState = null
|
|
887
|
+
return
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
const trailingUnstable = this._streaming ? 2 : 0
|
|
891
|
+
this._parseState = parseMarkdownIncremental(this._content, this._parseState, trailingUnstable)
|
|
892
|
+
|
|
893
|
+
const tokens = this._parseState.tokens
|
|
894
|
+
|
|
895
|
+
// Parse failure fallback
|
|
896
|
+
if (tokens.length === 0 && this._content.length > 0) {
|
|
897
|
+
this.clearBlockStates()
|
|
898
|
+
const fallback = this.createMarkdownCodeRenderable(this._content, `${this.id}-fallback`)
|
|
899
|
+
this.add(fallback)
|
|
900
|
+
this._blockStates = [
|
|
901
|
+
{
|
|
902
|
+
token: { type: "text", raw: this._content, text: this._content } as MarkedToken,
|
|
903
|
+
tokenRaw: this._content,
|
|
904
|
+
renderable: fallback,
|
|
905
|
+
},
|
|
906
|
+
]
|
|
907
|
+
return
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
const blockTokens = this.buildRenderableTokens(tokens)
|
|
911
|
+
const lastBlockIndex = blockTokens.length - 1
|
|
912
|
+
|
|
913
|
+
let blockIndex = 0
|
|
914
|
+
for (let i = 0; i < blockTokens.length; i++) {
|
|
915
|
+
const token = blockTokens[i]
|
|
916
|
+
const hasNextToken = i < lastBlockIndex
|
|
917
|
+
const existing = this._blockStates[blockIndex]
|
|
918
|
+
|
|
919
|
+
const shouldForceRefresh = forceTableRefresh
|
|
920
|
+
|
|
921
|
+
// Same token object reference means unchanged
|
|
922
|
+
if (existing && existing.token === token) {
|
|
923
|
+
if (shouldForceRefresh) {
|
|
924
|
+
this.updateBlockRenderable(existing, token, blockIndex, hasNextToken)
|
|
925
|
+
existing.tokenRaw = token.raw
|
|
926
|
+
}
|
|
927
|
+
blockIndex++
|
|
928
|
+
continue
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// Same content, update reference
|
|
932
|
+
if (existing && existing.tokenRaw === token.raw && existing.token.type === token.type) {
|
|
933
|
+
existing.token = token
|
|
934
|
+
if (shouldForceRefresh) {
|
|
935
|
+
this.updateBlockRenderable(existing, token, blockIndex, hasNextToken)
|
|
936
|
+
existing.tokenRaw = token.raw
|
|
937
|
+
}
|
|
938
|
+
blockIndex++
|
|
939
|
+
continue
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// Same type, different content - update in place
|
|
943
|
+
if (existing && existing.token.type === token.type) {
|
|
944
|
+
this.updateBlockRenderable(existing, token, blockIndex, hasNextToken)
|
|
945
|
+
existing.token = token
|
|
946
|
+
existing.tokenRaw = token.raw
|
|
947
|
+
blockIndex++
|
|
948
|
+
continue
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// Different type or new block
|
|
952
|
+
if (existing) {
|
|
953
|
+
existing.renderable.destroyRecursively()
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
let renderable: Renderable | undefined
|
|
957
|
+
let tableContentCache: TableContentCache | undefined
|
|
958
|
+
|
|
959
|
+
if (this._renderNode) {
|
|
960
|
+
const context: RenderNodeContext = {
|
|
961
|
+
syntaxStyle: this._syntaxStyle,
|
|
962
|
+
conceal: this._conceal,
|
|
963
|
+
concealCode: this._concealCode,
|
|
964
|
+
treeSitterClient: this._treeSitterClient,
|
|
965
|
+
defaultRender: () => this.createDefaultRenderable(token, blockIndex, hasNextToken),
|
|
966
|
+
}
|
|
967
|
+
const custom = this._renderNode(token, context)
|
|
968
|
+
if (custom) {
|
|
969
|
+
renderable = custom
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
if (!renderable) {
|
|
974
|
+
if (token.type === "table") {
|
|
975
|
+
const tableBlock = this.createTableBlock(
|
|
976
|
+
token,
|
|
977
|
+
`${this.id}-block-${blockIndex}`,
|
|
978
|
+
this.getInterBlockMargin(token, hasNextToken),
|
|
979
|
+
)
|
|
980
|
+
renderable = tableBlock.renderable
|
|
981
|
+
tableContentCache = tableBlock.tableContentCache
|
|
982
|
+
} else {
|
|
983
|
+
renderable = this.createDefaultRenderable(token, blockIndex, hasNextToken) ?? undefined
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
if (token.type === "table" && !tableContentCache && renderable instanceof TextTableRenderable) {
|
|
988
|
+
const { cache } = this.buildTableContentCache(token as Tokens.Table)
|
|
989
|
+
tableContentCache = cache ?? undefined
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
if (renderable) {
|
|
993
|
+
this.add(renderable)
|
|
994
|
+
this._blockStates[blockIndex] = {
|
|
995
|
+
token,
|
|
996
|
+
tokenRaw: token.raw,
|
|
997
|
+
renderable,
|
|
998
|
+
tableContentCache,
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
blockIndex++
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
while (this._blockStates.length > blockIndex) {
|
|
1005
|
+
const removed = this._blockStates.pop()!
|
|
1006
|
+
removed.renderable.destroyRecursively()
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
private clearBlockStates(): void {
|
|
1011
|
+
for (const state of this._blockStates) {
|
|
1012
|
+
state.renderable.destroyRecursively()
|
|
1013
|
+
}
|
|
1014
|
+
this._blockStates = []
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* Re-render existing blocks without rebuilding the parse state or block structure.
|
|
1019
|
+
* Used when only style/conceal changes - much faster than full rebuild.
|
|
1020
|
+
*/
|
|
1021
|
+
private rerenderBlocks(): void {
|
|
1022
|
+
for (let i = 0; i < this._blockStates.length; i++) {
|
|
1023
|
+
const state = this._blockStates[i]
|
|
1024
|
+
const hasNextToken = i < this._blockStates.length - 1
|
|
1025
|
+
const marginBottom = this.getInterBlockMargin(state.token, hasNextToken)
|
|
1026
|
+
|
|
1027
|
+
if (state.token.type === "code") {
|
|
1028
|
+
this.applyCodeBlockRenderable(state.renderable as CodeRenderable, state.token as Tokens.Code, marginBottom)
|
|
1029
|
+
continue
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
if (state.token.type === "table") {
|
|
1033
|
+
const tableToken = state.token as Tokens.Table
|
|
1034
|
+
const { cache } = this.buildTableContentCache(tableToken, state.tableContentCache, true)
|
|
1035
|
+
|
|
1036
|
+
if (!cache) {
|
|
1037
|
+
if (state.renderable instanceof CodeRenderable) {
|
|
1038
|
+
this.applyMarkdownCodeRenderable(state.renderable, tableToken.raw, marginBottom)
|
|
1039
|
+
} else {
|
|
1040
|
+
state.renderable.destroyRecursively()
|
|
1041
|
+
const fallbackRenderable = this.createMarkdownCodeRenderable(
|
|
1042
|
+
tableToken.raw,
|
|
1043
|
+
`${this.id}-block-${i}`,
|
|
1044
|
+
marginBottom,
|
|
1045
|
+
)
|
|
1046
|
+
this.add(fallbackRenderable)
|
|
1047
|
+
state.renderable = fallbackRenderable
|
|
1048
|
+
}
|
|
1049
|
+
state.tableContentCache = undefined
|
|
1050
|
+
continue
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
if (state.renderable instanceof TextTableRenderable) {
|
|
1054
|
+
state.renderable.content = cache.content
|
|
1055
|
+
this.applyTableRenderableOptions(state.renderable, this.resolveTableRenderableOptions())
|
|
1056
|
+
state.renderable.marginBottom = marginBottom
|
|
1057
|
+
state.tableContentCache = cache
|
|
1058
|
+
continue
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
state.renderable.destroyRecursively()
|
|
1062
|
+
const tableRenderable = this.createTextTableRenderable(cache.content, `${this.id}-block-${i}`, marginBottom)
|
|
1063
|
+
this.add(tableRenderable)
|
|
1064
|
+
state.renderable = tableRenderable
|
|
1065
|
+
state.tableContentCache = cache
|
|
1066
|
+
continue
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
if (state.renderable instanceof CodeRenderable) {
|
|
1070
|
+
this.applyMarkdownCodeRenderable(state.renderable, state.token.raw, marginBottom)
|
|
1071
|
+
continue
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
state.renderable.destroyRecursively()
|
|
1075
|
+
const markdownRenderable = this.createMarkdownCodeRenderable(
|
|
1076
|
+
state.token.raw,
|
|
1077
|
+
`${this.id}-block-${i}`,
|
|
1078
|
+
marginBottom,
|
|
1079
|
+
)
|
|
1080
|
+
this.add(markdownRenderable)
|
|
1081
|
+
state.renderable = markdownRenderable
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
public clearCache(): void {
|
|
1086
|
+
this._parseState = null
|
|
1087
|
+
this.clearBlockStates()
|
|
1088
|
+
this.updateBlocks()
|
|
1089
|
+
this.requestRender()
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
public refreshStyles(): void {
|
|
1093
|
+
this._styleDirty = false
|
|
1094
|
+
this.rerenderBlocks()
|
|
1095
|
+
this.requestRender()
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
protected renderSelf(buffer: OptimizedBuffer, deltaTime: number): void {
|
|
1099
|
+
// Check if style/conceal changed - re-render blocks before rendering
|
|
1100
|
+
if (this._styleDirty) {
|
|
1101
|
+
this._styleDirty = false
|
|
1102
|
+
this.rerenderBlocks()
|
|
1103
|
+
}
|
|
1104
|
+
super.renderSelf(buffer, deltaTime)
|
|
1105
|
+
}
|
|
1106
|
+
}
|