@nexart/codemode-sdk 1.5.0 → 1.5.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +289 -0
  2. package/CODE_MODE_PROTOCOL.md +471 -0
  3. package/README.md +232 -55
  4. package/dist/builder-manifest.d.ts +79 -0
  5. package/dist/builder-manifest.d.ts.map +1 -0
  6. package/dist/builder-manifest.js +97 -0
  7. package/dist/core-index.d.ts +21 -0
  8. package/dist/core-index.d.ts.map +1 -0
  9. package/dist/core-index.js +26 -0
  10. package/dist/engine.d.ts +17 -39
  11. package/dist/engine.d.ts.map +1 -1
  12. package/dist/engine.js +52 -253
  13. package/dist/execute.d.ts +46 -0
  14. package/dist/execute.d.ts.map +1 -0
  15. package/dist/execute.js +282 -0
  16. package/dist/index.d.ts +24 -17
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +30 -16
  19. package/dist/noise-bridge.d.ts +44 -0
  20. package/dist/noise-bridge.d.ts.map +1 -0
  21. package/dist/noise-bridge.js +68 -0
  22. package/dist/noise-engine.d.ts +74 -0
  23. package/dist/noise-engine.d.ts.map +1 -0
  24. package/dist/noise-engine.js +132 -0
  25. package/dist/noise-sketches/fractalNoise.d.ts +11 -0
  26. package/dist/noise-sketches/fractalNoise.d.ts.map +1 -0
  27. package/dist/noise-sketches/fractalNoise.js +121 -0
  28. package/dist/noise-sketches/index.d.ts +21 -0
  29. package/dist/noise-sketches/index.d.ts.map +1 -0
  30. package/dist/noise-sketches/index.js +28 -0
  31. package/dist/sound-bridge.d.ts +89 -0
  32. package/dist/sound-bridge.d.ts.map +1 -0
  33. package/dist/sound-bridge.js +128 -0
  34. package/dist/soundart-engine.d.ts +87 -0
  35. package/dist/soundart-engine.d.ts.map +1 -0
  36. package/dist/soundart-engine.js +173 -0
  37. package/dist/soundart-sketches/chladniBloom.d.ts +3 -0
  38. package/dist/soundart-sketches/chladniBloom.d.ts.map +1 -0
  39. package/dist/soundart-sketches/chladniBloom.js +53 -0
  40. package/dist/soundart-sketches/dualVortex.d.ts +3 -0
  41. package/dist/soundart-sketches/dualVortex.d.ts.map +1 -0
  42. package/dist/soundart-sketches/dualVortex.js +67 -0
  43. package/dist/soundart-sketches/geometryIllusion.d.ts +3 -0
  44. package/dist/soundart-sketches/geometryIllusion.d.ts.map +1 -0
  45. package/dist/soundart-sketches/geometryIllusion.js +89 -0
  46. package/dist/soundart-sketches/index.d.ts +39 -0
  47. package/dist/soundart-sketches/index.d.ts.map +1 -0
  48. package/dist/soundart-sketches/index.js +72 -0
  49. package/dist/soundart-sketches/isoflow.d.ts +3 -0
  50. package/dist/soundart-sketches/isoflow.d.ts.map +1 -0
  51. package/dist/soundart-sketches/isoflow.js +60 -0
  52. package/dist/soundart-sketches/loomWeave.d.ts +3 -0
  53. package/dist/soundart-sketches/loomWeave.d.ts.map +1 -0
  54. package/dist/soundart-sketches/loomWeave.js +59 -0
  55. package/dist/soundart-sketches/noiseTerraces.d.ts +3 -0
  56. package/dist/soundart-sketches/noiseTerraces.d.ts.map +1 -0
  57. package/dist/soundart-sketches/noiseTerraces.js +53 -0
  58. package/dist/soundart-sketches/orb.d.ts +3 -0
  59. package/dist/soundart-sketches/orb.d.ts.map +1 -0
  60. package/dist/soundart-sketches/orb.js +50 -0
  61. package/dist/soundart-sketches/pixelGlyphs.d.ts +3 -0
  62. package/dist/soundart-sketches/pixelGlyphs.d.ts.map +1 -0
  63. package/dist/soundart-sketches/pixelGlyphs.js +72 -0
  64. package/dist/soundart-sketches/prismFlowFields.d.ts +3 -0
  65. package/dist/soundart-sketches/prismFlowFields.d.ts.map +1 -0
  66. package/dist/soundart-sketches/prismFlowFields.js +51 -0
  67. package/dist/soundart-sketches/radialBurst.d.ts +3 -0
  68. package/dist/soundart-sketches/radialBurst.d.ts.map +1 -0
  69. package/dist/soundart-sketches/radialBurst.js +60 -0
  70. package/dist/soundart-sketches/resonantSoundBodies.d.ts +3 -0
  71. package/dist/soundart-sketches/resonantSoundBodies.d.ts.map +1 -0
  72. package/dist/soundart-sketches/resonantSoundBodies.js +89 -0
  73. package/dist/soundart-sketches/rings.d.ts +11 -0
  74. package/dist/soundart-sketches/rings.d.ts.map +1 -0
  75. package/dist/soundart-sketches/rings.js +89 -0
  76. package/dist/soundart-sketches/squares.d.ts +3 -0
  77. package/dist/soundart-sketches/squares.d.ts.map +1 -0
  78. package/dist/soundart-sketches/squares.js +52 -0
  79. package/dist/soundart-sketches/waveStripes.d.ts +3 -0
  80. package/dist/soundart-sketches/waveStripes.d.ts.map +1 -0
  81. package/dist/soundart-sketches/waveStripes.js +44 -0
  82. package/dist/types.d.ts +41 -1
  83. package/dist/types.d.ts.map +1 -1
  84. package/dist/types.js +1 -1
  85. package/package.json +24 -15
