castle-web-cli 0.4.233 → 0.4.234
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/dist/api.d.ts +11 -0
- package/dist/api.js +43 -0
- package/dist/bundle.d.ts +64 -0
- package/dist/bundle.js +558 -2
- package/dist/castle-host/host.d.ts +17 -2
- package/dist/castle-host/host.js +793 -36
- package/dist/castleJson.d.ts +20 -1
- package/dist/castleJson.js +44 -2
- package/dist/check.js +9 -2
- package/dist/chunkLoader.d.ts +3 -0
- package/dist/chunkLoader.js +111 -0
- package/dist/devParty.d.ts +26 -0
- package/dist/devParty.js +231 -0
- package/dist/devSaveStorage.js +4 -0
- package/dist/devSessionStorage.js +3 -1
- package/dist/devSocial.d.ts +24 -0
- package/dist/devSocial.js +70 -0
- package/dist/ide.d.ts +2 -0
- package/dist/ide.js +119 -15
- package/dist/index.js +8 -2
- package/dist/init.js +1 -1
- package/dist/save-deck.d.ts +20 -1
- package/dist/save-deck.js +141 -5
- package/dist/serve.js +29 -11
- package/dist/shell/assets/{index-BjOxR-lW.js → index-DulbYIJm.js} +97 -97
- package/dist/shell/index.html +1 -1
- package/dist/vitePlugins.d.ts +2 -1
- package/dist/vitePlugins.js +13 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +260 -3
- package/kits/base/sdk/castle.d.ts +7 -3
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +162 -1
- package/kits/base/sdk/commands.js +3 -0
- package/kits/base/sdk/display.d.ts +3 -0
- package/kits/base/sdk/display.js +9 -3
- package/kits/base/sdk/hub.d.ts +33 -6
- package/kits/base/sdk/hub.js +50 -4
- package/kits/base/sdk/multiplayer.d.ts +7 -1
- package/kits/base/sdk/multiplayer.js +140 -40
- package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
- package/kits/base/sdk/party.d.ts +23 -0
- package/kits/base/sdk/party.js +91 -0
- package/kits/base/sdk/reconnectBudget.d.ts +23 -0
- package/kits/base/sdk/reconnectBudget.js +96 -0
- package/kits/base/sdk/save.d.ts +38 -1
- package/kits/base/sdk/save.js +79 -6
- package/kits/base/sdk/server/hub.d.ts +31 -1
- package/kits/base/sdk/server/hub.js +50 -3
- package/kits/base/sdk/server/platformHandle.d.ts +13 -1
- package/kits/base/sdk/server/storage.d.ts +4 -0
- package/kits/base/sdk/server/storage.js +19 -3
- package/kits/base/sdk/server/wrapper.d.ts +7 -1
- package/kits/base/sdk/server/wrapper.js +10 -1
- package/kits/base/sdk/social.d.ts +9 -0
- package/kits/base/sdk/social.js +5 -0
- package/kits/hub-game/CLAUDE.md +123 -3
- package/kits/hub-game/README.md +63 -0
- package/kits/hub-game/castle.json +5 -5
- package/kits/hub-game/code/client/act.js +312 -0
- package/kits/hub-game/code/client/actionLayout.js +147 -0
- package/kits/hub-game/code/client/actionOverflow.js +556 -0
- package/kits/hub-game/code/client/arrivalCamera.js +50 -0
- package/kits/hub-game/code/client/askSlot.js +117 -0
- package/kits/hub-game/code/client/avatar.js +4 -2
- package/kits/hub-game/code/client/avatarShare.js +2 -0
- package/kits/hub-game/code/client/backVisibility.js +13 -0
- package/kits/hub-game/code/client/ballot.js +15 -10
- package/kits/hub-game/code/client/build.js +16 -0
- package/kits/hub-game/code/client/chat.js +41 -5
- package/kits/hub-game/code/client/chatModeration.js +5 -0
- package/kits/hub-game/code/client/chrome.js +1148 -258
- package/kits/hub-game/code/client/crowdNames.js +241 -0
- package/kits/hub-game/code/client/decor.js +10 -4
- package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
- package/kits/hub-game/code/client/doorErrors.js +39 -0
- package/kits/hub-game/code/client/fall.js +18 -0
- package/kits/hub-game/code/client/farAvatars.js +233 -0
- package/kits/hub-game/code/client/firstJoin.js +9 -2
- package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
- package/kits/hub-game/code/client/frameBatch.js +5 -0
- package/kits/hub-game/code/client/grab.js +31 -11
- package/kits/hub-game/code/client/hookLayer.js +87 -8
- package/kits/hub-game/code/client/hudCopy.js +51 -0
- package/kits/hub-game/code/client/hudRate.js +20 -0
- package/kits/hub-game/code/client/idle.js +14 -2
- package/kits/hub-game/code/client/invites.js +231 -0
- package/kits/hub-game/code/client/joinError.js +9 -0
- package/kits/hub-game/code/client/labelsNear.js +31 -2
- package/kits/hub-game/code/client/landscapeLayout.js +17 -0
- package/kits/hub-game/code/client/layoutCache.js +264 -0
- package/kits/hub-game/code/client/loadTelemetry.js +20 -0
- package/kits/hub-game/code/client/loadingCover.js +148 -0
- package/kits/hub-game/code/client/loadingEntry.js +8 -0
- package/kits/hub-game/code/client/menuRows.js +43 -0
- package/kits/hub-game/code/client/modelReady.js +7 -0
- package/kits/hub-game/code/client/padCueArrival.js +23 -0
- package/kits/hub-game/code/client/padCues.js +112 -0
- package/kits/hub-game/code/client/padOccupancy.js +88 -0
- package/kits/hub-game/code/client/padReadability.js +26 -0
- package/kits/hub-game/code/client/padRings.js +69 -0
- package/kits/hub-game/code/client/pushVisit.js +14 -0
- package/kits/hub-game/code/client/quality.js +205 -0
- package/kits/hub-game/code/client/qualityEntry.js +55 -0
- package/kits/hub-game/code/client/safeLayout.js +338 -0
- package/kits/hub-game/code/client/safeStyle.js +42 -0
- package/kits/hub-game/code/client/say.js +12 -3
- package/kits/hub-game/code/client/shot.js +64 -10
- package/kits/hub-game/code/client/shotFit.js +56 -0
- package/kits/hub-game/code/client/signIn.js +28 -0
- package/kits/hub-game/code/client/state.js +53 -0
- package/kits/hub-game/code/client/talk.js +209 -45
- package/kits/hub-game/code/client/tiers.js +68 -66
- package/kits/hub-game/code/client/together.js +7 -2
- package/kits/hub-game/code/client/weakestLookBake.js +92 -0
- package/kits/hub-game/code/client/weakestTier.js +295 -0
- package/kits/hub-game/code/client/worldLabels.js +241 -0
- package/kits/hub-game/code/client/yours.js +10 -9
- package/kits/hub-game/code/npcDisplayText.js +55 -0
- package/kits/hub-game/code/server/act.js +124 -0
- package/kits/hub-game/code/server/actions.js +6 -1
- package/kits/hub-game/code/server/actors.js +2 -1
- package/kits/hub-game/code/server/analytics.js +83 -0
- package/kits/hub-game/code/server/anonymousEntry.js +49 -0
- package/kits/hub-game/code/server/arrivalPose.js +36 -0
- package/kits/hub-game/code/server/companion.js +28 -3
- package/kits/hub-game/code/server/doorAnalytics.js +52 -0
- package/kits/hub-game/code/server/earned.js +22 -5
- package/kits/hub-game/code/server/frameBatch.js +183 -0
- package/kits/hub-game/code/server/friendsAmong.js +49 -9
- package/kits/hub-game/code/server/history.js +2 -0
- package/kits/hub-game/code/server/hub.js +1306 -95
- package/kits/hub-game/code/server/idle.js +30 -1
- package/kits/hub-game/code/server/index.js +26 -4
- package/kits/hub-game/code/server/invites.js +19 -0
- package/kits/hub-game/code/server/labels.js +9 -1
- package/kits/hub-game/code/server/loadAbandon.js +106 -0
- package/kits/hub-game/code/server/manifest.js +211 -3
- package/kits/hub-game/code/server/menu.js +31 -3
- package/kits/hub-game/code/server/npcs.js +226 -64
- package/kits/hub-game/code/server/observe.js +408 -0
- package/kits/hub-game/code/server/padOccupancy.js +85 -0
- package/kits/hub-game/code/server/players.js +9 -1
- package/kits/hub-game/code/server/resumePose.js +152 -0
- package/kits/hub-game/code/server/say.js +1 -1
- package/kits/hub-game/code/server/standing.js +4 -5
- package/kits/hub-game/code/server/storageLimit.js +187 -0
- package/kits/hub-game/code/server/vis.js +67 -5
- package/kits/hub-game/code/shared/act.js +35 -0
- package/kits/hub-game/code/shared/danceIdle.js +28 -0
- package/kits/hub-game/code/shared/loadStages.js +12 -0
- package/kits/hub-game/code/shared/quality.js +74 -0
- package/kits/hub-game/code/shared/say.js +2 -0
- package/kits/hub-game/code/shared/shot.js +35 -1
- package/kits/hub-game/code/systems/hub.js +970 -169
- package/kits/hub-game/docs/analytics.md +279 -0
- package/kits/hub-game/docs/contract.md +1257 -42
- package/kits/hub-game/docs/home-pieces.md +9 -2
- package/kits/hub-game/docs/observed-progress.md +252 -0
- package/kits/hub-game/main.jsx +2 -0
- package/kits/hub-game/package-lock.json +10 -3
- package/kits/hub-game/package.json +6 -3
- package/kits/hub-game/play/player.js +142 -0
- package/kits/hub-game/play/registry.js +47 -0
- package/kits/hub-game/play.jsx +37 -0
- package/kits/hub-game/scripts/check.mjs +39 -5
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -1
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +11 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +5 -5
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +3 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +19 -3
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +3 -3
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -1
- package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
- package/kits/hub-game/scripts/test-act-client.mjs +186 -0
- package/kits/hub-game/scripts/test-act.mjs +171 -0
- package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
- package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +367 -2
- package/kits/hub-game/scripts/test-actors.mjs +20 -7
- package/kits/hub-game/scripts/test-analytics.mjs +76 -0
- package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
- package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
- package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +49 -10
- package/kits/hub-game/scripts/test-avatar.mjs +44 -0
- package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
- package/kits/hub-game/scripts/test-ballot.mjs +11 -4
- package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
- package/kits/hub-game/scripts/test-build.mjs +20 -2
- package/kits/hub-game/scripts/test-chat.mjs +206 -5
- package/kits/hub-game/scripts/test-companion-chat.mjs +20 -2
- package/kits/hub-game/scripts/test-control-layout-dom.mjs +120 -0
- package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +45 -4
- package/kits/hub-game/scripts/test-decor.mjs +7 -0
- package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
- package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
- package/kits/hub-game/scripts/test-earned.mjs +33 -3
- package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
- package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
- package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +47 -4
- package/kits/hub-game/scripts/test-high-only.mjs +170 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +321 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +879 -11
- package/kits/hub-game/scripts/test-hud-clear.mjs +162 -59
- package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
- package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
- package/kits/hub-game/scripts/test-idle.mjs +66 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +20 -0
- package/kits/hub-game/scripts/test-interest.mjs +15 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
- package/kits/hub-game/scripts/test-invites.mjs +109 -0
- package/kits/hub-game/scripts/test-labels.mjs +71 -3
- package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
- package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
- package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
- package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
- package/kits/hub-game/scripts/test-manifest.mjs +265 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +105 -0
- package/kits/hub-game/scripts/test-menu.mjs +23 -0
- package/kits/hub-game/scripts/test-npcs.mjs +819 -10
- package/kits/hub-game/scripts/test-observed.mjs +745 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
- package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
- package/kits/hub-game/scripts/test-picker.mjs +234 -7
- package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
- package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
- package/kits/hub-game/scripts/test-quality.mjs +385 -0
- package/kits/hub-game/scripts/test-rehello.mjs +699 -5
- package/kits/hub-game/scripts/test-resume-action-order.mjs +598 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
- package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
- package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
- package/kits/hub-game/scripts/test-say.mjs +1 -1
- package/kits/hub-game/scripts/test-shot.mjs +145 -0
- package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +22 -17
- package/kits/hub-game/scripts/test-standing.mjs +35 -2
- package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
- package/kits/hub-game/scripts/test-stuck.mjs +5 -4
- package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +86 -13
- package/kits/hub-game/scripts/test-tiers.mjs +7 -8
- package/kits/hub-game/scripts/test-vis.mjs +433 -6
- package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
- package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +50 -6
- package/kits/hub-game/scripts/test-yours.mjs +39 -8
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
- package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +369 -30
- package/kits/multiplayer-3d/package-lock.json +8 -1
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
- package/kits/physics-2d/CLAUDE.md +10 -1
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/frozenActors.js +233 -0
- package/kits/physics-2d/engine/scene.js +87 -5
- package/kits/physics-2d/eslint.config.js +1 -1
- package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
- package/kits/physics-2d/play/behaviors/Camera.js +40 -0
- package/kits/physics-2d/play/behaviors/Collider.js +122 -0
- package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
- package/kits/physics-2d/play/behaviors/Goal.js +46 -0
- package/kits/physics-2d/play/behaviors/Joints.js +126 -0
- package/kits/physics-2d/play/behaviors/Layout.js +71 -0
- package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
- package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
- package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
- package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
- package/kits/physics-2d/play/behaviors/Style.js +209 -0
- package/kits/physics-2d/play/behaviors/Text.js +85 -0
- package/kits/physics-2d/play/behaviors/Video.js +93 -0
- package/kits/physics-3d/CLAUDE.md +25 -1651
- package/kits/physics-3d/behaviors/Body.jsx +3 -0
- package/kits/physics-3d/behaviors/Model.jsx +3 -0
- package/kits/physics-3d/behaviors/Player.jsx +35 -18
- package/kits/physics-3d/behaviors/Shape.jsx +3 -0
- package/kits/physics-3d/behaviors/Solid.jsx +3 -0
- package/kits/physics-3d/behaviors/Transform.jsx +3 -0
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-camera.md +542 -0
- package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
- package/kits/physics-3d/docs/engine-load.md +149 -0
- package/kits/physics-3d/docs/engine-look.md +114 -0
- package/kits/physics-3d/docs/engine-shadows.md +372 -0
- package/kits/physics-3d/docs/engine-skip-work.md +187 -0
- package/kits/physics-3d/docs/engine-sky.md +198 -0
- package/kits/physics-3d/docs/engine-static-actors.md +226 -0
- package/kits/physics-3d/docs/engine-view.md +37 -0
- package/kits/physics-3d/docs/pxmodel-format.md +1 -1
- package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -333
- package/kits/physics-3d/engine3d/actornode.js +1 -0
- package/kits/physics-3d/engine3d/branches.js +3 -13
- package/kits/physics-3d/engine3d/cage.js +2 -7
- package/kits/physics-3d/engine3d/cageops.js +2 -17
- package/kits/physics-3d/engine3d/dataBehaviors.js +12 -0
- package/kits/physics-3d/engine3d/framecap.js +4 -1
- package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
- package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
- package/kits/physics-3d/engine3d/gait.js +8 -0
- package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
- package/kits/physics-3d/engine3d/look.js +7 -0
- package/kits/physics-3d/engine3d/modelFiles.js +3 -17
- package/kits/physics-3d/engine3d/modelMath.js +49 -0
- package/kits/physics-3d/engine3d/modelready.js +16 -0
- package/kits/physics-3d/engine3d/motion.js +3 -3
- package/kits/physics-3d/engine3d/nearshadows.js +77 -10
- package/kits/physics-3d/engine3d/orbitinput.js +59 -25
- package/kits/physics-3d/engine3d/partgeometry.js +1 -16
- package/kits/physics-3d/engine3d/paths.js +1 -9
- package/kits/physics-3d/engine3d/playTimings.js +50 -0
- package/kits/physics-3d/engine3d/playerRun.js +372 -0
- package/kits/physics-3d/engine3d/pxmodel.js +3 -3
- package/kits/physics-3d/engine3d/rapier.js +27 -0
- package/kits/physics-3d/engine3d/scatter.js +1 -11
- package/kits/physics-3d/engine3d/shadowfade.js +23 -15
- package/kits/physics-3d/engine3d/sky.js +1 -1
- package/kits/physics-3d/engine3d/squarefirst.js +177 -0
- package/kits/physics-3d/engine3d/stillshadows.js +399 -0
- package/kits/physics-3d/engine3d/sweep.js +1 -25
- package/kits/physics-3d/engine3d/world3d.js +468 -18
- package/kits/physics-3d/eslint.config.js +2 -1
- package/kits/physics-3d/main.jsx +6 -3
- package/kits/physics-3d/package-lock.json +7 -0
- package/kits/physics-3d/package.json +5 -1
- package/kits/physics-3d/play/behaviors/Body.js +31 -0
- package/kits/physics-3d/play/behaviors/Door.js +37 -0
- package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
- package/kits/physics-3d/play/behaviors/Model.js +23 -0
- package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
- package/kits/physics-3d/play/behaviors/Player.js +1204 -0
- package/kits/physics-3d/play/behaviors/Shape.js +47 -0
- package/kits/physics-3d/play/behaviors/Solid.js +16 -0
- package/kits/physics-3d/play/behaviors/Transform.js +29 -0
- package/kits/physics-3d/pnpm-lock.yaml +8 -0
- package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
- package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
- package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +52 -4
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
- package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +6 -3
- package/kits/physics-3d/scripts/test-frame-cap.mjs +1 -1
- package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
- package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
- package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1 -1
- package/kits/physics-3d/scripts/test-near-shadows.mjs +2 -2
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +88 -7
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +40 -3
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +75 -1
- package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
- package/kits/physics-3d/scripts/test-sky.mjs +1 -1
- package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +3 -1
- package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +5 -2
- package/kits/physics-3d/scripts/test-steady-hover.mjs +5 -2
- package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
- package/kits/physics-3d/systems/physics3d.js +37 -4
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +33 -10
- package/kits/real-time/code/client/gameHooks.js +2 -0
- package/kits/real-time/code/client/joinOverlay.js +9 -4
- package/kits/real-time/code/server/session.js +6 -4
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { placementCache, makeLayoutCache } from '../code/client/layoutCache.js';
|
|
4
|
+
import { actionLayout } from '../code/client/actionLayout.js';
|
|
5
|
+
import { makeChrome } from '../code/client/chrome.js';
|
|
6
|
+
import { makeWorldLayout, mapWorldPoint, relevantLabels } from '../code/client/worldLabels.js';
|
|
7
|
+
import { near, nearCandidates, nearFor, labelBox, chromeItem } from '../code/client/labelsNear.js';
|
|
8
|
+
import { PerspectiveCamera } from 'three';
|
|
9
|
+
import { domRect, fakeDom } from './fixtures/fake-dom.mjs';
|
|
10
|
+
|
|
11
|
+
// Recorded inputs cover turns, keyboard-sized views, insets, wrapped copy,
|
|
12
|
+
// disappearing prompts, and changing obstacle order/visibility.
|
|
13
|
+
const cache = placementCache();
|
|
14
|
+
let calls = 0;
|
|
15
|
+
for (let i = 0; i < 20; i += 1) {
|
|
16
|
+
const inputs = {
|
|
17
|
+
view: [{ w: 360, h: 780 }, { w: 844, h: 390 }, { w: 360, h: 475 }, { w: 640, h: 300 }][i % 4],
|
|
18
|
+
safe: { left: i % 3 * 12, right: i % 2 * 24, top: i % 4 * 8, bottom: i % 5 * 6 },
|
|
19
|
+
offers: Array.from({ length: i % 4 }, (_, j) => ({ w: 90 + j * 24, h: i % 3 ? 44 : 64 })),
|
|
20
|
+
more: { w: 100, h: 44 }, launcher: { w: 110, h: 44 },
|
|
21
|
+
obstacles: i % 2 ? [{ left: 12, right: 130, top: 120, bottom: 230 }] : [],
|
|
22
|
+
};
|
|
23
|
+
const fresh = actionLayout(inputs);
|
|
24
|
+
const place = () => {calls += 1; return actionLayout(inputs);};
|
|
25
|
+
assert.deepEqual(cache(inputs, place), fresh);
|
|
26
|
+
const before = calls;
|
|
27
|
+
assert.deepEqual(cache(structuredClone(inputs), place), fresh);
|
|
28
|
+
assert.equal(calls, before, 'identical recorded inputs reuse placement');
|
|
29
|
+
assert.equal(calls, i + 1, 'changed input recomputes');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const dom = fakeDom({ viewW: 360, viewH: 780 });
|
|
33
|
+
const create = document.createElement;
|
|
34
|
+
document.createElement = (tag) => {
|
|
35
|
+
const node = create(tag), original = node.getBoundingClientRect;
|
|
36
|
+
node.getBoundingClientRect = () => {
|
|
37
|
+
dom.log.push(`${node.id} rect read`);
|
|
38
|
+
if (node.style.flexDirection !== 'column-reverse') {return original();}
|
|
39
|
+
const maxWidth = Number.parseFloat(node.style.maxWidth) || window.innerWidth - 24;
|
|
40
|
+
const sizes = node.children.filter((child) => child.style.display !== 'none').map((child) => {
|
|
41
|
+
const width = Math.min(maxWidth, child.textContent.length * 7 + 40);
|
|
42
|
+
return { width, height: 44 + Math.max(0, Math.ceil(child.textContent.length * 7 / Math.max(1, width - 40)) - 1) * 20 };
|
|
43
|
+
});
|
|
44
|
+
const width = Math.max(0, ...sizes.map((size) => size.width));
|
|
45
|
+
const height = sizes.reduce((sum, size) => sum + size.height, 0) + Math.max(0, sizes.length - 1) * 6;
|
|
46
|
+
const right = window.innerWidth - Number.parseFloat(node.style.right);
|
|
47
|
+
const bottom = window.innerHeight - (node.style.bottom.startsWith('max') ? 132 : Number.parseFloat(node.style.bottom));
|
|
48
|
+
return domRect({ left: right - width, right, top: bottom - height, bottom });
|
|
49
|
+
};
|
|
50
|
+
return node;
|
|
51
|
+
};
|
|
52
|
+
const source = () => ({ addEventListener() {}, removeEventListener() {} });
|
|
53
|
+
Object.assign(window, source());
|
|
54
|
+
// Geometry snapshots need no geometry observer or invalidation listeners.
|
|
55
|
+
globalThis.ResizeObserver = class { constructor() {throw new Error('no geometry observers');} };
|
|
56
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
57
|
+
const offers = [{ id: 'start', label: 'Start' }, { id: 'sit', label: 'Sit' }];
|
|
58
|
+
const draw = () => chrome.setActions(offers, () => {}, true, 1);
|
|
59
|
+
draw();
|
|
60
|
+
const initialStack = dom.made.findLast((node) => node.style.flexDirection === 'column-reverse');
|
|
61
|
+
assert.deepEqual({ ...initialStack.getBoundingClientRect() }, {}, 'browser rect coordinates live on the prototype');
|
|
62
|
+
chrome.beginLayoutFrame();
|
|
63
|
+
offers.reverse(); draw(); // Force a placement solve while the snapshot is active.
|
|
64
|
+
const activeStack = dom.made.findLast((node) => node.style.flexDirection === 'column-reverse');
|
|
65
|
+
assert.equal(activeStack.style.display, 'flex', 'prototype-getter rects keep action chips visible during a snapshot');
|
|
66
|
+
assert(activeStack.children.every((chip) => chip.style.display !== 'none'));
|
|
67
|
+
offers.reverse(); draw();
|
|
68
|
+
let mark = dom.log.length;
|
|
69
|
+
draw();
|
|
70
|
+
assert.deepEqual(dom.log.slice(mark), [], 'unchanged legacy placement reads and writes nothing');
|
|
71
|
+
for (const change of [
|
|
72
|
+
() => {window.innerHeight = 475;},
|
|
73
|
+
() => {offers.reverse();},
|
|
74
|
+
() => {offers[0].label = 'A longer label';},
|
|
75
|
+
() => {chrome.showBack(true, 'Town');},
|
|
76
|
+
]) {
|
|
77
|
+
chrome.endLayoutFrame(); change(); chrome.beginLayoutFrame(); draw();
|
|
78
|
+
// A setter may affect the next snapshot, so let that accepted delay settle.
|
|
79
|
+
chrome.endLayoutFrame(); chrome.beginLayoutFrame(); draw();
|
|
80
|
+
mark = dom.log.length; draw();
|
|
81
|
+
assert.deepEqual(dom.log.slice(mark), [], 'unchanged snapshot placement writes nothing');
|
|
82
|
+
}
|
|
83
|
+
// Compare the actual legacy DOM placement with a forced fresh solve too.
|
|
84
|
+
for (let i = 0; i < 20; i += 1) {
|
|
85
|
+
[window.innerWidth, window.innerHeight] = [[360, 780], [844, 390], [360, 475], [640, 300]][i % 4];
|
|
86
|
+
offers[0].label = i % 3 ? 'Start' : 'A long prompt that wraps to another line';
|
|
87
|
+
chrome.showBack(i % 2 === 0, 'Town');
|
|
88
|
+
const back = dom.made.find((node) => node.textContent === '‹ Town');
|
|
89
|
+
back.rect = { left: 12, right: 100 + i, top: 12, bottom: 56 + i };
|
|
90
|
+
const canAct = i % 5 !== 0;
|
|
91
|
+
const frame = () => chrome.setActions(offers, () => {}, canAct, 1);
|
|
92
|
+
const snapshot = () => {
|
|
93
|
+
const stack = dom.made.findLast((node) => node.style.flexDirection === 'column-reverse');
|
|
94
|
+
return [structuredClone(stack.styles), stack.children.map((chip) => structuredClone(chip.styles))];
|
|
95
|
+
};
|
|
96
|
+
chrome.endLayoutFrame(); chrome.beginLayoutFrame(); frame();
|
|
97
|
+
// Hidden sources have no geometry sample. A newly shown action stack seeds
|
|
98
|
+
// its visible chip sizes on the first solve, then caches those inputs.
|
|
99
|
+
frame(); const placed = snapshot();
|
|
100
|
+
mark = dom.log.length; frame();
|
|
101
|
+
assert.deepEqual(snapshot(), placed);
|
|
102
|
+
assert.deepEqual(dom.log.slice(mark), [], 'cached legacy placement has no DOM work');
|
|
103
|
+
chrome.endLayoutFrame(); chrome.beginLayoutFrame(); frame();
|
|
104
|
+
assert.deepEqual(snapshot(), placed, 'cached and fresh legacy placement agree');
|
|
105
|
+
}
|
|
106
|
+
const chip = dom.made.findLast((node) => node.style.flexDirection === 'column-reverse').children[0];
|
|
107
|
+
let fractionalWidth = 90.25;
|
|
108
|
+
chip.getBoundingClientRect = () => ({ left: 0, right: fractionalWidth, top: 0, bottom: 44.4, width: fractionalWidth, height: 44.4 });
|
|
109
|
+
chrome.endLayoutFrame(); chrome.beginLayoutFrame(); draw();
|
|
110
|
+
fractionalWidth = 90.5;
|
|
111
|
+
chrome.endLayoutFrame(); chrome.beginLayoutFrame(); mark = dom.log.length; draw();
|
|
112
|
+
assert(dom.log.slice(mark).some((line) => line.includes('style.')), 'fractional chip geometry changes placement even when offset sizes round identically');
|
|
113
|
+
chrome.dispose();
|
|
114
|
+
|
|
115
|
+
// A sibling growing can move a fixed-size canvas without a resize event,
|
|
116
|
+
// observer notification, or any change to the canvas/ancestor styles.
|
|
117
|
+
const geometry = makeLayoutCache();
|
|
118
|
+
const layoutOrder = [];
|
|
119
|
+
let siblingHeight = 20, ancestorTop = 0;
|
|
120
|
+
const canvas = { style: {}, children: [], getBoundingClientRect() {
|
|
121
|
+
layoutOrder.push('read');
|
|
122
|
+
return { left: 0, right: 300, top: siblingHeight + ancestorTop, bottom: siblingHeight + ancestorTop + 200, width: 300, height: 200 };
|
|
123
|
+
} };
|
|
124
|
+
geometry.beginFrame([canvas]);
|
|
125
|
+
assert.equal(geometry.rect(canvas).top, 20);
|
|
126
|
+
layoutOrder.push('write');
|
|
127
|
+
geometry.rect(canvas); geometry.rect(canvas);
|
|
128
|
+
assert.deepEqual(layoutOrder, ['read', 'write'], 'later rect consumers reuse the clean read phase');
|
|
129
|
+
geometry.endFrame(); siblingHeight = 80;
|
|
130
|
+
geometry.beginFrame();
|
|
131
|
+
assert.equal(geometry.rect(canvas).top, 80, 'sibling shifts are fresh next frame without signals');
|
|
132
|
+
geometry.endFrame(); ancestorTop = 15;
|
|
133
|
+
geometry.beginFrame();
|
|
134
|
+
assert.equal(geometry.rect(canvas).top, 95, 'ancestor movement is fresh without signals');
|
|
135
|
+
geometry.endFrame();
|
|
136
|
+
siblingHeight = 120;
|
|
137
|
+
assert.equal(geometry.rect(canvas).top, 135, 'standalone callers never reuse an old rect');
|
|
138
|
+
geometry.dispose();
|
|
139
|
+
delete globalThis.ResizeObserver;
|
|
140
|
+
delete window.addEventListener; delete window.visualViewport;
|
|
141
|
+
|
|
142
|
+
// Movement reuses snapshot sizes; content and size-changing styles refresh
|
|
143
|
+
// the affected source once, and later consumers reuse that measurement.
|
|
144
|
+
{
|
|
145
|
+
const cache = makeLayoutCache();
|
|
146
|
+
let reads = 0;
|
|
147
|
+
const node = { style: { position: 'absolute', left: '10px', top: '20px', whiteSpace: 'nowrap' }, children: [], textContent: 'Tag',
|
|
148
|
+
getBoundingClientRect() {
|
|
149
|
+
reads += 1;
|
|
150
|
+
const left = Number.parseFloat(this.style.left), top = Number.parseFloat(this.style.top), width = this.textContent.length * 7 + 20;
|
|
151
|
+
return { left, right: left + width, top, bottom: top + 24, width, height: 24 };
|
|
152
|
+
} };
|
|
153
|
+
cache.register(node, { positioned: true }); cache.beginFrame();
|
|
154
|
+
const width = cache.rect(node).width;
|
|
155
|
+
node.style.left = '12px'; node.style.top = '25px';
|
|
156
|
+
assert.equal(cache.rect(node).left, 12); assert.equal(cache.rect(node).top, 25);
|
|
157
|
+
assert.equal(cache.rect(node).width, width); assert.equal(reads, 1, 'position-only movement reuses the snapshot');
|
|
158
|
+
node.textContent = 'Longer tag';
|
|
159
|
+
node.className = 'large'; node.style.fontSize = '20px'; node.children.push({ style: { display: 'none' } });
|
|
160
|
+
assert.equal(cache.rect(node).left, 12); assert.equal(cache.rect(node).top, 25);
|
|
161
|
+
assert.equal(cache.rect(node).width, 'Longer tag'.length * 7 + 20); assert.equal(reads, 2);
|
|
162
|
+
cache.endFrame(); cache.beginFrame();
|
|
163
|
+
assert.equal(cache.rect(node).width, 'Longer tag'.length * 7 + 20); assert.equal(reads, 2, 'unchanged positioned measurements persist across frames');
|
|
164
|
+
cache.endFrame(); cache.unregister(node); cache.beginFrame();
|
|
165
|
+
assert.equal(reads, 2, 'removed sources are no longer read');
|
|
166
|
+
cache.endFrame(); cache.dispose();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Browser mutations gate expensive input checks; the no-observer fallback
|
|
170
|
+
// must keep the same geometry reuse. Count rects with the existing fake DOM.
|
|
171
|
+
for (const [observed, cssText] of [[false, false], [true, false], [false, true], [true, true]]) {
|
|
172
|
+
const previousObserver = globalThis.MutationObserver;
|
|
173
|
+
const targets = new Set();
|
|
174
|
+
let records = [], deliver;
|
|
175
|
+
const notify = (target, type = 'attributes') => {
|
|
176
|
+
for (let node = target; node; node = node.parent) {
|
|
177
|
+
if (targets.has(node)) {records.push({ target, type, attributeName: 'style' }); return;}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
if (observed) {globalThis.MutationObserver = class {
|
|
181
|
+
constructor(callback) {deliver = () => callback(this.takeRecords());}
|
|
182
|
+
observe(node) {targets.add(node);}
|
|
183
|
+
takeRecords() {const pending = records; records = []; return pending;}
|
|
184
|
+
disconnect() {targets.clear(); records = [];}
|
|
185
|
+
};}
|
|
186
|
+
else {delete globalThis.MutationObserver;}
|
|
187
|
+
const dom = fakeDom({ viewW: 360, viewH: 780 });
|
|
188
|
+
let reads = 0, textReads = 0, sizeStyleReads = 0;
|
|
189
|
+
let cssFormat = (css) => css;
|
|
190
|
+
const make = (hidden = false) => {
|
|
191
|
+
const node = document.createElement('div'); dom.body.appendChild(node);
|
|
192
|
+
Object.assign(node.style, { position: 'absolute', left: '10px', top: '20px', whiteSpace: 'nowrap', display: hidden ? 'none' : 'block' });
|
|
193
|
+
node.textContent = 'Tag'; node.rect = { left: 10, right: 60, top: 20, bottom: 44 };
|
|
194
|
+
if (cssText) {
|
|
195
|
+
// Serialize backing values directly, like a browser's CSSStyleDeclaration;
|
|
196
|
+
// this must not call any of the individual property getters below.
|
|
197
|
+
Object.defineProperty(node.styles, 'cssText', { get: () => cssFormat(Object.entries(node.styles).filter(([, value]) => value !== '')
|
|
198
|
+
.map(([key, value]) => `${key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)}: ${value};`).join(' ')) });
|
|
199
|
+
}
|
|
200
|
+
// Visibility checks still read display; position inputs drive shift math.
|
|
201
|
+
const positionInputs = new Set(['left', 'right', 'top', 'translate', 'transform', 'display', 'cssText']);
|
|
202
|
+
node.style = new Proxy(node.style, {
|
|
203
|
+
get(target, key) {if (!positionInputs.has(key)) {sizeStyleReads += 1;} return target[key];},
|
|
204
|
+
set(target, key, value) {target[key] = value; notify(node); return true;},
|
|
205
|
+
});
|
|
206
|
+
const text = Object.getOwnPropertyDescriptor(node, 'textContent');
|
|
207
|
+
Object.defineProperty(node, 'textContent', {
|
|
208
|
+
get() {textReads += 1; return text.get();},
|
|
209
|
+
set(value) {text.set(value); notify(node, 'childList');},
|
|
210
|
+
});
|
|
211
|
+
const rect = node.getBoundingClientRect;
|
|
212
|
+
node.getBoundingClientRect = () => {
|
|
213
|
+
assert.notEqual(node.style.display, 'none', 'hidden nodes never read geometry');
|
|
214
|
+
reads += 1; return rect();
|
|
215
|
+
};
|
|
216
|
+
for (const key of ['offsetWidth', 'offsetHeight', 'offsetLeft']) {
|
|
217
|
+
const property = Object.getOwnPropertyDescriptor(node, key);
|
|
218
|
+
Object.defineProperty(node, key, { get() {
|
|
219
|
+
assert.notEqual(node.style.display, 'none', 'hidden nodes never read offsets');
|
|
220
|
+
return property.get();
|
|
221
|
+
} });
|
|
222
|
+
}
|
|
223
|
+
return node;
|
|
224
|
+
};
|
|
225
|
+
const cache = makeLayoutCache();
|
|
226
|
+
try {
|
|
227
|
+
const labels = Array.from({ length: 40 }, () => make());
|
|
228
|
+
const panels = Array.from({ length: 10 }, () => make(true));
|
|
229
|
+
for (const node of [...labels, ...panels]) {cache.register(node, { positioned: true });}
|
|
230
|
+
const consume = () => {
|
|
231
|
+
for (const node of [...labels, ...panels]) {cache.rect(node); cache.size(node);}
|
|
232
|
+
};
|
|
233
|
+
cache.beginFrame(); consume(); cache.endFrame();
|
|
234
|
+
assert.equal(reads, 40, 'only visible labels seed their measurements');
|
|
235
|
+
if (cssText) {assert.equal(sizeStyleReads, 0, 'cssText measurements read no individual size styles');}
|
|
236
|
+
reads = 0; textReads = 0; sizeStyleReads = 0;
|
|
237
|
+
for (let frame = 0; frame < 3; frame += 1) {cache.beginFrame(); consume(); cache.endFrame();}
|
|
238
|
+
assert.equal(reads, 0, '40 positioned labels and 10 hidden panels do zero geometry reads on unchanged frames');
|
|
239
|
+
if (cssText) {assert.equal(sizeStyleReads, 0, '40 unchanged labels read no individual size styles');}
|
|
240
|
+
if (observed) {
|
|
241
|
+
assert.equal(textReads, 0, 'clean labels never poll textContent');
|
|
242
|
+
assert.equal(sizeStyleReads, 0, 'clean labels never poll size styles');
|
|
243
|
+
}
|
|
244
|
+
labels[0].textContent = 'Longer label';
|
|
245
|
+
if (observed) {deliver();} // Also cover mutation callbacks between frames.
|
|
246
|
+
cache.beginFrame(); consume(); cache.endFrame();
|
|
247
|
+
assert.equal(reads, 1, 'changed label copy is read once');
|
|
248
|
+
reads = 0; cache.beginFrame();
|
|
249
|
+
labels[1].textContent = 'Changed during the synchronous frame';
|
|
250
|
+
cache.rect(labels[1]); cache.rect(labels[1]); cache.size(labels[1]); cache.endFrame();
|
|
251
|
+
assert.equal(reads, 1, 'takeRecords catches same-frame text before its callback');
|
|
252
|
+
reads = 0; window.innerWidth = 640;
|
|
253
|
+
cache.beginFrame(); consume(); cache.endFrame();
|
|
254
|
+
assert.equal(reads, 40, 'viewport resize refreshes visible labels but never hidden panels');
|
|
255
|
+
reads = 0; cache.invalidate(labels[2]);
|
|
256
|
+
cache.beginFrame(); consume(); cache.endFrame();
|
|
257
|
+
assert.equal(reads, 1, 'explicit invalidation refreshes just its source');
|
|
258
|
+
reads = 0; sizeStyleReads = 0; cache.beginFrame();
|
|
259
|
+
for (const [i, node] of labels.entries()) {
|
|
260
|
+
node.style.left = `${30 + i}px`; node.style.top = '40px';
|
|
261
|
+
assert.equal(cache.rect(node).left, 30 + i);
|
|
262
|
+
}
|
|
263
|
+
assert.equal(cache.rect(labels[0]).left, 30); assert.equal(cache.rect(labels[0]).top, 40);
|
|
264
|
+
cache.endFrame(); cache.beginFrame(); consume(); cache.endFrame();
|
|
265
|
+
assert.equal(reads, 0, 'position writes use shift across frame boundaries');
|
|
266
|
+
if (cssText) {assert.equal(sizeStyleReads, 0, 'moving 40 labels reads no individual size styles');}
|
|
267
|
+
for (const [key, value] of [['width', '80px'], ['width', ''], ['fontSize', '32px'], ['paddingLeft', '12px'],
|
|
268
|
+
['borderLeftWidth', '2px'], ['fontVariant', 'small-caps'], ['fontFamily', 'Example: One'], ['fontFamily', 'Example: Two'],
|
|
269
|
+
['borderLeft', '1px solid red'], ['borderLeft', '9px solid red'], ['fontFamily', '"Example; One"'], ['fontFamily', '"Example; Two"']]) {
|
|
270
|
+
if (!cssText && ['borderLeftWidth', 'fontVariant', 'borderLeft'].includes(key)) {continue;}
|
|
271
|
+
reads = 0; sizeStyleReads = 0; cache.beginFrame();
|
|
272
|
+
labels[2].style[key] = value;
|
|
273
|
+
cache.rect(labels[2]); cache.rect(labels[2]); cache.endFrame();
|
|
274
|
+
assert.equal(reads, 1, `${key}: changed size input refreshes once`);
|
|
275
|
+
if (cssText) {assert.equal(sizeStyleReads, 0, `${key}: comparison and measurement use cssText`);}
|
|
276
|
+
}
|
|
277
|
+
if (cssText) {
|
|
278
|
+
reads = 0;
|
|
279
|
+
cssFormat = (css) => css.replace('font-size:', 'FONT-SIZE:').replace('32px;', '32px !IMPORTANT;');
|
|
280
|
+
notify(labels[2]);
|
|
281
|
+
cache.beginFrame(); consume(); cache.endFrame();
|
|
282
|
+
assert.equal(reads, 0, 'property case and !important alone do not change size inputs');
|
|
283
|
+
labels[2].style.color = 'red';
|
|
284
|
+
cache.beginFrame(); consume(); cache.endFrame();
|
|
285
|
+
assert.equal(reads, 0, 'paint-only changes reuse the measurement');
|
|
286
|
+
}
|
|
287
|
+
reads = 0;
|
|
288
|
+
panels[0].style.display = 'block';
|
|
289
|
+
cache.beginFrame(); consume(); cache.endFrame();
|
|
290
|
+
assert.equal(reads, 1, 'a newly displayed panel is measured once');
|
|
291
|
+
reads = 0; panels[0].style.display = 'none';
|
|
292
|
+
cache.beginFrame(); consume(); cache.endFrame();
|
|
293
|
+
assert.equal(reads, 0, 'hiding a measured source reads no geometry');
|
|
294
|
+
dom.body.style.display = 'none';
|
|
295
|
+
cache.beginFrame(); consume(); cache.endFrame();
|
|
296
|
+
assert.equal(reads, 0, 'an ancestor hiding all labels reads no geometry');
|
|
297
|
+
dom.body.style.display = 'block';
|
|
298
|
+
cache.beginFrame(); consume(); cache.endFrame();
|
|
299
|
+
assert.equal(reads, 40, 'ancestor visibility restores fresh label measurements');
|
|
300
|
+
// In-flow siblings can move without mutating the source or its ancestors.
|
|
301
|
+
const flow = make(), unused = make();
|
|
302
|
+
cache.register(flow); cache.register(unused);
|
|
303
|
+
cache.beginFrame(); cache.rect(flow); cache.endFrame(); reads = 0;
|
|
304
|
+
flow.rect = { left: 10, right: 60, top: 80, bottom: 104 }; textReads = 0;
|
|
305
|
+
cache.beginFrame();
|
|
306
|
+
assert.equal(reads, 1, 'only the previously read in-flow source is sampled');
|
|
307
|
+
if (observed) {assert.equal(textReads, 0, 'an unmutated in-flow sample reuses its copy');}
|
|
308
|
+
assert.equal(cache.rect(flow).top, 80); cache.endFrame();
|
|
309
|
+
cache.rect(flow); cache.endFrame(); flow.textContent = 'A much longer in-flow copy'; textReads = 0;
|
|
310
|
+
cache.beginFrame();
|
|
311
|
+
if (observed) {assert(textReads > 0, 'mutated in-flow copy is sampled again');}
|
|
312
|
+
cache.endFrame(); cache.beginFrame();
|
|
313
|
+
flow.textContent = 'Tag'; flow.rect = { left: 10, right: 60, top: 80, bottom: 140 };
|
|
314
|
+
assert.equal(cache.rect(flow).height, 60, 'a later copy change compares against the fresh sample');
|
|
315
|
+
cache.endFrame();
|
|
316
|
+
cache.beginFrame(); cache.endFrame(); cache.beginFrame(); cache.endFrame(); reads = 0;
|
|
317
|
+
cache.beginFrame();
|
|
318
|
+
assert.equal(reads, 0, 'in-flow sources leave the working set when unused');
|
|
319
|
+
unused.rect = { left: 10, right: 60, top: 100, bottom: 124 };
|
|
320
|
+
assert.equal(cache.rect(unused).top, 100, 'first read after idle gets fresh in-flow geometry');
|
|
321
|
+
cache.endFrame();
|
|
322
|
+
// A size input changed while a source is idle stays unsampled until measured.
|
|
323
|
+
flow.style.width = '100px';
|
|
324
|
+
cache.beginFrame(); cache.rect(flow); cache.endFrame(); cache.beginFrame(); cache.endFrame();
|
|
325
|
+
flow.style.width = '200px'; cache.beginFrame(); cache.endFrame();
|
|
326
|
+
cache.rect(flow); cache.beginFrame();
|
|
327
|
+
flow.style.width = '100px'; flow.rect = { left: 10, right: 60, top: 80, bottom: 150 };
|
|
328
|
+
assert.equal(cache.rect(flow).height, 70, 'a style changed while idle is sampled before reuse');
|
|
329
|
+
cache.endFrame(); flow.style.width = '';
|
|
330
|
+
// Descendant-only sizing changes join the next read phase.
|
|
331
|
+
if (observed) {
|
|
332
|
+
const child = make(); labels[3].appendChild(child); notify(labels[3], 'childList');
|
|
333
|
+
labels[3].rect = { left: 10, right: 60, top: 20, bottom: 44 };
|
|
334
|
+
cache.beginFrame();
|
|
335
|
+
child.style.fontSize = '40px'; labels[3].rect = { left: 10, right: 60, top: 20, bottom: 60 };
|
|
336
|
+
assert.equal(cache.rect(labels[3]).height, 24, 'descendant styles preserve this frame snapshot');
|
|
337
|
+
cache.endFrame(); cache.beginFrame();
|
|
338
|
+
assert.equal(cache.rect(labels[3]).height, 40, 'descendant styles refresh next frame');
|
|
339
|
+
cache.endFrame();
|
|
340
|
+
}
|
|
341
|
+
// Replacing children with the same copy can still change the size.
|
|
342
|
+
if (observed) {
|
|
343
|
+
const old = make(); labels[7].appendChild(old); notify(labels[7], 'childList');
|
|
344
|
+
cache.beginFrame(); cache.rect(labels[7]); cache.endFrame();
|
|
345
|
+
labels[7].removeChild?.(old); labels[7].appendChild(make()); notify(labels[7], 'childList');
|
|
346
|
+
labels[7].rect = { left: 10, right: 90, top: 20, bottom: 70 };
|
|
347
|
+
cache.beginFrame();
|
|
348
|
+
assert.equal(cache.rect(labels[7]).height, 50, 'child replacement re-measures even when text is unchanged');
|
|
349
|
+
cache.endFrame();
|
|
350
|
+
}
|
|
351
|
+
// Inherited changes no observer sees are bounded by a periodic refresh.
|
|
352
|
+
labels[8].rect = { left: 10, right: 60, top: 20, bottom: 64 };
|
|
353
|
+
let refreshed = -1;
|
|
354
|
+
for (let frame = 0; frame < 31 && refreshed < 0; frame += 1) {
|
|
355
|
+
cache.beginFrame(); if (cache.rect(labels[8]).height === 44) {refreshed = frame;} cache.endFrame();
|
|
356
|
+
}
|
|
357
|
+
assert(refreshed >= 0, 'positioned measurements refresh within 30 frames');
|
|
358
|
+
cache.beginFrame(); reads = 0;
|
|
359
|
+
labels[5].style.whiteSpace = 'normal'; labels[5].style.left = '240px';
|
|
360
|
+
labels[5].rect = { left: 240, right: 300, top: 20, bottom: 78 };
|
|
361
|
+
assert.equal(cache.rect(labels[5]).height, 58, 'movement into an auto-width lane refreshes wrapping');
|
|
362
|
+
cache.rect(labels[5]); cache.size(labels[5]); cache.endFrame();
|
|
363
|
+
assert.equal(reads, 1, 'changed wrapping is measured once');
|
|
364
|
+
reads = 0; sizeStyleReads = 0; cache.beginFrame();
|
|
365
|
+
labels[5].style.left = '270px';
|
|
366
|
+
labels[5].rect = { left: 270, right: 300, top: 20, bottom: 98 };
|
|
367
|
+
assert.equal(cache.rect(labels[5]).height, 78, 'an already-wrapping label moved into a narrower lane is re-measured');
|
|
368
|
+
cache.rect(labels[5]); cache.endFrame();
|
|
369
|
+
assert.equal(reads, 1, 'the wrapping position change is measured once');
|
|
370
|
+
if (cssText) {assert.equal(sizeStyleReads, 0, 'wrapping position checks use parsed cssText');}
|
|
371
|
+
if (observed) {
|
|
372
|
+
const parent = make(), child = labels[6]; parent.appendChild(child); cache.register(parent);
|
|
373
|
+
cache.beginFrame(); cache.rect(child); cache.endFrame();
|
|
374
|
+
parent.style.fontSize = '32px';
|
|
375
|
+
child.rect = { left: 10, right: 60, top: 20, bottom: 52 };
|
|
376
|
+
cache.beginFrame();
|
|
377
|
+
assert.equal(cache.rect(child).height, 32, 'ancestor style changes refresh positioned descendants');
|
|
378
|
+
cache.endFrame();
|
|
379
|
+
}
|
|
380
|
+
cache.unregister(labels[4]);
|
|
381
|
+
cache.beginFrame(); cache.endFrame();
|
|
382
|
+
assert(!targets.has(labels[4]), 'removed nodes leave the observer targets');
|
|
383
|
+
} finally {
|
|
384
|
+
cache.dispose();
|
|
385
|
+
assert.equal(targets.size, 0, 'dispose disconnects the mutation observer');
|
|
386
|
+
if (previousObserver) {globalThis.MutationObserver = previousObserver;}
|
|
387
|
+
else {delete globalThis.MutationObserver;}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// A repeated flush reads translated geometry before restoring any styles.
|
|
392
|
+
const order = [];
|
|
393
|
+
const node = (left, top, width, height) => {
|
|
394
|
+
const values = {};
|
|
395
|
+
return { style: new Proxy(values, { set(target, key, value) {order.push('write'); target[key] = value; return true;} }),
|
|
396
|
+
getBoundingClientRect() {
|
|
397
|
+
order.push('read');
|
|
398
|
+
const [dx, dy] = (values.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
399
|
+
return { left: left + dx, right: left + width + dx, top: top + dy, bottom: top + height + dy, width, height };
|
|
400
|
+
} };
|
|
401
|
+
};
|
|
402
|
+
const pointer = node(300, 40, 100, 26), hud = node(250, 10, 300, 110);
|
|
403
|
+
const layout = makeWorldLayout(() => [{ kind: 'pointer', node: pointer }, { kind: 'hud', node: hud }], () => ({ w: 844, h: 390 }));
|
|
404
|
+
layout.flush();
|
|
405
|
+
const translated = pointer.style.translate;
|
|
406
|
+
order.length = 0; layout.flush();
|
|
407
|
+
assert.equal(pointer.style.translate, translated);
|
|
408
|
+
assert(order.lastIndexOf('read') < order.indexOf('write'), 'all layout reads precede writes');
|
|
409
|
+
layout.begin();
|
|
410
|
+
// Drive the real hub method and projection with a perspective camera. Forcing
|
|
411
|
+
// candidate gathering on the reference path must not change a rendered frame.
|
|
412
|
+
const hubSource = readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
|
|
413
|
+
// Late crowd-name placement shares the same snapshot, including on a return
|
|
414
|
+
// to a resident scene; ending it early would make that pass read after writes.
|
|
415
|
+
{
|
|
416
|
+
const source = hubSource.slice(hubSource.indexOf(' registerLate(scene)'), hubSource.indexOf(' // The places this player will walk'));
|
|
417
|
+
const registerLate = new Function('Hub', `return ({${source}}).registerLate;`)({ deck: {} });
|
|
418
|
+
const geometry = makeLayoutCache(), callbacks = [];
|
|
419
|
+
let top = 20;
|
|
420
|
+
const node = { style: {}, getBoundingClientRect: () => ({ left: 0, right: 100, top, bottom: top + 24, width: 100, height: 24 }) };
|
|
421
|
+
geometry.register(node); geometry.beginFrame(); top = 80;
|
|
422
|
+
const context = {
|
|
423
|
+
applyVisibility() {}, applyWear() {},
|
|
424
|
+
fadeNames() {assert.equal(geometry.rect(node).top, 20, 'late crowd geometry uses the read-phase sample');},
|
|
425
|
+
endLayoutFrame() {geometry.endFrame();},
|
|
426
|
+
};
|
|
427
|
+
const scene = { registerSystem: (system) => callbacks.push(system.afterBehaviors) };
|
|
428
|
+
registerLate.call(context, scene); registerLate.call(context, scene);
|
|
429
|
+
assert.equal(callbacks.length, 1, 'resident scene keeps its one late pass');
|
|
430
|
+
for (const callback of callbacks) {callback(scene);}
|
|
431
|
+
geometry.endFrame();
|
|
432
|
+
assert.equal(geometry.active(), false);
|
|
433
|
+
geometry.dispose();
|
|
434
|
+
}
|
|
435
|
+
const nearMethod = hubSource.slice(hubSource.indexOf(' nearLabels(scene,'), hubSource.indexOf(' // The People list'));
|
|
436
|
+
const projectSource = hubSource.slice(hubSource.indexOf('function project('), hubSource.indexOf('function statsWanted('));
|
|
437
|
+
const project = new Function('mapWorldPoint', `${projectSource}; return project;`)(mapWorldPoint);
|
|
438
|
+
const Hub = { deck: {}, hub: { labelsMe: {}, place: {} } };
|
|
439
|
+
const nearLabels = new Function('Hub', 'sceneKeyOf', 'nearFor', 'nearCandidates', 'project', 'labelBox', 'chromeItem', 'near', 'relevantLabels',
|
|
440
|
+
`return ({${nearMethod}}).nearLabels;`)(Hub, () => 'test', nearFor, nearCandidates, project, labelBox, chromeItem, near, relevantLabels);
|
|
441
|
+
const context = () => ({ chrome: { measureLabel: () => ({ w: 100, h: 26 }) }, attention: {} });
|
|
442
|
+
const cachedContext = context(), freshContext = context();
|
|
443
|
+
const labelScene = { data: {}, getActor: () => null };
|
|
444
|
+
const placed = [
|
|
445
|
+
{ id: 'front', at: { x: 0, y: 0, z: 0 }, label: { text: 'Front', style: 'sign' }, always: true },
|
|
446
|
+
{ id: 'behind', at: { x: 0, y: 0, z: 10 }, label: { text: 'Behind', style: 'sign' }, always: true },
|
|
447
|
+
];
|
|
448
|
+
const camera = new PerspectiveCamera(60, 844 / 390, 0.1, 100);
|
|
449
|
+
camera.position.set(0, 2, 5);
|
|
450
|
+
for (let frame = 0; frame < 6; frame += 1) {
|
|
451
|
+
camera.lookAt(0, 1.6, frame < 2 ? 0 : 10); camera.updateMatrixWorld();
|
|
452
|
+
freshContext.nearCandidates = {};
|
|
453
|
+
const args = [labelScene, placed, { x: 0, y: 0, z: 0 }, camera, { w: 844, h: 390 }, 1000 + frame * 16, false, true];
|
|
454
|
+
const actual = nearLabels.call(cachedContext, ...args);
|
|
455
|
+
assert.deepEqual(actual, nearLabels.call(freshContext, ...args), `real camera frame ${frame}`);
|
|
456
|
+
if (frame === 2) {assert(actual.some(({ id }) => id === 'behind'), 'camera turn shows the new sign before the 100 ms refresh');}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// Exercise the pure Player HUD pass without JSX, engine boot or a browser.
|
|
460
|
+
const player = readFileSync(new URL('../../physics-3d/behaviors/Player.jsx', import.meta.url), 'utf8');
|
|
461
|
+
const hudContents = new Function(`${player.slice(player.indexOf('function hudContents('), player.indexOf('export class Player'))}; return hudContents;`)();
|
|
462
|
+
const actor = (id, x, z, components) => ({ id, components: { Transform: { x, y: 0, z }, ...components } });
|
|
463
|
+
const self = actor('self', 0, 0, { Pickup: {} });
|
|
464
|
+
const first = actor('first', 0, 2, { Pickup: {}, Lookable: { text: 'First' } });
|
|
465
|
+
const tie = actor('tie', 0, 2, { Lookable: { text: 'Tie' } });
|
|
466
|
+
const disabled = actor('disabled', 0, 1, { Pickup: { $enabled: false }, Lookable: { text: 'Disabled', $enabled: false } });
|
|
467
|
+
let scans = 0;
|
|
468
|
+
let awake = [self, first, tie, disabled];
|
|
469
|
+
const scene = { getActors() {scans += 1; return awake;} };
|
|
470
|
+
assert.deepEqual(hudContents(scene, self, self.components.Transform, 0), { remaining: 2, look: 'First' });
|
|
471
|
+
assert.equal(scans, 1, 'pickup count and Lookable text share one actor traversal');
|
|
472
|
+
assert.deepEqual(hudContents(scene, self, self.components.Transform, Math.PI), { remaining: 2, look: '' });
|
|
473
|
+
awake = [self, tie, disabled];
|
|
474
|
+
assert.deepEqual(hudContents(scene, self, self.components.Transform, 0), { remaining: 1, look: 'Tie' });
|
|
475
|
+
awake = [];
|
|
476
|
+
assert.deepEqual(hudContents(scene, self, self.components.Transform, 0), { remaining: 0, look: '' });
|
|
477
|
+
// Descendant-only changes become visible in N+1 even with identical copy.
|
|
478
|
+
{
|
|
479
|
+
const dom = fakeDom({ viewW: 800, viewH: 600 });
|
|
480
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
481
|
+
const spec = { title: 'Today', big: '3', text: 'Keep going' };
|
|
482
|
+
chrome.setHudClear(true); chrome.setHud(spec, null);
|
|
483
|
+
const big = dom.made.find((node) => node.textContent === '3'), hud = big.parent;
|
|
484
|
+
Object.defineProperty(hud, 'rect', { get() {
|
|
485
|
+
return { left: 100, right: 300, top: 12, bottom: 37 + Number.parseFloat(big.style.fontSize) };
|
|
486
|
+
} });
|
|
487
|
+
assert.equal(big.style.fontSize, '32px');
|
|
488
|
+
const bottom = () => chrome.padOccupancyControls().find((box) => box.left === 100 && box.right === 300).bottom;
|
|
489
|
+
chrome.beginLayoutFrame();
|
|
490
|
+
assert.equal(bottom(), 69);
|
|
491
|
+
chrome.setHudClear(false); chrome.setHud(spec, null);
|
|
492
|
+
assert.equal(big.style.fontSize, '56px');
|
|
493
|
+
assert.equal(bottom(), 69, 'N uses its read-phase HUD, despite the descendant font change');
|
|
494
|
+
chrome.endLayoutFrame(); chrome.beginLayoutFrame();
|
|
495
|
+
assert.equal(bottom(), 93, 'N+1 measures the restored 56 px child without a copy/key change');
|
|
496
|
+
chrome.endLayoutFrame(); chrome.dispose();
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// A dock can stay display:flex with an empty box while all its buttons hide.
|
|
500
|
+
// Showing a descendant must update the dock on N+1, without invalidation.
|
|
501
|
+
{
|
|
502
|
+
const dom = fakeDom({ viewW: 360, viewH: 780 });
|
|
503
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
504
|
+
const people = dom.made.find((node) => node.tag === 'button' && node.parent?.style.flexWrap === 'wrap-reverse' && node.textContent !== 'Doors');
|
|
505
|
+
const dock = people.parent;
|
|
506
|
+
Object.defineProperty(dock, 'rect', { get() {
|
|
507
|
+
const show = dock.children.some((node) => node.style.display !== 'none');
|
|
508
|
+
return { left: 10, right: show ? 120 : 10, top: 730, bottom: show ? 770 : 730 };
|
|
509
|
+
} });
|
|
510
|
+
const drawn = () => chrome.padOccupancyControls().some((box) => box.left === 10 && box.right === 120 && box.bottom === 770);
|
|
511
|
+
chrome.beginLayoutFrame(); assert.equal(drawn(), false);
|
|
512
|
+
chrome.setPeople([{ key: 'p', playerId: 'p', username: 'Ada', actions: [] }]);
|
|
513
|
+
assert.equal(people.style.display, 'block');
|
|
514
|
+
assert.equal(drawn(), false, 'the existing dock keeps its empty N snapshot');
|
|
515
|
+
chrome.endLayoutFrame(); chrome.beginLayoutFrame();
|
|
516
|
+
assert.equal(drawn(), true, 'the dock source is measured again in N+1');
|
|
517
|
+
chrome.endLayoutFrame(); chrome.dispose();
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// Real chrome walking/camera frames: warm content may move, fade and restore
|
|
521
|
+
// world-placement translations, but all geometry reads stay in the read phase.
|
|
522
|
+
{
|
|
523
|
+
const motion = fakeDom({ viewW: 844, viewH: 390 });
|
|
524
|
+
const createNode = document.createElement;
|
|
525
|
+
const size = (node) => {
|
|
526
|
+
if (node.style.display === 'none') {return { w: 0, h: 0 };}
|
|
527
|
+
const text = node.textContent || node.children.map((child) => child.textContent).join('');
|
|
528
|
+
return { w: text.length * 7 + 20, h: node.style.fontSize === '42px' ? 42 : 24 };
|
|
529
|
+
};
|
|
530
|
+
const fresh = (node) => {
|
|
531
|
+
const { w, h } = size(node);
|
|
532
|
+
let x = Number.parseFloat(node.style.left) || 0, y = Number.parseFloat(node.style.top) || 0;
|
|
533
|
+
if (node.style.left === '50%') {x = 422;}
|
|
534
|
+
const anchor = node.style.transform;
|
|
535
|
+
if (anchor.includes('-50%')) {x -= w / 2;}
|
|
536
|
+
if (anchor.includes('-100%')) {y -= h;}
|
|
537
|
+
else if (anchor.includes('-50%, -50%')) {y -= h / 2;}
|
|
538
|
+
const [dx, dy] = (node.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
539
|
+
return { left: x + dx, right: x + dx + w, top: y + dy, bottom: y + dy + h, width: w, height: h };
|
|
540
|
+
};
|
|
541
|
+
document.createElement = (tag) => {
|
|
542
|
+
const node = createNode(tag);
|
|
543
|
+
node.getBoundingClientRect = () => {motion.log.push(`${node.id} rect read`); return fresh(node);};
|
|
544
|
+
for (const [prop, value] of Object.entries({ offsetWidth: () => size(node).w, offsetHeight: () => size(node).h,
|
|
545
|
+
offsetLeft: () => Number.parseFloat(node.style.left) || 0, offsetTop: () => Number.parseFloat(node.style.top) || 0 })) {
|
|
546
|
+
Object.defineProperty(node, prop, { get() {motion.log.push(`${node.id} ${prop} read`); return value();} });
|
|
547
|
+
}
|
|
548
|
+
return node;
|
|
549
|
+
};
|
|
550
|
+
const moving = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {}, worldLabelsDefault: true });
|
|
551
|
+
const root = motion.body.children[0];
|
|
552
|
+
assert.equal(root.style.position, 'fixed'); assert.equal(root.style.inset, '0'); assert.equal(root.style.transform, '');
|
|
553
|
+
const frame = (n) => {
|
|
554
|
+
moving.beginWorldLabels();
|
|
555
|
+
moving.setHudClear(true);
|
|
556
|
+
moving.setHud({ title: 'Town', big: '3', text: 'Meet at the well' }, null);
|
|
557
|
+
moving.setLabels([
|
|
558
|
+
{ id: 'sign', text: 'Well', x: 250 + n * 2, y: 190 + n, opacity: 1 - n / 50 },
|
|
559
|
+
{ id: 'npc', text: 'Hello', speech: true, npc: true, x: 560 + n, y: 210 - n },
|
|
560
|
+
{ id: 'emoji', text: '👋', emote: true, x: 720 - n, y: 200 + n },
|
|
561
|
+
]);
|
|
562
|
+
moving.setPointers([{ id: 'goal:well', text: 'Well', x: 422 + n, y: 35 + n, angle: null },
|
|
563
|
+
{ id: 'friend', text: 'Ada', x: 760 - n, y: 300 - n, angle: n % 2 ? null : n / 10 }]);
|
|
564
|
+
moving.flushHudClear();
|
|
565
|
+
moving.flushWorldLabels();
|
|
566
|
+
return moving.crowdNameLabelBoxes();
|
|
567
|
+
};
|
|
568
|
+
moving.beginLayoutFrame();
|
|
569
|
+
motion.log.length = 0;
|
|
570
|
+
moving.setLabels([{ id: 'new', text: 'First-frame label', x: 300, y: 190 }]);
|
|
571
|
+
const created = motion.made.find((node) => node.textContent === 'First-frame label');
|
|
572
|
+
const first = moving.crowdNameLabelBoxes();
|
|
573
|
+
const second = moving.crowdNameLabelBoxes();
|
|
574
|
+
assert.deepEqual(first, second);
|
|
575
|
+
const expected = fresh(created);
|
|
576
|
+
assert.deepEqual(first, [{ left: expected.left, right: expected.right, top: expected.top, bottom: expected.bottom }]);
|
|
577
|
+
assert.equal(motion.log.filter((line) => line === `${created.id} rect read`).length, 1, 'a new label is measured correctly once when first needed');
|
|
578
|
+
moving.endLayoutFrame();
|
|
579
|
+
moving.setLabels([]);
|
|
580
|
+
motion.log.length = 0; moving.beginLayoutFrame();
|
|
581
|
+
assert(!motion.log.some((line) => line.startsWith(`${created.id} `)), 'removed label sources are unregistered');
|
|
582
|
+
moving.endLayoutFrame();
|
|
583
|
+
frame(0); frame(0);
|
|
584
|
+
const stringify = JSON.stringify;
|
|
585
|
+
try {
|
|
586
|
+
JSON.stringify = () => {throw new Error('no JSON serialization during moving chrome frames');};
|
|
587
|
+
for (let n = 1; n <= 20; n += 1) {
|
|
588
|
+
motion.log.length = 0;
|
|
589
|
+
moving.beginLayoutFrame();
|
|
590
|
+
const boxes = frame(n);
|
|
591
|
+
const pointer = motion.made.find((node) => node.children.some((child) => child.textContent === 'Ada'));
|
|
592
|
+
const pointerBox = moving.layoutGeometry().rect(pointer);
|
|
593
|
+
const firstWrite = motion.log.findIndex((line) => line.includes(' style.'));
|
|
594
|
+
assert(firstWrite >= 0);
|
|
595
|
+
assert(!motion.log.slice(firstWrite).some((line) => line.endsWith(' read')), `frame ${n}: no geometry read after a style write`);
|
|
596
|
+
const nodes = motion.made.filter((node) => ['Well', 'Hello', '👋'].includes(node.textContent) && node.parent?.style.inset === '0');
|
|
597
|
+
assert.equal(nodes.length, 3);
|
|
598
|
+
for (const node of nodes) {
|
|
599
|
+
assert.equal(node.parent.style.position, 'absolute');
|
|
600
|
+
assert.equal(node.parent.style.inset, '0');
|
|
601
|
+
assert.equal(node.parent.style.transform, '');
|
|
602
|
+
}
|
|
603
|
+
moving.endLayoutFrame();
|
|
604
|
+
motion.log.length = 0;
|
|
605
|
+
assert.deepEqual(pointerBox, pointer.getBoundingClientRect(), `frame ${n}: pointer anchor switches use the sampled size`);
|
|
606
|
+
assert.deepEqual(boxes, nodes.map((node) => {
|
|
607
|
+
const { left, right, top, bottom } = node.getBoundingClientRect();
|
|
608
|
+
return { left, right, top, bottom };
|
|
609
|
+
}), `frame ${n}: translated samples equal fresh reads outside the frame`);
|
|
610
|
+
}
|
|
611
|
+
} finally {JSON.stringify = stringify; moving.dispose();}
|
|
612
|
+
}
|
|
613
|
+
// Exercise the real pad/crowd control pass after HUD and pointer setters.
|
|
614
|
+
// Shift lock is an external source registered before the frame's read phase.
|
|
615
|
+
{
|
|
616
|
+
const dom = fakeDom({ viewW: 640, viewH: 300 });
|
|
617
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
618
|
+
const lock = document.createElement('button'); dom.body.appendChild(lock);
|
|
619
|
+
lock.style.display = 'block';
|
|
620
|
+
const read = lock.getBoundingClientRect;
|
|
621
|
+
lock.getBoundingClientRect = () => {dom.log.push('shift-lock rect read'); return read();};
|
|
622
|
+
chrome.safeSurface('engine-shift-lock', lock, 'control');
|
|
623
|
+
const scene = { three: { renderer: { domElement: { parentElement: { querySelector: () => lock } } } } };
|
|
624
|
+
const from = hubSource.indexOf(' if (padOccupancy || crowdNames) {');
|
|
625
|
+
const source = hubSource.slice(from, hubSource.indexOf(' // A clear HUD (v1.26)', from));
|
|
626
|
+
let controls;
|
|
627
|
+
const pass = new Function('Hub', 'placeLabels', `return function(chrome, scene, padOccupancy, crowdNames) {
|
|
628
|
+
const labels = [], worldLabelCount = 0, own = {}, view = { w: 640, h: 300 }, lt = {}, cam = {}, now = 1000;
|
|
629
|
+
${source}
|
|
630
|
+
};`)(Hub, (labels, own, boxes) => {controls = boxes; return labels;});
|
|
631
|
+
const context = { hudClear: true };
|
|
632
|
+
const draw = () => {
|
|
633
|
+
chrome.setHudClear(true); chrome.setHud({ title: 'Town', big: '3', text: 'Find the well' }, null);
|
|
634
|
+
chrome.setPointers([{ id: 'friend', text: 'Ada', x: 320, y: 240, angle: null }]);
|
|
635
|
+
};
|
|
636
|
+
draw(); chrome.flushHudClear();
|
|
637
|
+
for (const [padOccupancy, crowdNames] of [[true, false], [false, true], [true, true]]) {
|
|
638
|
+
lock.rect = { left: 580, right: 624, top: 200 + Number(crowdNames), bottom: 244 + Number(crowdNames) };
|
|
639
|
+
dom.log.length = 0; chrome.beginLayoutFrame();
|
|
640
|
+
const expected = chrome.layoutGeometry().rect(lock);
|
|
641
|
+
draw(); pass.call(context, chrome, scene, padOccupancy, crowdNames);
|
|
642
|
+
const boxes = crowdNames ? context.crowdFrame.controls : controls;
|
|
643
|
+
assert(boxes.some((box) => box.left === expected.left && box.top === expected.top && box.bottom === expected.bottom));
|
|
644
|
+
const firstWrite = dom.log.findIndex((line) => line.includes(' style.'));
|
|
645
|
+
assert(firstWrite >= 0);
|
|
646
|
+
assert.equal(dom.log.filter((line) => line === 'shift-lock rect read').length, 1, 'Shift lock is read once in the read phase');
|
|
647
|
+
assert(!dom.log.slice(firstWrite).some((line) => line.endsWith(' read')), 'pad/crowd Shift-lock clearance never reads geometry after writes');
|
|
648
|
+
chrome.endLayoutFrame();
|
|
649
|
+
}
|
|
650
|
+
chrome.dispose();
|
|
651
|
+
}
|
|
652
|
+
// A visible speech bubble can grow after the frame-start measurement, from
|
|
653
|
+
// new copy or from moving into a narrower auto-width lane.
|
|
654
|
+
for (const change of ['text', 'wrap']) {
|
|
655
|
+
const dom = fakeDom({ viewW: 360, viewH: 780 }, (node) => ({
|
|
656
|
+
w: 120, h: node.textContent === 'Longer reply' || Number.parseFloat(node.style.left) > 220 ? 58 : 24,
|
|
657
|
+
}));
|
|
658
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
659
|
+
chrome.setHudClear(true); chrome.setHud({ title: 'Town' }, null);
|
|
660
|
+
const hud = dom.made.find((node) => node.textContent === 'Town').parent;
|
|
661
|
+
hud.rect = { left: 12, right: 348, top: 12, bottom: 106 };
|
|
662
|
+
const draw = (text = 'Short reply', x = 180) => chrome.setLabels([{ id: 'reply', text, x, y: 100, speech: true }]);
|
|
663
|
+
draw(); chrome.flushHudClear();
|
|
664
|
+
const bubble = dom.made.find((node) => node.textContent === 'Short reply');
|
|
665
|
+
assert.equal(bubble.style.top, '136px');
|
|
666
|
+
chrome.beginLayoutFrame(); dom.log.length = 0;
|
|
667
|
+
draw(change === 'text' ? 'Longer reply' : 'Short reply', change === 'wrap' ? 260 : 180);
|
|
668
|
+
chrome.flushHudClear();
|
|
669
|
+
assert.equal(bubble.style.top, '170px', `${change}: grown bubble clears the HUD in the same frame`);
|
|
670
|
+
chrome.layoutGeometry().size(bubble); chrome.layoutGeometry().size(bubble);
|
|
671
|
+
assert.equal(dom.log.filter((line) => line === `${bubble.id} read`).length, 2, `${change}: width and height are refreshed once`);
|
|
672
|
+
chrome.endLayoutFrame(); chrome.dispose();
|
|
673
|
+
}
|
|
674
|
+
// A late web font changes metrics with no DOM write: drop every measurement.
|
|
675
|
+
{
|
|
676
|
+
const dom = fakeDom({ viewW: 360, viewH: 780 });
|
|
677
|
+
const listeners = {};
|
|
678
|
+
document.fonts = { addEventListener: (type, fn) => {listeners[type] = fn;}, removeEventListener: (type) => {delete listeners[type];} };
|
|
679
|
+
const node = document.createElement('div'); dom.body.appendChild(node);
|
|
680
|
+
Object.assign(node.style, { position: 'absolute', left: '0px', top: '0px', whiteSpace: 'nowrap' });
|
|
681
|
+
let height = 24;
|
|
682
|
+
node.getBoundingClientRect = () => ({ left: 0, right: 50, top: 0, bottom: height, width: 50, height });
|
|
683
|
+
const cache = makeLayoutCache(); cache.register(node, { positioned: true });
|
|
684
|
+
cache.beginFrame(); assert.equal(cache.rect(node).height, 24); cache.endFrame();
|
|
685
|
+
height = 30; listeners.loadingdone();
|
|
686
|
+
cache.beginFrame(); assert.equal(cache.rect(node).height, 30, 'font loading refreshes measurements'); cache.endFrame();
|
|
687
|
+
cache.dispose(); assert(!listeners.loadingdone, 'dispose removes the font listener');
|
|
688
|
+
delete document.fonts;
|
|
689
|
+
}
|
|
690
|
+
console.log('placement cache: prototype DOMRect action placement, changed-copy/wrap clearance, persistent measurements with/without mutation observers (40 labels/10 hidden panels), 20 recorded states, legacy DOM reuse/invalidation, fresh frame rects, sibling shifts, translation-only walking frames without late reads/serialization, descendant HUD/dock growth, new-label first reads, and single-pass HUD counts passed');
|