breeze-router 0.4.0 → 1.0.1
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 +8 -1
- package/dist/BreezeRouter.js +103 -55
- package/dist/BreezeRouter.js.map +1 -1
- package/dist/BreezeRouter.min.js +1 -1
- package/dist/BreezeRouter.min.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ npm install breeze-router
|
|
|
17
17
|
```javascript
|
|
18
18
|
<script type="module">
|
|
19
19
|
import BreezeRouter from
|
|
20
|
-
"https://unpkg.com/breeze-router@0.
|
|
20
|
+
"https://unpkg.com/breeze-router@1.0.1/dist/BreezeRouter.min.js";
|
|
21
21
|
</script>
|
|
22
22
|
```
|
|
23
23
|
|
|
@@ -64,6 +64,13 @@ ROUTER.add("/users/:username/posts/:postId", async ({ route, params }) => {
|
|
|
64
64
|
|
|
65
65
|
// Call the `start` method to start the router.
|
|
66
66
|
ROUTER.start();
|
|
67
|
+
|
|
68
|
+
// You can register the callbacks to run when the router is ready.
|
|
69
|
+
// This is a good time to do some initial work like injecting some
|
|
70
|
+
// global headers or footers into the page.
|
|
71
|
+
ROUTER.ready(() => {
|
|
72
|
+
console.log("ROUTER is ready now.");
|
|
73
|
+
});
|
|
67
74
|
```
|
|
68
75
|
|
|
69
76
|
## License
|
package/dist/BreezeRouter.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Check if given param is function
|
|
5
4
|
* @param {Function} fn
|
|
@@ -102,6 +101,26 @@ class BreezeRouter {
|
|
|
102
101
|
* @type {string}
|
|
103
102
|
*/
|
|
104
103
|
#ignoreAttribute = "data-breeze-ignore";
|
|
104
|
+
#isReady = false;
|
|
105
|
+
#isReadyCallbacks = [];
|
|
106
|
+
|
|
107
|
+
previousPath = "";
|
|
108
|
+
/**
|
|
109
|
+
* The previous route that was navigated to.
|
|
110
|
+
*
|
|
111
|
+
* @type {import('./types.js').Route|null}
|
|
112
|
+
*/
|
|
113
|
+
previousRoute = null;
|
|
114
|
+
previousParams = {};
|
|
115
|
+
|
|
116
|
+
currentPath = "";
|
|
117
|
+
/**
|
|
118
|
+
* The current route that we're on.
|
|
119
|
+
*
|
|
120
|
+
* @type {import('./types.js').Route|null}
|
|
121
|
+
*/
|
|
122
|
+
currentRoute = null;
|
|
123
|
+
currentParams = {};
|
|
105
124
|
|
|
106
125
|
/**
|
|
107
126
|
* Creates a new BreezeRouter instance.
|
|
@@ -122,13 +141,6 @@ class BreezeRouter {
|
|
|
122
141
|
*/
|
|
123
142
|
this._routes = {};
|
|
124
143
|
|
|
125
|
-
/**
|
|
126
|
-
* The previous route that was navigated to
|
|
127
|
-
* @type {import('./types.js').Route|null}
|
|
128
|
-
* @private
|
|
129
|
-
*/
|
|
130
|
-
this._previousRoute = null;
|
|
131
|
-
|
|
132
144
|
// Bind event listeners
|
|
133
145
|
window.addEventListener("popstate", this._onChanged.bind(this));
|
|
134
146
|
document.body.addEventListener("click", this._handleClick.bind(this));
|
|
@@ -142,6 +154,17 @@ class BreezeRouter {
|
|
|
142
154
|
this._onChanged();
|
|
143
155
|
}
|
|
144
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Register the callback when the router is ready.
|
|
159
|
+
*
|
|
160
|
+
* @param {Function} fn - Callback function.
|
|
161
|
+
*/
|
|
162
|
+
ready(fn) {
|
|
163
|
+
if (typeof fn === 'function') {
|
|
164
|
+
this.#isReadyCallbacks.push(fn);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
145
168
|
/**
|
|
146
169
|
* Adds a new route to the router.
|
|
147
170
|
* @param {string} route - The route path to add.
|
|
@@ -165,19 +188,22 @@ class BreezeRouter {
|
|
|
165
188
|
const types = {};
|
|
166
189
|
|
|
167
190
|
// Route has types defined.
|
|
168
|
-
if (route.includes(
|
|
191
|
+
if (route.includes("<")) {
|
|
169
192
|
// Split the URL segments by '/'.
|
|
170
|
-
const urlSegments = route
|
|
193
|
+
const urlSegments = route
|
|
194
|
+
.split("/")
|
|
195
|
+
.filter((segment) => segment.includes("<"));
|
|
171
196
|
|
|
172
197
|
// Loop through each segment and get its type.
|
|
173
|
-
urlSegments.forEach(segment => {
|
|
198
|
+
urlSegments.forEach((segment) => {
|
|
174
199
|
// Get the type.
|
|
175
|
-
const type = segment
|
|
176
|
-
.
|
|
177
|
-
.replace(
|
|
200
|
+
const type = segment
|
|
201
|
+
.match(/\<.+\>/)?.[0]
|
|
202
|
+
.replace("<", "")
|
|
203
|
+
.replace(">", "");
|
|
178
204
|
|
|
179
205
|
// Get the prop name.
|
|
180
|
-
const propName = segment.replace(/\<.+\>/,
|
|
206
|
+
const propName = segment.replace(/\<.+\>/, "").replace(":", "");
|
|
181
207
|
|
|
182
208
|
// Store the prop name and type.
|
|
183
209
|
types[propName] = type;
|
|
@@ -185,7 +211,7 @@ class BreezeRouter {
|
|
|
185
211
|
}
|
|
186
212
|
|
|
187
213
|
// Remove all '<type>' definitions.
|
|
188
|
-
route = route.replaceAll(/\<.+\>/g,
|
|
214
|
+
route = route.replaceAll(/\<.+\>/g, "");
|
|
189
215
|
|
|
190
216
|
this._routes[route] = {
|
|
191
217
|
path: route,
|
|
@@ -202,6 +228,9 @@ class BreezeRouter {
|
|
|
202
228
|
* @returns {void}
|
|
203
229
|
*/
|
|
204
230
|
navigateTo(url) {
|
|
231
|
+
this.previousPath = this.currentPath;
|
|
232
|
+
this.previousRoute = this.currentRoute;
|
|
233
|
+
this.previousParams = this.currentParams;
|
|
205
234
|
window.history.pushState({ url }, "", url);
|
|
206
235
|
this._onChanged();
|
|
207
236
|
}
|
|
@@ -219,14 +248,32 @@ class BreezeRouter {
|
|
|
219
248
|
const path = window.location.pathname;
|
|
220
249
|
const { route, params } = this._matchUrlToRoute(path);
|
|
221
250
|
|
|
251
|
+
this.currentPath = addTrailingSlash(path);
|
|
252
|
+
this.currentRoute = route;
|
|
253
|
+
this.currentParams = params;
|
|
254
|
+
|
|
222
255
|
// If no matching route found, route will be '404' route
|
|
223
|
-
// which has been handled by _matchUrlToRoute already
|
|
256
|
+
// which has been handled by _matchUrlToRoute already.
|
|
224
257
|
await this._handleRoute({ route, params });
|
|
225
258
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
259
|
+
if (!this.#isReady) {
|
|
260
|
+
this.#isReady = true;
|
|
261
|
+
this.#isReadyCallbacks.forEach(fn => fn(this));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
document.dispatchEvent(
|
|
265
|
+
new CustomEvent("breeze-route-changed", {
|
|
266
|
+
detail: {
|
|
267
|
+
previousPath: this.previousPath,
|
|
268
|
+
previousRoute: this.previousRoute,
|
|
269
|
+
previousParams: this.previousParams,
|
|
270
|
+
currentPath: this.currentPath,
|
|
271
|
+
currentRoute: this.currentRoute,
|
|
272
|
+
currentParams: this.currentParams,
|
|
273
|
+
router: this,
|
|
274
|
+
},
|
|
275
|
+
}),
|
|
276
|
+
);
|
|
230
277
|
}
|
|
231
278
|
|
|
232
279
|
/**
|
|
@@ -257,49 +304,50 @@ class BreezeRouter {
|
|
|
257
304
|
url = addTrailingSlash(url);
|
|
258
305
|
}
|
|
259
306
|
|
|
260
|
-
const matchedRoute = Object.entries(this._routes).find(
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
307
|
+
const matchedRoute = Object.entries(this._routes).find(
|
|
308
|
+
([route, routeObject]) => {
|
|
309
|
+
if (url.split("/").length !== route.split("/").length) {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
264
312
|
|
|
265
|
-
|
|
313
|
+
const { types } = routeObject;
|
|
266
314
|
|
|
267
|
-
|
|
268
|
-
|
|
315
|
+
let routeSegments = route.split("/").slice(1);
|
|
316
|
+
let urlSegments = url.split("/").slice(1);
|
|
269
317
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
318
|
+
// If each segment in the url matches the corresponding segment in the route path,
|
|
319
|
+
// or the route path segment starts with a ':' then the route is matched.
|
|
320
|
+
const match = routeSegments.every((segment, i) => {
|
|
321
|
+
if (!segment.startsWith(":")) {
|
|
322
|
+
return segment === urlSegments[i];
|
|
323
|
+
}
|
|
276
324
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
325
|
+
// /product/:id => segment/segment
|
|
326
|
+
// /product/123 => urlSegment/urlSegment
|
|
327
|
+
const type = types[segment.replace(":", "")];
|
|
280
328
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
: true;
|
|
329
|
+
// const segmentType =
|
|
330
|
+
const isValid =
|
|
331
|
+
type === "number" ? Number.isInteger(Number(urlSegments[i])) : true;
|
|
285
332
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
if (!match) {
|
|
290
|
-
return false;
|
|
291
|
-
}
|
|
333
|
+
return isValid;
|
|
334
|
+
});
|
|
292
335
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (segment.startsWith(":")) {
|
|
296
|
-
const propName = segment.slice(1);
|
|
297
|
-
params[propName] = decodeURIComponent(urlSegments[i]);
|
|
336
|
+
if (!match) {
|
|
337
|
+
return false;
|
|
298
338
|
}
|
|
299
|
-
});
|
|
300
339
|
|
|
301
|
-
|
|
302
|
-
|
|
340
|
+
// If the route matches the URL, pull out any params from the URL.
|
|
341
|
+
routeSegments.forEach((segment, i) => {
|
|
342
|
+
if (segment.startsWith(":")) {
|
|
343
|
+
const propName = segment.slice(1);
|
|
344
|
+
params[propName] = decodeURIComponent(urlSegments[i]);
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
return true;
|
|
349
|
+
},
|
|
350
|
+
);
|
|
303
351
|
|
|
304
352
|
if (matchedRoute) {
|
|
305
353
|
return {
|
package/dist/BreezeRouter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BreezeRouter.js","sources":["../src/utils.js","../src/index.js"],"sourcesContent":["// @ts-check\n\n/**\n * Check if given param is function\n * @param {Function} fn\n * @returns {boolean}\n */\nexport const isFunction = (fn) => {\n if (!fn) return false;\n return fn.constructor.name.toLowerCase() === \"function\";\n};\n\n/**\n * Check if given param is async function\n * @param {Function} fn\n * @returns {boolean}\n */\nexport const isAsyncFunction = (fn) => {\n if (!fn) return false;\n return fn.constructor.name.toLowerCase() === \"asyncfunction\";\n};\n\n/**\n * Remove trailing slash of a given url.\n * @param {string} url\n * @returns {string}\n */\nexport const removeTrailingSlash = (url) => {\n if (url.endsWith(\"/\")) {\n url = url.replace(/\\/$/, \"\");\n }\n\n return url;\n};\n\n/**\n * Add trailing slash of a given url.\n * @param {string} url\n * @returns {string}\n */\nexport const addTrailingSlash = (url) => {\n url = url.trim();\n if (!url.endsWith(\"/\")) {\n url = url + \"/\";\n }\n\n return url;\n};\n\n/**\n * Find anchor element from click event.\n * @param {Event} e - The click event.\n * @returns {HTMLAnchorElement|undefined}\n */\nexport const findAnchor = (e) => {\n return e.composedPath().find((elem) => {\n return elem.tagName === \"A\";\n });\n};\n\n/**\n * Check if the router should handle a click event on an anchor element.\n * @param {Event} e - The click event.\n * @param {HTMLAnchorElement} anchor - The anchor element.\n * @returns {boolean} - True if the router should handle the event, false otherwise.\n */\nexport const shouldRouterHandleClick = (e, anchor) => {\n // If the event has already been handled by another event listener\n if (e.defaultPrevented) {\n return false;\n }\n\n // If the user is holding down the meta, control, or shift key\n if (e.metaKey || e.ctrlKey || e.shiftKey) {\n return false;\n }\n\n if (!anchor) {\n return false;\n }\n\n if (anchor.target) {\n return false;\n }\n\n if (\n anchor.hasAttribute(\"download\") ||\n anchor.getAttribute(\"rel\") === \"external\"\n ) {\n return false;\n }\n\n const href = anchor.href;\n if (!href || href.startsWith(\"mailto:\")) {\n return false;\n }\n\n // If the href attribute does not start with the same origin\n if (!href.startsWith(location.origin)) {\n return false;\n }\n\n return true;\n};\n","// @ts-check\nimport {\n\tisFunction,\n\tisAsyncFunction,\n\tremoveTrailingSlash,\n\taddTrailingSlash,\n\tfindAnchor,\n\tshouldRouterHandleClick,\n} from \"./utils.js\";\n\n/**\n * Class representing a router.\n */\nexport default class BreezeRouter {\n\t/**\n\t * `data-` attribute to allow users to skip the router behavior,\n\t * anchor link with this attribute set will behavior as normal link.\n\t * @type {string}\n\t */\n\t#ignoreAttribute = \"data-breeze-ignore\";\n\n\t/**\n\t * Creates a new BreezeRouter instance.\n\t * @param {object} config - Config.\n\t * @constructor\n\t */\n\tconstructor(config) {\n\t\tconst { ignoreAttribute } = config || {};\n\n\t\tif (ignoreAttribute) {\n\t\t\tthis.#ignoreAttribute = ignoreAttribute;\n\t\t}\n\n\t\t/**\n\t\t * Object containing all registered routes.\n\t\t * @type {object}\n\t\t * @private\n\t\t */\n\t\tthis._routes = {};\n\n\t\t/**\n\t\t * The previous route that was navigated to\n\t\t * @type {import('./types.js').Route|null}\n\t\t * @private\n\t\t */\n\t\tthis._previousRoute = null;\n\n\t\t// Bind event listeners\n\t\twindow.addEventListener(\"popstate\", this._onChanged.bind(this));\n\t\tdocument.body.addEventListener(\"click\", this._handleClick.bind(this));\n\t}\n\n\t/**\n\t * Starts the router.\n\t * @returns {void}\n\t */\n\tstart() {\n\t\tthis._onChanged();\n\t}\n\n\t/**\n\t * Adds a new route to the router.\n\t * @param {string} route - The route path to add.\n\t * @param {Function} handler - The async function to handle the route\n\t * @returns {BreezeRouter|void} The BreezeRouter instance.\n\t */\n\tadd(route, handler) {\n\t\troute = route.trim();\n\t\tif (route !== \"/\") {\n\t\t\troute = addTrailingSlash(route);\n\t\t}\n\n\t\tif (this._routes[route]) {\n\t\t\treturn console.warn(`Route already exists: ${route}`);\n\t\t}\n\n\t\tif (typeof handler !== \"function\") {\n\t\t\treturn console.error(`handler of route '${route}' must be a function.`);\n\t\t}\n\n\t\tconst types = {};\n\n\t\t// Route has types defined.\n\t\tif (route.includes('<')) {\n\t\t\t// Split the URL segments by '/'.\n\t\t\tconst urlSegments = route.split('/').filter(segment => segment.includes('<'));\n\n\t\t\t// Loop through each segment and get its type.\n\t\t\turlSegments.forEach(segment => {\n\t\t\t\t// Get the type.\n\t\t\t\tconst type = segment.match(/\\<.+\\>/)?.[0]\n\t\t\t\t\t.replace('<', '')\n\t\t\t\t\t.replace('>', '');\n\n\t\t\t\t// Get the prop name.\n\t\t\t\tconst propName = segment.replace(/\\<.+\\>/, '').replace(':', '');\n\n\t\t\t\t// Store the prop name and type.\n\t\t\t\ttypes[propName] = type;\n\t\t\t});\n\t\t}\n\n\t\t// Remove all '<type>' definitions.\n\t\troute = route.replaceAll(/\\<.+\\>/g, '');\n\n\t\tthis._routes[route] = {\n\t\t\tpath: route,\n\t\t\ttypes,\n\t\t\thandler,\n\t\t};\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Navigates to the specified URL.\n\t * @param {string} url - The URL to navigate to\n\t * @returns {void}\n\t */\n\tnavigateTo(url) {\n\t\twindow.history.pushState({ url }, \"\", url);\n\t\tthis._onChanged();\n\t}\n\n\t/**\n\t * Redirects a URL\n\t * @param {string} url\n\t * @returns {void}\n\t */\n\tredirect(url) {\n\t\tthis.navigateTo(url);\n\t}\n\n\tasync _onChanged() {\n\t\tconst path = window.location.pathname;\n\t\tconst { route, params } = this._matchUrlToRoute(path);\n\n\t\t// If no matching route found, route will be '404' route\n\t\t// which has been handled by _matchUrlToRoute already\n\t\tawait this._handleRoute({ route, params });\n\n\t\t/**\n\t\t * Update previous route, so application route handler can check and decide if it should re-render whole page.\n\t\t */\n\t\tthis._previousRoute = route;\n\t}\n\n\t/**\n\t * Processes route callbacks registered by app\n\t * @param {import('./types.js').MatchedRoute} options\n\t * @returns {Promise<void>}\n\t */\n\tasync _handleRoute({ route, params }) {\n\t\tif (isFunction(route?.handler)) {\n\t\t\troute.handler({ route, params });\n\t\t}\n\n\t\tif (isAsyncFunction(route?.handler)) {\n\t\t\tawait route.handler({ route, params });\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * @param {string} url - Current url users visite or nagivate to.\n\t * @returns {import('./types.js').MatchedRoute}\n\t */\n\t_matchUrlToRoute(url) {\n\t\t/** @type {import('./types.js').RouteParams} */\n\t\tconst params = {};\n\n\t\tif (url !== \"/\") {\n\t\t\turl = addTrailingSlash(url);\n\t\t}\n\n\t\tconst matchedRoute = Object.entries(this._routes).find(([route, routeObject]) => {\n\t\t\tif (url.split(\"/\").length !== route.split(\"/\").length) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst { types } = routeObject;\n\n\t\t\tlet routeSegments = route.split(\"/\").slice(1);\n\t\t\tlet urlSegments = url.split(\"/\").slice(1);\n\n\t\t\t// If each segment in the url matches the corresponding segment in the route path,\n\t\t\t// or the route path segment starts with a ':' then the route is matched.\n\t\t\tconst match = routeSegments.every((segment, i) => {\n\t\t\t\tif (!segment.startsWith(\":\")) {\n\t\t\t\t\treturn segment === urlSegments[i];\n\t\t\t\t}\n\n\t\t\t\t// /product/:id => segment/segment\n\t\t\t\t// /product/123 => urlSegment/urlSegment\n\t\t\t\tconst type = types[segment.replace(':', '')];\n\n\t\t\t\t// const segmentType = \n\t\t\t\tconst isValid = type === 'number'\n\t\t\t\t\t? Number.isInteger(Number(urlSegments[i]))\n\t\t\t\t\t: true;\n\n\t\t\t\treturn isValid;\n\t\t\t});\n\n\t\t\tif (!match) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// If the route matches the URL, pull out any params from the URL.\n\t\t\trouteSegments.forEach((segment, i) => {\n\t\t\t\tif (segment.startsWith(\":\")) {\n\t\t\t\t\tconst propName = segment.slice(1);\n\t\t\t\t\tparams[propName] = decodeURIComponent(urlSegments[i]);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn true;\n\t\t});\n\n\t\tif (matchedRoute) {\n\t\t\treturn {\n\t\t\t\troute: this._routes[matchedRoute[0]],\n\t\t\t\tparams,\n\t\t\t\tsearchParams: new URLSearchParams(window.location.search),\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\troute: this._routes[404],\n\t\t\t\tparams,\n\t\t\t\tsearchParams: null,\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Handles <a> link clicks\n\t * @param {Event} event\n\t * @returns {void}\n\t */\n\t_handleClick(event) {\n\t\tconst anchor = findAnchor(event);\n\t\tif (!anchor) {\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * Allow users to define an `data-` attribute to skip the route handling.\n\t\t * Default to `data-breeze-ignore`.\n\t\t */\n\t\tif (anchor.hasAttribute(this.#ignoreAttribute)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (!shouldRouterHandleClick(event, anchor)) {\n\t\t\treturn;\n\t\t}\n\n\t\tevent.preventDefault();\n\t\tlet href = anchor.getAttribute(\"href\")?.trim();\n\t\tif (!href?.startsWith(\"/\")) {\n\t\t\thref = \"/\" + href;\n\t\t}\n\n\t\tthis.navigateTo(href);\n\t}\n\n\t/**\n\t * Add or remove search param to current url.\n\t * @param {HTMLInputElement} checkbox\n\t * @param {string} value\n\t * @returns void\n\t */\n\ttoggleParam(checkbox, value) {\n\t\tconst params = new URLSearchParams(location.search);\n\t\tconst name = checkbox.getAttribute(\"name\");\n\t\tif (!name) {\n\t\t\treturn console.warn(`name attribute is not set on ${checkbox.outerHTML}`);\n\t\t}\n\t\tif (checkbox.checked) {\n\t\t\t!params.has(name) && params.set(name, value);\n\t\t} else if (!checkbox.checked) {\n\t\t\tparams.has(name) && params.delete(name);\n\t\t}\n\n\t\tconst newUrl = !!params.size\n\t\t\t? `${location.pathname}?${params.toString()}`\n\t\t\t: location.pathname;\n\t\tthis.navigateTo(newUrl);\n\t}\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,UAAU,GAAG,CAAC,EAAE,KAAK;AAClC,EAAE,IAAI,CAAC,EAAE,EAAE,OAAO,KAAK,CAAC;AACxB,EAAE,OAA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AK,EAAE;AAC9B,EAAE,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACtD,EAAE,MAAM,IAAI,GAAG,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;AAC7C,EAAE,IAAI,CAAC,IAAI,EAAE;AACb,GAAG,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,6BAA6B,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC7E,GAAG;AACH,EAAE,IAAI,QAAQ,CAAC,OAAO,EAAE;AACxB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAChD,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;AAChC,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC3C,GAAG;AACH;AACA,EAAE,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI;AAC9B,KAAK,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;AAChD,KAAK,QAAQ,CAAC,QAAQ,CAAC;AACvB,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAC1B,EAAE;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"BreezeRouter.js","sources":["../src/utils.js","../src/index.js"],"sourcesContent":["// @ts-check\n/**\n * Check if given param is function\n * @param {Function} fn\n * @returns {boolean}\n */\nexport const isFunction = (fn) => {\n if (!fn) return false;\n return fn.constructor.name.toLowerCase() === \"function\";\n};\n\n/**\n * Check if given param is async function\n * @param {Function} fn\n * @returns {boolean}\n */\nexport const isAsyncFunction = (fn) => {\n if (!fn) return false;\n return fn.constructor.name.toLowerCase() === \"asyncfunction\";\n};\n\n/**\n * Remove trailing slash of a given url.\n * @param {string} url\n * @returns {string}\n */\nexport const removeTrailingSlash = (url) => {\n if (url.endsWith(\"/\")) {\n url = url.replace(/\\/$/, \"\");\n }\n\n return url;\n};\n\n/**\n * Add trailing slash of a given url.\n * @param {string} url\n * @returns {string}\n */\nexport const addTrailingSlash = (url) => {\n url = url.trim();\n if (!url.endsWith(\"/\")) {\n url = url + \"/\";\n }\n\n return url;\n};\n\n/**\n * Find anchor element from click event.\n * @param {Event} e - The click event.\n * @returns {HTMLAnchorElement|undefined}\n */\nexport const findAnchor = (e) => {\n return e.composedPath().find((elem) => {\n return elem.tagName === \"A\";\n });\n};\n\n/**\n * Check if the router should handle a click event on an anchor element.\n * @param {Event} e - The click event.\n * @param {HTMLAnchorElement} anchor - The anchor element.\n * @returns {boolean} - True if the router should handle the event, false otherwise.\n */\nexport const shouldRouterHandleClick = (e, anchor) => {\n // If the event has already been handled by another event listener\n if (e.defaultPrevented) {\n return false;\n }\n\n // If the user is holding down the meta, control, or shift key\n if (e.metaKey || e.ctrlKey || e.shiftKey) {\n return false;\n }\n\n if (!anchor) {\n return false;\n }\n\n if (anchor.target) {\n return false;\n }\n\n if (\n anchor.hasAttribute(\"download\") ||\n anchor.getAttribute(\"rel\") === \"external\"\n ) {\n return false;\n }\n\n const href = anchor.href;\n if (!href || href.startsWith(\"mailto:\")) {\n return false;\n }\n\n // If the href attribute does not start with the same origin\n if (!href.startsWith(location.origin)) {\n return false;\n }\n\n return true;\n};\n","// @ts-check\nimport {\n\tisFunction,\n\tisAsyncFunction,\n\tremoveTrailingSlash,\n\taddTrailingSlash,\n\tfindAnchor,\n\tshouldRouterHandleClick,\n} from \"./utils.js\";\n\n/**\n * Class representing a router.\n */\nexport default class BreezeRouter {\n\t/**\n\t * `data-` attribute to allow users to skip the router behavior,\n\t * anchor link with this attribute set will behavior as normal link.\n\t * @type {string}\n\t */\n\t#ignoreAttribute = \"data-breeze-ignore\";\n\t#isReady = false;\n\t#isReadyCallbacks = [];\n\n\tpreviousPath = \"\";\n\t/**\n\t * The previous route that was navigated to.\n\t *\n\t * @type {import('./types.js').Route|null}\n\t */\n\tpreviousRoute = null;\n\tpreviousParams = {};\n\n\tcurrentPath = \"\";\n\t/**\n\t * The current route that we're on.\n\t *\n\t * @type {import('./types.js').Route|null}\n\t */\n\tcurrentRoute = null;\n\tcurrentParams = {};\n\n\t/**\n\t * Creates a new BreezeRouter instance.\n\t * @param {object} config - Config.\n\t * @constructor\n\t */\n\tconstructor(config) {\n\t\tconst { ignoreAttribute } = config || {};\n\n\t\tif (ignoreAttribute) {\n\t\t\tthis.#ignoreAttribute = ignoreAttribute;\n\t\t}\n\n\t\t/**\n\t\t * Object containing all registered routes.\n\t\t * @type {object}\n\t\t * @private\n\t\t */\n\t\tthis._routes = {};\n\n\t\t// Bind event listeners\n\t\twindow.addEventListener(\"popstate\", this._onChanged.bind(this));\n\t\tdocument.body.addEventListener(\"click\", this._handleClick.bind(this));\n\t}\n\n\t/**\n\t * Starts the router.\n\t * @returns {void}\n\t */\n\tstart() {\n\t\tthis._onChanged();\n\t}\n\n\t/**\n\t * Register the callback when the router is ready.\n\t * \n\t * @param {Function} fn - Callback function.\n\t */\n\tready(fn) {\n\t\tif (typeof fn === 'function') {\n\t\t\tthis.#isReadyCallbacks.push(fn);\n\t\t}\n\t}\n\n\t/**\n\t * Adds a new route to the router.\n\t * @param {string} route - The route path to add.\n\t * @param {Function} handler - The async function to handle the route\n\t * @returns {BreezeRouter|void} The BreezeRouter instance.\n\t */\n\tadd(route, handler) {\n\t\troute = route.trim();\n\t\tif (route !== \"/\") {\n\t\t\troute = addTrailingSlash(route);\n\t\t}\n\n\t\tif (this._routes[route]) {\n\t\t\treturn console.warn(`Route already exists: ${route}`);\n\t\t}\n\n\t\tif (typeof handler !== \"function\") {\n\t\t\treturn console.error(`handler of route '${route}' must be a function.`);\n\t\t}\n\n\t\tconst types = {};\n\n\t\t// Route has types defined.\n\t\tif (route.includes(\"<\")) {\n\t\t\t// Split the URL segments by '/'.\n\t\t\tconst urlSegments = route\n\t\t\t\t.split(\"/\")\n\t\t\t\t.filter((segment) => segment.includes(\"<\"));\n\n\t\t\t// Loop through each segment and get its type.\n\t\t\turlSegments.forEach((segment) => {\n\t\t\t\t// Get the type.\n\t\t\t\tconst type = segment\n\t\t\t\t\t.match(/\\<.+\\>/)?.[0]\n\t\t\t\t\t.replace(\"<\", \"\")\n\t\t\t\t\t.replace(\">\", \"\");\n\n\t\t\t\t// Get the prop name.\n\t\t\t\tconst propName = segment.replace(/\\<.+\\>/, \"\").replace(\":\", \"\");\n\n\t\t\t\t// Store the prop name and type.\n\t\t\t\ttypes[propName] = type;\n\t\t\t});\n\t\t}\n\n\t\t// Remove all '<type>' definitions.\n\t\troute = route.replaceAll(/\\<.+\\>/g, \"\");\n\n\t\tthis._routes[route] = {\n\t\t\tpath: route,\n\t\t\ttypes,\n\t\t\thandler,\n\t\t};\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Navigates to the specified URL.\n\t * @param {string} url - The URL to navigate to\n\t * @returns {void}\n\t */\n\tnavigateTo(url) {\n\t\tthis.previousPath = this.currentPath;\n\t\tthis.previousRoute = this.currentRoute;\n\t\tthis.previousParams = this.currentParams;\n\t\twindow.history.pushState({ url }, \"\", url);\n\t\tthis._onChanged();\n\t}\n\n\t/**\n\t * Redirects a URL\n\t * @param {string} url\n\t * @returns {void}\n\t */\n\tredirect(url) {\n\t\tthis.navigateTo(url);\n\t}\n\n\tasync _onChanged() {\n\t\tconst path = window.location.pathname;\n\t\tconst { route, params } = this._matchUrlToRoute(path);\n\n\t\tthis.currentPath = addTrailingSlash(path);\n\t\tthis.currentRoute = route;\n\t\tthis.currentParams = params;\n\n\t\t// If no matching route found, route will be '404' route\n\t\t// which has been handled by _matchUrlToRoute already.\n\t\tawait this._handleRoute({ route, params });\n\n\t\tif (!this.#isReady) {\n\t\t\tthis.#isReady = true;\n\t\t\tthis.#isReadyCallbacks.forEach(fn => fn(this));\n\t\t}\n\n\t\tdocument.dispatchEvent(\n\t\t\tnew CustomEvent(\"breeze-route-changed\", {\n\t\t\t\tdetail: {\n\t\t\t\t\tpreviousPath: this.previousPath,\n\t\t\t\t\tpreviousRoute: this.previousRoute,\n\t\t\t\t\tpreviousParams: this.previousParams,\n\t\t\t\t\tcurrentPath: this.currentPath,\n\t\t\t\t\tcurrentRoute: this.currentRoute,\n\t\t\t\t\tcurrentParams: this.currentParams,\n\t\t\t\t\trouter: this,\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Processes route callbacks registered by app\n\t * @param {import('./types.js').MatchedRoute} options\n\t * @returns {Promise<void>}\n\t */\n\tasync _handleRoute({ route, params }) {\n\t\tif (isFunction(route?.handler)) {\n\t\t\troute.handler({ route, params });\n\t\t}\n\n\t\tif (isAsyncFunction(route?.handler)) {\n\t\t\tawait route.handler({ route, params });\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * @param {string} url - Current url users visite or nagivate to.\n\t * @returns {import('./types.js').MatchedRoute}\n\t */\n\t_matchUrlToRoute(url) {\n\t\t/** @type {import('./types.js').RouteParams} */\n\t\tconst params = {};\n\n\t\tif (url !== \"/\") {\n\t\t\turl = addTrailingSlash(url);\n\t\t}\n\n\t\tconst matchedRoute = Object.entries(this._routes).find(\n\t\t\t([route, routeObject]) => {\n\t\t\t\tif (url.split(\"/\").length !== route.split(\"/\").length) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tconst { types } = routeObject;\n\n\t\t\t\tlet routeSegments = route.split(\"/\").slice(1);\n\t\t\t\tlet urlSegments = url.split(\"/\").slice(1);\n\n\t\t\t\t// If each segment in the url matches the corresponding segment in the route path,\n\t\t\t\t// or the route path segment starts with a ':' then the route is matched.\n\t\t\t\tconst match = routeSegments.every((segment, i) => {\n\t\t\t\t\tif (!segment.startsWith(\":\")) {\n\t\t\t\t\t\treturn segment === urlSegments[i];\n\t\t\t\t\t}\n\n\t\t\t\t\t// /product/:id => segment/segment\n\t\t\t\t\t// /product/123 => urlSegment/urlSegment\n\t\t\t\t\tconst type = types[segment.replace(\":\", \"\")];\n\n\t\t\t\t\t// const segmentType =\n\t\t\t\t\tconst isValid =\n\t\t\t\t\t\ttype === \"number\" ? Number.isInteger(Number(urlSegments[i])) : true;\n\n\t\t\t\t\treturn isValid;\n\t\t\t\t});\n\n\t\t\t\tif (!match) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\t// If the route matches the URL, pull out any params from the URL.\n\t\t\t\trouteSegments.forEach((segment, i) => {\n\t\t\t\t\tif (segment.startsWith(\":\")) {\n\t\t\t\t\t\tconst propName = segment.slice(1);\n\t\t\t\t\t\tparams[propName] = decodeURIComponent(urlSegments[i]);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\treturn true;\n\t\t\t},\n\t\t);\n\n\t\tif (matchedRoute) {\n\t\t\treturn {\n\t\t\t\troute: this._routes[matchedRoute[0]],\n\t\t\t\tparams,\n\t\t\t\tsearchParams: new URLSearchParams(window.location.search),\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\troute: this._routes[404],\n\t\t\t\tparams,\n\t\t\t\tsearchParams: null,\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Handles <a> link clicks\n\t * @param {Event} event\n\t * @returns {void}\n\t */\n\t_handleClick(event) {\n\t\tconst anchor = findAnchor(event);\n\t\tif (!anchor) {\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * Allow users to define an `data-` attribute to skip the route handling.\n\t\t * Default to `data-breeze-ignore`.\n\t\t */\n\t\tif (anchor.hasAttribute(this.#ignoreAttribute)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (!shouldRouterHandleClick(event, anchor)) {\n\t\t\treturn;\n\t\t}\n\n\t\tevent.preventDefault();\n\t\tlet href = anchor.getAttribute(\"href\")?.trim();\n\t\tif (!href?.startsWith(\"/\")) {\n\t\t\thref = \"/\" + href;\n\t\t}\n\n\t\tthis.navigateTo(href);\n\t}\n\n\t/**\n\t * Add or remove search param to current url.\n\t * @param {HTMLInputElement} checkbox\n\t * @param {string} value\n\t * @returns void\n\t */\n\ttoggleParam(checkbox, value) {\n\t\tconst params = new URLSearchParams(location.search);\n\t\tconst name = checkbox.getAttribute(\"name\");\n\t\tif (!name) {\n\t\t\treturn console.warn(`name attribute is not set on ${checkbox.outerHTML}`);\n\t\t}\n\t\tif (checkbox.checked) {\n\t\t\t!params.has(name) && params.set(name, value);\n\t\t} else if (!checkbox.checked) {\n\t\t\tparams.has(name) && params.delete(name);\n\t\t}\n\n\t\tconst newUrl = !!params.size\n\t\t\t? `${location.pathname}?${params.toString()}`\n\t\t\t: location.pathname;\n\t\tthis.navigateTo(newUrl);\n\t}\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,UAAU,GAAG,CAAC,EAAE,KAAK;AAClC,EAAE,IAAI,CAAC,EAAE,EAAE,OAAO,KAAK,CAAC;AACxB,EAAE,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC;AAC1D,CAAC,CAAC;AACF;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,eAAe,GAAG,CAAC,EAAE,KAAK;AACvC,EAAE,IAAI,CAAC,EAAE,EAAE,OAAO,KAAK,CAAC;AACxB,EAAE,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,eAAe,CAAC;AAC/D,CAAC,CAAC;AAcF;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,gBAAgB,GAAG,CAAC,GAAG,KAAK;AACzC,EAAE,GAAG,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;AACnB,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AAC1B,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AACpB,GAAG;AACH;AACA,E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GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAChD,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;AAChC,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC3C,GAAG;AACH;AACA,EAAE,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI;AAC9B,KAAK,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;AAChD,KAAK,QAAQ,CAAC,QAAQ,CAAC;AACvB,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAC1B,EAAE;AACF;;;;"}
|
package/dist/BreezeRouter.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const t=t=>((t=t.trim()).endsWith("/")||(t+="/"),t);class e{#t="data-breeze-ignore";constructor(t){const{ignoreAttribute:e}=t||{};e&&(this.#t=e),this._routes={},
|
|
1
|
+
const t=t=>((t=t.trim()).endsWith("/")||(t+="/"),t);class e{#t="data-breeze-ignore";#e=!1;#r=[];previousPath="";previousRoute=null;previousParams={};currentPath="";currentRoute=null;currentParams={};constructor(t){const{ignoreAttribute:e}=t||{};e&&(this.#t=e),this._routes={},window.addEventListener("popstate",this._onChanged.bind(this)),document.body.addEventListener("click",this._handleClick.bind(this))}start(){this._onChanged()}ready(t){"function"==typeof t&&this.#r.push(t)}add(e,r){if("/"!==(e=e.trim())&&(e=t(e)),this._routes[e])return console.warn(`Route already exists: ${e}`);if("function"!=typeof r)return console.error(`handler of route '${e}' must be a function.`);const a={};if(e.includes("<")){e.split("/").filter((t=>t.includes("<"))).forEach((t=>{const e=t.match(/\<.+\>/)?.[0].replace("<","").replace(">",""),r=t.replace(/\<.+\>/,"").replace(":","");a[r]=e}))}return e=e.replaceAll(/\<.+\>/g,""),this._routes[e]={path:e,types:a,handler:r},this}navigateTo(t){this.previousPath=this.currentPath,this.previousRoute=this.currentRoute,this.previousParams=this.currentParams,window.history.pushState({url:t},"",t),this._onChanged()}redirect(t){this.navigateTo(t)}async _onChanged(){const e=window.location.pathname,{route:r,params:a}=this._matchUrlToRoute(e);this.currentPath=t(e),this.currentRoute=r,this.currentParams=a,await this._handleRoute({route:r,params:a}),this.#e||(this.#e=!0,this.#r.forEach((t=>t(this)))),document.dispatchEvent(new CustomEvent("breeze-route-changed",{detail:{previousPath:this.previousPath,previousRoute:this.previousRoute,previousParams:this.previousParams,currentPath:this.currentPath,currentRoute:this.currentRoute,currentParams:this.currentParams,router:this}}))}async _handleRoute({route:t,params:e}){var r;r=t?.handler,r&&"function"===r.constructor.name.toLowerCase()&&t.handler({route:t,params:e}),(t=>!!t&&"asyncfunction"===t.constructor.name.toLowerCase())(t?.handler)&&await t.handler({route:t,params:e})}_matchUrlToRoute(e){const r={};"/"!==e&&(e=t(e));const a=Object.entries(this._routes).find((([t,a])=>{if(e.split("/").length!==t.split("/").length)return!1;const{types:s}=a;let i=t.split("/").slice(1),n=e.split("/").slice(1);return!!i.every(((t,e)=>{if(!t.startsWith(":"))return t===n[e];return"number"!==s[t.replace(":","")]||Number.isInteger(Number(n[e]))}))&&(i.forEach(((t,e)=>{if(t.startsWith(":")){const a=t.slice(1);r[a]=decodeURIComponent(n[e])}})),!0)}));return a?{route:this._routes[a[0]],params:r,searchParams:new URLSearchParams(window.location.search)}:{route:this._routes[404],params:r,searchParams:null}}_handleClick(t){const e=t.composedPath().find((t=>"A"===t.tagName));if(!e)return;if(e.hasAttribute(this.#t))return;if(!((t,e)=>{if(t.defaultPrevented)return!1;if(t.metaKey||t.ctrlKey||t.shiftKey)return!1;if(!e)return!1;if(e.target)return!1;if(e.hasAttribute("download")||"external"===e.getAttribute("rel"))return!1;const r=e.href;return!(!r||r.startsWith("mailto:")||!r.startsWith(location.origin))})(t,e))return;t.preventDefault();let r=e.getAttribute("href")?.trim();r?.startsWith("/")||(r="/"+r),this.navigateTo(r)}toggleParam(t,e){const r=new URLSearchParams(location.search),a=t.getAttribute("name");if(!a)return console.warn(`name attribute is not set on ${t.outerHTML}`);t.checked?!r.has(a)&&r.set(a,e):t.checked||r.has(a)&&r.delete(a);const s=r.size?`${location.pathname}?${r.toString()}`:location.pathname;this.navigateTo(s)}}export{e as default};
|
|
2
2
|
//# sourceMappingURL=BreezeRouter.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BreezeRouter.min.js","sources":["../src/utils.js","../src/index.js"],"sourcesContent":["// @ts-check\n\n/**\n * Check if given param is function\n * @param {Function} fn\n * @returns {boolean}\n */\nexport const isFunction = (fn) => {\n if (!fn) return false;\n return fn.constructor.name.toLowerCase() === \"function\";\n};\n\n/**\n * Check if given param is async function\n * @param {Function} fn\n * @returns {boolean}\n */\nexport const isAsyncFunction = (fn) => {\n if (!fn) return false;\n return fn.constructor.name.toLowerCase() === \"asyncfunction\";\n};\n\n/**\n * Remove trailing slash of a given url.\n * @param {string} url\n * @returns {string}\n */\nexport const removeTrailingSlash = (url) => {\n if (url.endsWith(\"/\")) {\n url = url.replace(/\\/$/, \"\");\n }\n\n return url;\n};\n\n/**\n * Add trailing slash of a given url.\n * @param {string} url\n * @returns {string}\n */\nexport const addTrailingSlash = (url) => {\n url = url.trim();\n if (!url.endsWith(\"/\")) {\n url = url + \"/\";\n }\n\n return url;\n};\n\n/**\n * Find anchor element from click event.\n * @param {Event} e - The click event.\n * @returns {HTMLAnchorElement|undefined}\n */\nexport const findAnchor = (e) => {\n return e.composedPath().find((elem) => {\n return elem.tagName === \"A\";\n });\n};\n\n/**\n * Check if the router should handle a click event on an anchor element.\n * @param {Event} e - The click event.\n * @param {HTMLAnchorElement} anchor - The anchor element.\n * @returns {boolean} - True if the router should handle the event, false otherwise.\n */\nexport const shouldRouterHandleClick = (e, anchor) => {\n // If the event has already been handled by another event listener\n if (e.defaultPrevented) {\n return false;\n }\n\n // If the user is holding down the meta, control, or shift key\n if (e.metaKey || e.ctrlKey || e.shiftKey) {\n return false;\n }\n\n if (!anchor) {\n return false;\n }\n\n if (anchor.target) {\n return false;\n }\n\n if (\n anchor.hasAttribute(\"download\") ||\n anchor.getAttribute(\"rel\") === \"external\"\n ) {\n return false;\n }\n\n const href = anchor.href;\n if (!href || href.startsWith(\"mailto:\")) {\n return false;\n }\n\n // If the href attribute does not start with the same origin\n if (!href.startsWith(location.origin)) {\n return false;\n }\n\n return true;\n};\n","// @ts-check\nimport {\n\tisFunction,\n\tisAsyncFunction,\n\tremoveTrailingSlash,\n\taddTrailingSlash,\n\tfindAnchor,\n\tshouldRouterHandleClick,\n} from \"./utils.js\";\n\n/**\n * Class representing a router.\n */\nexport default class BreezeRouter {\n\t/**\n\t * `data-` attribute to allow users to skip the router behavior,\n\t * anchor link with this attribute set will behavior as normal link.\n\t * @type {string}\n\t */\n\t#ignoreAttribute = \"data-breeze-ignore\";\n\n\t/**\n\t * Creates a new BreezeRouter instance.\n\t * @param {object} config - Config.\n\t * @constructor\n\t */\n\tconstructor(config) {\n\t\tconst { ignoreAttribute } = config || {};\n\n\t\tif (ignoreAttribute) {\n\t\t\tthis.#ignoreAttribute = ignoreAttribute;\n\t\t}\n\n\t\t/**\n\t\t * Object containing all registered routes.\n\t\t * @type {object}\n\t\t * @private\n\t\t */\n\t\tthis._routes = {};\n\n\t\t/**\n\t\t * The previous route that was navigated to\n\t\t * @type {import('./types.js').Route|null}\n\t\t * @private\n\t\t */\n\t\tthis._previousRoute = null;\n\n\t\t// Bind event listeners\n\t\twindow.addEventListener(\"popstate\", this._onChanged.bind(this));\n\t\tdocument.body.addEventListener(\"click\", this._handleClick.bind(this));\n\t}\n\n\t/**\n\t * Starts the router.\n\t * @returns {void}\n\t */\n\tstart() {\n\t\tthis._onChanged();\n\t}\n\n\t/**\n\t * Adds a new route to the router.\n\t * @param {string} route - The route path to add.\n\t * @param {Function} handler - The async function to handle the route\n\t * @returns {BreezeRouter|void} The BreezeRouter instance.\n\t */\n\tadd(route, handler) {\n\t\troute = route.trim();\n\t\tif (route !== \"/\") {\n\t\t\troute = addTrailingSlash(route);\n\t\t}\n\n\t\tif (this._routes[route]) {\n\t\t\treturn console.warn(`Route already exists: ${route}`);\n\t\t}\n\n\t\tif (typeof handler !== \"function\") {\n\t\t\treturn console.error(`handler of route '${route}' must be a function.`);\n\t\t}\n\n\t\tconst types = {};\n\n\t\t// Route has types defined.\n\t\tif (route.includes('<')) {\n\t\t\t// Split the URL segments by '/'.\n\t\t\tconst urlSegments = route.split('/').filter(segment => segment.includes('<'));\n\n\t\t\t// Loop through each segment and get its type.\n\t\t\turlSegments.forEach(segment => {\n\t\t\t\t// Get the type.\n\t\t\t\tconst type = segment.match(/\\<.+\\>/)?.[0]\n\t\t\t\t\t.replace('<', '')\n\t\t\t\t\t.replace('>', '');\n\n\t\t\t\t// Get the prop name.\n\t\t\t\tconst propName = segment.replace(/\\<.+\\>/, '').replace(':', '');\n\n\t\t\t\t// Store the prop name and type.\n\t\t\t\ttypes[propName] = type;\n\t\t\t});\n\t\t}\n\n\t\t// Remove all '<type>' definitions.\n\t\troute = route.replaceAll(/\\<.+\\>/g, '');\n\n\t\tthis._routes[route] = {\n\t\t\tpath: route,\n\t\t\ttypes,\n\t\t\thandler,\n\t\t};\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Navigates to the specified URL.\n\t * @param {string} url - The URL to navigate to\n\t * @returns {void}\n\t */\n\tnavigateTo(url) {\n\t\twindow.history.pushState({ url }, \"\", url);\n\t\tthis._onChanged();\n\t}\n\n\t/**\n\t * Redirects a URL\n\t * @param {string} url\n\t * @returns {void}\n\t */\n\tredirect(url) {\n\t\tthis.navigateTo(url);\n\t}\n\n\tasync _onChanged() {\n\t\tconst path = window.location.pathname;\n\t\tconst { route, params } = this._matchUrlToRoute(path);\n\n\t\t// If no matching route found, route will be '404' route\n\t\t// which has been handled by _matchUrlToRoute already\n\t\tawait this._handleRoute({ route, params });\n\n\t\t/**\n\t\t * Update previous route, so application route handler can check and decide if it should re-render whole page.\n\t\t */\n\t\tthis._previousRoute = route;\n\t}\n\n\t/**\n\t * Processes route callbacks registered by app\n\t * @param {import('./types.js').MatchedRoute} options\n\t * @returns {Promise<void>}\n\t */\n\tasync _handleRoute({ route, params }) {\n\t\tif (isFunction(route?.handler)) {\n\t\t\troute.handler({ route, params });\n\t\t}\n\n\t\tif (isAsyncFunction(route?.handler)) {\n\t\t\tawait route.handler({ route, params });\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * @param {string} url - Current url users visite or nagivate to.\n\t * @returns {import('./types.js').MatchedRoute}\n\t */\n\t_matchUrlToRoute(url) {\n\t\t/** @type {import('./types.js').RouteParams} */\n\t\tconst params = {};\n\n\t\tif (url !== \"/\") {\n\t\t\turl = addTrailingSlash(url);\n\t\t}\n\n\t\tconst matchedRoute = Object.entries(this._routes).find(([route, routeObject]) => {\n\t\t\tif (url.split(\"/\").length !== route.split(\"/\").length) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst { types } = routeObject;\n\n\t\t\tlet routeSegments = route.split(\"/\").slice(1);\n\t\t\tlet urlSegments = url.split(\"/\").slice(1);\n\n\t\t\t// If each segment in the url matches the corresponding segment in the route path,\n\t\t\t// or the route path segment starts with a ':' then the route is matched.\n\t\t\tconst match = routeSegments.every((segment, i) => {\n\t\t\t\tif (!segment.startsWith(\":\")) {\n\t\t\t\t\treturn segment === urlSegments[i];\n\t\t\t\t}\n\n\t\t\t\t// /product/:id => segment/segment\n\t\t\t\t// /product/123 => urlSegment/urlSegment\n\t\t\t\tconst type = types[segment.replace(':', '')];\n\n\t\t\t\t// const segmentType = \n\t\t\t\tconst isValid = type === 'number'\n\t\t\t\t\t? Number.isInteger(Number(urlSegments[i]))\n\t\t\t\t\t: true;\n\n\t\t\t\treturn isValid;\n\t\t\t});\n\n\t\t\tif (!match) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// If the route matches the URL, pull out any params from the URL.\n\t\t\trouteSegments.forEach((segment, i) => {\n\t\t\t\tif (segment.startsWith(\":\")) {\n\t\t\t\t\tconst propName = segment.slice(1);\n\t\t\t\t\tparams[propName] = decodeURIComponent(urlSegments[i]);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn true;\n\t\t});\n\n\t\tif (matchedRoute) {\n\t\t\treturn {\n\t\t\t\troute: this._routes[matchedRoute[0]],\n\t\t\t\tparams,\n\t\t\t\tsearchParams: new URLSearchParams(window.location.search),\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\troute: this._routes[404],\n\t\t\t\tparams,\n\t\t\t\tsearchParams: null,\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Handles <a> link clicks\n\t * @param {Event} event\n\t * @returns {void}\n\t */\n\t_handleClick(event) {\n\t\tconst anchor = findAnchor(event);\n\t\tif (!anchor) {\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * Allow users to define an `data-` attribute to skip the route handling.\n\t\t * Default to `data-breeze-ignore`.\n\t\t */\n\t\tif (anchor.hasAttribute(this.#ignoreAttribute)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (!shouldRouterHandleClick(event, anchor)) {\n\t\t\treturn;\n\t\t}\n\n\t\tevent.preventDefault();\n\t\tlet href = anchor.getAttribute(\"href\")?.trim();\n\t\tif (!href?.startsWith(\"/\")) {\n\t\t\thref = \"/\" + href;\n\t\t}\n\n\t\tthis.navigateTo(href);\n\t}\n\n\t/**\n\t * Add or remove search param to current url.\n\t * @param {HTMLInputElement} checkbox\n\t * @param {string} value\n\t * @returns void\n\t */\n\ttoggleParam(checkbox, value) {\n\t\tconst params = new URLSearchParams(location.search);\n\t\tconst name = checkbox.getAttribute(\"name\");\n\t\tif (!name) {\n\t\t\treturn console.warn(`name attribute is not set on ${checkbox.outerHTML}`);\n\t\t}\n\t\tif (checkbox.checked) {\n\t\t\t!params.has(name) && params.set(name, value);\n\t\t} else if (!checkbox.checked) {\n\t\t\tparams.has(name) && params.delete(name);\n\t\t}\n\n\t\tconst newUrl = !!params.size\n\t\t\t? `${location.pathname}?${params.toString()}`\n\t\t\t: location.pathname;\n\t\tthis.navigateTo(newUrl);\n\t}\n}\n"],"names":["addTrailingSlash","url","trim","endsWith","BreezeRouter","ignoreAttribute","constructor","config","this","_routes","_previousRoute","window","addEventListener","_onChanged","bind","document","body","_handleClick","start","add","route","handler","console","warn","error","types","includes","split","filter","segment","forEach","type","match","replace","propName","replaceAll","path","navigateTo","history","pushState","redirect","async","location","pathname","params","_matchUrlToRoute","_handleRoute","fn","name","toLowerCase","isAsyncFunction","matchedRoute","Object","entries","find","routeObject","length","routeSegments","slice","urlSegments","every","i","startsWith","Number","isInteger","decodeURIComponent","searchParams","URLSearchParams","search","event","anchor","composedPath","elem","tagName","hasAttribute","e","defaultPrevented","metaKey","ctrlKey","shiftKey","target","getAttribute","href","origin","shouldRouterHandleClick","preventDefault","toggleParam","checkbox","value","outerHTML","checked","has","set","delete","newUrl","size","toString"],"mappings":"AAOO,MAiCMA,EAAoBC,KAC/BA,EAAMA,EAAIC,QACDC,SAAS,OAChBF,GAAY,KAGPA,GCjCM,MAAMG,EAMpBC,GAAmB,qBAOnBC,YAAYC,GACX,MAAMF,gBAAEA,GAAoBE,GAAU,GAElCF,IACHG,MAAKH,EAAmBA,GAQzBG,KAAKC,QAAU,GAOfD,KAAKE,eAAiB,KAGtBC,OAAOC,iBAAiB,WAAYJ,KAAKK,WAAWC,KAAKN,OACzDO,SAASC,KAAKJ,iBAAiB,QAASJ,KAAKS,aAAaH,KAAKN,MAC/D,CAMDU,QACCV,KAAKK,YACL,CAQDM,IAAIC,EAAOC,GAMV,GAJc,OADdD,EAAQA,EAAMlB,UAEbkB,EAAQpB,EAAiBoB,IAGtBZ,KAAKC,QAAQW,GAChB,OAAOE,QAAQC,KAAK,yBAAyBH,KAG9C,GAAuB,m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InB,ECuJNC,CAAwBf,EAAOC,GACnC,OAGDD,EAAMgB,iBACN,IAAIH,EAAOZ,EAAOW,aAAa,SAAS/E,OACnCgF,GAAMpB,WAAW,OACrBoB,EAAO,IAAMA,GAGd1E,KAAK6B,WAAW6C,EAChB,CAQDI,YAAYC,EAAUC,GACrB,MAAM5C,EAAS,IAAIuB,gBAAgBzB,SAAS0B,QACtCpB,EAAOuC,EAASN,aAAa,QACnC,IAAKjC,EACJ,OAAO1B,QAAQC,KAAK,gCAAgCgE,EAASE,aAE1DF,EAASG,SACX9C,EAAO+C,IAAI3C,IAASJ,EAAOgD,IAAI5C,EAAMwC,GAC3BD,EAASG,SACpB9C,EAAO+C,IAAI3C,IAASJ,EAAOiD,OAAO7C,GAGnC,MAAM8C,EAAWlD,EAAOmD,KACrB,GAAGrD,SAASC,YAAYC,EAAOoD,aAC/BtD,SAASC,SACZnC,KAAK6B,WAAWyD,EAChB"}
|
|
1
|
+
{"version":3,"file":"BreezeRouter.min.js","sources":["../src/utils.js","../src/index.js"],"sourcesContent":["// @ts-check\n/**\n * Check if given param is function\n * @param {Function} fn\n * @returns {boolean}\n */\nexport const isFunction = (fn) => {\n if (!fn) return false;\n return fn.constructor.name.toLowerCase() === \"function\";\n};\n\n/**\n * Check if given param is async function\n * @param {Function} fn\n * @returns {boolean}\n */\nexport const isAsyncFunction = (fn) => {\n if (!fn) return false;\n return fn.constructor.name.toLowerCase() === \"asyncfunction\";\n};\n\n/**\n * Remove trailing slash of a given url.\n * @param {string} url\n * @returns {string}\n */\nexport const removeTrailingSlash = (url) => {\n if (url.endsWith(\"/\")) {\n url = url.replace(/\\/$/, \"\");\n }\n\n return url;\n};\n\n/**\n * Add trailing slash of a given url.\n * @param {string} url\n * @returns {string}\n */\nexport const addTrailingSlash = (url) => {\n url = url.trim();\n if (!url.endsWith(\"/\")) {\n url = url + \"/\";\n }\n\n return url;\n};\n\n/**\n * Find anchor element from click event.\n * @param {Event} e - The click event.\n * @returns {HTMLAnchorElement|undefined}\n */\nexport const findAnchor = (e) => {\n return e.composedPath().find((elem) => {\n return elem.tagName === \"A\";\n });\n};\n\n/**\n * Check if the router should handle a click event on an anchor element.\n * @param {Event} e - The click event.\n * @param {HTMLAnchorElement} anchor - The anchor element.\n * @returns {boolean} - True if the router should handle the event, false otherwise.\n */\nexport const shouldRouterHandleClick = (e, anchor) => {\n // If the event has already been handled by another event listener\n if (e.defaultPrevented) {\n return false;\n }\n\n // If the user is holding down the meta, control, or shift key\n if (e.metaKey || e.ctrlKey || e.shiftKey) {\n return false;\n }\n\n if (!anchor) {\n return false;\n }\n\n if (anchor.target) {\n return false;\n }\n\n if (\n anchor.hasAttribute(\"download\") ||\n anchor.getAttribute(\"rel\") === \"external\"\n ) {\n return false;\n }\n\n const href = anchor.href;\n if (!href || href.startsWith(\"mailto:\")) {\n return false;\n }\n\n // If the href attribute does not start with the same origin\n if (!href.startsWith(location.origin)) {\n return false;\n }\n\n return true;\n};\n","// @ts-check\nimport {\n\tisFunction,\n\tisAsyncFunction,\n\tremoveTrailingSlash,\n\taddTrailingSlash,\n\tfindAnchor,\n\tshouldRouterHandleClick,\n} from \"./utils.js\";\n\n/**\n * Class representing a router.\n */\nexport default class BreezeRouter {\n\t/**\n\t * `data-` attribute to allow users to skip the router behavior,\n\t * anchor link with this attribute set will behavior as normal link.\n\t * @type {string}\n\t */\n\t#ignoreAttribute = \"data-breeze-ignore\";\n\t#isReady = false;\n\t#isReadyCallbacks = [];\n\n\tpreviousPath = \"\";\n\t/**\n\t * The previous route that was navigated to.\n\t *\n\t * @type {import('./types.js').Route|null}\n\t */\n\tpreviousRoute = null;\n\tpreviousParams = {};\n\n\tcurrentPath = \"\";\n\t/**\n\t * The current route that we're on.\n\t *\n\t * @type {import('./types.js').Route|null}\n\t */\n\tcurrentRoute = null;\n\tcurrentParams = {};\n\n\t/**\n\t * Creates a new BreezeRouter instance.\n\t * @param {object} config - Config.\n\t * @constructor\n\t */\n\tconstructor(config) {\n\t\tconst { ignoreAttribute } = config || {};\n\n\t\tif (ignoreAttribute) {\n\t\t\tthis.#ignoreAttribute = ignoreAttribute;\n\t\t}\n\n\t\t/**\n\t\t * Object containing all registered routes.\n\t\t * @type {object}\n\t\t * @private\n\t\t */\n\t\tthis._routes = {};\n\n\t\t// Bind event listeners\n\t\twindow.addEventListener(\"popstate\", this._onChanged.bind(this));\n\t\tdocument.body.addEventListener(\"click\", this._handleClick.bind(this));\n\t}\n\n\t/**\n\t * Starts the router.\n\t * @returns {void}\n\t */\n\tstart() {\n\t\tthis._onChanged();\n\t}\n\n\t/**\n\t * Register the callback when the router is ready.\n\t * \n\t * @param {Function} fn - Callback function.\n\t */\n\tready(fn) {\n\t\tif (typeof fn === 'function') {\n\t\t\tthis.#isReadyCallbacks.push(fn);\n\t\t}\n\t}\n\n\t/**\n\t * Adds a new route to the router.\n\t * @param {string} route - The route path to add.\n\t * @param {Function} handler - The async function to handle the route\n\t * @returns {BreezeRouter|void} The BreezeRouter instance.\n\t */\n\tadd(route, handler) {\n\t\troute = route.trim();\n\t\tif (route !== \"/\") {\n\t\t\troute = addTrailingSlash(route);\n\t\t}\n\n\t\tif (this._routes[route]) {\n\t\t\treturn console.warn(`Route already exists: ${route}`);\n\t\t}\n\n\t\tif (typeof handler !== \"function\") {\n\t\t\treturn console.error(`handler of route '${route}' must be a function.`);\n\t\t}\n\n\t\tconst types = {};\n\n\t\t// Route has types defined.\n\t\tif (route.includes(\"<\")) {\n\t\t\t// Split the URL segments by '/'.\n\t\t\tconst urlSegments = route\n\t\t\t\t.split(\"/\")\n\t\t\t\t.filter((segment) => segment.includes(\"<\"));\n\n\t\t\t// Loop through each segment and get its type.\n\t\t\turlSegments.forEach((segment) => {\n\t\t\t\t// Get the type.\n\t\t\t\tconst type = segment\n\t\t\t\t\t.match(/\\<.+\\>/)?.[0]\n\t\t\t\t\t.replace(\"<\", \"\")\n\t\t\t\t\t.replace(\">\", \"\");\n\n\t\t\t\t// Get the prop name.\n\t\t\t\tconst propName = segment.replace(/\\<.+\\>/, \"\").replace(\":\", \"\");\n\n\t\t\t\t// Store the prop name and type.\n\t\t\t\ttypes[propName] = type;\n\t\t\t});\n\t\t}\n\n\t\t// Remove all '<type>' definitions.\n\t\troute = route.replaceAll(/\\<.+\\>/g, \"\");\n\n\t\tthis._routes[route] = {\n\t\t\tpath: route,\n\t\t\ttypes,\n\t\t\thandler,\n\t\t};\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Navigates to the specified URL.\n\t * @param {string} url - The URL to navigate to\n\t * @returns {void}\n\t */\n\tnavigateTo(url) {\n\t\tthis.previousPath = this.currentPath;\n\t\tthis.previousRoute = this.currentRoute;\n\t\tthis.previousParams = this.currentParams;\n\t\twindow.history.pushState({ url }, \"\", url);\n\t\tthis._onChanged();\n\t}\n\n\t/**\n\t * Redirects a URL\n\t * @param {string} url\n\t * @returns {void}\n\t */\n\tredirect(url) {\n\t\tthis.navigateTo(url);\n\t}\n\n\tasync _onChanged() {\n\t\tconst path = window.location.pathname;\n\t\tconst { route, params } = this._matchUrlToRoute(path);\n\n\t\tthis.currentPath = addTrailingSlash(path);\n\t\tthis.currentRoute = route;\n\t\tthis.currentParams = params;\n\n\t\t// If no matching route found, route will be '404' route\n\t\t// which has been handled by _matchUrlToRoute already.\n\t\tawait this._handleRoute({ route, params });\n\n\t\tif (!this.#isReady) {\n\t\t\tthis.#isReady = true;\n\t\t\tthis.#isReadyCallbacks.forEach(fn => fn(this));\n\t\t}\n\n\t\tdocument.dispatchEvent(\n\t\t\tnew CustomEvent(\"breeze-route-changed\", {\n\t\t\t\tdetail: {\n\t\t\t\t\tpreviousPath: this.previousPath,\n\t\t\t\t\tpreviousRoute: this.previousRoute,\n\t\t\t\t\tpreviousParams: this.previousParams,\n\t\t\t\t\tcurrentPath: this.currentPath,\n\t\t\t\t\tcurrentRoute: this.currentRoute,\n\t\t\t\t\tcurrentParams: this.currentParams,\n\t\t\t\t\trouter: this,\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Processes route callbacks registered by app\n\t * @param {import('./types.js').MatchedRoute} options\n\t * @returns {Promise<void>}\n\t */\n\tasync _handleRoute({ route, params }) {\n\t\tif (isFunction(route?.handler)) {\n\t\t\troute.handler({ route, params });\n\t\t}\n\n\t\tif (isAsyncFunction(route?.handler)) {\n\t\t\tawait route.handler({ route, params });\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * @param {string} url - Current url users visite or nagivate to.\n\t * @returns {import('./types.js').MatchedRoute}\n\t */\n\t_matchUrlToRoute(url) {\n\t\t/** @type {import('./types.js').RouteParams} */\n\t\tconst params = {};\n\n\t\tif (url !== \"/\") {\n\t\t\turl = addTrailingSlash(url);\n\t\t}\n\n\t\tconst matchedRoute = Object.entries(this._routes).find(\n\t\t\t([route, routeObject]) => {\n\t\t\t\tif (url.split(\"/\").length !== route.split(\"/\").length) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tconst { types } = routeObject;\n\n\t\t\t\tlet routeSegments = route.split(\"/\").slice(1);\n\t\t\t\tlet urlSegments = url.split(\"/\").slice(1);\n\n\t\t\t\t// If each segment in the url matches the corresponding segment in the route path,\n\t\t\t\t// or the route path segment starts with a ':' then the route is matched.\n\t\t\t\tconst match = routeSegments.every((segment, i) => {\n\t\t\t\t\tif (!segment.startsWith(\":\")) {\n\t\t\t\t\t\treturn segment === urlSegments[i];\n\t\t\t\t\t}\n\n\t\t\t\t\t// /product/:id => segment/segment\n\t\t\t\t\t// /product/123 => urlSegment/urlSegment\n\t\t\t\t\tconst type = types[segment.replace(\":\", \"\")];\n\n\t\t\t\t\t// const segmentType =\n\t\t\t\t\tconst isValid =\n\t\t\t\t\t\ttype === \"number\" ? Number.isInteger(Number(urlSegments[i])) : true;\n\n\t\t\t\t\treturn isValid;\n\t\t\t\t});\n\n\t\t\t\tif (!match) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\t// If the route matches the URL, pull out any params from the URL.\n\t\t\t\trouteSegments.forEach((segment, i) => {\n\t\t\t\t\tif (segment.startsWith(\":\")) {\n\t\t\t\t\t\tconst propName = segment.slice(1);\n\t\t\t\t\t\tparams[propName] = decodeURIComponent(urlSegments[i]);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\treturn true;\n\t\t\t},\n\t\t);\n\n\t\tif (matchedRoute) {\n\t\t\treturn {\n\t\t\t\troute: this._routes[matchedRoute[0]],\n\t\t\t\tparams,\n\t\t\t\tsearchParams: new URLSearchParams(window.location.search),\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\troute: this._routes[404],\n\t\t\t\tparams,\n\t\t\t\tsearchParams: null,\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Handles <a> link clicks\n\t * @param {Event} event\n\t * @returns {void}\n\t */\n\t_handleClick(event) {\n\t\tconst anchor = findAnchor(event);\n\t\tif (!anchor) {\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * Allow users to define an `data-` attribute to skip the route handling.\n\t\t * Default to `data-breeze-ignore`.\n\t\t */\n\t\tif (anchor.hasAttribute(this.#ignoreAttribute)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (!shouldRouterHandleClick(event, anchor)) {\n\t\t\treturn;\n\t\t}\n\n\t\tevent.preventDefault();\n\t\tlet href = anchor.getAttribute(\"href\")?.trim();\n\t\tif (!href?.startsWith(\"/\")) {\n\t\t\thref = \"/\" + href;\n\t\t}\n\n\t\tthis.navigateTo(href);\n\t}\n\n\t/**\n\t * Add or remove search param to current url.\n\t * @param {HTMLInputElement} checkbox\n\t * @param {string} value\n\t * @returns void\n\t */\n\ttoggleParam(checkbox, value) {\n\t\tconst params = new URLSearchParams(location.search);\n\t\tconst name = checkbox.getAttribute(\"name\");\n\t\tif (!name) {\n\t\t\treturn console.warn(`name attribute is not set on ${checkbox.outerHTML}`);\n\t\t}\n\t\tif (checkbox.checked) {\n\t\t\t!params.has(name) && params.set(name, value);\n\t\t} else if (!checkbox.checked) {\n\t\t\tparams.has(name) && params.delete(name);\n\t\t}\n\n\t\tconst newUrl = !!params.size\n\t\t\t? `${location.pathname}?${params.toString()}`\n\t\t\t: location.pathname;\n\t\tthis.navigateTo(newUrl);\n\t}\n}\n"],"names":["addTrailingSlash","url","trim","endsWith","BreezeRouter","ignoreAttribute","isReady","isReadyCallbacks","previousPath","previousRoute","previousParams","currentPath","currentRoute","currentParams","constructor","config","this","_routes","window","addEventListener","_onChanged","bind","document","body","_handleClick","start","ready","fn","push","add","route","handler","console","warn","error","types","includes","split","filter","segment","forEach","type","match","replace","propName","replaceAll","path","navigateTo","history","pushState","redirect","async","location","pathname","params","_matchUrlToRoute","_handleRoute","dispatchEvent","CustomEvent","detail","router","name","toLowerCase","isAsyncFunction","matchedRoute","Object","entries","find","routeObject","length","routeSegments","slice","urlSegments","every","i","startsWith","Number","isInteger","decodeURIComponent","searchParams","URLSearchParams","search","event","anchor","composedPath","elem","tagName","hasAttribute","e","defaultPrevented","metaKey","ctrlKey","shiftKey","target","getAttribute","href","origin","shouldRouterHandleClick","preventDefault","toggleParam","checkbox","value","outerHTML","checked","has","set","delete","newUrl","size","toString"],"mappings":"AAMO,MAiCMA,EAAoBC,KAC/BA,EAAMA,EAAIC,QACDC,SAAS,OAChBF,GAAY,KAGPA,GChCM,MAAMG,EAMpBC,GAAmB,qBACnBC,IAAW,EACXC,GAAoB,GAEpBC,aAAe,GAMfC,cAAgB,KAChBC,eAAiB,CAAA,EAEjBC,YAAc,GAMdC,aAAe,KACfC,cAAgB,CAAA,EAOhBC,YAAYC,GACX,MAAMV,gBAAEA,GAAoBU,GAAU,GAElCV,IACHW,MAAKX,EAAmBA,GAQzBW,KAAKC,QAAU,GAGfC,OAAOC,iBAAiB,WAAYH,KAAKI,WAAWC,KAAKL,OACzDM,SAASC,KAAKJ,iBAAiB,QAASH,KAAKQ,aAAaH,KAAKL,MAC/D,CAMDS,QACCT,KAAKI,YACL,CAODM,MAAMC,GACa,mBAAPA,GACVX,M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