@solidrt/2d 0.0.72 → 0.0.73

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/2d",
3
- "version": "0.0.72",
3
+ "version": "0.0.73",
4
4
  "license": "MIT",
5
5
  "funding": "https://github.com/sponsors/wellawaretech",
6
6
  "author": "Antoine van Wel",
@@ -16,10 +16,10 @@
16
16
  "AGENTS.md"
17
17
  ],
18
18
  "devDependencies": {
19
- "@solidrt/test": "0.0.72"
19
+ "@solidrt/test": "0.0.73"
20
20
  },
21
21
  "peerDependencies": {
22
- "@solidjs/signals": "2.0.0-rc.13",
23
- "@solidrt/core": "0.0.72"
22
+ "@solidjs/signals": "2.0.0-rc.14",
23
+ "@solidrt/core": "0.0.73"
24
24
  }
25
25
  }
@@ -1,4 +1,4 @@
1
- import { callRef, createEffect, merge, onFrame, untrack } from "@solidrt/core"
1
+ import { callRef, createEffect, merge, onFrame, onLayout, untrack } from "@solidrt/core"
2
2
  import type { InputMap, VoidComponent } from "@solidrt/core"
3
3
  import { createCamera2d } from "../camera2d.ts"
4
4
  import type { Camera2d as Camera2dHandle, Camera2dAxes, Camera2dOptions } from "../camera2d.ts"
@@ -33,9 +33,10 @@ const MAX_CAMERA_DT = 0.1
33
33
  * the follow's zones, the offset lane or a rate follows its prop, and a
34
34
  * bounds, pivot or offset change re-clamps and pushes the pose at once -
35
35
  * the `<OrbitCamera>` rule. The view's `size()` is the viewport (live: a
36
- * fill layer's box, a setSize, a `<View2d>` resize). Frames run only
37
- * while the camera moves (`active()`), so a resting camera leaves the
38
- * app demand-driven idle.
36
+ * fill layer's box, a setSize, a `<View2d>` resize), re-read after every
37
+ * layout so a resting camera's pivot follows a resize too. Frames run
38
+ * only while the camera moves (`active()`), so a resting camera leaves
39
+ * the app demand-driven idle.
39
40
  */
40
41
  export let Camera2d: VoidComponent<Camera2dProps> = props => {
41
42
  let target = useSpriteLayer().viewport
@@ -61,6 +62,14 @@ export let Camera2d: VoidComponent<Camera2dProps> = props => {
61
62
  })
62
63
  },
63
64
  )
65
+ // The viewport follows layout: a fill layer's first box replaces its
66
+ // creation size, a <View2d> or window resize changes it, and a camera at
67
+ // rest runs no frame to notice, so its pivot (a viewport fraction) would
68
+ // sit where the old size put it until it next moved. A child mounts after
69
+ // its layer, so this handler runs after the one that sizes the view;
70
+ // update(0) re-reads the viewport and pushes only when it changed.
71
+ // Untracked: the control reads its options through the props getters.
72
+ onLayout(() => untrack(() => cam.update(0)))
64
73
  // A bounds, pivot or offset prop change re-clamps and pushes the pose
65
74
  // at once (set({}) applies the clamps and the lanes). Deferred: the
66
75
  // creation already clamped and pushed the initial pose. Untracked: the
@@ -303,6 +303,10 @@ export let SpriteLayer: ParentComponent<SpriteLayerProps> = props => {
303
303
  { defer: true },
304
304
  )
305
305
  callRef(() => props.viewRef, view)
306
+ // An adopted layer outlives the component, so its own view must not: a
307
+ // layer of the component's own takes the view with it (createSpriteLayer's
308
+ // owner-scoped dispose), an adopted one frees nothing of the component's.
309
+ if (untrack(() => props.layer)) onCleanup(() => view.dispose())
306
310
  let pointer = untrack(() => props.pointer) ?? null
307
311
  if (pointer) onCleanup(feedPointer(view, pointer))
308
312
  // The view's own handlers at the root of the walk; the props are read