terminal-pilot 0.0.30 → 0.0.31
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 +1375 -435
- package/dist/cli.js.map +4 -4
- package/dist/commands/close-session.js +485 -6
- package/dist/commands/close-session.js.map +4 -4
- package/dist/commands/create-session.js +485 -6
- package/dist/commands/create-session.js.map +4 -4
- package/dist/commands/fill.js +485 -6
- package/dist/commands/fill.js.map +4 -4
- package/dist/commands/get-session.js +485 -6
- package/dist/commands/get-session.js.map +4 -4
- package/dist/commands/index.js +626 -44
- package/dist/commands/index.js.map +4 -4
- package/dist/commands/install.js +622 -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 +485 -6
- package/dist/commands/list-sessions.js.map +4 -4
- package/dist/commands/press-key.js +485 -6
- package/dist/commands/press-key.js.map +4 -4
- package/dist/commands/read-history.js +485 -6
- package/dist/commands/read-history.js.map +4 -4
- package/dist/commands/read-screen.js +485 -6
- package/dist/commands/read-screen.js.map +4 -4
- package/dist/commands/resize.js +485 -6
- package/dist/commands/resize.js.map +4 -4
- package/dist/commands/screenshot.js +485 -6
- package/dist/commands/screenshot.js.map +4 -4
- package/dist/commands/send-signal.js +485 -6
- package/dist/commands/send-signal.js.map +4 -4
- package/dist/commands/type.js +485 -6
- package/dist/commands/type.js.map +4 -4
- package/dist/commands/uninstall.js +550 -20
- package/dist/commands/uninstall.js.map +4 -4
- package/dist/commands/wait-for-exit.js +485 -6
- package/dist/commands/wait-for-exit.js.map +4 -4
- package/dist/commands/wait-for.js +485 -6
- package/dist/commands/wait-for.js.map +4 -4
- package/dist/testing/cli-repl.js +1375 -435
- package/dist/testing/cli-repl.js.map +4 -4
- package/dist/testing/qa-cli.js +1385 -445
- 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,437 @@
|
|
|
1
|
+
const MAX_PARTIAL_DEPTH = 100;
|
|
2
|
+
const HTML_ESCAPE = {
|
|
3
|
+
"&": "&",
|
|
4
|
+
"<": "<",
|
|
5
|
+
">": ">",
|
|
6
|
+
'"': """,
|
|
7
|
+
"'": "'",
|
|
8
|
+
"/": "/",
|
|
9
|
+
"`": "`",
|
|
10
|
+
"=": "="
|
|
11
|
+
};
|
|
12
|
+
export function renderTemplate(template, view, options = {}) {
|
|
13
|
+
const prepared = options.yield === undefined
|
|
14
|
+
? template
|
|
15
|
+
: resolveTemplatePartials(template, options.partials ?? {})
|
|
16
|
+
.split("{{yield}}")
|
|
17
|
+
.join(options.yield);
|
|
18
|
+
const tokens = parseTemplate(prepared);
|
|
19
|
+
validatePartialReferences(tokens, options.partials ?? {}, []);
|
|
20
|
+
if (options.validate === true) {
|
|
21
|
+
const expanded = resolveTemplatePartials(prepared, options.partials ?? {});
|
|
22
|
+
validateVariables(parseTemplate(expanded), { view });
|
|
23
|
+
}
|
|
24
|
+
const state = {
|
|
25
|
+
escape: options.escape === "none" ? String : escapeHtml,
|
|
26
|
+
partials: options.partials ?? {},
|
|
27
|
+
partialStack: [],
|
|
28
|
+
preserveMissing: options.yield !== undefined && options.escape === "none",
|
|
29
|
+
validate: options.validate === true
|
|
30
|
+
};
|
|
31
|
+
return renderTokens(tokens, { view }, prepared, state);
|
|
32
|
+
}
|
|
33
|
+
export function getTemplatePartialNames(template) {
|
|
34
|
+
const names = new Set();
|
|
35
|
+
collectPartialNames(parseTemplate(template), names);
|
|
36
|
+
return [...names];
|
|
37
|
+
}
|
|
38
|
+
export function resolveTemplatePartials(template, partials) {
|
|
39
|
+
return expandTemplatePartials(template, partials, []);
|
|
40
|
+
}
|
|
41
|
+
function renderTemplateInContext(template, context, state) {
|
|
42
|
+
return renderTokens(parseTemplate(template), context, template, state);
|
|
43
|
+
}
|
|
44
|
+
function parseTemplate(template) {
|
|
45
|
+
const root = [];
|
|
46
|
+
const stack = [];
|
|
47
|
+
let tokens = root;
|
|
48
|
+
let index = 0;
|
|
49
|
+
while (index < template.length) {
|
|
50
|
+
const open = template.indexOf("{{", index);
|
|
51
|
+
if (open === -1) {
|
|
52
|
+
appendText(tokens, template.slice(index), index);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
appendText(tokens, template.slice(index, open), index);
|
|
56
|
+
const parsed = parseTag(template, open);
|
|
57
|
+
const standalone = getStandalone(template, open, parsed.end, parsed.kind);
|
|
58
|
+
if (standalone !== undefined) {
|
|
59
|
+
trimTextAfter(tokens, standalone.lineStart);
|
|
60
|
+
}
|
|
61
|
+
if (parsed.kind === "comment") {
|
|
62
|
+
index = standalone?.nextIndex ?? parsed.end;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (parsed.kind === "delimiter") {
|
|
66
|
+
throw new Error("Custom delimiters are not supported");
|
|
67
|
+
}
|
|
68
|
+
if (parsed.kind === "section" || parsed.kind === "inverted") {
|
|
69
|
+
const token = {
|
|
70
|
+
type: parsed.kind,
|
|
71
|
+
name: parsed.name,
|
|
72
|
+
children: [],
|
|
73
|
+
rawStart: parsed.end,
|
|
74
|
+
rawEnd: standalone?.lineStart ?? open
|
|
75
|
+
};
|
|
76
|
+
tokens.push(token);
|
|
77
|
+
stack.push({ token, parent: tokens });
|
|
78
|
+
tokens = token.children;
|
|
79
|
+
index = standalone?.nextIndex ?? parsed.end;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (parsed.kind === "partial") {
|
|
83
|
+
tokens.push({
|
|
84
|
+
type: "partial",
|
|
85
|
+
name: parsed.name,
|
|
86
|
+
indent: standalone === undefined ? "" : template.slice(standalone.lineStart, open)
|
|
87
|
+
});
|
|
88
|
+
index = standalone?.nextIndex ?? parsed.end;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (parsed.kind === "close") {
|
|
92
|
+
const frame = stack.pop();
|
|
93
|
+
if (frame === undefined) {
|
|
94
|
+
throw new Error(`Closing unopened section "${parsed.name}"`);
|
|
95
|
+
}
|
|
96
|
+
if (frame.token.name !== parsed.name) {
|
|
97
|
+
throw new Error(`Unclosed section "${frame.token.name}" before closing "${parsed.name}"`);
|
|
98
|
+
}
|
|
99
|
+
frame.token.rawEnd = open;
|
|
100
|
+
tokens = frame.parent;
|
|
101
|
+
index = standalone?.nextIndex ?? parsed.end;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
tokens.push({ type: parsed.kind, name: parsed.name, raw: template.slice(open, parsed.end) });
|
|
105
|
+
index = parsed.end;
|
|
106
|
+
}
|
|
107
|
+
const frame = stack.pop();
|
|
108
|
+
if (frame !== undefined) {
|
|
109
|
+
throw new Error(`Unclosed section "${frame.token.name}"`);
|
|
110
|
+
}
|
|
111
|
+
return root;
|
|
112
|
+
}
|
|
113
|
+
function parseTag(template, open) {
|
|
114
|
+
if (template.startsWith("{{{", open)) {
|
|
115
|
+
const close = template.indexOf("}}}", open + 3);
|
|
116
|
+
if (close === -1) {
|
|
117
|
+
throw new Error("Unclosed unescaped tag");
|
|
118
|
+
}
|
|
119
|
+
return { kind: "unescaped", name: template.slice(open + 3, close).trim(), end: close + 3 };
|
|
120
|
+
}
|
|
121
|
+
const close = template.indexOf("}}", open + 2);
|
|
122
|
+
if (close === -1) {
|
|
123
|
+
throw new Error("Unclosed tag");
|
|
124
|
+
}
|
|
125
|
+
const raw = template.slice(open + 2, close).trim();
|
|
126
|
+
const sigil = raw[0];
|
|
127
|
+
const name = sigil === undefined ? "" : raw.slice(1).trim();
|
|
128
|
+
const end = close + 2;
|
|
129
|
+
if (sigil === "#")
|
|
130
|
+
return { kind: "section", name, end };
|
|
131
|
+
if (sigil === "^")
|
|
132
|
+
return { kind: "inverted", name, end };
|
|
133
|
+
if (sigil === "/")
|
|
134
|
+
return { kind: "close", name, end };
|
|
135
|
+
if (sigil === "!")
|
|
136
|
+
return { kind: "comment", name, end };
|
|
137
|
+
if (sigil === "&")
|
|
138
|
+
return { kind: "unescaped", name, end };
|
|
139
|
+
if (sigil === ">")
|
|
140
|
+
return { kind: "partial", name, end };
|
|
141
|
+
if (sigil === "=" && raw.endsWith("="))
|
|
142
|
+
return { kind: "delimiter", name, end };
|
|
143
|
+
return { kind: "name", name: raw, end };
|
|
144
|
+
}
|
|
145
|
+
function getStandalone(template, tagStart, tagEnd, kind) {
|
|
146
|
+
if (!["section", "inverted", "close", "comment", "partial", "delimiter"].includes(kind)) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
const lineStart = template.lastIndexOf("\n", tagStart - 1) + 1;
|
|
150
|
+
if (!isWhitespace(template.slice(lineStart, tagStart))) {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
let cursor = tagEnd;
|
|
154
|
+
while (cursor < template.length && (template[cursor] === " " || template[cursor] === "\t")) {
|
|
155
|
+
cursor += 1;
|
|
156
|
+
}
|
|
157
|
+
if (template.startsWith("\r\n", cursor)) {
|
|
158
|
+
return { lineStart, nextIndex: cursor + 2 };
|
|
159
|
+
}
|
|
160
|
+
if (template[cursor] === "\n") {
|
|
161
|
+
return { lineStart, nextIndex: cursor + 1 };
|
|
162
|
+
}
|
|
163
|
+
if (cursor === template.length) {
|
|
164
|
+
return { lineStart, nextIndex: cursor };
|
|
165
|
+
}
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
function renderTokens(tokens, context, template, state) {
|
|
169
|
+
let output = "";
|
|
170
|
+
for (const token of tokens) {
|
|
171
|
+
switch (token.type) {
|
|
172
|
+
case "text":
|
|
173
|
+
output += token.value;
|
|
174
|
+
continue;
|
|
175
|
+
case "name":
|
|
176
|
+
case "unescaped": {
|
|
177
|
+
const result = lookup(context, token.name);
|
|
178
|
+
if (!result.hit || result.value == null) {
|
|
179
|
+
if (state.validate) {
|
|
180
|
+
throw new Error(`Template variable "${token.name}" not found.`);
|
|
181
|
+
}
|
|
182
|
+
if (state.preserveMissing) {
|
|
183
|
+
output += token.raw;
|
|
184
|
+
}
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const rendered = String(result.value);
|
|
188
|
+
output += token.type === "name" ? state.escape(rendered) : rendered;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
case "partial": {
|
|
192
|
+
if (!Object.hasOwn(state.partials, token.name)) {
|
|
193
|
+
throw new Error(`Partial "${token.name}" not found.`);
|
|
194
|
+
}
|
|
195
|
+
if (state.partialStack.includes(token.name)) {
|
|
196
|
+
throw new Error(`Circular partial reference detected: ${[...state.partialStack, token.name].join(" -> ")}.`);
|
|
197
|
+
}
|
|
198
|
+
if (state.partialStack.length >= MAX_PARTIAL_DEPTH) {
|
|
199
|
+
throw new Error(`Maximum partial depth exceeded (${MAX_PARTIAL_DEPTH}).`);
|
|
200
|
+
}
|
|
201
|
+
const partial = indentPartial(state.partials[token.name], token.indent);
|
|
202
|
+
output += renderTokens(parseTemplate(partial), context, partial, {
|
|
203
|
+
...state,
|
|
204
|
+
partialStack: [...state.partialStack, token.name]
|
|
205
|
+
});
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
case "inverted": {
|
|
209
|
+
const result = lookup(context, token.name);
|
|
210
|
+
if (!result.hit && state.validate) {
|
|
211
|
+
throw new Error(`Template variable "${token.name}" not found.`);
|
|
212
|
+
}
|
|
213
|
+
const value = result.value;
|
|
214
|
+
if (!value || (Array.isArray(value) && value.length === 0)) {
|
|
215
|
+
output += renderTokens(token.children, context, template, state);
|
|
216
|
+
}
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
case "section": {
|
|
220
|
+
const result = lookup(context, token.name);
|
|
221
|
+
if (!result.hit && state.validate) {
|
|
222
|
+
throw new Error(`Template variable "${token.name}" not found.`);
|
|
223
|
+
}
|
|
224
|
+
const value = result.value;
|
|
225
|
+
if (!value) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (Array.isArray(value)) {
|
|
229
|
+
for (const item of value) {
|
|
230
|
+
output += renderTokens(token.children, pushContext(context, item), template, state);
|
|
231
|
+
}
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (typeof value === "function") {
|
|
235
|
+
const raw = template.slice(token.rawStart, token.rawEnd);
|
|
236
|
+
const rendered = value.call(context.view, raw, (nextTemplate) => renderTemplateInContext(nextTemplate, context, state));
|
|
237
|
+
if (rendered != null) {
|
|
238
|
+
output += String(rendered);
|
|
239
|
+
}
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (typeof value === "object" || typeof value === "string" || typeof value === "number") {
|
|
243
|
+
output += renderTokens(token.children, pushContext(context, value), template, state);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
output += renderTokens(token.children, context, template, state);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return output;
|
|
251
|
+
}
|
|
252
|
+
function lookup(context, name) {
|
|
253
|
+
if (name === ".") {
|
|
254
|
+
return { hit: true, value: callLambda(context.view, context.view) };
|
|
255
|
+
}
|
|
256
|
+
let cursor = context;
|
|
257
|
+
while (cursor !== undefined) {
|
|
258
|
+
const result = name.includes(".")
|
|
259
|
+
? lookupDotted(cursor.view, name)
|
|
260
|
+
: lookupName(cursor.view, name);
|
|
261
|
+
if (result.hit) {
|
|
262
|
+
return { hit: true, value: callLambda(result.value, cursor.view) };
|
|
263
|
+
}
|
|
264
|
+
cursor = cursor.parent;
|
|
265
|
+
}
|
|
266
|
+
return { hit: false, value: undefined };
|
|
267
|
+
}
|
|
268
|
+
function collectPartialNames(tokens, names) {
|
|
269
|
+
for (const token of tokens) {
|
|
270
|
+
if (token.type === "partial") {
|
|
271
|
+
names.add(token.name);
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
if (token.type === "section" || token.type === "inverted") {
|
|
275
|
+
collectPartialNames(token.children, names);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function validateVariables(tokens, context) {
|
|
280
|
+
for (const token of tokens) {
|
|
281
|
+
if (token.type === "text" || token.type === "partial") {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (token.type === "name" || token.type === "unescaped") {
|
|
285
|
+
if (!lookup(context, token.name).hit) {
|
|
286
|
+
throw new Error(`Template variable "${token.name}" not found.`);
|
|
287
|
+
}
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (token.type !== "section" && token.type !== "inverted") {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
const result = lookup(context, token.name);
|
|
294
|
+
if (!result.hit) {
|
|
295
|
+
throw new Error(`Template variable "${token.name}" not found.`);
|
|
296
|
+
}
|
|
297
|
+
if (Array.isArray(result.value) && result.value.length > 0) {
|
|
298
|
+
for (const item of result.value) {
|
|
299
|
+
validateVariables(token.children, pushContext(context, item));
|
|
300
|
+
}
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (typeof result.value === "object" && result.value !== null ||
|
|
304
|
+
typeof result.value === "string" ||
|
|
305
|
+
typeof result.value === "number") {
|
|
306
|
+
validateVariables(token.children, pushContext(context, result.value));
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
validateVariables(token.children, context);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function validatePartialReferences(tokens, partials, partialStack) {
|
|
313
|
+
for (const token of tokens) {
|
|
314
|
+
if (token.type === "section" || token.type === "inverted") {
|
|
315
|
+
validatePartialReferences(token.children, partials, partialStack);
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
if (token.type !== "partial") {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (!Object.hasOwn(partials, token.name)) {
|
|
322
|
+
throw new Error(`Partial "${token.name}" not found.`);
|
|
323
|
+
}
|
|
324
|
+
if (partialStack.includes(token.name)) {
|
|
325
|
+
throw new Error(`Circular partial reference detected: ${[...partialStack, token.name].join(" -> ")}.`);
|
|
326
|
+
}
|
|
327
|
+
if (partialStack.length >= MAX_PARTIAL_DEPTH) {
|
|
328
|
+
throw new Error(`Maximum partial depth exceeded (${MAX_PARTIAL_DEPTH}).`);
|
|
329
|
+
}
|
|
330
|
+
validatePartialReferences(parseTemplate(partials[token.name]), partials, [
|
|
331
|
+
...partialStack,
|
|
332
|
+
token.name
|
|
333
|
+
]);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function indentPartial(partial, indent) {
|
|
337
|
+
if (indent === "") {
|
|
338
|
+
return partial;
|
|
339
|
+
}
|
|
340
|
+
return partial
|
|
341
|
+
.split("\n")
|
|
342
|
+
.map((line) => (line === "" ? "" : `${indent}${line}`))
|
|
343
|
+
.join("\n");
|
|
344
|
+
}
|
|
345
|
+
function expandTemplatePartials(template, partials, partialStack) {
|
|
346
|
+
let output = "";
|
|
347
|
+
let index = 0;
|
|
348
|
+
while (index < template.length) {
|
|
349
|
+
const open = template.indexOf("{{", index);
|
|
350
|
+
if (open === -1) {
|
|
351
|
+
output += template.slice(index);
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
const parsed = parseTag(template, open);
|
|
355
|
+
if (parsed.kind !== "partial") {
|
|
356
|
+
output += template.slice(index, parsed.end);
|
|
357
|
+
index = parsed.end;
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (!Object.hasOwn(partials, parsed.name)) {
|
|
361
|
+
throw new Error(`Partial "${parsed.name}" not found.`);
|
|
362
|
+
}
|
|
363
|
+
if (partialStack.includes(parsed.name)) {
|
|
364
|
+
throw new Error(`Circular partial reference detected: ${[...partialStack, parsed.name].join(" -> ")}.`);
|
|
365
|
+
}
|
|
366
|
+
if (partialStack.length >= MAX_PARTIAL_DEPTH) {
|
|
367
|
+
throw new Error(`Maximum partial depth exceeded (${MAX_PARTIAL_DEPTH}).`);
|
|
368
|
+
}
|
|
369
|
+
const standalone = getStandalone(template, open, parsed.end, parsed.kind);
|
|
370
|
+
const beforePartial = standalone === undefined
|
|
371
|
+
? template.slice(index, open)
|
|
372
|
+
: template.slice(index, standalone.lineStart);
|
|
373
|
+
const indent = standalone === undefined ? "" : template.slice(standalone.lineStart, open);
|
|
374
|
+
const partial = indentPartial(partials[parsed.name], indent);
|
|
375
|
+
output +=
|
|
376
|
+
beforePartial + expandTemplatePartials(partial, partials, [...partialStack, parsed.name]);
|
|
377
|
+
index = standalone?.nextIndex ?? parsed.end;
|
|
378
|
+
}
|
|
379
|
+
return output;
|
|
380
|
+
}
|
|
381
|
+
function lookupName(view, name) {
|
|
382
|
+
if (!isPropertyContainer(view) || !hasProperty(view, name)) {
|
|
383
|
+
return { hit: false, value: undefined };
|
|
384
|
+
}
|
|
385
|
+
return { hit: true, value: view[name] };
|
|
386
|
+
}
|
|
387
|
+
function lookupDotted(view, name) {
|
|
388
|
+
const parts = name.split(".");
|
|
389
|
+
let value = view;
|
|
390
|
+
for (const part of parts) {
|
|
391
|
+
if (!isPropertyContainer(value) || !hasProperty(value, part)) {
|
|
392
|
+
return { hit: false, value: undefined };
|
|
393
|
+
}
|
|
394
|
+
value = Object(value)[part];
|
|
395
|
+
}
|
|
396
|
+
return { hit: true, value };
|
|
397
|
+
}
|
|
398
|
+
function callLambda(value, view) {
|
|
399
|
+
return typeof value === "function" ? value.call(view) : value;
|
|
400
|
+
}
|
|
401
|
+
function pushContext(parent, view) {
|
|
402
|
+
return { view, parent };
|
|
403
|
+
}
|
|
404
|
+
function appendText(tokens, value, start) {
|
|
405
|
+
if (value === "") {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const previous = tokens[tokens.length - 1];
|
|
409
|
+
if (previous?.type === "text") {
|
|
410
|
+
previous.value += value;
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
tokens.push({ type: "text", value, start });
|
|
414
|
+
}
|
|
415
|
+
function trimTextAfter(tokens, lineStart) {
|
|
416
|
+
const previous = tokens[tokens.length - 1];
|
|
417
|
+
if (previous?.type !== "text") {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const keep = Math.max(0, lineStart - previous.start);
|
|
421
|
+
previous.value = previous.value.slice(0, keep);
|
|
422
|
+
if (previous.value === "") {
|
|
423
|
+
tokens.pop();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function escapeHtml(value) {
|
|
427
|
+
return value.replace(/[&<>"'`=/]/g, (char) => HTML_ESCAPE[char] ?? char);
|
|
428
|
+
}
|
|
429
|
+
function isWhitespace(value) {
|
|
430
|
+
return value.trim() === "";
|
|
431
|
+
}
|
|
432
|
+
function isPropertyContainer(value) {
|
|
433
|
+
return (typeof value === "object" && value !== null) || typeof value === "function";
|
|
434
|
+
}
|
|
435
|
+
function hasProperty(value, key) {
|
|
436
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
437
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const text: {
|
|
2
|
+
readonly intro: (content: string) => string;
|
|
3
|
+
readonly heading: (content: string) => string;
|
|
4
|
+
readonly section: (content: string) => string;
|
|
5
|
+
readonly sectionHeader: (content: string) => string;
|
|
6
|
+
readonly command: (content: string) => string;
|
|
7
|
+
readonly argument: (content: string) => string;
|
|
8
|
+
readonly option: (content: string) => string;
|
|
9
|
+
readonly example: (content: string) => string;
|
|
10
|
+
readonly usageCommand: (content: string) => string;
|
|
11
|
+
readonly link: (content: string) => string;
|
|
12
|
+
readonly muted: (content: string) => string;
|
|
13
|
+
readonly error: (content: string) => string;
|
|
14
|
+
readonly badge: (content: string) => string;
|
|
15
|
+
readonly selectLabel: (label: string, detail?: string) => string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { color } from "./color.js";
|
|
2
|
+
import { resolveOutputFormat } from "../internal/output-format.js";
|
|
3
|
+
import { getTheme } from "../internal/theme-detect.js";
|
|
4
|
+
import { typography } from "../tokens/typography.js";
|
|
5
|
+
function renderMarkdownInline(content) {
|
|
6
|
+
return content.replaceAll("\r\n", " ").replaceAll("\n", " ").replaceAll("\r", " ");
|
|
7
|
+
}
|
|
8
|
+
function renderMarkdownCode(content) {
|
|
9
|
+
const value = renderMarkdownInline(content);
|
|
10
|
+
let longestRun = 0;
|
|
11
|
+
let currentRun = 0;
|
|
12
|
+
for (const char of value) {
|
|
13
|
+
if (char === "`") {
|
|
14
|
+
currentRun += 1;
|
|
15
|
+
longestRun = Math.max(longestRun, currentRun);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
currentRun = 0;
|
|
19
|
+
}
|
|
20
|
+
const delimiter = "`".repeat(longestRun + 1);
|
|
21
|
+
const paddedValue = value.startsWith("`") || value.endsWith("`") ? ` ${value} ` : value;
|
|
22
|
+
return `${delimiter}${paddedValue}${delimiter}`;
|
|
23
|
+
}
|
|
24
|
+
function renderMarkdownLink(content) {
|
|
25
|
+
const value = renderMarkdownInline(content);
|
|
26
|
+
const label = value.replaceAll("\\", "\\\\").replaceAll("[", "\\[").replaceAll("]", "\\]");
|
|
27
|
+
const url = value.replaceAll("\\", "\\\\").replaceAll("(", "\\(").replaceAll(")", "\\)");
|
|
28
|
+
return `[${label}](${url})`;
|
|
29
|
+
}
|
|
30
|
+
export const text = {
|
|
31
|
+
intro(content) {
|
|
32
|
+
const format = resolveOutputFormat();
|
|
33
|
+
if (format === "json")
|
|
34
|
+
return content;
|
|
35
|
+
if (format === "markdown")
|
|
36
|
+
return `**${content}**`;
|
|
37
|
+
return getTheme().intro(content);
|
|
38
|
+
},
|
|
39
|
+
heading(content) {
|
|
40
|
+
const format = resolveOutputFormat();
|
|
41
|
+
if (format === "json")
|
|
42
|
+
return content;
|
|
43
|
+
if (format === "markdown")
|
|
44
|
+
return `## ${content}`;
|
|
45
|
+
return getTheme().header(content);
|
|
46
|
+
},
|
|
47
|
+
section(content) {
|
|
48
|
+
const format = resolveOutputFormat();
|
|
49
|
+
if (format === "json")
|
|
50
|
+
return content;
|
|
51
|
+
if (format === "markdown")
|
|
52
|
+
return `**${content}**`;
|
|
53
|
+
return typography.bold(content);
|
|
54
|
+
},
|
|
55
|
+
sectionHeader(content) {
|
|
56
|
+
const format = resolveOutputFormat();
|
|
57
|
+
if (format === "json")
|
|
58
|
+
return content;
|
|
59
|
+
if (format === "markdown")
|
|
60
|
+
return `## ${content}`;
|
|
61
|
+
return typography.bold(content.toUpperCase());
|
|
62
|
+
},
|
|
63
|
+
command(content) {
|
|
64
|
+
const format = resolveOutputFormat();
|
|
65
|
+
if (format === "json")
|
|
66
|
+
return content;
|
|
67
|
+
if (format === "markdown")
|
|
68
|
+
return renderMarkdownCode(content);
|
|
69
|
+
return getTheme().accent(content);
|
|
70
|
+
},
|
|
71
|
+
argument(content) {
|
|
72
|
+
const format = resolveOutputFormat();
|
|
73
|
+
if (format === "json")
|
|
74
|
+
return content;
|
|
75
|
+
if (format === "markdown")
|
|
76
|
+
return `<${content}>`;
|
|
77
|
+
return getTheme().muted(content);
|
|
78
|
+
},
|
|
79
|
+
option(content) {
|
|
80
|
+
const format = resolveOutputFormat();
|
|
81
|
+
if (format === "json")
|
|
82
|
+
return content;
|
|
83
|
+
if (format === "markdown")
|
|
84
|
+
return renderMarkdownCode(content);
|
|
85
|
+
return color.yellow(content);
|
|
86
|
+
},
|
|
87
|
+
example(content) {
|
|
88
|
+
const format = resolveOutputFormat();
|
|
89
|
+
if (format === "json")
|
|
90
|
+
return content;
|
|
91
|
+
if (format === "markdown")
|
|
92
|
+
return renderMarkdownCode(content);
|
|
93
|
+
return getTheme().muted(content);
|
|
94
|
+
},
|
|
95
|
+
usageCommand(content) {
|
|
96
|
+
const format = resolveOutputFormat();
|
|
97
|
+
if (format === "json")
|
|
98
|
+
return content;
|
|
99
|
+
if (format === "markdown")
|
|
100
|
+
return renderMarkdownCode(content);
|
|
101
|
+
return color.green(content);
|
|
102
|
+
},
|
|
103
|
+
link(content) {
|
|
104
|
+
const format = resolveOutputFormat();
|
|
105
|
+
if (format === "json")
|
|
106
|
+
return content;
|
|
107
|
+
if (format === "markdown")
|
|
108
|
+
return renderMarkdownLink(content);
|
|
109
|
+
return getTheme().accent(content);
|
|
110
|
+
},
|
|
111
|
+
muted(content) {
|
|
112
|
+
const format = resolveOutputFormat();
|
|
113
|
+
if (format === "json")
|
|
114
|
+
return content;
|
|
115
|
+
if (format === "markdown")
|
|
116
|
+
return `*${content}*`;
|
|
117
|
+
return getTheme().muted(content);
|
|
118
|
+
},
|
|
119
|
+
error(content) {
|
|
120
|
+
const format = resolveOutputFormat();
|
|
121
|
+
if (format === "json")
|
|
122
|
+
return content;
|
|
123
|
+
if (format === "markdown")
|
|
124
|
+
return `**${content}**`;
|
|
125
|
+
return getTheme().error(content);
|
|
126
|
+
},
|
|
127
|
+
badge(content) {
|
|
128
|
+
const format = resolveOutputFormat();
|
|
129
|
+
if (format === "json")
|
|
130
|
+
return content;
|
|
131
|
+
if (format === "markdown")
|
|
132
|
+
return `[${content}]`;
|
|
133
|
+
return getTheme().badge(content);
|
|
134
|
+
},
|
|
135
|
+
selectLabel(label, detail) {
|
|
136
|
+
if (!detail) {
|
|
137
|
+
return label;
|
|
138
|
+
}
|
|
139
|
+
const format = resolveOutputFormat();
|
|
140
|
+
if (format !== "terminal") {
|
|
141
|
+
return `${label} — ${detail}`;
|
|
142
|
+
}
|
|
143
|
+
return `${label} ${typography.dim("—")} ${typography.dim(detail)}`;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CellStyle } from "./types.js";
|
|
2
|
+
export interface StyledSegment {
|
|
3
|
+
text: string;
|
|
4
|
+
style: CellStyle;
|
|
5
|
+
}
|
|
6
|
+
export interface StyledLine {
|
|
7
|
+
segments: StyledSegment[];
|
|
8
|
+
}
|
|
9
|
+
export declare function hasAnsi(text: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Parse a block of text that may contain ANSI SGR escape codes into a sequence of
|
|
12
|
+
* logical lines split on "\n". Each line is a list of styled segments: contiguous
|
|
13
|
+
* printable runs of characters sharing the same style.
|
|
14
|
+
*
|
|
15
|
+
* Common cursor-affecting line controls are rendered into their visible result.
|
|
16
|
+
* `baseStyle` is used as the initial style and as the restore target for SGR reset / default color.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseAnsi(text: string, baseStyle?: CellStyle): StyledLine[];
|