@meituan-nocode/vite-plugin-nocode-compiler 0.3.0 → 0.3.1-beta.1
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/dist/index.cjs +356 -88
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +346 -88
- package/package.json +8 -7
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -24,32 +34,13 @@ __export(index_exports, {
|
|
|
24
34
|
default: () => index_default
|
|
25
35
|
});
|
|
26
36
|
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
var import_path = require("path");
|
|
28
|
-
var import_fs = require("fs");
|
|
29
37
|
var import_nocode_compiler_core = require("@meituan-nocode/nocode-compiler-core");
|
|
30
38
|
|
|
31
|
-
// src/utils.ts
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
let body = "";
|
|
35
|
-
req.on("data", (chunk) => {
|
|
36
|
-
body += chunk.toString();
|
|
37
|
-
});
|
|
38
|
-
req.on("end", () => {
|
|
39
|
-
try {
|
|
40
|
-
resolve(JSON.parse(body));
|
|
41
|
-
} catch (e) {
|
|
42
|
-
reject(e);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
req.on("error", reject);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// package.json
|
|
50
|
-
var version = "0.3.0";
|
|
39
|
+
// src/utils/index.ts
|
|
40
|
+
var import_path = require("path");
|
|
41
|
+
var import_fs = require("fs");
|
|
51
42
|
|
|
52
|
-
// src/
|
|
43
|
+
// src/utils/vite-compat.ts
|
|
53
44
|
function getHotChannel(server) {
|
|
54
45
|
try {
|
|
55
46
|
if (server.hot && typeof server.hot.on === "function") {
|
|
@@ -71,7 +62,7 @@ function safeOnConnection(server, callback) {
|
|
|
71
62
|
channel.on("connection", callback);
|
|
72
63
|
return true;
|
|
73
64
|
} catch (e) {
|
|
74
|
-
console.warn("[
|
|
65
|
+
console.warn("[vite-compat] Error setting up connection listener:", e);
|
|
75
66
|
return false;
|
|
76
67
|
}
|
|
77
68
|
}
|
|
@@ -84,7 +75,7 @@ function safeSendHmrUpdate(server, payload) {
|
|
|
84
75
|
channel.send(payload);
|
|
85
76
|
return true;
|
|
86
77
|
} catch (e) {
|
|
87
|
-
console.warn("[
|
|
78
|
+
console.warn("[vite-compat] Error sending HMR update:", e);
|
|
88
79
|
return false;
|
|
89
80
|
}
|
|
90
81
|
}
|
|
@@ -95,7 +86,7 @@ function safeInvalidateModule(server, mod) {
|
|
|
95
86
|
return true;
|
|
96
87
|
}
|
|
97
88
|
} catch (e) {
|
|
98
|
-
console.warn("[
|
|
89
|
+
console.warn("[vite-compat] Error invalidating module:", e);
|
|
99
90
|
}
|
|
100
91
|
return false;
|
|
101
92
|
}
|
|
@@ -105,20 +96,59 @@ function safeGetModulesByFile(server, filePath) {
|
|
|
105
96
|
return server.moduleGraph.getModulesByFile(filePath) || null;
|
|
106
97
|
}
|
|
107
98
|
} catch (e) {
|
|
108
|
-
console.warn("[
|
|
99
|
+
console.warn("[vite-compat] Error getting modules by file:", e);
|
|
109
100
|
}
|
|
110
101
|
return null;
|
|
111
102
|
}
|
|
112
|
-
|
|
113
|
-
|
|
103
|
+
function triggerHmrUpdate(server, fullPath, verbose = false) {
|
|
104
|
+
const modules = server.moduleGraph.getModulesByFile(fullPath);
|
|
105
|
+
if (modules && modules.size > 0) {
|
|
106
|
+
for (const mod of modules) {
|
|
107
|
+
safeInvalidateModule(server, mod);
|
|
108
|
+
safeSendHmrUpdate(server, {
|
|
109
|
+
type: "update",
|
|
110
|
+
updates: [
|
|
111
|
+
{
|
|
112
|
+
type: "js-update",
|
|
113
|
+
path: mod.url,
|
|
114
|
+
acceptedPath: mod.url,
|
|
115
|
+
timestamp: Date.now()
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
});
|
|
119
|
+
if (verbose) {
|
|
120
|
+
console.log(`[vite-compat] HMR triggered for: ${mod.url}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
const mod = server.moduleGraph.getModuleById(fullPath);
|
|
125
|
+
if (mod) {
|
|
126
|
+
safeInvalidateModule(server, mod);
|
|
127
|
+
safeSendHmrUpdate(server, {
|
|
128
|
+
type: "update",
|
|
129
|
+
updates: [
|
|
130
|
+
{
|
|
131
|
+
type: "js-update",
|
|
132
|
+
path: mod.url,
|
|
133
|
+
acceptedPath: mod.url,
|
|
134
|
+
timestamp: Date.now()
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/utils/index.ts
|
|
143
|
+
function resolveFileToAbsPath(file, rootDir) {
|
|
114
144
|
if ((0, import_path.isAbsolute)(file)) {
|
|
115
145
|
return (0, import_fs.existsSync)(file) ? (0, import_path.normalize)(file) : null;
|
|
116
146
|
}
|
|
117
|
-
const fromRoot = (0, import_path.join)(
|
|
147
|
+
const fromRoot = (0, import_path.join)(rootDir, file);
|
|
118
148
|
if ((0, import_fs.existsSync)(fromRoot)) {
|
|
119
149
|
return (0, import_path.normalize)(fromRoot);
|
|
120
150
|
}
|
|
121
|
-
let dir =
|
|
151
|
+
let dir = rootDir;
|
|
122
152
|
while (true) {
|
|
123
153
|
const candidate = (0, import_path.join)(dir, file);
|
|
124
154
|
if ((0, import_fs.existsSync)(candidate)) {
|
|
@@ -130,6 +160,254 @@ function resolveFileToAbsPath(file, viteRoot) {
|
|
|
130
160
|
}
|
|
131
161
|
return null;
|
|
132
162
|
}
|
|
163
|
+
function readJsonBody(req) {
|
|
164
|
+
return new Promise((resolve2, reject) => {
|
|
165
|
+
let body = "";
|
|
166
|
+
req.on("data", (chunk) => {
|
|
167
|
+
body += chunk.toString();
|
|
168
|
+
});
|
|
169
|
+
req.on("end", () => {
|
|
170
|
+
try {
|
|
171
|
+
resolve2(JSON.parse(body));
|
|
172
|
+
} catch (e) {
|
|
173
|
+
reject(e);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
req.on("error", reject);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// package.json
|
|
181
|
+
var version = "0.3.1-beta.1";
|
|
182
|
+
|
|
183
|
+
// src/design-mode/types.ts
|
|
184
|
+
var SANDBOX_SCRIPT_PATH = "/sandbox-script.js";
|
|
185
|
+
var VIRTUAL_CODE_API_PATH = "/api/virtual-code";
|
|
186
|
+
var DEFAULT_DESIGN_MODE_OPTIONS = {
|
|
187
|
+
enableVirtualCode: true,
|
|
188
|
+
virtualCodeApiPath: VIRTUAL_CODE_API_PATH,
|
|
189
|
+
verbose: false,
|
|
190
|
+
exclude: [/node_modules/],
|
|
191
|
+
include: [/\.[jt]sx?$/]
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// src/design-mode/virtual-code.ts
|
|
195
|
+
var path = __toESM(require("path"), 1);
|
|
196
|
+
var virtualCodeMap = /* @__PURE__ */ new Map();
|
|
197
|
+
function matchesDesignModePattern(id, options) {
|
|
198
|
+
const exclude = options.exclude || [];
|
|
199
|
+
const include = options.include || [];
|
|
200
|
+
if (exclude.some((re) => re.test(id))) return false;
|
|
201
|
+
if (!include.some((re) => re.test(id))) return false;
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
function extractRelativePath(id) {
|
|
205
|
+
const srcIndex = id.indexOf("/src/");
|
|
206
|
+
return srcIndex !== -1 ? id.slice(srcIndex + 1) : null;
|
|
207
|
+
}
|
|
208
|
+
function hasVirtualCode(id) {
|
|
209
|
+
const relativePath = extractRelativePath(id);
|
|
210
|
+
if (!relativePath) return false;
|
|
211
|
+
return virtualCodeMap.has(relativePath) || virtualCodeMap.has("/" + relativePath);
|
|
212
|
+
}
|
|
213
|
+
function shouldSkipDesignModeTransform(id, options) {
|
|
214
|
+
if (!matchesDesignModePattern(id, options)) return true;
|
|
215
|
+
if (hasVirtualCode(id)) return true;
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
function loadVirtualCode(id, options) {
|
|
219
|
+
if (!matchesDesignModePattern(id, options)) return void 0;
|
|
220
|
+
const relativePath = extractRelativePath(id);
|
|
221
|
+
if (!relativePath) return void 0;
|
|
222
|
+
const code = virtualCodeMap.get(relativePath) || virtualCodeMap.get("/" + relativePath);
|
|
223
|
+
if (code && options.verbose) {
|
|
224
|
+
console.log(`[DesignMode] Using virtual code for: ${relativePath}`);
|
|
225
|
+
}
|
|
226
|
+
return code;
|
|
227
|
+
}
|
|
228
|
+
function createVirtualCodeMiddleware(server, options, projectRoot) {
|
|
229
|
+
var _a;
|
|
230
|
+
const apiPath = options.virtualCodeApiPath || VIRTUAL_CODE_API_PATH;
|
|
231
|
+
const verbose = (_a = options.verbose) != null ? _a : false;
|
|
232
|
+
return (req, res, next) => {
|
|
233
|
+
var _a2;
|
|
234
|
+
if (!((_a2 = req.url) == null ? void 0 : _a2.startsWith(apiPath))) {
|
|
235
|
+
return next();
|
|
236
|
+
}
|
|
237
|
+
if (req.method === "OPTIONS") {
|
|
238
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
239
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
|
240
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
241
|
+
res.statusCode = 204;
|
|
242
|
+
res.end();
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
res.setHeader("Content-Type", "application/json");
|
|
246
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
247
|
+
if (req.method === "POST") {
|
|
248
|
+
let body = "";
|
|
249
|
+
req.on("data", (chunk) => body += chunk.toString());
|
|
250
|
+
req.on("end", () => {
|
|
251
|
+
try {
|
|
252
|
+
const { filePath, content } = JSON.parse(body);
|
|
253
|
+
virtualCodeMap.set(filePath, content);
|
|
254
|
+
if (verbose) {
|
|
255
|
+
console.log(`[DnD] Virtual code set for: ${filePath}`);
|
|
256
|
+
}
|
|
257
|
+
const fullPath = path.resolve(projectRoot, filePath);
|
|
258
|
+
triggerHmrUpdate(server, fullPath, verbose);
|
|
259
|
+
res.end(JSON.stringify({ success: true, filePath }));
|
|
260
|
+
} catch (error) {
|
|
261
|
+
res.statusCode = 500;
|
|
262
|
+
res.end(JSON.stringify({ error: String(error) }));
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (req.method === "GET") {
|
|
268
|
+
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
269
|
+
const filePath = url.searchParams.get("path");
|
|
270
|
+
if (filePath) {
|
|
271
|
+
const content = virtualCodeMap.get(filePath);
|
|
272
|
+
res.statusCode = content ? 200 : 404;
|
|
273
|
+
res.end(JSON.stringify(content ? { content } : { error: "Not found" }));
|
|
274
|
+
} else {
|
|
275
|
+
res.end(JSON.stringify({ paths: Array.from(virtualCodeMap.keys()) }));
|
|
276
|
+
}
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (req.method === "DELETE") {
|
|
280
|
+
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
281
|
+
const filePath = url.searchParams.get("path");
|
|
282
|
+
const pathsToInvalidate = filePath ? [filePath] : Array.from(virtualCodeMap.keys());
|
|
283
|
+
filePath ? virtualCodeMap.delete(filePath) : virtualCodeMap.clear();
|
|
284
|
+
if (verbose) {
|
|
285
|
+
console.log(`[DnD] Virtual code ${filePath ? `cleared for: ${filePath}` : "all cleared"}`);
|
|
286
|
+
}
|
|
287
|
+
for (const p of pathsToInvalidate) {
|
|
288
|
+
const fullPath = path.resolve(projectRoot, p);
|
|
289
|
+
triggerHmrUpdate(server, fullPath, verbose);
|
|
290
|
+
}
|
|
291
|
+
res.end(JSON.stringify({ success: true, clearedPaths: pathsToInvalidate }));
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
res.statusCode = 405;
|
|
295
|
+
res.end(JSON.stringify({ error: "Method not allowed" }));
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/design-mode/sandbox-script.ts
|
|
300
|
+
function getSandboxScriptContent() {
|
|
301
|
+
return '(()=>{var e={572(e,t,n){var r=n(736).Symbol;e.exports=r},561(e,t,n){var r=n(572),o=n(504),i=n(567),s=r?r.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":s&&s in Object(e)?o(e):i(e)}},605(e,t,n){var r=n(327),o=/^\\s+/;e.exports=function(e){return e?e.slice(0,r(e)+1).replace(o,""):e}},433(e,t,n){var r="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g;e.exports=r},504(e,t,n){var r=n(572),o=Object.prototype,i=o.hasOwnProperty,s=o.toString,a=r?r.toStringTag:void 0;e.exports=function(e){var t=i.call(e,a),n=e[a];try{e[a]=void 0;var r=!0}catch(e){}var o=s.call(e);return r&&(t?e[a]=n:delete e[a]),o}},567(e){var t=Object.prototype.toString;e.exports=function(e){return t.call(e)}},736(e,t,n){var r=n(433),o="object"==typeof self&&self&&self.Object===Object&&self,i=r||o||Function("return this")();e.exports=i},327(e){var t=/\\s/;e.exports=function(e){for(var n=e.length;n--&&t.test(e.charAt(n)););return n}},702(e,t,n){var r=n(230),o=n(381),i=n(569),s=Math.max,a=Math.min;e.exports=function(e,t,n){var c,u,l,d,f,h,p=0,g=!1,m=!1,v=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){var n=c,r=u;return c=u=void 0,p=t,d=e.apply(r,n)}function w(e){var n=e-h;return void 0===h||n>=t||n<0||m&&e-p>=l}function b(){var e=o();if(w(e))return E(e);f=setTimeout(b,function(e){var n=t-(e-h);return m?a(n,l-(e-p)):n}(e))}function E(e){return f=void 0,v&&c?y(e):(c=u=void 0,d)}function N(){var e=o(),n=w(e);if(c=arguments,u=this,h=e,n){if(void 0===f)return function(e){return p=e,f=setTimeout(b,t),g?y(e):d}(h);if(m)return clearTimeout(f),f=setTimeout(b,t),y(h)}return void 0===f&&(f=setTimeout(b,t)),d}return t=i(t)||0,r(n)&&(g=!!n.leading,l=(m="maxWait"in n)?s(i(n.maxWait)||0,t):l,v="trailing"in n?!!n.trailing:v),N.cancel=function(){void 0!==f&&clearTimeout(f),p=0,c=h=u=f=void 0},N.flush=function(){return void 0===f?d:E(o())},N}},230(e){e.exports=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}},470(e){e.exports=function(e){return null!=e&&"object"==typeof e}},89(e,t,n){var r=n(561),o=n(470);e.exports=function(e){return"symbol"==typeof e||o(e)&&"[object Symbol]"==r(e)}},381(e,t,n){var r=n(736);e.exports=function(){return r.Date.now()}},569(e,t,n){var r=n(605),o=n(230),i=n(89),s=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,c=/^0o[0-7]+$/i,u=parseInt;e.exports=function(e){if("number"==typeof e)return e;if(i(e))return NaN;if(o(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=o(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=r(e);var n=a.test(e);return n||c.test(e)?u(e.slice(2),n?2:8):s.test(e)?NaN:+e}}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";var e=n(702),t=n.n(e),r=class extends Error{code;constructor(e,t){super(t),this.name="PenpalError",this.code=e}},o=e=>({name:e.name,message:e.message,stack:e.stack,penpalCode:e instanceof r?e.code:void 0}),i=Symbol("Reply"),s=class{value;transferables;#e=i;constructor(e,t){this.value=e,this.transferables=t?.transferables}},a="penpal",c=e=>"object"==typeof e&&null!==e,u=e=>"function"==typeof e,l=e=>"SYN"===e.type,d=e=>"ACK1"===e.type,f=e=>"ACK2"===e.type,h=e=>"CALL"===e.type,p=e=>"REPLY"===e.type,g=(e,t=[])=>{const n=[];for(const r of Object.keys(e)){const o=e[r];u(o)?n.push([...t,r]):c(o)&&n.push(...g(o,[...t,r]))}return n},m=e=>e.join("."),v=(e,t,n)=>({namespace:a,channel:e,type:"REPLY",callId:t,isError:!0,...n instanceof Error?{value:o(n),isSerializedErrorInstance:!0}:{value:n}}),y=crypto.randomUUID?.bind(crypto)??(()=>new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")),w=Symbol("CallOptions"),b=class{transferables;timeout;#e=w;constructor(e){this.transferables=e?.transferables,this.timeout=e?.timeout}},E=new Set(["apply","call","bind"]),N=(e,t,n=[])=>new Proxy(n.length?()=>{}:Object.create(null),{get(r,o){if("then"!==o)return n.length&&E.has(o)?Reflect.get(r,o):N(e,t,[...n,o])},apply:(t,r,o)=>e(n,o)}),C=e=>new r("CONNECTION_DESTROYED",`Method call ${m(e)}() failed due to destroyed connection`),S=class extends Error{constructor(e){super(`You\'ve hit a bug in Penpal. Please file an issue with the following information: ${e}`)}},x="deprecated-penpal",O=e=>e.join("."),P=e=>new S(`Unexpected message to translate: ${JSON.stringify(e)}`),T=({messenger:e,methods:t,timeout:n,channel:o,log:i})=>{const w=y();let E;const S=[];let O=!1;const P=g(t),{promise:T,resolve:M,reject:I}=(()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}})(),A=void 0!==n?setTimeout(()=>{I(new r("CONNECTION_TIMEOUT",`Connection timed out after ${n}ms`))},n):void 0,R=()=>{for(const e of S)e()},L=()=>{if(O)return;S.push(((e,t,n,o)=>{let i=!1;const l=async l=>{if(i)return;if(!h(l))return;o?.(`Received ${m(l.methodPath)}() call`,l);const{methodPath:d,args:f,id:p}=l;let g,y;try{const e=((e,t)=>{const n=e.reduce((e,t)=>c(e)?e[t]:void 0,t);return u(n)?n:void 0})(d,t);if(!e)throw new r("METHOD_NOT_FOUND",`Method \\`${m(d)}\\` is not found.`);let o=await e(...f);o instanceof s&&(y=o.transferables,o=await o.value),g={namespace:a,channel:n,type:"REPLY",callId:p,value:o}}catch(e){g=v(n,p,e)}if(!i)try{o?.(`Sending ${m(d)}() reply`,g),e.sendMessage(g,y)}catch(t){throw"DataCloneError"===t.name&&(g=v(n,p,t),o?.(`Sending ${m(d)}() reply`,g),e.sendMessage(g)),t}};return e.addMessageHandler(l),()=>{i=!0,e.removeMessageHandler(l)}})(e,t,o,i));const{remoteProxy:n,destroy:l}=((e,t,n)=>{let o=!1;const i=new Map,s=e=>{if(!p(e))return;const{callId:t,value:o,isError:s,isSerializedErrorInstance:a}=e,c=i.get(t);c&&(i.delete(t),n?.(`Received ${m(c.methodPath)}() call`,e),s?c.reject(a?(({name:e,message:t,stack:n,penpalCode:o})=>{const i=o?new r(o,t):new Error(t);return i.name=e,i.stack=n,i})(o):o):c.resolve(o))};return e.addMessageHandler(s),{remoteProxy:N((s,c)=>{if(o)throw C(s);const u=y(),l=c[c.length-1],d=l instanceof b,{timeout:f,transferables:h}=d?l:{},p=d?c.slice(0,-1):c;return new Promise((o,c)=>{const l=void 0!==f?window.setTimeout(()=>{i.delete(u),c(new r("METHOD_CALL_TIMEOUT",`Method call ${m(s)}() timed out after ${f}ms`))},f):void 0;i.set(u,{methodPath:s,resolve:o,reject:c,timeoutId:l});try{const r={namespace:a,channel:t,type:"CALL",id:u,methodPath:s,args:p};n?.(`Sending ${m(s)}() call`,r),e.sendMessage(r,h)}catch(e){c(new r("TRANSMISSION_FAILED",e.message))}})},n),destroy:()=>{o=!0,e.removeMessageHandler(s);for(const{methodPath:e,reject:t,timeoutId:n}of i.values())clearTimeout(n),t(C(e));i.clear()}}})(e,o,i);S.push(l),clearTimeout(A),O=!0,M({remoteProxy:n,destroy:R})},D=()=>{const t={namespace:a,type:"SYN",channel:o,participantId:w};i?.("Sending handshake SYN",t);try{e.sendMessage(t)}catch(e){I(new r("TRANSMISSION_FAILED",e.message))}},F=t=>{l(t)&&(t=>{if(i?.("Received handshake SYN",t),t.participantId===E&&E!==x)return;if(E=t.participantId,D(),!(w>E||E===x))return;const n={namespace:a,channel:o,type:"ACK1",methodPaths:P};i?.("Sending handshake ACK1",n);try{e.sendMessage(n)}catch(e){return void I(new r("TRANSMISSION_FAILED",e.message))}})(t),d(t)&&(t=>{i?.("Received handshake ACK1",t);const n={namespace:a,channel:o,type:"ACK2"};i?.("Sending handshake ACK2",n);try{e.sendMessage(n)}catch(e){return void I(new r("TRANSMISSION_FAILED",e.message))}L()})(t),f(t)&&(e=>{i?.("Received handshake ACK2",e),L()})(t)};return e.addMessageHandler(F),S.push(()=>e.removeMessageHandler(F)),D(),T},M=new WeakSet,I=class{#t;#n;#r;#o;#i;#s=new Set;#a;#c=!1;constructor({remoteWindow:e,allowedOrigins:t}){if(!e)throw new r("INVALID_ARGUMENT","remoteWindow must be defined");this.#t=e,this.#n=t?.length?t:[window.origin]}initialize=({log:e,validateReceivedMessage:t})=>{this.#r=e,this.#o=t,window.addEventListener("message",this.#u)};sendMessage=(e,t)=>{if(l(e)){const n=this.#l(e);return void this.#t.postMessage(e,{targetOrigin:n,transfer:t})}if(d(e)||this.#c){const n=this.#c?(e=>{if(d(e))return{penpal:"synAck",methodNames:e.methodPaths.map(O)};if(h(e))return{penpal:"call",id:e.id,methodName:O(e.methodPath),args:e.args};if(p(e))return e.isError?{penpal:"reply",id:e.callId,resolution:"rejected",...e.isSerializedErrorInstance?{returnValue:e.value,returnValueIsError:!0}:{returnValue:e.value}}:{penpal:"reply",id:e.callId,resolution:"fulfilled",returnValue:e.value};throw P(e)})(e):e,r=this.#l(e);return void this.#t.postMessage(n,{targetOrigin:r,transfer:t})}if(f(e)){const{port1:n,port2:r}=new MessageChannel;this.#a=n,n.addEventListener("message",this.#d),n.start();const o=[r,...t||[]],i=this.#l(e);return void this.#t.postMessage(e,{targetOrigin:i,transfer:o})}if(!this.#a)throw new S("Port is undefined");this.#a.postMessage(e,{transfer:t})};addMessageHandler=e=>{this.#s.add(e)};removeMessageHandler=e=>{this.#s.delete(e)};destroy=()=>{window.removeEventListener("message",this.#u),this.#f(),this.#s.clear()};#h=e=>this.#n.some(t=>t instanceof RegExp?t.test(e):t===e||"*"===t);#l=e=>{if(l(e))return"*";if(!this.#i)throw new S("Concrete remote origin not set");return"null"===this.#i&&this.#n.includes("*")?"*":this.#i};#f=()=>{this.#a?.removeEventListener("message",this.#d),this.#a?.close(),this.#a=void 0};#u=({source:e,origin:t,ports:n,data:r})=>{if(e===this.#t&&((e=>c(e)&&"penpal"in e)(r)&&(this.#r?.("Please upgrade the child window to the latest version of Penpal."),this.#c=!0,r=(e=>{if("syn"===e.penpal)return{namespace:a,channel:void 0,type:"SYN",participantId:x};if("ack"===e.penpal)return{namespace:a,channel:void 0,type:"ACK2"};if("call"===e.penpal)return{namespace:a,channel:void 0,type:"CALL",id:e.id,methodPath:(t=e.methodName,t.split(".")),args:e.args};var t;if("reply"===e.penpal)return"fulfilled"===e.resolution?{namespace:a,channel:void 0,type:"REPLY",callId:e.id,value:e.returnValue}:{namespace:a,channel:void 0,type:"REPLY",callId:e.id,isError:!0,...e.returnValueIsError?{value:e.returnValue,isSerializedErrorInstance:!0}:{value:e.returnValue}};throw P(e)})(r)),this.#o?.(r)))if(this.#h(t)){if(l(r)&&(this.#f(),this.#i=t),f(r)&&!this.#c){if(this.#a=n[0],!this.#a)throw new S("No port received on ACK2");this.#a.addEventListener("message",this.#d),this.#a.start()}for(const e of this.#s)e(r)}else this.#r?.(`Received a message from origin \\`${t}\\` which did not match allowed origins \\`[${this.#n.join(", ")}]\\``)};#d=({data:e})=>{if(this.#o?.(e))for(const t of this.#s)t(e)}},A=document,R=window,L=Array.prototype,D=L.filter,F=L.indexOf,j=L.map,$=L.push,_=L.reverse,k=L.slice,W=L.splice,z=/^#[\\w-]*$/,U=/^\\.[\\w-]*$/,V=/<.+>/,H=/^\\w+$/;function B(e,t){return void 0===t&&(t=A),U.test(e)?t.getElementsByClassName(e.slice(1)):H.test(e)?t.getElementsByTagName(e):t.querySelectorAll(e)}function Y(e,t){if(void 0===t&&(t=A),e){if(e.__cash)return e;var n=e;if(ne(e)){if(t.__cash&&(t=t[0]),!(n=z.test(e)?t.getElementById(e.slice(1)):V.test(e)?ke(e):B(e,t)))return}else if(te(e))return this.ready(e);(n.nodeType||n===R)&&(n=[n]),this.length=n.length;for(var r=0,o=this.length;r<o;r++)this[r]=n[r]}}function K(e,t){return new Y(e,t)}var q=K.fn=K.prototype=Y.prototype={constructor:K,__cash:!0,length:0,splice:W};q.get=function(e){return void 0===e?k.call(this):this[e<0?e+this.length:e]},q.eq=function(e){return K(this.get(e))},q.first=function(){return this.eq(0)},q.last=function(){return this.eq(-1)},q.map=function(e){return K(j.call(this,function(t,n){return e.call(t,n,t)}))},q.slice=function(){return K(k.apply(this,arguments))};var G=/(?:^\\w|[A-Z]|\\b\\w)/g,X=/[\\s-_]+/g;function J(e){return e.replace(G,function(e,t){return e[t?"toUpperCase":"toLowerCase"]()}).replace(X,"")}function Z(e,t){for(var n=0,r=e.length;n<r&&!1!==t.call(e[n],e[n],n,e);n++);}K.camelCase=J,K.each=Z,q.each=function(e){return Z(this,function(t,n){return e.call(t,n,t)}),this},q.removeProp=function(e){return this.each(function(t,n){delete n[e]})},K.extend=q.extend=function(e){void 0===e&&(e=this);for(var t=arguments,n=t.length,r=n<2?0:1;r<n;r++)for(var o in t[r])e[o]=t[r][o];return e};var Q=1;function ee(e,t){var n=e&&(e.matches||e.webkitMatchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector);return!!n&&n.call(e,t)}function te(e){return"function"==typeof e}function ne(e){return"string"==typeof e}function re(e){return!isNaN(parseFloat(e))&&isFinite(e)}K.guid=Q,K.matches=ee,K.isFunction=te,K.isString=ne,K.isNumeric=re;var oe=Array.isArray;function ie(e){return ne(e)?function(t,n){return ee(n,e)}:e.__cash?function(t,n){return e.is(n)}:function(e,t,n){return t===n}}K.isArray=oe,q.prop=function(e,t){if(e){if(ne(e))return arguments.length<2?this[0]&&this[0][e]:this.each(function(n,r){r[e]=t});for(var n in e)this.prop(n,e[n]);return this}},q.filter=function(e){if(!e)return K();var t=te(e)?e:ie(e);return K(D.call(this,function(n,r){return t.call(n,r,n,e)}))};var se=/\\S+/g;function ae(e){return ne(e)&&e.match(se)||[]}function ce(e){return e.filter(function(e,t,n){return n.indexOf(e)===t})}function ue(e,t,n){if(1===e.nodeType){var r=R.getComputedStyle(e,null);return t?n?r.getPropertyValue(t):r[t]:r}}function le(e,t){return parseInt(ue(e,t),10)||0}q.hasClass=function(e){var t=ae(e),n=!1;return t.length&&this.each(function(e,r){return!(n=r.classList.contains(t[0]))}),n},q.removeAttr=function(e){var t=ae(e);return t.length?this.each(function(e,n){Z(t,function(e){n.removeAttribute(e)})}):this},q.attr=function(e,t){if(e){if(ne(e)){if(arguments.length<2){if(!this[0])return;var n=this[0].getAttribute(e);return null===n?void 0:n}return null===t?this.removeAttr(e):this.each(function(n,r){r.setAttribute(e,t)})}for(var r in e)this.attr(r,e[r]);return this}},q.toggleClass=function(e,t){var n=ae(e),r=void 0!==t;return n.length?this.each(function(e,o){Z(n,function(e){r?t?o.classList.add(e):o.classList.remove(e):o.classList.toggle(e)})}):this},q.addClass=function(e){return this.toggleClass(e,!0)},q.removeClass=function(e){return arguments.length?this.toggleClass(e,!1):this.attr("class","")},K.unique=ce,q.add=function(e,t){return K(ce(this.get().concat(K(e,t).get())))};var de=/^--/;function fe(e){return de.test(e)}var he={},pe=A.createElement("div").style,ge=["webkit","moz","ms","o"];function me(e,t){if(void 0===t&&(t=fe(e)),t)return e;if(!he[e]){var n=J(e),r=""+n.charAt(0).toUpperCase()+n.slice(1);Z((n+" "+ge.join(r+" ")+r).split(" "),function(t){if(t in pe)return he[e]=t,!1})}return he[e]}K.prefixedProp=me;var ve={animationIterationCount:!0,columnCount:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0};function ye(e,t,n){return void 0===n&&(n=fe(e)),n||ve[e]||!re(t)?t:t+"px"}q.css=function(e,t){if(ne(e)){var n=fe(e);return e=me(e,n),arguments.length<2?this[0]&&ue(this[0],e,n):e?(t=ye(e,t,n),this.each(function(r,o){1===o.nodeType&&(n?o.style.setProperty(e,t):o.style[e]=t)})):this}for(var r in e)this.css(r,e[r]);return this};var we="__cashData",be=/^data-(.*)/;function Ee(e){return e[we]=e[we]||{}}function Ne(e,t){var n=Ee(e);if(t){if(!(t in n)){var r=e.dataset?e.dataset[t]||e.dataset[J(t)]:K(e).attr("data-"+t);if(void 0!==r){try{r=JSON.parse(r)}catch(e){}n[t]=r}}return n[t]}return n}function Ce(e,t){return le(e,"border"+(t?"Left":"Top")+"Width")+le(e,"padding"+(t?"Left":"Top"))+le(e,"padding"+(t?"Right":"Bottom"))+le(e,"border"+(t?"Right":"Bottom")+"Width")}function Se(e,t){for(var n=0,r=t.length;n<r;n++)if(e.indexOf(t[n])<0)return!1;return!0}function xe(e,t,n){Z(e[n],function(e){e[0];var r=e[1];t.removeEventListener(n,r)}),delete e[n]}K.hasData=function(e){return we in e},q.data=function(e,t){var n=this;if(!e){if(!this[0])return;return Z(this[0].attributes,function(e){var t=e.name.match(be);t&&n.data(t[1])}),Ne(this[0])}if(ne(e))return void 0===t?this[0]&&Ne(this[0],e):this.each(function(n,r){return function(e,t,n){Ee(e)[t]=n}(r,e,t)});for(var r in e)this.data(r,e[r]);return this},q.removeData=function(e){return this.each(function(t,n){return function(e,t){void 0===t?delete e[we]:delete Ee(e)[t]}(n,e)})},Z(["Width","Height"],function(e){q["inner"+e]=function(){if(this[0])return this[0]===R?R["inner"+e]:this[0]["client"+e]}}),Z(["width","height"],function(e,t){q[e]=function(n){return this[0]?arguments.length?(n=parseInt(n,10),this.each(function(r,o){if(1===o.nodeType){var i=ue(o,"boxSizing");o.style[e]=ye(e,n+("border-box"===i?Ce(o,!t):0))}})):this[0]===R?this[0][J("outer-"+e)]:this[0].getBoundingClientRect()[e]-Ce(this[0],!t):void 0===n?void 0:this}}),Z(["Width","Height"],function(e,t){q["outer"+e]=function(n){if(this[0])return this[0]===R?R["outer"+e]:this[0]["offset"+e]+(n?le(this[0],"margin"+(t?"Top":"Left"))+le(this[0],"margin"+(t?"Bottom":"Right")):0)}});var Oe="__cashEvents";function Pe(e){return e[Oe]=e[Oe]||{}}function Te(e){var t=e.split(".");return[t[0],t.slice(1).sort()]}function Me(e,t,n,r){var o=Pe(e);if(t){var i=o[t];if(!i)return;r&&(r.guid=r.guid||Q++),o[t]=i.filter(function(o){var i=o[0],s=o[1];if(r&&s.guid!==r.guid||!Se(i,n))return!0;e.removeEventListener(t,s)})}else if(n&&n.length)for(t in o)Me(e,t,n,r);else for(t in o)xe(o,e,t)}q.off=function(e,t){var n=this;return void 0===e?this.each(function(e,t){return Me(t)}):Z(ae(e),function(e){var r=Te(e),o=r[0],i=r[1];n.each(function(e,n){return Me(n,o,i,t)})}),this},q.on=function(e,t,n,r){var o=this;if(!ne(e)){for(var i in e)this.on(i,t,e[i]);return this}return te(t)&&(n=t,t=!1),Z(ae(e),function(e){var i=Te(e),s=i[0],a=i[1];o.each(function(e,o){var i=function e(i){if(!i.namespace||Se(a,i.namespace.split("."))){var c=o;if(t){for(var u=i.target;!ee(u,t);){if(u===o)return;if(!(u=u.parentNode))return}c=u}i.namespace=i.namespace||"";var l=n.call(c,i,i.data);r&&Me(o,s,a,e),!1===l&&(i.preventDefault(),i.stopPropagation())}};i.guid=n.guid=n.guid||Q++,function(e,t,n,r){r.guid=r.guid||Q++;var o=Pe(e);o[t]=o[t]||[],o[t].push([n,r]),e.addEventListener(t,r)}(o,s,a,i)})}),this},q.one=function(e,t,n){return this.on(e,t,n,!0)},q.ready=function(e){var t=function(){return e(K)};return"loading"!==A.readyState?setTimeout(t):A.addEventListener("DOMContentLoaded",t),this},q.trigger=function(e,t){var n=e;if(ne(e)){var r=Te(e),o=r[0],i=r[1];(n=A.createEvent("HTMLEvents")).initEvent(o,!0,!0),n.namespace=i.join(".")}return n.data=t,this.each(function(e,t){t.dispatchEvent(n)})};var Ie=/select-one/i,Ae=/select-multiple/i;function Re(e){var t=e.type;return Ie.test(t)?function(e){return e.selectedIndex<0?null:e.options[e.selectedIndex].value}(e):Ae.test(t)?function(e){var t=[];return Z(e.options,function(e){!e.selected||e.disabled||e.parentNode.disabled||t.push(e.value)}),t}(e):e.value}var Le=/%20/g,De=/file|reset|submit|button|image/i,Fe=/radio|checkbox/i;q.serialize=function(){var e="";return this.each(function(t,n){Z(n.elements||[n],function(t){if(!t.disabled&&t.name&&"FIELDSET"!==t.tagName&&!De.test(t.type)&&(!Fe.test(t.type)||t.checked)){var n=Re(t);void 0!==n&&Z(oe(n)?n:[n],function(n){e+=function(e,t){return"&"+encodeURIComponent(e)+"="+encodeURIComponent(t).replace(Le,"+")}(t.name,n)})}})}),e.substr(1)},q.val=function(e){return void 0===e?this[0]&&Re(this[0]):this.each(function(t,n){var r=Ae.test(n.type),o=null===e?r?[]:"":e;r&&oe(o)?Z(n.options,function(e){e.selected=o.indexOf(e.value)>=0}):n.value=o})},q.clone=function(){return this.map(function(e,t){return t.cloneNode(!0)})},q.detach=function(){return this.each(function(e,t){t.parentNode&&t.parentNode.removeChild(t)})};var je,$e=/^\\s*<(\\w+)[^>]*>/,_e=/^\\s*<(\\w+)\\s*\\/?>(?:<\\/\\1>)?\\s*$/;function ke(e){if(function(){if(!je){var e=A.createElement("table"),t=A.createElement("tr");je={"*":A.createElement("div"),tr:A.createElement("tbody"),td:t,th:t,thead:e,tbody:e,tfoot:e}}}(),!ne(e))return[];if(_e.test(e))return[A.createElement(RegExp.$1)];var t=$e.test(e)&&RegExp.$1,n=je[t]||je["*"];return n.innerHTML=e,K(n.childNodes).detach().get()}function We(e,t,n){if(void 0!==t){var r=ne(t);!r&&t.length?Z(t,function(t){return We(e,t,n)}):Z(e,r?function(e){e.insertAdjacentHTML(n?"afterbegin":"beforeend",t)}:function(e,r){return function(e,t,n){n?e.insertBefore(t,e.childNodes[0]):e.appendChild(t)}(e,r?t.cloneNode(!0):t,n)})}}K.parseHTML=ke,q.empty=function(){var e=this[0];if(e)for(;e.firstChild;)e.removeChild(e.firstChild);return this},q.append=function(){var e=this;return Z(arguments,function(t){We(e,t)}),this},q.appendTo=function(e){return We(K(e),this),this},q.html=function(e){if(void 0===e)return this[0]&&this[0].innerHTML;var t=e.nodeType?e[0].outerHTML:e;return this.each(function(e,n){n.innerHTML=t})},q.insertAfter=function(e){var t=this;return K(e).each(function(e,n){var r=n.parentNode;t.each(function(t,o){r.insertBefore(e?o.cloneNode(!0):o,n.nextSibling)})}),this},q.after=function(){var e=this;return Z(_.apply(arguments),function(t){_.apply(K(t).slice()).insertAfter(e)}),this},q.insertBefore=function(e){var t=this;return K(e).each(function(e,n){var r=n.parentNode;t.each(function(t,o){r.insertBefore(e?o.cloneNode(!0):o,n)})}),this},q.before=function(){var e=this;return Z(arguments,function(t){K(t).insertBefore(e)}),this},q.prepend=function(){var e=this;return Z(arguments,function(t){We(e,t,!0)}),this},q.prependTo=function(e){return We(K(e),_.apply(this.slice()),!0),this},q.remove=function(){return this.detach().off()},q.replaceWith=function(e){var t=this;return this.each(function(n,r){var o=r.parentNode;if(o){var i=n?K(e).clone():K(e);if(!i[0])return t.remove(),!1;o.replaceChild(i[0],r),K(i[0]).after(i.slice(1))}})},q.replaceAll=function(e){return K(e).replaceWith(this),this},q.text=function(e){return void 0===e?this[0]?this[0].textContent:"":this.each(function(t,n){n.textContent=e})};var ze=A.documentElement;q.offset=function(){var e=this[0];if(e){var t=e.getBoundingClientRect();return{top:t.top+R.pageYOffset-ze.clientTop,left:t.left+R.pageXOffset-ze.clientLeft}}},q.offsetParent=function(){return K(this[0]&&this[0].offsetParent)},q.position=function(){var e=this[0];if(e)return{left:e.offsetLeft,top:e.offsetTop}},q.children=function(e){var t=[];return this.each(function(e,n){$.apply(t,n.children)}),t=K(ce(t)),e?t.filter(function(t,n){return ee(n,e)}):t},q.contents=function(){var e=[];return this.each(function(t,n){$.apply(e,"IFRAME"===n.tagName?[n.contentDocument]:n.childNodes)}),K(e.length&&ce(e))},q.find=function(e){for(var t=[],n=0,r=this.length;n<r;n++){var o=B(e,this[n]);o.length&&$.apply(t,o)}return K(t.length&&ce(t))},q.has=function(e){var t=ne(e)?function(t,n){return!!B(e,n).length}:function(t,n){return n.contains(e)};return this.filter(t)},q.is=function(e){if(!e||!this[0])return!1;var t=ie(e),n=!1;return this.each(function(r,o){return!(n=t(r,o,e))}),n},q.next=function(){return K(this[0]&&this[0].nextElementSibling)},q.not=function(e){if(!e||!this[0])return this;var t=ie(e);return this.filter(function(n,r){return!t(n,r,e)})},q.parent=function(){var e=[];return this.each(function(t,n){n&&n.parentNode&&e.push(n.parentNode)}),K(ce(e))},q.index=function(e){var t=e?K(e)[0]:this[0],n=e?this:K(t).parent().children();return F.call(n,t)},q.closest=function(e){return e&&this[0]?this.is(e)?this.filter(e):this.parent().closest(e):K()},q.parents=function(e){var t,n=[];return this.each(function(r,o){for(t=o;t&&t.parentNode&&t!==A.body.parentNode;)t=t.parentNode,(!e||e&&ee(t,e))&&n.push(t)}),K(ce(n))},q.prev=function(){return K(this[0]&&this[0].previousElementSibling)},q.siblings=function(){var e=this[0];return this.parent().children().filter(function(t,n){return n!==e})};const Ue=K,Ve=new class{getFiberNode(e){try{const t=Object.keys(e).find(e=>e.startsWith("__reactFiber$")||e.startsWith("__reactInternalInstance$"));return t?e[t]:null}catch(e){return console.warn("[ReactFiberService] Error getting fiber node:",e),null}}getDebugOwner(e){const t=this.getFiberNode(e);return t?._debugOwner??null}getDebugSource(e){const t=this.getFiberNode(e);return t?._debugSource??null}getOwnerDebugSource(e){const t=this.getDebugOwner(e);return t?._debugSource??null}hasDirectSourceInfo(e){return!!e.getAttribute("data-nocode-id")||!!this.getDebugSource(e)}hasOwnerNocodeId(e){const t=this.getDebugOwner(e);if(!t?.memoizedProps)return!1;const n=t.memoizedProps["data-nocode-id"];return"string"==typeof n&&n.length>0}getOwnerNocodeId(e){const t=this.getDebugOwner(e);if(!t?.memoizedProps)return null;const n=t.memoizedProps["data-nocode-id"];return"string"==typeof n?n:null}isSelectableElement(e){if(this.hasDirectSourceInfo(e))return!0;const t=this.getFiberNode(e),n=this.getOwnerDebugSource(e);return!!(t?.return&&5!==t.return.tag&&this.hasOwnerNocodeId(e)&&n)}isComponent(e){if(!this.isSelectableElement(e))return!1;if(e.getAttribute("data-nocode-components-name"))return!0;if(this.getDebugSource(e))return!1;const t=this.getFiberNode(e);return!(!t?.return||5===t.return.tag)}getComponentName(e){const t=e.getAttribute("data-nocode-tag-name");if(t)return t;const n=this.getDebugOwner(e);if(n?.type){const e=n.type;if("function"==typeof e){const t=e.displayName||e.name||"Unknown";return this.normalizeComponentName(t)}if("string"==typeof e)return e}return e.tagName.toLowerCase()}normalizeComponentName(e){return e.replace(/\\d+$/,"")}getComponentProps(e){if(!this.isComponent(e))return;const t=this.getDebugOwner(e);return t?.memoizedProps?this.sanitizeProps(t.memoizedProps):void 0}sanitizeProps(e){const t={};for(const[n,r]of Object.entries(e)){if("children"===n||n.startsWith("_"))continue;const e=this.sanitizeValue(r);void 0!==e&&(t[n]=e)}return t}sanitizeValue(e){if(null===e)return null;if(void 0===e)return;if("function"==typeof e)return;if("symbol"==typeof e)return;if("object"!=typeof e)return e;if("$$typeof"in e)return;if(e instanceof Node)return;if(Array.isArray(e)){const t=[];for(const n of e){const e=this.sanitizeValue(n);void 0!==e&&t.push(e)}return t}const t={};for(const[n,r]of Object.entries(e)){if(n.startsWith("_"))continue;const e=this.sanitizeValue(r);void 0!==e&&(t[n]=e)}return t}buildComponentInfo(e,t){const n=this.isComponent(e),r={isComponent:n,componentType:n?"component":"host",name:n?this.getComponentName(e):e.tagName.toLowerCase()};if(n){const n={...t,...this.getComponentProps(e)??{}},{cleanProps:o,extractedProps:i}=this.extractSpecialProps(n);i.componentsName&&(r.componentsName=i.componentsName),i.componentsVersion&&(r.componentsVersion=i.componentsVersion),r.props=o}return r}extractSpecialProps(e){const t={},n={};for(const[r,o]of Object.entries(e))"componentsName"===r&&"string"==typeof o?n.componentsName=o:"componentsVersion"===r&&"string"==typeof o?n.componentsVersion=o:t[r]=o;return{cleanProps:t,extractedProps:n}}};function He(e){const t={},n=e.attributes;for(let e=0;e<n.length;e++){const r=n[e];r.name.startsWith("data-nocode-")&&(t[r.name.replace("data-nocode-","").replace(/-([a-z])/g,(e,t)=>t.toUpperCase())]=r.value)}return t}const Be="data-dnd",Ye=`[${Be}]`;function Ke(e){return document.querySelector(`[${Be}="${e}"]`)}const qe=(e,t)=>{const n=e.getBoundingClientRect(),{x:r,y:o}=((e,t)=>{let n=e.x,r=e.y;if(t){const e=t.getBoundingClientRect();n-=e.left,r-=e.top}return{x:n,y:r}})({x:n.left,y:n.top},t);return{width:e.offsetWidth,height:e.offsetHeight,top:o,left:r}},Ge=(e,t)=>{const n=qe(e,t),r=function(e){return e.dataset}(e),o=Xe(e),i=Je(e),s=(e=>{const t=window.getComputedStyle(e);return{display:t.display,flexDirection:t.flexDirection,flexWrap:t.flexWrap,position:t.position}})(e),a=r.dnd||"",c=function(e){if(!e)return{};const t=e.split(":");if(t.length>=3){const n=t.pop(),r=t.pop(),o=t.join(":");return{id:e,filename:decodeURIComponent(o),component:r,codeId:n}}return 2===t.length?{id:e,component:t[0],codeId:t[1]}:{id:e}}(a),u=He(e),l=function(e){const t=He(e);return Ve.buildComponentInfo(e,t)}(e),d=(e=>{const t=e.querySelectorAll(`:scope > ${Ye}`);if(!t.length)return[];const n=[];return t.forEach(e=>{const t=e;n.push(qe(t))}),n})(e);return{id:a,codeId:c.codeId,name:c.component||e.tagName.toLowerCase(),filename:c.filename,bounding:n,display:o,computedStyle:s,text:i,nocodeData:u,componentInfo:l,childrenBoundings:d.length>0?d:void 0}},Xe=e=>Ue(e).css("display"),Je=e=>{const t=[];return e.childNodes.forEach(e=>{if(e.nodeType===Node.TEXT_NODE){const n=e.textContent?.trim()||"";n&&t.push(n)}}),t.join(" ")};function Ze(e){const t=["div","p","section","article","main","header","footer","nav","h1","h2","h3","h4","h5","h6","span","a","button","i","input","textarea","select","label","form","ul","ol","li","table","thead","tbody","tr","td","th","img","video","audio","canvas","svg"];try{const n=e.tagName.toLowerCase();if(!t.includes(n))return!1;const r=window.getComputedStyle(e);if("none"===r.display||"hidden"===r.visibility||"0"===r.opacity)return!1;const o=e.getBoundingClientRect();return!("inline"!==r.display&&"inline-block"!==r.display&&(0===o.width||0===o.height))}catch(e){return console.warn("Element validation failed:",e),!1}}function Qe(e,t=20){let n=e,r=0;for(;n&&r<t;){if(n.getAttribute(Be))return n;n=n.parentElement,r++}return null}function et(e){const t=window.getComputedStyle(e),n={};for(let e=0;e<t.length;e++){const r=t[e];n[r]=t.getPropertyValue(r)}return n}function tt(e){return(...t)=>{try{const n=e(...t);return n&&"function"==typeof n.then?n.catch(n=>(console.error(`Async error in ${e.name}:`,n),console.error("Error stack:",n.stack),console.error("Function arguments:",t),null)):n}catch(n){return console.error(`Sync error in ${e.name}:`,n),n instanceof Error&&console.error("Error stack:",n.stack),console.error("Function arguments:",t),null}}}const nt={getDraggableParentsData:(e,t)=>{const n=function(e,t){const n=((e,t)=>{const n=document.elementFromPoint(e,t);if(!n)return null;const r=n=>{if(n?.shadowRoot){const o=n.shadowRoot.elementFromPoint(e,t);return o===n?n:o?.shadowRoot?r(o):o||n}return n};return r(n)})(e,t);if(!n)return null;let r=n;if(!Ze(r)){let e=r.parentElement,t=0;const n=20;for(;e&&t<n;){if(Ze(e)){r=e;break}e=e.parentElement,t++}if(!Ze(r))return null}const o=Qe(r);return o&&Ze(o)?o:null}(e.x,e.y);if(!n)return;const r=(e=>{const t=Ue(e).closest(Ye).get(0),n=Ue(e).parents(Ye).get();return n[0]!==t&&n.unshift(t),n})(n);if(r.length){if(t){const e=r.map(e=>Ge(e));return{...e[0],computedStyle:et(n),parents:e.slice(1)}}return{...Ge(r[0]),computedStyle:et(r[0])}}},getElementDataById:e=>{const t=Ke(e);if(t)return{...Ge(t),computedStyle:et(t)};console.warn("[getElementDataById] Element not found for domId:",e)},getEditableTextElementAtPosition:e=>{const t=function(e,t){if(document.caretPositionFromPoint){const n=document.caretPositionFromPoint(e,t);return n?.offsetNode??null}if(document.caretRangeFromPoint){const n=document.caretRangeFromPoint(e,t);return n?.startContainer??null}return document.elementFromPoint(e,t)}(e.x,e.y);if(!t)return void console.log("[getEditableTextElementAtPosition] No node at point:",e);if(t.nodeType!==Node.TEXT_NODE)return void console.log("[getEditableTextElementAtPosition] Not a text node:",t.nodeType);const n=t.textContent?.trim();if(!n)return void console.log("[getEditableTextElementAtPosition] Empty text node");const r=t.parentElement;if(!r)return void console.log("[getEditableTextElementAtPosition] No parent element");const o=Qe(r);if(o){if(function(e){const t=e.childNodes;let n=!1;for(let e=0;e<t.length;e++){const r=t[e];if(r.nodeType===Node.ELEMENT_NODE)return!1;if(r.nodeType===Node.TEXT_NODE){const e=r.textContent?.trim();e&&(n=!0)}}return n}(o))return console.log("[getEditableTextElementAtPosition] Found editable text element:",o.tagName,o.textContent),{...Ge(o),computedStyle:et(o)};console.log("[getEditableTextElementAtPosition] Element has child elements, cannot edit directly:",o.tagName)}else console.log("[getEditableTextElementAtPosition] No marked element found")},updateElementTextContent:(e,t)=>{const n=Ke(e);return n?(n.textContent=t,!0):(console.warn("[updateElementTextContent] Element not found:",e),!1)},scrollToElement:e=>{const t=Ke(e);return t?(t.scrollIntoView({behavior:"instant",block:"center",inline:"center"}),!0):(console.warn("[scrollToElement] Element not found for domId:",e),!1)}},rt=Object.fromEntries(Object.entries(nt).map(([e,t])=>[e,tt(t)])),ot="nocode-design-mode";let it=null,st=!1,at=null;const ct=t()(()=>{it?.onWindowMutated&&(console.log(`${ot} - Notifying parent of DOM mutation`),it.onWindowMutated({added:{},removed:{}}))},100),ut=async()=>{if(st||it)return it;st=!0,console.log(`${ot} - Creating penpal connection`);const e=(({messenger:e,methods:t={},timeout:n,channel:o,log:i})=>{if(!e)throw new r("INVALID_ARGUMENT","messenger must be defined");if(M.has(e))throw new r("INVALID_ARGUMENT","A messenger can only be used for a single connection");M.add(e);const s=[e.destroy],u=(e=>{let t,n=!1;return(...r)=>(n||(n=!0,t=e(...r)),t)})(t=>{if(t){const t={namespace:a,channel:o,type:"DESTROY"};try{e.sendMessage(t)}catch(e){}}for(const e of s)e();i?.("Connection destroyed")}),l=e=>(e=>c(e)&&e.namespace===a)(e)&&e.channel===o;return{promise:(async()=>{try{e.initialize({log:i,validateReceivedMessage:l}),e.addMessageHandler(e=>{(e=>"DESTROY"===e.type)(e)&&u(!1)});const{remoteProxy:r,destroy:a}=await T({messenger:e,methods:t,timeout:n,channel:o,log:i});return s.push(a),r}catch(e){throw u(!0),e}})(),destroy:()=>{u(!0)}}})({messenger:new I({remoteWindow:window===window.top?(console.warn(`${ot} - Not in an iframe, using window.parent as fallback`),window.parent):window.parent===window.top?window.parent:window.top?(console.log(`${ot} - Using window.top for nested iframe scenario`),window.top):window.parent,allowedOrigins:["*"]}),methods:rt});return e.promise.then(e=>{if(!e)return console.error(`${ot} - Failed to setup penpal connection: child is null`),void lt();it=e,console.log(`${ot} - Penpal connection set`),(()=>{if(at)return;at=new MutationObserver(e=>{e.some(e=>{const t=e.target;return"SCRIPT"!==t.tagName&&"STYLE"!==t.tagName&&("attributes"!==e.type||"style"===e.attributeName||"class"===e.attributeName)})&&ct()});const e=()=>{document.body&&at&&(at.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"],characterData:!0}),console.log(`${ot} - MutationObserver started`))};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()})()}).finally(()=>{st=!1}),e.promise.catch(e=>{console.error(`${ot} - Failed to setup penpal connection:`,e),lt()}),it},lt=t()(()=>{st||(console.log(`${ot} - Reconnecting to penpal parent`),it=null,ut())},1e3);ut()})()})();';
|
|
302
|
+
}
|
|
303
|
+
function createSandboxScriptMiddleware(options) {
|
|
304
|
+
var _a;
|
|
305
|
+
const verbose = (_a = options.verbose) != null ? _a : false;
|
|
306
|
+
const scriptContent = getSandboxScriptContent();
|
|
307
|
+
return (req, res, next) => {
|
|
308
|
+
if (req.url !== SANDBOX_SCRIPT_PATH) {
|
|
309
|
+
return next();
|
|
310
|
+
}
|
|
311
|
+
if (!scriptContent) {
|
|
312
|
+
if (verbose) {
|
|
313
|
+
console.warn("[DesignMode] sandbox-script.js not embedded. Build may be incomplete.");
|
|
314
|
+
}
|
|
315
|
+
res.statusCode = 404;
|
|
316
|
+
res.end("/* sandbox-script.js not available */");
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
320
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
321
|
+
res.end(scriptContent);
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function injectSandboxScript(html) {
|
|
325
|
+
const scriptTag = `<script src="${SANDBOX_SCRIPT_PATH}"></script>`;
|
|
326
|
+
if (html.includes(SANDBOX_SCRIPT_PATH)) {
|
|
327
|
+
return html;
|
|
328
|
+
}
|
|
329
|
+
if (html.includes("</head>")) {
|
|
330
|
+
return html.replace("</head>", ` ${scriptTag}
|
|
331
|
+
</head>`);
|
|
332
|
+
}
|
|
333
|
+
if (html.includes("<body>")) {
|
|
334
|
+
return html.replace("<body>", `<body>
|
|
335
|
+
${scriptTag}`);
|
|
336
|
+
}
|
|
337
|
+
return html + `
|
|
338
|
+
${scriptTag}`;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/visual-edit/override-code.ts
|
|
342
|
+
var overrideMap = /* @__PURE__ */ new Map();
|
|
343
|
+
function loadOverrideCode(id) {
|
|
344
|
+
const [filePath] = id.split("?", 2);
|
|
345
|
+
return overrideMap.get(filePath);
|
|
346
|
+
}
|
|
347
|
+
function clearAllOverridesAndInvalidate(server) {
|
|
348
|
+
if (overrideMap.size === 0) return;
|
|
349
|
+
for (const filePath of overrideMap.keys()) {
|
|
350
|
+
const mods = safeGetModulesByFile(server, filePath);
|
|
351
|
+
if (mods && mods.size > 0) {
|
|
352
|
+
for (const mod of mods) {
|
|
353
|
+
safeInvalidateModule(server, mod);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
overrideMap.clear();
|
|
358
|
+
}
|
|
359
|
+
var OVERRIDE_API_PATH = "/__nocode_file_override";
|
|
360
|
+
function createOverrideMiddleware(server) {
|
|
361
|
+
return async (req, res, next) => {
|
|
362
|
+
var _a;
|
|
363
|
+
if (!((_a = req.url) == null ? void 0 : _a.startsWith(OVERRIDE_API_PATH))) {
|
|
364
|
+
return next();
|
|
365
|
+
}
|
|
366
|
+
if (req.method !== "POST") {
|
|
367
|
+
return next();
|
|
368
|
+
}
|
|
369
|
+
try {
|
|
370
|
+
const { file, code } = await readJsonBody(req);
|
|
371
|
+
if (!file || typeof code !== "string") {
|
|
372
|
+
res.statusCode = 400;
|
|
373
|
+
res.end(JSON.stringify({ error: "file and code are required" }));
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const absolutePath = resolveFileToAbsPath(file, server.config.root);
|
|
377
|
+
if (!absolutePath) {
|
|
378
|
+
console.warn("[nocode-compiler] file not found:", file, server.config.root);
|
|
379
|
+
res.statusCode = 404;
|
|
380
|
+
res.end(JSON.stringify({ error: "file not found" }));
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
overrideMap.set(absolutePath, code);
|
|
384
|
+
const mods = safeGetModulesByFile(server, absolutePath);
|
|
385
|
+
if (mods && mods.size > 0) {
|
|
386
|
+
for (const mod of mods) {
|
|
387
|
+
safeInvalidateModule(server, mod);
|
|
388
|
+
safeSendHmrUpdate(server, {
|
|
389
|
+
type: "update",
|
|
390
|
+
updates: [
|
|
391
|
+
{
|
|
392
|
+
type: "js-update",
|
|
393
|
+
path: mod.url,
|
|
394
|
+
acceptedPath: mod.url,
|
|
395
|
+
timestamp: Date.now()
|
|
396
|
+
}
|
|
397
|
+
]
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
res.statusCode = 200;
|
|
402
|
+
res.end(JSON.stringify({ success: true }));
|
|
403
|
+
} catch (error) {
|
|
404
|
+
res.statusCode = 500;
|
|
405
|
+
res.end(JSON.stringify({ error: String(error) }));
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// src/index.ts
|
|
133
411
|
var PLUGIN_NAME = "vite-plugin-nocode-compiler";
|
|
134
412
|
function ensurePluginFirst(config, onError) {
|
|
135
413
|
try {
|
|
@@ -149,6 +427,10 @@ function componentCompiler(options = {}) {
|
|
|
149
427
|
enableLogging: false,
|
|
150
428
|
...options
|
|
151
429
|
};
|
|
430
|
+
const designModeOptions = {
|
|
431
|
+
...DEFAULT_DESIGN_MODE_OPTIONS,
|
|
432
|
+
...options.designModeOptions
|
|
433
|
+
};
|
|
152
434
|
const monitorService = new import_nocode_compiler_core.MonitorService({
|
|
153
435
|
pluginName: "vite-plugin-nocode-compiler",
|
|
154
436
|
framework: "vite",
|
|
@@ -157,8 +439,10 @@ function componentCompiler(options = {}) {
|
|
|
157
439
|
monitorService.reportMetrics(import_nocode_compiler_core.MetricType.PLUGIN_USE, 1);
|
|
158
440
|
const vueCompiler = new import_nocode_compiler_core.VueCompiler(options);
|
|
159
441
|
const jsxCompiler = new import_nocode_compiler_core.JSXCompiler(options);
|
|
442
|
+
const designModeCompiler = new import_nocode_compiler_core.DesignModeCompiler(options);
|
|
160
443
|
let server;
|
|
161
444
|
let pkgRegistry;
|
|
445
|
+
let projectRoot = "";
|
|
162
446
|
return {
|
|
163
447
|
name: PLUGIN_NAME,
|
|
164
448
|
enforce: "pre",
|
|
@@ -166,81 +450,59 @@ function componentCompiler(options = {}) {
|
|
|
166
450
|
* 配置解析完成后:
|
|
167
451
|
* 1. 将本插件移到插件列表最前面,确保在所有 enforce: 'pre' 插件中第一个执行
|
|
168
452
|
* 2. 初始化 PackageVersionRegistry
|
|
453
|
+
* 并预扫描项目 dependencies,填充版本缓存
|
|
169
454
|
*/
|
|
170
455
|
configResolved(config) {
|
|
171
456
|
ensurePluginFirst(config, (error) => monitorService.reportError(error, { scene: "ensurePluginFirst" }));
|
|
172
457
|
pkgRegistry = new import_nocode_compiler_core.PackageVersionRegistry(config.root);
|
|
458
|
+
projectRoot = config.root;
|
|
459
|
+
(0, import_nocode_compiler_core.preloadDependencyVersions)(pkgRegistry);
|
|
173
460
|
},
|
|
174
461
|
/**
|
|
175
|
-
* 配置开发服务器,添加 Override
|
|
176
|
-
* 兼容 Vite 2.x -
|
|
462
|
+
* 配置开发服务器,添加 Override 中间件和设计模式中间件
|
|
463
|
+
* 兼容 Vite 2.x - 6.x
|
|
177
464
|
*/
|
|
178
465
|
configureServer(_server) {
|
|
179
466
|
server = _server;
|
|
180
467
|
safeOnConnection(server, () => {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
for (const mod of mods) {
|
|
186
|
-
safeInvalidateModule(server, mod);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
overrideMap.clear();
|
|
191
|
-
});
|
|
192
|
-
server.middlewares.use("/__nocode_file_override", async (req, res, next) => {
|
|
193
|
-
if (req.method !== "POST") {
|
|
194
|
-
return next();
|
|
195
|
-
}
|
|
196
|
-
try {
|
|
197
|
-
const { file, code } = await readJsonBody(req);
|
|
198
|
-
if (!file || typeof code !== "string") {
|
|
199
|
-
res.statusCode = 400;
|
|
200
|
-
res.end(JSON.stringify({ error: "file and code are required" }));
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
const absolutePath = resolveFileToAbsPath(file, server.config.root);
|
|
204
|
-
if (!absolutePath) {
|
|
205
|
-
console.warn("[nocode-compiler] file not found:", file, server.config.root);
|
|
206
|
-
res.statusCode = 404;
|
|
207
|
-
res.end(JSON.stringify({ error: "file not found" }));
|
|
208
|
-
return;
|
|
468
|
+
clearAllOverridesAndInvalidate(server);
|
|
469
|
+
if (virtualCodeMap.size > 0) {
|
|
470
|
+
if (designModeOptions.verbose) {
|
|
471
|
+
console.log(`[DesignMode] Client reconnected, clearing ${virtualCodeMap.size} virtual code entries`);
|
|
209
472
|
}
|
|
210
|
-
|
|
211
|
-
const mods = safeGetModulesByFile(server, absolutePath);
|
|
212
|
-
if (mods && mods.size > 0) {
|
|
213
|
-
for (const mod of mods) {
|
|
214
|
-
safeInvalidateModule(server, mod);
|
|
215
|
-
safeSendHmrUpdate(server, {
|
|
216
|
-
type: "update",
|
|
217
|
-
updates: [
|
|
218
|
-
{
|
|
219
|
-
type: "js-update",
|
|
220
|
-
path: mod.url,
|
|
221
|
-
acceptedPath: mod.url,
|
|
222
|
-
timestamp: Date.now()
|
|
223
|
-
}
|
|
224
|
-
]
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
res.statusCode = 200;
|
|
229
|
-
res.end(JSON.stringify({ success: true }));
|
|
230
|
-
} catch (error) {
|
|
231
|
-
res.statusCode = 500;
|
|
232
|
-
res.end(JSON.stringify({ error: String(error) }));
|
|
473
|
+
virtualCodeMap.clear();
|
|
233
474
|
}
|
|
234
475
|
});
|
|
476
|
+
server.middlewares.use(createOverrideMiddleware(server));
|
|
477
|
+
server.middlewares.use(createSandboxScriptMiddleware(designModeOptions));
|
|
478
|
+
if (designModeOptions.enableVirtualCode) {
|
|
479
|
+
server.middlewares.use(createVirtualCodeMiddleware(server, designModeOptions, projectRoot));
|
|
480
|
+
console.log(`[DesignMode] Virtual code API enabled at ${designModeOptions.virtualCodeApiPath}`);
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
/**
|
|
484
|
+
* 转换 index.html:
|
|
485
|
+
* 1. 在 <body> 标签上注入组件库版本信息和编译插件版本
|
|
486
|
+
* 2. 注入 sandbox script(设计模式功能)
|
|
487
|
+
* 兼容 Vite 2.x - 6.x(transformIndexHtml 从 Vite 2 起就支持简单函数形式)
|
|
488
|
+
*/
|
|
489
|
+
transformIndexHtml(html) {
|
|
490
|
+
const metadata = (0, import_nocode_compiler_core.generateBodyMetadata)(pkgRegistry, version);
|
|
491
|
+
html = (0, import_nocode_compiler_core.injectBodyMetadata)(html, metadata);
|
|
492
|
+
html = injectSandboxScript(html);
|
|
493
|
+
return html;
|
|
235
494
|
},
|
|
236
495
|
/**
|
|
237
|
-
*
|
|
496
|
+
* 加载模块时,检查 override 和虚拟代码
|
|
238
497
|
*/
|
|
239
498
|
load(id) {
|
|
240
499
|
if (id.includes("node_modules")) return;
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
243
|
-
return
|
|
500
|
+
const overrideCode = loadOverrideCode(id);
|
|
501
|
+
if (overrideCode) {
|
|
502
|
+
return overrideCode;
|
|
503
|
+
}
|
|
504
|
+
if (designModeOptions.enableVirtualCode) {
|
|
505
|
+
return loadVirtualCode(id, designModeOptions);
|
|
244
506
|
}
|
|
245
507
|
return void 0;
|
|
246
508
|
},
|
|
@@ -249,6 +511,12 @@ function componentCompiler(options = {}) {
|
|
|
249
511
|
return code;
|
|
250
512
|
}
|
|
251
513
|
const [filePath, query] = id.split("?", 2);
|
|
514
|
+
if (!shouldSkipDesignModeTransform(id, designModeOptions)) {
|
|
515
|
+
const result = designModeCompiler.compile(code, filePath);
|
|
516
|
+
if (result) {
|
|
517
|
+
code = result.code;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
252
520
|
const { useJSXCompiler, useVueCompiler } = (0, import_nocode_compiler_core.detectCompileScenario)({
|
|
253
521
|
filePath,
|
|
254
522
|
query
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* 设计模式插件选项(Vite 特有配置)
|
|
5
|
+
*/
|
|
6
|
+
interface DesignModePluginOptions {
|
|
7
|
+
/** 是否启用虚拟代码 API,默认 true */
|
|
8
|
+
enableVirtualCode?: boolean;
|
|
9
|
+
/** 虚拟代码 API 路径,默认 '/api/virtual-code' */
|
|
10
|
+
virtualCodeApiPath?: string;
|
|
11
|
+
/** 是否启用详细日志,默认 false */
|
|
12
|
+
verbose?: boolean;
|
|
13
|
+
/** 要排除的文件模式,默认 [/node_modules/] */
|
|
14
|
+
exclude?: RegExp[];
|
|
15
|
+
/** 要包含的文件模式,默认 [/\.[jt]sx?$/] */
|
|
16
|
+
include?: RegExp[];
|
|
17
|
+
}
|
|
18
|
+
|
|
3
19
|
interface NocodeCompilerOptions {
|
|
20
|
+
/** 是否启用日志,默认 false */
|
|
4
21
|
enableLogging?: boolean;
|
|
22
|
+
/** 根路径配置 */
|
|
5
23
|
rootPath?: string;
|
|
24
|
+
/** 设计模式插件选项 */
|
|
25
|
+
designModeOptions?: DesignModePluginOptions;
|
|
6
26
|
}
|
|
7
27
|
declare function componentCompiler(options?: NocodeCompilerOptions): Plugin;
|
|
8
28
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* 设计模式插件选项(Vite 特有配置)
|
|
5
|
+
*/
|
|
6
|
+
interface DesignModePluginOptions {
|
|
7
|
+
/** 是否启用虚拟代码 API,默认 true */
|
|
8
|
+
enableVirtualCode?: boolean;
|
|
9
|
+
/** 虚拟代码 API 路径,默认 '/api/virtual-code' */
|
|
10
|
+
virtualCodeApiPath?: string;
|
|
11
|
+
/** 是否启用详细日志,默认 false */
|
|
12
|
+
verbose?: boolean;
|
|
13
|
+
/** 要排除的文件模式,默认 [/node_modules/] */
|
|
14
|
+
exclude?: RegExp[];
|
|
15
|
+
/** 要包含的文件模式,默认 [/\.[jt]sx?$/] */
|
|
16
|
+
include?: RegExp[];
|
|
17
|
+
}
|
|
18
|
+
|
|
3
19
|
interface NocodeCompilerOptions {
|
|
20
|
+
/** 是否启用日志,默认 false */
|
|
4
21
|
enableLogging?: boolean;
|
|
22
|
+
/** 根路径配置 */
|
|
5
23
|
rootPath?: string;
|
|
24
|
+
/** 设计模式插件选项 */
|
|
25
|
+
designModeOptions?: DesignModePluginOptions;
|
|
6
26
|
}
|
|
7
27
|
declare function componentCompiler(options?: NocodeCompilerOptions): Plugin;
|
|
8
28
|
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import { JSXCompiler, VueCompiler, DesignModeCompiler, detectCompileScenario, PackageVersionRegistry, MonitorService, MetricType, preloadDependencyVersions, generateBodyMetadata, injectBodyMetadata } from "@meituan-nocode/nocode-compiler-core";
|
|
3
|
+
|
|
4
|
+
// src/utils/index.ts
|
|
2
5
|
import { normalize, dirname, isAbsolute, join } from "path";
|
|
3
6
|
import { existsSync } from "fs";
|
|
4
|
-
import { JSXCompiler, VueCompiler, detectCompileScenario, PackageVersionRegistry, MonitorService, MetricType } from "@meituan-nocode/nocode-compiler-core";
|
|
5
|
-
|
|
6
|
-
// src/utils.ts
|
|
7
|
-
function readJsonBody(req) {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
let body = "";
|
|
10
|
-
req.on("data", (chunk) => {
|
|
11
|
-
body += chunk.toString();
|
|
12
|
-
});
|
|
13
|
-
req.on("end", () => {
|
|
14
|
-
try {
|
|
15
|
-
resolve(JSON.parse(body));
|
|
16
|
-
} catch (e) {
|
|
17
|
-
reject(e);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
req.on("error", reject);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// package.json
|
|
25
|
-
var version = "0.3.0";
|
|
26
7
|
|
|
27
|
-
// src/
|
|
8
|
+
// src/utils/vite-compat.ts
|
|
28
9
|
function getHotChannel(server) {
|
|
29
10
|
try {
|
|
30
11
|
if (server.hot && typeof server.hot.on === "function") {
|
|
@@ -46,7 +27,7 @@ function safeOnConnection(server, callback) {
|
|
|
46
27
|
channel.on("connection", callback);
|
|
47
28
|
return true;
|
|
48
29
|
} catch (e) {
|
|
49
|
-
console.warn("[
|
|
30
|
+
console.warn("[vite-compat] Error setting up connection listener:", e);
|
|
50
31
|
return false;
|
|
51
32
|
}
|
|
52
33
|
}
|
|
@@ -59,7 +40,7 @@ function safeSendHmrUpdate(server, payload) {
|
|
|
59
40
|
channel.send(payload);
|
|
60
41
|
return true;
|
|
61
42
|
} catch (e) {
|
|
62
|
-
console.warn("[
|
|
43
|
+
console.warn("[vite-compat] Error sending HMR update:", e);
|
|
63
44
|
return false;
|
|
64
45
|
}
|
|
65
46
|
}
|
|
@@ -70,7 +51,7 @@ function safeInvalidateModule(server, mod) {
|
|
|
70
51
|
return true;
|
|
71
52
|
}
|
|
72
53
|
} catch (e) {
|
|
73
|
-
console.warn("[
|
|
54
|
+
console.warn("[vite-compat] Error invalidating module:", e);
|
|
74
55
|
}
|
|
75
56
|
return false;
|
|
76
57
|
}
|
|
@@ -80,20 +61,59 @@ function safeGetModulesByFile(server, filePath) {
|
|
|
80
61
|
return server.moduleGraph.getModulesByFile(filePath) || null;
|
|
81
62
|
}
|
|
82
63
|
} catch (e) {
|
|
83
|
-
console.warn("[
|
|
64
|
+
console.warn("[vite-compat] Error getting modules by file:", e);
|
|
84
65
|
}
|
|
85
66
|
return null;
|
|
86
67
|
}
|
|
87
|
-
|
|
88
|
-
|
|
68
|
+
function triggerHmrUpdate(server, fullPath, verbose = false) {
|
|
69
|
+
const modules = server.moduleGraph.getModulesByFile(fullPath);
|
|
70
|
+
if (modules && modules.size > 0) {
|
|
71
|
+
for (const mod of modules) {
|
|
72
|
+
safeInvalidateModule(server, mod);
|
|
73
|
+
safeSendHmrUpdate(server, {
|
|
74
|
+
type: "update",
|
|
75
|
+
updates: [
|
|
76
|
+
{
|
|
77
|
+
type: "js-update",
|
|
78
|
+
path: mod.url,
|
|
79
|
+
acceptedPath: mod.url,
|
|
80
|
+
timestamp: Date.now()
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
if (verbose) {
|
|
85
|
+
console.log(`[vite-compat] HMR triggered for: ${mod.url}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
const mod = server.moduleGraph.getModuleById(fullPath);
|
|
90
|
+
if (mod) {
|
|
91
|
+
safeInvalidateModule(server, mod);
|
|
92
|
+
safeSendHmrUpdate(server, {
|
|
93
|
+
type: "update",
|
|
94
|
+
updates: [
|
|
95
|
+
{
|
|
96
|
+
type: "js-update",
|
|
97
|
+
path: mod.url,
|
|
98
|
+
acceptedPath: mod.url,
|
|
99
|
+
timestamp: Date.now()
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/utils/index.ts
|
|
108
|
+
function resolveFileToAbsPath(file, rootDir) {
|
|
89
109
|
if (isAbsolute(file)) {
|
|
90
110
|
return existsSync(file) ? normalize(file) : null;
|
|
91
111
|
}
|
|
92
|
-
const fromRoot = join(
|
|
112
|
+
const fromRoot = join(rootDir, file);
|
|
93
113
|
if (existsSync(fromRoot)) {
|
|
94
114
|
return normalize(fromRoot);
|
|
95
115
|
}
|
|
96
|
-
let dir =
|
|
116
|
+
let dir = rootDir;
|
|
97
117
|
while (true) {
|
|
98
118
|
const candidate = join(dir, file);
|
|
99
119
|
if (existsSync(candidate)) {
|
|
@@ -105,6 +125,254 @@ function resolveFileToAbsPath(file, viteRoot) {
|
|
|
105
125
|
}
|
|
106
126
|
return null;
|
|
107
127
|
}
|
|
128
|
+
function readJsonBody(req) {
|
|
129
|
+
return new Promise((resolve2, reject) => {
|
|
130
|
+
let body = "";
|
|
131
|
+
req.on("data", (chunk) => {
|
|
132
|
+
body += chunk.toString();
|
|
133
|
+
});
|
|
134
|
+
req.on("end", () => {
|
|
135
|
+
try {
|
|
136
|
+
resolve2(JSON.parse(body));
|
|
137
|
+
} catch (e) {
|
|
138
|
+
reject(e);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
req.on("error", reject);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// package.json
|
|
146
|
+
var version = "0.3.1-beta.1";
|
|
147
|
+
|
|
148
|
+
// src/design-mode/types.ts
|
|
149
|
+
var SANDBOX_SCRIPT_PATH = "/sandbox-script.js";
|
|
150
|
+
var VIRTUAL_CODE_API_PATH = "/api/virtual-code";
|
|
151
|
+
var DEFAULT_DESIGN_MODE_OPTIONS = {
|
|
152
|
+
enableVirtualCode: true,
|
|
153
|
+
virtualCodeApiPath: VIRTUAL_CODE_API_PATH,
|
|
154
|
+
verbose: false,
|
|
155
|
+
exclude: [/node_modules/],
|
|
156
|
+
include: [/\.[jt]sx?$/]
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/design-mode/virtual-code.ts
|
|
160
|
+
import * as path from "path";
|
|
161
|
+
var virtualCodeMap = /* @__PURE__ */ new Map();
|
|
162
|
+
function matchesDesignModePattern(id, options) {
|
|
163
|
+
const exclude = options.exclude || [];
|
|
164
|
+
const include = options.include || [];
|
|
165
|
+
if (exclude.some((re) => re.test(id))) return false;
|
|
166
|
+
if (!include.some((re) => re.test(id))) return false;
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
function extractRelativePath(id) {
|
|
170
|
+
const srcIndex = id.indexOf("/src/");
|
|
171
|
+
return srcIndex !== -1 ? id.slice(srcIndex + 1) : null;
|
|
172
|
+
}
|
|
173
|
+
function hasVirtualCode(id) {
|
|
174
|
+
const relativePath = extractRelativePath(id);
|
|
175
|
+
if (!relativePath) return false;
|
|
176
|
+
return virtualCodeMap.has(relativePath) || virtualCodeMap.has("/" + relativePath);
|
|
177
|
+
}
|
|
178
|
+
function shouldSkipDesignModeTransform(id, options) {
|
|
179
|
+
if (!matchesDesignModePattern(id, options)) return true;
|
|
180
|
+
if (hasVirtualCode(id)) return true;
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
function loadVirtualCode(id, options) {
|
|
184
|
+
if (!matchesDesignModePattern(id, options)) return void 0;
|
|
185
|
+
const relativePath = extractRelativePath(id);
|
|
186
|
+
if (!relativePath) return void 0;
|
|
187
|
+
const code = virtualCodeMap.get(relativePath) || virtualCodeMap.get("/" + relativePath);
|
|
188
|
+
if (code && options.verbose) {
|
|
189
|
+
console.log(`[DesignMode] Using virtual code for: ${relativePath}`);
|
|
190
|
+
}
|
|
191
|
+
return code;
|
|
192
|
+
}
|
|
193
|
+
function createVirtualCodeMiddleware(server, options, projectRoot) {
|
|
194
|
+
var _a;
|
|
195
|
+
const apiPath = options.virtualCodeApiPath || VIRTUAL_CODE_API_PATH;
|
|
196
|
+
const verbose = (_a = options.verbose) != null ? _a : false;
|
|
197
|
+
return (req, res, next) => {
|
|
198
|
+
var _a2;
|
|
199
|
+
if (!((_a2 = req.url) == null ? void 0 : _a2.startsWith(apiPath))) {
|
|
200
|
+
return next();
|
|
201
|
+
}
|
|
202
|
+
if (req.method === "OPTIONS") {
|
|
203
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
204
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
|
205
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
206
|
+
res.statusCode = 204;
|
|
207
|
+
res.end();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
res.setHeader("Content-Type", "application/json");
|
|
211
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
212
|
+
if (req.method === "POST") {
|
|
213
|
+
let body = "";
|
|
214
|
+
req.on("data", (chunk) => body += chunk.toString());
|
|
215
|
+
req.on("end", () => {
|
|
216
|
+
try {
|
|
217
|
+
const { filePath, content } = JSON.parse(body);
|
|
218
|
+
virtualCodeMap.set(filePath, content);
|
|
219
|
+
if (verbose) {
|
|
220
|
+
console.log(`[DnD] Virtual code set for: ${filePath}`);
|
|
221
|
+
}
|
|
222
|
+
const fullPath = path.resolve(projectRoot, filePath);
|
|
223
|
+
triggerHmrUpdate(server, fullPath, verbose);
|
|
224
|
+
res.end(JSON.stringify({ success: true, filePath }));
|
|
225
|
+
} catch (error) {
|
|
226
|
+
res.statusCode = 500;
|
|
227
|
+
res.end(JSON.stringify({ error: String(error) }));
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (req.method === "GET") {
|
|
233
|
+
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
234
|
+
const filePath = url.searchParams.get("path");
|
|
235
|
+
if (filePath) {
|
|
236
|
+
const content = virtualCodeMap.get(filePath);
|
|
237
|
+
res.statusCode = content ? 200 : 404;
|
|
238
|
+
res.end(JSON.stringify(content ? { content } : { error: "Not found" }));
|
|
239
|
+
} else {
|
|
240
|
+
res.end(JSON.stringify({ paths: Array.from(virtualCodeMap.keys()) }));
|
|
241
|
+
}
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (req.method === "DELETE") {
|
|
245
|
+
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
246
|
+
const filePath = url.searchParams.get("path");
|
|
247
|
+
const pathsToInvalidate = filePath ? [filePath] : Array.from(virtualCodeMap.keys());
|
|
248
|
+
filePath ? virtualCodeMap.delete(filePath) : virtualCodeMap.clear();
|
|
249
|
+
if (verbose) {
|
|
250
|
+
console.log(`[DnD] Virtual code ${filePath ? `cleared for: ${filePath}` : "all cleared"}`);
|
|
251
|
+
}
|
|
252
|
+
for (const p of pathsToInvalidate) {
|
|
253
|
+
const fullPath = path.resolve(projectRoot, p);
|
|
254
|
+
triggerHmrUpdate(server, fullPath, verbose);
|
|
255
|
+
}
|
|
256
|
+
res.end(JSON.stringify({ success: true, clearedPaths: pathsToInvalidate }));
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
res.statusCode = 405;
|
|
260
|
+
res.end(JSON.stringify({ error: "Method not allowed" }));
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// src/design-mode/sandbox-script.ts
|
|
265
|
+
function getSandboxScriptContent() {
|
|
266
|
+
return '(()=>{var e={572(e,t,n){var r=n(736).Symbol;e.exports=r},561(e,t,n){var r=n(572),o=n(504),i=n(567),s=r?r.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":s&&s in Object(e)?o(e):i(e)}},605(e,t,n){var r=n(327),o=/^\\s+/;e.exports=function(e){return e?e.slice(0,r(e)+1).replace(o,""):e}},433(e,t,n){var r="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g;e.exports=r},504(e,t,n){var r=n(572),o=Object.prototype,i=o.hasOwnProperty,s=o.toString,a=r?r.toStringTag:void 0;e.exports=function(e){var t=i.call(e,a),n=e[a];try{e[a]=void 0;var r=!0}catch(e){}var o=s.call(e);return r&&(t?e[a]=n:delete e[a]),o}},567(e){var t=Object.prototype.toString;e.exports=function(e){return t.call(e)}},736(e,t,n){var r=n(433),o="object"==typeof self&&self&&self.Object===Object&&self,i=r||o||Function("return this")();e.exports=i},327(e){var t=/\\s/;e.exports=function(e){for(var n=e.length;n--&&t.test(e.charAt(n)););return n}},702(e,t,n){var r=n(230),o=n(381),i=n(569),s=Math.max,a=Math.min;e.exports=function(e,t,n){var c,u,l,d,f,h,p=0,g=!1,m=!1,v=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){var n=c,r=u;return c=u=void 0,p=t,d=e.apply(r,n)}function w(e){var n=e-h;return void 0===h||n>=t||n<0||m&&e-p>=l}function b(){var e=o();if(w(e))return E(e);f=setTimeout(b,function(e){var n=t-(e-h);return m?a(n,l-(e-p)):n}(e))}function E(e){return f=void 0,v&&c?y(e):(c=u=void 0,d)}function N(){var e=o(),n=w(e);if(c=arguments,u=this,h=e,n){if(void 0===f)return function(e){return p=e,f=setTimeout(b,t),g?y(e):d}(h);if(m)return clearTimeout(f),f=setTimeout(b,t),y(h)}return void 0===f&&(f=setTimeout(b,t)),d}return t=i(t)||0,r(n)&&(g=!!n.leading,l=(m="maxWait"in n)?s(i(n.maxWait)||0,t):l,v="trailing"in n?!!n.trailing:v),N.cancel=function(){void 0!==f&&clearTimeout(f),p=0,c=h=u=f=void 0},N.flush=function(){return void 0===f?d:E(o())},N}},230(e){e.exports=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}},470(e){e.exports=function(e){return null!=e&&"object"==typeof e}},89(e,t,n){var r=n(561),o=n(470);e.exports=function(e){return"symbol"==typeof e||o(e)&&"[object Symbol]"==r(e)}},381(e,t,n){var r=n(736);e.exports=function(){return r.Date.now()}},569(e,t,n){var r=n(605),o=n(230),i=n(89),s=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,c=/^0o[0-7]+$/i,u=parseInt;e.exports=function(e){if("number"==typeof e)return e;if(i(e))return NaN;if(o(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=o(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=r(e);var n=a.test(e);return n||c.test(e)?u(e.slice(2),n?2:8):s.test(e)?NaN:+e}}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";var e=n(702),t=n.n(e),r=class extends Error{code;constructor(e,t){super(t),this.name="PenpalError",this.code=e}},o=e=>({name:e.name,message:e.message,stack:e.stack,penpalCode:e instanceof r?e.code:void 0}),i=Symbol("Reply"),s=class{value;transferables;#e=i;constructor(e,t){this.value=e,this.transferables=t?.transferables}},a="penpal",c=e=>"object"==typeof e&&null!==e,u=e=>"function"==typeof e,l=e=>"SYN"===e.type,d=e=>"ACK1"===e.type,f=e=>"ACK2"===e.type,h=e=>"CALL"===e.type,p=e=>"REPLY"===e.type,g=(e,t=[])=>{const n=[];for(const r of Object.keys(e)){const o=e[r];u(o)?n.push([...t,r]):c(o)&&n.push(...g(o,[...t,r]))}return n},m=e=>e.join("."),v=(e,t,n)=>({namespace:a,channel:e,type:"REPLY",callId:t,isError:!0,...n instanceof Error?{value:o(n),isSerializedErrorInstance:!0}:{value:n}}),y=crypto.randomUUID?.bind(crypto)??(()=>new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")),w=Symbol("CallOptions"),b=class{transferables;timeout;#e=w;constructor(e){this.transferables=e?.transferables,this.timeout=e?.timeout}},E=new Set(["apply","call","bind"]),N=(e,t,n=[])=>new Proxy(n.length?()=>{}:Object.create(null),{get(r,o){if("then"!==o)return n.length&&E.has(o)?Reflect.get(r,o):N(e,t,[...n,o])},apply:(t,r,o)=>e(n,o)}),C=e=>new r("CONNECTION_DESTROYED",`Method call ${m(e)}() failed due to destroyed connection`),S=class extends Error{constructor(e){super(`You\'ve hit a bug in Penpal. Please file an issue with the following information: ${e}`)}},x="deprecated-penpal",O=e=>e.join("."),P=e=>new S(`Unexpected message to translate: ${JSON.stringify(e)}`),T=({messenger:e,methods:t,timeout:n,channel:o,log:i})=>{const w=y();let E;const S=[];let O=!1;const P=g(t),{promise:T,resolve:M,reject:I}=(()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}})(),A=void 0!==n?setTimeout(()=>{I(new r("CONNECTION_TIMEOUT",`Connection timed out after ${n}ms`))},n):void 0,R=()=>{for(const e of S)e()},L=()=>{if(O)return;S.push(((e,t,n,o)=>{let i=!1;const l=async l=>{if(i)return;if(!h(l))return;o?.(`Received ${m(l.methodPath)}() call`,l);const{methodPath:d,args:f,id:p}=l;let g,y;try{const e=((e,t)=>{const n=e.reduce((e,t)=>c(e)?e[t]:void 0,t);return u(n)?n:void 0})(d,t);if(!e)throw new r("METHOD_NOT_FOUND",`Method \\`${m(d)}\\` is not found.`);let o=await e(...f);o instanceof s&&(y=o.transferables,o=await o.value),g={namespace:a,channel:n,type:"REPLY",callId:p,value:o}}catch(e){g=v(n,p,e)}if(!i)try{o?.(`Sending ${m(d)}() reply`,g),e.sendMessage(g,y)}catch(t){throw"DataCloneError"===t.name&&(g=v(n,p,t),o?.(`Sending ${m(d)}() reply`,g),e.sendMessage(g)),t}};return e.addMessageHandler(l),()=>{i=!0,e.removeMessageHandler(l)}})(e,t,o,i));const{remoteProxy:n,destroy:l}=((e,t,n)=>{let o=!1;const i=new Map,s=e=>{if(!p(e))return;const{callId:t,value:o,isError:s,isSerializedErrorInstance:a}=e,c=i.get(t);c&&(i.delete(t),n?.(`Received ${m(c.methodPath)}() call`,e),s?c.reject(a?(({name:e,message:t,stack:n,penpalCode:o})=>{const i=o?new r(o,t):new Error(t);return i.name=e,i.stack=n,i})(o):o):c.resolve(o))};return e.addMessageHandler(s),{remoteProxy:N((s,c)=>{if(o)throw C(s);const u=y(),l=c[c.length-1],d=l instanceof b,{timeout:f,transferables:h}=d?l:{},p=d?c.slice(0,-1):c;return new Promise((o,c)=>{const l=void 0!==f?window.setTimeout(()=>{i.delete(u),c(new r("METHOD_CALL_TIMEOUT",`Method call ${m(s)}() timed out after ${f}ms`))},f):void 0;i.set(u,{methodPath:s,resolve:o,reject:c,timeoutId:l});try{const r={namespace:a,channel:t,type:"CALL",id:u,methodPath:s,args:p};n?.(`Sending ${m(s)}() call`,r),e.sendMessage(r,h)}catch(e){c(new r("TRANSMISSION_FAILED",e.message))}})},n),destroy:()=>{o=!0,e.removeMessageHandler(s);for(const{methodPath:e,reject:t,timeoutId:n}of i.values())clearTimeout(n),t(C(e));i.clear()}}})(e,o,i);S.push(l),clearTimeout(A),O=!0,M({remoteProxy:n,destroy:R})},D=()=>{const t={namespace:a,type:"SYN",channel:o,participantId:w};i?.("Sending handshake SYN",t);try{e.sendMessage(t)}catch(e){I(new r("TRANSMISSION_FAILED",e.message))}},F=t=>{l(t)&&(t=>{if(i?.("Received handshake SYN",t),t.participantId===E&&E!==x)return;if(E=t.participantId,D(),!(w>E||E===x))return;const n={namespace:a,channel:o,type:"ACK1",methodPaths:P};i?.("Sending handshake ACK1",n);try{e.sendMessage(n)}catch(e){return void I(new r("TRANSMISSION_FAILED",e.message))}})(t),d(t)&&(t=>{i?.("Received handshake ACK1",t);const n={namespace:a,channel:o,type:"ACK2"};i?.("Sending handshake ACK2",n);try{e.sendMessage(n)}catch(e){return void I(new r("TRANSMISSION_FAILED",e.message))}L()})(t),f(t)&&(e=>{i?.("Received handshake ACK2",e),L()})(t)};return e.addMessageHandler(F),S.push(()=>e.removeMessageHandler(F)),D(),T},M=new WeakSet,I=class{#t;#n;#r;#o;#i;#s=new Set;#a;#c=!1;constructor({remoteWindow:e,allowedOrigins:t}){if(!e)throw new r("INVALID_ARGUMENT","remoteWindow must be defined");this.#t=e,this.#n=t?.length?t:[window.origin]}initialize=({log:e,validateReceivedMessage:t})=>{this.#r=e,this.#o=t,window.addEventListener("message",this.#u)};sendMessage=(e,t)=>{if(l(e)){const n=this.#l(e);return void this.#t.postMessage(e,{targetOrigin:n,transfer:t})}if(d(e)||this.#c){const n=this.#c?(e=>{if(d(e))return{penpal:"synAck",methodNames:e.methodPaths.map(O)};if(h(e))return{penpal:"call",id:e.id,methodName:O(e.methodPath),args:e.args};if(p(e))return e.isError?{penpal:"reply",id:e.callId,resolution:"rejected",...e.isSerializedErrorInstance?{returnValue:e.value,returnValueIsError:!0}:{returnValue:e.value}}:{penpal:"reply",id:e.callId,resolution:"fulfilled",returnValue:e.value};throw P(e)})(e):e,r=this.#l(e);return void this.#t.postMessage(n,{targetOrigin:r,transfer:t})}if(f(e)){const{port1:n,port2:r}=new MessageChannel;this.#a=n,n.addEventListener("message",this.#d),n.start();const o=[r,...t||[]],i=this.#l(e);return void this.#t.postMessage(e,{targetOrigin:i,transfer:o})}if(!this.#a)throw new S("Port is undefined");this.#a.postMessage(e,{transfer:t})};addMessageHandler=e=>{this.#s.add(e)};removeMessageHandler=e=>{this.#s.delete(e)};destroy=()=>{window.removeEventListener("message",this.#u),this.#f(),this.#s.clear()};#h=e=>this.#n.some(t=>t instanceof RegExp?t.test(e):t===e||"*"===t);#l=e=>{if(l(e))return"*";if(!this.#i)throw new S("Concrete remote origin not set");return"null"===this.#i&&this.#n.includes("*")?"*":this.#i};#f=()=>{this.#a?.removeEventListener("message",this.#d),this.#a?.close(),this.#a=void 0};#u=({source:e,origin:t,ports:n,data:r})=>{if(e===this.#t&&((e=>c(e)&&"penpal"in e)(r)&&(this.#r?.("Please upgrade the child window to the latest version of Penpal."),this.#c=!0,r=(e=>{if("syn"===e.penpal)return{namespace:a,channel:void 0,type:"SYN",participantId:x};if("ack"===e.penpal)return{namespace:a,channel:void 0,type:"ACK2"};if("call"===e.penpal)return{namespace:a,channel:void 0,type:"CALL",id:e.id,methodPath:(t=e.methodName,t.split(".")),args:e.args};var t;if("reply"===e.penpal)return"fulfilled"===e.resolution?{namespace:a,channel:void 0,type:"REPLY",callId:e.id,value:e.returnValue}:{namespace:a,channel:void 0,type:"REPLY",callId:e.id,isError:!0,...e.returnValueIsError?{value:e.returnValue,isSerializedErrorInstance:!0}:{value:e.returnValue}};throw P(e)})(r)),this.#o?.(r)))if(this.#h(t)){if(l(r)&&(this.#f(),this.#i=t),f(r)&&!this.#c){if(this.#a=n[0],!this.#a)throw new S("No port received on ACK2");this.#a.addEventListener("message",this.#d),this.#a.start()}for(const e of this.#s)e(r)}else this.#r?.(`Received a message from origin \\`${t}\\` which did not match allowed origins \\`[${this.#n.join(", ")}]\\``)};#d=({data:e})=>{if(this.#o?.(e))for(const t of this.#s)t(e)}},A=document,R=window,L=Array.prototype,D=L.filter,F=L.indexOf,j=L.map,$=L.push,_=L.reverse,k=L.slice,W=L.splice,z=/^#[\\w-]*$/,U=/^\\.[\\w-]*$/,V=/<.+>/,H=/^\\w+$/;function B(e,t){return void 0===t&&(t=A),U.test(e)?t.getElementsByClassName(e.slice(1)):H.test(e)?t.getElementsByTagName(e):t.querySelectorAll(e)}function Y(e,t){if(void 0===t&&(t=A),e){if(e.__cash)return e;var n=e;if(ne(e)){if(t.__cash&&(t=t[0]),!(n=z.test(e)?t.getElementById(e.slice(1)):V.test(e)?ke(e):B(e,t)))return}else if(te(e))return this.ready(e);(n.nodeType||n===R)&&(n=[n]),this.length=n.length;for(var r=0,o=this.length;r<o;r++)this[r]=n[r]}}function K(e,t){return new Y(e,t)}var q=K.fn=K.prototype=Y.prototype={constructor:K,__cash:!0,length:0,splice:W};q.get=function(e){return void 0===e?k.call(this):this[e<0?e+this.length:e]},q.eq=function(e){return K(this.get(e))},q.first=function(){return this.eq(0)},q.last=function(){return this.eq(-1)},q.map=function(e){return K(j.call(this,function(t,n){return e.call(t,n,t)}))},q.slice=function(){return K(k.apply(this,arguments))};var G=/(?:^\\w|[A-Z]|\\b\\w)/g,X=/[\\s-_]+/g;function J(e){return e.replace(G,function(e,t){return e[t?"toUpperCase":"toLowerCase"]()}).replace(X,"")}function Z(e,t){for(var n=0,r=e.length;n<r&&!1!==t.call(e[n],e[n],n,e);n++);}K.camelCase=J,K.each=Z,q.each=function(e){return Z(this,function(t,n){return e.call(t,n,t)}),this},q.removeProp=function(e){return this.each(function(t,n){delete n[e]})},K.extend=q.extend=function(e){void 0===e&&(e=this);for(var t=arguments,n=t.length,r=n<2?0:1;r<n;r++)for(var o in t[r])e[o]=t[r][o];return e};var Q=1;function ee(e,t){var n=e&&(e.matches||e.webkitMatchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector);return!!n&&n.call(e,t)}function te(e){return"function"==typeof e}function ne(e){return"string"==typeof e}function re(e){return!isNaN(parseFloat(e))&&isFinite(e)}K.guid=Q,K.matches=ee,K.isFunction=te,K.isString=ne,K.isNumeric=re;var oe=Array.isArray;function ie(e){return ne(e)?function(t,n){return ee(n,e)}:e.__cash?function(t,n){return e.is(n)}:function(e,t,n){return t===n}}K.isArray=oe,q.prop=function(e,t){if(e){if(ne(e))return arguments.length<2?this[0]&&this[0][e]:this.each(function(n,r){r[e]=t});for(var n in e)this.prop(n,e[n]);return this}},q.filter=function(e){if(!e)return K();var t=te(e)?e:ie(e);return K(D.call(this,function(n,r){return t.call(n,r,n,e)}))};var se=/\\S+/g;function ae(e){return ne(e)&&e.match(se)||[]}function ce(e){return e.filter(function(e,t,n){return n.indexOf(e)===t})}function ue(e,t,n){if(1===e.nodeType){var r=R.getComputedStyle(e,null);return t?n?r.getPropertyValue(t):r[t]:r}}function le(e,t){return parseInt(ue(e,t),10)||0}q.hasClass=function(e){var t=ae(e),n=!1;return t.length&&this.each(function(e,r){return!(n=r.classList.contains(t[0]))}),n},q.removeAttr=function(e){var t=ae(e);return t.length?this.each(function(e,n){Z(t,function(e){n.removeAttribute(e)})}):this},q.attr=function(e,t){if(e){if(ne(e)){if(arguments.length<2){if(!this[0])return;var n=this[0].getAttribute(e);return null===n?void 0:n}return null===t?this.removeAttr(e):this.each(function(n,r){r.setAttribute(e,t)})}for(var r in e)this.attr(r,e[r]);return this}},q.toggleClass=function(e,t){var n=ae(e),r=void 0!==t;return n.length?this.each(function(e,o){Z(n,function(e){r?t?o.classList.add(e):o.classList.remove(e):o.classList.toggle(e)})}):this},q.addClass=function(e){return this.toggleClass(e,!0)},q.removeClass=function(e){return arguments.length?this.toggleClass(e,!1):this.attr("class","")},K.unique=ce,q.add=function(e,t){return K(ce(this.get().concat(K(e,t).get())))};var de=/^--/;function fe(e){return de.test(e)}var he={},pe=A.createElement("div").style,ge=["webkit","moz","ms","o"];function me(e,t){if(void 0===t&&(t=fe(e)),t)return e;if(!he[e]){var n=J(e),r=""+n.charAt(0).toUpperCase()+n.slice(1);Z((n+" "+ge.join(r+" ")+r).split(" "),function(t){if(t in pe)return he[e]=t,!1})}return he[e]}K.prefixedProp=me;var ve={animationIterationCount:!0,columnCount:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0};function ye(e,t,n){return void 0===n&&(n=fe(e)),n||ve[e]||!re(t)?t:t+"px"}q.css=function(e,t){if(ne(e)){var n=fe(e);return e=me(e,n),arguments.length<2?this[0]&&ue(this[0],e,n):e?(t=ye(e,t,n),this.each(function(r,o){1===o.nodeType&&(n?o.style.setProperty(e,t):o.style[e]=t)})):this}for(var r in e)this.css(r,e[r]);return this};var we="__cashData",be=/^data-(.*)/;function Ee(e){return e[we]=e[we]||{}}function Ne(e,t){var n=Ee(e);if(t){if(!(t in n)){var r=e.dataset?e.dataset[t]||e.dataset[J(t)]:K(e).attr("data-"+t);if(void 0!==r){try{r=JSON.parse(r)}catch(e){}n[t]=r}}return n[t]}return n}function Ce(e,t){return le(e,"border"+(t?"Left":"Top")+"Width")+le(e,"padding"+(t?"Left":"Top"))+le(e,"padding"+(t?"Right":"Bottom"))+le(e,"border"+(t?"Right":"Bottom")+"Width")}function Se(e,t){for(var n=0,r=t.length;n<r;n++)if(e.indexOf(t[n])<0)return!1;return!0}function xe(e,t,n){Z(e[n],function(e){e[0];var r=e[1];t.removeEventListener(n,r)}),delete e[n]}K.hasData=function(e){return we in e},q.data=function(e,t){var n=this;if(!e){if(!this[0])return;return Z(this[0].attributes,function(e){var t=e.name.match(be);t&&n.data(t[1])}),Ne(this[0])}if(ne(e))return void 0===t?this[0]&&Ne(this[0],e):this.each(function(n,r){return function(e,t,n){Ee(e)[t]=n}(r,e,t)});for(var r in e)this.data(r,e[r]);return this},q.removeData=function(e){return this.each(function(t,n){return function(e,t){void 0===t?delete e[we]:delete Ee(e)[t]}(n,e)})},Z(["Width","Height"],function(e){q["inner"+e]=function(){if(this[0])return this[0]===R?R["inner"+e]:this[0]["client"+e]}}),Z(["width","height"],function(e,t){q[e]=function(n){return this[0]?arguments.length?(n=parseInt(n,10),this.each(function(r,o){if(1===o.nodeType){var i=ue(o,"boxSizing");o.style[e]=ye(e,n+("border-box"===i?Ce(o,!t):0))}})):this[0]===R?this[0][J("outer-"+e)]:this[0].getBoundingClientRect()[e]-Ce(this[0],!t):void 0===n?void 0:this}}),Z(["Width","Height"],function(e,t){q["outer"+e]=function(n){if(this[0])return this[0]===R?R["outer"+e]:this[0]["offset"+e]+(n?le(this[0],"margin"+(t?"Top":"Left"))+le(this[0],"margin"+(t?"Bottom":"Right")):0)}});var Oe="__cashEvents";function Pe(e){return e[Oe]=e[Oe]||{}}function Te(e){var t=e.split(".");return[t[0],t.slice(1).sort()]}function Me(e,t,n,r){var o=Pe(e);if(t){var i=o[t];if(!i)return;r&&(r.guid=r.guid||Q++),o[t]=i.filter(function(o){var i=o[0],s=o[1];if(r&&s.guid!==r.guid||!Se(i,n))return!0;e.removeEventListener(t,s)})}else if(n&&n.length)for(t in o)Me(e,t,n,r);else for(t in o)xe(o,e,t)}q.off=function(e,t){var n=this;return void 0===e?this.each(function(e,t){return Me(t)}):Z(ae(e),function(e){var r=Te(e),o=r[0],i=r[1];n.each(function(e,n){return Me(n,o,i,t)})}),this},q.on=function(e,t,n,r){var o=this;if(!ne(e)){for(var i in e)this.on(i,t,e[i]);return this}return te(t)&&(n=t,t=!1),Z(ae(e),function(e){var i=Te(e),s=i[0],a=i[1];o.each(function(e,o){var i=function e(i){if(!i.namespace||Se(a,i.namespace.split("."))){var c=o;if(t){for(var u=i.target;!ee(u,t);){if(u===o)return;if(!(u=u.parentNode))return}c=u}i.namespace=i.namespace||"";var l=n.call(c,i,i.data);r&&Me(o,s,a,e),!1===l&&(i.preventDefault(),i.stopPropagation())}};i.guid=n.guid=n.guid||Q++,function(e,t,n,r){r.guid=r.guid||Q++;var o=Pe(e);o[t]=o[t]||[],o[t].push([n,r]),e.addEventListener(t,r)}(o,s,a,i)})}),this},q.one=function(e,t,n){return this.on(e,t,n,!0)},q.ready=function(e){var t=function(){return e(K)};return"loading"!==A.readyState?setTimeout(t):A.addEventListener("DOMContentLoaded",t),this},q.trigger=function(e,t){var n=e;if(ne(e)){var r=Te(e),o=r[0],i=r[1];(n=A.createEvent("HTMLEvents")).initEvent(o,!0,!0),n.namespace=i.join(".")}return n.data=t,this.each(function(e,t){t.dispatchEvent(n)})};var Ie=/select-one/i,Ae=/select-multiple/i;function Re(e){var t=e.type;return Ie.test(t)?function(e){return e.selectedIndex<0?null:e.options[e.selectedIndex].value}(e):Ae.test(t)?function(e){var t=[];return Z(e.options,function(e){!e.selected||e.disabled||e.parentNode.disabled||t.push(e.value)}),t}(e):e.value}var Le=/%20/g,De=/file|reset|submit|button|image/i,Fe=/radio|checkbox/i;q.serialize=function(){var e="";return this.each(function(t,n){Z(n.elements||[n],function(t){if(!t.disabled&&t.name&&"FIELDSET"!==t.tagName&&!De.test(t.type)&&(!Fe.test(t.type)||t.checked)){var n=Re(t);void 0!==n&&Z(oe(n)?n:[n],function(n){e+=function(e,t){return"&"+encodeURIComponent(e)+"="+encodeURIComponent(t).replace(Le,"+")}(t.name,n)})}})}),e.substr(1)},q.val=function(e){return void 0===e?this[0]&&Re(this[0]):this.each(function(t,n){var r=Ae.test(n.type),o=null===e?r?[]:"":e;r&&oe(o)?Z(n.options,function(e){e.selected=o.indexOf(e.value)>=0}):n.value=o})},q.clone=function(){return this.map(function(e,t){return t.cloneNode(!0)})},q.detach=function(){return this.each(function(e,t){t.parentNode&&t.parentNode.removeChild(t)})};var je,$e=/^\\s*<(\\w+)[^>]*>/,_e=/^\\s*<(\\w+)\\s*\\/?>(?:<\\/\\1>)?\\s*$/;function ke(e){if(function(){if(!je){var e=A.createElement("table"),t=A.createElement("tr");je={"*":A.createElement("div"),tr:A.createElement("tbody"),td:t,th:t,thead:e,tbody:e,tfoot:e}}}(),!ne(e))return[];if(_e.test(e))return[A.createElement(RegExp.$1)];var t=$e.test(e)&&RegExp.$1,n=je[t]||je["*"];return n.innerHTML=e,K(n.childNodes).detach().get()}function We(e,t,n){if(void 0!==t){var r=ne(t);!r&&t.length?Z(t,function(t){return We(e,t,n)}):Z(e,r?function(e){e.insertAdjacentHTML(n?"afterbegin":"beforeend",t)}:function(e,r){return function(e,t,n){n?e.insertBefore(t,e.childNodes[0]):e.appendChild(t)}(e,r?t.cloneNode(!0):t,n)})}}K.parseHTML=ke,q.empty=function(){var e=this[0];if(e)for(;e.firstChild;)e.removeChild(e.firstChild);return this},q.append=function(){var e=this;return Z(arguments,function(t){We(e,t)}),this},q.appendTo=function(e){return We(K(e),this),this},q.html=function(e){if(void 0===e)return this[0]&&this[0].innerHTML;var t=e.nodeType?e[0].outerHTML:e;return this.each(function(e,n){n.innerHTML=t})},q.insertAfter=function(e){var t=this;return K(e).each(function(e,n){var r=n.parentNode;t.each(function(t,o){r.insertBefore(e?o.cloneNode(!0):o,n.nextSibling)})}),this},q.after=function(){var e=this;return Z(_.apply(arguments),function(t){_.apply(K(t).slice()).insertAfter(e)}),this},q.insertBefore=function(e){var t=this;return K(e).each(function(e,n){var r=n.parentNode;t.each(function(t,o){r.insertBefore(e?o.cloneNode(!0):o,n)})}),this},q.before=function(){var e=this;return Z(arguments,function(t){K(t).insertBefore(e)}),this},q.prepend=function(){var e=this;return Z(arguments,function(t){We(e,t,!0)}),this},q.prependTo=function(e){return We(K(e),_.apply(this.slice()),!0),this},q.remove=function(){return this.detach().off()},q.replaceWith=function(e){var t=this;return this.each(function(n,r){var o=r.parentNode;if(o){var i=n?K(e).clone():K(e);if(!i[0])return t.remove(),!1;o.replaceChild(i[0],r),K(i[0]).after(i.slice(1))}})},q.replaceAll=function(e){return K(e).replaceWith(this),this},q.text=function(e){return void 0===e?this[0]?this[0].textContent:"":this.each(function(t,n){n.textContent=e})};var ze=A.documentElement;q.offset=function(){var e=this[0];if(e){var t=e.getBoundingClientRect();return{top:t.top+R.pageYOffset-ze.clientTop,left:t.left+R.pageXOffset-ze.clientLeft}}},q.offsetParent=function(){return K(this[0]&&this[0].offsetParent)},q.position=function(){var e=this[0];if(e)return{left:e.offsetLeft,top:e.offsetTop}},q.children=function(e){var t=[];return this.each(function(e,n){$.apply(t,n.children)}),t=K(ce(t)),e?t.filter(function(t,n){return ee(n,e)}):t},q.contents=function(){var e=[];return this.each(function(t,n){$.apply(e,"IFRAME"===n.tagName?[n.contentDocument]:n.childNodes)}),K(e.length&&ce(e))},q.find=function(e){for(var t=[],n=0,r=this.length;n<r;n++){var o=B(e,this[n]);o.length&&$.apply(t,o)}return K(t.length&&ce(t))},q.has=function(e){var t=ne(e)?function(t,n){return!!B(e,n).length}:function(t,n){return n.contains(e)};return this.filter(t)},q.is=function(e){if(!e||!this[0])return!1;var t=ie(e),n=!1;return this.each(function(r,o){return!(n=t(r,o,e))}),n},q.next=function(){return K(this[0]&&this[0].nextElementSibling)},q.not=function(e){if(!e||!this[0])return this;var t=ie(e);return this.filter(function(n,r){return!t(n,r,e)})},q.parent=function(){var e=[];return this.each(function(t,n){n&&n.parentNode&&e.push(n.parentNode)}),K(ce(e))},q.index=function(e){var t=e?K(e)[0]:this[0],n=e?this:K(t).parent().children();return F.call(n,t)},q.closest=function(e){return e&&this[0]?this.is(e)?this.filter(e):this.parent().closest(e):K()},q.parents=function(e){var t,n=[];return this.each(function(r,o){for(t=o;t&&t.parentNode&&t!==A.body.parentNode;)t=t.parentNode,(!e||e&&ee(t,e))&&n.push(t)}),K(ce(n))},q.prev=function(){return K(this[0]&&this[0].previousElementSibling)},q.siblings=function(){var e=this[0];return this.parent().children().filter(function(t,n){return n!==e})};const Ue=K,Ve=new class{getFiberNode(e){try{const t=Object.keys(e).find(e=>e.startsWith("__reactFiber$")||e.startsWith("__reactInternalInstance$"));return t?e[t]:null}catch(e){return console.warn("[ReactFiberService] Error getting fiber node:",e),null}}getDebugOwner(e){const t=this.getFiberNode(e);return t?._debugOwner??null}getDebugSource(e){const t=this.getFiberNode(e);return t?._debugSource??null}getOwnerDebugSource(e){const t=this.getDebugOwner(e);return t?._debugSource??null}hasDirectSourceInfo(e){return!!e.getAttribute("data-nocode-id")||!!this.getDebugSource(e)}hasOwnerNocodeId(e){const t=this.getDebugOwner(e);if(!t?.memoizedProps)return!1;const n=t.memoizedProps["data-nocode-id"];return"string"==typeof n&&n.length>0}getOwnerNocodeId(e){const t=this.getDebugOwner(e);if(!t?.memoizedProps)return null;const n=t.memoizedProps["data-nocode-id"];return"string"==typeof n?n:null}isSelectableElement(e){if(this.hasDirectSourceInfo(e))return!0;const t=this.getFiberNode(e),n=this.getOwnerDebugSource(e);return!!(t?.return&&5!==t.return.tag&&this.hasOwnerNocodeId(e)&&n)}isComponent(e){if(!this.isSelectableElement(e))return!1;if(e.getAttribute("data-nocode-components-name"))return!0;if(this.getDebugSource(e))return!1;const t=this.getFiberNode(e);return!(!t?.return||5===t.return.tag)}getComponentName(e){const t=e.getAttribute("data-nocode-tag-name");if(t)return t;const n=this.getDebugOwner(e);if(n?.type){const e=n.type;if("function"==typeof e){const t=e.displayName||e.name||"Unknown";return this.normalizeComponentName(t)}if("string"==typeof e)return e}return e.tagName.toLowerCase()}normalizeComponentName(e){return e.replace(/\\d+$/,"")}getComponentProps(e){if(!this.isComponent(e))return;const t=this.getDebugOwner(e);return t?.memoizedProps?this.sanitizeProps(t.memoizedProps):void 0}sanitizeProps(e){const t={};for(const[n,r]of Object.entries(e)){if("children"===n||n.startsWith("_"))continue;const e=this.sanitizeValue(r);void 0!==e&&(t[n]=e)}return t}sanitizeValue(e){if(null===e)return null;if(void 0===e)return;if("function"==typeof e)return;if("symbol"==typeof e)return;if("object"!=typeof e)return e;if("$$typeof"in e)return;if(e instanceof Node)return;if(Array.isArray(e)){const t=[];for(const n of e){const e=this.sanitizeValue(n);void 0!==e&&t.push(e)}return t}const t={};for(const[n,r]of Object.entries(e)){if(n.startsWith("_"))continue;const e=this.sanitizeValue(r);void 0!==e&&(t[n]=e)}return t}buildComponentInfo(e,t){const n=this.isComponent(e),r={isComponent:n,componentType:n?"component":"host",name:n?this.getComponentName(e):e.tagName.toLowerCase()};if(n){const n={...t,...this.getComponentProps(e)??{}},{cleanProps:o,extractedProps:i}=this.extractSpecialProps(n);i.componentsName&&(r.componentsName=i.componentsName),i.componentsVersion&&(r.componentsVersion=i.componentsVersion),r.props=o}return r}extractSpecialProps(e){const t={},n={};for(const[r,o]of Object.entries(e))"componentsName"===r&&"string"==typeof o?n.componentsName=o:"componentsVersion"===r&&"string"==typeof o?n.componentsVersion=o:t[r]=o;return{cleanProps:t,extractedProps:n}}};function He(e){const t={},n=e.attributes;for(let e=0;e<n.length;e++){const r=n[e];r.name.startsWith("data-nocode-")&&(t[r.name.replace("data-nocode-","").replace(/-([a-z])/g,(e,t)=>t.toUpperCase())]=r.value)}return t}const Be="data-dnd",Ye=`[${Be}]`;function Ke(e){return document.querySelector(`[${Be}="${e}"]`)}const qe=(e,t)=>{const n=e.getBoundingClientRect(),{x:r,y:o}=((e,t)=>{let n=e.x,r=e.y;if(t){const e=t.getBoundingClientRect();n-=e.left,r-=e.top}return{x:n,y:r}})({x:n.left,y:n.top},t);return{width:e.offsetWidth,height:e.offsetHeight,top:o,left:r}},Ge=(e,t)=>{const n=qe(e,t),r=function(e){return e.dataset}(e),o=Xe(e),i=Je(e),s=(e=>{const t=window.getComputedStyle(e);return{display:t.display,flexDirection:t.flexDirection,flexWrap:t.flexWrap,position:t.position}})(e),a=r.dnd||"",c=function(e){if(!e)return{};const t=e.split(":");if(t.length>=3){const n=t.pop(),r=t.pop(),o=t.join(":");return{id:e,filename:decodeURIComponent(o),component:r,codeId:n}}return 2===t.length?{id:e,component:t[0],codeId:t[1]}:{id:e}}(a),u=He(e),l=function(e){const t=He(e);return Ve.buildComponentInfo(e,t)}(e),d=(e=>{const t=e.querySelectorAll(`:scope > ${Ye}`);if(!t.length)return[];const n=[];return t.forEach(e=>{const t=e;n.push(qe(t))}),n})(e);return{id:a,codeId:c.codeId,name:c.component||e.tagName.toLowerCase(),filename:c.filename,bounding:n,display:o,computedStyle:s,text:i,nocodeData:u,componentInfo:l,childrenBoundings:d.length>0?d:void 0}},Xe=e=>Ue(e).css("display"),Je=e=>{const t=[];return e.childNodes.forEach(e=>{if(e.nodeType===Node.TEXT_NODE){const n=e.textContent?.trim()||"";n&&t.push(n)}}),t.join(" ")};function Ze(e){const t=["div","p","section","article","main","header","footer","nav","h1","h2","h3","h4","h5","h6","span","a","button","i","input","textarea","select","label","form","ul","ol","li","table","thead","tbody","tr","td","th","img","video","audio","canvas","svg"];try{const n=e.tagName.toLowerCase();if(!t.includes(n))return!1;const r=window.getComputedStyle(e);if("none"===r.display||"hidden"===r.visibility||"0"===r.opacity)return!1;const o=e.getBoundingClientRect();return!("inline"!==r.display&&"inline-block"!==r.display&&(0===o.width||0===o.height))}catch(e){return console.warn("Element validation failed:",e),!1}}function Qe(e,t=20){let n=e,r=0;for(;n&&r<t;){if(n.getAttribute(Be))return n;n=n.parentElement,r++}return null}function et(e){const t=window.getComputedStyle(e),n={};for(let e=0;e<t.length;e++){const r=t[e];n[r]=t.getPropertyValue(r)}return n}function tt(e){return(...t)=>{try{const n=e(...t);return n&&"function"==typeof n.then?n.catch(n=>(console.error(`Async error in ${e.name}:`,n),console.error("Error stack:",n.stack),console.error("Function arguments:",t),null)):n}catch(n){return console.error(`Sync error in ${e.name}:`,n),n instanceof Error&&console.error("Error stack:",n.stack),console.error("Function arguments:",t),null}}}const nt={getDraggableParentsData:(e,t)=>{const n=function(e,t){const n=((e,t)=>{const n=document.elementFromPoint(e,t);if(!n)return null;const r=n=>{if(n?.shadowRoot){const o=n.shadowRoot.elementFromPoint(e,t);return o===n?n:o?.shadowRoot?r(o):o||n}return n};return r(n)})(e,t);if(!n)return null;let r=n;if(!Ze(r)){let e=r.parentElement,t=0;const n=20;for(;e&&t<n;){if(Ze(e)){r=e;break}e=e.parentElement,t++}if(!Ze(r))return null}const o=Qe(r);return o&&Ze(o)?o:null}(e.x,e.y);if(!n)return;const r=(e=>{const t=Ue(e).closest(Ye).get(0),n=Ue(e).parents(Ye).get();return n[0]!==t&&n.unshift(t),n})(n);if(r.length){if(t){const e=r.map(e=>Ge(e));return{...e[0],computedStyle:et(n),parents:e.slice(1)}}return{...Ge(r[0]),computedStyle:et(r[0])}}},getElementDataById:e=>{const t=Ke(e);if(t)return{...Ge(t),computedStyle:et(t)};console.warn("[getElementDataById] Element not found for domId:",e)},getEditableTextElementAtPosition:e=>{const t=function(e,t){if(document.caretPositionFromPoint){const n=document.caretPositionFromPoint(e,t);return n?.offsetNode??null}if(document.caretRangeFromPoint){const n=document.caretRangeFromPoint(e,t);return n?.startContainer??null}return document.elementFromPoint(e,t)}(e.x,e.y);if(!t)return void console.log("[getEditableTextElementAtPosition] No node at point:",e);if(t.nodeType!==Node.TEXT_NODE)return void console.log("[getEditableTextElementAtPosition] Not a text node:",t.nodeType);const n=t.textContent?.trim();if(!n)return void console.log("[getEditableTextElementAtPosition] Empty text node");const r=t.parentElement;if(!r)return void console.log("[getEditableTextElementAtPosition] No parent element");const o=Qe(r);if(o){if(function(e){const t=e.childNodes;let n=!1;for(let e=0;e<t.length;e++){const r=t[e];if(r.nodeType===Node.ELEMENT_NODE)return!1;if(r.nodeType===Node.TEXT_NODE){const e=r.textContent?.trim();e&&(n=!0)}}return n}(o))return console.log("[getEditableTextElementAtPosition] Found editable text element:",o.tagName,o.textContent),{...Ge(o),computedStyle:et(o)};console.log("[getEditableTextElementAtPosition] Element has child elements, cannot edit directly:",o.tagName)}else console.log("[getEditableTextElementAtPosition] No marked element found")},updateElementTextContent:(e,t)=>{const n=Ke(e);return n?(n.textContent=t,!0):(console.warn("[updateElementTextContent] Element not found:",e),!1)},scrollToElement:e=>{const t=Ke(e);return t?(t.scrollIntoView({behavior:"instant",block:"center",inline:"center"}),!0):(console.warn("[scrollToElement] Element not found for domId:",e),!1)}},rt=Object.fromEntries(Object.entries(nt).map(([e,t])=>[e,tt(t)])),ot="nocode-design-mode";let it=null,st=!1,at=null;const ct=t()(()=>{it?.onWindowMutated&&(console.log(`${ot} - Notifying parent of DOM mutation`),it.onWindowMutated({added:{},removed:{}}))},100),ut=async()=>{if(st||it)return it;st=!0,console.log(`${ot} - Creating penpal connection`);const e=(({messenger:e,methods:t={},timeout:n,channel:o,log:i})=>{if(!e)throw new r("INVALID_ARGUMENT","messenger must be defined");if(M.has(e))throw new r("INVALID_ARGUMENT","A messenger can only be used for a single connection");M.add(e);const s=[e.destroy],u=(e=>{let t,n=!1;return(...r)=>(n||(n=!0,t=e(...r)),t)})(t=>{if(t){const t={namespace:a,channel:o,type:"DESTROY"};try{e.sendMessage(t)}catch(e){}}for(const e of s)e();i?.("Connection destroyed")}),l=e=>(e=>c(e)&&e.namespace===a)(e)&&e.channel===o;return{promise:(async()=>{try{e.initialize({log:i,validateReceivedMessage:l}),e.addMessageHandler(e=>{(e=>"DESTROY"===e.type)(e)&&u(!1)});const{remoteProxy:r,destroy:a}=await T({messenger:e,methods:t,timeout:n,channel:o,log:i});return s.push(a),r}catch(e){throw u(!0),e}})(),destroy:()=>{u(!0)}}})({messenger:new I({remoteWindow:window===window.top?(console.warn(`${ot} - Not in an iframe, using window.parent as fallback`),window.parent):window.parent===window.top?window.parent:window.top?(console.log(`${ot} - Using window.top for nested iframe scenario`),window.top):window.parent,allowedOrigins:["*"]}),methods:rt});return e.promise.then(e=>{if(!e)return console.error(`${ot} - Failed to setup penpal connection: child is null`),void lt();it=e,console.log(`${ot} - Penpal connection set`),(()=>{if(at)return;at=new MutationObserver(e=>{e.some(e=>{const t=e.target;return"SCRIPT"!==t.tagName&&"STYLE"!==t.tagName&&("attributes"!==e.type||"style"===e.attributeName||"class"===e.attributeName)})&&ct()});const e=()=>{document.body&&at&&(at.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"],characterData:!0}),console.log(`${ot} - MutationObserver started`))};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()})()}).finally(()=>{st=!1}),e.promise.catch(e=>{console.error(`${ot} - Failed to setup penpal connection:`,e),lt()}),it},lt=t()(()=>{st||(console.log(`${ot} - Reconnecting to penpal parent`),it=null,ut())},1e3);ut()})()})();';
|
|
267
|
+
}
|
|
268
|
+
function createSandboxScriptMiddleware(options) {
|
|
269
|
+
var _a;
|
|
270
|
+
const verbose = (_a = options.verbose) != null ? _a : false;
|
|
271
|
+
const scriptContent = getSandboxScriptContent();
|
|
272
|
+
return (req, res, next) => {
|
|
273
|
+
if (req.url !== SANDBOX_SCRIPT_PATH) {
|
|
274
|
+
return next();
|
|
275
|
+
}
|
|
276
|
+
if (!scriptContent) {
|
|
277
|
+
if (verbose) {
|
|
278
|
+
console.warn("[DesignMode] sandbox-script.js not embedded. Build may be incomplete.");
|
|
279
|
+
}
|
|
280
|
+
res.statusCode = 404;
|
|
281
|
+
res.end("/* sandbox-script.js not available */");
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
285
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
286
|
+
res.end(scriptContent);
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function injectSandboxScript(html) {
|
|
290
|
+
const scriptTag = `<script src="${SANDBOX_SCRIPT_PATH}"></script>`;
|
|
291
|
+
if (html.includes(SANDBOX_SCRIPT_PATH)) {
|
|
292
|
+
return html;
|
|
293
|
+
}
|
|
294
|
+
if (html.includes("</head>")) {
|
|
295
|
+
return html.replace("</head>", ` ${scriptTag}
|
|
296
|
+
</head>`);
|
|
297
|
+
}
|
|
298
|
+
if (html.includes("<body>")) {
|
|
299
|
+
return html.replace("<body>", `<body>
|
|
300
|
+
${scriptTag}`);
|
|
301
|
+
}
|
|
302
|
+
return html + `
|
|
303
|
+
${scriptTag}`;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/visual-edit/override-code.ts
|
|
307
|
+
var overrideMap = /* @__PURE__ */ new Map();
|
|
308
|
+
function loadOverrideCode(id) {
|
|
309
|
+
const [filePath] = id.split("?", 2);
|
|
310
|
+
return overrideMap.get(filePath);
|
|
311
|
+
}
|
|
312
|
+
function clearAllOverridesAndInvalidate(server) {
|
|
313
|
+
if (overrideMap.size === 0) return;
|
|
314
|
+
for (const filePath of overrideMap.keys()) {
|
|
315
|
+
const mods = safeGetModulesByFile(server, filePath);
|
|
316
|
+
if (mods && mods.size > 0) {
|
|
317
|
+
for (const mod of mods) {
|
|
318
|
+
safeInvalidateModule(server, mod);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
overrideMap.clear();
|
|
323
|
+
}
|
|
324
|
+
var OVERRIDE_API_PATH = "/__nocode_file_override";
|
|
325
|
+
function createOverrideMiddleware(server) {
|
|
326
|
+
return async (req, res, next) => {
|
|
327
|
+
var _a;
|
|
328
|
+
if (!((_a = req.url) == null ? void 0 : _a.startsWith(OVERRIDE_API_PATH))) {
|
|
329
|
+
return next();
|
|
330
|
+
}
|
|
331
|
+
if (req.method !== "POST") {
|
|
332
|
+
return next();
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
const { file, code } = await readJsonBody(req);
|
|
336
|
+
if (!file || typeof code !== "string") {
|
|
337
|
+
res.statusCode = 400;
|
|
338
|
+
res.end(JSON.stringify({ error: "file and code are required" }));
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const absolutePath = resolveFileToAbsPath(file, server.config.root);
|
|
342
|
+
if (!absolutePath) {
|
|
343
|
+
console.warn("[nocode-compiler] file not found:", file, server.config.root);
|
|
344
|
+
res.statusCode = 404;
|
|
345
|
+
res.end(JSON.stringify({ error: "file not found" }));
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
overrideMap.set(absolutePath, code);
|
|
349
|
+
const mods = safeGetModulesByFile(server, absolutePath);
|
|
350
|
+
if (mods && mods.size > 0) {
|
|
351
|
+
for (const mod of mods) {
|
|
352
|
+
safeInvalidateModule(server, mod);
|
|
353
|
+
safeSendHmrUpdate(server, {
|
|
354
|
+
type: "update",
|
|
355
|
+
updates: [
|
|
356
|
+
{
|
|
357
|
+
type: "js-update",
|
|
358
|
+
path: mod.url,
|
|
359
|
+
acceptedPath: mod.url,
|
|
360
|
+
timestamp: Date.now()
|
|
361
|
+
}
|
|
362
|
+
]
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
res.statusCode = 200;
|
|
367
|
+
res.end(JSON.stringify({ success: true }));
|
|
368
|
+
} catch (error) {
|
|
369
|
+
res.statusCode = 500;
|
|
370
|
+
res.end(JSON.stringify({ error: String(error) }));
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/index.ts
|
|
108
376
|
var PLUGIN_NAME = "vite-plugin-nocode-compiler";
|
|
109
377
|
function ensurePluginFirst(config, onError) {
|
|
110
378
|
try {
|
|
@@ -124,6 +392,10 @@ function componentCompiler(options = {}) {
|
|
|
124
392
|
enableLogging: false,
|
|
125
393
|
...options
|
|
126
394
|
};
|
|
395
|
+
const designModeOptions = {
|
|
396
|
+
...DEFAULT_DESIGN_MODE_OPTIONS,
|
|
397
|
+
...options.designModeOptions
|
|
398
|
+
};
|
|
127
399
|
const monitorService = new MonitorService({
|
|
128
400
|
pluginName: "vite-plugin-nocode-compiler",
|
|
129
401
|
framework: "vite",
|
|
@@ -132,8 +404,10 @@ function componentCompiler(options = {}) {
|
|
|
132
404
|
monitorService.reportMetrics(MetricType.PLUGIN_USE, 1);
|
|
133
405
|
const vueCompiler = new VueCompiler(options);
|
|
134
406
|
const jsxCompiler = new JSXCompiler(options);
|
|
407
|
+
const designModeCompiler = new DesignModeCompiler(options);
|
|
135
408
|
let server;
|
|
136
409
|
let pkgRegistry;
|
|
410
|
+
let projectRoot = "";
|
|
137
411
|
return {
|
|
138
412
|
name: PLUGIN_NAME,
|
|
139
413
|
enforce: "pre",
|
|
@@ -141,81 +415,59 @@ function componentCompiler(options = {}) {
|
|
|
141
415
|
* 配置解析完成后:
|
|
142
416
|
* 1. 将本插件移到插件列表最前面,确保在所有 enforce: 'pre' 插件中第一个执行
|
|
143
417
|
* 2. 初始化 PackageVersionRegistry
|
|
418
|
+
* 并预扫描项目 dependencies,填充版本缓存
|
|
144
419
|
*/
|
|
145
420
|
configResolved(config) {
|
|
146
421
|
ensurePluginFirst(config, (error) => monitorService.reportError(error, { scene: "ensurePluginFirst" }));
|
|
147
422
|
pkgRegistry = new PackageVersionRegistry(config.root);
|
|
423
|
+
projectRoot = config.root;
|
|
424
|
+
preloadDependencyVersions(pkgRegistry);
|
|
148
425
|
},
|
|
149
426
|
/**
|
|
150
|
-
* 配置开发服务器,添加 Override
|
|
151
|
-
* 兼容 Vite 2.x -
|
|
427
|
+
* 配置开发服务器,添加 Override 中间件和设计模式中间件
|
|
428
|
+
* 兼容 Vite 2.x - 6.x
|
|
152
429
|
*/
|
|
153
430
|
configureServer(_server) {
|
|
154
431
|
server = _server;
|
|
155
432
|
safeOnConnection(server, () => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
for (const mod of mods) {
|
|
161
|
-
safeInvalidateModule(server, mod);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
overrideMap.clear();
|
|
166
|
-
});
|
|
167
|
-
server.middlewares.use("/__nocode_file_override", async (req, res, next) => {
|
|
168
|
-
if (req.method !== "POST") {
|
|
169
|
-
return next();
|
|
170
|
-
}
|
|
171
|
-
try {
|
|
172
|
-
const { file, code } = await readJsonBody(req);
|
|
173
|
-
if (!file || typeof code !== "string") {
|
|
174
|
-
res.statusCode = 400;
|
|
175
|
-
res.end(JSON.stringify({ error: "file and code are required" }));
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
const absolutePath = resolveFileToAbsPath(file, server.config.root);
|
|
179
|
-
if (!absolutePath) {
|
|
180
|
-
console.warn("[nocode-compiler] file not found:", file, server.config.root);
|
|
181
|
-
res.statusCode = 404;
|
|
182
|
-
res.end(JSON.stringify({ error: "file not found" }));
|
|
183
|
-
return;
|
|
433
|
+
clearAllOverridesAndInvalidate(server);
|
|
434
|
+
if (virtualCodeMap.size > 0) {
|
|
435
|
+
if (designModeOptions.verbose) {
|
|
436
|
+
console.log(`[DesignMode] Client reconnected, clearing ${virtualCodeMap.size} virtual code entries`);
|
|
184
437
|
}
|
|
185
|
-
|
|
186
|
-
const mods = safeGetModulesByFile(server, absolutePath);
|
|
187
|
-
if (mods && mods.size > 0) {
|
|
188
|
-
for (const mod of mods) {
|
|
189
|
-
safeInvalidateModule(server, mod);
|
|
190
|
-
safeSendHmrUpdate(server, {
|
|
191
|
-
type: "update",
|
|
192
|
-
updates: [
|
|
193
|
-
{
|
|
194
|
-
type: "js-update",
|
|
195
|
-
path: mod.url,
|
|
196
|
-
acceptedPath: mod.url,
|
|
197
|
-
timestamp: Date.now()
|
|
198
|
-
}
|
|
199
|
-
]
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
res.statusCode = 200;
|
|
204
|
-
res.end(JSON.stringify({ success: true }));
|
|
205
|
-
} catch (error) {
|
|
206
|
-
res.statusCode = 500;
|
|
207
|
-
res.end(JSON.stringify({ error: String(error) }));
|
|
438
|
+
virtualCodeMap.clear();
|
|
208
439
|
}
|
|
209
440
|
});
|
|
441
|
+
server.middlewares.use(createOverrideMiddleware(server));
|
|
442
|
+
server.middlewares.use(createSandboxScriptMiddleware(designModeOptions));
|
|
443
|
+
if (designModeOptions.enableVirtualCode) {
|
|
444
|
+
server.middlewares.use(createVirtualCodeMiddleware(server, designModeOptions, projectRoot));
|
|
445
|
+
console.log(`[DesignMode] Virtual code API enabled at ${designModeOptions.virtualCodeApiPath}`);
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
/**
|
|
449
|
+
* 转换 index.html:
|
|
450
|
+
* 1. 在 <body> 标签上注入组件库版本信息和编译插件版本
|
|
451
|
+
* 2. 注入 sandbox script(设计模式功能)
|
|
452
|
+
* 兼容 Vite 2.x - 6.x(transformIndexHtml 从 Vite 2 起就支持简单函数形式)
|
|
453
|
+
*/
|
|
454
|
+
transformIndexHtml(html) {
|
|
455
|
+
const metadata = generateBodyMetadata(pkgRegistry, version);
|
|
456
|
+
html = injectBodyMetadata(html, metadata);
|
|
457
|
+
html = injectSandboxScript(html);
|
|
458
|
+
return html;
|
|
210
459
|
},
|
|
211
460
|
/**
|
|
212
|
-
*
|
|
461
|
+
* 加载模块时,检查 override 和虚拟代码
|
|
213
462
|
*/
|
|
214
463
|
load(id) {
|
|
215
464
|
if (id.includes("node_modules")) return;
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
218
|
-
return
|
|
465
|
+
const overrideCode = loadOverrideCode(id);
|
|
466
|
+
if (overrideCode) {
|
|
467
|
+
return overrideCode;
|
|
468
|
+
}
|
|
469
|
+
if (designModeOptions.enableVirtualCode) {
|
|
470
|
+
return loadVirtualCode(id, designModeOptions);
|
|
219
471
|
}
|
|
220
472
|
return void 0;
|
|
221
473
|
},
|
|
@@ -224,6 +476,12 @@ function componentCompiler(options = {}) {
|
|
|
224
476
|
return code;
|
|
225
477
|
}
|
|
226
478
|
const [filePath, query] = id.split("?", 2);
|
|
479
|
+
if (!shouldSkipDesignModeTransform(id, designModeOptions)) {
|
|
480
|
+
const result = designModeCompiler.compile(code, filePath);
|
|
481
|
+
if (result) {
|
|
482
|
+
code = result.code;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
227
485
|
const { useJSXCompiler, useVueCompiler } = detectCompileScenario({
|
|
228
486
|
filePath,
|
|
229
487
|
query
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meituan-nocode/vite-plugin-nocode-compiler",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1-beta.1",
|
|
4
4
|
"description": "Vite plugin for nocode compiler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -16,14 +16,15 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@nocode/design-mode-sandbox-script": "0.1.0-beta.3",
|
|
21
|
+
"@meituan-nocode/nocode-compiler-core": "0.2.9-beta.1"
|
|
22
|
+
},
|
|
19
23
|
"devDependencies": {
|
|
20
|
-
"@types/node": "^20.
|
|
24
|
+
"@types/node": "^20.19.31",
|
|
25
|
+
"tsup": "8.5.0",
|
|
21
26
|
"typescript": "^5.0.0",
|
|
22
|
-
"vite": "^4.5.14"
|
|
23
|
-
"tsup": "8.5.0"
|
|
24
|
-
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@meituan-nocode/nocode-compiler-core": "0.2.8"
|
|
27
|
+
"vite": "^4.5.14"
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
29
30
|
"dev": "tsup --watch",
|