@amaster.ai/vite-plugins 1.1.0-beta.62 → 1.1.0-beta.63

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 CHANGED
@@ -1,110 +1,11 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var m=require('fs'),d=require('path'),C=require('process'),S=require('fs/promises');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var m__default=/*#__PURE__*/_interopDefault(m);var d__default=/*#__PURE__*/_interopDefault(d);var C__default=/*#__PURE__*/_interopDefault(C);var S__default=/*#__PURE__*/_interopDefault(S);var R="@amaster/bridge-monitor",x="\0"+R;function A(){return '<script type="module" src="/@id/@amaster/bridge-monitor"></script>'}function L(r){return `
2
- // Bridge monitor module - handles all bridge logic
3
- const SOURCE_KEY = Symbol.for("__jsxSource__");
4
- const SESSION_KEY = "${r}";
5
-
6
- // Expose minimal API for external bridge script
7
- window.__AMASTER_BRIDGE__ = {
8
- getSourceInfo: (element) => element?.[SOURCE_KEY],
9
- getSourceMap: () => window.sourceElementMap,
10
- postToParent: (type, data) => {
11
- window.parent.postMessage({ type, data, key: SESSION_KEY }, "*");
12
- },
13
- isDev: true,
14
- };
15
-
16
- // Listen for HMR updates
17
- if (import.meta.hot) {
18
- import.meta.hot.on('vite:afterUpdate', (payload) => {
19
- // Dispatch custom event for bridge.js to listen
20
- window.dispatchEvent(new CustomEvent('amaster:hmr-update', {
21
- detail: {
22
- updates: payload?.updates || []
23
- }
24
- }));
25
- });
26
- }
27
-
28
- // Import and monitor Tailwind config
29
- (async () => {
30
- try {
31
- const tailwindConfig = await import('@amaster/tailwind-config');
32
- let config = tailwindConfig.default;
33
- const onUpdate = tailwindConfig.onUpdate;
34
-
35
- if (!config) {
36
- return;
37
- }
38
-
39
- const sendConfig = (type, newConfig) => {
40
- config = newConfig || config;
41
- const serializableConfig = JSON.parse(JSON.stringify(config));
42
-
43
- // Dispatch event for bridge.js to handle
44
- window.dispatchEvent(new CustomEvent('amaster:tailwind-config', {
45
- detail: {
46
- type: type,
47
- config: serializableConfig
48
- }
49
- }));
50
- };
51
-
52
- // Send initial config
53
- sendConfig('loaded');
54
-
55
- // Listen for bridge ready event and resend config
56
- window.addEventListener('amaster:bridge-ready', () => {
57
- sendConfig('loaded');
58
- });
59
-
60
- // Listen for config updates
61
- if (onUpdate) {
62
- onUpdate((newConfig) => {
63
- sendConfig('updated', newConfig);
64
- });
65
- }
66
- } catch (e) {
67
- // Silently fail if tailwind config is not available
68
- }
69
- })();
70
-
71
- // Listen for bridge script URL from platform
72
- window.addEventListener("message", (event) => {
73
- const { type, data, key } = event.data;
74
-
75
- if (key !== SESSION_KEY) {
76
- return;
77
- }
78
-
79
- if (type === "amaster.loadBridge" && data?.scriptContent) {
80
- // Create blob URL from script content
81
- const blob = new Blob([data.scriptContent], { type: 'application/javascript' });
82
- const blobUrl = URL.createObjectURL(blob);
83
-
84
- const script = document.createElement("script");
85
- script.src = blobUrl;
86
- script.onload = () => {
87
- URL.revokeObjectURL(blobUrl);
88
- };
89
- script.onerror = () => {
90
- URL.revokeObjectURL(blobUrl);
91
- };
92
- document.head.appendChild(script);
93
- }
94
- });
95
-
96
- window.addEventListener("DOMContentLoaded", () => {
97
- window.__AMASTER_BRIDGE__?.postToParent("amaster.bridge.initialized", {});
98
- });
99
-
100
- export default {};
101
- `}function O(){let r=false;return {name:"vite-plugin-editor-bridge",configResolved(n){r=n.command==="serve";},resolveId(n){if(n===R)return x},load(n){if(n===x){let e=process.env.VITE_AMASTER_KEY||"";return L(e)}},transformIndexHtml(n){if(!r)return n;let e=A();return n.replace("</body>",`${e}</body>`)}}}function T(r){let n=false,e=r?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(t){n=t.command==="serve";},transform(t,o){if(!n||!o.endsWith(e))return null;try{return t.includes("window.__APP_ROUTES__")?null:{code:`${t}
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var y=require('fs'),d=require('path'),url=require('url'),C=require('process'),w=require('fs/promises');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var y__default=/*#__PURE__*/_interopDefault(y);var d__default=/*#__PURE__*/_interopDefault(d);var C__default=/*#__PURE__*/_interopDefault(C);var w__default=/*#__PURE__*/_interopDefault(w);var q=url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))),H=d.dirname(q),R="@amaster/bridge-monitor",O="\0"+R,m=null;function M(){if(m)return m;try{let t=d.resolve(H,"../dist/bridge-module.global.js");return m=y.readFileSync(t,"utf-8"),m}catch(t){return console.warn("[editor-bridge] Failed to load pre-built bridge module:",t),""}}function N(){return '<script type="module" src="/@id/@amaster/bridge-monitor"></script>'}function B(t){return M().replace(/__SESSION_KEY__/g,t)+`
2
+ export default {};`}function T(){let t=false;return {name:"vite-plugin-editor-bridge",configResolved(n){t=n.command==="serve";},resolveId(n){if(n===R)return O},load(n){if(n===O){let e=process.env.VITE_AMASTER_KEY||"";return B(e)}},transformIndexHtml(n){if(!t)return n;let e=N();return n.replace("</body>",`${e}</body>`)}}}function P(t){let n=false,e=t?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(r){n=r.command==="serve";},transform(r,o){if(!n||!o.endsWith(e))return null;try{return r.includes("window.__APP_ROUTES__")?null:{code:`${r}
102
3
 
103
4
  // Development mode: Expose routes to window.__APP_ROUTES__
104
5
  if (typeof window !== 'undefined') {
105
6
  window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];
106
7
  }
107
- `,map:null}}catch{return null}}}}function P(){let r="",n=`
8
+ `,map:null}}catch{return null}}}}function I(){let t="",n=`
108
9
  <script>
109
10
  (function() {
110
11
  'use strict';
@@ -795,8 +696,8 @@ if (typeof window !== 'undefined') {
795
696
 
796
697
  originalConsole.log('[BrowserLogs] Log collection started');
797
698
  })();
798
- </script>`;return {name:"vite-plugin-browser-logs",configResolved(e){let t=C__default.default.env.WORKSPACE_DIR;if(t)r=d__default.default.join(t,"browser.log");else {let o=e.root||C__default.default.cwd();for(;o!==d__default.default.dirname(o)&&!m__default.default.existsSync(d__default.default.join(o,"package.json"));)o=d__default.default.dirname(o);r=d__default.default.join(o,"browser.log");}},configureServer(e){e.middlewares.use((t,o,l)=>{if(t.url==="/__browser__"&&t.method==="POST"){let i=t.headers.origin||"*",u="";t.on("data",c=>{u+=c.toString();}),t.on("end",()=>{try{let c=d__default.default.dirname(r);m__default.default.existsSync(c)||m__default.default.mkdirSync(c,{recursive:!0}),m__default.default.appendFileSync(r,`${u}
799
- `,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:!0}));}catch(c){console.error("[BrowserLogs] Write error:",c),o.writeHead(500,{"Content-Type":"application/json","Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:false,error:String(c)}));}});}else if(t.url==="/__browser__"&&t.method==="OPTIONS"){let i=t.headers.origin||"*";o.writeHead(204,{"Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Max-Age":"86400"}),o.end();}else if(t.url==="/__browser__"){let i=t.headers.origin||"*";o.writeHead(405,{"Content-Type":"application/json","Access-Control-Allow-Origin":i}),o.end(JSON.stringify({error:"Method not allowed"}));}else l();}),console.log("[BrowserLogs] Logs will be written to:",r);},transformIndexHtml(e){return e.replace(/<head([^>]*)>/i,`<head$1>${n}`)}}}var j=`
699
+ </script>`;return {name:"vite-plugin-browser-logs",configResolved(e){let r=C__default.default.env.WORKSPACE_DIR;if(r)t=d__default.default.join(r,"browser.log");else {let o=e.root||C__default.default.cwd();for(;o!==d__default.default.dirname(o)&&!y__default.default.existsSync(d__default.default.join(o,"package.json"));)o=d__default.default.dirname(o);t=d__default.default.join(o,"browser.log");}},configureServer(e){e.middlewares.use((r,o,l)=>{if(r.url==="/__browser__"&&r.method==="POST"){let i=r.headers.origin||"*",c="";r.on("data",u=>{c+=u.toString();}),r.on("end",()=>{try{let u=d__default.default.dirname(t);y__default.default.existsSync(u)||y__default.default.mkdirSync(u,{recursive:!0}),y__default.default.appendFileSync(t,`${c}
700
+ `,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:!0}));}catch(u){console.error("[BrowserLogs] Write error:",u),o.writeHead(500,{"Content-Type":"application/json","Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:false,error:String(u)}));}});}else if(r.url==="/__browser__"&&r.method==="OPTIONS"){let i=r.headers.origin||"*";o.writeHead(204,{"Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Max-Age":"86400"}),o.end();}else if(r.url==="/__browser__"){let i=r.headers.origin||"*";o.writeHead(405,{"Content-Type":"application/json","Access-Control-Allow-Origin":i}),o.end(JSON.stringify({error:"Method not allowed"}));}else l();}),console.log("[BrowserLogs] Logs will be written to:",t);},transformIndexHtml(e){return e.replace(/<head([^>]*)>/i,`<head$1>${n}`)}}}var F=`
800
701
  import * as React from "react";
801
702
  import * as ReactJSXDevRuntime from "react/jsx-dev-runtime";
802
703
 
@@ -979,14 +880,14 @@ export function jsxDEV(type, props, key, isStatic, source, self) {
979
880
 
980
881
  return _jsxDEV(type, props, key, isStatic, source, self);
981
882
  }
982
- `;function v(){let r=false,n="";return {name:"vite-plugin-jsx-source-tagger",enforce:"pre",configResolved(e){r=e.command==="serve",n=e.root;},resolveId(e,t){return r&&e==="react/jsx-dev-runtime"&&!t?.includes("\0jsx-source")?"\0jsx-source/jsx-dev-runtime":null},load(e){return r&&e==="\0jsx-source/jsx-dev-runtime"?j.replace('const PROJECT_ROOT = "";',`const PROJECT_ROOT = ${JSON.stringify(n)};`):null}}}function _(r){let n="",e=false,t=null,o=null,l=r?.configPath||"./tailwind.config.ts",i="@amaster/tailwind-config",u="\0"+i,c=async()=>{let a=d__default.default.resolve(n,l);try{return await S__default.default.access(a),a}catch{if(l.endsWith(".ts")){let s=a.replace(/\.ts$/,".js");try{return await S__default.default.access(s),s}catch{return null}}else if(l.endsWith(".js")){let s=a.replace(/\.js$/,".ts");try{return await S__default.default.access(s),s}catch{return null}}return null}},h=async a=>{try{let s=await c();if(!s)return null;if(a){let E=await a.ssrLoadModule(s);return t=E.default||E,t}let f=await import(`file://${s}?t=${Date.now()}`);return t=f.default||f,t}catch(s){return console.error("[tailwind-config-sync] Failed to generate config:",s),null}};return {name:"vite-plugin-tailwind-config-sync",configResolved(a){n=a.root,e=a.command==="serve";},async buildStart(){e&&await h();},resolveId(a){if(a===i)return u},async load(a){if(a===u)return await h(o),t?`
883
+ `;function S(){let t=false,n="";return {name:"vite-plugin-jsx-source-tagger",enforce:"pre",configResolved(e){t=e.command==="serve",n=e.root;},resolveId(e,r){return t&&e==="react/jsx-dev-runtime"&&!r?.includes("\0jsx-source")?"\0jsx-source/jsx-dev-runtime":null},load(e){return t&&e==="\0jsx-source/jsx-dev-runtime"?F.replace('const PROJECT_ROOT = "";',`const PROJECT_ROOT = ${JSON.stringify(n)};`):null}}}function b(t){let n="",e=false,r=null,o=null,l=t?.configPath||"./tailwind.config.ts",i="@amaster/tailwind-config",c="\0"+i,u=async()=>{let a=d__default.default.resolve(n,l);try{return await w__default.default.access(a),a}catch{if(l.endsWith(".ts")){let s=a.replace(/\.ts$/,".js");try{return await w__default.default.access(s),s}catch{return null}}else if(l.endsWith(".js")){let s=a.replace(/\.js$/,".ts");try{return await w__default.default.access(s),s}catch{return null}}return null}},v=async a=>{try{let s=await u();if(!s)return null;if(a){let E=await a.ssrLoadModule(s);return r=E.default||E,r}let f=await import(`file://${s}?t=${Date.now()}`);return r=f.default||f,r}catch(s){return console.error("[tailwind-config-sync] Failed to generate config:",s),null}};return {name:"vite-plugin-tailwind-config-sync",configResolved(a){n=a.root,e=a.command==="serve";},async buildStart(){e&&await v();},resolveId(a){if(a===i)return c},async load(a){if(a===c)return await v(o),r?`
983
884
  // Use global variable to persist callbacks and current config across HMR updates
984
885
  if (!window.__tailwindConfigCallbacks) {
985
886
  window.__tailwindConfigCallbacks = [];
986
887
  }
987
888
 
988
889
  // Always update current config with the latest from server
989
- let tailwindConfigCurrent = ${JSON.stringify(t)};
890
+ let tailwindConfigCurrent = ${JSON.stringify(r)};
990
891
 
991
892
  if (import.meta.hot) {
992
893
  // Accept self updates
@@ -1016,12 +917,12 @@ export function onUpdate(fn) {
1016
917
  };
1017
918
  export default tailwindConfigCurrent;
1018
919
 
1019
- `:"export default null;"},configureServer(a){e&&(o=a,(async()=>{try{let s=await c();s&&a.watcher.add(s);}catch{}})());},async handleHotUpdate({file:a,server:s}){let p=await c();if(!p||d__default.default.normalize(a)!==d__default.default.normalize(p))return;let f=s.moduleGraph.getModuleById(p);f&&s.moduleGraph.invalidateModule(f),await h(s);let g=s.moduleGraph.getModuleById(u);return g?(s.moduleGraph.invalidateModule(g),[g]):[]}}}function b(r={}){let{designWidth:n=375,maxWidth:e=750,baseFontSize:t=12,minRootSize:o=12,maxRootSize:l=24}=r;return {name:"vite-plugin-taro-style-adapter",apply:"serve",transformIndexHtml(i){let u=`
920
+ `:"export default null;"},configureServer(a){e&&(o=a,(async()=>{try{let s=await u();s&&a.watcher.add(s);}catch{}})());},async handleHotUpdate({file:a,server:s}){let p=await u();if(!p||d__default.default.normalize(a)!==d__default.default.normalize(p))return;let f=s.moduleGraph.getModuleById(p);f&&s.moduleGraph.invalidateModule(f),await v(s);let g=s.moduleGraph.getModuleById(c);return g?(s.moduleGraph.invalidateModule(g),[g]):[]}}}function x(t={}){let{designWidth:n=375,maxWidth:e=750,baseFontSize:r=12,minRootSize:o=12,maxRootSize:l=24}=t;return {name:"vite-plugin-taro-style-adapter",apply:"serve",transformIndexHtml(i){let c=`
1020
921
  <script data-taro-flexible="true">
1021
922
  (function() {
1022
923
  var designWidth = ${n};
1023
924
  var maxWidth = ${e};
1024
- var baseFontSize = ${t};
925
+ var baseFontSize = ${r};
1025
926
  var minRootSize = ${o};
1026
927
  var maxRootSize = ${l};
1027
928
 
@@ -1057,7 +958,7 @@ export default tailwindConfigCurrent;
1057
958
  document.addEventListener('DOMContentLoaded', setRootFontSize);
1058
959
  })();
1059
960
  </script>
1060
- `;return i.replace("</head>",`${u}
961
+ `;return i.replace("</head>",`${c}
1061
962
  <style data-taro-adapter="true">
1062
963
  /* \u4EC5 H5 \u751F\u6548\uFF1A\u9690\u85CF Taro \u9875\u9762\u5BB9\u5668\u6EDA\u52A8\u6761\uFF0C\u4F46\u4ECD\u53EF\u6EDA\u52A8 */
1063
964
  .taro_page {
@@ -1103,5 +1004,5 @@ export default tailwindConfigCurrent;
1103
1004
  object-fit: contain;
1104
1005
  }
1105
1006
  </style>
1106
- </head>`)}}}function y(r={}){let{ratio:n=2}=r;return {postcssPlugin:"postcss-rpx2px",Declaration(e){e.value?.includes("rpx")&&(e.value=e.value.replace(/(-?\d*\.?\d+)rpx/gi,(t,o)=>{let l=parseFloat(o)/n;return l===0?"0":`${l}px`}));}}}y.postcss=true;function k(r={}){let{additional:n=[],autoInjectTaroApp:e=true,autoInjectVite:t=true}=r,o={},l=new Set(n);return e&&Object.keys(process.env).forEach(i=>{i.startsWith("TARO_APP_")&&l.add(i);}),t&&Object.keys(process.env).forEach(i=>{i.startsWith("VITE_")&&l.add(i);}),l.forEach(i=>{let u=process.env[i]||"";o[`process.env.${i}`]=JSON.stringify(u);}),o}function D(){return {"process.env.TARO_APP_API_BASE_URL":JSON.stringify(process.env.TARO_APP_API_BASE_URL||""),"process.env.VITE_API_BASE_URL":JSON.stringify(process.env.VITE_API_BASE_URL||"")}}function N(r={}){let n=r.isTaro??C__default.default.env.TARO_ENV==="h5",e=[O(),T()];return r.jsxSourceTagger!==false&&e.push(v()),r.tailwindConfigSync!==false&&e.push(_({configPath:r.tailwindConfigPath})),n&&(e.unshift(b(r.styleAdapter)),e.unshift({name:"dev-postcss-rpx2px-plugin",apply:"serve",config(t){typeof t.css?.postcss=="object"&&t.css?.postcss.plugins?.unshift(y());}})),C__default.default.env.WORKSPACE_GIT_REPO&&e.push(P()),e}exports.default=N;exports.editorBridgePlugin=O;exports.injectAmasterEnv=D;exports.injectTaroEnv=k;exports.jsxSourceTaggerPlugin=v;exports.routesExposePlugin=T;exports.rpx2pxPlugin=y;exports.tailwindConfigSyncPlugin=_;exports.taroStyleAdapterPlugin=b;//# sourceMappingURL=index.cjs.map
1007
+ </head>`)}}}function h(t={}){let{ratio:n=2}=t;return {postcssPlugin:"postcss-rpx2px",Declaration(e){e.value?.includes("rpx")&&(e.value=e.value.replace(/(-?\d*\.?\d+)rpx/gi,(r,o)=>{let l=parseFloat(o)/n;return l===0?"0":`${l}px`}));}}}h.postcss=true;function U(t={}){let{additional:n=[],autoInjectTaroApp:e=true,autoInjectVite:r=true}=t,o={},l=new Set(n);return e&&Object.keys(process.env).forEach(i=>{i.startsWith("TARO_APP_")&&l.add(i);}),r&&Object.keys(process.env).forEach(i=>{i.startsWith("VITE_")&&l.add(i);}),l.forEach(i=>{let c=process.env[i]||"";o[`process.env.${i}`]=JSON.stringify(c);}),o}function z(){return {"process.env.TARO_APP_API_BASE_URL":JSON.stringify(process.env.TARO_APP_API_BASE_URL||""),"process.env.VITE_API_BASE_URL":JSON.stringify(process.env.VITE_API_BASE_URL||"")}}function W(t={}){let n=t.isTaro??C__default.default.env.TARO_ENV==="h5",e=[T(),P()];return t.jsxSourceTagger!==false&&e.push(S()),t.tailwindConfigSync!==false&&e.push(b({configPath:t.tailwindConfigPath})),n&&(e.unshift(x(t.styleAdapter)),e.unshift({name:"dev-postcss-rpx2px-plugin",apply:"serve",config(r){typeof r.css?.postcss=="object"&&r.css?.postcss.plugins?.unshift(h());}})),C__default.default.env.WORKSPACE_GIT_REPO&&e.push(I()),e}exports.default=W;exports.editorBridgePlugin=T;exports.injectAmasterEnv=z;exports.injectTaroEnv=U;exports.jsxSourceTaggerPlugin=S;exports.routesExposePlugin=P;exports.rpx2pxPlugin=h;exports.tailwindConfigSyncPlugin=b;exports.taroStyleAdapterPlugin=x;//# sourceMappingURL=index.cjs.map
1107
1008
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/editor-bridge.ts","../src/routes-expose.ts","../src/browser-logs.ts","../src/tagger.ts","../src/tailwind-config-sync.ts","../src/taro-style-adapter.ts","../src/postcss-rpx2px.ts","../src/taro-env-inject.ts","../src/index.ts"],"names":["VIRTUAL_MODULE_ID","RESOLVED_VIRTUAL_MODULE_ID","getBridgeScriptContent","getVirtualModuleContent","sessionKey","editorBridgePlugin","isDev","config","id","html","bridgeScript","routesExposePlugin","options","routesPath","code","browserLogsPlugin","logFilePath","injectedScript","workspaceDir","process","path","dir","fs","devServer","req","res","next","origin","body","chunk","logDir","error","devRuntimeCode","jsxSourceTaggerPlugin","projectRoot","importer","tailwindConfigSyncPlugin","cachedConfig","viteServer","configPath","findConfigFile","configFile","jsConfig","tsConfig","generateConfig","server","tailwindInputFile","configModule","userConfig","resolvedConfig","file","configMod","mod","taroStyleAdapterPlugin","designWidth","maxWidth","baseFontSize","minRootSize","maxRootSize","flexibleScript","rpx2pxPlugin","ratio","decl","_match","num","pxValue","injectTaroEnv","additional","autoInjectTaroApp","autoInjectVite","constants","varsToInject","key","varName","value","injectAmasterEnv","devTools","isTaro","plugins"],"mappings":"uZAEA,IAAMA,CAA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AQ,GAAA,CAAI,iBAAA,EAAqB,EAAE,CACrF,CACF,CClBe,SAARC,CAAAA,CAA0BhE,CAAAA,CAA2B,EAAC,CAAa,CAGxE,IAAMiE,CAAAA,CAASjE,CAAAA,CAAQ,MAAA,EAAUO,kBAAAA,CAAQ,GAAA,CAAI,QAAA,GAAa,IAAA,CAEpD2D,CAAAA,CAAoB,CAExBzE,CAAAA,GACAM,CAAAA,EAEF,CAAA,CAGA,OAAIC,CAAAA,CAAQ,eAAA,GAAoB,KAAA,EAC9BkE,CAAAA,CAAQ,IAAA,CAAK7C,CAAAA,EAAuB,CAAA,CAIlCrB,CAAAA,CAAQ,kBAAA,GAAuB,KAAA,EACjCkE,CAAAA,CAAQ,IAAA,CACN1C,CAAAA,CAAyB,CACvB,UAAA,CAAYxB,CAAAA,CAAQ,kBACtB,CAAC,CACH,CAAA,CAIEiE,CAAAA,GAEFC,CAAAA,CAAQ,OAAA,CAAQzB,CAAAA,CAAuBzC,CAAAA,CAAQ,YAAY,CAAC,EAG5DkE,CAAAA,CAAQ,OAAA,CAAQ,CACd,IAAA,CAAM,2BAAA,CACN,KAAA,CAAO,OAAA,CACP,MAAA,CAAOvE,CAAAA,CAAQ,CACT,OAAOA,CAAAA,CAAO,GAAA,EAAK,OAAA,EAAY,QAAA,EAEjCA,CAAAA,CAAO,KAAK,OAAA,CAAQ,OAAA,EAAS,OAAA,CAAQqD,CAAAA,EAAc,EAEvD,CACF,CAAC,CAAA,CAAA,CAICzC,kBAAAA,CAAQ,GAAA,CAAI,kBAAA,EACd2D,CAAAA,CAAQ,IAAA,CAAK/D,CAAAA,EAAmB,EAG3B+D,CACT","file":"index.cjs","sourcesContent":["import type { Plugin } from \"vite\";\n\nconst VIRTUAL_MODULE_ID = \"@amaster/bridge-monitor\";\nconst RESOLVED_VIRTUAL_MODULE_ID = \"\\0\" + VIRTUAL_MODULE_ID;\n\n/**\n * Generate bridge script content with environment variables\n */\nfunction getBridgeScriptContent() {\n return `<script type=\"module\" src=\"/@id/@amaster/bridge-monitor\"></script>`;\n}\n\n/**\n * Generate virtual module content for HMR and Tailwind config monitoring\n */\nfunction getVirtualModuleContent(sessionKey: string) {\n return `\n// Bridge monitor module - handles all bridge logic\nconst SOURCE_KEY = Symbol.for(\"__jsxSource__\");\nconst SESSION_KEY = \"${sessionKey}\";\n\n// Expose minimal API for external bridge script\nwindow.__AMASTER_BRIDGE__ = {\n getSourceInfo: (element) => element?.[SOURCE_KEY],\n getSourceMap: () => window.sourceElementMap,\n postToParent: (type, data) => {\n window.parent.postMessage({ type, data, key: SESSION_KEY }, \"*\");\n },\n isDev: true,\n};\n\n// Listen for HMR updates\nif (import.meta.hot) {\n import.meta.hot.on('vite:afterUpdate', (payload) => {\n // Dispatch custom event for bridge.js to listen\n window.dispatchEvent(new CustomEvent('amaster:hmr-update', {\n detail: {\n updates: payload?.updates || []\n }\n }));\n });\n}\n\n// Import and monitor Tailwind config\n(async () => {\n try {\n const tailwindConfig = await import('@amaster/tailwind-config');\n let config = tailwindConfig.default;\n const onUpdate = tailwindConfig.onUpdate;\n \n if (!config) {\n return;\n }\n \n const sendConfig = (type, newConfig) => {\n config = newConfig || config;\n const serializableConfig = JSON.parse(JSON.stringify(config));\n \n // Dispatch event for bridge.js to handle\n window.dispatchEvent(new CustomEvent('amaster:tailwind-config', {\n detail: {\n type: type,\n config: serializableConfig\n }\n }));\n };\n \n // Send initial config\n sendConfig('loaded');\n \n // Listen for bridge ready event and resend config\n window.addEventListener('amaster:bridge-ready', () => {\n sendConfig('loaded');\n });\n \n // Listen for config updates\n if (onUpdate) {\n onUpdate((newConfig) => {\n sendConfig('updated', newConfig);\n });\n }\n } catch (e) {\n // Silently fail if tailwind config is not available\n }\n})();\n\n// Listen for bridge script URL from platform\nwindow.addEventListener(\"message\", (event) => {\n const { type, data, key } = event.data;\n \n if (key !== SESSION_KEY) {\n return;\n }\n \n if (type === \"amaster.loadBridge\" && data?.scriptContent) {\n // Create blob URL from script content\n const blob = new Blob([data.scriptContent], { type: 'application/javascript' });\n const blobUrl = URL.createObjectURL(blob);\n \n const script = document.createElement(\"script\");\n script.src = blobUrl;\n script.onload = () => {\n URL.revokeObjectURL(blobUrl);\n };\n script.onerror = () => {\n URL.revokeObjectURL(blobUrl);\n };\n document.head.appendChild(script);\n }\n});\n\nwindow.addEventListener(\"DOMContentLoaded\", () => {\n window.__AMASTER_BRIDGE__?.postToParent(\"amaster.bridge.initialized\", {});\n});\n\nexport default {};\n`;\n}\n\n/**\n * Vite plugin: Inject editor bridge script\n * Injects minimal bridge that loads external script from platform\n * Also provides virtual module for HMR and Tailwind config monitoring\n */\nexport function editorBridgePlugin(): Plugin {\n let isDev = false;\n\n return {\n name: \"vite-plugin-editor-bridge\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n },\n\n resolveId(id) {\n if (id === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_MODULE_ID) {\n // Virtual module is now inlined in HTML, but keep this for potential future use\n const sessionKey = process.env.VITE_AMASTER_KEY || \"\";\n return getVirtualModuleContent(sessionKey);\n }\n },\n\n transformIndexHtml(html) {\n if (!isDev) return html;\n\n const bridgeScript = getBridgeScriptContent();\n return html.replace(\"</body>\", `${bridgeScript}</body>`);\n },\n };\n}\n","import type { Plugin } from \"vite\";\n\n/**\n * Vite plugin: Expose routes to window.__APP_ROUTES__\n * Only enabled in development mode\n */\nexport function routesExposePlugin(options?: { routesFilePath?: string }): Plugin {\n let isDev = false;\n const routesPath = options?.routesFilePath || \"src/routes.tsx\";\n\n return {\n name: \"vite-plugin-routes-expose\",\n enforce: \"post\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n },\n\n transform(code: string, id: string) {\n if (!isDev) {\n return null;\n }\n\n if (!id.endsWith(routesPath)) {\n return null;\n }\n\n try {\n if (code.includes(\"window.__APP_ROUTES__\")) {\n return null;\n }\n\n const transformedCode = `${code}\n\n// Development mode: Expose routes to window.__APP_ROUTES__\nif (typeof window !== 'undefined') {\n window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];\n}\n`;\n\n return {\n code: transformedCode,\n map: null,\n };\n } catch {\n return null;\n }\n },\n };\n}\n","import type { Plugin } from \"vite\";\nimport { Buffer } from \"node:buffer\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\n\n/**\n * Browser logs collection plugin\n * Injects script into HTML head to collect console logs and network requests\n * Logs are written directly to browser.log file (same level as index.html)\n */\nexport function browserLogsPlugin(): Plugin {\n let logFilePath = \"\";\n\n // Script to inject into browser\n const injectedScript = `\n<script>\n(function() {\n 'use strict';\n \n // Log API path (provided by Vite dev server)\n var LOG_API_PATH = '/__browser__';\n \n // Save original fetch before any interception, used exclusively for log writing\n var __originalFetch__ = window.fetch.bind(window);\n \n // Write queue to ensure sequential writes\n var writeQueue = [];\n var isWriting = false;\n \n // Process write queue to ensure sequential writes\n function processWriteQueue() {\n if (isWriting || writeQueue.length === 0) return;\n \n isWriting = true;\n var entry = writeQueue.shift();\n var logText = JSON.stringify(entry);\n \n __originalFetch__(LOG_API_PATH, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: logText\n })\n .then(function(response) {\n isWriting = false;\n if (!response.ok) {\n console.warn('[BrowserLogs] Failed to write log:', response.status);\n }\n // Continue processing next item in queue\n processWriteQueue();\n })\n .catch(function(error) {\n console.warn('[BrowserLogs] Failed to write log:', error.message);\n // On failure, put log back to queue head for retry\n writeQueue.unshift(entry);\n isWriting = false;\n // Retry after delay\n setTimeout(processWriteQueue, 1000);\n });\n }\n \n // Limit headers object size\n function truncateHeaders(headers) {\n if (!headers) return headers;\n var jsonStr = JSON.stringify(headers);\n if (jsonStr.length <= MAX_HEADER_SIZE) return headers;\n return '[Headers truncated, size: ' + jsonStr.length + ']';\n }\n \n // Truncate oversized log entries\n function truncateLogEntry(entry) {\n var jsonStr = JSON.stringify(entry);\n if (jsonStr.length <= MAX_LOG_ENTRY_SIZE) {\n return entry;\n }\n \n // If oversized, progressively truncate non-critical fields\n var truncated = Object.assign({}, entry);\n \n // 1. Truncate response body first\n if (truncated.responseBody && typeof truncated.responseBody === 'string') {\n truncated.responseBody = truncated.responseBody.substring(0, 500) + '... [truncated]';\n }\n \n // 2. Truncate request body\n if (truncated.requestBody && typeof truncated.requestBody === 'string') {\n truncated.requestBody = truncated.requestBody.substring(0, 500) + '... [truncated]';\n }\n \n // 3. Truncate message\n if (truncated.message && typeof truncated.message === 'string' && truncated.message.length > 1000) {\n truncated.message = truncated.message.substring(0, 1000) + '... [truncated]';\n }\n \n // 4. Truncate stack\n if (truncated.stack && Array.isArray(truncated.stack) && truncated.stack.length > 3) {\n truncated.stack = truncated.stack.slice(0, 3);\n }\n \n // Add truncation marker\n truncated._truncated = true;\n truncated._originalSize = jsonStr.length;\n \n return truncated;\n }\n \n // Add log and send immediately (ensure order)\n function addLog(entry) {\n var truncatedEntry = truncateLogEntry(entry);\n writeQueue.push(truncatedEntry);\n processWriteQueue();\n }\n \n // ============================================\n // Console log collection\n // ============================================\n var originalConsole = {\n log: console.log,\n info: console.info,\n warn: console.warn,\n error: console.error,\n debug: console.debug\n };\n \n function getStackTrace() {\n var stack = new Error().stack || '';\n var lines = stack.split('\\\\n').slice(3);\n // Limit stack lines\n return lines.slice(0, MAX_STACK_LINES).map(function(line) { return line.trim(); });\n }\n \n function formatMessage(args) {\n return Array.from(args).map(function(arg) {\n if (arg === null) return 'null';\n if (arg === undefined) return 'undefined';\n if (typeof arg === 'object') {\n try {\n return JSON.stringify(arg);\n } catch (e) {\n return String(arg);\n }\n }\n return String(arg);\n }).join(' ');\n }\n \n function createLogEntry(level, args) {\n return {\n type: 'console',\n timestamp: new Date().toISOString(),\n level: level,\n message: formatMessage(args),\n stack: getStackTrace()\n };\n }\n \n // Keywords to filter from console log collection\n var FILTERED_CONSOLE_KEYWORDS = ['[vite]', '[BrowserLogs]'];\n \n // Check if message should be filtered\n function shouldFilterConsoleLog(args) {\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n if (typeof arg === 'string') {\n for (var j = 0; j < FILTERED_CONSOLE_KEYWORDS.length; j++) {\n if (arg.indexOf(FILTERED_CONSOLE_KEYWORDS[j]) !== -1) {\n return true;\n }\n }\n }\n }\n return false;\n }\n \n function wrapConsoleMethod(method, level) {\n return function() {\n var args = arguments;\n // Filter out logs containing [vite]\n if (shouldFilterConsoleLog(args)) {\n return originalConsole[method].apply(console, args);\n }\n var entry = createLogEntry(level, args);\n addLog(entry);\n return originalConsole[method].apply(console, args);\n };\n }\n \n console.log = wrapConsoleMethod('log', 'log');\n console.info = wrapConsoleMethod('info', 'info');\n console.warn = wrapConsoleMethod('warn', 'warn');\n console.error = wrapConsoleMethod('error', 'error');\n console.debug = wrapConsoleMethod('debug', 'debug');\n \n // ============================================\n // Network request collection (exclude SSE and log API requests)\n // ============================================\n \n var MAX_BODY_SIZE = 2000;\n var MAX_LOG_ENTRY_SIZE = 3000; // Max single log entry length\n var MAX_HEADER_SIZE = 500; // Max single header object length\n var MAX_STACK_LINES = 5; // Max stack lines to keep\n const FILTERED_URLS = ['/__browser__', '/builtin']; // Filter out log API and Vite built-in requests\n \n function isSSERequest(url, headers) {\n var sseUrlPatterns = ['/events', '/sse', '/stream', 'text/event-stream'];\n var urlStr = String(url).toLowerCase();\n for (var i = 0; i < sseUrlPatterns.length; i++) {\n if (urlStr.indexOf(sseUrlPatterns[i]) !== -1) {\n return true;\n }\n }\n \n if (headers) {\n if (typeof headers.get === 'function') {\n var accept = headers.get('Accept') || headers.get('accept');\n if (accept && accept.indexOf('text/event-stream') !== -1) {\n return true;\n }\n } else if (typeof headers === 'object') {\n for (var key in headers) {\n if (key.toLowerCase() === 'accept' && headers[key].indexOf('text/event-stream') !== -1) {\n return true;\n }\n }\n }\n }\n \n return false;\n }\n \n function shouldFilterRequest(url) {\n return FILTERED_URLS.some(function(filteredUrl) {\n return String(url).indexOf(filteredUrl) !== -1;\n });\n }\n \n function formatRequestBody(body) {\n if (!body) return null;\n \n try {\n if (typeof body === 'string') {\n return body.substring(0, MAX_BODY_SIZE);\n }\n if (body instanceof FormData) {\n var formDataObj = {};\n body.forEach(function(value, key) {\n if (value instanceof File) {\n formDataObj[key] = '[File: ' + value.name + ', size: ' + value.size + ']';\n } else {\n formDataObj[key] = String(value).substring(0, 1000);\n }\n });\n return JSON.stringify(formDataObj);\n }\n if (body instanceof Blob) {\n return '[Blob: size=' + body.size + ', type=' + body.type + ']';\n }\n if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {\n return '[Binary: size=' + body.byteLength + ']';\n }\n if (body instanceof URLSearchParams) {\n return body.toString().substring(0, MAX_BODY_SIZE);\n }\n return String(body).substring(0, MAX_BODY_SIZE);\n } catch (e) {\n return '[Error reading body: ' + e.message + ']';\n }\n }\n \n function formatResponseBody(response, responseType) {\n if (!response) return null;\n \n try {\n if (responseType === '' || responseType === 'text') {\n return String(response).substring(0, MAX_BODY_SIZE);\n }\n if (responseType === 'json') {\n return JSON.stringify(response).substring(0, MAX_BODY_SIZE);\n }\n if (responseType === 'document') {\n return '[Document]';\n }\n if (responseType === 'blob') {\n return '[Blob: size=' + response.size + ']';\n }\n if (responseType === 'arraybuffer') {\n return '[ArrayBuffer: size=' + response.byteLength + ']';\n }\n return String(response).substring(0, MAX_BODY_SIZE);\n } catch (e) {\n return '[Error reading response: ' + e.message + ']';\n }\n }\n \n // Intercept XMLHttpRequest\n var originalXHROpen = XMLHttpRequest.prototype.open;\n var originalXHRSend = XMLHttpRequest.prototype.send;\n var originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;\n \n XMLHttpRequest.prototype.open = function(method, url, async, user, password) {\n this.__requestInfo__ = {\n method: method,\n url: url,\n startTime: null,\n headers: {}\n };\n return originalXHROpen.apply(this, arguments);\n };\n \n XMLHttpRequest.prototype.setRequestHeader = function(name, value) {\n if (this.__requestInfo__ && this.__requestInfo__.headers) {\n this.__requestInfo__.headers[name] = value;\n }\n return originalXHRSetRequestHeader.apply(this, arguments);\n };\n \n XMLHttpRequest.prototype.send = function(body) {\n var xhr = this;\n var requestInfo = xhr.__requestInfo__;\n \n if (requestInfo) {\n // Skip SSE requests and filtered requests\n if (isSSERequest(requestInfo.url, requestInfo.headers) || shouldFilterRequest(requestInfo.url)) {\n return originalXHRSend.apply(this, arguments);\n }\n \n requestInfo.startTime = Date.now();\n requestInfo.requestBody = formatRequestBody(body);\n \n xhr.addEventListener('loadend', function() {\n var contentType = xhr.getResponseHeader('Content-Type') || '';\n if (contentType.indexOf('text/event-stream') !== -1) {\n return;\n }\n \n var responseHeaders = {};\n var allHeaders = xhr.getAllResponseHeaders();\n if (allHeaders) {\n allHeaders.split('\\\\r\\\\n').forEach(function(line) {\n var parts = line.split(': ');\n if (parts.length === 2) {\n responseHeaders[parts[0]] = parts[1];\n }\n });\n }\n \n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'xhr',\n method: requestInfo.method,\n url: requestInfo.url,\n status: xhr.status,\n statusText: xhr.statusText,\n duration: Date.now() - requestInfo.startTime,\n requestHeaders: truncateHeaders(requestInfo.headers),\n requestBody: requestInfo.requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseType: xhr.responseType,\n responseBody: formatResponseBody(xhr.response, xhr.responseType),\n responseSize: xhr.response ? (typeof xhr.response === 'string' ? xhr.response.length : (xhr.response.byteLength || xhr.response.size || null)) : null\n };\n \n addLog(entry);\n });\n }\n \n return originalXHRSend.apply(this, arguments);\n };\n \n // Intercept Fetch API\n var originalFetch = window.fetch;\n \n function headersToObject(headers) {\n var obj = {};\n if (!headers) return obj;\n \n if (typeof headers.forEach === 'function') {\n headers.forEach(function(value, key) {\n obj[key] = value;\n });\n } else if (typeof headers === 'object') {\n for (var key in headers) {\n obj[key] = headers[key];\n }\n }\n return obj;\n }\n \n window.fetch = function(input, init) {\n var startTime = Date.now();\n var method = (init && init.method) || 'GET';\n var url = typeof input === 'string' ? input : input.url;\n var headers = init && init.headers;\n \n // Skip SSE requests and filtered requests\n if (isSSERequest(url, headers) || shouldFilterRequest(url)) {\n return originalFetch.apply(this, arguments);\n }\n \n var requestHeaders = headersToObject(headers);\n var requestBody = formatRequestBody(init && init.body);\n \n return originalFetch.apply(this, arguments)\n .then(function(response) {\n var contentType = response.headers.get('Content-Type') || '';\n if (contentType.indexOf('text/event-stream') !== -1) {\n return response;\n }\n \n var clonedResponse = response.clone();\n var responseHeaders = headersToObject(response.headers);\n \n clonedResponse.text().then(function(bodyText) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: response.status,\n statusText: response.statusText,\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseBody: bodyText ? bodyText.substring(0, MAX_BODY_SIZE) : null,\n responseSize: bodyText ? bodyText.length : null,\n ok: response.ok\n };\n \n addLog(entry);\n }).catch(function(e) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: response.status,\n statusText: response.statusText,\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseBody: '[Unable to read: ' + e.message + ']',\n responseSize: null,\n ok: response.ok\n };\n \n addLog(entry);\n });\n \n return response;\n })\n .catch(function(error) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: 0,\n statusText: 'Network Error',\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: null,\n responseBody: null,\n error: error.message\n };\n \n addLog(entry);\n throw error;\n });\n };\n \n // ============================================\n // Global error capture\n // ============================================\n window.addEventListener('error', function(event) {\n var entry = {\n type: 'error',\n timestamp: new Date().toISOString(),\n level: 'error',\n message: event.message,\n stack: event.error ? event.error.stack : 'at ' + event.filename + ':' + event.lineno + ':' + event.colno\n };\n addLog(entry);\n });\n \n // ============================================\n // Vite deps 504 error capture using PerformanceObserver\n // Only captures 504 errors for node_modules/.vite resources (pre-bundled dependencies)\n // ============================================\n var reportedUrls = {}; // Track reported URLs to avoid duplicates\n \n if (typeof PerformanceObserver !== 'undefined') {\n var perfObserver = new PerformanceObserver(function(list) {\n var entries = list.getEntries();\n for (var i = 0; i < entries.length; i++) {\n var perfEntry = entries[i];\n // Only check script resources\n if (perfEntry.initiatorType !== 'script') {\n continue;\n }\n \n var resourceUrl = perfEntry.name || '';\n // Only report errors for node_modules/.vite resources\n if (resourceUrl.indexOf('node_modules/.vite') === -1 && resourceUrl.indexOf('/node_modules/.vite') === -1) {\n continue;\n }\n \n // Check if response status is 504 (Gateway Timeout)\n // responseStatus is available in Resource Timing Level 2\n var status = perfEntry.responseStatus;\n if (status === 504) {\n // Avoid duplicate reports\n if (reportedUrls[resourceUrl]) {\n continue;\n }\n reportedUrls[resourceUrl] = true;\n \n var entry = {\n type: 'vite-deps-error',\n timestamp: new Date().toISOString(),\n level: 'error',\n url: resourceUrl,\n status: 504,\n message: 'Vite pre-bundled dependency returned 504 Gateway Timeout: ' + resourceUrl,\n duration: perfEntry.duration,\n transferSize: perfEntry.transferSize\n };\n addLog(entry);\n }\n }\n });\n \n try {\n perfObserver.observe({ type: 'resource', buffered: true });\n } catch (e) {\n // Fallback for browsers that don't support the options\n try {\n perfObserver.observe({ entryTypes: ['resource'] });\n } catch (e2) {\n originalConsole.warn('[BrowserLogs] PerformanceObserver not supported:', e2.message);\n }\n }\n }\n \n // ============================================\n // Script load error capture (for 504 and other network errors)\n // This captures errors that PerformanceObserver might miss\n // ============================================\n \n // Use MutationObserver to watch for dynamically added script tags\n function attachScriptErrorHandler(script) {\n if (script.__errorHandlerAttached__) return;\n script.__errorHandlerAttached__ = true;\n \n script.addEventListener('error', function(event) {\n var src = script.src || '';\n \n // Only report errors for node_modules/.vite resources\n if (src.indexOf('node_modules/.vite') === -1 && src.indexOf('/node_modules/.vite') === -1) {\n return;\n }\n \n // Avoid duplicate reports\n if (reportedUrls[src]) {\n return;\n }\n reportedUrls[src] = true;\n \n var entry = {\n type: 'vite-deps-error',\n timestamp: new Date().toISOString(),\n level: 'error',\n url: src,\n status: 'load-error',\n message: 'Vite pre-bundled dependency failed to load (possibly 504 Gateway Timeout): ' + src,\n errorType: event.type\n };\n addLog(entry);\n });\n }\n \n // Attach error handlers to existing scripts\n var existingScripts = document.querySelectorAll('script[src]');\n for (var i = 0; i < existingScripts.length; i++) {\n attachScriptErrorHandler(existingScripts[i]);\n }\n \n // Watch for dynamically added scripts\n if (typeof MutationObserver !== 'undefined') {\n var scriptObserver = new MutationObserver(function(mutations) {\n for (var i = 0; i < mutations.length; i++) {\n var mutation = mutations[i];\n for (var j = 0; j < mutation.addedNodes.length; j++) {\n var node = mutation.addedNodes[j];\n if (node.nodeName === 'SCRIPT' && node.src) {\n attachScriptErrorHandler(node);\n }\n // Also check child nodes\n if (node.querySelectorAll) {\n var scripts = node.querySelectorAll('script[src]');\n for (var k = 0; k < scripts.length; k++) {\n attachScriptErrorHandler(scripts[k]);\n }\n }\n }\n }\n });\n \n scriptObserver.observe(document.documentElement, {\n childList: true,\n subtree: true\n });\n }\n \n // Also intercept document.createElement to catch scripts before they're added to DOM\n var originalCreateElement = document.createElement.bind(document);\n document.createElement = function(tagName) {\n var element = originalCreateElement(tagName);\n if (tagName.toLowerCase() === 'script') {\n // Use a setter to catch when src is set\n var originalSrc = '';\n Object.defineProperty(element, '__originalSrc__', {\n get: function() { return originalSrc; },\n set: function(val) { originalSrc = val; }\n });\n \n // Defer attaching error handler until src is set\n var srcDescriptor = Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src');\n if (srcDescriptor && srcDescriptor.set) {\n var originalSrcSetter = srcDescriptor.set;\n Object.defineProperty(element, 'src', {\n get: function() {\n return srcDescriptor.get ? srcDescriptor.get.call(this) : this.getAttribute('src');\n },\n set: function(value) {\n if (originalSrcSetter) {\n originalSrcSetter.call(this, value);\n } else {\n this.setAttribute('src', value);\n }\n attachScriptErrorHandler(this);\n },\n configurable: true\n });\n }\n }\n return element;\n };\n \n window.addEventListener('unhandledrejection', function(event) {\n var entry = {\n type: 'error',\n timestamp: new Date().toISOString(),\n level: 'error',\n message: 'Unhandled Promise Rejection: ' + (event.reason ? (event.reason.message || String(event.reason)) : 'Unknown'),\n stack: event.reason && event.reason.stack ? event.reason.stack : ''\n };\n addLog(entry);\n });\n \n // ============================================\n // Send remaining logs on page unload\n // ============================================\n window.addEventListener('beforeunload', function() {\n if (writeQueue.length > 0) {\n // Use sendBeacon to ensure logs are sent\n writeQueue.forEach(function(entry) {\n navigator.sendBeacon(LOG_API_PATH, JSON.stringify(entry));\n });\n writeQueue = [];\n }\n });\n \n // ============================================\n // Provide manual flush method\n // ============================================\n window.__flushBrowserLogs__ = function() {\n return new Promise(function(resolve) {\n // Wait for queue to finish processing\n function checkQueue() {\n if (writeQueue.length === 0 && !isWriting) {\n resolve();\n } else {\n setTimeout(checkQueue, 100);\n }\n }\n checkQueue();\n });\n };\n \n // Provide method to get queue status\n window.__getBrowserLogsStatus__ = function() {\n return {\n queueLength: writeQueue.length,\n isWriting: isWriting\n };\n };\n \n originalConsole.log('[BrowserLogs] Log collection started');\n})();\n</script>`;\n\n return {\n name: \"vite-plugin-browser-logs\",\n\n configResolved(config) {\n // Determine log file path: use WORKSPACE_DIR env var (set by PM2/Docker),\n // or find the nearest directory containing package.json from config.root,\n // to ensure browser.log is always at the workspace root level.\n const workspaceDir = process.env.WORKSPACE_DIR;\n if (workspaceDir) {\n logFilePath = path.join(workspaceDir, \"browser.log\");\n } else {\n // Fallback: walk up from config.root to find directory with package.json\n let dir = config.root || process.cwd();\n while (dir !== path.dirname(dir)) {\n if (fs.existsSync(path.join(dir, \"package.json\"))) {\n break;\n }\n dir = path.dirname(dir);\n }\n logFilePath = path.join(dir, \"browser.log\");\n }\n },\n\n configureServer(devServer) {\n // Add log write API\n devServer.middlewares.use((req, res, next) => {\n if (req.url === \"/__browser__\" && req.method === \"POST\") {\n // Get request origin, dynamically set CORS headers to avoid protocol mismatch\n const origin = req.headers.origin || \"*\";\n\n let body = \"\";\n req.on(\"data\", (chunk: Buffer) => {\n body += chunk.toString();\n });\n req.on(\"end\", () => {\n try {\n // Ensure log directory exists\n const logDir = path.dirname(logFilePath);\n if (!fs.existsSync(logDir)) {\n fs.mkdirSync(logDir, { recursive: true });\n }\n // Append to log file\n fs.appendFileSync(logFilePath, `${body}\\n`, \"utf-8\");\n res.writeHead(200, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n });\n res.end(JSON.stringify({ success: true }));\n } catch (error) {\n console.error(\"[BrowserLogs] Write error:\", error);\n res.writeHead(500, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n });\n res.end(JSON.stringify({ success: false, error: String(error) }));\n }\n });\n } else if (req.url === \"/__browser__\" && req.method === \"OPTIONS\") {\n // Handle CORS preflight request\n const origin = req.headers.origin || \"*\";\n res.writeHead(204, {\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n \"Access-Control-Max-Age\": \"86400\",\n });\n res.end();\n } else if (req.url === \"/__browser__\") {\n const origin = req.headers.origin || \"*\";\n res.writeHead(405, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n });\n res.end(JSON.stringify({ error: \"Method not allowed\" }));\n } else {\n next();\n }\n });\n\n console.log(\"[BrowserLogs] Logs will be written to:\", logFilePath);\n },\n\n transformIndexHtml(html) {\n // Insert script after <head> tag to ensure earliest execution\n return html.replace(/<head([^>]*)>/i, `<head$1>${injectedScript}`);\n },\n };\n}\n","import type { Plugin } from \"vite\";\n\n/**\n * Runtime code that will be injected to replace react/jsx-dev-runtime\n * This code tags DOM elements with source information using refs\n */\nconst devRuntimeCode = `\nimport * as React from \"react\";\nimport * as ReactJSXDevRuntime from \"react/jsx-dev-runtime\";\n\nconst _jsxDEV = ReactJSXDevRuntime.jsxDEV;\nexport const Fragment = ReactJSXDevRuntime.Fragment;\n\nconst SOURCE_KEY = Symbol.for(\"__jsxSource__\");\nconst PROJECT_ROOT = \"\";\n\nconst cleanFileName = (fileName) => {\n if (!fileName) return \"\";\n // Remove project root prefix to get relative path\n if (PROJECT_ROOT && fileName.startsWith(PROJECT_ROOT)) {\n const relative = fileName.slice(PROJECT_ROOT.length);\n return relative.startsWith(\"/\") ? relative.slice(1) : relative;\n }\n return fileName;\n};\n\n// Global map to track elements by source location\nconst sourceElementMap = new Map();\nwindow.sourceElementMap = sourceElementMap;\n\nfunction getSourceKey(sourceInfo) {\n return \\`\\${cleanFileName(sourceInfo.fileName)}:\\${sourceInfo.lineNumber}:\\${sourceInfo.columnNumber}\\`;\n}\n\nfunction unregisterElement(node, sourceInfo) {\n const key = getSourceKey(sourceInfo);\n const refs = sourceElementMap.get(key);\n if (refs) {\n for (const ref of refs) {\n if (ref.deref() === node) {\n refs.delete(ref);\n break;\n }\n }\n if (refs.size === 0) {\n sourceElementMap.delete(key);\n }\n }\n}\n\nfunction registerElement(node, sourceInfo) {\n const key = getSourceKey(sourceInfo);\n if (!sourceElementMap.has(key)) {\n sourceElementMap.set(key, new Set());\n }\n sourceElementMap.get(key).add(new WeakRef(node));\n}\n\nfunction getTypeName(type) {\n if (typeof type === \"string\") return type;\n if (typeof type === \"function\") return type.displayName || type.name || \"Unknown\";\n if (typeof type === \"object\" && type !== null) {\n return type.displayName || type.render?.displayName || type.render?.name || \"Unknown\";\n }\n return \"Unknown\";\n}\n\nexport function jsxDEV(type, props, key, isStatic, source, self) {\n // For custom components, tag their rendered output\n if (source?.fileName && typeof type !== \"string\" && type !== Fragment) {\n const typeName = getTypeName(type);\n const fileName = cleanFileName(source.fileName);\n \n const jsxSourceInfo = {\n fileName,\n lineNumber: source.lineNumber,\n columnNumber: source.columnNumber,\n displayName: typeName,\n isComponent: true,\n };\n\n const originalRef = props?.ref;\n \n // Check if component can safely receive refs\n // - forwardRef components have $$typeof symbol\n // - Class components have prototype.isReactComponent\n // - If there's already a ref, the component expects it\n const isForwardRef = type.$$typeof === Symbol.for('react.forward_ref');\n const isClassComponent = typeof type === 'function' && type.prototype?.isReactComponent;\n const hasExistingRef = originalRef !== undefined;\n \n const canReceiveRef = isForwardRef || isClassComponent || hasExistingRef;\n \n if (canReceiveRef) {\n const enhancedProps = {\n ...props,\n ref: (node) => {\n if (node) {\n const existingSource = node[SOURCE_KEY];\n if (existingSource) {\n // 组件级的 source 总是覆盖元素级的 source\n if (!existingSource.isComponent) {\n unregisterElement(node, existingSource);\n node[SOURCE_KEY] = jsxSourceInfo;\n registerElement(node, jsxSourceInfo);\n }\n } else {\n node[SOURCE_KEY] = jsxSourceInfo;\n registerElement(node, jsxSourceInfo);\n }\n }\n if (typeof originalRef === \"function\") {\n originalRef(node);\n } else if (originalRef && typeof originalRef === \"object\") {\n originalRef.current = node;\n }\n },\n };\n return _jsxDEV(type, enhancedProps, key, isStatic, source, self);\n }\n\n return _jsxDEV(type, props, key, isStatic, source, self);\n }\n\n // For host elements (div, span, etc.), tag with source info\n if (source?.fileName && typeof type === \"string\") {\n const fileName = cleanFileName(source.fileName);\n \n // 判断当前元素是否在组件库中定义\n const isInLibrary = fileName.includes('/components/') || \n fileName.includes('/ui/') || \n fileName.includes('node_modules');\n \n // 组件库内部的元素不标记,不支持可视化编辑\n if (isInLibrary) {\n return _jsxDEV(type, props, key, isStatic, source, self);\n }\n \n const sourceInfo = {\n fileName,\n lineNumber: source.lineNumber,\n columnNumber: source.columnNumber,\n displayName: type,\n isComponent: false, // 标记这是元素级别的 source\n };\n\n const originalRef = props?.ref;\n\n const enhancedProps = {\n ...props,\n ref: (node) => {\n if (node) {\n const existingSource = node[SOURCE_KEY];\n // 如果已有 source,检查是否应该保留外层的\n if (existingSource) {\n // 如果已有的是组件级别的 source(isComponent: true),保留它\n if (existingSource.isComponent) {\n // 不更新,保留组件级别的 source\n if (typeof originalRef === \"function\") {\n originalRef(node);\n } else if (originalRef && typeof originalRef === \"object\") {\n originalRef.current = node;\n }\n return;\n }\n \n // 否则按正常逻辑更新\n if (getSourceKey(existingSource) !== getSourceKey(sourceInfo)) {\n unregisterElement(node, existingSource);\n node[SOURCE_KEY] = sourceInfo;\n registerElement(node, sourceInfo);\n }\n } else {\n node[SOURCE_KEY] = sourceInfo;\n registerElement(node, sourceInfo);\n }\n }\n if (typeof originalRef === \"function\") {\n originalRef(node);\n } else if (originalRef && typeof originalRef === \"object\") {\n originalRef.current = node;\n }\n },\n };\n return _jsxDEV(type, enhancedProps, key, isStatic, source, self);\n }\n\n return _jsxDEV(type, props, key, isStatic, source, self);\n}\n`;\n\n/**\n * Vite plugin: JSX Source Tagger\n * Intercepts react/jsx-dev-runtime to add source information to DOM elements\n * Only enabled in development mode\n */\nexport function jsxSourceTaggerPlugin(): Plugin {\n let isDev = false;\n let projectRoot = \"\";\n\n return {\n name: \"vite-plugin-jsx-source-tagger\",\n enforce: \"pre\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n projectRoot = config.root;\n },\n\n resolveId(id, importer) {\n if (!isDev) return null;\n\n // Intercept react/jsx-dev-runtime imports\n if (id === \"react/jsx-dev-runtime\" && !importer?.includes(\"\\0jsx-source\")) {\n return \"\\0jsx-source/jsx-dev-runtime\";\n }\n return null;\n },\n\n load(id) {\n if (!isDev) return null;\n\n // Return our custom runtime code with injected projectRoot\n if (id === \"\\0jsx-source/jsx-dev-runtime\") {\n return devRuntimeCode.replace(\n 'const PROJECT_ROOT = \"\";',\n `const PROJECT_ROOT = ${JSON.stringify(projectRoot)};`\n );\n }\n return null;\n },\n };\n}\n","import type { Plugin } from \"vite\";\nimport fs from \"fs/promises\";\nimport path from \"path\";\n\n/**\n * Vite plugin: Tailwind Config Sync\n * Simplified version - just return raw config without resolveConfig\n */\nexport function tailwindConfigSyncPlugin(options?: { configPath?: string }): Plugin {\n let projectRoot = \"\";\n let isDev = false;\n let cachedConfig: Record<string, unknown> | null = null;\n let viteServer: any = null;\n\n const configPath = options?.configPath || \"./tailwind.config.ts\";\n const VIRTUAL_MODULE_ID = \"@amaster/tailwind-config\";\n const RESOLVED_VIRTUAL_MODULE_ID = \"\\0\" + VIRTUAL_MODULE_ID;\n\n const findConfigFile = async (): Promise<string | null> => {\n const configFile = path.resolve(projectRoot, configPath);\n\n try {\n await fs.access(configFile);\n return configFile;\n } catch {\n // If specified config doesn't exist, try alternative extensions\n if (configPath.endsWith(\".ts\")) {\n const jsConfig = configFile.replace(/\\.ts$/, \".js\");\n try {\n await fs.access(jsConfig);\n return jsConfig;\n } catch {\n return null;\n }\n } else if (configPath.endsWith(\".js\")) {\n const tsConfig = configFile.replace(/\\.js$/, \".ts\");\n try {\n await fs.access(tsConfig);\n return tsConfig;\n } catch {\n return null;\n }\n }\n return null;\n }\n };\n\n const generateConfig = async (server?: any): Promise<Record<string, unknown> | null> => {\n try {\n const tailwindInputFile = await findConfigFile();\n if (!tailwindInputFile) {\n return null;\n }\n\n // If we have a Vite server, use its module graph to load the config\n // This ensures we get the latest version after HMR\n if (server) {\n const configModule = await server.ssrLoadModule(tailwindInputFile);\n const rawConfig = configModule.default || configModule;\n cachedConfig = rawConfig;\n return cachedConfig;\n }\n\n // Fallback: use dynamic import with cache busting\n const configUrl = `file://${tailwindInputFile}?t=${Date.now()}`;\n const userConfig = await import(configUrl);\n\n const rawConfig = userConfig.default || userConfig;\n cachedConfig = rawConfig;\n return cachedConfig;\n } catch (error) {\n console.error(\"[tailwind-config-sync] Failed to generate config:\", error);\n return null;\n }\n };\n\n return {\n name: \"vite-plugin-tailwind-config-sync\",\n\n configResolved(resolvedConfig) {\n projectRoot = resolvedConfig.root;\n isDev = resolvedConfig.command === \"serve\";\n },\n\n async buildStart() {\n if (!isDev) return;\n await generateConfig();\n },\n\n resolveId(id) {\n if (id === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n },\n\n async load(id) {\n if (id === RESOLVED_VIRTUAL_MODULE_ID) {\n // Always regenerate config to get latest, pass viteServer if available\n await generateConfig(viteServer);\n\n // If no config found, return empty module\n if (!cachedConfig) {\n return `export default null;`;\n }\n\n // Generate code with HMR support\n const code = `\n// Use global variable to persist callbacks and current config across HMR updates\nif (!window.__tailwindConfigCallbacks) {\n window.__tailwindConfigCallbacks = [];\n}\n\n// Always update current config with the latest from server\nlet tailwindConfigCurrent = ${JSON.stringify(cachedConfig)};\n\nif (import.meta.hot) {\n // Accept self updates\n import.meta.hot.accept((newModule) => {\n if (newModule && newModule.default) {\n // Call all update callbacks with the new config from window\n window.__tailwindConfigCallbacks.forEach((callback) => {\n try {\n // Pass the actual config object, not the Proxy\n callback(newModule.default);\n } catch (e) {\n console.error('[TailwindConfig] Callback error:', e);\n }\n });\n }\n });\n}\n\nexport function onUpdate(fn) {\n window.__tailwindConfigCallbacks.push(fn);\n return () => { \n const index = window.__tailwindConfigCallbacks.indexOf(fn);\n if (index > -1) {\n window.__tailwindConfigCallbacks.splice(index, 1);\n }\n };\n};\nexport default tailwindConfigCurrent;\n\n`;\n return code;\n }\n },\n\n configureServer(server) {\n if (!isDev) return;\n\n viteServer = server;\n\n (async () => {\n try {\n const tailwindInputFile = await findConfigFile();\n if (tailwindInputFile) {\n server.watcher.add(tailwindInputFile);\n }\n } catch {\n // Ignore errors\n }\n })();\n },\n\n async handleHotUpdate({ file, server }) {\n const tailwindInputFile = await findConfigFile();\n\n if (!tailwindInputFile || path.normalize(file) !== path.normalize(tailwindInputFile)) {\n return;\n }\n\n // Invalidate the config file in SSR module graph first\n const configMod = server.moduleGraph.getModuleById(tailwindInputFile);\n if (configMod) {\n server.moduleGraph.invalidateModule(configMod);\n }\n\n // Then regenerate config using the server's SSR loader\n await generateConfig(server);\n\n // Finally invalidate our virtual module\n const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);\n if (mod) {\n server.moduleGraph.invalidateModule(mod);\n return [mod];\n }\n\n return [];\n },\n };\n}\n","import type { Plugin } from 'vite';\n\nexport interface TaroStyleAdapterOptions {\n /**\n * Design width for responsive scaling (default: 375)\n * Should match Taro config's designWidth\n */\n designWidth?: number;\n \n /**\n * Maximum viewport width to scale (default: 750)\n * Beyond this width, font-size stays fixed\n */\n maxWidth?: number;\n\n /**\n * Base font size in pixels (default: 12)\n * Should match Taro config's baseFontSize\n */\n baseFontSize?: number;\n\n /**\n * Minimum root font size in pixels (default: 12)\n * Should match Taro config's minRootSize\n */\n minRootSize?: number;\n\n /**\n * Maximum root font size in pixels (default: 24)\n * Should match Taro config's maxRootSize\n */\n maxRootSize?: number;\n}\n\n/**\n * Taro H5 样式适配插件\n * \n * 功能:\n * 1. 动态计算根字号,使 H5 的 rem 与小程序的 rpx 行为对齐\n * 2. 隐藏 Taro 页面容器的滚动条,用于编辑器 iframe 预览\n * \n * 原理:\n * - 小程序 rpx: 1rpx = 屏幕宽度 / 750\n * - H5 rem: Taro 把 rpx 转成 rem,基于 baseFontSize\n * - 本插件动态设置 html font-size,使 rem 的实际像素值与 rpx 对齐\n * \n * 注意:此插件会覆盖 Taro 默认注入的根字号脚本,配置需与 Taro pxtransform 保持一致\n * \n * @example\n * ```ts\n * // In Taro config/dev.ts\n * import { taroStyleAdapterPlugin } from '@amaster.ai/vite-plugins'\n * \n * export default {\n * compiler: {\n * type: 'vite',\n * vitePlugins: [\n * taroStyleAdapterPlugin({ \n * designWidth: 375,\n * baseFontSize: 12,\n * minRootSize: 12,\n * maxRootSize: 24\n * })\n * ]\n * }\n * }\n * ```\n */\nexport function taroStyleAdapterPlugin(options: TaroStyleAdapterOptions = {}): Plugin {\n const { \n designWidth = 375, \n maxWidth = 750,\n baseFontSize = 12,\n minRootSize = 12,\n maxRootSize = 24\n } = options;\n \n return {\n name: 'vite-plugin-taro-style-adapter',\n apply: 'serve', // 仅在开发模式下生效\n transformIndexHtml(html) {\n // 动态根字号脚本\n // 公式:fontSize = (clientWidth / designWidth) * baseFontSize\n // 当 designWidth=375, baseFontSize=12 时:\n // - 375px 屏幕 → 12px (1rem = 12px)\n // - 750px 屏幕 → 24px (1rem = 24px)\n // 这样 rem 值在不同屏幕宽度下的视觉比例与小程序 rpx 一致\n const flexibleScript = `\n<script data-taro-flexible=\"true\">\n(function() {\n var designWidth = ${designWidth};\n var maxWidth = ${maxWidth};\n var baseFontSize = ${baseFontSize};\n var minRootSize = ${minRootSize};\n var maxRootSize = ${maxRootSize};\n \n function setRootFontSize() {\n var docEl = document.documentElement;\n var clientWidth = docEl.clientWidth;\n \n // 限制最大宽度\n if (clientWidth > maxWidth) {\n clientWidth = maxWidth;\n }\n \n // 计算根字号: (屏幕宽度 / 设计稿宽度) * 基准字号\n var fontSize = (clientWidth / designWidth) * baseFontSize;\n \n // 应用最小/最大限制\n if (fontSize < minRootSize) {\n fontSize = minRootSize;\n } else if (fontSize > maxRootSize) {\n fontSize = maxRootSize;\n }\n \n docEl.style.fontSize = fontSize + 'px';\n }\n \n setRootFontSize();\n \n // 监听窗口变化\n window.addEventListener('resize', setRootFontSize);\n window.addEventListener('orientationchange', setRootFontSize);\n \n // 页面显示时重新计算(解决某些浏览器的 bug)\n document.addEventListener('DOMContentLoaded', setRootFontSize);\n})();\n</script>\n`;\n\n // 滚动条隐藏样式 + Taro Image 组件修复\n const styles = `\n<style data-taro-adapter=\"true\">\n /* 仅 H5 生效:隐藏 Taro 页面容器滚动条,但仍可滚动 */\n .taro_page {\n -ms-overflow-style: none; /* IE/Edge 老版 */\n scrollbar-width: none; /* Firefox */\n }\n\n .taro_page::-webkit-scrollbar {\n width: 0;\n height: 0;\n display: none; /* Chrome/Safari */\n }\n\n /* 隐藏 Taro ScrollView 组件的滚动条 */\n .taro-scroll-view__scroll-y,\n .taro-scroll-view__scroll-x {\n -ms-overflow-style: none; /* IE/Edge 老版 */\n scrollbar-width: none; /* Firefox */\n }\n\n .taro-scroll-view__scroll-y::-webkit-scrollbar,\n .taro-scroll-view__scroll-x::-webkit-scrollbar {\n width: 0;\n height: 0;\n display: none; /* Chrome/Safari */\n }\n\n /*\n * 修复 Taro Image 组件在 H5 下的尺寸问题\n * \n * 问题:Taro Image 组件使用 aspectFit 模式时,内部 img 使用 max-width/max-height: 100%\n * 导致小尺寸图片(如 SVG 图标)无法按指定尺寸显示,只显示原始尺寸\n * \n * 解决:让 img 填满 taro-image-core 容器,由容器控制尺寸\n */\n taro-image-core img.taro-img__mode-aspectfit {\n width: 100%;\n height: 100%;\n max-width: none;\n max-height: none;\n position: static;\n transform: none;\n object-fit: contain;\n }\n</style>\n`;\n \n // 在 </head> 之前插入脚本和样式\n return html.replace('</head>', `${flexibleScript}${styles}</head>`);\n }\n };\n}\n","/**\n * PostCSS 插件:H5 模式下将 rpx 预转换为 px\n *\n * 问题背景:\n * - Taro 的 pxtransform 在 H5 模式下会处理 rpx,但它把 rpx 值直接除以 rootValue\n * - 导致 96rpx 被转成 8rem(96/12),实际显示为 96px\n * - 而正确应该是:96rpx = 48px = 4rem = 48px\n *\n * 解决方案:\n * - 在 pxtransform 之前,先把 rpx 转成 px(rpx / 2)\n * - 然后 pxtransform 会正确地把 px 转成 rem(px / 12)\n *\n * 转换链路:96rpx → 48px → 4rem → 48px(正确)\n * \n * @example\n * ```ts\n * // In Taro config/index.ts\n * import { rpx2pxPlugin } from '@amaster.ai/vite-plugins'\n * \n * // 在 postcss-config-loader-plugin 中使用\n * {\n * name: 'postcss-config-loader-plugin',\n * config(config) {\n * if (typeof config.css?.postcss === 'object') {\n * config.css?.postcss.plugins?.unshift(tailwindcss())\n * // H5 模式下添加 rpx2px 插件\n * if (process.env.TARO_ENV === 'h5') {\n * config.css?.postcss.plugins?.unshift(rpx2pxPlugin())\n * }\n * }\n * }\n * }\n * ```\n */\n\nexport interface Rpx2pxPluginOptions {\n /**\n * rpx 到 px 的转换比例(默认 2)\n * 即 1rpx = 1/ratio px\n * 默认值 2 表示 2rpx = 1px(基于 375 设计稿)\n */\n ratio?: number;\n}\n\ninterface PostCSSDeclaration {\n value: string;\n}\n\ninterface PostCSSPlugin {\n postcssPlugin: string;\n Declaration: (decl: PostCSSDeclaration) => void;\n}\n\ntype PostCSSPluginCreator = {\n (): PostCSSPlugin;\n postcss: boolean;\n};\n\nexport function rpx2pxPlugin(options: Rpx2pxPluginOptions = {}): PostCSSPlugin {\n const { ratio = 2 } = options;\n \n return {\n postcssPlugin: 'postcss-rpx2px',\n Declaration(decl: PostCSSDeclaration) {\n if (decl.value?.includes('rpx')) {\n decl.value = decl.value.replace(/(-?\\d*\\.?\\d+)rpx/gi, (_match: string, num: string) => {\n const pxValue = parseFloat(num) / ratio;\n return pxValue === 0 ? '0' : `${pxValue}px`;\n });\n }\n }\n };\n}\n\n// PostCSS 插件标识\n(rpx2pxPlugin as PostCSSPluginCreator).postcss = true;\n","/**\n * Taro Environment Variables Injection Helper\n * \n * Automatically injects environment variables into Taro's defineConstants\n * so that they will be replaced at build time.\n * \n * @example\n * ```ts\n * // In Taro config/index.ts\n * import { injectTaroEnv } from '@amaster.ai/vite-plugins/taro-env-inject'\n * \n * export default defineConfig({\n * defineConstants: {\n * ...injectTaroEnv()\n * }\n * })\n * ```\n */\n\nexport interface TaroEnvInjectOptions {\n /**\n * Additional environment variable names to inject\n * @default []\n */\n additional?: string[];\n \n /**\n * Whether to inject all TARO_APP_* prefixed variables\n * @default true\n */\n autoInjectTaroApp?: boolean;\n \n /**\n * Whether to inject all VITE_* prefixed variables\n * @default true\n */\n autoInjectVite?: boolean;\n}\n\n/**\n * Inject environment variables into Taro's defineConstants\n * \n * This function reads environment variables and formats them for Taro's defineConstants.\n * Taro will replace these at build time, converting `process.env.XXX` to actual values.\n */\nexport function injectTaroEnv(options: TaroEnvInjectOptions = {}): Record<string, string> {\n const {\n additional = [],\n autoInjectTaroApp = true,\n autoInjectVite = true,\n } = options;\n\n const constants: Record<string, string> = {};\n\n // Collect variable names to inject\n const varsToInject = new Set<string>(additional);\n\n // Auto-detect TARO_APP_* variables\n if (autoInjectTaroApp) {\n Object.keys(process.env).forEach(key => {\n if (key.startsWith('TARO_APP_')) {\n varsToInject.add(key);\n }\n });\n }\n\n // Auto-detect VITE_* variables\n if (autoInjectVite) {\n Object.keys(process.env).forEach(key => {\n if (key.startsWith('VITE_')) {\n varsToInject.add(key);\n }\n });\n }\n\n // Inject variables into defineConstants format\n varsToInject.forEach(varName => {\n const value = process.env[varName] || '';\n constants[`process.env.${varName}`] = JSON.stringify(value);\n });\n\n return constants;\n}\n\n/**\n * Inject specific environment variables for amaster.ai mini-program builds\n * \n * This is a convenience function that injects the standard environment variables\n * used by @amaster.ai/http-client for API base URL configuration.\n */\nexport function injectAmasterEnv(): Record<string, string> {\n return {\n 'process.env.TARO_APP_API_BASE_URL': JSON.stringify(process.env.TARO_APP_API_BASE_URL || ''),\n 'process.env.VITE_API_BASE_URL': JSON.stringify(process.env.VITE_API_BASE_URL || ''),\n };\n}\n","import { editorBridgePlugin } from \"./editor-bridge\";\nimport { routesExposePlugin } from \"./routes-expose\";\nimport { browserLogsPlugin } from \"./browser-logs\";\nimport { jsxSourceTaggerPlugin } from \"./tagger\";\nimport { tailwindConfigSyncPlugin } from \"./tailwind-config-sync\";\n// import { smartReloadPlugin } from \"./smart-reload\"; // 智能重载功能开发中,暂不启用\nimport { taroStyleAdapterPlugin, type TaroStyleAdapterOptions } from \"./taro-style-adapter\";\nimport { rpx2pxPlugin } from \"./postcss-rpx2px\";\nimport process from \"node:process\";\nimport type { Plugin } from \"vite\";\n\nexport interface DevToolsOptions {\n /**\n * 是否为 Taro 项目\n * - true: 启用 Taro 相关插件(taroStyleAdapterPlugin、rpx2pxPlugin)\n * - false: 禁用 Taro 相关插件\n * - undefined: 自动检测(通过 process.env.TARO_ENV 判断,默认为 false)\n */\n isTaro?: boolean;\n\n /**\n * Taro style adapter options\n * Controls H5 responsive scaling to match mini-program rpx behavior\n * 仅在 isTaro 为 true 时生效\n */\n styleAdapter?: TaroStyleAdapterOptions;\n\n /**\n * 是否启用 JSX Source Tagger(通过 Symbol 标记元素源码位置)\n * 默认:开发模式启用\n */\n jsxSourceTagger?: boolean;\n\n /**\n * 是否启用 Tailwind Config 同步(生成 JSON 文件)\n * 默认:开发模式启用\n */\n tailwindConfigSync?: boolean;\n\n /**\n * Tailwind 配置文件路径\n * 默认:./tailwind.config.ts\n */\n tailwindConfigPath?: string;\n}\n\n/**\n * 开发工具插件集合,简化调用,vite.config.ts 直接 devTools() 即可\n *\n * @param options 配置项\n * @param options.isTaro 是否为 Taro 项目(默认根据 TARO_ENV 自动判断)\n * @param options.styleAdapter Taro H5 样式适配配置,designWidth 应与 Taro config 一致\n * @returns Plugin[] Vite 插件数组\n *\n * @example\n * ```ts\n * // Taro 项目 - config/dev.ts\n * import devTools from \"@amaster.ai/vite-plugins\";\n *\n * export default {\n * compiler: {\n * type: 'vite',\n * vitePlugins: [devTools({ isTaro: true })]\n * }\n * }\n * ```\n *\n * @example\n * ```ts\n * // React 项目 - vite.config.ts\n * import devTools from \"@amaster.ai/vite-plugins\";\n *\n * export default {\n * plugins: [devTools()] // isTaro 默认为 false\n * }\n * ```\n */\nexport default function devTools(options: DevToolsOptions = {}): Plugin[] {\n // 判断是否为 Taro 项目\n // 优先使用用户显式配置,否则通过环境变量判断\n const isTaro = options.isTaro ?? process.env.TARO_ENV === \"h5\";\n\n const plugins: Plugin[] = [\n // componentIdPlugin(), // 暂不启用\n editorBridgePlugin(),\n routesExposePlugin(),\n // smartReloadPlugin() // 智能重载:拦截 full-reload,静默等待重连\n ];\n\n // JSX Source Tagger - 默认开发模式启用\n if (options.jsxSourceTagger !== false) {\n plugins.push(jsxSourceTaggerPlugin());\n }\n\n // Tailwind Config Sync - 默认开发模式启用\n if (options.tailwindConfigSync !== false) {\n plugins.push(\n tailwindConfigSyncPlugin({\n configPath: options.tailwindConfigPath,\n })\n );\n }\n\n // 仅在 Taro 项目中添加 Taro 相关插件\n if (isTaro) {\n // Taro H5 样式适配(运行时)\n plugins.unshift(taroStyleAdapterPlugin(options.styleAdapter));\n\n // H5 开发模式下添加 rpx2px PostCSS 插件(编译时)\n plugins.unshift({\n name: \"dev-postcss-rpx2px-plugin\",\n apply: \"serve\",\n config(config) {\n if (typeof config.css?.postcss === \"object\") {\n // 在最前面插入,确保在 pxtransform 之前执行\n config.css?.postcss.plugins?.unshift(rpx2pxPlugin());\n }\n },\n });\n }\n\n // process.env.WORKSPACE_GIT_REPO 有这个表示是在 sandbox 里面运行,启用浏览器日志插件\n if (process.env.WORKSPACE_GIT_REPO) {\n plugins.push(browserLogsPlugin());\n }\n\n return plugins;\n}\n\nexport {\n editorBridgePlugin,\n routesExposePlugin,\n // smartReloadPlugin\n};\n\n// Export Taro environment injection helpers\nexport { injectTaroEnv, injectAmasterEnv } from \"./taro-env-inject\";\n\n// Export Taro style adapter plugin and its types\nexport { taroStyleAdapterPlugin, type TaroStyleAdapterOptions } from \"./taro-style-adapter\";\n\n// Export PostCSS rpx2px plugin for H5 mode\nexport { rpx2pxPlugin, type Rpx2pxPluginOptions } from \"./postcss-rpx2px\";\n\n// Export tagger and tailwind config sync plugins\nexport { jsxSourceTaggerPlugin } from \"./tagger\";\nexport { tailwindConfigSyncPlugin } from \"./tailwind-config-sync\";\n"]}
1
+ {"version":3,"sources":["../src/editor-bridge.ts","../src/routes-expose.ts","../src/browser-logs.ts","../src/tagger.ts","../src/tailwind-config-sync.ts","../src/taro-style-adapter.ts","../src/postcss-rpx2px.ts","../src/taro-env-inject.ts","../src/index.ts"],"names":["__filename","fileURLToPath","__dirname","dirname","VIRTUAL_MODULE_ID","RESOLVED_VIRTUAL_MODULE_ID","bridgeModuleContent","loadBridgeModule","bridgeModulePath","resolve","readFileSync","err","getBridgeScriptContent","getVirtualModuleContent","sessionKey","editorBridgePlugin","isDev","config","id","html","bridgeScript","routesExposePlugin","options","routesPath","code","browserLogsPlugin","logFilePath","injectedScript","workspaceDir","process","path","dir","fs","devServer","req","res","next","origin","body","chunk","logDir","error","devRuntimeCode","jsxSourceTaggerPlugin","projectRoot","importer","tailwindConfigSyncPlugin","cachedConfig","viteServer","configPath","findConfigFile","configFile","jsConfig","tsConfig","generateConfig","server","tailwindInputFile","configModule","userConfig","resolvedConfig","file","configMod","mod","taroStyleAdapterPlugin","designWidth","maxWidth","baseFontSize","minRootSize","maxRootSize","flexibleScript","rpx2pxPlugin","ratio","decl","_match","num","pxValue","injectTaroEnv","additional","autoInjectTaroApp","autoInjectVite","constants","varsToInject","key","varName","value","injectAmasterEnv","devTools","isTaro","plugins"],"mappings":"+fAKA,IAAMA,CAAAA,CAAaC,kBAAc,2PAAe,CAAA,CAC1CC,CAAAA,CAAYC,UAAQH,CAAU,CAAA,CAE9BI,CAAAA,CAAoB,yBAAA,CACpBC,EAA6B,IAAA,CAAOD,CAAAA,CAGtCE,CAAAA,CAAqC,IAAA,CAEzC,SAASC,CAAAA,EAA2B,CAClC,GAAID,CAAAA,CAAqB,OAAOA,EAEhC,GAAI,CACF,IAAME,CAAAA,CAAmBC,UAAQP,CAAAA,CAAW,iCAAiC,CAAA,CAC7E,OAAAI,EAAsBI,cAAAA,CAAaF,CAAAA,CAAkB,OAAO,CAAA,CACrDF,CACT,CAAA,MAASK,CAAAA,CAAK,CACZ,OAAA,OAAA,CAAQ,IAAA,CAAK,0DAA2DA,CAAG,CAAA,CACpE,EACT,CACF,CAKA,SAASC,CAAAA,EAAyB,CAChC,OAAO,oEACT,CAKA,SAASC,CAAAA,CAAwBC,CAAAA,CAAoB,CAMnD,OALqBP,CAAAA,GAGW,OAAA,CAAQ,kBAAA,CAAoBO,CAAU,CAAA,CAElD;AAAA,kBAAA,CACtB,CAOO,SAASC,CAAAA,EAA6B,CAC3C,I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AA,EAEjCA,CAAAA,CAAO,KAAK,OAAA,CAAQ,OAAA,EAAS,OAAA,CAAQqD,CAAAA,EAAc,EAEvD,CACF,CAAC,CAAA,CAAA,CAICzC,kBAAAA,CAAQ,GAAA,CAAI,kBAAA,EACd2D,CAAAA,CAAQ,IAAA,CAAK/D,CAAAA,EAAmB,EAG3B+D,CACT","file":"index.cjs","sourcesContent":["import type { Plugin } from \"vite\";\nimport { readFileSync } from \"fs\";\nimport { resolve, dirname } from \"path\";\nimport { fileURLToPath } from \"url\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\nconst VIRTUAL_MODULE_ID = \"@amaster/bridge-monitor\";\nconst RESOLVED_VIRTUAL_MODULE_ID = \"\\0\" + VIRTUAL_MODULE_ID;\n\n// Load pre-built bridge module at plugin initialization\nlet bridgeModuleContent: string | null = null;\n\nfunction loadBridgeModule(): string {\n if (bridgeModuleContent) return bridgeModuleContent;\n\n try {\n const bridgeModulePath = resolve(__dirname, \"../dist/bridge-module.global.js\");\n bridgeModuleContent = readFileSync(bridgeModulePath, \"utf-8\");\n return bridgeModuleContent;\n } catch (err) {\n console.warn(\"[editor-bridge] Failed to load pre-built bridge module:\", err);\n return \"\";\n }\n}\n\n/**\n * Generate bridge script content with environment variables\n */\nfunction getBridgeScriptContent() {\n return `<script type=\"module\" src=\"/@id/@amaster/bridge-monitor\"></script>`;\n}\n\n/**\n * Generate virtual module content for HMR and Tailwind config monitoring\n */\nfunction getVirtualModuleContent(sessionKey: string) {\n const bridgeModule = loadBridgeModule();\n\n // Replace __SESSION_KEY__ macro with actual session key\n const moduleCode = bridgeModule.replace(/__SESSION_KEY__/g, sessionKey);\n\n return moduleCode + \"\\nexport default {};\";\n}\n\n/**\n * Vite plugin: Inject editor bridge script\n * Injects minimal bridge that loads external script from platform\n * Also provides virtual module for HMR and Tailwind config monitoring\n */\nexport function editorBridgePlugin(): Plugin {\n let isDev = false;\n\n return {\n name: \"vite-plugin-editor-bridge\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n },\n\n resolveId(id) {\n if (id === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_MODULE_ID) {\n // Virtual module is now inlined in HTML, but keep this for potential future use\n const sessionKey = process.env.VITE_AMASTER_KEY || \"\";\n return getVirtualModuleContent(sessionKey);\n }\n },\n\n transformIndexHtml(html) {\n if (!isDev) return html;\n\n const bridgeScript = getBridgeScriptContent();\n return html.replace(\"</body>\", `${bridgeScript}</body>`);\n },\n };\n}\n","import type { Plugin } from \"vite\";\n\n/**\n * Vite plugin: Expose routes to window.__APP_ROUTES__\n * Only enabled in development mode\n */\nexport function routesExposePlugin(options?: { routesFilePath?: string }): Plugin {\n let isDev = false;\n const routesPath = options?.routesFilePath || \"src/routes.tsx\";\n\n return {\n name: \"vite-plugin-routes-expose\",\n enforce: \"post\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n },\n\n transform(code: string, id: string) {\n if (!isDev) {\n return null;\n }\n\n if (!id.endsWith(routesPath)) {\n return null;\n }\n\n try {\n if (code.includes(\"window.__APP_ROUTES__\")) {\n return null;\n }\n\n const transformedCode = `${code}\n\n// Development mode: Expose routes to window.__APP_ROUTES__\nif (typeof window !== 'undefined') {\n window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];\n}\n`;\n\n return {\n code: transformedCode,\n map: null,\n };\n } catch {\n return null;\n }\n },\n };\n}\n","import type { Plugin } from \"vite\";\nimport { Buffer } from \"node:buffer\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\n\n/**\n * Browser logs collection plugin\n * Injects script into HTML head to collect console logs and network requests\n * Logs are written directly to browser.log file (same level as index.html)\n */\nexport function browserLogsPlugin(): Plugin {\n let logFilePath = \"\";\n\n // Script to inject into browser\n const injectedScript = `\n<script>\n(function() {\n 'use strict';\n \n // Log API path (provided by Vite dev server)\n var LOG_API_PATH = '/__browser__';\n \n // Save original fetch before any interception, used exclusively for log writing\n var __originalFetch__ = window.fetch.bind(window);\n \n // Write queue to ensure sequential writes\n var writeQueue = [];\n var isWriting = false;\n \n // Process write queue to ensure sequential writes\n function processWriteQueue() {\n if (isWriting || writeQueue.length === 0) return;\n \n isWriting = true;\n var entry = writeQueue.shift();\n var logText = JSON.stringify(entry);\n \n __originalFetch__(LOG_API_PATH, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: logText\n })\n .then(function(response) {\n isWriting = false;\n if (!response.ok) {\n console.warn('[BrowserLogs] Failed to write log:', response.status);\n }\n // Continue processing next item in queue\n processWriteQueue();\n })\n .catch(function(error) {\n console.warn('[BrowserLogs] Failed to write log:', error.message);\n // On failure, put log back to queue head for retry\n writeQueue.unshift(entry);\n isWriting = false;\n // Retry after delay\n setTimeout(processWriteQueue, 1000);\n });\n }\n \n // Limit headers object size\n function truncateHeaders(headers) {\n if (!headers) return headers;\n var jsonStr = JSON.stringify(headers);\n if (jsonStr.length <= MAX_HEADER_SIZE) return headers;\n return '[Headers truncated, size: ' + jsonStr.length + ']';\n }\n \n // Truncate oversized log entries\n function truncateLogEntry(entry) {\n var jsonStr = JSON.stringify(entry);\n if (jsonStr.length <= MAX_LOG_ENTRY_SIZE) {\n return entry;\n }\n \n // If oversized, progressively truncate non-critical fields\n var truncated = Object.assign({}, entry);\n \n // 1. Truncate response body first\n if (truncated.responseBody && typeof truncated.responseBody === 'string') {\n truncated.responseBody = truncated.responseBody.substring(0, 500) + '... [truncated]';\n }\n \n // 2. Truncate request body\n if (truncated.requestBody && typeof truncated.requestBody === 'string') {\n truncated.requestBody = truncated.requestBody.substring(0, 500) + '... [truncated]';\n }\n \n // 3. Truncate message\n if (truncated.message && typeof truncated.message === 'string' && truncated.message.length > 1000) {\n truncated.message = truncated.message.substring(0, 1000) + '... [truncated]';\n }\n \n // 4. Truncate stack\n if (truncated.stack && Array.isArray(truncated.stack) && truncated.stack.length > 3) {\n truncated.stack = truncated.stack.slice(0, 3);\n }\n \n // Add truncation marker\n truncated._truncated = true;\n truncated._originalSize = jsonStr.length;\n \n return truncated;\n }\n \n // Add log and send immediately (ensure order)\n function addLog(entry) {\n var truncatedEntry = truncateLogEntry(entry);\n writeQueue.push(truncatedEntry);\n processWriteQueue();\n }\n \n // ============================================\n // Console log collection\n // ============================================\n var originalConsole = {\n log: console.log,\n info: console.info,\n warn: console.warn,\n error: console.error,\n debug: console.debug\n };\n \n function getStackTrace() {\n var stack = new Error().stack || '';\n var lines = stack.split('\\\\n').slice(3);\n // Limit stack lines\n return lines.slice(0, MAX_STACK_LINES).map(function(line) { return line.trim(); });\n }\n \n function formatMessage(args) {\n return Array.from(args).map(function(arg) {\n if (arg === null) return 'null';\n if (arg === undefined) return 'undefined';\n if (typeof arg === 'object') {\n try {\n return JSON.stringify(arg);\n } catch (e) {\n return String(arg);\n }\n }\n return String(arg);\n }).join(' ');\n }\n \n function createLogEntry(level, args) {\n return {\n type: 'console',\n timestamp: new Date().toISOString(),\n level: level,\n message: formatMessage(args),\n stack: getStackTrace()\n };\n }\n \n // Keywords to filter from console log collection\n var FILTERED_CONSOLE_KEYWORDS = ['[vite]', '[BrowserLogs]'];\n \n // Check if message should be filtered\n function shouldFilterConsoleLog(args) {\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n if (typeof arg === 'string') {\n for (var j = 0; j < FILTERED_CONSOLE_KEYWORDS.length; j++) {\n if (arg.indexOf(FILTERED_CONSOLE_KEYWORDS[j]) !== -1) {\n return true;\n }\n }\n }\n }\n return false;\n }\n \n function wrapConsoleMethod(method, level) {\n return function() {\n var args = arguments;\n // Filter out logs containing [vite]\n if (shouldFilterConsoleLog(args)) {\n return originalConsole[method].apply(console, args);\n }\n var entry = createLogEntry(level, args);\n addLog(entry);\n return originalConsole[method].apply(console, args);\n };\n }\n \n console.log = wrapConsoleMethod('log', 'log');\n console.info = wrapConsoleMethod('info', 'info');\n console.warn = wrapConsoleMethod('warn', 'warn');\n console.error = wrapConsoleMethod('error', 'error');\n console.debug = wrapConsoleMethod('debug', 'debug');\n \n // ============================================\n // Network request collection (exclude SSE and log API requests)\n // ============================================\n \n var MAX_BODY_SIZE = 2000;\n var MAX_LOG_ENTRY_SIZE = 3000; // Max single log entry length\n var MAX_HEADER_SIZE = 500; // Max single header object length\n var MAX_STACK_LINES = 5; // Max stack lines to keep\n const FILTERED_URLS = ['/__browser__', '/builtin']; // Filter out log API and Vite built-in requests\n \n function isSSERequest(url, headers) {\n var sseUrlPatterns = ['/events', '/sse', '/stream', 'text/event-stream'];\n var urlStr = String(url).toLowerCase();\n for (var i = 0; i < sseUrlPatterns.length; i++) {\n if (urlStr.indexOf(sseUrlPatterns[i]) !== -1) {\n return true;\n }\n }\n \n if (headers) {\n if (typeof headers.get === 'function') {\n var accept = headers.get('Accept') || headers.get('accept');\n if (accept && accept.indexOf('text/event-stream') !== -1) {\n return true;\n }\n } else if (typeof headers === 'object') {\n for (var key in headers) {\n if (key.toLowerCase() === 'accept' && headers[key].indexOf('text/event-stream') !== -1) {\n return true;\n }\n }\n }\n }\n \n return false;\n }\n \n function shouldFilterRequest(url) {\n return FILTERED_URLS.some(function(filteredUrl) {\n return String(url).indexOf(filteredUrl) !== -1;\n });\n }\n \n function formatRequestBody(body) {\n if (!body) return null;\n \n try {\n if (typeof body === 'string') {\n return body.substring(0, MAX_BODY_SIZE);\n }\n if (body instanceof FormData) {\n var formDataObj = {};\n body.forEach(function(value, key) {\n if (value instanceof File) {\n formDataObj[key] = '[File: ' + value.name + ', size: ' + value.size + ']';\n } else {\n formDataObj[key] = String(value).substring(0, 1000);\n }\n });\n return JSON.stringify(formDataObj);\n }\n if (body instanceof Blob) {\n return '[Blob: size=' + body.size + ', type=' + body.type + ']';\n }\n if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {\n return '[Binary: size=' + body.byteLength + ']';\n }\n if (body instanceof URLSearchParams) {\n return body.toString().substring(0, MAX_BODY_SIZE);\n }\n return String(body).substring(0, MAX_BODY_SIZE);\n } catch (e) {\n return '[Error reading body: ' + e.message + ']';\n }\n }\n \n function formatResponseBody(response, responseType) {\n if (!response) return null;\n \n try {\n if (responseType === '' || responseType === 'text') {\n return String(response).substring(0, MAX_BODY_SIZE);\n }\n if (responseType === 'json') {\n return JSON.stringify(response).substring(0, MAX_BODY_SIZE);\n }\n if (responseType === 'document') {\n return '[Document]';\n }\n if (responseType === 'blob') {\n return '[Blob: size=' + response.size + ']';\n }\n if (responseType === 'arraybuffer') {\n return '[ArrayBuffer: size=' + response.byteLength + ']';\n }\n return String(response).substring(0, MAX_BODY_SIZE);\n } catch (e) {\n return '[Error reading response: ' + e.message + ']';\n }\n }\n \n // Intercept XMLHttpRequest\n var originalXHROpen = XMLHttpRequest.prototype.open;\n var originalXHRSend = XMLHttpRequest.prototype.send;\n var originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;\n \n XMLHttpRequest.prototype.open = function(method, url, async, user, password) {\n this.__requestInfo__ = {\n method: method,\n url: url,\n startTime: null,\n headers: {}\n };\n return originalXHROpen.apply(this, arguments);\n };\n \n XMLHttpRequest.prototype.setRequestHeader = function(name, value) {\n if (this.__requestInfo__ && this.__requestInfo__.headers) {\n this.__requestInfo__.headers[name] = value;\n }\n return originalXHRSetRequestHeader.apply(this, arguments);\n };\n \n XMLHttpRequest.prototype.send = function(body) {\n var xhr = this;\n var requestInfo = xhr.__requestInfo__;\n \n if (requestInfo) {\n // Skip SSE requests and filtered requests\n if (isSSERequest(requestInfo.url, requestInfo.headers) || shouldFilterRequest(requestInfo.url)) {\n return originalXHRSend.apply(this, arguments);\n }\n \n requestInfo.startTime = Date.now();\n requestInfo.requestBody = formatRequestBody(body);\n \n xhr.addEventListener('loadend', function() {\n var contentType = xhr.getResponseHeader('Content-Type') || '';\n if (contentType.indexOf('text/event-stream') !== -1) {\n return;\n }\n \n var responseHeaders = {};\n var allHeaders = xhr.getAllResponseHeaders();\n if (allHeaders) {\n allHeaders.split('\\\\r\\\\n').forEach(function(line) {\n var parts = line.split(': ');\n if (parts.length === 2) {\n responseHeaders[parts[0]] = parts[1];\n }\n });\n }\n \n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'xhr',\n method: requestInfo.method,\n url: requestInfo.url,\n status: xhr.status,\n statusText: xhr.statusText,\n duration: Date.now() - requestInfo.startTime,\n requestHeaders: truncateHeaders(requestInfo.headers),\n requestBody: requestInfo.requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseType: xhr.responseType,\n responseBody: formatResponseBody(xhr.response, xhr.responseType),\n responseSize: xhr.response ? (typeof xhr.response === 'string' ? xhr.response.length : (xhr.response.byteLength || xhr.response.size || null)) : null\n };\n \n addLog(entry);\n });\n }\n \n return originalXHRSend.apply(this, arguments);\n };\n \n // Intercept Fetch API\n var originalFetch = window.fetch;\n \n function headersToObject(headers) {\n var obj = {};\n if (!headers) return obj;\n \n if (typeof headers.forEach === 'function') {\n headers.forEach(function(value, key) {\n obj[key] = value;\n });\n } else if (typeof headers === 'object') {\n for (var key in headers) {\n obj[key] = headers[key];\n }\n }\n return obj;\n }\n \n window.fetch = function(input, init) {\n var startTime = Date.now();\n var method = (init && init.method) || 'GET';\n var url = typeof input === 'string' ? input : input.url;\n var headers = init && init.headers;\n \n // Skip SSE requests and filtered requests\n if (isSSERequest(url, headers) || shouldFilterRequest(url)) {\n return originalFetch.apply(this, arguments);\n }\n \n var requestHeaders = headersToObject(headers);\n var requestBody = formatRequestBody(init && init.body);\n \n return originalFetch.apply(this, arguments)\n .then(function(response) {\n var contentType = response.headers.get('Content-Type') || '';\n if (contentType.indexOf('text/event-stream') !== -1) {\n return response;\n }\n \n var clonedResponse = response.clone();\n var responseHeaders = headersToObject(response.headers);\n \n clonedResponse.text().then(function(bodyText) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: response.status,\n statusText: response.statusText,\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseBody: bodyText ? bodyText.substring(0, MAX_BODY_SIZE) : null,\n responseSize: bodyText ? bodyText.length : null,\n ok: response.ok\n };\n \n addLog(entry);\n }).catch(function(e) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: response.status,\n statusText: response.statusText,\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseBody: '[Unable to read: ' + e.message + ']',\n responseSize: null,\n ok: response.ok\n };\n \n addLog(entry);\n });\n \n return response;\n })\n .catch(function(error) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: 0,\n statusText: 'Network Error',\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: null,\n responseBody: null,\n error: error.message\n };\n \n addLog(entry);\n throw error;\n });\n };\n \n // ============================================\n // Global error capture\n // ============================================\n window.addEventListener('error', function(event) {\n var entry = {\n type: 'error',\n timestamp: new Date().toISOString(),\n level: 'error',\n message: event.message,\n stack: event.error ? event.error.stack : 'at ' + event.filename + ':' + event.lineno + ':' + event.colno\n };\n addLog(entry);\n });\n \n // ============================================\n // Vite deps 504 error capture using PerformanceObserver\n // Only captures 504 errors for node_modules/.vite resources (pre-bundled dependencies)\n // ============================================\n var reportedUrls = {}; // Track reported URLs to avoid duplicates\n \n if (typeof PerformanceObserver !== 'undefined') {\n var perfObserver = new PerformanceObserver(function(list) {\n var entries = list.getEntries();\n for (var i = 0; i < entries.length; i++) {\n var perfEntry = entries[i];\n // Only check script resources\n if (perfEntry.initiatorType !== 'script') {\n continue;\n }\n \n var resourceUrl = perfEntry.name || '';\n // Only report errors for node_modules/.vite resources\n if (resourceUrl.indexOf('node_modules/.vite') === -1 && resourceUrl.indexOf('/node_modules/.vite') === -1) {\n continue;\n }\n \n // Check if response status is 504 (Gateway Timeout)\n // responseStatus is available in Resource Timing Level 2\n var status = perfEntry.responseStatus;\n if (status === 504) {\n // Avoid duplicate reports\n if (reportedUrls[resourceUrl]) {\n continue;\n }\n reportedUrls[resourceUrl] = true;\n \n var entry = {\n type: 'vite-deps-error',\n timestamp: new Date().toISOString(),\n level: 'error',\n url: resourceUrl,\n status: 504,\n message: 'Vite pre-bundled dependency returned 504 Gateway Timeout: ' + resourceUrl,\n duration: perfEntry.duration,\n transferSize: perfEntry.transferSize\n };\n addLog(entry);\n }\n }\n });\n \n try {\n perfObserver.observe({ type: 'resource', buffered: true });\n } catch (e) {\n // Fallback for browsers that don't support the options\n try {\n perfObserver.observe({ entryTypes: ['resource'] });\n } catch (e2) {\n originalConsole.warn('[BrowserLogs] PerformanceObserver not supported:', e2.message);\n }\n }\n }\n \n // ============================================\n // Script load error capture (for 504 and other network errors)\n // This captures errors that PerformanceObserver might miss\n // ============================================\n \n // Use MutationObserver to watch for dynamically added script tags\n function attachScriptErrorHandler(script) {\n if (script.__errorHandlerAttached__) return;\n script.__errorHandlerAttached__ = true;\n \n script.addEventListener('error', function(event) {\n var src = script.src || '';\n \n // Only report errors for node_modules/.vite resources\n if (src.indexOf('node_modules/.vite') === -1 && src.indexOf('/node_modules/.vite') === -1) {\n return;\n }\n \n // Avoid duplicate reports\n if (reportedUrls[src]) {\n return;\n }\n reportedUrls[src] = true;\n \n var entry = {\n type: 'vite-deps-error',\n timestamp: new Date().toISOString(),\n level: 'error',\n url: src,\n status: 'load-error',\n message: 'Vite pre-bundled dependency failed to load (possibly 504 Gateway Timeout): ' + src,\n errorType: event.type\n };\n addLog(entry);\n });\n }\n \n // Attach error handlers to existing scripts\n var existingScripts = document.querySelectorAll('script[src]');\n for (var i = 0; i < existingScripts.length; i++) {\n attachScriptErrorHandler(existingScripts[i]);\n }\n \n // Watch for dynamically added scripts\n if (typeof MutationObserver !== 'undefined') {\n var scriptObserver = new MutationObserver(function(mutations) {\n for (var i = 0; i < mutations.length; i++) {\n var mutation = mutations[i];\n for (var j = 0; j < mutation.addedNodes.length; j++) {\n var node = mutation.addedNodes[j];\n if (node.nodeName === 'SCRIPT' && node.src) {\n attachScriptErrorHandler(node);\n }\n // Also check child nodes\n if (node.querySelectorAll) {\n var scripts = node.querySelectorAll('script[src]');\n for (var k = 0; k < scripts.length; k++) {\n attachScriptErrorHandler(scripts[k]);\n }\n }\n }\n }\n });\n \n scriptObserver.observe(document.documentElement, {\n childList: true,\n subtree: true\n });\n }\n \n // Also intercept document.createElement to catch scripts before they're added to DOM\n var originalCreateElement = document.createElement.bind(document);\n document.createElement = function(tagName) {\n var element = originalCreateElement(tagName);\n if (tagName.toLowerCase() === 'script') {\n // Use a setter to catch when src is set\n var originalSrc = '';\n Object.defineProperty(element, '__originalSrc__', {\n get: function() { return originalSrc; },\n set: function(val) { originalSrc = val; }\n });\n \n // Defer attaching error handler until src is set\n var srcDescriptor = Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src');\n if (srcDescriptor && srcDescriptor.set) {\n var originalSrcSetter = srcDescriptor.set;\n Object.defineProperty(element, 'src', {\n get: function() {\n return srcDescriptor.get ? srcDescriptor.get.call(this) : this.getAttribute('src');\n },\n set: function(value) {\n if (originalSrcSetter) {\n originalSrcSetter.call(this, value);\n } else {\n this.setAttribute('src', value);\n }\n attachScriptErrorHandler(this);\n },\n configurable: true\n });\n }\n }\n return element;\n };\n \n window.addEventListener('unhandledrejection', function(event) {\n var entry = {\n type: 'error',\n timestamp: new Date().toISOString(),\n level: 'error',\n message: 'Unhandled Promise Rejection: ' + (event.reason ? (event.reason.message || String(event.reason)) : 'Unknown'),\n stack: event.reason && event.reason.stack ? event.reason.stack : ''\n };\n addLog(entry);\n });\n \n // ============================================\n // Send remaining logs on page unload\n // ============================================\n window.addEventListener('beforeunload', function() {\n if (writeQueue.length > 0) {\n // Use sendBeacon to ensure logs are sent\n writeQueue.forEach(function(entry) {\n navigator.sendBeacon(LOG_API_PATH, JSON.stringify(entry));\n });\n writeQueue = [];\n }\n });\n \n // ============================================\n // Provide manual flush method\n // ============================================\n window.__flushBrowserLogs__ = function() {\n return new Promise(function(resolve) {\n // Wait for queue to finish processing\n function checkQueue() {\n if (writeQueue.length === 0 && !isWriting) {\n resolve();\n } else {\n setTimeout(checkQueue, 100);\n }\n }\n checkQueue();\n });\n };\n \n // Provide method to get queue status\n window.__getBrowserLogsStatus__ = function() {\n return {\n queueLength: writeQueue.length,\n isWriting: isWriting\n };\n };\n \n originalConsole.log('[BrowserLogs] Log collection started');\n})();\n</script>`;\n\n return {\n name: \"vite-plugin-browser-logs\",\n\n configResolved(config) {\n // Determine log file path: use WORKSPACE_DIR env var (set by PM2/Docker),\n // or find the nearest directory containing package.json from config.root,\n // to ensure browser.log is always at the workspace root level.\n const workspaceDir = process.env.WORKSPACE_DIR;\n if (workspaceDir) {\n logFilePath = path.join(workspaceDir, \"browser.log\");\n } else {\n // Fallback: walk up from config.root to find directory with package.json\n let dir = config.root || process.cwd();\n while (dir !== path.dirname(dir)) {\n if (fs.existsSync(path.join(dir, \"package.json\"))) {\n break;\n }\n dir = path.dirname(dir);\n }\n logFilePath = path.join(dir, \"browser.log\");\n }\n },\n\n configureServer(devServer) {\n // Add log write API\n devServer.middlewares.use((req, res, next) => {\n if (req.url === \"/__browser__\" && req.method === \"POST\") {\n // Get request origin, dynamically set CORS headers to avoid protocol mismatch\n const origin = req.headers.origin || \"*\";\n\n let body = \"\";\n req.on(\"data\", (chunk: Buffer) => {\n body += chunk.toString();\n });\n req.on(\"end\", () => {\n try {\n // Ensure log directory exists\n const logDir = path.dirname(logFilePath);\n if (!fs.existsSync(logDir)) {\n fs.mkdirSync(logDir, { recursive: true });\n }\n // Append to log file\n fs.appendFileSync(logFilePath, `${body}\\n`, \"utf-8\");\n res.writeHead(200, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n });\n res.end(JSON.stringify({ success: true }));\n } catch (error) {\n console.error(\"[BrowserLogs] Write error:\", error);\n res.writeHead(500, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n });\n res.end(JSON.stringify({ success: false, error: String(error) }));\n }\n });\n } else if (req.url === \"/__browser__\" && req.method === \"OPTIONS\") {\n // Handle CORS preflight request\n const origin = req.headers.origin || \"*\";\n res.writeHead(204, {\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n \"Access-Control-Max-Age\": \"86400\",\n });\n res.end();\n } else if (req.url === \"/__browser__\") {\n const origin = req.headers.origin || \"*\";\n res.writeHead(405, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n });\n res.end(JSON.stringify({ error: \"Method not allowed\" }));\n } else {\n next();\n }\n });\n\n console.log(\"[BrowserLogs] Logs will be written to:\", logFilePath);\n },\n\n transformIndexHtml(html) {\n // Insert script after <head> tag to ensure earliest execution\n return html.replace(/<head([^>]*)>/i, `<head$1>${injectedScript}`);\n },\n };\n}\n","import type { Plugin } from \"vite\";\n\n/**\n * Runtime code that will be injected to replace react/jsx-dev-runtime\n * This code tags DOM elements with source information using refs\n */\nconst devRuntimeCode = `\nimport * as React from \"react\";\nimport * as ReactJSXDevRuntime from \"react/jsx-dev-runtime\";\n\nconst _jsxDEV = ReactJSXDevRuntime.jsxDEV;\nexport const Fragment = ReactJSXDevRuntime.Fragment;\n\nconst SOURCE_KEY = Symbol.for(\"__jsxSource__\");\nconst PROJECT_ROOT = \"\";\n\nconst cleanFileName = (fileName) => {\n if (!fileName) return \"\";\n // Remove project root prefix to get relative path\n if (PROJECT_ROOT && fileName.startsWith(PROJECT_ROOT)) {\n const relative = fileName.slice(PROJECT_ROOT.length);\n return relative.startsWith(\"/\") ? relative.slice(1) : relative;\n }\n return fileName;\n};\n\n// Global map to track elements by source location\nconst sourceElementMap = new Map();\nwindow.sourceElementMap = sourceElementMap;\n\nfunction getSourceKey(sourceInfo) {\n return \\`\\${cleanFileName(sourceInfo.fileName)}:\\${sourceInfo.lineNumber}:\\${sourceInfo.columnNumber}\\`;\n}\n\nfunction unregisterElement(node, sourceInfo) {\n const key = getSourceKey(sourceInfo);\n const refs = sourceElementMap.get(key);\n if (refs) {\n for (const ref of refs) {\n if (ref.deref() === node) {\n refs.delete(ref);\n break;\n }\n }\n if (refs.size === 0) {\n sourceElementMap.delete(key);\n }\n }\n}\n\nfunction registerElement(node, sourceInfo) {\n const key = getSourceKey(sourceInfo);\n if (!sourceElementMap.has(key)) {\n sourceElementMap.set(key, new Set());\n }\n sourceElementMap.get(key).add(new WeakRef(node));\n}\n\nfunction getTypeName(type) {\n if (typeof type === \"string\") return type;\n if (typeof type === \"function\") return type.displayName || type.name || \"Unknown\";\n if (typeof type === \"object\" && type !== null) {\n return type.displayName || type.render?.displayName || type.render?.name || \"Unknown\";\n }\n return \"Unknown\";\n}\n\nexport function jsxDEV(type, props, key, isStatic, source, self) {\n // For custom components, tag their rendered output\n if (source?.fileName && typeof type !== \"string\" && type !== Fragment) {\n const typeName = getTypeName(type);\n const fileName = cleanFileName(source.fileName);\n \n const jsxSourceInfo = {\n fileName,\n lineNumber: source.lineNumber,\n columnNumber: source.columnNumber,\n displayName: typeName,\n isComponent: true,\n };\n\n const originalRef = props?.ref;\n \n // Check if component can safely receive refs\n // - forwardRef components have $$typeof symbol\n // - Class components have prototype.isReactComponent\n // - If there's already a ref, the component expects it\n const isForwardRef = type.$$typeof === Symbol.for('react.forward_ref');\n const isClassComponent = typeof type === 'function' && type.prototype?.isReactComponent;\n const hasExistingRef = originalRef !== undefined;\n \n const canReceiveRef = isForwardRef || isClassComponent || hasExistingRef;\n \n if (canReceiveRef) {\n const enhancedProps = {\n ...props,\n ref: (node) => {\n if (node) {\n const existingSource = node[SOURCE_KEY];\n if (existingSource) {\n // 组件级的 source 总是覆盖元素级的 source\n if (!existingSource.isComponent) {\n unregisterElement(node, existingSource);\n node[SOURCE_KEY] = jsxSourceInfo;\n registerElement(node, jsxSourceInfo);\n }\n } else {\n node[SOURCE_KEY] = jsxSourceInfo;\n registerElement(node, jsxSourceInfo);\n }\n }\n if (typeof originalRef === \"function\") {\n originalRef(node);\n } else if (originalRef && typeof originalRef === \"object\") {\n originalRef.current = node;\n }\n },\n };\n return _jsxDEV(type, enhancedProps, key, isStatic, source, self);\n }\n\n return _jsxDEV(type, props, key, isStatic, source, self);\n }\n\n // For host elements (div, span, etc.), tag with source info\n if (source?.fileName && typeof type === \"string\") {\n const fileName = cleanFileName(source.fileName);\n \n // 判断当前元素是否在组件库中定义\n const isInLibrary = fileName.includes('/components/') || \n fileName.includes('/ui/') || \n fileName.includes('node_modules');\n \n // 组件库内部的元素不标记,不支持可视化编辑\n if (isInLibrary) {\n return _jsxDEV(type, props, key, isStatic, source, self);\n }\n \n const sourceInfo = {\n fileName,\n lineNumber: source.lineNumber,\n columnNumber: source.columnNumber,\n displayName: type,\n isComponent: false, // 标记这是元素级别的 source\n };\n\n const originalRef = props?.ref;\n\n const enhancedProps = {\n ...props,\n ref: (node) => {\n if (node) {\n const existingSource = node[SOURCE_KEY];\n // 如果已有 source,检查是否应该保留外层的\n if (existingSource) {\n // 如果已有的是组件级别的 source(isComponent: true),保留它\n if (existingSource.isComponent) {\n // 不更新,保留组件级别的 source\n if (typeof originalRef === \"function\") {\n originalRef(node);\n } else if (originalRef && typeof originalRef === \"object\") {\n originalRef.current = node;\n }\n return;\n }\n \n // 否则按正常逻辑更新\n if (getSourceKey(existingSource) !== getSourceKey(sourceInfo)) {\n unregisterElement(node, existingSource);\n node[SOURCE_KEY] = sourceInfo;\n registerElement(node, sourceInfo);\n }\n } else {\n node[SOURCE_KEY] = sourceInfo;\n registerElement(node, sourceInfo);\n }\n }\n if (typeof originalRef === \"function\") {\n originalRef(node);\n } else if (originalRef && typeof originalRef === \"object\") {\n originalRef.current = node;\n }\n },\n };\n return _jsxDEV(type, enhancedProps, key, isStatic, source, self);\n }\n\n return _jsxDEV(type, props, key, isStatic, source, self);\n}\n`;\n\n/**\n * Vite plugin: JSX Source Tagger\n * Intercepts react/jsx-dev-runtime to add source information to DOM elements\n * Only enabled in development mode\n */\nexport function jsxSourceTaggerPlugin(): Plugin {\n let isDev = false;\n let projectRoot = \"\";\n\n return {\n name: \"vite-plugin-jsx-source-tagger\",\n enforce: \"pre\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n projectRoot = config.root;\n },\n\n resolveId(id, importer) {\n if (!isDev) return null;\n\n // Intercept react/jsx-dev-runtime imports\n if (id === \"react/jsx-dev-runtime\" && !importer?.includes(\"\\0jsx-source\")) {\n return \"\\0jsx-source/jsx-dev-runtime\";\n }\n return null;\n },\n\n load(id) {\n if (!isDev) return null;\n\n // Return our custom runtime code with injected projectRoot\n if (id === \"\\0jsx-source/jsx-dev-runtime\") {\n return devRuntimeCode.replace(\n 'const PROJECT_ROOT = \"\";',\n `const PROJECT_ROOT = ${JSON.stringify(projectRoot)};`\n );\n }\n return null;\n },\n };\n}\n","import type { Plugin } from \"vite\";\nimport fs from \"fs/promises\";\nimport path from \"path\";\n\n/**\n * Vite plugin: Tailwind Config Sync\n * Simplified version - just return raw config without resolveConfig\n */\nexport function tailwindConfigSyncPlugin(options?: { configPath?: string }): Plugin {\n let projectRoot = \"\";\n let isDev = false;\n let cachedConfig: Record<string, unknown> | null = null;\n let viteServer: any = null;\n\n const configPath = options?.configPath || \"./tailwind.config.ts\";\n const VIRTUAL_MODULE_ID = \"@amaster/tailwind-config\";\n const RESOLVED_VIRTUAL_MODULE_ID = \"\\0\" + VIRTUAL_MODULE_ID;\n\n const findConfigFile = async (): Promise<string | null> => {\n const configFile = path.resolve(projectRoot, configPath);\n\n try {\n await fs.access(configFile);\n return configFile;\n } catch {\n // If specified config doesn't exist, try alternative extensions\n if (configPath.endsWith(\".ts\")) {\n const jsConfig = configFile.replace(/\\.ts$/, \".js\");\n try {\n await fs.access(jsConfig);\n return jsConfig;\n } catch {\n return null;\n }\n } else if (configPath.endsWith(\".js\")) {\n const tsConfig = configFile.replace(/\\.js$/, \".ts\");\n try {\n await fs.access(tsConfig);\n return tsConfig;\n } catch {\n return null;\n }\n }\n return null;\n }\n };\n\n const generateConfig = async (server?: any): Promise<Record<string, unknown> | null> => {\n try {\n const tailwindInputFile = await findConfigFile();\n if (!tailwindInputFile) {\n return null;\n }\n\n // If we have a Vite server, use its module graph to load the config\n // This ensures we get the latest version after HMR\n if (server) {\n const configModule = await server.ssrLoadModule(tailwindInputFile);\n const rawConfig = configModule.default || configModule;\n cachedConfig = rawConfig;\n return cachedConfig;\n }\n\n // Fallback: use dynamic import with cache busting\n const configUrl = `file://${tailwindInputFile}?t=${Date.now()}`;\n const userConfig = await import(configUrl);\n\n const rawConfig = userConfig.default || userConfig;\n cachedConfig = rawConfig;\n return cachedConfig;\n } catch (error) {\n console.error(\"[tailwind-config-sync] Failed to generate config:\", error);\n return null;\n }\n };\n\n return {\n name: \"vite-plugin-tailwind-config-sync\",\n\n configResolved(resolvedConfig) {\n projectRoot = resolvedConfig.root;\n isDev = resolvedConfig.command === \"serve\";\n },\n\n async buildStart() {\n if (!isDev) return;\n await generateConfig();\n },\n\n resolveId(id) {\n if (id === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n },\n\n async load(id) {\n if (id === RESOLVED_VIRTUAL_MODULE_ID) {\n // Always regenerate config to get latest, pass viteServer if available\n await generateConfig(viteServer);\n\n // If no config found, return empty module\n if (!cachedConfig) {\n return `export default null;`;\n }\n\n // Generate code with HMR support\n const code = `\n// Use global variable to persist callbacks and current config across HMR updates\nif (!window.__tailwindConfigCallbacks) {\n window.__tailwindConfigCallbacks = [];\n}\n\n// Always update current config with the latest from server\nlet tailwindConfigCurrent = ${JSON.stringify(cachedConfig)};\n\nif (import.meta.hot) {\n // Accept self updates\n import.meta.hot.accept((newModule) => {\n if (newModule && newModule.default) {\n // Call all update callbacks with the new config from window\n window.__tailwindConfigCallbacks.forEach((callback) => {\n try {\n // Pass the actual config object, not the Proxy\n callback(newModule.default);\n } catch (e) {\n console.error('[TailwindConfig] Callback error:', e);\n }\n });\n }\n });\n}\n\nexport function onUpdate(fn) {\n window.__tailwindConfigCallbacks.push(fn);\n return () => { \n const index = window.__tailwindConfigCallbacks.indexOf(fn);\n if (index > -1) {\n window.__tailwindConfigCallbacks.splice(index, 1);\n }\n };\n};\nexport default tailwindConfigCurrent;\n\n`;\n return code;\n }\n },\n\n configureServer(server) {\n if (!isDev) return;\n\n viteServer = server;\n\n (async () => {\n try {\n const tailwindInputFile = await findConfigFile();\n if (tailwindInputFile) {\n server.watcher.add(tailwindInputFile);\n }\n } catch {\n // Ignore errors\n }\n })();\n },\n\n async handleHotUpdate({ file, server }) {\n const tailwindInputFile = await findConfigFile();\n\n if (!tailwindInputFile || path.normalize(file) !== path.normalize(tailwindInputFile)) {\n return;\n }\n\n // Invalidate the config file in SSR module graph first\n const configMod = server.moduleGraph.getModuleById(tailwindInputFile);\n if (configMod) {\n server.moduleGraph.invalidateModule(configMod);\n }\n\n // Then regenerate config using the server's SSR loader\n await generateConfig(server);\n\n // Finally invalidate our virtual module\n const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);\n if (mod) {\n server.moduleGraph.invalidateModule(mod);\n return [mod];\n }\n\n return [];\n },\n };\n}\n","import type { Plugin } from 'vite';\n\nexport interface TaroStyleAdapterOptions {\n /**\n * Design width for responsive scaling (default: 375)\n * Should match Taro config's designWidth\n */\n designWidth?: number;\n \n /**\n * Maximum viewport width to scale (default: 750)\n * Beyond this width, font-size stays fixed\n */\n maxWidth?: number;\n\n /**\n * Base font size in pixels (default: 12)\n * Should match Taro config's baseFontSize\n */\n baseFontSize?: number;\n\n /**\n * Minimum root font size in pixels (default: 12)\n * Should match Taro config's minRootSize\n */\n minRootSize?: number;\n\n /**\n * Maximum root font size in pixels (default: 24)\n * Should match Taro config's maxRootSize\n */\n maxRootSize?: number;\n}\n\n/**\n * Taro H5 样式适配插件\n * \n * 功能:\n * 1. 动态计算根字号,使 H5 的 rem 与小程序的 rpx 行为对齐\n * 2. 隐藏 Taro 页面容器的滚动条,用于编辑器 iframe 预览\n * \n * 原理:\n * - 小程序 rpx: 1rpx = 屏幕宽度 / 750\n * - H5 rem: Taro 把 rpx 转成 rem,基于 baseFontSize\n * - 本插件动态设置 html font-size,使 rem 的实际像素值与 rpx 对齐\n * \n * 注意:此插件会覆盖 Taro 默认注入的根字号脚本,配置需与 Taro pxtransform 保持一致\n * \n * @example\n * ```ts\n * // In Taro config/dev.ts\n * import { taroStyleAdapterPlugin } from '@amaster.ai/vite-plugins'\n * \n * export default {\n * compiler: {\n * type: 'vite',\n * vitePlugins: [\n * taroStyleAdapterPlugin({ \n * designWidth: 375,\n * baseFontSize: 12,\n * minRootSize: 12,\n * maxRootSize: 24\n * })\n * ]\n * }\n * }\n * ```\n */\nexport function taroStyleAdapterPlugin(options: TaroStyleAdapterOptions = {}): Plugin {\n const { \n designWidth = 375, \n maxWidth = 750,\n baseFontSize = 12,\n minRootSize = 12,\n maxRootSize = 24\n } = options;\n \n return {\n name: 'vite-plugin-taro-style-adapter',\n apply: 'serve', // 仅在开发模式下生效\n transformIndexHtml(html) {\n // 动态根字号脚本\n // 公式:fontSize = (clientWidth / designWidth) * baseFontSize\n // 当 designWidth=375, baseFontSize=12 时:\n // - 375px 屏幕 → 12px (1rem = 12px)\n // - 750px 屏幕 → 24px (1rem = 24px)\n // 这样 rem 值在不同屏幕宽度下的视觉比例与小程序 rpx 一致\n const flexibleScript = `\n<script data-taro-flexible=\"true\">\n(function() {\n var designWidth = ${designWidth};\n var maxWidth = ${maxWidth};\n var baseFontSize = ${baseFontSize};\n var minRootSize = ${minRootSize};\n var maxRootSize = ${maxRootSize};\n \n function setRootFontSize() {\n var docEl = document.documentElement;\n var clientWidth = docEl.clientWidth;\n \n // 限制最大宽度\n if (clientWidth > maxWidth) {\n clientWidth = maxWidth;\n }\n \n // 计算根字号: (屏幕宽度 / 设计稿宽度) * 基准字号\n var fontSize = (clientWidth / designWidth) * baseFontSize;\n \n // 应用最小/最大限制\n if (fontSize < minRootSize) {\n fontSize = minRootSize;\n } else if (fontSize > maxRootSize) {\n fontSize = maxRootSize;\n }\n \n docEl.style.fontSize = fontSize + 'px';\n }\n \n setRootFontSize();\n \n // 监听窗口变化\n window.addEventListener('resize', setRootFontSize);\n window.addEventListener('orientationchange', setRootFontSize);\n \n // 页面显示时重新计算(解决某些浏览器的 bug)\n document.addEventListener('DOMContentLoaded', setRootFontSize);\n})();\n</script>\n`;\n\n // 滚动条隐藏样式 + Taro Image 组件修复\n const styles = `\n<style data-taro-adapter=\"true\">\n /* 仅 H5 生效:隐藏 Taro 页面容器滚动条,但仍可滚动 */\n .taro_page {\n -ms-overflow-style: none; /* IE/Edge 老版 */\n scrollbar-width: none; /* Firefox */\n }\n\n .taro_page::-webkit-scrollbar {\n width: 0;\n height: 0;\n display: none; /* Chrome/Safari */\n }\n\n /* 隐藏 Taro ScrollView 组件的滚动条 */\n .taro-scroll-view__scroll-y,\n .taro-scroll-view__scroll-x {\n -ms-overflow-style: none; /* IE/Edge 老版 */\n scrollbar-width: none; /* Firefox */\n }\n\n .taro-scroll-view__scroll-y::-webkit-scrollbar,\n .taro-scroll-view__scroll-x::-webkit-scrollbar {\n width: 0;\n height: 0;\n display: none; /* Chrome/Safari */\n }\n\n /*\n * 修复 Taro Image 组件在 H5 下的尺寸问题\n * \n * 问题:Taro Image 组件使用 aspectFit 模式时,内部 img 使用 max-width/max-height: 100%\n * 导致小尺寸图片(如 SVG 图标)无法按指定尺寸显示,只显示原始尺寸\n * \n * 解决:让 img 填满 taro-image-core 容器,由容器控制尺寸\n */\n taro-image-core img.taro-img__mode-aspectfit {\n width: 100%;\n height: 100%;\n max-width: none;\n max-height: none;\n position: static;\n transform: none;\n object-fit: contain;\n }\n</style>\n`;\n \n // 在 </head> 之前插入脚本和样式\n return html.replace('</head>', `${flexibleScript}${styles}</head>`);\n }\n };\n}\n","/**\n * PostCSS 插件:H5 模式下将 rpx 预转换为 px\n *\n * 问题背景:\n * - Taro 的 pxtransform 在 H5 模式下会处理 rpx,但它把 rpx 值直接除以 rootValue\n * - 导致 96rpx 被转成 8rem(96/12),实际显示为 96px\n * - 而正确应该是:96rpx = 48px = 4rem = 48px\n *\n * 解决方案:\n * - 在 pxtransform 之前,先把 rpx 转成 px(rpx / 2)\n * - 然后 pxtransform 会正确地把 px 转成 rem(px / 12)\n *\n * 转换链路:96rpx → 48px → 4rem → 48px(正确)\n * \n * @example\n * ```ts\n * // In Taro config/index.ts\n * import { rpx2pxPlugin } from '@amaster.ai/vite-plugins'\n * \n * // 在 postcss-config-loader-plugin 中使用\n * {\n * name: 'postcss-config-loader-plugin',\n * config(config) {\n * if (typeof config.css?.postcss === 'object') {\n * config.css?.postcss.plugins?.unshift(tailwindcss())\n * // H5 模式下添加 rpx2px 插件\n * if (process.env.TARO_ENV === 'h5') {\n * config.css?.postcss.plugins?.unshift(rpx2pxPlugin())\n * }\n * }\n * }\n * }\n * ```\n */\n\nexport interface Rpx2pxPluginOptions {\n /**\n * rpx 到 px 的转换比例(默认 2)\n * 即 1rpx = 1/ratio px\n * 默认值 2 表示 2rpx = 1px(基于 375 设计稿)\n */\n ratio?: number;\n}\n\ninterface PostCSSDeclaration {\n value: string;\n}\n\ninterface PostCSSPlugin {\n postcssPlugin: string;\n Declaration: (decl: PostCSSDeclaration) => void;\n}\n\ntype PostCSSPluginCreator = {\n (): PostCSSPlugin;\n postcss: boolean;\n};\n\nexport function rpx2pxPlugin(options: Rpx2pxPluginOptions = {}): PostCSSPlugin {\n const { ratio = 2 } = options;\n \n return {\n postcssPlugin: 'postcss-rpx2px',\n Declaration(decl: PostCSSDeclaration) {\n if (decl.value?.includes('rpx')) {\n decl.value = decl.value.replace(/(-?\\d*\\.?\\d+)rpx/gi, (_match: string, num: string) => {\n const pxValue = parseFloat(num) / ratio;\n return pxValue === 0 ? '0' : `${pxValue}px`;\n });\n }\n }\n };\n}\n\n// PostCSS 插件标识\n(rpx2pxPlugin as PostCSSPluginCreator).postcss = true;\n","/**\n * Taro Environment Variables Injection Helper\n * \n * Automatically injects environment variables into Taro's defineConstants\n * so that they will be replaced at build time.\n * \n * @example\n * ```ts\n * // In Taro config/index.ts\n * import { injectTaroEnv } from '@amaster.ai/vite-plugins/taro-env-inject'\n * \n * export default defineConfig({\n * defineConstants: {\n * ...injectTaroEnv()\n * }\n * })\n * ```\n */\n\nexport interface TaroEnvInjectOptions {\n /**\n * Additional environment variable names to inject\n * @default []\n */\n additional?: string[];\n \n /**\n * Whether to inject all TARO_APP_* prefixed variables\n * @default true\n */\n autoInjectTaroApp?: boolean;\n \n /**\n * Whether to inject all VITE_* prefixed variables\n * @default true\n */\n autoInjectVite?: boolean;\n}\n\n/**\n * Inject environment variables into Taro's defineConstants\n * \n * This function reads environment variables and formats them for Taro's defineConstants.\n * Taro will replace these at build time, converting `process.env.XXX` to actual values.\n */\nexport function injectTaroEnv(options: TaroEnvInjectOptions = {}): Record<string, string> {\n const {\n additional = [],\n autoInjectTaroApp = true,\n autoInjectVite = true,\n } = options;\n\n const constants: Record<string, string> = {};\n\n // Collect variable names to inject\n const varsToInject = new Set<string>(additional);\n\n // Auto-detect TARO_APP_* variables\n if (autoInjectTaroApp) {\n Object.keys(process.env).forEach(key => {\n if (key.startsWith('TARO_APP_')) {\n varsToInject.add(key);\n }\n });\n }\n\n // Auto-detect VITE_* variables\n if (autoInjectVite) {\n Object.keys(process.env).forEach(key => {\n if (key.startsWith('VITE_')) {\n varsToInject.add(key);\n }\n });\n }\n\n // Inject variables into defineConstants format\n varsToInject.forEach(varName => {\n const value = process.env[varName] || '';\n constants[`process.env.${varName}`] = JSON.stringify(value);\n });\n\n return constants;\n}\n\n/**\n * Inject specific environment variables for amaster.ai mini-program builds\n * \n * This is a convenience function that injects the standard environment variables\n * used by @amaster.ai/http-client for API base URL configuration.\n */\nexport function injectAmasterEnv(): Record<string, string> {\n return {\n 'process.env.TARO_APP_API_BASE_URL': JSON.stringify(process.env.TARO_APP_API_BASE_URL || ''),\n 'process.env.VITE_API_BASE_URL': JSON.stringify(process.env.VITE_API_BASE_URL || ''),\n };\n}\n","import { editorBridgePlugin } from \"./editor-bridge\";\nimport { routesExposePlugin } from \"./routes-expose\";\nimport { browserLogsPlugin } from \"./browser-logs\";\nimport { jsxSourceTaggerPlugin } from \"./tagger\";\nimport { tailwindConfigSyncPlugin } from \"./tailwind-config-sync\";\n// import { smartReloadPlugin } from \"./smart-reload\"; // 智能重载功能开发中,暂不启用\nimport { taroStyleAdapterPlugin, type TaroStyleAdapterOptions } from \"./taro-style-adapter\";\nimport { rpx2pxPlugin } from \"./postcss-rpx2px\";\nimport process from \"node:process\";\nimport type { Plugin } from \"vite\";\n\nexport interface DevToolsOptions {\n /**\n * 是否为 Taro 项目\n * - true: 启用 Taro 相关插件(taroStyleAdapterPlugin、rpx2pxPlugin)\n * - false: 禁用 Taro 相关插件\n * - undefined: 自动检测(通过 process.env.TARO_ENV 判断,默认为 false)\n */\n isTaro?: boolean;\n\n /**\n * Taro style adapter options\n * Controls H5 responsive scaling to match mini-program rpx behavior\n * 仅在 isTaro 为 true 时生效\n */\n styleAdapter?: TaroStyleAdapterOptions;\n\n /**\n * 是否启用 JSX Source Tagger(通过 Symbol 标记元素源码位置)\n * 默认:开发模式启用\n */\n jsxSourceTagger?: boolean;\n\n /**\n * 是否启用 Tailwind Config 同步(生成 JSON 文件)\n * 默认:开发模式启用\n */\n tailwindConfigSync?: boolean;\n\n /**\n * Tailwind 配置文件路径\n * 默认:./tailwind.config.ts\n */\n tailwindConfigPath?: string;\n}\n\n/**\n * 开发工具插件集合,简化调用,vite.config.ts 直接 devTools() 即可\n *\n * @param options 配置项\n * @param options.isTaro 是否为 Taro 项目(默认根据 TARO_ENV 自动判断)\n * @param options.styleAdapter Taro H5 样式适配配置,designWidth 应与 Taro config 一致\n * @returns Plugin[] Vite 插件数组\n *\n * @example\n * ```ts\n * // Taro 项目 - config/dev.ts\n * import devTools from \"@amaster.ai/vite-plugins\";\n *\n * export default {\n * compiler: {\n * type: 'vite',\n * vitePlugins: [devTools({ isTaro: true })]\n * }\n * }\n * ```\n *\n * @example\n * ```ts\n * // React 项目 - vite.config.ts\n * import devTools from \"@amaster.ai/vite-plugins\";\n *\n * export default {\n * plugins: [devTools()] // isTaro 默认为 false\n * }\n * ```\n */\nexport default function devTools(options: DevToolsOptions = {}): Plugin[] {\n // 判断是否为 Taro 项目\n // 优先使用用户显式配置,否则通过环境变量判断\n const isTaro = options.isTaro ?? process.env.TARO_ENV === \"h5\";\n\n const plugins: Plugin[] = [\n // componentIdPlugin(), // 暂不启用\n editorBridgePlugin(),\n routesExposePlugin(),\n // smartReloadPlugin() // 智能重载:拦截 full-reload,静默等待重连\n ];\n\n // JSX Source Tagger - 默认开发模式启用\n if (options.jsxSourceTagger !== false) {\n plugins.push(jsxSourceTaggerPlugin());\n }\n\n // Tailwind Config Sync - 默认开发模式启用\n if (options.tailwindConfigSync !== false) {\n plugins.push(\n tailwindConfigSyncPlugin({\n configPath: options.tailwindConfigPath,\n })\n );\n }\n\n // 仅在 Taro 项目中添加 Taro 相关插件\n if (isTaro) {\n // Taro H5 样式适配(运行时)\n plugins.unshift(taroStyleAdapterPlugin(options.styleAdapter));\n\n // H5 开发模式下添加 rpx2px PostCSS 插件(编译时)\n plugins.unshift({\n name: \"dev-postcss-rpx2px-plugin\",\n apply: \"serve\",\n config(config) {\n if (typeof config.css?.postcss === \"object\") {\n // 在最前面插入,确保在 pxtransform 之前执行\n config.css?.postcss.plugins?.unshift(rpx2pxPlugin());\n }\n },\n });\n }\n\n // process.env.WORKSPACE_GIT_REPO 有这个表示是在 sandbox 里面运行,启用浏览器日志插件\n if (process.env.WORKSPACE_GIT_REPO) {\n plugins.push(browserLogsPlugin());\n }\n\n return plugins;\n}\n\nexport {\n editorBridgePlugin,\n routesExposePlugin,\n // smartReloadPlugin\n};\n\n// Export Taro environment injection helpers\nexport { injectTaroEnv, injectAmasterEnv } from \"./taro-env-inject\";\n\n// Export Taro style adapter plugin and its types\nexport { taroStyleAdapterPlugin, type TaroStyleAdapterOptions } from \"./taro-style-adapter\";\n\n// Export PostCSS rpx2px plugin for H5 mode\nexport { rpx2pxPlugin, type Rpx2pxPluginOptions } from \"./postcss-rpx2px\";\n\n// Export tagger and tailwind config sync plugins\nexport { jsxSourceTaggerPlugin } from \"./tagger\";\nexport { tailwindConfigSyncPlugin } from \"./tailwind-config-sync\";\n"]}