dredless 1.4.1 → 1.5.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.
@@ -218,8 +218,8 @@
218
218
  resolveUrl = (baseUrl, path = "") => new URL(String(path).replace(/^\//, ""), `${normalizeBaseUrl(baseUrl)}/`).href;
219
219
  hostName = (baseUrl) => new URL(normalizeBaseUrl(baseUrl)).hostname;
220
220
  asNumber = (value, fallback = 0) => {
221
- const number = Number(value);
222
- return Number.isFinite(number) ? number : fallback;
221
+ const number2 = Number(value);
222
+ return Number.isFinite(number2) ? number2 : fallback;
223
223
  };
224
224
  wsModulePromise = null;
225
225
  }
@@ -774,6 +774,14 @@
774
774
  }
775
775
  });
776
776
 
777
+ // src/protocol/codec/ui-integer.js
778
+ function encodeUnsigned(value) {
779
+ if (value < 64) return [value];
780
+ if (value < 256) return [128, value];
781
+ if (value < 65536) return [129, value & 255, value >>> 8];
782
+ return [130, value & 255, value >>> 8 & 255, value >>> 16 & 255, value >>> 24];
783
+ }
784
+
777
785
  // src/protocol/outbound/machine-config.js
778
786
  init_constants();
779
787
  function uint32(value, name) {
@@ -782,25 +790,19 @@
782
790
  }
783
791
  return value;
784
792
  }
785
- function encodeUnsigned(value) {
786
- if (value < 64) return [value];
787
- if (value < 256) return [128, value];
788
- if (value < 65536) return [129, value & 255, value >>> 8];
789
- return [130, value & 255, value >>> 8 & 255, value >>> 16 & 255, value >>> 24];
790
- }
791
793
  function encodeFloat(value, name, max) {
792
794
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > max) {
793
795
  throw new RangeError(`${name} must be a finite number between 0 and ${max}`);
794
796
  }
795
- const number = Math.fround(value);
796
- if (Number.isInteger(number)) {
797
- if (number < 64) return [number];
798
- if (number < 128) return [132, number];
799
- return [133, number & 255, number >>> 8];
797
+ const number2 = Math.fround(value);
798
+ if (Number.isInteger(number2)) {
799
+ if (number2 < 64) return [number2];
800
+ if (number2 < 128) return [132, number2];
801
+ return [133, number2 & 255, number2 >>> 8];
800
802
  }
801
803
  const bytes = new Uint8Array(5);
802
804
  bytes[0] = 136;
803
- new DataView(bytes.buffer).setFloat32(1, number, true);
805
+ new DataView(bytes.buffer).setFloat32(1, number2, true);
804
806
  return [...bytes];
805
807
  }
806
808
  function section(name, values) {
@@ -951,8 +953,8 @@
951
953
  });
952
954
  }
953
955
  var DisconnectError = class extends Error {
954
- constructor(disconnect, message2 = "Disconnected") {
955
- super(`${message2}: ${disconnect.name ?? "Unknown"} (${disconnect.code})${disconnect.reason ? ` \u2014 ${disconnect.reason}` : ""}`);
956
+ constructor(disconnect, message3 = "Disconnected") {
957
+ super(`${message3}: ${disconnect.name ?? "Unknown"} (${disconnect.code})${disconnect.reason ? ` \u2014 ${disconnect.reason}` : ""}`);
956
958
  this.name = "DisconnectError";
957
959
  this.disconnect = disconnect;
958
960
  }
@@ -2103,7 +2105,7 @@
2103
2105
  {
2104
2106
  "id": 219,
2105
2107
  "name": "Spawn Point (Packaged)",
2106
- "desc": "Buildable. Can be set to spawn a specific rank.",
2108
+ "desc": "Buildable. Can be set to spawn specific ranks.",
2107
2109
  "image": "item/spawn",
2108
2110
  "rarity": 0,
2109
2111
  "max_stack": 1,
@@ -2124,7 +2126,7 @@
2124
2126
  {
2125
2127
  "id": 220,
2126
2128
  "name": "Door (Packaged)",
2127
- "desc": "Buildable. Can be restricted to specific ranks. Press R to rotate.",
2129
+ "desc": "Buildable. Can be restricted to specific ranks.",
2128
2130
  "image": "item/door",
2129
2131
  "rarity": 0,
2130
2132
  "max_stack": 1,
@@ -2803,6 +2805,22 @@
2803
2805
  "rarity": 1,
2804
2806
  "max_stack": 1
2805
2807
  },
2808
+ {
2809
+ "id": 266,
2810
+ "name": "Advanced Expando Box (Packaged)",
2811
+ "desc": "Buildable. Dense bulk storage with configurable size limits. Spills more items when shot.",
2812
+ "image": "item/exbox_adv",
2813
+ "rarity": 2,
2814
+ "max_stack": 1
2815
+ },
2816
+ {
2817
+ "id": 267,
2818
+ "name": "Advanced Logistics Controller",
2819
+ "desc": "Component. Used to produce advanced logistics machinery.",
2820
+ "image": "item/adv_logi_controller",
2821
+ "rarity": 2,
2822
+ "max_stack": 1
2823
+ },
2806
2824
  {
2807
2825
  "id": 300,
2808
2826
  "name": "Eternal Bronze Wrench",
@@ -3427,6 +3445,7 @@
3427
3445
  }
3428
3446
  function toUint8Array(value) {
3429
3447
  if (value instanceof Uint8Array) return value;
3448
+ if (value instanceof ArrayBuffer) return new Uint8Array(value);
3430
3449
  if (isArrayBufferLike(value)) return new Uint8Array(value);
3431
3450
  if (ArrayBuffer.isView(value)) {
3432
3451
  return new Uint8Array(value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength));
@@ -3729,18 +3748,32 @@
3729
3748
  }
3730
3749
  return chacha20Into(out, key, nonce, data.length, data);
3731
3750
  }
3751
+ var WORLD_KEY_CACHE = /* @__PURE__ */ new Map();
3752
+ var WORLD_KEY_CACHE_LIMIT = 64;
3753
+ var MATERIAL_SCRATCH = new Uint8Array(44);
3754
+ function worldKeyBytes(worldId, seed) {
3755
+ const text2 = `${worldId}${seed}`;
3756
+ let bytes = WORLD_KEY_CACHE.get(text2);
3757
+ if (!bytes) {
3758
+ if (WORLD_KEY_CACHE.size >= WORLD_KEY_CACHE_LIMIT) WORLD_KEY_CACHE.clear();
3759
+ bytes = encoder.encode(text2);
3760
+ WORLD_KEY_CACHE.set(text2, bytes);
3761
+ }
3762
+ return bytes;
3763
+ }
3732
3764
  function decryptPayload(wireBytes, worldId, seed) {
3733
3765
  const wire = toUint8Array(wireBytes);
3734
- if (wire.length < 8) throw new Error("payload too short");
3735
- const view = new DataView(wire.buffer, wire.byteOffset, wire.byteLength);
3736
- const packetWordA = view.getUint32(0, true);
3737
- const packetWordB = view.getUint32(wire.length - 4, true);
3738
- const material = Uint8Array.from(SHARED_CHACHA_MATERIAL);
3739
- const worldKey = encoder.encode(`${worldId}${seed}`);
3766
+ const length = wire.length;
3767
+ if (length < 8) throw new Error("payload too short");
3768
+ const packetWordA = readLe32(wire, 0);
3769
+ const packetWordB = readLe32(wire, length - 4);
3770
+ const material = MATERIAL_SCRATCH;
3771
+ const worldKey = worldKeyBytes(worldId, seed);
3772
+ const keyLength = worldKey.length;
3740
3773
  for (let i = 0, l = 0, r = 0; i < 44; i++, l += 7, r += 11) {
3741
- material[i] ^= worldKey[i % worldKey.length] ^ rotl32(packetWordA, l) & 255 ^ rotr32(packetWordB, r) & 255;
3774
+ material[i] = SHARED_CHACHA_MATERIAL[i] ^ worldKey[i % keyLength] ^ rotl32(packetWordA, l) & 255 ^ rotr32(packetWordB, r) & 255;
3742
3775
  }
3743
- const ciphertext = wire.subarray(4, wire.length - 4);
3776
+ const ciphertext = wire.subarray(4, length - 4);
3744
3777
  return chacha20Xor(material.subarray(0, 32), material.subarray(32, 44), ciphertext);
3745
3778
  }
3746
3779
 
@@ -3785,35 +3818,35 @@
3785
3818
  return out;
3786
3819
  }
3787
3820
  function encodeNumberWithFormat(value, format) {
3788
- const number = Number(value);
3821
+ const number2 = Number(value);
3789
3822
  switch (format) {
3790
3823
  case "positive-fixint":
3791
- return Uint8Array.of(number & 127);
3824
+ return Uint8Array.of(number2 & 127);
3792
3825
  case "negative-fixint":
3793
- return Uint8Array.of(number & 255);
3826
+ return Uint8Array.of(number2 & 255);
3794
3827
  case "uint8":
3795
- return Uint8Array.of(204, number & 255);
3828
+ return Uint8Array.of(204, number2 & 255);
3796
3829
  case "uint16":
3797
- return Uint8Array.of(205, number >>> 8 & 255, number & 255);
3830
+ return Uint8Array.of(205, number2 >>> 8 & 255, number2 & 255);
3798
3831
  case "uint32":
3799
- return Uint8Array.of(206, number >>> 24 & 255, number >>> 16 & 255, number >>> 8 & 255, number & 255);
3832
+ return Uint8Array.of(206, number2 >>> 24 & 255, number2 >>> 16 & 255, number2 >>> 8 & 255, number2 & 255);
3800
3833
  case "int8":
3801
- return Uint8Array.of(208, number & 255);
3834
+ return Uint8Array.of(208, number2 & 255);
3802
3835
  case "int16":
3803
- return Uint8Array.of(209, number >> 8 & 255, number & 255);
3836
+ return Uint8Array.of(209, number2 >> 8 & 255, number2 & 255);
3804
3837
  case "int32":
3805
- return Uint8Array.of(210, number >> 24 & 255, number >> 16 & 255, number >> 8 & 255, number & 255);
3838
+ return Uint8Array.of(210, number2 >> 24 & 255, number2 >> 16 & 255, number2 >> 8 & 255, number2 & 255);
3806
3839
  case "float64": {
3807
3840
  const out = new Uint8Array(9);
3808
3841
  out[0] = 203;
3809
- new DataView(out.buffer).setFloat64(1, number, false);
3842
+ new DataView(out.buffer).setFloat64(1, number2, false);
3810
3843
  return out;
3811
3844
  }
3812
3845
  case "float32":
3813
3846
  default: {
3814
3847
  const out = new Uint8Array(5);
3815
3848
  out[0] = 202;
3816
- new DataView(out.buffer).setFloat32(1, number, false);
3849
+ new DataView(out.buffer).setFloat32(1, number2, false);
3817
3850
  return out;
3818
3851
  }
3819
3852
  }
@@ -3957,10 +3990,36 @@
3957
3990
  for (let i = 0; i < count; i++) items[i] = readFast(bytes);
3958
3991
  return items;
3959
3992
  }
3993
+ var KEY_CACHE = /* @__PURE__ */ new Map();
3994
+ var KEY_CACHE_LIMIT = 512;
3995
+ function readKeyFast(bytes) {
3996
+ const head = bytes[cursor];
3997
+ if ((head & 224) !== 160) return readFast(bytes);
3998
+ const len = head & 31;
3999
+ const start = cursor + 1;
4000
+ const end = start + len;
4001
+ if (end > bytes.length) return readFast(bytes);
4002
+ let hash = len;
4003
+ for (let i = start; i < end; i++) hash = Math.imul(hash, 31) + bytes[i] | 0;
4004
+ const entry = KEY_CACHE.get(hash);
4005
+ if (entry !== void 0) {
4006
+ const cached = entry.bytes;
4007
+ let same = cached.length === len;
4008
+ for (let i = 0; same && i < len; i++) same = cached[i] === bytes[start + i];
4009
+ if (same) {
4010
+ cursor = end;
4011
+ return entry.text;
4012
+ }
4013
+ }
4014
+ cursor = start;
4015
+ const text2 = readStrFast(bytes, len);
4016
+ if (entry === void 0 && KEY_CACHE.size < KEY_CACHE_LIMIT) KEY_CACHE.set(hash, { bytes: bytes.slice(start, end), text: text2 });
4017
+ return text2;
4018
+ }
3960
4019
  function readMapFast(bytes, count) {
3961
4020
  const obj = {};
3962
4021
  for (let i = 0; i < count; i++) {
3963
- const key = readFast(bytes);
4022
+ const key = readKeyFast(bytes);
3964
4023
  obj[typeof key === "string" ? key : String(key)] = readFast(bytes);
3965
4024
  }
3966
4025
  return obj;
@@ -4609,12 +4668,14 @@
4609
4668
  if (!resolved) {
4610
4669
  cached = compute();
4611
4670
  resolved = true;
4671
+ compute = null;
4612
4672
  }
4613
4673
  return cached;
4614
4674
  },
4615
4675
  set(value) {
4616
4676
  cached = value;
4617
4677
  resolved = true;
4678
+ compute = null;
4618
4679
  }
4619
4680
  });
4620
4681
  return target;
@@ -5009,12 +5070,23 @@
5009
5070
  // Append new wire components without shifting stable Dredless table IDs.
5010
5071
  [79, { name: "launcher_config", defaults: { q20: 0, q24: 300 }, fields: numericFields({ 1: 20, 2: 24 }) }],
5011
5072
  [80, { name: "rank_filter", defaults: { q20: 4 }, fields: numericFields({ 1: 20 }) }],
