{"version":3,"file":"emit.cjs","names":[],"sources":["../../../src/codegen/emit.ts"],"sourcesContent":["import { print } from \"esrap\";\nimport ts from \"esrap/languages/ts\";\n\nimport { DEFAULT_FORMATTING } from \"../config.js\";\nimport type { GeneratedModel } from \"../types.js\";\nimport {\n  buildVirtualManifestProgram,\n  joinManifestSections,\n  type EmitManifestOptions,\n} from \"./manifest.js\";\nimport { buildFullProgram } from \"./types.js\";\n\nexport type { EmitManifestOptions };\n\nexport type ManifestEmitKind = \"virtual\" | \"ambient-types\" | \"standalone-manifest\";\n\nexport type EmitManifestSourceOptions = EmitManifestOptions & {\n  kind?: ManifestEmitKind | undefined;\n};\n\nfunction unwrapDefault<T>(mod: T): T {\n  let curr: any = mod;\n  while (\n    curr &&\n    typeof curr !== \"function\" &&\n    typeof curr === \"object\" &&\n    \"default\" in curr &&\n    curr.default\n  ) {\n    curr = curr.default;\n  }\n  return curr;\n}\n\n/**\n * Emits route manifest source for a given program shape.\n *\n * - `virtual` — runtime manifest only (no `as const`, no type aliases)\n * - `ambient-types` — full program for `routes.d.ts`\n * - `standalone-manifest` — full program for standalone manifest files\n *\n * All kinds default to `DEFAULT_FORMATTING.quotes` when `quotes` is omitted.\n */\nexport function emitManifestSource(\n  model: GeneratedModel,\n  options: EmitManifestSourceOptions = {},\n): string {\n  const kind = options.kind ?? \"virtual\";\n  const quotes = options.quotes ?? DEFAULT_FORMATTING.quotes;\n  const program =\n    kind === \"virtual\"\n      ? buildVirtualManifestProgram(model, options.rewriteImportPath)\n      : buildFullProgram(model, options);\n\n  const printFn = unwrapDefault(print);\n  const tsLang = unwrapDefault(ts);\n  const { code } = printFn(program, tsLang({ quotes }));\n  const header = kind === \"virtual\" ? (options.header ?? []) : options.header;\n  return joinManifestSections(header, code);\n}\n\nexport function emitVirtualManifestSource(\n  model: GeneratedModel,\n  options: Partial<EmitManifestOptions> = {},\n): string {\n  return emitManifestSource(model, { ...options, kind: \"virtual\" });\n}\n\nexport function emitTypeDeclarationsSource(\n  model: GeneratedModel,\n  options: Partial<EmitManifestOptions> = {},\n): string {\n  return emitManifestSource(model, { ...options, kind: \"ambient-types\" });\n}\n\nexport function emitRouteManifestSource(\n  model: GeneratedModel,\n  options: EmitManifestOptions = {},\n): string {\n  return emitManifestSource(model, { ...options, kind: \"standalone-manifest\" });\n}\n"],"mappings":";;;;;;;;AAoBA,SAAS,cAAiB,KAAW;CACnC,IAAI,OAAY;CAChB,OACE,QACA,OAAO,SAAS,cAChB,OAAO,SAAS,YAChB,aAAa,QACb,KAAK,SAEL,OAAO,KAAK;CAEd,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,mBACd,OACA,UAAqC,CAAC,GAC9B;CACR,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,SAAS,QAAQ,UAAU,eAAA,mBAAmB;CACpD,MAAM,UACJ,SAAS,YACL,iBAAA,4BAA4B,OAAO,QAAQ,iBAAiB,IAC5D,cAAA,iBAAiB,OAAO,OAAO;CAIrC,MAAM,EAAE,SAFQ,cAAc,MAAA,KAEb,CAAA,CAAQ,SADV,cAAc,mBAAA,OACK,CAAA,CAAO,EAAE,OAAO,CAAC,CAAC;CAEpD,OAAO,iBAAA,qBADQ,SAAS,YAAa,QAAQ,UAAU,CAAC,IAAK,QAAQ,QACjC,IAAI;AAC1C;AASA,SAAgB,2BACd,OACA,UAAwC,CAAC,GACjC;CACR,OAAO,mBAAmB,OAAO;EAAE,GAAG;EAAS,MAAM;CAAgB,CAAC;AACxE"}