@thewhateverapp/tile-sdk 0.17.0 → 0.17.1

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.
@@ -2,6 +2,7 @@ export { TileProvider, TileContext } from './TileProvider.js';
2
2
  export type { TileContextValue } from './TileProvider.js';
3
3
  export { useTile } from './useTile.js';
4
4
  export { useKeyboard } from './useKeyboard.js';
5
+ export { useViewport } from './useViewport.js';
5
6
  export { TileContainer } from './TileContainer.js';
6
7
  export { withTile } from './withTile.js';
7
8
  export * from './overlay/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9D,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAQzC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9D,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAQzC,cAAc,oBAAoB,CAAC"}
@@ -2,6 +2,7 @@
2
2
  export { TileProvider, TileContext } from './TileProvider.js';
3
3
  export { useTile } from './useTile.js';
4
4
  export { useKeyboard } from './useKeyboard.js';
5
+ export { useViewport } from './useViewport.js';
5
6
  export { TileContainer } from './TileContainer.js';
6
7
  export { withTile } from './withTile.js';
7
8
  // TileInitializer removed - router should be injected directly into TileProvider
@@ -0,0 +1,14 @@
1
+ export interface SafeAreaInsets {
2
+ top: number;
3
+ right: number;
4
+ bottom: number;
5
+ left: number;
6
+ }
7
+ export interface ViewportInfo {
8
+ width: number;
9
+ height: number;
10
+ safeAreaInsets: SafeAreaInsets;
11
+ isVisualViewport: boolean;
12
+ }
13
+ export declare function useViewport(): ViewportInfo;
14
+ //# sourceMappingURL=useViewport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useViewport.d.ts","sourceRoot":"","sources":["../../src/react/useViewport.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAyDD,wBAAgB,WAAW,IAAI,YAAY,CAwB1C"}
@@ -0,0 +1,69 @@
1
+ import { useEffect, useState } from 'react';
2
+ const defaultInsets = { top: 0, right: 0, bottom: 0, left: 0 };
3
+ function readSafeAreaInsets() {
4
+ if (typeof window === 'undefined' || typeof document === 'undefined') {
5
+ return defaultInsets;
6
+ }
7
+ if (!document.body) {
8
+ return defaultInsets;
9
+ }
10
+ const probe = document.createElement('div');
11
+ probe.style.cssText = [
12
+ 'position:fixed',
13
+ 'top:0',
14
+ 'left:0',
15
+ 'right:0',
16
+ 'bottom:0',
17
+ 'padding-top:env(safe-area-inset-top)',
18
+ 'padding-right:env(safe-area-inset-right)',
19
+ 'padding-bottom:env(safe-area-inset-bottom)',
20
+ 'padding-left:env(safe-area-inset-left)',
21
+ 'pointer-events:none',
22
+ 'visibility:hidden'
23
+ ].join(';');
24
+ document.body.appendChild(probe);
25
+ const style = window.getComputedStyle(probe);
26
+ const insets = {
27
+ top: Number.parseFloat(style.paddingTop) || 0,
28
+ right: Number.parseFloat(style.paddingRight) || 0,
29
+ bottom: Number.parseFloat(style.paddingBottom) || 0,
30
+ left: Number.parseFloat(style.paddingLeft) || 0,
31
+ };
32
+ document.body.removeChild(probe);
33
+ return insets;
34
+ }
35
+ function getViewportInfo() {
36
+ if (typeof window === 'undefined') {
37
+ return { width: 0, height: 0, safeAreaInsets: defaultInsets, isVisualViewport: false };
38
+ }
39
+ const visual = window.visualViewport;
40
+ const width = visual?.width ?? window.innerWidth;
41
+ const height = visual?.height ?? window.innerHeight;
42
+ return {
43
+ width,
44
+ height,
45
+ safeAreaInsets: readSafeAreaInsets(),
46
+ isVisualViewport: Boolean(visual),
47
+ };
48
+ }
49
+ export function useViewport() {
50
+ const [info, setInfo] = useState(() => getViewportInfo());
51
+ useEffect(() => {
52
+ if (typeof window === 'undefined')
53
+ return;
54
+ const update = () => setInfo(getViewportInfo());
55
+ const visual = window.visualViewport;
56
+ update();
57
+ window.addEventListener('resize', update);
58
+ window.addEventListener('orientationchange', update);
59
+ visual?.addEventListener('resize', update);
60
+ visual?.addEventListener('scroll', update);
61
+ return () => {
62
+ window.removeEventListener('resize', update);
63
+ window.removeEventListener('orientationchange', update);
64
+ visual?.removeEventListener('resize', update);
65
+ visual?.removeEventListener('scroll', update);
66
+ };
67
+ }, []);
68
+ return info;
69
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thewhateverapp/tile-sdk",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
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",