5012
- [81, { name: "spawn_point", fields: [] }]
5073
+ [81, { name: "spawn_point", fields: [] }],
5074
+ // Official production WASM e0ed7795 (2026-11-14), dispatcher tags 173/174.
5075
+ // Keep the wire field names until their public domain semantics are exposed.
5076
+ [82, {
5077
+ name: "advanced_expando_size_config",
5078
+ defaults: { q20: 20, q24: 100, q28: 20, q32: 100, q36: 0, q37: 0, q38: 0, q39: 0 },
5079
+ packedBeforeValues: true,
5080
+ packedBits: [{ bit: 16, offset: 37 }, { bit: 32, offset: 38 }, { bit: 64, offset: 39 }],
5081
+ fields: numericFields({ 1: 20, 2: 24, 4: 28, 8: 32 })
5082
+ }],
5083
+ [83, { name: "advanced_expando_color_config", defaults: { q20: 14540253, q24: 4210752, q28: 100, q32: 0 }, fields: numericFields({ 1: 20, 2: 24, 4: 28 }) }]
5013
5084
  ]);
5014
5085
  for (const spec of MODEL_TABLE_SPECS.values()) {
5015
5086
  for (const blob of spec.blobs || []) blob.key = blobKey(blob.offset);
5016
5087
  for (const item of spec.packedBits || []) item.key = qKey(item.offset);
5017
5088
  if (spec.packedOffsets) spec.packedOffsetKeys = spec.packedOffsets.map(qKey);
5089
+ spec.packedAnyMask = (spec.packedBits || []).reduce((mask, item) => mask | item.bit, spec.packedMask || 0);
5018
5090
  if (spec.orderedValues) {
5019
5091
  spec.orderedItems = [
5020
5092
  ...(spec.blobs || []).map((item) => ({ bit: item.bit, offset: item.offset, key: item.key, kind: "blob" })),
@@ -5109,7 +5181,9 @@
5109
5181
  [169, 77],
5110
5182
  [170, 79],
5111
5183
  [171, 80],
5112
- [172, 81]
5184
+ [172, 81],
5185
+ [173, 82],
5186
+ [174, 83]
5113
5187
  ]);
5114
5188
  var MASK_ONLY_TABLES = /* @__PURE__ */ new Set([13, 22, 23, 27, 28, 30, 36, 40, 46, 48, 52, 58, 64, 65, 66, 68, 73, 74]);
5115
5189
  var ENTITY_FOOTPRINTS = /* @__PURE__ */ new Map([
@@ -5160,7 +5234,8 @@
5160
5234
  261,
5161
5235
  263,
5162
5236
  264,
5163
- 265
5237
+ 265,
5238
+ 266
5164
5239
  ]);
5165
5240
  var FabricatorType = Object.freeze({
5166
5241
  Starter: "starter",
@@ -5311,9 +5386,9 @@
5311
5386
  }
5312
5387
  function boundedProgress(value) {
5313
5388
  if (value == null) return null;
5314
- const number = Number(value);
5315
- if (!Number.isFinite(number)) return null;
5316
- return Math.max(0, Math.min(100, number));
5389
+ const number2 = Number(value);
5390
+ if (!Number.isFinite(number2)) return null;
5391
+ return Math.max(0, Math.min(100, number2));
5317
5392
  }
5318
5393
  function summarizeFabricator(entity, record, itemHolderRecord = null, typeRecord = null) {
5319
5394
  if (!record) return null;
@@ -5512,12 +5587,12 @@
5512
5587
  }
5513
5588
  function summarizeProjectile(entity, record) {
5514
5589
  if (!record) return null;
5515
- const color = record.q20 ?? 16777215;
5590
+ const color2 = record.q20 ?? 16777215;
5516
5591
  const itemId = record.q28 ?? 1;
5517
5592
  return {
5518
5593
  entity,
5519
- color,
5520
- colorCss: colorToCss(color),
5594
+ color: color2,
5595
+ colorCss: colorToCss(color2),
5521
5596
  botStyle: Boolean(record.q33),
5522
5597
  indicatorCount: record.q24 ?? 1,
5523
5598
  spriteItemId: itemId === 0 ? null : itemId,
@@ -5675,7 +5750,7 @@
5675
5750
  }
5676
5751
  function summarizeShipControl(entity, record) {
5677
5752
  if (!record) return null;
5678
- const color = record.q32 == null ? null : Number(record.q32);
5753
+ const color2 = record.q32 == null ? null : Number(record.q32);
5679
5754
  const shieldMaxHpOffset = typeof record.q68 === "number" ? record.q68 : null;
5680
5755
  const shieldMaxHp = shieldMaxHpOffset == null ? null : shieldMaxHpOffset + 2e3;
5681
5756
  const shieldBaseHp = typeof record.q72 === "number" ? record.q72 : null;
@@ -5691,8 +5766,8 @@
5691
5766
  name: decodeText(record.blob116),
5692
5767
  hexCode: decodeText(record.blob128),
5693
5768
  shipWorldId: record.q20 ?? null,
5694
- color: Number.isFinite(color) ? color : null,
5695
- colorCss: Number.isFinite(color) ? colorToCss(color) : null,
5769
+ color: Number.isFinite(color2) ? color2 : null,
5770
+ colorCss: Number.isFinite(color2) ? colorToCss(color2) : null,
5696
5771
  thrustX: numberOrNull(record.q24, 20),
5697
5772
  thrustY: numberOrNull(record.q28, 20),
5698
5773
  value52: numberOrNull(record.q52, 20),
@@ -5760,14 +5835,14 @@
5760
5835
  }
5761
5836
  function summarizeShipWorldMetadata(lockdownRecord, shipRecord) {
5762
5837
  if (!lockdownRecord && !shipRecord) return null;
5763
- const color = shipRecord?.q24 == null ? null : Number(shipRecord.q24);
5838
+ const color2 = shipRecord?.q24 == null ? null : Number(shipRecord.q24);
5764
5839
  const lockdownCountdownSeconds = typeof lockdownRecord?.q20 === "number" ? lockdownRecord.q20 : null;
5765
5840
  const onlineShipOwnerCount = typeof lockdownRecord?.q24 === "number" ? lockdownRecord.q24 : null;
5766
5841
  const requiredShipOwnerCount = typeof lockdownRecord?.q28 === "number" ? lockdownRecord.q28 : null;
5767
5842
  return {
5768
5843
  name: decodeText(shipRecord?.blob20),
5769
- color: Number.isFinite(color) ? color : null,
5770
- colorCss: Number.isFinite(color) ? colorToCss(color) : null,
5844
+ color: Number.isFinite(color2) ? color2 : null,
5845
+ colorCss: Number.isFinite(color2) ? colorToCss(color2) : null,
5771
5846
  width: typeof shipRecord?.q32 === "number" ? shipRecord.q32 : null,
5772
5847
  height: typeof shipRecord?.q36 === "number" ? shipRecord.q36 : null,
5773
5848
  lockdownTimerSeconds: lockdownCountdownSeconds,
@@ -5782,14 +5857,17 @@
5782
5857
  }
5783
5858
  function summarizeItemCrate(entity, sizeRecord, itemRecord = null, healthRecord = null) {
5784
5859
  if (!sizeRecord) return null;
5860
+ const size = scaledSizeSummary(sizeRecord);
5785
5861
  const itemId = itemRecord?.q20 ?? null;
5786
5862
  const count = itemRecord?.q24 ?? null;
5787
5863
  return {
5788
5864
  entity,
5789
5865
  ...itemSummary(itemId, count),
5790
5866
  boxSprite: Boolean(itemRecord?.q29),
5791
- width: sizeRecord.q20 ?? null,
5792
- height: sizeRecord.q24 ?? null,
5867
+ width: size.width,
5868
+ height: size.height,
5869
+ rawWidth: size.rawWidth,
5870
+ rawHeight: size.rawHeight,
5793
5871
  itemState: cloneRecord(itemRecord || healthRecord || {}),
5794
5872
  sizeState: cloneRecord(sizeRecord)
5795
5873
  };
@@ -5806,11 +5884,26 @@
5806
5884
  state: cloneRecord(record)
5807
5885
  };
5808
5886
  }
5809
- function summarizeExpandoBox(entity, itemHolderRecord, sizeRecord) {
5810
- if (!itemHolderRecord && !sizeRecord) return null;
5887
+ function summarizeExpandoBox(entity, itemHolderRecord, sizeRecord, sizeConfig = null, colorConfig = null, advanced = false) {
5888
+ if (!itemHolderRecord && !sizeRecord && !advanced) return null;
5811
5889
  const size = scaledSizeSummary(sizeRecord);
5812
5890
  return {
5813
5891
  entity,
5892
+ advanced,
5893
+ config: advanced ? {
5894
+ minWidth: (sizeConfig?.q20 ?? 20) / 10,
5895
+ maxWidth: (sizeConfig?.q24 ?? 100) / 10,
5896
+ minHeight: (sizeConfig?.q28 ?? 20) / 10,
5897
+ maxHeight: (sizeConfig?.q32 ?? 100) / 10,
5898
+ minEnabled: Boolean(sizeConfig?.q37),
5899
+ maxEnabled: Boolean(sizeConfig?.q38),
5900
+ fixedSize: Boolean(sizeConfig?.q39),
5901
+ backgroundColor: (colorConfig?.q20 ?? 14540253) >>> 0,
5902
+ borderColor: (colorConfig?.q24 ?? 4210752) >>> 0,
5903
+ opacity: (colorConfig?.q28 ?? 100) / 100
5904
+ } : null,
5905
+ sizeConfigState: cloneRecord(sizeConfig || {}),
5906
+ colorConfigState: cloneRecord(colorConfig || {}),
5814
5907
  ...itemSummary(itemHolderRecord?.q20 ?? null, itemHolderRecord?.q24 ?? null),
5815
5908
  width: size?.width ?? null,
5816
5909
  height: size?.height ?? null,
@@ -5830,7 +5923,7 @@
5830
5923
  const title = decodeText(zoneRecord?.blob28) ?? decodeText(labelRecord?.blob20);
5831
5924
  const key = decodeText(labelRecord?.blob24) ?? decodeText(labelRecord?.blob28);
5832
5925
  const description = decodeText(zoneRecord?.blob40);
5833
- const color = zoneRecord?.q20 ?? labelRecord?.q28 ?? null;
5926
+ const color2 = zoneRecord?.q20 ?? labelRecord?.q28 ?? null;
5834
5927
  const accentColor = zoneRecord?.q24 ?? labelRecord?.q32 ?? null;
5835
5928
  const kind = key === "mine" ? "mining_zone" : key === "dock" ? "dock" : zoneRecord ? "portal" : "marker";
5836
5929
  return {
@@ -5839,8 +5932,8 @@
5839
5932
  title,
5840
5933
  key,
5841
5934
  description,
5842
- color,
5843
- colorCss: color != null && Number.isFinite(Number(color)) ? colorToCss(Number(color)) : null,
5935
+ color: color2,
5936
+ colorCss: color2 != null && Number.isFinite(Number(color2)) ? colorToCss(Number(color2)) : null,
5844
5937
  accentColor,
5845
5938
  accentColorCss: accentColor != null && Number.isFinite(Number(accentColor)) ? colorToCss(Number(accentColor)) : null,
5846
5939
  width: sizeRecord?.q20 ?? null,
@@ -5849,13 +5942,13 @@
5849
5942
  zoneState: cloneRecord(zoneRecord || {})
5850
5943
  };
5851
5944
  }
5852
- function summarizeDockingSpring(entity, springRecord, bodyRecord = null, sizeRecord = null) {
5853
- if (!springRecord || bodyRecord?.q32 !== -1 || sizeRecord?.q20 !== 160 || sizeRecord?.q24 !== 160) return null;
5945
+ function summarizeDockingSpring(entity, springRecord, sizeRecord = null) {
5946
+ if (!springRecord) return null;
5854
5947
  return {
5855
5948
  entity,
5856
5949
  id: springRecord.q20 ?? null,
5857
- width: sizeRecord.q20,
5858
- height: sizeRecord.q24,
5950
+ width: sizeRecord?.q20 == null ? null : sizeRecord.q20 / 10,
5951
+ height: sizeRecord?.q24 == null ? null : sizeRecord.q24 / 10,
5859
5952
  state: cloneRecord(springRecord)
5860
5953
  };
5861
5954
  }
@@ -6012,13 +6105,13 @@
6012
6105
  function enumValueName(map, value) {
6013
6106
  return value == null ? null : map.get(value) ?? null;
6014
6107
  }
6015
- function colorToCss(color) {
6016
- return `rgb(${color >> 16 & 255},${color >> 8 & 255},${color & 255})`;
6108
+ function colorToCss(color2) {
6109
+ return `rgb(${color2 >> 16 & 255},${color2 >> 8 & 255},${color2 & 255})`;
6017
6110
  }
6018
- function previewActionName(color) {
6019
- if (color === 65280) return "place";
6020
- if (color === 16711680) return "break";
6021
- if (color === 255) return "blueprint";
6111
+ function previewActionName(color2) {
6112
+ if (color2 === 65280) return "place";
6113
+ if (color2 === 16711680) return "break";
6114
+ if (color2 === 255) return "blueprint";
6022
6115
  return null;
6023
6116
  }
6024
6117
  function bitOffsets(value) {
@@ -6067,10 +6160,10 @@
6067
6160
  }
6068
6161
  function summarizePlayerPreview(entity, record, blueprintItems = []) {
6069
6162
  if (!record) return null;
6070
- const color = record.q40 == null ? null : Number(record.q40);
6163
+ const color2 = record.q40 == null ? null : Number(record.q40);
6071
6164
  const active = typeof record.q36 === "number" && record.q36 !== 0;
6072
6165
  if (!active && record.q36 == null) return null;
6073
- const actionName = Number.isFinite(color) ? previewActionName(color) : null;
6166
+ const actionName = Number.isFinite(color2) ? previewActionName(color2) : null;
6074
6167
  return {
6075
6168
  entity,
6076
6169
  active,
@@ -6079,8 +6172,8 @@
6079
6172
  width: numberOrNull(record.q28, 10),
6080
6173
  height: numberOrNull(record.q32, 10),
6081
6174
  progress: record.q36 ?? null,
6082
- color: Number.isFinite(color) ? color : null,
6083
- colorCss: Number.isFinite(color) ? colorToCss(color) : null,
6175
+ color: Number.isFinite(color2) ? color2 : null,
6176
+ colorCss: Number.isFinite(color2) ? colorToCss(color2) : null,
6084
6177
  actionName,
6085
6178
  blueprintId: record.q44 ?? null,
6086
6179
  blueprintItems: actionName === "blueprint" ? blueprintItems : [],
@@ -6427,6 +6520,10 @@
6427
6520
  defineLazyProperty: defineLazyProperty2
6428
6521
  } = decoder_exports;
6429
6522
  var ModelState = class {
6523
+ #entityRevisions = /* @__PURE__ */ new Map();
6524
+ #entityIds = null;
6525
+ #recordRevisions = /* @__PURE__ */ new WeakMap();
6526
+ #revision = 0;
6430
6527
  #localPlayerEntity = null;
6431
6528
  #blueprintItems = null;
6432
6529
  #helmOccupied = /* @__PURE__ */ new Map();
@@ -6465,10 +6562,32 @@
6465
6562
  record(tableId, entityId) {
6466
6563
  return this.table(tableId).get(Number(entityId)) || null;
6467
6564
  }
6565
+ /** Monotonic local revision, independent of the server's generation counter. */
6566
+ get revision() {
6567
+ return this.#revision;
6568
+ }
6569
+ /** Live component IDs without creating entity/debug summaries. */
6570
+ componentEntityIds() {
6571
+ this.#entityIds ??= [...this.#entityRevisions.keys()].sort((a, b) => a - b);
6572
+ return this.#entityIds.values();
6573
+ }
6574
+ /** Latest record mutation for a live entity, or zero after removal. */
6575
+ entityRevision(entityId) {
6576
+ return this.#entityRevisions.get(Number(entityId)) ?? 0;
6577
+ }
6578
+ /** Revision of a decoded record, without creating entity/debug summaries. */
6579
+ recordRevision(record) {
6580
+ return record ? this.#recordRevisions.get(record) ?? 0 : 0;
6581
+ }
6582
+ /** Stateful navigation destination without constructing derived entity lists. */
6583
+ navigationDestination(entityId) {
6584
+ const record = this.record(78, entityId);
6585
+ return this.#navigationUnitAutoWarp.get(Number(entityId))?.destination ?? navigationDestinationFromRecord2(record);
6586
+ }
6468
6587
  entity(entityId) {
6469
6588
  const id = Number(entityId);
6470
6589
  if (!Number.isFinite(id)) return null;
6471
- return this.#derivedState().entitiesById.get(id) || null;
6590
+ return this.#derivedEntityIndex().entitiesById.get(id) || null;
6472
6591
  }
6473
6592
  entities() {
6474
6593
  return this.#derivedState().entities.slice();
@@ -6480,10 +6599,11 @@
6480
6599
  // O(1) point lookup. Callers previously had to materialise and scan the whole
6481
6600
  // block list to answer this.
6482
6601
  blockAt(x, y) {
6483
- this.#derivedState();
6602
+ this.#derivedEntityIndex();
6484
6603
  return this.#blocksIndex().get(blockKey2(x, y)) || null;
6485
6604
  }
6486
6605
  apply(bytes, { full = false } = {}) {
6606
+ this.#revision++;
6487
6607
  this.#blueprintItems = null;
6488
6608
  const reader = new ModelReader2(bytes);
6489
6609
  const update = {
@@ -6517,9 +6637,9 @@
6517
6637
  if (reader.trailingZeroOnly()) break;
6518
6638
  throw new Error(`unsupported model_data section tag ${tag}`);
6519
6639
  }
6520
- const section2 = this.#readSection(reader, tag, tableId);
6521
- update.sections.push(section2);
6522
- for (const record of section2.records) update.changedEntities.add(record.entity);
6640
+ const section3 = this.#readSection(reader, tag, tableId);
6641
+ update.sections.push(section3);
6642
+ for (const record of section3.records) update.changedEntities.add(record.entity);
6523
6643
  }
6524
6644
  } catch (error) {
6525
6645
  update.error = error;
@@ -6656,25 +6776,45 @@
6656
6776
  this._derived = null;
6657
6777
  }
6658
6778
  #updateDerived(update) {
6659
- if (!this._derived) return;
6779
+ const derived = this._derived;
6780
+ if (!derived) return;
6660
6781
  if (!update.removals.length && !update.changedEntities.size) return;
6661
- for (const section2 of update.sections) {
6662
- for (const record of section2.records || []) this.#addDerivedEntityTable(record.entity, section2.table);
6782
+ for (const section3 of update.sections) {
6783
+ for (const record of section3.records || []) this.#addDerivedEntityTable(record.entity, section3.table);
6663
6784
  }
6664
- if (update.sections.some((section2) => section2.table === 12)) {
6785
+ const dirty = derived.dirtyEntities ??= /* @__PURE__ */ new Set();
6786
+ if (update.sections.some((section3) => section3.table === 12)) {
6665
6787
  for (const entityId of this.table(55).keys()) update.changedEntities.add(entityId);
6666
6788
  }
6667
- for (const entityId of update.removals) this.#removeDerivedEntity(entityId);
6668
- for (const entityId of update.changedEntities) this.#refreshDerivedEntity(entityId);
6669
- this._derived.summariesDirty = true;
6670
- this._derived.tableSummariesDirty = true;
6789
+ for (const entityId of update.removals) {
6790
+ derived.entityTableIds.delete(entityId);
6791
+ dirty.add(entityId);
6792
+ }
6793
+ for (const entityId of update.changedEntities) dirty.add(entityId);
6794
+ }
6795
+ #flushDerivedEntities() {
6796
+ const derived = this._derived;
6797
+ const dirty = derived.dirtyEntities;
6798
+ if (!dirty || dirty.size === 0) return;
6799
+ derived.dirtyEntities = null;
6800
+ for (const entityId of dirty) this.#refreshDerivedEntity(entityId);
6801
+ derived.summariesDirty = true;
6802
+ derived.tableSummariesDirty = true;
6803
+ }
6804
+ // Current entity summaries without the per-category lists. Point lookups go
6805
+ // through here: rebuilding those lists is O(total entities) and was the whole
6806
+ // cost of entity(id) on a large world.
6807
+ #derivedEntityIndex() {
6808
+ if (!this._derived) return this.#derivedState();
6809
+ this.#flushDerivedEntities();
6810
+ return this._derived;
6671
6811
  }
6672
6812
  #updateNavigationUnitAutoWarp(update) {
6673
6813
  const trackedBeforeUpdate = new Set(this.#navigationUnitAutoWarp.keys());
6674
6814
  const initializedThisUpdate = /* @__PURE__ */ new Set();
6675
- for (const section2 of update.sections || []) {
6676
- if (section2.table !== 78) continue;
6677
- for (const changed of section2.records || []) {
6815
+ for (const section3 of update.sections || []) {
6816
+ if (section3.table !== 78) continue;
6817
+ for (const changed of section3.records || []) {
6678
6818
  const typeId = entityTypeIdFromRecord2(this.record(7, changed.entity));
6679
6819
  if (typeId !== NAVIGATION_UNIT_TYPE_ID2) continue;
6680
6820
  const record = this.record(78, changed.entity);
@@ -6737,12 +6877,12 @@
6737
6877
  }
6738
6878
  }
6739
6879
  #updateHelmOccupancy(update) {
6740
- const table7 = update.sections.find((section2) => section2.table === 7);
6880
+ const table7 = update.sections.find((section3) => section3.table === 7);
6741
6881
  if (!table7) return;
6742
6882
  const changedZoomState = /* @__PURE__ */ new Map();
6743
- for (const section2 of update.sections) {
6744
- if (section2.table !== 55) continue;
6745
- for (const changed of section2.records) {
6883
+ for (const section3 of update.sections) {
6884
+ if (section3.table !== 55) continue;
6885
+ for (const changed of section3.records) {
6746
6886
  if (!(changed.mask & 16)) continue;
6747
6887
  const player = this.record(55, changed.entity);
6748
6888
  changedZoomState.set(changed.entity, Boolean(player?.q107));
@@ -6761,7 +6901,7 @@
6761
6901
  }
6762
6902
  }
6763
6903
  #updateCommsStationOccupancy(update) {
6764
- const table7 = update.sections.find((section2) => section2.table === 7);
6904
+ const table7 = update.sections.find((section3) => section3.table === 7);
6765
6905
  if (!table7) return;
6766
6906
  for (const changed of table7.records) {
6767
6907
  const record = this.record(7, changed.entity);
@@ -6782,6 +6922,7 @@
6782
6922
  }
6783
6923
  #derivedState() {
6784
6924
  if (this._derived) {
6925
+ this.#flushDerivedEntities();
6785
6926
  this.#ensureDerivedSummaries();
6786
6927
  return this._derived;
6787
6928
  }
@@ -6859,7 +7000,7 @@
6859
7000
  if (old) this.#removeEntityFromDerivedBlocks(derived, old);
6860
7001
  const next = this.#summarizeEntity(entityId, rows);
6861
7002
  derived.entitiesById.set(entityId, next);
6862
- if (!derived.entityIds.includes(entityId)) insertSorted(derived.entityIds, entityId);
7003
+ if (!old) insertSorted(derived.entityIds, entityId);
6863
7004
  this.#addEntityToDerivedBlocks(derived, next);
6864
7005
  derived.entityCount = derived.entityIds.length;
6865
7006
  }
@@ -7059,7 +7200,7 @@
7059
7200
  const thrusterRecord = rec(50);
7060
7201
  const labelRecord = rec(9);
7061
7202
  const zoneLabelRecord = rec(25);
7062
- const dockingSpringRecord = rec(26);
7203
+ const dockingSpringRecord = rec(22);
7063
7204
  const hugeThrusterRecord = rec(23);
7064
7205
  const bodyStateRecord = rec(1);
7065
7206
  const typeRecord = rec(7);
@@ -7074,7 +7215,8 @@
7074
7215
  const dynamicBody = bodyStateRecord?.q20 === -4;
7075
7216
  const typeId = entityTypeIdFromRecord2(typeRecord);
7076
7217
  const itemHolder = summarizeItemHolder2(entityId, itemHolderRecord);
7077
- const isExpandoBox = typeId === EXPANDO_BOX_TYPE_ID2 || markerTypeId === EXPANDO_BOX_TYPE_ID2;
7218
+ const isAdvancedExpandoBox = typeId === 266 || Boolean(rec(82) || rec(83));
7219
+ const isExpandoBox = isAdvancedExpandoBox || typeId === EXPANDO_BOX_TYPE_ID2 || markerTypeId === EXPANDO_BOX_TYPE_ID2;
7078
7220
  const health = summarizeHealth2(entityId, healthRecord);
7079
7221
  const projectile = summarizeProjectile2(entityId, rec(24));
7080
7222
  const combatBeams = summarizeCombatBeams2(entityId, rec(15));
@@ -7108,9 +7250,9 @@
7108
7250
  const door = typeId === 220 ? summarizeDoor2(entityId, spawnPointRecord, doorRecord, rec(80)) : null;
7109
7251
  const shipSize = shipControl && this.isOverworld ? summarizeShipSize2(entityId, rec(3)) : null;
7110
7252
  const hoverOutline = summarizeHoverOutline2(entityId, crateSizeRecord);
7111
- const expandoBox = isExpandoBox ? summarizeExpandoBox2(entityId, itemHolderRecord, expandoSizeRecord) : null;
7253
+ const expandoBox = isExpandoBox ? summarizeExpandoBox2(entityId, itemHolderRecord, expandoSizeRecord, rec(82), rec(83), isAdvancedExpandoBox) : null;
7112
7254
  const mapMarker = this.isOverworld ? summarizeMapMarker2(entityId, labelRecord, zoneLabelRecord, crateSizeRecord) : null;
7113
- const dockingSpring = this.isOverworld ? summarizeDockingSpring2(entityId, dockingSpringRecord, bodyStateRecord, crateSizeRecord) : null;
7255
+ const dockingSpring = this.isOverworld ? summarizeDockingSpring2(entityId, dockingSpringRecord, crateSizeRecord) : null;
7114
7256
  const hugeThruster = this.isOverworld ? summarizeHugeThruster2(entityId, hugeThrusterRecord, crateSizeRecord) : null;
7115
7257
  const itemCrate = this.isOverworld && !rec(2) && !rec(18) && !combatBeams && !projectile && !ball && !rcd && health && crateSizeRecord ? summarizeItemCrate2(entityId, crateSizeRecord, crateItemRecord, healthRecord) : null;
7116
7258
  const bot = (this.isOverworld || rec(18) || combatBeams) && !projectile && !ball && !rcd ? summarizeBot2(entityId, {
@@ -7349,6 +7491,8 @@
7349
7491
  if (delta === 0) break;
7350
7492
  entity += delta;
7351
7493
  removals.push(entity);
7494
+ this.#entityRevisions.delete(entity);
7495
+ this.#entityIds = null;
7352
7496
  for (const records of this.tables.values()) records.delete(entity);
7353
7497
  this.#helmOccupied.delete(entity);
7354
7498
  this.#commsStationOccupied.delete(entity);
@@ -7363,7 +7507,7 @@
7363
7507
  return this.#readSectionRecords(reader, tag, tableId, spec);
7364
7508
  }
7365
7509
  #readSectionRecords(reader, tag, tableId, spec) {
7366
- const section2 = { tag, table: tableId, name: spec?.name || null, records: [] };
7510
+ const section3 = { tag, table: tableId, name: spec?.name || null, records: [] };
7367
7511
  let records = this.tables.get(tableId);
7368
7512
  let entity = 0;
7369
7513
  while (reader.remaining > 0) {
@@ -7385,6 +7529,9 @@
7385
7529
  if (!records) this.tables.set(tableId, records = /* @__PURE__ */ new Map());
7386
7530
  let record = records.get(entity);
7387
7531
  if (!record) records.set(entity, record = { ...spec?.defaults });
7532
+ if (!this.#entityRevisions.has(entity)) this.#entityIds = null;
7533
+ this.#entityRevisions.set(entity, this.#revision);
7534
+ this.#recordRevisions.set(record, this.#revision);
7388
7535
  record.lastMask = mask;
7389
7536
  try {
7390
7537
  if (spec) this.#applyRecordSpec(reader, record, mask, spec);
@@ -7393,9 +7540,9 @@
7393
7540
  throw new Error(`model table ${tableId} tag ${tag} entity ${entity} mask ${mask} offset ${reader.offset}: ${error.message}`);
7394
7541
  }
7395
7542
  const changed = { entity, mask };
7396
- section2.records.push(changed);
7543
+ section3.records.push(changed);
7397
7544
  }
7398
- return section2;
7545
+ return section3;
7399
7546
  }
7400
7547
  #applyRecordSpec(reader, record, mask, spec) {
7401
7548
  if (typeof spec.read === "function") {
@@ -7403,9 +7550,7 @@
7403
7550
  if (spec.scale) record.scaled = spec.scale(record);
7404
7551
  return;
7405
7552
  }
7406
- const hasPacked = Boolean(
7407
- spec.packedMask && mask & spec.packedMask || spec.packedBits?.some((item) => mask & item.bit)
7408
- );
7553
+ const hasPacked = (mask & spec.packedAnyMask) !== 0;
7409
7554
  let packed = null;
7410
7555
  if (hasPacked && spec.packedBeforeValues) packed = reader.readUnsigned();
7411
7556
  let packedIndex = 0;
@@ -7445,11 +7590,11 @@
7445
7590
  removals: update.removals.length,
7446
7591
  unknownTags: update.unknownTags,
7447
7592
  error: update.error?.message || null,
7448
- sections: update.sections.map((section2) => ({
7449
- tag: section2.tag,
7450
- table: section2.table,
7451
- name: section2.name,
7452
- records: section2.records.length
7593
+ sections: update.sections.map((section3) => ({
7594
+ tag: section3.tag,
7595
+ table: section3.table,
7596
+ name: section3.name,
7597
+ records: section3.records.length
7453
7598
  }))
7454
7599
  };
7455
7600
  }
@@ -7670,10 +7815,58 @@
7670
7815
  target.push(value);
7671
7816
  if (target.length > limit) target.splice(0, target.length - limit);
7672
7817
  }
7673
- var TILE_KEY_OFFSET = 1 << 24;
7674
- var TILE_KEY_STRIDE = 1 << 25;
7818
+ var CHUNK_SIZE = 64;
7819
+ var CHUNK_CELLS = CHUNK_SIZE * CHUNK_SIZE;
7820
+ var COLUMN_SHAPE = CHUNK_CELLS;
7821
+ var COLUMN_HP = CHUNK_CELLS * 2;
7822
+ var COLUMN_COLOR = CHUNK_CELLS * 3;
7823
+ var COLUMN_FLAGS = CHUNK_CELLS * 4;
7824
+ var CHUNK_COORD_LIMIT = 1 << 15;
7825
+ var TILE_COORD_LIMIT = CHUNK_COORD_LIMIT * CHUNK_SIZE;
7826
+ var TILE_OBJECT_KEY_COUNT = 13;
7827
+ var CONCAT_BATCH = 4096;
7828
+ var TileFlags = Object.freeze({
7829
+ /** The cell holds a tile. Zero means the cell is empty. */
7830
+ Present: 1,
7831
+ /** The tile was sent without a color; its `color` is null. */
7832
+ NoColor: 2
7833
+ });
7834
+ var SHAPE_NAMES_BY_ID = Array.from({ length: 256 }, (_, shape) => TILE_SHAPE_NAMES.get(shape) ?? null);
7835
+ var isByte = (value) => typeof value === "number" && (value & 255) === value;
7836
+ var isCellIndex = (value) => Number.isInteger(value) && value >= 0 && value < CHUNK_SIZE;
7837
+ var isChunkCoord = (value) => Number.isInteger(value) && value >= -CHUNK_COORD_LIMIT && value < CHUNK_COORD_LIMIT;
7838
+ var isTileCoord = (value) => Number.isInteger(value) && value >= -TILE_COORD_LIMIT && value < TILE_COORD_LIMIT;
7839
+ var chunkKey = (chunkX, chunkY) => (chunkY + CHUNK_COORD_LIMIT) * (CHUNK_COORD_LIMIT * 2) + (chunkX + CHUNK_COORD_LIMIT);
7840
+ var looseTileKey = (x, y) => `${x},${y}`;
7841
+ var TileCollection = class {
7842
+ #count;
7843
+ #objects;
7844
+ constructor(count, objects) {
7845
+ this.#count = count;
7846
+ this.#objects = objects;
7847
+ }
7848
+ get size() {
7849
+ return this.#count();
7850
+ }
7851
+ // A fresh array of every tile.
7852
+ toArray() {
7853
+ return this.#objects().slice();
7854
+ }
7855
+ };
7675
7856
  var WorldState = class {
7676
- #materialCounts = /* @__PURE__ */ new Map();
7857
+ #chunkGrids = /* @__PURE__ */ new Map();
7858
+ // Tiles the columns cannot hold: non-byte values, out-of-range coordinates,
7859
+ // or extra caller fields. Only reachable through setTile()/malformed patches.
7860
+ #looseTiles = /* @__PURE__ */ new Map();
7861
+ #chunkViews = null;
7862
+ #tileVersion = 0;
7863
+ #tileStats = null;
7864
+ #tileStatsVersion = -1;
7865
+ #tileObjects = null;
7866
+ #tileObjectsVersion = -1;
7867
+ #tileObjectsRequestedVersion = -1;
7868
+ #materialDefs = null;
7869
+ #materialDefsTileset = null;
7677
7870
  constructor(id, limits = {}) {
7678
7871
  this.historyLimits = {
7679
7872
  eventHistory: normalizeLimit(limits.eventHistory, DEFAULT_HISTORY_LIMITS.eventHistory),
@@ -7690,7 +7883,7 @@
7690
7883
  this.blockHeight = null;
7691
7884
  this.parentWorld = null;
7692
7885
  this.parentEntity = null;
7693
- this.tiles = /* @__PURE__ */ new Map();
7886
+ this.tiles = new TileCollection(() => this.#readTileStats().count, () => this.#readTileObjects());
7694
7887
  this.chunks = [];
7695
7888
  this.events = [];
7696
7889
  this.modelPackets = [];
@@ -7702,7 +7895,7 @@
7702
7895
  this.meta = null;
7703
7896
  }
7704
7897
  readMeta(packet) {
7705
- this.meta = packet;
7898
+ this.meta = { ...this.meta, ...packet };
7706
7899
  this.seed = packet.seed ?? this.seed;
7707
7900
  const isOverworld = packet.is_overworld ?? this.isOverworld;
7708
7901
  this.isOverworld = isOverworld == null ? null : Boolean(isOverworld);
@@ -7723,15 +7916,15 @@
7723
7916
  }
7724
7917
  addCommsBubble(packet) {
7725
7918
  const raw = packet?.bubble && typeof packet.bubble === "object" ? packet.bubble : {};
7726
- const color = Number.isFinite(Number(raw.color)) ? Number(raw.color) : null;
7919
+ const color2 = Number.isFinite(Number(raw.color)) ? Number(raw.color) : null;
7727
7920
  const bubble = {
7728
7921
  sequence: ++this._bubbleSequence,
7729
7922
  worldId: this.id,
7730
7923
  entity: Number.isFinite(Number(raw.model_id)) ? Number(raw.model_id) : null,
7731
7924
  modelId: Number.isFinite(Number(raw.model_id)) ? Number(raw.model_id) : null,
7732
7925
  message: typeof raw.msg === "string" ? raw.msg : "",
7733
- color,
7734
- colorCss: color == null ? null : `rgb(${color >> 16 & 255},${color >> 8 & 255},${color & 255})`,
7926
+ color: color2,
7927
+ colorCss: color2 == null ? null : `rgb(${color2 >> 16 & 255},${color2 >> 8 & 255},${color2 & 255})`,
7735
7928
  durationSeconds: Number.isFinite(Number(raw.time)) ? Number(raw.time) : null,
7736
7929
  raw: { ...raw }
7737
7930
  };
@@ -7747,10 +7940,16 @@
7747
7940
  }
7748
7941
  applyTile(value) {
7749
7942
  if (!Array.isArray(value) || value.length !== 6) return null;
7750
- const [x, y, material, shape, hp, color] = value;
7751
- return this.setTile({ x, y, material, shape, hp, integrity: hp, color });
7943
+ const [x, y, material, shape, hp, color2] = value;
7944
+ return this.setTile({ x, y, material, shape, hp, integrity: hp, color: color2 });
7752
7945
  }
7753
7946
  applyChunk(value) {
7947
+ const patch = this.applyChunkPatch(value);
7948
+ return patch ? patch.tiles : null;
7949
+ }
7950
+ // Applies a chunk patch and returns its history entry. The entry's `tiles`
7951
+ // array is built on first read, so ingestion never allocates tile objects.
7952
+ applyChunkPatch(value) {
7754
7953
  if (!Array.isArray(value) || value.length !== 7) return null;
7755
7954
  const [chunkX, chunkY, minX, minY, maxX, maxY, compressedPatch] = value;
7756
7955
  const patch = decompressWorldChunk(compressedPatch);
@@ -7758,33 +7957,144 @@
7758
7957
  const height = maxY - minY + 1;
7759
7958
  const count = width * height;
7760
7959
  const hasColor = patch.length >= count * 4;
7761
- const tiles = new Array(count);
7762
7960
  const baseX = chunkX << 6;
7763
7961
  const baseY = chunkY << 6;
7764
- for (let i = 0; i < count; i++) {
7765
- const localX = minX + i % width;
7766
- const localY = minY + Math.floor(i / width);
7767
- const hp = patch[i + count * 2];
7768
- tiles[i] = this.#storeTile(this.#buildTile(
7769
- baseX + localX,
7770
- baseY + localY,
7771
- patch[i],
7772
- patch[i + count],
7773
- hp,
7774
- hasColor ? patch[i + count * 3] : null
7775
- ));
7962
+ const entry = { chunkX, chunkY, minX, minY, maxX, maxY };
7963
+ const wellFormed = isChunkCoord(chunkX) && isChunkCoord(chunkY) && isCellIndex(minX) && isCellIndex(minY) && isCellIndex(maxX) && isCellIndex(maxY) && width > 0 && height > 0 && patch.length >= count * 3;
7964
+ if (wellFormed) {
7965
+ this.#writeChunkColumns(this.#chunkGrid(chunkX, chunkY), patch, minX, minY, width, height, hasColor);
7966
+ defineLazyProperty(entry, "tiles", () => {
7967
+ const tiles = new Array(count);
7968
+ for (let i = 0; i < count; i++) {
7969
+ tiles[i] = this.#buildTile(
7970
+ baseX + minX + i % width,
7971
+ baseY + minY + Math.floor(i / width),
7972
+ patch[i],
7973
+ patch[i + count],
7974
+ patch[i + count * 2],
7975
+ hasColor ? patch[i + count * 3] : null
7976
+ );
7977
+ }
7978
+ return tiles;
7979
+ });
7980
+ } else {
7981
+ const tiles = new Array(count);
7982
+ for (let i = 0; i < count; i++) {
7983
+ tiles[i] = this.#storeTile(this.#buildTile(
7984
+ baseX + minX + i % width,
7985
+ baseY + minY + Math.floor(i / width),
7986
+ patch[i],
7987
+ patch[i + count],
7988
+ patch[i + count * 2],
7989
+ hasColor ? patch[i + count * 3] : null
7990
+ ));
7991
+ }
7992
+ entry.tiles = tiles;
7776
7993
  }
7777
7994
  this.totalChunkCount += 1;
7778
- pushBounded(this.chunks, { chunkX, chunkY, minX, minY, maxX, maxY, tiles }, this.historyLimits.chunkHistory);
7995
+ pushBounded(this.chunks, entry, this.historyLimits.chunkHistory);
7779
7996
  this.lastChunkPatch = { chunkX, chunkY, minX, minY, maxX, maxY, count, hasColor };
7780
- return tiles;
7997
+ return entry;
7781
7998
  }
7782
7999
  setTile(tile) {
7783
8000
  return this.#storeTile(this.normalizeTile(tile));
7784
8001
  }
7785
- // Chunk decoding produces millions of tiles at join time, so build the final
7786
- // object in one pass instead of a literal plus a spread copy.
7787
- #buildTile(x, y, material, shape, hp, color) {
8002
+ /** Bumped on every tile write; compare to skip work when nothing changed. */
8003
+ get tileVersion() {
8004
+ return this.#tileVersion;
8005
+ }
8006
+ // Zero-copy access for consumers that scan tiles every tick. The returned
8007
+ // views are live and stable for the life of the chunk: read the typed arrays
8008
+ // directly and use each view's `version` to skip chunks that have not changed.
8009
+ tileChunks() {
8010
+ return this.#chunkViews ??= Array.from(this.#chunkGrids.values(), (grid) => grid.view);
8011
+ }
8012
+ tileAt(x, y) {
8013
+ if (this.#looseTiles.size > 0) {
8014
+ const loose = this.#looseTiles.get(looseTileKey(x, y));
8015
+ if (loose) return loose;
8016
+ }
8017
+ if (!isTileCoord(x) || !isTileCoord(y)) return null;
8018
+ const grid = this.#chunkGrids.get(chunkKey(x >> 6, y >> 6));
8019
+ if (!grid) return null;
8020
+ const data = grid.data;
8021
+ const cell = (y & 63) << 6 | x & 63;
8022
+ const flags = data[COLUMN_FLAGS + cell];
8023
+ if (flags === 0) return null;
8024
+ return this.#buildTile(
8025
+ x,
8026
+ y,
8027
+ data[cell],
8028
+ data[COLUMN_SHAPE + cell],
8029
+ data[COLUMN_HP + cell],
8030
+ flags & TileFlags.NoColor ? null : data[COLUMN_COLOR + cell]
8031
+ );
8032
+ }
8033
+ // Drops tile objects retained for repeated `tiles.toArray()` reads. They are
8034
+ // rebuilt on the next read.
8035
+ releaseTileObjects() {
8036
+ this.#tileObjects = null;
8037
+ this.#tileObjectsRequestedVersion = -1;
8038
+ for (const grid of this.#chunkGrids.values()) {
8039
+ grid.objects = null;
8040
+ grid.objectsRequestedVersion = -1;
8041
+ }
8042
+ }
8043
+ #chunkGrid(chunkX, chunkY) {
8044
+ const key = chunkKey(chunkX, chunkY);
8045
+ let grid = this.#chunkGrids.get(key);
8046
+ if (!grid) {
8047
+ const data = new Uint8Array(CHUNK_CELLS * 5);
8048
+ grid = {
8049
+ data,
8050
+ stats: null,
8051
+ objects: null,
8052
+ objectsRequestedVersion: -1,
8053
+ view: {
8054
+ chunkX,
8055
+ chunkY,
8056
+ originX: chunkX << 6,
8057
+ originY: chunkY << 6,
8058
+ version: 0,
8059
+ material: data.subarray(0, COLUMN_SHAPE),
8060
+ shape: data.subarray(COLUMN_SHAPE, COLUMN_HP),
8061
+ hp: data.subarray(COLUMN_HP, COLUMN_COLOR),
8062
+ color: data.subarray(COLUMN_COLOR, COLUMN_FLAGS),
8063
+ flags: data.subarray(COLUMN_FLAGS, COLUMN_FLAGS + CHUNK_CELLS)
8064
+ }
8065
+ };
8066
+ this.#chunkGrids.set(key, grid);
8067
+ this.#chunkViews = null;
8068
+ }
8069
+ return grid;
8070
+ }
8071
+ // The only bookkeeping a tile write does. Counts and tile objects are derived
8072
+ // later, on demand, from whichever chunks were touched.
8073
+ #touchChunk(grid) {
8074
+ grid.stats = null;
8075
+ grid.objects = null;
8076
+ grid.view.version = ++this.#tileVersion;
8077
+ }
8078
+ #writeChunkColumns(grid, patch, minX, minY, width, height, hasColor) {
8079
+ const data = grid.data;
8080
+ const count = width * height;
8081
+ const columns = hasColor ? 4 : 3;
8082
+ const flag = hasColor ? TileFlags.Present : TileFlags.Present | TileFlags.NoColor;
8083
+ const rows = width === CHUNK_SIZE ? 1 : height;
8084
+ const span = width === CHUNK_SIZE ? count : width;
8085
+ for (let row = 0; row < rows; row++) {
8086
+ const start = (minY + row << 6) + minX;
8087
+ const from = row * width;
8088
+ for (let column = 0; column < columns; column++) {
8089
+ const source = column * count + from;
8090
+ data.set(patch.subarray(source, source + span), column * CHUNK_CELLS + start);
8091
+ }
8092
+ if (!hasColor) data.fill(0, COLUMN_COLOR + start, COLUMN_COLOR + start + span);
8093
+ data.fill(flag, COLUMN_FLAGS + start, COLUMN_FLAGS + start + span);
8094
+ }
8095
+ this.#touchChunk(grid);
8096
+ }
8097
+ #buildTile(x, y, material, shape, hp, color2) {
7788
8098
  const def = this.tileDefinition(material);
7789
8099
  const maxHp = def?.hp ?? null;
7790
8100
  const value = hp ?? null;
@@ -7795,7 +8105,7 @@
7795
8105
  shape,
7796
8106
  hp: value,
7797
8107
  integrity: value,
7798
- color,
8108
+ color: color2,
7799
8109
  materialName: def?.name ?? null,
7800
8110
  shapeName: tileShapeName(shape),
7801
8111
  solid: def?.solid ?? null,
@@ -7804,22 +8114,147 @@
7804
8114
  hpValue: typeof value === "number" && typeof maxHp === "number" ? Math.round(value / 255 * maxHp) : null
7805
8115
  };
7806
8116
  }
7807
- // Numeric key: a template string per tile was a measurable share of chunk
7808
- // decode. The map is only ever read through values()/size, so the key format
7809
- // is internal.
7810
- #storeTile(normalized) {
7811
- const key = (normalized.y + TILE_KEY_OFFSET) * TILE_KEY_STRIDE + (normalized.x + TILE_KEY_OFFSET);
7812
- const previous = this.tiles.get(key);
7813
- if (previous !== void 0) this.#countMaterial(previous.material, -1);
7814
- this.#countMaterial(normalized.material, 1);
7815
- this.tiles.set(key, normalized);
7816
- return normalized;
7817
- }
7818
- #countMaterial(material, delta) {
7819
- const id = Number(material);
7820
- const next = (this.#materialCounts.get(id) || 0) + delta;
7821
- if (next > 0) this.#materialCounts.set(id, next);
7822
- else this.#materialCounts.delete(id);
8117
+ #storeTile(tile) {
8118
+ const { x, y } = tile;
8119
+ const inRange = isTileCoord(x) && isTileCoord(y);
8120
+ const columnar = inRange && isByte(tile.material) && isByte(tile.shape) && isByte(tile.hp) && (tile.color === null || isByte(tile.color)) && Object.keys(tile).length === TILE_OBJECT_KEY_COUNT;
8121
+ if (this.#looseTiles.size > 0 && this.#looseTiles.delete(looseTileKey(x, y))) this.#tileVersion++;
8122
+ if (columnar) {
8123
+ const grid2 = this.#chunkGrid(x >> 6, y >> 6);
8124
+ const data = grid2.data;
8125
+ const cell = (y & 63) << 6 | x & 63;
8126
+ data[cell] = tile.material;
8127
+ data[COLUMN_SHAPE + cell] = tile.shape;
8128
+ data[COLUMN_HP + cell] = tile.hp;
8129
+ data[COLUMN_COLOR + cell] = tile.color ?? 0;
8130
+ data[COLUMN_FLAGS + cell] = tile.color === null ? TileFlags.Present | TileFlags.NoColor : TileFlags.Present;
8131
+ this.#touchChunk(grid2);
8132
+ return tile;
8133
+ }
8134
+ const grid = inRange ? this.#chunkGrids.get(chunkKey(x >> 6, y >> 6)) : void 0;
8135
+ if (grid) {
8136
+ const cell = (y & 63) << 6 | x & 63;
8137
+ if (grid.data[COLUMN_FLAGS + cell] !== 0) {
8138
+ grid.data[COLUMN_FLAGS + cell] = 0;
8139
+ this.#touchChunk(grid);
8140
+ }
8141
+ }
8142
+ this.#looseTiles.set(looseTileKey(x, y), tile);
8143
+ this.#tileVersion++;
8144
+ return tile;
8145
+ }
8146
+ // Tile and material counts, derived from the columns on first read after a
8147
+ // write. Only chunks touched since the last read are rescanned.
8148
+ #readTileStats() {
8149
+ if (this.#tileStats && this.#tileStatsVersion === this.#tileVersion) return this.#tileStats;
8150
+ const totals = new Int32Array(256);
8151
+ let count = 0;
8152
+ for (const grid of this.#chunkGrids.values()) {
8153
+ let stats = grid.stats;
8154
+ if (!stats) {
8155
+ const data = grid.data;
8156
+ const histogram2 = new Uint16Array(256);
8157
+ let present = 0;
8158
+ for (let cell = 0; cell < CHUNK_CELLS; cell++) {
8159
+ if (data[COLUMN_FLAGS + cell] === 0) continue;
8160
+ histogram2[data[cell]]++;
8161
+ present++;
8162
+ }
8163
+ stats = grid.stats = { count: present, histogram: histogram2 };
8164
+ }
8165
+ count += stats.count;
8166
+ const histogram = stats.histogram;
8167
+ for (let material = 0; material < 256; material++) totals[material] += histogram[material];
8168
+ }
8169
+ const materials = /* @__PURE__ */ new Map();
8170
+ for (let material = 0; material < 256; material++) {
8171
+ if (totals[material] > 0) materials.set(material, totals[material]);
8172
+ }
8173
+ for (const tile of this.#looseTiles.values()) {
8174
+ const id = Number(tile.material);
8175
+ materials.set(id, (materials.get(id) || 0) + 1);
8176
+ count++;
8177
+ }
8178
+ this.#tileStatsVersion = this.#tileVersion;
8179
+ return this.#tileStats = { count, materials };
8180
+ }
8181
+ // Per-material fields of a tile object, resolved once per tileset instead of
8182
+ // once per tile.
8183
+ #readMaterialDefs() {
8184
+ if (this.#materialDefs && this.#materialDefsTileset === this.tileset) return this.#materialDefs;
8185
+ const defs = new Array(256);
8186
+ for (let material = 0; material < 256; material++) {
8187
+ const def = this.tileDefinition(material);
8188
+ defs[material] = { name: def?.name ?? null, solid: def?.solid ?? null, maxHp: def?.hp ?? null };
8189
+ }
8190
+ this.#materialDefsTileset = this.tileset;
8191
+ return this.#materialDefs = defs;
8192
+ }
8193
+ #buildChunkTiles(grid) {
8194
+ const defs = this.#readMaterialDefs();
8195
+ const data = grid.data;
8196
+ const baseX = grid.view.originX;
8197
+ const baseY = grid.view.originY;
8198
+ const tiles = [];
8199
+ for (let cell = 0; cell < CHUNK_CELLS; cell++) {
8200
+ const flags = data[COLUMN_FLAGS + cell];
8201
+ if (flags === 0) continue;
8202
+ const material = data[cell];
8203
+ const shape = data[COLUMN_SHAPE + cell];
8204
+ const hp = data[COLUMN_HP + cell];
8205
+ const def = defs[material];
8206
+ const maxHp = def.maxHp;
8207
+ tiles.push({
8208
+ x: baseX + (cell & 63),
8209
+ y: baseY + (cell >> 6),
8210
+ material,
8211
+ shape,
8212
+ hp,
8213
+ integrity: hp,
8214
+ color: flags & TileFlags.NoColor ? null : data[COLUMN_COLOR + cell],
8215
+ materialName: def.name,
8216
+ shapeName: SHAPE_NAMES_BY_ID[shape],
8217
+ solid: def.solid,
8218
+ maxHp,
8219
+ hpRatio: hp / 255,
8220
+ hpValue: typeof maxHp === "number" ? Math.round(hp / 255 * maxHp) : null
8221
+ });
8222
+ }
8223
+ return tiles;
8224
+ }
8225
+ // Every tile as an object. Objects are retained only once a caller asks a
8226
+ // second time for the same unchanged data, so a one-off dump leaves nothing
8227
+ // behind while a caller that polls pays only for chunks that changed.
8228
+ #readTileObjects() {
8229
+ if (this.#materialDefsTileset !== this.tileset) {
8230
+ this.releaseTileObjects();
8231
+ this.#materialDefs = null;
8232
+ }
8233
+ const version = this.#tileVersion;
8234
+ if (this.#tileObjects && this.#tileObjectsVersion === version) return this.#tileObjects;
8235
+ const parts = [];
8236
+ for (const grid of this.#chunkGrids.values()) {
8237
+ let tiles = grid.objects;
8238
+ if (!tiles) {
8239
+ tiles = this.#buildChunkTiles(grid);
8240
+ if (grid.objectsRequestedVersion === grid.view.version) grid.objects = tiles;
8241
+ else grid.objectsRequestedVersion = grid.view.version;
8242
+ }
8243
+ parts.push(tiles);
8244
+ }
8245
+ if (this.#looseTiles.size > 0) parts.push([...this.#looseTiles.values()]);
8246
+ let out = [];
8247
+ for (let start = 0; start < parts.length; start += CONCAT_BATCH) {
8248
+ out = out.concat(...parts.slice(start, start + CONCAT_BATCH));
8249
+ }
8250
+ if (this.#tileObjectsRequestedVersion === version) {
8251
+ this.#tileObjects = out;
8252
+ this.#tileObjectsVersion = version;
8253
+ } else {
8254
+ this.#tileObjects = null;
8255
+ this.#tileObjectsRequestedVersion = version;
8256
+ }
8257
+ return out;
7823
8258
  }
7824
8259
  normalizeTile(tile) {
7825
8260
  const def = this.tileDefinition(tile.material);
@@ -7837,10 +8272,8 @@
7837
8272
  hpValue: typeof hp === "number" && typeof maxHp === "number" ? Math.round(hp / 255 * maxHp) : null
7838
8273
  };
7839
8274
  }
7840
- // Counts are maintained as tiles are stored; this used to rescan every tile
7841
- // on each call and ran on every snapshot.
7842
8275
  materials() {
7843
- return [...this.#materialCounts.entries()].sort((a, b) => a[0] - b[0]).map(([material, count]) => {
8276
+ return [...this.#readTileStats().materials.entries()].sort((a, b) => a[0] - b[0]).map(([material, count]) => {
7844
8277
  const def = this.tileDefinition(material);
7845
8278
  return {
7846
8279
  material,
@@ -7865,7 +8298,7 @@
7865
8298
  block_h: this.blockHeight,
7866
8299
  parent_world: this.parentWorld,
7867
8300
  parent_ent: this.parentEntity,
7868
- tileCount: this.tiles.size,
8301
+ tileCount: this.#readTileStats().count,
7869
8302
  chunkCount: this.totalChunkCount,
7870
8303
  lastChunkPatch: this.lastChunkPatch,
7871
8304
  lastPacket: this.lastPacket,
@@ -7886,7 +8319,7 @@
7886
8319
  pvpEvent: model.pvpEvent,
7887
8320
  pvpParties: model.pvpParties,
7888
8321
  commsBubbles: this.commsBubbles.slice(),
7889
- tiles: includeTiles ? [...this.tiles.values()] : void 0
8322
+ tiles: includeTiles ? this.tiles.toArray() : void 0
7890
8323
  };
7891
8324
  }
7892
8325
  table(id) {
@@ -8036,8 +8469,10 @@
8036
8469
  if (decoded && typeof decoded === "object") {
8037
8470
  for (const [kind, value] of Object.entries(decoded)) {
8038
8471
  try {
8039
- if (kind === "0") updates.push({ kind, tiles: world.applyChunk(value) });
8040
- else if (kind === "1") updates.push({ kind, tile: world.applyTile(value) });
8472
+ if (kind === "0") {
8473
+ const patch = world.applyChunkPatch(value);
8474
+ updates.push(defineLazyProperty({ kind }, "tiles", () => patch ? patch.tiles : null));
8475
+ } else if (kind === "1") updates.push({ kind, tile: world.applyTile(value) });
8041
8476
  else updates.push({ kind, value });
8042
8477
  } catch (error) {
8043
8478
  errors.push(error);
@@ -8099,14 +8534,14 @@
8099
8534
  // src/protocol/outbound/blueprint.js
8100
8535
  var BLUEPRINT_PLACEMENT_TYPE = 9;
8101
8536
  function requireFiniteNumber(value, name) {
8102
- const number = Number(value);
8103
- if (!Number.isFinite(number)) throw new TypeError(`${name} must be a finite number`);
8104
- return number;
8537
+ const number2 = Number(value);
8538
+ if (!Number.isFinite(number2)) throw new TypeError(`${name} must be a finite number`);
8539
+ return number2;
8105
8540
  }
8106
8541
  function requirePositiveInteger(value, name) {
8107
- const number = Number(value);
8108
- if (!Number.isInteger(number) || number <= 0) throw new RangeError(`${name} must be a positive integer`);
8109
- return number;
8542
+ const number2 = Number(value);
8543
+ if (!Number.isInteger(number2) || number2 <= 0) throw new RangeError(`${name} must be a positive integer`);
8544
+ return number2;
8110
8545
  }
8111
8546
  function normalizeBlueprintDimension(placement, publicName, protocolName) {
8112
8547
  const value = placement[publicName] ?? placement[protocolName];
@@ -8127,19 +8562,19 @@
8127
8562
 
8128
8563
  // src/protocol/outbound/chat.js
8129
8564
  var CHAT_MESSAGE_TYPE = 2;
8130
- function buildChatMessage(message2 = "") {
8565
+ function buildChatMessage(message3 = "") {
8131
8566
  return {
8132
8567
  type: CHAT_MESSAGE_TYPE,
8133
- msg: String(message2)
8568
+ msg: String(message3)
8134
8569
  };
8135
8570
  }
8136
8571
 
8137
8572
  // src/protocol/outbound/comms.js
8138
8573
  var COMMS_MESSAGE_TYPE = 3;
8139
- function buildCommsMessage(message2 = "") {
8574
+ function buildCommsMessage(message3 = "") {
8140
8575
  return {
8141
8576
  type: COMMS_MESSAGE_TYPE,
8142
- msg: String(message2)
8577
+ msg: String(message3)
8143
8578
  };
8144
8579
  }
8145
8580
  function normalizeCommsEvent(event) {
@@ -8148,9 +8583,9 @@
8148
8583
  ...event,
8149
8584
  entity: event?.ent_id != null && Number.isFinite(Number(event.ent_id)) ? Number(event.ent_id) : null,
8150
8585
  rawMessages,
8151
- messages: rawMessages.map((message2) => ({
8152
- raw: message2,
8153
- text: flattenRichText(message2)
8586
+ messages: rawMessages.map((message3) => ({
8587
+ raw: message3,
8588
+ text: flattenRichText(message3)
8154
8589
  }))
8155
8590
  };
8156
8591
  }
@@ -8447,19 +8882,19 @@
8447
8882
  };
8448
8883
  }
8449
8884
  function normalizeInventoryIndex(value, name) {
8450
- const number = Number(value);
8451
- if (!Number.isInteger(number) || number < 0) throw new RangeError(`${name} must be a non-negative integer inventory slot`);
8452
- return number;
8885
+ const number2 = Number(value);
8886
+ if (!Number.isInteger(number2) || number2 < 0) throw new RangeError(`${name} must be a non-negative integer inventory slot`);
8887
+ return number2;
8453
8888
  }
8454
8889
  function normalizeCount(value) {
8455
- const number = Number(value ?? 0);
8456
- return Number.isFinite(number) ? number : 0;
8890
+ const number2 = Number(value ?? 0);
8891
+ return Number.isFinite(number2) ? number2 : 0;
8457
8892
  }
8458
8893
  function normalizeItemId(value, count) {
8459
8894
  if (value == null) return null;
8460
- const number = Number(value);
8461
- if (!Number.isFinite(number)) return null;
8462
- return number === 0 && count === 0 ? null : number;
8895
+ const number2 = Number(value);
8896
+ if (!Number.isFinite(number2)) return null;
8897
+ return number2 === 0 && count === 0 ? null : number2;
8463
8898
  }
8464
8899
 
8465
8900
  // src/protocol/outbound/ship-management.js
@@ -8493,9 +8928,9 @@
8493
8928
  throw new RangeError('direction must be "down", "up", "left", "right", or an integer from 0 to 3');
8494
8929
  }
8495
8930
  function requireNonNegativeInteger(value, name) {
8496
- const number = Number(value);
8497
- if (!Number.isInteger(number) || number < 0) throw new RangeError(`${name} must be a non-negative integer`);
8498
- return number;
8931
+ const number2 = Number(value);
8932
+ if (!Number.isInteger(number2) || number2 < 0) throw new RangeError(`${name} must be a non-negative integer`);
8933
+ return number2;
8499
8934
  }
8500
8935
  function normalizePrivacy(value) {
8501
8936
  if (value === true || value === 1 || value === "private") return 1;
@@ -8513,9 +8948,9 @@
8513
8948
  }
8514
8949
  function buildShipManagementMessage(act, arg = null, extra = null) {
8515
8950
  if (typeof act !== "string" || !act) throw new TypeError(`act must be a non-empty string`);
8516
- const message2 = { type: SHIP_MANAGEMENT_TYPE, act, arg };
8517
- if (extra && typeof extra === "object") Object.assign(message2, extra);
8518
- return message2;
8951
+ const message3 = { type: SHIP_MANAGEMENT_TYPE, act, arg };
8952
+ if (extra && typeof extra === "object") Object.assign(message3, extra);
8953
+ return message3;
8519
8954
  }
8520
8955
  function buildShipPrivacyMessage(privacy) {
8521
8956
  return buildShipManagementMessage(SET_PRIVACY_ACTION, normalizePrivacy(privacy));
@@ -8557,13 +8992,13 @@
8557
8992
  function buildShipRenameRequestMessage() {
8558
8993
  return buildShipManagementMessage(RENAME_REQUEST_ACTION);
8559
8994
  }
8560
- function buildShipRenameCommitMessage(name, color) {
8995
+ function buildShipRenameCommitMessage(name, color2) {
8561
8996
  if (typeof name !== "string") throw new TypeError("name must be a string");
8562
8997
  if (name.length > 32) throw new RangeError("name must be at most 32 UTF-16 code units");
8563
- if (typeof color !== "string" || !/^#[0-9a-f]{6}$/i.test(color)) {
8998
+ if (typeof color2 !== "string" || !/^#[0-9a-f]{6}$/i.test(color2)) {
8564
8999
  throw new TypeError("color must be a #RRGGBB hex string");
8565
9000
  }
8566
- return buildShipManagementMessage(RENAME_COMMIT_ACTION, name, { arg2: color });
9001
+ return buildShipManagementMessage(RENAME_COMMIT_ACTION, name, { arg2: color2 });
8567
9002
  }
8568
9003
  function normalizeShipConfig(event = {}) {
8569
9004
  const source = event && typeof event === "object" ? event : {};
@@ -8679,8 +9114,8 @@
8679
9114
  };
8680
9115
  }
8681
9116
  function normalizeNonNegativeNumber(value) {
8682
- const number = Number(value);
8683
- return Number.isFinite(number) && number > 0 ? number : 0;
9117
+ const number2 = Number(value);
9118
+ return Number.isFinite(number2) && number2 > 0 ? number2 : 0;
8684
9119
  }
8685
9120
  function ownerRankForPlayers(players) {
8686
9121
  const ranks = players.filter((player) => Number(player.captainRank) > 0).map((player) => Number(player.captainRank)).filter(Number.isFinite);
@@ -8737,6 +9172,79 @@
8737
9172
  };
8738
9173
  }
8739
9174
 
9175
+ // src/protocol/outbound/advanced-expando.js
9176
+ init_constants();
9177
+ function number(value, name, min, max) {
9178
+ if (typeof value !== "number" || !Number.isFinite(value) || value < min || value > max) {
9179
+ throw new RangeError(`${name} must be a finite number between ${min} and ${max}`);
9180
+ }
9181
+ return value;
9182
+ }
9183
+ function float(value, name, min, max) {
9184
+ const bytes = new Uint8Array(5);
9185
+ bytes[0] = 136;
9186
+ new DataView(bytes.buffer).setFloat32(1, number(value, name, min, max), true);
9187
+ return [...bytes];
9188
+ }
9189
+ function color(value, name) {
9190
+ number(value, name, 0, 16777215);
9191
+ if (!Number.isInteger(value)) throw new RangeError(`${name} must be an integer RGB color`);
9192
+ return encodeUnsigned(value);
9193
+ }
9194
+ function bool(value, name) {
9195
+ if (typeof value !== "boolean") throw new TypeError(`${name} must be a boolean`);
9196
+ return value ? 141 : 142;
9197
+ }
9198
+ function section2(name, values) {
9199
+ const text2 = encoder.encode(name);
9200
+ return [138, text2.length, ...text2, 0, 144, ...values, 145];
9201
+ }
9202
+ function message2(entity, action, config) {
9203
+ number(entity, "entity", 0, 4294967295);
9204
+ if (!Number.isInteger(entity)) throw new RangeError("entity must be an unsigned 32-bit integer");
9205
+ const {
9206
+ minWidth = 2,
9207
+ maxWidth = 10,
9208
+ minHeight = 2,
9209
+ maxHeight = 10,
9210
+ minEnabled = false,
9211
+ maxEnabled = false,
9212
+ fixedSize = false,
9213
+ backgroundColor = 14540253,
9214
+ borderColor = 4210752,
9215
+ opacity = 1
9216
+ } = config;
9217
+ return Uint8Array.from([
9218
+ 144,
9219
+ action,
9220
+ ...encodeUnsigned(entity),
9221
+ ...section2("config_expando_size", [
9222
+ ...float(minWidth, "minWidth", 2, 100),
9223
+ ...float(maxWidth, "maxWidth", 2, 100),
9224
+ ...float(minHeight, "minHeight", 2, 100),
9225
+ ...float(maxHeight, "maxHeight", 2, 100),
9226
+ bool(minEnabled, "minEnabled"),
9227
+ bool(maxEnabled, "maxEnabled"),
9228
+ bool(fixedSize, "fixedSize")
9229
+ ]),
9230
+ ...section2("config_expando_colors", [
9231
+ ...color(backgroundColor, "backgroundColor"),
9232
+ ...color(borderColor, "borderColor"),
9233
+ ...float(opacity, "opacity", 0, 1)
9234
+ ]),
9235
+ 145
9236
+ ]);
9237
+ }
9238
+ function buildAdvancedExpandoBoxConfigData(entity, config = {}) {
9239
+ return message2(entity, 0, config);
9240
+ }
9241
+ function buildAdvancedExpandoBoxCopyConfigData(config = {}) {
9242
+ return message2(11, 1, config);
9243
+ }
9244
+ function buildAdvancedExpandoBoxPasteConfigData(entity, config = {}) {
9245
+ return message2(entity, 2, config);
9246
+ }
9247
+
8740
9248
  // src/protocol/outbound/ui-config.js
8741
9249
  init_constants();
8742
9250
  var NAV_UNIT_COMMAND = "config_nav_unit";
@@ -8792,18 +9300,11 @@
8792
9300
  High: "high"
8793
9301
  });
8794
9302
  function requireByteInteger(value, name) {
8795
- const number = Number(value);
8796
- if (!Number.isInteger(number) || number < 0 || number > 255) {
9303
+ const number2 = Number(value);
9304
+ if (!Number.isInteger(number2) || number2 < 0 || number2 > 255) {
8797
9305
  throw new RangeError(`${name} must be an integer between 0 and 255`);
8798
9306
  }
8799
- return number;
8800
- }
8801
- function requireUint16(value, name) {
8802
- const number = Number(value);
8803
- if (!Number.isInteger(number) || number < 0 || number > 65535) {
8804
- throw new RangeError(`${name} must be an integer between 0 and 65535`);
8805
- }
8806
- return number;
9307
+ return number2;
8807
9308
  }
8808
9309
  function navConfigBool(value) {
8809
9310
  return value ? NAV_UNIT_TRUE : NAV_UNIT_FALSE;
@@ -8814,32 +9315,32 @@
8814
9315
  throw new TypeError(`warp must be true, false, "start", "idle", or "cancel"`);
8815
9316
  }
8816
9317
  function requirePusherMode(value, name) {
8817
- const number = PUSHER_MODE_VALUES.get(value);
8818
- if (number == null || !Number.isInteger(number) || number < 0 || number > 2) {
9318
+ const number2 = PUSHER_MODE_VALUES.get(value);
9319
+ if (number2 == null || !Number.isInteger(number2) || number2 < 0 || number2 > 2) {
8819
9320
  throw new RangeError(`${name} must be PusherMode.Push, PusherMode.Pull, or PusherMode.DoNothing`);
8820
9321
  }
8821
- return number;
9322
+ return number2;
8822
9323
  }
8823
9324
  function requireLoaderPosition(value, name) {
8824
- const number = LOADER_POSITION_VALUES.get(value);
8825
- if (number == null || !Number.isInteger(number) || number < 0 || number > 7) {
9325
+ const number2 = LOADER_POSITION_VALUES.get(value);
9326
+ if (number2 == null || !Number.isInteger(number2) || number2 < 0 || number2 > 7) {
8826
9327
  throw new RangeError(`${name} must be a LoaderPosition value`);
8827
9328
  }
8828
- return number;
9329
+ return number2;
8829
9330
  }
8830
9331
  function requireLoaderPriority(value, name) {
8831
- const number = LOADER_PRIORITY_VALUES.get(value);
8832
- if (number == null || !Number.isInteger(number) || number < -1 || number > 1) {
9332
+ const number2 = LOADER_PRIORITY_VALUES.get(value);
9333
+ if (number2 == null || !Number.isInteger(number2) || number2 < -1 || number2 > 1) {
8833
9334
  throw new RangeError(`${name} must be a LoaderPriority value`);
8834
9335
  }
8835
- return number + 1;
9336
+ return number2 + 1;
8836
9337
  }
8837
9338
  function requireLoaderFilterMode(value, name) {
8838
- const number = LOADER_FILTER_MODE_VALUES.get(value);
8839
- if (number == null || !Number.isInteger(number) || number < 0 || number > 3) {
9339
+ const number2 = LOADER_FILTER_MODE_VALUES.get(value);
9340
+ if (number2 == null || !Number.isInteger(number2) || number2 < 0 || number2 > 3) {
8840
9341
  throw new RangeError(`${name} must be a LoaderFilterMode value`);
8841
9342
  }
8842
- return number;
9343
+ return number2;
8843
9344
  }
8844
9345
  var CLIPBOARD_TARGET_VALUES = /* @__PURE__ */ new Map([
8845
9346
  ["launcher", 8],
@@ -8876,54 +9377,54 @@
8876
9377
  [FixedAngleDirection.Down, 3]
8877
9378
  ]);
8878
9379
  function requireClipboardTarget(value, name = "target") {
8879
- const number = typeof value === "string" ? CLIPBOARD_TARGET_VALUES.get(value) : Number(value);
8880
- if (number == null || !Number.isInteger(number) || number < 0 || number > 255) {
9380
+ const number2 = typeof value === "string" ? CLIPBOARD_TARGET_VALUES.get(value) : Number(value);
9381
+ if (number2 == null || !Number.isInteger(number2) || number2 < 0 || number2 > 255) {
8881
9382
  throw new RangeError(`${name} must be a clipboard target byte or known target name`);
8882
9383
  }
8883
- return number;
9384
+ return number2;
8884
9385
  }
8885
9386
  function requireFixedAngle(value, name = "direction") {
8886
- const number = FIXED_ANGLE_VALUES.get(value);
8887
- if (number == null || !Number.isInteger(number) || number < 0 || number > 3) {
9387
+ const number2 = FIXED_ANGLE_VALUES.get(value);
9388
+ if (number2 == null || !Number.isInteger(number2) || number2 < 0 || number2 > 3) {
8888
9389
  throw new RangeError(`${name} must be a FixedAngleDirection value`);
8889
9390
  }
8890
- return number;
9391
+ return number2;
8891
9392
  }
8892
9393
  function requireAngleDegrees(value, name = "angle") {
8893
- const number = Number(value);
8894
- if (!Number.isInteger(number) || number < 0 || number > 359) {
9394
+ const number2 = Number(value);
9395
+ if (!Number.isInteger(number2) || number2 < 0 || number2 > 359) {
8895
9396
  throw new RangeError(`${name} must be an integer degree value between 0 and 359`);
8896
9397
  }
8897
- return number;
9398
+ return number2;
8898
9399
  }
8899
9400
  function requireFiniteNumber2(value, name) {
8900
- const number = Number(value);
8901
- if (!Number.isFinite(number)) throw new RangeError(`${name} must be a finite number`);
8902
- return number;
9401
+ const number2 = Number(value);
9402
+ if (!Number.isFinite(number2)) throw new RangeError(`${name} must be a finite number`);
9403
+ return number2;
8903
9404
  }
8904
9405
  function requireNonNegativeInteger2(value, name) {
8905
- const number = Number(value);
8906
- if (!Number.isInteger(number) || number < 0) throw new RangeError(`${name} must be a non-negative integer`);
8907
- return number;
9406
+ const number2 = Number(value);
9407
+ if (!Number.isInteger(number2) || number2 < 0) throw new RangeError(`${name} must be a non-negative integer`);
9408
+ return number2;
8908
9409
  }
8909
9410
  function encodeCompactNumber(value, name) {
8910
- const number = requireFiniteNumber2(value, name);
8911
- if (!Number.isInteger(number)) {
9411
+ const number2 = requireFiniteNumber2(value, name);
9412
+ if (!Number.isInteger(number2)) {
8912
9413
  const out = new Uint8Array(5);
8913
9414
  out[0] = 136;
8914
- new DataView(out.buffer).setFloat32(1, number, true);
9415
+ new DataView(out.buffer).setFloat32(1, number2, true);
8915
9416
  return [...out];
8916
9417
  }
8917
- if (number < 0) throw new RangeError(`${name} must be non-negative`);
8918
- if (number <= 31) return [number];
8919
- if (number <= 127) return [132, number];
8920
- if (number <= 65535) return [133, number & 255, number >> 8 & 255];
9418
+ if (number2 < 0) throw new RangeError(`${name} must be non-negative`);
9419
+ if (number2 <= 31) return [number2];
9420
+ if (number2 <= 127) return [132, number2];
9421
+ if (number2 <= 65535) return [133, number2 & 255, number2 >> 8 & 255];
8921
9422
  throw new RangeError(`${name} must be 65535 or lower`);
8922
9423
  }
8923
9424
  function encodeCompactItemId(value, name) {
8924
- const number = requireNonNegativeInteger2(value, name);
8925
- if (number === 0) return [0];
8926
- return encodeCompactNumber(number, name);
9425
+ const number2 = requireNonNegativeInteger2(value, name);
9426
+ if (number2 === 0) return [0];
9427
+ return encodeCompactNumber(number2, name);
8927
9428
  }
8928
9429
  function encodeLoaderCycle(cycle) {
8929
9430
  const seconds = requireFiniteNumber2(cycle, "cycle");
@@ -8935,16 +9436,12 @@
8935
9436
  throw new RangeError(`cycle is too large`);
8936
9437
  }
8937
9438
  function encodeUiCommandTarget(entity, action = 0) {
8938
- const entityId = requireUint16(entity, "entity");
8939
- const actionId = requireByteInteger(action, "action");
8940
- if (actionId && entityId > 255) {
8941
- throw new RangeError(`copy/paste UI config currently requires an entity id below 256`);
9439
+ const entityId = Number(entity);
9440
+ if (!Number.isInteger(entityId) || entityId < 0 || entityId > 4294967295) {
9441
+ throw new RangeError("entity must be an unsigned 32-bit integer");
8942
9442
  }
8943
- return [
8944
- NAV_UNIT_HEADER_TAG,
8945
- actionId ? actionId : entityId >> 8 & 255,
8946
- entityId & 255
8947
- ];
9443
+ const actionId = requireByteInteger(action, "action");
9444
+ return [NAV_UNIT_HEADER_TAG, actionId, ...encodeUnsigned(entityId)];
8948
9445
  }
8949
9446
  function encodeUiCommandSection(commandName) {
8950
9447
  const command = encoder.encode(commandName);
@@ -9293,11 +9790,11 @@
9293
9790
  send(command = {}) {
9294
9791
  return this.client.send(command);
9295
9792
  }
9296
- sendMessage(message2, options = {}) {
9297
- return this.client.sendMessage(message2, options);
9793
+ sendMessage(message3, options = {}) {
9794
+ return this.client.sendMessage(message3, options);
9298
9795
  }
9299
- sendRaw(message2, options = {}) {
9300
- return this.client.sendRaw(message2, options);
9796
+ sendRaw(message3, options = {}) {
9797
+ return this.client.sendRaw(message3, options);
9301
9798
  }
9302
9799
  sendEntityCommand(cmd, args = [-1, -1, -1]) {
9303
9800
  return this.client.sendEntityCommand(cmd, args);
@@ -9600,6 +10097,7 @@
9600
10097
  this.recyclers = new EntitySummaryCollection(client, scope, "recyclers");
9601
10098
  this.blocks = new BlockCollection(client, scope);
9602
10099
  this.materials = new MaterialCollection(client, scope);
10100
+ this.tiles = new TileDomain(client, scope);
9603
10101
  }
9604
10102
  get id() {
9605
10103
  return worldStateFor(this.client, this.scope)?.id ?? null;
@@ -9800,6 +10298,27 @@
9800
10298
  return worldStateFor(this.client, this.scope)?.materials() || [];
9801
10299
  }
9802
10300
  };
10301
+ var TileDomain = class {
10302
+ constructor(client, scope) {
10303
+ this.client = client;
10304
+ this.scope = scope;
10305
+ }
10306
+ get count() {
10307
+ return worldStateFor(this.client, this.scope)?.tiles.size ?? 0;
10308
+ }
10309
+ get version() {
10310
+ return worldStateFor(this.client, this.scope)?.tileVersion ?? 0;
10311
+ }
10312
+ chunks() {
10313
+ return worldStateFor(this.client, this.scope)?.tileChunks() || [];
10314
+ }
10315
+ at(x, y) {
10316
+ return worldStateFor(this.client, this.scope)?.tileAt(x, y) ?? null;
10317
+ }
10318
+ all() {
10319
+ return worldStateFor(this.client, this.scope)?.tiles.toArray() || [];
10320
+ }
10321
+ };
9803
10322
  var MachineCollection = class {
9804
10323
  constructor(client, scope) {
9805
10324
  this.client = client;
@@ -10272,8 +10791,8 @@
10272
10791
  panel() {
10273
10792
  return this.client.commsPanels.get(this.id) || null;
10274
10793
  }
10275
- sendMessage(message2 = "") {
10276
- return this.client.sendCommsMessage(message2);
10794
+ sendMessage(message3 = "") {
10795
+ return this.client.sendCommsMessage(message3);
10277
10796
  }
10278
10797
  };
10279
10798
  var SignHandle = class extends MachineHandle {
@@ -10420,6 +10939,21 @@
10420
10939
  get count() {
10421
10940
  return this.state?.count;
10422
10941
  }
10942
+ #requireAdvanced() {
10943
+ if (!this.state?.advanced) throw new Error("Configuration requires an Advanced Expando Box");
10944
+ }
10945
+ configure(config = {}) {
10946
+ this.#requireAdvanced();
10947
+ return this.client.sendAdvancedExpandoBoxConfig(this.id, config);
10948
+ }
10949
+ copy(config = {}) {
10950
+ this.#requireAdvanced();
10951
+ return this.client.copyAdvancedExpandoBoxConfig(this.id, config);
10952
+ }
10953
+ paste(config = {}) {
10954
+ this.#requireAdvanced();
10955
+ return this.client.pasteAdvancedExpandoBoxConfig(this.id, config);
10956
+ }
10423
10957
  };
10424
10958
  var CargoEjectorHandle = class extends MachineHandle {
10425
10959
  get state() {
@@ -10692,9 +11226,9 @@
10692
11226
  return normalizeInventorySlotIndex(value, name);
10693
11227
  }
10694
11228
  function normalizeInventorySlotIndex(value, name = "slot") {
10695
- const number = Number(value);
10696
- if (!Number.isInteger(number) || number < 0) throw new RangeError(`${name} must be a non-negative inventory slot index`);
10697
- return number;
11229
+ const number2 = Number(value);
11230
+ if (!Number.isInteger(number2) || number2 < 0) throw new RangeError(`${name} must be a non-negative inventory slot index`);
11231
+ return number2;
10698
11232
  }
10699
11233
  function currentPlayerSummary(client, scope = "current") {
10700
11234
  const sid = Number(client?.sid);
@@ -10776,14 +11310,14 @@
10776
11310
  return normalized;
10777
11311
  }
10778
11312
  function normalizePositiveFinite(value, name) {
10779
- const number = Number(value);
10780
- if (!Number.isFinite(number) || number <= 0) throw new RangeError(`${name} must be a positive finite number`);
10781
- return number;
11313
+ const number2 = Number(value);
11314
+ if (!Number.isFinite(number2) || number2 <= 0) throw new RangeError(`${name} must be a positive finite number`);
11315
+ return number2;
10782
11316
  }
10783
11317
  function normalizePositiveInteger(value, name) {
10784
- const number = Number(value);
10785
- if (!Number.isInteger(number) || number <= 0) throw new RangeError(`${name} must be a positive integer`);
10786
- return number;
11318
+ const number2 = Number(value);
11319
+ if (!Number.isInteger(number2) || number2 <= 0) throw new RangeError(`${name} must be a positive integer`);
11320
+ return number2;
10787
11321
  }
10788
11322
  function normalizeScannerResultPacket(packet) {
10789
11323
  const manifest = packet?.manifest && typeof packet.manifest === "object" ? packet.manifest : {};
@@ -11004,18 +11538,18 @@
11004
11538
  this.emit("command", normalized);
11005
11539
  return this;
11006
11540
  }
11007
- sendMessage(message2, { afterReady = true } = {}) {
11541
+ sendMessage(message3, { afterReady = true } = {}) {
11008
11542
  this.#assertWritable();
11009
11543
  if (!this.connected || afterReady && !this.ready) {
11010
- this.#queuedMessages.push({ message: message2, afterReady });
11544
+ this.#queuedMessages.push({ message: message3, afterReady });
11011
11545
  return this;
11012
11546
  }
11013
- this.ws.send(encodeMsgpack(message2));
11014
- this.emit("message", message2);
11547
+ this.ws.send(encodeMsgpack(message3));
11548
+ this.emit("message", message3);
11015
11549
  return this;
11016
11550
  }
11017
- sendRaw(message2, options = {}) {
11018
- return this.sendMessage(message2, options);
11551
+ sendRaw(message3, options = {}) {
11552
+ return this.sendMessage(message3, options);
11019
11553
  }
11020
11554
  sendBlueprintPlacement(placement) {
11021
11555
  return this.sendMessage(buildBlueprintPlacementMessage(placement));
@@ -11068,9 +11602,9 @@
11068
11602
  this.#savePending = false;
11069
11603
  }
11070
11604
  }
11071
- async renameShip(name, { color, timeout = 1e4 } = {}) {
11605
+ async renameShip(name, { color: color2, timeout = 1e4 } = {}) {
11072
11606
  this.#assertWritable();
11073
- buildShipRenameCommitMessage(name, color === void 0 ? "#000000" : color);
11607
+ buildShipRenameCommitMessage(name, color2 === void 0 ? "#000000" : color2);
11074
11608
  if (!Number.isFinite(timeout) || timeout <= 0 || timeout > 2147483647) {
11075
11609
  throw new RangeError("timeout must be positive milliseconds no greater than 2147483647");
11076
11610
  }
@@ -11101,7 +11635,7 @@
11101
11635
  try {
11102
11636
  if (!response.allow) throw new Error(response.message || "Ship rename unavailable");
11103
11637
  if (this.worlds.currentWorldId !== worldId) throw new Error("World changed while requesting ship rename");
11104
- this.sendMessage(buildShipRenameCommitMessage(name, color === void 0 ? response.initial_color : color));
11638
+ this.sendMessage(buildShipRenameCommitMessage(name, color2 === void 0 ? response.initial_color : color2));
11105
11639
  resolve();
11106
11640
  } catch (error) {
11107
11641
  reject(error);
@@ -11143,7 +11677,7 @@
11143
11677
  }
11144
11678
  async recoverStarterItem(itemId, { timeout = 1e4 } = {}) {
11145
11679
  this.#assertWritable();
11146
- const message2 = buildStarterRecoveryMessage(itemId);
11680
+ const message3 = buildStarterRecoveryMessage(itemId);
11147
11681
  if (!Number.isFinite(timeout) || timeout <= 0 || timeout > 2147483647) {
11148
11682
  throw new RangeError("timeout must be positive milliseconds no greater than 2147483647");
11149
11683
  }
@@ -11181,7 +11715,7 @@
11181
11715
  this.on("disconnect", disconnected);
11182
11716
  this.on("demote", demoted);
11183
11717
  try {
11184
- this.sendMessage(message2);
11718
+ this.sendMessage(message3);
11185
11719
  } catch (error) {
11186
11720
  cleanup();
11187
11721
  reject(error);
@@ -11215,7 +11749,7 @@
11215
11749
  async demoteSelf(options = {}) {
11216
11750
  await this.#awaitManagementConfirmation("Self-demotion", buildDemoteSelfMessage(), "demote", () => true, options);
11217
11751
  }
11218
- async #awaitManagementConfirmation(operation, message2, event, accept, { timeout = 1e4 } = {}) {
11752
+ async #awaitManagementConfirmation(operation, message3, event, accept, { timeout = 1e4 } = {}) {
11219
11753
  this.#assertWritable();
11220
11754
  if (!Number.isFinite(timeout) || timeout <= 0 || timeout > 2147483647) {
11221
11755
  throw new RangeError("timeout must be positive milliseconds no greater than 2147483647");
@@ -11251,7 +11785,7 @@
11251
11785
  this.on("disconnect", disconnected);
11252
11786
  if (event !== "demote") this.on("demote", demoted);
11253
11787
  try {
11254
- this.sendMessage(message2);
11788
+ this.sendMessage(message3);
11255
11789
  } catch (error) {
11256
11790
  fail(error);
11257
11791
  }
@@ -11263,11 +11797,11 @@
11263
11797
  sendEntityCommand(cmd, args = [-1, -1, -1]) {
11264
11798
  return this.sendMessage({ type: 5, cmd, args });
11265
11799
  }
11266
- sendChatMessage(message2 = "") {
11267
- return this.sendMessage(buildChatMessage(message2));
11800
+ sendChatMessage(message3 = "") {
11801
+ return this.sendMessage(buildChatMessage(message3));
11268
11802
  }
11269
- sendCommsMessage(message2 = "") {
11270
- return this.sendMessage(buildCommsMessage(message2));
11803
+ sendCommsMessage(message3 = "") {
11804
+ return this.sendMessage(buildCommsMessage(message3));
11271
11805
  }
11272
11806
  sendFabricatorMessage(cmd, args = [-1, -1, -1]) {
11273
11807
  return this.sendEntityCommand(cmd, args);
@@ -11296,6 +11830,19 @@
11296
11830
  fabricatorEject(row) {
11297
11831
  return this.sendFabricatorMessage("eject", [row, -1, -1]);
11298
11832
  }
11833
+ #advancedExpandoBoxConfigDefaults(entity, config) {
11834
+ const observed = this.worlds.shipWorld()?.entity(entity)?.contents?.expandoBox?.config;
11835
+ return { ...observed, ...Object.fromEntries(Object.entries(config).filter(([, value]) => value !== void 0)) };
11836
+ }
11837
+ sendAdvancedExpandoBoxConfig(entity, config = {}) {
11838
+ return this.sendUiConfig(buildAdvancedExpandoBoxConfigData(entity, this.#advancedExpandoBoxConfigDefaults(entity, config)));
11839
+ }
11840
+ copyAdvancedExpandoBoxConfig(entity, config = {}) {
11841
+ return this.sendUiConfig(buildAdvancedExpandoBoxCopyConfigData(this.#advancedExpandoBoxConfigDefaults(entity, config)));
11842
+ }
11843
+ pasteAdvancedExpandoBoxConfig(entity, config = {}) {
11844
+ return this.sendUiConfig(buildAdvancedExpandoBoxPasteConfigData(entity, this.#advancedExpandoBoxConfigDefaults(entity, config)));
11845
+ }
11299
11846
  sendLauncherConfig(entity, config = {}) {
11300
11847
  return this.sendUiConfig(buildLauncherConfigData(entity, this.#launcherConfigDefaults(entity, config)));
11301
11848
  }
@@ -11529,14 +12076,14 @@
11529
12076
  return this.useHeldItem(options, command);
11530
12077
  }
11531
12078
  placeBlueprint(placement, { invSlot = 0, hold = true, mx = null, my = null } = {}, command = {}) {
11532
- const message2 = buildBlueprintPlacementMessage(placement);
11533
- this.sendMessage(message2);
12079
+ const message3 = buildBlueprintPlacementMessage(placement);
12080
+ this.sendMessage(message3);
11534
12081
  return this.placeHeldItem(
11535
12082
  { invSlot, hold },
11536
12083
  {
11537
12084
  ...command,
11538
- mx: mx ?? message2.x,
11539
- my: my ?? message2.y
12085
+ mx: mx ?? message3.x,
12086
+ my: my ?? message3.y
11540
12087
  }
11541
12088
  );
11542
12089
  }
@@ -11741,12 +12288,12 @@
11741
12288
  }
11742
12289
  #bindAttachedSocket() {
11743
12290
  const open = () => this.#attachedOpen();
11744
- const message2 = (event) => this.#handleSocketMessage(event?.data ?? event);
12291
+ const message3 = (event) => this.#handleSocketMessage(event?.data ?? event);
11745
12292
  const error = (event) => this.#fail(event?.error || new Error("WebSocket error"));
11746
12293
  const close = (event, reason) => this.#handleSocketClose(event, reason);
11747
12294
  if (typeof this.ws.addEventListener === "function") {
11748
12295
  this.ws.addEventListener("open", open);
11749
- this.ws.addEventListener("message", message2);
12296
+ this.ws.addEventListener("message", message3);
11750
12297
  this.ws.addEventListener("error", error);
11751
12298
  this.ws.addEventListener("close", close);
11752
12299
  return;
@@ -11758,7 +12305,7 @@
11758
12305
  this.ws.on("close", close);
11759
12306
  return;
11760
12307
  }
11761
- for (const [type, handler] of Object.entries({ open, message: message2, error, close })) {
12308
+ for (const [type, handler] of Object.entries({ open, message: message3, error, close })) {
11762
12309
  const previous = this.ws[`on${type}`];
11763
12310
  this.ws[`on${type}`] = (...args) => {
11764
12311
  if (typeof previous === "function") previous.apply(this.ws, args);
@@ -12062,7 +12609,7 @@
12062
12609
  return headers;
12063
12610
  }
12064
12611
  #navigationUnitConfigDefaults(entity, config = {}) {
12065
- const summary = this.entity(entity)?.contents?.navigationUnit || null;
12612
+ const summary = this.worlds.shipWorld()?.entity(entity)?.contents?.navigationUnit || null;
12066
12613
  return {
12067
12614
  destination: config.destination ?? summary?.destination,
12068
12615
  page: config.page ?? 0,
@@ -12159,8 +12706,8 @@
12159
12706
  init_constants();
12160
12707
  init_runtime();
12161
12708
  init_http();
12162
- function createShipSpec(name = "", color = "") {
12163
- return { type: "new", name: String(name ?? ""), color: String(color ?? "") };
12709
+ function createShipSpec(name = "", color2 = "") {
12710
+ return { type: "new", name: String(name ?? ""), color: String(color2 ?? "") };
12164
12711
  }
12165
12712
  function createInviteShipSpec(code) {
12166
12713
  return { type: "invite", code: String(code ?? "") };
@@ -12311,7 +12858,7 @@
12311
12858
  if (!found) throw new Error("Account page has no clan form; authentication may be required or the page format has changed");
12312
12859
  const fields = /* @__PURE__ */ new Map();
12313
12860
  let name = null;
12314
- let color = null;
12861
+ let color2 = null;
12315
12862
  for (const paragraph of source.matchAll(/<p\b[^>]*>([\s\S]*?)<\/p\s*>/gi)) {
12316
12863
  const label = paragraph[1].match(/<b\b[^>]*>([\s\S]*?)<\/b\s*>/i);
12317
12864
  const code = paragraph[1].match(/<code\b((?:"[^"]*"|'[^']*'|[^'">])*)>([\s\S]*?)<\/code\s*>/i);
@@ -12320,7 +12867,7 @@
12320
12867
  if (label) fields.set(text(label[1]).replace(/:\s*$/, "").toLowerCase(), attrs.get("data-info") ?? null);
12321
12868
  if ((attrs.get("class") || "").split(/\s+/).includes("user") && /^You are:$/i.test(text(paragraph[1].slice(0, code.index)))) {
12322
12869
  name = decodeHtml(code[2].replace(/<[^>]*>/g, ""));
12323
- color = parseAccountColor(attrs.get("style") || "");
12870
+ color2 = parseAccountColor(attrs.get("style") || "");
12324
12871
  }
12325
12872
  }
12326
12873
  const rawIdentity = fields.get("identity (service)") || null;
@@ -12328,7 +12875,7 @@
12328
12875
  const count = text(source).match(/Your current clan tag has\s+([\d,]+)\s+other users?\b/i);
12329
12876
  return {
12330
12877
  name,
12331
- color,
12878
+ color: color2,
12332
12879
  email: fields.get("email") || null,
12333
12880
  identity: identityParts ? identityParts[1].trim() : rawIdentity,
12334
12881
  identityService: identityParts ? identityParts[2].trim() : null,
@@ -12337,14 +12884,14 @@
12337
12884
  };
12338
12885
  }
12339
12886
  function parseAccountColor(style) {
12340
- let color = null;
12887
+ let color2 = null;
12341
12888
  for (const declaration of style.split(";")) {
12342
12889
  const match = declaration.match(/^\s*background(?:-color)?\s*:\s*#([0-9a-f]{6}|[0-9a-f]{3})\s*(?:!important\s*)?$/i);
12343
12890
  if (!match) continue;
12344
12891
  const hex = match[1].length === 3 ? [...match[1]].map((digit) => digit + digit).join("") : match[1];
12345
- color = parseInt(hex, 16);
12892
+ color2 = parseInt(hex, 16);
12346
12893
  }
12347
- return color;
12894
+ return color2;
12348
12895
  }
12349
12896
  function parseShipsWithPerks(source) {
12350
12897
  const heading = source.match(/<(b|strong)\b[^>]*>\s*Ships\s+with\s+Perks\s+Applied\s*:\s*<\/\1\s*>/i);
@@ -12474,8 +13021,8 @@
12474
13021
  async startShipConnection(server2, ship = null) {
12475
13022
  return this.#startShipConnection(server2, ship, false);
12476
13023
  }
12477
- async startNewShipConnection(server2, name = "", color = "") {
12478
- return this.#startShipConnection(server2, createShipSpec(name, color), false);
13024
+ async startNewShipConnection(server2, name = "", color2 = "") {
13025
+ return this.#startShipConnection(server2, createShipSpec(name, color2), false);
12479
13026
  }
12480
13027
  async joinInviteConnection(server2, code) {
12481
13028
  return this.#startShipConnection(server2, createInviteShipSpec(code), false);
@@ -12486,8 +13033,8 @@
12486
13033
  async startShip(server2, ship = null) {
12487
13034
  return readyClient(await this.startShipConnection(server2, ship));
12488
13035
  }
12489
- async startNewShip(server2, name = "", color = "") {
12490
- return readyClient(await this.startNewShipConnection(server2, name, color));
13036
+ async startNewShip(server2, name = "", color2 = "") {
13037
+ return readyClient(await this.startNewShipConnection(server2, name, color2));
12491
13038
  }
12492
13039
  async joinInvite(server2, code) {
12493
13040
  return readyClient(await this.joinInviteConnection(server2, code));
@@ -12668,8 +13215,8 @@
12668
13215
  async startShipConnection(server2, ship = null) {
12669
13216
  return this.#joinBrowserConnection(server2, ship, false);
12670
13217
  }
12671
- async startNewShipConnection(server2, name = "", color = "") {
12672
- return this.#joinBrowserConnection(server2, createShipSpec(name, color), false);
13218
+ async startNewShipConnection(server2, name = "", color2 = "") {
13219
+ return this.#joinBrowserConnection(server2, createShipSpec(name, color2), false);
12673
13220
  }
12674
13221
  async joinInviteConnection(server2, code) {
12675
13222
  return this.#joinBrowserConnection(server2, createInviteShipSpec(code), false);
@@ -12680,8 +13227,8 @@
12680
13227
  async startShip(server2, ship = null) {
12681
13228
  return readyBrowserClient(await this.startShipConnection(server2, ship));
12682
13229
  }
12683
- async startNewShip(server2, name = "", color = "") {
12684
- return readyBrowserClient(await this.startNewShipConnection(server2, name, color));
13230
+ async startNewShip(server2, name = "", color2 = "") {
13231
+ return readyBrowserClient(await this.startNewShipConnection(server2, name, color2));
12685
13232
  }
12686
13233
  async joinInvite(server2, code) {
12687
13234
  return readyBrowserClient(await this.joinInviteConnection(server2, code));
@@ -12788,8 +13335,8 @@
12788
13335
  async function startShip(server2, ship = null, session = null) {
12789
13336
  return (session || browserSession()).startShip(server2, ship);
12790
13337
  }
12791
- async function startNewShip(server2, name = "", color = "", session = null) {
12792
- return (session || browserSession()).startNewShip(server2, name, color);
13338
+ async function startNewShip(server2, name = "", color2 = "", session = null) {
13339
+ return (session || browserSession()).startNewShip(server2, name, color2);
12793
13340
  }
12794
13341
  async function joinInvite(server2, code, session = null) {
12795
13342
  return (session || browserSession()).joinInvite(server2, code);