{"mappings":";AAAA,UAAYA,MAAW,QACvB,OAAS,oBAAAC,EAAkB,0BAAAC,MAA8B,aAEzD,SAASC,GAAc,CACnB,IAAMC,EAASH,EAAiB,EAC1BI,EAAe,OAAO,WAAe,IAAc,WAAW,cAAgB,OAC9EC,GAAWF,EAAO,MAAQC,GAAc,OAAO,QACrD,OAAO,MAAM,QAAQC,CAAO,EAAIA,EAAQ,OAAQC,GAAM,OAAOA,GAAM,QAAQ,EAAI,CAAC,CACpF,CAEA,SAASC,EAAkBC,EAAUH,EAAS,CAC1C,IAAMI,EAAQD,EAAS,MAAM,GAAG,EAAE,CAAC,GAAK,GACxC,OAAIC,GAASJ,EAAQ,KAAMC,GAAMA,EAAE,YAAY,IAAMG,EAAM,YAAY,CAAC,EAC7DD,EAAS,MAAMC,EAAM,OAAS,CAAC,GAAK,IAExCD,GAAY,GACvB,CAGA,SAASE,GAAe,CACpB,IAAMP,EAASH,EAAiB,EAC1BI,EAAe,OAAO,WAAe,IAAc,WAAW,cAAgB,OAC9EO,EAAWR,EAAO,UAAYC,GAAc,SAClD,OAAI,OAAOO,GAAa,UAAYA,IAAa,GACtCA,EACP,OAAO,OAAW,KAAe,OAAO,SACjCJ,EAAkB,OAAO,SAAS,SAAUL,EAAY,CAAC,EAE7D,GACX,CASO,SAASU,GAAc,CAC1B,OAAa,uBAAqBX,EAAwBS,EAAcA,CAAY,CACxF,CAEO,SAASG,GAAc,CAC1B,OAAOH,EAAa,CACxB,CAeO,SAASI,GAAgB,CAC5B,IAAMC,EAAOL,EAAa,EAC1B,OAAI,OAAO,OAAW,KAAe,OAAO,SACjC,GAAGK,CAAI,GAAG,OAAO,SAAS,MAAM,GAAG,OAAO,SAAS,IAAI,GAE3DA,CACX","names":["React","getTalizenConfig","subscribeTalizenConfig","readLocales","config","globalConfig","locales","l","stripLocalePrefix","pathname","first","readPathname","injected","usePathname","getPathname","getLocalePath","path"],"sources":["../esm/npm/talizen@0.2.55/node_modules/talizen/router.js"],"sourcesContent":["import * as React from \"react\";\nimport { getTalizenConfig, subscribeTalizenConfig } from \"./core.js\";\n// readLocales 读取站点配置的语言列表（仅用于回退时剥路径前缀）。直接读 TalizenConfig，不依赖 i18n 模块。\nfunction readLocales() {\n    const config = getTalizenConfig();\n    const globalConfig = typeof globalThis !== \"undefined\" ? globalThis.TalizenConfig : undefined;\n    const locales = (config.i18n ?? globalConfig?.i18n)?.locales;\n    return Array.isArray(locales) ? locales.filter((l) =\u003e typeof l === \"string\") : [];\n}\n// stripLocalePrefix 去掉路径开头的已知语言段（默认语言本就无前缀，天然命中 else）。\nfunction stripLocalePrefix(pathname, locales) {\n    const first = pathname.split(\"/\")[1] ?? \"\";\n    if (first \u0026\u0026 locales.some((l) =\u003e l.toLowerCase() === first.toLowerCase())) {\n        return pathname.slice(first.length + 1) || \"/\";\n    }\n    return pathname || \"/\";\n}\n// readPathname 返回当前页面「去掉语言前缀」的路径。优先用渲染引擎注入的 TalizenConfig.pathname\n// （SSR 与客户端一致，避免水合不一致）；缺失时在客户端回退到按 locales 剥 window.location.pathname。\nfunction readPathname() {\n    const config = getTalizenConfig();\n    const globalConfig = typeof globalThis !== \"undefined\" ? globalThis.TalizenConfig : undefined;\n    const injected = config.pathname ?? globalConfig?.pathname;\n    if (typeof injected === \"string\" \u0026\u0026 injected !== \"\")\n        return injected;\n    if (typeof window !== \"undefined\" \u0026\u0026 window.location) {\n        return stripLocalePrefix(window.location.pathname, readLocales());\n    }\n    return \"/\";\n}\n/**\n * 当前页面路径（已去掉语言前缀，SSR 与客户端返回一致，不含 query / hash）。对标 next/navigation 的 usePathname。\n * 组件渲染里用 usePathname()；服务端取数用 getPathname()。\n *\n * ```tsx\n * const pathname = usePathname()   // 访问 /en/blog 时返回 \"/blog\"\n * ```\n */\nexport function usePathname() {\n    return React.useSyncExternalStore(subscribeTalizenConfig, readPathname, readPathname);\n}\n/** usePathname 的非 hook 版本，用于 getServerSideProps / 事件回调等非渲染场景。 */\nexport function getPathname() {\n    return readPathname();\n}\n/**\n * 语言切换用的 href：当前页「去前缀路径 + 保留 query/hash」，配合 i18n 的 `\u003cLink\u003e` 使用——\n * Link 会补上目标语言前缀并写入 `CREGHT_LOCALE` cookie 记住选择：\n *\n * ```tsx\n * import { Link } from \"talizen\"\n * import { getLocalePath } from \"talizen\"\n *\n * \u003cLink href={getLocalePath()} locale=\"en\"\u003eEnglish\u003c/Link\u003e\n * \u003cLink href={getLocalePath()} locale=\"zh-CN\"\u003e中文\u003c/Link\u003e\n * ```\n *\n * query / hash 仅在客户端可得；SSR 期只返回路径部分。\n */\nexport function getLocalePath() {\n    const path = readPathname();\n    if (typeof window !== \"undefined\" \u0026\u0026 window.location) {\n        return `${path}${window.location.search}${window.location.hash}`;\n    }\n    return path;\n}\n"],"version":3}
