@manyducks.co/dolla 3.1.0 β 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/index.d.ts +1 -1
- package/dist/core/signals.d.ts +33 -1
- package/dist/core-2CFW0uRa.js +1047 -0
- package/dist/core-2CFW0uRa.js.map +1 -0
- package/dist/index.js +2 -4
- package/dist/jsx-dev-runtime.js +1 -1
- package/dist/jsx-runtime.js +1 -1
- package/dist/router/types.d.ts +4 -3
- package/dist/router/utils.d.ts +1 -1
- package/dist/router.js +148 -150
- package/dist/router.js.map +1 -1
- package/dist/translate.js +24 -24
- package/package.json +1 -1
- package/dist/context-B5blupD2.js +0 -363
- package/dist/context-B5blupD2.js.map +0 -1
- package/dist/core-JHktdqjt.js +0 -242
- package/dist/core-JHktdqjt.js.map +0 -1
- package/dist/signals-CMJPGr_M.js +0 -354
- package/dist/signals-CMJPGr_M.js.map +0 -1
package/dist/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","names":[],"sources":["../src/router/utils.ts","../src/router/store.ts","../src/router/router.ts","../src/router/index.ts"],"sourcesContent":["import { View } from \"../types.js\";\nimport { assert, isArray, isFunction, isObject, isString, uniqueId } from \"../utils.js\";\nimport type { JourneyStep, Route, RouteLayer, Stringable } from \"./types.js\";\n\nexport interface Match {\n /**\n * The path string that triggered this match.\n */\n path: string;\n\n /**\n * The pattern satisfied by `path`.\n */\n pattern: string;\n\n /**\n * Named params as parsed from `path`.\n */\n params: Record<string, string>;\n\n /**\n * Query params as parsed from `path`.\n */\n query: Record<string, string>;\n\n /**\n * Freeform data you wish to store with this route.\n * Merged `data` from all matched layers are available on the router's `match.meta`.\n */\n meta: Record<any, any>;\n}\n\nexport interface RouteMatch extends Match {\n layers: RouteLayer[];\n redirect?: string | ((match: Match) => string) | ((match: Match) => Promise<string>);\n}\n\nexport type RoutePayload = {\n pattern: string;\n meta: Record<any, any>;\n layers?: RouteLayer[];\n redirect?: string | ((match: Match) => string) | ((match: Match) => Promise<string>);\n};\n\nexport type RouteMatchOptions = {\n willMatch?: (route: RoutePayload) => boolean;\n};\n\n/**\n * Separates a URL path into multiple fragments.\n *\n * @param path - A path string (e.g. `\"/api/users/5\"`)\n * @returns an array of fragments (e.g. `[\"api\", \"users\", \"5\"]`)\n */\nexport function splitPath(path: string): string[] {\n return path\n .split(\"/\")\n .map((f) => f.trim())\n .filter(Boolean);\n}\n\n/**\n * Joins multiple URL path fragments into a single string.\n *\n * @param parts - One or more URL fragments (e.g. `[\"api\", \"users\", 5]`)\n * @returns a joined path (e.g. `\"api/users/5\"`)\n */\n\nexport function joinPath(parts: { toString(): string }[]): string {\n const joined = parts\n .map((p) => p.toString())\n .filter(Boolean)\n .join(\"/\");\n if (!joined) return \"\";\n\n const isAbsolute = joined.startsWith(\"/\");\n const segments = joined.split(\"/\");\n const resolved: string[] = [];\n\n for (const segment of segments) {\n if (segment === \"\" || segment === \".\") continue;\n if (segment === \"..\") {\n // Pop the previous segment unless we're at the root, or already backing up\n if (resolved.length > 0 && resolved[resolved.length - 1] !== \"..\") {\n resolved.pop();\n } else if (!isAbsolute) {\n resolved.push(\"..\");\n }\n } else {\n resolved.push(segment);\n }\n }\n\n let result = resolved.join(\"/\");\n if (isAbsolute) result = \"/\" + result;\n\n return result || (isAbsolute ? \"/\" : \"\");\n}\n\nexport function resolvePath(base: string, part: string | null = null): string {\n if (part == null) {\n part = base;\n base = \"\";\n }\n\n // If the target is absolute, it replaces the base entirely\n if (part.startsWith(\"/\")) return joinPath([part]);\n\n // Otherwise, join them and let joinPath resolve the '.' and '..'\n return joinPath([base, part]);\n}\n\nexport function parseQueryParams(query: string): Record<string, string> {\n return Object.fromEntries(new URLSearchParams(query));\n}\n\nexport function mergeQueryParams(\n previous: Record<string, string>,\n current: Record<string, Stringable>,\n preserve?: boolean | string[],\n) {\n const merged: Record<string, any> = {};\n\n if (preserve === true) {\n Object.assign(merged, previous);\n } else if (isArray(preserve)) {\n for (const key of preserve) {\n if (key in previous) merged[key] = previous[key];\n }\n }\n\n Object.assign(merged, current);\n return new URLSearchParams(merged as Record<string, string>);\n}\n\nexport class RouteNode {\n staticChildren = new Map<string, RouteNode>();\n numericChild: RouteNode | null = null;\n paramChild: RouteNode | null = null;\n wildcardChild: RouteNode | null = null;\n\n // Set if this node represents the end of a valid path\n route?: RoutePayload;\n paramName?: string;\n numericName?: string;\n}\n\nexport function buildRouteTree(routes: Route[]): RouteNode {\n const root = new RouteNode();\n const redirectsToValidate: RoutePayload[] = [];\n\n function insertIntoTree(pattern: string, payload: RoutePayload) {\n const parts = splitPath(pattern);\n let current = root;\n\n for (const part of parts) {\n if (part === \"*\") {\n current = current.wildcardChild ??= new RouteNode();\n } else if (part.charCodeAt(0) === 123) {\n // {\n if (part.charCodeAt(1) === 35) {\n // #\n current = current.numericChild ??= new RouteNode();\n current.numericName = part.slice(2, -1);\n } else {\n current = current.paramChild ??= new RouteNode();\n current.paramName = part.slice(1, -1);\n }\n } else {\n const key = part.toLowerCase();\n let next = current.staticChildren.get(key);\n if (!next) current.staticChildren.set(key, (next = new RouteNode()));\n current = next;\n }\n }\n current.route = payload;\n }\n\n function parse(route: Route, parents: Route[] = [], layers: RouteLayer[] = []) {\n assert(isObject<Route>(route) && isString(route.path), \"Invalid route object\");\n\n const parentPaths = parents.map((p) => p.path);\n const parent = parents.at(-1);\n const meta = parent && route.meta ? { ...parent.meta, ...route.meta } : route.meta || {};\n\n const rawPattern = parentPaths.length ? joinPath([...parentPaths, route.path]) : route.path;\n const patterns = expandOptionalPaths(rawPattern);\n\n if (route.redirect) {\n assert(!route.routes && !route.view, \"Route cannot mix redirect with view/routes\");\n let redirect = route.redirect;\n\n if (isString(redirect)) {\n redirect = resolvePath(joinPath(parentPaths), redirect);\n if (!redirect.startsWith(\"/\")) redirect = \"/\" + redirect;\n }\n\n for (const pattern of patterns) {\n const payload: RoutePayload = { pattern, meta, redirect };\n insertIntoTree(pattern, payload);\n if (isString(redirect)) redirectsToValidate.push(payload);\n }\n\n return;\n }\n\n assert(route.view || route.routes, \"Route must have view, redirect, or routes\");\n\n let view = (route.view || ((props: any) => props.children)) as View<any>;\n if (!isFunction(view) && !(view as any)._lazy) {\n throw new TypeError(`Expected view function for ${route.path}`);\n }\n\n if (route.routes) {\n // For parent nodes, create the layer using the raw pattern and recurse\n const layer: RouteLayer = {\n id: uniqueId(),\n pattern: rawPattern,\n view,\n preload: route.preload,\n errorView: route.errorView,\n };\n for (const subroute of route.routes) parse(subroute, [...parents, route], [...layers, layer]);\n } else {\n // For leaf nodes, register every permutation as a valid endpoint\n for (const pattern of patterns) {\n const layer: RouteLayer = {\n id: uniqueId(),\n pattern, // Use the specific expanded pattern for this layer\n view,\n preload: route.preload,\n errorView: route.errorView,\n };\n insertIntoTree(pattern, { pattern, meta, layers: [...layers, layer] });\n }\n }\n }\n\n for (const route of routes) parse(route);\n\n for (const payload of redirectsToValidate) {\n assert(\n matchRoute(root, payload.redirect as string, { willMatch: (r) => r !== payload }),\n `Dead redirect: ${payload.pattern} -> ${payload.redirect}`,\n );\n }\n\n return root;\n}\n\nexport function matchRoute(rootNode: RouteNode, url: string, options: RouteMatchOptions = {}): RouteMatch | undefined {\n const [path, query] = url.split(\"?\");\n const parts = splitPath(path);\n const paramState: Record<string, string> = {}; // Reused across branches\n\n function search(node: RouteNode, index: number): RouteMatch | undefined {\n // if we've consumed all URL parts\n if (index === parts.length) {\n if (node.route && (!options.willMatch || options.willMatch(node.route))) {\n return {\n path: path || \"/\",\n pattern: node.route.pattern,\n params: { ...paramState },\n query: parseQueryParams(query || \"\"),\n meta: node.route.meta,\n layers: node.route.layers ?? [],\n redirect: node.route.redirect,\n };\n }\n\n // Allow wildcards to match zero remaining segments\n if (node.wildcardChild && node.wildcardChild.route) {\n if (!options.willMatch || options.willMatch(node.wildcardChild.route)) {\n return {\n path: path || \"/\",\n pattern: node.wildcardChild.route.pattern,\n params: { ...paramState, wildcard: \"/\" },\n query: parseQueryParams(query || \"\"),\n meta: node.wildcardChild.route.meta,\n layers: node.wildcardChild.route.layers ?? [],\n redirect: node.wildcardChild.route.redirect,\n };\n }\n }\n\n return undefined;\n }\n\n const part = parts[index];\n const lowerPart = part.toLowerCase();\n\n const staticNode = node.staticChildren.get(lowerPart);\n if (staticNode) {\n const result = search(staticNode, index + 1);\n if (result) return result;\n }\n\n if (node.numericChild && !isNaN(Number(part))) {\n paramState[node.numericChild.numericName!] = part;\n const result = search(node.numericChild, index + 1);\n if (result) return result;\n delete paramState[node.numericChild.numericName!];\n }\n\n if (node.paramChild) {\n paramState[node.paramChild.paramName!] = decodeURIComponent(part);\n const result = search(node.paramChild, index + 1);\n if (result) return result;\n delete paramState[node.paramChild.paramName!];\n }\n\n if (node.wildcardChild && node.wildcardChild.route) {\n if (!options.willMatch || options.willMatch(node.wildcardChild.route)) {\n return {\n path: path || \"/\",\n pattern: node.wildcardChild.route.pattern,\n params: { ...paramState, wildcard: \"/\" + parts.slice(index).map(decodeURIComponent).join(\"/\") },\n query: parseQueryParams(query || \"\"),\n meta: node.wildcardChild.route.meta,\n layers: node.wildcardChild.route.layers ?? [],\n redirect: node.wildcardChild.route.redirect,\n };\n }\n }\n\n return undefined;\n }\n\n return search(rootNode, 0);\n}\n\nexport interface ResolvedRoute {\n match?: RouteMatch;\n journey: JourneyStep[];\n}\n\n/**\n * Takes a URL and finds a match, following redirects.\n */\nexport async function resolveRoute(\n rootNode: RouteNode,\n path: string,\n journey: JourneyStep[] = [],\n): Promise<ResolvedRoute> {\n const match = matchRoute(rootNode, path);\n\n if (!match) return { journey: [...journey, { kind: \"miss\", message: `no match for '${path}'` }] };\n\n if (match.redirect != null) {\n let target = match.redirect;\n\n if (isString(target)) {\n target = replaceParams(target, match.params);\n } else {\n target = await target(match);\n assert(isString(target), \"Redirect function must return a path.\");\n if (!target.startsWith(\"/\")) target = resolvePath(match.path, target);\n }\n\n return resolveRoute(rootNode, target, [\n ...journey,\n { kind: \"redirect\", message: `redirecting '${match.path}' -> '${target}'` },\n ]);\n }\n\n // TODO: Data preload\n\n return { match, journey: [...journey, { kind: \"match\", message: `matched route '${match.path}'` }] };\n}\n\n/**\n * Intercepts links within the root node.\n *\n * This is adapted from https://github.com/choojs/nanohref/blob/master/index.js\n *\n * @param root - Element under which to intercept link clicks\n * @param callback - Function to call when a click event is intercepted\n * @param _window - (optional) Override for global window object\n */\nexport function catchLinks(\n root: Element,\n callback: (href: string, anchor: HTMLAnchorElement) => void,\n _window = window,\n) {\n function handler(e: MouseEvent) {\n if ((e.button && e.button !== 0) || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.defaultPrevented) return;\n\n const anchor = (e.target as Element).closest(\"a\");\n if (!anchor || !root.contains(anchor)) return;\n\n const href = anchor.getAttribute(\"href\");\n if (!href) return;\n\n if (\n _window.location.protocol !== anchor.protocol ||\n _window.location.hostname !== anchor.hostname ||\n _window.location.port !== anchor.port ||\n anchor.hasAttribute(\"data-router-ignore\") ||\n anchor.hasAttribute(\"download\") ||\n anchor.getAttribute(\"target\") === \"_blank\" ||\n /^[\\w-_]+:/.test(href)\n ) {\n return;\n }\n\n e.preventDefault();\n callback(href, anchor);\n }\n\n root.addEventListener(\"click\", handler as any);\n return () => root.removeEventListener(\"click\", handler as any);\n}\n\nexport function expandOptionalPaths(path: string): string[] {\n const parts = splitPath(path);\n const permutations: string[][] = [[]];\n\n for (const part of parts) {\n // Strictly enforces the inside style: {param?} or {#param?}\n const isOptional = part.endsWith(\"?}\");\n const cleanPart = isOptional ? part.replace(\"?\", \"\") : part;\n\n if (isOptional) {\n const withPart = permutations.map((p) => [...p, cleanPart]);\n permutations.push(...withPart);\n } else {\n for (const p of permutations) {\n p.push(cleanPart);\n }\n }\n }\n\n return permutations.map((p) => \"/\" + p.join(\"/\")).map((p) => (p === \"/\" ? p : p.replace(/\\/$/, \"\")));\n}\n\n/**\n * Replace route pattern param placeholders with real matched values.\n */\nexport function replaceParams(path: string, params: Record<string, string | number>) {\n for (const key in params) {\n const value = String(params[key]);\n path = path\n .replace(`{${key}}`, value)\n .replace(`{#${key}}`, value)\n .replace(`{${key}?}`, value) // Handle optional string param\n .replace(`{#${key}?}`, value); // Handle optional numeric param\n }\n\n // Remove any remaining unmatched optional parameters\n path = path.replace(/\\{#?[a-zA-Z0-9_]+\\?\\}/g, \"\");\n\n // Clean up any double slashes created by the removal\n path = path.replace(/\\/+/g, \"/\");\n\n // Strip trailing slash unless the entire path is just \"/\"\n if (path.length > 1 && path.endsWith(\"/\")) {\n path = path.slice(0, -1);\n }\n\n return path;\n}\n\nexport interface HistoryAdapter {\n getPath(): string;\n getSearch(): string;\n getKey(): string;\n getIndex(): number;\n push(url: string): void;\n replace(url: string): void;\n}\n\nexport function createHistoryAdapter(useHash: boolean): HistoryAdapter {\n let currentIndex = window.history.state?.index || 0;\n\n if (window.history.state?.index === undefined) {\n window.history.replaceState({ ...window.history.state, key: Date.now().toString(), index: currentIndex }, \"\");\n }\n\n const getPath = useHash ? () => window.location.hash.slice(1).split(\"?\")[0] || \"/\" : () => window.location.pathname;\n const getSearch = useHash\n ? () => {\n const hash = window.location.hash;\n const searchIndex = hash.indexOf(\"?\");\n return searchIndex !== -1 ? hash.slice(searchIndex) : \"\";\n }\n : () => window.location.search;\n\n const getKey = () => window.history.state?.key || \"root\";\n const getIndex = () => window.history.state?.index || 0;\n\n return {\n getPath,\n getSearch,\n getKey,\n getIndex,\n push: (url) => {\n currentIndex++;\n const prefix = useHash ? \"/#\" : \"\";\n window.history.pushState({ key: uniqueId(), index: currentIndex }, \"\", prefix + url);\n },\n replace: (url) => {\n const prefix = useHash ? \"/#\" : \"\";\n window.history.replaceState({ key: getKey(), index: currentIndex }, \"\", prefix + url);\n },\n };\n}\n","import { compose, getDebug, peek, type Context, type Getter, type Setter } from \"../core\";\nimport type { Router } from \"./types\";\nimport { mergeQueryParams, resolvePath, type HistoryAdapter, type Match } from \"./utils\";\n\nexport interface RouterStoreProps {\n currentMatch: Getter<Match>;\n setCurrentMatch: Setter<Match>;\n progress: Getter<number>;\n history: HistoryAdapter;\n updateRoute: () => void;\n guards: Set<() => boolean | Promise<boolean>>;\n}\n\nexport function RouterStore(\n this: Context,\n { currentMatch, setCurrentMatch, progress, history, updateRoute, guards }: RouterStoreProps,\n): Router {\n this.name = \"dolla:router\";\n const debug = getDebug(this);\n\n async function navigate(path: string, replace: boolean) {\n for (const guard of guards) {\n if (await guard()) return;\n }\n\n debug.info(`πΊοΈ navigating to '${path}'${replace ? \" (replace)\" : \"\"}`);\n\n const resolved = resolvePath(history.getPath(), path);\n replace ? history.replace(resolved) : history.push(resolved);\n updateRoute();\n }\n\n return {\n path: compose(() => currentMatch().path),\n pattern: compose(() => currentMatch().pattern),\n params: compose(() => currentMatch().params),\n query: compose(() => currentMatch().query),\n meta: compose(() => currentMatch().meta),\n progress: progress,\n\n setQuery(params) {\n const m = peek(currentMatch);\n const merged = mergeQueryParams(m.query, params, true);\n const query = Object.fromEntries(merged);\n\n setCurrentMatch({ ...m, query });\n\n const queryString = merged.size ? \"?\" + merged.toString() : \"\";\n history.replace(m.path + queryString);\n\n return query;\n },\n\n back: (steps = 1) => window.history.go(-steps),\n forward: (steps = 1) => window.history.go(steps),\n\n push: (path) => navigate(path, false),\n replace: (path) => navigate(path, true),\n\n block: (guard) => {\n guards.add(guard);\n return () => guards.delete(guard);\n },\n\n isActive(path: string, exact = false) {\n const target = path === \"/\" ? \"/\" : path.replace(/\\/$/, \"\");\n const targetSlash = target === \"/\" ? \"/\" : target + \"/\";\n\n return compose(() => {\n const current = currentMatch().path;\n const normalized = current === \"/\" ? \"/\" : current.replace(/\\/$/, \"\");\n\n if (exact) return normalized === target;\n\n // Ensure segment boundaries match (prevents /app matching /apple)\n return normalized === target || normalized.startsWith(targetSlash);\n });\n },\n };\n}\n","import { addStore, Context, createContext, onCleanup, onMount } from \"../core/context.js\";\nimport { DollaPlugin, getDebug, getRootElement } from \"../core/index.js\";\nimport { DynamicNode } from \"../core/markup/nodes/dynamic.js\";\nimport { ViewNode } from \"../core/markup/nodes/view.js\";\nimport type { MarkupNode } from \"../core/markup/types.js\";\nimport { addListener, createMarkup } from \"../core/markup/utils.js\";\nimport { batch, peek, createAtom } from \"../core/signals.js\";\nimport { DEBUG } from \"../core/symbols.js\";\nimport type { View } from \"../types.js\";\nimport { assert } from \"../utils.js\";\nimport { RouterStore } from \"./store.js\";\nimport type { ActiveLayer, LazyLoader, LazyView, RouterOptions } from \"./types.js\";\nimport {\n buildRouteTree,\n catchLinks,\n createHistoryAdapter,\n type Match,\n mergeQueryParams,\n replaceParams,\n resolveRoute,\n} from \"./utils.js\";\n\nconst ROUTER_ROOT_SLOT = Symbol();\n\n/**\n * Lazy loads a view when its route is first matched.\n *\n * @example\n * {\n * path: \"/users\",\n * view: lazy(() => import(\"./views/users.js\"))\n * }\n */\nexport function lazy(load: LazyLoader): LazyView {\n return { _lazy: true, load };\n}\n\nexport function createRouterPlugin(options: RouterOptions): DollaPlugin {\n return function (context) {\n if (\"scrollRestoration\" in window.history) {\n window.history.scrollRestoration = \"manual\";\n }\n\n const history = createHistoryAdapter(!!options.hash);\n const scrollCache = new Map<string, number>();\n let currentKey = history.getKey();\n\n const [currentMatch, setCurrentMatch] = createAtom<Match>({\n path: history.getPath(),\n pattern: \"\",\n params: {},\n query: Object.fromEntries(new URLSearchParams(history.getSearch())),\n meta: {},\n });\n\n const [progress, setProgress] = createAtom(0);\n const routeTree = buildRouteTree(options.routes);\n\n const guards = new Set<() => boolean | Promise<boolean>>();\n\n const routerContext = createContext(context);\n routerContext.name = \"dolla:router\";\n\n const console = getDebug(routerContext);\n const [rootSlot, setRootSlot] = createAtom<MarkupNode>();\n\n context[ROUTER_ROOT_SLOT] = rootSlot;\n\n const rootLayer: Partial<ActiveLayer> = {\n context,\n slot: rootSlot,\n setSlot: setRootSlot,\n };\n\n const activeLayers: ActiveLayer[] = [];\n\n /**\n * Run when the location changes. Diffs and mounts new routes and updates\n * the signals accordingly.\n */\n async function updateRoute(href?: string) {\n scrollCache.set(currentKey, window.scrollY);\n\n const path = href ?? history.getPath();\n const { match, journey } = await resolveRoute(routeTree, path);\n\n if (context[DEBUG]) {\n for (let i = 0; i < journey.length; i++) {\n const step = journey[i];\n const tag = `(update ${i + 1}/${journey.length})`;\n if (step.kind === \"match\") {\n console.info(`π ${tag} ${step.message}`);\n } else if (step.kind === \"redirect\") {\n console.info(`β©οΈ ${tag} ${step.message}`);\n } else {\n console.info(`π ${tag} ${step.message}`);\n }\n }\n }\n\n if (!match) throw new Error(`Failed to match route '${path}'`);\n\n const { layers, params } = match;\n const targetKeys: string[] = [];\n let branchIndex = 0;\n\n // Compute keys and find out where mounted layers diverge from matched layers\n for (let i = 0; i < layers.length; i++) {\n const key = `${layers[i].id}:${replaceParams(layers[i].pattern, params)}`;\n targetKeys.push(key);\n if (branchIndex === i && activeLayers[i]?.key === key) branchIndex++;\n }\n\n const tasks: Promise<void>[] = [];\n const preloadedData: any[] = []; // Offsets match loop index minus divIndex\n\n // Execute preloads and lazy component fetches\n for (let i = branchIndex; i < layers.length; i++) {\n const layer = layers[i];\n\n if (layer.preload) {\n tasks.push(\n Promise.resolve(layer.preload(match)).then((data) => {\n preloadedData[i - branchIndex] = data;\n }),\n );\n }\n\n const view = layer.view as LazyView;\n if (view._lazy) {\n tasks.push(\n view.load().then((mod) => {\n layer.view = (mod as any).default ?? mod; // Overwrite with loaded module\n }),\n );\n }\n }\n\n let caughtError: Error | null = null;\n let errorIndex = -1;\n\n // Track loading progress if there are async tasks\n if (tasks.length > 0) {\n setProgress(0.1);\n let completed = 0;\n const increment = 0.8 / tasks.length;\n\n tasks.forEach((p) => p.then(() => setProgress(0.1 + ++completed * increment)).catch(() => {}));\n\n try {\n await Promise.all(tasks);\n } catch (error) {\n setProgress(0);\n if (error instanceof RedirectError) return api.replace(error.redirectPath);\n\n caughtError = error instanceof Error ? error : new Error(String(error));\n errorIndex = branchIndex;\n }\n }\n\n // Merge query params and sync URL if redirect occurred\n const query = mergeQueryParams(peek(currentMatch).query, match.query, options.preserveQuery);\n const queryString = query.toString();\n const newUrl = match.path + (queryString ? `?${queryString}` : \"\");\n\n if (newUrl !== history.getPath() + history.getSearch()) {\n history.replace(newUrl);\n }\n\n // Batch state updates and DOM mutations\n batch(() => {\n setCurrentMatch({ ...match, query: Object.fromEntries(query) });\n\n if (branchIndex === layers.length && activeLayers.length === layers.length) return;\n\n // Fast truncate arrays and drop old DOM branches\n if (activeLayers[branchIndex]) {\n activeLayers[branchIndex].node.unmount();\n activeLayers.length = branchIndex;\n }\n\n // Mount new layers\n for (let i = branchIndex; i < layers.length; i++) {\n const layer = layers[i];\n const parent = activeLayers[i - 1] ?? rootLayer;\n const [slot, setSlot] = createAtom<MarkupNode>();\n\n let viewToMount = layer.view as View<any>;\n let propsToPass: any = {\n data: preloadedData[i - branchIndex],\n children: createMarkup(DynamicNode, { args: [slot] }),\n };\n\n // Handle Error Boundaries\n if (caughtError && i === errorIndex) {\n if (!layer.errorView) throw caughtError;\n viewToMount = layer.errorView;\n propsToPass = { error: caughtError };\n }\n\n const node = new ViewNode(parent.context!, viewToMount, propsToPass);\n parent.setSlot(node);\n\n activeLayers.push({\n id: layer.id,\n key: targetKeys[i],\n node,\n context: node.context,\n slot,\n setSlot,\n });\n\n if (caughtError && i === errorIndex) break;\n }\n });\n\n setProgress(0);\n\n requestAnimationFrame(() => {\n window.scrollTo(0, scrollCache.get(history.getKey()) ?? 0);\n currentKey = history.getKey();\n });\n }\n\n const api = addStore(context, RouterStore, {\n currentMatch,\n setCurrentMatch,\n progress,\n history,\n updateRoute,\n guards,\n });\n\n onMount(context, () => {\n let isReverting = false;\n let isReplaying = false;\n let lastIndex = history.getIndex();\n\n const removePop = addListener(window, \"popstate\", async () => {\n // If this popstate is the result of us reverting the URL, ignore it.\n if (isReverting) {\n isReverting = false;\n return;\n }\n\n // If this popstate is the result of us replaying an allowed navigation, accept it.\n if (isReplaying) {\n isReplaying = false;\n lastIndex = history.getIndex();\n updateRoute();\n return;\n }\n\n const newIndex = history.getIndex();\n const delta = lastIndex - newIndex; // Positive if user clicked Back\n\n // If guards exist, revert synchronously first\n if (guards.size > 0) {\n isReverting = true;\n window.history.go(delta); // Restores the URL immediately\n\n // Run guards while the URL is back in its original state\n let blocked = false;\n for (const guard of guards) {\n if (await guard()) {\n blocked = true;\n break;\n }\n }\n\n // If guards passed, replay the intended navigation\n if (!blocked) {\n isReplaying = true;\n window.history.go(-delta);\n }\n return;\n }\n\n // Normal flow (no guards)\n lastIndex = newIndex;\n updateRoute();\n });\n\n // Block tab closure/reload if guards exist\n const removeUnload = addListener(window, \"beforeunload\", (e: BeforeUnloadEvent) => {\n if (guards.size > 0) {\n e.preventDefault();\n e.returnValue = \"\"; // Triggers the native browser warning dialog\n }\n });\n\n const removeClick = catchLinks(getRootElement(context), api.push);\n\n onCleanup(context, () => {\n removePop();\n removeUnload();\n removeClick();\n });\n\n updateRoute();\n });\n };\n}\n\n/**\n * Displays the router's content.\n */\nexport function Outlet(this: Context) {\n this.name = \"dolla:router\";\n\n const rootSlot = this[ROUTER_ROOT_SLOT];\n assert(rootSlot != null, \"Router plugin not found on root.\");\n\n return new DynamicNode(this, rootSlot);\n}\n\nexport class RedirectError extends Error {\n constructor(public redirectPath: string) {\n super(`Redirecting to ${redirectPath}`);\n this.name = \"RedirectError\";\n }\n}\n","import { Context, getStore } from \"../core\";\nimport { RouterStore } from \"./store\";\n\nexport { createRouterPlugin, lazy, Outlet, RedirectError } from \"./router\";\nexport type { RouterOptions } from \"./types\";\n\nexport function getRouter(context: Context) {\n return getStore(context, RouterStore);\n}\n"],"mappings":";;;;AAsDA,SAAgB,EAAU,GAAwB;AAChD,QAAO,EACJ,MAAM,IAAI,CACV,KAAK,MAAM,EAAE,MAAM,CAAC,CACpB,OAAO,QAAQ;;AAUpB,SAAgB,EAAS,GAAyC;CAChE,IAAM,IAAS,EACZ,KAAK,MAAM,EAAE,UAAU,CAAC,CACxB,OAAO,QAAQ,CACf,KAAK,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AAW,EAAQ,UAAU,EAC7B,IAAQ,IAAY;AAG1B,QAAI,EAAO,OAAO,GAAG;AAEnB,KADA,IAAc,IACd,OAAO,QAAQ,GAAG,EAAM;KAGxB,IAAI,IAAU;AACd,UAAK,IAAM,KAAS,EAClB,KAAI,MAAM,GAAO,EAAE;AACjB,UAAU;AACV;;AAKJ,KAAK,MACH,IAAc,IACd,OAAO,QAAQ,GAAG,CAAC,EAAM;AAE3B;;AAKF,IADA,IAAY,GACZ,GAAa;KACb,EAGI,IAAe,EAAY,QAAQ,iBAAiB,MAAyB;AACjF,IAAI,EAAO,OAAO,MAChB,EAAE,gBAAgB,EAClB,EAAE,cAAc;KAElB,EAEI,IAAc,EAAW,EAAe,EAAQ,EAAE,EAAI,KAAK;AAQjE,GANA,EAAU,SAAe;AAGvB,IAFA,GAAW,EACX,GAAc,EACd,GAAa;KACb,EAEF,GAAa;IACb;;;AAON,SAAgB,IAAsB;AACpC,MAAK,OAAO;CAEZ,IAAM,IAAW,KAAK;AAGtB,QAFA,EAAO,KAAY,MAAM,mCAAmC,EAErD,IAAI,EAAY,MAAM,EAAS;;AAGxC,IAAa,IAAb,cAAmC,MAAM;CACvC,YAAY,GAA6B;AAEvC,EADA,MAAM,kBAAkB,IAAe,EADtB,KAAA,eAAA,GAEjB,KAAK,OAAO;;;;;ACzThB,SAAgB,EAAU,GAAkB;AAC1C,QAAO,EAAS,GAAS,EAAY"}
|
|
1
|
+
{"version":3,"file":"router.js","names":[],"sources":["../src/router/utils.ts","../src/router/store.ts","../src/router/router.ts","../src/router/index.ts"],"sourcesContent":["import { View } from \"../types.js\";\nimport { assert, isArray, isFunction, isObject, isString, uniqueId } from \"../utils.js\";\nimport type { JourneyStep, Route, RouteLayer, Stringable } from \"./types.js\";\n\nexport interface Match {\n /**\n * The path string that triggered this match.\n */\n path: string;\n\n /**\n * The pattern satisfied by `path`.\n */\n pattern: string;\n\n /**\n * Named params as parsed from `path`.\n */\n params: Record<string, string>;\n\n /**\n * Query params as parsed from `path`.\n */\n query: Record<string, string>;\n\n /**\n * Freeform data you wish to store with this route.\n * Merged `data` from all matched layers are available on the router's `match.meta`.\n */\n meta: Record<any, any>;\n}\n\nexport interface RouteMatch extends Match {\n layers: RouteLayer[];\n redirect?: string | ((match: Match) => string) | ((match: Match) => Promise<string>);\n}\n\nexport type RoutePayload = {\n pattern: string;\n meta: Record<any, any>;\n layers?: RouteLayer[];\n redirect?: string | ((match: Match) => string) | ((match: Match) => Promise<string>);\n};\n\nexport type RouteMatchOptions = {\n willMatch?: (route: RoutePayload) => boolean;\n};\n\n/**\n * Separates a URL path into multiple fragments.\n *\n * @param path - A path string (e.g. `\"/api/users/5\"`)\n * @returns an array of fragments (e.g. `[\"api\", \"users\", \"5\"]`)\n */\nexport function splitPath(path: string): string[] {\n return path\n .split(\"/\")\n .map((f) => f.trim())\n .filter(Boolean);\n}\n\n/**\n * Joins multiple URL path fragments into a single string.\n *\n * @param parts - One or more URL fragments (e.g. `[\"api\", \"users\", 5]`)\n * @returns a joined path (e.g. `\"api/users/5\"`)\n */\n\nexport function joinPath(parts: { toString(): string }[]): string {\n const joined = parts\n .map((p) => p.toString())\n .filter(Boolean)\n .join(\"/\");\n if (!joined) return \"\";\n\n const isAbsolute = joined.startsWith(\"/\");\n const segments = joined.split(\"/\");\n const resolved: string[] = [];\n\n for (const segment of segments) {\n if (segment === \"\" || segment === \".\") continue;\n if (segment === \"..\") {\n // Pop the previous segment unless we're at the root, or already backing up\n if (resolved.length > 0 && resolved[resolved.length - 1] !== \"..\") {\n resolved.pop();\n } else if (!isAbsolute) {\n resolved.push(\"..\");\n }\n } else {\n resolved.push(segment);\n }\n }\n\n let result = resolved.join(\"/\");\n if (isAbsolute) result = \"/\" + result;\n\n return result || (isAbsolute ? \"/\" : \"\");\n}\n\nexport function resolvePath(base: string, part: string | null = null): string {\n if (part == null) {\n part = base;\n base = \"\";\n }\n\n // If the target is absolute, it replaces the base entirely\n if (part.startsWith(\"/\")) return joinPath([part]);\n\n // Otherwise, join them and let joinPath resolve the '.' and '..'\n return joinPath([base, part]);\n}\n\nexport function parseQueryParams(query: string): Record<string, string> {\n return Object.fromEntries(new URLSearchParams(query));\n}\n\nexport function mergeQueryParams(\n previous: Record<string, string>,\n current: Record<string, Stringable | null>,\n preserve?: boolean | string[],\n) {\n const merged: Record<string, any> = {};\n\n if (preserve === true) {\n Object.assign(merged, previous);\n } else if (isArray(preserve)) {\n for (const key of preserve) {\n if (key in previous) merged[key] = previous[key];\n }\n }\n\n for (const [key, value] of Object.entries(current)) {\n if (value === null) {\n delete merged[key]; // Explicit nulls act as 'delete'\n } else {\n merged[key] = value;\n }\n }\n\n return new URLSearchParams(merged as Record<string, string>);\n}\n\nexport class RouteNode {\n staticChildren = new Map<string, RouteNode>();\n numericChild: RouteNode | null = null;\n paramChild: RouteNode | null = null;\n wildcardChild: RouteNode | null = null;\n\n // Set if this node represents the end of a valid path\n route?: RoutePayload;\n paramName?: string;\n numericName?: string;\n}\n\nexport function buildRouteTree(routes: Route[]): RouteNode {\n const root = new RouteNode();\n const redirectsToValidate: RoutePayload[] = [];\n\n function insertIntoTree(pattern: string, payload: RoutePayload) {\n const parts = splitPath(pattern);\n let current = root;\n\n for (const part of parts) {\n if (part === \"*\") {\n current = current.wildcardChild ??= new RouteNode();\n } else if (part.charCodeAt(0) === 123) {\n // {\n if (part.charCodeAt(1) === 35) {\n // #\n current = current.numericChild ??= new RouteNode();\n current.numericName = part.slice(2, -1);\n } else {\n current = current.paramChild ??= new RouteNode();\n current.paramName = part.slice(1, -1);\n }\n } else {\n const key = part.toLowerCase();\n let next = current.staticChildren.get(key);\n if (!next) current.staticChildren.set(key, (next = new RouteNode()));\n current = next;\n }\n }\n current.route = payload;\n }\n\n function parse(route: Route, parents: Route[] = [], layers: RouteLayer[] = []) {\n assert(isObject<Route>(route) && isString(route.path), \"Invalid route object\");\n\n const parentPaths = parents.map((p) => p.path);\n const parent = parents.at(-1);\n const meta = parent && route.meta ? { ...parent.meta, ...route.meta } : route.meta || {};\n\n const rawPattern = parentPaths.length ? joinPath([...parentPaths, route.path]) : route.path;\n const patterns = expandOptionalPaths(rawPattern);\n\n if (route.redirect) {\n assert(!route.routes && !route.view, \"Route cannot mix redirect with view/routes\");\n let redirect = route.redirect;\n\n if (isString(redirect)) {\n redirect = resolvePath(joinPath(parentPaths), redirect);\n if (!redirect.startsWith(\"/\")) redirect = \"/\" + redirect;\n }\n\n for (const pattern of patterns) {\n const payload: RoutePayload = { pattern, meta, redirect };\n insertIntoTree(pattern, payload);\n if (isString(redirect)) redirectsToValidate.push(payload);\n }\n\n return;\n }\n\n assert(route.view || route.routes, \"Route must have view, redirect, or routes\");\n\n let view = (route.view || ((props: any) => props.children)) as View<any>;\n if (!isFunction(view) && !(view as any)._lazy) {\n throw new TypeError(`Expected view function for ${route.path}`);\n }\n\n if (route.routes) {\n // For parent nodes, create the layer using the raw pattern and recurse\n const layer: RouteLayer = {\n id: uniqueId(),\n pattern: rawPattern,\n view,\n preload: route.preload,\n errorView: route.errorView,\n };\n for (const subroute of route.routes) parse(subroute, [...parents, route], [...layers, layer]);\n } else {\n // For leaf nodes, register every permutation as a valid endpoint\n for (const pattern of patterns) {\n const layer: RouteLayer = {\n id: uniqueId(),\n pattern, // Use the specific expanded pattern for this layer\n view,\n preload: route.preload,\n errorView: route.errorView,\n };\n insertIntoTree(pattern, { pattern, meta, layers: [...layers, layer] });\n }\n }\n }\n\n for (const route of routes) parse(route);\n\n for (const payload of redirectsToValidate) {\n assert(\n matchRoute(root, payload.redirect as string, { willMatch: (r) => r !== payload }),\n `Dead redirect: ${payload.pattern} -> ${payload.redirect}`,\n );\n }\n\n return root;\n}\n\nexport function matchRoute(rootNode: RouteNode, url: string, options: RouteMatchOptions = {}): RouteMatch | undefined {\n const [path, query] = url.split(\"?\");\n const parts = splitPath(path);\n const paramState: Record<string, string> = {}; // Reused across branches\n\n function search(node: RouteNode, index: number): RouteMatch | undefined {\n // if we've consumed all URL parts\n if (index === parts.length) {\n if (node.route && (!options.willMatch || options.willMatch(node.route))) {\n return {\n path: path || \"/\",\n pattern: node.route.pattern,\n params: { ...paramState },\n query: parseQueryParams(query || \"\"),\n meta: node.route.meta,\n layers: node.route.layers ?? [],\n redirect: node.route.redirect,\n };\n }\n\n // Allow wildcards to match zero remaining segments\n if (node.wildcardChild && node.wildcardChild.route) {\n if (!options.willMatch || options.willMatch(node.wildcardChild.route)) {\n return {\n path: path || \"/\",\n pattern: node.wildcardChild.route.pattern,\n params: { ...paramState, wildcard: \"/\" },\n query: parseQueryParams(query || \"\"),\n meta: node.wildcardChild.route.meta,\n layers: node.wildcardChild.route.layers ?? [],\n redirect: node.wildcardChild.route.redirect,\n };\n }\n }\n\n return undefined;\n }\n\n const part = parts[index];\n const lowerPart = part.toLowerCase();\n\n const staticNode = node.staticChildren.get(lowerPart);\n if (staticNode) {\n const result = search(staticNode, index + 1);\n if (result) return result;\n }\n\n if (node.numericChild && !isNaN(Number(part))) {\n paramState[node.numericChild.numericName!] = part;\n const result = search(node.numericChild, index + 1);\n if (result) return result;\n delete paramState[node.numericChild.numericName!];\n }\n\n if (node.paramChild) {\n paramState[node.paramChild.paramName!] = decodeURIComponent(part);\n const result = search(node.paramChild, index + 1);\n if (result) return result;\n delete paramState[node.paramChild.paramName!];\n }\n\n if (node.wildcardChild && node.wildcardChild.route) {\n if (!options.willMatch || options.willMatch(node.wildcardChild.route)) {\n return {\n path: path || \"/\",\n pattern: node.wildcardChild.route.pattern,\n params: { ...paramState, wildcard: \"/\" + parts.slice(index).map(decodeURIComponent).join(\"/\") },\n query: parseQueryParams(query || \"\"),\n meta: node.wildcardChild.route.meta,\n layers: node.wildcardChild.route.layers ?? [],\n redirect: node.wildcardChild.route.redirect,\n };\n }\n }\n\n return undefined;\n }\n\n return search(rootNode, 0);\n}\n\nexport interface ResolvedRoute {\n match?: RouteMatch;\n journey: JourneyStep[];\n}\n\n/**\n * Takes a URL and finds a match, following redirects.\n */\nexport async function resolveRoute(\n rootNode: RouteNode,\n path: string,\n journey: JourneyStep[] = [],\n): Promise<ResolvedRoute> {\n const match = matchRoute(rootNode, path);\n\n if (!match) return { journey: [...journey, { kind: \"miss\", message: `no match for '${path}'` }] };\n\n if (match.redirect != null) {\n let target = match.redirect;\n\n if (isString(target)) {\n target = replaceParams(target, match.params);\n } else {\n target = await target(match);\n assert(isString(target), \"Redirect function must return a path.\");\n if (!target.startsWith(\"/\")) target = resolvePath(match.path, target);\n }\n\n return resolveRoute(rootNode, target, [\n ...journey,\n { kind: \"redirect\", message: `redirecting '${match.path}' -> '${target}'` },\n ]);\n }\n\n // TODO: Data preload\n\n return { match, journey: [...journey, { kind: \"match\", message: `matched route '${match.path}'` }] };\n}\n\n/**\n * Intercepts links within the root node.\n *\n * This is adapted from https://github.com/choojs/nanohref/blob/master/index.js\n *\n * @param root - Element under which to intercept link clicks\n * @param callback - Function to call when a click event is intercepted\n * @param _window - (optional) Override for global window object\n */\nexport function catchLinks(\n root: Element,\n callback: (href: string, anchor: HTMLAnchorElement) => void,\n _window = window,\n) {\n function handler(e: MouseEvent) {\n if ((e.button && e.button !== 0) || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.defaultPrevented) return;\n\n const anchor = (e.target as Element).closest(\"a\");\n if (!anchor || !root.contains(anchor)) return;\n\n const href = anchor.getAttribute(\"href\");\n if (!href) return;\n\n if (\n _window.location.protocol !== anchor.protocol ||\n _window.location.hostname !== anchor.hostname ||\n _window.location.port !== anchor.port ||\n anchor.hasAttribute(\"data-router-ignore\") ||\n anchor.hasAttribute(\"download\") ||\n anchor.getAttribute(\"target\") === \"_blank\" ||\n /^[\\w-_]+:/.test(href)\n ) {\n return;\n }\n\n e.preventDefault();\n callback(href, anchor);\n }\n\n root.addEventListener(\"click\", handler as any);\n return () => root.removeEventListener(\"click\", handler as any);\n}\n\nexport function expandOptionalPaths(path: string): string[] {\n const parts = splitPath(path);\n const permutations: string[][] = [[]];\n\n for (const part of parts) {\n // Strictly enforces the inside style: {param?} or {#param?}\n const isOptional = part.endsWith(\"?}\");\n const cleanPart = isOptional ? part.replace(\"?\", \"\") : part;\n\n if (isOptional) {\n const withPart = permutations.map((p) => [...p, cleanPart]);\n permutations.push(...withPart);\n } else {\n for (const p of permutations) {\n p.push(cleanPart);\n }\n }\n }\n\n return permutations.map((p) => \"/\" + p.join(\"/\")).map((p) => (p === \"/\" ? p : p.replace(/\\/$/, \"\")));\n}\n\n/**\n * Replace route pattern param placeholders with real matched values.\n */\nexport function replaceParams(path: string, params: Record<string, string | number>) {\n for (const key in params) {\n const value = String(params[key]);\n path = path\n .replace(`{${key}}`, value)\n .replace(`{#${key}}`, value)\n .replace(`{${key}?}`, value) // Handle optional string param\n .replace(`{#${key}?}`, value); // Handle optional numeric param\n }\n\n // Remove any remaining unmatched optional parameters\n path = path.replace(/\\{#?[a-zA-Z0-9_]+\\?\\}/g, \"\");\n\n // Clean up any double slashes created by the removal\n path = path.replace(/\\/+/g, \"/\");\n\n // Strip trailing slash unless the entire path is just \"/\"\n if (path.length > 1 && path.endsWith(\"/\")) {\n path = path.slice(0, -1);\n }\n\n return path;\n}\n\nexport interface HistoryAdapter {\n getPath(): string;\n getSearch(): string;\n getKey(): string;\n getIndex(): number;\n push(url: string): void;\n replace(url: string): void;\n}\n\nexport function createHistoryAdapter(useHash: boolean): HistoryAdapter {\n let currentIndex = window.history.state?.index || 0;\n\n if (window.history.state?.index === undefined) {\n window.history.replaceState({ ...window.history.state, key: Date.now().toString(), index: currentIndex }, \"\");\n }\n\n const getPath = useHash ? () => window.location.hash.slice(1).split(\"?\")[0] || \"/\" : () => window.location.pathname;\n const getSearch = useHash\n ? () => {\n const hash = window.location.hash;\n const searchIndex = hash.indexOf(\"?\");\n return searchIndex !== -1 ? hash.slice(searchIndex) : \"\";\n }\n : () => window.location.search;\n\n const getKey = () => window.history.state?.key || \"root\";\n const getIndex = () => window.history.state?.index || 0;\n\n return {\n getPath,\n getSearch,\n getKey,\n getIndex,\n push: (url) => {\n currentIndex++;\n const prefix = useHash ? \"/#\" : \"\";\n window.history.pushState({ key: uniqueId(), index: currentIndex }, \"\", prefix + url);\n },\n replace: (url) => {\n const prefix = useHash ? \"/#\" : \"\";\n window.history.replaceState({ key: getKey(), index: currentIndex }, \"\", prefix + url);\n },\n };\n}\n","import { compose, getDebug, peek, unwrap, type Context, type Getter, type MaybeGetter, type Setter } from \"../core\";\nimport type { Router } from \"./types\";\nimport { mergeQueryParams, resolvePath, type HistoryAdapter, type Match } from \"./utils\";\n\nexport interface RouterStoreProps {\n currentMatch: Getter<Match>;\n setCurrentMatch: Setter<Match>;\n progress: Getter<number>;\n history: HistoryAdapter;\n updateRoute: () => void;\n guards: Set<() => boolean | Promise<boolean>>;\n}\n\nexport function RouterStore(\n this: Context,\n { currentMatch, setCurrentMatch, progress, history, updateRoute, guards }: RouterStoreProps,\n): Router {\n this.name = \"dolla:router\";\n const debug = getDebug(this);\n\n async function navigate(path: string, replace: boolean) {\n for (const guard of guards) {\n if (await guard()) return;\n }\n\n debug.info(`πΊοΈ navigating to '${path}'${replace ? \" (replace)\" : \"\"}`);\n\n const resolved = resolvePath(history.getPath(), path);\n replace ? history.replace(resolved) : history.push(resolved);\n updateRoute();\n }\n\n return {\n path: compose(() => currentMatch().path),\n pattern: compose(() => currentMatch().pattern),\n params: compose(() => currentMatch().params),\n query: compose(() => currentMatch().query),\n meta: compose(() => currentMatch().meta),\n progress: progress,\n\n setQuery(params) {\n const m = peek(currentMatch);\n const merged = mergeQueryParams(m.query, params, true);\n const query = Object.fromEntries(merged);\n\n setCurrentMatch({ ...m, query });\n\n const queryString = merged.size ? \"?\" + merged.toString() : \"\";\n history.replace(m.path + queryString);\n\n return query;\n },\n\n back: (steps = 1) => window.history.go(-steps),\n forward: (steps = 1) => window.history.go(steps),\n\n push: (path) => navigate(path, false),\n replace: (path) => navigate(path, true),\n\n block: (guard) => {\n guards.add(guard);\n return () => guards.delete(guard);\n },\n\n isActive(path: MaybeGetter<string>, exact = false) {\n return compose(() => {\n const _path = unwrap(path);\n const target = _path === \"/\" ? \"/\" : _path.replace(/\\/$/, \"\");\n const targetSlash = target === \"/\" ? \"/\" : target + \"/\";\n\n const current = currentMatch().path;\n const normalized = current === \"/\" ? \"/\" : current.replace(/\\/$/, \"\");\n\n if (exact) return normalized === target;\n\n // Ensure segment boundaries match (prevents /app matching /apple)\n return normalized === target || normalized.startsWith(targetSlash);\n });\n },\n };\n}\n","import { addStore, Context, createContext, onCleanup, onMount } from \"../core/context.js\";\nimport { DollaPlugin, getDebug, getRootElement } from \"../core/index.js\";\nimport { DynamicNode } from \"../core/markup/nodes/dynamic.js\";\nimport { ViewNode } from \"../core/markup/nodes/view.js\";\nimport type { MarkupNode } from \"../core/markup/types.js\";\nimport { addListener, createMarkup } from \"../core/markup/utils.js\";\nimport { batch, peek, createAtom } from \"../core/signals.js\";\nimport { DEBUG } from \"../core/symbols.js\";\nimport type { View } from \"../types.js\";\nimport { assert } from \"../utils.js\";\nimport { RouterStore } from \"./store.js\";\nimport type { ActiveLayer, LazyLoader, LazyView, RouterOptions } from \"./types.js\";\nimport {\n buildRouteTree,\n catchLinks,\n createHistoryAdapter,\n type Match,\n mergeQueryParams,\n replaceParams,\n resolveRoute,\n} from \"./utils.js\";\n\nconst ROUTER_ROOT_SLOT = Symbol();\n\n/**\n * Lazy loads a view when its route is first matched.\n *\n * @example\n * {\n * path: \"/users\",\n * view: lazy(() => import(\"./views/users.js\"))\n * }\n */\nexport function lazy(load: LazyLoader): LazyView {\n return { _lazy: true, load };\n}\n\nexport function createRouterPlugin(options: RouterOptions): DollaPlugin {\n return function (context) {\n if (\"scrollRestoration\" in window.history) {\n window.history.scrollRestoration = \"manual\";\n }\n\n const history = createHistoryAdapter(!!options.hash);\n const scrollCache = new Map<string, number>();\n let currentKey = history.getKey();\n\n const [currentMatch, setCurrentMatch] = createAtom<Match>({\n path: history.getPath(),\n pattern: \"\",\n params: {},\n query: Object.fromEntries(new URLSearchParams(history.getSearch())),\n meta: {},\n });\n\n const [progress, setProgress] = createAtom(0);\n const routeTree = buildRouteTree(options.routes);\n\n const guards = new Set<() => boolean | Promise<boolean>>();\n\n const routerContext = createContext(context);\n routerContext.name = \"dolla:router\";\n\n const console = getDebug(routerContext);\n const [rootSlot, setRootSlot] = createAtom<MarkupNode>();\n\n context[ROUTER_ROOT_SLOT] = rootSlot;\n\n const rootLayer: Partial<ActiveLayer> = {\n context,\n slot: rootSlot,\n setSlot: setRootSlot,\n };\n\n const activeLayers: ActiveLayer[] = [];\n\n /**\n * Run when the location changes. Diffs and mounts new routes and updates\n * the signals accordingly.\n */\n async function updateRoute(href?: string) {\n scrollCache.set(currentKey, window.scrollY);\n\n const path = href ?? history.getPath();\n const { match, journey } = await resolveRoute(routeTree, path);\n\n if (context[DEBUG]) {\n for (let i = 0; i < journey.length; i++) {\n const step = journey[i];\n const tag = `(update ${i + 1}/${journey.length})`;\n if (step.kind === \"match\") {\n console.info(`π ${tag} ${step.message}`);\n } else if (step.kind === \"redirect\") {\n console.info(`β©οΈ ${tag} ${step.message}`);\n } else {\n console.info(`π ${tag} ${step.message}`);\n }\n }\n }\n\n if (!match) throw new Error(`Failed to match route '${path}'`);\n\n const { layers, params } = match;\n const targetKeys: string[] = [];\n let branchIndex = 0;\n\n // Compute keys and find out where mounted layers diverge from matched layers\n for (let i = 0; i < layers.length; i++) {\n const key = `${layers[i].id}:${replaceParams(layers[i].pattern, params)}`;\n targetKeys.push(key);\n if (branchIndex === i && activeLayers[i]?.key === key) branchIndex++;\n }\n\n const tasks: Promise<void>[] = [];\n const preloadedData: any[] = []; // Offsets match loop index minus divIndex\n\n // Execute preloads and lazy component fetches\n for (let i = branchIndex; i < layers.length; i++) {\n const layer = layers[i];\n\n if (layer.preload) {\n tasks.push(\n Promise.resolve(layer.preload(match)).then((data) => {\n preloadedData[i - branchIndex] = data;\n }),\n );\n }\n\n const view = layer.view as LazyView;\n if (view._lazy) {\n tasks.push(\n view.load().then((mod) => {\n layer.view = (mod as any).default ?? mod; // Overwrite with loaded module\n }),\n );\n }\n }\n\n let caughtError: Error | null = null;\n let errorIndex = -1;\n\n // Track loading progress if there are async tasks\n if (tasks.length > 0) {\n setProgress(0.1);\n let completed = 0;\n const increment = 0.8 / tasks.length;\n\n tasks.forEach((p) => p.then(() => setProgress(0.1 + ++completed * increment)).catch(() => {}));\n\n try {\n await Promise.all(tasks);\n } catch (error) {\n setProgress(0);\n if (error instanceof RedirectError) return api.replace(error.redirectPath);\n\n caughtError = error instanceof Error ? error : new Error(String(error));\n errorIndex = branchIndex;\n }\n }\n\n // Merge query params and sync URL if redirect occurred\n const query = mergeQueryParams(peek(currentMatch).query, match.query, options.preserveQuery);\n const queryString = query.toString();\n const newUrl = match.path + (queryString ? `?${queryString}` : \"\");\n\n if (newUrl !== history.getPath() + history.getSearch()) {\n history.replace(newUrl);\n }\n\n // Batch state updates and DOM mutations\n batch(() => {\n setCurrentMatch({ ...match, query: Object.fromEntries(query) });\n\n if (branchIndex === layers.length && activeLayers.length === layers.length) return;\n\n // Fast truncate arrays and drop old DOM branches\n if (activeLayers[branchIndex]) {\n activeLayers[branchIndex].node.unmount();\n activeLayers.length = branchIndex;\n }\n\n // Mount new layers\n for (let i = branchIndex; i < layers.length; i++) {\n const layer = layers[i];\n const parent = activeLayers[i - 1] ?? rootLayer;\n const [slot, setSlot] = createAtom<MarkupNode>();\n\n let viewToMount = layer.view as View<any>;\n let propsToPass: any = {\n data: preloadedData[i - branchIndex],\n children: createMarkup(DynamicNode, { args: [slot] }),\n };\n\n // Handle Error Boundaries\n if (caughtError && i === errorIndex) {\n if (!layer.errorView) throw caughtError;\n viewToMount = layer.errorView;\n propsToPass = { error: caughtError };\n }\n\n const node = new ViewNode(parent.context!, viewToMount, propsToPass);\n parent.setSlot(node);\n\n activeLayers.push({\n id: layer.id,\n key: targetKeys[i],\n node,\n context: node.context,\n slot,\n setSlot,\n });\n\n if (caughtError && i === errorIndex) break;\n }\n });\n\n setProgress(0);\n\n requestAnimationFrame(() => {\n window.scrollTo(0, scrollCache.get(history.getKey()) ?? 0);\n currentKey = history.getKey();\n });\n }\n\n const api = addStore(context, RouterStore, {\n currentMatch,\n setCurrentMatch,\n progress,\n history,\n updateRoute,\n guards,\n });\n\n onMount(context, () => {\n let isReverting = false;\n let isReplaying = false;\n let lastIndex = history.getIndex();\n\n const removePop = addListener(window, \"popstate\", async () => {\n // If this popstate is the result of us reverting the URL, ignore it.\n if (isReverting) {\n isReverting = false;\n return;\n }\n\n // If this popstate is the result of us replaying an allowed navigation, accept it.\n if (isReplaying) {\n isReplaying = false;\n lastIndex = history.getIndex();\n updateRoute();\n return;\n }\n\n const newIndex = history.getIndex();\n const delta = lastIndex - newIndex; // Positive if user clicked Back\n\n // If guards exist, revert synchronously first\n if (guards.size > 0) {\n isReverting = true;\n window.history.go(delta); // Restores the URL immediately\n\n // Run guards while the URL is back in its original state\n let blocked = false;\n for (const guard of guards) {\n if (await guard()) {\n blocked = true;\n break;\n }\n }\n\n // If guards passed, replay the intended navigation\n if (!blocked) {\n isReplaying = true;\n window.history.go(-delta);\n }\n return;\n }\n\n // Normal flow (no guards)\n lastIndex = newIndex;\n updateRoute();\n });\n\n // Block tab closure/reload if guards exist\n const removeUnload = addListener(window, \"beforeunload\", (e: BeforeUnloadEvent) => {\n if (guards.size > 0) {\n e.preventDefault();\n e.returnValue = \"\"; // Triggers the native browser warning dialog\n }\n });\n\n const removeClick = catchLinks(getRootElement(context), api.push);\n\n onCleanup(context, () => {\n removePop();\n removeUnload();\n removeClick();\n });\n\n updateRoute();\n });\n };\n}\n\n/**\n * Displays the router's content.\n */\nexport function Outlet(this: Context) {\n this.name = \"dolla:router\";\n\n const rootSlot = this[ROUTER_ROOT_SLOT];\n assert(rootSlot != null, \"Router plugin not found on root.\");\n\n return new DynamicNode(this, rootSlot);\n}\n\nexport class RedirectError extends Error {\n constructor(public redirectPath: string) {\n super(`Redirecting to ${redirectPath}`);\n this.name = \"RedirectError\";\n }\n}\n","import { Context, getStore } from \"../core\";\nimport { RouterStore } from \"./store\";\n\nexport { createRouterPlugin, lazy, Outlet, RedirectError } from \"./router\";\nexport type { RouterOptions } from \"./types\";\n\nexport function getRouter(context: Context) {\n return getStore(context, RouterStore);\n}\n"],"mappings":";;AAsDA,SAAgB,EAAU,GAAwB;AAChD,QAAO,EACJ,MAAM,IAAI,CACV,KAAK,MAAM,EAAE,MAAM,CAAC,CACpB,OAAO,QAAQ;;AAUpB,SAAgB,EAAS,GAAyC;CAChE,IAAM,IAAS,EACZ,KAAK,MAAM,EAAE,UAAU,CAAC,CACxB,OAAO,QAAQ,CACf,KAAK,IAAI;AACZ,KAAI,CAAC,EAAQ,QAAO;CAEpB,IAAM,IAAa,EAAO,WAAW,IAAI,EACnC,IAAW,EAAO,MAAM,IAAI,EAC5B,IAAqB,EAAE;AAE7B,MAAK,IAAM,KAAW,EAChB,OAAY,MAAM,MAAY,QAC9B,MAAY,OAEV,EAAS,SAAS,KAAK,EAAS,EAAS,SAAS,OAAO,OAC3D,EAAS,KAAK,GACJ,KACV,EAAS,KAAK,KAAK,GAGrB,EAAS,KAAK,EAAQ;CAI1B,IAAI,IAAS,EAAS,KAAK,IAAI;AAG/B,QAFI,MAAY,IAAS,MAAM,IAExB,MAAW,IAAa,MAAM;;AAGvC,SAAgB,EAAY,GAAc,IAAsB,MAAc;AAU5E,QATI,MACF,IAAO,GACP,IAAO,KAIL,EAAK,WAAW,IAAI,GAAS,EAAS,CAAC,EAAK,CAAC,GAG1C,EAAS,CAAC,GAAM,EAAK,CAAC;;AAG/B,SAAgB,EAAiB,GAAuC;AACtE,QAAO,OAAO,YAAY,IAAI,gBAAgB,EAAM,CAAC;;AAGvD,SAAgB,EACd,GACA,GACA,GACA;CACA,IAAM,IAA8B,EAAE;AAEtC,KAAI,MAAa,GACf,QAAO,OAAO,GAAQ,EAAS;UACtB,EAAQ,EAAS,OACrB,IAAM,KAAO,EAChB,CAAI,KAAO,MAAU,EAAO,KAAO,EAAS;AAIhD,MAAK,IAAM,CAAC,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BAAkB,IAAe,EADtB,KAAA,eAAA,GAEjB,KAAK,OAAO;;;;;ACzThB,SAAgB,EAAU,GAAkB;AAC1C,QAAO,EAAS,GAAS,EAAY"}
|
package/dist/translate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as e, I as t, N as n, O as r } from "./core-2CFW0uRa.js";
|
|
2
2
|
//#region src/translate/index.ts
|
|
3
3
|
var i = Symbol("Dolla.Translator");
|
|
4
4
|
function a(e) {
|
|
@@ -11,29 +11,29 @@ function o(e) {
|
|
|
11
11
|
if (!e[i]) throw Error("Translate plugin isn't loaded.");
|
|
12
12
|
return e[i];
|
|
13
13
|
}
|
|
14
|
-
function s(
|
|
14
|
+
function s(t) {
|
|
15
15
|
let i = /* @__PURE__ */ new Map();
|
|
16
|
-
if (i.set("number", (e, t, n) => new Intl.NumberFormat(e, n).format(Number(t))), i.set("datetime", (e, t, n) => new Intl.DateTimeFormat(e, n).format(new Date(t))), i.set("list", (e, t, n) => new Intl.ListFormat(e, n).format(t)),
|
|
17
|
-
let a, [o, s] =
|
|
16
|
+
if (i.set("number", (e, t, n) => new Intl.NumberFormat(e, n).format(Number(t))), i.set("datetime", (e, t, n) => new Intl.DateTimeFormat(e, n).format(new Date(t))), i.set("list", (e, t, n) => new Intl.ListFormat(e, n).format(t)), t.formatters) for (let e in t.formatters) i.set(e, t.formatters[e]);
|
|
17
|
+
let a, [o, s] = r("en"), l = [...Object.keys(t.translations)];
|
|
18
18
|
async function u(e) {
|
|
19
|
-
let
|
|
19
|
+
let n;
|
|
20
20
|
if (e === void 0) {
|
|
21
21
|
let e = [];
|
|
22
22
|
if (typeof navigator < "u") {
|
|
23
23
|
let t = navigator;
|
|
24
24
|
t.languages?.length > 0 ? e.push(...t.languages) : t.language ? e.push(t.language) : t.browserLanguage ? e.push(t.browserLanguage) : t.userLanguage && e.push(t.userLanguage);
|
|
25
25
|
}
|
|
26
|
-
for (let
|
|
27
|
-
|
|
26
|
+
for (let r of e) if (r in t.translations) {
|
|
27
|
+
n = r;
|
|
28
28
|
break;
|
|
29
29
|
}
|
|
30
|
-
} else e in
|
|
31
|
-
if (
|
|
32
|
-
let e = Object.keys(
|
|
33
|
-
e && (
|
|
30
|
+
} else e in t.translations && (n = e);
|
|
31
|
+
if (n == null) {
|
|
32
|
+
let e = Object.keys(t.translations).at(0);
|
|
33
|
+
e && (n = e);
|
|
34
34
|
}
|
|
35
|
-
if (!
|
|
36
|
-
a = await c(
|
|
35
|
+
if (!n || !(n in t.translations)) throw Error(`Locale '${e}' has no translation.`);
|
|
36
|
+
a = await c(n, i, t.translations[n]), s(n);
|
|
37
37
|
}
|
|
38
38
|
function d(t, n) {
|
|
39
39
|
return e(() => (o(), a?.(t, n) ?? t));
|
|
@@ -51,20 +51,20 @@ function s(r) {
|
|
|
51
51
|
format: f
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
async function c(e,
|
|
55
|
-
let a = l(
|
|
56
|
-
return function(
|
|
57
|
-
if (i && (i.context != null && (
|
|
58
|
-
let
|
|
59
|
-
o.has(
|
|
54
|
+
async function c(e, r, i) {
|
|
55
|
+
let a = l(t(i) ? await i() : i), o = new Map(a);
|
|
56
|
+
return function(t, i) {
|
|
57
|
+
if (i && (i.context != null && (t += "_" + i.context), i.count != null)) if (i.ordinal) {
|
|
58
|
+
let r = `${t}_ordinal_(=${i.count})`;
|
|
59
|
+
o.has(r) ? t = r : t += "_ordinal_" + new Intl.PluralRules(e, { type: "ordinal" }).select(n(i.count));
|
|
60
60
|
} else {
|
|
61
|
-
let
|
|
62
|
-
o.has(
|
|
61
|
+
let r = `${t}_(=${i.count})`;
|
|
62
|
+
o.has(r) ? t = r : t += "_" + new Intl.PluralRules(e).select(n(i.count));
|
|
63
63
|
}
|
|
64
|
-
let a = o.get(
|
|
65
|
-
if (!a) return
|
|
64
|
+
let a = o.get(t);
|
|
65
|
+
if (!a) return t;
|
|
66
66
|
let s = "";
|
|
67
|
-
for (let
|
|
67
|
+
for (let t = 0; t < a.length; t++) s += a[t](i, r, e);
|
|
68
68
|
return s;
|
|
69
69
|
};
|
|
70
70
|
}
|
package/package.json
CHANGED
package/dist/context-B5blupD2.js
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
import { a as e, c as t, d as n, f as r, i, l as a, m as o, o as s, p as c, u as l } from "./signals-CMJPGr_M.js";
|
|
2
|
-
//#region src/core/markup/types.ts
|
|
3
|
-
var u = Symbol(), d = Symbol(), f = Symbol(), p = class {
|
|
4
|
-
static [f] = !0;
|
|
5
|
-
get [d]() {
|
|
6
|
-
return !0;
|
|
7
|
-
}
|
|
8
|
-
}, m = class extends p {
|
|
9
|
-
#e;
|
|
10
|
-
constructor(e, t) {
|
|
11
|
-
super(), this.#e = t;
|
|
12
|
-
}
|
|
13
|
-
getRoot() {
|
|
14
|
-
return this.#e;
|
|
15
|
-
}
|
|
16
|
-
isMounted() {
|
|
17
|
-
return this.#e.parentNode != null;
|
|
18
|
-
}
|
|
19
|
-
mount(e, t) {
|
|
20
|
-
N(e, this.#e, t);
|
|
21
|
-
}
|
|
22
|
-
unmount(e = !1) {
|
|
23
|
-
e || this.#e.parentNode?.removeChild(this.#e);
|
|
24
|
-
}
|
|
25
|
-
move(e, t) {
|
|
26
|
-
F(e, this.#e, t);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/core/markup/scheduler.ts
|
|
31
|
-
function h(e) {
|
|
32
|
-
e();
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/core/markup/nodes/dynamic.ts
|
|
36
|
-
var g = class extends p {
|
|
37
|
-
#e = P("");
|
|
38
|
-
#t = [];
|
|
39
|
-
#n;
|
|
40
|
-
#r;
|
|
41
|
-
#i;
|
|
42
|
-
constructor(e, t) {
|
|
43
|
-
super(), this.#n = e, this.#r = t;
|
|
44
|
-
}
|
|
45
|
-
getRoot() {
|
|
46
|
-
return this.#e;
|
|
47
|
-
}
|
|
48
|
-
isMounted() {
|
|
49
|
-
return this.#e.parentNode != null;
|
|
50
|
-
}
|
|
51
|
-
mount(e, t) {
|
|
52
|
-
this.isMounted() || (N(e, this.#e, t), this.#i = s(this.#r, (e) => {
|
|
53
|
-
h(() => {
|
|
54
|
-
this.#o(e);
|
|
55
|
-
});
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
unmount(e = !1) {
|
|
59
|
-
this.#i?.(), this.isMounted() && (e || this.#e.parentNode?.removeChild(this.#e), this.#a(e));
|
|
60
|
-
}
|
|
61
|
-
move(e, t) {
|
|
62
|
-
let n = t?.nextSibling ?? null;
|
|
63
|
-
if (e.moveBefore) try {
|
|
64
|
-
e.moveBefore(this.#e, n), n = this.#e.nextSibling;
|
|
65
|
-
for (let t = 0; t < this.#t.length; t++) {
|
|
66
|
-
let r = this.#t[t].getRoot();
|
|
67
|
-
r && e.moveBefore(r, n);
|
|
68
|
-
}
|
|
69
|
-
return;
|
|
70
|
-
} catch {}
|
|
71
|
-
e.insertBefore(this.#e, n), n = this.#e.nextSibling;
|
|
72
|
-
for (let t = 0; t < this.#t.length; t++) this.#t[t].move(e, this.#t[t - 1]?.getRoot() ?? this.#e);
|
|
73
|
-
}
|
|
74
|
-
#a(e) {
|
|
75
|
-
for (let t = 0; t < this.#t.length; t++) this.#t[t].unmount(e);
|
|
76
|
-
this.#t.length = 0;
|
|
77
|
-
}
|
|
78
|
-
#o(e) {
|
|
79
|
-
if (!this.isMounted()) return;
|
|
80
|
-
if ((typeof e == "string" || typeof e == "number") && this.#t.length === 1) {
|
|
81
|
-
let t = this.#t[0];
|
|
82
|
-
if (t instanceof m) {
|
|
83
|
-
let n = t.getRoot();
|
|
84
|
-
if (n && n.nodeType === Node.TEXT_NODE) {
|
|
85
|
-
n.nodeValue = String(e);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (this.#a(!1), e == null || e === !1) return;
|
|
91
|
-
let t = M(this.#n, e), n = this.#e.parentElement, r = this.#e;
|
|
92
|
-
for (let e = 0; e < t.length; e++) {
|
|
93
|
-
let i = t[e];
|
|
94
|
-
i.mount(n, r), this.#t.push(i);
|
|
95
|
-
let a = i.getRoot();
|
|
96
|
-
a && (r = a);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}, _ = Symbol("parentElement"), v = Symbol("debug"), y = Symbol("isSVG"), b = ["ref", "children"], x = class extends p {
|
|
100
|
-
#e;
|
|
101
|
-
#t;
|
|
102
|
-
#n;
|
|
103
|
-
#r = !1;
|
|
104
|
-
#i = [];
|
|
105
|
-
#a = /* @__PURE__ */ new Set();
|
|
106
|
-
#o;
|
|
107
|
-
constructor(e, t, n) {
|
|
108
|
-
if (super(), this.#t = n, this.#n = e, t === "svg" ? (this.#n = V(e), this.#n[y] = !0, this.#r = !0) : this.#n[y] && t === "foreignObject" && (this.#n = V(e), this.#n[y] = !1, this.#r = !1), this.#n[y] ? this.#e = document.createElementNS("http://www.w3.org/2000/svg", t) : this.#e = document.createElement(t), this.#n[v]) {
|
|
109
|
-
let e = Y(this.#n);
|
|
110
|
-
e && (this.#e.dataset.view = e.context.name);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
getRoot() {
|
|
114
|
-
return this.#e;
|
|
115
|
-
}
|
|
116
|
-
isMounted() {
|
|
117
|
-
return this.#e.parentNode != null;
|
|
118
|
-
}
|
|
119
|
-
mount(e, t) {
|
|
120
|
-
let n = this.isMounted();
|
|
121
|
-
if (!n && (this.#c(this.#e, o(b, this.#t)), this.#t.children)) {
|
|
122
|
-
this.#i = M(this.#n, this.#t.children);
|
|
123
|
-
for (let e of this.#i) e.mount(this.#e);
|
|
124
|
-
}
|
|
125
|
-
let r = t?.nextSibling ?? null;
|
|
126
|
-
if ((this.#e.parentNode !== e || this.#e.nextSibling !== r) && N(e, this.#e, r), !n) {
|
|
127
|
-
if (l(this.#t.ref)) {
|
|
128
|
-
let e = this.#t.ref(this.#e);
|
|
129
|
-
l(e) && (this.#o = e);
|
|
130
|
-
}
|
|
131
|
-
this.#r && H(this.#n);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
unmount(e = !1) {
|
|
135
|
-
!e && this.#e.parentNode && this.#e.parentNode.removeChild(this.#e);
|
|
136
|
-
for (let e of this.#i) e.unmount(!0);
|
|
137
|
-
this.#a.forEach((e) => e()), this.#a.clear(), this.#r && U(this.#n), this.#o &&= (this.#o(), void 0), this.#i.length = 0;
|
|
138
|
-
}
|
|
139
|
-
move(e, t) {
|
|
140
|
-
if (e.moveBefore) try {
|
|
141
|
-
e.moveBefore(this.#e, t?.nextSibling ?? null);
|
|
142
|
-
return;
|
|
143
|
-
} catch {}
|
|
144
|
-
this.mount(e, t);
|
|
145
|
-
}
|
|
146
|
-
#s(e, t) {
|
|
147
|
-
l(e) ? this.#a.add(s(e, (e) => {
|
|
148
|
-
h(() => t(e));
|
|
149
|
-
})) : t(e);
|
|
150
|
-
}
|
|
151
|
-
#c(e, t) {
|
|
152
|
-
for (let n in t) {
|
|
153
|
-
let r = t[n];
|
|
154
|
-
if (n === "style") this.#l(e, r);
|
|
155
|
-
else if (n === "class" || n === "className") this.#u(e, r);
|
|
156
|
-
else if (n === "for") this.#s(r, (t) => {
|
|
157
|
-
e.htmlFor = t;
|
|
158
|
-
});
|
|
159
|
-
else if (n[0] === "." || n.startsWith("prop:")) {
|
|
160
|
-
let t = n.substring(5);
|
|
161
|
-
this.#s(r, (n) => {
|
|
162
|
-
e[t] = n;
|
|
163
|
-
});
|
|
164
|
-
} else if (n[0] === ":" || n.startsWith("attr:")) {
|
|
165
|
-
let t = n.substring(5).toLowerCase();
|
|
166
|
-
this.#s(r, (n) => {
|
|
167
|
-
E(e, t, n);
|
|
168
|
-
});
|
|
169
|
-
} else if (n[0] === "@" && l(r)) {
|
|
170
|
-
let t = n.substring(1);
|
|
171
|
-
this.#a.add(I(e, t, r));
|
|
172
|
-
} else if (n.startsWith("on") && l(r)) {
|
|
173
|
-
let t = n.toLowerCase().slice(2);
|
|
174
|
-
this.#a.add(I(e, t, r));
|
|
175
|
-
} else n in e && !this.#n[y] ? typeof e[n] == "boolean" ? this.#s(r, (t) => {
|
|
176
|
-
let r = !!t;
|
|
177
|
-
e[n] = r, E(e, n, r);
|
|
178
|
-
}) : this.#s(r, (t) => {
|
|
179
|
-
e[n] = t;
|
|
180
|
-
}) : this.#s(r, (t) => {
|
|
181
|
-
E(e, n, t);
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
#l(e, t) {
|
|
186
|
-
let n = /* @__PURE__ */ new Set(), r = (t) => {
|
|
187
|
-
n.forEach((e) => {
|
|
188
|
-
e(), this.#a.delete(e);
|
|
189
|
-
}), n.clear(), e.style.cssText = "";
|
|
190
|
-
let r = C(t);
|
|
191
|
-
for (let [t, { value: i, priority: a }] of Object.entries(r)) if (l(i)) {
|
|
192
|
-
let r = s(i, (n) => {
|
|
193
|
-
n ? e.style.setProperty(t, T(n), a) : e.style.removeProperty(t);
|
|
194
|
-
});
|
|
195
|
-
this.#a.add(r), n.add(r);
|
|
196
|
-
} else i != null && e.style.setProperty(t, T(i), a);
|
|
197
|
-
};
|
|
198
|
-
l(t) ? this.#a.add(s(t, r)) : r(t);
|
|
199
|
-
}
|
|
200
|
-
#u(e, t) {
|
|
201
|
-
let n = /* @__PURE__ */ new Set(), r = (t) => {
|
|
202
|
-
n.forEach((e) => {
|
|
203
|
-
e(), this.#a.delete(e);
|
|
204
|
-
}), n.clear(), E(e, "class", null);
|
|
205
|
-
let r = S(t);
|
|
206
|
-
for (let [t, i] of Object.entries(r)) if (t !== "undefined") if (l(i)) {
|
|
207
|
-
let r = s(i, (n) => e.classList.toggle(t, !!n));
|
|
208
|
-
this.#a.add(r), n.add(r);
|
|
209
|
-
} else i && e.classList.add(t);
|
|
210
|
-
};
|
|
211
|
-
l(t) ? this.#a.add(s(t, r)) : r(t);
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
function S(e) {
|
|
215
|
-
return c(e) ? Object.fromEntries(e.split(" ").map((e) => [e, !0])) : a(e) ? Object.assign({}, ...e.filter(Boolean).map(S)) : r(e) ? e : {};
|
|
216
|
-
}
|
|
217
|
-
function C(e) {
|
|
218
|
-
return c(e) ? Object.fromEntries(e.split(";").filter((e) => e.trim()).map((e) => {
|
|
219
|
-
let [t, n] = e.split(":");
|
|
220
|
-
return [w(t.trim()), {
|
|
221
|
-
value: n.replace("!important", "").trim(),
|
|
222
|
-
priority: n.includes("!important") ? "important" : ""
|
|
223
|
-
}];
|
|
224
|
-
})) : a(e) ? Object.assign({}, ...e.filter(Boolean).map(C)) : r(e) ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e.startsWith("--") ? e : w(e), { value: t }])) : {};
|
|
225
|
-
}
|
|
226
|
-
function w(e) {
|
|
227
|
-
return e.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (e, t) => (t ? "-" : "") + e.toLowerCase());
|
|
228
|
-
}
|
|
229
|
-
function T(e) {
|
|
230
|
-
return n(e) ? `${e}px` : e;
|
|
231
|
-
}
|
|
232
|
-
function E(e, t, n) {
|
|
233
|
-
n ? e.setAttribute(t, String(n)) : e.removeAttribute(t);
|
|
234
|
-
}
|
|
235
|
-
//#endregion
|
|
236
|
-
//#region src/core/markup/utils.ts
|
|
237
|
-
function D(e, t) {
|
|
238
|
-
return {
|
|
239
|
-
[u]: !0,
|
|
240
|
-
type: e,
|
|
241
|
-
props: t
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
function O(e) {
|
|
245
|
-
return e && e[u];
|
|
246
|
-
}
|
|
247
|
-
function k(e) {
|
|
248
|
-
return e && e[d];
|
|
249
|
-
}
|
|
250
|
-
function A(e) {
|
|
251
|
-
return e && e[f];
|
|
252
|
-
}
|
|
253
|
-
function j(e, t = V()) {
|
|
254
|
-
let n = M(t, e);
|
|
255
|
-
return n.length === 1 ? n[0] : new g(t, () => n);
|
|
256
|
-
}
|
|
257
|
-
function M(e, ...t) {
|
|
258
|
-
let r = [];
|
|
259
|
-
function i(t) {
|
|
260
|
-
if (!(t == null || t === !1)) if (a(t)) for (let e = 0; e < t.length; e++) i(t[e]);
|
|
261
|
-
else if (c(t) || n(t)) r.push(new m(e, P(String(t))));
|
|
262
|
-
else if (O(t)) {
|
|
263
|
-
let { type: n, props: i } = t;
|
|
264
|
-
A(n) ? r.push(new n(e, ...i.args)) : l(n) ? r.push(new R(e, n, i)) : c(n) && r.push(new x(e, n, i));
|
|
265
|
-
} else k(t) ? r.push(t) : t instanceof Node ? r.push(new m(e, t)) : l(t) && r.push(new g(e, t));
|
|
266
|
-
}
|
|
267
|
-
for (let e = 0; e < t.length; e++) i(t[e]);
|
|
268
|
-
return r;
|
|
269
|
-
}
|
|
270
|
-
function N(e, t, n) {
|
|
271
|
-
n ? e.insertBefore(t, n?.nextSibling) : e.appendChild(t);
|
|
272
|
-
}
|
|
273
|
-
function P(e) {
|
|
274
|
-
return document.createTextNode(e);
|
|
275
|
-
}
|
|
276
|
-
function F(e, t, n) {
|
|
277
|
-
let r = n?.nextSibling ?? null;
|
|
278
|
-
if (e.moveBefore) try {
|
|
279
|
-
e.moveBefore(t, r);
|
|
280
|
-
return;
|
|
281
|
-
} catch {}
|
|
282
|
-
e.insertBefore(t, r);
|
|
283
|
-
}
|
|
284
|
-
function I(e, t, n) {
|
|
285
|
-
return e.addEventListener(t, n), () => e.removeEventListener(t, n);
|
|
286
|
-
}
|
|
287
|
-
//#endregion
|
|
288
|
-
//#region src/core/markup/nodes/view.ts
|
|
289
|
-
var L = Symbol.for("ViewNode"), R = class extends p {
|
|
290
|
-
#e;
|
|
291
|
-
#t;
|
|
292
|
-
#n;
|
|
293
|
-
context;
|
|
294
|
-
constructor(e, t, n) {
|
|
295
|
-
super(), this.context = V(e), this.context[L] = this, this.context.name = t.name, this.#e = n, this.#t = t;
|
|
296
|
-
}
|
|
297
|
-
getRoot() {
|
|
298
|
-
return this.#n?.getRoot();
|
|
299
|
-
}
|
|
300
|
-
isMounted() {
|
|
301
|
-
return this.context.isMounted;
|
|
302
|
-
}
|
|
303
|
-
mount(t, n) {
|
|
304
|
-
let r = this.isMounted();
|
|
305
|
-
if (!r) {
|
|
306
|
-
let t = e(() => this.#t.call(this.context, this.#e, this.context));
|
|
307
|
-
t != null && t !== !1 ? this.#n = j(t, this.context) : this.#n = new m(this.context, P(""));
|
|
308
|
-
}
|
|
309
|
-
this.#n.mount(t, n), r || H(this.context);
|
|
310
|
-
}
|
|
311
|
-
unmount(e = !1) {
|
|
312
|
-
this.#n?.unmount(e), U(this.context);
|
|
313
|
-
}
|
|
314
|
-
move(e, t) {
|
|
315
|
-
this.#n?.move(e, t);
|
|
316
|
-
}
|
|
317
|
-
}, z = Symbol("Context.mountListeners"), B = Symbol("Context.cleanupListeners");
|
|
318
|
-
function V(e) {
|
|
319
|
-
return Object.assign(Object.create(e ?? null), { isMounted: !1 });
|
|
320
|
-
}
|
|
321
|
-
function H(e) {
|
|
322
|
-
e.isMounted || (e.isMounted = !0, W(e, z));
|
|
323
|
-
}
|
|
324
|
-
function U(e) {
|
|
325
|
-
e.isMounted && (e.isMounted = !1, W(e, B));
|
|
326
|
-
}
|
|
327
|
-
function W(e, t) {
|
|
328
|
-
if (Object.hasOwn(e, t)) {
|
|
329
|
-
for (let n of e[t]) n();
|
|
330
|
-
e[t].length = 0;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
function G(e, t) {
|
|
334
|
-
Object.hasOwn(e, z) ? e[z].push(t) : e[z] = [t];
|
|
335
|
-
}
|
|
336
|
-
function K(e, t) {
|
|
337
|
-
Object.hasOwn(e, B) ? e[B].push(t) : e[B] = [t];
|
|
338
|
-
}
|
|
339
|
-
function q(e, t) {
|
|
340
|
-
e.isMounted ? K(e, i(t)) : G(e, () => {
|
|
341
|
-
K(e, i(t));
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
function J(e) {
|
|
345
|
-
return e[_];
|
|
346
|
-
}
|
|
347
|
-
function Y(e) {
|
|
348
|
-
return e[L];
|
|
349
|
-
}
|
|
350
|
-
var X = Symbol("Dolla.StoreId");
|
|
351
|
-
function Z(e, n, ...r) {
|
|
352
|
-
n[X] ??= Symbol(n.name), t(!Object.hasOwn(e, n[X]), "Store was already provided on this context.");
|
|
353
|
-
let i = V(e);
|
|
354
|
-
return G(e, () => H(i)), K(e, () => U(i)), i.name = n.name, e[n[X]] = n.call(i, r[0], i);
|
|
355
|
-
}
|
|
356
|
-
function Q(e, n) {
|
|
357
|
-
let r = n[X], i = r ? e[r] : void 0;
|
|
358
|
-
return t(i != null, `Store '${n.name}' is not provided by this context.`), i;
|
|
359
|
-
}
|
|
360
|
-
//#endregion
|
|
361
|
-
export { p as S, j as _, Q as a, g as b, q as c, R as d, N as f, F as g, P as h, J as i, G as l, D as m, V as n, H as o, I as p, Y as r, K as s, Z as t, U as u, v, h as x, _ as y };
|
|
362
|
-
|
|
363
|
-
//# sourceMappingURL=context-B5blupD2.js.map
|