{"_id":"@basementuniverse/view-port","_rev":"3-e6e7ad49731fb5a756060cbfe5fd632f","name":"@basementuniverse/view-port","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"@basementuniverse/view-port","version":"1.0.0","author":{"url":"https://gordonlarrigan.com","name":"Gordon Larrigan","email":"gordonlarrigan@gmail.com"},"license":"MIT","_id":"@basementuniverse/view-port@1.0.0","maintainers":[{"name":"basementuniverse","email":"gordonlarrigan@gmail.com"}],"homepage":"https://github.com/basementuniverse/view-port#readme","bugs":{"url":"https://github.com/basementuniverse/view-port/issues"},"dist":{"shasum":"81b13cf2c0e2a6baaa1e68f924913069cb3c821b","tarball":"https://registry.npmjs.org/@basementuniverse/view-port/-/view-port-1.0.0.tgz","fileCount":5,"integrity":"sha512-s9fHf0g2XTc5C9hhZtAW0I61JK/tXoqgpUwM1bAgeeFyxYu8h01bDOm+MoEOq3X4wl7OdQcJR99SYopt0YcQ+A==","signatures":[{"sig":"MEUCIBKrBHnU6anE/9XShRlcaKD+lkVVQlOzhiaND4n3NSU3AiEA1aSZWcpkvlSGNuHlKAGzHbacRRA9uaPqxfeJLm8miQM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":47194},"main":"build/index.js","types":"build/index.d.ts","gitHead":"9efef51c149e9e308a201abfac42a501f1001868","scripts":{"build":"webpack","watch":"webpack --watch"},"_npmUser":{"name":"basementuniverse","email":"gordonlarrigan@gmail.com"},"repository":{"url":"git+https://github.com/basementuniverse/view-port.git","type":"git"},"_npmVersion":"11.6.2","description":"A viewport into worldspace, for rendering chunks in games.","directories":{},"_nodeVersion":"24.12.0","dependencies":{"@basementuniverse/vec":"^2.5.0"},"_hasShrinkwrap":false,"devDependencies":{"webpack":"^5.3.2","ts-loader":"^8.0.7","typescript":"^4.9.4","@types/node":"^18.11.12","webpack-cli":"^4.1.0","clean-webpack-plugin":"^4.0.0-alpha.0"},"_npmOperationalInternal":{"tmp":"tmp/view-port_1.0.0_1773458608763_0.262158235694832","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@basementuniverse/view-port","version":"1.1.0","author":{"url":"https://gordonlarrigan.com","name":"Gordon Larrigan","email":"gordonlarrigan@gmail.com"},"license":"MIT","_id":"@basementuniverse/view-port@1.1.0","maintainers":[{"name":"basementuniverse","email":"gordonlarrigan@gmail.com"}],"homepage":"https://github.com/basementuniverse/view-port#readme","bugs":{"url":"https://github.com/basementuniverse/view-port/issues"},"dist":{"shasum":"16204a04646ff102dd886dfce17972f8fb64a9ef","tarball":"https://registry.npmjs.org/@basementuniverse/view-port/-/view-port-1.1.0.tgz","fileCount":5,"integrity":"sha512-xqHhojfXPsYA5Ni95T/id8Xb/uvhwNhzdZm+pd7Sedk4SWXkrXxYkTHB1/wmO8eVZTF/h/0rBG9Byk9PAndHig==","signatures":[{"sig":"MEUCIQC9N9TFZmZdpCgTpfCJJyUAkUxzYv/Q/Jb+Y2MoIX03mQIgRXp3+fCTTJ1PQeS/79Wym04IHI4Sn9O+SgnZcStbnKA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":47819},"main":"build/index.js","types":"build/index.d.ts","gitHead":"3b1210380a4d638d4b66504c4e15ee86965c77a4","scripts":{"build":"webpack","watch":"webpack --watch"},"_npmUser":{"name":"basementuniverse","email":"gordonlarrigan@gmail.com"},"repository":{"url":"git+https://github.com/basementuniverse/view-port.git","type":"git"},"_npmVersion":"11.6.2","description":"A viewport into worldspace, for rendering chunks in games.","directories":{},"_nodeVersion":"24.12.0","dependencies":{"@basementuniverse/vec":"^2.5.0"},"_hasShrinkwrap":false,"devDependencies":{"webpack":"^5.3.2","ts-loader":"^8.0.7","typescript":"^4.9.4","@types/node":"^18.11.12","webpack-cli":"^4.1.0","clean-webpack-plugin":"^4.0.0-alpha.0"},"_npmOperationalInternal":{"tmp":"tmp/view-port_1.1.0_1773852940501_0.9405973643634036","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"@basementuniverse/view-port","version":"1.2.0","description":"A viewport into worldspace, for rendering chunks in games.","author":{"name":"Gordon Larrigan","email":"gordonlarrigan@gmail.com","url":"https://gordonlarrigan.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/basementuniverse/view-port.git"},"main":"build/index.js","types":"build/index.d.ts","scripts":{"build":"webpack --mode production","build:dev":"webpack --mode development","watch":"webpack --watch"},"dependencies":{"@basementuniverse/vec":"^2.5.1"},"devDependencies":{"@types/node":"^18.11.12","clean-webpack-plugin":"^4.0.0-alpha.0","ts-loader":"^8.0.7","typescript":"^4.9.4","webpack":"^5.3.2","webpack-cli":"^4.1.0"},"gitHead":"3870138602251991b56d5fc45f5b4208871e97e3","_id":"@basementuniverse/view-port@1.2.0","bugs":{"url":"https://github.com/basementuniverse/view-port/issues"},"homepage":"https://github.com/basementuniverse/view-port#readme","_nodeVersion":"24.12.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-1lfMv4DHbv1E8lAcWdRmOBxJvqKudnGTAcrOrYDX7i42//BHlaLfVVNHFpgysXy41Ohi1tFVfC4q22Fq0f+NMA==","shasum":"56d855b7d85d29a9b3fc58f269b627beb8ea203e","tarball":"https://registry.npmjs.org/@basementuniverse/view-port/-/view-port-1.2.0.tgz","fileCount":5,"unpackedSize":19686,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDb+JSYg1uHA0ASkxOrgeJUjFrNY7Iov6mgT4YuJVeQSgIgHEPOP6y8QmKmpeTn8nXwQ/VSsyq1huKD+6PeU9wLOt8="}]},"_npmUser":{"name":"basementuniverse","email":"gordonlarrigan@gmail.com"},"directories":{},"maintainers":[{"name":"basementuniverse","email":"gordonlarrigan@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/view-port_1.2.0_1786900165186_0.4624654929942551"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-14T03:23:28.653Z","modified":"2026-08-16T17:09:25.500Z","1.0.0":"2026-03-14T03:23:28.918Z","1.1.0":"2026-03-18T16:55:40.646Z","1.2.0":"2026-08-16T17:09:25.337Z"},"bugs":{"url":"https://github.com/basementuniverse/view-port/issues"},"author":{"name":"Gordon Larrigan","email":"gordonlarrigan@gmail.com","url":"https://gordonlarrigan.com"},"license":"MIT","homepage":"https://github.com/basementuniverse/view-port#readme","repository":{"type":"git","url":"git+https://github.com/basementuniverse/view-port.git"},"description":"A viewport into worldspace, for rendering chunks in games.","maintainers":[{"name":"basementuniverse","email":"gordonlarrigan@gmail.com"}],"readme":"# view-port\n\nA viewport into worldspace, for rendering chunks in games.\n\nIf you're rendering tile-based worlds, the `@basementuniverse/tile-map` package is a better choice since it contains tile-map specific functionality.\n\nThis package is more general-purpose; it provides a `ViewPort` class which calculates which chunks are visible, generates new chunks if necessary, and updates/draws them.\n\n## Installation\n\n```bash\nnpm install @basementuniverse/view-port\n```\n\nFor direct browser usage, include the UMD build with a script tag:\n\n```html\n<script src=\"build/index.js\"></script>\n```\n\nThe build exposes its exports through the `BasementUniverseViewPort` browser\nnamespace. It does not add each export directly to `window`.\n\n## How to use\n\nSee the [example](./example/example.html) for a complete example of how to use the `ViewPort` class.\n\nCreate a viewport:\n\n```js\nconst viewPort = new ViewPort(options);\n```\n\nWhen using the library directly from a browser script, prefix exports with\n`BasementUniverseViewPort`:\n\n```html\n<script src=\"build/index.js\"></script>\n<script>\n  const viewPort = new BasementUniverseViewPort.ViewPort({\n    // options here...\n  });\n\n  viewPort.update(deltaTime, screenSize, camera);\n</script>\n```\n\nUpdate it every frame:\n\n```js\nfunction update(deltaTime) {\n  viewPort.update(deltaTime, screenSize, camera);\n}\n```\n\nDraw it every frame:\n\n```js\nfunction draw(context) {\n  viewPort.draw(context, screenSize, camera);\n}\n```\n\nGet the visible chunks:\n\n```js\nconst visibleChunks = viewPort.getVisibleChunks(camera);\n```\n\n## Options\n\n```ts\nexport type ViewPortOptions<T extends ViewPortChunk = any> = {\n  /**\n   * The size of each grid cell in world units.\n   *\n   * Default is (100, 100)\n   */\n  gridSize: vec2;\n\n  /**\n   * A function that generates a chunk for a given grid cell coordinate.\n   *\n   * Default is a function that returns an empty object.\n   *\n   * `v` is in grid-cell coordinates.\n   */\n  generator: (v: vec2) => T;\n\n  /**\n   * Buffer area around the viewport in grid cells. Chunks within this area\n   * will also be generated and updated.\n   */\n  border: number;\n\n  /**\n   * The number of chunks to store in the spatial hash buffer before old chunks\n   * are removed. This should be at least the number of chunks that can be\n   * visible at once, plus the buffer area.\n   */\n  bufferAmount: number;\n\n  /**\n   * The maximum number of chunks to generate per update. This is to prevent\n   * performance issues when the camera moves quickly and many chunks need to\n   * be generated at once.\n   */\n  maxElementsToGenerate: number;\n\n  /**\n   * The maximum number of elements to store in the spatial hash.\n   */\n  spatialHashMaxElements: number;\n\n  /**\n   * The maximum number of elements to remove from the spatial hash when it\n   * exceeds the maximum number of elements.\n   */\n  spatialHashMaxElementsToRemove: number;\n\n  /**\n   * Optional debug options\n   *\n   * Can be a boolean value (in which case all sub-options will be set to the\n   * same value), or an object allowing specific debug options to be enabled\n   * individually\n   */\n  debug?: Partial<ViewPortDebugOptions> | boolean;\n};\n```\n","readmeFilename":"README.md"}