@amaster.ai/vite-plugins 1.0.0-beta.46 → 1.0.0-beta.47
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 +140 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +140 -79
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,77 +1,116 @@
|
|
|
1
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (element.hasAttribute("data-link-href") && !noJumpOut) {
|
|
6
|
-
const href = element.getAttribute("data-link-href");
|
|
7
|
-
const target = element.getAttribute("data-link-target");
|
|
8
|
-
if (href) {
|
|
9
|
-
if (target === "_blank") {
|
|
10
|
-
window.open(href, "_blank");
|
|
11
|
-
} else {
|
|
12
|
-
window.location.href = href;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
} else if(noJumpOut && element.tagName === "A") {
|
|
16
|
-
e.preventDefault();
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
</script>`;function I(r){return `<script type="module">
|
|
20
|
-
(function() {
|
|
21
|
-
const SOURCE_KEY = Symbol.for("__jsxSource__");
|
|
22
|
-
const SESSION_KEY = "${r}";
|
|
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 j(r){return `
|
|
2
|
+
// Bridge monitor module - handles all bridge logic
|
|
3
|
+
const SOURCE_KEY = Symbol.for("__jsxSource__");
|
|
4
|
+
const SESSION_KEY = "${r}";
|
|
23
5
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
}
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
// Import and monitor Tailwind config
|
|
29
|
+
(async () => {
|
|
30
|
+
try {
|
|
31
|
+
const tailwindConfig = await import('@amaster/tailwind-config');
|
|
32
|
+
const config = tailwindConfig.default;
|
|
37
33
|
|
|
38
|
-
if (
|
|
39
|
-
console.warn("[Bridge] Invalid session key");
|
|
34
|
+
if (!config) {
|
|
40
35
|
return;
|
|
41
36
|
}
|
|
42
37
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
// Get actual config from window (Proxy reads from here)
|
|
39
|
+
const actualConfig = window.__tailwindConfigCurrent;
|
|
40
|
+
|
|
41
|
+
if (!actualConfig) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const sendConfig = (type) => {
|
|
46
|
+
// Serialize config to JSON (remove functions)
|
|
47
|
+
const serializableConfig = JSON.parse(JSON.stringify(actualConfig));
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
// Dispatch event for bridge.js to handle
|
|
50
|
+
window.dispatchEvent(new CustomEvent('amaster:tailwind-config', {
|
|
51
|
+
detail: {
|
|
52
|
+
type: type,
|
|
53
|
+
config: serializableConfig
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Send initial config
|
|
59
|
+
sendConfig('loaded');
|
|
60
|
+
|
|
61
|
+
// Listen for bridge ready event and resend config
|
|
62
|
+
window.addEventListener('amaster:bridge-ready', () => {
|
|
63
|
+
sendConfig('loaded');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Listen for config updates
|
|
67
|
+
if (config.onUpdate) {
|
|
68
|
+
config.onUpdate((newConfig) => {
|
|
69
|
+
sendConfig('updated');
|
|
70
|
+
});
|
|
61
71
|
}
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
window.__AMASTER_BRIDGE__?.postToParent("amaster.bridge.initialized", {});
|
|
66
|
-
});
|
|
72
|
+
} catch (e) {
|
|
73
|
+
// Silently fail if tailwind config is not available
|
|
74
|
+
}
|
|
67
75
|
})();
|
|
68
|
-
|
|
76
|
+
|
|
77
|
+
// Listen for bridge script URL from platform
|
|
78
|
+
window.addEventListener("message", (event) => {
|
|
79
|
+
const { type, data, key } = event.data;
|
|
80
|
+
|
|
81
|
+
if (key !== SESSION_KEY) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (type === "amaster.loadBridge" && data?.scriptContent) {
|
|
86
|
+
// Create blob URL from script content
|
|
87
|
+
const blob = new Blob([data.scriptContent], { type: 'application/javascript' });
|
|
88
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
89
|
+
|
|
90
|
+
const script = document.createElement("script");
|
|
91
|
+
script.src = blobUrl;
|
|
92
|
+
script.onload = () => {
|
|
93
|
+
URL.revokeObjectURL(blobUrl);
|
|
94
|
+
};
|
|
95
|
+
script.onerror = () => {
|
|
96
|
+
URL.revokeObjectURL(blobUrl);
|
|
97
|
+
};
|
|
98
|
+
document.head.appendChild(script);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
window.addEventListener("load", () => {
|
|
103
|
+
window.__AMASTER_BRIDGE__?.postToParent("amaster.bridge.initialized", {});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
export default {};
|
|
107
|
+
`}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 j(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}
|
|
69
108
|
|
|
70
109
|
// Development mode: Expose routes to window.__APP_ROUTES__
|
|
71
110
|
if (typeof window !== 'undefined') {
|
|
72
111
|
window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];
|
|
73
112
|
}
|
|
74
|
-
`,map:null}}catch{return null}}}}function
|
|
113
|
+
`,map:null}}catch{return null}}}}function P(){let r="",n=`
|
|
75
114
|
<script>
|
|
76
115
|
(function() {
|
|
77
116
|
'use strict';
|
|
@@ -752,8 +791,8 @@ if (typeof window !== 'undefined') {
|
|
|
752
791
|
|
|
753
792
|
originalConsole.log('[BrowserLogs] Log collection started');
|
|
754
793
|
})();
|
|
755
|
-
</script>`;return {name:"vite-plugin-browser-logs",configResolved(
|
|
756
|
-
`,"utf-8"),
|
|
794
|
+
</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}
|
|
795
|
+
`,"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 k=`
|
|
757
796
|
import * as React from "react";
|
|
758
797
|
import * as ReactJSXDevRuntime from "react/jsx-dev-runtime";
|
|
759
798
|
|
|
@@ -899,36 +938,58 @@ export function jsxDEV(type, props, key, isStatic, source, self) {
|
|
|
899
938
|
|
|
900
939
|
return _jsxDEV(type, props, key, isStatic, source, self);
|
|
901
940
|
}
|
|
902
|
-
`;function v(){let r=false,
|
|
903
|
-
|
|
941
|
+
`;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"?k.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?`
|
|
942
|
+
// Use global variable to persist callbacks and current config across HMR updates
|
|
943
|
+
if (!window.__tailwindConfigCallbacks) {
|
|
944
|
+
window.__tailwindConfigCallbacks = [];
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// Always update current config with the latest from server
|
|
948
|
+
window.__tailwindConfigCurrent = ${JSON.stringify(t)};
|
|
904
949
|
|
|
905
|
-
let _updateConfig;
|
|
906
950
|
if (import.meta.hot) {
|
|
907
951
|
// Accept self updates
|
|
908
952
|
import.meta.hot.accept((newModule) => {
|
|
909
|
-
if (newModule &&
|
|
910
|
-
|
|
953
|
+
if (newModule && newModule.default) {
|
|
954
|
+
// Call all update callbacks with the new config from window
|
|
955
|
+
window.__tailwindConfigCallbacks.forEach((callback) => {
|
|
956
|
+
try {
|
|
957
|
+
// Pass the actual config object, not the Proxy
|
|
958
|
+
callback(window.__tailwindConfigCurrent);
|
|
959
|
+
} catch (e) {
|
|
960
|
+
console.error('[TailwindConfig] Callback error:', e);
|
|
961
|
+
}
|
|
962
|
+
});
|
|
911
963
|
}
|
|
912
964
|
});
|
|
913
965
|
}
|
|
914
966
|
|
|
915
|
-
export default new Proxy(
|
|
967
|
+
export default new Proxy({}, {
|
|
916
968
|
get(target, prop) {
|
|
917
969
|
if (prop === 'then') return undefined;
|
|
918
|
-
if (prop === '
|
|
919
|
-
return (fn) => {
|
|
970
|
+
if (prop === 'onUpdate') {
|
|
971
|
+
return (fn) => {
|
|
972
|
+
window.__tailwindConfigCallbacks.push(fn);
|
|
973
|
+
return () => {
|
|
974
|
+
const index = window.__tailwindConfigCallbacks.indexOf(fn);
|
|
975
|
+
if (index > -1) {
|
|
976
|
+
window.__tailwindConfigCallbacks.splice(index, 1);
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
};
|
|
920
980
|
}
|
|
921
|
-
|
|
981
|
+
// Always read from the global current config
|
|
982
|
+
return window.__tailwindConfigCurrent[prop];
|
|
922
983
|
}
|
|
923
984
|
});
|
|
924
|
-
|
|
985
|
+
`:"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=`
|
|
925
986
|
<script data-taro-flexible="true">
|
|
926
987
|
(function() {
|
|
927
|
-
var designWidth = ${
|
|
928
|
-
var maxWidth = ${
|
|
929
|
-
var baseFontSize = ${
|
|
930
|
-
var minRootSize = ${
|
|
931
|
-
var maxRootSize = ${
|
|
988
|
+
var designWidth = ${n};
|
|
989
|
+
var maxWidth = ${e};
|
|
990
|
+
var baseFontSize = ${t};
|
|
991
|
+
var minRootSize = ${o};
|
|
992
|
+
var maxRootSize = ${l};
|
|
932
993
|
|
|
933
994
|
function setRootFontSize() {
|
|
934
995
|
var docEl = document.documentElement;
|
|
@@ -962,7 +1023,7 @@ export default new Proxy(config, {
|
|
|
962
1023
|
document.addEventListener('DOMContentLoaded', setRootFontSize);
|
|
963
1024
|
})();
|
|
964
1025
|
</script>
|
|
965
|
-
`;return
|
|
1026
|
+
`;return i.replace("</head>",`${u}
|
|
966
1027
|
<style data-taro-adapter="true">
|
|
967
1028
|
/* \u4EC5 H5 \u751F\u6548\uFF1A\u9690\u85CF Taro \u9875\u9762\u5BB9\u5668\u6EDA\u52A8\u6761\uFF0C\u4F46\u4ECD\u53EF\u6EDA\u52A8 */
|
|
968
1029
|
.taro_page {
|
|
@@ -1008,5 +1069,5 @@ export default new Proxy(config, {
|
|
|
1008
1069
|
object-fit: contain;
|
|
1009
1070
|
}
|
|
1010
1071
|
</style>
|
|
1011
|
-
</head>`)}}}function y(r={}){let{ratio:
|
|
1072
|
+
</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 L(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 q(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=q;exports.editorBridgePlugin=O;exports.injectAmasterEnv=D;exports.injectTaroEnv=L;exports.jsxSourceTaggerPlugin=v;exports.routesExposePlugin=T;exports.rpx2pxPlugin=y;exports.tailwindConfigSyncPlugin=_;exports.taroStyleAdapterPlugin=b;//# sourceMappingURL=index.cjs.map
|
|
1012
1073
|
//# sourceMappingURL=index.cjs.map
|