@kittycad/web-view 1.0.0 → 1.0.1
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/README.md +91 -0
- package/package.json +1 -1
- package/kcl_wasm_lib_bg.wasm +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# @kittycad/web-view
|
|
2
|
+
|
|
3
|
+
Various helpers to get a Zoo KittyCAD WebRTC stream onto a web page!
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
* Each instance runs on a Web Worker, preventing main worker blocking.
|
|
8
|
+
* Take KCL as a string input, or a map of `path -> string`s.
|
|
9
|
+
* Supports raw scene and modeling commands.
|
|
10
|
+
* Managed multiplexing so that many can be used at once on a page.
|
|
11
|
+
* Supports Zoo camera controls (middle to pan, right to rotate, wheel to zoom).
|
|
12
|
+
* Written in vanilla TypeScript for easy porting to other frameworks.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install @kittycad/web-view @kittycad/lib
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
You will need to copy `node_modules/@kittycad/kcl-wasm-lib/kcl_wasm_lib_bg.wasm`
|
|
21
|
+
to the root of a directory that will be served by your web server.
|
|
22
|
+
|
|
23
|
+
## Quick demo
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
make serve
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Building
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
make build
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Example
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import * as zoo from '@kittycad/lib'
|
|
39
|
+
import { ZooWebView } from '@kittycad/web-view'
|
|
40
|
+
|
|
41
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
42
|
+
const token = 'api-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
43
|
+
|
|
44
|
+
const zooClient = new zoo.Client({
|
|
45
|
+
token,
|
|
46
|
+
baseUrl: 'wss://api.dev.zoo.dev',
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const zooWebView = new ZooWebView({
|
|
50
|
+
zooClient,
|
|
51
|
+
size: {
|
|
52
|
+
width: 256,
|
|
53
|
+
height: 256,
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
document.body.appendChild(zooWebView.el)
|
|
58
|
+
|
|
59
|
+
zooWebView.addEventListener('ready', (ev: Event) => {
|
|
60
|
+
const executor = ev.target.rtc.executor()
|
|
61
|
+
const project = new Map<string, string>()
|
|
62
|
+
project.set('main.kcl', `
|
|
63
|
+
import "ok.kcl"
|
|
64
|
+
sketch001 = startSketchOn(XY)
|
|
65
|
+
profile001 = startProfile(sketch001, at = [-3.5, -2.23])
|
|
66
|
+
|> line(end = [4.53, 5.73])
|
|
67
|
+
|> line(end = [5.18, -3.74])
|
|
68
|
+
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|
69
|
+
|> close()
|
|
70
|
+
extrude001 = extrude(profile001, length = 5 * 1)
|
|
71
|
+
|> appearance(color="#0000FF")
|
|
72
|
+
`)
|
|
73
|
+
project.set('ok.kcl', `
|
|
74
|
+
sketch001 = startSketchOn(XY)
|
|
75
|
+
profile001 = startProfile(sketch001, at = [-1.5, -2.23])
|
|
76
|
+
|> line(end = [4.53, 5.73])
|
|
77
|
+
|> line(end = [5.18, -3.74])
|
|
78
|
+
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|
79
|
+
|> close()
|
|
80
|
+
extrude001 = extrude(profile001, length = 5 * 1)
|
|
81
|
+
|> appearance(color="#FF0000")
|
|
82
|
+
`)
|
|
83
|
+
void executor.submit(project).then(() => {
|
|
84
|
+
console.log('All done running!')
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Pretty screenshot of making tons of these
|
|
91
|
+

|
package/package.json
CHANGED
package/kcl_wasm_lib_bg.wasm
DELETED
|
Binary file
|