@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.
- package/CHANGELOG.md +78 -0
- package/LICENSE.md +62 -0
- package/README.md +172 -25
- package/builder.manifest.schema.json +62 -0
- package/dist/builder-manifest.d.ts +1 -1
- package/dist/builder-manifest.js +1 -1
- package/dist/core-index.d.ts +1 -1
- package/dist/core-index.js +1 -1
- package/dist/entry/browser.d.ts +37 -0
- package/dist/entry/browser.d.ts.map +1 -0
- package/dist/entry/browser.js +55 -0
- package/dist/entry/node.d.ts +21 -0
- package/dist/entry/node.d.ts.map +1 -0
- package/dist/entry/node.js +32 -0
- package/dist/execute.d.ts.map +1 -1
- package/dist/execute.js +4 -3
- package/dist/execution-sandbox.d.ts +107 -0
- package/dist/execution-sandbox.d.ts.map +1 -0
- package/dist/execution-sandbox.js +207 -0
- package/dist/index.d.ts +14 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -33
- package/dist/loop-engine.d.ts +3 -0
- package/dist/loop-engine.d.ts.map +1 -1
- package/dist/loop-engine.js +17 -7
- package/dist/p5-runtime.d.ts +3 -1
- package/dist/p5-runtime.d.ts.map +1 -1
- package/dist/p5-runtime.js +2 -0
- package/dist/sdk/codemode/builder-manifest.d.ts +79 -0
- package/dist/sdk/codemode/builder-manifest.d.ts.map +1 -0
- package/dist/sdk/codemode/builder-manifest.js +97 -0
- package/dist/sdk/codemode/core-index.d.ts +21 -0
- package/dist/sdk/codemode/core-index.d.ts.map +1 -0
- package/dist/sdk/codemode/core-index.js +26 -0
- package/dist/sdk/codemode/engine.d.ts +24 -0
- package/dist/sdk/codemode/engine.d.ts.map +1 -0
- package/dist/sdk/codemode/engine.js +67 -0
- package/dist/sdk/codemode/execute.d.ts +46 -0
- package/dist/sdk/codemode/execute.d.ts.map +1 -0
- package/dist/sdk/codemode/execute.js +283 -0
- package/dist/sdk/codemode/execution-sandbox.d.ts +107 -0
- package/dist/sdk/codemode/execution-sandbox.d.ts.map +1 -0
- package/dist/sdk/codemode/execution-sandbox.js +207 -0
- package/dist/sdk/codemode/index.d.ts +31 -0
- package/dist/sdk/codemode/index.d.ts.map +1 -0
- package/dist/sdk/codemode/index.js +63 -0
- package/dist/sdk/codemode/loop-engine.d.ts +22 -0
- package/dist/sdk/codemode/loop-engine.d.ts.map +1 -0
- package/dist/sdk/codemode/loop-engine.js +229 -0
- package/dist/sdk/codemode/noise-bridge.d.ts +44 -0
- package/dist/sdk/codemode/noise-bridge.d.ts.map +1 -0
- package/dist/sdk/codemode/noise-bridge.js +68 -0
- package/dist/sdk/codemode/noise-engine.d.ts +74 -0
- package/dist/sdk/codemode/noise-engine.d.ts.map +1 -0
- package/dist/sdk/codemode/noise-engine.js +132 -0
- package/dist/sdk/codemode/noise-sketches/fractalNoise.d.ts +11 -0
- package/dist/sdk/codemode/noise-sketches/fractalNoise.d.ts.map +1 -0
- package/dist/sdk/codemode/noise-sketches/fractalNoise.js +121 -0
- package/dist/sdk/codemode/noise-sketches/index.d.ts +21 -0
- package/dist/sdk/codemode/noise-sketches/index.d.ts.map +1 -0
- package/dist/sdk/codemode/noise-sketches/index.js +28 -0
- package/dist/sdk/codemode/p5-runtime.d.ts +75 -0
- package/dist/sdk/codemode/p5-runtime.d.ts.map +1 -0
- package/dist/sdk/codemode/p5-runtime.js +1031 -0
- package/dist/sdk/codemode/sound-bridge.d.ts +89 -0
- package/dist/sdk/codemode/sound-bridge.d.ts.map +1 -0
- package/dist/sdk/codemode/sound-bridge.js +128 -0
- package/dist/sdk/codemode/soundart-engine.d.ts +87 -0
- package/dist/sdk/codemode/soundart-engine.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-engine.js +173 -0
- package/dist/sdk/codemode/soundart-sketches/chladniBloom.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/chladniBloom.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/chladniBloom.js +53 -0
- package/dist/sdk/codemode/soundart-sketches/dualVortex.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/dualVortex.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/dualVortex.js +67 -0
- package/dist/sdk/codemode/soundart-sketches/geometryIllusion.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/geometryIllusion.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/geometryIllusion.js +89 -0
- package/dist/sdk/codemode/soundart-sketches/index.d.ts +39 -0
- package/dist/sdk/codemode/soundart-sketches/index.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/index.js +72 -0
- package/dist/sdk/codemode/soundart-sketches/isoflow.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/isoflow.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/isoflow.js +60 -0
- package/dist/sdk/codemode/soundart-sketches/loomWeave.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/loomWeave.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/loomWeave.js +59 -0
- package/dist/sdk/codemode/soundart-sketches/noiseTerraces.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/noiseTerraces.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/noiseTerraces.js +53 -0
- package/dist/sdk/codemode/soundart-sketches/orb.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/orb.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/orb.js +50 -0
- package/dist/sdk/codemode/soundart-sketches/pixelGlyphs.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/pixelGlyphs.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/pixelGlyphs.js +72 -0
- package/dist/sdk/codemode/soundart-sketches/prismFlowFields.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/prismFlowFields.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/prismFlowFields.js +51 -0
- package/dist/sdk/codemode/soundart-sketches/radialBurst.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/radialBurst.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/radialBurst.js +60 -0
- package/dist/sdk/codemode/soundart-sketches/resonantSoundBodies.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/resonantSoundBodies.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/resonantSoundBodies.js +89 -0
- package/dist/sdk/codemode/soundart-sketches/rings.d.ts +11 -0
- package/dist/sdk/codemode/soundart-sketches/rings.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/rings.js +89 -0
- package/dist/sdk/codemode/soundart-sketches/squares.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/squares.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/squares.js +52 -0
- package/dist/sdk/codemode/soundart-sketches/waveStripes.d.ts +3 -0
- package/dist/sdk/codemode/soundart-sketches/waveStripes.d.ts.map +1 -0
- package/dist/sdk/codemode/soundart-sketches/waveStripes.js +44 -0
- package/dist/sdk/codemode/static-engine.d.ts +20 -0
- package/dist/sdk/codemode/static-engine.d.ts.map +1 -0
- package/dist/sdk/codemode/static-engine.js +144 -0
- package/dist/sdk/codemode/types.d.ts +191 -0
- package/dist/sdk/codemode/types.d.ts.map +1 -0
- package/dist/sdk/codemode/types.js +32 -0
- package/dist/shared/noiseSnapshot.d.ts +59 -0
- package/dist/shared/noiseSnapshot.d.ts.map +1 -0
- package/dist/shared/noiseSnapshot.js +72 -0
- package/dist/shared/soundSnapshot.d.ts +94 -0
- package/dist/shared/soundSnapshot.d.ts.map +1 -0
- package/dist/shared/soundSnapshot.js +128 -0
- package/dist/static-engine.d.ts +7 -0
- package/dist/static-engine.d.ts.map +1 -1
- package/dist/static-engine.js +82 -14
- package/dist/types.d.ts +28 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/package.json +31 -5
package/dist/execute.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../execute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EAMtB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../execute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EAMtB,MAAM,SAAS,CAAC;AAuNjB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,qBAAqB,CAAC,CAmChC;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"}
|
package/dist/execute.js
CHANGED
|
@@ -143,7 +143,8 @@ async function executeStatic(input, vars) {
|
|
|
143
143
|
vars: vars,
|
|
144
144
|
onComplete: (result) => {
|
|
145
145
|
resolve({
|
|
146
|
-
image: result.blob,
|
|
146
|
+
image: 'blob' in result ? result.blob : undefined,
|
|
147
|
+
frames: 'imageData' in result ? [result.imageData] : undefined,
|
|
147
148
|
metadata: createMetadata(input, vars),
|
|
148
149
|
});
|
|
149
150
|
},
|
|
@@ -174,7 +175,7 @@ async function executeLoop(input, vars) {
|
|
|
174
175
|
vars: vars,
|
|
175
176
|
onComplete: (result) => {
|
|
176
177
|
resolve({
|
|
177
|
-
video: result.blob,
|
|
178
|
+
video: 'blob' in result && result.type === 'video' ? result.blob : undefined,
|
|
178
179
|
metadata: createMetadata(input, vars),
|
|
179
180
|
});
|
|
180
181
|
},
|
|
@@ -214,7 +215,7 @@ export async function executeCodeMode(input) {
|
|
|
214
215
|
// Normalize VAR values
|
|
215
216
|
const vars = normalizeVars(input.vars);
|
|
216
217
|
// ╔═══════════════════════════════════════════════════════════════════════╗
|
|
217
|
-
// ║ BUILDER MANIFEST CONTEXT (v1.
|
|
218
|
+
// ║ BUILDER MANIFEST CONTEXT (v1.6.0) ║
|
|
218
219
|
// ║ ║
|
|
219
220
|
// ║ Internal context for builder attribution. ║
|
|
220
221
|
// ║ This is NOT exposed to sketch code, NOT serialized, NOT logged. ║
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NexArt Code Mode SDK - Execution Sandbox
|
|
3
|
+
* Version: 1.6.0 (Protocol v1.2.0)
|
|
4
|
+
*
|
|
5
|
+
* ╔══════════════════════════════════════════════════════════════════════════╗
|
|
6
|
+
* ║ EXECUTION BOUNDARY — HARD ENFORCEMENT ║
|
|
7
|
+
* ║ ║
|
|
8
|
+
* ║ This module enforces determinism by blocking all external entropy ║
|
|
9
|
+
* ║ sources at RUNTIME, not just via static pattern scanning. ║
|
|
10
|
+
* ║ ║
|
|
11
|
+
* ║ Blocked APIs (throw [Code Mode Protocol Error]): ║
|
|
12
|
+
* ║ - Date, Date.now, Date.parse, new Date() ║
|
|
13
|
+
* ║ - performance, performance.now ║
|
|
14
|
+
* ║ - process (Node.js) ║
|
|
15
|
+
* ║ - navigator ║
|
|
16
|
+
* ║ - globalThis ║
|
|
17
|
+
* ║ - crypto.getRandomValues ║
|
|
18
|
+
* ║ - Math.random (use seeded random() instead) ║
|
|
19
|
+
* ║ - setTimeout, setInterval, requestAnimationFrame ║
|
|
20
|
+
* ║ - fetch, XMLHttpRequest ║
|
|
21
|
+
* ║ - document, window ║
|
|
22
|
+
* ║ - import, require ║
|
|
23
|
+
* ║ ║
|
|
24
|
+
* ║ All blocked symbols throw immediately on access — no silent undefined. ║
|
|
25
|
+
* ╚══════════════════════════════════════════════════════════════════════════╝
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Forbidden APIs - these are injected into the execution scope to override globals
|
|
29
|
+
*/
|
|
30
|
+
export declare const FORBIDDEN_APIS: {
|
|
31
|
+
readonly Date: (...args: any[]) => never;
|
|
32
|
+
readonly performance: object;
|
|
33
|
+
readonly process: object;
|
|
34
|
+
readonly navigator: object;
|
|
35
|
+
readonly globalThis: object;
|
|
36
|
+
readonly crypto: object;
|
|
37
|
+
readonly setTimeout: (...args: any[]) => never;
|
|
38
|
+
readonly setInterval: (...args: any[]) => never;
|
|
39
|
+
readonly clearTimeout: (...args: any[]) => never;
|
|
40
|
+
readonly clearInterval: (...args: any[]) => never;
|
|
41
|
+
readonly requestAnimationFrame: (...args: any[]) => never;
|
|
42
|
+
readonly cancelAnimationFrame: (...args: any[]) => never;
|
|
43
|
+
readonly fetch: (...args: any[]) => never;
|
|
44
|
+
readonly XMLHttpRequest: (...args: any[]) => never;
|
|
45
|
+
readonly WebSocket: (...args: any[]) => never;
|
|
46
|
+
readonly document: object;
|
|
47
|
+
readonly window: object;
|
|
48
|
+
readonly self: object;
|
|
49
|
+
readonly top: object;
|
|
50
|
+
readonly parent: object;
|
|
51
|
+
readonly frames: object;
|
|
52
|
+
readonly location: object;
|
|
53
|
+
readonly history: object;
|
|
54
|
+
readonly localStorage: object;
|
|
55
|
+
readonly sessionStorage: object;
|
|
56
|
+
readonly indexedDB: object;
|
|
57
|
+
readonly caches: object;
|
|
58
|
+
readonly Notification: (...args: any[]) => never;
|
|
59
|
+
readonly Worker: (...args: any[]) => never;
|
|
60
|
+
readonly SharedWorker: (...args: any[]) => never;
|
|
61
|
+
readonly ServiceWorker: object;
|
|
62
|
+
readonly Blob: (...args: any[]) => never;
|
|
63
|
+
readonly File: (...args: any[]) => never;
|
|
64
|
+
readonly FileReader: (...args: any[]) => never;
|
|
65
|
+
readonly URL: (...args: any[]) => never;
|
|
66
|
+
readonly URLSearchParams: (...args: any[]) => never;
|
|
67
|
+
readonly Headers: (...args: any[]) => never;
|
|
68
|
+
readonly Request: (...args: any[]) => never;
|
|
69
|
+
readonly Response: (...args: any[]) => never;
|
|
70
|
+
readonly EventSource: (...args: any[]) => never;
|
|
71
|
+
readonly Image: (...args: any[]) => never;
|
|
72
|
+
readonly Audio: (...args: any[]) => never;
|
|
73
|
+
readonly Video: (...args: any[]) => never;
|
|
74
|
+
readonly eval: (...args: any[]) => never;
|
|
75
|
+
readonly Function: (...args: any[]) => never;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Create a safe Math object with random() blocked
|
|
79
|
+
*/
|
|
80
|
+
export declare function createSafeMath(): typeof Math;
|
|
81
|
+
/**
|
|
82
|
+
* List of all forbidden API names for documentation
|
|
83
|
+
*/
|
|
84
|
+
export declare const FORBIDDEN_API_NAMES: string[];
|
|
85
|
+
/**
|
|
86
|
+
* Build the complete sandbox context for sketch execution.
|
|
87
|
+
* This includes the p5 runtime plus all forbidden API stubs.
|
|
88
|
+
*/
|
|
89
|
+
export declare function buildSandboxContext(p5Runtime: Record<string, any>): Record<string, any>;
|
|
90
|
+
/**
|
|
91
|
+
* Create a sandboxed function that executes user code with blocked globals.
|
|
92
|
+
*
|
|
93
|
+
* The function is constructed with:
|
|
94
|
+
* 1. All forbidden APIs as explicit parameters (override globals)
|
|
95
|
+
* 2. The p5 runtime as explicit parameters
|
|
96
|
+
* 3. A `with(context)` wrapper for additional safety
|
|
97
|
+
*/
|
|
98
|
+
export declare function createSandboxedExecutor(code: string, additionalParams?: string[]): Function;
|
|
99
|
+
/**
|
|
100
|
+
* Execute user code in a sandboxed environment.
|
|
101
|
+
*
|
|
102
|
+
* @param code - The user sketch code to execute
|
|
103
|
+
* @param p5Runtime - The p5-like runtime object
|
|
104
|
+
* @param additionalContext - Additional context variables (frameCount, t, etc.)
|
|
105
|
+
*/
|
|
106
|
+
export declare function executeSandboxed(code: string, p5Runtime: Record<string, any>, additionalContext?: Record<string, any>): void;
|
|
107
|
+
//# sourceMappingURL=execution-sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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AAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAavF;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,gBAAgB,GAAE,MAAM,EAAO,GAC9B,QAAQ,CAiBV;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC9B,iBAAiB,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAC1C,IAAI,CAsBN"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NexArt Code Mode SDK - Execution Sandbox
|
|
3
|
+
* Version: 1.6.0 (Protocol v1.2.0)
|
|
4
|
+
*
|
|
5
|
+
* ╔══════════════════════════════════════════════════════════════════════════╗
|
|
6
|
+
* ║ EXECUTION BOUNDARY — HARD ENFORCEMENT ║
|
|
7
|
+
* ║ ║
|
|
8
|
+
* ║ This module enforces determinism by blocking all external entropy ║
|
|
9
|
+
* ║ sources at RUNTIME, not just via static pattern scanning. ║
|
|
10
|
+
* ║ ║
|
|
11
|
+
* ║ Blocked APIs (throw [Code Mode Protocol Error]): ║
|
|
12
|
+
* ║ - Date, Date.now, Date.parse, new Date() ║
|
|
13
|
+
* ║ - performance, performance.now ║
|
|
14
|
+
* ║ - process (Node.js) ║
|
|
15
|
+
* ║ - navigator ║
|
|
16
|
+
* ║ - globalThis ║
|
|
17
|
+
* ║ - crypto.getRandomValues ║
|
|
18
|
+
* ║ - Math.random (use seeded random() instead) ║
|
|
19
|
+
* ║ - setTimeout, setInterval, requestAnimationFrame ║
|
|
20
|
+
* ║ - fetch, XMLHttpRequest ║
|
|
21
|
+
* ║ - document, window ║
|
|
22
|
+
* ║ - import, require ║
|
|
23
|
+
* ║ ║
|
|
24
|
+
* ║ All blocked symbols throw immediately on access — no silent undefined. ║
|
|
25
|
+
* ╚══════════════════════════════════════════════════════════════════════════╝
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Create a throwing stub for a forbidden API
|
|
29
|
+
*/
|
|
30
|
+
function createForbiddenStub(name) {
|
|
31
|
+
const stub = function () {
|
|
32
|
+
throw new Error(`[Code Mode Protocol Error] Forbidden API: ${name}`);
|
|
33
|
+
};
|
|
34
|
+
return new Proxy(stub, {
|
|
35
|
+
get(_target, prop) {
|
|
36
|
+
if (prop === Symbol.toPrimitive || prop === 'toString' || prop === 'valueOf') {
|
|
37
|
+
return () => { throw new Error(`[Code Mode Protocol Error] Forbidden API: ${name}`); };
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`[Code Mode Protocol Error] Forbidden API: ${name}.${String(prop)}`);
|
|
40
|
+
},
|
|
41
|
+
apply() {
|
|
42
|
+
throw new Error(`[Code Mode Protocol Error] Forbidden API: ${name}()`);
|
|
43
|
+
},
|
|
44
|
+
construct() {
|
|
45
|
+
throw new Error(`[Code Mode Protocol Error] Forbidden API: new ${name}()`);
|
|
46
|
+
},
|
|
47
|
+
set() {
|
|
48
|
+
throw new Error(`[Code Mode Protocol Error] Forbidden API: ${name} (assignment blocked)`);
|
|
49
|
+
},
|
|
50
|
+
has() {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a frozen object that throws on any property access
|
|
57
|
+
*/
|
|
58
|
+
function createForbiddenObject(name) {
|
|
59
|
+
return new Proxy({}, {
|
|
60
|
+
get(_target, prop) {
|
|
61
|
+
if (prop === Symbol.toPrimitive || prop === 'toString' || prop === 'valueOf') {
|
|
62
|
+
return () => { throw new Error(`[Code Mode Protocol Error] Forbidden API: ${name}`); };
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`[Code Mode Protocol Error] Forbidden API: ${name}.${String(prop)}`);
|
|
65
|
+
},
|
|
66
|
+
set() {
|
|
67
|
+
throw new Error(`[Code Mode Protocol Error] Forbidden API: ${name} (assignment blocked)`);
|
|
68
|
+
},
|
|
69
|
+
has() {
|
|
70
|
+
return true;
|
|
71
|
+
},
|
|
72
|
+
apply() {
|
|
73
|
+
throw new Error(`[Code Mode Protocol Error] Forbidden API: ${name}()`);
|
|
74
|
+
},
|
|
75
|
+
construct() {
|
|
76
|
+
throw new Error(`[Code Mode Protocol Error] Forbidden API: new ${name}()`);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Forbidden APIs - these are injected into the execution scope to override globals
|
|
82
|
+
*/
|
|
83
|
+
export const FORBIDDEN_APIS = {
|
|
84
|
+
Date: createForbiddenStub('Date'),
|
|
85
|
+
performance: createForbiddenObject('performance'),
|
|
86
|
+
process: createForbiddenObject('process'),
|
|
87
|
+
navigator: createForbiddenObject('navigator'),
|
|
88
|
+
globalThis: createForbiddenObject('globalThis'),
|
|
89
|
+
crypto: createForbiddenObject('crypto'),
|
|
90
|
+
setTimeout: createForbiddenStub('setTimeout'),
|
|
91
|
+
setInterval: createForbiddenStub('setInterval'),
|
|
92
|
+
clearTimeout: createForbiddenStub('clearTimeout'),
|
|
93
|
+
clearInterval: createForbiddenStub('clearInterval'),
|
|
94
|
+
requestAnimationFrame: createForbiddenStub('requestAnimationFrame'),
|
|
95
|
+
cancelAnimationFrame: createForbiddenStub('cancelAnimationFrame'),
|
|
96
|
+
fetch: createForbiddenStub('fetch'),
|
|
97
|
+
XMLHttpRequest: createForbiddenStub('XMLHttpRequest'),
|
|
98
|
+
WebSocket: createForbiddenStub('WebSocket'),
|
|
99
|
+
document: createForbiddenObject('document'),
|
|
100
|
+
window: createForbiddenObject('window'),
|
|
101
|
+
self: createForbiddenObject('self'),
|
|
102
|
+
top: createForbiddenObject('top'),
|
|
103
|
+
parent: createForbiddenObject('parent'),
|
|
104
|
+
frames: createForbiddenObject('frames'),
|
|
105
|
+
location: createForbiddenObject('location'),
|
|
106
|
+
history: createForbiddenObject('history'),
|
|
107
|
+
localStorage: createForbiddenObject('localStorage'),
|
|
108
|
+
sessionStorage: createForbiddenObject('sessionStorage'),
|
|
109
|
+
indexedDB: createForbiddenObject('indexedDB'),
|
|
110
|
+
caches: createForbiddenObject('caches'),
|
|
111
|
+
Notification: createForbiddenStub('Notification'),
|
|
112
|
+
Worker: createForbiddenStub('Worker'),
|
|
113
|
+
SharedWorker: createForbiddenStub('SharedWorker'),
|
|
114
|
+
ServiceWorker: createForbiddenObject('ServiceWorker'),
|
|
115
|
+
Blob: createForbiddenStub('Blob'),
|
|
116
|
+
File: createForbiddenStub('File'),
|
|
117
|
+
FileReader: createForbiddenStub('FileReader'),
|
|
118
|
+
URL: createForbiddenStub('URL'),
|
|
119
|
+
URLSearchParams: createForbiddenStub('URLSearchParams'),
|
|
120
|
+
Headers: createForbiddenStub('Headers'),
|
|
121
|
+
Request: createForbiddenStub('Request'),
|
|
122
|
+
Response: createForbiddenStub('Response'),
|
|
123
|
+
EventSource: createForbiddenStub('EventSource'),
|
|
124
|
+
Image: createForbiddenStub('Image'),
|
|
125
|
+
Audio: createForbiddenStub('Audio'),
|
|
126
|
+
Video: createForbiddenStub('Video'),
|
|
127
|
+
eval: createForbiddenStub('eval'),
|
|
128
|
+
Function: createForbiddenStub('Function'),
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Create a safe Math object with random() blocked
|
|
132
|
+
*/
|
|
133
|
+
export function createSafeMath() {
|
|
134
|
+
const safeMath = Object.create(Math);
|
|
135
|
+
Object.defineProperty(safeMath, 'random', {
|
|
136
|
+
get() {
|
|
137
|
+
throw new Error('[Code Mode Protocol Error] Forbidden API: Math.random() — use random() instead (seeded)');
|
|
138
|
+
},
|
|
139
|
+
configurable: false,
|
|
140
|
+
enumerable: true
|
|
141
|
+
});
|
|
142
|
+
return Object.freeze(safeMath);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* List of all forbidden API names for documentation
|
|
146
|
+
*/
|
|
147
|
+
export const FORBIDDEN_API_NAMES = Object.keys(FORBIDDEN_APIS);
|
|
148
|
+
/**
|
|
149
|
+
* Build the complete sandbox context for sketch execution.
|
|
150
|
+
* This includes the p5 runtime plus all forbidden API stubs.
|
|
151
|
+
*/
|
|
152
|
+
export function buildSandboxContext(p5Runtime) {
|
|
153
|
+
const safeMath = createSafeMath();
|
|
154
|
+
const context = {
|
|
155
|
+
...FORBIDDEN_APIS,
|
|
156
|
+
Math: safeMath,
|
|
157
|
+
};
|
|
158
|
+
for (const key of Object.keys(p5Runtime)) {
|
|
159
|
+
context[key] = p5Runtime[key];
|
|
160
|
+
}
|
|
161
|
+
return context;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Create a sandboxed function that executes user code with blocked globals.
|
|
165
|
+
*
|
|
166
|
+
* The function is constructed with:
|
|
167
|
+
* 1. All forbidden APIs as explicit parameters (override globals)
|
|
168
|
+
* 2. The p5 runtime as explicit parameters
|
|
169
|
+
* 3. A `with(context)` wrapper for additional safety
|
|
170
|
+
*/
|
|
171
|
+
export function createSandboxedExecutor(code, additionalParams = []) {
|
|
172
|
+
const forbiddenParamNames = Object.keys(FORBIDDEN_APIS);
|
|
173
|
+
const allParams = [
|
|
174
|
+
'context',
|
|
175
|
+
'Math',
|
|
176
|
+
...forbiddenParamNames,
|
|
177
|
+
...additionalParams
|
|
178
|
+
];
|
|
179
|
+
const wrappedCode = `
|
|
180
|
+
"use strict";
|
|
181
|
+
with(context) {
|
|
182
|
+
${code}
|
|
183
|
+
}
|
|
184
|
+
`;
|
|
185
|
+
return new Function(...allParams, wrappedCode);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Execute user code in a sandboxed environment.
|
|
189
|
+
*
|
|
190
|
+
* @param code - The user sketch code to execute
|
|
191
|
+
* @param p5Runtime - The p5-like runtime object
|
|
192
|
+
* @param additionalContext - Additional context variables (frameCount, t, etc.)
|
|
193
|
+
*/
|
|
194
|
+
export function executeSandboxed(code, p5Runtime, additionalContext = {}) {
|
|
195
|
+
const safeMath = createSafeMath();
|
|
196
|
+
const fullContext = {
|
|
197
|
+
...p5Runtime,
|
|
198
|
+
...additionalContext,
|
|
199
|
+
Math: safeMath,
|
|
200
|
+
...FORBIDDEN_APIS,
|
|
201
|
+
};
|
|
202
|
+
const forbiddenValues = Object.keys(FORBIDDEN_APIS).map(key => FORBIDDEN_APIS[key]);
|
|
203
|
+
const additionalParamNames = Object.keys(additionalContext);
|
|
204
|
+
const additionalValues = Object.values(additionalContext);
|
|
205
|
+
const executor = createSandboxedExecutor(code, additionalParamNames);
|
|
206
|
+
executor(fullContext, safeMath, ...forbiddenValues, ...additionalValues);
|
|
207
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,50 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* NexArt Code Mode Runtime SDK
|
|
3
|
-
* Version: 1.1.0 (Protocol v1.0.0)
|
|
2
|
+
* NexArt Code Mode Runtime SDK - App Integration Layer
|
|
4
3
|
*
|
|
5
4
|
* ╔══════════════════════════════════════════════════════════════════════════╗
|
|
6
|
-
* ║
|
|
5
|
+
* ║ LOCAL SDK WRAPPER ║
|
|
7
6
|
* ║ ║
|
|
8
|
-
* ║ This
|
|
9
|
-
* ║
|
|
7
|
+
* ║ This file re-exports the core runtime from @nexart/codemode-sdk (npm) ║
|
|
8
|
+
* ║ and adds app-specific integrations (SoundArt, Noise, etc.) ║
|
|
10
9
|
* ║ ║
|
|
11
|
-
* ║
|
|
12
|
-
* ║
|
|
13
|
-
* ║ SDK Version: 1.1.0 ║
|
|
14
|
-
* ║ Protocol Version: 1.0.0 ║
|
|
15
|
-
* ║ Phase: 1 ║
|
|
16
|
-
* ║ Enforcement: HARD ║
|
|
10
|
+
* ║ For core Code Mode: import from '@nexart/codemode-sdk' ║
|
|
11
|
+
* ║ For app integrations: import from 'sdk/codemode' ║
|
|
17
12
|
* ╚══════════════════════════════════════════════════════════════════════════╝
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { executeCodeMode } from '@nexart/codemode-sdk';
|
|
22
|
-
*
|
|
23
|
-
* const result = await executeCodeMode({
|
|
24
|
-
* source: `function setup() { background(255); ellipse(width/2, height/2, 100); }`,
|
|
25
|
-
* width: 1950,
|
|
26
|
-
* height: 2400,
|
|
27
|
-
* seed: 12345,
|
|
28
|
-
* vars: [50, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
29
|
-
* mode: 'static'
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* console.log(result.metadata.protocolVersion); // '1.0.0'
|
|
33
|
-
* ```
|
|
34
13
|
*/
|
|
35
|
-
export { executeCodeMode, validateCodeModeSource } from '
|
|
36
|
-
export type { ExecuteCodeModeInput, ExecuteCodeModeResult, ProtocolMetadata, } from '
|
|
37
|
-
export {
|
|
14
|
+
export { executeCodeMode, validateCodeModeSource, DEFAULT_CONFIG, PROTOCOL_IDENTITY, } from '@nexart/codemode-sdk';
|
|
15
|
+
export type { ExecuteCodeModeInput, ExecuteCodeModeResult, ProtocolMetadata, RenderResult, TimeVariables, } from '@nexart/codemode-sdk';
|
|
16
|
+
export { createP5Runtime, injectTimeVariables, injectProtocolVariables, createProtocolVAR } from './p5-runtime';
|
|
17
|
+
export type { P5Runtime, P5RuntimeConfig } from './p5-runtime';
|
|
38
18
|
export { createEngine } from './engine';
|
|
39
|
-
export type { Engine, EngineConfig, RunOptions,
|
|
40
|
-
export { DEFAULT_CONFIG } from './types';
|
|
19
|
+
export type { Engine, EngineConfig, RunOptions, ProgressInfo, RenderMode, } from './types';
|
|
20
|
+
export { DEFAULT_CONFIG as LOCAL_DEFAULT_CONFIG } from './types';
|
|
41
21
|
export { renderSoundArtViaCodeMode, canRenderViaCodeMode, getCodeModeAvailableStyles, type SoundArtEngineConfig, type SoundArtRenderOptions, type SoundArtRenderResult, type SoundArtMetadata, } from './soundart-engine';
|
|
42
22
|
export { type SoundSnapshot, type SoundFeatures, createSoundSnapshot, createEmptySoundSnapshot, freezeSoundSnapshot, } from '../../shared/soundSnapshot';
|
|
43
23
|
export { injectSoundGlobals, createSoundGlobals, createEmptySoundGlobals, generateSoundPalette, inferGenreProfile, createSoundHelpers, type SoundGlobals, type GenreProfile, } from './sound-bridge';
|
|
44
24
|
export { getSoundArtSketch, getAvailableSoundArtSketches, isSoundArtSketchAvailable, type SoundArtSketchName, } from './soundart-sketches';
|
|
45
|
-
export { createP5Runtime, type P5Runtime, type P5RuntimeConfig } from './p5-runtime';
|
|
46
25
|
export { renderNoiseViaCodeMode, compileNoiseSystem, canRenderNoiseViaCodeMode, type NoiseEngineConfig, type NoiseRenderOptions, type NoiseRenderResult, type NoiseMetadata, } from './noise-engine';
|
|
47
26
|
export { type NoiseSnapshot, type NoiseParams, type NoiseBlendMode, createNoiseSnapshot, validateNoiseSnapshot, } from '../../shared/noiseSnapshot';
|
|
48
27
|
export { createNoiseGlobals, injectNoiseGlobals, type NoiseGlobals, } from './noise-bridge';
|
|
49
28
|
export { getNoiseSketch, getAvailableNoiseSketchNames, isValidNoiseSketch, type NoiseSketchName, } from './noise-sketches';
|
|
29
|
+
export { registerBuilderManifest } from './builder-manifest';
|
|
30
|
+
export type { NexArtBuilderManifest } from './types';
|
|
50
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,cAAc,EACd,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,YAAY,EACZ,aAAa,GACd,MAAM,sBAAsB,CAAC;AAO9B,OAAO,EAAE,eAAe,EAA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gB,CAAC;AAExB,OAAO,EACL,cAAc,EACd,4BAA4B,EAC5B,kBAAkB,EAClB,KAAK,eAAe,GACrB,MAAM,kBAAkB,CAAC;AAkB1B,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,55 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* NexArt Code Mode Runtime SDK
|
|
3
|
-
* Version: 1.1.0 (Protocol v1.0.0)
|
|
2
|
+
* NexArt Code Mode Runtime SDK - App Integration Layer
|
|
4
3
|
*
|
|
5
4
|
* ╔══════════════════════════════════════════════════════════════════════════╗
|
|
6
|
-
* ║
|
|
5
|
+
* ║ LOCAL SDK WRAPPER ║
|
|
7
6
|
* ║ ║
|
|
8
|
-
* ║ This
|
|
9
|
-
* ║
|
|
7
|
+
* ║ This file re-exports the core runtime from @nexart/codemode-sdk (npm) ║
|
|
8
|
+
* ║ and adds app-specific integrations (SoundArt, Noise, etc.) ║
|
|
10
9
|
* ║ ║
|
|
11
|
-
* ║
|
|
12
|
-
* ║
|
|
13
|
-
* ║ SDK Version: 1.1.0 ║
|
|
14
|
-
* ║ Protocol Version: 1.0.0 ║
|
|
15
|
-
* ║ Phase: 1 ║
|
|
16
|
-
* ║ Enforcement: HARD ║
|
|
10
|
+
* ║ For core Code Mode: import from '@nexart/codemode-sdk' ║
|
|
11
|
+
* ║ For app integrations: import from 'sdk/codemode' ║
|
|
17
12
|
* ╚══════════════════════════════════════════════════════════════════════════╝
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { executeCodeMode } from '@nexart/codemode-sdk';
|
|
22
|
-
*
|
|
23
|
-
* const result = await executeCodeMode({
|
|
24
|
-
* source: `function setup() { background(255); ellipse(width/2, height/2, 100); }`,
|
|
25
|
-
* width: 1950,
|
|
26
|
-
* height: 2400,
|
|
27
|
-
* seed: 12345,
|
|
28
|
-
* vars: [50, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
29
|
-
* mode: 'static'
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* console.log(result.metadata.protocolVersion); // '1.0.0'
|
|
33
|
-
* ```
|
|
34
13
|
*/
|
|
35
14
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
36
|
-
//
|
|
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
|
|
37
22
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
38
|
-
export {
|
|
39
|
-
export { PROTOCOL_IDENTITY } from './types';
|
|
23
|
+
export { createP5Runtime, injectTimeVariables, injectProtocolVariables, createProtocolVAR } from './p5-runtime';
|
|
40
24
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
41
|
-
// LEGACY ENGINE API (
|
|
25
|
+
// LEGACY ENGINE API (kept for backwards compatibility)
|
|
42
26
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
43
27
|
export { createEngine } from './engine';
|
|
44
|
-
export { DEFAULT_CONFIG } from './types';
|
|
28
|
+
export { DEFAULT_CONFIG as LOCAL_DEFAULT_CONFIG } from './types';
|
|
45
29
|
// SoundArt → Code Mode integration
|
|
46
30
|
export { renderSoundArtViaCodeMode, canRenderViaCodeMode, getCodeModeAvailableStyles, } from './soundart-engine';
|
|
47
31
|
export { createSoundSnapshot, createEmptySoundSnapshot, freezeSoundSnapshot, } from '../../shared/soundSnapshot';
|
|
48
32
|
export { injectSoundGlobals, createSoundGlobals, createEmptySoundGlobals, generateSoundPalette, inferGenreProfile, createSoundHelpers, } from './sound-bridge';
|
|
49
33
|
export { getSoundArtSketch, getAvailableSoundArtSketches, isSoundArtSketchAvailable, } from './soundart-sketches';
|
|
50
|
-
export { createP5Runtime } from './p5-runtime';
|
|
51
34
|
// Noise → Code Mode integration
|
|
52
35
|
export { renderNoiseViaCodeMode, compileNoiseSystem, canRenderNoiseViaCodeMode, } from './noise-engine';
|
|
53
36
|
export { createNoiseSnapshot, validateNoiseSnapshot, } from '../../shared/noiseSnapshot';
|
|
54
37
|
export { createNoiseGlobals, injectNoiseGlobals, } from './noise-bridge';
|
|
55
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.
|
package/dist/loop-engine.d.ts
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Determinism Guarantee:
|
|
14
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.
|
|
15
18
|
*/
|
|
16
19
|
import type { EngineConfig, RunOptions } from './types';
|
|
17
20
|
export declare function cancelLoopMode(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop-engine.d.ts","sourceRoot":"","sources":["../loop-engine.ts"],"names":[],"mappings":"AAAA
|
|
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"}
|
package/dist/loop-engine.js
CHANGED
|
@@ -12,9 +12,13 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Determinism Guarantee:
|
|
14
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.
|
|
15
18
|
*/
|
|
16
19
|
import { DEFAULT_CONFIG } from './types';
|
|
17
20
|
import { createP5Runtime, injectProtocolVariables } from './p5-runtime';
|
|
21
|
+
import { FORBIDDEN_APIS, createSafeMath } from './execution-sandbox';
|
|
18
22
|
let isCancelled = false;
|
|
19
23
|
export function cancelLoopMode() {
|
|
20
24
|
isCancelled = true;
|
|
@@ -72,16 +76,22 @@ export async function runLoopMode(config, options) {
|
|
|
72
76
|
}
|
|
73
77
|
// Inject totalFrames into runtime
|
|
74
78
|
p.totalFrames = totalFrames;
|
|
75
|
-
// Create
|
|
76
|
-
|
|
77
|
-
const
|
|
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]);
|
|
78
88
|
onProgress?.({
|
|
79
89
|
phase: 'setup',
|
|
80
90
|
percent: 10,
|
|
81
91
|
message: 'Executing setup()...',
|
|
82
92
|
});
|
|
83
|
-
// Execute setup() once with time = 0, VAR, and
|
|
84
|
-
wrappedSetup(p, 0, 0, 0, 0, p.VAR, totalFrames);
|
|
93
|
+
// Execute setup() once with time = 0, VAR, totalFrames, and sandboxed context
|
|
94
|
+
wrappedSetup(p, 0, 0, 0, 0, p.VAR, totalFrames, safeMath, ...forbiddenValues);
|
|
85
95
|
// Capture frames
|
|
86
96
|
const frames = [];
|
|
87
97
|
onProgress?.({
|
|
@@ -108,8 +118,8 @@ export async function runLoopMode(config, options) {
|
|
|
108
118
|
// 2. Reset blend mode to NORMAL (Protocol v1.1 requirement)
|
|
109
119
|
// Prevents blend mode state from persisting across frames
|
|
110
120
|
p.blendMode('NORMAL');
|
|
111
|
-
// Execute draw() with time variables, VAR, and
|
|
112
|
-
wrappedDraw(p, frame, t, time, t, p.VAR, totalFrames);
|
|
121
|
+
// Execute draw() with time variables, VAR, totalFrames, and sandboxed context
|
|
122
|
+
wrappedDraw(p, frame, t, time, t, p.VAR, totalFrames, safeMath, ...forbiddenValues);
|
|
113
123
|
// Capture frame as PNG blob
|
|
114
124
|
const blob = await new Promise((resolve, reject) => {
|
|
115
125
|
canvas.toBlob((b) => b ? resolve(b) : reject(new Error(`Failed to capture frame ${frame}`)), 'image/png');
|
package/dist/p5-runtime.d.ts
CHANGED
|
@@ -49,7 +49,8 @@ export interface P5Runtime {
|
|
|
49
49
|
export interface P5RuntimeConfig {
|
|
50
50
|
seed?: number;
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
type RuntimeCanvas = HTMLCanvasElement;
|
|
53
|
+
export declare function createP5Runtime(canvas: RuntimeCanvas, width: number, height: number, config?: P5RuntimeConfig): P5Runtime;
|
|
53
54
|
export declare function injectTimeVariables(p: P5Runtime, time: TimeVariables): void;
|
|
54
55
|
/**
|
|
55
56
|
* VAR Protocol Constants (Phase 1 — Protocol v1.0.0)
|
|
@@ -70,4 +71,5 @@ export declare const VAR_MAX = 100;
|
|
|
70
71
|
*/
|
|
71
72
|
export declare function createProtocolVAR(vars?: number[]): readonly number[];
|
|
72
73
|
export declare function injectProtocolVariables(p: P5Runtime, vars?: number[]): void;
|
|
74
|
+
export {};
|
|
73
75
|
//# sourceMappingURL=p5-runtime.d.ts.map
|
package/dist/p5-runtime.d.ts.map
CHANGED
|
@@ -1 +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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AM,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"}
|
package/dist/p5-runtime.js
CHANGED
|
@@ -93,6 +93,8 @@ function createSeededNoise(seed = 0) {
|
|
|
93
93
|
}
|
|
94
94
|
export function createP5Runtime(canvas, width, height, config) {
|
|
95
95
|
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
|
96
|
+
if (!ctx)
|
|
97
|
+
throw new Error('Failed to get 2D context');
|
|
96
98
|
let currentFill = 'rgba(255, 255, 255, 1)';
|
|
97
99
|
let currentStroke = 'rgba(0, 0, 0, 1)';
|
|
98
100
|
let strokeEnabled = true;
|