@mulmoclaude/shapescript-plugin 2.4.0 → 2.5.1

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.
@@ -7787,7 +7787,6 @@ var _c = (e) => typeof e == "object" && !!e && !Array.isArray(e), vc = {
7787
7787
  });
7788
7788
  for (let [e, t] of Object.entries({
7789
7789
  pi: Math.PI,
7790
- tau: 2 * Math.PI,
7791
7790
  true: !0,
7792
7791
  false: !1
7793
7792
  })) this.set(e, t);
@@ -8888,6 +8887,14 @@ var Qc = class {
8888
8887
  if (e.type === a.IDENTIFIER || typeof e.value == "string") return this.advance();
8889
8888
  throw new o(`Expected identifier but got ${e.type}`, e.line, e.column);
8890
8889
  }
8890
+ parseStatementLine() {
8891
+ let e = this.parseNode();
8892
+ return e && this.expectEndOfStatement(), e;
8893
+ }
8894
+ expectEndOfStatement() {
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);
8897
+ }
8891
8898
  skipNewlines() {
8892
8899
  for (; this.current().type === a.NEWLINE;) this.advance();
8893
8900
  }
@@ -9151,7 +9158,7 @@ var Qc = class {
9151
9158
  let e = {};
9152
9159
  for (; this.current().type !== a.RBRACE && this.current().type !== a.EOF;) {
9153
9160
  if (this.skipNewlines(), !this.parseProperty(e)) return e;
9154
- this.skipNewlines();
9161
+ this.expectEndOfStatement(), this.skipNewlines();
9155
9162
  }
9156
9163
  return e;
9157
9164
  }
@@ -9192,7 +9199,7 @@ var Qc = class {
9192
9199
  this.skipNewlines();
9193
9200
  let e = [];
9194
9201
  for (; this.current().type !== a.RBRACE && this.current().type !== a.EOF;) {
9195
- let t = this.parseNode();
9202
+ let t = this.parseStatementLine();
9196
9203
  t && e.push(t), this.skipNewlines();
9197
9204
  }
9198
9205
  return e;
@@ -9221,7 +9228,7 @@ var Qc = class {
9221
9228
  let r = this.current();
9222
9229
  if (r.type === a.RBRACE || r.type === a.EOF) break;
9223
9230
  if (e !== "polygon") throw new o(`Unexpected token in ${e}: ${r.type}`, r.line, r.column);
9224
- (n ??= []).push(this.parsePathCommand("polygon")), this.skipNewlines();
9231
+ (n ??= []).push(this.parsePathCommand("polygon")), this.expectEndOfStatement(), this.skipNewlines();
9225
9232
  }
9226
9233
  }), this.expect(a.RBRACE)), {
9227
9234
  type: "shape",
@@ -9285,7 +9292,7 @@ var Qc = class {
9285
9292
  let n;
9286
9293
  if (this.current().type === a.LBRACE) n = this.parseBlock();
9287
9294
  else for (n = []; this.current().type !== a.CASE && this.current().type !== a.ELSE && this.current().type !== a.RBRACE && this.current().type !== a.EOF;) {
9288
- let e = this.parseNode();
9295
+ let e = this.parseStatementLine();
9289
9296
  e && n.push(e), this.skipNewlines();
9290
9297
  }
9291
9298
  t.push({
@@ -9295,7 +9302,7 @@ var Qc = class {
9295
9302
  } else if (this.current().type === a.ELSE) {
9296
9303
  if (this.advance(), this.skipNewlines(), this.current().type === a.LBRACE) n = this.parseBlock();
9297
9304
  else for (n = []; this.current().type !== a.CASE && this.current().type !== a.RBRACE && this.current().type !== a.EOF;) {
9298
- let e = this.parseNode();
9305
+ let e = this.parseStatementLine();
9299
9306
  e && n.push(e), this.skipNewlines();
9300
9307
  }
9301
9308
  } else this.skipNewlines(), this.current().type !== a.CASE && this.current().type !== a.ELSE && this.current().type !== a.RBRACE && this.advance();
@@ -9323,9 +9330,9 @@ var Qc = class {
9323
9330
  type: "option",
9324
9331
  name: e,
9325
9332
  defaultValue: n
9326
- });
9333
+ }), this.expectEndOfStatement();
9327
9334
  } else {
9328
- let e = this.parseNode();
9335
+ let e = this.parseStatementLine();
9329
9336
  e && n.push(e);
9330
9337
  }
