@hraness/design-kit 0.31.1
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/ARTICLE_COPY.md +208 -0
- package/HERO_FIELDS.md +55 -0
- package/ICONS.md +56 -0
- package/LANTERN_MATERIAL.md +60 -0
- package/LICENSE +21 -0
- package/MARKETING_COPY.md +49 -0
- package/MARKETING_PRESET.md +108 -0
- package/PALETTES.md +90 -0
- package/PAPER_THEME.md +128 -0
- package/README.md +745 -0
- package/STATUS_PAGES.md +67 -0
- package/STYLE.md +245 -0
- package/WRITING.md +72 -0
- package/dist/browser/index.js +2345 -0
- package/dist/chunk-44djxk16.js +6872 -0
- package/dist/chunk-5gtx3pza.js +9 -0
- package/dist/chunk-77391vmq.js +454 -0
- package/dist/chunk-7b1586eb.js +1209 -0
- package/dist/chunk-8834fh4n.js +6 -0
- package/dist/chunk-9t8xyqte.js +870 -0
- package/dist/chunk-cejpzyfh.js +446 -0
- package/dist/chunk-eh71jz57.js +429 -0
- package/dist/chunk-evb02bc1.js +516 -0
- package/dist/chunk-h4k7yv6x.js +368 -0
- package/dist/chunk-he8eznb1.js +760 -0
- package/dist/chunk-mr1vdcjq.js +404 -0
- package/dist/chunk-wzvdn8ey.js +116 -0
- package/dist/fonts/nebula-sans/social-fonts.generated.js +53 -0
- package/dist/icons.js +48 -0
- package/dist/index.js +237 -0
- package/dist/launch.js +41 -0
- package/dist/mockups/client.js +422 -0
- package/dist/mockups/index.js +1850 -0
- package/dist/portfolio.js +1549 -0
- package/dist/provider-marks.js +19 -0
- package/dist/react/charts.js +11 -0
- package/dist/react/hero-backdrop.js +8 -0
- package/dist/react/index.js +7252 -0
- package/dist/react/platform-install.js +10 -0
- package/dist/react/server.js +137 -0
- package/dist/stylex-manifest.json +1 -0
- package/dist/stylex.css +5392 -0
- package/dist/syntax-highlighting.js +15 -0
- package/dist/testing.js +250 -0
- package/package.json +377 -0
- package/portfolio-inventory.json +31 -0
- package/scripts/check-lantern-material-snapshot.d.mts +26 -0
- package/scripts/check-lantern-material-snapshot.mjs +126 -0
- package/scripts/check-marketing-snapshot.d.mts +12 -0
- package/scripts/check-marketing-snapshot.mjs +58 -0
- package/scripts/lantern-material-snapshot.ts +101 -0
- package/scripts/marketing-textures.ts +48 -0
- package/scripts/paper-theme-snapshot.ts +97 -0
- package/scripts/product-marketing-snapshot.ts +149 -0
- package/src/appearance-menu.css +266 -0
- package/src/appearance.ts +32 -0
- package/src/article-html.ts +269 -0
- package/src/article.ts +686 -0
- package/src/browser/appearance-menu.ts +604 -0
- package/src/browser/artifact-share.ts +164 -0
- package/src/browser/design-palette.ts +197 -0
- package/src/browser/foil.ts +124 -0
- package/src/browser/hero-light.ts +11 -0
- package/src/browser/index.ts +29 -0
- package/src/browser/status-field.ts +432 -0
- package/src/browser/status-page.ts +100 -0
- package/src/browser/sticky-offset.ts +82 -0
- package/src/browser/theme-color-sync.ts +213 -0
- package/src/charts.css +7 -0
- package/src/compiler-components.css +34 -0
- package/src/compiler-foundation.css +18 -0
- package/src/compiler-palettes.css +7 -0
- package/src/compiler-tokens.css +342 -0
- package/src/components.css +3 -0
- package/src/design-gallery.css +431 -0
- package/src/effects.css +14 -0
- package/src/fonts/geist-mono/GeistMono[wght].woff2 +0 -0
- package/src/fonts/geist-mono/OFL.txt +93 -0
- package/src/fonts/geist-mono/PROVENANCE.md +12 -0
- package/src/fonts/instrument-serif/OFL.txt +93 -0
- package/src/fonts/instrument-serif/UPSTREAM.md +14 -0
- package/src/fonts/instrument-serif/instrument-serif-latin-400.woff2 +0 -0
- package/src/fonts/nebula-sans/LICENSE.txt +96 -0
- package/src/fonts/nebula-sans/NebulaSans-Black.woff2 +0 -0
- package/src/fonts/nebula-sans/NebulaSans-BlackItalic.woff2 +0 -0
- package/src/fonts/nebula-sans/NebulaSans-Bold.otf +0 -0
- package/src/fonts/nebula-sans/NebulaSans-Bold.woff2 +0 -0
- package/src/fonts/nebula-sans/NebulaSans-BoldItalic.woff2 +0 -0
- package/src/fonts/nebula-sans/NebulaSans-Book.otf +0 -0
- package/src/fonts/nebula-sans/NebulaSans-Book.woff2 +0 -0
- package/src/fonts/nebula-sans/NebulaSans-BookItalic.woff2 +0 -0
- package/src/fonts/nebula-sans/NebulaSans-Light.woff2 +0 -0
- package/src/fonts/nebula-sans/NebulaSans-LightItalic.woff2 +0 -0
- package/src/fonts/nebula-sans/NebulaSans-Medium.woff2 +0 -0
- package/src/fonts/nebula-sans/NebulaSans-MediumItalic.woff2 +0 -0
- package/src/fonts/nebula-sans/NebulaSans-Semibold.woff2 +0 -0
- package/src/fonts/nebula-sans/NebulaSans-SemiboldItalic.woff2 +0 -0
- package/src/fonts/nebula-sans/PROVENANCE.md +14 -0
- package/src/fonts/nebula-sans/social-fonts.generated.ts +3873 -0
- package/src/fonts.css +106 -0
- package/src/icons/act60/act60.svg +5 -0
- package/src/icons/act60/application.svg +9 -0
- package/src/icons/act60/chapter-compare.svg +3 -0
- package/src/icons/act60/decree-residence.svg +6 -0
- package/src/icons/act60/estimate.svg +7 -0
- package/src/icons/act60/export-services.svg +4 -0
- package/src/icons/act60/investor.svg +13 -0
- package/src/icons/act60/presence.svg +7 -0
- package/src/icons/aicharts/aicharts.svg +6 -0
- package/src/icons/aicharts/cost-compare.svg +4 -0
- package/src/icons/aicharts/task-audio.svg +7 -0
- package/src/icons/aicharts/task-coding.svg +6 -0
- package/src/icons/aicharts/task-images.svg +3 -0
- package/src/icons/aicharts/task-reasoning.svg +9 -0
- package/src/icons/aicharts/task-research.svg +5 -0
- package/src/icons/aicharts/task-video.svg +4 -0
- package/src/icons/manifest.json +1371 -0
- package/src/icons/platonik/conversation.svg +3 -0
- package/src/icons/platonik/creature.svg +7 -0
- package/src/icons/platonik/economy.svg +4 -0
- package/src/icons/platonik/keep-light.svg +6 -0
- package/src/icons/platonik/platonik.svg +7 -0
- package/src/icons/platonik/spark-route.svg +15 -0
- package/src/icons/receipts/act60-retry.receipt.json +888 -0
- package/src/icons/receipts/act60.receipt.json +1366 -0
- package/src/icons/receipts/aicharts.receipt.json +1546 -0
- package/src/icons/receipts/platonik.receipt.json +1011 -0
- package/src/icons/receipts/roughday.receipt.json +770 -0
- package/src/icons/receipts/shared.receipt.json +1296 -0
- package/src/icons/receipts/slopcamera.receipt.json +1495 -0
- package/src/icons/receipts/soundfish-retry.receipt.json +460 -0
- package/src/icons/receipts/soundfish.receipt.json +1709 -0
- package/src/icons/receipts/sponge.receipt.json +1743 -0
- package/src/icons/receipts/stripe-history-retry.receipt.json +145 -0
- package/src/icons/receipts/stripe-history.receipt.json +1202 -0
- package/src/icons/receipts/wordcell.receipt.json +1924 -0
- package/src/icons/roughday/finance.svg +7 -0
- package/src/icons/roughday/roughday.svg +6 -0
- package/src/icons/roughday/technology.svg +4 -0
- package/src/icons/roughday/world.svg +4 -0
- package/src/icons/sets/act60.json +63 -0
- package/src/icons/sets/aicharts.json +63 -0
- package/src/icons/sets/platonik.json +39 -0
- package/src/icons/sets/roughday.json +25 -0
- package/src/icons/sets/shared.json +12 -0
- package/src/icons/sets/slopcamera.json +47 -0
- package/src/icons/sets/soundfish.json +43 -0
- package/src/icons/sets/sponge.json +51 -0
- package/src/icons/sets/stripe-history.json +39 -0
- package/src/icons/sets/wordcell.json +51 -0
- package/src/icons/shared/agent-skill.svg +4 -0
- package/src/icons/shared/cli.svg +5 -0
- package/src/icons/shared/privacy.svg +3 -0
- package/src/icons/shared/research.svg +7 -0
- package/src/icons/shared/sdk.svg +3 -0
- package/src/icons/slopcamera/diagram.svg +3 -0
- package/src/icons/slopcamera/direct-scene.svg +5 -0
- package/src/icons/slopcamera/edit-video.svg +17 -0
- package/src/icons/slopcamera/mcp.svg +3 -0
- package/src/icons/slopcamera/native-world.svg +3 -0
- package/src/icons/slopcamera/slopcamera.svg +11 -0
- package/src/icons/soundfish/agent-ui.svg +7 -0
- package/src/icons/soundfish/collaborate.svg +5 -0
- package/src/icons/soundfish/compose.svg +3 -0
- package/src/icons/soundfish/hear.svg +6 -0
- package/src/icons/soundfish/human-ui.svg +6 -0
- package/src/icons/soundfish/share.svg +3 -0
- package/src/icons/soundfish/soundfish.svg +6 -0
- package/src/icons/sponge/api.svg +3 -0
- package/src/icons/sponge/documents.svg +3 -0
- package/src/icons/sponge/library.svg +3 -0
- package/src/icons/sponge/one-question.svg +5 -0
- package/src/icons/sponge/people-direct.svg +5 -0
- package/src/icons/sponge/read.svg +3 -0
- package/src/icons/sponge/save.svg +4 -0
- package/src/icons/sponge/sponge.svg +7 -0
- package/src/icons/stripe-history/company-history.svg +3 -0
- package/src/icons/stripe-history/evidence.svg +4 -0
- package/src/icons/stripe-history/independence.svg +7 -0
- package/src/icons/stripe-history/publications.svg +11 -0
- package/src/icons/stripe-history/sources.svg +6 -0
- package/src/icons/stripe-history/stripe-history.svg +3 -0
- package/src/icons/wordcell/backlinks.svg +6 -0
- package/src/icons/wordcell/capture.svg +6 -0
- package/src/icons/wordcell/git-provenance.svg +4 -0
- package/src/icons/wordcell/kb.svg +4 -0
- package/src/icons/wordcell/markdown.svg +4 -0
- package/src/icons/wordcell/scopes.svg +3 -0
- package/src/icons/wordcell/search.svg +7 -0
- package/src/icons.generated.ts +734 -0
- package/src/icons.ts +51 -0
- package/src/index.ts +275 -0
- package/src/lantern-material.css +213 -0
- package/src/launch.ts +624 -0
- package/src/marketing-assets/UPSTREAM.md +18 -0
- package/src/marketing-assets/cells.svg +1 -0
- package/src/marketing-assets/grain.svg +1 -0
- package/src/marketing-forced-colors.css +12 -0
- package/src/mockups/client.tsx +415 -0
- package/src/mockups/core.tsx +318 -0
- package/src/mockups/frames.tsx +368 -0
- package/src/mockups/index.ts +14 -0
- package/src/mockups/surfaces.tsx +681 -0
- package/src/mockups.css +2607 -0
- package/src/palette-appearance.ts +45 -0
- package/src/palette-bridge.css +124 -0
- package/src/palette-color.ts +41 -0
- package/src/palette-system.css +721 -0
- package/src/palette-themes.ts +23 -0
- package/src/palette-tokens.stylex.ts +519 -0
- package/src/palettes.css +3 -0
- package/src/palettes.ts +161 -0
- package/src/paper-theme.css +244 -0
- package/src/plain-publication.css +1241 -0
- package/src/plain-site.css +397 -0
- package/src/platforms.ts +151 -0
- package/src/portfolio.generated.json +1595 -0
- package/src/portfolio.generated.ts +1596 -0
- package/src/portfolio.ts +226 -0
- package/src/product-marketing-foundation.css +433 -0
- package/src/product-marketing-preset.css +261 -0
- package/src/product-marketing.css +2186 -0
- package/src/provider-marks.generated.ts +112 -0
- package/src/provider-marks.ts +143 -0
- package/src/react/animated-rail-stage.stylex.ts +15 -0
- package/src/react/animated-rail-stage.tsx +51 -0
- package/src/react/app-shell.stylex.ts +104 -0
- package/src/react/app-shell.tsx +121 -0
- package/src/react/article.tsx +602 -0
- package/src/react/aurora-dots-background.tsx +34 -0
- package/src/react/charts.stylex.ts +563 -0
- package/src/react/charts.tsx +610 -0
- package/src/react/chat.stylex.ts +34 -0
- package/src/react/chat.tsx +155 -0
- package/src/react/design-gallery.tsx +943 -0
- package/src/react/design-palette.stylex.ts +124 -0
- package/src/react/design-palette.tsx +196 -0
- package/src/react/design-theme-context.tsx +41 -0
- package/src/react/effects.stylex.ts +325 -0
- package/src/react/fader.stylex.ts +71 -0
- package/src/react/fader.tsx +151 -0
- package/src/react/foil-card-math.ts +100 -0
- package/src/react/foil-card-surface.stylex.ts +326 -0
- package/src/react/foil-card-surface.tsx +742 -0
- package/src/react/foil-mark.tsx +35 -0
- package/src/react/foil.stylex.ts +163 -0
- package/src/react/haptics.ts +228 -0
- package/src/react/hero-backdrop.tsx +22 -0
- package/src/react/index.ts +38 -0
- package/src/react/keyboard-shortcuts.ts +228 -0
- package/src/react/lantern-material-gallery.tsx +166 -0
- package/src/react/lantern-material.stylex.ts +39 -0
- package/src/react/launch-beats.tsx +73 -0
- package/src/react/navigation-rail.stylex.ts +130 -0
- package/src/react/navigation-rail.tsx +228 -0
- package/src/react/particle-halo.tsx +115 -0
- package/src/react/phaser-dots.tsx +501 -0
- package/src/react/platform-icons.tsx +94 -0
- package/src/react/platform-install.stylex.ts +385 -0
- package/src/react/platform-install.tsx +389 -0
- package/src/react/playback-transport.stylex.ts +14 -0
- package/src/react/playback-transport.tsx +112 -0
- package/src/react/procedural-backdrop.tsx +192 -0
- package/src/react/procedural-recipe.ts +323 -0
- package/src/react/product-marketing.stylex.ts +4469 -0
- package/src/react/product-marketing.tsx +1611 -0
- package/src/react/production-data-preview-notice.stylex.ts +40 -0
- package/src/react/production-data-preview-notice.tsx +34 -0
- package/src/react/provider-mark.stylex.ts +132 -0
- package/src/react/provider-mark.tsx +120 -0
- package/src/react/relative-time.tsx +117 -0
- package/src/react/route-state.stylex.ts +39 -0
- package/src/react/route-state.tsx +350 -0
- package/src/react/server.ts +11 -0
- package/src/react/social-kit-panel.tsx +103 -0
- package/src/react/sticky-offset.tsx +33 -0
- package/src/react/surfaces.stylex.ts +179 -0
- package/src/react/surfaces.tsx +330 -0
- package/src/react/syntax-code.tsx +33 -0
- package/src/react/theme-color-sync.ts +1 -0
- package/src/react/theme-resolution.ts +11 -0
- package/src/react/theme.stylex.ts +276 -0
- package/src/react/theme.tsx +402 -0
- package/src/reading.css +72 -0
- package/src/relative-time.ts +185 -0
- package/src/reset.css +2 -0
- package/src/site-shell.css +16 -0
- package/src/status-page-html.ts +63 -0
- package/src/status-page.css +276 -0
- package/src/status-page.ts +323 -0
- package/src/styles.css +21 -0
- package/src/syntax-code-lexers.ts +303 -0
- package/src/syntax-highlighting.css +78 -0
- package/src/syntax-highlighting.ts +477 -0
- package/src/syntax-tokens.ts +33 -0
- package/src/testing.ts +307 -0
- package/src/tokens.css +3 -0
- package/src/typography.css +86 -0
- package/vendor/evilcharts/LICENSE +21 -0
- package/vendor/evilcharts/UPSTREAM.md +14 -0
- package/vendor/platform-marks/LICENSE +30 -0
- package/vendor/platform-marks/UPSTREAM.md +15 -0
- package/vendor/platform-marks/apple.svg +1 -0
- package/vendor/platform-marks/linux.svg +1 -0
- package/vendor/provider-marks/CRUSH-LICENSE.md +134 -0
- package/vendor/provider-marks/LICENSE +21 -0
- package/vendor/provider-marks/UPSTREAM.md +27 -0
- package/vendor/provider-marks/aider.svg +3 -0
- package/vendor/provider-marks/crush-heartbit.svg +8 -0
- package/vendor/provider-marks/lobehub/alibabacloud-color.svg +1 -0
- package/vendor/provider-marks/lobehub/alibabacloud.svg +1 -0
- package/vendor/provider-marks/lobehub/amp-color.svg +1 -0
- package/vendor/provider-marks/lobehub/amp.svg +1 -0
- package/vendor/provider-marks/lobehub/anthropic.svg +1 -0
- package/vendor/provider-marks/lobehub/claude-color.svg +1 -0
- package/vendor/provider-marks/lobehub/claude.svg +1 -0
- package/vendor/provider-marks/lobehub/claudecode-color.svg +1 -0
- package/vendor/provider-marks/lobehub/claudecode.svg +1 -0
- package/vendor/provider-marks/lobehub/codex-color.svg +1 -0
- package/vendor/provider-marks/lobehub/codex.svg +1 -0
- package/vendor/provider-marks/lobehub/cursor.svg +1 -0
- package/vendor/provider-marks/lobehub/deepseek-color.svg +1 -0
- package/vendor/provider-marks/lobehub/deepseek.svg +1 -0
- package/vendor/provider-marks/lobehub/devin-color.svg +1 -0
- package/vendor/provider-marks/lobehub/devin.svg +1 -0
- package/vendor/provider-marks/lobehub/gemini-color.svg +1 -0
- package/vendor/provider-marks/lobehub/gemini.svg +1 -0
- package/vendor/provider-marks/lobehub/geminicli-color.svg +1 -0
- package/vendor/provider-marks/lobehub/geminicli.svg +1 -0
- package/vendor/provider-marks/lobehub/goose.svg +1 -0
- package/vendor/provider-marks/lobehub/meta-color.svg +1 -0
- package/vendor/provider-marks/lobehub/meta.svg +1 -0
- package/vendor/provider-marks/lobehub/mistral-color.svg +1 -0
- package/vendor/provider-marks/lobehub/mistral.svg +1 -0
- package/vendor/provider-marks/lobehub/moonshot.svg +1 -0
- package/vendor/provider-marks/lobehub/nvidia-color.svg +1 -0
- package/vendor/provider-marks/lobehub/nvidia.svg +1 -0
- package/vendor/provider-marks/lobehub/openai.svg +1 -0
- package/vendor/provider-marks/lobehub/opencode.svg +1 -0
- package/vendor/provider-marks/lobehub/perplexity-color.svg +1 -0
- package/vendor/provider-marks/lobehub/perplexity.svg +1 -0
- package/vendor/provider-marks/lobehub/qwen-color.svg +1 -0
- package/vendor/provider-marks/lobehub/qwen.svg +1 -0
- package/vendor/provider-marks/lobehub/xai.svg +1 -0
- package/vendor/provider-marks/lobehub/zai.svg +1 -0
|
@@ -0,0 +1,760 @@
|
|
|
1
|
+
// src/syntax-highlighting.ts
|
|
2
|
+
import { highlight } from "sugar-high";
|
|
3
|
+
|
|
4
|
+
// src/syntax-tokens.ts
|
|
5
|
+
function escapeHtml(value) {
|
|
6
|
+
return value.replace(/[&<>"']/gu, (character) => {
|
|
7
|
+
switch (character) {
|
|
8
|
+
case "&":
|
|
9
|
+
return "&";
|
|
10
|
+
case "<":
|
|
11
|
+
return "<";
|
|
12
|
+
case ">":
|
|
13
|
+
return ">";
|
|
14
|
+
case '"':
|
|
15
|
+
return """;
|
|
16
|
+
case "'":
|
|
17
|
+
return "'";
|
|
18
|
+
default:
|
|
19
|
+
return character;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function token(kind, value) {
|
|
24
|
+
return `<span class="syntax-token syntax-token--${kind}">${escapeHtml(value)}</span>`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/syntax-code-lexers.ts
|
|
28
|
+
var rustKeywords = new Set("as async await break const continue crate dyn else enum extern false fn for if impl in let loop match mod move mut pub ref return self Self static struct super trait true type unsafe use where while union yield".split(" "));
|
|
29
|
+
var rustTypes = new Set("bool char str usize isize u8 u16 u32 u64 u128 i8 i16 i32 i64 i128 f32 f64".split(" "));
|
|
30
|
+
var leanKeywords = new Set("abbrev axiom by case class deriving do else end example exists export false for forall fun have if import in inductive instance let match namespace noncomputable opaque open partial private protected public return section simp simpa structure termination_by theorem then true universe variable where with def".split(" "));
|
|
31
|
+
var tlaKeywords = new Set("ACTION ASSUME ASSUMPTION AXIOM BOOLEAN BY CASE CHOOSE CONSTANT CONSTANTS COROLLARY DEF DEFINE DEFS DOMAIN ELSE ENABLED EXCEPT EXTENDS FALSE HAVE HIDE IF IN INSTANCE LAMBDA LEMMA LET LOCAL MODULE NEW OBVIOUS OMITTED ONLY OTHER PICK PROOF PROPOSITION PROVE QED RECURSIVE STATE SUBSET SUFFICES TAKE TEMPORAL THEOREM THEN TRUE UNCHANGED UNION USE VARIABLE VARIABLES WITH WITNESS".split(" "));
|
|
32
|
+
function matchAt(pattern, source, cursor) {
|
|
33
|
+
pattern.lastIndex = cursor;
|
|
34
|
+
return pattern.exec(source)?.[0] ?? "";
|
|
35
|
+
}
|
|
36
|
+
function lineEnd(source, start) {
|
|
37
|
+
let cursor = start;
|
|
38
|
+
while (cursor < source.length && source[cursor] !== `
|
|
39
|
+
` && source[cursor] !== "\r")
|
|
40
|
+
cursor += 1;
|
|
41
|
+
return cursor;
|
|
42
|
+
}
|
|
43
|
+
function blockCommentEnd(source, start, open, close) {
|
|
44
|
+
let cursor = start + open.length;
|
|
45
|
+
let depth = 1;
|
|
46
|
+
while (cursor < source.length) {
|
|
47
|
+
if (source.startsWith(open, cursor)) {
|
|
48
|
+
depth += 1;
|
|
49
|
+
cursor += open.length;
|
|
50
|
+
} else if (source.startsWith(close, cursor)) {
|
|
51
|
+
depth -= 1;
|
|
52
|
+
cursor += close.length;
|
|
53
|
+
if (depth === 0)
|
|
54
|
+
return cursor;
|
|
55
|
+
} else
|
|
56
|
+
cursor += 1;
|
|
57
|
+
}
|
|
58
|
+
return cursor;
|
|
59
|
+
}
|
|
60
|
+
function rustRawStringEnd(source, start) {
|
|
61
|
+
let cursor = start;
|
|
62
|
+
if (source.startsWith("br", cursor) || source.startsWith("cr", cursor))
|
|
63
|
+
cursor += 1;
|
|
64
|
+
if (source[cursor] !== "r")
|
|
65
|
+
return null;
|
|
66
|
+
cursor += 1;
|
|
67
|
+
const hashesStart = cursor;
|
|
68
|
+
while (source[cursor] === "#")
|
|
69
|
+
cursor += 1;
|
|
70
|
+
const hashes = cursor - hashesStart;
|
|
71
|
+
if (source[cursor] !== '"')
|
|
72
|
+
return null;
|
|
73
|
+
cursor += 1;
|
|
74
|
+
while (cursor < source.length) {
|
|
75
|
+
if (source[cursor++] !== '"')
|
|
76
|
+
continue;
|
|
77
|
+
let seen = 0;
|
|
78
|
+
while (seen < hashes && source[cursor] === "#") {
|
|
79
|
+
seen += 1;
|
|
80
|
+
cursor += 1;
|
|
81
|
+
}
|
|
82
|
+
if (seen === hashes)
|
|
83
|
+
return cursor;
|
|
84
|
+
}
|
|
85
|
+
return cursor;
|
|
86
|
+
}
|
|
87
|
+
function quotedEnd(source, start, quote, escapes, doubled = false) {
|
|
88
|
+
let cursor = start + 1;
|
|
89
|
+
while (cursor < source.length) {
|
|
90
|
+
const character = source[cursor++];
|
|
91
|
+
if (escapes && character === "\\" && cursor < source.length)
|
|
92
|
+
cursor += 1;
|
|
93
|
+
else if (character === quote) {
|
|
94
|
+
if (doubled && source[cursor] === quote)
|
|
95
|
+
cursor += 1;
|
|
96
|
+
else
|
|
97
|
+
return cursor;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return cursor;
|
|
101
|
+
}
|
|
102
|
+
function followingCharacter(source, start) {
|
|
103
|
+
let cursor = start;
|
|
104
|
+
while (/\s/u.test(source[cursor] ?? "") && cursor < source.length)
|
|
105
|
+
cursor += 1;
|
|
106
|
+
return source[cursor] ?? "";
|
|
107
|
+
}
|
|
108
|
+
function identifierAt(source, start) {
|
|
109
|
+
let cursor = start;
|
|
110
|
+
while (cursor < source.length) {
|
|
111
|
+
const code = source.codePointAt(cursor) ?? 0;
|
|
112
|
+
const ascii = code === 95 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || cursor > start && code >= 48 && code <= 57;
|
|
113
|
+
if (!ascii && (code < 128 || /[\s«»∀∃→←↔∧∨¬≤≥≠∈]/u.test(String.fromCodePoint(code))))
|
|
114
|
+
break;
|
|
115
|
+
cursor += code > 65535 ? 2 : 1;
|
|
116
|
+
}
|
|
117
|
+
return source.slice(start, cursor);
|
|
118
|
+
}
|
|
119
|
+
function highlightProgram(source, language) {
|
|
120
|
+
const html = [];
|
|
121
|
+
const numbers = /(?:0[xX][0-9a-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|[0-9][0-9_]*(?:\.(?![.A-Za-z_\u0080-\u{10ffff}])[0-9_]*)?(?:[eE][+-]?[0-9_]+)?)(?:[iu](?:8|16|32|64|128|size)|f(?:32|64))?/uy;
|
|
122
|
+
const rustCharacters = /b?'(?:\\(?:[nrt0\\'"]|x[0-9a-fA-F]{2}|u\{[0-9a-fA-F_]{1,6}\})|[^'\\\r\n])'/uy;
|
|
123
|
+
const tlaWords = /\\[A-Za-z]+/y;
|
|
124
|
+
const keywords = language === "rust" ? rustKeywords : language === "lean" ? leanKeywords : tlaKeywords;
|
|
125
|
+
const lineComment = language === "rust" ? "//" : language === "lean" ? "--" : "\\*";
|
|
126
|
+
const openComment = language === "rust" ? "/*" : language === "lean" ? "/-" : "(*";
|
|
127
|
+
const closeComment = language === "rust" ? "*/" : language === "lean" ? "-/" : "*)";
|
|
128
|
+
let cursor = 0;
|
|
129
|
+
const emit = (kind, end) => {
|
|
130
|
+
html.push(token(kind, source.slice(cursor, end)));
|
|
131
|
+
cursor = end;
|
|
132
|
+
};
|
|
133
|
+
while (cursor < source.length) {
|
|
134
|
+
if (source.startsWith(lineComment, cursor)) {
|
|
135
|
+
emit("comment", lineEnd(source, cursor));
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (source.startsWith(openComment, cursor)) {
|
|
139
|
+
emit("comment", blockCommentEnd(source, cursor, openComment, closeComment));
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (language === "rust") {
|
|
143
|
+
const rawEnd = rustRawStringEnd(source, cursor);
|
|
144
|
+
if (rawEnd !== null) {
|
|
145
|
+
emit("string", rawEnd);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const character2 = matchAt(rustCharacters, source, cursor);
|
|
149
|
+
if (character2 !== "") {
|
|
150
|
+
emit("string", cursor + character2.length);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const lifetime = source[cursor] === "'" ? identifierAt(source, cursor + 1) : "";
|
|
154
|
+
if (lifetime !== "") {
|
|
155
|
+
emit("variable", cursor + 1 + lifetime.length);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (source.startsWith('b"', cursor) || source.startsWith('c"', cursor)) {
|
|
159
|
+
emit("string", quotedEnd(source, cursor + 1, '"', true));
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (source.startsWith("r#", cursor)) {
|
|
163
|
+
const identifier2 = identifierAt(source, cursor + 2);
|
|
164
|
+
if (identifier2 !== "") {
|
|
165
|
+
emit("variable", cursor + 2 + identifier2.length);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (source[cursor] === '"') {
|
|
171
|
+
emit("string", quotedEnd(source, cursor, '"', true));
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (language === "lean" && source[cursor] === "«") {
|
|
175
|
+
const end = source.indexOf("»", cursor + 1);
|
|
176
|
+
emit("variable", end === -1 ? source.length : end + 1);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (language === "tla") {
|
|
180
|
+
const word = matchAt(tlaWords, source, cursor);
|
|
181
|
+
if (word !== "") {
|
|
182
|
+
emit("keyword", cursor + word.length);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const number = matchAt(numbers, source, cursor);
|
|
187
|
+
if (number !== "") {
|
|
188
|
+
emit("number", cursor + number.length);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const identifier = identifierAt(source, cursor);
|
|
192
|
+
if (identifier !== "") {
|
|
193
|
+
const end = cursor + identifier.length;
|
|
194
|
+
const next = followingCharacter(source, end);
|
|
195
|
+
const kind = keywords.has(identifier) ? "keyword" : language === "rust" && rustTypes.has(identifier) ? "type" : next === "(" || language === "rust" && source[end] === "!" && source[end + 1] !== "=" ? "function" : /^[A-Z]/u.test(identifier) ? "type" : null;
|
|
196
|
+
if (kind === null) {
|
|
197
|
+
html.push(escapeHtml(identifier));
|
|
198
|
+
cursor = end;
|
|
199
|
+
} else
|
|
200
|
+
emit(kind, end);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const character = source[cursor] ?? "";
|
|
204
|
+
if (/[{}()[\];,.#:+*/%&|!<>=?~^\\'∀∃λ→←↔∧∨¬≤≥≠∈-]/u.test(character))
|
|
205
|
+
emit("operator", cursor + 1);
|
|
206
|
+
else {
|
|
207
|
+
html.push(escapeHtml(character));
|
|
208
|
+
cursor += 1;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return html.join("");
|
|
212
|
+
}
|
|
213
|
+
function tomlStringEnd(source, start) {
|
|
214
|
+
const quote = source[start] ?? '"';
|
|
215
|
+
const triple = quote.repeat(3);
|
|
216
|
+
if (!source.startsWith(triple, start))
|
|
217
|
+
return quotedEnd(source, start, quote, quote === '"');
|
|
218
|
+
let cursor = start + 3;
|
|
219
|
+
while (cursor < source.length) {
|
|
220
|
+
if (source[cursor] === "\\" && quote === '"') {
|
|
221
|
+
cursor += Math.min(2, source.length - cursor);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (source.startsWith(triple, cursor)) {
|
|
225
|
+
cursor += 3;
|
|
226
|
+
for (let extra = 0;extra < 2 && source[cursor] === quote; extra += 1)
|
|
227
|
+
cursor += 1;
|
|
228
|
+
return cursor;
|
|
229
|
+
}
|
|
230
|
+
cursor += 1;
|
|
231
|
+
}
|
|
232
|
+
return cursor;
|
|
233
|
+
}
|
|
234
|
+
function highlightToml(source) {
|
|
235
|
+
const html = [];
|
|
236
|
+
const bare = /[A-Za-z0-9_-]+/y;
|
|
237
|
+
const scalar = /(?:[+-]?(?:inf|nan)|true|false|[+-]?(?:0x[0-9a-fA-F_]+|0o[0-7_]+|0b[01_]+|[0-9][0-9_]*(?:\.[0-9_]+)?(?:[eE][+-]?[0-9_]+)?))(?![A-Za-z0-9_-])/y;
|
|
238
|
+
const date = /[0-9]{4}-[0-9]{2}-[0-9]{2}(?:[Tt ][0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]+)?(?:[Zz]|[+-][0-9]{2}:[0-9]{2})?)?|[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]+)?/y;
|
|
239
|
+
let cursor = 0;
|
|
240
|
+
let expectsKey = true;
|
|
241
|
+
let lineStart = true;
|
|
242
|
+
let table = false;
|
|
243
|
+
const containers = [];
|
|
244
|
+
const emit = (kind, end) => {
|
|
245
|
+
html.push(token(kind, source.slice(cursor, end)));
|
|
246
|
+
cursor = end;
|
|
247
|
+
};
|
|
248
|
+
while (cursor < source.length) {
|
|
249
|
+
const character = source[cursor] ?? "";
|
|
250
|
+
if (character === `
|
|
251
|
+
` || character === "\r") {
|
|
252
|
+
html.push(character);
|
|
253
|
+
cursor += 1;
|
|
254
|
+
lineStart = true;
|
|
255
|
+
table = false;
|
|
256
|
+
if (containers.length === 0)
|
|
257
|
+
expectsKey = true;
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (/\s/u.test(character)) {
|
|
261
|
+
html.push(escapeHtml(character));
|
|
262
|
+
cursor += 1;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (character === "#") {
|
|
266
|
+
emit("comment", lineEnd(source, cursor));
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (lineStart && character === "[" && containers.length === 0) {
|
|
270
|
+
table = true;
|
|
271
|
+
expectsKey = true;
|
|
272
|
+
}
|
|
273
|
+
lineStart = false;
|
|
274
|
+
if (character === '"' || character === "'") {
|
|
275
|
+
emit(expectsKey ? "property" : "string", tomlStringEnd(source, cursor));
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
if (!expectsKey) {
|
|
279
|
+
const value = matchAt(date, source, cursor) || matchAt(scalar, source, cursor);
|
|
280
|
+
if (value !== "") {
|
|
281
|
+
emit(value === "true" || value === "false" ? "keyword" : "number", cursor + value.length);
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const word = matchAt(bare, source, cursor);
|
|
286
|
+
if (word !== "") {
|
|
287
|
+
if (expectsKey)
|
|
288
|
+
emit("property", cursor + word.length);
|
|
289
|
+
else {
|
|
290
|
+
html.push(escapeHtml(word));
|
|
291
|
+
cursor += word.length;
|
|
292
|
+
}
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (character === "=")
|
|
296
|
+
expectsKey = false;
|
|
297
|
+
else if (character === "{" || !table && character === "[") {
|
|
298
|
+
containers.push(character);
|
|
299
|
+
expectsKey = character === "{";
|
|
300
|
+
} else if (!table && (character === "}" || character === "]")) {
|
|
301
|
+
containers.pop();
|
|
302
|
+
expectsKey = false;
|
|
303
|
+
} else if (character === ",")
|
|
304
|
+
expectsKey = containers.at(-1) === "{";
|
|
305
|
+
if (/[=.,{}[\]]/u.test(character))
|
|
306
|
+
emit("operator", cursor + 1);
|
|
307
|
+
else {
|
|
308
|
+
html.push(escapeHtml(character));
|
|
309
|
+
cursor += 1;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return html.join("");
|
|
313
|
+
}
|
|
314
|
+
function yamlBlockEnd(source, headerEnd, parentIndent, explicitIndent) {
|
|
315
|
+
let cursor = headerEnd;
|
|
316
|
+
let contentIndent = explicitIndent === 0 ? null : parentIndent + explicitIndent;
|
|
317
|
+
while (cursor < source.length) {
|
|
318
|
+
const start = cursor;
|
|
319
|
+
if (source[cursor] === "\r")
|
|
320
|
+
cursor += 1;
|
|
321
|
+
if (source[cursor] === `
|
|
322
|
+
`)
|
|
323
|
+
cursor += 1;
|
|
324
|
+
const lineStart = cursor;
|
|
325
|
+
while (source[cursor] === " ")
|
|
326
|
+
cursor += 1;
|
|
327
|
+
const indent = cursor - lineStart;
|
|
328
|
+
const end = lineEnd(source, cursor);
|
|
329
|
+
if (cursor === end) {
|
|
330
|
+
cursor = end;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (contentIndent === null)
|
|
334
|
+
contentIndent = indent > parentIndent ? indent : null;
|
|
335
|
+
if (contentIndent === null || indent < contentIndent)
|
|
336
|
+
return start;
|
|
337
|
+
cursor = end;
|
|
338
|
+
}
|
|
339
|
+
return cursor;
|
|
340
|
+
}
|
|
341
|
+
function highlightYaml(source) {
|
|
342
|
+
const html = [];
|
|
343
|
+
const names = /[&*][^\s,[\]{}]+/y;
|
|
344
|
+
const scalar = /(?:true|false|null|~|[+-]?(?:\.inf|\.nan|0x[0-9a-fA-F_]+|0o[0-7_]+|[0-9][0-9_]*(?:\.[0-9_]*)?(?:[eE][+-]?[0-9_]+)?))(?=$|[\s,\]}])/iy;
|
|
345
|
+
let cursor = 0;
|
|
346
|
+
let lineStart = 0;
|
|
347
|
+
let cachedLineEnd = -1;
|
|
348
|
+
const currentLineEnd = () => {
|
|
349
|
+
if (cachedLineEnd < cursor)
|
|
350
|
+
cachedLineEnd = lineEnd(source, cursor);
|
|
351
|
+
return cachedLineEnd;
|
|
352
|
+
};
|
|
353
|
+
const emit = (kind, end) => {
|
|
354
|
+
html.push(token(kind, source.slice(cursor, end)));
|
|
355
|
+
cursor = end;
|
|
356
|
+
};
|
|
357
|
+
while (cursor < source.length) {
|
|
358
|
+
const character = source[cursor] ?? "";
|
|
359
|
+
if (character === `
|
|
360
|
+
` || character === "\r") {
|
|
361
|
+
html.push(character);
|
|
362
|
+
cursor += 1;
|
|
363
|
+
lineStart = cursor;
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (/\s/u.test(character)) {
|
|
367
|
+
html.push(escapeHtml(character));
|
|
368
|
+
cursor += 1;
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
if (character === "#") {
|
|
372
|
+
emit("comment", currentLineEnd());
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
if (character === '"' || character === "'") {
|
|
376
|
+
const end2 = quotedEnd(source, cursor, character, character === '"', character === "'");
|
|
377
|
+
emit(followingCharacter(source, end2) === ":" ? "property" : "string", end2);
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
const name = matchAt(names, source, cursor);
|
|
381
|
+
if (name !== "") {
|
|
382
|
+
emit("variable", cursor + name.length);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if ((character === "|" || character === ">") && /^(?:[1-9][+-]?|[+-][1-9]?|)[ \t]*(?:#.*)?$/u.test(source.slice(cursor + 1, currentLineEnd()))) {
|
|
386
|
+
const end2 = currentLineEnd();
|
|
387
|
+
const header = source.slice(cursor, end2);
|
|
388
|
+
const explicit = /[1-9]/u.exec(header)?.[0];
|
|
389
|
+
let indentation = lineStart;
|
|
390
|
+
while (source[indentation] === " ")
|
|
391
|
+
indentation += 1;
|
|
392
|
+
emit("operator", cursor + 1 + (header.slice(1).match(/^[1-9+-]{0,2}/u)?.[0].length ?? 0));
|
|
393
|
+
const comment = source.indexOf("#", cursor);
|
|
394
|
+
if (comment !== -1 && comment < end2) {
|
|
395
|
+
html.push(escapeHtml(source.slice(cursor, comment)));
|
|
396
|
+
cursor = comment;
|
|
397
|
+
emit("comment", end2);
|
|
398
|
+
} else {
|
|
399
|
+
html.push(escapeHtml(source.slice(cursor, end2)));
|
|
400
|
+
cursor = end2;
|
|
401
|
+
}
|
|
402
|
+
const bodyEnd = yamlBlockEnd(source, end2, indentation - lineStart, Number(explicit ?? 0));
|
|
403
|
+
if (bodyEnd > cursor)
|
|
404
|
+
emit("string", bodyEnd);
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
if ((source.startsWith("---", cursor) || source.startsWith("...", cursor)) && cursor === lineStart && /^\s?$/u.test(source[cursor + 3] ?? "")) {
|
|
408
|
+
emit("marker", cursor + 3);
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
if (/[{}[\],]/u.test(character) || (character === ":" || character === "-" || character === "?") && /^\s?$/u.test(source[cursor + 1] ?? "")) {
|
|
412
|
+
emit("operator", cursor + 1);
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
const value = matchAt(scalar, source, cursor);
|
|
416
|
+
if (value !== "") {
|
|
417
|
+
emit(/^(?:true|false|null|~)$/iu.test(value) ? "keyword" : "number", cursor + value.length);
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
let end = cursor;
|
|
421
|
+
while (end < source.length && source[end] !== `
|
|
422
|
+
` && source[end] !== "\r") {
|
|
423
|
+
if (/[{}[\],]/u.test(source[end] ?? "") || source[end] === ":" && /^\s?$/u.test(source[end + 1] ?? "") || source[end] === "#" && end > cursor && /\s/u.test(source[end - 1] ?? ""))
|
|
424
|
+
break;
|
|
425
|
+
end += 1;
|
|
426
|
+
}
|
|
427
|
+
if (end === cursor)
|
|
428
|
+
end += 1;
|
|
429
|
+
const valueEnd = source.slice(cursor, end).trimEnd().length + cursor;
|
|
430
|
+
if (source[end] === ":" && valueEnd > cursor)
|
|
431
|
+
emit("property", valueEnd);
|
|
432
|
+
else {
|
|
433
|
+
html.push(escapeHtml(source.slice(cursor, end)));
|
|
434
|
+
cursor = end;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return html.join("");
|
|
438
|
+
}
|
|
439
|
+
function highlightCodeLexer(source, language) {
|
|
440
|
+
if (language === "toml")
|
|
441
|
+
return highlightToml(source);
|
|
442
|
+
if (language === "yaml")
|
|
443
|
+
return highlightYaml(source);
|
|
444
|
+
return highlightProgram(source, language);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// src/syntax-highlighting.ts
|
|
448
|
+
var syntaxLanguages = ["css", "html", "json", "lean", "markdown", "rust", "shell", "text", "tla", "toml", "typescript", "yaml"];
|
|
449
|
+
var maximumSyntaxCharacters = 128 * 1024;
|
|
450
|
+
function classOnlySyntax(html) {
|
|
451
|
+
const result = html.replace(/<span class="sh__token--(class|comment|entity|identifier|jsxliterals|keyword|property|sign|space|string)" style="color:var\(--sh-\1\)">/gu, '<span class="sh__token--$1">');
|
|
452
|
+
if (/<[A-Za-z][^<>]*\sstyle\s*=/iu.test(result)) {
|
|
453
|
+
throw new Error("Unrecognized inline style in class-only syntax output.");
|
|
454
|
+
}
|
|
455
|
+
return result;
|
|
456
|
+
}
|
|
457
|
+
var shellKeywords = new Set(["case", "do", "done", "elif", "else", "esac", "fi", "for", "function", "if", "in", "select", "then", "time", "until", "while"]);
|
|
458
|
+
var shellKeywordsFollowedByCommand = new Set(["do", "elif", "if", "then", "until", "while"]);
|
|
459
|
+
function languageToken(input) {
|
|
460
|
+
const tokens = input.trim().toLowerCase().split(/\s+/u);
|
|
461
|
+
const languageClass = tokens.find((token2) => token2.startsWith("language-"));
|
|
462
|
+
return (languageClass ?? tokens[0] ?? "").replace(/^language-/u, "");
|
|
463
|
+
}
|
|
464
|
+
function resolveSyntaxLanguage(input) {
|
|
465
|
+
if (typeof input !== "string")
|
|
466
|
+
return "text";
|
|
467
|
+
switch (languageToken(input)) {
|
|
468
|
+
case "css":
|
|
469
|
+
return "css";
|
|
470
|
+
case "htm":
|
|
471
|
+
case "html":
|
|
472
|
+
case "xml":
|
|
473
|
+
return "html";
|
|
474
|
+
case "json":
|
|
475
|
+
case "jsonc":
|
|
476
|
+
return "json";
|
|
477
|
+
case "lean":
|
|
478
|
+
case "lean4":
|
|
479
|
+
return "lean";
|
|
480
|
+
case "rust":
|
|
481
|
+
case "rs":
|
|
482
|
+
return "rust";
|
|
483
|
+
case "tla":
|
|
484
|
+
case "tla+":
|
|
485
|
+
case "tlaplus":
|
|
486
|
+
return "tla";
|
|
487
|
+
case "toml":
|
|
488
|
+
return "toml";
|
|
489
|
+
case "yaml":
|
|
490
|
+
case "yml":
|
|
491
|
+
return "yaml";
|
|
492
|
+
case "markdown":
|
|
493
|
+
case "md":
|
|
494
|
+
case "mdx":
|
|
495
|
+
return "markdown";
|
|
496
|
+
case "bash":
|
|
497
|
+
case "console":
|
|
498
|
+
case "sh":
|
|
499
|
+
case "shell":
|
|
500
|
+
case "zsh":
|
|
501
|
+
return "shell";
|
|
502
|
+
case "javascript":
|
|
503
|
+
case "js":
|
|
504
|
+
case "jsx":
|
|
505
|
+
case "ts":
|
|
506
|
+
case "tsx":
|
|
507
|
+
case "typescript":
|
|
508
|
+
return "typescript";
|
|
509
|
+
case "plaintext":
|
|
510
|
+
case "text":
|
|
511
|
+
case "txt":
|
|
512
|
+
default:
|
|
513
|
+
return "text";
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function inferSyntaxLanguage(code) {
|
|
517
|
+
if (code.length > maximumSyntaxCharacters)
|
|
518
|
+
return "text";
|
|
519
|
+
const trimmed = code.trim();
|
|
520
|
+
if (trimmed === "")
|
|
521
|
+
return "text";
|
|
522
|
+
if (trimmed[0] === "{" || trimmed[0] === "[") {
|
|
523
|
+
try {
|
|
524
|
+
const value = JSON.parse(trimmed);
|
|
525
|
+
if (value !== null && typeof value === "object")
|
|
526
|
+
return "json";
|
|
527
|
+
} catch {}
|
|
528
|
+
}
|
|
529
|
+
const first = (trimmed.split(`
|
|
530
|
+
`, 1)[0] ?? "").slice(0, 2048);
|
|
531
|
+
if (/^#!\s*(?:\/bin\/(?:ba|z)?sh|\/usr\/bin\/env\s+(?:ba|z)?sh)(?:\s|$)/u.test(first) || /^(?:\$\s+)?(?:bun|npm|pnpm|yarn)\s+(?:add|install|run|test|build|remove|update|exec|dlx|create|init|ci|publish|pack)\b/u.test(first) || /^(?:\$\s+)?(?:bunx|npx)\s+(?:skills\s+add\b|create-[\w-]+\b|@[\w-]+\/[\w-]+\b|[\w-]+\s+--?[A-Za-z])/u.test(first) || /^(?:\$\s+)?git\s+(?:clone|status|diff|log|show|fetch|pull|push|checkout|switch|add|commit|branch|tag)\b/u.test(first) || /^(?:\$\s+)?curl\s+(?:--?[A-Za-z]|https?:\/\/)/u.test(first))
|
|
532
|
+
return "shell";
|
|
533
|
+
if (/^(?:export\s+)?(?:const|let|var)\s+[A-Za-z_$][\w$]*(?:\s*:[^=]+)?\s*=/u.test(first) || /^import\s+(?:[\w*{].*\s+from\s+)?["']/u.test(first) || /^(?:export\s+)?(?:async\s+)?function\s+[A-Za-z_$][\w$]*\s*\(/u.test(first))
|
|
534
|
+
return "typescript";
|
|
535
|
+
if (/^#{1,6}\s+\S/u.test(first) || /^`{3,}\w*/u.test(first))
|
|
536
|
+
return "markdown";
|
|
537
|
+
if (/^<!doctype\s+html\b/iu.test(first) || /^<([a-z][\w:-]*)(?:\s[^<>]*|)>(?:[^]*?)<\/\1\s*>/iu.test(trimmed))
|
|
538
|
+
return "html";
|
|
539
|
+
const opening = trimmed.indexOf("{");
|
|
540
|
+
if (opening > 0 && opening < 2048 && /^[.#]?[a-zA-Z_][\w.# :>+~,-]*$/u.test(trimmed.slice(0, opening).trimEnd())) {
|
|
541
|
+
const declaration = trimmed.slice(opening + 1, opening + 2049).trimStart();
|
|
542
|
+
const colon = declaration.indexOf(":");
|
|
543
|
+
if (colon > 0 && /^-{0,2}[a-zA-Z][a-zA-Z-]*$/u.test(declaration.slice(0, colon).trimEnd()) && /^[^{};]+[;}]/u.test(declaration.slice(colon + 1).trimStart()))
|
|
544
|
+
return "css";
|
|
545
|
+
}
|
|
546
|
+
return "text";
|
|
547
|
+
}
|
|
548
|
+
function tokenHtml(kind, html) {
|
|
549
|
+
return `<span class="syntax-token syntax-token--${kind}">${html}</span>`;
|
|
550
|
+
}
|
|
551
|
+
function highlightMarkdownInline(value) {
|
|
552
|
+
let html = "";
|
|
553
|
+
let cursor = 0;
|
|
554
|
+
for (const match of value.matchAll(/`[^`\n]+`/gu)) {
|
|
555
|
+
const index = match.index;
|
|
556
|
+
const inlineCode = match[0];
|
|
557
|
+
html += escapeHtml(value.slice(cursor, index));
|
|
558
|
+
html += token("inline", inlineCode);
|
|
559
|
+
cursor = index + inlineCode.length;
|
|
560
|
+
}
|
|
561
|
+
return html + escapeHtml(value.slice(cursor));
|
|
562
|
+
}
|
|
563
|
+
function isMarkdownWhitespace(codeUnit) {
|
|
564
|
+
return codeUnit === 9 || codeUnit === 10 || codeUnit === 11 || codeUnit === 12 || codeUnit === 13 || codeUnit === 32 || codeUnit === 160 || codeUnit === 5760 || codeUnit >= 8192 && codeUnit <= 8202 || codeUnit === 8232 || codeUnit === 8233 || codeUnit === 8239 || codeUnit === 8287 || codeUnit === 12288 || codeUnit === 65279;
|
|
565
|
+
}
|
|
566
|
+
function isMarkdownLineTerminator(codeUnit) {
|
|
567
|
+
return codeUnit === 10 || codeUnit === 13 || codeUnit === 8232 || codeUnit === 8233;
|
|
568
|
+
}
|
|
569
|
+
function isAsciiDigit(codeUnit) {
|
|
570
|
+
return codeUnit >= 48 && codeUnit <= 57;
|
|
571
|
+
}
|
|
572
|
+
function markdownLineParts(line, kind) {
|
|
573
|
+
let markerStart = 0;
|
|
574
|
+
while (markerStart < line.length && isMarkdownWhitespace(line.charCodeAt(markerStart))) {
|
|
575
|
+
markerStart += 1;
|
|
576
|
+
}
|
|
577
|
+
let markerEnd = markerStart;
|
|
578
|
+
if (kind === "fence") {
|
|
579
|
+
const fence = line.charCodeAt(markerStart);
|
|
580
|
+
if (fence !== 96 && fence !== 126)
|
|
581
|
+
return null;
|
|
582
|
+
while (markerEnd < line.length && line.charCodeAt(markerEnd) === fence) {
|
|
583
|
+
markerEnd += 1;
|
|
584
|
+
}
|
|
585
|
+
if (markerEnd - markerStart < 3)
|
|
586
|
+
return null;
|
|
587
|
+
} else if (kind === "heading") {
|
|
588
|
+
while (markerEnd < line.length && markerEnd - markerStart < 6 && line.charCodeAt(markerEnd) === 35) {
|
|
589
|
+
markerEnd += 1;
|
|
590
|
+
}
|
|
591
|
+
if (markerEnd === markerStart)
|
|
592
|
+
return null;
|
|
593
|
+
} else {
|
|
594
|
+
const first = line.charCodeAt(markerStart);
|
|
595
|
+
if (first === 42 || first === 43 || first === 45) {
|
|
596
|
+
markerEnd += 1;
|
|
597
|
+
} else if (isAsciiDigit(first)) {
|
|
598
|
+
while (markerEnd < line.length && isAsciiDigit(line.charCodeAt(markerEnd))) {
|
|
599
|
+
markerEnd += 1;
|
|
600
|
+
}
|
|
601
|
+
if (line.charCodeAt(markerEnd) !== 46)
|
|
602
|
+
return null;
|
|
603
|
+
markerEnd += 1;
|
|
604
|
+
} else {
|
|
605
|
+
return null;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const separatorStart = markerEnd;
|
|
609
|
+
if (kind !== "fence") {
|
|
610
|
+
while (markerEnd < line.length && isMarkdownWhitespace(line.charCodeAt(markerEnd))) {
|
|
611
|
+
markerEnd += 1;
|
|
612
|
+
}
|
|
613
|
+
if (markerEnd === separatorStart)
|
|
614
|
+
return null;
|
|
615
|
+
}
|
|
616
|
+
for (let cursor = markerEnd;cursor < line.length; cursor += 1) {
|
|
617
|
+
if (isMarkdownLineTerminator(line.charCodeAt(cursor)))
|
|
618
|
+
return null;
|
|
619
|
+
}
|
|
620
|
+
return {
|
|
621
|
+
content: line.slice(markerEnd),
|
|
622
|
+
indentation: line.slice(0, markerStart),
|
|
623
|
+
marker: line.slice(markerStart, separatorStart),
|
|
624
|
+
separator: line.slice(separatorStart, markerEnd)
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
function highlightMarkdownLine(line) {
|
|
628
|
+
const fence = markdownLineParts(line, "fence");
|
|
629
|
+
if (fence !== null) {
|
|
630
|
+
return `${escapeHtml(fence.indentation)}${token("marker", fence.marker)}${token("keyword", fence.content)}`;
|
|
631
|
+
}
|
|
632
|
+
const heading = markdownLineParts(line, "heading");
|
|
633
|
+
if (heading !== null) {
|
|
634
|
+
return `${escapeHtml(heading.indentation)}${token("marker", heading.marker)}${escapeHtml(heading.separator)}${tokenHtml("heading", highlightMarkdownInline(heading.content))}`;
|
|
635
|
+
}
|
|
636
|
+
const listItem = markdownLineParts(line, "list");
|
|
637
|
+
if (listItem !== null) {
|
|
638
|
+
return `${escapeHtml(listItem.indentation)}${token("marker", listItem.marker)}${escapeHtml(listItem.separator)}${highlightMarkdownInline(listItem.content)}`;
|
|
639
|
+
}
|
|
640
|
+
const quote = /^(\s*)(>)(\s?)(.*)$/u.exec(line);
|
|
641
|
+
if (quote !== null) {
|
|
642
|
+
return `${escapeHtml(quote[1] ?? "")}${token("marker", quote[2] ?? "")}${escapeHtml(quote[3] ?? "")}${highlightMarkdownInline(quote[4] ?? "")}`;
|
|
643
|
+
}
|
|
644
|
+
return highlightMarkdownInline(line);
|
|
645
|
+
}
|
|
646
|
+
function highlightMarkdown(value) {
|
|
647
|
+
return value.split(`
|
|
648
|
+
`).map(highlightMarkdownLine).join(`
|
|
649
|
+
`);
|
|
650
|
+
}
|
|
651
|
+
function isShellOperator(character) {
|
|
652
|
+
return character === "&" || character === "(" || character === ")" || character === ";" || character === "<" || character === ">" || character === "|";
|
|
653
|
+
}
|
|
654
|
+
function isShellWhitespace(character) {
|
|
655
|
+
return /\s/u.test(character);
|
|
656
|
+
}
|
|
657
|
+
function isEscaped(line, index) {
|
|
658
|
+
let backslashes = 0;
|
|
659
|
+
for (let cursor = index - 1;cursor >= 0 && line[cursor] === "\\"; cursor -= 1) {
|
|
660
|
+
backslashes += 1;
|
|
661
|
+
}
|
|
662
|
+
return backslashes % 2 === 1;
|
|
663
|
+
}
|
|
664
|
+
function highlightShellLine(line) {
|
|
665
|
+
let cursor = 0;
|
|
666
|
+
let expectsCommand = true;
|
|
667
|
+
let html = "";
|
|
668
|
+
while (cursor < line.length) {
|
|
669
|
+
const character = line[cursor] ?? "";
|
|
670
|
+
if (isShellWhitespace(character)) {
|
|
671
|
+
html += escapeHtml(character);
|
|
672
|
+
cursor += 1;
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
if (character === "#") {
|
|
676
|
+
html += token("comment", line.slice(cursor));
|
|
677
|
+
break;
|
|
678
|
+
}
|
|
679
|
+
if (character === "'" || character === '"') {
|
|
680
|
+
const quote = character;
|
|
681
|
+
let end2 = cursor + 1;
|
|
682
|
+
while (end2 < line.length) {
|
|
683
|
+
const next = line[end2] ?? "";
|
|
684
|
+
end2 += 1;
|
|
685
|
+
if (next === quote && (quote === "'" || !isEscaped(line, end2 - 1)))
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
html += token("string", line.slice(cursor, end2));
|
|
689
|
+
cursor = end2;
|
|
690
|
+
expectsCommand = false;
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
if (character === "$") {
|
|
694
|
+
if (line.slice(0, cursor).trim() === "" && /\s/u.test(line[cursor + 1] ?? "")) {
|
|
695
|
+
html += token("operator", character);
|
|
696
|
+
cursor += 1;
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
const variable = /^\$(?:\{[^}\n]*\}|[A-Za-z_][A-Za-z0-9_]*|[?$!#*@0-9-])/u.exec(line.slice(cursor))?.[0] ?? "$";
|
|
700
|
+
html += token("variable", variable);
|
|
701
|
+
cursor += variable.length;
|
|
702
|
+
expectsCommand = false;
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
if (isShellOperator(character)) {
|
|
706
|
+
const pair = line.slice(cursor, cursor + 2);
|
|
707
|
+
const operator = pair === "&&" || pair === "||" || pair === ">>" || pair === "<<" ? pair : character;
|
|
708
|
+
html += token("operator", operator);
|
|
709
|
+
cursor += operator.length;
|
|
710
|
+
expectsCommand = operator === ";" || operator === "&&" || operator === "||" || operator === "|";
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
let end = cursor + 1;
|
|
714
|
+
while (end < line.length) {
|
|
715
|
+
const next = line[end] ?? "";
|
|
716
|
+
if (isShellWhitespace(next) || isShellOperator(next) || next === "$" || next === "'" || next === '"') {
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
end += 1;
|
|
720
|
+
}
|
|
721
|
+
const word = line.slice(cursor, end);
|
|
722
|
+
if (shellKeywords.has(word)) {
|
|
723
|
+
html += token("keyword", word);
|
|
724
|
+
expectsCommand = shellKeywordsFollowedByCommand.has(word);
|
|
725
|
+
} else if (word.startsWith("-")) {
|
|
726
|
+
html += token("flag", word);
|
|
727
|
+
expectsCommand = false;
|
|
728
|
+
} else if (expectsCommand && !word.includes("=")) {
|
|
729
|
+
html += token("command", word);
|
|
730
|
+
expectsCommand = false;
|
|
731
|
+
} else if (/^[A-Za-z_][A-Za-z0-9_]*=/u.test(word)) {
|
|
732
|
+
html += token("variable", word);
|
|
733
|
+
} else {
|
|
734
|
+
html += escapeHtml(word);
|
|
735
|
+
expectsCommand = false;
|
|
736
|
+
}
|
|
737
|
+
cursor = end;
|
|
738
|
+
}
|
|
739
|
+
return html;
|
|
740
|
+
}
|
|
741
|
+
function highlightShell(value) {
|
|
742
|
+
return value.split(`
|
|
743
|
+
`).map(highlightShellLine).join(`
|
|
744
|
+
`);
|
|
745
|
+
}
|
|
746
|
+
function highlightCode(code, languageHint, options = {}) {
|
|
747
|
+
const styles = options.styles ?? "inline";
|
|
748
|
+
if (styles !== "inline" && styles !== "classes") {
|
|
749
|
+
throw new Error("Syntax styles must be inline or classes.");
|
|
750
|
+
}
|
|
751
|
+
const language = code.length > maximumSyntaxCharacters ? "text" : languageHint === undefined || languageHint.trim() === "" || languageHint === "auto" ? inferSyntaxLanguage(code) : resolveSyntaxLanguage(languageHint);
|
|
752
|
+
const html = language === "text" ? escapeHtml(code) : language === "markdown" ? highlightMarkdown(code) : language === "shell" ? highlightShell(code) : language === "rust" || language === "toml" || language === "yaml" || language === "lean" || language === "tla" ? highlightCodeLexer(code, language) : highlight(code);
|
|
753
|
+
return Object.freeze({
|
|
754
|
+
className: `syntax-code language-${language}`,
|
|
755
|
+
html: styles === "classes" ? classOnlySyntax(html) : html,
|
|
756
|
+
language
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
export { syntaxLanguages, maximumSyntaxCharacters, resolveSyntaxLanguage, inferSyntaxLanguage, highlightCode };
|