@colyseus/sdk 0.17.40 → 0.17.41

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 (47) 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 +1 -1
  40. package/build/transport/H3Transport.mjs +1 -1
  41. package/build/transport/WebSocketTransport.cjs +1 -1
  42. package/build/transport/WebSocketTransport.mjs +1 -1
  43. package/dist/colyseus.js +1 -1
  44. package/dist/debug.js +70 -44
  45. package/dist/debug.js.map +1 -1
  46. package/package.json +3 -3
  47. package/src/debug.ts +69 -43
package/build/debug.mjs 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.41
7
7
  import { Client } from './Client.mjs';
8
8
  import { CloseCode } from '@colyseus/shared-types';
9
9
 
@@ -86,6 +86,19 @@ let modalStack = [];
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 @@ function selectModal(modal) {
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 @@ document.addEventListener('keydown', function (e) {
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 @@ function initialize() {
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 @@ function createMenu(logoContainer) {
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 @@ function createMenu(logoContainer) {
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 @@ function createMenu(logoContainer) {
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 @@ function createMenu(logoContainer) {
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 @@ function createMenu(logoContainer) {
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 @@ function createMenu(logoContainer) {
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 @@ function openSettingsModal() {
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
@@ -868,7 +889,7 @@ function openSendMessagesModal(uniquePanelId) {
868
889
  return;
869
890
  }
870
891
  // Remove existing modal if present
871
- var existingModal = document.getElementById('debug-send-messages-modal');
892
+ var existingModal = getDebugRoot().getElementById('debug-send-messages-modal');
872
893
  if (existingModal) {
873
894
  existingModal.remove();
874
895
  }
@@ -1263,7 +1284,7 @@ function openSendMessagesModal(uniquePanelId) {
1263
1284
  });
1264
1285
  formContainer.appendChild(sendButton);
1265
1286
  modal.appendChild(formContainer);
1266
- document.body.appendChild(modal);
1287
+ getDebugRoot().appendChild(modal);
1267
1288
  }
1268
1289
  // Create and open State Inspector modal
1269
1290
  function openStateInspectorModal(uniquePanelId) {
@@ -1274,7 +1295,7 @@ function openStateInspectorModal(uniquePanelId) {
1274
1295
  }
1275
1296
  var room = debugInfo.room;
1276
1297
  // Remove existing modal if present
1277
- var existingModal = document.getElementById('debug-state-inspector-modal');
1298
+ var existingModal = getDebugRoot().getElementById('debug-state-inspector-modal');
1278
1299
  if (existingModal) {
1279
1300
  existingModal.remove();
1280
1301
  }
@@ -1663,7 +1684,7 @@ function openStateInspectorModal(uniquePanelId) {
1663
1684
  */
1664
1685
  };
1665
1686
  modal.appendChild(contentContainer);
1666
- document.body.appendChild(modal);
1687
+ getDebugRoot().appendChild(modal);
1667
1688
  // Drag and resize state variables
1668
1689
  var isDragging = false;
1669
1690
  var dragStartX = 0;
@@ -1868,9 +1889,10 @@ function openStateInspectorModal(uniquePanelId) {
1868
1889
  }
1869
1890
  // Apply panel position based on current setting
1870
1891
  function applyPanelPosition() {
1871
- var logoContainer = document.getElementById('debug-logo-container');
1872
- var menu = document.getElementById('debug-menu');
1873
- var panels = document.querySelectorAll('[id^="debug-panel-"]');
1892
+ var root = getDebugRoot();
1893
+ var logoContainer = root.getElementById('debug-logo-container');
1894
+ var menu = root.getElementById('debug-menu');
1895
+ var panels = root.querySelectorAll('[id^="debug-panel-"]');
1874
1896
  var positions = {
1875
1897
  'bottom-right': { bottom: '14px', right: '14px', top: 'auto', left: 'auto' },
1876
1898
  'bottom-left': { bottom: '14px', left: '14px', top: 'auto', right: 'auto' },
@@ -1906,9 +1928,10 @@ function applyPanelPosition() {
1906
1928
  function hidePanelsForSession() {
1907
1929
  panelsHidden = true;
1908
1930
  savePreferences(); // Save the hidden state
1909
- var logoContainer = document.getElementById('debug-logo-container');
1910
- var menu = document.getElementById('debug-menu');
1911
- var panels = document.querySelectorAll('[id^="debug-panel-"]');
1931
+ var root = getDebugRoot();
1932
+ var logoContainer = root.getElementById('debug-logo-container');
1933
+ var menu = root.getElementById('debug-menu');
1934
+ var panels = root.querySelectorAll('[id^="debug-panel-"]');
1912
1935
  if (logoContainer) {
1913
1936
  logoContainer.style.display = 'none';
1914
1937
  }
@@ -1935,7 +1958,7 @@ function formatBytes(bytes) {
1935
1958
  // Helper function to create debug panel for a room
1936
1959
  function createDebugPanel(uniquePanelId, debugInfo) {
1937
1960
  // Check if panel already exists
1938
- var existingPanel = document.getElementById('debug-panel-' + uniquePanelId);
1961
+ var existingPanel = getDebugRoot().getElementById('debug-panel-' + uniquePanelId);
1939
1962
  if (existingPanel) {
1940
1963
  return existingPanel;
1941
1964
  }
@@ -2064,11 +2087,12 @@ function createDebugPanel(uniquePanelId, debugInfo) {
2064
2087
  labelSpan.textContent = 'Reconnecting...';
2065
2088
  }
2066
2089
  // Inject CSS animation if not already present
2067
- if (!document.getElementById('debug-pulse-animation')) {
2090
+ var pulseRoot = getDebugRoot();
2091
+ if (!pulseRoot.getElementById('debug-pulse-animation')) {
2068
2092
  var style = document.createElement('style');
2069
2093
  style.id = 'debug-pulse-animation';
2070
2094
  style.textContent = '@keyframes debug-pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }';
2071
- document.head.appendChild(style);
2095
+ pulseRoot.appendChild(style);
2072
2096
  }
2073
2097
  // Apply initial style
2074
2098
  applyNormalStyle();
@@ -2126,12 +2150,13 @@ function createDebugPanel(uniquePanelId, debugInfo) {
2126
2150
  panel.appendChild(title);
2127
2151
  panel.appendChild(content);
2128
2152
  panel.appendChild(actionsContainer);
2129
- // Prepend panel to body so new panels appear first
2130
- if (document.body.firstChild) {
2131
- document.body.insertBefore(panel, document.body.firstChild);
2153
+ // Prepend panel inside the shadow root so new panels appear first
2154
+ var root = getDebugRoot();
2155
+ if (root.firstChild) {
2156
+ root.insertBefore(panel, root.firstChild);
2132
2157
  }
2133
2158
  else {
2134
- document.body.appendChild(panel);
2159
+ root.appendChild(panel);
2135
2160
  }
2136
2161
  return panel;
2137
2162
  }
@@ -2139,7 +2164,7 @@ function createDebugPanel(uniquePanelId, debugInfo) {
2139
2164
  function repositionDebugPanels() {
2140
2165
  if (panelsHidden)
2141
2166
  return;
2142
- var panels = Array.from(document.querySelectorAll('[id^="debug-panel-"]'))
2167
+ var panels = Array.from(getDebugRoot().querySelectorAll('[id^="debug-panel-"]'))
2143
2168
  .filter(function (panel) { return panel.style.display !== 'none'; })
2144
2169
  .reverse(); // Reverse to get oldest first (since new panels are prepended)
2145
2170
  // Calculate logoIcon container width: 22px width + 10px padding on each side = 42px
@@ -2181,35 +2206,36 @@ function repositionDebugPanels() {
2181
2206
  }
2182
2207
  // Update debug panel content
2183
2208
  function updateDebugPanel(uniquePanelId, debugInfo) {
2209
+ var root = getDebugRoot();
2184
2210
  var contentId = 'debug-content-' + uniquePanelId;
2185
2211
  var panelId = 'debug-panel-' + uniquePanelId;
2186
2212
  var titleId = 'debug-title-' + uniquePanelId;
2187
- var content = document.getElementById(contentId);
2188
- var panel = document.getElementById(panelId);
2189
- var title = document.getElementById(titleId);
2213
+ var content = root.getElementById(contentId);
2214
+ var panel = root.getElementById(panelId);
2215
+ var title = root.getElementById(titleId);
2190
2216
  if (!content || !panel) {
2191
2217
  // Only create if panel doesn't exist
2192
2218
  if (!panel) {
2193
2219
  createDebugPanel(uniquePanelId, debugInfo);
2194
- content = document.getElementById(contentId);
2195
- title = document.getElementById(titleId);
2220
+ content = root.getElementById(contentId);
2221
+ title = root.getElementById(titleId);
2196
2222
  repositionDebugPanels();
2197
2223
  }
2198
2224
  else {
2199
- content = document.getElementById(contentId);
2200
- title = document.getElementById(titleId);
2225
+ content = root.getElementById(contentId);
2226
+ title = root.getElementById(titleId);
2201
2227
  }
2202
2228
  }
2203
2229
  // Update title with room name only (roomId and sessionId are in tooltip)
2204
- var titleTextEl = document.getElementById('debug-title-text-' + uniquePanelId);
2230
+ var titleTextEl = root.getElementById('debug-title-text-' + uniquePanelId);
2205
2231
  var roomNameEl = titleTextEl?.querySelector('.debug-room-name');
2206
2232
  if (roomNameEl)
2207
2233
  roomNameEl.textContent = debugInfo.roomName;
2208
- document.getElementById('debug-tooltip-' + uniquePanelId).innerHTML = '<div><strong>Room ID:</strong> ' + debugInfo.roomId + '</div><div><strong>Session ID:</strong> ' + debugInfo.sessionId + '</div>';
2234
+ root.getElementById('debug-tooltip-' + uniquePanelId).innerHTML = '<div><strong>Room ID:</strong> ' + debugInfo.roomId + '</div><div><strong>Session ID:</strong> ' + debugInfo.sessionId + '</div>';
2209
2235
  // Update ping in header
2210
2236
  var pingDisplay = debugInfo.pingMs !== null ? debugInfo.pingMs + 'ms' : '--';
2211
2237
  var pingColor = debugInfo.pingMs !== null ? (debugInfo.pingMs < 100 ? '#22c55e' : debugInfo.pingMs < 200 ? '#eab308' : '#ef4444') : '#888';
2212
- var pingElement = document.getElementById('debug-ping-' + uniquePanelId);
2238
+ var pingElement = root.getElementById('debug-ping-' + uniquePanelId);
2213
2239
  if (pingElement) {
2214
2240
  pingElement.textContent = pingDisplay;
2215
2241
  pingElement.style.color = pingColor;
@@ -2235,7 +2261,7 @@ function updateDebugPanel(uniquePanelId, debugInfo) {
2235
2261
  }
2236
2262
  // Draw graph on canvas
2237
2263
  function drawGraph(canvasId, data, color) {
2238
- var canvas = document.getElementById(canvasId);
2264
+ var canvas = getDebugRoot().getElementById(canvasId);
2239
2265
  if (!canvas)
2240
2266
  return;
2241
2267
  var ctx = canvas.getContext('2d');
@@ -2396,7 +2422,7 @@ function applyMonkeyPatches() {
2396
2422
  room.onMessage('__playground_message_types', (messageTypes) => {
2397
2423
  debugInfo.messageTypes = messageTypes;
2398
2424
  // Show/hide message button based on message types availability
2399
- var messageBtnElement = document.getElementById('debug-message-btn-' + uniquePanelId);
2425
+ var messageBtnElement = getDebugRoot().getElementById('debug-message-btn-' + uniquePanelId);
2400
2426
  if (messageBtnElement) {
2401
2427
  messageBtnElement.style.display = messageTypes ? 'flex' : 'none';
2402
2428
  }
@@ -2530,7 +2556,7 @@ function applyMonkeyPatches() {
2530
2556
  debugInfo.pingInterval = null;
2531
2557
  }
2532
2558
  roomDebugInfo.delete(uniquePanelId);
2533
- var panel = document.getElementById('debug-panel-' + uniquePanelId);
2559
+ var panel = getDebugRoot().getElementById('debug-panel-' + uniquePanelId);
2534
2560
  if (panel) {
2535
2561
  panel.remove();
2536
2562
  repositionDebugPanels();