@colyseus/sdk 0.17.40 → 0.17.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/build/3rd_party/discord.cjs +1 -1
  2. package/build/3rd_party/discord.mjs +1 -1
  3. package/build/Auth.cjs +1 -1
  4. package/build/Auth.mjs +1 -1
  5. package/build/Client.cjs +1 -1
  6. package/build/Client.mjs +1 -1
  7. package/build/Connection.cjs +1 -1
  8. package/build/Connection.mjs +1 -1
  9. package/build/HTTP.cjs +1 -1
  10. package/build/HTTP.mjs +1 -1
  11. package/build/Room.cjs +1 -1
  12. package/build/Room.mjs +1 -1
  13. package/build/Storage.cjs +1 -1
  14. package/build/Storage.mjs +1 -1
  15. package/build/core/nanoevents.cjs +1 -1
  16. package/build/core/nanoevents.mjs +1 -1
  17. package/build/core/signal.cjs +1 -1
  18. package/build/core/signal.mjs +1 -1
  19. package/build/core/utils.cjs +1 -1
  20. package/build/core/utils.mjs +1 -1
  21. package/build/debug.cjs +70 -44
  22. package/build/debug.cjs.map +1 -1
  23. package/build/debug.mjs +70 -44
  24. package/build/debug.mjs.map +1 -1
  25. package/build/errors/Errors.cjs +1 -1
  26. package/build/errors/Errors.mjs +1 -1
  27. package/build/fetchXHR.cjs +1 -1
  28. package/build/fetchXHR.mjs +1 -1
  29. package/build/index.cjs +1 -1
  30. package/build/index.mjs +1 -1
  31. package/build/legacy.cjs +1 -1
  32. package/build/legacy.mjs +1 -1
  33. package/build/serializer/NoneSerializer.cjs +1 -1
  34. package/build/serializer/NoneSerializer.mjs +1 -1
  35. package/build/serializer/SchemaSerializer.cjs +1 -1
  36. package/build/serializer/SchemaSerializer.mjs +1 -1
  37. package/build/serializer/Serializer.cjs +1 -1
  38. package/build/serializer/Serializer.mjs +1 -1
  39. package/build/transport/H3Transport.cjs +70 -21
  40. package/build/transport/H3Transport.cjs.map +1 -1
  41. package/build/transport/H3Transport.d.ts +16 -0
  42. package/build/transport/H3Transport.mjs +69 -23
  43. package/build/transport/H3Transport.mjs.map +1 -1
  44. package/build/transport/WebSocketTransport.cjs +1 -1
  45. package/build/transport/WebSocketTransport.mjs +1 -1
  46. package/dist/colyseus.js +69 -21
  47. package/dist/colyseus.js.map +1 -1
  48. package/dist/debug.js +70 -44
  49. package/dist/debug.js.map +1 -1
  50. package/package.json +4 -4
  51. package/src/debug.ts +69 -43
  52. package/src/transport/H3Transport.ts +74 -24
package/dist/debug.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // This software is released under the MIT License.
4
4
  // https://opensource.org/license/MIT
5
5
  //
