// BANNER START const require = (await import("node:module")).createRequire(import.meta.url); const __filename = (await import("node:url")).fileURLToPath(import.meta.url); const __dirname = (await import("node:path")).dirname(__filename); // BANNER END "use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { default: () => src_default, getNuxtStyleRouteName: () => getNuxtStyleRouteName }); module.exports = __toCommonJS(src_exports); var import_common = require("@vue-macros/common"); var import_unplugin = require("unplugin"); // src/utils.ts function getNuxtStyleRouteName(node) { var _a; if (((_a = node.parent) == null ? void 0 : _a.isRoot()) && node.value.pathSegment === "") return "index"; let name = node.value.subSegments.map((segment) => { if (typeof segment === "string") return `-${segment}`; return segment.paramName; }).join(""); if (node.value.components.size && node.children.has("index")) name += "/"; const parent = node.parent; return ((parent && !parent.isRoot() ? getNuxtStyleRouteName(parent).replace(/\/$/, "") : "") + name).replace(/^-|-$/, ""); } // src/index.ts var src_default = (0, import_unplugin.createUnplugin)((options) => ({ name: "unplugin-vue-router-extend", enforce: "pre", transform(code, id) { var _a; const name = (_a = options.routeMap.get(id)) == null ? void 0 : _a.name; if (!name) return; const lang = (0, import_common.getLang)(id); const s = new import_common.MagicString(code); if (lang === "vue") { const sfc = (0, import_common.parseSFC)(code, id); if (sfc.script) { const offset = sfc.script.loc.start.offset; transformAST(sfc.getScriptAst(), name, s, offset); } else { const normalScript = (0, import_common.addNormalScript)(sfc, s); const scriptOffset = normalScript.start(); s.appendLeft( scriptOffset, ` import { defineComponent } from 'vue' export default /* @__PURE__ */ defineComponent({ name: '${name}' })` ); normalScript.end(); } } else if (/[jt]sx?$/.test(lang)) { const ast = (0, import_common.babelParse)(code, lang); transformAST(ast, name, s); } return (0, import_common.generateTransform)(s, id); } })); function transformAST(ast, name, s, offset = 0) { var _a, _b; for (const stmt of ast.body) { if (stmt.type === "ExportDefaultDeclaration" && stmt.declaration.type === "CallExpression" && stmt.declaration.callee.type === "Identifier" && stmt.declaration.callee.name === "defineComponent") { const argument = stmt.declaration.arguments.find((i) => i.type === "ObjectExpression"); if (argument) { if (!((_a = argument.properties) == null ? void 0 : _a.find( (prop) => prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "name" ))) { s.appendLeft( offset + argument.end - 1, `${!((_b = argument.extra) == null ? void 0 : _b.trailingComma) && argument.properties.length ? "," : ""} name: '${name}'` ); } } else { s.appendRight(offset + stmt.declaration.end - 1, `, { name: '${name}' }`); } } } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getNuxtStyleRouteName }); exports.default = module.exports;