slicejs-web-framework 4.0.0 → 4.0.1
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/.opencode/opencode.json +14 -14
- package/LICENSE +21 -21
- package/README.md +97 -97
- package/Slice/Components/Structural/ContextManager/ContextManager.js +422 -422
- package/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +470 -470
- package/Slice/Components/Structural/Controller/Controller.js +1406 -1406
- package/Slice/Components/Structural/Controller/allowedValuesValidation.js +52 -52
- package/Slice/Components/Structural/Debugger/Debugger.html +72 -72
- package/Slice/Components/Structural/Debugger/Debugger.js +1505 -1505
- package/Slice/Components/Structural/EventManager/EventManager.js +651 -651
- package/Slice/Components/Structural/EventManager/EventManagerDebugger.js +985 -985
- package/Slice/Components/Structural/LeakInspector/LeakInspector.js +296 -296
- package/Slice/Components/Structural/Logger/Log.js +10 -10
- package/Slice/Components/Structural/Logger/LogViewer/LogViewer.js +662 -662
- package/Slice/Components/Structural/Logger/Logger.js +225 -225
- package/Slice/Components/Structural/Router/Router.js +793 -793
- package/Slice/Components/Structural/StylesManager/StylesManager.js +82 -82
- package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +162 -162
- package/Slice/Slice.js +686 -697
- package/Slice/tests/build-bundled-component-without-category.test.js +103 -103
- package/Slice/tests/build-js-only-visual-components.test.js +144 -144
- package/Slice/tests/build-singleton.test.js +244 -244
- package/Slice/tests/bundle-v2-runtime-contract.test.js +738 -738
- package/Slice/tests/context-patch-use.test.js +95 -95
- package/Slice/tests/destroy-cascade.test.js +215 -215
- package/Slice/tests/event-emitters.test.js +79 -79
- package/Slice/tests/event-registry.test.js +141 -141
- package/Slice/tests/fixtures/real-runtime-loader.mjs +21 -21
- package/Slice/tests/leak-orphans.test.js +131 -131
- package/Slice/tests/props-allowed-values-validation.test.js +119 -119
- package/Slice/tests/public-env-runtime-accessors.test.js +44 -44
- package/Slice/tests/public-env-typed-accessors.test.js +66 -66
- package/Slice/tests/router-loading-finally.test.js +68 -68
- package/api/framework/devDepsOptimizer.js +335 -335
- package/api/framework/express.js +3 -3
- package/api/framework/precompressedStatic.js +93 -93
- package/api/framework/publicEnvResolver.js +123 -123
- package/api/framework/securityMiddleware.js +197 -197
- package/api/framework/server.js +411 -411
- package/api/index.js +7 -7
- package/api/tests/dev-deps-optimizer.test.js +137 -137
- package/api/tests/dev-server-external.test.js +56 -56
- package/api/tests/precompressed-static.test.js +119 -119
- package/api/tests/public-env-resolver.test.js +193 -193
- package/package.json +49 -49
- package/sliceConfig.schema.json +122 -122
- package/src/App/index.html +69 -69
- package/src/App/index.js +20 -20
- package/src/App/style.css +11 -11
- package/src/Components/AppComponents/AboutSection/AboutSection.css +9 -9
- package/src/Components/AppComponents/AboutSection/AboutSection.html +8 -8
- package/src/Components/AppComponents/AboutSection/AboutSection.js +12 -12
- package/src/Components/AppComponents/AppShell/AppShell.css +10 -10
- package/src/Components/AppComponents/AppShell/AppShell.html +4 -4
- package/src/Components/AppComponents/AppShell/AppShell.js +36 -36
- package/src/Components/AppComponents/HomeSection/HomeSection.css +20 -20
- package/src/Components/AppComponents/HomeSection/HomeSection.html +10 -10
- package/src/Components/AppComponents/HomeSection/HomeSection.js +19 -19
- package/src/Components/components.js +8 -8
- package/src/public/Styles/sliceStyles.css +34 -34
- package/src/public/Themes/Dark.css +42 -42
- package/src/public/Themes/Light.css +31 -31
- package/src/public/Themes/Slice.css +47 -47
- package/src/public/manifest.json +15 -15
- package/src/public/robots.txt +4 -4
- package/src/public/sitemap.xml +8 -8
- package/src/routes.js +9 -9
- package/src/sliceConfig.json +72 -72
- package/tests/router-emit-ordering.test.js +63 -63
- package/types/index.d.ts +219 -219
|
@@ -1,296 +1,296 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LeakInspector — dev-only memory-leak panel.
|
|
3
|
-
*
|
|
4
|
-
* Surfaces components that stay registered in `slice.controller.activeComponents`
|
|
5
|
-
* while detached from the live DOM (built then cleared via innerHTML=''/remove()
|
|
6
|
-
* without destroyComponent). Intentionally-cached components (Route/MultiRoute/
|
|
7
|
-
* Router-managed) are excluded by the Controller's findOrphans() criteria.
|
|
8
|
-
*
|
|
9
|
-
* Mirrors EventManagerDebugger: draggable fixed panel, conditional auto-refresh
|
|
10
|
-
* that only runs while open. Read-only except for the per-orphan Destroy action.
|
|
11
|
-
*/
|
|
12
|
-
export default class LeakInspector extends HTMLElement {
|
|
13
|
-
constructor() {
|
|
14
|
-
super();
|
|
15
|
-
this.isOpen = false;
|
|
16
|
-
this._autoRefreshTimer = null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async init() {
|
|
20
|
-
this.innerHTML = this.renderTemplate();
|
|
21
|
-
slice.stylesManager.registerComponentStyles('LeakInspector', this.renderStyles());
|
|
22
|
-
this.cacheElements();
|
|
23
|
-
this.bindEvents();
|
|
24
|
-
this.makeDraggable();
|
|
25
|
-
this.render();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
toggle() {
|
|
29
|
-
this.isOpen ? this.close() : this.open();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
open() {
|
|
33
|
-
this.isOpen = true;
|
|
34
|
-
this.container.classList.add('active');
|
|
35
|
-
this._startAutoRefresh();
|
|
36
|
-
this.render();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
close() {
|
|
40
|
-
this.isOpen = false;
|
|
41
|
-
this.container.classList.remove('active');
|
|
42
|
-
this._stopAutoRefresh();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
_startAutoRefresh() {
|
|
46
|
-
this._stopAutoRefresh();
|
|
47
|
-
this._autoRefreshTimer = setInterval(() => {
|
|
48
|
-
if (!this.isOpen) return;
|
|
49
|
-
this.render();
|
|
50
|
-
}, 1500);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
_stopAutoRefresh() {
|
|
54
|
-
if (this._autoRefreshTimer) {
|
|
55
|
-
clearInterval(this._autoRefreshTimer);
|
|
56
|
-
this._autoRefreshTimer = null;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
cacheElements() {
|
|
61
|
-
this.container = this.querySelector('#leak-inspector');
|
|
62
|
-
this.header = this.querySelector('.leak-header');
|
|
63
|
-
this.list = this.querySelector('#leak-list');
|
|
64
|
-
this.countLabel = this.querySelector('#leak-count');
|
|
65
|
-
this.sizeLabel = this.querySelector('#leak-size');
|
|
66
|
-
this.growthLabel = this.querySelector('#leak-growth');
|
|
67
|
-
this.refreshButton = this.querySelector('#leak-refresh');
|
|
68
|
-
this.closeButton = this.querySelector('#leak-close');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
bindEvents() {
|
|
72
|
-
this.refreshButton.addEventListener('click', () => this.render());
|
|
73
|
-
this.closeButton.addEventListener('click', () => this.close());
|
|
74
|
-
// Per-orphan Destroy (event delegation).
|
|
75
|
-
this.list.addEventListener('click', (event) => {
|
|
76
|
-
const button = event.target.closest('[data-destroy]');
|
|
77
|
-
if (!button) return;
|
|
78
|
-
const sliceId = button.getAttribute('data-destroy');
|
|
79
|
-
const component = slice.controller.activeComponents.get(sliceId);
|
|
80
|
-
if (component) {
|
|
81
|
-
slice.controller.destroyComponent(component);
|
|
82
|
-
this.render();
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
render() {
|
|
88
|
-
const controller = slice?.controller;
|
|
89
|
-
if (!controller || !(controller.activeComponents instanceof Map)) {
|
|
90
|
-
this.list.textContent = 'Controller not available.';
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
controller.sampleComponentGrowth();
|
|
95
|
-
const orphans = controller.findOrphans();
|
|
96
|
-
|
|
97
|
-
this.sizeLabel.textContent = String(controller.activeComponents.size);
|
|
98
|
-
this.countLabel.textContent = String(orphans.length);
|
|
99
|
-
|
|
100
|
-
const growing = controller.isGrowthMonotonic();
|
|
101
|
-
this.growthLabel.textContent = growing ? 'growing ▲' : 'stable';
|
|
102
|
-
this.growthLabel.classList.toggle('warn', growing);
|
|
103
|
-
|
|
104
|
-
if (orphans.length === 0) {
|
|
105
|
-
this.list.innerHTML = '<div class="empty">No leaks detected ✓</div>';
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
this.list.innerHTML = orphans.map((orphan) => {
|
|
110
|
-
const path = orphan.retainPath.map((p) => this.escapeHtml(p)).join(' ◂ ');
|
|
111
|
-
return `
|
|
112
|
-
<details class="leak-row">
|
|
113
|
-
<summary>
|
|
114
|
-
<div class="leak-name">${this.escapeHtml(orphan.name)}</div>
|
|
115
|
-
<div class="leak-actions-row">
|
|
116
|
-
<span class="leak-id">${this.escapeHtml(orphan.sliceId)}</span>
|
|
117
|
-
<button class="leak-destroy" data-destroy="${this.escapeHtml(orphan.sliceId)}" title="Destroy now">destroy</button>
|
|
118
|
-
</div>
|
|
119
|
-
</summary>
|
|
120
|
-
<div class="leak-detail">
|
|
121
|
-
<div class="leak-reason">${this.escapeHtml(orphan.reason)}</div>
|
|
122
|
-
<div class="leak-path"><span class="path-key">retains</span> ${path}</div>
|
|
123
|
-
</div>
|
|
124
|
-
</details>
|
|
125
|
-
`;
|
|
126
|
-
}).join('');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
makeDraggable() {
|
|
130
|
-
if (!this.header || !this.container) return;
|
|
131
|
-
let offset = { x: 0, y: 0 };
|
|
132
|
-
let isDragging = false;
|
|
133
|
-
this.header.style.cursor = 'grab';
|
|
134
|
-
|
|
135
|
-
this.header.addEventListener('mousedown', (event) => {
|
|
136
|
-
if (event.target.closest('.btn')) return;
|
|
137
|
-
isDragging = true;
|
|
138
|
-
offset.x = event.clientX - this.container.getBoundingClientRect().left;
|
|
139
|
-
offset.y = event.clientY - this.container.getBoundingClientRect().top;
|
|
140
|
-
this.header.style.cursor = 'grabbing';
|
|
141
|
-
});
|
|
142
|
-
document.addEventListener('mousemove', (event) => {
|
|
143
|
-
if (!isDragging) return;
|
|
144
|
-
const rect = this.container.getBoundingClientRect();
|
|
145
|
-
const x = Math.min(Math.max(event.clientX - offset.x, 0), window.innerWidth - rect.width);
|
|
146
|
-
const y = Math.min(Math.max(event.clientY - offset.y, 0), window.innerHeight - rect.height);
|
|
147
|
-
this.container.style.left = `${x}px`;
|
|
148
|
-
this.container.style.top = `${y}px`;
|
|
149
|
-
this.container.style.right = 'auto';
|
|
150
|
-
this.container.style.bottom = 'auto';
|
|
151
|
-
});
|
|
152
|
-
document.addEventListener('mouseup', () => {
|
|
153
|
-
if (!isDragging) return;
|
|
154
|
-
isDragging = false;
|
|
155
|
-
this.header.style.cursor = 'grab';
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
escapeHtml(value) {
|
|
160
|
-
return String(value)
|
|
161
|
-
.replace(/&/g, '&')
|
|
162
|
-
.replace(/</g, '<')
|
|
163
|
-
.replace(/>/g, '>')
|
|
164
|
-
.replace(/"/g, '"');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
renderTemplate() {
|
|
168
|
-
return `
|
|
169
|
-
<div id="leak-inspector">
|
|
170
|
-
<div class="leak-header">
|
|
171
|
-
<div class="brand">
|
|
172
|
-
<span class="status-dot"></span>
|
|
173
|
-
<span class="glyph">⚠</span>
|
|
174
|
-
<span class="title">LEAK INSPECTOR</span>
|
|
175
|
-
</div>
|
|
176
|
-
<div class="actions">
|
|
177
|
-
<button id="leak-refresh" class="btn" title="Refresh" aria-label="Refresh">⟳</button>
|
|
178
|
-
<button id="leak-close" class="btn" title="Close" aria-label="Close">✕</button>
|
|
179
|
-
</div>
|
|
180
|
-
</div>
|
|
181
|
-
<div class="leak-stats">
|
|
182
|
-
<div class="stat"><span class="stat-label">orphans</span><span id="leak-count" class="stat-value danger">0</span></div>
|
|
183
|
-
<div class="stat"><span class="stat-label">active</span><span id="leak-size" class="stat-value">0</span></div>
|
|
184
|
-
<div class="stat"><span class="stat-label">trend</span><span id="leak-growth" class="stat-value">stable</span></div>
|
|
185
|
-
</div>
|
|
186
|
-
<div class="leak-list" id="leak-list"></div>
|
|
187
|
-
</div>
|
|
188
|
-
`;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
renderStyles() {
|
|
192
|
-
return `
|
|
193
|
-
slice-leak-inspector {
|
|
194
|
-
--li-accent: var(--danger-color, #ff6b6b);
|
|
195
|
-
--li-accent-rgb: 255, 107, 107;
|
|
196
|
-
--li-surface: var(--primary-background-color, rgba(17, 19, 28, 0.86));
|
|
197
|
-
--li-raised: var(--secondary-background-color, rgba(255, 255, 255, 0.035));
|
|
198
|
-
--li-raised-2: var(--tertiary-background-color, rgba(255, 255, 255, 0.06));
|
|
199
|
-
--li-border: var(--medium-color, rgba(255, 255, 255, 0.09));
|
|
200
|
-
--li-text: var(--font-primary-color, #e8eaf2);
|
|
201
|
-
--li-dim: var(--font-secondary-color, #888fa6);
|
|
202
|
-
--li-warn: var(--warning-color, #f5b14c);
|
|
203
|
-
--li-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Cascadia Code', Menlo, Consolas, monospace;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
slice-leak-inspector #leak-inspector {
|
|
207
|
-
position: fixed;
|
|
208
|
-
bottom: 20px;
|
|
209
|
-
left: 20px;
|
|
210
|
-
width: min(380px, calc(100vw - 40px));
|
|
211
|
-
max-height: 64vh;
|
|
212
|
-
background: var(--li-surface);
|
|
213
|
-
border: 1px solid var(--li-border);
|
|
214
|
-
border-radius: 14px;
|
|
215
|
-
box-shadow: 0 24px 60px -12px rgba(0,0,0,0.55), 0 0 38px -18px rgba(var(--li-accent-rgb), 0.5);
|
|
216
|
-
-webkit-backdrop-filter: blur(22px) saturate(1.3);
|
|
217
|
-
backdrop-filter: blur(22px) saturate(1.3);
|
|
218
|
-
display: none;
|
|
219
|
-
flex-direction: column;
|
|
220
|
-
z-index: 10001;
|
|
221
|
-
overflow: hidden;
|
|
222
|
-
color: var(--li-text);
|
|
223
|
-
font-family: var(--li-mono);
|
|
224
|
-
}
|
|
225
|
-
slice-leak-inspector #leak-inspector.active {
|
|
226
|
-
display: flex;
|
|
227
|
-
animation: li-in 0.26s cubic-bezier(0.16, 1, 0.3, 1);
|
|
228
|
-
}
|
|
229
|
-
@keyframes li-in { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
|
|
230
|
-
slice-leak-inspector #leak-inspector * { box-sizing: border-box; }
|
|
231
|
-
slice-leak-inspector #leak-inspector::before {
|
|
232
|
-
content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
|
|
233
|
-
background: linear-gradient(180deg, var(--li-accent), transparent 70%); opacity: 0.85; pointer-events: none;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
slice-leak-inspector .leak-header {
|
|
237
|
-
display: flex; justify-content: space-between; align-items: center;
|
|
238
|
-
padding: 12px 14px;
|
|
239
|
-
background: radial-gradient(120% 140% at 0% 0%, rgba(var(--li-accent-rgb), 0.1), transparent 60%), var(--li-raised);
|
|
240
|
-
border-bottom: 1px solid var(--li-border); user-select: none;
|
|
241
|
-
}
|
|
242
|
-
slice-leak-inspector .brand { display: flex; align-items: center; gap: 9px; }
|
|
243
|
-
slice-leak-inspector .status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--li-accent); animation: li-pulse 2.4s ease-out infinite; }
|
|
244
|
-
@keyframes li-pulse { 0% { box-shadow: 0 0 0 0 rgba(var(--li-accent-rgb), 0.55); } 70% { box-shadow: 0 0 0 7px rgba(var(--li-accent-rgb), 0); } 100% { box-shadow: 0 0 0 0 rgba(var(--li-accent-rgb), 0); } }
|
|
245
|
-
slice-leak-inspector .glyph { color: var(--li-accent); font-size: 12px; }
|
|
246
|
-
slice-leak-inspector .title { font-weight: 600; font-size: 11px; letter-spacing: 0.16em; color: var(--li-text); }
|
|
247
|
-
slice-leak-inspector .actions { display: flex; gap: 6px; }
|
|
248
|
-
slice-leak-inspector .btn {
|
|
249
|
-
width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
|
|
250
|
-
border-radius: 7px; border: 1px solid var(--li-border); background: var(--li-raised);
|
|
251
|
-
color: var(--li-dim); cursor: pointer; font-size: 13px; line-height: 1;
|
|
252
|
-
transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
|
|
253
|
-
}
|
|
254
|
-
slice-leak-inspector .btn:hover { color: var(--li-text); background: var(--li-raised-2); border-color: rgba(var(--li-accent-rgb), 0.5); }
|
|
255
|
-
slice-leak-inspector .btn:active { transform: scale(0.92); }
|
|
256
|
-
|
|
257
|
-
slice-leak-inspector .leak-stats {
|
|
258
|
-
display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--li-border); background: var(--li-raised);
|
|
259
|
-
}
|
|
260
|
-
slice-leak-inspector .stat { flex: 1; display: flex; flex-direction: column; gap: 3px; align-items: center; padding: 6px 4px; border-radius: 8px; background: rgba(0,0,0,0.18); border: 1px solid var(--li-border); }
|
|
261
|
-
slice-leak-inspector .stat-label { font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--li-dim); }
|
|
262
|
-
slice-leak-inspector .stat-value { font-size: 16px; font-weight: 700; color: var(--li-text); }
|
|
263
|
-
slice-leak-inspector .stat-value.danger { color: var(--li-accent); }
|
|
264
|
-
slice-leak-inspector .stat-value.warn { color: var(--li-warn); }
|
|
265
|
-
|
|
266
|
-
slice-leak-inspector .leak-list { padding: 10px 12px 12px; overflow: auto; display: flex; flex-direction: column; gap: 7px; }
|
|
267
|
-
slice-leak-inspector .leak-list::-webkit-scrollbar { width: 8px; }
|
|
268
|
-
slice-leak-inspector .leak-list::-webkit-scrollbar-thumb { background: var(--li-raised-2); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
|
|
269
|
-
|
|
270
|
-
slice-leak-inspector .leak-row { display: block; padding: 9px 11px; background: var(--li-raised); border-radius: 9px; border: 1px solid var(--li-border); border-left: 2px solid var(--li-accent); }
|
|
271
|
-
slice-leak-inspector .leak-row summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; list-style: none; }
|
|
272
|
-
slice-leak-inspector .leak-row summary::-webkit-details-marker { display: none; }
|
|
273
|
-
slice-leak-inspector .leak-name { font-family: var(--li-mono); font-size: 12px; font-weight: 600; color: var(--li-text); }
|
|
274
|
-
slice-leak-inspector .leak-actions-row { display: flex; align-items: center; gap: 8px; }
|
|
275
|
-
slice-leak-inspector .leak-id { font-size: 10px; color: var(--li-dim); }
|
|
276
|
-
slice-leak-inspector .leak-destroy {
|
|
277
|
-
all: unset; cursor: pointer; font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase;
|
|
278
|
-
padding: 2px 8px; border-radius: 999px; color: var(--li-accent);
|
|
279
|
-
background: rgba(var(--li-accent-rgb), 0.12); border: 1px solid rgba(var(--li-accent-rgb), 0.3);
|
|
280
|
-
}
|
|
281
|
-
slice-leak-inspector .leak-destroy:hover { background: rgba(var(--li-accent-rgb), 0.22); }
|
|
282
|
-
slice-leak-inspector .leak-detail { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--li-border); display: flex; flex-direction: column; gap: 6px; }
|
|
283
|
-
slice-leak-inspector .leak-reason { font-size: 11px; color: var(--li-dim); }
|
|
284
|
-
slice-leak-inspector .leak-path { font-family: var(--li-mono); font-size: 10.5px; color: var(--li-text); word-break: break-word; }
|
|
285
|
-
slice-leak-inspector .path-key { color: var(--li-dim); margin-right: 6px; }
|
|
286
|
-
slice-leak-inspector .empty { color: var(--li-dim); font-size: 11px; letter-spacing: 0.04em; text-align: center; padding: 22px 0; }
|
|
287
|
-
|
|
288
|
-
@media (prefers-reduced-motion: reduce) {
|
|
289
|
-
slice-leak-inspector #leak-inspector.active { animation: none; }
|
|
290
|
-
slice-leak-inspector .status-dot { animation: none; }
|
|
291
|
-
}
|
|
292
|
-
`;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
customElements.define('slice-leak-inspector', LeakInspector);
|
|
1
|
+
/**
|
|
2
|
+
* LeakInspector — dev-only memory-leak panel.
|
|
3
|
+
*
|
|
4
|
+
* Surfaces components that stay registered in `slice.controller.activeComponents`
|
|
5
|
+
* while detached from the live DOM (built then cleared via innerHTML=''/remove()
|
|
6
|
+
* without destroyComponent). Intentionally-cached components (Route/MultiRoute/
|
|
7
|
+
* Router-managed) are excluded by the Controller's findOrphans() criteria.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors EventManagerDebugger: draggable fixed panel, conditional auto-refresh
|
|
10
|
+
* that only runs while open. Read-only except for the per-orphan Destroy action.
|
|
11
|
+
*/
|
|
12
|
+
export default class LeakInspector extends HTMLElement {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this.isOpen = false;
|
|
16
|
+
this._autoRefreshTimer = null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async init() {
|
|
20
|
+
this.innerHTML = this.renderTemplate();
|
|
21
|
+
slice.stylesManager.registerComponentStyles('LeakInspector', this.renderStyles());
|
|
22
|
+
this.cacheElements();
|
|
23
|
+
this.bindEvents();
|
|
24
|
+
this.makeDraggable();
|
|
25
|
+
this.render();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
toggle() {
|
|
29
|
+
this.isOpen ? this.close() : this.open();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
open() {
|
|
33
|
+
this.isOpen = true;
|
|
34
|
+
this.container.classList.add('active');
|
|
35
|
+
this._startAutoRefresh();
|
|
36
|
+
this.render();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
close() {
|
|
40
|
+
this.isOpen = false;
|
|
41
|
+
this.container.classList.remove('active');
|
|
42
|
+
this._stopAutoRefresh();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_startAutoRefresh() {
|
|
46
|
+
this._stopAutoRefresh();
|
|
47
|
+
this._autoRefreshTimer = setInterval(() => {
|
|
48
|
+
if (!this.isOpen) return;
|
|
49
|
+
this.render();
|
|
50
|
+
}, 1500);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_stopAutoRefresh() {
|
|
54
|
+
if (this._autoRefreshTimer) {
|
|
55
|
+
clearInterval(this._autoRefreshTimer);
|
|
56
|
+
this._autoRefreshTimer = null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
cacheElements() {
|
|
61
|
+
this.container = this.querySelector('#leak-inspector');
|
|
62
|
+
this.header = this.querySelector('.leak-header');
|
|
63
|
+
this.list = this.querySelector('#leak-list');
|
|
64
|
+
this.countLabel = this.querySelector('#leak-count');
|
|
65
|
+
this.sizeLabel = this.querySelector('#leak-size');
|
|
66
|
+
this.growthLabel = this.querySelector('#leak-growth');
|
|
67
|
+
this.refreshButton = this.querySelector('#leak-refresh');
|
|
68
|
+
this.closeButton = this.querySelector('#leak-close');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
bindEvents() {
|
|
72
|
+
this.refreshButton.addEventListener('click', () => this.render());
|
|
73
|
+
this.closeButton.addEventListener('click', () => this.close());
|
|
74
|
+
// Per-orphan Destroy (event delegation).
|
|
75
|
+
this.list.addEventListener('click', (event) => {
|
|
76
|
+
const button = event.target.closest('[data-destroy]');
|
|
77
|
+
if (!button) return;
|
|
78
|
+
const sliceId = button.getAttribute('data-destroy');
|
|
79
|
+
const component = slice.controller.activeComponents.get(sliceId);
|
|
80
|
+
if (component) {
|
|
81
|
+
slice.controller.destroyComponent(component);
|
|
82
|
+
this.render();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
render() {
|
|
88
|
+
const controller = slice?.controller;
|
|
89
|
+
if (!controller || !(controller.activeComponents instanceof Map)) {
|
|
90
|
+
this.list.textContent = 'Controller not available.';
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
controller.sampleComponentGrowth();
|
|
95
|
+
const orphans = controller.findOrphans();
|
|
96
|
+
|
|
97
|
+
this.sizeLabel.textContent = String(controller.activeComponents.size);
|
|
98
|
+
this.countLabel.textContent = String(orphans.length);
|
|
99
|
+
|
|
100
|
+
const growing = controller.isGrowthMonotonic();
|
|
101
|
+
this.growthLabel.textContent = growing ? 'growing ▲' : 'stable';
|
|
102
|
+
this.growthLabel.classList.toggle('warn', growing);
|
|
103
|
+
|
|
104
|
+
if (orphans.length === 0) {
|
|
105
|
+
this.list.innerHTML = '<div class="empty">No leaks detected ✓</div>';
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this.list.innerHTML = orphans.map((orphan) => {
|
|
110
|
+
const path = orphan.retainPath.map((p) => this.escapeHtml(p)).join(' ◂ ');
|
|
111
|
+
return `
|
|
112
|
+
<details class="leak-row">
|
|
113
|
+
<summary>
|
|
114
|
+
<div class="leak-name">${this.escapeHtml(orphan.name)}</div>
|
|
115
|
+
<div class="leak-actions-row">
|
|
116
|
+
<span class="leak-id">${this.escapeHtml(orphan.sliceId)}</span>
|
|
117
|
+
<button class="leak-destroy" data-destroy="${this.escapeHtml(orphan.sliceId)}" title="Destroy now">destroy</button>
|
|
118
|
+
</div>
|
|
119
|
+
</summary>
|
|
120
|
+
<div class="leak-detail">
|
|
121
|
+
<div class="leak-reason">${this.escapeHtml(orphan.reason)}</div>
|
|
122
|
+
<div class="leak-path"><span class="path-key">retains</span> ${path}</div>
|
|
123
|
+
</div>
|
|
124
|
+
</details>
|
|
125
|
+
`;
|
|
126
|
+
}).join('');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
makeDraggable() {
|
|
130
|
+
if (!this.header || !this.container) return;
|
|
131
|
+
let offset = { x: 0, y: 0 };
|
|
132
|
+
let isDragging = false;
|
|
133
|
+
this.header.style.cursor = 'grab';
|
|
134
|
+
|
|
135
|
+
this.header.addEventListener('mousedown', (event) => {
|
|
136
|
+
if (event.target.closest('.btn')) return;
|
|
137
|
+
isDragging = true;
|
|
138
|
+
offset.x = event.clientX - this.container.getBoundingClientRect().left;
|
|
139
|
+
offset.y = event.clientY - this.container.getBoundingClientRect().top;
|
|
140
|
+
this.header.style.cursor = 'grabbing';
|
|
141
|
+
});
|
|
142
|
+
document.addEventListener('mousemove', (event) => {
|
|
143
|
+
if (!isDragging) return;
|
|
144
|
+
const rect = this.container.getBoundingClientRect();
|
|
145
|
+
const x = Math.min(Math.max(event.clientX - offset.x, 0), window.innerWidth - rect.width);
|
|
146
|
+
const y = Math.min(Math.max(event.clientY - offset.y, 0), window.innerHeight - rect.height);
|
|
147
|
+
this.container.style.left = `${x}px`;
|
|
148
|
+
this.container.style.top = `${y}px`;
|
|
149
|
+
this.container.style.right = 'auto';
|
|
150
|
+
this.container.style.bottom = 'auto';
|
|
151
|
+
});
|
|
152
|
+
document.addEventListener('mouseup', () => {
|
|
153
|
+
if (!isDragging) return;
|
|
154
|
+
isDragging = false;
|
|
155
|
+
this.header.style.cursor = 'grab';
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
escapeHtml(value) {
|
|
160
|
+
return String(value)
|
|
161
|
+
.replace(/&/g, '&')
|
|
162
|
+
.replace(/</g, '<')
|
|
163
|
+
.replace(/>/g, '>')
|
|
164
|
+
.replace(/"/g, '"');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
renderTemplate() {
|
|
168
|
+
return `
|
|
169
|
+
<div id="leak-inspector">
|
|
170
|
+
<div class="leak-header">
|
|
171
|
+
<div class="brand">
|
|
172
|
+
<span class="status-dot"></span>
|
|
173
|
+
<span class="glyph">⚠</span>
|
|
174
|
+
<span class="title">LEAK INSPECTOR</span>
|
|
175
|
+
</div>
|
|
176
|
+
<div class="actions">
|
|
177
|
+
<button id="leak-refresh" class="btn" title="Refresh" aria-label="Refresh">⟳</button>
|
|
178
|
+
<button id="leak-close" class="btn" title="Close" aria-label="Close">✕</button>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
<div class="leak-stats">
|
|
182
|
+
<div class="stat"><span class="stat-label">orphans</span><span id="leak-count" class="stat-value danger">0</span></div>
|
|
183
|
+
<div class="stat"><span class="stat-label">active</span><span id="leak-size" class="stat-value">0</span></div>
|
|
184
|
+
<div class="stat"><span class="stat-label">trend</span><span id="leak-growth" class="stat-value">stable</span></div>
|
|
185
|
+
</div>
|
|
186
|
+
<div class="leak-list" id="leak-list"></div>
|
|
187
|
+
</div>
|
|
188
|
+
`;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
renderStyles() {
|
|
192
|
+
return `
|
|
193
|
+
slice-leak-inspector {
|
|
194
|
+
--li-accent: var(--danger-color, #ff6b6b);
|
|
195
|
+
--li-accent-rgb: 255, 107, 107;
|
|
196
|
+
--li-surface: var(--primary-background-color, rgba(17, 19, 28, 0.86));
|
|
197
|
+
--li-raised: var(--secondary-background-color, rgba(255, 255, 255, 0.035));
|
|
198
|
+
--li-raised-2: var(--tertiary-background-color, rgba(255, 255, 255, 0.06));
|
|
199
|
+
--li-border: var(--medium-color, rgba(255, 255, 255, 0.09));
|
|
200
|
+
--li-text: var(--font-primary-color, #e8eaf2);
|
|
201
|
+
--li-dim: var(--font-secondary-color, #888fa6);
|
|
202
|
+
--li-warn: var(--warning-color, #f5b14c);
|
|
203
|
+
--li-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Cascadia Code', Menlo, Consolas, monospace;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
slice-leak-inspector #leak-inspector {
|
|
207
|
+
position: fixed;
|
|
208
|
+
bottom: 20px;
|
|
209
|
+
left: 20px;
|
|
210
|
+
width: min(380px, calc(100vw - 40px));
|
|
211
|
+
max-height: 64vh;
|
|
212
|
+
background: var(--li-surface);
|
|
213
|
+
border: 1px solid var(--li-border);
|
|
214
|
+
border-radius: 14px;
|
|
215
|
+
box-shadow: 0 24px 60px -12px rgba(0,0,0,0.55), 0 0 38px -18px rgba(var(--li-accent-rgb), 0.5);
|
|
216
|
+
-webkit-backdrop-filter: blur(22px) saturate(1.3);
|
|
217
|
+
backdrop-filter: blur(22px) saturate(1.3);
|
|
218
|
+
display: none;
|
|
219
|
+
flex-direction: column;
|
|
220
|
+
z-index: 10001;
|
|
221
|
+
overflow: hidden;
|
|
222
|
+
color: var(--li-text);
|
|
223
|
+
font-family: var(--li-mono);
|
|
224
|
+
}
|
|
225
|
+
slice-leak-inspector #leak-inspector.active {
|
|
226
|
+
display: flex;
|
|
227
|
+
animation: li-in 0.26s cubic-bezier(0.16, 1, 0.3, 1);
|
|
228
|
+
}
|
|
229
|
+
@keyframes li-in { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
|
|
230
|
+
slice-leak-inspector #leak-inspector * { box-sizing: border-box; }
|
|
231
|
+
slice-leak-inspector #leak-inspector::before {
|
|
232
|
+
content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
|
|
233
|
+
background: linear-gradient(180deg, var(--li-accent), transparent 70%); opacity: 0.85; pointer-events: none;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
slice-leak-inspector .leak-header {
|
|
237
|
+
display: flex; justify-content: space-between; align-items: center;
|
|
238
|
+
padding: 12px 14px;
|
|
239
|
+
background: radial-gradient(120% 140% at 0% 0%, rgba(var(--li-accent-rgb), 0.1), transparent 60%), var(--li-raised);
|
|
240
|
+
border-bottom: 1px solid var(--li-border); user-select: none;
|
|
241
|
+
}
|
|
242
|
+
slice-leak-inspector .brand { display: flex; align-items: center; gap: 9px; }
|
|
243
|
+
slice-leak-inspector .status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--li-accent); animation: li-pulse 2.4s ease-out infinite; }
|
|
244
|
+
@keyframes li-pulse { 0% { box-shadow: 0 0 0 0 rgba(var(--li-accent-rgb), 0.55); } 70% { box-shadow: 0 0 0 7px rgba(var(--li-accent-rgb), 0); } 100% { box-shadow: 0 0 0 0 rgba(var(--li-accent-rgb), 0); } }
|
|
245
|
+
slice-leak-inspector .glyph { color: var(--li-accent); font-size: 12px; }
|
|
246
|
+
slice-leak-inspector .title { font-weight: 600; font-size: 11px; letter-spacing: 0.16em; color: var(--li-text); }
|
|
247
|
+
slice-leak-inspector .actions { display: flex; gap: 6px; }
|
|
248
|
+
slice-leak-inspector .btn {
|
|
249
|
+
width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
|
|
250
|
+
border-radius: 7px; border: 1px solid var(--li-border); background: var(--li-raised);
|
|
251
|
+
color: var(--li-dim); cursor: pointer; font-size: 13px; line-height: 1;
|
|
252
|
+
transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
|
|
253
|
+
}
|
|
254
|
+
slice-leak-inspector .btn:hover { color: var(--li-text); background: var(--li-raised-2); border-color: rgba(var(--li-accent-rgb), 0.5); }
|
|
255
|
+
slice-leak-inspector .btn:active { transform: scale(0.92); }
|
|
256
|
+
|
|
257
|
+
slice-leak-inspector .leak-stats {
|
|
258
|
+
display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--li-border); background: var(--li-raised);
|
|
259
|
+
}
|
|
260
|
+
slice-leak-inspector .stat { flex: 1; display: flex; flex-direction: column; gap: 3px; align-items: center; padding: 6px 4px; border-radius: 8px; background: rgba(0,0,0,0.18); border: 1px solid var(--li-border); }
|
|
261
|
+
slice-leak-inspector .stat-label { font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--li-dim); }
|
|
262
|
+
slice-leak-inspector .stat-value { font-size: 16px; font-weight: 700; color: var(--li-text); }
|
|
263
|
+
slice-leak-inspector .stat-value.danger { color: var(--li-accent); }
|
|
264
|
+
slice-leak-inspector .stat-value.warn { color: var(--li-warn); }
|
|
265
|
+
|
|
266
|
+
slice-leak-inspector .leak-list { padding: 10px 12px 12px; overflow: auto; display: flex; flex-direction: column; gap: 7px; }
|
|
267
|
+
slice-leak-inspector .leak-list::-webkit-scrollbar { width: 8px; }
|
|
268
|
+
slice-leak-inspector .leak-list::-webkit-scrollbar-thumb { background: var(--li-raised-2); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
|
|
269
|
+
|
|
270
|
+
slice-leak-inspector .leak-row { display: block; padding: 9px 11px; background: var(--li-raised); border-radius: 9px; border: 1px solid var(--li-border); border-left: 2px solid var(--li-accent); }
|
|
271
|
+
slice-leak-inspector .leak-row summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; list-style: none; }
|
|
272
|
+
slice-leak-inspector .leak-row summary::-webkit-details-marker { display: none; }
|
|
273
|
+
slice-leak-inspector .leak-name { font-family: var(--li-mono); font-size: 12px; font-weight: 600; color: var(--li-text); }
|
|
274
|
+
slice-leak-inspector .leak-actions-row { display: flex; align-items: center; gap: 8px; }
|
|
275
|
+
slice-leak-inspector .leak-id { font-size: 10px; color: var(--li-dim); }
|
|
276
|
+
slice-leak-inspector .leak-destroy {
|
|
277
|
+
all: unset; cursor: pointer; font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase;
|
|
278
|
+
padding: 2px 8px; border-radius: 999px; color: var(--li-accent);
|
|
279
|
+
background: rgba(var(--li-accent-rgb), 0.12); border: 1px solid rgba(var(--li-accent-rgb), 0.3);
|
|
280
|
+
}
|
|
281
|
+
slice-leak-inspector .leak-destroy:hover { background: rgba(var(--li-accent-rgb), 0.22); }
|
|
282
|
+
slice-leak-inspector .leak-detail { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--li-border); display: flex; flex-direction: column; gap: 6px; }
|
|
283
|
+
slice-leak-inspector .leak-reason { font-size: 11px; color: var(--li-dim); }
|
|
284
|
+
slice-leak-inspector .leak-path { font-family: var(--li-mono); font-size: 10.5px; color: var(--li-text); word-break: break-word; }
|
|
285
|
+
slice-leak-inspector .path-key { color: var(--li-dim); margin-right: 6px; }
|
|
286
|
+
slice-leak-inspector .empty { color: var(--li-dim); font-size: 11px; letter-spacing: 0.04em; text-align: center; padding: 22px 0; }
|
|
287
|
+
|
|
288
|
+
@media (prefers-reduced-motion: reduce) {
|
|
289
|
+
slice-leak-inspector #leak-inspector.active { animation: none; }
|
|
290
|
+
slice-leak-inspector .status-dot { animation: none; }
|
|
291
|
+
}
|
|
292
|
+
`;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
customElements.define('slice-leak-inspector', LeakInspector);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export default class Log {
|
|
2
|
-
constructor(logType, componentCategory, componentSliceId, message, error = null) {
|
|
3
|
-
this.logType = logType;
|
|
4
|
-
this.componentCategory = componentCategory;
|
|
5
|
-
this.componentSliceId = componentSliceId;
|
|
6
|
-
this.message = message;
|
|
7
|
-
this.error = error;
|
|
8
|
-
this.timestamp = new Date();
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
export default class Log {
|
|
2
|
+
constructor(logType, componentCategory, componentSliceId, message, error = null) {
|
|
3
|
+
this.logType = logType;
|
|
4
|
+
this.componentCategory = componentCategory;
|
|
5
|
+
this.componentSliceId = componentSliceId;
|
|
6
|
+
this.message = message;
|
|
7
|
+
this.error = error;
|
|
8
|
+
this.timestamp = new Date();
|
|
9
|
+
}
|
|
10
|
+
}
|