/* oxlint-disable typescript/switch-exhaustiveness-check */
import type { ReactNode } from "react"
import type { TSD } from "tsdoc.json"
export type ModProps = {
docs: TSD.Doc[]
className?: string
}
export function Mod({ docs, className = `` }: ModProps): ReactNode {
return (
{docs.map((doc) => (
))}
)
}
export type DocProps = {
doc: TSD.Doc
isRoot?: boolean
}
export function Doc({ doc, isRoot }: DocProps): ReactNode {
const offset0 = stringToNumber(doc.name)
const offset1 = offset0 << 1
return (
{doc.name}
{(() => {
switch (doc.type) {
case `function`:
return
}
})()}
)
}
type FunctionMainContentProps = {
doc: TSD.FunctionDoc
}
function FunctionMainContent({ doc }: FunctionMainContentProps): ReactNode {
switch (doc.kind) {
case `regular`:
return
case `overloaded`:
return
}
}
type OverloadedFunctionMainContentProps = {
doc: TSD.OverloadedFunctionDoc
}
function OverloadedFunctionMainContent({
doc,
}: OverloadedFunctionMainContentProps): ReactNode {
const withoutImplementation = doc.overloads.slice(0, -1)
return (
<>
{withoutImplementation.map((overload, idx) => {
const overloadBlock = overload.blocks.find(
(block) => block.name === `@overload`,
)
const overloadName =
overloadBlock?.desc?.content[0].type === `plainText`
? overloadBlock.desc.content[0].text
: idx.toString()
if (doc.name === `atom`) console.log(overloadName)
return (
)
})}
>
)
}
type RegularFunctionMainContentProps = {
doc: TSD.RegularFunctionDoc
}
function RegularFunctionMainContent({
doc,
}: RegularFunctionMainContentProps): ReactNode {
const returnValue = doc.blocks.find((block) => block.name === `@returns`)
return (
<>
{doc.sections.map((section) => (
))}
{doc.params.length ? (
) : null}
{doc.params.map((param, index) => (
))}
{returnValue ? : null}
>
)
}
type ParamBlockProps = {
param: TSD.ParamBlock
index: number
}
function ParamBlock({ param, index }: ParamBlockProps): ReactNode {
return (
{param.desc ? : null}
)
}
type BlockProps = {
block: TSD.DocBlock
}
function Block({ block }: BlockProps): ReactNode {
const blockName = block.name.split(`@`)[1]
return (
)
}
type SectionProps = {
section: TSD.DocSection
}
function DocSection({ section }: SectionProps): ReactNode {
return (
{section.content.map((content) => (
))}
)
}
type SectionContentProps = {
content: TSD.SectionContent
}
function SectionContent({ content }: SectionContentProps): ReactNode {
switch (content.type) {
case `paragraph`:
return
case `fencedCode`:
return
}
}
type FencedCodeProps = {
fencedCode: TSD.FencedCode
}
function FencedCode({ fencedCode }: FencedCodeProps): ReactNode {
return (
{fencedCode.content}
)
}
type ParagraphProps = {
paragraph: TSD.Paragraph
}
function Paragraph({ paragraph }: ParagraphProps): ReactNode {
return (
{paragraph.content.map((content) => (
))}
)
}
type ParagraphContentProps = {
content: TSD.ParagraphContent
}
function ParagraphContent({ content }: ParagraphContentProps): ReactNode | null {
switch (content.type) {
case `link`:
return {content.text}
case `plainText`:
return {content.text}
case `softBreak`:
return null
}
}
function stringToNumber(str: string): number {
let hash = 0
if (str.length === 0) return hash
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i)
hash = (hash << 5) - hash + char
hash |= 0 // Convert to 32bit integer
}
return hash
}