@mulmoclaude/shapescript-plugin 1.2.0 → 1.4.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 (46) hide show
  1. package/README.md +19 -0
  2. package/dist/core/dispatch.d.ts +8 -3
  3. package/dist/core/dispatch.d.ts.map +1 -1
  4. package/dist/core/index.d.ts +5 -2
  5. package/dist/core/index.d.ts.map +1 -1
  6. package/dist/core/paths.d.ts +5 -0
  7. package/dist/core/paths.d.ts.map +1 -1
  8. package/dist/core-CpVzK-0i.js +53 -0
  9. package/dist/core-bcFgqR_m.cjs +1 -0
  10. package/dist/core.cjs +1 -1
  11. package/dist/core.js +4 -3
  12. package/dist/export/tool.d.ts +45 -0
  13. package/dist/export/tool.d.ts.map +1 -0
  14. package/dist/export/usdz.d.ts +17 -0
  15. package/dist/export/usdz.d.ts.map +1 -0
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.js +4 -4
  18. package/dist/lang/de.d.ts.map +1 -1
  19. package/dist/lang/en.d.ts.map +1 -1
  20. package/dist/lang/es.d.ts.map +1 -1
  21. package/dist/lang/fr.d.ts.map +1 -1
  22. package/dist/lang/ja.d.ts.map +1 -1
  23. package/dist/lang/ko.d.ts.map +1 -1
  24. package/dist/lang/messages.d.ts +2 -0
  25. package/dist/lang/messages.d.ts.map +1 -1
  26. package/dist/lang/ptBR.d.ts.map +1 -1
  27. package/dist/lang/zh.d.ts.map +1 -1
  28. package/dist/render/index.d.ts +2 -0
  29. package/dist/render/index.d.ts.map +1 -1
  30. package/dist/render/renderer.d.ts +11 -0
  31. package/dist/render/renderer.d.ts.map +1 -1
  32. package/dist/render/tool.d.ts +118 -0
  33. package/dist/render/tool.d.ts.map +1 -0
  34. package/dist/render.cjs +2 -2
  35. package/dist/render.js +115 -11
  36. package/dist/samples-DPOGWslc.js +1038 -0
  37. package/dist/samples-DZNAeuSZ.cjs +210 -0
  38. package/dist/style.css +1 -1
  39. package/dist/{toThreeJS-B5LiF110.js → toThreeJS-BX_aeGdA.js} +18 -18
  40. package/dist/{toThreeJS-BOBpx5Dc.cjs → toThreeJS-XGDoVISb.cjs} +1 -1
  41. package/dist/vue/View.vue.d.ts.map +1 -1
  42. package/dist/vue.cjs +16 -16
  43. package/dist/vue.js +1760 -1716
  44. package/package.json +1 -1
  45. package/dist/samples-DHEKUNs5.cjs +0 -186
  46. package/dist/samples-SaXsqbHJ.js +0 -180
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulmoclaude/shapescript-plugin",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "presentShapeScript \u2014 interactive 3D visualizations authored in the ShapeScript language (parser + Three.js renderer). Core (tool definition + execute) on `.`, Vue View/Preview on `./vue`.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,186 +0,0 @@
1
- const e=require("./toThreeJS-BOBpx5Dc.cjs");let t=require("@mulmoclaude/core/artifacts");var n=`presentShapeScript`,r={type:`function`,name:n,description:"Display interactive 3D visualizations using ShapeScript with expressions, variables, control flow, and functions. A new `script` is saved to `artifacts/shapes/` and the returned `filePath` names it; pass `path` instead to present a source that already exists.",parameters:{type:`object`,properties:{title:{type:`string`,description:`Title for the 3D visualization`},script:{type:`string`,description:`ShapeScript code defining the 3D scene. Supported features and syntax are listed below. Syntax, evaluation, geometry and resource-limit errors are returned as diagnostics; correct the script and retry.
2
-
3
- ## SYNTAX OVERVIEW:
4
-
5
- ### Expressions & Operators:
6
- - Arithmetic: +, -, *, /, % with proper precedence
7
- - Comparison: =, <>, <, <=, >, >=
8
- - Boolean: and, or, not
9
- - Parentheses for grouping: (2 + 3) * 4
10
-
11
- ### Variables:
12
- define radius 2
13
- define red (1 0 0)
14
- sphere { size radius color red }
15
-
16
- ### Control Flow:
17
-
18
- For loops with variables:
19
- for i in 1 to 5 {
20
- cube { position (i * 2) 0 0 size 1 }
21
- }
22
-
23
- For loops with step:
24
- for i in 0 to 10 step 2 {
25
- sphere { position 0 i 0 }
26
- }
27
-
28
- If/else conditionals:
29
- define showSphere 1
30
- if showSphere {
31
- sphere { size 2 }
32
- } else {
33
- cube { size 2 }
34
- }
35
-
36
- Switch statements:
37
- define shape 2
38
- switch shape {
39
- case 1
40
- cube
41
- case 2
42
- sphere
43
- else
44
- cone
45
- }
46
-
47
- ### Built-in Functions:
48
-
49
- Math: round, floor, ceil, abs, sign, sqrt, pow, min, max
50
- Trig: sin, cos, tan, asin, acos, atan, atan2 (uses radians)
51
- Vector: dot, cross, length, normalize, sum
52
-
53
- IMPORTANT: Function calls require NO space between name and parenthesis:
54
- - sin(x) ✓ function call
55
- - sin (x) ✗ NOT a function call (identifier + parenthesized expression)
56
-
57
- Examples:
58
- for i in 1 to 8 {
59
- define angle (i * 0.785) // 45 degrees in radians
60
- cube { position (cos(angle) * 3) 0 (sin(angle) * 3) }
61
- }
62
-
63
- ### Primitives & Properties:
64
-
65
- Shapes: cube, sphere, cylinder, cone, torus, circle, square, polygon (sides 3–256)
66
- Properties: position X Y Z, rotation X Y Z, size X Y Z
67
- Materials: color R G B (0-1), opacity (0-1)
68
-
69
- ### CSG Operations:
70
- union, difference, intersection, xor, stencil
71
-
72
- Example:
73
- difference {
74
- sphere { size 2 color (1 0.5 0) }
75
- cube { size 1.5 }
76
- }
77
-
78
- ### Builders:
79
- - extrude: extrude { polygon { sides 3 } } or extrude path { point 0 0 point 1 0 point 0 1 }
80
- - fill: fill { square } or fill path { ... }
81
- - lathe: lathe path { point 1 0 curve 0 2 1 -1 } (revolves about Y)
82
- - loft: loft { square translate 0 0 2 circle } (closed planar sections joined with caps)
83
- - hull: hull { cube { position -1 0 0 } cube { position 1 0 0 } } (convex envelope)
84
- - stencil preserves the first shape and paints its surface with later shapes' materials.
85
- Loft sections must each have one perimeter and enclose an area; extrude/fill primitive profiles must lie in XY.
86
-
87
- ### Additional Expressions:
88
- - Constants: pi, tau, true, false
89
- - Scientific notation and unary plus: 1e-3, +2
90
- - Tuple/vector members: vector.x, vector.y, vector.z; color.red/green/blue/alpha
91
- - Tuple/string length: value.count; zero-based indexing: values[0]
92
- - String literals, join(...), trim(...); min/max also accept tuples
93
- - Custom shapes with options:
94
- define post { option height 2 cylinder { size 0.2 height } }
95
- post { height 3 }
96
-
97
- ### Compatibility:
98
- This plugin implements the documented modeling subset, not all upstream ShapeScript syntax.
99
- Function calls use name(...); trig functions and rotation/orientation properties use radians.
100
- Relative rotate/orientation commands and path rotate use turns (1 = 360 degrees).
101
- Path point/curve coordinates are relative steps. Curves accept optional control-point offsets.
102
- Imports, textures, text/fonts, arbitrary objects, and general user-defined functions are not supported.
103
-
104
- ### Comments:
105
- // Single-line comment
106
- /* Multi-line
107
- comment */
108
-
109
- ## COMPLETE EXAMPLES:
110
-
111
- Linear arrangement with expressions:
112
- define spacing 1.5
113
- for i in 1 to 4 {
114
- cylinder { position ((i - 2.5) * spacing) 0 0 size 0.4 1 }
115
- }
116
-
117
- Circular pattern:
118
- define count 12
119
- for i in 1 to count {
120
- define angle ((i / count) * 6.283) // 2 * PI
121
- cube {
122
- position (cos(angle) * 3) 0 (sin(angle) * 3)
123
- color (i / count) 0.5 (1 - i / count)
124
- size 0.5
125
- }
126
- }
127
-
128
- Conditional geometry:
129
- define makeHollow 1
130
- if makeHollow {
131
- difference {
132
- sphere { size 2 color (1 0 0) }
133
- sphere { size 1.7 }
134
- }
135
- } else {
136
- sphere { size 2 color (1 0 0) }
137
- }
138
-
139
- Mathematical visualization:
140
- for x in -5 to 5 {
141
- for z in -5 to 5 {
142
- define height (sin(x * 0.5) * cos(z * 0.5) * 2)
143
- cube {
144
- position (x * 0.3) height (z * 0.3)
145
- size 0.25 (abs(height) + 0.1) 0.25
146
- color (0.5 + height * 0.25) 0.3 (0.5 - height * 0.25)
147
- }
148
- }
149
- }`},path:{type:`string`,description:"Path to an EXISTING ShapeScript source to present in place, instead of `script` — a `.shape` file this tool saved earlier (`artifacts/shapes/…`) or any other on disk. Provide either `script` or `path`, never both. Edits the user makes in the view write back to that same file."}},required:[`title`]}},i=`shapes`,a=`shape`,o=[`.shape`];function s(){let e=globalThis.crypto;if(e?.getRandomValues){let t=e.getRandomValues(new Uint8Array(4));return Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}return Math.random().toString(16).slice(2,10).padEnd(8,`0`)}function c(e,n=new Date,r=s()){let o=(0,t.buildArtifactRelPath)({dir:i,title:e,ext:`.shape`,fallback:a,now:n,partitioned:!1,suffix:r});return{relPath:o,filePath:(0,t.toWorkspaceArtifactPath)(o)}}function l(e){return!e.startsWith(`${t.ARTIFACTS_ROOT}/${i}/`)||!e.endsWith(`.shape`)?!1:!(0,t.hasUnsafePathSegment)(e)}function u(e){return e.startsWith(`${t.ARTIFACTS_ROOT}/`)?e.slice(t.ARTIFACTS_ROOT.length+1):e}function d(e){return(0,t.classifyFilePath)(e,o)!==null}function f(e,t){if(l(t))return{files:e.files.artifacts,rel:u(t)};let n=e.files.byPath;return n&&d(t)?{files:n,rel:t}:null}async function p(e,t){if(typeof t?.path!=`string`)throw Error(`path must be an existing .shape file`);let n=f(e,t.path);if(!n)throw Error(`path must be an existing .shape file`);switch(t.kind){case`loadShape`:return{script:await n.files.read(n.rel)};case`saveShape`:if(typeof t.script!=`string`)throw Error("saveShape requires `script` as a string");if(!await n.files.exists(n.rel))throw Error(`No ShapeScript exists at ${t.path}`);return await n.files.write(n.rel,t.script),{path:t.path};default:throw Error(`shapescript plugin: unknown dispatch kind ${JSON.stringify(t)}`)}}var m=`Acknowledge that the 3D visualization has been created and is displayed to the user. They can rotate, zoom, and pan the camera.`,h=e=>typeof e==`string`&&e.trim()!==``;function g(t){e.r(e.n(e.Pn(t)))}async function _(e,t){let n=e.files;if(!n)throw Error("This host cannot open a ShapeScript by path — pass the source as `script` instead");let r=f({files:n},t);if(!r)throw Error("`path` must be a .shape file, without `.` / `..` segments");if(!await r.files.exists(r.rel))throw Error(`No ShapeScript exists at ${t}`);return r.files.read(r.rel)}var v=5;async function y(e,t,n){let r=e.files?.artifacts;if(r){for(let e=0;e<v;e++){let{relPath:e,filePath:i}=c(n);if(!await r.exists(e))return await r.write(e,t),i}throw Error(`Could not allocate a free path under artifacts/shapes — try again with a different title`)}}async function b(e,t){if(h(t.path)&&h(t.script))throw Error("Provide either `script` or `path`, not both");if(h(t.path))return{script:await _(e,t.path),filePath:t.path};if(!h(t.script))throw Error(`ShapeScript code is required but was not provided`);return{script:t.script}}var x=async(t,n)=>{let r=`INVALID_ARGUMENT`;try{if(!e.In(n))throw Error("presentShapeScript args must be an object with `script` or `path`");if(!h(n.title))throw Error(`A nonempty visualization title is required`);let i=await b(t??{},n);r=`EVALUATION_ERROR`,g(i.script);let a=i.filePath??await y(t??{},i.script,n.title);return{message:a?`Saved ShapeScript to ${a}`:`Created 3D visualization: ${n.title}`,title:n.title,data:a?{script:i.script,filePath:a}:{script:i.script},instructions:m}}catch(t){let n={code:t instanceof e.Fn?`PARSE_ERROR`:t instanceof e.t?`LIMIT_EXCEEDED`:r,message:t instanceof Error?t.message:String(t),...t instanceof e.Fn&&t.line!==void 0?{line:t.line}:{},...t instanceof e.Fn&&t.column!==void 0?{column:t.column}:{}};return{message:`ShapeScript error: ${n.message}`,error:n,jsonData:{error:n},instructions:`The visualization was not created. Correct the ShapeScript using the returned diagnostic and call presentShapeScript again.`}}},S={toolDefinition:r,execute:x,generatingMessage:`Creating 3D visualization...`,waitingMessage:`Tell the user that the 3D visualization was created and will be presented shortly.`,isEnabled:()=>!0},C=x,w=[{name:`Basic Shapes`,args:{title:`Basic 3D Shapes`,script:`// Basic shapes demonstration
150
- cube { position -2 0 0 size 1 color (1 0.3 0.3) }
151
- sphere { position 0 0 0 size 1 color (0.3 1 0.3) }
152
- cylinder { position 2 0 0 size 0.5 1 color (0.3 0.3 1) }`}},{name:`Circular Pattern`,args:{title:`Circular Pattern`,script:`// 12個の立方体を円形に配置
153
-
154
- define count 12
155
- define radius 3
156
-
157
- for i in 1 to count {
158
- // 各立方体の角度を計算(2 * PI = 6.283ラジアン)
159
- define angle ((i / count) * 6.283)
160
-
161
- // 円形配置のためのX座標とZ座標を計算
162
- define x (cos(angle) * radius)
163
- define z (sin(angle) * radius)
164
-
165
- // グラデーションカラーを作成
166
- define colorValue (i / count)
167
-
168
- cube {
169
- position x 0 z
170
- size 0.5
171
- color colorValue 0.5 (1 - colorValue)
172
- }
173
- }
174
-
175
- // 中心に参考用の球体を配置
176
- sphere {
177
- position 0 0 0
178
- size 0.3
179
- color 1 1 0
180
- opacity 0.5
181
- }`}},{name:`CSG Difference`,args:{title:`Hollow Sphere`,script:`// Create a hollow sphere using CSG difference
182
- difference {
183
- sphere { size 2 color (1 0.5 0) }
184
- sphere { size 1.7 color (1 1 1) }
185
- cube { position 0 0 2 size 2 }
186
- }`}}];Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return c}});
@@ -1,180 +0,0 @@
1
- import { Fn as e, In as t, Pn as n, n as r, r as i, t as a } from "./toThreeJS-B5LiF110.js";
2
- import { ARTIFACTS_ROOT as o, buildArtifactRelPath as s, classifyFilePath as c, hasUnsafePathSegment as l, toWorkspaceArtifactPath as u } from "@mulmoclaude/core/artifacts";
3
- //#region src/core/definition.ts
4
- var d = "presentShapeScript", f = {
5
- type: "function",
6
- name: d,
7
- description: "Display interactive 3D visualizations using ShapeScript with expressions, variables, control flow, and functions. A new `script` is saved to `artifacts/shapes/` and the returned `filePath` names it; pass `path` instead to present a source that already exists.",
8
- parameters: {
9
- type: "object",
10
- properties: {
11
- title: {
12
- type: "string",
13
- description: "Title for the 3D visualization"
14
- },
15
- script: {
16
- type: "string",
17
- description: "ShapeScript code defining the 3D scene. Supported features and syntax are listed below. Syntax, evaluation, geometry and resource-limit errors are returned as diagnostics; correct the script and retry.\n\n## SYNTAX OVERVIEW:\n\n### Expressions & Operators:\n- Arithmetic: +, -, *, /, % with proper precedence\n- Comparison: =, <>, <, <=, >, >=\n- Boolean: and, or, not\n- Parentheses for grouping: (2 + 3) * 4\n\n### Variables:\ndefine radius 2\ndefine red (1 0 0)\nsphere { size radius color red }\n\n### Control Flow:\n\nFor loops with variables:\nfor i in 1 to 5 {\n cube { position (i * 2) 0 0 size 1 }\n}\n\nFor loops with step:\nfor i in 0 to 10 step 2 {\n sphere { position 0 i 0 }\n}\n\nIf/else conditionals:\ndefine showSphere 1\nif showSphere {\n sphere { size 2 }\n} else {\n cube { size 2 }\n}\n\nSwitch statements:\ndefine shape 2\nswitch shape {\ncase 1\n cube\ncase 2\n sphere\nelse\n cone\n}\n\n### Built-in Functions:\n\nMath: round, floor, ceil, abs, sign, sqrt, pow, min, max\nTrig: sin, cos, tan, asin, acos, atan, atan2 (uses radians)\nVector: dot, cross, length, normalize, sum\n\nIMPORTANT: Function calls require NO space between name and parenthesis:\n- sin(x) ✓ function call\n- sin (x) ✗ NOT a function call (identifier + parenthesized expression)\n\nExamples:\nfor i in 1 to 8 {\n define angle (i * 0.785) // 45 degrees in radians\n cube { position (cos(angle) * 3) 0 (sin(angle) * 3) }\n}\n\n### Primitives & Properties:\n\nShapes: cube, sphere, cylinder, cone, torus, circle, square, polygon (sides 3–256)\nProperties: position X Y Z, rotation X Y Z, size X Y Z\nMaterials: color R G B (0-1), opacity (0-1)\n\n### CSG Operations:\nunion, difference, intersection, xor, stencil\n\nExample:\ndifference {\n sphere { size 2 color (1 0.5 0) }\n cube { size 1.5 }\n}\n\n### Builders:\n- extrude: extrude { polygon { sides 3 } } or extrude path { point 0 0 point 1 0 point 0 1 }\n- fill: fill { square } or fill path { ... }\n- lathe: lathe path { point 1 0 curve 0 2 1 -1 } (revolves about Y)\n- loft: loft { square translate 0 0 2 circle } (closed planar sections joined with caps)\n- hull: hull { cube { position -1 0 0 } cube { position 1 0 0 } } (convex envelope)\n- stencil preserves the first shape and paints its surface with later shapes' materials.\nLoft sections must each have one perimeter and enclose an area; extrude/fill primitive profiles must lie in XY.\n\n### Additional Expressions:\n- Constants: pi, tau, true, false\n- Scientific notation and unary plus: 1e-3, +2\n- Tuple/vector members: vector.x, vector.y, vector.z; color.red/green/blue/alpha\n- Tuple/string length: value.count; zero-based indexing: values[0]\n- String literals, join(...), trim(...); min/max also accept tuples\n- Custom shapes with options:\ndefine post { option height 2 cylinder { size 0.2 height } }\npost { height 3 }\n\n### Compatibility:\nThis plugin implements the documented modeling subset, not all upstream ShapeScript syntax.\nFunction calls use name(...); trig functions and rotation/orientation properties use radians.\nRelative rotate/orientation commands and path rotate use turns (1 = 360 degrees).\nPath point/curve coordinates are relative steps. Curves accept optional control-point offsets.\nImports, textures, text/fonts, arbitrary objects, and general user-defined functions are not supported.\n\n### Comments:\n// Single-line comment\n/* Multi-line\n comment */\n\n## COMPLETE EXAMPLES:\n\nLinear arrangement with expressions:\ndefine spacing 1.5\nfor i in 1 to 4 {\n cylinder { position ((i - 2.5) * spacing) 0 0 size 0.4 1 }\n}\n\nCircular pattern:\ndefine count 12\nfor i in 1 to count {\n define angle ((i / count) * 6.283) // 2 * PI\n cube {\n position (cos(angle) * 3) 0 (sin(angle) * 3)\n color (i / count) 0.5 (1 - i / count)\n size 0.5\n }\n}\n\nConditional geometry:\ndefine makeHollow 1\nif makeHollow {\n difference {\n sphere { size 2 color (1 0 0) }\n sphere { size 1.7 }\n }\n} else {\n sphere { size 2 color (1 0 0) }\n}\n\nMathematical visualization:\nfor x in -5 to 5 {\n for z in -5 to 5 {\n define height (sin(x * 0.5) * cos(z * 0.5) * 2)\n cube {\n position (x * 0.3) height (z * 0.3)\n size 0.25 (abs(height) + 0.1) 0.25\n color (0.5 + height * 0.25) 0.3 (0.5 - height * 0.25)\n }\n }\n}"
18
- },
19
- path: {
20
- type: "string",
21
- description: "Path to an EXISTING ShapeScript source to present in place, instead of `script` — a `.shape` file this tool saved earlier (`artifacts/shapes/…`) or any other on disk. Provide either `script` or `path`, never both. Edits the user makes in the view write back to that same file."
22
- }
23
- },
24
- required: ["title"]
25
- }
26
- }, p = "shapes", m = "shape", h = [".shape"];
27
- function g() {
28
- let e = globalThis.crypto;
29
- if (e?.getRandomValues) {
30
- let t = e.getRandomValues(/* @__PURE__ */ new Uint8Array(4));
31
- return Array.from(t, (e) => e.toString(16).padStart(2, "0")).join("");
32
- }
33
- return Math.random().toString(16).slice(2, 10).padEnd(8, "0");
34
- }
35
- function _(e, t = /* @__PURE__ */ new Date(), n = g()) {
36
- let r = s({
37
- dir: p,
38
- title: e,
39
- ext: ".shape",
40
- fallback: m,
41
- now: t,
42
- partitioned: !1,
43
- suffix: n
44
- });
45
- return {
46
- relPath: r,
47
- filePath: u(r)
48
- };
49
- }
50
- function v(e) {
51
- return !e.startsWith(`${o}/${p}/`) || !e.endsWith(".shape") ? !1 : !l(e);
52
- }
53
- function y(e) {
54
- return e.startsWith(`${o}/`) ? e.slice(o.length + 1) : e;
55
- }
56
- function b(e) {
57
- return c(e, h) !== null;
58
- }
59
- //#endregion
60
- //#region src/core/dispatch.ts
61
- function x(e, t) {
62
- if (v(t)) return {
63
- files: e.files.artifacts,
64
- rel: y(t)
65
- };
66
- let n = e.files.byPath;
67
- return n && b(t) ? {
68
- files: n,
69
- rel: t
70
- } : null;
71
- }
72
- async function S(e, t) {
73
- if (typeof t?.path != "string") throw Error("path must be an existing .shape file");
74
- let n = x(e, t.path);
75
- if (!n) throw Error("path must be an existing .shape file");
76
- switch (t.kind) {
77
- case "loadShape": return { script: await n.files.read(n.rel) };
78
- case "saveShape":
79
- if (typeof t.script != "string") throw Error("saveShape requires `script` as a string");
80
- if (!await n.files.exists(n.rel)) throw Error(`No ShapeScript exists at ${t.path}`);
81
- return await n.files.write(n.rel, t.script), { path: t.path };
82
- default: throw Error(`shapescript plugin: unknown dispatch kind ${JSON.stringify(t)}`);
83
- }
84
- }
85
- //#endregion
86
- //#region src/core/plugin.ts
87
- var C = "Acknowledge that the 3D visualization has been created and is displayed to the user. They can rotate, zoom, and pan the camera.", w = (e) => typeof e == "string" && e.trim() !== "";
88
- function T(e) {
89
- i(r(n(e)));
90
- }
91
- async function E(e, t) {
92
- let n = e.files;
93
- if (!n) throw Error("This host cannot open a ShapeScript by path — pass the source as `script` instead");
94
- let r = x({ files: n }, t);
95
- if (!r) throw Error("`path` must be a .shape file, without `.` / `..` segments");
96
- if (!await r.files.exists(r.rel)) throw Error(`No ShapeScript exists at ${t}`);
97
- return r.files.read(r.rel);
98
- }
99
- var D = 5;
100
- async function O(e, t, n) {
101
- let r = e.files?.artifacts;
102
- if (r) {
103
- for (let e = 0; e < D; e++) {
104
- let { relPath: e, filePath: i } = _(n);
105
- if (!await r.exists(e)) return await r.write(e, t), i;
106
- }
107
- throw Error("Could not allocate a free path under artifacts/shapes — try again with a different title");
108
- }
109
- }
110
- async function k(e, t) {
111
- if (w(t.path) && w(t.script)) throw Error("Provide either `script` or `path`, not both");
112
- if (w(t.path)) return {
113
- script: await E(e, t.path),
114
- filePath: t.path
115
- };
116
- if (!w(t.script)) throw Error("ShapeScript code is required but was not provided");
117
- return { script: t.script };
118
- }
119
- var A = async (n, r) => {
120
- let i = "INVALID_ARGUMENT";
121
- try {
122
- if (!t(r)) throw Error("presentShapeScript args must be an object with `script` or `path`");
123
- if (!w(r.title)) throw Error("A nonempty visualization title is required");
124
- let e = await k(n ?? {}, r);
125
- i = "EVALUATION_ERROR", T(e.script);
126
- let a = e.filePath ?? await O(n ?? {}, e.script, r.title);
127
- return {
128
- message: a ? `Saved ShapeScript to ${a}` : `Created 3D visualization: ${r.title}`,
129
- title: r.title,
130
- data: a ? {
131
- script: e.script,
132
- filePath: a
133
- } : { script: e.script },
134
- instructions: C
135
- };
136
- } catch (t) {
137
- let n = {
138
- code: t instanceof e ? "PARSE_ERROR" : t instanceof a ? "LIMIT_EXCEEDED" : i,
139
- message: t instanceof Error ? t.message : String(t),
140
- ...t instanceof e && t.line !== void 0 ? { line: t.line } : {},
141
- ...t instanceof e && t.column !== void 0 ? { column: t.column } : {}
142
- };
143
- return {
144
- message: `ShapeScript error: ${n.message}`,
145
- error: n,
146
- jsonData: { error: n },
147
- instructions: "The visualization was not created. Correct the ShapeScript using the returned diagnostic and call presentShapeScript again."
148
- };
149
- }
150
- }, j = {
151
- toolDefinition: f,
152
- execute: A,
153
- generatingMessage: "Creating 3D visualization...",
154
- waitingMessage: "Tell the user that the 3D visualization was created and will be presented shortly.",
155
- isEnabled: () => !0
156
- }, M = A, N = [
157
- {
158
- name: "Basic Shapes",
159
- args: {
160
- title: "Basic 3D Shapes",
161
- script: "// Basic shapes demonstration\ncube { position -2 0 0 size 1 color (1 0.3 0.3) }\nsphere { position 0 0 0 size 1 color (0.3 1 0.3) }\ncylinder { position 2 0 0 size 0.5 1 color (0.3 0.3 1) }"
162
- }
163
- },
164
- {
165
- name: "Circular Pattern",
166
- args: {
167
- title: "Circular Pattern",
168
- script: "// 12個の立方体を円形に配置\n\ndefine count 12\ndefine radius 3\n\nfor i in 1 to count {\n // 各立方体の角度を計算(2 * PI = 6.283ラジアン)\n define angle ((i / count) * 6.283)\n\n // 円形配置のためのX座標とZ座標を計算\n define x (cos(angle) * radius)\n define z (sin(angle) * radius)\n\n // グラデーションカラーを作成\n define colorValue (i / count)\n\n cube {\n position x 0 z\n size 0.5\n color colorValue 0.5 (1 - colorValue)\n }\n}\n\n// 中心に参考用の球体を配置\nsphere {\n position 0 0 0\n size 0.3\n color 1 1 0\n opacity 0.5\n}"
169
- }
170
- },
171
- {
172
- name: "CSG Difference",
173
- args: {
174
- title: "Hollow Sphere",
175
- script: "// Create a hollow sphere using CSG difference\ndifference {\n sphere { size 2 color (1 0.5 0) }\n sphere { size 1.7 color (1 1 1) }\n cube { position 0 0 2 size 2 }\n}"
176
- }
177
- }
178
- ];
179
- //#endregion
180
- export { S as a, b as c, y as d, f, A as i, v as l, M as n, x as o, d as p, j as r, h as s, N as t, _ as u };