@nexart/codemode-sdk 1.8.1 → 1.8.2

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.
Files changed (137) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE.md +5 -5
  3. package/README.md +72 -11
  4. package/dist/sdk/codemode/core-index.d.ts +6 -4
  5. package/dist/sdk/codemode/core-index.d.ts.map +1 -1
  6. package/dist/sdk/codemode/core-index.js +6 -4
  7. package/dist/{entry → sdk/codemode/entry}/browser.d.ts +5 -2
  8. package/dist/sdk/codemode/entry/browser.d.ts.map +1 -0
  9. package/dist/{entry → sdk/codemode/entry}/browser.js +10 -4
  10. package/dist/{entry → sdk/codemode/entry}/node.d.ts +2 -1
  11. package/dist/sdk/codemode/entry/node.d.ts.map +1 -0
  12. package/dist/{entry → sdk/codemode/entry}/node.js +2 -1
  13. package/dist/{runtime.d.ts → sdk/codemode/runtime.d.ts} +2 -2
  14. package/dist/sdk/codemode/runtime.d.ts.map +1 -0
  15. package/dist/{runtime.js → sdk/codemode/runtime.js} +3 -2
  16. package/dist/sdk/codemode/static-engine.d.ts.map +1 -1
  17. package/dist/sdk/codemode/static-engine.js +24 -11
  18. package/dist/sdk/codemode/version.d.ts +18 -0
  19. package/dist/sdk/codemode/version.d.ts.map +1 -0
  20. package/dist/sdk/codemode/version.js +17 -0
  21. package/examples/agent-quickstart.ts +159 -0
  22. package/examples/preflight-test.ts +1 -1
  23. package/package.json +2 -1
  24. package/dist/builder-manifest.d.ts +0 -79
  25. package/dist/builder-manifest.d.ts.map +0 -1
  26. package/dist/builder-manifest.js +0 -97
  27. package/dist/core-index.d.ts +0 -21
  28. package/dist/core-index.d.ts.map +0 -1
  29. package/dist/core-index.js +0 -26
  30. package/dist/engine.d.ts +0 -24
  31. package/dist/engine.d.ts.map +0 -1
  32. package/dist/engine.js +0 -67
  33. package/dist/entry/browser.d.ts.map +0 -1
  34. package/dist/entry/node.d.ts.map +0 -1
  35. package/dist/execute.d.ts +0 -46
  36. package/dist/execute.d.ts.map +0 -1
  37. package/dist/execute.js +0 -283
  38. package/dist/execution-sandbox.d.ts +0 -107
  39. package/dist/execution-sandbox.d.ts.map +0 -1
  40. package/dist/execution-sandbox.js +0 -207
  41. package/dist/index.d.ts +0 -31
  42. package/dist/index.d.ts.map +0 -1
  43. package/dist/index.js +0 -63
  44. package/dist/loop-engine.d.ts +0 -22
  45. package/dist/loop-engine.d.ts.map +0 -1
  46. package/dist/loop-engine.js +0 -229
  47. package/dist/noise-bridge.d.ts +0 -44
  48. package/dist/noise-bridge.d.ts.map +0 -1
  49. package/dist/noise-bridge.js +0 -68
  50. package/dist/noise-engine.d.ts +0 -74
  51. package/dist/noise-engine.d.ts.map +0 -1
  52. package/dist/noise-engine.js +0 -132
  53. package/dist/noise-sketches/fractalNoise.d.ts +0 -11
  54. package/dist/noise-sketches/fractalNoise.d.ts.map +0 -1
  55. package/dist/noise-sketches/fractalNoise.js +0 -121
  56. package/dist/noise-sketches/index.d.ts +0 -21
  57. package/dist/noise-sketches/index.d.ts.map +0 -1
  58. package/dist/noise-sketches/index.js +0 -28
  59. package/dist/p5-runtime.d.ts +0 -75
  60. package/dist/p5-runtime.d.ts.map +0 -1
  61. package/dist/p5-runtime.js +0 -1031
  62. package/dist/runtime.d.ts.map +0 -1
  63. package/dist/sdk/codemode/index.d.ts +0 -31
  64. package/dist/sdk/codemode/index.d.ts.map +0 -1
  65. package/dist/sdk/codemode/index.js +0 -63
  66. package/dist/sdk/codemode/noise-bridge.d.ts +0 -44
  67. package/dist/sdk/codemode/noise-bridge.d.ts.map +0 -1
  68. package/dist/sdk/codemode/noise-bridge.js +0 -68
  69. package/dist/sdk/codemode/noise-engine.d.ts +0 -74
  70. package/dist/sdk/codemode/noise-engine.d.ts.map +0 -1
  71. package/dist/sdk/codemode/noise-engine.js +0 -132
  72. package/dist/sdk/codemode/noise-sketches/fractalNoise.d.ts +0 -11
  73. package/dist/sdk/codemode/noise-sketches/fractalNoise.d.ts.map +0 -1
  74. package/dist/sdk/codemode/noise-sketches/fractalNoise.js +0 -121
  75. package/dist/sdk/codemode/noise-sketches/index.d.ts +0 -21
  76. package/dist/sdk/codemode/noise-sketches/index.d.ts.map +0 -1
  77. package/dist/sdk/codemode/noise-sketches/index.js +0 -28
  78. package/dist/shared/noiseSnapshot.d.ts +0 -59
  79. package/dist/shared/noiseSnapshot.d.ts.map +0 -1
  80. package/dist/shared/noiseSnapshot.js +0 -72
  81. package/dist/sound-bridge.d.ts +0 -89
  82. package/dist/sound-bridge.d.ts.map +0 -1
  83. package/dist/sound-bridge.js +0 -128
  84. package/dist/soundart-engine.d.ts +0 -87
  85. package/dist/soundart-engine.d.ts.map +0 -1
  86. package/dist/soundart-engine.js +0 -173
  87. package/dist/soundart-sketches/chladniBloom.d.ts +0 -3
  88. package/dist/soundart-sketches/chladniBloom.d.ts.map +0 -1
  89. package/dist/soundart-sketches/chladniBloom.js +0 -53
  90. package/dist/soundart-sketches/dualVortex.d.ts +0 -3
  91. package/dist/soundart-sketches/dualVortex.d.ts.map +0 -1
  92. package/dist/soundart-sketches/dualVortex.js +0 -67
  93. package/dist/soundart-sketches/geometryIllusion.d.ts +0 -3
  94. package/dist/soundart-sketches/geometryIllusion.d.ts.map +0 -1
  95. package/dist/soundart-sketches/geometryIllusion.js +0 -89
  96. package/dist/soundart-sketches/index.d.ts +0 -39
  97. package/dist/soundart-sketches/index.d.ts.map +0 -1
  98. package/dist/soundart-sketches/index.js +0 -72
  99. package/dist/soundart-sketches/isoflow.d.ts +0 -3
  100. package/dist/soundart-sketches/isoflow.d.ts.map +0 -1
  101. package/dist/soundart-sketches/isoflow.js +0 -60
  102. package/dist/soundart-sketches/loomWeave.d.ts +0 -3
  103. package/dist/soundart-sketches/loomWeave.d.ts.map +0 -1
  104. package/dist/soundart-sketches/loomWeave.js +0 -59
  105. package/dist/soundart-sketches/noiseTerraces.d.ts +0 -3
  106. package/dist/soundart-sketches/noiseTerraces.d.ts.map +0 -1
  107. package/dist/soundart-sketches/noiseTerraces.js +0 -53
  108. package/dist/soundart-sketches/orb.d.ts +0 -3
  109. package/dist/soundart-sketches/orb.d.ts.map +0 -1
  110. package/dist/soundart-sketches/orb.js +0 -50
  111. package/dist/soundart-sketches/pixelGlyphs.d.ts +0 -3
  112. package/dist/soundart-sketches/pixelGlyphs.d.ts.map +0 -1
  113. package/dist/soundart-sketches/pixelGlyphs.js +0 -72
  114. package/dist/soundart-sketches/prismFlowFields.d.ts +0 -3
  115. package/dist/soundart-sketches/prismFlowFields.d.ts.map +0 -1
  116. package/dist/soundart-sketches/prismFlowFields.js +0 -51
  117. package/dist/soundart-sketches/radialBurst.d.ts +0 -3
  118. package/dist/soundart-sketches/radialBurst.d.ts.map +0 -1
  119. package/dist/soundart-sketches/radialBurst.js +0 -60
  120. package/dist/soundart-sketches/resonantSoundBodies.d.ts +0 -3
  121. package/dist/soundart-sketches/resonantSoundBodies.d.ts.map +0 -1
  122. package/dist/soundart-sketches/resonantSoundBodies.js +0 -89
  123. package/dist/soundart-sketches/rings.d.ts +0 -11
  124. package/dist/soundart-sketches/rings.d.ts.map +0 -1
  125. package/dist/soundart-sketches/rings.js +0 -89
  126. package/dist/soundart-sketches/squares.d.ts +0 -3
  127. package/dist/soundart-sketches/squares.d.ts.map +0 -1
  128. package/dist/soundart-sketches/squares.js +0 -52
  129. package/dist/soundart-sketches/waveStripes.d.ts +0 -3
  130. package/dist/soundart-sketches/waveStripes.d.ts.map +0 -1
  131. package/dist/soundart-sketches/waveStripes.js +0 -44
  132. package/dist/static-engine.d.ts +0 -20
  133. package/dist/static-engine.d.ts.map +0 -1
  134. package/dist/static-engine.js +0 -157
  135. package/dist/types.d.ts +0 -191
  136. package/dist/types.d.ts.map +0 -1
  137. package/dist/types.js +0 -32
