@amaster.ai/vite-plugins 1.0.0-beta.7 → 1.0.0-beta.73
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 +153 -0
- package/dist/bridge-module.global.js +14 -0
- package/dist/index.cjs +489 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +251 -10
- package/dist/index.d.ts +251 -10
- package/dist/index.js +489 -28
- package/dist/index.js.map +1 -1
- package/package.json +25 -5
- package/dist/bridge.bridge.js +0 -24
package/dist/index.cjs
CHANGED
|
@@ -1,30 +1,11 @@
|
|
|
1
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var
|
|
2
|
-
|
|
3
|
-
const element = e.target;
|
|
4
|
-
const noJumpOut = document.body.classList.contains("forbid-jump-out")
|
|
5
|
-
if (element.hasAttribute("data-link-href") && !noJumpOut) {
|
|
6
|
-
const href = element.getAttribute("data-link-href");
|
|
7
|
-
const target = element.getAttribute("data-link-target");
|
|
8
|
-
if (href) {
|
|
9
|
-
if (target === "_blank") {
|
|
10
|
-
window.open(href, "_blank");
|
|
11
|
-
} else {
|
|
12
|
-
window.location.href = href;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
} else if(noJumpOut && element.tagName === "A") {
|
|
16
|
-
e.preventDefault();
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
</script>`;function H(){try{let r=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(r),n=b.resolve(e,"../dist/bridge.bridge.js");return `<script>
|
|
20
|
-
${f.readFileSync(n,"utf-8")}
|
|
21
|
-
</script>`}catch(r){return console.warn("Failed to read bridge script:",r),""}}function h(){let r=false,e="";return {name:"vite-plugin-editor-bridge",configResolved(n){r=n.command==="serve",r&&(e=H());},transformIndexHtml(n){let o=`${I}${r?e:""}</body>`;return n.replace("</body>",o)}}}function v(r){let e=false,n=r?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(t){e=t.command==="serve";},transform(t,o){if(!e||!o.endsWith(n))return null;try{return t.includes("window.__APP_ROUTES__")?null:{code:`${t}
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var y=require('fs'),d=require('path'),url=require('url'),A=require('process'),w=require('fs/promises'),k=require('@babel/generator'),parser=require('@babel/parser'),L=require('@babel/traverse');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var y__default=/*#__PURE__*/_interopDefault(y);var d__default=/*#__PURE__*/_interopDefault(d);var A__default=/*#__PURE__*/_interopDefault(A);var w__default=/*#__PURE__*/_interopDefault(w);var k__default=/*#__PURE__*/_interopDefault(k);var L__default=/*#__PURE__*/_interopDefault(L);var F=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))),U=d.dirname(F),P="@amaster/bridge-monitor",T="\0"+P,m=null;function z(){if(m)return m;try{let e=d.resolve(U,"../dist/bridge-module.global.js");return m=y.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}
|
|
22
3
|
|
|
23
4
|
// Development mode: Expose routes to window.__APP_ROUTES__
|
|
24
5
|
if (typeof window !== 'undefined') {
|
|
25
6
|
window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];
|
|
26
7
|
}
|
|
27
|
-
`,map:null}}catch{return null}}}}function
|
|
8
|
+
`,map:null}}catch{return null}}}}function j(){let e="",n=`
|
|
28
9
|
<script>
|
|
29
10
|
(function() {
|
|
30
11
|
'use strict';
|
|
@@ -32,6 +13,9 @@ if (typeof window !== 'undefined') {
|
|
|
32
13
|
// Log API path (provided by Vite dev server)
|
|
33
14
|
var LOG_API_PATH = '/__browser__';
|
|
34
15
|
|
|
16
|
+
// Save original fetch before any interception, used exclusively for log writing
|
|
17
|
+
var __originalFetch__ = window.fetch.bind(window);
|
|
18
|
+
|
|
35
19
|
// Write queue to ensure sequential writes
|
|
36
20
|
var writeQueue = [];
|
|
37
21
|
var isWriting = false;
|
|
@@ -44,7 +28,7 @@ if (typeof window !== 'undefined') {
|
|
|
44
28
|
var entry = writeQueue.shift();
|
|
45
29
|
var logText = JSON.stringify(entry);
|
|
46
30
|
|
|
47
|
-
|
|
31
|
+
__originalFetch__(LOG_API_PATH, {
|
|
48
32
|
method: 'POST',
|
|
49
33
|
headers: { 'Content-Type': 'application/json' },
|
|
50
34
|
body: logText
|
|
@@ -162,12 +146,19 @@ if (typeof window !== 'undefined') {
|
|
|
162
146
|
};
|
|
163
147
|
}
|
|
164
148
|
|
|
165
|
-
//
|
|
149
|
+
// Keywords to filter from console log collection
|
|
150
|
+
var FILTERED_CONSOLE_KEYWORDS = ['[vite]', '[BrowserLogs]'];
|
|
151
|
+
|
|
152
|
+
// Check if message should be filtered
|
|
166
153
|
function shouldFilterConsoleLog(args) {
|
|
167
154
|
for (var i = 0; i < args.length; i++) {
|
|
168
155
|
var arg = args[i];
|
|
169
|
-
if (typeof arg === 'string'
|
|
170
|
-
|
|
156
|
+
if (typeof arg === 'string') {
|
|
157
|
+
for (var j = 0; j < FILTERED_CONSOLE_KEYWORDS.length; j++) {
|
|
158
|
+
if (arg.indexOf(FILTERED_CONSOLE_KEYWORDS[j]) !== -1) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
171
162
|
}
|
|
172
163
|
}
|
|
173
164
|
return false;
|
|
@@ -490,6 +481,170 @@ if (typeof window !== 'undefined') {
|
|
|
490
481
|
addLog(entry);
|
|
491
482
|
});
|
|
492
483
|
|
|
484
|
+
// ============================================
|
|
485
|
+
// Vite deps 504 error capture using PerformanceObserver
|
|
486
|
+
// Only captures 504 errors for node_modules/.vite resources (pre-bundled dependencies)
|
|
487
|
+
// ============================================
|
|
488
|
+
var reportedUrls = {}; // Track reported URLs to avoid duplicates
|
|
489
|
+
|
|
490
|
+
if (typeof PerformanceObserver !== 'undefined') {
|
|
491
|
+
var perfObserver = new PerformanceObserver(function(list) {
|
|
492
|
+
var entries = list.getEntries();
|
|
493
|
+
for (var i = 0; i < entries.length; i++) {
|
|
494
|
+
var perfEntry = entries[i];
|
|
495
|
+
// Only check script resources
|
|
496
|
+
if (perfEntry.initiatorType !== 'script') {
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
var resourceUrl = perfEntry.name || '';
|
|
501
|
+
// Only report errors for node_modules/.vite resources
|
|
502
|
+
if (resourceUrl.indexOf('node_modules/.vite') === -1 && resourceUrl.indexOf('/node_modules/.vite') === -1) {
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// Check if response status is 504 (Gateway Timeout)
|
|
507
|
+
// responseStatus is available in Resource Timing Level 2
|
|
508
|
+
var status = perfEntry.responseStatus;
|
|
509
|
+
if (status === 504) {
|
|
510
|
+
// Avoid duplicate reports
|
|
511
|
+
if (reportedUrls[resourceUrl]) {
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
reportedUrls[resourceUrl] = true;
|
|
515
|
+
|
|
516
|
+
var entry = {
|
|
517
|
+
type: 'vite-deps-error',
|
|
518
|
+
timestamp: new Date().toISOString(),
|
|
519
|
+
level: 'error',
|
|
520
|
+
url: resourceUrl,
|
|
521
|
+
status: 504,
|
|
522
|
+
message: 'Vite pre-bundled dependency returned 504 Gateway Timeout: ' + resourceUrl,
|
|
523
|
+
duration: perfEntry.duration,
|
|
524
|
+
transferSize: perfEntry.transferSize
|
|
525
|
+
};
|
|
526
|
+
addLog(entry);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
try {
|
|
532
|
+
perfObserver.observe({ type: 'resource', buffered: true });
|
|
533
|
+
} catch (e) {
|
|
534
|
+
// Fallback for browsers that don't support the options
|
|
535
|
+
try {
|
|
536
|
+
perfObserver.observe({ entryTypes: ['resource'] });
|
|
537
|
+
} catch (e2) {
|
|
538
|
+
originalConsole.warn('[BrowserLogs] PerformanceObserver not supported:', e2.message);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// ============================================
|
|
544
|
+
// Script load error capture (for 504 and other network errors)
|
|
545
|
+
// This captures errors that PerformanceObserver might miss
|
|
546
|
+
// ============================================
|
|
547
|
+
|
|
548
|
+
// Use MutationObserver to watch for dynamically added script tags
|
|
549
|
+
function attachScriptErrorHandler(script) {
|
|
550
|
+
if (script.__errorHandlerAttached__) return;
|
|
551
|
+
script.__errorHandlerAttached__ = true;
|
|
552
|
+
|
|
553
|
+
script.addEventListener('error', function(event) {
|
|
554
|
+
var src = script.src || '';
|
|
555
|
+
|
|
556
|
+
// Only report errors for node_modules/.vite resources
|
|
557
|
+
if (src.indexOf('node_modules/.vite') === -1 && src.indexOf('/node_modules/.vite') === -1) {
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// Avoid duplicate reports
|
|
562
|
+
if (reportedUrls[src]) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
reportedUrls[src] = true;
|
|
566
|
+
|
|
567
|
+
var entry = {
|
|
568
|
+
type: 'vite-deps-error',
|
|
569
|
+
timestamp: new Date().toISOString(),
|
|
570
|
+
level: 'error',
|
|
571
|
+
url: src,
|
|
572
|
+
status: 'load-error',
|
|
573
|
+
message: 'Vite pre-bundled dependency failed to load (possibly 504 Gateway Timeout): ' + src,
|
|
574
|
+
errorType: event.type
|
|
575
|
+
};
|
|
576
|
+
addLog(entry);
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// Attach error handlers to existing scripts
|
|
581
|
+
var existingScripts = document.querySelectorAll('script[src]');
|
|
582
|
+
for (var i = 0; i < existingScripts.length; i++) {
|
|
583
|
+
attachScriptErrorHandler(existingScripts[i]);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// Watch for dynamically added scripts
|
|
587
|
+
if (typeof MutationObserver !== 'undefined') {
|
|
588
|
+
var scriptObserver = new MutationObserver(function(mutations) {
|
|
589
|
+
for (var i = 0; i < mutations.length; i++) {
|
|
590
|
+
var mutation = mutations[i];
|
|
591
|
+
for (var j = 0; j < mutation.addedNodes.length; j++) {
|
|
592
|
+
var node = mutation.addedNodes[j];
|
|
593
|
+
if (node.nodeName === 'SCRIPT' && node.src) {
|
|
594
|
+
attachScriptErrorHandler(node);
|
|
595
|
+
}
|
|
596
|
+
// Also check child nodes
|
|
597
|
+
if (node.querySelectorAll) {
|
|
598
|
+
var scripts = node.querySelectorAll('script[src]');
|
|
599
|
+
for (var k = 0; k < scripts.length; k++) {
|
|
600
|
+
attachScriptErrorHandler(scripts[k]);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
scriptObserver.observe(document.documentElement, {
|
|
608
|
+
childList: true,
|
|
609
|
+
subtree: true
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// Also intercept document.createElement to catch scripts before they're added to DOM
|
|
614
|
+
var originalCreateElement = document.createElement.bind(document);
|
|
615
|
+
document.createElement = function(tagName) {
|
|
616
|
+
var element = originalCreateElement(tagName);
|
|
617
|
+
if (tagName.toLowerCase() === 'script') {
|
|
618
|
+
// Use a setter to catch when src is set
|
|
619
|
+
var originalSrc = '';
|
|
620
|
+
Object.defineProperty(element, '__originalSrc__', {
|
|
621
|
+
get: function() { return originalSrc; },
|
|
622
|
+
set: function(val) { originalSrc = val; }
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
// Defer attaching error handler until src is set
|
|
626
|
+
var srcDescriptor = Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src');
|
|
627
|
+
if (srcDescriptor && srcDescriptor.set) {
|
|
628
|
+
var originalSrcSetter = srcDescriptor.set;
|
|
629
|
+
Object.defineProperty(element, 'src', {
|
|
630
|
+
get: function() {
|
|
631
|
+
return srcDescriptor.get ? srcDescriptor.get.call(this) : this.getAttribute('src');
|
|
632
|
+
},
|
|
633
|
+
set: function(value) {
|
|
634
|
+
if (originalSrcSetter) {
|
|
635
|
+
originalSrcSetter.call(this, value);
|
|
636
|
+
} else {
|
|
637
|
+
this.setAttribute('src', value);
|
|
638
|
+
}
|
|
639
|
+
attachScriptErrorHandler(this);
|
|
640
|
+
},
|
|
641
|
+
configurable: true
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return element;
|
|
646
|
+
};
|
|
647
|
+
|
|
493
648
|
window.addEventListener('unhandledrejection', function(event) {
|
|
494
649
|
var entry = {
|
|
495
650
|
type: 'error',
|
|
@@ -541,6 +696,312 @@ if (typeof window !== 'undefined') {
|
|
|
541
696
|
|
|
542
697
|
originalConsole.log('[BrowserLogs] Log collection started');
|
|
543
698
|
})();
|
|
544
|
-
</script>`;return {name:"vite-plugin-browser-logs",configResolved(
|
|
545
|
-
`,"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(
|
|
699
|
+
</script>`;return {name:"vite-plugin-browser-logs",configResolved(r){let t=A__default.default.env.WORKSPACE_DIR;if(t)e=d__default.default.join(t,"browser.log");else {let o=r.root||A__default.default.cwd();for(;o!==d__default.default.dirname(o)&&!y__default.default.existsSync(d__default.default.join(o,"package.json"));)o=d__default.default.dirname(o);e=d__default.default.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__default.default.dirname(e);y__default.default.existsSync(u)||y__default.default.mkdirSync(u,{recursive:!0}),y__default.default.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=`
|
|
701
|
+
import * as React from "react";
|
|
702
|
+
import * as ReactJSXDevRuntime from "react/jsx-dev-runtime";
|
|
703
|
+
|
|
704
|
+
const _jsxDEV = ReactJSXDevRuntime.jsxDEV;
|
|
705
|
+
export const Fragment = ReactJSXDevRuntime.Fragment;
|
|
706
|
+
|
|
707
|
+
const SOURCE_KEY = Symbol.for("__jsxSource__");
|
|
708
|
+
const PROJECT_ROOT = "";
|
|
709
|
+
|
|
710
|
+
const cleanFileName = (fileName) => {
|
|
711
|
+
if (!fileName) return "";
|
|
712
|
+
// Remove project root prefix to get relative path
|
|
713
|
+
if (PROJECT_ROOT && fileName.startsWith(PROJECT_ROOT)) {
|
|
714
|
+
const relative = fileName.slice(PROJECT_ROOT.length);
|
|
715
|
+
return relative.startsWith("/") ? relative.slice(1) : relative;
|
|
716
|
+
}
|
|
717
|
+
return fileName;
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
// Global map to track elements by source location
|
|
721
|
+
const sourceElementMap = new Map();
|
|
722
|
+
window.sourceElementMap = sourceElementMap;
|
|
723
|
+
|
|
724
|
+
function getSourceKey(sourceInfo) {
|
|
725
|
+
return \`\${cleanFileName(sourceInfo.fileName)}:\${sourceInfo.lineNumber}:\${sourceInfo.columnNumber}\`;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
function unregisterElement(node, sourceInfo) {
|
|
729
|
+
const key = getSourceKey(sourceInfo);
|
|
730
|
+
const refs = sourceElementMap.get(key);
|
|
731
|
+
if (refs) {
|
|
732
|
+
for (const ref of refs) {
|
|
733
|
+
if (ref.deref() === node) {
|
|
734
|
+
refs.delete(ref);
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (refs.size === 0) {
|
|
739
|
+
sourceElementMap.delete(key);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function registerElement(node, sourceInfo) {
|
|
745
|
+
const key = getSourceKey(sourceInfo);
|
|
746
|
+
if (!sourceElementMap.has(key)) {
|
|
747
|
+
sourceElementMap.set(key, new Set());
|
|
748
|
+
}
|
|
749
|
+
sourceElementMap.get(key).add(new WeakRef(node));
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
function getTypeName(type) {
|
|
753
|
+
if (typeof type === "string") return type;
|
|
754
|
+
if (typeof type === "function") return type.displayName || type.name || "Unknown";
|
|
755
|
+
if (typeof type === "object" && type !== null) {
|
|
756
|
+
return type.displayName || type.render?.displayName || type.render?.name || "Unknown";
|
|
757
|
+
}
|
|
758
|
+
return "Unknown";
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
export function jsxDEV(type, props, key, isStatic, source, self) {
|
|
762
|
+
// For custom components, tag their rendered output
|
|
763
|
+
if (source?.fileName && typeof type !== "string" && type !== Fragment) {
|
|
764
|
+
const typeName = getTypeName(type);
|
|
765
|
+
const fileName = cleanFileName(source.fileName);
|
|
766
|
+
|
|
767
|
+
const jsxSourceInfo = {
|
|
768
|
+
fileName,
|
|
769
|
+
lineNumber: source.lineNumber,
|
|
770
|
+
columnNumber: source.columnNumber,
|
|
771
|
+
displayName: typeName,
|
|
772
|
+
isComponent: true,
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
const originalRef = props?.ref;
|
|
776
|
+
|
|
777
|
+
// Check if component can safely receive refs
|
|
778
|
+
// - forwardRef components have $$typeof symbol
|
|
779
|
+
// - Class components have prototype.isReactComponent
|
|
780
|
+
// - If there's already a ref, the component expects it
|
|
781
|
+
const isForwardRef = type.$$typeof === Symbol.for('react.forward_ref');
|
|
782
|
+
const isClassComponent = typeof type === 'function' && type.prototype?.isReactComponent;
|
|
783
|
+
const hasExistingRef = originalRef !== undefined;
|
|
784
|
+
|
|
785
|
+
const canReceiveRef = isForwardRef || isClassComponent || hasExistingRef;
|
|
786
|
+
|
|
787
|
+
if (canReceiveRef) {
|
|
788
|
+
const enhancedProps = {
|
|
789
|
+
...props,
|
|
790
|
+
ref: (node) => {
|
|
791
|
+
if (node) {
|
|
792
|
+
const existingSource = node[SOURCE_KEY];
|
|
793
|
+
if (existingSource) {
|
|
794
|
+
// \u7EC4\u4EF6\u7EA7\u7684 source \u603B\u662F\u8986\u76D6\u5143\u7D20\u7EA7\u7684 source
|
|
795
|
+
if (!existingSource.isComponent) {
|
|
796
|
+
unregisterElement(node, existingSource);
|
|
797
|
+
node[SOURCE_KEY] = jsxSourceInfo;
|
|
798
|
+
registerElement(node, jsxSourceInfo);
|
|
799
|
+
}
|
|
800
|
+
} else {
|
|
801
|
+
node[SOURCE_KEY] = jsxSourceInfo;
|
|
802
|
+
registerElement(node, jsxSourceInfo);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
if (typeof originalRef === "function") {
|
|
806
|
+
originalRef(node);
|
|
807
|
+
} else if (originalRef && typeof originalRef === "object") {
|
|
808
|
+
originalRef.current = node;
|
|
809
|
+
}
|
|
810
|
+
},
|
|
811
|
+
};
|
|
812
|
+
return _jsxDEV(type, enhancedProps, key, isStatic, source, self);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
return _jsxDEV(type, props, key, isStatic, source, self);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// For host elements (div, span, etc.), tag with source info
|
|
819
|
+
if (source?.fileName && typeof type === "string") {
|
|
820
|
+
const fileName = cleanFileName(source.fileName);
|
|
821
|
+
|
|
822
|
+
// \u5224\u65AD\u5F53\u524D\u5143\u7D20\u662F\u5426\u5728\u7EC4\u4EF6\u5E93\u4E2D\u5B9A\u4E49
|
|
823
|
+
const isInLibrary = fileName.includes('src/components/ui/') ||
|
|
824
|
+
fileName.includes('node_modules');
|
|
825
|
+
|
|
826
|
+
// \u7EC4\u4EF6\u5E93\u5185\u90E8\u7684\u5143\u7D20\u4E0D\u6807\u8BB0\uFF0C\u4E0D\u652F\u6301\u53EF\u89C6\u5316\u7F16\u8F91
|
|
827
|
+
if (isInLibrary) {
|
|
828
|
+
return _jsxDEV(type, props, key, isStatic, source, self);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
const sourceInfo = {
|
|
832
|
+
fileName,
|
|
833
|
+
lineNumber: source.lineNumber,
|
|
834
|
+
columnNumber: source.columnNumber,
|
|
835
|
+
displayName: type,
|
|
836
|
+
isComponent: false, // \u6807\u8BB0\u8FD9\u662F\u5143\u7D20\u7EA7\u522B\u7684 source
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
const originalRef = props?.ref;
|
|
840
|
+
|
|
841
|
+
const enhancedProps = {
|
|
842
|
+
...props,
|
|
843
|
+
ref: (node) => {
|
|
844
|
+
if (node) {
|
|
845
|
+
const existingSource = node[SOURCE_KEY];
|
|
846
|
+
// \u5982\u679C\u5DF2\u6709 source\uFF0C\u68C0\u67E5\u662F\u5426\u5E94\u8BE5\u4FDD\u7559\u5916\u5C42\u7684
|
|
847
|
+
if (existingSource) {
|
|
848
|
+
// \u5982\u679C\u5DF2\u6709\u7684\u662F\u7EC4\u4EF6\u7EA7\u522B\u7684 source\uFF08isComponent: true\uFF09\uFF0C\u4FDD\u7559\u5B83
|
|
849
|
+
if (existingSource.isComponent) {
|
|
850
|
+
// \u4E0D\u66F4\u65B0\uFF0C\u4FDD\u7559\u7EC4\u4EF6\u7EA7\u522B\u7684 source
|
|
851
|
+
if (typeof originalRef === "function") {
|
|
852
|
+
originalRef(node);
|
|
853
|
+
} else if (originalRef && typeof originalRef === "object") {
|
|
854
|
+
originalRef.current = node;
|
|
855
|
+
}
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// \u5426\u5219\u6309\u6B63\u5E38\u903B\u8F91\u66F4\u65B0
|
|
860
|
+
if (getSourceKey(existingSource) !== getSourceKey(sourceInfo)) {
|
|
861
|
+
unregisterElement(node, existingSource);
|
|
862
|
+
node[SOURCE_KEY] = sourceInfo;
|
|
863
|
+
registerElement(node, sourceInfo);
|
|
864
|
+
}
|
|
865
|
+
} else {
|
|
866
|
+
node[SOURCE_KEY] = sourceInfo;
|
|
867
|
+
registerElement(node, sourceInfo);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
if (typeof originalRef === "function") {
|
|
871
|
+
originalRef(node);
|
|
872
|
+
} else if (originalRef && typeof originalRef === "object") {
|
|
873
|
+
originalRef.current = node;
|
|
874
|
+
}
|
|
875
|
+
},
|
|
876
|
+
};
|
|
877
|
+
return _jsxDEV(type, enhancedProps, key, isStatic, source, self);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
return _jsxDEV(type, props, key, isStatic, source, self);
|
|
881
|
+
}
|
|
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__default.default.resolve(n,l);try{return await w__default.default.access(a),a}catch{if(l.endsWith(".ts")){let s=a.replace(/\.ts$/,".js");try{return await w__default.default.access(s),s}catch{return null}}else if(l.endsWith(".js")){let s=a.replace(/\.js$/,".ts");try{return await w__default.default.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?`
|
|
883
|
+
// Use global variable to persist callbacks and current config across HMR updates
|
|
884
|
+
if (!window.__tailwindConfigCallbacks) {
|
|
885
|
+
window.__tailwindConfigCallbacks = [];
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// Always update current config with the latest from server
|
|
889
|
+
let tailwindConfigCurrent = ${JSON.stringify(t)};
|
|
890
|
+
|
|
891
|
+
if (import.meta.hot) {
|
|
892
|
+
// Accept self updates
|
|
893
|
+
import.meta.hot.accept((newModule) => {
|
|
894
|
+
if (newModule && newModule.default) {
|
|
895
|
+
// Call all update callbacks with the new config from window
|
|
896
|
+
window.__tailwindConfigCallbacks.forEach((callback) => {
|
|
897
|
+
try {
|
|
898
|
+
// Pass the actual config object, not the Proxy
|
|
899
|
+
callback(newModule.default);
|
|
900
|
+
} catch (e) {
|
|
901
|
+
console.error('[TailwindConfig] Callback error:', e);
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
export function onUpdate(fn) {
|
|
909
|
+
window.__tailwindConfigCallbacks.push(fn);
|
|
910
|
+
return () => {
|
|
911
|
+
const index = window.__tailwindConfigCallbacks.indexOf(fn);
|
|
912
|
+
if (index > -1) {
|
|
913
|
+
window.__tailwindConfigCallbacks.splice(index, 1);
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
};
|
|
917
|
+
export default tailwindConfigCurrent;
|
|
918
|
+
|
|
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__default.default.normalize(a)!==d__default.default.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=`
|
|
920
|
+
<script data-taro-flexible="true">
|
|
921
|
+
(function() {
|
|
922
|
+
var designWidth = ${n};
|
|
923
|
+
var maxWidth = ${r};
|
|
924
|
+
var baseFontSize = ${t};
|
|
925
|
+
var minRootSize = ${o};
|
|
926
|
+
var maxRootSize = ${l};
|
|
927
|
+
|
|
928
|
+
function setRootFontSize() {
|
|
929
|
+
var docEl = document.documentElement;
|
|
930
|
+
var clientWidth = docEl.clientWidth;
|
|
931
|
+
|
|
932
|
+
// \u9650\u5236\u6700\u5927\u5BBD\u5EA6
|
|
933
|
+
if (clientWidth > maxWidth) {
|
|
934
|
+
clientWidth = maxWidth;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
// \u8BA1\u7B97\u6839\u5B57\u53F7: (\u5C4F\u5E55\u5BBD\u5EA6 / \u8BBE\u8BA1\u7A3F\u5BBD\u5EA6) * \u57FA\u51C6\u5B57\u53F7
|
|
938
|
+
var fontSize = (clientWidth / designWidth) * baseFontSize;
|
|
939
|
+
|
|
940
|
+
// \u5E94\u7528\u6700\u5C0F/\u6700\u5927\u9650\u5236
|
|
941
|
+
if (fontSize < minRootSize) {
|
|
942
|
+
fontSize = minRootSize;
|
|
943
|
+
} else if (fontSize > maxRootSize) {
|
|
944
|
+
fontSize = maxRootSize;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
docEl.style.fontSize = fontSize + 'px';
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
setRootFontSize();
|
|
951
|
+
|
|
952
|
+
// \u76D1\u542C\u7A97\u53E3\u53D8\u5316
|
|
953
|
+
window.addEventListener('resize', setRootFontSize);
|
|
954
|
+
window.addEventListener('orientationchange', setRootFontSize);
|
|
955
|
+
|
|
956
|
+
// \u9875\u9762\u663E\u793A\u65F6\u91CD\u65B0\u8BA1\u7B97\uFF08\u89E3\u51B3\u67D0\u4E9B\u6D4F\u89C8\u5668\u7684 bug\uFF09
|
|
957
|
+
document.addEventListener('DOMContentLoaded', setRootFontSize);
|
|
958
|
+
})();
|
|
959
|
+
</script>
|
|
960
|
+
`;return i.replace("</head>",`${c}
|
|
961
|
+
<style data-taro-adapter="true">
|
|
962
|
+
/* \u4EC5 H5 \u751F\u6548\uFF1A\u9690\u85CF Taro \u9875\u9762\u5BB9\u5668\u6EDA\u52A8\u6761\uFF0C\u4F46\u4ECD\u53EF\u6EDA\u52A8 */
|
|
963
|
+
.taro_page {
|
|
964
|
+
-ms-overflow-style: none; /* IE/Edge \u8001\u7248 */
|
|
965
|
+
scrollbar-width: none; /* Firefox */
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
.taro_page::-webkit-scrollbar {
|
|
969
|
+
width: 0;
|
|
970
|
+
height: 0;
|
|
971
|
+
display: none; /* Chrome/Safari */
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/* \u9690\u85CF Taro ScrollView \u7EC4\u4EF6\u7684\u6EDA\u52A8\u6761 */
|
|
975
|
+
.taro-scroll-view__scroll-y,
|
|
976
|
+
.taro-scroll-view__scroll-x {
|
|
977
|
+
-ms-overflow-style: none; /* IE/Edge \u8001\u7248 */
|
|
978
|
+
scrollbar-width: none; /* Firefox */
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
.taro-scroll-view__scroll-y::-webkit-scrollbar,
|
|
982
|
+
.taro-scroll-view__scroll-x::-webkit-scrollbar {
|
|
983
|
+
width: 0;
|
|
984
|
+
height: 0;
|
|
985
|
+
display: none; /* Chrome/Safari */
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/*
|
|
989
|
+
* \u4FEE\u590D Taro Image \u7EC4\u4EF6\u5728 H5 \u4E0B\u7684\u5C3A\u5BF8\u95EE\u9898
|
|
990
|
+
*
|
|
991
|
+
* \u95EE\u9898\uFF1ATaro Image \u7EC4\u4EF6\u4F7F\u7528 aspectFit \u6A21\u5F0F\u65F6\uFF0C\u5185\u90E8 img \u4F7F\u7528 max-width/max-height: 100%
|
|
992
|
+
* \u5BFC\u81F4\u5C0F\u5C3A\u5BF8\u56FE\u7247\uFF08\u5982 SVG \u56FE\u6807\uFF09\u65E0\u6CD5\u6309\u6307\u5B9A\u5C3A\u5BF8\u663E\u793A\uFF0C\u53EA\u663E\u793A\u539F\u59CB\u5C3A\u5BF8
|
|
993
|
+
*
|
|
994
|
+
* \u89E3\u51B3\uFF1A\u8BA9 img \u586B\u6EE1 taro-image-core \u5BB9\u5668\uFF0C\u7531\u5BB9\u5668\u63A7\u5236\u5C3A\u5BF8
|
|
995
|
+
*/
|
|
996
|
+
taro-image-core img.taro-img__mode-aspectfit {
|
|
997
|
+
width: 100%;
|
|
998
|
+
height: 100%;
|
|
999
|
+
max-width: none;
|
|
1000
|
+
max-height: none;
|
|
1001
|
+
position: static;
|
|
1002
|
+
transform: none;
|
|
1003
|
+
object-fit: contain;
|
|
1004
|
+
}
|
|
1005
|
+
</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.default.default??k__default.default,Y=L__default.default.default??L__default.default;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=parser.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__default.default.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__default.default.env.WORKSPACE_GIT_REPO&&r.push(j()),r}exports.default=ne;exports.editorBridgePlugin=C;exports.injectAmasterEnv=te;exports.injectTaroEnv=re;exports.jsxInlineStyleRpxPlugin=R;exports.jsxSourceTaggerPlugin=S;exports.routesExposePlugin=I;exports.rpx2pxPlugin=h;exports.tailwindConfigSyncPlugin=b;exports.taroStyleAdapterPlugin=x;exports.transformJsxInlineStyleRpx=D;//# sourceMappingURL=index.cjs.map
|
|
546
1007
|
//# sourceMappingURL=index.cjs.map
|