@indiegems/gem-web-sdk 15.3.3 → 16.0.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/CHANGELOG.md CHANGED
@@ -16,6 +16,32 @@ Its entries are grouped under up to five headings:
16
16
  - **Rebuild**: a type changed. Recompile against the new version; code that compiles today keeps compiling unless the entry says otherwise.
17
17
  - **New capability**: something a game can now do. Nothing changes unless you use it.
18
18
 
19
+ ## 16.0.1
20
+
21
+ Upgrading from 16.0.0. Impact: none.
22
+
23
+ Nothing in this release asks anything of a game.
24
+
25
+ ## 16.0.0
26
+
27
+ Upgrading from 15.3.3. Impact: required.
28
+
29
+ ### Must change
30
+
31
+ - If you run the parent conformance kit against your own parent, it now reports version 2. Update your test fixture to provide the new userActivation and reportError members. A parent that advertises the new app links, open game or store capabilities must also expose surfacesShown and dismiss so the new cases can run. Cases for capabilities the parent does not advertise pass vacuously, but the check that an unadvertised capability is refused always runs.
32
+
33
+ ### Rebuild
34
+
35
+ - The lists and unions of messages sent between game and parent each gained entries for app links, opening an app or game, similar games and the store. Recompiling is enough. If your code switches exhaustively over these message types, add cases for the new ones or let them fall through to your default handling.
36
+ - The capability type gained three new names: appLinks, openGame and store. Recompiling is enough. If you keep an exhaustive mapping over capabilities, add entries for these three.
37
+ - The size check for raw messages now takes an optional cap argument. Existing calls compile and behave as before, so recompiling is enough.
38
+
39
+ ### New capability
40
+
41
+ - Games can now use Gem.arcade to ask the Arcade for app-store links, to open an app listing, to open another game, and to fetch similar games as cards. An availability check tells you whether the Arcade supports each feature. Every call resolves with an outcome of ok, declined or unavailable plus a reason, and never rejects. If the Arcade does not advertise the capability, the call resolves unavailable without sending anything. Calls that act on the player need a real press from the player, and only one such call can be open at a time. Draw cards the way the Arcade draws its tiles, and treat card text as player text.
42
+ - Games can now use Gem.store to read the platform store's offers, start a purchase, and listen for purchases that settle later. Calls resolve with an outcome and never reject, and a store that is not advertised resolves as unavailable without sending anything. A purchase needs a real press from the player, and only one can be open at a time. If a purchase comes back without success, treat the result as unknown rather than as proof that nothing was bought, because the connection can close after the player has paid. Re-read the player's holdings and keep your settlement listener attached. Show prices exactly as given.
43
+ - If you embed a game with the frame class, you can now send any of the new Arcade or store asks through a single requestArcade call. It is gated on the capability the message belongs to. Answers to those asks are delivered to a new onArcadeAnswer callback that you can pass in the frame options.
44
+
19
45
  ## 15.3.3
20
46
 
21
47
  Upgrading from 15.3.2. Impact: none.
package/README.md CHANGED
@@ -31,6 +31,7 @@ Read them here rather than guessing from the type declarations, which carry sign
31
31
  | leaderboards | [`docs/leaderboards.md`](docs/leaderboards.md) |
32
32
  | currencies, items, shops and loot | [`docs/inventory-and-catalogs.md`](docs/inventory-and-catalogs.md), [`docs/game-economy-tutorial.md`](docs/game-economy-tutorial.md), [`docs/trading-and-gifting.md`](docs/trading-and-gifting.md) |
33
33
  | Gems, Coins and achievements | [`docs/arcade-economy.md`](docs/arcade-economy.md), [`docs/achievements.md`](docs/achievements.md), [`docs/brand-art.md`](docs/brand-art.md) |
34
+ | linking to the Arcade app or your game's app, opening another game, games like yours, and selling Gem packs, Boosts and passes for real money — the Arcade Store | [`docs/arcade-and-store.md`](docs/arcade-and-store.md) |
34
35
  | what to signal at every break in play — level complete, game over, back to menu | [`docs/platform-moments.md`](docs/platform-moments.md) |
35
36
  | daily challenges, async opponents, friends | [`docs/daily-challenges.md`](docs/daily-challenges.md), [`docs/async-opponents.md`](docs/async-opponents.md), [`docs/friends.md`](docs/friends.md) |
36
37
  | a button the player presses for a revive or an extra try — rewarded ads | [`docs/rewarded-ads.md`](docs/rewarded-ads.md) |
@@ -16,12 +16,18 @@ interface ParentFixture {
16
16
  port1: MessagePort;
17
17
  port2: MessagePort;
18
18
  };
19
+ readonly userActivation: {
20
+ readonly isActive: boolean;
21
+ } | undefined;
22
+ readonly reportError: (code: string, message?: string) => void;
19
23
  }
20
24
  interface ParentUnderTest {
21
25
  start(): void;
22
26
  close(): void;
23
27
  readonly state: string;
24
28
  readonly protocolVersion: number | null;
29
+ readonly surfacesShown?: number;
30
+ dismiss?(): void;
25
31
  }
26
32
  type ParentFactory = (fixture: ParentFixture) => ParentUnderTest;
