terminal-pilot 0.0.30 → 0.0.32
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/dist/cli.js +1599 -497
- package/dist/cli.js.map +4 -4
- package/dist/commands/close-session.js +489 -6
- package/dist/commands/close-session.js.map +4 -4
- package/dist/commands/create-session.js +489 -6
- package/dist/commands/create-session.js.map +4 -4
- package/dist/commands/fill.js +489 -6
- package/dist/commands/fill.js.map +4 -4
- package/dist/commands/get-session.js +489 -6
- package/dist/commands/get-session.js.map +4 -4
- package/dist/commands/index.js +630 -44
- package/dist/commands/index.js.map +4 -4
- package/dist/commands/install.js +626 -40
- package/dist/commands/install.js.map +4 -4
- package/dist/commands/installer.js +68 -17
- package/dist/commands/installer.js.map +4 -4
- package/dist/commands/list-sessions.js +489 -6
- package/dist/commands/list-sessions.js.map +4 -4
- package/dist/commands/press-key.js +489 -6
- package/dist/commands/press-key.js.map +4 -4
- package/dist/commands/read-history.js +489 -6
- package/dist/commands/read-history.js.map +4 -4
- package/dist/commands/read-screen.js +489 -6
- package/dist/commands/read-screen.js.map +4 -4
- package/dist/commands/resize.js +489 -6
- package/dist/commands/resize.js.map +4 -4
- package/dist/commands/runtime.js.map +1 -1
- package/dist/commands/screenshot.js +489 -6
- package/dist/commands/screenshot.js.map +4 -4
- package/dist/commands/send-signal.js +489 -6
- package/dist/commands/send-signal.js.map +4 -4
- package/dist/commands/type.js +489 -6
- package/dist/commands/type.js.map +4 -4
- package/dist/commands/uninstall.js +554 -20
- package/dist/commands/uninstall.js.map +4 -4
- package/dist/commands/wait-for-exit.js +489 -6
- package/dist/commands/wait-for-exit.js.map +4 -4
- package/dist/commands/wait-for.js +489 -6
- package/dist/commands/wait-for.js.map +4 -4
- package/dist/testing/cli-repl.js +1599 -497
- package/dist/testing/cli-repl.js.map +4 -4
- package/dist/testing/qa-cli.js +1609 -507
- package/dist/testing/qa-cli.js.map +4 -4
- package/node_modules/@poe-code/agent-defs/README.md +35 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/claude-code.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/claude-code.js +21 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/claude-desktop.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/claude-desktop.js +18 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/codex.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/codex.js +25 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/cursor.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/cursor.js +15 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/gemini-cli.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/gemini-cli.js +16 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/goose.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/goose.js +16 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/index.d.ts +9 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/index.js +9 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/kimi.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/kimi.js +16 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/opencode.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/opencode.js +20 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/poe-agent.d.ts +2 -0
- package/node_modules/@poe-code/agent-defs/dist/agents/poe-agent.js +14 -0
- package/node_modules/@poe-code/agent-defs/dist/index.d.ts +5 -0
- package/node_modules/@poe-code/agent-defs/dist/index.js +3 -0
- package/node_modules/@poe-code/agent-defs/dist/registry.d.ts +3 -0
- package/node_modules/@poe-code/agent-defs/dist/registry.js +45 -0
- package/node_modules/@poe-code/agent-defs/dist/specifier.d.ts +7 -0
- package/node_modules/@poe-code/agent-defs/dist/specifier.js +40 -0
- package/node_modules/@poe-code/agent-defs/dist/types.d.ts +28 -0
- package/node_modules/@poe-code/agent-defs/dist/types.js +1 -0
- package/node_modules/@poe-code/agent-defs/package.json +20 -0
- package/node_modules/@poe-code/agent-skill-config/dist/apply.js +2 -1
- package/node_modules/@poe-code/agent-skill-config/dist/bridge-active-skills.d.ts +1 -0
- package/node_modules/@poe-code/agent-skill-config/dist/bridge-active-skills.js +37 -18
- package/node_modules/@poe-code/agent-skill-config/dist/resolve-skill-reference.js +8 -4
- package/node_modules/@poe-code/agent-skill-config/package.json +1 -5
- package/node_modules/@poe-code/config-mutations/README.md +55 -0
- package/node_modules/@poe-code/config-mutations/dist/error-codes.d.ts +1 -0
- package/node_modules/@poe-code/config-mutations/dist/error-codes.js +6 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/apply-mutation.d.ts +6 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/apply-mutation.js +829 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.d.ts +17 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.js +64 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/run-mutations.d.ts +7 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/run-mutations.js +39 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/index.d.ts +13 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/index.js +49 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/json.d.ts +32 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/json.js +171 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/object.d.ts +4 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/object.js +27 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/toml.d.ts +2 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/toml.js +75 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/yaml.d.ts +2 -0
- package/node_modules/@poe-code/config-mutations/dist/formats/yaml.js +76 -0
- package/node_modules/@poe-code/config-mutations/dist/fs-utils.d.ts +18 -0
- package/node_modules/@poe-code/config-mutations/dist/fs-utils.js +43 -0
- package/node_modules/@poe-code/config-mutations/dist/index.d.ts +8 -0
- package/node_modules/@poe-code/config-mutations/dist/index.js +8 -0
- package/node_modules/@poe-code/config-mutations/dist/mutations/config-mutation.d.ts +47 -0
- package/node_modules/@poe-code/config-mutations/dist/mutations/config-mutation.js +34 -0
- package/node_modules/@poe-code/config-mutations/dist/mutations/file-mutation.d.ts +62 -0
- package/node_modules/@poe-code/config-mutations/dist/mutations/file-mutation.js +55 -0
- package/node_modules/@poe-code/config-mutations/dist/mutations/template-mutation.d.ts +40 -0
- package/node_modules/@poe-code/config-mutations/dist/mutations/template-mutation.js +32 -0
- package/node_modules/@poe-code/config-mutations/dist/template/render.d.ts +6 -0
- package/node_modules/@poe-code/config-mutations/dist/template/render.js +8 -0
- package/node_modules/@poe-code/config-mutations/dist/testing/format-utils.d.ts +7 -0
- package/node_modules/@poe-code/config-mutations/dist/testing/format-utils.js +21 -0
- package/node_modules/@poe-code/config-mutations/dist/testing/index.d.ts +3 -0
- package/node_modules/@poe-code/config-mutations/dist/testing/index.js +2 -0
- package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.d.ts +25 -0
- package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.js +194 -0
- package/node_modules/@poe-code/config-mutations/dist/types.d.ts +168 -0
- package/node_modules/@poe-code/config-mutations/dist/types.js +6 -0
- package/node_modules/@poe-code/config-mutations/package.json +29 -0
- package/node_modules/@poe-code/frontmatter/README.md +35 -0
- package/node_modules/@poe-code/frontmatter/dist/fences.d.ts +25 -0
- package/node_modules/@poe-code/frontmatter/dist/fences.js +100 -0
- package/node_modules/@poe-code/frontmatter/dist/index.d.ts +3 -0
- package/node_modules/@poe-code/frontmatter/dist/index.js +3 -0
- package/node_modules/@poe-code/frontmatter/dist/parse.d.ts +20 -0
- package/node_modules/@poe-code/frontmatter/dist/parse.js +209 -0
- package/node_modules/@poe-code/frontmatter/dist/stringify.d.ts +1 -0
- package/node_modules/@poe-code/frontmatter/dist/stringify.js +48 -0
- package/node_modules/@poe-code/frontmatter/package.json +25 -0
- package/node_modules/toolcraft-design/README.md +160 -0
- package/node_modules/toolcraft-design/dist/acp/components.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/acp/components.js +137 -0
- package/node_modules/toolcraft-design/dist/acp/index.d.ts +3 -0
- package/node_modules/toolcraft-design/dist/acp/index.js +2 -0
- package/node_modules/toolcraft-design/dist/acp/writer.d.ts +13 -0
- package/node_modules/toolcraft-design/dist/acp/writer.js +21 -0
- package/node_modules/toolcraft-design/dist/components/browser.d.ts +15 -0
- package/node_modules/toolcraft-design/dist/components/browser.js +31 -0
- package/node_modules/toolcraft-design/dist/components/catalog.d.ts +26 -0
- package/node_modules/toolcraft-design/dist/components/catalog.js +95 -0
- package/node_modules/toolcraft-design/dist/components/color.d.ts +31 -0
- package/node_modules/toolcraft-design/dist/components/color.js +102 -0
- package/node_modules/toolcraft-design/dist/components/command-errors.d.ts +16 -0
- package/node_modules/toolcraft-design/dist/components/command-errors.js +23 -0
- package/node_modules/toolcraft-design/dist/components/detail-card.d.ts +22 -0
- package/node_modules/toolcraft-design/dist/components/detail-card.js +45 -0
- package/node_modules/toolcraft-design/dist/components/help-formatter-plain.d.ts +5 -0
- package/node_modules/toolcraft-design/dist/components/help-formatter-plain.js +132 -0
- package/node_modules/toolcraft-design/dist/components/help-formatter.d.ts +33 -0
- package/node_modules/toolcraft-design/dist/components/help-formatter.js +213 -0
- package/node_modules/toolcraft-design/dist/components/index.d.ts +16 -0
- package/node_modules/toolcraft-design/dist/components/index.js +10 -0
- package/node_modules/toolcraft-design/dist/components/logger.d.ts +11 -0
- package/node_modules/toolcraft-design/dist/components/logger.js +60 -0
- package/node_modules/toolcraft-design/dist/components/symbols.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/components/symbols.js +71 -0
- package/node_modules/toolcraft-design/dist/components/table.d.ts +15 -0
- package/node_modules/toolcraft-design/dist/components/table.js +302 -0
- package/node_modules/toolcraft-design/dist/components/template.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/components/template.js +437 -0
- package/node_modules/toolcraft-design/dist/components/text.d.ts +16 -0
- package/node_modules/toolcraft-design/dist/components/text.js +145 -0
- package/node_modules/toolcraft-design/dist/dashboard/ansi.d.ts +18 -0
- package/node_modules/toolcraft-design/dist/dashboard/ansi.js +343 -0
- package/node_modules/toolcraft-design/dist/dashboard/buffer.d.ts +25 -0
- package/node_modules/toolcraft-design/dist/dashboard/buffer.js +219 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/border.d.ts +9 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/border.js +123 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/footer.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/footer.js +56 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/output-pane.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/output-pane.js +268 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/stats-pane.d.ts +7 -0
- package/node_modules/toolcraft-design/dist/dashboard/components/stats-pane.js +107 -0
- package/node_modules/toolcraft-design/dist/dashboard/dashboard.d.ts +20 -0
- package/node_modules/toolcraft-design/dist/dashboard/dashboard.js +167 -0
- package/node_modules/toolcraft-design/dist/dashboard/demo.d.ts +13 -0
- package/node_modules/toolcraft-design/dist/dashboard/demo.js +145 -0
- package/node_modules/toolcraft-design/dist/dashboard/index.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/dashboard/index.js +4 -0
- package/node_modules/toolcraft-design/dist/dashboard/keymap.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/dashboard/keymap.js +233 -0
- package/node_modules/toolcraft-design/dist/dashboard/layout.d.ts +25 -0
- package/node_modules/toolcraft-design/dist/dashboard/layout.js +79 -0
- package/node_modules/toolcraft-design/dist/dashboard/should-use-dashboard.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/dashboard/should-use-dashboard.js +7 -0
- package/node_modules/toolcraft-design/dist/dashboard/snapshot.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/dashboard/snapshot.js +68 -0
- package/node_modules/toolcraft-design/dist/dashboard/store.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/dashboard/store.js +51 -0
- package/node_modules/toolcraft-design/dist/dashboard/terminal-width.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/dashboard/terminal-width.js +71 -0
- package/node_modules/toolcraft-design/dist/dashboard/terminal.d.ts +37 -0
- package/node_modules/toolcraft-design/dist/dashboard/terminal.js +264 -0
- package/node_modules/toolcraft-design/dist/dashboard/types.d.ts +38 -0
- package/node_modules/toolcraft-design/dist/dashboard/types.js +1 -0
- package/node_modules/toolcraft-design/dist/explorer/actions.d.ts +16 -0
- package/node_modules/toolcraft-design/dist/explorer/actions.js +39 -0
- package/node_modules/toolcraft-design/dist/explorer/demo.d.ts +13 -0
- package/node_modules/toolcraft-design/dist/explorer/demo.js +297 -0
- package/node_modules/toolcraft-design/dist/explorer/events.d.ts +67 -0
- package/node_modules/toolcraft-design/dist/explorer/events.js +1 -0
- package/node_modules/toolcraft-design/dist/explorer/filter.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/explorer/filter.js +95 -0
- package/node_modules/toolcraft-design/dist/explorer/index.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/explorer/index.js +8 -0
- package/node_modules/toolcraft-design/dist/explorer/jobs.d.ts +7 -0
- package/node_modules/toolcraft-design/dist/explorer/jobs.js +59 -0
- package/node_modules/toolcraft-design/dist/explorer/keymap.d.ts +21 -0
- package/node_modules/toolcraft-design/dist/explorer/keymap.js +376 -0
- package/node_modules/toolcraft-design/dist/explorer/layout.d.ts +20 -0
- package/node_modules/toolcraft-design/dist/explorer/layout.js +73 -0
- package/node_modules/toolcraft-design/dist/explorer/reducer.d.ts +9 -0
- package/node_modules/toolcraft-design/dist/explorer/reducer.js +782 -0
- package/node_modules/toolcraft-design/dist/explorer/render/detail.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/explorer/render/detail.js +97 -0
- package/node_modules/toolcraft-design/dist/explorer/render/footer.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/explorer/render/footer.js +73 -0
- package/node_modules/toolcraft-design/dist/explorer/render/header.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/explorer/render/header.js +49 -0
- package/node_modules/toolcraft-design/dist/explorer/render/index.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/explorer/render/index.js +53 -0
- package/node_modules/toolcraft-design/dist/explorer/render/list.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/explorer/render/list.js +116 -0
- package/node_modules/toolcraft-design/dist/explorer/render/modal.d.ts +3 -0
- package/node_modules/toolcraft-design/dist/explorer/render/modal.js +87 -0
- package/node_modules/toolcraft-design/dist/explorer/render/test-fixtures.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/explorer/render/test-fixtures.js +156 -0
- package/node_modules/toolcraft-design/dist/explorer/render/text.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/explorer/render/text.js +81 -0
- package/node_modules/toolcraft-design/dist/explorer/runtime.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/explorer/runtime.js +340 -0
- package/node_modules/toolcraft-design/dist/explorer/runtime.test-helpers.d.ts +50 -0
- package/node_modules/toolcraft-design/dist/explorer/runtime.test-helpers.js +101 -0
- package/node_modules/toolcraft-design/dist/explorer/state.d.ts +137 -0
- package/node_modules/toolcraft-design/dist/explorer/state.js +86 -0
- package/node_modules/toolcraft-design/dist/explorer/theme.d.ts +27 -0
- package/node_modules/toolcraft-design/dist/explorer/theme.js +29 -0
- package/node_modules/toolcraft-design/dist/index.d.ts +50 -0
- package/node_modules/toolcraft-design/dist/index.js +43 -0
- package/node_modules/toolcraft-design/dist/internal/color-support.d.ts +9 -0
- package/node_modules/toolcraft-design/dist/internal/color-support.js +12 -0
- package/node_modules/toolcraft-design/dist/internal/output-format.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/internal/output-format.js +22 -0
- package/node_modules/toolcraft-design/dist/internal/strip-ansi.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/internal/strip-ansi.js +50 -0
- package/node_modules/toolcraft-design/dist/internal/theme-detect.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/internal/theme-detect.js +71 -0
- package/node_modules/toolcraft-design/dist/internal/theme-state.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/internal/theme-state.js +35 -0
- package/node_modules/toolcraft-design/dist/prompts/index.d.ts +91 -0
- package/node_modules/toolcraft-design/dist/prompts/index.js +137 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/cancel-symbol.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/cancel-symbol.js +4 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/confirm.d.ts +9 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/confirm.js +47 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/core.d.ts +55 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/core.js +274 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/glyphs.d.ts +20 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/glyphs.js +53 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/index.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/index.js +6 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/keys.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/keys.js +28 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/multiselect.d.ts +13 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/multiselect.js +131 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/pagination.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/pagination.js +52 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/password.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/password.js +55 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/select.d.ts +18 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/select.js +89 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/test-helpers.d.ts +21 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/test-helpers.js +32 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/text.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/text.js +60 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/wrap.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/prompts/interactive/wrap.js +18 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/cancel.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/cancel.js +9 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/intro.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/intro.js +16 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/log.d.ts +18 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/log.js +104 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/note.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/note.js +39 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/outro.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/outro.js +16 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/spinner.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/prompts/primitives/spinner.js +74 -0
- package/node_modules/toolcraft-design/dist/prompts/theme.d.ts +11 -0
- package/node_modules/toolcraft-design/dist/prompts/theme.js +15 -0
- package/node_modules/toolcraft-design/dist/static/index.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/static/index.js +2 -0
- package/node_modules/toolcraft-design/dist/static/menu.d.ts +11 -0
- package/node_modules/toolcraft-design/dist/static/menu.js +42 -0
- package/node_modules/toolcraft-design/dist/static/spinner.d.ts +14 -0
- package/node_modules/toolcraft-design/dist/static/spinner.js +52 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/ast.d.ts +92 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/ast.js +1 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/demo-content.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/demo-content.js +139 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/index.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/index.js +8 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/block.d.ts +7 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/block.js +1495 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/frontmatter.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/frontmatter.js +36 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/inline.d.ts +10 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/inline.js +1190 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser.d.ts +5 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser.js +42 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/renderer.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/renderer.js +615 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/testing/theme-render-fixture.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/terminal-markdown/testing/theme-render-fixture.js +27 -0
- package/node_modules/toolcraft-design/dist/tokens/brand.d.ts +5 -0
- package/node_modules/toolcraft-design/dist/tokens/brand.js +5 -0
- package/node_modules/toolcraft-design/dist/tokens/colors.d.ts +37 -0
- package/node_modules/toolcraft-design/dist/tokens/colors.js +85 -0
- package/node_modules/toolcraft-design/dist/tokens/index.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/tokens/index.js +5 -0
- package/node_modules/toolcraft-design/dist/tokens/spacing.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/tokens/spacing.js +6 -0
- package/node_modules/toolcraft-design/dist/tokens/typography.d.ts +7 -0
- package/node_modules/toolcraft-design/dist/tokens/typography.js +8 -0
- package/node_modules/toolcraft-design/dist/tokens/widths.d.ts +5 -0
- package/node_modules/toolcraft-design/dist/tokens/widths.js +5 -0
- package/node_modules/toolcraft-design/package.json +44 -0
- package/package.json +15 -5
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { parseBlockDocument } from "./parser/block.js";
|
|
2
|
+
export function parse(markdown) {
|
|
3
|
+
const { frontmatter, frontmatterRange, children } = parseBlockDocument(markdown);
|
|
4
|
+
const ast = withRange({
|
|
5
|
+
type: "root",
|
|
6
|
+
children: frontmatter === undefined
|
|
7
|
+
? children
|
|
8
|
+
: [createFrontmatterNode(frontmatter, frontmatterRange), ...children]
|
|
9
|
+
}, {
|
|
10
|
+
start: 0,
|
|
11
|
+
end: Buffer.byteLength(markdown, "utf8")
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
...(frontmatter === undefined ? {} : { frontmatter }),
|
|
15
|
+
ast
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function createFrontmatterNode(data, range) {
|
|
19
|
+
const node = {
|
|
20
|
+
type: "frontmatter",
|
|
21
|
+
data
|
|
22
|
+
};
|
|
23
|
+
if (range === undefined) {
|
|
24
|
+
return node;
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(node, "range", {
|
|
27
|
+
value: range,
|
|
28
|
+
enumerable: false,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true
|
|
31
|
+
});
|
|
32
|
+
return node;
|
|
33
|
+
}
|
|
34
|
+
function withRange(node, range) {
|
|
35
|
+
Object.defineProperty(node, "range", {
|
|
36
|
+
value: range,
|
|
37
|
+
enumerable: false,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true
|
|
40
|
+
});
|
|
41
|
+
return node;
|
|
42
|
+
}
|
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
import { symbols } from "../components/symbols.js";
|
|
2
|
+
import { displayWidth, graphemes } from "../dashboard/terminal-width.js";
|
|
3
|
+
import { getTheme } from "../internal/theme-detect.js";
|
|
4
|
+
import { stripAnsi } from "../internal/strip-ansi.js";
|
|
5
|
+
import { spacing } from "../tokens/spacing.js";
|
|
6
|
+
import { typography } from "../tokens/typography.js";
|
|
7
|
+
import { widths } from "../tokens/widths.js";
|
|
8
|
+
const lineChar = "─";
|
|
9
|
+
export function render(ast, options = {}) {
|
|
10
|
+
const requestedWidth = options.width ?? process.stdout.columns ?? widths.maxLine;
|
|
11
|
+
if (!Number.isFinite(requestedWidth) || requestedWidth <= 0) {
|
|
12
|
+
throw new Error("width must be a positive finite number.");
|
|
13
|
+
}
|
|
14
|
+
const width = Math.max(1, requestedWidth);
|
|
15
|
+
const context = {
|
|
16
|
+
width,
|
|
17
|
+
showFrontmatter: options.showFrontmatter ?? false,
|
|
18
|
+
theme: getTheme(),
|
|
19
|
+
footnotes: ast.type === "root" ? createFootnoteState(ast.children) : undefined
|
|
20
|
+
};
|
|
21
|
+
return renderNode(ast, context);
|
|
22
|
+
}
|
|
23
|
+
function renderNode(node, context) {
|
|
24
|
+
switch (node.type) {
|
|
25
|
+
case "root":
|
|
26
|
+
return renderRoot(node, context);
|
|
27
|
+
case "heading":
|
|
28
|
+
return renderHeading(node, context);
|
|
29
|
+
case "paragraph":
|
|
30
|
+
return renderParagraph(node, context);
|
|
31
|
+
case "blockquote":
|
|
32
|
+
return renderBlockquote(node, context);
|
|
33
|
+
case "alert":
|
|
34
|
+
return renderAlert(node, context);
|
|
35
|
+
case "code":
|
|
36
|
+
return renderCodeBlock(node, context);
|
|
37
|
+
case "list":
|
|
38
|
+
return renderList(node, context);
|
|
39
|
+
case "table":
|
|
40
|
+
return renderTable(node, context);
|
|
41
|
+
case "html":
|
|
42
|
+
return renderHtml(node, context);
|
|
43
|
+
case "text":
|
|
44
|
+
case "strong":
|
|
45
|
+
case "emphasis":
|
|
46
|
+
case "strikethrough":
|
|
47
|
+
case "inlineCode":
|
|
48
|
+
case "link":
|
|
49
|
+
case "image":
|
|
50
|
+
case "break":
|
|
51
|
+
case "footnoteReference":
|
|
52
|
+
return renderInline([node], context).join("\n");
|
|
53
|
+
case "thematicBreak":
|
|
54
|
+
return `${context.theme.divider(lineChar.repeat(context.width))}\n\n`;
|
|
55
|
+
case "frontmatter":
|
|
56
|
+
return context.showFrontmatter ? renderFrontmatter(node.data, context) : "";
|
|
57
|
+
case "footnoteDefinition":
|
|
58
|
+
return "";
|
|
59
|
+
default:
|
|
60
|
+
return "children" in node ? renderChildren(node.children, context) : "";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function renderRoot(node, context) {
|
|
64
|
+
const mainOutput = renderChildren(node.children.filter((child) => child.type !== "footnoteDefinition"), context);
|
|
65
|
+
const footnotesOutput = renderReferencedFootnotes(context);
|
|
66
|
+
return `${mainOutput}${footnotesOutput}`;
|
|
67
|
+
}
|
|
68
|
+
function renderChildren(children, context) {
|
|
69
|
+
return children.map((child) => renderNode(child, context)).join("");
|
|
70
|
+
}
|
|
71
|
+
function renderParagraph(node, context) {
|
|
72
|
+
const lines = renderInline(node.children, context);
|
|
73
|
+
if (lines.length === 0) {
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
76
|
+
return `${lines.join("\n")}\n\n`;
|
|
77
|
+
}
|
|
78
|
+
function renderHeading(node, context) {
|
|
79
|
+
const lines = renderInline(node.children, context);
|
|
80
|
+
if (lines.length === 0) {
|
|
81
|
+
return "";
|
|
82
|
+
}
|
|
83
|
+
const styledLines = lines.map((line) => styleHeading(line, node.depth, context));
|
|
84
|
+
if (node.depth === 1) {
|
|
85
|
+
const underlineWidth = Math.max(...lines.map((line) => visibleWidth(line)));
|
|
86
|
+
return `${styledLines.join("\n")}\n${context.theme.header(lineChar.repeat(underlineWidth))}\n\n`;
|
|
87
|
+
}
|
|
88
|
+
return `${styledLines.join("\n")}\n\n`;
|
|
89
|
+
}
|
|
90
|
+
function renderBlockquote(node, context) {
|
|
91
|
+
const prefix = `${symbols.bar} `;
|
|
92
|
+
const body = renderBlockChildren(node.children, reduceWidth(context, prefix));
|
|
93
|
+
if (body.length === 0) {
|
|
94
|
+
return `${symbols.bar}\n\n`;
|
|
95
|
+
}
|
|
96
|
+
const lines = body
|
|
97
|
+
.split("\n")
|
|
98
|
+
.map((line) => (line.length > 0 ? `${prefix}${typography.dim(line)}` : symbols.bar));
|
|
99
|
+
return `${lines.join("\n")}\n\n`;
|
|
100
|
+
}
|
|
101
|
+
function renderAlert(node, context) {
|
|
102
|
+
const prefix = `${symbols.bar} `;
|
|
103
|
+
const labelLine = `${prefix}${formatAlertLabel(node.kind, context)}`;
|
|
104
|
+
const body = renderBlockChildren(node.children, reduceWidth(context, prefix));
|
|
105
|
+
if (body.length === 0) {
|
|
106
|
+
return `${labelLine}\n\n`;
|
|
107
|
+
}
|
|
108
|
+
const lines = body
|
|
109
|
+
.split("\n")
|
|
110
|
+
.map((line) => (line.length > 0 ? `${prefix}${line}` : symbols.bar));
|
|
111
|
+
return `${labelLine}\n${lines.join("\n")}\n\n`;
|
|
112
|
+
}
|
|
113
|
+
function renderCodeBlock(node, context) {
|
|
114
|
+
const indent = " ".repeat(spacing.sm);
|
|
115
|
+
const lines = node.value.split("\n").map((line) => stripAnsi(line));
|
|
116
|
+
const longestLine = lines.reduce((max, line) => Math.max(max, visibleWidth(line)), 0);
|
|
117
|
+
const borderWidth = Math.max(3, Math.min(context.width - indent.length, longestLine));
|
|
118
|
+
const border = context.theme.muted(`${indent}${lineChar.repeat(borderWidth)}`);
|
|
119
|
+
const content = lines.map((line) => `${indent}${line}`).join("\n");
|
|
120
|
+
return `${border}\n${content}\n${border}\n\n`;
|
|
121
|
+
}
|
|
122
|
+
function renderList(node, context) {
|
|
123
|
+
const items = node.children
|
|
124
|
+
.map((child, index) => {
|
|
125
|
+
if (child.type !== "listItem") {
|
|
126
|
+
return renderNode(child, context).trimEnd();
|
|
127
|
+
}
|
|
128
|
+
return renderListItem(child, node, index, context);
|
|
129
|
+
})
|
|
130
|
+
.filter((item) => item.length > 0);
|
|
131
|
+
if (items.length === 0) {
|
|
132
|
+
return "";
|
|
133
|
+
}
|
|
134
|
+
return `${items.join("\n")}\n\n`;
|
|
135
|
+
}
|
|
136
|
+
function renderTable(node, context) {
|
|
137
|
+
const rows = node.children.filter((child) => child.type === "tableRow");
|
|
138
|
+
if (rows.length === 0) {
|
|
139
|
+
return "";
|
|
140
|
+
}
|
|
141
|
+
const columnCount = Math.max(node.align.length, ...rows.map((row) => row.children.length));
|
|
142
|
+
if (columnCount === 0) {
|
|
143
|
+
return "";
|
|
144
|
+
}
|
|
145
|
+
const renderedRows = rows.map((row) => Array.from({ length: columnCount }, (_, columnIndex) => {
|
|
146
|
+
const cell = row.children[columnIndex];
|
|
147
|
+
return cell?.type === "tableCell" ? renderTableCell(cell, context) : "";
|
|
148
|
+
}));
|
|
149
|
+
const columnWidths = Array.from({ length: columnCount }, (_, columnIndex) => Math.max(...renderedRows.map((row) => visibleWidth(row[columnIndex] ?? "")), 0));
|
|
150
|
+
if (getRenderedTableWidth(columnWidths) > context.width) {
|
|
151
|
+
return renderStackedTable(rows, columnCount, context);
|
|
152
|
+
}
|
|
153
|
+
const lines = renderedRows.map((row, rowIndex) => row.map((cell, columnIndex) => alignTableCell(rowIndex === 0 ? context.theme.header(typography.bold(cell)) : cell, columnWidths[columnIndex] ?? 0, node.align[columnIndex] ?? null)));
|
|
154
|
+
const outputLines = lines.map((row, rowIndex) => {
|
|
155
|
+
const line = `${symbols.bar}${row
|
|
156
|
+
.map((cell) => `${" ".repeat(spacing.sm)}${cell}${" ".repeat(spacing.sm)}`)
|
|
157
|
+
.join(symbols.bar)}${symbols.bar}`;
|
|
158
|
+
if (rowIndex !== 0 || lines.length === 1) {
|
|
159
|
+
return line;
|
|
160
|
+
}
|
|
161
|
+
const divider = context.theme.muted(`├${columnWidths.map((width) => lineChar.repeat(width + spacing.sm * 2)).join("┼")}┤`);
|
|
162
|
+
return `${line}\n${divider}`;
|
|
163
|
+
});
|
|
164
|
+
return `${outputLines.join("\n")}\n\n`;
|
|
165
|
+
}
|
|
166
|
+
function renderStackedTable(rows, columnCount, context) {
|
|
167
|
+
const headerRow = rows[0];
|
|
168
|
+
if (headerRow === undefined) {
|
|
169
|
+
return "";
|
|
170
|
+
}
|
|
171
|
+
const dataRows = rows.slice(1);
|
|
172
|
+
if (dataRows.length === 0) {
|
|
173
|
+
const headerLines = Array.from({ length: columnCount }, (_, columnIndex) => tokenizeText(getStackedTableLabel(headerRow.children[columnIndex], columnIndex, context), [
|
|
174
|
+
typography.bold
|
|
175
|
+
])).flatMap((tokens) => wrapTokens(tokens, context.width));
|
|
176
|
+
return headerLines.length === 0 ? "" : `${headerLines.join("\n")}\n\n`;
|
|
177
|
+
}
|
|
178
|
+
const blocks = dataRows
|
|
179
|
+
.map((row) => Array.from({ length: columnCount }, (_, columnIndex) => renderStackedTableField(headerRow.children[columnIndex], row.children[columnIndex], columnIndex, context))
|
|
180
|
+
.filter((field) => field.length > 0)
|
|
181
|
+
.join("\n"))
|
|
182
|
+
.filter((block) => block.length > 0);
|
|
183
|
+
return blocks.length === 0 ? "" : `${blocks.join("\n\n")}\n\n`;
|
|
184
|
+
}
|
|
185
|
+
function renderListItem(node, list, index, context) {
|
|
186
|
+
const marker = getListMarker(node, list, index);
|
|
187
|
+
const indent = " ".repeat(spacing.sm);
|
|
188
|
+
const firstPrefix = `${indent}${marker} `;
|
|
189
|
+
const body = renderBlockChildren(node.children, reduceWidth(context, firstPrefix));
|
|
190
|
+
const continuationPrefix = `${indent}${" ".repeat(marker.length + 1)}`;
|
|
191
|
+
if (body.length === 0) {
|
|
192
|
+
return firstPrefix.trimEnd();
|
|
193
|
+
}
|
|
194
|
+
return prefixBlock(body, firstPrefix, continuationPrefix);
|
|
195
|
+
}
|
|
196
|
+
function styleHeading(value, depth, context) {
|
|
197
|
+
if (depth <= 2) {
|
|
198
|
+
return context.theme.header(typography.bold(value));
|
|
199
|
+
}
|
|
200
|
+
if (depth <= 4) {
|
|
201
|
+
return typography.bold(value);
|
|
202
|
+
}
|
|
203
|
+
return context.theme.muted(typography.bold(value));
|
|
204
|
+
}
|
|
205
|
+
function renderFrontmatter(data, context) {
|
|
206
|
+
const entries = Object.entries(data);
|
|
207
|
+
if (entries.length === 0) {
|
|
208
|
+
return "";
|
|
209
|
+
}
|
|
210
|
+
const lines = entries.flatMap(([key, value]) => wrapText(`${key}: ${formatFrontmatterValue(value)}`, context.width).map((line) => typography.dim(line)));
|
|
211
|
+
return `${lines.join("\n")}\n\n`;
|
|
212
|
+
}
|
|
213
|
+
function formatFrontmatterValue(value) {
|
|
214
|
+
if (value === null) {
|
|
215
|
+
return "null";
|
|
216
|
+
}
|
|
217
|
+
if (typeof value === "string") {
|
|
218
|
+
return value;
|
|
219
|
+
}
|
|
220
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
221
|
+
return String(value);
|
|
222
|
+
}
|
|
223
|
+
const ancestors = [];
|
|
224
|
+
return JSON.stringify(value, function (_key, nestedValue) {
|
|
225
|
+
if (typeof nestedValue !== "object" || nestedValue === null) {
|
|
226
|
+
return nestedValue;
|
|
227
|
+
}
|
|
228
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) {
|
|
229
|
+
ancestors.pop();
|
|
230
|
+
}
|
|
231
|
+
if (ancestors.includes(nestedValue)) {
|
|
232
|
+
return "[Circular]";
|
|
233
|
+
}
|
|
234
|
+
ancestors.push(nestedValue);
|
|
235
|
+
return nestedValue;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
function renderHtml(node, context) {
|
|
239
|
+
const value = stripAnsi(stripHtmlTags(node.value)).trim();
|
|
240
|
+
if (value.length === 0) {
|
|
241
|
+
return "";
|
|
242
|
+
}
|
|
243
|
+
const lines = wrapText(value, context.width);
|
|
244
|
+
if (lines.length === 0) {
|
|
245
|
+
return "";
|
|
246
|
+
}
|
|
247
|
+
return `${lines.join("\n")}\n\n`;
|
|
248
|
+
}
|
|
249
|
+
function renderBlockChildren(children, context) {
|
|
250
|
+
const renderedChildren = children
|
|
251
|
+
.map((child) => ({
|
|
252
|
+
type: child.type,
|
|
253
|
+
value: renderNode(child, context).trimEnd()
|
|
254
|
+
}))
|
|
255
|
+
.filter((child) => child.value.length > 0);
|
|
256
|
+
if (renderedChildren.length === 0) {
|
|
257
|
+
return "";
|
|
258
|
+
}
|
|
259
|
+
let output = renderedChildren[0].value;
|
|
260
|
+
for (let index = 1; index < renderedChildren.length; index += 1) {
|
|
261
|
+
const previous = renderedChildren[index - 1];
|
|
262
|
+
const current = renderedChildren[index];
|
|
263
|
+
const separator = previous.type === "paragraph" && current.type === "list" ? "\n" : "\n\n";
|
|
264
|
+
output += `${separator}${current.value}`;
|
|
265
|
+
}
|
|
266
|
+
return output;
|
|
267
|
+
}
|
|
268
|
+
function renderReferencedFootnotes(context) {
|
|
269
|
+
const footnotes = context.footnotes;
|
|
270
|
+
if (footnotes === undefined || footnotes.labelsInOrder.length === 0) {
|
|
271
|
+
return "";
|
|
272
|
+
}
|
|
273
|
+
const rendered = [];
|
|
274
|
+
for (let index = 0; index < footnotes.labelsInOrder.length; index += 1) {
|
|
275
|
+
const label = footnotes.labelsInOrder[index];
|
|
276
|
+
const definition = footnotes.definitions.get(label);
|
|
277
|
+
const number = footnotes.numbers.get(label);
|
|
278
|
+
if (definition !== undefined && number !== undefined) {
|
|
279
|
+
rendered.push(renderFootnoteDefinition(definition, number, context));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (rendered.length === 0) {
|
|
283
|
+
return "";
|
|
284
|
+
}
|
|
285
|
+
return `${rendered.join("\n")}\n\n`;
|
|
286
|
+
}
|
|
287
|
+
function renderFootnoteDefinition(node, number, context) {
|
|
288
|
+
const marker = typography.dim(`[${number}]`);
|
|
289
|
+
const firstPrefix = `${" ".repeat(spacing.sm)}${marker} `;
|
|
290
|
+
const continuationPrefix = `${" ".repeat(spacing.sm + visibleWidth(`[${number}] `))}`;
|
|
291
|
+
const body = renderBlockChildren(node.children, reduceWidth(context, firstPrefix));
|
|
292
|
+
if (body.length === 0) {
|
|
293
|
+
return firstPrefix.trimEnd();
|
|
294
|
+
}
|
|
295
|
+
return prefixBlock(body, firstPrefix, continuationPrefix);
|
|
296
|
+
}
|
|
297
|
+
function getListMarker(node, list, index) {
|
|
298
|
+
if (node.checked === true) {
|
|
299
|
+
return symbols.active;
|
|
300
|
+
}
|
|
301
|
+
if (node.checked === false) {
|
|
302
|
+
return symbols.inactive;
|
|
303
|
+
}
|
|
304
|
+
if (list.ordered) {
|
|
305
|
+
return `${(list.start ?? 1) + index}.`;
|
|
306
|
+
}
|
|
307
|
+
return "•";
|
|
308
|
+
}
|
|
309
|
+
function prefixBlock(rendered, firstPrefix, restPrefix) {
|
|
310
|
+
return rendered
|
|
311
|
+
.split("\n")
|
|
312
|
+
.map((line, index) => {
|
|
313
|
+
const prefix = index === 0 ? firstPrefix : restPrefix;
|
|
314
|
+
return line.length > 0 ? `${prefix}${line}` : prefix.trimEnd();
|
|
315
|
+
})
|
|
316
|
+
.join("\n");
|
|
317
|
+
}
|
|
318
|
+
function reduceWidth(context, prefix) {
|
|
319
|
+
return {
|
|
320
|
+
...context,
|
|
321
|
+
width: Math.max(1, context.width - visibleWidth(prefix))
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function renderInline(nodes, context) {
|
|
325
|
+
const tokens = tokenizeInline(nodes, context);
|
|
326
|
+
return wrapTokens(tokens, context.width);
|
|
327
|
+
}
|
|
328
|
+
function tokenizeInline(nodes, context) {
|
|
329
|
+
const tokens = [];
|
|
330
|
+
for (const node of nodes) {
|
|
331
|
+
collectInlineTokens(node, [], context, tokens);
|
|
332
|
+
}
|
|
333
|
+
return tokens;
|
|
334
|
+
}
|
|
335
|
+
function collectInlineTokens(node, formatters, context, tokens) {
|
|
336
|
+
switch (node.type) {
|
|
337
|
+
case "text":
|
|
338
|
+
tokens.push(...tokenizeText(stripAnsi(node.value), formatters));
|
|
339
|
+
return;
|
|
340
|
+
case "strong":
|
|
341
|
+
collectChildren(node.children, [...formatters, typography.bold], context, tokens);
|
|
342
|
+
return;
|
|
343
|
+
case "emphasis":
|
|
344
|
+
collectChildren(node.children, [...formatters, typography.italic], context, tokens);
|
|
345
|
+
return;
|
|
346
|
+
case "strikethrough":
|
|
347
|
+
collectChildren(node.children, [...formatters, typography.strikethrough], context, tokens);
|
|
348
|
+
return;
|
|
349
|
+
case "inlineCode":
|
|
350
|
+
tokens.push(...tokenizeText(stripAnsi(node.value), [...formatters, context.theme.accent]));
|
|
351
|
+
return;
|
|
352
|
+
case "link":
|
|
353
|
+
collectLinkTokens(node, formatters, context, tokens);
|
|
354
|
+
return;
|
|
355
|
+
case "image":
|
|
356
|
+
tokens.push(createWordToken(formatImagePlaceholder(stripAnsi(node.alt)), [
|
|
357
|
+
...formatters,
|
|
358
|
+
context.theme.muted
|
|
359
|
+
]));
|
|
360
|
+
return;
|
|
361
|
+
case "footnoteReference": {
|
|
362
|
+
const footnoteNumber = resolveFootnoteNumber(node.label, context);
|
|
363
|
+
if (footnoteNumber !== null) {
|
|
364
|
+
tokens.push(createWordToken(`[${footnoteNumber}]`, [...formatters, typography.dim]));
|
|
365
|
+
}
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
case "html": {
|
|
369
|
+
const value = stripAnsi(stripHtmlTags(node.value));
|
|
370
|
+
if (value.length > 0) {
|
|
371
|
+
tokens.push(...tokenizeText(value, formatters));
|
|
372
|
+
}
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
case "break":
|
|
376
|
+
tokens.push({ type: "break" });
|
|
377
|
+
return;
|
|
378
|
+
default:
|
|
379
|
+
if ("children" in node) {
|
|
380
|
+
collectChildren(node.children, formatters, context, tokens);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function collectChildren(children, formatters, context, tokens) {
|
|
385
|
+
for (const child of children) {
|
|
386
|
+
collectInlineTokens(child, formatters, context, tokens);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function collectLinkTokens(node, formatters, context, tokens) {
|
|
390
|
+
if (isAutolink(node)) {
|
|
391
|
+
tokens.push(createWordToken(stripAnsi(node.url), [...formatters, context.theme.accent]));
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const childTokens = [];
|
|
395
|
+
collectChildren(node.children, formatters, context, childTokens);
|
|
396
|
+
const trimmedChildTokens = trimTrailingSpaces(childTokens);
|
|
397
|
+
tokens.push(...trimmedChildTokens);
|
|
398
|
+
if (trimmedChildTokens.some((token) => token.type === "word")) {
|
|
399
|
+
tokens.push({ type: "space", value: " " });
|
|
400
|
+
}
|
|
401
|
+
tokens.push(createWordToken(`(${stripAnsi(node.url)})`, [...formatters, context.theme.accent]));
|
|
402
|
+
}
|
|
403
|
+
function isAutolink(node) {
|
|
404
|
+
if (node.children.length !== 1 || node.children[0]?.type !== "text") {
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
const label = node.children[0].value;
|
|
408
|
+
return (label === node.url ||
|
|
409
|
+
(node.url.startsWith("http://") && label === node.url.slice("http://".length)) ||
|
|
410
|
+
(node.url.startsWith("mailto:") && label === node.url.slice("mailto:".length)));
|
|
411
|
+
}
|
|
412
|
+
function formatImagePlaceholder(alt) {
|
|
413
|
+
return alt.length > 0 ? `[image: ${alt}]` : "[image]";
|
|
414
|
+
}
|
|
415
|
+
function createWordToken(value, formatters) {
|
|
416
|
+
return { type: "word", value, formatters };
|
|
417
|
+
}
|
|
418
|
+
function trimTrailingSpaces(tokens) {
|
|
419
|
+
let end = tokens.length;
|
|
420
|
+
while (end > 0 && tokens[end - 1]?.type === "space") {
|
|
421
|
+
end -= 1;
|
|
422
|
+
}
|
|
423
|
+
return tokens.slice(0, end);
|
|
424
|
+
}
|
|
425
|
+
function tokenizeText(value, formatters) {
|
|
426
|
+
const lines = value.split("\n");
|
|
427
|
+
return lines.flatMap((line, lineIndex) => {
|
|
428
|
+
const pieces = line
|
|
429
|
+
.split(/([ \t]+)/)
|
|
430
|
+
.filter((piece) => piece.length > 0)
|
|
431
|
+
.map((piece) => /^[ \t]+$/.test(piece)
|
|
432
|
+
? { type: "space", value: piece }
|
|
433
|
+
: { type: "word", value: piece, formatters });
|
|
434
|
+
return lineIndex < lines.length - 1 ? [...pieces, { type: "break" }] : pieces;
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
function wrapTokens(tokens, width) {
|
|
438
|
+
const lines = [];
|
|
439
|
+
let currentLine = "";
|
|
440
|
+
let currentWidth = 0;
|
|
441
|
+
let pendingSpace = "";
|
|
442
|
+
const flushLine = () => {
|
|
443
|
+
lines.push(currentLine);
|
|
444
|
+
currentLine = "";
|
|
445
|
+
currentWidth = 0;
|
|
446
|
+
pendingSpace = "";
|
|
447
|
+
};
|
|
448
|
+
for (const token of tokens) {
|
|
449
|
+
if (token.type === "break") {
|
|
450
|
+
flushLine();
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
if (token.type === "space") {
|
|
454
|
+
if (currentWidth > 0) {
|
|
455
|
+
pendingSpace += token.value;
|
|
456
|
+
}
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
const chunks = splitWord(token.value, width);
|
|
460
|
+
for (let index = 0; index < chunks.length; index++) {
|
|
461
|
+
const chunk = chunks[index];
|
|
462
|
+
const gap = index === 0 ? pendingSpace : "";
|
|
463
|
+
const chunkWidth = visibleWidth(chunk);
|
|
464
|
+
const gapWidth = visibleWidth(gap);
|
|
465
|
+
if (currentWidth > 0 && currentWidth + chunkWidth + gapWidth > width) {
|
|
466
|
+
flushLine();
|
|
467
|
+
}
|
|
468
|
+
if (currentWidth > 0 && gapWidth > 0) {
|
|
469
|
+
currentLine += gap;
|
|
470
|
+
currentWidth += gapWidth;
|
|
471
|
+
}
|
|
472
|
+
currentLine += applyFormatters(chunk, token.formatters);
|
|
473
|
+
currentWidth += chunkWidth;
|
|
474
|
+
pendingSpace = "";
|
|
475
|
+
if (index < chunks.length - 1) {
|
|
476
|
+
flushLine();
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
if (currentLine.length > 0) {
|
|
481
|
+
lines.push(currentLine);
|
|
482
|
+
}
|
|
483
|
+
return lines;
|
|
484
|
+
}
|
|
485
|
+
function splitWord(value, width) {
|
|
486
|
+
if (visibleWidth(value) <= width) {
|
|
487
|
+
return [value];
|
|
488
|
+
}
|
|
489
|
+
const chunks = [];
|
|
490
|
+
let chunk = "";
|
|
491
|
+
let chunkWidth = 0;
|
|
492
|
+
for (const grapheme of graphemes(value)) {
|
|
493
|
+
const graphemeWidth = visibleWidth(grapheme);
|
|
494
|
+
if (chunk.length > 0 && chunkWidth + graphemeWidth > width) {
|
|
495
|
+
chunks.push(chunk);
|
|
496
|
+
chunk = "";
|
|
497
|
+
chunkWidth = 0;
|
|
498
|
+
}
|
|
499
|
+
chunk += grapheme;
|
|
500
|
+
chunkWidth += graphemeWidth;
|
|
501
|
+
if (chunkWidth >= width) {
|
|
502
|
+
chunks.push(chunk);
|
|
503
|
+
chunk = "";
|
|
504
|
+
chunkWidth = 0;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (chunk.length > 0) {
|
|
508
|
+
chunks.push(chunk);
|
|
509
|
+
}
|
|
510
|
+
return chunks;
|
|
511
|
+
}
|
|
512
|
+
function applyFormatters(value, formatters) {
|
|
513
|
+
return formatters.reduce((text, formatter) => formatter(text), value);
|
|
514
|
+
}
|
|
515
|
+
function wrapText(value, width) {
|
|
516
|
+
const tokens = tokenizeText(value, []);
|
|
517
|
+
return wrapTokens(tokens, Math.max(1, width));
|
|
518
|
+
}
|
|
519
|
+
function createFootnoteState(children) {
|
|
520
|
+
return {
|
|
521
|
+
definitions: new Map(children.flatMap((child) => child.type === "footnoteDefinition" ? [[child.label, child]] : [])),
|
|
522
|
+
labelsInOrder: [],
|
|
523
|
+
numbers: new Map()
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
function resolveFootnoteNumber(label, context) {
|
|
527
|
+
const footnotes = context.footnotes;
|
|
528
|
+
if (footnotes === undefined || !footnotes.definitions.has(label)) {
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
const existing = footnotes.numbers.get(label);
|
|
532
|
+
if (existing !== undefined) {
|
|
533
|
+
return existing;
|
|
534
|
+
}
|
|
535
|
+
const number = footnotes.numbers.size + 1;
|
|
536
|
+
footnotes.numbers.set(label, number);
|
|
537
|
+
footnotes.labelsInOrder.push(label);
|
|
538
|
+
return number;
|
|
539
|
+
}
|
|
540
|
+
function formatAlertLabel(kind, context) {
|
|
541
|
+
switch (kind) {
|
|
542
|
+
case "NOTE":
|
|
543
|
+
return context.theme.info("Note");
|
|
544
|
+
case "TIP":
|
|
545
|
+
return context.theme.success("Tip");
|
|
546
|
+
case "IMPORTANT":
|
|
547
|
+
return context.theme.info("Important");
|
|
548
|
+
case "WARNING":
|
|
549
|
+
return context.theme.warning("Warning");
|
|
550
|
+
case "CAUTION":
|
|
551
|
+
return context.theme.error("Caution");
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function renderTableCell(node, context) {
|
|
555
|
+
return wrapTokens(tokenizeInline(node.children, context), Number.MAX_SAFE_INTEGER).join(" ");
|
|
556
|
+
}
|
|
557
|
+
function renderStackedTableField(headerCell, cell, columnIndex, context) {
|
|
558
|
+
const tokens = [
|
|
559
|
+
...tokenizeText(getStackedTableLabel(headerCell, columnIndex, context), [typography.bold]),
|
|
560
|
+
createWordToken(":", [typography.bold]),
|
|
561
|
+
{ type: "space", value: " " },
|
|
562
|
+
...getStackedTableValueTokens(cell, context)
|
|
563
|
+
];
|
|
564
|
+
return wrapTokens(tokens, context.width).join("\n");
|
|
565
|
+
}
|
|
566
|
+
function getStackedTableLabel(headerCell, columnIndex, context) {
|
|
567
|
+
if (headerCell?.type !== "tableCell") {
|
|
568
|
+
return `Column ${columnIndex + 1}`;
|
|
569
|
+
}
|
|
570
|
+
const label = stripAnsi(renderTableCell(headerCell, context)).trim();
|
|
571
|
+
return label.length > 0 ? label : `Column ${columnIndex + 1}`;
|
|
572
|
+
}
|
|
573
|
+
function getStackedTableValueTokens(cell, context) {
|
|
574
|
+
if (cell?.type !== "tableCell") {
|
|
575
|
+
return [createWordToken("—", [context.theme.muted])];
|
|
576
|
+
}
|
|
577
|
+
const tokens = trimTrailingSpaces(tokenizeInline(cell.children, context));
|
|
578
|
+
return tokens.length > 0 ? tokens : [createWordToken("—", [context.theme.muted])];
|
|
579
|
+
}
|
|
580
|
+
function getRenderedTableWidth(columnWidths) {
|
|
581
|
+
return columnWidths.reduce((totalWidth, width) => totalWidth + width + spacing.sm * 2, columnWidths.length + 1);
|
|
582
|
+
}
|
|
583
|
+
function alignTableCell(value, width, align) {
|
|
584
|
+
const extraSpace = Math.max(0, width - visibleWidth(value));
|
|
585
|
+
if (align === "right") {
|
|
586
|
+
return `${" ".repeat(extraSpace)}${value}`;
|
|
587
|
+
}
|
|
588
|
+
if (align === "center") {
|
|
589
|
+
const leftPadding = Math.floor(extraSpace / 2);
|
|
590
|
+
const rightPadding = extraSpace - leftPadding;
|
|
591
|
+
return `${" ".repeat(leftPadding)}${value}${" ".repeat(rightPadding)}`;
|
|
592
|
+
}
|
|
593
|
+
return `${value}${" ".repeat(extraSpace)}`;
|
|
594
|
+
}
|
|
595
|
+
function stripHtmlTags(value) {
|
|
596
|
+
let output = "";
|
|
597
|
+
let inTag = false;
|
|
598
|
+
for (const char of value) {
|
|
599
|
+
if (char === "<") {
|
|
600
|
+
inTag = true;
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (char === ">" && inTag) {
|
|
604
|
+
inTag = false;
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
if (!inTag) {
|
|
608
|
+
output += char;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return output;
|
|
612
|
+
}
|
|
613
|
+
function visibleWidth(value) {
|
|
614
|
+
return displayWidth(stripAnsi(value));
|
|
615
|
+
}
|
package/node_modules/toolcraft-design/dist/terminal-markdown/testing/theme-render-fixture.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|