@newkrok/nape-js 2.1.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -128688,18 +128688,30 @@ function getNape() {
128688
128688
  return nape_compiled_default;
128689
128689
  }
128690
128690
 
128691
+ // src/core/cache.ts
128692
+ var cache = /* @__PURE__ */ new WeakMap();
128693
+ function getOrCreate(inner, create) {
128694
+ if (!inner) return null;
128695
+ let wrapper = cache.get(inner);
128696
+ if (!wrapper) {
128697
+ wrapper = create(inner);
128698
+ cache.set(inner, wrapper);
128699
+ }
128700
+ return wrapper;
128701
+ }
128702
+
128691
128703
  // src/geom/Vec2.ts
128692
128704
  var Vec2 = class _Vec2 {
128693
128705
  constructor(x = 0, y = 0) {
128694
- const nape = getNape();
128695
- this._inner = new nape.geom.Vec2(x, y);
128706
+ this._inner = new (getNape()).geom.Vec2(x, y);
128696
128707
  }
128697
- /** @internal Wrap an existing Haxe Vec2 without calling the constructor. */
128708
+ /** @internal Wrap an existing Haxe Vec2 with caching. */
128698
128709
  static _wrap(inner) {
128699
- if (!inner) return null;
128700
- const v = Object.create(_Vec2.prototype);
128701
- v._inner = inner;
128702
- return v;
128710
+ return getOrCreate(inner, (raw) => {
128711
+ const v = Object.create(_Vec2.prototype);
128712
+ v._inner = raw;
128713
+ return v;
128714
+ });
128703
128715
  }
128704
128716
  // ---------------------------------------------------------------------------
128705
128717
  // Properties
@@ -128838,19 +128850,16 @@ var Vec2 = class _Vec2 {
128838
128850
  // src/geom/AABB.ts
128839
128851
  var AABB = class _AABB {
128840
128852
  constructor(x, y, width, height) {
128841
- const nape = getNape();
128842
- this._inner = new nape.geom.AABB(x, y, width, height);
128853
+ this._inner = new (getNape()).geom.AABB(x, y, width, height);
128843
128854
  }
128844
128855
  /** @internal */
128845
128856
  static _wrap(inner) {
128846
- if (!inner) return null;
128847
- const a = Object.create(_AABB.prototype);
128848
- a._inner = inner;
128849
- return a;
128857
+ return getOrCreate(inner, (raw) => {
128858
+ const a = Object.create(_AABB.prototype);
128859
+ a._inner = raw;
128860
+ return a;
128861
+ });
128850
128862
  }
128851
- // ---------------------------------------------------------------------------
128852
- // Properties
128853
- // ---------------------------------------------------------------------------
128854
128863
  get min() {
128855
128864
  return Vec2._wrap(this._inner.get_min());
128856
128865
  }
@@ -128887,9 +128896,6 @@ var AABB = class _AABB {
128887
128896
  set height(value) {
128888
128897
  this._inner.set_height(value);
128889
128898
  }
128890
- // ---------------------------------------------------------------------------
128891
- // Methods
128892
- // ---------------------------------------------------------------------------
128893
128899
  copy() {
128894
128900
  return _AABB._wrap(this._inner.copy());
128895
128901
  }
@@ -128898,18 +128904,6 @@ var AABB = class _AABB {
128898
128904
  }
128899
128905
  };
128900
128906
 
128901
- // src/core/registry.ts
128902
- var registry = /* @__PURE__ */ new Map();
128903
- function registerWrapper(name, wrapFn) {
128904
- registry.set(name, wrapFn);
128905
- }
128906
- function wrapWith(name, inner) {
128907
- if (!inner) return null;
128908
- const fn = registry.get(name);
128909
- if (!fn) throw new Error(`Wrapper not registered: ${name}`);
128910
- return fn(inner);
128911
- }
128912
-
128913
128907
  // src/util/NapeList.ts
128914
128908
  var NapeList = class {
128915
128909
  /** @internal */
@@ -128985,8 +128979,7 @@ var NapeList = class {
128985
128979
  // src/phys/Material.ts
128986
128980
  var Material = class _Material {
128987
128981
  constructor(elasticity = 0, dynamicFriction = 1, staticFriction = 2, density = 1, rollingFriction = 1e-3) {
128988
- const nape = getNape();
128989
- this._inner = new nape.phys.Material(
128982
+ this._inner = new (getNape()).phys.Material(
128990
128983
  elasticity,
128991
128984
  dynamicFriction,
128992
128985
  staticFriction,
@@ -128996,10 +128989,11 @@ var Material = class _Material {
128996
128989
  }
128997
128990
  /** @internal */
128998
128991
  static _wrap(inner) {
128999
- if (!inner) return null;
129000
- const m = Object.create(_Material.prototype);
129001
- m._inner = inner;
129002
- return m;
128992
+ return getOrCreate(inner, (raw) => {
128993
+ const m = Object.create(_Material.prototype);
128994
+ m._inner = raw;
128995
+ return m;
128996
+ });
129003
128997
  }
129004
128998
  get elasticity() {
129005
128999
  return this._inner.get_elasticity();
@@ -129045,15 +129039,15 @@ var Material = class _Material {
129045
129039
  // src/phys/FluidProperties.ts
129046
129040
  var FluidProperties = class _FluidProperties {
129047
129041
  constructor(density = 1, viscosity = 1) {
129048
- const nape = getNape();
129049
- this._inner = new nape.phys.FluidProperties(density, viscosity);
129042
+ this._inner = new (getNape()).phys.FluidProperties(density, viscosity);
129050
129043
  }
129051
129044
  /** @internal */
129052
129045
  static _wrap(inner) {
129053
- if (!inner) return null;
129054
- const f = Object.create(_FluidProperties.prototype);
129055
- f._inner = inner;
129056
- return f;
129046
+ return getOrCreate(inner, (raw) => {
129047
+ const f = Object.create(_FluidProperties.prototype);
129048
+ f._inner = raw;
129049
+ return f;
129050
+ });
129057
129051
  }
129058
129052
  get density() {
129059
129053
  return this._inner.get_density();
@@ -129087,8 +129081,7 @@ var FluidProperties = class _FluidProperties {
129087
129081
  // src/dynamics/InteractionFilter.ts
129088
129082
  var InteractionFilter = class _InteractionFilter {
129089
129083
  constructor(collisionGroup = 1, collisionMask = -1, sensorGroup = 1, sensorMask = -1, fluidGroup = 1, fluidMask = -1) {
129090
- const nape = getNape();
129091
- this._inner = new nape.dynamics.InteractionFilter(
129084
+ this._inner = new (getNape()).dynamics.InteractionFilter(
129092
129085
  collisionGroup,
129093
129086
  collisionMask,
129094
129087
  sensorGroup,
@@ -129099,10 +129092,11 @@ var InteractionFilter = class _InteractionFilter {
129099
129092
  }
129100
129093
  /** @internal */
129101
129094
  static _wrap(inner) {
129102
- if (!inner) return null;
129103
- const f = Object.create(_InteractionFilter.prototype);
129104
- f._inner = inner;
129105
- return f;
129095
+ return getOrCreate(inner, (raw) => {
129096
+ const f = Object.create(_InteractionFilter.prototype);
129097
+ f._inner = raw;
129098
+ return f;
129099
+ });
129106
129100
  }
129107
129101
  get collisionGroup() {
129108
129102
  return this._inner.get_collisionGroup();
@@ -129143,15 +129137,12 @@ var InteractionFilter = class _InteractionFilter {
129143
129137
  get userData() {
129144
129138
  return this._inner.get_userData();
129145
129139
  }
129146
- /** Check if two filters should produce a collision interaction. */
129147
129140
  shouldCollide(other) {
129148
129141
  return this._inner.shouldCollide(other._inner);
129149
129142
  }
129150
- /** Check if two filters should produce a sensor interaction. */
129151
129143
  shouldSense(other) {
129152
129144
  return this._inner.shouldSense(other._inner);
129153
129145
  }
129154
- /** Check if two filters should produce a fluid interaction. */
129155
129146
  shouldFlow(other) {
129156
129147
  return this._inner.shouldFlow(other._inner);
129157
129148
  }
@@ -129177,24 +129168,29 @@ function fromNativeShapeType(native) {
129177
129168
  }
129178
129169
 
129179
129170
  // src/shape/Shape.ts
129180
- var _CircleClass = null;
129181
- var _PolygonClass = null;
129182
- function _registerCircleClass(cls) {
129183
- _CircleClass = cls;
129171
+ var _circleWrap;
129172
+ var _polygonWrap;
129173
+ function _bindCircleWrap(fn) {
129174
+ _circleWrap = fn;
129184
129175
  }
129185
- function _registerPolygonClass(cls) {
129186
- _PolygonClass = cls;
129176
+ function _bindPolygonWrap(fn) {
129177
+ _polygonWrap = fn;
129187
129178
  }
129188
129179
  var Shape = class _Shape {
129189
129180
  /** @internal – shapes are created via Circle or Polygon constructors. */
129190
129181
  constructor() {
129182
+ this._inner = void 0;
129191
129183
  }
129192
129184
  /** @internal */
129193
129185
  static _wrap(inner) {
129194
129186
  if (!inner) return null;
129195
- const s = Object.create(_Shape.prototype);
129196
- s._inner = inner;
129197
- return s;
129187
+ if (inner.isCircle() && _circleWrap) return _circleWrap(inner);
129188
+ if (inner.isPolygon() && _polygonWrap) return _polygonWrap(inner);
129189
+ return getOrCreate(inner, (raw) => {
129190
+ const s = Object.create(_Shape.prototype);
129191
+ s._inner = raw;
129192
+ return s;
129193
+ });
129198
129194
  }
129199
129195
  // ---------------------------------------------------------------------------
129200
129196
  // Properties
@@ -129202,9 +129198,8 @@ var Shape = class _Shape {
129202
129198
  get type() {
129203
129199
  return fromNativeShapeType(this._inner.get_type());
129204
129200
  }
129205
- /** The body this shape is attached to (null if none). */
129206
129201
  get body() {
129207
- return wrapWith("Body", this._inner.get_body());
129202
+ return Body._wrap(this._inner.get_body());
129208
129203
  }
129209
129204
  set body(value) {
129210
129205
  this._inner.set_body(value?._inner ?? null);
@@ -129251,13 +129246,13 @@ var Shape = class _Shape {
129251
129246
  return {
129252
129247
  _inner: raw,
129253
129248
  add(cbType) {
129254
- raw.add(cbType._inner ?? cbType);
129249
+ raw.add(cbType._inner);
129255
129250
  },
129256
129251
  remove(cbType) {
129257
- raw.remove(cbType._inner ?? cbType);
129252
+ raw.remove(cbType._inner);
129258
129253
  },
129259
129254
  has(cbType) {
129260
- return raw.has(cbType._inner ?? cbType);
129255
+ return raw.has(cbType._inner);
129261
129256
  },
129262
129257
  clear() {
129263
129258
  raw.clear();
@@ -129285,14 +129280,14 @@ var Shape = class _Shape {
129285
129280
  /** Cast to Circle — returns the Circle wrapper or null if not a circle. */
129286
129281
  get castCircle() {
129287
129282
  const raw = this._inner.get_castCircle();
129288
- if (!raw || !_CircleClass) return null;
129289
- return _CircleClass._wrap(raw);
129283
+ if (!raw || !_circleWrap) return null;
129284
+ return _circleWrap(raw);
129290
129285
  }
129291
129286
  /** Cast to Polygon — returns the Polygon wrapper or null if not a polygon. */
129292
129287
  get castPolygon() {
129293
129288
  const raw = this._inner.get_castPolygon();
129294
- if (!raw || !_PolygonClass) return null;
129295
- return _PolygonClass._wrap(raw);
129289
+ if (!raw || !_polygonWrap) return null;
129290
+ return _polygonWrap(raw);
129296
129291
  }
129297
129292
  // ---------------------------------------------------------------------------
129298
129293
  // Methods
@@ -129313,7 +129308,7 @@ var Shape = class _Shape {
129313
129308
  this._inner.rotate(angle);
129314
129309
  }
129315
129310
  transform(matrix) {
129316
- this._inner.transform(matrix?._inner ?? matrix);
129311
+ this._inner.transform(matrix._inner);
129317
129312
  }
129318
129313
  contains(point) {
129319
129314
  return this._inner.contains(point._inner);
@@ -129326,6 +129321,130 @@ var Shape = class _Shape {
129326
129321
  }
129327
129322
  };
129328
129323
 
129324
+ // src/space/Space.ts
129325
+ var Space = class _Space {
129326
+ constructor(gravity) {
129327
+ this._inner = new (getNape()).space.Space(gravity?._inner);
129328
+ }
129329
+ /** @internal */
129330
+ static _wrap(inner) {
129331
+ return getOrCreate(inner, (raw) => {
129332
+ const s = Object.create(_Space.prototype);
129333
+ s._inner = raw;
129334
+ return s;
129335
+ });
129336
+ }
129337
+ // ---------------------------------------------------------------------------
129338
+ // Properties
129339
+ // ---------------------------------------------------------------------------
129340
+ get gravity() {
129341
+ return Vec2._wrap(this._inner.get_gravity());
129342
+ }
129343
+ set gravity(value) {
129344
+ this._inner.set_gravity(value._inner);
129345
+ }
129346
+ get worldLinearDrag() {
129347
+ return this._inner.get_worldLinearDrag();
129348
+ }
129349
+ set worldLinearDrag(value) {
129350
+ this._inner.set_worldLinearDrag(value);
129351
+ }
129352
+ get worldAngularDrag() {
129353
+ return this._inner.get_worldAngularDrag();
129354
+ }
129355
+ set worldAngularDrag(value) {
129356
+ this._inner.set_worldAngularDrag(value);
129357
+ }
129358
+ get sortContacts() {
129359
+ return this._inner.get_sortContacts();
129360
+ }
129361
+ set sortContacts(value) {
129362
+ this._inner.set_sortContacts(value);
129363
+ }
129364
+ get bodies() {
129365
+ return new NapeList(this._inner.get_bodies(), Body._wrap);
129366
+ }
129367
+ get liveBodies() {
129368
+ return new NapeList(this._inner.get_liveBodies(), Body._wrap);
129369
+ }
129370
+ get constraints() {
129371
+ return this._inner.get_constraints();
129372
+ }
129373
+ get liveConstraints() {
129374
+ return this._inner.get_liveConstraints();
129375
+ }
129376
+ get arbiters() {
129377
+ return this._inner.get_arbiters();
129378
+ }
129379
+ get listeners() {
129380
+ return this._inner.get_listeners();
129381
+ }
129382
+ get compounds() {
129383
+ return this._inner.get_compounds();
129384
+ }
129385
+ /** The static world body (always present, immovable). */
129386
+ get world() {
129387
+ return Body._wrap(this._inner.get_world());
129388
+ }
129389
+ get timeStamp() {
129390
+ return this._inner.get_timeStamp();
129391
+ }
129392
+ get elapsedTime() {
129393
+ return this._inner.get_elapsedTime();
129394
+ }
129395
+ get broadphase() {
129396
+ return this._inner.get_broadphase();
129397
+ }
129398
+ get userData() {
129399
+ return this._inner.get_userData();
129400
+ }
129401
+ // ---------------------------------------------------------------------------
129402
+ // Simulation
129403
+ // ---------------------------------------------------------------------------
129404
+ step(deltaTime, velocityIterations = 10, positionIterations = 10) {
129405
+ this._inner.step(deltaTime, velocityIterations, positionIterations);
129406
+ }
129407
+ clear() {
129408
+ this._inner.clear();
129409
+ }
129410
+ // ---------------------------------------------------------------------------
129411
+ // Visitors
129412
+ // ---------------------------------------------------------------------------
129413
+ visitBodies(fn) {
129414
+ this._inner.visitBodies((raw) => fn(Body._wrap(raw)));
129415
+ }
129416
+ visitConstraints(fn) {
129417
+ this._inner.visitConstraints(fn);
129418
+ }
129419
+ visitCompounds(fn) {
129420
+ this._inner.visitCompounds(fn);
129421
+ }
129422
+ // ---------------------------------------------------------------------------
129423
+ // Queries
129424
+ // ---------------------------------------------------------------------------
129425
+ shapesUnderPoint(point, filter, output) {
129426
+ return this._inner.shapesUnderPoint(point._inner, filter?._inner ?? filter, output);
129427
+ }
129428
+ bodiesUnderPoint(point, filter, output) {
129429
+ return this._inner.bodiesUnderPoint(point._inner, filter?._inner ?? filter, output);
129430
+ }
129431
+ shapesInAABB(aabb, containment, strict, filter, output) {
129432
+ return this._inner.shapesInAABB(aabb._inner, containment, strict, filter?._inner ?? filter, output);
129433
+ }
129434
+ bodiesInAABB(aabb, containment, strict, filter, output) {
129435
+ return this._inner.bodiesInAABB(aabb._inner, containment, strict, filter?._inner ?? filter, output);
129436
+ }
129437
+ rayCast(ray, inner, filter) {
129438
+ return this._inner.rayCast(ray?._inner ?? ray, inner, filter?._inner ?? filter);
129439
+ }
129440
+ rayMultiCast(ray, inner, filter, output) {
129441
+ return this._inner.rayMultiCast(ray?._inner ?? ray, inner, filter?._inner ?? filter, output);
129442
+ }
129443
+ toString() {
129444
+ return `Space(bodies=${this.bodies.length})`;
129445
+ }
129446
+ };
129447
+
129329
129448
  // src/phys/BodyType.ts
129330
129449
  var BodyType = /* @__PURE__ */ ((BodyType2) => {
129331
129450
  BodyType2["STATIC"] = "STATIC";
@@ -129355,18 +129474,18 @@ function fromNativeBodyType(native) {
129355
129474
  // src/phys/Body.ts
129356
129475
  var Body = class _Body {
129357
129476
  constructor(type = "DYNAMIC" /* DYNAMIC */, position) {
129358
- const nape = getNape();
129359
- this._inner = new nape.phys.Body(
129477
+ this._inner = new (getNape()).phys.Body(
129360
129478
  toNativeBodyType(type),
129361
129479
  position?._inner
129362
129480
  );
129363
129481
  }
129364
129482
  /** @internal */
129365
129483
  static _wrap(inner) {
129366
- if (!inner) return null;
129367
- const b = Object.create(_Body.prototype);
129368
- b._inner = inner;
129369
- return b;
129484
+ return getOrCreate(inner, (raw) => {
129485
+ const b = Object.create(_Body.prototype);
129486
+ b._inner = raw;
129487
+ return b;
129488
+ });
129370
129489
  }
129371
129490
  // ---------------------------------------------------------------------------
129372
129491
  // Type
@@ -129519,7 +129638,7 @@ var Body = class _Body {
129519
129638
  return new NapeList(this._inner.get_shapes(), Shape._wrap);
129520
129639
  }
129521
129640
  get space() {
129522
- return wrapWith("Space", this._inner.get_space());
129641
+ return Space._wrap(this._inner.get_space());
129523
129642
  }
129524
129643
  set space(value) {
129525
129644
  this._inner.set_space(value?._inner ?? null);
@@ -129548,79 +129667,57 @@ var Body = class _Body {
129548
129667
  // ---------------------------------------------------------------------------
129549
129668
  // Methods
129550
129669
  // ---------------------------------------------------------------------------
129551
- /** Integrate the body forward by deltaTime seconds. */
129552
129670
  integrate(deltaTime) {
129553
129671
  this._inner.integrate(deltaTime);
129554
129672
  }
129555
- /** Apply a linear impulse at an optional world-space point. */
129556
129673
  applyImpulse(impulse, pos, sleepable) {
129557
129674
  this._inner.applyImpulse(impulse._inner, pos?._inner, sleepable);
129558
129675
  }
129559
- /** Apply an angular impulse (torque × dt). */
129560
129676
  applyAngularImpulse(impulse, sleepable) {
129561
129677
  this._inner.applyAngularImpulse(impulse, sleepable);
129562
129678
  }
129563
- /** Set velocity so the body reaches the target position/rotation in deltaTime. */
129564
129679
  setVelocityFromTarget(targetPosition, targetRotation, deltaTime) {
129565
- this._inner.setVelocityFromTarget(
129566
- targetPosition._inner,
129567
- targetRotation,
129568
- deltaTime
129569
- );
129680
+ this._inner.setVelocityFromTarget(targetPosition._inner, targetRotation, deltaTime);
129570
129681
  }
129571
- /** Transform a point from local to world coordinates. */
129572
129682
  localPointToWorld(point, weak = false) {
129573
129683
  return Vec2._wrap(this._inner.localPointToWorld(point._inner, weak));
129574
129684
  }
129575
- /** Transform a point from world to local coordinates. */
129576
129685
  worldPointToLocal(point, weak = false) {
129577
129686
  return Vec2._wrap(this._inner.worldPointToLocal(point._inner, weak));
129578
129687
  }
129579
- /** Transform a direction vector from local to world coordinates. */
129580
129688
  localVectorToWorld(vector, weak = false) {
129581
129689
  return Vec2._wrap(this._inner.localVectorToWorld(vector._inner, weak));
129582
129690
  }
129583
- /** Transform a direction vector from world to local coordinates. */
129584
129691
  worldVectorToLocal(vector, weak = false) {
129585
129692
  return Vec2._wrap(this._inner.worldVectorToLocal(vector._inner, weak));
129586
129693
  }
129587
- /** Translate all shapes on this body by the given offset. */
129588
129694
  translateShapes(translation) {
129589
129695
  this._inner.translateShapes(translation._inner);
129590
129696
  }
129591
- /** Rotate all shapes on this body by the given angle. */
129592
129697
  rotateShapes(angle) {
129593
129698
  this._inner.rotateShapes(angle);
129594
129699
  }
129595
- /** Scale all shapes on this body. */
129596
129700
  scaleShapes(scaleX, scaleY) {
129597
129701
  this._inner.scaleShapes(scaleX, scaleY);
129598
129702
  }
129599
- /** Align the body so that its center of mass is at its position. */
129600
129703
  align() {
129601
129704
  this._inner.align();
129602
129705
  }
129603
- /** Rotate the body about a world-space centre point. */
129604
129706
  rotate(centre, angle) {
129605
129707
  this._inner.rotate(centre._inner, angle);
129606
129708
  }
129607
- /** Set the material for all shapes on this body. */
129608
129709
  setShapeMaterials(material) {
129609
129710
  this._inner.setShapeMaterials(material._inner);
129610
129711
  }
129611
- /** Set the interaction filter for all shapes on this body. */
129612
129712
  setShapeFilters(filter) {
129613
129713
  this._inner.setShapeFilters(filter._inner);
129614
129714
  }
129615
- /** Set the fluid properties for all shapes on this body. */
129616
129715
  setShapeFluidProperties(fluidProperties) {
129617
129716
  this._inner.setShapeFluidProperties(fluidProperties._inner);
129618
129717
  }
129619
- /** Check if a world-space point is inside this body. */
129620
129718
  contains(point) {
129621
129719
  return this._inner.contains(point._inner);
129622
129720
  }
129623
- /** Crush factor for resolving inter-penetration. */
129624
129721
  crushFactor() {
129625
129722
  return this._inner.crushFactor();
129626
129723
  }
@@ -129631,14 +129728,12 @@ var Body = class _Body {
129631
129728
  return this._inner.toString();
129632
129729
  }
129633
129730
  };
129634
- registerWrapper("Body", Body._wrap);
129635
129731
 
129636
129732
  // src/shape/Circle.ts
129637
129733
  var Circle = class _Circle extends Shape {
129638
129734
  constructor(radius = 50, localCOM, material, filter) {
129639
129735
  super();
129640
- const nape = getNape();
129641
- this._inner = new nape.shape.Circle(
129736
+ this._inner = new (getNape()).shape.Circle(
129642
129737
  radius,
129643
129738
  localCOM?._inner,
129644
129739
  material?._inner,
@@ -129647,10 +129742,11 @@ var Circle = class _Circle extends Shape {
129647
129742
  }
129648
129743
  /** @internal */
129649
129744
  static _wrap(inner) {
129650
- if (!inner) return null;
129651
- const c = Object.create(_Circle.prototype);
129652
- c._inner = inner;
129653
- return c;
129745
+ return getOrCreate(inner, (raw) => {
129746
+ const c = Object.create(_Circle.prototype);
129747
+ c._inner = raw;
129748
+ return c;
129749
+ });
129654
129750
  }
129655
129751
  get radius() {
129656
129752
  return this._inner.get_radius();
@@ -129659,17 +129755,10 @@ var Circle = class _Circle extends Shape {
129659
129755
  this._inner.set_radius(value);
129660
129756
  }
129661
129757
  };
129662
- _registerCircleClass(Circle);
129758
+ _bindCircleWrap((inner) => Circle._wrap(inner));
129663
129759
 
129664
129760
  // src/shape/Polygon.ts
129665
129761
  var Polygon = class _Polygon extends Shape {
129666
- /**
129667
- * Create a polygon from an array of vertices.
129668
- *
129669
- * @param vertices Array of Vec2 or raw Haxe vertex list.
129670
- * @param material Optional material.
129671
- * @param filter Optional interaction filter.
129672
- */
129673
129762
  constructor(vertices, material, filter) {
129674
129763
  super();
129675
129764
  const nape = getNape();
@@ -129685,49 +129774,27 @@ var Polygon = class _Polygon extends Shape {
129685
129774
  }
129686
129775
  /** @internal */
129687
129776
  static _wrap(inner) {
129688
- if (!inner) return null;
129689
- const p = Object.create(_Polygon.prototype);
129690
- p._inner = inner;
129691
- return p;
129777
+ return getOrCreate(inner, (raw) => {
129778
+ const p = Object.create(_Polygon.prototype);
129779
+ p._inner = raw;
129780
+ return p;
129781
+ });
129692
129782
  }
129693
129783
  // ---------------------------------------------------------------------------
129694
- // Static factory methods — return raw Haxe vertex arrays suitable for the
129695
- // Polygon constructor.
129784
+ // Static factory methods
129696
129785
  // ---------------------------------------------------------------------------
129697
- /**
129698
- * Create vertex list for an axis-aligned box centred at the origin.
129699
- *
129700
- * Usage: `new Polygon(Polygon.box(100, 50))`
129701
- */
129702
129786
  static box(width, height, weak = false) {
129703
129787
  return getNape().shape.Polygon.box(width, height, weak);
129704
129788
  }
129705
- /**
129706
- * Create vertex list for a rectangle at the given offset.
129707
- *
129708
- * Usage: `new Polygon(Polygon.rect(x, y, w, h))`
129709
- */
129710
129789
  static rect(x, y, width, height, weak = false) {
129711
129790
  return getNape().shape.Polygon.rect(x, y, width, height, weak);
129712
129791
  }
129713
- /**
129714
- * Create vertex list for a regular polygon (equilateral triangle, hexagon, etc.).
129715
- *
129716
- * @param xRadius Horizontal radius.
129717
- * @param yRadius Vertical radius.
129718
- * @param sides Number of sides.
129719
- * @param angle Starting angle offset (radians).
129720
- * @param weak Whether returned Vec2s are weak.
129721
- */
129722
129792
  static regular(xRadius, yRadius, sides, angle = 0, weak = false) {
129723
- return getNape().shape.Polygon.regular(
129724
- xRadius,
129725
- yRadius,
129726
- sides,
129727
- angle,
129728
- weak
129729
- );
129793
+ return getNape().shape.Polygon.regular(xRadius, yRadius, sides, angle, weak);
129730
129794
  }
129795
+ // ---------------------------------------------------------------------------
129796
+ // Properties
129797
+ // ---------------------------------------------------------------------------
129731
129798
  /** Read-only list of local-space vertices. */
129732
129799
  get localVerts() {
129733
129800
  return this._inner.get_localVerts();
@@ -129745,200 +129812,27 @@ var Polygon = class _Polygon extends Shape {
129745
129812
  return this._inner.validity();
129746
129813
  }
129747
129814
  };
129748
- _registerPolygonClass(Polygon);
129749
-
129750
- // src/space/Space.ts
129751
- var Space = class _Space {
129752
- constructor(gravity) {
129753
- const nape = getNape();
129754
- this._inner = new nape.space.Space(gravity?._inner);
129755
- }
129756
- /** @internal */
129757
- static _wrap(inner) {
129758
- if (!inner) return null;
129759
- const s = Object.create(_Space.prototype);
129760
- s._inner = inner;
129761
- return s;
129762
- }
129763
- // ---------------------------------------------------------------------------
129764
- // Properties
129765
- // ---------------------------------------------------------------------------
129766
- get gravity() {
129767
- return Vec2._wrap(this._inner.get_gravity());
129768
- }
129769
- set gravity(value) {
129770
- this._inner.set_gravity(value._inner);
129771
- }
129772
- get worldLinearDrag() {
129773
- return this._inner.get_worldLinearDrag();
129774
- }
129775
- set worldLinearDrag(value) {
129776
- this._inner.set_worldLinearDrag(value);
129777
- }
129778
- get worldAngularDrag() {
129779
- return this._inner.get_worldAngularDrag();
129780
- }
129781
- set worldAngularDrag(value) {
129782
- this._inner.set_worldAngularDrag(value);
129783
- }
129784
- get sortContacts() {
129785
- return this._inner.get_sortContacts();
129786
- }
129787
- set sortContacts(value) {
129788
- this._inner.set_sortContacts(value);
129789
- }
129790
- get bodies() {
129791
- return new NapeList(this._inner.get_bodies(), Body._wrap);
129792
- }
129793
- get liveBodies() {
129794
- return new NapeList(this._inner.get_liveBodies(), Body._wrap);
129795
- }
129796
- get constraints() {
129797
- return this._inner.get_constraints();
129798
- }
129799
- get liveConstraints() {
129800
- return this._inner.get_liveConstraints();
129801
- }
129802
- get arbiters() {
129803
- return this._inner.get_arbiters();
129804
- }
129805
- get listeners() {
129806
- return this._inner.get_listeners();
129807
- }
129808
- get compounds() {
129809
- return this._inner.get_compounds();
129810
- }
129811
- /** The static world body (always present, immovable). */
129812
- get world() {
129813
- return Body._wrap(this._inner.get_world());
129814
- }
129815
- get timeStamp() {
129816
- return this._inner.get_timeStamp();
129817
- }
129818
- get elapsedTime() {
129819
- return this._inner.get_elapsedTime();
129820
- }
129821
- get broadphase() {
129822
- return this._inner.get_broadphase();
129823
- }
129824
- get userData() {
129825
- return this._inner.get_userData();
129826
- }
129827
- // ---------------------------------------------------------------------------
129828
- // Simulation
129829
- // ---------------------------------------------------------------------------
129830
- /**
129831
- * Advance the simulation by one time step.
129832
- *
129833
- * @param deltaTime Time to advance (seconds), e.g. 1/60.
129834
- * @param velocityIterations Velocity solver iterations (default 10).
129835
- * @param positionIterations Position solver iterations (default 10).
129836
- */
129837
- step(deltaTime, velocityIterations = 10, positionIterations = 10) {
129838
- this._inner.step(deltaTime, velocityIterations, positionIterations);
129839
- }
129840
- /** Remove all bodies, constraints, and listeners. */
129841
- clear() {
129842
- this._inner.clear();
129843
- }
129844
- // ---------------------------------------------------------------------------
129845
- // Visitors
129846
- // ---------------------------------------------------------------------------
129847
- /** Call `fn` for every body in the space. */
129848
- visitBodies(fn) {
129849
- this._inner.visitBodies((raw) => fn(Body._wrap(raw)));
129850
- }
129851
- /** Call `fn` for every constraint in the space. */
129852
- visitConstraints(fn) {
129853
- this._inner.visitConstraints(fn);
129854
- }
129855
- /** Call `fn` for every compound in the space. */
129856
- visitCompounds(fn) {
129857
- this._inner.visitCompounds(fn);
129858
- }
129859
- // ---------------------------------------------------------------------------
129860
- // Queries
129861
- // ---------------------------------------------------------------------------
129862
- /** Find shapes under a world-space point. */
129863
- shapesUnderPoint(point, filter, output) {
129864
- return this._inner.shapesUnderPoint(
129865
- point._inner,
129866
- filter?._inner ?? filter,
129867
- output
129868
- );
129869
- }
129870
- /** Find bodies under a world-space point. */
129871
- bodiesUnderPoint(point, filter, output) {
129872
- return this._inner.bodiesUnderPoint(
129873
- point._inner,
129874
- filter?._inner ?? filter,
129875
- output
129876
- );
129877
- }
129878
- /** Find shapes inside an AABB. */
129879
- shapesInAABB(aabb, containment, strict, filter, output) {
129880
- return this._inner.shapesInAABB(
129881
- aabb._inner,
129882
- containment,
129883
- strict,
129884
- filter?._inner ?? filter,
129885
- output
129886
- );
129887
- }
129888
- /** Find bodies inside an AABB. */
129889
- bodiesInAABB(aabb, containment, strict, filter, output) {
129890
- return this._inner.bodiesInAABB(
129891
- aabb._inner,
129892
- containment,
129893
- strict,
129894
- filter?._inner ?? filter,
129895
- output
129896
- );
129897
- }
129898
- /** Cast a ray into the space. */
129899
- rayCast(ray, inner, filter) {
129900
- return this._inner.rayCast(
129901
- ray?._inner ?? ray,
129902
- inner,
129903
- filter?._inner ?? filter
129904
- );
129905
- }
129906
- /** Cast a ray and return all hits. */
129907
- rayMultiCast(ray, inner, filter, output) {
129908
- return this._inner.rayMultiCast(
129909
- ray?._inner ?? ray,
129910
- inner,
129911
- filter?._inner ?? filter,
129912
- output
129913
- );
129914
- }
129915
- toString() {
129916
- return `Space(bodies=${this.bodies.length})`;
129917
- }
129918
- };
129919
- registerWrapper("Space", Space._wrap);
129815
+ _bindPolygonWrap((inner) => Polygon._wrap(inner));
129920
129816
 
129921
129817
  // src/dynamics/InteractionGroup.ts
129922
129818
  var InteractionGroup = class _InteractionGroup {
129923
129819
  constructor(ignore = false) {
129924
- const nape = getNape();
129925
- this._inner = new nape.dynamics.InteractionGroup(ignore);
129820
+ this._inner = new (getNape()).dynamics.InteractionGroup(ignore);
129926
129821
  }
129927
129822
  /** @internal */
129928
129823
  static _wrap(inner) {
129929
- if (!inner) return null;
129930
- const g = Object.create(_InteractionGroup.prototype);
129931
- g._inner = inner;
129932
- return g;
129824
+ return getOrCreate(inner, (raw) => {
129825
+ const g = Object.create(_InteractionGroup.prototype);
129826
+ g._inner = raw;
129827
+ return g;
129828
+ });
129933
129829
  }
129934
- /** Parent group. */
129935
129830
  get group() {
129936
129831
  return _InteractionGroup._wrap(this._inner.get_group());
129937
129832
  }
129938
129833
  set group(value) {
129939
129834
  this._inner.set_group(value?._inner ?? null);
129940
129835
  }
129941
- /** If true, interactions between members of this group are ignored. */
129942
129836
  get ignore() {
129943
129837
  return this._inner.get_ignore();
129944
129838
  }
@@ -129984,15 +129878,15 @@ function toNativeCbEvent(event) {
129984
129878
  // src/callbacks/CbType.ts
129985
129879
  var CbType = class _CbType {
129986
129880
  constructor() {
129987
- const nape = getNape();
129988
- this._inner = new nape.callbacks.CbType();
129881
+ this._inner = new (getNape()).callbacks.CbType();
129989
129882
  }
129990
129883
  /** @internal */
129991
129884
  static _wrap(inner) {
129992
- if (!inner) return null;
129993
- const c = Object.create(_CbType.prototype);
129994
- c._inner = inner;
129995
- return c;
129885
+ return getOrCreate(inner, (raw) => {
129886
+ const c = Object.create(_CbType.prototype);
129887
+ c._inner = raw;
129888
+ return c;
129889
+ });
129996
129890
  }
129997
129891
  /** Built-in type matching any body. */
129998
129892
  static get ANY_BODY() {
@@ -130073,10 +129967,11 @@ var OptionType = class _OptionType {
130073
129967
  }
130074
129968
  /** @internal */
130075
129969
  static _wrap(inner) {
130076
- if (!inner) return null;
130077
- const o = Object.create(_OptionType.prototype);
130078
- o._inner = inner;
130079
- return o;
129970
+ return getOrCreate(inner, (raw) => {
129971
+ const o = Object.create(_OptionType.prototype);
129972
+ o._inner = raw;
129973
+ return o;
129974
+ });
130080
129975
  }
130081
129976
  };
130082
129977
 
@@ -130084,16 +129979,18 @@ var OptionType = class _OptionType {
130084
129979
  var Listener = class _Listener {
130085
129980
  /** @internal */
130086
129981
  constructor() {
129982
+ this._inner = void 0;
130087
129983
  }
130088
129984
  /** @internal */
130089
129985
  static _wrap(inner) {
130090
- if (!inner) return null;
130091
- const l = Object.create(_Listener.prototype);
130092
- l._inner = inner;
130093
- return l;
129986
+ return getOrCreate(inner, (raw) => {
129987
+ const l = Object.create(_Listener.prototype);
129988
+ l._inner = raw;
129989
+ return l;
129990
+ });
130094
129991
  }
130095
129992
  get space() {
130096
- return wrapWith("Space", this._inner.get_space());
129993
+ return Space._wrap(this._inner.get_space());
130097
129994
  }
130098
129995
  set space(value) {
130099
129996
  this._inner.set_space(value?._inner ?? null);
@@ -130125,8 +130022,7 @@ var BodyListener = class _BodyListener extends Listener {
130125
130022
  */
130126
130023
  constructor(event, options, handler, precedence = 0) {
130127
130024
  super();
130128
- const nape = getNape();
130129
- this._inner = new nape.callbacks.BodyListener(
130025
+ this._inner = new (getNape()).callbacks.BodyListener(
130130
130026
  toNativeCbEvent(event),
130131
130027
  options._inner,
130132
130028
  handler,
@@ -130135,10 +130031,11 @@ var BodyListener = class _BodyListener extends Listener {
130135
130031
  }
130136
130032
  /** @internal */
130137
130033
  static _wrap(inner) {
130138
- if (!inner) return null;
130139
- const l = Object.create(_BodyListener.prototype);
130140
- l._inner = inner;
130141
- return l;
130034
+ return getOrCreate(inner, (raw) => {
130035
+ const l = Object.create(_BodyListener.prototype);
130036
+ l._inner = raw;
130037
+ return l;
130038
+ });
130142
130039
  }
130143
130040
  };
130144
130041
 
@@ -130154,8 +130051,7 @@ var InteractionListener = class _InteractionListener extends Listener {
130154
130051
  */
130155
130052
  constructor(event, interactionType, options1, options2, handler, precedence = 0) {
130156
130053
  super();
130157
- const nape = getNape();
130158
- this._inner = new nape.callbacks.InteractionListener(
130054
+ this._inner = new (getNape()).callbacks.InteractionListener(
130159
130055
  toNativeCbEvent(event),
130160
130056
  toNativeInteractionType(interactionType),
130161
130057
  options1._inner,
@@ -130166,12 +130062,13 @@ var InteractionListener = class _InteractionListener extends Listener {
130166
130062
  }
130167
130063
  /** @internal */
130168
130064
  static _wrap(inner) {
130169
- if (!inner) return null;
130170
- const l = Object.create(
130171
- _InteractionListener.prototype
130172
- );
130173
- l._inner = inner;
130174
- return l;
130065
+ return getOrCreate(inner, (raw) => {
130066
+ const l = Object.create(
130067
+ _InteractionListener.prototype
130068
+ );
130069
+ l._inner = raw;
130070
+ return l;
130071
+ });
130175
130072
  }
130176
130073
  };
130177
130074
 
@@ -130179,8 +130076,7 @@ var InteractionListener = class _InteractionListener extends Listener {
130179
130076
  var ConstraintListener = class _ConstraintListener extends Listener {
130180
130077
  constructor(event, options, handler, precedence = 0) {
130181
130078
  super();
130182
- const nape = getNape();
130183
- this._inner = new nape.callbacks.ConstraintListener(
130079
+ this._inner = new (getNape()).callbacks.ConstraintListener(
130184
130080
  toNativeCbEvent(event),
130185
130081
  options._inner,
130186
130082
  handler,
@@ -130189,12 +130085,13 @@ var ConstraintListener = class _ConstraintListener extends Listener {
130189
130085
  }
130190
130086
  /** @internal */
130191
130087
  static _wrap(inner) {
130192
- if (!inner) return null;
130193
- const l = Object.create(
130194
- _ConstraintListener.prototype
130195
- );
130196
- l._inner = inner;
130197
- return l;
130088
+ return getOrCreate(inner, (raw) => {
130089
+ const l = Object.create(
130090
+ _ConstraintListener.prototype
130091
+ );
130092
+ l._inner = raw;
130093
+ return l;
130094
+ });
130198
130095
  }
130199
130096
  };
130200
130097
 
@@ -130202,7 +130099,6 @@ var ConstraintListener = class _ConstraintListener extends Listener {
130202
130099
  var PreListener = class _PreListener extends Listener {
130203
130100
  constructor(interactionType, options1, options2, handler, precedence = 0, pure = false) {
130204
130101
  super();
130205
- const nape = getNape();
130206
130102
  const wrappedHandler = (cb) => {
130207
130103
  const result = handler(cb);
130208
130104
  if (typeof result === "string" && result in PreFlag) {
@@ -130210,7 +130106,7 @@ var PreListener = class _PreListener extends Listener {
130210
130106
  }
130211
130107
  return result;
130212
130108
  };
130213
- this._inner = new nape.callbacks.PreListener(
130109
+ this._inner = new (getNape()).callbacks.PreListener(
130214
130110
  toNativeInteractionType(interactionType),
130215
130111
  options1._inner,
130216
130112
  options2._inner,
@@ -130221,10 +130117,11 @@ var PreListener = class _PreListener extends Listener {
130221
130117
  }
130222
130118
  /** @internal */
130223
130119
  static _wrap(inner) {
130224
- if (!inner) return null;
130225
- const l = Object.create(_PreListener.prototype);
130226
- l._inner = inner;
130227
- return l;
130120
+ return getOrCreate(inner, (raw) => {
130121
+ const l = Object.create(_PreListener.prototype);
130122
+ l._inner = raw;
130123
+ return l;
130124
+ });
130228
130125
  }
130229
130126
  };
130230
130127
 
@@ -130232,19 +130129,21 @@ var PreListener = class _PreListener extends Listener {
130232
130129
  var Constraint = class _Constraint {
130233
130130
  /** @internal */
130234
130131
  constructor() {
130132
+ this._inner = void 0;
130235
130133
  }
130236
130134
  /** @internal */
130237
130135
  static _wrap(inner) {
130238
- if (!inner) return null;
130239
- const c = Object.create(_Constraint.prototype);
130240
- c._inner = inner;
130241
- return c;
130136
+ return getOrCreate(inner, (raw) => {
130137
+ const c = Object.create(_Constraint.prototype);
130138
+ c._inner = raw;
130139
+ return c;
130140
+ });
130242
130141
  }
130243
130142
  // ---------------------------------------------------------------------------
130244
130143
  // Properties common to all constraints
130245
130144
  // ---------------------------------------------------------------------------
130246
130145
  get space() {
130247
- return wrapWith("Space", this._inner.get_space());
130146
+ return Space._wrap(this._inner.get_space());
130248
130147
  }
130249
130148
  set space(value) {
130250
130149
  this._inner.set_space(value?._inner ?? null);
@@ -130342,8 +130241,7 @@ var Constraint = class _Constraint {
130342
130241
  var PivotJoint = class _PivotJoint extends Constraint {
130343
130242
  constructor(body1, body2, anchor1, anchor2) {
130344
130243
  super();
130345
- const nape = getNape();
130346
- this._inner = new nape.constraint.PivotJoint(
130244
+ this._inner = new (getNape()).constraint.PivotJoint(
130347
130245
  body1?._inner ?? null,
130348
130246
  body2?._inner ?? null,
130349
130247
  anchor1._inner,
@@ -130352,10 +130250,11 @@ var PivotJoint = class _PivotJoint extends Constraint {
130352
130250
  }
130353
130251
  /** @internal */
130354
130252
  static _wrap(inner) {
130355
- if (!inner) return null;
130356
- const j = Object.create(_PivotJoint.prototype);
130357
- j._inner = inner;
130358
- return j;
130253
+ return getOrCreate(inner, (raw) => {
130254
+ const j = Object.create(_PivotJoint.prototype);
130255
+ j._inner = raw;
130256
+ return j;
130257
+ });
130359
130258
  }
130360
130259
  get body1() {
130361
130260
  return Body._wrap(this._inner.get_body1());
@@ -130387,8 +130286,7 @@ var PivotJoint = class _PivotJoint extends Constraint {
130387
130286
  var DistanceJoint = class _DistanceJoint extends Constraint {
130388
130287
  constructor(body1, body2, anchor1, anchor2, jointMin, jointMax) {
130389
130288
  super();
130390
- const nape = getNape();
130391
- this._inner = new nape.constraint.DistanceJoint(
130289
+ this._inner = new (getNape()).constraint.DistanceJoint(
130392
130290
  body1?._inner ?? null,
130393
130291
  body2?._inner ?? null,
130394
130292
  anchor1._inner,
@@ -130399,10 +130297,11 @@ var DistanceJoint = class _DistanceJoint extends Constraint {
130399
130297
  }
130400
130298
  /** @internal */
130401
130299
  static _wrap(inner) {
130402
- if (!inner) return null;
130403
- const j = Object.create(_DistanceJoint.prototype);
130404
- j._inner = inner;
130405
- return j;
130300
+ return getOrCreate(inner, (raw) => {
130301
+ const j = Object.create(_DistanceJoint.prototype);
130302
+ j._inner = raw;
130303
+ return j;
130304
+ });
130406
130305
  }
130407
130306
  get body1() {
130408
130307
  return Body._wrap(this._inner.get_body1());
@@ -130446,8 +130345,7 @@ var DistanceJoint = class _DistanceJoint extends Constraint {
130446
130345
  var AngleJoint = class _AngleJoint extends Constraint {
130447
130346
  constructor(body1, body2, jointMin, jointMax, ratio = 1) {
130448
130347
  super();
130449
- const nape = getNape();
130450
- this._inner = new nape.constraint.AngleJoint(
130348
+ this._inner = new (getNape()).constraint.AngleJoint(
130451
130349
  body1?._inner ?? null,
130452
130350
  body2?._inner ?? null,
130453
130351
  jointMin,
@@ -130457,10 +130355,11 @@ var AngleJoint = class _AngleJoint extends Constraint {
130457
130355
  }
130458
130356
  /** @internal */
130459
130357
  static _wrap(inner) {
130460
- if (!inner) return null;
130461
- const j = Object.create(_AngleJoint.prototype);
130462
- j._inner = inner;
130463
- return j;
130358
+ return getOrCreate(inner, (raw) => {
130359
+ const j = Object.create(_AngleJoint.prototype);
130360
+ j._inner = raw;
130361
+ return j;
130362
+ });
130464
130363
  }
130465
130364
  get body1() {
130466
130365
  return Body._wrap(this._inner.get_body1());
@@ -130498,8 +130397,7 @@ var AngleJoint = class _AngleJoint extends Constraint {
130498
130397
  var WeldJoint = class _WeldJoint extends Constraint {
130499
130398
  constructor(body1, body2, anchor1, anchor2, phase = 0) {
130500
130399
  super();
130501
- const nape = getNape();
130502
- this._inner = new nape.constraint.WeldJoint(
130400
+ this._inner = new (getNape()).constraint.WeldJoint(
130503
130401
  body1?._inner ?? null,
130504
130402
  body2?._inner ?? null,
130505
130403
  anchor1._inner,
@@ -130509,10 +130407,11 @@ var WeldJoint = class _WeldJoint extends Constraint {
130509
130407
  }
130510
130408
  /** @internal */
130511
130409
  static _wrap(inner) {
130512
- if (!inner) return null;
130513
- const j = Object.create(_WeldJoint.prototype);
130514
- j._inner = inner;
130515
- return j;
130410
+ return getOrCreate(inner, (raw) => {
130411
+ const j = Object.create(_WeldJoint.prototype);
130412
+ j._inner = raw;
130413
+ return j;
130414
+ });
130516
130415
  }
130517
130416
  get body1() {
130518
130417
  return Body._wrap(this._inner.get_body1());
@@ -130550,8 +130449,7 @@ var WeldJoint = class _WeldJoint extends Constraint {
130550
130449
  var MotorJoint = class _MotorJoint extends Constraint {
130551
130450
  constructor(body1, body2, rate, ratio = 1) {
130552
130451
  super();
130553
- const nape = getNape();
130554
- this._inner = new nape.constraint.MotorJoint(
130452
+ this._inner = new (getNape()).constraint.MotorJoint(
130555
130453
  body1?._inner ?? null,
130556
130454
  body2?._inner ?? null,
130557
130455
  rate,
@@ -130560,10 +130458,11 @@ var MotorJoint = class _MotorJoint extends Constraint {
130560
130458
  }
130561
130459
  /** @internal */
130562
130460
  static _wrap(inner) {
130563
- if (!inner) return null;
130564
- const j = Object.create(_MotorJoint.prototype);
130565
- j._inner = inner;
130566
- return j;
130461
+ return getOrCreate(inner, (raw) => {
130462
+ const j = Object.create(_MotorJoint.prototype);
130463
+ j._inner = raw;
130464
+ return j;
130465
+ });
130567
130466
  }
130568
130467
  get body1() {
130569
130468
  return Body._wrap(this._inner.get_body1());
@@ -130595,8 +130494,7 @@ var MotorJoint = class _MotorJoint extends Constraint {
130595
130494
  var LineJoint = class _LineJoint extends Constraint {
130596
130495
  constructor(body1, body2, anchor1, anchor2, direction, jointMin, jointMax) {
130597
130496
  super();
130598
- const nape = getNape();
130599
- this._inner = new nape.constraint.LineJoint(
130497
+ this._inner = new (getNape()).constraint.LineJoint(
130600
130498
  body1?._inner ?? null,
130601
130499
  body2?._inner ?? null,
130602
130500
  anchor1._inner,
@@ -130608,10 +130506,11 @@ var LineJoint = class _LineJoint extends Constraint {
130608
130506
  }
130609
130507
  /** @internal */
130610
130508
  static _wrap(inner) {
130611
- if (!inner) return null;
130612
- const j = Object.create(_LineJoint.prototype);
130613
- j._inner = inner;
130614
- return j;
130509
+ return getOrCreate(inner, (raw) => {
130510
+ const j = Object.create(_LineJoint.prototype);
130511
+ j._inner = raw;
130512
+ return j;
130513
+ });
130615
130514
  }
130616
130515
  get body1() {
130617
130516
  return Body._wrap(this._inner.get_body1());
@@ -130661,8 +130560,7 @@ var LineJoint = class _LineJoint extends Constraint {
130661
130560
  var PulleyJoint = class _PulleyJoint extends Constraint {
130662
130561
  constructor(body1, body2, body3, body4, anchor1, anchor2, anchor3, anchor4, jointMin, jointMax, ratio = 1) {
130663
130562
  super();
130664
- const nape = getNape();
130665
- this._inner = new nape.constraint.PulleyJoint(
130563
+ this._inner = new (getNape()).constraint.PulleyJoint(
130666
130564
  body1?._inner ?? null,
130667
130565
  body2?._inner ?? null,
130668
130566
  body3?._inner ?? null,
@@ -130678,10 +130576,11 @@ var PulleyJoint = class _PulleyJoint extends Constraint {
130678
130576
  }
130679
130577
  /** @internal */
130680
130578
  static _wrap(inner) {
130681
- if (!inner) return null;
130682
- const j = Object.create(_PulleyJoint.prototype);
130683
- j._inner = inner;
130684
- return j;
130579
+ return getOrCreate(inner, (raw) => {
130580
+ const j = Object.create(_PulleyJoint.prototype);
130581
+ j._inner = raw;
130582
+ return j;
130583
+ });
130685
130584
  }
130686
130585
  get body1() {
130687
130586
  return Body._wrap(this._inner.get_body1());