@fluixi/compiler 1.0.0-alpha.75 → 1.0.0-alpha.76
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/analyze/intrinsics.cjs +1 -0
- package/dist/analyze/intrinsics.d.ts +67 -0
- package/dist/analyze/intrinsics.d.ts.map +1 -0
- package/dist/analyze/intrinsics.js +91 -0
- package/dist/analyze/intrinsics.mjs +1 -0
- package/dist/analyze/props-destructure.cjs +1 -0
- package/dist/analyze/props-destructure.d.ts +84 -0
- package/dist/analyze/props-destructure.d.ts.map +1 -0
- package/dist/analyze/props-destructure.js +272 -0
- package/dist/analyze/props-destructure.mjs +1 -0
- package/dist/analyze/reactive-bindings.cjs +1 -0
- package/dist/analyze/reactive-bindings.d.ts +34 -0
- package/dist/analyze/reactive-bindings.d.ts.map +1 -0
- package/dist/analyze/reactive-bindings.js +153 -0
- package/dist/analyze/reactive-bindings.mjs +1 -0
- package/dist/{babel-GXO3KAVI.mjs → babel-YQ42WUS3.mjs} +1 -1
- package/dist/chunk-545LMC5W.mjs +1 -0
- package/dist/{chunk-TIE4XNAM.mjs → chunk-L2QPV25P.mjs} +1 -1
- package/dist/frontend/babel/build-ir-lit.cjs +1 -1
- package/dist/frontend/babel/build-ir-lit.mjs +1 -1
- package/dist/frontend/babel/build-ir.cjs +1 -1
- package/dist/frontend/babel/build-ir.mjs +1 -1
- package/dist/frontend/babel/index.cjs +1 -1
- package/dist/frontend/babel/index.mjs +1 -1
- package/dist/frontend/babel/lower-template.cjs +1 -1
- package/dist/frontend/babel/lower-template.mjs +1 -1
- package/dist/frontend/babel/plugin.cjs +1 -1
- package/dist/frontend/babel/plugin.mjs +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.mjs +9 -9
- package/dist/integrations.cjs +18 -14
- package/dist/integrations.d.ts +14 -0
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +16 -1
- package/dist/integrations.mjs +11 -11
- package/dist/lower/compile-template.cjs +1 -1
- package/dist/lower/compile-template.mjs +1 -1
- package/dist/lower/template.cjs +1 -1
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +7 -5
- package/dist/lower/template.mjs +1 -1
- package/dist/resolve/component-globals.cjs +9 -9
- package/dist/resolve/component-globals.d.ts +8 -0
- package/dist/resolve/component-globals.d.ts.map +1 -1
- package/dist/resolve/component-globals.js +17 -3
- package/dist/resolve/component-globals.mjs +9 -9
- package/dist/resolve/write-globals.cjs +9 -9
- package/dist/resolve/write-globals.mjs +9 -9
- package/dist/transform/index.cjs +5 -1
- package/dist/transform/index.d.ts +4 -0
- package/dist/transform/index.d.ts.map +1 -1
- package/dist/transform/index.js +2 -0
- package/dist/transform/index.mjs +14 -10
- package/dist/transform/intrinsics.cjs +3 -0
- package/dist/transform/intrinsics.d.ts +22 -0
- package/dist/transform/intrinsics.d.ts.map +1 -0
- package/dist/transform/intrinsics.js +78 -0
- package/dist/transform/intrinsics.mjs +3 -0
- package/dist/transform/props.cjs +3 -0
- package/dist/transform/props.d.ts +46 -0
- package/dist/transform/props.d.ts.map +1 -0
- package/dist/transform/props.js +221 -0
- package/dist/transform/props.mjs +12 -0
- package/dist/transform/templates.cjs +4 -1
- package/dist/transform/templates.d.ts +20 -0
- package/dist/transform/templates.d.ts.map +1 -1
- package/dist/transform/templates.js +41 -6
- package/dist/transform/templates.mjs +13 -10
- package/dist/transform-ZWIHEZVN.mjs +7 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/transform-PJX2GNSV.mjs +0 -3
package/dist/transform/index.mjs
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import{parse as
|
|
2
|
-
`),t=e.filter(
|
|
3
|
-
`),t=[];for(let r=0,i=0;r<e.length;r++)t.push(i),i+=e[r].length+1;return function(i){let
|
|
4
|
-
`,0),a=-1;for(;
|
|
5
|
-
`,
|
|
6
|
-
`)i.line+=1,i.column=0,this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,a=!0,l=!1;else{if(this.hires||a||
|
|
7
|
-
`);if(t.length>1){for(let r=0;r<t.length-1;r++)this.generatedCodeLine++,this.raw[this.generatedCodeLine]=this.rawSegments=[];this.generatedCodeColumn=0}this.generatedCodeColumn+=t[t.length-1].length}},
|
|
8
|
-
`,
|
|
1
|
+
import{parse as Rn}from"@babel/parser";var vt=44,xt=59,Oe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Me=new Uint8Array(64),bt=new Uint8Array(128);for(let n=0;n<Oe.length;n++){let e=Oe.charCodeAt(n);Me[n]=e,bt[e]=n}function A(n,e,t){let r=e-t;r=r<0?-r<<1|1:r<<1;do{let i=r&31;r>>>=5,r>0&&(i|=32),n.write(Me[i])}while(r>0);return e}var Pe=1024*16,Le=typeof TextDecoder<"u"?new TextDecoder:typeof Buffer<"u"?{decode(n){return Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString()}}:{decode(n){let e="";for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return e}},Nt=class{constructor(){this.pos=0,this.out="",this.buffer=new Uint8Array(Pe)}write(n){let{buffer:e}=this;e[this.pos++]=n,this.pos===Pe&&(this.out+=Le.decode(e),this.pos=0)}flush(){let{buffer:n,out:e,pos:t}=this;return t>0?e+Le.decode(n.subarray(0,t)):e}};function Ae(n){let e=new Nt,t=0,r=0,i=0,s=0;for(let o=0;o<n.length;o++){let a=n[o];if(o>0&&e.write(xt),a.length===0)continue;let l=0;for(let c=0;c<a.length;c++){let u=a[c];c>0&&e.write(vt),l=A(e,u[0],l),u.length!==1&&(t=A(e,u[1],t),r=A(e,u[2],r),i=A(e,u[3],i),u.length!==4&&(s=A(e,u[4],s)))}}return e.flush()}var K=class n{constructor(e){this.bits=e instanceof n?e.bits.slice():[]}add(e){this.bits[e>>5]|=1<<(e&31)}has(e){return!!(this.bits[e>>5]&1<<(e&31))}},G=class n{constructor(e,t,r){this.start=e,this.end=t,this.original=r,this.intro="",this.outro="",this.content=r,this.storeName=!1,this.edited=!1,this.previous=null,this.next=null}appendLeft(e){this.outro+=e}appendRight(e){this.intro=this.intro+e}clone(){let e=new n(this.start,this.end,this.original);return e.intro=this.intro,e.outro=this.outro,e.content=this.content,e.storeName=this.storeName,e.edited=this.edited,e}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,r){return this.content=e,r||(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(e){let t=e-this.start,r=this.original.slice(0,t),i=this.original.slice(t);this.original=r;let s=new n(e,this.end,i);return s.outro=this.outro,this.outro="",this.end=e,this.edited?(s.edit("",!1),this.content=""):this.content=r,s.next=this.next,s.next&&(s.next.previous=s),s.previous=this,this.next=s,s}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 r=this.split(this.end-t.length);this.edited&&r.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 wt(){return typeof globalThis<"u"&&typeof globalThis.btoa=="function"?n=>globalThis.btoa(unescape(encodeURIComponent(n))):typeof Buffer=="function"?n=>Buffer.from(n,"utf-8").toString("base64"):()=>{throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.")}}var Rt=wt(),de=class{constructor(e){this.version=3,this.file=e.file,this.sources=e.sources,this.sourcesContent=e.sourcesContent,this.names=e.names,this.mappings=Ae(e.mappings),typeof e.x_google_ignoreList<"u"&&(this.x_google_ignoreList=e.x_google_ignoreList),typeof e.debugId<"u"&&(this.debugId=e.debugId)}toString(){return JSON.stringify(this)}toUrl(){return"data:application/json;charset=utf-8;base64,"+Rt(this.toString())}};function St(n){let e=n.split(`
|
|
2
|
+
`),t=e.filter(s=>/^\t+/.test(s)),r=e.filter(s=>/^ {2,}/.test(s));if(t.length===0&&r.length===0)return null;if(t.length>=r.length)return" ";let i=r.reduce((s,o)=>{let a=/^ +/.exec(o)[0].length;return Math.min(a,s)},1/0);return new Array(i+1).join(" ")}function kt(n,e){let t=n.split(/[/\\]/),r=e.split(/[/\\]/);for(t.pop();t[0]===r[0];)t.shift(),r.shift();if(t.length){let i=t.length;for(;i--;)t[i]=".."}return t.concat(r).join("/")}var Et=Object.prototype.toString;function Ct(n){return Et.call(n)==="[object Object]"}function je(n){let e=n.split(`
|
|
3
|
+
`),t=[];for(let r=0,i=0;r<e.length;r++)t.push(i),i+=e[r].length+1;return function(i){let s=0,o=t.length;for(;s<o;){let c=s+o>>1;i<t[c]?o=c:s=c+1}let a=s-1,l=i-t[a];return{line:a,column:l}}}var It=/\w/,pe=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,r,i){if(t.length){let s=t.length-1,o=t.indexOf(`
|
|
4
|
+
`,0),a=-1;for(;o>=0&&s>o;){let c=[this.generatedCodeColumn,e,r.line,r.column];i>=0&&c.push(i),this.rawSegments.push(c),this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,a=o,o=t.indexOf(`
|
|
5
|
+
`,o+1)}let l=[this.generatedCodeColumn,e,r.line,r.column];i>=0&&l.push(i),this.rawSegments.push(l),this.advance(t.slice(a+1))}else this.pending&&(this.rawSegments.push(this.pending),this.advance(t));this.pending=null}addUneditedChunk(e,t,r,i,s){let o=t.start,a=!0,l=!1;for(;o<t.end;){if(r[o]===`
|
|
6
|
+
`)i.line+=1,i.column=0,this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,a=!0,l=!1;else{if(this.hires||a||s.has(o)){let c=[this.generatedCodeColumn,e,i.line,i.column];this.hires==="boundary"?It.test(r[o])?l||(this.rawSegments.push(c),l=!0):(this.rawSegments.push(c),l=!1):this.rawSegments.push(c)}i.column+=1,this.generatedCodeColumn+=1,a=!1}o+=1}this.pending=null}advance(e){if(!e)return;let t=e.split(`
|
|
7
|
+
`);if(t.length>1){for(let r=0;r<t.length-1;r++)this.generatedCodeLine++,this.raw[this.generatedCodeLine]=this.rawSegments=[];this.generatedCodeColumn=0}this.generatedCodeColumn+=t[t.length-1].length}},j=`
|
|
8
|
+
`,T={insertLeft:!1,insertRight:!1,storeName:!1},$=class n{constructor(e,t={}){let r=new G(0,e.length,e);Object.defineProperties(this,{original:{writable:!0,value:e},outro:{writable:!0,value:""},intro:{writable:!0,value:""},firstChunk:{writable:!0,value:r},lastChunk:{writable:!0,value:r},lastSearchedChunk:{writable:!0,value:r},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 K},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]=r,this.byEnd[e.length]=r}addSourcemapLocation(e){this.sourcemapLocations.add(e)}append(e){if(typeof e!="string")throw new TypeError("outro content must be a string");return this.outro+=e,this}appendLeft(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let r=this.byEnd[e];return r?r.appendLeft(t):this.intro+=t,this}appendRight(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let r=this.byStart[e];return r?r.appendRight(t):this.outro+=t,this}clone(){let e=new n(this.original,{filename:this.filename,offset:this.offset}),t=this.firstChunk,r=e.firstChunk=e.lastSearchedChunk=t.clone();for(;t;){e.byStart[r.start]=r,e.byEnd[r.end]=r;let i=t.next,s=i&&i.clone();s&&(r.next=s,s.previous=r,r=s),t=i}return e.lastChunk=r,this.indentExclusionRanges&&(e.indentExclusionRanges=this.indentExclusionRanges.slice()),e.sourcemapLocations=new K(this.sourcemapLocations),e.intro=this.intro,e.outro=this.outro,e}generateDecodedMap(e){e=e||{};let t=0,r=Object.keys(this.storedNames),i=new pe(e.hires),s=je(this.original);return this.intro&&i.advance(this.intro),this.firstChunk.eachNext(o=>{let a=s(o.start);o.intro.length&&i.advance(o.intro),o.edited?i.addEdit(t,o.content,a,o.storeName?r.indexOf(o.original):-1):i.addUneditedChunk(t,o,this.original,a,this.sourcemapLocations),o.outro.length&&i.advance(o.outro)}),this.outro&&i.advance(this.outro),{file:e.file?e.file.split(/[/\\]/).pop():void 0,sources:[e.source?kt(e.file||"",e.source):e.file||""],sourcesContent:e.includeContent?[this.original]:void 0,names:r,mappings:i.raw,x_google_ignoreList:this.ignoreList?[t]:void 0}}generateMap(e){return new de(this.generateDecodedMap(e))}_ensureindentStr(){this.indentStr===void 0&&(this.indentStr=St(this.original))}_getRawIndentString(){return this._ensureindentStr(),this.indentStr}getIndentString(){return this._ensureindentStr(),this.indentStr===null?" ":this.indentStr}indent(e,t){let r=/^[^\r\n]/gm;if(Ct(e)&&(t=e,e=void 0),e===void 0&&(this._ensureindentStr(),e=this.indentStr||" "),e==="")return this;t=t||{};let i={};t.exclude&&(typeof t.exclude[0]=="number"?[t.exclude]:t.exclude).forEach(u=>{for(let p=u[0];p<u[1];p+=1)i[p]=!0});let s=t.indentStart!==!1,o=c=>s?`${e}${c}`:(s=!0,c);this.intro=this.intro.replace(r,o);let a=0,l=this.firstChunk;for(;l;){let c=l.end;if(l.edited)i[a]||(l.content=l.content.replace(r,o),l.content.length&&(s=l.content[l.content.length-1]===`
|
|
9
9
|
`));else for(a=l.start;a<c;){if(!i[a]){let u=this.original[a];u===`
|
|
10
|
-
`?o=!0:u!=="\r"&&o&&(o=!1,a===l.start||(this._splitChunk(l,a),l=l.next),l.prependRight(e))}a+=1}a=l.end,l=l.next}return this.outro=this.outro.replace(r,s),this}insert(){throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)")}insertLeft(e,t){return R.insertLeft||(console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"),R.insertLeft=!0),this.appendLeft(e,t)}insertRight(e,t){return R.insertRight||(console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"),R.insertRight=!0),this.prependRight(e,t)}move(e,t,r){if(e=e+this.offset,t=t+this.offset,r=r+this.offset,r>=e&&r<=t)throw new Error("Cannot move a selection inside itself");this._split(e),this._split(t),this._split(r);let i=this.byStart[e],o=this.byEnd[t],s=i.previous,a=o.next,l=this.byStart[r];if(!l&&o===this.lastChunk)return this;let c=l?l.previous:this.lastChunk;return s&&(s.next=a),a&&(a.previous=s),c&&(c.next=i),l&&(l.previous=o),i.previous||(this.firstChunk=o.next),o.next||(this.lastChunk=i.previous,this.lastChunk.next=null),i.previous=c,o.next=l||null,c||(this.firstChunk=i),l||(this.lastChunk=o),this}overwrite(e,t,r,i){return i=i||{},this.update(e,t,r,{...i,overwrite:!i.contentOnly})}update(e,t,r,i){if(e=e+this.offset,t=t+this.offset,typeof r!="string")throw new 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 new Error("end is out of bounds");if(e===t)throw new Error("Cannot overwrite a zero-length range – use appendLeft or prependRight instead");this._split(e),this._split(t),i===!0&&(R.storeName||(console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"),R.storeName=!0),i={storeName:!0});let o=i!==void 0?i.storeName:!1,s=i!==void 0?i.overwrite:!1;if(o){let c=this.original.slice(e,t);Object.defineProperty(this.storedNames,c,{writable:!0,value:!0,enumerable:!0})}let a=this.byStart[e],l=this.byEnd[t];if(a){let c=a;for(;c!==l;){if(c.next!==this.byStart[c.end])throw new Error("Cannot overwrite across a split point");c=c.next,c.edit("",!1)}a.edit(r,o,!s)}else{let c=new J(e,t,"").edit(r,o);l.next=c,c.previous=l}return this}prepend(e){if(typeof e!="string")throw new TypeError("outro content must be a string");return this.intro=e+this.intro,this}prependLeft(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let r=this.byEnd[e];return r?r.prependLeft(t):this.intro=t+this.intro,this}prependRight(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let r=this.byStart[e];return r?r.prependRight(t):this.outro=t+this.outro,this}remove(e,t){if(e=e+this.offset,t=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 new Error("Character is out of bounds");if(e>t)throw new Error("end must be greater than start");this._split(e),this._split(t);let r=this.byStart[e];for(;r;)r.intro="",r.outro="",r.edit(""),r=t>r.end?this.byStart[r.end]:null;return this}reset(e,t){if(e=e+this.offset,t=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 new Error("Character is out of bounds");if(e>t)throw new Error("end must be greater than start");this._split(e),this._split(t);let r=this.byStart[e];for(;r;)r.reset(),r=t>r.end?this.byStart[r.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(E);if(e!==-1)return this.outro.substr(e+1);let t=this.outro,r=this.lastChunk;do{if(r.outro.length>0){if(e=r.outro.lastIndexOf(E),e!==-1)return r.outro.substr(e+1)+t;t=r.outro+t}if(r.content.length>0){if(e=r.content.lastIndexOf(E),e!==-1)return r.content.substr(e+1)+t;t=r.content+t}if(r.intro.length>0){if(e=r.intro.lastIndexOf(E),e!==-1)return r.intro.substr(e+1)+t;t=r.intro+t}}while(r=r.previous);return e=this.intro.lastIndexOf(E),e!==-1?this.intro.substr(e+1)+t:this.intro+t}slice(e=0,t=this.original.length-this.offset){if(e=e+this.offset,t=t+this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}let r="",i=this.firstChunk;for(;i&&(i.start>e||i.end<=e);){if(i.start<t&&i.end>=t)return r;i=i.next}if(i&&i.edited&&i.start!==e)throw new Error(`Cannot use replaced character ${e} as slice start anchor.`);let o=i;for(;i;){i.intro&&(o!==i||i.start===e)&&(r+=i.intro);let s=i.start<t&&i.end>=t;if(s&&i.edited&&i.end!==t)throw new Error(`Cannot use replaced character ${t} as slice end anchor.`);let a=o===i?e-i.start:0,l=s?i.content.length+t-i.end:i.content.length;if(r+=i.content.slice(a,l),i.outro&&(!s||i.end===t)&&(r+=i.outro),s)break;i=i.next}return r}snip(e,t){let r=this.clone();return r.remove(0,e),r.remove(t,r.original.length),r}_split(e){if(this.byStart[e]||this.byEnd[e])return;let t=this.lastSearchedChunk,r=t,i=e>t.end;for(;t;){if(t.contains(e))return this._splitChunk(t,e);if(t=i?this.byStart[t.end]:this.byEnd[t.start],t===r)return;r=t}}_splitChunk(e,t){if(e.edited&&e.content.length){let i=ye(this.original)(t);throw new Error(`Cannot split a chunk that has already been edited (${i.line}:${i.column} – "${e.original}")`)}let r=e.split(t);return this.byEnd[t]=e,this.byStart[t]=r,this.byEnd[r.end]=r,e===this.lastChunk&&(this.lastChunk=r),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=new RegExp((e||"\\s")+"+$");if(this.outro=this.outro.replace(t,""),this.outro.length)return!0;let r=this.lastChunk;do{let i=r.end,o=r.trimEnd(t);if(r.end!==i&&(this.lastChunk===r&&(this.lastChunk=r.next),this.byEnd[r.end]=r,this.byStart[r.next.start]=r.next,this.byEnd[r.next.end]=r.next),o)return!0;r=r.previous}while(r);return!1}trimEnd(e){return this.trimEndAborted(e),this}trimStartAborted(e){let t=new RegExp("^"+(e||"\\s")+"+");if(this.intro=this.intro.replace(t,""),this.intro.length)return!0;let r=this.firstChunk;do{let i=r.end,o=r.trimStart(t);if(r.end!==i&&(r===this.lastChunk&&(this.lastChunk=r.next),this.byEnd[r.end]=r,this.byStart[r.next.start]=r.next,this.byEnd[r.next.end]=r.next),o)return!0;r=r.next}while(r);return!1}trimStart(e){return this.trimStartAborted(e),this}hasChanged(){return this.original!==this.toString()}_replaceRegexp(e,t){function r(o,s){return typeof t=="string"?t.replace(/\$(\$|&|\d+)/g,(a,l)=>l==="$"?"$":l==="&"?o[0]:+l<o.length?o[+l]:`$${l}`):t(...o,o.index,s,o.groups)}function i(o,s){let a,l=[];for(;a=o.exec(s);)l.push(a);return l}if(e.global)i(e,this.original).forEach(s=>{if(s.index!=null){let a=r(s,this.original);a!==s[0]&&this.overwrite(s.index,s.index+s[0].length,a)}});else{let o=this.original.match(e);if(o&&o.index!=null){let s=r(o,this.original);s!==o[0]&&this.overwrite(o.index,o.index+o[0].length,s)}}return this}_replaceString(e,t){let{original:r}=this,i=r.indexOf(e);return i!==-1&&(typeof t=="function"&&(t=t(e,i,r)),e!==t&&this.overwrite(i,i+e.length,t)),this}replace(e,t){return typeof e=="string"?this._replaceString(e,t):this._replaceRegexp(e,t)}_replaceAllString(e,t){let{original:r}=this,i=e.length;for(let o=r.indexOf(e);o!==-1;o=r.indexOf(e,o+i)){let s=r.slice(o,o+i),a=t;typeof t=="function"&&(a=t(s,o,r)),s!==a&&this.overwrite(o,o+i,a)}return this}replaceAll(e,t){if(typeof e=="string")return this._replaceAllString(e,t);if(!e.global)throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");return this._replaceRegexp(e,t)}};function rt(n){switch(n.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return n.reactive?"reactive-prop":n.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function w(n){let e=[],t=new Map,r=i=>{switch(i.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let o of i.children)r(o);return!1;case"fragment":for(let o of i.children)r(o);return!1;case"element":{let o=!0;for(let a of i.children)r(a)||(o=!1);let s;for(let a of i.props)if(s=rt(a),s)break;return!s&&!o&&(s=it(i)),i.static=!s,s?t.set(i,s):e.push(i),i.static}default:return!1}};for(let i of Array.isArray(n)?n:[n])r(i);return{staticElements:e,reasons:t}}function it(n){for(let e of n.children){if(e.kind==="expr")return"expression-child";if(e.kind==="component")return"component-child";if(e.kind==="control")return"control-child";if(e.kind==="element"&&!e.static||e.kind==="fragment")return"expression-child"}return"expression-child"}var F={kind:"eager"},ot=["pointerdown","focusin","keydown"],be=new Set(["eager","idle","visible","interaction","media","never"]),v=class extends Error{};function te(n){return n.startsWith("load:")}function H(n,e){let t=n.slice(5);if(!be.has(t))throw new v(`Unknown load strategy 'load:${t}'. Expected one of ${[...be].join(", ")}.`);switch(t){case"eager":return F;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return e?{kind:"visible",rootMargin:e}:{kind:"visible"};case"interaction":return{kind:"interaction",events:e?st(e):[...ot]};case"media":if(!e)throw new v(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new v(`Unhandled load strategy '${t}'.`)}}function st(n){let e=n.split(/[\s,]+/).map(t=>t.trim()).filter(Boolean);if(e.length===0)throw new v("'load:interaction' was given no event names.");return e}function q(n){return n.kind!=="eager"&&n.kind!=="never"}var I=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],T=["Suspense","SuspenseList","Await"],S=["Router","Outlet","Redirect","Link"],rn=[...I,...T,...S],ne=new Set([...I,...T]);function Re(n={}){let{controlFlowModule:e="@fluixi/dom",coreModule:t="@fluixi/core",routerModule:r="@fluixi/core/router-next"}=n,i={};for(let o of I)i[o]=e;for(let o of T)i[o]=t;for(let o of S)i[o]=r;return i}function U(n,e={}){let{resolver:t,isBound:r,modules:i,strategyFor:o}=e,s=Re(i),a=new Map,l=new Set,c=p=>{let{name:d}=p;if(!d||d.includes(".")||r?.(d))return;let h=u(d);if(!h){l.add(d);return}let m=h.origin==="builtin"&&ne.has(d)?F:o?.(p)??F;p.source={...h,loading:m},a.set(d,p.source)},u=p=>{if(ne.has(p))return{module:s[p],export:p,origin:"builtin"};let d=t?.resolve(p);if(d)return{module:d.module,export:d.export,origin:"rule"};if(S.includes(p))return{module:s[p],export:p,origin:"builtin"}};return X(n,p=>{p.kind==="component"&&c(p)}),{resolved:a,unresolved:[...l]}}function X(n,e){let t=Array.isArray(n)?n:[n];for(let r of t){e(r);let i=r.children;i&&X(i,e)}}function z(n){let e=[];X(n,o=>{o.kind==="component"&&o.source&&e.push(o)});let t=new Set,r=new Set;for(let o of e){let{module:s,loading:a}=o.source;a.kind==="eager"&&t.add(s),a.kind==="never"&&r.add(s)}let i=new Map;for(let o of e){let s=o.source;q(s.loading)&&t.has(s.module)&&(s.loading={kind:"eager"},i.set(s.module,(i.get(s.module)??0)+1))}return{collapsed:i,conflicted:[...r].filter(o=>t.has(o))}}var at=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),we={className:"class",htmlFor:"for"},lt=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),ct=new Set(["script","style","textarea","title"]);function re(n){return ct.has(n)}function Se(n){return we[n]??n}function $(n){return n.kind!=="attr"||n.expr!==void 0||n.name.includes(":")?!1:!lt.has(n.name)}function ie(n){if(!n.static||re(n.tag))return!1;for(let e of n.props)if(!$(e))return!1;for(let e of n.children)if(e.kind!=="text"&&!(e.kind==="element"&&ie(e)))return!1;return!0}function O(n){let e=n.props.map(dt).filter(Boolean).join(""),t=`<${n.tag}${e}>`;return at.has(n.tag)?t:`${t}${n.children.map(ut).join("")}</${n.tag}>`}function ut(n){if(n.kind==="text")return ft(n.value);if(n.kind!=="element")throw new Error(`serializeStatic: unexpected ${n.kind}`);return O(n)}function dt(n){let e=we[n.name]??n.name,t=n.literal;return t===!0||t===void 0?` ${e}`:t===!1||t===null?"":` ${e}="${pt(String(t))}"`}function pt(n){return n.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function ft(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var ht="<!--fx-->",mt="<!--fx/-->";function G(n){return n.kind==="expr"||n.kind==="component"||n.kind==="control"}function gt(n){return n.kind==="text"||n.kind==="element"&&Ce(n)}function Ce(n){return n.svg||re(n.tag)||!n.props.every(e=>$(e))?!1:n.children.every(e=>gt(e)||G(e))}function W(n){if(G(n))return!0;let e=n.children;return e?e.some(W):!1}function ke(n){for(let e=0;e<n.children.length;e++){let t=n.children[e];if(t.kind==="text"&&(t.value===""||n.children[e+1]?.kind==="text"))return!1}return n.children.every(e=>e.kind!=="element"||ke(e))}function Ne(n){if(!Ce(n)||!ke(n)||!n.children.some(W))return null;let e=[],t=[],r=0,i=s=>{let a=`_n$${r++}`;return e.push({ref:a,expr:s}),a};return o(n,"_el$"),{html:vt(n),tag:n.tag,steps:e,holes:t};function o(s,a){let l=-1;s.children.forEach((u,p)=>{W(u)&&(l=p)});let c=null;for(let u=0;u<=l;u++){let p=s.children[u],d=c?`${c}.nextSibling`:`${a}.firstChild`;if(G(p)){let m=i(d),_=i(`holeEnd(${m})`);t.push({parentRef:a,startRef:m,endRef:_,node:p}),c=_;continue}let h=i(d);p.kind==="element"&&W(p)&&o(p,h),c=h}}}function vt(n){return O(Ee(n)).split(Ie).join(ht+mt)}function Ee(n){return{...n,children:n.children.map(e=>G(e)?{kind:"text",value:Ie}:e.kind==="element"?Ee(e):e)}}var Ie="\0fx-hole\0";var oe={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},mn={version:2,module:"@fluixi/dom",symbols:[...oe.symbols,"template","cloneTemplate","walk"]};var xt={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function yt(n){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(n)}function $e(n){return yt(n)?n:JSON.stringify(n)}function bt(n){return n.expr!==void 0?n.reactive?`() => (${n.expr})`:`(${n.expr})`:JSON.stringify(n.literal??!0)}function Rt(n){return n.expr!==void 0?`(${n.expr})`:JSON.stringify(n.literal??!0)}function wt(n,e,t){let r=n.filter(a=>a.kind==="spread"),o=n.filter(a=>a.kind!=="spread").map(a=>`${$e(a.name)}: ${bt(a)}`);e!=null&&o.push(`children: ${e}`);let s=`{ ${o.join(", ")} }`;return r.length>0?(t.add("mergeProps"),`mergeProps(${r.map(a=>a.expr).join(", ")}, ${s})`):s}function Oe(n,e,t){return n.length===1?L(n[0],e,t):`[${n.map(r=>L(r,e,t)).join(", ")}]`}function Te(n,e,t,r,i){r.add("createMemo"),r.add("createComponent");let o=e.filter(c=>c.kind==="spread"),a=e.filter(c=>c.kind!=="spread").map(c=>`get ${$e(c.name)}() { return ${Rt(c)}; }`);t.length>0&&a.push(`get children() { return ${Oe(t,r,i)}; }`);let l=`{ ${a.join(", ")} }`;return o.length>0&&(r.add("mergeProps"),l=`mergeProps(${o.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${n}, ${l}))`}function St(n,e){let t=Se(e.name),r=e.literal;return r===!0||r===void 0?`${n}.setAttribute(${JSON.stringify(t)}, "");`:r===!1||r===null?"":`${n}.setAttribute(${JSON.stringify(t)}, ${JSON.stringify(String(r))});`}var Le=!1;function L(n,e,t){switch(n.kind){case"text":return JSON.stringify(n.value);case"expr":return n.reactive?`() => (${n.code})`:`(${n.code})`;case"fragment":return n.children.length===0?"null":Oe(n.children,e,t);case"component":return Te(n.name,n.props,n.children,e,t);case"control":{let r=xt[n.control]??n.control;return e.add(r),Te(r,n.props,n.children,e,t)}case"element":{if(t&&n.static&&!n.svg&&ie(n)){e.add("templateNode");let a=`_tmpl$${t.length}`;return t.push({id:a,html:O(n),tag:n.tag,svg:!1}),`templateNode(${a}, ${JSON.stringify(n.tag)})`}if(t&&Le){let a=Ne(n);if(a){e.add("templateNode"),e.add("insert"),e.add("holeEnd"),e.add("holeContent"),e.add("holeScope");let l=`_tmpl$${t.length}`;t.push({id:l,html:a.html,tag:a.tag,svg:!1});let c=[`const _el$ = templateNode(${l}, ${JSON.stringify(a.tag)}, true);`];for(let u of a.steps)c.push(`const ${u.ref} = ${u.expr};`);for(let u of a.holes)c.push(`insert(${u.parentRef}, holeScope(${u.startRef}, () => (${L(u.node,e,t)})), ${u.endRef}, holeContent(${u.startRef}, ${u.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}e.add("createNativeElement");let r=JSON.stringify(n.tag),i="_el$",o=[],s=n.svg?`${r}, true`:r;if(o.push(`const ${i} = createNativeElement(${s});`),n.props.length>0)if(!n.svg&&n.props.every($))for(let a of n.props)o.push(St(i,a));else{e.add("spread");let a=n.svg?", isSVG: true":"";o.push(`spread({ element: ${i}, props: ${wt(n.props,null,e)}${a} });`)}for(let a of n.children){e.add("insert");let l=L(a,e,t),c=a.kind==="expr"&&a.reactive||a.kind==="component"||a.kind==="control";o.push(c?`insert(${i}, ${l}, null);`:`insert(${i}, ${l});`)}return o.push(`return ${i};`),`(() => { ${o.join(" ")} })()`}}}function V(n,e){if(!e||e.length===0)return n;let t=new Map(e.map(r=>[r.id,JSON.stringify(r.html)]));return n.replace(/_tmpl\$\d+/g,r=>t.get(r)??r)}var C={name:"imperative",contract:oe,emit(n,e){let t=new Set,r=e?.templateClone!==!1?[]:void 0;return Le=e?.partialTemplates===!0,{code:L(n,t,r),imports:Array.from(t),templates:r}}};var Ct=n=>"components"in n;function Me(n,e){return n.replace(/\$(\d+)/g,(t,r)=>e[Number(r)]??t)}function kt(n,e){return typeof e=="string"?{module:e,export:n}:e}function K(n=[]){let e=new Map,t=[],r=[];for(let s of n){if(!Ct(s)){r.push(s);continue}for(let[a,l]of Object.entries(s.components)){let c=kt(a,l),u=e.get(a);if(u&&u.module!==c.module){let p=t.find(d=>d.name===a);p?p.modules.push(c.module):t.push({name:a,modules:[u.module,c.module]});continue}e.set(a,c)}}let i=new Map;return{resolve:s=>{if(i.has(s))return i.get(s);let a=e.get(s);if(!a)for(let l of r){let c=s.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(c){a={module:Me(l.module,c),export:l.export?Me(l.export,c):s};break}}return i.set(s,a),a},names:()=>[...e.keys()],conflicts:()=>t}}import{parseTemplate as Nt}from"@fluixi/template-parser";function M(n){let e=n.split(/\r\n|\n|\r/),t=0;for(let i=0;i<e.length;i++)/[^ \t]/.test(e[i])&&(t=i);let r="";for(let i=0;i<e.length;i++){let o=e[i].replace(/\t/g," ");i!==0&&(o=o.replace(/^ +/,"")),i!==e.length-1&&(o=o.replace(/ +$/,"")),o&&(i!==t&&(o+=" "),r+=o)}return r}var Pe=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Et(n){return n.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function Ae(n){return n.charAt(0).toUpperCase()+n.slice(1)}var se=class{constructor(e,t){this.holes=e;this.used=t}hole(e){return this.holes[e]??{code:"undefined",reactive:!1}}emit(e){let{code:t,imports:r,templates:i}=C.emit(e,{});for(let o of r)this.used.add(o);return V(t,i)}lowerRoot(e){let t=this.lowerChildren(e);return t.length===1?t[0]:{kind:"fragment",children:t}}lowerChildren(e){let t=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.kind==="Element"||i.kind==="Component"){let s=i.attributes.find(a=>a.kind==="IfDirective");if(s&&s.kind==="IfDirective"){let a=r+1;a<e.length&&this.isBlankText(e[a])&&a++;let l=e[a],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(u=>u.kind==="ElseDirective");t.push(this.lowerIf(i,s.hole,c?l:null)),c&&(r=a);continue}if(i.attributes.some(a=>a.kind==="EachDirective")){t.push(this.lowerEach(i));continue}}let o=this.lowerNode(i);o&&t.push(o)}return t}isBlankText(e){return e.kind==="Text"&&!e.raw&&M(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let t=M(e.value);return t?{kind:"text",value:t}:null}case"Comment":return null;case"Expression":{let t=this.hole(e.hole);return{kind:"expr",code:t.code,reactive:t.reactive}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(e.children)};case"Element":return this.lowerElement(e);case"Component":return this.lowerComponent(e);default:return null}}lowerElement(e){let t=e.attributes.find(r=>r.kind==="Attribute"&&r.name==="is");if(e.tag==="component"&&t&&t.value&&t.value.kind==="hole"){let r=e.attributes.filter(o=>o!==t),i=this.lowerComponent({...e,kind:"Component",tag:"Dynamic",tagHole:null,attributes:r});return i.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(t.value.hole).code})`}),i}return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:this.lowerAttributes(e.attributes),children:this.lowerChildren(e.children),static:!1}}lowerComponent(e){let t=e.tagHole!=null?this.hole(e.tagHole).code:e.tag,r=this.lowerAttributes(e.attributes),{slots:i,rest:o}=this.partitionSlots(e.children);for(let[l,c]of i){let u=c.length===1?c[0]:{kind:"fragment",children:c},p={name:l,kind:"attr",expr:this.emit(u),jsxElement:!0},d=r.findIndex(h=>h.name===l);d>=0?r[d]=p:r.push(p)}let s=e.attributes.find(l=>l.kind==="LoadDirective"),a=s?H(`load:${s.strategy}`,s.modifier):void 0;return{kind:"component",name:t,props:r,children:this.lowerChildren(o),...a?{load:a}:{}}}partitionSlots(e){let t=new Map,r=[];for(let i of e){if(i.kind==="Element"||i.kind==="Component"){let o=i.attributes.find(s=>s.kind==="Attribute"&&s.name==="slot");if(o&&o.value&&o.value.kind==="static"){let s={...i,attributes:i.attributes.filter(c=>c!==o)},a=s.kind==="Element"?this.lowerElement(s):this.lowerComponent(s),l=t.get(o.value.value)??[];l.push(a),t.set(o.value.value,l);continue}}r.push(i)}return{slots:t,rest:r}}lowerIf(e,t,r){let i=this.hole(t),o=[{name:"when",kind:"attr",expr:i.code,reactive:i.reactive}];if(r){let a=this.stripAndLower(r,l=>l.kind==="ElseDirective");o.push({name:"fallback",kind:"attr",expr:this.emit(a),jsxElement:!0})}let s=this.stripAndLower(e,a=>a.kind==="IfDirective");return{kind:"component",name:"Show",props:o,children:[s]}}lowerEach(e){let t=e.attributes.find(l=>l.kind==="EachDirective");if(!t||t.kind!=="EachDirective")return this.lowerNode(e);let r=this.hole(t.hole),i=[{name:"each",kind:"attr",expr:r.code,reactive:r.reactive}];if(t.key){let l="static"in t.key?`(item) => item[${JSON.stringify(t.key.static)}]`:this.hole(t.key.hole).code;i.push({name:"by",kind:"attr",expr:l})}let o=this.itemArrow(e),s;if(o){let l={kind:"expr",code:o.body,reactive:o.bodyReactive},c=this.rebuildWithChildren(e,[l]);s=`(${o.params.join(", ")}) => (${this.emit(c)})`}else{let l=this.stripAndLower(e,c=>c.kind==="EachDirective");s=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:i,children:[{kind:"expr",code:s,reactive:!1}]}}itemArrow(e){let t=e.children.filter(r=>!this.isBlankText(r));return t.length!==1||t[0].kind!=="Expression"?null:this.hole(t[0].hole).arrow??null}stripAndLower(e,t){let r={...e,attributes:e.attributes.filter(i=>!t(i))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(e,t){let r=this.lowerAttributes(e.attributes.filter(i=>i.kind!=="EachDirective"));return e.kind==="Element"?{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:r,children:t,static:!1}:{kind:"component",name:e.tag,props:r,children:t}}lowerAttributes(e){let t=[],r=[],i=!1,o=[],s=!1,a=[];for(let l of e)switch(l.kind){case"IfDirective":case"EachDirective":case"ElseDirective":break;case"Attribute":t.push(this.plainAttr(l));break;case"PropertyBinding":t.push({name:l.name,kind:"prop",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"EventBinding":t.push(this.eventProp(l));break;case"RefBinding":t.push({name:"ref",kind:"ref",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"Spread":t.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let c=this.hole(l.hole);r.push(`${JSON.stringify(l.name)}: ${c.code}`),i=i||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);o.push(`${JSON.stringify(l.name)}: ${c.code}`),s=s||c.reactive;break}case"BindDirective":t.push(...this.bindProps(l.name,this.hole(l.hole).code));break;case"UseDirective":{let c=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!c)break;a.push(l.name!=null&&l.hole!=null?`[${c}, () => (${this.hole(l.hole).code})]`:`[${c}]`);break}}return r.length>0&&t.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:i}),o.length>0&&t.push({name:"style",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:s}),a.length>0&&t.push({name:"use",kind:"attr",expr:`[${a.join(", ")}]`}),t}eventProp(e){let t=e.name.toLowerCase(),r=this.hole(e.hole).code;if(!(e.syntax==="colon"||e.modifiers.length>0))return{name:"on"+Ae(e.name),kind:"event",event:{name:t,delegated:Pe.has(t)},expr:r};let o=this.wrapHandler(r,e.modifiers),s=this.eventOptions(e.modifiers),a=s?`[${o}, ${s}]`:o;return{name:"on:"+t,kind:"attr",expr:a}}wrapHandler(e,t){let r=t.includes("self")?"if (e.target !== e.currentTarget) return; ":"",i=[];return t.includes("prevent")&&i.push("e.preventDefault();"),t.includes("stop")&&i.push("e.stopPropagation();"),!r&&i.length===0?e:`(e) => { ${r}${i.join(" ")} return (${e})(e); }`}eventOptions(e){let t=[];return e.includes("capture")&&t.push("capture: true"),e.includes("once")&&t.push("once: true"),e.includes("passive")&&t.push("passive: true"),t.length?`{ ${t.join(", ")} }`:null}bindProps(e,t){let r=e==="checked",i=r?"change":"input",o=r?"checked":"value",s=`(${t})`;return[{name:e,kind:"attr",expr:`${s}[0]()`,reactive:!0},{name:"on"+Ae(i),kind:"event",event:{name:i,delegated:Pe.has(i)},expr:`(e) => ${s}[1](e.target.${o})`}]}plainAttr(e){let t=e.value,r=e.name;e.name==="class"?r=t&&t.kind==="hole"&&this.hole(t.hole).object?"classList":"className":e.name==="html"&&(r="innerHTML");let o={name:r,kind:"attr"};if(t==null)return o.literal=!0,o;if(t.kind==="static")return o.literal=t.value,o;if(t.kind==="hole"){let l=this.hole(t.hole);return o.expr=l.code,o.reactive=l.reactive,o}let s=!1,a=t.parts.map(l=>{if("text"in l)return Et(l.text);let c=this.hole(l.hole);return s=s||c.reactive,"${"+c.code+"}"}).join("");return o.expr="`"+a+"`",o.reactive=s,o}};function _e(n,e,t,r={}){let{root:i}=Nt(n,{svg:r.svg});return new se(e,t).lowerRoot(i.children)}function je(n,e,t={}){let r=new Set,i=_e(n,[...e],r,{svg:t.svg});w(i),U(i,{resolver:K(t.resolve??[]),modules:{controlFlowModule:t.controlFlowModule??"@fluixi/dom",coreModule:t.coreModule??"@fluixi/core",routerModule:t.routerModule??"@fluixi/core/router-next"},strategyFor:l=>l.load}),z(i);let{code:o,imports:s,templates:a}=C.emit(i,{templateClone:t.templateClone,partialTemplates:t.partialTemplates});for(let l of s)r.add(l);return t.hoistTemplates?{code:o,imports:[...r],ir:i,templates:a}:{code:V(o,a),imports:[...r],ir:i}}var It="children";function k(n){switch(n.kind){case"call":return!0;case"member":return n.property!==It;case"compound":return n.parts.some(k);case"opaque":return!1}}var Tt=new Set(["CallExpression","OptionalCallExpression"]),$t=new Set(["MemberExpression","OptionalMemberExpression"]);function b(n){if(!n)return{kind:"opaque"};if(Tt.has(n.type))return{kind:"call"};if($t.has(n.type)){let e=n.property;return{kind:"member",property:!(n.computed===!0)&&e?.type==="Identifier"?e.name:null}}return n.type==="ConditionalExpression"?{kind:"compound",parts:[n.test,n.consequent,n.alternate].map(P)}:n.type==="LogicalExpression"||n.type==="BinaryExpression"?{kind:"compound",parts:[n.left,n.right].map(P)}:n.type==="TemplateLiteral"?{kind:"compound",parts:n.expressions.map(P)}:n.type==="ObjectExpression"?{kind:"compound",parts:n.properties.filter(t=>(t.type==="ObjectProperty"||t.type==="Property")&&t.computed!==!0).map(t=>P(t.value))}:n.type==="ArrayExpression"?{kind:"compound",parts:n.elements.filter(t=>t!=null&&t.type!=="SpreadElement").map(P)}:{kind:"opaque"}}var P=n=>b(n);var Ot=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),Lt=/^on[A-Z]/,Mt=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]),Be=n=>k(b(n));function A(n){if(n.type==="StringLiteral"||n.type==="NumericLiteral"||n.type==="BooleanLiteral"||n.type==="Literal"&&(typeof n.value=="string"||typeof n.value=="number"||typeof n.value=="boolean"))return n.value}var ae=n=>!!n&&typeof A(n)=="string";function Pt(n,e){return n.type==="JSXIdentifier"?{tag:n.name,component:n.name[0]!==n.name[0].toLowerCase()}:n.type==="JSXMemberExpression"?{tag:e.code(n),component:!0}:n.type==="JSXNamespacedName"?{tag:`${n.namespace.name}:${n.name.name}`,component:!1}:{tag:"div",component:!1}}function le(n){return n.type==="JSXIdentifier"?n.name==="class"?"className":n.name:n.type==="JSXNamespacedName"?`${n.namespace.name}:${n.name.name}`:"unknown"}function At(n,e){let t=le(n.name),r=Lt.test(t),i=r||t.startsWith("on:")||t==="ref",s={name:t,kind:r?"event":"attr"};if(r){let l=t.slice(2).toLowerCase();s.event={name:l,delegated:Mt.has(l)}}let a=n.value;if(a==null)return s.literal=!0,s;if(ae(a))return s.literal=A(a),s;if(a.type==="JSXExpressionContainer"&&a.expression?.type!=="JSXEmptyExpression"){let l=a.expression,c=A(l);return c!==void 0?(s.literal=c,s):(s.expr=e.code(l),s.reactive=i?!1:Be(l),(l.type==="JSXElement"||l.type==="JSXFragment")&&(s.jsxElement=!0),s)}return s.literal=!0,s}function De(n,e){let t=n.value;return t==null?null:ae(t)?JSON.stringify(A(t)):t.type==="JSXExpressionContainer"&&t.expression?.type!=="JSXEmptyExpression"?e.code(t.expression):null}function _t(n,e){let t=[],r=[];for(let i of n){if(i.type==="JSXSpreadAttribute"){t.push({name:"",kind:"spread",expr:e.code(i.argument)});continue}if(i.type!=="JSXAttribute"||te(le(i.name)))continue;let o=i.name.type==="JSXNamespacedName"?i.name.namespace.name:null;if(o==="use"){let s=i.name.name.name;e.used.add(s);let a=De(i,e);r.push(a!=null?`[${s}, () => (${a})]`:`[${s}]`);continue}if(o==="oncapture"){let s=i.name.name.name.toLowerCase(),a=De(i,e)??"undefined";t.push({name:"on:"+s,kind:"attr",expr:`[${a}, { capture: true }]`});continue}t.push(At(i,e))}return r.length>0&&t.push({name:"use",kind:"attr",expr:`[${r.join(", ")}]`}),t}function Je(n,e){let t=[];for(let r of n)if(r.type==="JSXText"){let i=M(r.value);i&&t.push({kind:"text",value:i})}else if(r.type==="JSXExpressionContainer"){if(r.expression?.type!=="JSXEmptyExpression"){let i=r.expression;t.push({kind:"expr",code:e.code(i),reactive:Be(i)})}}else r.type==="JSXElement"||r.type==="JSXFragment"?t.push(Fe(r,e)):r.type==="JSXSpreadChild"&&t.push({kind:"expr",code:e.code(r.expression),reactive:!1});return t}function jt(n){for(let e of n){if(e.type!=="JSXAttribute")continue;let t=le(e.name);if(te(t)){if(e.value&&!ae(e.value))throw new v(`'${t}' needs a literal value, not an expression — the strategy is compile-time.`);return H(t,e.value?A(e.value):null)}}}function Fe(n,e){if(n.type==="JSXFragment")return{kind:"fragment",children:Je(n.children,e)};let{tag:t,component:r}=Pt(n.openingElement.name,e),i=_t(n.openingElement.attributes,e),o=Je(n.children,e);if(r){let s=jt(n.openingElement.attributes);return{kind:"component",name:t,props:i,children:o,...s?{load:s}:{}}}return{kind:"element",tag:t,svg:Ot.has(t),props:i,children:o,static:!1}}function He(n,e){let t=Fe(n,e);return w(t),t}function x(n,e){if(n)switch(n.type){case"Identifier":e.add(n.name);return;case"ObjectPattern":for(let t of n.properties)t.type==="RestElement"?x(t.argument,e):x(t.value,e);return;case"ArrayPattern":for(let t of n.elements)x(t,e);return;case"AssignmentPattern":x(n.left,e);return;case"RestElement":x(n.argument,e);return}}function qe(n,e){switch(n.type){case"ImportDeclaration":for(let t of n.specifiers)x(t.local,e);return;case"VariableDeclaration":for(let t of n.declarations)x(t.id,e);return;case"FunctionDeclaration":case"ClassDeclaration":x(n.id,e);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":n.declaration&&qe(n.declaration,e);return}}function ce(n){let e=new Set;for(let t of n.body)qe(t,e);return e}var Jt=new Set(I),Bt=new Set(T),Ft=new Set(S),Ht=new Set(["createMemo","createEffect","createRenderEffect","createRoot","createSignal","onCleanup","batch","untrack"]);function ue(n,e,t=null,r=""){if(!(!n||typeof n!="object")){if(Array.isArray(n)){for(let i of n)ue(i,e,t,r);return}typeof n.type=="string"&&e(n,t,r);for(let i of Object.keys(n))i==="loc"||i==="leadingComments"||i==="trailingComments"||ue(n[i],e,typeof n.type=="string"?n:t,i)}}var de=n=>n.type==="JSXElement"||n.type==="JSXFragment";function qt(n,e,t){return de(n)?!(e&&de(e)&&t==="children"):!1}function Ut(n,e){return n.type==="TaggedTemplateExpression"&&n.tag?.type==="Identifier"&&(n.tag.name===e||n.tag.name==="svg")}function Ue(n){return n.filter(e=>!n.some(t=>t!==e&&t.start<=e.start&&t.end>=e.end&&t.end-t.start>e.end-e.start))}function Y(n,e,t,r){let i=Ue(r.filter(s=>s.start>=e&&s.end<=t)).sort((s,a)=>a.start-s.start),o=n.slice(e,t);for(let s of i)o=o.slice(0,s.start-e)+s.code+o.slice(s.end-e);return o}function Xt(n,e,t){let r={code:Y(n,e.start,e.end,t),reactive:k(b(e))};return e.type==="ArrowFunctionExpression"&&e.body?.type!=="BlockStatement"&&(r.arrow={params:e.params.map(i=>Y(n,i.start,i.end,t)),body:Y(n,e.body.start,e.body.end,t),bodyReactive:k(b(e.body))}),e.type==="ObjectExpression"&&(r.object=!0),r}function Xe(n,e,t){if(!e||e.length===0)return n;let r=new Map;for(let i of e){let o=`${i.svg?"svg:":""}${i.html}`,s=t.get(o);s||(s=`_fxTmpl$${t.size}`,t.set(o,s)),r.set(i.id,s)}return n.replace(/_tmpl\$\d+/g,i=>r.get(i)??i)}function pe(n,e){if(n.kind==="component"&&n.source){let t=n.source;t.origin==="builtin"?e.builtins.add(n.name):q(t.loading)&&!e.resolved.has(n.name)?e.deferred.set(n.name,t):(e.deferred.delete(n.name),e.resolved.set(n.name,t))}if("props"in n&&n.props)for(let t of n.props)t.kind==="event"&&t.event?.delegated&&e.delegatedEvents.add(t.event.name);if("children"in n&&n.children)for(let t of n.children)pe(t,e)}function zt(n){let e=[`kind: ${JSON.stringify(n.kind)}`];return n.kind==="visible"&&n.rootMargin&&e.push(`rootMargin: ${JSON.stringify(n.rootMargin)}`),n.kind==="interaction"&&e.push(`events: ${JSON.stringify(n.events)}`),n.kind==="media"&&e.push(`query: ${JSON.stringify(n.query)}`),`{ ${e.join(", ")} }`}function Wt(n){let e=[];return n.quasi.quasis.forEach((t,r)=>{if(e.push({kind:"static",text:t.value.cooked??t.value.raw,start:t.start}),r<n.quasi.expressions.length){let i=n.quasi.expressions[r];e.push({kind:"hole",index:r,start:i.start,end:i.end})}}),e}function Gt(n,e,t={}){let r=t.litTag??"html",i=t.format??"both",o=i!=="jsx",s=i!=="lit";if(!(o&&(n.includes(`${r}\``)||n.includes("svg`")))&&!(s&&n.includes("<")))return null;let l=Dt(n,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:!0}),c=[];if(ue(l.program,(f,y,Z)=>{(o&&Ut(f,r)||s&&qt(f,y,Z))&&c.push(f)}),c.length===0)return null;c.sort((f,y)=>y.start-f.start||f.end-y.end);let u=new Set,p={builtins:new Set,resolved:new Map,deferred:new Map,delegatedEvents:new Set},d=new Map,h=[];for(let f of c){let y=c.some(g=>g!==f&&g.start<=f.start&&g.end>=f.end&&g.end-g.start>f.end-f.start);if(de(f)){h.push({start:f.start,end:f.end,code:Vt(n,f,h,y,u,p,d,t)});continue}let Z=f.quasi.expressions.map(g=>Xt(n,g,h)),j=je(Wt(f),Z,{...t,hoistTemplates:!0,templateClone:t.templateClone??!0,partialTemplates:y?!1:t.partialTemplates??!0,svg:f.tag.name==="svg"});for(let g of j.imports)u.add(g);pe(j.ir,p),h.push({start:f.start,end:f.end,code:Xe(j.code,j.templates,d)})}let m=new B(n);for(let f of Ue(h))m.overwrite(f.start,f.end,f.code);let _=ce(l.program),fe=Kt(u,p,d,_,t);fe&&m.prepend(fe);for(let f of l.program.body)f.type==="ImportDeclaration"&&f.source?.value==="@fluixi/core/rx"&&m.overwrite(f.source.start,f.source.end,JSON.stringify("@fluixi/reactive"));return{code:m.toString(),map:m.generateMap({source:e,includeContent:!0,hires:!0})}}function Vt(n,e,t,r,i,o,s,a){let l=He(e,{code:u=>Y(n,u.start,u.end,t),used:i});w(l),U(l,{resolver:K(a.resolve??[]),modules:{controlFlowModule:a.controlFlowModule??a.runtimeModule??"@fluixi/dom",coreModule:a.coreModule??"@fluixi/core",routerModule:a.routerModule??"@fluixi/core/router-next"},strategyFor:u=>u.load}),z(l);let c=C.emit(l,{templateClone:a.templateClone??!0,partialTemplates:r?!1:a.partialTemplates??!0});for(let u of c.imports)i.add(u);return pe(l,o),Xe(c.code,c.templates,s)}function Kt(n,e,t,r,i){let o=i.runtimeModule??"@fluixi/dom",s=i.coreModule??"@fluixi/core",a=new Map,l=(d,h)=>a.set(d,[...a.get(d)??[],h]),c=new Set(n);for(let d of e.builtins)c.add(d);e.delegatedEvents.size>0&&c.add("delegateEvents");for(let d of[...c].sort())r.has(d)||(Ht.has(d)?l(i.reactiveModule??"@fluixi/reactive/signal",d):Ft.has(d)?l(i.routerModule??"@fluixi/core/router-next",d):Bt.has(d)?l(s,d):Jt.has(d)?l(i.controlFlowModule??o,d):l(o,d));for(let[d,h]of e.resolved)r.has(d)||l(h.module,h.export==="default"?`default as ${d}`:d===h.export?d:`${h.export} as ${d}`);let u=[];for(let[d,h]of a)u.push(`import { ${h.join(", ")} } from ${JSON.stringify(d)};`);let p=[...e.deferred].filter(([d])=>!r.has(d));if(p.length>0){r.has("deferred")||u.push(`import { deferred } from ${JSON.stringify(s)};`);for(let[d,h]of p)u.push(`const ${d} = deferred(() => import(${JSON.stringify(h.module)}), { strategy: ${zt(h.loading)}, export: ${JSON.stringify(h.export)} });`)}for(let[d,h]of t)u.push(`const ${h} = ${JSON.stringify(d.startsWith("svg:")?d.slice(4):d)};`);return e.delegatedEvents.size>0&&u.push(`delegateEvents(${JSON.stringify([...e.delegatedEvents])});`),u.length>0?u.join(`
|
|
10
|
+
`?s=!0:u!=="\r"&&s&&(s=!1,a===l.start||(this._splitChunk(l,a),l=l.next),l.prependRight(e))}a+=1}a=l.end,l=l.next}return this.outro=this.outro.replace(r,o),this}insert(){throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)")}insertLeft(e,t){return T.insertLeft||(console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"),T.insertLeft=!0),this.appendLeft(e,t)}insertRight(e,t){return T.insertRight||(console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"),T.insertRight=!0),this.prependRight(e,t)}move(e,t,r){if(e=e+this.offset,t=t+this.offset,r=r+this.offset,r>=e&&r<=t)throw new Error("Cannot move a selection inside itself");this._split(e),this._split(t),this._split(r);let i=this.byStart[e],s=this.byEnd[t],o=i.previous,a=s.next,l=this.byStart[r];if(!l&&s===this.lastChunk)return this;let c=l?l.previous:this.lastChunk;return o&&(o.next=a),a&&(a.previous=o),c&&(c.next=i),l&&(l.previous=s),i.previous||(this.firstChunk=s.next),s.next||(this.lastChunk=i.previous,this.lastChunk.next=null),i.previous=c,s.next=l||null,c||(this.firstChunk=i),l||(this.lastChunk=s),this}overwrite(e,t,r,i){return i=i||{},this.update(e,t,r,{...i,overwrite:!i.contentOnly})}update(e,t,r,i){if(e=e+this.offset,t=t+this.offset,typeof r!="string")throw new 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 new Error("end is out of bounds");if(e===t)throw new Error("Cannot overwrite a zero-length range – use appendLeft or prependRight instead");this._split(e),this._split(t),i===!0&&(T.storeName||(console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"),T.storeName=!0),i={storeName:!0});let s=i!==void 0?i.storeName:!1,o=i!==void 0?i.overwrite:!1;if(s){let c=this.original.slice(e,t);Object.defineProperty(this.storedNames,c,{writable:!0,value:!0,enumerable:!0})}let a=this.byStart[e],l=this.byEnd[t];if(a){let c=a;for(;c!==l;){if(c.next!==this.byStart[c.end])throw new Error("Cannot overwrite across a split point");c=c.next,c.edit("",!1)}a.edit(r,s,!o)}else{let c=new G(e,t,"").edit(r,s);l.next=c,c.previous=l}return this}prepend(e){if(typeof e!="string")throw new TypeError("outro content must be a string");return this.intro=e+this.intro,this}prependLeft(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let r=this.byEnd[e];return r?r.prependLeft(t):this.intro=t+this.intro,this}prependRight(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let r=this.byStart[e];return r?r.prependRight(t):this.outro=t+this.outro,this}remove(e,t){if(e=e+this.offset,t=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 new Error("Character is out of bounds");if(e>t)throw new Error("end must be greater than start");this._split(e),this._split(t);let r=this.byStart[e];for(;r;)r.intro="",r.outro="",r.edit(""),r=t>r.end?this.byStart[r.end]:null;return this}reset(e,t){if(e=e+this.offset,t=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 new Error("Character is out of bounds");if(e>t)throw new Error("end must be greater than start");this._split(e),this._split(t);let r=this.byStart[e];for(;r;)r.reset(),r=t>r.end?this.byStart[r.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(j);if(e!==-1)return this.outro.substr(e+1);let t=this.outro,r=this.lastChunk;do{if(r.outro.length>0){if(e=r.outro.lastIndexOf(j),e!==-1)return r.outro.substr(e+1)+t;t=r.outro+t}if(r.content.length>0){if(e=r.content.lastIndexOf(j),e!==-1)return r.content.substr(e+1)+t;t=r.content+t}if(r.intro.length>0){if(e=r.intro.lastIndexOf(j),e!==-1)return r.intro.substr(e+1)+t;t=r.intro+t}}while(r=r.previous);return e=this.intro.lastIndexOf(j),e!==-1?this.intro.substr(e+1)+t:this.intro+t}slice(e=0,t=this.original.length-this.offset){if(e=e+this.offset,t=t+this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}let r="",i=this.firstChunk;for(;i&&(i.start>e||i.end<=e);){if(i.start<t&&i.end>=t)return r;i=i.next}if(i&&i.edited&&i.start!==e)throw new Error(`Cannot use replaced character ${e} as slice start anchor.`);let s=i;for(;i;){i.intro&&(s!==i||i.start===e)&&(r+=i.intro);let o=i.start<t&&i.end>=t;if(o&&i.edited&&i.end!==t)throw new Error(`Cannot use replaced character ${t} as slice end anchor.`);let a=s===i?e-i.start:0,l=o?i.content.length+t-i.end:i.content.length;if(r+=i.content.slice(a,l),i.outro&&(!o||i.end===t)&&(r+=i.outro),o)break;i=i.next}return r}snip(e,t){let r=this.clone();return r.remove(0,e),r.remove(t,r.original.length),r}_split(e){if(this.byStart[e]||this.byEnd[e])return;let t=this.lastSearchedChunk,r=t,i=e>t.end;for(;t;){if(t.contains(e))return this._splitChunk(t,e);if(t=i?this.byStart[t.end]:this.byEnd[t.start],t===r)return;r=t}}_splitChunk(e,t){if(e.edited&&e.content.length){let i=je(this.original)(t);throw new Error(`Cannot split a chunk that has already been edited (${i.line}:${i.column} – "${e.original}")`)}let r=e.split(t);return this.byEnd[t]=e,this.byStart[t]=r,this.byEnd[r.end]=r,e===this.lastChunk&&(this.lastChunk=r),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=new RegExp((e||"\\s")+"+$");if(this.outro=this.outro.replace(t,""),this.outro.length)return!0;let r=this.lastChunk;do{let i=r.end,s=r.trimEnd(t);if(r.end!==i&&(this.lastChunk===r&&(this.lastChunk=r.next),this.byEnd[r.end]=r,this.byStart[r.next.start]=r.next,this.byEnd[r.next.end]=r.next),s)return!0;r=r.previous}while(r);return!1}trimEnd(e){return this.trimEndAborted(e),this}trimStartAborted(e){let t=new RegExp("^"+(e||"\\s")+"+");if(this.intro=this.intro.replace(t,""),this.intro.length)return!0;let r=this.firstChunk;do{let i=r.end,s=r.trimStart(t);if(r.end!==i&&(r===this.lastChunk&&(this.lastChunk=r.next),this.byEnd[r.end]=r,this.byStart[r.next.start]=r.next,this.byEnd[r.next.end]=r.next),s)return!0;r=r.next}while(r);return!1}trimStart(e){return this.trimStartAborted(e),this}hasChanged(){return this.original!==this.toString()}_replaceRegexp(e,t){function r(s,o){return typeof t=="string"?t.replace(/\$(\$|&|\d+)/g,(a,l)=>l==="$"?"$":l==="&"?s[0]:+l<s.length?s[+l]:`$${l}`):t(...s,s.index,o,s.groups)}function i(s,o){let a,l=[];for(;a=s.exec(o);)l.push(a);return l}if(e.global)i(e,this.original).forEach(o=>{if(o.index!=null){let a=r(o,this.original);a!==o[0]&&this.overwrite(o.index,o.index+o[0].length,a)}});else{let s=this.original.match(e);if(s&&s.index!=null){let o=r(s,this.original);o!==s[0]&&this.overwrite(s.index,s.index+s[0].length,o)}}return this}_replaceString(e,t){let{original:r}=this,i=r.indexOf(e);return i!==-1&&(typeof t=="function"&&(t=t(e,i,r)),e!==t&&this.overwrite(i,i+e.length,t)),this}replace(e,t){return typeof e=="string"?this._replaceString(e,t):this._replaceRegexp(e,t)}_replaceAllString(e,t){let{original:r}=this,i=e.length;for(let s=r.indexOf(e);s!==-1;s=r.indexOf(e,s+i)){let o=r.slice(s,s+i),a=t;typeof t=="function"&&(a=t(o,s,r)),o!==a&&this.overwrite(s,s+i,a)}return this}replaceAll(e,t){if(typeof e=="string")return this._replaceAllString(e,t);if(!e.global)throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");return this._replaceRegexp(e,t)}};function Tt(n){switch(n.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return n.reactive?"reactive-prop":n.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function O(n){let e=[],t=new Map,r=i=>{switch(i.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let s of i.children)r(s);return!1;case"fragment":for(let s of i.children)r(s);return!1;case"element":{let s=!0;for(let a of i.children)r(a)||(s=!1);let o;for(let a of i.props)if(o=Tt(a),o)break;return!o&&!s&&(o=$t(i)),i.static=!o,o?t.set(i,o):e.push(i),i.static}default:return!1}};for(let i of Array.isArray(n)?n:[n])r(i);return{staticElements:e,reasons:t}}function $t(n){for(let e of n.children){if(e.kind==="expr")return"expression-child";if(e.kind==="component")return"component-child";if(e.kind==="control")return"control-child";if(e.kind==="element"&&!e.static||e.kind==="fragment")return"expression-child"}return"expression-child"}var Y={kind:"eager"},Ot=["pointerdown","focusin","keydown"],De=new Set(["eager","idle","visible","interaction","media","never"]),R=class extends Error{};function fe(n){return n.startsWith("load:")}function Z(n,e){let t=n.slice(5);if(!De.has(t))throw new R(`Unknown load strategy 'load:${t}'. Expected one of ${[...De].join(", ")}.`);switch(t){case"eager":return Y;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return e?{kind:"visible",rootMargin:e}:{kind:"visible"};case"interaction":return{kind:"interaction",events:e?Pt(e):[...Ot]};case"media":if(!e)throw new R(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new R(`Unhandled load strategy '${t}'.`)}}function Pt(n){let e=n.split(/[\s,]+/).map(t=>t.trim()).filter(Boolean);if(e.length===0)throw new R("'load:interaction' was given no event names.");return e}function Q(n){return n.kind!=="eager"&&n.kind!=="never"}var D=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],_=["Suspense","SuspenseList","Await"],P=["Router","Outlet","Redirect","Link"],Hn=[...D,..._,...P],he=new Set([...D,..._]);function _e(n={}){let{controlFlowModule:e="@fluixi/dom",coreModule:t="@fluixi/core",routerModule:r="@fluixi/core/router-next"}=n,i={};for(let s of D)i[s]=e;for(let s of _)i[s]=t;for(let s of P)i[s]=r;return i}function ee(n,e={}){let{resolver:t,isBound:r,modules:i,strategyFor:s}=e,o=_e(i),a=new Map,l=new Set,c=p=>{let{name:d}=p;if(!d||d.includes(".")||r?.(d))return;let m=u(d);if(!m){l.add(d);return}let f=m.origin==="builtin"&&he.has(d)?Y:s?.(p)??Y;p.source={...m,loading:f},a.set(d,p.source)},u=p=>{if(he.has(p))return{module:o[p],export:p,origin:"builtin"};let d=t?.resolve(p);if(d)return{module:d.module,export:d.export,origin:"rule"};if(P.includes(p))return{module:o[p],export:p,origin:"builtin"}};return te(n,p=>{p.kind==="component"&&c(p)}),{resolved:a,unresolved:[...l]}}function te(n,e){let t=Array.isArray(n)?n:[n];for(let r of t){e(r);let i=r.children;i&&te(i,e)}}function ne(n){let e=[];te(n,s=>{s.kind==="component"&&s.source&&e.push(s)});let t=new Set,r=new Set;for(let s of e){let{module:o,loading:a}=s.source;a.kind==="eager"&&t.add(o),a.kind==="never"&&r.add(o)}let i=new Map;for(let s of e){let o=s.source;Q(o.loading)&&t.has(o.module)&&(o.loading={kind:"eager"},i.set(o.module,(i.get(o.module)??0)+1))}return{collapsed:i,conflicted:[...r].filter(s=>t.has(s))}}var Lt=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Be={className:"class",htmlFor:"for"},Mt=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),At=new Set(["script","style","textarea","title"]);function me(n){return At.has(n)}function Je(n){return Be[n]??n}function B(n){return n.kind!=="attr"||n.expr!==void 0||n.name.includes(":")?!1:!Mt.has(n.name)}function ge(n){if(!n.static||me(n.tag))return!1;for(let e of n.props)if(!B(e))return!1;for(let e of n.children)if(e.kind!=="text"&&!(e.kind==="element"&&ge(e)))return!1;return!0}function J(n){let e=n.props.map(Dt).filter(Boolean).join(""),t=`<${n.tag}${e}>`;return Lt.has(n.tag)?t:`${t}${n.children.map(jt).join("")}</${n.tag}>`}function jt(n){if(n.kind==="text")return Bt(n.value);if(n.kind!=="element")throw new Error(`serializeStatic: unexpected ${n.kind}`);return J(n)}function Dt(n){let e=Be[n.name]??n.name,t=n.literal;return t===!0||t===void 0?` ${e}`:t===!1||t===null?"":` ${e}="${_t(String(t))}"`}function _t(n){return n.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Bt(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var Jt="<!--fx-->",Ft="<!--fx/-->";function ie(n){return n.kind==="expr"||n.kind==="component"||n.kind==="control"}function Ht(n){return n.kind==="text"||n.kind==="element"&&Fe(n)}function Fe(n){return n.svg||me(n.tag)||!n.props.every(e=>B(e))?!1:n.children.every(e=>Ht(e)||ie(e))}function re(n){if(ie(n))return!0;let e=n.children;return e?e.some(re):!1}function He(n){for(let e=0;e<n.children.length;e++){let t=n.children[e];if(t.kind==="text"&&(t.value===""||n.children[e+1]?.kind==="text"))return!1}return n.children.every(e=>e.kind!=="element"||He(e))}function Ue(n){if(!Fe(n)||!He(n)||!n.children.some(re))return null;let e=[],t=[],r=0,i=o=>{let a=`_n$${r++}`;return e.push({ref:a,expr:o}),a};return s(n,"_el$"),{html:Ut(n),tag:n.tag,steps:e,holes:t};function s(o,a){let l=-1;o.children.forEach((u,p)=>{re(u)&&(l=p)});let c=null;for(let u=0;u<=l;u++){let p=o.children[u],d=c?`${c}.nextSibling`:`${a}.firstChild`;if(ie(p)){let f=i(d),g=i(`holeEnd(${f})`);t.push({parentRef:a,startRef:f,endRef:g,node:p}),c=g;continue}let m=i(d);p.kind==="element"&&re(p)&&s(p,m),c=m}}}function Ut(n){return J(qe(n)).split(Xe).join(Jt+Ft)}function qe(n){return{...n,children:n.children.map(e=>ie(e)?{kind:"text",value:Xe}:e.kind==="element"?qe(e):e)}}var Xe="\0fx-hole\0";var ye={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},Qn={version:2,module:"@fluixi/dom",symbols:[...ye.symbols,"template","cloneTemplate","walk"]};var qt={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function Xt(n){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(n)}function Ve(n){return Xt(n)?n:JSON.stringify(n)}function zt(n){return n.expr!==void 0?n.reactive?`() => (${n.expr})`:`(${n.expr})`:JSON.stringify(n.literal??!0)}function Vt(n){return n.expr!==void 0?`(${n.expr})`:JSON.stringify(n.literal??!0)}function Wt(n,e,t){let r=n.filter(a=>a.kind==="spread"),s=n.filter(a=>a.kind!=="spread").map(a=>`${Ve(a.name)}: ${zt(a)}`);e!=null&&s.push(`children: ${e}`);let o=`{ ${s.join(", ")} }`;return r.length>0?(t.add("mergeProps"),`mergeProps(${r.map(a=>a.expr).join(", ")}, ${o})`):o}function We(n,e,t){return n.length===1?F(n[0],e,t):`[${n.map(r=>F(r,e,t)).join(", ")}]`}function ze(n,e,t,r,i){r.add("createMemo"),r.add("createComponent");let s=e.filter(c=>c.kind==="spread"),a=e.filter(c=>c.kind!=="spread").map(c=>`get ${Ve(c.name)}() { return ${Vt(c)}; }`);t.length>0&&a.push(`get children() { return ${We(t,r,i)}; }`);let l=`{ ${a.join(", ")} }`;return s.length>0&&(r.add("mergeProps"),l=`mergeProps(${s.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${n}, ${l}))`}function Kt(n,e){let t=Je(e.name),r=e.literal;return r===!0||r===void 0?`${n}.setAttribute(${JSON.stringify(t)}, "");`:r===!1||r===null?"":`${n}.setAttribute(${JSON.stringify(t)}, ${JSON.stringify(String(r))});`}var Ke=!1;function F(n,e,t){switch(n.kind){case"text":return JSON.stringify(n.value);case"expr":return n.reactive?`() => (${n.code})`:`(${n.code})`;case"fragment":return n.children.length===0?"null":We(n.children,e,t);case"component":return ze(n.name,n.props,n.children,e,t);case"control":{let r=qt[n.control]??n.control;return e.add(r),ze(r,n.props,n.children,e,t)}case"element":{if(t&&n.static&&!n.svg&&ge(n)){e.add("templateNode");let a=`_tmpl$${t.length}`;return t.push({id:a,html:J(n),tag:n.tag,svg:!1}),`templateNode(${a}, ${JSON.stringify(n.tag)})`}if(t&&Ke){let a=Ue(n);if(a){e.add("templateNode"),e.add("insert"),e.add("holeEnd"),e.add("holeContent"),e.add("holeScope");let l=`_tmpl$${t.length}`;t.push({id:l,html:a.html,tag:a.tag,svg:!1});let c=[`const _el$ = templateNode(${l}, ${JSON.stringify(a.tag)}, true);`];for(let u of a.steps)c.push(`const ${u.ref} = ${u.expr};`);for(let u of a.holes)c.push(`insert(${u.parentRef}, holeScope(${u.startRef}, () => (${F(u.node,e,t)})), ${u.endRef}, holeContent(${u.startRef}, ${u.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}e.add("createNativeElement");let r=JSON.stringify(n.tag),i="_el$",s=[],o=n.svg?`${r}, true`:r;if(s.push(`const ${i} = createNativeElement(${o});`),n.props.length>0)if(!n.svg&&n.props.every(B))for(let a of n.props)s.push(Kt(i,a));else{e.add("spread");let a=n.svg?", isSVG: true":"";s.push(`spread({ element: ${i}, props: ${Wt(n.props,null,e)}${a} });`)}for(let a of n.children){e.add("insert");let l=F(a,e,t),c=a.kind==="expr"&&a.reactive||a.kind==="component"||a.kind==="control";s.push(c?`insert(${i}, ${l}, null);`:`insert(${i}, ${l});`)}return s.push(`return ${i};`),`(() => { ${s.join(" ")} })()`}}}function se(n,e){if(!e||e.length===0)return n;let t=new Map(e.map(r=>[r.id,JSON.stringify(r.html)]));return n.replace(/_tmpl\$\d+/g,r=>t.get(r)??r)}var L={name:"imperative",contract:ye,emit(n,e){let t=new Set,r=e?.templateClone!==!1?[]:void 0;return Ke=e?.partialTemplates===!0,{code:F(n,t,r),imports:Array.from(t),templates:r}}};var Gt=n=>"components"in n;function Ge(n,e){return n.replace(/\$(\d+)/g,(t,r)=>e[Number(r)]??t)}function Yt(n,e){return typeof e=="string"?{module:e,export:n}:e}function oe(n=[]){let e=new Map,t=[],r=[];for(let o of n){if(!Gt(o)){r.push(o);continue}for(let[a,l]of Object.entries(o.components)){let c=Yt(a,l),u=e.get(a);if(u&&u.module!==c.module){let p=t.find(d=>d.name===a);p?p.modules.push(c.module):t.push({name:a,modules:[u.module,c.module]});continue}e.set(a,c)}}let i=new Map;return{resolve:o=>{if(i.has(o))return i.get(o);let a=e.get(o);if(!a)for(let l of r){let c=o.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(c){a={module:Ge(l.module,c),export:l.export?Ge(l.export,c):o};break}}return i.set(o,a),a},names:()=>[...e.keys()],conflicts:()=>t}}import{parseTemplate as Zt}from"@fluixi/template-parser";function H(n){let e=n.split(/\r\n|\n|\r/),t=0;for(let i=0;i<e.length;i++)/[^ \t]/.test(e[i])&&(t=i);let r="";for(let i=0;i<e.length;i++){let s=e[i].replace(/\t/g," ");i!==0&&(s=s.replace(/^ +/,"")),i!==e.length-1&&(s=s.replace(/ +$/,"")),s&&(i!==t&&(s+=" "),r+=s)}return r}var Ye=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Qt(n){return n.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function Ze(n){return n.charAt(0).toUpperCase()+n.slice(1)}var ve=class{constructor(e,t){this.holes=e;this.used=t}hole(e){return this.holes[e]??{code:"undefined",reactive:!1}}emit(e){let{code:t,imports:r,templates:i}=L.emit(e,{});for(let s of r)this.used.add(s);return se(t,i)}lowerRoot(e){let t=this.lowerChildren(e);return t.length===1?t[0]:{kind:"fragment",children:t}}lowerChildren(e){let t=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.kind==="Element"||i.kind==="Component"){let o=i.attributes.find(a=>a.kind==="IfDirective");if(o&&o.kind==="IfDirective"){let a=r+1;a<e.length&&this.isBlankText(e[a])&&a++;let l=e[a],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(u=>u.kind==="ElseDirective");t.push(this.lowerIf(i,o.hole,c?l:null)),c&&(r=a);continue}if(i.attributes.some(a=>a.kind==="EachDirective")){t.push(this.lowerEach(i));continue}}let s=this.lowerNode(i);s&&t.push(s)}return t}isBlankText(e){return e.kind==="Text"&&!e.raw&&H(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let t=H(e.value);return t?{kind:"text",value:t}:null}case"Comment":return null;case"Expression":{let t=this.hole(e.hole);return{kind:"expr",code:t.code,reactive:t.reactive}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(e.children)};case"Element":return this.lowerElement(e);case"Component":return this.lowerComponent(e);default:return null}}lowerElement(e){let t=e.attributes.find(r=>r.kind==="Attribute"&&r.name==="is");if(e.tag==="component"&&t&&t.value&&t.value.kind==="hole"){let r=e.attributes.filter(s=>s!==t),i=this.lowerComponent({...e,kind:"Component",tag:"Dynamic",tagHole:null,attributes:r});return i.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(t.value.hole).code})`}),i}return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:this.lowerAttributes(e.attributes),children:this.lowerChildren(e.children),static:!1}}lowerComponent(e){let t=e.tagHole!=null?this.hole(e.tagHole).code:e.tag,r=this.lowerAttributes(e.attributes),{slots:i,rest:s}=this.partitionSlots(e.children);for(let[l,c]of i){let u=c.length===1?c[0]:{kind:"fragment",children:c},p={name:l,kind:"attr",expr:this.emit(u),jsxElement:!0},d=r.findIndex(m=>m.name===l);d>=0?r[d]=p:r.push(p)}let o=e.attributes.find(l=>l.kind==="LoadDirective"),a=o?Z(`load:${o.strategy}`,o.modifier):void 0;return{kind:"component",name:t,props:r,children:this.lowerChildren(s),...a?{load:a}:{}}}partitionSlots(e){let t=new Map,r=[];for(let i of e){if(i.kind==="Element"||i.kind==="Component"){let s=i.attributes.find(o=>o.kind==="Attribute"&&o.name==="slot");if(s&&s.value&&s.value.kind==="static"){let o={...i,attributes:i.attributes.filter(c=>c!==s)},a=o.kind==="Element"?this.lowerElement(o):this.lowerComponent(o),l=t.get(s.value.value)??[];l.push(a),t.set(s.value.value,l);continue}}r.push(i)}return{slots:t,rest:r}}lowerIf(e,t,r){let i=this.hole(t),s=[{name:"when",kind:"attr",expr:i.code,reactive:i.reactive}];if(r){let a=this.stripAndLower(r,l=>l.kind==="ElseDirective");s.push({name:"fallback",kind:"attr",expr:this.emit(a),jsxElement:!0})}let o=this.stripAndLower(e,a=>a.kind==="IfDirective");return{kind:"component",name:"Show",props:s,children:[o]}}lowerEach(e){let t=e.attributes.find(l=>l.kind==="EachDirective");if(!t||t.kind!=="EachDirective")return this.lowerNode(e);let r=this.hole(t.hole),i=[{name:"each",kind:"attr",expr:r.code,reactive:r.reactive}];if(t.key){let l="static"in t.key?`(item) => item[${JSON.stringify(t.key.static)}]`:this.hole(t.key.hole).code;i.push({name:"by",kind:"attr",expr:l})}let s=this.itemArrow(e),o;if(s){let l={kind:"expr",code:s.body,reactive:s.bodyReactive},c=this.rebuildWithChildren(e,[l]);o=`(${s.params.join(", ")}) => (${this.emit(c)})`}else{let l=this.stripAndLower(e,c=>c.kind==="EachDirective");o=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:i,children:[{kind:"expr",code:o,reactive:!1}]}}itemArrow(e){let t=e.children.filter(r=>!this.isBlankText(r));return t.length!==1||t[0].kind!=="Expression"?null:this.hole(t[0].hole).arrow??null}stripAndLower(e,t){let r={...e,attributes:e.attributes.filter(i=>!t(i))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(e,t){let r=this.lowerAttributes(e.attributes.filter(i=>i.kind!=="EachDirective"));return e.kind==="Element"?{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:r,children:t,static:!1}:{kind:"component",name:e.tag,props:r,children:t}}lowerAttributes(e){let t=[],r=[],i=!1,s=[],o=!1,a=[];for(let l of e)switch(l.kind){case"IfDirective":case"EachDirective":case"ElseDirective":break;case"Attribute":t.push(this.plainAttr(l));break;case"PropertyBinding":t.push({name:l.name,kind:"prop",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"EventBinding":t.push(this.eventProp(l));break;case"RefBinding":t.push({name:"ref",kind:"ref",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"Spread":t.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let c=this.hole(l.hole);r.push(`${JSON.stringify(l.name)}: ${c.code}`),i=i||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);s.push(`${JSON.stringify(l.name)}: ${c.code}`),o=o||c.reactive;break}case"BindDirective":t.push(...this.bindProps(l.name,this.hole(l.hole).code));break;case"UseDirective":{let c=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!c)break;a.push(l.name!=null&&l.hole!=null?`[${c}, () => (${this.hole(l.hole).code})]`:`[${c}]`);break}}return r.length>0&&t.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:i}),s.length>0&&t.push({name:"style",kind:"attr",expr:`{ ${s.join(", ")} }`,reactive:o}),a.length>0&&t.push({name:"use",kind:"attr",expr:`[${a.join(", ")}]`}),t}eventProp(e){let t=e.name.toLowerCase(),r=this.hole(e.hole).code;if(!(e.syntax==="colon"||e.modifiers.length>0))return{name:"on"+Ze(e.name),kind:"event",event:{name:t,delegated:Ye.has(t)},expr:r};let s=this.wrapHandler(r,e.modifiers),o=this.eventOptions(e.modifiers),a=o?`[${s}, ${o}]`:s;return{name:"on:"+t,kind:"attr",expr:a}}wrapHandler(e,t){let r=t.includes("self")?"if (e.target !== e.currentTarget) return; ":"",i=[];return t.includes("prevent")&&i.push("e.preventDefault();"),t.includes("stop")&&i.push("e.stopPropagation();"),!r&&i.length===0?e:`(e) => { ${r}${i.join(" ")} return (${e})(e); }`}eventOptions(e){let t=[];return e.includes("capture")&&t.push("capture: true"),e.includes("once")&&t.push("once: true"),e.includes("passive")&&t.push("passive: true"),t.length?`{ ${t.join(", ")} }`:null}bindProps(e,t){let r=e==="checked",i=r?"change":"input",s=r?"checked":"value";this.used.add("bindPair");let o=`bindPair(${t})`;return[{name:e,kind:"attr",expr:`${o}[0]()`,reactive:!0},{name:"on"+Ze(i),kind:"event",event:{name:i,delegated:Ye.has(i)},expr:`(e) => ${o}[1](e.target.${s})`}]}plainAttr(e){let t=e.value,r=e.name;e.name==="class"?r=t&&t.kind==="hole"&&this.hole(t.hole).object?"classList":"className":e.name==="html"&&(r="innerHTML");let s={name:r,kind:"attr"};if(t==null)return s.literal=!0,s;if(t.kind==="static")return s.literal=t.value,s;if(t.kind==="hole"){let l=this.hole(t.hole);return s.expr=l.code,s.reactive=l.reactive,s}let o=!1,a=t.parts.map(l=>{if("text"in l)return Qt(l.text);let c=this.hole(l.hole);return o=o||c.reactive,"${"+c.code+"}"}).join("");return s.expr="`"+a+"`",s.reactive=o,s}};function Qe(n,e,t,r={}){let{root:i}=Zt(n,{svg:r.svg});return new ve(e,t).lowerRoot(i.children)}function et(n,e,t={}){let r=new Set,i=Qe(n,[...e],r,{svg:t.svg});O(i),ee(i,{resolver:oe(t.resolve??[]),modules:{controlFlowModule:t.controlFlowModule??"@fluixi/dom",coreModule:t.coreModule??"@fluixi/core",routerModule:t.routerModule??"@fluixi/core/router-next"},strategyFor:l=>l.load}),ne(i);let{code:s,imports:o,templates:a}=L.emit(i,{templateClone:t.templateClone,partialTemplates:t.partialTemplates});for(let l of o)r.add(l);return t.hoistTemplates?{code:s,imports:[...r],ir:i,templates:a}:{code:se(s,a),imports:[...r],ir:i}}var en="children";function M(n){switch(n.kind){case"call":return!0;case"member":return n.property!==en;case"compound":return n.parts.some(M);case"opaque":return!1}}var tn=new Set(["CallExpression","OptionalCallExpression"]),nn=new Set(["MemberExpression","OptionalMemberExpression"]);function E(n){if(!n)return{kind:"opaque"};if(tn.has(n.type))return{kind:"call"};if(nn.has(n.type)){let e=n.property;return{kind:"member",property:!(n.computed===!0)&&e?.type==="Identifier"?e.name:null}}return n.type==="ConditionalExpression"?{kind:"compound",parts:[n.test,n.consequent,n.alternate].map(U)}:n.type==="LogicalExpression"||n.type==="BinaryExpression"?{kind:"compound",parts:[n.left,n.right].map(U)}:n.type==="TemplateLiteral"?{kind:"compound",parts:n.expressions.map(U)}:n.type==="ObjectExpression"?{kind:"compound",parts:n.properties.filter(t=>(t.type==="ObjectProperty"||t.type==="Property")&&t.computed!==!0).map(t=>U(t.value))}:n.type==="ArrayExpression"?{kind:"compound",parts:n.elements.filter(t=>t!=null&&t.type!=="SpreadElement").map(U)}:{kind:"opaque"}}var U=n=>E(n);var rn=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),sn=/^on[A-Z]/,on=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]),rt=n=>M(E(n));function q(n){if(n.type==="StringLiteral"||n.type==="NumericLiteral"||n.type==="BooleanLiteral"||n.type==="Literal"&&(typeof n.value=="string"||typeof n.value=="number"||typeof n.value=="boolean"))return n.value}var xe=n=>!!n&&typeof q(n)=="string";function an(n,e){return n.type==="JSXIdentifier"?{tag:n.name,component:n.name[0]!==n.name[0].toLowerCase()}:n.type==="JSXMemberExpression"?{tag:e.code(n),component:!0}:n.type==="JSXNamespacedName"?{tag:`${n.namespace.name}:${n.name.name}`,component:!1}:{tag:"div",component:!1}}function be(n){return n.type==="JSXIdentifier"?n.name==="class"?"className":n.name:n.type==="JSXNamespacedName"?`${n.namespace.name}:${n.name.name}`:"unknown"}function ln(n,e){let t=be(n.name),r=sn.test(t),i=r||t.startsWith("on:")||t==="ref",o={name:t,kind:r?"event":"attr"};if(r){let l=t.slice(2).toLowerCase();o.event={name:l,delegated:on.has(l)}}let a=n.value;if(a==null)return o.literal=!0,o;if(xe(a))return o.literal=q(a),o;if(a.type==="JSXExpressionContainer"&&a.expression?.type!=="JSXEmptyExpression"){let l=a.expression,c=q(l);return c!==void 0?(o.literal=c,o):(o.expr=e.code(l),o.reactive=i?!1:rt(l),(l.type==="JSXElement"||l.type==="JSXFragment")&&(o.jsxElement=!0),o)}return o.literal=!0,o}function tt(n,e){let t=n.value;return t==null?null:xe(t)?JSON.stringify(q(t)):t.type==="JSXExpressionContainer"&&t.expression?.type!=="JSXEmptyExpression"?e.code(t.expression):null}function cn(n,e){let t=[],r=[];for(let i of n){if(i.type==="JSXSpreadAttribute"){t.push({name:"",kind:"spread",expr:e.code(i.argument)});continue}if(i.type!=="JSXAttribute"||fe(be(i.name)))continue;let s=i.name.type==="JSXNamespacedName"?i.name.namespace.name:null;if(s==="use"){let o=i.name.name.name;e.used.add(o);let a=tt(i,e);r.push(a!=null?`[${o}, () => (${a})]`:`[${o}]`);continue}if(s==="oncapture"){let o=i.name.name.name.toLowerCase(),a=tt(i,e)??"undefined";t.push({name:"on:"+o,kind:"attr",expr:`[${a}, { capture: true }]`});continue}t.push(ln(i,e))}return r.length>0&&t.push({name:"use",kind:"attr",expr:`[${r.join(", ")}]`}),t}function nt(n,e){let t=[];for(let r of n)if(r.type==="JSXText"){let i=H(r.value);i&&t.push({kind:"text",value:i})}else if(r.type==="JSXExpressionContainer"){if(r.expression?.type!=="JSXEmptyExpression"){let i=r.expression;t.push({kind:"expr",code:e.code(i),reactive:rt(i)})}}else r.type==="JSXElement"||r.type==="JSXFragment"?t.push(it(r,e)):r.type==="JSXSpreadChild"&&t.push({kind:"expr",code:e.code(r.expression),reactive:!1});return t}function un(n){for(let e of n){if(e.type!=="JSXAttribute")continue;let t=be(e.name);if(fe(t)){if(e.value&&!xe(e.value))throw new R(`'${t}' needs a literal value, not an expression — the strategy is compile-time.`);return Z(t,e.value?q(e.value):null)}}}function it(n,e){if(n.type==="JSXFragment")return{kind:"fragment",children:nt(n.children,e)};let{tag:t,component:r}=an(n.openingElement.name,e),i=cn(n.openingElement.attributes,e),s=nt(n.children,e);if(r){let o=un(n.openingElement.attributes);return{kind:"component",name:t,props:i,children:s,...o?{load:o}:{}}}return{kind:"element",tag:t,svg:rn.has(t),props:i,children:s,static:!1}}function st(n,e){let t=it(n,e);return O(t),t}function S(n,e){if(n)switch(n.type){case"Identifier":e.add(n.name);return;case"ObjectPattern":for(let t of n.properties)t.type==="RestElement"?S(t.argument,e):S(t.value,e);return;case"ArrayPattern":for(let t of n.elements)S(t,e);return;case"AssignmentPattern":S(n.left,e);return;case"RestElement":S(n.argument,e);return}}function ot(n,e){switch(n.type){case"ImportDeclaration":for(let t of n.specifiers)S(t.local,e);return;case"VariableDeclaration":for(let t of n.declarations)S(t.id,e);return;case"FunctionDeclaration":case"ClassDeclaration":S(n.id,e);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":n.declaration&&ot(n.declaration,e);return}}function X(n){let e=new Set;for(let t of n.body)ot(t,e);return e}import{parse as fn}from"@babel/parser";function v(n,e){if(n)switch(n.type){case"Identifier":e.add(n.name);return;case"ObjectPattern":for(let t of n.properties)t.type==="RestElement"?v(t.argument,e):v(t.value,e);return;case"ArrayPattern":for(let t of n.elements)v(t,e);return;case"AssignmentPattern":v(n.left,e);return;case"RestElement":v(n.argument,e);return}}function Ne(n){switch(n.type){case"StringLiteral":case"NumericLiteral":case"BooleanLiteral":case"NullLiteral":case"BigIntLiteral":case"RegExpLiteral":case"Identifier":return!0;case"Literal":return!0;case"TemplateLiteral":return n.expressions.every(Ne);case"UnaryExpression":return Ne(n.argument);case"MemberExpression":return!1;default:return!1}}function ae(n,e){if(!(!n||typeof n!="object")){e(n);for(let t of Object.keys(n)){if(t==="loc"||t==="range"||t==="leadingComments"||t==="trailingComments")continue;let r=n[t];if(Array.isArray(r))for(let i of r)i&&typeof i=="object"&&ae(i,e);else r&&typeof r=="object"&&typeof r.type=="string"&&ae(r,e)}}}function dn(n){let e=new Set;return ae(n,t=>{if(t.type==="AssignmentExpression")v(t.left,e);else if(t.type==="UpdateExpression"){let r=t.argument;r?.type==="Identifier"&&e.add(r.name)}}),e}function pn(n,e){let t=new Set,r=i=>{let s=new Set;v(i,s);for(let o of s)e.has(o)&&t.add(o)};return ae(n,i=>{switch(i.type){case"VariableDeclarator":r(i.id);return;case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":r(i.id);for(let s of i.params??[])r(s);return;case"CatchClause":r(i.param);return;case"ClassDeclaration":case"ClassExpression":r(i.id);return}}),t}function at(n,e,t){for(let r of n.properties??[]){if(r.type==="RestElement"){let u=r.argument;if(u?.type!=="Identifier"||e.length>0){let p=new Set;v(u,p);for(let d of p)t.bails.push({name:d,reason:"rest"});continue}t.rest={name:u.name,keys:[]};continue}if(r.computed){let u=new Set;v(r.value,u);for(let p of u)t.bails.push({name:p,reason:"computed"});continue}let i=r.key,s=i.type==="Identifier"?i.name:i.value,o=r.value,a;o.type==="AssignmentPattern"&&(a=o.right,o=o.left);let l=[...e,s];if(o.type==="Identifier"){if(a&&!Ne(a)){t.bails.push({name:o.name,reason:"unsafe-default"});continue}t.reads.push({name:o.name,path:l,...a?{fallback:a}:{}});continue}if(o.type==="ObjectPattern"){if(a){let u=new Set;v(o,u);for(let p of u)t.bails.push({name:p,reason:"unsafe-default"});continue}at(o,l,t);continue}let c=new Set;v(o,c);for(let u of c)t.bails.push({name:u,reason:"computed"})}}function we(n,e){let t={reads:[],bails:[]};if(n?.type!=="ObjectPattern"||(at(n,[],t),t.rest&&(e?.type!=="BlockStatement"?(t.bails.push({name:t.rest.name,reason:"rest"}),delete t.rest):t.rest.keys=(n.properties??[]).filter(a=>a.type!=="RestElement"&&!a.computed).map(a=>{let l=a.key;return l.type==="Identifier"?l.name:l.value})),t.reads.length===0&&!t.rest))return t;let r=new Set(t.reads.map(a=>a.name));t.rest&&r.add(t.rest.name);let i=dn(e),s=pn(e,r),o=[];for(let a of t.reads)i.has(a.name)?t.bails.push({name:a.name,reason:"reassigned"}):s.has(a.name)?t.bails.push({name:a.name,reason:"shadowed"}):o.push(a);return t.reads=o,t.rest&&i.has(t.rest.name)?(t.bails.push({name:t.rest.name,reason:"reassigned"}),delete t.rest):t.rest&&s.has(t.rest.name)&&(t.bails.push({name:t.rest.name,reason:"shadowed"}),delete t.rest),t}function Re(n){switch(n){case"rest":return"this rest element cannot be served by splitProps, and copying the props into a plain object would lose the getters";case"computed":return"the property is not known until it runs";case"reassigned":return"the binding is assigned to, and props are read-only";case"shadowed":return"an inner scope binds the same name";case"unsafe-default":return"the default would have to run again on every read"}}function z(n,e,t=null){if(!(!n||typeof n!="object"||typeof n.type!="string")&&!n.type.startsWith("TS")&&e(n,t)!==!1)for(let r of Object.keys(n)){if(r==="loc"||r==="leadingComments"||r==="trailingComments")continue;let i=n[r];if(Array.isArray(i))for(let s of i)z(s,e,n);else i&&typeof i=="object"&&z(i,e,n)}}function lt(n){return!!n&&n[0]>="A"&&n[0]<="Z"}function hn(n){let e=[];return z(n,t=>{if(t.type==="FunctionDeclaration"&<(t.id?.name)){e.push(t);return}if(t.type==="VariableDeclarator"&<(t.id?.name)){let r=t.init;r&&(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")&&e.push(r)}}),e}function mn(n){let e=new Set;return z(n,t=>{t.type==="Identifier"&&e.add(t.name)}),e}function gn(n,e){if(!e)return!0;switch(e.type){case"MemberExpression":case"OptionalMemberExpression":return!(e.property===n&&!e.computed);case"ObjectProperty":case"ObjectMethod":case"ClassProperty":case"ClassMethod":return!(e.key===n&&!e.computed);case"LabeledStatement":case"BreakStatement":case"ContinueStatement":return e.label!==n;case"ImportSpecifier":case"ExportSpecifier":return!1;default:return!0}}function Se(n,e,t={}){let r=[],i=[],s=new Set;for(let o of hn(n)){let a=o.params?.[0];if(a?.type!=="ObjectPattern")continue;let l=we(a,o.body);for(let f of l.bails)i.push({name:f.name,reason:f.reason,message:Re(f.reason),start:a.start});if(l.bails.length>0||l.reads.length===0&&!l.rest)continue;let c=mn(o),u=t.parameterName??"props";for(;c.has(u);)u=`_${u}`;let p=new Map;for(let f of l.reads){let g=`${u}.${f.path.join(".")}`,y=f.fallback;p.set(f.name,y?`(${g} === undefined ? ${e.slice(y.start,y.end)} : ${g})`:g)}let d=a.typeAnnotation;if(r.push({start:a.start,end:d?.start??a.end,code:u}),l.rest){let f=l.rest.keys.map(y=>JSON.stringify(y)).join(", "),g=o.body;r.push({start:g.start+1,end:g.start+1,code:`
|
|
11
|
+
const [, ${l.rest.name}] = splitProps(${u}, [${f}]);`}),s.add("splitProps")}let m=[];z(o.body,(f,g)=>{if(f.type!=="Identifier")return;let y=p.get(f.name);if(!y)return;let w=g?.type==="ObjectProperty"&&g.shorthand&&g.value===f;if(!w&&!gn(f,g))return;let x=l.reads.find(V=>V.name===f.name).path;m.push({node:f,parent:w?g:null,text:y,property:x[x.length-1]})});for(let f of m)f.parent?r.push({start:f.parent.start,end:f.parent.end,code:`${f.node.name}: ${f.text}`}):r.push({start:f.node.start,end:f.node.end,code:f.text}),yn(f.node,u,f.property)}return{edits:r,diagnostics:i,used:s}}function yn(n,e,t){n.type="MemberExpression",n.computed=!1,n.optional=!1,n.object={type:"Identifier",name:e,start:n.start,end:n.start},n.property={type:"Identifier",name:t,start:n.end,end:n.end},delete n.name}function vn(n,e="module.tsx",t={}){let r=fn(n,{sourceType:"module",plugins:["typescript","jsx"],errorRecovery:!0}),{edits:i,diagnostics:s,used:o}=Se(r.program,n,t),a=new $(n);for(let l of i)l.start===l.end?a.appendLeft(l.start,l.code):a.overwrite(l.start,l.end,l.code);return o.has("splitProps")&&!X(r.program).has("splitProps")&&a.prepend(`import { splitProps } from ${JSON.stringify(t.runtimeModule??"@fluixi/dom")};
|
|
12
|
+
`),{code:a.toString(),map:a.generateMap({source:e,includeContent:!0,hires:!0}),diagnostics:s,rewritten:i.filter(l=>l.code!==(t.parameterName??"props")).length}}var C="@fluixi/reactive/signal",I={$signal:{export:"signal",module:C,returns:"signal-handle"},$memo:{export:"memo",module:C,returns:"memo-handle"},$effect:{export:"effect",module:C,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:C,returns:"resource-handle"},$selector:{export:"createSelector",module:C,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:C,returns:"memo-accessor"},$untrack:{export:"untrack",module:C,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}},ct={signal:"signal-handle",memo:"memo-handle",effect:"effect",store:"store-handle",createSignal:["signal-accessor","signal-setter"],createMemo:"memo-accessor",createEffect:"effect",createRenderEffect:"effect",createStore:"reactive-object",resource:"resource-handle",createResource:"reactive-object",createSelector:"memo-accessor",createDeferred:"memo-accessor"},xn=["@fluixi/reactive","@fluixi/reactive/signal","@fluixi/reactive/signal-next","@fluixi/reactive/store","@fluixi/core","@fluixi/core/rx"],bn=new RegExp(`\\$(?:${Object.keys(I).map(n=>n.slice(1)).join("|")})\\s*\\(`);function ut(n){return bn.test(n)}function dt(n){return Object.prototype.hasOwnProperty.call(I,n)}function pt(n){return xn.includes(n)}function b(n,e){if(n)switch(n.type){case"Identifier":e.add(n.name);return;case"ObjectPattern":for(let t of n.properties??[])t.type==="RestElement"?b(t.argument,e):b(t.value,e);return;case"ArrayPattern":for(let t of n.elements??[])b(t,e);return;case"AssignmentPattern":b(n.left,e);return;case"RestElement":b(n.argument,e);return}}function le(n,e){if(!(!n||typeof n!="object"||typeof n.type!="string")){e(n);for(let t of Object.keys(n)){if(t==="loc"||t==="leadingComments"||t==="trailingComments")continue;let r=n[t];if(Array.isArray(r))for(let i of r)le(i,e);else r&&typeof r=="object"&&le(r,e)}}}function Nn(n,e){if(n.type!=="CallExpression")return;let t=n.callee;if(t?.type!=="Identifier")return;let r=t.name,i=e.primitives.get(r);if(i)return i;let s=I[r];if(s&&!e.shadowed.has(r))return s.returns}function wn(n,e,t){if(Array.isArray(e)){n.type==="ArrayPattern"&&n.elements.forEach((r,i)=>{let s=e[i];r?.type==="Identifier"&&s&&t.set(r.name,s)});return}n.type==="Identifier"&&t.set(n.name,e)}function ft(n){let e={kinds:new Map,primitives:new Map,shadowed:new Set},t=n;le(t,r=>{let i=new Set;if(r.type==="VariableDeclarator")b(r.id,i);else if(r.type==="FunctionDeclaration"||r.type==="ClassDeclaration")b(r.id,i);else if(r.type==="ImportDefaultSpecifier"||r.type==="ImportNamespaceSpecifier")b(r.local,i);else if(r.type==="ImportSpecifier")b(r.local,i);else if(r.type==="FunctionExpression"||r.type==="ArrowFunctionExpression"||r.type==="FunctionDeclaration")for(let s of r.params??[])b(s,i);for(let s of i)I[s]&&e.shadowed.add(s)});for(let r of t.body??[])if(r.type==="ImportDeclaration"&&pt(r.source?.value))for(let i of r.specifiers??[]){if(i.type!=="ImportSpecifier")continue;let s=i.imported,o=s.type==="Identifier"?s.name:s.value,a=ct[o];a&&e.primitives.set(i.local.name,a)}return le(t,r=>{if(r.type!=="VariableDeclarator"||!r.init)return;let i=Nn(r.init,e);i&&wn(r.id,i,e.kinds)}),e}function ke(n,e){if(!(!n||typeof n!="object"||typeof n.type!="string")){e(n);for(let t of Object.keys(n)){if(t==="loc"||t==="leadingComments"||t==="trailingComments")continue;let r=n[t];if(Array.isArray(r))for(let i of r)ke(i,e);else r&&typeof r=="object"&&ke(r,e)}}}function ht(n){let e=[],t=[],r=new Map,i=new Set,{shadowed:s}=ft(n);return ke(n,o=>{if(o.type!=="CallExpression")return;let a=o.callee;if(a?.type!=="Identifier")return;let l=a.name;if(!dt(l))return;if(s.has(l)){i.has(l)||(i.add(l),t.push({name:l,message:`${l} is reserved for the compiler, and this module binds it. The call keeps your binding's meaning; rename it to use the intrinsic.`,start:a.start}));return}let c=I[l];e.push({start:a.start,end:a.end,code:c.export});let u=r.get(c.module)??new Set;u.add(c.export),r.set(c.module,u)}),{edits:e,diagnostics:t,imports:r}}function mt(n,e){let t=[];for(let[r,i]of[...n.imports].sort(([s],[o])=>s.localeCompare(o))){let s=[...i].filter(o=>!e.has(o)).sort();s.length&&t.push(`import { ${s.join(", ")} } from ${JSON.stringify(r)};`)}return t.length?`${t.join(`
|
|
13
|
+
`)}
|
|
14
|
+
`:""}var Sn=new Set(D),kn=new Set(_),En=new Set(P),Cn=new Set(["createMemo","createEffect","createRenderEffect","createRoot","createSignal","onCleanup","batch","untrack"]);function Ee(n,e,t=null,r=""){if(!(!n||typeof n!="object")){if(Array.isArray(n)){for(let i of n)Ee(i,e,t,r);return}typeof n.type=="string"&&e(n,t,r);for(let i of Object.keys(n))i==="loc"||i==="leadingComments"||i==="trailingComments"||Ee(n[i],e,typeof n.type=="string"?n:t,i)}}var Ce=n=>n.type==="JSXElement"||n.type==="JSXFragment";function In(n,e,t){return Ce(n)?!(e&&Ce(e)&&t==="children"):!1}function Tn(n,e){return n.type==="TaggedTemplateExpression"&&n.tag?.type==="Identifier"&&(n.tag.name===e||n.tag.name==="svg")}function gt(n){return n.filter(e=>!n.some(t=>t!==e&&t.start<=e.start&&t.end>=e.end&&t.end-t.start>e.end-e.start))}function ce(n,e,t,r){let i=gt(r.filter(o=>o.start>=e&&o.end<=t)).sort((o,a)=>a.start-o.start),s=n.slice(e,t);for(let o of i)s=s.slice(0,o.start-e)+o.code+s.slice(o.end-e);return s}function $n(n,e,t){let r={code:ce(n,e.start,e.end,t),reactive:M(E(e))};return e.type==="ArrowFunctionExpression"&&e.body?.type!=="BlockStatement"&&(r.arrow={params:e.params.map(i=>ce(n,i.start,i.end,t)),body:ce(n,e.body.start,e.body.end,t),bodyReactive:M(E(e.body))}),e.type==="ObjectExpression"&&(r.object=!0),r}function yt(n,e,t){if(!e||e.length===0)return n;let r=new Map;for(let i of e){let s=`${i.svg?"svg:":""}${i.html}`,o=t.get(s);o||(o=`_fxTmpl$${t.size}`,t.set(s,o)),r.set(i.id,o)}return n.replace(/_tmpl\$\d+/g,i=>r.get(i)??i)}function Ie(n,e){if(n.kind==="component"&&n.source){let t=n.source;t.origin==="builtin"?e.builtins.add(n.name):Q(t.loading)&&!e.resolved.has(n.name)?e.deferred.set(n.name,t):(e.deferred.delete(n.name),e.resolved.set(n.name,t))}if("props"in n&&n.props)for(let t of n.props)t.kind==="event"&&t.event?.delegated&&e.delegatedEvents.add(t.event.name);if("children"in n&&n.children)for(let t of n.children)Ie(t,e)}function On(n){let e=[`kind: ${JSON.stringify(n.kind)}`];return n.kind==="visible"&&n.rootMargin&&e.push(`rootMargin: ${JSON.stringify(n.rootMargin)}`),n.kind==="interaction"&&e.push(`events: ${JSON.stringify(n.events)}`),n.kind==="media"&&e.push(`query: ${JSON.stringify(n.query)}`),`{ ${e.join(", ")} }`}function Pn(n){let e=[];return n.quasi.quasis.forEach((t,r)=>{if(e.push({kind:"static",text:t.value.cooked??t.value.raw,start:t.start}),r<n.quasi.expressions.length){let i=n.quasi.expressions[r];e.push({kind:"hole",index:r,start:i.start,end:i.end})}}),e}function Ln(n,e,t={}){let r=t.litTag??"html",i=t.format??"both",s=i!=="jsx",o=i!=="lit",a=s&&(n.includes(`${r}\``)||n.includes("svg`")),l=t.intrinsics!==!1&&ut(n);if(!a&&!(o&&n.includes("<"))&&!l)return null;let c=Rn(n,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:!0}),u=[];Ee(c.program,(h,k,ue)=>{(s&&Tn(h,r)||o&&In(h,k,ue))&&u.push(h)});let p=t.propsDestructure?Se(c.program,n,{runtimeModule:t.runtimeModule}):{edits:[],diagnostics:[],used:new Set},d=t.intrinsics===!1?{edits:[],diagnostics:[],imports:new Map}:ht(c.program);if(u.length===0&&p.edits.length===0&&d.edits.length===0&&d.diagnostics.length===0&&p.diagnostics.length===0)return null;u.sort((h,k)=>k.start-h.start||h.end-k.end);let f=new Set(p.used),g={builtins:new Set,resolved:new Map,deferred:new Map,delegatedEvents:new Set},y=new Map,w=[...p.edits,...d.edits];for(let h of u){let k=u.some(N=>N!==h&&N.start<=h.start&&N.end>=h.end&&N.end-N.start>h.end-h.start);if(Ce(h)){w.push({start:h.start,end:h.end,code:Mn(n,h,w,k,f,g,y,t)});continue}let ue=h.quasi.expressions.map(N=>$n(n,N,w)),W=et(Pn(h),ue,{...t,hoistTemplates:!0,templateClone:t.templateClone??!0,partialTemplates:k?!1:t.partialTemplates??!0,svg:h.tag.name==="svg"});for(let N of W.imports)f.add(N);Ie(W.ir,g),w.push({start:h.start,end:h.end,code:yt(W.code,W.templates,y)})}let x=new $(n);for(let h of gt(w))h.start===h.end?x.appendLeft(h.start,h.code):x.overwrite(h.start,h.end,h.code);let V=X(c.program),Te=An(f,g,y,V,t);Te&&x.prepend(Te);let $e=mt(d,V);$e&&x.prepend($e);for(let h of c.program.body)h.type==="ImportDeclaration"&&h.source?.value==="@fluixi/core/rx"&&x.overwrite(h.source.start,h.source.end,JSON.stringify("@fluixi/reactive"));return{code:x.toString(),map:x.generateMap({source:e,includeContent:!0,hires:!0}),...p.diagnostics.length?{propsDiagnostics:p.diagnostics}:{},...d.diagnostics.length?{intrinsicDiagnostics:d.diagnostics}:{}}}function Mn(n,e,t,r,i,s,o,a){let l=st(e,{code:u=>ce(n,u.start,u.end,t),used:i});O(l),ee(l,{resolver:oe(a.resolve??[]),modules:{controlFlowModule:a.controlFlowModule??a.runtimeModule??"@fluixi/dom",coreModule:a.coreModule??"@fluixi/core",routerModule:a.routerModule??"@fluixi/core/router-next"},strategyFor:u=>u.load}),ne(l);let c=L.emit(l,{templateClone:a.templateClone??!0,partialTemplates:r?!1:a.partialTemplates??!0});for(let u of c.imports)i.add(u);return Ie(l,s),yt(c.code,c.templates,o)}function An(n,e,t,r,i){let s=i.runtimeModule??"@fluixi/dom",o=i.coreModule??"@fluixi/core",a=new Map,l=(d,m)=>a.set(d,[...a.get(d)??[],m]),c=new Set(n);for(let d of e.builtins)c.add(d);e.delegatedEvents.size>0&&c.add("delegateEvents");for(let d of[...c].sort())r.has(d)||(Cn.has(d)?l(i.reactiveModule??"@fluixi/reactive/signal",d):En.has(d)?l(i.routerModule??"@fluixi/core/router-next",d):kn.has(d)?l(o,d):Sn.has(d)?l(i.controlFlowModule??s,d):l(s,d));for(let[d,m]of e.resolved)r.has(d)||l(m.module,m.export==="default"?`default as ${d}`:d===m.export?d:`${m.export} as ${d}`);let u=[];for(let[d,m]of a)u.push(`import { ${m.join(", ")} } from ${JSON.stringify(d)};`);let p=[...e.deferred].filter(([d])=>!r.has(d));if(p.length>0){r.has("deferred")||u.push(`import { deferred } from ${JSON.stringify(o)};`);for(let[d,m]of p)u.push(`const ${d} = deferred(() => import(${JSON.stringify(m.module)}), { strategy: ${On(m.loading)}, export: ${JSON.stringify(m.export)} });`)}for(let[d,m]of t)u.push(`const ${m} = ${JSON.stringify(d.startsWith("svg:")?d.slice(4):d)};`);return e.delegatedEvents.size>0&&u.push(`delegateEvents(${JSON.stringify([...e.delegatedEvents])});`),u.length>0?u.join(`
|
|
11
15
|
`)+`
|
|
12
|
-
`:null}export{
|
|
16
|
+
`:null}export{Re as explainBail,X as moduleBindings,we as planPropsDestructure,E as shapeOf,vn as transformProps,Ln as transformTemplates};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";var m=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var b=(t,n)=>{for(var r in n)m(t,r,{get:n[r],enumerable:!0})},w=(t,n,r,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of h(n))!S.call(t,i)&&i!==r&&m(t,i,{get:()=>n[i],enumerable:!(e=R(n,i))||e.enumerable});return t};var E=t=>w(m({},"__esModule",{value:!0}),t);var D={};b(D,{collectIntrinsicEdits:()=>$,intrinsicImports:()=>C});module.exports=E(D);var f="@fluixi/reactive/signal",d={$signal:{export:"signal",module:f,returns:"signal-handle"},$memo:{export:"memo",module:f,returns:"memo-handle"},$effect:{export:"effect",module:f,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:f,returns:"resource-handle"},$selector:{export:"createSelector",module:f,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:f,returns:"memo-accessor"},$untrack:{export:"untrack",module:f,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}},I={signal:"signal-handle",memo:"memo-handle",effect:"effect",store:"store-handle",createSignal:["signal-accessor","signal-setter"],createMemo:"memo-accessor",createEffect:"effect",createRenderEffect:"effect",createStore:"reactive-object",resource:"resource-handle",createResource:"reactive-object",createSelector:"memo-accessor",createDeferred:"memo-accessor"},k=["@fluixi/reactive","@fluixi/reactive/signal","@fluixi/reactive/signal-next","@fluixi/reactive/store","@fluixi/core","@fluixi/core/rx"],P=new RegExp(`\\$(?:${Object.keys(d).map(t=>t.slice(1)).join("|")})\\s*\\(`);function N(t){return Object.prototype.hasOwnProperty.call(d,t)}function x(t){return k.includes(t)}function o(t,n){if(t)switch(t.type){case"Identifier":n.add(t.name);return;case"ObjectPattern":for(let r of t.properties??[])r.type==="RestElement"?o(r.argument,n):o(r.value,n);return;case"ArrayPattern":for(let r of t.elements??[])o(r,n);return;case"AssignmentPattern":o(t.left,n);return;case"RestElement":o(t.argument,n);return}}function p(t,n){if(!(!t||typeof t!="object"||typeof t.type!="string")){n(t);for(let r of Object.keys(t)){if(r==="loc"||r==="leadingComments"||r==="trailingComments")continue;let e=t[r];if(Array.isArray(e))for(let i of e)p(i,n);else e&&typeof e=="object"&&p(e,n)}}}function M(t,n){if(t.type!=="CallExpression")return;let r=t.callee;if(r?.type!=="Identifier")return;let e=r.name,i=n.primitives.get(e);if(i)return i;let s=d[e];if(s&&!n.shadowed.has(e))return s.returns}function j(t,n,r){if(Array.isArray(n)){t.type==="ArrayPattern"&&t.elements.forEach((e,i)=>{let s=n[i];e?.type==="Identifier"&&s&&r.set(e.name,s)});return}t.type==="Identifier"&&r.set(t.name,n)}function v(t){let n={kinds:new Map,primitives:new Map,shadowed:new Set},r=t;p(r,e=>{let i=new Set;if(e.type==="VariableDeclarator")o(e.id,i);else if(e.type==="FunctionDeclaration"||e.type==="ClassDeclaration")o(e.id,i);else if(e.type==="ImportDefaultSpecifier"||e.type==="ImportNamespaceSpecifier")o(e.local,i);else if(e.type==="ImportSpecifier")o(e.local,i);else if(e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"||e.type==="FunctionDeclaration")for(let s of e.params??[])o(s,i);for(let s of i)d[s]&&n.shadowed.add(s)});for(let e of r.body??[])if(e.type==="ImportDeclaration"&&x(e.source?.value))for(let i of e.specifiers??[]){if(i.type!=="ImportSpecifier")continue;let s=i.imported,a=s.type==="Identifier"?s.name:s.value,c=I[a];c&&n.primitives.set(i.local.name,c)}return p(r,e=>{if(e.type!=="VariableDeclarator"||!e.init)return;let i=M(e.init,n);i&&j(e.id,i,n.kinds)}),n}function g(t,n){if(!(!t||typeof t!="object"||typeof t.type!="string")){n(t);for(let r of Object.keys(t)){if(r==="loc"||r==="leadingComments"||r==="trailingComments")continue;let e=t[r];if(Array.isArray(e))for(let i of e)g(i,n);else e&&typeof e=="object"&&g(e,n)}}}function $(t){let n=[],r=[],e=new Map,i=new Set,{shadowed:s}=v(t);return g(t,a=>{if(a.type!=="CallExpression")return;let c=a.callee;if(c?.type!=="Identifier")return;let l=c.name;if(!N(l))return;if(s.has(l)){i.has(l)||(i.add(l),r.push({name:l,message:`${l} is reserved for the compiler, and this module binds it. The call keeps your binding's meaning; rename it to use the intrinsic.`,start:c.start}));return}let u=d[l];n.push({start:c.start,end:c.end,code:u.export});let y=e.get(u.module)??new Set;y.add(u.export),e.set(u.module,y)}),{edits:n,diagnostics:r,imports:e}}function C(t,n){let r=[];for(let[e,i]of[...t.imports].sort(([s],[a])=>s.localeCompare(a))){let s=[...i].filter(a=>!n.has(a)).sort();s.length&&r.push(`import { ${s.join(", ")} } from ${JSON.stringify(e)};`)}return r.length?`${r.join(`
|
|
2
|
+
`)}
|
|
3
|
+
`:""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface IntrinsicEdit {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
code: string;
|
|
5
|
+
}
|
|
6
|
+
export interface IntrinsicDiagnostic {
|
|
7
|
+
/** The `$` name the module bound itself. */
|
|
8
|
+
name: string;
|
|
9
|
+
message: string;
|
|
10
|
+
start: number;
|
|
11
|
+
}
|
|
12
|
+
export interface IntrinsicsResult {
|
|
13
|
+
edits: IntrinsicEdit[];
|
|
14
|
+
diagnostics: IntrinsicDiagnostic[];
|
|
15
|
+
/** Runtime exports the rewritten code needs, by module. */
|
|
16
|
+
imports: Map<string, Set<string>>;
|
|
17
|
+
}
|
|
18
|
+
/** Find the `$` calls in a module and say what they compile to. */
|
|
19
|
+
export declare function collectIntrinsicEdits(program: unknown): IntrinsicsResult;
|
|
20
|
+
/** The import statements a result needs, minus anything the module already binds. */
|
|
21
|
+
export declare function intrinsicImports(result: IntrinsicsResult, bound: Set<string>): string;
|
|
22
|
+
//# sourceMappingURL=intrinsics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intrinsics.d.ts","sourceRoot":"","sources":["../../src/transform/intrinsics.ts"],"names":[],"mappings":"AAwBA,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,mBAAmB;IAClC,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,WAAW,EAAE,mBAAmB,EAAE,CAAC;IACnC,2DAA2D;IAC3D,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;CACnC;AAaD,mEAAmE;AACnE,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAuCxE;AAED,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAOrF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile the `$` intrinsics into the runtime calls they stand for.
|
|
3
|
+
*
|
|
4
|
+
* const [count, setCount] = $signal(0);
|
|
5
|
+
* → const [count, setCount] = createSignal(0); + the import
|
|
6
|
+
*
|
|
7
|
+
* Only the callee is rewritten, so arguments keep the author's text and the span stays
|
|
8
|
+
* put — `$signal(0)` and `createSignal(0)` map to the same place. Imports are collected
|
|
9
|
+
* from what the module actually used, so a file with one `$signal` gets one import.
|
|
10
|
+
*
|
|
11
|
+
* A module that binds `$signal` itself keeps its own meaning and is reported instead;
|
|
12
|
+
* the compiler quietly rewriting code that means something else is the one outcome
|
|
13
|
+
* worth failing over.
|
|
14
|
+
*/
|
|
15
|
+
import { INTRINSICS, isIntrinsicName } from '../analyze/intrinsics.js';
|
|
16
|
+
import { resolveReactiveBindings } from '../analyze/reactive-bindings.js';
|
|
17
|
+
function walk(root, visit) {
|
|
18
|
+
if (!root || typeof root !== 'object' || typeof root.type !== 'string')
|
|
19
|
+
return;
|
|
20
|
+
visit(root);
|
|
21
|
+
for (const key of Object.keys(root)) {
|
|
22
|
+
if (key === 'loc' || key === 'leadingComments' || key === 'trailingComments')
|
|
23
|
+
continue;
|
|
24
|
+
const value = root[key];
|
|
25
|
+
if (Array.isArray(value))
|
|
26
|
+
for (const item of value)
|
|
27
|
+
walk(item, visit);
|
|
28
|
+
else if (value && typeof value === 'object')
|
|
29
|
+
walk(value, visit);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Find the `$` calls in a module and say what they compile to. */
|
|
33
|
+
export function collectIntrinsicEdits(program) {
|
|
34
|
+
const edits = [];
|
|
35
|
+
const diagnostics = [];
|
|
36
|
+
const imports = new Map();
|
|
37
|
+
const reported = new Set();
|
|
38
|
+
const { shadowed } = resolveReactiveBindings(program);
|
|
39
|
+
walk(program, (node) => {
|
|
40
|
+
if (node.type !== 'CallExpression')
|
|
41
|
+
return;
|
|
42
|
+
const callee = node.callee;
|
|
43
|
+
if (callee?.type !== 'Identifier')
|
|
44
|
+
return;
|
|
45
|
+
const name = callee.name;
|
|
46
|
+
if (!isIntrinsicName(name))
|
|
47
|
+
return;
|
|
48
|
+
if (shadowed.has(name)) {
|
|
49
|
+
if (!reported.has(name)) {
|
|
50
|
+
reported.add(name);
|
|
51
|
+
diagnostics.push({
|
|
52
|
+
name,
|
|
53
|
+
message: `${name} is reserved for the compiler, and this module binds it. The call keeps your binding's meaning; rename it to use the intrinsic.`,
|
|
54
|
+
start: callee.start,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const intrinsic = INTRINSICS[name];
|
|
60
|
+
// The callee only. Arguments are untouched, so a template or JSX inside one is still
|
|
61
|
+
// compiled by the pass that owns it.
|
|
62
|
+
edits.push({ start: callee.start, end: callee.end, code: intrinsic.export });
|
|
63
|
+
const forModule = imports.get(intrinsic.module) ?? new Set();
|
|
64
|
+
forModule.add(intrinsic.export);
|
|
65
|
+
imports.set(intrinsic.module, forModule);
|
|
66
|
+
});
|
|
67
|
+
return { edits, diagnostics, imports };
|
|
68
|
+
}
|
|
69
|
+
/** The import statements a result needs, minus anything the module already binds. */
|
|
70
|
+
export function intrinsicImports(result, bound) {
|
|
71
|
+
const lines = [];
|
|
72
|
+
for (const [module, names] of [...result.imports].sort(([a], [b]) => a.localeCompare(b))) {
|
|
73
|
+
const wanted = [...names].filter((name) => !bound.has(name)).sort();
|
|
74
|
+
if (wanted.length)
|
|
75
|
+
lines.push(`import { ${wanted.join(', ')} } from ${JSON.stringify(module)};`);
|
|
76
|
+
}
|
|
77
|
+
return lines.length ? `${lines.join('\n')}\n` : '';
|
|
78
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var f="@fluixi/reactive/signal",d={$signal:{export:"signal",module:f,returns:"signal-handle"},$memo:{export:"memo",module:f,returns:"memo-handle"},$effect:{export:"effect",module:f,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:f,returns:"resource-handle"},$selector:{export:"createSelector",module:f,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:f,returns:"memo-accessor"},$untrack:{export:"untrack",module:f,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}},y={signal:"signal-handle",memo:"memo-handle",effect:"effect",store:"store-handle",createSignal:["signal-accessor","signal-setter"],createMemo:"memo-accessor",createEffect:"effect",createRenderEffect:"effect",createStore:"reactive-object",resource:"resource-handle",createResource:"reactive-object",createSelector:"memo-accessor",createDeferred:"memo-accessor"},v=["@fluixi/reactive","@fluixi/reactive/signal","@fluixi/reactive/signal-next","@fluixi/reactive/store","@fluixi/core","@fluixi/core/rx"],S=new RegExp(`\\$(?:${Object.keys(d).map(t=>t.slice(1)).join("|")})\\s*\\(`);function I(t){return Object.prototype.hasOwnProperty.call(d,t)}function N(t){return v.includes(t)}function o(t,n){if(t)switch(t.type){case"Identifier":n.add(t.name);return;case"ObjectPattern":for(let r of t.properties??[])r.type==="RestElement"?o(r.argument,n):o(r.value,n);return;case"ArrayPattern":for(let r of t.elements??[])o(r,n);return;case"AssignmentPattern":o(t.left,n);return;case"RestElement":o(t.argument,n);return}}function p(t,n){if(!(!t||typeof t!="object"||typeof t.type!="string")){n(t);for(let r of Object.keys(t)){if(r==="loc"||r==="leadingComments"||r==="trailingComments")continue;let e=t[r];if(Array.isArray(e))for(let i of e)p(i,n);else e&&typeof e=="object"&&p(e,n)}}}function R(t,n){if(t.type!=="CallExpression")return;let r=t.callee;if(r?.type!=="Identifier")return;let e=r.name,i=n.primitives.get(e);if(i)return i;let s=d[e];if(s&&!n.shadowed.has(e))return s.returns}function h(t,n,r){if(Array.isArray(n)){t.type==="ArrayPattern"&&t.elements.forEach((e,i)=>{let s=n[i];e?.type==="Identifier"&&s&&r.set(e.name,s)});return}t.type==="Identifier"&&r.set(t.name,n)}function x(t){let n={kinds:new Map,primitives:new Map,shadowed:new Set},r=t;p(r,e=>{let i=new Set;if(e.type==="VariableDeclarator")o(e.id,i);else if(e.type==="FunctionDeclaration"||e.type==="ClassDeclaration")o(e.id,i);else if(e.type==="ImportDefaultSpecifier"||e.type==="ImportNamespaceSpecifier")o(e.local,i);else if(e.type==="ImportSpecifier")o(e.local,i);else if(e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"||e.type==="FunctionDeclaration")for(let s of e.params??[])o(s,i);for(let s of i)d[s]&&n.shadowed.add(s)});for(let e of r.body??[])if(e.type==="ImportDeclaration"&&N(e.source?.value))for(let i of e.specifiers??[]){if(i.type!=="ImportSpecifier")continue;let s=i.imported,a=s.type==="Identifier"?s.name:s.value,c=y[a];c&&n.primitives.set(i.local.name,c)}return p(r,e=>{if(e.type!=="VariableDeclarator"||!e.init)return;let i=R(e.init,n);i&&h(e.id,i,n.kinds)}),n}function m(t,n){if(!(!t||typeof t!="object"||typeof t.type!="string")){n(t);for(let r of Object.keys(t)){if(r==="loc"||r==="leadingComments"||r==="trailingComments")continue;let e=t[r];if(Array.isArray(e))for(let i of e)m(i,n);else e&&typeof e=="object"&&m(e,n)}}}function j(t){let n=[],r=[],e=new Map,i=new Set,{shadowed:s}=x(t);return m(t,a=>{if(a.type!=="CallExpression")return;let c=a.callee;if(c?.type!=="Identifier")return;let l=c.name;if(!I(l))return;if(s.has(l)){i.has(l)||(i.add(l),r.push({name:l,message:`${l} is reserved for the compiler, and this module binds it. The call keeps your binding's meaning; rename it to use the intrinsic.`,start:c.start}));return}let u=d[l];n.push({start:c.start,end:c.end,code:u.export});let g=e.get(u.module)??new Set;g.add(u.export),e.set(u.module,g)}),{edits:n,diagnostics:r,imports:e}}function $(t,n){let r=[];for(let[e,i]of[...t.imports].sort(([s],[a])=>s.localeCompare(a))){let s=[...i].filter(a=>!n.has(a)).sort();s.length&&r.push(`import { ${s.join(", ")} } from ${JSON.stringify(e)};`)}return r.length?`${r.join(`
|
|
2
|
+
`)}
|
|
3
|
+
`:""}export{j as collectIntrinsicEdits,$ as intrinsicImports};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";var $=Object.create;var h=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var J=(e,n)=>{for(var t in n)h(e,t,{get:n[t],enumerable:!0})},D=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of T(n))!V.call(e,r)&&r!==t&&h(e,r,{get:()=>n[r],enumerable:!(s=L(n,r))||s.enumerable});return e};var U=(e,n,t)=>(t=e!=null?$(F(e)):{},D(n||!e||!e.__esModule?h(t,"default",{value:e,enumerable:!0}):t,e)),W=e=>D(h({},"__esModule",{value:!0}),e);var Q={};J(Q,{collectPropsEdits:()=>M,transformProps:()=>K});module.exports=W(Q);var A=require("@babel/parser"),C=U(require("magic-string"),1);function l(e,n){if(e)switch(e.type){case"Identifier":n.add(e.name);return;case"ObjectPattern":for(let t of e.properties)t.type==="RestElement"?l(t.argument,n):l(t.value,n);return;case"ArrayPattern":for(let t of e.elements)l(t,n);return;case"AssignmentPattern":l(e.left,n);return;case"RestElement":l(e.argument,n);return}}function P(e){switch(e.type){case"StringLiteral":case"NumericLiteral":case"BooleanLiteral":case"NullLiteral":case"BigIntLiteral":case"RegExpLiteral":case"Identifier":return!0;case"Literal":return!0;case"TemplateLiteral":return e.expressions.every(P);case"UnaryExpression":return P(e.argument);case"MemberExpression":return!1;default:return!1}}function b(e,n){if(!(!e||typeof e!="object")){n(e);for(let t of Object.keys(e)){if(t==="loc"||t==="range"||t==="leadingComments"||t==="trailingComments")continue;let s=e[t];if(Array.isArray(s))for(let r of s)r&&typeof r=="object"&&b(r,n);else s&&typeof s=="object"&&typeof s.type=="string"&&b(s,n)}}}function Z(e){let n=new Set;return b(e,t=>{if(t.type==="AssignmentExpression")l(t.left,n);else if(t.type==="UpdateExpression"){let s=t.argument;s?.type==="Identifier"&&n.add(s.name)}}),n}function _(e,n){let t=new Set,s=r=>{let u=new Set;l(r,u);for(let c of u)n.has(c)&&t.add(c)};return b(e,r=>{switch(r.type){case"VariableDeclarator":s(r.id);return;case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":s(r.id);for(let u of r.params??[])s(u);return;case"CatchClause":s(r.param);return;case"ClassDeclaration":case"ClassExpression":s(r.id);return}}),t}function E(e,n,t){for(let s of e.properties??[]){if(s.type==="RestElement"){let d=s.argument;if(d?.type!=="Identifier"||n.length>0){let f=new Set;l(d,f);for(let w of f)t.bails.push({name:w,reason:"rest"});continue}t.rest={name:d.name,keys:[]};continue}if(s.computed){let d=new Set;l(s.value,d);for(let f of d)t.bails.push({name:f,reason:"computed"});continue}let r=s.key,u=r.type==="Identifier"?r.name:r.value,c=s.value,a;c.type==="AssignmentPattern"&&(a=c.right,c=c.left);let i=[...n,u];if(c.type==="Identifier"){if(a&&!P(a)){t.bails.push({name:c.name,reason:"unsafe-default"});continue}t.reads.push({name:c.name,path:i,...a?{fallback:a}:{}});continue}if(c.type==="ObjectPattern"){if(a){let d=new Set;l(c,d);for(let f of d)t.bails.push({name:f,reason:"unsafe-default"});continue}E(c,i,t);continue}let N=new Set;l(c,N);for(let d of N)t.bails.push({name:d,reason:"computed"})}}function v(e,n){let t={reads:[],bails:[]};if(e?.type!=="ObjectPattern"||(E(e,[],t),t.rest&&(n?.type!=="BlockStatement"?(t.bails.push({name:t.rest.name,reason:"rest"}),delete t.rest):t.rest.keys=(e.properties??[]).filter(a=>a.type!=="RestElement"&&!a.computed).map(a=>{let i=a.key;return i.type==="Identifier"?i.name:i.value})),t.reads.length===0&&!t.rest))return t;let s=new Set(t.reads.map(a=>a.name));t.rest&&s.add(t.rest.name);let r=Z(n),u=_(n,s),c=[];for(let a of t.reads)r.has(a.name)?t.bails.push({name:a.name,reason:"reassigned"}):u.has(a.name)?t.bails.push({name:a.name,reason:"shadowed"}):c.push(a);return t.reads=c,t.rest&&r.has(t.rest.name)?(t.bails.push({name:t.rest.name,reason:"reassigned"}),delete t.rest):t.rest&&u.has(t.rest.name)&&(t.bails.push({name:t.rest.name,reason:"shadowed"}),delete t.rest),t}function R(e){switch(e){case"rest":return"this rest element cannot be served by splitProps, and copying the props into a plain object would lose the getters";case"computed":return"the property is not known until it runs";case"reassigned":return"the binding is assigned to, and props are read-only";case"shadowed":return"an inner scope binds the same name";case"unsafe-default":return"the default would have to run again on every read"}}function g(e,n){if(e)switch(e.type){case"Identifier":n.add(e.name);return;case"ObjectPattern":for(let t of e.properties)t.type==="RestElement"?g(t.argument,n):g(t.value,n);return;case"ArrayPattern":for(let t of e.elements)g(t,n);return;case"AssignmentPattern":g(e.left,n);return;case"RestElement":g(e.argument,n);return}}function j(e,n){switch(e.type){case"ImportDeclaration":for(let t of e.specifiers)g(t.local,n);return;case"VariableDeclaration":for(let t of e.declarations)g(t.id,n);return;case"FunctionDeclaration":case"ClassDeclaration":g(e.id,n);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":e.declaration&&j(e.declaration,n);return}}function O(e){let n=new Set;for(let t of e.body)j(t,n);return n}function y(e,n,t=null){if(!(!e||typeof e!="object"||typeof e.type!="string")&&!e.type.startsWith("TS")&&n(e,t)!==!1)for(let s of Object.keys(e)){if(s==="loc"||s==="leadingComments"||s==="trailingComments")continue;let r=e[s];if(Array.isArray(r))for(let u of r)y(u,n,e);else r&&typeof r=="object"&&y(r,n,e)}}function I(e){return!!e&&e[0]>="A"&&e[0]<="Z"}function q(e){let n=[];return y(e,t=>{if(t.type==="FunctionDeclaration"&&I(t.id?.name)){n.push(t);return}if(t.type==="VariableDeclarator"&&I(t.id?.name)){let s=t.init;s&&(s.type==="ArrowFunctionExpression"||s.type==="FunctionExpression")&&n.push(s)}}),n}function z(e){let n=new Set;return y(e,t=>{t.type==="Identifier"&&n.add(t.name)}),n}function G(e,n){if(!n)return!0;switch(n.type){case"MemberExpression":case"OptionalMemberExpression":return!(n.property===e&&!n.computed);case"ObjectProperty":case"ObjectMethod":case"ClassProperty":case"ClassMethod":return!(n.key===e&&!n.computed);case"LabeledStatement":case"BreakStatement":case"ContinueStatement":return n.label!==e;case"ImportSpecifier":case"ExportSpecifier":return!1;default:return!0}}function M(e,n,t={}){let s=[],r=[],u=new Set;for(let c of q(e)){let a=c.params?.[0];if(a?.type!=="ObjectPattern")continue;let i=v(a,c.body);for(let o of i.bails)r.push({name:o.name,reason:o.reason,message:R(o.reason),start:a.start});if(i.bails.length>0||i.reads.length===0&&!i.rest)continue;let N=z(c),d=t.parameterName??"props";for(;N.has(d);)d=`_${d}`;let f=new Map;for(let o of i.reads){let p=`${d}.${o.path.join(".")}`,m=o.fallback;f.set(o.name,m?`(${p} === undefined ? ${n.slice(m.start,m.end)} : ${p})`:p)}let w=a.typeAnnotation;if(s.push({start:a.start,end:w?.start??a.end,code:d}),i.rest){let o=i.rest.keys.map(m=>JSON.stringify(m)).join(", "),p=c.body;s.push({start:p.start+1,end:p.start+1,code:`
|
|
2
|
+
const [, ${i.rest.name}] = splitProps(${d}, [${o}]);`}),u.add("splitProps")}let k=[];y(c.body,(o,p)=>{if(o.type!=="Identifier")return;let m=f.get(o.name);if(!m)return;let x=p?.type==="ObjectProperty"&&p.shorthand&&p.value===o;if(!x&&!G(o,p))return;let S=i.reads.find(B=>B.name===o.name).path;k.push({node:o,parent:x?p:null,text:m,property:S[S.length-1]})});for(let o of k)o.parent?s.push({start:o.parent.start,end:o.parent.end,code:`${o.node.name}: ${o.text}`}):s.push({start:o.node.start,end:o.node.end,code:o.text}),H(o.node,d,o.property)}return{edits:s,diagnostics:r,used:u}}function H(e,n,t){e.type="MemberExpression",e.computed=!1,e.optional=!1,e.object={type:"Identifier",name:n,start:e.start,end:e.start},e.property={type:"Identifier",name:t,start:e.end,end:e.end},delete e.name}function K(e,n="module.tsx",t={}){let s=(0,A.parse)(e,{sourceType:"module",plugins:["typescript","jsx"],errorRecovery:!0}),{edits:r,diagnostics:u,used:c}=M(s.program,e,t),a=new C.default(e);for(let i of r)i.start===i.end?a.appendLeft(i.start,i.code):a.overwrite(i.start,i.end,i.code);return c.has("splitProps")&&!O(s.program).has("splitProps")&&a.prepend(`import { splitProps } from ${JSON.stringify(t.runtimeModule??"@fluixi/dom")};
|
|
3
|
+
`),{code:a.toString(),map:a.generateMap({source:n,includeContent:!0,hires:!0}),diagnostics:u,rewritten:r.filter(i=>i.code!==(t.parameterName??"props")).length}}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import MagicString from 'magic-string';
|
|
2
|
+
import { type DestructureBail } from '../analyze/props-destructure.js';
|
|
3
|
+
export interface PropsDiagnostic {
|
|
4
|
+
/** The binding we couldn't rewrite. */
|
|
5
|
+
name: string;
|
|
6
|
+
reason: DestructureBail;
|
|
7
|
+
/** Sentence for the message. */
|
|
8
|
+
message: string;
|
|
9
|
+
/** Character offset of the pattern it came from. */
|
|
10
|
+
start: number;
|
|
11
|
+
}
|
|
12
|
+
export interface PropsTransformOptions {
|
|
13
|
+
/** Name to give the props parameter. @default 'props' */
|
|
14
|
+
parameterName?: string;
|
|
15
|
+
/** Module `splitProps` is imported from when a rest needs it. @default '@fluixi/dom' */
|
|
16
|
+
runtimeModule?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface PropsTransformResult {
|
|
19
|
+
code: string;
|
|
20
|
+
map: ReturnType<MagicString['generateMap']>;
|
|
21
|
+
diagnostics: PropsDiagnostic[];
|
|
22
|
+
/** How many bindings were rewritten. Zero means the source came back untouched. */
|
|
23
|
+
rewritten: number;
|
|
24
|
+
}
|
|
25
|
+
/** One span to replace. Same shape the template transform uses for its own edits. */
|
|
26
|
+
export interface PropsEdit {
|
|
27
|
+
start: number;
|
|
28
|
+
end: number;
|
|
29
|
+
code: string;
|
|
30
|
+
}
|
|
31
|
+
export interface PropsEditsResult {
|
|
32
|
+
edits: PropsEdit[];
|
|
33
|
+
diagnostics: PropsDiagnostic[];
|
|
34
|
+
/** Runtime symbols the emitted code needs — `splitProps`, when a pattern had a rest. */
|
|
35
|
+
used: Set<string>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Work out the edits without applying them, so a caller that already has the source in a
|
|
39
|
+
* MagicString can fold them into its own. That's how the template transform picks this
|
|
40
|
+
* up: one string, one map, and holes get the rewrite because it slices them with the
|
|
41
|
+
* edits applied.
|
|
42
|
+
*/
|
|
43
|
+
export declare function collectPropsEdits(program: unknown, code: string, options?: PropsTransformOptions): PropsEditsResult;
|
|
44
|
+
/** Run the rewrite on its own. The template transform folds the edits in instead. */
|
|
45
|
+
export declare function transformProps(code: string, filename?: string, options?: PropsTransformOptions): PropsTransformResult;
|
|
46
|
+
//# sourceMappingURL=props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/transform/props.ts"],"names":[],"mappings":"AAaA,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAqC,KAAK,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAU1G,MAAM,WAAW,eAAe;IAC9B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAqB;IACpC,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;IAC5C,WAAW,EAAE,eAAe,EAAE,CAAC;IAC/B,mFAAmF;IACnF,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qFAAqF;AACrF,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,WAAW,EAAE,eAAe,EAAE,CAAC;IAC/B,wFAAwF;IACxF,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACnB;AA+ED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAA0B,GAClC,gBAAgB,CAuFlB;AAgBD,qFAAqF;AACrF,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,QAAQ,SAAe,EACvB,OAAO,GAAE,qBAA0B,GAClC,oBAAoB,CA0BtB"}
|