@oasiz/sdk 1.2.0 → 1.2.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.
- package/README.md +43 -1
- package/dist/index.cjs +894 -0
- package/dist/index.d.cts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.global.js +252 -0
- package/dist/index.js +893 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
type HapticType = "light" | "medium" | "heavy" | "success" | "error";
|
|
2
|
+
type LogOverlayLevel = "debug" | "log" | "info" | "warn" | "error";
|
|
3
|
+
interface LogOverlayEntry {
|
|
4
|
+
id: number;
|
|
5
|
+
level: LogOverlayLevel;
|
|
6
|
+
message: string;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
}
|
|
9
|
+
interface LogOverlayOptions {
|
|
10
|
+
collapsed?: boolean;
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
maxEntries?: number;
|
|
13
|
+
title?: string;
|
|
14
|
+
}
|
|
15
|
+
interface LogOverlayHandle {
|
|
16
|
+
clear: () => void;
|
|
17
|
+
destroy: () => void;
|
|
18
|
+
hide: () => void;
|
|
19
|
+
isVisible: () => boolean;
|
|
20
|
+
show: () => void;
|
|
21
|
+
}
|
|
2
22
|
interface ScoreAnchor {
|
|
3
23
|
raw: number;
|
|
4
24
|
normalized: 100 | 300 | 600 | 950;
|
|
@@ -10,6 +30,8 @@ type GameState = Record<string, unknown>;
|
|
|
10
30
|
|
|
11
31
|
declare function triggerHaptic(type: HapticType): void;
|
|
12
32
|
|
|
33
|
+
declare function enableLogOverlay(options?: LogOverlayOptions): LogOverlayHandle;
|
|
34
|
+
|
|
13
35
|
interface ShareRoomCodeOptions {
|
|
14
36
|
inviteOverride?: boolean;
|
|
15
37
|
}
|
|
@@ -49,6 +71,7 @@ declare const oasiz: {
|
|
|
49
71
|
submitScore: typeof submitScore;
|
|
50
72
|
emitScoreConfig: typeof emitScoreConfig;
|
|
51
73
|
triggerHaptic: typeof triggerHaptic;
|
|
74
|
+
enableLogOverlay: typeof enableLogOverlay;
|
|
52
75
|
loadGameState: typeof loadGameState;
|
|
53
76
|
saveGameState: typeof saveGameState;
|
|
54
77
|
flushGameState: typeof flushGameState;
|
|
@@ -65,4 +88,4 @@ declare const oasiz: {
|
|
|
65
88
|
readonly playerAvatar: string | undefined;
|
|
66
89
|
};
|
|
67
90
|
|
|
68
|
-
export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, type ShareRoomCodeOptions, type Unsubscribe, emitScoreConfig, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, shareRoomCode, submitScore, triggerHaptic };
|
|
91
|
+
export { type GameState, type HapticType, type LogOverlayEntry, type LogOverlayHandle, type LogOverlayLevel, type LogOverlayOptions, type ScoreAnchor, type ScoreConfig, type ShareRoomCodeOptions, type Unsubscribe, emitScoreConfig, enableLogOverlay, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, shareRoomCode, submitScore, triggerHaptic };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
type HapticType = "light" | "medium" | "heavy" | "success" | "error";
|
|
2
|
+
type LogOverlayLevel = "debug" | "log" | "info" | "warn" | "error";
|
|
3
|
+
interface LogOverlayEntry {
|
|
4
|
+
id: number;
|
|
5
|
+
level: LogOverlayLevel;
|
|
6
|
+
message: string;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
}
|
|
9
|
+
interface LogOverlayOptions {
|
|
10
|
+
collapsed?: boolean;
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
maxEntries?: number;
|
|
13
|
+
title?: string;
|
|
14
|
+
}
|
|
15
|
+
interface LogOverlayHandle {
|
|
16
|
+
clear: () => void;
|
|
17
|
+
destroy: () => void;
|
|
18
|
+
hide: () => void;
|
|
19
|
+
isVisible: () => boolean;
|
|
20
|
+
show: () => void;
|
|
21
|
+
}
|
|
2
22
|
interface ScoreAnchor {
|
|
3
23
|
raw: number;
|
|
4
24
|
normalized: 100 | 300 | 600 | 950;
|
|
@@ -10,6 +30,8 @@ type GameState = Record<string, unknown>;
|
|
|
10
30
|
|
|
11
31
|
declare function triggerHaptic(type: HapticType): void;
|
|
12
32
|
|
|
33
|
+
declare function enableLogOverlay(options?: LogOverlayOptions): LogOverlayHandle;
|
|
34
|
+
|
|
13
35
|
interface ShareRoomCodeOptions {
|
|
14
36
|
inviteOverride?: boolean;
|
|
15
37
|
}
|
|
@@ -49,6 +71,7 @@ declare const oasiz: {
|
|
|
49
71
|
submitScore: typeof submitScore;
|
|
50
72
|
emitScoreConfig: typeof emitScoreConfig;
|
|
51
73
|
triggerHaptic: typeof triggerHaptic;
|
|
74
|
+
enableLogOverlay: typeof enableLogOverlay;
|
|
52
75
|
loadGameState: typeof loadGameState;
|
|
53
76
|
saveGameState: typeof saveGameState;
|
|
54
77
|
flushGameState: typeof flushGameState;
|
|
@@ -65,4 +88,4 @@ declare const oasiz: {
|
|
|
65
88
|
readonly playerAvatar: string | undefined;
|
|
66
89
|
};
|
|
67
90
|
|
|
68
|
-
export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, type ShareRoomCodeOptions, type Unsubscribe, emitScoreConfig, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, shareRoomCode, submitScore, triggerHaptic };
|
|
91
|
+
export { type GameState, type HapticType, type LogOverlayEntry, type LogOverlayHandle, type LogOverlayLevel, type LogOverlayOptions, type ScoreAnchor, type ScoreConfig, type ShareRoomCodeOptions, type Unsubscribe, emitScoreConfig, enableLogOverlay, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, shareRoomCode, submitScore, triggerHaptic };
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var oasiz = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
flushGameState: () => flushGameState,
|
|
25
|
+
getGameId: () => getGameId,
|
|
26
|
+
getPlayerAvatar: () => getPlayerAvatar,
|
|
27
|
+
getPlayerName: () => getPlayerName,
|
|
28
|
+
getRoomCode: () => getRoomCode,
|
|
29
|
+
loadGameState: () => loadGameState,
|
|
30
|
+
oasiz: () => oasiz,
|
|
31
|
+
onPause: () => onPause,
|
|
32
|
+
onResume: () => onResume,
|
|
33
|
+
saveGameState: () => saveGameState,
|
|
34
|
+
shareRoomCode: () => shareRoomCode,
|
|
35
|
+
submitScore: () => submitScore,
|
|
36
|
+
triggerHaptic: () => triggerHaptic
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// src/haptics.ts
|
|
40
|
+
function isDevelopment() {
|
|
41
|
+
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
42
|
+
return nodeEnv !== "production";
|
|
43
|
+
}
|
|
44
|
+
function getBridgeWindow() {
|
|
45
|
+
if (typeof window === "undefined") {
|
|
46
|
+
return void 0;
|
|
47
|
+
}
|
|
48
|
+
return window;
|
|
49
|
+
}
|
|
50
|
+
function triggerHaptic(type) {
|
|
51
|
+
const bridge = getBridgeWindow();
|
|
52
|
+
if (typeof bridge?.triggerHaptic === "function") {
|
|
53
|
+
bridge.triggerHaptic(type);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (isDevelopment()) {
|
|
57
|
+
console.warn(
|
|
58
|
+
"[oasiz/sdk] triggerHaptic bridge is unavailable. This is expected in local development."
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/multiplayer.ts
|
|
64
|
+
function isDevelopment2() {
|
|
65
|
+
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
66
|
+
return nodeEnv !== "production";
|
|
67
|
+
}
|
|
68
|
+
function getBridgeWindow2() {
|
|
69
|
+
if (typeof window === "undefined") {
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
return window;
|
|
73
|
+
}
|
|
74
|
+
function shareRoomCode(roomCode) {
|
|
75
|
+
const bridge = getBridgeWindow2();
|
|
76
|
+
if (typeof bridge?.shareRoomCode === "function") {
|
|
77
|
+
bridge.shareRoomCode(roomCode);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (isDevelopment2()) {
|
|
81
|
+
console.warn(
|
|
82
|
+
"[oasiz/sdk] shareRoomCode bridge is unavailable. This is expected in local development."
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function getGameId() {
|
|
87
|
+
const bridge = getBridgeWindow2();
|
|
88
|
+
return bridge?.__GAME_ID__;
|
|
89
|
+
}
|
|
90
|
+
function getRoomCode() {
|
|
91
|
+
const bridge = getBridgeWindow2();
|
|
92
|
+
return bridge?.__ROOM_CODE__;
|
|
93
|
+
}
|
|
94
|
+
function getPlayerName() {
|
|
95
|
+
const bridge = getBridgeWindow2();
|
|
96
|
+
return bridge?.__PLAYER_NAME__;
|
|
97
|
+
}
|
|
98
|
+
function getPlayerAvatar() {
|
|
99
|
+
const bridge = getBridgeWindow2();
|
|
100
|
+
return bridge?.__PLAYER_AVATAR__;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/score.ts
|
|
104
|
+
function isDevelopment3() {
|
|
105
|
+
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
106
|
+
return nodeEnv !== "production";
|
|
107
|
+
}
|
|
108
|
+
function warnMissingBridge(methodName) {
|
|
109
|
+
if (isDevelopment3()) {
|
|
110
|
+
console.warn(
|
|
111
|
+
"[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function getBridgeWindow3() {
|
|
116
|
+
if (typeof window === "undefined") {
|
|
117
|
+
return void 0;
|
|
118
|
+
}
|
|
119
|
+
return window;
|
|
120
|
+
}
|
|
121
|
+
function submitScore(score) {
|
|
122
|
+
if (!Number.isFinite(score)) {
|
|
123
|
+
if (isDevelopment3()) {
|
|
124
|
+
console.warn("[oasiz/sdk] submitScore expected a finite number:", score);
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const bridge = getBridgeWindow3();
|
|
129
|
+
const normalizedScore = Math.max(0, Math.floor(score));
|
|
130
|
+
if (typeof bridge?.submitScore === "function") {
|
|
131
|
+
bridge.submitScore(normalizedScore);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
warnMissingBridge("submitScore");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/state.ts
|
|
138
|
+
function isDevelopment4() {
|
|
139
|
+
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
140
|
+
return nodeEnv !== "production";
|
|
141
|
+
}
|
|
142
|
+
function getBridgeWindow4() {
|
|
143
|
+
if (typeof window === "undefined") {
|
|
144
|
+
return void 0;
|
|
145
|
+
}
|
|
146
|
+
return window;
|
|
147
|
+
}
|
|
148
|
+
function isPlainObject(value) {
|
|
149
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
const proto = Object.getPrototypeOf(value);
|
|
153
|
+
return proto === Object.prototype || proto === null;
|
|
154
|
+
}
|
|
155
|
+
function warnMissingBridge2(methodName) {
|
|
156
|
+
if (isDevelopment4()) {
|
|
157
|
+
console.warn(
|
|
158
|
+
"[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function loadGameState() {
|
|
163
|
+
const bridge = getBridgeWindow4();
|
|
164
|
+
if (typeof bridge?.loadGameState !== "function") {
|
|
165
|
+
warnMissingBridge2("loadGameState");
|
|
166
|
+
return {};
|
|
167
|
+
}
|
|
168
|
+
const state = bridge.loadGameState();
|
|
169
|
+
if (!isPlainObject(state)) {
|
|
170
|
+
if (isDevelopment4()) {
|
|
171
|
+
console.warn(
|
|
172
|
+
"[oasiz/sdk] loadGameState returned invalid data. Falling back to empty object."
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
return {};
|
|
176
|
+
}
|
|
177
|
+
return state;
|
|
178
|
+
}
|
|
179
|
+
function saveGameState(state) {
|
|
180
|
+
if (!isPlainObject(state)) {
|
|
181
|
+
if (isDevelopment4()) {
|
|
182
|
+
console.warn("[oasiz/sdk] saveGameState expected a plain object:", state);
|
|
183
|
+
}
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const bridge = getBridgeWindow4();
|
|
187
|
+
if (typeof bridge?.saveGameState === "function") {
|
|
188
|
+
bridge.saveGameState(state);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
warnMissingBridge2("saveGameState");
|
|
192
|
+
}
|
|
193
|
+
function flushGameState() {
|
|
194
|
+
const bridge = getBridgeWindow4();
|
|
195
|
+
if (typeof bridge?.flushGameState === "function") {
|
|
196
|
+
bridge.flushGameState();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
warnMissingBridge2("flushGameState");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/lifecycle.ts
|
|
203
|
+
function isDevelopment5() {
|
|
204
|
+
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
205
|
+
return nodeEnv !== "production";
|
|
206
|
+
}
|
|
207
|
+
function addLifecycleListener(eventName, callback) {
|
|
208
|
+
if (typeof window === "undefined") {
|
|
209
|
+
if (isDevelopment5()) {
|
|
210
|
+
console.warn(
|
|
211
|
+
"[oasiz/sdk] " + eventName + " listener registered without a browser window. This is expected in local development."
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
return () => {
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
const handler = () => callback();
|
|
218
|
+
window.addEventListener(eventName, handler);
|
|
219
|
+
return () => window.removeEventListener(eventName, handler);
|
|
220
|
+
}
|
|
221
|
+
function onPause(callback) {
|
|
222
|
+
return addLifecycleListener("oasiz:pause", callback);
|
|
223
|
+
}
|
|
224
|
+
function onResume(callback) {
|
|
225
|
+
return addLifecycleListener("oasiz:resume", callback);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// src/index.ts
|
|
229
|
+
var oasiz = {
|
|
230
|
+
submitScore,
|
|
231
|
+
triggerHaptic,
|
|
232
|
+
loadGameState,
|
|
233
|
+
saveGameState,
|
|
234
|
+
flushGameState,
|
|
235
|
+
shareRoomCode,
|
|
236
|
+
onPause,
|
|
237
|
+
onResume,
|
|
238
|
+
get gameId() {
|
|
239
|
+
return getGameId();
|
|
240
|
+
},
|
|
241
|
+
get roomCode() {
|
|
242
|
+
return getRoomCode();
|
|
243
|
+
},
|
|
244
|
+
get playerName() {
|
|
245
|
+
return getPlayerName();
|
|
246
|
+
},
|
|
247
|
+
get playerAvatar() {
|
|
248
|
+
return getPlayerAvatar();
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
return __toCommonJS(index_exports);
|
|
252
|
+
})();
|