aberdeen 1.6.0 → 1.7.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/README.md +5 -11
- package/dist/aberdeen.d.ts +173 -129
- package/dist/aberdeen.js +181 -95
- package/dist/aberdeen.js.map +3 -3
- package/dist/dispatcher.d.ts +10 -7
- package/dist/dispatcher.js +11 -10
- package/dist/dispatcher.js.map +3 -3
- package/dist/route.d.ts +17 -0
- package/dist/route.js +62 -20
- package/dist/route.js.map +3 -3
- package/dist-min/aberdeen.js +9 -7
- package/dist-min/aberdeen.js.map +3 -3
- package/dist-min/dispatcher.js +2 -2
- package/dist-min/dispatcher.js.map +3 -3
- package/dist-min/route.js +2 -2
- package/dist-min/route.js.map +3 -3
- package/html-to-aberdeen +3 -6
- package/package.json +1 -1
- package/skill/SKILL.md +286 -76
- package/skill/aberdeen.md +219 -203
- package/skill/dispatcher.md +16 -13
- package/skill/prediction.md +3 -3
- package/skill/route.md +44 -16
- package/skill/transitions.md +3 -3
- package/src/aberdeen.ts +397 -237
- package/src/dispatcher.ts +16 -13
- package/src/route.ts +90 -19
package/dist-min/dispatcher.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var N=Symbol("MATCH_FAILED"),K=Symbol("MATCH_REST");class O{routes=[];addRoute(...q){let j=q.slice(0,-1),k=q[q.length-1];if(typeof k!=="function")throw Error("Last argument should be a handler function");if(j.filter((G)=>G===K).length>1)throw Error("Only one MATCH_REST is allowed");this.routes.push({matchers:j,handler:k})}dispatch(q){for(let j of this.routes){let k=P(j,q);if(k)return j.handler(...k),!0}return!1}}function P(q,j){let k=[],z=0;for(let G of q.matchers){if(G===K){let B=j.length-(q.matchers.length-1);if(B<0)return;k.push(j.slice(z,z+B)),z+=B;continue}if(z>=j.length)return;let J=j[z];if(typeof G==="string"){if(J!==G)return}else if(typeof G==="function"){let B=G(J);if(B===N||typeof B==="number"&&isNaN(B))return;k.push(B)}z++}if(z===j.length)return k}export{K as MATCH_REST,N as MATCH_FAILED,O as Dispatcher};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=A71DE93F7C3425E164756E2164756E21
|
|
4
4
|
//# sourceMappingURL=dispatcher.js.map
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/dispatcher.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * Symbol to return when a custom {@link Dispatcher.addRoute} matcher cannot match a segment.\n */\nexport const
|
|
5
|
+
"/**\n * Symbol to return when a custom {@link Dispatcher.addRoute} matcher cannot match a segment.\n */\nexport const MATCH_FAILED: unique symbol = Symbol(\"MATCH_FAILED\");\n\n/**\n * Special {@link Dispatcher.addRoute} matcher that matches the rest of the segments as an array of strings.\n */\nexport const MATCH_REST: unique symbol = Symbol(\"MATCH_REST\");\n\ntype Matcher = string | ((segment: string) => any) | typeof MATCH_REST;\n\ntype ExtractParamType<M> = M extends string\n? never : (\n M extends ((segment: string) => infer R)\n ? Exclude<R, typeof MATCH_FAILED>\n : (M extends typeof MATCH_REST ? string[] : never)\n);\n\ntype ParamsFromMatchers<T extends Matcher[]> = T extends [infer M1, ...infer Rest]\n? (\n M1 extends Matcher\n ? (\n ExtractParamType<M1> extends never\n ? ParamsFromMatchers<Rest extends Matcher[] ? Rest : []>\n : [ExtractParamType<M1>, ...ParamsFromMatchers<Rest extends Matcher[] ? Rest : []>]\n ) : never\n) : [];\n\ninterface DispatcherRoute {\n matchers: Matcher[];\n handler: (...params: any[]) => void;\n}\n\n/**\n * Simple route matcher and dispatcher.\n * \n * Example usage:\n * \n * ```ts\n * import * as route from 'aberdeen/route';\n * import { Dispatcher, MATCH_REST } from 'aberdeen/dispatcher';\n * \n * const dispatcher = new Dispatcher();\n * \n * dispatcher.addRoute(\"user\", Number, \"stream\", String, (id, stream) => {\n * console.log(`User ${id}, stream ${stream}`);\n * });\n *\n * dispatcher.dispatch([\"user\", \"42\", \"stream\", \"music\"]);\n * // Logs: User 42, stream music\n * \n * dispatcher.addRoute(\"search\", MATCH_REST, (terms: string[]) => {\n * console.log(\"Search terms:\", terms);\n * });\n * \n * dispatcher.dispatch([\"search\", \"classical\", \"piano\"]);\n * // Logs: Search terms: [ 'classical', 'piano' ]\n * ```\n */\nexport class Dispatcher {\n private routes: Array<DispatcherRoute> = [];\n \n /**\n * Add a route with matchers and a handler function.\n * @param args An array of matchers followed by a handler function. Each matcher can be:\n * - A string: matches exactly that string.\n * - A function: takes a string segment and returns a value (of any type) if it matches, or {@link MATCH_FAILED} if it doesn't match. The return value (if not `MATCH_FAILED` and not `NaN`) is passed as a parameter to the handler function. The standard JavaScript functions `Number` and `String` can be used to match numeric and string segments respectively.\n * - The special {@link MATCH_REST} symbol: matches the rest of the segments as an array of strings. Only one `MATCH_REST` is allowed.\n * @template T - Array of matcher types.\n * @template H - Handler function type, inferred from the matchers.\n */\n addRoute<T extends Matcher[], H extends (...args: ParamsFromMatchers<T>) => void>(...args: [...T, H]): void {\n const matchers = args.slice(0, -1) as Matcher[];\n const handler = args[args.length - 1] as (...args: any) => any;\n\n if (typeof handler !== \"function\") {\n throw new Error(\"Last argument should be a handler function\");\n }\n \n const restCount = matchers.filter(m => m === MATCH_REST).length;\n if (restCount > 1) {\n throw new Error(\"Only one MATCH_REST is allowed\");\n }\n\n this.routes.push({ matchers, handler });\n }\n \n /**\n * Dispatches the given segments to the first route handler that matches.\n * @param segments Array of string segments to match against the added routes. When using this class with the Aberdeen `route` module, one would typically pass `route.current.p`.\n * @returns True if a matching route was found and handled, false otherwise.\n */\n dispatch(segments: string[]): boolean {\n for (const route of this.routes) {\n const args = matchRoute(route, segments);\n if (args) {\n route.handler(...args);\n return true;\n }\n }\n return false;\n }\n}\n\nfunction matchRoute(route: DispatcherRoute, segments: string[]): any[] | undefined {\n const args: any[] = [];\n let segmentIndex = 0;\n\n for (const matcher of route.matchers) {\n if (matcher === MATCH_REST) {\n const len = segments.length - (route.matchers.length - 1);\n if (len < 0) return;\n args.push(segments.slice(segmentIndex, segmentIndex + len));\n segmentIndex += len;\n continue;\n }\n\n if (segmentIndex >= segments.length) return;\n const segment = segments[segmentIndex];\n \n if (typeof matcher === \"string\") {\n if (segment !== matcher) return;\n } else if (typeof matcher === \"function\") {\n const result = matcher(segment);\n if (result === MATCH_FAILED || (typeof result === 'number' && isNaN(result))) return;\n args.push(result);\n }\n \n segmentIndex++;\n }\n if (segmentIndex === segments.length) return args; // success!\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "AAGO,IAAM,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "AAGO,IAAM,EAA8B,OAAO,cAAc,EAKnD,EAA4B,OAAO,YAAY,EAoDrD,MAAM,CAAW,CACZ,OAAiC,CAAC,EAW1C,QAAiF,IAAI,EAAuB,CACxG,IAAM,EAAW,EAAK,MAAM,EAAG,EAAE,EAC3B,EAAU,EAAK,EAAK,OAAS,GAEnC,GAAI,OAAO,IAAY,WACnB,MAAU,MAAM,4CAA4C,EAIhE,GADkB,EAAS,OAAO,KAAK,IAAM,CAAU,EAAE,OACzC,EACZ,MAAU,MAAM,gCAAgC,EAGpD,KAAK,OAAO,KAAK,CAAE,WAAU,SAAQ,CAAC,EAQ1C,QAAQ,CAAC,EAA6B,CAClC,QAAW,KAAS,KAAK,OAAQ,CAC7B,IAAM,EAAO,EAAW,EAAO,CAAQ,EACvC,GAAI,EAEA,OADA,EAAM,QAAQ,GAAG,CAAI,EACd,GAGf,MAAO,GAEf,CAEA,SAAS,CAAU,CAAC,EAAwB,EAAuC,CAC/E,IAAM,EAAc,CAAC,EACjB,EAAe,EAEnB,QAAW,KAAW,EAAM,SAAU,CAClC,GAAI,IAAY,EAAY,CACxB,IAAM,EAAM,EAAS,QAAU,EAAM,SAAS,OAAS,GACvD,GAAI,EAAM,EAAG,OACb,EAAK,KAAK,EAAS,MAAM,EAAc,EAAe,CAAG,CAAC,EAC1D,GAAgB,EAChB,SAGJ,GAAI,GAAgB,EAAS,OAAQ,OACrC,IAAM,EAAU,EAAS,GAEzB,GAAI,OAAO,IAAY,UACnB,GAAI,IAAY,EAAS,OACtB,QAAI,OAAO,IAAY,WAAY,CACtC,IAAM,EAAS,EAAQ,CAAO,EAC9B,GAAI,IAAW,GAAiB,OAAO,IAAW,UAAY,MAAM,CAAM,EAAI,OAC9E,EAAK,KAAK,CAAM,EAGpB,IAEJ,GAAI,IAAiB,EAAS,OAAQ,OAAO",
|
|
8
|
+
"debugId": "A71DE93F7C3425E164756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist-min/route.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{clean as
|
|
1
|
+
import{clean as $,$ as j,proxy as q,runQueue as Q,unproxy as X,copy as Y,merge as f,clone as K,leakScope as C}from"./aberdeen.js";var N=()=>{};function d(z){if(z===!0)N=console.log.bind(console,"aberdeen router");else if(z===!1)N=()=>{};else N=z}var B=typeof ABERDEEN_FAKE_WINDOW<"u"?ABERDEEN_FAKE_WINDOW:window,V=B.location,M=B.history;function U(){return _({path:V.pathname,hash:V.hash,search:Object.fromEntries(new URLSearchParams(V.search)),state:M.state?.state||{}},"load",(M.state?.stack?.length||0)+1)}function Z(z,A,G){if(z===A)return!0;if(typeof z!=="object"||!z||typeof A!=="object"||!A)return!1;if(z.constructor!==A.constructor)return!1;if(A instanceof Array){if(z.length!==A.length)return!1;for(let D=0;D<A.length;D++)if(!Z(z[D],A[D],G))return!1}else{for(let D of Object.keys(A))if(!Z(z[D],A[D],G))return!1;if(!G){for(let D of Object.keys(z))if(!A.hasOwnProperty(D))return!1}}return!0}function I(z){let A=new URLSearchParams(z.search).toString();return(A?`${z.path}?${A}`:z.path)+z.hash}function _(z,A,G){let D=z.path||(z.p||[]).join("/")||"/";if(D=(""+D).replace(/\/+$/,""),!D.startsWith("/"))D=`/${D}`;return{path:D,hash:z.hash&&z.hash!=="#"?z.hash.startsWith("#")?z.hash:"#"+z.hash:"",p:D.length>1?D.slice(1).replace(/\/+$/,"").split("/"):[],nav:A,search:typeof z.search==="object"&&z.search?K(z.search):{},state:typeof z.state==="object"&&z.state?K(z.state):{},depth:G}}function F(z){if(typeof z==="string")z={path:z};else if(z instanceof Array)z={p:z};if(z.p)z.p=z.p.map(String);if(z.search)for(let A of Object.keys(z.search))z.search[A]=String(z.search[A]);return z}function T(z,A="go"){O=(M.state?.stack||[]).concat(JSON.stringify(X(H)));let D=_(F(z),A,O.length+1);Y(H,D),N(A,D),M.pushState({state:D.state,stack:O},"",I(D)),Q()}function m(z){let A=K(X(H));f(A,F(z)),T(A)}function x(z={}){let A=F(z),G=M.state?.stack||[];for(let J=G.length-1;J>=0;J--){let L=JSON.parse(G[J]);if(Z(L,A,!0)){let W=J-G.length;N("back",W,L),M.go(W);return}}let D=_(A,"back",G.length+1);N("back not found, replacing",A),Y(H,D)}function w(z=1){let A=X(H).p,G=M.state?.stack||[];for(let J=G.length-1;J>=0;J--){let L=JSON.parse(G[J]);if(L.p.length<A.length&&Z(L.p,A.slice(0,L.p.length),!1)){N(`up to ${J+1} / ${G.length}`,L),M.go(J-G.length);return}}let D=_({p:A.slice(0,A.length-z)},"back",G.length+1);N("up not found, replacing",D),Y(H,D)}function b(z="main"){let A=j();A.addEventListener("scroll",D),$(()=>A.removeEventListener("scroll",D));let G=X(H).state.scroll?.[z];if(G)N("restoring scroll",z,G),Object.assign(A,G);function D(){(H.state.scroll||={})[z]={scrollTop:A.scrollTop,scrollLeft:A.scrollLeft}}}function v(){j({click:A,keydown:z});function z(G){if(G.key==="Enter")A(G)}function A(G){let D=G.target;while(D&&D.tagName?.toUpperCase()!=="A")D=D.parentElement;if(!D)return;let J=D,L=J.getAttribute("href");if(!L)return;if(L.startsWith("#"))return;if(L.startsWith("//")||/^[^/?#]+:/.test(L))return;if(J.getAttribute("target")||J.getAttribute("download"))return;if(typeof MouseEvent<"u"&&G instanceof MouseEvent&&(G.ctrlKey||G.metaKey||G.shiftKey))return;G.preventDefault();let W=new URL(L,V.href);T({path:W.pathname,search:Object.fromEntries(W.searchParams),hash:W.hash})}}var O,H=q({});function P(){O=M.state?.stack||[];let z=U();N("initial",z),Y(X(H),z)}P();B.addEventListener("popstate",function(z){let A=U(),G=M.state?.stack||[];if(G.length!==O.length){let D=Math.min(O.length,G.length)-1;if(D<0||G[D]===O[D])A.nav=G.length<O.length?"back":"forward"}O=G,N("popstate",A),Y(H,A),Q()});C(()=>{j(()=>{H.path="/"+Array.from(H.p).join("/")}),j(()=>{let z=M.state?.stack||[],A=_(H,X(H).nav,z.length+1);Y(H,A);let G={state:A.state,stack:z},D=I(A);if(D!==V.pathname+V.search+V.hash||!Z(M.state,G,!1))N("replaceState",A,G,D),M.replaceState(G,"",D)})});export{w as up,d as setLog,P as reset,m as push,b as persistScroll,v as interceptLinks,T as go,H as current,x as back};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=5664D4E7BFEE227364756E2164756E21
|
|
4
4
|
//# sourceMappingURL=route.js.map
|
package/dist-min/route.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/route.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import {clean, getParentElement, $, proxy, runQueue, unproxy, copy, merge, clone, leakScope} from \"./aberdeen.js\";\n\ntype NavType = \"load\" | \"back\" | \"forward\" | \"go\" | \"push\";\n\n/**\n* The class for the global `route` object.\n*/\nexport interface Route {\n\t/** The current path of the URL as a string. For instance `\"/\"` or `\"/users/123/feed\"`. Paths are normalized to always start with a `/` and never end with a `/` (unless it's the root path). */\n\tpath: string;\n\t/** An convenience array containing path segments, mapping to `path`. For instance `[]` (for `\"/\"`) or `['users', '123', 'feed']` (for `\"/users/123/feed\"`). */\n\tp: string[];\n\t/** The hash fragment including the leading `#`, or an empty string. For instance `\"#my_section\"` or `\"\"`. */\n\thash: string;\n\t/** The query string interpreted as search parameters. So `\"a=x&b=y\"` becomes `{a: \"x\", b: \"y\"}`. */\n\tsearch: Record<string, string>;\n\t/** An object to be used for any additional data you want to associate with the current page. Data should be JSON-compatible. */\n\tstate: Record<string, any>;\n\t/** The navigation depth of the current session. Starts at 1. Writing to this property has no effect. */\n\tdepth: number;\n\t/** The navigation action that got us to this page. Writing to this property has no effect.\n\t- `\"load\"`: An initial page load.\n\t- `\"back\"` or `\"forward\"`: When we navigated backwards or forwards in the stack.\n\t- `\"go\"`: When we added a new page on top of the stack.\n\t- `\"push\"`: When we added a new page on top of the stack, merging with the current page.\n\tMostly useful for page transition animations. Writing to this property has no effect.\n\t*/\n\tnav: NavType;\n}\n\nlet log: (...args: any) => void = () => {};\n\n/**\n * Configure logging on route changes.\n * @param value `true` to enable logging to console, `false` to disable logging, or a custom logging function. Defaults to `false`.\n */\nexport function setLog(value: boolean | ((...args: any[]) => void)) {\n\tif (value === true) {\n\t\tlog = console.log.bind(console, 'aberdeen router');\n\t} else if (value === false) {\n\t\tlog = () => {};\n\t} else {\n\t\tlog = value;\n\t}\n}\n\nfunction getRouteFromBrowser(): Route {\n\treturn toCanonRoute({\n\t\tpath: location.pathname,\n\t\thash: location.hash,\n\t\tsearch: Object.fromEntries(new URLSearchParams(location.search)),\n\t\tstate: history.state?.state || {},\n\t}, \"load\", (history.state?.stack?.length || 0) + 1);\n}\n\n/**\n* Deep compare `a` and `b`. If `partial` is true, objects contained in `b` may be a subset\n* of their counterparts in `a` and still be considered equal.\n*/\nfunction equal(a: any, b: any, partial: boolean): boolean {\n\tif (a===b) return true;\n\tif (typeof a !== \"object\" || !a || typeof b !== \"object\" || !b) return false; // otherwise they would have been equal\n\tif (a.constructor !== b.constructor) return false;\n\tif (b instanceof Array) {\n\t\tif (a.length !== b.length) return false;\n\t\tfor(let i = 0; i < b.length; i++) {\n\t\t\tif (!equal(a[i], b[i], partial)) return false;\n\t\t}\n\t} else {\n\t\tfor(const k of Object.keys(b)) {\n\t\t\tif (!equal(a[k], b[k], partial)) return false;\n\t\t}\n\t\tif (!partial) {\n\t\t\tfor(const k of Object.keys(a)) {\n\t\t\t\tif (!b.hasOwnProperty(k)) return false;\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction getUrl(target: Route) {\n\tconst search = new URLSearchParams(target.search).toString();\n\treturn (search ? `${target.path}?${search}` : target.path) + target.hash;\n}\n\nfunction toCanonRoute(target: Partial<Route>, nav: NavType, depth: number): Route {\n\tlet path = target.path || (target.p || []).join(\"/\") || \"/\";\n\tpath = (\"\"+path).replace(/\\/+$/, \"\");\n\tif (!path.startsWith(\"/\")) path = `/${path}`;\n\t\n\treturn {\n\t\tpath,\n\t\thash: target.hash && target.hash !==\"#\" ? (target.hash.startsWith(\"#\") ? target.hash : \"#\" + target.hash) : \"\",\n\t\tp: path.length > 1 ? path.slice(1).replace(/\\/+$/, \"\").split(\"/\") : [],\n\t\tnav,\n\t\tsearch: typeof target.search === 'object' && target.search ? clone(target.search) : {},\n\t\tstate: typeof target.state === 'object' && target.state ? clone(target.state) : {},\n\t\tdepth,\n\t};\n}\n\n\ntype RouteTarget = string | (string|number)[] | Partial<Omit<Omit<Route,\"p\">,\"search\"> & {\n\t/** An convenience array containing path segments, mapping to `path`. For instance `[]` (for `\"/\"`) or `['users', 123, 'feed']` (for `\"/users/123/feed\"`). Values may be integers but will be converted to strings.*/\n\tp: (string|number)[],\n\t/** The query string interpreted as search parameters. So `\"a=x&b=y\"` becomes `{a: \"x\", b: \"y\", c: 42}`. Values may be integers but will be converted to strings. */\n\tsearch: Record<string,string|number>,\n}>;\n\nfunction targetToPartial(target: RouteTarget) {\n\t// Convert shortcut values to objects\n\tif (typeof target === 'string') {\n\t\ttarget = {path: target};\n\t} else if (target instanceof Array) {\n\t\ttarget = {p: target};\n\t}\n\t// Convert numbers in p and search to strings\n\tif (target.p) {\n\t\ttarget.p = target.p.map(String);\n\t}\n\tif (target.search) {\n\t\tfor(const key of Object.keys(target.search)) {\n\t\t\ttarget.search[key] = String(target.search[key]);\n\t\t}\n\t}\n\treturn target as Partial<Route>;\n}\n\n\n/**\n* Navigate to a new URL by pushing a new history entry.\n* \n* Note that this happens synchronously, immediately updating `route` and processing any reactive updates based on that.\n* \n* @param target A subset of the {@link Route} properties to navigate to. If neither `p` nor `path` is given, the current path is used. For other properties, an empty/default value is assumed if not given. For convenience:\n* - You may pass a string instead of an object, which is interpreted as the `path`.\n* - You may pass an array instead of an object, which is interpreted as the `p` array.\n* - If you pass `p`, it may contain numbers, which will be converted to strings.\n* - If you pass `search`, its values may be numbers, which will be converted to strings.\n* \n* Examples:\n* ```js\n* // Navigate to /users/123\n* route.go(\"/users/123\");\n* \n* // Navigate to /users/123?tab=feed#top\n* route.go({p: [\"users\", 123], search: {tab: \"feed\"}, hash: \"top\"});\n* ```\n*/\nexport function go(target: RouteTarget, nav: NavType = \"go\"): void {\n\tconst stack: string[] = history.state?.stack || [];\n\n\tprevStack = stack.concat(JSON.stringify(unproxy(current)));\n\t\n\tconst newRoute: Route = toCanonRoute(targetToPartial(target), nav, prevStack.length + 1);\n\tcopy(current, newRoute);\n\t\n\tlog(nav, newRoute);\n\thistory.pushState({state: newRoute.state, stack: prevStack}, \"\", getUrl(newRoute));\n\t\n\trunQueue();\n}\n\n/**\n * Modify the current route by merging `target` into it (using {@link merge}), pushing a new history entry.\n * \n * This is useful for things like opening modals or side panels, where you want a browser back action to return to the previous state.\n * \n * @param target Same as for {@link go}, but merged into the current route instead deleting all state.\n */\nexport function push(target: RouteTarget): void {\n\tconst c = clone(unproxy(current));\n\tmerge(c, targetToPartial(target));\n\tgo(c);\n}\n\n/**\n * Try to go back in history to the first entry that matches the given target. If none is found, the given state will replace the current page. This is useful for \"cancel\" or \"close\" actions that should return to the previous page if possible, but create a new page if not (for instance when arriving at the current page through a direct link).\n * \n * Consider using {@link up} to go up in the path hierarchy.\n * \n * @param target The target route to go back to. May be a subset of {@link Route}, or a string (for `path`), or an array of strings (for `p`).\n */\nexport function back(target: RouteTarget = {}): void {\n\tconst partial = targetToPartial(target);\n\tconst stack: string[] = history.state?.stack || [];\n\tfor(let i = stack.length - 1; i >= 0; i--) {\n\t\tconst histRoute: Route = JSON.parse(stack[i]);\n\t\tif (equal(histRoute, partial, true)) {\n\t\t\tconst pages = i - stack.length;\n\t\t\tlog(`back`, pages, histRoute);\n\t\t\thistory.go(pages);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst newRoute = toCanonRoute(partial, \"back\", stack.length + 1);\n\tlog(`back not found, replacing`, partial);\n\tcopy(current, newRoute);\n}\n\n/**\n* Navigate up in the path hierarchy, by going back to the first history entry\n* that has a shorter path than the current one. If there's none, we just shorten\n* the current path.\n* \n* Note that going back in browser history happens asynchronously, so `route` will not be updated immediately.\n*/\nexport function up(stripCount: number = 1): void {\n\tconst currentP = unproxy(current).p;\n\tconst stack: string[] = history.state?.stack || [];\n\tfor(let i = stack.length - 1; i >= 0; i--) {\n\t\tconst histRoute: Route = JSON.parse(stack[i]);\n\t\tif (histRoute.p.length < currentP.length && equal(histRoute.p, currentP.slice(0, histRoute.p.length), false)) {\n\t\t\t// This route is shorter and matches the start of the current path\n\t\t\tlog(`up to ${i+1} / ${stack.length}`, histRoute);\n\t\t\thistory.go(i - stack.length);\n\t\t\treturn;\n\t\t}\n\t}\n\t// Replace current route with /\n\tconst newRoute = toCanonRoute({p: currentP.slice(0, currentP.length - stripCount)}, \"back\", stack.length + 1);\n\tlog(`up not found, replacing`, newRoute);\n\tcopy(current, newRoute);\n}\n\n/**\n* Restore and store the vertical and horizontal scroll position for\n* the parent element to the page state.\n*\n* @param {string} name - A unique (within this page) name for this\n* scrollable element. Defaults to 'main'.\n*\n* The scroll position will be persisted in `route.aux.scroll.<name>`.\n*/\nexport function persistScroll(name = \"main\") {\n\tconst el = getParentElement();\n\tel.addEventListener(\"scroll\", onScroll);\n\tclean(() => el.removeEventListener(\"scroll\", onScroll));\n\t\n\tconst restore = unproxy(current).state.scroll?.[name];\n\tif (restore) {\n\t\tlog(\"restoring scroll\", name, restore);\n\t\tObject.assign(el, restore);\n\t}\n\t\n\tfunction onScroll() {\n\t\t(current.state.scroll ||= {})[name] = {\n\t\t\tscrollTop: el.scrollTop,\n\t\t\tscrollLeft: el.scrollLeft,\n\t\t};\n\t}\n}\n\nlet prevStack: string[];\n\n/**\n* The global {@link Route} object reflecting the current URL and browser history state. Changes you make to this affect the current browser history item (modifying the URL if needed).\n*/\nexport const current: Route = proxy({}) as Route;\n\n/**\n * Reset the router to its initial state, based on the current browser state. Intended for testing purposes only.\n * @internal\n * */\nexport function reset() {\n\tprevStack = history.state?.stack || [];\n\tconst initRoute = getRouteFromBrowser();\n\tlog('initial', initRoute);\n\tcopy(unproxy(current), initRoute);\n}\nreset();\n\n// Handle browser history back and forward\nwindow.addEventListener(\"popstate\", function(event: PopStateEvent) {\n\tconst newRoute = getRouteFromBrowser();\n\t\n\t// If the stack length changes, and at least the top-most shared entry is the same,\n\t// we'll interpret this as a \"back\" or \"forward\" navigation.\n\tconst stack: string[] = history.state?.stack || [];\n\tif (stack.length !== prevStack.length) {\n\t\tconst maxIndex = Math.min(prevStack.length, stack.length) - 1;\n\t\tif (maxIndex < 0 || stack[maxIndex] === prevStack[maxIndex]) {\n\t\t\tnewRoute.nav = stack.length < prevStack.length ? \"back\" : \"forward\";\n\t\t}\n\t}\n\t// else nav will be \"load\"\n\t\n\tprevStack = stack;\n\tlog('popstate', newRoute);\n\tcopy(current, newRoute);\n\t\n\trunQueue();\n});\n\n// Make sure these observers are never cleaned up, not even by `unmountAll`.\nleakScope(() => {\n\t// Sync `p` to `path`. We need to do this in a separate, higher-priority observer,\n\t// so that setting `route.p` will not be immediately overruled by the pre-existing `route.path`.\n\t$(() => {\n\t\tcurrent.path = \"/\" + Array.from(current.p).join(\"/\");\n\t});\n\n\t// Do a replaceState based on changes to proxy\n\t$(() => {\n\n\t\t// First normalize `route`\n\t\tconst stack = history.state?.stack || [];\n\t\tconst newRoute = toCanonRoute(current, unproxy(current).nav, stack.length + 1);\n\t\tcopy(current, newRoute);\n\t\t\n\t\t// Then replace the current browser state if something actually changed\n\t\tconst state = {state: newRoute.state, stack};\n\t\tconst url = getUrl(newRoute);\n\t\tif (url !== location.pathname + location.search + location.hash || !equal(history.state, state, false)) {\n\t\t\tlog('replaceState', newRoute, state, url);\n\t\t\thistory.replaceState(state, \"\", url);\n\t\t}\n\t});\n});\n"
|
|
5
|
+
"import {clean, $, proxy, runQueue, unproxy, copy, merge, clone, leakScope} from \"./aberdeen.js\";\n\ntype NavType = \"load\" | \"back\" | \"forward\" | \"go\" | \"push\";\n\n/**\n* The class for the global `route` object.\n*/\nexport interface Route {\n\t/** The current path of the URL as a string. For instance `\"/\"` or `\"/users/123/feed\"`. Paths are normalized to always start with a `/` and never end with a `/` (unless it's the root path). */\n\tpath: string;\n\t/** An convenience array containing path segments, mapping to `path`. For instance `[]` (for `\"/\"`) or `['users', '123', 'feed']` (for `\"/users/123/feed\"`). */\n\tp: string[];\n\t/** The hash fragment including the leading `#`, or an empty string. For instance `\"#my_section\"` or `\"\"`. */\n\thash: string;\n\t/** The query string interpreted as search parameters. So `\"a=x&b=y\"` becomes `{a: \"x\", b: \"y\"}`. */\n\tsearch: Record<string, string>;\n\t/** An object to be used for any additional data you want to associate with the current page. Data should be JSON-compatible. */\n\tstate: Record<string, any>;\n\t/** The navigation depth of the current session. Starts at 1. Writing to this property has no effect. */\n\tdepth: number;\n\t/** The navigation action that got us to this page. Writing to this property has no effect.\n\t- `\"load\"`: An initial page load.\n\t- `\"back\"` or `\"forward\"`: When we navigated backwards or forwards in the stack.\n\t- `\"go\"`: When we added a new page on top of the stack.\n\t- `\"push\"`: When we added a new page on top of the stack, merging with the current page.\n\tMostly useful for page transition animations. Writing to this property has no effect.\n\t*/\n\tnav: NavType;\n}\n\nlet log: (...args: any) => void = () => {};\n\n/**\n * Configure logging on route changes.\n * @param value `true` to enable logging to console, `false` to disable logging, or a custom logging function. Defaults to `false`.\n */\nexport function setLog(value: boolean | ((...args: any[]) => void)) {\n\tif (value === true) {\n\t\tlog = console.log.bind(console, 'aberdeen router');\n\t} else if (value === false) {\n\t\tlog = () => {};\n\t} else {\n\t\tlog = value;\n\t}\n}\n\ndeclare const ABERDEEN_FAKE_WINDOW: Window | undefined;\nconst windowE = typeof ABERDEEN_FAKE_WINDOW !== 'undefined'? ABERDEEN_FAKE_WINDOW : window;\nconst locationE = windowE.location;\nconst historyE = windowE.history;\n\nfunction getRouteFromBrowser(): Route {\n\treturn toCanonRoute({\n\t\tpath: locationE.pathname,\n\t\thash: locationE.hash,\n\t\tsearch: Object.fromEntries(new URLSearchParams(locationE.search)),\n\t\tstate: \thistoryE.state?.state || {},\n\t}, \"load\", (historyE.state?.stack?.length || 0) + 1);\n}\n\n/**\n* Deep compare `a` and `b`. If `partial` is true, objects contained in `b` may be a subset\n* of their counterparts in `a` and still be considered equal.\n*/\nfunction equal(a: any, b: any, partial: boolean): boolean {\n\tif (a===b) return true;\n\tif (typeof a !== \"object\" || !a || typeof b !== \"object\" || !b) return false; // otherwise they would have been equal\n\tif (a.constructor !== b.constructor) return false;\n\tif (b instanceof Array) {\n\t\tif (a.length !== b.length) return false;\n\t\tfor(let i = 0; i < b.length; i++) {\n\t\t\tif (!equal(a[i], b[i], partial)) return false;\n\t\t}\n\t} else {\n\t\tfor(const k of Object.keys(b)) {\n\t\t\tif (!equal(a[k], b[k], partial)) return false;\n\t\t}\n\t\tif (!partial) {\n\t\t\tfor(const k of Object.keys(a)) {\n\t\t\t\tif (!b.hasOwnProperty(k)) return false;\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction getUrl(target: Route) {\n\tconst search = new URLSearchParams(target.search).toString();\n\treturn (search ? `${target.path}?${search}` : target.path) + target.hash;\n}\n\nfunction toCanonRoute(target: Partial<Route>, nav: NavType, depth: number): Route {\n\tlet path = target.path || (target.p || []).join(\"/\") || \"/\";\n\tpath = (\"\"+path).replace(/\\/+$/, \"\");\n\tif (!path.startsWith(\"/\")) path = `/${path}`;\n\t\n\treturn {\n\t\tpath,\n\t\thash: target.hash && target.hash !==\"#\" ? (target.hash.startsWith(\"#\") ? target.hash : \"#\" + target.hash) : \"\",\n\t\tp: path.length > 1 ? path.slice(1).replace(/\\/+$/, \"\").split(\"/\") : [],\n\t\tnav,\n\t\tsearch: typeof target.search === 'object' && target.search ? clone(target.search) : {},\n\t\tstate: typeof target.state === 'object' && target.state ? clone(target.state) : {},\n\t\tdepth,\n\t};\n}\n\n\ntype RouteTarget = string | (string|number)[] | Partial<Omit<Omit<Route,\"p\">,\"search\"> & {\n\t/** An convenience array containing path segments, mapping to `path`. For instance `[]` (for `\"/\"`) or `['users', 123, 'feed']` (for `\"/users/123/feed\"`). Values may be integers but will be converted to strings.*/\n\tp: (string|number)[],\n\t/** The query string interpreted as search parameters. So `\"a=x&b=y\"` becomes `{a: \"x\", b: \"y\", c: 42}`. Values may be integers but will be converted to strings. */\n\tsearch: Record<string,string|number>,\n}>;\n\nfunction targetToPartial(target: RouteTarget) {\n\t// Convert shortcut values to objects\n\tif (typeof target === 'string') {\n\t\ttarget = {path: target};\n\t} else if (target instanceof Array) {\n\t\ttarget = {p: target};\n\t}\n\t// Convert numbers in p and search to strings\n\tif (target.p) {\n\t\ttarget.p = target.p.map(String);\n\t}\n\tif (target.search) {\n\t\tfor(const key of Object.keys(target.search)) {\n\t\t\ttarget.search[key] = String(target.search[key]);\n\t\t}\n\t}\n\treturn target as Partial<Route>;\n}\n\n\n/**\n* Navigate to a new URL by pushing a new history entry.\n* \n* Note that this happens synchronously, immediately updating `route` and processing any reactive updates based on that.\n* \n* @param target A subset of the {@link Route} properties to navigate to. If neither `p` nor `path` is given, the current path is used. For other properties, an empty/default value is assumed if not given. For convenience:\n* - You may pass a string instead of an object, which is interpreted as the `path`.\n* - You may pass an array instead of an object, which is interpreted as the `p` array.\n* - If you pass `p`, it may contain numbers, which will be converted to strings.\n* - If you pass `search`, its values may be numbers, which will be converted to strings.\n* \n* Examples:\n* ```js\n* // Navigate to /users/123\n* route.go(\"/users/123\");\n* \n* // Navigate to /users/123?tab=feed#top\n* route.go({p: [\"users\", 123], search: {tab: \"feed\"}, hash: \"top\"});\n* ```\n*/\nexport function go(target: RouteTarget, nav: NavType = \"go\"): void {\n\tconst stack: string[] = historyE.state?.stack || [];\n\n\tprevStack = stack.concat(JSON.stringify(unproxy(current)));\n\t\n\tconst newRoute: Route = toCanonRoute(targetToPartial(target), nav, prevStack.length + 1);\n\tcopy(current, newRoute);\n\t\n\tlog(nav, newRoute);\n\thistoryE.pushState({state: newRoute.state, stack: prevStack}, \"\", getUrl(newRoute));\n\t\n\trunQueue();\n}\n\n/**\n * Modify the current route by merging `target` into it (using {@link merge}), pushing a new history entry.\n * \n * This is useful for things like opening modals or side panels, where you want a browser back action to return to the previous state.\n * \n * @param target Same as for {@link go}, but merged into the current route instead deleting all state.\n */\nexport function push(target: RouteTarget): void {\n\tconst c = clone(unproxy(current));\n\tmerge(c, targetToPartial(target));\n\tgo(c);\n}\n\n/**\n * Try to go back in history to the first entry that matches the given target. If none is found, the given state will replace the current page. This is useful for \"cancel\" or \"close\" actions that should return to the previous page if possible, but create a new page if not (for instance when arriving at the current page through a direct link).\n * \n * Consider using {@link up} to go up in the path hierarchy.\n * \n * @param target The target route to go back to. May be a subset of {@link Route}, or a string (for `path`), or an array of strings (for `p`).\n */\nexport function back(target: RouteTarget = {}): void {\n\tconst partial = targetToPartial(target);\n\tconst stack: string[] = historyE.state?.stack || [];\n\tfor(let i = stack.length - 1; i >= 0; i--) {\n\t\tconst histRoute: Route = JSON.parse(stack[i]);\n\t\tif (equal(histRoute, partial, true)) {\n\t\t\tconst pages = i - stack.length;\n\t\t\tlog(`back`, pages, histRoute);\n\t\t\thistoryE.go(pages);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst newRoute = toCanonRoute(partial, \"back\", stack.length + 1);\n\tlog(`back not found, replacing`, partial);\n\tcopy(current, newRoute);\n}\n\n/**\n* Navigate up in the path hierarchy, by going back to the first history entry\n* that has a shorter path than the current one. If there's none, we just shorten\n* the current path.\n* \n* Note that going back in browser history happens asynchronously, so `route` will not be updated immediately.\n*/\nexport function up(stripCount: number = 1): void {\n\tconst currentP = unproxy(current).p;\n\tconst stack: string[] = historyE.state?.stack || [];\n\tfor(let i = stack.length - 1; i >= 0; i--) {\n\t\tconst histRoute: Route = JSON.parse(stack[i]);\n\t\tif (histRoute.p.length < currentP.length && equal(histRoute.p, currentP.slice(0, histRoute.p.length), false)) {\n\t\t\t// This route is shorter and matches the start of the current path\n\t\t\tlog(`up to ${i+1} / ${stack.length}`, histRoute);\n\t\t\thistoryE.go(i - stack.length);\n\t\t\treturn;\n\t\t}\n\t}\n\t// Replace current route with /\n\tconst newRoute = toCanonRoute({p: currentP.slice(0, currentP.length - stripCount)}, \"back\", stack.length + 1);\n\tlog(`up not found, replacing`, newRoute);\n\tcopy(current, newRoute);\n}\n\n/**\n* Restore and store the vertical and horizontal scroll position for\n* the parent element to the page state.\n*\n* @param {string} name - A unique (within this page) name for this\n* scrollable element. Defaults to 'main'.\n*\n* The scroll position will be persisted in `route.aux.scroll.<name>`.\n*/\nexport function persistScroll(name = \"main\") {\n\tconst el = $()!;\n\tel.addEventListener(\"scroll\", onScroll);\n\tclean(() => el.removeEventListener(\"scroll\", onScroll));\n\t\n\tconst restore = unproxy(current).state.scroll?.[name];\n\tif (restore) {\n\t\tlog(\"restoring scroll\", name, restore);\n\t\tObject.assign(el, restore);\n\t}\n\t\n\tfunction onScroll() {\n\t\t(current.state.scroll ||= {})[name] = {\n\t\t\tscrollTop: el.scrollTop,\n\t\t\tscrollLeft: el.scrollLeft,\n\t\t};\n\t}\n}\n\n/**\n * Intercept clicks and Enter key presses on links (`<a>` tags) and use Aberdeen routing\n * instead of browser navigation for local paths (paths without a protocol or host).\n * \n * This allows you to use regular HTML anchor tags for navigation without needing to\n * manually attach click handlers to each link.\n * \n * @example\n * ```js\n * // In your root component:\n * route.interceptLinks();\n * \n * // Now you can use regular anchor tags:\n * $('a text=About href=/corporate/about');\n * ```\n */\nexport function interceptLinks() {\n\t$({\n\t\tclick: handleEvent,\n\t\tkeydown: handleKeyEvent,\n\t});\n\t\n\tfunction handleKeyEvent(e: KeyboardEvent) {\n\t\tif (e.key === \"Enter\") {\n\t\t\thandleEvent(e);\n\t\t}\n\t}\n\t\n\tfunction handleEvent(e: Event) {\n\t\t// Find the closest <a> tag\n\t\tlet target = e.target as HTMLElement | null;\n\t\twhile (target && target.tagName?.toUpperCase() !== \"A\") {\n\t\t\ttarget = target.parentElement;\n\t\t}\n\t\t\n\t\tif (!target) return;\n\t\t\n\t\tconst anchor = target as HTMLAnchorElement;\n\t\tconst href = anchor.getAttribute(\"href\");\n\t\t\n\t\tif (!href) return;\n\t\t\n\t\t// Skip hash-only links\n\t\tif (href.startsWith(\"#\")) return;\n\t\t\n\t\t// Skip if it has a protocol or is protocol-relative (// or contains : before any / ? #)\n\t\tif (href.startsWith(\"//\") || /^[^/?#]+:/.test(href)) return;\n\t\t\n\t\t// Skip if the link has target or download attribute\n\t\tif (anchor.getAttribute(\"target\") || anchor.getAttribute(\"download\")) return;\n\t\t\n\t\t// Skip if modifier keys are pressed (Ctrl/Cmd click to open in new tab)\n\t\tif (typeof MouseEvent !== 'undefined' && e instanceof MouseEvent && (e.ctrlKey || e.metaKey || e.shiftKey)) return;\n\t\t\n\t\te.preventDefault();\n\t\t\n\t\t// Parse using URL to handle both absolute and relative paths correctly\n\t\tconst url = new URL(href, locationE.href);\n\t\tgo({\n\t\t\tpath: url.pathname,\n\t\t\tsearch: Object.fromEntries(url.searchParams),\n\t\t\thash: url.hash,\n\t\t});\n\t}\n}\n\nlet prevStack: string[];\n\n/**\n* The global {@link Route} object reflecting the current URL and browser history state. Changes you make to this affect the current browser history item (modifying the URL if needed).\n*/\nexport const current: Route = proxy({}) as Route;\n\n/**\n * Reset the router to its initial state, based on the current browser state. Intended for testing purposes only.\n * @internal\n * */\nexport function reset() {\n\tprevStack = historyE.state?.stack || [];\n\tconst initRoute = getRouteFromBrowser();\n\tlog('initial', initRoute);\n\tcopy(unproxy(current), initRoute);\n}\nreset();\n\n// Handle browser history back and forward\nwindowE.addEventListener(\"popstate\", function(event: PopStateEvent) {\n\tconst newRoute = getRouteFromBrowser();\n\t\n\t// If the stack length changes, and at least the top-most shared entry is the same,\n\t// we'll interpret this as a \"back\" or \"forward\" navigation.\n\tconst stack: string[] = historyE.state?.stack || [];\n\tif (stack.length !== prevStack.length) {\n\t\tconst maxIndex = Math.min(prevStack.length, stack.length) - 1;\n\t\tif (maxIndex < 0 || stack[maxIndex] === prevStack[maxIndex]) {\n\t\t\tnewRoute.nav = stack.length < prevStack.length ? \"back\" : \"forward\";\n\t\t}\n\t}\n\t// else nav will be \"load\"\n\t\n\tprevStack = stack;\n\tlog('popstate', newRoute);\n\tcopy(current, newRoute);\n\t\n\trunQueue();\n});\n\n// Make sure these observers are never cleaned up, not even by `unmountAll`.\nleakScope(() => {\n\t// Sync `p` to `path`. We need to do this in a separate, higher-priority observer,\n\t// so that setting `route.p` will not be immediately overruled by the pre-existing `route.path`.\n\t$(() => {\n\t\tcurrent.path = \"/\" + Array.from(current.p).join(\"/\");\n\t});\n\n\t// Do a replaceState based on changes to proxy\n\t$(() => {\n\n\t\t// First normalize `route`\n\t\tconst stack = historyE.state?.stack || [];\n\t\tconst newRoute = toCanonRoute(current, unproxy(current).nav, stack.length + 1);\n\t\tcopy(current, newRoute);\n\t\t\n\t\t// Then replace the current browser state if something actually changed\n\t\tconst state = {state: newRoute.state, stack};\n\t\tconst url = getUrl(newRoute);\n\t\tif (url !== locationE.pathname + locationE.search + locationE.hash || !equal(historyE.state, state, false)) {\n\t\t\tlog('replaceState', newRoute, state, url);\n\t\t\thistoryE.replaceState(state, \"\", url);\n\t\t}\n\t});\n});\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "AAAA,gBAAQ,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "AAAA,gBAAQ,OAAO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= {
|
|
|
245
245
|
'border-radius': 'r',
|
|
246
246
|
};
|
|
247
247
|
|
|
248
|
-
function kebabToCamel(str) {
|
|
249
|
-
return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
250
|
-
}
|
|
251
|
-
|
|
252
248
|
function convertStyleToAberdeen(styleString) {
|
|
253
249
|
const rules = styleString.split(';').map(s => s.trim()).filter(Boolean);
|
|
254
250
|
const resultParts = [];
|
|
@@ -263,8 +259,9 @@ function convertStyleToAberdeen(styleString) {
|
|
|
263
259
|
}
|
|
264
260
|
|
|
265
261
|
const addPart = (key, value) => {
|
|
262
|
+
value = value.replace(/\bvar\(--([a-zA-Z_][a-zA-Z_0-9]*)\)/g, (_all, p1) => '$'+p1);
|
|
266
263
|
if (value.includes(' ')) {
|
|
267
|
-
resultParts.push(`${key}:
|
|
264
|
+
resultParts.push(`${key}: ${value};`);
|
|
268
265
|
} else {
|
|
269
266
|
resultParts.push(`${key}:${value}`);
|
|
270
267
|
}
|
|
@@ -284,7 +281,7 @@ function convertStyleToAberdeen(styleString) {
|
|
|
284
281
|
handleGroup('padding-left', 'padding-right', 'ph');
|
|
285
282
|
|
|
286
283
|
for (const [key, value] of Object.entries(props)) {
|
|
287
|
-
const shortcut = CSS_PROPERTY_TO_SHORTCUT[key] ||
|
|
284
|
+
const shortcut = CSS_PROPERTY_TO_SHORTCUT[key] || key;
|
|
288
285
|
addPart(shortcut, value);
|
|
289
286
|
}
|
|
290
287
|
|