{
  "version": 3,
  "sources": ["trip_route_profile.js"],
  "sourcesContent": ["/*\n * static/js/trip_route_profile.js \u2014 draws a route's profile on a trip page\n * (SNOW-1215).\n *\n * Finds every `[data-trip-route-profile]` and draws the route named by its\n * `data-payload` \u2014 the id of a `json_script` block whose `route` key is a\n * route Feature \u2014 with route_profile.js, the drawing the map's route\n * panel uses. The Plan page's route card is the first caller; it reads the\n * meeting picker's payload, which already carries the route.\n *\n * THE PLAN PAGE PLACES NO POINT: it is for choosing, not for reading\n * terrain, so its profile is the drawing alone.\n *\n * THE TRIP PAGE DOES (SNOW-1216). A profile marked `data-trip-route-scrub`\n * takes a press or a drag anywhere on the lane: the point follows the\n * pointer's x for as long as it is held, with any pointer, and stays where\n * it was let go. Each placement draws the profile's cursor line and\n * readout and is announced as a `trip:route-cursor` event on the document,\n * `{index}`, which trip_map.js draws on the line. Unlike the map's panel\n * (route_rail.js) there is no \"a tap must be on the outline\" rule and no\n * click to swallow: nothing else on this lane answers a press. The lane\n * is `touch-action: pan-y`, so a vertical swipe still scrolls the page.\n *\n * Publishes (frozen `window.pwaTripRouteProfile`), for tests:\n *\n *   bindScrub(view, lane) \u2014 wire one drawn profile's presses\n */\n\n(function tripRouteProfileInit() {\n  'use strict';\n\n  // Server-translated copy; the literals are the English fallback (see\n  // static/js/i18n_strings.js).\n  var PROFILE_STRINGS = {\n    'unit-m': '%(value)s m',\n    'unit-km': '%(value)s km',\n    'lane-label': 'Elevation profile of %(name)s',\n  };\n\n  /**\n   * Draw one profile from its payload.\n   *\n   * @param {HTMLElement} root The `[data-trip-route-profile]` element.\n   * @param {Object<string, string>} strings The profile's copy.\n   */\n  function drawOne(root, strings) {\n    var source = document.getElementById(root.dataset.payload || '');\n    if (!source) return;\n    var payload;\n    try {\n      payload = JSON.parse(source.textContent || 'null');\n    } catch (_err) {\n      return;\n    }\n    var feature = payload && payload.route;\n    if (!feature) return;\n    var view = self.pwaRouteProfile.mount(root, strings);\n    if (!view) return;\n    var read = self.pwaRouteProfile.read(feature);\n    view.draw(read.profile, read.legs, read.sampleCount, read.spanM, root.dataset.name || '');\n    if (root.hasAttribute('data-trip-route-scrub')) bindScrub(view, view.lane);\n  }\n\n  /**\n   * Place the point at a sample index, on the profile and (by the event)\n   * on the map.\n   *\n   * @param {{cursor: function(?number): void}} view The drawn profile.\n   * @param {?number} index The index, or null.\n   */\n  function place(view, index) {\n    view.cursor(index);\n    document.dispatchEvent(new CustomEvent('trip:route-cursor', { detail: { index: index } }));\n  }\n\n  /**\n   * Wire a drawn profile's presses: a press places the point and a drag\n   * moves it.\n   *\n   * @param {{cursor: function(?number): void, indexAt: function(number): ?number}} view\n   * @param {Element} lane The view's lane.\n   */\n  function bindScrub(view, lane) {\n    /** The pointer holding the point, or null. @type {?number} */\n    var held = null;\n    var last = null;\n\n    /** @param {number} clientX */\n    function follow(clientX) {\n      var index = view.indexAt(clientX);\n      if (index === null || index === last) return;\n      last = index;\n      place(view, index);\n    }\n\n    lane.addEventListener('pointerdown', function (event) {\n      var press = /** @type {PointerEvent} */ (event);\n      if (press.isPrimary === false || press.button !== 0) return;\n      held = press.pointerId;\n      if (lane.setPointerCapture) {\n        try {\n          lane.setPointerCapture(press.pointerId);\n        } catch (_err) {\n          // A synthetic or already-released pointer cannot be captured.\n        }\n      }\n      follow(press.clientX);\n    });\n    lane.addEventListener('pointermove', function (event) {\n      var move = /** @type {PointerEvent} */ (event);\n      if (held === move.pointerId) follow(move.clientX);\n    });\n    ['pointerup', 'pointercancel', 'lostpointercapture'].forEach(function (type) {\n      lane.addEventListener(type, function (event) {\n        if (held === /** @type {PointerEvent} */ (event).pointerId) held = null;\n      });\n    });\n    /** @type {HTMLElement} */ (lane).style.cursor = 'ew-resize';\n  }\n\n  /** Draw every profile on the page. */\n  function init() {\n    if (!self.pwaRouteProfile || !self.pwaRouteRailCore || !self.pwaElevationProfileCore) return;\n    var strings = self.pwaStrings.read('route-profile-strings-template', PROFILE_STRINGS);\n    document.querySelectorAll('[data-trip-route-profile]').forEach(function (root) {\n      drawOne(/** @type {HTMLElement} */ (root), strings);\n    });\n  }\n\n  self.pwaTripRouteProfile = Object.freeze({ bindScrub: bindScrub });\n\n  if (document.readyState === 'loading') {\n    document.addEventListener('DOMContentLoaded', init);\n  } else {\n    init();\n  }\n})();\n"],
  "mappings": "CA4BC,UAAgC,CAC/B,aAIA,IAAIA,EAAkB,CACpB,SAAU,cACV,UAAW,eACX,aAAc,+BAChB,EAQA,SAASC,EAAQC,EAAMC,EAAS,CAC9B,IAAIC,EAAS,SAAS,eAAeF,EAAK,QAAQ,SAAW,EAAE,EAC/D,GAAKE,EACL,KAAIC,EACJ,GAAI,CACFA,EAAU,KAAK,MAAMD,EAAO,aAAe,MAAM,CACnD,MAAe,CACb,MACF,CACA,IAAIE,EAAUD,GAAWA,EAAQ,MACjC,GAAKC,EACL,KAAIC,EAAO,KAAK,gBAAgB,MAAML,EAAMC,CAAO,EACnD,GAAKI,EACL,KAAIC,EAAO,KAAK,gBAAgB,KAAKF,CAAO,EAC5CC,EAAK,KAAKC,EAAK,QAASA,EAAK,KAAMA,EAAK,YAAaA,EAAK,MAAON,EAAK,QAAQ,MAAQ,EAAE,EACpFA,EAAK,aAAa,uBAAuB,GAAGO,EAAUF,EAAMA,EAAK,IAAI,IAC3E,CASA,SAASG,EAAMH,EAAMI,EAAO,CAC1BJ,EAAK,OAAOI,CAAK,EACjB,SAAS,cAAc,IAAI,YAAY,oBAAqB,CAAE,OAAQ,CAAE,MAAOA,CAAM,CAAE,CAAC,CAAC,CAC3F,CASA,SAASF,EAAUF,EAAMK,EAAM,CAE7B,IAAIC,EAAO,KACPC,EAAO,KAGX,SAASC,EAAOC,EAAS,CACvB,IAAIL,EAAQJ,EAAK,QAAQS,CAAO,EAC5BL,IAAU,MAAQA,IAAUG,IAChCA,EAAOH,EACPD,EAAMH,EAAMI,CAAK,EACnB,CAEAC,EAAK,iBAAiB,cAAe,SAAUK,EAAO,CACpD,IAAIC,EAAqCD,EACzC,GAAI,EAAAC,EAAM,YAAc,IAASA,EAAM,SAAW,GAElD,IADAL,EAAOK,EAAM,UACTN,EAAK,kBACP,GAAI,CACFA,EAAK,kBAAkBM,EAAM,SAAS,CACxC,MAAe,CAEf,CAEFH,EAAOG,EAAM,OAAO,EACtB,CAAC,EACDN,EAAK,iBAAiB,cAAe,SAAUK,EAAO,CACpD,IAAIE,EAAoCF,EACpCJ,IAASM,EAAK,WAAWJ,EAAOI,EAAK,OAAO,CAClD,CAAC,EACD,CAAC,YAAa,gBAAiB,oBAAoB,EAAE,QAAQ,SAAUC,EAAM,CAC3ER,EAAK,iBAAiBQ,EAAM,SAAUH,EAAO,CACvCJ,IAAsCI,EAAO,YAAWJ,EAAO,KACrE,CAAC,CACH,CAAC,EAC2BD,EAAM,MAAM,OAAS,WACnD,CAGA,SAASS,GAAO,CACd,GAAI,GAAC,KAAK,iBAAmB,CAAC,KAAK,kBAAoB,CAAC,KAAK,yBAC7D,KAAIlB,EAAU,KAAK,WAAW,KAAK,iCAAkCH,CAAe,EACpF,SAAS,iBAAiB,2BAA2B,EAAE,QAAQ,SAAUE,EAAM,CAC7ED,EAAoCC,EAAOC,CAAO,CACpD,CAAC,EACH,CAEA,KAAK,oBAAsB,OAAO,OAAO,CAAE,UAAWM,CAAU,CAAC,EAE7D,SAAS,aAAe,UAC1B,SAAS,iBAAiB,mBAAoBY,CAAI,EAElDA,EAAK,CAET,GAAG",
  "names": ["PROFILE_STRINGS", "drawOne", "root", "strings", "source", "payload", "feature", "view", "read", "bindScrub", "place", "index", "lane", "held", "last", "follow", "clientX", "event", "press", "move", "type", "init"]
}
