npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vehicle-path2

v1.0.10

Published

Vehicle motion simulator library for dual-axle vehicle movement along paths composed of lines and Bezier curves

Readme

vehicle-path2

Library untuk simulasi pergerakan kendaraan dual-axle sepanjang jalur.

Instalasi

npm install vehicle-path2

Quick Start

import { useVehicleSimulation } from 'vehicle-path2/react'

function App() {
  const sim = useVehicleSimulation({ wheelbase: 30 })

  // Buat jalur
  sim.addLine({ id: 'line1', start: [0, 0], end: [400, 0] })
  sim.addLine({ id: 'line2', start: [400, 0], end: [400, 300] })
  sim.connect('line1', 'line2')

  // Tambah kendaraan
  sim.addVehicles({ id: 'v1', lineId: 'line1', position: 0 })

  // Gerakkan ke tujuan
  sim.goto({ id: 'v1', lineId: 'line2', position: 1.0 })

  // Jalankan animasi
  sim.prepare()
  sim.tick(5) // panggil di animation loop
}

API

Format Posisi

Semua nilai posisi menggunakan format 0-1 untuk persentase:

  • 0 = 0% (awal line)
  • 0.5 = 50% (tengah line)
  • 1 = 100% (ujung line)

Untuk posisi absolut (dalam satuan koordinat), gunakan isPercentage: false.

Setup

const sim = useVehicleSimulation({
  wheelbase: 30,                    // jarak antar roda
  tangentMode: 'proportional-40'    // mode kurva (opsional)
})

Scene

sim.addLine({ id: 'line1', start: [0, 0], end: [400, 0] })
sim.updateLine('line1', { end: [500, 100] })
sim.removeLine('line1')
sim.clearScene()

Koneksi

sim.connect('line1', 'line2')
sim.connect('line1', 'line2', { fromOffset: 0.8, toOffset: 0.2 })
sim.connect('line1', 'line2', { fromOffset: 150, fromIsPercentage: false, toOffset: 50, toIsPercentage: false })
sim.updateConnection('line1', 'line2', { fromOffset: 0.5 })              // update offset
sim.updateConnection('line1', 'line2', { toOffset: 100, toIsPercentage: false }) // absolute
sim.disconnect('line1', 'line2')

Kendaraan

sim.addVehicles({ id: 'v1', lineId: 'line1', position: 0 })
sim.addVehicles({ id: 'v2', lineId: 'line1', position: 150, isPercentage: false }) // absolute
sim.updateVehicle('v1', { position: 0.5 })                    // pindah ke 50%
sim.updateVehicle('v1', { lineId: 'line2' })                  // pindah ke line lain
sim.updateVehicle('v1', { lineId: 'line2', position: 0.8 })   // pindah ke 80% di line2
sim.removeVehicle('v1')
sim.clearVehicles()

Pergerakan

sim.goto({ id: 'v1', lineId: 'line2' })                // default position = 1.0 (ujung)
sim.goto({ id: 'v1', lineId: 'line2', position: 0.5 }) // 0.5 = tengah line
sim.goto({ id: 'v1', lineId: 'line2', position: 150, isPercentage: false }) // absolute
sim.goto({ id: 'v1', lineId: 'line2', position: 0.5, wait: true })          // berhenti di tujuan
sim.goto({ id: 'v1', lineId: 'line2', payload: { orderId: '123' } })        // dengan payload
sim.clearQueue('v1')

Animasi

sim.prepare()              // siapkan sebelum animasi
sim.tick(5)                // gerakkan 5 pixel per tick
sim.reset()                // kembali ke posisi awal
sim.isMoving()             // cek ada yang bergerak
sim.continueVehicle('v1')  // lanjutkan vehicle yang wait

Load dari DSL

sim.loadFromDSL(`
  line1 : (0, 0) -> (400, 0)
  line2 : (400, 0) -> (400, 300)
  line1 -> line2
`)

State

sim.lines          // semua line
sim.curves         // semua koneksi
sim.vehicles       // kendaraan (posisi awal)
sim.movingVehicles // kendaraan (posisi saat animasi)

Contoh Lengkap

import { useVehicleSimulation } from 'vehicle-path2/react'
import { useEffect } from 'react'

function AnimatedVehicle() {
  const sim = useVehicleSimulation({ wheelbase: 30 })

  useEffect(() => {
    sim.addLine({ id: 'line1', start: [100, 100], end: [500, 100] })
    sim.addVehicles({ id: 'v1', lineId: 'line1', position: 0 })
    sim.goto({ id: 'v1', lineId: 'line1', position: 1.0 })
    sim.prepare()

    const animate = () => {
      if (sim.tick(3)) {
        requestAnimationFrame(animate)
      }
    }
    requestAnimationFrame(animate)
  }, [])

  return (
    <svg width={600} height={200}>
      {sim.movingVehicles.map(v => (
        <circle
          key={v.id}
          cx={v.rear.position.x}
          cy={v.rear.position.y}
          r={10}
          fill="blue"
        />
      ))}
    </svg>
  )
}

License

MIT