Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import { defineConfig } from 'vitepress'
import fs from 'node:fs'
import path from 'node:path'

const llvmGrammar = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'llvm.tmLanguage.json'), 'utf-8')
)

export default defineConfig({
title: 'ChadScript',
description: 'Compile TypeScript to native binaries via LLVM',

base: '/ChadScript/',
appearance: 'dark',

markdown: {
languages: [llvmGrammar],
},

transformPageData(pageData) {
const mdPath = path.resolve(__dirname, '..', pageData.relativePath)
try {
Expand Down
18 changes: 18 additions & 0 deletions docs/.vitepress/llvm.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "llvm",
"scopeName": "source.llvm",
"patterns": [
{ "match": ";.*$", "name": "comment.line.llvm" },
{ "match": "\\b(define|declare|global|constant|private|internal|external|unnamed_addr|align|to|nuw|nsw|exact|inbounds|volatile|tail|musttail|notail)\\b", "name": "keyword.other.llvm" },
{ "match": "\\b(ret|br|switch|invoke|resume|unreachable|call|alloca|load|store|getelementptr|extractvalue|insertvalue|extractelement|insertelement|shufflevector|phi|select|icmp|fcmp|add|sub|mul|udiv|sdiv|urem|srem|fadd|fsub|fmul|fdiv|frem|shl|lshr|ashr|and|or|xor|trunc|zext|sext|fptrunc|fpext|fptoui|fptosi|uitofp|sitofp|ptrtoint|inttoptr|bitcast|addrspacecast)\\b", "name": "keyword.control.llvm" },
{ "match": "\\b(i1|i8|i16|i32|i64|i128|float|double|void|label|metadata|token|ptr)\\b", "name": "storage.type.llvm" },
{ "match": "\\b(eq|ne|ugt|uge|ult|ule|sgt|sge|slt|sle|oeq|ogt|oge|olt|ole|one|ord|ueq|une|uno|true|false|null|zeroinitializer|undef|poison)\\b", "name": "constant.language.llvm" },
{ "match": "@[a-zA-Z$._][a-zA-Z$._0-9]*", "name": "entity.name.function.llvm" },
{ "match": "%[a-zA-Z$._][a-zA-Z$._0-9]*", "name": "variable.other.llvm" },
{ "match": "%[0-9]+", "name": "variable.other.llvm" },
{ "match": "\\b-?[0-9]+\\.?[0-9]*([eE][+-]?[0-9]+)?\\b", "name": "constant.numeric.llvm" },
{ "match": "c\"[^\"]*\"", "name": "string.quoted.double.llvm" },
{ "match": "\"[^\"]*\"", "name": "string.quoted.double.llvm" },
{ "match": "^[a-zA-Z$._][a-zA-Z$._0-9]*:", "name": "entity.name.label.llvm" }
]
}
79 changes: 74 additions & 5 deletions docs/.vitepress/theme/ExampleTabs.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<script setup lang="ts">
import { ref, computed } from 'vue'
import { ref, computed, watch, onMounted, onUnmounted, nextTick } from 'vue'

const activeTab = ref(0)
const copied = ref(false)
const cmdText = ref('')
const showOutput = ref(false)
const containerRef = ref<HTMLElement | null>(null)
let isVisible = false

const examples = [
{
Expand Down Expand Up @@ -99,6 +103,8 @@ function highlight(code: string): string {
const highlightedCode = computed(() => highlight(examples[activeTab.value].code))

let copyTimeout: ReturnType<typeof setTimeout> | null = null
let typeTimeouts: ReturnType<typeof setTimeout>[] = []
let observer: IntersectionObserver | null = null

function copyCode() {
const code = examples[activeTab.value].code
Expand All @@ -107,10 +113,59 @@ function copyCode() {
if (copyTimeout) clearTimeout(copyTimeout)
copyTimeout = setTimeout(() => { copied.value = false }, 1500)
}

function runTypewriter(text: string) {
typeTimeouts.forEach(t => clearTimeout(t))
typeTimeouts = []
cmdText.value = ''
showOutput.value = false

const cmdPart = text.slice(2)
let i = 0
function tick() {
if (i < cmdPart.length) {
cmdText.value = cmdPart.slice(0, i + 1)
i++
const t = setTimeout(tick, 40)
typeTimeouts.push(t)
} else {
const t = setTimeout(() => { showOutput.value = true }, 150)
typeTimeouts.push(t)
}
}
const t = setTimeout(tick, 300)
typeTimeouts.push(t)
}

watch(activeTab, () => {
runTypewriter(examples[activeTab.value].run)
})

onMounted(() => {
nextTick(() => {
if (!containerRef.value) return
observer = new IntersectionObserver(
(entries) => {
const wasVisible = isVisible
isVisible = entries[0].isIntersecting
if (isVisible && !wasVisible) {
runTypewriter(examples[activeTab.value].run)
}
},
{ threshold: 0.3 }
)
observer.observe(containerRef.value)
})
})

onUnmounted(() => {
if (observer) observer.disconnect()
typeTimeouts.forEach(t => clearTimeout(t))
})
</script>

<template>
<div class="example-tabs">
<div class="example-tabs" ref="containerRef">
<h2 class="example-heading">Examples</h2>
<div class="tab-bar">
<button
Expand All @@ -129,8 +184,8 @@ function copyCode() {
</div>
<pre class="panel-code"><code v-html="highlightedCode"></code></pre>
<div class="panel-terminal">
<div class="terminal-line terminal-cmd">{{ examples[activeTab].run }}</div>
<div class="terminal-line terminal-out">{{ examples[activeTab].output }}</div>
<div class="terminal-line terminal-cmd"><span class="terminal-prompt">$</span> {{ cmdText }}<span v-if="!showOutput" class="cursor">|</span></div>
<div v-if="showOutput" class="terminal-line terminal-out">{{ examples[activeTab].output }}</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -262,14 +317,28 @@ function copyCode() {
line-height: 1.6;
}

.terminal-prompt {
color: var(--vp-c-brand-1);
}

.terminal-cmd {
color: var(--vp-c-text-2);
color: var(--vp-c-text-1);
}

.terminal-out {
color: var(--vp-c-text-3);
}

.cursor {
color: var(--vp-c-brand-1);
animation: blink 0.6s step-end infinite;
font-weight: 300;
}

@keyframes blink {
50% { opacity: 0; }
}

@media (max-width: 768px) {
.tab-bar {
overflow-x: auto;
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/theme/HeroBenchmarks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ onMounted(() => {
<style scoped>
.hero-bench {
width: 360px;
margin: 2.5rem auto 0;
padding: 22px 24px;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
Expand Down
Loading
Loading