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AC5B,UAAd,EAAK,MAAyB,EAAK,MAAM,KAAK,GAEpD,CFnDO,SAAS,eACd,OAAO,IAAI,UACb,CAEA,IAAM,WAAN,MACE,WAAA,GACE,KAAK,OAAS,GAKd,OAAO,iBAAiB,cAHJ,GAAM,kBAAkB,EAAI,KAAK,UAGF,GACnD,OAAO,iBAAiB,QAHJ,GAAM,kBAAkB,EAAI,KAAK,QAAQ,KAGhB,EAC/C,CAEA,GAAA,CAAI,EAAM,GACR,KAAK,OAAO,KAAK,CAAC,MAAO,IAAI,MAAM,GAAO,WAC5C,CAEA,EAAA,CAAG,GACD,EAAW,IAAM,UAAU,GAC3B,MACM,EADO,UAAS,gBAAgB,OAAO,SAAS,KAAM,KACxC,EACpB,OAAO,QAAQ,UAAU,KAAM,KAAM,GACrC,OAAO,SAAS,KAAO,CACzB,GAIF,SAAS,kBAAkB,EAAI,EAAQ,GAAS,GAC9C,MAAM,EAAU,WAAW,EAAI,GAC/B,QAAgB,IAAZ,EAAuB,OAE3B,MAAM,EAAS,CAAC,EACV,EAAU,YAAY,EAAQ,EAAS,GACzC,GACF,EAAQ,EAAS,EAErB,CAEA,SAAS,WAAW,EAAI,GACtB,GAAI,EACF,OAAO,YAAY,EAAG,OAAO,SAAS,MAExC,MAAM,EAAU,YAAY,EAAG,QACzB,EAAU,YAAY,EAAG,QAE/B,OAAO,IAAY,OAAU,EAAY,CAC3C,CAEA,SAAS,YAAY,EAAQ,EAAM,GACjC,MAAM,EAAQ,EAAO,MAAK,GAAK,EAAE,MAAM,QAAQ,EAAM,KACrD,QAAO,GAAQ,EAAM,OACvB,Q","file":"/npm/@techexp/hash-router@0.3.2/dist/HashRouter-esm.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@techexp/hash-router@0.3.2/dist/HashRouter-esm.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import {Stringer} from '@techexp/jshelper'\nimport {cleanPath, getHashPath} from './utils/RouterUtils'\nimport {Route} from './utils/Route'\n\nexport function createRouter() {\n  return new HashRouter()\n}\n\nclass HashRouter {\n  constructor() {\n    this.routes = []\n\n    const hashHandler = ev => hashChangeHandler(ev, this.routes)\n    const loadHandler = ev => hashChangeHandler(ev, this.routes, true)\n\n    window.addEventListener('hashchange', hashHandler, false)\n    window.addEventListener('load', loadHandler, false)\n  }\n\n  add(path, handler) {\n    this.routes.push({route: new Route(path), handler})\n  }\n\n  go(hashPath) {\n    hashPath = '#' + cleanPath(hashPath)\n    const base = Stringer.substringBefore(window.location.href, '#')\n    const href = base + hashPath\n    window.history.pushState(null, null, hashPath)\n    window.location.href = href\n  }\n}\n\n\nfunction hashChangeHandler(ev, routes, isLoad = false) {\n  const newPath = getNewPath(ev, isLoad)\n  if (newPath === undefined) return\n\n  const params = {}\n  const handler = findHandler(routes, newPath, params)\n  if (handler) {\n    handler(newPath, params)\n  }\n}\n\nfunction getNewPath(ev, isLoad) {\n  if (isLoad) {\n    return getHashPath(ev.target.location.href)\n  }\n  const oldPath = getHashPath(ev.oldURL)\n  const newPath = getHashPath(ev.newURL)\n\n  return oldPath === newPath ? undefined : newPath\n}\n\nfunction findHandler(routes, path, params) {\n  const found = routes.find(r => r.route.isMatch(path, params))\n  return found ? found.handler : false\n}\n","import {Stringer} from '@techexp/jshelper'\n\nexport function getHashPath(href) {\n  href = Stringer.substringAfter(href, '#')\n  return cleanPath(href)\n}\n\nexport function cleanPath(path) {\n  return Stringer.strip(path, ' /#')\n}","import {cleanPath} from './RouterUtils'\n\nexport class Route {\n  constructor(path) {\n    this.parts = parsePath(path)\n  }\n\n  /**\n   * Check if given path matches this route\n   * @param {String} path\n   * @param {Object, optional} params An object to populate with path parameters and values\n   */\n  isMatch(path, params = {}) {\n    const pathItems = tokenizePath(path)\n    if (this.parts.length !== pathItems.length) return false\n\n    for (let i = 0; i < pathItems.length; i++) {\n      const part = this.parts[i]\n      const item = pathItems[i]\n      if (! isPartMatch(part, item)) return false\n\n      if (part.type === 'param') {\n        params[part.value] = item\n      }\n    }\n    return true\n  }\n}\n\n/** Return an array of objects {type: 'param|regex|string', value: 'Value of part'} */\nfunction parsePath(path) {\n  return tokenizePath(path).map(p => parsePart(p))\n}\n\nfunction tokenizePath(path) {\n  return cleanPath(path).split('/').map(p => p.trim()).filter(p => p.length > 0)\n}\n\nfunction parsePart(part) {\n  if (part.startsWith(':')) {\n    return {type: 'param', value: part.substring(1)}\n  }\n\n  if (part.startsWith('[') && part.endsWith(']')) {\n    const value = part.substring(1, part.length - 1)\n    return {type: 'regex', value: new RegExp(value)}\n  }\n  return {type: 'string', value: part}\n}\n\nfunction isPartMatch(part, s) {\n  if (part.type === 'param') return true\n  if (part.type === 'string') return s === part.value\n  if (part.type === 'regex') return part.value.test(s)\n  return false\n}\n"]}