@nexart/codemode-sdk 1.0.1 → 1.1.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/CHANGELOG.md +109 -0
- package/CODE_MODE_PROTOCOL.md +312 -0
- package/README.md +308 -56
- package/dist/core-index.d.ts +21 -0
- package/dist/core-index.d.ts.map +1 -0
- package/dist/core-index.js +26 -0
- package/dist/execute.d.ts +46 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +268 -0
- package/dist/index.d.ts +36 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -17
- package/dist/loop-engine.d.ts +4 -1
- package/dist/loop-engine.d.ts.map +1 -1
- package/dist/loop-engine.js +17 -12
- package/dist/noise-bridge.d.ts +44 -0
- package/dist/noise-bridge.d.ts.map +1 -0
- package/dist/noise-bridge.js +68 -0
- package/dist/noise-engine.d.ts +74 -0
- package/dist/noise-engine.d.ts.map +1 -0
- package/dist/noise-engine.js +132 -0
- package/dist/noise-sketches/fractalNoise.d.ts +11 -0
- package/dist/noise-sketches/fractalNoise.d.ts.map +1 -0
- package/dist/noise-sketches/fractalNoise.js +121 -0
- package/dist/noise-sketches/index.d.ts +21 -0
- package/dist/noise-sketches/index.d.ts.map +1 -0
- package/dist/noise-sketches/index.js +28 -0
- package/dist/p5-runtime.d.ts +56 -4
- package/dist/p5-runtime.d.ts.map +1 -1
- package/dist/p5-runtime.js +348 -22
- package/dist/sound-bridge.d.ts +89 -0
- package/dist/sound-bridge.d.ts.map +1 -0
- package/dist/sound-bridge.js +128 -0
- package/dist/soundart-engine.d.ts +87 -0
- package/dist/soundart-engine.d.ts.map +1 -0
- package/dist/soundart-engine.js +173 -0
- package/dist/soundart-sketches/chladniBloom.d.ts +3 -0
- package/dist/soundart-sketches/chladniBloom.d.ts.map +1 -0
- package/dist/soundart-sketches/chladniBloom.js +53 -0
- package/dist/soundart-sketches/dualVortex.d.ts +3 -0
- package/dist/soundart-sketches/dualVortex.d.ts.map +1 -0
- package/dist/soundart-sketches/dualVortex.js +67 -0
- package/dist/soundart-sketches/geometryIllusion.d.ts +3 -0
- package/dist/soundart-sketches/geometryIllusion.d.ts.map +1 -0
- package/dist/soundart-sketches/geometryIllusion.js +89 -0
- package/dist/soundart-sketches/index.d.ts +39 -0
- package/dist/soundart-sketches/index.d.ts.map +1 -0
- package/dist/soundart-sketches/index.js +72 -0
- package/dist/soundart-sketches/isoflow.d.ts +3 -0
- package/dist/soundart-sketches/isoflow.d.ts.map +1 -0
- package/dist/soundart-sketches/isoflow.js +60 -0
- package/dist/soundart-sketches/loomWeave.d.ts +3 -0
- package/dist/soundart-sketches/loomWeave.d.ts.map +1 -0
- package/dist/soundart-sketches/loomWeave.js +59 -0
- package/dist/soundart-sketches/noiseTerraces.d.ts +3 -0
- package/dist/soundart-sketches/noiseTerraces.d.ts.map +1 -0
- package/dist/soundart-sketches/noiseTerraces.js +53 -0
- package/dist/soundart-sketches/orb.d.ts +3 -0
- package/dist/soundart-sketches/orb.d.ts.map +1 -0
- package/dist/soundart-sketches/orb.js +50 -0
- package/dist/soundart-sketches/pixelGlyphs.d.ts +3 -0
- package/dist/soundart-sketches/pixelGlyphs.d.ts.map +1 -0
- package/dist/soundart-sketches/pixelGlyphs.js +72 -0
- package/dist/soundart-sketches/prismFlowFields.d.ts +3 -0
- package/dist/soundart-sketches/prismFlowFields.d.ts.map +1 -0
- package/dist/soundart-sketches/prismFlowFields.js +51 -0
- package/dist/soundart-sketches/radialBurst.d.ts +3 -0
- package/dist/soundart-sketches/radialBurst.d.ts.map +1 -0
- package/dist/soundart-sketches/radialBurst.js +60 -0
- package/dist/soundart-sketches/resonantSoundBodies.d.ts +3 -0
- package/dist/soundart-sketches/resonantSoundBodies.d.ts.map +1 -0
- package/dist/soundart-sketches/resonantSoundBodies.js +89 -0
- package/dist/soundart-sketches/rings.d.ts +11 -0
- package/dist/soundart-sketches/rings.d.ts.map +1 -0
- package/dist/soundart-sketches/rings.js +89 -0
- package/dist/soundart-sketches/squares.d.ts +3 -0
- package/dist/soundart-sketches/squares.d.ts.map +1 -0
- package/dist/soundart-sketches/squares.js +52 -0
- package/dist/soundart-sketches/waveStripes.d.ts +3 -0
- package/dist/soundart-sketches/waveStripes.d.ts.map +1 -0
- package/dist/soundart-sketches/waveStripes.js +44 -0
- package/dist/static-engine.d.ts +4 -1
- package/dist/static-engine.d.ts.map +1 -1
- package/dist/static-engine.js +13 -8
- package/dist/types.d.ts +75 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +19 -1
- package/package.json +23 -17
package/README.md
CHANGED
|
@@ -1,85 +1,197 @@
|
|
|
1
1
|
# NexArt Code Mode Runtime SDK
|
|
2
2
|
|
|
3
|
-
Version: 0.
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
**Version: 1.0.2 (Protocol v1.0.0)**
|
|
4
|
+
|
|
5
|
+
╔══════════════════════════════════════════════════════════════════════════════╗
|
|
6
|
+
║ @nexart/codemode-sdk — Canonical Code Mode Authority ║
|
|
7
|
+
║ ║
|
|
8
|
+
║ This SDK defines the official Code Mode execution surface. ║
|
|
9
|
+
║ All implementations (NexArt, ByX, external) MUST use this SDK. ║
|
|
10
|
+
║ ║
|
|
11
|
+
║ Protocol: nexart ║
|
|
12
|
+
║ Engine: codemode ║
|
|
13
|
+
║ SDK Version: 1.0.2 ║
|
|
14
|
+
║ Protocol Version: 1.0.0 ║
|
|
15
|
+
║ Phase: 1 ║
|
|
16
|
+
║ Enforcement: HARD ║
|
|
17
|
+
╚══════════════════════════════════════════════════════════════════════════════╝
|
|
6
18
|
|
|
7
19
|
---
|
|
8
20
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
21
|
+
## PROTOCOL LOCK — v1.0.0
|
|
22
|
+
|
|
23
|
+
| Property | Value |
|
|
24
|
+
|----------|-------|
|
|
25
|
+
| Protocol Name | NexArt Code Mode |
|
|
26
|
+
| Version | v1.0.0 |
|
|
27
|
+
| Status | **HARD LOCKED** |
|
|
28
|
+
| Phase | 1 |
|
|
29
|
+
| Lock Date | December 2024 |
|
|
30
|
+
|
|
31
|
+
**This protocol surface is frozen. Any breaking change requires v2.0.0.**
|
|
32
|
+
|
|
33
|
+
The following are locked and will not change in v1.x:
|
|
34
|
+
|
|
35
|
+
- Execution model (Static and Loop modes)
|
|
36
|
+
- VAR[0..9] specification (0-10 read-only variables, missing indices return 0)
|
|
37
|
+
- Determinism guarantee (seed + VAR → identical output)
|
|
38
|
+
- Time semantics (t, frameCount, time, tGlobal)
|
|
39
|
+
- Random and noise behavior (seeded Mulberry32, Perlin)
|
|
40
|
+
- Forbidden patterns list (13 patterns)
|
|
41
|
+
- Canvas pre-initialization (no createCanvas)
|
|
12
42
|
|
|
13
43
|
---
|
|
14
44
|
|
|
15
|
-
|
|
45
|
+
A minimal, deterministic rendering engine for generative art.
|
|
16
46
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
47
|
+
## Protocol Authority
|
|
48
|
+
|
|
49
|
+
**This SDK is the single source of truth for Code Mode semantics.**
|
|
50
|
+
|
|
51
|
+
If someone asks: "How does Code Mode work in NexArt?"
|
|
52
|
+
|
|
53
|
+
The answer is: "Whatever @nexart/codemode-sdk does — that is the protocol."
|
|
20
54
|
|
|
21
55
|
---
|
|
22
56
|
|
|
23
|
-
##
|
|
57
|
+
## What's New in v1.0.2
|
|
24
58
|
|
|
25
|
-
|
|
26
|
-
|
|
59
|
+
- **VAR input is now optional (0-10 elements)**
|
|
60
|
+
- Omit `vars` or pass `[]` for empty (defaults to all zeros)
|
|
61
|
+
- Input length must be 0-10 (throws if > 10)
|
|
62
|
+
- Values must be finite numbers in [0, 100] (throws if out of range)
|
|
63
|
+
- Runtime VAR is ALWAYS 10 elements (padded with zeros for consistency)
|
|
64
|
+
- **Backwards compatible**: existing code passing 10 elements works unchanged
|
|
27
65
|
|
|
28
|
-
|
|
66
|
+
## v1.0.1
|
|
29
67
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
```
|
|
68
|
+
- Protocol Lock section formalized with HARD LOCKED status
|
|
69
|
+
- VAR specification clarified with enforcement tables
|
|
70
|
+
|
|
71
|
+
## v1.0.0 (Protocol Lock)
|
|
72
|
+
|
|
73
|
+
- **Protocol Lock**: Phase 1 execution surface is now LOCKED
|
|
74
|
+
- **Canonical Entry Point**: `executeCodeMode()` is the official execution API
|
|
75
|
+
- **Protocol Metadata**: All executions include protocol headers for verification
|
|
76
|
+
- **VAR[0..9] Protocol Variables**: First-class protocol inputs (read-only, 0-100)
|
|
77
|
+
- **Full CSS Color Support**: hex, rgb(), rgba(), hsl(), hsla()
|
|
78
|
+
- **Determinism Guarantee**: Same code + seed + vars = identical output
|
|
44
79
|
|
|
45
80
|
---
|
|
46
81
|
|
|
47
82
|
## What This SDK Is
|
|
48
83
|
|
|
49
|
-
This SDK provides
|
|
84
|
+
This SDK provides the **canonical runtime** for executing p5.js-style generative art:
|
|
50
85
|
|
|
51
86
|
- **Static Mode**: Executes `setup()` only, outputs PNG
|
|
52
87
|
- **Loop Mode**: Frame-authoritative rendering, outputs MP4
|
|
88
|
+
- **Deterministic**: Seed-controlled randomness, no external state
|
|
89
|
+
- **Protocol-Compliant**: All outputs include verification metadata
|
|
90
|
+
|
|
91
|
+
The SDK enforces the **NexArt Code Mode Protocol v1.0.0** for reproducible, mint-safe generative art.
|
|
53
92
|
|
|
54
93
|
---
|
|
55
94
|
|
|
56
95
|
## What This SDK Is NOT
|
|
57
96
|
|
|
58
|
-
- **Not a
|
|
97
|
+
- **Not a suggestion** — This SDK IS the protocol, not a reference implementation
|
|
59
98
|
- **Not a UI library** — No React components, no wallet integration
|
|
60
99
|
- **Not an IPFS client** — Does not handle storage or minting
|
|
61
100
|
- **Not p5.js** — Uses a minimal subset of p5.js-like functions
|
|
62
101
|
|
|
63
102
|
---
|
|
64
103
|
|
|
65
|
-
##
|
|
104
|
+
## Installation
|
|
66
105
|
|
|
67
|
-
|
|
106
|
+
```bash
|
|
107
|
+
# Copy the sdk/codemode folder to your project
|
|
108
|
+
cp -r sdk/codemode your-project/lib/codemode
|
|
109
|
+
```
|
|
68
110
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Canonical API
|
|
114
|
+
|
|
115
|
+
### `executeCodeMode(input: ExecuteCodeModeInput): Promise<ExecuteCodeModeResult>`
|
|
116
|
+
|
|
117
|
+
**This is the official, canonical entry point for Code Mode execution.**
|
|
118
|
+
|
|
119
|
+
All implementations MUST use this function.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { executeCodeMode } from '@nexart/codemode-sdk';
|
|
123
|
+
|
|
124
|
+
const result = await executeCodeMode({
|
|
125
|
+
source: `
|
|
126
|
+
function setup() {
|
|
127
|
+
background(255);
|
|
128
|
+
fill(0);
|
|
129
|
+
let size = map(VAR[0], 0, 100, 50, 200);
|
|
130
|
+
ellipse(width/2, height/2, size);
|
|
131
|
+
}
|
|
132
|
+
`,
|
|
133
|
+
width: 1950,
|
|
134
|
+
height: 2400,
|
|
135
|
+
seed: 12345,
|
|
136
|
+
vars: [50, 75, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
137
|
+
mode: 'static'
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Result includes protocol metadata
|
|
141
|
+
console.log(result.metadata.protocol); // 'nexart'
|
|
142
|
+
console.log(result.metadata.engine); // 'codemode'
|
|
143
|
+
console.log(result.metadata.protocolVersion); // '1.0.0'
|
|
144
|
+
console.log(result.metadata.deterministic); // true
|
|
145
|
+
console.log(result.image); // PNG Blob
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Input Parameters
|
|
149
|
+
|
|
150
|
+
| Parameter | Type | Required | Description |
|
|
151
|
+
|-----------|------|----------|-------------|
|
|
152
|
+
| `source` | `string` | ✅ | Code with setup() and optional draw() |
|
|
153
|
+
| `width` | `number` | ✅ | Canvas width in pixels |
|
|
154
|
+
| `height` | `number` | ✅ | Canvas height in pixels |
|
|
155
|
+
| `seed` | `number` | ✅ | Seed for deterministic randomness |
|
|
156
|
+
| `vars` | `number[]` | ❌ | VAR[0..9] values (0-100), defaults to all zeros |
|
|
157
|
+
| `mode` | `'static' \| 'loop'` | ✅ | Execution mode |
|
|
158
|
+
| `totalFrames` | `number` | ⚠️ | Required for loop mode |
|
|
159
|
+
|
|
160
|
+
### Result Structure
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
interface ExecuteCodeModeResult {
|
|
164
|
+
image?: Blob; // Static mode: PNG
|
|
165
|
+
video?: Blob; // Loop mode: MP4
|
|
166
|
+
frames?: ImageData[]; // Optional: raw frame data
|
|
167
|
+
metadata: {
|
|
168
|
+
protocol: 'nexart';
|
|
169
|
+
engine: 'codemode';
|
|
170
|
+
protocolVersion: '1.0.0';
|
|
171
|
+
phase: 1;
|
|
172
|
+
deterministic: true;
|
|
173
|
+
seed: number;
|
|
174
|
+
vars: number[];
|
|
175
|
+
width: number;
|
|
176
|
+
height: number;
|
|
177
|
+
mode: 'static' | 'loop';
|
|
178
|
+
totalFrames?: number;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
72
182
|
|
|
73
183
|
---
|
|
74
184
|
|
|
75
|
-
## API
|
|
185
|
+
## Legacy API
|
|
186
|
+
|
|
187
|
+
> ⚠️ **Note**: The `createEngine()` API is still supported but new implementations should use `executeCodeMode()`.
|
|
76
188
|
|
|
77
189
|
### `createEngine(config: EngineConfig): Engine`
|
|
78
190
|
|
|
79
191
|
Create a rendering engine instance.
|
|
80
192
|
|
|
81
193
|
```typescript
|
|
82
|
-
import { createEngine } from '
|
|
194
|
+
import { createEngine } from './codemode';
|
|
83
195
|
|
|
84
196
|
const engine = createEngine({
|
|
85
197
|
mode: 'static', // 'static' | 'loop'
|
|
@@ -100,9 +212,13 @@ await engine.run({
|
|
|
100
212
|
function setup() {
|
|
101
213
|
background(255);
|
|
102
214
|
fill(0);
|
|
103
|
-
|
|
215
|
+
// Use VAR for external control
|
|
216
|
+
let size = map(VAR[0], 0, 100, 50, 200);
|
|
217
|
+
ellipse(width/2, height/2, size);
|
|
104
218
|
}
|
|
105
219
|
`,
|
|
220
|
+
seed: 12345, // Optional: seed for deterministic randomness
|
|
221
|
+
vars: [50, 75, 0, 0, 0, 0, 0, 0, 0, 0], // Optional: VAR[0..9] values (0-100)
|
|
106
222
|
onPreview: (canvas) => {
|
|
107
223
|
// Optional: called with canvas after first frame
|
|
108
224
|
},
|
|
@@ -122,6 +238,53 @@ await engine.run({
|
|
|
122
238
|
});
|
|
123
239
|
```
|
|
124
240
|
|
|
241
|
+
### Protocol Variables (VAR[0..9]) — Protocol v1.0.0
|
|
242
|
+
|
|
243
|
+
Protocol variables are first-class inputs that control artwork parameters.
|
|
244
|
+
|
|
245
|
+
**VAR Specification (SDK v1.0.2):**
|
|
246
|
+
|
|
247
|
+
| Property | Value | Enforcement |
|
|
248
|
+
|----------|-------|-------------|
|
|
249
|
+
| Input count | 0-10 (VAR[0]..VAR[9]) | HARD — throws if > 10 |
|
|
250
|
+
| Runtime count | Always 10 | Padded with zeros |
|
|
251
|
+
| Type | finite number | HARD — throws if non-number |
|
|
252
|
+
| Range | 0-100 | HARD — throws if out of range |
|
|
253
|
+
| Mutability | Read-only | HARD — Proxy blocks writes |
|
|
254
|
+
| Injection | Before execution | Guaranteed |
|
|
255
|
+
| Lifecycle | Stable for entire render | Guaranteed |
|
|
256
|
+
| Default | All zeros | If not provided |
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
// Pass values when running (0-10 elements)
|
|
260
|
+
await engine.run({
|
|
261
|
+
code: myCode,
|
|
262
|
+
vars: [80, 50, 25], // VAR[0]=80, VAR[1]=50, VAR[2]=25, VAR[3..9]=0
|
|
263
|
+
onComplete: (result) => { /* ... */ },
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// Or omit entirely (all zeros)
|
|
267
|
+
await engine.run({
|
|
268
|
+
code: myCode,
|
|
269
|
+
onComplete: (result) => { /* ... */ },
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// Access in sketch code
|
|
273
|
+
function setup() {
|
|
274
|
+
let density = map(VAR[0], 0, 100, 10, 200);
|
|
275
|
+
let speed = map(VAR[1], 0, 100, 0.5, 5);
|
|
276
|
+
// VAR[5] returns 0 if not provided
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**Rules (Protocol Law):**
|
|
281
|
+
- Input accepts 0-10 elements; runtime VAR is always 10 elements
|
|
282
|
+
- VAR is injected BEFORE code execution (padded with zeros if needed)
|
|
283
|
+
- VAR values are READ-ONLY at runtime (Proxy-protected)
|
|
284
|
+
- Writing to VAR throws a protocol error
|
|
285
|
+
- Values MUST be in range 0-100 (throws if out of range)
|
|
286
|
+
- Same code + same seed + same VARs = identical output
|
|
287
|
+
|
|
125
288
|
### `engine.stop(): void`
|
|
126
289
|
|
|
127
290
|
Cancel a running render (Loop mode only).
|
|
@@ -160,20 +323,35 @@ Get the resolved engine configuration.
|
|
|
160
323
|
|
|
161
324
|
---
|
|
162
325
|
|
|
163
|
-
## Forbidden Patterns
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
326
|
+
## Forbidden Patterns — LOCKED v1.0.0
|
|
327
|
+
|
|
328
|
+
The following 13 patterns are rejected with `[Code Mode Protocol Error]`:
|
|
329
|
+
|
|
330
|
+
| Pattern | Reason |
|
|
331
|
+
|---------|--------|
|
|
332
|
+
| `setTimeout` | Async timing breaks determinism |
|
|
333
|
+
| `setInterval` | Async timing breaks determinism |
|
|
334
|
+
| `requestAnimationFrame` | Async timing breaks determinism |
|
|
335
|
+
| `Date.now()` | Time-based entropy forbidden |
|
|
336
|
+
| `new Date()` | Time-based entropy forbidden |
|
|
337
|
+
| `Math.random()` | Use seeded `random()` instead |
|
|
338
|
+
| `fetch()` | External IO forbidden |
|
|
339
|
+
| `XMLHttpRequest` | External IO forbidden |
|
|
340
|
+
| `createCanvas()` | Canvas is pre-initialized |
|
|
341
|
+
| `document.*` | DOM access forbidden |
|
|
342
|
+
| `window.*` | DOM access forbidden |
|
|
343
|
+
| `import` | External imports forbidden |
|
|
344
|
+
| `require()` | External imports forbidden |
|
|
345
|
+
|
|
346
|
+
Additionally in Loop Mode:
|
|
347
|
+
- `noLoop()` — Incompatible with frame capture
|
|
170
348
|
|
|
171
349
|
---
|
|
172
350
|
|
|
173
351
|
## Example: Static Mode
|
|
174
352
|
|
|
175
353
|
```typescript
|
|
176
|
-
import { createEngine } from '
|
|
354
|
+
import { createEngine } from './codemode';
|
|
177
355
|
|
|
178
356
|
const engine = createEngine({ mode: 'static' });
|
|
179
357
|
|
|
@@ -202,7 +380,7 @@ await engine.run({
|
|
|
202
380
|
## Example: Loop Mode
|
|
203
381
|
|
|
204
382
|
```typescript
|
|
205
|
-
import { createEngine } from '
|
|
383
|
+
import { createEngine } from './codemode';
|
|
206
384
|
|
|
207
385
|
const engine = createEngine({
|
|
208
386
|
mode: 'loop',
|
|
@@ -257,7 +435,17 @@ The SDK includes a minimal p5.js-like runtime with:
|
|
|
257
435
|
`push`, `pop`, `translate`, `rotate`, `scale`, `resetMatrix`
|
|
258
436
|
|
|
259
437
|
**Color:**
|
|
260
|
-
`colorMode`, `color`, `lerpColor`
|
|
438
|
+
`colorMode`, `color`, `lerpColor`, `red`, `green`, `blue`, `alpha`, `hue`, `saturation`, `brightness`
|
|
439
|
+
|
|
440
|
+
**Color Formats:**
|
|
441
|
+
All of the following are accepted by `fill()`, `stroke()`, `background()`:
|
|
442
|
+
- Grayscale: `fill(128)`, `fill(128, 127)`
|
|
443
|
+
- RGB: `fill(255, 0, 0)`, `fill(255, 0, 0, 128)`
|
|
444
|
+
- Hex: `fill('#ff0000')`, `fill('#f00')`
|
|
445
|
+
- CSS: `fill('rgb(255,0,0)')`, `fill('rgba(255,0,0,0.5)')`, `fill('hsl(180,50%,50%)')`
|
|
446
|
+
|
|
447
|
+
**Protocol Variables:**
|
|
448
|
+
`VAR` — Array of 10 values (VAR[0] through VAR[9])
|
|
261
449
|
|
|
262
450
|
**Math:**
|
|
263
451
|
`random`, `noise`, `map`, `constrain`, `lerp`, `dist`, `mag`, `norm`
|
|
@@ -278,14 +466,14 @@ Loop Mode requires server-side video encoding. The SDK calls:
|
|
|
278
466
|
POST /api/encode-loop
|
|
279
467
|
```
|
|
280
468
|
|
|
281
|
-
Ensure your server has this endpoint available
|
|
469
|
+
Ensure your server has this endpoint available (NexArt provides this).
|
|
282
470
|
|
|
283
471
|
---
|
|
284
472
|
|
|
285
473
|
## Files
|
|
286
474
|
|
|
287
475
|
```
|
|
288
|
-
|
|
476
|
+
sdk/codemode/
|
|
289
477
|
├── index.ts # Main export
|
|
290
478
|
├── engine.ts # createEngine entry point
|
|
291
479
|
├── types.ts # TypeScript types
|
|
@@ -297,16 +485,80 @@ Ensure your server has this endpoint available, or provide your own encoding sol
|
|
|
297
485
|
|
|
298
486
|
---
|
|
299
487
|
|
|
300
|
-
##
|
|
488
|
+
## License
|
|
301
489
|
|
|
302
|
-
|
|
490
|
+
MIT License
|
|
303
491
|
|
|
304
|
-
|
|
492
|
+
Copyright (c) 2024 NexArt
|
|
305
493
|
|
|
306
494
|
---
|
|
307
495
|
|
|
308
|
-
##
|
|
496
|
+
## External Builders
|
|
309
497
|
|
|
310
|
-
|
|
498
|
+
This SDK is designed for use by:
|
|
311
499
|
|
|
312
|
-
|
|
500
|
+
- **NexArt App**: The main generative art platform
|
|
501
|
+
- **ByX**: Curated collection system
|
|
502
|
+
- **External Builders**: Any platform consuming NexArt Code Mode
|
|
503
|
+
|
|
504
|
+
### Integration Example
|
|
505
|
+
|
|
506
|
+
```typescript
|
|
507
|
+
import { executeCodeMode } from '@nexart/codemode-sdk';
|
|
508
|
+
|
|
509
|
+
// Execute with explicit VAR values
|
|
510
|
+
const result = await executeCodeMode({
|
|
511
|
+
source: artistCode,
|
|
512
|
+
width: 1950,
|
|
513
|
+
height: 2400,
|
|
514
|
+
seed: 12345,
|
|
515
|
+
vars: [50, 75, 25, 0, 0, 0, 0, 0, 0, 0], // Exactly 10 values
|
|
516
|
+
mode: 'static'
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// Result includes full protocol metadata for verification
|
|
520
|
+
const { image, metadata } = result;
|
|
521
|
+
console.log(metadata.protocolVersion); // '1.0.0'
|
|
522
|
+
console.log(metadata.deterministic); // true
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
### Error Handling
|
|
526
|
+
|
|
527
|
+
All protocol violations throw descriptive errors:
|
|
528
|
+
|
|
529
|
+
```typescript
|
|
530
|
+
try {
|
|
531
|
+
await executeCodeMode({ ... });
|
|
532
|
+
} catch (error) {
|
|
533
|
+
// "[Code Mode Protocol Error] VAR array must have exactly 10 elements, got 5"
|
|
534
|
+
// "[Code Mode Protocol Error] Forbidden pattern: Math.random()"
|
|
535
|
+
console.error(error.message);
|
|
536
|
+
}
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
|
|
541
|
+
## Frozen Execution Guarantees — v1.0.0
|
|
542
|
+
|
|
543
|
+
The following guarantees are LOCKED and will not change in v1.x:
|
|
544
|
+
|
|
545
|
+
| Guarantee | Description |
|
|
546
|
+
|-----------|-------------|
|
|
547
|
+
| Determinism | Same code + same seed + same VARs = identical output |
|
|
548
|
+
| Static Mode | `setup()` only, single PNG output |
|
|
549
|
+
| Loop Mode | Frame-authoritative, `draw()` per frame, MP4 output |
|
|
550
|
+
| Time Semantics | `t` ∈ [0,1), `frameCount` ∈ [0,totalFrames), `time` in seconds |
|
|
551
|
+
| Random | Seeded Mulberry32 PRNG via `random()` |
|
|
552
|
+
| Noise | Seeded Perlin noise via `noise()` |
|
|
553
|
+
| Canvas | Pre-initialized, no `createCanvas()` |
|
|
554
|
+
| VAR | Exactly 10 read-only protocol variables |
|
|
555
|
+
| Forbidden Patterns | 13 patterns rejected (see above) |
|
|
556
|
+
|
|
557
|
+
---
|
|
558
|
+
|
|
559
|
+
## Future Work (Phase 2+)
|
|
560
|
+
|
|
561
|
+
- GSL v1 SDK (protocol layer) — separate package
|
|
562
|
+
- Extended p5.js compatibility
|
|
563
|
+
- WebGL rendering support
|
|
564
|
+
- GIF output option
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexart/codemode-sdk v1.1.0 — Core Exports
|
|
3
|
+
*
|
|
4
|
+
* Canonical execution engine for NexArt Code Mode.
|
|
5
|
+
* This is the single source of truth for Code Mode semantics.
|
|
6
|
+
*
|
|
7
|
+
* Protocol: v1.0.0 (LOCKED)
|
|
8
|
+
* Enforcement: HARD
|
|
9
|
+
*/
|
|
10
|
+
export { executeCodeMode, validateCodeModeSource, } from './execute';
|
|
11
|
+
export { type RenderMode, type TimeVariables, type ProtocolMetadata, type EngineConfig, type RenderResult, type RunOptions, type ProgressInfo, type Engine, type ExecuteCodeModeInput, type ExecuteCodeModeResult, PROTOCOL_IDENTITY, DEFAULT_VARS, DEFAULT_CONFIG, } from './types';
|
|
12
|
+
export { createP5Runtime, injectTimeVariables, createProtocolVAR, VAR_COUNT, VAR_MIN, VAR_MAX, CODE_MODE_PROTOCOL_VERSION, CODE_MODE_PROTOCOL_PHASE, CODE_MODE_ENFORCEMENT, type P5Runtime, type P5RuntimeConfig, } from './p5-runtime';
|
|
13
|
+
export { runStaticMode, } from './static-engine';
|
|
14
|
+
export { runLoopMode, cancelLoopMode, } from './loop-engine';
|
|
15
|
+
export { createEngine, } from './engine';
|
|
16
|
+
/**
|
|
17
|
+
* SDK Identity
|
|
18
|
+
*/
|
|
19
|
+
export declare const SDK_VERSION = "1.1.1";
|
|
20
|
+
export declare const SDK_NAME = "@nexart/codemode-sdk";
|
|
21
|
+
//# sourceMappingURL=core-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-index.d.ts","sourceRoot":"","sources":["../core-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EACL,eAAe,EACf,sBAAsB,GACvB,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,iBAAiB,EACjB,YAAY,EACZ,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACT,OAAO,EACP,OAAO,EACP,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,EACrB,KAAK,SAAS,EACd,KAAK,eAAe,GACrB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,aAAa,GACd,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,WAAW,EACX,cAAc,GACf,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,YAAY,GACb,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,eAAO,MAAM,QAAQ,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexart/codemode-sdk v1.1.0 — Core Exports
|
|
3
|
+
*
|
|
4
|
+
* Canonical execution engine for NexArt Code Mode.
|
|
5
|
+
* This is the single source of truth for Code Mode semantics.
|
|
6
|
+
*
|
|
7
|
+
* Protocol: v1.0.0 (LOCKED)
|
|
8
|
+
* Enforcement: HARD
|
|
9
|
+
*/
|
|
10
|
+
// Core execution
|
|
11
|
+
export { executeCodeMode, validateCodeModeSource, } from './execute';
|
|
12
|
+
// Protocol types
|
|
13
|
+
export { PROTOCOL_IDENTITY, DEFAULT_VARS, DEFAULT_CONFIG, } from './types';
|
|
14
|
+
// Runtime
|
|
15
|
+
export { createP5Runtime, injectTimeVariables, createProtocolVAR, VAR_COUNT, VAR_MIN, VAR_MAX, CODE_MODE_PROTOCOL_VERSION, CODE_MODE_PROTOCOL_PHASE, CODE_MODE_ENFORCEMENT, } from './p5-runtime';
|
|
16
|
+
// Static engine
|
|
17
|
+
export { runStaticMode, } from './static-engine';
|
|
18
|
+
// Loop engine
|
|
19
|
+
export { runLoopMode, cancelLoopMode, } from './loop-engine';
|
|
20
|
+
// Engine utilities
|
|
21
|
+
export { createEngine, } from './engine';
|
|
22
|
+
/**
|
|
23
|
+
* SDK Identity
|
|
24
|
+
*/
|
|
25
|
+
export const SDK_VERSION = '1.1.1';
|
|
26
|
+
export const SDK_NAME = '@nexart/codemode-sdk';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NexArt Code Mode Runtime SDK - Canonical Execution Entry Point
|
|
3
|
+
*
|
|
4
|
+
* ╔══════════════════════════════════════════════════════════════════════════╗
|
|
5
|
+
* ║ CODE MODE PROTOCOL v1.0.0 (Phase 1) — CANONICAL ENTRY POINT ║
|
|
6
|
+
* ║ ║
|
|
7
|
+
* ║ This is the ONLY official way to execute Code Mode. ║
|
|
8
|
+
* ║ All implementations (NexArt, ByX, external) MUST use this function. ║
|
|
9
|
+
* ║ ║
|
|
10
|
+
* ║ Authority: @nexart/codemode-sdk ║
|
|
11
|
+
* ╚══════════════════════════════════════════════════════════════════════════╝
|
|
12
|
+
*/
|
|
13
|
+
import { ExecuteCodeModeInput, ExecuteCodeModeResult } from './types';
|
|
14
|
+
/**
|
|
15
|
+
* executeCodeMode — Canonical Code Mode Execution Entry Point
|
|
16
|
+
*
|
|
17
|
+
* This is the ONLY official way to execute Code Mode.
|
|
18
|
+
* All implementations MUST use this function.
|
|
19
|
+
*
|
|
20
|
+
* @param input - Execution parameters
|
|
21
|
+
* @returns Promise<ExecuteCodeModeResult> - Execution result with protocol metadata
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const result = await executeCodeMode({
|
|
26
|
+
* source: `function setup() { background(255); ellipse(width/2, height/2, 100); }`,
|
|
27
|
+
* width: 1950,
|
|
28
|
+
* height: 2400,
|
|
29
|
+
* seed: 12345,
|
|
30
|
+
* vars: [50, 75, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
31
|
+
* mode: 'static'
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* console.log(result.metadata.protocolVersion); // '1.0.0'
|
|
35
|
+
* console.log(result.image); // PNG Blob
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function executeCodeMode(input: ExecuteCodeModeInput): Promise<ExecuteCodeModeResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Validate code without executing
|
|
41
|
+
*/
|
|
42
|
+
export declare function validateCodeModeSource(source: string, mode: 'static' | 'loop'): {
|
|
43
|
+
valid: boolean;
|
|
44
|
+
errors: string[];
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../execute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EAKtB,MAAM,SAAS,CAAC;AA4MjB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,qBAAqB,CAAC,CAqBhC;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAuCpH"}
|