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BAChD,IAAK,iBAEP,eAAe,oBAAoB,EAAS,GAC/C,MAAM,EAAU,0BAA0B,KAc1C,IAAI,EACJ,GAFmB,KAAK,WAAW,IAAY,EAAQ,WAAW,MAAQ,EAAQ,WAAW,MAAQ,kBAAkB,KAAK,GAE5G,CACZ,MAAM,EAAM,KAAK,WAAW,GAAW,EAAU,KAAK,QAAQ,QAAQ,MAAO,GAC7E,IAAK,GAAG,WAAW,GACf,MAAM,IAAI,MAAM,+BAA+B,KAEnD,EAAS,cAAc,GAAK,IAChC,KACK,CACD,MAAM,EAAW,EAAQ,QAAQ,EAAS,CAAE,MAAO,CAAC,QAAQ,SAC5D,EAAS,cAAc,GAAU,IACrC,CACA,MAAM,QAAiB,OAAO,GACxB,EA1BkB,CAAC,IACrB,MAAM,EAAa,GAAK,SAAW,GAAK,WAAa,EACrD,GAAyB,mBAAd,EACP,OAAO,EACX,GAAI,GAAkC,iBAAd,EAAwB,CAC5C,GAAiC,mBAAtB,EAAU,QACjB,OAAO,EAAU,QACrB,GAAmC,mBAAxB,EAAU,UACjB,OAAO,EAAU,SACzB,CACA,OAAO,IAAI,EAgBJ,CAAgB,GACtB,IACD,EAAM,0BACQ,mBAAP,SACD,EAAG,EAAK,EAAS,cAAW,EAE1C","file":"/npm/irgen@0.3.2/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/irgen@0.3.2/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { pathToFileURL } from \"node:url\";\nimport { createRequire } from \"node:module\";\nimport { app } from \"./dsl/runtime.js\";\nimport { frontend } from \"./dsl/frontend-runtime.js\";\nimport { aggregateDecls } from \"./dsl/aggregator.js\";\nimport { registerBuiltins, runMapper, listMappers } from \"./mappers/index.js\";\nimport { engine as loweringEngine } from \"./lowering/engine.js\";\nimport { emitterEngine } from \"./emit/engine.js\";\nimport { getEmitterForTarget } from \"./emit/registry.js\";\nimport { createExtensionContext } from \"./extensions/context.js\";\nasync function importAllEmitters() {\n    try {\n        const fs = await import(\"node:fs/promises\");\n        async function walk(dir) {\n            const entries = await fs.readdir(dir, { withFileTypes: true });\n            for (const ent of entries) {\n                if (ent.isDirectory()) {\n                    await walk(new URL(`./${ent.name}/`, dir));\n                }\n                else if (ent.name.endsWith(\".js\") || ent.name.endsWith(\".ts\")) {\n                    try {\n                        await import(new URL(`./${ent.name}`, dir).href);\n                    }\n                    catch {\n                        // ignore optional emitters\n                    }\n                }\n            }\n        }\n        await walk(new URL(\"./emit/\", import.meta.url));\n    }\n    catch {\n        // ignore missing emit folder in consumer builds\n    }\n}\nasync function ensureTargetTransforms(targets) {\n    if (targets.includes(\"backend\")) {\n        await import(\"./lowering/targets/to-backend.js\");\n    }\n    if (targets.includes(\"frontend\")) {\n        await import(\"./lowering/targets/to-frontend.js\");\n    }\n    if (targets.includes(\"electron\")) {\n        await import(\"./lowering/targets/to-electron.js\");\n    }\n    if (targets.includes(\"static-site\")) {\n        await import(\"./lowering/targets/to-static-site.js\");\n    }\n}\nfunction pickPolicy(src, target) {\n    if (!src)\n        return undefined;\n    if (src[target])\n        return src[target];\n    // Also check for kebab-case and camelCase variations\n    const camelVariant = target.replace(/-([a-z])/g, (_, c) => c.toUpperCase());\n    const targetVariations = [\n        target,\n        target.replace(/-/g, \"\"),\n        target.replace(/([A-Z])/g, \"-$1\").toLowerCase(),\n        camelVariant,\n    ];\n    for (const variant of targetVariations) {\n        if (src[variant])\n            return src[variant];\n    }\n    const keys = Object.keys(src);\n    const looksNamespaced = keys.some(k => [\"backend\", \"frontend\", \"electron\", \"cli\", \"static-site\", \"staticSite\"].includes(k));\n    return looksNamespaced ? undefined : src;\n}\nexport class Codegen {\n    extensions;\n    constructor(opts) {\n        this.extensions = opts?.extensions ?? [];\n    }\n    app = app;\n    frontend = frontend;\n    async applyExtensions() {\n        if (!this.extensions.length)\n            return;\n        const ctx = createExtensionContext();\n        for (const ext of this.extensions) {\n            const fn = Array.isArray(ext) ? ext[0] : ext;\n            const options = Array.isArray(ext) ? ext[1] : undefined;\n            await fn(ctx, options);\n        }\n    }\n    async generate(options) {\n        const targets = options.targets ?? [\"backend\"];\n        const outDir = options.outDir ?? \"generated\";\n        const prefer = targets.some(t => t === \"frontend\" || t === \"electron\" || t === \"static-site\") ? \"frontend\" : \"backend\";\n        registerBuiltins();\n        await this.applyExtensions();\n        await importAllEmitters();\n        await ensureTargetTransforms(targets);\n        const unified = await aggregateDecls(options.entries, { prefer });\n        const bundlePolicies = unified?.meta?.policies;\n        const results = {};\n        for (const target of targets) {\n            const fromDsl = pickPolicy(bundlePolicies, target);\n            const fromOpts = pickPolicy(options.policies, target);\n            const mergedPolicies = fromDsl && fromOpts ? { ...fromDsl, ...fromOpts } : fromOpts ?? fromDsl;\n            const domainIr = await runMapper(target, unified, mergedPolicies);\n            const transformName = `${target}-target`;\n            const ir = loweringEngine.getTransform(transformName)\n                ? await loweringEngine.runTransform(transformName, domainIr, mergedPolicies)\n                : domainIr;\n            results[target] = ir;\n            const chosenEmitter = options.emitterMap?.[target] ??\n                getEmitterForTarget(target) ??\n                (target === \"backend\" ? \"backend-tsmorph\" : target === \"frontend\" ? \"frontend-tsmorph\" : target === \"electron\" ? \"electron-shell\" : target === \"static-site\" ? \"static-site-html\" : null);\n            if (chosenEmitter) {\n                const multiple = targets.length > 1;\n                const targetOutDir = multiple ? path.resolve(process.cwd(), outDir, target) : path.resolve(process.cwd(), outDir);\n                await emitterEngine.runEmitter(chosenEmitter, ir, targetOutDir);\n            }\n        }\n        return { decl: unified, ir: results };\n    }\n}\nexport { createExtensionContext, listMappers, runMapper, registerBuiltins };\nexport { app, frontend };\n// helper for CLI-like extension loading\nexport async function loadExtensionModule(modPath, ctx) {\n    const require = createRequire(import.meta.url);\n    const pickExtensionFn = (mod) => {\n        const candidate = (mod?.default ?? mod?.extension ?? mod);\n        if (typeof candidate === \"function\")\n            return candidate;\n        if (candidate && typeof candidate === \"object\") {\n            if (typeof candidate.default === \"function\")\n                return candidate.default;\n            if (typeof candidate.extension === \"function\")\n                return candidate.extension;\n        }\n        return null;\n    };\n    const isPathLike = path.isAbsolute(modPath) || modPath.startsWith(\".\") || modPath.startsWith(\"/\") || /^[A-Za-z]:[\\\\/]/.test(modPath);\n    let modUrl;\n    if (isPathLike) {\n        const abs = path.isAbsolute(modPath) ? modPath : path.resolve(process.cwd(), modPath);\n        if (!fs.existsSync(abs)) {\n            throw new Error(`extension module not found: ${modPath}`);\n        }\n        modUrl = pathToFileURL(abs).href;\n    }\n    else {\n        const resolved = require.resolve(modPath, { paths: [process.cwd()] });\n        modUrl = pathToFileURL(resolved).href;\n    }\n    const imported = await import(modUrl);\n    const fn = pickExtensionFn(imported);\n    if (!ctx)\n        ctx = createExtensionContext();\n    if (typeof fn === \"function\") {\n        await fn(ctx, imported.options ?? undefined);\n    }\n}\n"]}