9331
9338
  }), this.expect(a.RBRACE), {
@@ -9370,7 +9377,7 @@ var Qc = class {
9370
9377
  for (; this.current().type !== a.RBRACE && this.current().type !== a.EOF;) {
9371
9378
  let t = this.current();
9372
9379
  if (this.startsStatement(t)) {
9373
- let e = this.parseNode();
9380
+ let e = this.parseStatementLine();
9374
9381
  e && n.push(e);
9375
9382
  } else if (r = this.parseVectorOrExpression(), this.skipNewlines(), this.current().type !== a.RBRACE) throw new o(`Function \`${e}\`: the expression it returns must be its last line`, this.current().line, this.current().column);
9376
9383
  this.skipNewlines();
@@ -9452,7 +9459,7 @@ var Qc = class {
9452
9459
  return e.lines.push(this.parseVectorOrExpression()), e;
9453
9460
  }
9454
9461
  return this.expect(a.LBRACE), this.skipNewlines(), this.scoped(() => {
9455
- for (; this.current().type !== a.RBRACE && this.current().type !== a.EOF;) this.parseTextLine(e), this.skipNewlines();
9462
+ for (; this.current().type !== a.RBRACE && this.current().type !== a.EOF;) this.parseTextLine(e), this.expectEndOfStatement(), this.skipNewlines();
9456
9463
  }), this.expect(a.RBRACE), e;
9457
9464
  }
9458
9465
  parseTextLine(e) {
@@ -9521,9 +9528,9 @@ var Qc = class {
9521
9528
  a.ROTATION,
9522
9529
  a.ORIENTATION
9523
9530
  ].includes(i.type)) Object.assign(t, this.parseProperties());
9524
- else if (this.isAlongOption(i)) r = this.parseAlong(e, r);
9531
+ else if (this.isAlongOption(i)) r = this.parseAlong(e, r), this.expectEndOfStatement();
9525
9532
  else {
9526
- let e = this.parseNode();
9533
+ let e = this.parseStatementLine();
9527
9534
  e && n.push(e);
9528
9535
  }
9529
9536
  this.skipNewlines();
@@ -9597,10 +9604,10 @@ var Qc = class {
9597
9604
  let n = [];
9598
9605
  for (; this.current().type !== a.RBRACE && this.current().type !== a.EOF;) {
9599
9606
  if (t !== void 0 && this.parsePathProperty(t)) {
9600
- this.skipNewlines();
9607
+ this.expectEndOfStatement(), this.skipNewlines();
9601
9608
  continue;
9602
9609
  }
9603
- n.push(this.parsePathCommand(e)), this.skipNewlines();
9610
+ n.push(this.parsePathCommand(e)), this.expectEndOfStatement(), this.skipNewlines();
9604
9611
  }
9605
9612
  return n;
9606
9613
  });
@@ -9661,7 +9668,7 @@ var Qc = class {
9661
9668
  if (n === "angle" && t.type === a.IDENTIFIER) this.advance(), e.angle = this.parseExpression();
9662
9669
  else if (t.type === a.POSITION || t.type === a.SIZE || t.type === a.ORIENTATION || t.type === a.ROTATION) this.advance(), e[t.type === a.ROTATION ? "orientation" : n] = this.parseVectorOrExpression();
9663
9670
  else throw new o(`Unexpected token in arc: ${t.type}`, t.line, t.column);
9664
- this.skipNewlines();
9671
+ this.expectEndOfStatement(), this.skipNewlines();
9665
9672
  }
9666
9673
  return this.expect(a.RBRACE), e;
9667
9674
  }
@@ -9806,7 +9813,7 @@ var Qc = class {
9806
9813
  Object.assign(t, e);
9807
9814
  } else if (this.current().type === a.IDENTIFIER) {
9808
9815
  let e = this.current().value;
9809
- this.advance(), t[e] = this.parseVectorOrExpression();
9816
+ this.advance(), t[e] = this.parseVectorOrExpression(), this.expectEndOfStatement();
9810
9817
  } else break;
9811
9818
  this.skipNewlines();
9812
9819
  }
