@amaster.ai/vite-plugins 1.0.0-beta.32 → 1.0.0-beta.34

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,4 +1,4 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var crypto=require('crypto'),g=require('fs'),S=require('path'),url=require('url'),H=require('process');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var g__default=/*#__PURE__*/_interopDefault(g);var S__default=/*#__PURE__*/_interopDefault(S);var H__default=/*#__PURE__*/_interopDefault(H);function T(t,e){let n=`${t}:${e}`;return crypto.createHash("md5").update(n).digest("hex").substring(0,12)}var O=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"]);function h(){let t=false;return {name:"vite-plugin-component-id",enforce:"pre",configResolved(e){t=e.command==="serve";},transform(e,n){if(!t||!/\.(tsx|jsx)$/.test(n)||n.includes("node_modules")||!/<[a-z]/.test(e))return null;try{let r=e,s=/<([a-z][\da-z]*)(?=[\s/>])/g,a,o=[];for(;(a=s.exec(e))!==null;){let i=a[1];if(!i)continue;let c=a.index,d=a.index+a[0].length;if(!O.has(i))continue;let l=d,p=!1,f=!1;for(;l<e.length&&!p;)e[l]===">"&&(p=!0,e.substring(c,l).includes("data-node-component-id")&&(f=!0)),l++;f||o.push({index:c,tag:i,tagEndIndex:d});}let u=e;for(let i=o.length-1;i>=0;i--){let c=o[i];if(!c)continue;let{index:d,tagEndIndex:l}=c,p=T(n,d),f=u.substring(0,l),y=u.substring(l);r=`${f} data-node-component-id="${p}"${y}`,u=r;}return {code:r,map:null}}catch{return null}}}}var P=`<script>
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var crypto=require('crypto'),g=require('fs'),b=require('path'),url=require('url'),P=require('process');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var g__default=/*#__PURE__*/_interopDefault(g);var b__default=/*#__PURE__*/_interopDefault(b);var P__default=/*#__PURE__*/_interopDefault(P);function E(t,e){let n=`${t}:${e}`;return crypto.createHash("md5").update(n).digest("hex").substring(0,12)}var O=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"]);function v(){let t=false;return {name:"vite-plugin-component-id",enforce:"pre",configResolved(e){t=e.command==="serve";},transform(e,n){if(!t||!/\.(tsx|jsx)$/.test(n)||n.includes("node_modules")||!/<[a-z]/.test(e))return null;try{let r=e,s=/<([a-z][\da-z]*)(?=[\s/>])/g,i,o=[];for(;(i=s.exec(e))!==null;){let a=i[1];if(!a)continue;let d=i.index,u=i.index+i[0].length;if(!O.has(a))continue;let c=u,p=!1,f=!1;for(;c<e.length&&!p;)e[c]===">"&&(p=!0,e.substring(d,c).includes("data-node-component-id")&&(f=!0)),c++;f||o.push({index:d,tag:a,tagEndIndex:u});}let l=e;for(let a=o.length-1;a>=0;a--){let d=o[a];if(!d)continue;let{index:u,tagEndIndex:c}=d,p=E(n,u),f=l.substring(0,c),y=l.substring(c);r=`${f} data-node-component-id="${p}"${y}`,l=r;}return {code:r,map:null}}catch{return null}}}}var I=`<script>
2
2
  document.addEventListener("click", (e) => {
3
3
  const element = e.target;
4
4
  const noJumpOut = document.body.classList.contains("forbid-jump-out")
@@ -16,9 +16,9 @@ document.addEventListener("click", (e) => {
16
16
  e.preventDefault();
17
17
  }
18
18
  });
19
- </script>`;function q(){try{let t=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=S.dirname(t),n=S.resolve(e,"../dist/bridge.bridge.js");return `<script>
19
+ </script>`;function C(){try{let t=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=b.dirname(t),n=b.resolve(e,"../dist/bridge.bridge.js");return `<script>
20
20
  ${g.readFileSync(n,"utf-8")}
21
- </script>`}catch(t){return console.warn("Failed to read bridge script:",t),""}}function v(){let t=false,e="";return {name:"vite-plugin-editor-bridge",configResolved(n){t=n.command==="serve",t&&(e=q());},transformIndexHtml(n){let s=`${P}${t?e:""}</body>`;return n.replace("</body>",s)}}}function b(t){let e=false,n=t?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(r){e=r.command==="serve";},transform(r,s){if(!e||!s.endsWith(n))return null;try{return r.includes("window.__APP_ROUTES__")?null:{code:`${r}
21
+ </script>`}catch(t){return console.warn("Failed to read bridge script:",t),""}}function h(){let t=false,e="";return {name:"vite-plugin-editor-bridge",configResolved(n){t=n.command==="serve",t&&(e=C());},transformIndexHtml(n){let s=`${I}${t?e:""}</body>`;return n.replace("</body>",s)}}}function S(t){let e=false,n=t?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(r){e=r.command==="serve";},transform(r,s){if(!e||!s.endsWith(n))return null;try{return r.includes("window.__APP_ROUTES__")?null:{code:`${r}
22
22
 
23
23
  // Development mode: Expose routes to window.__APP_ROUTES__
24
24
  if (typeof window !== 'undefined') {
@@ -705,8 +705,529 @@ if (typeof window !== 'undefined') {
705
705
 
706
706
  originalConsole.log('[BrowserLogs] Log collection started');
707
707
  })();
708
- </script>`;return {name:"vite-plugin-browser-logs",configResolved(n){let r=n.root||H__default.default.cwd();t=S__default.default.join(r,"browser.log");},configureServer(n){n.middlewares.use((r,s,a)=>{if(r.url==="/__browser__"&&r.method==="POST"){let o=r.headers.origin||"*",u="";r.on("data",i=>{u+=i.toString();}),r.on("end",()=>{try{let i=S__default.default.dirname(t);g__default.default.existsSync(i)||g__default.default.mkdirSync(i,{recursive:!0}),g__default.default.appendFileSync(t,`${u}
709
- `,"utf-8"),s.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":o,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),s.end(JSON.stringify({success:!0}));}catch(i){console.error("[BrowserLogs] Write error:",i),s.writeHead(500,{"Content-Type":"application/json","Access-Control-Allow-Origin":o,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),s.end(JSON.stringify({success:false,error:String(i)}));}});}else if(r.url==="/__browser__"&&r.method==="OPTIONS"){let o=r.headers.origin||"*";s.writeHead(204,{"Access-Control-Allow-Origin":o,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Max-Age":"86400"}),s.end();}else if(r.url==="/__browser__"){let o=r.headers.origin||"*";s.writeHead(405,{"Content-Type":"application/json","Access-Control-Allow-Origin":o}),s.end(JSON.stringify({error:"Method not allowed"}));}else a();}),console.log("[BrowserLogs] Logs will be written to:",t);},transformIndexHtml(n){return n.replace(/<head([^>]*)>/i,`<head$1>${e}`)}}}function m(){return {name:"vite-plugin-taro-style-adapter",apply:"serve",transformIndexHtml(t){return t.replace("</head>",`
708
+ </script>`;return {name:"vite-plugin-browser-logs",configResolved(n){let r=n.root||P__default.default.cwd();t=b__default.default.join(r,"browser.log");},configureServer(n){n.middlewares.use((r,s,i)=>{if(r.url==="/__browser__"&&r.method==="POST"){let o=r.headers.origin||"*",l="";r.on("data",a=>{l+=a.toString();}),r.on("end",()=>{try{let a=b__default.default.dirname(t);g__default.default.existsSync(a)||g__default.default.mkdirSync(a,{recursive:!0}),g__default.default.appendFileSync(t,`${l}
709
+ `,"utf-8"),s.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":o,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),s.end(JSON.stringify({success:!0}));}catch(a){console.error("[BrowserLogs] Write error:",a),s.writeHead(500,{"Content-Type":"application/json","Access-Control-Allow-Origin":o,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),s.end(JSON.stringify({success:false,error:String(a)}));}});}else if(r.url==="/__browser__"&&r.method==="OPTIONS"){let o=r.headers.origin||"*";s.writeHead(204,{"Access-Control-Allow-Origin":o,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Max-Age":"86400"}),s.end();}else if(r.url==="/__browser__"){let o=r.headers.origin||"*";s.writeHead(405,{"Content-Type":"application/json","Access-Control-Allow-Origin":o}),s.end(JSON.stringify({error:"Method not allowed"}));}else i();}),console.log("[BrowserLogs] Logs will be written to:",t);},transformIndexHtml(n){return n.replace(/<head([^>]*)>/i,`<head$1>${e}`)}}}function w(){let t=`
710
+ <script>
711
+ (function() {
712
+ 'use strict';
713
+
714
+ var PLUGIN_TAG = '[SmartReload]';
715
+ // full-reload \u540E\u7B49\u5F85 WebSocket \u65AD\u5F00\u7684\u7A97\u53E3\u671F\uFF08ms\uFF09
716
+ var DISCONNECT_DETECT_WINDOW = 300;
717
+ // WebSocket \u65AD\u5F00\u540E\u7B49\u5F85\u91CD\u8FDE\u7684\u8D85\u65F6\u65F6\u95F4\uFF08ms\uFF09\uFF0C\u8D85\u65F6\u540E fallback \u5230 full-reload
718
+ var RECONNECT_TIMEOUT = 5000;
719
+ // \u91CD\u8FDE\u6210\u529F\u540E\uFF0C\u7B49\u5F85\u662F\u5426\u6709 full-reload/update \u6D88\u606F\u7684\u7A97\u53E3\u671F\uFF08ms\uFF09
720
+ var POST_RECONNECT_WINDOW = 2000;
721
+ // \u6291\u5236 location.reload \u540E\u7684\u6700\u5927\u7A97\u53E3\u671F\uFF08ms\uFF09\uFF0C\u8D85\u65F6\u540E\u6267\u884C soft-reload \u6062\u590D HMR
722
+ var RELOAD_SUPPRESS_WINDOW = 5000;
723
+ // soft-reload \u5EF6\u8FDF\uFF08ms\uFF09\uFF0C\u7ED9\u7528\u6237\u4E00\u4E2A\u89C6\u89C9\u53CD\u9988\u7684\u65F6\u95F4
724
+ var SOFT_RELOAD_DELAY = 800;
725
+
726
+ // ============================================
727
+ // \u72B6\u6001\u7BA1\u7406
728
+ // ============================================
729
+ var state = {
730
+ // \u662F\u5426\u5DF2\u7ECF\u62E6\u622A\u4E86 Vite HMR WebSocket
731
+ wsIntercepted: false,
732
+ // \u662F\u5426\u6B63\u5728\u7B49\u5F85\u5224\u65AD full-reload \u7C7B\u578B\uFF08300ms \u7A97\u53E3\u671F\uFF09
733
+ detectingReloadType: false,
734
+ // \u5EF6\u8FDF\u6267\u884C full-reload \u7684\u5B9A\u65F6\u5668
735
+ reloadTimer: null,
736
+ // \u662F\u5426\u6B63\u5728\u7B49\u5F85\u670D\u52A1\u5668\u91CD\u8FDE
737
+ waitingForReconnect: false,
738
+ // \u662F\u5426\u662F\u670D\u52A1\u5668\u91CD\u542F\u573A\u666F
739
+ isServerRestart: false,
740
+ // overlay \u5BB9\u5668
741
+ overlayEl: null,
742
+ // \u91CD\u8FDE\u8D85\u65F6\u5B9A\u65F6\u5668
743
+ reconnectTimeoutTimer: null,
744
+ // \u91CD\u8FDE\u540E\u7B49\u5F85\u53D8\u66F4\u7684\u5B9A\u65F6\u5668
745
+ postReconnectTimer: null,
746
+ // \u662F\u5426\u6B63\u5728\u6291\u5236 location.reload
747
+ suppressingReload: false,
748
+ // \u6291\u5236 reload \u7684\u5B9A\u65F6\u5668
749
+ suppressReloadTimer: null,
750
+ // \u5DF2\u62E6\u622A\u7684 reload \u6B21\u6570\uFF08\u7528\u4E8E\u5224\u65AD\u662F\u5426\u9700\u8981 soft-reload\uFF09
751
+ suppressedReloadCount: 0
752
+ };
753
+
754
+ // ============================================
755
+ // \u65E5\u5FD7\u5DE5\u5177
756
+ // ============================================
757
+ function log() {
758
+ var args = [PLUGIN_TAG];
759
+ for (var i = 0; i < arguments.length; i++) {
760
+ args.push(arguments[i]);
761
+ }
762
+ console.debug.apply(console, args);
763
+ }
764
+
765
+ // ============================================
766
+ // \u72B6\u6001\u63D0\u793A Overlay
767
+ // ============================================
768
+ function showOverlay(message) {
769
+ removeOverlay();
770
+ var el = document.createElement('div');
771
+ el.id = '__smart_reload_overlay__';
772
+ el.style.cssText = [
773
+ 'position: fixed',
774
+ 'bottom: 16px',
775
+ 'right: 16px',
776
+ 'z-index: 99999',
777
+ 'padding: 8px 16px',
778
+ 'background: rgba(0,0,0,0.75)',
779
+ 'color: #fff',
780
+ 'font-size: 13px',
781
+ 'font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
782
+ 'border-radius: 8px',
783
+ 'box-shadow: 0 2px 8px rgba(0,0,0,0.3)',
784
+ 'pointer-events: none',
785
+ 'transition: opacity 0.3s',
786
+ 'opacity: 1',
787
+ 'display: flex',
788
+ 'align-items: center',
789
+ 'gap: 8px'
790
+ ].join(';');
791
+
792
+ var spinner = document.createElement('div');
793
+ spinner.style.cssText = [
794
+ 'width: 14px',
795
+ 'height: 14px',
796
+ 'border: 2px solid rgba(255,255,255,0.3)',
797
+ 'border-top-color: #fff',
798
+ 'border-radius: 50%',
799
+ 'animation: __smart_reload_spin__ 0.8s linear infinite',
800
+ 'flex-shrink: 0'
801
+ ].join(';');
802
+
803
+ if (!document.getElementById('__smart_reload_keyframes__')) {
804
+ var styleEl = document.createElement('style');
805
+ styleEl.id = '__smart_reload_keyframes__';
806
+ styleEl.textContent = '@keyframes __smart_reload_spin__ { to { transform: rotate(360deg); } }';
807
+ document.head.appendChild(styleEl);
808
+ }
809
+
810
+ var textEl = document.createElement('span');
811
+ textEl.textContent = message;
812
+
813
+ el.appendChild(spinner);
814
+ el.appendChild(textEl);
815
+ document.body.appendChild(el);
816
+ state.overlayEl = el;
817
+ }
818
+
819
+ function showSuccessOverlay(message) {
820
+ removeOverlay();
821
+ var el = document.createElement('div');
822
+ el.id = '__smart_reload_overlay__';
823
+ el.style.cssText = [
824
+ 'position: fixed',
825
+ 'bottom: 16px',
826
+ 'right: 16px',
827
+ 'z-index: 99999',
828
+ 'padding: 8px 16px',
829
+ 'background: rgba(34,139,34,0.85)',
830
+ 'color: #fff',
831
+ 'font-size: 13px',
832
+ 'font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
833
+ 'border-radius: 8px',
834
+ 'box-shadow: 0 2px 8px rgba(0,0,0,0.3)',
835
+ 'pointer-events: none',
836
+ 'transition: opacity 0.3s',
837
+ 'opacity: 1',
838
+ 'display: flex',
839
+ 'align-items: center',
840
+ 'gap: 8px'
841
+ ].join(';');
842
+
843
+ var checkmark = document.createElement('span');
844
+ checkmark.textContent = '\u2713';
845
+ checkmark.style.cssText = 'font-size: 16px; font-weight: bold;';
846
+
847
+ var textEl = document.createElement('span');
848
+ textEl.textContent = message;
849
+
850
+ el.appendChild(checkmark);
851
+ el.appendChild(textEl);
852
+ document.body.appendChild(el);
853
+ state.overlayEl = el;
854
+
855
+ // \u81EA\u52A8\u6D88\u5931
856
+ setTimeout(function() {
857
+ removeOverlay();
858
+ }, 2000);
859
+ }
860
+
861
+ function updateOverlayText(message) {
862
+ if (state.overlayEl) {
863
+ var textEl = state.overlayEl.querySelector('span:last-child');
864
+ if (textEl) {
865
+ textEl.textContent = message;
866
+ }
867
+ }
868
+ }
869
+
870
+ function removeOverlay() {
871
+ if (state.overlayEl) {
872
+ state.overlayEl.style.opacity = '0';
873
+ var el = state.overlayEl;
874
+ setTimeout(function() {
875
+ if (el && el.parentNode) {
876
+ el.parentNode.removeChild(el);
877
+ }
878
+ }, 300);
879
+ state.overlayEl = null;
880
+ }
881
+ }
882
+
883
+ // ============================================
884
+ // \u6E05\u9664\u6240\u6709\u5B9A\u65F6\u5668
885
+ // ============================================
886
+ function clearAllTimers() {
887
+ if (state.reloadTimer) {
888
+ clearTimeout(state.reloadTimer);
889
+ state.reloadTimer = null;
890
+ }
891
+ if (state.reconnectTimeoutTimer) {
892
+ clearTimeout(state.reconnectTimeoutTimer);
893
+ state.reconnectTimeoutTimer = null;
894
+ }
895
+ if (state.postReconnectTimer) {
896
+ clearTimeout(state.postReconnectTimer);
897
+ state.postReconnectTimer = null;
898
+ }
899
+ if (state.suppressReloadTimer) {
900
+ clearTimeout(state.suppressReloadTimer);
901
+ state.suppressReloadTimer = null;
902
+ }
903
+ }
904
+
905
+ // ============================================
906
+ // \u91CD\u7F6E\u72B6\u6001
907
+ // ============================================
908
+ function resetState() {
909
+ state.detectingReloadType = false;
910
+ state.isServerRestart = false;
911
+ state.waitingForReconnect = false;
912
+ state.suppressingReload = false;
913
+ state.suppressedReloadCount = 0;
914
+ clearAllTimers();
915
+ }
916
+
917
+ // ============================================
918
+ // \u6267\u884C\u771F\u6B63\u7684 full-reload
919
+ // ============================================
920
+ function executeFullReload() {
921
+ log('Executing full-reload');
922
+ resetState();
923
+ removeOverlay();
924
+ originalLocationReload.call(window.location);
925
+ }
926
+
927
+ // ============================================
928
+ // Soft-reload\uFF1A\u5EF6\u8FDF\u5237\u65B0\uFF0C\u6062\u590D HMR \u8FDE\u63A5
929
+ // \u5728\u6291\u5236 reload \u540E\uFF0CVite \u5BA2\u6237\u7AEF\u7684 WebSocket \u5DF2\u6B7B\uFF0C
930
+ // \u9700\u8981\u901A\u8FC7 reload \u6062\u590D HMR\u3002\u4F7F\u7528\u5EF6\u8FDF\u8BA9\u7528\u6237\u611F\u77E5\u5230"\u91CD\u8FDE\u6210\u529F"\u3002
931
+ // ============================================
932
+ function scheduleSoftReload() {
933
+ log('Scheduling soft-reload to restore HMR connection');
934
+ showSuccessOverlay('Server ready, refreshing...');
935
+ setTimeout(function() {
936
+ resetState();
937
+ removeOverlay();
938
+ originalLocationReload.call(window.location);
939
+ }, SOFT_RELOAD_DELAY);
940
+ }
941
+
942
+ // ============================================
943
+ // \u62E6\u622A location.reload
944
+ // Vite \u5BA2\u6237\u7AEF\u5728 HTTP ping \u6210\u529F\u540E\u4F1A\u76F4\u63A5\u8C03\u7528 location.reload()
945
+ // \u6211\u4EEC\u9700\u8981\u5728\u670D\u52A1\u5668\u91CD\u542F\u671F\u95F4\u62E6\u622A\u8FD9\u4E2A\u8C03\u7528
946
+ // ============================================
947
+ var originalLocationReload = window.location.reload.bind(window.location);
948
+
949
+ try {
950
+ Object.defineProperty(window.location, 'reload', {
951
+ value: function smartReloadInterceptedReload() {
952
+ if (state.suppressingReload || state.waitingForReconnect || state.isServerRestart) {
953
+ state.suppressedReloadCount++;
954
+ log('Suppressed location.reload() during server restart (count: ' + state.suppressedReloadCount + ')');
955
+
956
+ // \u9996\u6B21\u6291\u5236\u65F6\uFF0C\u542F\u52A8 soft-reload \u5B9A\u65F6\u5668
957
+ // \u540E\u7EED\u91CD\u590D\u8C03\u7528\u53EA\u91CD\u7F6E\u5B9A\u65F6\u5668\uFF08\u9632\u6296\uFF09
958
+ if (state.suppressReloadTimer) {
959
+ clearTimeout(state.suppressReloadTimer);
960
+ }
961
+ state.suppressReloadTimer = setTimeout(function() {
962
+ if (state.suppressingReload || state.isServerRestart) {
963
+ log('Reload suppress window expired, performing soft-reload');
964
+ scheduleSoftReload();
965
+ }
966
+ }, RELOAD_SUPPRESS_WINDOW);
967
+
968
+ return;
969
+ }
970
+ return originalLocationReload.call(window.location);
971
+ },
972
+ writable: true,
973
+ configurable: true
974
+ });
975
+ log('location.reload intercepted via defineProperty');
976
+ } catch (e) {
977
+ // \u67D0\u4E9B\u6D4F\u89C8\u5668\u73AF\u5883\u53EF\u80FD\u4E0D\u5141\u8BB8\u4FEE\u6539 location.reload
978
+ // \u6B64\u65F6\u63D2\u4EF6\u7684 WebSocket \u6D88\u606F\u62E6\u622A\u4ECD\u7136\u6709\u6548\uFF0C\u53EA\u662F\u65E0\u6CD5\u62E6\u622A Vite \u7684 HTTP ping \u540E\u7684 reload
979
+ log('Failed to intercept location.reload (plugin will have limited effectiveness):', e.message);
980
+ }
981
+
982
+ // ============================================
983
+ // \u8FDB\u5165\u670D\u52A1\u5668\u91CD\u542F\u7B49\u5F85\u6A21\u5F0F
984
+ // ============================================
985
+ function enterServerRestartMode(reason) {
986
+ log('Entering server restart mode:', reason);
987
+
988
+ state.isServerRestart = true;
989
+ state.waitingForReconnect = true;
990
+ state.suppressingReload = true;
991
+ state.detectingReloadType = false;
992
+
993
+ if (state.reloadTimer) {
994
+ clearTimeout(state.reloadTimer);
995
+ state.reloadTimer = null;
996
+ }
997
+
998
+ showOverlay('Server restarting, waiting for reconnect...');
999
+
1000
+ // \u8D85\u65F6\u4FDD\u62A4\uFF1A\u5982\u679C\u6307\u5B9A\u65F6\u95F4\u5185\u65E0\u6CD5\u91CD\u8FDE\uFF0C\u6267\u884C full-reload
1001
+ if (state.reconnectTimeoutTimer) {
1002
+ clearTimeout(state.reconnectTimeoutTimer);
1003
+ }
1004
+ state.reconnectTimeoutTimer = setTimeout(function() {
1005
+ if (state.waitingForReconnect || state.isServerRestart) {
1006
+ log('Reconnect timeout (' + RECONNECT_TIMEOUT + 'ms), performing full-reload as fallback');
1007
+ executeFullReload();
1008
+ }
1009
+ }, RECONNECT_TIMEOUT);
1010
+ }
1011
+
1012
+ // ============================================
1013
+ // \u62E6\u622A WebSocket \u6784\u9020\u51FD\u6570
1014
+ // ============================================
1015
+ var OriginalWebSocket = window.WebSocket;
1016
+
1017
+ function isViteHmrWebSocket(url) {
1018
+ if (typeof url !== 'string') return false;
1019
+ // \u53EA\u5339\u914D Vite HMR \u7279\u5F81\u7684 URL
1020
+ // Vite 4.x/5.x \u4F7F\u7528 /__vite_hmr \u6216\u5E26 token \u53C2\u6570\u7684\u8DEF\u5F84
1021
+ return url.includes('/__vite_hmr') || url.includes('?token=');
1022
+ }
1023
+
1024
+ function createWsProxy(ws) {
1025
+ var originalAddEventListener = ws.addEventListener.bind(ws);
1026
+ var originalRemoveEventListener = ws.removeEventListener.bind(ws);
1027
+
1028
+ ws.addEventListener = function(type, listener, options) {
1029
+ if (type === 'message') {
1030
+ var wrappedListener = function(event) {
1031
+ var intercepted = handleWsMessage(event);
1032
+ if (!intercepted) {
1033
+ listener.call(ws, event);
1034
+ }
1035
+ };
1036
+ listener.__smartReloadWrapped__ = wrappedListener;
1037
+ return originalAddEventListener(type, wrappedListener, options);
1038
+ }
1039
+ return originalAddEventListener(type, listener, options);
1040
+ };
1041
+
1042
+ ws.removeEventListener = function(type, listener, options) {
1043
+ if (type === 'message' && listener.__smartReloadWrapped__) {
1044
+ return originalRemoveEventListener(type, listener.__smartReloadWrapped__, options);
1045
+ }
1046
+ return originalRemoveEventListener(type, listener, options);
1047
+ };
1048
+
1049
+ var originalOnMessage = null;
1050
+ var onMessageDescriptor = Object.getOwnPropertyDescriptor(WebSocket.prototype, 'onmessage') ||
1051
+ Object.getOwnPropertyDescriptor(ws, 'onmessage');
1052
+
1053
+ if (onMessageDescriptor) {
1054
+ Object.defineProperty(ws, 'onmessage', {
1055
+ get: function() {
1056
+ return originalOnMessage;
1057
+ },
1058
+ set: function(handler) {
1059
+ originalOnMessage = handler;
1060
+ var wrappedHandler = function(event) {
1061
+ var intercepted = handleWsMessage(event);
1062
+ if (!intercepted && handler) {
1063
+ handler.call(ws, event);
1064
+ }
1065
+ };
1066
+ if (onMessageDescriptor.set) {
1067
+ onMessageDescriptor.set.call(ws, wrappedHandler);
1068
+ }
1069
+ },
1070
+ configurable: true
1071
+ });
1072
+ }
1073
+
1074
+ originalAddEventListener('close', function(event) {
1075
+ handleWsClose(event);
1076
+ });
1077
+
1078
+ originalAddEventListener('open', function() {
1079
+ handleWsOpen();
1080
+ });
1081
+
1082
+ state.wsIntercepted = true;
1083
+ log('Vite HMR WebSocket intercepted');
1084
+
1085
+ return ws;
1086
+ }
1087
+
1088
+ window.WebSocket = function SmartReloadWebSocket(url, protocols) {
1089
+ var ws;
1090
+ if (protocols !== undefined) {
1091
+ ws = new OriginalWebSocket(url, protocols);
1092
+ } else {
1093
+ ws = new OriginalWebSocket(url);
1094
+ }
1095
+
1096
+ if (!state.wsIntercepted && isViteHmrWebSocket(url)) {
1097
+ return createWsProxy(ws);
1098
+ }
1099
+
1100
+ return ws;
1101
+ };
1102
+
1103
+ window.WebSocket.prototype = OriginalWebSocket.prototype;
1104
+ window.WebSocket.CONNECTING = OriginalWebSocket.CONNECTING;
1105
+ window.WebSocket.OPEN = OriginalWebSocket.OPEN;
1106
+ window.WebSocket.CLOSING = OriginalWebSocket.CLOSING;
1107
+ window.WebSocket.CLOSED = OriginalWebSocket.CLOSED;
1108
+
1109
+ // ============================================
1110
+ // WebSocket \u6D88\u606F\u5904\u7406
1111
+ // ============================================
1112
+ function handleWsMessage(event) {
1113
+ var data;
1114
+ try {
1115
+ data = JSON.parse(event.data);
1116
+ } catch (e) {
1117
+ // \u975E JSON \u6D88\u606F\uFF0C\u4E0D\u62E6\u622A
1118
+ return false;
1119
+ }
1120
+
1121
+ // \u5904\u7406 full-reload \u6D88\u606F
1122
+ if (data.type === 'full-reload') {
1123
+ // \u5982\u679C\u5DF2\u7ECF\u5728\u670D\u52A1\u5668\u91CD\u542F\u6A21\u5F0F\uFF0C\u62E6\u622A\u6240\u6709 full-reload
1124
+ if (state.isServerRestart) {
1125
+ log('Suppressed full-reload during server restart');
1126
+ return true;
1127
+ }
1128
+
1129
+ log('Intercepted full-reload, path:', data.path || '(none)');
1130
+
1131
+ // \u8FDB\u5165\u68C0\u6D4B\u6A21\u5F0F\uFF1A\u7B49\u5F85\u770B WebSocket \u662F\u5426\u65AD\u5F00
1132
+ state.detectingReloadType = true;
1133
+
1134
+ // \u8BBE\u7F6E\u5B9A\u65F6\u5668\uFF1A\u5982\u679C\u7A97\u53E3\u671F\u5185 WebSocket \u6CA1\u6709\u65AD\u5F00\uFF0C\u8BF4\u660E\u662F\u771F\u6B63\u7684\u6A21\u5757\u53D8\u66F4
1135
+ state.reloadTimer = setTimeout(function() {
1136
+ if (state.detectingReloadType && !state.isServerRestart) {
1137
+ log('WebSocket still connected after ' + DISCONNECT_DETECT_WINDOW + 'ms - real module change, executing reload');
1138
+ state.detectingReloadType = false;
1139
+ executeFullReload();
1140
+ }
1141
+ }, DISCONNECT_DETECT_WINDOW);
1142
+
1143
+ // \u62E6\u622A\uFF0C\u4E0D\u4F20\u9012\u7ED9 Vite \u5BA2\u6237\u7AEF
1144
+ return true;
1145
+ }
1146
+
1147
+ // \u5904\u7406 connected \u6D88\u606F\uFF08Vite \u670D\u52A1\u5668\u53D1\u9001\u7684\u9996\u6761\u6D88\u606F\uFF09
1148
+ if (data.type === 'connected') {
1149
+ if (state.isServerRestart) {
1150
+ log('Reconnected to Vite server after restart');
1151
+
1152
+ // \u6E05\u9664\u91CD\u8FDE\u8D85\u65F6
1153
+ if (state.reconnectTimeoutTimer) {
1154
+ clearTimeout(state.reconnectTimeoutTimer);
1155
+ state.reconnectTimeoutTimer = null;
1156
+ }
1157
+
1158
+ state.waitingForReconnect = false;
1159
+ updateOverlayText('Reconnected, checking for changes...');
1160
+
1161
+ // \u91CD\u8FDE\u540E\u7B49\u5F85\u4E00\u6BB5\u65F6\u95F4\uFF0C\u770B\u662F\u5426\u6709 full-reload \u6216 update \u6D88\u606F
1162
+ // \u5982\u679C\u6CA1\u6709\uFF0C\u8BF4\u660E\u4E0D\u9700\u8981\u5237\u65B0
1163
+ state.postReconnectTimer = setTimeout(function() {
1164
+ if (state.isServerRestart) {
1165
+ log('No changes detected after reconnect, performing soft-reload to restore HMR');
1166
+ // \u5373\u4F7F\u6CA1\u6709\u6A21\u5757\u53D8\u66F4\uFF0C\u4E5F\u9700\u8981 soft-reload \u6765\u6062\u590D HMR WebSocket \u8FDE\u63A5
1167
+ // \u56E0\u4E3A Vite \u5BA2\u6237\u7AEF\u5728 WebSocket \u65AD\u5F00\u540E\u4E0D\u4F1A\u81EA\u52A8\u91CD\u5EFA\u8FDE\u63A5
1168
+ scheduleSoftReload();
1169
+ }
1170
+ }, POST_RECONNECT_WINDOW);
1171
+ }
1172
+ return false; // \u8BA9 connected \u6D88\u606F\u6B63\u5E38\u4F20\u9012
1173
+ }
1174
+
1175
+ // \u5904\u7406 update \u6D88\u606F\uFF08HMR \u70ED\u66F4\u65B0\uFF09
1176
+ if (data.type === 'update' && state.isServerRestart) {
1177
+ // \u91CD\u8FDE\u540E\u6536\u5230 HMR update\uFF0C\u8BF4\u660E\u6709\u6A21\u5757\u53D8\u66F4
1178
+ // \u8BA9 HMR update \u6B63\u5E38\u5904\u7406
1179
+ log('Received HMR update after reconnect, letting HMR handle it');
1180
+ if (state.postReconnectTimer) {
1181
+ clearTimeout(state.postReconnectTimer);
1182
+ state.postReconnectTimer = null;
1183
+ }
1184
+ // \u6709 HMR update \u8BF4\u660E WebSocket \u662F\u6D3B\u7684\uFF0C\u53EF\u4EE5\u76F4\u63A5\u6062\u590D
1185
+ resetState();
1186
+ showSuccessOverlay('HMR update applied');
1187
+ return false; // \u8BA9 update \u6D88\u606F\u6B63\u5E38\u4F20\u9012\u7ED9 Vite \u5BA2\u6237\u7AEF\u5904\u7406 HMR
1188
+ }
1189
+
1190
+ return false;
1191
+ }
1192
+
1193
+ // ============================================
1194
+ // WebSocket \u8FDE\u63A5\u4E8B\u4EF6\u5904\u7406
1195
+ // ============================================
1196
+ function handleWsClose(event) {
1197
+ log('WebSocket closed, code:', event.code, 'wasClean:', event.wasClean);
1198
+
1199
+ // \u573A\u666F1\uFF1A\u6536\u5230 full-reload \u540E WebSocket \u65AD\u5F00 \u2192 \u670D\u52A1\u5668\u91CD\u542F
1200
+ if (state.detectingReloadType) {
1201
+ enterServerRestartMode('full-reload followed by disconnect');
1202
+ return;
1203
+ }
1204
+
1205
+ // \u573A\u666F2\uFF1A\u6CA1\u6709 full-reload \u6D88\u606F\uFF0CWebSocket \u76F4\u63A5\u65AD\u5F00
1206
+ // \u53EA\u5728\u975E\u6B63\u5E38\u5173\u95ED\u65F6\u624D\u8FDB\u5165\u91CD\u542F\u6A21\u5F0F\uFF08wasClean === false \u8868\u793A\u975E\u6B63\u5E38\u65AD\u5F00\uFF09
1207
+ if (!state.isServerRestart && !event.wasClean) {
1208
+ enterServerRestartMode('unexpected disconnect (server process killed)');
1209
+ }
1210
+ }
1211
+
1212
+ function handleWsOpen() {
1213
+ log('WebSocket opened');
1214
+ // \u91CD\u8FDE\u540E\u7684\u5904\u7406\u7531 handleWsMessage \u4E2D\u7684 connected \u6D88\u606F\u5904\u7406
1215
+ }
1216
+
1217
+ // ============================================
1218
+ // \u66B4\u9732 API \u4F9B\u8C03\u8BD5\u4F7F\u7528
1219
+ // ============================================
1220
+ window.__smartReloadState__ = state;
1221
+ window.__smartReloadForceReload__ = function() {
1222
+ log('Force reload triggered by user');
1223
+ resetState();
1224
+ removeOverlay();
1225
+ originalLocationReload.call(window.location);
1226
+ };
1227
+
1228
+ log('Smart Reload initialized');
1229
+ })();
1230
+ </script>`;return {name:"vite-plugin-smart-reload",enforce:"pre",apply:"serve",transformIndexHtml(e){return e.replace(/<head([^>]*)>/i,`<head$1>${t}`)}}}function m(){return {name:"vite-plugin-taro-style-adapter",apply:"serve",transformIndexHtml(t){return t.replace("</head>",`
710
1231
  <style data-taro-adapter="true">
711
1232
  /* \u4EC5 H5 \u751F\u6548\uFF1A\u9690\u85CF Taro \u9875\u9762\u5BB9\u5668\u6EDA\u52A8\u6761\uFF0C\u4F46\u4ECD\u53EF\u6EDA\u52A8 */
712
1233
  .taro_page {
@@ -734,5 +1255,5 @@ if (typeof window !== 'undefined') {
734
1255
  display: none; /* Chrome/Safari */
735
1256
  }
736
1257
  </style>
737
- </head>`)}}}function k(t={}){let{additional:e=[],autoInjectTaroApp:n=true,autoInjectVite:r=true}=t,s={},a=new Set(e);return n&&Object.keys(process.env).forEach(o=>{o.startsWith("TARO_APP_")&&a.add(o);}),r&&Object.keys(process.env).forEach(o=>{o.startsWith("VITE_")&&a.add(o);}),a.forEach(o=>{let u=process.env[o]||"";s[`process.env.${o}`]=JSON.stringify(u);}),s}function L(){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 B(t={}){let e=[m(),h(),v(),b()];return H__default.default.env.WORKSPACE_GIT_REPO&&e.push(_()),e}exports.componentIdPlugin=h;exports.default=B;exports.editorBridgePlugin=v;exports.injectAmasterEnv=L;exports.injectTaroEnv=k;exports.routesExposePlugin=b;exports.taroStyleAdapterPlugin=m;//# sourceMappingURL=index.cjs.map
1258
+ </head>`)}}}function L(t={}){let{additional:e=[],autoInjectTaroApp:n=true,autoInjectVite:r=true}=t,s={},i=new Set(e);return n&&Object.keys(process.env).forEach(o=>{o.startsWith("TARO_APP_")&&i.add(o);}),r&&Object.keys(process.env).forEach(o=>{o.startsWith("VITE_")&&i.add(o);}),i.forEach(o=>{let l=process.env[o]||"";s[`process.env.${o}`]=JSON.stringify(l);}),s}function H(){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(t={}){let e=[m(),v(),h(),S(),w()];return P__default.default.env.WORKSPACE_GIT_REPO&&e.push(_()),e}exports.componentIdPlugin=v;exports.default=q;exports.editorBridgePlugin=h;exports.injectAmasterEnv=H;exports.injectTaroEnv=L;exports.routesExposePlugin=S;exports.smartReloadPlugin=w;exports.taroStyleAdapterPlugin=m;//# sourceMappingURL=index.cjs.map
738
1259
  //# sourceMappingURL=index.cjs.map