6
- // colyseus.js@0.17.40
6
+ // colyseus.js@0.17.42
7
7
  (function (Client_ts, sharedTypes) {
8
8
  'use strict';
9
9
 
@@ -86,6 +86,19 @@
86
86
  const BASE_MODAL_ZINDEX = 10000;
87
87
  // Load preferences on script load
88
88
  loadPreferences();
89
+ // Shadow DOM root — isolates all debug UI from page-level CSS.
90
+ // Every SDK element is appended here so page rules like `canvas { width: 100vw }`
91
+ // can't reach (or stretch) the debug panel's sparklines, logo, menu, or modals.
92
+ let _debugShadowRoot = null;
93
+ function getDebugRoot() {
94
+ if (_debugShadowRoot)
95
+ return _debugShadowRoot;
96
+ const host = document.createElement('div');
97
+ host.id = 'colyseus-debug-shadow-host';
98
+ _debugShadowRoot = host.attachShadow({ mode: 'open' });
99
+ document.body.appendChild(host);
100
+ return _debugShadowRoot;
101
+ }
89
102
  // Function to select a modal (bring to front)
90
103
  function selectModal(modal) {
91
104
  if (!modal)
@@ -98,8 +111,9 @@
98
111
  // Add to end of stack (most recent)
99
112
  modalStack.push(modal);
100
113
  // Update z-indexes for all modals based on their position in stack
114
+ var root = getDebugRoot();
101
115
  modalStack.forEach((m, i) => {
102
- if (document.body.contains(m)) {
116
+ if (root.contains(m)) {
103
117
  m.style.zIndex = (BASE_MODAL_ZINDEX + i).toString();
104
118
  }
105
119
  });
@@ -116,7 +130,7 @@
116
130
  if (e.key === 'Escape' && modalStack.length > 0) {
117
131
  // Get the most recent modal (top of stack)
118
132
  const topModal = modalStack[modalStack.length - 1];
119
- if (topModal && document.body.contains(topModal)) {
133
+ if (topModal && getDebugRoot().contains(topModal)) {
120
134
  topModal.remove();
121
135
  }
122
136
  }
@@ -366,7 +380,7 @@
366
380
  // Use insertAdjacentHTML for better Safari compatibility with SVG
367
381
  icon.insertAdjacentHTML('beforeend', logoIcon);
368
382
  container.appendChild(icon);
369
- document.body.appendChild(container);
383
+ getDebugRoot().appendChild(container);
370
384
  // Create menu first
371
385
  createMenu(container);
372
386
  // Apply initial position after menu is created
@@ -493,7 +507,8 @@
493
507
  gradient = `linear-gradient(to right, #00c800 0%, ${yellowColor} ${yellowPercent}%, ${color} ${valuePercent}%, #333 ${valuePercent}%, #333 100%)`;
494
508
  }
495
509
  var styleId = 'latency-slider-style';
496
- var existingStyle = document.getElementById(styleId);
510
+ var root = getDebugRoot();
511
+ var existingStyle = root.getElementById(styleId);
497
512
  if (existingStyle) {
498
513
  existingStyle.remove();
499
514
  }
@@ -513,7 +528,7 @@
513
528
  border: none;
514
529
  }
515
530
  `;
516
- document.head.appendChild(style);
531
+ root.appendChild(style);
517
532
  }
518
533
  // Initialize slider color
519
534
  updateSliderColor(parseInt(latencySlider.value));
@@ -557,10 +572,10 @@
557
572
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
558
573
  }
559
574
  `;
560
- document.head.appendChild(style);
575
+ getDebugRoot().appendChild(style);
561
576
  // Function to update container border color
562
577
  function updateContainerBackgroundColor() {
563
- var container = document.getElementById('debug-logo-container');
578
+ var container = getDebugRoot().getElementById('debug-logo-container');
564
579
  if (container) {
565
580
  // Update to normal state (hover handlers will update on hover)
566
581
  container.style.borderColor = getBorderColor(preferences.latencySimulation.delay, 0.7);
@@ -620,7 +635,7 @@
620
635
  openSettingsModal();
621
636
  });
622
637
  menu.appendChild(settingsOption);
623
- document.body.appendChild(menu);
638
+ getDebugRoot().appendChild(menu);
624
639
  // Toggle menu on logo click
625
640
  var menuVisible = false;
626
641
  var hostUpdateInterval = null;
@@ -640,9 +655,15 @@
640
655
  }
641
656
  }
642
657
  });