@@ -9826,7 +9833,7 @@ var Qc = class {
9826
9833
  parse() {
9827
9834
  let e = [];
9828
9835
  for (; this.current().type !== a.EOF;) {
9829
- let t = this.pos, n = this.parseNode();
9836
+ let t = this.pos, n = this.parseStatementLine();
9830
9837
  n && e.push(n), this.skipNewlines(), n === null && this.refuseStalledToken(t);
9831
9838
  }
9832
9839
  return e;
@@ -13492,26 +13499,46 @@ function hh(e) {
13492
13499
  }
13493
13500
  return n;
13494
13501
  }
13495
- var gh = 3e4, _h = 8, vh = 12, yh = 4, bh = 1e-9, xh = class extends Error {
13502
+ var gh = "pathValue";
13503
+ function _h(e) {
13504
+ return e.userData[gh] = !0, e;
13505
+ }
13506
+ function vh(e) {
13507
+ return e.userData[gh] === !0;
13508
+ }
13509
+ var yh = /* @__PURE__ */ new Set([
13510
+ "circle",
13511
+ "square",
13512
+ "roundrect",
13513
+ "polygon"
13514
+ ]);
13515
+ function bh(e) {
13516
+ if (!vh(e)) throw Error("`loft` expects `path` cross-sections, not meshes — pass the path itself rather than a `fill` of it");
13517
+ if (e.isMesh) return tl(e);
13518
+ let t = hh(e);
13519
+ if (t.length < 3) throw Error("A `loft` cross-section needs at least three points");
13520
+ return t;
13521
+ }
13522
+ var xh = 3e4, Sh = 8, Ch = 12, wh = 4, Th = 1e-9, Eh = class extends Error {
13496
13523
  constructor(e) {
13497
13524
  super(e), this.name = "ShapeScriptLimitError";
13498
13525
  }
13499
13526
  };
13500
- function Sh(e) {
13527
+ function Dh(e) {
13501
13528
  return {
13502
13529
  ...e,
13503
13530
  color: e.color?.clone(),
13504
13531
  glow: e.glow?.clone()
13505
13532
  };
13506
13533
  }
13507
- var Ch = 200, wh = 200;
13508
- function Th(e) {
13534
+ var Oh = 200, kh = 200;
13535
+ function Ah(e) {
13509
13536
  let t = e.getAttribute("position"), n = e.getIndex(), r = n?.count ?? t.count, i = new J(), a = new J(), o = new J(), s = 0;
13510
13537
  for (let e = 0; e < r; e += 3) i.fromBufferAttribute(t, n ? n.getX(e) : e), a.fromBufferAttribute(t, n ? n.getX(e + 1) : e + 1), o.fromBufferAttribute(t, n ? n.getX(e + 2) : e + 2), s += i.dot(a.cross(o));
13511
13538
  return s / 6;
13512
13539
  }
13513
- function Eh(e) {
13514
- if (Th(e) >= 0) return e;
13540
+ function jh(e) {
13541
+ if (Ah(e) >= 0) return e;
13515
13542
  let t = e.getIndex();
13516
13543
  if (t) {
13517
13544
  for (let e = 0; e < t.count; e += 3) {
@@ -13527,10 +13554,10 @@ function Eh(e) {
13527
13554
  }
13528
13555
  return e;
13529
13556
  }
13530
- function Dh(e) {
13557
+ function Mh(e) {
13531
13558
  return Math.max(0, Math.round(Math.log2(Math.max(4, e))) - 2);
13532
13559
  }
13533
- var Oh = class {
13560
+ var Nh = class {
13534
13561
  options;
13535
13562
  evaluator;
13536
13563
  symbols;
@@ -13587,15 +13614,15 @@ var Oh = class {
13587
13614
  this.chargeEstimate(r * n);
13588
13615
  }
13589
13616
  chargeEstimate(e) {
13590
- if (this.vertexCount + e > this.maxVertices) throw new xh(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or simplify the path`);
13617
+ if (this.vertexCount + e > this.maxVertices) throw new Eh(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or simplify the path`);
13591
13618
  }
13592
13619
  makeMesh(e, t) {
13593
- if (this.vertexCount += e.getAttribute("position")?.count ?? 0, this.vertexCount > this.maxVertices) throw e.dispose(), t.dispose(), new xh(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or use fewer shapes`);
13620
+ if (this.vertexCount += e.getAttribute("position")?.count ?? 0, this.vertexCount > this.maxVertices) throw e.dispose(), t.dispose(), new Eh(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or use fewer shapes`);
13594
13621
  return new ti(e, t);
13595
13622
  }
13596
13623
  convertNode(e) {
13597
- if (this.nodeCount += 1, this.nodeCount > this.maxNodes) throw new xh(`ShapeScript produced more than ${this.maxNodes} objects — reduce the loop counts or the nesting`);
13598
- if (Date.now() - this.startedAt > this.maxDurationMs) throw new xh(`ShapeScript took longer than ${this.maxDurationMs}ms to build — simplify the model or use fewer boolean operations`);
13624
+ 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`);
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`);
13599
13626
  switch (e.type) {
13600
13627
  case "shape": return this.convertShape(e);
13601
13628
  case "csg": return this.convertCSG(e);
@@ -13618,7 +13645,7 @@ var Oh = class {
13618
13645
  case "material": return this.handleMaterialCommand(e), null;
13619
13646
  case "smoothing": return this.currentTransform().material.smoothing = this.evaluateNumber(e.value), null;
13620
13647
  case "background": return this.handleBackground(e.value), null;
13621
- case "print": return this.logs.length < Ch && this.logs.push(Fh(this.evaluator.evaluate(e.value))), null;
13648
+ case "print": return this.logs.length < Oh && this.logs.push(Bh(this.evaluator.evaluate(e.value))), null;
13622
13649
  case "assert":
13623
13650
  if (!this.evaluator.evaluateToBoolean(e.value)) throw Error("Assertion failed");
13624
13651
  return null;
@@ -13637,10 +13664,10 @@ var Oh = class {
13637
13664
  convertPathProfile(e) {
13638
13665
  return this.withPathDetail(() => {
13639
13666
  let t = this.collectPathPoints(e), n = this.shapeFromPathPoints(t);
13640
- if (!mh(t)) return this.lineFromPath(e, n);
13641
- this.chargePathEstimate(n, vh), this.requireEnclosedArea(n, "path");
13667
+ if (!mh(t)) return _h(this.lineFromPath(e, n));
13668
+ this.chargePathEstimate(n, Ch), this.requireEnclosedArea(n, "path");
13642
13669
  let r = this.makeMesh(this.placePath(new Qa(n), e), this.createMaterial({ properties: {} }));
13643
- return this.applyCurrentTransform(r), r;
13670
+ return this.applyCurrentTransform(r), _h(r);
13644
13671
  });
13645
13672
  }
13646
13673
  withPathDetail(e) {
@@ -13661,7 +13688,7 @@ var Oh = class {
13661
13688
  return this.applyCurrentTransform(o), o;
13662
13689
  }
13663
13690
  warn(e) {
13664
- this.warningSet.has(e) || this.warnings.length >= wh || (this.warningSet.add(e), this.warnings.push(e));
13691
+ this.warningSet.has(e) || this.warnings.length >= kh || (this.warningSet.add(e), this.warnings.push(e));
13665
13692
  }
13666
13693
  handleBackground(e) {
13667
13694
  if (this.sceneDepth > 0) throw Error("`background` can only be used at the root of the script");
@@ -13730,7 +13757,10 @@ var Oh = class {
13730
13757
  }
13731
13758
  }
13732
13759
  convertShape(e) {
13733
- return e.points === void 0 ? this.withShapeOptions(e.properties, () => this.finishMesh(this.createGeometry(e), e, !1)) : this.placeValue(this.polygonValue(e));
13760
+ return e.points === void 0 ? this.withShapeOptions(e.properties, () => {
13761
+ let t = this.finishMesh(this.createGeometry(e), e, !1);
13762
+ return yh.has(e.primitive) ? _h(t) : t;
13763
+ }) : this.placeValue(this.polygonValue(e));
13734
13764
  }
13735
13765
  captureValues(e, t) {
13736
13766
  let n = this.valueSink;
@@ -13746,20 +13776,21 @@ var Oh = class {
13746
13776
  if (_c(e) && e.kind === "mesh") return this.placeMesh(e);
13747
13777
  if (_c(e) && e.kind === "polygon") return this.placePolygons([e]);
13748
13778
  if (Array.isArray(e) && e.length > 0 && e.every((e) => _c(e) && (e.kind === "mesh" || e.kind === "polygon"))) {
13749
- 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 = Ph([...t.map((e) => e.geometry), ...r ? [r] : []]);
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] : []]);
13750
13780
  r?.dispose();
13751
- let a = this.placeMesh({
13781
+ let a = n.length === 0 && t.every((e) => e.path), o = this.placeMesh({
13752
13782
  kind: "mesh",
13753
- geometry: i
13783
+ geometry: i,
13784
+ ...a ? { path: a } : {}
13754
13785
  });
13755
- return i.dispose(), a;
13786
+ return i.dispose(), o;
13756
13787
  }
13757
13788
  throw Error("Unused value — a statement that is not a shape does nothing here; use `define` or `print`");
13758
13789
  }
13759
13790
  transformedForCapture(e) {
13760
13791
  let t = this.currentTransform().matrix, n = t.equals(new Y());
13761
13792
  if (Array.isArray(e)) return n ? e : e.map((e) => this.transformedForCapture(e));
13762
- if (!jh(e) || n) return e;
13793
+ if (!Ih(e) || n) return e;
13763
13794
  if (e.kind === "polygon") return {
13764
13795
  ...e,
13765
13796
  points: e.points.map((e) => new J(...e).applyMatrix4(t).toArray())
@@ -13781,7 +13812,7 @@ var Oh = class {
13781
13812
  }
13782
13813
  placeMesh(e) {
13783
13814
  let t = e.geometry.clone(), n = this.makeMesh(t, this.createMaterial({ properties: {} }, void 0, t.hasAttribute("color")));
13784
- return e.name !== void 0 && (n.name = e.name), this.applyCurrentTransform(n), n;
13815
+ return e.name !== void 0 && (n.name = e.name), e.path && _h(n), this.applyCurrentTransform(n), n;
13785
13816
  }
13786
13817
  placePolygons(e) {
13787
13818
  let t = e.some((e) => e.colors !== void 0), n = Ms(e, t);
@@ -13799,31 +13830,32 @@ var Oh = class {
13799
13830
  this.captureValues(r, () => this.inScope(n, () => {
13800
13831
  this.currentTransform().matrix.identity(), this.addChildren(n, e), t?.(r);
13801
13832
  }));
13802
- let i = this.meshesIn(n), a = i.map((e) => Mh(e).applyMatrix4(e.matrixWorld)), o = i.length === 1 ? i[0] : void 0, s = o?.geometry.userData.polygons, c = o && s ? s.map((e) => ({
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) => ({
13803
13834
  ...e,
13804
13835
  points: e.points.map((e) => new J(...e).applyMatrix4(o.matrixWorld).toArray())
13805
- })) : void 0;
13836
+ })) : void 0, l = i.length > 0 && i.every(vh);
13806
13837
  return {
13807
13838
  captured: r,
13808
13839
  geometries: a,
13809
13840
  name: o?.name || void 0,
13810
- polygons: c
13841
+ polygons: c,
13842
+ path: l
13811
13843
  };
13812
13844
  } finally {
13813
13845
  oh(n), this.vertexCount = i, this.vertexCount += this.retained.slice(a).reduce((e, t) => e + t.getAttribute("position").count, 0);
13814
13846
  }
13815
13847
  }
13816
13848
  convertMesh(e) {
13817
- let { captured: t, geometries: n } = this.buildScratch(e.children), r = Ah(t).filter((e) => e.kind === "polygon"), i = Ah(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)];
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)];
13818
13850
  if (s.length === 0) throw Error("`mesh` needs at least one polygon");
13819
- let c = Ph(s);
13851
+ let c = zh(s);
13820
13852
  o.forEach((e) => e.dispose()), i.length === 0 && n.length === 0 && (c.userData = { polygons: r });
13821
13853
  let l = this.makeMesh(c, this.createMaterial({ properties: {} }, void 0, c.hasAttribute("color")));
13822
13854
  return this.applyCurrentTransform(l), l;
13823
13855
  }
13824
13856
  polygonValue(e) {
13825
13857
  let t = [], n = [], r = e.properties.color === void 0 ? void 0 : this.evaluateRGBA(e.properties.color), i = r !== void 0, a = (e) => {
13826
- if (++this.pathCommandCount > this.maxLoopIterations) throw new xh(`ShapeScript polygon exceeds ${this.maxLoopIterations} commands`);
13858
+ if (++this.pathCommandCount > this.maxLoopIterations) throw new Eh(`ShapeScript polygon exceeds ${this.maxLoopIterations} commands`);
13827
13859
  switch (e.type) {
13828
13860
  case "define":
13829
13861
  this.handleDefine(e);
@@ -13891,29 +13923,31 @@ var Oh = class {
13891
13923
  }), t;
13892
13924
  }
13893
13925
  shapeValue(e) {
13894
- let { captured: t, geometries: n, name: r, polygons: i } = this.buildScratch([e]);
13926
+ let { captured: t, geometries: n, name: r, polygons: i, path: a } = this.buildScratch([e]);
13895
13927
  if (n.length === 0) {
13896
13928
  if (t.length === 1) return t[0];
13897
13929
  if (t.length > 1) return t;
13898
13930
  throw Error("The shape used as a value produced nothing");
13899
13931
  }
13900
- let a = Ph(n);
13901
- return n.forEach((e) => e.dispose()), this.chargeRetained(a), {
13932
+ let o = zh(n);
13933
+ return n.forEach((e) => e.dispose()), this.chargeRetained(o), {
13902
13934
  kind: "mesh",
13903
- geometry: a,
13935
+ geometry: o,
13904
13936
  ...r === void 0 ? {} : { name: r },
13905
- ...i === void 0 ? {} : { polygons: i }
13937
+ ...i === void 0 ? {} : { polygons: i },
13938
+ ...a ? { path: a } : {}
13906
13939
  };
13907
13940
  }
13908
13941
  callShapeFunction(e, t) {
13909
13942
  let { params: n = [], body: r = [], value: i, name: a } = e.definition;
13910
13943
  return this.evaluator.withArguments(n, t, () => {
13911
- let { captured: e, geometries: t } = this.buildScratch(r, (e) => {
13944
+ let { captured: e, geometries: t, path: n } = this.buildScratch(r, (e) => {
13912
13945
  i !== void 0 && e.push(this.transformedForCapture(this.evaluator.evaluate(i)));
13913
13946
  });
13914
- for (let n of t) this.chargeRetained(n), e.push({
13947
+ for (let r of t) this.chargeRetained(r), e.push({
13915
13948
  kind: "mesh",
13916
- geometry: n
13949
+ geometry: r,
13950
+ ...n ? { path: n } : {}
13917
13951
  });
13918
13952
  if (e.length === 0) throw Error(`Function \`${a}\` produced no value`);
13919
13953
  return e.length === 1 ? e[0] : e;
@@ -13927,7 +13961,7 @@ var Oh = class {
13927
13961
  switch (e.primitive) {
13928
13962
  case "cube": return this.requireExtent("cube", t), new Ai(t[0], t[1], t[2]);
13929
13963
  case "sphere": return this.requireExtent("sphere", t), new eo(.5, this.detailLevel, this.detailLevel).scale(...t);
13930
- case "icosphere": return this.requireExtent("icosphere", t), js(.5, Dh(this.detailLevel)).geometry.scale(...t);
13964
+ case "icosphere": return this.requireExtent("icosphere", t), js(.5, Mh(this.detailLevel)).geometry.scale(...t);
13931
13965
  case "cylinder": {
13932
13966
  let n = e.properties.radiusTop ? this.evaluateNumber(e.properties.radiusTop) : t[0] / 2, r = e.properties.radiusBottom ? this.evaluateNumber(e.properties.radiusBottom) : t[0] / 2, i = e.properties.height ? this.evaluateNumber(e.properties.height) : t[1];
13933
13967
  return this.requireExtent("cylinder", [n || r, i]), new Mi(n, r, i, this.detailLevel);
@@ -13963,7 +13997,7 @@ var Oh = class {
13963
13997
  return this.requireExtent("torus", [i, a]), new to(i, a, Math.max(3, Math.floor(this.detailLevel / 2)), this.detailLevel);
13964
13998
  }
13965
13999
  materialFor(e, t) {
13966
- let n = Sh(t);
14000
+ let n = Dh(t);
13967
14001
  return e.material !== void 0 && this.applyMaterialValue(n, this.evaluator.evaluate(e.material)), e.color !== void 0 && this.applyColor(n, this.evaluateRGBA(e.color)), e.opacity !== void 0 && (n.opacity *= this.evaluateNumber(e.opacity)), e.metallicity !== void 0 && (n.metallicity = this.evaluateNumber(e.metallicity)), e.roughness !== void 0 && (n.roughness = this.evaluateNumber(e.roughness)), e.glow !== void 0 && (n.glow = this.glowColor(this.evaluator.evaluate(e.glow))), e.texture !== void 0 && this.warnTexture(this.evaluator.evaluate(e.texture)), n;
13968
14002
  }
13969
14003
  applyColor(e, [t, n, r, i]) {
@@ -14085,7 +14119,7 @@ var Oh = class {
14085
14119
  });
14086
14120
  }
14087
14121
  iterations(e) {
14088
- return Fc(this.evaluator.evaluate(e), this.maxLoopIterations, () => new xh(`ShapeScript loop exceeds ${this.maxLoopIterations} iterations — narrow the range or increase the step`));
14122
+ return Fc(this.evaluator.evaluate(e), this.maxLoopIterations, () => new Eh(`ShapeScript loop exceeds ${this.maxLoopIterations} iterations — narrow the range or increase the step`));
14089
14123
  }
14090
14124
  convertIf(e) {
14091
14125
  let t = new An(), n = this.evaluator.evaluateToBoolean(e.condition);
@@ -14103,7 +14137,7 @@ var Oh = class {
14103
14137
  }
14104
14138
  convertCustomShape(e) {
14105
14139
  let t = this.symbols.get(e.name);
14106
- if (t !== void 0 && jh(t)) {
14140
+ if (t !== void 0 && Ih(t)) {
14107
14141
  let n = new An();
14108
14142
  return this.inScope(n, () => {
14109
14143
  this.applyPlacement(this.currentTransform().matrix, e.properties);
@@ -14124,7 +14158,7 @@ var Oh = class {
14124
14158
  size: c
14125
14159
  }), this.currentTransform().material = this.materialFor(u, this.currentTransform().material);
14126
14160
  for (let e of n.options ?? []) this.symbols.set(e.name, this.evaluator.evaluate(e.defaultValue));
14127
- for (let [e, t] of Object.entries(u)) e in kh || this.symbols.set(e, this.evaluator.evaluate(t));
14161
+ for (let [e, t] of Object.entries(u)) e in Ph || this.symbols.set(e, this.evaluator.evaluate(t));
14128
14162
  l !== void 0 && (r.name = String(this.evaluator.evaluate(l))), this.withShapeOptions(u, () => this.addChildren(r, i));
14129
14163
  });
14130
14164
  }
@@ -14136,7 +14170,7 @@ var Oh = class {
14136
14170
  let e = this.currentTransform();
14137
14171
  this.transformStack.push({
14138
14172
  matrix: e.matrix.clone(),
14139
- material: Sh(e.material)
14173
+ material: Dh(e.material)
14140
14174
  });
14141
14175
  }
14142
14176
  popTransform() {
@@ -14234,9 +14268,9 @@ var Oh = class {
14234
14268
  n.matrix.multiply(r);
14235
14269
  }
14236
14270
  requireEnclosedArea(e, t) {
14237
- let n = e.getPoints(vh), r = Wa.area(n);
14271
+ let n = e.getPoints(Ch), r = Wa.area(n);
14238
14272
  if (!Number.isFinite(r)) throw Error(`\`${t}\` needs finite path coordinates — these overflow`);
14239
- if (n.length < 3 || Math.abs(r) < bh) throw Error(`\`${t}\` needs a path that encloses an area — this one has fewer than three distinct points, or they are collinear`);
14273
+ if (n.length < 3 || Math.abs(r) < Th) throw Error(`\`${t}\` needs a path that encloses an area — this one has fewer than three distinct points, or they are collinear`);
14240
14274
  return e;
14241
14275
  }
14242
14276
  extrudeProperties(e) {
@@ -14263,7 +14297,7 @@ var Oh = class {
14263
14297
  let { depth: t, properties: n } = this.extrudeProperties(e);
14264
14298
  return e.path ? this.withPathDetail(() => {
14265
14299
  let r = e.path, i = this.collectPathPoints(r), a = this.shapeFromPathPoints(i), o = Math.max(1, Math.floor(this.detailLevel / 4));
14266
- this.chargePathEstimate(a, o, yh);
14300
+ this.chargePathEstimate(a, o, wh);
14267
14301
  let s = mh(i) ? new qa(this.requireEnclosedArea(a, "extrude"), {
14268
14302
  depth: t,
14269
14303
  bevelEnabled: !1,
@@ -14283,7 +14317,7 @@ var Oh = class {
14283
14317
  curveSegments: 1
14284
14318
  }).translate(0, 0, -t / 2)] : [], a = n.map((e) => ul(hh(e), t)), o = [...i, ...a];
14285
14319
  for (let e of o) this.chargeEstimate(e.getAttribute("position").count);
14286
- let s = o.length === 1 ? o[0] : Ph(o);
14320
+ let s = o.length === 1 ? o[0] : zh(o);
14287
14321
  return o.length > 1 && o.forEach((e) => e.dispose()), s;
14288
14322
  });
14289
14323
  });
@@ -14302,7 +14336,7 @@ var Oh = class {
14302
14336
  if (!n.length) throw Error("`extrude … along` needs a planar section to sweep");
14303
14337
  let { points: r, closed: i } = this.sweepPathOf(t);
14304
14338
  this.chargeEstimate(n.reduce((e, t) => e + t.length * r.length, 0));
14305
- let a = n.map((e) => al(ol(e, r, i), i)), o = a.length === 1 ? a[0] : Ph(a);
14339
+ let a = n.map((e) => al(ol(e, r, i), i)), o = a.length === 1 ? a[0] : zh(a);
14306
14340
  return a.length > 1 && a.forEach((e) => e.dispose()), o;
14307
14341
  });
14308
14342
  }
@@ -14342,7 +14376,7 @@ var Oh = class {
14342
14376
  }, a = (e) => {
14343
14377
  if (t.multiply(e), !t.elements.every(Number.isFinite)) throw Error("Path transform overflowed to a non-finite value — `translate`, `rotate` and `scale` accumulate inside a path");
14344
14378
  }, o = (e) => {
14345
- if (++this.pathCommandCount > this.maxLoopIterations) throw new xh(`ShapeScript path exceeds ${this.maxLoopIterations} commands`);
14379
+ if (++this.pathCommandCount > this.maxLoopIterations) throw new Eh(`ShapeScript path exceeds ${this.maxLoopIterations} commands`);
14346
14380
  switch (e.type) {
14347
14381
  case "define":
14348
14382
  this.handleDefine(e);
@@ -14442,7 +14476,7 @@ var Oh = class {
14442
14476
  requireLatheProfile(e) {
14443
14477
  if (!e.every((e) => Number.isFinite(e.x) && Number.isFinite(e.y))) throw Error("`lathe` profile has non-finite coordinates — a curve control point or a path command overflowed");
14444
14478
  let t = Math.max(...e.map((e) => Math.abs(e.x))), n = Math.max(...e.map((e) => e.y)) - Math.min(...e.map((e) => e.y));
14445
- if (t < bh || n < bh) throw Error("`lathe` needs a profile with both radius and height — one on the axis of rotation sweeps nothing");
14479
+ if (t < Th || n < Th) throw Error("`lathe` needs a profile with both radius and height — one on the axis of rotation sweeps nothing");
14446
14480
  }
14447
14481
  buildLathe(e) {
14448
14482
  let t = null;
@@ -14462,7 +14496,7 @@ var Oh = class {
14462
14496
  if (r.length < 2) throw Error("Lathe path must have at least 2 points");
14463
14497
  if (this.requireLatheProfile(r), r.every((e) => e.x <= uh)) for (let e of r) e.x = -e.x;
14464
14498
  this.chargeEstimate(r.length * (this.detailLevel + 1));
14465
- let i = Eh(new Xa(r, this.detailLevel));
14499
+ let i = jh(new Xa(r, this.detailLevel));
14466
14500
  return this.finishMesh(i, e, !0, this.currentTransform().material);
14467
14501
  });
14468
14502
  }
@@ -14471,18 +14505,22 @@ var Oh = class {
14471
14505
  this.operandDepth++;
14472
14506
  try {
14473
14507
  this.captureValues(null, () => this.inScope(e, () => {
14474
- this.currentTransform().matrix.identity(), this.addChildren(e, t), n = Sh(this.currentTransform().material);
14508
+ this.currentTransform().matrix.identity(), this.addChildren(e, t), n = Dh(this.currentTransform().material);
14475
14509
  }));
14476
14510
  } finally {
14477
14511
  this.operandDepth--;
14478
14512
  }
14479
14513
  e.updateMatrixWorld(!0);
14480
- let r = [], i = [];
14514
+ let r = [], i = [], a = [];
14481
14515
  return e.traverse((e) => {
14482
- e.isMesh ? r.push(e) : e.isLine && i.push(e);
14516
+ if (e.isMesh) r.push(e);
14517
+ else if (e.isLine) i.push(e);
14518
+ else return;
14519
+ a.push(e);
14483
14520
  }), {
14484
14521
  meshes: r,
14485
14522
  lines: i,
14523
+ operands: a,
14486
14524
  material: n
14487
14525
  };
14488
14526
  }
@@ -14490,7 +14528,7 @@ var Oh = class {
14490
14528
  let n = new An(), r = this.vertexCount, i, a;
14491
14529
  try {
14492
14530
  let r = this.buildOperands(n, e.children);
14493
- a = r.material, i = t(r.meshes, r.lines);
14531
+ a = r.material, i = t(r.meshes, r.lines, r.operands);
14494
14532
  } finally {
14495
14533
  oh(n), this.vertexCount = r;
14496
14534
  }
@@ -14500,9 +14538,9 @@ var Oh = class {
14500
14538
  return this.withShapeOptions(e.properties, () => this.buildLoft(e));
14501
14539
  }
14502
14540
  buildLoft(e) {
14503
- return this.buildFromChildren(e, (e) => {
14504
- let t = e.map(tl), n = t.length * Math.max(0, ...t.map((e) => e.length));
14505
- return this.chargeEstimate(n), al(t);
14541
+ return this.buildFromChildren(e, (e, t, n) => {
14542
+ let r = n.map(bh), i = r.length * Math.max(0, ...r.map((e) => e.length));
14543
+ return this.chargeEstimate(i), al(r);
14506
14544
  });
14507
14545
  }
14508
14546
  planarShapes(e) {
@@ -14516,11 +14554,11 @@ var Oh = class {
14516
14554
  let t = El(this.textOf(e), {
14517
14555
  ...e.wrapWidth === void 0 ? {} : { wrapWidth: this.textWrapWidth(e.wrapWidth) },
14518
14556
  lineSpacing: e.lineSpacing === void 0 ? 0 : this.evaluateNumber(e.lineSpacing),
14519
- curveSegments: Math.max(1, Math.floor(this.detailLevel / _h))
14557
+ curveSegments: Math.max(1, Math.floor(this.detailLevel / Sh))
14520
14558
  });
14521
14559
  t.missing.length && this.warn(`The built-in font has no glyph for ${[...new Set(t.missing)].map((e) => `"${e}"`).join(" ")} — drawn as "?"`);
14522
14560
  let n = t.rings.reduce((e, t) => e + t.length, 0);
14523
- return t.shapes.length === 0 ? null : this.operandDepth > 0 || this.valueSink !== null ? (this.chargeEstimate(n), this.finishMesh(new Qa(t.shapes, 1), e, !0)) : this.textOutline(e, t, n);
14561
+ return t.shapes.length === 0 ? null : this.operandDepth > 0 || this.valueSink !== null ? (this.chargeEstimate(n), _h(this.finishMesh(new Qa(t.shapes, 1), e, !0))) : this.textOutline(e, t, n);
14524
14562
  });
14525
14563
  }
14526
14564
  textWrapWidth(e) {
@@ -14531,7 +14569,7 @@ var Oh = class {
14531
14569
  textOf(e) {
14532
14570
  let t = e.lines.map((e) => {
14533
14571
  let t = this.evaluator.evaluate(e);
14534
- return Dl(Array.isArray(t) ? t : [t], (e) => Fh(e));
14572
+ return Dl(Array.isArray(t) ? t : [t], (e) => Bh(e));
14535
14573
  }).join("\n");
14536
14574
  if (t.length > 2e3) throw Error(`\`text\` is limited to ${hl} characters`);
14537
14575
  return t;
@@ -14568,7 +14606,7 @@ var Oh = class {
14568
14606
  return new Qa(t, 1);
14569
14607
  });
14570
14608
  let n = this.buildPath(t);
14571
- this.chargePathEstimate(n, vh), this.requireEnclosedArea(n, "fill");
14609
+ this.chargePathEstimate(n, Ch), this.requireEnclosedArea(n, "fill");
14572
14610
  let r = this.placePath(new Qa(n), t);
14573
14611
  return this.finishMesh(r, e);
14574
14612
  });
@@ -14593,7 +14631,7 @@ var Oh = class {
14593
14631
  throw r.dispose(), e;
14594
14632
  }
14595
14633
  this.chargeEstimate(r.getAttribute("position").count);
14596
- let a = Nh(t);
14634
+ let a = Rh(t);
14597
14635
  return a && r.setAttribute("color", new X(new Float32Array(r.getAttribute("position").count * 3).map((e, t) => a[t % 3]), 3)), r;
14598
14636
  });
14599
14637
  }
@@ -14668,7 +14706,7 @@ var Oh = class {
14668
14706
  if (!e.every(Number.isFinite)) throw Error("Expected finite color channels");
14669
14707
  return e;
14670
14708
  }
14671
- }, kh = {
14709
+ }, Ph = {
14672
14710
  position: !0,
14673
14711
  orientation: !0,
14674
14712
  rotation: !0,
@@ -14683,23 +14721,23 @@ var Oh = class {
14683
14721
  detail: !0,
14684
14722
  smoothing: !0
14685
14723
  };
14686
- function Ah(e) {
14724
+ function Fh(e) {
14687
14725
  let t = [];
14688
- for (let n of e) Array.isArray(n) ? t.push(...Ah(n)) : jh(n) && t.push(n);
14726
+ for (let n of e) Array.isArray(n) ? t.push(...Fh(n)) : Ih(n) && t.push(n);
14689
14727
  return t;
14690
14728
  }
14691
- function jh(e) {
14729
+ function Ih(e) {
14692
14730
  return _c(e) && (e.kind === "mesh" || e.kind === "polygon");
14693
14731
  }
14694
- function Mh(e) {
14695
- let t = e.geometry.clone(), n = Nh(e);
14732
+ function Lh(e) {
14733
+ let t = e.geometry.clone(), n = Rh(e);
14696
14734
  if (n && !t.hasAttribute("color")) {
14697
14735
  let e = t.getAttribute("position").count;
14698
14736
  t.setAttribute("color", new X(new Float32Array(e * 3).map((e, t) => n[t % 3]), 3));
14699
14737
  }
14700
14738
  return t;
14701
14739
  }
14702
- function Nh(e) {
14740
+ function Rh(e) {
14703
14741
  let t = Array.isArray(e.material) ? e.material[0] : e.material, n = e.geometry.getAttribute("color");
14704
14742
  if (n && n.count > 0) {
14705
14743
  let e = [
@@ -14716,7 +14754,7 @@ function Nh(e) {
14716
14754
  t.color.b
14717
14755
  ];
14718
14756
  }
14719
- function Ph(e) {
14757
+ function zh(e) {
14720
14758
  let t = e.some((e) => e.hasAttribute("color")), n = e.map((e) => {
14721
14759
  let n = e.index ? e.toNonIndexed() : e.clone();
14722
14760
  n.hasAttribute("normal") || n.computeVertexNormals();
@@ -14733,11 +14771,11 @@ function Ph(e) {
14733
14771
  if (!r) throw Error("Could not combine the shapes into one mesh");
14734
14772
  return n.length > 1 && n.forEach((e) => e.dispose()), r;
14735
14773
  }
14736
- function Fh(e) {
14737
- return Array.isArray(e) ? e.map((e) => Array.isArray(e) ? `(${Fh(e)})` : Fh(e)).join(" ") : typeof e == "object" ? e.kind === "range" ? `${e.from} to ${e.to} step ${e.step}` : `<${e.kind}>` : String(e);
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);
14738
14776
  }
14739
- function Ih(e, t = {}) {
14740
- return new Oh(t).convert(e);
14777
+ function Vh(e, t = {}) {
14778
+ return new Nh(t).convert(e);
14741
14779
  }
14742
14780
  //#endregion
14743
- export { f as $, Me as $t, ki as A, G as An, se as At, _ as B, t as Bn, oe as Bt, en as C, Zt as Cn, me as Ct, Di as D, no as Dn, ve as Dt, P as E, Mn as En, _e as Et, bs as F, rt as Fn, H as Ft, jt as G, R as Gt, He as H, i as Hn, U as Ht, T as I, W as In, M as It, ti as J, F as Jt, Ft as K, fo as Kt, S as L, nt as Ln, De as Lt, w as M, oo as Mn, re as Mt, fi as N, et as Nn, B as Nt, Go as O, Qe as On, ye as Ot, qe as P, ro as Pn, V as Pt, d as Q, le as Qt, pn as R, o as Rn, Oe as Rt, tn as S, J as Sn, pe as St, ee as T, $t as Tn, ge as Tt, Ue as U, z as Ut, g as V, r as Vn, ne as Vt, s as W, L as Wt, mo as X, l as Xt, Ur as Y, I as Yt, ho as Z, it as Zt, Bt as _, C as _n, xe as _t, oh as a, uo as an, Za as at, Oi as b, x as bn, Te as bt, j as c, c as cn, ce as ct, Ai as d, br as dn, ke as dt, Ae as en, m as et, vr as f, so as fn, ue as ft, Ln as g, k as gn, be as gt, u as h, O as hn, Ce as ht, lh as i, zn as in, ci as it, X as j, Cs as jn, ie as jt, at as k, Ze as kn, Ee as kt, Ko as l, Xt as ln, lt, y as m, A as mn, te as mt, xh as n, Ve as nn, Uo as nt, ch as o, b as on, cs as ot, Mr as p, v as pn, N as pt, Y as q, Hr as qt, Ih as r, We as rn, Ho as rt, $c as s, ls as sn, Mt as st, gh as t, de as tn, p as tt, Xo as u, yr as un, je as ut, Ss as v, E as vn, Se as vt, ii as w, Je as wn, he as wt, Ei as x, q as xn, fe as xt, Yo as y, D as yn, we as yt, h as z, e as zn, ae as zt };
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 };