slicejs-web-framework 4.0.2 → 4.1.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.
Files changed (73) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +97 -97
  3. package/Slice/Components/Structural/ContextManager/ContextManager.js +422 -422
  4. package/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +470 -470
  5. package/Slice/Components/Structural/Controller/Controller.js +1406 -1406
  6. package/Slice/Components/Structural/Controller/allowedValuesValidation.js +52 -52
  7. package/Slice/Components/Structural/Debugger/Debugger.html +72 -72
  8. package/Slice/Components/Structural/Debugger/Debugger.js +1505 -1505
  9. package/Slice/Components/Structural/EventManager/EventManager.js +651 -651
  10. package/Slice/Components/Structural/EventManager/EventManagerDebugger.js +985 -985
  11. package/Slice/Components/Structural/LeakInspector/LeakInspector.js +296 -296
  12. package/Slice/Components/Structural/Logger/Log.js +10 -10
  13. package/Slice/Components/Structural/Logger/LogViewer/LogViewer.js +662 -662
  14. package/Slice/Components/Structural/Logger/Logger.js +225 -225
  15. package/Slice/Components/Structural/Router/Router.js +820 -810
  16. package/Slice/Components/Structural/Router/applyRouteMetadata.js +39 -0
  17. package/Slice/Components/Structural/StylesManager/StylesManager.js +82 -82
  18. package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +175 -175
  19. package/Slice/Slice.js +711 -710
  20. package/api/framework/devDepsOptimizer.js +335 -335
  21. package/api/framework/express.js +3 -3
  22. package/api/framework/precompressedStatic.js +102 -93
  23. package/api/framework/publicEnvResolver.js +123 -123
  24. package/api/framework/securityMiddleware.js +197 -197
  25. package/api/framework/seo.js +387 -0
  26. package/api/framework/server.js +777 -410
  27. package/api/index.js +14 -4
  28. package/package.json +6 -2
  29. package/sliceConfig.schema.json +122 -122
  30. package/src/App/index.html +69 -69
  31. package/src/App/index.js +20 -20
  32. package/src/App/style.css +11 -11
  33. package/src/Components/AppComponents/AboutSection/AboutSection.css +9 -9
  34. package/src/Components/AppComponents/AboutSection/AboutSection.html +8 -8
  35. package/src/Components/AppComponents/AboutSection/AboutSection.js +12 -12
  36. package/src/Components/AppComponents/AppShell/AppShell.css +10 -10
  37. package/src/Components/AppComponents/AppShell/AppShell.html +4 -4
  38. package/src/Components/AppComponents/AppShell/AppShell.js +36 -36
  39. package/src/Components/AppComponents/HomeSection/HomeSection.css +20 -20
  40. package/src/Components/AppComponents/HomeSection/HomeSection.html +10 -10
  41. package/src/Components/AppComponents/HomeSection/HomeSection.js +19 -19
  42. package/src/Components/components.js +8 -8
  43. package/src/public/Styles/sliceStyles.css +34 -34
  44. package/src/public/Themes/Dark.css +42 -42
  45. package/src/public/Themes/Light.css +31 -31
  46. package/src/public/Themes/Slice.css +47 -47
  47. package/src/public/manifest.json +15 -15
  48. package/src/public/robots.txt +4 -4
  49. package/src/public/sitemap.xml +8 -8
  50. package/src/routes.js +9 -9
  51. package/src/sliceConfig.json +72 -72
  52. package/types/index.d.ts +219 -219
  53. package/.opencode/opencode.json +0 -15
  54. package/Slice/tests/build-bundled-component-without-category.test.js +0 -103
  55. package/Slice/tests/build-js-only-visual-components.test.js +0 -144
  56. package/Slice/tests/build-singleton.test.js +0 -244
  57. package/Slice/tests/bundle-v2-runtime-contract.test.js +0 -747
  58. package/Slice/tests/context-patch-use.test.js +0 -95
  59. package/Slice/tests/destroy-cascade.test.js +0 -215
  60. package/Slice/tests/event-emitters.test.js +0 -79
  61. package/Slice/tests/event-registry.test.js +0 -141
  62. package/Slice/tests/fixtures/real-runtime-loader.mjs +0 -21
  63. package/Slice/tests/leak-orphans.test.js +0 -131
  64. package/Slice/tests/props-allowed-values-validation.test.js +0 -119
  65. package/Slice/tests/public-env-runtime-accessors.test.js +0 -44
  66. package/Slice/tests/public-env-typed-accessors.test.js +0 -66
  67. package/Slice/tests/router-loading-finally.test.js +0 -68
  68. package/api/tests/dev-deps-optimizer.test.js +0 -137
  69. package/api/tests/dev-server-external.test.js +0 -56
  70. package/api/tests/precompressed-static.test.js +0 -119
  71. package/api/tests/public-env-resolver.test.js +0 -193
  72. package/tests/router-build-failure.test.js +0 -125
  73. package/tests/router-emit-ordering.test.js +0 -63
