@nexart/codemode-sdk 1.5.1 → 1.7.0

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 (134) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/LICENSE.md +62 -0
  3. package/README.md +172 -25
  4. package/builder.manifest.schema.json +62 -0
  5. package/dist/builder-manifest.d.ts +1 -1
  6. package/dist/builder-manifest.js +1 -1
  7. package/dist/core-index.d.ts +1 -1
  8. package/dist/core-index.js +1 -1
  9. package/dist/entry/browser.d.ts +37 -0
  10. package/dist/entry/browser.d.ts.map +1 -0
  11. package/dist/entry/browser.js +55 -0
  12. package/dist/entry/node.d.ts +21 -0
  13. package/dist/entry/node.d.ts.map +1 -0
  14. package/dist/entry/node.js +32 -0
  15. package/dist/execute.d.ts.map +1 -1
  16. package/dist/execute.js +4 -3
  17. package/dist/execution-sandbox.d.ts +107 -0
  18. package/dist/execution-sandbox.d.ts.map +1 -0
  19. package/dist/execution-sandbox.js +207 -0
  20. package/dist/index.d.ts +14 -33
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +41 -33
  23. package/dist/loop-engine.d.ts +3 -0
  24. package/dist/loop-engine.d.ts.map +1 -1
  25. package/dist/loop-engine.js +17 -7
  26. package/dist/p5-runtime.d.ts +3 -1
  27. package/dist/p5-runtime.d.ts.map +1 -1
  28. package/dist/p5-runtime.js +2 -0
  29. package/dist/sdk/codemode/builder-manifest.d.ts +79 -0
  30. package/dist/sdk/codemode/builder-manifest.d.ts.map +1 -0
  31. package/dist/sdk/codemode/builder-manifest.js +97 -0
  32. package/dist/sdk/codemode/core-index.d.ts +21 -0
  33. package/dist/sdk/codemode/core-index.d.ts.map +1 -0
  34. package/dist/sdk/codemode/core-index.js +26 -0
  35. package/dist/sdk/codemode/engine.d.ts +24 -0
  36. package/dist/sdk/codemode/engine.d.ts.map +1 -0
  37. package/dist/sdk/codemode/engine.js +67 -0
  38. package/dist/sdk/codemode/execute.d.ts +46 -0
  39. package/dist/sdk/codemode/execute.d.ts.map +1 -0
  40. package/dist/sdk/codemode/execute.js +283 -0
  41. package/dist/sdk/codemode/execution-sandbox.d.ts +107 -0
  42. package/dist/sdk/codemode/execution-sandbox.d.ts.map +1 -0
  43. package/dist/sdk/codemode/execution-sandbox.js +207 -0
  44. package/dist/sdk/codemode/index.d.ts +31 -0
  45. package/dist/sdk/codemode/index.d.ts.map +1 -0
  46. package/dist/sdk/codemode/index.js +63 -0
  47. package/dist/sdk/codemode/loop-engine.d.ts +22 -0
  48. package/dist/sdk/codemode/loop-engine.d.ts.map +1 -0
  49. package/dist/sdk/codemode/loop-engine.js +229 -0
  50. package/dist/sdk/codemode/noise-bridge.d.ts +44 -0
  51. package/dist/sdk/codemode/noise-bridge.d.ts.map +1 -0
  52. package/dist/sdk/codemode/noise-bridge.js +68 -0
  53. package/dist/sdk/codemode/noise-engine.d.ts +74 -0
  54. package/dist/sdk/codemode/noise-engine.d.ts.map +1 -0
  55. package/dist/sdk/codemode/noise-engine.js +132 -0
  56. package/dist/sdk/codemode/noise-sketches/fractalNoise.d.ts +11 -0
  57. package/dist/sdk/codemode/noise-sketches/fractalNoise.d.ts.map +1 -0
  58. package/dist/sdk/codemode/noise-sketches/fractalNoise.js +121 -0
  59. package/dist/sdk/codemode/noise-sketches/index.d.ts +21 -0
  60. package/dist/sdk/codemode/noise-sketches/index.d.ts.map +1 -0
  61. package/dist/sdk/codemode/noise-sketches/index.js +28 -0
  62. package/dist/sdk/codemode/p5-runtime.d.ts +75 -0
  63. package/dist/sdk/codemode/p5-runtime.d.ts.map +1 -0
  64. package/dist/sdk/codemode/p5-runtime.js +1031 -0
  65. package/dist/sdk/codemode/sound-bridge.d.ts +89 -0
  66. package/dist/sdk/codemode/sound-bridge.d.ts.map +1 -0
  67. package/dist/sdk/codemode/sound-bridge.js +128 -0
  68. package/dist/sdk/codemode/soundart-engine.d.ts +87 -0
  69. package/dist/sdk/codemode/soundart-engine.d.ts.map +1 -0
  70. package/dist/sdk/codemode/soundart-engine.js +173 -0
  71. package/dist/sdk/codemode/soundart-sketches/chladniBloom.d.ts +3 -0
  72. package/dist/sdk/codemode/soundart-sketches/chladniBloom.d.ts.map +1 -0
  73. package/dist/sdk/codemode/soundart-sketches/chladniBloom.js +53 -0
  74. package/dist/sdk/codemode/soundart-sketches/dualVortex.d.ts +3 -0
  75. package/dist/sdk/codemode/soundart-sketches/dualVortex.d.ts.map +1 -0
  76. package/dist/sdk/codemode/soundart-sketches/dualVortex.js +67 -0
  77. package/dist/sdk/codemode/soundart-sketches/geometryIllusion.d.ts +3 -0
  78. package/dist/sdk/codemode/soundart-sketches/geometryIllusion.d.ts.map +1 -0
  79. package/dist/sdk/codemode/soundart-sketches/geometryIllusion.js +89 -0
  80. package/dist/sdk/codemode/soundart-sketches/index.d.ts +39 -0
  81. package/dist/sdk/codemode/soundart-sketches/index.d.ts.map +1 -0
  82. package/dist/sdk/codemode/soundart-sketches/index.js +72 -0
  83. package/dist/sdk/codemode/soundart-sketches/isoflow.d.ts +3 -0
  84. package/dist/sdk/codemode/soundart-sketches/isoflow.d.ts.map +1 -0
  85. package/dist/sdk/codemode/soundart-sketches/isoflow.js +60 -0
  86. package/dist/sdk/codemode/soundart-sketches/loomWeave.d.ts +3 -0
  87. package/dist/sdk/codemode/soundart-sketches/loomWeave.d.ts.map +1 -0
  88. package/dist/sdk/codemode/soundart-sketches/loomWeave.js +59 -0
  89. package/dist/sdk/codemode/soundart-sketches/noiseTerraces.d.ts +3 -0
  90. package/dist/sdk/codemode/soundart-sketches/noiseTerraces.d.ts.map +1 -0
  91. package/dist/sdk/codemode/soundart-sketches/noiseTerraces.js +53 -0
  92. package/dist/sdk/codemode/soundart-sketches/orb.d.ts +3 -0
  93. package/dist/sdk/codemode/soundart-sketches/orb.d.ts.map +1 -0
  94. package/dist/sdk/codemode/soundart-sketches/orb.js +50 -0
  95. package/dist/sdk/codemode/soundart-sketches/pixelGlyphs.d.ts +3 -0
  96. package/dist/sdk/codemode/soundart-sketches/pixelGlyphs.d.ts.map +1 -0
  97. package/dist/sdk/codemode/soundart-sketches/pixelGlyphs.js +72 -0
  98. package/dist/sdk/codemode/soundart-sketches/prismFlowFields.d.ts +3 -0
  99. package/dist/sdk/codemode/soundart-sketches/prismFlowFields.d.ts.map +1 -0
  100. package/dist/sdk/codemode/soundart-sketches/prismFlowFields.js +51 -0
  101. package/dist/sdk/codemode/soundart-sketches/radialBurst.d.ts +3 -0
  102. package/dist/sdk/codemode/soundart-sketches/radialBurst.d.ts.map +1 -0
  103. package/dist/sdk/codemode/soundart-sketches/radialBurst.js +60 -0
  104. package/dist/sdk/codemode/soundart-sketches/resonantSoundBodies.d.ts +3 -0
  105. package/dist/sdk/codemode/soundart-sketches/resonantSoundBodies.d.ts.map +1 -0
  106. package/dist/sdk/codemode/soundart-sketches/resonantSoundBodies.js +89 -0
  107. package/dist/sdk/codemode/soundart-sketches/rings.d.ts +11 -0
  108. package/dist/sdk/codemode/soundart-sketches/rings.d.ts.map +1 -0
  109. package/dist/sdk/codemode/soundart-sketches/rings.js +89 -0
  110. package/dist/sdk/codemode/soundart-sketches/squares.d.ts +3 -0
  111. package/dist/sdk/codemode/soundart-sketches/squares.d.ts.map +1 -0
  112. package/dist/sdk/codemode/soundart-sketches/squares.js +52 -0
  113. package/dist/sdk/codemode/soundart-sketches/waveStripes.d.ts +3 -0
  114. package/dist/sdk/codemode/soundart-sketches/waveStripes.d.ts.map +1 -0
  115. package/dist/sdk/codemode/soundart-sketches/waveStripes.js +44 -0
  116. package/dist/sdk/codemode/static-engine.d.ts +20 -0
  117. package/dist/sdk/codemode/static-engine.d.ts.map +1 -0
  118. package/dist/sdk/codemode/static-engine.js +144 -0
  119. package/dist/sdk/codemode/types.d.ts +191 -0
  120. package/dist/sdk/codemode/types.d.ts.map +1 -0
  121. package/dist/sdk/codemode/types.js +32 -0
  122. package/dist/shared/noiseSnapshot.d.ts +59 -0
  123. package/dist/shared/noiseSnapshot.d.ts.map +1 -0
  124. package/dist/shared/noiseSnapshot.js +72 -0
  125. package/dist/shared/soundSnapshot.d.ts +94 -0
  126. package/dist/shared/soundSnapshot.d.ts.map +1 -0
  127. package/dist/shared/soundSnapshot.js +128 -0
  128. package/dist/static-engine.d.ts +7 -0
  129. package/dist/static-engine.d.ts.map +1 -1
  130. package/dist/static-engine.js +82 -14
  131. package/dist/types.d.ts +28 -6
  132. package/dist/types.d.ts.map +1 -1
  133. package/dist/types.js +1 -1
  134. package/package.json +31 -5
