@mulmoclaude/shapescript-plugin 2.5.1 → 2.6.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.
@@ -8893,7 +8893,7 @@ var Qc = class {
8893
8893
  }
8894
8894
  expectEndOfStatement() {
8895
8895
  let e = this.current(), t = this.tokens[this.pos - 1];
8896
- if (!(!t || e.type === a.NEWLINE || e.type === a.RBRACE || e.type === a.EOF || e.line !== t.line)) throw new o(`Unexpected \`${String(e.value)}\` after a statement — ShapeScript takes one statement per line; start a new line here`, e.line, e.column);
8896
+ if (t && e.type !== a.NEWLINE && e.type !== a.RBRACE && e.type !== a.EOF && e.line === t.line) throw new o(`Unexpected \`${String(e.value)}\` after a statement — ShapeScript takes one statement per line; start a new line here`, e.line, e.column);
8897
8897
  }
8898
8898
  skipNewlines() {
8899
8899
  for (; this.current().type === a.NEWLINE;) this.advance();
@@ -10454,8 +10454,7 @@ function _u(e, t, n, r, i = null, a = 0, o = 0) {
10454
10454
  let e = w(p);
10455
10455
  C = r(e, T(p) - e, !0, o + 1, a + p / 8, _);
10456
10456
  } else C = S && _u(p, t, n, r, i, a, o + 1);
10457
- if (C) return !0;
10458
- return !1;
10457
+ return !!C;
10459
10458
  function w(e) {
10460
10459
  let { uint16Array: t, uint32Array: n } = $, r = e * 2;
10461
10460
  for (; !zl(r, t);) e = Hl(e), r = e * 2;
@@ -13573,6 +13572,7 @@ var Nh = class {
13573
13572
  logs = [];
13574
13573
  background;
13575
13574
  sceneDepth = 0;
13575
+ customShapeDepth = 0;
13576
13576
  valueSink = null;
13577
13577
  retained = [];
13578
13578
  constructor(e = {}) {
@@ -13621,8 +13621,7 @@ var Nh = class {
13621
13621
  return new ti(e, t);
13622
13622
  }
13623
13623
  convertNode(e) {
13624
- if (this.nodeCount += 1, this.nodeCount > this.maxNodes) throw new Eh(`ShapeScript produced more than ${this.maxNodes} objectsreduce the loop counts or the nesting`);
13625
- if (Date.now() - this.startedAt > this.maxDurationMs) throw new Eh(`ShapeScript took longer than ${this.maxDurationMs}ms to build — simplify the model or use fewer boolean operations`);
13624
+ if (Ph.has(e.type) && this.chargeNode(), Date.now() - this.startedAt > this.maxDurationMs) throw new Eh(`ShapeScript took longer than ${this.maxDurationMs}ms to build simplify the model or use fewer boolean operations`);
13626
13625
  switch (e.type) {
13627
13626
  case "shape": return this.convertShape(e);
13628
13627
  case "csg": return this.convertCSG(e);
@@ -13645,7 +13644,7 @@ var Nh = class {
13645
13644
  case "material": return this.handleMaterialCommand(e), null;
13646
13645
  case "smoothing": return this.currentTransform().material.smoothing = this.evaluateNumber(e.value), null;
13647
13646
  case "background": return this.handleBackground(e.value), null;
13648
- case "print": return this.logs.length < Oh && this.logs.push(Bh(this.evaluator.evaluate(e.value))), null;
13647
+ case "print": return this.logs.length < Oh && this.logs.push(Uh(this.evaluator.evaluate(e.value))), null;
13649
13648
  case "assert":
13650
13649
  if (!this.evaluator.evaluateToBoolean(e.value)) throw Error("Assertion failed");
13651
13650
  return null;
@@ -13717,6 +13716,9 @@ var Nh = class {
13717
13716
  this.sceneDepth--, this.popTransform(), this.symbols.popScope();
13718
13717
  }
13719
13718
  }
13719
+ chargeNode() {
13720
+ if (this.nodeCount += 1, this.nodeCount > this.maxNodes) throw new Eh(`ShapeScript produced more than ${this.maxNodes} objects — reduce the loop counts or the nesting`);
13721
+ }
13720
13722
  addChildren(e, t) {
13721
13723
  for (let n of t) {
13722
13724
  let t = this.convertNode(n);
@@ -13760,7 +13762,7 @@ var Nh = class {
13760
13762
  return e.points === void 0 ? this.withShapeOptions(e.properties, () => {
13761
13763
  let t = this.finishMesh(this.createGeometry(e), e, !1);
13762
13764
  return yh.has(e.primitive) ? _h(t) : t;
13763
- }) : this.placeValue(this.polygonValue(e));
13765
+ }) : this.placeValue(this.polygonValue(e), { charged: !0 });
13764
13766
  }
13765
13767
  captureValues(e, t) {
13766
13768
  let n = this.valueSink;
@@ -13771,12 +13773,12 @@ var Nh = class {
13771
13773
  this.valueSink = n;
13772
13774
  }
13773
13775
  }
13774
- placeValue(e) {
13776
+ placeValue(e, { charged: t = !1 } = {}) {
13775
13777
  if (this.valueSink) return this.valueSink.push(this.transformedForCapture(e)), null;
13776
- if (_c(e) && e.kind === "mesh") return this.placeMesh(e);
13778
+ if (!t && Rh(e) && this.chargeNode(), _c(e) && e.kind === "mesh") return this.placeMesh(e);
13777
13779
  if (_c(e) && e.kind === "polygon") return this.placePolygons([e]);
13778
13780
  if (Array.isArray(e) && e.length > 0 && e.every((e) => _c(e) && (e.kind === "mesh" || e.kind === "polygon"))) {
13779
- let t = e.filter((e) => _c(e) && e.kind === "mesh"), n = e.filter((e) => _c(e) && e.kind === "polygon"), r = n.length ? Ms(n, n.some((e) => e.colors)) : void 0, i = zh([...t.map((e) => e.geometry), ...r ? [r] : []]);
13781
+ let t = e.filter((e) => _c(e) && e.kind === "mesh"), n = e.filter((e) => _c(e) && e.kind === "polygon"), r = n.length ? Ms(n, n.some((e) => e.colors)) : void 0, i = Hh([...t.map((e) => e.geometry), ...r ? [r] : []]);
13780
13782
  r?.dispose();
13781
13783
  let a = n.length === 0 && t.every((e) => e.path), o = this.placeMesh({
13782
13784
  kind: "mesh",
@@ -13790,7 +13792,7 @@ var Nh = class {
13790
13792
  transformedForCapture(e) {
13791
13793
  let t = this.currentTransform().matrix, n = t.equals(new Y());
13792
13794
  if (Array.isArray(e)) return n ? e : e.map((e) => this.transformedForCapture(e));
13793
- if (!Ih(e) || n) return e;
13795
+ if (!zh(e) || n) return e;
13794
13796
  if (e.kind === "polygon") return {
13795
13797
  ...e,
13796
13798
  points: e.points.map((e) => new J(...e).applyMatrix4(t).toArray())
@@ -13830,7 +13832,7 @@ var Nh = class {
13830
13832
  this.captureValues(r, () => this.inScope(n, () => {
13831
13833
  this.currentTransform().matrix.identity(), this.addChildren(n, e), t?.(r);
13832
13834
  }));
13833
- let i = this.meshesIn(n), a = i.map((e) => Lh(e).applyMatrix4(e.matrixWorld)), o = i.length === 1 ? i[0] : void 0, s = o?.geometry.userData.polygons, c = o && s ? s.map((e) => ({
13835
+ let i = this.meshesIn(n), a = i.map((e) => Bh(e).applyMatrix4(e.matrixWorld)), o = i.length === 1 ? i[0] : void 0, s = o?.geometry.userData.polygons, c = o && s ? s.map((e) => ({
13834
13836
  ...e,
13835
13837
  points: e.points.map((e) => new J(...e).applyMatrix4(o.matrixWorld).toArray())
13836
13838
  })) : void 0, l = i.length > 0 && i.every(vh);
@@ -13846,9 +13848,9 @@ var Nh = class {
13846
13848
  }
13847
13849
  }
13848
13850
  convertMesh(e) {
13849
- let { captured: t, geometries: n } = this.buildScratch(e.children), r = Fh(t).filter((e) => e.kind === "polygon"), i = Fh(t).filter((e) => e.kind === "mesh"), a = r.some((e) => e.colors !== void 0), o = [...r.length ? [Ms(r, a)] : [], ...n], s = [...o, ...i.map((e) => e.geometry)];
13851
+ let { captured: t, geometries: n } = this.buildScratch(e.children), r = Lh(t).filter((e) => e.kind === "polygon"), i = Lh(t).filter((e) => e.kind === "mesh"), a = r.some((e) => e.colors !== void 0), o = [...r.length ? [Ms(r, a)] : [], ...n], s = [...o, ...i.map((e) => e.geometry)];
13850
13852
  if (s.length === 0) throw Error("`mesh` needs at least one polygon");
13851
- let c = zh(s);
13853
+ let c = Hh(s);
13852
13854
  o.forEach((e) => e.dispose()), i.length === 0 && n.length === 0 && (c.userData = { polygons: r });
13853
13855
  let l = this.makeMesh(c, this.createMaterial({ properties: {} }, void 0, c.hasAttribute("color")));
13854
13856
  return this.applyCurrentTransform(l), l;
@@ -13929,7 +13931,7 @@ var Nh = class {
13929
13931
  if (t.length > 1) return t;
13930
13932
  throw Error("The shape used as a value produced nothing");
13931
13933
  }
13932
- let o = zh(n);
13934
+ let o = Hh(n);
13933
13935
  return n.forEach((e) => e.dispose()), this.chargeRetained(o), {
13934
13936
  kind: "mesh",
13935
13937
  geometry: o,
@@ -14137,7 +14139,7 @@ var Nh = class {
14137
14139
  }
14138
14140
  convertCustomShape(e) {
14139
14141
  let t = this.symbols.get(e.name);
14140
- if (t !== void 0 && Ih(t)) {
14142
+ if (t !== void 0 && zh(t)) {
14141
14143
  let n = new An();
14142
14144
  return this.inScope(n, () => {
14143
14145
  this.applyPlacement(this.currentTransform().matrix, e.properties);
@@ -14149,18 +14151,27 @@ var Nh = class {
14149
14151
  if (typeof t != "object" || Array.isArray(t) || !("type" in t)) return this.placeValue(t);
14150
14152
  let n = t;
14151
14153
  if (!n.body) throw Error(`Custom shape '${e.name}' has no body`);
14152
- let r = new An(), i = n.body, { position: a, orientation: o, rotation: s, size: c, name: l, ...u } = e.properties;
14153
- return this.inScope(r, () => {
14154
- this.applyPlacement(this.currentTransform().matrix, {
14155
- position: a,
14156
- orientation: o,
14157
- rotation: s,
14158
- size: c
14159
- }), this.currentTransform().material = this.materialFor(u, this.currentTransform().material);
14160
- for (let e of n.options ?? []) this.symbols.set(e.name, this.evaluator.evaluate(e.defaultValue));
14161
- for (let [e, t] of Object.entries(u)) e in Ph || this.symbols.set(e, this.evaluator.evaluate(t));
14162
- l !== void 0 && (r.name = String(this.evaluator.evaluate(l))), this.withShapeOptions(u, () => this.addChildren(r, i));
14163
- });
14154
+ if (this.customShapeDepth >= Fh) throw Error(`Custom shape \`${e.name}\` recursed more than ${Fh} levels deep`);
14155
+ let r = new An(), i = n.body, { position: a, orientation: o, rotation: s, size: c, name: l, ...u } = e.properties, d = this.evaluateOptionOverrides(u);
14156
+ this.customShapeDepth++;
14157
+ try {
14158
+ return this.inScope(r, () => {
14159
+ this.applyPlacement(this.currentTransform().matrix, {
14160
+ position: a,
14161
+ orientation: o,
14162
+ rotation: s,
14163
+ size: c
14164
+ }), this.currentTransform().material = this.materialFor(u, this.currentTransform().material);
14165
+ for (let e of n.options ?? []) this.symbols.set(e.name, this.evaluator.evaluate(e.defaultValue));
14166
+ for (let [e, t] of d) this.symbols.set(e, t);
14167
+ l !== void 0 && (r.name = String(this.evaluator.evaluate(l))), this.withShapeOptions(u, () => this.addChildren(r, i));
14168
+ });
14169
+ } finally {
14170
+ this.customShapeDepth--;
14171
+ }
14172
+ }
14173
+ evaluateOptionOverrides(e) {
14174
+ return Object.entries(e).filter(([e]) => !(e in Ih)).map(([e, t]) => [e, this.evaluator.evaluate(t)]);
14164
14175
  }
14165
14176
  applyPlacement(e, t) {
14166
14177
  let n = t.position ? new J(...this.evaluateVector3(t.position)) : new J(), r = t.orientation ?? t.rotation, i = r ? this.rotationOf(r) : new Mt(), a = t.size ? new J(...this.evaluateSize(t.size)) : new J(1, 1, 1);
@@ -14317,7 +14328,7 @@ var Nh = class {
14317
14328
  curveSegments: 1
14318
14329
  }).translate(0, 0, -t / 2)] : [], a = n.map((e) => ul(hh(e), t)), o = [...i, ...a];
14319
14330
  for (let e of o) this.chargeEstimate(e.getAttribute("position").count);
14320
- let s = o.length === 1 ? o[0] : zh(o);
14331
+ let s = o.length === 1 ? o[0] : Hh(o);
14321
14332
  return o.length > 1 && o.forEach((e) => e.dispose()), s;
14322
14333
  });
14323
14334
  });
@@ -14336,7 +14347,7 @@ var Nh = class {
14336
14347
  if (!n.length) throw Error("`extrude … along` needs a planar section to sweep");
14337
14348
  let { points: r, closed: i } = this.sweepPathOf(t);
14338
14349
  this.chargeEstimate(n.reduce((e, t) => e + t.length * r.length, 0));
14339
- let a = n.map((e) => al(ol(e, r, i), i)), o = a.length === 1 ? a[0] : zh(a);
14350
+ let a = n.map((e) => al(ol(e, r, i), i)), o = a.length === 1 ? a[0] : Hh(a);
14340
14351
  return a.length > 1 && a.forEach((e) => e.dispose()), o;
14341
14352
  });
14342
14353
  }
@@ -14569,7 +14580,7 @@ var Nh = class {
14569
14580
  textOf(e) {
14570
14581
  let t = e.lines.map((e) => {
14571
14582
  let t = this.evaluator.evaluate(e);
14572
- return Dl(Array.isArray(t) ? t : [t], (e) => Bh(e));
14583
+ return Dl(Array.isArray(t) ? t : [t], (e) => Uh(e));
14573
14584
  }).join("\n");
14574
14585
  if (t.length > 2e3) throw Error(`\`text\` is limited to ${hl} characters`);
14575
14586
  return t;
@@ -14631,7 +14642,7 @@ var Nh = class {
14631
14642
  throw r.dispose(), e;
14632
14643
  }
14633
14644
  this.chargeEstimate(r.getAttribute("position").count);
14634
- let a = Rh(t);
14645
+ let a = Vh(t);
14635
14646
  return a && r.setAttribute("color", new X(new Float32Array(r.getAttribute("position").count * 3).map((e, t) => a[t % 3]), 3)), r;
14636
14647
  });
14637
14648
  }
@@ -14706,7 +14717,19 @@ var Nh = class {
14706
14717
  if (!e.every(Number.isFinite)) throw Error("Expected finite color channels");
14707
14718
  return e;
14708
14719
  }
14709
- }, Ph = {
14720
+ }, Ph = /* @__PURE__ */ new Set([
14721
+ "shape",
14722
+ "csg",
14723
+ "extrude",
14724
+ "loft",
14725
+ "lathe",
14726
+ "fill",
14727
+ "hull",
14728
+ "minkowski",
14729
+ "text",
14730
+ "mesh",
14731
+ "path"
14732
+ ]), Fh = 256, Ih = {
14710
14733
  position: !0,
14711
14734
  orientation: !0,
14712
14735
  rotation: !0,
@@ -14721,23 +14744,26 @@ var Nh = class {
14721
14744
  detail: !0,
14722
14745
  smoothing: !0
14723
14746
  };
14724
- function Fh(e) {
14747
+ function Lh(e) {
14725
14748
  let t = [];
14726
- for (let n of e) Array.isArray(n) ? t.push(...Fh(n)) : Ih(n) && t.push(n);
14749
+ for (let n of e) Array.isArray(n) ? t.push(...Lh(n)) : zh(n) && t.push(n);
14727
14750
  return t;
14728
14751
  }
14729
- function Ih(e) {
14752
+ function Rh(e) {
14753
+ return zh(e) || Array.isArray(e) && e.length > 0 && e.every(zh);
14754
+ }
14755
+ function zh(e) {
14730
14756
  return _c(e) && (e.kind === "mesh" || e.kind === "polygon");
14731
14757
  }
14732
- function Lh(e) {
14733
- let t = e.geometry.clone(), n = Rh(e);
14758
+ function Bh(e) {
14759
+ let t = e.geometry.clone(), n = Vh(e);
14734
14760
  if (n && !t.hasAttribute("color")) {
14735
14761
  let e = t.getAttribute("position").count;
14736
14762
  t.setAttribute("color", new X(new Float32Array(e * 3).map((e, t) => n[t % 3]), 3));
14737
14763
  }
14738
14764
  return t;
14739
14765
  }
14740
- function Rh(e) {
14766
+ function Vh(e) {
14741
14767
  let t = Array.isArray(e.material) ? e.material[0] : e.material, n = e.geometry.getAttribute("color");
14742
14768
  if (n && n.count > 0) {
14743
14769
  let e = [
@@ -14754,7 +14780,7 @@ function Rh(e) {
14754
14780
  t.color.b
14755
14781
  ];
14756
14782
  }
14757
- function zh(e) {
14783
+ function Hh(e) {
14758
14784
  let t = e.some((e) => e.hasAttribute("color")), n = e.map((e) => {
14759
14785
  let n = e.index ? e.toNonIndexed() : e.clone();
14760
14786
  n.hasAttribute("normal") || n.computeVertexNormals();
@@ -14771,11 +14797,11 @@ function zh(e) {
14771
14797
  if (!r) throw Error("Could not combine the shapes into one mesh");
14772
14798
  return n.length > 1 && n.forEach((e) => e.dispose()), r;
14773
14799
  }
14774
- function Bh(e) {
14775
- return Array.isArray(e) ? e.map((e) => Array.isArray(e) ? `(${Bh(e)})` : Bh(e)).join(" ") : typeof e == "object" ? e.kind === "range" ? `${e.from} to ${e.to} step ${e.step}` : `<${e.kind}>` : String(e);
14800
+ function Uh(e) {
14801
+ return Array.isArray(e) ? e.map((e) => Array.isArray(e) ? `(${Uh(e)})` : Uh(e)).join(" ") : typeof e == "object" ? e.kind === "range" ? `${e.from} to ${e.to} step ${e.step}` : `<${e.kind}>` : String(e);
14776
14802
  }
14777
- function Vh(e, t = {}) {
14803
+ function Wh(e, t = {}) {
14778
14804
  return new Nh(t).convert(e);
14779
14805
  }
14780
14806
  //#endregion
14781
- export { d as $, le as $t, ki as A, Ze as An, Ee as At, h as B, e as Bn, ae as Bt, en as C, J as Cn, pe as Ct, Di as D, Mn as Dn, _e as Dt, P as E, $t as En, ge as Et, bs as F, ro as Fn, V as Ft, s as G, L as Gt, g as H, r as Hn, ne as Ht, An as I, rt as In, H as It, Y as J, Hr as Jt, jt as K, R as Kt, T as L, W as Ln, M as Lt, w as M, Cs as Mn, ie as Mt, fi as N, oo as Nn, re as Nt, Go as O, no as On, ve as Ot, qe as P, et as Pn, B as Pt, ho as Q, it as Qt, S as R, nt as Rn, De as Rt, tn as S, q as Sn, fe as St, ee as T, Je as Tn, he as Tt, He as U, i as Un, U as Ut, _ as V, t as Vn, oe as Vt, Ue as W, z as Wt, Ur as X, I as Xt, ti as Y, F as Yt, mo as Z, l as Zt, Bt as _, k as _n, be as _t, oh as a, zn as an, ci as at, Oi as b, D as bn, we as bt, j as c, ls as cn, Mt as ct, Ai as d, yr as dn, je as dt, Me as en, f as et, vr as f, br as fn, ke as ft, Ln as g, O as gn, Ce as gt, u as h, A as hn, te as ht, lh as i, We as in, Ho as it, X as j, G as jn, se as jt, at as k, Qe as kn, ye as kt, Ko as l, c as ln, ce as lt, y as m, v as mn, N as mt, Eh as n, de as nn, p as nt, ch as o, uo as on, Za as ot, Mr as p, so as pn, ue as pt, Ft as q, fo as qt, Vh as r, Ve as rn, Uo as rt, $c as s, b as sn, cs as st, xh as t, Ae as tn, m as tt, Xo as u, Xt as un, lt as ut, Ss as v, C as vn, xe as vt, ii as w, Zt as wn, me as wt, Ei as x, x as xn, Te as xt, Yo as y, E as yn, Se as yt, pn as z, o as zn, Oe as zt };
14807
+ export { d as $, le as $t, ki as A, Ze as An, Ee as At, h as B, e as Bn, ae as Bt, en as C, J as Cn, pe as Ct, Di as D, Mn as Dn, _e as Dt, P as E, $t as En, ge as Et, bs as F, ro as Fn, V as Ft, s as G, L as Gt, g as H, r as Hn, ne as Ht, An as I, rt as In, H as It, Y as J, Hr as Jt, jt as K, R as Kt, T as L, W as Ln, M as Lt, w as M, Cs as Mn, ie as Mt, fi as N, oo as Nn, re as Nt, Go as O, no as On, ve as Ot, qe as P, et as Pn, B as Pt, ho as Q, it as Qt, S as R, nt as Rn, De as Rt, tn as S, q as Sn, fe as St, ee as T, Je as Tn, he as Tt, He as U, i as Un, U as Ut, _ as V, t as Vn, oe as Vt, Ue as W, z as Wt, Ur as X, I as Xt, ti as Y, F as Yt, mo as Z, l as Zt, Bt as _, k as _n, be as _t, oh as a, zn as an, ci as at, Oi as b, D as bn, we as bt, j as c, ls as cn, Mt as ct, Ai as d, yr as dn, je as dt, Me as en, f as et, vr as f, br as fn, ke as ft, Ln as g, O as gn, Ce as gt, u as h, A as hn, te as ht, lh as i, We as in, Ho as it, X as j, G as jn, se as jt, at as k, Qe as kn, ye as kt, Ko as l, c as ln, ce as lt, y as m, v as mn, N as mt, Eh as n, de as nn, p as nt, ch as o, uo as on, Za as ot, Mr as p, so as pn, ue as pt, Ft as q, fo as qt, Wh as r, Ve as rn, Uo as rt, $c as s, b as sn, cs as st, xh as t, Ae as tn, m as tt, Xo as u, Xt as un, lt as ut, Ss as v, C as vn, xe as vt, ii as w, Zt as wn, me as wt, Ei as x, x as xn, Te as xt, Yo as y, E as yn, Se as yt, pn as z, o as zn, Oe as zt };