@oasiz/sdk 1.5.2 → 1.5.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.
- package/README.md +14 -11
- package/dist/index.cjs +31 -3
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +31 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,9 @@ Typed SDK for integrating browser games with the Oasiz platform: score, haptics,
|
|
|
21
21
|
npm install @oasiz/sdk
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
The published package includes ESM, CommonJS, and TypeScript declarations.
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
25
27
|
|
|
26
28
|
```ts
|
|
27
29
|
import { oasiz } from "@oasiz/sdk";
|
|
@@ -36,10 +38,10 @@ oasiz.saveGameState({ level, coins: 42 });
|
|
|
36
38
|
// 3. Trigger haptics on key events
|
|
37
39
|
oasiz.triggerHaptic("medium");
|
|
38
40
|
|
|
39
|
-
// 4. Respect the host's top safe area
|
|
41
|
+
// 4. Respect the host's top safe area (percent of viewport height → CSS vh)
|
|
40
42
|
document.documentElement.style.setProperty(
|
|
41
43
|
"--safe-top",
|
|
42
|
-
`${oasiz.safeAreaTop}
|
|
44
|
+
`${oasiz.safeAreaTop}vh`,
|
|
43
45
|
);
|
|
44
46
|
|
|
45
47
|
// 5. Submit score when the game ends
|
|
@@ -194,15 +196,15 @@ private onGameOver(): void {
|
|
|
194
196
|
|
|
195
197
|
### Layout
|
|
196
198
|
|
|
197
|
-
Use the runtime safe-area value instead of hardcoded top offsets. The
|
|
199
|
+
Use the runtime safe-area value instead of hardcoded top offsets. The SDK returns the top inset as **a percentage of the viewport height (0–100)**. If the host exposes CSS pixels via `window.getSafeAreaTop()` or `window.__OASIZ_SAFE_AREA_TOP__`, the SDK converts using `window.innerHeight`. The host may instead set **`window.getSafeAreaTopPercent()`** or **`window.__OASIZ_SAFE_AREA_TOP_PERCENT__`** (0–100) and that value is used directly.
|
|
198
200
|
|
|
199
201
|
#### `oasiz.getSafeAreaTop(): number`
|
|
200
202
|
|
|
201
|
-
Returns the
|
|
203
|
+
Returns the top inset as a percentage of viewport height (0–100). To get pixels in JavaScript, use `(getSafeAreaTop() / 100) * window.innerHeight`. In CSS, the same value matches **`vh`** units (for example `12.5vh` for 12.5% of the viewport height). Unsupported hosts return `0`.
|
|
202
204
|
|
|
203
205
|
```ts
|
|
204
|
-
const
|
|
205
|
-
document.documentElement.style.setProperty("--safe-top", `${
|
|
206
|
+
const safeTopPct = oasiz.getSafeAreaTop();
|
|
207
|
+
document.documentElement.style.setProperty("--safe-top", `${safeTopPct}vh`);
|
|
206
208
|
```
|
|
207
209
|
|
|
208
210
|
#### `oasiz.safeAreaTop`
|
|
@@ -453,9 +455,10 @@ public class GameManager : MonoBehaviour
|
|
|
453
455
|
OasizSDK.OnPause += OnPause;
|
|
454
456
|
OasizSDK.OnResume += OnResume;
|
|
455
457
|
|
|
456
|
-
// Offset UI for the host's top safe area
|
|
457
|
-
float
|
|
458
|
-
|
|
458
|
+
// Offset UI for the host's top safe area (0–100 percent of Screen.height)
|
|
459
|
+
float safeTopPct = OasizSDK.SafeAreaTop;
|
|
460
|
+
float safeTopPx = safeTopPct / 100f * Screen.height;
|
|
461
|
+
Debug.Log($"Safe area top: {safeTopPx}px ({safeTopPct}% of height)");
|
|
459
462
|
|
|
460
463
|
// Emit score normalization anchors
|
|
461
464
|
OasizSDK.EmitScoreConfig(new ScoreConfig(
|
|
@@ -498,7 +501,7 @@ public class GameManager : MonoBehaviour
|
|
|
498
501
|
| `oasiz.loadGameState()` | `OasizSDK.LoadGameState()` → `Dictionary<string, object>` |
|
|
499
502
|
| `oasiz.saveGameState(obj)` | `OasizSDK.SaveGameState(Dictionary<string, object>)` |
|
|
500
503
|
| `oasiz.flushGameState()` | `OasizSDK.FlushGameState()` |
|
|
501
|
-
| `oasiz.getSafeAreaTop()` / `safeAreaTop` | `OasizSDK.GetSafeAreaTop()` / `OasizSDK.SafeAreaTop` (`float`,
|
|
504
|
+
| `oasiz.getSafeAreaTop()` / `safeAreaTop` | `OasizSDK.GetSafeAreaTop()` / `OasizSDK.SafeAreaTop` (`float`, 0–100, % of viewport height) |
|
|
502
505
|
| `oasiz.setLeaderboardVisible(v)` | `OasizSDK.SetLeaderboardVisible(bool)` |
|
|
503
506
|
| `oasiz.onPause` / `onResume` | `OasizSDK.OnPause` / `OnResume` static events |
|
|
504
507
|
| `oasiz.onBackButton` | `OasizSDK.OnBackButton` or `SubscribeBackButton(Action)` (reference-counts `__oasizSetBackOverride`) |
|
package/dist/index.cjs
CHANGED
|
@@ -1217,22 +1217,50 @@ function warnMissingBridge4(methodName) {
|
|
|
1217
1217
|
);
|
|
1218
1218
|
}
|
|
1219
1219
|
}
|
|
1220
|
-
function
|
|
1220
|
+
function normalizeSafeAreaTopPixels(value) {
|
|
1221
1221
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
1222
1222
|
return 0;
|
|
1223
1223
|
}
|
|
1224
1224
|
return Math.max(0, value);
|
|
1225
1225
|
}
|
|
1226
|
+
function normalizeSafeAreaTopPercent(value) {
|
|
1227
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
1228
|
+
return 0;
|
|
1229
|
+
}
|
|
1230
|
+
return Math.min(100, Math.max(0, value));
|
|
1231
|
+
}
|
|
1232
|
+
function viewportInnerHeight(bridge) {
|
|
1233
|
+
const h = bridge.innerHeight;
|
|
1234
|
+
if (typeof h !== "number" || !Number.isFinite(h) || h <= 0) {
|
|
1235
|
+
return 0;
|
|
1236
|
+
}
|
|
1237
|
+
return h;
|
|
1238
|
+
}
|
|
1239
|
+
function pixelsTopToPercentOfViewport(pixels, bridge) {
|
|
1240
|
+
const h = viewportInnerHeight(bridge);
|
|
1241
|
+
if (h <= 0) {
|
|
1242
|
+
return 0;
|
|
1243
|
+
}
|
|
1244
|
+
return normalizeSafeAreaTopPercent(pixels / h * 100);
|
|
1245
|
+
}
|
|
1226
1246
|
function getSafeAreaTop() {
|
|
1227
1247
|
const bridge = getBridgeWindow6();
|
|
1228
1248
|
if (!bridge) {
|
|
1229
1249
|
return 0;
|
|
1230
1250
|
}
|
|
1251
|
+
if (typeof bridge.getSafeAreaTopPercent === "function") {
|
|
1252
|
+
return normalizeSafeAreaTopPercent(bridge.getSafeAreaTopPercent());
|
|
1253
|
+
}
|
|
1254
|
+
if (typeof bridge.__OASIZ_SAFE_AREA_TOP_PERCENT__ !== "undefined") {
|
|
1255
|
+
return normalizeSafeAreaTopPercent(bridge.__OASIZ_SAFE_AREA_TOP_PERCENT__);
|
|
1256
|
+
}
|
|
1231
1257
|
if (typeof bridge.getSafeAreaTop === "function") {
|
|
1232
|
-
|
|
1258
|
+
const px = normalizeSafeAreaTopPixels(bridge.getSafeAreaTop());
|
|
1259
|
+
return pixelsTopToPercentOfViewport(px, bridge);
|
|
1233
1260
|
}
|
|
1234
1261
|
if (typeof bridge.__OASIZ_SAFE_AREA_TOP__ !== "undefined") {
|
|
1235
|
-
|
|
1262
|
+
const px = normalizeSafeAreaTopPixels(bridge.__OASIZ_SAFE_AREA_TOP__);
|
|
1263
|
+
return pixelsTopToPercentOfViewport(px, bridge);
|
|
1236
1264
|
}
|
|
1237
1265
|
warnMissingBridge4("getSafeAreaTop");
|
|
1238
1266
|
return 0;
|
package/dist/index.d.cts
CHANGED
|
@@ -62,6 +62,12 @@ type Unsubscribe = () => void;
|
|
|
62
62
|
declare function onPause(callback: () => void): Unsubscribe;
|
|
63
63
|
declare function onResume(callback: () => void): Unsubscribe;
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Top safe-area inset as a percentage of the viewport height (0–100).
|
|
67
|
+
* The host may expose CSS pixels via `getSafeAreaTop` / `__OASIZ_SAFE_AREA_TOP__`
|
|
68
|
+
* (converted using `window.innerHeight`), or percentages via
|
|
69
|
+
* `getSafeAreaTopPercent` / `__OASIZ_SAFE_AREA_TOP_PERCENT__`.
|
|
70
|
+
*/
|
|
65
71
|
declare function getSafeAreaTop(): number;
|
|
66
72
|
declare function setLeaderboardVisible(visible: boolean): void;
|
|
67
73
|
|
package/dist/index.d.ts
CHANGED
|
@@ -62,6 +62,12 @@ type Unsubscribe = () => void;
|
|
|
62
62
|
declare function onPause(callback: () => void): Unsubscribe;
|
|
63
63
|
declare function onResume(callback: () => void): Unsubscribe;
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Top safe-area inset as a percentage of the viewport height (0–100).
|
|
67
|
+
* The host may expose CSS pixels via `getSafeAreaTop` / `__OASIZ_SAFE_AREA_TOP__`
|
|
68
|
+
* (converted using `window.innerHeight`), or percentages via
|
|
69
|
+
* `getSafeAreaTopPercent` / `__OASIZ_SAFE_AREA_TOP_PERCENT__`.
|
|
70
|
+
*/
|
|
65
71
|
declare function getSafeAreaTop(): number;
|
|
66
72
|
declare function setLeaderboardVisible(visible: boolean): void;
|
|
67
73
|
|
package/dist/index.js
CHANGED
|
@@ -1171,22 +1171,50 @@ function warnMissingBridge4(methodName) {
|
|
|
1171
1171
|
);
|
|
1172
1172
|
}
|
|
1173
1173
|
}
|
|
1174
|
-
function
|
|
1174
|
+
function normalizeSafeAreaTopPixels(value) {
|
|
1175
1175
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
1176
1176
|
return 0;
|
|
1177
1177
|
}
|
|
1178
1178
|
return Math.max(0, value);
|
|
1179
1179
|
}
|
|
1180
|
+
function normalizeSafeAreaTopPercent(value) {
|
|
1181
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
1182
|
+
return 0;
|
|
1183
|
+
}
|
|
1184
|
+
return Math.min(100, Math.max(0, value));
|
|
1185
|
+
}
|
|
1186
|
+
function viewportInnerHeight(bridge) {
|
|
1187
|
+
const h = bridge.innerHeight;
|
|
1188
|
+
if (typeof h !== "number" || !Number.isFinite(h) || h <= 0) {
|
|
1189
|
+
return 0;
|
|
1190
|
+
}
|
|
1191
|
+
return h;
|
|
1192
|
+
}
|
|
1193
|
+
function pixelsTopToPercentOfViewport(pixels, bridge) {
|
|
1194
|
+
const h = viewportInnerHeight(bridge);
|
|
1195
|
+
if (h <= 0) {
|
|
1196
|
+
return 0;
|
|
1197
|
+
}
|
|
1198
|
+
return normalizeSafeAreaTopPercent(pixels / h * 100);
|
|
1199
|
+
}
|
|
1180
1200
|
function getSafeAreaTop() {
|
|
1181
1201
|
const bridge = getBridgeWindow6();
|
|
1182
1202
|
if (!bridge) {
|
|
1183
1203
|
return 0;
|
|
1184
1204
|
}
|
|
1205
|
+
if (typeof bridge.getSafeAreaTopPercent === "function") {
|
|
1206
|
+
return normalizeSafeAreaTopPercent(bridge.getSafeAreaTopPercent());
|
|
1207
|
+
}
|
|
1208
|
+
if (typeof bridge.__OASIZ_SAFE_AREA_TOP_PERCENT__ !== "undefined") {
|
|
1209
|
+
return normalizeSafeAreaTopPercent(bridge.__OASIZ_SAFE_AREA_TOP_PERCENT__);
|
|
1210
|
+
}
|
|
1185
1211
|
if (typeof bridge.getSafeAreaTop === "function") {
|
|
1186
|
-
|
|
1212
|
+
const px = normalizeSafeAreaTopPixels(bridge.getSafeAreaTop());
|
|
1213
|
+
return pixelsTopToPercentOfViewport(px, bridge);
|
|
1187
1214
|
}
|
|
1188
1215
|
if (typeof bridge.__OASIZ_SAFE_AREA_TOP__ !== "undefined") {
|
|
1189
|
-
|
|
1216
|
+
const px = normalizeSafeAreaTopPixels(bridge.__OASIZ_SAFE_AREA_TOP__);
|
|
1217
|
+
return pixelsTopToPercentOfViewport(px, bridge);
|
|
1190
1218
|
}
|
|
1191
1219
|
warnMissingBridge4("getSafeAreaTop");
|
|
1192
1220
|
return 0;
|