@@ -0,0 +1,282 @@
1
+ /**
2
+ * NexArt Code Mode Runtime SDK - Canonical Execution Entry Point
3
+ *
4
+ * ╔══════════════════════════════════════════════════════════════════════════╗
5
+ * ║ CODE MODE PROTOCOL v1.2.0 (Phase 3) — 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 { runStaticMode } from './static-engine';
14
+ import { runLoopMode } from './loop-engine';
15
+ import { PROTOCOL_IDENTITY, DEFAULT_CONFIG, } from './types';
16
+ import { getBuilderManifest } from './builder-manifest';
17
+ /**
18
+ * Validate and normalize VAR array to 10 elements.
19
+ *
20
+ * Rules (SDK v1.0.2, Protocol v1.0.0):
21
+ * - VAR is OPTIONAL: omit or pass [] for empty (defaults to all zeros)
22
+ * - VAR input length MUST be 0-10 elements (protocol error if > 10)
23
+ * - VAR values MUST be finite numbers (protocol error if not)
24
+ * - VAR values MUST be in range 0-100 (protocol error if out of range, NO clamping)
25
+ * - VAR is read-only inside sketches
26
+ * - Output is ALWAYS 10 elements (padded with zeros) for protocol consistency
27
+ */
28
+ function normalizeVars(vars) {
29
+ if (!vars || !Array.isArray(vars)) {
30
+ console.log('[CodeMode] No vars provided, using defaults [0,0,0,0,0,0,0,0,0,0]');
31
+ return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
32
+ }
33
+ if (vars.length > 10) {
34
+ throw new Error(`[Code Mode Protocol Error] VAR array must have at most 10 elements, got ${vars.length}`);
35
+ }
36
+ const result = [];
37
+ for (let i = 0; i < vars.length; i++) {
38
+ const v = vars[i];
39
+ if (typeof v !== 'number' || !Number.isFinite(v)) {
40
+ throw new Error(`[Code Mode Protocol Error] VAR[${i}] must be a finite number, got ${typeof v === 'number' ? v : typeof v}`);
41
+ }
42
+ if (v < 0 || v > 100) {
43
+ throw new Error(`[Code Mode Protocol Error] VAR[${i}] = ${v} is out of range. Values must be 0-100.`);
44
+ }
45
+ result.push(v);
46
+ }
47
+ // Pad with zeros to always have 10 elements for protocol consistency
48
+ while (result.length < 10) {
49
+ result.push(0);
50
+ }
51
+ return result;
52
+ }
53
+ /**
54
+ * Validate execution input
55
+ */
56
+ function validateInput(input) {
57
+ if (!input.source || typeof input.source !== 'string') {
58
+ throw new Error('[Code Mode Protocol Error] source is required and must be a string');
59
+ }
60
+ if (typeof input.width !== 'number' || input.width <= 0) {
61
+ throw new Error('[Code Mode Protocol Error] width must be a positive number');
62
+ }
63
+ if (typeof input.height !== 'number' || input.height <= 0) {
64
+ throw new Error('[Code Mode Protocol Error] height must be a positive number');
65
+ }
66
+ if (typeof input.seed !== 'number') {
67
+ throw new Error('[Code Mode Protocol Error] seed is required and must be a number');
68
+ }
69
+ if (input.mode !== 'static' && input.mode !== 'loop') {
70
+ throw new Error('[Code Mode Protocol Error] mode must be "static" or "loop"');
71
+ }
72
+ if (input.mode === 'loop') {
73
+ if (typeof input.totalFrames !== 'number' || input.totalFrames <= 0) {
74
+ throw new Error('[Code Mode Protocol Error] totalFrames is required for loop mode and must be a positive number');
75
+ }
76
+ }
77
+ // Validate forbidden patterns per CODE_MODE_PROTOCOL.md
78
+ const forbiddenPatterns = [
79
+ // Async timing (breaks determinism)
80
+ { pattern: /setTimeout\s*\(/, name: 'setTimeout' },
81
+ { pattern: /setInterval\s*\(/, name: 'setInterval' },
82
+ { pattern: /requestAnimationFrame\s*\(/, name: 'requestAnimationFrame' },
83
+ // Time-based entropy (breaks determinism)
84
+ { pattern: /Date\.now\s*\(/, name: 'Date.now() — use time variable instead' },
85
+ { pattern: /new\s+Date\s*\(/, name: 'new Date() — use time variable instead' },
86
+ // Unseeded random (use random() instead)
87
+ { pattern: /Math\.random\s*\(/, name: 'Math.random() — use random() instead (seeded)' },
88
+ // External IO (breaks determinism)
89
+ { pattern: /fetch\s*\(/, name: 'fetch() — external IO forbidden' },
90
+ { pattern: /XMLHttpRequest/, name: 'XMLHttpRequest — external IO forbidden' },
91
+ // Canvas is pre-initialized
92
+ { pattern: /createCanvas\s*\(/, name: 'createCanvas() — canvas is pre-initialized' },
93
+ // DOM manipulation forbidden
94
+ { pattern: /document\./, name: 'DOM access — document.* forbidden' },
95
+ { pattern: /window\./, name: 'DOM access — window.* forbidden' },
96
+ // External imports forbidden
97
+ { pattern: /\bimport\s+/, name: 'import — external imports forbidden' },
98
+ { pattern: /\brequire\s*\(/, name: 'require() — external imports forbidden' },
99
+ ];
100
+ for (const { pattern, name } of forbiddenPatterns) {
101
+ if (pattern.test(input.source)) {
102
+ throw new Error(`[Code Mode Protocol Error] Forbidden pattern: ${name}`);
103
+ }
104
+ }
105
+ // Loop mode specific validation
106
+ if (input.mode === 'loop') {
107
+ if (!/function\s+draw\s*\(\s*\)/.test(input.source)) {
108
+ throw new Error('[Code Mode Protocol Error] Loop mode requires a draw() function');
109
+ }
110
+ if (/noLoop\s*\(\s*\)/.test(input.source)) {
111
+ throw new Error('[Code Mode Protocol Error] noLoop() is forbidden in Loop mode');
112
+ }
113
+ }
114
+ }
115
+ /**
116
+ * Create protocol metadata for the execution result
117
+ */
118
+ function createMetadata(input, vars) {
119
+ return {
120
+ ...PROTOCOL_IDENTITY,
121
+ seed: input.seed,
122
+ vars,
123
+ width: input.width,
124
+ height: input.height,
125
+ mode: input.mode,
126
+ ...(input.mode === 'loop' && input.totalFrames ? { totalFrames: input.totalFrames } : {}),
127
+ };
128
+ }
129
+ /**
130
+ * Execute Code Mode in Static mode - delegates to static-engine.ts
131
+ */
132
+ async function executeStatic(input, vars) {
133
+ console.log('[CodeMode] Rendered via @nexart/codemode-sdk (Protocol v1.2.0)');
134
+ console.log('[CodeMode] Execution: Static mode — delegating to static-engine');
135
+ return new Promise((resolve, reject) => {
136
+ runStaticMode({
137
+ mode: 'static',
138
+ width: input.width,
139
+ height: input.height,
140
+ }, {
141
+ code: input.source,
142
+ seed: input.seed,
143
+ vars: vars,
144
+ onComplete: (result) => {
145
+ resolve({
146
+ image: result.blob,
147
+ metadata: createMetadata(input, vars),
148
+ });
149
+ },
150
+ onError: (error) => {
151
+ reject(error);
152
+ },
153
+ });
154
+ });
155
+ }
156
+ /**
157
+ * Execute Code Mode in Loop mode - delegates to loop-engine.ts
158
+ */
159
+ async function executeLoop(input, vars) {
160
+ console.log('[CodeMode] Rendered via @nexart/codemode-sdk (Protocol v1.2.0)');
161
+ console.log(`[CodeMode] Execution: Loop mode — delegating to loop-engine (${input.totalFrames} frames)`);
162
+ const fps = DEFAULT_CONFIG.fps;
163
+ const duration = (input.totalFrames || 60) / fps;
164
+ return new Promise((resolve, reject) => {
165
+ runLoopMode({
166
+ mode: 'loop',
167
+ width: input.width,
168
+ height: input.height,
169
+ duration: duration,
170
+ fps: fps,
171
+ }, {
172
+ code: input.source,
173
+ seed: input.seed,
174
+ vars: vars,
175
+ onComplete: (result) => {
176
+ resolve({
177
+ video: result.blob,
178
+ metadata: createMetadata(input, vars),
179
+ });
180
+ },
181
+ onError: (error) => {
182
+ reject(error);
183
+ },
184
+ });
185
+ });
186
+ }
187
+ /**
188
+ * executeCodeMode — Canonical Code Mode Execution Entry Point
189
+ *
190
+ * This is the ONLY official way to execute Code Mode.
191
+ * All implementations MUST use this function.
192
+ *
193
+ * @param input - Execution parameters
194
+ * @returns Promise<ExecuteCodeModeResult> - Execution result with protocol metadata
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * const result = await executeCodeMode({
199
+ * source: `function setup() { background(255); ellipse(width/2, height/2, 100); }`,
200
+ * width: 1950,
201
+ * height: 2400,
202
+ * seed: 12345,
203
+ * vars: [50, 75, 0, 0, 0, 0, 0, 0, 0, 0],
204
+ * mode: 'static'
205
+ * });
206
+ *
207
+ * console.log(result.metadata.protocolVersion); // '1.2.0'
208
+ * console.log(result.image); // PNG Blob
209
+ * ```
210
+ */
211
+ export async function executeCodeMode(input) {
212
+ // Validate input
213
+ validateInput(input);
214
+ // Normalize VAR values
215
+ const vars = normalizeVars(input.vars);
216
+ // ╔═══════════════════════════════════════════════════════════════════════╗
217
+ // ║ BUILDER MANIFEST CONTEXT (v1.5.1) ║
218
+ // ║ ║
219
+ // ║ Internal context for builder attribution. ║
220
+ // ║ This is NOT exposed to sketch code, NOT serialized, NOT logged. ║
221
+ // ║ Does NOT affect execution behavior or determinism. ║
222
+ // ╚═══════════════════════════════════════════════════════════════════════╝
223
+ const _executionContext = {
224
+ builderManifest: getBuilderManifest(),
225
+ };
226
+ // Note: _executionContext is intentionally unused.
227
+ // It prepares the SDK for future attribution without activating anything.
228
+ void _executionContext;
229
+ // Log protocol execution
230
+ console.log('[CodeMode] ════════════════════════════════════════════════');
231
+ console.log('[CodeMode] Protocol v1.2.0 — Phase 3 — HARD Enforcement');
232
+ console.log(`[CodeMode] Mode: ${input.mode}`);
233
+ console.log(`[CodeMode] Seed: ${input.seed}`);
234
+ console.log(`[CodeMode] VAR: [${vars.join(', ')}]`);
235
+ console.log('[CodeMode] ════════════════════════════════════════════════');
236
+ // Execute based on mode
237
+ if (input.mode === 'static') {
238
+ return executeStatic(input, vars);
239
+ }
240
+ else {
241
+ return executeLoop(input, vars);
242
+ }
243
+ }
244
+ /**
245
+ * Validate code without executing
246
+ */
247
+ export function validateCodeModeSource(source, mode) {
248
+ const errors = [];
249
+ // Same forbidden patterns as validateInput per CODE_MODE_PROTOCOL.md
250
+ const forbiddenPatterns = [
251
+ { pattern: /setTimeout\s*\(/, name: 'setTimeout' },
252
+ { pattern: /setInterval\s*\(/, name: 'setInterval' },
253
+ { pattern: /requestAnimationFrame\s*\(/, name: 'requestAnimationFrame' },
254
+ { pattern: /Date\.now\s*\(/, name: 'Date.now() — use time variable instead' },
255
+ { pattern: /new\s+Date\s*\(/, name: 'new Date() — use time variable instead' },
256
+ { pattern: /Math\.random\s*\(/, name: 'Math.random() — use random() instead (seeded)' },
257
+ { pattern: /fetch\s*\(/, name: 'fetch() — external IO forbidden' },
258
+ { pattern: /XMLHttpRequest/, name: 'XMLHttpRequest — external IO forbidden' },
259
+ { pattern: /createCanvas\s*\(/, name: 'createCanvas() — canvas is pre-initialized' },
260
+ { pattern: /document\./, name: 'DOM access — document.* forbidden' },
261
+ { pattern: /window\./, name: 'DOM access — window.* forbidden' },
262
+ { pattern: /\bimport\s+/, name: 'import — external imports forbidden' },
263
+ { pattern: /\brequire\s*\(/, name: 'require() — external imports forbidden' },
264
+ ];
265
+ for (const { pattern, name } of forbiddenPatterns) {
266
+ if (pattern.test(source)) {
267
+ errors.push(`Forbidden pattern: ${name}`);
268
+ }
269
+ }
270
+ if (mode === 'loop') {
271
+ if (!/function\s+draw\s*\(\s*\)/.test(source)) {
272
+ errors.push('Loop mode requires a draw() function');
273
+ }
274
+ if (/noLoop\s*\(\s*\)/.test(source)) {
275
+ errors.push('noLoop() is forbidden in Loop mode');
276
+ }
277
+ }
278
+ return {
279
+ valid: errors.length === 0,
280
+ errors,
281
+ };
282
+ }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * NexArt Code Mode Runtime SDK
3
- * Version: 1.5.0 (Protocol v1.2.0)
3
+ * Version: 1.1.0 (Protocol v1.0.0)
4
4
  *
5
5
  * ╔══════════════════════════════════════════════════════════════════════════╗
6
6
  * ║ @nexart/codemode-sdk — Canonical Code Mode Authority ║
@@ -10,9 +10,9 @@
10
10
  * ║ ║
11
11
  * ║ Protocol: nexart ║
12
12
  * ║ Engine: codemode ║
13
- * ║ SDK Version: 1.5.0 ║
14
- * ║ Protocol Version: 1.2.0 ║
15
- * ║ Phase: 3
13
+ * ║ SDK Version: 1.1.0 ║
14
+ * ║ Protocol Version: 1.0.0 ║
15
+ * ║ Phase: 1
16
16
  * ║ Enforcement: HARD ║
17
17
  * ╚══════════════════════════════════════════════════════════════════════════╝
18
18
  *
@@ -21,23 +21,30 @@
21
21
  * import { executeCodeMode } from '@nexart/codemode-sdk';
22
22
  *
23
23
  * const result = await executeCodeMode({
24
- * source: `
25
- * function setup() {
26
- * background(255);
27
- * fill(0);
28
- * ellipse(width/2, height/2, 100);
29
- * }
30
- * `,
31
- * mode: 'static',
24
+ * source: `function setup() { background(255); ellipse(width/2, height/2, 100); }`,
32
25
  * width: 1950,
33
26
  * height: 2400,
34
27
  * seed: 12345,
35
- * vars: [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]
28
+ * vars: [50, 0, 0, 0, 0, 0, 0, 0, 0, 0],
29
+ * mode: 'static'
36
30
  * });
37
- * console.log('Rendered:', result.blob.size, 'bytes');
31
+ *
32
+ * console.log(result.metadata.protocolVersion); // '1.0.0'
38
33
  * ```
39
34
  */
40
- export { executeCodeMode, validateCodeModeSource } from './engine';
41
- export type { ExecuteCodeModeInput, ExecuteCodeModeResult, ProtocolMetadata, RenderResult, TimeVariables, } from './types';
42
- export { DEFAULT_CONFIG, PROTOCOL_IDENTITY } from './types';
35
+ export { executeCodeMode, validateCodeModeSource } from './execute';
36
+ export type { ExecuteCodeModeInput, ExecuteCodeModeResult, ProtocolMetadata, } from './types';
37
+ export { PROTOCOL_IDENTITY } from './types';
38
+ export { createEngine } from './engine';
39
+ export type { Engine, EngineConfig, RunOptions, RenderResult, ProgressInfo, RenderMode, TimeVariables, } from './types';
40
+ export { DEFAULT_CONFIG } from './types';
41
+ export { renderSoundArtViaCodeMode, canRenderViaCodeMode, getCodeModeAvailableStyles, type SoundArtEngineConfig, type SoundArtRenderOptions, type SoundArtRenderResult, type SoundArtMetadata, } from './soundart-engine';
42
+ export { type SoundSnapshot, type SoundFeatures, createSoundSnapshot, createEmptySoundSnapshot, freezeSoundSnapshot, } from '../../shared/soundSnapshot';
43
+ export { injectSoundGlobals, createSoundGlobals, createEmptySoundGlobals, generateSoundPalette, inferGenreProfile, createSoundHelpers, type SoundGlobals, type GenreProfile, } from './sound-bridge';
44
+ export { getSoundArtSketch, getAvailableSoundArtSketches, isSoundArtSketchAvailable, type SoundArtSketchName, } from './soundart-sketches';
45
+ export { createP5Runtime, type P5Runtime, type P5RuntimeConfig } from './p5-runtime';
46
+ export { renderNoiseViaCodeMode, compileNoiseSystem, canRenderNoiseViaCodeMode, type NoiseEngineConfig, type NoiseRenderOptions, type NoiseRenderResult, type NoiseMetadata, } from './noise-engine';
47
+ export { type NoiseSnapshot, type NoiseParams, type NoiseBlendMode, createNoiseSnapshot, validateNoiseSnapshot, } from '../../shared/noiseSnapshot';
48
+ export { createNoiseGlobals, injectNoiseGlobals, type NoiseGlobals, } from './noise-bridge';
49
+ export { getNoiseSketch, getAvailableNoiseSketchNames, isValidNoiseSketch, type NoiseSketchName, } from './noise-sketches';
43
50
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AACnE,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,YAAY,EACZ,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,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tB,kBAAkB,EAClB,yBAAyB,EACzB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,aAAa,GACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,KAAK,YAAY,GAClB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,cAAc,EACd,4BAA4B,EAC5B,kBAAkB,EAClB,KAAK,eAAe,GACrB,MAAM,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * NexArt Code Mode Runtime SDK
3
- * Version: 1.5.0 (Protocol v1.2.0)
3
+ * Version: 1.1.0 (Protocol v1.0.0)
4
4
  *
5
5
  * ╔══════════════════════════════════════════════════════════════════════════╗
6
6
  * ║ @nexart/codemode-sdk — Canonical Code Mode Authority ║
@@ -10,9 +10,9 @@
10
10
  * ║ ║
11
11
  * ║ Protocol: nexart ║
12
12
  * ║ Engine: codemode ║
13
- * ║ SDK Version: 1.5.0 ║
14
- * ║ Protocol Version: 1.2.0 ║
15
- * ║ Phase: 3
13
+ * ║ SDK Version: 1.1.0 ║
14
+ * ║ Protocol Version: 1.0.0 ║
15
+ * ║ Phase: 1
16
16
  * ║ Enforcement: HARD ║
17
17
  * ╚══════════════════════════════════════════════════════════════════════════╝
18
18
  *
@@ -21,21 +21,35 @@
21
21
  * import { executeCodeMode } from '@nexart/codemode-sdk';
22
22
  *
23
23
  * const result = await executeCodeMode({
24
- * source: `
25
- * function setup() {
26
- * background(255);
27
- * fill(0);
28
- * ellipse(width/2, height/2, 100);
29
- * }
30
- * `,
31
- * mode: 'static',
24
+ * source: `function setup() { background(255); ellipse(width/2, height/2, 100); }`,
32
25
  * width: 1950,
33
26
  * height: 2400,
34
27
  * seed: 12345,
35
- * vars: [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]
28
+ * vars: [50, 0, 0, 0, 0, 0, 0, 0, 0, 0],
29
+ * mode: 'static'
36
30
  * });
37
- * console.log('Rendered:', result.blob.size, 'bytes');
31
+ *
32
+ * console.log(result.metadata.protocolVersion); // '1.0.0'
38
33
  * ```
39
34
  */
40
- export { executeCodeMode, validateCodeModeSource } from './engine';
41
- export { DEFAULT_CONFIG, PROTOCOL_IDENTITY } from './types';
35
+ // ═══════════════════════════════════════════════════════════════════════════
36
+ // CANONICAL EXECUTION ENTRY POINT
37
+ // ═══════════════════════════════════════════════════════════════════════════
38
+ export { executeCodeMode, validateCodeModeSource } from './execute';
39
+ export { PROTOCOL_IDENTITY } from './types';
40
+ // ═══════════════════════════════════════════════════════════════════════════
41
+ // LEGACY ENGINE API (use executeCodeMode for new implementations)
42
+ // ═══════════════════════════════════════════════════════════════════════════
43
+ export { createEngine } from './engine';
44
+ export { DEFAULT_CONFIG } from './types';
45
+ // SoundArt → Code Mode integration
46
+ export { renderSoundArtViaCodeMode, canRenderViaCodeMode, getCodeModeAvailableStyles, } from './soundart-engine';
47
+ export { createSoundSnapshot, createEmptySoundSnapshot, freezeSoundSnapshot, } from '../../shared/soundSnapshot';
48
+ export { injectSoundGlobals, createSoundGlobals, createEmptySoundGlobals, generateSoundPalette, inferGenreProfile, createSoundHelpers, } from './sound-bridge';
49
+ export { getSoundArtSketch, getAvailableSoundArtSketches, isSoundArtSketchAvailable, } from './soundart-sketches';
50
+ export { createP5Runtime } from './p5-runtime';
51
+ // Noise → Code Mode integration
52
+ export { renderNoiseViaCodeMode, compileNoiseSystem, canRenderNoiseViaCodeMode, } from './noise-engine';
53
+ export { createNoiseSnapshot, validateNoiseSnapshot, } from '../../shared/noiseSnapshot';
54
+ export { createNoiseGlobals, injectNoiseGlobals, } from './noise-bridge';
55
+ export { getNoiseSketch, getAvailableNoiseSketchNames, isValidNoiseSketch, } from './noise-sketches';
@@ -0,0 +1,44 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,68 @@
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
+ }
@@ -0,0 +1,74 @@
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
@@ -0,0 +1 @@
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,M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