@useavalon/avalon 0.1.11 → 0.1.13

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 (141) hide show
  1. package/README.md +54 -54
  2. package/mod.ts +302 -302
  3. package/package.json +49 -26
  4. package/src/build/integration-bundler-plugin.ts +116 -116
  5. package/src/build/integration-config.ts +168 -168
  6. package/src/build/integration-detection-plugin.ts +117 -117
  7. package/src/build/integration-resolver-plugin.ts +90 -90
  8. package/src/build/island-manifest.ts +269 -269
  9. package/src/build/island-types-generator.ts +476 -476
  10. package/src/build/mdx-island-transform.ts +464 -464
  11. package/src/build/mdx-plugin.ts +98 -98
  12. package/src/build/page-island-transform.ts +598 -598
  13. package/src/build/prop-extractors/index.ts +21 -21
  14. package/src/build/prop-extractors/lit.ts +140 -140
  15. package/src/build/prop-extractors/qwik.ts +16 -16
  16. package/src/build/prop-extractors/solid.ts +125 -125
  17. package/src/build/prop-extractors/svelte.ts +194 -194
  18. package/src/build/prop-extractors/vue.ts +111 -111
  19. package/src/build/sidecar-file-manager.ts +104 -104
  20. package/src/build/sidecar-renderer.ts +30 -30
  21. package/src/client/adapters/index.ts +21 -13
  22. package/src/client/components.ts +35 -35
  23. package/src/client/css-hmr-handler.ts +344 -344
  24. package/src/client/framework-adapter.ts +462 -462
  25. package/src/client/hmr-coordinator.ts +396 -396
  26. package/src/client/hmr-error-overlay.js +533 -533
  27. package/src/client/main.js +824 -816
  28. package/src/client/types/framework-runtime.d.ts +68 -68
  29. package/src/client/types/vite-hmr.d.ts +46 -46
  30. package/src/client/types/vite-virtual-modules.d.ts +70 -60
  31. package/src/components/Image.tsx +123 -123
  32. package/src/components/IslandErrorBoundary.tsx +145 -145
  33. package/src/components/LayoutDataErrorBoundary.tsx +141 -141
  34. package/src/components/LayoutErrorBoundary.tsx +127 -127
  35. package/src/components/PersistentIsland.tsx +52 -52
  36. package/src/components/StreamingErrorBoundary.tsx +233 -233
  37. package/src/components/StreamingLayout.tsx +538 -538
  38. package/src/core/components/component-analyzer.ts +192 -192
  39. package/src/core/components/component-detection.ts +508 -508
  40. package/src/core/components/enhanced-framework-detector.ts +500 -500
  41. package/src/core/components/framework-registry.ts +563 -563
  42. package/src/core/content/mdx-processor.ts +46 -46
  43. package/src/core/integrations/index.ts +19 -19
  44. package/src/core/integrations/loader.ts +125 -125
  45. package/src/core/integrations/registry.ts +175 -175
  46. package/src/core/islands/island-persistence.ts +325 -325
  47. package/src/core/islands/island-state-serializer.ts +258 -258
  48. package/src/core/islands/persistent-island-context.tsx +80 -80
  49. package/src/core/islands/use-persistent-state.ts +68 -68
  50. package/src/core/layout/enhanced-layout-resolver.ts +322 -322
  51. package/src/core/layout/layout-cache-manager.ts +485 -485
  52. package/src/core/layout/layout-composer.ts +357 -357
  53. package/src/core/layout/layout-data-loader.ts +516 -516
  54. package/src/core/layout/layout-discovery.ts +243 -243
  55. package/src/core/layout/layout-matcher.ts +299 -299
  56. package/src/core/layout/layout-types.ts +110 -110
  57. package/src/core/modules/framework-module-resolver.ts +273 -273
  58. package/src/islands/component-analysis.ts +213 -213
  59. package/src/islands/css-utils.ts +565 -565
  60. package/src/islands/discovery/index.ts +80 -80
  61. package/src/islands/discovery/registry.ts +340 -340
  62. package/src/islands/discovery/resolver.ts +477 -477
  63. package/src/islands/discovery/scanner.ts +386 -386
  64. package/src/islands/discovery/types.ts +117 -117
  65. package/src/islands/discovery/validator.ts +544 -544
  66. package/src/islands/discovery/watcher.ts +368 -368
  67. package/src/islands/framework-detection.ts +428 -428
  68. package/src/islands/integration-loader.ts +490 -490
  69. package/src/islands/island.tsx +565 -565
  70. package/src/islands/render-cache.ts +550 -550
  71. package/src/islands/types.ts +80 -80
  72. package/src/islands/universal-css-collector.ts +157 -157
  73. package/src/islands/universal-head-collector.ts +137 -137
  74. package/src/layout-system.d.ts +592 -592
  75. package/src/layout-system.ts +218 -218
  76. package/src/middleware/discovery.ts +268 -268
  77. package/src/middleware/executor.ts +315 -315
  78. package/src/middleware/index.ts +76 -76
  79. package/src/middleware/types.ts +99 -99
  80. package/src/nitro/build-config.ts +575 -575
  81. package/src/nitro/config.ts +483 -483
  82. package/src/nitro/error-handler.ts +636 -636
  83. package/src/nitro/index.ts +173 -173
  84. package/src/nitro/island-manifest.ts +584 -584
  85. package/src/nitro/middleware-adapter.ts +260 -260
  86. package/src/nitro/renderer.ts +1471 -1471
  87. package/src/nitro/route-discovery.ts +439 -439
  88. package/src/nitro/types.ts +321 -321
  89. package/src/render/collect-css.ts +198 -198
  90. package/src/render/error-pages.ts +79 -79
  91. package/src/render/isolated-ssr-renderer.ts +654 -654
  92. package/src/render/ssr.ts +1030 -1030
  93. package/src/schemas/api.ts +30 -30
  94. package/src/schemas/core.ts +64 -64
  95. package/src/schemas/index.ts +212 -212
  96. package/src/schemas/layout.ts +279 -279
  97. package/src/schemas/routing/index.ts +38 -38
  98. package/src/schemas/routing.ts +376 -376
  99. package/src/types/as-island.ts +20 -20
  100. package/src/types/image.d.ts +106 -106
  101. package/src/types/index.d.ts +22 -22
  102. package/src/types/island-jsx.d.ts +33 -33
  103. package/src/types/island-prop.d.ts +20 -20
  104. package/src/types/layout.ts +285 -285
  105. package/src/types/mdx.d.ts +6 -6
  106. package/src/types/routing.ts +555 -555
  107. package/src/types/types.ts +5 -5
  108. package/src/types/urlpattern.d.ts +49 -49
  109. package/src/types/vite-env.d.ts +11 -11
  110. package/src/utils/dev-logger.ts +299 -299
  111. package/src/utils/fs.ts +151 -151
  112. package/src/vite-plugin/auto-discover.ts +551 -551
  113. package/src/vite-plugin/config.ts +266 -266
  114. package/src/vite-plugin/errors.ts +127 -127
  115. package/src/vite-plugin/image-optimization.ts +156 -156
  116. package/src/vite-plugin/integration-activator.ts +126 -126
  117. package/src/vite-plugin/island-sidecar-plugin.ts +176 -176
  118. package/src/vite-plugin/module-discovery.ts +189 -189
  119. package/src/vite-plugin/nitro-integration.ts +1354 -1354
  120. package/src/vite-plugin/plugin.ts +403 -409
  121. package/src/vite-plugin/types.ts +327 -327
  122. package/src/vite-plugin/validation.ts +228 -228
  123. package/src/client/adapters/index.js +0 -12
  124. package/src/client/adapters/lit-adapter.js +0 -467
  125. package/src/client/adapters/lit-adapter.ts +0 -654
  126. package/src/client/adapters/preact-adapter.js +0 -223
  127. package/src/client/adapters/preact-adapter.ts +0 -331
  128. package/src/client/adapters/qwik-adapter.js +0 -259
  129. package/src/client/adapters/qwik-adapter.ts +0 -345
  130. package/src/client/adapters/react-adapter.js +0 -220
  131. package/src/client/adapters/react-adapter.ts +0 -353
  132. package/src/client/adapters/solid-adapter.js +0 -295
  133. package/src/client/adapters/solid-adapter.ts +0 -451
  134. package/src/client/adapters/svelte-adapter.js +0 -368
  135. package/src/client/adapters/svelte-adapter.ts +0 -524
  136. package/src/client/adapters/vue-adapter.js +0 -278
  137. package/src/client/adapters/vue-adapter.ts +0 -467
  138. package/src/client/components.js +0 -23
  139. package/src/client/css-hmr-handler.js +0 -263
  140. package/src/client/framework-adapter.js +0 -283
  141. package/src/client/hmr-coordinator.js +0 -274