@@ -1,470 +1,470 @@
1
- /**
2
- * ContextManager debug panel.
3
- */
4
- export default class ContextManagerDebugger extends HTMLElement {
5
- constructor() {
6
- super();
7
- this.isOpen = false;
8
- this.filterText = '';
9
- this._contextSubscriptions = new Map();
10
- this._debounceTimer = null;
11
- }
12
-
13
- /**
14
- * Initialize panel UI.
15
- * @returns {Promise<void>}
16
- */
17
- async init() {
18
- this.innerHTML = this.renderTemplate();
19
- slice.stylesManager.registerComponentStyles('ContextManagerDebugger', this.renderStyles());
20
- this.cacheElements();
21
- this.bindEvents();
22
- this.makeDraggable();
23
- this._subscribeToAllContexts();
24
- this.renderList();
25
- }
26
-
27
- /**
28
- * Toggle panel visibility.
29
- * @returns {void}
30
- */
31
- toggle() {
32
- this.isOpen = !this.isOpen;
33
- this.container.classList.toggle('active', this.isOpen);
34
- if (this.isOpen) {
35
- this._subscribeToAllContexts();
36
- this.renderList();
37
- }
38
- }
39
-
40
- /**
41
- * Show panel.
42
- * @returns {void}
43
- */
44
- open() {
45
- this.isOpen = true;
46
- this.container.classList.add('active');
47
- this._subscribeToAllContexts();
48
- this.renderList();
49
- }
50
-
51
- /**
52
- * Hide panel.
53
- * @returns {void}
54
- */
55
- close() {
56
- this.isOpen = false;
57
- this.container.classList.remove('active');
58
- }
59
-
60
- disconnectedCallback() {
61
- this._unsubscribeAll();
62
- }
63
-
64
- _unsubscribeAll() {
65
- for (const [name, id] of this._contextSubscriptions) {
66
- slice.events.unsubscribe(`context:${name}`, id);
67
- }
68
- this._contextSubscriptions.clear();
69
- if (this._createdSub) {
70
- slice.events.unsubscribe('context:__created', this._createdSub);
71
- this._createdSub = null;
72
- }
73
- }
74
-
75
- _subscribeToAllContexts() {
76
- if (!slice?.context?.contexts) return;
77
- slice.context.contexts.forEach((value, name) => {
78
- if (this._contextSubscriptions.has(name)) return;
79
- const id = slice.events.subscribe(`context:${name}`, () => this._scheduleRender());
80
- this._contextSubscriptions.set(name, id);
81
- });
82
- if (!this._createdSub) {
83
- this._createdSub = slice.events.subscribe('context:__created', ({ name }) => {
84
- if (!this._contextSubscriptions.has(name)) {
85
- const id = slice.events.subscribe(`context:${name}`, () => this._scheduleRender());
86
- this._contextSubscriptions.set(name, id);
87
- }
88
- this._scheduleRender();
89
- });
90
- }
91
- }
92
-
93
- _scheduleRender() {
94
- if (this._debounceTimer) clearTimeout(this._debounceTimer);
95
- this._debounceTimer = setTimeout(() => {
96
- if (this.isOpen) this.renderList();
97
- }, 50);
98
- }
99
-
100
- cacheElements() {
101
- this.container = this.querySelector('#context-debugger');
102
- this.header = this.querySelector('.context-header');
103
- this.list = this.querySelector('#context-list');
104
- this.filterInput = this.querySelector('#context-filter');
105
- this.countLabel = this.querySelector('#context-count');
106
- this.refreshButton = this.querySelector('#context-refresh');
107
- this.closeButton = this.querySelector('#context-close');
108
- }
109
-
110
- bindEvents() {
111
- this.refreshButton.addEventListener('click', () => this.renderList());
112
- this.closeButton.addEventListener('click', () => this.close());
113
- this.filterInput.addEventListener('input', (event) => {
114
- this.filterText = event.target.value.trim().toLowerCase();
115
- this.renderList();
116
- });
117
- }
118
-
119
- makeDraggable() {
120
- if (!this.header || !this.container) return;
121
-
122
- let offset = { x: 0, y: 0 };
123
- let isDragging = false;
124
-
125
- this.header.style.cursor = 'grab';
126
-
127
- this.header.addEventListener('mousedown', (event) => {
128
- if (event.target.closest('.btn')) return;
129
- isDragging = true;
130
- offset.x = event.clientX - this.container.getBoundingClientRect().left;
131
- offset.y = event.clientY - this.container.getBoundingClientRect().top;
132
- this.header.style.cursor = 'grabbing';
133
- });
134
-
135
- document.addEventListener('mousemove', (event) => {
136
- if (!isDragging) return;
137
- const rect = this.container.getBoundingClientRect();
138
- const maxX = window.innerWidth - rect.width;
139
- const maxY = window.innerHeight - rect.height;
140
- const x = Math.min(Math.max(event.clientX - offset.x, 0), maxX);
141
- const y = Math.min(Math.max(event.clientY - offset.y, 0), maxY);
142
- this.container.style.left = `${x}px`;
143
- this.container.style.top = `${y}px`;
144
- this.container.style.right = 'auto';
145
- this.container.style.bottom = 'auto';
146
- });
147
-
148
- document.addEventListener('mouseup', () => {
149
- if (!isDragging) return;
150
- isDragging = false;
151
- this.header.style.cursor = 'grab';
152
- });
153
- }
154
-
155
- renderList() {
156
- if (!slice?.context?.contexts) {
157
- this.list.textContent = 'ContextManager not available.';
158
- this.countLabel.textContent = '0';
159
- return;
160
- }
161
-
162
- const items = [];
163
- slice.context.contexts.forEach((value, name) => {
164
- if (this.filterText && !name.toLowerCase().includes(this.filterText)) {
165
- return;
166
- }
167
- const keys = value?.state ? Object.keys(value.state).length : 0;
168
- items.push({ name, keys, state: value?.state || {} });
169
- });
170
-
171
- items.sort((a, b) => a.name.localeCompare(b.name));
172
-
173
- this.countLabel.textContent = String(items.length);
174
- this.list.innerHTML = items.length
175
- ? items.map((item) => {
176
- let preview;
177
- try { preview = JSON.stringify(item.state, null, 2); } catch { preview = String(item.state); }
178
- return `
179
- <div class="context-row">
180
- <div class="context-row-head">
181
- <div class="context-name">${item.name}</div>
182
- <div class="context-keys">${item.keys} keys</div>
183
- </div>
184
- <pre class="context-preview">${this.escapeHtml(preview)}</pre>
185
- </div>
186
- `;
187
- }).join('')
188
- : '<div class="empty">No contexts</div>';
189
- }
190
-
191
- escapeHtml(value) {
192
- return value
193
- .replace(/&/g, '&amp;')
194
- .replace(/</g, '&lt;')
195
- .replace(/>/g, '&gt;')
196
- .replace(/"/g, '&quot;')
197
- .replace(/'/g, '&#39;');
198
- }
199
-
200
- renderTemplate() {
201
- return `
202
- <div id="context-debugger">
203
- <div class="context-header">
204
- <div class="brand">
205
- <span class="status-dot"></span>
206
- <span class="glyph">◈</span>
207
- <span class="title">CONTEXT</span>
208
- </div>
209
- <div class="actions">
210
- <button id="context-refresh" class="btn" title="Refresh" aria-label="Refresh">⟳</button>
211
- <button id="context-close" class="btn" title="Close" aria-label="Close">✕</button>
212
- </div>
213
- </div>
214
- <div class="context-toolbar">
215
- <input id="context-filter" type="text" placeholder="filter contexts…" autocomplete="off" spellcheck="false" />
216
- <div class="count"><span id="context-count">0</span></div>
217
- </div>
218
- <div class="context-list" id="context-list"></div>
219
- </div>
220
- `;
221
- }
222
-
223
- renderStyles() {
224
- return `
225
- /* Slice Instruments — context store. All selectors scoped to the
226
- <slice-contextmanager-debugger> tag so nothing clashes with app styles.
227
- Every --si-* token reads the matching framework theme variable from
228
- :root, falling back to the original hardcoded value if absent. */
229
- slice-contextmanager-debugger {
230
- --si-accent: var(--primary-color, #6ee7ff);
231
- --si-accent-rgb: var(--primary-color-rgb, 110, 231, 255);
232
- --si-surface: var(--primary-background-color, rgba(17, 19, 28, 0.86));
233
- --si-raised: var(--secondary-background-color, rgba(255, 255, 255, 0.035));
234
- --si-raised-2: var(--tertiary-background-color, rgba(255, 255, 255, 0.06));
235
- --si-border: var(--medium-color, rgba(255, 255, 255, 0.09));
236
- --si-text: var(--font-primary-color, #e8eaf2);
237
- --si-dim: var(--font-secondary-color, #888fa6);
238
- --si-danger: var(--danger-color, #ff6b6b);
239
- --si-success: var(--success-color, #46d39a);
240
- --si-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Cascadia Code', Menlo, Consolas, monospace;
241
- }
242
-
243
- slice-contextmanager-debugger #context-debugger {
244
- position: fixed;
245
- bottom: 20px;
246
- left: 20px;
247
- width: min(400px, calc(100vw - 40px));
248
- max-height: 64vh;
249
- background: var(--si-surface);
250
- border: 1px solid var(--si-border);
251
- border-radius: 14px;
252
- box-shadow:
253
- 0 24px 60px -12px rgba(0, 0, 0, 0.55),
254
- 0 0 0 1px rgba(0, 0, 0, 0.2),
255
- 0 0 38px -18px rgba(var(--si-accent-rgb), 0.55);
256
- -webkit-backdrop-filter: blur(22px) saturate(1.3);
257
- backdrop-filter: blur(22px) saturate(1.3);
258
- display: none;
259
- flex-direction: column;
260
- z-index: 10001;
261
- overflow: hidden;
262
- color: var(--si-text);
263
- font-family: var(--si-mono);
264
- }
265
-
266
- slice-contextmanager-debugger #context-debugger.active {
267
- display: flex;
268
- animation: si-context-in 0.26s cubic-bezier(0.16, 1, 0.3, 1);
269
- }
270
-
271
- @keyframes si-context-in {
272
- from { opacity: 0; transform: translateY(10px) scale(0.985); }
273
- to { opacity: 1; transform: translateY(0) scale(1); }
274
- }
275
-
276
- slice-contextmanager-debugger #context-debugger * { box-sizing: border-box; }
277
-
278
- slice-contextmanager-debugger #context-debugger::before {
279
- content: '';
280
- position: absolute;
281
- left: 0; top: 0; bottom: 0;
282
- width: 2px;
283
- background: linear-gradient(180deg, var(--si-accent), transparent 70%);
284
- opacity: 0.85;
285
- pointer-events: none;
286
- }
287
-
288
- slice-contextmanager-debugger #context-debugger > .context-header {
289
- display: flex;
290
- justify-content: space-between;
291
- align-items: center;
292
- padding: 12px 14px;
293
- background:
294
- radial-gradient(120% 140% at 0% 0%, rgba(var(--si-accent-rgb), 0.10), transparent 60%),
295
- var(--si-raised);
296
- border-bottom: 1px solid var(--si-border);
297
- user-select: none;
298
- }
299
-
300
- slice-contextmanager-debugger .brand { display: flex; align-items: center; gap: 9px; }
301
-
302
- slice-contextmanager-debugger .status-dot {
303
- width: 7px; height: 7px;
304
- border-radius: 50%;
305
- background: var(--si-accent);
306
- animation: si-pulse-ctx 2.4s ease-out infinite;
307
- }
308
-
309
- @keyframes si-pulse-ctx {
310
- 0% { box-shadow: 0 0 0 0 rgba(var(--si-accent-rgb), 0.55); }
311
- 70% { box-shadow: 0 0 0 7px rgba(var(--si-accent-rgb), 0); }
312
- 100% { box-shadow: 0 0 0 0 rgba(var(--si-accent-rgb), 0); }
313
- }
314
-
315
- slice-contextmanager-debugger .glyph { color: var(--si-accent); font-size: 12px; opacity: 0.9; }
316
-
317
- slice-contextmanager-debugger .title {
318
- font-weight: 600;
319
- font-size: 11px;
320
- letter-spacing: 0.18em;
321
- color: var(--si-text);
322
- }
323
-
324
- slice-contextmanager-debugger .actions { display: flex; gap: 6px; }
325
-
326
- slice-contextmanager-debugger .btn {
327
- width: 26px; height: 26px;
328
- display: flex; align-items: center; justify-content: center;
329
- border-radius: 7px;
330
- border: 1px solid var(--si-border);
331
- background: var(--si-raised);
332
- color: var(--si-dim);
333
- cursor: pointer;
334
- font-size: 13px;
335
- line-height: 1;
336
- transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
337
- }
338
- slice-contextmanager-debugger .btn:hover {
339
- color: var(--si-text);
340
- background: var(--si-raised-2);
341
- border-color: rgba(var(--si-accent-rgb), 0.5);
342
- }
343
- slice-contextmanager-debugger .btn:active { transform: scale(0.92); }
344
- slice-contextmanager-debugger #context-refresh:hover { color: var(--si-accent); }
345
-
346
- slice-contextmanager-debugger .context-toolbar {
347
- display: flex;
348
- gap: 10px;
349
- align-items: center;
350
- padding: 10px 12px;
351
- border-bottom: 1px solid var(--si-border);
352
- }
353
-
354
- slice-contextmanager-debugger .context-toolbar input {
355
- flex: 1;
356
- min-width: 0;
357
- padding: 7px 10px 7px 30px;
358
- border-radius: 8px;
359
- border: 1px solid var(--si-border);
360
- background:
361
- var(--si-raised) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 24 24' fill='none' stroke='%23888fa6' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat 10px center;
362
- color: var(--si-text);
363
- font-family: var(--si-mono);
364
- font-size: 12px;
365
- transition: border-color 0.15s ease, box-shadow 0.15s ease;
366
- }
367
- slice-contextmanager-debugger .context-toolbar input::placeholder { color: var(--si-dim); }
368
- slice-contextmanager-debugger .context-toolbar input:focus {
369
- outline: none;
370
- border-color: rgba(var(--si-accent-rgb), 0.6);
371
- box-shadow: 0 0 0 3px rgba(var(--si-accent-rgb), 0.12);
372
- }
373
-
374
- slice-contextmanager-debugger .context-toolbar .count { font-size: 11px; color: var(--si-dim); min-width: 22px; text-align: center; }
375
- slice-contextmanager-debugger .context-toolbar .count span { color: var(--si-accent); font-weight: 600; }
376
-
377
- slice-contextmanager-debugger .context-list {
378
- padding: 10px 12px 12px;
379
- overflow: auto;
380
- display: flex;
381
- flex-direction: column;
382
- gap: 9px;
383
- }
384
- slice-contextmanager-debugger .context-list::-webkit-scrollbar { width: 8px; }
385
- slice-contextmanager-debugger .context-list::-webkit-scrollbar-thumb {
386
- background: var(--si-raised-2);
387
- border-radius: 8px;
388
- border: 2px solid transparent;
389
- background-clip: padding-box;
390
- }
391
- slice-contextmanager-debugger .context-list::-webkit-scrollbar-thumb:hover { background: rgba(var(--si-accent-rgb), 0.4); background-clip: padding-box; }
392
-
393
- slice-contextmanager-debugger .context-row {
394
- border: 1px solid var(--si-border);
395
- border-left: 2px solid transparent;
396
- border-radius: 10px;
397
- background: var(--si-raised);
398
- padding: 10px 11px;
399
- display: flex;
400
- flex-direction: column;
401
- gap: 8px;
402
- transition: border-color 0.18s ease, background 0.18s ease;
403
- }
404
- slice-contextmanager-debugger .context-row:hover { background: var(--si-raised-2); border-left-color: var(--si-accent); }
405
-
406
- slice-contextmanager-debugger .context-row-head {
407
- display: flex;
408
- align-items: center;
409
- justify-content: space-between;
410
- gap: 10px;
411
- }
412
-
413
- slice-contextmanager-debugger .context-name {
414
- font-weight: 600;
415
- font-size: 12.5px;
416
- color: var(--si-text);
417
- font-family: var(--si-mono);
418
- }
419
-
420
- slice-contextmanager-debugger .context-keys {
421
- font-size: 10px;
422
- letter-spacing: 0.04em;
423
- text-transform: uppercase;
424
- color: var(--si-accent);
425
- background: rgba(var(--si-accent-rgb), 0.12);
426
- border: 1px solid rgba(var(--si-accent-rgb), 0.25);
427
- padding: 1px 8px;
428
- border-radius: 999px;
429
- white-space: nowrap;
430
- }
431
-
432
- slice-contextmanager-debugger .context-preview {
433
- background: rgba(0, 0, 0, 0.3);
434
- border-radius: 8px;
435
- padding: 10px;
436
- border: 1px solid var(--si-border);
437
- max-height: 200px;
438
- overflow: auto;
439
- font-size: 11px;
440
- line-height: 1.55;
441
- font-family: var(--si-mono);
442
- color: #c5cad8;
443
- white-space: pre;
444
- margin: 0;
445
- }
446
- slice-contextmanager-debugger .context-preview::-webkit-scrollbar { width: 8px; height: 8px; }
447
- slice-contextmanager-debugger .context-preview::-webkit-scrollbar-thumb {
448
- background: var(--si-raised-2);
449
- border-radius: 8px;
450
- border: 2px solid transparent;
451
- background-clip: padding-box;
452
- }
453
-
454
- slice-contextmanager-debugger .empty {
455
- color: var(--si-dim);
456
- font-size: 11px;
457
- letter-spacing: 0.04em;
458
- text-align: center;
459
- padding: 22px 0;
460
- }
461
-
462
- @media (prefers-reduced-motion: reduce) {
463
- slice-contextmanager-debugger #context-debugger.active { animation: none; }
464
- slice-contextmanager-debugger .status-dot { animation: none; }
465
- }
466
- `;
467
- }
468
- }
469
-
470
- customElements.define('slice-contextmanager-debugger', ContextManagerDebugger);
1
+ /**
2
+ * ContextManager debug panel.
3
+ */
4
+ export default class ContextManagerDebugger extends HTMLElement {
5
+ constructor() {
6
+ super();
7
+ this.isOpen = false;
8
+ this.filterText = '';
9
+ this._contextSubscriptions = new Map();
10
+ this._debounceTimer = null;
11
+ }
12
+
13
+ /**
14
+ * Initialize panel UI.
15
+ * @returns {Promise<void>}
16
+ */
17
+ async init() {
18
+ this.innerHTML = this.renderTemplate();
19
+ slice.stylesManager.registerComponentStyles('ContextManagerDebugger', this.renderStyles());
20
+ this.cacheElements();
21
+ this.bindEvents();
22
+ this.makeDraggable();
23
+ this._subscribeToAllContexts();
24
+ this.renderList();
25
+ }
26
+
27
+ /**
28
+ * Toggle panel visibility.
29
+ * @returns {void}
30
+ */
31
+ toggle() {
32
+ this.isOpen = !this.isOpen;
33
+ this.container.classList.toggle('active', this.isOpen);
34
+ if (this.isOpen) {
35
+ this._subscribeToAllContexts();
36
+ this.renderList();
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Show panel.
42
+ * @returns {void}
43
+ */
44
+ open() {
45
+ this.isOpen = true;
46
+ this.container.classList.add('active');
47
+ this._subscribeToAllContexts();
48
+ this.renderList();
49
+ }
50
+
51
+ /**
52
+ * Hide panel.
53
+ * @returns {void}
54
+ */
55
+ close() {
56
+ this.isOpen = false;
57
+ this.container.classList.remove('active');
58
+ }
59
+
60
+ disconnectedCallback() {
61
+ this._unsubscribeAll();
62
+ }
63
+
64
+ _unsubscribeAll() {
65
+ for (const [name, id] of this._contextSubscriptions) {
66
+ slice.events.unsubscribe(`context:${name}`, id);
67
+ }
68
+ this._contextSubscriptions.clear();
69
+ if (this._createdSub) {
70
+ slice.events.unsubscribe('context:__created', this._createdSub);
71
+ this._createdSub = null;
72
+ }
73
+ }
74
+
75
+ _subscribeToAllContexts() {
76
+ if (!slice?.context?.contexts) return;
77
+ slice.context.contexts.forEach((value, name) => {
78
+ if (this._contextSubscriptions.has(name)) return;
79
+ const id = slice.events.subscribe(`context:${name}`, () => this._scheduleRender());
80
+ this._contextSubscriptions.set(name, id);
81
+ });
82
+ if (!this._createdSub) {
83
+ this._createdSub = slice.events.subscribe('context:__created', ({ name }) => {
84
+ if (!this._contextSubscriptions.has(name)) {
85
+ const id = slice.events.subscribe(`context:${name}`, () => this._scheduleRender());
86
+ this._contextSubscriptions.set(name, id);
87
+ }
88
+ this._scheduleRender();
89
+ });
90
+ }
91
+ }
92
+
93
+ _scheduleRender() {
94
+ if (this._debounceTimer) clearTimeout(this._debounceTimer);
95
+ this._debounceTimer = setTimeout(() => {
96
+ if (this.isOpen) this.renderList();
97
+ }, 50);
98
+ }
99
+
100
+ cacheElements() {
101
+ this.container = this.querySelector('#context-debugger');
102
+ this.header = this.querySelector('.context-header');
103
+ this.list = this.querySelector('#context-list');
104
+ this.filterInput = this.querySelector('#context-filter');
105
+ this.countLabel = this.querySelector('#context-count');
106
+ this.refreshButton = this.querySelector('#context-refresh');
107
+ this.closeButton = this.querySelector('#context-close');
108
+ }
109
+
110
+ bindEvents() {
111
+ this.refreshButton.addEventListener('click', () => this.renderList());
112
+ this.closeButton.addEventListener('click', () => this.close());
113
+ this.filterInput.addEventListener('input', (event) => {
114
+ this.filterText = event.target.value.trim().toLowerCase();
115
+ this.renderList();
116
+ });
117
+ }
118
+
119
+ makeDraggable() {
120
+ if (!this.header || !this.container) return;
121
+
122
+ let offset = { x: 0, y: 0 };
123
+ let isDragging = false;
124
+
125
+ this.header.style.cursor = 'grab';
126
+
127
+ this.header.addEventListener('mousedown', (event) => {
128
+ if (event.target.closest('.btn')) return;
129
+ isDragging = true;
130
+ offset.x = event.clientX - this.container.getBoundingClientRect().left;
131
+ offset.y = event.clientY - this.container.getBoundingClientRect().top;
132
+ this.header.style.cursor = 'grabbing';
133
+ });
134
+
135
+ document.addEventListener('mousemove', (event) => {
136
+ if (!isDragging) return;
137
+ const rect = this.container.getBoundingClientRect();
138
+ const maxX = window.innerWidth - rect.width;
139
+ const maxY = window.innerHeight - rect.height;
140
+ const x = Math.min(Math.max(event.clientX - offset.x, 0), maxX);
141
+ const y = Math.min(Math.max(event.clientY - offset.y, 0), maxY);
142
+ this.container.style.left = `${x}px`;
143
+ this.container.style.top = `${y}px`;
144
+ this.container.style.right = 'auto';
145
+ this.container.style.bottom = 'auto';
146
+ });
147
+
148
+ document.addEventListener('mouseup', () => {
149
+ if (!isDragging) return;
150
+ isDragging = false;
151
+ this.header.style.cursor = 'grab';
152
+ });
153
+ }
154
+
155
+ renderList() {
156
+ if (!slice?.context?.contexts) {
157
+ this.list.textContent = 'ContextManager not available.';
158
+ this.countLabel.textContent = '0';
159
+ return;
160
+ }
161
+
162
+ const items = [];
163
+ slice.context.contexts.forEach((value, name) => {
164
+ if (this.filterText && !name.toLowerCase().includes(this.filterText)) {
165
+ return;
166
+ }
167
+ const keys = value?.state ? Object.keys(value.state).length : 0;
168
+ items.push({ name, keys, state: value?.state || {} });
169
+ });
170
+
171
+ items.sort((a, b) => a.name.localeCompare(b.name));
172
+
173
+ this.countLabel.textContent = String(items.length);
174
+ this.list.innerHTML = items.length
175
+ ? items.map((item) => {
176
+ let preview;
177
+ try { preview = JSON.stringify(item.state, null, 2); } catch { preview = String(item.state); }
178
+ return `
179
+ <div class="context-row">
180
+ <div class="context-row-head">
181
+ <div class="context-name">${item.name}</div>
182
+ <div class="context-keys">${item.keys} keys</div>
183
+ </div>
184
+ <pre class="context-preview">${this.escapeHtml(preview)}</pre>
185
+ </div>
186
+ `;
187
+ }).join('')
188
+ : '<div class="empty">No contexts</div>';
189
+ }
190
+
191
+ escapeHtml(value) {
192
+ return value
193
+ .replace(/&/g, '&amp;')
194
+ .replace(/</g, '&lt;')
195
+ .replace(/>/g, '&gt;')
196
+ .replace(/"/g, '&quot;')
197
+ .replace(/'/g, '&#39;');
198
+ }
199
+
200
+ renderTemplate() {
201
+ return `
202
+ <div id="context-debugger">
203
+ <div class="context-header">
204
+ <div class="brand">
205
+ <span class="status-dot"></span>
206
+ <span class="glyph">◈</span>
207
+ <span class="title">CONTEXT</span>
208
+ </div>
209
+ <div class="actions">
210
+ <button id="context-refresh" class="btn" title="Refresh" aria-label="Refresh">⟳</button>
211
+ <button id="context-close" class="btn" title="Close" aria-label="Close">✕</button>
212
+ </div>
213
+ </div>
214
+ <div class="context-toolbar">
215
+ <input id="context-filter" type="text" placeholder="filter contexts…" autocomplete="off" spellcheck="false" />
216
+ <div class="count"><span id="context-count">0</span></div>
217
+ </div>
218
+ <div class="context-list" id="context-list"></div>
219
+ </div>
220
+ `;
221
+ }
222
+
223
+ renderStyles() {
224
+ return `
225
+ /* Slice Instruments — context store. All selectors scoped to the
226
+ <slice-contextmanager-debugger> tag so nothing clashes with app styles.
227
+ Every --si-* token reads the matching framework theme variable from
228
+ :root, falling back to the original hardcoded value if absent. */
229
+ slice-contextmanager-debugger {
230
+ --si-accent: var(--primary-color, #6ee7ff);
231
+ --si-accent-rgb: var(--primary-color-rgb, 110, 231, 255);
232
+ --si-surface: var(--primary-background-color, rgba(17, 19, 28, 0.86));
233
+ --si-raised: var(--secondary-background-color, rgba(255, 255, 255, 0.035));
234
+ --si-raised-2: var(--tertiary-background-color, rgba(255, 255, 255, 0.06));
235
+ --si-border: var(--medium-color, rgba(255, 255, 255, 0.09));
236
+ --si-text: var(--font-primary-color, #e8eaf2);
237
+ --si-dim: var(--font-secondary-color, #888fa6);
238
+ --si-danger: var(--danger-color, #ff6b6b);
239
+ --si-success: var(--success-color, #46d39a);
240
+ --si-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Cascadia Code', Menlo, Consolas, monospace;
241
+ }
242
+
243
+ slice-contextmanager-debugger #context-debugger {
244
+ position: fixed;
245
+ bottom: 20px;
246
+ left: 20px;
247
+ width: min(400px, calc(100vw - 40px));
248
+ max-height: 64vh;
249
+ background: var(--si-surface);
250
+ border: 1px solid var(--si-border);
251
+ border-radius: 14px;
252
+ box-shadow:
253
+ 0 24px 60px -12px rgba(0, 0, 0, 0.55),
254
+ 0 0 0 1px rgba(0, 0, 0, 0.2),
255
+ 0 0 38px -18px rgba(var(--si-accent-rgb), 0.55);
256
+ -webkit-backdrop-filter: blur(22px) saturate(1.3);
257
+ backdrop-filter: blur(22px) saturate(1.3);
258
+ display: none;
259
+ flex-direction: column;
260
+ z-index: 10001;
261
+ overflow: hidden;
262
+ color: var(--si-text);
263
+ font-family: var(--si-mono);
264
+ }
265
+
266
+ slice-contextmanager-debugger #context-debugger.active {
267
+ display: flex;
268
+ animation: si-context-in 0.26s cubic-bezier(0.16, 1, 0.3, 1);
269
+ }
270
+
271
+ @keyframes si-context-in {
272
+ from { opacity: 0; transform: translateY(10px) scale(0.985); }
273
+ to { opacity: 1; transform: translateY(0) scale(1); }
274
+ }
275
+
276
+ slice-contextmanager-debugger #context-debugger * { box-sizing: border-box; }
277
+
278
+ slice-contextmanager-debugger #context-debugger::before {
279
+ content: '';
280
+ position: absolute;
281
+ left: 0; top: 0; bottom: 0;
282
+ width: 2px;
283
+ background: linear-gradient(180deg, var(--si-accent), transparent 70%);
284
+ opacity: 0.85;
285
+ pointer-events: none;
286
+ }
287
+
288
+ slice-contextmanager-debugger #context-debugger > .context-header {
289
+ display: flex;
290
+ justify-content: space-between;
291
+ align-items: center;
292
+ padding: 12px 14px;
293
+ background:
294
+ radial-gradient(120% 140% at 0% 0%, rgba(var(--si-accent-rgb), 0.10), transparent 60%),
295
+ var(--si-raised);
296
+ border-bottom: 1px solid var(--si-border);
297
+ user-select: none;
298
+ }
299
+
300
+ slice-contextmanager-debugger .brand { display: flex; align-items: center; gap: 9px; }
301
+
302
+ slice-contextmanager-debugger .status-dot {
303
+ width: 7px; height: 7px;
304
+ border-radius: 50%;
305
+ background: var(--si-accent);
306
+ animation: si-pulse-ctx 2.4s ease-out infinite;
307
+ }
308
+
309
+ @keyframes si-pulse-ctx {
310
+ 0% { box-shadow: 0 0 0 0 rgba(var(--si-accent-rgb), 0.55); }
311
+ 70% { box-shadow: 0 0 0 7px rgba(var(--si-accent-rgb), 0); }
312
+ 100% { box-shadow: 0 0 0 0 rgba(var(--si-accent-rgb), 0); }
313
+ }
314
+
315
+ slice-contextmanager-debugger .glyph { color: var(--si-accent); font-size: 12px; opacity: 0.9; }
316
+
317
+ slice-contextmanager-debugger .title {
318
+ font-weight: 600;
319
+ font-size: 11px;
320
+ letter-spacing: 0.18em;
321
+ color: var(--si-text);
322
+ }
323
+
324
+ slice-contextmanager-debugger .actions { display: flex; gap: 6px; }
325
+
326
+ slice-contextmanager-debugger .btn {
327
+ width: 26px; height: 26px;
328
+ display: flex; align-items: center; justify-content: center;
329
+ border-radius: 7px;
330
+ border: 1px solid var(--si-border);
331
+ background: var(--si-raised);
332
+ color: var(--si-dim);
333
+ cursor: pointer;
334
+ font-size: 13px;
335
+ line-height: 1;
336
+ transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
337
+ }
338
+ slice-contextmanager-debugger .btn:hover {
339
+ color: var(--si-text);
340
+ background: var(--si-raised-2);
341
+ border-color: rgba(var(--si-accent-rgb), 0.5);
342
+ }
343
+ slice-contextmanager-debugger .btn:active { transform: scale(0.92); }
344
+ slice-contextmanager-debugger #context-refresh:hover { color: var(--si-accent); }
345
+
346
+ slice-contextmanager-debugger .context-toolbar {
347
+ display: flex;
348
+ gap: 10px;
349
+ align-items: center;
350
+ padding: 10px 12px;
351
+ border-bottom: 1px solid var(--si-border);
352
+ }
353
+
354
+ slice-contextmanager-debugger .context-toolbar input {
355
+ flex: 1;
356
+ min-width: 0;
357
+ padding: 7px 10px 7px 30px;
358
+ border-radius: 8px;
359
+ border: 1px solid var(--si-border);
360
+ background:
361
+ var(--si-raised) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 24 24' fill='none' stroke='%23888fa6' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat 10px center;
362
+ color: var(--si-text);
363
+ font-family: var(--si-mono);
364
+ font-size: 12px;
365
+ transition: border-color 0.15s ease, box-shadow 0.15s ease;
366
+ }
367
+ slice-contextmanager-debugger .context-toolbar input::placeholder { color: var(--si-dim); }
368
+ slice-contextmanager-debugger .context-toolbar input:focus {
369
+ outline: none;
370
+ border-color: rgba(var(--si-accent-rgb), 0.6);
371
+ box-shadow: 0 0 0 3px rgba(var(--si-accent-rgb), 0.12);
372
+ }
373
+
374
+ slice-contextmanager-debugger .context-toolbar .count { font-size: 11px; color: var(--si-dim); min-width: 22px; text-align: center; }
375
+ slice-contextmanager-debugger .context-toolbar .count span { color: var(--si-accent); font-weight: 600; }
376
+
377
+ slice-contextmanager-debugger .context-list {
378
+ padding: 10px 12px 12px;
379
+ overflow: auto;
380
+ display: flex;
381
+ flex-direction: column;
382
+ gap: 9px;
383
+ }
384
+ slice-contextmanager-debugger .context-list::-webkit-scrollbar { width: 8px; }
385
+ slice-contextmanager-debugger .context-list::-webkit-scrollbar-thumb {
386
+ background: var(--si-raised-2);
387
+ border-radius: 8px;
388
+ border: 2px solid transparent;
389
+ background-clip: padding-box;
390
+ }
391
+ slice-contextmanager-debugger .context-list::-webkit-scrollbar-thumb:hover { background: rgba(var(--si-accent-rgb), 0.4); background-clip: padding-box; }
392
+
393
+ slice-contextmanager-debugger .context-row {
394
+ border: 1px solid var(--si-border);
395
+ border-left: 2px solid transparent;
396
+ border-radius: 10px;
397
+ background: var(--si-raised);
398
+ padding: 10px 11px;
399
+ display: flex;
400
+ flex-direction: column;
401
+ gap: 8px;
402
+ transition: border-color 0.18s ease, background 0.18s ease;
403
+ }
404
+ slice-contextmanager-debugger .context-row:hover { background: var(--si-raised-2); border-left-color: var(--si-accent); }
405
+
406
+ slice-contextmanager-debugger .context-row-head {
407
+ display: flex;
408
+ align-items: center;
409
+ justify-content: space-between;
410
+ gap: 10px;
411
+ }
412
+
413
+ slice-contextmanager-debugger .context-name {
414
+ font-weight: 600;
415
+ font-size: 12.5px;
416
+ color: var(--si-text);
417
+ font-family: var(--si-mono);
418
+ }
419
+
420
+ slice-contextmanager-debugger .context-keys {
421
+ font-size: 10px;
422
+ letter-spacing: 0.04em;
423
+ text-transform: uppercase;
424
+ color: var(--si-accent);
425
+ background: rgba(var(--si-accent-rgb), 0.12);
426
+ border: 1px solid rgba(var(--si-accent-rgb), 0.25);
427
+ padding: 1px 8px;
428
+ border-radius: 999px;
429
+ white-space: nowrap;
430
+ }
431
+
432
+ slice-contextmanager-debugger .context-preview {
433
+ background: rgba(0, 0, 0, 0.3);
434
+ border-radius: 8px;
435
+ padding: 10px;
436
+ border: 1px solid var(--si-border);
437
+ max-height: 200px;
438
+ overflow: auto;
439
+ font-size: 11px;
440
+ line-height: 1.55;
441
+ font-family: var(--si-mono);
442
+ color: #c5cad8;
443
+ white-space: pre;
444
+ margin: 0;
445
+ }
446
+ slice-contextmanager-debugger .context-preview::-webkit-scrollbar { width: 8px; height: 8px; }
447
+ slice-contextmanager-debugger .context-preview::-webkit-scrollbar-thumb {
448
+ background: var(--si-raised-2);
449
+ border-radius: 8px;
450
+ border: 2px solid transparent;
451
+ background-clip: padding-box;
452
+ }
453
+
454
+ slice-contextmanager-debugger .empty {
455
+ color: var(--si-dim);
456
+ font-size: 11px;
457
+ letter-spacing: 0.04em;
458
+ text-align: center;
459
+ padding: 22px 0;
460
+ }
461
+
462
+ @media (prefers-reduced-motion: reduce) {
463
+ slice-contextmanager-debugger #context-debugger.active { animation: none; }
464
+ slice-contextmanager-debugger .status-dot { animation: none; }
465
+ }
466
+ `;
467
+ }
468
+ }
469
+
470
+ customElements.define('slice-contextmanager-debugger', ContextManagerDebugger);