svelte-highlight 7.23.1 → 7.24.0
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/AnsiOutput.svelte +33 -6
- package/AnsiOutput.svelte.d.ts +8 -0
- package/CodeToolbar.svelte +144 -0
- package/CodeToolbar.svelte.d.ts +125 -0
- package/CodeWindow.svelte +19 -0
- package/CodeWindow.svelte.d.ts +10 -0
- package/CopyButton.svelte +107 -3
- package/CopyButton.svelte.d.ts +17 -1
- package/DiffFileList.svelte +523 -0
- package/DiffFileList.svelte.d.ts +94 -0
- package/DiffFileListItem.svelte +44 -0
- package/DiffMinimap.svelte +99 -0
- package/DiffMinimap.svelte.d.ts +17 -0
- package/DiffStats.svelte +43 -0
- package/DiffStats.svelte.d.ts +17 -0
- package/DiffView.svelte +1213 -0
- package/DiffView.svelte.d.ts +76 -0
- package/FileTabs.svelte +2 -5
- package/Highlight.svelte +158 -2
- package/Highlight.svelte.d.ts +50 -2
- package/HighlightAuto.svelte.d.ts +3 -2
- package/HighlightAutoLazy.svelte +112 -0
- package/HighlightAutoLazy.svelte.d.ts +66 -0
- package/HighlightDiff.svelte +162 -0
- package/HighlightDiff.svelte.d.ts +102 -0
- package/HighlightEditable.svelte +65 -766
- package/HighlightEditable.svelte.d.ts +15 -5
- package/HighlightStream.svelte +117 -218
- package/HighlightStream.svelte.d.ts +8 -0
- package/HighlightSvelte.svelte.d.ts +3 -2
- package/HighlightVirtual.svelte +41 -8
- package/HighlightVirtual.svelte.d.ts +8 -0
- package/LangTag.svelte +33 -4
- package/LangTag.svelte.d.ts +6 -2
- package/LineNumbers.svelte +25 -4
- package/LineNumbers.svelte.d.ts +8 -0
- package/MarkdownStream.svelte +1 -0
- package/README.md +736 -19
- package/ToolbarButton.svelte +90 -0
- package/ToolbarButton.svelte.d.ts +106 -0
- package/Typewriter.svelte +59 -10
- package/Typewriter.svelte.d.ts +7 -0
- package/WrapToggle.svelte +34 -0
- package/WrapToggle.svelte.d.ts +39 -0
- package/action.js +7 -3
- package/ansi.d.ts +1 -3
- package/ansi.js +44 -12
- package/auto-detect.d.ts +52 -0
- package/auto-detect.js +208 -0
- package/code-region.d.ts +7 -0
- package/code-region.js +20 -0
- package/css-highlights.js +115 -0
- package/css-walk.js +50 -0
- package/diff-controller.d.ts +120 -0
- package/diff-controller.js +721 -0
- package/diff-edits.d.ts +101 -0
- package/diff-edits.js +890 -0
- package/diff-html.d.ts +8 -0
- package/diff-html.js +60 -0
- package/diff-languages.d.ts +4 -0
- package/diff-languages.js +73 -0
- package/diff.d.ts +161 -0
- package/diff.js +1111 -0
- package/editable-commands.js +81 -0
- package/editable-css-paint.js +5 -3
- package/editable-dom-paint.js +1 -1
- package/editable-history.js +199 -0
- package/editable-line-dom.js +176 -1
- package/editable-painter.js +356 -0
- package/editable.d.ts +118 -0
- package/editable.js +513 -0
- package/engine.d.ts +1 -1
- package/fence.js +1 -1
- package/highlight-cascade.js +679 -0
- package/highlight-theme.d.ts +7 -0
- package/highlight-theme.js +23 -46
- package/incremental-tokenize.js +1 -1
- package/index.d.ts +39 -6
- package/index.js +30 -0
- package/languages/detect-index.d.ts +16 -0
- package/languages/detect-index.js +6 -0
- package/languages/loaders.d.ts +8 -0
- package/languages/loaders.js +370 -0
- package/package.json +50 -2
- package/preprocessor.js +20 -5
- package/search.js +2 -2
- package/stream-highlighter.js +198 -0
- package/stream.css +16 -0
- package/stream.d.ts +60 -0
- package/stream.js +283 -0
- package/style-registry.js +34 -3
- package/styles/3024.css +1 -1
- package/styles/3024.js +1 -1
- package/styles/apathy.css +1 -1
- package/styles/apathy.js +1 -1
- package/styles/apprentice.css +1 -1
- package/styles/apprentice.js +1 -1
- package/styles/ashes.css +1 -1
- package/styles/ashes.js +1 -1
- package/styles/atelier-cave-light.css +1 -1
- package/styles/atelier-cave-light.js +1 -1
- package/styles/atelier-cave.css +1 -1
- package/styles/atelier-cave.js +1 -1
- package/styles/atelier-dune-light.css +1 -1
- package/styles/atelier-dune-light.js +1 -1
- package/styles/atelier-dune.css +1 -1
- package/styles/atelier-dune.js +1 -1
- package/styles/atelier-estuary-light.css +1 -1
- package/styles/atelier-estuary-light.js +1 -1
- package/styles/atelier-estuary.css +1 -1
- package/styles/atelier-estuary.js +1 -1
- package/styles/atelier-forest-light.css +1 -1
- package/styles/atelier-forest-light.js +1 -1
- package/styles/atelier-forest.css +1 -1
- package/styles/atelier-forest.js +1 -1
- package/styles/atelier-heath-light.css +1 -1
- package/styles/atelier-heath-light.js +1 -1
- package/styles/atelier-heath.css +1 -1
- package/styles/atelier-heath.js +1 -1
- package/styles/atelier-lakeside-light.css +1 -1
- package/styles/atelier-lakeside-light.js +1 -1
- package/styles/atelier-lakeside.css +1 -1
- package/styles/atelier-lakeside.js +1 -1
- package/styles/atelier-plateau-light.css +1 -1
- package/styles/atelier-plateau-light.js +1 -1
- package/styles/atelier-plateau.css +1 -1
- package/styles/atelier-plateau.js +1 -1
- package/styles/atelier-savanna-light.css +1 -1
- package/styles/atelier-savanna-light.js +1 -1
- package/styles/atelier-savanna.css +1 -1
- package/styles/atelier-savanna.js +1 -1
- package/styles/atelier-seaside-light.css +1 -1
- package/styles/atelier-seaside-light.js +1 -1
- package/styles/atelier-seaside.css +1 -1
- package/styles/atelier-seaside.js +1 -1
- package/styles/atelier-sulphurpool-light.css +1 -1
- package/styles/atelier-sulphurpool-light.js +1 -1
- package/styles/atelier-sulphurpool.css +1 -1
- package/styles/atelier-sulphurpool.js +1 -1
- package/styles/atlas.css +1 -1
- package/styles/atlas.js +1 -1
- package/styles/base16-github.css +1 -1
- package/styles/base16-github.js +1 -1
- package/styles/base16-ir-black.css +1 -1
- package/styles/base16-ir-black.js +1 -1
- package/styles/base16-monokai.css +1 -1
- package/styles/base16-monokai.js +1 -1
- package/styles/base16-nord.css +1 -1
- package/styles/base16-nord.js +1 -1
- package/styles/bespin.css +1 -1
- package/styles/bespin.js +1 -1
- package/styles/black-metal-bathory.css +1 -1
- package/styles/black-metal-bathory.js +1 -1
- package/styles/black-metal-burzum.css +1 -1
- package/styles/black-metal-burzum.js +1 -1
- package/styles/black-metal-dark-funeral.css +1 -1
- package/styles/black-metal-dark-funeral.js +1 -1
- package/styles/black-metal-gorgoroth.css +1 -1
- package/styles/black-metal-gorgoroth.js +1 -1
- package/styles/black-metal-immortal.css +1 -1
- package/styles/black-metal-immortal.js +1 -1
- package/styles/black-metal-khold.css +1 -1
- package/styles/black-metal-khold.js +1 -1
- package/styles/black-metal-marduk.css +1 -1
- package/styles/black-metal-marduk.js +1 -1
- package/styles/black-metal-mayhem.css +1 -1
- package/styles/black-metal-mayhem.js +1 -1
- package/styles/black-metal-nile.css +1 -1
- package/styles/black-metal-nile.js +1 -1
- package/styles/black-metal-venom.css +1 -1
- package/styles/black-metal-venom.js +1 -1
- package/styles/black-metal.css +1 -1
- package/styles/black-metal.js +1 -1
- package/styles/brewer.css +1 -1
- package/styles/brewer.js +1 -1
- package/styles/bright.css +1 -1
- package/styles/bright.js +1 -1
- package/styles/brogrammer.css +1 -1
- package/styles/brogrammer.js +1 -1
- package/styles/brush-trees-dark.css +1 -1
- package/styles/brush-trees-dark.js +1 -1
- package/styles/brush-trees.css +1 -1
- package/styles/brush-trees.js +1 -1
- package/styles/chalk.css +1 -1
- package/styles/chalk.js +1 -1
- package/styles/circus.css +1 -1
- package/styles/circus.js +1 -1
- package/styles/classic-dark.css +1 -1
- package/styles/classic-dark.js +1 -1
- package/styles/classic-light.css +1 -1
- package/styles/classic-light.js +1 -1
- package/styles/codeschool.css +1 -1
- package/styles/codeschool.js +1 -1
- package/styles/colors.css +1 -1
- package/styles/colors.js +1 -1
- package/styles/cupcake.css +1 -1
- package/styles/cupcake.js +1 -1
- package/styles/cupertino.css +1 -1
- package/styles/cupertino.js +1 -1
- package/styles/cybertopia-cherry.css +2 -1
- package/styles/cybertopia-cherry.js +2 -1
- package/styles/cybertopia-dimmer.css +2 -1
- package/styles/cybertopia-dimmer.js +2 -1
- package/styles/cybertopia-icecap.css +2 -1
- package/styles/cybertopia-icecap.js +2 -1
- package/styles/cybertopia-saturated.css +2 -1
- package/styles/cybertopia-saturated.js +2 -1
- package/styles/danqing.css +1 -1
- package/styles/danqing.js +1 -1
- package/styles/darcula.css +1 -1
- package/styles/darcula.js +1 -1
- package/styles/dark-violet.css +1 -1
- package/styles/dark-violet.js +1 -1
- package/styles/darkmoss.css +1 -1
- package/styles/darkmoss.js +1 -1
- package/styles/darktooth.css +1 -1
- package/styles/darktooth.js +1 -1
- package/styles/decaf.css +1 -1
- package/styles/decaf.js +1 -1
- package/styles/default-dark.css +1 -1
- package/styles/default-dark.js +1 -1
- package/styles/default-light.css +1 -1
- package/styles/default-light.js +1 -1
- package/styles/dirtysea.css +1 -1
- package/styles/dirtysea.js +1 -1
- package/styles/docco.css +1 -1
- package/styles/docco.js +1 -1
- package/styles/dracula.css +1 -1
- package/styles/dracula.js +1 -1
- package/styles/edge-dark.css +1 -1
- package/styles/edge-dark.js +1 -1
- package/styles/edge-light.css +1 -1
- package/styles/edge-light.js +1 -1
- package/styles/eighties.css +1 -1
- package/styles/eighties.js +1 -1
- package/styles/embers.css +1 -1
- package/styles/embers.js +1 -1
- package/styles/equilibrium-dark.css +1 -1
- package/styles/equilibrium-dark.js +1 -1
- package/styles/equilibrium-gray-dark.css +1 -1
- package/styles/equilibrium-gray-dark.js +1 -1
- package/styles/equilibrium-gray-light.css +1 -1
- package/styles/equilibrium-gray-light.js +1 -1
- package/styles/equilibrium-light.css +1 -1
- package/styles/equilibrium-light.js +1 -1
- package/styles/espresso.css +1 -1
- package/styles/espresso.js +1 -1
- package/styles/eva-dim.css +1 -1
- package/styles/eva-dim.js +1 -1
- package/styles/eva.css +1 -1
- package/styles/eva.js +1 -1
- package/styles/flat.css +1 -1
- package/styles/flat.js +1 -1
- package/styles/framer.css +1 -1
- package/styles/framer.js +1 -1
- package/styles/fruit-soda.css +1 -1
- package/styles/fruit-soda.js +1 -1
- package/styles/gigavolt.css +1 -1
- package/styles/gigavolt.js +1 -1
- package/styles/gml.css +1 -1
- package/styles/gml.js +1 -1
- package/styles/google-dark.css +1 -1
- package/styles/google-dark.js +1 -1
- package/styles/google-light.css +1 -1
- package/styles/google-light.js +1 -1
- package/styles/googlecode.css +1 -1
- package/styles/googlecode.js +1 -1
- package/styles/grayscale-dark.css +1 -1
- package/styles/grayscale-dark.js +1 -1
- package/styles/grayscale-light.css +1 -1
- package/styles/grayscale-light.js +1 -1
- package/styles/grayscale.css +1 -1
- package/styles/grayscale.js +1 -1
- package/styles/green-screen.css +1 -1
- package/styles/green-screen.js +1 -1
- package/styles/gruvbox-dark-hard.css +1 -1
- package/styles/gruvbox-dark-hard.js +1 -1
- package/styles/gruvbox-dark-medium.css +1 -1
- package/styles/gruvbox-dark-medium.js +1 -1
- package/styles/gruvbox-dark-pale.css +1 -1
- package/styles/gruvbox-dark-pale.js +1 -1
- package/styles/gruvbox-dark-soft.css +1 -1
- package/styles/gruvbox-dark-soft.js +1 -1
- package/styles/gruvbox-light-hard.css +1 -1
- package/styles/gruvbox-light-hard.js +1 -1
- package/styles/gruvbox-light-medium.css +1 -1
- package/styles/gruvbox-light-medium.js +1 -1
- package/styles/gruvbox-light-soft.css +1 -1
- package/styles/gruvbox-light-soft.js +1 -1
- package/styles/hardcore.css +1 -1
- package/styles/hardcore.js +1 -1
- package/styles/harmonic16-dark.css +1 -1
- package/styles/harmonic16-dark.js +1 -1
- package/styles/harmonic16-light.css +1 -1
- package/styles/harmonic16-light.js +1 -1
- package/styles/heetch-dark.css +1 -1
- package/styles/heetch-dark.js +1 -1
- package/styles/heetch-light.css +1 -1
- package/styles/heetch-light.js +1 -1
- package/styles/helios.css +1 -1
- package/styles/helios.js +1 -1
- package/styles/hopscotch.css +1 -1
- package/styles/hopscotch.js +1 -1
- package/styles/horizon-dark.css +1 -1
- package/styles/horizon-dark.js +1 -1
- package/styles/horizon-light.css +1 -1
- package/styles/horizon-light.js +1 -1
- package/styles/humanoid-dark.css +1 -1
- package/styles/humanoid-dark.js +1 -1
- package/styles/humanoid-light.css +1 -1
- package/styles/humanoid-light.js +1 -1
- package/styles/ia-dark.css +1 -1
- package/styles/ia-dark.js +1 -1
- package/styles/ia-light.css +1 -1
- package/styles/ia-light.js +1 -1
- package/styles/icy-dark.css +1 -1
- package/styles/icy-dark.js +1 -1
- package/styles/idea.css +1 -1
- package/styles/idea.js +1 -1
- package/styles/intellij-light.css +1 -1
- package/styles/intellij-light.js +1 -1
- package/styles/ir-black.css +1 -1
- package/styles/ir-black.js +1 -1
- package/styles/isotope.css +1 -1
- package/styles/isotope.js +1 -1
- package/styles/kimber.css +1 -1
- package/styles/kimber.js +1 -1
- package/styles/kimbie-dark.css +1 -1
- package/styles/kimbie-dark.js +1 -1
- package/styles/kimbie-light.css +1 -1
- package/styles/kimbie-light.js +1 -1
- package/styles/london-tube.css +1 -1
- package/styles/london-tube.js +1 -1
- package/styles/macintosh.css +1 -1
- package/styles/macintosh.js +1 -1
- package/styles/marrakesh.css +1 -1
- package/styles/marrakesh.js +1 -1
- package/styles/materia.css +1 -1
- package/styles/materia.js +1 -1
- package/styles/material-darker.css +1 -1
- package/styles/material-darker.js +1 -1
- package/styles/material-lighter.css +1 -1
- package/styles/material-lighter.js +1 -1
- package/styles/material-palenight.css +1 -1
- package/styles/material-palenight.js +1 -1
- package/styles/material-vivid.css +1 -1
- package/styles/material-vivid.js +1 -1
- package/styles/material.css +1 -1
- package/styles/material.js +1 -1
- package/styles/mellow-purple.css +1 -1
- package/styles/mellow-purple.js +1 -1
- package/styles/mexico-light.css +1 -1
- package/styles/mexico-light.js +1 -1
- package/styles/mocha.css +1 -1
- package/styles/mocha.js +1 -1
- package/styles/nebula.css +1 -1
- package/styles/nebula.js +1 -1
- package/styles/nnfx-dark.css +1 -1
- package/styles/nnfx-dark.js +1 -1
- package/styles/nnfx-light.css +1 -1
- package/styles/nnfx-light.js +1 -1
- package/styles/nord.css +1 -1
- package/styles/nord.js +1 -1
- package/styles/nova.css +1 -1
- package/styles/nova.js +1 -1
- package/styles/ocean.css +1 -1
- package/styles/ocean.js +1 -1
- package/styles/oceanicnext.css +1 -1
- package/styles/oceanicnext.js +1 -1
- package/styles/one-light.css +1 -1
- package/styles/one-light.js +1 -1
- package/styles/onedark.css +1 -1
- package/styles/onedark.js +1 -1
- package/styles/outrun-dark.css +1 -1
- package/styles/outrun-dark.js +1 -1
- package/styles/papercolor-dark.css +1 -1
- package/styles/papercolor-dark.js +1 -1
- package/styles/papercolor-light.css +1 -1
- package/styles/papercolor-light.js +1 -1
- package/styles/paraiso.css +1 -1
- package/styles/paraiso.js +1 -1
- package/styles/pasque.css +1 -1
- package/styles/pasque.js +1 -1
- package/styles/phd.css +1 -1
- package/styles/phd.js +1 -1
- package/styles/pico.css +1 -1
- package/styles/pico.js +1 -1
- package/styles/pojoaque.css +1 -1
- package/styles/pojoaque.js +1 -1
- package/styles/pop.css +1 -1
- package/styles/pop.js +1 -1
- package/styles/porple.css +1 -1
- package/styles/porple.js +1 -1
- package/styles/qualia.css +1 -1
- package/styles/qualia.js +1 -1
- package/styles/railscasts.css +1 -1
- package/styles/railscasts.js +1 -1
- package/styles/rebecca.css +1 -1
- package/styles/rebecca.js +1 -1
- package/styles/ros-pine-dawn.css +1 -1
- package/styles/ros-pine-dawn.js +1 -1
- package/styles/ros-pine-moon.css +1 -1
- package/styles/ros-pine-moon.js +1 -1
- package/styles/ros-pine.css +1 -1
- package/styles/ros-pine.js +1 -1
- package/styles/sagelight.css +1 -1
- package/styles/sagelight.js +1 -1
- package/styles/sandcastle.css +1 -1
- package/styles/sandcastle.js +1 -1
- package/styles/school-book.css +1 -1
- package/styles/school-book.js +1 -1
- package/styles/seti-ui.css +1 -1
- package/styles/seti-ui.js +1 -1
- package/styles/shapeshifter.css +1 -1
- package/styles/shapeshifter.js +1 -1
- package/styles/silk-dark.css +1 -1
- package/styles/silk-dark.js +1 -1
- package/styles/silk-light.css +1 -1
- package/styles/silk-light.js +1 -1
- package/styles/snazzy.css +1 -1
- package/styles/snazzy.js +1 -1
- package/styles/solar-flare-light.css +1 -1
- package/styles/solar-flare-light.js +1 -1
- package/styles/solar-flare.css +1 -1
- package/styles/solar-flare.js +1 -1
- package/styles/solarized-dark.css +1 -1
- package/styles/solarized-dark.js +1 -1
- package/styles/solarized-light.css +1 -1
- package/styles/solarized-light.js +1 -1
- package/styles/spacemacs.css +1 -1
- package/styles/spacemacs.js +1 -1
- package/styles/stackoverflow-dark.css +1 -1
- package/styles/stackoverflow-dark.js +1 -1
- package/styles/stackoverflow-light.css +1 -1
- package/styles/stackoverflow-light.js +1 -1
- package/styles/summercamp.css +1 -1
- package/styles/summercamp.js +1 -1
- package/styles/summerfruit-dark.css +1 -1
- package/styles/summerfruit-dark.js +1 -1
- package/styles/summerfruit-light.css +1 -1
- package/styles/summerfruit-light.js +1 -1
- package/styles/synth-midnight-terminal-dark.css +1 -1
- package/styles/synth-midnight-terminal-dark.js +1 -1
- package/styles/synth-midnight-terminal-light.css +1 -1
- package/styles/synth-midnight-terminal-light.js +1 -1
- package/styles/tango.css +1 -1
- package/styles/tango.js +1 -1
- package/styles/tender.css +1 -1
- package/styles/tender.js +1 -1
- package/styles/tomorrow-night.css +1 -1
- package/styles/tomorrow-night.js +1 -1
- package/styles/tomorrow.css +1 -1
- package/styles/tomorrow.js +1 -1
- package/styles/twilight.css +1 -1
- package/styles/twilight.js +1 -1
- package/styles/unikitty-dark.css +1 -1
- package/styles/unikitty-dark.js +1 -1
- package/styles/unikitty-light.css +1 -1
- package/styles/unikitty-light.js +1 -1
- package/styles/vs2015.css +1 -1
- package/styles/vs2015.js +1 -1
- package/styles/vulcan.css +1 -1
- package/styles/vulcan.js +1 -1
- package/styles/windows-10-light.css +1 -1
- package/styles/windows-10-light.js +1 -1
- package/styles/windows-10.css +1 -1
- package/styles/windows-10.js +1 -1
- package/styles/windows-95-light.css +1 -1
- package/styles/windows-95-light.js +1 -1
- package/styles/windows-95.css +1 -1
- package/styles/windows-95.js +1 -1
- package/styles/windows-high-contrast-light.css +1 -1
- package/styles/windows-high-contrast-light.js +1 -1
- package/styles/windows-high-contrast.css +1 -1
- package/styles/windows-high-contrast.js +1 -1
- package/styles/windows-nt-light.css +1 -1
- package/styles/windows-nt-light.js +1 -1
- package/styles/windows-nt.css +1 -1
- package/styles/windows-nt.js +1 -1
- package/styles/woodland.css +1 -1
- package/styles/woodland.js +1 -1
- package/styles/xcode-dusk.css +1 -1
- package/styles/xcode-dusk.js +1 -1
- package/styles/xcode.css +1 -1
- package/styles/xcode.js +1 -1
- package/styles/xt256.css +1 -1
- package/styles/xt256.js +1 -1
- package/styles/zenburn.css +1 -1
- package/styles/zenburn.js +1 -1
- package/themes/_base-css.d.ts +1 -0
- package/themes/_base-css.js +1 -0
- package/themes/cybertopia-cherry.css +5 -1
- package/themes/cybertopia-cherry.js +1 -1
- package/themes/cybertopia-dimmer.css +5 -1
- package/themes/cybertopia-dimmer.js +1 -1
- package/themes/cybertopia-icecap.css +5 -1
- package/themes/cybertopia-icecap.js +1 -1
- package/themes/cybertopia-saturated.css +5 -1
- package/themes/cybertopia-saturated.js +1 -1
- package/typewriter-units.d.ts +3 -0
- package/typewriter-units.js +43 -0
- package/virtual-window.js +9 -4
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
import type { Row } from "./diff";
|
|
4
|
+
import type { Annotation, DiffController } from "./diff-controller";
|
|
5
|
+
|
|
6
|
+
export type DiffViewProps = HTMLAttributes<HTMLElement> & {
|
|
7
|
+
/** A controller from `createDiffController`. */
|
|
8
|
+
diff: DiffController;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* While streaming, keep the newest row in view until the reader scrolls.
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
follow?: boolean;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Show accept/reject buttons on each change. Filling the `actions` slot
|
|
18
|
+
* shows it without this.
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
review?: boolean;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Wrap long lines instead of scrolling each side sideways. Rows are
|
|
25
|
+
* measured, so wrapped rows keep virtualization.
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
wrap?: boolean;
|
|
29
|
+
|
|
30
|
+
/** @default "default" */
|
|
31
|
+
palette?: "default" | "colorblind";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Extra rows rendered above and below the viewport.
|
|
35
|
+
* @default 10
|
|
36
|
+
*/
|
|
37
|
+
overscan?: number;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Handle n/p (next/previous change), e/c (expand/collapse), v (view),
|
|
41
|
+
* and a/r/u (accept/reject/undo, with `review`) while focused.
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
keyboard?: boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Render only the rows in view. `"auto"` virtualizes past 500 rows, so
|
|
48
|
+
* small diffs keep browser find (Ctrl/Cmd+F), printing, and server
|
|
49
|
+
* rendering of every row.
|
|
50
|
+
* @default "auto"
|
|
51
|
+
*/
|
|
52
|
+
virtualize?: "auto" | boolean;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type DiffViewSlots = {
|
|
56
|
+
/** Replaces a fold row. */
|
|
57
|
+
fold: {
|
|
58
|
+
fold: NonNullable<Row["fold"]>;
|
|
59
|
+
count: number | undefined;
|
|
60
|
+
toggle: () => void;
|
|
61
|
+
};
|
|
62
|
+
/** Replaces an annotation card. The row grows to fit it. */
|
|
63
|
+
note: { note: Annotation };
|
|
64
|
+
/** Controls shown on the first row of each change. */
|
|
65
|
+
actions: {
|
|
66
|
+
change: number;
|
|
67
|
+
decision: "accepted" | "rejected" | undefined;
|
|
68
|
+
decide: (decision: "accepted" | "rejected" | undefined) => void;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default class DiffView extends SvelteComponentTyped<
|
|
73
|
+
DiffViewProps,
|
|
74
|
+
Record<string, never>,
|
|
75
|
+
DiffViewSlots
|
|
76
|
+
> {}
|
package/FileTabs.svelte
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
let root;
|
|
21
21
|
|
|
22
22
|
/** @type {HTMLButtonElement[]} */
|
|
23
|
-
|
|
23
|
+
const tabs = [];
|
|
24
24
|
|
|
25
25
|
// Used to pick a neighbor when the active file disappears from `files`.
|
|
26
26
|
let lastValidIndex = -1;
|
|
@@ -133,10 +133,7 @@
|
|
|
133
133
|
class:active={file === active}
|
|
134
134
|
aria-controls="{baseId}-panel"
|
|
135
135
|
tabindex={file === active ? 0 : -1}
|
|
136
|
-
{
|
|
137
|
-
// Spread sidesteps Biome `useValidAriaValues` on templated booleans.
|
|
138
|
-
"aria-selected": file === active,
|
|
139
|
-
}}
|
|
136
|
+
aria-selected={file === active}
|
|
140
137
|
on:click={() => selectTab(file)}
|
|
141
138
|
on:keydown={(event) => handleKeydown(event, index)}
|
|
142
139
|
>
|
package/Highlight.svelte
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
<script context="module">
|
|
2
|
+
let instanceCount = 0;
|
|
3
|
+
function nextInstanceId() {
|
|
4
|
+
return ++instanceCount;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The resolver loads on first paint, so `"dom"`-only pages don't bundle
|
|
9
|
+
* it. One load serves every instance.
|
|
10
|
+
* @type {Promise<typeof import("./highlight-cascade.js")> | undefined}
|
|
11
|
+
*/
|
|
12
|
+
let cascadeLoad;
|
|
13
|
+
|
|
14
|
+
/** @type {typeof import("./highlight-cascade.js") | undefined} */
|
|
15
|
+
let cascadeModule;
|
|
16
|
+
|
|
17
|
+
function loadCascade() {
|
|
18
|
+
// A static specifier, so bundlers split the module into its own chunk.
|
|
19
|
+
cascadeLoad ??= import("./highlight-cascade.js").then(
|
|
20
|
+
(module) => (cascadeModule = module),
|
|
21
|
+
(error) => {
|
|
22
|
+
cascadeLoad = undefined;
|
|
23
|
+
throw error;
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
return cascadeLoad;
|
|
27
|
+
}
|
|
28
|
+
</script>
|
|
29
|
+
|
|
1
30
|
<script>
|
|
2
31
|
/** @type {import("./languages").LanguageType<string>} */
|
|
3
32
|
export let language;
|
|
@@ -11,7 +40,30 @@
|
|
|
11
40
|
/** @type {boolean} */
|
|
12
41
|
export let wrap = false;
|
|
13
42
|
|
|
14
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Rendering engine. `"css-highlights"` paints tokens via the CSS Custom
|
|
45
|
+
* Highlight API over plain text instead of a `<span>` per token, falling
|
|
46
|
+
* back to `"dom"` where unsupported. SSR renders `"dom"` markup; the swap
|
|
47
|
+
* happens after mount. No effect with a custom default slot.
|
|
48
|
+
* @type {"dom" | "css-highlights"}
|
|
49
|
+
*/
|
|
50
|
+
export let engine = "dom";
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Theme CSS or `ThemePalette` for `::highlight()` rules (`"css-highlights"`
|
|
54
|
+
* only). Each token gets the color and background the `"dom"` engine's
|
|
55
|
+
* markup would get. Bold and italic are dropped. Without a theme, the
|
|
56
|
+
* text stays plain.
|
|
57
|
+
* @type {string | import("./theme.d.ts").ThemePalette | undefined}
|
|
58
|
+
*/
|
|
59
|
+
export let theme = undefined;
|
|
60
|
+
|
|
61
|
+
import { afterUpdate, createEventDispatcher, onMount } from "svelte";
|
|
62
|
+
import {
|
|
63
|
+
createScopeHighlights,
|
|
64
|
+
paintTokenRanges,
|
|
65
|
+
resolveEngine,
|
|
66
|
+
} from "./css-highlights.js";
|
|
15
67
|
import LangTag from "./LangTag.svelte";
|
|
16
68
|
import { ensureRegistered, registry } from "./registry.js";
|
|
17
69
|
|
|
@@ -21,6 +73,10 @@
|
|
|
21
73
|
*/
|
|
22
74
|
const dispatch = createEventDispatcher();
|
|
23
75
|
|
|
76
|
+
// Distinct from HighlightEditable's numeric ids, so names never clash.
|
|
77
|
+
const highlightPrefix = `hljs-highlight-${nextInstanceId()}`;
|
|
78
|
+
const cssHighlights = createScopeHighlights(highlightPrefix);
|
|
79
|
+
|
|
24
80
|
/** @type {string} */
|
|
25
81
|
let highlighted = "";
|
|
26
82
|
|
|
@@ -30,13 +86,106 @@
|
|
|
30
86
|
/** @type {import("./engine.d.ts").ScopeEvent[] | undefined} */
|
|
31
87
|
let lastDispatchedEvents;
|
|
32
88
|
|
|
89
|
+
/** @type {HTMLElement | undefined} */
|
|
90
|
+
let codeElement;
|
|
91
|
+
|
|
92
|
+
let mounted = false;
|
|
93
|
+
|
|
94
|
+
/** The resolver, once loaded. */
|
|
95
|
+
let cascadeApi = cascadeModule;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* What the current ranges were painted from, if any.
|
|
99
|
+
* @type {{ runs: unknown; code: HTMLElement; text: Node | null } | undefined}
|
|
100
|
+
*/
|
|
101
|
+
let painted;
|
|
102
|
+
|
|
103
|
+
$: resolvedEngineValue = resolveEngine(engine);
|
|
104
|
+
// Wait for mount, so hydration sees the same markup as SSR.
|
|
105
|
+
$: wantsPainting = mounted && resolvedEngineValue === "css-highlights";
|
|
106
|
+
$: if (wantsPainting && !cascadeApi) {
|
|
107
|
+
loadCascade().then(
|
|
108
|
+
(module) => {
|
|
109
|
+
// Unmounted meanwhile: paint nothing. Otherwise the reactive
|
|
110
|
+
// statements below paint the latest props.
|
|
111
|
+
if (mounted) cascadeApi = module;
|
|
112
|
+
},
|
|
113
|
+
() => {
|
|
114
|
+
// Keep the "dom" markup.
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
// When painting, LangTag gets an empty `highlighted` and renders `code` as
|
|
119
|
+
// plain text. Until the resolver loads, keep the "dom" markup, so the code
|
|
120
|
+
// never shows as plain text without colors.
|
|
121
|
+
$: painting = wantsPainting && cascadeApi !== undefined;
|
|
122
|
+
$: cascade =
|
|
123
|
+
painting && cascadeApi && theme !== undefined
|
|
124
|
+
? cascadeApi.createThemeCascade(theme, outsideColor)
|
|
125
|
+
: undefined;
|
|
126
|
+
// One range per run of text, named by its resolved color and background.
|
|
127
|
+
$: runs =
|
|
128
|
+
cascade && cascadeApi
|
|
129
|
+
? cascadeApi.cascadeRanges(events, cascade)
|
|
130
|
+
: undefined;
|
|
131
|
+
$: cssHighlightStyle =
|
|
132
|
+
runs && cascadeApi
|
|
133
|
+
? cascadeApi.cascadeHighlightStyle(runs.styles, highlightPrefix)
|
|
134
|
+
: "";
|
|
135
|
+
|
|
136
|
+
/** The color the `<pre>` inherits, for themes that use `currentColor`. */
|
|
137
|
+
function outsideColor() {
|
|
138
|
+
const outside = codeElement?.closest("pre")?.parentElement;
|
|
139
|
+
return outside ? getComputedStyle(outside).color : null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function paint() {
|
|
143
|
+
if (!painting || !codeElement || !runs) {
|
|
144
|
+
if (painted) {
|
|
145
|
+
cssHighlights.clear();
|
|
146
|
+
painted = undefined;
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const text = codeElement.firstChild;
|
|
151
|
+
if (
|
|
152
|
+
painted?.runs === runs &&
|
|
153
|
+
painted.code === codeElement &&
|
|
154
|
+
painted.text === text
|
|
155
|
+
) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
cssHighlights.clear();
|
|
159
|
+
paintTokenRanges(cssHighlights, codeElement, runs.ranges);
|
|
160
|
+
painted = { runs, code: codeElement, text };
|
|
161
|
+
}
|
|
162
|
+
|
|
33
163
|
afterUpdate(() => {
|
|
34
164
|
if (events !== lastDispatchedEvents) {
|
|
35
165
|
lastDispatchedEvents = events;
|
|
36
166
|
dispatch("highlight", { highlighted, events });
|
|
37
167
|
}
|
|
168
|
+
paint();
|
|
38
169
|
});
|
|
39
170
|
|
|
171
|
+
onMount(() => {
|
|
172
|
+
mounted = true;
|
|
173
|
+
return () => {
|
|
174
|
+
mounted = false;
|
|
175
|
+
cssHighlights.clear();
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The engine on screen. `"css-highlights"` once it paints. `"dom"`
|
|
181
|
+
* before mount, where `CSS.highlights` is missing, until the color
|
|
182
|
+
* resolver loads, for good if that load fails, and with a custom
|
|
183
|
+
* default slot.
|
|
184
|
+
*/
|
|
185
|
+
export function resolvedEngine() {
|
|
186
|
+
return painting && codeElement ? "css-highlights" : "dom";
|
|
187
|
+
}
|
|
188
|
+
|
|
40
189
|
$: {
|
|
41
190
|
ensureRegistered(language);
|
|
42
191
|
const source = String(code ?? "");
|
|
@@ -46,13 +195,20 @@
|
|
|
46
195
|
}
|
|
47
196
|
</script>
|
|
48
197
|
|
|
198
|
+
<svelte:head
|
|
199
|
+
>{#if cssHighlightStyle}
|
|
200
|
+
{@html cssHighlightStyle}
|
|
201
|
+
{/if}</svelte:head
|
|
202
|
+
>
|
|
203
|
+
|
|
49
204
|
<slot {highlighted} {langtag} {wrap} languageName={language.name} {events}>
|
|
50
205
|
<LangTag
|
|
51
206
|
{...$$restProps}
|
|
52
207
|
languageName={language.name}
|
|
53
208
|
{langtag}
|
|
54
209
|
{wrap}
|
|
55
|
-
{highlighted}
|
|
210
|
+
highlighted={painting ? "" : highlighted}
|
|
56
211
|
{code}
|
|
212
|
+
bind:codeElement
|
|
57
213
|
/>
|
|
58
214
|
</slot>
|
package/Highlight.svelte.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
import type { HTMLAttributes } from "svelte/elements";
|
|
3
3
|
import type { ScopeEvent } from "./engine.d.ts";
|
|
4
4
|
import type { LanguageType } from "./languages";
|
|
5
|
+
import type { ThemePalette } from "./theme.d.ts";
|
|
5
6
|
|
|
6
7
|
export type LangtagProps = {
|
|
7
8
|
/**
|
|
@@ -40,8 +41,19 @@ export type LangtagProps = {
|
|
|
40
41
|
wrap?: boolean;
|
|
41
42
|
};
|
|
42
43
|
|
|
44
|
+
export type CodeRegionProps = {
|
|
45
|
+
/**
|
|
46
|
+
* Accessible name of the scrollable code region. The region is
|
|
47
|
+
* keyboard-focusable so keyboard users can scroll it. Inside a
|
|
48
|
+
* `CodeWindow`, the window's `title` or `label` is the default.
|
|
49
|
+
* @default "Code"
|
|
50
|
+
*/
|
|
51
|
+
label?: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
43
54
|
export type HighlightProps = HTMLAttributes<HTMLPreElement> &
|
|
44
|
-
LangtagProps &
|
|
55
|
+
LangtagProps &
|
|
56
|
+
CodeRegionProps & {
|
|
45
57
|
/**
|
|
46
58
|
* Code to highlight. The container also reads `--overflow-x`,
|
|
47
59
|
* `--overflow-y`, `--border-radius`, `--width`, and `--max-width`.
|
|
@@ -54,6 +66,34 @@ export type HighlightProps = HTMLAttributes<HTMLPreElement> &
|
|
|
54
66
|
* import typescript from "svelte-highlight/languages/typescript";
|
|
55
67
|
*/
|
|
56
68
|
language: LanguageType<string>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Rendering engine. `"css-highlights"` paints tokens with the CSS
|
|
72
|
+
* Custom Highlight API (`CSS.highlights`) over plain text, instead of
|
|
73
|
+
* a `<span>` per token. Falls back to `"dom"` where `CSS.highlights`
|
|
74
|
+
* is missing; check with `resolvedEngine()`.
|
|
75
|
+
*
|
|
76
|
+
* SSR always renders the `"dom"` markup. The swap to plain text
|
|
77
|
+
* happens after mount. Has no effect with a custom default slot.
|
|
78
|
+
*
|
|
79
|
+
* Colors only: `::highlight()` ignores `font-weight` and
|
|
80
|
+
* `font-style`, so bold and italic are dropped. Underlines are
|
|
81
|
+
* dropped too.
|
|
82
|
+
* @default "dom"
|
|
83
|
+
*/
|
|
84
|
+
engine?: "dom" | "css-highlights";
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Theme for the `"css-highlights"` engine's `::highlight()` rules:
|
|
88
|
+
* theme CSS from `svelte-highlight/styles/*`, or a `ThemePalette`
|
|
89
|
+
* from `svelte-highlight/themes/*`. Each token gets the `color` and
|
|
90
|
+
* `background-color` that the theme gives its `<span>` in the `"dom"`
|
|
91
|
+
* engine. Without a theme, the text stays plain. Ignored by the
|
|
92
|
+
* `"dom"` engine.
|
|
93
|
+
* @example
|
|
94
|
+
* import github from "svelte-highlight/styles/github";
|
|
95
|
+
*/
|
|
96
|
+
theme?: string | ThemePalette;
|
|
57
97
|
};
|
|
58
98
|
|
|
59
99
|
export type HighlightEvents = {
|
|
@@ -81,4 +121,12 @@ export default class Highlight extends SvelteComponentTyped<
|
|
|
81
121
|
HighlightProps,
|
|
82
122
|
HighlightEvents,
|
|
83
123
|
HighlightSlots
|
|
84
|
-
> {
|
|
124
|
+
> {
|
|
125
|
+
/**
|
|
126
|
+
* The engine on screen. `"css-highlights"` once it paints. `"dom"`
|
|
127
|
+
* before mount, where `CSS.highlights` is missing, until the color
|
|
128
|
+
* resolver loads, for good if that load fails, and with a custom
|
|
129
|
+
* default slot.
|
|
130
|
+
*/
|
|
131
|
+
resolvedEngine(): "dom" | "css-highlights";
|
|
132
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import type { HTMLAttributes } from "svelte/elements";
|
|
3
3
|
import type { ScopeEvent } from "./engine.d.ts";
|
|
4
|
-
import type { LangtagProps } from "./Highlight.svelte";
|
|
4
|
+
import type { CodeRegionProps, LangtagProps } from "./Highlight.svelte";
|
|
5
5
|
import type { LanguageName } from "./languages";
|
|
6
6
|
|
|
7
7
|
export type HighlightAutoProps = HTMLAttributes<HTMLPreElement> &
|
|
8
|
-
LangtagProps &
|
|
8
|
+
LangtagProps &
|
|
9
|
+
CodeRegionProps & {
|
|
9
10
|
/** Code to highlight. */
|
|
10
11
|
code: any;
|
|
11
12
|
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import LangTag from "./LangTag.svelte";
|
|
3
|
+
|
|
4
|
+
/** @type {any} */
|
|
5
|
+
export let code;
|
|
6
|
+
|
|
7
|
+
/** @type {(import("./languages").LanguageName | (string & {}))[] | undefined} */
|
|
8
|
+
export let languageNames = undefined;
|
|
9
|
+
|
|
10
|
+
/** @type {boolean} */
|
|
11
|
+
export let langtag = false;
|
|
12
|
+
|
|
13
|
+
/** @type {boolean} */
|
|
14
|
+
export let wrap = false;
|
|
15
|
+
|
|
16
|
+
import { afterUpdate, createEventDispatcher, onMount } from "svelte";
|
|
17
|
+
import { highlightAutoIfLoaded, highlightAutoLazy } from "./auto-detect.js";
|
|
18
|
+
import { escapeHtml, TEXT } from "./engine.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {{ highlighted: string; language: string; events: import("./engine.d.ts").ScopeEvent[]; secondBest?: { language: string | undefined; relevance: number } }} HighlightEventDetail
|
|
22
|
+
* @type {import("svelte").EventDispatcher<{ highlight: HighlightEventDetail}>}
|
|
23
|
+
*/
|
|
24
|
+
const dispatch = createEventDispatcher();
|
|
25
|
+
|
|
26
|
+
/** @type {string} */
|
|
27
|
+
let highlighted = "";
|
|
28
|
+
|
|
29
|
+
/** @type {string} */
|
|
30
|
+
let language = "";
|
|
31
|
+
|
|
32
|
+
/** @type {import("./engine.d.ts").ScopeEvent[]} */
|
|
33
|
+
let events = [];
|
|
34
|
+
|
|
35
|
+
/** @type {{ language: string | undefined; relevance: number } | undefined} */
|
|
36
|
+
let secondBest;
|
|
37
|
+
|
|
38
|
+
// True once `events` holds a detection result, not the plain-text
|
|
39
|
+
// placeholder. Only results dispatch `highlight`.
|
|
40
|
+
let detected = false;
|
|
41
|
+
|
|
42
|
+
/** @type {import("./engine.d.ts").ScopeEvent[] | undefined} */
|
|
43
|
+
let lastDispatchedEvents;
|
|
44
|
+
|
|
45
|
+
afterUpdate(() => {
|
|
46
|
+
if (detected && events !== lastDispatchedEvents) {
|
|
47
|
+
lastDispatchedEvents = events;
|
|
48
|
+
dispatch("highlight", { highlighted, language, events, secondBest });
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/** @param {string} source */
|
|
53
|
+
function showPlainText(source) {
|
|
54
|
+
highlighted = escapeHtml(source);
|
|
55
|
+
language = "";
|
|
56
|
+
events = [{ t: TEXT, v: source }];
|
|
57
|
+
secondBest = undefined;
|
|
58
|
+
detected = false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @param {import("./engine.d.ts").HighlightResult} result */
|
|
62
|
+
function showResult(result) {
|
|
63
|
+
highlighted = result.value;
|
|
64
|
+
language = result.language ?? "";
|
|
65
|
+
events = result.events;
|
|
66
|
+
secondBest = result.secondBest;
|
|
67
|
+
detected = true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Bumped on every run, so a slow load for older `code` can't overwrite
|
|
71
|
+
// the result for newer `code`.
|
|
72
|
+
let run = 0;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {string} source
|
|
76
|
+
* @param {string[] | undefined} names
|
|
77
|
+
*/
|
|
78
|
+
async function detect(source, names) {
|
|
79
|
+
const id = ++run;
|
|
80
|
+
const options = { languageNames: names };
|
|
81
|
+
const ready = highlightAutoIfLoaded(source, options);
|
|
82
|
+
if (ready) {
|
|
83
|
+
showResult(ready);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
showPlainText(source);
|
|
87
|
+
const result = await highlightAutoLazy(source, options);
|
|
88
|
+
if (id === run) showResult(result);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Server and first client render both show plain text, so hydration
|
|
92
|
+
// matches. Detection starts after mount.
|
|
93
|
+
let mounted = false;
|
|
94
|
+
onMount(() => {
|
|
95
|
+
mounted = true;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
$: source = String(code ?? "");
|
|
99
|
+
$: if (!mounted) showPlainText(source);
|
|
100
|
+
$: if (mounted) detect(source, languageNames);
|
|
101
|
+
</script>
|
|
102
|
+
|
|
103
|
+
<slot {highlighted} {langtag} {wrap} languageName={language} {events}>
|
|
104
|
+
<LangTag
|
|
105
|
+
{...$$restProps}
|
|
106
|
+
languageName={language}
|
|
107
|
+
{langtag}
|
|
108
|
+
{wrap}
|
|
109
|
+
{highlighted}
|
|
110
|
+
{code}
|
|
111
|
+
/>
|
|
112
|
+
</slot>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
import type { ScopeEvent } from "./engine.d.ts";
|
|
4
|
+
import type { CodeRegionProps, LangtagProps } from "./Highlight.svelte";
|
|
5
|
+
import type { LanguageName } from "./languages";
|
|
6
|
+
|
|
7
|
+
export type HighlightAutoLazyProps = HTMLAttributes<HTMLPreElement> &
|
|
8
|
+
LangtagProps &
|
|
9
|
+
CodeRegionProps & {
|
|
10
|
+
/** Code to highlight. */
|
|
11
|
+
code: any;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Detect among these grammars only. Skips the fingerprint step and
|
|
15
|
+
* loads each named grammar on demand. Use canonical names.
|
|
16
|
+
* @example ["javascript", "typescript"]
|
|
17
|
+
*/
|
|
18
|
+
languageNames?: (LanguageName | (string & {}))[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type HighlightAutoLazyEvents = {
|
|
22
|
+
/**
|
|
23
|
+
* Fires when a detection result renders. Does not fire for the
|
|
24
|
+
* plain-text placeholder shown during SSR and while grammars load.
|
|
25
|
+
*/
|
|
26
|
+
highlight: CustomEvent<{
|
|
27
|
+
/** The highlighted HTML. */
|
|
28
|
+
highlighted: string;
|
|
29
|
+
|
|
30
|
+
/** The detected language name, e.g. `"css"`. */
|
|
31
|
+
language: string;
|
|
32
|
+
|
|
33
|
+
/** Scope events behind `highlighted` (see `svelte-highlight/engine`). */
|
|
34
|
+
events: ScopeEvent[];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Runner-up candidate and its relevance score; `undefined` when no other
|
|
38
|
+
* candidate scored above zero.
|
|
39
|
+
*/
|
|
40
|
+
secondBest?: { language: string | undefined; relevance: number };
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type HighlightAutoLazySlots = {
|
|
45
|
+
default: {
|
|
46
|
+
/** The highlighted HTML. */
|
|
47
|
+
highlighted: string;
|
|
48
|
+
|
|
49
|
+
/** Scope events behind `highlighted` (see `svelte-highlight/engine`). */
|
|
50
|
+
events: ScopeEvent[];
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Like `HighlightAuto`, but does not import every grammar. It scores the
|
|
56
|
+
* code against a small fingerprint index, loads only a few likely
|
|
57
|
+
* grammars, and lets the relevance engine pick among them and every
|
|
58
|
+
* grammar already registered.
|
|
59
|
+
*
|
|
60
|
+
* Renders plain text during SSR and until the grammars load.
|
|
61
|
+
*/
|
|
62
|
+
export default class HighlightAutoLazy extends SvelteComponentTyped<
|
|
63
|
+
HighlightAutoLazyProps,
|
|
64
|
+
HighlightAutoLazyEvents,
|
|
65
|
+
HighlightAutoLazySlots
|
|
66
|
+
> {}
|