643
- // Close menu when clicking outside
658
+ // Close menu when clicking outside.
659
+ // Because menu/logo live inside a shadow root, event.target is retargeted
660
+ // to the shadow host for document-level listeners, so we walk the composed
661
+ // path to see whether the real click target was inside the menu or logo.
644
662
  document.addEventListener('click', function (e) {
645
- if (menuVisible && !menu.contains(e.target) && !logoContainer.contains(e.target)) {
663
+ var path = typeof e.composedPath === 'function' ? e.composedPath() : [e.target];
664
+ var clickedInsideMenu = path.indexOf(menu) !== -1;
665
+ var clickedInsideLogo = path.indexOf(logoContainer) !== -1;
666
+ if (menuVisible && !clickedInsideMenu && !clickedInsideLogo) {
646
667
  menuVisible = false;
647
668
  menu.style.display = 'none';
648
669
  if (hostUpdateInterval) {
@@ -655,7 +676,7 @@
655
676
  // Create and open Settings modal
656
677
  function openSettingsModal() {
657
678
  // Remove existing modal if present
658
- var existingModal = document.getElementById('debug-settings-modal');
679
+ var existingModal = getDebugRoot().getElementById('debug-settings-modal');
659
680
  if (existingModal) {
660
681
  existingModal.remove();
661
682
  }
@@ -834,7 +855,7 @@
834
855
  hideContainer.appendChild(hideButton);
835
856
  modal.appendChild(hideContainer);
836
857
  overlay.appendChild(modal);
837
- document.body.appendChild(overlay);
858
+ getDebugRoot().appendChild(overlay);
838
859
  // Mark as selected modal when opened
839
860
  selectModal(overlay);
840
861
  // Update close button to cleanup from modal stack
@@ -869,7 +890,7 @@
869
890
  return;
870
891
  }
871
892
  // Remove existing modal if present
872
- var existingModal = document.getElementById('debug-send-messages-modal');
893
+ var existingModal = getDebugRoot().getElementById('debug-send-messages-modal');
873
894
  if (existingModal) {
874
895
  existingModal.remove();
875
896
  }
@@ -1267,7 +1288,7 @@
1267
1288
  });
1268
1289
  formContainer.appendChild(sendButton);
1269
1290
  modal.appendChild(formContainer);
1270
- document.body.appendChild(modal);
1291
+ getDebugRoot().appendChild(modal);
1271
1292
  }
1272
1293
  // Create and open State Inspector modal
1273
1294
  function openStateInspectorModal(uniquePanelId) {
@@ -1279,7 +1300,7 @@
1279
1300
  }
1280
1301
  var room = debugInfo.room;
1281
1302
  // Remove existing modal if present
1282
- var existingModal = document.getElementById('debug-state-inspector-modal');
1303
+ var existingModal = getDebugRoot().getElementById('debug-state-inspector-modal');
1283
1304
  if (existingModal) {
1284
1305
  existingModal.remove();
1285
1306
  }
@@ -1669,7 +1690,7 @@
1669
1690
  */
1670
1691
  };
1671
1692
  modal.appendChild(contentContainer);
1672
- document.body.appendChild(modal);
1693
+ getDebugRoot().appendChild(modal);
1673
1694
  // Drag and resize state variables
1674
1695
  var isDragging = false;
1675
1696
  var dragStartX = 0;
@@ -1874,9 +1895,10 @@
1874
1895
  }
1875
1896
  // Apply panel position based on current setting
