svelte-origin 1.0.0-next.48 → 1.0.0-next.49
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/LLM.md +545 -540
- package/README.md +678 -678
- package/dist/cli.js +46 -46
- package/dist/globals.d.ts +649 -649
- package/dist/index.d.ts +1 -1
- package/dist/index.js +66 -66
- package/dist/plugin.js +39 -39
- package/dist/post-process.js +46 -46
- package/dist/preprocess.js +42 -42
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/origin.d.ts +5 -7
- package/dist/runtime-inline.d.ts +4 -5
- package/dist/runtime-inline.min.js +1 -1
- package/dist/schema-resolver.d.ts +13 -0
- package/dist/transform/schema-codegen.d.ts +5 -0
- package/dist/vite-dts.js +7 -7
- package/package.json +1 -1
package/dist/post-process.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import*as N from"node:fs";import*as M from"node:path";import{fileURLToPath as
|
|
2
|
-
`,Z+2);if($===-1)return X>Z;if(X>Z&&X<=$)return!0;Z=$+1;continue}if(Y==="/"&&Q[Z+1]==="*"){let $=Q.indexOf("*/",Z+2);if($===-1)return X>Z;if(X>Z&&X<$+2)return!0;Z=$+2;continue}if(Y==='"'||Y==="'"||Y==="`"){let $=Y,_=Z;Z++;while(Z<Q.length){if(Q[Z]==="\\"){Z+=2;continue}if(Q[Z]===$){if(X>_&&X<=Z)return!0;Z++;break}if($==="`"&&Q[Z]==="$"&&Q[Z+1]==="{"){let J=Z;Z+=2;let
|
|
3
|
-
`,_+2);if(
|
|
1
|
+
import*as N from"node:fs";import*as M from"node:path";import{fileURLToPath as N0}from"node:url";import H0 from"magic-string";var EZ={hasMacros:/\$origin\s*[.(]/,origin:/\$origin\s*\(/g,originWithParents:/\$origin\s*\(\s*\[/,originPropsInOrigin:/\$origin\s*\.\s*props\s*\(\s*\{/g,standaloneOriginProps:/(?:let|const|export\s+const|export\s+let)\s+\w+\s*=\s*\$origin\s*\.\s*props\s*\(/g,bindableInAttrs:/\$bindable\s*\(/g,originComponent:/\$origin\s*\.\s*component\s*\(\s*(\w+)\s*\)/g,originCreate:/\$origin\s*\.\s*create\s*\(\s*(\w+)\s*(?:,\s*(\{[^}]*\}))?\s*\)/g,originBind:/\$origin\s*\.\s*bind\s*\(\s*([^)]+)\s*\)/g,originForOrigin:/\$origin\s*\.\s*for\s*\(\s*(\w+)\s*\)/g,originForElement:/\$origin\s*\.\s*for\s*\(\s*['"]([\w-]+)['"]\s*\)/g};function u(Q){return EZ.hasMacros.test(Q)}function v(Q,X){let Z=0;while(Z<X){let Y=Q[Z];if(Y==="/"&&Q[Z+1]==="/"){let $=Q.indexOf(`
|
|
2
|
+
`,Z+2);if($===-1)return X>Z;if(X>Z&&X<=$)return!0;Z=$+1;continue}if(Y==="/"&&Q[Z+1]==="*"){let $=Q.indexOf("*/",Z+2);if($===-1)return X>Z;if(X>Z&&X<$+2)return!0;Z=$+2;continue}if(Y==='"'||Y==="'"||Y==="`"){let $=Y,_=Z;Z++;while(Z<Q.length){if(Q[Z]==="\\"){Z+=2;continue}if(Q[Z]===$){if(X>_&&X<=Z)return!0;Z++;break}if($==="`"&&Q[Z]==="$"&&Q[Z+1]==="{"){let J=Z;Z+=2;let U=1;while(Z<Q.length&&U>0){if(Q[Z]==="{")U++;else if(Q[Z]==="}")U--;else if(Q[Z]==="\\")Z++;Z++}if(X>_&&X<J)return!0;continue}Z++}continue}Z++}return!1}function o(Q){if(!Q.startsWith("$bindable"))return{isBindable:!1};let X=9;if(Q[X]==="<"){let _=1;X++;while(X<Q.length&&_>0){let J=Q[X];if(J==="="&&Q[X+1]===">"){X+=2;continue}if(J==="<")_++;else if(J===">")_--;X++}}while(X<Q.length&&/\s/.test(Q[X]))X++;if(Q[X]!=="(")return{isBindable:!1};let Z=X,Y=O(Q,Z);if(Y===-1)return{isBindable:!1};return{isBindable:!0,innerValue:Q.slice(Z+1,Y).trim()||"undefined"}}function s(Q){let X=0,Z=0;for(let Y=0;Y<Q.length-4;Y++){let $=Q[Y];if($==='"'||$==="'"||$==="`"){let _=$;Y++;while(Y<Q.length&&Q[Y]!==_){if(Q[Y]==="\\")Y++;Y++}continue}if($==="{"||$==="("||$==="[")X++;else if($==="}"||$===")"||$==="]")X--;else if($==="<"){let _=Y>0?Q[Y-1]:"";if(/[\w$)]/.test(_))Z++}else if($===">"){if(Y>0&&Q[Y-1]==="=")continue;if(Z>0)Z--}else if(X===0&&Z===0&&Q.slice(Y,Y+4)===" as ")return Y}return-1}function O(Q,X,Z="(",Y=")"){let $=0;for(let _=X;_<Q.length;_++){let J=Q[_];if(J==="/"&&Q[_+1]==="/"){let U=Q.indexOf(`
|
|
3
|
+
`,_+2);if(U!==-1)_=U;else _=Q.length;continue}if(J==="/"&&Q[_+1]==="*"){let U=Q.indexOf("*/",_+2);if(U!==-1)_=U+1;else _=Q.length;continue}if(J==='"'||J==="'"||J==="`"){let U=J;_++;while(_<Q.length&&Q[_]!==U){if(Q[_]==="\\")_++;_++}continue}if(J===Z)$++;else if(J===Y){if($--,$===0)return _}}return-1}function a(Q){return`import { ${Q.join(", ")} } from 'svelte-origin/runtime'`}function l(Q,X){let Z=[],_=X.split(".").map((H)=>H.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("\\s*\\.\\s*"),J=new RegExp(_+"\\s*\\(","g"),U;while((U=J.exec(Q))!==null){let H=U.index,W=H+U[0].length-1;if(v(Q,H))continue;let q=MZ(Q,H);if(q)Z.push({...q,macroOpenParen:W})}return Z}function MZ(Q,X){let Z=X-1;while(Z>=0&&/\s/.test(Q[Z]))Z--;if(Q[Z]!=="=")return null;let Y=Z;Z--;while(Z>=0&&/\s/.test(Q[Z]))Z--;let $=null,_=-1,J=Z+1,U=0,H=-1,W=Z;while(W>=0){let j=Q[W];if(j==='"'||j==="'"||j==="`"){W--;while(W>=0&&Q[W]!==j){if(Q[W-1]==="\\")W--;W--}W--;continue}if(j===">"||j===")"||j==="]"||j==="}")U++;else if(j==="<"||j==="("||j==="["||j==="{")U--;else if(j===":"&&U===0){H=W;break}else if(U===0&&/[;\n{]/.test(j))break;W--}if(H!==-1){_=J,$=Q.slice(H+1,_).trim(),Z=H-1;while(Z>=0&&/\s/.test(Q[Z]))Z--}if(!/[\w$]/.test(Q[Z]))return null;let q=Z+1;while(Z>=0&&/[\w$]/.test(Q[Z]))Z--;let z=Z+1,K=Q.slice(z,q);if(!K)return null;while(Z>=0&&/\s/.test(Q[Z]))Z--;let w=-1;if(Q.slice(Z-4,Z+1)==="const")w=Z-4,Z-=5;else if(Q.slice(Z-2,Z+1)==="let")w=Z-2,Z-=3;else if(Q.slice(Z-2,Z+1)==="var")w=Z-2,Z-=3;else return null;let G=w;while(Z>=0&&/\s/.test(Q[Z]))Z--;let L=!1;if(Q.slice(Z-5,Z+1)==="export"){L=!0,G=Z-5,Z-=6;while(Z>=0&&/\s/.test(Q[Z]))Z--}let T=Y+1;return{varName:K,startIndex:G,valueStartIndex:T,hasExport:L,typeAnnotation:$}}function wQ(Q){return/\b(type|interface)\s+\$\$Props\b/.test(Q)}function TQ(Q){let X=0,Z=0,Y=Q.match(/^<script[^>]*>/);if(Y)Z=Y[0].length,X=Z;while(Z<Q.length){while(Z<Q.length&&/\s/.test(Q[Z]))Z++;if(Q.slice(Z,Z+6)==="import"){Z+=6;while(Z<Q.length&&/\s/.test(Q[Z]))Z++;if(Q.slice(Z,Z+4)==="type"&&/\s/.test(Q[Z+4])){Z+=4;while(Z<Q.length&&/\s/.test(Q[Z]))Z++}let _=!1;while(Z<Q.length){let J=Q[Z];if(J==="{"){let U=O(Q,Z,"{","}");if(U!==-1){Z=U+1;continue}}if(J==='"'||J==="'"||J==="`"){let U=J;Z++;while(Z<Q.length&&Q[Z]!==U){if(Q[Z]==="\\")Z++;Z++}Z++;while(Z<Q.length&&Q[Z]!==`
|
|
4
4
|
`&&Q[Z]!==";")Z++;if(Q[Z]===";")Z++;if(Q[Z]===`
|
|
5
|
-
`)Z++;X=Z,_=!0;break}if(Q.slice(Z,Z+4)==="from"&&/\s/.test(Q[Z+4])){Z+=4;while(Z<Q.length&&/\s/.test(Q[Z]))Z++;continue}Z++}if(!_)break;continue}if(Q[Z]==="<")break;if(/[a-zA-Z_$]/.test(Q[Z])){if(Q.slice(Z,Z+6)==="export"){let _=Q.slice(Z+6,Z+20);if(!/\s*(const|let|var|function|class|default|type|interface|\{)/.test(_))break}break}Z++}if(X>0)return X;let $=Q.match(/<script[^>]*>/);if($)return $.index+$[0].length;return 0}function
|
|
6
|
-
`);if(Y!==-1){X=X.slice(Y+1).trim();continue}X="";break}break}let Z=X.indexOf("*/");if(Z!==-1){let Y=X.slice(Z+2).trim();if(Y.match(/^(\w+)\s*:/))X=Y}return X}function
|
|
7
|
-
`,_+2);if(
|
|
8
|
-
`,Z+2);if(
|
|
9
|
-
`,Z+2);if(
|
|
10
|
-
`);if(Z.length<=1)return Q;let Y=1/0;for(let _=1;_<Z.length-1;_++){let J=Z[_];if(!J.trim())continue;let
|
|
11
|
-
`)}function
|
|
12
|
-
`||$[
|
|
13
|
-
__attrSchema: ${
|
|
14
|
-
__parents: ${
|
|
5
|
+
`)Z++;X=Z,_=!0;break}if(Q.slice(Z,Z+4)==="from"&&/\s/.test(Q[Z+4])){Z+=4;while(Z<Q.length&&/\s/.test(Q[Z]))Z++;continue}Z++}if(!_)break;continue}if(Q[Z]==="<")break;if(/[a-zA-Z_$]/.test(Q[Z])){if(Q.slice(Z,Z+6)==="export"){let _=Q.slice(Z+6,Z+20);if(!/\s*(const|let|var|function|class|default|type|interface|\{)/.test(_))break}break}Z++}if(X>0)return X;let $=Q.match(/<script[^>]*>/);if($)return $.index+$[0].length;return 0}function r(Q){let X=Q.trim();while(!0){if(X.startsWith("/*")){let Y=X.indexOf("*/");if(Y!==-1){X=X.slice(Y+2).trim();continue}break}if(X.startsWith("//")){let Y=X.indexOf(`
|
|
6
|
+
`);if(Y!==-1){X=X.slice(Y+1).trim();continue}X="";break}break}let Z=X.indexOf("*/");if(Z!==-1){let Y=X.slice(Z+2).trim();if(Y.match(/^(\w+)\s*:/))X=Y}return X}function SZ(Q){let X=0,Z=0;while(X<Q.length){let Y=Q[X];if(Y==='"'||Y==="'"||Y==="`"){let _=Y;X++;while(X<Q.length&&Q[X]!==_){if(Q[X]==="\\")X++;X++}X++;continue}if(Y==="/"&&Q[X+1]==="*"){Z++,X+=2;continue}if(Y==="*"&&Q[X+1]==="/")if(Z>0){Z--,X+=2;continue}else return kZ(Q,X);X++}return-1}function kZ(Q,X){let Z=X-1;while(Z>=0&&/\s/.test(Q[Z]))Z--;let Y=Q.slice(0,Z+1),$=0,_=0;while(_<Y.length){let J=Y[_];if(J==='"'||J==="'"||J==="`"){let K=J;_++;while(_<Y.length&&Y[_]!==K){if(Y[_]==="\\")_++;_++}if(_<Y.length)$=_+1,_++;continue}if(J==="{"||J==="("||J==="["){let K=J,w=J==="{"?"}":J==="("?")":"]",G=1;_++;while(_<Y.length&&G>0){let L=Y[_];if(L===K)G++;else if(L===w){if(G--,G===0)$=_+1}else if(L==='"'||L==="'"||L==="`"){let T=L;_++;while(_<Y.length&&Y[_]!==T){if(Y[_]==="\\")_++;_++}}_++}continue}let H=Y.slice(_),W=H.match(/^(true|false|null|undefined)\b/);if(W){_+=W[0].length;let K=Y.slice(_);if(/^\s+[\w$]/.test(K)){$=_;break}$=_;continue}let q=H.match(/^-?\d+(\.\d+)?/);if(q){_+=q[0].length;let K=Y.slice(_);if(/^\s+[\w$]/.test(K)){$=_;break}$=_;continue}let z=H.match(/^[\w$]+/);if(z){_+=z[0].length;let K=Y.slice(_);if(/^\s+[\w$]/.test(K)){$=_;break}$=_;continue}_++}return $>0?$:X}function t(Q){let X=Q.trim(),Z=SZ(X);if(Z!==-1)X=X.slice(0,Z).trim();let Y=0;while(Y<X.length){let $=X[Y];if($==='"'||$==="'"||$==="`"){let J=$;Y++;while(Y<X.length&&X[Y]!==J){if(X[Y]==="\\")Y++;Y++}Y++;continue}if($==="{"||$==="("||$==="["){let J=1;Y++;while(Y<X.length&&J>0){let U=X[Y];if(U==="{"||U==="("||U==="[")J++;else if(U==="}"||U===")"||U==="]")J--;else if(U==='"'||U==="'"||U==="`"){let H=U;Y++;while(Y<X.length&&X[Y]!==H){if(X[Y]==="\\")Y++;Y++}}Y++}continue}if($==="/"&&X[Y+1]==="*"){X=X.slice(0,Y).trim();break}if($==="/"&&X[Y+1]==="/"){X=X.slice(0,Y).trim();break}Y++}return X}function P(Q){let X=[],Z="",Y=0,$=0,_=0;while(_<Q.length){let J=Q[_];if(J==="/"&&Q[_+1]==="/"){let H=Q.indexOf(`
|
|
7
|
+
`,_+2);if(H!==-1)Z+=Q.slice(_,H+1),_=H+1;else Z+=Q.slice(_),_=Q.length;continue}if(J==="/"&&Q[_+1]==="*"){let H=Q.indexOf("*/",_+2);if(H!==-1)Z+=Q.slice(_,H+2),_=H+2;else Z+=Q.slice(_),_=Q.length;continue}if(J==='"'||J==="'"||J==="`"){let H=J;Z+=J,_++;while(_<Q.length&&Q[_]!==H){if(Q[_]==="\\")Z+=Q[_],_++;if(_<Q.length)Z+=Q[_],_++}if(_<Q.length)Z+=Q[_],_++;continue}if(J==="<"){let H=Z.length>0?Z[Z.length-1]:"";if(/[\w$)]/.test(H))$++;Z+=J,_++;continue}if(J===">"){if(_>0&&Q[_-1]==="="){Z+=J,_++;continue}if($>0)$--;Z+=J,_++;continue}if(J==="{"||J==="("||J==="[")Y++,Z+=J;else if(J==="}"||J===")"||J==="]")Y--,Z+=J;else if(J===","&&Y===0&&$===0)X.push(Z),Z="";else Z+=J;_++}if(Z.trim())X.push(Z);return X}function e(Q){return`{ ${jQ(Q).map(({key:Y,defaultValue:$,bindable:_,hasDefault:J})=>`${Y}: { default: ${$}, bindable: ${_}, hasDefault: ${J} }`).join(", ")} }`}function jQ(Q){let X=[],Z=P(Q);for(let Y of Z){let $=Y.trim();if(!$)continue;if($=r($),!$)continue;let _=$.indexOf(":");if(_===-1)continue;let J=$.slice(0,_).trim(),U=$.slice(_+1).trim();U=t(U);let H=s(U);if(H!==-1)U=U.slice(0,H).trim();let W=o(U);if(W.isBindable){let q=W.innerValue,z=q!==""&&q!=="undefined";X.push({key:J,defaultValue:q,bindable:!0,hasDefault:z})}else{let q=U!=="undefined";X.push({key:J,defaultValue:U,bindable:!1,hasDefault:q})}}return X}function vQ(Q){let X=[],Z=0;while(Z<Q.length){while(Z<Q.length&&/[\s,]/.test(Q[Z]))Z++;if(Z>=Q.length)break;if(Q.slice(Z,Z+2)==="/*"){let W=Q.indexOf("*/",Z+2);if(W!==-1){Z=W+2;continue}}if(Q.slice(Z,Z+2)==="//"){let W=Q.indexOf(`
|
|
8
|
+
`,Z+2);if(W!==-1){Z=W+1;continue}else break}let Y=!1,$=!1,_=!1,J=!1;if(Q.slice(Z).match(/^get\s+/))Y=!0,Z+=Q.slice(Z).match(/^get\s+/)[0].length;else if(Q.slice(Z).match(/^set\s+/))$=!0,Z+=Q.slice(Z).match(/^set\s+/)[0].length;else if(Q.slice(Z).match(/^async\s+\*/)){_=!0,J=!0,Z+=Q.slice(Z).match(/^async\s+\*/)[0].length;while(Z<Q.length&&/\s/.test(Q[Z]))Z++}else if(Q.slice(Z).match(/^async\s+/))_=!0,Z+=Q.slice(Z).match(/^async\s+/)[0].length;else if(Q[Z]==="*"){J=!0,Z++;while(Z<Q.length&&/\s/.test(Q[Z]))Z++}let U=!1,H="";if(Q[Z]==="["){U=!0;let W=Z,q=1;Z++;while(Z<Q.length&&q>0){if(Q[Z]==="[")q++;else if(Q[Z]==="]")q--;Z++}H=Q.slice(W,Z)}else{let W=Q.slice(Z).match(/^(\$?\w+)/);if(!W)break;H=W[1],Z+=H.length}while(Z<Q.length&&/\s/.test(Q[Z]))Z++;if(Q[Z]===":"){Z++;let W=Z,q=0,z=0;while(Z<Q.length){let w=Q[Z];if(w==="/"&&Q[Z+1]==="/"){let G=Q.indexOf(`
|
|
9
|
+
`,Z+2);if(G!==-1){Z=G+1;continue}else break}if(w==="/"&&Q[Z+1]==="*"){let G=Q.indexOf("*/",Z+2);if(G!==-1){Z=G+2;continue}else break}if(w==='"'||w==="'"||w==="`"){let G=w;Z++;while(Z<Q.length&&Q[Z]!==G){if(Q[Z]==="\\")Z++;Z++}Z++;continue}if((w===","||w==="}")&&q===0&&z===0)break;if(w==="{"||w==="("||w==="[")q++;if(w==="}"||w===")"||w==="]")q--;if(w==="<"&&Z>0&&/\w/.test(Q[Z-1]))z++;if(w===">"&&z>0)z--;Z++}let K=Q.slice(W,Z).trim();X.push({key:H,value:K,isGetter:Y,isSetter:$,isMethod:!1,isAsync:_,isGenerator:J,isComputed:U})}else if(Q[Z]==="("){let W=Z,q=1;Z++;while(Z<Q.length&&q>0){if(Q[Z]==="(")q++;if(Q[Z]===")")q--;Z++}while(Z<Q.length&&/\s/.test(Q[Z]))Z++;if(Q[Z]===":"){Z++;let z=0;while(Z<Q.length){let K=Q[Z];if(K==="<"||K==="("||K==="[")z++;if(K===">"||K===")"||K==="]")z--;if(K==="{"&&z===0)break;Z++}}if(Q[Z]==="{"){let z=Z;q=1,Z++;while(Z<Q.length&&q>0){if(Q[Z]==="{")q++;if(Q[Z]==="}")q--;Z++}let K=Z;if(Y){let w=Q.slice(z,K);X.push({key:H,value:w,isGetter:Y,isSetter:$,isMethod:!1,isAsync:_,isGenerator:J,isComputed:U})}else if($){let w=Q.slice(W,K);X.push({key:H,value:w,isGetter:Y,isSetter:$,isMethod:!1,isAsync:_,isGenerator:J,isComputed:U})}else{let w=Q.slice(W,K);X.push({key:H,value:w,isGetter:!1,isSetter:!1,isMethod:!0,isAsync:_,isGenerator:J,isComputed:U})}}else{let z=Q.slice(W,Z);X.push({key:H,value:z,isGetter:Y,isSetter:$,isMethod:!Y&&!$,isAsync:_,isGenerator:J,isComputed:U})}}else if(Q[Z]==="{"){let W=Z,q=1;Z++;while(Z<Q.length&&q>0){if(Q[Z]==="{")q++;if(Q[Z]==="}")q--;Z++}let z=Q.slice(W,Z);X.push({key:H,value:z,isGetter:Y,isSetter:$,isMethod:!1,isAsync:_,isGenerator:J,isComputed:U})}else break}return X}function LQ(Q){let X=Q.trim();if(!X.endsWith(")"))return!1;let Z=0;for(let Y=X.length-1;Y>=0;Y--)if(X[Y]===")")Z++;else if(X[Y]==="("){if(Z--,Z===0)return!0}return!1}function QQ(Q){let X=Q.trim(),Z=0;for(let Y=X.length-1;Y>=0;Y--)if(X[Y]===")")Z++;else if(X[Y]==="("){if(Z--,Z===0)return X.slice(0,Y)}return X}function ZQ(Q){let X=Q.trim(),Z=0;for(let Y=0;Y<X.length;Y++){let $=X[Y];if($==="(")Z++;else if($===")")Z--;else if($==="<"&&Z===0)return!0}return!1}function NQ(Q){let X=Q.trim(),Z=X.indexOf("<");if(Z!==-1)return X.slice(0,Z);let Y=X.indexOf("(");return Y===-1?X:X.slice(0,Y)}function b(Q){let X=Q.trim();if(ZQ(X)&&!LQ(X))return`${X}()`;return X}function OQ(Q){let X=/\$origin\s*\.\s*create\s*\(/g,Z=[],Y;while((Y=X.exec(Q))!==null){let $=Y.index;if(v(Q,$))continue;let _=$+Y[0].length-1,J=O(Q,_);if(J===-1)continue;let U=Q.slice(_+1,J).trim(),H=U,W=null,q=0;for(let z=0;z<U.length;z++){let K=U[z];if(K==="("||K==="{"||K==="["||K==="<")q++;else if(K===")"||K==="}"||K==="]"||K===">")q--;else if(K===","&&q===0){H=U.slice(0,z).trim(),W=U.slice(z+1).trim();break}}Z.push({callStart:$,callEnd:J+1,factoryExpr:b(H),propsExpr:W})}return Z}function IZ(Q){let X=/\$origin\s*\.\s*bind\s*\(/g,Z=!1,Y=Q,$;while(($=X.exec(Q))!==null){let _=$.index;if(v(Q,_))continue;let J=_+$[0].length-1,U=O(Q,J);if(U===-1)continue;let H=Q.slice(J+1,U).trim(),W=Q.slice(_,U+1),q=`__bindable(() => ${H}, (v) => { ${H} = v })`;Y=Y.replace(W,q),Z=!0}return{code:Y,hasBindable:Z}}function FQ(Q,X){if(X){let{code:Z,hasBindable:Y}=IZ(X);return{replacement:`__createOriginInstance(${Q}, ${Z})`,needsHelper:!0,needsBindable:Y}}return{replacement:`${Q}({})`,needsHelper:!1,needsBindable:!1}}function BQ(Q){let X=OQ(Q);if(X.length===0)return{result:Q,needsHelper:!1,needsBindable:!1};let Z=Q,Y=0,$=!1,_=!1;for(let J of X){let{replacement:U,needsHelper:H,needsBindable:W}=FQ(J.factoryExpr,J.propsExpr);if(H)$=!0;if(W)_=!0;let q=J.callStart+Y,z=J.callEnd+Y;Z=Z.slice(0,q)+U+Z.slice(z),Y+=U.length-(J.callEnd-J.callStart)}return{result:Z,needsHelper:$,needsBindable:_}}function CQ(Q,X){let Z={derivedNames:new Set,stateNames:new Set,valueNames:new Set,methodNames:new Set,getterNames:new Set,superDelegatingGetters:new Set,superDelegatingMethods:new Set};for(let Y of Q){let{key:$,value:_,isGetter:J,isMethod:U,isSetter:H}=Y;if(!J&&!U&&!H&&_.startsWith("$state"))Z.stateNames.add($);else if(!J&&!U&&!H)Z.valueNames.add($);if(U)Z.methodNames.add($);if(J)Z.getterNames.add($);if(J&&X){let W=_.trim();if(new RegExp(`^\\{\\s*return\\s+this\\.super\\.${$}\\s*\\}$`).test(W))Z.superDelegatingGetters.add($)}if(U&&X){let W=_.trim();if(new RegExp(`^\\([^)]*\\)\\s*\\{\\s*return\\s+this\\.super\\.${$}\\([^)]*\\)\\s*\\}$`).test(W))Z.superDelegatingMethods.add($)}if(J&&/return\s+\$derived(\.by)?\s*\(/.test(_))Z.derivedNames.add($)}return Z}function XQ(Q,X){let{propName:Z,hasParents:Y,metadata:$}=X,{derivedNames:_,stateNames:J,valueNames:U,methodNames:H,getterNames:W,superDelegatingGetters:q,superDelegatingMethods:z}=$,K=Q;K=K.replace(/this\.super\./g,"__super."),K=K.replace(/this\.super\b/g,"__super");let w=new RegExp(`this\\.${Z}\\.`,"g");K=K.replace(w,"__props.");let G=new RegExp(`this\\.${Z}\\b`,"g");return K=K.replace(G,"__props"),K=K.replace(/this\.(\w+)/g,(L,T)=>{if(T==="super")return L;if(_.has(T))return`__${T}`;if(J.has(T))return T;if(U.has(T))return T;if(q.has(T)||z.has(T))return`__super.${T}`;if(H.has(T)||W.has(T))return Y?`__super.${T}`:`__self.${T}`;return Y?`__super.${T}`:`__self.${T}`}),K}function YQ(Q,X){let{propName:Z,metadata:Y}=X,{derivedNames:$,stateNames:_,valueNames:J}=Y,U=Q,H=/\$derived(\.by)?\s*\(/g,W=[],q;while((q=H.exec(Q))!==null){let w=q.index+q[0].length-1,G=O(Q,w);if(G!==-1){let L=Q.slice(w+1,G),T=XQ(L,X);W.push({start:w+1,end:G,replacement:T})}}for(let w of W.reverse())U=U.slice(0,w.start)+w.replacement+U.slice(w.end);U=U.replace(/this\.super\./g,"__super."),U=U.replace(/this\.super\b/g,"__super");let z=new RegExp(`this\\.${Z}\\.`,"g");U=U.replace(z,`__self.${Z}.`);let K=new RegExp(`this\\.${Z}\\b`,"g");return U=U.replace(K,`__self.${Z}`),U=U.replace(/this\.(\w+)/g,(w,G)=>{if(G==="super")return w;if($.has(G))return`__${G}`;if(_.has(G))return G;if(J.has(G))return G;return`__self.${G}`}),U=U.replace(/\bthis\b(?!\.)/g,"__self"),U}function yQ(Q){if(Q.length===0)return"\t\tconst __props = __inputAttrs";let X=[];for(let Z of Q){let Y=Z.hasDefault?` ?? ${Z.defaultValue}`:"";X.push(`get ${Z.key}() { return __inputAttrs.${Z.key}${Y} }`),X.push(`set ${Z.key}(v) { const __d = Object.getOwnPropertyDescriptor(__inputAttrs, '${Z.key}'); if (__d?.set) __inputAttrs.${Z.key} = v }`)}return` const __props = { ${X.join(", ")} }`}function PQ(Q,X){let Z=X.match(/^\$state(?:\.(\w+))?(?:<([^>]+(?:<[^>]+>)*)>)?\s*\(/);if(!Z)return null;let Y=Z[1],$=Z[2],_=X.indexOf("("),J=O(X,_);if(J===-1)return null;let U=X.slice(_+1,J).trim(),H=Y?`.${Y}`:"",W=$?`<${$}>`:"";return{declaration:` let ${Q} = $state${H}${W}(${U})`,getter:`get ${Q}() { return ${Q} }`,setter:`set ${Q}(v) { ${Q} = v }`}}function bQ(Q,X,Z){let Y=X.match(/return\s+\$derived(\.by)?\s*\(/);if(!Y)return null;let $=Y[1]?"$derived.by":"$derived",J=X.indexOf($+"(")+$.length,U=O(X,J);if(U===-1)return null;let H=X.slice(J+1,U).trim(),W=XQ(H,Z);return{declaration:` let __${Q} = ${$}(${W})`,getter:`get ${Q}() { return __${Q} }`}}function $Q(Q,X){let Z=Q.split(`
|
|
10
|
+
`);if(Z.length<=1)return Q;let Y=1/0;for(let _=1;_<Z.length-1;_++){let J=Z[_];if(!J.trim())continue;let H=J.search(/\S/);if(H>=0&&H<Y)Y=H}if(Y===1/0)Y=0;let $=[];for(let _=0;_<Z.length;_++){let J=Z[_],U=J.trim();if(_===0){$.push(U);continue}if(_===Z.length-1){$.push(X+U);continue}if(!U){$.push("");continue}let H=J.search(/\S/),W=Math.max(0,H-Y);$.push(X+"\t"+"\t".repeat(W)+U)}return $.join(`
|
|
11
|
+
`)}function gQ(Q,X,Z,Y){let $=/\$origin\s*\(/g,_,J=!1;while((_=$.exec(X))!==null){let U=_.index;if(v(X,U))continue;let H=U+_[0].length-1,W=O(X,H);if(W===-1){console.warn(`[svelte-origin] Could not find matching ) for $origin( at index ${U}`);continue}let q=X.slice(H+1,W),z=vZ(q,Y,Z);Q.overwrite(U,W+1,`__createOrigin(${z})`),Z.add("__createOrigin"),J=!0}return J}function vZ(Q,X,Z){let Y=[],$=Q.trim(),_=null;if($.startsWith("[")){let j=O($,0,"[","]");if(j!==-1){Y=$.slice(1,j).split(",").map((F)=>F.trim()).filter((F)=>F);let B=j+1;while(B<$.length&&/[\s,]/.test($[B]))B++;$=$.slice(B)}}if($.startsWith("{")){let j=O($,0,"{","}");if(j!==-1){let A=$.slice(j+1).trim();if(A.startsWith(",")){if(A=A.slice(1).trim(),A)_=A}$=$.slice(1,j)}}let J=$.match(/(\w+)\s*:\s*\$origin\s*\.\s*props\s*\(/),U="{}",H="",W=$,q="props",z=null;if(J){q=J[1];let j=J.index,A=j+J[0].length-1,B=O($,A);if(B!==-1){let F=$.slice(A+1,B).trim();if(F.startsWith("[")){let S=O(F,0,"[","]");if(S!==-1){let D=S+1;while(D<F.length&&/[\s,]/.test(F[D]))D++;F=F.slice(D)}}if(F.startsWith("{")){let S=O(F,0,"{","}");if(S!==-1)H=F.slice(1,S)}U=e(H);let V=B+1;while(V<$.length&&($[V]===","||$[V]===" "||$[V]===`
|
|
12
|
+
`||$[V]==="\t"))V++;W=$.slice(0,j)+$.slice(V)}}else{let j=$.match(/(\w+)\s*:\s*(\w+)\s*,/);if(j){let A=j[1],B=j[2];if((A==="props"||A==="attrs")&&/^[A-Z]/.test(B)&&!["$state","$derived","$effect","$bindable"].includes(B)){q=A,z=B;let F=j.index,V=F+j[0].length;W=$.slice(0,F)+$.slice(V)}}}let K=jQ(H),{body:w,attachments:G}=NZ(W.trim(),Y,K,q,X,Z),L=Y.length>0?`[${Y.join(", ")}]`:"undefined",T=`{
|
|
13
|
+
__attrSchema: ${U},
|
|
14
|
+
__parents: ${L},`;if(z)T+=`
|
|
15
15
|
__propsRef: ${z},`;if(T+=`
|
|
16
16
|
__create: (__inputAttrs${Y.length>0?", __super":""}) => {
|
|
17
|
-
${
|
|
18
|
-
}`,
|
|
19
|
-
__attachments: { ${
|
|
17
|
+
${w}
|
|
18
|
+
}`,G.length>0)T+=`,
|
|
19
|
+
__attachments: { ${G.join(", ")} }`;if(_){let{result:j,needsHelper:A,needsBindable:B}=BQ(_);if(A&&Z)Z.add("__createOriginInstance");if(B&&Z)Z.add("__bindable");T+=`,
|
|
20
20
|
__onInit: ${j}`}return T+=`
|
|
21
|
-
}`,T}function
|
|
22
|
-
return { ${
|
|
23
|
-
`))h
|
|
24
|
-
`))
|
|
25
|
-
`))
|
|
21
|
+
}`,T}function NZ(Q,X=[],Z=[],Y="props",$,_){let{result:J,needsHelper:U,needsBindable:H}=BQ(Q);if(U&&_)_.add("__createOriginInstance");if(H&&_)_.add("__bindable");let W=J.trim(),q=X.length>0,z=yQ(Z);if(!W){let B=[`get ${Y}() { return __props }`];if(q)B.push("get super() { return __super }");return{body:`${z}
|
|
22
|
+
return { ${B.join(", ")} }`,attachments:[]}}let K=vQ(W),w=CQ(K,q),G={hasParents:q,propName:Y,metadata:w},L=[],T=[`get ${Y}() { return __props }`],j=[];if(q)T.push("get super() { return __super }");for(let B of K){let{key:F,value:V,isGetter:S,isMethod:D,isSetter:f,isAsync:n,isGenerator:GQ,isComputed:c}=B;if(F===Y)continue;if(D&&F.startsWith("$")){let R=F.slice(1),h=n?"async ":"";j.push(`${R}: ${h}function${V}`);continue}if(!S&&!D&&!f&&V.startsWith("$state")){let R=PQ(F,V);if(R){L.push(R.declaration),T.push(R.getter),T.push(R.setter);continue}}let AZ=n?"async ":"",RZ=GQ?"*":"",DZ=c?F:F;if(S){let R=bQ(F,V,G);if(R){L.push(R.declaration),T.push(R.getter);continue}let h=YQ(V,G);if(h.includes(`
|
|
23
|
+
`))h=$Q(h,"\t\t\t");T.push(`get ${F}() ${h}`)}else if(f){let R=YQ(V,G);if(R.includes(`
|
|
24
|
+
`))R=$Q(R,"\t\t\t");T.push(`set ${F}${R}`)}else if(D){let R=YQ(V,G);if(R.includes(`
|
|
25
|
+
`))R=$Q(R,"\t\t\t");T.push(`${AZ}${RZ}${DZ}${R}`)}else{let R=XQ(V,G);L.push(` let ${F} = ${R}`),T.push(`get ${F}() { return ${F} }`),T.push(`set ${F}(v) { ${F} = v }`)}}let A=L.length>0?L.join(`
|
|
26
26
|
`)+`
|
|
27
27
|
`:"";return{body:`${z}
|
|
28
|
-
${
|
|
28
|
+
${A} const __self = {
|
|
29
29
|
${T.join(`,
|
|
30
30
|
`)}
|
|
31
31
|
}
|
|
32
|
-
return __self`,attachments:j}}function
|
|
32
|
+
return __self`,attachments:j}}function fQ(Q,X,Z){return CZ(Q,X,Z)}function CZ(Q,X,Z){let _="$origin.props".replace(/\./g,"\\s*\\.\\s*").replace(/\$/g,"\\$"),J=new RegExp(_+"\\s*\\(","g"),U,H=!1;while((U=J.exec(X))!==null){let W=U.index;if(v(X,W))continue;let q=X.slice(Math.max(0,W-20),W);if(/:\s*$/.test(q))continue;let z=W+U[0].length-1,K=O(X,z);if(K===-1){console.warn(`[svelte-origin] Could not find matching ) for $origin.props( at index ${W}`);continue}let w=X.slice(z+1,K).trim(),G=yZ(w);Q.overwrite(W,K+1,`__createAttrs(${G})`),Z.add("__createAttrs"),H=!0}return H}function yZ(Q){let X=[],Z=Q.trim();if(Z.startsWith("[")){let J=O(Z,0,"[","]");if(J!==-1){X=Z.slice(1,J).split(",").map((W)=>W.trim()).filter((W)=>W);let H=J+1;while(H<Z.length&&/[\s,]/.test(Z[H]))H++;Z=Z.slice(H)}}let Y="";if(Z.startsWith("{")){let J=O(Z,0,"{","}");if(J!==-1)Y=Z.slice(1,J)}let $=e(Y),_=X.length>0?`[${X.join(", ")}]`:"undefined";return`{
|
|
33
33
|
__attrSchema: ${$},
|
|
34
34
|
__parents: ${_}
|
|
35
|
-
}`}function
|
|
36
|
-
`)),$=!0}return $}function
|
|
35
|
+
}`}function PZ(Q){let X=l(Q,"$origin.create"),Z=[];for(let Y of X){let{varName:$,startIndex:_,macroOpenParen:J}=Y,U=O(Q,J);if(U===-1){console.warn(`[svelte-origin] Could not find matching ) for $origin.create( at index ${J}`);continue}let H=Q.slice(J+1,U).trim(),W=H,q=null,z=0,K=-1;for(let w=0;w<H.length;w++){let G=H[w];if(G==="("||G==="{"||G==="["||G==="<")z++;else if(G===")"||G==="}"||G==="]"||G===">")z--;else if(G===","&&z===0){K=w;break}}if(K!==-1)W=H.slice(0,K).trim(),q=H.slice(K+1).trim();Z.push({varName:$,factoryExpr:W,propsExpr:q,startIndex:_,endIndex:U+1})}return Z}function bZ(Q){let X=/\$origin\s*\.\s*bind\s*\(\s*([^)]+)\s*\)/g,Z=!1;return{code:Q.replace(X,($,_)=>{return Z=!0,`__BIND__${_.trim()}__BIND__`}),hasBind:Z}}function gZ(Q,X,Z){let Y=b(X),$=[];if(!Z)return $.push(`let ${Q} = ${Y}({})`),$;let{code:_,hasBind:J}=bZ(Z),U=Z.match(/^\{([\s\S]*)\}$/);if(!U)return $.push(`let __${Q}_props = $state(${Z})`),$.push(`let ${Q} = ${Y}(__${Q}_props)`),$;let H=U[1],W=fZ(J?_.slice(1,-1):H);if(W.length===0)return $.push(`let ${Q} = ${Y}({})`),$;let q=[],z=[];for(let{key:K,value:w}of W){let G=J?w.match(/^__BIND__(.+)__BIND__$/):null;if(G){let L=G[1];q.push(` get ${K}() { return ${L} },`),q.push(` set ${K}(v) { ${L} = v },`)}else q.push(` get ${K}() { return ${w} },`)}return $.push(...z),$.push(`let __${Q}_attrs = {`),$.push(...q),$.push("}"),$.push(`let ${Q} = ${Y}(__${Q}_attrs)`),$}function fZ(Q){let X=[],Z=0;while(Z<Q.length){while(Z<Q.length&&/\s/.test(Q[Z]))Z++;if(Z>=Q.length)break;let Y="",$="";if(Q[Z]==='"'||Q[Z]==="'"){let _=Q[Z];Z++;let J=Z;while(Z<Q.length&&Q[Z]!==_){if(Q[Z]==="\\")Z++;Z++}Y=Q.slice(J,Z),Z++}else if(/[\w$]/.test(Q[Z])){let _=Z;while(Z<Q.length&&/[\w$]/.test(Q[Z]))Z++;Y=Q.slice(_,Z)}else{Z++;continue}while(Z<Q.length&&/\s/.test(Q[Z]))Z++;if(Q[Z]===":"){Z++;while(Z<Q.length&&/\s/.test(Q[Z]))Z++;let _=Z,J=0;while(Z<Q.length){let U=Q[Z];if(U==='"'||U==="'"){let H=U;Z++;while(Z<Q.length&&Q[Z]!==H){if(Q[Z]==="\\")Z++;Z++}Z++;continue}if(U==="`"){Z++;while(Z<Q.length&&Q[Z]!=="`"){if(Q[Z]==="\\")Z++;else if(Q[Z]==="$"&&Q[Z+1]==="{"){Z+=2;let H=1;while(Z<Q.length&&H>0){if(Q[Z]==="{")H++;else if(Q[Z]==="}")H--;else if(Q[Z]==='"'||Q[Z]==="'"){let W=Q[Z];Z++;while(Z<Q.length&&Q[Z]!==W){if(Q[Z]==="\\")Z++;Z++}}Z++}continue}Z++}Z++;continue}if(U==="("||U==="{"||U==="[")J++;else if(U===")"||U==="}"||U==="]"){if(J--,J<0)break}else if(U===","&&J===0)break;Z++}$=Q.slice(_,Z).trim()}else $=Y;if(Y&&$)X.push({key:Y,value:$});if(Q[Z]===",")Z++}return X}function xQ(Q,X,Z){let Y=PZ(X);if(Y.length===0)return!1;let $=!1;for(let{varName:_,factoryExpr:J,propsExpr:U,startIndex:H,endIndex:W}of Y){let q=gZ(_,J,U);Q.overwrite(H,W,q.join(`
|
|
36
|
+
`)),$=!0}return $}function hQ(Q,X,Z){let Y=OQ(X),$=!1;for(let _ of Y){let J=X.slice(Math.max(0,_.callStart-100),_.callStart);if(/(?:let|const|var)\s+\w+\s*=\s*$/.test(J))continue;let{replacement:U,needsHelper:H,needsBindable:W}=FQ(_.factoryExpr,_.propsExpr);if(H)Z.add("__createOriginInstance");if(W)Z.add("__bindable");Q.overwrite(_.callStart,_.callEnd,U),$=!0}return $}function VQ(Q,X){let Z=lZ(Q,X);if(Z)return Z;let Y=dZ(Q,X);if(Y)return Y;return null}function _Q(Q,X){let Z=xZ(Q,X);if(Z)return Z;let Y=hZ(Q,X);if(Y)return Y;return null}function C(Q,X){let Z=[new RegExp(`import\\s*\\{[^}]*\\b${X}\\b[^}]*\\}\\s*from\\s*['"]([^'"]+)['"]`),new RegExp(`import\\s+type\\s*\\{[^}]*\\b${X}\\b[^}]*\\}\\s*from\\s*['"]([^'"]+)['"]`),new RegExp(`import\\s*\\{[^}]*\\bas\\s+${X}\\b[^}]*\\}\\s*from\\s*['"]([^'"]+)['"]`),new RegExp(`import\\s+type\\s*\\{[^}]*\\bas\\s+${X}\\b[^}]*\\}\\s*from\\s*['"]([^'"]+)['"]`),new RegExp(`import\\s+${X}\\s+from\\s*['"]([^'"]+)['"]`),new RegExp(`import\\s*\\*\\s*as\\s+${X}\\s+from\\s*['"]([^'"]+)['"]`),new RegExp(`export\\s*\\{[^}]*\\b${X}\\b[^}]*\\}\\s*from\\s*['"]([^'"]+)['"]`),new RegExp(`export\\s*\\{[^}]*\\bas\\s+${X}\\b[^}]*\\}\\s*from\\s*['"]([^'"]+)['"]`)];for(let Y of Z){let $=Y.exec(Q);if($)return $[1]}return null}function xZ(Q,X){let Y=new RegExp(`export\\s+(?:const|var|let)\\s+${X}\\s*=\\s*\\$origin\\s*\\.\\s*props\\s*\\(`,"s").exec(Q);if(!Y)return null;let $=Y.index+Y[0].length-1,_=O(Q,$);if(_===-1)return null;let J=Q.slice($+1,_).trim(),U=[];if(J.startsWith("[")){let z=O(J,0,"[","]");if(z!==-1){U=J.slice(1,z).split(",").map((G)=>G.trim()).map((G)=>{let L=G.match(/^(\w+)\s*\(/);if(L)return L[1];return G}).filter((G)=>G&&/^\w+$/.test(G));let w=z+1;while(w<J.length&&/[\s,]/.test(J[w]))w++;J=J.slice(w)}}if(!J.startsWith("{"))return{attrs:[],parentNames:U};let H=O(J,0,"{","}");if(H===-1)return{attrs:[],parentNames:U};let W=J.slice(1,H);return{attrs:pQ(W),parentNames:U}}function hZ(Q,X){let Y=new RegExp(`export\\s+(?:const|var|let)\\s+${X}\\s*=\\s*__createAttrs\\s*\\(\\s*\\{`,"s").exec(Q);if(!Y)return null;let $=Y.index+Y[0].length-1,_=O(Q,$,"{","}");if(_===-1)return null;let J=Q.slice($+1,_),U=J.match(/__attrSchema\s*:\s*\{/);if(!U)return{attrs:[],parentNames:[]};let H=U.index+U[0].length-1,W=O(J,H,"{","}");if(W===-1)return{attrs:[],parentNames:[]};let q=J.slice(H+1,W),z=uQ(q),K=J.match(/__parents\s*:\s*\[([^\]]*)\]/),w=[];if(K&&K[1].trim())w=K[1].split(",").map((G)=>G.trim()).filter((G)=>G&&/^\w+$/.test(G));return{attrs:z,parentNames:w}}function lZ(Q,X){let Z=uZ(Q,X);if(Z)return Z;let Y=pZ(Q,X);if(Y)return Y;let $=mZ(Q,X);if($)return $;return null}function uZ(Q,X){let Y=new RegExp(`export\\s+(?:const|var|let)\\s+${X}\\s*=\\s*\\$origin\\s*\\(`,"s").exec(Q);if(!Y)return null;let $=Y.index+Y[0].length-1,_=O(Q,$);if(_===-1)return null;let J=Q.slice($+1,_);return AQ(J)}function pZ(Q,X){let Y=new RegExp(`export\\s+function\\s+${X}\\s*(?:<[^>]*>)?\\s*\\([^)]*\\)\\s*(?::\\s*[^{]+)?\\s*\\{`,"s").exec(Q);if(!Y)return null;let $=Y.index+Y[0].length-1,_=O(Q,$,"{","}");if(_===-1)return null;let J=Q.slice($+1,_);return lQ(J)}function mZ(Q,X){let Y=new RegExp(`export\\s+(?:const|var|let)\\s+${X}\\s*=\\s*(?:<[^>]*>)?\\s*\\([^)]*\\)\\s*(?::\\s*[^=]+)?\\s*=>\\s*`,"s").exec(Q);if(!Y)return null;let $=Q.slice(Y.index+Y[0].length).trim();if($.startsWith("$origin(")){let _=Y.index+Y[0].length+$.indexOf("$origin(")+8,J=O(Q,_-1);if(J===-1)return null;let U=Q.slice(_,J);return AQ(U)}if($.startsWith("{")){let _=Y.index+Y[0].length,J=O(Q,_,"{","}");if(J===-1)return null;let U=Q.slice(_+1,J);return lQ(U)}return null}function lQ(Q){let X=Q.match(/(?:return\s+)?\$origin\s*\(/);if(!X)return null;let Z=X.index+X[0].length-1,Y=O(Q,Z);if(Y===-1)return null;let $=Q.slice(Z+1,Y);return AQ($)}function AQ(Q){let X=[],Z=Q.trim();if(Z.startsWith("[")){let W=O(Z,0,"[","]");if(W!==-1){X=Z.slice(1,W).split(",").map((K)=>K.trim()).map((K)=>{let w=K.match(/^(\w+)\s*\(/);if(w)return w[1];return K}).filter((K)=>K&&/^\w+$/.test(K));let z=W+1;while(z<Z.length&&/[\s,]/.test(Z[z]))z++;Z=Z.slice(z)}}let Y=Z.match(/(\w+)\s*:\s*\$origin\s*\.\s*props\s*\(\s*\{/);if(!Y){let W=Z.match(/(?:props|attrs)\s*:\s*([A-Z]\w*)\b/);if(W){let q=W[1];if(!["Object","Array","String","Number","Boolean"].includes(q))return{attrs:[],parentNames:X,propsRef:q}}return{attrs:[],parentNames:X}}let $=Y.index,_=Z.indexOf("{",$+Y[0].length-1),J=O(Z,_,"{","}");if(J===-1)return{attrs:[],parentNames:X};let U=Z.slice(_+1,J);return{attrs:pQ(U),parentNames:X}}function dZ(Q,X){let Y=new RegExp(`export\\s+(?:const|var|let)\\s+${X}\\s*=\\s*__createOrigin\\s*\\(\\s*\\{`,"s").exec(Q);if(!Y)return null;let $=Y.index+Y[0].length-1,_=O(Q,$,"{","}");if(_===-1)return null;let J=Q.slice($+1,_),U=J.match(/__attrSchema\s*:\s*\{/);if(!U)return{attrs:[],parentNames:[]};let H=U.index+U[0].length-1,W=O(J,H,"{","}");if(W===-1)return{attrs:[],parentNames:[]};let q=J.slice(H+1,W),z=uQ(q),K=J.match(/__parents\s*:\s*\[([^\]]*)\]/),w=[];if(K&&K[1].trim())w=K[1].split(",").map((T)=>T.trim()).filter((T)=>T&&/^\w+$/.test(T));let G=J.match(/__propsRef\s*:\s*(\w+)/),L=G?G[1]:void 0;return{attrs:z,parentNames:w,propsRef:L}}function uQ(Q){let X=[],Z=0;while(Z<Q.length){while(Z<Q.length&&/[\s,]/.test(Q[Z]))Z++;if(Z>=Q.length)break;if(Q.slice(Z,Z+2)==="/*"){let G=Q.indexOf("*/",Z+2);if(G!==-1){Z=G+2;continue}}let Y=Q.slice(Z).match(/^(\w+)\s*:/);if(!Y)break;let $=Y[1];Z+=Y[0].length;while(Z<Q.length&&/\s/.test(Q[Z]))Z++;if(Q[Z]!=="{")break;let _=Z,J=O(Q,_,"{","}");if(J===-1)break;let U=Q.slice(_+1,J),H="undefined",W=!1,q=!1,z=U.match(/\bdefault\s*:\s*/);if(z){let G=z.index+z[0].length,L=0,T=G;while(T<U.length){let j=U[T];if(j==="{"||j==="("||j==="[")L++;else if(j==="}"||j===")"||j==="]")L--;else if(j===","&&L===0)break;T++}H=U.slice(G,T).trim()}let K=U.match(/\bbindable\s*:\s*(true|false)/);if(K)W=K[1]==="true";let w=U.match(/\bhasDefault\s*:\s*(true|false)/);if(w)q=w[1]==="true";X.push({key:$,defaultValue:H,bindable:W,hasDefault:q}),Z=J+1}return X}function pQ(Q){let X=[],Z=P(Q);for(let Y of Z){let $=Y.trim();if(!$)continue;if($=r($),!$)continue;let _=$.indexOf(":");if(_===-1)continue;let J=$.slice(0,_).trim(),U=$.slice(_+1).trim();U=t(U);let H=s(U);if(H!==-1)U=U.slice(0,H).trim();let W=o(U);if(W.isBindable){let q=W.innerValue,z=q!==""&&q!=="undefined";X.push({key:J,defaultValue:q,bindable:!0,hasDefault:z})}else{let q=U!=="undefined";X.push({key:J,defaultValue:U,bindable:!1,hasDefault:q})}}return X}function JQ(Q){return`___${Q}`}function g(Q,X){let Z=JQ(Q);return`${Q}: ${Z} = ${X}`}function UQ(Q){let X=JQ(Q);return`${Q}: ${X}`}function HQ(Q){let X=JQ(Q);return`get ${Q}() { return ${X} }`}function WQ(Q){let X=JQ(Q);return`set ${Q}(v) { ${X} = v }`}function iZ(Q){if(LQ(Q))return`ReturnType<typeof ${QQ(Q)}>`;return`typeof ${Q}`}function p(Q,X,Z={}){let{useNewApi:Y=!0,useUserPropsType:$=!1}=Z,_=[];for(let H of Q)if(H.bindable)if(H.hasDefault)_.push(g(H.key,`$bindable(${H.defaultValue})`));else _.push(g(H.key,"$bindable()"));else if(H.hasDefault)_.push(g(H.key,H.defaultValue));else _.push(UQ(H.key));if($)return`let { ${_.join(", ")} }: $$Props = $props()`;let J=iZ(X),U=Y?"$origin.Props":"$origin.Props";return`let { ${_.join(", ")} }: ${U}<${J}> = $props()`}function RQ(Q,X){let Z=[];for(let Y of X)if(Z.push(HQ(Y.key)),Y.bindable)Z.push(WQ(Y.key));return`${Q}({ ${Z.join(", ")} })`}function zQ(Q){let X=[],Z=[];for(let $ of Q.attrs){let _=DQ($.defaultValue),J=$.hasDefault?"?":"";if(X.push(`${$.key}${J}: ${_}`),$.bindable)Z.push($.key)}return{interfaceContent:X.length>0?`{ ${X.join("; ")} }`:"{}",bindings:Z}}function DQ(Q){if(Q==="undefined")return"unknown";if(Q==="true"||Q==="false")return"boolean";if(/^-?\d+$/.test(Q))return"number";if(/^-?\d+\.\d+$/.test(Q))return"number";if(/^['"]/.test(Q))return"string";if(Q.startsWith("["))return"unknown[]";if(Q.startsWith("{"))return"Record<string, unknown>";if(Q==="null")return"null";return"unknown"}function nZ(Q,X,Z,Y="regenerated on save"){let $=[],_=[];for(let H of Z.attrs){let W=DQ(H.defaultValue),q=H.hasDefault?"?":"";if($.push(` ${H.key}${q}: ${W};`),H.bindable)_.push(`"${H.key}"`)}let J=$.length>0?`{
|
|
37
37
|
${$.join(`
|
|
38
38
|
`)}
|
|
39
|
-
}`:"{}",
|
|
39
|
+
}`:"{}",U=_.length>0?_.join(" | "):"never";return`// Auto-generated by svelte-origin
|
|
40
40
|
// Do not edit manually - ${Y}
|
|
41
41
|
|
|
42
42
|
import type { Component } from 'svelte';
|
|
@@ -49,18 +49,18 @@ import type { ${Q} } from '${X}';
|
|
|
49
49
|
*/
|
|
50
50
|
type Props = ${J};
|
|
51
51
|
|
|
52
|
-
declare const __component: Component<Props, {}, ${
|
|
52
|
+
declare const __component: Component<Props, {}, ${U}>;
|
|
53
53
|
export default __component;
|
|
54
|
-
`}function
|
|
55
|
-
`)),Z.set(Y,{varName:Y,factoryExpr:$,startPos:_,endPos:J}),{...X,restVarInjected:
|
|
56
|
-
`)),Y.set($,{varName:$,factoryExpr:_,startPos:J,endPos:
|
|
57
|
-
`));return X.neededImports.add("__attrsFor"),X}function
|
|
58
|
-
`))}Z.neededImports.add("__attrsFor")}function
|
|
54
|
+
`}function mQ(Q){let X=[],Z=l(Q,"$origin.component");for(let Y of Z){let{varName:$,startIndex:_,macroOpenParen:J}=Y,U=O(Q,J);if(U===-1){console.warn(`[svelte-origin] Could not find matching ) for $origin.component( at index ${J}`);continue}let H=Q.slice(J+1,U).trim();X.push({varName:$,factoryExpr:H,startIndex:_,endIndex:U+1,isGeneric:ZQ(H)})}return X.sort((Y,$)=>Y.startIndex-$.startIndex),X}function cZ(Q){let X=b(Q);return ZQ(Q)?`$origin.Props<ReturnType<typeof ${QQ(X)}>>`:`$origin.Props<typeof ${Q}>`}function oZ(Q,X,Z,Y,$,_,J,U,H){let W=[],q=b(X),z=J;if($&&_){let K=cZ(X);W.push(`type $$Props = ${K}`)}if(Z&&Y){let K=Y[1];if(!/\.\.\.\s*(\w+)\s*$/.test(K)&&!z){let L=K.trimEnd()?`${K.trimEnd()}, ...___originAttrs`:"...___originAttrs",T=H.indexOf("}",Y.index+5);if(T!==-1)U.overwrite(Y.index+5,T,` ${L} `),z=!0;W.push(`let ${Q} = ${q}(__attrsFor(${q}, ___originAttrs))`)}else{let G=K.match(/\.\.\.\s*(\w+)\s*$/),L=G?G[1]:"___originAttrs";W.push(`let ${Q} = ${q}(__attrsFor(${q}, ${L}))`)}}else W.push("let ___attrs: $$Props = $props()",`let ${Q} = ${q}(__attrsFor(${q}, ___attrs))`);return{lines:W,restVarInjected:z}}function dQ(Q,X,Z){let{varName:Y,factoryExpr:$,startIndex:_,endIndex:J}=Q,U=oZ(Y,$,X.hasExistingProps,X.existingPropsMatch,X.isFirstDeclaration,X.needsPropsInjection,X.restVarInjected,X.s,X.source);if(X.neededImports.add("__attrsFor"),X.isFirstDeclaration&&X.needsPropsInjection)X.propsTypeDeclaration="";return X.s.overwrite(_,J,U.lines.join(`
|
|
55
|
+
`)),Z.set(Y,{varName:Y,factoryExpr:$,startPos:_,endPos:J}),{...X,restVarInjected:U.restVarInjected,isFirstDeclaration:!1}}function sZ(Q,X,Z,Y){let{varName:$,factoryExpr:_,startIndex:J,endIndex:U}=Q,H=b(_),W=wQ(Z.source),q=p(X.attrs,H,{useNewApi:!0,useUserPropsType:W}),z=RQ(H,X.attrs),K=[q,`let ${$} = ${z}`];Z.s.overwrite(J,U,K.join(`
|
|
56
|
+
`)),Y.set($,{varName:$,factoryExpr:_,startPos:J,endPos:U})}function iQ(Q,X,Z){let Y=X.match(/let\s*\{([^}]*)\}\s*(?::\s*[^=]+)?\s*=\s*\$props\s*\(\s*\)/),$=!!Y,_=!wQ(X)&&!$;return{s:Q,source:X,neededImports:Z,existingPropsMatch:Y,hasExistingProps:$,needsPropsInjection:_,isFirstDeclaration:!0,restVarInjected:!1,propsTypeDeclaration:null}}async function aZ(Q,X,Z,Y){let $=mQ(X);if($.length===0)return{changed:!1,propsTypeDeclaration:null,originInstances:new Map};let _=iQ(Q,X,Z),J=new Map;for(let U of $){let H=!0;if(Y){let W=NQ(U.factoryExpr),q=C(X,W),z=await Y(U.factoryExpr,W,q);if(z&&z.attrs.length>0)sZ(U,z,_,J),_={..._,isFirstDeclaration:!1},H=!1}if(H)_=dQ(U,_,J)}return{changed:!0,propsTypeDeclaration:_.propsTypeDeclaration,originInstances:J}}function rZ(Q,X,Z){let Y=mQ(X);if(Y.length===0)return{changed:!1,propsTypeDeclaration:null,originInstances:new Map};let $=iQ(Q,X,Z),_=new Map;for(let J of Y)$=dQ(J,$,_);return{changed:!0,propsTypeDeclaration:$.propsTypeDeclaration,originInstances:_}}function EQ(Q,X,Z){return rZ(Q,X,Z)}async function nQ(Q,X,Z,Y){return aZ(Q,X,Z,Y?async(_,J,U)=>{return Y.resolve(U,J)}:void 0)}function cQ(Q){return`svelteHTML.IntrinsicElements['${Q}']`}function oQ(Q){let X=[];for(let Z of Q)if(X.push(HQ(Z.key)),Z.bindable)X.push(WQ(Z.key));return`{ ${X.join(", ")} }`}function tZ(Q){let X=[];for(let Z of Q)if(Z.bindable)X.push(Z.hasDefault?g(Z.key,`$bindable(${Z.defaultValue})`):g(Z.key,"$bindable()"));else if(Z.hasDefault)X.push(g(Z.key,Z.defaultValue));else X.push(UQ(Z.key));return X.join(", ")}function sQ(Q){let X=[],Z=l(Q,"$origin.for");for(let Y of Z){let{varName:$,startIndex:_,macroOpenParen:J}=Y,U=O(Q,J);if(U===-1)continue;let H=Q.slice(J+1,U).trim(),W=H.match(/^['"](\w+)['"]$/);X.push({varName:$,arg:H,startIndex:_,endIndex:U+1,isElement:!!W,elementName:W?W[1]:void 0,factoryName:W?void 0:H})}return X.sort((Y,$)=>Y.startIndex-$.startIndex),X}function eZ(Q){let X=Q.match(/let\s*\{([^}]*)\}\s*(?::\s*[^=]+)?\s*=\s*\$props\s*\(\s*\)/);if(!X)return null;let Z=X[1],Y=Z.match(/\.\.\.\s*(\w+)\s*$/);return{match:X,content:Z,restVarName:Y?Y[1]:null}}function aQ(Q,X,Z,Y){let $=Z.content.trimEnd()?`${Z.content.trimEnd()}, ...${Y}`:`...${Y}`,_=X.indexOf("}",Z.match.index+5);if(_!==-1)Q.overwrite(Z.match.index+5,_,` ${$} `)}function rQ(Q,X,Z){let Y=eZ(X);return{s:Q,source:X,neededImports:Z,existingProps:Y,restVarName:Y?.restVarName??null,restVarInjected:!1}}function tQ(Q,X){let Z=cQ(Q.elementName);if(X.existingProps){if(!X.restVarName&&!X.restVarInjected)X.restVarName="___restAttrs",aQ(X.s,X.source,X.existingProps,X.restVarName),X.restVarInjected=!0;X.s.overwrite(Q.startIndex,Q.endIndex,`let ${Q.varName} = ${X.restVarName} as ${Z}`)}else X.s.overwrite(Q.startIndex,Q.endIndex,`let { ...${Q.varName} } = $props<${Z}>()`);return X}function eQ(Q,X){if(X.existingProps){if(!X.restVarName&&!X.restVarInjected)X.restVarName="___restAttrs",aQ(X.s,X.source,X.existingProps,X.restVarName),X.restVarInjected=!0;X.s.overwrite(Q.startIndex,Q.endIndex,`let ${Q.varName} = __attrsFor(${Q.factoryName}, ${X.restVarName})`)}else X.s.overwrite(Q.startIndex,Q.endIndex,[`let ___attrs: $origin.Props<typeof ${Q.factoryName}> = $props()`,`let ${Q.varName} = __attrsFor(${Q.factoryName}, ___attrs)`].join(`
|
|
57
|
+
`));return X.neededImports.add("__attrsFor"),X}function Q0(Q,X,Z){if(Z.existingProps){let Y=tZ(X.attrs),$=Z.existingProps.content.match(/,?\s*\.\.\.\s*(\w+)\s*$/),_=Z.existingProps.content,J="";if($)J=$[0],_=Z.existingProps.content.slice(0,$.index);let U=_.trimEnd()?`${_.trimEnd()}, ${Y}${J}`:`${Y}${J}`,H=Z.source.indexOf("}",Z.existingProps.match.index+5);if(H!==-1)Z.s.overwrite(Z.existingProps.match.index+5,H,` ${U} `);let W=oQ(X.attrs);Z.s.overwrite(Q.startIndex,Q.endIndex,`let ${Q.varName} = __attrsFor(${Q.factoryName}, ${W})`)}else{let Y=p(X.attrs,Q.factoryName,{useNewApi:!0}),$=oQ(X.attrs);Z.s.overwrite(Q.startIndex,Q.endIndex,[Y,`let ${Q.varName} = __attrsFor(${Q.factoryName}, ${$})`].join(`
|
|
58
|
+
`))}Z.neededImports.add("__attrsFor")}function Z0(Q,X,Z){let Y=sQ(X);if(Y.length===0)return!1;let $=rQ(Q,X,Z);for(let _ of Y)if(_.isElement&&_.elementName)$=tQ(_,$);else if(_.factoryName)$=eQ(_,$);return!0}async function X0(Q,X,Z,Y){let $=sQ(X);if($.length===0)return!1;let _=rQ(Q,X,Z);for(let J of $)if(J.isElement&&J.elementName)_=tQ(J,_);else if(J.factoryName){let U=!0;if(Y){let H=C(X,J.factoryName),W=await Y(J.factoryName,H);if(W&&W.attrs.length>0)Q0(J,W,_),U=!1}if(U)_=eQ(J,_)}return!0}function MQ(Q,X,Z){return Z0(Q,X,Z)}async function QZ(Q,X,Z,Y){return X0(Q,X,Z,Y?async(_,J)=>{if(!J)return null;return Y.resolve(J,_)}:void 0)}function $Z(Q,X,Z){let Y=!1,$=Y0(X,Z);for(let _ of $.reverse()){let J=_0(_,Z);if(J)Q.overwrite(_.startPos,_.endPos,J),Y=!0}return Y}function Y0(Q,X){let Z=[],Y=/\b(let|const|var)\s*\{/g,$;while(($=Y.exec(Q))!==null){if(v(Q,$.index))continue;let _=$[1],J=$.index+$[0].length-1,U=O(Q,J,"{","}");if(U===-1)continue;let H=U+1;while(H<Q.length&&/\s/.test(Q[H]))H++;if(Q[H]!=="=")continue;H++;while(H<Q.length&&/\s/.test(Q[H]))H++;let W="";while(H<Q.length&&/[\w$]/.test(Q[H]))W+=Q[H],H++;if(!W)continue;if(!X.has(W))continue;let q=!1;while(H<Q.length&&/\s/.test(Q[H]))H++;if(Q[H]==="."){H++;while(H<Q.length&&/\s/.test(Q[H]))H++;let G=U0(Q,H);if(G==="props")q=!0,H+=G.length;else continue}let z=H;while(z<Q.length&&/\s/.test(Q[z])&&Q[z]!==`
|
|
59
59
|
`)z++;if(Q[z]===";")z++;if(Q[z]===`
|
|
60
|
-
`)z++;let
|
|
60
|
+
`)z++;let K=Q.slice(J+1,U),w=$0(K,q);Z.push({startPos:$.index,endPos:z,sourceVar:W,isPropsAccess:q,methods:w.methods,props:w.props,nestedPropsPattern:w.nestedProps})}return Z}function $0(Q,X){let Z=[],Y=[],$=null,_=P(Q);for(let J of _){let U=J.trim();if(!U)continue;if(U.match(/^props\s*:\s*\{/)){let W=U.indexOf("{"),q=O(U,W,"{","}");if(q!==-1){let z=U.slice(W+1,q),K=P(z),w=[];for(let G of K){let L=ZZ(G.trim());if(L)w.push(L)}$={startPos:0,endPos:0,props:w}}continue}if(X){let W=ZZ(U);if(W)Y.push(W)}else{let W=_Z(U);if(W)Z.push(W)}}return{methods:Z,props:Y,nestedProps:$}}function _Z(Q){let X=Q.trim();if(!X)return null;let Z=J0(X),Y,$=null,_=X;if(Z!==-1){Y=X.slice(0,Z).trim(),_=X.slice(Z+1).trim();let U=YZ(_);if(U!==-1)return $=_.slice(0,U).trim(),{key:Y,alias:$,defaultValue:_.slice(U+1).trim()};else return $=_,{key:Y,alias:$,defaultValue:null}}let J=YZ(X);if(J!==-1)return Y=X.slice(0,J).trim(),{key:Y,alias:null,defaultValue:X.slice(J+1).trim()};return{key:X,alias:null,defaultValue:null}}function ZZ(Q){let X=_Z(Q);if(!X)return null;let Z=!1,Y=null;if(X.defaultValue){if(X.defaultValue.match(/^\$bindable\s*\(/)){Z=!0;let _=X.defaultValue.indexOf("("),J=O(X.defaultValue,_,"(",")");if(J!==-1)Y=X.defaultValue.slice(_+1,J).trim()||null}}return{...X,isBindable:Z,bindableDefault:Y}}function _0(Q,X){let Z=[];if(!X.get(Q.sourceVar))return null;for(let $ of Q.methods){let _=$.alias||$.key;if($.defaultValue)Z.push(`let ${_} = ${Q.sourceVar}.${$.key}?.bind(${Q.sourceVar}) ?? ${$.defaultValue}`);else Z.push(`let ${_} = ${Q.sourceVar}.${$.key}.bind(${Q.sourceVar})`)}if(Q.nestedPropsPattern)for(let $ of Q.nestedPropsPattern.props)Z.push(...XZ($,Q.sourceVar));if(Q.isPropsAccess)for(let $ of Q.props)Z.push(...XZ($,Q.sourceVar));return Z.join(`
|
|
61
61
|
`)+`
|
|
62
|
-
`}function
|
|
63
|
-
`,Z+2);Z=Y===-1?Q.length:Y+1;continue}if(Q[Z]==="/"&&Q[Z+1]==="*"){let Y=Q.indexOf("*/",Z+2);Z=Y===-1?Q.length:Y+2;continue}if(Q[Z]==='"'||Q[Z]==="'"||Q[Z]==="`"){let Y=Q[Z];X+=Q[Z],Z++;while(Z<Q.length&&Q[Z]!==Y){if(Q[Z]==="\\")X+=Q[Z],Z++;if(Z<Q.length)X+=Q[Z],Z++}if(Z<Q.length)X+=Q[Z],Z++;continue}X+=Q[Z],Z++}return X}function
|
|
62
|
+
`}function XZ(Q,X){let Z=[],Y=Q.alias||Q.key;if(Q.isBindable){let $=Q.bindableDefault||"undefined";Z.push(`let ${Y} = $derived(${X}.props.${Q.key} ?? ${$})`)}else if(Q.defaultValue)Z.push(`let ${Y} = $derived(${X}.props.${Q.key} ?? ${Q.defaultValue})`);else Z.push(`let ${Y} = $derived(${X}.props.${Q.key})`);return Z}function J0(Q){let X=0;for(let Z=0;Z<Q.length;Z++){let Y=Q[Z];if(Y==="{"||Y==="("||Y==="["||Y==="<")X++;else if(Y==="}"||Y===")"||Y==="]"||Y===">")X--;else if(Y===":"&&X===0)return Z}return-1}function YZ(Q){let X=0;for(let Z=0;Z<Q.length;Z++){let Y=Q[Z];if(Y==="{"||Y==="("||Y==="["||Y==="<")X++;else if(Y==="}"||Y===")"||Y==="]"||Y===">")X--;else if(Y==="="&&X===0){if(Q[Z+1]!=="="&&Q[Z+1]!==">")return Z}}return-1}function U0(Q,X){let Z="",Y=X;while(Y<Q.length&&/[\w$]/.test(Q[Y]))Z+=Q[Y],Y++;return Z}function W0(Q){let X="",Z=0;while(Z<Q.length){if(Q[Z]==="/"&&Q[Z+1]==="/"){let Y=Q.indexOf(`
|
|
63
|
+
`,Z+2);Z=Y===-1?Q.length:Y+1;continue}if(Q[Z]==="/"&&Q[Z+1]==="*"){let Y=Q.indexOf("*/",Z+2);Z=Y===-1?Q.length:Y+2;continue}if(Q[Z]==='"'||Q[Z]==="'"||Q[Z]==="`"){let Y=Q[Z];X+=Q[Z],Z++;while(Z<Q.length&&Q[Z]!==Y){if(Q[Z]==="\\")X+=Q[Z],Z++;if(Z<Q.length)X+=Q[Z],Z++}if(Z<Q.length)X+=Q[Z],Z++;continue}X+=Q[Z],Z++}return X}function JZ(Q,X,Z){if(X)return;let Y=W0(Q),$=/\$origin\s*\.\s*component\s*\(/,_=/\$origin\s*\.\s*for\s*\(\s*\w+\s*\)/,J=/\$origin\s*\.\s*for\s*\(\s*['"]/;if($.test(Y)){let U=Z?` in "${Z}"`:"";throw Error(`[svelte-origin] $origin.component()${U} can only be used inside .svelte components.
|
|
64
64
|
|
|
65
65
|
Use $origin.create() instead for programmatic origin creation in .svelte.ts/.svelte.js files.
|
|
66
66
|
|
|
@@ -69,26 +69,26 @@ export default __component;
|
|
|
69
69
|
let counter = $origin.component(Counter)
|
|
70
70
|
|
|
71
71
|
// Use:
|
|
72
|
-
let counter = $origin.create(Counter, { count: 0 })`)}if(_.test(Y)||J.test(Y)){let
|
|
72
|
+
let counter = $origin.create(Counter, { count: 0 })`)}if(_.test(Y)||J.test(Y)){let U=Z?` in "${Z}"`:"";throw Error(`[svelte-origin] $origin.for()${U} can only be used inside .svelte components.
|
|
73
73
|
|
|
74
|
-
This macro is for forwarding props to child components in templates.`)}}function
|
|
75
|
-
`+
|
|
76
|
-
`+Q.propsTypeDeclaration)}}}else{let Y=
|
|
74
|
+
This macro is for forwarding props to child components in templates.`)}}function UZ(Q,X){return{s:new H0(Q),source:Q,isComponent:X,neededImports:new Set,svelteImports:new Set,changed:!1,propsTypeDeclaration:null}}function HZ(Q){if(!Q.isComponent)Q.changed=gQ(Q.s,Q.source,Q.neededImports,Q.svelteImports)||Q.changed,Q.changed=fQ(Q.s,Q.source,Q.neededImports)||Q.changed;Q.changed=xQ(Q.s,Q.source,Q.neededImports)||Q.changed,Q.changed=hQ(Q.s,Q.s.toString(),Q.neededImports)||Q.changed}function WZ(Q,X){if(Q.changed=X.changed||Q.changed,Q.propsTypeDeclaration=X.propsTypeDeclaration,X.originInstances.size>0)Q.changed=$Z(Q.s,Q.source,X.originInstances)||Q.changed}function z0(Q){let X=/<script[^>]*>/.test(Q.source),Z=Q.propsTypeDeclaration&&Q.propsTypeDeclaration.length>0;if(Q.isComponent&&(Q.neededImports.size>0||Z))if(X){let Y=Q.source.match(/<script[^>]*>/);if(Y){let $=Y.index+Y[0].length,_=TQ(Q.source);if(Q.neededImports.size>0)Q.s.appendLeft($,`
|
|
75
|
+
`+a([...Q.neededImports]));if(Z){let J=_>$?_:$;Q.s.appendLeft(J,`
|
|
76
|
+
`+Q.propsTypeDeclaration)}}}else{let Y=TQ(Q.source);if(Q.neededImports.size>0)Q.s.prepend(a([...Q.neededImports])+`
|
|
77
77
|
`);if(Z)Q.s.appendLeft(Y,Q.propsTypeDeclaration+`
|
|
78
|
-
`)}else if(Q.neededImports.size>0||Q.svelteImports.size>0){if(Q.neededImports.size>0)Q.s.prepend(
|
|
78
|
+
`)}else if(Q.neededImports.size>0||Q.svelteImports.size>0){if(Q.neededImports.size>0)Q.s.prepend(a([...Q.neededImports])+`
|
|
79
79
|
`);if(Q.svelteImports.size>0)Q.s.prepend(`import { ${[...Q.svelteImports].join(", ")} } from 'svelte'
|
|
80
|
-
`)}}function
|
|
81
|
-
`)Y=!1,X+=J;_++;continue}if($){if(J==="*"&&
|
|
80
|
+
`)}}function zZ(Q){if(z0(Q),!Q.changed)return{code:Q.source,changed:!1};return{code:Q.s.toString(),changed:!0,map:Q.s.generateMap({hires:!0})}}async function qZ(Q,X){if(!u(Q))return{code:Q,changed:!1};let{isComponent:Z=!1,schemaResolver:Y,filename:$}=X;JZ(Q,Z,$);let _=UZ(Q,Z);if(HZ(_),Z){let J=Y?await nQ(_.s,Q,_.neededImports,Y):EQ(_.s,Q,_.neededImports);WZ(_,J)}if(Z){let J=Y?await QZ(_.s,Q,_.neededImports,Y):MQ(_.s,Q,_.neededImports);_.changed=J||_.changed}return zZ(_)}function q0(Q,X){if(!u(Q))return{code:Q,changed:!1};let{isComponent:Z=!1,filename:Y}=X;JZ(Q,Z,Y);let $=UZ(Q,Z);if(HZ($),Z){let _=EQ($.s,Q,$.neededImports);WZ($,_)}if(Z){let _=MQ($.s,Q,$.neededImports);$.changed=_||$.changed}return zZ($)}function KZ(Q,X={}){if(X.schemaResolver)return qZ(Q,X);return q0(Q,X)}async function n1(Q,X){return qZ(Q,X)}import{writeFileSync as K0,mkdirSync as G0,existsSync as w0,readdirSync as T0}from"node:fs";import{dirname as j0,join as GZ,basename as L0}from"node:path";function a1(Q,X,Z){if(!Z.enabled||!Q)return;try{let Y=Z.outputDir??j0(Q);if(!w0(Y))G0(Y,{recursive:!0});let $=L0(Q),_=GZ(Y,`${$}.transformed.txt`);if(K0(_,X,"utf-8"),Z.debug)console.log(`[svelte-origin] Wrote transformed output to ${_}`)}catch(Y){console.warn("[svelte-origin] Failed to write transformed output:",Y)}}function wZ(Q,X){let Z=[];function Y($){let _=T0($,{withFileTypes:!0});for(let J of _){if(J.name.startsWith(".")||J.name==="node_modules")continue;let U=GZ($,J.name);if(J.isDirectory())Y(U);else if(J.isFile()){if(X.some((W)=>J.name.endsWith(W)))Z.push(U)}}}return Y(Q),Z}import{readFileSync as M0,statSync as BZ}from"node:fs";import{basename as OZ,dirname as S0}from"node:path";import{existsSync as E,readFileSync as SQ,statSync as O0}from"node:fs";import{dirname as x,join as k,resolve as I,isAbsolute as y}from"node:path";function F0(Q){let X="",Z=!1,Y=!1,$=!1,_=0;while(_<Q.length){let J=Q[_],U=Q[_+1];if(Y){if(J===`
|
|
81
|
+
`)Y=!1,X+=J;_++;continue}if($){if(J==="*"&&U==="/"){$=!1,_+=2;continue}_++;continue}if(Z){if(X+=J,J==="\\"&&U){X+=U,_+=2;continue}if(J==='"')Z=!1;_++;continue}if(J==='"'){Z=!0,X+=J,_++;continue}if(J==="/"&&U==="/"){Y=!0,_+=2;continue}if(J==="/"&&U==="*"){$=!0,_+=2;continue}X+=J,_++}return X}function TZ(Q,X=new Set){let Z=I(Q);if(X.has(Z))return null;if(X.add(Z),!E(Z))return null;try{let Y=SQ(Z,"utf-8"),$=F0(Y),_=JSON.parse($),J=x(Z),U={},H=_.compilerOptions?.baseUrl,W=_.extends;if(W){let q=Array.isArray(W)?W:[W];for(let z of q){let K;if(z.startsWith("."))K=I(J,z);else if(z.startsWith("/")||/^[a-zA-Z]:/.test(z))K=z;else{let G=B0(z,J);if(G)K=G;else continue}if(!K.endsWith(".json")){if(E(K+".json"))K=K+".json";else if(E(k(K,"tsconfig.json")))K=k(K,"tsconfig.json")}let w=TZ(K,X);if(w){if(w.paths)U={...w.paths,...U};if(w.baseUrl&&!H){let G=x(K);H=I(G,w.baseUrl)}}}}if(_.compilerOptions?.paths)U={...U,..._.compilerOptions.paths};if(H&&!y(H))H=I(J,H);return{paths:Object.keys(U).length>0?U:void 0,baseUrl:H}}catch{return null}}function B0(Q,X){let Z=X,Y=y(X)?(X.match(/^[a-zA-Z]:[/\\]/)||["/"])[0]:"/";while(Z!==Y&&Z!==x(Z)){let $=k(Z,"node_modules",Q);if(E($)){if($.endsWith(".json"))return $;let _=k($,"tsconfig.json");if(E(_))return _;if(E($+".json"))return $+".json"}Z=x(Z)}return null}function V0(Q,X){let Z={};for(let[Y,$]of Object.entries(Q)){if(!$||$.length===0)continue;let _=$[0],J=Y.endsWith("/*"),U=J?Y.slice(0,-2):Y;if(J&&_.endsWith("/*"))_=_.slice(0,-2);let H=y(_)?_:I(X,_);Z[U]=H}return Z}function A0(Q,X){if(!E(Q))return{};try{let Z=SQ(Q,"utf-8"),Y={},$=Z.match(/alias\s*:\s*\{([^}]+)\}/s);if(!$)return{};let _=$[1],J=/['"]?(\$[\w-]+)['"]?\s*:\s*['"]([^'"]+)['"]/g,U;while((U=J.exec(_))!==null){let[,H,W]=U,q=y(W)?W:I(X,W);Y[H]=q}return Y}catch{return{}}}function R0(Q){let X=[],Z=["tsconfig.json","jsconfig.json",".svelte-kit/tsconfig.json"];for(let Y of Z){let $=I(Q,Y);if(E($))X.push($)}return X}function Q2(Q={}){let{aliases:X={},root:Z=process.cwd(),autoDetect:Y=!0,tsconfig:$,svelteConfig:_}=Q,J=y(Z)?Z:I(process.cwd(),Z),U={};if(Y){let H=$?[y($)?$:I(J,$)]:R0(J);for(let z of H){let K=TZ(z);if(K?.paths){let w=K.baseUrl||x(z);U={...V0(K.paths,w),...U}}}let W=_?y(_)?_:I(J,_):I(J,"svelte.config.js"),q=A0(W,J);U={...U,...q}}for(let[H,W]of Object.entries(X))U[H]=y(W)?W:I(J,W);return{aliases:U,root:J}}function jZ(Q,X,Z){if(Q.startsWith("."))return I(Z,Q);let Y=Object.entries(X).sort((_,J)=>J[0].length-_[0].length);for(let[_,J]of Y){if(Q===_)return J;if(Q.startsWith(_+"/")){let U=Q.slice(_.length+1);return k(J,U)}}let $=D0(Q,Z);if($)return $;return null}function D0(Q,X){if(Q.startsWith(".")||Q.startsWith("/")||/^[a-zA-Z]:/.test(Q))return null;let Z,Y;if(Q.startsWith("@")){let J=Q.split("/");if(J.length<2)return null;Z=`${J[0]}/${J[1]}`,Y=J.slice(2).join("/")}else{let J=Q.indexOf("/");if(J===-1)Z=Q,Y="";else Z=Q.slice(0,J),Y=Q.slice(J+1)}let $=X,_=y(X)?(X.match(/^[a-zA-Z]:[/\\]/)||["/"])[0]:"/";while($!==_&&$!==x($)){let J=k($,"node_modules"),U=k(J,Z);if(E(U)){let H=k(U,"package.json"),W=Y?`./${Y}`:".";if(E(H))try{let q=JSON.parse(SQ(H,"utf-8"));if(q.exports){let z=E0(q.exports,W);if(z)return k(U,z)}if(!Y){let z=q.module||q.main||"index.js";return k(U,z)}}catch{}if(Y)return k(U,Y);return k(U,"index.js")}$=x($)}return null}function E0(Q,X){if(typeof Q==="string")return X==="."?Q:null;if(typeof Q!=="object"||Q===null)return null;let Z=Q[X];if(Z)return qQ(Z);if(X==="."&&Q["."])return qQ(Q["."]);if(X==="."){let Y=qQ(Q);if(Y)return Y}return null}function qQ(Q){if(typeof Q==="string")return Q;if(typeof Q!=="object"||Q===null)return null;let X=Q,Z=["svelte","import","module","default","require"];for(let Y of Z)if(Y in X){let $=X[Y];if(typeof $==="string")return $;let _=qQ($);if(_)return _}return null}function LZ(Q){if(E(Q))try{let Y=O0(Q);if(Y.isFile())return Q;if(Y.isDirectory()){let $=["index.ts","index.js"];for(let _ of $){let J=k(Q,_);if(E(J))return J}}}catch{}let X=[".ts",".js",".svelte.ts",".svelte.js"];if(Q.endsWith(".svelte")){let Y=Q+".ts";if(E(Y))return Y}if(Q.endsWith(".svelte.js")){let Y=Q.slice(0,-3)+".ts";if(E(Y))return Y}for(let Y of X){let $=Q+Y;if(E($))return $}let Z=["/index.ts","/index.js"];for(let Y of Z){let $=Q+Y;if(E($))return $}return null}var i=new Map;function k0(Q,X){let Z=i.get(Q);if(!Z)return!1;try{for(let Y=0;Y<Z.filePaths.length;Y++)if(BZ(Z.filePaths[Y]).mtimeMs!==Z.mtimes[Y]){if(X)console.log(`[svelte-origin] Cache stale for ${Q}: ${Z.filePaths[Y]} changed`);return!1}return!0}catch{return!1}}function FZ(Q,X){let Z=[],Y=[];for(let $ of X)try{let _=BZ($).mtimeMs;Z.push($),Y.push(_)}catch{}if(Z.length>0)i.set(Q,{filePaths:Z,mtimes:Y})}function J2(Q,X){let Z=OZ(Q);for(let[Y,$]of i.entries())if($.filePaths.some((J)=>J===Q||OZ(J)===Z))X.delete(Y),i.delete(Y)}function m(Q,X,Z=!1){for(let Y of X){let $=Q.findIndex((_)=>_.key===Y.key);if($===-1)Q.push(Y);else if(Z)Q[$]=Y}}function I0(Q,X,Z,Y){let $=jZ(Q,Z,X);if(!$){if(Y)console.log(`[svelte-origin] No alias match for ${Q}, skipping`);return null}if(Y)console.log(`[svelte-origin] Resolved path: ${$}`);let _=LZ($);if(!_){if(Y)console.log(`[svelte-origin] Could not find file for ${$}`);return null}if(Y)console.log(`[svelte-origin] Found file: ${_}`);let J=M0(_,"utf-8");return{filePath:_,source:J}}async function d(Q,X,Z,Y,$,_={},J=null){let{debug:U=!1,aliases:H={}}=_,W=J===null,q=J??new Set,z=Q==="attrs"?`attrs::${X}::${Z}`:`${X}::${Z}`;if($.has(z)&&k0(z,U)){if(U)console.log(`[svelte-origin] Cache hit for ${z}`);return $.get(z)||null}if($.has(z))$.delete(z),i.delete(z);try{let K=S0(Y);if(U)console.log(`[svelte-origin] Resolving ${Q}: ${Z} from ${X}`);let w=I0(X,K,H,U);if(!w)return $.set(z,null),null;let{filePath:G,source:L}=w;q.add(G);let T=Q==="attrs"?_Q(L,Z):VQ(L,Z);if(!T){if($.set(z,null),W)FZ(z,q);return null}let j=[];for(let B of T.parentNames){let F=C(L,B),V=null;if(F)V=Q==="attrs"?await d("attrs",F,B,G,$,_,q):await d("origin",F,B,G,$,_,q);else if(Q==="attrs")V=await IQ(L,B,G,$,_,q);if(V)m(j,V.attrs)}if(Q==="origin"&&T.propsRef){let B=C(L,T.propsRef),F=null;if(B){if(U)console.log(`[svelte-origin] Resolving propsRef: ${T.propsRef} from import ${B}`);F=await d("attrs",B,T.propsRef,G,$,_,q)}else{if(U)console.log(`[svelte-origin] Resolving propsRef: ${T.propsRef} from same file`);F=await IQ(L,T.propsRef,G,$,_,q)}if(F)m(j,F.attrs,!0)}m(j,T.attrs,!0);let A={attrs:j,parentNames:T.parentNames};if(U)console.log(`[svelte-origin] Resolved ${Q} schema for ${Z}:`,A.attrs.map((B)=>B.key));if($.set(z,A),W)FZ(z,q);return A}catch(K){if(U)console.error(`[svelte-origin] Error resolving ${Q} schema for ${X}:`,K);return $.set(z,null),null}}async function kQ(Q,X,Z,Y,$={}){return d("origin",Q,X,Z,Y,$)}async function IQ(Q,X,Z,Y,$={},_=null){let{debug:J=!1}=$;if(_)_.add(Z);let U=_Q(Q,X);if(!U)return null;if(U.parentNames.length===0)return U;let H=[];for(let W of U.parentNames){let q=C(Q,W),z=null;if(q)z=await d("attrs",q,W,Z,Y,$,_);else z=await IQ(Q,W,Z,Y,$,_);if(z)m(H,z.attrs)}if(m(H,U.attrs,!0),J)console.log(`[svelte-origin] Resolved same-file attrs for ${X}:`,H.map((W)=>W.key));return{attrs:H,parentNames:U.parentNames}}function VZ(Q,X,Z={}){let{debug:Y=!1,moduleImports:$}=Z;return{resolve:async(_,J)=>{if(_!==null)return kQ(_,J,Q,X,Z);if($?.has(J)){let H=$.get(J);if(Y)console.log(`[svelte-origin] Found ${J} in module imports: ${H}`);return kQ(H,J,Q,X,Z)}if(Y)console.log(`[svelte-origin] No import path for ${J}, attempting sibling file resolution`);let U=v0(J,Q);for(let H of U){if(Y)console.log(`[svelte-origin] Trying sibling path: ${H}`);let W=await kQ(H,J,Q,X,Z);if(W){if(Y)console.log(`[svelte-origin] Found schema in sibling file: ${H}`);return W}}if(Y)console.log(`[svelte-origin] Could not find schema for ${J} in sibling files`);return null}}}function v0(Q,X){let Z=new Set,Y=[],$=(z)=>{if(!Z.has(z))Z.add(z),Y.push(z)},_=[".svelte.ts",".svelte.js",".svelte"],J=Q.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),U=Q.charAt(0).toLowerCase()+Q.slice(1),H=Q,W=Q.replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase();for(let z of _)$(`./${J}${z}`),$(`./${U}${z}`),$(`./${H}${z}`),$(`./${W}${z}`);let q=Q.match(/^[A-Z][a-z]+(?=[A-Z])/);if(q){let z=Q.slice(q[0].length);if(z){let K=z.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),w=z.charAt(0).toLowerCase()+z.slice(1),G=z,L=z.replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase();for(let T of _)$(`./${K}${T}`),$(`./${w}${T}`),$(`./${G}${T}`),$(`./${L}${T}`)}}for(let z of _)$(`./state${z}`),$(`./factory${z}`),$(`./schema${z}`),$(`./origin${z}`);return Y}var C0=[".svelte",".svelte.ts",".svelte.js",".js",".ts"],KQ=null;function y0(){if(KQ!==null)return KQ;let Q=M.dirname(N0(import.meta.url)),X=[M.join(Q,"runtime-inline.min.js"),M.join(Q,"../dist/runtime-inline.min.js")];for(let Z of X)if(N.existsSync(Z))return KQ=N.readFileSync(Z,"utf-8"),KQ;throw Error(`[svelte-origin] Cannot find runtime-inline.min.js. Tried:
|
|
82
82
|
`+X.map((Z)=>` - ${Z}`).join(`
|
|
83
83
|
`)+`
|
|
84
|
-
Please run 'bun run build' to generate it.`)}function
|
|
85
|
-
`);let Y=/(\}\s*:\s*)\$origin\.Props<typeof (\w+)>(\s*=\s*\$props\(\))/g;return Z=Z.replace(Y,($,_,J,
|
|
84
|
+
Please run 'bun run build' to generate it.`)}function P0(Q,X){let Z=/import\s*\{([^}]+)\}\s*from\s*['"]svelte-origin\/runtime['"]/g,Y=!1;return{code:Q.replace(Z,(_,J)=>{return Y=!0,`import {${J}} from '${X}'`}),changed:Y}}function b0(Q,X){let Z=Q;Z=Z.replace(/(?:var|const|let)\s+\$\w+\s*=\s*globalThis\.\$\w+(?:\s*,\s*\$\w+\s*=\s*globalThis\.\$\w+)*\s*;?\n?/g,""),Z=Z.replace(/(?:var|const|let)\s*\{\s*\$origin\s*(?:,\s*\$\w+\s*)*\}\s*=\s*globalThis\s*;?\n?/g,""),Z=Z.replace(/\/\/\s*@ts-ignore\s*-?\s*macros are transformed at build time\n?/g,""),Z=Z.replace(/\ntype \$\$Props = \$origin\.Props<[^>]+>\n/g,`
|
|
85
|
+
`);let Y=/(\}\s*:\s*)\$origin\.Props<typeof (\w+)>(\s*=\s*\$props\(\))/g;return Z=Z.replace(Y,($,_,J,U)=>{for(let[H,W]of X.entries())if(W&&H.endsWith(`::${J}`)){let{interfaceContent:q}=zQ(W);return`${_}${q}${U}`}return`${_}Record<string, unknown>${U}`}),Z}function g0(Q,X){if(!X||X.attrs.length===0)return`import type { Component } from 'svelte'
|
|
86
86
|
|
|
87
87
|
declare const ${Q}: Component<{}, {}, ''>
|
|
88
88
|
type ${Q} = typeof ${Q}
|
|
89
89
|
|
|
90
90
|
export { ${Q} as default }
|
|
91
|
-
`;let{interfaceContent:Z,bindings:Y}=
|
|
91
|
+
`;let{interfaceContent:Z,bindings:Y}=zQ(X),$=Y.length>0?`'${Y.join("' | '")}'`:"''";return`import type { Component } from 'svelte'
|
|
92
92
|
|
|
93
93
|
export interface Props ${Z}
|
|
94
94
|
|
|
@@ -96,4 +96,4 @@ declare const ${Q}: Component<Props, {}, ${$}>
|
|
|
96
96
|
type ${Q} = typeof ${Q}
|
|
97
97
|
|
|
98
98
|
export { ${Q} as default }
|
|
99
|
-
`}function
|
|
99
|
+
`}function f0(Q){let X=Q.match(/\$origin\.component\s*\(\s*(\w+)\s*\)/);return X?X[1]:null}async function x0(Q){let{dir:X,dryRun:Z=!1,verbose:Y=!1,inlineDependencies:$=!0}=Q,_={filesProcessed:0,files:[],errors:[]},J=wZ(X,C0);if(Y)console.log(` Found ${J.length} files to check`);let U=new Map,H={debug:Y,aliases:{}},W=!1;for(let q of J)try{let z=N.readFileSync(q,"utf-8"),K=u(z),w=$&&z.includes("from 'svelte-origin/runtime'");if(!K&&!w)continue;if(Y)console.log(` Processing: ${M.relative(X,q)}`);let G=q.endsWith(".svelte"),L=VZ(q,U,H),T=K?await KZ(z,{filename:q,isComponent:G,schemaResolver:L}):{changed:!1,code:z},j=b0(T.changed?T.code:z,U),A=T.changed?T.code:z,B=j!==A,F=!1;if($){let V=M.dirname(q),S=M.join(X,"__svelte-origin-runtime.js"),D=M.relative(V,S).replace(/\\/g,"/");if(!D.startsWith("."))D="./"+D;let f=P0(j,D);if(f.changed)j=f.code,W=!0,F=!0}if(T.changed||B||F){if(_.filesProcessed++,_.files.push(q),!Z)N.writeFileSync(q,j,"utf-8");if(Y)console.log(` ${Z?"Would transform":"Transformed"}: ${M.relative(X,q)}`);if(G){let V=q+".d.ts";if(N.existsSync(V)){let S=f0(z),D=null;if(S){for(let[GQ,c]of U.entries())if(c&&GQ.endsWith(`::${S}`)){D=c;break}}let f=M.basename(q,".svelte"),n=g0(f,D);if(!Z)N.writeFileSync(V,n,"utf-8");if(Y)console.log(` ${Z?"Would regenerate":"Regenerated"} .d.ts: ${M.basename(V)}`);_.files.push(V)}}}}catch(z){let K=`Error processing ${M.relative(X,q)}: ${z}`;if(_.errors.push(K),Y)console.error(` ${K}`)}if(W&&$){let q=M.join(X,"__svelte-origin-runtime.js");try{let z=y0();if(!Z)N.writeFileSync(q,z,"utf-8");if(Y)console.log(` ${Z?"Would write":"Wrote"} inline runtime: __svelte-origin-runtime.js`);_.files.push(q)}catch(z){_.errors.push(`Error writing inline runtime: ${z}`)}}return _}var j2=x0;export{x0 as postProcess,j2 as default};
|