@gd-kirie/ipc 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # @gd-kirie/ipc
2
+
3
+ Thin browser-side IPC transport for Kirie WebView pages.
4
+
5
+ The package is imported by web content running inside a Kirie WebView. Native platforms continue to provide the low
6
+ level bridge on `globalThis`, and this package only wraps that bridge with a small typed module API.
7
+
8
+ ## API
9
+
10
+ ```ts
11
+ import { onIpcMessageReceived, sendIpcMessage } from "@gd-kirie/ipc";
12
+
13
+ sendIpcMessage({
14
+ type: "web_ready",
15
+ });
16
+
17
+ const unsubscribe = onIpcMessageReceived((message) => {
18
+ console.log(message);
19
+ });
20
+
21
+ unsubscribe();
22
+ ```
23
+
24
+ `sendIpcMessage()` serializes the message with `JSON.stringify()` and forwards the
25
+ result to the current native bridge:
26
+
27
+ - Android: `globalThis.KirieAndroidBridge.postMessage(...)`
28
+ - iOS: `globalThis.webkit.messageHandlers.kirie.postMessage(...)`
29
+
30
+ `onIpcMessageReceived()` listens for `kirie:ipc-message` events dispatched by the
31
+ native bridge.
@@ -0,0 +1,21 @@
1
+ //#region src/index.d.ts
2
+ type AndroidBridge = {
3
+ postMessage(messageJson: string): void;
4
+ };
5
+ type IosBridge = {
6
+ postMessage(messageJson: string): void;
7
+ };
8
+ declare global {
9
+ var KirieAndroidBridge: AndroidBridge | undefined;
10
+ var webkit: {
11
+ messageHandlers?: {
12
+ kirie?: IosBridge;
13
+ };
14
+ } | undefined;
15
+ }
16
+ type KirieIpcMessageHandler<TMessage = unknown> = (message: TMessage) => void;
17
+ declare function sendIpcMessage(message: unknown): void;
18
+ declare function onIpcMessageReceived<TMessage = unknown>(handler: KirieIpcMessageHandler<TMessage>): () => void;
19
+ //#endregion
20
+ export { KirieIpcMessageHandler, onIpcMessageReceived, sendIpcMessage };
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";KAEK,aAAA;EACH,WAAA,CAAY,WAAA;AAAA;AAAA,KAGT,SAAA;EACH,WAAA,CAAY,WAAA;AAAA;AAAA;MAIR,kBAAA,EAAoB,aAAA;EAAA,IAEpB,MAAA;IAEE,eAAA;MACE,KAAA,GAAQ,SAAA;IAAA;EAAA;AAAA;AAAA,KAMN,sBAAA,wBAA8C,OAAA,EAAS,QAAA;AAAA,iBAEnD,cAAA,CAAe,OAAA;AAAA,iBAuBf,oBAAA,oBAAA,CACd,OAAA,EAAS,sBAAA,CAAuB,QAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ //#region src/index.ts
2
+ const IPC_MESSAGE_EVENT = "kirie:ipc-message";
3
+ function sendIpcMessage(message) {
4
+ const messageJson = JSON.stringify(message);
5
+ if (messageJson === void 0) throw new TypeError("Kirie IPC message root must serialize to a JSON string. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description for details.");
6
+ const androidBridge = globalThis.KirieAndroidBridge;
7
+ if (androidBridge) {
8
+ androidBridge.postMessage(messageJson);
9
+ return;
10
+ }
11
+ const iosBridge = globalThis.webkit?.messageHandlers?.kirie;
12
+ if (iosBridge) {
13
+ iosBridge.postMessage(messageJson);
14
+ return;
15
+ }
16
+ throw new Error("Kirie native IPC bridge is not available.");
17
+ }
18
+ function onIpcMessageReceived(handler) {
19
+ const listener = (event) => {
20
+ handler(event.detail);
21
+ };
22
+ globalThis.addEventListener(IPC_MESSAGE_EVENT, listener);
23
+ return () => {
24
+ globalThis.removeEventListener(IPC_MESSAGE_EVENT, listener);
25
+ };
26
+ }
27
+ //#endregion
28
+ export { onIpcMessageReceived, sendIpcMessage };
29
+
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["const IPC_MESSAGE_EVENT = \"kirie:ipc-message\";\n\ntype AndroidBridge = {\n postMessage(messageJson: string): void;\n};\n\ntype IosBridge = {\n postMessage(messageJson: string): void;\n};\n\ndeclare global {\n var KirieAndroidBridge: AndroidBridge | undefined;\n\n var webkit:\n | {\n messageHandlers?: {\n kirie?: IosBridge;\n };\n }\n | undefined;\n}\n\nexport type KirieIpcMessageHandler<TMessage = unknown> = (message: TMessage) => void;\n\nexport function sendIpcMessage(message: unknown): void {\n const messageJson = JSON.stringify(message);\n if (messageJson === undefined) {\n throw new TypeError(\n \"Kirie IPC message root must serialize to a JSON string. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description for details.\",\n );\n }\n\n const androidBridge = globalThis.KirieAndroidBridge;\n if (androidBridge) {\n androidBridge.postMessage(messageJson);\n return;\n }\n\n const iosBridge = globalThis.webkit?.messageHandlers?.kirie;\n if (iosBridge) {\n iosBridge.postMessage(messageJson);\n return;\n }\n\n throw new Error(\"Kirie native IPC bridge is not available.\");\n}\n\nexport function onIpcMessageReceived<TMessage = unknown>(\n handler: KirieIpcMessageHandler<TMessage>,\n): () => void {\n const listener = (event: Event) => {\n handler((event as CustomEvent<TMessage>).detail);\n };\n\n globalThis.addEventListener(IPC_MESSAGE_EVENT, listener);\n\n return () => {\n globalThis.removeEventListener(IPC_MESSAGE_EVENT, listener);\n };\n}\n"],"mappings":";AAAA,MAAM,oBAAoB;AAwB1B,SAAgB,eAAe,SAAwB;CACrD,MAAM,cAAc,KAAK,UAAU,QAAQ;AAC3C,KAAI,gBAAgB,KAAA,EAClB,OAAM,IAAI,UACR,uLACD;CAGH,MAAM,gBAAgB,WAAW;AACjC,KAAI,eAAe;AACjB,gBAAc,YAAY,YAAY;AACtC;;CAGF,MAAM,YAAY,WAAW,QAAQ,iBAAiB;AACtD,KAAI,WAAW;AACb,YAAU,YAAY,YAAY;AAClC;;AAGF,OAAM,IAAI,MAAM,4CAA4C;;AAG9D,SAAgB,qBACd,SACY;CACZ,MAAM,YAAY,UAAiB;AACjC,UAAS,MAAgC,OAAO;;AAGlD,YAAW,iBAAiB,mBAAmB,SAAS;AAExD,cAAa;AACX,aAAW,oBAAoB,mBAAmB,SAAS"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@gd-kirie/ipc",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/moeru-ai/godot-kirie.git",
8
+ "directory": "packages/ipc"
9
+ },
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "devDependencies": {
22
+ "tsdown": "^0.21.10",
23
+ "typescript": "^5.9.3"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "registry": "https://registry.npmjs.org"
28
+ },
29
+ "scripts": {
30
+ "build": "tsdown",
31
+ "typecheck": "tsc -p tsconfig.json --noEmit"
32
+ }
33
+ }