1876
1897
  function applyPanelPosition() {
1877
- var logoContainer = document.getElementById('debug-logo-container');
1878
- var menu = document.getElementById('debug-menu');
1879
- var panels = document.querySelectorAll('[id^="debug-panel-"]');
1898
+ var root = getDebugRoot();
1899
+ var logoContainer = root.getElementById('debug-logo-container');
1900
+ var menu = root.getElementById('debug-menu');
1901
+ var panels = root.querySelectorAll('[id^="debug-panel-"]');
1880
1902
  var positions = {
1881
1903
  'bottom-right': { bottom: '14px', right: '14px', top: 'auto', left: 'auto' },
1882
1904
  'bottom-left': { bottom: '14px', left: '14px', top: 'auto', right: 'auto' },
@@ -1912,9 +1934,10 @@
1912
1934
  function hidePanelsForSession() {
1913
1935
  panelsHidden = true;
1914
1936
  savePreferences(); // Save the hidden state
1915
- var logoContainer = document.getElementById('debug-logo-container');
1916
- var menu = document.getElementById('debug-menu');
1917
- var panels = document.querySelectorAll('[id^="debug-panel-"]');
1937
+ var root = getDebugRoot();
1938
+ var logoContainer = root.getElementById('debug-logo-container');
1939
+ var menu = root.getElementById('debug-menu');
1940
+ var panels = root.querySelectorAll('[id^="debug-panel-"]');
1918
1941
  if (logoContainer) {
1919
1942
  logoContainer.style.display = 'none';
1920
1943
  }
@@ -1941,7 +1964,7 @@
1941
1964
  // Helper function to create debug panel for a room
1942
1965
  function createDebugPanel(uniquePanelId, debugInfo) {
1943
1966
  // Check if panel already exists
1944
- var existingPanel = document.getElementById('debug-panel-' + uniquePanelId);
1967
+ var existingPanel = getDebugRoot().getElementById('debug-panel-' + uniquePanelId);
1945
1968
  if (existingPanel) {
1946
1969
  return existingPanel;
1947
1970
  }
@@ -2070,11 +2093,12 @@
2070
2093
  labelSpan.textContent = 'Reconnecting...';
2071
2094
  }
2072
2095
  // Inject CSS animation if not already present
2073
- if (!document.getElementById('debug-pulse-animation')) {
2096
+ var pulseRoot = getDebugRoot();
2097
+ if (!pulseRoot.getElementById('debug-pulse-animation')) {
2074
2098
  var style = document.createElement('style');
2075
2099
  style.id = 'debug-pulse-animation';
2076
2100
  style.textContent = '@keyframes debug-pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }';
2077
- document.head.appendChild(style);
2101
+ pulseRoot.appendChild(style);
2078
2102
  }
2079
2103
  // Apply initial style
2080
2104
  applyNormalStyle();
@@ -2132,12 +2156,13 @@
2132
2156
  panel.appendChild(title);
2133
2157
  panel.appendChild(content);
2134
2158
  panel.appendChild(actionsContainer);
2135
- // Prepend panel to body so new panels appear first
2136
- if (document.body.firstChild) {
2137
- document.body.insertBefore(panel, document.body.firstChild);
2159
+ // Prepend panel inside the shadow root so new panels appear first
2160
+ var root = getDebugRoot();
2161
+ if (root.firstChild) {
2162
+ root.insertBefore(panel, root.firstChild);
2138
2163
  }
2139
2164
  else {
2140
- document.body.appendChild(panel);
2165
+ root.appendChild(panel);
2141
2166
  }
2142
2167
  return panel;
2143
2168
  }
@@ -2145,7 +2170,7 @@
2145
2170
  function repositionDebugPanels() {
2146
2171
  if (panelsHidden)
2147
2172
  return;
2148
- var panels = Array.from(document.querySelectorAll('[id^="debug-panel-"]'))
2173
+ var panels = Array.from(getDebugRoot().querySelectorAll('[id^="debug-panel-"]'))
2149
2174
  .filter(function (panel) { return panel.style.display !== 'none'; })
2150
2175
  .reverse(); // Reverse to get oldest first (since new panels are prepended)
2151
2176
  // Calculate logoIcon container width: 22px width + 10px padding on each side = 42px
@@ -2187,35 +2212,36 @@
2187
2212
  }
2188
2213
  // Update debug panel content
2189
2214
  function updateDebugPanel(uniquePanelId, debugInfo) {
2215
+ var root = getDebugRoot();
2190
2216
  var contentId = 'debug-content-' + uniquePanelId;
2191
2217
  var panelId = 'debug-panel-' + uniquePanelId;
2192
2218
  var titleId = 'debug-title-' + uniquePanelId;
2193
- var content = document.getElementById(contentId);
2194
- var panel = document.getElementById(panelId);
2195
- var title = document.getElementById(titleId);
2219
+ var content = root.getElementById(contentId);
2220
+ var panel = root.getElementById(panelId);
2221
+ var title = root.getElementById(titleId);
2196
2222
  if (!content || !panel) {
2197
2223
  // Only create if panel doesn't exist
2198
2224
  if (!panel) {
2199
2225
  createDebugPanel(uniquePanelId, debugInfo);
2200
- content = document.getElementById(contentId);
2201
- title = document.getElementById(titleId);
2226
+ content = root.getElementById(contentId);
2227
+ title = root.getElementById(titleId);
2202
2228
  repositionDebugPanels();
2203
2229
  }
2204
2230
  else {
2205
- content = document.getElementById(contentId);
2206
- title = document.getElementById(titleId);
2231
+ content = root.getElementById(contentId);
2232
+ title = root.getElementById(titleId);
2207
2233
  }
2208
2234
  }
2209
2235
  // Update title with room name only (roomId and sessionId are in tooltip)
2210
- var titleTextEl = document.getElementById('debug-title-text-' + uniquePanelId);
2236
+ var titleTextEl = root.getElementById('debug-title-text-' + uniquePanelId);
2211
2237
  var roomNameEl = titleTextEl === null || titleTextEl === void 0 ? void 0 : titleTextEl.querySelector('.debug-room-name');
2212
2238
  if (roomNameEl)
2213
2239
  roomNameEl.textContent = debugInfo.roomName;
2214
- document.getElementById('debug-tooltip-' + uniquePanelId).innerHTML = '<div><strong>Room ID:</strong> ' + debugInfo.roomId + '</div><div><strong>Session ID:</strong> ' + debugInfo.sessionId + '</div>';
2240
+ root.getElementById('debug-tooltip-' + uniquePanelId).innerHTML = '<div><strong>Room ID:</strong> ' + debugInfo.roomId + '</div><div><strong>Session ID:</strong> ' + debugInfo.sessionId + '</div>';
2215
2241
  // Update ping in header
2216
2242
  var pingDisplay = debugInfo.pingMs !== null ? debugInfo.pingMs + 'ms' : '--';
2217
2243
  var pingColor = debugInfo.pingMs !== null ? (debugInfo.pingMs < 100 ? '#22c55e' : debugInfo.pingMs < 200 ? '#eab308' : '#ef4444') : '#888';
2218
- var pingElement = document.getElementById('debug-ping-' + uniquePanelId);
2244
+ var pingElement = root.getElementById('debug-ping-' + uniquePanelId);
2219
2245
  if (pingElement) {
2220
2246
  pingElement.textContent = pingDisplay;
2221
2247
  pingElement.style.color = pingColor;
@@ -2241,7 +2267,7 @@
2241
2267
  }
2242
2268
  // Draw graph on canvas
2243
2269
  function drawGraph(canvasId, data, color) {
2244
- var canvas = document.getElementById(canvasId);
2270
+ var canvas = getDebugRoot().getElementById(canvasId);
2245
2271
  if (!canvas)
2246
2272
  return;
2247
2273
  var ctx = canvas.getContext('2d');
@@ -2403,7 +2429,7 @@
2403
2429
  room.onMessage('__playground_message_types', (messageTypes) => {
2404
2430
  debugInfo.messageTypes = messageTypes;
2405
2431
  // Show/hide message button based on message types availability
2406
- var messageBtnElement = document.getElementById('debug-message-btn-' + uniquePanelId);
2432
+ var messageBtnElement = getDebugRoot().getElementById('debug-message-btn-' + uniquePanelId);
2407
2433
  if (messageBtnElement) {
2408
2434
  messageBtnElement.style.display = messageTypes ? 'flex' : 'none';
2409
2435
  }
@@ -2537,7 +2563,7 @@
2537
2563
  debugInfo.pingInterval = null;
2538
2564
  }
2539
2565
  roomDebugInfo.delete(uniquePanelId);
2540
- var panel = document.getElementById('debug-panel-' + uniquePanelId);
2566
+ var panel = getDebugRoot().getElementById('debug-panel-' + uniquePanelId);
2541
2567
  if (panel) {
2542
2568
  panel.remove();
2543
2569
  repositionDebugPanels();