{
  "element": "nve-joystick",
  "entrypoint": "@nvidia-elements/core/joystick/joystick.examples.json",
  "items": [
    {
      "id": "joystick",
      "name": "Default",
      "template": "<nve-joystick aria-label=\"Movement\"></nve-joystick>\n",
      "summary": "Select a direction and intensity with a circular movement region. Release the pointer or arrow keys to return to center.",
      "description": "Both axes use normalized values from -1 to 1. Applications can derive length with Math.hypot(x, y) and angle with Math.atan2(-y, x). This angle uses radians from the rightward direction with counterclockwise positive rotation. Use undefined at neutral. Keep these derived quantities outside the writable value. The angle does not describe the robot's heading.",
      "composition": false,
      "tags": []
    },
    {
      "id": "joystick-size",
      "name": "Size",
      "template": "<div nve-layout=\"row gap:lg align:wrap\">\n  <nve-joystick aria-label=\"Small movement\" size=\"sm\"></nve-joystick>\n  <nve-joystick aria-label=\"Medium movement\" size=\"md\"></nve-joystick>\n  <nve-joystick aria-label=\"Large movement\" size=\"lg\"></nve-joystick>\n</div>\n",
      "summary": "Choose small, medium, or large controls to fit the available space. Each size scales the movement surface and thumb together.",
      "description": "",
      "composition": false,
      "tags": []
    },
    {
      "id": "joystick-opacity",
      "name": "Opacity",
      "template": "<div\n  nve-layout=\"row align:center pad:lg\"\n  style=\"width: 100%; min-height: 16rem; background: repeating-conic-gradient(var(--nve-sys-layer-container-background) 0% 25%, var(--nve-sys-layer-canvas-background) 0% 50%) center / 2rem 2rem\"\n>\n  <nve-joystick aria-label=\"Movement\" opacity></nve-joystick>\n</div>\n",
      "summary": "Overlay a joystick with a translucent background on a checkered scene. Keep the border and thumb at full opacity for contrast.",
      "description": "",
      "composition": false,
      "tags": [
        "theme"
      ]
    },
    {
      "id": "joystick-constraints",
      "name": "Constraints",
      "template": "<div nve-layout=\"row gap:lg align:wrap\">\n  <nve-joystick aria-label=\"Circular movement\"></nve-joystick>\n  <nve-joystick aria-label=\"Independent axes\" constraint=\"square\"></nve-joystick>\n  <nve-joystick aria-label=\"Turn\" constraint=\"horizontal\"></nve-joystick>\n  <nve-joystick aria-label=\"Vertical movement\" constraint=\"vertical\"></nve-joystick>\n</div>\n",
      "summary": "Compare circular, square, and single-axis movement regions. Choose a constraint that matches the available commands.",
      "description": "Circle bounds normalized magnitude to one. Square allows independent full-scale axes and a magnitude of up to Math.SQRT2. Use circle for planar direction and intensity, or square for independent limits such as forward velocity and turning rate. Equally scaled planar velocity axes can produce about 41% greater diagonal speed with square input.",
      "composition": false,
      "tags": []
    },
    {
      "id": "joystick-hold",
      "name": "Hold",
      "template": "<nve-joystick aria-label=\"Persistent target\" release=\"hold\"></nve-joystick>\n",
      "summary": "Keep the last position after release for persistent target selection. Press Escape during an interaction to return to center.",
      "description": "",
      "composition": false,
      "tags": []
    },
    {
      "id": "joystick-states",
      "name": "States",
      "template": "<div nve-layout=\"row gap:lg align:wrap\">\n  <nve-joystick aria-label=\"Recorded input\" readonly value='{\"x\":0.4,\"y\":-0.6}'></nve-joystick>\n  <nve-joystick aria-label=\"Unavailable control\" disabled></nve-joystick>\n</div>\n",
      "summary": "Display recorded input without generating control events. Use read-only state for inspection and disabled state for unavailable controls.",
      "description": "Set readOnly to true before assigning recorded vectors through .value. Use undefined for an absent sample and a zero vector for recorded neutral input. The recording layer captures source, sample time, engagement transitions, and mapping configuration. Preserve its clock during replay and avoid applying input shaping to recorded samples again.",
      "composition": false,
      "tags": []
    },
    {
      "id": "joystick-travel-turn",
      "name": "TravelTurn",
      "template": "<div id=\"joystick-travel-turn\" nve-layout=\"column gap:lg\">\n  <div nve-layout=\"row gap:lg align:wrap\">\n    <div nve-layout=\"column gap:sm\">\n      <label for=\"joystick-travel\">Travel</label>\n      <nve-joystick id=\"joystick-travel\" constraint=\"square\"></nve-joystick>\n      <output data-travel style=\"width: 170px\">Released: x 0.00, y 0.00</output>\n    </div>\n    <div nve-layout=\"column gap:sm\">\n      <label for=\"joystick-turn\">Turn</label>\n      <nve-joystick id=\"joystick-turn\" constraint=\"horizontal\"></nve-joystick>\n      <output data-turn>Released: x 0.00, y 0.00</output>\n    </div>\n  </div>\n  <output data-command>vx 0.00 m/s, vy 0.00 m/s, wz 0.00 rad/s</output>\n</div>\n<script type=\"module\">\n  const group = document.querySelector(\"#joystick-travel-turn\");\n  const travel = group.querySelector(\"#joystick-travel\");\n  const turn = group.querySelector(\"#joystick-turn\");\n  const maxForwardMps = 1;\n  const maxLateralMps = 0.5;\n  const maxYawRadps = 1;\n\n  function describe(control) {\n    const value = control.value;\n    const state = control.matches(\":state(active)\") ? \"Engaged\" : \"Released\";\n    return state + \": \" + (value ? \"x \" + value.x.toFixed(2) + \", y \" + value.y.toFixed(2) : \"No sample\");\n  }\n\n  function update() {\n    group.querySelector(\"[data-travel]\").textContent = describe(travel);\n    group.querySelector(\"[data-turn]\").textContent = describe(turn);\n    const translation = travel.matches(\":state(active)\") ? travel.value : undefined;\n    const rotation = turn.matches(\":state(active)\") ? turn.value : undefined;\n    const command = {\n      vx: -(translation?.y ?? 0) * maxForwardMps,\n      vy: -(translation?.x ?? 0) * maxLateralMps,\n      wz: -(rotation?.x ?? 0) * maxYawRadps,\n    };\n    group.querySelector(\"[data-command]\").textContent = \"vx \" + command.vx.toFixed(2) + \" m/s, vy \" + command.vy.toFixed(2) + \" m/s, wz \" + command.wz.toFixed(2) + \" rad/s\";\n  }\n\n  for (const type of [\"input\", \"interaction-start\", \"interaction-end\"]) group.addEventListener(type, update);\n  await customElements.whenDefined(\"nve-joystick\");\n  update();\n</script>\n",
      "summary": "Map travel and turn input to body-frame velocities in meters and radians per second. Engage either joystick to update its command axes.",
      "description": "Input maps to ROS body axes: x-forward, y-left, z-up, with positive yaw counterclockwise. Travel uses square constraints for independent axis limits; use circle to bound normalized translation magnitude. The illustrative maxima are 1 m/s forward, 0.5 m/s lateral, and 1 rad/s yaw. Each control's :state(active) CSS custom state gates its displayed velocity. Interaction events refresh the readouts. The application chooses its limits and publishes the latest command at its own cadence, including while input remains stationary.",
      "composition": false,
      "tags": []
    },
    {
      "id": "joystick-input-shaping",
      "name": "InputShaping",
      "template": "<div id=\"joystick-shaping\" nve-layout=\"column gap:md\">\n  <nve-joystick aria-label=\"Movement\" constraint=\"circle\"></nve-joystick>\n  <nve-range>\n    <label for=\"joystick-deadzone\">Dead zone</label>\n    <input id=\"joystick-deadzone\" type=\"range\" min=\"0\" max=\"0.5\" step=\"0.01\" value=\"0\" />\n  </nve-range>\n  <nve-range>\n    <label for=\"joystick-response\">Response exponent</label>\n    <input id=\"joystick-response\" type=\"range\" min=\"1\" max=\"3\" step=\"0.1\" value=\"1\" />\n  </nve-range>\n  <output data-settings>Dead zone 0.00, response 1.0</output>\n  <output data-raw>Raw: x 0.00, y 0.00</output>\n  <output data-shaped>Shaped: x 0.00, y 0.00</output>\n</div>\n<script type=\"module\">\n  const group = document.querySelector(\"#joystick-shaping\");\n  const joystick = group.querySelector(\"nve-joystick\");\n  const deadzone = group.querySelector(\"#joystick-deadzone\");\n  const response = group.querySelector(\"#joystick-response\");\n\n  function shape(value, deadzone, exponent) {\n    const magnitude = Math.hypot(value.x, value.y);\n    if (magnitude <= deadzone) return { x: 0, y: 0 };\n    const strength = ((magnitude - deadzone) / (1 - deadzone)) ** exponent;\n    return { x: (value.x / magnitude) * strength, y: (value.y / magnitude) * strength };\n  }\n\n  function update() {\n    const raw = joystick.value ?? { x: 0, y: 0 };\n    const shaped = shape(raw, deadzone.valueAsNumber, response.valueAsNumber);\n    group.querySelector(\"[data-settings]\").textContent = \"Dead zone \" + deadzone.valueAsNumber.toFixed(2) + \", response \" + response.valueAsNumber.toFixed(1);\n    group.querySelector(\"[data-raw]\").textContent = \"Raw: x \" + raw.x.toFixed(2) + \", y \" + raw.y.toFixed(2);\n    group.querySelector(\"[data-shaped]\").textContent = \"Shaped: x \" + shaped.x.toFixed(2) + \", y \" + shaped.y.toFixed(2);\n  }\n\n  group.addEventListener(\"input\", update);\n  await customElements.whenDefined(\"nve-joystick\");\n  update();\n</script>\n",
      "summary": "Adjust a radial dead zone and response curve before mapping input to commands. Compare the shaped vector with the unchanged joystick value.",
      "description": "A dead zone of zero and response exponent of one leave circular input unchanged. The dead zone makes neutral easier to select; a larger exponent provides finer control near neutral. The remaining range scales back to full output at the boundary and preserves direction. Shaping produces a separate command vector without rewriting .value. Map it to physical units afterward. Apply filtering in one input layer to avoid processing hardware or recorded samples twice. [ROS joystick parameters](https://github.com/ros-drivers/joystick_drivers/blob/ros2/joy/README.md)",
      "composition": false,
      "tags": []
    },
    {
      "id": "joystick-form",
      "name": "Form",
      "template": "<form nve-layout=\"column gap:md\">\n  <label for=\"joystick-form\">Target</label>\n  <nve-joystick id=\"joystick-form\" name=\"target\" release=\"hold\" value='{\"x\":0.2,\"y\":-0.3}'></nve-joystick>\n  <nve-button type=\"reset\">Reset target</nve-button>\n</form>\n",
      "summary": "Submit both axes as separate named fields and restore the declared position with form reset. Use held values when selecting persistent form targets.",
      "description": "",
      "composition": false,
      "tags": []
    },
    {
      "id": "joystick-accessible-feedback",
      "name": "AccessibleFeedback",
      "template": "<nve-joystick aria-label=\"Movement\" i18n='{\"joystickPosition\":\"Horizontal {x}, vertical {y}.\"}'></nve-joystick>\n",
      "summary": "Override joystickPosition through i18n to localize spoken coordinates while keeping built-in position announcements.",
      "description": "",
      "composition": false,
      "tags": []
    },
    {
      "id": "joystick-external-feedback",
      "name": "ExternalFeedback",
      "template": "<div id=\"joystick-external-feedback\" nve-layout=\"column gap:md\">\n  <nve-joystick aria-label=\"Target\" announce=\"off\" release=\"hold\"></nve-joystick>\n  <output aria-live=\"polite\" aria-atomic=\"true\">Target: X 0, Y 0</output>\n</div>\n<script type=\"module\">\n  const root = document.querySelector(\"#joystick-external-feedback\");\n  const joystick = root.querySelector(\"nve-joystick\");\n  const output = root.querySelector(\"output\");\n  joystick.addEventListener(\"change\", () => {\n    const value = joystick.value;\n    output.textContent = value ? \"Target: X \" + value.x + \", Y \" + value.y : \"No target\";\n  });\n</script>\n",
      "summary": "Supply application announcements with a labeled output. Disable built-in announcements to avoid duplicate feedback.",
      "description": "",
      "composition": false,
      "tags": []
    }
  ]
}