@useavalon/avalon 0.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 (159) hide show
  1. package/README.md +54 -0
  2. package/mod.ts +301 -0
  3. package/package.json +85 -0
  4. package/src/build/README.md +310 -0
  5. package/src/build/integration-bundler-plugin.ts +116 -0
  6. package/src/build/integration-config.ts +168 -0
  7. package/src/build/integration-detection-plugin.ts +117 -0
  8. package/src/build/integration-resolver-plugin.ts +90 -0
  9. package/src/build/island-manifest.ts +269 -0
  10. package/src/build/island-types-generator.ts +476 -0
  11. package/src/build/mdx-island-transform.ts +464 -0
  12. package/src/build/mdx-plugin.ts +98 -0
  13. package/src/build/page-island-transform.ts +598 -0
  14. package/src/build/prop-extractors/index.ts +21 -0
  15. package/src/build/prop-extractors/lit.ts +140 -0
  16. package/src/build/prop-extractors/qwik.ts +16 -0
  17. package/src/build/prop-extractors/solid.ts +125 -0
  18. package/src/build/prop-extractors/svelte.ts +194 -0
  19. package/src/build/prop-extractors/vue.ts +111 -0
  20. package/src/build/sidecar-file-manager.ts +104 -0
  21. package/src/build/sidecar-renderer.ts +30 -0
  22. package/src/client/adapters/index.ts +13 -0
  23. package/src/client/adapters/lit-adapter.ts +654 -0
  24. package/src/client/adapters/preact-adapter.ts +331 -0
  25. package/src/client/adapters/qwik-adapter.ts +345 -0
  26. package/src/client/adapters/react-adapter.ts +353 -0
  27. package/src/client/adapters/solid-adapter.ts +451 -0
  28. package/src/client/adapters/svelte-adapter.ts +524 -0
  29. package/src/client/adapters/vue-adapter.ts +467 -0
  30. package/src/client/components.ts +35 -0
  31. package/src/client/css-hmr-handler.ts +344 -0
  32. package/src/client/framework-adapter.ts +462 -0
  33. package/src/client/hmr-coordinator.ts +396 -0
  34. package/src/client/hmr-error-overlay.js +533 -0
  35. package/src/client/main.js +816 -0
  36. package/src/client/tests/css-hmr-handler.test.ts +360 -0
  37. package/src/client/tests/framework-adapter.test.ts +519 -0
  38. package/src/client/tests/hmr-coordinator.test.ts +176 -0
  39. package/src/client/tests/hydration-option-parsing.test.ts +107 -0
  40. package/src/client/tests/lit-adapter.test.ts +427 -0
  41. package/src/client/tests/preact-adapter.test.ts +353 -0
  42. package/src/client/tests/qwik-adapter.test.ts +343 -0
  43. package/src/client/tests/react-adapter.test.ts +317 -0
  44. package/src/client/tests/solid-adapter.test.ts +396 -0
  45. package/src/client/tests/svelte-adapter.test.ts +387 -0
  46. package/src/client/tests/vue-adapter.test.ts +407 -0
  47. package/src/client/types/framework-runtime.d.ts +68 -0
  48. package/src/client/types/vite-hmr.d.ts +46 -0
  49. package/src/client/types/vite-virtual-modules.d.ts +60 -0
  50. package/src/components/Image.tsx +123 -0
  51. package/src/components/IslandErrorBoundary.tsx +145 -0
  52. package/src/components/LayoutDataErrorBoundary.tsx +141 -0
  53. package/src/components/LayoutErrorBoundary.tsx +127 -0
  54. package/src/components/PersistentIsland.tsx +52 -0
  55. package/src/components/StreamingErrorBoundary.tsx +233 -0
  56. package/src/components/StreamingLayout.tsx +538 -0
  57. package/src/components/tests/component-analyzer.test.ts +96 -0
  58. package/src/components/tests/component-detection.test.ts +347 -0
  59. package/src/components/tests/persistent-islands.test.ts +398 -0
  60. package/src/core/components/component-analyzer.ts +192 -0
  61. package/src/core/components/component-detection.ts +508 -0
  62. package/src/core/components/enhanced-framework-detector.ts +500 -0
  63. package/src/core/components/framework-registry.ts +563 -0
  64. package/src/core/components/tests/enhanced-framework-detector.test.ts +577 -0
  65. package/src/core/components/tests/framework-registry.test.ts +465 -0
  66. package/src/core/content/mdx-processor.ts +46 -0
  67. package/src/core/integrations/README.md +282 -0
  68. package/src/core/integrations/index.ts +19 -0
  69. package/src/core/integrations/loader.ts +125 -0
  70. package/src/core/integrations/registry.ts +195 -0
  71. package/src/core/islands/island-persistence.ts +325 -0
  72. package/src/core/islands/island-state-serializer.ts +258 -0
  73. package/src/core/islands/persistent-island-context.tsx +80 -0
  74. package/src/core/islands/use-persistent-state.ts +68 -0
  75. package/src/core/layout/enhanced-layout-resolver.ts +322 -0
  76. package/src/core/layout/layout-cache-manager.ts +485 -0
  77. package/src/core/layout/layout-composer.ts +357 -0
  78. package/src/core/layout/layout-data-loader.ts +516 -0
  79. package/src/core/layout/layout-discovery.ts +243 -0
  80. package/src/core/layout/layout-matcher.ts +299 -0
  81. package/src/core/layout/layout-types.ts +110 -0
  82. package/src/core/layout/tests/enhanced-layout-resolver.test.ts +477 -0
  83. package/src/core/layout/tests/layout-cache-optimization.test.ts +149 -0
  84. package/src/core/layout/tests/layout-composer.test.ts +486 -0
  85. package/src/core/layout/tests/layout-data-loader.test.ts +443 -0
  86. package/src/core/layout/tests/layout-discovery.test.ts +253 -0
  87. package/src/core/layout/tests/layout-matcher.test.ts +480 -0
  88. package/src/core/modules/framework-module-resolver.ts +273 -0
  89. package/src/core/modules/tests/framework-module-resolver.test.ts +263 -0
  90. package/src/core/modules/tests/module-resolution-integration.test.ts +117 -0
  91. package/src/islands/component-analysis.ts +213 -0
  92. package/src/islands/css-utils.ts +565 -0
  93. package/src/islands/discovery/index.ts +80 -0
  94. package/src/islands/discovery/registry.ts +340 -0
  95. package/src/islands/discovery/resolver.ts +477 -0
  96. package/src/islands/discovery/scanner.ts +386 -0
  97. package/src/islands/discovery/tests/island-discovery.test.ts +881 -0
  98. package/src/islands/discovery/types.ts +117 -0
  99. package/src/islands/discovery/validator.ts +544 -0
  100. package/src/islands/discovery/watcher.ts +368 -0
  101. package/src/islands/framework-detection.ts +428 -0
  102. package/src/islands/integration-loader.ts +490 -0
  103. package/src/islands/island.tsx +565 -0
  104. package/src/islands/render-cache.ts +550 -0
  105. package/src/islands/types.ts +80 -0
  106. package/src/islands/universal-css-collector.ts +157 -0
  107. package/src/islands/universal-head-collector.ts +137 -0
  108. package/src/layout-system.d.ts +592 -0
  109. package/src/layout-system.ts +218 -0
  110. package/src/middleware/__tests__/discovery.test.ts +107 -0
  111. package/src/middleware/discovery.ts +268 -0
  112. package/src/middleware/executor.ts +315 -0
  113. package/src/middleware/index.ts +76 -0
  114. package/src/middleware/types.ts +99 -0
  115. package/src/nitro/build-config.ts +576 -0
  116. package/src/nitro/config.ts +483 -0
  117. package/src/nitro/error-handler.ts +636 -0
  118. package/src/nitro/index.ts +173 -0
  119. package/src/nitro/island-manifest.ts +584 -0
  120. package/src/nitro/middleware-adapter.ts +260 -0
  121. package/src/nitro/renderer.ts +1458 -0
  122. package/src/nitro/route-discovery.ts +439 -0
  123. package/src/nitro/types.ts +321 -0
  124. package/src/render/collect-css.ts +198 -0
  125. package/src/render/error-pages.ts +79 -0
  126. package/src/render/isolated-ssr-renderer.ts +654 -0
  127. package/src/render/ssr.ts +1030 -0
  128. package/src/schemas/api.ts +30 -0
  129. package/src/schemas/core.ts +64 -0
  130. package/src/schemas/index.ts +212 -0
  131. package/src/schemas/layout.ts +279 -0
  132. package/src/schemas/routing/index.ts +38 -0
  133. package/src/schemas/routing.ts +376 -0
  134. package/src/types/as-island.ts +20 -0
  135. package/src/types/image.d.ts +106 -0
  136. package/src/types/index.d.ts +22 -0
  137. package/src/types/island-jsx.d.ts +33 -0
  138. package/src/types/island-prop.d.ts +20 -0
  139. package/src/types/layout.ts +285 -0
  140. package/src/types/mdx.d.ts +6 -0
  141. package/src/types/routing.ts +555 -0
  142. package/src/types/tests/layout-types.test.ts +197 -0
  143. package/src/types/types.ts +5 -0
  144. package/src/types/urlpattern.d.ts +49 -0
  145. package/src/types/vite-env.d.ts +11 -0
  146. package/src/utils/dev-logger.ts +299 -0
  147. package/src/utils/fs.ts +151 -0
  148. package/src/vite-plugin/auto-discover.ts +551 -0
  149. package/src/vite-plugin/config.ts +266 -0
  150. package/src/vite-plugin/errors.ts +127 -0
  151. package/src/vite-plugin/image-optimization.ts +151 -0
  152. package/src/vite-plugin/integration-activator.ts +126 -0
  153. package/src/vite-plugin/island-sidecar-plugin.ts +176 -0
  154. package/src/vite-plugin/module-discovery.ts +189 -0
  155. package/src/vite-plugin/nitro-integration.ts +1334 -0
  156. package/src/vite-plugin/plugin.ts +329 -0
  157. package/src/vite-plugin/tests/image-optimization.test.ts +54 -0
  158. package/src/vite-plugin/types.ts +327 -0
  159. package/src/vite-plugin/validation.ts +228 -0
@@ -0,0 +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
+ }