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,1190 @@
|
|
|
1
|
+
const INLINE_HTML_TAGS = new Set([
|
|
2
|
+
"a",
|
|
3
|
+
"abbr",
|
|
4
|
+
"address",
|
|
5
|
+
"article",
|
|
6
|
+
"aside",
|
|
7
|
+
"b",
|
|
8
|
+
"base",
|
|
9
|
+
"basefont",
|
|
10
|
+
"bdi",
|
|
11
|
+
"bdo",
|
|
12
|
+
"blockquote",
|
|
13
|
+
"body",
|
|
14
|
+
"br",
|
|
15
|
+
"button",
|
|
16
|
+
"caption",
|
|
17
|
+
"center",
|
|
18
|
+
"cite",
|
|
19
|
+
"code",
|
|
20
|
+
"col",
|
|
21
|
+
"colgroup",
|
|
22
|
+
"data",
|
|
23
|
+
"dd",
|
|
24
|
+
"del",
|
|
25
|
+
"details",
|
|
26
|
+
"dfn",
|
|
27
|
+
"dialog",
|
|
28
|
+
"div",
|
|
29
|
+
"dl",
|
|
30
|
+
"dt",
|
|
31
|
+
"em",
|
|
32
|
+
"fieldset",
|
|
33
|
+
"figcaption",
|
|
34
|
+
"figure",
|
|
35
|
+
"footer",
|
|
36
|
+
"form",
|
|
37
|
+
"h1",
|
|
38
|
+
"h2",
|
|
39
|
+
"h3",
|
|
40
|
+
"h4",
|
|
41
|
+
"h5",
|
|
42
|
+
"h6",
|
|
43
|
+
"head",
|
|
44
|
+
"header",
|
|
45
|
+
"hr",
|
|
46
|
+
"html",
|
|
47
|
+
"i",
|
|
48
|
+
"img",
|
|
49
|
+
"input",
|
|
50
|
+
"ins",
|
|
51
|
+
"kbd",
|
|
52
|
+
"label",
|
|
53
|
+
"legend",
|
|
54
|
+
"li",
|
|
55
|
+
"link",
|
|
56
|
+
"main",
|
|
57
|
+
"mark",
|
|
58
|
+
"menu",
|
|
59
|
+
"nav",
|
|
60
|
+
"ol",
|
|
61
|
+
"option",
|
|
62
|
+
"p",
|
|
63
|
+
"param",
|
|
64
|
+
"pre",
|
|
65
|
+
"q",
|
|
66
|
+
"rp",
|
|
67
|
+
"rt",
|
|
68
|
+
"rtc",
|
|
69
|
+
"ruby",
|
|
70
|
+
"s",
|
|
71
|
+
"samp",
|
|
72
|
+
"search",
|
|
73
|
+
"section",
|
|
74
|
+
"small",
|
|
75
|
+
"span",
|
|
76
|
+
"strong",
|
|
77
|
+
"sub",
|
|
78
|
+
"summary",
|
|
79
|
+
"sup",
|
|
80
|
+
"table",
|
|
81
|
+
"tbody",
|
|
82
|
+
"td",
|
|
83
|
+
"tfoot",
|
|
84
|
+
"th",
|
|
85
|
+
"thead",
|
|
86
|
+
"time",
|
|
87
|
+
"title",
|
|
88
|
+
"tr",
|
|
89
|
+
"u",
|
|
90
|
+
"ul",
|
|
91
|
+
"var",
|
|
92
|
+
"wbr"
|
|
93
|
+
]);
|
|
94
|
+
export function parseInline(raw, options = {}) {
|
|
95
|
+
const nodes = [];
|
|
96
|
+
const delimiters = [];
|
|
97
|
+
const footnoteLabels = options.footnoteLabels;
|
|
98
|
+
const allowLiteralAutolinks = options.allowLiteralAutolinks ?? true;
|
|
99
|
+
const offsets = options.offsets ?? createOffsetMap(raw, options.offset ?? 0);
|
|
100
|
+
let textBuffer = "";
|
|
101
|
+
let textStart = 0;
|
|
102
|
+
let index = 0;
|
|
103
|
+
const appendText = (value, start) => {
|
|
104
|
+
if (textBuffer.length === 0) {
|
|
105
|
+
textStart = start;
|
|
106
|
+
}
|
|
107
|
+
textBuffer += value;
|
|
108
|
+
};
|
|
109
|
+
const flushText = (end = index) => {
|
|
110
|
+
if (textBuffer.length === 0) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
nodes.push(createTextNode(textBuffer, createRange(offsets, textStart, end)));
|
|
114
|
+
textBuffer = "";
|
|
115
|
+
};
|
|
116
|
+
while (index < raw.length) {
|
|
117
|
+
const char = raw[index];
|
|
118
|
+
if (char === "\\" && index + 1 < raw.length && isEscapable(raw[index + 1])) {
|
|
119
|
+
appendText(raw[index + 1], index);
|
|
120
|
+
index += 2;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (char === "`") {
|
|
124
|
+
const code = parseInlineCode(raw, index, offsets);
|
|
125
|
+
if (code !== null) {
|
|
126
|
+
flushText();
|
|
127
|
+
nodes.push(code.node);
|
|
128
|
+
index = code.end;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (char === "!" && index + 1 < raw.length && raw[index + 1] === "[") {
|
|
133
|
+
const image = parseImage(raw, index, offsets);
|
|
134
|
+
if (image !== null) {
|
|
135
|
+
flushText();
|
|
136
|
+
nodes.push(image.node);
|
|
137
|
+
index = image.end;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (char === "[") {
|
|
142
|
+
const footnoteReference = parseFootnoteReference(raw, index, footnoteLabels, offsets);
|
|
143
|
+
if (footnoteReference !== null) {
|
|
144
|
+
flushText();
|
|
145
|
+
nodes.push(footnoteReference.node);
|
|
146
|
+
index = footnoteReference.end;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const link = parseLink(raw, index, footnoteLabels, offsets);
|
|
150
|
+
if (link !== null) {
|
|
151
|
+
flushText();
|
|
152
|
+
nodes.push(link.node);
|
|
153
|
+
index = link.end;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (char === "<") {
|
|
158
|
+
const autolink = parseAutolink(raw, index, offsets);
|
|
159
|
+
if (autolink !== null) {
|
|
160
|
+
flushText();
|
|
161
|
+
nodes.push(autolink.node);
|
|
162
|
+
index = autolink.end;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const html = parseInlineHtmlTag(raw, index, offsets);
|
|
166
|
+
if (html !== null) {
|
|
167
|
+
flushText();
|
|
168
|
+
nodes.push(html.node);
|
|
169
|
+
index = html.end;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (char === "\n") {
|
|
174
|
+
if (textBuffer.endsWith("\\")) {
|
|
175
|
+
textBuffer = textBuffer.slice(0, -1);
|
|
176
|
+
flushText(index - 1);
|
|
177
|
+
nodes.push(withRange({ type: "break" }, createRange(offsets, index, index + 1)));
|
|
178
|
+
index += 1;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const trailingSpaceStart = findTrailingHardBreakSpaceStart(textBuffer);
|
|
182
|
+
if (trailingSpaceStart !== -1) {
|
|
183
|
+
const trailingSpaceCount = textBuffer.length - trailingSpaceStart;
|
|
184
|
+
textBuffer = textBuffer.slice(0, trailingSpaceStart);
|
|
185
|
+
flushText(index - trailingSpaceCount);
|
|
186
|
+
nodes.push(withRange({ type: "break" }, createRange(offsets, index, index + 1)));
|
|
187
|
+
index += 1;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (allowLiteralAutolinks) {
|
|
192
|
+
const literalAutolink = parseLiteralAutolink(raw, index, offsets);
|
|
193
|
+
if (literalAutolink !== null) {
|
|
194
|
+
flushText();
|
|
195
|
+
nodes.push(literalAutolink.node);
|
|
196
|
+
index = literalAutolink.end;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (char === "*" || char === "_" || char === "~") {
|
|
201
|
+
const delimiter = parseDelimiter(raw, index, char);
|
|
202
|
+
if (delimiter !== null) {
|
|
203
|
+
flushText();
|
|
204
|
+
const node = createTextNode(raw.slice(index, index + delimiter.length), {
|
|
205
|
+
start: offsets[index] ?? 0,
|
|
206
|
+
end: offsets[index + delimiter.length] ?? offsets[offsets.length - 1] ?? 0
|
|
207
|
+
});
|
|
208
|
+
nodes.push(node);
|
|
209
|
+
delimiters.push({
|
|
210
|
+
...delimiter,
|
|
211
|
+
node,
|
|
212
|
+
position: nodes.length - 1
|
|
213
|
+
});
|
|
214
|
+
index += delimiter.length;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
appendText(char, index);
|
|
219
|
+
index += 1;
|
|
220
|
+
}
|
|
221
|
+
flushText();
|
|
222
|
+
if (delimiters.length === 0) {
|
|
223
|
+
return normalizeInlineNodes(nodes);
|
|
224
|
+
}
|
|
225
|
+
const pairs = matchDelimiterPairs(delimiters);
|
|
226
|
+
if (pairs.length === 0) {
|
|
227
|
+
return normalizeInlineNodes(nodes);
|
|
228
|
+
}
|
|
229
|
+
return buildInlineNodes(nodes, delimiters, pairs);
|
|
230
|
+
}
|
|
231
|
+
function parseDelimiter(input, start, marker) {
|
|
232
|
+
const length = readRunLength(input, start, marker);
|
|
233
|
+
const before = start === 0 ? null : input[start - 1];
|
|
234
|
+
const after = start + length >= input.length ? null : input[start + length];
|
|
235
|
+
const leftFlanking = !isDelimiterWhitespace(after) &&
|
|
236
|
+
(!isDelimiterPunctuation(after) ||
|
|
237
|
+
isDelimiterWhitespace(before) ||
|
|
238
|
+
isDelimiterPunctuation(before));
|
|
239
|
+
const rightFlanking = !isDelimiterWhitespace(before) &&
|
|
240
|
+
(!isDelimiterPunctuation(before) ||
|
|
241
|
+
isDelimiterWhitespace(after) ||
|
|
242
|
+
isDelimiterPunctuation(after));
|
|
243
|
+
if (marker === "~") {
|
|
244
|
+
if (length < 2) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
marker,
|
|
249
|
+
length,
|
|
250
|
+
canOpen: leftFlanking,
|
|
251
|
+
canClose: rightFlanking
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
if (marker === "_") {
|
|
255
|
+
return {
|
|
256
|
+
marker,
|
|
257
|
+
length,
|
|
258
|
+
canOpen: leftFlanking && (!rightFlanking || isDelimiterPunctuation(before)),
|
|
259
|
+
canClose: rightFlanking && (!leftFlanking || isDelimiterPunctuation(after))
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
marker,
|
|
264
|
+
length,
|
|
265
|
+
canOpen: leftFlanking,
|
|
266
|
+
canClose: rightFlanking
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function matchDelimiterPairs(delimiters) {
|
|
270
|
+
const pairs = [];
|
|
271
|
+
const previous = delimiters.map((_, index) => index - 1);
|
|
272
|
+
const next = delimiters.map((_, index) => (index + 1 < delimiters.length ? index + 1 : -1));
|
|
273
|
+
const active = delimiters.map(() => true);
|
|
274
|
+
let sequence = 0;
|
|
275
|
+
let closerIndex = 0;
|
|
276
|
+
const unlinkDelimiter = (index) => {
|
|
277
|
+
if (!active[index]) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const previousIndex = previous[index];
|
|
281
|
+
const nextIndex = next[index];
|
|
282
|
+
if (previousIndex !== -1) {
|
|
283
|
+
next[previousIndex] = nextIndex;
|
|
284
|
+
}
|
|
285
|
+
if (nextIndex !== -1) {
|
|
286
|
+
previous[nextIndex] = previousIndex;
|
|
287
|
+
}
|
|
288
|
+
active[index] = false;
|
|
289
|
+
};
|
|
290
|
+
const pruneDelimiter = (index) => {
|
|
291
|
+
const delimiter = delimiters[index];
|
|
292
|
+
if (delimiter.length === 0) {
|
|
293
|
+
unlinkDelimiter(index);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (delimiter.marker === "~" && delimiter.length < 2) {
|
|
297
|
+
delimiter.canOpen = false;
|
|
298
|
+
delimiter.canClose = false;
|
|
299
|
+
unlinkDelimiter(index);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
while (closerIndex !== -1) {
|
|
303
|
+
const closer = delimiters[closerIndex];
|
|
304
|
+
if (!closer.canClose || closer.length === 0) {
|
|
305
|
+
closerIndex = next[closerIndex];
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const openerIndex = findMatchingOpener(delimiters, previous, closerIndex);
|
|
309
|
+
if (openerIndex === null) {
|
|
310
|
+
const nextCloserIndex = next[closerIndex];
|
|
311
|
+
if (!closer.canOpen) {
|
|
312
|
+
unlinkDelimiter(closerIndex);
|
|
313
|
+
}
|
|
314
|
+
closerIndex = nextCloserIndex;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const opener = delimiters[openerIndex];
|
|
318
|
+
const pairLength = getPairLength(opener, closer);
|
|
319
|
+
if (pairLength === 0 || opener.position + 1 >= closer.position) {
|
|
320
|
+
closerIndex = next[closerIndex];
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
pairs.push({
|
|
324
|
+
opener,
|
|
325
|
+
closer,
|
|
326
|
+
kind: getPairKind(opener.marker, pairLength),
|
|
327
|
+
sequence
|
|
328
|
+
});
|
|
329
|
+
opener.length -= pairLength;
|
|
330
|
+
closer.length -= pairLength;
|
|
331
|
+
let trappedIndex = next[openerIndex];
|
|
332
|
+
while (trappedIndex !== -1 && trappedIndex !== closerIndex) {
|
|
333
|
+
const nextTrappedIndex = next[trappedIndex];
|
|
334
|
+
unlinkDelimiter(trappedIndex);
|
|
335
|
+
trappedIndex = nextTrappedIndex;
|
|
336
|
+
}
|
|
337
|
+
pruneDelimiter(openerIndex);
|
|
338
|
+
pruneDelimiter(closerIndex);
|
|
339
|
+
if (!active[closerIndex] || !closer.canClose || closer.length === 0) {
|
|
340
|
+
closerIndex = next[closerIndex];
|
|
341
|
+
}
|
|
342
|
+
sequence += 1;
|
|
343
|
+
}
|
|
344
|
+
return pairs;
|
|
345
|
+
}
|
|
346
|
+
function findMatchingOpener(delimiters, previous, closerIndex) {
|
|
347
|
+
const closer = delimiters[closerIndex];
|
|
348
|
+
let openerIndex = previous[closerIndex];
|
|
349
|
+
while (openerIndex !== -1) {
|
|
350
|
+
const opener = delimiters[openerIndex];
|
|
351
|
+
if (opener.marker === closer.marker &&
|
|
352
|
+
opener.canOpen &&
|
|
353
|
+
opener.length > 0 &&
|
|
354
|
+
!violatesMultipleOfThreeRule(opener, closer)) {
|
|
355
|
+
return openerIndex;
|
|
356
|
+
}
|
|
357
|
+
openerIndex = previous[openerIndex];
|
|
358
|
+
}
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
function violatesMultipleOfThreeRule(opener, closer) {
|
|
362
|
+
if (opener.marker === "~") {
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
if (!opener.canClose || !closer.canOpen) {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
return ((opener.length + closer.length) % 3 === 0 &&
|
|
369
|
+
(opener.length % 3 !== 0 || closer.length % 3 !== 0));
|
|
370
|
+
}
|
|
371
|
+
function getPairLength(opener, closer) {
|
|
372
|
+
if (opener.marker === "~") {
|
|
373
|
+
return opener.length >= 2 && closer.length >= 2 ? 2 : 0;
|
|
374
|
+
}
|
|
375
|
+
return opener.length >= 2 && closer.length >= 2 ? 2 : 1;
|
|
376
|
+
}
|
|
377
|
+
function getPairKind(marker, pairLength) {
|
|
378
|
+
if (marker === "~") {
|
|
379
|
+
return "strikethrough";
|
|
380
|
+
}
|
|
381
|
+
return pairLength === 2 ? "strong" : "emphasis";
|
|
382
|
+
}
|
|
383
|
+
function buildInlineNodes(nodes, delimiters, pairs) {
|
|
384
|
+
const delimiterEntries = new Map();
|
|
385
|
+
for (const delimiter of delimiters) {
|
|
386
|
+
delimiterEntries.set(delimiter.node, {
|
|
387
|
+
delimiter,
|
|
388
|
+
opens: [],
|
|
389
|
+
closes: []
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
for (const pair of pairs) {
|
|
393
|
+
delimiterEntries.get(pair.opener.node)?.opens.push(pair);
|
|
394
|
+
delimiterEntries.get(pair.closer.node)?.closes.push(pair);
|
|
395
|
+
}
|
|
396
|
+
const root = [];
|
|
397
|
+
const stack = [{ children: root }];
|
|
398
|
+
const appendNode = (node) => {
|
|
399
|
+
stack[stack.length - 1]?.children.push(node);
|
|
400
|
+
};
|
|
401
|
+
for (const node of nodes) {
|
|
402
|
+
if (node.type !== "text") {
|
|
403
|
+
appendNode(node);
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
const delimiterEntry = delimiterEntries.get(node);
|
|
407
|
+
if (delimiterEntry === undefined) {
|
|
408
|
+
appendNode(node);
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
delimiterEntry.closes.sort((left, right) => left.sequence - right.sequence);
|
|
412
|
+
for (const pair of delimiterEntry.closes) {
|
|
413
|
+
const current = stack[stack.length - 1];
|
|
414
|
+
if (current?.pair === pair) {
|
|
415
|
+
stack.pop();
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (delimiterEntry.delimiter.length > 0) {
|
|
419
|
+
appendNode(createTextNode(delimiterEntry.delimiter.marker.repeat(delimiterEntry.delimiter.length), node.range));
|
|
420
|
+
}
|
|
421
|
+
delimiterEntry.opens.sort((left, right) => right.sequence - left.sequence);
|
|
422
|
+
for (const pair of delimiterEntry.opens) {
|
|
423
|
+
const wrapper = withRange(createDelimiterNode(pair.kind), {
|
|
424
|
+
start: pair.opener.node.range?.start ?? pair.opener.position,
|
|
425
|
+
end: pair.closer.node.range?.end ?? pair.closer.position
|
|
426
|
+
});
|
|
427
|
+
appendNode(wrapper);
|
|
428
|
+
stack.push({ pair, children: wrapper.children });
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return normalizeInlineNodes(root);
|
|
432
|
+
}
|
|
433
|
+
function createDelimiterNode(kind) {
|
|
434
|
+
return { type: kind, children: [] };
|
|
435
|
+
}
|
|
436
|
+
function createTextNode(value, range) {
|
|
437
|
+
return range === undefined ? { type: "text", value } : withRange({ type: "text", value }, range);
|
|
438
|
+
}
|
|
439
|
+
function withRange(node, range) {
|
|
440
|
+
Object.defineProperty(node, "range", {
|
|
441
|
+
value: range,
|
|
442
|
+
enumerable: false,
|
|
443
|
+
configurable: true,
|
|
444
|
+
writable: true
|
|
445
|
+
});
|
|
446
|
+
return node;
|
|
447
|
+
}
|
|
448
|
+
function mergeRanges(left, right) {
|
|
449
|
+
if (left === undefined) {
|
|
450
|
+
return right;
|
|
451
|
+
}
|
|
452
|
+
if (right === undefined) {
|
|
453
|
+
return left;
|
|
454
|
+
}
|
|
455
|
+
return {
|
|
456
|
+
start: Math.min(left.start, right.start),
|
|
457
|
+
end: Math.max(left.end, right.end)
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
function normalizeInlineNodes(nodes) {
|
|
461
|
+
const normalized = [];
|
|
462
|
+
for (const node of nodes) {
|
|
463
|
+
const nextNode = normalizeInlineNode(node);
|
|
464
|
+
if (nextNode === null) {
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
const previousNode = normalized[normalized.length - 1];
|
|
468
|
+
if (previousNode?.type === "text" && nextNode.type === "text") {
|
|
469
|
+
previousNode.value += nextNode.value;
|
|
470
|
+
const range = mergeRanges(previousNode.range, nextNode.range);
|
|
471
|
+
if (range !== undefined) {
|
|
472
|
+
withRange(previousNode, range);
|
|
473
|
+
}
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
normalized.push(nextNode);
|
|
477
|
+
}
|
|
478
|
+
return normalized;
|
|
479
|
+
}
|
|
480
|
+
function normalizeInlineNode(node) {
|
|
481
|
+
if (node.type === "text") {
|
|
482
|
+
return node.value.length === 0 ? null : node;
|
|
483
|
+
}
|
|
484
|
+
if (node.type === "emphasis" ||
|
|
485
|
+
node.type === "strong" ||
|
|
486
|
+
node.type === "strikethrough" ||
|
|
487
|
+
node.type === "link") {
|
|
488
|
+
const nextNode = { ...node, children: normalizeInlineNodes(node.children) };
|
|
489
|
+
return node.range === undefined ? nextNode : withRange(nextNode, node.range);
|
|
490
|
+
}
|
|
491
|
+
return node;
|
|
492
|
+
}
|
|
493
|
+
function parseInlineCode(input, start, offsets) {
|
|
494
|
+
const fenceLength = readRunLength(input, start, "`");
|
|
495
|
+
let index = start + fenceLength;
|
|
496
|
+
while (index < input.length) {
|
|
497
|
+
if (input[index] !== "`") {
|
|
498
|
+
index += 1;
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
const closingFenceLength = readRunLength(input, index, "`");
|
|
502
|
+
if (closingFenceLength === fenceLength) {
|
|
503
|
+
const value = normalizeInlineCodeValue(input.slice(start + fenceLength, index));
|
|
504
|
+
return {
|
|
505
|
+
node: offsets === undefined
|
|
506
|
+
? {
|
|
507
|
+
type: "inlineCode",
|
|
508
|
+
value
|
|
509
|
+
}
|
|
510
|
+
: withRange({
|
|
511
|
+
type: "inlineCode",
|
|
512
|
+
value
|
|
513
|
+
}, createRange(offsets, start, index + fenceLength)),
|
|
514
|
+
end: index + fenceLength
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
index += closingFenceLength;
|
|
518
|
+
}
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
function normalizeInlineCodeValue(value) {
|
|
522
|
+
if (value.length >= 2 &&
|
|
523
|
+
value.startsWith(" ") &&
|
|
524
|
+
value.endsWith(" ") &&
|
|
525
|
+
(value[1] === "`" || value[value.length - 2] === "`") &&
|
|
526
|
+
value.trim().length > 0) {
|
|
527
|
+
return value.slice(1, -1);
|
|
528
|
+
}
|
|
529
|
+
return value;
|
|
530
|
+
}
|
|
531
|
+
function parseLink(input, start, footnoteLabels, offsets) {
|
|
532
|
+
const label = parseBracketedLabel(input, start);
|
|
533
|
+
if (label === null || label.end >= input.length || input[label.end] !== "(") {
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
const destination = parseLinkDestination(input, label.end);
|
|
537
|
+
if (destination === null) {
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
return {
|
|
541
|
+
node: withRange({
|
|
542
|
+
type: "link",
|
|
543
|
+
url: destination.url,
|
|
544
|
+
...(destination.title === undefined ? {} : { title: destination.title }),
|
|
545
|
+
children: parseInline(label.value, {
|
|
546
|
+
footnoteLabels,
|
|
547
|
+
allowLiteralAutolinks: false,
|
|
548
|
+
...(offsets === undefined
|
|
549
|
+
? {}
|
|
550
|
+
: { offsets: sliceOffsetMap(offsets, label.contentStart, label.end - 1) })
|
|
551
|
+
})
|
|
552
|
+
}, offsets === undefined
|
|
553
|
+
? { start, end: destination.end }
|
|
554
|
+
: createRange(offsets, start, destination.end)),
|
|
555
|
+
end: destination.end
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
function parseImage(input, start, offsets) {
|
|
559
|
+
const label = parseBracketedLabel(input, start + 1);
|
|
560
|
+
if (label === null || label.end >= input.length || input[label.end] !== "(") {
|
|
561
|
+
return null;
|
|
562
|
+
}
|
|
563
|
+
const destination = parseLinkDestination(input, label.end);
|
|
564
|
+
if (destination === null) {
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
return {
|
|
568
|
+
node: withRange({
|
|
569
|
+
type: "image",
|
|
570
|
+
url: destination.url,
|
|
571
|
+
alt: decodeEscapes(label.value),
|
|
572
|
+
...(destination.title === undefined ? {} : { title: destination.title })
|
|
573
|
+
}, offsets === undefined
|
|
574
|
+
? { start, end: destination.end }
|
|
575
|
+
: createRange(offsets, start, destination.end)),
|
|
576
|
+
end: destination.end
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
function parseBracketedLabel(input, start) {
|
|
580
|
+
if (start >= input.length || input[start] !== "[") {
|
|
581
|
+
return null;
|
|
582
|
+
}
|
|
583
|
+
let depth = 1;
|
|
584
|
+
let index = start + 1;
|
|
585
|
+
while (index < input.length) {
|
|
586
|
+
const char = input[index];
|
|
587
|
+
if (char === "\\" && index + 1 < input.length) {
|
|
588
|
+
index += 2;
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
if (char === "`") {
|
|
592
|
+
const code = parseInlineCode(input, index);
|
|
593
|
+
if (code !== null) {
|
|
594
|
+
index = code.end;
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
if (char === "[") {
|
|
599
|
+
depth += 1;
|
|
600
|
+
index += 1;
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (char === "]") {
|
|
604
|
+
depth -= 1;
|
|
605
|
+
if (depth === 0) {
|
|
606
|
+
return {
|
|
607
|
+
value: input.slice(start + 1, index),
|
|
608
|
+
contentStart: start + 1,
|
|
609
|
+
end: index + 1
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
index += 1;
|
|
614
|
+
}
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
function parseLinkDestination(input, openParenIndex) {
|
|
618
|
+
let depth = 1;
|
|
619
|
+
let quote = null;
|
|
620
|
+
let index = openParenIndex + 1;
|
|
621
|
+
while (index < input.length) {
|
|
622
|
+
const char = input[index];
|
|
623
|
+
if (quote !== null) {
|
|
624
|
+
if (char === "\\" && index + 1 < input.length) {
|
|
625
|
+
index += 2;
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
if (char === quote) {
|
|
629
|
+
quote = null;
|
|
630
|
+
}
|
|
631
|
+
index += 1;
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
if (char === "\\" && index + 1 < input.length && isEscapable(input[index + 1])) {
|
|
635
|
+
index += 2;
|
|
636
|
+
continue;
|
|
637
|
+
}
|
|
638
|
+
if (char === '"' || char === "'") {
|
|
639
|
+
quote = char;
|
|
640
|
+
index += 1;
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
if (char === "(") {
|
|
644
|
+
depth += 1;
|
|
645
|
+
index += 1;
|
|
646
|
+
continue;
|
|
647
|
+
}
|
|
648
|
+
if (char === ")") {
|
|
649
|
+
depth -= 1;
|
|
650
|
+
if (depth === 0) {
|
|
651
|
+
const content = input.slice(openParenIndex + 1, index);
|
|
652
|
+
const parsed = parseLinkDestinationContent(content);
|
|
653
|
+
return {
|
|
654
|
+
...parsed,
|
|
655
|
+
end: index + 1
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
index += 1;
|
|
660
|
+
}
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
function parseLinkDestinationContent(content) {
|
|
664
|
+
const trimmedEnd = trimAsciiWhitespaceEndIndex(content);
|
|
665
|
+
if (trimmedEnd === 0) {
|
|
666
|
+
return { url: "" };
|
|
667
|
+
}
|
|
668
|
+
const quote = content[trimmedEnd - 1];
|
|
669
|
+
if (quote === '"' || quote === "'") {
|
|
670
|
+
const titleStart = findTrailingQuotedSegmentStart(content, trimmedEnd, quote);
|
|
671
|
+
if (titleStart !== -1) {
|
|
672
|
+
let separatorStart = titleStart;
|
|
673
|
+
while (separatorStart > 0 && isAsciiWhitespace(content[separatorStart - 1])) {
|
|
674
|
+
separatorStart -= 1;
|
|
675
|
+
}
|
|
676
|
+
if (separatorStart < titleStart) {
|
|
677
|
+
return {
|
|
678
|
+
url: decodeEscapes(trimAsciiWhitespace(content.slice(0, separatorStart))),
|
|
679
|
+
title: decodeEscapes(content.slice(titleStart + 1, trimmedEnd - 1))
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
return { url: decodeEscapes(trimAsciiWhitespace(content.slice(0, trimmedEnd))) };
|
|
685
|
+
}
|
|
686
|
+
function findTrailingQuotedSegmentStart(content, end, quote) {
|
|
687
|
+
let index = end - 2;
|
|
688
|
+
while (index >= 0) {
|
|
689
|
+
if (content[index] === quote && !isEscaped(content, index)) {
|
|
690
|
+
return index;
|
|
691
|
+
}
|
|
692
|
+
index -= 1;
|
|
693
|
+
}
|
|
694
|
+
return -1;
|
|
695
|
+
}
|
|
696
|
+
function parseAutolink(input, start, offsets) {
|
|
697
|
+
let index = start + 1;
|
|
698
|
+
while (index < input.length && input[index] !== ">") {
|
|
699
|
+
const char = input[index];
|
|
700
|
+
if (char === "<" || char === "\n" || char === " " || char === "\t") {
|
|
701
|
+
return null;
|
|
702
|
+
}
|
|
703
|
+
index += 1;
|
|
704
|
+
}
|
|
705
|
+
if (index >= input.length || index === start + 1) {
|
|
706
|
+
return null;
|
|
707
|
+
}
|
|
708
|
+
const url = input.slice(start + 1, index);
|
|
709
|
+
if (!isAutolinkUrl(url)) {
|
|
710
|
+
return null;
|
|
711
|
+
}
|
|
712
|
+
return {
|
|
713
|
+
node: withRange({
|
|
714
|
+
type: "link",
|
|
715
|
+
url,
|
|
716
|
+
children: [
|
|
717
|
+
createTextNode(url, offsets === undefined
|
|
718
|
+
? { start: start + 1, end: index }
|
|
719
|
+
: createRange(offsets, start + 1, index))
|
|
720
|
+
]
|
|
721
|
+
}, offsets === undefined ? { start, end: index + 1 } : createRange(offsets, start, index + 1)),
|
|
722
|
+
end: index + 1
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
function parseFootnoteReference(input, start, footnoteLabels, offsets) {
|
|
726
|
+
if (footnoteLabels === undefined ||
|
|
727
|
+
start + 3 >= input.length ||
|
|
728
|
+
input[start] !== "[" ||
|
|
729
|
+
input[start + 1] !== "^") {
|
|
730
|
+
return null;
|
|
731
|
+
}
|
|
732
|
+
let labelEnd = start + 2;
|
|
733
|
+
while (labelEnd < input.length && input[labelEnd] !== "]") {
|
|
734
|
+
if (!isFootnoteLabelChar(input[labelEnd])) {
|
|
735
|
+
return null;
|
|
736
|
+
}
|
|
737
|
+
labelEnd += 1;
|
|
738
|
+
}
|
|
739
|
+
if (labelEnd === start + 2 || labelEnd >= input.length) {
|
|
740
|
+
return null;
|
|
741
|
+
}
|
|
742
|
+
const label = input.slice(start + 2, labelEnd);
|
|
743
|
+
if (!footnoteLabels.has(label)) {
|
|
744
|
+
return null;
|
|
745
|
+
}
|
|
746
|
+
return {
|
|
747
|
+
node: withRange({ type: "footnoteReference", label }, offsets === undefined
|
|
748
|
+
? { start, end: labelEnd + 1 }
|
|
749
|
+
: createRange(offsets, start, labelEnd + 1)),
|
|
750
|
+
end: labelEnd + 1
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
function parseLiteralAutolink(input, start, offsets) {
|
|
754
|
+
if (!isLiteralAutolinkBoundaryBefore(input, start)) {
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
const urlLiteral = parseLiteralUrlAutolink(input, start);
|
|
758
|
+
if (urlLiteral !== null) {
|
|
759
|
+
return createLiteralAutolinkNode(urlLiteral.text, urlLiteral.url, start, urlLiteral.end, offsets);
|
|
760
|
+
}
|
|
761
|
+
const wwwLiteral = parseLiteralWwwAutolink(input, start);
|
|
762
|
+
if (wwwLiteral !== null) {
|
|
763
|
+
return createLiteralAutolinkNode(wwwLiteral.text, `http://${wwwLiteral.text}`, start, wwwLiteral.end, offsets);
|
|
764
|
+
}
|
|
765
|
+
const emailLiteral = parseLiteralEmailAutolink(input, start);
|
|
766
|
+
if (emailLiteral !== null) {
|
|
767
|
+
return createLiteralAutolinkNode(emailLiteral.text, `mailto:${emailLiteral.text}`, start, emailLiteral.end, offsets);
|
|
768
|
+
}
|
|
769
|
+
return null;
|
|
770
|
+
}
|
|
771
|
+
function createLiteralAutolinkNode(text, url, start, end, offsets) {
|
|
772
|
+
return {
|
|
773
|
+
node: withRange({
|
|
774
|
+
type: "link",
|
|
775
|
+
url,
|
|
776
|
+
children: [
|
|
777
|
+
createTextNode(text, offsets === undefined ? { start, end } : createRange(offsets, start, end))
|
|
778
|
+
]
|
|
779
|
+
}, offsets === undefined ? { start, end } : createRange(offsets, start, end)),
|
|
780
|
+
end
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
function parseLiteralUrlAutolink(input, start) {
|
|
784
|
+
const hasHttp = input.startsWith("http://", start);
|
|
785
|
+
const hasHttps = input.startsWith("https://", start);
|
|
786
|
+
if (!hasHttp && !hasHttps) {
|
|
787
|
+
return null;
|
|
788
|
+
}
|
|
789
|
+
const end = scanLiteralAutolinkEnd(input, start);
|
|
790
|
+
const text = trimLiteralAutolinkText(input.slice(start, end));
|
|
791
|
+
const prefixLength = hasHttps ? "https://".length : "http://".length;
|
|
792
|
+
if (text.length <= prefixLength) {
|
|
793
|
+
return null;
|
|
794
|
+
}
|
|
795
|
+
return { text, url: text, end: start + text.length };
|
|
796
|
+
}
|
|
797
|
+
function parseLiteralWwwAutolink(input, start) {
|
|
798
|
+
if (!input.startsWith("www.", start)) {
|
|
799
|
+
return null;
|
|
800
|
+
}
|
|
801
|
+
const end = scanLiteralAutolinkEnd(input, start);
|
|
802
|
+
const text = trimLiteralAutolinkText(input.slice(start, end));
|
|
803
|
+
if (!hasDotAfterPrefix(text, 4)) {
|
|
804
|
+
return null;
|
|
805
|
+
}
|
|
806
|
+
return { text, end: start + text.length };
|
|
807
|
+
}
|
|
808
|
+
function parseLiteralEmailAutolink(input, start) {
|
|
809
|
+
if (!isEmailLocalPartChar(input[start] ?? "")) {
|
|
810
|
+
return null;
|
|
811
|
+
}
|
|
812
|
+
const end = scanLiteralAutolinkEnd(input, start);
|
|
813
|
+
const text = trimLiteralAutolinkText(input.slice(start, end));
|
|
814
|
+
if (!isValidLiteralEmail(text)) {
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
return { text, end: start + text.length };
|
|
818
|
+
}
|
|
819
|
+
function parseInlineHtmlTag(input, start, offsets) {
|
|
820
|
+
if (input[start] !== "<") {
|
|
821
|
+
return null;
|
|
822
|
+
}
|
|
823
|
+
let index = start + 1;
|
|
824
|
+
let closing = false;
|
|
825
|
+
if (index < input.length && input[index] === "/") {
|
|
826
|
+
closing = true;
|
|
827
|
+
index += 1;
|
|
828
|
+
}
|
|
829
|
+
if (index >= input.length || !isAsciiLetter(input[index])) {
|
|
830
|
+
return null;
|
|
831
|
+
}
|
|
832
|
+
index += 1;
|
|
833
|
+
while (index < input.length && isHtmlTagNameChar(input[index])) {
|
|
834
|
+
index += 1;
|
|
835
|
+
}
|
|
836
|
+
const tagName = input.slice(start + (closing ? 2 : 1), index).toLowerCase();
|
|
837
|
+
if (!INLINE_HTML_TAGS.has(tagName)) {
|
|
838
|
+
return null;
|
|
839
|
+
}
|
|
840
|
+
if (closing) {
|
|
841
|
+
index = skipHtmlWhitespace(input, index);
|
|
842
|
+
if (index >= input.length || input[index] !== ">") {
|
|
843
|
+
return null;
|
|
844
|
+
}
|
|
845
|
+
return {
|
|
846
|
+
node: withRange({ type: "html", value: input.slice(start, index + 1) }, offsets === undefined ? { start, end: index + 1 } : createRange(offsets, start, index + 1)),
|
|
847
|
+
end: index + 1
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
while (index < input.length) {
|
|
851
|
+
index = skipHtmlWhitespace(input, index);
|
|
852
|
+
if (index >= input.length) {
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
if (input[index] === ">") {
|
|
856
|
+
return {
|
|
857
|
+
node: withRange({ type: "html", value: input.slice(start, index + 1) }, offsets === undefined ? { start, end: index + 1 } : createRange(offsets, start, index + 1)),
|
|
858
|
+
end: index + 1
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
if (input[index] === "/") {
|
|
862
|
+
const selfClosingEnd = skipHtmlWhitespace(input, index + 1);
|
|
863
|
+
if (selfClosingEnd >= input.length || input[selfClosingEnd] !== ">") {
|
|
864
|
+
return null;
|
|
865
|
+
}
|
|
866
|
+
return {
|
|
867
|
+
node: withRange({ type: "html", value: input.slice(start, selfClosingEnd + 1) }, offsets === undefined
|
|
868
|
+
? { start, end: selfClosingEnd + 1 }
|
|
869
|
+
: createRange(offsets, start, selfClosingEnd + 1)),
|
|
870
|
+
end: selfClosingEnd + 1
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
if (!isHtmlAttributeNameStartChar(input[index])) {
|
|
874
|
+
return null;
|
|
875
|
+
}
|
|
876
|
+
index += 1;
|
|
877
|
+
while (index < input.length && isHtmlAttributeNameChar(input[index])) {
|
|
878
|
+
index += 1;
|
|
879
|
+
}
|
|
880
|
+
index = skipHtmlWhitespace(input, index);
|
|
881
|
+
if (index >= input.length || input[index] !== "=") {
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
index = skipHtmlWhitespace(input, index + 1);
|
|
885
|
+
if (index >= input.length) {
|
|
886
|
+
return null;
|
|
887
|
+
}
|
|
888
|
+
const quote = input[index];
|
|
889
|
+
if (quote === '"' || quote === "'") {
|
|
890
|
+
index += 1;
|
|
891
|
+
while (index < input.length && input[index] !== quote) {
|
|
892
|
+
index += 1;
|
|
893
|
+
}
|
|
894
|
+
if (index >= input.length) {
|
|
895
|
+
return null;
|
|
896
|
+
}
|
|
897
|
+
index += 1;
|
|
898
|
+
continue;
|
|
899
|
+
}
|
|
900
|
+
while (index < input.length && !isHtmlWhitespace(input[index]) && input[index] !== ">") {
|
|
901
|
+
const char = input[index];
|
|
902
|
+
if (char === '"' || char === "'" || char === "<" || char === "=" || char === "`") {
|
|
903
|
+
return null;
|
|
904
|
+
}
|
|
905
|
+
index += 1;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
return null;
|
|
909
|
+
}
|
|
910
|
+
function decodeEscapes(value) {
|
|
911
|
+
let result = "";
|
|
912
|
+
let index = 0;
|
|
913
|
+
while (index < value.length) {
|
|
914
|
+
if (value[index] === "\\" && index + 1 < value.length && isEscapable(value[index + 1])) {
|
|
915
|
+
result += value[index + 1];
|
|
916
|
+
index += 2;
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
result += value[index];
|
|
920
|
+
index += 1;
|
|
921
|
+
}
|
|
922
|
+
return result;
|
|
923
|
+
}
|
|
924
|
+
function findTrailingHardBreakSpaceStart(value) {
|
|
925
|
+
let start = value.length;
|
|
926
|
+
while (start > 0 && (value[start - 1] === " " || value[start - 1] === "\t")) {
|
|
927
|
+
start -= 1;
|
|
928
|
+
}
|
|
929
|
+
return value.length - start >= 2 ? start : -1;
|
|
930
|
+
}
|
|
931
|
+
function readRunLength(input, start, char) {
|
|
932
|
+
let index = start;
|
|
933
|
+
while (index < input.length && input[index] === char) {
|
|
934
|
+
index += 1;
|
|
935
|
+
}
|
|
936
|
+
return index - start;
|
|
937
|
+
}
|
|
938
|
+
function trimAsciiWhitespace(value) {
|
|
939
|
+
const start = trimAsciiWhitespaceStartIndex(value);
|
|
940
|
+
const end = trimAsciiWhitespaceEndIndex(value);
|
|
941
|
+
return value.slice(start, end);
|
|
942
|
+
}
|
|
943
|
+
function trimAsciiWhitespaceStartIndex(value) {
|
|
944
|
+
let index = 0;
|
|
945
|
+
while (index < value.length && isAsciiWhitespace(value[index])) {
|
|
946
|
+
index += 1;
|
|
947
|
+
}
|
|
948
|
+
return index;
|
|
949
|
+
}
|
|
950
|
+
function trimAsciiWhitespaceEndIndex(value) {
|
|
951
|
+
let index = value.length;
|
|
952
|
+
while (index > 0 && isAsciiWhitespace(value[index - 1])) {
|
|
953
|
+
index -= 1;
|
|
954
|
+
}
|
|
955
|
+
return index;
|
|
956
|
+
}
|
|
957
|
+
function isAutolinkUrl(value) {
|
|
958
|
+
if (value.length < 3 || !isAsciiLetter(value[0])) {
|
|
959
|
+
return false;
|
|
960
|
+
}
|
|
961
|
+
let index = 1;
|
|
962
|
+
while (index < value.length) {
|
|
963
|
+
const char = value[index];
|
|
964
|
+
if (char === ":") {
|
|
965
|
+
return index >= 2;
|
|
966
|
+
}
|
|
967
|
+
if (!isAsciiLetter(char) && !isDigit(char) && char !== "+" && char !== "." && char !== "-") {
|
|
968
|
+
return false;
|
|
969
|
+
}
|
|
970
|
+
index += 1;
|
|
971
|
+
}
|
|
972
|
+
return false;
|
|
973
|
+
}
|
|
974
|
+
function scanLiteralAutolinkEnd(input, start) {
|
|
975
|
+
let index = start;
|
|
976
|
+
while (index < input.length) {
|
|
977
|
+
const char = input[index];
|
|
978
|
+
if (char === "\n" || isAsciiWhitespace(char) || char === "<") {
|
|
979
|
+
break;
|
|
980
|
+
}
|
|
981
|
+
index += 1;
|
|
982
|
+
}
|
|
983
|
+
return index;
|
|
984
|
+
}
|
|
985
|
+
function trimLiteralAutolinkText(value) {
|
|
986
|
+
let end = value.length;
|
|
987
|
+
while (end > 0) {
|
|
988
|
+
const lastChar = value[end - 1];
|
|
989
|
+
if (lastChar === "." ||
|
|
990
|
+
lastChar === "," ||
|
|
991
|
+
lastChar === ":" ||
|
|
992
|
+
lastChar === ";" ||
|
|
993
|
+
lastChar === "!" ||
|
|
994
|
+
lastChar === "?") {
|
|
995
|
+
end -= 1;
|
|
996
|
+
continue;
|
|
997
|
+
}
|
|
998
|
+
if ((lastChar === ")" && hasMoreClosersThanOpeners(value.slice(0, end), "(", ")")) ||
|
|
999
|
+
(lastChar === "]" && hasMoreClosersThanOpeners(value.slice(0, end), "[", "]")) ||
|
|
1000
|
+
(lastChar === "}" && hasMoreClosersThanOpeners(value.slice(0, end), "{", "}"))) {
|
|
1001
|
+
end -= 1;
|
|
1002
|
+
continue;
|
|
1003
|
+
}
|
|
1004
|
+
break;
|
|
1005
|
+
}
|
|
1006
|
+
return value.slice(0, end);
|
|
1007
|
+
}
|
|
1008
|
+
function hasMoreClosersThanOpeners(value, opener, closer) {
|
|
1009
|
+
let balance = 0;
|
|
1010
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
1011
|
+
if (value[index] === opener) {
|
|
1012
|
+
balance += 1;
|
|
1013
|
+
continue;
|
|
1014
|
+
}
|
|
1015
|
+
if (value[index] === closer) {
|
|
1016
|
+
balance -= 1;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
return balance < 0;
|
|
1020
|
+
}
|
|
1021
|
+
function isLiteralAutolinkBoundaryBefore(input, start) {
|
|
1022
|
+
if (start === 0) {
|
|
1023
|
+
return true;
|
|
1024
|
+
}
|
|
1025
|
+
const previous = input[start - 1];
|
|
1026
|
+
if (previous === "(" && start >= 2 && input[start - 2] === "]") {
|
|
1027
|
+
return false;
|
|
1028
|
+
}
|
|
1029
|
+
return (!isAsciiLetter(previous) &&
|
|
1030
|
+
!isDigit(previous) &&
|
|
1031
|
+
previous !== "_" &&
|
|
1032
|
+
previous !== "." &&
|
|
1033
|
+
previous !== "+" &&
|
|
1034
|
+
previous !== "-" &&
|
|
1035
|
+
previous !== "@" &&
|
|
1036
|
+
previous !== "/");
|
|
1037
|
+
}
|
|
1038
|
+
function hasDotAfterPrefix(value, prefixLength) {
|
|
1039
|
+
if (value.length <= prefixLength) {
|
|
1040
|
+
return false;
|
|
1041
|
+
}
|
|
1042
|
+
for (let index = prefixLength; index < value.length; index += 1) {
|
|
1043
|
+
if (value[index] === ".") {
|
|
1044
|
+
return true;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
return false;
|
|
1048
|
+
}
|
|
1049
|
+
function isValidLiteralEmail(value) {
|
|
1050
|
+
const atIndex = value.indexOf("@");
|
|
1051
|
+
if (atIndex <= 0 || atIndex === value.length - 1 || value.indexOf("@", atIndex + 1) !== -1) {
|
|
1052
|
+
return false;
|
|
1053
|
+
}
|
|
1054
|
+
const localPart = value.slice(0, atIndex);
|
|
1055
|
+
const domain = value.slice(atIndex + 1);
|
|
1056
|
+
if (domain[0] === "." || domain[domain.length - 1] === "." || !hasDotAfterPrefix(domain, 0)) {
|
|
1057
|
+
return false;
|
|
1058
|
+
}
|
|
1059
|
+
for (let index = 0; index < localPart.length; index += 1) {
|
|
1060
|
+
if (!isEmailLocalPartChar(localPart[index])) {
|
|
1061
|
+
return false;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
for (let index = 0; index < domain.length; index += 1) {
|
|
1065
|
+
if (!isEmailDomainChar(domain[index])) {
|
|
1066
|
+
return false;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
return true;
|
|
1070
|
+
}
|
|
1071
|
+
function isEscaped(value, index) {
|
|
1072
|
+
let slashCount = 0;
|
|
1073
|
+
let cursor = index - 1;
|
|
1074
|
+
while (cursor >= 0 && value[cursor] === "\\") {
|
|
1075
|
+
slashCount += 1;
|
|
1076
|
+
cursor -= 1;
|
|
1077
|
+
}
|
|
1078
|
+
return slashCount % 2 === 1;
|
|
1079
|
+
}
|
|
1080
|
+
function skipHtmlWhitespace(value, start) {
|
|
1081
|
+
let index = start;
|
|
1082
|
+
while (index < value.length && isHtmlWhitespace(value[index])) {
|
|
1083
|
+
index += 1;
|
|
1084
|
+
}
|
|
1085
|
+
return index;
|
|
1086
|
+
}
|
|
1087
|
+
function isEscapable(value) {
|
|
1088
|
+
return (value === "!" ||
|
|
1089
|
+
value === '"' ||
|
|
1090
|
+
value === "#" ||
|
|
1091
|
+
value === "$" ||
|
|
1092
|
+
value === "%" ||
|
|
1093
|
+
value === "&" ||
|
|
1094
|
+
value === "'" ||
|
|
1095
|
+
value === "(" ||
|
|
1096
|
+
value === ")" ||
|
|
1097
|
+
value === "*" ||
|
|
1098
|
+
value === "+" ||
|
|
1099
|
+
value === "," ||
|
|
1100
|
+
value === "-" ||
|
|
1101
|
+
value === "." ||
|
|
1102
|
+
value === "/" ||
|
|
1103
|
+
value === ":" ||
|
|
1104
|
+
value === ";" ||
|
|
1105
|
+
value === "<" ||
|
|
1106
|
+
value === "=" ||
|
|
1107
|
+
value === ">" ||
|
|
1108
|
+
value === "?" ||
|
|
1109
|
+
value === "@" ||
|
|
1110
|
+
value === "[" ||
|
|
1111
|
+
value === "\\" ||
|
|
1112
|
+
value === "]" ||
|
|
1113
|
+
value === "^" ||
|
|
1114
|
+
value === "_" ||
|
|
1115
|
+
value === "`" ||
|
|
1116
|
+
value === "{" ||
|
|
1117
|
+
value === "|" ||
|
|
1118
|
+
value === "}" ||
|
|
1119
|
+
value === "~");
|
|
1120
|
+
}
|
|
1121
|
+
function isAsciiWhitespace(value) {
|
|
1122
|
+
return value === " " || value === "\t";
|
|
1123
|
+
}
|
|
1124
|
+
function isDelimiterWhitespace(value) {
|
|
1125
|
+
return value === null || /\s/u.test(value);
|
|
1126
|
+
}
|
|
1127
|
+
function isDelimiterPunctuation(value) {
|
|
1128
|
+
return value !== null && /[\p{P}\p{S}]/u.test(value);
|
|
1129
|
+
}
|
|
1130
|
+
function isHtmlWhitespace(value) {
|
|
1131
|
+
return value === " " || value === "\t";
|
|
1132
|
+
}
|
|
1133
|
+
function isAsciiLetter(value) {
|
|
1134
|
+
return (value >= "a" && value <= "z") || (value >= "A" && value <= "Z");
|
|
1135
|
+
}
|
|
1136
|
+
function isDigit(value) {
|
|
1137
|
+
return value >= "0" && value <= "9";
|
|
1138
|
+
}
|
|
1139
|
+
function isEmailLocalPartChar(value) {
|
|
1140
|
+
return (isAsciiLetter(value) ||
|
|
1141
|
+
isDigit(value) ||
|
|
1142
|
+
value === "." ||
|
|
1143
|
+
value === "_" ||
|
|
1144
|
+
value === "%" ||
|
|
1145
|
+
value === "+" ||
|
|
1146
|
+
value === "-");
|
|
1147
|
+
}
|
|
1148
|
+
function isEmailDomainChar(value) {
|
|
1149
|
+
return isAsciiLetter(value) || isDigit(value) || value === "." || value === "-";
|
|
1150
|
+
}
|
|
1151
|
+
function isFootnoteLabelChar(value) {
|
|
1152
|
+
return isAsciiLetter(value) || isDigit(value) || value === "-" || value === "_";
|
|
1153
|
+
}
|
|
1154
|
+
function isHtmlTagNameChar(value) {
|
|
1155
|
+
return isAsciiLetter(value) || isDigit(value) || value === "-";
|
|
1156
|
+
}
|
|
1157
|
+
function isHtmlAttributeNameStartChar(value) {
|
|
1158
|
+
return isAsciiLetter(value) || value === ":" || value === "_";
|
|
1159
|
+
}
|
|
1160
|
+
function isHtmlAttributeNameChar(value) {
|
|
1161
|
+
return isHtmlAttributeNameStartChar(value) || isDigit(value) || value === "-" || value === ".";
|
|
1162
|
+
}
|
|
1163
|
+
function createRange(offsets, start, end) {
|
|
1164
|
+
return {
|
|
1165
|
+
start: offsets[start] ?? offsets[offsets.length - 1] ?? 0,
|
|
1166
|
+
end: offsets[end] ?? offsets[offsets.length - 1] ?? 0
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
function sliceOffsetMap(offsets, start, end) {
|
|
1170
|
+
return offsets.slice(start, end + 1);
|
|
1171
|
+
}
|
|
1172
|
+
function createOffsetMap(input, absoluteStart = 0) {
|
|
1173
|
+
const offsets = new Array(input.length + 1).fill(absoluteStart);
|
|
1174
|
+
let byteOffset = absoluteStart;
|
|
1175
|
+
let index = 0;
|
|
1176
|
+
while (index < input.length) {
|
|
1177
|
+
offsets[index] = byteOffset;
|
|
1178
|
+
const codePoint = input.codePointAt(index) ?? 0;
|
|
1179
|
+
const codeUnitLength = codePoint > 0xffff ? 2 : 1;
|
|
1180
|
+
const byteLength = codePoint <= 0x7f ? 1 : codePoint <= 0x7ff ? 2 : codePoint <= 0xffff ? 3 : 4;
|
|
1181
|
+
for (let offsetIndex = 1; offsetIndex < codeUnitLength; offsetIndex += 1) {
|
|
1182
|
+
offsets[index + offsetIndex] = byteOffset;
|
|
1183
|
+
}
|
|
1184
|
+
byteOffset += byteLength;
|
|
1185
|
+
index += codeUnitLength;
|
|
1186
|
+
offsets[index] = byteOffset;
|
|
1187
|
+
}
|
|
1188
|
+
offsets[input.length] = byteOffset;
|
|
1189
|
+
return offsets;
|
|
1190
|
+
}
|