@amaster.ai/vite-plugins 1.1.67-beta.0 → 1.1.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -0
- package/dist/index.cjs +76 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +76 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -152,3 +152,43 @@ This includes:
|
|
|
152
152
|
## License
|
|
153
153
|
|
|
154
154
|
MIT
|
|
155
|
+
|
|
156
|
+
## React development startup states
|
|
157
|
+
|
|
158
|
+
`devTools()` automatically includes `startupPlugin()` for non-Taro development servers.
|
|
159
|
+
No changes to the application entry point or components are required.
|
|
160
|
+
|
|
161
|
+
- A self-contained Helige loading screen appears only when the first render takes
|
|
162
|
+
longer than 300 ms. It uses inline CSS and no downloaded assets.
|
|
163
|
+
- The first React commit under `#root` removes the screen and reports readiness to
|
|
164
|
+
the Vite server. Subsequent HTML requests, including other browsers, skip the
|
|
165
|
+
screen. This state belongs to the Vite process and resets when Vite restarts.
|
|
166
|
+
- A default-exported, unmodified empty array in `src/routes.tsx` identifies the
|
|
167
|
+
blank template. It displays “正在生成你的应用” until routes are added. Changing
|
|
168
|
+
between empty and populated routes reloads the page; successful React mounting
|
|
169
|
+
then removes loading. This is a template convention, not an AI job-status API.
|
|
170
|
+
- Syntax errors, runtime failures, and Vite error events dismiss the screen so
|
|
171
|
+
diagnostics remain visible. A stalled cold start offers a retry after 60 seconds.
|
|
172
|
+
- Styles use a Shadow DOM, support small screens and reduced motion, and do not
|
|
173
|
+
depend on application CSS. Production builds and Taro are unaffected.
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
import devTools from '@amaster.ai/vite-plugins'
|
|
177
|
+
|
|
178
|
+
export default defineConfig({
|
|
179
|
+
plugins: [react(), ...devTools({
|
|
180
|
+
startup: {
|
|
181
|
+
delayMs: 300,
|
|
182
|
+
routesFile: 'src/routes.tsx',
|
|
183
|
+
placeholder: true,
|
|
184
|
+
},
|
|
185
|
+
})],
|
|
186
|
+
})
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Set `startup: false` to disable both states, or `startup: { placeholder: false }`
|
|
190
|
+
to retain only cold-start loading. Automatic readiness supports React 18+ apps
|
|
191
|
+
using static `react-dom/client` imports and mounting with `createRoot` or
|
|
192
|
+
`hydrateRoot` on `#root`. Other entry-point conventions should disable this feature.
|
|
193
|
+
Readiness means React has committed a UI (including Suspense fallbacks), not that
|
|
194
|
+
all application data or lazy routes have finished loading.
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,73 @@
|
|
|
1
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var
|
|
2
|
-
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var crypto=require('crypto'),S=require('fs'),h=require('path'),X=require('@babel/generator'),parser=require('@babel/parser'),g=require('@babel/types'),url=require('url'),M=require('process'),O=require('fs/promises'),ne=require('@babel/traverse'),traceMapping=require('@jridgewell/trace-mapping'),module$1=require('module');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var S__default=/*#__PURE__*/_interopDefault(S);var h__default=/*#__PURE__*/_interopDefault(h);var X__default=/*#__PURE__*/_interopDefault(X);var g__namespace=/*#__PURE__*/_interopNamespace(g);var M__default=/*#__PURE__*/_interopDefault(M);var O__default=/*#__PURE__*/_interopDefault(O);var ne__default=/*#__PURE__*/_interopDefault(ne);function B(e){let r=window,t=document.createElement("div");t.id="amaster-dev-startup",t.style.cssText="position:fixed;inset:0;z-index:2147483000;display:none;";let n=t.attachShadow({mode:"open"}),o=document.createElement("style");o.textContent=e.css,n.appendChild(o);let a=document.createElement("div");a.id="vpss",a.innerHTML=e.markup,n.appendChild(a),document.documentElement.appendChild(t);let u=false,d=0,c=0,i,l=setTimeout(()=>{u||(t.style.display="block");},e.generating?0:e.delayMs),s=setTimeout(()=>{!u&&!e.generating&&(a.innerHTML='<div class="hl-loading" role="alert"><div class="hl-title">\u5E94\u7528\u52A0\u8F7D\u65F6\u95F4\u8F83\u957F</div><p class="hl-caption">\u53EF\u4EE5\u5237\u65B0\u91CD\u8BD5\uFF0C\u6216\u67E5\u770B\u9884\u89C8\u4E2D\u7684\u9519\u8BEF\u4FE1\u606F</p><button type="button">\u91CD\u65B0\u52A0\u8F7D</button></div>',a.querySelector("button")?.addEventListener("click",()=>location.reload()),t.style.display="block");},6e4);function p(){u=true,clearTimeout(l),clearTimeout(s),cancelAnimationFrame(d),window.removeEventListener("error",y,true),window.removeEventListener("unhandledrejection",f),t.remove();}function f(){p(),clearTimeout(i);}function y(v){(v instanceof ErrorEvent||v.target instanceof HTMLScriptElement)&&f();}function m(){c++,fetch(e.readyUrl,{method:"POST",credentials:"same-origin",keepalive:true}).then(v=>{!v.ok&&v.status!==409&&c<3&&(i=setTimeout(m,1e3));}).catch(()=>{c<3&&(i=setTimeout(m,1e3));});}function H(){u||e.generating||d||(d=requestAnimationFrame(()=>{p(),m();}));}r.__AMASTER_STARTUP__={mounted:H,failed:f},window.addEventListener("error",y,true),window.addEventListener("unhandledrejection",f),window.addEventListener("pagehide",()=>{p(),clearTimeout(i);},{once:true});}function F(e){try{let t=parser.parse(e,{sourceType:"module",plugins:["typescript","jsx"]}),n=t.program.body.find(a=>g__namespace.isExportDefaultDeclaration(a));if(!n||!g__namespace.isExportDefaultDeclaration(n))return !1;let o=n.declaration;if(g__namespace.isIdentifier(o)){let c=function(i){g__namespace.isIdentifier(i,{name:a})&&d++;for(let l of g__namespace.VISITOR_KEYS[i.type]||[]){let s=i[l];Array.isArray(s)?s.forEach(p=>{p?.type&&c(p);}):s&&typeof s=="object"&&"type"in s&&c(s);}};var r=c;let a=o.name,u=t.program.body.flatMap(i=>g__namespace.isVariableDeclaration(i)&&i.kind==="const"?i.declarations:[]).find(i=>g__namespace.isIdentifier(i.id,{name:a}));if(!u?.init)return !1;let d=0;if(c(t.program),d!==2)return !1;o=u.init;}for(;g__namespace.isTSAsExpression(o)||g__namespace.isTSSatisfiesExpression(o);)o=o.expression;return g__namespace.isArrayExpression(o)&&o.elements.length===0}catch{return false}}var U=`
|
|
2
|
+
import * as client from 'react-dom/client';
|
|
3
|
+
import { createElement, useEffect } from 'react';
|
|
4
|
+
export * from 'react-dom/client';
|
|
5
|
+
function StartupCommit({children}) {
|
|
6
|
+
useEffect(() => { window.__AMASTER_STARTUP__?.mounted(); });
|
|
7
|
+
return children;
|
|
8
|
+
}
|
|
9
|
+
function wrapRoot(root) {
|
|
10
|
+
const render = root.render.bind(root);
|
|
11
|
+
root.render = (children) => render(createElement(StartupCommit, null, children));
|
|
12
|
+
return root;
|
|
13
|
+
}
|
|
14
|
+
export function createRoot(container, options) {
|
|
15
|
+
const root = client.createRoot(container, options);
|
|
16
|
+
return container?.id === 'root' ? wrapRoot(root) : root;
|
|
17
|
+
}
|
|
18
|
+
export function hydrateRoot(container, children, options) {
|
|
19
|
+
const content = container?.id === 'root' ? createElement(StartupCommit, null, children) : children;
|
|
20
|
+
const root = client.hydrateRoot(container, content, options);
|
|
21
|
+
return container?.id === 'root' ? wrapRoot(root) : root;
|
|
22
|
+
}
|
|
23
|
+
export default { ...client, createRoot, hydrateRoot };
|
|
24
|
+
if (import.meta.hot) {
|
|
25
|
+
import.meta.hot.on('vite:error', () => window.__AMASTER_STARTUP__?.failed());
|
|
26
|
+
}
|
|
27
|
+
`;var q=`
|
|
28
|
+
<div class="hl-loading" role="status" aria-live="polite">
|
|
29
|
+
<div class="hl-orbit" aria-hidden="true"><i></i><i></i><i></i><span class="hl-core"></span></div>
|
|
30
|
+
<div class="hl-title">\u8BA9\u60F3\u6CD5\uFF0C\u5373\u523B\u5448\u73B0</div>
|
|
31
|
+
<div class="hl-caption">\u6B63\u5728\u51C6\u5907\u4F60\u7684\u5E94\u7528</div>
|
|
32
|
+
<div class="hl-footnote">\u6CB3\u72F8\u54E5 \xB7 \u628A\u60F3\u6CD5\u53D8\u6210\u5E94\u7528</div>
|
|
33
|
+
</div>`,z='<section class="scene" role="status" aria-live="polite"><div class="canvas" aria-hidden="true"><div class="window"><div class="chrome"><i></i><i></i><i></i><div class="address"></div></div><div class="layout"><div class="sidebar"><i></i><i></i><i></i><i></i></div><div class="content"><div class="line"></div><div class="line short"></div><div class="tiles"><div class="tile"></div><div class="tile"></div><div class="tile"></div></div><div class="rows"><i></i><i></i><i></i></div></div></div></div><div class="spark"></div></div><h1>\u6B63\u5728\u751F\u6210\u4F60\u7684\u5E94\u7528</h1><p class="caption">\u8BA9\u60F3\u6CD5\uFF0C\u4E00\u70B9\u70B9\u6210\u4E3A\u73B0\u5B9E<br>\u9875\u9762\u51C6\u5907\u597D\u540E\uFF0C\u4F1A\u81EA\u52A8\u663E\u793A\u5728\u8FD9\u91CC</p></section>',J=`
|
|
34
|
+
#vpss { background: #fafaff; background: radial-gradient(ellipse at 50% 44%, #f0eeff 0%, #fafaff 48%, #fff 100%); font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif; color:#29283b; }
|
|
35
|
+
#vpss .hl-loading { text-align:center; padding:32px 24px; width:min(100%,420px); box-sizing:border-box; }
|
|
36
|
+
#vpss .hl-orbit { position:relative; width:144px; height:144px; margin:30px auto 22px; }
|
|
37
|
+
#vpss .hl-orbit i { position:absolute; inset:0; border:1px solid rgba(125,105,211,.3); border-radius:50%; opacity:0; animation:hl-ripple 3.6s cubic-bezier(.2,.5,.3,1) infinite; }
|
|
38
|
+
#vpss .hl-orbit i:nth-child(2){animation-delay:1.2s} #vpss .hl-orbit i:nth-child(3){animation-delay:2.4s}
|
|
39
|
+
#vpss .hl-core { position:absolute; width:38px; height:38px; left:53px; top:53px; border-radius:14px; transform:rotate(-12deg); background:linear-gradient(140deg,#8d9aef,#7961c5); box-shadow:0 0 0 9px rgba(137,120,222,.07),0 8px 30px rgba(117,94,196,.22); animation:hl-breathe 3.6s ease-in-out infinite; }
|
|
40
|
+
#vpss .hl-core:after {content:"";position:absolute;inset:10px;border:1px solid rgba(255,255,255,.72);border-radius:5px;}
|
|
41
|
+
#vpss .hl-title { font-size:21px; font-weight:500; line-height:1.6; letter-spacing:1px; }
|
|
42
|
+
#vpss .hl-caption { font-size:13px; color:#817c93; margin-top:9px; letter-spacing:.4px; }
|
|
43
|
+
#vpss .hl-footnote { font-size:11px; color:#9792a6; margin-top:52px; letter-spacing:1px; }
|
|
44
|
+
@keyframes hl-ripple {0%{transform:scale(.3);opacity:0}15%{opacity:.7}100%{transform:scale(1);opacity:0}}
|
|
45
|
+
@keyframes hl-breathe {0%,100%{transform:rotate(-12deg) scale(.96)}50%{transform:rotate(-6deg) scale(1.04)}}
|
|
46
|
+
@media(prefers-reduced-motion:reduce){#vpss .hl-orbit i,#vpss .hl-core{animation:none}#vpss .hl-orbit i:first-child{opacity:.3;transform:scale(.75)}}
|
|
47
|
+
@media(max-height:480px){#vpss .hl-orbit{margin:12px auto}#vpss .hl-footnote{margin-top:18px}}
|
|
48
|
+
|
|
49
|
+
#vpss{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;overflow:auto;padding:24px;}
|
|
50
|
+
#vpss button{font:inherit;padding:8px 14px;border:1px solid #ded9ec;border-radius:8px;background:#fff;color:#514768;cursor:pointer;}
|
|
51
|
+
|
|
52
|
+
*{box-sizing:border-box}
|
|
53
|
+
|
|
54
|
+
.scene{width:440px;max-width:100%;text-align:center}
|
|
55
|
+
.canvas{width:294px;height:188px;max-width:100%;margin:0 auto 43px;position:relative;perspective:800px}
|
|
56
|
+
.window{position:absolute;inset:0;border-radius:13px;background:rgba(255,255,255,.92);border:1px solid rgba(157,144,198,.23);box-shadow:0 16px 48px -18px rgba(95,77,155,.28);overflow:hidden;transform:rotate(-3deg);animation:float 5s ease-in-out infinite}
|
|
57
|
+
.chrome{height:27px;display:flex;align-items:center;gap:4px;padding:0 11px;border-bottom:1px solid #eeebf5;background:#fcfbff}.chrome i{width:4px;height:4px;border-radius:50%;background:#dcd6ea}.address{height:5px;width:67px;border-radius:3px;background:#eae6f2;margin-left:9px}
|
|
58
|
+
.layout{height:calc(100% - 27px);display:flex}.sidebar{width:48px;border-right:1px solid #f0edf6;padding:15px 9px}.sidebar i{display:block;height:4px;background:#e6e1f1;margin:0 0 10px;border-radius:2px}.sidebar i:first-child{background:#beb1e6}.content{flex:1;padding:17px 16px;text-align:left}.line{height:6px;border-radius:3px;background:#e8e3f2;width:51%;margin-bottom:9px}.line.short{height:4px;width:72%;background:#f0edf7;margin-bottom:17px}.tiles{display:flex;gap:7px}.tile{flex:1;height:40px;border-radius:5px;background:#f0ecfb;animation:materialize 4s ease-in-out infinite}.tile:nth-child(2){animation-delay:.4s;background:#eeedf9}.tile:nth-child(3){animation-delay:.8s;background:#f2effa}.rows{margin-top:14px}.rows i{display:block;height:4px;background:#eeebf5;border-radius:2px;margin:0 0 8px}.rows i:last-child{width:63%}
|
|
59
|
+
.spark{position:absolute;right:-10px;bottom:13px;width:42px;height:42px;border-radius:13px;background:linear-gradient(145deg,#9d9cec,#8270c7);box-shadow:0 6px 19px rgba(115,94,186,.18);display:grid;place-items:center;transform:rotate(6deg);animation:spark-breathe 4s ease-in-out infinite}.spark:before{content:"";width:19px;height:19px;background:#fff;clip-path:polygon(50% 0,62% 37%,100% 50%,62% 63%,50% 100%,38% 63%,0 50%,38% 37%);opacity:.9}
|
|
60
|
+
h1{font-size:23px;font-weight:500;letter-spacing:.5px;margin:0 0 13px;line-height:1.5}.caption{font-size:14px;line-height:1.9;color:#827b95;margin:0}
|
|
61
|
+
@keyframes float{0%,100%{transform:translateY(0) rotate(-3deg)}50%{transform:translateY(-5px) rotate(-2deg)}}@keyframes materialize{0%,100%{opacity:.45;transform:translateY(2px)}45%,65%{opacity:1;transform:translateY(0)}}@keyframes spark-breathe{0%,100%{transform:rotate(6deg) scale(.97)}50%{transform:rotate(0) scale(1.03)}}
|
|
62
|
+
@media(prefers-reduced-motion:reduce){*{animation:none!important}}@media(max-width:360px){.canvas{width:250px;height:165px}.spark{right:-4px}h1{font-size:21px}}@media(max-height:450px){.canvas{margin-bottom:22px;height:145px;width:240px}}
|
|
63
|
+
`;var he=X__default.default.default??X__default.default,R="virtual:amaster-startup/react-dom-client",$="\0"+R,K="__amaster_dev__/startup/ready";function T(e={}){let r=Number.isFinite(e.delayMs)?Math.max(0,e.delayMs):300,t="",n="",o="",a=false,u="",d=false,c=()=>{if(e.placeholder===false)return false;try{return F(S.readFileSync(n,"utf8"))}catch{return false}};return {name:"amaster-dev-startup",apply:"serve",enforce:"pre",configResolved(i){t=i.root,n=h__default.default.resolve(t,e.routesFile||"src/routes.tsx"),o=(i.base.startsWith("/")?i.base:new URL(i.base).pathname).replace(/\/?$/,"/")+K;},configureServer(i){a=false,u=crypto.randomUUID(),d=c(),i.watcher.add(n),i.middlewares.use((l,s,p)=>{let f=new URL(l.url||"/","http://vite.local");if(f.pathname!==o)return l.headers.accept?.includes("text/html")&&s.setHeader("Cache-Control","no-store"),p();s.setHeader("Cache-Control","no-store"),l.method!=="POST"?(s.statusCode=405,s.setHeader("Allow","POST")):f.searchParams.get("boot")!==u||c()?s.statusCode=409:(a=true,s.statusCode=204),s.end();});},resolveId(i){if(i===R)return $},load(i){if(i===$)return U},transform(i,l,s){let p=l.split("?")[0];if(!(s?.ssr||p.includes("node_modules")||!p.startsWith(t+"/")||!/\.[cm]?[jt]sx?$/.test(p)||!i.includes("react-dom/client")))try{let f=parser.parse(i,{sourceType:"module",plugins:["jsx","typescript"]}),y=f.program.body.filter(m=>m.type==="ImportDeclaration"&&m.source.value==="react-dom/client");if(!y.length)return;for(let m of y)m.type==="ImportDeclaration"&&(m.source.value=R);return he(f,{sourceMaps:!0,sourceFileName:l,retainLines:!0},i)}catch{}},handleHotUpdate(i){if(h__default.default.resolve(i.file)!==n)return;let l=c();if(l!==d)return d=l,u=crypto.randomUUID(),a=false,i.server.ws.send({type:"full-reload"}),[]},transformIndexHtml(i){let l=c();if(a&&!l)return i;let s=JSON.stringify({generating:l,delayMs:r,readyUrl:o+"?boot="+u,css:J,markup:l?z:q}).replace(/</g,"\\u003c");return [{tag:"script",children:`(${B.toString()})(${s});`.replace(/[\u0080-\uffff]/g,p=>"\\u"+p.charCodeAt(0).toString(16).padStart(4,"0")),injectTo:"head"},{tag:"script",attrs:{type:"module"},children:`import { createHotContext } from ${JSON.stringify(o.replace(K,"@vite/client"))}; createHotContext("/__amaster_dev__/startup").on("vite:error", () => window.__AMASTER_STARTUP__?.failed());`,injectTo:"head"}]}}}var we=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))),_e=h.dirname(we),G="@amaster/bridge-monitor",Y="\0"+G,x=null;function Ee(){if(x)return x;try{let e=h.resolve(_e,"../dist/bridge-module.global.js");return x=S.readFileSync(e,"utf-8"),x}catch(e){return console.warn("[editor-bridge] Failed to load pre-built bridge module:",e),""}}function Re(){return '<script type="module" src="/@id/@amaster/bridge-monitor"></script>'}function Te(e){return Ee().replace(/__SESSION_KEY__/g,e)+`
|
|
64
|
+
export default {};`}function Q(){let e=false;return {name:"vite-plugin-editor-bridge",configResolved(r){e=r.command==="serve";},resolveId(r){if(r===G)return Y},load(r){if(r===Y){let t=process.env.VITE_AMASTER_KEY||"";return Te(t)}},transformIndexHtml(r){if(!e)return r;let t=Re();return r.replace("</body>",`${t}</body>`)}}}function Z(e){let r=false,t=e?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(n){r=n.command==="serve";},transform(n,o){if(!r||!o.endsWith(t))return null;try{return n.includes("window.__APP_ROUTES__")?null:{code:`${n}
|
|
3
65
|
|
|
4
66
|
// Development mode: Expose routes to window.__APP_ROUTES__
|
|
5
67
|
if (typeof window !== 'undefined') {
|
|
6
68
|
window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];
|
|
7
69
|
}
|
|
8
|
-
`,map:null}}catch{return null}}}}function
|
|
70
|
+
`,map:null}}catch{return null}}}}function te(){let e="",r=`
|
|
9
71
|
<script>
|
|
10
72
|
(function() {
|
|
11
73
|
'use strict';
|
|
@@ -812,9 +874,9 @@ if (typeof window !== 'undefined') {
|
|
|
812
874
|
|
|
813
875
|
originalConsole.log('[BrowserLogs] Log collection started');
|
|
814
876
|
})();
|
|
815
|
-
</script>`;return {name:"vite-plugin-browser-logs",configResolved(
|
|
816
|
-
`):
|
|
817
|
-
`,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":
|
|
877
|
+
</script>`;return {name:"vite-plugin-browser-logs",configResolved(t){let n=M__default.default.env.WORKSPACE_DIR;if(n)e=h__default.default.join(n,"browser.log");else {let o=t.root||M__default.default.cwd();for(;o!==h__default.default.dirname(o)&&!S__default.default.existsSync(h__default.default.join(o,"package.json"));)o=h__default.default.dirname(o);e=h__default.default.join(o,"browser.log");}},configureServer(t){t.middlewares.use((n,o,a)=>{if(n.url==="/__browser__"&&n.method==="POST"){let u=n.headers.origin||"*",d="";n.on("data",c=>{d+=c.toString();}),n.on("end",()=>{try{let c=d,i;try{i=JSON.parse(d);}catch{i=null;}Array.isArray(i)?c=i.map(s=>JSON.stringify(s)).join(`
|
|
878
|
+
`):i&&typeof i=="object"&&(c=JSON.stringify(i));let l=h__default.default.dirname(e);S__default.default.existsSync(l)||S__default.default.mkdirSync(l,{recursive:!0}),S__default.default.appendFileSync(e,`${c}
|
|
879
|
+
`,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":u,"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":u,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:false,error:String(c)}));}});}else if(n.url==="/__browser__"&&n.method==="OPTIONS"){let u=n.headers.origin||"*";o.writeHead(204,{"Access-Control-Allow-Origin":u,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Max-Age":"86400"}),o.end();}else if(n.url==="/__browser__"){let u=n.headers.origin||"*";o.writeHead(405,{"Content-Type":"application/json","Access-Control-Allow-Origin":u}),o.end(JSON.stringify({error:"Method not allowed"}));}else a();}),console.log("[BrowserLogs] Logs will be written to:",e);},transformIndexHtml(t){return t.replace(/<head([^>]*)>/i,`<head$1>${r}`)}}}var Pe=`
|
|
818
880
|
import * as React from "react";
|
|
819
881
|
import * as ReactJSXDevRuntime from "react/jsx-dev-runtime";
|
|
820
882
|
|
|
@@ -996,7 +1058,7 @@ export function jsxDEV(type, props, key, isStatic, source, self) {
|
|
|
996
1058
|
|
|
997
1059
|
return _jsxDEV(type, props, key, isStatic, source, self);
|
|
998
1060
|
}
|
|
999
|
-
`;function
|
|
1061
|
+
`;function P(e={}){let r=false,t="";return {name:"vite-plugin-jsx-source-tagger",enforce:"pre",configResolved(n){r=n.command==="serve",t=e.projectRoot||n.root;},resolveId(n,o){return r&&n==="react/jsx-dev-runtime"&&!o?.includes("\0jsx-source")?"\0jsx-source/jsx-dev-runtime":null},load(n){return r&&n==="\0jsx-source/jsx-dev-runtime"?Pe.replace('const PROJECT_ROOT = "";',`const PROJECT_ROOT = ${JSON.stringify(t)};`):null}}}function A(e){let r="",t=false,n=null,o=null,a=e?.configPath||"./tailwind.config.ts",u="@amaster/tailwind-config",d="\0"+u,c=async()=>{let l=h__default.default.resolve(r,a);try{return await O__default.default.access(l),l}catch{if(a.endsWith(".ts")){let s=l.replace(/\.ts$/,".js");try{return await O__default.default.access(s),s}catch{return null}}else if(a.endsWith(".js")){let s=l.replace(/\.js$/,".ts");try{return await O__default.default.access(s),s}catch{return null}}return null}},i=async l=>{try{let s=await c();if(!s)return null;if(l){let m=await l.ssrLoadModule(s);return n=m.default||m,n}let f=await import(`file://${s}?t=${Date.now()}`);return n=f.default||f,n}catch(s){return console.error("[tailwind-config-sync] Failed to generate config:",s),null}};return {name:"vite-plugin-tailwind-config-sync",configResolved(l){r=l.root,t=l.command==="serve";},async buildStart(){t&&await i();},resolveId(l){if(l===u)return d},async load(l){if(l===d)return await i(o),n?`
|
|
1000
1062
|
// Use global variable to persist callbacks and current config across HMR updates
|
|
1001
1063
|
if (!window.__tailwindConfigCallbacks) {
|
|
1002
1064
|
window.__tailwindConfigCallbacks = [];
|
|
@@ -1033,14 +1095,14 @@ export function onUpdate(fn) {
|
|
|
1033
1095
|
};
|
|
1034
1096
|
export default tailwindConfigCurrent;
|
|
1035
1097
|
|
|
1036
|
-
`:"export default null;"},configureServer(
|
|
1098
|
+
`:"export default null;"},configureServer(l){t&&(o=l,(async()=>{try{let s=await c();s&&l.watcher.add(s);}catch{}})());},async handleHotUpdate({file:l,server:s}){let p=await c();if(!p||h__default.default.normalize(l)!==h__default.default.normalize(p))return;let f=s.moduleGraph.getModuleById(p);f&&s.moduleGraph.invalidateModule(f),await i(s);let y=s.moduleGraph.getModuleById(d);return y?(s.moduleGraph.invalidateModule(y),[y]):[]}}}function k(e={}){let{designWidth:r=375,maxWidth:t=750,baseFontSize:n=12,minRootSize:o=12,maxRootSize:a=24}=e;return {name:"vite-plugin-taro-style-adapter",apply:"serve",transformIndexHtml(u){let d=`
|
|
1037
1099
|
<script data-taro-flexible="true">
|
|
1038
1100
|
(function() {
|
|
1039
|
-
var designWidth = ${
|
|
1040
|
-
var maxWidth = ${
|
|
1101
|
+
var designWidth = ${r};
|
|
1102
|
+
var maxWidth = ${t};
|
|
1041
1103
|
var baseFontSize = ${n};
|
|
1042
1104
|
var minRootSize = ${o};
|
|
1043
|
-
var maxRootSize = ${
|
|
1105
|
+
var maxRootSize = ${a};
|
|
1044
1106
|
|
|
1045
1107
|
function setRootFontSize() {
|
|
1046
1108
|
var docEl = document.documentElement;
|
|
@@ -1074,7 +1136,7 @@ export default tailwindConfigCurrent;
|
|
|
1074
1136
|
document.addEventListener('DOMContentLoaded', setRootFontSize);
|
|
1075
1137
|
})();
|
|
1076
1138
|
</script>
|
|
1077
|
-
`;return
|
|
1139
|
+
`;return u.replace("</head>",`${d}
|
|
1078
1140
|
<style data-taro-adapter="true">
|
|
1079
1141
|
/* \u4EC5 H5 \u751F\u6548\uFF1A\u9690\u85CF Taro \u9875\u9762\u5BB9\u5668\u6EDA\u52A8\u6761\uFF0C\u4F46\u4ECD\u53EF\u6EDA\u52A8 */
|
|
1080
1142
|
.taro_page {
|
|
@@ -1120,6 +1182,6 @@ export default tailwindConfigCurrent;
|
|
|
1120
1182
|
object-fit: contain;
|
|
1121
1183
|
}
|
|
1122
1184
|
</style>
|
|
1123
|
-
</head>`)}}}function
|
|
1124
|
-
exports.default=
|
|
1185
|
+
</head>`)}}}function w(e={}){let{ratio:r=2}=e;return {postcssPlugin:"postcss-rpx2px",Declaration(t){t.value?.includes("rpx")&&(t.value=t.value.replace(/(-?\d*\.?\d+)rpx/gi,(n,o)=>{let a=parseFloat(o)/r;return a===0?"0":`${a}px`}));}}}w.postcss=true;var Ce=/(-?\d*\.?\d+)rpx/gi,Ae=X__default.default.default??X__default.default,ke=ne__default.default.default??ne__default.default;function I(e,r){return e.replace(Ce,(t,n)=>{let o=Number.parseFloat(n)/r;return o===0?"0":`${o}px`})}function Ie(e,r){if(!e.value.includes("rpx"))return false;let t=I(e.value,r);return t===e.value?false:(e.value=t,e.extra?.raw&&(e.extra.rawValue=t,e.extra.raw=JSON.stringify(t)),true)}function je(e,r){let t=e.value.raw;if(!t.includes("rpx"))return false;let n=I(t,r),o=e.value.cooked==null?void 0:I(e.value.cooked,r);return n===t&&o===e.value.cooked?false:(e.value.raw=n,e.value.cooked=o,true)}function Le(e){return e.name.type==="JSXIdentifier"&&e.name.name==="style"}function Ne(e,r){let t=false;return e.traverse({StringLiteral(n){Ie(n.node,r)&&(t=true);},TemplateElement(n){je(n.node,r)&&(t=true);}}),t}function oe(e,r=2){let t=parser.parse(e,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:true}),n=false;return ke(t,{JSXAttribute(o){if(!Le(o.node)||o.node.value?.type!=="JSXExpressionContainer")return;let a=o.get("value");a.isJSXExpressionContainer()&&Ne(a,r)&&(n=true);}}),n?{changed:true,code:Ae(t,{retainLines:true,decoratorsBeforeExport:true,jsescOption:{minimal:true}},e).code}:{changed:false,code:e}}function j(e={}){let{ratio:r=2}=e;return {name:"vite-plugin-jsx-inline-style-rpx",enforce:"pre",transform(t,n){if(process.env.TARO_ENV!=="h5"||!/\.[jt]sx($|\?)/.test(n))return null;let o=oe(t,r);return o.changed?{code:o.code,map:null}:null}}}function L(){return {name:"vite-plugin-taro-jsx-dev-source",apply:"serve",enforce:"post",config(e){let r=typeof e.esbuild=="object"&&e.esbuild?e.esbuild:{};e.esbuild={...r,jsxDev:true};}}}var Be=ne__default.default.default??ne__default.default;function Fe(e){return e.split("?",1)[0]||e}function Ue(e){let r=Fe(e);return /\.[cm]?[jt]sx$/.test(r)&&!r.includes("/node_modules/")}function ae(e){let r=e.key;return r.type==="Identifier"?r.name:r.type==="StringLiteral"?r.value:""}function b(e,r){return e.properties.find(t=>t.type==="ObjectProperty"&&ae(t)===r)}function _(e){return e?.value.type==="NumericLiteral"}function qe(e){return e?.value.type==="StringLiteral"}function ze(e){return e.type==="Identifier"&&e.name==="jsxDEV"}function Je(e){return ae(e)==="children"}function We(e){let r=e.arguments[1];if(r?.type==="ObjectExpression"){let t=r.properties.find(n=>n.type==="ObjectProperty"&&!Je(n));if(t)return t.value}return e.callee}function Ve(e){return e.type!=="ObjectExpression"?false:qe(b(e,"fileName"))&&_(b(e,"lineNumber"))&&_(b(e,"columnNumber"))}function se(e,r,t){r.value===t||r.start==null||r.end==null||e.push({start:r.start,end:r.end,value:String(t)});}function Xe(e,r){return r.sort((t,n)=>n.start-t.start).reduce((t,n)=>t.slice(0,n.start)+n.value+t.slice(n.end),e)}function le(e,r){if(!r||!e.includes("jsxDEV"))return null;let t=new traceMapping.TraceMap(r),n=[],o;try{o=parser.parse(e,{sourceType:"module",plugins:["jsx","typescript"]});}catch{return null}return Be(o,{CallExpression(a){let u=a.node;if(!ze(u.callee))return;let d=u.arguments[4];if(!d||d.type==="SpreadElement"||d.type==="ArgumentPlaceholder"||!Ve(d))return;let c=We(u);if(!c.loc)return;let i=traceMapping.originalPositionFor(t,{line:c.loc.start.line,column:c.loc.start.column});if(i.line==null||i.column==null)return;let l=b(d,"lineNumber"),s=b(d,"columnNumber");!_(l)||!_(s)||(se(n,l.value,i.line),se(n,s.value,i.column+1));}}),n.length===0?null:Xe(e,n)}function N(){let e=false;return {name:"vite-plugin-jsx-source-map-remap",enforce:"post",configResolved(r){e=r.command==="serve";},transform(r,t){if(!e||!Ue(t))return null;let n=this.getCombinedSourcemap;if(typeof n!="function")return null;let o=n.call(this);if(!o||!o.mappings)return null;let a=le(r,o);return a?{code:a,map:o}:null}}}var Ye="src/app.config.ts",Ge=module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))),{parse:Qe}=Ge("@babel/parser");function D(){let e=new Set;return {name:"amaster-taro-h5-history-fallback",apply:"serve",configureServer(r){e.size===0&&(e=rt()),e.size!==0&&r.middlewares.use((t,n,o)=>{let a=Ze(t,e);if(!a){o();return}n.statusCode=302,n.setHeader("Location",a),n.end();});}}}function Ze(e,r){let t=(e.method||"GET").toUpperCase();if(t!=="GET"&&t!=="HEAD")return null;let n=at(e.url||"/");if(!n||!st(e.headers||{}))return null;let o=fe(n.pathname);return r.has(o)?lt(o,n.search):null}function et(e,r="app.config.ts"){let n=Qe(e,{sourceType:"module",sourceFilename:r,plugins:["typescript","jsx"]}).program,o=Array.isArray(n.body)?n.body:[],a=new Map;for(let c of o){if(c.type!=="VariableDeclaration")continue;let i=Array.isArray(c.declarations)?c.declarations:[];for(let l of i){let s=l.id,p=l.init;if(!E(s)||!de(p))continue;let f=ce(p);f&&a.set(s.name,f);}}let u=[],d=tt(o);if(d){let c=ot(d,"pages");if(de(c))return u=ce(c)||[],u;if(E(c)){let i=c.name;u=a.get(typeof i=="string"?i:"")||[];}}return u}function tt(e){for(let r of e){if(r.type!=="ExportDefaultDeclaration")continue;let t=r.declaration;if(t?.type==="ObjectExpression")return t;if(t?.type!=="CallExpression")return null;let n=t.callee;if(!E(n,"defineAppConfig"))return null;let a=(Array.isArray(t.arguments)?t.arguments:[])[0];return it(a)?a:null}return null}function rt(){let e=h__default.default.resolve(process.cwd(),Ye);if(!S__default.default.existsSync(e))return new Set;let r=S__default.default.readFileSync(e,"utf8");return nt(et(r,e))}function nt(e){return new Set((e||[]).map(fe).filter(Boolean))}function fe(e){return e.trim().replace(/^\/+/,"").replace(/\/+$/,"")}function ce(e){let r=[],t=Array.isArray(e.elements)?e.elements:[];for(let n of t){if(!n||n.type!=="StringLiteral")return null;r.push(n.value);}return r}function ot(e,r){let t=Array.isArray(e.properties)?e.properties:[];for(let n of t){if(n.type!=="ObjectProperty")continue;let o=n.key;if(E(o)&&o.name===r||o?.type==="StringLiteral"&&o.value===r)return n.value||null}return null}function E(e,r){return e?.type==="Identifier"&&(r?e.name===r:true)}function de(e){return e?.type==="ArrayExpression"}function it(e){return e?.type==="ObjectExpression"}function st(e){let r=pe(e,"sec-fetch-dest");if(r&&r!=="document"&&r!=="iframe")return false;let t=pe(e,"accept");return t?t.includes("text/html")||t.includes("application/xhtml+xml"):true}function pe(e,r){let t=e[r]||e[r.toLowerCase()]||e[r.toUpperCase()];return Array.isArray(t)?t.join(","):t||""}function at(e){try{let r=new URL(e,"http://amaster.local");return r.pathname=decodeURIComponent(r.pathname),r}catch{return null}}function lt(e,r){return `/#${`/${e}${r||""}`}`}function ut(e={}){let{additional:r=[],autoInjectTaroApp:t=true,autoInjectVite:n=true}=e,o={},a=new Set(r);return t&&Object.keys(process.env).forEach(u=>{u.startsWith("TARO_APP_")&&a.add(u);}),n&&Object.keys(process.env).forEach(u=>{u.startsWith("VITE_")&&a.add(u);}),a.forEach(u=>{let d=process.env[u]||"";o[`process.env.${u}`]=JSON.stringify(d);}),o}function ct(){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||""),"process.env.API_BASE_URL":JSON.stringify(process.env.API_BASE_URL||"")}}function dt(e={}){let r=e.isTaro??M__default.default.env.TARO_ENV==="h5",t=[Q(),Z()];return !r&&e.startup!==false&&t.push(T(e.startup)),e.jsxSourceTagger!==false&&t.push(P({projectRoot:r?M__default.default.cwd():void 0})),e.tailwindConfigSync!==false&&t.push(A({configPath:e.tailwindConfigPath})),r&&(e.taroH5HistoryFallback!==false&&t.unshift(D()),e.jsxSourceTagger!==false&&(t.push(L()),t.push(N())),t.unshift(j()),t.unshift(k(e.styleAdapter)),t.unshift({name:"dev-postcss-rpx2px-plugin",apply:"serve",config(n){typeof n.css?.postcss=="object"&&n.css?.postcss.plugins?.unshift(w());}})),M__default.default.env.WORKSPACE_GIT_REPO&&t.push(te()),t}
|
|
1186
|
+
exports.default=dt;exports.editorBridgePlugin=Q;exports.injectAmasterEnv=ct;exports.injectTaroEnv=ut;exports.jsxInlineStyleRpxPlugin=j;exports.jsxSourceMapRemapPlugin=N;exports.jsxSourceTaggerPlugin=P;exports.remapJsxDevSourceLocations=le;exports.routesExposePlugin=Z;exports.rpx2pxPlugin=w;exports.startupPlugin=T;exports.tailwindConfigSyncPlugin=A;exports.taroH5HistoryFallbackPlugin=D;exports.taroJsxDevSourcePlugin=L;exports.taroStyleAdapterPlugin=k;exports.transformJsxInlineStyleRpx=oe;//# sourceMappingURL=index.cjs.map
|
|
1125
1187
|
//# sourceMappingURL=index.cjs.map
|