@thunderclap-engine/engine 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +390 -0
- package/LICENSE +21 -0
- package/README.md +333 -2
- package/dist/analytics/analytics.d.ts +80 -0
- package/dist/analytics/analytics.js +129 -0
- package/dist/analytics/index.d.ts +1 -0
- package/dist/analytics/index.js +1 -0
- package/dist/anim/aim.d.ts +43 -0
- package/dist/anim/aim.js +157 -0
- package/dist/anim/clip.d.ts +98 -0
- package/dist/anim/clip.js +282 -0
- package/dist/anim/compress.d.ts +65 -0
- package/dist/anim/compress.js +339 -0
- package/dist/anim/foot-ik.d.ts +74 -0
- package/dist/anim/foot-ik.js +241 -0
- package/dist/anim/graph.d.ts +153 -0
- package/dist/anim/graph.js +532 -0
- package/dist/anim/ik.d.ts +105 -0
- package/dist/anim/ik.js +435 -0
- package/dist/anim/index.d.ts +36 -0
- package/dist/anim/index.js +21 -0
- package/dist/anim/match.d.ts +66 -0
- package/dist/anim/match.js +153 -0
- package/dist/anim/mixer.d.ts +113 -0
- package/dist/anim/mixer.js +314 -0
- package/dist/anim/morph.d.ts +41 -0
- package/dist/anim/morph.js +94 -0
- package/dist/anim/pose.d.ts +74 -0
- package/dist/anim/pose.js +254 -0
- package/dist/anim/quat.d.ts +44 -0
- package/dist/anim/quat.js +187 -0
- package/dist/anim/retarget.d.ts +97 -0
- package/dist/anim/retarget.js +366 -0
- package/dist/anim/root-motion.d.ts +44 -0
- package/dist/anim/root-motion.js +224 -0
- package/dist/anim/skin-pose.d.ts +39 -0
- package/dist/anim/skin-pose.js +53 -0
- package/dist/anim/socket.d.ts +47 -0
- package/dist/anim/socket.js +84 -0
- package/dist/anim/spring-chain.d.ts +73 -0
- package/dist/anim/spring-chain.js +294 -0
- package/dist/assets/atlas.d.ts +90 -0
- package/dist/assets/atlas.js +212 -0
- package/dist/assets/baked.d.ts +33 -0
- package/dist/assets/baked.js +38 -0
- package/dist/assets/bundle.d.ts +88 -0
- package/dist/assets/bundle.js +464 -0
- package/dist/assets/cache.d.ts +56 -0
- package/dist/assets/cache.js +123 -0
- package/dist/assets/gltf-load.d.ts +252 -0
- package/dist/assets/gltf-load.js +661 -0
- package/dist/assets/gltf-skin.d.ts +36 -0
- package/dist/assets/gltf-skin.js +109 -0
- package/dist/assets/gltf.d.ts +706 -0
- package/dist/assets/gltf.js +1376 -0
- package/dist/assets/index.d.ts +20 -0
- package/dist/assets/index.js +10 -0
- package/dist/assets/ktx2.d.ts +71 -0
- package/dist/assets/ktx2.js +213 -0
- package/dist/assets/manifest.d.ts +79 -0
- package/dist/assets/manifest.js +7 -0
- package/dist/assets/meshopt.d.ts +23 -0
- package/dist/assets/meshopt.js +403 -0
- package/dist/audio/audio.d.ts +733 -0
- package/dist/audio/audio.js +2013 -0
- package/dist/audio/dsp.d.ts +61 -0
- package/dist/audio/dsp.js +159 -0
- package/dist/audio/duck.d.ts +44 -0
- package/dist/audio/duck.js +101 -0
- package/dist/audio/envelope.d.ts +53 -0
- package/dist/audio/envelope.js +106 -0
- package/dist/audio/index.d.ts +13 -0
- package/dist/audio/index.js +14 -0
- package/dist/audio/music.d.ts +113 -0
- package/dist/audio/music.js +548 -0
- package/dist/audio/occlusion.d.ts +55 -0
- package/dist/audio/occlusion.js +61 -0
- package/dist/audio/persist.d.ts +23 -0
- package/dist/audio/persist.js +27 -0
- package/dist/audio/recipes.d.ts +55 -0
- package/dist/audio/recipes.js +227 -0
- package/dist/audio/send.d.ts +41 -0
- package/dist/audio/send.js +118 -0
- package/dist/audio/sprites.d.ts +59 -0
- package/dist/audio/sprites.js +43 -0
- package/dist/audio/synth.d.ts +103 -0
- package/dist/audio/synth.js +197 -0
- package/dist/audio/variations.d.ts +25 -0
- package/dist/audio/variations.js +55 -0
- package/dist/audio/zones.d.ts +100 -0
- package/dist/audio/zones.js +167 -0
- package/dist/core/detached-surface.d.ts +44 -0
- package/dist/core/detached-surface.js +104 -0
- package/dist/core/events.d.ts +24 -0
- package/dist/core/events.js +43 -0
- package/dist/core/game.d.ts +409 -0
- package/dist/core/game.js +530 -0
- package/dist/core/hash.d.ts +24 -0
- package/dist/core/hash.js +49 -0
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.js +9 -0
- package/dist/core/loop.d.ts +113 -0
- package/dist/core/loop.js +185 -0
- package/dist/core/math.d.ts +58 -0
- package/dist/core/math.js +210 -0
- package/dist/core/noise.d.ts +40 -0
- package/dist/core/noise.js +247 -0
- package/dist/core/pool.d.ts +42 -0
- package/dist/core/pool.js +85 -0
- package/dist/core/random.d.ts +61 -0
- package/dist/core/random.js +199 -0
- package/dist/core/scene.d.ts +79 -0
- package/dist/core/scene.js +195 -0
- package/dist/core/timer.d.ts +66 -0
- package/dist/core/timer.js +286 -0
- package/dist/fx/billboard-wgsl.d.ts +29 -0
- package/dist/fx/billboard-wgsl.js +158 -0
- package/dist/fx/billboard.d.ts +249 -0
- package/dist/fx/billboard.js +702 -0
- package/dist/fx/debug-draw.d.ts +127 -0
- package/dist/fx/debug-draw.js +523 -0
- package/dist/fx/debug-wgsl.d.ts +7 -0
- package/dist/fx/debug-wgsl.js +32 -0
- package/dist/fx/decals-wgsl.d.ts +15 -0
- package/dist/fx/decals-wgsl.js +173 -0
- package/dist/fx/decals.d.ts +216 -0
- package/dist/fx/decals.js +607 -0
- package/dist/fx/effect.d.ts +129 -0
- package/dist/fx/effect.js +349 -0
- package/dist/fx/effects/hit-spark.json +48 -0
- package/dist/fx/effects/index.d.ts +8 -0
- package/dist/fx/effects/index.js +9 -0
- package/dist/fx/effects/magic-aura.json +47 -0
- package/dist/fx/effects/smoke-puff.json +34 -0
- package/dist/fx/emit-surface.d.ts +40 -0
- package/dist/fx/emit-surface.js +124 -0
- package/dist/fx/flicker.d.ts +30 -0
- package/dist/fx/flicker.js +42 -0
- package/dist/fx/index.d.ts +31 -0
- package/dist/fx/index.js +20 -0
- package/dist/fx/particles-wgsl.d.ts +57 -0
- package/dist/fx/particles-wgsl.js +828 -0
- package/dist/fx/particles.d.ts +566 -0
- package/dist/fx/particles.js +1533 -0
- package/dist/fx/random.d.ts +15 -0
- package/dist/fx/random.js +20 -0
- package/dist/fx/sky-wgsl.d.ts +23 -0
- package/dist/fx/sky-wgsl.js +127 -0
- package/dist/fx/sky.d.ts +96 -0
- package/dist/fx/sky.js +175 -0
- package/dist/fx/text-atlas.d.ts +143 -0
- package/dist/fx/text-atlas.js +327 -0
- package/dist/fx/trail-wgsl.d.ts +11 -0
- package/dist/fx/trail-wgsl.js +42 -0
- package/dist/fx/trail.d.ts +194 -0
- package/dist/fx/trail.js +555 -0
- package/dist/fx/water-wgsl.d.ts +34 -0
- package/dist/fx/water-wgsl.js +197 -0
- package/dist/fx/water.d.ts +176 -0
- package/dist/fx/water.js +371 -0
- package/dist/geom/collide/bvh.d.ts +151 -0
- package/dist/geom/collide/bvh.js +493 -0
- package/dist/geom/collide/debug.d.ts +14 -0
- package/dist/geom/collide/debug.js +74 -0
- package/dist/geom/collide/grid.d.ts +26 -0
- package/dist/geom/collide/grid.js +91 -0
- package/dist/geom/collide/index.d.ts +8 -0
- package/dist/geom/collide/index.js +8 -0
- package/dist/geom/collide/queries.d.ts +70 -0
- package/dist/geom/collide/queries.js +583 -0
- package/dist/geom/collide/serialize.d.ts +14 -0
- package/dist/geom/collide/serialize.js +145 -0
- package/dist/geom/collide/shapes.d.ts +161 -0
- package/dist/geom/collide/shapes.js +686 -0
- package/dist/geom/collide/slide.d.ts +66 -0
- package/dist/geom/collide/slide.js +375 -0
- package/dist/geom/collide/tile-slide.d.ts +88 -0
- package/dist/geom/collide/tile-slide.js +255 -0
- package/dist/geom/geometry.d.ts +95 -0
- package/dist/geom/geometry.js +322 -0
- package/dist/geom/heightfield.d.ts +72 -0
- package/dist/geom/heightfield.js +295 -0
- package/dist/geom/hull.d.ts +27 -0
- package/dist/geom/hull.js +279 -0
- package/dist/geom/index.d.ts +35 -0
- package/dist/geom/index.js +23 -0
- package/dist/geom/iso.d.ts +74 -0
- package/dist/geom/iso.js +89 -0
- package/dist/geom/lod.d.ts +29 -0
- package/dist/geom/lod.js +27 -0
- package/dist/geom/ops.d.ts +47 -0
- package/dist/geom/ops.js +285 -0
- package/dist/geom/primitives.d.ts +97 -0
- package/dist/geom/primitives.js +359 -0
- package/dist/geom/shapes.d.ts +43 -0
- package/dist/geom/shapes.js +88 -0
- package/dist/geom/simplify.d.ts +38 -0
- package/dist/geom/simplify.js +519 -0
- package/dist/geom/split.d.ts +37 -0
- package/dist/geom/split.js +413 -0
- package/dist/geom/sweep.d.ts +83 -0
- package/dist/geom/sweep.js +534 -0
- package/dist/geom/tangents.d.ts +16 -0
- package/dist/geom/tangents.js +124 -0
- package/dist/geom/triangulate.d.ts +19 -0
- package/dist/geom/triangulate.js +147 -0
- package/dist/host/default.d.ts +10 -0
- package/dist/host/default.js +10 -0
- package/dist/host/index.d.ts +4 -0
- package/dist/host/index.js +3 -0
- package/dist/host/types.d.ts +144 -0
- package/dist/host/types.js +1 -0
- package/dist/host/web-links.d.ts +38 -0
- package/dist/host/web-links.js +110 -0
- package/dist/host/web.d.ts +30 -0
- package/dist/host/web.js +216 -0
- package/dist/host/xr.d.ts +24 -0
- package/dist/host/xr.js +59 -0
- package/dist/i18n/i18n.d.ts +59 -0
- package/dist/i18n/i18n.js +241 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/index.js +3 -0
- package/dist/i18n/message.d.ts +72 -0
- package/dist/i18n/message.js +369 -0
- package/dist/i18n/negotiate.d.ts +17 -0
- package/dist/i18n/negotiate.js +58 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1 -0
- package/dist/input/bindings.d.ts +31 -0
- package/dist/input/bindings.js +141 -0
- package/dist/input/clock.d.ts +44 -0
- package/dist/input/clock.js +49 -0
- package/dist/input/follow.d.ts +133 -0
- package/dist/input/follow.js +218 -0
- package/dist/input/gestures.d.ts +281 -0
- package/dist/input/gestures.js +662 -0
- package/dist/input/glyphs.d.ts +35 -0
- package/dist/input/glyphs.js +216 -0
- package/dist/input/gyro.d.ts +85 -0
- package/dist/input/gyro.js +140 -0
- package/dist/input/index.d.ts +19 -0
- package/dist/input/index.js +16 -0
- package/dist/input/input.d.ts +543 -0
- package/dist/input/input.js +1492 -0
- package/dist/input/look.d.ts +327 -0
- package/dist/input/look.js +681 -0
- package/dist/input/magnify.d.ts +177 -0
- package/dist/input/magnify.js +131 -0
- package/dist/input/pointer-dispatch.d.ts +138 -0
- package/dist/input/pointer-dispatch.js +180 -0
- package/dist/input/pointer-router.d.ts +204 -0
- package/dist/input/pointer-router.js +533 -0
- package/dist/input/pointer-sources.d.ts +164 -0
- package/dist/input/pointer-sources.js +306 -0
- package/dist/input/rays.d.ts +138 -0
- package/dist/input/rays.js +615 -0
- package/dist/input/record.d.ts +209 -0
- package/dist/input/record.js +601 -0
- package/dist/input/touch-zones.d.ts +147 -0
- package/dist/input/touch-zones.js +300 -0
- package/dist/input/types.d.ts +158 -0
- package/dist/input/types.js +1 -0
- package/dist/input/xr-source.d.ts +53 -0
- package/dist/input/xr-source.js +164 -0
- package/dist/nav/astar.d.ts +45 -0
- package/dist/nav/astar.js +182 -0
- package/dist/nav/corridor.d.ts +40 -0
- package/dist/nav/corridor.js +95 -0
- package/dist/nav/crowd.d.ts +94 -0
- package/dist/nav/crowd.js +624 -0
- package/dist/nav/flow.d.ts +61 -0
- package/dist/nav/flow.js +193 -0
- package/dist/nav/grid.d.ts +108 -0
- package/dist/nav/grid.js +210 -0
- package/dist/nav/heap.d.ts +22 -0
- package/dist/nav/heap.js +92 -0
- package/dist/nav/index.d.ts +37 -0
- package/dist/nav/index.js +19 -0
- package/dist/nav/mesh/areas.d.ts +44 -0
- package/dist/nav/mesh/areas.js +98 -0
- package/dist/nav/mesh/bake-options.d.ts +33 -0
- package/dist/nav/mesh/bake-options.js +76 -0
- package/dist/nav/mesh/contour.d.ts +22 -0
- package/dist/nav/mesh/contour.js +323 -0
- package/dist/nav/mesh/flow3.d.ts +35 -0
- package/dist/nav/mesh/flow3.js +229 -0
- package/dist/nav/mesh/links.d.ts +38 -0
- package/dist/nav/mesh/links.js +72 -0
- package/dist/nav/mesh/mesh-path.d.ts +152 -0
- package/dist/nav/mesh/mesh-path.js +643 -0
- package/dist/nav/mesh/mesh-reach.d.ts +78 -0
- package/dist/nav/mesh/mesh-reach.js +450 -0
- package/dist/nav/mesh/navmesh.d.ts +117 -0
- package/dist/nav/mesh/navmesh.js +647 -0
- package/dist/nav/mesh/polymesh.d.ts +24 -0
- package/dist/nav/mesh/polymesh.js +384 -0
- package/dist/nav/mesh/regions.d.ts +12 -0
- package/dist/nav/mesh/regions.js +367 -0
- package/dist/nav/mesh/serialize.d.ts +13 -0
- package/dist/nav/mesh/serialize.js +197 -0
- package/dist/nav/mesh/voxelize.d.ts +111 -0
- package/dist/nav/mesh/voxelize.js +552 -0
- package/dist/nav/obstacles.d.ts +75 -0
- package/dist/nav/obstacles.js +294 -0
- package/dist/nav/path.d.ts +59 -0
- package/dist/nav/path.js +177 -0
- package/dist/nav/query-queue.d.ts +46 -0
- package/dist/nav/query-queue.js +308 -0
- package/dist/nav/reach.d.ts +53 -0
- package/dist/nav/reach.js +148 -0
- package/dist/nav/steer.d.ts +36 -0
- package/dist/nav/steer.js +78 -0
- package/dist/platform/boot.d.ts +28 -0
- package/dist/platform/boot.js +43 -0
- package/dist/platform/device-mode.d.ts +40 -0
- package/dist/platform/device-mode.js +104 -0
- package/dist/platform/device.d.ts +31 -0
- package/dist/platform/device.js +91 -0
- package/dist/platform/environment.d.ts +42 -0
- package/dist/platform/environment.js +82 -0
- package/dist/platform/gpu.d.ts +40 -0
- package/dist/platform/gpu.js +57 -0
- package/dist/platform/index.d.ts +18 -0
- package/dist/platform/index.js +10 -0
- package/dist/platform/letterbox.d.ts +43 -0
- package/dist/platform/letterbox.js +57 -0
- package/dist/platform/links.d.ts +20 -0
- package/dist/platform/links.js +43 -0
- package/dist/platform/screens.d.ts +36 -0
- package/dist/platform/screens.js +138 -0
- package/dist/platform/surface.d.ts +72 -0
- package/dist/platform/surface.js +157 -0
- package/dist/platform/xr-fake.d.ts +168 -0
- package/dist/platform/xr-fake.js +434 -0
- package/dist/platform/xr-surface.d.ts +120 -0
- package/dist/platform/xr-surface.js +214 -0
- package/dist/platform/xr-types.d.ts +262 -0
- package/dist/post/ao.d.ts +12 -0
- package/dist/post/ao.js +136 -0
- package/dist/post/blend.d.ts +27 -0
- package/dist/post/blend.js +129 -0
- package/dist/post/depth-pass.d.ts +43 -0
- package/dist/post/depth-pass.js +118 -0
- package/dist/post/dof.d.ts +1 -0
- package/dist/post/dof.js +66 -0
- package/dist/post/exposure.d.ts +80 -0
- package/dist/post/exposure.js +322 -0
- package/dist/post/index.d.ts +12 -0
- package/dist/post/index.js +11 -0
- package/dist/post/lens-dirt.d.ts +13 -0
- package/dist/post/lens-dirt.js +91 -0
- package/dist/post/lut.d.ts +19 -0
- package/dist/post/lut.js +50 -0
- package/dist/post/motion-blur.d.ts +9 -0
- package/dist/post/motion-blur.js +78 -0
- package/dist/post/post-stack.d.ts +302 -0
- package/dist/post/post-stack.js +1137 -0
- package/dist/post/settings.d.ts +485 -0
- package/dist/post/settings.js +416 -0
- package/dist/post/shaders.d.ts +25 -0
- package/dist/post/shaders.js +410 -0
- package/dist/post/ssr.d.ts +16 -0
- package/dist/post/ssr.js +155 -0
- package/dist/post/taa.d.ts +74 -0
- package/dist/post/taa.js +235 -0
- package/dist/post/white-balance.d.ts +25 -0
- package/dist/post/white-balance.js +98 -0
- package/dist/render/bindings.d.ts +98 -0
- package/dist/render/bindings.js +281 -0
- package/dist/render/blend.d.ts +13 -0
- package/dist/render/blend.js +26 -0
- package/dist/render/camera-2d.d.ts +72 -0
- package/dist/render/camera-2d.js +92 -0
- package/dist/render/camera.d.ts +302 -0
- package/dist/render/camera.js +671 -0
- package/dist/render/color.d.ts +16 -0
- package/dist/render/color.js +41 -0
- package/dist/render/compressed.d.ts +104 -0
- package/dist/render/compressed.js +248 -0
- package/dist/render/diagnostics.d.ts +15 -0
- package/dist/render/diagnostics.js +43 -0
- package/dist/render/dynamic-resolution.d.ts +70 -0
- package/dist/render/dynamic-resolution.js +126 -0
- package/dist/render/fake-gpu.d.ts +204 -0
- package/dist/render/fake-gpu.js +426 -0
- package/dist/render/flipbook.d.ts +56 -0
- package/dist/render/flipbook.js +87 -0
- package/dist/render/frame.d.ts +278 -0
- package/dist/render/frame.js +174 -0
- package/dist/render/fullscreen.d.ts +54 -0
- package/dist/render/fullscreen.js +91 -0
- package/dist/render/gpu-timer.d.ts +73 -0
- package/dist/render/gpu-timer.js +186 -0
- package/dist/render/index.d.ts +53 -0
- package/dist/render/index.js +29 -0
- package/dist/render/instance-list.d.ts +185 -0
- package/dist/render/instance-list.js +547 -0
- package/dist/render/lights.d.ts +181 -0
- package/dist/render/lights.js +233 -0
- package/dist/render/lod.d.ts +54 -0
- package/dist/render/lod.js +52 -0
- package/dist/render/material.d.ts +165 -0
- package/dist/render/material.js +292 -0
- package/dist/render/mesh.d.ts +284 -0
- package/dist/render/mesh.js +472 -0
- package/dist/render/mipmap.d.ts +16 -0
- package/dist/render/mipmap.js +121 -0
- package/dist/render/parallax.d.ts +50 -0
- package/dist/render/parallax.js +47 -0
- package/dist/render/pbr-wgsl.d.ts +31 -0
- package/dist/render/pbr-wgsl.js +119 -0
- package/dist/render/ping-pong.d.ts +42 -0
- package/dist/render/ping-pong.js +74 -0
- package/dist/render/renderer.d.ts +741 -0
- package/dist/render/renderer.js +2486 -0
- package/dist/render/scene-pipelines.d.ts +44 -0
- package/dist/render/scene-pipelines.js +92 -0
- package/dist/render/scene-target.d.ts +170 -0
- package/dist/render/scene-target.js +450 -0
- package/dist/render/shadow.d.ts +74 -0
- package/dist/render/shadow.js +208 -0
- package/dist/render/skin.d.ts +112 -0
- package/dist/render/skin.js +240 -0
- package/dist/render/snapshot.d.ts +36 -0
- package/dist/render/snapshot.js +34 -0
- package/dist/render/standard.d.ts +162 -0
- package/dist/render/standard.js +263 -0
- package/dist/render/texture.d.ts +142 -0
- package/dist/render/texture.js +228 -0
- package/dist/render/tile-layer.d.ts +110 -0
- package/dist/render/tile-layer.js +304 -0
- package/dist/render/transform.d.ts +115 -0
- package/dist/render/transform.js +318 -0
- package/dist/render/wgsl.d.ts +131 -0
- package/dist/render/wgsl.js +528 -0
- package/dist/save/codec.d.ts +49 -0
- package/dist/save/codec.js +169 -0
- package/dist/save/index.d.ts +8 -0
- package/dist/save/index.js +8 -0
- package/dist/save/journal.d.ts +24 -0
- package/dist/save/journal.js +102 -0
- package/dist/save/migrate.d.ts +15 -0
- package/dist/save/migrate.js +37 -0
- package/dist/save/schema.d.ts +72 -0
- package/dist/save/schema.js +154 -0
- package/dist/save/settings.d.ts +28 -0
- package/dist/save/settings.js +59 -0
- package/dist/save/slots.d.ts +56 -0
- package/dist/save/slots.js +200 -0
- package/dist/save/storage.d.ts +35 -0
- package/dist/save/storage.js +62 -0
- package/dist/save/store.d.ts +114 -0
- package/dist/save/store.js +269 -0
- package/dist/testing/fake-host.d.ts +103 -0
- package/dist/testing/fake-host.js +163 -0
- package/dist/testing/fixed-clock.d.ts +25 -0
- package/dist/testing/fixed-clock.js +30 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.js +5 -0
- package/dist/testing/test-game.d.ts +76 -0
- package/dist/testing/test-game.js +92 -0
- package/dist/tween/ease.d.ts +77 -0
- package/dist/tween/ease.js +192 -0
- package/dist/tween/index.d.ts +8 -0
- package/dist/tween/index.js +7 -0
- package/dist/tween/timeline.d.ts +78 -0
- package/dist/tween/timeline.js +269 -0
- package/dist/tween/tween.d.ts +168 -0
- package/dist/tween/tween.js +320 -0
- package/dist/ui/anchor.d.ts +206 -0
- package/dist/ui/anchor.js +307 -0
- package/dist/ui/caption.d.ts +122 -0
- package/dist/ui/caption.js +286 -0
- package/dist/ui/cursor.d.ts +105 -0
- package/dist/ui/cursor.js +261 -0
- package/dist/ui/dom.d.ts +30 -0
- package/dist/ui/dom.js +92 -0
- package/dist/ui/floats.d.ts +86 -0
- package/dist/ui/floats.js +260 -0
- package/dist/ui/hud.d.ts +198 -0
- package/dist/ui/hud.js +431 -0
- package/dist/ui/index.d.ts +37 -0
- package/dist/ui/index.js +34 -0
- package/dist/ui/inventory-card.d.ts +52 -0
- package/dist/ui/inventory-card.js +173 -0
- package/dist/ui/inventory-context.d.ts +29 -0
- package/dist/ui/inventory-context.js +125 -0
- package/dist/ui/inventory-drag.d.ts +63 -0
- package/dist/ui/inventory-drag.js +394 -0
- package/dist/ui/inventory-grid.d.ts +66 -0
- package/dist/ui/inventory-grid.js +625 -0
- package/dist/ui/inventory-radial.d.ts +39 -0
- package/dist/ui/inventory-radial.js +168 -0
- package/dist/ui/inventory.d.ts +128 -0
- package/dist/ui/inventory.js +154 -0
- package/dist/ui/layout.d.ts +356 -0
- package/dist/ui/layout.js +856 -0
- package/dist/ui/link.d.ts +64 -0
- package/dist/ui/link.js +155 -0
- package/dist/ui/loading.d.ts +40 -0
- package/dist/ui/loading.js +157 -0
- package/dist/ui/loupe.d.ts +74 -0
- package/dist/ui/loupe.js +164 -0
- package/dist/ui/menu-nav.d.ts +33 -0
- package/dist/ui/menu-nav.js +28 -0
- package/dist/ui/minimap-canvas.d.ts +145 -0
- package/dist/ui/minimap-canvas.js +460 -0
- package/dist/ui/notify.d.ts +40 -0
- package/dist/ui/notify.js +141 -0
- package/dist/ui/orb.d.ts +53 -0
- package/dist/ui/orb.js +304 -0
- package/dist/ui/overlay.d.ts +213 -0
- package/dist/ui/overlay.js +394 -0
- package/dist/ui/padnav.d.ts +53 -0
- package/dist/ui/padnav.js +146 -0
- package/dist/ui/perf.d.ts +130 -0
- package/dist/ui/perf.js +329 -0
- package/dist/ui/rotate-card.d.ts +54 -0
- package/dist/ui/rotate-card.js +97 -0
- package/dist/ui/stack.d.ts +128 -0
- package/dist/ui/stack.js +312 -0
- package/dist/ui/styles.d.ts +13 -0
- package/dist/ui/styles.js +200 -0
- package/dist/ui/text-scale.d.ts +67 -0
- package/dist/ui/text-scale.js +102 -0
- package/dist/ui/theme.d.ts +70 -0
- package/dist/ui/theme.js +98 -0
- package/dist/ui/toast.d.ts +23 -0
- package/dist/ui/toast.js +46 -0
- package/dist/ui/tooltip.d.ts +89 -0
- package/dist/ui/tooltip.js +333 -0
- package/dist/ui/widgets-2.d.ts +134 -0
- package/dist/ui/widgets-2.js +399 -0
- package/dist/ui/widgets-3.d.ts +91 -0
- package/dist/ui/widgets-3.js +212 -0
- package/dist/ui/widgets.d.ts +34 -0
- package/dist/ui/widgets.js +50 -0
- package/dist/ui/world-panel/index.d.ts +5 -0
- package/dist/ui/world-panel/index.js +5 -0
- package/dist/ui/world-panel/layout.d.ts +38 -0
- package/dist/ui/world-panel/layout.js +68 -0
- package/dist/ui/world-panel/paint.d.ts +96 -0
- package/dist/ui/world-panel/paint.js +136 -0
- package/dist/ui/world-panel/panel.d.ts +235 -0
- package/dist/ui/world-panel/panel.js +762 -0
- package/dist/ui/world-panel/wgsl.d.ts +10 -0
- package/dist/ui/world-panel/wgsl.js +52 -0
- package/dist/ui/world-panel/widgets.d.ts +207 -0
- package/dist/ui/world-panel/widgets.js +569 -0
- package/dist/voxel/chunks.d.ts +77 -0
- package/dist/voxel/chunks.js +149 -0
- package/dist/voxel/grid.d.ts +84 -0
- package/dist/voxel/grid.js +223 -0
- package/dist/voxel/index.d.ts +22 -0
- package/dist/voxel/index.js +7 -0
- package/dist/voxel/mesher-worker.d.ts +14 -0
- package/dist/voxel/mesher-worker.js +47 -0
- package/dist/voxel/mesher.d.ts +73 -0
- package/dist/voxel/mesher.js +306 -0
- package/dist/voxel/ray.d.ts +32 -0
- package/dist/voxel/ray.js +73 -0
- package/dist/voxel/wgsl.d.ts +16 -0
- package/dist/voxel/wgsl.js +28 -0
- package/dist/voxel/worker-client.d.ts +79 -0
- package/dist/voxel/worker-client.js +122 -0
- package/package.json +177 -3
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The inventory grid (ws/ui-inventory): a `role="grid"` of `gridcell`s with a roving tabindex,
|
|
3
|
+
* items that may span cells, a count badge, keyboard and pad pick-up and drop, a hover and focus
|
|
4
|
+
* card, a context hook and a polite announcer. It is also a `DropTarget`, so `drag.register(grid)`
|
|
5
|
+
* lets pointers drag between grids and onto a `slotsTarget`.
|
|
6
|
+
*
|
|
7
|
+
* Keys (consumed with `preventDefault` and `stopPropagation`, like `segmented`): arrows move the
|
|
8
|
+
* focus, clamped, no wrap; Home and End go to the row's ends; Enter or Space activates the item
|
|
9
|
+
* (`onActivate`); a held Enter or Space (key repeat) picks it up, the next Enter or Space drops it
|
|
10
|
+
* (`aria-grabbed` on the source cell meanwhile); Escape puts it back; Shift+F10 and the
|
|
11
|
+
* ContextMenu key call `onContext`. `act(action)` is the same for a pad: `select` picks up or
|
|
12
|
+
* drops, `back` cancels, `secondary` is the context hook, the directions move the focus. While an
|
|
13
|
+
* item is held and the focus is at the left or right edge, the next left or right walks to the
|
|
14
|
+
* next registered target (`DragLink.cross`).
|
|
15
|
+
*/
|
|
16
|
+
import { h } from './dom.js';
|
|
17
|
+
import { themePx } from './hud.js';
|
|
18
|
+
import { defaultInventoryLabels, ensureInventoryStyles, iconNode, } from './inventory.js';
|
|
19
|
+
const EDGE_LEFT = 'left';
|
|
20
|
+
const EDGE_RIGHT = 'right';
|
|
21
|
+
/** An inventory grid. See the module comment. */
|
|
22
|
+
export function grid(opts) {
|
|
23
|
+
const cols = Math.max(1, Math.floor(opts.cols));
|
|
24
|
+
const rows = Math.max(1, Math.floor(opts.rows));
|
|
25
|
+
const n = cols * rows;
|
|
26
|
+
const labels = { ...defaultInventoryLabels, ...opts.labels };
|
|
27
|
+
const hoverMs = opts.hoverMs ?? 250;
|
|
28
|
+
// Data: the anchored item per cell, and which anchor covers each cell (-1: none).
|
|
29
|
+
const anchors = new Array(n).fill(null);
|
|
30
|
+
const cover = new Int32Array(n).fill(-1);
|
|
31
|
+
const cells = [];
|
|
32
|
+
const spots = [];
|
|
33
|
+
const rowEls = [];
|
|
34
|
+
const live = h('span', { class: 'tc-sr-only', 'aria-live': 'polite' });
|
|
35
|
+
ensureInventoryStyles(live.ownerDocument);
|
|
36
|
+
for (let r = 0; r < rows; r++) {
|
|
37
|
+
const row = h('div', { class: 'tc-grid-row', role: 'row' });
|
|
38
|
+
for (let c = 0; c < cols; c++) {
|
|
39
|
+
const cell = h('div', {
|
|
40
|
+
class: 'tc-cell',
|
|
41
|
+
role: 'gridcell',
|
|
42
|
+
tabindex: r === 0 && c === 0 ? '0' : '-1',
|
|
43
|
+
'aria-label': labels.empty,
|
|
44
|
+
dataset: { col: String(c), row: String(r) },
|
|
45
|
+
});
|
|
46
|
+
cells.push(cell);
|
|
47
|
+
spots.push({ el: cell, col: c, row: r });
|
|
48
|
+
row.append(cell);
|
|
49
|
+
}
|
|
50
|
+
rowEls.push(row);
|
|
51
|
+
}
|
|
52
|
+
const element = h('div', {
|
|
53
|
+
class: 'tc-grid',
|
|
54
|
+
role: 'grid',
|
|
55
|
+
'aria-label': opts.label,
|
|
56
|
+
'aria-rowcount': String(rows),
|
|
57
|
+
'aria-colcount': String(cols),
|
|
58
|
+
style: {
|
|
59
|
+
'--tc-cell-size': themePx(opts.cellSize ?? 56),
|
|
60
|
+
'--tc-cell-gap': themePx(opts.gap ?? 4),
|
|
61
|
+
},
|
|
62
|
+
}, ...rowEls, live);
|
|
63
|
+
const idx = (c, r) => r * cols + c;
|
|
64
|
+
const inBounds = (c, r) => c >= 0 && r >= 0 && c < cols && r < rows;
|
|
65
|
+
const spanOf = (item) => ({
|
|
66
|
+
w: Math.max(1, Math.floor(item.span?.w ?? 1)),
|
|
67
|
+
h: Math.max(1, Math.floor(item.span?.h ?? 1)),
|
|
68
|
+
});
|
|
69
|
+
/** Whether `item` fits anchored at (c, r), ignoring the cells `ignore` (its own anchor) covers. */
|
|
70
|
+
function fits(c, r, item, ignore) {
|
|
71
|
+
const { w, h: hh } = spanOf(item);
|
|
72
|
+
if (!inBounds(c, r) || c + w > cols || r + hh > rows)
|
|
73
|
+
return false;
|
|
74
|
+
for (let y = r; y < r + hh; y++)
|
|
75
|
+
for (let x = c; x < c + w; x++) {
|
|
76
|
+
const a = cover[idx(x, y)];
|
|
77
|
+
if (a !== -1 && a !== ignore)
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
function labelOf(item) {
|
|
83
|
+
return item.label ?? item.id;
|
|
84
|
+
}
|
|
85
|
+
function renderCell(i) {
|
|
86
|
+
const cell = cells[i];
|
|
87
|
+
const item = anchors[i];
|
|
88
|
+
const prev = cell.querySelector('.tc-cell-item');
|
|
89
|
+
prev?.remove();
|
|
90
|
+
cell.removeAttribute('data-covered');
|
|
91
|
+
cell.style.removeProperty('--tc-span-w');
|
|
92
|
+
cell.style.removeProperty('--tc-span-h');
|
|
93
|
+
if (!item) {
|
|
94
|
+
const a = cover[i];
|
|
95
|
+
if (a !== -1 && a !== i)
|
|
96
|
+
cell.setAttribute('data-covered', '');
|
|
97
|
+
cell.setAttribute('aria-label', a !== -1 ? labelOf(anchors[a]) : labels.empty);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const { w, h: hh } = spanOf(item);
|
|
101
|
+
if (w > 1)
|
|
102
|
+
cell.style.setProperty('--tc-span-w', String(w));
|
|
103
|
+
if (hh > 1)
|
|
104
|
+
cell.style.setProperty('--tc-span-h', String(hh));
|
|
105
|
+
const box = h('div', {
|
|
106
|
+
class: 'tc-cell-item',
|
|
107
|
+
'data-tone': item.tone,
|
|
108
|
+
'data-id': item.id,
|
|
109
|
+
'data-locked': item.locked === true,
|
|
110
|
+
}, iconNode(item.icon, element.ownerDocument), item.count !== undefined && item.count > 1
|
|
111
|
+
? h('span', { class: 'tc-cell-count' }, String(item.count))
|
|
112
|
+
: null);
|
|
113
|
+
cell.append(box);
|
|
114
|
+
cell.setAttribute('aria-label', labels.cell(labelOf(item), item.count));
|
|
115
|
+
}
|
|
116
|
+
function place(c, r, item) {
|
|
117
|
+
const a = idx(c, r);
|
|
118
|
+
const { w, h: hh } = spanOf(item);
|
|
119
|
+
anchors[a] = item;
|
|
120
|
+
for (let y = r; y < r + hh; y++)
|
|
121
|
+
for (let x = c; x < c + w; x++) {
|
|
122
|
+
cover[idx(x, y)] = a;
|
|
123
|
+
if (idx(x, y) !== a)
|
|
124
|
+
renderCell(idx(x, y));
|
|
125
|
+
}
|
|
126
|
+
renderCell(a);
|
|
127
|
+
}
|
|
128
|
+
function unplace(a) {
|
|
129
|
+
const item = anchors[a];
|
|
130
|
+
if (!item)
|
|
131
|
+
return null;
|
|
132
|
+
anchors[a] = null;
|
|
133
|
+
for (let i = 0; i < n; i++)
|
|
134
|
+
if (cover[i] === a) {
|
|
135
|
+
cover[i] = -1;
|
|
136
|
+
if (i !== a)
|
|
137
|
+
renderCell(i);
|
|
138
|
+
}
|
|
139
|
+
renderCell(a);
|
|
140
|
+
return item;
|
|
141
|
+
}
|
|
142
|
+
function set(cell, item) {
|
|
143
|
+
if (!inBounds(cell.col, cell.row))
|
|
144
|
+
return false;
|
|
145
|
+
const i = idx(cell.col, cell.row);
|
|
146
|
+
const covering = cover[i];
|
|
147
|
+
if (item && !fits(cell.col, cell.row, item, covering === -1 ? -2 : covering))
|
|
148
|
+
return false;
|
|
149
|
+
if (covering !== -1)
|
|
150
|
+
unplace(covering);
|
|
151
|
+
if (item)
|
|
152
|
+
place(cell.col, cell.row, item);
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
function get(cell) {
|
|
156
|
+
if (!inBounds(cell.col, cell.row))
|
|
157
|
+
return null;
|
|
158
|
+
const a = cover[idx(cell.col, cell.row)];
|
|
159
|
+
return a === -1 ? null : anchors[a];
|
|
160
|
+
}
|
|
161
|
+
function find(item) {
|
|
162
|
+
const a = anchors.indexOf(item);
|
|
163
|
+
return a < 0 ? null : { col: a % cols, row: Math.floor(a / cols) };
|
|
164
|
+
}
|
|
165
|
+
function move(from, to) {
|
|
166
|
+
if (!inBounds(from.col, from.row))
|
|
167
|
+
return false;
|
|
168
|
+
const a = cover[idx(from.col, from.row)];
|
|
169
|
+
if (a === -1)
|
|
170
|
+
return false;
|
|
171
|
+
const item = anchors[a];
|
|
172
|
+
if (!fits(to.col, to.row, item, a))
|
|
173
|
+
return false;
|
|
174
|
+
unplace(a);
|
|
175
|
+
place(to.col, to.row, item);
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
// ---------------------------------------------------------------- focus
|
|
179
|
+
const focused = { col: 0, row: 0 };
|
|
180
|
+
let focusIdx = 0;
|
|
181
|
+
function setFocus(c, r, moveFocus) {
|
|
182
|
+
c = Math.max(0, Math.min(cols - 1, c));
|
|
183
|
+
r = Math.max(0, Math.min(rows - 1, r));
|
|
184
|
+
const i = idx(c, r);
|
|
185
|
+
if (i !== focusIdx) {
|
|
186
|
+
cells[focusIdx].tabIndex = -1;
|
|
187
|
+
focusIdx = i;
|
|
188
|
+
cells[i].tabIndex = 0;
|
|
189
|
+
focused.col = c;
|
|
190
|
+
focused.row = r;
|
|
191
|
+
opts.onFocus?.(focused);
|
|
192
|
+
if (carry)
|
|
193
|
+
showCarry();
|
|
194
|
+
}
|
|
195
|
+
if (moveFocus)
|
|
196
|
+
cells[i].focus({ preventScroll: true });
|
|
197
|
+
}
|
|
198
|
+
// ---------------------------------------------------------------- card
|
|
199
|
+
let hoverTimer = null;
|
|
200
|
+
let cardAnchor = null;
|
|
201
|
+
function showCard(i) {
|
|
202
|
+
const card = opts.card;
|
|
203
|
+
if (!card || !opts.describe)
|
|
204
|
+
return;
|
|
205
|
+
const a = cover[i];
|
|
206
|
+
const item = a === -1 ? null : anchors[a];
|
|
207
|
+
const desc = item ? opts.describe(item, spots[i]) : null;
|
|
208
|
+
if (!desc) {
|
|
209
|
+
hideCard();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
card.set(desc);
|
|
213
|
+
cardAnchor = cells[a];
|
|
214
|
+
card.show(cardAnchor);
|
|
215
|
+
}
|
|
216
|
+
function hideCard() {
|
|
217
|
+
if (hoverTimer !== null) {
|
|
218
|
+
clearTimeout(hoverTimer);
|
|
219
|
+
hoverTimer = null;
|
|
220
|
+
}
|
|
221
|
+
if (cardAnchor) {
|
|
222
|
+
opts.card?.hide();
|
|
223
|
+
cardAnchor = null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function cellIndexOf(target) {
|
|
227
|
+
const el = target?.closest?.('.tc-cell') ?? null;
|
|
228
|
+
if (!el || !element.contains(el))
|
|
229
|
+
return -1;
|
|
230
|
+
return idx(Number(el.dataset.col), Number(el.dataset.row));
|
|
231
|
+
}
|
|
232
|
+
// ---------------------------------------------------------------- carry (keyboard and pad)
|
|
233
|
+
let carry = null;
|
|
234
|
+
const scratchTo = { grid: null, col: 0, row: 0 };
|
|
235
|
+
function announce(text) {
|
|
236
|
+
live.textContent = '';
|
|
237
|
+
live.textContent = text;
|
|
238
|
+
}
|
|
239
|
+
function clearOver() {
|
|
240
|
+
for (const c of cells) {
|
|
241
|
+
c.removeAttribute('data-over');
|
|
242
|
+
c.removeAttribute('data-reject');
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/** The focused cell shows the held item's landing: `data-over`, and `data-reject` when refused. */
|
|
246
|
+
function showCarry() {
|
|
247
|
+
clearOver();
|
|
248
|
+
if (!carry)
|
|
249
|
+
return;
|
|
250
|
+
const cell = cells[focusIdx];
|
|
251
|
+
cell.setAttribute('data-over', '');
|
|
252
|
+
if (!canDrop(spots[focusIdx], carry))
|
|
253
|
+
cell.setAttribute('data-reject', '');
|
|
254
|
+
}
|
|
255
|
+
function pickUp() {
|
|
256
|
+
const a = cover[focusIdx];
|
|
257
|
+
if (a === -1)
|
|
258
|
+
return false;
|
|
259
|
+
const item = anchors[a];
|
|
260
|
+
if (item.locked)
|
|
261
|
+
return false;
|
|
262
|
+
carry = { item, from: { grid: self, col: a % cols, row: Math.floor(a / cols) }, source: self };
|
|
263
|
+
cells[a].setAttribute('aria-grabbed', 'true');
|
|
264
|
+
hideCard();
|
|
265
|
+
announce(labels.pickedUp(labelOf(item)));
|
|
266
|
+
self.link?.carryStart(carry);
|
|
267
|
+
showCarry();
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
function dropHeld() {
|
|
271
|
+
if (!carry)
|
|
272
|
+
return false;
|
|
273
|
+
const pick = carry;
|
|
274
|
+
const spot = spots[focusIdx];
|
|
275
|
+
let ok;
|
|
276
|
+
if (self.link)
|
|
277
|
+
ok = self.link.commit(self, spot, pick);
|
|
278
|
+
else if (canDrop(spot, pick)) {
|
|
279
|
+
drop(spot, pick);
|
|
280
|
+
carryEnd();
|
|
281
|
+
ok = true;
|
|
282
|
+
}
|
|
283
|
+
else
|
|
284
|
+
ok = false;
|
|
285
|
+
announce(ok ? labels.dropped(labelOf(pick.item)) : labels.rejected(labelOf(pick.item)));
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
function cancelHeld() {
|
|
289
|
+
if (!carry)
|
|
290
|
+
return false;
|
|
291
|
+
const pick = carry;
|
|
292
|
+
if (self.link)
|
|
293
|
+
self.link.cancelCarry();
|
|
294
|
+
else
|
|
295
|
+
carryEnd();
|
|
296
|
+
announce(labels.cancelled(labelOf(pick.item)));
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
function carryEnd() {
|
|
300
|
+
carry = null;
|
|
301
|
+
for (const c of cells)
|
|
302
|
+
c.removeAttribute('aria-grabbed');
|
|
303
|
+
clearOver();
|
|
304
|
+
}
|
|
305
|
+
function carryIn(pick, side) {
|
|
306
|
+
carry = pick;
|
|
307
|
+
const c = side === EDGE_LEFT ? 0 : cols - 1;
|
|
308
|
+
const r = Math.min(rows - 1, pick.from.row);
|
|
309
|
+
hideCard();
|
|
310
|
+
// Land on the same row where it exists, else the last row; focus moves here.
|
|
311
|
+
if (idx(c, r) === focusIdx)
|
|
312
|
+
showCarry();
|
|
313
|
+
setFocus(c, r, true);
|
|
314
|
+
if (idx(c, r) === focusIdx)
|
|
315
|
+
showCarry();
|
|
316
|
+
}
|
|
317
|
+
function stepFocus(dc, dr) {
|
|
318
|
+
const c = focused.col + dc;
|
|
319
|
+
const r = focused.row + dr;
|
|
320
|
+
if (carry && dr === 0 && (c < 0 || c >= cols)) {
|
|
321
|
+
const dir = c < 0 ? EDGE_LEFT : EDGE_RIGHT;
|
|
322
|
+
if (self.link?.cross(self, dir, carry)) {
|
|
323
|
+
clearOver();
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (!inBounds(c, r))
|
|
328
|
+
return true;
|
|
329
|
+
setFocus(c, r, true);
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
const cellOf = (i) => ({ col: i % cols, row: Math.floor(i / cols) });
|
|
333
|
+
function activate() {
|
|
334
|
+
const a = cover[focusIdx];
|
|
335
|
+
if (a === -1)
|
|
336
|
+
return;
|
|
337
|
+
opts.onActivate?.(cellOf(a), anchors[a]);
|
|
338
|
+
}
|
|
339
|
+
function context(i) {
|
|
340
|
+
const a = cover[i];
|
|
341
|
+
if (a === -1 || !opts.onContext)
|
|
342
|
+
return false;
|
|
343
|
+
setFocus(a % cols, Math.floor(a / cols), true);
|
|
344
|
+
hideCard();
|
|
345
|
+
opts.onContext(cellOf(a), anchors[a], cells[a]);
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
function act(action) {
|
|
349
|
+
switch (action) {
|
|
350
|
+
case 'select':
|
|
351
|
+
return carry ? dropHeld() : pickUp();
|
|
352
|
+
case 'back':
|
|
353
|
+
return cancelHeld();
|
|
354
|
+
case 'secondary':
|
|
355
|
+
return context(focusIdx);
|
|
356
|
+
case 'left':
|
|
357
|
+
return stepFocus(-1, 0);
|
|
358
|
+
case 'right':
|
|
359
|
+
return stepFocus(1, 0);
|
|
360
|
+
case 'up':
|
|
361
|
+
return stepFocus(0, -1);
|
|
362
|
+
case 'down':
|
|
363
|
+
return stepFocus(0, 1);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
// ---------------------------------------------------------------- events
|
|
367
|
+
let holdFired = false;
|
|
368
|
+
element.addEventListener('keydown', (e) => {
|
|
369
|
+
let handled = true;
|
|
370
|
+
switch (e.key) {
|
|
371
|
+
case 'ArrowLeft':
|
|
372
|
+
stepFocus(-1, 0);
|
|
373
|
+
break;
|
|
374
|
+
case 'ArrowRight':
|
|
375
|
+
stepFocus(1, 0);
|
|
376
|
+
break;
|
|
377
|
+
case 'ArrowUp':
|
|
378
|
+
stepFocus(0, -1);
|
|
379
|
+
break;
|
|
380
|
+
case 'ArrowDown':
|
|
381
|
+
stepFocus(0, 1);
|
|
382
|
+
break;
|
|
383
|
+
case 'Home':
|
|
384
|
+
setFocus(0, focused.row, true);
|
|
385
|
+
break;
|
|
386
|
+
case 'End':
|
|
387
|
+
setFocus(cols - 1, focused.row, true);
|
|
388
|
+
break;
|
|
389
|
+
case 'Enter':
|
|
390
|
+
case ' ':
|
|
391
|
+
if (e.repeat) {
|
|
392
|
+
if (!holdFired && !carry) {
|
|
393
|
+
holdFired = true;
|
|
394
|
+
pickUp();
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
else if (carry)
|
|
398
|
+
dropHeld();
|
|
399
|
+
else if (holdFired)
|
|
400
|
+
holdFired = false;
|
|
401
|
+
break;
|
|
402
|
+
case 'Escape':
|
|
403
|
+
if (carry)
|
|
404
|
+
cancelHeld();
|
|
405
|
+
else if (cardAnchor)
|
|
406
|
+
hideCard();
|
|
407
|
+
else
|
|
408
|
+
handled = false;
|
|
409
|
+
break;
|
|
410
|
+
case 'F10':
|
|
411
|
+
if (e.shiftKey)
|
|
412
|
+
context(focusIdx);
|
|
413
|
+
else
|
|
414
|
+
handled = false;
|
|
415
|
+
break;
|
|
416
|
+
case 'ContextMenu':
|
|
417
|
+
context(focusIdx);
|
|
418
|
+
break;
|
|
419
|
+
default:
|
|
420
|
+
handled = false;
|
|
421
|
+
}
|
|
422
|
+
if (handled) {
|
|
423
|
+
e.preventDefault();
|
|
424
|
+
e.stopPropagation();
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
element.addEventListener('keyup', (e) => {
|
|
428
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
429
|
+
if (!holdFired && !carry && !e.repeat && cells[focusIdx] === e.target) {
|
|
430
|
+
// A tap of Enter or Space activates on release, so a hold never also activates.
|
|
431
|
+
activate();
|
|
432
|
+
}
|
|
433
|
+
holdFired = false;
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
element.addEventListener('focusin', (e) => {
|
|
437
|
+
const i = cellIndexOf(e.target);
|
|
438
|
+
if (i < 0)
|
|
439
|
+
return;
|
|
440
|
+
if (i !== focusIdx)
|
|
441
|
+
setFocus(i % cols, Math.floor(i / cols), false);
|
|
442
|
+
// Entering from outside (Tab, a carry-in from the neighbour grid) is a focus change too.
|
|
443
|
+
else if (!element.contains(e.relatedTarget))
|
|
444
|
+
opts.onFocus?.(focused);
|
|
445
|
+
showCard(i);
|
|
446
|
+
});
|
|
447
|
+
element.addEventListener('focusout', (e) => {
|
|
448
|
+
if (e.relatedTarget && element.contains(e.relatedTarget))
|
|
449
|
+
return;
|
|
450
|
+
hideCard();
|
|
451
|
+
});
|
|
452
|
+
element.addEventListener('pointerover', (e) => {
|
|
453
|
+
const i = cellIndexOf(e.target);
|
|
454
|
+
if (i < 0 || hoverTimer !== null)
|
|
455
|
+
return;
|
|
456
|
+
hoverTimer = setTimeout(() => {
|
|
457
|
+
hoverTimer = null;
|
|
458
|
+
if (!isDragging())
|
|
459
|
+
showCard(i);
|
|
460
|
+
}, hoverMs);
|
|
461
|
+
});
|
|
462
|
+
element.addEventListener('pointerout', (e) => {
|
|
463
|
+
if (e.relatedTarget && element.contains(e.relatedTarget)) {
|
|
464
|
+
const from = cellIndexOf(e.target);
|
|
465
|
+
const to = cellIndexOf(e.relatedTarget);
|
|
466
|
+
if (from === to)
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (hoverTimer !== null) {
|
|
470
|
+
clearTimeout(hoverTimer);
|
|
471
|
+
hoverTimer = null;
|
|
472
|
+
}
|
|
473
|
+
if (cardAnchor && element.ownerDocument.activeElement !== cardAnchor)
|
|
474
|
+
hideCard();
|
|
475
|
+
});
|
|
476
|
+
element.addEventListener('pointerdown', (e) => {
|
|
477
|
+
const i = cellIndexOf(e.target);
|
|
478
|
+
if (i < 0)
|
|
479
|
+
return;
|
|
480
|
+
const c = i % cols;
|
|
481
|
+
const r = Math.floor(i / cols);
|
|
482
|
+
if (e.button === 2)
|
|
483
|
+
return; // contextmenu follows
|
|
484
|
+
if (e.button !== 0)
|
|
485
|
+
return;
|
|
486
|
+
setFocus(c, r, true);
|
|
487
|
+
const pick = pickFrom(i);
|
|
488
|
+
if (pick && self.link) {
|
|
489
|
+
hideCard();
|
|
490
|
+
self.link.pointerStart(pick, e);
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
element.addEventListener('click', (e) => {
|
|
494
|
+
const i = cellIndexOf(e.target);
|
|
495
|
+
if (i < 0 || e.button !== 0)
|
|
496
|
+
return;
|
|
497
|
+
if (carry) {
|
|
498
|
+
setFocus(i % cols, Math.floor(i / cols), true);
|
|
499
|
+
dropHeld();
|
|
500
|
+
}
|
|
501
|
+
else if (!isDragging())
|
|
502
|
+
activate();
|
|
503
|
+
});
|
|
504
|
+
element.addEventListener('contextmenu', (e) => {
|
|
505
|
+
const i = cellIndexOf(e.target);
|
|
506
|
+
if (i < 0)
|
|
507
|
+
return;
|
|
508
|
+
e.preventDefault();
|
|
509
|
+
e.stopPropagation();
|
|
510
|
+
context(i);
|
|
511
|
+
});
|
|
512
|
+
const isDragging = () => self.link?.pointerActive() ?? false;
|
|
513
|
+
// ---------------------------------------------------------------- DropTarget
|
|
514
|
+
function spotAt(x, y) {
|
|
515
|
+
const r = element.getBoundingClientRect();
|
|
516
|
+
if (x < r.left || y < r.top || x >= r.right || y >= r.bottom)
|
|
517
|
+
return null;
|
|
518
|
+
const cell0 = cells[0].getBoundingClientRect();
|
|
519
|
+
const pitchX = cols > 1 ? cells[1].getBoundingClientRect().left - cell0.left : cell0.width;
|
|
520
|
+
const pitchY = rows > 1 ? cells[cols].getBoundingClientRect().top - cell0.top : cell0.height;
|
|
521
|
+
const c = Math.floor((x - cell0.left) / pitchX);
|
|
522
|
+
const rr = Math.floor((y - cell0.top) / pitchY);
|
|
523
|
+
if (!inBounds(c, rr))
|
|
524
|
+
return null;
|
|
525
|
+
return spots[idx(c, rr)];
|
|
526
|
+
}
|
|
527
|
+
function canDrop(spot, pick) {
|
|
528
|
+
const own = pick.source === self;
|
|
529
|
+
const ignore = own ? idx(pick.from.col, pick.from.row) : -2;
|
|
530
|
+
if (!fits(spot.col, spot.row, pick.item, ignore))
|
|
531
|
+
return false;
|
|
532
|
+
if (!opts.canDrop)
|
|
533
|
+
return true;
|
|
534
|
+
scratchTo.grid = self;
|
|
535
|
+
scratchTo.col = spot.col;
|
|
536
|
+
scratchTo.row = spot.row;
|
|
537
|
+
return opts.canDrop(pick.from, scratchTo, pick.item);
|
|
538
|
+
}
|
|
539
|
+
function drop(spot, pick) {
|
|
540
|
+
const to = { grid: self, col: spot.col, row: spot.row };
|
|
541
|
+
if (pick.source === self)
|
|
542
|
+
move(pick.from, spot);
|
|
543
|
+
else
|
|
544
|
+
set(spot, pick.item);
|
|
545
|
+
opts.onMove?.(pick.from, to, pick.item);
|
|
546
|
+
}
|
|
547
|
+
function release(pick, to) {
|
|
548
|
+
set(pick.from, null);
|
|
549
|
+
opts.onMove?.(pick.from, to, pick.item);
|
|
550
|
+
}
|
|
551
|
+
function hover(spot, reject) {
|
|
552
|
+
clearOver();
|
|
553
|
+
if (!spot)
|
|
554
|
+
return;
|
|
555
|
+
spot.el.setAttribute('data-over', '');
|
|
556
|
+
if (reject)
|
|
557
|
+
spot.el.setAttribute('data-reject', '');
|
|
558
|
+
}
|
|
559
|
+
function pickAt(x, y) {
|
|
560
|
+
const spot = spotAt(x, y);
|
|
561
|
+
return spot ? pickFrom(idx(spot.col, spot.row)) : null;
|
|
562
|
+
}
|
|
563
|
+
function pickFrom(i) {
|
|
564
|
+
const a = cover[i];
|
|
565
|
+
if (a === -1)
|
|
566
|
+
return null;
|
|
567
|
+
const item = anchors[a];
|
|
568
|
+
if (item.locked)
|
|
569
|
+
return null;
|
|
570
|
+
return { item, from: { grid: self, col: a % cols, row: Math.floor(a / cols) }, source: self };
|
|
571
|
+
}
|
|
572
|
+
const self = {
|
|
573
|
+
element,
|
|
574
|
+
cols,
|
|
575
|
+
rows,
|
|
576
|
+
get grid() {
|
|
577
|
+
return self;
|
|
578
|
+
},
|
|
579
|
+
link: null,
|
|
580
|
+
set,
|
|
581
|
+
get,
|
|
582
|
+
find,
|
|
583
|
+
move,
|
|
584
|
+
get items() {
|
|
585
|
+
const out = [];
|
|
586
|
+
for (let i = 0; i < n; i++) {
|
|
587
|
+
const item = anchors[i];
|
|
588
|
+
if (item)
|
|
589
|
+
out.push({ col: i % cols, row: Math.floor(i / cols), item });
|
|
590
|
+
}
|
|
591
|
+
return out;
|
|
592
|
+
},
|
|
593
|
+
focus(cell) {
|
|
594
|
+
setFocus(cell.col, cell.row, true);
|
|
595
|
+
},
|
|
596
|
+
get focused() {
|
|
597
|
+
return focused;
|
|
598
|
+
},
|
|
599
|
+
get held() {
|
|
600
|
+
return carry?.item ?? null;
|
|
601
|
+
},
|
|
602
|
+
act,
|
|
603
|
+
clear() {
|
|
604
|
+
for (let i = 0; i < n; i++)
|
|
605
|
+
if (anchors[i])
|
|
606
|
+
unplace(i);
|
|
607
|
+
},
|
|
608
|
+
remove() {
|
|
609
|
+
hideCard();
|
|
610
|
+
if (carry)
|
|
611
|
+
cancelHeld();
|
|
612
|
+
element.remove();
|
|
613
|
+
},
|
|
614
|
+
spotAt,
|
|
615
|
+
spots: () => spots,
|
|
616
|
+
canDrop,
|
|
617
|
+
drop,
|
|
618
|
+
release,
|
|
619
|
+
hover,
|
|
620
|
+
pickAt,
|
|
621
|
+
carryIn,
|
|
622
|
+
carryEnd,
|
|
623
|
+
};
|
|
624
|
+
return self;
|
|
625
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type InventoryHost } from './inventory.js';
|
|
2
|
+
export interface RadialItem {
|
|
3
|
+
id: string;
|
|
4
|
+
icon: string | HTMLElement | HTMLCanvasElement;
|
|
5
|
+
label: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface RadialOptions {
|
|
9
|
+
/** Four to eight items; fewer or more are clamped. */
|
|
10
|
+
items: RadialItem[];
|
|
11
|
+
/** Ring radius, theme px. Default 110. */
|
|
12
|
+
radius?: number;
|
|
13
|
+
/** Aim length under which nothing is highlighted (0..1). Default 0.35. */
|
|
14
|
+
deadzone?: number;
|
|
15
|
+
onPick: (id: string) => void;
|
|
16
|
+
onCancel?: () => void;
|
|
17
|
+
/** Accessible name. Default `Radial menu`. */
|
|
18
|
+
label?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface Radial {
|
|
21
|
+
readonly element: HTMLElement;
|
|
22
|
+
/** Show, centred at `at` (client CSS px) or at the frame's centre; takes the focus. */
|
|
23
|
+
open(at?: {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
}): void;
|
|
27
|
+
/** Hide without picking; the focus returns to where it was. */
|
|
28
|
+
close(): void;
|
|
29
|
+
/** Aim from a stick or a drag, -1..1 on both axes; outside the dead zone the sector is highlighted. */
|
|
30
|
+
aim(x: number, y: number): void;
|
|
31
|
+
/** The highlighted sector, or -1. */
|
|
32
|
+
readonly highlighted: number;
|
|
33
|
+
/** Fire `onPick` for the highlighted item (if any, and enabled) and close. */
|
|
34
|
+
pick(): boolean;
|
|
35
|
+
readonly visible: boolean;
|
|
36
|
+
remove(): void;
|
|
37
|
+
}
|
|
38
|
+
/** A radial menu on the host's `hud` layer. See the module comment. */
|
|
39
|
+
export declare function radial(host: InventoryHost, opts: RadialOptions): Radial;
|