Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a2723b9
Merge pull request #1 from tapava/develop
tapava Dec 26, 2025
32ba131
Merge pull request #2 from tapava/develop
tapava Dec 26, 2025
3009df6
fix(.gitignore): add .npmrc to ignore list to prevent committing npm …
Ghassen-Lassoued Dec 26, 2025
42e024a
Merge branch 'main' of https://github.com/tapava/compute-kit
Ghassen-Lassoued Dec 26, 2025
db7a1e3
fix(ci): update publish conditions and refine package publishing steps
Ghassen-Lassoued Dec 26, 2025
45100c0
chore: trigger publish workflow
Ghassen-Lassoued Dec 26, 2025
9e5acea
ci: add dedicated publish workflow
Ghassen-Lassoued Dec 26, 2025
88b920c
refactor: remove vanilla demo example and associated files
Ghassen-Lassoued Dec 26, 2025
0e8cef3
chore: include README.md in package files for core and react packages
Ghassen-Lassoued Dec 26, 2025
1dbde14
chore: bump version to 0.1.1 for core and react packages
Ghassen-Lassoued Dec 26, 2025
babfaaa
feat: add support for remote dependencies in ComputeKit and update RE…
Ghassen-Lassoued Dec 26, 2025
7c50389
chore: update license attribution in README.md
Ghassen-Lassoued Dec 26, 2025
b8a0be8
feat: add TODO list for future enhancements and features in ComputeKit
Ghassen-Lassoued Dec 27, 2025
bfbfa54
feat: enhance WASM loading with error handling and absolute path reso…
Ghassen-Lassoued Dec 27, 2025
0aae49c
feat: implement WASM loading and configuration for Vercel deployment
Ghassen-Lassoued Dec 27, 2025
f7a6340
fix: update vercel.json with version 2 and fix regex pattern
Ghassen-Lassoued Dec 27, 2025
e6aaa7a
fix: include compute.wasm in git for Vercel deployment
Ghassen-Lassoued Dec 27, 2025
c911ac9
refactor: build WASM during deployment instead of committing it
Ghassen-Lassoued Dec 27, 2025
a231df8
trigger redeploy
Ghassen-Lassoued Dec 27, 2025
84603d9
feat: add @computekit/react-query package for TanStack Query integration
Ghassen-Lassoued Dec 27, 2025
db0195e
ci: add @computekit/react-query to publish workflow
Ghassen-Lassoued Dec 27, 2025
5927ca1
doc: Add comprehensive documentation for ComputeKit
Ghassen-Lassoued Dec 27, 2025
f703f2c
fix: ensure pages setup is correctly enabled in workflow
Ghassen-Lassoued Dec 27, 2025
5a58ae8
fix: remove unnecessary enablement configuration in Setup Pages step
Ghassen-Lassoued Dec 27, 2025
bc6cf59
feat: update theme colors and add custom styles for ComputeKit
Ghassen-Lassoued Dec 27, 2025
e8d1da8
feat: enhance search component with improved styling and functionality
Ghassen-Lassoued Dec 27, 2025
4f98e33
fix: update code block styling for improved readability and dark them…
Ghassen-Lassoued Dec 27, 2025
4e22a11
feat: replace static table of contents with collapsible details in do…
Ghassen-Lassoued Dec 27, 2025
7ea8a3b
Add comprehensive documentation for debugging, performance, and multi…
Ghassen-Lassoued Dec 28, 2025
a20c9fa
feat: add raw block support for code snippets in documentation
Ghassen-Lassoued Dec 28, 2025
76b8822
fix: update table of contents formatting for improved readability
Ghassen-Lassoued Dec 28, 2025
6aade4a
chore: bump package versions for core, react-query, and react to late…
Ghassen-Lassoued Dec 28, 2025
163bf63
fix: add live demo link to documentation for better accessibility
Ghassen-Lassoued Dec 28, 2025
6cf6d10
fix: update WASM loading logic to support multiple paths and improve …
Ghassen-Lassoued Dec 29, 2025
d0a43d4
fix: enhance WASM loading logic to support multiple paths and improve…
Ghassen-Lassoued Dec 29, 2025
bafb432
fix: update WASM loading logic to use Vite-resolved URL and improve e…
Ghassen-Lassoued Dec 29, 2025
28f1847
Include WASM file for StackBlitz
Ghassen-Lassoued Dec 29, 2025
08cebff
fix: add StackBlitz links to README and index documentation for easie…
Ghassen-Lassoued Dec 29, 2025
c605f69
Revise README description and tagline
tapava Jan 2, 2026
ece8b0e
Update documentation
Ghassen-Lassoued Jan 7, 2026
1025667
Merge branch 'main' of https://github.com/tapava/compute-kit
Ghassen-Lassoued Jan 7, 2026
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
13 changes: 9 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
publish:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

