-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12c6df6
commit 88f02c7
Showing
92 changed files
with
702 additions
and
407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<script lang="ts"> | ||
import Header from '$lib/layout/Header.svelte'; | ||
import Svg from './Svg.svelte'; | ||
import link from 'bootstrap-icons/icons/link-45deg.svg?raw'; | ||
export let depth: 1 | 2 | 3 | 4 | 5 | 6; | ||
export let text: string; | ||
export let id: string = text.toLowerCase().replace(/\s/g, '-').trim(); | ||
export let headerClassName: string | undefined = undefined; | ||
</script> | ||
|
||
{#if depth > 1} | ||
<svelte:element this={'h' + depth} {id} class={headerClassName}> | ||
{text} | ||
<a class="anchor-link" href="#{id}" aria-label="link to {text}"><Svg className="icon-24 align-middle" svg={link} /></a> | ||
</svelte:element> | ||
{:else} | ||
<Header title={text} /> | ||
{/if} | ||
|
||
<style lang="scss"> | ||
.anchor-link { | ||
text-decoration: none; | ||
opacity: 0; | ||
transition: opacity 0.15s ease-in-out; | ||
&:focus, | ||
&:hover, | ||
:hover > &, | ||
:target > & { | ||
opacity: 1; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,13 @@ | ||
<script lang="ts"> | ||
import Svg from './Svg.svelte'; | ||
import link from 'bootstrap-icons/icons/link-45deg.svg?raw'; | ||
import Heading from '$lib/layout/Heading.svelte'; | ||
export let level: 1 | 2 | 3; | ||
export let label: string; | ||
export let id: string; | ||
export let id: string = label.toLowerCase().replace(/\s/g, '-').trim(); | ||
export let headerClassName: string | undefined = undefined; | ||
</script> | ||
|
||
<section> | ||
<svelte:element this={'h' + level} {id} class={headerClassName}> | ||
{label} | ||
<a class="anchor-link" href="#{id}" aria-label="link to {label}"><Svg className="icon-24 align-middle" svg={link} /></a> | ||
</svelte:element> | ||
<Heading depth={level} text={label} {id} {headerClassName} /> | ||
<slot /> | ||
</section> | ||
|
||
<style lang="scss"> | ||
.anchor-link { | ||
text-decoration: none; | ||
opacity: 0; | ||
transition: opacity 0.15s ease-in-out; | ||
&:focus, | ||
&:hover, | ||
:hover > &, | ||
:target > & { | ||
opacity: 1; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<script lang="ts"> | ||
import SvelteMarkdown, {type Renderers} from 'svelte-markdown'; | ||
import Heading from '$lib/layout/Heading.svelte'; | ||
import MdCode from '$lib/markdown/renderers/MdCode.svelte'; | ||
import {marked} from 'marked'; | ||
import MdSection from '$lib/markdown/renderers/MdSection.svelte'; | ||
import MdImage from '$lib/markdown/renderers/MdImage.svelte'; | ||
export let source: string; | ||
function getTokens(src: string) { | ||
const tokens = marked.lexer(src); | ||
const walkTokens = (tokens: marked.TokensList | marked.Token[]) => { | ||
let indexLastHeading = -1; | ||
for (let i = 0; i < tokens.length; i++) { | ||
const token = tokens[i]; | ||
if ((token as marked.Tokens.Generic).tokens?.length) { | ||
walkTokens((token as marked.Tokens.Generic).tokens!); | ||
} | ||
if (token.type === 'heading' && token.depth === 2) { | ||
if (indexLastHeading >= 0) { | ||
tokens.splice(indexLastHeading, i - indexLastHeading, { | ||
type: 'section', | ||
tokens: tokens.slice(indexLastHeading, i), | ||
} as unknown as marked.Token); | ||
i = indexLastHeading + 1; | ||
} | ||
indexLastHeading = i; | ||
} | ||
} | ||
if (indexLastHeading >= 0) { | ||
tokens.splice(indexLastHeading, tokens.length - indexLastHeading, { | ||
type: 'section', | ||
tokens: tokens.slice(indexLastHeading, tokens.length), | ||
} as unknown as marked.Token); | ||
} | ||
}; | ||
walkTokens(tokens); | ||
return tokens; | ||
} | ||
$: tokens = getTokens(source); | ||
const renderers: Partial<Renderers> = {image: MdImage, heading: Heading, code: MdCode, section: MdSection} as Partial<Renderers>; | ||
</script> | ||
|
||
<SvelteMarkdown source={tokens} {renderers} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<script lang="ts"> | ||
import Code from '$lib/layout/Code.svelte'; | ||
import Sample from '$lib/layout/Sample.svelte'; | ||
import type {SampleInfo} from '$lib/layout/sample'; | ||
import {selectedFramework$} from '$lib/stores'; | ||
import samples from '../samples'; | ||
export let lang: string; | ||
export let text: string; | ||
let code = ''; | ||
let title: string; | ||
let sample: SampleInfo; | ||
let height = 500; | ||
const extensions: Map<string, string> = new Map(); | ||
extensions.set('typescript', 'ts'); | ||
extensions.set('bash', 'sh'); | ||
async function getCode(text: string, selectedFramework: string, lang: string) { | ||
if (lang !== 'sample' && text.trim().match(/^\{[a-z-]+\}$/) && extensions.has(lang)) { | ||
const codeKey = text.trim().slice(1, -1); | ||
code = (await import(`../../../../../docs/code/${codeKey}/${codeKey}-${selectedFramework}.${extensions.get(lang)}?raw`)).default; | ||
} else { | ||
code = text.trim(); | ||
} | ||
} | ||
async function getSample(text: string, lang: string) { | ||
if (lang === 'sample') { | ||
const match = text.trim().match(/^\{([^:]+):([a-zA-Z-/]+):(\d+)\}$/); | ||
if (match) { | ||
title = match[1]; | ||
const sampleKey = match[2]; | ||
height = Number.parseInt(match[3], 10); | ||
if (samples.has(sampleKey)) { | ||
sample = samples.get(sampleKey)!; | ||
} | ||
} | ||
} | ||
} | ||
$: void getCode(text, $selectedFramework$, lang); | ||
$: void getSample(text, lang); | ||
</script> | ||
|
||
{#if lang === 'sample'} | ||
{#if sample} | ||
<Sample {title} {sample} {height} /> | ||
{:else} | ||
Sample not found, make sure to fill the samples.ts file. | ||
{/if} | ||
{:else} | ||
<Code language={lang} {code} /> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script lang="ts"> | ||
export let href = ''; | ||
export let title: string; | ||
export let text = ''; | ||
let src: string; | ||
async function getSrc(href: string) { | ||
src = (await import(`../../../resources/images/${href.slice(href.indexOf('resources/images/') + 17, -5)}.webp`)).default; | ||
} | ||
$: void getSrc(href); | ||
</script> | ||
|
||
<img {src} {title} alt={text} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<section><slot /></section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type {SampleInfo} from '$lib/layout/sample'; | ||
|
||
import focustrack from '@agnos-ui/samples/focustrack/focustrack'; | ||
import floatingUI from '@agnos-ui/samples/floatingUI/floatingUI'; | ||
|
||
const samples: Map<string, SampleInfo> = new Map(); | ||
samples.set('focustrack/focustrack', focustrack); | ||
samples.set('floatingUI/floatingUI', floatingUI); | ||
|
||
export default samples; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {readFile, readdir} from 'node:fs/promises'; | ||
|
||
const validMdRegex = /^\d{2}-[a-z-]*\.md$/g; | ||
|
||
export async function listMarkdown() { | ||
const categories = (await readdir(`../docs`)).filter((folder) => folder !== 'code'); | ||
const files: {slug: string; path: string}[] = []; | ||
for (const category of categories) { | ||
(await readdir(`../docs/${category}`)) | ||
.filter((file) => file.match(validMdRegex)) | ||
.forEach((file) => { | ||
files.push({slug: `${category}/${file.slice(3, -3)}`, path: `../docs/${category}/${file}`}); | ||
}); | ||
} | ||
return files; | ||
} | ||
|
||
export async function listSections(base: string) { | ||
return (await readdir(`../docs/${base}`)) | ||
.filter((file) => file.match(validMdRegex)) | ||
.map((file) => { | ||
const name = file.slice(3, -3); | ||
return {name, title: name.substring(0, 1).toUpperCase() + name.substring(1).replace('-', ' ')}; | ||
}); | ||
} | ||
|
||
export async function retrieveMarkdown(slug: string) { | ||
const files = await listMarkdown(); | ||
const file = files.find((file) => file.slug === slug); | ||
return file ? await readFile(file.path, 'utf-8') : undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.