@viji-dev/sdk 1.0.1 → 1.0.3
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 +18 -106
- package/package.json +3 -3
- package/src/cli/commands/create.js +25 -7
- package/src/templates/scene-templates.js +5 -5
package/README.md
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
# Viji SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Development environment for [Viji Creative](https://viji.art) scenes. Write scene code in your IDE, preview it live in the browser with real-time parameter controls, audio analysis, video input, and interaction handling — the same execution environment as the Viji platform. Supports Canvas 2D, WebGL, P5.js, and GLSL shaders.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
+
Requires [Node.js](https://nodejs.org/) v18 or later.
|
|
8
|
+
|
|
7
9
|
```bash
|
|
8
10
|
npm install -g @viji-dev/sdk
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
To update to the latest version:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm update -g @viji-dev/sdk
|
|
17
|
+
```
|
|
12
18
|
|
|
13
19
|
## Quick Start
|
|
14
20
|
|
|
15
21
|
```bash
|
|
16
|
-
# Create a
|
|
17
|
-
mkdir my-
|
|
22
|
+
# Create a workspace folder (any name works)
|
|
23
|
+
mkdir my-viji-scenes && cd my-viji-scenes
|
|
18
24
|
|
|
19
25
|
# Create your first scene (native renderer is the default)
|
|
20
26
|
viji create my-scene
|
|
@@ -58,7 +64,7 @@ The server watches the `scenes/` directory for changes and pushes updates to the
|
|
|
58
64
|
|
|
59
65
|
### `viji build <scene-name> [-o <file>]`
|
|
60
66
|
|
|
61
|
-
Bundle a scene into a single file for deployment.
|
|
67
|
+
Bundle a scene into a single file for deployment to the Viji platform.
|
|
62
68
|
|
|
63
69
|
```bash
|
|
64
70
|
viji build my-scene # outputs dist/my-scene.js
|
|
@@ -67,114 +73,20 @@ viji build my-scene -o bundle/output.js # custom output path
|
|
|
67
73
|
|
|
68
74
|
Multi-file scenes (with local imports) are resolved and concatenated automatically.
|
|
69
75
|
|
|
70
|
-
##
|
|
71
|
-
|
|
72
|
-
### Native Renderer
|
|
73
|
-
|
|
74
|
-
```javascript
|
|
75
|
-
// @renderer native
|
|
76
|
-
|
|
77
|
-
const speed = viji.slider(1.0, { min: 0.1, max: 5.0, label: 'Speed' });
|
|
78
|
-
const baseColor = viji.color('#4488ff', { label: 'Color' });
|
|
79
|
-
|
|
80
|
-
function render(viji) {
|
|
81
|
-
const ctx = viji.useContext('2d');
|
|
82
|
-
const { width, height, time } = viji;
|
|
83
|
-
|
|
84
|
-
ctx.fillStyle = '#000000';
|
|
85
|
-
ctx.fillRect(0, 0, width, height);
|
|
86
|
-
|
|
87
|
-
const x = width / 2 + Math.cos(time * speed.value) * 100;
|
|
88
|
-
const y = height / 2 + Math.sin(time * speed.value) * 100;
|
|
89
|
-
|
|
90
|
-
ctx.beginPath();
|
|
91
|
-
ctx.arc(x, y, 40, 0, Math.PI * 2);
|
|
92
|
-
ctx.fillStyle = baseColor.value;
|
|
93
|
-
ctx.fill();
|
|
94
|
-
}
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Available contexts: `viji.useContext('2d')`, `viji.useContext('webgl')`, `viji.useContext('webgl2')`.
|
|
98
|
-
|
|
99
|
-
### P5 Renderer
|
|
100
|
-
|
|
101
|
-
```javascript
|
|
102
|
-
// @renderer p5
|
|
103
|
-
|
|
104
|
-
const speed = viji.slider(1.0, { min: 0.1, max: 5.0, label: 'Speed' });
|
|
105
|
-
|
|
106
|
-
function render(viji, p5) {
|
|
107
|
-
p5.background(0);
|
|
108
|
-
const x = viji.width / 2 + p5.cos(viji.time * speed.value) * 100;
|
|
109
|
-
const y = viji.height / 2 + p5.sin(viji.time * speed.value) * 100;
|
|
110
|
-
p5.noStroke();
|
|
111
|
-
p5.fill(255);
|
|
112
|
-
p5.ellipse(x, y, 80, 80);
|
|
113
|
-
}
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### GLSL Shader
|
|
117
|
-
|
|
118
|
-
```glsl
|
|
119
|
-
// @renderer shader
|
|
120
|
-
precision highp float;
|
|
121
|
-
|
|
122
|
-
uniform vec2 u_resolution;
|
|
123
|
-
uniform float u_time;
|
|
124
|
-
uniform vec2 u_mouse;
|
|
125
|
-
|
|
126
|
-
void main() {
|
|
127
|
-
vec2 uv = gl_FragCoord.xy / u_resolution;
|
|
128
|
-
vec3 col = 0.5 + 0.5 * cos(u_time + uv.xyx + vec3(0.0, 2.0, 4.0));
|
|
129
|
-
gl_FragColor = vec4(col, 1.0);
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
Shader scenes receive a full set of uniforms automatically: `u_resolution`, `u_time`, `u_deltaTime`, `u_mouse`, `u_audio*`, `u_video*`, and more. See the core documentation for the complete uniform list.
|
|
134
|
-
|
|
135
|
-
## Parameter System
|
|
136
|
-
|
|
137
|
-
Parameters create UI controls that artists can tweak in real time:
|
|
138
|
-
|
|
139
|
-
```javascript
|
|
140
|
-
const speed = viji.slider(1.0, { min: 0, max: 10, label: 'Speed' });
|
|
141
|
-
const tint = viji.color('#ff0000', { label: 'Tint' });
|
|
142
|
-
const mirror = viji.toggle(false, { label: 'Mirror' });
|
|
143
|
-
const mode = viji.select('circles', { options: ['circles', 'squares', 'lines'], label: 'Mode' });
|
|
144
|
-
const label = viji.text('Hello', { label: 'Label' });
|
|
145
|
-
const count = viji.number(5, { min: 1, max: 100, step: 1, label: 'Count' });
|
|
146
|
-
const bg = viji.image(null, { label: 'Background' });
|
|
147
|
-
const reset = viji.button({ label: 'Reset' });
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
Access values via `speed.value`, `tint.value`, etc. Button parameters expose `reset.pressed`.
|
|
76
|
+
## Writing Scenes
|
|
151
77
|
|
|
152
|
-
|
|
78
|
+
The SDK includes built-in documentation for the Viji scene API, parameter system, renderers, audio/video analysis, and interaction handling.
|
|
153
79
|
|
|
154
|
-
|
|
80
|
+
Start the development server and open the docs panel from the toolbar, or navigate directly to `http://localhost:3000/docs`.
|
|
155
81
|
|
|
156
|
-
|
|
157
|
-
|----------|------|-------------|
|
|
158
|
-
| `canvas` | `OffscreenCanvas` | The rendering canvas |
|
|
159
|
-
| `width`, `height` | `number` | Canvas dimensions |
|
|
160
|
-
| `time` | `number` | Elapsed time in seconds |
|
|
161
|
-
| `deltaTime` | `number` | Time since last frame |
|
|
162
|
-
| `frameCount` | `number` | Total frames rendered |
|
|
163
|
-
| `fps` | `number` | Current frames per second |
|
|
164
|
-
| `audio` | `AudioAPI` | Audio analysis (volume, bands, beat, spectral) |
|
|
165
|
-
| `video` | `VideoAPI` | Video input |
|
|
166
|
-
| `mouse` | `MouseAPI` | Mouse position and buttons |
|
|
167
|
-
| `keyboard` | `KeyboardAPI` | Key states (`isPressed`, `wasPressed`, `wasReleased`) |
|
|
168
|
-
| `touches` | `TouchAPI` | Touch points |
|
|
169
|
-
| `pointer` | `PointerAPI` | Unified pointer input |
|
|
170
|
-
| `device` | `DeviceSensorState` | Accelerometer, gyroscope |
|
|
82
|
+
The documentation includes live code playgrounds where you can experiment with the API directly in the browser.
|
|
171
83
|
|
|
172
84
|
## Project Structure
|
|
173
85
|
|
|
174
|
-
After creating a few scenes, your
|
|
86
|
+
After creating a few scenes, your workspace looks like this:
|
|
175
87
|
|
|
176
88
|
```
|
|
177
|
-
my-
|
|
89
|
+
my-viji-scenes/
|
|
178
90
|
├── scenes/
|
|
179
91
|
│ ├── my-scene/
|
|
180
92
|
│ │ └── main.js
|
|
@@ -185,7 +97,7 @@ my-project/
|
|
|
185
97
|
└── global.d.ts # IDE type support (auto-generated)
|
|
186
98
|
```
|
|
187
99
|
|
|
188
|
-
No configuration files, no `node_modules`, no build tools in
|
|
100
|
+
No configuration files, no `node_modules`, no build tools in your workspace. Everything is handled by the globally installed SDK.
|
|
189
101
|
|
|
190
102
|
## License
|
|
191
103
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viji-dev/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Professional toolkit for creating interactive Viji scenes",
|
|
6
6
|
"keywords": [
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"typescript-eslint": "^8.39.1",
|
|
69
69
|
"vite": "^6.3.5",
|
|
70
70
|
"zustand": "^5.0.6",
|
|
71
|
-
"@viji-dev/
|
|
72
|
-
"@viji-dev/
|
|
71
|
+
"@viji-dev/docs-viewer": "0.1.0",
|
|
72
|
+
"@viji-dev/design-system": "0.1.0"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"dev": "vite",
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { mkdir, writeFile } from 'fs/promises';
|
|
1
|
+
import { mkdir, writeFile, readFile } from 'fs/promises';
|
|
2
2
|
import { existsSync } from 'fs';
|
|
3
|
-
import { join } from 'path';
|
|
4
|
-
import {
|
|
3
|
+
import { join, dirname } from 'path';
|
|
4
|
+
import { createRequire } from 'module';
|
|
5
|
+
import { getSceneTemplate, getGlobalDtsFileName, getSceneFileExtension, VALID_RENDERERS } from '../../templates/scene-templates.js';
|
|
5
6
|
import { validateProjectName } from '../utils/cli-utils.js';
|
|
6
7
|
|
|
8
|
+
function resolveCoreDtsPath(fileName) {
|
|
9
|
+
try {
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
const coreEntry = require.resolve('@viji-dev/core');
|
|
12
|
+
return join(dirname(coreEntry), fileName);
|
|
13
|
+
} catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
export async function createCommand(sceneName, options) {
|
|
8
19
|
try {
|
|
9
20
|
const renderer = options.renderer || 'native';
|
|
@@ -38,10 +49,17 @@ export async function createCommand(sceneName, options) {
|
|
|
38
49
|
|
|
39
50
|
const globalDtsPath = join(cwd, 'global.d.ts');
|
|
40
51
|
if (!existsSync(globalDtsPath)) {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
const dtsFileName = getGlobalDtsFileName(renderer);
|
|
53
|
+
if (dtsFileName) {
|
|
54
|
+
const dtsSourcePath = resolveCoreDtsPath(dtsFileName);
|
|
55
|
+
if (dtsSourcePath && existsSync(dtsSourcePath)) {
|
|
56
|
+
const dtsContent = await readFile(dtsSourcePath, 'utf-8');
|
|
57
|
+
await writeFile(globalDtsPath, dtsContent);
|
|
58
|
+
console.log('Created global.d.ts for IDE type support');
|
|
59
|
+
} else {
|
|
60
|
+
console.warn('Could not locate core type definitions — global.d.ts was not created.');
|
|
61
|
+
console.warn('IDE autocompletion for the Viji API may not be available.');
|
|
62
|
+
}
|
|
45
63
|
}
|
|
46
64
|
}
|
|
47
65
|
|
|
@@ -60,9 +60,9 @@ void main() {
|
|
|
60
60
|
`,
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
const
|
|
64
|
-
native:
|
|
65
|
-
p5:
|
|
63
|
+
const GLOBAL_DTS_FILE = {
|
|
64
|
+
native: 'artist-global.d.ts',
|
|
65
|
+
p5: 'artist-global-p5.d.ts',
|
|
66
66
|
shader: null,
|
|
67
67
|
};
|
|
68
68
|
|
|
@@ -74,8 +74,8 @@ export function getSceneTemplate(renderer = 'native') {
|
|
|
74
74
|
return template;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
export function
|
|
78
|
-
return
|
|
77
|
+
export function getGlobalDtsFileName(renderer = 'native') {
|
|
78
|
+
return GLOBAL_DTS_FILE[renderer] ?? GLOBAL_DTS_FILE.native;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export function getSceneFileExtension(renderer = 'native') {
|