com.superfive.js 1.0.3 → 1.0.4

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/dist/main.js CHANGED
@@ -38,7 +38,8 @@ function sendPlatformMessage(type, payload) {
38
38
  if (!isInPlatformMode()) return;
39
39
  const message = {
40
40
  type,
41
- payload
41
+ payload,
42
+ eventKey: getPlatformParam("key") || void 0
42
43
  };
43
44
  window.parent.postMessage(message, "*");
44
45
  }
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","names":["message: PlatformMessage"],"sources":["../src/main.ts"],"sourcesContent":["import type { PlatformMessage } from './types.ts';\n\n/**\n * Get a parameter from the hash (!#p=1&difficulty=2&muted=1)\n *\n * @param key The key of the parameter\n * @returns The value of the parameter or null if the parameter is not found\n */\nfunction getHashParams(key: string): string | null {\n const hash = window.location.hash.replace(/^#!?/, '')\n return new URLSearchParams(hash).get(key);\n}\n\n/**\n * Get a parameter from the url (?p=1&difficulty=2&muted=1)\n *\n * @param key The key of the parameter\n * @returns The value of the parameter or null if the parameter is not found\n */\nfunction getUrlParam(name: string): string | null {\n return new URLSearchParams(window.location.search).get(name);\n}\n\n/**\n * Get a parameter from the platform\n *\n * @param key The key of the parameter\n * @returns The value of the parameter or null if the parameter is not found\n */\nexport function getPlatformParam(key: string): string | null {\n return getHashParams(key) || getUrlParam(key);\n}\n\n/**\n * Check if the game is running in the SuperFive platform\n *\n * @returns True if the game is in platform mode, false otherwise\n */\nexport function isInPlatformMode(): boolean {\n return getPlatformParam('p') === '1';\n}\n\n/**\n * Check if the game should start muted\n *\n * @returns True if the game should start muted, false otherwise\n */\nexport function startMuted(): boolean {\n return getPlatformParam('muted') === '1';\n}\n\n/**\n * Get the difficulty of the game\n *\n * The difficulty is a number between 0 and 2\n * - 0: Easy\n * - 1: Medium\n * - 2: Hard\n *\n * @returns The difficulty of the game as a number between 0 and 2\n */\nexport function getDifficulty(): number {\n return parseInt(getPlatformParam('difficulty') || '0', 10);\n}\n\n// ==============================================================\n// Message Handling\n// ==============================================================\n\n/**\n * Subscribe to the platform's messages to handle platform events\n *\n * @returns void\n */\nexport function subscribeToPlatformMessages(): void {\n if (!isInPlatformMode()) return;\n window.addEventListener('message', handlePlatformMessage);\n}\n\n/**\n * Unsubscribe from the platform's messages\n *\n * @returns void\n */\nexport function unsubscribeFromPlatformMessages(): void {\n window.removeEventListener('message', handlePlatformMessage);\n}\n\n/**\n * Handle the platform's messages\n *\n * @param event The message event\n * @returns void\n */\nfunction handlePlatformMessage(event: MessageEvent): void {\n const data = event.data;\n if (!data || !data.type) return;\n\n // Validate message shape\n if (typeof data.type !== 'string') return;\n\n // Emit custom event for game to handle\n const customEvent = new CustomEvent('platformMessage', { \n detail: { type: data.type, payload: data.payload } \n });\n window.dispatchEvent(customEvent);\n}\n\n// ==============================================================\n// Sending Messages Methods\n// ==============================================================\n\n/**\n * Send a message to the platform\n *\n * @param type The type of the message\n * @param payload The payload of the message\n * @returns void\n */\nexport function sendPlatformMessage(type: PlatformMessage['type'], payload?: any): void {\n if (!isInPlatformMode()) return;\n const message: PlatformMessage = { type, payload };\n window.parent.postMessage(message, '*');\n}\n\n/**\n * Send a message to the platform to indicate that the game is ready (loaded and ready to play)\n *\n * @returns void\n */\nexport function sendReady(): void {\n sendPlatformMessage('game_ready');\n}\n\n/**\n * Send a message to the platform to indicate that the game is won\n *\n * @returns void\n */\nexport function sendWin(): void {\n sendPlatformMessage('game_won');\n}\n\n/**\n * Send a message to the platform to indicate that the game is lost\n *\n * @returns void\n */\nexport function sendLose(): void {\n sendPlatformMessage('game_lost');\n}\n"],"mappings":"AAQA,SAAS,cAAc,KAA4B;CACjD,MAAM,OAAO,OAAO,SAAS,KAAK,QAAQ,QAAQ,GAAG;AACrD,QAAO,IAAI,gBAAgB,KAAK,CAAC,IAAI,IAAI;;AAS3C,SAAS,YAAY,MAA6B;AAChD,QAAO,IAAI,gBAAgB,OAAO,SAAS,OAAO,CAAC,IAAI,KAAK;;AAS9D,SAAgB,iBAAiB,KAA4B;AAC3D,QAAO,cAAc,IAAI,IAAI,YAAY,IAAI;;AAQ/C,SAAgB,mBAA4B;AAC1C,QAAO,iBAAiB,IAAI,KAAK;;AAQnC,SAAgB,aAAsB;AACpC,QAAO,iBAAiB,QAAQ,KAAK;;AAavC,SAAgB,gBAAwB;AACtC,QAAO,SAAS,iBAAiB,aAAa,IAAI,KAAK,GAAG;;AAY5D,SAAgB,8BAAoC;AAClD,KAAI,CAAC,kBAAkB,CAAE;AACzB,QAAO,iBAAiB,WAAW,sBAAsB;;AAQ3D,SAAgB,kCAAwC;AACtD,QAAO,oBAAoB,WAAW,sBAAsB;;AAS9D,SAAS,sBAAsB,OAA2B;CACxD,MAAM,OAAO,MAAM;AACnB,KAAI,CAAC,QAAQ,CAAC,KAAK,KAAM;AAGzB,KAAI,OAAO,KAAK,SAAS,SAAU;CAGnC,MAAM,cAAc,IAAI,YAAY,mBAAmB,EACrD,QAAQ;EAAE,MAAM,KAAK;EAAM,SAAS,KAAK;EAAS,EACnD,CAAC;AACF,QAAO,cAAc,YAAY;;AAcnC,SAAgB,oBAAoB,MAA+B,SAAqB;AACtF,KAAI,CAAC,kBAAkB,CAAE;CACzB,MAAMA,UAA2B;EAAE;EAAM;EAAS;AAClD,QAAO,OAAO,YAAY,SAAS,IAAI;;AAQzC,SAAgB,YAAkB;AAChC,qBAAoB,aAAa;;AAQnC,SAAgB,UAAgB;AAC9B,qBAAoB,WAAW;;AAQjC,SAAgB,WAAiB;AAC/B,qBAAoB,YAAY"}
1
+ {"version":3,"file":"main.js","names":["message: PlatformMessage"],"sources":["../src/main.ts"],"sourcesContent":["import type { PlatformMessage } from './types.ts';\n\n/**\n * Get a parameter from the hash (!#p=1&difficulty=2&muted=1)\n *\n * @param key The key of the parameter\n * @returns The value of the parameter or null if the parameter is not found\n */\nfunction getHashParams(key: string): string | null {\n const hash = window.location.hash.replace(/^#!?/, '')\n return new URLSearchParams(hash).get(key);\n}\n\n/**\n * Get a parameter from the url (?p=1&difficulty=2&muted=1)\n *\n * @param key The key of the parameter\n * @returns The value of the parameter or null if the parameter is not found\n */\nfunction getUrlParam(name: string): string | null {\n return new URLSearchParams(window.location.search).get(name);\n}\n\n/**\n * Get a parameter from the platform\n *\n * @param key The key of the parameter\n * @returns The value of the parameter or null if the parameter is not found\n */\nexport function getPlatformParam(key: string): string | null {\n return getHashParams(key) || getUrlParam(key);\n}\n\n/**\n * Check if the game is running in the SuperFive platform\n *\n * @returns True if the game is in platform mode, false otherwise\n */\nexport function isInPlatformMode(): boolean {\n return getPlatformParam('p') === '1';\n}\n\n/**\n * Check if the game should start muted\n *\n * @returns True if the game should start muted, false otherwise\n */\nexport function startMuted(): boolean {\n return getPlatformParam('muted') === '1';\n}\n\n/**\n * Get the difficulty of the game\n *\n * The difficulty is a number between 0 and 2\n * - 0: Easy\n * - 1: Medium\n * - 2: Hard\n *\n * @returns The difficulty of the game as a number between 0 and 2\n */\nexport function getDifficulty(): number {\n return parseInt(getPlatformParam('difficulty') || '0', 10);\n}\n\n// ==============================================================\n// Message Handling\n// ==============================================================\n\n/**\n * Subscribe to the platform's messages to handle platform events\n *\n * @returns void\n */\nexport function subscribeToPlatformMessages(): void {\n if (!isInPlatformMode()) return;\n window.addEventListener('message', handlePlatformMessage);\n}\n\n/**\n * Unsubscribe from the platform's messages\n *\n * @returns void\n */\nexport function unsubscribeFromPlatformMessages(): void {\n window.removeEventListener('message', handlePlatformMessage);\n}\n\n/**\n * Handle the platform's messages\n *\n * @param event The message event\n * @returns void\n */\nfunction handlePlatformMessage(event: MessageEvent): void {\n const data = event.data;\n if (!data || !data.type) return;\n\n // Validate message shape\n if (typeof data.type !== 'string') return;\n\n // Emit custom event for game to handle\n const customEvent = new CustomEvent('platformMessage', { \n detail: { type: data.type, payload: data.payload } \n });\n window.dispatchEvent(customEvent);\n}\n\n// ==============================================================\n// Sending Messages Methods\n// ==============================================================\n\n/**\n * Send a message to the platform\n *\n * @param type The type of the message\n * @param payload The payload of the message\n * @returns void\n */\nexport function sendPlatformMessage(type: PlatformMessage['type'], payload?: any): void {\n if (!isInPlatformMode()) return;\n const message: PlatformMessage = { type, payload, eventKey: getPlatformParam('key') || undefined };\n window.parent.postMessage(message, '*');\n}\n\n/**\n * Send a message to the platform to indicate that the game is ready (loaded and ready to play)\n *\n * @returns void\n */\nexport function sendReady(): void {\n sendPlatformMessage('game_ready');\n}\n\n/**\n * Send a message to the platform to indicate that the game is won\n *\n * @returns void\n */\nexport function sendWin(): void {\n sendPlatformMessage('game_won');\n}\n\n/**\n * Send a message to the platform to indicate that the game is lost\n *\n * @returns void\n */\nexport function sendLose(): void {\n sendPlatformMessage('game_lost');\n}\n"],"mappings":"AAQA,SAAS,cAAc,KAA4B;CACjD,MAAM,OAAO,OAAO,SAAS,KAAK,QAAQ,QAAQ,GAAG;AACrD,QAAO,IAAI,gBAAgB,KAAK,CAAC,IAAI,IAAI;;AAS3C,SAAS,YAAY,MAA6B;AAChD,QAAO,IAAI,gBAAgB,OAAO,SAAS,OAAO,CAAC,IAAI,KAAK;;AAS9D,SAAgB,iBAAiB,KAA4B;AAC3D,QAAO,cAAc,IAAI,IAAI,YAAY,IAAI;;AAQ/C,SAAgB,mBAA4B;AAC1C,QAAO,iBAAiB,IAAI,KAAK;;AAQnC,SAAgB,aAAsB;AACpC,QAAO,iBAAiB,QAAQ,KAAK;;AAavC,SAAgB,gBAAwB;AACtC,QAAO,SAAS,iBAAiB,aAAa,IAAI,KAAK,GAAG;;AAY5D,SAAgB,8BAAoC;AAClD,KAAI,CAAC,kBAAkB,CAAE;AACzB,QAAO,iBAAiB,WAAW,sBAAsB;;AAQ3D,SAAgB,kCAAwC;AACtD,QAAO,oBAAoB,WAAW,sBAAsB;;AAS9D,SAAS,sBAAsB,OAA2B;CACxD,MAAM,OAAO,MAAM;AACnB,KAAI,CAAC,QAAQ,CAAC,KAAK,KAAM;AAGzB,KAAI,OAAO,KAAK,SAAS,SAAU;CAGnC,MAAM,cAAc,IAAI,YAAY,mBAAmB,EACrD,QAAQ;EAAE,MAAM,KAAK;EAAM,SAAS,KAAK;EAAS,EACnD,CAAC;AACF,QAAO,cAAc,YAAY;;AAcnC,SAAgB,oBAAoB,MAA+B,SAAqB;AACtF,KAAI,CAAC,kBAAkB,CAAE;CACzB,MAAMA,UAA2B;EAAE;EAAM;EAAS,UAAU,iBAAiB,MAAM,IAAI,KAAA;EAAW;AAClG,QAAO,OAAO,YAAY,SAAS,IAAI;;AAQzC,SAAgB,YAAkB;AAChC,qBAAoB,aAAa;;AAQnC,SAAgB,UAAgB;AAC9B,qBAAoB,WAAW;;AAQjC,SAAgB,WAAiB;AAC/B,qBAAoB,YAAY"}
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export interface PlatformMessage {
2
2
  type: 'game_ready' | 'game_won' | 'game_lost' | 'game_restart' | 'game_mute';
3
3
  payload?: any;
4
+ eventKey?: string;
4
5
  }
5
6
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,WAAW,GAAG,cAAc,GAAG,WAAW,CAAC;IAC7E,OAAO,CAAC,EAAE,GAAG,CAAC;CACf"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,WAAW,GAAG,cAAc,GAAG,WAAW,CAAC;IAC7E,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.superfive.js",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "main": "./dist/main.js",
6
6
  "module": "./dist/main.js",