svelte-highlight 7.12.0 → 7.14.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 +193 -0
- package/AnsiOutput.svelte.d.ts +112 -0
- package/CodeWindow.svelte +110 -0
- package/CodeWindow.svelte.d.ts +136 -0
- package/CopyButton.svelte +2 -5
- package/CopyButton.svelte.d.ts +16 -20
- package/FileTabs.svelte +161 -0
- package/FileTabs.svelte.d.ts +96 -0
- package/Highlight.svelte +15 -25
- package/Highlight.svelte.d.ts +9 -10
- package/HighlightAuto.svelte +20 -25
- package/HighlightAuto.svelte.d.ts +2 -2
- package/HighlightEditable.svelte +385 -0
- package/HighlightEditable.svelte.d.ts +113 -0
- package/HighlightStyle.svelte +21 -6
- package/HighlightStyle.svelte.d.ts +22 -1
- package/HighlightSvelte.svelte +15 -23
- package/HighlightSvelte.svelte.d.ts +1 -1
- package/LangTag.svelte.d.ts +3 -3
- package/LineNumbers.svelte.d.ts +10 -10
- package/README.md +621 -0
- package/Typewriter.svelte +238 -0
- package/Typewriter.svelte.d.ts +65 -0
- package/action.d.ts +20 -0
- package/action.js +22 -0
- package/ansi.d.ts +36 -0
- package/ansi.js +198 -0
- package/core.js +22 -0
- package/highlighter.svelte.js +22 -0
- package/index.d.ts +10 -0
- package/index.js +8 -0
- package/languages/bibtex.js +2 -2
- package/languages/bicep.js +6 -0
- package/languages/blade.js +35 -1
- package/languages/caddy.js +1 -1
- package/languages/cairo.js +15 -0
- package/languages/clarity.js +1 -1
- package/languages/cue.js +31 -1
- package/languages/cypher.js +9 -0
- package/languages/d2.js +2 -2
- package/languages/dax.d.ts +2 -0
- package/languages/dax.js +75 -0
- package/languages/dhall.js +7 -0
- package/languages/dotenv.js +5 -1
- package/languages/fish.js +8 -0
- package/languages/gleam.js +7 -0
- package/languages/groq.js +19 -0
- package/languages/hcl.js +4 -1
- package/languages/hlsl.d.ts +2 -0
- package/languages/hlsl.js +88 -0
- package/languages/html.js +28 -0
- package/languages/index.d.ts +20 -0
- package/languages/index.js +10 -0
- package/languages/jq.d.ts +2 -0
- package/languages/jq.js +120 -0
- package/languages/jsonnet.js +9 -2
- package/languages/just.d.ts +2 -0
- package/languages/just.js +120 -0
- package/languages/kql.d.ts +2 -0
- package/languages/kql.js +122 -0
- package/languages/liquid.js +1 -0
- package/languages/logql.d.ts +2 -0
- package/languages/logql.js +82 -0
- package/languages/marko.js +84 -1
- package/languages/mdx.js +40 -1
- package/languages/move.js +20 -0
- package/languages/nickel.js +16 -1
- package/languages/nushell.js +23 -0
- package/languages/pkl.js +2 -1
- package/languages/prisma.js +2 -1
- package/languages/promql.js +35 -2
- package/languages/pug.js +22 -0
- package/languages/razor.js +64 -5
- package/languages/rego.d.ts +2 -0
- package/languages/rego.js +94 -0
- package/languages/rescript.js +70 -2
- package/languages/rst.d.ts +2 -0
- package/languages/rst.js +144 -0
- package/languages/solidity.js +2 -1
- package/languages/svelte.js +12 -3
- package/languages/templ.d.ts +2 -0
- package/languages/templ.js +254 -0
- package/languages/toml.js +3 -1
- package/languages/typst.d.ts +2 -0
- package/languages/typst.js +185 -0
- package/languages/v.js +24 -2
- package/languages/vue.js +4 -2
- package/languages/vyper.js +18 -0
- package/languages/wgsl.js +14 -0
- package/languages/zig.js +7 -0
- package/load-language.d.ts +9 -0
- package/load-language.js +15 -0
- package/package.json +11 -2
- package/preprocessor.js +373 -0
- package/scoped.d.ts +12 -0
- package/scoped.js +55 -24
- package/static.d.ts +36 -0
- package/static.js +1 -0
- package/styles/1c-light.css +1 -1
- package/styles/1c-light.js +1 -1
- package/styles/3024.css +1 -1
- package/styles/3024.js +1 -1
- package/styles/a11y-dark.css +1 -1
- package/styles/a11y-dark.js +1 -1
- package/styles/a11y-light.css +1 -1
- package/styles/a11y-light.js +1 -1
- package/styles/agate.css +1 -1
- package/styles/agate.js +1 -1
- package/styles/an-old-hope.css +1 -1
- package/styles/an-old-hope.js +1 -1
- package/styles/androidstudio.css +1 -1
- package/styles/androidstudio.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/arduino-light.css +1 -1
- package/styles/arduino-light.js +1 -1
- package/styles/arta.css +1 -1
- package/styles/arta.js +1 -1
- package/styles/ascetic.css +1 -1
- package/styles/ascetic.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/atom-one-dark-reasonable.css +1 -1
- package/styles/atom-one-dark-reasonable.js +1 -1
- package/styles/atom-one-dark.css +1 -1
- package/styles/atom-one-dark.js +1 -1
- package/styles/atom-one-light.css +1 -1
- package/styles/atom-one-light.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/brown-paper.css +1 -1
- package/styles/brown-paper.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/codepen-embed.css +1 -1
- package/styles/codepen-embed.js +1 -1
- package/styles/codeschool.css +1 -1
- package/styles/codeschool.js +1 -1
- package/styles/color-brewer.css +1 -1
- package/styles/color-brewer.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/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/dark.css +1 -1
- package/styles/dark.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/default.css +1 -1
- package/styles/default.js +1 -1
- package/styles/devibeans.css +1 -1
- package/styles/devibeans.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/far.css +1 -1
- package/styles/far.js +1 -1
- package/styles/felipec.css +1 -1
- package/styles/felipec.js +1 -1
- package/styles/flat.css +1 -1
- package/styles/flat.js +1 -1
- package/styles/foundation.css +1 -1
- package/styles/foundation.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/github-dark-dimmed.css +1 -1
- package/styles/github-dark-dimmed.js +1 -1
- package/styles/github-dark.css +1 -1
- package/styles/github-dark.js +1 -1
- package/styles/github.css +1 -1
- package/styles/github.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 -2
- package/styles/googlecode.js +1 -2
- package/styles/gradient-dark.css +2 -3
- package/styles/gradient-dark.js +2 -3
- package/styles/gradient-light.css +2 -3
- package/styles/gradient-light.js +2 -3
- 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/hybrid.css +1 -1
- package/styles/hybrid.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/isbl-editor-dark.css +1 -1
- package/styles/isbl-editor-dark.js +1 -1
- package/styles/isbl-editor-light.css +1 -1
- package/styles/isbl-editor-light.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/lightfair.css +1 -1
- package/styles/lightfair.js +1 -1
- package/styles/lioshi.css +1 -1
- package/styles/lioshi.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/magula.css +1 -2
- package/styles/magula.js +1 -2
- 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/mono-blue.css +1 -1
- package/styles/mono-blue.js +1 -1
- package/styles/monokai-sublime.css +1 -1
- package/styles/monokai-sublime.js +1 -1
- package/styles/monokai.css +1 -1
- package/styles/monokai.js +1 -1
- package/styles/nebula.css +1 -1
- package/styles/nebula.js +1 -1
- package/styles/night-owl.css +1 -1
- package/styles/night-owl.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/obsidian.css +1 -1
- package/styles/obsidian.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/panda-syntax-dark.css +1 -2
- package/styles/panda-syntax-dark.js +1 -2
- 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-dark.css +1 -1
- package/styles/paraiso-dark.js +1 -1
- package/styles/paraiso-light.css +1 -1
- package/styles/paraiso-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/purebasic.css +1 -1
- package/styles/purebasic.js +1 -1
- package/styles/qtcreator-dark.css +1 -1
- package/styles/qtcreator-dark.js +1 -1
- package/styles/qtcreator-light.css +1 -1
- package/styles/qtcreator-light.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/rainbow.css +1 -1
- package/styles/rainbow.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/rose-pine-dawn.css +1 -1
- package/styles/rose-pine-dawn.js +1 -1
- package/styles/rose-pine-moon.css +1 -1
- package/styles/rose-pine-moon.js +1 -1
- package/styles/rose-pine.css +1 -1
- package/styles/rose-pine.js +1 -1
- package/styles/routeros.css +1 -1
- package/styles/routeros.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/shades-of-purple.css +2 -3
- package/styles/shades-of-purple.js +2 -3
- 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/srcery.css +1 -1
- package/styles/srcery.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/sunburst.css +1 -1
- package/styles/sunburst.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/tokyo-night-dark.css +1 -2
- package/styles/tokyo-night-dark.js +1 -2
- package/styles/tokyo-night-light.css +1 -2
- package/styles/tokyo-night-light.js +1 -2
- package/styles/tomorrow-night-blue.css +1 -1
- package/styles/tomorrow-night-blue.js +1 -1
- package/styles/tomorrow-night-bright.css +1 -1
- package/styles/tomorrow-night-bright.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/vs.css +1 -1
- package/styles/vs.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
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/** @type {import("./languages").LanguageType<string>} */
|
|
3
|
+
export let language;
|
|
4
|
+
|
|
5
|
+
/** @type {string} */
|
|
6
|
+
export let code = "";
|
|
7
|
+
|
|
8
|
+
/** @type {number} Number of spaces inserted by the Tab key. */
|
|
9
|
+
export let tabSize = 2;
|
|
10
|
+
|
|
11
|
+
/** @type {number} Maximum number of undo snapshots retained. */
|
|
12
|
+
export let historyLimit = 200;
|
|
13
|
+
|
|
14
|
+
import hljs from "highlight.js/lib/core";
|
|
15
|
+
import { createEventDispatcher, onMount } from "svelte";
|
|
16
|
+
|
|
17
|
+
const dispatch = createEventDispatcher();
|
|
18
|
+
const TRAILING_NEWLINE = /\n$/;
|
|
19
|
+
|
|
20
|
+
/** @type {HTMLElement} */
|
|
21
|
+
let editor;
|
|
22
|
+
|
|
23
|
+
// Don't re-highlight during IME composition.
|
|
24
|
+
let composing = false;
|
|
25
|
+
let mounted = false;
|
|
26
|
+
let restoringSelection = false;
|
|
27
|
+
|
|
28
|
+
// Tracks `code` so parent updates vs local edits can be distinguished.
|
|
29
|
+
let internalCode = code;
|
|
30
|
+
|
|
31
|
+
$: hljs.registerLanguage(language.name, language.register);
|
|
32
|
+
$: indentUnit = " ".repeat(tabSize);
|
|
33
|
+
$: if (mounted && code !== internalCode) syncExternal();
|
|
34
|
+
|
|
35
|
+
function getSelectionRange() {
|
|
36
|
+
const selection = window.getSelection();
|
|
37
|
+
if (!selection || selection.rangeCount === 0) return null;
|
|
38
|
+
const range = selection.getRangeAt(0);
|
|
39
|
+
if (!editor.contains(range.commonAncestorContainer)) return null;
|
|
40
|
+
const pre = range.cloneRange();
|
|
41
|
+
pre.selectNodeContents(editor);
|
|
42
|
+
pre.setEnd(range.startContainer, range.startOffset);
|
|
43
|
+
const start = pre.toString().length;
|
|
44
|
+
return { start, end: start + range.toString().length };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getCaretOffset() {
|
|
48
|
+
const sel = getSelectionRange();
|
|
49
|
+
return sel ? sel.end : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function nodeAtOffset(offset) {
|
|
53
|
+
const walker = document.createTreeWalker(
|
|
54
|
+
editor,
|
|
55
|
+
NodeFilter.SHOW_TEXT,
|
|
56
|
+
null,
|
|
57
|
+
);
|
|
58
|
+
let count = 0;
|
|
59
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
60
|
+
const next = count + node.textContent.length;
|
|
61
|
+
if (offset <= next) return { node, offset: offset - count };
|
|
62
|
+
count = next;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function setSelection(start, end) {
|
|
68
|
+
const from = nodeAtOffset(start);
|
|
69
|
+
if (!from) return;
|
|
70
|
+
const range = document.createRange();
|
|
71
|
+
range.setStart(from.node, from.offset);
|
|
72
|
+
const to = end != null && end !== start ? nodeAtOffset(end) : null;
|
|
73
|
+
if (to) range.setEnd(to.node, to.offset);
|
|
74
|
+
else range.collapse(true);
|
|
75
|
+
const selection = window.getSelection();
|
|
76
|
+
selection.removeAllRanges();
|
|
77
|
+
selection.addRange(range);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function paint() {
|
|
81
|
+
const html = hljs.highlight(code, { language: language.name }).value;
|
|
82
|
+
// Trailing empty line needs a phantom `\n` for caret placement.
|
|
83
|
+
editor.innerHTML = code === "" || code.endsWith("\n") ? `${html}\n` : html;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function renderAt(start, end) {
|
|
87
|
+
paint();
|
|
88
|
+
if (start == null) return;
|
|
89
|
+
restoringSelection = true;
|
|
90
|
+
setSelection(start, end);
|
|
91
|
+
restoringSelection = false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function syncCaretToHistory() {
|
|
95
|
+
if (restoringSelection || composing || undoStack.length === 0) return;
|
|
96
|
+
const sel = getSelectionRange();
|
|
97
|
+
if (!sel) return;
|
|
98
|
+
const top = undoStack[undoStack.length - 1];
|
|
99
|
+
if (top.code !== code) return;
|
|
100
|
+
undoStack[undoStack.length - 1] = {
|
|
101
|
+
code: top.code,
|
|
102
|
+
start: sel.start,
|
|
103
|
+
end: sel.end,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** @type {Array<{ code: string; start: number; end: number }>} */
|
|
108
|
+
let undoStack = [];
|
|
109
|
+
/** @type {Array<{ code: string; start: number; end: number }>} */
|
|
110
|
+
let redoStack = [];
|
|
111
|
+
let lastRecord = 0;
|
|
112
|
+
|
|
113
|
+
function emitHistory() {
|
|
114
|
+
const future = redoStack.slice().reverse();
|
|
115
|
+
dispatch("history", {
|
|
116
|
+
entries: [...undoStack, ...future].map((snap) => ({
|
|
117
|
+
size: snap.code.length,
|
|
118
|
+
})),
|
|
119
|
+
index: undoStack.length - 1,
|
|
120
|
+
canUndo: canUndo(),
|
|
121
|
+
canRedo: canRedo(),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Coalesce typing within 250ms; Enter/Tab/paste pass coalesce=false.
|
|
126
|
+
function pushHistory(snap, coalesce) {
|
|
127
|
+
redoStack = [];
|
|
128
|
+
const now = Date.now();
|
|
129
|
+
if (coalesce && undoStack.length > 1 && now - lastRecord < 250) {
|
|
130
|
+
undoStack[undoStack.length - 1] = snap;
|
|
131
|
+
} else {
|
|
132
|
+
undoStack.push(snap);
|
|
133
|
+
const limit = Math.max(1, historyLimit);
|
|
134
|
+
if (undoStack.length > limit) {
|
|
135
|
+
undoStack.splice(0, undoStack.length - limit);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
lastRecord = coalesce ? now : 0;
|
|
139
|
+
emitHistory();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function applySnapshot(snap) {
|
|
143
|
+
code = snap.code;
|
|
144
|
+
internalCode = snap.code;
|
|
145
|
+
dispatch("change", { code });
|
|
146
|
+
emitHistory();
|
|
147
|
+
renderAt(snap.start, snap.end);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function commit(value, start, end, coalesce) {
|
|
151
|
+
code = value;
|
|
152
|
+
internalCode = value;
|
|
153
|
+
dispatch("change", { code });
|
|
154
|
+
pushHistory({ code: value, start, end }, coalesce);
|
|
155
|
+
renderAt(start, end);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function syncExternal() {
|
|
159
|
+
internalCode = code;
|
|
160
|
+
pushHistory({ code, start: code.length, end: code.length }, false);
|
|
161
|
+
paint();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function insertText(text) {
|
|
165
|
+
const sel = getSelectionRange();
|
|
166
|
+
if (!sel) return;
|
|
167
|
+
const value = code.slice(0, sel.start) + text + code.slice(sel.end);
|
|
168
|
+
commit(value, sel.start + text.length, undefined, false);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Indent/dedent selected lines; blank lines skipped on indent.
|
|
172
|
+
function shiftIndent(outdent) {
|
|
173
|
+
const sel = getSelectionRange();
|
|
174
|
+
if (!sel) return;
|
|
175
|
+
const blockStart = code.lastIndexOf("\n", sel.start - 1) + 1;
|
|
176
|
+
const lines = code.slice(blockStart, sel.end).split("\n");
|
|
177
|
+
|
|
178
|
+
let firstDelta = 0;
|
|
179
|
+
let totalDelta = 0;
|
|
180
|
+
const next = lines
|
|
181
|
+
.map((line, index) => {
|
|
182
|
+
if (outdent) {
|
|
183
|
+
const leading = line.length - line.trimStart().length;
|
|
184
|
+
const remove = Math.min(tabSize, leading);
|
|
185
|
+
if (index === 0) firstDelta = -remove;
|
|
186
|
+
totalDelta -= remove;
|
|
187
|
+
return line.slice(remove);
|
|
188
|
+
}
|
|
189
|
+
if (line.length === 0) return line;
|
|
190
|
+
if (index === 0) firstDelta = tabSize;
|
|
191
|
+
totalDelta += tabSize;
|
|
192
|
+
return indentUnit + line;
|
|
193
|
+
})
|
|
194
|
+
.join("\n");
|
|
195
|
+
|
|
196
|
+
if (totalDelta === 0) return;
|
|
197
|
+
const value = code.slice(0, blockStart) + next + code.slice(sel.end);
|
|
198
|
+
const start = Math.max(blockStart, sel.start + firstDelta);
|
|
199
|
+
commit(value, start, sel.end + totalDelta, false);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function indentCommand() {
|
|
203
|
+
const sel = getSelectionRange();
|
|
204
|
+
if (sel && code.slice(sel.start, sel.end).includes("\n"))
|
|
205
|
+
shiftIndent(false);
|
|
206
|
+
else insertText(indentUnit);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function ensureFocus() {
|
|
210
|
+
if (document.activeElement === editor) return;
|
|
211
|
+
// Restore selection after focus; default caret to end.
|
|
212
|
+
const prior = getSelectionRange();
|
|
213
|
+
editor.focus();
|
|
214
|
+
if (prior) setSelection(prior.start, prior.end);
|
|
215
|
+
else setSelection(code.length);
|
|
216
|
+
syncCaretToHistory();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function undo() {
|
|
220
|
+
if (undoStack.length <= 1) return;
|
|
221
|
+
redoStack.push(undoStack.pop());
|
|
222
|
+
applySnapshot(undoStack[undoStack.length - 1]);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function redo() {
|
|
226
|
+
if (redoStack.length === 0) return;
|
|
227
|
+
const snap = redoStack.pop();
|
|
228
|
+
undoStack.push(snap);
|
|
229
|
+
applySnapshot(snap);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function focus() {
|
|
233
|
+
editor.focus();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function selectAll() {
|
|
237
|
+
editor.focus();
|
|
238
|
+
setSelection(0, code.length);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function insert(text) {
|
|
242
|
+
ensureFocus();
|
|
243
|
+
insertText(text);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function indent() {
|
|
247
|
+
ensureFocus();
|
|
248
|
+
indentCommand();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function outdent() {
|
|
252
|
+
ensureFocus();
|
|
253
|
+
shiftIndent(true);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export function setCode(value) {
|
|
257
|
+
if (value === code) return;
|
|
258
|
+
internalCode = value;
|
|
259
|
+
code = value;
|
|
260
|
+
dispatch("change", { code });
|
|
261
|
+
pushHistory({ code: value, start: value.length, end: value.length }, false);
|
|
262
|
+
paint();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export function clear() {
|
|
266
|
+
setCode("");
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function getCode() {
|
|
270
|
+
return code;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export function canUndo() {
|
|
274
|
+
return undoStack.length > 1;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function canRedo() {
|
|
278
|
+
return redoStack.length > 0;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function onInput() {
|
|
282
|
+
if (composing) return;
|
|
283
|
+
// innerText keeps contenteditable line breaks; textContent doesn't.
|
|
284
|
+
code = editor.innerText.replace(TRAILING_NEWLINE, "");
|
|
285
|
+
internalCode = code;
|
|
286
|
+
const caret = getCaretOffset() ?? code.length;
|
|
287
|
+
dispatch("change", { code });
|
|
288
|
+
pushHistory({ code, start: caret, end: caret }, true);
|
|
289
|
+
renderAt(caret);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function onKeydown(event) {
|
|
293
|
+
const mod = event.metaKey || event.ctrlKey;
|
|
294
|
+
|
|
295
|
+
if (mod && event.key === "z" && !event.shiftKey) {
|
|
296
|
+
event.preventDefault();
|
|
297
|
+
undo();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (mod && (event.key === "y" || (event.key === "z" && event.shiftKey))) {
|
|
301
|
+
event.preventDefault();
|
|
302
|
+
redo();
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (event.key === "Enter") {
|
|
306
|
+
event.preventDefault();
|
|
307
|
+
insertText("\n");
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (event.key === "Tab") {
|
|
311
|
+
event.preventDefault();
|
|
312
|
+
if (event.shiftKey) shiftIndent(true);
|
|
313
|
+
else indentCommand();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function onPaste(event) {
|
|
318
|
+
event.preventDefault();
|
|
319
|
+
insertText(event.clipboardData?.getData("text/plain") ?? "");
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function onBlur() {
|
|
323
|
+
dispatch("blur", { code: getCode() });
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function onCompositionStart() {
|
|
327
|
+
composing = true;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function onCompositionEnd() {
|
|
331
|
+
composing = false;
|
|
332
|
+
onInput();
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
onMount(() => {
|
|
336
|
+
paint();
|
|
337
|
+
undoStack = [{ code, start: 0, end: 0 }];
|
|
338
|
+
mounted = true;
|
|
339
|
+
emitHistory();
|
|
340
|
+
|
|
341
|
+
editor.addEventListener("input", onInput);
|
|
342
|
+
editor.addEventListener("keydown", onKeydown);
|
|
343
|
+
editor.addEventListener("paste", onPaste);
|
|
344
|
+
editor.addEventListener("mouseup", syncCaretToHistory);
|
|
345
|
+
editor.addEventListener("keyup", syncCaretToHistory);
|
|
346
|
+
document.addEventListener("selectionchange", syncCaretToHistory);
|
|
347
|
+
editor.addEventListener("blur", onBlur);
|
|
348
|
+
editor.addEventListener("compositionstart", onCompositionStart);
|
|
349
|
+
editor.addEventListener("compositionend", onCompositionEnd);
|
|
350
|
+
|
|
351
|
+
return () => {
|
|
352
|
+
editor.removeEventListener("input", onInput);
|
|
353
|
+
editor.removeEventListener("keydown", onKeydown);
|
|
354
|
+
editor.removeEventListener("paste", onPaste);
|
|
355
|
+
editor.removeEventListener("mouseup", syncCaretToHistory);
|
|
356
|
+
editor.removeEventListener("keyup", syncCaretToHistory);
|
|
357
|
+
document.removeEventListener("selectionchange", syncCaretToHistory);
|
|
358
|
+
editor.removeEventListener("blur", onBlur);
|
|
359
|
+
editor.removeEventListener("compositionstart", onCompositionStart);
|
|
360
|
+
editor.removeEventListener("compositionend", onCompositionEnd);
|
|
361
|
+
};
|
|
362
|
+
});
|
|
363
|
+
</script>
|
|
364
|
+
|
|
365
|
+
<pre
|
|
366
|
+
style:overflow-x="var(--overflow-x, auto)"
|
|
367
|
+
style:border-radius="var(--border-radius, 0)"
|
|
368
|
+
{...$$restProps}
|
|
369
|
+
><code
|
|
370
|
+
bind:this={editor}
|
|
371
|
+
class:hljs={true}
|
|
372
|
+
contenteditable="true"
|
|
373
|
+
spellcheck="false"
|
|
374
|
+
></code></pre>
|
|
375
|
+
|
|
376
|
+
<style>
|
|
377
|
+
code {
|
|
378
|
+
outline: none;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
code:focus {
|
|
382
|
+
outline: var(--outline-width, 2px) solid var(--outline-color, #4589ff);
|
|
383
|
+
outline-offset: var(--outline-offset, -2px);
|
|
384
|
+
}
|
|
385
|
+
</style>
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
import type { LanguageType } from "./languages";
|
|
4
|
+
|
|
5
|
+
export type HighlightEditableProps = HTMLAttributes<HTMLPreElement> & {
|
|
6
|
+
/**
|
|
7
|
+
* Editable code (`bind:code`).
|
|
8
|
+
*/
|
|
9
|
+
code?: string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* highlight.js language module.
|
|
13
|
+
* Import languages from `svelte-highlight/languages/*`.
|
|
14
|
+
* @example
|
|
15
|
+
* import typescript from "svelte-highlight/languages/typescript";
|
|
16
|
+
*/
|
|
17
|
+
language: LanguageType<string>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Number of spaces inserted by the Tab key.
|
|
21
|
+
* @default 2
|
|
22
|
+
*/
|
|
23
|
+
tabSize?: number;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Maximum number of undo snapshots retained. Older snapshots are dropped
|
|
27
|
+
* once the limit is exceeded.
|
|
28
|
+
* @default 200
|
|
29
|
+
*/
|
|
30
|
+
historyLimit?: number;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Color of the focus outline.
|
|
34
|
+
* @default "#4589ff"
|
|
35
|
+
*/
|
|
36
|
+
"--outline-color"?: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Width of the focus outline.
|
|
40
|
+
* @default "2px"
|
|
41
|
+
*/
|
|
42
|
+
"--outline-width"?: string | number;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Offset of the focus outline.
|
|
46
|
+
* @default "-2px"
|
|
47
|
+
*/
|
|
48
|
+
"--outline-offset"?: string | number;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type HighlightEditableEvents = {
|
|
52
|
+
/**
|
|
53
|
+
* Fired on each edit with current plain-text code.
|
|
54
|
+
*/
|
|
55
|
+
change: CustomEvent<{ code: string }>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Fired when the editor loses focus with the current plain-text code.
|
|
59
|
+
*/
|
|
60
|
+
blur: CustomEvent<{ code: string }>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Undo/redo history. `entries` is oldest→newest; `index` is current.
|
|
64
|
+
*/
|
|
65
|
+
history: CustomEvent<{
|
|
66
|
+
entries: { size: number }[];
|
|
67
|
+
index: number;
|
|
68
|
+
canUndo: boolean;
|
|
69
|
+
canRedo: boolean;
|
|
70
|
+
}>;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default class HighlightEditable extends SvelteComponentTyped<
|
|
74
|
+
HighlightEditableProps,
|
|
75
|
+
HighlightEditableEvents,
|
|
76
|
+
Record<string, never>
|
|
77
|
+
> {
|
|
78
|
+
/** Undo to the previous history snapshot. */
|
|
79
|
+
undo(): void;
|
|
80
|
+
|
|
81
|
+
/** Redo the last undone history snapshot. */
|
|
82
|
+
redo(): void;
|
|
83
|
+
|
|
84
|
+
/** Focus the editor. */
|
|
85
|
+
focus(): void;
|
|
86
|
+
|
|
87
|
+
/** Select the entire document. */
|
|
88
|
+
selectAll(): void;
|
|
89
|
+
|
|
90
|
+
/** Insert text at the caret (replacing any selection). */
|
|
91
|
+
insert(text: string): void;
|
|
92
|
+
|
|
93
|
+
/** Indent the selected lines (or insert one indent at the caret). */
|
|
94
|
+
indent(): void;
|
|
95
|
+
|
|
96
|
+
/** Dedent the selected lines. */
|
|
97
|
+
outdent(): void;
|
|
98
|
+
|
|
99
|
+
/** Replace the entire document, recording it as an undo step. */
|
|
100
|
+
setCode(value: string): void;
|
|
101
|
+
|
|
102
|
+
/** Empty the document. */
|
|
103
|
+
clear(): void;
|
|
104
|
+
|
|
105
|
+
/** Read the current code. */
|
|
106
|
+
getCode(): string;
|
|
107
|
+
|
|
108
|
+
/** Whether an undo step is available. */
|
|
109
|
+
canUndo(): boolean;
|
|
110
|
+
|
|
111
|
+
/** Whether a redo step is available. */
|
|
112
|
+
canRedo(): boolean;
|
|
113
|
+
}
|
package/HighlightStyle.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { scopeClassFor, scopeStyle } from "./scoped.js";
|
|
2
|
+
import { dualStyle, scopeClassFor, scopeStyle } from "./scoped.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Theme CSS from `svelte-highlight/styles/<theme>`.
|
|
@@ -7,15 +7,30 @@
|
|
|
7
7
|
* import a11yDark from "svelte-highlight/styles/a11y-dark";
|
|
8
8
|
* @type {string}
|
|
9
9
|
*/
|
|
10
|
-
export let theme;
|
|
10
|
+
export let theme = undefined;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @type {string}
|
|
13
|
+
* Light theme CSS. With `dark`, overrides `theme`.
|
|
14
|
+
* @type {string | undefined}
|
|
15
|
+
*/
|
|
16
|
+
export let light = undefined;
|
|
17
|
+
|
|
18
|
+
/** Dark theme CSS; pair with `light`. */
|
|
19
|
+
export let dark = undefined;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Theme switch: `"auto"` | `"light"` | `"dark"` | CSS selector for dark.
|
|
23
|
+
* @type {"auto" | "light" | "dark" | string}
|
|
15
24
|
*/
|
|
16
|
-
export let
|
|
25
|
+
export let mode = "auto";
|
|
26
|
+
|
|
27
|
+
/** Scope class for prefixed selectors. */
|
|
28
|
+
export let scopeClass = scopeClassFor(theme ?? `${light}${dark}`);
|
|
17
29
|
|
|
18
|
-
$: style =
|
|
30
|
+
$: style =
|
|
31
|
+
light !== undefined && dark !== undefined
|
|
32
|
+
? dualStyle(light, dark, scopeClass, mode)
|
|
33
|
+
: scopeStyle(theme, scopeClass);
|
|
19
34
|
</script>
|
|
20
35
|
|
|
21
36
|
<svelte:head> {@html style} </svelte:head>
|
|
@@ -7,7 +7,28 @@ export type HighlightStyleProps = HTMLAttributes<HTMLDivElement> & {
|
|
|
7
7
|
* @example
|
|
8
8
|
* import a11yDark from "svelte-highlight/styles/a11y-dark";
|
|
9
9
|
*/
|
|
10
|
-
theme
|
|
10
|
+
theme?: string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Light theme CSS; pair with `dark` to emit both stylesheets and switch
|
|
14
|
+
* automatically. Takes precedence over `theme` when both `light` and `dark`
|
|
15
|
+
* are provided.
|
|
16
|
+
*/
|
|
17
|
+
light?: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Dark theme CSS; pair with `light` to emit both stylesheets.
|
|
21
|
+
*/
|
|
22
|
+
dark?: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* How to switch between `light` and `dark`:
|
|
26
|
+
* `"auto"` uses `prefers-color-scheme` media queries, `"light"`/`"dark"`
|
|
27
|
+
* force a single theme, and any other string is a CSS selector that gates
|
|
28
|
+
* the dark block (e.g. `[data-theme="dark"]`).
|
|
29
|
+
* @default "auto"
|
|
30
|
+
*/
|
|
31
|
+
mode?: "auto" | "light" | "dark" | (string & {});
|
|
11
32
|
|
|
12
33
|
/**
|
|
13
34
|
* Wrapper class the scoped selectors target.
|
package/HighlightSvelte.svelte
CHANGED
|
@@ -1,37 +1,29 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
import { createEventDispatcher } from "svelte";
|
|
3
|
+
import { highlightLanguage } from "./core.js";
|
|
4
|
+
import { createHighlighter } from "./highlighter.svelte.js";
|
|
2
5
|
import LangTag from "./LangTag.svelte";
|
|
3
|
-
|
|
4
|
-
/** @type {any} */
|
|
5
|
-
export let code;
|
|
6
|
-
|
|
7
|
-
/** @type {boolean} */
|
|
8
|
-
export let langtag = false;
|
|
9
|
-
|
|
10
|
-
import hljs from "highlight.js/lib/core";
|
|
11
|
-
import { afterUpdate, createEventDispatcher } from "svelte";
|
|
12
6
|
import svelte from "./languages/svelte";
|
|
13
7
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/** @type {string} */
|
|
17
|
-
let highlighted = "";
|
|
8
|
+
/** @type {{ code: any; langtag?: boolean; [key: string]: any }} */
|
|
9
|
+
let { code, langtag = false, ...restProps } = $props();
|
|
18
10
|
|
|
19
|
-
|
|
20
|
-
if (highlighted) dispatch("highlight", { highlighted });
|
|
21
|
-
});
|
|
11
|
+
const dispatch = createEventDispatcher();
|
|
22
12
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
highlighted
|
|
26
|
-
|
|
13
|
+
const core = createHighlighter(
|
|
14
|
+
() => highlightLanguage(svelte, code),
|
|
15
|
+
(highlighted) => {
|
|
16
|
+
if (highlighted) dispatch("highlight", { highlighted });
|
|
17
|
+
},
|
|
18
|
+
);
|
|
27
19
|
</script>
|
|
28
20
|
|
|
29
|
-
<slot {
|
|
21
|
+
<slot highlighted={core.value} {langtag} languageName="svelte">
|
|
30
22
|
<LangTag
|
|
31
|
-
{
|
|
23
|
+
{...restProps}
|
|
32
24
|
languageName="svelte"
|
|
33
25
|
{langtag}
|
|
34
|
-
{
|
|
26
|
+
highlighted={core.value}
|
|
35
27
|
{code}
|
|
36
28
|
/>
|
|
37
29
|
</slot>
|
package/LangTag.svelte.d.ts
CHANGED
|
@@ -6,17 +6,17 @@ import type { LanguageName } from "./languages";
|
|
|
6
6
|
export type LangTagProps = HTMLAttributes<HTMLPreElement> &
|
|
7
7
|
LangtagProps & {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Code to highlight.
|
|
10
10
|
*/
|
|
11
11
|
code: any;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Highlighted HTML.
|
|
15
15
|
*/
|
|
16
16
|
highlighted: string;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Language name.
|
|
20
20
|
* @default "plaintext"
|
|
21
21
|
*/
|
|
22
22
|
languageName?: LanguageName | (string & {});
|