@leeguoo/pwtk-network-debugger 1.2.23 → 1.2.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -7976,7 +7976,7 @@ async function createShareLink(requestData) {
7976
7976
  decryptedResponse: requestData.decryptedResponse,
7977
7977
  error: requestData.error,
7978
7978
  creator: "PWTK Network Debugger by Leo (@leeguoo)",
7979
- version: "1.2.23"
7979
+ version: "1.2.24"
7980
7980
  }
7981
7981
  };
7982
7982
  const originalFetch = window.__originalFetch || window.fetch;
@@ -8057,7 +8057,7 @@ function formatAsCurl(requestData) {
8057
8057
  }
8058
8058
  return curl;
8059
8059
  }
8060
- class DebugPanel {
8060
+ const _DebugPanel = class _DebugPanel {
8061
8061
  constructor(interceptor, config = {}) {
8062
8062
  this.isDragging = false;
8063
8063
  this.isResizing = false;
@@ -8066,17 +8066,22 @@ class DebugPanel {
8066
8066
  this.consoleHistory = [];
8067
8067
  this.requestsCache = [];
8068
8068
  this.interceptor = interceptor;
8069
+ const savedConfig = this.loadConfig();
8069
8070
  this.config = {
8070
8071
  position: "bottom-right",
8071
8072
  theme: "dark",
8072
8073
  minimized: false,
8073
8074
  showConsole: true,
8075
+ ...savedConfig,
8076
+ // 先应用保存的配置
8074
8077
  ...config
8078
+ // 再应用传入的配置(优先级最高)
8075
8079
  };
8076
8080
  this.createPanel();
8077
8081
  this.bindEvents();
8078
8082
  this.startListening();
8079
8083
  logger.setPanel(this);
8084
+ this.loadPosition();
8080
8085
  }
8081
8086
  createPanel() {
8082
8087
  if (!document.getElementById("network-debugger-styles")) {
@@ -8507,6 +8512,7 @@ Created by Leo (@leeguoo)`);
8507
8512
  }
8508
8513
  });
8509
8514
  }
8515
+ this.saveConfig();
8510
8516
  }
8511
8517
  toggleFullscreen() {
8512
8518
  this.container.classList.toggle("fullscreen");
@@ -8680,6 +8686,9 @@ Created by Leo (@leeguoo)`);
8680
8686
  handleMouseUp() {
8681
8687
  if (this.isDragging || this.isResizing) {
8682
8688
  this.container.style.transition = "all 0.3s ease";
8689
+ if (this.isDragging) {
8690
+ this.savePosition();
8691
+ }
8683
8692
  }
8684
8693
  this.isDragging = false;
8685
8694
  this.isResizing = false;
@@ -8696,7 +8705,89 @@ Created by Leo (@leeguoo)`);
8696
8705
  const styles2 = document.getElementById("network-debugger-styles");
8697
8706
  if (styles2) styles2.remove();
8698
8707
  }
8699
- }
8708
+ // ========== localStorage 方法 ==========
8709
+ /**
8710
+ * 从 localStorage 加载配置
8711
+ */
8712
+ loadConfig() {
8713
+ try {
8714
+ const saved = localStorage.getItem(_DebugPanel.STORAGE_KEY);
8715
+ if (saved) {
8716
+ const config = JSON.parse(saved);
8717
+ logger.debug("加载保存的配置:", config);
8718
+ return config;
8719
+ }
8720
+ } catch (error) {
8721
+ logger.error("加载配置失败:", error);
8722
+ }
8723
+ return {};
8724
+ }
8725
+ /**
8726
+ * 保存配置到 localStorage
8727
+ */
8728
+ saveConfig() {
8729
+ try {
8730
+ const configToSave = {
8731
+ position: this.config.position,
8732
+ theme: this.config.theme,
8733
+ minimized: this.config.minimized,
8734
+ showConsole: this.config.showConsole
8735
+ };
8736
+ localStorage.setItem(_DebugPanel.STORAGE_KEY, JSON.stringify(configToSave));
8737
+ logger.debug("配置已保存:", configToSave);
8738
+ } catch (error) {
8739
+ logger.error("保存配置失败:", error);
8740
+ }
8741
+ }
8742
+ /**
8743
+ * 加载保存的位置
8744
+ */
8745
+ loadPosition() {
8746
+ try {
8747
+ const positionKey = `${_DebugPanel.STORAGE_KEY}-position`;
8748
+ const saved = localStorage.getItem(positionKey);
8749
+ if (saved) {
8750
+ const position = JSON.parse(saved);
8751
+ if (position.left !== void 0) {
8752
+ this.container.style.left = position.left + "px";
8753
+ }
8754
+ if (position.top !== void 0) {
8755
+ this.container.style.top = position.top + "px";
8756
+ }
8757
+ if (position.right !== void 0) {
8758
+ this.container.style.right = position.right + "px";
8759
+ }
8760
+ if (position.bottom !== void 0) {
8761
+ this.container.style.bottom = position.bottom + "px";
8762
+ }
8763
+ logger.debug("加载保存的位置:", position);
8764
+ }
8765
+ } catch (error) {
8766
+ logger.error("加载位置失败:", error);
8767
+ }
8768
+ }
8769
+ /**
8770
+ * 保存当前位置
8771
+ */
8772
+ savePosition() {
8773
+ try {
8774
+ const positionKey = `${_DebugPanel.STORAGE_KEY}-position`;
8775
+ const rect = this.container.getBoundingClientRect();
8776
+ const position = {
8777
+ left: rect.left,
8778
+ top: rect.top,
8779
+ right: window.innerWidth - rect.right,
8780
+ bottom: window.innerHeight - rect.bottom
8781
+ };
8782
+ localStorage.setItem(positionKey, JSON.stringify(position));
8783
+ logger.debug("位置已保存:", position);
8784
+ } catch (error) {
8785
+ logger.error("保存位置失败:", error);
8786
+ }
8787
+ }
8788
+ };
8789
+ _DebugPanel.STORAGE_KEY = "pwtk-debugger-config";
8790
+ let DebugPanel = _DebugPanel;
8700
8791
  class NetworkDebugger {
8701
8792
  constructor() {
8702
8793
  this.interceptor = null;