@@ -0,0 +1,121 @@
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 const FRACTAL_NOISE_SKETCH = `
10
+ // Fractal Noise - Code Mode Sketch
11
+ // Uses N.* noise globals and standard p5-like functions
12
+
13
+ function setup() {
14
+ // Set seeded random for reproducibility
15
+ randomSeed(N.seed);
16
+ noiseSeed(N.seed);
17
+
18
+ // Set background color
19
+ background(N.bgR, N.bgG, N.bgB);
20
+
21
+ // Noise rendering parameters
22
+ const adjustedScale = N.scale * (1 / N.zoom) * 0.05;
23
+ const cellSize = 4; // Fixed for quality
24
+
25
+ // Generate cellular points if needed
26
+ const numPoints = Math.floor(20 + N.cellDensity * 180);
27
+ const cellPoints = [];
28
+ for (let i = 0; i < numPoints; i++) {
29
+ cellPoints.push([random(0, width), random(0, height)]);
30
+ }
31
+
32
+ // Helper: Perlin FBM (Fractional Brownian Motion)
33
+ function perlinFBM(x, y, scale) {
34
+ let value = 0;
35
+ let amplitude = 1;
36
+ let frequency = 1;
37
+ let maxValue = 0;
38
+
39
+ const oct = Math.min(N.octaves, 6); // Cap for performance
40
+
41
+ for (let i = 0; i < oct; i++) {
42
+ value += noise(x * scale * frequency, y * scale * frequency) * amplitude;
43
+ maxValue += amplitude;
44
+ amplitude *= N.persistence;
45
+ frequency *= N.lacunarity;
46
+ }
47
+
48
+ return value / maxValue;
49
+ }
50
+
51
+ // Helper: Cellular noise (Worley)
52
+ function cellularNoise(x, y, points) {
53
+ let sampleX = x;
54
+ let sampleY = y;
55
+
56
+ // Warp distortion if using warp mode
57
+ if (N.isWarp && N.cellDistortion > 0) {
58
+ const distortionAmount = N.cellDistortion * 100;
59
+ sampleX += noise(x * 0.01, y * 0.01) * distortionAmount;
60
+ sampleY += noise(y * 0.01, x * 0.01) * distortionAmount;
61
+ }
62
+
63
+ // Find distances to closest points
64
+ let minDist = 999999;
65
+ let secondMinDist = 999999;
66
+
67
+ for (let i = 0; i < points.length; i++) {
68
+ const px = points[i][0];
69
+ const py = points[i][1];
70
+ const dx = sampleX - px;
71
+ const dy = sampleY - py;
72
+ const dist = Math.sqrt(dx * dx + dy * dy);
73
+
74
+ if (dist < minDist) {
75
+ secondMinDist = minDist;
76
+ minDist = dist;
77
+ } else if (dist < secondMinDist) {
78
+ secondMinDist = dist;
79
+ }
80
+ }
81
+
82
+ // Normalize distance
83
+ return Math.min(1.0, (secondMinDist - minDist) / 50);
84
+ }
85
+
86
+ // Render the noise grid
87
+ noStroke();
88
+
89
+ for (let y = 0; y < height; y += cellSize) {
90
+ for (let x = 0; x < width; x += cellSize) {
91
+ // Calculate Perlin value
92
+ const perlinValue = perlinFBM(x, y, adjustedScale);
93
+
94
+ // Calculate final value based on blend mode
95
+ let finalValue = perlinValue;
96
+
97
+ if (!N.isPerlinOnly) {
98
+ const cellValue = cellularNoise(x, y, cellPoints);
99
+
100
+ if (N.isBlend) {
101
+ finalValue = perlinValue * cellValue;
102
+ } else if (N.isWarp) {
103
+ finalValue = (perlinValue + cellValue) / 2;
104
+ } else if (N.isInterleave) {
105
+ finalValue = (Math.floor(x / 20) + Math.floor(y / 20)) % 2 === 0
106
+ ? perlinValue
107
+ : cellValue;
108
+ }
109
+ }
110
+
111
+ // Set opacity based on noise value
112
+ const alpha = map(finalValue, 0, 1, 0, 255);
113
+
114
+ // Fill with noise color and calculated alpha
115
+ fill(N.noiseR, N.noiseG, N.noiseB, alpha);
116
+ rect(x, y, cellSize, cellSize);
117
+ }
118
+ }
119
+ }
120
+ `;
121
+ export default FRACTAL_NOISE_SKETCH;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Noise Sketches Index
3
+ *
4
+ * Exports all available noise sketch generators for the Code Mode runtime.
5
+ */
6
+ import FRACTAL_NOISE_SKETCH from './fractalNoise';
7
+ export type NoiseSketchName = 'fractalNoise';
8
+ /**
9
+ * Get a noise sketch by name
10
+ */
11
+ export declare function getNoiseSketch(name: NoiseSketchName): string;
12
+ /**
13
+ * Check if a sketch name is valid
14
+ */
15
+ export declare function isValidNoiseSketch(name: string): name is NoiseSketchName;
16
+ /**
17
+ * Get list of all available noise sketch names
18
+ */
19
+ export declare function getAvailableNoiseSketchNames(): NoiseSketchName[];
20
+ export { FRACTAL_NOISE_SKETCH };
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../noise-sketches/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,oBAAoB,MAAM,gBAAgB,CAAC;AAElD,MAAM,MAAM,eAAe,GAAG,cAAc,CAAC;AAM7C;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAE5D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,eAAe,CAExE;AAED;;GAEG;AACH,wBAAgB,4BAA4B,IAAI,eAAe,EAAE,CAEhE;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Noise Sketches Index
3
+ *
4
+ * Exports all available noise sketch generators for the Code Mode runtime.
5
+ */
6
+ import FRACTAL_NOISE_SKETCH from './fractalNoise';
7
+ const NOISE_SKETCHES = {
8
+ fractalNoise: FRACTAL_NOISE_SKETCH,
9
+ };
10
+ /**
11
+ * Get a noise sketch by name
12
+ */
13
+ export function getNoiseSketch(name) {
14
+ return NOISE_SKETCHES[name];
15
+ }
16
+ /**
17
+ * Check if a sketch name is valid
18
+ */
19
+ export function isValidNoiseSketch(name) {
20
+ return name in NOISE_SKETCHES;
21
+ }
22
+ /**
23
+ * Get list of all available noise sketch names
24
+ */
25
+ export function getAvailableNoiseSketchNames() {
26
+ return Object.keys(NOISE_SKETCHES);
27
+ }
28
+ export { FRACTAL_NOISE_SKETCH };
@@ -0,0 +1,75 @@
1
+ /**
2
+ * NexArt Code Mode Runtime SDK - p5-like Runtime
3
+ *
4
+ * ╔══════════════════════════════════════════════════════════════════════════╗
5
+ * ║ CODE MODE PROTOCOL v1.2.0 (Phase 3) — STABLE ║
6
+ * ║ ║
7
+ * ║ Status: HARD PROTOCOL ENFORCEMENT ║
8
+ * ║ This is the stable, canonical execution surface. ║
9
+ * ║ SDKs, ByX, and external builders can depend on this API. ║
10
+ * ║ ║
11
+ * ║ Phase 1 Surface: ║
12
+ * ║ - VAR[0..9]: 10 read-only protocol variables (0-100 range) ║
13
+ * ║ - Drawing: line, rect, ellipse, circle, triangle, quad, arc, etc. ║
14
+ * ║ - Style: fill, stroke, colorMode, strokeWeight ║
15
+ * ║ - Transform: push, pop, translate, rotate, scale ║
16
+ * ║ - Random: random(), randomSeed(), randomGaussian() (seeded) ║
17
+ * ║ - Noise: noise(), noiseSeed(), noiseDetail() (seeded) ║
18
+ * ║ - Math: map, constrain, lerp, lerpColor, dist, mag, norm ║
19
+ * ║ - Color: Full CSS format support, color extraction functions ║
20
+ * ║ - Time: frameCount, t, time, tGlobal ║
21
+ * ║ ║
22
+ * ║ Determinism Guarantees: ║
23
+ * ║ - Same code + same seed + same VARs = identical output ║
24
+ * ║ - No external state, no browser entropy, no time-based drift ║
25
+ * ║ - Randomness ONLY from: random(), noise() (both seeded) ║
26
+ * ║ ║
27
+ * ║ ⚠️ Future changes require Phase 2+ ║
28
+ * ╚══════════════════════════════════════════════════════════════════════════╝
29
+ */
30
+ import type { TimeVariables } from './types';
31
+ /**
32
+ * Code Mode Protocol Version
33
+ * This constant defines the locked protocol version.
34
+ * Changes to the execution surface require a version bump.
35
+ */
36
+ export declare const CODE_MODE_PROTOCOL_VERSION = "1.2.0";
37
+ export declare const CODE_MODE_PROTOCOL_PHASE = 3;
38
+ export declare const CODE_MODE_ENFORCEMENT: "HARD";
39
+ export interface P5Runtime {
40
+ [key: string]: any;
41
+ width: number;
42
+ height: number;
43
+ frameCount: number;
44
+ PI: number;
45
+ TWO_PI: number;
46
+ HALF_PI: number;
47
+ QUARTER_PI: number;
48
+ }
49
+ export interface P5RuntimeConfig {
50
+ seed?: number;
51
+ }
52
+ type RuntimeCanvas = HTMLCanvasElement;
53
+ export declare function createP5Runtime(canvas: RuntimeCanvas, width: number, height: number, config?: P5RuntimeConfig): P5Runtime;
54
+ export declare function injectTimeVariables(p: P5Runtime, time: TimeVariables): void;
55
+ /**
56
+ * VAR Protocol Constants (Phase 1 — Protocol v1.0.0)
57
+ * SDK v1.0.2: VAR input is optional (0-10 elements), but runtime always has 10
58
+ */
59
+ export declare const VAR_COUNT = 10;
60
+ export declare const VAR_MIN = 0;
61
+ export declare const VAR_MAX = 100;
62
+ /**
63
+ * Create a protected, read-only VAR array for protocol execution.
64
+ *
65
+ * SDK v1.0.2 Rules (Protocol v1.0.0):
66
+ * - Input accepts 0-10 elements
67
+ * - Runtime VAR is ALWAYS 10 elements (padded with zeros)
68
+ * - Values are numeric, must be in 0-100 range (validated upstream)
69
+ * - Read-only: writes throw descriptive errors
70
+ * - Available in both setup() and draw()
71
+ */
72
+ export declare function createProtocolVAR(vars?: number[]): readonly number[];
73
+ export declare function injectProtocolVariables(p: P5Runtime, vars?: number[]): void;
74
+ export {};
75
+ //# sourceMappingURL=p5-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"p5-runtime.d.ts","sourceRoot":"","sources":["../../../p5-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,UAAU,CAAC;AAClD,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,qBAAqB,EAAG,MAAe,CAAC;AAErD,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAmED,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,KAAK,aAAa,GAAG,iBAAiB,CAAC;AAEvC,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,eAAe,GACvB,SAAS,CAs8BX;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAM3E;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,eAAO,MAAM,OAAO,IAAI,CAAC;AACzB,eAAO,MAAM,OAAO,MAAM,CAAC;AAE3B;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE,CAmCpE;AAED,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAE3E"}