wu-framework 1.1.14 → 1.1.16

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 (90) hide show
  1. package/LICENSE +39 -39
  2. package/README.md +408 -408
  3. package/dist/wu-framework.cjs.js.map +1 -1
  4. package/dist/wu-framework.dev.js +15151 -15151
  5. package/dist/wu-framework.dev.js.map +1 -1
  6. package/dist/wu-framework.esm.js.map +1 -1
  7. package/dist/wu-framework.umd.js.map +1 -1
  8. package/integrations/astro/README.md +127 -127
  9. package/integrations/astro/WuApp.astro +63 -63
  10. package/integrations/astro/WuShell.astro +39 -39
  11. package/integrations/astro/index.js +68 -68
  12. package/integrations/astro/package.json +38 -38
  13. package/integrations/astro/types.d.ts +53 -53
  14. package/package.json +161 -161
  15. package/src/adapters/angular/ai.js +30 -30
  16. package/src/adapters/angular/index.d.ts +154 -154
  17. package/src/adapters/angular/index.js +932 -932
  18. package/src/adapters/angular.d.ts +3 -3
  19. package/src/adapters/angular.js +3 -3
  20. package/src/adapters/index.js +168 -168
  21. package/src/adapters/lit/ai.js +20 -20
  22. package/src/adapters/lit/index.d.ts +120 -120
  23. package/src/adapters/lit/index.js +721 -721
  24. package/src/adapters/lit.d.ts +3 -3
  25. package/src/adapters/lit.js +3 -3
  26. package/src/adapters/preact/ai.js +33 -33
  27. package/src/adapters/preact/index.d.ts +108 -108
  28. package/src/adapters/preact/index.js +661 -661
  29. package/src/adapters/preact.d.ts +3 -3
  30. package/src/adapters/preact.js +3 -3
  31. package/src/adapters/react/index.js +48 -54
  32. package/src/adapters/react.d.ts +3 -3
  33. package/src/adapters/react.js +3 -3
  34. package/src/adapters/shared.js +64 -64
  35. package/src/adapters/solid/ai.js +32 -32
  36. package/src/adapters/solid/index.d.ts +101 -101
  37. package/src/adapters/solid/index.js +586 -586
  38. package/src/adapters/solid.d.ts +3 -3
  39. package/src/adapters/solid.js +3 -3
  40. package/src/adapters/svelte/ai.js +31 -31
  41. package/src/adapters/svelte/index.d.ts +166 -166
  42. package/src/adapters/svelte/index.js +798 -798
  43. package/src/adapters/svelte.d.ts +3 -3
  44. package/src/adapters/svelte.js +3 -3
  45. package/src/adapters/vanilla/ai.js +30 -30
  46. package/src/adapters/vanilla/index.d.ts +179 -179
  47. package/src/adapters/vanilla/index.js +785 -785
  48. package/src/adapters/vanilla.d.ts +3 -3
  49. package/src/adapters/vanilla.js +3 -3
  50. package/src/adapters/vue/ai.js +52 -52
  51. package/src/adapters/vue/index.d.ts +299 -299
  52. package/src/adapters/vue/index.js +610 -610
  53. package/src/adapters/vue.d.ts +3 -3
  54. package/src/adapters/vue.js +3 -3
  55. package/src/ai/wu-ai-actions.js +261 -261
  56. package/src/ai/wu-ai-agent.js +546 -546
  57. package/src/ai/wu-ai-browser-primitives.js +354 -354
  58. package/src/ai/wu-ai-browser.js +380 -380
  59. package/src/ai/wu-ai-context.js +332 -332
  60. package/src/ai/wu-ai-conversation.js +613 -613
  61. package/src/ai/wu-ai-orchestrate.js +1021 -1021
  62. package/src/ai/wu-ai-permissions.js +381 -381
  63. package/src/ai/wu-ai-provider.js +700 -700
  64. package/src/ai/wu-ai-schema.js +225 -225
  65. package/src/ai/wu-ai-triggers.js +396 -396
  66. package/src/ai/wu-ai.js +804 -804
  67. package/src/core/wu-app.js +236 -236
  68. package/src/core/wu-cache.js +477 -477
  69. package/src/core/wu-core.js +1398 -1398
  70. package/src/core/wu-error-boundary.js +382 -382
  71. package/src/core/wu-event-bus.js +348 -348
  72. package/src/core/wu-hooks.js +350 -350
  73. package/src/core/wu-html-parser.js +190 -190
  74. package/src/core/wu-iframe-sandbox.js +328 -328
  75. package/src/core/wu-loader.js +272 -272
  76. package/src/core/wu-logger.js +134 -134
  77. package/src/core/wu-manifest.js +509 -509
  78. package/src/core/wu-mcp-bridge.js +432 -432
  79. package/src/core/wu-overrides.js +510 -510
  80. package/src/core/wu-performance.js +228 -228
  81. package/src/core/wu-plugin.js +348 -348
  82. package/src/core/wu-prefetch.js +414 -414
  83. package/src/core/wu-proxy-sandbox.js +476 -476
  84. package/src/core/wu-sandbox.js +779 -779
  85. package/src/core/wu-script-executor.js +113 -113
  86. package/src/core/wu-snapshot-sandbox.js +227 -227
  87. package/src/core/wu-strategies.js +256 -256
  88. package/src/core/wu-style-bridge.js +477 -477
  89. package/src/index.js +224 -224
  90. package/src/utils/dependency-resolver.js +327 -327
