{
  "version": 3,
  "sources": ["route_lifts_core.js"],
  "sourcesContent": ["/*\n * static/js/route_lifts_core.js \u2014 a recorded route's lift rides, on the map,\n * the profile and the point card (SNOW-994).\n *\n * A route uploaded from a lift-served day carries `lift_ranges`: each ride\n * found at upload (track/lifts.py), in the two index spaces a leg is sent\n * in (track/lift_wire.py) \u2014 `from`/`to`, the first and last 25 m slope\n * segment, both inclusive, which the profile and the point card read; and\n * `point_from`/`point_to`, the feature's own coordinates, which the map\n * slices the lift line from. `kind` is the lift's kind when the map has\n * named it, or null; `duration_s` is the time on it.\n *\n * This module is the pure half: what to draw, and which ride a cursor is\n * on. The map's layers are route_drawing_core.js's, the profile's band\n * elevation_profile_core.js's, and the card route_point_card_core.js's.\n *\n * Hex literal for MapLibre, which cannot read a custom property: it mirrors\n * `--color-route-lift` in `src/css/main.css`.\n *\n * Exports (frozen `self.pwaRouteLiftsCore`):\n *\n *   LIFT_COLOUR               \u2014 the lift line and station ring\n *   KINDS                     \u2014 the four kinds a ride can be named\n *   liftCollection(fc)        \u2014 one LineString per ride and a Point at\n *                               each of its two stations,\n *                               `{uuid | token, i, kind, role}`\n *   ranges(properties)        \u2014 a feature's usable lift ranges\n *   rangeAt(ranges, index)    \u2014 the ride a segment index is on, or null\n *   hasLifts(fc)              \u2014 whether any route in a payload has a ride\n */\n\n// @ts-check\n\n(function () {\n  'use strict';\n\n  /** Mirrors `--color-route-lift`. */\n  const LIFT_COLOUR = '#0d9488';\n\n  /** The kinds the server names a ride (apps/routes/services/lift_kinds.py). */\n  const KINDS = Object.freeze(['cable_car', 'gondola', 'chair_lift', 'drag_lift']);\n\n  /**\n   * One ride as it arrives on the wire, checked rather than trusted.\n   *\n   * @typedef {object} WireLift\n   * @property {number} [i] Its 1-based number.\n   * @property {number} [from] Its first slope segment, inclusive.\n   * @property {number} [to] Its last slope segment, inclusive.\n   * @property {number} [point_from] Its first coordinate index.\n   * @property {number} [point_to] Its last coordinate index, inclusive.\n   * @property {?string} [kind] One of KINDS, or null.\n   * @property {number} [duration_s] Seconds on the lift.\n   */\n\n  /**\n   * @typedef {{type: string, features: Array<object>}} FeatureCollection\n   */\n\n  /**\n   * An empty FeatureCollection \u2014 `setData` throws on a null.\n   *\n   * @returns {FeatureCollection}\n   */\n  function empty() {\n    return { type: 'FeatureCollection', features: [] };\n  }\n\n  /**\n   * Whether a value is a usable, non-negative integer index.\n   *\n   * @param {*} value\n   * @returns {boolean}\n   */\n  function isIndex(value) {\n    return Number.isInteger(value) && value >= 0;\n  }\n\n  /**\n   * A feature's lift ranges, keeping only those whose segment indexes\n   * hold together. A kind outside KINDS reads as unknown.\n   *\n   * @param {any} properties A route feature's properties.\n   * @returns {Array<WireLift>}\n   */\n  function ranges(properties) {\n    const raw = properties && properties.lift_ranges;\n    if (!Array.isArray(raw)) return [];\n    return raw\n      .filter((range) => range && isIndex(range.from) && isIndex(range.to)\n        && range.from <= range.to)\n      .map((range) => Object.assign({}, range, {\n        kind: KINDS.includes(range.kind) ? range.kind : null,\n      }));\n  }\n\n  /**\n   * The ride a slope-segment index is on, both ends inclusive.\n   *\n   * @param {Array<WireLift>} lifts A feature's `ranges`.\n   * @param {number} index A segment index.\n   * @returns {?WireLift}\n   */\n  function rangeAt(lifts, index) {\n    if (!Array.isArray(lifts) || !Number.isFinite(index)) return null;\n    for (const lift of lifts) {\n      if (/** @type {number} */ (lift.from) <= index\n        && index <= /** @type {number} */ (lift.to)) {\n        return lift;\n      }\n    }\n    return null;\n  }\n\n  /**\n   * What a route's drawn features carry to name it: its `uuid`, or a\n   * pending share's `token`, as route_legs_core.js's legs do.\n   *\n   * @param {any} properties\n   * @returns {{uuid?: string, token?: string}}\n   */\n  function routeIdentity(properties) {\n    if (properties.uuid) return { uuid: String(properties.uuid) };\n    if (properties.token) return { token: String(properties.token) };\n    return {};\n  }\n\n  /**\n   * One LineString per ride and a Point at each of its stations.\n   *\n   * The line is `coordinates[point_from..point_to]`, both inclusive; a\n   * ride whose indexes do not slice the geometry is left out. The two\n   * stations carry `role: 'station'`, the line `role: 'line'`, so one\n   * source feeds the line layer and the ring layer.\n   *\n   * @param {?{features?: Array<any>}} geojson The routes FeatureCollection.\n   * @returns {FeatureCollection}\n   */\n  function liftCollection(geojson) {\n    const out = empty();\n    const features = (geojson && geojson.features) || [];\n    for (const feature of features) {\n      const properties = (feature && feature.properties) || {};\n      const coordinates = feature && feature.geometry && feature.geometry.coordinates;\n      if (!Array.isArray(coordinates)) continue;\n      for (const lift of ranges(properties)) {\n        const first = lift.point_from;\n        const last = lift.point_to;\n        if (!isIndex(first) || !isIndex(last)) continue;\n        if (/** @type {number} */ (first) >= /** @type {number} */ (last)) continue;\n        if (/** @type {number} */ (last) >= coordinates.length) continue;\n        const line = coordinates.slice(first, /** @type {number} */ (last) + 1);\n        const base = Object.assign({ i: lift.i, kind: lift.kind }, routeIdentity(properties));\n        out.features.push({\n          type: 'Feature',\n          geometry: { type: 'LineString', coordinates: line },\n          properties: Object.assign({ role: 'line' }, base),\n        });\n        for (const point of [line[0], line[line.length - 1]]) {\n          out.features.push({\n            type: 'Feature',\n            geometry: { type: 'Point', coordinates: [point[0], point[1]] },\n            properties: Object.assign({ role: 'station' }, base),\n          });\n        }\n      }\n    }\n    return out;\n  }\n\n  /**\n   * Whether any route in a payload carries a ride.\n   *\n   * @param {?{features?: Array<any>}} geojson\n   * @returns {boolean}\n   */\n  function hasLifts(geojson) {\n    const features = (geojson && geojson.features) || [];\n    return features.some((feature) => ranges(feature && feature.properties).length > 0);\n  }\n\n  self.pwaRouteLiftsCore = Object.freeze({\n    LIFT_COLOUR: LIFT_COLOUR,\n    KINDS: KINDS,\n    liftCollection: liftCollection,\n    ranges: ranges,\n    rangeAt: rangeAt,\n    hasLifts: hasLifts,\n  });\n})();\n"],
  "mappings": "CAiCC,UAAY,CACX,aAGA,MAAMA,EAAc,UAGdC,EAAQ,OAAO,OAAO,CAAC,YAAa,UAAW,aAAc,WAAW,CAAC,EAwB/E,SAASC,GAAQ,CACf,MAAO,C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CAAI,GACTD,GAAiCC,GACjCA,GAASF,EAAY,OAAQ,SACxD,MAAMG,EAAOH,EAAY,MAAMC,EAA8BC,EAAQ,CAAC,EAChEE,EAAO,OAAO,OAAO,CAAE,EAAGX,EAAK,EAAG,KAAMA,EAAK,IAAK,EAAGC,EAAcP,CAAU,CAAC,EACpFU,EAAI,SAAS,KAAK,CAChB,KAAM,UACN,SAAU,CAAE,KAAM,aAAc,YAAaM,CAAK,EAClD,WAAY,OAAO,OAAO,CAAE,KAAM,MAAO,EAAGC,CAAI,CAClD,CAAC,EACD,UAAWC,IAAS,CAACF,EAAK,CAAC,EAAGA,EAAKA,EAAK,OAAS,CAAC,CAAC,EACjDN,EAAI,SAAS,KAAK,CAChB,KAAM,UACN,SAAU,CAAE,KAAM,QAAS,YAAa,CAACQ,EAAM,CAAC,EAAGA,EAAM,CAAC,CAAC,CAAE,EAC7D,WAAY,OAAO,OAAO,CAAE,KAAM,SAAU,EAAGD,CAAI,CACrD,CAAC,CAEL,CACF,CACA,OAAOP,CACT,CAQA,SAASS,EAASV,EAAS,CAEzB,OADkBA,GAAWA,EAAQ,UAAa,CAAC,GACnC,KAAMG,GAAYb,EAAOa,GAAWA,EAAQ,UAAU,EAAE,OAAS,CAAC,CACpF,CAEA,KAAK,kBAAoB,OAAO,OAAO,CACrC,YAAalB,EACb,MAAOC,EACP,eAAgBa,EAChB,OAAQT,EACR,QAASI,EACT,SAAUgB,CACZ,CAAC,CACH,GAAG",
  "names": ["LIFT_COLOUR", "KINDS", "empty", "isIndex", "value", "ranges", "properties", "raw", "range", "rangeAt", "lifts", "index", "lift", "routeIdentity", "liftCollection", "geojson", "out", "features", "feature", "coordinates", "first", "last", "line", "base", "point", "hasLifts"]
}
