@weiwangfds/wasm-ripple 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,324 @@
1
+ # Wasm-Ripple
2
+
3
+
4
+ [![Rust](https://img.shields.io/badge/Rust-000000?style=for-the-badge&logo=rust)](https://www.rust-lang.org/)
5
+ [![WebAssembly](https://img.shields.io/badge/WebAssembly-2024%20Stable-blue?style=for-the-badge&logo=webassembly)](https://webassembly.org/)
6
+
7
+ A high-performance, memory-safe message queue library compiled to WebAssembly, designed for modern web applications.
8
+
9
+ ## โœจ Features
10
+
11
+ - **๐Ÿš€ High Performance** - Built with Rust and compiled to WebAssembly for near-native speed
12
+ - **๐Ÿงต Memory Safe** - Rust's ownership model ensures memory safety without garbage collection pauses
13
+ - **๐Ÿ“ก Topic-based Pub/Sub** - Flexible publish/subscribe pattern with topic-based messaging
14
+ - **๐Ÿ”„ Cross-tab Communication** - Seamless message passing between browser tabs via BroadcastChannel API
15
+ - **โšก Synchronous & Async** - Choose between immediate delivery or microtask-based async publishing
16
+ - **๐Ÿ’พ Ring Buffer Support** - Optional message buffering with O(1) operations and overflow handling
17
+ - **๐Ÿ“ฆ Zero-copy Messaging** - Direct JavaScript value passing without serialization overhead
18
+ - **๐ŸŽฏ Lightweight** - ~40KB gzipped WebAssembly module
19
+
20
+ ## ๐Ÿ“ฆ Installation
21
+
22
+ ```bash
23
+ npm install wasm-ripple
24
+ ```
25
+
26
+ Or use directly from the `pkg` directory:
27
+
28
+ ```html
29
+ <script type="module">
30
+ import init, { MessageQueue } from './pkg/wasm_ripple.js';
31
+
32
+ await init();
33
+ const mq = new MessageQueue('my-channel');
34
+ </script>
35
+ ```
36
+
37
+ ## ๐Ÿš€ Quick Start
38
+
39
+ ```javascript
40
+ import init, { MessageQueue } from 'wasm-ripple';
41
+
42
+ // Initialize the WASM module
43
+ await init();
44
+
45
+ // Create a message queue with optional channel name for cross-tab communication
46
+ const mq = new MessageQueue('my-app');
47
+
48
+ // Register a topic and get its ID (REQUIRED for all operations)
49
+ const topicId = mq.register_topic('events');
50
+
51
+ // Subscribe to a topic using ID
52
+ // Callback receives: payload, topic_id, timestamp, message_id
53
+ const subId = mq.subscribe(topicId, (payload, tid, ts, msgId) => {
54
+ console.log('Received:', payload);
55
+ });
56
+
57
+ // Publish a message synchronously using topic ID
58
+ mq.publish(topicId, { text: 'Hello, World!', count: 42 });
59
+
60
+ // Or publish asynchronously (non-blocking)
61
+ await mq.publish_async(topicId, { text: 'Async message', data: [1, 2, 3] });
62
+
63
+ // Batch publish for high throughput
64
+ const messages = new Array(100).fill({ data: 'batch' });
65
+ mq.publish_batch_by_id(topicId, messages);
66
+
67
+ // Unsubscribe when done
68
+ mq.unsubscribe(topicId, subId);
69
+
70
+ // Clean up resources
71
+ mq.close();
72
+ ```
73
+
74
+ ## ๐Ÿ“Š Performance
75
+
76
+ Benchmark results on Chrome (Apple M3 Pro):
77
+
78
+ | Metric | Result | Notes |
79
+ | :--- | :--- | :--- |
80
+ | **Sync Throughput** | **~5.3M ops/sec** | Zero-allocation hot path |
81
+ | **Batch Throughput** | **~7.9M ops/sec** | Optimized batch processing |
82
+ | **Latency** | **~0.3 ยตs** | Ultra-low overhead dispatch |
83
+ | **100k Messages** | **~20 ms** | Full processing time |
84
+
85
+ > **Note**: These results are achieved using the optimized ID-based API and zero-allocation dispatch mechanism.
86
+
87
+ ## ๐Ÿ“š API Reference
88
+
89
+ ### Constructor
90
+
91
+ ```javascript
92
+ const mq = new MessageQueue(channelName?: string)
93
+ ```
94
+
95
+ - `channelName` (optional): Channel name for cross-tab communication via BroadcastChannel
96
+
97
+ ### Topic Management
98
+
99
+ ```javascript
100
+ // Register a topic and get its ID (O(1) lookups)
101
+ const topicId = mq.register_topic('my-topic'); // returns number (u32)
102
+
103
+ // Check if topic exists by ID
104
+ const exists = mq.has_topic(topicId); // returns boolean
105
+
106
+ // Destroy a topic by ID
107
+ const destroyed = mq.destroy_topic(topicId); // returns boolean
108
+
109
+ // Get topic count
110
+ const count = mq.topic_count(); // returns number
111
+ ```
112
+
113
+ ### Subscription
114
+
115
+ ```javascript
116
+ // Subscribe to a topic by ID
117
+ // Callback signature: (payload, topic_id, timestamp, message_id)
118
+ const subId = mq.subscribe(topicId, callback); // returns subscriber ID
119
+
120
+ // Unsubscribe
121
+ const success = mq.unsubscribe(topicId, subId); // returns boolean
122
+
123
+ // Unsubscribe all
124
+ const count = mq.unsubscribe_all(topicId); // returns number of unsubscribed
125
+
126
+ // Get subscriber count
127
+ const count = mq.subscriber_count(topicId); // returns number
128
+ ```
129
+
130
+ ### Publishing
131
+
132
+ ```javascript
133
+ // Synchronous publish (immediate delivery)
134
+ mq.publish(topicId, payload);
135
+
136
+ // Asynchronous publish (delivered in microtask)
137
+ await mq.publish_async(topicId, payload);
138
+
139
+ // Batch publish (highest throughput)
140
+ mq.publish_batch_by_id(topicId, [payload1, payload2, ...]);
141
+ ```
142
+
143
+ ### Ring Buffer Management
144
+
145
+ ```javascript
146
+ // Enable message buffering for a topic
147
+ mq.enable_topic_buffer(topicId, 100); // capacity (default: 100)
148
+
149
+ // Check if buffering is enabled
150
+ const hasBuffer = mq.has_buffer(topicId); // boolean
151
+
152
+ // Get buffer size
153
+ const size = mq.get_buffer_size(topicId); // current message count
154
+
155
+ // Get buffer capacity
156
+ const capacity = mq.get_buffer_capacity(topicId); // maximum capacity
157
+
158
+ // Get buffered messages
159
+ const messages = mq.get_buffered_messages(topicId); // Array of messages
160
+
161
+ // Clear buffer
162
+ const cleared = mq.clear_buffer(topicId); // number of cleared messages
163
+
164
+ // Disable buffering
165
+ mq.disable_topic_buffer(topicId);
166
+ ```
167
+
168
+ ### Utilities
169
+
170
+ ```javascript
171
+ // Get unique client ID
172
+ const clientId = mq.get_client_id(); // string
173
+
174
+ // Close the queue and release resources
175
+ mq.close();
176
+ ```
177
+
178
+ ## ๐Ÿ”„ Ring Buffer
179
+
180
+ The ring buffer provides efficient message caching with O(1) operations:
181
+
182
+ ```javascript
183
+ const logTopic = mq.register_topic('logs');
184
+
185
+ // Enable buffer with capacity of 5 messages
186
+ mq.enable_topic_buffer(logTopic, 5);
187
+
188
+ // Publish 10 messages
189
+ for (let i = 0; i < 10; i++) {
190
+ mq.publish(logTopic, { id: i, message: `Log ${i}` });
191
+ }
192
+
193
+ // Buffer only keeps the last 5 messages (IDs 5-9)
194
+ console.log(mq.get_buffer_size(logTopic)); // 5
195
+ console.log(mq.get_buffer_capacity(logTopic)); // 5
196
+
197
+ // Retrieve buffered messages
198
+ const messages = mq.get_buffered_messages(logTopic);
199
+ console.log(messages[0].payload.id); // 5 (oldest)
200
+ console.log(messages[4].payload.id); // 9 (newest)
201
+ ```
202
+
203
+ **Key Features:**
204
+ - **Fixed size**: Prevents unbounded memory growth
205
+ - **Automatic overflow**: Oldest messages are automatically displaced when full
206
+ - **O(1) operations**: Constant time push and retrieval
207
+ - **Per-topic**: Each topic can have different buffer settings
208
+
209
+ ## ๐ŸŒ Cross-tab Communication
210
+
211
+ Open the same page in multiple tabs to test cross-tab messaging:
212
+
213
+ ```javascript
214
+ // In tab 1
215
+ const mq = new MessageQueue('cross-tab-channel');
216
+ const topicId = mq.register_topic('updates');
217
+ mq.subscribe(topicId, (msg) => console.log('Tab 1 received:', msg));
218
+
219
+ // In tab 2
220
+ const mq = new MessageQueue('cross-tab-channel');
221
+ const topicId = mq.register_topic('updates');
222
+ mq.publish(topicId, { text: 'Hello from tab 2!' });
223
+ // Tab 1 will receive the message!
224
+ ```
225
+
226
+ ## ๐Ÿ†š Comparison
227
+
228
+ | Feature | **wasm-mq** | **Mitt / Tiny-emitter** | **PubSubJS** | **RxJS** |
229
+ | :--- | :--- | :--- | :--- | :--- |
230
+ | **Sync Throughput** | ~5.3M ops/sec | **~26M ops/sec** | ~18M ops/sec | ~41M ops/sec |
231
+ | **Batch Throughput** | ~7.0M ops/sec | **~44M ops/sec** | ~19M ops/sec | ~47M ops/sec |
232
+ | **Memory Jitter** | **Low (ยฑ0.5 MB)** | Medium (ยฑ0.7 MB) | High (ยฑ1.0 MB) | High (ยฑ0.9 MB) |
233
+ | **Cross-tab** | โœ… **Built-in** | โŒ (Manual) | โŒ | โŒ |
234
+ | **Buffering** | โœ… **Ring Buffer** | โŒ | โŒ | โœ… (ReplaySubject) |
235
+ | **Size (Gzipped)** | ~40KB (WASM) | < 200B | ~3KB | > 20KB |
236
+
237
+ ### When to use which?
238
+
239
+ 1. **Use `wasm-mq` if:**
240
+ * You need **Cross-tab Communication** out of the box.
241
+ * You require **stable memory usage** (low jitter) for long-running apps (dashboards, games).
242
+ * You need **Message History (Ring Buffer)** for late subscribers.
243
+ * You are already using Rust/WASM and want zero-overhead communication within WASM.
244
+
245
+ 2. **Use `mitt` if:**
246
+ * You just need simple, ultra-fast component communication within a single page.
247
+ * Bundle size (<200B) is your top priority.
248
+
249
+ 3. **Use `RxJS` if:**
250
+ * You need complex functional reactive programming (FRP) operators (map, filter, throttle, debounce).
251
+
252
+ ### ๐Ÿ”ฌ Running Benchmarks
253
+
254
+ You can verify these results yourself by running the included benchmark suite:
255
+
256
+ ```bash
257
+ # Start local server
258
+ npm run serve
259
+
260
+ # Open in browser
261
+ # http://localhost:8000/benchmark/comparison/index.html
262
+ ```
263
+
264
+ ## ๐Ÿ—๏ธ Building from Source
265
+
266
+ ```bash
267
+ # Install Rust and wasm-pack
268
+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
269
+ cargo install wasm-pack
270
+
271
+ # Clone and build
272
+ git clone <repo-url>
273
+ cd mq-
274
+ wasm-pack build --dev --target web
275
+
276
+ # The compiled files will be in the `pkg/` directory
277
+ ```
278
+
279
+ ## ๐Ÿ“– Examples
280
+
281
+ Please refer to the code snippets in the "Quick Start" section above for usage examples.
282
+
283
+ ## ๐ŸŽฏ Use Cases
284
+
285
+ - **Real-time dashboards** - Broadcast updates across multiple tabs
286
+ - **State synchronization** - Keep application state in sync
287
+ - **Event logging** - Buffer and replay events with ring buffer
288
+ - **Multi-tab coordination** - Coordinate actions between browser tabs
289
+ - **Message caching** - Temporarily cache messages for new subscribers
290
+
291
+ ## ๐Ÿ”ง Configuration
292
+
293
+ ### Release Build Optimization
294
+
295
+ The library is optimized for size in release mode:
296
+
297
+ ```toml
298
+ [profile.release]
299
+ lto = true # Link-time optimization
300
+ opt-level = "s" # Optimize for size
301
+ strip = true # Remove debug symbols
302
+ codegen-units = 1 # Better optimization at cost of compile time
303
+ ```
304
+
305
+ Result: ~40KB gzipped WebAssembly module
306
+
307
+ ## ๐Ÿงช Testing
308
+
309
+ ```bash
310
+ # Run Rust tests
311
+ cargo test
312
+ ```
313
+
314
+ ## ๐Ÿ“ License
315
+
316
+ MIT OR Apache-2.0
317
+
318
+ ## ๐Ÿค Contributing
319
+
320
+ Contributions are welcome! Please feel free to submit a Pull Request.
321
+
322
+ ## ๐Ÿ“ฎ Support
323
+
324
+ For issues and questions, please use the GitHub issue tracker.
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@weiwangfds/wasm-ripple",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "Wei Wang <weiwangfds@163.com>"
6
+ ],
7
+ "description": "A high-performance, memory-safe message queue library compiled to WebAssembly",
8
+ "version": "0.1.0",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/weiwangfds/wasm-ripple"
13
+ },
14
+ "files": [
15
+ "wasm_ripple_bg.wasm",
16
+ "wasm_ripple.js",
17
+ "wasm_ripple.d.ts"
18
+ ],
19
+ "main": "wasm_ripple.js",
20
+ "types": "wasm_ripple.d.ts",
21
+ "sideEffects": [
22
+ "./snippets/*"
23
+ ]
24
+ }
@@ -0,0 +1,159 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class MessageQueue {
5
+ free(): void;
6
+ [Symbol.dispose](): void;
7
+ /**
8
+ * Check if a topic has buffering enabled
9
+ * @param topic_id - ID of the topic
10
+ */
11
+ has_buffer(topic_id: number): boolean;
12
+ /**
13
+ * Get the number of topics
14
+ */
15
+ topic_count(): number;
16
+ /**
17
+ * Unsubscribe from a topic using its ID
18
+ */
19
+ unsubscribe(topic_id: number, sub_id: number): boolean;
20
+ /**
21
+ * Clear all buffered messages for a topic
22
+ * @param topic_id - ID of the topic
23
+ * @returns Number of messages cleared
24
+ */
25
+ clear_buffer(topic_id: number): number;
26
+ create_topic(topic_name: string): boolean;
27
+ destroy_topic(topic_id: number): boolean;
28
+ get_client_id(): string;
29
+ /**
30
+ * Publish a message asynchronously using Promise/microtask
31
+ * This returns immediately and delivers the message in the next microtask
32
+ * Useful for non-blocking operations and better browser responsiveness
33
+ */
34
+ publish_async(topic_id: number, payload: any): Promise<any>;
35
+ /**
36
+ * Register a topic and get its ID (handle) for fast publishing
37
+ * Returns the topic ID that can be used with publish_by_id
38
+ */
39
+ register_topic(topic_name: string): number;
40
+ /**
41
+ * Get the current size of the message buffer for a topic
42
+ * @param topic_id - ID of the topic
43
+ * @returns Number of messages currently buffered, or -1 if buffering is not enabled
44
+ */
45
+ get_buffer_size(topic_id: number): number;
46
+ /**
47
+ * Unsubscribe all subscribers from a topic
48
+ */
49
+ unsubscribe_all(topic_id: number): number;
50
+ /**
51
+ * Get the number of subscribers for a specific topic
52
+ */
53
+ subscriber_count(topic_id: number): number;
54
+ /**
55
+ * Enable message buffering for a specific topic
56
+ * Messages will be cached in a ring buffer for later retrieval
57
+ * @param topic_id - ID of the topic
58
+ * @param capacity - Maximum number of messages to buffer (default: 100)
59
+ */
60
+ enable_topic_buffer(topic_id: number, capacity?: number | null): void;
61
+ /**
62
+ * Get the buffer capacity for a topic
63
+ * @param topic_id - ID of the topic
64
+ * @returns Maximum buffer capacity, or 0 if buffering is not enabled
65
+ */
66
+ get_buffer_capacity(topic_id: number): number;
67
+ /**
68
+ * Publish multiple messages by ID (handle) efficiently
69
+ * This is the fastest way to publish multiple messages
70
+ */
71
+ publish_batch_by_id(topic_id: number, payloads: Array<any>): void;
72
+ /**
73
+ * Disable message buffering for a specific topic
74
+ * Clears all buffered messages
75
+ * @param topic_id - ID of the topic
76
+ */
77
+ disable_topic_buffer(topic_id: number): void;
78
+ /**
79
+ * Get buffered messages for a topic as a JavaScript array
80
+ * @param topic_id - ID of the topic
81
+ * @returns Array of buffered messages (oldest first), or empty array if no buffer
82
+ */
83
+ get_buffered_messages(topic_id: number): Array<any>;
84
+ constructor(channel_name?: string | null);
85
+ close(): void;
86
+ /**
87
+ * Publish using a topic ID (handle)
88
+ * This is O(1) and avoids string hashing/copying - significantly faster for high frequency
89
+ */
90
+ publish(topic_id: number, payload: any): void;
91
+ /**
92
+ * Check if a topic exists
93
+ */
94
+ has_topic(topic_id: number): boolean;
95
+ /**
96
+ * Subscribe to a topic using its ID
97
+ * Callback signature: (payload, topic_id, timestamp, message_id)
98
+ */
99
+ subscribe(topic_id: number, callback: Function): number;
100
+ }
101
+
102
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
103
+
104
+ export interface InitOutput {
105
+ readonly memory: WebAssembly.Memory;
106
+ readonly __wbg_messagequeue_free: (a: number, b: number) => void;
107
+ readonly messagequeue_clear_buffer: (a: number, b: number) => number;
108
+ readonly messagequeue_close: (a: number, b: number) => void;
109
+ readonly messagequeue_create_topic: (a: number, b: number, c: number) => number;
110
+ readonly messagequeue_destroy_topic: (a: number, b: number) => number;
111
+ readonly messagequeue_disable_topic_buffer: (a: number, b: number, c: number) => void;
112
+ readonly messagequeue_enable_topic_buffer: (a: number, b: number, c: number, d: number) => void;
113
+ readonly messagequeue_get_buffer_capacity: (a: number, b: number) => number;
114
+ readonly messagequeue_get_buffer_size: (a: number, b: number) => number;
115
+ readonly messagequeue_get_buffered_messages: (a: number, b: number, c: number) => void;
116
+ readonly messagequeue_get_client_id: (a: number, b: number) => void;
117
+ readonly messagequeue_has_buffer: (a: number, b: number) => number;
118
+ readonly messagequeue_has_topic: (a: number, b: number) => number;
119
+ readonly messagequeue_new: (a: number, b: number, c: number) => void;
120
+ readonly messagequeue_publish: (a: number, b: number, c: number, d: number) => void;
121
+ readonly messagequeue_publish_async: (a: number, b: number, c: number, d: number) => void;
122
+ readonly messagequeue_publish_batch_by_id: (a: number, b: number, c: number, d: number) => void;
123
+ readonly messagequeue_register_topic: (a: number, b: number, c: number) => number;
124
+ readonly messagequeue_subscribe: (a: number, b: number, c: number, d: number) => void;
125
+ readonly messagequeue_subscriber_count: (a: number, b: number) => number;
126
+ readonly messagequeue_topic_count: (a: number) => number;
127
+ readonly messagequeue_unsubscribe: (a: number, b: number, c: number) => number;
128
+ readonly messagequeue_unsubscribe_all: (a: number, b: number) => number;
129
+ readonly __wasm_bindgen_func_elem_144: (a: number, b: number, c: number) => void;
130
+ readonly __wasm_bindgen_func_elem_43: (a: number, b: number) => void;
131
+ readonly __wasm_bindgen_func_elem_528: (a: number, b: number, c: number, d: number) => void;
132
+ readonly __wbindgen_export: (a: number, b: number) => number;
133
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
134
+ readonly __wbindgen_export3: (a: number) => void;
135
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
136
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
137
+ }
138
+
139
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
140
+
141
+ /**
142
+ * Instantiates the given `module`, which can either be bytes or
143
+ * a precompiled `WebAssembly.Module`.
144
+ *
145
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
146
+ *
147
+ * @returns {InitOutput}
148
+ */
149
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
150
+
151
+ /**
152
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
153
+ * for everything else, calls `WebAssembly.instantiate` directly.
154
+ *
155
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
156
+ *
157
+ * @returns {Promise<InitOutput>}
158
+ */
159
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/wasm_ripple.js ADDED
@@ -0,0 +1,805 @@
1
+ let wasm;
2
+
3
+ function addHeapObject(obj) {
4
+ if (heap_next === heap.length) heap.push(heap.length + 1);
5
+ const idx = heap_next;
6
+ heap_next = heap[idx];
7
+
8
+ heap[idx] = obj;
9
+ return idx;
10
+ }
11
+
12
+ const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
13
+ ? { register: () => {}, unregister: () => {} }
14
+ : new FinalizationRegistry(state => state.dtor(state.a, state.b));
15
+
16
+ function dropObject(idx) {
17
+ if (idx < 132) return;
18
+ heap[idx] = heap_next;
19
+ heap_next = idx;
20
+ }
21
+
22
+ let cachedDataViewMemory0 = null;
23
+ function getDataViewMemory0() {
24
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
25
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
26
+ }
27
+ return cachedDataViewMemory0;
28
+ }
29
+
30
+ function getStringFromWasm0(ptr, len) {
31
+ ptr = ptr >>> 0;
32
+ return decodeText(ptr, len);
33
+ }
34
+
35
+ let cachedUint8ArrayMemory0 = null;
36
+ function getUint8ArrayMemory0() {
37
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
38
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
39
+ }
40
+ return cachedUint8ArrayMemory0;
41
+ }
42
+
43
+ function getObject(idx) { return heap[idx]; }
44
+
45
+ function handleError(f, args) {
46
+ try {
47
+ return f.apply(this, args);
48
+ } catch (e) {
49
+ wasm.__wbindgen_export3(addHeapObject(e));
50
+ }
51
+ }
52
+
53
+ let heap = new Array(128).fill(undefined);
54
+ heap.push(undefined, null, true, false);
55
+
56
+ let heap_next = heap.length;
57
+
58
+ function isLikeNone(x) {
59
+ return x === undefined || x === null;
60
+ }
61
+
62
+ function makeMutClosure(arg0, arg1, dtor, f) {
63
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
64
+ const real = (...args) => {
65
+
66
+ // First up with a closure we increment the internal reference
67
+ // count. This ensures that the Rust closure environment won't
68
+ // be deallocated while we're invoking it.
69
+ state.cnt++;
70
+ const a = state.a;
71
+ state.a = 0;
72
+ try {
73
+ return f(a, state.b, ...args);
74
+ } finally {
75
+ state.a = a;
76
+ real._wbg_cb_unref();
77
+ }
78
+ };
79
+ real._wbg_cb_unref = () => {
80
+ if (--state.cnt === 0) {
81
+ state.dtor(state.a, state.b);
82
+ state.a = 0;
83
+ CLOSURE_DTORS.unregister(state);
84
+ }
85
+ };
86
+ CLOSURE_DTORS.register(real, state, state);
87
+ return real;
88
+ }
89
+
90
+ function passStringToWasm0(arg, malloc, realloc) {
91
+ if (realloc === undefined) {
92
+ const buf = cachedTextEncoder.encode(arg);
93
+ const ptr = malloc(buf.length, 1) >>> 0;
94
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
95
+ WASM_VECTOR_LEN = buf.length;
96
+ return ptr;
97
+ }
98
+
99
+ let len = arg.length;
100
+ let ptr = malloc(len, 1) >>> 0;
101
+
102
+ const mem = getUint8ArrayMemory0();
103
+
104
+ let offset = 0;
105
+
106
+ for (; offset < len; offset++) {
107
+ const code = arg.charCodeAt(offset);
108
+ if (code > 0x7F) break;
109
+ mem[ptr + offset] = code;
110
+ }
111
+ if (offset !== len) {
112
+ if (offset !== 0) {
113
+ arg = arg.slice(offset);
114
+ }
115
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
116
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
117
+ const ret = cachedTextEncoder.encodeInto(arg, view);
118
+
119
+ offset += ret.written;
120
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
121
+ }
122
+
123
+ WASM_VECTOR_LEN = offset;
124
+ return ptr;
125
+ }
126
+
127
+ function takeObject(idx) {
128
+ const ret = getObject(idx);
129
+ dropObject(idx);
130
+ return ret;
131
+ }
132
+
133
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
134
+ cachedTextDecoder.decode();
135
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
136
+ let numBytesDecoded = 0;
137
+ function decodeText(ptr, len) {
138
+ numBytesDecoded += len;
139
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
140
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
141
+ cachedTextDecoder.decode();
142
+ numBytesDecoded = len;
143
+ }
144
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
145
+ }
146
+
147
+ const cachedTextEncoder = new TextEncoder();
148
+
149
+ if (!('encodeInto' in cachedTextEncoder)) {
150
+ cachedTextEncoder.encodeInto = function (arg, view) {
151
+ const buf = cachedTextEncoder.encode(arg);
152
+ view.set(buf);
153
+ return {
154
+ read: arg.length,
155
+ written: buf.length
156
+ };
157
+ }
158
+ }
159
+
160
+ let WASM_VECTOR_LEN = 0;
161
+
162
+ function __wasm_bindgen_func_elem_144(arg0, arg1, arg2) {
163
+ wasm.__wasm_bindgen_func_elem_144(arg0, arg1, addHeapObject(arg2));
164
+ }
165
+
166
+ function __wasm_bindgen_func_elem_528(arg0, arg1, arg2, arg3) {
167
+ wasm.__wasm_bindgen_func_elem_528(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
168
+ }
169
+
170
+ const MessageQueueFinalization = (typeof FinalizationRegistry === 'undefined')
171
+ ? { register: () => {}, unregister: () => {} }
172
+ : new FinalizationRegistry(ptr => wasm.__wbg_messagequeue_free(ptr >>> 0, 1));
173
+
174
+ /**
175
+ * A WebAssembly-based message queue with support for:
176
+ * - Topic-based pub/sub messaging
177
+ * - Cross-tab communication via BroadcastChannel
178
+ * - Synchronous and asynchronous publishing
179
+ * - Zero-copy message passing (using JsValue)
180
+ */
181
+ export class MessageQueue {
182
+ __destroy_into_raw() {
183
+ const ptr = this.__wbg_ptr;
184
+ this.__wbg_ptr = 0;
185
+ MessageQueueFinalization.unregister(this);
186
+ return ptr;
187
+ }
188
+ free() {
189
+ const ptr = this.__destroy_into_raw();
190
+ wasm.__wbg_messagequeue_free(ptr, 0);
191
+ }
192
+ /**
193
+ * Check if a topic has buffering enabled
194
+ * @param topic_id - ID of the topic
195
+ * @param {number} topic_id
196
+ * @returns {boolean}
197
+ */
198
+ has_buffer(topic_id) {
199
+ const ret = wasm.messagequeue_has_buffer(this.__wbg_ptr, topic_id);
200
+ return ret !== 0;
201
+ }
202
+ /**
203
+ * Get the number of topics
204
+ * @returns {number}
205
+ */
206
+ topic_count() {
207
+ const ret = wasm.messagequeue_topic_count(this.__wbg_ptr);
208
+ return ret >>> 0;
209
+ }
210
+ /**
211
+ * Unsubscribe from a topic using its ID
212
+ * @param {number} topic_id
213
+ * @param {number} sub_id
214
+ * @returns {boolean}
215
+ */
216
+ unsubscribe(topic_id, sub_id) {
217
+ const ret = wasm.messagequeue_unsubscribe(this.__wbg_ptr, topic_id, sub_id);
218
+ return ret !== 0;
219
+ }
220
+ /**
221
+ * Clear all buffered messages for a topic
222
+ * @param topic_id - ID of the topic
223
+ * @returns Number of messages cleared
224
+ * @param {number} topic_id
225
+ * @returns {number}
226
+ */
227
+ clear_buffer(topic_id) {
228
+ const ret = wasm.messagequeue_clear_buffer(this.__wbg_ptr, topic_id);
229
+ return ret >>> 0;
230
+ }
231
+ /**
232
+ * @param {string} topic_name
233
+ * @returns {boolean}
234
+ */
235
+ create_topic(topic_name) {
236
+ const ptr0 = passStringToWasm0(topic_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
237
+ const len0 = WASM_VECTOR_LEN;
238
+ const ret = wasm.messagequeue_create_topic(this.__wbg_ptr, ptr0, len0);
239
+ return ret !== 0;
240
+ }
241
+ /**
242
+ * @param {number} topic_id
243
+ * @returns {boolean}
244
+ */
245
+ destroy_topic(topic_id) {
246
+ const ret = wasm.messagequeue_destroy_topic(this.__wbg_ptr, topic_id);
247
+ return ret !== 0;
248
+ }
249
+ /**
250
+ * @returns {string}
251
+ */
252
+ get_client_id() {
253
+ let deferred1_0;
254
+ let deferred1_1;
255
+ try {
256
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
257
+ wasm.messagequeue_get_client_id(retptr, this.__wbg_ptr);
258
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
259
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
260
+ deferred1_0 = r0;
261
+ deferred1_1 = r1;
262
+ return getStringFromWasm0(r0, r1);
263
+ } finally {
264
+ wasm.__wbindgen_add_to_stack_pointer(16);
265
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
266
+ }
267
+ }
268
+ /**
269
+ * Publish a message asynchronously using Promise/microtask
270
+ * This returns immediately and delivers the message in the next microtask
271
+ * Useful for non-blocking operations and better browser responsiveness
272
+ * @param {number} topic_id
273
+ * @param {any} payload
274
+ * @returns {Promise<any>}
275
+ */
276
+ publish_async(topic_id, payload) {
277
+ try {
278
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
279
+ wasm.messagequeue_publish_async(retptr, this.__wbg_ptr, topic_id, addHeapObject(payload));
280
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
281
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
282
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
283
+ if (r2) {
284
+ throw takeObject(r1);
285
+ }
286
+ return takeObject(r0);
287
+ } finally {
288
+ wasm.__wbindgen_add_to_stack_pointer(16);
289
+ }
290
+ }
291
+ /**
292
+ * Register a topic and get its ID (handle) for fast publishing
293
+ * Returns the topic ID that can be used with publish_by_id
294
+ * @param {string} topic_name
295
+ * @returns {number}
296
+ */
297
+ register_topic(topic_name) {
298
+ const ptr0 = passStringToWasm0(topic_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
299
+ const len0 = WASM_VECTOR_LEN;
300
+ const ret = wasm.messagequeue_register_topic(this.__wbg_ptr, ptr0, len0);
301
+ return ret >>> 0;
302
+ }
303
+ /**
304
+ * Get the current size of the message buffer for a topic
305
+ * @param topic_id - ID of the topic
306
+ * @returns Number of messages currently buffered, or -1 if buffering is not enabled
307
+ * @param {number} topic_id
308
+ * @returns {number}
309
+ */
310
+ get_buffer_size(topic_id) {
311
+ const ret = wasm.messagequeue_get_buffer_size(this.__wbg_ptr, topic_id);
312
+ return ret;
313
+ }
314
+ /**
315
+ * Unsubscribe all subscribers from a topic
316
+ * @param {number} topic_id
317
+ * @returns {number}
318
+ */
319
+ unsubscribe_all(topic_id) {
320
+ const ret = wasm.messagequeue_unsubscribe_all(this.__wbg_ptr, topic_id);
321
+ return ret >>> 0;
322
+ }
323
+ /**
324
+ * Get the number of subscribers for a specific topic
325
+ * @param {number} topic_id
326
+ * @returns {number}
327
+ */
328
+ subscriber_count(topic_id) {
329
+ const ret = wasm.messagequeue_subscriber_count(this.__wbg_ptr, topic_id);
330
+ return ret >>> 0;
331
+ }
332
+ /**
333
+ * Enable message buffering for a specific topic
334
+ * Messages will be cached in a ring buffer for later retrieval
335
+ * @param topic_id - ID of the topic
336
+ * @param capacity - Maximum number of messages to buffer (default: 100)
337
+ * @param {number} topic_id
338
+ * @param {number | null} [capacity]
339
+ */
340
+ enable_topic_buffer(topic_id, capacity) {
341
+ try {
342
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
343
+ wasm.messagequeue_enable_topic_buffer(retptr, this.__wbg_ptr, topic_id, isLikeNone(capacity) ? 0x100000001 : (capacity) >>> 0);
344
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
345
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
346
+ if (r1) {
347
+ throw takeObject(r0);
348
+ }
349
+ } finally {
350
+ wasm.__wbindgen_add_to_stack_pointer(16);
351
+ }
352
+ }
353
+ /**
354
+ * Get the buffer capacity for a topic
355
+ * @param topic_id - ID of the topic
356
+ * @returns Maximum buffer capacity, or 0 if buffering is not enabled
357
+ * @param {number} topic_id
358
+ * @returns {number}
359
+ */
360
+ get_buffer_capacity(topic_id) {
361
+ const ret = wasm.messagequeue_get_buffer_capacity(this.__wbg_ptr, topic_id);
362
+ return ret >>> 0;
363
+ }
364
+ /**
365
+ * Publish multiple messages by ID (handle) efficiently
366
+ * This is the fastest way to publish multiple messages
367
+ * @param {number} topic_id
368
+ * @param {Array<any>} payloads
369
+ */
370
+ publish_batch_by_id(topic_id, payloads) {
371
+ try {
372
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
373
+ wasm.messagequeue_publish_batch_by_id(retptr, this.__wbg_ptr, topic_id, addHeapObject(payloads));
374
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
375
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
376
+ if (r1) {
377
+ throw takeObject(r0);
378
+ }
379
+ } finally {
380
+ wasm.__wbindgen_add_to_stack_pointer(16);
381
+ }
382
+ }
383
+ /**
384
+ * Disable message buffering for a specific topic
385
+ * Clears all buffered messages
386
+ * @param topic_id - ID of the topic
387
+ * @param {number} topic_id
388
+ */
389
+ disable_topic_buffer(topic_id) {
390
+ try {
391
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
392
+ wasm.messagequeue_disable_topic_buffer(retptr, this.__wbg_ptr, topic_id);
393
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
394
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
395
+ if (r1) {
396
+ throw takeObject(r0);
397
+ }
398
+ } finally {
399
+ wasm.__wbindgen_add_to_stack_pointer(16);
400
+ }
401
+ }
402
+ /**
403
+ * Get buffered messages for a topic as a JavaScript array
404
+ * @param topic_id - ID of the topic
405
+ * @returns Array of buffered messages (oldest first), or empty array if no buffer
406
+ * @param {number} topic_id
407
+ * @returns {Array<any>}
408
+ */
409
+ get_buffered_messages(topic_id) {
410
+ try {
411
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
412
+ wasm.messagequeue_get_buffered_messages(retptr, this.__wbg_ptr, topic_id);
413
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
414
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
415
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
416
+ if (r2) {
417
+ throw takeObject(r1);
418
+ }
419
+ return takeObject(r0);
420
+ } finally {
421
+ wasm.__wbindgen_add_to_stack_pointer(16);
422
+ }
423
+ }
424
+ /**
425
+ * @param {string | null} [channel_name]
426
+ */
427
+ constructor(channel_name) {
428
+ try {
429
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
430
+ var ptr0 = isLikeNone(channel_name) ? 0 : passStringToWasm0(channel_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
431
+ var len0 = WASM_VECTOR_LEN;
432
+ wasm.messagequeue_new(retptr, ptr0, len0);
433
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
434
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
435
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
436
+ if (r2) {
437
+ throw takeObject(r1);
438
+ }
439
+ this.__wbg_ptr = r0 >>> 0;
440
+ MessageQueueFinalization.register(this, this.__wbg_ptr, this);
441
+ return this;
442
+ } finally {
443
+ wasm.__wbindgen_add_to_stack_pointer(16);
444
+ }
445
+ }
446
+ close() {
447
+ try {
448
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
449
+ wasm.messagequeue_close(retptr, this.__wbg_ptr);
450
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
451
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
452
+ if (r1) {
453
+ throw takeObject(r0);
454
+ }
455
+ } finally {
456
+ wasm.__wbindgen_add_to_stack_pointer(16);
457
+ }
458
+ }
459
+ /**
460
+ * Publish using a topic ID (handle)
461
+ * This is O(1) and avoids string hashing/copying - significantly faster for high frequency
462
+ * @param {number} topic_id
463
+ * @param {any} payload
464
+ */
465
+ publish(topic_id, payload) {
466
+ try {
467
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
468
+ wasm.messagequeue_publish(retptr, this.__wbg_ptr, topic_id, addHeapObject(payload));
469
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
470
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
471
+ if (r1) {
472
+ throw takeObject(r0);
473
+ }
474
+ } finally {
475
+ wasm.__wbindgen_add_to_stack_pointer(16);
476
+ }
477
+ }
478
+ /**
479
+ * Check if a topic exists
480
+ * @param {number} topic_id
481
+ * @returns {boolean}
482
+ */
483
+ has_topic(topic_id) {
484
+ const ret = wasm.messagequeue_has_topic(this.__wbg_ptr, topic_id);
485
+ return ret !== 0;
486
+ }
487
+ /**
488
+ * Subscribe to a topic using its ID
489
+ * Callback signature: (payload, topic_id, timestamp, message_id)
490
+ * @param {number} topic_id
491
+ * @param {Function} callback
492
+ * @returns {number}
493
+ */
494
+ subscribe(topic_id, callback) {
495
+ try {
496
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
497
+ wasm.messagequeue_subscribe(retptr, this.__wbg_ptr, topic_id, addHeapObject(callback));
498
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
499
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
500
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
501
+ if (r2) {
502
+ throw takeObject(r1);
503
+ }
504
+ return r0 >>> 0;
505
+ } finally {
506
+ wasm.__wbindgen_add_to_stack_pointer(16);
507
+ }
508
+ }
509
+ }
510
+ if (Symbol.dispose) MessageQueue.prototype[Symbol.dispose] = MessageQueue.prototype.free;
511
+
512
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
513
+
514
+ async function __wbg_load(module, imports) {
515
+ if (typeof Response === 'function' && module instanceof Response) {
516
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
517
+ try {
518
+ return await WebAssembly.instantiateStreaming(module, imports);
519
+ } catch (e) {
520
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
521
+
522
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
523
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
524
+
525
+ } else {
526
+ throw e;
527
+ }
528
+ }
529
+ }
530
+
531
+ const bytes = await module.arrayBuffer();
532
+ return await WebAssembly.instantiate(bytes, imports);
533
+ } else {
534
+ const instance = await WebAssembly.instantiate(module, imports);
535
+
536
+ if (instance instanceof WebAssembly.Instance) {
537
+ return { instance, module };
538
+ } else {
539
+ return instance;
540
+ }
541
+ }
542
+ }
543
+
544
+ function __wbg_get_imports() {
545
+ const imports = {};
546
+ imports.wbg = {};
547
+ imports.wbg.__wbg___wbindgen_is_null_dfda7d66506c95b5 = function(arg0) {
548
+ const ret = getObject(arg0) === null;
549
+ return ret;
550
+ };
551
+ imports.wbg.__wbg___wbindgen_is_object_ce774f3490692386 = function(arg0) {
552
+ const val = getObject(arg0);
553
+ const ret = typeof(val) === 'object' && val !== null;
554
+ return ret;
555
+ };
556
+ imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
557
+ const ret = getObject(arg0) === undefined;
558
+ return ret;
559
+ };
560
+ imports.wbg.__wbg___wbindgen_number_get_9619185a74197f95 = function(arg0, arg1) {
561
+ const obj = getObject(arg1);
562
+ const ret = typeof(obj) === 'number' ? obj : undefined;
563
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
564
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
565
+ };
566
+ imports.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42 = function(arg0, arg1) {
567
+ const obj = getObject(arg1);
568
+ const ret = typeof(obj) === 'string' ? obj : undefined;
569
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
570
+ var len1 = WASM_VECTOR_LEN;
571
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
572
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
573
+ };
574
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
575
+ throw new Error(getStringFromWasm0(arg0, arg1));
576
+ };
577
+ imports.wbg.__wbg__wbg_cb_unref_87dfb5aaa0cbcea7 = function(arg0) {
578
+ getObject(arg0)._wbg_cb_unref();
579
+ };
580
+ imports.wbg.__wbg_call_3020136f7a2d6e44 = function() { return handleError(function (arg0, arg1, arg2) {
581
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
582
+ return addHeapObject(ret);
583
+ }, arguments) };
584
+ imports.wbg.__wbg_call_760a3f0ff6ecdb31 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
585
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3), getObject(arg4), getObject(arg5), getObject(arg6));
586
+ return addHeapObject(ret);
587
+ }, arguments) };
588
+ imports.wbg.__wbg_call_985cbf350d9ec0e5 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
589
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3), getObject(arg4), getObject(arg5));
590
+ return addHeapObject(ret);
591
+ }, arguments) };
592
+ imports.wbg.__wbg_call_abb4ff46ce38be40 = function() { return handleError(function (arg0, arg1) {
593
+ const ret = getObject(arg0).call(getObject(arg1));
594
+ return addHeapObject(ret);
595
+ }, arguments) };
596
+ imports.wbg.__wbg_close_c956ddbf0426a990 = function(arg0) {
597
+ getObject(arg0).close();
598
+ };
599
+ imports.wbg.__wbg_crypto_59726e04573101a0 = function() { return handleError(function (arg0) {
600
+ const ret = getObject(arg0).crypto;
601
+ return addHeapObject(ret);
602
+ }, arguments) };
603
+ imports.wbg.__wbg_data_8bf4ae669a78a688 = function(arg0) {
604
+ const ret = getObject(arg0).data;
605
+ return addHeapObject(ret);
606
+ };
607
+ imports.wbg.__wbg_from_29a8414a7a7cd19d = function(arg0) {
608
+ const ret = Array.from(getObject(arg0));
609
+ return addHeapObject(ret);
610
+ };
611
+ imports.wbg.__wbg_get_6b7bd52aca3f9671 = function(arg0, arg1) {
612
+ const ret = getObject(arg0)[arg1 >>> 0];
613
+ return addHeapObject(ret);
614
+ };
615
+ imports.wbg.__wbg_instanceof_Window_b5cf7783caa68180 = function(arg0) {
616
+ let result;
617
+ try {
618
+ result = getObject(arg0) instanceof Window;
619
+ } catch (_) {
620
+ result = false;
621
+ }
622
+ const ret = result;
623
+ return ret;
624
+ };
625
+ imports.wbg.__wbg_isArray_ca6bc609f742df3f = function(arg0) {
626
+ const ret = Array.isArray(getObject(arg0));
627
+ return ret;
628
+ };
629
+ imports.wbg.__wbg_length_d45040a40c570362 = function(arg0) {
630
+ const ret = getObject(arg0).length;
631
+ return ret;
632
+ };
633
+ imports.wbg.__wbg_new_25f239778d6112b9 = function() {
634
+ const ret = new Array();
635
+ return addHeapObject(ret);
636
+ };
637
+ imports.wbg.__wbg_new_b3dd747604c3c93e = function() { return handleError(function (arg0, arg1) {
638
+ const ret = new BroadcastChannel(getStringFromWasm0(arg0, arg1));
639
+ return addHeapObject(ret);
640
+ }, arguments) };
641
+ imports.wbg.__wbg_new_ff12d2b041fb48f1 = function(arg0, arg1) {
642
+ try {
643
+ var state0 = {a: arg0, b: arg1};
644
+ var cb0 = (arg0, arg1) => {
645
+ const a = state0.a;
646
+ state0.a = 0;
647
+ try {
648
+ return __wasm_bindgen_func_elem_528(a, state0.b, arg0, arg1);
649
+ } finally {
650
+ state0.a = a;
651
+ }
652
+ };
653
+ const ret = new Promise(cb0);
654
+ return addHeapObject(ret);
655
+ } finally {
656
+ state0.a = state0.b = 0;
657
+ }
658
+ };
659
+ imports.wbg.__wbg_new_no_args_cb138f77cf6151ee = function(arg0, arg1) {
660
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
661
+ return addHeapObject(ret);
662
+ };
663
+ imports.wbg.__wbg_new_with_args_df9e7125ffe55248 = function(arg0, arg1, arg2, arg3) {
664
+ const ret = new Function(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
665
+ return addHeapObject(ret);
666
+ };
667
+ imports.wbg.__wbg_now_69d776cd24f5215b = function() {
668
+ const ret = Date.now();
669
+ return ret;
670
+ };
671
+ imports.wbg.__wbg_postMessage_ee7b4e76cd1ed685 = function() { return handleError(function (arg0, arg1) {
672
+ getObject(arg0).postMessage(getObject(arg1));
673
+ }, arguments) };
674
+ imports.wbg.__wbg_push_7d9be8f38fc13975 = function(arg0, arg1) {
675
+ const ret = getObject(arg0).push(getObject(arg1));
676
+ return ret;
677
+ };
678
+ imports.wbg.__wbg_randomUUID_9f549a1cc1e2b0bf = function(arg0, arg1) {
679
+ const ret = getObject(arg1).randomUUID();
680
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
681
+ const len1 = WASM_VECTOR_LEN;
682
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
683
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
684
+ };
685
+ imports.wbg.__wbg_random_cc1f9237d866d212 = function() {
686
+ const ret = Math.random();
687
+ return ret;
688
+ };
689
+ imports.wbg.__wbg_resolve_fd5bfbaa4ce36e1e = function(arg0) {
690
+ const ret = Promise.resolve(getObject(arg0));
691
+ return addHeapObject(ret);
692
+ };
693
+ imports.wbg.__wbg_set_onmessage_6fa00f5d8f1c055a = function(arg0, arg1) {
694
+ getObject(arg0).onmessage = getObject(arg1);
695
+ };
696
+ imports.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335 = function() {
697
+ const ret = typeof global === 'undefined' ? null : global;
698
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
699
+ };
700
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1 = function() {
701
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
702
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
703
+ };
704
+ imports.wbg.__wbg_static_accessor_SELF_08f5a74c69739274 = function() {
705
+ const ret = typeof self === 'undefined' ? null : self;
706
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
707
+ };
708
+ imports.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024 = function() {
709
+ const ret = typeof window === 'undefined' ? null : window;
710
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
711
+ };
712
+ imports.wbg.__wbg_then_4f95312d68691235 = function(arg0, arg1) {
713
+ const ret = getObject(arg0).then(getObject(arg1));
714
+ return addHeapObject(ret);
715
+ };
716
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
717
+ // Cast intrinsic for `Ref(String) -> Externref`.
718
+ const ret = getStringFromWasm0(arg0, arg1);
719
+ return addHeapObject(ret);
720
+ };
721
+ imports.wbg.__wbindgen_cast_32bc49bfb4050e32 = function(arg0, arg1) {
722
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 1, function: Function { arguments: [Externref], shim_idx: 2, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
723
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_43, __wasm_bindgen_func_elem_144);
724
+ return addHeapObject(ret);
725
+ };
726
+ imports.wbg.__wbindgen_cast_46d6ccd6e2a13afa = function(arg0, arg1) {
727
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 1, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 2, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
728
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_43, __wasm_bindgen_func_elem_144);
729
+ return addHeapObject(ret);
730
+ };
731
+ imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
732
+ // Cast intrinsic for `F64 -> Externref`.
733
+ const ret = arg0;
734
+ return addHeapObject(ret);
735
+ };
736
+ imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
737
+ const ret = getObject(arg0);
738
+ return addHeapObject(ret);
739
+ };
740
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
741
+ takeObject(arg0);
742
+ };
743
+
744
+ return imports;
745
+ }
746
+
747
+ function __wbg_finalize_init(instance, module) {
748
+ wasm = instance.exports;
749
+ __wbg_init.__wbindgen_wasm_module = module;
750
+ cachedDataViewMemory0 = null;
751
+ cachedUint8ArrayMemory0 = null;
752
+
753
+
754
+
755
+ return wasm;
756
+ }
757
+
758
+ function initSync(module) {
759
+ if (wasm !== undefined) return wasm;
760
+
761
+
762
+ if (typeof module !== 'undefined') {
763
+ if (Object.getPrototypeOf(module) === Object.prototype) {
764
+ ({module} = module)
765
+ } else {
766
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
767
+ }
768
+ }
769
+
770
+ const imports = __wbg_get_imports();
771
+ if (!(module instanceof WebAssembly.Module)) {
772
+ module = new WebAssembly.Module(module);
773
+ }
774
+ const instance = new WebAssembly.Instance(module, imports);
775
+ return __wbg_finalize_init(instance, module);
776
+ }
777
+
778
+ async function __wbg_init(module_or_path) {
779
+ if (wasm !== undefined) return wasm;
780
+
781
+
782
+ if (typeof module_or_path !== 'undefined') {
783
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
784
+ ({module_or_path} = module_or_path)
785
+ } else {
786
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
787
+ }
788
+ }
789
+
790
+ if (typeof module_or_path === 'undefined') {
791
+ module_or_path = new URL('wasm_ripple_bg.wasm', import.meta.url);
792
+ }
793
+ const imports = __wbg_get_imports();
794
+
795
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
796
+ module_or_path = fetch(module_or_path);
797
+ }
798
+
799
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
800
+
801
+ return __wbg_finalize_init(instance, module);
802
+ }
803
+
804
+ export { initSync };
805
+ export default __wbg_init;
Binary file