steps:
- uses: actions/checkout@v4
Expand All @@ -53,9 +53,14 @@ jobs:
run: npm ci

- name: Build packages
run: npm run build
run: npm run build:packages

- name: Publish @computekit/core
run: cd packages/core && npm publish --access public || echo "Already published or failed"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to npm
run: npm publish --workspaces --access public
- name: Publish @computekit/react
run: cd packages/react && npm publish --access public || echo "Already published or failed"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
45 changes: 45 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy Documentation to GitHub Pages

on:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: 'pages'
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
with:
source: ./docs
destination: ./_site

- name: Upload artifact
uses: actions/upload-pages-artifact@v3

deploy:
runs-on: ubuntu-latest
needs: build
permissions:
pages: write
id-token: write
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
43 changes: 43 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Publish to npm

on:
workflow_dispatch:
push:
branches: [main]

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 22.x
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build packages
run: npm run build:packages

- name: Publish @computekit/core
run: cd packages/core && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
continue-on-error: true

- name: Publish @computekit/react
run: cd packages/react && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
continue-on-error: true

- name: Publish @computekit/react-query
run: cd packages/react-query && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
continue-on-error: true
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ build/
*.wasm
*.wasm.map

# But include the demo WASM file for StackBlitz
!examples/react-demo/public/compute.wasm

# IDE
.idea/
.vscode/
Expand All @@ -30,6 +33,9 @@ yarn-error.log*
.env.local
.env.*.local

# npm tokens - NEVER commit these!
.npmrc

# Temporary files
*.tmp
*.temp
Expand Down
91 changes: 58 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,33 @@

# ComputeKit

**The React-first toolkit for WASM and Web Workers**
**A tiny toolkit for heavy computations using Web Workers**

*Run heavy computations with React hooks. Use WASM for native-speed performance. Keep your UI at 60fps.*
*Integration with React hooks and WASM*