@@ -1,190 +1,190 @@
1
- /**
2
- * WU-HTML-PARSER: Fetch and parse HTML entries from micro-apps.
3
- *
4
- * Used in "strict" sandbox mode. The flow:
5
- * 1. Fetch the HTML page at the app's URL
6
- * 2. Parse it: extract inline/external scripts, inline/external styles, and clean DOM
7
- * 3. Return structured result so wu-core can inject DOM + styles into Shadow DOM
8
- * and execute scripts inside the proxy sandbox via WuScriptExecutor.
9
- *
10
- * This is the qiankun-style "HTML entry" approach that enables real JS isolation.
11
- */
12
-
13
- import { logger } from './wu-logger.js';
14
-
15
- export class WuHtmlParser {
16
- constructor() {
17
- this._cache = new Map();
18
- }
19
-
20
- /**
21
- * Fetch HTML content from a URL.
22
- * @param {string} url - App URL (e.g. http://localhost:3001)
23
- * @param {string} appName - For logging
24
- * @returns {Promise<string>} Raw HTML string
25
- */
26
- async fetchHtml(url, appName) {
27
- logger.wuDebug(`[HtmlParser] Fetching HTML for ${appName} from ${url}`);
28
-
29
- const response = await fetch(url, {
30
- method: 'GET',
31
- headers: { 'Accept': 'text/html,application/xhtml+xml,*/*' }
32
- });
33
-
34
- if (!response.ok) {
35
- throw new Error(`[HtmlParser] Failed to fetch ${url}: HTTP ${response.status}`);
36
- }
37
-
38
- const html = await response.text();
39
- if (!html || !html.trim()) {
40
- throw new Error(`[HtmlParser] Empty HTML response from ${url}`);
41
- }
42
-
43
- logger.wuDebug(`[HtmlParser] Fetched ${html.length} chars for ${appName}`);
44
- return html;
45
- }
46
-
47
- /**
48
- * Parse HTML string into structured parts.
49
- *
50
- * @param {string} html - Raw HTML
51
- * @param {string} appName - App identifier
52
- * @param {string} baseUrl - Base URL for resolving relative paths
53
- * @returns {{
54
- * dom: string,
55
- * scripts: { inline: string[], external: string[] },
56
- * styles: { inline: string[], external: string[] }
57
- * }}
58
- */
59
- parse(html, appName, baseUrl) {
60
- const cacheKey = `${appName}:${html.length}`;
61
- if (this._cache.has(cacheKey)) {
62
- return this._cache.get(cacheKey);
63
- }
64
-
65
- const temp = document.createElement('div');
66
- temp.innerHTML = html;
67
-
68
- const inlineScripts = [];
69
- const externalScripts = [];
70
- const inlineStyles = [];
71
- const externalStyles = [];
72
-
73
- this._extractResources(temp, {
74
- inlineScripts, externalScripts,
75
- inlineStyles, externalStyles,
76
- baseUrl
77
- });
78
-
79
- const result = {
80
- dom: temp.innerHTML,
81
- scripts: { inline: inlineScripts, external: externalScripts },
82
- styles: { inline: inlineStyles, external: externalStyles }
83
- };
84
-
85
- this._cache.set(cacheKey, result);
86
-
87
- logger.wuDebug(
88
- `[HtmlParser] ${appName}: ${inlineScripts.length} inline scripts, ` +
89
- `${externalScripts.length} external scripts, ` +
90
- `${inlineStyles.length + externalStyles.length} styles`
91
- );
92
-
93
- return result;
94
- }
95
-
96
- /**
97
- * Convenience: fetch + parse in one call.
98
- */
99
- async fetchAndParse(url, appName) {
100
- const html = await this.fetchHtml(url, appName);
101
- return this.parse(html, appName, url);
102
- }
103
-
104
- /**
105
- * Recursively walk the DOM, extracting scripts and styles,
106
- * replacing them with comments to keep the DOM clean.
107
- */
108
- _extractResources(element, ctx) {
109
- // Iterate over a static copy since we mutate the DOM
110
- const children = Array.from(element.children);
111
-
112
- for (const child of children) {
113
- const tag = child.nodeName.toLowerCase();
114
-
115
- if (tag === 'script') {
116
- this._extractScript(child, ctx);
117
- child.replaceWith(document.createComment('wu:script'));
118
- continue;
119
- }
120
-
121
- if (tag === 'style') {
122
- const text = child.textContent?.trim();
123
- if (text) ctx.inlineStyles.push(text);
124
- child.replaceWith(document.createComment('wu:style'));
125
- continue;
126
- }
127
-
128
- if (tag === 'link') {
129
- const rel = child.getAttribute('rel');
130
- const href = child.getAttribute('href');
131
- if (rel === 'stylesheet' && href) {
132
- ctx.externalStyles.push(this._resolveUrl(href, ctx.baseUrl));
133
- child.replaceWith(document.createComment('wu:link'));
134
- continue;
135
- }
136
- }
137
-
138
- // Recurse into children
139
- if (child.children.length > 0) {
140
- this._extractResources(child, ctx);
141
- }
142
- }
143
- }
144
-
145
- /**
146
- * Extract a <script> tag into inline or external list.
147
- * Skips type="module" scripts (they can't be eval'd — use module mode for those).
148
- */
149
- _extractScript(el, ctx) {
150
- const type = el.getAttribute('type') || '';
151
- const src = el.getAttribute('src');
152
-
153
- // Module scripts can't be executed via new Function / eval.
154
- // If the app uses ES modules, it should use sandbox: 'module' mode.
155
- if (type === 'module') {
156
- logger.wuDebug('[HtmlParser] Skipping type="module" script (use sandbox: "module" for ES modules)');
157
- return;
158
- }
159
-
160
- if (src) {
161
- ctx.externalScripts.push(this._resolveUrl(src, ctx.baseUrl));
162
- } else {
163
- const text = el.textContent?.trim();
164
- if (text) ctx.inlineScripts.push(text);
165
- }
166
- }
167
-
168
- /**
169
- * Resolve a relative URL against a base URL.
170
- */
171
- _resolveUrl(url, baseUrl) {
172
- if (url.startsWith('http://') || url.startsWith('https://')) return url;
173
- if (url.startsWith('//')) return `https:${url}`;
174
-
175
- try {
176
- return new URL(url, baseUrl).href;
177
- } catch {
178
- // Fallback for environments without URL constructor
179
- const base = baseUrl.replace(/\/$/, '');
180
- return url.startsWith('/') ? base + url : `${base}/${url}`;
181
- }
182
- }
183
-
184
- /**
185
- * Clear the parse cache.
186
- */
187
- clearCache() {
188
- this._cache.clear();
189
- }
190
- }
1
+ /**
2
+ * WU-HTML-PARSER: Fetch and parse HTML entries from micro-apps.
3
+ *
4
+ * Used in "strict" sandbox mode. The flow:
5
+ * 1. Fetch the HTML page at the app's URL
6
+ * 2. Parse it: extract inline/external scripts, inline/external styles, and clean DOM
7
+ * 3. Return structured result so wu-core can inject DOM + styles into Shadow DOM
8
+ * and execute scripts inside the proxy sandbox via WuScriptExecutor.
9
+ *
10
+ * This is the qiankun-style "HTML entry" approach that enables real JS isolation.
11
+ */
12
+
13
+ import { logger } from './wu-logger.js';
14
+
15
+ export class WuHtmlParser {
16
+ constructor() {
17
+ this._cache = new Map();
18
+ }
19
+
20
+ /**
21
+ * Fetch HTML content from a URL.
22
+ * @param {string} url - App URL (e.g. http://localhost:3001)
23
+ * @param {string} appName - For logging
24
+ * @returns {Promise<string>} Raw HTML string
25
+ */
26
+ async fetchHtml(url, appName) {
27
+ logger.wuDebug(`[HtmlParser] Fetching HTML for ${appName} from ${url}`);
28
+
29
+ const response = await fetch(url, {
30
+ method: 'GET',
31
+ headers: { 'Accept': 'text/html,application/xhtml+xml,*/*' }
32
+ });
33
+
34
+ if (!response.ok) {
35
+ throw new Error(`[HtmlParser] Failed to fetch ${url}: HTTP ${response.status}`);
36
+ }
37
+
38
+ const html = await response.text();
39
+ if (!html || !html.trim()) {
40
+ throw new Error(`[HtmlParser] Empty HTML response from ${url}`);
41
+ }
42
+
43
+ logger.wuDebug(`[HtmlParser] Fetched ${html.length} chars for ${appName}`);
44
+ return html;
45
+ }
46
+
47
+ /**
48
+ * Parse HTML string into structured parts.
49
+ *
50
+ * @param {string} html - Raw HTML
51
+ * @param {string} appName - App identifier
52
+ * @param {string} baseUrl - Base URL for resolving relative paths
53
+ * @returns {{
54
+ * dom: string,
55
+ * scripts: { inline: string[], external: string[] },
56
+ * styles: { inline: string[], external: string[] }
57
+ * }}
58
+ */
59
+ parse(html, appName, baseUrl) {
60
+ const cacheKey = `${appName}:${html.length}`;
61
+ if (this._cache.has(cacheKey)) {
62
+ return this._cache.get(cacheKey);
63
+ }
64
+
65
+ const temp = document.createElement('div');
66
+ temp.innerHTML = html;
67
+
68
+ const inlineScripts = [];
69
+ const externalScripts = [];
70
+ const inlineStyles = [];
71
+ const externalStyles = [];
72
+
73
+ this._extractResources(temp, {
74
+ inlineScripts, externalScripts,
75
+ inlineStyles, externalStyles,
76
+ baseUrl
77
+ });
78
+
79
+ const result = {
80
+ dom: temp.innerHTML,
81
+ scripts: { inline: inlineScripts, external: externalScripts },
82
+ styles: { inline: inlineStyles, external: externalStyles }
83
+ };
84
+
85
+ this._cache.set(cacheKey, result);
86
+
87
+ logger.wuDebug(
88
+ `[HtmlParser] ${appName}: ${inlineScripts.length} inline scripts, ` +
89
+ `${externalScripts.length} external scripts, ` +
90
+ `${inlineStyles.length + externalStyles.length} styles`
91
+ );
92
+
93
+ return result;
94
+ }
95
+
96
+ /**
97
+ * Convenience: fetch + parse in one call.
98
+ */
99
+ async fetchAndParse(url, appName) {
100
+ const html = await this.fetchHtml(url, appName);
101
+ return this.parse(html, appName, url);
102
+ }
103
+
104
+ /**
105
+ * Recursively walk the DOM, extracting scripts and styles,
106
+ * replacing them with comments to keep the DOM clean.
107
+ */
108
+ _extractResources(element, ctx) {
109
+ // Iterate over a static copy since we mutate the DOM
110
+ const children = Array.from(element.children);
111
+
112
+ for (const child of children) {
113
+ const tag = child.nodeName.toLowerCase();
114
+
115
+ if (tag === 'script') {
116
+ this._extractScript(child, ctx);
117
+ child.replaceWith(document.createComment('wu:script'));
118
+ continue;
119
+ }
120
+
121
+ if (tag === 'style') {
122
+ const text = child.textContent?.trim();
123
+ if (text) ctx.inlineStyles.push(text);
124
+ child.replaceWith(document.createComment('wu:style'));
125
+ continue;
126
+ }
127
+
128
+ if (tag === 'link') {
129
+ const rel = child.getAttribute('rel');
130
+ const href = child.getAttribute('href');
131
+ if (rel === 'stylesheet' && href) {
132
+ ctx.externalStyles.push(this._resolveUrl(href, ctx.baseUrl));
133
+ child.replaceWith(document.createComment('wu:link'));
134
+ continue;
135
+ }
136
+ }
137
+
138
+ // Recurse into children
139
+ if (child.children.length > 0) {
140
+ this._extractResources(child, ctx);
141
+ }
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Extract a <script> tag into inline or external list.
147
+ * Skips type="module" scripts (they can't be eval'd — use module mode for those).
148
+ */
149
+ _extractScript(el, ctx) {
150
+ const type = el.getAttribute('type') || '';
151
+ const src = el.getAttribute('src');
152
+
153
+ // Module scripts can't be executed via new Function / eval.
154
+ // If the app uses ES modules, it should use sandbox: 'module' mode.
155
+ if (type === 'module') {
156
+ logger.wuDebug('[HtmlParser] Skipping type="module" script (use sandbox: "module" for ES modules)');
157
+ return;
158
+ }
159
+
160
+ if (src) {
161
+ ctx.externalScripts.push(this._resolveUrl(src, ctx.baseUrl));
162
+ } else {
163
+ const text = el.textContent?.trim();
164
+ if (text) ctx.inlineScripts.push(text);
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Resolve a relative URL against a base URL.
170
+ */
171
+ _resolveUrl(url, baseUrl) {
172
+ if (url.startsWith('http://') || url.startsWith('https://')) return url;
173
+ if (url.startsWith('//')) return `https:${url}`;
174
+
175
+ try {
176
+ return new URL(url, baseUrl).href;
177
+ } catch {
178
+ // Fallback for environments without URL constructor
179
+ const base = baseUrl.replace(/\/$/, '');
180
+ return url.startsWith('/') ? base + url : `${base}/${url}`;
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Clear the parse cache.
186
+ */
187
+ clearCache() {
188
+ this._cache.clear();
189
+ }
190
+ }