PageSourceSearch

https://opencode.ai/_build/assets/query-C5C68Kfb.js

js opencode.ai collected 2026-09-24 08:23:53 UTC 22,852 bytes, 786 lines download raw bytes

1import { a5 as runWithOwner, m as createMemo, U as getOwner, ah as useContext, af as untrack, k as createContext, q as createSignal, n as createRenderEffect, a0 as on, ac as startTransition, a3 as resetErrorBoundaries, e as batch, X as isServer, ai as voidFn, i as createComponent, Q as getListener, a1 as onCleanup, a9 as sharedConfig } from "./tr-UliDDw9Z.js";
2function createBeforeLeave() {
3  let listeners = /* @__PURE__ */ new Set();
4  function subscribe(listener) {
5    listeners.add(listener);
6    return () => listeners.delete(listener);
7  }
8  let ignore = false;
9  function confirm(to, options) {
10    if (ignore) return !(ignore = false);
11    const e = {
12      to,
13      options,
14      defaultPrevented: false,
15      preventDefault: () => e.defaultPrevented = true
16    };
17    for (const l of listeners) l.listener({
18      ...e,
19      from: l.location,
20      retry: (force) => {
21        force && (ignore = true);
22        l.navigate(to, {
23          ...options,
24          resolve: false
25        });
26      }
27    });
28    return !e.defaultPrevented;
29  }
30  return {
31    subscribe,
32    confirm
33  };
34}
35let depth;
36function saveCurrentDepth() {
37  if (!window.history.state || window.history.state._depth == null) {
38    window.history.replaceState({
39      ...window.history.state,
40      _depth: window.history.length - 1
41    }, "");
42  }
43  depth = window.history.state._depth;
44}
45{
46  saveCurrentDepth();
47}
48function keepDepth(state) {
49  return {
50    ...state,
51    _depth: window.history.state && window.history.state._depth
52  };
53}
54function notifyIfNotBlocked(notify, block) {
55  let ignore = false;
56  return () => {
57    const prevDepth = depth;
58    saveCurrentDepth();
59    const delta = prevDepth == null ? null : depth - prevDepth;
60    if (ignore) {
61      ignore = false;
62      return;
63    }
64    if (delta && block(delta)) {
65      ignore = true;
66      window.history.go(-delta);
67    } else {
68      notify();
69    }
70  };
71}
72const hasSchemeRegex = /^(?:[a-z0-9]+:)?\/\//i;
73const trimPathRegex = /^\/+|(\/)\/+$/g;
74const mockBase = "http://sr";
75function normalizePath(path, omitSlash = false) {
76  const s = path.replace(trimPathRegex, "$1");
77  return s ? omitSlash || /^[?#]/.test(s) ? s : "/" + s : "";
78}
79function resolvePath(base, path, from) {
80  if (hasSchemeRegex.test(path)) {
81    return void 0;
82  }
83  const basePath = normalizePath(base);
84  const fromPath = from && normalizePath(from);
85  let result = "";
86  if (!fromPath || path.startsWith("/")) {
87    result = basePath;
88  } else if (fromPath.toLowerCase().indexOf(basePath.toLowerCase()) !== 0) {
89    result = basePath + fromPath;
90  } else {
91    result = fromPath;
92  }
93  return (result || "/") + normalizePath(path, !result);
94}
95function invariant(value, message) {
96  if (value == null) {
97    throw new Error(message);
98  }
99  return value;
100}
101function joinPaths(from, to) {
102  return normalizePath(from).replace(/\/*(\*.*)?$/g, "") + normalizePath(to);
103}
104function extractSearchParams(url) {
105  const params = {};
106  url.searchParams.forEach((value, key) => {
107    if (key in params) {
108      if (Array.isArray(params[key])) params[key].push(value);
109      else params[key] = [params[key], value];
110    } else params[key] = value;
111  });
112  return params;
113}
114function createMatcher(path, partial, matchFilters) {
115  const [pattern, splat] = path.split("/*", 2);
116  const segments = pattern.split("/").filter(Boolean);
117  const len = segments.length;
118  return (location) => {
119    const locSegments = location.split("/").filter(Boolean);
120    const lenDiff = locSegments.length - len;
121    if (lenDiff < 0 || lenDiff > 0 && splat === void 0 && !partial) {
122      return null;
123    }
124    const match = {
125      path: len ? "" : "/",
126      params: {}
127    };
128    const matchFilter = (s) => matchFilters === void 0 ? void 0 : matchFilters[s];
129    for (let i = 0; i < len; i++) {
130      const segment = segments[i];
131      const dynamic = segment[0] === ":";
132      const locSegment = dynamic ? locSegments[i] : locSegments[i].toLowerCase();
133      const key = dynamic ? segment.slice(1) : segment.toLowerCase();
134      if (dynamic && matchSegment(locSegment, matchFilter(key))) {
135        match.params[key] = locSegment;
136      } else if (dynamic || !matchSegment(locSegment, key)) {
137        return null;
138      }
139      match.path += `/${locSegment}`;
140    }
141    if (splat) {
142      const remainder = lenDiff ? locSegments.slice(-lenDiff).join("/") : "";
143      if (matchSegment(remainder, matchFilter(splat))) {
144        match.params[splat] = remainder;
145      } else {
146        return null;
147      }
148    }
149    return match;
150  };
151}
152function matchSegment(input, filter) {
153  const isEqual = (s) => s === input;
154  if (filter === void 0) {
155    return true;
156  } else if (typeof filter === "string") {
157    return isEqual(filter);
158  } else if (typeof filter === "function") {
159    return filter(input);
160  } else if (Array.isArray(filter)) {
161    return filter.some(isEqual);
162  } else if (filter instanceof RegExp) {
163    return filter.test(input);
164  }
165  return false;
166}
167function scoreRoute(route) {
168  const [pattern, splat] = route.pattern.split("/*", 2);
169  const segments = pattern.split("/").filter(Boolean);
170  return segments.reduce((score, segment) => score + (segment.startsWith(":") ? 2 : 3), segments.length - (splat === void 0 ? 0 : 1));
171}
172function createMemoObject(fn) {
173  const map = /* @__PURE__ */ new Map();
174  const owner = getOwner();
175  return new Proxy({}, {
176    get(_, property) {
177      if (!map.has(property)) {
178        runWithOwner(owner, () => map.set(property, createMemo(() => fn()[property])));
179      }
180      return map.get(property)();
181    },
182    getOwnPropertyDescriptor() {
183      return {
184        enumerable: true,
185        configurable: true
186      };
187    },
188    ownKeys() {
189      return Reflect.ownKeys(fn());
190    },
191    has(_, property) {
192      return property in fn();
193    }
194  });
195}
196function mergeSearchString(search, params) {
197  const merged = new URLSearchParams(search);
198  Object.entries(params).forEach(([key, value]) => {
199    if (value == null || value === "" || value instanceof Array && !value.length) {
200      merged.delete(key);
201    } else {
202      if (value instanceof Array) {
203        merged.delete(key);
204        value.forEach((v) => {
205          merged.append(key, String(v));
206        });
207      } else {
208        merged.set(key, String(value));
209      }
210    }
211  });
212  const s = merged.toString();
213  return s ? `?${s}` : "";
214}
215function expandOptionals(pattern) {
216  let match = /(\/?\:[^\/]+)\?/.exec(pattern);
217  if (!match) return [pattern];
218  let prefix = pattern.slice(0, match.index);
219  let suffix = pattern.slice(match.index + match[0].length);
220  const prefixes = [prefix, prefix += match[1]];
221  while (match = /^(\/\:[^\/]+)\?/.exec(suffix)) {
222    prefixes.push(prefix += match[1]);
223    suffix = suffix.slice(match[0].length);
224  }
225  return expandOptionals(suffix).reduce((results, expansion) => [...results, ...prefixes.map((p) => p + expansion)], []);
226}
227const MAX_REDIRECTS = 100;
228const RouterContextObj = createContext();
229const RouteContextObj = createContext();
230const useRouter = () => invariant(useContext(RouterContextObj), "<A> and 'use' router primitives can be only used inside a Route.");
231const useRoute = () => useContext(RouteContextObj) || useRouter().base;
232const useResolvedPath = (path) => {
233  const route = useRoute();
234  return createMemo(() => route.resolvePath(path()));
235};
236const useHref = (to) => {
237  const router = useRouter();
238  return createMemo(() => {
239    const to_ = to();
240    return to_ !== void 0 ? router.renderPath(to_) : to_;
241  });
242};
243const useNavigate = () => useRouter().navigatorFactory();
244const useLocation = () => useRouter().location;
245const useParams = () => useRouter().params;
246const useSearchParams = () => {
247  const location = useLocation();
248  const navigate = useNavigate();
249  const setSearchParams = (params, options) => {
250    const searchString = untrack(() => mergeSearchString(location.search, params) + location.hash);
251    navigate(searchString, {
252      scroll: false,
253      resolve: false,
254      ...options
255    });
256  };
257  return [location.query, setSearchParams];
258};
259function createRoutes(routeDef, base = "") {
260  const {
261    component,
262    preload,
263    load,
264    children,
265    info
266  } = routeDef;
267  const isLeaf = !children || Array.isArray(children) && !children.length;
268  const shared = {
269    key: routeDef,
270    component,
271    preload: preload || load,
272    info
273  };
274  return asArray(routeDef.path).reduce((acc, originalPath) => {
275    for (const expandedPath of expandOptionals(originalPath)) {
276      const path = joinPaths(base, expandedPath);
277      let pattern = isLeaf ? path : path.split("/*", 1)[0];
278      pattern = pattern.split("/").map((s) => {
279        return s.startsWith(":") || s.startsWith("*") ? s : encodeURIComponent(s);
280      }).join("/");
281      acc.push({
282        ...shared,
283        originalPath,
284        pattern,
285        matcher: createMatcher(pattern, !isLeaf, routeDef.matchFilters)
286      });
287    }
288    return acc;
289  }, []);
290}
291function createBranch(routes, index = 0) {
292  return {
293    routes,
294    score: scoreRoute(routes[routes.length - 1]) * 1e4 - index,
295    matcher(location) {
296      const matches = [];
297      for (let i = routes.length - 1; i >= 0; i--) {
298        const route = routes[i];
299        const match = route.matcher(location);
300        if (!match) {
301          return null;
302        }
303        matches.unshift({
304          ...match,
305          route
306        });
307      }
308      return matches;
309    }
310  };
311}
312function asArray(value) {
313  return Array.isArray(value) ? value : [value];
314}
315function createBranches(routeDef, base = "", stack = [], branches = []) {
316  const routeDefs = asArray(routeDef);
317  for (let i = 0, len = routeDefs.length; i < len; i++) {
318    const def = routeDefs[i];
319    if (def && typeof def === "object") {
320      if (!def.hasOwnProperty("path")) def.path = "";
321      const routes = createRoutes(def, base);
322      for (const route of routes) {
323        stack.push(route);
324        const isEmptyArray = Array.isArray(def.children) && def.children.length === 0;
325        if (def.children && !isEmptyArray) {
326          createBranches(def.children, route.pattern, stack, branches);
327        } else {
328          const branch = createBranch([...stack], branches.length);
329          branches.push(branch);
330        }
331        stack.pop();
332      }
333    }
334  }
335  return stack.length ? branches : branches.sort((a, b) => b.score - a.score);
336}
337function getRouteMatches(branches, location) {
338  for (let i = 0, len = branches.length; i < len; i++) {
339    const match = branches[i].matcher(location);
340    if (match) {
341      return match;
342    }
343  }
344  return [];
345}
346function createLocation(path, state, queryWrapper) {
347  const origin = new URL(mockBase);
348  const url = createMemo((prev) => {
349    const path_ = path();
350    try {
351      return new URL(path_, origin);
352    } catch (err) {
353      console.error(`Invalid path ${path_}`);
354      return prev;
355    }
356  }, origin, {
357    equals: (a, b) => a.href === b.href
358  });
359  const pathname = createMemo(() => url().pathname);
360  const search = createMemo(() => url().search, true);
361  const hash = createMemo(() => url().hash);
362  const key = () => "";
363  const queryFn = on(search, () => extractSearchParams(url()));
364  return {
365    get pathname() {
366      return pathname();
367    },
368    get search() {
369      return search();
370    },
371    get hash() {
372      return hash();
373    },
374    get state() {
375      return state();
376    },
377    get key() {
378      return key();
379    },
380    query: queryWrapper ? queryWrapper(queryFn) : createMemoObject(queryFn)
381  };
382}
383let intent;
384function getIntent() {
385  return intent;
386}
387let inPreloadFn = false;
388function getInPreloadFn() {
389  return inPreloadFn;
390}
391function setInPreloadFn(value) {
392  inPreloadFn = value;
393}
394function createRouterContext(integration, branches, getContext, options = {}) {
395  const {
396    signal: [source, setSource],
397    utils = {}
398  } = integration;
399  const parsePath = utils.parsePath || ((p) => p);
400  const renderPath = utils.renderPath || ((p) => p);
401  const beforeLeave = utils.beforeLeave || createBeforeLeave();
402  const basePath = resolvePath("", options.base || "");
403  if (basePath === void 0) {
404    throw new Error(`${basePath} is not a valid base path`);
405  } else if (basePath && !source().value) {
406    setSource({
407      value: basePath,
408      replace: true,
409      scroll: false
410    });
411  }
412  const [isRouting, setIsRouting] = createSignal(false);
413  let lastTransitionTarget;
414  const transition = (newIntent, newTarget) => {
415    if (newTarget.value === reference() && newTarget.state === state()) return;
416    if (lastTransitionTarget === void 0) setIsRouting(true);
417    intent = newIntent;
418    lastTransitionTarget = newTarget;
419    startTransition(() => {
420      if (lastTransitionTarget !== newTarget) return;
421      setReference(lastTransitionTarget.value);
422      setState(lastTransitionTarget.state);
423      resetErrorBoundaries();
424      submissions[1]((subs) => subs.filter((s) => s.pending));
425    }).finally(() => {
426      if (lastTransitionTarget !== newTarget) return;
427      batch(() => {
428        intent = void 0;
429        if (newIntent === "navigate") navigateEnd(lastTransitionTarget);
430        setIsRouting(false);
431        lastTransitionTarget = void 0;
432      });
433    });
434  };
435  const [reference, setReference] = createSignal(source().value);
436  const [state, setState] = createSignal(source().state);
437  const location = createLocation(reference, state, utils.queryWrapper);
438  const referrers = [];
439  const submissions = createSignal([]);
440  const matches = createMemo(() => {
441    if (typeof options.transformUrl === "function") {
442      return getRouteMatches(branches(), options.transformUrl(location.pathname));
443    }
444    return getRouteMatches(branches(), location.pathname);
445  });
446  const buildParams = () => {
447    const m = matches();
448    const params2 = {};
449    for (let i = 0; i < m.length; i++) {
450      Object.assign(params2, m[i].params);
451    }
452    return params2;
453  };
454  const params = utils.paramsWrapper ? utils.paramsWrapper(buildParams, branches) : createMemoObject(buildParams);
455  const baseRoute = {
456    pattern: basePath,
457    path: () => basePath,
458    outlet: () => null,
459    resolvePath(to) {
460      return resolvePath(basePath, to);
461    }
462  };
463  createRenderEffect(on(source, (source2) => transition("native", source2), {
464    defer: true
465  }));
466  return {
467    base: baseRoute,
468    location,
469    params,
470    isRouting,
471    renderPath,
472    parsePath,
473    navigatorFactory,
474    matches,
475    beforeLeave,
476    preloadRoute,
477    singleFlight: options.singleFlight === void 0 ? true : options.singleFlight,
478    submissions
479  };
480  function navigateFromRoute(route, to, options2) {
481    untrack(() => {
482      if (typeof to === "number") {
483        if (!to) {
484        } else if (utils.go) {
485          utils.go(to);
486        } else {
487          console.warn("Router integration does not support relative routing");
488        }
489        return;
490      }
491      const queryOnly = !to || to[0] === "?";
492      const {
493        replace,
494        resolve,
495        scroll,
496        state: nextState
497      } = {
498        replace: false,
499        resolve: !queryOnly,
500        scroll: true,
501        ...options2
502      };
503      const resolvedTo = resolve ? route.resolvePath(to) : resolvePath(queryOnly && location.pathname || "", to);
504      if (resolvedTo === void 0) {
505        throw new Error(`Path '${to}' is not a routable path`);
506      } else if (referrers.length >= MAX_REDIRECTS) {
507        throw new Error("Too many redirects");
508      }
509      const current = reference();
510      if (resolvedTo !== current || nextState !== state()) {
511        if (isServer) ;
512        else if (beforeLeave.confirm(resolvedTo, options2)) {
513          referrers.push({
514            value: current,
515            replace,
516            scroll,
517            state: state()
518          });
519          transition("navigate", {
520            value: resolvedTo,
521            state: nextState
522          });
523        }
524      }
525    });
526  }
527  function navigatorFactory(route) {
528    route = route || useContext(RouteContextObj) || baseRoute;
529    return (to, options2) => navigateFromRoute(route, to, options2);
530  }
531  function navigateEnd(next) {
532    const first = referrers[0];
533    if (first) {
534      setSource({
535        ...next,
536        replace: first.replace,
537        scroll: first.scroll
538      });
539      referrers.length = 0;
540    }
541  }
542  function preloadRoute(url, preloadData) {
543    const matches2 = getRouteMatches(branches(), url.pathname);
544    const prevIntent = intent;
545    intent = "preload";
546    for (let match in matches2) {
547      const {
548        route,
549        params: params2
550      } = matches2[match];
551      route.component && route.component.preload && route.component.preload();
552      const {
553        preload
554      } = route;
555      inPreloadFn = true;
556      preloadData && preload && runWithOwner(getContext(), () => preload({
557        params: params2,
558        location: {
559          pathname: url.pathname,
560          search: url.search,
561          hash: url.hash,
562          query: extractSearchParams(url),
563          state: null,
564          key: ""
565        },
566        intent: "preload"
567      }));
568      inPreloadFn = false;
569    }
570    intent = prevIntent;
571  }
572}
573function createRouteContext(router, parent, outlet, match) {
574  const {
575    base,
576    location,
577    params
578  } = router;
579  const {
580    pattern,
581    component,
582    preload
583  } = match().route;
584  const path = createMemo(() => match().path);
585  component && component.preload && component.preload();
586  inPreloadFn = true;
587  const data = preload ? preload({
588    params,
589    location,
590    intent: intent || "initial"
591  }) : void 0;
592  inPreloadFn = false;
593  const route = {
594    parent,
595    pattern,
596    path,
597    outlet: () => component ? createComponent(component, {
598      params,
599      location,
600      data,
601      get children() {
602        return outlet();
603      }
604    }) : outlet(),
605    resolvePath(to) {
606      return resolvePath(base.path(), to, path());
607    }
608  };
609  return route;
610}
611const LocationHeader = "Location";
612const PRELOAD_TIMEOUT = 5e3;
613const CACHE_TIMEOUT = 18e4;
614let cacheMap = /* @__PURE__ */ new Map();
615{
616  setInterval(() => {
617    const now = Date.now();
618    for (let [k, v] of cacheMap.entries()) {
619      if (!v[4].count && now - v[0] > CACHE_TIMEOUT) {
620        cacheMap.delete(k);
621      }
622    }
623  }, 3e5);
624}
625function getCache() {
626  return cacheMap;
627}
628function revalidate(key, force = true) {
629  return startTransition(() => {
630    const now = Date.now();
631    cacheKeyOp(key, (entry) => {
632      force && (entry[0] = 0);
633      entry[4][1](now);
634    });
635  });
636}
637function cacheKeyOp(key, fn) {
638  key && !Array.isArray(key) && (key = [key]);
639  for (let k of cacheMap.keys()) {
640    if (key === void 0 || matchKey(k, key)) fn(cacheMap.get(k));
641  }
642}
643function query(fn, name) {
644  if (fn.GET) fn = fn.GET;
645  const cachedFn = (...args) => {
646    const cache = getCache();
647    const intent2 = getIntent();
648    const inPreloadFn2 = getInPreloadFn();
649    const owner = getOwner();
650    const navigate = owner ? useNavigate() : void 0;
651    const now = Date.now();
652    const key = name + hashKey(args);
653    let cached = cache.get(key);
654    let tracking;
655    if (getListener() && !isServer) {
656      tracking = true;
657      onCleanup(() => cached[4].count--);
658    }
659    if (cached && cached[0] && (intent2 === "native" || cached[4].count || Date.now() - cached[0] < PRELOAD_TIMEOUT)) {
660      if (tracking) {
661        cached[4].count++;
662        cached[4][0]();
663      }
664      if (cached[3] === "preload" && intent2 !== "preload") {
665        cached[0] = now;
666      }
667      let res2 = cached[1];
668      if (intent2 !== "preload") {
669        res2 = "then" in cached[1] ? cached[1].then(handleResponse(false), handleResponse(true)) : handleResponse(false)(cached[1]);
670        intent2 === "navigate" && startTransition(() => cached[4][1](cached[0]));
671      }
672      inPreloadFn2 && "then" in res2 && res2.catch(() => {
673      });
674      return res2;
675    }
676    let res;
677    if (sharedConfig.has && sharedConfig.has(key)) {
678      res = sharedConfig.load(key);
679      delete globalThis._$HY.r[key];
680    } else res = fn(...args);
681    if (cached) {
682      cached[0] = now;
683      cached[1] = res;
684      cached[3] = intent2;
685      intent2 === "navigate" && startTransition(() => cached[4][1](cached[0]));
686    } else {
687      cache.set(key, cached = [now, res, , intent2, createSignal(now)]);
688      cached[4].count = 0;
689    }
690    if (tracking) {
691      cached[4].count++;
692      cached[4][0]();
693    }
694    if (intent2 !== "preload") {
695      res = "then" in res ? res.then(handleResponse(false), handleResponse(true)) : handleResponse(false)(res);
696    }
697    inPreloadFn2 && "then" in res && res.catch(() => {
698    });
699    return res;
700    function handleResponse(error) {
701      return async (v) => {
702        if (v instanceof Response) {
703          const url = v.headers.get(LocationHeader);
704          if (url !== null) {
705            if (navigate && url.startsWith("/")) startTransition(() => {
706              navigate(url, {
707                replace: true
708              });
709            });
710            else window.location.href = url;
711            return;
712          }
713          if (v.customBody) v = await v.customBody();
714        }
715        if (error) throw v;
716        cached[2] = v;
717        return v;
718      };
719    }
720  };
721  cachedFn.keyFor = (...args) => name + hashKey(args);
722  cachedFn.key = name;
723  return cachedFn;
724}
725query.get = (key) => {
726  const cached = getCache().get(key);
727  return cached[2];
728};
729query.set = (key, value) => {
730  const cache = getCache();
731  const now = Date.now();
732  let cached = cache.get(key);
733  if (cached) {
734    cached[0] = now;
735    cached[1] = Promise.resolve(value);
736    cached[2] = value;
737    cached[3] = "preload";
738  } else {
739    cache.set(key, cached = [now, Promise.resolve(value), value, "preload", createSignal(now)]);
740    cached[4].count = 0;
741  }
742};
743query.delete = (key) => getCache().delete(key);
744query.clear = () => getCache().clear();
745function matchKey(key, keys) {
746  for (let k of keys) {
747    if (k && key.startsWith(k)) return true;
748  }
749  return false;
750}
751function hashKey(args) {
752  return JSON.stringify(args, (_, val) => isPlainObject(val) ? Object.keys(val).sort().reduce((result, key) => {
753    result[key] = val[key];
754    return result;
755  }, {}) : val);
756}
757function isPlainObject(obj) {
758  let proto;
759  return obj != null && typeof obj === "object" && (!(proto = Object.getPrototypeOf(obj)) || proto === Object.prototype);
760}
761export {
762  RouteContextObj as R,
763  RouterContextObj as a,
764  createBeforeLeave as b,
765  cacheKeyOp as c,
766  createBranches as d,
767  createRouteContext as e,
768  createRouterContext as f,
769  getIntent as g,
770  hashKey as h,
771  notifyIfNotBlocked as i,
772  setInPreloadFn as j,
773  keepDepth as k,
774  useLocation as l,
775  mockBase as m,
776  normalizePath as n,
777  useNavigate as o,
778  useParams as p,
779  query as q,
780  revalidate as r,
781  saveCurrentDepth as s,
782  useResolvedPath as t,
783  useHref as u,
784  useRouter as v,
785  useSearchParams as w
786};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.