@amaster.ai/vite-plugins 1.1.4 → 1.1.5

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.js CHANGED
@@ -1,11 +1,11 @@
1
- import y,{readFileSync}from'fs';import d,{dirname,resolve}from'path';import {fileURLToPath}from'url';import A from'process';import w from'fs/promises';import k from'@babel/generator';import {parse}from'@babel/parser';import L from'@babel/traverse';var F=fileURLToPath(import.meta.url),U=dirname(F),P="@amaster/bridge-monitor",T="\0"+P,m=null;function z(){if(m)return m;try{let e=resolve(U,"../dist/bridge-module.global.js");return m=readFileSync(e,"utf-8"),m}catch(e){return console.warn("[editor-bridge] Failed to load pre-built bridge module:",e),""}}function W(){return '<script type="module" src="/@id/@amaster/bridge-monitor"></script>'}function X(e){return z().replace(/__SESSION_KEY__/g,e)+`
2
- export default {};`}function C(){let e=false;return {name:"vite-plugin-editor-bridge",configResolved(n){e=n.command==="serve";},resolveId(n){if(n===P)return T},load(n){if(n===T){let r=process.env.VITE_AMASTER_KEY||"";return X(r)}},transformIndexHtml(n){if(!e)return n;let r=W();return n.replace("</body>",`${r}</body>`)}}}function I(e){let n=false,r=e?.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(r))return null;try{return t.includes("window.__APP_ROUTES__")?null:{code:`${t}
1
+ import h,{readFileSync}from'fs';import f,{dirname,resolve}from'path';import {fileURLToPath}from'url';import I from'process';import _ from'fs/promises';import j from'@babel/generator';import {parse}from'@babel/parser';import k from'@babel/traverse';var F=fileURLToPath(import.meta.url),U=dirname(F),C="@amaster/bridge-monitor",O="\0"+C,y=null;function z(){if(y)return y;try{let e=resolve(U,"../dist/bridge-module.global.js");return y=readFileSync(e,"utf-8"),y}catch(e){return console.warn("[editor-bridge] Failed to load pre-built bridge module:",e),""}}function W(){return '<script type="module" src="/@id/@amaster/bridge-monitor"></script>'}function X(e){return z().replace(/__SESSION_KEY__/g,e)+`
2
+ export default {};`}function P(){let e=false;return {name:"vite-plugin-editor-bridge",configResolved(n){e=n.command==="serve";},resolveId(n){if(n===C)return O},load(n){if(n===O){let t=process.env.VITE_AMASTER_KEY||"";return X(t)}},transformIndexHtml(n){if(!e)return n;let t=W();return n.replace("</body>",`${t}</body>`)}}}function A(e){let n=false,t=e?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(r){n=r.command==="serve";},transform(r,o){if(!n||!o.endsWith(t))return null;try{return r.includes("window.__APP_ROUTES__")?null:{code:`${r}
3
3
 
4
4
  // Development mode: Expose routes to window.__APP_ROUTES__
5
5
  if (typeof window !== 'undefined') {
6
6
  window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];
7
7
  }
8
- `,map:null}}catch{return null}}}}function j(){let e="",n=`
8
+ `,map:null}}catch{return null}}}}function L(){let e="",n=`
9
9
  <script>
10
10
  (function() {
11
11
  'use strict';
@@ -16,17 +16,108 @@ if (typeof window !== 'undefined') {
16
16
  // Save original fetch before any interception, used exclusively for log writing
17
17
  var __originalFetch__ = window.fetch.bind(window);
18
18
 
19
- // Write queue to ensure sequential writes
20
- var writeQueue = [];
19
+ // Batch queue to ensure sequential writes
20
+ var pendingLogs = [];
21
+ var batchQueue = [];
21
22
  var isWriting = false;
23
+ var flushTimer = null;
24
+ var MAX_REPORT_BATCH_SIZE = 10;
25
+ var REPORT_INTERVAL_MS = 5000;
26
+ var DEDUPE_WINDOW_MS = 5000;
27
+ var MAX_DEDUPE_CACHE_SIZE = 10;
28
+ var dedupeCache = {};
22
29
 
23
- // Process write queue to ensure sequential writes
30
+ function clearFlushTimer() {
31
+ if (flushTimer) {
32
+ clearTimeout(flushTimer);
33
+ flushTimer = null;
34
+ }
35
+ }
36
+
37
+ function cleanupDedupCache(now) {
38
+ var cacheSize = 0;
39
+ for (var dedupeKey in dedupeCache) {
40
+ if (now - dedupeCache[dedupeKey] >= DEDUPE_WINDOW_MS) {
41
+ delete dedupeCache[dedupeKey];
42
+ continue;
43
+ }
44
+ cacheSize++;
45
+ }
46
+
47
+ if (cacheSize <= MAX_DEDUPE_CACHE_SIZE) {
48
+ return;
49
+ }
50
+
51
+ var sortedKeys = Object.keys(dedupeCache).sort(function(a, b) {
52
+ return dedupeCache[a] - dedupeCache[b];
53
+ });
54
+ var overflowCount = sortedKeys.length - MAX_DEDUPE_CACHE_SIZE;
55
+ for (var i = 0; i < overflowCount; i++) {
56
+ delete dedupeCache[sortedKeys[i]];
57
+ }
58
+ }
59
+
60
+ function createDedupKey(entry) {
61
+ if (!entry || entry.type === 'request') {
62
+ return '';
63
+ }
64
+
65
+ var dedupeEntry = {};
66
+ for (var key in entry) {
67
+ if (key === 'timestamp' || key === '_truncated' || key === '_originalSize') {
68
+ continue;
69
+ }
70
+ dedupeEntry[key] = entry[key];
71
+ }
72
+
73
+ try {
74
+ return JSON.stringify(dedupeEntry);
75
+ } catch (e) {
76
+ return '';
77
+ }
78
+ }
79
+
80
+ function shouldSkipDuplicate(entry) {
81
+ var dedupeKey = createDedupKey(entry);
82
+ if (!dedupeKey) {
83
+ return false;
84
+ }
85
+
86
+ var now = Date.now();
87
+ var lastReportedAt = dedupeCache[dedupeKey];
88
+ dedupeCache[dedupeKey] = now;
89
+ cleanupDedupCache(now);
90
+
91
+ return typeof lastReportedAt === 'number' && now - lastReportedAt < DEDUPE_WINDOW_MS;
92
+ }
93
+
94
+ function flushPendingLogs() {
95
+ if (pendingLogs.length === 0) {
96
+ clearFlushTimer();
97
+ return;
98
+ }
99
+
100
+ clearFlushTimer();
101
+ batchQueue.push(pendingLogs.splice(0, pendingLogs.length));
102
+ processWriteQueue();
103
+ }
104
+
105
+ function scheduleFlush() {
106
+ if (pendingLogs.length === 0 || flushTimer) return;
107
+
108
+ flushTimer = setTimeout(function() {
109
+ flushTimer = null;
110
+ flushPendingLogs();
111
+ }, REPORT_INTERVAL_MS);
112
+ }
113
+
114
+ // Process batch queue to ensure sequential writes
24
115
  function processWriteQueue() {
25
- if (isWriting || writeQueue.length === 0) return;
116
+ if (isWriting || batchQueue.length === 0) return;
26
117
 
27
118
  isWriting = true;
28
- var entry = writeQueue.shift();
29
- var logText = JSON.stringify(entry);
119
+ var batch = batchQueue.shift();
120
+ var logText = JSON.stringify(batch);
30
121
 
31
122
  __originalFetch__(LOG_API_PATH, {
32
123
  method: 'POST',
@@ -38,13 +129,13 @@ if (typeof window !== 'undefined') {
38
129
  if (!response.ok) {
39
130
  console.warn('[BrowserLogs] Failed to write log:', response.status);
40
131
  }
41
- // Continue processing next item in queue
132
+ // Continue processing next batch in queue
42
133
  processWriteQueue();
43
134
  })
44
135
  .catch(function(error) {
45
136
  console.warn('[BrowserLogs] Failed to write log:', error.message);
46
- // On failure, put log back to queue head for retry
47
- writeQueue.unshift(entry);
137
+ // On failure, put batch back to queue head for retry
138
+ batchQueue.unshift(batch);
48
139
  isWriting = false;
49
140
  // Retry after delay
50
141
  setTimeout(processWriteQueue, 1000);
@@ -96,11 +187,21 @@ if (typeof window !== 'undefined') {
96
187
  return truncated;
97
188
  }
98
189
 
99
- // Add log and send immediately (ensure order)
190
+ // Add log to batch buffer. Flush when batch is full, or after a short delay if it has content.
100
191
  function addLog(entry) {
101
192
  var truncatedEntry = truncateLogEntry(entry);
102
- writeQueue.push(truncatedEntry);
103
- processWriteQueue();
193
+ if (shouldSkipDuplicate(truncatedEntry)) {
194
+ return;
195
+ }
196
+
197
+ pendingLogs.push(truncatedEntry);
198
+
199
+ if (pendingLogs.length >= MAX_REPORT_BATCH_SIZE) {
200
+ flushPendingLogs();
201
+ return;
202
+ }
203
+
204
+ scheduleFlush();
104
205
  }
105
206
 
106
207
  // ============================================
@@ -660,12 +761,18 @@ if (typeof window !== 'undefined') {
660
761
  // Send remaining logs on page unload
661
762
  // ============================================
662
763
  window.addEventListener('beforeunload', function() {
663
- if (writeQueue.length > 0) {
764
+ if (pendingLogs.length > 0) {
765
+ batchQueue.push(pendingLogs.splice(0, pendingLogs.length));
766
+ }
767
+
768
+ clearFlushTimer();
769
+
770
+ if (batchQueue.length > 0) {
664
771
  // Use sendBeacon to ensure logs are sent
665
- writeQueue.forEach(function(entry) {
666
- navigator.sendBeacon(LOG_API_PATH, JSON.stringify(entry));
772
+ batchQueue.forEach(function(batch) {
773
+ navigator.sendBeacon(LOG_API_PATH, JSON.stringify(batch));
667
774
  });
668
- writeQueue = [];
775
+ batchQueue = [];
669
776
  }
670
777
  });
671
778
 
@@ -674,9 +781,11 @@ if (typeof window !== 'undefined') {
674
781
  // ============================================
675
782
  window.__flushBrowserLogs__ = function() {
676
783
  return new Promise(function(resolve) {
784
+ flushPendingLogs();
785
+
677
786
  // Wait for queue to finish processing
678
787
  function checkQueue() {
679
- if (writeQueue.length === 0 && !isWriting) {
788
+ if (pendingLogs.length === 0 && batchQueue.length === 0 && !isWriting) {
680
789
  resolve();
681
790
  } else {
682
791
  setTimeout(checkQueue, 100);
@@ -688,16 +797,24 @@ if (typeof window !== 'undefined') {
688
797
 
689
798
  // Provide method to get queue status
690
799
  window.__getBrowserLogsStatus__ = function() {
800
+ var queuedLogCount = pendingLogs.length;
801
+ for (var i = 0; i < batchQueue.length; i++) {
802
+ queuedLogCount += batchQueue[i].length;
803
+ }
804
+
691
805
  return {
692
- queueLength: writeQueue.length,
806
+ queueLength: queuedLogCount,
807
+ pendingLogs: pendingLogs.length,
808
+ batchQueueLength: batchQueue.length,
693
809
  isWriting: isWriting
694
810
  };
695
811
  };
696
812
 
697
813
  originalConsole.log('[BrowserLogs] Log collection started');
698
814
  })();
699
- </script>`;return {name:"vite-plugin-browser-logs",configResolved(r){let t=A.env.WORKSPACE_DIR;if(t)e=d.join(t,"browser.log");else {let o=r.root||A.cwd();for(;o!==d.dirname(o)&&!y.existsSync(d.join(o,"package.json"));)o=d.dirname(o);e=d.join(o,"browser.log");}},configureServer(r){r.middlewares.use((t,o,l)=>{if(t.url==="/__browser__"&&t.method==="POST"){let i=t.headers.origin||"*",c="";t.on("data",u=>{c+=u.toString();}),t.on("end",()=>{try{let u=d.dirname(e);y.existsSync(u)||y.mkdirSync(u,{recursive:!0}),y.appendFileSync(e,`${c}
700
- `,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:!0}));}catch(u){console.error("[BrowserLogs] Write error:",u),o.writeHead(500,{"Content-Type":"application/json","Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:false,error:String(u)}));}});}else if(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:",e);},transformIndexHtml(r){return r.replace(/<head([^>]*)>/i,`<head$1>${n}`)}}}var J=`
815
+ </script>`;return {name:"vite-plugin-browser-logs",configResolved(t){let r=I.env.WORKSPACE_DIR;if(r)e=f.join(r,"browser.log");else {let o=t.root||I.cwd();for(;o!==f.dirname(o)&&!h.existsSync(f.join(o,"package.json"));)o=f.dirname(o);e=f.join(o,"browser.log");}},configureServer(t){t.middlewares.use((r,o,u)=>{if(r.url==="/__browser__"&&r.method==="POST"){let a=r.headers.origin||"*",c="";r.on("data",l=>{c+=l.toString();}),r.on("end",()=>{try{let l=c,d;try{d=JSON.parse(c);}catch{d=null;}Array.isArray(d)?l=d.map(s=>JSON.stringify(s)).join(`
816
+ `):d&&typeof d=="object"&&(l=JSON.stringify(d));let i=f.dirname(e);h.existsSync(i)||h.mkdirSync(i,{recursive:!0}),h.appendFileSync(e,`${l}
817
+ `,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":a,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:!0}));}catch(l){console.error("[BrowserLogs] Write error:",l),o.writeHead(500,{"Content-Type":"application/json","Access-Control-Allow-Origin":a,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:false,error:String(l)}));}});}else if(r.url==="/__browser__"&&r.method==="OPTIONS"){let a=r.headers.origin||"*";o.writeHead(204,{"Access-Control-Allow-Origin":a,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Max-Age":"86400"}),o.end();}else if(r.url==="/__browser__"){let a=r.headers.origin||"*";o.writeHead(405,{"Content-Type":"application/json","Access-Control-Allow-Origin":a}),o.end(JSON.stringify({error:"Method not allowed"}));}else u();}),console.log("[BrowserLogs] Logs will be written to:",e);},transformIndexHtml(t){return t.replace(/<head([^>]*)>/i,`<head$1>${n}`)}}}var J=`
701
818
  import * as React from "react";
702
819
  import * as ReactJSXDevRuntime from "react/jsx-dev-runtime";
703
820
 
@@ -879,14 +996,14 @@ export function jsxDEV(type, props, key, isStatic, source, self) {
879
996
 
880
997
  return _jsxDEV(type, props, key, isStatic, source, self);
881
998
  }
882
- `;function S(){let e=false,n="";return {name:"vite-plugin-jsx-source-tagger",enforce:"pre",configResolved(r){e=r.command==="serve",n=r.root;},resolveId(r,t){return e&&r==="react/jsx-dev-runtime"&&!t?.includes("\0jsx-source")?"\0jsx-source/jsx-dev-runtime":null},load(r){return e&&r==="\0jsx-source/jsx-dev-runtime"?J.replace('const PROJECT_ROOT = "";',`const PROJECT_ROOT = ${JSON.stringify(n)};`):null}}}function b(e){let n="",r=false,t=null,o=null,l=e?.configPath||"./tailwind.config.ts",i="@amaster/tailwind-config",c="\0"+i,u=async()=>{let a=d.resolve(n,l);try{return await w.access(a),a}catch{if(l.endsWith(".ts")){let s=a.replace(/\.ts$/,".js");try{return await w.access(s),s}catch{return null}}else if(l.endsWith(".js")){let s=a.replace(/\.js$/,".ts");try{return await w.access(s),s}catch{return null}}return null}},v=async a=>{try{let s=await u();if(!s)return null;if(a){let O=await a.ssrLoadModule(s);return t=O.default||O,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,r=a.command==="serve";},async buildStart(){r&&await v();},resolveId(a){if(a===i)return c},async load(a){if(a===c)return await v(o),t?`
999
+ `;function S(){let e=false,n="";return {name:"vite-plugin-jsx-source-tagger",enforce:"pre",configResolved(t){e=t.command==="serve",n=t.root;},resolveId(t,r){return e&&t==="react/jsx-dev-runtime"&&!r?.includes("\0jsx-source")?"\0jsx-source/jsx-dev-runtime":null},load(t){return e&&t==="\0jsx-source/jsx-dev-runtime"?J.replace('const PROJECT_ROOT = "";',`const PROJECT_ROOT = ${JSON.stringify(n)};`):null}}}function w(e){let n="",t=false,r=null,o=null,u=e?.configPath||"./tailwind.config.ts",a="@amaster/tailwind-config",c="\0"+a,l=async()=>{let i=f.resolve(n,u);try{return await _.access(i),i}catch{if(u.endsWith(".ts")){let s=i.replace(/\.ts$/,".js");try{return await _.access(s),s}catch{return null}}else if(u.endsWith(".js")){let s=i.replace(/\.js$/,".ts");try{return await _.access(s),s}catch{return null}}return null}},d=async i=>{try{let s=await l();if(!s)return null;if(i){let T=await i.ssrLoadModule(s);return r=T.default||T,r}let p=await import(`file://${s}?t=${Date.now()}`);return r=p.default||p,r}catch(s){return console.error("[tailwind-config-sync] Failed to generate config:",s),null}};return {name:"vite-plugin-tailwind-config-sync",configResolved(i){n=i.root,t=i.command==="serve";},async buildStart(){t&&await d();},resolveId(i){if(i===a)return c},async load(i){if(i===c)return await d(o),r?`
883
1000
  // Use global variable to persist callbacks and current config across HMR updates
884
1001
  if (!window.__tailwindConfigCallbacks) {
885
1002
  window.__tailwindConfigCallbacks = [];
886
1003
  }
887
1004
 
888
1005
  // Always update current config with the latest from server
889
- let tailwindConfigCurrent = ${JSON.stringify(t)};
1006
+ let tailwindConfigCurrent = ${JSON.stringify(r)};
890
1007
 
891
1008
  if (import.meta.hot) {
892
1009
  // Accept self updates
@@ -916,14 +1033,14 @@ export function onUpdate(fn) {
916
1033
  };
917
1034
  export default tailwindConfigCurrent;
918
1035
 
919
- `:"export default null;"},configureServer(a){r&&(o=a,(async()=>{try{let s=await u();s&&a.watcher.add(s);}catch{}})());},async handleHotUpdate({file:a,server:s}){let p=await u();if(!p||d.normalize(a)!==d.normalize(p))return;let f=s.moduleGraph.getModuleById(p);f&&s.moduleGraph.invalidateModule(f),await v(s);let g=s.moduleGraph.getModuleById(c);return g?(s.moduleGraph.invalidateModule(g),[g]):[]}}}function x(e={}){let{designWidth:n=375,maxWidth:r=750,baseFontSize:t=12,minRootSize:o=12,maxRootSize:l=24}=e;return {name:"vite-plugin-taro-style-adapter",apply:"serve",transformIndexHtml(i){let c=`
1036
+ `:"export default null;"},configureServer(i){t&&(o=i,(async()=>{try{let s=await l();s&&i.watcher.add(s);}catch{}})());},async handleHotUpdate({file:i,server:s}){let g=await l();if(!g||f.normalize(i)!==f.normalize(g))return;let p=s.moduleGraph.getModuleById(g);p&&s.moduleGraph.invalidateModule(p),await d(s);let m=s.moduleGraph.getModuleById(c);return m?(s.moduleGraph.invalidateModule(m),[m]):[]}}}function E(e={}){let{designWidth:n=375,maxWidth:t=750,baseFontSize:r=12,minRootSize:o=12,maxRootSize:u=24}=e;return {name:"vite-plugin-taro-style-adapter",apply:"serve",transformIndexHtml(a){let c=`
920
1037
  <script data-taro-flexible="true">
921
1038
  (function() {
922
1039
  var designWidth = ${n};
923
- var maxWidth = ${r};
924
- var baseFontSize = ${t};
1040
+ var maxWidth = ${t};
1041
+ var baseFontSize = ${r};
925
1042
  var minRootSize = ${o};
926
- var maxRootSize = ${l};
1043
+ var maxRootSize = ${u};
927
1044
 
928
1045
  function setRootFontSize() {
929
1046
  var docEl = document.documentElement;
@@ -957,7 +1074,7 @@ export default tailwindConfigCurrent;
957
1074
  document.addEventListener('DOMContentLoaded', setRootFontSize);
958
1075
  })();
959
1076
  </script>
960
- `;return i.replace("</head>",`${c}
1077
+ `;return a.replace("</head>",`${c}
961
1078
  <style data-taro-adapter="true">
962
1079
  /* \u4EC5 H5 \u751F\u6548\uFF1A\u9690\u85CF Taro \u9875\u9762\u5BB9\u5668\u6EDA\u52A8\u6761\uFF0C\u4F46\u4ECD\u53EF\u6EDA\u52A8 */
963
1080
  .taro_page {
@@ -1003,5 +1120,5 @@ export default tailwindConfigCurrent;
1003
1120
  object-fit: contain;
1004
1121
  }
1005
1122
  </style>
1006
- </head>`)}}}function h(e={}){let{ratio:n=2}=e;return {postcssPlugin:"postcss-rpx2px",Declaration(r){r.value?.includes("rpx")&&(r.value=r.value.replace(/(-?\d*\.?\d+)rpx/gi,(t,o)=>{let l=parseFloat(o)/n;return l===0?"0":`${l}px`}));}}}h.postcss=true;var $=/(-?\d*\.?\d+)rpx/gi,K=k.default??k,Y=L.default??L;function E(e,n){return e.replace($,(r,t)=>{let o=Number.parseFloat(t)/n;return o===0?"0":`${o}px`})}function G(e,n){if(!e.value.includes("rpx"))return false;let r=E(e.value,n);return r===e.value?false:(e.value=r,e.extra?.raw&&(e.extra.rawValue=r,e.extra.raw=JSON.stringify(r)),true)}function Q(e,n){let r=e.value.raw;if(!r.includes("rpx"))return false;let t=E(r,n),o=e.value.cooked==null?void 0:E(e.value.cooked,n);return t===r&&o===e.value.cooked?false:(e.value.raw=t,e.value.cooked=o,true)}function Z(e){return e.name.type==="JSXIdentifier"&&e.name.name==="style"}function ee(e,n){let r=false;return e.traverse({StringLiteral(t){G(t.node,n)&&(r=true);},TemplateElement(t){Q(t.node,n)&&(r=true);}}),r}function D(e,n=2){let r=parse(e,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:true}),t=false;return Y(r,{JSXAttribute(o){if(!Z(o.node)||o.node.value?.type!=="JSXExpressionContainer")return;let l=o.get("value");l.isJSXExpressionContainer()&&ee(l,n)&&(t=true);}}),t?{changed:true,code:K(r,{retainLines:true,decoratorsBeforeExport:true,jsescOption:{minimal:true}},e).code}:{changed:false,code:e}}function R(e={}){let{ratio:n=2}=e;return {name:"vite-plugin-jsx-inline-style-rpx",enforce:"pre",transform(r,t){if(process.env.TARO_ENV!=="h5"||!/\.[jt]sx($|\?)/.test(t))return null;let o=D(r,n);return o.changed?{code:o.code,map:null}:null}}}function re(e={}){let{additional:n=[],autoInjectTaroApp:r=true,autoInjectVite:t=true}=e,o={},l=new Set(n);return r&&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 c=process.env[i]||"";o[`process.env.${i}`]=JSON.stringify(c);}),o}function te(){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 ne(e={}){let n=e.isTaro??A.env.TARO_ENV==="h5",r=[C(),I()];return e.jsxSourceTagger!==false&&r.push(S()),e.tailwindConfigSync!==false&&r.push(b({configPath:e.tailwindConfigPath})),n&&(r.unshift(R()),r.unshift(x(e.styleAdapter)),r.unshift({name:"dev-postcss-rpx2px-plugin",apply:"serve",config(t){typeof t.css?.postcss=="object"&&t.css?.postcss.plugins?.unshift(h());}})),A.env.WORKSPACE_GIT_REPO&&r.push(j()),r}export{ne as default,C as editorBridgePlugin,te as injectAmasterEnv,re as injectTaroEnv,R as jsxInlineStyleRpxPlugin,S as jsxSourceTaggerPlugin,I as routesExposePlugin,h as rpx2pxPlugin,b as tailwindConfigSyncPlugin,x as taroStyleAdapterPlugin,D as transformJsxInlineStyleRpx};//# sourceMappingURL=index.js.map
1123
+ </head>`)}}}function v(e={}){let{ratio:n=2}=e;return {postcssPlugin:"postcss-rpx2px",Declaration(t){t.value?.includes("rpx")&&(t.value=t.value.replace(/(-?\d*\.?\d+)rpx/gi,(r,o)=>{let u=parseFloat(o)/n;return u===0?"0":`${u}px`}));}}}v.postcss=true;var K=/(-?\d*\.?\d+)rpx/gi,$=j.default??j,Y=k.default??k;function x(e,n){return e.replace(K,(t,r)=>{let o=Number.parseFloat(r)/n;return o===0?"0":`${o}px`})}function Q(e,n){if(!e.value.includes("rpx"))return false;let t=x(e.value,n);return t===e.value?false:(e.value=t,e.extra?.raw&&(e.extra.rawValue=t,e.extra.raw=JSON.stringify(t)),true)}function G(e,n){let t=e.value.raw;if(!t.includes("rpx"))return false;let r=x(t,n),o=e.value.cooked==null?void 0:x(e.value.cooked,n);return r===t&&o===e.value.cooked?false:(e.value.raw=r,e.value.cooked=o,true)}function Z(e){return e.name.type==="JSXIdentifier"&&e.name.name==="style"}function ee(e,n){let t=false;return e.traverse({StringLiteral(r){Q(r.node,n)&&(t=true);},TemplateElement(r){G(r.node,n)&&(t=true);}}),t}function D(e,n=2){let t=parse(e,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:true}),r=false;return Y(t,{JSXAttribute(o){if(!Z(o.node)||o.node.value?.type!=="JSXExpressionContainer")return;let u=o.get("value");u.isJSXExpressionContainer()&&ee(u,n)&&(r=true);}}),r?{changed:true,code:$(t,{retainLines:true,decoratorsBeforeExport:true,jsescOption:{minimal:true}},e).code}:{changed:false,code:e}}function R(e={}){let{ratio:n=2}=e;return {name:"vite-plugin-jsx-inline-style-rpx",enforce:"pre",transform(t,r){if(process.env.TARO_ENV!=="h5"||!/\.[jt]sx($|\?)/.test(r))return null;let o=D(t,n);return o.changed?{code:o.code,map:null}:null}}}function te(e={}){let{additional:n=[],autoInjectTaroApp:t=true,autoInjectVite:r=true}=e,o={},u=new Set(n);return t&&Object.keys(process.env).forEach(a=>{a.startsWith("TARO_APP_")&&u.add(a);}),r&&Object.keys(process.env).forEach(a=>{a.startsWith("VITE_")&&u.add(a);}),u.forEach(a=>{let c=process.env[a]||"";o[`process.env.${a}`]=JSON.stringify(c);}),o}function re(){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 ne(e={}){let n=e.isTaro??I.env.TARO_ENV==="h5",t=[P(),A()];return e.jsxSourceTagger!==false&&t.push(S()),e.tailwindConfigSync!==false&&t.push(w({configPath:e.tailwindConfigPath})),n&&(t.unshift(R()),t.unshift(E(e.styleAdapter)),t.unshift({name:"dev-postcss-rpx2px-plugin",apply:"serve",config(r){typeof r.css?.postcss=="object"&&r.css?.postcss.plugins?.unshift(v());}})),I.env.WORKSPACE_GIT_REPO&&t.push(L()),t}export{ne as default,P as editorBridgePlugin,re as injectAmasterEnv,te as injectTaroEnv,R as jsxInlineStyleRpxPlugin,S as jsxSourceTaggerPlugin,A as routesExposePlugin,v as rpx2pxPlugin,w as tailwindConfigSyncPlugin,E as taroStyleAdapterPlugin,D as transformJsxInlineStyleRpx};//# sourceMappingURL=index.js.map
1007
1124
  //# sourceMappingURL=index.js.map