slicejs-web-framework 3.4.3 → 3.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.
- package/.opencode/opencode.json +14 -14
- package/Slice/Components/Structural/ContextManager/ContextManager.js +422 -422
- package/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +468 -468
- package/Slice/Components/Structural/Controller/Controller.js +1406 -1198
- package/Slice/Components/Structural/Debugger/Debugger.js +1503 -1503
- package/Slice/Components/Structural/EventManager/EventManager.js +651 -366
- package/Slice/Components/Structural/EventManager/EventManagerDebugger.js +368 -30
- package/Slice/Components/Structural/LeakInspector/LeakInspector.js +296 -0
- package/Slice/Components/Structural/Logger/Logger.js +225 -225
- package/Slice/Components/Structural/Router/Router.js +775 -775
- package/Slice/Components/Structural/StylesManager/StylesManager.js +82 -82
- package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +106 -106
- package/Slice/Slice.js +663 -627
- 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/event-emitters.test.js +79 -0
- package/Slice/tests/event-registry.test.js +141 -0
- package/Slice/tests/fixtures/real-runtime-loader.mjs +21 -21
- package/Slice/tests/leak-orphans.test.js +131 -0
- package/Slice/tests/public-env-typed-accessors.test.js +66 -66
- package/api/index.js +308 -281
- package/api/utils/publicEnvResolver.js +123 -123
- package/package.json +44 -44
- package/sliceConfig.schema.json +10 -1
- package/src/sliceConfig.json +5 -1
- package/types/index.d.ts +12 -0
|
@@ -0,0 +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);
|