{"version":3,"file":"notFoundState.js","names":[],"sources":["esm/notFoundState.js"],"sourcesContent":["import * as React from \"react\";\nlet currentNotFoundState = null;\nconst notFoundListeners = /* @__PURE__ */ new Set();\nfunction getNotFoundState() {\n  return currentNotFoundState;\n}\nfunction setNotFoundState(state) {\n  currentNotFoundState = state;\n  notFoundListeners.forEach((listener) => listener());\n}\nfunction clearNotFoundState() {\n  if (currentNotFoundState !== null) {\n    currentNotFoundState = null;\n    notFoundListeners.forEach((listener) => listener());\n  }\n}\nfunction useNotFoundState() {\n  const [, forceUpdate] = React.useReducer((x) => x + 1, 0);\n  React.useEffect(() => {\n    notFoundListeners.add(forceUpdate);\n    return () => {\n      notFoundListeners.delete(forceUpdate);\n    };\n  }, []);\n  return currentNotFoundState;\n}\nfunction findNearestNotFoundRoute(pathname, rootNode) {\n  if (!rootNode) return null;\n  const pathParts = pathname.split(\"/\").filter(Boolean);\n  function findNotFoundInNode(node) {\n    if (node.route === \"+not-found\") {\n      return node;\n    }\n    for (const child of node.children || []) {\n      if (child.route === \"+not-found\") {\n        return child;\n      }\n    }\n    return null;\n  }\n  function traverse(node, depth, notFoundStack) {\n    const notFoundAtLevel = findNotFoundInNode(node);\n    if (notFoundAtLevel) {\n      notFoundStack.push(notFoundAtLevel);\n    }\n    if (depth >= pathParts.length) {\n      return notFoundStack.length > 0 ? notFoundStack[notFoundStack.length - 1] : null;\n    }\n    const segment = pathParts[depth];\n    for (const child of node.children || []) {\n      if (child.route === \"+not-found\") continue;\n      const childRoute = child.route || \"\";\n      const isDynamic = childRoute.startsWith(\"[\");\n      const isMatch = childRoute === segment || isDynamic;\n      if (isMatch) {\n        const result = traverse(child, depth + 1, [...notFoundStack]);\n        if (result) return result;\n      }\n    }\n    return notFoundStack.length > 0 ? notFoundStack[notFoundStack.length - 1] : null;\n  }\n  return traverse(rootNode, 0, []);\n}\nfunction findRouteNodeByPath(notFoundPath, rootNode) {\n  if (!rootNode) return null;\n  const normalizedPath = notFoundPath.replace(/^(\\.?\\/)+|\\/+$/g, \"\");\n  function searchNode(node) {\n    const nodeContextKey = node.contextKey || \"\";\n    const contextKeyNormalized = nodeContextKey.replace(/^(\\.?\\/)+/, \"\").replace(/\\.[^.]+$/, \"\");\n    if (contextKeyNormalized === normalizedPath) {\n      return node;\n    }\n    for (const child of node.children || []) {\n      const found2 = searchNode(child);\n      if (found2) return found2;\n    }\n    return null;\n  }\n  const found = searchNode(rootNode);\n  if (found) return found;\n  for (const child of rootNode.children || []) {\n    const found2 = searchNode(child);\n    if (found2) return found2;\n  }\n  return null;\n}\nexport {\n  clearNotFoundState,\n  findNearestNotFoundRoute,\n  findRouteNodeByPath,\n  getNotFoundState,\n  setNotFoundState,\n  useNotFoundState\n};\n//# sourceMappingURL=notFoundState.js.map\n"],"mappings":";;;AACA,IAAI,uBAAuB;AAC3B,MAAM,oCAAoC,IAAI,IAAI;AAClD,SAAS,mBAAmB;CAC1B,OAAO;AACT;AACA,SAAS,iBAAiB,OAAO;CAC/B,uBAAuB;CACvB,kBAAkB,SAAS,aAAa,SAAS,CAAC;AACpD;AACA,SAAS,qBAAqB;CAC5B,IAAI,yBAAyB,MAAM;EACjC,uBAAuB;EACvB,kBAAkB,SAAS,aAAa,SAAS,CAAC;CACpD;AACF;AACA,SAAS,mBAAmB;CAC1B,MAAM,GAAG,eAAe,MAAM,YAAY,MAAM,IAAI,GAAG,CAAC;CACxD,MAAM,gBAAgB;EACpB,kBAAkB,IAAI,WAAW;EACjC,aAAa;GACX,kBAAkB,OAAO,WAAW;EACtC;CACF,GAAG,CAAC,CAAC;CACL,OAAO;AACT;AACA,SAAS,yBAAyB,UAAU,UAAU;CACpD,IAAI,CAAC,UAAU,OAAO;CACtB,MAAM,YAAY,SAAS,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;CACpD,SAAS,mBAAmB,MAAM;EAChC,IAAI,KAAK,UAAU,cAAc;GAC/B,OAAO;EACT;EACA,KAAK,MAAM,SAAS,KAAK,YAAY,CAAC,GAAG;GACvC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