@pascal-app/geometry-script 0.0.0-stage → 1.0.4
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/LICENSE +21 -0
- package/README.md +4 -2
- package/bpy/runner.py +169 -0
- package/dist/blender-local.d.ts +16 -0
- package/dist/blender-local.d.ts.map +1 -0
- package/dist/blender-local.js +49 -0
- package/dist/blender.d.ts +30 -0
- package/dist/blender.d.ts.map +1 -0
- package/dist/blender.js +79 -0
- package/dist/compile.d.ts +34 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +783 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/sandbox-window.d.ts +2 -0
- package/dist/sandbox-window.d.ts.map +1 -0
- package/dist/sandbox-window.js +5 -0
- package/dist/sandbox-worker.d.ts +2 -0
- package/dist/sandbox-worker.d.ts.map +1 -0
- package/dist/sandbox-worker.js +52 -0
- package/dist/sandbox.d.ts +2 -0
- package/dist/sandbox.js +2 -0
- package/dist/transform.d.ts +10 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +73 -0
- package/package.json +66 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a three.js module the model wrote (`import … from 'three'`,
|
|
3
|
+
* `export const params`, `export default function build`) into a function
|
|
4
|
+
* body evaluated with the modules injected. Only the allowlisted modules
|
|
5
|
+
* resolve; anything else fails with the list of what is available.
|
|
6
|
+
*/
|
|
7
|
+
export type ModuleTable = Record<string, Record<string, unknown>>;
|
|
8
|
+
export declare function moduleKey(specifier: string): string | null;
|
|
9
|
+
export declare function transformModule(code: string, modules: ModuleTable): string;
|
|
10
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;AAKjE,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK1D;AA2BD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAmC1E"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a three.js module the model wrote (`import … from 'three'`,
|
|
3
|
+
* `export const params`, `export default function build`) into a function
|
|
4
|
+
* body evaluated with the modules injected. Only the allowlisted modules
|
|
5
|
+
* resolve; anything else fails with the list of what is available.
|
|
6
|
+
*/
|
|
7
|
+
const IMPORT_RE = /^\s*import\s+([\s\S]+?)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;
|
|
8
|
+
const SIDE_EFFECT_IMPORT_RE = /^\s*import\s+['"][^'"]+['"]\s*;?/gm;
|
|
9
|
+
export function moduleKey(specifier) {
|
|
10
|
+
if (specifier === 'three')
|
|
11
|
+
return 'three';
|
|
12
|
+
if (specifier === 'three-bvh-csg')
|
|
13
|
+
return 'three-bvh-csg';
|
|
14
|
+
const addon = specifier.match(/^three\/(?:addons|examples\/jsm)\/(?:.+\/)?([^/]+?)(?:\.js)?$/);
|
|
15
|
+
return addon ? addon[1] : null;
|
|
16
|
+
}
|
|
17
|
+
function bindingsFor(clause, moduleRef) {
|
|
18
|
+
const out = [];
|
|
19
|
+
let rest = clause.trim();
|
|
20
|
+
const namespace = rest.match(/^\*\s+as\s+([A-Za-z_$][\w$]*)$/);
|
|
21
|
+
if (namespace)
|
|
22
|
+
return `const ${namespace[1]} = ${moduleRef};`;
|
|
23
|
+
const named = rest.match(/\{([\s\S]*)\}/);
|
|
24
|
+
if (named) {
|
|
25
|
+
const specs = named[1]
|
|
26
|
+
.split(',')
|
|
27
|
+
.map((s) => s.trim())
|
|
28
|
+
.filter(Boolean)
|
|
29
|
+
.map((s) => {
|
|
30
|
+
const [imported, local] = s.split(/\s+as\s+/).map((p) => p.trim());
|
|
31
|
+
return local ? `${imported}: ${local}` : imported;
|
|
32
|
+
});
|
|
33
|
+
out.push(`const { ${specs.join(', ')} } = ${moduleRef};`);
|
|
34
|
+
rest = rest.replace(named[0], '').replace(/,\s*$/, '').replace(/^\s*,/, '').trim();
|
|
35
|
+
}
|
|
36
|
+
const defaultName = rest.replace(/,$/, '').trim();
|
|
37
|
+
if (defaultName) {
|
|
38
|
+
out.push(`const ${defaultName} = ${moduleRef}.default ?? ${moduleRef};`);
|
|
39
|
+
}
|
|
40
|
+
return out.join(' ');
|
|
41
|
+
}
|
|
42
|
+
export function transformModule(code, modules) {
|
|
43
|
+
const unknown = [];
|
|
44
|
+
let body = code.replace(IMPORT_RE, (_all, clause, specifier) => {
|
|
45
|
+
const key = moduleKey(specifier);
|
|
46
|
+
if (!key || !(key in modules)) {
|
|
47
|
+
unknown.push(specifier);
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
return bindingsFor(clause, `__modules[${JSON.stringify(key)}]`);
|
|
51
|
+
});
|
|
52
|
+
body = body.replace(SIDE_EFFECT_IMPORT_RE, '');
|
|
53
|
+
if (unknown.length > 0) {
|
|
54
|
+
const available = Object.keys(modules)
|
|
55
|
+
.map((key) => (key === 'three' || key === 'three-bvh-csg' ? key : `three/addons/…/${key}.js`))
|
|
56
|
+
.join(', ');
|
|
57
|
+
throw new Error(`Unsupported import ${unknown.join(', ')}. Available: ${available}.`);
|
|
58
|
+
}
|
|
59
|
+
body = body
|
|
60
|
+
.replace(/export\s+default\s+(async\s+)?function\s*\*?\s*([A-Za-z_$][\w$]*)?\s*\(/, (_m, a, n) => n ? `const __default = ${a ?? ''}function ${n}(` : `const __default = ${a ?? ''}function (`)
|
|
61
|
+
.replace(/export\s+default\s+/, 'const __default = ')
|
|
62
|
+
.replace(/export\s+(const|let|var|function|class)\s/g, '$1 ')
|
|
63
|
+
.replace(/export\s*\{[^}]*\}\s*;?/g, '');
|
|
64
|
+
// A block scope lets `import * as THREE from 'three'` shadow the injected THREE.
|
|
65
|
+
return `{
|
|
66
|
+
${body}
|
|
67
|
+
return {
|
|
68
|
+
build: typeof __default !== 'undefined' ? __default : typeof build !== 'undefined' ? build : undefined,
|
|
69
|
+
params: typeof params !== 'undefined' ? params : undefined,
|
|
70
|
+
mount: typeof mount !== 'undefined' ? mount : undefined,
|
|
71
|
+
};
|
|
72
|
+
}`;
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pascal-app/geometry-script",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "Compiles AI-authored three.js and Blender (bpy) geometry scripts into GLB artifacts with a Pascal manifest. Runs in a browser worker, Bun or Node — no DOM, no React.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./compile": {
|
|
15
|
+
"types": "./dist/compile.d.ts",
|
|
16
|
+
"import": "./dist/compile.js",
|
|
17
|
+
"default": "./dist/compile.js"
|
|
18
|
+
},
|
|
19
|
+
"./sandbox": {
|
|
20
|
+
"types": "./dist/sandbox.d.ts",
|
|
21
|
+
"import": "./dist/sandbox.js",
|
|
22
|
+
"default": "./dist/sandbox.js"
|
|
23
|
+
},
|
|
24
|
+
"./blender": {
|
|
25
|
+
"types": "./dist/blender.d.ts",
|
|
26
|
+
"import": "./dist/blender.js",
|
|
27
|
+
"default": "./dist/blender.js"
|
|
28
|
+
},
|
|
29
|
+
"./blender-local": {
|
|
30
|
+
"types": "./dist/blender-local.d.ts",
|
|
31
|
+
"import": "./dist/blender-local.js",
|
|
32
|
+
"default": "./dist/blender-local.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"bpy",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc --build && bun ../../scripts/fix-node-esm-imports.ts dist && bun scripts/build-sandbox.ts",
|
|
42
|
+
"dev": "tsgo --build --watch",
|
|
43
|
+
"check-types": "tsgo --noEmit",
|
|
44
|
+
"prepublishOnly": "npm run build",
|
|
45
|
+
"test": "bun test"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@pascal-app/core": "^1.0.4",
|
|
49
|
+
"three-bvh-csg": "^0.0.18"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"three": "^0.186"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@pascal/typescript-config": "*",
|
|
56
|
+
"@types/bun": "^1.4.2",
|
|
57
|
+
"@types/three": "^0.184.0",
|
|
58
|
+
"typescript": "6.0.3"
|
|
59
|
+
},
|
|
60
|
+
"repository": {
|
|
61
|
+
"type": "git",
|
|
62
|
+
"url": "git+https://github.com/pascalorg/editor.git",
|
|
63
|
+
"directory": "packages/geometry-script"
|
|
64
|
+
},
|
|
65
|
+
"license": "MIT",
|
|
66
|
+
"homepage": "https://github.com/pascalorg/editor/tree/main/packages/geometry-script#readme",
|
|
67
|
+
"bugs": "https://github.com/pascalorg/editor/issues"
|
|
68
|
+
}
|