ÃÊÁ ] º ÷ÿÿÿ÷w÷ÿ÷ÿð ð üÿ ÿð ü÷ÿÿÿw÷÷÷÷ÿÿ import { createSignal, onCleanup } from "/node_modules/.vite/deps/solid-js.js?v=5eac7255";
|
function bindEvent(target, type, handler) {
|
target.addEventListener(type, handler);
|
return () => target.removeEventListener(type, handler);
|
}
|
function intercept([value, setValue], get, set) {
|
return [get ? () => get(value()) : value, set ? (v) => setValue(set(v)) : setValue];
|
}
|
function querySelector(selector) {
|
// Guard against selector being an invalid CSS selector
|
try {
|
return document.querySelector(selector);
|
}
|
catch (e) {
|
return null;
|
}
|
}
|
function scrollToHash(hash, fallbackTop) {
|
const el = querySelector(`#${hash}`);
|
if (el) {
|
el.scrollIntoView();
|
}
|
else if (fallbackTop) {
|
window.scrollTo(0, 0);
|
}
|
}
|
export function createMemoryHistory() {
|
const entries = ["/"];
|
let index = 0;
|
const listeners = [];
|
const go = (n) => {
|
// https://github.com/remix-run/react-router/blob/682810ca929d0e3c64a76f8d6e465196b7a2ac58/packages/router/history.ts#L245
|
index = Math.max(0, Math.min(index + n, entries.length - 1));
|
const value = entries[index];
|
listeners.forEach(listener => listener(value));
|
};
|
return {
|
get: () => entries[index],
|
set: ({ value, scroll, replace }) => {
|
if (replace) {
|
entries[index] = value;
|
}
|
else {
|
entries.splice(index + 1, entries.length - index, value);
|
index++;
|
}
|
if (scroll) {
|
scrollToHash(value.split("#")[1] || "", true);
|
}
|
},
|
back: () => {
|
go(-1);
|
},
|
forward: () => {
|
go(1);
|
},
|
go,
|
listen: (listener) => {
|
listeners.push(listener);
|
return () => {
|
const index = listeners.indexOf(listener);
|
listeners.splice(index, 1);
|
};
|
}
|
};
|
}
|
export function createIntegration(get, set, init, utils) {
|
let ignore = false;
|
const wrap = (value) => (typeof value === "string" ? { value } : value);
|
const signal = intercept(createSignal(wrap(get()), { equals: (a, b) => a.value === b.value }), undefined, next => {
|
!ignore && set(next);
|
return next;
|
});
|
init &&
|
onCleanup(init((value = get()) => {
|
ignore = true;
|
signal[1](wrap(value));
|
ignore = false;
|
}));
|
return {
|
signal,
|
utils
|
};
|
}
|
export function normalizeIntegration(integration) {
|
if (!integration) {
|
return {
|
signal: createSignal({ value: "" })
|
};
|
}
|
else if (Array.isArray(integration)) {
|
return {
|
signal: integration
|
};
|
}
|
return integration;
|
}
|
export function staticIntegration(obj) {
|
return {
|
signal: [() => obj, next => Object.assign(obj, next)]
|
};
|
}
|
export function pathIntegration() {
|
return createIntegration(() => ({
|
value: window.location.pathname + window.location.search + window.location.hash,
|
state: history.state
|
}), ({ value, replace, scroll, state }) => {
|
if (replace) {
|
window.history.replaceState(state, "", value);
|
}
|
else {
|
window.history.pushState(state, "", value);
|
}
|
scrollToHash(window.location.hash.slice(1), scroll);
|
}, notify => bindEvent(window, "popstate", () => notify()), {
|
go: delta => window.history.go(delta)
|
});
|
}
|
export function hashIntegration() {
|
return createIntegration(() => window.location.hash.slice(1), ({ value, replace, scroll, state }) => {
|
if (replace) {
|
window.history.replaceState(state, "", "#" + value);
|
}
|
else {
|
window.location.hash = value;
|
}
|
const hashIndex = value.indexOf("#");
|
const hash = hashIndex >= 0 ? value.slice(hashIndex + 1) : "";
|
scrollToHash(hash, scroll);
|
}, notify => bindEvent(window, "hashchange", () => notify()), {
|
go: delta => window.history.go(delta),
|
renderPath: path => `#${path}`,
|
parsePath: str => {
|
const to = str.replace(/^.*?#/, "");
|
// Hash-only hrefs like `#foo` from plain anchors will come in as `/#foo` whereas a link to
|
// `/foo` will be `/#/foo`. Check if the to starts with a `/` and if not append it as a hash
|
// to the current path so we can handle these in-page anchors correctly.
|
if (!to.startsWith("/")) {
|
const [, path = "/"] = window.location.hash.split("#", 2);
|
return `${path}#${to}`;
|
}
|
return to;
|
}
|
});
|
}
|
export function memoryIntegration() {
|
const memoryHistory = createMemoryHistory();
|
return createIntegration(memoryHistory.get, memoryHistory.set, memoryHistory.listen, {
|
go: memoryHistory.go
|
});
|
}
|
|