wu-framework 1.1.15 → 1.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -20
- package/dist/wu-framework.cjs.js +1 -1
- package/dist/wu-framework.cjs.js.map +1 -1
- package/dist/wu-framework.dev.js +15511 -15146
- package/dist/wu-framework.dev.js.map +1 -1
- package/dist/wu-framework.esm.js +1 -1
- package/dist/wu-framework.esm.js.map +1 -1
- package/dist/wu-framework.umd.js +1 -1
- package/dist/wu-framework.umd.js.map +1 -1
- package/package.json +166 -161
- package/src/adapters/angular/ai.js +30 -30
- package/src/adapters/angular/index.d.ts +154 -154
- package/src/adapters/angular/index.js +932 -932
- package/src/adapters/angular.d.ts +3 -3
- package/src/adapters/angular.js +3 -3
- package/src/adapters/index.js +168 -168
- package/src/adapters/lit/ai.js +20 -20
- package/src/adapters/lit/index.d.ts +120 -120
- package/src/adapters/lit/index.js +721 -721
- package/src/adapters/lit.d.ts +3 -3
- package/src/adapters/lit.js +3 -3
- package/src/adapters/preact/ai.js +33 -33
- package/src/adapters/preact/index.d.ts +108 -108
- package/src/adapters/preact/index.js +661 -661
- package/src/adapters/preact.d.ts +3 -3
- package/src/adapters/preact.js +3 -3
- package/src/adapters/react/index.js +48 -54
- package/src/adapters/react.d.ts +3 -3
- package/src/adapters/react.js +3 -3
- package/src/adapters/shared.js +64 -64
- package/src/adapters/solid/ai.js +32 -32
- package/src/adapters/solid/index.d.ts +101 -101
- package/src/adapters/solid/index.js +586 -586
- package/src/adapters/solid.d.ts +3 -3
- package/src/adapters/solid.js +3 -3
- package/src/adapters/svelte/ai.js +31 -31
- package/src/adapters/svelte/index.d.ts +166 -166
- package/src/adapters/svelte/index.js +798 -798
- package/src/adapters/svelte.d.ts +3 -3
- package/src/adapters/svelte.js +3 -3
- package/src/adapters/vanilla/ai.js +30 -30
- package/src/adapters/vanilla/index.d.ts +179 -179
- package/src/adapters/vanilla/index.js +785 -785
- package/src/adapters/vanilla.d.ts +3 -3
- package/src/adapters/vanilla.js +3 -3
- package/src/adapters/vue/ai.js +52 -52
- package/src/adapters/vue/index.d.ts +299 -299
- package/src/adapters/vue/index.js +610 -610
- package/src/adapters/vue.d.ts +3 -3
- package/src/adapters/vue.js +3 -3
- package/src/ai/wu-ai-actions.js +261 -261
- package/src/ai/wu-ai-agent.js +546 -546
- package/src/ai/wu-ai-browser-primitives.js +354 -354
- package/src/ai/wu-ai-browser.js +380 -380
- package/src/ai/wu-ai-context.js +332 -332
- package/src/ai/wu-ai-conversation.js +613 -613
- package/src/ai/wu-ai-orchestrate.js +1021 -1021
- package/src/ai/wu-ai-permissions.js +381 -381
- package/src/ai/wu-ai-provider.js +700 -700
- package/src/ai/wu-ai-schema.js +225 -225
- package/src/ai/wu-ai-triggers.js +396 -396
- package/src/ai/wu-ai.js +804 -804
- package/src/core/wu-app.js +236 -236
- package/src/core/wu-cache.js +498 -477
- package/src/core/wu-core.js +1412 -1398
- package/src/core/wu-error-boundary.js +396 -382
- package/src/core/wu-event-bus.js +390 -348
- package/src/core/wu-hooks.js +350 -350
- package/src/core/wu-html-parser.js +199 -190
- package/src/core/wu-iframe-sandbox.js +328 -328
- package/src/core/wu-loader.js +385 -273
- package/src/core/wu-logger.js +142 -134
- package/src/core/wu-manifest.js +532 -509
- package/src/core/wu-mcp-bridge.js +432 -432
- package/src/core/wu-overrides.js +510 -510
- package/src/core/wu-performance.js +228 -228
- package/src/core/wu-plugin.js +401 -348
- package/src/core/wu-prefetch.js +414 -414
- package/src/core/wu-proxy-sandbox.js +477 -476
- package/src/core/wu-sandbox.js +779 -779
- package/src/core/wu-script-executor.js +161 -113
- package/src/core/wu-snapshot-sandbox.js +227 -227
- package/src/core/wu-store.js +13 -3
- package/src/core/wu-strategies.js +256 -256
- package/src/core/wu-style-bridge.js +477 -477
- package/src/index.d.ts +317 -0
- package/src/index.js +234 -224
- package/src/utils/dependency-resolver.js +327 -327
|
@@ -1,190 +1,199 @@
|
|
|
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
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const inlineScripts = [];
|
|
69
|
-
const externalScripts = [];
|
|
70
|
-
const inlineStyles = [];
|
|
71
|
-
const externalStyles = [];
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
inlineScripts, externalScripts,
|
|
75
|
-
inlineStyles, externalStyles,
|
|
76
|
-
baseUrl
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
*
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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 parser = new DOMParser();
|
|
66
|
+
const doc = parser.parseFromString(html, 'text/html');
|
|
67
|
+
|
|
68
|
+
const inlineScripts = [];
|
|
69
|
+
const externalScripts = [];
|
|
70
|
+
const inlineStyles = [];
|
|
71
|
+
const externalStyles = [];
|
|
72
|
+
|
|
73
|
+
const ctx = {
|
|
74
|
+
inlineScripts, externalScripts,
|
|
75
|
+
inlineStyles, externalStyles,
|
|
76
|
+
baseUrl
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// DOMParser moves <style>, <link>, and some <script> tags to <head>.
|
|
80
|
+
// Extract resources from both head and body to capture everything.
|
|
81
|
+
if (doc.head) {
|
|
82
|
+
this._extractResources(doc.head, ctx);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const temp = doc.body || doc.documentElement;
|
|
86
|
+
this._extractResources(temp, ctx);
|
|
87
|
+
|
|
88
|
+
const result = {
|
|
89
|
+
dom: temp.innerHTML,
|
|
90
|
+
scripts: { inline: inlineScripts, external: externalScripts },
|
|
91
|
+
styles: { inline: inlineStyles, external: externalStyles }
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
this._cache.set(cacheKey, result);
|
|
95
|
+
|
|
96
|
+
logger.wuDebug(
|
|
97
|
+
`[HtmlParser] ${appName}: ${inlineScripts.length} inline scripts, ` +
|
|
98
|
+
`${externalScripts.length} external scripts, ` +
|
|
99
|
+
`${inlineStyles.length + externalStyles.length} styles`
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Convenience: fetch + parse in one call.
|
|
107
|
+
*/
|
|
108
|
+
async fetchAndParse(url, appName) {
|
|
109
|
+
const html = await this.fetchHtml(url, appName);
|
|
110
|
+
return this.parse(html, appName, url);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Recursively walk the DOM, extracting scripts and styles,
|
|
115
|
+
* replacing them with comments to keep the DOM clean.
|
|
116
|
+
*/
|
|
117
|
+
_extractResources(element, ctx) {
|
|
118
|
+
// Iterate over a static copy since we mutate the DOM
|
|
119
|
+
const children = Array.from(element.children);
|
|
120
|
+
|
|
121
|
+
for (const child of children) {
|
|
122
|
+
const tag = child.nodeName.toLowerCase();
|
|
123
|
+
|
|
124
|
+
if (tag === 'script') {
|
|
125
|
+
this._extractScript(child, ctx);
|
|
126
|
+
child.replaceWith(document.createComment('wu:script'));
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (tag === 'style') {
|
|
131
|
+
const text = child.textContent?.trim();
|
|
132
|
+
if (text) ctx.inlineStyles.push(text);
|
|
133
|
+
child.replaceWith(document.createComment('wu:style'));
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (tag === 'link') {
|
|
138
|
+
const rel = child.getAttribute('rel');
|
|
139
|
+
const href = child.getAttribute('href');
|
|
140
|
+
if (rel === 'stylesheet' && href) {
|
|
141
|
+
ctx.externalStyles.push(this._resolveUrl(href, ctx.baseUrl));
|
|
142
|
+
child.replaceWith(document.createComment('wu:link'));
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Recurse into children
|
|
148
|
+
if (child.children.length > 0) {
|
|
149
|
+
this._extractResources(child, ctx);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Extract a <script> tag into inline or external list.
|
|
156
|
+
* Skips type="module" scripts (they can't be eval'd — use module mode for those).
|
|
157
|
+
*/
|
|
158
|
+
_extractScript(el, ctx) {
|
|
159
|
+
const type = el.getAttribute('type') || '';
|
|
160
|
+
const src = el.getAttribute('src');
|
|
161
|
+
|
|
162
|
+
// Module scripts can't be executed via new Function / eval.
|
|
163
|
+
// If the app uses ES modules, it should use sandbox: 'module' mode.
|
|
164
|
+
if (type === 'module') {
|
|
165
|
+
logger.wuDebug('[HtmlParser] Skipping type="module" script (use sandbox: "module" for ES modules)');
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (src) {
|
|
170
|
+
ctx.externalScripts.push(this._resolveUrl(src, ctx.baseUrl));
|
|
171
|
+
} else {
|
|
172
|
+
const text = el.textContent?.trim();
|
|
173
|
+
if (text) ctx.inlineScripts.push(text);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Resolve a relative URL against a base URL.
|
|
179
|
+
*/
|
|
180
|
+
_resolveUrl(url, baseUrl) {
|
|
181
|
+
if (url.startsWith('http://') || url.startsWith('https://')) return url;
|
|
182
|
+
if (url.startsWith('//')) return `https:${url}`;
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
return new URL(url, baseUrl).href;
|
|
186
|
+
} catch {
|
|
187
|
+
// Fallback for environments without URL constructor
|
|
188
|
+
const base = baseUrl.replace(/\/$/, '');
|
|
189
|
+
return url.startsWith('/') ? base + url : `${base}/${url}`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Clear the parse cache.
|
|
195
|
+
*/
|
|
196
|
+
clearCache() {
|
|
197
|
+
this._cache.clear();
|
|
198
|
+
}
|
|
199
|
+
}
|