roamwright 0.20.1 → 0.54.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/.prettierrc.yaml +12 -0
- package/CONTRIBUTING.md +19 -14
- package/README.md +35 -16
- package/examples/animals.html +49 -0
- package/examples/animals.js +209 -0
- package/examples/crowds.html +50 -0
- package/examples/crowds.js +268 -0
- package/examples/effects.html +53 -0
- package/examples/effects.js +343 -0
- package/examples/figure-motion.html +55 -0
- package/examples/figure-motion.js +265 -0
- package/examples/figure.html +49 -0
- package/examples/figure.js +238 -0
- package/examples/fliers.html +53 -0
- package/examples/fliers.js +292 -0
- package/examples/fortification.html +54 -0
- package/examples/fortification.js +288 -0
- package/examples/house-kit.html +48 -0
- package/examples/house-kit.js +175 -0
- package/examples/index.html +26 -16
- package/examples/island.html +48 -0
- package/examples/island.js +134 -52
- package/examples/land.html +54 -0
- package/examples/land.js +392 -0
- package/examples/props-and-plants.html +53 -0
- package/examples/props-and-plants.js +275 -0
- package/examples/rooms.html +48 -0
- package/examples/rooms.js +242 -0
- package/examples/ships.html +51 -0
- package/examples/ships.js +235 -0
- package/examples/showcase.css +320 -0
- package/examples/small-world-land.js +151 -0
- package/examples/small-world-life.js +160 -0
- package/examples/small-world-town.js +127 -0
- package/examples/small-world.html +57 -0
- package/examples/small-world.js +226 -0
- package/examples/soundscape.html +138 -0
- package/examples/soundscape.js +467 -0
- package/examples/stage-kits.js +300 -0
- package/examples/stage.js +374 -0
- package/examples/towns.html +50 -0
- package/examples/towns.js +325 -0
- package/examples/viaduct-camera.js +8 -4
- package/examples/viaduct-landscape.js +28 -17
- package/examples/viaduct.html +45 -43
- package/examples/viaduct.js +68 -92
- package/geometry/animal-camel-body.js +410 -0
- package/geometry/animal-camel-head.js +118 -0
- package/geometry/animal-canine-body.js +361 -0
- package/geometry/animal-canine-breeds.js +316 -0
- package/geometry/animal-canine-head.js +337 -0
- package/geometry/animal-cattle-body.js +391 -0
- package/geometry/animal-cattle-coat.js +42 -0
- package/geometry/animal-cattle-head.js +152 -0
- package/geometry/animal-hen.js +248 -0
- package/geometry/animal-horse-body.js +446 -0
- package/geometry/animal-horse-bridle.js +171 -0
- package/geometry/animal-horse-coat.js +68 -0
- package/geometry/animal-horse-face.js +162 -0
- package/geometry/animal-horse-hair.js +304 -0
- package/geometry/animal-horse-head.js +133 -0
- package/geometry/animal-horse-tack.js +157 -0
- package/geometry/animal-options.js +59 -0
- package/geometry/animal-shapes.js +21 -0
- package/geometry/animal-skin.js +390 -0
- package/geometry/builder-cells.js +10 -2
- package/geometry/builder-frame.js +2 -1
- package/geometry/builder.js +15 -4
- package/geometry/card-emblem.js +437 -0
- package/geometry/catenary-canvas.js +396 -0
- package/geometry/cloth-folds.js +143 -0
- package/geometry/crawl-shapes.js +71 -0
- package/geometry/creased-sheet.js +7 -2
- package/geometry/crowd-dress.js +315 -0
- package/geometry/crowd-far.js +174 -0
- package/geometry/crowd-look.js +42 -0
- package/geometry/crowd-weld.js +218 -0
- package/geometry/ear.js +9 -4
- package/geometry/erosion.js +7 -4
- package/geometry/face-grid.js +26 -6
- package/geometry/field-map.js +59 -0
- package/geometry/figure-arms.js +339 -0
- package/geometry/figure-beard.js +250 -0
- package/geometry/figure-body.js +297 -0
- package/geometry/figure-bow.js +105 -0
- package/geometry/figure-cloak.js +189 -0
- package/geometry/figure-clothes.js +337 -0
- package/geometry/figure-face-grids.js +75 -0
- package/geometry/figure-gear.js +446 -0
- package/geometry/figure-hair-far.js +151 -0
- package/geometry/figure-hair-hangs.js +108 -0
- package/geometry/figure-hair-patch.js +66 -0
- package/geometry/figure-hair.js +320 -0
- package/geometry/figure-hands.js +321 -0
- package/geometry/figure-head-features.js +280 -0
- package/geometry/figure-head.js +375 -0
- package/geometry/figure-headwear.js +223 -0
- package/geometry/figure-legs.js +231 -0
- package/geometry/figure-limbs.js +39 -0
- package/geometry/figure-sculpt.js +82 -0
- package/geometry/figure-skin.js +97 -0
- package/geometry/figure-skirts.js +303 -0
- package/geometry/figure-trunk.js +411 -0
- package/geometry/flier-corvid-body.js +322 -0
- package/geometry/flier-corvid-wings.js +154 -0
- package/geometry/flier-long-body.js +195 -0
- package/geometry/flier-shapes.js +219 -0
- package/geometry/flier-soaring-bird.js +84 -0
- package/geometry/foliage.js +177 -4
- package/geometry/fort-city-walls.js +479 -0
- package/geometry/fort-gate-approach.js +233 -0
- package/geometry/fort-great-walls.js +280 -0
- package/geometry/fort-keep.js +297 -0
- package/geometry/fort-parts.js +261 -0
- package/geometry/fort-polyline.js +261 -0
- package/geometry/fort-portal.js +96 -0
- package/geometry/fort-ring-wall.js +267 -0
- package/geometry/fort-seawall.js +104 -0
- package/geometry/fort-terrace-gates.js +323 -0
- package/geometry/fort-terrace-plan.js +250 -0
- package/geometry/fort-terrace-wall.js +345 -0
- package/geometry/garment-tags.js +11 -3
- package/geometry/grid-gather.js +69 -0
- package/geometry/grid-sample.js +185 -0
- package/geometry/hair-gathers.js +19 -4
- package/geometry/hair-locks.js +1 -1
- package/geometry/hair-patch.js +6 -2
- package/geometry/hair-shell.js +14 -2
- package/geometry/head-presets.js +103 -0
- package/geometry/head-profile.js +13 -2
- package/geometry/head-shape.js +51 -23
- package/geometry/heightfield.js +26 -9
- package/geometry/horizon-angles.js +166 -0
- package/geometry/house-kit-body.js +195 -0
- package/geometry/house-kit-courtyard-parts.js +340 -0
- package/geometry/house-kit-courtyard-roof.js +223 -0
- package/geometry/house-kit-courtyard.js +409 -0
- package/geometry/house-kit-cut.js +29 -0
- package/geometry/house-kit-extras.js +192 -0
- package/geometry/house-kit-forms.js +298 -0
- package/geometry/house-kit-frame.js +74 -0
- package/geometry/house-kit-marks.js +93 -0
- package/geometry/house-kit-openings.js +193 -0
- package/geometry/house-kit-palette.js +54 -0
- package/geometry/house-kit-pool.js +71 -0
- package/geometry/house-kit-roofs.js +151 -0
- package/geometry/house-kit.js +202 -0
- package/geometry/instances.js +4 -4
- package/geometry/lamp-wash.js +65 -0
- package/geometry/land-clearings.js +83 -0
- package/geometry/land-ditches.js +290 -0
- package/geometry/land-dry-basin.js +327 -0
- package/geometry/land-dunes.js +150 -0
- package/geometry/land-earthworks.js +432 -0
- package/geometry/land-edge.js +292 -0
- package/geometry/land-mound-faces.js +349 -0
- package/geometry/land-near-relief.js +102 -0
- package/geometry/land-sheet.js +220 -0
- package/geometry/land-town-ground.js +256 -0
- package/geometry/land-waters.js +228 -0
- package/geometry/land-wildness.js +123 -0
- package/geometry/lathed-vessel.js +293 -0
- package/geometry/outline-grid.js +5 -4
- package/geometry/outline-segments.js +74 -0
- package/geometry/part-ranges.js +35 -0
- package/geometry/path-field.js +35 -1
- package/geometry/planked-floor.js +149 -0
- package/geometry/plant-broadleaf.js +268 -0
- package/geometry/plant-shrub.js +198 -0
- package/geometry/plant-tints.js +80 -0
- package/geometry/plant-trees.js +453 -0
- package/geometry/plant-tussock.js +107 -0
- package/geometry/primitives.js +65 -23
- package/geometry/prop-battlefield.js +69 -0
- package/geometry/prop-camp.js +175 -0
- package/geometry/prop-door.js +26 -0
- package/geometry/prop-harbour.js +105 -0
- package/geometry/prop-haycock.js +60 -0
- package/geometry/prop-sacks.js +74 -0
- package/geometry/prop-sheaf.js +68 -0
- package/geometry/prop-street.js +69 -0
- package/geometry/prop-tents.js +396 -0
- package/geometry/prop-tombs.js +80 -0
- package/geometry/prop-trade.js +393 -0
- package/geometry/prop-vehicles.js +218 -0
- package/geometry/props.js +58 -0
- package/geometry/room-arcade.js +134 -0
- package/geometry/room-dome.js +188 -0
- package/geometry/room-flames.js +138 -0
- package/geometry/room-frame.js +106 -0
- package/geometry/room-furniture.js +260 -0
- package/geometry/room-hearth.js +98 -0
- package/geometry/room-kit.js +59 -0
- package/geometry/room-openings.js +142 -0
- package/geometry/room-stairs.js +180 -0
- package/geometry/room-surfaces.js +272 -0
- package/geometry/sampled-surface.js +24 -10
- package/geometry/scatter-grid.js +6 -3
- package/geometry/sculpt.js +5 -1
- package/geometry/ship-fittings.js +350 -0
- package/geometry/ship-hull.js +460 -0
- package/geometry/ship-kit.js +208 -0
- package/geometry/ship-lines.js +69 -0
- package/geometry/ship-oars.js +150 -0
- package/geometry/ship-presets.js +131 -0
- package/geometry/ship-rig.js +374 -0
- package/geometry/ship-sails.js +148 -0
- package/geometry/shore-grid.js +5 -1
- package/geometry/strata-field.js +44 -11
- package/geometry/strata-tiles.js +20 -6
- package/geometry/stream.js +32 -17
- package/geometry/swept-tube.js +124 -0
- package/geometry/terrain-chunks.js +139 -51
- package/geometry/terrain-extension.js +24 -8
- package/geometry/town-courtyard-inn.js +272 -0
- package/geometry/town-ground.js +76 -0
- package/geometry/town-houses.js +343 -0
- package/geometry/town-lights.js +254 -0
- package/geometry/town-lots.js +172 -0
- package/geometry/town-plan.js +370 -0
- package/geometry/town-works.js +465 -0
- package/geometry/village-layout.js +181 -0
- package/geometry/village-yards.js +167 -0
- package/geometry/wall-runs.js +64 -0
- package/index.js +134 -3
- package/math/cloud-textures.js +3 -7
- package/math/curve.js +5 -1
- package/math/lamp-texels.js +43 -0
- package/math/lit-share.js +22 -0
- package/math/mountain-ranges.js +177 -54
- package/math/periodic.js +6 -0
- package/math/rectangles.js +8 -2
- package/math/rock-texture.js +17 -12
- package/math/surface-textures.js +24 -9
- package/math/wandering-path.js +40 -0
- package/math/ways.js +120 -0
- package/motion/action-dynamics.js +398 -0
- package/motion/animal-bearing.js +247 -0
- package/motion/animal-canine-bearing.js +178 -0
- package/motion/animal-canine-cast.js +131 -0
- package/motion/animal-cattle-cast.js +64 -0
- package/motion/animal-herd-cast.js +154 -0
- package/motion/animal-horse-still.js +161 -0
- package/motion/animal-troop-cast.js +43 -0
- package/motion/arm-reach.js +3 -2
- package/motion/ballistic-arc.js +182 -2
- package/motion/biped-cycle.js +4 -2
- package/motion/biped-leg.js +4 -1
- package/motion/biped-posture.js +459 -0
- package/motion/biped-stride.js +142 -32
- package/motion/boat-sailing.js +214 -0
- package/motion/contact-transition.js +5 -6
- package/motion/crowd-alarms.js +36 -6
- package/motion/crowd-attention.js +108 -0
- package/motion/crowd-beasts.js +203 -0
- package/motion/crowd-camp.js +295 -0
- package/motion/crowd-figure.js +100 -0
- package/motion/crowd-herd.js +86 -0
- package/motion/crowd-hold.js +130 -0
- package/motion/crowd-pose.js +296 -0
- package/motion/crowd-poses.js +481 -0
- package/motion/crowd-routine.js +44 -14
- package/motion/crowd-town.js +166 -0
- package/motion/crowd-water.js +143 -0
- package/motion/deck-surface.js +4 -2
- package/motion/figure-acts.js +411 -0
- package/motion/figure-arms.js +437 -0
- package/motion/figure-blade-slide.js +149 -0
- package/motion/figure-body-place.js +180 -0
- package/motion/figure-bones.js +118 -0
- package/motion/figure-bow-draw.js +70 -0
- package/motion/figure-fingers.js +215 -0
- package/motion/figure-gaze.js +205 -0
- package/motion/figure-gestures.js +452 -0
- package/motion/figure-grip.js +134 -0
- package/motion/figure-head.js +287 -0
- package/motion/figure-legs.js +264 -0
- package/motion/figure-links.js +293 -0
- package/motion/figure-locomotion.js +391 -0
- package/motion/figure-mount-up.js +180 -0
- package/motion/figure-mount.js +201 -0
- package/motion/figure-pose-frame.js +375 -0
- package/motion/figure-pose-table.js +156 -0
- package/motion/figure-pose.js +343 -0
- package/motion/figure-seat.js +267 -0
- package/motion/figure-sway.js +125 -0
- package/motion/flier-corvid-pose.js +74 -0
- package/motion/flier-flight-air.js +122 -0
- package/motion/flier-flight-echelon.js +164 -0
- package/motion/flier-flight-roost.js +131 -0
- package/motion/flier-swarm-flight.js +252 -0
- package/motion/formation.js +193 -0
- package/motion/instance-sight.js +8 -1
- package/motion/melee-contact.js +143 -0
- package/motion/moorings.js +48 -0
- package/motion/path-steering.js +358 -0
- package/motion/player.js +7 -6
- package/motion/quadruped.js +109 -33
- package/motion/spaces.js +58 -6
- package/motion/speech-cadence.js +304 -0
- package/motion/vessel-motion.js +57 -0
- package/motion/walk-grid.js +235 -0
- package/motion/weather.js +70 -12
- package/motion/wind.js +27 -1
- package/package.json +27 -4
- package/rendering/alpha-mips.js +340 -0
- package/rendering/animal-camel-figure.js +29 -0
- package/rendering/animal-canine-figure.js +59 -0
- package/rendering/animal-cattle-figure.js +36 -0
- package/rendering/animal-horse-figure.js +49 -0
- package/rendering/atmosphere.js +86 -0
- package/rendering/camera-track.js +156 -0
- package/rendering/{road-surface.js → cart-track.js} +40 -11
- package/rendering/caster-motion.js +2 -1
- package/rendering/cell-lod-options.js +46 -0
- package/rendering/cell-lod.js +665 -80
- package/rendering/cloth-material.js +140 -0
- package/rendering/cloud-dome.js +2 -2
- package/rendering/compilation-schedule.js +18 -10
- package/rendering/contact-shadows.js +5 -2
- package/rendering/context.js +47 -8
- package/rendering/crowd-batches.js +420 -0
- package/rendering/crowd-herd.js +198 -0
- package/rendering/crowd-rig.js +132 -0
- package/rendering/crowd-skinning.js +52 -9
- package/rendering/crowd-update.js +419 -0
- package/rendering/crowd-visibility.js +107 -0
- package/rendering/day-cycle-defaults.js +200 -0
- package/rendering/day-cycle.js +487 -0
- package/rendering/daylight.js +1 -3
- package/rendering/detail-range.js +6 -5
- package/rendering/dof.js +11 -4
- package/rendering/effects-frame.js +149 -0
- package/rendering/effects-water-rises.js +221 -0
- package/rendering/energy-stream.js +128 -0
- package/rendering/facade-glass-material.js +105 -0
- package/rendering/far-shadow.js +81 -54
- package/rendering/field-surface.js +138 -0
- package/rendering/figure-shield.js +105 -0
- package/rendering/figure-skeleton.js +329 -0
- package/rendering/fire-light-watch.js +197 -0
- package/rendering/fire-pools.js +148 -0
- package/rendering/flame-sources.js +86 -0
- package/rendering/flier-bird-looks.js +97 -0
- package/rendering/flier-corvid-figure.js +67 -0
- package/rendering/flier-long-body-company.js +169 -0
- package/rendering/flier-swarm.js +186 -0
- package/rendering/flocks.js +6 -2
- package/rendering/garment-material.js +145 -49
- package/rendering/glsl-literal.js +19 -0
- package/rendering/ground-marks.js +316 -0
- package/rendering/hair-strands.js +38 -24
- package/rendering/height-haze.js +80 -33
- package/rendering/height-probe.js +15 -3
- package/rendering/house-kit-meshes.js +124 -0
- package/rendering/interior-bake.js +807 -0
- package/rendering/label-layout.js +13 -3
- package/rendering/label-range.js +5 -2
- package/rendering/lamp-light-map.js +159 -0
- package/rendering/lamp-maps.js +62 -0
- package/rendering/lamp-wash.js +51 -0
- package/rendering/light-budget.js +19 -3
- package/rendering/light-points.js +21 -5
- package/rendering/local-lights.js +27 -7
- package/rendering/material-lod.js +5 -6
- package/rendering/memory-estimate.js +84 -0
- package/rendering/moored-fleet.js +186 -0
- package/rendering/part-costs.js +104 -0
- package/rendering/particle-bursts.js +386 -0
- package/rendering/particle-emitters.js +61 -25
- package/rendering/particle-light-bursts.js +189 -0
- package/rendering/particles.js +134 -34
- package/rendering/pen-flocks.js +118 -0
- package/rendering/piece-batch.js +282 -6
- package/rendering/planar-reflection-options.js +159 -0
- package/rendering/planar-reflection.js +780 -77
- package/rendering/plant-cells.js +122 -0
- package/rendering/plant-reeds.js +113 -0
- package/rendering/plant-shade-trees.js +239 -0
- package/rendering/plant-tuft-patch.js +122 -0
- package/rendering/post-shaders.js +84 -21
- package/rendering/post.js +39 -19
- package/rendering/pressed-cover.js +135 -0
- package/rendering/prop-dig.js +136 -0
- package/rendering/room-light.js +250 -0
- package/rendering/room-materials.js +78 -0
- package/rendering/room-space.js +111 -0
- package/rendering/scene-lights.js +106 -0
- package/rendering/sea-shaders.js +83 -26
- package/rendering/settlement-approach.js +226 -0
- package/rendering/settlement-dissolve.js +89 -0
- package/rendering/settlement-quarter-warm.js +55 -0
- package/rendering/settlement-quarter.js +477 -0
- package/rendering/settlement-switch.js +42 -0
- package/rendering/settlement-town.js +110 -0
- package/rendering/shader-warmup.js +80 -36
- package/rendering/shadow-depth.js +40 -18
- package/rendering/ship-meshes.js +150 -0
- package/rendering/shot-cuts.js +68 -0
- package/rendering/sky-occlusion.js +42 -15
- package/rendering/sky-pmrem.js +216 -0
- package/rendering/sky.js +112 -50
- package/rendering/smoke-shadows.js +201 -0
- package/rendering/stage-framing.js +182 -0
- package/rendering/stage-lights.js +46 -39
- package/rendering/stain-material.js +74 -0
- package/rendering/static-point-shadow.js +62 -23
- package/rendering/still-casters.js +77 -27
- package/rendering/strata-material.js +2 -2
- package/rendering/street-lamps.js +166 -0
- package/rendering/sunbeam-motes.js +670 -0
- package/rendering/surface-light.js +65 -6
- package/rendering/surface-material.js +306 -0
- package/rendering/surface-projection.js +32 -0
- package/rendering/surface-snippets.js +314 -0
- package/rendering/taa.js +49 -18
- package/rendering/tree-impostor.js +929 -0
- package/rendering/vehicle-train.js +92 -0
- package/rendering/viewport.js +67 -4
- package/rendering/water-material.js +270 -82
- package/rendering/waypoint-beacons.js +191 -0
- package/rendering/world-matrices.js +0 -2
- package/ruff.toml +20 -0
- package/runtime/cue-cursor.js +21 -0
- package/runtime/device-quality.js +13 -2
- package/runtime/device.js +73 -0
- package/runtime/diagnostic-log.js +11 -3
- package/runtime/effect-sites.js +85 -0
- package/runtime/figure-orders.js +59 -0
- package/runtime/first-use.js +8 -5
- package/runtime/foley-script.js +124 -0
- package/runtime/foley-strides.js +333 -0
- package/runtime/frame-pacing.js +18 -4
- package/runtime/frame-yield.js +18 -0
- package/runtime/gpu-timing.js +8 -4
- package/runtime/grid-cache.js +16 -6
- package/runtime/grid-rows.js +5 -5
- package/runtime/hand-over.js +7 -2
- package/runtime/land-bake.js +78 -0
- package/runtime/lazy-sets.js +105 -0
- package/runtime/pool.js +17 -3
- package/runtime/quality-fit.js +59 -27
- package/runtime/region-pass-lay.js +40 -0
- package/runtime/region-pass.js +78 -0
- package/runtime/search.js +6 -2
- package/runtime/settlement-reach.js +42 -0
- package/runtime/sound-calls.js +113 -0
- package/runtime/sound-impacts.js +297 -0
- package/runtime/sound-voices.js +194 -0
- package/runtime/soundscape.js +282 -0
- package/runtime/spatial-audio.js +69 -20
- package/runtime/steady-frames.js +221 -0
- package/runtime/withdrawable-task.js +19 -8
- package/scripts/app-parts.mjs +118 -0
- package/scripts/bake-revisions.mjs +81 -0
- package/scripts/browser-scripts.mjs +64 -0
- package/scripts/bundle.mjs +192 -0
- package/scripts/check-app.sh +26 -0
- package/scripts/eslint-config.mjs +119 -0
- package/scripts/format.sh +92 -0
- package/scripts/keep-builds.mjs +158 -0
- package/scripts/layers.mjs +112 -0
- package/scripts/lint.sh +49 -0
- package/scripts/module-graph.mjs +123 -0
- package/scripts/pre-commit.sh +38 -0
- package/scripts/serve.py +5 -3
- package/scripts/site.mjs +358 -0
- package/scripts/test-runner.sh +42 -0
- package/scripts/vendor.mjs +221 -0
- package/scripts/verify-publish.mjs +175 -0
- package/scripts/world.mk +59 -0
- package/tools/README.md +73 -0
- package/tools/contact-sheet.cjs +137 -0
- package/tools/cpu-profile.cjs +275 -0
- package/tools/cpu-profile.test.cjs +98 -0
- package/tools/first-draws.cjs +395 -0
- package/tools/flight-guard.cjs +482 -0
- package/tools/flight-guard.test.cjs +153 -0
- package/tools/flight-profile.cjs +145 -0
- package/tools/frame-bench.cjs +336 -0
- package/tools/frame-parts.cjs +365 -0
- package/tools/ios-sim.sh +145 -0
- package/tools/load-audit.cjs +201 -0
- package/tools/look-compare.cjs +304 -0
- package/tools/look-guard.cjs +407 -0
- package/tools/look-guard.test.cjs +93 -0
- package/tools/look-stats.cjs +185 -0
- package/tools/look-stats.test.cjs +71 -0
- package/tools/memory-audit.cjs +323 -0
- package/tools/page-driver.cjs +320 -0
- package/tools/page-driver.test.cjs +219 -0
- package/tools/program-census-report.cjs +191 -0
- package/tools/program-census.cjs +465 -0
- package/tools/program-census.test.cjs +332 -0
- package/tools/remote-runner.sh +265 -0
- package/tools/runners.test.cjs +59 -0
- package/tools/scene-audit-beat.cjs +344 -0
- package/tools/scene-audit-sheet.cjs +282 -0
- package/tools/scene-audit.cjs +471 -0
- package/tools/scene-audit.test.cjs +201 -0
- package/tools/scene-batch.cjs +219 -0
- package/tools/scene-bench.cjs +149 -0
- package/tools/scene-bench.test.cjs +33 -0
- package/tools/scene-run.cjs +443 -0
- package/tools/scene-run.test.cjs +94 -0
- package/tools/servers.sh +59 -0
- package/tools/shader-arrival.cjs +316 -0
- package/tools/shader-renewal.cjs +53 -0
- package/tools/shader-renewal.test.cjs +115 -0
- package/tools/speed-guard.cjs +258 -0
- package/tools/stills.cjs +492 -0
- package/tools/stills.test.cjs +49 -0
- package/tools/turns.sh +7 -0
- package/tools/yaml.cjs +158 -0
- package/examples/viaduct.css +0 -75
- package/rendering/light-shafts.js +0 -131
package/scripts/site.mjs
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
// Static site generator for worlds built on Roamwright.
|
|
2
|
+
// Copies content-hashed app bundles, Three.js, and Roamwright bundles into a publish directory,
|
|
3
|
+
// writes one SEO-annotated HTML page per world route, generates modulepreload tags, manifest,
|
|
4
|
+
// icons, service worker, sitemap.xml, robots.txt, root redirect index.html, and SPA 404.html.
|
|
5
|
+
import { execFileSync } from 'node:child_process';
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { cpSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
9
|
+
import { bundleInlineScripts, bundleScript } from './browser-scripts.mjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Escapes HTML special characters for safe attribute and text interpolation.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} s
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
export const escapeHtml = s => String(s).replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Clips a description string cleanly at a word boundary to at most `max` characters.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} s
|
|
23
|
+
* @param {number} [max=160]
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
export const clipDescription = (s, max = 160) =>
|
|
27
|
+
s.length <= max ? s : s.slice(0, s.lastIndexOf(' ', max - 1)).replace(/[,;:.]$/, '') + '…';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Computes startup modulepreload tags, per-land preload script, service-worker initial files,
|
|
31
|
+
* lazy parts map, and per-land scene script lists from `parts.json` and `roamwright.json`.
|
|
32
|
+
*
|
|
33
|
+
* @param {object} options
|
|
34
|
+
* @param {Record<string, string[]>} options.imports Parsed `app/parts.json`.
|
|
35
|
+
* @param {{ files: string[], preload: string[] }} options.engine Parsed `app/roamwright.json`.
|
|
36
|
+
* @param {string} options.base Base URL path (e.g. `'/world/'`).
|
|
37
|
+
* @param {string} options.appDir Content-hashed app folder name (e.g. `'app-0123456789/'`).
|
|
38
|
+
* @param {string} options.library URL of self-hosted Three.js module.
|
|
39
|
+
* @param {Record<string, string>} options.landParts Map from land id to land builder entry path in `imports`.
|
|
40
|
+
* @param {string} options.crossingStorageKey `sessionStorage` key recording an active cross-land transition.
|
|
41
|
+
* @param {string} [options.addonsPart='node_modules/three/examples/jsm/postprocessing/EffectComposer.js']
|
|
42
|
+
* @param {string} [options.sceneScriptPrefix='data/scene-scripts/']
|
|
43
|
+
* @param {(part: string) => string | null} [options.landPartForScene] Maps a scene-script part key to its land builder part key.
|
|
44
|
+
* @returns {{ preloads: string, landPreloads: (land: string) => string, firstFiles: string[], laterParts: Record<string, string[]>, landScenes: Record<string, string[]> }}
|
|
45
|
+
*/
|
|
46
|
+
export function computePreloads({
|
|
47
|
+
imports,
|
|
48
|
+
engine,
|
|
49
|
+
base,
|
|
50
|
+
appDir,
|
|
51
|
+
library,
|
|
52
|
+
landParts,
|
|
53
|
+
crossingStorageKey,
|
|
54
|
+
addonsPart = 'node_modules/three/examples/jsm/postprocessing/EffectComposer.js',
|
|
55
|
+
sceneScriptPrefix = 'data/scene-scripts/',
|
|
56
|
+
landPartForScene = null,
|
|
57
|
+
}) {
|
|
58
|
+
const href = file => `${base}${appDir}${file}`;
|
|
59
|
+
const engineURL = file => base + file;
|
|
60
|
+
const page = imports['main.js'];
|
|
61
|
+
const lands = {};
|
|
62
|
+
for (const [land, part] of Object.entries(landParts)) {
|
|
63
|
+
if (!imports[part]) throw new Error(`parts.json names no part for ${part}`);
|
|
64
|
+
lands[land] = imports[part].filter(file => !page.includes(file)).map(href);
|
|
65
|
+
}
|
|
66
|
+
const landPreloads = land =>
|
|
67
|
+
`<script>(()=>{const parts=${JSON.stringify(lands)};let land=/[?&]r=/.test(location.search)?null:${JSON.stringify(land)};try{land=JSON.parse(sessionStorage.getItem(${JSON.stringify(crossingStorageKey)})).land}catch{}for(const href of parts[land]??[])document.head.appendChild(Object.assign(document.createElement("link"),{rel:"modulepreload",href}))})()</script>`;
|
|
68
|
+
|
|
69
|
+
const isEntry = part => imports[part][0] === part.split('/').pop();
|
|
70
|
+
const entryFiles = Object.keys(imports)
|
|
71
|
+
.filter(isEntry)
|
|
72
|
+
.flatMap(part => imports[part]);
|
|
73
|
+
const addons = imports[addonsPart] ?? [];
|
|
74
|
+
const firstFiles = [library, ...engine.files.map(engineURL), ...new Set([...page, ...entryFiles, ...addons].map(href)), href('app.css')];
|
|
75
|
+
|
|
76
|
+
const landScenes = {};
|
|
77
|
+
if (landPartForScene) {
|
|
78
|
+
for (const part of Object.keys(imports).filter(p => p.startsWith(sceneScriptPrefix))) {
|
|
79
|
+
const land = landPartForScene(part);
|
|
80
|
+
if (land) (landScenes[land] ??= []).push(...imports[part].filter(file => !page.includes(file)));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const first = new Set(firstFiles);
|
|
85
|
+
const laterParts = Object.fromEntries(
|
|
86
|
+
Object.entries(imports)
|
|
87
|
+
.filter(([part, files]) => !isEntry(part) && !first.has(href(files[0])))
|
|
88
|
+
.map(([part, files]) => [part, files.filter(file => !first.has(href(file)))]),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
preloads: [library, ...engine.preload.map(engineURL), ...page.map(href)].map(h => `<link rel="modulepreload" href="${h}">`).join(''),
|
|
93
|
+
landPreloads,
|
|
94
|
+
firstFiles,
|
|
95
|
+
laterParts,
|
|
96
|
+
landScenes,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Generates the complete publish-only static site directory from a built `index.html` and `app/`.
|
|
102
|
+
*
|
|
103
|
+
* @param {object} config
|
|
104
|
+
* @param {string} config.built Path to built `index.html`.
|
|
105
|
+
* @param {string} config.outDir Subdirectory inside the site root (e.g. `.site/world`).
|
|
106
|
+
* @param {string} config.base URL base path (e.g. `'/world/'`).
|
|
107
|
+
* @param {string} config.origin Public origin (e.g. `'https://example.com'`).
|
|
108
|
+
* @param {string} config.siteName Human-readable site title.
|
|
109
|
+
* @param {Array<object>} config.pages Route descriptor list (`{ path, title, name, desc, text, section, links }`).
|
|
110
|
+
* @param {Record<string, string>} config.landParts Map from land id to land builder entry path.
|
|
111
|
+
* @param {(path: string) => string} config.landOfPath Maps a route path to its land id.
|
|
112
|
+
* @param {(part: string) => string | null} [config.landPartForScene] Maps a scene-script part key to its land builder part key.
|
|
113
|
+
* @param {string} config.crossingStorageKey `sessionStorage` key for cross-land navigation.
|
|
114
|
+
* @param {string[]} config.cleanDirs Top-level route directories wiped before regenerating.
|
|
115
|
+
* @param {object} config.homeJsonLd Additional JSON-LD properties merged onto the root WebSite/VideoGame schema object.
|
|
116
|
+
* @param {{ background: string, theme: string }} config.manifestColors Web app manifest colours.
|
|
117
|
+
* @param {number[]} [config.iconSizes=[180, 192, 512]]
|
|
118
|
+
* @param {(size: number) => Buffer} config.iconPng Procedural PNG icon renderer.
|
|
119
|
+
* @param {string} config.serviceWorkerSource Service worker template text with `__BUILD__`, `__BASE__`, `__FIRST__`, `__PARTS__`, `__SCENES__`.
|
|
120
|
+
* @param {string} [config.analyticsId=''] Optional Google Analytics measurement id (omitted when empty).
|
|
121
|
+
* @param {object} config.esbuild esbuild module for inline script and service worker minification.
|
|
122
|
+
* @param {string | number} config.revision Three.js `REVISION`.
|
|
123
|
+
* @param {string} config.vendorDir Path to local `vendor/` directory.
|
|
124
|
+
* @param {string} config.enginePackageDir Path to installed `roamwright` package directory.
|
|
125
|
+
* @param {string} config.repoRoot Repository root used for git `lastmod` lookup.
|
|
126
|
+
* @returns {{ pageCount: number, appDir: string, partCount: number, hash: string }}
|
|
127
|
+
*/
|
|
128
|
+
export function buildStaticSite({
|
|
129
|
+
built,
|
|
130
|
+
outDir,
|
|
131
|
+
base,
|
|
132
|
+
origin,
|
|
133
|
+
siteName,
|
|
134
|
+
pages,
|
|
135
|
+
landParts,
|
|
136
|
+
landOfPath,
|
|
137
|
+
landPartForScene = null,
|
|
138
|
+
crossingStorageKey,
|
|
139
|
+
cleanDirs = [],
|
|
140
|
+
homeJsonLd = {},
|
|
141
|
+
manifestColors = { background: '#070d10', theme: '#0d1420' },
|
|
142
|
+
iconSizes = [180, 192, 512],
|
|
143
|
+
iconPng,
|
|
144
|
+
serviceWorkerSource,
|
|
145
|
+
analyticsId = '',
|
|
146
|
+
esbuild,
|
|
147
|
+
revision,
|
|
148
|
+
vendorDir,
|
|
149
|
+
enginePackageDir,
|
|
150
|
+
repoRoot,
|
|
151
|
+
}) {
|
|
152
|
+
const url = p => origin + base + (p ? p + '/' : '');
|
|
153
|
+
let page = readFileSync(built, 'utf8');
|
|
154
|
+
const app = join(dirname(resolve(built)), 'app');
|
|
155
|
+
const PARTS_LIST = 'parts.json';
|
|
156
|
+
const BUILD_ONLY = new Set([PARTS_LIST, 'roamwright.json']);
|
|
157
|
+
const parts = readdirSync(app)
|
|
158
|
+
.filter(f => !BUILD_ONLY.has(f))
|
|
159
|
+
.sort();
|
|
160
|
+
if (!page.includes('"./app/main.js"') || !page.includes('"./app/app.css"')) {
|
|
161
|
+
throw new Error(`${built} does not name ./app/main.js and ./app/app.css: is it the built page?`);
|
|
162
|
+
}
|
|
163
|
+
const digest = createHash('sha1');
|
|
164
|
+
for (const part of parts) digest.update(part).update(readFileSync(join(app, part)));
|
|
165
|
+
const hash = digest.digest('hex').slice(0, 10);
|
|
166
|
+
const appDir = `app-${hash}/`;
|
|
167
|
+
page = page.replaceAll('"./app/', `"${base}${appDir}`);
|
|
168
|
+
|
|
169
|
+
const threeDir = `three-r${revision}/`;
|
|
170
|
+
const engine = JSON.parse(readFileSync(join(app, 'roamwright.json'), 'utf8'));
|
|
171
|
+
const library = `${base}${threeDir}three.module.min.js`;
|
|
172
|
+
const { preloads, landPreloads, firstFiles, laterParts, landScenes } = computePreloads({
|
|
173
|
+
imports: JSON.parse(readFileSync(join(app, PARTS_LIST), 'utf8')),
|
|
174
|
+
engine,
|
|
175
|
+
base,
|
|
176
|
+
appDir,
|
|
177
|
+
library,
|
|
178
|
+
landParts,
|
|
179
|
+
crossingStorageKey,
|
|
180
|
+
landPartForScene,
|
|
181
|
+
});
|
|
182
|
+
page = page.replace('</head>', preloads + '</head>');
|
|
183
|
+
|
|
184
|
+
mkdirSync(outDir, { recursive: true });
|
|
185
|
+
for (const f of readdirSync(outDir)) {
|
|
186
|
+
if (/^(?:app-[0-9a-f]+|three-r\d+)$/.test(f)) rmSync(join(outDir, f), { recursive: true, force: true });
|
|
187
|
+
}
|
|
188
|
+
for (const d of cleanDirs) rmSync(join(outDir, d), { recursive: true, force: true });
|
|
189
|
+
cpSync(app, join(outDir, appDir), { recursive: true, filter: f => !BUILD_ONLY.has(basename(f)) });
|
|
190
|
+
for (const part of parts.filter(part => part.endsWith('.js'))) {
|
|
191
|
+
const file = join(outDir, appDir, part);
|
|
192
|
+
writeFileSync(
|
|
193
|
+
file,
|
|
194
|
+
readFileSync(file, 'utf8').replaceAll('"../vendor/three/', `"../${threeDir}`).replaceAll('"../vendor/roamwright/', '"../roamwright/'),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
rmSync(join(outDir, threeDir), { recursive: true, force: true });
|
|
198
|
+
mkdirSync(join(outDir, threeDir));
|
|
199
|
+
for (const name of ['three.module.min.js', 'LICENSE']) cpSync(join(vendorDir, 'three', name), join(outDir, threeDir, name));
|
|
200
|
+
rmSync(join(outDir, 'roamwright'), { recursive: true, force: true });
|
|
201
|
+
for (const file of engine.files) {
|
|
202
|
+
const target = join(outDir, file);
|
|
203
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
204
|
+
writeFileSync(target, readFileSync(join(vendorDir, file), 'utf8').replaceAll('"../../three/', `"../../${threeDir}`));
|
|
205
|
+
}
|
|
206
|
+
cpSync(join(enginePackageDir, 'licenses'), join(outDir, 'licenses/roamwright'), { recursive: true });
|
|
207
|
+
cpSync(join(enginePackageDir, 'LICENSE'), join(outDir, 'licenses/roamwright/LICENSE'));
|
|
208
|
+
|
|
209
|
+
for (const size of iconSizes) writeFileSync(join(outDir, `icon-${size}.png`), iconPng(size));
|
|
210
|
+
writeFileSync(
|
|
211
|
+
join(outDir, 'manifest.webmanifest'),
|
|
212
|
+
JSON.stringify({
|
|
213
|
+
name: siteName,
|
|
214
|
+
short_name: siteName,
|
|
215
|
+
start_url: base,
|
|
216
|
+
scope: base,
|
|
217
|
+
display: 'fullscreen',
|
|
218
|
+
orientation: 'any',
|
|
219
|
+
background_color: manifestColors.background,
|
|
220
|
+
theme_color: manifestColors.theme,
|
|
221
|
+
icons: iconSizes.slice(1).map(size => ({
|
|
222
|
+
src: `${base}icon-${size}.png`,
|
|
223
|
+
sizes: `${size}x${size}`,
|
|
224
|
+
type: 'image/png',
|
|
225
|
+
purpose: 'any maskable',
|
|
226
|
+
})),
|
|
227
|
+
}),
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
function head(p) {
|
|
231
|
+
const desc = clipDescription(p.desc);
|
|
232
|
+
const crumbs = [{ name: siteName, item: url('') }];
|
|
233
|
+
if (p.section) crumbs.push({ name: p.section });
|
|
234
|
+
if (p.path) crumbs.push({ name: p.name, item: url(p.path) });
|
|
235
|
+
const data = p.path
|
|
236
|
+
? {
|
|
237
|
+
'@context': 'https://schema.org',
|
|
238
|
+
'@type': 'WebPage',
|
|
239
|
+
name: p.name,
|
|
240
|
+
description: desc,
|
|
241
|
+
url: url(p.path),
|
|
242
|
+
isPartOf: { '@id': url('') + '#site' },
|
|
243
|
+
breadcrumb: {
|
|
244
|
+
'@type': 'BreadcrumbList',
|
|
245
|
+
itemListElement: crumbs.map((c, i) => ({
|
|
246
|
+
'@type': 'ListItem',
|
|
247
|
+
position: i + 1,
|
|
248
|
+
name: c.name,
|
|
249
|
+
...(c.item && { item: c.item }),
|
|
250
|
+
})),
|
|
251
|
+
},
|
|
252
|
+
}
|
|
253
|
+
: {
|
|
254
|
+
'@context': 'https://schema.org',
|
|
255
|
+
'@type': ['WebSite', 'VideoGame'],
|
|
256
|
+
'@id': url('') + '#site',
|
|
257
|
+
name: siteName,
|
|
258
|
+
url: url(''),
|
|
259
|
+
description: desc,
|
|
260
|
+
inLanguage: 'en',
|
|
261
|
+
genre: ['Fantasy', 'Exploration'],
|
|
262
|
+
gamePlatform: 'Web browser',
|
|
263
|
+
applicationCategory: 'Game',
|
|
264
|
+
operatingSystem: 'Any',
|
|
265
|
+
...homeJsonLd,
|
|
266
|
+
};
|
|
267
|
+
return [
|
|
268
|
+
`<title>${escapeHtml(p.title)}</title>`,
|
|
269
|
+
`<meta name="description" content="${escapeHtml(desc)}">`,
|
|
270
|
+
`<link rel="canonical" href="${url(p.path)}">`,
|
|
271
|
+
`<link rel="manifest" href="${base}manifest.webmanifest">`,
|
|
272
|
+
`<link rel="apple-touch-icon" href="${base}icon-180.png">`,
|
|
273
|
+
`<meta property="og:type" content="website">`,
|
|
274
|
+
`<meta property="og:site_name" content="${siteName}">`,
|
|
275
|
+
`<meta property="og:title" content="${escapeHtml(p.title)}">`,
|
|
276
|
+
`<meta property="og:description" content="${escapeHtml(desc)}">`,
|
|
277
|
+
`<meta property="og:url" content="${url(p.path)}">`,
|
|
278
|
+
`<meta name="twitter:card" content="summary">`,
|
|
279
|
+
`<script type="application/ld+json">${JSON.stringify(data).replace(/</g, '\\u003c')}</script>`,
|
|
280
|
+
].join('');
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function card(p) {
|
|
284
|
+
const links = p.links
|
|
285
|
+
.map(
|
|
286
|
+
g =>
|
|
287
|
+
`<p><b>${escapeHtml(g.label)}</b> ${g.items.map(i => `<a href="${base}${i.path ? i.path + '/' : ''}">${escapeHtml(i.name)}</a>`).join(' · ')}</p>`,
|
|
288
|
+
)
|
|
289
|
+
.join('');
|
|
290
|
+
if (!p.path) return `<section id="t-route" class="t-index"><nav aria-label="Pages">${links}</nav></section>`;
|
|
291
|
+
return (
|
|
292
|
+
`<section id="t-route"><span>${escapeHtml(p.section ?? siteName)}</span><h1>${escapeHtml(p.name)}</h1><p>${escapeHtml(p.text ?? p.desc)}</p>` +
|
|
293
|
+
(links ? `<nav aria-label="Related pages">${links}</nav>` : '') +
|
|
294
|
+
'</section>'
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
writeFileSync(join(outDir, 'version.json'), JSON.stringify({ build: hash }));
|
|
299
|
+
writeFileSync(
|
|
300
|
+
join(outDir, 'sw.js'),
|
|
301
|
+
bundleScript(
|
|
302
|
+
esbuild,
|
|
303
|
+
serviceWorkerSource
|
|
304
|
+
.replace("'__BUILD__'", JSON.stringify(hash))
|
|
305
|
+
.replace("'__BASE__'", JSON.stringify(base))
|
|
306
|
+
.replace('__FIRST__', JSON.stringify(firstFiles))
|
|
307
|
+
.replace('__PARTS__', JSON.stringify(laterParts))
|
|
308
|
+
.replace('__SCENES__', JSON.stringify(landScenes)),
|
|
309
|
+
),
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
const countVisits = analyticsId
|
|
313
|
+
? `<script>if(!navigator.webdriver){window.dataLayer=window.dataLayer||[];window.gtag=function(){dataLayer.push(arguments)};gtag('js',new Date());gtag('config','${analyticsId}');const t=document.createElement('script');t.async=true;t.src='https://www.googletagmanager.com/gtag/js?id=${analyticsId}';document.head.appendChild(t)}</script>`
|
|
314
|
+
: '';
|
|
315
|
+
const upToDate = `<script>fetch(${JSON.stringify(base + 'version.json')},{cache:"no-store"}).then(r=>r.json()).then(v=>{if(v.build!==${JSON.stringify(hash)}&&!location.search.includes("b="+v.build)){const q=new URLSearchParams(location.search);q.set("b",v.build);location.replace(location.pathname+"?"+q)}}).catch(()=>{})</script>`;
|
|
316
|
+
|
|
317
|
+
const inlineCache = new Map();
|
|
318
|
+
for (const p of pages) {
|
|
319
|
+
let html = page
|
|
320
|
+
.replace(/<title>[^<]*<\/title>/, head(p) + upToDate + countVisits)
|
|
321
|
+
.replace('</head>', landPreloads(landOfPath(p.path)) + '</head>');
|
|
322
|
+
html = html.replace(/<section id="t-route" hidden><\/section>/, card(p));
|
|
323
|
+
const dir = join(outDir, p.path);
|
|
324
|
+
mkdirSync(dir, { recursive: true });
|
|
325
|
+
writeFileSync(join(dir, 'index.html'), bundleInlineScripts(esbuild, html, inlineCache));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
let changed = '';
|
|
329
|
+
try {
|
|
330
|
+
changed = execFileSync('git', ['log', '-1', '--format=%cs', '--', 'src'], {
|
|
331
|
+
cwd: repoRoot,
|
|
332
|
+
encoding: 'utf8',
|
|
333
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
334
|
+
}).trim();
|
|
335
|
+
} catch {}
|
|
336
|
+
changed ||= new Date().toISOString().slice(0, 10);
|
|
337
|
+
writeFileSync(
|
|
338
|
+
join(outDir, 'sitemap.xml'),
|
|
339
|
+
'<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' +
|
|
340
|
+
pages.map(p => `<url><loc>${url(p.path)}</loc><lastmod>${changed}</lastmod></url>`).join('') +
|
|
341
|
+
'</urlset>\n',
|
|
342
|
+
);
|
|
343
|
+
const root = join(outDir, '..');
|
|
344
|
+
writeFileSync(join(root, 'robots.txt'), `User-agent: *\nAllow: /\n\nSitemap: ${origin}${base}sitemap.xml\n`);
|
|
345
|
+
writeFileSync(
|
|
346
|
+
join(root, 'index.html'),
|
|
347
|
+
`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escapeHtml(siteName)}</title><meta http-equiv="refresh" content="0; url=${base}"><link rel="canonical" href="${url('')}"><style>body{margin:0;background:#14110d;color:#d9cdb4;font:16px/1.5 Georgia,serif;display:grid;place-items:center;min-height:100vh}a{color:#e8c47a}</style></head><body><p><a href="${base}">${escapeHtml(siteName)}</a></p></body></html>\n`,
|
|
348
|
+
);
|
|
349
|
+
writeFileSync(
|
|
350
|
+
join(root, '404.html'),
|
|
351
|
+
bundleInlineScripts(
|
|
352
|
+
esbuild,
|
|
353
|
+
`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="robots" content="noindex"><title>${escapeHtml(siteName)}</title><script>var b='${base}',p=location.pathname;location.replace(p.indexOf(b)===0&&p.length>b.length?b+'?r='+encodeURIComponent(p.slice(b.length).replace(/\\/+$/,''))+location.hash:b);</script></head><body></body></html>\n`,
|
|
354
|
+
inlineCache,
|
|
355
|
+
),
|
|
356
|
+
);
|
|
357
|
+
return { pageCount: pages.length, appDir, partCount: parts.length, hash };
|
|
358
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Shared offline unit-test runner for worlds built on Roamwright.
|
|
3
|
+
# Resolves the repository's `.venv/bin/python` (checking worktree -> main checkout -> python3),
|
|
4
|
+
# runs Python unittest files, Node test files, Node module-mock test files, and an optional extra check.
|
|
5
|
+
#
|
|
6
|
+
# Config environment variables:
|
|
7
|
+
# TEST_ROOT repository root (default: current directory)
|
|
8
|
+
# TEST_PY_FILES space-separated Python unittest scripts
|
|
9
|
+
# TEST_NODE_FILES space-separated globs/files for `node --test --test-reporter=dot`
|
|
10
|
+
# TEST_NODE_MOCK_FILES space-separated globs/files for `node --experimental-test-module-mocks --test --test-reporter=dot`
|
|
11
|
+
# TEST_EXTRA_CMD optional extra verification command
|
|
12
|
+
set -eu
|
|
13
|
+
ROOT="${TEST_ROOT:-$(pwd)}"
|
|
14
|
+
cd "$ROOT"
|
|
15
|
+
|
|
16
|
+
PYTHON=".venv/bin/python"
|
|
17
|
+
if [ ! -x "$PYTHON" ]; then
|
|
18
|
+
common_dir=$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null || true)
|
|
19
|
+
if [ -n "$common_dir" ] && [ -x "$(dirname "$common_dir")/.venv/bin/python" ]; then
|
|
20
|
+
PYTHON="$(dirname "$common_dir")/.venv/bin/python"
|
|
21
|
+
else
|
|
22
|
+
PYTHON="python3"
|
|
23
|
+
fi
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
if [ -n "${TEST_PY_FILES:-}" ]; then
|
|
27
|
+
for py in $TEST_PY_FILES; do
|
|
28
|
+
"$PYTHON" "$py" -q
|
|
29
|
+
done
|
|
30
|
+
fi
|
|
31
|
+
if [ -n "${TEST_NODE_FILES:-}" ]; then
|
|
32
|
+
# shellcheck disable=SC2086
|
|
33
|
+
node --test --test-reporter=dot $TEST_NODE_FILES
|
|
34
|
+
fi
|
|
35
|
+
if [ -n "${TEST_NODE_MOCK_FILES:-}" ]; then
|
|
36
|
+
# shellcheck disable=SC2086
|
|
37
|
+
node --experimental-test-module-mocks --test --test-reporter=dot $TEST_NODE_MOCK_FILES
|
|
38
|
+
fi
|
|
39
|
+
if [ -n "${TEST_EXTRA_CMD:-}" ]; then
|
|
40
|
+
sh -c "$TEST_EXTRA_CMD"
|
|
41
|
+
fi
|
|
42
|
+
echo "test: every unit test passed"
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// Self-hosted Three.js and Roamwright engine vendor bundling helpers.
|
|
2
|
+
// Bundles the locked Three.js core module and tree-shaken Roamwright groups (engine, worker, jobs, optional)
|
|
3
|
+
// into `vendor/` so a world update can reuse cached engine and Three.js bundles across deployments.
|
|
4
|
+
import { copyFileSync, mkdirSync, readdirSync, readFileSync, rmSync } from 'node:fs';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
7
|
+
import { walkReach } from './module-graph.mjs';
|
|
8
|
+
|
|
9
|
+
const defaultRequire = createRequire(import.meta.url);
|
|
10
|
+
const THREE_URL = '../../three/three.module.min.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Collects unique engine subpath specifiers (`roamwright/...`) from an esbuild import list.
|
|
14
|
+
*
|
|
15
|
+
* @param {Array<{ path: string }>} imports
|
|
16
|
+
* @param {string} [prefix='roamwright/']
|
|
17
|
+
* @returns {Set<string>}
|
|
18
|
+
*/
|
|
19
|
+
export function engineImports(imports, prefix = 'roamwright/') {
|
|
20
|
+
return new Set(imports.map(i => i.path).filter(p => p.startsWith(prefix)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Reads the surviving engine export names imported by tree-shaken application outputs.
|
|
25
|
+
* A namespace or dynamic import maps to `null`, signalling that the full subpath API must be kept.
|
|
26
|
+
*
|
|
27
|
+
* @param {Array<{ path: string, text: string }>} files Output files from the first tree-shaken esbuild pass.
|
|
28
|
+
* @param {Record<string, { imports: Array<{ path: string, kind: string, external?: boolean }> }>} outputs Metafile outputs map.
|
|
29
|
+
* @param {object} options
|
|
30
|
+
* @param {(source: string, opts: object) => object} options.parse ESTree parser (e.g. `acorn.parse`).
|
|
31
|
+
* @param {string} [options.prefix='roamwright/']
|
|
32
|
+
* @returns {Map<string, Set<string> | null>}
|
|
33
|
+
*/
|
|
34
|
+
export function usedEngineExports(files, outputs, { parse, prefix = 'roamwright/' }) {
|
|
35
|
+
const names = new Map();
|
|
36
|
+
for (const file of files) {
|
|
37
|
+
const output = outputs[relative(process.cwd(), file.path)];
|
|
38
|
+
const engine = output.imports.filter(i => i.external && i.path.startsWith(prefix));
|
|
39
|
+
if (!engine.length) continue;
|
|
40
|
+
for (const i of engine) {
|
|
41
|
+
if (i.kind === 'dynamic-import') names.set(i.path, null);
|
|
42
|
+
else if (!names.has(i.path)) names.set(i.path, new Set());
|
|
43
|
+
}
|
|
44
|
+
for (const node of parse(file.text, { ecmaVersion: 'latest', sourceType: 'module' }).body) {
|
|
45
|
+
const id = node.source?.value;
|
|
46
|
+
const used = names.get(id);
|
|
47
|
+
if (!used) continue;
|
|
48
|
+
if (node.type === 'ExportAllDeclaration' || node.specifiers.some(s => s.type === 'ImportNamespaceSpecifier')) {
|
|
49
|
+
names.set(id, null);
|
|
50
|
+
} else {
|
|
51
|
+
for (const s of node.specifiers) {
|
|
52
|
+
used.add(s.type === 'ImportDefaultSpecifier' ? 'default' : (s.imported ?? s.local).name);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return names;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Bundles the locked `three` ESM entry point into `vendor/three/three.module.min.js` with esbuild
|
|
62
|
+
* and copies its `LICENSE` alongside it.
|
|
63
|
+
*
|
|
64
|
+
* @param {object} esbuild esbuild module.
|
|
65
|
+
* @param {object} [options]
|
|
66
|
+
* @param {(specifier: string) => string} [options.resolveModule] Module resolver from the consumer root.
|
|
67
|
+
* @param {string} [options.outDir='vendor/three']
|
|
68
|
+
* @param {string} [options.target='es2022']
|
|
69
|
+
*/
|
|
70
|
+
export async function buildThree(esbuild, { resolveModule = defaultRequire.resolve, outDir = 'vendor/three', target = 'es2022' } = {}) {
|
|
71
|
+
const root = join(dirname(resolveModule('three')), '..');
|
|
72
|
+
mkdirSync(outDir, { recursive: true });
|
|
73
|
+
await esbuild.build({
|
|
74
|
+
entryPoints: [join(root, 'build/three.module.js')],
|
|
75
|
+
outfile: join(outDir, 'three.module.min.js'),
|
|
76
|
+
bundle: true,
|
|
77
|
+
format: 'esm',
|
|
78
|
+
target,
|
|
79
|
+
treeShaking: true,
|
|
80
|
+
minify: true,
|
|
81
|
+
legalComments: 'none',
|
|
82
|
+
logLevel: 'silent',
|
|
83
|
+
});
|
|
84
|
+
copyFileSync(join(root, 'LICENSE'), join(outDir, 'LICENSE'));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Removes stale engine bundles under `vendor/roamwright/` not listed in the current build manifest.
|
|
89
|
+
*
|
|
90
|
+
* @param {string[]} files Relative manifest paths (e.g. `roamwright/<version>/<file>.js`).
|
|
91
|
+
* @param {string} [vendorRoot='vendor/roamwright']
|
|
92
|
+
*/
|
|
93
|
+
export function pruneEngine(files, vendorRoot = 'vendor/roamwright') {
|
|
94
|
+
const listed = new Set(files);
|
|
95
|
+
for (const version of readdirSync(vendorRoot, { withFileTypes: true })) {
|
|
96
|
+
const folder = join(vendorRoot, version.name);
|
|
97
|
+
if (!version.isDirectory()) continue;
|
|
98
|
+
for (const name of readdirSync(folder)) {
|
|
99
|
+
if (!listed.has(`roamwright/${version.name}/${name}`)) rmSync(join(folder, name), { force: true });
|
|
100
|
+
}
|
|
101
|
+
if (!readdirSync(folder).length) rmSync(folder, { recursive: true });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Bundles the tree-shaken Roamwright engine subpaths used by a world into grouped ESM files under
|
|
107
|
+
* `vendor/roamwright/<version>/`, returning an esbuild rewrite plugin and preload manifest.
|
|
108
|
+
*
|
|
109
|
+
* @param {object} esbuild esbuild module.
|
|
110
|
+
* @param {object} options
|
|
111
|
+
* @param {Set<string>} options.all All engine subpaths imported anywhere in the world.
|
|
112
|
+
* @param {Map<string, Set<string> | null>} options.used Surviving export names per engine subpath.
|
|
113
|
+
* @param {Set<string>} options.startup Engine subpaths required at page startup.
|
|
114
|
+
* @param {Set<string>} options.workerStartup Engine subpaths required at worker startup.
|
|
115
|
+
* @param {Set<string>} options.workerJobs Engine subpaths required by lazy worker jobs.
|
|
116
|
+
* @param {string | number} options.revision Three.js `REVISION` stamped into the bundle banner.
|
|
117
|
+
* @param {(sources: Record<string, string>) => Record<string, string>} options.compactShaders Shader compactor callback.
|
|
118
|
+
* @param {(specifier: string) => string} [options.resolveModule] Module resolver from the consumer root.
|
|
119
|
+
* @returns {Promise<{ plugin: object, manifest: { files: string[], preload: string[] } }>}
|
|
120
|
+
*/
|
|
121
|
+
export async function buildRoamwright(
|
|
122
|
+
esbuild,
|
|
123
|
+
{ all, used, startup, workerStartup, workerJobs, revision, compactShaders, resolveModule = defaultRequire.resolve },
|
|
124
|
+
) {
|
|
125
|
+
const root = dirname(resolveModule('roamwright'));
|
|
126
|
+
const { version } = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
127
|
+
const directory = `vendor/roamwright/${version}`;
|
|
128
|
+
const modules = new Map(
|
|
129
|
+
[...all].sort().map((id, index) => [
|
|
130
|
+
id,
|
|
131
|
+
{
|
|
132
|
+
id,
|
|
133
|
+
prefix: `m${index}_`,
|
|
134
|
+
group: workerStartup.has(id) ? 'worker' : workerJobs.has(id) ? 'jobs' : startup.has(id) ? 'engine' : 'optional',
|
|
135
|
+
},
|
|
136
|
+
]),
|
|
137
|
+
);
|
|
138
|
+
const sources = new Map([...modules.values()].map(m => [resolveModule(m.id), m]));
|
|
139
|
+
const api = await esbuild.build({
|
|
140
|
+
entryPoints: [...sources.keys()],
|
|
141
|
+
outdir: directory,
|
|
142
|
+
format: 'esm',
|
|
143
|
+
bundle: true,
|
|
144
|
+
external: ['three'],
|
|
145
|
+
metafile: true,
|
|
146
|
+
write: false,
|
|
147
|
+
});
|
|
148
|
+
const shaderSources = {};
|
|
149
|
+
for (const input of Object.keys(api.metafile.inputs)) {
|
|
150
|
+
const source = readFileSync(input, 'utf8');
|
|
151
|
+
if (source.includes('/* glsl */')) {
|
|
152
|
+
shaderSources[resolve(input)] = source.replaceAll(/\/\* glsl \*\/\s*`/g, '`/* glsl */');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const shaders = compactShaders(shaderSources);
|
|
156
|
+
const groups = new Map();
|
|
157
|
+
for (const output of Object.values(api.metafile.outputs)) {
|
|
158
|
+
const m = sources.get(resolve(output.entryPoint));
|
|
159
|
+
const required = used.get(m.id);
|
|
160
|
+
m.names = required === null ? output.exports : output.exports.filter(name => required?.has(name));
|
|
161
|
+
if (!groups.has(m.group)) groups.set(m.group, []);
|
|
162
|
+
const list = m.names.map(name => `${name} as ${m.prefix}${name}`).join(', ');
|
|
163
|
+
groups.get(m.group).push(`export { ${list} } from ${JSON.stringify(m.id)};`);
|
|
164
|
+
}
|
|
165
|
+
const bundles = await esbuild.build({
|
|
166
|
+
entryPoints: [...groups.keys()].map(group => ({ in: 'engine-group:' + group, out: group })),
|
|
167
|
+
outdir: directory,
|
|
168
|
+
entryNames: '[name]-[hash]',
|
|
169
|
+
chunkNames: 'shared-[hash]',
|
|
170
|
+
banner: { js: `/* Three.js r${revision} */` },
|
|
171
|
+
format: 'esm',
|
|
172
|
+
target: 'es2022',
|
|
173
|
+
bundle: true,
|
|
174
|
+
splitting: true,
|
|
175
|
+
treeShaking: true,
|
|
176
|
+
minify: true,
|
|
177
|
+
legalComments: 'none',
|
|
178
|
+
metafile: true,
|
|
179
|
+
plugins: [
|
|
180
|
+
{
|
|
181
|
+
name: 'engine-groups',
|
|
182
|
+
setup(build) {
|
|
183
|
+
build.onLoad({ filter: /\.js$/ }, args => (shaders[args.path] === undefined ? undefined : { contents: shaders[args.path] }));
|
|
184
|
+
build.onResolve({ filter: /^engine-group:/ }, args => ({
|
|
185
|
+
path: args.path.slice('engine-group:'.length),
|
|
186
|
+
namespace: 'engine-group',
|
|
187
|
+
}));
|
|
188
|
+
build.onLoad({ filter: /.*/, namespace: 'engine-group' }, args => ({
|
|
189
|
+
contents: groups.get(args.path).join('\n'),
|
|
190
|
+
resolveDir: root,
|
|
191
|
+
}));
|
|
192
|
+
build.onResolve({ filter: /^three$/ }, () => ({ path: THREE_URL, external: true }));
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
});
|
|
197
|
+
const outputs = bundles.metafile.outputs;
|
|
198
|
+
const entries = new Map();
|
|
199
|
+
for (const [file, output] of Object.entries(outputs)) {
|
|
200
|
+
if (output.entryPoint) entries.set(output.entryPoint.slice('engine-group:'.length), file);
|
|
201
|
+
}
|
|
202
|
+
const plugin = {
|
|
203
|
+
name: 'self-hosted-roamwright',
|
|
204
|
+
setup(build) {
|
|
205
|
+
build.onResolve({ filter: /^roamwright\// }, ({ path }) => ({ path, namespace: 'engine-api' }));
|
|
206
|
+
build.onLoad({ filter: /.*/, namespace: 'engine-api' }, ({ path }) => {
|
|
207
|
+
const m = modules.get(path);
|
|
208
|
+
const list = m.names.map(name => `${m.prefix}${name} as ${name}`).join(', ');
|
|
209
|
+
return { contents: `export { ${list} } from "engine-asset:${m.group}";` };
|
|
210
|
+
});
|
|
211
|
+
build.onResolve({ filter: /^engine-asset:/ }, ({ path }) => ({
|
|
212
|
+
path: '../' + entries.get(path.slice('engine-asset:'.length)),
|
|
213
|
+
external: true,
|
|
214
|
+
}));
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
const preloadRoots = [...startup].map(id => entries.get(modules.get(id).group));
|
|
218
|
+
const preload = walkReach(outputs, preloadRoots, { kinds: ['import-statement'] });
|
|
219
|
+
const paths = files => [...files].map(f => 'roamwright/' + version + '/' + basename(f)).sort();
|
|
220
|
+
return { plugin, manifest: { files: paths(Object.keys(outputs)), preload: paths(preload) } };
|
|
221
|
+
}
|