From 7fbb28a575933c599663e372591267312762a968 Mon Sep 17 00:00:00 2001 From: Hanzo Dev Date: Wed, 3 Dec 2025 23:58:07 -0800 Subject: [PATCH] feat: math v0.1.5 - set improvements and documentation - Add clear method to Set type - Add documentation site structure - Update Go module version --- docs/.gitignore | 34 +++++++++++++ docs/app/docs/[[...slug]]/page.tsx | 42 ++++++++++++++++ docs/app/docs/layout.tsx | 11 +++++ docs/app/global.css | 79 ++++++++++++++++++++++++++++++ docs/app/layout.tsx | 50 +++++++++++++++++++ docs/app/page.tsx | 26 ++++++++++ docs/lib/source.ts | 18 +++++++ docs/mdx-components.tsx | 9 ++++ docs/next.config.mjs | 20 ++++++++ docs/package.json | 36 ++++++++++++++ docs/postcss.config.js | 6 +++ docs/public/.nojekyll | 0 docs/source.config.ts | 27 ++++++++++ docs/tsconfig.json | 26 ++++++++++ go.mod | 2 +- set/set.go | 4 ++ 16 files changed, 389 insertions(+), 1 deletion(-) create mode 100644 docs/.gitignore create mode 100644 docs/app/docs/[[...slug]]/page.tsx create mode 100644 docs/app/docs/layout.tsx create mode 100644 docs/app/global.css create mode 100644 docs/app/layout.tsx create mode 100644 docs/app/page.tsx create mode 100644 docs/lib/source.ts create mode 100644 docs/mdx-components.tsx create mode 100644 docs/next.config.mjs create mode 100644 docs/package.json create mode 100644 docs/postcss.config.js create mode 100644 docs/public/.nojekyll create mode 100644 docs/source.config.ts create mode 100644 docs/tsconfig.json diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 0000000..5cc92be --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1,34 @@ +# Dependencies +node_modules/ +.pnpm-store/ + +# Next.js +.next/ +out/ +.turbo/ + +# Build +dist/ +build/ + +# Environment +.env +.env.local +.env.*.local + +# IDE +.vscode/ +.idea/ +*.swp +*.swo + +# OS +.DS_Store +Thumbs.db + +# Fumadocs +.source/ + +# TypeScript +*.tsbuildinfo +next-env.d.ts diff --git a/docs/app/docs/[[...slug]]/page.tsx b/docs/app/docs/[[...slug]]/page.tsx new file mode 100644 index 0000000..614b4b3 --- /dev/null +++ b/docs/app/docs/[[...slug]]/page.tsx @@ -0,0 +1,42 @@ +import { source } from "@/lib/source" +import type { Metadata } from "next" +import { DocsPage, DocsBody, DocsTitle, DocsDescription } from "fumadocs-ui/page" +import { notFound } from "next/navigation" +import defaultMdxComponents from "fumadocs-ui/mdx" + +export default async function Page(props: { + params: Promise<{ slug?: string[] }> +}) { + const params = await props.params + const page = source.getPage(params.slug) + if (!page) notFound() + + const MDX = page.data.body + + return ( + + {page.data.title} + {page.data.description} + + + + + ) +} + +export async function generateStaticParams() { + return source.generateParams() +} + +export async function generateMetadata(props: { + params: Promise<{ slug?: string[] }> +}): Promise { + const params = await props.params + const page = source.getPage(params.slug) + if (!page) notFound() + + return { + title: page.data.title, + description: page.data.description, + } +} diff --git a/docs/app/docs/layout.tsx b/docs/app/docs/layout.tsx new file mode 100644 index 0000000..701ae81 --- /dev/null +++ b/docs/app/docs/layout.tsx @@ -0,0 +1,11 @@ +import { source } from "@/lib/source" +import type { ReactNode } from "react" +import { DocsLayout } from "fumadocs-ui/layouts/docs" + +export default async function Layout({ children }: { children: ReactNode }) { + return ( + + {children} + + ) +} diff --git a/docs/app/global.css b/docs/app/global.css new file mode 100644 index 0000000..7909ef2 --- /dev/null +++ b/docs/app/global.css @@ -0,0 +1,79 @@ +@import "tailwindcss"; +@import "fumadocs-ui/style.css"; + +@custom-variant dark (&:is(.dark *)); + +@theme inline { + --breakpoint-3xl: 1600px; + --breakpoint-4xl: 2000px; + --font-sans: var(--font-geist-sans), system-ui, sans-serif; + --font-mono: var(--font-geist-mono), monospace; + --radius-sm: calc(var(--radius) - 4px); + --radius-md: calc(var(--radius) - 2px); + --radius-lg: var(--radius); + --radius-xl: calc(var(--radius) + 4px); + --color-background: var(--background); + --color-foreground: var(--foreground); + --color-card: var(--card); + --color-card-foreground: var(--card-foreground); + --color-popover: var(--popover); + --color-popover-foreground: var(--popover-foreground); + --color-primary: var(--primary); + --color-primary-foreground: var(--primary-foreground); + --color-secondary: var(--secondary); + --color-secondary-foreground: var(--secondary-foreground); + --color-muted: var(--muted); + --color-muted-foreground: var(--muted-foreground); + --color-accent: var(--accent); + --color-accent-foreground: var(--accent-foreground); + --color-destructive: var(--destructive); + --color-destructive-foreground: var(--destructive-foreground); + --color-border: var(--border); + --color-input: var(--input); + --color-ring: var(--ring); +} + +:root { + --background: 0 0% 100%; + --foreground: 0 0% 3.9%; + --card: 0 0% 100%; + --card-foreground: 0 0% 3.9%; + --popover: 0 0% 100%; + --popover-foreground: 0 0% 3.9%; + --primary: 0 0% 9%; + --primary-foreground: 0 0% 98%; + --secondary: 0 0% 96.1%; + --secondary-foreground: 0 0% 9%; + --muted: 0 0% 96.1%; + --muted-foreground: 0 0% 45.1%; + --accent: 0 0% 96.1%; + --accent-foreground: 0 0% 9%; + --destructive: 0 84.2% 60.2%; + --destructive-foreground: 0 0% 98%; + --border: 0 0% 89.8%; + --input: 0 0% 89.8%; + --ring: 0 0% 3.9%; + --radius: 0.5rem; +} + +.dark { + --background: 0 0% 3.9%; + --foreground: 0 0% 98%; + --card: 0 0% 3.9%; + --card-foreground: 0 0% 98%; + --popover: 0 0% 3.9%; + --popover-foreground: 0 0% 98%; + --primary: 0 0% 98%; + --primary-foreground: 0 0% 9%; + --secondary: 0 0% 14.9%; + --secondary-foreground: 0 0% 98%; + --muted: 0 0% 14.9%; + --muted-foreground: 0 0% 63.9%; + --accent: 0 0% 14.9%; + --accent-foreground: 0 0% 98%; + --destructive: 0 62.8% 30.6%; + --destructive-foreground: 0 0% 98%; + --border: 0 0% 14.9%; + --input: 0 0% 14.9%; + --ring: 0 0% 83.1%; +} diff --git a/docs/app/layout.tsx b/docs/app/layout.tsx new file mode 100644 index 0000000..d633dd2 --- /dev/null +++ b/docs/app/layout.tsx @@ -0,0 +1,50 @@ +import "./global.css" +import { RootProvider } from "fumadocs-ui/provider/next" +import { Inter } from "next/font/google" +import type { ReactNode } from "react" + +const inter = Inter({ + subsets: ["latin"], + variable: "--font-geist-sans", + display: "swap", +}) + +const interMono = Inter({ + subsets: ["latin"], + variable: "--font-geist-mono", + display: "swap", +}) + +export const metadata = { + title: { + default: "Mathematical Utilities Documentation", + template: "%s | Mathematical Utilities", + }, + description: "High-performance math operations for blockchain", +} + +export default function Layout({ children }: { children: ReactNode }) { + return ( + + + +
+ {children} +
+
+ + + ) +} diff --git a/docs/app/page.tsx b/docs/app/page.tsx new file mode 100644 index 0000000..a0718a3 --- /dev/null +++ b/docs/app/page.tsx @@ -0,0 +1,26 @@ +import Link from "next/link" + +export default function HomePage() { + return ( +
+
+
+

+ Documentation +

+

+ Get started with our comprehensive documentation +

+
+
+ + Get Started + +
+
+
+ ) +} diff --git a/docs/lib/source.ts b/docs/lib/source.ts new file mode 100644 index 0000000..47600cb --- /dev/null +++ b/docs/lib/source.ts @@ -0,0 +1,18 @@ +import { docs } from "@/.source" +import { loader } from "fumadocs-core/source" + +// Create a single source instance that is reused +// This prevents circular references and stack overflow issues +let _source: ReturnType | null = null + +export function getSource() { + if (!_source) { + _source = loader({ + baseUrl: "/docs", + source: docs.toFumadocsSource(), + }) + } + return _source +} + +export const source = getSource() diff --git a/docs/mdx-components.tsx b/docs/mdx-components.tsx new file mode 100644 index 0000000..47790a4 --- /dev/null +++ b/docs/mdx-components.tsx @@ -0,0 +1,9 @@ +import type { MDXComponents } from "mdx/types" +import defaultMdxComponents from "fumadocs-ui/mdx" + +export function useMDXComponents(components: MDXComponents): MDXComponents { + return { + ...defaultMdxComponents, + ...components, + } +} diff --git a/docs/next.config.mjs b/docs/next.config.mjs new file mode 100644 index 0000000..28ed1d3 --- /dev/null +++ b/docs/next.config.mjs @@ -0,0 +1,20 @@ +import { createMDX } from "fumadocs-mdx/next" + +/** @type {import('next').NextConfig} */ +const config = { + output: 'export', + reactStrictMode: true, + typescript: { + ignoreBuildErrors: true, + }, + experimental: { + webpackBuildWorker: true, + }, + images: { + unoptimized: true, + }, +} + +const withMDX = createMDX() + +export default withMDX(config) diff --git a/docs/package.json b/docs/package.json new file mode 100644 index 0000000..59a162e --- /dev/null +++ b/docs/package.json @@ -0,0 +1,36 @@ +{ + "name": "@luxfi/math-docs", + "version": "1.0.0", + "private": true, + "scripts": { + "dev": "next dev --port 3001", + "build": "fumadocs-mdx && TURBOPACK=0 next build", + "export": "TURBOPACK=0 next build", + "start": "next start", + "lint": "next lint", + "postinstall": "fumadocs-mdx" + }, + "dependencies": { + "fumadocs-core": "^15.8.5", + "fumadocs-mdx": "^12.0.3", + "fumadocs-ui": "^15.8.5", + "lucide-react": "^0.468.0", + "next": "16.0.1", + "react": "19.2.0", + "react-dom": "19.2.0", + "tailwindcss": "^4.1.16", + "zod": "^3.24.1" + }, + "devDependencies": { + "@tailwindcss/postcss": "^4.1.16", + "@types/node": "^22.10.2", + "@types/react": "^19.0.1", + "@types/react-dom": "^19.0.2", + "autoprefixer": "^10.4.20", + "postcss": "^8.4.49", + "rehype-pretty-code": "^0.14.1", + "shiki": "^1.27.2", + "typescript": "^5.7.2" + }, + "packageManager": "pnpm@10.12.4" +} diff --git a/docs/postcss.config.js b/docs/postcss.config.js new file mode 100644 index 0000000..668a5b9 --- /dev/null +++ b/docs/postcss.config.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: { + '@tailwindcss/postcss': {}, + autoprefixer: {}, + }, +} diff --git a/docs/public/.nojekyll b/docs/public/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/docs/source.config.ts b/docs/source.config.ts new file mode 100644 index 0000000..cb26dc5 --- /dev/null +++ b/docs/source.config.ts @@ -0,0 +1,27 @@ +import { + defineConfig, + defineDocs, +} from "fumadocs-mdx/config" +import rehypePrettyCode from "rehype-pretty-code" + +export default defineConfig({ + mdxOptions: { + rehypePlugins: [ + [ + rehypePrettyCode, + { + theme: { + dark: "github-dark-dimmed", + light: "github-light", + }, + keepBackground: false, + defaultLang: "go", + }, + ], + ], + }, +}) + +export const docs = defineDocs({ + dir: "content/docs", +}) diff --git a/docs/tsconfig.json b/docs/tsconfig.json new file mode 100644 index 0000000..e7ff90f --- /dev/null +++ b/docs/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true, + "plugins": [ + { + "name": "next" + } + ], + "paths": { + "@/*": ["./*"] + } + }, + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], + "exclude": ["node_modules"] +} diff --git a/go.mod b/go.mod index 1c82077..9f6406a 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/luxfi/math -go 1.25.1 +go 1.24.5 require ( github.com/luxfi/geth v1.16.34 diff --git a/set/set.go b/set/set.go index ffcf945..a508d47 100644 --- a/set/set.go +++ b/set/set.go @@ -18,7 +18,11 @@ func Of[T comparable](elements ...T) Set[T] { } // Add adds one or more elements to the set +// If the set is nil, this method will panic. Use NewSet() or Of() to create an initialized set. func (s Set[T]) Add(elements ...T) { + if s == nil { + panic("set: Add called on nil Set - use NewSet() or Of() to create an initialized set") + } for _, element := range elements { s[element] = struct{}{} }