@metagptx/web-sdk 0.0.52-beta.19 → 0.0.52-beta.22
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/plugins.js +16 -9
- package/package.json +3 -1
package/dist/plugins.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import e from"
|
|
1
|
+
import*as e from"@babel/parser";import*as t from"@babel/parser";import n from"@babel/traverse";import*as r from"@babel/types";import*as i from"@babel/types";import a from"node:fs";import o from"node:path";var s=44,c=59,l=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,u=new Uint8Array(64),d=new Uint8Array(128);for(let e=0;e<l.length;e++){let t=l.charCodeAt(e);u[e]=t,d[t]=e}function f(e,t,n){let r=t-n;r=r<0?-r<<1|1:r<<1;do{let t=r&31;r>>>=5,r>0&&(t|=32),e.write(u[t])}while(r>0);return t}var p=1024*16,m=typeof TextDecoder<`u`?new TextDecoder:typeof Buffer<`u`?{decode(e){let t=Buffer.from(e.buffer,e.byteOffset,e.byteLength);return t.toString()}}:{decode(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return t}},h=class{constructor(){this.pos=0,this.out=``,this.buffer=new Uint8Array(p)}write(e){let{buffer:t}=this;t[this.pos++]=e,this.pos===p&&(this.out+=m.decode(t),this.pos=0)}flush(){let{buffer:e,out:t,pos:n}=this;return n>0?t+m.decode(e.subarray(0,n)):t}};function g(e){let t=new h,n=0,r=0,i=0,a=0;for(let o=0;o<e.length;o++){let l=e[o];if(o>0&&t.write(c),l.length===0)continue;let u=0;for(let e=0;e<l.length;e++){let o=l[e];e>0&&t.write(s),u=f(t,o[0],u),o.length!==1&&(n=f(t,o[1],n),r=f(t,o[2],r),i=f(t,o[3],i),o.length!==4&&(a=f(t,o[4],a)))}}return t.flush()}var _=class e{constructor(t){this.bits=t instanceof e?t.bits.slice():[]}add(e){this.bits[e>>5]|=1<<(e&31)}has(e){return!!(this.bits[e>>5]&1<<(e&31))}},v=class e{constructor(e,t,n){this.start=e,this.end=t,this.original=n,this.intro=``,this.outro=``,this.content=n,this.storeName=!1,this.edited=!1,this.previous=null,this.next=null}appendLeft(e){this.outro+=e}appendRight(e){this.intro+=e}clone(){let t=new e(this.start,this.end,this.original);return t.intro=this.intro,t.outro=this.outro,t.content=this.content,t.storeName=this.storeName,t.edited=this.edited,t}contains(e){return this.start<e&&e<this.end}eachNext(e){let t=this;for(;t;)e(t),t=t.next}eachPrevious(e){let t=this;for(;t;)e(t),t=t.previous}edit(e,t,n){return this.content=e,n||(this.intro=``,this.outro=``),this.storeName=t,this.edited=!0,this}prependLeft(e){this.outro=e+this.outro}prependRight(e){this.intro=e+this.intro}reset(){this.intro=``,this.outro=``,this.edited&&(this.content=this.original,this.storeName=!1,this.edited=!1)}split(t){let n=t-this.start,r=this.original.slice(0,n),i=this.original.slice(n);this.original=r;let a=new e(t,this.end,i);return a.outro=this.outro,this.outro=``,this.end=t,this.edited?(a.edit(``,!1),this.content=``):this.content=r,a.next=this.next,a.next&&(a.next.previous=a),a.previous=this,this.next=a,a}toString(){return this.intro+this.content+this.outro}trimEnd(e){if(this.outro=this.outro.replace(e,``),this.outro.length)return!0;let t=this.content.replace(e,``);if(t.length)return t!==this.content&&(this.split(this.start+t.length).edit(``,void 0,!0),this.edited&&this.edit(t,this.storeName,!0)),!0;if(this.edit(``,void 0,!0),this.intro=this.intro.replace(e,``),this.intro.length)return!0}trimStart(e){if(this.intro=this.intro.replace(e,``),this.intro.length)return!0;let t=this.content.replace(e,``);if(t.length){if(t!==this.content){let e=this.split(this.end-t.length);this.edited&&e.edit(t,this.storeName,!0),this.edit(``,void 0,!0)}return!0}else if(this.edit(``,void 0,!0),this.outro=this.outro.replace(e,``),this.outro.length)return!0}};function y(){return typeof globalThis<`u`&&typeof globalThis.btoa==`function`?e=>globalThis.btoa(unescape(encodeURIComponent(e))):typeof Buffer==`function`?e=>Buffer.from(e,`utf-8`).toString(`base64`):()=>{throw Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.")}}const b=y();var x=class{constructor(e){this.version=3,this.file=e.file,this.sources=e.sources,this.sourcesContent=e.sourcesContent,this.names=e.names,this.mappings=g(e.mappings),e.x_google_ignoreList!==void 0&&(this.x_google_ignoreList=e.x_google_ignoreList),e.debugId!==void 0&&(this.debugId=e.debugId)}toString(){return JSON.stringify(this)}toUrl(){return`data:application/json;charset=utf-8;base64,`+b(this.toString())}};function S(e){let t=e.split(`
|
|
2
|
+
`),n=t.filter(e=>/^\t+/.test(e)),r=t.filter(e=>/^ {2,}/.test(e));if(n.length===0&&r.length===0)return null;if(n.length>=r.length)return` `;let i=r.reduce((e,t)=>{let n=/^ +/.exec(t)[0].length;return Math.min(n,e)},1/0);return Array(i+1).join(` `)}function C(e,t){let n=e.split(/[/\\]/),r=t.split(/[/\\]/);for(n.pop();n[0]===r[0];)n.shift(),r.shift();if(n.length){let e=n.length;for(;e--;)n[e]=`..`}return n.concat(r).join(`/`)}const w=Object.prototype.toString;function T(e){return w.call(e)===`[object Object]`}function E(e){let t=e.split(`
|
|
3
|
+
`),n=[];for(let e=0,r=0;e<t.length;e++)n.push(r),r+=t[e].length+1;return function(e){let t=0,r=n.length;for(;t<r;){let i=t+r>>1;e<n[i]?r=i:t=i+1}let i=t-1,a=e-n[i];return{line:i,column:a}}}const D=/\w/;var O=class{constructor(e){this.hires=e,this.generatedCodeLine=0,this.generatedCodeColumn=0,this.raw=[],this.rawSegments=this.raw[this.generatedCodeLine]=[],this.pending=null}addEdit(e,t,n,r){if(t.length){let i=t.length-1,a=t.indexOf(`
|
|
4
|
+
`,0),o=-1;for(;a>=0&&i>a;){let i=[this.generatedCodeColumn,e,n.line,n.column];r>=0&&i.push(r),this.rawSegments.push(i),this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,o=a,a=t.indexOf(`
|
|
5
|
+
`,a+1)}let s=[this.generatedCodeColumn,e,n.line,n.column];r>=0&&s.push(r),this.rawSegments.push(s),this.advance(t.slice(o+1))}else this.pending&&(this.rawSegments.push(this.pending),this.advance(t));this.pending=null}addUneditedChunk(e,t,n,r,i){let a=t.start,o=!0,s=!1;for(;a<t.end;){if(n[a]===`
|
|
6
|
+
`)r.line+=1,r.column=0,this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,o=!0,s=!1;else{if(this.hires||o||i.has(a)){let t=[this.generatedCodeColumn,e,r.line,r.column];this.hires===`boundary`?D.test(n[a])?s||(this.rawSegments.push(t),s=!0):(this.rawSegments.push(t),s=!1):this.rawSegments.push(t)}r.column+=1,this.generatedCodeColumn+=1,o=!1}a+=1}this.pending=null}advance(e){if(!e)return;let t=e.split(`
|
|
7
|
+
`);if(t.length>1){for(let e=0;e<t.length-1;e++)this.generatedCodeLine++,this.raw[this.generatedCodeLine]=this.rawSegments=[];this.generatedCodeColumn=0}this.generatedCodeColumn+=t[t.length-1].length}};const k=`
|
|
8
|
+
`,A={insertLeft:!1,insertRight:!1,storeName:!1};var j=class e{constructor(e,t={}){let n=new v(0,e.length,e);Object.defineProperties(this,{original:{writable:!0,value:e},outro:{writable:!0,value:``},intro:{writable:!0,value:``},firstChunk:{writable:!0,value:n},lastChunk:{writable:!0,value:n},lastSearchedChunk:{writable:!0,value:n},byStart:{writable:!0,value:{}},byEnd:{writable:!0,value:{}},filename:{writable:!0,value:t.filename},indentExclusionRanges:{writable:!0,value:t.indentExclusionRanges},sourcemapLocations:{writable:!0,value:new _},storedNames:{writable:!0,value:{}},indentStr:{writable:!0,value:void 0},ignoreList:{writable:!0,value:t.ignoreList},offset:{writable:!0,value:t.offset||0}}),this.byStart[0]=n,this.byEnd[e.length]=n}addSourcemapLocation(e){this.sourcemapLocations.add(e)}append(e){if(typeof e!=`string`)throw TypeError(`outro content must be a string`);return this.outro+=e,this}appendLeft(e,t){if(e+=this.offset,typeof t!=`string`)throw TypeError(`inserted content must be a string`);this._split(e);let n=this.byEnd[e];return n?n.appendLeft(t):this.intro+=t,this}appendRight(e,t){if(e+=this.offset,typeof t!=`string`)throw TypeError(`inserted content must be a string`);this._split(e);let n=this.byStart[e];return n?n.appendRight(t):this.outro+=t,this}clone(){let t=new e(this.original,{filename:this.filename,offset:this.offset}),n=this.firstChunk,r=t.firstChunk=t.lastSearchedChunk=n.clone();for(;n;){t.byStart[r.start]=r,t.byEnd[r.end]=r;let e=n.next,i=e&&e.clone();i&&(r.next=i,i.previous=r,r=i),n=e}return t.lastChunk=r,this.indentExclusionRanges&&(t.indentExclusionRanges=this.indentExclusionRanges.slice()),t.sourcemapLocations=new _(this.sourcemapLocations),t.intro=this.intro,t.outro=this.outro,t}generateDecodedMap(e){e||={};let t=0,n=Object.keys(this.storedNames),r=new O(e.hires),i=E(this.original);return this.intro&&r.advance(this.intro),this.firstChunk.eachNext(e=>{let a=i(e.start);e.intro.length&&r.advance(e.intro),e.edited?r.addEdit(t,e.content,a,e.storeName?n.indexOf(e.original):-1):r.addUneditedChunk(t,e,this.original,a,this.sourcemapLocations),e.outro.length&&r.advance(e.outro)}),this.outro&&r.advance(this.outro),{file:e.file?e.file.split(/[/\\]/).pop():void 0,sources:[e.source?C(e.file||``,e.source):e.file||``],sourcesContent:e.includeContent?[this.original]:void 0,names:n,mappings:r.raw,x_google_ignoreList:this.ignoreList?[t]:void 0}}generateMap(e){return new x(this.generateDecodedMap(e))}_ensureindentStr(){this.indentStr===void 0&&(this.indentStr=S(this.original))}_getRawIndentString(){return this._ensureindentStr(),this.indentStr}getIndentString(){return this._ensureindentStr(),this.indentStr===null?` `:this.indentStr}indent(e,t){let n=/^[^\r\n]/gm;if(T(e)&&(t=e,e=void 0),e===void 0&&(this._ensureindentStr(),e=this.indentStr||` `),e===``)return this;t||={};let r={};if(t.exclude){let e=typeof t.exclude[0]==`number`?[t.exclude]:t.exclude;e.forEach(e=>{for(let t=e[0];t<e[1];t+=1)r[t]=!0})}let i=t.indentStart!==!1,a=t=>i?`${e}${t}`:(i=!0,t);this.intro=this.intro.replace(n,a);let o=0,s=this.firstChunk;for(;s;){let t=s.end;if(s.edited)r[o]||(s.content=s.content.replace(n,a),s.content.length&&(i=s.content[s.content.length-1]===`
|
|
9
|
+
`));else for(o=s.start;o<t;){if(!r[o]){let t=this.original[o];t===`
|
|
10
|
+
`?i=!0:t!==`\r`&&i&&(i=!1,o===s.start?s.prependRight(e):(this._splitChunk(s,o),s=s.next,s.prependRight(e)))}o+=1}o=s.end,s=s.next}return this.outro=this.outro.replace(n,a),this}insert(){throw Error(`magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)`)}insertLeft(e,t){return A.insertLeft||(console.warn(`magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead`),A.insertLeft=!0),this.appendLeft(e,t)}insertRight(e,t){return A.insertRight||(console.warn(`magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead`),A.insertRight=!0),this.prependRight(e,t)}move(e,t,n){if(e+=this.offset,t+=this.offset,n+=this.offset,n>=e&&n<=t)throw Error(`Cannot move a selection inside itself`);this._split(e),this._split(t),this._split(n);let r=this.byStart[e],i=this.byEnd[t],a=r.previous,o=i.next,s=this.byStart[n];if(!s&&i===this.lastChunk)return this;let c=s?s.previous:this.lastChunk;return a&&(a.next=o),o&&(o.previous=a),c&&(c.next=r),s&&(s.previous=i),r.previous||(this.firstChunk=i.next),i.next||(this.lastChunk=r.previous,this.lastChunk.next=null),r.previous=c,i.next=s||null,c||(this.firstChunk=r),s||(this.lastChunk=i),this}overwrite(e,t,n,r){return r||={},this.update(e,t,n,{...r,overwrite:!r.contentOnly})}update(e,t,n,r){if(e+=this.offset,t+=this.offset,typeof n!=`string`)throw TypeError(`replacement content must be a string`);if(this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(t>this.original.length)throw Error(`end is out of bounds`);if(e===t)throw Error(`Cannot overwrite a zero-length range – use appendLeft or prependRight instead`);this._split(e),this._split(t),r===!0&&(A.storeName||(console.warn(`The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string`),A.storeName=!0),r={storeName:!0});let i=r===void 0?!1:r.storeName,a=r===void 0?!1:r.overwrite;if(i){let n=this.original.slice(e,t);Object.defineProperty(this.storedNames,n,{writable:!0,value:!0,enumerable:!0})}let o=this.byStart[e],s=this.byEnd[t];if(o){let e=o;for(;e!==s;){if(e.next!==this.byStart[e.end])throw Error(`Cannot overwrite across a split point`);e=e.next,e.edit(``,!1)}o.edit(n,i,!a)}else{let r=new v(e,t,``).edit(n,i);s.next=r,r.previous=s}return this}prepend(e){if(typeof e!=`string`)throw TypeError(`outro content must be a string`);return this.intro=e+this.intro,this}prependLeft(e,t){if(e+=this.offset,typeof t!=`string`)throw TypeError(`inserted content must be a string`);this._split(e);let n=this.byEnd[e];return n?n.prependLeft(t):this.intro=t+this.intro,this}prependRight(e,t){if(e+=this.offset,typeof t!=`string`)throw TypeError(`inserted content must be a string`);this._split(e);let n=this.byStart[e];return n?n.prependRight(t):this.outro=t+this.outro,this}remove(e,t){if(e+=this.offset,t+=this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(e===t)return this;if(e<0||t>this.original.length)throw Error(`Character is out of bounds`);if(e>t)throw Error(`end must be greater than start`);this._split(e),this._split(t);let n=this.byStart[e];for(;n;)n.intro=``,n.outro=``,n.edit(``),n=t>n.end?this.byStart[n.end]:null;return this}reset(e,t){if(e+=this.offset,t+=this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(e===t)return this;if(e<0||t>this.original.length)throw Error(`Character is out of bounds`);if(e>t)throw Error(`end must be greater than start`);this._split(e),this._split(t);let n=this.byStart[e];for(;n;)n.reset(),n=t>n.end?this.byStart[n.end]:null;return this}lastChar(){if(this.outro.length)return this.outro[this.outro.length-1];let e=this.lastChunk;do{if(e.outro.length)return e.outro[e.outro.length-1];if(e.content.length)return e.content[e.content.length-1];if(e.intro.length)return e.intro[e.intro.length-1]}while(e=e.previous);return this.intro.length?this.intro[this.intro.length-1]:``}lastLine(){let e=this.outro.lastIndexOf(k);if(e!==-1)return this.outro.substr(e+1);let t=this.outro,n=this.lastChunk;do{if(n.outro.length>0){if(e=n.outro.lastIndexOf(k),e!==-1)return n.outro.substr(e+1)+t;t=n.outro+t}if(n.content.length>0){if(e=n.content.lastIndexOf(k),e!==-1)return n.content.substr(e+1)+t;t=n.content+t}if(n.intro.length>0){if(e=n.intro.lastIndexOf(k),e!==-1)return n.intro.substr(e+1)+t;t=n.intro+t}}while(n=n.previous);return e=this.intro.lastIndexOf(k),e===-1?this.intro+t:this.intro.substr(e+1)+t}slice(e=0,t=this.original.length-this.offset){if(e+=this.offset,t+=this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}let n=``,r=this.firstChunk;for(;r&&(r.start>e||r.end<=e);){if(r.start<t&&r.end>=t)return n;r=r.next}if(r&&r.edited&&r.start!==e)throw Error(`Cannot use replaced character ${e} as slice start anchor.`);let i=r;for(;r;){r.intro&&(i!==r||r.start===e)&&(n+=r.intro);let a=r.start<t&&r.end>=t;if(a&&r.edited&&r.end!==t)throw Error(`Cannot use replaced character ${t} as slice end anchor.`);let o=i===r?e-r.start:0,s=a?r.content.length+t-r.end:r.content.length;if(n+=r.content.slice(o,s),r.outro&&(!a||r.end===t)&&(n+=r.outro),a)break;r=r.next}return n}snip(e,t){let n=this.clone();return n.remove(0,e),n.remove(t,n.original.length),n}_split(e){if(this.byStart[e]||this.byEnd[e])return;let t=this.lastSearchedChunk,n=t,r=e>t.end;for(;t;){if(t.contains(e))return this._splitChunk(t,e);if(t=r?this.byStart[t.end]:this.byEnd[t.start],t===n)return;n=t}}_splitChunk(e,t){if(e.edited&&e.content.length){let n=E(this.original)(t);throw Error(`Cannot split a chunk that has already been edited (${n.line}:${n.column} – "${e.original}")`)}let n=e.split(t);return this.byEnd[t]=e,this.byStart[t]=n,this.byEnd[n.end]=n,e===this.lastChunk&&(this.lastChunk=n),this.lastSearchedChunk=e,!0}toString(){let e=this.intro,t=this.firstChunk;for(;t;)e+=t.toString(),t=t.next;return e+this.outro}isEmpty(){let e=this.firstChunk;do if(e.intro.length&&e.intro.trim()||e.content.length&&e.content.trim()||e.outro.length&&e.outro.trim())return!1;while(e=e.next);return!0}length(){let e=this.firstChunk,t=0;do t+=e.intro.length+e.content.length+e.outro.length;while(e=e.next);return t}trimLines(){return this.trim(`[\\r\\n]`)}trim(e){return this.trimStart(e).trimEnd(e)}trimEndAborted(e){let t=RegExp((e||`\\s`)+`+$`);if(this.outro=this.outro.replace(t,``),this.outro.length)return!0;let n=this.lastChunk;do{let e=n.end,r=n.trimEnd(t);if(n.end!==e&&(this.lastChunk===n&&(this.lastChunk=n.next),this.byEnd[n.end]=n,this.byStart[n.next.start]=n.next,this.byEnd[n.next.end]=n.next),r)return!0;n=n.previous}while(n);return!1}trimEnd(e){return this.trimEndAborted(e),this}trimStartAborted(e){let t=RegExp(`^`+(e||`\\s`)+`+`);if(this.intro=this.intro.replace(t,``),this.intro.length)return!0;let n=this.firstChunk;do{let e=n.end,r=n.trimStart(t);if(n.end!==e&&(n===this.lastChunk&&(this.lastChunk=n.next),this.byEnd[n.end]=n,this.byStart[n.next.start]=n.next,this.byEnd[n.next.end]=n.next),r)return!0;n=n.next}while(n);return!1}trimStart(e){return this.trimStartAborted(e),this}hasChanged(){return this.original!==this.toString()}_replaceRegexp(e,t){function n(e,n){return typeof t==`string`?t.replace(/\$(\$|&|\d+)/g,(t,n)=>{if(n===`$`)return`$`;if(n===`&`)return e[0];let r=+n;return r<e.length?e[+n]:`$${n}`}):t(...e,e.index,n,e.groups)}function r(e,t){let n,r=[];for(;n=e.exec(t);)r.push(n);return r}if(e.global){let t=r(e,this.original);t.forEach(e=>{if(e.index!=null){let t=n(e,this.original);t!==e[0]&&this.overwrite(e.index,e.index+e[0].length,t)}})}else{let t=this.original.match(e);if(t&&t.index!=null){let e=n(t,this.original);e!==t[0]&&this.overwrite(t.index,t.index+t[0].length,e)}}return this}_replaceString(e,t){let{original:n}=this,r=n.indexOf(e);return r!==-1&&(typeof t==`function`&&(t=t(e,r,n)),e!==t&&this.overwrite(r,r+e.length,t)),this}replace(e,t){return typeof e==`string`?this._replaceString(e,t):this._replaceRegexp(e,t)}_replaceAllString(e,t){let{original:n}=this,r=e.length;for(let i=n.indexOf(e);i!==-1;i=n.indexOf(e,i+r)){let e=n.slice(i,i+r),a=t;typeof t==`function`&&(a=t(e,i,n)),e!==a&&this.overwrite(i,i+r,a)}return this}replaceAll(e,t){if(typeof e==`string`)return this._replaceAllString(e,t);if(!e.global)throw TypeError(`MagicString.prototype.replaceAll called with a non-global RegExp argument`);return this._replaceRegexp(e,t)}};const M=n.default||n;function N(){let t=`virtual:404-page`,n=`import { createClient } from "@metagptx/web-sdk";
|
|
2
11
|
import { useMemo, useState } from "react";
|
|
3
12
|
|
|
4
13
|
const client = createClient();
|
|
@@ -179,18 +188,16 @@ export default function NotFoundPage() {
|
|
|
179
188
|
</div>
|
|
180
189
|
);
|
|
181
190
|
}
|
|
182
|
-
`;return{name:`vite-plugin-404`,enforce:`pre`,resolveId(
|
|
183
|
-
|
|
184
|
-
import NotFoundPage from 'virtual:404-page'
|
|
185
|
-
$1`),r=!0;else{let t=/(^import\s[^;]+;)/gm,n=[...e.matchAll(t)];if(n.length>0){let t=n[n.length-1],i=t.index+t[0].length,a=e.substring(0,i),o=e.substring(i);e=`${a}\nimport NotFoundPage from 'virtual:404-page';${o}`,r=!0}}}let a=/path\s*=\s*["']\*["']/.test(e);if(!a){if(/\/\/\s*MODULE_ROUTES_END/.test(e)){let t=e.match(/(\s*)\/\/\s*MODULE_ROUTES_END/);if(t){let n=t[1];e=e.replace(/(\s*)\/\/\s*MODULE_ROUTES_END/,`${n}<Route path="*" element={<NotFoundPage />} />\n$1// MODULE_ROUTES_END`),r=!0}}else if(/<\/Routes>/.test(e)){let t=e.match(/(\s*)<\/Routes>/);if(t){let n=t[1],i=e.match(/(\s+)<Route\s+path=/),a=i?i[1]:`${n} `;e=e.replace(/(\s*)<\/Routes>/,`${a}<Route path="*" element={<NotFoundPage />} />\n$1</Routes>`),r=!0}}else if(/<Route\s+path=/.test(e)){let t=/<Route\s[^>]*\/>|<Route\s[^>]*>[\s\S]*?<\/Route>/g,n=[...e.matchAll(t)];if(n.length>0){let t=n[n.length-1],i=t.index+t[0].length,a=e.substring(0,i),o=e.substring(i),s=a.split(`
|
|
186
|
-
`),c=s[s.length-1],l=c.match(/^(\s*)/)?.[1]||``;e=`${a}\n${l}<Route path="*" element={<NotFoundPage />} />${o}`,r=!0}}}return r?{code:e,map:null}:null}}}const o=r.default||r;function s(r={}){let{routeFile:a=`src/App.tsx`,entryFile:s=`src/main.tsx`,moduleId:c=`virtual:routes-manifest`,notifyParent:l=!0,messageType:u=`ROUTES_MANIFEST`,excludePaths:d=[`*`]}=r,f=`\0${c}`,p=process.cwd();function m(e,t){for(let n of e)if(i.isJSXAttribute(n)&&i.isJSXIdentifier(n.name,{name:t})&&i.isStringLiteral(n.value))return n.value.value}function h(e){for(let t of e)if(i.isJSXAttribute(t)&&i.isJSXIdentifier(t.name,{name:`element`})){let e=t.value;if(i.isJSXExpressionContainer(e)){let t=e.expression;if(i.isJSXElement(t)){let e=t.openingElement;if(i.isJSXIdentifier(e.name))return e.name.name}}}}function g(e){return e.some(e=>i.isJSXAttribute(e)&&i.isJSXIdentifier(e.name,{name:`element`}))}function _(e){return e.some(e=>i.isJSXAttribute(e)&&i.isJSXIdentifier(e.name,{name:`index`}))}function v(e,t){let n=[];for(let r of e)if(i.isJSXElement(r)){let e=r.openingElement;if(i.isJSXIdentifier(e.name,{name:`Route`})){let e=y(r,t);e&&n.push(e)}}return n}function y(e,t){let n=e.openingElement.attributes,r=m(n,`path`),i=_(n),a=g(n),o=h(n),s;if(i)s=t||`/`;else if(r===void 0)return null;else s=r.startsWith(`/`)?r:t===`/`?`/${r}`:`${t}/${r}`;s=s.replace(/\/+/g,`/`),s!==`/`&&s.endsWith(`/`)&&(s=s.slice(0,-1));let c={path:s,hasElement:a,elementName:o,isWildcard:r===`*`,isIndex:i};if(e.children&&e.children.length>0){let t=v(e.children,s);t.length>0&&(c.children=t)}return c}function b(e,t=[]){for(let n of e)n.hasElement&&t.push({path:n.path,elementName:n.elementName}),n.children&&b(n.children,t);return t}function x(e){let t=0;for(let n of e)t++,n.children&&(t+=x(n.children));return t}function S(t){let r={routeTree:[],routes:[],pageCount:0,total:0,generatedAt:new Date().toISOString()};if(!e.existsSync(t))return console.warn(`[routes-scanner] Route file not found: ${t}`),r;let a=e.readFileSync(t,`utf-8`),s;try{s=n.parse(a,{sourceType:`module`,plugins:[`jsx`,`typescript`]})}catch(e){return console.error(`[routes-scanner] Failed to parse route file:`,e),r}let c=[];o(s,{JSXElement(e){let t=e.node.openingElement;if(i.isJSXIdentifier(t.name,{name:`Routes`})){let t=e.node.children;for(let e of t)if(i.isJSXElement(e)){let t=e.openingElement;if(i.isJSXIdentifier(t.name,{name:`Route`})){let t=y(e,``);t&&c.push(t)}}e.stop()}}});let l=b(c),u=l.filter(e=>!d.some(t=>e.path===t||e.path.match(RegExp(`^${t.replace(`*`,`.*`)}$`))));return{routeTree:c,routes:l,pageCount:u.length,total:x(c),generatedAt:new Date().toISOString()}}return{name:`vite-plugin-routes-scanner`,configResolved(e){p=e.root},resolveId(e){if(e===c)return f},load(e){if(e===f){let e=t.resolve(p,a),n=S(e),r=l?`
|
|
191
|
+
`;function i(e){for(let t of e)if(r.isJSXAttribute(t)&&r.isJSXIdentifier(t.name,{name:`path`})&&r.isStringLiteral(t.value))return t.value.value}function a(e,t){return e.source.value.includes(t)}return{name:`vite-plugin-404`,enforce:`pre`,resolveId(e){return e===t||e.startsWith(t)?`\0${t}.tsx`:null},load(e){return e===`\0${t}.tsx`||e.includes(`virtual:404-page`)?n:null},transform(t,n){if(!n.includes(`App.tsx`)||!n.endsWith(`.tsx`))return null;let o;try{o=e.parse(t,{sourceType:`module`,plugins:[`jsx`,`typescript`]})}catch{return null}let s=!1,c=!1,l=-1,u=-1,d=` `;if(M(o,{ImportDeclaration(e){let t=e.node;a(t,`virtual:404-page`)&&(s=!0),t.end&&t.end>l&&(l=t.end)},JSXElement(e){let n=e.node.openingElement;if(r.isJSXIdentifier(n.name,{name:`Route`})){let e=i(n.attributes);if(e===`*`&&(c=!0),n.start!==void 0&&n.start!==null){let e=t.lastIndexOf(`
|
|
192
|
+
`,n.start)+1,r=t.substring(e,n.start);/^\s+$/.test(r)&&(d=r)}}if(r.isJSXIdentifier(n.name,{name:`Routes`})){let t=e.node.closingElement;t&&t.start!==void 0&&t.start!==null&&(u=t.start)}}}),s||c||l===-1)return null;let f=new j(t),p=`
|
|
193
|
+
import NotFoundPage from 'virtual:404-page';`;if(f.appendRight(l,p),u!==-1){let e=`${d}<Route path="*" element={<NotFoundPage />} />\n`;f.appendLeft(u,e)}return{code:f.toString(),map:f.generateMap({hires:!0})}}}}const P=n.default||n;function F(e={}){let{routeFile:n=`src/App.tsx`,entryFile:r=`src/main.tsx`,moduleId:s=`virtual:routes-manifest`,notifyParent:c=!0,messageType:l=`ROUTES_MANIFEST`,excludePaths:u=[`*`]}=e,d=`\0${s}`,f=process.cwd();function p(e,t){for(let n of e)if(i.isJSXAttribute(n)&&i.isJSXIdentifier(n.name,{name:t})&&i.isStringLiteral(n.value))return n.value.value}function m(e){for(let t of e)if(i.isJSXAttribute(t)&&i.isJSXIdentifier(t.name,{name:`element`})){let e=t.value;if(i.isJSXExpressionContainer(e)){let t=e.expression;if(i.isJSXElement(t)){let e=t.openingElement;if(i.isJSXIdentifier(e.name))return e.name.name}}}}function h(e){return e.some(e=>i.isJSXAttribute(e)&&i.isJSXIdentifier(e.name,{name:`element`}))}function g(e){return e.some(e=>i.isJSXAttribute(e)&&i.isJSXIdentifier(e.name,{name:`index`}))}function _(e,t){let n=[];for(let r of e)if(i.isJSXElement(r)){let e=r.openingElement;if(i.isJSXIdentifier(e.name,{name:`Route`})){let e=v(r,t);e&&n.push(e)}}return n}function v(e,t){let n=e.openingElement.attributes,r=p(n,`path`),i=g(n),a=h(n),o=m(n),s;if(i)s=t||`/`;else if(r===void 0)return null;else s=r.startsWith(`/`)?r:t===`/`?`/${r}`:`${t}/${r}`;s=s.replace(/\/+/g,`/`),s!==`/`&&s.endsWith(`/`)&&(s=s.slice(0,-1));let c={path:s,hasElement:a,elementName:o,isWildcard:r===`*`,isIndex:i};if(e.children&&e.children.length>0){let t=_(e.children,s);t.length>0&&(c.children=t)}return c}function y(e,t=[]){for(let n of e)n.hasElement&&t.push({path:n.path,elementName:n.elementName}),n.children&&y(n.children,t);return t}function b(e){let t=0;for(let n of e)t++,n.children&&(t+=b(n.children));return t}function x(e){let n={routeTree:[],routes:[],pageCount:0,total:0,generatedAt:new Date().toISOString()};if(!a.existsSync(e))return console.warn(`[routes-scanner] Route file not found: ${e}`),n;let r=a.readFileSync(e,`utf-8`),o;try{o=t.parse(r,{sourceType:`module`,plugins:[`jsx`,`typescript`]})}catch(e){return console.error(`[routes-scanner] Failed to parse route file:`,e),n}let s=[];P(o,{JSXElement(e){let t=e.node.openingElement;if(i.isJSXIdentifier(t.name,{name:`Routes`})){let t=e.node.children;for(let e of t)if(i.isJSXElement(e)){let t=e.openingElement;if(i.isJSXIdentifier(t.name,{name:`Route`})){let t=v(e,``);t&&s.push(t)}}e.stop()}}});let c=y(s),l=c.filter(e=>!u.some(t=>e.path===t||e.path.match(RegExp(`^${t.replace(`*`,`.*`)}$`))));return{routeTree:s,routes:c,pageCount:l.length,total:b(s),generatedAt:new Date().toISOString()}}return{name:`vite-plugin-routes-scanner`,configResolved(e){f=e.root},resolveId(e){if(e===s)return d},load(e){if(e===d){let e=o.resolve(f,n),t=x(e),r=c?`
|
|
187
194
|
// 向父级 iframe 发送路由信息
|
|
188
195
|
function notifyParentWindow() {
|
|
189
196
|
console.log('[routes-scanner] notifyParentWindow', routesManifest);
|
|
190
197
|
if (typeof window !== 'undefined' && window.parent && window.parent !== window) {
|
|
191
198
|
try {
|
|
192
199
|
window.parent.postMessage({
|
|
193
|
-
type: '${
|
|
200
|
+
type: '${l}',
|
|
194
201
|
targetName: window.name,
|
|
195
202
|
data: routesManifest,
|
|
196
203
|
}, '*');
|
|
@@ -211,11 +218,11 @@ if (typeof window !== 'undefined') {
|
|
|
211
218
|
|
|
212
219
|
export { notifyParentWindow };
|
|
213
220
|
`:``;return`
|
|
214
|
-
export const routesManifest = ${JSON.stringify(
|
|
221
|
+
export const routesManifest = ${JSON.stringify(t,null,2)};
|
|
215
222
|
export const routeTree = routesManifest.routeTree;
|
|
216
223
|
export const routes = routesManifest.routes;
|
|
217
224
|
export const pageCount = routesManifest.pageCount;
|
|
218
225
|
export const total = routesManifest.total;
|
|
219
226
|
${r}
|
|
220
227
|
export default routesManifest;
|
|
221
|
-
`}},transform(e,
|
|
228
|
+
`}},transform(e,t){let n=t.replace(/\\/g,`/`),i=o.resolve(f,r).replace(/\\/g,`/`);if(n===i&&c){let t=`import "${s}";\n`;return e.includes(s)?null:{code:t+e,map:null}}return null},configureServer(e){let t=o.resolve(f,n);e.watcher.add(t),e.watcher.on(`change`,n=>{if(n===t){let t=e.moduleGraph.getModuleById(d);t&&(e.moduleGraph.invalidateModule(t),e.ws.send({type:`full-reload`}))}})}}}function I(e={}){let{404:t={},routes:n={}}=e,{enable:r=!0}=t,{enable:i=!0,...a}=n,o=[];return r&&o.push(N()),i&&o.push(F(a)),o}export{I as atoms};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metagptx/web-sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.52-beta.
|
|
4
|
+
"version": "0.0.52-beta.22",
|
|
5
5
|
"packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b",
|
|
6
6
|
"description": "TypeScript SDK for interacting with FuncSea API",
|
|
7
7
|
"author": "MetaGPTX",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@antfu/eslint-config": "^5.4.1",
|
|
74
|
+
"@babel/generator": "^7.28.6",
|
|
74
75
|
"@babel/parser": "^7.28.6",
|
|
75
76
|
"@babel/traverse": "^7.28.6",
|
|
76
77
|
"@babel/types": "^7.28.6",
|
|
@@ -80,6 +81,7 @@
|
|
|
80
81
|
"@vitest/coverage-v8": "^3.2.4",
|
|
81
82
|
"bumpp": "^10.1.0",
|
|
82
83
|
"eslint": "^9.36.0",
|
|
84
|
+
"magic-string": "^0.30.21",
|
|
83
85
|
"prettier": "^3.6.2",
|
|
84
86
|
"tsdown": "^0.11.9",
|
|
85
87
|
"typescript": "^5.8.3",
|