@mocanvas/mocanvas 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +114 -0
- package/dist/index.d.ts +1969 -0
- package/dist/index.js +6422 -0
- package/dist/index.js.map +1 -0
- package/dist/ui-62NV5N7K.css +550 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Symbio Digital
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# mocanvas
|
|
2
|
+
|
|
3
|
+
An infinite-canvas SDK for the web: a React component with default shapes,
|
|
4
|
+
tools and UI, on top of a Rust + WebAssembly engine that does geometry,
|
|
5
|
+
hit-testing, culling and tessellation and writes GPU buffers straight into
|
|
6
|
+
linear memory.
|
|
7
|
+
|
|
8
|
+
- Repository, docs and issues: <https://github.com/SYMBIO/mocanvas>
|
|
9
|
+
- Benchmarks against the library it is shaped after:
|
|
10
|
+
[docs/BENCHMARK.md](https://github.com/SYMBIO/mocanvas/blob/main/docs/BENCHMARK.md)
|
|
11
|
+
- Coming from tldraw:
|
|
12
|
+
[docs/MIGRATION.md](https://github.com/SYMBIO/mocanvas/blob/main/docs/MIGRATION.md)
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @mocanvas/mocanvas react react-dom
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`react` and `react-dom` (>= 18) are peer dependencies.
|
|
21
|
+
|
|
22
|
+
## Use
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { createRoot } from "react-dom/client"
|
|
26
|
+
import { Mocanvas, createShapeId, type Editor } from "@mocanvas/mocanvas"
|
|
27
|
+
|
|
28
|
+
function App() {
|
|
29
|
+
function onMount(editor: Editor) {
|
|
30
|
+
editor.createShapes([
|
|
31
|
+
{
|
|
32
|
+
id: createShapeId(),
|
|
33
|
+
type: "geo",
|
|
34
|
+
x: 100,
|
|
35
|
+
y: 100,
|
|
36
|
+
props: { geo: "rectangle", w: 200, h: 120, color: "blue", fill: "semi" },
|
|
37
|
+
},
|
|
38
|
+
])
|
|
39
|
+
editor.zoomToFit()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div style={{ position: "absolute", inset: 0 }}>
|
|
44
|
+
<Mocanvas onMount={onMount} />
|
|
45
|
+
</div>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
createRoot(document.getElementById("root")!).render(<App />)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`<Mocanvas />` fills its container, so give the container a size. The default
|
|
53
|
+
UI stylesheet is imported by the package itself — no extra CSS import.
|
|
54
|
+
|
|
55
|
+
## ESM only
|
|
56
|
+
|
|
57
|
+
The package ships ES modules and no CommonJS build. It locates its `.wasm`
|
|
58
|
+
asset with `import.meta.url`, which has no CommonJS equivalent. Vite, webpack
|
|
59
|
+
5, Next, Astro, Remix and Rollup all consume it as-is; `require("mocanvas")`
|
|
60
|
+
does not work.
|
|
61
|
+
|
|
62
|
+
## The WebAssembly engine
|
|
63
|
+
|
|
64
|
+
The engine lives in `@mocanvas/wasm` and is loaded on mount. **No bundler
|
|
65
|
+
configuration is required.** It resolves as
|
|
66
|
+
`new URL("../pkg/mocanvas_bg.wasm", import.meta.url)`, which bundlers
|
|
67
|
+
recognise — they emit the file as an asset and rewrite the URL — then fetches
|
|
68
|
+
it and verifies it really is WebAssembly. The file is ~256 KB and is fetched
|
|
69
|
+
separately; it is deliberately not inlined into the JavaScript bundle.
|
|
70
|
+
|
|
71
|
+
When that URL does not answer with WebAssembly (a dev server's HTML fallback, a
|
|
72
|
+
404 page), the loader uses a base64 copy that ships in the package instead of
|
|
73
|
+
failing, logs one warning, and the canvas renders. The copy is behind a dynamic
|
|
74
|
+
`import()`, so it is its own chunk and is never downloaded otherwise.
|
|
75
|
+
|
|
76
|
+
Two optional notes:
|
|
77
|
+
|
|
78
|
+
- **Vite's dependency optimizer** pre-bundles with esbuild and rewrites that
|
|
79
|
+
URL without moving the asset, which is the one common way to land on the
|
|
80
|
+
fallback in `vite dev`. Excluding the package skips the extra download:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
// vite.config.ts — an optimisation, not a requirement
|
|
84
|
+
export default defineConfig({ optimizeDeps: { exclude: ["@mocanvas/wasm"] } })
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`vite build` is unaffected either way.
|
|
88
|
+
|
|
89
|
+
- **To serve the asset from a location of your own**, load the engine before
|
|
90
|
+
rendering:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { loadEngine } from "@mocanvas/wasm"
|
|
94
|
+
await loadEngine("/assets/mocanvas_bg.wasm") // URL, Response or bytes
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
An explicit input is used as given, with no fallback. The engine is a
|
|
98
|
+
singleton, so a later `<Mocanvas />` reuses it.
|
|
99
|
+
|
|
100
|
+
## Packages
|
|
101
|
+
|
|
102
|
+
| Package | What |
|
|
103
|
+
| ------------------ | ---------------------------------------------------------- |
|
|
104
|
+
| `@mocanvas/mocanvas` | `<Mocanvas />`, default shapes, tools, UI |
|
|
105
|
+
| `@mocanvas/editor` | `Editor`, `ShapeUtil`, `StateNode`, geometry, `<Canvas />` |
|
|
106
|
+
| `@mocanvas/store` | records, `Store`, schema, migrations, `.tldr` IO |
|
|
107
|
+
| `@mocanvas/state` | signals |
|
|
108
|
+
| `@mocanvas/wasm` | engine bindings |
|
|
109
|
+
| `@mocanvas/sync` | multiplayer: record diffs, presence, cursors |
|
|
110
|
+
| `@mocanvas/compat` | `TL`-prefixed aliases for a tldraw migration |
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT
|