[![npm version](https://img.shields.io/npm/v/@computekit/core.svg)](https://www.npmjs.com/package/@computekit/core)
[![Bundle Size](https://img.shields.io/bundlephobia/minzip/@computekit/core)](https://bundlephobia.com/package/@computekit/core)
[![Bundle Size Core](https://img.shields.io/bundlephobia/minzip/@computekit/core?label=core%20size)](https://bundlephobia.com/package/@computekit/core)
[![Bundle Size React](https://img.shields.io/bundlephobia/minzip/@computekit/react?label=react%20size)](https://bundlephobia.com/package/@computekit/react)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue)](https://www.typescriptlang.org/)
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/compute-kit?file=README.md)

[Getting Started](#-getting-started) • [Examples](#-examples) • [API](#-api) • [React Hooks](#-react-hooks) • [WASM](#-webassembly-support)
[📚 Documentation](https://tapava.github.io/compute-kit) • [Live Demo](https://computekit-demo.vercel.app/) • [Getting Started](#-getting-started) • [Examples](#-examples) • [API](#-api) • [React Hooks](#-react-hooks) • [WASM](#-webassembly-support)

</div>

---

## ✨ Features

- ⚛️ **React-first** — Purpose-built hooks like `useCompute` with loading, error, and progress states
- 🦀 **WASM integration** — Load and call AssemblyScript/Rust WASM modules with zero boilerplate
- 🚀 **Non-blocking** — Everything runs in Web Workers, keeping your UI at 60fps
- 🔧 **Zero config** — No manual worker files, postMessage handlers, or WASM glue code
- 📦 **Tiny** — Core library is ~3KB gzipped
- 🎯 **TypeScript** — Full type safety for your compute functions and WASM bindings
- 🔄 **Worker pool** — Automatic load balancing across CPU cores
- 📊 **Progress tracking** Built-in progress reporting for long-running tasks
- 🔄 **Worker pool** : Automatic load balancing across CPU cores
- ⚛️ **React-first** : Provides hooks like `useCompute` with loading, error, and progress states
- 🦀 **WASM integration** : Easily load and call AssemblyScript/Rust WASM modules
- 🚀 **Non-blocking** : Everything runs in Web Workers
- 🔧 **Zero config** : No manual worker files or postMessage handlers
- 📦 **Tiny** : Core library is ~5KB gzipped
- 🎯 **TypeScript** : Full type safety for your compute functions and WASM bindings
- 📊 **Progress tracking** : Built-in progress reporting for long-running tasks

---

Expand All @@ -48,7 +50,7 @@ You _can_ use Web Workers and WASM without a library. But here's the reality:

---

## 🎯 When to use ComputeKit
## 🎯 When to use this toolkit (And when not to use it)

| ✅ Use ComputeKit | ❌ Don't use ComputeKit |
| ---------------------------------- | ---------------------------- |
Expand Down Expand Up @@ -102,7 +104,7 @@ kit.register('fibonacci', (n: number) => {

// 3. Run it (non-blocking!)
const result = await kit.run('fibonacci', 50);
console.log(result); // 12586269025 UI never froze!
console.log(result); // 12586269025 : UI never froze!
```

### React Usage
Expand Down Expand Up @@ -158,7 +160,7 @@ function Calculator() {

### React + WASM (Full Example)

This is where ComputeKit shines combining `useCompute` with WASM for native-speed performance:
This is where ComputeKit shines : combining `useCompute` with WASM for native-speed performance:

```tsx
import { ComputeKitProvider, useComputeKit, useCompute } from '@computekit/react';
Expand Down Expand Up @@ -252,7 +254,7 @@ function ImageProcessor() {

**Key benefits:**

- WASM runs in a Web Worker via `useCompute` UI stays responsive
- WASM runs in a Web Worker via `useCompute` : UI stays responsive
- Same familiar `loading`, `data`, `error` pattern as other compute functions
- WASM memory management encapsulated in the registered function
- Can easily add progress reporting, cancellation, etc.
Expand Down Expand Up @@ -323,11 +325,29 @@ const kit = new ComputeKit(options?: ComputeKitOptions);

#### Options

| Option | Type | Default | Description |
| ------------ | --------- | ------------------------------- | ----------------------- |
| `maxWorkers` | `number` | `navigator.hardwareConcurrency` | Max workers in the pool |
| `timeout` | `number` | `30000` | Default timeout in ms |
| `debug` | `boolean` | `false` | Enable debug logging |
| Option | Type | Default | Description |
| -------------------- | ---------- | ------------------------------- | ----------------------------------- |
| `maxWorkers` | `number` | `navigator.hardwareConcurrency` | Max workers in the pool |
| `timeout` | `number` | `30000` | Default timeout in ms |
| `debug` | `boolean` | `false` | Enable debug logging |
| `remoteDependencies` | `string[]` | `[]` | External scripts to load in workers |

### Remote Dependencies

Load external libraries inside your workers:

```typescript
const kit = new ComputeKit({
remoteDependencies: [
'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js',
],
});

kit.register('processData', (data: number[]) => {
// @ts-ignore - lodash loaded via importScripts
return _.chunk(data, 3);
});
```

#### Methods

Expand Down Expand Up @@ -363,20 +383,23 @@ const {
loading, // Boolean loading state
error, // Error if failed
progress, // Progress info
status, // 'idle' | 'running' | 'success' | 'error' | 'cancelled'
run, // Function to execute
reset, // Reset state
cancel, // Cancel current operation
} = useCompute<TInput, TOutput>(functionName, options?);
```

````

### `useComputeCallback`

Returns a memoized async function (similar to `useCallback`).

```typescript
const calculate = useComputeCallback('sum');
const result = await calculate([1, 2, 3, 4, 5]);
```
````

### `usePoolStats`

Expand Down Expand Up @@ -433,13 +456,13 @@ const wasmModule = await loadWasmModule('/compute/sum.wasm');

## ⚡ Performance Tips

1. **Transfer large data** Use typed arrays (Uint8Array, Float64Array) for automatic transfer optimization
1. **Transfer large data** : Use typed arrays (Uint8Array, Float64Array) for automatic transfer optimization

2. **Batch small operations** Combine many small tasks into one larger task
2. **Batch small operations** : Combine many small tasks into one larger task

3. **Right-size your pool** More workers ≠ better. Match to CPU cores.
3. **Right-size your pool** : More workers ≠ better. Match to CPU cores.

4. **Use WASM for math** AssemblyScript functions can be 10-100x faster for numeric work
4. **Use WASM for math** : AssemblyScript functions can be 10-100x faster for numeric work

```typescript
// ❌ Slow: Many small calls
Expand Down Expand Up @@ -500,13 +523,14 @@ computekit/
│ └── package.json
├── compute/ # AssemblyScript functions
│ ├── blur.ts
│ ├── fibonacci.ts
│ ├── mandelbrot.ts
│ └── matrix.ts
│ ├── matrix.ts
│ └── sum.ts
├── examples/
│ ├── react-demo/ # React example app
│ └── vanilla-demo/ # Vanilla JS example
│ └── react-demo/ # React example app
└── docs/ # Documentation
```
Expand All @@ -519,8 +543,8 @@ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md)

```bash
# Clone the repo
git clone https://github.com/your-username/computekit.git
cd computekit
git clone https://github.com/tapava/compute-kit.git
cd compute-kit

# Install dependencies
npm install
Expand All @@ -539,7 +563,7 @@ npm test

## 📄 License

MIT © [Your Name](https://github.com/your-username)
MIT © [Ghassen Lassoued](https://github.com/tapava)

---

Expand All @@ -548,6 +572,7 @@ MIT © [Your Name](https://github.com/your-username)
<sub>Built with ❤️ for the web platform</sub>
</p>
<p>
<a href="https://github.com/your-username/computekit">⭐ Star on GitHub</a>
<a href="https://tapava.github.io/compute-kit">📚 Read the Docs</a> •
<a href="https://github.com/tapava/compute-kit">⭐ Star on GitHub</a>
</p>
</div>
26 changes: 26 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ComputeKit TODO

## Features

- [ ] **Progress throttling** - Add optional `progressThrottle` option to prevent state flooding when compute functions fire progress updates in tight loops. Should throttle/debounce progress callbacks to avoid choking the main thread with re-renders.
- Add `progressThrottle?: number` option (ms) to `ComputeOptions`
- Throttle `onProgress` calls in the React hook
- Consider both throttle (regular intervals) and debounce (wait for pause) strategies

- [ ] **Typed registry** - Add TypeScript support to narrow function names to only registered functions for autocomplete and type safety.
- Make `useCompute('functionName')` autocomplete only registered function names
- Type safety on input/output based on registered function signatures
- Consider using TypeScript's string literal types or const assertions

## Improvements

- [ ] Add more WASM examples (Rust, C++)
- [ ] Benchmark suite for comparing JS vs WASM performance
- [ ] Documentation site (Docusaurus or similar)

## Ideas

- [ ] `useComputeMultiple` hook for managing multiple parallel tasks
- [ ] `useComputeFile` hook for loading functions from separate files
- [ ] Built-in caching for compute results
- [ ] Streaming results for very large outputs
File renamed without changes.
1 change: 1 addition & 0 deletions compute/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export {
vectorMagnitude,
vectorNormalize,
} from './matrix';
export { getBufferPtr, blurImage } from './blur';
6 changes: 6 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore Jekyll build output
_site/
.sass-cache/
.jekyll-cache/
.jekyll-metadata
vendor/
6 changes: 6 additions & 0 deletions docs/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://rubygems.org"

gem "jekyll", "~> 4.3"
gem "just-the-docs", "~> 0.8"
gem "jekyll-seo-tag"
gem "jekyll-include-cache"
Loading
Loading