@thewhateverapp/tile-sdk 0.14.2 → 0.14.3

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.
@@ -10,17 +10,20 @@ export interface SceneRendererProps {
10
10
  onEvent?: (event: string, data?: unknown) => void;
11
11
  /** Whether the scene is paused */
12
12
  paused?: boolean;
13
- /** Width override (default: TILE_WIDTH) */
13
+ /** Fixed width (if not set, fills container responsively) */
14
14
  width?: number;
15
- /** Height override (default: TILE_HEIGHT) */
15
+ /** Fixed height (if not set, fills container responsively) */
16
16
  height?: number;
17
17
  /** Enable debug rendering */
18
18
  debug?: boolean;
19
19
  }
20
20
  /**
21
21
  * SceneRenderer - Renders a SceneSpecV1 with physics, components, and timeline
22
+ *
23
+ * By default, fills its parent container responsively. Pass explicit width/height
24
+ * to override with fixed dimensions.
22
25
  */
23
- export declare function SceneRenderer({ spec: inputSpec, onEvent, paused, width, height, debug, }: SceneRendererProps): React.JSX.Element;
26
+ export declare function SceneRenderer({ spec: inputSpec, onEvent, paused, width: fixedWidth, height: fixedHeight, debug, }: SceneRendererProps): React.JSX.Element;
24
27
  import { useScene } from './SceneContext.js';
25
28
  export { useScene };
26
29
  //# sourceMappingURL=SceneRenderer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SceneRenderer.d.ts","sourceRoot":"","sources":["../../src/scene/SceneRenderer.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAU,MAAM,2BAA2B,CAAC;AAqBrE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,oCAAoC;IACpC,IAAI,EAAE,WAAW,CAAC;IAClB,qEAAqE;IACrE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAClD,kCAAkC;IAClC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,2CAA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,EAAE,CAAC"}
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import React, { useEffect, useRef, useCallback, useMemo } from 'react';
2
+ import React, { useEffect, useRef, useCallback, useMemo, useState } from 'react';
3
3
  import { compileScene } from '@thewhateverapp/scene-sdk';
4
4
  import { PixiGame, useGameLoop, Container } from '../pixi/index.js';
5
5
  import { SceneContext, createEntityState, createPlayerState, createCameraState, createInputState, createTimelineState, } from './SceneContext.js';
@@ -10,10 +10,42 @@ import { useComponentRunner } from './components/ComponentRunner.js';
10
10
  import { useTimelineExecutor } from './timeline/TimelineExecutor.js';
11
11
  import { useCameraController } from './camera/CameraController.js';
12
12
  import { TILE_WIDTH, TILE_HEIGHT } from '../react/PixiGame.js';
13
+ /**
14
+ * Hook to track container size using ResizeObserver
15
+ */
16
+ function useContainerSize(containerRef) {
17
+ const [size, setSize] = useState({ width: TILE_WIDTH, height: TILE_HEIGHT });
18
+ useEffect(() => {
19
+ const container = containerRef.current;
20
+ if (!container)
21
+ return;
22
+ const updateSize = () => {
23
+ const rect = container.getBoundingClientRect();
24
+ if (rect.width > 0 && rect.height > 0) {
25
+ setSize({ width: rect.width, height: rect.height });
26
+ }
27
+ };
28
+ // Initial size
29
+ updateSize();
30
+ // Watch for resize
31
+ const observer = new ResizeObserver(updateSize);
32
+ observer.observe(container);
33
+ return () => observer.disconnect();
34
+ }, [containerRef]);
35
+ return size;
36
+ }
13
37
  /**
14
38
  * SceneRenderer - Renders a SceneSpecV1 with physics, components, and timeline
39
+ *
40
+ * By default, fills its parent container responsively. Pass explicit width/height
41
+ * to override with fixed dimensions.
15
42
  */
16
- export function SceneRenderer({ spec: inputSpec, onEvent, paused = false, width = TILE_WIDTH, height = TILE_HEIGHT, debug = false, }) {
43
+ export function SceneRenderer({ spec: inputSpec, onEvent, paused = false, width: fixedWidth, height: fixedHeight, debug = false, }) {
44
+ const containerRef = useRef(null);
45
+ const autoSize = useContainerSize(containerRef);
46
+ // Use fixed dimensions if provided, otherwise auto-size to container
47
+ const width = fixedWidth ?? autoSize.width;
48
+ const height = fixedHeight ?? autoSize.height;
17
49
  // Compile patterns once on mount
18
50
  const compiledSpec = useMemo(() => compileScene(inputSpec), [inputSpec]);
19
51
  // Get background color from spec
@@ -24,8 +56,9 @@ export function SceneRenderer({ spec: inputSpec, onEvent, paused = false, width
24
56
  }
25
57
  return 0x0a0a1a; // Default dark background
26
58
  }, [compiledSpec]);
27
- return (React.createElement(PixiGame, { width: width, height: height, background: backgroundColor, paused: paused },
28
- React.createElement(SceneContent, { spec: compiledSpec, onEvent: onEvent, paused: paused, width: width, height: height, debug: debug })));
59
+ return (React.createElement("div", { ref: containerRef, style: { width: '100%', height: '100%' } },
60
+ React.createElement(PixiGame, { width: width, height: height, background: backgroundColor, paused: paused },
61
+ React.createElement(SceneContent, { spec: compiledSpec, onEvent: onEvent, paused: paused, width: width, height: height, debug: debug }))));
29
62
  }
30
63
  /**
31
64
  * Inner component that runs inside PixiGame context
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thewhateverapp/tile-sdk",
3
- "version": "0.14.2",
3
+ "version": "0.14.3",
4
4
  "description": "SDK for building interactive tiles on The Whatever App platform",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",