@amaster.ai/vite-plugins 1.0.0-beta.45 → 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 +141 -77
- 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 +141 -77
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,74 +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
|
+
};
|
|
33
15
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
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
|
-
}
|
|
49
|
-
script.src = data.scriptUrl;
|
|
50
|
-
script.onload = () => {
|
|
51
|
-
console.log("[Bridge] External script loaded");
|
|
52
|
-
window.__AMASTER_BRIDGE__?.postToParent("amaster.bridge.ready", {});
|
|
53
|
-
};
|
|
54
|
-
script.onerror = () => {
|
|
55
|
-
console.error("[Bridge] Failed to load external script");
|
|
56
|
-
};
|
|
57
|
-
document.head.appendChild(script);
|
|
38
|
+
// Get actual config from window (Proxy reads from here)
|
|
39
|
+
const actualConfig = window.__tailwindConfigCurrent;
|
|
40
|
+
|
|
41
|
+
if (!actualConfig) {
|
|
42
|
+
return;
|
|
58
43
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
44
|
+
|
|
45
|
+
const sendConfig = (type) => {
|
|
46
|
+
// Serialize config to JSON (remove functions)
|
|
47
|
+
const serializableConfig = JSON.parse(JSON.stringify(actualConfig));
|
|
48
|
+
|
|
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
|
+
});
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {
|
|
73
|
+
// Silently fail if tailwind config is not available
|
|
74
|
+
}
|
|
64
75
|
})();
|
|
65
|
-
|
|
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}
|
|
66
108
|
|
|
67
109
|
// Development mode: Expose routes to window.__APP_ROUTES__
|
|
68
110
|
if (typeof window !== 'undefined') {
|
|
69
111
|
window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];
|
|
70
112
|
}
|
|
71
|
-
`,map:null}}catch{return null}}}}function
|
|
113
|
+
`,map:null}}catch{return null}}}}function P(){let r="",n=`
|
|
72
114
|
<script>
|
|
73
115
|
(function() {
|
|
74
116
|
'use strict';
|
|
@@ -749,8 +791,8 @@ if (typeof window !== 'undefined') {
|
|
|
749
791
|
|
|
750
792
|
originalConsole.log('[BrowserLogs] Log collection started');
|
|
751
793
|
})();
|
|
752
|
-
</script>`;return {name:"vite-plugin-browser-logs",configResolved(
|
|
753
|
-
`,"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=`
|
|
754
796
|
import * as React from "react";
|
|
755
797
|
import * as ReactJSXDevRuntime from "react/jsx-dev-runtime";
|
|
756
798
|
|
|
@@ -896,36 +938,58 @@ export function jsxDEV(type, props, key, isStatic, source, self) {
|
|
|
896
938
|
|
|
897
939
|
return _jsxDEV(type, props, key, isStatic, source, self);
|
|
898
940
|
}
|
|
899
|
-
`;function v(){let r=false,
|
|
900
|
-
|
|
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)};
|
|
901
949
|
|
|
902
|
-
let _updateConfig;
|
|
903
950
|
if (import.meta.hot) {
|
|
904
951
|
// Accept self updates
|
|
905
952
|
import.meta.hot.accept((newModule) => {
|
|
906
|
-
if (newModule &&
|
|
907
|
-
|
|
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
|
+
});
|
|
908
963
|
}
|
|
909
964
|
});
|
|
910
965
|
}
|
|
911
966
|
|
|
912
|
-
export default new Proxy(
|
|
967
|
+
export default new Proxy({}, {
|
|
913
968
|
get(target, prop) {
|
|
914
969
|
if (prop === 'then') return undefined;
|
|
915
|
-
if (prop === '
|
|
916
|
-
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
|
+
};
|
|
917
980
|
}
|
|
918
|
-
|
|
981
|
+
// Always read from the global current config
|
|
982
|
+
return window.__tailwindConfigCurrent[prop];
|
|
919
983
|
}
|
|
920
984
|
});
|
|
921
|
-
|
|
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=`
|
|
922
986
|
<script data-taro-flexible="true">
|
|
923
987
|
(function() {
|
|
924
|
-
var designWidth = ${
|
|
925
|
-
var maxWidth = ${
|
|
926
|
-
var baseFontSize = ${
|
|
927
|
-
var minRootSize = ${
|
|
928
|
-
var maxRootSize = ${
|
|
988
|
+
var designWidth = ${n};
|
|
989
|
+
var maxWidth = ${e};
|
|
990
|
+
var baseFontSize = ${t};
|
|
991
|
+
var minRootSize = ${o};
|
|
992
|
+
var maxRootSize = ${l};
|
|
929
993
|
|
|
930
994
|
function setRootFontSize() {
|
|
931
995
|
var docEl = document.documentElement;
|
|
@@ -959,7 +1023,7 @@ export default new Proxy(config, {
|
|
|
959
1023
|
document.addEventListener('DOMContentLoaded', setRootFontSize);
|
|
960
1024
|
})();
|
|
961
1025
|
</script>
|
|
962
|
-
`;return
|
|
1026
|
+
`;return i.replace("</head>",`${u}
|
|
963
1027
|
<style data-taro-adapter="true">
|
|
964
1028
|
/* \u4EC5 H5 \u751F\u6548\uFF1A\u9690\u85CF Taro \u9875\u9762\u5BB9\u5668\u6EDA\u52A8\u6761\uFF0C\u4F46\u4ECD\u53EF\u6EDA\u52A8 */
|
|
965
1029
|
.taro_page {
|
|
@@ -1005,5 +1069,5 @@ export default new Proxy(config, {
|
|
|
1005
1069
|
object-fit: contain;
|
|
1006
1070
|
}
|
|
1007
1071
|
</style>
|
|
1008
|
-
</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
|
|
1009
1073
|
//# sourceMappingURL=index.cjs.map
|