sveld 0.36.7 → 0.36.9
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/lib/browser.d.ts +9 -0
- package/lib/browser.js +218 -218
- package/lib/chunk-0beysrt7.js +62 -0
- package/lib/chunk-26w7fg2w.js +13 -0
- package/lib/chunk-bbeezhqq.js +6 -0
- package/lib/chunk-cqkng6ys.js +7 -0
- package/lib/chunk-hpxd4cgm.js +1 -0
- package/lib/chunk-mdth9bg3.js +225 -0
- package/lib/chunk-n5cjh6db.js +1 -0
- package/lib/chunk-nrz6c5ew.js +10 -0
- package/lib/chunk-ptdfswsv.js +2 -0
- package/lib/chunk-syz2wqmb.js +3 -0
- package/lib/chunk-yzabyfqs.js +16 -0
- package/lib/cli-entry.js +1 -1
- package/lib/index.d.ts +9 -0
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/lib/chunk-02g49ekt.js +0 -13
- package/lib/chunk-0q7qnmx3.js +0 -2
- package/lib/chunk-4ndm4k55.js +0 -16
- package/lib/chunk-5x7ma2jx.js +0 -62
- package/lib/chunk-bjwm35xb.js +0 -1
- package/lib/chunk-c5sqd852.js +0 -1
- package/lib/chunk-fk94b2eb.js +0 -6
- package/lib/chunk-hytk5gv8.js +0 -225
- package/lib/chunk-jvqe4bt1.js +0 -3
- package/lib/chunk-tjthqdyw.js +0 -10
- package/lib/chunk-wn9w3zst.js +0 -7
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{va as P}from"./chunk-syz2wqmb.js";import{Ba as R}from"./chunk-ptdfswsv.js";import{existsSync as k,readdirSync as N,statSync as D}from"node:fs";import m from"node:path";var F="__sveld_resolved_props__",C="__SveldResolvedProps__",M=/ \| undefined$/,O=/[^A-Za-z0-9_-]/g,j=/[^A-Za-z0-9_$]/g,G=/^[0-9]/,L=2;class I{api;symbolFlags;typeFlags;tsconfigPath;overlay=new Map;constructor(e,t,n,r){this.api=e,this.symbolFlags=t,this.typeFlags=n,this.tsconfigPath=r}static async create(e=process.cwd()){let t=q(e);if(!t)return console.warn("Warning: `resolveTypes` could not locate a tsconfig.json. Skipping semantic resolution."),null;let n;try{n=await import("./chunk-26w7fg2w.js")}catch(o){return console.warn("Warning: `resolveTypes` requires the `typescript` package to be installed. Skipping semantic resolution.",o),null}let r=new I(null,n.SymbolFlags,n.TypeFlags,t),s=new n.API({cwd:e,fs:r.createFileSystem()});return r.api=s,r}async expandAll(e){let t=new Map;if(e.length===0)return t;let n=new Map;for(let s of e){if(!s.metadata.canonicalPropsType)continue;if(s.metadata.referencesComponentGenerics)continue;let o=this.virtualFileName(s.filePath,s.moduleName);this.overlay.set(o,z(s.metadata)),n.set(o,s)}if(n.size===0)return t;let r=await this.api.updateSnapshot({openProject:this.tsconfigPath,fileChanges:{created:Array.from(n.keys())}});try{let[s]=n.keys(),o=await r.getDefaultProjectForFile(s);if(!o)return t;let i=o.checker,T=await Promise.all(Array.from(n,async([a,f])=>{let l=this.overlay.get(a);if(!l)return null;let g=V(l),c=await i.getTypeAtPosition(a,g);if(!c)return null;let p=new Map,h=await i.getPropertiesOfType(c);for(let u of h){if(!u.name||u.name.startsWith("__"))continue;p.set(u.name,{name:u.name,symbols:[u],forceOptional:!1})}if((c.flags&this.typeFlags.Union)!==0){let u=await c.getTypes(),A=await Promise.all(u.map((b)=>i.getPropertiesOfType(b)));for(let b of A)for(let d of b){if(!d.name||d.name.startsWith("__")||p.has(d.name))continue;let w=p.get(d.name);if(w)w.symbols.push(d);else p.set(d.name,{name:d.name,symbols:[d],forceOptional:!0})}}return{filePath:f.filePath,groups:Array.from(p.values())}})),y=[],x=[];T.forEach((a,f)=>{if(!a)return;a.groups.forEach((l,g)=>{for(let c of l.symbols)y.push(c),x.push({fileIndex:f,groupIndex:g})})});let E=y.length>0?await i.getTypeOfSymbol(y):[],_=await Promise.all(E.map((a)=>a?i.typeToString(a):Promise.resolve("any"))),v=new Map;y.forEach((a,f)=>{let{fileIndex:l,groupIndex:g}=x[f],c=(a.flags&this.symbolFlags.Optional)!==0,p=_[f];if(c)p=p.replace(M,"");let h=v.get(l)??new Map,S=h.get(g)??[];S.push(p),h.set(g,S),v.set(l,h)}),T.forEach((a,f)=>{if(!a)return;let l=v.get(f),g=a.groups.map((c,p)=>{let h=l?.get(p)??[],S=!(c.forceOptional||c.symbols.some((u)=>(u.flags&this.symbolFlags.Optional)!==0));return{name:c.name,type:Array.from(new Set(h)).join(" | "),isRequired:S}});g.sort((c,p)=>c.name.localeCompare(p.name)),t.set(a.filePath,g)})}finally{await r.dispose?.()}return t}async checkExamples(e){let t=new Map;if(e.length===0)return t;let n=[];for(let s of e)for(let o of s.sources){let i=this.exampleFileName(s.filePath,s.moduleName,o.id);this.overlay.set(i,W(o)),n.push({filePath:s.filePath,source:o,file:i})}if(n.length===0)return t;let r=await this.api.updateSnapshot({openProject:this.tsconfigPath,fileChanges:{created:n.map((s)=>s.file)}});try{let[s]=n,o=await r.getDefaultProjectForFile(s.file);if(!o)return t;await Promise.all(n.map(async({filePath:i,source:T,file:y})=>{let[x,E]=await Promise.all([o.program.getSyntacticDiagnostics(y),o.program.getSemanticDiagnostics(y)]),_=[...x,...E];if(_.length===0)return;let v=this.overlay.get(y)??"",a=_.map((l)=>X(l,v)).sort((l,g)=>l.line-g.line).map((l)=>`Line ${l.line}: ${l.text}`).join(`
|
|
2
|
+
`),f=t.get(i)??[];f.push({id:T.id,name:T.name,message:a}),t.set(i,f)}))}finally{await r.dispose?.()}return t}async dispose(){this.overlay.clear(),await this.api?.close?.()}createFileSystem(){return{readFile:(e)=>this.overlay.get(P(e)),fileExists:(e)=>this.overlay.has(P(e))?!0:void 0,getAccessibleEntries:(e)=>{let t=P(e),n=Array.from(this.overlay.keys()).filter((o)=>P(m.dirname(o))===t);if(n.length===0)return;let r=[],s=[];try{for(let o of N(e)){let i=m.join(e,o);try{(D(i).isDirectory()?s:r).push(o)}catch{}}}catch{}for(let o of n){let i=m.basename(o);if(!r.includes(i))r.push(i)}return{files:r,directories:s}}}}virtualFileName(e,t){let n=m.dirname(m.resolve(e));return P(m.join(n,`__sveld_resolved_${t}.ts`))}exampleFileName(e,t,n){let r=m.dirname(m.resolve(e)),s=n.replace(O,"_");return P(m.join(r,`__sveld_example_${t}_${s}.ts`))}}function z(e){return[...e.typeImportStatements,...e.localTypeDeclarations,`type ${C} = ${e.canonicalPropsType};`,`declare const ${F}: ${C};`].join(`
|
|
3
|
+
`)}function U(e){let t=e.replace(j,"_");if(t===""||G.test(t))return`_${t}`;return t}function W(e){return`const ${U(e.name)} = null as unknown as (${e.type});
|
|
4
|
+
${e.code}
|
|
5
|
+
`}function X(e,t){let n=e.pos??0,r=t.slice(0,n).split(`
|
|
6
|
+
`).length;return{line:Math.max(1,r-L+1),text:String(e.text??"").trim()}}function V(e){let t=e.lastIndexOf("declare const");return e.indexOf(F,t)+2}function q(e){let t=m.resolve(e);while(!0){let n=m.join(t,"tsconfig.json");if(k(n))return n;let r=m.dirname(t);if(r===t)return null;t=r}}export{I as TypeResolver};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{$ as gt,A as _,B as K,C as _e,E as Ce,H as pt,I as Y,J as lt,K as N,L as J,M as dt,N as oe,O as ie,P as Ve,R as ut,S as mt,T as ft,U as yt,V as Oe,W as $e,X as Ge,Y as fe,Z as Ke,_ as Je,ba as Tt,ca as ze,da as Ze,ea as bt,fa as xt,ga as De,ha as et,ja as tt,ka as z,la as We,ma as ht,u as B,w as we,x as st,y as Te,z as ct}from"./chunk-yzabyfqs.js";import{oa as St}from"./chunk-0beysrt7.js";var ke={a:"HTMLAnchorElement",abbr:"HTMLElement",address:"HTMLElement",applet:"HTMLUnknownElement",area:"HTMLAreaElement",article:"HTMLElement",aside:"HTMLElement",audio:"HTMLAudioElement",b:"HTMLElement",base:"HTMLBaseElement",basefont:"HTMLElement",bdi:"HTMLElement",bdo:"HTMLElement",blockquote:"HTMLQuoteElement",body:"HTMLBodyElement",br:"HTMLBRElement",button:"HTMLButtonElement",canvas:"HTMLCanvasElement",caption:"HTMLTableCaptionElement",cite:"HTMLElement",code:"HTMLElement",col:"HTMLTableColElement",colgroup:"HTMLTableColElement",data:"HTMLDataElement",datalist:"HTMLDataListElement",dd:"HTMLElement",del:"HTMLModElement",details:"HTMLDetailsElement",dfn:"HTMLElement",dialog:"HTMLDialogElement",dir:"HTMLDirectoryElement",div:"HTMLDivElement",dl:"HTMLDListElement",dt:"HTMLElement",em:"HTMLElement",embed:"HTMLEmbedElement",fieldset:"HTMLFieldSetElement",figcaption:"HTMLElement",figure:"HTMLElement",font:"HTMLFontElement",footer:"HTMLElement",form:"HTMLFormElement",frame:"HTMLFrameElement",frameset:"HTMLFrameSetElement",h1:"HTMLHeadingElement",h2:"HTMLHeadingElement",h3:"HTMLHeadingElement",h4:"HTMLHeadingElement",h5:"HTMLHeadingElement",h6:"HTMLHeadingElement",head:"HTMLHeadElement",header:"HTMLElement",hgroup:"HTMLElement",hr:"HTMLHRElement",html:"HTMLHtmlElement",i:"HTMLElement",iframe:"HTMLIFrameElement",img:"HTMLImageElement",input:"HTMLInputElement",ins:"HTMLModElement",kbd:"HTMLElement",label:"HTMLLabelElement",legend:"HTMLLegendElement",li:"HTMLLIElement",link:"HTMLLinkElement",main:"HTMLElement",map:"HTMLMapElement",mark:"HTMLElement",marquee:"HTMLMarqueeElement",menu:"HTMLMenuElement",meta:"HTMLMetaElement",meter:"HTMLMeterElement",nav:"HTMLElement",noscript:"HTMLElement",object:"HTMLObjectElement",ol:"HTMLOListElement",optgroup:"HTMLOptGroupElement",option:"HTMLOptionElement",output:"HTMLOutputElement",p:"HTMLParagraphElement",param:"HTMLParamElement",picture:"HTMLPictureElement",pre:"HTMLPreElement",progress:"HTMLProgressElement",q:"HTMLQuoteElement",rp:"HTMLElement",rt:"HTMLElement",ruby:"HTMLElement",s:"HTMLElement",samp:"HTMLElement",script:"HTMLScriptElement",search:"HTMLElement",section:"HTMLElement",select:"HTMLSelectElement",slot:"HTMLSlotElement",small:"HTMLElement",source:"HTMLSourceElement",span:"HTMLSpanElement",strong:"HTMLElement",style:"HTMLStyleElement",sub:"HTMLElement",summary:"HTMLElement",sup:"HTMLElement",table:"HTMLTableElement",tbody:"HTMLTableSectionElement",td:"HTMLTableCellElement",template:"HTMLTemplateElement",textarea:"HTMLTextAreaElement",tfoot:"HTMLTableSectionElement",th:"HTMLTableCellElement",thead:"HTMLTableSectionElement",time:"HTMLTimeElement",title:"HTMLTitleElement",tr:"HTMLTableRowElement",track:"HTMLTrackElement",u:"HTMLElement",ul:"HTMLUListElement",var:"HTMLElement",video:"HTMLVideoElement",wbr:"HTMLElement"};function Pt(e){return e in ke}function Le(e){if(Pt(e))return ke[e];return"HTMLElement"}function Se(){return{syntaxMode:"legacy",scriptLanguage:void 0,source:void 0,parsed:void 0,runesOptionOverride:void 0,sourceLineStartOffsetsCache:void 0,rest_props:void 0,extends:void 0,customElementTag:void 0,componentComment:void 0,componentCommentSource:void 0,generics:null,scriptGenericsAttribute:void 0,diagnosticRecords:[],componentFilePath:"",props:new Map,moduleExports:new Map,propLocalToPublicName:new Map,reactive_vars:new Set,funcDecls:new Map,vars:new Set,valueImportBindingsByLocalName:new Map,pendingCallDefaultCandidates:[],pendingContextKeyCandidates:[],runesPropsDeclarationMetadataByDeclaratorStart:new Map,typedRunesPropsDeclarations:[],explicitPropTypesByName:new Map,explicitVariableTypesByName:new Map,typeImportBindingsByLocalName:new Map,localTypeDeclarationsByName:new Map,wholePropsLocals:new Set,restPropLocals:new Set,componentScope:new Map,scopeDeclarations:new WeakMap,activeScopes:[],slots:new Map,snippetPropLocals:new Set,deferredSlotBlockGenerics:[],events:new Map,eventDescriptions:new Map,forwardedEvents:new Map,jsDocEventNames:new Set,jsDocEventSources:new Map,bindings:new Map,contexts:new Map,typedefs:new Map,variableInfoCache:new Map,variableInfoCacheBuilt:!1}}function Et({hasTypeScriptType:e,hasJSDocType:t,inferredType:n,finalType:r}){if(e)return"typescript";if(t)return"jsdoc";if(n!==void 0)return"default";if(r!==void 0)return"inferred";return"unknown"}function ne(e){let t=e.explicitType??e.jsdocType??e.resolvedType??e.typeSeed,n=e.jsdocParams??e.resolvedParams,r=e.jsdocReturnType??e.resolvedReturnType;if(e.isFunctionDeclaration&&t==="() => any"&&r)t=n&&n.length>0?`(${n.map((p)=>`${p.name}${p.optional?"?":""}: ${p.type}`).join(", ")}) => ${r}`:`() => ${r}`;let i=e.jsdocDescription??e.resolvedDescription;if(i===void 0&&t!==void 0)i=e.typedefs?.get(t)?.description;let c=Et({hasTypeScriptType:e.explicitType!==void 0,hasJSDocType:e.jsdocType!==void 0||e.jsdocParams!==void 0||e.jsdocReturnType!==void 0||e.resolvedType!==void 0,inferredType:e.inferredTypeForSource,finalType:t}),s=e.initializerIsFunction||e.isFunctionDeclaration||e.inferIsFunctionFromTypeSignature===!0&&(!!e.jsdocParams?.length||e.jsdocReturnType!==void 0||!!e.jsdocType?.includes("=>")||!!e.resolvedType?.includes("=>")||!!e.explicitType?.includes("=>"));return{type:t,typeSource:c,description:i,params:n,returnType:r,isFunction:s}}function vt(e){if(!e||typeof e!=="object"||!("type"in e))return;let t=String(e.type);if(t!=="InlineComponent"&&t!=="Element")return;let n="name"in e&&typeof e.name==="string"?e.name:void 0;if(!n)return;let r=t==="InlineComponent"?{type:"InlineComponent",name:n}:{type:"Element",name:n};if(t==="Element"&&n==="svelte:element"&&"tag"in e&&typeof e.tag==="string")r.thisValue=e.tag;return r}function Ne(e,t){if(e.rest_props!==void 0)return;let n=vt(t);if(n)e.rest_props=n}function C(e,t,n){if(!t||e.has(t))return;e.set(t,n)}function de(e,t){for(let n=e.activeScopes.length-1;n>=0;n-=1){let r=e.activeScopes[n]?.get(t);if(!r)continue;return r.kind==="prop"?r.publicPropName:void 0}return}function E(e,t=new Set){if(!e||typeof e!=="object"||!("type"in e))return t;switch(e.type){case"Identifier":t.add(e.name);break;case"AssignmentPattern":E(e.left,t);break;case"ArrayPattern":for(let n of e.elements)E(n??void 0,t);break;case"ObjectPattern":for(let n of e.properties)if(n.type==="Property")E(n.value,t);else if(n.type==="RestElement")E(n.argument,t);break;case"RestElement":E(e.argument,t);break}return t}function Ee(e,t){let n=E(t);if(!n)return;for(let r of n){let i=de(e,r);if(i)e.reactive_vars.add(i)}}function ue(e){if(!e||typeof e!=="object"||!("type"in e))return!1;switch(String(e.type)){case"BlockStatement":case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":case"CatchClause":case"EachBlock":case"ThenBlock":case"CatchBlock":return!0;default:return!1}}function Re(e){if(!e||typeof e!=="object"||!("type"in e))return!1;let t=String(e.type);return t==="FunctionDeclaration"||t==="FunctionExpression"||t==="ArrowFunctionExpression"}function Mt(e,t){let n=e.scopeDeclarations.get(t);if(!n)n=new Map,e.scopeDeclarations.set(t,n);return n}function Dt(e,t,n){let r=[];if(n.id.type==="Identifier")return r.push({kind:"local",name:n.id.name}),r;if(n.id.type!=="ObjectPattern")return r;for(let i of n.id.properties){if(i.type==="RestElement"){if(i.argument.type==="Identifier")r.push({kind:"local",name:i.argument.name});continue}if(i.computed)continue;let c=e.getPropertyName(i.key);if(!c)continue;let s;if(i.value.type==="Identifier")s=i.value.name;else if(i.value.type==="AssignmentPattern"&&i.value.left.type==="Identifier")s=i.value.left.name;if(!s)continue;r.push({kind:"prop",name:s,publicPropName:c})}return r}function Pe(e,t,n,r,i){if(!we(t))return;let c=i?.allowRunesProps??!1,s=i?.forceProp??!1,p=t;for(let d of p.declarations){if(c&&_(K(d.init),"$props")){for(let T of Dt(e,p,d))C(T.kind==="prop"?n:r,T.name,T.kind==="prop"?{kind:"prop",publicPropName:T.publicPropName}:{kind:"local"});continue}let f=p.kind==="var"?r:n,y=s?"prop":"local";for(let T of E(d.id))C(f,T,y==="prop"?{kind:"prop",publicPropName:T}:{kind:"local"})}}function Ct(e,t){if("id"in e&&e.id&&typeof e.id==="object"&&"name"in e.id&&typeof e.id.name==="string")C(t,e.id.name,{kind:"local"});for(let n of e.params)for(let r of E(n))C(t,r,{kind:"local"})}function kt(e,t,n,r){if(!Array.isArray(t))return;for(let i of t){if(!i||typeof i!=="object"||!("type"in i))continue;switch(i.type){case"VariableDeclaration":Pe(e,i,n,r);break;case"FunctionDeclaration":if(i.id?.name)C(n,i.id.name,{kind:"local"});break;case"ClassDeclaration":if(i.id?.name)C(n,i.id.name,{kind:"local"});break}}}function Lt(e,t,n){if(!n||typeof n!=="object")return;let r="content"in n&&n.content&&typeof n.content==="object"&&"body"in n.content&&Array.isArray(n.content.body)?n.content:("body"in n)&&Array.isArray(n.body)?n:void 0;if(!r||!("body"in r)||!Array.isArray(r.body))return;for(let i of r.body){if(!i||typeof i!=="object"||!("type"in i))continue;switch(i.type){case"ImportDeclaration":for(let c of i.specifiers??[])if(c.local?.name)C(t.componentScope,c.local.name,{kind:"local"});break;case"VariableDeclaration":Pe(e,i,t.componentScope,t.componentScope,{allowRunesProps:!0});break;case"FunctionDeclaration":if(i.id?.name)C(t.componentScope,i.id.name,{kind:"local"});break;case"ClassDeclaration":if(i.id?.name)C(t.componentScope,i.id.name,{kind:"local"});break;case"ExportNamedDeclaration":if(!i.declaration||typeof i.declaration!=="object"||!("type"in i.declaration))break;if(i.declaration.type==="VariableDeclaration")Pe(e,i.declaration,t.componentScope,t.componentScope,{forceProp:!0});else if(i.declaration.type==="FunctionDeclaration"&&i.declaration.id?.name)C(t.componentScope,i.declaration.id.name,{kind:"prop",publicPropName:i.declaration.id.name});break}}}function Ie(e,t){t.componentScope.clear(),t.scopeDeclarations=new WeakMap,t.activeScopes.length=0,Lt(e,t,t.parsed?.instance)}function Ae(e){return{varScopeStack:[e.componentScope]}}function He(e,t,n,r){if(!ue(r))return;let i=Mt(t,r),c=n.varScopeStack[n.varScopeStack.length-1]??t.componentScope;switch(String(r.type)){case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":Ct(r,i);break;case"BlockStatement":kt(e,r.body,i,c);break;case"CatchClause":if("param"in r)for(let p of E(r.param))C(i,p,{kind:"local"});break;case"EachBlock":{let p=r;for(let d of E(p.context))C(i,d,{kind:"local"});if(typeof p.index==="string")C(i,p.index,{kind:"local"});else if(p.index&&"name"in p.index)C(i,p.index.name,{kind:"local"});break}case"ThenBlock":if("value"in r)for(let p of E(r.value))C(i,p,{kind:"local"});break;case"CatchBlock":if("error"in r)for(let p of E(r.error))C(i,p,{kind:"local"});break}if(Re(r))n.varScopeStack.push(i)}function je(e,t){if(Re(t))e.varScopeStack.pop()}var Nt=new Set(["$state","$derived","$effect","$props","$bindable","$inspect","$host"]);function wt(e,t){switch(t?.type){case"MemberExpression":return t.computed||e===t.object;case"MethodDefinition":return!!t.computed;case"MetaProperty":return e===t.meta;case"PropertyDefinition":return t.computed||e===t.value;case"Property":return t.computed||e===t.value;case"ExportSpecifier":case"ImportSpecifier":return e===t.local;case"LabeledStatement":case"BreakStatement":case"ContinueStatement":return!1;default:return!0}}function Rt(e,t){for(let n=t.length-1;n>=0;n-=1)if(t[n]?.has(e))return!0;return!1}function It(e){let t=new Set;if(!e||typeof e!=="object"||!("type"in e))return t;switch(String(e.type)){case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":{let n=e;if(n.id?.name)t.add(n.id.name);for(let r of n.params??[])E(r,t);break}case"BlockStatement":me(e.body,t);break;case"CatchClause":E(e.param,t);break;case"EachBlock":{let n=e;if(E(n.context,t),typeof n.index==="string")t.add(n.index);else if(n.index?.name)t.add(n.index.name);break}case"ThenBlock":E(e.value,t);break;case"CatchBlock":E(e.error,t);break}return t}function me(e,t){if(!Array.isArray(e))return;for(let n of e){if(!n||typeof n!=="object"||!("type"in n))continue;switch(String(n.type)){case"ImportDeclaration":for(let r of n.specifiers??[])if(r.local?.name)t.add(r.local.name);break;case"VariableDeclaration":for(let r of n.declarations??[])E(r.id,t);break;case"FunctionDeclaration":case"ClassDeclaration":{let r=n.id?.name;if(r)t.add(r);break}case"ExportNamedDeclaration":{let r=n.declaration;if(r&&typeof r==="object"&&"type"in r)me([r],t);break}}}}function ve(e,t){if(!e||typeof e!=="object")return!1;let n=[...t],r=!1;return B(e,{enter(i,c){if(r){this.skip();return}if(ue(i))n.push(It(i));if(c&&i.type==="Identifier"&&Nt.has(i.name)&&!c.type.startsWith("TS")&&wt(i,c)&&!Rt(i.name,n))r=!0,this.skip()},leave(i){if(ue(i))n.pop()}}),r}function Fe(e){if(!e||typeof e!=="object")return;if("content"in e){let t=e.content,n=t&&typeof t==="object"&&"body"in t?t.body:void 0;if(Array.isArray(n))return n}if("body"in e&&Array.isArray(e.body))return e.body;return}function Be(e){if(e.runesOptionOverride!==void 0)return e.runesOptionOverride?"runes":"legacy";let t=e.parsed;if(!t)return"legacy";let n=new Set;me(Fe(t.module),n);let r=new Set;return me(Fe(t.instance),r),ve(t.module,[n])||ve(t.instance,[n,r])||ve(t.html,[n,r])?"runes":"legacy"}var At=/[A-Za-z_$][\w$]*/g;function Ht(e,t,n){let r=new Map,i=t.typeParameters?.params,c=n.typeArguments?.params;if(!i?.length||!c?.length)return r;for(let s=0;s<i.length;s++){let p=i[s]?.name,d=c[s];if(!p||d?.start===void 0||d?.end===void 0)continue;let f=J(e,d.start,d.end)?.trim();if(f)r.set(p,f)}return r}function jt(e,t){if(t.size===0)return e;return e.replace(At,(n)=>t.get(n)??n)}function re(e,t,n,r,i=new Set){let c=new Map;if(!n?.type)return c;let s=(p)=>{for(let d of p){if(d?.type!=="TSPropertySignature"||d.computed)continue;if(!d.key)continue;let f=e.getPropertyName(d.key);if(!f)continue;let y=d.typeAnnotation?.start,T=d.typeAnnotation?.end;if(y===void 0||T===void 0)continue;let M=J(t,y+1,T)?.trim();if(!M)continue;c.set(f,{type:M,optional:d.optional===!0,source:N(t,d)})}};switch(n.type){case"TSTypeLiteral":s(n.members??[]);break;case"TSInterfaceDeclaration":s(n.body?.body??[]);break;case"TSTypeAliasDeclaration":{let p=re(e,t,n.typeAnnotation,r,i);for(let[d,f]of p)c.set(d,f);break}case"TSTypeReference":{let p=Ge(n.typeName);if(!p||i.has(p))break;let d=r.get(p);if(!d)break;i.add(p);let f=re(e,t,d,r,i);i.delete(p);let y=Ht(t,d,n);for(let[T,M]of f)c.set(T,y.size===0?M:{...M,type:jt(M.type,y)});break}case"TSIntersectionType":for(let p of n.types??[]){let d=re(e,t,p,r,i);for(let[f,y]of d)c.set(f,y)}break;case"TSParenthesizedType":{let p=re(e,t,n.typeAnnotation,r,i);for(let[d,f]of p)c.set(d,f);break}}return c}function Xe(e,t,n){if(t.runesPropsDeclarationMetadataByDeclaratorStart.clear(),t.explicitPropTypesByName.clear(),t.explicitVariableTypesByName.clear(),t.typeImportBindingsByLocalName.clear(),t.localTypeDeclarationsByName.clear(),t.typedRunesPropsDeclarations.length=0,!t.source)return;let r=n;t.scriptLanguage=e.resolveScriptLanguage(r),t.customElementTag=r.options?.customElement?.tag,t.runesOptionOverride=r.options?.runes,t.scriptGenericsAttribute=e.resolveScriptGenericsAttribute(r);let i=r.instance?.content?.body??[];for(let c of i){if(!c?.type)continue;if(c.type==="ImportDeclaration"&&c.source?.value)for(let s of c.specifiers??[]){let p=s.local?.name;if(!p)continue;if(!(c.importKind==="type"||s.importKind==="type"))continue;let f,y;if(s.type==="ImportSpecifier")f="named",y=s.imported?.type==="Identifier"?s.imported.name:typeof s.imported?.value==="string"?s.imported.value:void 0;else if(s.type==="ImportDefaultSpecifier")f="default";else if(s.type==="ImportNamespaceSpecifier")f="namespace";if(!f)continue;t.typeImportBindingsByLocalName.set(p,{importedName:y,localName:p,source:String(c.source.value),specifierType:f})}if((c.type==="TSInterfaceDeclaration"||c.type==="TSTypeAliasDeclaration")&&c.id?.name&&c.start!==void 0&&c.end!==void 0)t.localTypeDeclarationsByName.set(c.id.name,{code:J(t,c.start,c.end)?.trim()??"",node:c,start:c.start});if(c.type==="ExportNamedDeclaration"&&c.declaration?.type==="VariableDeclaration")for(let s of c.declaration.declarations??[]){if(s.id?.type!=="Identifier"||!s.id.name)continue;let p=fe(t,s.id.typeAnnotation);if(p)t.explicitPropTypesByName.set(s.id.name,p)}else if(c.type==="VariableDeclaration")for(let s of c.declarations??[]){if(s.id?.type!=="Identifier"||!s.id.name)continue;let p=fe(t,s.id.typeAnnotation);if(p)t.explicitVariableTypesByName.set(s.id.name,p)}}for(let c of i){if(!c||typeof c!=="object"||!("declarations"in c))continue;for(let s of c.declarations??[]){if(!_(K(s.init),"$props"))continue;let p=s.id?.typeAnnotation?void 0:_e(s.init),d=s.id?.typeAnnotation?.typeAnnotation??p,f=s.id?.typeAnnotation?fe(t,s.id.typeAnnotation):Ke(t,p),y=re(e,t,d,new Map(Array.from(t.localTypeDeclarationsByName.entries(),([w,A])=>[w,A.node]))),T=new Set,M=new Set;if(Je(t,d,T,M),ze(t,T,M),s.start!==void 0){let w={canonicalType:f,props:y,referencedImportedTypes:T,referencedLocalTypes:M};if(t.runesPropsDeclarationMetadataByDeclaratorStart.set(s.start,w),f)t.typedRunesPropsDeclarations.push(w)}}}}function qe(e,t,n){for(let r of n.declarations){if(!_(K(r.init),"$props"))continue;if(r.id.type==="Identifier"){t.wholePropsLocals.add(r.id.name),t.restPropLocals.add(r.id.name);let s=Oe(t,r.start);if(s)for(let[p,d]of s.props)oe(e,t,p,{name:p,kind:"let",type:d.type,typeSource:"typescript",isFunction:!1,isFunctionDeclaration:!1,isRequired:!d.optional,constant:!1,reactive:!1,source:d.source});continue}if(r.id.type!=="ObjectPattern")continue;let i=z(t,e,n),c=r.id.properties.filter((s)=>{if(s.type!=="Property"||s.computed)return!1;if(!e.getPropertyName(s.key))return!1;if(s.value.type==="Identifier")return!0;return s.value.type==="AssignmentPattern"&&s.value.left.type==="Identifier"}).length;for(let s of r.id.properties){if(s.type==="RestElement"){if(s.argument.type==="Identifier")t.restPropLocals.add(s.argument.name);continue}let p=e.getPropertyName(s.key);if(!p)continue;let d,f;if(s.value.type==="Identifier")d=s.value.name;else{let m=s.value;d=m.left.name,f=m.right}if(!d)continue;if(e.trackPropLocalName(p,d),p==="children")t.snippetPropLocals.add(d);let y=We(t,e,s)??(c===1?i:void 0),T=$e(t,r.start,p),{init:M,bindable:w}=Ve(f),A=M==null?{isFunction:!1}:ie(e,t,M),{value:Q,type:Z,isFunction:ae,defaultValue:be}=A,xe=T?.type===void 0&&y?.type===void 0?A.resolvedType:void 0;if(A.pendingCallDefault)t.pendingCallDefaultCandidates.push({propName:p,location:"props",...A.pendingCallDefault});let{type:he,typeSource:se,description:ce,params:pe,returnType:o,isFunction:a}=ne({explicitType:T?.type,typeSeed:Z,inferredTypeForSource:Z,jsdocType:y?.type,jsdocDescription:y?.description,jsdocParams:y?.params,jsdocReturnType:y?.returnType,resolvedType:xe,resolvedDescription:A.resolvedDescription,resolvedParams:A.resolvedParams,resolvedReturnType:A.resolvedReturnType,initializerIsFunction:ae,isFunctionDeclaration:!1,inferIsFunctionFromTypeSignature:!0});if(w)t.reactive_vars.add(p);oe(e,t,p,{name:p,...d===p?{}:{localName:d},kind:"let",description:ce,binding:y?.binding,deprecated:y?.deprecated,tags:y?.tags,...w?{bindable:!0}:{},type:he,typeSource:se,value:Q,defaultValue:be,params:pe,returnType:o,isFunction:a,isFunctionDeclaration:!1,isRequired:M==null&&T?.optional!==!0,constant:!1,reactive:w,source:N(t,s)})}}}function Ue(e,t){if(e.syntaxMode!=="runes")return;for(let[n,r]of Array.from(e.events.entries())){if(r.type!=="dispatched")continue;if(t.has(n)||e.forwardedEvents.has(n))continue;let i=`on${n}`,c=e.props.get(i);if(!c)continue;let s=c.type!==void 0||c.params!==void 0||c.returnType!==void 0,p=r.detail===void 0||r.detail==="undefined"||r.detail==="null"?"() => void":`(detail: ${r.detail}) => void`;e.props.set(i,{...c,description:c.description??r.description,type:s?c.type:p,typeSource:s?c.typeSource:"inferred",isFunction:!0}),e.events.delete(n)}}var Ye=new Set(["TSAsExpression","TSSatisfiesExpression","TSNonNullExpression","TSTypeAssertion","TSInstantiationExpression"]);function ye(e){if(!e||typeof e!=="object")return;B(e,{enter(t){if(!Ye.has(t.type))return;let n=t.expression;while(n&&Ye.has(n.type))n=n.expression;if(n)this.replace(n)}})}function ge(e,t){let n=t.source?.value;if(typeof n!=="string"||t.importKind==="type")return;for(let r of t.specifiers??[]){if(r.type!=="ImportSpecifier"||r.importKind==="type")continue;let i=r.local?.name;if(!i)continue;let c=r.imported?.name??(typeof r.imported?.value==="string"?r.imported.value:i);e.valueImportBindingsByLocalName.set(i,{localName:i,importedName:c,source:n})}}function Me(e,t){if(!t)return;B(t,{enter(n){if(n.type==="ImportDeclaration")ge(e,n);if(n.type==="FunctionDeclaration"){let r=n;if(r.id?.name)e.funcDecls.set(r.id.name,r)}}})}function nt(e,t,n){let r=t+1;while(r<e.length){if(e[r]==="\\"){r+=2;continue}if(e[r]===n)return r+1;r++}return r}function rt(e,t){let n=t+1,r=0;while(n<e.length){let i=e[n];if(i==="\\"){n+=2;continue}if(r===0){if(i==="`")return n+1;if(i==="$"&&e[n+1]==="{"){r=1,n+=2;continue}n++;continue}if(i==="{")r++;else if(i==="}")r--;else if(i==='"'||i==="'"){n=nt(e,n,i);continue}else if(i==="`"){n=rt(e,n);continue}n++}return n}function Ft(e,t){let n=[],r=e.length,i=0;while(i<r){let c=e[i];if(c==='"'||c==="'"){i=nt(e,i,c);continue}if(c==="`"){i=rt(e,i);continue}if(c==="/"&&e[i+1]==="/"){let s=i+2;while(s<r&&e[s]!==`
|
|
2
|
+
`)s++;i=s;continue}if(c==="/"&&e[i+1]==="*"){let s=i,p=i+2;while(p<r&&!(e[p]==="*"&&e[p+1]==="/"))p++;let d=Math.min(p+2,r),f=e.slice(s,d);n.push({end:d+t,isJsDoc:f.startsWith("/**")&&f.length>4,text:f}),i=d;continue}i++}return n}function Qe(e,t,n){if(!e||typeof e!=="object"||!("type"in e))return;let r=e;if(r.type==="FunctionDeclaration"){if(r.id?.type==="Identifier"&&r.id.name)n.push({name:r.id.name,start:t});return}if(r.type==="VariableDeclaration"){for(let i of r.declarations??[])if(i?.id?.type==="Identifier"&&i.id.name)n.push({name:i.id.name,start:t})}}function Bt(e){let t=[];for(let n of e){if(!n||typeof n!=="object"||!("type"in n))continue;let r=n;if(r.start===void 0)continue;if(r.type==="ExportNamedDeclaration"&&r.declaration)Qe(r.declaration,r.start,t);else Qe(r,r.start,t)}return t}function _t(e,t,n){let r;for(let i of e){if(i.end>t)break;if(!i.isJsDoc)continue;if(!et.test(n.slice(i.end,t)))continue;r=i}return r}function ot(e,t){let n=new Map;if(!e.source)return n;let r=[e.parsed?.module,e.parsed?.instance],i=[],c=[];for(let s of r){let p=s?.content;if(!p?.body||p.start===void 0||p.end===void 0)continue;i.push(...Ft(e.source.slice(p.start,p.end),p.start)),c.push(...Bt(p.body))}i.sort((s,p)=>s.end-p.end);for(let s of c){let p=_t(i,s.start,e.source);if(!p)continue;let d=Ze(p.text),{type:f,description:y}=tt(d);if(!f)continue;n.set(s.name,{type:t.aliasType(f.type),description:y||f.description})}return n}function it(e){if(e==="var")return"let";if(e==="using"||e==="await using")return"const";return e}var Vt=null,at=/^@component/,Ot=/\r/g,$t=/^\{\s*\}$/;class k{ctx=Se();static mapToArray(e){return Array.from(e,([t,n])=>n)}static getStaticAttributeValue(e){if(!Array.isArray(e.value))return;return e.value.map((t)=>t.data??t.raw??"").join("").trim()}resolveScriptLanguage(e){let t=[e.instance,e.module].filter((r)=>r!==void 0),n=!1;for(let r of t){let i=r.attributes?.find((s)=>s.name==="lang");if(!i){n=!0;continue}if(k.getStaticAttributeValue(i)?.toLowerCase()==="ts")return"ts"}return n?"js":void 0}resolveScriptGenericsAttribute(e){let t=e.instance?.attributes?.find((s)=>s.name==="generics");if(!t)return;let n=N(this.ctx,t),r=e.instance?.attributes?.find((s)=>s.name==="lang");if((r?k.getStaticAttributeValue(r)?.toLowerCase():void 0)!=="ts"){Y(this.ctx,"syntax-skipped","generics",'<script generics="..."> requires lang="ts"; the generics attribute was ignored because the script is not TypeScript.',n);return}let c=k.getStaticAttributeValue(t);if(!c)return;return{value:c,source:n}}resolvePublicPropName(e){return this.ctx.propLocalToPublicName.get(e)??e}trackPropLocalName(e,t=e){this.ctx.propLocalToPublicName.set(t,e)}getPropByLocalOrPublic(e){return this.ctx.props.get(this.resolvePublicPropName(e))}getPropTypeByLocalOrPublic(e){return this.getPropByLocalOrPublic(e)?.type}getExplicitPropType(e){return this.ctx.explicitPropTypesByName.get(e)}getPropertyName(e){if(!e||typeof e!=="object"||!("type"in e))return;if(Te(e))return e.name;if(st(e))return e.value==null?void 0:String(e.value);return}isNumericConstant(e){if(!e||typeof e!=="object"||!("type"in e))return!1;if(e.type!=="MemberExpression")return!1;let t=e,n=t.object&&"name"in t.object?t.object.name:void 0,r=t.property&&"name"in t.property?t.property.name:void 0;if(!n||!r)return!1;if(n==="Number")return["POSITIVE_INFINITY","NEGATIVE_INFINITY","MAX_VALUE","MIN_VALUE","MAX_SAFE_INTEGER","MIN_SAFE_INTEGER","EPSILON","NaN"].includes(r);if(n==="Math")return["PI","E","LN2","LN10","LOG2E","LOG10E","SQRT2","SQRT1_2"].includes(r);return!1}resolveLocalVarJSDoc(e){for(let n of this.ctx.vars)if(n.declarations.some((i)=>i.id&&typeof i.id==="object"&&("type"in i.id)&&i.id.type==="Identifier"&&("name"in i.id)&&i.id.name===e))return z(this.ctx,this,n);let t=this.ctx.funcDecls.get(e);if(t)return z(this.ctx,this,t);return}addModuleExport(e,t){if(dt(e)===void 0)return;if(this.ctx.moduleExports.has(e)){let n=this.ctx.moduleExports.get(e);this.ctx.moduleExports.set(e,{...n,...t})}else this.ctx.moduleExports.set(e,t)}aliasType(e){if(e==="*")return"any";return e.trim()}findVariableTypeAndDescription(e){let t=this.getPropByLocalOrPublic(e);if(t?.type)return{type:t.type,description:t.description};if(!this.ctx.variableInfoCacheBuilt)this.ctx.variableInfoCache=ot(this.ctx,this),this.ctx.variableInfoCacheBuilt=!0;let n=this.ctx.variableInfoCache.get(e),r=this.ctx.explicitVariableTypesByName.get(e);if(r)return{type:r,description:n?.description};return n??null}accumulateGeneric(e,t){if(this.ctx.generics)this.ctx.generics=[`${this.ctx.generics[0]}, ${e}`,`${this.ctx.generics[1]}, ${t}`];else this.ctx.generics=[e,t]}cleanup(){this.ctx=Se()}static SCRIPT_BLOCK_REGEX=/(<script[^>]*>)([\s\S]*?)(<\/script>)/gi;static TS_DIRECTIVE_REGEX=/\/\/\s*@ts-[^\n\r]*/g;static stripTypeScriptDirectivesFromScripts(e){return k.SCRIPT_BLOCK_REGEX.lastIndex=0,e.replace(k.SCRIPT_BLOCK_REGEX,(t,n,r,i)=>{k.TS_DIRECTIVE_REGEX.lastIndex=0;let c=r.replace(k.TS_DIRECTIVE_REGEX,"");return n+c+i})}parseSvelteComponent(e,t){this.cleanup(),this.ctx.componentFilePath=t.filePath;let n=k.stripTypeScriptDirectivesFromScripts(e);this.ctx.source=n;let{modern:r,intoLegacy:i}=St(n);if(Xe(this,this.ctx,r),this.ctx.parsed=i(),this.ctx.scriptLanguage==="ts")ye(this.ctx.parsed.module),ye(this.ctx.parsed.instance),ye(this.ctx.parsed.html);this.ctx.syntaxMode=Be(this.ctx);let c=this.ctx.parsed.css,s=c?.start!==void 0&&c?.end!==void 0?n.slice(0,c.start)+" ".repeat(c.end-c.start)+n.slice(c.end):n;ht(this.ctx,this,s);let p={type:"ComponentRoot",instance:this.ctx.parsed.instance,html:this.ctx.parsed.html};if(Me(this.ctx,this.ctx.parsed?.module),Me(this.ctx,this.ctx.parsed?.instance),this.ctx.parsed?.module)B(this.ctx.parsed?.module,{enter:(o)=>{if(o.type==="ImportDeclaration")ge(this.ctx,o);if(o.type==="FunctionDeclaration"){let a=o;if(a.id?.name)this.ctx.funcDecls.set(a.id.name,a)}if(o.type==="VariableDeclaration")this.ctx.vars.add(o);if(o.type==="ExportNamedDeclaration"){if(o.declaration==null)return;if(!o.declaration||typeof o.declaration!=="object"||!("type"in o.declaration))return;let a,m,b=!1,l,u,x,S=!1,g,D,h;if(o.declaration.type==="FunctionDeclaration"){let H=o.declaration;if(!H.id?.name)return;a=H.id.name,m="function",l=void 0,u="() => any",S=!0,b=!0}else if(o.declaration.type==="VariableDeclaration"){let H=o.declaration,X=H.declarations[0];if(!X||typeof X!=="object"||!("id"in X))return;let{id:q,init:le}=X;if(!q||typeof q!=="object"||!("name"in q))return;let ee=q.name;a=ee,m=it(H.kind);let v=le==null?{isFunction:!1}:ie(this,this.ctx,le);if({value:l,type:u,isFunction:S,defaultValue:g}=v,D=u,h=v,x=this.getExplicitPropType(ee),h.pendingCallDefault)this.ctx.pendingCallDefaultCandidates.push({propName:ee,location:"moduleExports",...h.pendingCallDefault})}else return;let L=z(this.ctx,this,o),{type:j,typeSource:V,description:P,params:R,returnType:I,isFunction:W}=ne({explicitType:x,typeSeed:u,inferredTypeForSource:D,jsdocType:L?.type,jsdocDescription:L?.description,jsdocParams:L?.params,jsdocReturnType:L?.returnType,resolvedType:h?.resolvedType,resolvedDescription:h?.resolvedDescription,resolvedParams:h?.resolvedParams,resolvedReturnType:h?.resolvedReturnType,initializerIsFunction:S,isFunctionDeclaration:b,typedefs:this.ctx.typedefs});this.addModuleExport(a,{name:a,kind:m,description:P,deprecated:L?.deprecated,tags:L?.tags,type:j,typeSource:V,value:l,defaultValue:g,params:R,returnType:I,isFunction:W,isFunctionDeclaration:b,isRequired:!1,constant:m==="const",reactive:!1,source:N(this.ctx,o)})}}});let d,f=new Set,y=new Set,T=[];Ie(this,this.ctx),this.ctx.activeScopes.push(this.ctx.componentScope);let M=Ae(this.ctx);if(B(p,{enter:(o,a,m)=>{He(this,this.ctx,M,o);let b=this.ctx.scopeDeclarations.get(o);if(b)this.ctx.activeScopes.push(b);if(o.type==="AssignmentExpression")Ee(this.ctx,o.left);if(o.type==="UpdateExpression")Ee(this.ctx,o.argument);if(o.type==="CallExpression"){let l=o,u=l.callee&&typeof l.callee==="object"&&"name"in l.callee?l.callee.name:void 0;if(u==="createEventDispatcher"){if(a&&typeof a==="object"&&"id"in a&&a.id&&typeof a.id==="object"&&"name"in a.id)d=a.id.name}if(u==="$host"){if(a&&typeof a==="object"&&"id"in a&&a.id&&typeof a.id==="object"&&"name"in a.id)f.add(a.id.name)}if(u==="setContext")ut(this.ctx,this,o,a??void 0);if(u)T.push({name:u,arguments:l.arguments,source:N(this.ctx,l)});if(ct(l.callee)&&Te(l.callee.property)&&l.callee.property.name==="dispatchEvent"&&(_(l.callee.object,"$host")||Te(l.callee.object)&&f.has(l.callee.object.name))){let x=yt(this.ctx,l);if(x)y.add(x)}}if(o&&typeof o==="object"&&"type"in o&&String(o.type)==="Spread"){let l=o;if(l.expression?.name==="$$restProps"||this.ctx.restPropLocals.has(l.expression?.name??""))Ne(this.ctx,a)}if(o.type==="FunctionDeclaration"){let l=o;if(l.id?.name)this.ctx.funcDecls.set(l.id.name,l)}if(o.type==="ImportDeclaration")ge(this.ctx,o);if(o.type==="VariableDeclaration"){if(this.ctx.vars.add(o),a&&typeof a==="object"&&"type"in a&&a.type==="Program"&&o.declarations.some((l)=>_(K(l.init),"$props")))qe(this,this.ctx,o)}if(o.type==="ExportNamedDeclaration"){if(o.declaration==null&&o.specifiers.length===0)return;let l;if(o.declaration==null&&o.specifiers[0]?.type==="ExportSpecifier"){let v=o.specifiers[0],O=v.local&&typeof v.local==="object"&&"name"in v.local?v.local.name:void 0,G=v.exported&&typeof v.exported==="object"&&"name"in v.exported?v.exported.name:void 0;if(!O||!G)return;let U;for(let te of Array.from(this.ctx.vars))if(te.declarations.some((F)=>F.id&&typeof F.id==="object"&&("type"in F.id)&&F.id.type==="Identifier"&&F.id.name===O)){U=te;break}o.declaration=U,l=G}if(o.declaration==null)return;if(!o.declaration||typeof o.declaration!=="object"||!("type"in o.declaration))return;let u,x=!1,S,g,D,h=!1,L=!1,j,V,P,R;if(o.declaration.type==="FunctionDeclaration"){let v=o.declaration;if(!v.id?.name)return;l??=v.id.name,j=v.id.name,u="function",S=void 0,g="() => any",h=!0,x=!0,L=!1}else if(o.declaration.type==="VariableDeclaration"){let v=o.declaration,O=v.declarations[0];if(!O||typeof O!=="object"||!("id"in O))return;let{id:G,init:U}=O;if(G&&typeof G==="object"&&"name"in G){let F=G.name;j=F,l??=F,D=this.getExplicitPropType(F)}else return;u=it(v.kind),L=u==="let"&&U==null;let te=U==null?{isFunction:!1}:ie(this,this.ctx,U);if({value:S,type:g,isFunction:h,defaultValue:V}=te,P=g,R=te,R.pendingCallDefault)this.ctx.pendingCallDefaultCandidates.push({propName:l,location:"props",...R.pendingCallDefault})}else return;let I=z(this.ctx,this,o),{type:W,typeSource:H,description:X,params:q,returnType:le,isFunction:ee}=ne({explicitType:D,typeSeed:g,inferredTypeForSource:P,jsdocType:I?.type,jsdocDescription:I?.description,jsdocParams:I?.params,jsdocReturnType:I?.returnType,resolvedType:R?.resolvedType,resolvedDescription:R?.resolvedDescription,resolvedParams:R?.resolvedParams,resolvedReturnType:R?.resolvedReturnType,initializerIsFunction:h,isFunctionDeclaration:x,typedefs:this.ctx.typedefs});oe(this,this.ctx,l,{name:l,...j!==void 0&&j!==l?{localName:j}:{},kind:u,description:X,binding:I?.binding,deprecated:I?.deprecated,tags:I?.tags,type:W,typeSource:H,value:S,defaultValue:V,params:q,returnType:le,isFunction:ee,isFunctionDeclaration:x,isRequired:L,constant:u==="const",reactive:this.ctx.reactive_vars.has(l),source:N(this.ctx,o)})}if(o&&typeof o==="object"&&"type"in o&&String(o.type)==="Comment"){let u=o?.data?.trim()??"";if(at.test(u))this.ctx.componentComment=u.replace(at,"").replace(Ot,""),this.ctx.componentCommentSource=N(this.ctx,o)}if(o&&typeof o==="object"&&"type"in o&&String(o.type)==="Slot"){let l=o,u=l.attributes?.find((g)=>g.name==="name")?.value?.[0]?.data,x=(l.attributes||[]).filter((g)=>g.name!=="name").reduce((g,D)=>{let h={value:void 0,replace:!1},L=D.value;if(L===void 0)return g;if(L[0]){let j=L[0],{type:V,expression:P,raw:R,start:I,end:W}=j;if(V==="Text"&&R!==void 0)h.value=JSON.stringify(R);else if(V==="AttributeShorthand"&&P&&typeof P==="object"&&"name"in P)h.value=P.name,h.replace=!0;if(P&&typeof P==="object"&&"type"in P){if(P.type==="Literal"&&"value"in P){let H=P.value;h.value=typeof H==="string"?JSON.stringify(H):String(H)}else if(P.type==="MemberExpression")h.value=pt(this.ctx,this,P);else if(P.type!=="Identifier"){if(I!==void 0&&W!==void 0){if(P.type==="ObjectExpression"||P.type==="TemplateLiteral")h.value=J(this.ctx,I+1,W-1)}}}}if(D.name)g[D.name]=h;return g},{}),S=l.children?.map(({start:g,end:D})=>{if(g===void 0||D===void 0)return"";return J(this.ctx,g,D)??""}).join("").trim();De(this.ctx,{slot_name:u,slot_props:x,slot_fallback:S,source:N(this.ctx,o)})}if(o&&typeof o==="object"&&"type"in o&&String(o.type)==="RenderTag"){let l=o,u=xt(this.ctx,l.expression);if(u){let x;if(u.arguments.length===0)x={};else if(u.arguments.length===1&&typeof u.arguments[0]==="object"&&u.arguments[0]&&"type"in u.arguments[0]&&u.arguments[0].type==="ObjectExpression")x=bt(this.ctx,this,u.arguments[0]);else if(u.arguments.length===1)Y(this.ctx,"syntax-skipped",u.publicName,`{@render ${u.publicName}(...)} argument is not a plain object literal; the render call was not mapped to slot metadata.`,N(this.ctx,o));let S=u.publicName==="children"?void 0:u.publicName,g=S===void 0?Vt:S;if(x!==void 0)De(this.ctx,{slot_name:S,slot_props:x,source:N(this.ctx,o)});if(x!==void 0||this.ctx.slots.has(g))this.ctx.snippetPropLocals.add(u.trackingName)}}if(o&&typeof o==="object"&&"type"in o&&String(o.type)==="EventHandler"){let l=o;if(l.expression==null&&l.name){if(a!=null&&typeof a==="object"&&"name"in a){let u=typeof a.name==="string"?a.name:void 0,x="type"in a?String(a.type):void 0;if(u&&x){let S=x==="InlineComponent"?{type:"InlineComponent",name:u}:{type:"Element",name:u};this.ctx.forwardedEvents.set(l.name,S);let g=this.ctx.events.get(l.name),D=this.ctx.eventDescriptions.get(l.name),h=g?.deprecated;if(!g)this.ctx.events.set(l.name,{type:"forwarded",name:l.name,element:S,description:D,deprecated:h,source:N(this.ctx,o)});else if(g.type==="forwarded"&&D&&!g.description)this.ctx.events.set(l.name,{...g,description:D,deprecated:g.deprecated??h,source:g.source||N(this.ctx,o)})}}}}if(a&&typeof a==="object"&&"type"in a&&(String(a.type)==="Element"||String(a.type)==="InlineComponent")&&o&&typeof o==="object"&&"type"in o&&String(o.type)==="Binding"){let l=o;if(l.expression?.name){let u=de(this.ctx,l.expression.name);if(u)this.ctx.reactive_vars.add(u)}if(String(a.type)==="Element"&&l.name==="this"&&l.expression?.name&&"name"in a&&typeof a.name==="string"){let u=de(this.ctx,l.expression.name);if(!u)return;let x=a.name;if(this.ctx.bindings.has(u)){let S=this.ctx.bindings.get(u);if(S&&!S.elements.includes(x))this.ctx.bindings.set(u,{...S,elements:[...S.elements,x]})}else this.ctx.bindings.set(u,{elements:[x]})}}},leave:(o)=>{if(this.ctx.scopeDeclarations.has(o))this.ctx.activeScopes.pop();je(M,o)}}),d!==void 0){for(let o of T)if(o.name===d){let a=o.arguments[0],m=a&&typeof a==="object"&&"value"in a?a.value:void 0,b=o.arguments[1],l=b&&typeof b==="object"&&"value"in b?b.value:void 0;if(m!=null)ft(this.ctx,{name:String(m),detail:l==null?"":mt(l),has_argument:Boolean(b),source:o.source})}}let w=new Set(y);if(d!==void 0){for(let o of T)if(o.name===d){let a=o.arguments[0],m=a&&typeof a==="object"&&"value"in a?a.value:void 0;if(m!=null)w.add(String(m))}}this.ctx.forwardedEvents.forEach((o,a)=>{let m=this.ctx.events.get(a);if(m&&m.type==="dispatched"&&!w.has(a)){let b=this.ctx.eventDescriptions.get(a),l={type:"forwarded",name:a,element:o,description:b,deprecated:m.deprecated,tags:m.tags,source:m.source};if(m.detail!==void 0&&m.detail!=="undefined")l.detail=m.detail;this.ctx.events.set(a,l)}}),Ue(this.ctx,w);let A=this.ctx.syntaxMode==="runes"?new Set(Array.from(this.ctx.snippetPropLocals,(o)=>this.resolvePublicPropName(o))):new Set,Q=k.mapToArray(this.ctx.props).filter((o)=>!A.has(o.name)).map((o)=>{if(this.ctx.bindings.has(o.name)){let a=this.ctx.bindings.get(o.name)?.elements.sort().map((m)=>Le(m)).join(" | ");return{...o,type:`null | ${a}`,typeSource:"inferred",reactive:o.reactive||this.ctx.reactive_vars.has(o.name)}}return{...o,reactive:o.reactive||this.ctx.reactive_vars.has(o.name)}});this.ctx.activeScopes.length=0;let Z=k.mapToArray(this.ctx.slots).map((o)=>{if(!o.slot_props)return o;if(typeof o.slot_props==="string")return $t.test(o.slot_props)?{...o,slot_props:"Record<string, never>"}:o;let a=o.slot_props,m=[];for(let l of Object.keys(a)){if(a[l].replace&&a[l].value!==void 0)a[l].value=this.getPropTypeByLocalOrPublic(a[l].value);if(a[l].value===void 0)a[l].value="any";m.push(`${l}: ${a[l].value}`)}let b=m.length===0?"Record<string, never>":m.length===1?`{ ${m[0]} }`:`{
|
|
3
|
+
${m.join(`;
|
|
4
|
+
`)};
|
|
5
|
+
}`;return{...o,slot_props:b}}).sort((o,a)=>{let m=o.name??"",b=a.name??"";if(m<b)return-1;if(m>b)return 1;return 0});if(this.ctx.deferredSlotBlockGenerics.length>0){let o=[...Q.map((a)=>a.type??""),...Z.map((a)=>a.slot_props??"")].join(`
|
|
6
|
+
`);for(let{name:a,constraint:m}of this.ctx.deferredSlotBlockGenerics){let b=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");if(!new RegExp(`\\b${b}\\b`).test(o))continue;this.accumulateGeneric(a,m)}}if(this.ctx.scriptGenericsAttribute){if(this.ctx.generics)Y(this.ctx,"syntax-skipped","generics",'Both the "generics" script attribute and @generics/@template JSDoc tags declare component generics; the script attribute takes precedence and the JSDoc declaration was ignored.',this.ctx.scriptGenericsAttribute.source);this.ctx.generics=Tt(this.ctx.scriptGenericsAttribute.value)}let ae=k.mapToArray(this.ctx.moduleExports),be=k.mapToArray(this.ctx.events).map((o)=>{switch(o.type){case"forwarded":return{...o,element:o.element.name};case"dispatched":return o;default:return o}}).sort((o,a)=>{let m=o.name.localeCompare(a.name);if(m!==0)return m;let b=o.type.localeCompare(a.type);if(b!==0)return b;if(o.type==="forwarded"&&a.type==="forwarded"){let l=o.element.localeCompare(a.element);if(l!==0)return l}return(o.detail??"").localeCompare(a.detail??"")}),xe=k.mapToArray(this.ctx.typedefs),he=k.mapToArray(this.ctx.contexts),se={props:new Map(this.ctx.pendingCallDefaultCandidates.filter((o)=>o.location==="props").map((o)=>[o.propName,o])),moduleExports:new Map(this.ctx.pendingCallDefaultCandidates.filter((o)=>o.location==="moduleExports").map((o)=>[o.propName,o]))};for(let o of Q)if(o.typeSource==="unknown"){let a=se.props.get(o.name);if(a)o.type="any";let m=a?a.importSource?`Prop "${o.name}" default calls "${a.calleeName}()" imported from "${a.importSource}"; falling back to "any" pending cross-file resolution.`:`Prop "${o.name}" default calls "${a.calleeName}()", but its return type could not be inferred; falling back to "any".`:`Prop "${o.name}" type could not be inferred; falling back to "${o.type??"any"}".`;Y(this.ctx,"prop-unknown-type",o.name,m,o.source)}for(let o of ae)if(o.typeSource==="unknown"&&se.moduleExports.has(o.name))o.type="any";for(let o of this.ctx.jsDocEventNames){if(w.has(o))continue;if(this.ctx.forwardedEvents.has(o))continue;if(this.ctx.props.has(`on${o}`))continue;Y(this.ctx,"event-no-source",o,`@event "${o}" has no matching dispatch or callback prop.`,this.ctx.jsDocEventSources.get(o))}let ce={source:lt(this.ctx,0,this.ctx.source?.length),syntaxMode:this.ctx.syntaxMode,...this.ctx.scriptLanguage?{scriptLanguage:this.ctx.scriptLanguage}:{},props:Q,moduleExports:ae,slots:Z,events:be,typedefs:xe,generics:this.ctx.generics,rest_props:this.ctx.rest_props,extends:this.ctx.extends,componentComment:this.ctx.componentComment,componentCommentSource:this.ctx.componentCommentSource,contexts:he,customElementTag:this.ctx.customElementTag,diagnostics:this.ctx.diagnosticRecords.slice()},pe=gt(this.ctx);if(pe)ce[Ce]=pe;return ce}}
|
|
7
|
+
export{k as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as d}from"./chunk-cqkng6ys.js";import{E as a,F as b,G as c}from"./chunk-yzabyfqs.js";import"./chunk-0beysrt7.js";import"./chunk-nrz6c5ew.js";import"./chunk-ptdfswsv.js";export{a as PARSED_COMPONENT_TYPE_SCRIPT_METADATA,c as applyResolvedProps,d as default,b as getParsedComponentTypeScriptMetadata};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import{D as ln,E as Ke,F as te,G as Sn,Q as bn,aa as Un,ia as un,v as K,y as cn}from"./chunk-yzabyfqs.js";import{sa as hn}from"./chunk-nrz6c5ew.js";import{ua as B,va as T,wa as Oe,xa as W}from"./chunk-syz2wqmb.js";import{Ba as Ze}from"./chunk-ptdfswsv.js";var At="sveld",xe="0.36.9";var Rt={name:At,version:xe,license:"Apache-2.0",description:"Generate TypeScript definitions and component documentation for your Svelte components.",type:"module",main:"./lib/index.js",types:"./lib/index.d.ts",exports:{".":{types:"./lib/index.d.ts",import:"./lib/index.js",default:"./lib/index.js"},"./browser":{types:"./lib/browser.d.ts",import:"./lib/browser.js",default:"./lib/browser.js"}},scripts:{test:"bun test --parallel","test:fixtures-types":"tsc --project tsconfig.fixtures.json","test:e2e":"bun tests/test-e2e.ts",format:"biome format --write .",lint:"biome lint .","lint:fix":"biome check --write --unsafe .",build:"bun scripts/build.ts",bench:"bun scripts/bench.ts","bench:cache":"bun scripts/bench.ts --cache","bench:mitata":"bun scripts/bench-mitata.ts",fuzz:"bun scripts/fuzz-parser.ts",typecheck:"tsc --noEmit"},devDependencies:{"@biomejs/biome":"2.5.10","@types/bun":"^1.3.14","@types/jest":"^30.0.0","@typescript/typescript6":"^6.0.2",acorn:"^8.18.0",culls:"^0.2.0","estree-walker":"^3.0.3",mitata:"^1.0.34",svelte:"^5.56.9",typescript:"^7.0.2"},bin:{sveld:"cli.js"},files:["lib","cli.js"],repository:{type:"git",url:"git+https://github.com/carbon-design-system/sveld.git"},homepage:"https://github.com/carbon-design-system/sveld",bugs:"https://github.com/carbon-design-system/sveld/issues",keywords:["svelte","svelte component","documentation","docgen","typescript","definitions","JSDocs","vite","vite-plugin"],maintainers:["Eric Liu (https://github.com/metonym)"]};var re="5.56.9";var Ce=1,Nt=new WeakMap;function j(e,t={}){let n=Nt.get(e),o=n?.get(t.entryExports);if(o)return o;let r=Array.from(e,([,i])=>{let{diagnostics:a,...p}=i;return p}).sort((i,a)=>i.moduleName.localeCompare(a.moduleName)),s={schemaVersion:Ce,generator:{name:At,version:xe,svelteVersion:re},total:r.length,components:r};if(t.entryExports&&t.entryExports.length>0)s.totalExports=t.entryExports.length,s.exports=t.entryExports;if(!n)n=new Map,Nt.set(e,n);return n.set(t.entryExports,s),s}import{readFile as Co}from"node:fs/promises";import Eo from"node:path";var Ot={none:0,patch:1,minor:2,major:3};function vo(e,t){return Ot[t]>Ot[e]?t:e}function So(e){return e.reduce((t,n)=>vo(t,n.bump),"none")}function _t(e){let t=[],n=0,o="",r=null;for(let s=0;s<e.length;s++){let i=e[s];if(r){if(o+=i,i==="\\")s++,o+=e[s]??"";else if(i===r)r=null;continue}if(i==='"'||i==="'"||i==="`"){r=i,o+=i;continue}if(i==="<"||i==="("||i==="{"||i==="[")n++;if(i===">"||i===")"||i==="}"||i==="]")n--;if(i==="|"&&n===0){t.push(o.trim()),o="";continue}o+=i}return t.push(o.trim()),new Set(t.filter((s)=>s.length>0))}function Ue(e,t){if(e===t)return"none";if(e===void 0||t===void 0)return"major";let n=_t(e),o=_t(t),r=[...o].some((i)=>!n.has(i)),s=[...n].some((i)=>!o.has(i));if(!r&&!s)return"none";if(r&&!s)return"minor";if(s&&!r)return"major";return"major"}function jt(e,t,n,o){let r=t==="prop"?"prop":"export",s=[],i=new Map(n.map((p)=>[p.name,p])),a=new Map(o.map((p)=>[p.name,p]));for(let[p,c]of a){if(i.has(p))continue;s.push({component:e,kind:t,name:p,bump:c.isRequired?"major":"minor",message:`${r} "${p}" added${c.isRequired?" (required)":""}`})}for(let[p]of i){if(a.has(p))continue;s.push({component:e,kind:t,name:p,bump:"major",message:`${r} "${p}" removed`})}for(let[p,c]of i){let l=a.get(p);if(!l)continue;if(c.isRequired!==l.isRequired)s.push({component:e,kind:t,name:p,bump:l.isRequired?"major":"minor",message:`${r} "${p}" became ${l.isRequired?"required":"optional"}`});let d=Ue(c.type,l.type);if(d!=="none")s.push({component:e,kind:t,name:p,bump:d,message:`${r} "${p}" type changed from \`${c.type??"unknown"}\` to \`${l.type??"unknown"}\``})}return s}function bo(e,t,n){let o=[],r=new Map(t.map((i)=>[i.name,i])),s=new Map(n.map((i)=>[i.name,i]));for(let[i]of s){if(r.has(i))continue;o.push({component:e,kind:"event",name:i,bump:"minor",message:`event "${i}" added`})}for(let[i]of r){if(s.has(i))continue;o.push({component:e,kind:"event",name:i,bump:"major",message:`event "${i}" removed`})}for(let[i,a]of r){let p=s.get(i);if(!p)continue;if(a.type!==p.type){o.push({component:e,kind:"event",name:i,bump:"major",message:`event "${i}" changed from ${a.type} to ${p.type}`});continue}let c=a.type==="dispatched"?a.detail:void 0,l=p.type==="dispatched"?p.detail:void 0,d=Ue(c,l);if(d!=="none")o.push({component:e,kind:"event",name:i,bump:d,message:`event "${i}" detail changed from \`${c??"unknown"}\` to \`${l??"unknown"}\``})}return o}function Mt(e){return e.name??"default"}function Po(e,t,n){let o=[],r=new Map(t.map((i)=>[Mt(i),i])),s=new Map(n.map((i)=>[Mt(i),i]));for(let[i]of s){if(r.has(i))continue;o.push({component:e,kind:"slot",name:i,bump:"minor",message:`slot "${i}" added`})}for(let[i]of r){if(s.has(i))continue;o.push({component:e,kind:"slot",name:i,bump:"major",message:`slot "${i}" removed`})}for(let[i,a]of r){let p=s.get(i);if(!p)continue;let c=Ue(a.slot_props,p.slot_props);if(c!=="none")o.push({component:e,kind:"slot",name:i,bump:c,message:`slot "${i}" props changed from \`${a.slot_props??"none"}\` to \`${p.slot_props??"none"}\``})}return o}var $o=new Set(["description","source","componentCommentSource","tags"]);function Ee(e){if(Array.isArray(e))return e.map(Ee);if(e!==null&&typeof e==="object"){let t={};for(let[n,o]of Object.entries(e)){if($o.has(n))continue;t[n]=Ee(o)}return t}return e}var ko=["generics","rest_props","extends","contexts","typedefs"];function Do(e,t,n){let o=[];for(let r of ko){let s=JSON.stringify(Ee(t[r])),i=JSON.stringify(Ee(n[r]));if(s!==i)o.push({component:e,kind:"shape",name:r,bump:"major",message:`"${r}" changed (breaking)`})}return o}function wo(e,t){let n=t.moduleName;return[...jt(n,"prop",e.props,t.props),...jt(n,"moduleExport",e.moduleExports,t.moduleExports),...bo(n,e.events,t.events),...Po(n,e.slots,t.slots),...Do(n,e,t)]}function To(e,t){let n=[],o=new Map(e.components.map((s)=>[s.moduleName,s])),r=new Map(t.components.map((s)=>[s.moduleName,s]));for(let[s]of r){if(o.has(s))continue;n.push({component:s,kind:"component",bump:"minor",message:`component "${s}" added`})}for(let[s]of o){if(r.has(s))continue;n.push({component:s,kind:"component",bump:"major",message:`component "${s}" removed`})}for(let[s,i]of o){let a=r.get(s);if(!a)continue;n.push(...wo(i,a))}return n}async function Ao(e){let t;try{t=await Co(Eo.resolve(e),"utf-8")}catch(n){if(n.code==="ENOENT")return null;throw n}try{return JSON.parse(t)}catch{throw Error(`sveld: could not parse "${e}" as JSON. Is it a sveld COMPONENT_API.json snapshot?`)}}function Ft(e){if(typeof e.check==="string")return e.check;return e.jsonOptions?.outFile??"COMPONENT_API.json"}async function It(e,t,n={}){let o=await Ao(t);if(o===null)return{snapshotExists:!1,snapshotFile:t,changes:[],bump:"none"};if(o.schemaVersion!==Ce)return{snapshotExists:!0,snapshotFile:t,changes:[{component:"*",kind:"shape",bump:"none",message:`snapshot schemaVersion ${o.schemaVersion} does not match the current schemaVersion ${Ce}; skipping diff`}],bump:"none"};let r=j(e,{entryExports:n.entryExports}),s=To(o,r);return{snapshotExists:!0,snapshotFile:t,changes:s,bump:So(s)}}var Ro={major:"BREAKING",minor:"additive",patch:"patch",none:"no change"};function Bt(e){if(!e.snapshotExists)return`sveld --check: no snapshot found at "${e.snapshotFile}". Run \`sveld --json\` and commit the output first.`;if(e.changes.length===0)return`sveld --check: no API changes detected against "${e.snapshotFile}".`;let t=[],n=e.changes.length;t.push(`sveld --check: ${n} API change${n===1?"":"s"} detected against "${e.snapshotFile}".`),t.push(`Suggested semver bump: ${e.bump}.`);let o=new Map;for(let r of e.changes){let s=o.get(r.component)??[];s.push(r),o.set(r.component,s)}for(let[r,s]of o){t.push(""),t.push(` ${r}`);for(let i of s)t.push(` [${Ro[i.bump]}] ${i.message}`)}return t.join(`
|
|
2
|
+
`)}function Gt(e){let t={kind:"check-report",...e};return W(t)}import{existsSync as No}from"node:fs";import{join as Oo}from"node:path";import{pathToFileURL as _o}from"node:url";var jo=["sveld.config.js","sveld.config.mjs","sveld.config.ts"];function Xi(e){return e}function Mo(e=process.cwd()){for(let t of jo){let n=Oo(e,t);if(No(n))return n}return null}async function Fo(e){let t;try{t=await import(`${_o(e).href}?t=${Date.now()}`)}catch(o){let r=o instanceof Error?o.message:String(o);throw Error(`sveld: failed to load config file "${e}".
|
|
3
|
+
${r}`)}let n=t.default;if(!K(n)||Array.isArray(n))throw Error(`sveld: config file "${e}" must export a configuration object as its default export. Did you forget \`export default defineConfig({ ... })\`?`);return n}async function Wt(e=process.cwd()){let t=Mo(e);if(t===null)return{};return Fo(t)}function Lt(...e){return Object.assign({},...e.filter(Boolean))}var He=new Map;function se(e){He.set(e.name,e)}function Xe(e){return He.get(e)}function qi(){return Array.from(He.values())}import{dirname as uo}from"node:path";import{lstatSync as Pn,readdirSync as Rr,readFileSync as Nr,realpathSync as Or,statSync as _r}from"node:fs";import{readFile as jr}from"node:fs/promises";import{dirname as Mr,isAbsolute as Fr,join as Ir,parse as Te,relative as ot,resolve as ue}from"node:path";function ie(e){return e}function L(e){if(e==="")return e;return e.startsWith(".")?e:`./${e}`}import{dirname as Io,resolve as Bo}from"node:path";var Go=/^(['"])(.*)\1$/;function Wo(e,t){let n=e.extends?.import;if(n===void 0)return null;let o=n.replace(Go,"$2");if(!B.test(o))return null;return Bo(Io(t),o)}function ae(e,t){let n=new Map;for(let o of e.values()){let r=t(o.filePath),s=Wo(o,r);if(s===null)continue;let i=n.get(s);if(i===void 0)i=new Set,n.set(s,i);i.add(r)}return n}function ve(e,t){let n=new Set,o=[];for(let r of e)if(!n.has(r))n.add(r),o.push(r);while(o.length>0){let r=o.shift(),s=t.get(r);if(s===void 0)continue;for(let i of s)if(!n.has(i))n.add(i),o.push(i)}return n}var Lo={"prop-unknown-type":"Props without inferred types","context-any-type":"Context values typed as `any`","event-no-source":"@event tags with no dispatch or callback","example-compile-error":"@example blocks that failed to compile","syntax-skipped":"Component syntax sveld skipped"},Vo=["prop-unknown-type","context-any-type","event-no-source","example-compile-error","syntax-skipped"];function Se(e){let t=new Set,n=[];for(let o of e){let r=`${o.component}:${o.kind}:${o.name}`;if(t.has(r))continue;t.add(r),n.push(o)}return n}function Vt(e){if(e.length===0)return"sveld: all types resolved.";let t=[],n=e.length;t.push(`sveld: ${n} unresolved type${n===1?"":"s"} found.`);for(let o of Vo){let r=e.filter((i)=>i.kind===o);if(r.length===0)continue;t.push(""),t.push(`${Lo[o]} (${r.length}):`);let s=new Map;for(let i of r){let a=s.get(i.component)??[];a.push(i),s.set(i.component,a)}for(let[i,a]of s){t.push(` ${i}`);for(let p of a){let c=p.source?` (${i}:${p.source.start.line}:${p.source.start.column})`:"";t.push(` - ${p.message}${c}`)}}}return t.join(`
|
|
4
|
+
`)}function Jt(e){return W({kind:"diagnostics",diagnostics:e})}var Jo=/^```([\w-]*)\r?\n([\s\S]*?)\r?\n?```$/,Uo=new Set(["","js","jsx","ts","tsx","javascript","typescript"]);function Ho(e){let t=e.trim();if(t==="")return null;let n=t.match(Jo);if(n){let o=n[1].toLowerCase();if(!Uo.has(o))return null;let r=n[2].trim();return r===""?null:r}if(t.startsWith("<"))return null;return t}function Ut(e){if(!e.isFunction)return"any";return`(${(e.params??[]).map((n)=>`${n.name}${n.optional?"?":""}: any`).join(", ")}) => any`}function be(e,t,n,o,r){let s=(e??[]).filter((a)=>a.name==="example"),i=[];return s.forEach((a,p)=>{let c=Ho(a.body);if(c===null)return;let l=s.length>1;i.push({id:l?`${t}#${p}`:t,name:l?`${n} (example ${p+1})`:n,type:o,code:c,...r?{source:r}:{}})}),i}function Ht(e){return e.name??"default"}function Xt(e){let t=[];for(let n of e.props)t.push(...be(n.tags,`prop:${n.name}`,n.name,Ut(n),n.source));for(let n of e.moduleExports)t.push(...be(n.tags,`export:${n.name}`,n.name,Ut(n),n.source));for(let n of e.slots)t.push(...be(n.tags,`slot:${Ht(n)}`,Ht(n),"any",n.source));for(let n of e.events)t.push(...be(n.tags,`event:${n.name}`,n.name,"any",n.source));return t}import{createHash as Xo}from"node:crypto";import{mkdirSync as Ko,readFileSync as qo,writeFileSync as zo}from"node:fs";import{dirname as Yo,isAbsolute as Qo,join as Zo,resolve as Kt}from"node:path";var qe=2,er=Zo("node_modules",".cache","sveld","parse-cache.json");function ze(){return`${xe}+svelte@${re}`}function zt(e,t){if(typeof t==="string")return Qo(t)?t:Kt(e,t);return Kt(e,er)}function Yt(e){return Xo("sha256").update(e).digest("hex")}function qt(){return{formatVersion:qe,toolchainVersion:ze(),entries:{}}}function tr(e){try{let t=qo(e,"utf-8"),n=JSON.parse(t);if(n.formatVersion!==qe||n.toolchainVersion!==ze())return qt();return n}catch{return qt()}}class Ye{cacheFilePath;file;next=new Map;blocked=new Set;constructor(e){this.cacheFilePath=e,this.file=tr(e)}has(e,t){if(this.blocked.has(e))return!1;let n=this.file.entries[e];return n!==void 0&&n.hash===t}get(e,t){if(this.blocked.has(e))return null;let n=this.file.entries[e];if(n===void 0||n.hash!==t)return null;if(this.next.set(e,n),n.typeScriptMetadata!==void 0)n.parsed[Ke]=n.typeScriptMetadata;return n.parsed}set(e,t,n){this.next.set(e,{hash:t,parsed:n,typeScriptMetadata:n[Ke]})}invalidate(e){this.blocked.add(e)}getGeneratedText(e,t){let n=this.next.get(e);if(n?.generatedText===void 0||n.generatedText.format!==t)return;return n.generatedText.text}setGeneratedText(e,t,n){let o=this.next.get(e);if(o===void 0)return;o.generatedText={format:t,text:n}}save(){Ko(Yo(this.cacheFilePath),{recursive:!0});let e={formatVersion:qe,toolchainVersion:ze(),entries:Object.fromEntries(this.next)};zo(this.cacheFilePath,JSON.stringify(e))}}import{existsSync as De,lstatSync as on,readFileSync as cr}from"node:fs";import{dirname as dn,join as lr,relative as ur,resolve as mn}from"node:path";var Q=null,Qe=null;function q(){if(Q)return Promise.resolve(Q);if(!Qe)Qe=Promise.all([import("./chunk-hpxd4cgm.js"),import("./chunk-n5cjh6db.js")]).then(([e,t])=>(Q={ComponentParser:e.default,parseSvelte:t.parse},Q));return Qe}function Pe(){if(!Q)throw Error("sveld: internal error, parser stack read before loadParserStack() resolved.");return Q}import{existsSync as tn,readFileSync as nr}from"node:fs";import{dirname as et,isAbsolute as or,join as rr,relative as sr,resolve as ke}from"node:path";function Qt(e){if(!K(e))return{};let t=e.svelte;return typeof t==="string"?{svelte:t}:{}}function Zt(e){if(!K(e))return{};let t={};if(typeof e.extends==="string")t.extends=e.extends;if(K(e.compilerOptions)){let n={};if(typeof e.compilerOptions.baseUrl==="string")n.baseUrl=e.compilerOptions.baseUrl;if(K(e.compilerOptions.paths)){let o={};for(let[r,s]of Object.entries(e.compilerOptions.paths))if(Array.isArray(s)&&s.every((i)=>typeof i==="string"))o[r]=s;if(Object.keys(o).length>0)n.paths=o}if(Object.keys(n).length>0)t.compilerOptions=n}return t}var $e=new Map,en=new Map,ir=/\/\*[\s\S]*?\*\/|\/\/.*/g,ar=/[.+?^${}()|[\]\\]/g;function pr(e){let t=e,n=ke(t,"/");while(t!==n){for(let o of["tsconfig.json","jsconfig.json"]){let r=rr(t,o);if(tn(r))return r}t=et(t)}return null}function nn(e){if($e.has(e))return $e.get(e)??null;try{let t=nr(e,"utf-8"),n;try{n=JSON.parse(t)}catch{let r=t.replace(ir,"");n=JSON.parse(r)}let o=Zt(n);if(o.extends){let r=or(o.extends)?o.extends:ke(et(e),o.extends),s=r.endsWith(".json")?r:`${r}.json`;if(tn(s)){let i=nn(s);if(i)o.compilerOptions={...i.compilerOptions,...o.compilerOptions,paths:{...i.compilerOptions?.paths,...o.compilerOptions?.paths}}}}return $e.set(e,o),o}catch{return $e.set(e,null),null}}function pe(e,t){if(e.startsWith(".")||e.startsWith("/"))return e;let n=pr(t);if(!n)return e;let o=nn(n);if(!o?.compilerOptions?.paths)return e;let{baseUrl:r=".",paths:s}=o.compilerOptions,i=et(n),a=ke(i,r);for(let[p,c]of Object.entries(s)){let l=en.get(p);if(!l){let m=p.split("*").map((f)=>f.replace(ar,"\\$&")).join("(.*)");l=new RegExp(`^${m}$`),en.set(p,l)}let d=e.match(l);if(d){let m=c[0];if(!m)continue;let f=m;for(let h=1;h<d.length;h++)f=f.replace("*",d[h]);return ke(a,f)}}return e}function ce(e,t){if(e.startsWith(".")||e.startsWith("/"))return e;let n=pe(e,t);if(n===e)return e;let o=sr(t,n);return o=T(o),o.startsWith(".")?o:`./${o}`}var rn=[".ts",".mts",".cts",".tsx",".js",".mjs",".cjs",".jsx",".d.ts"],dr=/\r?\n/,mr=/^\s*\*+/;function v(e){return e&&typeof e==="object"?e:void 0}function ee(e){return Array.isArray(e)?e:[]}function G(e){return cn(e)?e.name:void 0}function z(e,t){let n=pe(e,t),o=mn(t,n);if(De(o)&&on(o).isFile())return o;for(let r of rn){let s=o+r;if(De(s))return s}if(De(o)&&on(o).isDirectory())for(let r of rn){let s=lr(o,`index${r}`);if(De(s))return s}return null}function fr(e,t){let n=e.slice(0,t).trimEnd();if(!n.endsWith("*/"))return;let o=n.length-2,r=n.lastIndexOf("/**",o);if(r===-1)return;let s=[];for(let i of n.slice(r+3,o).split(dr)){let a=i.replace(mr,"").trim();if(a.startsWith("@"))break;if(a)s.push(a)}return s.join(" ")||void 0}function gr(e,t){let n=e.slice(0,t).trimEnd();if(!n.endsWith("*/"))return;let o=n.length-2,r=n.lastIndexOf("/**",o);if(r===-1)return;return n.slice(r,o+2)}function Z(e,t){if(!t)return;return e.text.slice(t.start,t.end)}function yr(e,t){let n=v(t?.typeAnnotation);if(n?.type!=="TSTypeAnnotation")return;return Z(e,v(n.typeAnnotation))}function tt(e,t){let n=v(t.returnType);return n?.type==="TSTypeAnnotation"?Z(e,v(n.typeAnnotation)):void 0}function sn(e,t){let n=ee(t.params).map((r)=>Z(e,r)??"").join(", "),o=tt(e,t);return`(${n})${o?` => ${o}`:""}`}function fn(e){if(e.type==="Literal"){let t=e.value;if(typeof t==="string")return"string";if(typeof t==="number")return"number";if(typeof t==="boolean")return"boolean"}if(e.type==="TemplateLiteral")return"string";return}function hr(e){if(!e)return;let t=e.lastIndexOf("=>");if(t===-1)return;return e.slice(t+2).trim()||void 0}function an(e){if(e.async||e.generator)return;let t=v(e.body);if(!t)return;let n=[];if(t.type==="BlockStatement"){if(le(t,n),n.length===0)return}else n.push(t);let o;for(let r of n){if(!r)return;let s=fn(r);if(!s)return;if(o===void 0)o=s;else if(o!==s)return}return o}function le(e,t){for(let n of ee(e.body)){if(n.type==="FunctionDeclaration"||n.type==="FunctionExpression"||n.type==="ArrowFunctionExpression")continue;if(n.type==="ReturnStatement"){t.push(v(n.argument)??null);continue}if(n.type==="BlockStatement"){le(n,t);continue}let o=v(n.consequent);if(o?.type==="BlockStatement")le(o,t);else if(o?.type==="ReturnStatement")t.push(v(o.argument)??null);let r=v(n.alternate);if(r?.type==="BlockStatement")le(r,t);else if(r?.type==="ReturnStatement")t.push(v(r.argument)??null);let s=v(n.body);if(s?.type==="BlockStatement")le(s,t)}}function pn(e,t,n){let o=e.filePath,r=fr(e.text,n),s=gr(e.text,n),i=s?un(s):void 0;if(t.type==="VariableDeclaration"){let a=t.kind??"const",p=[];for(let c of ee(t.declarations)){let l=v(c.id),d=G(l);if(!d)continue;let m=yr(e,l),f,g,h,u=v(c.init);if(u)if(u.type==="ArrowFunctionExpression"||u.type==="FunctionExpression"){if(!m)m=sn(e,u);g=tt(e,u)??i??hr(m)??an(u)}else{if(f=Z(e,u),!m)m=fn(u);h=ln(u)??void 0}p.push({name:d,kind:a,type:m,value:f,returnType:g,literalValue:h,description:r,declFile:o,isTypeOnly:!1})}return p}if(t.type==="FunctionDeclaration"||t.type==="TSDeclareFunction"){let a=G(v(t.id));if(!a)return[];return[{name:a,kind:"function",type:sn(e,t),returnType:tt(e,t)??i??an(t),description:r,declFile:o,isTypeOnly:!1}]}if(t.type==="ClassDeclaration"){let a=G(v(t.id));if(!a)return[];return[{name:a,kind:"class",type:a,description:r,declFile:o,isTypeOnly:!1}]}if(t.type==="TSTypeAliasDeclaration"){let a=G(v(t.id));if(!a)return[];return[{name:a,kind:"type",type:Z(e,v(t.typeAnnotation)),description:r,declFile:o,isTypeOnly:!0}]}if(t.type==="TSInterfaceDeclaration"){let a=G(v(t.id));if(!a)return[];return[{name:a,kind:"interface",type:Z(e,v(t.body)),description:r,declFile:o,isTypeOnly:!0}]}if(t.type==="TSEnumDeclaration"){let a=G(v(t.id));if(!a)return[];return[{name:a,kind:"enum",type:a,description:r,declFile:o,isTypeOnly:!1}]}return[]}function xr(e){let t;try{t=cr(e,"utf-8")}catch{return null}let n=`<script lang="ts">
|
|
5
|
+
${t}
|
|
6
|
+
</script>`;try{let o=Pe().parseSvelte(n,{modern:!0}),r=ee(o.instance?.content?.body);return{source:{text:n,filePath:e,dir:dn(e)},body:r}}catch(o){let r=o instanceof Error?o.message:String(o);return console.warn(`Warning: Failed to parse entry export module ${e}: ${r}`),null}}function Cr(e,t){for(let n of e){if(n.type!=="ImportDeclaration")continue;let o=v(n.source)?.value;if(typeof o!=="string")continue;for(let r of ee(n.specifiers)){if(r.type!=="ImportSpecifier")continue;if(G(v(r.local))===t){let s=G(v(r.imported))??t;return{specifier:o,importedName:s}}}}return null}function V(e,t){let n=t.cache.get(e);if(n)return n;if(t.computing.has(e))return[];t.computing.add(e);let o=xr(e);if(!o)return t.computing.delete(e),t.cache.set(e,[]),[];let{source:r,body:s}=o,i=[],a=new Map;for(let c of s){let l=c.type==="ExportNamedDeclaration"?v(c.declaration):c;if(!l)continue;for(let d of pn(r,l,l.start))a.set(d.name,d)}let p=(c)=>{let l=a.get(c);if(l)return l;let d=Cr(s,c);if(!d||d.specifier.endsWith(".svelte"))return null;let m=z(d.specifier,r.dir);if(!m)return null;return V(m,t).find((f)=>f.name===d.importedName)??null};for(let c of s){if(c.type==="ExportAllDeclaration"){let g=v(c.source)?.value;if(typeof g!=="string"||g.endsWith(".svelte"))continue;let h=z(g,r.dir);if(!h)continue;let u=c.exportKind==="type";for(let C of V(h,t))i.push(u?{...C,isTypeOnly:!0}:C);continue}if(c.type!=="ExportNamedDeclaration")continue;let l=v(c.declaration);if(l){i.push(...pn(r,l,c.start));continue}let d=v(c.source)?.value,m=typeof d==="string"?d:void 0;if(m?.endsWith(".svelte"))continue;let f=c.exportKind==="type";for(let g of ee(c.specifiers)){if(g.type!=="ExportSpecifier")continue;let h=G(v(g.exported)),u=G(v(g.local));if(!h||!u||u==="default"||h==="default")continue;let C=f||g.exportKind==="type",y=null;if(m){let S=z(m,r.dir);if(S)y=V(S,t).find((E)=>E.name===u)??null}else y=p(u);if(y?.declFile.endsWith(".svelte"))continue;if(y)i.push({...y,name:h,isTypeOnly:y.isTypeOnly||C});else i.push({name:h,kind:C?"type":"const",declFile:e,isTypeOnly:C})}}return t.computing.delete(e),t.cache.set(e,i),i}async function we(e){await q();let t=mn(e),n=dn(t),o=V(t,{cache:new Map,computing:new Set}),r=new Map;for(let s of o){let{declFile:i,returnType:a,...p}=s,c=T(`./${ur(n,i)}`);r.set(s.name,{...p,source:c})}return Array.from(r.values()).sort((s,i)=>s.name.localeCompare(i.name))}import{lstatSync as Er,readdirSync as vr,readFileSync as Sr}from"node:fs";import{dirname as br,join as gn,resolve as Pr}from"node:path";var yn=new Map;function $r(e){return hn(e,{ecmaVersion:"latest",sourceType:"module"})}function nt(e,t,n=new Set){let o=yn.get(e);if(!o)o=$r(e),yn.set(e,o);let r={};for(let s of o.body)if(s.type==="ExportDefaultDeclaration"){let i=s.declaration.name;if(i in r)r[i].default=!0;else r[i]={source:L(""),default:!0}}else if(s.type==="ExportAllDeclaration"){if(!s.source)continue;let i=pe(s.source.value,t),a=Pr(t,i);if(!Er(a).isFile()){let l=vr(a);for(let d of l)if(d.includes("index")){a=gn(a,d);break}}if(n.has(a))continue;n.add(a);let p=Sr(a,"utf-8"),c=nt(p,br(a),n);n.delete(a);for(let[l,d]of Object.entries(c)){let m=L(T(`./${gn(s.source.value,d.source)}`));r[l]={...d,source:m}}}else if(s.type==="ExportNamedDeclaration")for(let i of s.specifiers){let a=i.exported.name,p=i.local.name,c=a||p;if(c in r){if(s.type==="ExportNamedDeclaration")r[c].mixed=!0;if(!r[c].source)r[c].source=L(ce(s.source?.value??"",t))}else r[c]={source:L(ce(s.source?.value??"",t)),default:p==="default"}}else if(s.type==="ImportDeclaration"){let i=s.specifiers[0].local.name;if(i in r){if(!r[i].source)r[i].source=L(ce(s.source?.value??"",t))}else r[i]={source:L(ce(s.source?.value??"",t)),default:i==="default"}}return r}import{existsSync as kr}from"node:fs";import{dirname as Dr}from"node:path";function xn(){return{cache:new Map,computing:new Set}}var wr=/\.[^./\\]+$/;function Tr(e){if(e.endsWith(".d.ts"))return null;let t=e.replace(wr,".d.ts");return kr(t)?t:null}function Cn(e,t,n){let o=Dr(e);return t.map((r)=>{if(!r.importSource||!r.importedName)return{candidate:r};let s=z(r.importSource,o);if(!s)return{candidate:r,failureReason:"module-not-found"};let i=V(s,n).find((p)=>p.name===r.importedName);if(!i)return{candidate:r,failureReason:"export-not-found"};if(i.returnType)return{candidate:r,type:i.returnType};let a=Tr(s);if(a){let p=V(a,n).find((c)=>c.name===r.importedName);if(p?.returnType)return{candidate:r,type:p.returnType}}return{candidate:r,failureReason:"return-type-unresolved"}})}function En(e,t){switch(t){case"module-not-found":return`Prop "${e.propName}" default calls "${e.calleeName}()", but "${e.importSource}" could not be resolved; falling back to "any".`;case"export-not-found":return`Prop "${e.propName}" default calls "${e.calleeName}()", but "${e.importedName}" is not exported from "${e.importSource}"; falling back to "any".`;case"return-type-unresolved":return`Prop "${e.propName}" default calls "${e.calleeName}()" imported from "${e.importSource}", but its return type could not be resolved; falling back to "any".`}}import{dirname as Ar}from"node:path";function vn(e,t,n){let o=Ar(e);return t.map((r)=>{let s=z(r.importSource,o);if(!s)return{candidate:r};let i=V(s,n).find((a)=>a.name===r.importedName);if(i?.kind!=="const"||i.literalValue===void 0)return{candidate:r};return{candidate:r,key:i.literalValue}})}function de(e){return{failFast:e?.failFast,resolveTypes:e?.resolveTypes===!0,documentExports:e?.documentExports===!0,cache:e?.cache,checkExamples:e?.checkExamples===!0,dryRun:e?.dryRun===!0}}var Br=/-/g;function $n(e,t=[],n=new Set){let o;try{let r=Or(e);if(n.has(r))return t;n.add(r),o=Rr(e,{withFileTypes:!0})}catch{return t}for(let r of o){if(r.name.startsWith("."))continue;let s=Ir(e,r.name),i=r.isSymbolicLink()?_r(s,{throwIfNoEntry:!1}):r;if(!i)continue;if(i.isDirectory())$n(s,t,n);else if(i.isFile()&&r.name.endsWith(".svelte"))t.push(s)}return t}function Gr(e){return $n(e).map((t)=>{let n=Te(t).name.replace(Br,""),o=L(T(`./${ot(e,t)}`));return{moduleName:n,source:o}}).sort((t,n)=>t.source.localeCompare(n.source))}function Wr(e){return Te(e).ext!==".svelte"}function Lr(e,t){let n=e.endsWith("/")?e:`${e}/`;return t.startsWith(n)}function rt(e,t){return{seenPaths:new Set(e.map(([,n])=>t(n.source))),seenModuleNamePaths:new Map(e.map(([n,o])=>[n,t(o.source)])),warnedModuleNames:new Set}}function st(e,t,n,o,r){for(let{moduleName:s,source:i}of Gr(e)){let a=o(i),p=t[s];if(p&&Wr(p.source)&&Lr(p.source,i)){r.seenPaths.delete(o(p.source)),p.source=i,r.seenPaths.add(a),r.seenModuleNamePaths.set(s,a);continue}if(r.seenPaths.has(a))continue;r.seenPaths.add(a);let c=r.seenModuleNamePaths.get(s);if(c===void 0)r.seenModuleNamePaths.set(s,a);else if(c!==a&&!r.warnedModuleNames.has(s))r.warnedModuleNames.add(s),console.warn(`Warning: multiple components named "${s}" found (${T(ot(e,c))} and ${T(ot(e,a))}). Both are included in TypeScript definitions, but only one can be the named export.`);n.push([s,{source:i,default:!1}])}}function it(e,t,n=!1){let o=Pn(e).isFile(),r=o?Mr(e):e,s=ue(r),i=(c)=>Fr(c)?ue(c):ue(s,c),a={};if(o){let c=Nr(e,"utf-8");try{a=nt(c,s,new Set([ue(e)]))}catch(l){if(!n)throw l;let d=l instanceof Error?l.message:String(l);console.warn(`Warning: Failed to parse component exports from ${e}: ${d}`)}}let p=Object.entries(a);if(t){let c=rt(p,i);st(s,a,p,i,c)}return{exports:a,allComponentEntries:p,rootDir:s,resolveComponentFilePath:i}}async function Ae(e){let t=await Promise.all(Array.from(e).map(async(n)=>{try{let o=await jr(n,"utf-8");return{path:n,content:o}}catch(o){return console.warn(`Warning: Failed to read file ${n}:`,o),{path:n,content:null}}}));return new Map(t.map(({path:n,content:o})=>[n,o]))}function H([e,t],n,o,r,s={}){let i=t.source,{ext:a,name:p}=Te(i),c=e;if(n.length===1&&e==="default")c=p;if(a===".svelte"){let l=r(i),d=o.get(l);if(d===null||d===void 0)return null;let m=T(i),f=s.memo?.get(l),g=s.hashes?.get(l),h=f===void 0?g===void 0?null:s.cache?.get(l,g):null,u;if(f!==void 0)u=f;else if(h)u=h;else{let C=new(Pe()).ComponentParser;try{u=C.parseSvelteComponent(d,{moduleName:c,filePath:m})}catch(y){if(s.failFast)throw y;let S=y instanceof Error?y.message:String(y),E=y instanceof Error?y.stack:void 0;return s.onParseError?.({filePath:m,moduleName:c,message:S,stack:E}),null}if(g!==void 0)s.cache?.set(l,g,u);s.memo?.set(l,u)}return{moduleName:c,filePath:m,...u}}return null}function at(e,t){let n=new Set;for(let o of e)for(let[,r]of o)if(Te(r.source).ext===".svelte")n.add(t(r.source));return n}function Re(e){if(e.length===0)return;console.error(`sveld: failed to parse ${e.length} component(s):`);for(let{filePath:t,message:n}of e)console.error(` - ${t}: ${n}`)}async function me(e,t,n={}){let o=n.documentExports===!0,{exports:r,allComponentEntries:s,rootDir:i,resolveComponentFilePath:a}=it(e,t,o),p=o&&Pn(e).isFile()?await we(ue(e)):[],c=Object.entries(r),l=at([c,s],a),d=await Ae(l),m=new Map,f=new Map,g=n.cache===!1?void 0:new Ye(zt(i,n.cache??!0)),h=g?new Map:void 0,u=new Set,C=new Map;if(g)for(let b of l){let x=d.get(b);if(x===null||x===void 0)continue;let k=Yt(x);if(C.set(b,k),!g.has(b,k))u.add(b)}if(l.size>0&&(!g||u.size>0))await q();let y=new Map,S=new Map,E={failFast:n.failFast===!0,onParseError:(b)=>y.set(b.filePath,b),cache:g,hashes:C,memo:S};for(let b of c){let x=H(b,c,d,a,E);if(x)m.set(x.moduleName,x)}for(let b of s){let x=H(b,s,d,a,E);if(x)f.set(x.filePath,x),h?.set(x.filePath,a(b[1].source))}if(g&&u.size>0){let b=ae(f,a),x=ve(u,b);for(let k of x){if(u.has(k))continue;g.invalidate(k),S.delete(k)}for(let k of c){let _=a(k[1].source);if(!x.has(_)||u.has(_))continue;let I=H(k,c,d,a,E);if(I)m.set(I.moduleName,I)}for(let k of s){let _=a(k[1].source);if(!x.has(_)||u.has(_))continue;let I=H(k,s,d,a,E);if(I)f.set(I.filePath,I),h?.set(I.filePath,_)}}let P=Array.from(y.values());if(Re(P),!n.dryRun)g?.save();let A=n.resolveTypes?Xr(m):[],O=n.checkExamples?qr(f):[];if(A.length>0||O.length>0){let{TypeResolver:b}=await import("./chunk-bbeezhqq.js"),x=await b.create(i);try{if(A.length>0)await Kr(A,x,a);if(O.length>0)await zr(O,x,a)}finally{await x?.dispose()}}let D=Vr(f),w=Ur(f);if(D.length>0||w.length>0){await q();let b=xn();for(let{component:x,candidates:k}of D){let _=Cn(a(x.filePath),k,b);Jr(x,_)}for(let{component:x,candidates:k}of w){let _=vn(a(x.filePath),k,b);Hr(x,_)}}let U=Se(Array.from(f.values()).flatMap((b)=>b.diagnostics??[]));return{exports:r,entryExports:p,components:m,allComponentsForTypes:f,errors:P,diagnostics:U,cache:g,resolvedPathByFilePath:h}}function Vr(e){let t=[];for(let n of e.values()){let o=te(n)?.pendingCallDefaultCandidates?.filter((r)=>r.importSource!==void 0);if(!o||o.length===0)continue;t.push({component:n,candidates:o})}return t}function Jr(e,t){for(let{candidate:n,type:o,failureReason:r}of t){let i=(n.location==="props"?e.props:e.moduleExports).find((a)=>a.name===n.propName);if(i?.typeSource!=="unknown")continue;if(o){if(i.type=o,i.typeSource="typescript",n.location==="props")e.diagnostics=(e.diagnostics??[]).filter((a)=>!(a.kind==="prop-unknown-type"&&a.name===n.propName));continue}if(n.location==="props"&&r){let a=e.diagnostics?.find((p)=>p.kind==="prop-unknown-type"&&p.name===n.propName);if(a)a.message=En(n,r)}}}function Ur(e){let t=[];for(let n of e.values()){let o=te(n)?.pendingContextKeyCandidates;if(!o||o.length===0)continue;t.push({component:n,candidates:o})}return t}function Hr(e,t){for(let{candidate:n,key:o}of t){if(!o){console.warn(`Warning: Could not resolve setContext key in ${e.filePath}. Use a string literal, const-bound string, or Symbol(). Skipping context type generation.`);continue}if(e.contexts?.some((r)=>r.key===o))continue;e.contexts=[...e.contexts??[],{key:o,typeName:bn(o),description:n.description,properties:n.properties}]}}function Xr(e){let t=[];for(let n of e.values()){let o=te(n);if(!o?.canonicalPropsType||n.props.length>0)continue;t.push({component:n,metadata:o})}return t}async function Kr(e,t,n){if(!t)return;let o=await t.expandAll(e.map(({component:r,metadata:s})=>({moduleName:r.moduleName,metadata:s,filePath:n(r.filePath)})));for(let{component:r}of e){let s=o.get(n(r.filePath));if(s)Sn(r,s)}}function qr(e){let t=[];for(let n of e.values()){let o=Xt(n);if(o.length===0)continue;t.push({component:n,sources:o})}return t}async function zr(e,t,n){if(!t)return;let o=await t.checkExamples(e.map(({component:r,sources:s})=>({moduleName:r.moduleName,filePath:n(r.filePath),sources:s})));for(let{component:r,sources:s}of e){let i=o.get(n(r.filePath));if(!i||i.length===0)continue;let a=new Map(s.map((c)=>[c.id,c.source])),p=r.diagnostics??[];for(let c of i){let l=a.get(c.id);p.push({component:r.filePath,kind:"example-compile-error",name:c.name,message:c.message,...l?{source:l}:{}})}r.diagnostics=p}}import{existsSync as kn,readFileSync as Yr}from"node:fs";import{join as Dn}from"node:path";function Ne(e){if(e){let n=Dn(process.cwd(),e);if(kn(n))return ie(e);return console.error(`Invalid entry point: ${n}. Pass a valid --entry (or "entry" option), or unset it and`),console.error('set the "svelte" field in your package.json instead.'),null}let t=Dn(process.cwd(),"package.json");if(!kn(t))return console.error("Could not locate a package.json file."),console.error(`Specify an entry point with --entry (or the "entry" option) instead.
|
|
7
|
+
`),null;try{let n=Qt(JSON.parse(Yr(t,"utf-8")));if(n.svelte?.trim())return ie(n.svelte);return console.error(`Could not determine an entry point.
|
|
8
|
+
`),console.error(`Specify an entry point to your Svelte code in the "svelte" field of your package.json, or pass --entry (or the "entry" option).
|
|
9
|
+
`),null}catch(n){throw console.error("Error reading package.json:",n),n}}import{lstatSync as Qr}from"node:fs";import{resolve as wn}from"node:path";async function Tn(e,t,n=!1){let{exports:o,allComponentEntries:r,rootDir:s,resolveComponentFilePath:i}=it(e,t,n),a=n&&Qr(e).isFile()?await we(wn(e)):[],p=Object.entries(o),c=rt(r,i),l=new Map,d=new Map;await q();let m=new Map,f={onParseError:(y)=>m.set(y.filePath,y)},g=()=>({exports:o,entryExports:a,components:l,allComponentsForTypes:d,errors:Array.from(m.values()),diagnostics:Se(Array.from(d.values()).flatMap((y)=>y.diagnostics??[]))});{let y=at([p,r],i),S=await Ae(y);for(let E of p){let P=H(E,p,S,i,f);if(P)l.set(P.moduleName,P)}for(let E of r){let P=H(E,r,S,i,f);if(P)d.set(P.filePath,P)}Re(g().errors)}let h=ae(d,i),u=(y,S,E,P,A)=>{let O=new Set;for(let D of E){let w=i(D[1].source);if(!P.has(w))continue;let U=H(D,E,A,i,f);if(U)y.set(S(U),U),O.add(w);else for(let[b,x]of y)if(i(x.filePath)===w)y.delete(b)}return O};return{get result(){return g()},update:async(y)=>{let S=y.filter((D)=>B.test(D)).map((D)=>wn(D));if(S.length===0)return{result:g(),reparsed:[]};if(t)st(s,o,r,i,c);let E=ve(S,h);for(let[D,w]of m)if(E.has(i(w.filePath)))m.delete(D);let P=await Ae(E),A=new Set;for(let D of u(l,(w)=>w.moduleName,p,E,P))A.add(D);for(let D of u(d,(w)=>w.filePath,r,E,P))A.add(D);h=ae(d,i);let O=g();return Re(O.errors),{result:O,reparsed:Array.from(A)}}}}import ls from"node:path";var An=!1;function Rn(e){An=e}function J(e){if(!An)console.error(e)}import{mkdir as Zr,readFile as es,writeFile as ts}from"node:fs/promises";import{parse as ns}from"node:path";class R{dryRun;constructor(e){this.dryRun=e?.dryRun===!0}async write(e,t){if(this.dryRun)return console.log(`would write "${T(e)}"`),!0;try{if(await es(e,"utf-8")===t)return!1}catch{}return await Zr(ns(e).dir,{recursive:!0}),await ts(e,t),!0}}var os=new Set(["string","number","boolean"]);function rs(e){return e.map((t)=>({kind:"field",name:t.name,...t.type?{type:{text:t.type}}:{},...t.value===void 0?{}:{default:t.value},...t.description?{description:t.description}:{},...t.deprecated===void 0?{}:{deprecated:t.deprecated}}))}function ss(e){let t=new Map;for(let o of e){if(!o.type||!os.has(o.type.trim()))continue;let r=o.name.toLowerCase(),s=t.get(r);if(s)s.push(o);else t.set(r,[o])}let n=[];for(let[o,r]of t){if(r.length!==1)continue;let s=r[0];n.push({name:o,fieldName:s.name,type:{text:s.type},...s.value===void 0?{}:{default:s.value},...s.description?{description:s.description}:{}})}return n}function is(e){return e.filter((t)=>t.type==="dispatched").map((t)=>({name:t.name,type:{text:`CustomEvent<${t.detail??"unknown"}>`},...t.description?{description:t.description}:{},...t.deprecated===void 0?{}:{deprecated:t.deprecated}}))}function as(e){return e.map((t)=>({name:t.default?"":t.name??"",...t.description?{description:t.description}:{},...t.deprecated===void 0?{}:{deprecated:t.deprecated}}))}function ps(e){let t={kind:"class",name:e.moduleName,...e.componentComment?{description:e.componentComment}:{},members:rs(e.props),attributes:ss(e.props),events:is(e.events),slots:as(e.slots)};if(e.customElementTag)t.tagName=e.customElementTag,t.customElement=!0;return t}function cs(e,t){let n=[{kind:"js",name:e.moduleName,declaration:{name:e.moduleName,module:t}}];if(e.customElementTag)n.push({kind:"custom-element-definition",name:e.customElementTag,declaration:{name:e.moduleName,module:t}});return n}function Nn(e,t={}){let n=j(e),o=t.resolveModulePath??((s)=>s.filePath);return{schemaVersion:"1.0.0",modules:n.components.map((s)=>{let i=o(s);return{kind:"javascript-module",path:i,declarations:[ps(s)],exports:cs(s,i)}})}}function pt(e,t){let n=Nn(e,{resolveModulePath:(o)=>Oe(o.filePath,t.inputDir)});return W(n)}async function ct(e,t){let n=pt(e,t),o=ls.join(process.cwd(),t.outFile);if(await new R({dryRun:t.dryRun}).write(o,n),!t.dryRun)J(`created "${t.outFile}".`)}import lt from"node:path";function On(e){let t=new Map;for(let[o,r]of Object.entries(e)){let s=t.get(r.source)||[];s.push({id:o,exportee:r}),t.set(r.source,s)}let n=[];for(let[o,r]of t){let s=B.test(o),i=r.some(({id:m,exportee:f})=>m!=="default"&&f.default),a=r.some(({exportee:m})=>!m.default),p=s&&i&&a,c=[],l=[],d=[];for(let{id:m,exportee:f}of r){if(m==="default"){l.push(`export { default } from "${o}";`);continue}if(f.default)if(f.mixed)l.push(`export { default as ${m} } from "${o}";`),l.push(`export { default } from "${o}";`);else d.push(`default as ${m}`);else if(s&&!p)d.push(`default as ${m}`);else c.push(m)}if(d.length>0&&c.length>0)n.push(`export { ${[...d,...c].join(", ")} } from "${o}";`);else{if(c.length>0)n.push(`export { ${c.join(", ")} } from "${o}";`);if(d.length>0)n.push(`export { ${d.join(", ")} } from "${o}";`)}n.push(...l)}return n.join(`
|
|
10
|
+
`)}function _n(e){return e.replace(B,"")}function jn(e){return e.replace(B,".svelte.d.ts")}function ut(e,t){return e.map((n)=>({...n,filePath:Oe(n.filePath,t)}))}function us(e,t,n){if(!t)return`${e.moduleName}.api.json`;if(!n.has(e.moduleName))n.add(e.moduleName),console.warn(`Warning: multiple components named "${e.moduleName}" found. Their JSON files are keyed by source path instead of name to avoid overwriting each other.`);return`${_n(e.filePath)}.api.json`}async function ds(e,t){let n=j(e),o=ut(n.components,t.inputDir),r=new Map;for(let i of o)r.set(i.moduleName,(r.get(i.moduleName)??0)+1);let s=new Set;await Promise.all(o.map(async(i)=>{let a=(r.get(i.moduleName)??0)>1,p=us(i,a,s),c=lt.resolve(lt.join(t.outDir||"",p)),d=await new R({dryRun:t.dryRun}).write(c,W(i));if(!t.dryRun)J(`${d?"created":"unchanged"} "${c}".`)}))}function dt(e,t){let n=j(e,{entryExports:t.entryExports}),o={...n,components:ut(n.components,t.inputDir)};return W(o)}function Mn(e,t){let n=j(e,{entryExports:t.entryExports});return`${ut(n.components,t.inputDir).map((r)=>JSON.stringify(r)).join(`
|
|
11
|
+
`)}
|
|
12
|
+
`}async function ms(e,t){let n=dt(e,t),o=lt.join(process.cwd(),t.outFile);if(await new R({dryRun:t.dryRun}).write(o,n),!t.dryRun)J(`created "${t.outFile}".`)}async function mt(e,t){if(t.outDir)await ds(e,t);else await ms(e,t)}import{join as mi}from"node:path";var In=/^[}\])>]/,fs=new Set(["{","(","["]),gs=new Set(["}",")","]"]);var ys=/\binterface\s+[A-Za-z_$][\w$]*(\s*<[^{};]*>)?\s*$/,Bn=/[ \t]+$/,hs=/\s+$/,xs=/[{([]$/,Cs=/\s/;function Es(e){return ys.test(e.slice(-200))}var vs=200;function Ss(e,t){let n="";for(let o=e.length-1;o>=0&&n.length<t;o--)n=e[o]+n;return n.length>t?n.slice(-t):n}function Fn(e,t){while(e.length>0&&t.test(e[e.length-1]))e.pop()}function bs(e){if(e.includes("{"))return!1;let t=null,n=0;for(let o=0;o<e.length;o++){let r=e[o],s=e[o-1];if(t){if(t==="double"&&r==='"'&&s!=="\\"||t==="single"&&r==="'"&&s!=="\\"||t==="template"&&r==="`"&&s!=="\\")t=null;continue}if(r==='"'||r==="'"||r==="`"){t=r==='"'?"double":r==="'"?"single":"template";continue}if(r===";"&&++n>=2)return!0}return!1}function Ps(e){let t="",n=null,o=!1;for(let r=0;r<e.length;r++){let s=e[r],i=e[r-1];if(n){if(t+=s,n==="double"&&s==='"'&&i!=="\\"||n==="single"&&s==="'"&&i!=="\\"||n==="template"&&s==="`"&&i!=="\\")n=null;o=!1;continue}if(s==='"'||s==="'"||s==="`"){n=s==='"'?"double":s==="'"?"single":"template",t+=s,o=!1;continue}if(Cs.test(s)){if(!o&&t.length>0)t+=" ",o=!0;continue}t+=s,o=!1}return t.trimEnd()}function $s(e,t){let n=0,o="normal";for(let r=t;r<e.length;r++){let s=e[r],i=e[r-1];if(o==="blockComment"){if(i==="*"&&s==="/")o="normal";continue}if(o==="double"||o==="single"){if(s===(o==="double"?'"':"'")&&i!=="\\")o="normal";continue}if(o==="template"){if(s==="`"&&i!=="\\")o="normal";continue}if(s==="/"&&e[r+1]==="*")o="blockComment";else if(s==='"')o="double";else if(s==="'")o="single";else if(s==="`")o="template";else if(s==="{")n++;else if(s==="}"){if(n--,n===0)return r}}return-1}function Gn(e){let t=[],n="normal";for(let o=0;o<e.length;o++){let r=e[o],s=e[o-1];if(n==="blockComment"){if(t.push(r),s==="*"&&r==="/")n="normal";continue}if(n==="double"||n==="single"){if(t.push(r),r===(n==="double"?'"':"'")&&s!=="\\")n="normal";continue}if(n==="template"){if(t.push(r),r==="`"&&s!=="\\")n="normal";continue}if(r==="/"&&e[o+1]==="*"){n="blockComment",t.push(r);continue}if(r==='"'){n="double",t.push(r);continue}if(r==="'"){n="single",t.push(r);continue}if(r==="`"){n="template",t.push(r);continue}if(r==="{"){let i=$s(e,o);if(i===-1){t.push(r);continue}let a=e.slice(o+1,i);if(a.trim()===""){t.push("{}"),o=i;continue}if(!a.includes("/*")&&e[o+1]!==`
|
|
13
|
+
`&&!bs(a)&&!Es(Ss(t,vs))){let p=Gn(a).trim();if(!p.includes(`
|
|
14
|
+
`)){let c=p.endsWith(";")?p.slice(0,-1):p,l=`{ ${Ps(c)} }`;if(l.length<=120){t.push(l),o=i;continue}}}if(t.push(r),e[o+1]!==`
|
|
15
|
+
`)t.push(`
|
|
16
|
+
`);continue}if(r==="}"){if(Fn(t,Bn),t[t.length-1]!==`
|
|
17
|
+
`)t.push(`
|
|
18
|
+
`);t.push(r);continue}if(r===";"){if(Fn(t,hs),t.push(";"),e[o+1]!==`
|
|
19
|
+
`)t.push(`
|
|
20
|
+
`);continue}t.push(r)}return t.join("")}function ks(e){let t="",n=null;for(let o=0;o<e.length;o++){let r=e[o],s=e[o-1];if(n){if(t+=r,n==="double"&&r==='"'&&s!=="\\"||n==="single"&&r==="'"&&s!=="\\"||n==="template"&&r==="`"&&s!=="\\")n=null;continue}if(r==='"'||r==="'"||r==="`"){n=r==='"'?"double":r==="'"?"single":"template",t+=r;continue}if(r===" "&&t.endsWith(" "))continue;t+=r}return t}function Ds(e){let t=e.split(`
|
|
21
|
+
`),n=[],o=0,r=!1,s=0;for(let i of t){let a=i.trim();if(a===""){n.push("");continue}if(r){if(n.push(`${" ".repeat(s)} ${a}`),a.includes("*/"))r=!1;continue}if(a.startsWith("/**")&&!a.includes("*/")){n.push(" ".repeat(o)+a),r=!0,s=o;continue}let p=ks(a),c=In.test(p),l=Math.max(0,o-(c?1:0));if(n.push(" ".repeat(l)+p),p.startsWith("/**")&&p.includes("*/"))continue;let d=null;for(let m=0;m<p.length;m++){let f=p[m],g=p[m-1];if(d){if(d==="double"&&f==='"'&&g!=="\\"||d==="single"&&f==="'"&&g!=="\\"||d==="template"&&f==="`"&&g!=="\\")d=null;continue}if(f==='"')d="double";else if(f==="'")d="single";else if(f==="`")d="template";else if(fs.has(f))o++;else if(gs.has(f))o=Math.max(0,o-1);else if(f==="<")o++;else if(f===">"&&g!=="=")o=Math.max(0,o-1)}}return n.join(`
|
|
22
|
+
`)}function ws(e){let t=e.split(`
|
|
23
|
+
`).map((o)=>o.replace(Bn,"")),n=[];for(let o of t){let r=o==="",s=n.length>0&&n[n.length-1]==="",i=n.length>0&&xs.test(n[n.length-1]);if(r){if(n.length===0||s||i)continue;n.push(o);continue}if(In.test(o)&&s)n.pop();n.push(o)}while(n.length>0&&n[n.length-1]==="")n.pop();return n.join(`
|
|
24
|
+
`)}function Wn(e){let t=Gn(e),n=Ds(t);return`${ws(n)}
|
|
25
|
+
`}var X="any",M="",Ts="Record<string, any>",gt="Record<string, never>",As=/(-|\s+|:)/,Rs=/("|')/,Ns=/CustomEvent/,Os=/^[A-Z]/,_s=/\n/,Hn=/=>/,js=/(?:^|\n)@default\b/,yt=/\n/g,Ms=/\s+/g,ne=/(^|[^.\w])Snippet(?:\s*<|\b)/,Fs=/import\s+type\s+[^;]*\bSnippet\b[^;]*from\s+"svelte";/,Is=/[.*+?^${}()|[\]\\]/g,Bs=/^const\s+/;function ht(e){return e.replace(Bs,"")}function Gs(e){if(!e)return;return e.replace(yt,`
|
|
26
|
+
* `)}function _e(e){if(!e)return"";return`/** ${e} */`}function je(e){if(!e)return"";return`/**
|
|
27
|
+
* ${e.replace(yt,`
|
|
28
|
+
* `)}
|
|
29
|
+
*/`}function Xn(e){if(e===void 0)return;return e===!0?"@deprecated":`@deprecated ${e}`}function Ws(e){let t=Xn(e);if(t===void 0)return;return`* ${t.replace(yt,`
|
|
30
|
+
* `)}
|
|
31
|
+
`}function Ls(e,t){if(!t)return[`@${e}`];if(!t.includes(`
|
|
32
|
+
`))return[`@${e} ${t}`];return[`@${e}`,...t.split(`
|
|
33
|
+
`)]}function Kn(e){let t=[];for(let{name:n,body:o}of e??[])t.push(...Ls(n,o));return t}function fe(e,t,n){let o=Xn(n),r=Kn(t),s=r.length>0;if(!e&&!s&&!o)return"";if(!s&&!o)return e?.includes(`
|
|
34
|
+
`)?je(e):_e(e);let i=[];if(e)i.push(...e.split(`
|
|
35
|
+
`));if(i.push(...r),o)i.push(...o.split(`
|
|
36
|
+
`));return`/**
|
|
37
|
+
* ${i.join(`
|
|
38
|
+
* `)}
|
|
39
|
+
*/`}function Vs(e){let t=Kn(e);if(t.length===0)return"";return t.map((n)=>`* ${n}
|
|
40
|
+
`).join("")}function Me(e){if(e===void 0)return X;return`${e}
|
|
41
|
+
`}function Fe(e){if(e.typedefs.length===0)return M;return e.typedefs.map((t)=>`${t.description?`${je(t.description)}
|
|
42
|
+
`:""}export ${t.ts}`).join(`
|
|
43
|
+
|
|
44
|
+
`)}var Ln=new Map;function qn(e,t){let n=Ln.get(t);if(n===void 0){let o=t.replace(Is,"\\$&");n=new RegExp(`\\b${o}\\b`),Ln.set(t,n)}return n.test(e)}var Vn,Jn=[];function xt(e){if(e!==Vn)Vn=e,Jn=Un(e);return Jn}function Js(e){if(e===null)return[];return e[0].split(",").map((t,n)=>({name:t.trim(),constraint:(xt(e[1]??"")[n]??t).trim()}))}function Us(e,t){let n=Js(e).filter(({name:o})=>qn(t,o));if(n.length===0)return{declSuffix:M,refSuffix:M};return{declSuffix:`<${n.map(({constraint:o})=>ht(o)).join(", ")}>`,refSuffix:`<${n.map(({name:o})=>o).join(", ")}>`}}function zn(e){if(!e.contexts||e.contexts.length===0)return M;let t=e.generics===null?[]:e.generics[0].split(",").map((n,o)=>({name:n.trim(),constraint:(xt(e.generics?.[1]??"")[o]??n).trim()}));return e.contexts.map((n)=>{let o=n.properties.map((a)=>{let p=a.description?`${_e(a.description)}
|
|
45
|
+
`:"",c=a.optional?"?":"";return`${p}${a.name}${c}: ${a.type};`}).join(`
|
|
46
|
+
`),r=n.description?`${je(n.description)}
|
|
47
|
+
`:"",s=t.filter(({name:a})=>n.properties.some((p)=>qn(p.type,a))).map(({constraint:a})=>a),i=s.length>0?`<${s.map(ht).join(", ")}>`:"";if(n.properties.length===0)return`${r}export type ${n.typeName} = Record<string, never>;`;return`${r}export type ${n.typeName}${i} = {
|
|
48
|
+
${o}
|
|
49
|
+
};`}).join(`
|
|
50
|
+
|
|
51
|
+
`)}function ge(e){if(As.test(e))return Rs.test(e)?e:`"${e}"`;return e}function Yn(e,t){if(!e)return;return`* ${t||e}
|
|
52
|
+
`}function Ct(e,t,n){return[Yn(Gs(e)),Ws(t),Vs(n)].filter(Boolean).join("")}function Et(e){return e.length>0?`/**
|
|
53
|
+
${e}*/`:M}function Hs(e){let t=e.props.filter((u)=>!u.isFunctionDeclaration&&u.kind!=="const"),n=new Set([...t.map((u)=>u.name),...Array.from(e.canonicalPropNames??[])]),o=t.map((u)=>{let C=u.value;if(typeof u.value==="string")C=u.value.replace(Ms," ");if(u.value===void 0)C="undefined";let S=js.test(u.description??"")||u.isFunction&&u.value===void 0,E=[Ct(u.description,u.deprecated,u.tags),Yn(u.constant,"@constant"),S?null:`* @default ${C}
|
|
54
|
+
`].filter(Boolean).join(""),P=u.constant&&!u.isFunction?u.value:u.type;return`
|
|
55
|
+
${Et(E)}
|
|
56
|
+
${u.name}${u.isRequired?"":"?"}: ${P};`}),r=e.canonicalPropsType?o.filter((u,C)=>{let y=t[C];return y?!(e.canonicalPropNames?.has(y.name)??!1):!0}):o,s=(e.slots||[]).filter((u)=>!u.default&&u.name!=null&&!n.has(u.name)).map((u)=>{let C=u.name,y=ge(C),S=fe(u.description,u.tags,u.deprecated),E=S?`${S}
|
|
57
|
+
`:"",A=u.slot_props&&u.slot_props!=="Record<string, never>"?`(this: void, ...args: [${u.slot_props}]) => void`:"(this: void) => void";return`
|
|
58
|
+
${E}${y}?: ${A};`}),i=(e.slots||[]).find((u)=>u.default||u.name===null),a=i&&!n.has("children")?(()=>{let u=fe(i.description,i.tags,i.deprecated),C=u?`${u}
|
|
59
|
+
`:"",S=i.slot_props&&i.slot_props!=="Record<string, never>"?`(this: void, ...args: [${i.slot_props}]) => void`:"(this: void) => void";return`
|
|
60
|
+
${C}children?: ${S};`})():"",p=e.events?Qs({events:e.events},n):[],c=[...s,a,...p].filter(Boolean),l=[...r,...c].join(`
|
|
61
|
+
`),d=`${e.moduleName}Props`,m=M,f=e.generics?`<${xt(e.generics[1]).map((u)=>ht(u.trim())).join(", ")}>`:"",g=e.generics?`<${e.generics[0]}>`:"",h=e.canonicalPropsType?`
|
|
62
|
+
type $Props${f} = ${e.canonicalPropsType}${l.trim()===""?"":` & {${l}
|
|
63
|
+
}`};
|
|
64
|
+
`:`
|
|
65
|
+
type $Props${f} = {
|
|
66
|
+
${l}
|
|
67
|
+
};
|
|
68
|
+
`;if(e.rest_props?.type==="Element"){let u;if(e.rest_props.name==="svelte:element")if(e.rest_props.thisValue)u=`SvelteHTMLElements["${e.rest_props.thisValue}"]`;else u="HTMLAttributes<HTMLElement>";else u=e.rest_props.name.split("|").map((S)=>`SvelteHTMLElements["${S.trim()}"]`).join(" & ");let C="[key: `data-${string}`]: unknown;",y=e.rest_props.description?e.rest_props.description.includes(`
|
|
69
|
+
`)?`${je(e.rest_props.description)}
|
|
70
|
+
`:`${_e(e.rest_props.description)}
|
|
71
|
+
`:"";if(e.extends===void 0)m=`
|
|
72
|
+
${y}${u?`type $RestProps = ${u};
|
|
73
|
+
`:""}
|
|
74
|
+
${e.canonicalPropsType?`type $Props${f} = (${e.canonicalPropsType}) & {${l}
|
|
75
|
+
|
|
76
|
+
${C}
|
|
77
|
+
};`:`type $Props${f} = {
|
|
78
|
+
${l}
|
|
79
|
+
|
|
80
|
+
${C}
|
|
81
|
+
};`}
|
|
82
|
+
|
|
83
|
+
export type ${d}${f} = Omit<$RestProps, keyof $Props${g}> & $Props${g};
|
|
84
|
+
`;else m=`
|
|
85
|
+
${y}${u?`type $RestProps = ${u};
|
|
86
|
+
`:""}
|
|
87
|
+
${e.canonicalPropsType?`type $Props${f} = (${e.canonicalPropsType}) & {${l}
|
|
88
|
+
|
|
89
|
+
${C}
|
|
90
|
+
};`:`type $Props${f} = {
|
|
91
|
+
${l}
|
|
92
|
+
|
|
93
|
+
${C}
|
|
94
|
+
};`}
|
|
95
|
+
|
|
96
|
+
export type ${d}${f} = Omit<$RestProps, keyof ($Props${g} & ${e.extends.interface})> & $Props${g} & ${e.extends.interface};
|
|
97
|
+
`}else if(l.trim()===""&&e.extends===void 0&&!e.canonicalPropsType)m=`
|
|
98
|
+
export type ${d}${f} = ${gt};
|
|
99
|
+
`;else if(e.canonicalPropsType)m=`
|
|
100
|
+
${h}
|
|
101
|
+
export type ${d}${f} = ${e.extends===void 0?"":`${e.extends.interface} & `}$Props${g};
|
|
102
|
+
`;else m=`
|
|
103
|
+
export type ${d}${f} = ${e.extends===void 0?"":`${e.extends.interface} & `} {
|
|
104
|
+
${l}
|
|
105
|
+
};
|
|
106
|
+
`;return{props_name:d,prop_def:m}}function Xs(e){if(e.slots.length===0)return gt;let t=e.slots.map(({name:n,slot_props:o,...r})=>{let s=r.default||n===null?"default":ge(n??""),i=fe(r.description,r.tags,r.deprecated);return`${i?`${i}
|
|
107
|
+
`:""}${ge(s)}: ${Me(o)};`}).join(`
|
|
108
|
+
`);return e.slots.length===1?`{${t}}`:`{
|
|
109
|
+
${t}
|
|
110
|
+
}`}var Ks=()=>"WindowEventMap",qs=new Set(["click","dblclick","mousedown","mouseup","mousemove","mouseover","mouseout","mouseenter","mouseleave","contextmenu","wheel","keydown","keyup","keypress","submit","change","input","focus","blur","focusin","focusout","reset","select","touchstart","touchend","touchmove","touchcancel","drag","dragstart","dragend","dragover","dragenter","dragleave","drop","pointerdown","pointerup","pointermove","pointerover","pointerout","pointerenter","pointerleave","pointercancel","gotpointercapture","lostpointercapture","play","pause","ended","volumechange","timeupdate","loadeddata","loadedmetadata","canplay","canplaythrough","seeking","seeked","playing","waiting","stalled","suspend","abort","error","emptied","ratechange","durationchange","loadstart","progress","loadend","animationstart","animationend","animationiteration","animationcancel","transitionstart","transitionend","transitionrun","transitioncancel","scroll","resize","load","unload","beforeunload","cut","copy","paste","compositionstart","compositionupdate","compositionend"]);function ft(e=X){if(Ns.test(e))return e;return`CustomEvent<${e}>`}function zs(e){return qs.has(e)}function Qn(e){switch(e.type){case"dispatched":return ft(e.detail);case"forwarded":{let t=e.element,o=!(t&&Os.test(t))||zs(e.name),r=e.detail!==void 0&&e.detail!=="undefined"&&!(e.detail==="null"&&o),s=e.detail==="null"&&!o;if(r||s)return ft(e.detail);else if(o)return`${Ks()}["${e.name}"]`;else return ft()}default:return e}}function Ys(e){if(e.events.length===0)return Ts;let t=e.events.map((n)=>{let o="",r=fe(n.description,n.tags,n.deprecated);if(r)o=`${r}
|
|
111
|
+
`;return`${o}${ge(n.name)}: ${Qn(n)};
|
|
112
|
+
`}).join("");return e.events.length===1?`{${t}}`:`{
|
|
113
|
+
${t}}`}function Qs(e,t){return e.events.map((n)=>{let o=`on${n.name}`;if(t.has(o))return;let r="",s=fe(n.description,n.tags,n.deprecated);if(s)r=`${s}
|
|
114
|
+
`;return`
|
|
115
|
+
${r}${ge(o)}?: (event: ${Qn(n)}) => void;`}).filter((n)=>n!==void 0)}function Zs(e){let t=e.type==="() => any";if(e.type&&Hn.test(e.type)&&!t)return e.type;else if(e.params&&e.params.length>0){let o=e.params.map((s)=>{let i=s.optional?"?":"";return`${s.name}${i}: ${s.type}`}).join(", "),r=e.returnType||X;return`(${o}) => ${r}`}else if(e.returnType)return`() => ${e.returnType}`;else return e.type||X}function Zn(e){return e.props.filter((t)=>t.isFunctionDeclaration||t.kind==="const").map((t)=>{let n=Ct(t.description,t.deprecated,t.tags),o=Zs(t);return`
|
|
116
|
+
${Et(n)}
|
|
117
|
+
${t.name}: ${o};`}).join(`
|
|
118
|
+
`)}function ei(e){let t=`${e.moduleName}Exports`,n=Zn({props:e.props});if(n.trim()==="")return{exports_name:t,exports_ref:t,exports_def:`export type ${t} = ${gt};`};let{declSuffix:o,refSuffix:r}=Us(e.generics,n);return{exports_name:t,exports_ref:`${t}${r}`,exports_def:`export type ${t}${o} = {${n}
|
|
119
|
+
};`}}function ti(e){let t=e.props.filter((n)=>n.bindable===!0||n.binding==="writable").map((n)=>`"${n.name}"`);return t.length===0?M:t.join(" | ")}function ni(e){let t=e.moduleName==="default"?"$$Component":e.moduleName,n=e.bindings===M?'""':e.bindings;return`declare const ${t}: Component<
|
|
120
|
+
${e.propsRef},
|
|
121
|
+
${e.exportsRef},
|
|
122
|
+
${n}
|
|
123
|
+
>;
|
|
124
|
+
export default ${t};`}function oi(e){let t=e.moduleName==="default"?"$$Component":e.moduleName,n=`${t}Component`,o=e.bindings===M?'""':e.bindings;return`interface ${n} {
|
|
125
|
+
new ${e.generic}(
|
|
126
|
+
options: ComponentConstructorOptions<${e.propsRef}>
|
|
127
|
+
): SvelteComponent<${e.propsRef}> & ${e.exportsRef};
|
|
128
|
+
${e.generic}(
|
|
129
|
+
this: void,
|
|
130
|
+
internals: ComponentInternals,
|
|
131
|
+
props: ${e.propsRef}
|
|
132
|
+
): {
|
|
133
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
134
|
+
$set?(props: Partial<${e.propsRef}>): void;
|
|
135
|
+
} & ${e.exportsRef};
|
|
136
|
+
element?: typeof HTMLElement;
|
|
137
|
+
z_$$bindings?: ${o};
|
|
138
|
+
}
|
|
139
|
+
declare const ${t}: ${n};
|
|
140
|
+
export default ${t};`}function ri(e){if(e.extends===void 0)return"";return`import type { ${e.extends.interface} } from ${e.extends.import};`}function si(e){if(!e.componentComment)return"";if(!_s.test(e.componentComment))return _e(e.componentComment.trim());return`/*${e.componentComment.split(`
|
|
141
|
+
`).map((t)=>`* ${t}`).join(`
|
|
142
|
+
`)}
|
|
143
|
+
*/`}function ii(e){return e.moduleExports.map((t)=>{let n=Ct(t.description,t.deprecated,t.tags),o,r=t.type&&Hn.test(t.type),s=t.type==="() => any";if(t.kind==="const"&&!r)o=`export declare const ${t.name}: ${t.type||X};
|
|
144
|
+
`;else if(t.params&&t.params.length>0){let a=t.params.map((c)=>{let l=c.optional?"?":"";return`${c.name}${l}: ${c.type}`}).join(", "),p=t.returnType||X;o=`export declare function ${t.name}(${a}): ${p};`}else if(t.returnType)o=`export declare function ${t.name}(): ${t.returnType};`;else if(r&&t.type&&!s){let[i,a,...p]=t.type.split("=>"),c=p.map((l)=>` => ${l.trim()}`).join("");o=`export declare function ${t.name}${i.trimEnd()}: ${a.trim()}${c};`}else if(r&&t.type){let[i,a,...p]=t.type.split("=>"),c=p.map((l)=>` => ${l.trim()}`).join("");o=`export declare function ${t.name}${i.trimEnd()}: ${a.trim()}${c};`}else if(t.kind==="const")o=`export declare const ${t.name}: ${t.type||X};
|
|
145
|
+
`;else o=`export type ${t.name} = ${t.type||X};`;return`
|
|
146
|
+
${Et(n)}
|
|
147
|
+
${o}`}).join(`
|
|
148
|
+
`)}var ai=120;function pi(e){let n=`export default class ${e.moduleName==="default"?"":e.moduleName}${e.generic} extends SvelteComponentTyped<`,o=[e.genericProps,e.events,e.slots];if(e.accessors.trim()===""&&o.every((r)=>!r.includes(`
|
|
149
|
+
`))){let r=`${n}${o.join(", ")}> {}`;if(r.length<=ai)return r}return`${n}
|
|
150
|
+
${e.genericProps},
|
|
151
|
+
${e.events},
|
|
152
|
+
${e.slots}
|
|
153
|
+
> {
|
|
154
|
+
${e.accessors}
|
|
155
|
+
}`}function vt(e,t){let n=te(e),{moduleName:o,typedefs:r,generics:s,props:i,moduleExports:a,slots:p,events:c,rest_props:l,extends:d,componentComment:m,contexts:f,syntaxMode:g}=e,h=t?.format==="component",u=s!==null,{props_name:C,prop_def:y}=Hs({moduleName:o,props:i,rest_props:l,extends:d,generics:s,slots:p,canonicalPropNames:new Set(n?.canonicalPropNames??[]),canonicalPropsType:n?.canonicalPropsType,events:h&&g==="legacy"?c:void 0}),S=s?`<${s[1]}>`:"",E=s?`${C}<${s[0]}>`:C,P=ii({moduleExports:a}),A=Fe({typedefs:r}),O=zn({contexts:f,generics:s}),D=(n?.typeImportStatements??[]).join(`
|
|
156
|
+
`),w=(n?.localTypeDeclarations??[]).join(`
|
|
157
|
+
|
|
158
|
+
`),{exports_ref:U,exports_def:b}=h?ei({props:i,moduleName:o,generics:s}):{exports_ref:M,exports_def:M},x=h?ti({props:i}):M,k=!Fs.test(D)&&(ne.test(y)||ne.test(P)||ne.test(A)||ne.test(O)||ne.test(w)||ne.test(b)),_=l?.type==="Element"&&(l.name!=="svelte:element"||l.name==="svelte:element"&&l.thisValue),I=l?.type==="Element"&&l.name==="svelte:element"&&!l.thisValue,fo=[h?u?`import type { SvelteComponent, ComponentConstructorOptions, ComponentInternals${k?", Snippet":""} } from "svelte";`:`import type { Component${k?", Snippet":""} } from "svelte";`:`import { SvelteComponentTyped${k?", type Snippet":""} } from "svelte";`,_?'import type { SvelteHTMLElements } from "svelte/elements";':"",I?'import type { HTMLAttributes } from "svelte/elements";':"",D,ri({extends:d})].filter(Boolean).join(`
|
|
159
|
+
`),go=h?u?oi({moduleName:o,generic:S,propsRef:E,exportsRef:U,bindings:x}):ni({moduleName:o,propsRef:E,exportsRef:U,bindings:x}):pi({moduleName:o,generic:S,genericProps:E,events:Ys({events:c}),slots:Xs({slots:p}),accessors:Zn({props:i})}),yo=[P,A,w,O,y,b,[si({componentComment:m}),go].filter(Boolean).join(`
|
|
160
|
+
`)].map((ho)=>ho.trim()).filter(Boolean).join(`
|
|
161
|
+
|
|
162
|
+
`);return Wn([fo,yo].filter(Boolean).join(`
|
|
163
|
+
|
|
164
|
+
`))}var St=/`/g,Ie=/\s+/g,F="--",eo=`| Prop name | Required | Kind | Reactive | Binding | Type | Default value | Description |
|
|
165
|
+
| :- | :- | :- | :- | :- | :- | :- | :- |
|
|
166
|
+
`,to=`| Slot name | Default | Props | Fallback | Description |
|
|
167
|
+
| :- | :- | :- | :- | :- |
|
|
168
|
+
`,no=`| Event name | Type | Detail | Description |
|
|
169
|
+
| :- | :- | :- | :- |
|
|
170
|
+
`,oo=`| Name | Kind | Type | Description |
|
|
171
|
+
| :- | :- | :- | :- |
|
|
172
|
+
`,Be=/\|/g,ci=/</g,li=/>/g,oe=/\n/g;function Y(e){if(e===void 0)return F;return`<code>${e.replace(Be,"|")}</code>`}function ye(e){return e.replace(ci,"<").replace(li,">")}function ro(e){if(e===void 0)return F;return`<code>${e.replace(St,"\\`").replace(Be,"|")}</code>`}function Ge(e,t){if(t===void 0)return e;let n=typeof t==="string"&&t.trim().length>0?`: ${ye(t).replace(oe," ").replace(Be,"|")}`:"";return`<s>${e}</s><br />**Deprecated**${n}`}function We(e){if(e===void 0||e.trim().length===0)return F;return ye(e).replace(oe,"<br />")}function so(e){if(e===void 0||e==="{}")return F;return Y(Me(e).replace(oe," "))}function io(e){if(e===void 0)return F;return Y(ye(e).replace(oe,"<br />"))}function ao(e,t){let n=[];if(e!==void 0&&e.trim().length>0)n.push(ye(e));for(let{name:o,body:r}of t??[]){let s=r?.trim();n.push(s?`@${o} ${ye(s)}`:`@${o}`)}if(n.length===0)return F;return n.join(`
|
|
173
|
+
`).replace(Be,"|").replace(oe,"<br />")}function po(e){if(e===void 0)return F;return Y(e.replace(oe," "))}function co(e,t,n){if(e.append("h1","Component Index"),e.append("h2","Components").tableOfContents(),e.append("divider"),n&&n.length>0)ui(e,n);let o=j(t);for(let r of o.components)di(e,r)}function ui(e,t){e.append("h2","Exports"),e.append("raw",oo);for(let n of t){let o=(n.type??n.value)?.replace(Ie," ").trim();e.append("raw",`| ${n.name} | ${`<code>${n.kind}</code>`} | ${Y(o)} | ${We(n.description)} |
|
|
174
|
+
`)}e.append("raw",`
|
|
175
|
+
`),e.append("divider")}function bt(e,t,n,o){if(t.length>0)n(),e.append("raw",`
|
|
176
|
+
`);else e.append("p",o??"None.")}function di(e,t){if(e.append("h2",`\`${t.moduleName}\``),t.generics)e.append("p",`**Type parameters:** ${Y(`<${t.generics[1]}>`)}`);if(t.typedefs.length>0)e.append("h3","Types").append("raw",`\`\`\`ts
|
|
177
|
+
${Fe({typedefs:t.typedefs})}
|
|
178
|
+
\`\`\`
|
|
179
|
+
|
|
180
|
+
`);e.append("h3","Props"),bt(e,t.props,()=>{e.append("raw",eo);let n=[...t.props].sort((o)=>{if(o.reactive)return-1;if(o.constant)return 1;return 0});for(let o of n)e.append("raw",`| ${Ge(o.name,o.deprecated)} | ${o.isRequired?"Yes":"No"} | ${`<code>${o.kind}</code>`} | ${o.reactive?"Yes":"No"} | ${o.binding??"--"} | ${Y(o.type)} | ${ro(o.value)} | ${We(o.description)} |
|
|
181
|
+
`)}),e.append("h3","Slots"),bt(e,t.slots,()=>{e.append("raw",to);for(let n of t.slots)e.append("raw",`| ${Ge(n.default?F:n.name??F,n.deprecated)} | ${n.default?"Yes":"No"} | ${so(n.slot_props)} | ${io(n.fallback)} | ${ao(n.description,n.tags)} |
|
|
182
|
+
`)}),e.append("h3","Events"),bt(e,t.events,()=>{e.append("raw",no);for(let n of t.events)e.append("raw",`| ${Ge(n.name,n.deprecated)} | ${n.type} | ${n.type==="dispatched"?po(n.detail):F} | ${We(n.description)} |
|
|
183
|
+
`)})}class Pt{sourceParts=[];hasToC=!1;toc=[];get source(){return this.sourceParts.join("")}appendLineBreaks(){return this.sourceParts.push(`
|
|
184
|
+
|
|
185
|
+
`),this}append(e,t){switch(e){case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":{let n=Number(e.slice(-1));if(this.sourceParts.push(`${"#".repeat(n)} ${t}`),this.hasToC&&e==="h2")this.toc.push({indent:0,raw:t??""});break}case"quote":this.sourceParts.push(`> ${t}`);break;case"p":this.sourceParts.push(t??"");break;case"divider":this.sourceParts.push("---");break;case"raw":this.sourceParts.push(t??"");break}if(e!=="raw")this.appendLineBreaks();return this}tableOfContents(){return this.sourceParts.push("<!-- __TOC__ -->"),this.hasToC=!0,this.appendLineBreaks(),this}end(){return this.sourceParts.join("").replace("<!-- __TOC__ -->",this.toc.map(({indent:t,raw:n})=>`${" ".repeat(t)}- [${n}](#${n.toLowerCase().replace(St,"").replace(Ie,"-")})`).join(`
|
|
186
|
+
`))}}class Le extends R{onAppend;markdownBase;constructor(e){super();this.onAppend=e.onAppend,this.markdownBase=new Pt}get source(){return this.markdownBase.source}get hasToC(){return this.markdownBase.hasToC}get toc(){return this.markdownBase.toc}appendLineBreaks(){return this.markdownBase.appendLineBreaks(),this}append(e,t){return this.markdownBase.append(e,t),this.onAppend?.call(this,e,this),this}tableOfContents(){return this.markdownBase.tableOfContents(),this}end(){return this.markdownBase.end()}}function $t(e,t){let n=new Le({onAppend:(o,r)=>{t.onAppend?.call(null,o,r,e)}});return co(n,e,t.entryExports),n.end()}async function kt(e,t){let n=t?.write!==!1,o=$t(e,t);if(n){let r=mi(process.cwd(),t.outFile);if(await new R({dryRun:t.dryRun}).write(r,o),!t.dryRun)J(`created "${t.outFile}".`)}return o}import{join as lo}from"node:path";async function Dt(e,t){let n=lo(process.cwd(),t.outDir,"index.d.ts"),o=new R({dryRun:t.dryRun}),r=t.preamble+On(t.exports),s=j(e),i=t.format??"class",a=s.components.map(async(p)=>{let c=jn(lo(t.outDir,p.filePath)),l=t.resolvedPathByFilePath?.get(p.filePath),d=l?t.cache?.getGeneratedText(l,i):void 0;if(d===void 0){if(d=vt(p,{format:t.format}),l)t.cache?.setGeneratedText(l,i,d)}await o.write(c,d)});if(await Promise.all([...a,o.write(n,`${r}
|
|
187
|
+
`)]),!t.dryRun)J("created TypeScript definitions.")}se({name:"json",componentSet:"exported",write:mt});se({name:"markdown",componentSet:"exported",write:kt});se({name:"types",componentSet:"all",write:Dt});se({name:"custom-elements",componentSet:"exported",write:ct});var fi=50;function gi(e){let t=e?.watch===!0,n,o,r=null,s,i=new Set,a=async()=>{if(r==null||o==null||i.size===0)return;let c=Array.from(i);i.clear();try{let{result:l}=await r.update(c);await he(l,e||{},o)}catch(l){console.error("sveld: failed to regenerate types in watch mode:",l)}},p=(c)=>{if(!t||r==null||!B.test(c))return;i.add(c),clearTimeout(s),s=setTimeout(a,fi)};return{name:"vite-plugin-sveld",apply:t?void 0:"build",enforce:"post",async buildStart(){if(o=Ne(e?.entry),t&&o!=null)r=await Tn(o,e?.glob===!0,e?.documentExports===!0),await he(r.result,e||{},o)},async generateBundle(){if(t)return;if(o!=null)n=await me(o,e?.glob===!0,de(e))},async writeBundle(){if(t)return;if(o!=null)await he(n,e||{},o),n.cache?.save()},handleHotUpdate(c){p(c.file)},watchChange(c){p(c)}}}function Ve(e,t,n){let o=Xe(e);if(!o)throw Error(`sveld: built-in writer "${e}" is not registered.`);return o.write(t,n)}async function he(e,t,n){let o=uo(n),r=t?.dryRun===!0;if(t?.types!==!1)await Ve("types",e.allComponentsForTypes,{outDir:"types",preamble:"",...t?.typesOptions,exports:e.exports,inputDir:o,dryRun:r,cache:e.cache,resolvedPathByFilePath:e.resolvedPathByFilePath});if(t?.json)await Ve("json",e.components,{outFile:"COMPONENT_API.json",...t?.jsonOptions,input:n,inputDir:o,entryExports:e.entryExports,dryRun:r});if(t?.markdown)await Ve("markdown",e.components,{outFile:"COMPONENT_INDEX.md",...t?.markdownOptions,entryExports:e.entryExports,dryRun:r});if(t?.customElements)await Ve("custom-elements",e.components,{outFile:"custom-elements.json",...t?.customElementsOptions,inputDir:o,dryRun:r});let s=Object.entries(t?.additionalWriters??{}).map(([i,a])=>{let p=Xe(i);if(!p){console.warn(`sveld: no writer registered with name "${i}"; skipping.`);return}let c=p.componentSet==="all"?e.allComponentsForTypes:e.components;return p.write(c,a)});await Promise.all(s)}async function mo(e,t,n){let o=uo(n);if(t?.json){let r={...t?.jsonOptions,inputDir:o,entryExports:e.entryExports},s=t.stdout==="ndjson"?Mn(e.components,r):dt(e.components,r);process.stdout.write(s);return}if(t?.markdown){let r=$t(e.components,{...t?.markdownOptions,entryExports:e.entryExports});process.stdout.write(r);return}if(t?.customElements){let r=pt(e.components,{...t?.customElementsOptions,inputDir:o});process.stdout.write(r)}}import{existsSync as yi}from"node:fs";import{join as hi}from"node:path";var wt="src/index.js",N={SUCCESS:0,USAGE_ERROR:1,GENERATION_FAILURE:2,BREAKING_CHANGE:3,DIAGNOSTICS:4},xi=`Usage: sveld [options]
|
|
188
|
+
|
|
189
|
+
Generate TypeScript definitions and component documentation for a Svelte
|
|
190
|
+
library. With no flags, only TypeScript definitions are generated for the
|
|
191
|
+
entry resolved from package.json#svelte.
|
|
192
|
+
|
|
193
|
+
--entry, --cache, --check, and --types-format accept their value as
|
|
194
|
+
--flag=value or as a separate --flag value argument.
|
|
195
|
+
|
|
196
|
+
Options:
|
|
197
|
+
--entry=<path> Entry point to uncompiled Svelte source (default: package.json "svelte" field)
|
|
198
|
+
--glob Analyze all *.svelte files instead of the entry barrel
|
|
199
|
+
--types Generate TypeScript definitions (default: true)
|
|
200
|
+
--json Generate component documentation in JSON format
|
|
201
|
+
--markdown Generate component documentation in Markdown format
|
|
202
|
+
--custom-elements Generate a Custom Elements Manifest (custom-elements.json)
|
|
203
|
+
--fail-fast Abort the run when a single component fails to parse
|
|
204
|
+
--dry-run Resolve, parse, and print "would write" lines for each output file instead of writing anything (including the parse cache)
|
|
205
|
+
--quiet Suppress progress logs (errors, the diagnostics summary, and the --check report are unaffected)
|
|
206
|
+
--stdout[=json|ndjson] Print the document from exactly one of --json, --markdown, or --custom-elements to stdout and write nothing to disk (rejects --types and --check); --stdout=ndjson prints one JSON object per component per line and requires --json
|
|
207
|
+
--cache[=<path>] Persist parsed output and skip re-parsing unchanged files (on by default, default path: node_modules/.cache/sveld/parse-cache.json; pass --cache=false to disable)
|
|
208
|
+
--resolve-types Expand opaque imported $props() types into JSON (alias: --resolveTypes, deprecated)
|
|
209
|
+
--check-examples Compile-check @example blocks against the TypeScript program (alias: --checkExamples, deprecated)
|
|
210
|
+
--report-diagnostics Print unresolved-type diagnostics to stderr
|
|
211
|
+
--strict Exit with code 1 when diagnostics exist (implies --report-diagnostics)
|
|
212
|
+
--types-format=<format> ".d.ts" output format: "class" (default) or "component" (Svelte 5 Component<...>)
|
|
213
|
+
--check[=<path>] Diff the parsed API against a committed snapshot; exit 1 on a breaking change (default path: COMPONENT_API.json)
|
|
214
|
+
--format=<text|json> Output format for the --check report and the diagnostics summary (default: text)
|
|
215
|
+
--help Print this help message and exit
|
|
216
|
+
--version Print the installed sveld version and exit
|
|
217
|
+
|
|
218
|
+
Exit codes:
|
|
219
|
+
0 success
|
|
220
|
+
1 usage or configuration error
|
|
221
|
+
2 generation failure
|
|
222
|
+
3 breaking API change detected by --check
|
|
223
|
+
4 diagnostics present under --strict
|
|
224
|
+
`,Tt={resolveTypes:"resolve-types",checkExamples:"check-examples"},Ci=["help","version","glob","types","json","markdown","quiet","stdout","custom-elements","strict","report-diagnostics","resolve-types","check-examples","fail-fast","entry","cache","check","types-format","format"],Ei=[...Ci,...Object.keys(Tt)],vi=new Set(["glob","types","json","markdown","quiet","custom-elements","strict","report-diagnostics","resolve-types","check-examples","fail-fast"]),Si=new Set(["entry","cache","check","types-format"]),bi=new Set(["entry","types-format"]),Pi=3;function $i(e,t){let n=e.length+1,o=t.length+1,r=Array.from({length:n},()=>Array(o).fill(0));for(let s=0;s<n;s++)r[s][0]=s;for(let s=0;s<o;s++)r[0][s]=s;for(let s=1;s<n;s++)for(let i=1;i<o;i++){let a=e[s-1]===t[i-1]?0:1;r[s][i]=Math.min(r[s-1][i]+1,r[s][i-1]+1,r[s-1][i-1]+a)}return r[n-1][o-1]}function ki(e){let t,n=Number.POSITIVE_INFINITY;for(let o of Ei){let r=$i(e,o);if(r<n)t=o,n=r}if(t===void 0||n>Pi)return;return Tt[t]??t}function Di(e,t){let n=e.indexOf("="),o=n===-1?e.slice(2):e.slice(2,n),r=Tt[o]??o,s=n===-1?!0:e.slice(n+1),i=!1;if(n===-1&&Si.has(r)){if(t!==void 0&&!t.startsWith("--"))s=t,i=!0;else if(bi.has(r))return{result:{kind:"usage-error",message:`sveld: --${r} requires a value (pass --${r}=<value> or --${r} <value>).`},consumedNext:!1,flag:r}}return{result:wi(r,s,e,o),consumedNext:i,flag:r}}function wi(e,t,n,o){switch(e){case"help":return{kind:"help"};case"version":return{kind:"version"};case"glob":case"types":case"json":case"markdown":case"quiet":return{kind:"option",option:{[e]:t===!0||t==="true"}};case"stdout":if(t===!0||t==="true")return{kind:"option",option:{stdout:!0}};if(t==="false")return{kind:"option",option:{stdout:!1}};return{kind:"option",option:{stdout:t}};case"custom-elements":return{kind:"option",option:{customElements:t===!0||t==="true"}};case"strict":return{kind:"option",option:{strict:t===!0||t==="true"}};case"report-diagnostics":return{kind:"option",option:{reportDiagnostics:t===!0||t==="true"}};case"resolve-types":return{kind:"option",option:{resolveTypes:t===!0||t==="true"}};case"check-examples":return{kind:"option",option:{checkExamples:t===!0||t==="true"}};case"fail-fast":return{kind:"option",option:{failFast:t===!0||t==="true"}};case"dry-run":return{kind:"option",option:{dryRun:t===!0||t==="true"}};case"entry":return typeof t==="string"?{kind:"option",option:{entry:t}}:{kind:"option",option:{}};case"cache":if(t==="false")return{kind:"option",option:{cache:!1}};return{kind:"option",option:{cache:typeof t==="string"?t:!0}};case"check":if(t==="false")return{kind:"option",option:{check:!1}};return{kind:"option",option:{check:typeof t==="string"?t:!0}};case"types-format":return typeof t==="string"?{kind:"option",option:{typesOptions:{format:t}}}:{kind:"option",option:{}};case"format":return typeof t==="string"?{kind:"option",option:{format:t}}:{kind:"option",option:{}};default:return{kind:"unknown",arg:n,suggestion:ki(o)}}}function Ti(e){let t={},n=!1;for(let o=0;o<e.length;o++){let r=e[o];if(!r.startsWith("--"))return{kind:"unknown",arg:r,positionalHint:n?!0:void 0};let{result:s,consumedNext:i,flag:a}=Di(r,e[o+1]);if(s.kind!=="option")return s;if(Object.assign(t,s.option),n=vi.has(a),i)o++}return{kind:"options",options:t}}async function Jc(e){let t=Ti(e.argv.slice(2));if(t.kind==="help"){console.log(xi);return}if(t.kind==="version"){console.log(Rt.version);return}if(t.kind==="usage-error"){console.error(t.message),e.exitCode=N.USAGE_ERROR;return}if(t.kind==="unknown"){let m=`Unknown flag: ${t.arg}`;if(t.suggestion)m+=` Did you mean --${t.suggestion}?`;if(t.positionalHint)m+=" (values are passed as --flag=value or --flag value)";console.error(m),console.error("Run sveld --help for a list of available flags."),e.exitCode=N.USAGE_ERROR;return}let n=t.options,o=await Wt(),r=Lt(o,n);if(o.typesOptions||n.typesOptions)r.typesOptions={...o.typesOptions,...n.typesOptions};if(r.stdout){if(r.stdout!==!0&&r.stdout!=="json"&&r.stdout!=="ndjson"){console.error(`sveld: --stdout must be "json" or "ndjson"; got "${r.stdout}".`),e.exitCode=N.USAGE_ERROR;return}if([r.json,r.markdown,r.customElements].filter(Boolean).length!==1){console.error("sveld: --stdout requires exactly one of --json, --markdown, or --custom-elements."),e.exitCode=N.USAGE_ERROR;return}if(r.stdout==="ndjson"&&!r.json){console.error("sveld: --stdout=ndjson is only valid with --json."),e.exitCode=N.USAGE_ERROR;return}if(r.types===!0){console.error("sveld: --stdout cannot be combined with --types; type definitions span multiple files."),e.exitCode=N.USAGE_ERROR;return}if(r.check){console.error("sveld: --stdout cannot be combined with --check; both write their document to stdout."),e.exitCode=N.USAGE_ERROR;return}}if(r.format!==void 0&&r.format!=="text"&&r.format!=="json"){console.error(`sveld: --format must be "text" or "json"; got "${r.format}".`),e.exitCode=N.USAGE_ERROR;return}Rn(r.quiet===!0);let s=Ne(r.entry),i;if(s!==null)i=s;else if(yi(hi(e.cwd(),wt)))console.error(`sveld: could not resolve an entry point; falling back to "${wt}". Set package.json#svelte (or pass --entry) to avoid relying on this fallback.`),i=ie(T(wt));else{e.exitCode=N.USAGE_ERROR;return}let a,p;try{if(a=await me(i,r.glob===!0,de(r)),r.check)p=await It(a.components,Ft(r),{entryExports:a.entryExports});if(r.stdout)await mo(a,r,i);else if(await he(a,r,i),!r.dryRun)a.cache?.save()}catch(m){console.error(m instanceof Error?m.message:String(m)),e.exitCode=N.GENERATION_FAILURE;return}let{diagnostics:c}=a;if((r.reportDiagnostics||r.strict)&&c.length>0)if(r.format==="json")e.stderr.write(Jt(c));else console.error(Vt(c));if(p)if(r.format==="json")e.stdout.write(Gt(p));else console.log(Bt(p));let d;if(p?.bump==="major")d=N.BREAKING_CHANGE;if(r.strict&&c.length>0)d=d===void 0?N.DIAGNOSTICS:Math.min(d,N.DIAGNOSTICS);if(d!==void 0)e.exitCode=d}
|
|
225
|
+
export{j as a,To as b,Ft as c,It as d,Bt as e,Gt as f,Vt as g,Ne as h,Xi as i,Wt as j,Lt as k,de as l,me as m,se as n,Xe as o,qi as p,gi as q,he as r,Jc as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{na as a,oa as b}from"./chunk-0beysrt7.js";import"./chunk-nrz6c5ew.js";import"./chunk-ptdfswsv.js";export{a as parse,b as parseModern};
|