@@ -1,533 +1,533 @@
1
- /**
2
- * HMR Error Overlay
3
- *
4
- * Provides detailed error feedback when HMR fails for island components.
5
- * Displays file paths, error details, and suggestions for fixing issues.
6
- */
7
-
8
- /**
9
- * Create and show the HMR error overlay
10
- * @param {Object} options - Error options
11
- * @param {string} options.framework - The framework name
12
- * @param {string} options.src - The component source path
13
- * @param {Error} options.error - The error that occurred
14
- * @param {string} [options.filePath] - The full file path (if available)
15
- * @param {number} [options.line] - The line number (if available)
16
- * @param {number} [options.column] - The column number (if available)
17
- */
18
- export function showHMRErrorOverlay({ framework, src, error, filePath, line, column }) {
19
- // Remove existing overlay
20
- removeHMRErrorOverlay();
21
-
22
- const overlay = document.createElement('div');
23
- overlay.id = 'avalon-hmr-error-overlay';
24
- overlay.style.cssText = `
25
- position: fixed;
26
- top: 0;
27
- left: 0;
28
- right: 0;
29
- bottom: 0;
30
- background: rgba(0, 0, 0, 0.85);
31
- z-index: 99999;
32
- display: flex;
33
- align-items: center;
34
- justify-content: center;
35
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
36
- backdrop-filter: blur(4px);
37
- `;
38
-
39
- const container = document.createElement('div');
40
- container.style.cssText = `
41
- background: #1a1a2e;
42
- border-radius: 12px;
43
- max-width: 700px;
44
- width: 90%;
45
- max-height: 80vh;
46
- overflow: auto;
47
- box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
48
- border: 1px solid rgba(255, 255, 255, 0.1);
49
- `;
50
-
51
- // Header
52
- const header = document.createElement('div');
53
- header.style.cssText = `
54
- background: linear-gradient(135deg, #e74c3c, #c0392b);
55
- padding: 16px 20px;
56
- display: flex;
57
- align-items: center;
58
- justify-content: space-between;
59
- border-radius: 12px 12px 0 0;
60
- `;
61
-
62
- const title = document.createElement('div');
63
- title.style.cssText = `
64
- display: flex;
65
- align-items: center;
66
- gap: 10px;
67
- color: white;
68
- font-weight: 600;
69
- font-size: 16px;
70
- `;
71
- title.innerHTML = `
72
- <span style="font-size: 20px;">⚠️</span>
73
- <span>HMR Update Failed</span>
74
- `;
75
-
76
- const closeBtn = document.createElement('button');
77
- closeBtn.style.cssText = `
78
- background: rgba(255, 255, 255, 0.2);
79
- border: none;
80
- color: white;
81
- width: 28px;
82
- height: 28px;
83
- border-radius: 6px;
84
- cursor: pointer;
85
- font-size: 18px;
86
- display: flex;
87
- align-items: center;
88
- justify-content: center;
89
- transition: background 0.2s;
90
- `;
91
- closeBtn.textContent = '×';
92
- closeBtn.onmouseover = () => closeBtn.style.background = 'rgba(255, 255, 255, 0.3)';
93
- closeBtn.onmouseout = () => closeBtn.style.background = 'rgba(255, 255, 255, 0.2)';
94
- closeBtn.onclick = removeHMRErrorOverlay;
95
-
96
- header.appendChild(title);
97
- header.appendChild(closeBtn);
98
-
99
- // Content
100
- const content = document.createElement('div');
101
- content.style.cssText = `
102
- padding: 20px;
103
- color: #e0e0e0;
104
- `;
105
-
106
- // File info section
107
- const fileInfo = document.createElement('div');
108
- fileInfo.style.cssText = `
109
- background: rgba(255, 255, 255, 0.05);
110
- border-radius: 8px;
111
- padding: 12px 16px;
112
- margin-bottom: 16px;
113
- font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
114
- font-size: 13px;
115
- `;
116
-
117
- const displayPath = filePath || src;
118
- const locationInfo = line ? `:${line}${column ? `:${column}` : ''}` : '';
119
-
120
- fileInfo.innerHTML = `
121
- <div style="color: #888; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;">
122
- Component
123
- </div>
124
- <div style="color: #61dafb; word-break: break-all;">
125
- ${escapeHtml(displayPath)}${locationInfo}
126
- </div>
127
- <div style="margin-top: 8px; color: #888; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;">
128
- Framework
129
- </div>
130
- <div style="color: #a78bfa;">
131
- ${escapeHtml(framework)}
132
- </div>
133
- `;
134
-
135
- // Error message section
136
- const errorSection = document.createElement('div');
137
- errorSection.style.cssText = `
138
- margin-bottom: 16px;
139
- `;
140
-
141
- const errorLabel = document.createElement('div');
142
- errorLabel.style.cssText = `
143
- color: #888;
144
- font-size: 11px;
145
- text-transform: uppercase;
146
- letter-spacing: 0.5px;
147
- margin-bottom: 8px;
148
- `;
149
- errorLabel.textContent = 'Error Message';
150
-
151
- const errorMessage = document.createElement('div');
152
- errorMessage.style.cssText = `
153
- background: rgba(231, 76, 60, 0.1);
154
- border: 1px solid rgba(231, 76, 60, 0.3);
155
- border-radius: 8px;
156
- padding: 12px 16px;
157
- color: #ff6b6b;
158
- font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
159
- font-size: 13px;
160
- white-space: pre-wrap;
161
- word-break: break-word;
162
- `;
163
- errorMessage.textContent = error.message || String(error);
164
-
165
- errorSection.appendChild(errorLabel);
166
- errorSection.appendChild(errorMessage);
167
-
168
- // Stack trace section (if available)
169
- if (error.stack) {
170
- const stackSection = document.createElement('div');
171
- stackSection.style.cssText = `
172
- margin-bottom: 16px;
173
- `;
174
-
175
- const stackLabel = document.createElement('div');
176
- stackLabel.style.cssText = `
177
- color: #888;
178
- font-size: 11px;
179
- text-transform: uppercase;
180
- letter-spacing: 0.5px;
181
- margin-bottom: 8px;
182
- display: flex;
183
- align-items: center;
184
- justify-content: space-between;
185
- `;
186
-
187
- const stackLabelText = document.createElement('span');
188
- stackLabelText.textContent = 'Stack Trace';
189
-
190
- const toggleBtn = document.createElement('button');
191
- toggleBtn.style.cssText = `
192
- background: rgba(255, 255, 255, 0.1);
193
- border: none;
194
- color: #888;
195
- padding: 4px 8px;
196
- border-radius: 4px;
197
- cursor: pointer;
198
- font-size: 11px;
199
- `;
200
- toggleBtn.textContent = 'Show';
201
-
202
- stackLabel.appendChild(stackLabelText);
203
- stackLabel.appendChild(toggleBtn);
204
-
205
- const stackTrace = document.createElement('div');
206
- stackTrace.style.cssText = `
207
- background: rgba(0, 0, 0, 0.3);
208
- border-radius: 8px;
209
- padding: 12px 16px;
210
- color: #888;
211
- font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
212
- font-size: 11px;
213
- white-space: pre-wrap;
214
- word-break: break-word;
215
- max-height: 200px;
216
- overflow: auto;
217
- display: none;
218
- `;
219
- stackTrace.textContent = formatStackTrace(error.stack);
220
-
221
- toggleBtn.onclick = () => {
222
- const isHidden = stackTrace.style.display === 'none';
223
- stackTrace.style.display = isHidden ? 'block' : 'none';
224
- toggleBtn.textContent = isHidden ? 'Hide' : 'Show';
225
- };
226
-
227
- stackSection.appendChild(stackLabel);
228
- stackSection.appendChild(stackTrace);
229
- content.appendChild(stackSection);
230
- }
231
-
232
- // Suggestions section
233
- const suggestions = getSuggestions(error, framework);
234
- if (suggestions.length > 0) {
235
- const suggestionsSection = document.createElement('div');
236
- suggestionsSection.style.cssText = `
237
- background: rgba(46, 204, 113, 0.1);
238
- border: 1px solid rgba(46, 204, 113, 0.3);
239
- border-radius: 8px;
240
- padding: 12px 16px;
241
- `;
242
-
243
- const suggestionsLabel = document.createElement('div');
244
- suggestionsLabel.style.cssText = `
245
- color: #2ecc71;
246
- font-size: 12px;
247
- font-weight: 600;
248
- margin-bottom: 8px;
249
- display: flex;
250
- align-items: center;
251
- gap: 6px;
252
- `;
253
- suggestionsLabel.innerHTML = '<span>💡</span><span>Suggestions</span>';
254
-
255
- const suggestionsList = document.createElement('ul');
256
- suggestionsList.style.cssText = `
257
- margin: 0;
258
- padding-left: 20px;
259
- color: #a0a0a0;
260
- font-size: 13px;
261
- line-height: 1.6;
262
- `;
263
-
264
- for (const suggestion of suggestions) {
265
- const li = document.createElement('li');
266
- li.textContent = suggestion;
267
- suggestionsList.appendChild(li);
268
- }
269
-
270
- suggestionsSection.appendChild(suggestionsLabel);
271
- suggestionsSection.appendChild(suggestionsList);
272
- content.appendChild(suggestionsSection);
273
- }
274
-
275
- // Footer
276
- const footer = document.createElement('div');
277
- footer.style.cssText = `
278
- padding: 12px 20px;
279
- border-top: 1px solid rgba(255, 255, 255, 0.1);
280
- display: flex;
281
- justify-content: space-between;
282
- align-items: center;
283
- font-size: 12px;
284
- color: #666;
285
- `;
286
-
287
- const timestamp = document.createElement('span');
288
- timestamp.textContent = `${new Date().toLocaleTimeString()}`;
289
-
290
- const actions = document.createElement('div');
291
- actions.style.cssText = `
292
- display: flex;
293
- gap: 8px;
294
- `;
295
-
296
- const reloadBtn = document.createElement('button');
297
- reloadBtn.style.cssText = `
298
- background: #3498db;
299
- border: none;
300
- color: white;
301
- padding: 6px 12px;
302
- border-radius: 6px;
303
- cursor: pointer;
304
- font-size: 12px;
305
- font-weight: 500;
306
- `;
307
- reloadBtn.textContent = 'Reload Page';
308
- reloadBtn.onclick = () => globalThis.location.reload();
309
-
310
- const dismissBtn = document.createElement('button');
311
- dismissBtn.style.cssText = `
312
- background: rgba(255, 255, 255, 0.1);
313
- border: none;
314
- color: #888;
315
- padding: 6px 12px;
316
- border-radius: 6px;
317
- cursor: pointer;
318
- font-size: 12px;
319
- `;
320
- dismissBtn.textContent = 'Dismiss';
321
- dismissBtn.onclick = removeHMRErrorOverlay;
322
-
323
- actions.appendChild(dismissBtn);
324
- actions.appendChild(reloadBtn);
325
-
326
- footer.appendChild(timestamp);
327
- footer.appendChild(actions);
328
-
329
- // Assemble
330
- content.insertBefore(fileInfo, content.firstChild);
331
- content.insertBefore(errorSection, content.children[1]);
332
-
333
- container.appendChild(header);
334
- container.appendChild(content);
335
- container.appendChild(footer);
336
- overlay.appendChild(container);
337
-
338
- // Add keyboard handler
339
- const handleKeydown = (e) => {
340
- if (e.key === 'Escape') {
341
- removeHMRErrorOverlay();
342
- }
343
- };
344
- document.addEventListener('keydown', handleKeydown);
345
- overlay._keydownHandler = handleKeydown;
346
-
347
- document.body.appendChild(overlay);
348
- }
349
-
350
- /**
351
- * Remove the HMR error overlay
352
- */
353
- export function removeHMRErrorOverlay() {
354
- const overlay = document.getElementById('avalon-hmr-error-overlay');
355
- if (overlay) {
356
- if (overlay._keydownHandler) {
357
- document.removeEventListener('keydown', overlay._keydownHandler);
358
- }
359
- overlay.remove();
360
- }
361
- }
362
-
363
- /**
364
- * Escape HTML special characters
365
- * @param {string} str - String to escape
366
- * @returns {string} Escaped string
367
- */
368
- function escapeHtml(str) {
369
- const div = document.createElement('div');
370
- div.textContent = str;
371
- return div.innerHTML;
372
- }
373
-
374
- /**
375
- * Format stack trace for display
376
- * @param {string} stack - Raw stack trace
377
- * @returns {string} Formatted stack trace
378
- */
379
- function formatStackTrace(stack) {
380
- return stack
381
- .split('\n')
382
- .map(line => line.trim())
383
- .filter(line => line.length > 0)
384
- .join('\n');
385
- }
386
-
387
- /**
388
- * Get suggestions based on the error
389
- * @param {Error} error - The error
390
- * @param {string} framework - The framework name
391
- * @returns {string[]} Array of suggestions
392
- */
393
- function getSuggestions(error, framework) {
394
- const suggestions = [];
395
- const message = error.message?.toLowerCase() || '';
396
-
397
- // Common error patterns
398
- if (message.includes('no default export')) {
399
- suggestions.push('Ensure your component has a default export');
400
- suggestions.push('Check that the export statement is correct: export default ComponentName');
401
- }
402
-
403
- if (message.includes('cannot find module') || message.includes('module not found')) {
404
- suggestions.push('Check that the import path is correct');
405
- suggestions.push('Verify the file exists at the specified location');
406
- suggestions.push('Check for typos in the file name or path');
407
- }
408
-
409
- if (message.includes('syntax error') || message.includes('unexpected token')) {
410
- suggestions.push('Check for syntax errors in your component');
411
- suggestions.push('Ensure all brackets and parentheses are properly closed');
412
- }
413
-
414
- if (message.includes('hydration') || message.includes('mismatch')) {
415
- suggestions.push('Ensure server and client render the same initial content');
416
- suggestions.push('Check for browser-only code that runs during SSR');
417
- }
418
-
419
- // Framework-specific suggestions
420
- switch (framework) {
421
- case 'vue':
422
- if (message.includes('template')) {
423
- suggestions.push('Check your Vue template syntax');
424
- }
425
- break;
426
- case 'svelte':
427
- if (message.includes('compile')) {
428
- suggestions.push('Check your Svelte component syntax');
429
- suggestions.push('Ensure reactive statements use $: prefix');
430
- }
431
- break;
432
- case 'solid':
433
- if (message.includes('signal') || message.includes('reactive')) {
434
- suggestions.push('Check your Solid.js signal usage');
435
- }
436
- break;
437
- case 'lit':
438
- if (message.includes('custom element') || message.includes('define')) {
439
- suggestions.push('Ensure your Lit element is properly decorated with @customElement');
440
- }
441
- break;
442
- }
443
-
444
- // Generic suggestions if none matched
445
- if (suggestions.length === 0) {
446
- suggestions.push('Check the browser console for more details');
447
- suggestions.push('Try reloading the page');
448
- }
449
-
450
- return suggestions;
451
- }
452
-
453
- /**
454
- * Show a toast notification for HMR events
455
- * @param {Object} options - Toast options
456
- * @param {string} options.message - The message to display
457
- * @param {string} [options.type='info'] - The type: 'success', 'error', 'info'
458
- * @param {number} [options.duration=3000] - Duration in milliseconds
459
- */
460
- export function showHMRToast({ message, type = 'info', duration = 3000 }) {
461
- // Remove existing toast
462
- const existing = document.getElementById('avalon-hmr-toast');
463
- if (existing) {
464
- existing.remove();
465
- }
466
-
467
- const colors = {
468
- success: { bg: '#2ecc71', icon: '✓' },
469
- error: { bg: '#e74c3c', icon: '✕' },
470
- info: { bg: '#3498db', icon: 'ℹ' },
471
- };
472
-
473
- const { bg, icon } = colors[type] || colors.info;
474
-
475
- const toast = document.createElement('div');
476
- toast.id = 'avalon-hmr-toast';
477
- toast.style.cssText = `
478
- position: fixed;
479
- bottom: 20px;
480
- right: 20px;
481
- background: ${bg};
482
- color: white;
483
- padding: 12px 16px;
484
- border-radius: 8px;
485
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
486
- font-size: 13px;
487
- display: flex;
488
- align-items: center;
489
- gap: 8px;
490
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
491
- z-index: 99998;
492
- animation: slideIn 0.3s ease;
493
- `;
494
-
495
- toast.innerHTML = `
496
- <span style="font-weight: bold;">${icon}</span>
497
- <span>${escapeHtml(message)}</span>
498
- `;
499
-
500
- // Add animation styles
501
- const style = document.createElement('style');
502
- style.textContent = `
503
- @keyframes slideIn {
504
- from {
505
- transform: translateX(100%);
506
- opacity: 0;
507
- }
508
- to {
509
- transform: translateX(0);
510
- opacity: 1;
511
- }
512
- }
513
- @keyframes slideOut {
514
- from {
515
- transform: translateX(0);
516
- opacity: 1;
517
- }
518
- to {
519
- transform: translateX(100%);
520
- opacity: 0;
521
- }
522
- }
523
- `;
524
- toast.appendChild(style);
525
-
526
- document.body.appendChild(toast);
527
-
528
- // Auto-remove after duration
529
- setTimeout(() => {
530
- toast.style.animation = 'slideOut 0.3s ease';
531
- setTimeout(() => toast.remove(), 300);
532
- }, duration);
533
- }
1
+ /**
2
+ * HMR Error Overlay
3
+ *
4
+ * Provides detailed error feedback when HMR fails for island components.
5
+ * Displays file paths, error details, and suggestions for fixing issues.
6
+ */
7
+
8
+ /**
9
+ * Create and show the HMR error overlay
10
+ * @param {Object} options - Error options
11
+ * @param {string} options.framework - The framework name
12
+ * @param {string} options.src - The component source path
13
+ * @param {Error} options.error - The error that occurred
14
+ * @param {string} [options.filePath] - The full file path (if available)
15
+ * @param {number} [options.line] - The line number (if available)
16
+ * @param {number} [options.column] - The column number (if available)
17
+ */
18
+ export function showHMRErrorOverlay({ framework, src, error, filePath, line, column }) {
19
+ // Remove existing overlay
20
+ removeHMRErrorOverlay();
21
+
22
+ const overlay = document.createElement('div');
23
+ overlay.id = 'avalon-hmr-error-overlay';
24
+ overlay.style.cssText = `
25
+ position: fixed;
26
+ top: 0;
27
+ left: 0;
28
+ right: 0;
29
+ bottom: 0;
30
+ background: rgba(0, 0, 0, 0.85);
31
+ z-index: 99999;
32
+ display: flex;
33
+ align-items: center;
34
+ justify-content: center;
35
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
36
+ backdrop-filter: blur(4px);
37
+ `;
38
+
39
+ const container = document.createElement('div');
40
+ container.style.cssText = `
41
+ background: #1a1a2e;
42
+ border-radius: 12px;
43
+ max-width: 700px;
44
+ width: 90%;
45
+ max-height: 80vh;
46
+ overflow: auto;
47
+ box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
48
+ border: 1px solid rgba(255, 255, 255, 0.1);
49
+ `;
50
+
51
+ // Header
52
+ const header = document.createElement('div');
53
+ header.style.cssText = `
54
+ background: linear-gradient(135deg, #e74c3c, #c0392b);
55
+ padding: 16px 20px;
56
+ display: flex;
57
+ align-items: center;
58
+ justify-content: space-between;
59
+ border-radius: 12px 12px 0 0;
60
+ `;
61
+
62
+ const title = document.createElement('div');
63
+ title.style.cssText = `
64
+ display: flex;
65
+ align-items: center;
66
+ gap: 10px;
67
+ color: white;
68
+ font-weight: 600;
69
+ font-size: 16px;
70
+ `;
71
+ title.innerHTML = `
72
+ <span style="font-size: 20px;">⚠️</span>
73
+ <span>HMR Update Failed</span>
74
+ `;
75
+
76
+ const closeBtn = document.createElement('button');
77
+ closeBtn.style.cssText = `
78
+ background: rgba(255, 255, 255, 0.2);
79
+ border: none;
80
+ color: white;
81
+ width: 28px;
82
+ height: 28px;
83
+ border-radius: 6px;
84
+ cursor: pointer;
85
+ font-size: 18px;
86
+ display: flex;
87
+ align-items: center;
88
+ justify-content: center;
89
+ transition: background 0.2s;
90
+ `;
91
+ closeBtn.textContent = '×';
92
+ closeBtn.onmouseover = () => closeBtn.style.background = 'rgba(255, 255, 255, 0.3)';
93
+ closeBtn.onmouseout = () => closeBtn.style.background = 'rgba(255, 255, 255, 0.2)';
94
+ closeBtn.onclick = removeHMRErrorOverlay;
95
+
96
+ header.appendChild(title);
97
+ header.appendChild(closeBtn);
98
+
99
+ // Content
100
+ const content = document.createElement('div');
101
+ content.style.cssText = `
102
+ padding: 20px;
103
+ color: #e0e0e0;
104
+ `;
105
+
106
+ // File info section
107
+ const fileInfo = document.createElement('div');
108
+ fileInfo.style.cssText = `
109
+ background: rgba(255, 255, 255, 0.05);
110
+ border-radius: 8px;
111
+ padding: 12px 16px;
112
+ margin-bottom: 16px;
113
+ font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
114
+ font-size: 13px;
115
+ `;
116
+
117
+ const displayPath = filePath || src;
118
+ const locationInfo = line ? `:${line}${column ? `:${column}` : ''}` : '';
119
+
120
+ fileInfo.innerHTML = `
121
+ <div style="color: #888; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;">
122
+ Component
123
+ </div>
124
+ <div style="color: #61dafb; word-break: break-all;">
125
+ ${escapeHtml(displayPath)}${locationInfo}
126
+ </div>
127
+ <div style="margin-top: 8px; color: #888; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;">
128
+ Framework
129
+ </div>
130
+ <div style="color: #a78bfa;">
131
+ ${escapeHtml(framework)}
132
+ </div>
133
+ `;
134
+
135
+ // Error message section
136
+ const errorSection = document.createElement('div');
137
+ errorSection.style.cssText = `
138
+ margin-bottom: 16px;
139
+ `;
140
+
141
+ const errorLabel = document.createElement('div');
142
+ errorLabel.style.cssText = `
143
+ color: #888;
144
+ font-size: 11px;
145
+ text-transform: uppercase;
146
+ letter-spacing: 0.5px;
147
+ margin-bottom: 8px;
148
+ `;
149
+ errorLabel.textContent = 'Error Message';
150
+
151
+ const errorMessage = document.createElement('div');
152
+ errorMessage.style.cssText = `
153
+ background: rgba(231, 76, 60, 0.1);
154
+ border: 1px solid rgba(231, 76, 60, 0.3);
155
+ border-radius: 8px;
156
+ padding: 12px 16px;
157
+ color: #ff6b6b;
158
+ font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
159
+ font-size: 13px;
160
+ white-space: pre-wrap;
161
+ word-break: break-word;
162
+ `;
163
+ errorMessage.textContent = error.message || String(error);
164
+
165
+ errorSection.appendChild(errorLabel);
166
+ errorSection.appendChild(errorMessage);
167
+
168
+ // Stack trace section (if available)
169
+ if (error.stack) {
170
+ const stackSection = document.createElement('div');
171
+ stackSection.style.cssText = `
172
+ margin-bottom: 16px;
173
+ `;
174
+
175
+ const stackLabel = document.createElement('div');
176
+ stackLabel.style.cssText = `
177
+ color: #888;
178
+ font-size: 11px;
179
+ text-transform: uppercase;
180
+ letter-spacing: 0.5px;
181
+ margin-bottom: 8px;
182
+ display: flex;
183
+ align-items: center;
184
+ justify-content: space-between;
185
+ `;
186
+
187
+ const stackLabelText = document.createElement('span');
188
+ stackLabelText.textContent = 'Stack Trace';
189
+
190
+ const toggleBtn = document.createElement('button');
191
+ toggleBtn.style.cssText = `
192
+ background: rgba(255, 255, 255, 0.1);
193
+ border: none;
194
+ color: #888;
195
+ padding: 4px 8px;
196
+ border-radius: 4px;
197
+ cursor: pointer;
198
+ font-size: 11px;
199
+ `;
200
+ toggleBtn.textContent = 'Show';
201
+
202
+ stackLabel.appendChild(stackLabelText);
203
+ stackLabel.appendChild(toggleBtn);
204
+
205
+ const stackTrace = document.createElement('div');
206
+ stackTrace.style.cssText = `
207
+ background: rgba(0, 0, 0, 0.3);
208
+ border-radius: 8px;
209
+ padding: 12px 16px;
210
+ color: #888;
211
+ font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
212
+ font-size: 11px;
213
+ white-space: pre-wrap;
214
+ word-break: break-word;
215
+ max-height: 200px;
216
+ overflow: auto;
217
+ display: none;
218
+ `;
219
+ stackTrace.textContent = formatStackTrace(error.stack);
220
+
221
+ toggleBtn.onclick = () => {
222
+ const isHidden = stackTrace.style.display === 'none';
223
+ stackTrace.style.display = isHidden ? 'block' : 'none';
224
+ toggleBtn.textContent = isHidden ? 'Hide' : 'Show';
225
+ };
226
+
227
+ stackSection.appendChild(stackLabel);
228
+ stackSection.appendChild(stackTrace);
229
+ content.appendChild(stackSection);
230
+ }
231
+
232
+ // Suggestions section
233
+ const suggestions = getSuggestions(error, framework);
234
+ if (suggestions.length > 0) {
235
+ const suggestionsSection = document.createElement('div');
236
+ suggestionsSection.style.cssText = `
237
+ background: rgba(46, 204, 113, 0.1);
238
+ border: 1px solid rgba(46, 204, 113, 0.3);
239
+ border-radius: 8px;
240
+ padding: 12px 16px;
241
+ `;
242
+
243
+ const suggestionsLabel = document.createElement('div');
244
+ suggestionsLabel.style.cssText = `
245
+ color: #2ecc71;
246
+ font-size: 12px;
247
+ font-weight: 600;
248
+ margin-bottom: 8px;
249
+ display: flex;
250
+ align-items: center;
251
+ gap: 6px;
252
+ `;
253
+ suggestionsLabel.innerHTML = '<span>💡</span><span>Suggestions</span>';
254
+
255
+ const suggestionsList = document.createElement('ul');
256
+ suggestionsList.style.cssText = `
257
+ margin: 0;
258
+ padding-left: 20px;
259
+ color: #a0a0a0;
260
+ font-size: 13px;
261
+ line-height: 1.6;
262
+ `;
263
+
264
+ for (const suggestion of suggestions) {
265
+ const li = document.createElement('li');
266
+ li.textContent = suggestion;
267
+ suggestionsList.appendChild(li);
268
+ }
269
+
270
+ suggestionsSection.appendChild(suggestionsLabel);
271
+ suggestionsSection.appendChild(suggestionsList);
272
+ content.appendChild(suggestionsSection);
273
+ }
274
+
275
+ // Footer
276
+ const footer = document.createElement('div');
277
+ footer.style.cssText = `
278
+ padding: 12px 20px;
279
+ border-top: 1px solid rgba(255, 255, 255, 0.1);
280
+ display: flex;
281
+ justify-content: space-between;
282
+ align-items: center;
283
+ font-size: 12px;
284
+ color: #666;
285
+ `;
286
+
287
+ const timestamp = document.createElement('span');
288
+ timestamp.textContent = `${new Date().toLocaleTimeString()}`;
289
+
290
+ const actions = document.createElement('div');
291
+ actions.style.cssText = `
292
+ display: flex;
293
+ gap: 8px;
294
+ `;
295
+
296
+ const reloadBtn = document.createElement('button');
297
+ reloadBtn.style.cssText = `
298
+ background: #3498db;
299
+ border: none;
300
+ color: white;
301
+ padding: 6px 12px;
302
+ border-radius: 6px;
303
+ cursor: pointer;
304
+ font-size: 12px;
305
+ font-weight: 500;
306
+ `;
307
+ reloadBtn.textContent = 'Reload Page';
308
+ reloadBtn.onclick = () => globalThis.location.reload();
309
+
310
+ const dismissBtn = document.createElement('button');
311
+ dismissBtn.style.cssText = `
312
+ background: rgba(255, 255, 255, 0.1);
313
+ border: none;
314
+ color: #888;
315
+ padding: 6px 12px;
316
+ border-radius: 6px;
317
+ cursor: pointer;
318
+ font-size: 12px;
319
+ `;
320
+ dismissBtn.textContent = 'Dismiss';
321
+ dismissBtn.onclick = removeHMRErrorOverlay;
322
+
323
+ actions.appendChild(dismissBtn);
324
+ actions.appendChild(reloadBtn);
325
+
326
+ footer.appendChild(timestamp);
327
+ footer.appendChild(actions);
328
+
329
+ // Assemble
330
+ content.insertBefore(fileInfo, content.firstChild);
331
+ content.insertBefore(errorSection, content.children[1]);
332
+
333
+ container.appendChild(header);
334
+ container.appendChild(content);
335
+ container.appendChild(footer);
336
+ overlay.appendChild(container);
337
+
338
+ // Add keyboard handler
339
+ const handleKeydown = (e) => {
340
+ if (e.key === 'Escape') {
341
+ removeHMRErrorOverlay();
342
+ }
343
+ };
344
+ document.addEventListener('keydown', handleKeydown);
345
+ overlay._keydownHandler = handleKeydown;
346
+
347
+ document.body.appendChild(overlay);
348
+ }
349
+
350
+ /**
351
+ * Remove the HMR error overlay
352
+ */
353
+ export function removeHMRErrorOverlay() {
354
+ const overlay = document.getElementById('avalon-hmr-error-overlay');
355
+ if (overlay) {
356
+ if (overlay._keydownHandler) {
357
+ document.removeEventListener('keydown', overlay._keydownHandler);
358
+ }
359
+ overlay.remove();
360
+ }
361
+ }
362
+
363
+ /**
364
+ * Escape HTML special characters
365
+ * @param {string} str - String to escape
366
+ * @returns {string} Escaped string
367
+ */
368
+ function escapeHtml(str) {
369
+ const div = document.createElement('div');
370
+ div.textContent = str;
371
+ return div.innerHTML;
372
+ }
373
+
374
+ /**
375
+ * Format stack trace for display
376
+ * @param {string} stack - Raw stack trace
377
+ * @returns {string} Formatted stack trace
378
+ */
379
+ function formatStackTrace(stack) {
380
+ return stack
381
+ .split('\n')
382
+ .map(line => line.trim())
383
+ .filter(line => line.length > 0)
384
+ .join('\n');
385
+ }
386
+
387
+ /**
388
+ * Get suggestions based on the error
389
+ * @param {Error} error - The error
390
+ * @param {string} framework - The framework name
391
+ * @returns {string[]} Array of suggestions
392
+ */
393
+ function getSuggestions(error, framework) {
394
+ const suggestions = [];
395
+ const message = error.message?.toLowerCase() || '';
396
+
397
+ // Common error patterns
398
+ if (message.includes('no default export')) {
399
+ suggestions.push('Ensure your component has a default export');
400
+ suggestions.push('Check that the export statement is correct: export default ComponentName');
401
+ }
402
+
403
+ if (message.includes('cannot find module') || message.includes('module not found')) {
404
+ suggestions.push('Check that the import path is correct');
405
+ suggestions.push('Verify the file exists at the specified location');
406
+ suggestions.push('Check for typos in the file name or path');
407
+ }
408
+
409
+ if (message.includes('syntax error') || message.includes('unexpected token')) {
410
+ suggestions.push('Check for syntax errors in your component');
411
+ suggestions.push('Ensure all brackets and parentheses are properly closed');
412
+ }
413
+
414
+ if (message.includes('hydration') || message.includes('mismatch')) {
415
+ suggestions.push('Ensure server and client render the same initial content');
416
+ suggestions.push('Check for browser-only code that runs during SSR');
417
+ }
418
+
419
+ // Framework-specific suggestions
420
+ switch (framework) {
421
+ case 'vue':
422
+ if (message.includes('template')) {
423
+ suggestions.push('Check your Vue template syntax');
424
+ }
425
+ break;
426
+ case 'svelte':
427
+ if (message.includes('compile')) {
428
+ suggestions.push('Check your Svelte component syntax');
429
+ suggestions.push('Ensure reactive statements use $: prefix');
430
+ }
431
+ break;
432
+ case 'solid':
433
+ if (message.includes('signal') || message.includes('reactive')) {
434
+ suggestions.push('Check your Solid.js signal usage');
435
+ }
436
+ break;
437
+ case 'lit':
438
+ if (message.includes('custom element') || message.includes('define')) {
439
+ suggestions.push('Ensure your Lit element is properly decorated with @customElement');
440
+ }
441
+ break;
442
+ }
443
+
444
+ // Generic suggestions if none matched
445
+ if (suggestions.length === 0) {
446
+ suggestions.push('Check the browser console for more details');
447
+ suggestions.push('Try reloading the page');
448
+ }
449
+
450
+ return suggestions;
451
+ }
452
+
453
+ /**
454
+ * Show a toast notification for HMR events
455
+ * @param {Object} options - Toast options
456
+ * @param {string} options.message - The message to display
457
+ * @param {string} [options.type='info'] - The type: 'success', 'error', 'info'
458
+ * @param {number} [options.duration=3000] - Duration in milliseconds
459
+ */
460
+ export function showHMRToast({ message, type = 'info', duration = 3000 }) {
461
+ // Remove existing toast
462
+ const existing = document.getElementById('avalon-hmr-toast');
463
+ if (existing) {
464
+ existing.remove();
465
+ }
466
+
467
+ const colors = {
468
+ success: { bg: '#2ecc71', icon: '✓' },
469
+ error: { bg: '#e74c3c', icon: '✕' },
470
+ info: { bg: '#3498db', icon: 'ℹ' },
471
+ };
472
+
473
+ const { bg, icon } = colors[type] || colors.info;
474
+
475
+ const toast = document.createElement('div');
476
+ toast.id = 'avalon-hmr-toast';
477
+ toast.style.cssText = `
478
+ position: fixed;
479
+ bottom: 20px;
480
+ right: 20px;
481
+ background: ${bg};
482
+ color: white;
483
+ padding: 12px 16px;
484
+ border-radius: 8px;
485
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
486
+ font-size: 13px;
487
+ display: flex;
488
+ align-items: center;
489
+ gap: 8px;
490
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
491
+ z-index: 99998;
492
+ animation: slideIn 0.3s ease;
493
+ `;
494
+
495
+ toast.innerHTML = `
496
+ <span style="font-weight: bold;">${icon}</span>
497
+ <span>${escapeHtml(message)}</span>
498
+ `;
499
+
500
+ // Add animation styles
501
+ const style = document.createElement('style');
502
+ style.textContent = `
503
+ @keyframes slideIn {
504
+ from {
505
+ transform: translateX(100%);
506
+ opacity: 0;
507
+ }
508
+ to {
509
+ transform: translateX(0);
510
+ opacity: 1;
511
+ }
512
+ }
513
+ @keyframes slideOut {
514
+ from {
515
+ transform: translateX(0);
516
+ opacity: 1;
517
+ }
518
+ to {
519
+ transform: translateX(100%);
520
+ opacity: 0;
521
+ }
522
+ }
523
+ `;
524
+ toast.appendChild(style);
525
+
526
+ document.body.appendChild(toast);
527
+
528
+ // Auto-remove after duration
529
+ setTimeout(() => {
530
+ toast.style.animation = 'slideOut 0.3s ease';
531
+ setTimeout(() => toast.remove(), 300);
532
+ }, duration);
533
+ }