package/dist/index.js DELETED
@@ -1,63 +0,0 @@
1
- /**
2
- * NexArt Code Mode Runtime SDK - App Integration Layer
3
- *
4
- * ╔══════════════════════════════════════════════════════════════════════════╗
5
- * ║ LOCAL SDK WRAPPER ║
6
- * ║ ║
7
- * ║ This file re-exports the core runtime from @nexart/codemode-sdk (npm) ║
8
- * ║ and adds app-specific integrations (SoundArt, Noise, etc.) ║
9
- * ║ ║
10
- * ║ For core Code Mode: import from '@nexart/codemode-sdk' ║
11
- * ║ For app integrations: import from 'sdk/codemode' ║
12
- * ╚══════════════════════════════════════════════════════════════════════════╝
13
- */
14
- // ═══════════════════════════════════════════════════════════════════════════
15
- // CORE RUNTIME - Re-exported from @nexart/codemode-sdk (npm package)
16
- // ═══════════════════════════════════════════════════════════════════════════
17
- export { executeCodeMode, validateCodeModeSource, DEFAULT_CONFIG, PROTOCOL_IDENTITY, } from '@nexart/codemode-sdk';
18
- // ═══════════════════════════════════════════════════════════════════════════
19
- // LOCAL P5 RUNTIME - Used by app integrations (SoundArt, Noise)
20
- // The npm package also exports createP5Runtime, but we keep local for
21
- // app-specific extensions that need tighter integration
22
- // ═══════════════════════════════════════════════════════════════════════════
23
- export { createP5Runtime, injectTimeVariables, injectProtocolVariables, createProtocolVAR } from './p5-runtime';
24
- // ═══════════════════════════════════════════════════════════════════════════
25
- // LEGACY ENGINE API (kept for backwards compatibility)
26
- // ═══════════════════════════════════════════════════════════════════════════
27
- export { createEngine } from './engine';
28
- export { DEFAULT_CONFIG as LOCAL_DEFAULT_CONFIG } from './types';
29
- // SoundArt → Code Mode integration
30
- export { renderSoundArtViaCodeMode, canRenderViaCodeMode, getCodeModeAvailableStyles, } from './soundart-engine';
31
- export { createSoundSnapshot, createEmptySoundSnapshot, freezeSoundSnapshot, } from '../../shared/soundSnapshot';
32
- export { injectSoundGlobals, createSoundGlobals, createEmptySoundGlobals, generateSoundPalette, inferGenreProfile, createSoundHelpers, } from './sound-bridge';
33
- export { getSoundArtSketch, getAvailableSoundArtSketches, isSoundArtSketchAvailable, } from './soundart-sketches';
34
- // Noise → Code Mode integration
35
- export { renderNoiseViaCodeMode, compileNoiseSystem, canRenderNoiseViaCodeMode, } from './noise-engine';
36
- export { createNoiseSnapshot, validateNoiseSnapshot, } from '../../shared/noiseSnapshot';
37
- export { createNoiseGlobals, injectNoiseGlobals, } from './noise-bridge';
38
- export { getNoiseSketch, getAvailableNoiseSketchNames, isValidNoiseSketch, } from './noise-sketches';
39
- // ═══════════════════════════════════════════════════════════════════════════
40
- // BUILDER MANIFEST (v1.6.0) — Passive Attribution
41
- //
42
- // The Builder Manifest is a declaration of intent, not a capability.
43
- // The SDK does not expose any API to read or inspect manifests.
44
- //
45
- // This is:
46
- // - Declarative (write-only)
47
- // - Optional (no errors if missing)
48
- // - Non-enforced (no validation)
49
- // - Non-rewarding (no incentives)
50
- //
51
- // There is NO SDK API to read manifests, NO validation, NO attribution
52
- // logic, and NO tracking. Execution behavior is identical with or without
53
- // a manifest registered.
54
- // ═══════════════════════════════════════════════════════════════════════════
55
- export { registerBuilderManifest } from './builder-manifest';
56
- // ═══════════════════════════════════════════════════════════════════════════
57
- // EXECUTION BOUNDARY (Internal — Not Exported)
58
- //
59
- // The execution sandbox blocks all external entropy sources at runtime.
60
- // See EXECUTION_BOUNDARY.md for details.
61
- // ═══════════════════════════════════════════════════════════════════════════
62
- // Note: FORBIDDEN_APIS and createSafeMath are NOT exported.
63
- // They are internal implementation details used by the engines.
@@ -1,22 +0,0 @@
1
- /**
2
- * NexArt Code Mode Runtime SDK - Loop Engine
3
- * Protocol: v1.2.0 (Phase 3) — HARD ENFORCEMENT
4
- *
5
- * Loop mode renderer: frame-authoritative, stateless execution.
6
- * - Executes setup() once
7
- * - Executes draw() once per frame
8
- * - Clears canvas before each frame (transparent)
9
- * - Resets blend mode to NORMAL before each frame
10
- * - Injects normalized time variables
11
- * - No canvas persistence between frames
12
- *
13
- * Determinism Guarantee:
14
- * Same code + same seed + same VARs = identical frame sequence
15
- *
16
- * Security:
17
- * All external entropy sources are blocked at runtime via execution sandbox.
18
- */
19
- import type { EngineConfig, RunOptions } from './types';
20
- export declare function cancelLoopMode(): void;
21
- export declare function runLoopMode(config: EngineConfig, options: RunOptions): Promise<void>;
22
- //# sourceMappingURL=loop-engine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loop-engine.d.ts","sourceRoot":"","sources":["../loop-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAA+B,MAAM,SAAS,CAAC;AAOrF,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED,wBAAsB,WAAW,CAC/B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,IAAI,CAAC,CA+Mf"}
@@ -1,229 +0,0 @@
1
- /**
2
- * NexArt Code Mode Runtime SDK - Loop Engine
3
- * Protocol: v1.2.0 (Phase 3) — HARD ENFORCEMENT
4
- *
5
- * Loop mode renderer: frame-authoritative, stateless execution.
6
- * - Executes setup() once
7
- * - Executes draw() once per frame
8
- * - Clears canvas before each frame (transparent)
9
- * - Resets blend mode to NORMAL before each frame
10
- * - Injects normalized time variables
11
- * - No canvas persistence between frames
12
- *
13
- * Determinism Guarantee:
14
- * Same code + same seed + same VARs = identical frame sequence
15
- *
16
- * Security:
17
- * All external entropy sources are blocked at runtime via execution sandbox.
18
- */
19
- import { DEFAULT_CONFIG } from './types';
20
- import { createP5Runtime, injectProtocolVariables } from './p5-runtime';
21
- import { FORBIDDEN_APIS, createSafeMath } from './execution-sandbox';
22
- let isCancelled = false;
23
- export function cancelLoopMode() {
24
- isCancelled = true;
25
- }
26
- export async function runLoopMode(config, options) {
27
- const { code, seed, vars, onPreview, onProgress, onComplete, onError } = options;
28
- const width = config.width ?? DEFAULT_CONFIG.width;
29
- const height = config.height ?? DEFAULT_CONFIG.height;
30
- const duration = Math.max(DEFAULT_CONFIG.minDuration, Math.min(DEFAULT_CONFIG.maxDuration, config.duration ?? DEFAULT_CONFIG.duration));
31
- const fps = config.fps ?? DEFAULT_CONFIG.fps;
32
- const totalFrames = Math.floor(duration * fps);
33
- isCancelled = false;
34
- try {
35
- onProgress?.({
36
- phase: 'setup',
37
- percent: 0,
38
- message: 'Initializing canvas...',
39
- });
40
- // Create canvas
41
- const canvas = document.createElement('canvas');
42
- canvas.width = width;
43
- canvas.height = height;
44
- // Create p5 runtime with optional seed for determinism
45
- const p = createP5Runtime(canvas, width, height, { seed });
46
- // Inject protocol variables (VAR[0..9])
47
- injectProtocolVariables(p, vars);
48
- // Validate code
49
- const hasDrawFunction = /function\s+draw\s*\(\s*\)/.test(code);
50
- if (!hasDrawFunction) {
51
- throw new Error('Loop Mode requires a draw() function.');
52
- }
53
- const forbiddenPatterns = [
54
- { pattern: /noLoop\s*\(\s*\)/, name: 'noLoop()' },
55
- { pattern: /setTimeout\s*\(/, name: 'setTimeout' },
56
- { pattern: /setInterval\s*\(/, name: 'setInterval' },
57
- { pattern: /requestAnimationFrame\s*\(/, name: 'requestAnimationFrame' },
58
- ];
59
- for (const { pattern, name } of forbiddenPatterns) {
60
- if (pattern.test(code)) {
61
- throw new Error(`Forbidden function in Loop Mode: ${name}`);
62
- }
63
- }
64
- onProgress?.({
65
- phase: 'setup',
66
- percent: 5,
67
- message: 'Parsing code...',
68
- });
69
- // Extract setup() and draw() functions
70
- const setupMatch = code.match(/function\s+setup\s*\(\s*\)\s*\{([\s\S]*?)\}(?=\s*function|\s*$)/);
71
- const drawMatch = code.match(/function\s+draw\s*\(\s*\)\s*\{([\s\S]*?)\}(?=\s*function|\s*$)/);
72
- const setupCode = setupMatch ? setupMatch[1].trim() : '';
73
- const drawCode = drawMatch ? drawMatch[1].trim() : '';
74
- if (!drawCode) {
75
- throw new Error('Loop Mode requires a draw() function with content.');
76
- }
77
- // Inject totalFrames into runtime
78
- p.totalFrames = totalFrames;
79
- // Create sandboxed execution context
80
- // All forbidden APIs are injected as parameters to override globals
81
- const safeMath = createSafeMath();
82
- const forbiddenKeys = Object.keys(FORBIDDEN_APIS);
83
- // Create wrapped functions with p5 context, time variables, VAR, totalFrames, and blocked globals
84
- const wrappedSetup = new Function('p', 'frameCount', 't', 'time', 'tGlobal', 'VAR', 'totalFrames', 'Math', ...forbiddenKeys, `with(p) { ${setupCode} }`);
85
- const wrappedDraw = new Function('p', 'frameCount', 't', 'time', 'tGlobal', 'VAR', 'totalFrames', 'Math', ...forbiddenKeys, `with(p) { ${drawCode} }`);
86
- // Get forbidden values array for execution
87
- const forbiddenValues = forbiddenKeys.map(k => FORBIDDEN_APIS[k]);
88
- onProgress?.({
89
- phase: 'setup',
90
- percent: 10,
91
- message: 'Executing setup()...',
92
- });
93
- // Execute setup() once with time = 0, VAR, totalFrames, and sandboxed context
94
- wrappedSetup(p, 0, 0, 0, 0, p.VAR, totalFrames, safeMath, ...forbiddenValues);
95
- // Capture frames
96
- const frames = [];
97
- onProgress?.({
98
- phase: 'rendering',
99
- frame: 0,
100
- totalFrames,
101
- percent: 10,
102
- message: `Rendering frames (0/${totalFrames})...`,
103
- });
104
- for (let frame = 0; frame < totalFrames; frame++) {
105
- if (isCancelled) {
106
- throw new Error('Rendering cancelled');
107
- }
108
- // Calculate normalized time variables
109
- // t = frame / totalFrames (range [0, 1))
110
- const t = frame / totalFrames;
111
- const time = t * duration;
112
- // Update p5 runtime frameCount
113
- p.frameCount = frame;
114
- // CRITICAL: Reset canvas state before each draw() call
115
- // This enforces stateless, frame-authoritative rendering
116
- // 1. Clear canvas (transparent)
117
- p.clear();
118
- // 2. Reset blend mode to NORMAL (Protocol v1.1 requirement)
119
- // Prevents blend mode state from persisting across frames
120
- p.blendMode('NORMAL');
121
- // Execute draw() with time variables, VAR, totalFrames, and sandboxed context
122
- wrappedDraw(p, frame, t, time, t, p.VAR, totalFrames, safeMath, ...forbiddenValues);
123
- // Capture frame as PNG blob
124
- const blob = await new Promise((resolve, reject) => {
125
- canvas.toBlob((b) => b ? resolve(b) : reject(new Error(`Failed to capture frame ${frame}`)), 'image/png');
126
- });
127
- frames.push(blob);
128
- // Provide preview on first frame
129
- if (frame === 0) {
130
- onPreview?.(canvas);
131
- }
132
- // Update progress
133
- const percent = 10 + Math.floor((frame / totalFrames) * 60);
134
- onProgress?.({
135
- phase: 'rendering',
136
- frame: frame + 1,
137
- totalFrames,
138
- percent,
139
- message: `Rendering frames (${frame + 1}/${totalFrames})...`,
140
- });
141
- // Yield to prevent blocking UI
142
- if (frame % 10 === 0) {
143
- await new Promise(resolve => setTimeout(resolve, 0));
144
- }
145
- }
146
- onProgress?.({
147
- phase: 'encoding',
148
- frame: totalFrames,
149
- totalFrames,
150
- percent: 70,
151
- message: 'Encoding video...',
152
- });
153
- // Encode to video (MP4)
154
- const videoBlob = await encodeFramesToMP4(frames, fps, width, height, (progress) => {
155
- const percent = 70 + Math.floor(progress * 30);
156
- onProgress?.({
157
- phase: 'encoding',
158
- frame: totalFrames,
159
- totalFrames,
160
- percent,
161
- message: `Encoding video (${Math.floor(progress * 100)}%)...`,
162
- });
163
- });
164
- onProgress?.({
165
- phase: 'complete',
166
- frame: totalFrames,
167
- totalFrames,
168
- percent: 100,
169
- message: 'Complete',
170
- });
171
- const result = {
172
- type: 'video',
173
- blob: videoBlob,
174
- frames: totalFrames,
175
- duration,
176
- };
177
- onComplete(result);
178
- }
179
- catch (error) {
180
- const err = error instanceof Error ? error : new Error(String(error));
181
- onError?.(err);
182
- }
183
- }
184
- /**
185
- * Encode frames to MP4 video
186
- * Uses server-side encoding endpoint for cross-browser reliability
187
- */
188
- async function encodeFramesToMP4(frames, fps, width, height, onProgress) {
189
- // Convert frames to base64 for server transport
190
- const frameDataUrls = [];
191
- for (let i = 0; i < frames.length; i++) {
192
- const reader = new FileReader();
193
- const dataUrl = await new Promise((resolve, reject) => {
194
- reader.onload = () => resolve(reader.result);
195
- reader.onerror = reject;
196
- reader.readAsDataURL(frames[i]);
197
- });
198
- frameDataUrls.push(dataUrl);
199
- onProgress?.(i / frames.length * 0.3);
200
- }
201
- // Send to server for encoding
202
- const response = await fetch('/api/encode-loop', {
203
- method: 'POST',
204
- headers: { 'Content-Type': 'application/json' },
205
- body: JSON.stringify({
206
- frames: frameDataUrls,
207
- fps,
208
- width,
209
- height,
210
- }),
211
- });
212
- if (!response.ok) {
213
- const errorText = await response.text();
214
- throw new Error(`Video encoding failed: ${errorText}`);
215
- }
216
- onProgress?.(0.8);
217
- const data = await response.json();
218
- if (!data.video) {
219
- throw new Error('No video data returned from encoder');
220
- }
221
- // Convert base64 to blob
222
- const binaryString = atob(data.video.split(',')[1] || data.video);
223
- const bytes = new Uint8Array(binaryString.length);
224
- for (let i = 0; i < binaryString.length; i++) {
225
- bytes[i] = binaryString.charCodeAt(i);
226
- }
227
- onProgress?.(1);
228
- return new Blob([bytes], { type: 'video/mp4' });
229
- }
@@ -1,44 +0,0 @@
1
- /**
2
- * Noise Bridge - Injects N.* globals into Code Mode runtime
3
- *
4
- * This is the bridge between NoiseSnapshot data and the Code Mode p5-runtime.
5
- * It creates frozen N.* globals that noise sketches can access deterministically.
6
- *
7
- * Similar to sound-bridge.ts for SoundArt, but for Noise parameters.
8
- */
9
- import type { NoiseSnapshot, NoiseBlendMode } from '../../shared/noiseSnapshot';
10
- /**
11
- * The N.* global object type for noise sketches
12
- */
13
- export interface NoiseGlobals {
14
- scale: number;
15
- octaves: number;
16
- persistence: number;
17
- lacunarity: number;
18
- cellDensity: number;
19
- cellDistortion: number;
20
- blendMode: NoiseBlendMode;
21
- isPerlinOnly: boolean;
22
- isBlend: boolean;
23
- isWarp: boolean;
24
- isInterleave: boolean;
25
- bgR: number;
26
- bgG: number;
27
- bgB: number;
28
- noiseR: number;
29
- noiseG: number;
30
- noiseB: number;
31
- seed: number;
32
- zoom: number;
33
- }
34
- /**
35
- * Create N.* globals from a NoiseSnapshot
36
- */
37
- export declare function createNoiseGlobals(snapshot: NoiseSnapshot): NoiseGlobals;
38
- /**
39
- * Inject N.* globals into code string
40
- *
41
- * This wraps the sketch code with N.* variable declarations
42
- */
43
- export declare function injectNoiseGlobals(sketchCode: string, globals: NoiseGlobals): string;
44
- //# sourceMappingURL=noise-bridge.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"noise-bridge.d.ts","sourceRoot":"","sources":["../noise-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,YAAY;IAE3B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IAGnB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IAGvB,SAAS,EAAE,cAAc,CAAC;IAC1B,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IAGtB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IAGf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,GAAG,YAAY,CAsBxE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,CA6BpF"}
@@ -1,68 +0,0 @@
1
- /**
2
- * Noise Bridge - Injects N.* globals into Code Mode runtime
3
- *
4
- * This is the bridge between NoiseSnapshot data and the Code Mode p5-runtime.
5
- * It creates frozen N.* globals that noise sketches can access deterministically.
6
- *
7
- * Similar to sound-bridge.ts for SoundArt, but for Noise parameters.
8
- */
9
- /**
10
- * Create N.* globals from a NoiseSnapshot
11
- */
12
- export function createNoiseGlobals(snapshot) {
13
- return Object.freeze({
14
- scale: snapshot.scale,
15
- octaves: snapshot.octaves,
16
- persistence: snapshot.persistence,
17
- lacunarity: snapshot.lacunarity,
18
- cellDensity: snapshot.cellDensity,
19
- cellDistortion: snapshot.cellDistortion,
20
- blendMode: snapshot.blendMode,
21
- isPerlinOnly: snapshot.blendMode === 'perlin_only',
22
- isBlend: snapshot.blendMode === 'blend',
23
- isWarp: snapshot.blendMode === 'warp',
24
- isInterleave: snapshot.blendMode === 'interleave',
25
- bgR: snapshot.bgR,
26
- bgG: snapshot.bgG,
27
- bgB: snapshot.bgB,
28
- noiseR: snapshot.noiseR,
29
- noiseG: snapshot.noiseG,
30
- noiseB: snapshot.noiseB,
31
- seed: snapshot.seed,
32
- zoom: snapshot.zoomLevel,
33
- });
34
- }
35
- /**
36
- * Inject N.* globals into code string
37
- *
38
- * This wraps the sketch code with N.* variable declarations
39
- */
40
- export function injectNoiseGlobals(sketchCode, globals) {
41
- const injection = `
42
- // === Injected Noise Globals (N.*) ===
43
- const N = Object.freeze({
44
- scale: ${globals.scale},
45
- octaves: ${globals.octaves},
46
- persistence: ${globals.persistence},
47
- lacunarity: ${globals.lacunarity},
48
- cellDensity: ${globals.cellDensity},
49
- cellDistortion: ${globals.cellDistortion},
50
- blendMode: '${globals.blendMode}',
51
- isPerlinOnly: ${globals.isPerlinOnly},
52
- isBlend: ${globals.isBlend},
53
- isWarp: ${globals.isWarp},
54
- isInterleave: ${globals.isInterleave},
55
- bgR: ${globals.bgR},
56
- bgG: ${globals.bgG},
57
- bgB: ${globals.bgB},
58
- noiseR: ${globals.noiseR},
59
- noiseG: ${globals.noiseG},
60
- noiseB: ${globals.noiseB},
61
- seed: ${globals.seed},
62
- zoom: ${globals.zoom}
63
- });
64
- // === End Injected Globals ===
65
-
66
- `;
67
- return injection + sketchCode;
68
- }
@@ -1,74 +0,0 @@
1
- /**
2
- * Noise → Code Mode Engine
3
- *
4
- * This is the orchestrator that runs Noise rendering through the Code Mode engine.
5
- * It replaces the legacy p5.js-based NoiseCanvas with a protocol-compliant pipeline.
6
- *
7
- * Architecture:
8
- * 1. NoiseParams from UI state
9
- * 2. NoiseParams → NoiseSnapshot conversion
10
- * 3. NoiseSnapshot injected as N.* globals into Code Mode
11
- * 4. Noise sketch executed via Code Mode runtime
12
- * 5. Result: PNG output (deterministic)
13
- */
14
- import type { NoiseSnapshot, NoiseParams } from '../../shared/noiseSnapshot';
15
- export interface NoiseEngineConfig {
16
- width: number;
17
- height: number;
18
- seed: number;
19
- }
20
- export interface NoiseRenderOptions {
21
- params: NoiseParams;
22
- canvas: HTMLCanvasElement;
23
- config: NoiseEngineConfig;
24
- onProgress?: (progress: number) => void;
25
- }
26
- export interface NoiseRenderResult {
27
- mode: 'noise';
28
- snapshot: NoiseSnapshot;
29
- metadata: NoiseMetadata;
30
- }
31
- export interface NoiseMetadata {
32
- mode: 'Noise';
33
- timestamp: string;
34
- enforcement: 'hard';
35
- renderedVia: 'codemode';
36
- noiseParams: {
37
- scale: number;
38
- octaves: number;
39
- persistence: number;
40
- lacunarity: number;
41
- cellDensity: number;
42
- cellDistortion: number;
43
- blendMode: string;
44
- };
45
- generationParams: {
46
- seed: number;
47
- canvasSize: {
48
- width: number;
49
- height: number;
50
- };
51
- };
52
- }
53
- /**
54
- * Render noise via Code Mode runtime
55
- *
56
- * This is the main entry point for protocol-compliant noise rendering.
57
- * All rendering goes through the Code Mode runtime for determinism.
58
- */
59
- export declare function renderNoiseViaCodeMode(options: NoiseRenderOptions): Promise<NoiseRenderResult>;
60
- /**
61
- * Compile noise params to a Code Mode system
62
- * This produces a reproducible system definition
63
- */
64
- export declare function compileNoiseSystem(params: NoiseParams): {
65
- sketchCode: string;
66
- snapshot: NoiseSnapshot;
67
- seed: number;
68
- };
69
- /**
70
- * Check if noise can be rendered via Code Mode
71
- * (Always true - no legacy fallback)
72
- */
73
- export declare function canRenderNoiseViaCodeMode(): boolean;
74
- //# sourceMappingURL=noise-engine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"noise-engine.d.ts","sourceRoot":"","sources":["../noise-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAM7E,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,WAAW,CAAC;IACpB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,aAAa,CAAC;IACxB,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,UAAU,CAAC;IACxB,WAAW,EAAE;QACX,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,cAAc,EAAE,MAAM,CAAC;QACvB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,gBAAgB,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC;KAC/C,CAAC;CACH;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAsF5B;AAwBD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,aAAa,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;CACd,CAUA;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,OAAO,CAEnD"}
@@ -1,132 +0,0 @@
1
- /**
2
- * Noise → Code Mode Engine
3
- *
4
- * This is the orchestrator that runs Noise rendering through the Code Mode engine.
5
- * It replaces the legacy p5.js-based NoiseCanvas with a protocol-compliant pipeline.
6
- *
7
- * Architecture:
8
- * 1. NoiseParams from UI state
9
- * 2. NoiseParams → NoiseSnapshot conversion
10
- * 3. NoiseSnapshot injected as N.* globals into Code Mode
11
- * 4. Noise sketch executed via Code Mode runtime
12
- * 5. Result: PNG output (deterministic)
13
- */
14
- import { createNoiseSnapshot, validateNoiseSnapshot } from '../../shared/noiseSnapshot';
15
- import { createP5Runtime } from './p5-runtime';
16
- import { createNoiseGlobals, injectNoiseGlobals } from './noise-bridge';
17
- import { getNoiseSketch } from './noise-sketches';
18
- /**
19
- * Render noise via Code Mode runtime
20
- *
21
- * This is the main entry point for protocol-compliant noise rendering.
22
- * All rendering goes through the Code Mode runtime for determinism.
23
- */
24
- export async function renderNoiseViaCodeMode(options) {
25
- const { params, canvas, config, onProgress } = options;
26
- // Protocol enforcement logging
27
- console.log('[Noise] Protocol enforcement: HARD | renderedVia: codemode');
28
- onProgress?.(0.1);
29
- // Create and validate snapshot
30
- const rawSnapshot = createNoiseSnapshot(params);
31
- const snapshot = validateNoiseSnapshot(rawSnapshot);
32
- onProgress?.(0.2);
33
- // Create N.* globals
34
- const noiseGlobals = createNoiseGlobals(snapshot);
35
- // Get the noise sketch
36
- const sketchName = 'fractalNoise';
37
- const sketchCode = getNoiseSketch(sketchName);
38
- // Inject N.* globals into sketch
39
- const injectedCode = injectNoiseGlobals(sketchCode, noiseGlobals);
40
- onProgress?.(0.3);
41
- // Set canvas dimensions
42
- canvas.width = config.width;
43
- canvas.height = config.height;
44
- // Create P5 runtime with correct signature
45
- const runtimeConfig = {
46
- seed: config.seed,
47
- };
48
- const runtime = createP5Runtime(canvas, config.width, config.height, runtimeConfig);
49
- onProgress?.(0.5);
50
- // Build globals with all runtime functions and noise globals
51
- const globals = {
52
- ...runtime,
53
- width: config.width,
54
- height: config.height,
55
- };
56
- // Execute the sketch
57
- try {
58
- executeNoiseSketch(injectedCode, globals);
59
- onProgress?.(0.9);
60
- console.log('[Noise] Rendered via Code Mode runtime');
61
- // Build metadata
62
- const metadata = {
63
- mode: 'Noise',
64
- timestamp: new Date().toISOString(),
65
- enforcement: 'hard',
66
- renderedVia: 'codemode',
67
- noiseParams: {
68
- scale: snapshot.scale,
69
- octaves: snapshot.octaves,
70
- persistence: snapshot.persistence,
71
- lacunarity: snapshot.lacunarity,
72
- cellDensity: snapshot.cellDensity,
73
- cellDistortion: snapshot.cellDistortion,
74
- blendMode: snapshot.blendMode,
75
- },
76
- generationParams: {
77
- seed: config.seed,
78
- canvasSize: { width: config.width, height: config.height },
79
- },
80
- };
81
- onProgress?.(1.0);
82
- return {
83
- mode: 'noise',
84
- snapshot,
85
- metadata,
86
- };
87
- }
88
- catch (error) {
89
- console.error('[Noise] Code Mode execution failed:', error);
90
- throw error;
91
- }
92
- }
93
- /**
94
- * Execute a noise sketch string in the context of the runtime globals
95
- */
96
- function executeNoiseSketch(code, globals) {
97
- const globalNames = Object.keys(globals);
98
- const globalValues = Object.values(globals);
99
- // Wrap the sketch code to call setup()
100
- const wrappedCode = `
101
- ${code}
102
-
103
- // Execute setup (noise is static - single frame)
104
- if (typeof setup === 'function') {
105
- setup();
106
- }
107
- `;
108
- // Create and execute the function
109
- const sketchFunction = new Function(...globalNames, wrappedCode);
110
- sketchFunction(...globalValues);
111
- }
112
- /**
113
- * Compile noise params to a Code Mode system
114
- * This produces a reproducible system definition
115
- */
116
- export function compileNoiseSystem(params) {
117
- const snapshot = validateNoiseSnapshot(createNoiseSnapshot(params));
118
- const noiseGlobals = createNoiseGlobals(snapshot);
119
- const sketchCode = injectNoiseGlobals(getNoiseSketch('fractalNoise'), noiseGlobals);
120
- return {
121
- sketchCode,
122
- snapshot,
123
- seed: params.seed,
124
- };
125
- }
126
- /**
127
- * Check if noise can be rendered via Code Mode
128
- * (Always true - no legacy fallback)
129
- */
130
- export function canRenderNoiseViaCodeMode() {
131
- return true;
132
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Fractal Noise - Code Mode Sketch
3
- *
4
- * This sketch implements Perlin FBM and Cellular noise rendering
5
- * through the Code Mode p5-runtime. Uses N.* globals for all parameters.
6
- *
7
- * Original: client/src/components/noise-canvas-simple.tsx
8
- */
9
- export declare const FRACTAL_NOISE_SKETCH = "\n// Fractal Noise - Code Mode Sketch\n// Uses N.* noise globals and standard p5-like functions\n\nfunction setup() {\n // Set seeded random for reproducibility\n randomSeed(N.seed);\n noiseSeed(N.seed);\n \n // Set background color\n background(N.bgR, N.bgG, N.bgB);\n \n // Noise rendering parameters\n const adjustedScale = N.scale * (1 / N.zoom) * 0.05;\n const cellSize = 4; // Fixed for quality\n \n // Generate cellular points if needed\n const numPoints = Math.floor(20 + N.cellDensity * 180);\n const cellPoints = [];\n for (let i = 0; i < numPoints; i++) {\n cellPoints.push([random(0, width), random(0, height)]);\n }\n \n // Helper: Perlin FBM (Fractional Brownian Motion)\n function perlinFBM(x, y, scale) {\n let value = 0;\n let amplitude = 1;\n let frequency = 1;\n let maxValue = 0;\n \n const oct = Math.min(N.octaves, 6); // Cap for performance\n \n for (let i = 0; i < oct; i++) {\n value += noise(x * scale * frequency, y * scale * frequency) * amplitude;\n maxValue += amplitude;\n amplitude *= N.persistence;\n frequency *= N.lacunarity;\n }\n \n return value / maxValue;\n }\n \n // Helper: Cellular noise (Worley)\n function cellularNoise(x, y, points) {\n let sampleX = x;\n let sampleY = y;\n \n // Warp distortion if using warp mode\n if (N.isWarp && N.cellDistortion > 0) {\n const distortionAmount = N.cellDistortion * 100;\n sampleX += noise(x * 0.01, y * 0.01) * distortionAmount;\n sampleY += noise(y * 0.01, x * 0.01) * distortionAmount;\n }\n \n // Find distances to closest points\n let minDist = 999999;\n let secondMinDist = 999999;\n \n for (let i = 0; i < points.length; i++) {\n const px = points[i][0];\n const py = points[i][1];\n const dx = sampleX - px;\n const dy = sampleY - py;\n const dist = Math.sqrt(dx * dx + dy * dy);\n \n if (dist < minDist) {\n secondMinDist = minDist;\n minDist = dist;\n } else if (dist < secondMinDist) {\n secondMinDist = dist;\n }\n }\n \n // Normalize distance\n return Math.min(1.0, (secondMinDist - minDist) / 50);\n }\n \n // Render the noise grid\n noStroke();\n \n for (let y = 0; y < height; y += cellSize) {\n for (let x = 0; x < width; x += cellSize) {\n // Calculate Perlin value\n const perlinValue = perlinFBM(x, y, adjustedScale);\n \n // Calculate final value based on blend mode\n let finalValue = perlinValue;\n \n if (!N.isPerlinOnly) {\n const cellValue = cellularNoise(x, y, cellPoints);\n \n if (N.isBlend) {\n finalValue = perlinValue * cellValue;\n } else if (N.isWarp) {\n finalValue = (perlinValue + cellValue) / 2;\n } else if (N.isInterleave) {\n finalValue = (Math.floor(x / 20) + Math.floor(y / 20)) % 2 === 0\n ? perlinValue\n : cellValue;\n }\n }\n \n // Set opacity based on noise value\n const alpha = map(finalValue, 0, 1, 0, 255);\n \n // Fill with noise color and calculated alpha\n fill(N.noiseR, N.noiseG, N.noiseB, alpha);\n rect(x, y, cellSize, cellSize);\n }\n }\n}\n";
10
- export default FRACTAL_NOISE_SKETCH;
11
- //# sourceMappingURL=fractalNoise.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fractalNoise.d.ts","sourceRoot":"","sources":["../../noise-sketches/fractalNoise.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,oBAAoB,4sGA+GhC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}