27
33
  interface ParentConformanceOptions {
@@ -44,7 +50,7 @@ interface ParentConformanceResult {
44
50
  readonly ok: boolean;
45
51
  readonly message?: string;
46
52
  }
47
- declare const PARENT_CONFORMANCE_VERSION = 1;
53
+ declare const PARENT_CONFORMANCE_VERSION = 2;
48
54
  declare const PARENT_CONFORMANCE_CASES: readonly ParentConformanceCase[];
49
55
  declare function runParentConformance(factory: ParentFactory, options: ParentConformanceOptions): Promise<readonly ParentConformanceResult[]>;
50
56
  export { PARENT_CONFORMANCE_CASES, PARENT_CONFORMANCE_VERSION, type ParentConformanceCase, ParentConformanceError, type ParentConformanceOptions, type ParentConformanceResult, type ParentFactory, type ParentFixture, type ParentState, type ParentUnderTest, runParentConformance };
package/dist/game.d.ts CHANGED
@@ -2326,6 +2326,120 @@ interface GemFriendChallengeResult {
2326
2326
  readonly retryAfterMs?: number;
2327
2327
  readonly detail?: string;
2328
2328
  }
2329
+ interface GemRequestAppLinks {
2330
+ readonly gem: typeof PROTOCOL;
2331
+ readonly type: "gem.requestAppLinks";
2332
+ readonly requestId: string;
2333
+ }
2334
+ interface GemAppLinksResult {
2335
+ readonly gem: typeof PROTOCOL;
2336
+ readonly type: "gem.appLinksResult";
2337
+ readonly requestId: string;
2338
+ readonly outcome: "ok" | "declined" | "unavailable";
2339
+ readonly reason?: string;
2340
+ readonly arcade?: {
2341
+ store: "app_store" | "google_play";
2342
+ };
2343
+ readonly game?: {
2344
+ store: "app_store" | "google_play";
2345
+ };
2346
+ }
2347
+ interface GemRequestOpenApp {
2348
+ readonly gem: typeof PROTOCOL;
2349
+ readonly type: "gem.requestOpenApp";
2350
+ readonly requestId: string;
2351
+ readonly target: "arcade" | "game";
2352
+ }
2353
+ interface GemOpenAppResult {
2354
+ readonly gem: typeof PROTOCOL;
2355
+ readonly type: "gem.openAppResult";
2356
+ readonly requestId: string;
2357
+ readonly outcome: "ok" | "declined" | "unavailable";
2358
+ readonly reason?: string;
2359
+ }
2360
+ interface GemRequestOpenGame {
2361
+ readonly gem: typeof PROTOCOL;
2362
+ readonly type: "gem.requestOpenGame";
2363
+ readonly requestId: string;
2364
+ readonly ref: string;
2365
+ }
2366
+ interface GemOpenGameResult {
2367
+ readonly gem: typeof PROTOCOL;
2368
+ readonly type: "gem.openGameResult";
2369
+ readonly requestId: string;
2370
+ readonly outcome: "ok" | "declined" | "unavailable";
2371
+ readonly reason?: string;
2372
+ }
2373
+ interface GemRequestSimilarGames {
2374
+ readonly gem: typeof PROTOCOL;
2375
+ readonly type: "gem.requestSimilarGames";
2376
+ readonly requestId: string;
2377
+ readonly limit?: number;
2378
+ }
2379
+ interface GemSimilarGamesResult {
2380
+ readonly gem: typeof PROTOCOL;
2381
+ readonly type: "gem.similarGamesResult";
2382
+ readonly requestId: string;
2383
+ readonly outcome: "ok" | "declined" | "unavailable";
2384
+ readonly reason?: string;
2385
+ readonly games: {
2386
+ gameId: string;
2387
+ slug?: string;
2388
+ iconUrl: string;
2389
+ capsuleLandscapeUrl: string;
2390
+ capsulePortraitUrl: string;
2391
+ previewVideoUrl?: string;
2392
+ previewPosterUrl?: string;
2393
+ untrusted: {
2394
+ name: string;
2395
+ tagline: string;
2396
+ shortDescription: string;
2397
+ tags: string[];
2398
+ };
2399
+ }[];
2400
+ }
2401
+ interface GemRequestStoreOffers {
2402
+ readonly gem: typeof PROTOCOL;
2403
+ readonly type: "gem.requestStoreOffers";
2404
+ readonly requestId: string;
2405
+ }
2406
+ interface GemStoreOffersResult {
2407
+ readonly gem: typeof PROTOCOL;
2408
+ readonly type: "gem.storeOffersResult";
2409
+ readonly requestId: string;
2410
+ readonly outcome: "ok" | "declined" | "unavailable";
2411
+ readonly reason?: string;
2412
+ readonly offers: {
2413
+ skuId: string;
2414
+ kind: "gem_pack" | "boost" | "pass" | "bundle";
2415
+ name: string;
2416
+ description: string;
2417
+ imageUrl?: string;
2418
+ priceDisplay: string;
2419
+ grant?: {
2420
+ currency: string;
2421
+ amount: number;
2422
+ };
2423
+ }[];
2424
+ }
2425
+ interface GemRequestStorePurchase {
2426
+ readonly gem: typeof PROTOCOL;
2427
+ readonly type: "gem.requestStorePurchase";
2428
+ readonly requestId: string;
2429
+ readonly skuId: string;
2430
+ }
2431
+ interface GemStorePurchaseResult {
2432
+ readonly gem: typeof PROTOCOL;
2433
+ readonly type: "gem.storePurchaseResult";
2434
+ readonly requestId: string;
2435
+ readonly outcome: "ok" | "declined" | "unavailable";
2436
+ readonly reason?: string;
2437
+ }
2438
+ interface GemStorePurchaseSettled {
2439
+ readonly gem: typeof PROTOCOL;
2440
+ readonly type: "gem.storePurchaseSettled";
2441
+ readonly skuId: string;
2442
+ }
2329
2443
  interface ConnectOptions {
2330
2444
  readonly clusterTargetId?: ClusterTargetLike;
2331
2445
  readonly retry?: StartMatchRetryOptions;
@@ -2869,6 +2983,8 @@ interface FramePlayer extends PlayerIdentity {
2869
2983
  readonly avatarUrl?: string;
2870
2984
  readonly boost: PlayerBoost;
2871
2985
  }
2986
+ type GemArcadeAsk = Omit<GemRequestAppLinks, "gem"> | Omit<GemRequestOpenApp, "gem"> | Omit<GemRequestOpenGame, "gem"> | Omit<GemRequestSimilarGames, "gem"> | Omit<GemRequestStoreOffers, "gem"> | Omit<GemRequestStorePurchase, "gem">;
2987
+ type GemArcadeAnswer = GemAppLinksResult | GemOpenAppResult | GemOpenGameResult | GemSimilarGamesResult | GemStoreOffersResult | GemStorePurchaseResult | GemStorePurchaseSettled;
2872
2988
  interface FrameCallbacks {
2873
2989
  onToken?(msg: GemToken): void;
2874
2990
  onPause?(msg: GemPause): void;
@@ -2905,6 +3021,7 @@ interface FrameCallbacks {
2905
3021
  onMomentResult?(msg: GemMomentResult): void;
2906
3022
  onSignInResult?(msg: GemSignInResult): void;
2907
3023
  onFriendChallengeResult?(msg: GemFriendChallengeResult): void;
3024
+ onArcadeAnswer?(msg: GemArcadeAnswer): void;
2908
3025
  onError?(code: GemErrorCode, message?: string): void;
2909
3026
  onDropped?(code: GemErrorCode, message?: string): void;
2910
3027
  onStateChange?(state: FrameState): void;
@@ -2983,6 +3100,7 @@ declare class GemFrame {
2983
3100
  readyCalled(): boolean;
2984
3101
  requestSignIn(requestId: string): boolean;
2985
3102
  requestFriendChallenge(requestId: string, playerId: string, template: string, params?: Readonly<Record<string, string | number>>): boolean;
3103
+ requestArcade(msg: GemArcadeAsk): boolean;
2986
3104
  close(): void;
2987
3105
  private transition;
2988
3106
  private refuseMalformed;
@@ -3002,6 +3120,72 @@ interface ShareApi {
3002
3120
  readonly available: boolean;
3003
3121
  request(request?: ShareRequest): void;
3004
3122
  }
3123
+ type ArcadeOutcomeKind = "ok" | "declined" | "unavailable";
3124
+ interface ArcadeOutcome {
3125
+ readonly outcome: ArcadeOutcomeKind;
3126
+ readonly reason?: string;
3127
+ }
3128
+ type AppStore = "app_store" | "google_play";
3129
+ interface AppListing {
3130
+ readonly store: AppStore;
3131
+ }
3132
+ interface AppLinksOutcome extends ArcadeOutcome {
3133
+ readonly arcade?: AppListing;
3134
+ readonly game?: AppListing;
3135
+ }
3136
+ interface GameCard {
3137
+ readonly gameId: string;
3138
+ readonly slug?: string;
3139
+ readonly name: PlayerText;
3140
+ readonly tagline: PlayerText;
3141
+ readonly shortDescription: PlayerText;
3142
+ readonly tags: readonly PlayerText[];
3143
+ readonly iconUrl: string;
3144
+ readonly capsuleLandscapeUrl: string;
3145
+ readonly capsulePortraitUrl: string;
3146
+ readonly previewVideoUrl?: string;
3147
+ readonly previewPosterUrl?: string;
3148
+ }
3149
+ interface SimilarGamesOutcome extends ArcadeOutcome {
3150
+ readonly games: readonly GameCard[];
3151
+ }
3152
+ interface ArcadeAvailability {
3153
+ readonly appLinks: boolean;
3154
+ readonly openGame: boolean;
3155
+ }
3156
+ interface ArcadeApi {
3157
+ readonly available: ArcadeAvailability;
3158
+ appLinks(): Promise<AppLinksOutcome>;
3159
+ openApp(target: "arcade" | "game"): Promise<ArcadeOutcome>;
3160
+ openGame(ref: string): Promise<ArcadeOutcome>;
3161
+ similarGames(options?: {
3162
+ readonly limit?: number;
3163
+ }): Promise<SimilarGamesOutcome>;
3164
+ }
3165
+ interface ArcadeOffer {
3166
+ readonly skuId: string;
3167
+ readonly kind: "gem_pack" | "boost" | "pass" | "bundle";
3168
+ readonly name: string;
3169
+ readonly description: string;
3170
+ readonly imageUrl?: string;
3171
+ readonly priceDisplay: string;
3172
+ readonly grant?: {
3173
+ readonly currency: string;
3174
+ readonly amount: number;
3175
+ };
3176
+ }
3177
+ interface StoreOffersOutcome extends ArcadeOutcome {
3178
+ readonly offers: readonly ArcadeOffer[];
3179
+ }
3180
+ interface StoreSettlement {
3181
+ readonly skuId: string;
3182
+ }
3183
+ interface StoreApi {
3184
+ readonly available: boolean;
3185
+ offers(): Promise<StoreOffersOutcome>;
3186
+ purchase(skuId: string): Promise<ArcadeOutcome>;
3187
+ onSettled(listener: (settlement: StoreSettlement) => void): () => void;
3188
+ }
3005
3189
  interface VibrationApi {
3006
3190
  readonly available: boolean;
3007
3191
  vibrate(pattern: number | readonly number[]): boolean;
@@ -3261,6 +3445,8 @@ interface Gem {
3261
3445
  readonly ads: AdsApi;
3262
3446
  readonly account: AccountApi;
3263
3447
  readonly share: ShareApi;
3448
+ readonly arcade: ArcadeApi;
3449
+ readonly store: StoreApi;
3264
3450
  readonly avatarPickerAvailable: boolean;
3265
3451
  openAvatarPicker(options?: {
3266
3452
  readonly tab?: "2d" | "3d";
@@ -3315,4 +3501,4 @@ interface ExitAnalytics {
3315
3501
  }
3316
3502
  declare function leaveAndExit(rooms: ExitRooms, bridge: ExitBridge | null, reason?: string, analytics?: ExitAnalytics): Promise<void>;
3317
3503
  declare function createGem(options?: GemOptions): Gem;
3318
- export { ARCADE_EMBEDDERS, AVATAR_RIGS, type AccountApi, type AdFormat, type AdOutcome, type AdOutcomeKind, type AdRequest, type AdsApi, AnalyticsApi, type AnalyticsFlushOptions, type AnalyticsFlushResult, type AnalyticsOptions, type AnalyticsRejection, type AnalyticsValue, AuthError, type AuthFailure, type AuthState, type Avatar3dFamily, type Avatar3dOffer, type Avatar3dPrice, type Avatar3dPurchaseRequest, type AvatarRigNode, type AvatarRigs, type Avatars3dApi, type BootMark, type BootTimeline, type Challenge, type ChallengeWindow, ChallengesApi, type ConfiguredPurchasePayment, type ConfiguredPurchaseRequest, type ConfiguredPurchaseResult, type ControlsApi, DEVICE_SETTINGS_MAX_BYTES, DedicatedServerError, type DedicatedServerFailure, type DedicatedServerSession, type DevToolsOpener, type DeviceSettings, type DeviceSettingsApi, type DeviceSettingsPutOutcome, type DirectPurchaseRequest, type DirectPurchaseResult, type EarnAllowance, type EarnAllowanceEvent, type EarnAllowancePeriod, type EarnAllowanceReadOptions, type EntityLeaderboard, type EntityLeaderboardEntry, type EntityLeaderboardOptions, type EntityType, type ExitAnalytics, type ExitBridge, type ExitRooms, type FrameState, type Friend, type FriendChallenge, FriendChallengeError, type FriendChallengeErrorCode, type FriendChallengeOutcome, type FriendChallengeOutcomeKind, type FriendChallengeRequest, type FriendChallengesPage, FriendsApi, type FriendsPage, type FunctionFailure, type FunctionInvokeOptions, type FunctionResult, FunctionsApi, type GameConfig, type GameMenu, type GameMenuItem, type GameServerLink, type GameSettingsApi, type Gem, GemApiError, type GemAudioChannels, GemClient, type GemCohort, type GemCohorts, GemConfigError, type GemControlBox, type GemCorner, type GemDevTools, GemFrame, GemFunctionError, type GemGameChoiceSetting, type GemGameSetting, type GemGameSettingBase, type GemGameSettingChange, type GemGameSettingIcon, type GemGameSettingOption, type GemGameSettingValue, type GemGameSliderSetting, type GemGameToggleSetting, type GemGraphicsQuality, type GemIdentity, type GemInsets, type GemLook, type GemLookBase, type GemLookDelta, type GemLookOptions, type GemLookSpeed, type GemMatchApi, type GemMatchServerModule, type GemOptions, type GemPlayer, type GemPrefs, type GemRecommendedSettings, type GemReservedArea, GemSaveError, type GemServerBundle, type GemServerFactory, type GemServerHost, type GemServerHostProfile, type GemServerLifecycle, type GemTerminationNotice, GemUnframedError, type GemViewport, type GetLeaderboardOptions, type JoinWelcome, type Leaderboard, type LeaderboardEntry, type LeaderboardPeriod, LeaderboardsApi, type ListChallengesOptions, type ListFriendChallengesOptions, type ListFriendsOptions, MAX_PERIODS_BACK, type MatchConnectOptions, type MatchConnection, type MatchHosting, type MatchHostingMode, type MatchServeOptions, type MatchTransport, type MessageMeta, type MomentKind, type MomentResult, type MomentSignal, type MomentsApi, type MultiTransportSession, PLATFORM_EVENTS, type PeriodOptions, PlatformApi, PlatformCurrenciesApi, type PlatformCurrency, type PlatformCurrencyAccess, type PlatformCurrencyPurchasePayment, type PlatformCurrencyPurchaseRequest, type PlatformCurrencyPurchaseResult, type PlatformCurrencyReadOptions, PlatformEarnAllowanceApi, type PlatformEventName, type PlayerBadge, type PlayerBoost, type PlayerBoostMultiplier, type PlayerIdentity, type PlayerProfile, PlayerText, type ProfileCallOptions, type ProfileShowcaseEntry, ProfilesApi, type PurchaseApi, type PurchaseOptions, type PurchaseOutcome, PurchaseRefusal, type PurchaseRefusalCode, type PurchaseRequest, type PutBytesOptions, type PutSaveOptions, type RankedRow, type RecipeAvailability, type RecipeLock, type RewardCue, type RewardedStatus, type SavePage, type SaveRecord, type SendOptions$1 as SendOptions, type ServerTokenGrant, type SessionEndReason, type ShareApi, type ShareRequest, ShowcaseApi, type ShowcaseCallOptions, type ShowcaseFriendEntry, type ShowcaseFriends, type ShowcaseValue, type SignInOutcome, type SignInOutcomeKind, type SnapshotCurrency, type SnapshotItem, type TransportAdvert, type TransportKind, TransportRefusal, UNRELIABLE_CHANNEL_LABEL, type VibrationApi, type WalletVisibleOptions, type WornAvatar3d, asPlayerText, createBootTimeline, createGem, experimentSelection, leaveAndExit, mapIdentity, markOnResolve, platformIconUrl, presentJoinCredential, readTemplateTransports, readTransportAdvert, reportOnResolve, text, webTransportAvailable };
3504
+ export { ARCADE_EMBEDDERS, AVATAR_RIGS, type AccountApi, type AdFormat, type AdOutcome, type AdOutcomeKind, type AdRequest, type AdsApi, AnalyticsApi, type AnalyticsFlushOptions, type AnalyticsFlushResult, type AnalyticsOptions, type AnalyticsRejection, type AnalyticsValue, type AppLinksOutcome, type AppListing, type AppStore, type ArcadeApi, type ArcadeAvailability, type ArcadeOffer, type ArcadeOutcome, type ArcadeOutcomeKind, AuthError, type AuthFailure, type AuthState, type Avatar3dFamily, type Avatar3dOffer, type Avatar3dPrice, type Avatar3dPurchaseRequest, type AvatarRigNode, type AvatarRigs, type Avatars3dApi, type BootMark, type BootTimeline, type Challenge, type ChallengeWindow, ChallengesApi, type ConfiguredPurchasePayment, type ConfiguredPurchaseRequest, type ConfiguredPurchaseResult, type ControlsApi, DEVICE_SETTINGS_MAX_BYTES, DedicatedServerError, type DedicatedServerFailure, type DedicatedServerSession, type DevToolsOpener, type DeviceSettings, type DeviceSettingsApi, type DeviceSettingsPutOutcome, type DirectPurchaseRequest, type DirectPurchaseResult, type EarnAllowance, type EarnAllowanceEvent, type EarnAllowancePeriod, type EarnAllowanceReadOptions, type EntityLeaderboard, type EntityLeaderboardEntry, type EntityLeaderboardOptions, type EntityType, type ExitAnalytics, type ExitBridge, type ExitRooms, type FrameState, type Friend, type FriendChallenge, FriendChallengeError, type FriendChallengeErrorCode, type FriendChallengeOutcome, type FriendChallengeOutcomeKind, type FriendChallengeRequest, type FriendChallengesPage, FriendsApi, type FriendsPage, type FunctionFailure, type FunctionInvokeOptions, type FunctionResult, FunctionsApi, type GameCard, type GameConfig, type GameMenu, type GameMenuItem, type GameServerLink, type GameSettingsApi, type Gem, GemApiError, type GemAudioChannels, GemClient, type GemCohort, type GemCohorts, GemConfigError, type GemControlBox, type GemCorner, type GemDevTools, GemFrame, GemFunctionError, type GemGameChoiceSetting, type GemGameSetting, type GemGameSettingBase, type GemGameSettingChange, type GemGameSettingIcon, type GemGameSettingOption, type GemGameSettingValue, type GemGameSliderSetting, type GemGameToggleSetting, type GemGraphicsQuality, type GemIdentity, type GemInsets, type GemLook, type GemLookBase, type GemLookDelta, type GemLookOptions, type GemLookSpeed, type GemMatchApi, type GemMatchServerModule, type GemOptions, type GemPlayer, type GemPrefs, type GemRecommendedSettings, type GemReservedArea, GemSaveError, type GemServerBundle, type GemServerFactory, type GemServerHost, type GemServerHostProfile, type GemServerLifecycle, type GemTerminationNotice, GemUnframedError, type GemViewport, type GetLeaderboardOptions, type JoinWelcome, type Leaderboard, type LeaderboardEntry, type LeaderboardPeriod, LeaderboardsApi, type ListChallengesOptions, type ListFriendChallengesOptions, type ListFriendsOptions, MAX_PERIODS_BACK, type MatchConnectOptions, type MatchConnection, type MatchHosting, type MatchHostingMode, type MatchServeOptions, type MatchTransport, type MessageMeta, type MomentKind, type MomentResult, type MomentSignal, type MomentsApi, type MultiTransportSession, PLATFORM_EVENTS, type PeriodOptions, PlatformApi, PlatformCurrenciesApi, type PlatformCurrency, type PlatformCurrencyAccess, type PlatformCurrencyPurchasePayment, type PlatformCurrencyPurchaseRequest, type PlatformCurrencyPurchaseResult, type PlatformCurrencyReadOptions, PlatformEarnAllowanceApi, type PlatformEventName, type PlayerBadge, type PlayerBoost, type PlayerBoostMultiplier, type PlayerIdentity, type PlayerProfile, PlayerText, type ProfileCallOptions, type ProfileShowcaseEntry, ProfilesApi, type PurchaseApi, type PurchaseOptions, type PurchaseOutcome, PurchaseRefusal, type PurchaseRefusalCode, type PurchaseRequest, type PutBytesOptions, type PutSaveOptions, type RankedRow, type RecipeAvailability, type RecipeLock, type RewardCue, type RewardedStatus, type SavePage, type SaveRecord, type SendOptions$1 as SendOptions, type ServerTokenGrant, type SessionEndReason, type ShareApi, type ShareRequest, ShowcaseApi, type ShowcaseCallOptions, type ShowcaseFriendEntry, type ShowcaseFriends, type ShowcaseValue, type SignInOutcome, type SignInOutcomeKind, type SimilarGamesOutcome, type SnapshotCurrency, type SnapshotItem, type StoreApi, type StoreOffersOutcome, type StoreSettlement, type TransportAdvert, type TransportKind, TransportRefusal, UNRELIABLE_CHANNEL_LABEL, type VibrationApi, type WalletVisibleOptions, type WornAvatar3d, asPlayerText, createBootTimeline, createGem, experimentSelection, leaveAndExit, mapIdentity, markOnResolve, platformIconUrl, presentJoinCredential, readTemplateTransports, readTransportAdvert, reportOnResolve, text, webTransportAvailable };
@@ -1,2 +1,2 @@
1
- var GemWebSdkBridgeBundle=(function(){'use strict';var L="GemWebSdkHandshake";function re(){return typeof document>"u"?void 0:document.readyState}var F=()=>Date.now();function $(t={}){let e=t.win??window,n=e,r=n[L];if(r!==void 0)return r;let s=t.readyState??re,i=t.now??F,d=[],a=[],c=y=>{let u=y.data;!u||u.type!=="gem.handshake"||(d.length>=4&&(d.shift(),a.shift(),p.dropped+=1),d.push(y),a.push(i()));};e.addEventListener("message",c);let p={events:d,times:a,dropped:0,late:s()==="complete",uninstall(){e.removeEventListener("message",c);}};return n[L]=p,p}function U(t,e,n={}){let r=t[L];if(r===void 0)return null;let s=n.ttlMs??9500,i=n.now??F,d=r.events.splice(0),a=r.times?.splice(0),c=0,p=0,y=false,u=i()-s;for(let f=d.length-1;f>=0;f--){let h=a?.[f];if(h!==void 0&&h<u){p+=1;continue}if(c+=1,e(d[f])===true){y=true;break}}return r.uninstall(),{capture:r,delivered:c,stale:p,accepted:y}}var l="gem-web-bridge",v={min:1,max:1},k=65536,H=8,R=5e3,B=1024;var b=Object.create(null),S="__malformed";var M=Object.create(null),oe=Object.freeze([["gem.asyncOpponents.","asyncOpponents"],["gem.vibration.","vibration"],["gem.viewport.","reservedAreas"],["gem.moments.","moments"],["gem.prefs.","audioChannels"]]);function W(t){let e=M[t];if(e!==void 0)return e;for(let[n,r]of oe)if(t.startsWith(n))return r}function ae(t){let e=/^([a-z][a-z0-9+.-]*):\/\/([a-z0-9.-]+|\[[0-9a-f:.]+\])(:([0-9]{1,5}))?$/i.exec(t);return e===null?false:e[4]===void 0||Number(e[4])<=65535}function se(t){let e;try{e=new URL(t);}catch{return false}return e.username!==""||e.password!==""?false:e.protocol==="https:"?true:e.protocol==="http:"&&(e.hostname==="localhost"||e.hostname==="127.0.0.1")}function ie(t){return /^[a-z]{2,8}(-[a-z0-9]{1,8})*$/i.test(t)}function le(t){return /^[a-z_]+$/.test(t)}function A(t,e,n){if(e>H)return `nesting deeper than ${H}`;if(++n.nodes>R)return `more than ${R} values`;if(n.bytes>k)return `over the ${k} byte limit`;if(t==null)return n.bytes+=4,null;let r=typeof t;if(r==="boolean")return n.bytes+=5,null;if(r==="number")return n.bytes+=8,null;if(r==="string")return n.bytes+=t.length*3+2,null;if(r!=="object")return `${r} is not plain data`;let s=t;if(n.seen.has(s))return "a repeated or cyclic object reference";if(n.seen.add(s),Array.isArray(t)){if(t.length>B)return `an array of ${t.length} entries, over the ${B} limit`;n.bytes+=2;for(let a of t){let c=A(a,e+1,n);if(c)return c}return null}let i=Object.getPrototypeOf(t);if(i!==Object.prototype&&i!==null)return "a value that is not a plain object";n.bytes+=2;let d=t;for(let a in d){if(!Object.prototype.hasOwnProperty.call(d,a))continue;if(++n.nodes>R)return `more than ${R} values`;if(n.bytes+=a.length*3+4,n.bytes>k)return `over the ${k} byte limit`;let c=A(d[a],e+1,n);if(c)return c}return null}function de(t){let e={nodes:0,bytes:0,seen:new Set},n=A(t,0,e);return n?`message contains ${n}`:e.bytes>k?`message is over the ${k} byte limit`:null}var me={origin:[ae,"not a well-formed origin"],url:[se,"not a safe absolute http(s) URL"],bcp47:[ie,"not a well-formed BCP 47 tag"],code:[le,"not a code of lower-case letters and underscores"]};function N(t,e,n){for(let r of e){let s=n===""?r.n:`${n}.${r.n}`,i=t[r.n];if(i==null){if(r.o)continue;return `${s}: required`}let d=q(i,r,s);if(d)return d}return null}function q(t,e,n){switch(e.k){case "u":return typeof t=="boolean"?null:q(t,{...e,k:typeof t=="string"?"s":"n"},n);case "s":{if(typeof t!="string")return `${n}: expected string`;if(t.length>e.max)return `${n}: exceeds ${e.max} characters`;if(e.f){let[r,s]=me[e.f];if(!r(t))return `${n}: ${s}`}return null}case "n":case "i":return typeof t!="number"||!(e.k=="i"?Number.isInteger:Number.isFinite)(t)?`${n}: expected ${e.k=="i"?"integer":"number"}`:t<e.lo||t>e.hi?`${n}: out of range ${e.lo}..${e.hi}`:null;case "b":return typeof t=="boolean"?null:`${n}: expected boolean`;case "e":{let r=e.v;return r.includes(t)?null:`${n}: not one of ${r.join("|")}`}case "o":return typeof t!="object"||t===null||Array.isArray(t)?`${n}: expected object`:N(t,e.fs,n);case "j":return typeof t!="object"||t===null||Array.isArray(t)?`${n}: expected a plain object`:null;case "a":{if(!Array.isArray(t))return `${n}: expected array`;if(t.length>e.max)return `${n}: exceeds ${e.max} items`;let r=e.it,s=`${n}[]`;for(let i of t){if(i==null){if(r.o)continue;return `${s}: required`}let d=q(i,r,s);if(d)return d}return null}default:{let r=e.k;return `${n}: unknown kind ${String(r)}`}}}var V=Object.create(null);function o(t,e,n,r){return b[t]=n,r&&(M[t]=r),V[t]=s=>{let i=de(s);if(i)return i;if(typeof s!="object"||s===null||Array.isArray(s))return "message: expected object";let d=s;return d.gem!==l?"gem: wrong protocol marker":d.type!==t?`type: expected ${t}`:N(d,e,"")}}var m={n:"requestId",k:"s",max:64};o("gem.handshake",[{n:"versions",k:"o",fs:[{n:"min",k:"i",lo:1,hi:1e3},{n:"max",k:"i",lo:1,hi:1e3}]},{n:"capabilities",k:"a",o:1,max:64,it:{n:"",k:"s",max:64}},{n:"embedder",k:"s",max:2048,f:"origin"},{n:"unbidden",k:"b",o:1}],30);o("gem.handshake.accept",[{n:"v",k:"i",lo:1,hi:1e3},{n:"capabilities",k:"a",o:1,max:64,it:{n:"",k:"s",max:64}}],5);o("gem.token",[{n:"token",k:"s",max:4096},{n:"requestId",k:"s",o:1,max:64},{n:"generation",k:"i",lo:0,hi:2147483647},{n:"apiBaseUrl",k:"s",o:1,max:512,f:"url"},{n:"playerId",k:"s",max:64},{n:"gameId",k:"s",max:64},{n:"channel",k:"e",v:["dev","test","release"]},{n:"gameVersion",k:"s",o:1,max:64},{n:"expiresAt",k:"i",lo:0,hi:4102444800},{n:"chainEndsAt",k:"i",lo:0,hi:4102444800},{n:"allowDevTools",k:"b",o:1}],30);o("gem.token.denied",[m,{n:"retryable",k:"b"},{n:"retryAfterMs",k:"i",o:1,lo:0,hi:36e5},{n:"reason",k:"e",v:["chain_exhausted","unavailable"]},{n:"correlationId",k:"s",max:64}],30);o("gem.player",[{n:"untrusted",k:"o",fs:[{n:"displayName",k:"s",max:64},{n:"displayTag",k:"s",o:1,max:80},{n:"displayHandle",k:"s",max:80}]},{n:"playerId",k:"s",o:1,max:64},{n:"discriminator",k:"s",o:1,max:8},{n:"avatarIconUrl",k:"s",o:1,max:2048,f:"url"},{n:"avatarIconId",k:"s",o:1,max:64},{n:"avatar3dId",k:"s",o:1,max:64},{n:"avatar3dModelUrl",k:"s",o:1,max:2048,f:"url"},{n:"avatar3dIconUrl",k:"s",o:1,max:2048,f:"url"},{n:"avatars3d",k:"a",o:1,max:8,it:{n:"",k:"o",fs:[{n:"family",k:"s",max:32},{n:"id",k:"s",max:64},{n:"modelUrl",k:"s",max:256,f:"url"},{n:"iconUrl",k:"s",max:256,f:"url"}]}},{n:"badges",k:"a",o:1,max:2,it:{n:"",k:"o",fs:[{n:"itemId",k:"s",max:64},{n:"iconUrl",k:"s",max:2048,f:"url"}]}},{n:"displayTag",k:"s",max:8},{n:"avatarUrl",k:"s",o:1,max:2048,f:"url"},{n:"boost",k:"o",o:1,fs:[{n:"multipliers",k:"a",max:8,it:{n:"",k:"o",fs:[{n:"currencyId",k:"s",max:64},{n:"currencySlug",k:"s",max:32},{n:"multiplierBp",k:"i",lo:1e4,hi:1e6}]}},{n:"expiresInDays",k:"i",o:1,lo:1,hi:7}]}],12);o("gem.pause",[{n:"paused",k:"b"}],120);o("gem.prefs",[{n:"reducedMotion",k:"b"},{n:"muted",k:"b"},{n:"showFrameStats",k:"b",o:1},{n:"music",k:"b",o:1},{n:"sounds",k:"b",o:1},{n:"locale",k:"s",max:35,f:"bcp47"},{n:"recommended",k:"o",o:1,fs:[{n:"volume",k:"i",lo:0,hi:100},{n:"batterySaver",k:"b"},{n:"keyboardLayout",k:"e",v:["wasd","arrows"]},{n:"gamepadConfirm",k:"e",v:["south","east"]},{n:"vibration",k:"b"},{n:"lookSensitivity",k:"i",o:1,lo:20,hi:400},{n:"gamepadLookSensitivity",k:"i",o:1,lo:20,hi:400},{n:"invertLookY",k:"b",o:1},{n:"touchMovement",k:"s",o:1,max:16,f:"code"},{n:"graphicsQuality",k:"s",o:1,max:16,f:"code"},{n:"graphicsQualityAuto",k:"b",o:1},{n:"colorHelp",k:"b",o:1}]}],60);o("gem.cohorts",[{n:"cohorts",k:"a",max:8,it:{n:"",k:"o",fs:[{n:"experimentId",k:"s",max:36},{n:"variantKey",k:"s",max:32}]}}],12,"cohorts");o("gem.earnAllowanceChanged",[],30,"earnAllowance");o("gem.viewport",[{n:"insets",k:"o",fs:[{n:"top",k:"i",lo:0,hi:4096},{n:"right",k:"i",lo:0,hi:4096},{n:"bottom",k:"i",lo:0,hi:4096},{n:"left",k:"i",lo:0,hi:4096}]},{n:"reserved",k:"a",o:1,max:4,it:{n:"",k:"o",fs:[{n:"x",k:"i",lo:0,hi:16384},{n:"y",k:"i",lo:0,hi:16384},{n:"width",k:"i",lo:0,hi:16384},{n:"height",k:"i",lo:0,hi:16384},{n:"control",k:"o",o:1,fs:[{n:"x",k:"i",lo:0,hi:16384},{n:"y",k:"i",lo:0,hi:16384},{n:"width",k:"i",lo:0,hi:16384},{n:"height",k:"i",lo:0,hi:16384}]}]}}],60,"viewport");o("gem.deviceSettings",[{n:"settings",k:"j",o:1}],12,"deviceSettings");o("gem.willTerminate",[{n:"reason",k:"e",v:["grant_expiring","session_ended","navigating","kill_switch"]},{n:"graceMs",k:"i",lo:0,hi:6e4}],10);o("gem.roomEvent",[{n:"event",k:"e",v:["updated","match_started","match_ready","match_failed","version_stale"]},{n:"roomId",k:"s",max:64},{n:"matchId",k:"s",o:1,max:64},{n:"version",k:"i",o:1,lo:0,hi:2147483647},{n:"reason",k:"s",o:1,max:64},{n:"platform",k:"e",o:1,v:["universal","mobile"]}],120,"rooms");o("gem.socketState",[{n:"connected",k:"b"},{n:"reason",k:"e",o:1,v:["connecting","dropped","watchdog","terminal"]}],12,"socketState");o("gem.seatedEvent",[{n:"roomId",k:"s",max:64}],60,"partySeating");o("gem.autoStartFailedEvent",[{n:"roomId",k:"s",max:64},{n:"code",k:"s",max:64}],30,"autoStartFailure");o("gem.ticketEvent",[{n:"event",k:"e",v:["queued","matched","expired","cancelled","failed"]},{n:"ticketId",k:"s",max:64},{n:"partySize",k:"i",o:1,lo:1,hi:64},{n:"queuedAt",k:"i",o:1,lo:0,hi:4102444800},{n:"expiresAt",k:"i",o:1,lo:0,hi:4102444800},{n:"reason",k:"s",o:1,max:64},{n:"roomId",k:"s",o:1,max:64}],60,"ticketEvents");o("gem.signalEvent",[{n:"event",k:"e",v:["hello","offer","answer","ice","peerJoined","peerLeft","migration","matchEnded","error"]},{n:"matchId",k:"s",max:64},{n:"data",k:"j"}],1800,"p2p");o("gem.dedicatedEvent",[{n:"event",k:"e",v:["answer","error","matchEnded"]},{n:"matchId",k:"s",max:64},{n:"sdp",k:"s",o:1,max:10240},{n:"sessionId",k:"s",o:1,max:64},{n:"code",k:"s",o:1,max:64},{n:"message",k:"s",o:1,max:256},{n:"reason",k:"s",o:1,max:64}],120,"dedicated");o("gem.partyResult",[m,{n:"partyId",k:"s",o:1,max:64}],30,"parties");o("gem.clusterTarget",[{n:"clusterTargetId",k:"s",max:64},{n:"clusterTargetIds",k:"a",o:1,max:3,it:{n:"",k:"s",max:64}}],12,"clusterTarget");o("gem.devtools",[{n:"action",k:"e",v:["open","close","toggle"]}],30,"devtools");o("gem.screenshot",[{n:"maxWidth",k:"i",lo:1,hi:7680},{n:"maxHeight",k:"i",lo:1,hi:4320}],6,"screenshot");o("gem.screenshot.denied",[{n:"reason",k:"e",v:["not_wired","no_source","unsupported","unreadable","tainted","too_large","busy","declined","failed"]},{n:"retryable",k:"b"}],12,"screenshot");o("gem.requestContext",[],12,"feedbackContext");o("gem.gameContext",[{n:"context",k:"j"}],12,"feedbackContext");o("gem.signal",[{n:"signal",k:"e",v:["join","offer","answer","ice","migrationAck","hostUnreachable"]},{n:"matchId",k:"s",max:64},{n:"data",k:"j"}],1200,"p2p");o("gem.dedicatedOffer",[{n:"matchId",k:"s",max:64},{n:"sdp",k:"s",max:10240},{n:"intent",k:"e",v:["initial","ice_restart","full_reconnect"]}],60,"dedicated");o("gem.partyRequest",[m],12,"parties");o("gem.ready",[],5);o("gem.engaged",[],5,"engagement");o("gem.progress",[{n:"loaded",k:"i",lo:0,hi:1099511627776},{n:"total",k:"i",lo:0,hi:1099511627776}],600);o("gem.requestToken",[m,{n:"reason",k:"e",v:["initial","expiring","rejected"]}],12);o("gem.requestLocalServer",[m,{n:"gameRoomId",k:"s",max:64}],6,"localHost");o("gem.localServer",[m,{n:"serverId",k:"s",o:1,max:128}],30,"localHost");o("gem.localServer.denied",[m,{n:"retryable",k:"b"},{n:"reason",k:"e",v:["refused","unavailable"]}],30,"localHost");o("gem.exit",[{n:"reason",k:"s",o:1,max:64}],5);o("gem.openExternal",[{n:"url",k:"s",max:2048,f:"url"}],6);o("gem.requestFullscreen",[{n:"enabled",k:"b"}],30);o("gem.audioState",[{n:"muted",k:"b"}],120,"audioState");o("gem.rewardCue",[{n:"currencySlug",k:"s",max:32},{n:"expected",k:"i",o:1,lo:1,hi:1e9},{n:"origin",k:"o",o:1,fs:[{n:"x",k:"i",lo:0,hi:16384},{n:"y",k:"i",lo:0,hi:16384}]}],60,"rewardCue");o("gem.walletDisplay",[{n:"visible",k:"b"},{n:"currencies",k:"a",o:1,max:8,it:{n:"",k:"s",max:64}},{n:"score",k:"b",o:1}],60,"walletDisplay");o("gem.controlsDeclare",[{n:"uses",k:"o",fs:[{n:"lookSensitivity",k:"s",o:1,max:16,f:"code"},{n:"gamepadLookSensitivity",k:"s",o:1,max:16,f:"code"},{n:"invertLookY",k:"s",o:1,max:16,f:"code"},{n:"touchMovement",k:"s",o:1,max:16,f:"code"}]}],60,"controls");o("gem.menu",[{n:"settings",k:"b"},{n:"items",k:"a",o:1,max:4,it:{n:"",k:"o",fs:[{n:"id",k:"s",max:32},{n:"label",k:"s",max:40}]}}],60,"gameMenu");o("gem.menuSelect",[{n:"entry",k:"e",v:["settings","item"]},{n:"id",k:"s",o:1,max:32}],60,"gameMenu");o("gem.gemCorner",[{n:"corner",k:"e",v:["top-left","top-right","bottom-left","bottom-right"]}],12,"gemCorner");o("gem.settingsDeclare",[{n:"settings",k:"a",max:8,it:{n:"",k:"o",fs:[{n:"id",k:"s",max:40},{n:"label",k:"s",max:40},{n:"kind",k:"e",v:["toggle","slider","choice"]},{n:"value",k:"u",max:40,lo:-1e6,hi:1e6},{n:"quick",k:"b",o:1},{n:"icon",k:"s",o:1,max:16,f:"code"},{n:"min",k:"n",o:1,lo:-1e6,hi:1e6},{n:"max",k:"n",o:1,lo:-1e6,hi:1e6},{n:"step",k:"n",o:1,lo:0,hi:1e6},{n:"options",k:"a",o:1,max:4,it:{n:"",k:"o",fs:[{n:"id",k:"s",max:40},{n:"label",k:"s",max:40}]}}]}}],120,"gameSettings");o("gem.settingChange",[{n:"id",k:"s",max:40},{n:"value",k:"u",max:40,lo:-1e6,hi:1e6}],120,"gameSettings");o("gem.requestShare",[{n:"params",k:"a",max:16,it:{n:"",k:"o",fs:[{n:"key",k:"s",max:64},{n:"value",k:"s",max:512}]}}],6,"share");o("gem.requestAvatarPicker",[{n:"tab",k:"e",o:1,v:["2d","3d"]}],6,"avatarPicker");o("gem.vibrate",[{n:"pattern",k:"a",max:99,it:{n:"",k:"i",lo:0,hi:1e4}}],600,"vibration");o("gem.frameStats",[{n:"fps",k:"i",lo:0,hi:1e3},{n:"frameTimeP95Ms",k:"i",lo:0,hi:1e5},{n:"counts",k:"e",o:1,v:["pageFrames","gameDraws"]}],120,"frameStats");o("gem.portraitBorders",[{n:"name",k:"s",o:1,max:40}],60,"portraitBorders");o("gem.error",[{n:"code",k:"e",v:["version_mismatch","handshake_timeout","handshake_duplicate","invalid_message","rate_limited","token_unavailable","unsupported","unsupported_capability","internal"]},{n:"message",k:"s",o:1,max:256}],60);o("gem.requestPurchase",[m,{n:"purchaseKind",k:"e",v:["item","recipe"]},{n:"targetId",k:"s",max:64},{n:"currencySlug",k:"s",max:32},{n:"quantity",k:"i",o:1,lo:1,hi:10},{n:"catalogId",k:"s",o:1,max:64}],12,"purchases");o("gem.requestAvatar3dPurchase",[m,{n:"itemId",k:"s",max:64},{n:"currencySlug",k:"s",max:32}],12,"avatar3dPurchases");o("gem.purchaseResult",[m,{n:"outcome",k:"e",v:["ok","declined","unavailable"]},{n:"reason",k:"s",o:1,max:64,f:"code"},{n:"purchaseId",k:"s",o:1,max:64}],30,"purchases");o("gem.deviceSettings.put",[m,{n:"settings",k:"j"}],30,"deviceSettings");o("gem.deviceSettings.result",[m,{n:"outcome",k:"e",v:["stored","too_large","unavailable"]}],30,"deviceSettings");o("gem.requestAd",[m,{n:"placement",k:"s",max:32},{n:"format",k:"e",v:["interstitial","rewarded"]}],6,"ads");o("gem.adResult",[m,{n:"outcome",k:"e",v:["shown","no_ad","unavailable"]}],12,"ads");o("gem.signalMoment",[m,{n:"kind",k:"e",v:["level_end","run_end","match_end","menu_return","other_break"]},{n:"placement",k:"s",o:1,max:32}],6,"moments");o("gem.momentResult",[m,{n:"shown",k:"b"}],12,"moments");o("gem.requestSignIn",[m],6,"signIn");o("gem.signInResult",[m,{n:"outcome",k:"e",v:["signed_in","declined","unavailable"]}],12,"signIn");o("gem.requestFriendChallenge",[m,{n:"playerId",k:"s",max:64},{n:"template",k:"s",max:64},{n:"params",k:"j",o:1}],12,"friendChallenges");o("gem.friendChallengeResult",[m,{n:"outcome",k:"e",v:["accepted","cancelled","refused","unavailable","rate_limited","invalid"]},{n:"code",k:"s",o:1,max:64},{n:"param",k:"s",o:1,max:64},{n:"channel",k:"s",o:1,max:16},{n:"configVersion",k:"i",o:1,lo:0,hi:9007199254740991},{n:"retryAfterMs",k:"i",o:1,lo:0,hi:864e5},{n:"detail",k:"s",o:1,max:300}],30,"friendChallenges");var G=Object.freeze(V);b.__malformed=60;Object.freeze(b);Object.freeze(M);var ce=/^[a-z0-9][a-z0-9_-]{0,39}$/;function ue(t){return typeof t=="string"&&ce.test(t)}function z(t){if(t===null||ue(t))return t;let e=typeof t=="string"?JSON.stringify(t.length>48?`${t.slice(0,48)}\u2026`:t):`a value of type ${typeof t}`;console.warn(`[gem] showPortraitBorders: ${e} is not a border name, so nothing was sent. A name is 1 to 40 of a-z, 0-9, _ and -, starting with a letter or digit, exactly as your store page declares it under media.portrait_borders. Pass null for no art.`);}var _={now:()=>Date.now(),setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},x=class{constructor(e=_){this.clock=e;}clock;tokens=new Map;lastRefill=new Map;allow(e){let n=b[e];if(n===void 0)return false;let r=this.clock.now(),s=this.lastRefill.get(e)??r,i=this.tokens.get(e)??n,d=Math.max(0,r-s),a=Math.min(n,i+d*n/6e4);return a<1?(this.tokens.set(e,a),this.lastRefill.set(e,r),false):(this.tokens.set(e,a-1),this.lastRefill.set(e,r),true)}};function C(t,e){return t.toLowerCase()===e.toLowerCase()}function O(t){let e=t.toLowerCase();return e==="localhost"||e.endsWith(".localhost")||e==="[::1]"||e==="::1"?true:/^127(\.\d{1,3}){3}$/.test(e)}function Y(t,e){if(typeof e!="string"||e==="")return false;let n,r;try{n=new URL(t),r=new URL(e);}catch{return false}return n.protocol!=="http:"&&n.protocol!=="https:"||r.protocol!=="http:"&&r.protocol!=="https:"||n.username!==""||n.password!==""||n.pathname!=="/"||n.search!==""||n.hash!==""||n.port===""?false:O(n.hostname)&&O(r.hostname)}function K(t,e){if(t.min>t.max||e.min>e.max)return null;let n=Math.min(t.max,e.max),r=Math.max(t.min,e.min);return n>=r?n:null}var X="[gem: use gem.text.toPlain()]",J=new Set,Q;function ge(t){try{if(J.has(t))return;let e=globalThis.location;if(Q??=!!e?.port&&O(e.hostname??""),!Q)return;J.add(t),console.warn(`[gem] ${t} is PlayerText, turned into a string: players see ${X}. Render text.toPlain(value) (text is in @indiegems/gem-web-sdk/sdk).
2
- ${new Error().stack}`);}catch{}}var D=class{#e;#n;constructor(e,n="player text"){this.#e=e,this.#n=n,Object.freeze(this);}toString(){return ge(this.#n),X}toJSON(){return this.toString()}get[Symbol.toStringTag](){return "PlayerText"}static unwrap(e){return e.#e}};function j(t,e){return new D(t,e)}function Z(t){return Math.min(16384,Math.max(0,Math.round(Number.isFinite(t)?t:0)))}function pe(t,e){if(t!==true)return {visible:false};let n=[],r=false;for(let s of Array.isArray(e)?e:[])s==="score"?r=true:typeof s=="string"&&s.length>0&&s.length<=64&&!n.includes(s)&&n.push(s);return !r&&n.length===0?{visible:true}:{visible:true,currencies:n.slice(0,8),score:r}}function ye(t){let e=[];for(let n of Array.isArray(t)?t:[]){if(e.length===4)break;if(typeof n!="object"||n===null)continue;let{id:r,label:s}=n;typeof r!="string"||r.length===0||r.length>32||typeof s!="string"||s.trim().length===0||e.some(i=>i.id===r)||e.push({id:r,label:s.trim().slice(0,40)});}return e.length===0?{settings:false}:{settings:false,items:e}}function ee(t,e){return Math.min(e,Math.max(0,Math.round(Number.isFinite(t)?t:0)))}function fe(t){let e=t.untrusted,n=j(e.displayName,"gem.player.displayName"),r=e.displayTag||e.displayHandle,s=r?j(r,"gem.player.displayTag"):void 0,i=t.discriminator||t.displayTag,d=i&&/^[0-9]{1,8}$/.test(i)?i:void 0,a=t.avatarIconUrl||t.avatarUrl,c=/^[\da-f]{8}(-[\da-f]{4}){3}-[\da-f]{12}$/i,p=t.avatarIconId,y=t.avatar3dId,u={displayName:n,displayHandle:s??n,badges:(t.badges??[]).map(g=>({itemId:g.itemId,iconUrl:g.iconUrl}))};t.playerId&&(u.playerId=t.playerId),d&&(u.discriminator=d),s&&(u.displayTag=s),a&&(u.avatarIconUrl=u.avatarUrl=a),p&&c.test(p)&&(u.avatarIconId=p),y&&c.test(y)&&(u.avatar3dId=y),t.avatar3dModelUrl&&(u.avatar3dModelUrl=t.avatar3dModelUrl),t.avatar3dIconUrl&&(u.avatar3dIconUrl=t.avatar3dIconUrl),t.avatars3d&&(u.avatars3d=t.avatars3d.filter(g=>c.test(g.id)&&/^[a-z][a-z0-9_]*$/.test(g.family)).filter((g,T,E)=>E.findIndex(I=>I.family==g.family)==T).map(({family:g,id:T,modelUrl:E,iconUrl:I})=>({family:g,id:T,modelUrl:E,iconUrl:I})));let f=t.boost,h=(f?.multipliers??[]).map(g=>({currencyId:g.currencyId,currencySlug:g.currencySlug,multiplier:g.multiplierBp/1e4})),P=h.some(g=>g.multiplier>1);return u.boost=P&&f?.expiresInDays?{active:P,multipliers:h,expiresInDays:f.expiresInDays}:{active:P,multipliers:h},u}var he=1e4,ke=new WeakMap;var w=class{constructor(e){this.options=e;if(e.expectedSource===void 0||e.expectedSource===null)throw new Error("GemFrame: expectedSource is required and must not be null \u2014 pass window.parent. The handshake transfers the MessagePort, and origin alone does not say WHICH document on that origin sent it.");this.expectedSource=e.expectedSource,this.clock=e.clock??_,this.inbound=new x(this.clock),this.outbound=new x(this.clock);}options;state="waiting";port=null;version=null;peerCapabilities=[];unbidden=false;engagedSent=false;readyPending=false;readySent=false;settleWaiters=[];clock;inbound;outbound;expectedSource;get currentState(){return this.state}get parentCapabilities(){return this.peerCapabilities}parentSupports(e){return this.peerCapabilities.includes(e)}get protocolVersion(){return this.version}get unbiddenLaunch(){return this.unbidden}handleWindowMessage(e){if(e.source!==this.expectedSource)return this.refuse(e,"handshake did not come from the expected embedder window"),false;if(!(this.options.allowedEmbedders.some(a=>C(a,e.origin))||Y(e.origin,this.options.selfOrigin)||(ke.get(this)??[]).some(a=>C(a,e.origin))))return this.refuse(e,`embedder '${e.origin}' is not in allowedEmbedders`),this.state==="waiting"&&this.transition("refused"),false;if(this.state==="connected")return this.fail("handshake_duplicate","this document already has a port"),false;if(this.state!=="waiting")return false;let r=G["gem.handshake"]?.(e.data);if(r)return this.refuse(e,`malformed handshake: ${r}`),false;let s=e.data;if(!C(s.embedder,e.origin))return this.refuse(e,`handshake claims embedder '${s.embedder}' but arrived from '${e.origin}'`),false;let i=e.ports?.[0];if(!i)return this.refuse(e,"handshake transferred no MessagePort"),false;let d=K(v,s.versions);return d===null?(i.onmessage=null,i.postMessage({gem:l,type:"gem.error",code:"version_mismatch",message:`frame supports v${v.min}..v${v.max}`}),i.close(),this.transition("refused"),this.options.onError?.("version_mismatch"),false):(this.port=i,this.version=d,i.onmessage=a=>this.receive(a.data,a.ports??[]),i.start?.(),this.peerCapabilities=s.capabilities??[],this.unbidden=s.unbidden===true,i.postMessage({gem:l,type:"gem.handshake.accept",v:d,...this.options.capabilities===void 0?{}:{capabilities:[...this.options.capabilities]}}),this.transition("connected"),this.readyPending&&(this.readyPending=false,this.ready()),true)}ready(){if(this.state!=="connected"||!this.port){this.readyPending=true;return}if(this.readySent){this.options.onDropped?.("internal","gem.ready was already sent; duplicate suppressed");return}this.readySent=true,this.send({gem:l,type:"gem.ready"});}settled(e=he){return this.state!=="waiting"?Promise.resolve(this.state):new Promise(n=>{let r=i=>{this.clock.clearTimeout(s),n(i);},s=this.clock.setTimeout(()=>{let i=this.settleWaiters.indexOf(r);i>=0&&this.settleWaiters.splice(i,1),n(this.state);},e);this.settleWaiters.push(r);})}progress(e,n){this.send({gem:l,type:"gem.progress",loaded:e,total:n});}requestToken(e,n){this.send({gem:l,type:"gem.requestToken",requestId:e,reason:n});}requestLocalServer(e,n){return this.parentSupports("localHost")?(this.send({gem:l,type:"gem.requestLocalServer",requestId:e,gameRoomId:n}),true):false}exit(e){this.send(e===void 0?{gem:l,type:"gem.exit"}:{gem:l,type:"gem.exit",reason:e});}openExternal(e){this.send({gem:l,type:"gem.openExternal",url:e});}requestFullscreen(e){this.send({gem:l,type:"gem.requestFullscreen",enabled:e});}reportMuted(e){return this.gated("audioState")?(this.send({gem:l,type:"gem.audioState",muted:e}),true):false}reportEngaged(){return this.engagedSent||!this.gated("engagement")||!this.send({gem:l,type:"gem.engaged"})?false:(this.engagedSent=true,true)}cueReward(e){if(!this.gated("rewardCue"))return false;let n={gem:l,type:"gem.rewardCue",currencySlug:String(e.currencySlug).slice(0,32)};return e.expected!==void 0&&Number.isFinite(e.expected)&&e.expected>=1&&(n.expected=Math.min(1e9,Math.round(e.expected))),e.origin&&(n.origin={x:Z(e.origin.x),y:Z(e.origin.y)}),this.send(n),true}showPortraitBorders(e){let n=z(e);return n===void 0||!this.gated("portraitBorders")?false:this.send(n===null?{gem:l,type:"gem.portraitBorders"}:{gem:l,type:"gem.portraitBorders",name:n})}setWalletVisible(e,n){return this.gated("walletDisplay")?this.send({gem:l,type:"gem.walletDisplay",...pe(e,n?.only)}):false}setMenu(e){return this.gated("gameMenu")?this.send({gem:l,type:"gem.menu",...ye(e)}):false}declareSettings(e){return this.gated("gameSettings")?this.send({gem:l,type:"gem.settingsDeclare",settings:e}):false}setGemCorner(e){return this.gated("gemCorner")?this.send({gem:l,type:"gem.gemCorner",corner:e}):false}requestShare(e){return this.gated("share")?this.send({gem:l,type:"gem.requestShare",params:e.map(({key:n,value:r})=>({key:n,value:r}))}):false}requestAvatarPicker(e){return this.gated("avatarPicker")?this.send({gem:l,type:"gem.requestAvatarPicker",...e==="2d"||e==="3d"?{tab:e}:{}}):false}requestVibrate(e){return this.gated("vibration")?this.send({gem:l,type:"gem.vibrate",pattern:[...e]}):false}reportFrameStats(e){return this.gated("frameStats")?(this.send({gem:l,type:"gem.frameStats",fps:ee(e.fps,1e3),frameTimeP95Ms:ee(e.frameTimeP95Ms,1e5),counts:e.counts==="gameDraws"?"gameDraws":"pageFrames"}),true):false}sendGameContext(e){return this.state!=="connected"?false:(this.send({gem:l,type:"gem.gameContext",context:e}),true)}signal(e,n,r){this.send({gem:l,type:"gem.signal",signal:e,matchId:n,data:r});}dedicatedOffer(e,n,r){this.send({gem:l,type:"gem.dedicatedOffer",matchId:e,sdp:n,intent:r});}requestParty(e){return this.send({gem:l,type:"gem.partyRequest",requestId:e})}requestPurchase(e,n,r,s,i,d){return this.send({gem:l,type:"gem.requestPurchase",requestId:e,purchaseKind:n,targetId:r,currencySlug:s,...i===void 0?{}:{quantity:i},...d===void 0?{}:{catalogId:d}})}requestAvatar3dPurchase(e,n,r){return this.parentSupports("avatar3dPurchases")?this.send({gem:l,type:"gem.requestAvatar3dPurchase",requestId:e,itemId:n,currencySlug:r}):false}putDeviceSettings(e,n){return this.send({gem:l,type:"gem.deviceSettings.put",requestId:e,settings:n})}requestAd(e,n,r){return this.send({gem:l,type:"gem.requestAd",requestId:e,placement:n,format:r})}signalMoment(e,n,r){return this.send({gem:l,type:"gem.signalMoment",requestId:e,kind:n,...r===void 0?{}:{placement:r}})}readyCalled(){return this.readySent||this.readyPending}requestSignIn(e){return this.send({gem:l,type:"gem.requestSignIn",requestId:e})}requestFriendChallenge(e,n,r,s){return this.send({gem:l,type:"gem.requestFriendChallenge",requestId:e,playerId:n,template:r,...s===void 0?{}:{params:s}})}close(){this.port&&(this.port.onmessage=null,this.port.close(),this.port=null),this.state!=="refused"&&this.transition("closed");}transition(e){if(this.state!==e){this.state=e;for(let n of this.settleWaiters.splice(0))n(e);this.options.onStateChange?.(e);}}refuseMalformed(e,n){if(!this.inbound.allow(S)){this.options.onDropped?.(e,n);return}this.fail(e,n);}dropUnknownType(e){this.inbound.allow(S)&&this.options.onDropped?.("unsupported",`ignored unknown message type '${e}'`);}refuse(e,n){e.ports?.[0]?.close?.(),this.inbound.allow(S)&&this.options.onRefused?.(n);}fail(e,n){this.options.onError?.(e,n),this.state==="connected"&&this.port&&this.send({gem:l,type:"gem.error",code:e,...n===void 0?{}:{message:n}});}gated(e){return this.state==="connected"&&this.parentSupports(e)}send(e){if(this.state!=="connected"||!this.port)return this.options.onDropped?.("internal",`dropped ${String(e.type)} before connect`),false;let n=e.type;if(!this.outbound.allow(n))return this.options.onError?.("rate_limited",`frame exceeded its own limit for ${n}`),false;let r=G[n]?.(e);return r?(this.options.onError?.("internal",`refusing to send malformed ${n}: ${r}`),false):(this.port.postMessage(this.version===null?e:{...e,v:this.version}),true)}receive(e,n=[]){let r=false;try{r=this.dispatchInbound(e,n);}finally{r||ne(n);}}dispatchInbound(e,n){if(this.state!=="connected")return false;let r=typeof e=="object"&&e!==null?e.type:void 0;if(typeof r!="string")return this.refuseMalformed("invalid_message","message has no type"),false;let s=G[r];if(!s)return this.dropUnknownType(r),false;if(!this.inbound.allow(r))return this.fail("rate_limited",`parent exceeded the limit for ${r}`),false;let i=W(r);if(i!==void 0&&!this.options.capabilities?.includes(i))return this.fail("unsupported_capability",`${r} requires the '${i}' capability, which this frame did not advertise`),false;let d=s(e);if(d)return this.fail("invalid_message",`${r}: ${d}`),false;let a=e;if(a.v!==this.version)return this.fail("invalid_message",`${r}: expected v ${String(this.version)}`),false;switch(r){case "gem.token":this.options.onToken?.(a);break;case "gem.pause":this.options.onPause?.(a);break;case "gem.menuSelect":this.options.onMenuSelect?.(a);break;case "gem.settingChange":this.options.onSettingChange?.(a);break;case "gem.prefs":this.options.onPrefs?.(a);break;case "gem.cohorts":this.options.onCohorts?.(a);break;case "gem.earnAllowanceChanged":this.options.onEarnAllowanceChanged?.();break;case "gem.viewport":this.options.onViewport?.(a);break;case "gem.willTerminate":this.options.onWillTerminate?.(a);break;case "gem.devtools":this.options.onDevtools?.(a.action);break;case "gem.requestContext":this.options.onRequestContext?.();break;case "gem.screenshot":{let c=n[0];if(!c){this.options.onError?.("invalid_message","gem.screenshot transferred no MessagePort");break}let p={maxWidth:a.maxWidth,maxHeight:a.maxHeight};if(!this.options.onScreenshot){c.close(),this.screenshotDenied("not_wired",false);break}return ne(n.slice(1)),this.options.onScreenshot(p,c,(y,u)=>this.screenshotDenied(y,u)),true}case "gem.token.denied":this.options.onTokenDenied?.(a);break;case "gem.localServer":this.options.onLocalServer?.(a);break;case "gem.localServer.denied":this.options.onLocalServerDenied?.(a);break;case "gem.player":{this.options.onPlayer?.(fe(a));break}case "gem.roomEvent":this.options.onRoomEvent?.(a);break;case "gem.seatedEvent":this.options.onSeatedEvent?.(a);break;case "gem.autoStartFailedEvent":this.options.onAutoStartFailedEvent?.(a);break;case "gem.ticketEvent":this.options.onTicketEvent?.(a);break;case "gem.socketState":this.options.onSocketState?.(a);break;case "gem.signalEvent":this.options.onSignalEvent?.(a);break;case "gem.dedicatedEvent":this.options.onDedicatedEvent?.(a);break;case "gem.clusterTarget":this.options.onClusterTarget?.(a);break;case "gem.partyResult":this.options.onPartyResult?.(a);break;case "gem.purchaseResult":this.options.onPurchaseResult?.(a);break;case "gem.deviceSettings":this.options.onDeviceSettings?.(a);break;case "gem.deviceSettings.result":this.options.onDeviceSettingsResult?.(a);break;case "gem.adResult":this.options.onAdResult?.(a);break;case "gem.momentResult":this.options.onMomentResult?.(a);break;case "gem.signInResult":this.options.onSignInResult?.(a);break;case "gem.friendChallengeResult":this.options.onFriendChallengeResult?.(a);break;case "gem.error":this.options.onError?.(a.code,a.message);break;default:this.fail("unsupported",`no frame handler for '${r}'`);}return false}screenshotDenied(e,n){this.send({gem:l,type:"gem.screenshot.denied",reason:e,retryable:n});}};function ne(t){for(let e of t)try{e?.close?.();}catch{}}$();function ve(t){if((t.expectedSource??window.parent)===window)throw new Error("GemWebSdkBridge.connect: this document is not framed (window.parent === window), so there is no embedder to hand it a port. A game runs inside the Gem Arcade iframe; opening it directly will never complete a handshake.");let e=new w({...t,expectedSource:t.expectedSource??window.parent}),n=r=>{let s=e.handleWindowMessage({data:r.data,origin:r.origin,source:r.source,ports:r.ports});return s&&window.removeEventListener("message",n),s};return window.addEventListener("message",n),U(window,n),e}var te={connect:ve,GemFrame:w,PROTOCOL:l,SUPPORTED_VERSIONS:v};window.GemWebSdkBridge=te;var Kn=te;return Kn;})();
1
+ var GemWebSdkBridgeBundle=(function(){'use strict';var L="GemWebSdkHandshake";function oe(){return typeof document>"u"?void 0:document.readyState}var U=()=>Date.now();function H(n={}){let e=n.win??window,t=e,r=t[L];if(r!==void 0)return r;let s=n.readyState??oe,i=n.now??U,d=[],a=[],u=y=>{let c=y.data;!c||c.type!=="gem.handshake"||(d.length>=4&&(d.shift(),a.shift(),p.dropped+=1),d.push(y),a.push(i()));};e.addEventListener("message",u);let p={events:d,times:a,dropped:0,late:s()==="complete",uninstall(){e.removeEventListener("message",u);}};return t[L]=p,p}function B(n,e,t={}){let r=n[L];if(r===void 0)return null;let s=t.ttlMs??9500,i=t.now??U,d=r.events.splice(0),a=r.times?.splice(0),u=0,p=0,y=false,c=i()-s;for(let f=d.length-1;f>=0;f--){let b=a?.[f];if(b!==void 0&&b<c){p+=1;continue}if(u+=1,e(d[f])===true){y=true;break}}return r.uninstall(),{capture:r,delivered:u,stale:p,accepted:y}}var l="gem-web-bridge",R={min:1,max:1},ae=65536,N=8,G=5e3,W=1024;var w=Object.create(null),x="__malformed";var j=Object.create(null),se=Object.freeze([["gem.asyncOpponents.","asyncOpponents"],["gem.vibration.","vibration"],["gem.viewport.","reservedAreas"],["gem.moments.","moments"],["gem.prefs.","audioChannels"]]);function O(n){let e=j[n];if(e!==void 0)return e;for(let[t,r]of se)if(n.startsWith(t))return r}function ie(n){let e=/^([a-z][a-z0-9+.-]*):\/\/([a-z0-9.-]+|\[[0-9a-f:.]+\])(:([0-9]{1,5}))?$/i.exec(n);return e===null?false:e[4]===void 0||Number(e[4])<=65535}function le(n){let e;try{e=new URL(n);}catch{return false}return e.username!==""||e.password!==""?false:e.protocol==="https:"?true:e.protocol==="http:"&&(e.hostname==="localhost"||e.hostname==="127.0.0.1")}function de(n){return /^[a-z]{2,8}(-[a-z0-9]{1,8})*$/i.test(n)}function me(n){return /^[a-z_]+$/.test(n)}function ue(n){return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(n)||/^[a-z0-9][a-z0-9-]{1,38}[a-z0-9]$/.test(n)&&!n.includes("--")}function _(n,e,t){if(e>N)return `nesting deeper than ${N}`;if(++t.nodes>G)return `more than ${G} values`;if(t.bytes>t.cap)return `over the ${t.cap} byte limit`;if(n==null)return t.bytes+=4,null;let r=typeof n;if(r==="boolean")return t.bytes+=5,null;if(r==="number")return t.bytes+=8,null;if(r==="string")return t.bytes+=n.length*3+2,null;if(r!=="object")return `${r} is not plain data`;let s=n;if(t.seen.has(s))return "a repeated or cyclic object reference";if(t.seen.add(s),Array.isArray(n)){if(n.length>W)return `an array of ${n.length} entries, over the ${W} limit`;t.bytes+=2;for(let a of n){let u=_(a,e+1,t);if(u)return u}return null}let i=Object.getPrototypeOf(n);if(i!==Object.prototype&&i!==null)return "a value that is not a plain object";t.bytes+=2;let d=n;for(let a in d){if(!Object.prototype.hasOwnProperty.call(d,a))continue;if(++t.nodes>G)return `more than ${G} values`;if(t.bytes+=a.length*3+4,t.bytes>t.cap)return `over the ${t.cap} byte limit`;let u=_(d[a],e+1,t);if(u)return u}return null}function ce(n,e=ae){let t={nodes:0,bytes:0,seen:new Set,cap:e},r=_(n,0,t);return r?`message contains ${r}`:t.bytes>e?`message is over the ${e} byte limit`:null}var ge={origin:[ie,"not a well-formed origin"],url:[le,"not a safe absolute http(s) URL"],bcp47:[de,"not a well-formed BCP 47 tag"],code:[me,"not a code of lower-case letters and underscores"],gameRef:[ue,"not a game id or web address"]};function V(n,e,t){for(let r of e){let s=t===""?r[0]:`${t}.${r[0]}`,i=n[r[0]];if(i==null){if(r[1]<"a")continue;return `${s}: required`}let d=M(i,r,s);if(d)return d}return null}function M(n,e,t){let r=e[1].toLowerCase();switch(r){case "u":return typeof n=="boolean"?null:M(n,typeof n=="string"?[e[0],"s",e[2]]:[e[0],"n",e[3],e[4]],t);case "s":{if(typeof n!="string")return `${t}: expected string`;if(n.length>e[2])return `${t}: exceeds ${e[2]} characters`;if(e[3]){let[s,i]=ge[e[3]];if(!s(n))return `${t}: ${i}`}return null}case "n":case "i":return typeof n!="number"||!(r=="i"?Number.isInteger:Number.isFinite)(n)?`${t}: expected ${r=="i"?"integer":"number"}`:n<e[2]||n>e[3]?`${t}: out of range ${e[2]}..${e[3]}`:null;case "b":return typeof n=="boolean"?null:`${t}: expected boolean`;case "e":{let s=e[2];return s.includes(n)?null:`${t}: not one of ${s.join("|")}`}case "o":return typeof n!="object"||n===null||Array.isArray(n)?`${t}: expected object`:V(n,e[2],t);case "j":return typeof n!="object"||n===null||Array.isArray(n)?`${t}: expected a plain object`:null;case "a":{if(!Array.isArray(n))return `${t}: expected array`;if(n.length>e[2])return `${t}: exceeds ${e[2]} items`;let s=e[3],i=`${t}[]`;for(let d of n){if(d==null){if(s[1]<"a")continue;return `${i}: required`}let a=M(d,s,i);if(a)return a}return null}default:return `${t}: unknown kind ${String(r)}`}}var z=Object.create(null);function o(n,e,t,r,s){return w[n]=t,r&&(j[n]=r),z[n]=i=>{let d=ce(i,s);if(d)return d;if(typeof i!="object"||i===null||Array.isArray(i))return "message: expected object";let a=i;return a.gem!==l?"gem: wrong protocol marker":a.type!==n?`type: expected ${n}`:V(a,e,"")}}var m=["requestId","s",64],h=["outcome","e",["ok","declined","unavailable"]],v=["reason","S",64,"code"];o("gem.handshake",[["versions","o",[["min","i",1,1e3],["max","i",1,1e3]]],["capabilities","A",64,["","s",64]],["embedder","s",2048,"origin"],["unbidden","B"]],30);o("gem.handshake.accept",[["v","i",1,1e3],["capabilities","A",64,["","s",64]]],5);o("gem.token",[["token","s",4096],["requestId","S",64],["generation","i",0,2147483647],["apiBaseUrl","S",512,"url"],["playerId","s",64],["gameId","s",64],["channel","e",["dev","test","release"]],["gameVersion","S",64],["expiresAt","i",0,4102444800],["chainEndsAt","i",0,4102444800],["allowDevTools","B"]],30);o("gem.token.denied",[m,["retryable","b"],["retryAfterMs","I",0,36e5],["reason","e",["chain_exhausted","unavailable"]],["correlationId","s",64]],30);o("gem.player",[["untrusted","o",[["displayName","s",64],["displayTag","S",80],["displayHandle","s",80]]],["playerId","S",64],["discriminator","S",8],["avatarIconUrl","S",2048,"url"],["avatarIconId","S",64],["avatar3dId","S",64],["avatar3dModelUrl","S",2048,"url"],["avatar3dIconUrl","S",2048,"url"],["avatars3d","A",8,["","o",[["family","s",32],["id","s",64],["modelUrl","s",256,"url"],["iconUrl","s",256,"url"]]]],["badges","A",2,["","o",[["itemId","s",64],["iconUrl","s",2048,"url"]]]],["displayTag","s",8],["avatarUrl","S",2048,"url"],["boost","O",[["multipliers","a",8,["","o",[["currencyId","s",64],["currencySlug","s",32],["multiplierBp","i",1e4,1e6]]]],["expiresInDays","I",1,7]]]],12);o("gem.pause",[["paused","b"]],120);o("gem.prefs",[["reducedMotion","b"],["muted","b"],["showFrameStats","B"],["music","B"],["sounds","B"],["locale","s",35,"bcp47"],["recommended","O",[["volume","i",0,100],["batterySaver","b"],["keyboardLayout","e",["wasd","arrows"]],["gamepadConfirm","e",["south","east"]],["vibration","b"],["lookSensitivity","I",20,400],["gamepadLookSensitivity","I",20,400],["invertLookY","B"],["touchMovement","S",16,"code"],["graphicsQuality","S",16,"code"],["graphicsQualityAuto","B"],["colorHelp","B"]]]],60);o("gem.cohorts",[["cohorts","a",8,["","o",[["experimentId","s",36],["variantKey","s",32]]]]],12,"cohorts");o("gem.earnAllowanceChanged",[],30,"earnAllowance");o("gem.viewport",[["insets","o",[["top","i",0,4096],["right","i",0,4096],["bottom","i",0,4096],["left","i",0,4096]]],["reserved","A",4,["","o",[["x","i",0,16384],["y","i",0,16384],["width","i",0,16384],["height","i",0,16384],["control","O",[["x","i",0,16384],["y","i",0,16384],["width","i",0,16384],["height","i",0,16384]]]]]]],60,"viewport");o("gem.deviceSettings",[["settings","J"]],12,"deviceSettings");o("gem.willTerminate",[["reason","e",["grant_expiring","session_ended","navigating","kill_switch"]],["graceMs","i",0,6e4]],10);o("gem.roomEvent",[["event","e",["updated","match_started","match_ready","match_failed","version_stale"]],["roomId","s",64],["matchId","S",64],["version","I",0,2147483647],["reason","S",64],["platform","E",["universal","mobile"]]],120,"rooms");o("gem.socketState",[["connected","b"],["reason","E",["connecting","dropped","watchdog","terminal"]]],12,"socketState");o("gem.seatedEvent",[["roomId","s",64]],60,"partySeating");o("gem.autoStartFailedEvent",[["roomId","s",64],["code","s",64]],30,"autoStartFailure");o("gem.ticketEvent",[["event","e",["queued","matched","expired","cancelled","failed"]],["ticketId","s",64],["partySize","I",1,64],["queuedAt","I",0,4102444800],["expiresAt","I",0,4102444800],["reason","S",64],["roomId","S",64]],60,"ticketEvents");o("gem.signalEvent",[["event","e",["hello","offer","answer","ice","peerJoined","peerLeft","migration","matchEnded","error"]],["matchId","s",64],["data","j"]],1800,"p2p");o("gem.dedicatedEvent",[["event","e",["answer","error","matchEnded"]],["matchId","s",64],["sdp","S",10240],["sessionId","S",64],["code","S",64],["message","S",256],["reason","S",64]],120,"dedicated");o("gem.partyResult",[m,["partyId","S",64]],30,"parties");o("gem.clusterTarget",[["clusterTargetId","s",64],["clusterTargetIds","A",3,["","s",64]]],12,"clusterTarget");o("gem.devtools",[["action","e",["open","close","toggle"]]],30,"devtools");o("gem.screenshot",[["maxWidth","i",1,7680],["maxHeight","i",1,4320]],6,"screenshot");o("gem.screenshot.denied",[["reason","e",["not_wired","no_source","unsupported","unreadable","tainted","too_large","busy","declined","failed"]],["retryable","b"]],12,"screenshot");o("gem.requestContext",[],12,"feedbackContext");o("gem.gameContext",[["context","j"]],12,"feedbackContext");o("gem.signal",[["signal","e",["join","offer","answer","ice","migrationAck","hostUnreachable"]],["matchId","s",64],["data","j"]],1200,"p2p");o("gem.dedicatedOffer",[["matchId","s",64],["sdp","s",10240],["intent","e",["initial","ice_restart","full_reconnect"]]],60,"dedicated");o("gem.partyRequest",[m],12,"parties");o("gem.ready",[],5);o("gem.engaged",[],5,"engagement");o("gem.progress",[["loaded","i",0,1099511627776],["total","i",0,1099511627776]],600);o("gem.requestToken",[m,["reason","e",["initial","expiring","rejected"]]],12);o("gem.requestLocalServer",[m,["gameRoomId","s",64]],6,"localHost");o("gem.localServer",[m,["serverId","S",128]],30,"localHost");o("gem.localServer.denied",[m,["retryable","b"],["reason","e",["refused","unavailable"]]],30,"localHost");o("gem.exit",[["reason","S",64]],5);o("gem.openExternal",[["url","s",2048,"url"]],6);o("gem.requestFullscreen",[["enabled","b"]],30);o("gem.audioState",[["muted","b"]],120,"audioState");o("gem.rewardCue",[["currencySlug","s",32],["expected","I",1,1e9],["origin","O",[["x","i",0,16384],["y","i",0,16384]]]],60,"rewardCue");o("gem.walletDisplay",[["visible","b"],["currencies","A",8,["","s",64]],["score","B"]],60,"walletDisplay");o("gem.controlsDeclare",[["uses","o",[["lookSensitivity","S",16,"code"],["gamepadLookSensitivity","S",16,"code"],["invertLookY","S",16,"code"],["touchMovement","S",16,"code"]]]],60,"controls");o("gem.menu",[["settings","b"],["items","A",4,["","o",[["id","s",32],["label","s",40]]]]],60,"gameMenu");o("gem.menuSelect",[["entry","e",["settings","item"]],["id","S",32]],60,"gameMenu");o("gem.gemCorner",[["corner","e",["top-left","top-right","bottom-left","bottom-right"]]],12,"gemCorner");o("gem.settingsDeclare",[["settings","a",8,["","o",[["id","s",40],["label","s",40],["kind","e",["toggle","slider","choice"]],["value","u",40,-1e6,1e6],["quick","B"],["icon","S",16,"code"],["min","N",-1e6,1e6],["max","N",-1e6,1e6],["step","N",0,1e6],["options","A",4,["","o",[["id","s",40],["label","s",40]]]]]]]],120,"gameSettings");o("gem.settingChange",[["id","s",40],["value","u",40,-1e6,1e6]],120,"gameSettings");o("gem.requestShare",[["params","a",16,["","o",[["key","s",64],["value","s",512]]]]],6,"share");o("gem.requestAvatarPicker",[["tab","E",["2d","3d"]]],6,"avatarPicker");o("gem.vibrate",[["pattern","a",99,["","i",0,1e4]]],600,"vibration");o("gem.frameStats",[["fps","i",0,1e3],["frameTimeP95Ms","i",0,1e5],["counts","E",["pageFrames","gameDraws"]]],120,"frameStats");o("gem.portraitBorders",[["name","S",40]],60,"portraitBorders");o("gem.error",[["code","e",["version_mismatch","handshake_timeout","handshake_duplicate","invalid_message","rate_limited","token_unavailable","unsupported","unsupported_capability","internal"]],["message","S",256]],60);o("gem.requestPurchase",[m,["purchaseKind","e",["item","recipe"]],["targetId","s",64],["currencySlug","s",32],["quantity","I",1,10],["catalogId","S",64]],12,"purchases");o("gem.requestAvatar3dPurchase",[m,["itemId","s",64],["currencySlug","s",32]],12,"avatar3dPurchases");o("gem.purchaseResult",[m,h,v,["purchaseId","S",64]],30,"purchases");o("gem.deviceSettings.put",[m,["settings","j"]],30,"deviceSettings");o("gem.deviceSettings.result",[m,["outcome","e",["stored","too_large","unavailable"]]],30,"deviceSettings");o("gem.requestAd",[m,["placement","s",32],["format","e",["interstitial","rewarded"]]],6,"ads");o("gem.adResult",[m,["outcome","e",["shown","no_ad","unavailable"]]],12,"ads");o("gem.signalMoment",[m,["kind","e",["level_end","run_end","match_end","menu_return","other_break"]],["placement","S",32]],6,"moments");o("gem.momentResult",[m,["shown","b"]],12,"moments");o("gem.requestSignIn",[m],6,"signIn");o("gem.signInResult",[m,["outcome","e",["signed_in","declined","unavailable"]]],12,"signIn");o("gem.requestFriendChallenge",[m,["playerId","s",64],["template","s",64],["params","J"]],12,"friendChallenges");o("gem.friendChallengeResult",[m,["outcome","e",["accepted","cancelled","refused","unavailable","rate_limited","invalid"]],["code","S",64],["param","S",64],["channel","S",16],["configVersion","I",0,9007199254740991],["retryAfterMs","I",0,864e5],["detail","S",300]],30,"friendChallenges");o("gem.requestAppLinks",[m],12,"appLinks");o("gem.appLinksResult",[m,h,v,["arcade","O",[["store","e",["app_store","google_play"]]]],["game","O",[["store","e",["app_store","google_play"]]]]],30,"appLinks");o("gem.requestOpenApp",[m,["target","e",["arcade","game"]]],6,"appLinks");o("gem.openAppResult",[m,h,v],30,"appLinks");o("gem.requestOpenGame",[m,["ref","s",40,"gameRef"]],6,"openGame");o("gem.openGameResult",[m,h,v],30,"openGame");o("gem.requestSimilarGames",[m,["limit","I",1,24]],12,"openGame");o("gem.similarGamesResult",[m,h,v,["games","a",24,["","o",[["gameId","s",36,"gameRef"],["slug","S",40,"gameRef"],["iconUrl","s",1024,"url"],["capsuleLandscapeUrl","s",1024,"url"],["capsulePortraitUrl","s",1024,"url"],["previewVideoUrl","S",1024,"url"],["previewPosterUrl","S",1024,"url"],["untrusted","o",[["name","s",64],["tagline","s",64],["shortDescription","s",320],["tags","a",10,["","s",32]]]]]]]],30,"openGame",524288);o("gem.requestStoreOffers",[m],12,"store");o("gem.storeOffersResult",[m,h,v,["offers","a",32,["","o",[["skuId","s",64],["kind","e",["gem_pack","boost","pass","bundle"]],["name","s",80],["description","s",400],["imageUrl","S",1024,"url"],["priceDisplay","s",32],["grant","O",[["currency","s",32],["amount","i",1,1e9]]]]]]],30,"store",262144);o("gem.requestStorePurchase",[m,["skuId","s",64]],12,"store");o("gem.storePurchaseResult",[m,h,v],30,"store");o("gem.storePurchaseSettled",[["skuId","s",64]],30,"store");var P=Object.freeze(z);w.__malformed=60;Object.freeze(w);Object.freeze(j);var pe=/^[a-z0-9][a-z0-9_-]{0,39}$/;function ye(n){return typeof n=="string"&&pe.test(n)}function K(n){if(n===null||ye(n))return n;let e=typeof n=="string"?JSON.stringify(n.length>48?`${n.slice(0,48)}\u2026`:n):`a value of type ${typeof n}`;console.warn(`[gem] showPortraitBorders: ${e} is not a border name, so nothing was sent. A name is 1 to 40 of a-z, 0-9, _ and -, starting with a letter or digit, exactly as your store page declares it under media.portrait_borders. Pass null for no art.`);}var D={now:()=>Date.now(),setTimeout:(n,e)=>setTimeout(n,e),clearTimeout:n=>clearTimeout(n)},k=class{constructor(e=D){this.clock=e;}clock;tokens=new Map;lastRefill=new Map;allow(e){let t=w[e];if(t===void 0)return false;let r=this.clock.now(),s=this.lastRefill.get(e)??r,i=this.tokens.get(e)??t,d=Math.max(0,r-s),a=Math.min(t,i+d*t/6e4);return a<1?(this.tokens.set(e,a),this.lastRefill.set(e,r),false):(this.tokens.set(e,a-1),this.lastRefill.set(e,r),true)}};function T(n,e){return n.toLowerCase()===e.toLowerCase()}function C(n){let e=n.toLowerCase();return e==="localhost"||e.endsWith(".localhost")||e==="[::1]"||e==="::1"?true:/^127(\.\d{1,3}){3}$/.test(e)}function Y(n,e){if(typeof e!="string"||e==="")return false;let t,r;try{t=new URL(n),r=new URL(e);}catch{return false}return t.protocol!=="http:"&&t.protocol!=="https:"||r.protocol!=="http:"&&r.protocol!=="https:"||t.username!==""||t.password!==""||t.pathname!=="/"||t.search!==""||t.hash!==""||t.port===""?false:C(t.hostname)&&C(r.hostname)}function J(n,e){if(n.min>n.max||e.min>e.max)return null;let t=Math.min(n.max,e.max),r=Math.max(n.min,e.min);return t>=r?t:null}var Z="[gem: use gem.text.toPlain()]",Q=new Set,X;function fe(n){try{if(Q.has(n))return;let e=globalThis.location;if(X??=!!e?.port&&C(e.hostname??""),!X)return;Q.add(n),console.warn(`[gem] ${n} is PlayerText, turned into a string: players see ${Z}. Render text.toPlain(value) (text is in @indiegems/gem-web-sdk/sdk).
2
+ ${new Error().stack}`);}catch{}}var F=class{#e;#t;constructor(e,t="player text"){this.#e=e,this.#t=t,Object.freeze(this);}toString(){return fe(this.#t),Z}toJSON(){return this.toString()}get[Symbol.toStringTag](){return "PlayerText"}static unwrap(e){return e.#e}};function $(n,e){return new F(n,e)}function ee(n){return Math.min(16384,Math.max(0,Math.round(Number.isFinite(n)?n:0)))}function he(n,e){if(n!==true)return {visible:false};let t=[],r=false;for(let s of Array.isArray(e)?e:[])s==="score"?r=true:typeof s=="string"&&s.length>0&&s.length<=64&&!t.includes(s)&&t.push(s);return !r&&t.length===0?{visible:true}:{visible:true,currencies:t.slice(0,8),score:r}}function ve(n){let e=[];for(let t of Array.isArray(n)?n:[]){if(e.length===4)break;if(typeof t!="object"||t===null)continue;let{id:r,label:s}=t;typeof r!="string"||r.length===0||r.length>32||typeof s!="string"||s.trim().length===0||e.some(i=>i.id===r)||e.push({id:r,label:s.trim().slice(0,40)});}return e.length===0?{settings:false}:{settings:false,items:e}}function te(n,e){return Math.min(e,Math.max(0,Math.round(Number.isFinite(n)?n:0)))}function be(n){let e=n.untrusted,t=$(e.displayName,"gem.player.displayName"),r=e.displayTag||e.displayHandle,s=r?$(r,"gem.player.displayTag"):void 0,i=n.discriminator||n.displayTag,d=i&&/^[0-9]{1,8}$/.test(i)?i:void 0,a=n.avatarIconUrl||n.avatarUrl,u=/^[\da-f]{8}(-[\da-f]{4}){3}-[\da-f]{12}$/i,p=n.avatarIconId,y=n.avatar3dId,c={displayName:t,displayHandle:s??t,badges:(n.badges??[]).map(g=>({itemId:g.itemId,iconUrl:g.iconUrl}))};n.playerId&&(c.playerId=n.playerId),d&&(c.discriminator=d),s&&(c.displayTag=s),a&&(c.avatarIconUrl=c.avatarUrl=a),p&&u.test(p)&&(c.avatarIconId=p),y&&u.test(y)&&(c.avatar3dId=y),n.avatar3dModelUrl&&(c.avatar3dModelUrl=n.avatar3dModelUrl),n.avatar3dIconUrl&&(c.avatar3dIconUrl=n.avatar3dIconUrl),n.avatars3d&&(c.avatars3d=n.avatars3d.filter(g=>u.test(g.id)&&/^[a-z][a-z0-9_]*$/.test(g.family)).filter((g,A,I)=>I.findIndex(q=>q.family==g.family)==A).map(({family:g,id:A,modelUrl:I,iconUrl:q})=>({family:g,id:A,modelUrl:I,iconUrl:q})));let f=n.boost,b=(f?.multipliers??[]).map(g=>({currencyId:g.currencyId,currencySlug:g.currencySlug,multiplier:g.multiplierBp/1e4})),E=b.some(g=>g.multiplier>1);return c.boost=E&&f?.expiresInDays?{active:E,multipliers:b,expiresInDays:f.expiresInDays}:{active:E,multipliers:b},c}var Re=1e4,we=["appLinks","openGame","store"],ke=new WeakMap;var S=class{constructor(e){this.options=e;if(e.expectedSource===void 0||e.expectedSource===null)throw new Error("GemFrame: expectedSource is required and must not be null \u2014 pass window.parent. The handshake transfers the MessagePort, and origin alone does not say WHICH document on that origin sent it.");this.expectedSource=e.expectedSource,this.clock=e.clock??D,this.inbound=new k(this.clock),this.outbound=new k(this.clock);}options;state="waiting";port=null;version=null;peerCapabilities=[];unbidden=false;engagedSent=false;readyPending=false;readySent=false;settleWaiters=[];clock;inbound;outbound;expectedSource;get currentState(){return this.state}get parentCapabilities(){return this.peerCapabilities}parentSupports(e){return this.peerCapabilities.includes(e)}get protocolVersion(){return this.version}get unbiddenLaunch(){return this.unbidden}handleWindowMessage(e){if(e.source!==this.expectedSource)return this.refuse(e,"handshake did not come from the expected embedder window"),false;if(!(this.options.allowedEmbedders.some(a=>T(a,e.origin))||Y(e.origin,this.options.selfOrigin)||(ke.get(this)??[]).some(a=>T(a,e.origin))))return this.refuse(e,`embedder '${e.origin}' is not in allowedEmbedders`),this.state==="waiting"&&this.transition("refused"),false;if(this.state==="connected")return this.fail("handshake_duplicate","this document already has a port"),false;if(this.state!=="waiting")return false;let r=P["gem.handshake"]?.(e.data);if(r)return this.refuse(e,`malformed handshake: ${r}`),false;let s=e.data;if(!T(s.embedder,e.origin))return this.refuse(e,`handshake claims embedder '${s.embedder}' but arrived from '${e.origin}'`),false;let i=e.ports?.[0];if(!i)return this.refuse(e,"handshake transferred no MessagePort"),false;let d=J(R,s.versions);return d===null?(i.onmessage=null,i.postMessage({gem:l,type:"gem.error",code:"version_mismatch",message:`frame supports v${R.min}..v${R.max}`}),i.close(),this.transition("refused"),this.options.onError?.("version_mismatch"),false):(this.port=i,this.version=d,i.onmessage=a=>this.receive(a.data,a.ports??[]),i.start?.(),this.peerCapabilities=s.capabilities??[],this.unbidden=s.unbidden===true,i.postMessage({gem:l,type:"gem.handshake.accept",v:d,...this.options.capabilities===void 0?{}:{capabilities:[...this.options.capabilities]}}),this.transition("connected"),this.readyPending&&(this.readyPending=false,this.ready()),true)}ready(){if(this.state!=="connected"||!this.port){this.readyPending=true;return}if(this.readySent){this.options.onDropped?.("internal","gem.ready was already sent; duplicate suppressed");return}this.readySent=true,this.send({gem:l,type:"gem.ready"});}settled(e=Re){return this.state!=="waiting"?Promise.resolve(this.state):new Promise(t=>{let r=i=>{this.clock.clearTimeout(s),t(i);},s=this.clock.setTimeout(()=>{let i=this.settleWaiters.indexOf(r);i>=0&&this.settleWaiters.splice(i,1),t(this.state);},e);this.settleWaiters.push(r);})}progress(e,t){this.send({gem:l,type:"gem.progress",loaded:e,total:t});}requestToken(e,t){this.send({gem:l,type:"gem.requestToken",requestId:e,reason:t});}requestLocalServer(e,t){return this.parentSupports("localHost")?(this.send({gem:l,type:"gem.requestLocalServer",requestId:e,gameRoomId:t}),true):false}exit(e){this.send(e===void 0?{gem:l,type:"gem.exit"}:{gem:l,type:"gem.exit",reason:e});}openExternal(e){this.send({gem:l,type:"gem.openExternal",url:e});}requestFullscreen(e){this.send({gem:l,type:"gem.requestFullscreen",enabled:e});}reportMuted(e){return this.gated("audioState")?(this.send({gem:l,type:"gem.audioState",muted:e}),true):false}reportEngaged(){return this.engagedSent||!this.gated("engagement")||!this.send({gem:l,type:"gem.engaged"})?false:(this.engagedSent=true,true)}cueReward(e){if(!this.gated("rewardCue"))return false;let t={gem:l,type:"gem.rewardCue",currencySlug:String(e.currencySlug).slice(0,32)};return e.expected!==void 0&&Number.isFinite(e.expected)&&e.expected>=1&&(t.expected=Math.min(1e9,Math.round(e.expected))),e.origin&&(t.origin={x:ee(e.origin.x),y:ee(e.origin.y)}),this.send(t),true}showPortraitBorders(e){let t=K(e);return t===void 0||!this.gated("portraitBorders")?false:this.send(t===null?{gem:l,type:"gem.portraitBorders"}:{gem:l,type:"gem.portraitBorders",name:t})}setWalletVisible(e,t){return this.gated("walletDisplay")?this.send({gem:l,type:"gem.walletDisplay",...he(e,t?.only)}):false}setMenu(e){return this.gated("gameMenu")?this.send({gem:l,type:"gem.menu",...ve(e)}):false}declareSettings(e){return this.gated("gameSettings")?this.send({gem:l,type:"gem.settingsDeclare",settings:e}):false}setGemCorner(e){return this.gated("gemCorner")?this.send({gem:l,type:"gem.gemCorner",corner:e}):false}requestShare(e){return this.gated("share")?this.send({gem:l,type:"gem.requestShare",params:e.map(({key:t,value:r})=>({key:t,value:r}))}):false}requestAvatarPicker(e){return this.gated("avatarPicker")?this.send({gem:l,type:"gem.requestAvatarPicker",...e==="2d"||e==="3d"?{tab:e}:{}}):false}requestVibrate(e){return this.gated("vibration")?this.send({gem:l,type:"gem.vibrate",pattern:[...e]}):false}reportFrameStats(e){return this.gated("frameStats")?(this.send({gem:l,type:"gem.frameStats",fps:te(e.fps,1e3),frameTimeP95Ms:te(e.frameTimeP95Ms,1e5),counts:e.counts==="gameDraws"?"gameDraws":"pageFrames"}),true):false}sendGameContext(e){return this.state!=="connected"?false:(this.send({gem:l,type:"gem.gameContext",context:e}),true)}signal(e,t,r){this.send({gem:l,type:"gem.signal",signal:e,matchId:t,data:r});}dedicatedOffer(e,t,r){this.send({gem:l,type:"gem.dedicatedOffer",matchId:e,sdp:t,intent:r});}requestParty(e){return this.send({gem:l,type:"gem.partyRequest",requestId:e})}requestPurchase(e,t,r,s,i,d){return this.send({gem:l,type:"gem.requestPurchase",requestId:e,purchaseKind:t,targetId:r,currencySlug:s,...i===void 0?{}:{quantity:i},...d===void 0?{}:{catalogId:d}})}requestAvatar3dPurchase(e,t,r){return this.parentSupports("avatar3dPurchases")?this.send({gem:l,type:"gem.requestAvatar3dPurchase",requestId:e,itemId:t,currencySlug:r}):false}putDeviceSettings(e,t){return this.send({gem:l,type:"gem.deviceSettings.put",requestId:e,settings:t})}requestAd(e,t,r){return this.send({gem:l,type:"gem.requestAd",requestId:e,placement:t,format:r})}signalMoment(e,t,r){return this.send({gem:l,type:"gem.signalMoment",requestId:e,kind:t,...r===void 0?{}:{placement:r}})}readyCalled(){return this.readySent||this.readyPending}requestSignIn(e){return this.send({gem:l,type:"gem.requestSignIn",requestId:e})}requestFriendChallenge(e,t,r,s){return this.send({gem:l,type:"gem.requestFriendChallenge",requestId:e,playerId:t,template:r,...s===void 0?{}:{params:s}})}requestArcade(e){return this.gated(O(e.type))&&this.send({gem:l,...e})}close(){this.port&&(this.port.onmessage=null,this.port.close(),this.port=null),this.state!=="refused"&&this.transition("closed");}transition(e){if(this.state!==e){this.state=e;for(let t of this.settleWaiters.splice(0))t(e);this.options.onStateChange?.(e);}}refuseMalformed(e,t){if(!this.inbound.allow(x)){this.options.onDropped?.(e,t);return}this.fail(e,t);}dropUnknownType(e){this.inbound.allow(x)&&this.options.onDropped?.("unsupported",`ignored unknown message type '${e}'`);}refuse(e,t){e.ports?.[0]?.close?.(),this.inbound.allow(x)&&this.options.onRefused?.(t);}fail(e,t){this.options.onError?.(e,t),this.state==="connected"&&this.port&&this.send({gem:l,type:"gem.error",code:e,...t===void 0?{}:{message:t}});}gated(e){return this.state==="connected"&&this.parentSupports(e)}send(e){if(this.state!=="connected"||!this.port)return this.options.onDropped?.("internal",`dropped ${String(e.type)} before connect`),false;let t=e.type;if(!this.outbound.allow(t))return this.options.onError?.("rate_limited",`frame exceeded its own limit for ${t}`),false;let r=P[t]?.(e);return r?(this.options.onError?.("internal",`refusing to send malformed ${t}: ${r}`),false):(this.port.postMessage(this.version===null?e:{...e,v:this.version}),true)}receive(e,t=[]){let r=false;try{r=this.dispatchInbound(e,t);}finally{r||ne(t);}}dispatchInbound(e,t){if(this.state!=="connected")return false;let r=typeof e=="object"&&e!==null?e.type:void 0;if(typeof r!="string")return this.refuseMalformed("invalid_message","message has no type"),false;let s=P[r];if(!s)return this.dropUnknownType(r),false;if(!this.inbound.allow(r))return this.fail("rate_limited",`parent exceeded the limit for ${r}`),false;let i=O(r);if(i!==void 0&&!this.options.capabilities?.includes(i))return this.fail("unsupported_capability",`${r} requires the '${i}' capability, which this frame did not advertise`),false;let d=s(e);if(d)return this.fail("invalid_message",`${r}: ${d}`),false;let a=e;if(a.v!==this.version)return this.fail("invalid_message",`${r}: expected v ${String(this.version)}`),false;switch(r){case "gem.token":this.options.onToken?.(a);break;case "gem.pause":this.options.onPause?.(a);break;case "gem.menuSelect":this.options.onMenuSelect?.(a);break;case "gem.settingChange":this.options.onSettingChange?.(a);break;case "gem.prefs":this.options.onPrefs?.(a);break;case "gem.cohorts":this.options.onCohorts?.(a);break;case "gem.earnAllowanceChanged":this.options.onEarnAllowanceChanged?.();break;case "gem.viewport":this.options.onViewport?.(a);break;case "gem.willTerminate":this.options.onWillTerminate?.(a);break;case "gem.devtools":this.options.onDevtools?.(a.action);break;case "gem.requestContext":this.options.onRequestContext?.();break;case "gem.screenshot":{let u=t[0];if(!u){this.options.onError?.("invalid_message","gem.screenshot transferred no MessagePort");break}let p={maxWidth:a.maxWidth,maxHeight:a.maxHeight};if(!this.options.onScreenshot){u.close(),this.screenshotDenied("not_wired",false);break}return ne(t.slice(1)),this.options.onScreenshot(p,u,(y,c)=>this.screenshotDenied(y,c)),true}case "gem.token.denied":this.options.onTokenDenied?.(a);break;case "gem.localServer":this.options.onLocalServer?.(a);break;case "gem.localServer.denied":this.options.onLocalServerDenied?.(a);break;case "gem.player":{this.options.onPlayer?.(be(a));break}case "gem.roomEvent":this.options.onRoomEvent?.(a);break;case "gem.seatedEvent":this.options.onSeatedEvent?.(a);break;case "gem.autoStartFailedEvent":this.options.onAutoStartFailedEvent?.(a);break;case "gem.ticketEvent":this.options.onTicketEvent?.(a);break;case "gem.socketState":this.options.onSocketState?.(a);break;case "gem.signalEvent":this.options.onSignalEvent?.(a);break;case "gem.dedicatedEvent":this.options.onDedicatedEvent?.(a);break;case "gem.clusterTarget":this.options.onClusterTarget?.(a);break;case "gem.partyResult":this.options.onPartyResult?.(a);break;case "gem.purchaseResult":this.options.onPurchaseResult?.(a);break;case "gem.deviceSettings":this.options.onDeviceSettings?.(a);break;case "gem.deviceSettings.result":this.options.onDeviceSettingsResult?.(a);break;case "gem.adResult":this.options.onAdResult?.(a);break;case "gem.momentResult":this.options.onMomentResult?.(a);break;case "gem.signInResult":this.options.onSignInResult?.(a);break;case "gem.friendChallengeResult":this.options.onFriendChallengeResult?.(a);break;case "gem.error":this.options.onError?.(a.code,a.message);break;default:if(we.includes(O(r))){this.options.onArcadeAnswer?.(a);break}this.fail("unsupported",`no frame handler for '${r}'`);}return false}screenshotDenied(e,t){this.send({gem:l,type:"gem.screenshot.denied",reason:e,retryable:t});}};function ne(n){for(let e of n)try{e?.close?.();}catch{}}H();function Se(n){if((n.expectedSource??window.parent)===window)throw new Error("GemWebSdkBridge.connect: this document is not framed (window.parent === window), so there is no embedder to hand it a port. A game runs inside the Gem Arcade iframe; opening it directly will never complete a handshake.");let e=new S({...n,expectedSource:n.expectedSource??window.parent}),t=r=>{let s=e.handleWindowMessage({data:r.data,origin:r.origin,source:r.source,ports:r.ports});return s&&window.removeEventListener("message",t),s};return window.addEventListener("message",t),B(window,t),e}var re={connect:Se,GemFrame:S,PROTOCOL:l,SUPPORTED_VERSIONS:R};window.GemWebSdkBridge=re;var cn=re;return cn;})();