a tool for shared writing and social publishing

remove ywasm

-6645
public/wasm/ywasm_bg.wasm

This is a binary file and will not be displayed.

-23
src/ywasm/LICENSE
··· 1 - The MIT License (MIT) 2 - 3 - Copyright (c) 2020 4 - - Kevin Jahns <kevin.jahns@pm.me>. 5 - - Bartosz Sypytkowski <b.sypytkowski@gmail.com>. 6 - 7 - Permission is hereby granted, free of charge, to any person obtaining a copy 8 - of this software and associated documentation files (the "Software"), to deal 9 - in the Software without restriction, including without limitation the rights 10 - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 - copies of the Software, and to permit persons to whom the Software is 12 - furnished to do so, subject to the following conditions: 13 - 14 - The above copyright notice and this permission notice shall be included in all 15 - copies or substantial portions of the Software. 16 - 17 - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 - SOFTWARE.
-36
src/ywasm/README.md
··· 1 - # Ywasm 2 - 3 - This project is a wrapper around [Yrs](../yrs/README.md) and targets Web Assembly bindings. 4 - 5 - It's a library used on collaborative document editing using Conflict-free Replicated Data Types. 6 - This enables to provide a shared document editing experience on a client devices without explicit requirement for hosting a single server - CRDTs can resolve potential update conflicts on their own with no central authority - as well as provide first-class offline editing capabilities, where document replicas are modified without having connection to each other, and then synchronize automatically once such connection is enabled. 7 - 8 - ## [Documentation](https://docs.rs/ywasm/) 9 - 10 - ## Example 11 - 12 - ```js 13 - import * as Y from 'ywasm'; 14 - 15 - const doc = new Y.YDoc() 16 - const text = doc.getText('name') 17 - 18 - // append text to our collaborative document 19 - text.insert(0, 'hello world', { bold: true }) 20 - 21 - // simulate update with remote peer 22 - const remoteDoc = new Y.YDoc() 23 - const remoteText = remoteDoc.getText('name') 24 - 25 - // in order to exchange data with other documents 26 - // we first need to create a state vector 27 - const remoteSV = Y.encodeStateVector(remoteDoc) 28 - // now compute a differential update based on remote document's state vector 29 - const update = Y.encodeStateAsUpdate(doc, remoteSV) 30 - // both update and state vector are serializable, we can pass them over the wire 31 - // now apply update to a remote document 32 - Y.applyUpdate(remoteDoc, update) 33 - 34 - const str = remoteText.toString() 35 - console.log(str) 36 - ```
-27
src/ywasm/package.json
··· 1 - { 2 - "name": "ywasm", 3 - "collaborators": [ 4 - "Kevin Jahns <kevin.jahns@protonmail.com>", 5 - "Bartosz Sypytkowski <b.sypytkowski@gmail.com>" 6 - ], 7 - "description": "High performance implementation of the Yjs CRDT", 8 - "version": "0.24.0", 9 - "license": "MIT", 10 - "repository": { 11 - "type": "git", 12 - "url": "https://github.com/yjs/y-crdt/" 13 - }, 14 - "files": [ 15 - "ywasm_bg.wasm", 16 - "ywasm.js", 17 - "ywasm.d.ts" 18 - ], 19 - "main": "ywasm.js", 20 - "homepage": "https://github.com/yjs/y-crdt/", 21 - "types": "ywasm.d.ts", 22 - "keywords": [ 23 - "crdt", 24 - "wasm", 25 - "yrs" 26 - ] 27 - }
-1537
src/ywasm/ywasm.d.ts
··· 1 - /* tslint:disable */ 2 - /* eslint-disable */ 3 - /** 4 - * When called will call console log errors whenever internal panic is called from within 5 - * WebAssembly module. 6 - */ 7 - export function setPanicHook(): void; 8 - /** 9 - * Encodes a state vector of a given ywasm document into its binary representation using lib0 v1 10 - * encoding. State vector is a compact representation of updates performed on a given document and 11 - * can be used by `encode_state_as_update` on remote peer to generate a delta update payload to 12 - * synchronize changes between peers. 13 - * 14 - * Example: 15 - * 16 - * ```javascript 17 - * import {YDoc, encodeStateVector, encodeStateAsUpdate, applyUpdate} from 'ywasm' 18 - * 19 - * /// document on machine A 20 - * const localDoc = new YDoc() 21 - * const localSV = encodeStateVector(localDoc) 22 - * 23 - * // document on machine B 24 - * const remoteDoc = new YDoc() 25 - * const remoteDelta = encodeStateAsUpdate(remoteDoc, localSV) 26 - * 27 - * applyUpdate(localDoc, remoteDelta) 28 - * ``` 29 - */ 30 - export function encodeStateVector(doc: YDoc): Uint8Array; 31 - /** 32 - * Returns a string dump representation of a given `update` encoded using lib0 v1 encoding. 33 - */ 34 - export function debugUpdateV1(update: Uint8Array): string; 35 - /** 36 - * Returns a string dump representation of a given `update` encoded using lib0 v2 encoding. 37 - */ 38 - export function debugUpdateV2(update: Uint8Array): string; 39 - /** 40 - * Merges a sequence of updates (encoded using lib0 v1 encoding) together, producing another 41 - * update (also lib0 v1 encoded) in the result. Returned binary is a combination of all input 42 - * `updates`, compressed. 43 - * 44 - * Returns an error whenever any of the input updates couldn't be decoded. 45 - */ 46 - export function mergeUpdatesV1(updates: Array<any>): Uint8Array; 47 - /** 48 - * Merges a sequence of updates (encoded using lib0 v2 encoding) together, producing another 49 - * update (also lib0 v2 encoded) in the result. Returned binary is a combination of all input 50 - * `updates`, compressed. 51 - * 52 - * Returns an error whenever any of the input updates couldn't be decoded. 53 - */ 54 - export function mergeUpdatesV2(updates: Array<any>): Uint8Array; 55 - /** 56 - * Encodes all updates that have happened since a given version `vector` into a compact delta 57 - * representation using lib0 v1 encoding. If `vector` parameter has not been provided, generated 58 - * delta payload will contain all changes of a current ywasm document, working effectivelly as its 59 - * state snapshot. 60 - * 61 - * Example: 62 - * 63 - * ```javascript 64 - * import {YDoc, encodeStateVector, encodeStateAsUpdate, applyUpdate} from 'ywasm' 65 - * 66 - * /// document on machine A 67 - * const localDoc = new YDoc() 68 - * const localSV = encodeStateVector(localDoc) 69 - * 70 - * // document on machine B 71 - * const remoteDoc = new YDoc() 72 - * const remoteDelta = encodeStateAsUpdate(remoteDoc, localSV) 73 - * 74 - * applyUpdate(localDoc, remoteDelta) 75 - * ``` 76 - */ 77 - export function encodeStateAsUpdate(doc: YDoc, vector?: Uint8Array | null): Uint8Array; 78 - /** 79 - * Encodes all updates that have happened since a given version `vector` into a compact delta 80 - * representation using lib0 v2 encoding. If `vector` parameter has not been provided, generated 81 - * delta payload will contain all changes of a current ywasm document, working effectivelly as its 82 - * state snapshot. 83 - * 84 - * Example: 85 - * 86 - * ```javascript 87 - * import {YDoc, encodeStateVector, encodeStateAsUpdate, applyUpdate} from 'ywasm' 88 - * 89 - * /// document on machine A 90 - * const localDoc = new YDoc() 91 - * const localSV = encodeStateVector(localDoc) 92 - * 93 - * // document on machine B 94 - * const remoteDoc = new YDoc() 95 - * const remoteDelta = encodeStateAsUpdateV2(remoteDoc, localSV) 96 - * 97 - * applyUpdate(localDoc, remoteDelta) 98 - * ``` 99 - */ 100 - export function encodeStateAsUpdateV2(doc: YDoc, vector?: Uint8Array | null): Uint8Array; 101 - /** 102 - * Applies delta update generated by the remote document replica to a current document. This 103 - * method assumes that a payload maintains lib0 v1 encoding format. 104 - * 105 - * Example: 106 - * 107 - * ```javascript 108 - * import {YDoc, encodeStateVector, encodeStateAsUpdate, applyUpdate} from 'ywasm' 109 - * 110 - * /// document on machine A 111 - * const localDoc = new YDoc() 112 - * const localSV = encodeStateVector(localDoc) 113 - * 114 - * // document on machine B 115 - * const remoteDoc = new YDoc() 116 - * const remoteDelta = encodeStateAsUpdate(remoteDoc, localSV) 117 - * 118 - * applyUpdateV2(localDoc, remoteDelta) 119 - * ``` 120 - */ 121 - export function applyUpdate(doc: YDoc, update: Uint8Array, origin: any): void; 122 - /** 123 - * Applies delta update generated by the remote document replica to a current document. This 124 - * method assumes that a payload maintains lib0 v2 encoding format. 125 - * 126 - * Example: 127 - * 128 - * ```javascript 129 - * import {YDoc, encodeStateVector, encodeStateAsUpdate, applyUpdate} from 'ywasm' 130 - * 131 - * /// document on machine A 132 - * const localDoc = new YDoc() 133 - * const localSV = encodeStateVector(localDoc) 134 - * 135 - * // document on machine B 136 - * const remoteDoc = new YDoc() 137 - * const remoteDelta = encodeStateAsUpdateV2(remoteDoc, localSV) 138 - * 139 - * applyUpdateV2(localDoc, remoteDelta) 140 - * ``` 141 - */ 142 - export function applyUpdateV2(doc: YDoc, update: Uint8Array, origin: any): void; 143 - export function snapshot(doc: YDoc): any; 144 - export function equalSnapshots(snap1: any, snap2: any): boolean; 145 - export function encodeSnapshotV1(snapshot: any): Uint8Array; 146 - export function encodeSnapshotV2(snapshot: any): Uint8Array; 147 - export function decodeSnapshotV2(snapshot: Uint8Array): any; 148 - export function decodeSnapshotV1(snapshot: Uint8Array): any; 149 - export function encodeStateFromSnapshotV1(doc: YDoc, snapshot: any): Uint8Array; 150 - export function encodeStateFromSnapshotV2(doc: YDoc, snapshot: any): Uint8Array; 151 - /** 152 - * Retrieves a sticky index corresponding to a given human-readable `index` pointing into 153 - * the shared `ytype`. Unlike standard indexes sticky indexes enables to track 154 - * the location inside of a shared y-types, even in the face of concurrent updates. 155 - * 156 - * If association is >= 0, the resulting position will point to location **after** the referenced index. 157 - * If association is < 0, the resulting position will point to location **before** the referenced index. 158 - */ 159 - export function createRelativePositionFromTypeIndex(ytype: any, index: number, assoc: number, txn: YTransaction | undefined): any; 160 - /** 161 - * Converts a sticky index (see: `createStickyIndexFromType`) into an object 162 - * containing human-readable index. 163 - */ 164 - export function createAbsolutePositionFromRelativePosition(rpos: any, doc: YDoc): any; 165 - /** 166 - * Serializes sticky index created by `createStickyIndexFromType` into a binary 167 - * payload. 168 - */ 169 - export function encodeRelativePosition(rpos: any): Uint8Array; 170 - /** 171 - * Deserializes sticky index serialized previously by `encodeStickyIndex`. 172 - */ 173 - export function decodeRelativePosition(bin: Uint8Array): any; 174 - export function compareRelativePositions(a: any, b: any): boolean; 175 - export function removeAwarenessStates(awareness: Awareness, clients: BigUint64Array): void; 176 - export function encodeAwarenessUpdate(awareness: Awareness, clients: any): Uint8Array; 177 - export function modifyAwarenessUpdate(update: Uint8Array, modify: Function): Uint8Array; 178 - export function applyAwarenessUpdate(awareness: Awareness, update: Uint8Array, _origin: any): void; 179 - export class Awareness { 180 - free(): void; 181 - constructor(doc: YDoc); 182 - destroy(): void; 183 - getLocalState(): any; 184 - setLocalState(state: any): void; 185 - setLocalStateField(key: string, value: any): void; 186 - getStates(): Map<any, any>; 187 - on(event: string, callback: Function): void; 188 - off(event: string, callback: Function): boolean; 189 - readonly doc: YDoc; 190 - readonly meta: Map<any, any>; 191 - } 192 - /** 193 - * A collection used to store data in an indexed sequence structure. This type is internally 194 - * implemented as a double linked list, which may squash values inserted directly one after another 195 - * into single list node upon transaction commit. 196 - * 197 - * Reading a root-level type as an YArray means treating its sequence components as a list, where 198 - * every countable element becomes an individual entity: 199 - * 200 - * - JSON-like primitives (booleans, numbers, strings, JSON maps, arrays etc.) are counted 201 - * individually. 202 - * - Text chunks inserted by [Text] data structure: each character becomes an element of an 203 - * array. 204 - * - Embedded and binary values: they count as a single element even though they correspond of 205 - * multiple bytes. 206 - * 207 - * Like all Yrs shared data types, YArray is resistant to the problem of interleaving (situation 208 - * when elements inserted one after another may interleave with other peers concurrent inserts 209 - * after merging all updates together). In case of Yrs conflict resolution is solved by using 210 - * unique document id to determine correct and consistent ordering. 211 - */ 212 - export class YArray { 213 - free(): void; 214 - /** 215 - * Creates a new preliminary instance of a `YArray` shared data type, with its state 216 - * initialized to provided parameter. 217 - * 218 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 219 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 220 - * document store and cannot be nested again: attempt to do so will result in an exception. 221 - */ 222 - constructor(items?: any[] | null); 223 - /** 224 - * Checks if current YArray reference is alive and has not been deleted by its parent collection. 225 - * This method only works on already integrated shared types and will return false is current 226 - * type is preliminary (has not been integrated into document). 227 - */ 228 - alive(txn: YTransaction): boolean; 229 - /** 230 - * Returns a number of elements stored within this instance of `YArray`. 231 - */ 232 - length(txn: YTransaction | undefined): number; 233 - /** 234 - * Converts an underlying contents of this `YArray` instance into their JSON representation. 235 - */ 236 - toJson(txn: YTransaction | undefined): any; 237 - /** 238 - * Inserts a given range of `items` into this `YArray` instance, starting at given `index`. 239 - */ 240 - insert(index: number, items: any[], txn: YTransaction | undefined): void; 241 - /** 242 - * Appends a range of `items` at the end of this `YArray` instance. 243 - */ 244 - push(items: any[], txn: YTransaction | undefined): void; 245 - /** 246 - * Deletes a range of items of given `length` from current `YArray` instance, 247 - * starting from given `index`. 248 - */ 249 - delete(index: number, length: number | null | undefined, txn: YTransaction | undefined): void; 250 - /** 251 - * Moves element found at `source` index into `target` index position. 252 - */ 253 - move(source: number, target: number, txn: YTransaction | undefined): void; 254 - /** 255 - * Returns an element stored under given `index`. 256 - */ 257 - get(index: number, txn: YTransaction | undefined): any; 258 - quote(lower: number | null | undefined, upper: number | null | undefined, lower_open: boolean | null | undefined, upper_open: boolean | null | undefined, txn: YTransaction | undefined): YWeakLink; 259 - /** 260 - * Returns an iterator that can be used to traverse over the values stored withing this 261 - * instance of `YArray`. 262 - * 263 - * Example: 264 - * 265 - * ```javascript 266 - * import YDoc from 'ywasm' 267 - * 268 - * /// document on machine A 269 - * const doc = new YDoc() 270 - * const array = doc.getArray('name') 271 - * const txn = doc.beginTransaction() 272 - * try { 273 - * array.push(txn, ['hello', 'world']) 274 - * for (let item of array.values(txn)) { 275 - * console.log(item) 276 - * } 277 - * } finally { 278 - * txn.free() 279 - * } 280 - * ``` 281 - */ 282 - values(txn: YTransaction | undefined): any; 283 - /** 284 - * Subscribes to all operations happening over this instance of `YArray`. All changes are 285 - * batched and eventually triggered during transaction commit phase. 286 - */ 287 - observe(callback: Function): void; 288 - unobserve(callback: Function): boolean; 289 - /** 290 - * Subscribes to all operations happening over this Y shared type, as well as events in 291 - * shared types stored within this one. All changes are batched and eventually triggered 292 - * during transaction commit phase. 293 - */ 294 - observeDeep(callback: Function): void; 295 - unobserveDeep(callback: Function): boolean; 296 - readonly type: number; 297 - /** 298 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 299 - * document. 300 - */ 301 - readonly id: any; 302 - /** 303 - * Returns true if this is a preliminary instance of `YArray`. 304 - * 305 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 306 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 307 - * document store and cannot be nested again: attempt to do so will result in an exception. 308 - */ 309 - readonly prelim: boolean; 310 - } 311 - /** 312 - * Event generated by `YArray.observe` method. Emitted during transaction commit phase. 313 - */ 314 - export class YArrayEvent { 315 - private constructor(); 316 - free(): void; 317 - /** 318 - * Returns an array of keys and indexes creating a path from root type down to current instance 319 - * of shared type (accessible via `target` getter). 320 - */ 321 - path(): any; 322 - /** 323 - * Returns a current shared type instance, that current event changes refer to. 324 - */ 325 - readonly target: any; 326 - readonly origin: any; 327 - /** 328 - * Returns a list of text changes made over corresponding `YArray` collection within 329 - * bounds of current transaction. These changes follow a format: 330 - * 331 - * - { insert: any[] } 332 - * - { delete: number } 333 - * - { retain: number } 334 - */ 335 - readonly delta: any; 336 - } 337 - /** 338 - * A ywasm document type. Documents are most important units of collaborative resources management. 339 - * All shared collections live within a scope of their corresponding documents. All updates are 340 - * generated on per-document basis (rather than individual shared type). All operations on shared 341 - * collections happen via [YTransaction], which lifetime is also bound to a document. 342 - * 343 - * Document manages so-called root types, which are top-level shared types definitions (as opposed 344 - * to recursively nested types). 345 - * 346 - * A basic workflow sample: 347 - * 348 - * ```javascript 349 - * import YDoc from 'ywasm' 350 - * 351 - * const doc = new YDoc() 352 - * const txn = doc.beginTransaction() 353 - * try { 354 - * const text = txn.getText('name') 355 - * text.push(txn, 'hello world') 356 - * const output = text.toString(txn) 357 - * console.log(output) 358 - * } finally { 359 - * txn.free() 360 - * } 361 - * ``` 362 - */ 363 - export class YDoc { 364 - free(): void; 365 - /** 366 - * Creates a new ywasm document. If `id` parameter was passed it will be used as this document 367 - * globally unique identifier (it's up to caller to ensure that requirement). Otherwise it will 368 - * be assigned a randomly generated number. 369 - */ 370 - constructor(options: any); 371 - /** 372 - * Returns a new transaction for this document. Ywasm shared data types execute their 373 - * operations in a context of a given transaction. Each document can have only one active 374 - * transaction at the time - subsequent attempts will cause exception to be thrown. 375 - * 376 - * Transactions started with `doc.beginTransaction` can be released using `transaction.free` 377 - * method. 378 - * 379 - * Example: 380 - * 381 - * ```javascript 382 - * import YDoc from 'ywasm' 383 - * 384 - * // helper function used to simplify transaction 385 - * // create/release cycle 386 - * YDoc.prototype.transact = callback => { 387 - * const txn = this.transaction() 388 - * try { 389 - * return callback(txn) 390 - * } finally { 391 - * txn.free() 392 - * } 393 - * } 394 - * 395 - * const doc = new YDoc() 396 - * const text = doc.getText('name') 397 - * doc.transact(txn => text.insert(txn, 0, 'hello world')) 398 - * ``` 399 - */ 400 - beginTransaction(origin: any): YTransaction; 401 - /** 402 - * Returns a `YText` shared data type, that's accessible for subsequent accesses using given 403 - * `name`. 404 - * 405 - * If there was no instance with this name before, it will be created and then returned. 406 - * 407 - * If there was an instance with this name, but it was of different type, it will be projected 408 - * onto `YText` instance. 409 - */ 410 - getText(name: string): YText; 411 - /** 412 - * Returns a `YArray` shared data type, that's accessible for subsequent accesses using given 413 - * `name`. 414 - * 415 - * If there was no instance with this name before, it will be created and then returned. 416 - * 417 - * If there was an instance with this name, but it was of different type, it will be projected 418 - * onto `YArray` instance. 419 - */ 420 - getArray(name: string): YArray; 421 - /** 422 - * Returns a `YMap` shared data type, that's accessible for subsequent accesses using given 423 - * `name`. 424 - * 425 - * If there was no instance with this name before, it will be created and then returned. 426 - * 427 - * If there was an instance with this name, but it was of different type, it will be projected 428 - * onto `YMap` instance. 429 - */ 430 - getMap(name: string): YMap; 431 - /** 432 - * Returns a `YXmlFragment` shared data type, that's accessible for subsequent accesses using 433 - * given `name`. 434 - * 435 - * If there was no instance with this name before, it will be created and then returned. 436 - * 437 - * If there was an instance with this name, but it was of different type, it will be projected 438 - * onto `YXmlFragment` instance. 439 - */ 440 - getXmlFragment(name: string): YXmlFragment; 441 - on(event: string, callback: Function): void; 442 - off(event: string, callback: Function): boolean; 443 - /** 444 - * Notify the parent document that you request to load data into this subdocument 445 - * (if it is a subdocument). 446 - */ 447 - load(parent_txn: YTransaction | undefined): void; 448 - /** 449 - * Emit `onDestroy` event and unregister all event handlers. 450 - */ 451 - destroy(parent_txn: YTransaction | undefined): void; 452 - /** 453 - * Returns a list of sub-documents existings within the scope of this document. 454 - */ 455 - getSubdocs(txn: YTransaction | undefined): Array<any>; 456 - /** 457 - * Returns a list of unique identifiers of the sub-documents existings within the scope of 458 - * this document. 459 - */ 460 - getSubdocGuids(txn: YTransaction | undefined): Set<any>; 461 - /** 462 - * Returns a list of all root-level replicated collections, together with their types. 463 - * These collections can then be accessed via `getMap`/`getText` etc. methods. 464 - * 465 - * Example: 466 - * ```js 467 - * import * as Y from 'ywasm' 468 - * 469 - * const doc = new Y.YDoc() 470 - * const ymap = doc.getMap('a') 471 - * const yarray = doc.getArray('b') 472 - * const ytext = doc.getText('c') 473 - * const yxml = doc.getXmlFragment('d') 474 - * 475 - * const roots = doc.roots() // [['a',ymap], ['b',yarray], ['c',ytext], ['d',yxml]] 476 - * ``` 477 - */ 478 - roots(txn: YTransaction | undefined): Array<any>; 479 - /** 480 - * Evaluates a JSON path expression (see: https://en.wikipedia.org/wiki/JSONPath) on 481 - * the document and returns an array of values matching that query. 482 - * 483 - * Currently, this method supports the following syntax: 484 - * - `$` - root object 485 - * - `@` - current object 486 - * - `.field` or `['field']` - member accessor 487 - * - `[1]` - array index (also supports negative indices) 488 - * - `.*` or `[*]` - wildcard (matches all members of an object or array) 489 - * - `..` - recursive descent (matches all descendants not only direct children) 490 - * - `[start:end:step]` - array slice operator (requires positive integer arguments) 491 - * - `['a', 'b', 'c']` - union operator (returns an array of values for each query) 492 - * - `[1, -1, 3]` - multiple indices operator (returns an array of values for each index) 493 - * 494 - * At the moment, JSON Path does not support filter predicates. 495 - */ 496 - selectAll(json_path: string): Array<any>; 497 - /** 498 - * Evaluates a JSON path expression (see: https://en.wikipedia.org/wiki/JSONPath) on 499 - * the document and returns first value matching that query. 500 - * 501 - * Currently, this method supports the following syntax: 502 - * - `$` - root object 503 - * - `@` - current object 504 - * - `.field` or `['field']` - member accessor 505 - * - `[1]` - array index (also supports negative indices) 506 - * - `.*` or `[*]` - wildcard (matches all members of an object or array) 507 - * - `..` - recursive descent (matches all descendants not only direct children) 508 - * - `[start:end:step]` - array slice operator (requires positive integer arguments) 509 - * - `['a', 'b', 'c']` - union operator (returns an array of values for each query) 510 - * - `[1, -1, 3]` - multiple indices operator (returns an array of values for each index) 511 - * 512 - * At the moment, JSON Path does not support filter predicates. 513 - */ 514 - selectOne(json_path: string): any; 515 - readonly type: number; 516 - /** 517 - * Checks if a document is a preliminary type. It returns false, if current document 518 - * is already a sub-document of another document. 519 - */ 520 - readonly prelim: boolean; 521 - /** 522 - * Returns a parent document of this document or null if current document is not sub-document. 523 - */ 524 - readonly parentDoc: YDoc | undefined; 525 - /** 526 - * Gets unique peer identifier of this `YDoc` instance. 527 - */ 528 - readonly id: number; 529 - /** 530 - * Gets globally unique identifier of this `YDoc` instance. 531 - */ 532 - readonly guid: string; 533 - readonly shouldLoad: boolean; 534 - readonly autoLoad: boolean; 535 - } 536 - /** 537 - * Collection used to store key-value entries in an unordered manner. Keys are always represented 538 - * as UTF-8 strings. Values can be any value type supported by Yrs: JSON-like primitives as well as 539 - * shared data types. 540 - * 541 - * In terms of conflict resolution, [Map] uses logical last-write-wins principle, meaning the past 542 - * updates are automatically overridden and discarded by newer ones, while concurrent updates made 543 - * by different peers are resolved into a single value using document id seniority to establish 544 - * order. 545 - */ 546 - export class YMap { 547 - free(): void; 548 - /** 549 - * Creates a new preliminary instance of a `YMap` shared data type, with its state 550 - * initialized to provided parameter. 551 - * 552 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 553 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 554 - * document store and cannot be nested again: attempt to do so will result in an exception. 555 - */ 556 - constructor(init?: object | null); 557 - /** 558 - * Checks if current YMap reference is alive and has not been deleted by its parent collection. 559 - * This method only works on already integrated shared types and will return false is current 560 - * type is preliminary (has not been integrated into document). 561 - */ 562 - alive(txn: YTransaction): boolean; 563 - /** 564 - * Returns a number of entries stored within this instance of `YMap`. 565 - */ 566 - length(txn: YTransaction | undefined): number; 567 - /** 568 - * Converts contents of this `YMap` instance into a JSON representation. 569 - */ 570 - toJson(txn: YTransaction | undefined): any; 571 - /** 572 - * Sets a given `key`-`value` entry within this instance of `YMap`. If another entry was 573 - * already stored under given `key`, it will be overridden with new `value`. 574 - */ 575 - set(key: string, value: any, txn: YTransaction | undefined): void; 576 - /** 577 - * Removes an entry identified by a given `key` from this instance of `YMap`, if such exists. 578 - */ 579 - delete(key: string, txn: YTransaction | undefined): void; 580 - /** 581 - * Returns value of an entry stored under given `key` within this instance of `YMap`, 582 - * or `undefined` if no such entry existed. 583 - */ 584 - get(key: string, txn: YTransaction | undefined): any; 585 - link(key: string, txn: YTransaction | undefined): any; 586 - /** 587 - * Returns an iterator that can be used to traverse over all entries stored within this 588 - * instance of `YMap`. Order of entry is not specified. 589 - * 590 - * Example: 591 - * 592 - * ```javascript 593 - * import YDoc from 'ywasm' 594 - * 595 - * /// document on machine A 596 - * const doc = new YDoc() 597 - * const map = doc.getMap('name') 598 - * const txn = doc.beginTransaction() 599 - * try { 600 - * map.set(txn, 'key1', 'value1') 601 - * map.set(txn, 'key2', true) 602 - * 603 - * for (let [key, value] of map.entries(txn)) { 604 - * console.log(key, value) 605 - * } 606 - * } finally { 607 - * txn.free() 608 - * } 609 - * ``` 610 - */ 611 - entries(txn: YTransaction | undefined): any; 612 - /** 613 - * Subscribes to all operations happening over this instance of `YMap`. All changes are 614 - * batched and eventually triggered during transaction commit phase. 615 - */ 616 - observe(callback: Function): void; 617 - /** 618 - * Unsubscribes a callback previously subscribed with `observe` method. 619 - */ 620 - unobserve(callback: Function): boolean; 621 - /** 622 - * Subscribes to all operations happening over this Y shared type, as well as events in 623 - * shared types stored within this one. All changes are batched and eventually triggered 624 - * during transaction commit phase. 625 - */ 626 - observeDeep(callback: Function): void; 627 - /** 628 - * Unsubscribes a callback previously subscribed with `observeDeep` method. 629 - */ 630 - unobserveDeep(callback: Function): boolean; 631 - readonly type: number; 632 - /** 633 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 634 - * document. 635 - */ 636 - readonly id: any; 637 - /** 638 - * Returns true if this is a preliminary instance of `YMap`. 639 - * 640 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 641 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 642 - * document store and cannot be nested again: attempt to do so will result in an exception. 643 - */ 644 - readonly prelim: boolean; 645 - } 646 - /** 647 - * Event generated by `YMap.observe` method. Emitted during transaction commit phase. 648 - */ 649 - export class YMapEvent { 650 - private constructor(); 651 - free(): void; 652 - /** 653 - * Returns an array of keys and indexes creating a path from root type down to current instance 654 - * of shared type (accessible via `target` getter). 655 - */ 656 - path(): any; 657 - readonly origin: any; 658 - /** 659 - * Returns a current shared type instance, that current event changes refer to. 660 - */ 661 - readonly target: any; 662 - /** 663 - * Returns a list of key-value changes made over corresponding `YMap` collection within 664 - * bounds of current transaction. These changes follow a format: 665 - * 666 - * - { action: 'add'|'update'|'delete', oldValue: any|undefined, newValue: any|undefined } 667 - */ 668 - readonly keys: any; 669 - } 670 - export class YSubdocsEvent { 671 - private constructor(); 672 - free(): void; 673 - readonly added: Array<any>; 674 - readonly removed: Array<any>; 675 - readonly loaded: Array<any>; 676 - } 677 - /** 678 - * A shared data type used for collaborative text editing. It enables multiple users to add and 679 - * remove chunks of text in efficient manner. This type is internally represented as a mutable 680 - * double-linked list of text chunks - an optimization occurs during `YTransaction.commit`, which 681 - * allows to squash multiple consecutively inserted characters together as a single chunk of text 682 - * even between transaction boundaries in order to preserve more efficient memory model. 683 - * 684 - * `YText` structure internally uses UTF-8 encoding and its length is described in a number of 685 - * bytes rather than individual characters (a single UTF-8 code point can consist of many bytes). 686 - * 687 - * Like all Yrs shared data types, `YText` is resistant to the problem of interleaving (situation 688 - * when characters inserted one after another may interleave with other peers concurrent inserts 689 - * after merging all updates together). In case of Yrs conflict resolution is solved by using 690 - * unique document id to determine correct and consistent ordering. 691 - */ 692 - export class YText { 693 - free(): void; 694 - /** 695 - * Creates a new preliminary instance of a `YText` shared data type, with its state initialized 696 - * to provided parameter. 697 - * 698 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 699 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 700 - * document store and cannot be nested again: attempt to do so will result in an exception. 701 - */ 702 - constructor(init?: string | null); 703 - /** 704 - * Checks if current YArray reference is alive and has not been deleted by its parent collection. 705 - * This method only works on already integrated shared types and will return false is current 706 - * type is preliminary (has not been integrated into document). 707 - */ 708 - alive(txn: YTransaction): boolean; 709 - /** 710 - * Returns length of an underlying string stored in this `YText` instance, 711 - * understood as a number of UTF-8 encoded bytes. 712 - */ 713 - length(txn: YTransaction | undefined): number; 714 - /** 715 - * Returns an underlying shared string stored in this data type. 716 - */ 717 - toString(txn: YTransaction | undefined): string; 718 - /** 719 - * Returns an underlying shared string stored in this data type. 720 - */ 721 - toJson(txn: YTransaction | undefined): any; 722 - /** 723 - * Inserts a given `chunk` of text into this `YText` instance, starting at a given `index`. 724 - * 725 - * Optional object with defined `attributes` will be used to wrap provided text `chunk` 726 - * with a formatting blocks.`attributes` are only supported for a `YText` instance which 727 - * already has been integrated into document store. 728 - */ 729 - insert(index: number, chunk: string, attributes: any, txn: YTransaction | undefined): void; 730 - /** 731 - * Inserts a given `embed` object into this `YText` instance, starting at a given `index`. 732 - * 733 - * Optional object with defined `attributes` will be used to wrap provided `embed` 734 - * with a formatting blocks.`attributes` are only supported for a `YText` instance which 735 - * already has been integrated into document store. 736 - */ 737 - insertEmbed(index: number, embed: any, attributes: any, txn: YTransaction | undefined): void; 738 - /** 739 - * Wraps an existing piece of text within a range described by `index`-`length` parameters with 740 - * formatting blocks containing provided `attributes` metadata. This method only works for 741 - * `YText` instances that already have been integrated into document store. 742 - */ 743 - format(index: number, length: number, attributes: any, txn: YTransaction | undefined): void; 744 - /** 745 - * Appends a given `chunk` of text at the end of current `YText` instance. 746 - * 747 - * Optional object with defined `attributes` will be used to wrap provided text `chunk` 748 - * with a formatting blocks.`attributes` are only supported for a `YText` instance which 749 - * already has been integrated into document store. 750 - */ 751 - push(chunk: string, attributes: any, txn: YTransaction | undefined): void; 752 - /** 753 - * Deletes a specified range of characters, starting at a given `index`. 754 - * Both `index` and `length` are counted in terms of a number of UTF-8 character bytes. 755 - */ 756 - delete(index: number, length: number, txn: YTransaction | undefined): void; 757 - quote(lower: number | null | undefined, upper: number | null | undefined, lower_open: boolean | null | undefined, upper_open: boolean | null | undefined, txn: YTransaction | undefined): YWeakLink; 758 - /** 759 - * Returns the Delta representation of this YText type. 760 - */ 761 - toDelta(snapshot: any, prev_snapshot: any, compute_ychange: Function | null | undefined, txn: YTransaction | undefined): Array<any>; 762 - applyDelta(delta: Array<any>, txn: YTransaction | undefined): void; 763 - /** 764 - * Subscribes to all operations happening over this instance of `YText`. All changes are 765 - * batched and eventually triggered during transaction commit phase. 766 - */ 767 - observe(callback: Function): void; 768 - /** 769 - * Unsubscribes a callback previously subscribed with `observe` method. 770 - */ 771 - unobserve(callback: Function): boolean; 772 - /** 773 - * Subscribes to all operations happening over this Y shared type, as well as events in 774 - * shared types stored within this one. All changes are batched and eventually triggered 775 - * during transaction commit phase. 776 - */ 777 - observeDeep(callback: Function): void; 778 - /** 779 - * Unsubscribes a callback previously subscribed with `observeDeep` method. 780 - */ 781 - unobserveDeep(callback: Function): boolean; 782 - readonly type: number; 783 - /** 784 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 785 - * document. 786 - */ 787 - readonly id: any; 788 - /** 789 - * Returns true if this is a preliminary instance of `YArray`. 790 - * 791 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 792 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 793 - * document store and cannot be nested again: attempt to do so will result in an exception. 794 - */ 795 - readonly prelim: boolean; 796 - } 797 - /** 798 - * Event generated by `YYText.observe` method. Emitted during transaction commit phase. 799 - */ 800 - export class YTextEvent { 801 - private constructor(); 802 - free(): void; 803 - /** 804 - * Returns an array of keys and indexes creating a path from root type down to current instance 805 - * of shared type (accessible via `target` getter). 806 - */ 807 - path(): any; 808 - /** 809 - * Returns a current shared type instance, that current event changes refer to. 810 - */ 811 - readonly target: any; 812 - readonly origin: any; 813 - /** 814 - * Returns a list of text changes made over corresponding `YText` collection within 815 - * bounds of current transaction. These changes follow a format: 816 - * 817 - * - { insert: string, attributes: any|undefined } 818 - * - { delete: number } 819 - * - { retain: number, attributes: any|undefined } 820 - */ 821 - readonly delta: any; 822 - } 823 - export class YTransaction { 824 - private constructor(); 825 - free(): void; 826 - /** 827 - * Given a logical identifier of the collection (obtained via `YText.id`, `YArray.id` etc.), 828 - * attempts to return an instance of that collection in the scope of current document. 829 - * 830 - * Returns `undefined` if an instance was not defined locally, haven't been integrated or 831 - * has been deleted. 832 - */ 833 - get(id: any): any; 834 - /** 835 - * Triggers a post-update series of operations without `free`ing the transaction. This includes 836 - * compaction and optimization of internal representation of updates, triggering events etc. 837 - * ywasm transactions are auto-committed when they are `free`d. 838 - */ 839 - commit(): void; 840 - /** 841 - * Encodes a state vector of a given transaction document into its binary representation using 842 - * lib0 v1 encoding. State vector is a compact representation of updates performed on a given 843 - * document and can be used by `encode_state_as_update` on remote peer to generate a delta 844 - * update payload to synchronize changes between peers. 845 - * 846 - * Example: 847 - * 848 - * ```javascript 849 - * import YDoc from 'ywasm' 850 - * 851 - * /// document on machine A 852 - * const localDoc = new YDoc() 853 - * const localTxn = localDoc.beginTransaction() 854 - * 855 - * // document on machine B 856 - * const remoteDoc = new YDoc() 857 - * const remoteTxn = localDoc.beginTransaction() 858 - * 859 - * try { 860 - * const localSV = localTxn.stateVectorV1() 861 - * const remoteDelta = remoteTxn.diffV1(localSv) 862 - * localTxn.applyV1(remoteDelta) 863 - * } finally { 864 - * localTxn.free() 865 - * remoteTxn.free() 866 - * } 867 - * ``` 868 - */ 869 - stateVectorV1(): Uint8Array; 870 - /** 871 - * Encodes all updates that have happened since a given version `vector` into a compact delta 872 - * representation using lib0 v1 encoding. If `vector` parameter has not been provided, generated 873 - * delta payload will contain all changes of a current ywasm document, working effectively as 874 - * its state snapshot. 875 - * 876 - * Example: 877 - * 878 - * ```javascript 879 - * import YDoc from 'ywasm' 880 - * 881 - * /// document on machine A 882 - * const localDoc = new YDoc() 883 - * const localTxn = localDoc.beginTransaction() 884 - * 885 - * // document on machine B 886 - * const remoteDoc = new YDoc() 887 - * const remoteTxn = localDoc.beginTransaction() 888 - * 889 - * try { 890 - * const localSV = localTxn.stateVectorV1() 891 - * const remoteDelta = remoteTxn.diffV1(localSv) 892 - * localTxn.applyV1(remoteDelta) 893 - * } finally { 894 - * localTxn.free() 895 - * remoteTxn.free() 896 - * } 897 - * ``` 898 - */ 899 - diffV1(vector?: Uint8Array | null): Uint8Array; 900 - /** 901 - * Encodes all updates that have happened since a given version `vector` into a compact delta 902 - * representation using lib0 v1 encoding. If `vector` parameter has not been provided, generated 903 - * delta payload will contain all changes of a current ywasm document, working effectively as 904 - * its state snapshot. 905 - * 906 - * Example: 907 - * 908 - * ```javascript 909 - * import YDoc from 'ywasm' 910 - * 911 - * /// document on machine A 912 - * const localDoc = new YDoc() 913 - * const localTxn = localDoc.beginTransaction() 914 - * 915 - * // document on machine B 916 - * const remoteDoc = new YDoc() 917 - * const remoteTxn = localDoc.beginTransaction() 918 - * 919 - * try { 920 - * const localSV = localTxn.stateVectorV1() 921 - * const remoteDelta = remoteTxn.diffV2(localSv) 922 - * localTxn.applyV2(remoteDelta) 923 - * } finally { 924 - * localTxn.free() 925 - * remoteTxn.free() 926 - * } 927 - * ``` 928 - */ 929 - diffV2(vector?: Uint8Array | null): Uint8Array; 930 - /** 931 - * Applies delta update generated by the remote document replica to a current transaction's 932 - * document. This method assumes that a payload maintains lib0 v1 encoding format. 933 - * 934 - * Example: 935 - * 936 - * ```javascript 937 - * import YDoc from 'ywasm' 938 - * 939 - * /// document on machine A 940 - * const localDoc = new YDoc() 941 - * const localTxn = localDoc.beginTransaction() 942 - * 943 - * // document on machine B 944 - * const remoteDoc = new YDoc() 945 - * const remoteTxn = localDoc.beginTransaction() 946 - * 947 - * try { 948 - * const localSV = localTxn.stateVectorV1() 949 - * const remoteDelta = remoteTxn.diffV1(localSv) 950 - * localTxn.applyV1(remoteDelta) 951 - * } finally { 952 - * localTxn.free() 953 - * remoteTxn.free() 954 - * } 955 - * ``` 956 - */ 957 - applyV1(diff: Uint8Array): void; 958 - /** 959 - * Applies delta update generated by the remote document replica to a current transaction's 960 - * document. This method assumes that a payload maintains lib0 v2 encoding format. 961 - * 962 - * Example: 963 - * 964 - * ```javascript 965 - * import YDoc from 'ywasm' 966 - * 967 - * /// document on machine A 968 - * const localDoc = new YDoc() 969 - * const localTxn = localDoc.beginTransaction() 970 - * 971 - * // document on machine B 972 - * const remoteDoc = new YDoc() 973 - * const remoteTxn = localDoc.beginTransaction() 974 - * 975 - * try { 976 - * const localSV = localTxn.stateVectorV1() 977 - * const remoteDelta = remoteTxn.diffV2(localSv) 978 - * localTxn.applyV2(remoteDelta) 979 - * } finally { 980 - * localTxn.free() 981 - * remoteTxn.free() 982 - * } 983 - * ``` 984 - */ 985 - applyV2(diff: Uint8Array): void; 986 - encodeUpdate(): Uint8Array; 987 - encodeUpdateV2(): Uint8Array; 988 - /** 989 - * Force garbage collection of the deleted elements, regardless of a parent doc was created 990 - * with `gc` option turned on or off. 991 - */ 992 - gc(): void; 993 - /** 994 - * Evaluates a JSON path expression (see: https://en.wikipedia.org/wiki/JSONPath) on 995 - * the document and returns an array of values matching that query. 996 - * 997 - * Currently, this method supports the following syntax: 998 - * - `$` - root object 999 - * - `@` - current object 1000 - * - `.field` or `['field']` - member accessor 1001 - * - `[1]` - array index (also supports negative indices) 1002 - * - `.*` or `[*]` - wildcard (matches all members of an object or array) 1003 - * - `..` - recursive descent (matches all descendants not only direct children) 1004 - * - `[start:end:step]` - array slice operator (requires positive integer arguments) 1005 - * - `['a', 'b', 'c']` - union operator (returns an array of values for each query) 1006 - * - `[1, -1, 3]` - multiple indices operator (returns an array of values for each index) 1007 - * 1008 - * At the moment, JSON Path does not support filter predicates. 1009 - */ 1010 - selectAll(json_path: string): Array<any>; 1011 - /** 1012 - * Evaluates a JSON path expression (see: https://en.wikipedia.org/wiki/JSONPath) on 1013 - * the document and returns first value matching that query. 1014 - * 1015 - * Currently, this method supports the following syntax: 1016 - * - `$` - root object 1017 - * - `@` - current object 1018 - * - `.field` or `['field']` - member accessor 1019 - * - `[1]` - array index (also supports negative indices) 1020 - * - `.*` or `[*]` - wildcard (matches all members of an object or array) 1021 - * - `..` - recursive descent (matches all descendants not only direct children) 1022 - * - `[start:end:step]` - array slice operator (requires positive integer arguments) 1023 - * - `['a', 'b', 'c']` - union operator (returns an array of values for each query) 1024 - * - `[1, -1, 3]` - multiple indices operator (returns an array of values for each index) 1025 - * 1026 - * At the moment, JSON Path does not support filter predicates. 1027 - */ 1028 - selectOne(json_path: string): any; 1029 - /** 1030 - * Returns state vector describing the state of the document 1031 - * at the moment when the transaction began. 1032 - */ 1033 - readonly beforeState: Map<any, any>; 1034 - /** 1035 - * Returns state vector describing the current state of 1036 - * the document. 1037 - */ 1038 - readonly afterState: Map<any, any>; 1039 - readonly pendingStructs: any; 1040 - /** 1041 - * Returns a unapplied delete set, that was received in one of the previous remote updates. 1042 - * This DeleteSet is waiting for a missing updates to arrive in order to be applied. 1043 - */ 1044 - readonly pendingDeleteSet: Map<any, any> | undefined; 1045 - /** 1046 - * Returns a delete set containing information about 1047 - * all blocks removed as part of a current transaction. 1048 - */ 1049 - readonly deleteSet: Map<any, any>; 1050 - readonly origin: any; 1051 - } 1052 - export class YUndoEvent { 1053 - private constructor(); 1054 - free(): void; 1055 - readonly origin: any; 1056 - readonly kind: any; 1057 - meta: any; 1058 - } 1059 - export class YUndoManager { 1060 - free(): void; 1061 - constructor(doc: YDoc, scope: any, options: any); 1062 - addToScope(ytypes: Array<any>): void; 1063 - addTrackedOrigin(origin: any): void; 1064 - removeTrackedOrigin(origin: any): void; 1065 - clear(): void; 1066 - stopCapturing(): void; 1067 - undo(): void; 1068 - redo(): void; 1069 - on(event: string, callback: Function): void; 1070 - off(event: string, callback: Function): boolean; 1071 - readonly canUndo: boolean; 1072 - readonly canRedo: boolean; 1073 - } 1074 - export class YWeakLink { 1075 - private constructor(); 1076 - free(): void; 1077 - /** 1078 - * Checks if current YWeakLink reference is alive and has not been deleted by its parent collection. 1079 - * This method only works on already integrated shared types and will return false is current 1080 - * type is preliminary (has not been integrated into document). 1081 - */ 1082 - alive(txn: YTransaction): boolean; 1083 - deref(txn: YTransaction | undefined): any; 1084 - unquote(txn: YTransaction | undefined): Array<any>; 1085 - toString(txn: YTransaction | undefined): string; 1086 - /** 1087 - * Subscribes to all operations happening over this instance of `YMap`. All changes are 1088 - * batched and eventually triggered during transaction commit phase. 1089 - */ 1090 - observe(callback: Function): void; 1091 - /** 1092 - * Unsubscribes a callback previously subscribed with `observe` method. 1093 - */ 1094 - unobserve(callback: Function): boolean; 1095 - /** 1096 - * Subscribes to all operations happening over this Y shared type, as well as events in 1097 - * shared types stored within this one. All changes are batched and eventually triggered 1098 - * during transaction commit phase. 1099 - */ 1100 - observeDeep(callback: Function): void; 1101 - /** 1102 - * Unsubscribes a callback previously subscribed with `observeDeep` method. 1103 - */ 1104 - unobserveDeep(callback: Function): boolean; 1105 - /** 1106 - * Returns true if this is a preliminary instance of `YWeakLink`. 1107 - * 1108 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 1109 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 1110 - * document store and cannot be nested again: attempt to do so will result in an exception. 1111 - */ 1112 - readonly prelim: boolean; 1113 - readonly type: number; 1114 - /** 1115 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 1116 - * document. 1117 - */ 1118 - readonly id: any; 1119 - } 1120 - /** 1121 - * Event generated by `YXmlElement.observe` method. Emitted during transaction commit phase. 1122 - */ 1123 - export class YWeakLinkEvent { 1124 - private constructor(); 1125 - free(): void; 1126 - /** 1127 - * Returns an array of keys and indexes creating a path from root type down to current instance 1128 - * of shared type (accessible via `target` getter). 1129 - */ 1130 - path(): any; 1131 - readonly origin: any; 1132 - /** 1133 - * Returns a current shared type instance, that current event changes refer to. 1134 - */ 1135 - readonly target: any; 1136 - } 1137 - /** 1138 - * XML element data type. It represents an XML node, which can contain key-value attributes 1139 - * (interpreted as strings) as well as other nested XML elements or rich text (represented by 1140 - * `YXmlText` type). 1141 - * 1142 - * In terms of conflict resolution, `YXmlElement` uses following rules: 1143 - * 1144 - * - Attribute updates use logical last-write-wins principle, meaning the past updates are 1145 - * automatically overridden and discarded by newer ones, while concurrent updates made by 1146 - * different peers are resolved into a single value using document id seniority to establish 1147 - * an order. 1148 - * - Child node insertion uses sequencing rules from other Yrs collections - elements are inserted 1149 - * using interleave-resistant algorithm, where order of concurrent inserts at the same index 1150 - * is established using peer's document id seniority. 1151 - */ 1152 - export class YXmlElement { 1153 - free(): void; 1154 - constructor(name: string, attributes: any, children: any); 1155 - /** 1156 - * Checks if current shared type reference is alive and has not been deleted by its parent collection. 1157 - * This method only works on already integrated shared types and will return false is current 1158 - * type is preliminary (has not been integrated into document). 1159 - */ 1160 - alive(txn: YTransaction): boolean; 1161 - /** 1162 - * Returns a tag name of this XML node. 1163 - */ 1164 - name(txn: YTransaction | undefined): string; 1165 - /** 1166 - * Returns a number of child XML nodes stored within this `YXMlElement` instance. 1167 - */ 1168 - length(txn: YTransaction | undefined): number; 1169 - insert(index: number, xml_node: any, txn: YTransaction | undefined): void; 1170 - push(xml_node: any, txn: YTransaction | undefined): void; 1171 - delete(index: number, length: number | null | undefined, txn: YTransaction | undefined): void; 1172 - /** 1173 - * Returns a first child of this XML node. 1174 - * It can be either `YXmlElement`, `YXmlText` or `undefined` if current node has not children. 1175 - */ 1176 - firstChild(txn: YTransaction | undefined): any; 1177 - /** 1178 - * Returns a next XML sibling node of this XMl node. 1179 - * It can be either `YXmlElement`, `YXmlText` or `undefined` if current node is a last child of 1180 - * parent XML node. 1181 - */ 1182 - nextSibling(txn: YTransaction | undefined): any; 1183 - /** 1184 - * Returns a previous XML sibling node of this XMl node. 1185 - * It can be either `YXmlElement`, `YXmlText` or `undefined` if current node is a first child 1186 - * of parent XML node. 1187 - */ 1188 - prevSibling(txn: YTransaction | undefined): any; 1189 - /** 1190 - * Returns a parent `YXmlElement` node or `undefined` if current node has no parent assigned. 1191 - */ 1192 - parent(txn: YTransaction | undefined): any; 1193 - /** 1194 - * Returns a string representation of this XML node. 1195 - */ 1196 - toString(txn: YTransaction | undefined): string; 1197 - /** 1198 - * Sets a `name` and `value` as new attribute for this XML node. If an attribute with the same 1199 - * `name` already existed on that node, its value with be overridden with a provided one. 1200 - * This method accepts any JavaScript value, not just strings. 1201 - */ 1202 - setAttribute(name: string, value: any, txn: YTransaction | undefined): void; 1203 - /** 1204 - * Returns a value of an attribute given its `name` as any JS value. If no attribute with such name existed, 1205 - * `undefined` will be returned. 1206 - */ 1207 - getAttribute(name: string, txn: YTransaction | undefined): any; 1208 - /** 1209 - * Removes an attribute from this XML node, given its `name`. 1210 - */ 1211 - removeAttribute(name: string, txn: YTransaction | undefined): void; 1212 - /** 1213 - * Returns an iterator that enables to traverse over all attributes of this XML node in 1214 - * unspecified order. This method returns attribute values as their original JS values, 1215 - * not just as strings. 1216 - */ 1217 - attributes(txn: YTransaction | undefined): any; 1218 - /** 1219 - * Returns an iterator that enables a deep traversal of this XML node - starting from first 1220 - * child over this XML node successors using depth-first strategy. 1221 - */ 1222 - treeWalker(txn: YTransaction | undefined): Array<any>; 1223 - /** 1224 - * Subscribes to all operations happening over this instance of `YXmlElement`. All changes are 1225 - * batched and eventually triggered during transaction commit phase. 1226 - */ 1227 - observe(callback: Function): void; 1228 - /** 1229 - * Unsubscribes a callback previously subscribed with `observe` method. 1230 - */ 1231 - unobserve(callback: Function): boolean; 1232 - /** 1233 - * Subscribes to all operations happening over this Y shared type, as well as events in 1234 - * shared types stored within this one. All changes are batched and eventually triggered 1235 - * during transaction commit phase. 1236 - */ 1237 - observeDeep(callback: Function): void; 1238 - /** 1239 - * Unsubscribes a callback previously subscribed with `observeDeep` method. 1240 - */ 1241 - unobserveDeep(callback: Function): boolean; 1242 - readonly type: number; 1243 - /** 1244 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 1245 - * document. 1246 - */ 1247 - readonly id: any; 1248 - /** 1249 - * Returns true if this is a preliminary instance of `YXmlElement`. 1250 - * 1251 - * Preliminary instances can be nested into other shared data types. 1252 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 1253 - * document store and cannot be nested again: attempt to do so will result in an exception. 1254 - */ 1255 - readonly prelim: boolean; 1256 - } 1257 - /** 1258 - * Event generated by `YXmlElement.observe` method. Emitted during transaction commit phase. 1259 - */ 1260 - export class YXmlEvent { 1261 - private constructor(); 1262 - free(): void; 1263 - /** 1264 - * Returns an array of keys and indexes creating a path from root type down to current instance 1265 - * of shared type (accessible via `target` getter). 1266 - */ 1267 - path(): any; 1268 - /** 1269 - * Returns a current shared type instance, that current event changes refer to. 1270 - */ 1271 - readonly target: any; 1272 - readonly origin: any; 1273 - /** 1274 - * Returns a list of attribute changes made over corresponding `YXmlText` collection within 1275 - * bounds of current transaction. These changes follow a format: 1276 - * 1277 - * - { action: 'add'|'update'|'delete', oldValue: string|undefined, newValue: string|undefined } 1278 - */ 1279 - readonly keys: any; 1280 - /** 1281 - * Returns a list of XML child node changes made over corresponding `YXmlElement` collection 1282 - * within bounds of current transaction. These changes follow a format: 1283 - * 1284 - * - { insert: (YXmlText|YXmlElement)[] } 1285 - * - { delete: number } 1286 - * - { retain: number } 1287 - */ 1288 - readonly delta: any; 1289 - } 1290 - /** 1291 - * Represents a list of `YXmlElement` and `YXmlText` types. 1292 - * A `YXmlFragment` is similar to a `YXmlElement`, but it does not have a 1293 - * nodeName and it does not have attributes. Though it can be bound to a DOM 1294 - * element - in this case the attributes and the nodeName are not shared 1295 - */ 1296 - export class YXmlFragment { 1297 - free(): void; 1298 - constructor(children: any[]); 1299 - /** 1300 - * Checks if current shared type reference is alive and has not been deleted by its parent collection. 1301 - * This method only works on already integrated shared types and will return false is current 1302 - * type is preliminary (has not been integrated into document). 1303 - */ 1304 - alive(txn: YTransaction): boolean; 1305 - /** 1306 - * Returns a number of child XML nodes stored within this `YXMlElement` instance. 1307 - */ 1308 - length(txn: YTransaction | undefined): number; 1309 - insert(index: number, xml_node: any, txn: YTransaction | undefined): void; 1310 - push(xml_node: any, txn: YTransaction | undefined): void; 1311 - delete(index: number, length: number | null | undefined, txn: YTransaction | undefined): void; 1312 - /** 1313 - * Returns a first child of this XML node. 1314 - * It can be either `YXmlElement`, `YXmlText` or `undefined` if current node has not children. 1315 - */ 1316 - firstChild(txn: YTransaction | undefined): any; 1317 - /** 1318 - * Returns a string representation of this XML node. 1319 - */ 1320 - toString(txn: YTransaction | undefined): string; 1321 - /** 1322 - * Returns an iterator that enables a deep traversal of this XML node - starting from first 1323 - * child over this XML node successors using depth-first strategy. 1324 - */ 1325 - treeWalker(txn: YTransaction | undefined): Array<any>; 1326 - /** 1327 - * Subscribes to all operations happening over this instance of `YXmlFragment`. All changes are 1328 - * batched and eventually triggered during transaction commit phase. 1329 - */ 1330 - observe(callback: Function): void; 1331 - /** 1332 - * Unsubscribes a callback previously subscribed with `observe` method. 1333 - */ 1334 - unobserve(callback: Function): boolean; 1335 - /** 1336 - * Subscribes to all operations happening over this Y shared type, as well as events in 1337 - * shared types stored within this one. All changes are batched and eventually triggered 1338 - * during transaction commit phase. 1339 - */ 1340 - observeDeep(callback: Function): void; 1341 - /** 1342 - * Unsubscribes a callback previously subscribed with `observeDeep` method. 1343 - */ 1344 - unobserveDeep(callback: Function): boolean; 1345 - readonly type: number; 1346 - /** 1347 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 1348 - * document. 1349 - */ 1350 - readonly id: any; 1351 - /** 1352 - * Returns true if this is a preliminary instance of `YXmlFragment`. 1353 - * 1354 - * Preliminary instances can be nested into other shared data types. 1355 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 1356 - * document store and cannot be nested again: attempt to do so will result in an exception. 1357 - */ 1358 - readonly prelim: boolean; 1359 - } 1360 - /** 1361 - * A shared data type used for collaborative text editing, that can be used in a context of 1362 - * `YXmlElement` nodee. It enables multiple users to add and remove chunks of text in efficient 1363 - * manner. This type is internally represented as a mutable double-linked list of text chunks 1364 - * - an optimization occurs during `YTransaction.commit`, which allows to squash multiple 1365 - * consecutively inserted characters together as a single chunk of text even between transaction 1366 - * boundaries in order to preserve more efficient memory model. 1367 - * 1368 - * Just like `YXmlElement`, `YXmlText` can be marked with extra metadata in form of attributes. 1369 - * 1370 - * `YXmlText` structure internally uses UTF-8 encoding and its length is described in a number of 1371 - * bytes rather than individual characters (a single UTF-8 code point can consist of many bytes). 1372 - * 1373 - * Like all Yrs shared data types, `YXmlText` is resistant to the problem of interleaving (situation 1374 - * when characters inserted one after another may interleave with other peers concurrent inserts 1375 - * after merging all updates together). In case of Yrs conflict resolution is solved by using 1376 - * unique document id to determine correct and consistent ordering. 1377 - */ 1378 - export class YXmlText { 1379 - free(): void; 1380 - constructor(text: string | null | undefined, attributes: any); 1381 - /** 1382 - * Checks if current shared type reference is alive and has not been deleted by its parent collection. 1383 - * This method only works on already integrated shared types and will return false is current 1384 - * type is preliminary (has not been integrated into document). 1385 - */ 1386 - alive(txn: YTransaction): boolean; 1387 - /** 1388 - * Returns length of an underlying string stored in this `YXmlText` instance, 1389 - * understood as a number of UTF-8 encoded bytes. 1390 - */ 1391 - length(txn: YTransaction | undefined): number; 1392 - /** 1393 - * Inserts a given `chunk` of text into this `YXmlText` instance, starting at a given `index`. 1394 - * 1395 - * Optional object with defined `attributes` will be used to wrap provided text `chunk` 1396 - * with a formatting blocks. 1397 - */ 1398 - insert(index: number, chunk: string, attributes: any, txn: YTransaction | undefined): void; 1399 - /** 1400 - * Formats text within bounds specified by `index` and `len` with a given formatting 1401 - * attributes. 1402 - */ 1403 - format(index: number, length: number, attributes: any, txn: YTransaction | undefined): void; 1404 - quote(lower: number | null | undefined, upper: number | null | undefined, lower_open: boolean | null | undefined, upper_open: boolean | null | undefined, txn: YTransaction | undefined): YWeakLink; 1405 - /** 1406 - * Returns the Delta representation of this YXmlText type. 1407 - */ 1408 - toDelta(snapshot: any, prev_snapshot: any, compute_ychange: Function | null | undefined, txn: YTransaction | undefined): Array<any>; 1409 - /** 1410 - * Inserts a given `embed` object into this `YXmlText` instance, starting at a given `index`. 1411 - * 1412 - * Optional object with defined `attributes` will be used to wrap provided `embed` 1413 - * with a formatting blocks.`attributes` are only supported for a `YXmlText` instance which 1414 - * already has been integrated into document store. 1415 - */ 1416 - insertEmbed(index: number, embed: any, attributes: any, txn: YTransaction | undefined): void; 1417 - /** 1418 - * Appends a given `chunk` of text at the end of `YXmlText` instance. 1419 - * 1420 - * Optional object with defined `attributes` will be used to wrap provided text `chunk` 1421 - * with a formatting blocks. 1422 - */ 1423 - push(chunk: string, attributes: any, txn: YTransaction | undefined): void; 1424 - applyDelta(delta: Array<any>, txn: YTransaction | undefined): void; 1425 - /** 1426 - * Deletes a specified range of characters, starting at a given `index`. 1427 - * Both `index` and `length` are counted in terms of a number of UTF-8 character bytes. 1428 - */ 1429 - delete(index: number, length: number, txn: YTransaction | undefined): void; 1430 - /** 1431 - * Returns a next XML sibling node of this XMl node. 1432 - * It can be either `YXmlElement`, `YXmlText` or `undefined` if current node is a last child of 1433 - * parent XML node. 1434 - */ 1435 - nextSibling(txn: YTransaction | undefined): any; 1436 - /** 1437 - * Returns a previous XML sibling node of this XMl node. 1438 - * It can be either `YXmlElement`, `YXmlText` or `undefined` if current node is a first child 1439 - * of parent XML node. 1440 - */ 1441 - prevSibling(txn: YTransaction | undefined): any; 1442 - /** 1443 - * Returns a parent `YXmlElement` node or `undefined` if current node has no parent assigned. 1444 - */ 1445 - parent(txn: YTransaction | undefined): any; 1446 - /** 1447 - * Returns an underlying string stored in this `YXmlText` instance. 1448 - */ 1449 - toString(txn: YTransaction | undefined): string; 1450 - /** 1451 - * Sets a `name` and `value` as new attribute for this XML node. If an attribute with the same 1452 - * `name` already existed on that node, its value with be overridden with a provided one. 1453 - * This method accepts any JavaScript value, not just strings. 1454 - */ 1455 - setAttribute(name: string, value: any, txn: YTransaction | undefined): void; 1456 - /** 1457 - * Returns a value of an attribute given its `name` as any JS value. If no attribute with such name existed, 1458 - * `undefined` will be returned. 1459 - */ 1460 - getAttribute(name: string, txn: YTransaction | undefined): any; 1461 - /** 1462 - * Removes an attribute from this XML node, given its `name`. 1463 - */ 1464 - removeAttribute(name: string, txn: YTransaction | undefined): void; 1465 - /** 1466 - * Returns an iterator that enables to traverse over all attributes of this XML node in 1467 - * unspecified order. This method returns attribute values as their original JS values, 1468 - * not just as strings. 1469 - */ 1470 - attributes(txn: YTransaction | undefined): any; 1471 - /** 1472 - * Subscribes to all operations happening over this instance of `YXmlText`. All changes are 1473 - * batched and eventually triggered during transaction commit phase. 1474 - */ 1475 - observe(callback: Function): void; 1476 - /** 1477 - * Unsubscribes a callback previously subscribed with `observe` method. 1478 - */ 1479 - unobserve(callback: Function): boolean; 1480 - /** 1481 - * Subscribes to all operations happening over this Y shared type, as well as events in 1482 - * shared types stored within this one. All changes are batched and eventually triggered 1483 - * during transaction commit phase. 1484 - */ 1485 - observeDeep(callback: Function): void; 1486 - /** 1487 - * Unsubscribes a callback previously subscribed with `observe` method. 1488 - */ 1489 - unobserveDeep(callback: Function): boolean; 1490 - readonly type: number; 1491 - /** 1492 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 1493 - * document. 1494 - */ 1495 - readonly id: any; 1496 - /** 1497 - * Returns true if this is a preliminary instance of `YXmlText`. 1498 - * 1499 - * Preliminary instances can be nested into other shared data types. 1500 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 1501 - * document store and cannot be nested again: attempt to do so will result in an exception. 1502 - */ 1503 - readonly prelim: boolean; 1504 - } 1505 - /** 1506 - * Event generated by `YXmlText.observe` method. Emitted during transaction commit phase. 1507 - */ 1508 - export class YXmlTextEvent { 1509 - private constructor(); 1510 - free(): void; 1511 - /** 1512 - * Returns an array of keys and indexes creating a path from root type down to current instance 1513 - * of shared type (accessible via `target` getter). 1514 - */ 1515 - path(): any; 1516 - /** 1517 - * Returns a current shared type instance, that current event changes refer to. 1518 - */ 1519 - readonly target: any; 1520 - readonly origin: any; 1521 - /** 1522 - * Returns a list of text changes made over corresponding `YText` collection within 1523 - * bounds of current transaction. These changes follow a format: 1524 - * 1525 - * - { insert: string, attributes: any|undefined } 1526 - * - { delete: number } 1527 - * - { retain: number, attributes: any|undefined } 1528 - */ 1529 - readonly delta: any; 1530 - /** 1531 - * Returns a list of attribute changes made over corresponding `YXmlText` collection within 1532 - * bounds of current transaction. These changes follow a format: 1533 - * 1534 - * - { action: 'add'|'update'|'delete', oldValue: string|undefined, newValue: string|undefined } 1535 - */ 1536 - readonly keys: any; 1537 - }
-5022
src/ywasm/ywasm.js
··· 1 - let imports = {}; 2 - imports["__wbindgen_placeholder__"] = module.exports; 3 - let wasm; 4 - const { TextDecoder, TextEncoder } = require(`util`); 5 - 6 - function addToExternrefTable0(obj) { 7 - const idx = wasm.__externref_table_alloc(); 8 - wasm.__wbindgen_export_2.set(idx, obj); 9 - return idx; 10 - } 11 - 12 - function handleError(f, args) { 13 - try { 14 - return f.apply(this, args); 15 - } catch (e) { 16 - const idx = addToExternrefTable0(e); 17 - wasm.__wbindgen_exn_store(idx); 18 - } 19 - } 20 - 21 - let cachedTextDecoder = new TextDecoder("utf-8", { 22 - ignoreBOM: true, 23 - fatal: true, 24 - }); 25 - 26 - cachedTextDecoder.decode(); 27 - 28 - let cachedUint8ArrayMemory0 = null; 29 - 30 - function getUint8ArrayMemory0() { 31 - if ( 32 - cachedUint8ArrayMemory0 === null || 33 - cachedUint8ArrayMemory0.byteLength === 0 34 - ) { 35 - cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); 36 - } 37 - return cachedUint8ArrayMemory0; 38 - } 39 - 40 - function getStringFromWasm0(ptr, len) { 41 - ptr = ptr >>> 0; 42 - return cachedTextDecoder.decode( 43 - getUint8ArrayMemory0().subarray(ptr, ptr + len), 44 - ); 45 - } 46 - 47 - let WASM_VECTOR_LEN = 0; 48 - 49 - let cachedTextEncoder = new TextEncoder("utf-8"); 50 - 51 - const encodeString = 52 - typeof cachedTextEncoder.encodeInto === "function" 53 - ? function (arg, view) { 54 - return cachedTextEncoder.encodeInto(arg, view); 55 - } 56 - : function (arg, view) { 57 - const buf = cachedTextEncoder.encode(arg); 58 - view.set(buf); 59 - return { 60 - read: arg.length, 61 - written: buf.length, 62 - }; 63 - }; 64 - 65 - function passStringToWasm0(arg, malloc, realloc) { 66 - if (realloc === undefined) { 67 - const buf = cachedTextEncoder.encode(arg); 68 - const ptr = malloc(buf.length, 1) >>> 0; 69 - getUint8ArrayMemory0() 70 - .subarray(ptr, ptr + buf.length) 71 - .set(buf); 72 - WASM_VECTOR_LEN = buf.length; 73 - return ptr; 74 - } 75 - 76 - let len = arg.length; 77 - let ptr = malloc(len, 1) >>> 0; 78 - 79 - const mem = getUint8ArrayMemory0(); 80 - 81 - let offset = 0; 82 - 83 - for (; offset < len; offset++) { 84 - const code = arg.charCodeAt(offset); 85 - if (code > 0x7f) break; 86 - mem[ptr + offset] = code; 87 - } 88 - 89 - if (offset !== len) { 90 - if (offset !== 0) { 91 - arg = arg.slice(offset); 92 - } 93 - ptr = realloc(ptr, len, (len = offset + arg.length * 3), 1) >>> 0; 94 - const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); 95 - const ret = encodeString(arg, view); 96 - 97 - offset += ret.written; 98 - ptr = realloc(ptr, len, offset, 1) >>> 0; 99 - } 100 - 101 - WASM_VECTOR_LEN = offset; 102 - return ptr; 103 - } 104 - 105 - let cachedDataViewMemory0 = null; 106 - 107 - function getDataViewMemory0() { 108 - if ( 109 - cachedDataViewMemory0 === null || 110 - cachedDataViewMemory0.buffer.detached === true || 111 - (cachedDataViewMemory0.buffer.detached === undefined && 112 - cachedDataViewMemory0.buffer !== wasm.memory.buffer) 113 - ) { 114 - cachedDataViewMemory0 = new DataView(wasm.memory.buffer); 115 - } 116 - return cachedDataViewMemory0; 117 - } 118 - 119 - function isLikeNone(x) { 120 - return x === undefined || x === null; 121 - } 122 - 123 - function debugString(val) { 124 - // primitive types 125 - const type = typeof val; 126 - if (type == "number" || type == "boolean" || val == null) { 127 - return `${val}`; 128 - } 129 - if (type == "string") { 130 - return `"${val}"`; 131 - } 132 - if (type == "symbol") { 133 - const description = val.description; 134 - if (description == null) { 135 - return "Symbol"; 136 - } else { 137 - return `Symbol(${description})`; 138 - } 139 - } 140 - if (type == "function") { 141 - const name = val.name; 142 - if (typeof name == "string" && name.length > 0) { 143 - return `Function(${name})`; 144 - } else { 145 - return "Function"; 146 - } 147 - } 148 - // objects 149 - if (Array.isArray(val)) { 150 - const length = val.length; 151 - let debug = "["; 152 - if (length > 0) { 153 - debug += debugString(val[0]); 154 - } 155 - for (let i = 1; i < length; i++) { 156 - debug += ", " + debugString(val[i]); 157 - } 158 - debug += "]"; 159 - return debug; 160 - } 161 - // Test for built-in 162 - const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); 163 - let className; 164 - if (builtInMatches && builtInMatches.length > 1) { 165 - className = builtInMatches[1]; 166 - } else { 167 - // Failed to match the standard '[object ClassName]' 168 - return toString.call(val); 169 - } 170 - if (className == "Object") { 171 - // we're a user defined class or Object 172 - // JSON.stringify avoids problems with cycles, and is generally much 173 - // easier than looping through ownProperties of `val`. 174 - try { 175 - return "Object(" + JSON.stringify(val) + ")"; 176 - } catch (_) { 177 - return "Object"; 178 - } 179 - } 180 - // errors 181 - if (val instanceof Error) { 182 - return `${val.name}: ${val.message}\n${val.stack}`; 183 - } 184 - // TODO we could test for more things here, like `Set`s and `Map`s. 185 - return className; 186 - } 187 - 188 - function takeFromExternrefTable0(idx) { 189 - const value = wasm.__wbindgen_export_2.get(idx); 190 - wasm.__externref_table_dealloc(idx); 191 - return value; 192 - } 193 - 194 - function _assertClass(instance, klass) { 195 - if (!(instance instanceof klass)) { 196 - throw new Error(`expected instance of ${klass.name}`); 197 - } 198 - } 199 - 200 - function passArrayJsValueToWasm0(array, malloc) { 201 - const ptr = malloc(array.length * 4, 4) >>> 0; 202 - for (let i = 0; i < array.length; i++) { 203 - const add = addToExternrefTable0(array[i]); 204 - getDataViewMemory0().setUint32(ptr + 4 * i, add, true); 205 - } 206 - WASM_VECTOR_LEN = array.length; 207 - return ptr; 208 - } 209 - /** 210 - * When called will call console log errors whenever internal panic is called from within 211 - * WebAssembly module. 212 - */ 213 - module.exports.setPanicHook = function () { 214 - wasm.setPanicHook(); 215 - }; 216 - 217 - /** 218 - * Encodes a state vector of a given ywasm document into its binary representation using lib0 v1 219 - * encoding. State vector is a compact representation of updates performed on a given document and 220 - * can be used by `encode_state_as_update` on remote peer to generate a delta update payload to 221 - * synchronize changes between peers. 222 - * 223 - * Example: 224 - * 225 - * ```javascript 226 - * import {YDoc, encodeStateVector, encodeStateAsUpdate, applyUpdate} from 'ywasm' 227 - * 228 - * /// document on machine A 229 - * const localDoc = new YDoc() 230 - * const localSV = encodeStateVector(localDoc) 231 - * 232 - * // document on machine B 233 - * const remoteDoc = new YDoc() 234 - * const remoteDelta = encodeStateAsUpdate(remoteDoc, localSV) 235 - * 236 - * applyUpdate(localDoc, remoteDelta) 237 - * ``` 238 - * @param {YDoc} doc 239 - * @returns {Uint8Array} 240 - */ 241 - module.exports.encodeStateVector = function (doc) { 242 - _assertClass(doc, YDoc); 243 - const ret = wasm.encodeStateVector(doc.__wbg_ptr); 244 - if (ret[2]) { 245 - throw takeFromExternrefTable0(ret[1]); 246 - } 247 - return takeFromExternrefTable0(ret[0]); 248 - }; 249 - 250 - /** 251 - * Returns a string dump representation of a given `update` encoded using lib0 v1 encoding. 252 - * @param {Uint8Array} update 253 - * @returns {string} 254 - */ 255 - module.exports.debugUpdateV1 = function (update) { 256 - let deferred2_0; 257 - let deferred2_1; 258 - try { 259 - const ret = wasm.debugUpdateV1(update); 260 - var ptr1 = ret[0]; 261 - var len1 = ret[1]; 262 - if (ret[3]) { 263 - ptr1 = 0; 264 - len1 = 0; 265 - throw takeFromExternrefTable0(ret[2]); 266 - } 267 - deferred2_0 = ptr1; 268 - deferred2_1 = len1; 269 - return getStringFromWasm0(ptr1, len1); 270 - } finally { 271 - wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); 272 - } 273 - }; 274 - 275 - /** 276 - * Returns a string dump representation of a given `update` encoded using lib0 v2 encoding. 277 - * @param {Uint8Array} update 278 - * @returns {string} 279 - */ 280 - module.exports.debugUpdateV2 = function (update) { 281 - let deferred2_0; 282 - let deferred2_1; 283 - try { 284 - const ret = wasm.debugUpdateV2(update); 285 - var ptr1 = ret[0]; 286 - var len1 = ret[1]; 287 - if (ret[3]) { 288 - ptr1 = 0; 289 - len1 = 0; 290 - throw takeFromExternrefTable0(ret[2]); 291 - } 292 - deferred2_0 = ptr1; 293 - deferred2_1 = len1; 294 - return getStringFromWasm0(ptr1, len1); 295 - } finally { 296 - wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); 297 - } 298 - }; 299 - 300 - /** 301 - * Merges a sequence of updates (encoded using lib0 v1 encoding) together, producing another 302 - * update (also lib0 v1 encoded) in the result. Returned binary is a combination of all input 303 - * `updates`, compressed. 304 - * 305 - * Returns an error whenever any of the input updates couldn't be decoded. 306 - * @param {Array<any>} updates 307 - * @returns {Uint8Array} 308 - */ 309 - module.exports.mergeUpdatesV1 = function (updates) { 310 - const ret = wasm.mergeUpdatesV1(updates); 311 - if (ret[2]) { 312 - throw takeFromExternrefTable0(ret[1]); 313 - } 314 - return takeFromExternrefTable0(ret[0]); 315 - }; 316 - 317 - /** 318 - * Merges a sequence of updates (encoded using lib0 v2 encoding) together, producing another 319 - * update (also lib0 v2 encoded) in the result. Returned binary is a combination of all input 320 - * `updates`, compressed. 321 - * 322 - * Returns an error whenever any of the input updates couldn't be decoded. 323 - * @param {Array<any>} updates 324 - * @returns {Uint8Array} 325 - */ 326 - module.exports.mergeUpdatesV2 = function (updates) { 327 - const ret = wasm.mergeUpdatesV2(updates); 328 - if (ret[2]) { 329 - throw takeFromExternrefTable0(ret[1]); 330 - } 331 - return takeFromExternrefTable0(ret[0]); 332 - }; 333 - 334 - /** 335 - * Encodes all updates that have happened since a given version `vector` into a compact delta 336 - * representation using lib0 v1 encoding. If `vector` parameter has not been provided, generated 337 - * delta payload will contain all changes of a current ywasm document, working effectivelly as its 338 - * state snapshot. 339 - * 340 - * Example: 341 - * 342 - * ```javascript 343 - * import {YDoc, encodeStateVector, encodeStateAsUpdate, applyUpdate} from 'ywasm' 344 - * 345 - * /// document on machine A 346 - * const localDoc = new YDoc() 347 - * const localSV = encodeStateVector(localDoc) 348 - * 349 - * // document on machine B 350 - * const remoteDoc = new YDoc() 351 - * const remoteDelta = encodeStateAsUpdate(remoteDoc, localSV) 352 - * 353 - * applyUpdate(localDoc, remoteDelta) 354 - * ``` 355 - * @param {YDoc} doc 356 - * @param {Uint8Array | null} [vector] 357 - * @returns {Uint8Array} 358 - */ 359 - module.exports.encodeStateAsUpdate = function (doc, vector) { 360 - _assertClass(doc, YDoc); 361 - const ret = wasm.encodeStateAsUpdate( 362 - doc.__wbg_ptr, 363 - isLikeNone(vector) ? 0 : addToExternrefTable0(vector), 364 - ); 365 - if (ret[2]) { 366 - throw takeFromExternrefTable0(ret[1]); 367 - } 368 - return takeFromExternrefTable0(ret[0]); 369 - }; 370 - 371 - /** 372 - * Encodes all updates that have happened since a given version `vector` into a compact delta 373 - * representation using lib0 v2 encoding. If `vector` parameter has not been provided, generated 374 - * delta payload will contain all changes of a current ywasm document, working effectivelly as its 375 - * state snapshot. 376 - * 377 - * Example: 378 - * 379 - * ```javascript 380 - * import {YDoc, encodeStateVector, encodeStateAsUpdate, applyUpdate} from 'ywasm' 381 - * 382 - * /// document on machine A 383 - * const localDoc = new YDoc() 384 - * const localSV = encodeStateVector(localDoc) 385 - * 386 - * // document on machine B 387 - * const remoteDoc = new YDoc() 388 - * const remoteDelta = encodeStateAsUpdateV2(remoteDoc, localSV) 389 - * 390 - * applyUpdate(localDoc, remoteDelta) 391 - * ``` 392 - * @param {YDoc} doc 393 - * @param {Uint8Array | null} [vector] 394 - * @returns {Uint8Array} 395 - */ 396 - module.exports.encodeStateAsUpdateV2 = function (doc, vector) { 397 - _assertClass(doc, YDoc); 398 - const ret = wasm.encodeStateAsUpdateV2( 399 - doc.__wbg_ptr, 400 - isLikeNone(vector) ? 0 : addToExternrefTable0(vector), 401 - ); 402 - if (ret[2]) { 403 - throw takeFromExternrefTable0(ret[1]); 404 - } 405 - return takeFromExternrefTable0(ret[0]); 406 - }; 407 - 408 - /** 409 - * Applies delta update generated by the remote document replica to a current document. This 410 - * method assumes that a payload maintains lib0 v1 encoding format. 411 - * 412 - * Example: 413 - * 414 - * ```javascript 415 - * import {YDoc, encodeStateVector, encodeStateAsUpdate, applyUpdate} from 'ywasm' 416 - * 417 - * /// document on machine A 418 - * const localDoc = new YDoc() 419 - * const localSV = encodeStateVector(localDoc) 420 - * 421 - * // document on machine B 422 - * const remoteDoc = new YDoc() 423 - * const remoteDelta = encodeStateAsUpdate(remoteDoc, localSV) 424 - * 425 - * applyUpdateV2(localDoc, remoteDelta) 426 - * ``` 427 - * @param {YDoc} doc 428 - * @param {Uint8Array} update 429 - * @param {any} origin 430 - */ 431 - module.exports.applyUpdate = function (doc, update, origin) { 432 - _assertClass(doc, YDoc); 433 - const ret = wasm.applyUpdate(doc.__wbg_ptr, update, origin); 434 - if (ret[1]) { 435 - throw takeFromExternrefTable0(ret[0]); 436 - } 437 - }; 438 - 439 - /** 440 - * Applies delta update generated by the remote document replica to a current document. This 441 - * method assumes that a payload maintains lib0 v2 encoding format. 442 - * 443 - * Example: 444 - * 445 - * ```javascript 446 - * import {YDoc, encodeStateVector, encodeStateAsUpdate, applyUpdate} from 'ywasm' 447 - * 448 - * /// document on machine A 449 - * const localDoc = new YDoc() 450 - * const localSV = encodeStateVector(localDoc) 451 - * 452 - * // document on machine B 453 - * const remoteDoc = new YDoc() 454 - * const remoteDelta = encodeStateAsUpdateV2(remoteDoc, localSV) 455 - * 456 - * applyUpdateV2(localDoc, remoteDelta) 457 - * ``` 458 - * @param {YDoc} doc 459 - * @param {Uint8Array} update 460 - * @param {any} origin 461 - */ 462 - module.exports.applyUpdateV2 = function (doc, update, origin) { 463 - _assertClass(doc, YDoc); 464 - const ret = wasm.applyUpdateV2(doc.__wbg_ptr, update, origin); 465 - if (ret[1]) { 466 - throw takeFromExternrefTable0(ret[0]); 467 - } 468 - }; 469 - 470 - /** 471 - * @param {YDoc} doc 472 - * @returns {any} 473 - */ 474 - module.exports.snapshot = function (doc) { 475 - _assertClass(doc, YDoc); 476 - const ret = wasm.snapshot(doc.__wbg_ptr); 477 - if (ret[2]) { 478 - throw takeFromExternrefTable0(ret[1]); 479 - } 480 - return takeFromExternrefTable0(ret[0]); 481 - }; 482 - 483 - /** 484 - * @param {any} snap1 485 - * @param {any} snap2 486 - * @returns {boolean} 487 - */ 488 - module.exports.equalSnapshots = function (snap1, snap2) { 489 - const ret = wasm.equalSnapshots(snap1, snap2); 490 - return ret !== 0; 491 - }; 492 - 493 - function getArrayU8FromWasm0(ptr, len) { 494 - ptr = ptr >>> 0; 495 - return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len); 496 - } 497 - /** 498 - * @param {any} snapshot 499 - * @returns {Uint8Array} 500 - */ 501 - module.exports.encodeSnapshotV1 = function (snapshot) { 502 - const ret = wasm.encodeSnapshotV1(snapshot); 503 - var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); 504 - wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); 505 - return v1; 506 - }; 507 - 508 - /** 509 - * @param {any} snapshot 510 - * @returns {Uint8Array} 511 - */ 512 - module.exports.encodeSnapshotV2 = function (snapshot) { 513 - const ret = wasm.encodeSnapshotV2(snapshot); 514 - var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); 515 - wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); 516 - return v1; 517 - }; 518 - 519 - function passArray8ToWasm0(arg, malloc) { 520 - const ptr = malloc(arg.length * 1, 1) >>> 0; 521 - getUint8ArrayMemory0().set(arg, ptr / 1); 522 - WASM_VECTOR_LEN = arg.length; 523 - return ptr; 524 - } 525 - /** 526 - * @param {Uint8Array} snapshot 527 - * @returns {any} 528 - */ 529 - module.exports.decodeSnapshotV2 = function (snapshot) { 530 - const ptr0 = passArray8ToWasm0(snapshot, wasm.__wbindgen_malloc); 531 - const len0 = WASM_VECTOR_LEN; 532 - const ret = wasm.decodeSnapshotV2(ptr0, len0); 533 - if (ret[2]) { 534 - throw takeFromExternrefTable0(ret[1]); 535 - } 536 - return takeFromExternrefTable0(ret[0]); 537 - }; 538 - 539 - /** 540 - * @param {Uint8Array} snapshot 541 - * @returns {any} 542 - */ 543 - module.exports.decodeSnapshotV1 = function (snapshot) { 544 - const ptr0 = passArray8ToWasm0(snapshot, wasm.__wbindgen_malloc); 545 - const len0 = WASM_VECTOR_LEN; 546 - const ret = wasm.decodeSnapshotV1(ptr0, len0); 547 - if (ret[2]) { 548 - throw takeFromExternrefTable0(ret[1]); 549 - } 550 - return takeFromExternrefTable0(ret[0]); 551 - }; 552 - 553 - /** 554 - * @param {YDoc} doc 555 - * @param {any} snapshot 556 - * @returns {Uint8Array} 557 - */ 558 - module.exports.encodeStateFromSnapshotV1 = function (doc, snapshot) { 559 - _assertClass(doc, YDoc); 560 - const ret = wasm.encodeStateFromSnapshotV1(doc.__wbg_ptr, snapshot); 561 - if (ret[3]) { 562 - throw takeFromExternrefTable0(ret[2]); 563 - } 564 - var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); 565 - wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); 566 - return v1; 567 - }; 568 - 569 - /** 570 - * @param {YDoc} doc 571 - * @param {any} snapshot 572 - * @returns {Uint8Array} 573 - */ 574 - module.exports.encodeStateFromSnapshotV2 = function (doc, snapshot) { 575 - _assertClass(doc, YDoc); 576 - const ret = wasm.encodeStateFromSnapshotV2(doc.__wbg_ptr, snapshot); 577 - if (ret[3]) { 578 - throw takeFromExternrefTable0(ret[2]); 579 - } 580 - var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); 581 - wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); 582 - return v1; 583 - }; 584 - 585 - /** 586 - * Retrieves a sticky index corresponding to a given human-readable `index` pointing into 587 - * the shared `ytype`. Unlike standard indexes sticky indexes enables to track 588 - * the location inside of a shared y-types, even in the face of concurrent updates. 589 - * 590 - * If association is >= 0, the resulting position will point to location **after** the referenced index. 591 - * If association is < 0, the resulting position will point to location **before** the referenced index. 592 - * @param {any} ytype 593 - * @param {number} index 594 - * @param {number} assoc 595 - * @param {YTransaction | undefined} txn 596 - * @returns {any} 597 - */ 598 - module.exports.createRelativePositionFromTypeIndex = function ( 599 - ytype, 600 - index, 601 - assoc, 602 - txn, 603 - ) { 604 - const ret = wasm.createRelativePositionFromTypeIndex( 605 - ytype, 606 - index, 607 - assoc, 608 - txn, 609 - ); 610 - if (ret[2]) { 611 - throw takeFromExternrefTable0(ret[1]); 612 - } 613 - return takeFromExternrefTable0(ret[0]); 614 - }; 615 - 616 - /** 617 - * Converts a sticky index (see: `createStickyIndexFromType`) into an object 618 - * containing human-readable index. 619 - * @param {any} rpos 620 - * @param {YDoc} doc 621 - * @returns {any} 622 - */ 623 - module.exports.createAbsolutePositionFromRelativePosition = function ( 624 - rpos, 625 - doc, 626 - ) { 627 - _assertClass(doc, YDoc); 628 - const ret = wasm.createAbsolutePositionFromRelativePosition( 629 - rpos, 630 - doc.__wbg_ptr, 631 - ); 632 - if (ret[2]) { 633 - throw takeFromExternrefTable0(ret[1]); 634 - } 635 - return takeFromExternrefTable0(ret[0]); 636 - }; 637 - 638 - /** 639 - * Serializes sticky index created by `createStickyIndexFromType` into a binary 640 - * payload. 641 - * @param {any} rpos 642 - * @returns {Uint8Array} 643 - */ 644 - module.exports.encodeRelativePosition = function (rpos) { 645 - const ret = wasm.encodeRelativePosition(rpos); 646 - if (ret[2]) { 647 - throw takeFromExternrefTable0(ret[1]); 648 - } 649 - return takeFromExternrefTable0(ret[0]); 650 - }; 651 - 652 - /** 653 - * Deserializes sticky index serialized previously by `encodeStickyIndex`. 654 - * @param {Uint8Array} bin 655 - * @returns {any} 656 - */ 657 - module.exports.decodeRelativePosition = function (bin) { 658 - const ret = wasm.decodeRelativePosition(bin); 659 - if (ret[2]) { 660 - throw takeFromExternrefTable0(ret[1]); 661 - } 662 - return takeFromExternrefTable0(ret[0]); 663 - }; 664 - 665 - /** 666 - * @param {any} a 667 - * @param {any} b 668 - * @returns {boolean} 669 - */ 670 - module.exports.compareRelativePositions = function (a, b) { 671 - const ret = wasm.compareRelativePositions(a, b); 672 - return ret !== 0; 673 - }; 674 - 675 - let cachedBigUint64ArrayMemory0 = null; 676 - 677 - function getBigUint64ArrayMemory0() { 678 - if ( 679 - cachedBigUint64ArrayMemory0 === null || 680 - cachedBigUint64ArrayMemory0.byteLength === 0 681 - ) { 682 - cachedBigUint64ArrayMemory0 = new BigUint64Array(wasm.memory.buffer); 683 - } 684 - return cachedBigUint64ArrayMemory0; 685 - } 686 - 687 - function passArray64ToWasm0(arg, malloc) { 688 - const ptr = malloc(arg.length * 8, 8) >>> 0; 689 - getBigUint64ArrayMemory0().set(arg, ptr / 8); 690 - WASM_VECTOR_LEN = arg.length; 691 - return ptr; 692 - } 693 - /** 694 - * @param {Awareness} awareness 695 - * @param {BigUint64Array} clients 696 - */ 697 - module.exports.removeAwarenessStates = function (awareness, clients) { 698 - _assertClass(awareness, Awareness); 699 - const ptr0 = passArray64ToWasm0(clients, wasm.__wbindgen_malloc); 700 - const len0 = WASM_VECTOR_LEN; 701 - const ret = wasm.removeAwarenessStates(awareness.__wbg_ptr, ptr0, len0); 702 - if (ret[1]) { 703 - throw takeFromExternrefTable0(ret[0]); 704 - } 705 - }; 706 - 707 - /** 708 - * @param {Awareness} awareness 709 - * @param {any} clients 710 - * @returns {Uint8Array} 711 - */ 712 - module.exports.encodeAwarenessUpdate = function (awareness, clients) { 713 - _assertClass(awareness, Awareness); 714 - const ret = wasm.encodeAwarenessUpdate(awareness.__wbg_ptr, clients); 715 - if (ret[2]) { 716 - throw takeFromExternrefTable0(ret[1]); 717 - } 718 - return takeFromExternrefTable0(ret[0]); 719 - }; 720 - 721 - /** 722 - * @param {Uint8Array} update 723 - * @param {Function} modify 724 - * @returns {Uint8Array} 725 - */ 726 - module.exports.modifyAwarenessUpdate = function (update, modify) { 727 - const ret = wasm.modifyAwarenessUpdate(update, modify); 728 - if (ret[2]) { 729 - throw takeFromExternrefTable0(ret[1]); 730 - } 731 - return takeFromExternrefTable0(ret[0]); 732 - }; 733 - 734 - /** 735 - * @param {Awareness} awareness 736 - * @param {Uint8Array} update 737 - * @param {any} _origin 738 - */ 739 - module.exports.applyAwarenessUpdate = function (awareness, update, _origin) { 740 - _assertClass(awareness, Awareness); 741 - const ret = wasm.applyAwarenessUpdate(awareness.__wbg_ptr, update, _origin); 742 - if (ret[1]) { 743 - throw takeFromExternrefTable0(ret[0]); 744 - } 745 - }; 746 - 747 - const AwarenessFinalization = 748 - typeof FinalizationRegistry === "undefined" 749 - ? { register: () => {}, unregister: () => {} } 750 - : new FinalizationRegistry((ptr) => 751 - wasm.__wbg_awareness_free(ptr >>> 0, 1), 752 - ); 753 - 754 - class Awareness { 755 - __destroy_into_raw() { 756 - const ptr = this.__wbg_ptr; 757 - this.__wbg_ptr = 0; 758 - AwarenessFinalization.unregister(this); 759 - return ptr; 760 - } 761 - 762 - free() { 763 - const ptr = this.__destroy_into_raw(); 764 - wasm.__wbg_awareness_free(ptr, 0); 765 - } 766 - /** 767 - * @param {YDoc} doc 768 - */ 769 - constructor(doc) { 770 - _assertClass(doc, YDoc); 771 - var ptr0 = doc.__destroy_into_raw(); 772 - const ret = wasm.awareness_new(ptr0); 773 - this.__wbg_ptr = ret >>> 0; 774 - AwarenessFinalization.register(this, this.__wbg_ptr, this); 775 - return this; 776 - } 777 - /** 778 - * @returns {YDoc} 779 - */ 780 - get doc() { 781 - const ret = wasm.awareness_doc(this.__wbg_ptr); 782 - return YDoc.__wrap(ret); 783 - } 784 - /** 785 - * @returns {Map<any, any>} 786 - */ 787 - get meta() { 788 - const ret = wasm.awareness_meta(this.__wbg_ptr); 789 - if (ret[2]) { 790 - throw takeFromExternrefTable0(ret[1]); 791 - } 792 - return takeFromExternrefTable0(ret[0]); 793 - } 794 - destroy() { 795 - wasm.awareness_destroy(this.__wbg_ptr); 796 - } 797 - /** 798 - * @returns {any} 799 - */ 800 - getLocalState() { 801 - const ret = wasm.awareness_getLocalState(this.__wbg_ptr); 802 - if (ret[2]) { 803 - throw takeFromExternrefTable0(ret[1]); 804 - } 805 - return takeFromExternrefTable0(ret[0]); 806 - } 807 - /** 808 - * @param {any} state 809 - */ 810 - setLocalState(state) { 811 - const ret = wasm.awareness_setLocalState(this.__wbg_ptr, state); 812 - if (ret[1]) { 813 - throw takeFromExternrefTable0(ret[0]); 814 - } 815 - } 816 - /** 817 - * @param {string} key 818 - * @param {any} value 819 - */ 820 - setLocalStateField(key, value) { 821 - const ptr0 = passStringToWasm0( 822 - key, 823 - wasm.__wbindgen_malloc, 824 - wasm.__wbindgen_realloc, 825 - ); 826 - const len0 = WASM_VECTOR_LEN; 827 - const ret = wasm.awareness_setLocalStateField( 828 - this.__wbg_ptr, 829 - ptr0, 830 - len0, 831 - value, 832 - ); 833 - if (ret[1]) { 834 - throw takeFromExternrefTable0(ret[0]); 835 - } 836 - } 837 - /** 838 - * @returns {Map<any, any>} 839 - */ 840 - getStates() { 841 - const ret = wasm.awareness_getStates(this.__wbg_ptr); 842 - if (ret[2]) { 843 - throw takeFromExternrefTable0(ret[1]); 844 - } 845 - return takeFromExternrefTable0(ret[0]); 846 - } 847 - /** 848 - * @param {string} event 849 - * @param {Function} callback 850 - */ 851 - on(event, callback) { 852 - const ptr0 = passStringToWasm0( 853 - event, 854 - wasm.__wbindgen_malloc, 855 - wasm.__wbindgen_realloc, 856 - ); 857 - const len0 = WASM_VECTOR_LEN; 858 - const ret = wasm.awareness_on(this.__wbg_ptr, ptr0, len0, callback); 859 - if (ret[1]) { 860 - throw takeFromExternrefTable0(ret[0]); 861 - } 862 - } 863 - /** 864 - * @param {string} event 865 - * @param {Function} callback 866 - * @returns {boolean} 867 - */ 868 - off(event, callback) { 869 - const ptr0 = passStringToWasm0( 870 - event, 871 - wasm.__wbindgen_malloc, 872 - wasm.__wbindgen_realloc, 873 - ); 874 - const len0 = WASM_VECTOR_LEN; 875 - const ret = wasm.awareness_off(this.__wbg_ptr, ptr0, len0, callback); 876 - if (ret[2]) { 877 - throw takeFromExternrefTable0(ret[1]); 878 - } 879 - return ret[0] !== 0; 880 - } 881 - } 882 - module.exports.Awareness = Awareness; 883 - 884 - const YArrayFinalization = 885 - typeof FinalizationRegistry === "undefined" 886 - ? { register: () => {}, unregister: () => {} } 887 - : new FinalizationRegistry((ptr) => wasm.__wbg_yarray_free(ptr >>> 0, 1)); 888 - /** 889 - * A collection used to store data in an indexed sequence structure. This type is internally 890 - * implemented as a double linked list, which may squash values inserted directly one after another 891 - * into single list node upon transaction commit. 892 - * 893 - * Reading a root-level type as an YArray means treating its sequence components as a list, where 894 - * every countable element becomes an individual entity: 895 - * 896 - * - JSON-like primitives (booleans, numbers, strings, JSON maps, arrays etc.) are counted 897 - * individually. 898 - * - Text chunks inserted by [Text] data structure: each character becomes an element of an 899 - * array. 900 - * - Embedded and binary values: they count as a single element even though they correspond of 901 - * multiple bytes. 902 - * 903 - * Like all Yrs shared data types, YArray is resistant to the problem of interleaving (situation 904 - * when elements inserted one after another may interleave with other peers concurrent inserts 905 - * after merging all updates together). In case of Yrs conflict resolution is solved by using 906 - * unique document id to determine correct and consistent ordering. 907 - */ 908 - class YArray { 909 - static __wrap(ptr) { 910 - ptr = ptr >>> 0; 911 - const obj = Object.create(YArray.prototype); 912 - obj.__wbg_ptr = ptr; 913 - YArrayFinalization.register(obj, obj.__wbg_ptr, obj); 914 - return obj; 915 - } 916 - 917 - __destroy_into_raw() { 918 - const ptr = this.__wbg_ptr; 919 - this.__wbg_ptr = 0; 920 - YArrayFinalization.unregister(this); 921 - return ptr; 922 - } 923 - 924 - free() { 925 - const ptr = this.__destroy_into_raw(); 926 - wasm.__wbg_yarray_free(ptr, 0); 927 - } 928 - /** 929 - * Creates a new preliminary instance of a `YArray` shared data type, with its state 930 - * initialized to provided parameter. 931 - * 932 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 933 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 934 - * document store and cannot be nested again: attempt to do so will result in an exception. 935 - * @param {any[] | null} [items] 936 - */ 937 - constructor(items) { 938 - var ptr0 = isLikeNone(items) 939 - ? 0 940 - : passArrayJsValueToWasm0(items, wasm.__wbindgen_malloc); 941 - var len0 = WASM_VECTOR_LEN; 942 - const ret = wasm.yarray_new(ptr0, len0); 943 - this.__wbg_ptr = ret >>> 0; 944 - YArrayFinalization.register(this, this.__wbg_ptr, this); 945 - return this; 946 - } 947 - /** 948 - * @returns {number} 949 - */ 950 - get type() { 951 - const ret = wasm.yarray_type(this.__wbg_ptr); 952 - return ret; 953 - } 954 - /** 955 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 956 - * document. 957 - * @returns {any} 958 - */ 959 - get id() { 960 - const ret = wasm.yarray_id(this.__wbg_ptr); 961 - if (ret[2]) { 962 - throw takeFromExternrefTable0(ret[1]); 963 - } 964 - return takeFromExternrefTable0(ret[0]); 965 - } 966 - /** 967 - * Returns true if this is a preliminary instance of `YArray`. 968 - * 969 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 970 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 971 - * document store and cannot be nested again: attempt to do so will result in an exception. 972 - * @returns {boolean} 973 - */ 974 - get prelim() { 975 - const ret = wasm.yarray_prelim(this.__wbg_ptr); 976 - return ret !== 0; 977 - } 978 - /** 979 - * Checks if current YArray reference is alive and has not been deleted by its parent collection. 980 - * This method only works on already integrated shared types and will return false is current 981 - * type is preliminary (has not been integrated into document). 982 - * @param {YTransaction} txn 983 - * @returns {boolean} 984 - */ 985 - alive(txn) { 986 - _assertClass(txn, YTransaction); 987 - const ret = wasm.yarray_alive(this.__wbg_ptr, txn.__wbg_ptr); 988 - return ret !== 0; 989 - } 990 - /** 991 - * Returns a number of elements stored within this instance of `YArray`. 992 - * @param {YTransaction | undefined} txn 993 - * @returns {number} 994 - */ 995 - length(txn) { 996 - const ret = wasm.yarray_length(this.__wbg_ptr, txn); 997 - if (ret[2]) { 998 - throw takeFromExternrefTable0(ret[1]); 999 - } 1000 - return ret[0] >>> 0; 1001 - } 1002 - /** 1003 - * Converts an underlying contents of this `YArray` instance into their JSON representation. 1004 - * @param {YTransaction | undefined} txn 1005 - * @returns {any} 1006 - */ 1007 - toJson(txn) { 1008 - const ret = wasm.yarray_toJson(this.__wbg_ptr, txn); 1009 - if (ret[2]) { 1010 - throw takeFromExternrefTable0(ret[1]); 1011 - } 1012 - return takeFromExternrefTable0(ret[0]); 1013 - } 1014 - /** 1015 - * Inserts a given range of `items` into this `YArray` instance, starting at given `index`. 1016 - * @param {number} index 1017 - * @param {any[]} items 1018 - * @param {YTransaction | undefined} txn 1019 - */ 1020 - insert(index, items, txn) { 1021 - const ptr0 = passArrayJsValueToWasm0(items, wasm.__wbindgen_malloc); 1022 - const len0 = WASM_VECTOR_LEN; 1023 - const ret = wasm.yarray_insert(this.__wbg_ptr, index, ptr0, len0, txn); 1024 - if (ret[1]) { 1025 - throw takeFromExternrefTable0(ret[0]); 1026 - } 1027 - } 1028 - /** 1029 - * Appends a range of `items` at the end of this `YArray` instance. 1030 - * @param {any[]} items 1031 - * @param {YTransaction | undefined} txn 1032 - */ 1033 - push(items, txn) { 1034 - const ptr0 = passArrayJsValueToWasm0(items, wasm.__wbindgen_malloc); 1035 - const len0 = WASM_VECTOR_LEN; 1036 - const ret = wasm.yarray_push(this.__wbg_ptr, ptr0, len0, txn); 1037 - if (ret[1]) { 1038 - throw takeFromExternrefTable0(ret[0]); 1039 - } 1040 - } 1041 - /** 1042 - * Deletes a range of items of given `length` from current `YArray` instance, 1043 - * starting from given `index`. 1044 - * @param {number} index 1045 - * @param {number | null | undefined} length 1046 - * @param {YTransaction | undefined} txn 1047 - */ 1048 - delete(index, length, txn) { 1049 - const ret = wasm.yarray_delete( 1050 - this.__wbg_ptr, 1051 - index, 1052 - isLikeNone(length) ? 0x100000001 : length >>> 0, 1053 - txn, 1054 - ); 1055 - if (ret[1]) { 1056 - throw takeFromExternrefTable0(ret[0]); 1057 - } 1058 - } 1059 - /** 1060 - * Moves element found at `source` index into `target` index position. 1061 - * @param {number} source 1062 - * @param {number} target 1063 - * @param {YTransaction | undefined} txn 1064 - */ 1065 - move(source, target, txn) { 1066 - const ret = wasm.yarray_move(this.__wbg_ptr, source, target, txn); 1067 - if (ret[1]) { 1068 - throw takeFromExternrefTable0(ret[0]); 1069 - } 1070 - } 1071 - /** 1072 - * Returns an element stored under given `index`. 1073 - * @param {number} index 1074 - * @param {YTransaction | undefined} txn 1075 - * @returns {any} 1076 - */ 1077 - get(index, txn) { 1078 - const ret = wasm.yarray_get(this.__wbg_ptr, index, txn); 1079 - if (ret[2]) { 1080 - throw takeFromExternrefTable0(ret[1]); 1081 - } 1082 - return takeFromExternrefTable0(ret[0]); 1083 - } 1084 - /** 1085 - * @param {number | null | undefined} lower 1086 - * @param {number | null | undefined} upper 1087 - * @param {boolean | null | undefined} lower_open 1088 - * @param {boolean | null | undefined} upper_open 1089 - * @param {YTransaction | undefined} txn 1090 - * @returns {YWeakLink} 1091 - */ 1092 - quote(lower, upper, lower_open, upper_open, txn) { 1093 - const ret = wasm.yarray_quote( 1094 - this.__wbg_ptr, 1095 - isLikeNone(lower) ? 0x100000001 : lower >>> 0, 1096 - isLikeNone(upper) ? 0x100000001 : upper >>> 0, 1097 - isLikeNone(lower_open) ? 0xffffff : lower_open ? 1 : 0, 1098 - isLikeNone(upper_open) ? 0xffffff : upper_open ? 1 : 0, 1099 - txn, 1100 - ); 1101 - if (ret[2]) { 1102 - throw takeFromExternrefTable0(ret[1]); 1103 - } 1104 - return YWeakLink.__wrap(ret[0]); 1105 - } 1106 - /** 1107 - * Returns an iterator that can be used to traverse over the values stored withing this 1108 - * instance of `YArray`. 1109 - * 1110 - * Example: 1111 - * 1112 - * ```javascript 1113 - * import YDoc from 'ywasm' 1114 - * 1115 - * /// document on machine A 1116 - * const doc = new YDoc() 1117 - * const array = doc.getArray('name') 1118 - * const txn = doc.beginTransaction() 1119 - * try { 1120 - * array.push(txn, ['hello', 'world']) 1121 - * for (let item of array.values(txn)) { 1122 - * console.log(item) 1123 - * } 1124 - * } finally { 1125 - * txn.free() 1126 - * } 1127 - * ``` 1128 - * @param {YTransaction | undefined} txn 1129 - * @returns {any} 1130 - */ 1131 - values(txn) { 1132 - const ret = wasm.yarray_values(this.__wbg_ptr, txn); 1133 - if (ret[2]) { 1134 - throw takeFromExternrefTable0(ret[1]); 1135 - } 1136 - return takeFromExternrefTable0(ret[0]); 1137 - } 1138 - /** 1139 - * Subscribes to all operations happening over this instance of `YArray`. All changes are 1140 - * batched and eventually triggered during transaction commit phase. 1141 - * @param {Function} callback 1142 - */ 1143 - observe(callback) { 1144 - const ret = wasm.yarray_observe(this.__wbg_ptr, callback); 1145 - if (ret[1]) { 1146 - throw takeFromExternrefTable0(ret[0]); 1147 - } 1148 - } 1149 - /** 1150 - * @param {Function} callback 1151 - * @returns {boolean} 1152 - */ 1153 - unobserve(callback) { 1154 - const ret = wasm.yarray_unobserve(this.__wbg_ptr, callback); 1155 - if (ret[2]) { 1156 - throw takeFromExternrefTable0(ret[1]); 1157 - } 1158 - return ret[0] !== 0; 1159 - } 1160 - /** 1161 - * Subscribes to all operations happening over this Y shared type, as well as events in 1162 - * shared types stored within this one. All changes are batched and eventually triggered 1163 - * during transaction commit phase. 1164 - * @param {Function} callback 1165 - */ 1166 - observeDeep(callback) { 1167 - const ret = wasm.yarray_observeDeep(this.__wbg_ptr, callback); 1168 - if (ret[1]) { 1169 - throw takeFromExternrefTable0(ret[0]); 1170 - } 1171 - } 1172 - /** 1173 - * @param {Function} callback 1174 - * @returns {boolean} 1175 - */ 1176 - unobserveDeep(callback) { 1177 - const ret = wasm.yarray_unobserveDeep(this.__wbg_ptr, callback); 1178 - if (ret[2]) { 1179 - throw takeFromExternrefTable0(ret[1]); 1180 - } 1181 - return ret[0] !== 0; 1182 - } 1183 - } 1184 - module.exports.YArray = YArray; 1185 - 1186 - const YArrayEventFinalization = 1187 - typeof FinalizationRegistry === "undefined" 1188 - ? { register: () => {}, unregister: () => {} } 1189 - : new FinalizationRegistry((ptr) => 1190 - wasm.__wbg_yarrayevent_free(ptr >>> 0, 1), 1191 - ); 1192 - /** 1193 - * Event generated by `YArray.observe` method. Emitted during transaction commit phase. 1194 - */ 1195 - class YArrayEvent { 1196 - static __wrap(ptr) { 1197 - ptr = ptr >>> 0; 1198 - const obj = Object.create(YArrayEvent.prototype); 1199 - obj.__wbg_ptr = ptr; 1200 - YArrayEventFinalization.register(obj, obj.__wbg_ptr, obj); 1201 - return obj; 1202 - } 1203 - 1204 - __destroy_into_raw() { 1205 - const ptr = this.__wbg_ptr; 1206 - this.__wbg_ptr = 0; 1207 - YArrayEventFinalization.unregister(this); 1208 - return ptr; 1209 - } 1210 - 1211 - free() { 1212 - const ptr = this.__destroy_into_raw(); 1213 - wasm.__wbg_yarrayevent_free(ptr, 0); 1214 - } 1215 - /** 1216 - * Returns an array of keys and indexes creating a path from root type down to current instance 1217 - * of shared type (accessible via `target` getter). 1218 - * @returns {any} 1219 - */ 1220 - path() { 1221 - const ret = wasm.yarrayevent_path(this.__wbg_ptr); 1222 - return ret; 1223 - } 1224 - /** 1225 - * Returns a current shared type instance, that current event changes refer to. 1226 - * @returns {any} 1227 - */ 1228 - get target() { 1229 - const ret = wasm.yarrayevent_target(this.__wbg_ptr); 1230 - return ret; 1231 - } 1232 - /** 1233 - * @returns {any} 1234 - */ 1235 - get origin() { 1236 - const ret = wasm.yarrayevent_origin(this.__wbg_ptr); 1237 - return ret; 1238 - } 1239 - /** 1240 - * Returns a list of text changes made over corresponding `YArray` collection within 1241 - * bounds of current transaction. These changes follow a format: 1242 - * 1243 - * - { insert: any[] } 1244 - * - { delete: number } 1245 - * - { retain: number } 1246 - * @returns {any} 1247 - */ 1248 - get delta() { 1249 - const ret = wasm.yarrayevent_delta(this.__wbg_ptr); 1250 - return ret; 1251 - } 1252 - } 1253 - module.exports.YArrayEvent = YArrayEvent; 1254 - 1255 - const YDocFinalization = 1256 - typeof FinalizationRegistry === "undefined" 1257 - ? { register: () => {}, unregister: () => {} } 1258 - : new FinalizationRegistry((ptr) => wasm.__wbg_ydoc_free(ptr >>> 0, 1)); 1259 - /** 1260 - * A ywasm document type. Documents are most important units of collaborative resources management. 1261 - * All shared collections live within a scope of their corresponding documents. All updates are 1262 - * generated on per-document basis (rather than individual shared type). All operations on shared 1263 - * collections happen via [YTransaction], which lifetime is also bound to a document. 1264 - * 1265 - * Document manages so-called root types, which are top-level shared types definitions (as opposed 1266 - * to recursively nested types). 1267 - * 1268 - * A basic workflow sample: 1269 - * 1270 - * ```javascript 1271 - * import YDoc from 'ywasm' 1272 - * 1273 - * const doc = new YDoc() 1274 - * const txn = doc.beginTransaction() 1275 - * try { 1276 - * const text = txn.getText('name') 1277 - * text.push(txn, 'hello world') 1278 - * const output = text.toString(txn) 1279 - * console.log(output) 1280 - * } finally { 1281 - * txn.free() 1282 - * } 1283 - * ``` 1284 - */ 1285 - class YDoc { 1286 - static __wrap(ptr) { 1287 - ptr = ptr >>> 0; 1288 - const obj = Object.create(YDoc.prototype); 1289 - obj.__wbg_ptr = ptr; 1290 - YDocFinalization.register(obj, obj.__wbg_ptr, obj); 1291 - return obj; 1292 - } 1293 - 1294 - __destroy_into_raw() { 1295 - const ptr = this.__wbg_ptr; 1296 - this.__wbg_ptr = 0; 1297 - YDocFinalization.unregister(this); 1298 - return ptr; 1299 - } 1300 - 1301 - free() { 1302 - const ptr = this.__destroy_into_raw(); 1303 - wasm.__wbg_ydoc_free(ptr, 0); 1304 - } 1305 - /** 1306 - * Creates a new ywasm document. If `id` parameter was passed it will be used as this document 1307 - * globally unique identifier (it's up to caller to ensure that requirement). Otherwise it will 1308 - * be assigned a randomly generated number. 1309 - * @param {any} options 1310 - */ 1311 - constructor(options) { 1312 - const ret = wasm.ydoc_new(options); 1313 - if (ret[2]) { 1314 - throw takeFromExternrefTable0(ret[1]); 1315 - } 1316 - this.__wbg_ptr = ret[0] >>> 0; 1317 - YDocFinalization.register(this, this.__wbg_ptr, this); 1318 - return this; 1319 - } 1320 - /** 1321 - * @returns {number} 1322 - */ 1323 - get type() { 1324 - const ret = wasm.ydoc_type(this.__wbg_ptr); 1325 - return ret; 1326 - } 1327 - /** 1328 - * Checks if a document is a preliminary type. It returns false, if current document 1329 - * is already a sub-document of another document. 1330 - * @returns {boolean} 1331 - */ 1332 - get prelim() { 1333 - const ret = wasm.ydoc_prelim(this.__wbg_ptr); 1334 - return ret !== 0; 1335 - } 1336 - /** 1337 - * Returns a parent document of this document or null if current document is not sub-document. 1338 - * @returns {YDoc | undefined} 1339 - */ 1340 - get parentDoc() { 1341 - const ret = wasm.ydoc_parentDoc(this.__wbg_ptr); 1342 - return ret === 0 ? undefined : YDoc.__wrap(ret); 1343 - } 1344 - /** 1345 - * Gets unique peer identifier of this `YDoc` instance. 1346 - * @returns {number} 1347 - */ 1348 - get id() { 1349 - const ret = wasm.ydoc_id(this.__wbg_ptr); 1350 - return ret; 1351 - } 1352 - /** 1353 - * Gets globally unique identifier of this `YDoc` instance. 1354 - * @returns {string} 1355 - */ 1356 - get guid() { 1357 - let deferred1_0; 1358 - let deferred1_1; 1359 - try { 1360 - const ret = wasm.ydoc_guid(this.__wbg_ptr); 1361 - deferred1_0 = ret[0]; 1362 - deferred1_1 = ret[1]; 1363 - return getStringFromWasm0(ret[0], ret[1]); 1364 - } finally { 1365 - wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); 1366 - } 1367 - } 1368 - /** 1369 - * @returns {boolean} 1370 - */ 1371 - get shouldLoad() { 1372 - const ret = wasm.ydoc_shouldLoad(this.__wbg_ptr); 1373 - return ret !== 0; 1374 - } 1375 - /** 1376 - * @returns {boolean} 1377 - */ 1378 - get autoLoad() { 1379 - const ret = wasm.ydoc_autoLoad(this.__wbg_ptr); 1380 - return ret !== 0; 1381 - } 1382 - /** 1383 - * Returns a new transaction for this document. Ywasm shared data types execute their 1384 - * operations in a context of a given transaction. Each document can have only one active 1385 - * transaction at the time - subsequent attempts will cause exception to be thrown. 1386 - * 1387 - * Transactions started with `doc.beginTransaction` can be released using `transaction.free` 1388 - * method. 1389 - * 1390 - * Example: 1391 - * 1392 - * ```javascript 1393 - * import YDoc from 'ywasm' 1394 - * 1395 - * // helper function used to simplify transaction 1396 - * // create/release cycle 1397 - * YDoc.prototype.transact = callback => { 1398 - * const txn = this.transaction() 1399 - * try { 1400 - * return callback(txn) 1401 - * } finally { 1402 - * txn.free() 1403 - * } 1404 - * } 1405 - * 1406 - * const doc = new YDoc() 1407 - * const text = doc.getText('name') 1408 - * doc.transact(txn => text.insert(txn, 0, 'hello world')) 1409 - * ``` 1410 - * @param {any} origin 1411 - * @returns {YTransaction} 1412 - */ 1413 - beginTransaction(origin) { 1414 - const ret = wasm.ydoc_beginTransaction(this.__wbg_ptr, origin); 1415 - return YTransaction.__wrap(ret); 1416 - } 1417 - /** 1418 - * Returns a `YText` shared data type, that's accessible for subsequent accesses using given 1419 - * `name`. 1420 - * 1421 - * If there was no instance with this name before, it will be created and then returned. 1422 - * 1423 - * If there was an instance with this name, but it was of different type, it will be projected 1424 - * onto `YText` instance. 1425 - * @param {string} name 1426 - * @returns {YText} 1427 - */ 1428 - getText(name) { 1429 - const ptr0 = passStringToWasm0( 1430 - name, 1431 - wasm.__wbindgen_malloc, 1432 - wasm.__wbindgen_realloc, 1433 - ); 1434 - const len0 = WASM_VECTOR_LEN; 1435 - const ret = wasm.ydoc_getText(this.__wbg_ptr, ptr0, len0); 1436 - return YText.__wrap(ret); 1437 - } 1438 - /** 1439 - * Returns a `YArray` shared data type, that's accessible for subsequent accesses using given 1440 - * `name`. 1441 - * 1442 - * If there was no instance with this name before, it will be created and then returned. 1443 - * 1444 - * If there was an instance with this name, but it was of different type, it will be projected 1445 - * onto `YArray` instance. 1446 - * @param {string} name 1447 - * @returns {YArray} 1448 - */ 1449 - getArray(name) { 1450 - const ptr0 = passStringToWasm0( 1451 - name, 1452 - wasm.__wbindgen_malloc, 1453 - wasm.__wbindgen_realloc, 1454 - ); 1455 - const len0 = WASM_VECTOR_LEN; 1456 - const ret = wasm.ydoc_getArray(this.__wbg_ptr, ptr0, len0); 1457 - return YArray.__wrap(ret); 1458 - } 1459 - /** 1460 - * Returns a `YMap` shared data type, that's accessible for subsequent accesses using given 1461 - * `name`. 1462 - * 1463 - * If there was no instance with this name before, it will be created and then returned. 1464 - * 1465 - * If there was an instance with this name, but it was of different type, it will be projected 1466 - * onto `YMap` instance. 1467 - * @param {string} name 1468 - * @returns {YMap} 1469 - */ 1470 - getMap(name) { 1471 - const ptr0 = passStringToWasm0( 1472 - name, 1473 - wasm.__wbindgen_malloc, 1474 - wasm.__wbindgen_realloc, 1475 - ); 1476 - const len0 = WASM_VECTOR_LEN; 1477 - const ret = wasm.ydoc_getMap(this.__wbg_ptr, ptr0, len0); 1478 - return YMap.__wrap(ret); 1479 - } 1480 - /** 1481 - * Returns a `YXmlFragment` shared data type, that's accessible for subsequent accesses using 1482 - * given `name`. 1483 - * 1484 - * If there was no instance with this name before, it will be created and then returned. 1485 - * 1486 - * If there was an instance with this name, but it was of different type, it will be projected 1487 - * onto `YXmlFragment` instance. 1488 - * @param {string} name 1489 - * @returns {YXmlFragment} 1490 - */ 1491 - getXmlFragment(name) { 1492 - const ptr0 = passStringToWasm0( 1493 - name, 1494 - wasm.__wbindgen_malloc, 1495 - wasm.__wbindgen_realloc, 1496 - ); 1497 - const len0 = WASM_VECTOR_LEN; 1498 - const ret = wasm.ydoc_getXmlFragment(this.__wbg_ptr, ptr0, len0); 1499 - return YXmlFragment.__wrap(ret); 1500 - } 1501 - /** 1502 - * @param {string} event 1503 - * @param {Function} callback 1504 - */ 1505 - on(event, callback) { 1506 - const ptr0 = passStringToWasm0( 1507 - event, 1508 - wasm.__wbindgen_malloc, 1509 - wasm.__wbindgen_realloc, 1510 - ); 1511 - const len0 = WASM_VECTOR_LEN; 1512 - const ret = wasm.ydoc_on(this.__wbg_ptr, ptr0, len0, callback); 1513 - if (ret[1]) { 1514 - throw takeFromExternrefTable0(ret[0]); 1515 - } 1516 - } 1517 - /** 1518 - * @param {string} event 1519 - * @param {Function} callback 1520 - * @returns {boolean} 1521 - */ 1522 - off(event, callback) { 1523 - const ptr0 = passStringToWasm0( 1524 - event, 1525 - wasm.__wbindgen_malloc, 1526 - wasm.__wbindgen_realloc, 1527 - ); 1528 - const len0 = WASM_VECTOR_LEN; 1529 - const ret = wasm.ydoc_off(this.__wbg_ptr, ptr0, len0, callback); 1530 - if (ret[2]) { 1531 - throw takeFromExternrefTable0(ret[1]); 1532 - } 1533 - return ret[0] !== 0; 1534 - } 1535 - /** 1536 - * Notify the parent document that you request to load data into this subdocument 1537 - * (if it is a subdocument). 1538 - * @param {YTransaction | undefined} parent_txn 1539 - */ 1540 - load(parent_txn) { 1541 - const ret = wasm.ydoc_load(this.__wbg_ptr, parent_txn); 1542 - if (ret[1]) { 1543 - throw takeFromExternrefTable0(ret[0]); 1544 - } 1545 - } 1546 - /** 1547 - * Emit `onDestroy` event and unregister all event handlers. 1548 - * @param {YTransaction | undefined} parent_txn 1549 - */ 1550 - destroy(parent_txn) { 1551 - const ret = wasm.ydoc_destroy(this.__wbg_ptr, parent_txn); 1552 - if (ret[1]) { 1553 - throw takeFromExternrefTable0(ret[0]); 1554 - } 1555 - } 1556 - /** 1557 - * Returns a list of sub-documents existings within the scope of this document. 1558 - * @param {YTransaction | undefined} txn 1559 - * @returns {Array<any>} 1560 - */ 1561 - getSubdocs(txn) { 1562 - const ret = wasm.ydoc_getSubdocs(this.__wbg_ptr, txn); 1563 - if (ret[2]) { 1564 - throw takeFromExternrefTable0(ret[1]); 1565 - } 1566 - return takeFromExternrefTable0(ret[0]); 1567 - } 1568 - /** 1569 - * Returns a list of unique identifiers of the sub-documents existings within the scope of 1570 - * this document. 1571 - * @param {YTransaction | undefined} txn 1572 - * @returns {Set<any>} 1573 - */ 1574 - getSubdocGuids(txn) { 1575 - const ret = wasm.ydoc_getSubdocGuids(this.__wbg_ptr, txn); 1576 - if (ret[2]) { 1577 - throw takeFromExternrefTable0(ret[1]); 1578 - } 1579 - return takeFromExternrefTable0(ret[0]); 1580 - } 1581 - /** 1582 - * Returns a list of all root-level replicated collections, together with their types. 1583 - * These collections can then be accessed via `getMap`/`getText` etc. methods. 1584 - * 1585 - * Example: 1586 - * ```js 1587 - * import * as Y from 'ywasm' 1588 - * 1589 - * const doc = new Y.YDoc() 1590 - * const ymap = doc.getMap('a') 1591 - * const yarray = doc.getArray('b') 1592 - * const ytext = doc.getText('c') 1593 - * const yxml = doc.getXmlFragment('d') 1594 - * 1595 - * const roots = doc.roots() // [['a',ymap], ['b',yarray], ['c',ytext], ['d',yxml]] 1596 - * ``` 1597 - * @param {YTransaction | undefined} txn 1598 - * @returns {Array<any>} 1599 - */ 1600 - roots(txn) { 1601 - const ret = wasm.ydoc_roots(this.__wbg_ptr, txn); 1602 - if (ret[2]) { 1603 - throw takeFromExternrefTable0(ret[1]); 1604 - } 1605 - return takeFromExternrefTable0(ret[0]); 1606 - } 1607 - /** 1608 - * Evaluates a JSON path expression (see: https://en.wikipedia.org/wiki/JSONPath) on 1609 - * the document and returns an array of values matching that query. 1610 - * 1611 - * Currently, this method supports the following syntax: 1612 - * - `$` - root object 1613 - * - `@` - current object 1614 - * - `.field` or `['field']` - member accessor 1615 - * - `[1]` - array index (also supports negative indices) 1616 - * - `.*` or `[*]` - wildcard (matches all members of an object or array) 1617 - * - `..` - recursive descent (matches all descendants not only direct children) 1618 - * - `[start:end:step]` - array slice operator (requires positive integer arguments) 1619 - * - `['a', 'b', 'c']` - union operator (returns an array of values for each query) 1620 - * - `[1, -1, 3]` - multiple indices operator (returns an array of values for each index) 1621 - * 1622 - * At the moment, JSON Path does not support filter predicates. 1623 - * @param {string} json_path 1624 - * @returns {Array<any>} 1625 - */ 1626 - selectAll(json_path) { 1627 - const ptr0 = passStringToWasm0( 1628 - json_path, 1629 - wasm.__wbindgen_malloc, 1630 - wasm.__wbindgen_realloc, 1631 - ); 1632 - const len0 = WASM_VECTOR_LEN; 1633 - const ret = wasm.ydoc_selectAll(this.__wbg_ptr, ptr0, len0); 1634 - if (ret[2]) { 1635 - throw takeFromExternrefTable0(ret[1]); 1636 - } 1637 - return takeFromExternrefTable0(ret[0]); 1638 - } 1639 - /** 1640 - * Evaluates a JSON path expression (see: https://en.wikipedia.org/wiki/JSONPath) on 1641 - * the document and returns first value matching that query. 1642 - * 1643 - * Currently, this method supports the following syntax: 1644 - * - `$` - root object 1645 - * - `@` - current object 1646 - * - `.field` or `['field']` - member accessor 1647 - * - `[1]` - array index (also supports negative indices) 1648 - * - `.*` or `[*]` - wildcard (matches all members of an object or array) 1649 - * - `..` - recursive descent (matches all descendants not only direct children) 1650 - * - `[start:end:step]` - array slice operator (requires positive integer arguments) 1651 - * - `['a', 'b', 'c']` - union operator (returns an array of values for each query) 1652 - * - `[1, -1, 3]` - multiple indices operator (returns an array of values for each index) 1653 - * 1654 - * At the moment, JSON Path does not support filter predicates. 1655 - * @param {string} json_path 1656 - * @returns {any} 1657 - */ 1658 - selectOne(json_path) { 1659 - const ptr0 = passStringToWasm0( 1660 - json_path, 1661 - wasm.__wbindgen_malloc, 1662 - wasm.__wbindgen_realloc, 1663 - ); 1664 - const len0 = WASM_VECTOR_LEN; 1665 - const ret = wasm.ydoc_selectOne(this.__wbg_ptr, ptr0, len0); 1666 - if (ret[2]) { 1667 - throw takeFromExternrefTable0(ret[1]); 1668 - } 1669 - return takeFromExternrefTable0(ret[0]); 1670 - } 1671 - } 1672 - module.exports.YDoc = YDoc; 1673 - 1674 - const YMapFinalization = 1675 - typeof FinalizationRegistry === "undefined" 1676 - ? { register: () => {}, unregister: () => {} } 1677 - : new FinalizationRegistry((ptr) => wasm.__wbg_ymap_free(ptr >>> 0, 1)); 1678 - /** 1679 - * Collection used to store key-value entries in an unordered manner. Keys are always represented 1680 - * as UTF-8 strings. Values can be any value type supported by Yrs: JSON-like primitives as well as 1681 - * shared data types. 1682 - * 1683 - * In terms of conflict resolution, [Map] uses logical last-write-wins principle, meaning the past 1684 - * updates are automatically overridden and discarded by newer ones, while concurrent updates made 1685 - * by different peers are resolved into a single value using document id seniority to establish 1686 - * order. 1687 - */ 1688 - class YMap { 1689 - static __wrap(ptr) { 1690 - ptr = ptr >>> 0; 1691 - const obj = Object.create(YMap.prototype); 1692 - obj.__wbg_ptr = ptr; 1693 - YMapFinalization.register(obj, obj.__wbg_ptr, obj); 1694 - return obj; 1695 - } 1696 - 1697 - __destroy_into_raw() { 1698 - const ptr = this.__wbg_ptr; 1699 - this.__wbg_ptr = 0; 1700 - YMapFinalization.unregister(this); 1701 - return ptr; 1702 - } 1703 - 1704 - free() { 1705 - const ptr = this.__destroy_into_raw(); 1706 - wasm.__wbg_ymap_free(ptr, 0); 1707 - } 1708 - /** 1709 - * Creates a new preliminary instance of a `YMap` shared data type, with its state 1710 - * initialized to provided parameter. 1711 - * 1712 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 1713 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 1714 - * document store and cannot be nested again: attempt to do so will result in an exception. 1715 - * @param {object | null} [init] 1716 - */ 1717 - constructor(init) { 1718 - const ret = wasm.ymap_new( 1719 - isLikeNone(init) ? 0 : addToExternrefTable0(init), 1720 - ); 1721 - this.__wbg_ptr = ret >>> 0; 1722 - YMapFinalization.register(this, this.__wbg_ptr, this); 1723 - return this; 1724 - } 1725 - /** 1726 - * @returns {number} 1727 - */ 1728 - get type() { 1729 - const ret = wasm.ymap_type(this.__wbg_ptr); 1730 - return ret; 1731 - } 1732 - /** 1733 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 1734 - * document. 1735 - * @returns {any} 1736 - */ 1737 - get id() { 1738 - const ret = wasm.ymap_id(this.__wbg_ptr); 1739 - if (ret[2]) { 1740 - throw takeFromExternrefTable0(ret[1]); 1741 - } 1742 - return takeFromExternrefTable0(ret[0]); 1743 - } 1744 - /** 1745 - * Returns true if this is a preliminary instance of `YMap`. 1746 - * 1747 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 1748 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 1749 - * document store and cannot be nested again: attempt to do so will result in an exception. 1750 - * @returns {boolean} 1751 - */ 1752 - get prelim() { 1753 - const ret = wasm.ymap_prelim(this.__wbg_ptr); 1754 - return ret !== 0; 1755 - } 1756 - /** 1757 - * Checks if current YMap reference is alive and has not been deleted by its parent collection. 1758 - * This method only works on already integrated shared types and will return false is current 1759 - * type is preliminary (has not been integrated into document). 1760 - * @param {YTransaction} txn 1761 - * @returns {boolean} 1762 - */ 1763 - alive(txn) { 1764 - _assertClass(txn, YTransaction); 1765 - const ret = wasm.ymap_alive(this.__wbg_ptr, txn.__wbg_ptr); 1766 - return ret !== 0; 1767 - } 1768 - /** 1769 - * Returns a number of entries stored within this instance of `YMap`. 1770 - * @param {YTransaction | undefined} txn 1771 - * @returns {number} 1772 - */ 1773 - length(txn) { 1774 - const ret = wasm.ymap_length(this.__wbg_ptr, txn); 1775 - if (ret[2]) { 1776 - throw takeFromExternrefTable0(ret[1]); 1777 - } 1778 - return ret[0] >>> 0; 1779 - } 1780 - /** 1781 - * Converts contents of this `YMap` instance into a JSON representation. 1782 - * @param {YTransaction | undefined} txn 1783 - * @returns {any} 1784 - */ 1785 - toJson(txn) { 1786 - const ret = wasm.ymap_toJson(this.__wbg_ptr, txn); 1787 - if (ret[2]) { 1788 - throw takeFromExternrefTable0(ret[1]); 1789 - } 1790 - return takeFromExternrefTable0(ret[0]); 1791 - } 1792 - /** 1793 - * Sets a given `key`-`value` entry within this instance of `YMap`. If another entry was 1794 - * already stored under given `key`, it will be overridden with new `value`. 1795 - * @param {string} key 1796 - * @param {any} value 1797 - * @param {YTransaction | undefined} txn 1798 - */ 1799 - set(key, value, txn) { 1800 - const ptr0 = passStringToWasm0( 1801 - key, 1802 - wasm.__wbindgen_malloc, 1803 - wasm.__wbindgen_realloc, 1804 - ); 1805 - const len0 = WASM_VECTOR_LEN; 1806 - const ret = wasm.ymap_set(this.__wbg_ptr, ptr0, len0, value, txn); 1807 - if (ret[1]) { 1808 - throw takeFromExternrefTable0(ret[0]); 1809 - } 1810 - } 1811 - /** 1812 - * Removes an entry identified by a given `key` from this instance of `YMap`, if such exists. 1813 - * @param {string} key 1814 - * @param {YTransaction | undefined} txn 1815 - */ 1816 - delete(key, txn) { 1817 - const ptr0 = passStringToWasm0( 1818 - key, 1819 - wasm.__wbindgen_malloc, 1820 - wasm.__wbindgen_realloc, 1821 - ); 1822 - const len0 = WASM_VECTOR_LEN; 1823 - const ret = wasm.ymap_delete(this.__wbg_ptr, ptr0, len0, txn); 1824 - if (ret[1]) { 1825 - throw takeFromExternrefTable0(ret[0]); 1826 - } 1827 - } 1828 - /** 1829 - * Returns value of an entry stored under given `key` within this instance of `YMap`, 1830 - * or `undefined` if no such entry existed. 1831 - * @param {string} key 1832 - * @param {YTransaction | undefined} txn 1833 - * @returns {any} 1834 - */ 1835 - get(key, txn) { 1836 - const ptr0 = passStringToWasm0( 1837 - key, 1838 - wasm.__wbindgen_malloc, 1839 - wasm.__wbindgen_realloc, 1840 - ); 1841 - const len0 = WASM_VECTOR_LEN; 1842 - const ret = wasm.ymap_get(this.__wbg_ptr, ptr0, len0, txn); 1843 - if (ret[2]) { 1844 - throw takeFromExternrefTable0(ret[1]); 1845 - } 1846 - return takeFromExternrefTable0(ret[0]); 1847 - } 1848 - /** 1849 - * @param {string} key 1850 - * @param {YTransaction | undefined} txn 1851 - * @returns {any} 1852 - */ 1853 - link(key, txn) { 1854 - const ptr0 = passStringToWasm0( 1855 - key, 1856 - wasm.__wbindgen_malloc, 1857 - wasm.__wbindgen_realloc, 1858 - ); 1859 - const len0 = WASM_VECTOR_LEN; 1860 - const ret = wasm.ymap_link(this.__wbg_ptr, ptr0, len0, txn); 1861 - if (ret[2]) { 1862 - throw takeFromExternrefTable0(ret[1]); 1863 - } 1864 - return takeFromExternrefTable0(ret[0]); 1865 - } 1866 - /** 1867 - * Returns an iterator that can be used to traverse over all entries stored within this 1868 - * instance of `YMap`. Order of entry is not specified. 1869 - * 1870 - * Example: 1871 - * 1872 - * ```javascript 1873 - * import YDoc from 'ywasm' 1874 - * 1875 - * /// document on machine A 1876 - * const doc = new YDoc() 1877 - * const map = doc.getMap('name') 1878 - * const txn = doc.beginTransaction() 1879 - * try { 1880 - * map.set(txn, 'key1', 'value1') 1881 - * map.set(txn, 'key2', true) 1882 - * 1883 - * for (let [key, value] of map.entries(txn)) { 1884 - * console.log(key, value) 1885 - * } 1886 - * } finally { 1887 - * txn.free() 1888 - * } 1889 - * ``` 1890 - * @param {YTransaction | undefined} txn 1891 - * @returns {any} 1892 - */ 1893 - entries(txn) { 1894 - const ret = wasm.ymap_entries(this.__wbg_ptr, txn); 1895 - if (ret[2]) { 1896 - throw takeFromExternrefTable0(ret[1]); 1897 - } 1898 - return takeFromExternrefTable0(ret[0]); 1899 - } 1900 - /** 1901 - * Subscribes to all operations happening over this instance of `YMap`. All changes are 1902 - * batched and eventually triggered during transaction commit phase. 1903 - * @param {Function} callback 1904 - */ 1905 - observe(callback) { 1906 - const ret = wasm.ymap_observe(this.__wbg_ptr, callback); 1907 - if (ret[1]) { 1908 - throw takeFromExternrefTable0(ret[0]); 1909 - } 1910 - } 1911 - /** 1912 - * Unsubscribes a callback previously subscribed with `observe` method. 1913 - * @param {Function} callback 1914 - * @returns {boolean} 1915 - */ 1916 - unobserve(callback) { 1917 - const ret = wasm.ymap_unobserve(this.__wbg_ptr, callback); 1918 - if (ret[2]) { 1919 - throw takeFromExternrefTable0(ret[1]); 1920 - } 1921 - return ret[0] !== 0; 1922 - } 1923 - /** 1924 - * Subscribes to all operations happening over this Y shared type, as well as events in 1925 - * shared types stored within this one. All changes are batched and eventually triggered 1926 - * during transaction commit phase. 1927 - * @param {Function} callback 1928 - */ 1929 - observeDeep(callback) { 1930 - const ret = wasm.ymap_observeDeep(this.__wbg_ptr, callback); 1931 - if (ret[1]) { 1932 - throw takeFromExternrefTable0(ret[0]); 1933 - } 1934 - } 1935 - /** 1936 - * Unsubscribes a callback previously subscribed with `observeDeep` method. 1937 - * @param {Function} callback 1938 - * @returns {boolean} 1939 - */ 1940 - unobserveDeep(callback) { 1941 - const ret = wasm.ymap_unobserveDeep(this.__wbg_ptr, callback); 1942 - if (ret[2]) { 1943 - throw takeFromExternrefTable0(ret[1]); 1944 - } 1945 - return ret[0] !== 0; 1946 - } 1947 - } 1948 - module.exports.YMap = YMap; 1949 - 1950 - const YMapEventFinalization = 1951 - typeof FinalizationRegistry === "undefined" 1952 - ? { register: () => {}, unregister: () => {} } 1953 - : new FinalizationRegistry((ptr) => 1954 - wasm.__wbg_ymapevent_free(ptr >>> 0, 1), 1955 - ); 1956 - /** 1957 - * Event generated by `YMap.observe` method. Emitted during transaction commit phase. 1958 - */ 1959 - class YMapEvent { 1960 - static __wrap(ptr) { 1961 - ptr = ptr >>> 0; 1962 - const obj = Object.create(YMapEvent.prototype); 1963 - obj.__wbg_ptr = ptr; 1964 - YMapEventFinalization.register(obj, obj.__wbg_ptr, obj); 1965 - return obj; 1966 - } 1967 - 1968 - __destroy_into_raw() { 1969 - const ptr = this.__wbg_ptr; 1970 - this.__wbg_ptr = 0; 1971 - YMapEventFinalization.unregister(this); 1972 - return ptr; 1973 - } 1974 - 1975 - free() { 1976 - const ptr = this.__destroy_into_raw(); 1977 - wasm.__wbg_ymapevent_free(ptr, 0); 1978 - } 1979 - /** 1980 - * @returns {any} 1981 - */ 1982 - get origin() { 1983 - const ret = wasm.ymapevent_origin(this.__wbg_ptr); 1984 - return ret; 1985 - } 1986 - /** 1987 - * Returns an array of keys and indexes creating a path from root type down to current instance 1988 - * of shared type (accessible via `target` getter). 1989 - * @returns {any} 1990 - */ 1991 - path() { 1992 - const ret = wasm.ymapevent_path(this.__wbg_ptr); 1993 - return ret; 1994 - } 1995 - /** 1996 - * Returns a current shared type instance, that current event changes refer to. 1997 - * @returns {any} 1998 - */ 1999 - get target() { 2000 - const ret = wasm.ymapevent_target(this.__wbg_ptr); 2001 - return ret; 2002 - } 2003 - /** 2004 - * Returns a list of key-value changes made over corresponding `YMap` collection within 2005 - * bounds of current transaction. These changes follow a format: 2006 - * 2007 - * - { action: 'add'|'update'|'delete', oldValue: any|undefined, newValue: any|undefined } 2008 - * @returns {any} 2009 - */ 2010 - get keys() { 2011 - const ret = wasm.ymapevent_keys(this.__wbg_ptr); 2012 - if (ret[2]) { 2013 - throw takeFromExternrefTable0(ret[1]); 2014 - } 2015 - return takeFromExternrefTable0(ret[0]); 2016 - } 2017 - } 2018 - module.exports.YMapEvent = YMapEvent; 2019 - 2020 - const YSubdocsEventFinalization = 2021 - typeof FinalizationRegistry === "undefined" 2022 - ? { register: () => {}, unregister: () => {} } 2023 - : new FinalizationRegistry((ptr) => 2024 - wasm.__wbg_ysubdocsevent_free(ptr >>> 0, 1), 2025 - ); 2026 - 2027 - class YSubdocsEvent { 2028 - static __wrap(ptr) { 2029 - ptr = ptr >>> 0; 2030 - const obj = Object.create(YSubdocsEvent.prototype); 2031 - obj.__wbg_ptr = ptr; 2032 - YSubdocsEventFinalization.register(obj, obj.__wbg_ptr, obj); 2033 - return obj; 2034 - } 2035 - 2036 - __destroy_into_raw() { 2037 - const ptr = this.__wbg_ptr; 2038 - this.__wbg_ptr = 0; 2039 - YSubdocsEventFinalization.unregister(this); 2040 - return ptr; 2041 - } 2042 - 2043 - free() { 2044 - const ptr = this.__destroy_into_raw(); 2045 - wasm.__wbg_ysubdocsevent_free(ptr, 0); 2046 - } 2047 - /** 2048 - * @returns {Array<any>} 2049 - */ 2050 - get added() { 2051 - const ret = wasm.ysubdocsevent_added(this.__wbg_ptr); 2052 - return ret; 2053 - } 2054 - /** 2055 - * @returns {Array<any>} 2056 - */ 2057 - get removed() { 2058 - const ret = wasm.ysubdocsevent_removed(this.__wbg_ptr); 2059 - return ret; 2060 - } 2061 - /** 2062 - * @returns {Array<any>} 2063 - */ 2064 - get loaded() { 2065 - const ret = wasm.ysubdocsevent_loaded(this.__wbg_ptr); 2066 - return ret; 2067 - } 2068 - } 2069 - module.exports.YSubdocsEvent = YSubdocsEvent; 2070 - 2071 - const YTextFinalization = 2072 - typeof FinalizationRegistry === "undefined" 2073 - ? { register: () => {}, unregister: () => {} } 2074 - : new FinalizationRegistry((ptr) => wasm.__wbg_ytext_free(ptr >>> 0, 1)); 2075 - /** 2076 - * A shared data type used for collaborative text editing. It enables multiple users to add and 2077 - * remove chunks of text in efficient manner. This type is internally represented as a mutable 2078 - * double-linked list of text chunks - an optimization occurs during `YTransaction.commit`, which 2079 - * allows to squash multiple consecutively inserted characters together as a single chunk of text 2080 - * even between transaction boundaries in order to preserve more efficient memory model. 2081 - * 2082 - * `YText` structure internally uses UTF-8 encoding and its length is described in a number of 2083 - * bytes rather than individual characters (a single UTF-8 code point can consist of many bytes). 2084 - * 2085 - * Like all Yrs shared data types, `YText` is resistant to the problem of interleaving (situation 2086 - * when characters inserted one after another may interleave with other peers concurrent inserts 2087 - * after merging all updates together). In case of Yrs conflict resolution is solved by using 2088 - * unique document id to determine correct and consistent ordering. 2089 - */ 2090 - class YText { 2091 - static __wrap(ptr) { 2092 - ptr = ptr >>> 0; 2093 - const obj = Object.create(YText.prototype); 2094 - obj.__wbg_ptr = ptr; 2095 - YTextFinalization.register(obj, obj.__wbg_ptr, obj); 2096 - return obj; 2097 - } 2098 - 2099 - __destroy_into_raw() { 2100 - const ptr = this.__wbg_ptr; 2101 - this.__wbg_ptr = 0; 2102 - YTextFinalization.unregister(this); 2103 - return ptr; 2104 - } 2105 - 2106 - free() { 2107 - const ptr = this.__destroy_into_raw(); 2108 - wasm.__wbg_ytext_free(ptr, 0); 2109 - } 2110 - /** 2111 - * Creates a new preliminary instance of a `YText` shared data type, with its state initialized 2112 - * to provided parameter. 2113 - * 2114 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 2115 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 2116 - * document store and cannot be nested again: attempt to do so will result in an exception. 2117 - * @param {string | null} [init] 2118 - */ 2119 - constructor(init) { 2120 - var ptr0 = isLikeNone(init) 2121 - ? 0 2122 - : passStringToWasm0( 2123 - init, 2124 - wasm.__wbindgen_malloc, 2125 - wasm.__wbindgen_realloc, 2126 - ); 2127 - var len0 = WASM_VECTOR_LEN; 2128 - const ret = wasm.ytext_new(ptr0, len0); 2129 - this.__wbg_ptr = ret >>> 0; 2130 - YTextFinalization.register(this, this.__wbg_ptr, this); 2131 - return this; 2132 - } 2133 - /** 2134 - * @returns {number} 2135 - */ 2136 - get type() { 2137 - const ret = wasm.ytext_type(this.__wbg_ptr); 2138 - return ret; 2139 - } 2140 - /** 2141 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 2142 - * document. 2143 - * @returns {any} 2144 - */ 2145 - get id() { 2146 - const ret = wasm.ytext_id(this.__wbg_ptr); 2147 - if (ret[2]) { 2148 - throw takeFromExternrefTable0(ret[1]); 2149 - } 2150 - return takeFromExternrefTable0(ret[0]); 2151 - } 2152 - /** 2153 - * Returns true if this is a preliminary instance of `YArray`. 2154 - * 2155 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 2156 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 2157 - * document store and cannot be nested again: attempt to do so will result in an exception. 2158 - * @returns {boolean} 2159 - */ 2160 - get prelim() { 2161 - const ret = wasm.ytext_prelim(this.__wbg_ptr); 2162 - return ret !== 0; 2163 - } 2164 - /** 2165 - * Checks if current YArray reference is alive and has not been deleted by its parent collection. 2166 - * This method only works on already integrated shared types and will return false is current 2167 - * type is preliminary (has not been integrated into document). 2168 - * @param {YTransaction} txn 2169 - * @returns {boolean} 2170 - */ 2171 - alive(txn) { 2172 - _assertClass(txn, YTransaction); 2173 - const ret = wasm.ytext_alive(this.__wbg_ptr, txn.__wbg_ptr); 2174 - return ret !== 0; 2175 - } 2176 - /** 2177 - * Returns length of an underlying string stored in this `YText` instance, 2178 - * understood as a number of UTF-8 encoded bytes. 2179 - * @param {YTransaction | undefined} txn 2180 - * @returns {number} 2181 - */ 2182 - length(txn) { 2183 - const ret = wasm.ytext_length(this.__wbg_ptr, txn); 2184 - if (ret[2]) { 2185 - throw takeFromExternrefTable0(ret[1]); 2186 - } 2187 - return ret[0] >>> 0; 2188 - } 2189 - /** 2190 - * Returns an underlying shared string stored in this data type. 2191 - * @param {YTransaction | undefined} txn 2192 - * @returns {string} 2193 - */ 2194 - toString(txn) { 2195 - let deferred2_0; 2196 - let deferred2_1; 2197 - try { 2198 - const ret = wasm.ytext_toString(this.__wbg_ptr, txn); 2199 - var ptr1 = ret[0]; 2200 - var len1 = ret[1]; 2201 - if (ret[3]) { 2202 - ptr1 = 0; 2203 - len1 = 0; 2204 - throw takeFromExternrefTable0(ret[2]); 2205 - } 2206 - deferred2_0 = ptr1; 2207 - deferred2_1 = len1; 2208 - return getStringFromWasm0(ptr1, len1); 2209 - } finally { 2210 - wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); 2211 - } 2212 - } 2213 - /** 2214 - * Returns an underlying shared string stored in this data type. 2215 - * @param {YTransaction | undefined} txn 2216 - * @returns {any} 2217 - */ 2218 - toJson(txn) { 2219 - const ret = wasm.ytext_toJson(this.__wbg_ptr, txn); 2220 - if (ret[2]) { 2221 - throw takeFromExternrefTable0(ret[1]); 2222 - } 2223 - return takeFromExternrefTable0(ret[0]); 2224 - } 2225 - /** 2226 - * Inserts a given `chunk` of text into this `YText` instance, starting at a given `index`. 2227 - * 2228 - * Optional object with defined `attributes` will be used to wrap provided text `chunk` 2229 - * with a formatting blocks.`attributes` are only supported for a `YText` instance which 2230 - * already has been integrated into document store. 2231 - * @param {number} index 2232 - * @param {string} chunk 2233 - * @param {any} attributes 2234 - * @param {YTransaction | undefined} txn 2235 - */ 2236 - insert(index, chunk, attributes, txn) { 2237 - const ptr0 = passStringToWasm0( 2238 - chunk, 2239 - wasm.__wbindgen_malloc, 2240 - wasm.__wbindgen_realloc, 2241 - ); 2242 - const len0 = WASM_VECTOR_LEN; 2243 - const ret = wasm.ytext_insert( 2244 - this.__wbg_ptr, 2245 - index, 2246 - ptr0, 2247 - len0, 2248 - attributes, 2249 - txn, 2250 - ); 2251 - if (ret[1]) { 2252 - throw takeFromExternrefTable0(ret[0]); 2253 - } 2254 - } 2255 - /** 2256 - * Inserts a given `embed` object into this `YText` instance, starting at a given `index`. 2257 - * 2258 - * Optional object with defined `attributes` will be used to wrap provided `embed` 2259 - * with a formatting blocks.`attributes` are only supported for a `YText` instance which 2260 - * already has been integrated into document store. 2261 - * @param {number} index 2262 - * @param {any} embed 2263 - * @param {any} attributes 2264 - * @param {YTransaction | undefined} txn 2265 - */ 2266 - insertEmbed(index, embed, attributes, txn) { 2267 - const ret = wasm.ytext_insertEmbed( 2268 - this.__wbg_ptr, 2269 - index, 2270 - embed, 2271 - attributes, 2272 - txn, 2273 - ); 2274 - if (ret[1]) { 2275 - throw takeFromExternrefTable0(ret[0]); 2276 - } 2277 - } 2278 - /** 2279 - * Wraps an existing piece of text within a range described by `index`-`length` parameters with 2280 - * formatting blocks containing provided `attributes` metadata. This method only works for 2281 - * `YText` instances that already have been integrated into document store. 2282 - * @param {number} index 2283 - * @param {number} length 2284 - * @param {any} attributes 2285 - * @param {YTransaction | undefined} txn 2286 - */ 2287 - format(index, length, attributes, txn) { 2288 - const ret = wasm.ytext_format( 2289 - this.__wbg_ptr, 2290 - index, 2291 - length, 2292 - attributes, 2293 - txn, 2294 - ); 2295 - if (ret[1]) { 2296 - throw takeFromExternrefTable0(ret[0]); 2297 - } 2298 - } 2299 - /** 2300 - * Appends a given `chunk` of text at the end of current `YText` instance. 2301 - * 2302 - * Optional object with defined `attributes` will be used to wrap provided text `chunk` 2303 - * with a formatting blocks.`attributes` are only supported for a `YText` instance which 2304 - * already has been integrated into document store. 2305 - * @param {string} chunk 2306 - * @param {any} attributes 2307 - * @param {YTransaction | undefined} txn 2308 - */ 2309 - push(chunk, attributes, txn) { 2310 - const ptr0 = passStringToWasm0( 2311 - chunk, 2312 - wasm.__wbindgen_malloc, 2313 - wasm.__wbindgen_realloc, 2314 - ); 2315 - const len0 = WASM_VECTOR_LEN; 2316 - const ret = wasm.ytext_push(this.__wbg_ptr, ptr0, len0, attributes, txn); 2317 - if (ret[1]) { 2318 - throw takeFromExternrefTable0(ret[0]); 2319 - } 2320 - } 2321 - /** 2322 - * Deletes a specified range of characters, starting at a given `index`. 2323 - * Both `index` and `length` are counted in terms of a number of UTF-8 character bytes. 2324 - * @param {number} index 2325 - * @param {number} length 2326 - * @param {YTransaction | undefined} txn 2327 - */ 2328 - delete(index, length, txn) { 2329 - const ret = wasm.ytext_delete(this.__wbg_ptr, index, length, txn); 2330 - if (ret[1]) { 2331 - throw takeFromExternrefTable0(ret[0]); 2332 - } 2333 - } 2334 - /** 2335 - * @param {number | null | undefined} lower 2336 - * @param {number | null | undefined} upper 2337 - * @param {boolean | null | undefined} lower_open 2338 - * @param {boolean | null | undefined} upper_open 2339 - * @param {YTransaction | undefined} txn 2340 - * @returns {YWeakLink} 2341 - */ 2342 - quote(lower, upper, lower_open, upper_open, txn) { 2343 - const ret = wasm.ytext_quote( 2344 - this.__wbg_ptr, 2345 - isLikeNone(lower) ? 0x100000001 : lower >>> 0, 2346 - isLikeNone(upper) ? 0x100000001 : upper >>> 0, 2347 - isLikeNone(lower_open) ? 0xffffff : lower_open ? 1 : 0, 2348 - isLikeNone(upper_open) ? 0xffffff : upper_open ? 1 : 0, 2349 - txn, 2350 - ); 2351 - if (ret[2]) { 2352 - throw takeFromExternrefTable0(ret[1]); 2353 - } 2354 - return YWeakLink.__wrap(ret[0]); 2355 - } 2356 - /** 2357 - * Returns the Delta representation of this YText type. 2358 - * @param {any} snapshot 2359 - * @param {any} prev_snapshot 2360 - * @param {Function | null | undefined} compute_ychange 2361 - * @param {YTransaction | undefined} txn 2362 - * @returns {Array<any>} 2363 - */ 2364 - toDelta(snapshot, prev_snapshot, compute_ychange, txn) { 2365 - const ret = wasm.ytext_toDelta( 2366 - this.__wbg_ptr, 2367 - snapshot, 2368 - prev_snapshot, 2369 - isLikeNone(compute_ychange) ? 0 : addToExternrefTable0(compute_ychange), 2370 - txn, 2371 - ); 2372 - if (ret[2]) { 2373 - throw takeFromExternrefTable0(ret[1]); 2374 - } 2375 - return takeFromExternrefTable0(ret[0]); 2376 - } 2377 - /** 2378 - * @param {Array<any>} delta 2379 - * @param {YTransaction | undefined} txn 2380 - */ 2381 - applyDelta(delta, txn) { 2382 - const ret = wasm.ytext_applyDelta(this.__wbg_ptr, delta, txn); 2383 - if (ret[1]) { 2384 - throw takeFromExternrefTable0(ret[0]); 2385 - } 2386 - } 2387 - /** 2388 - * Subscribes to all operations happening over this instance of `YText`. All changes are 2389 - * batched and eventually triggered during transaction commit phase. 2390 - * @param {Function} callback 2391 - */ 2392 - observe(callback) { 2393 - const ret = wasm.ytext_observe(this.__wbg_ptr, callback); 2394 - if (ret[1]) { 2395 - throw takeFromExternrefTable0(ret[0]); 2396 - } 2397 - } 2398 - /** 2399 - * Unsubscribes a callback previously subscribed with `observe` method. 2400 - * @param {Function} callback 2401 - * @returns {boolean} 2402 - */ 2403 - unobserve(callback) { 2404 - const ret = wasm.ytext_unobserve(this.__wbg_ptr, callback); 2405 - if (ret[2]) { 2406 - throw takeFromExternrefTable0(ret[1]); 2407 - } 2408 - return ret[0] !== 0; 2409 - } 2410 - /** 2411 - * Subscribes to all operations happening over this Y shared type, as well as events in 2412 - * shared types stored within this one. All changes are batched and eventually triggered 2413 - * during transaction commit phase. 2414 - * @param {Function} callback 2415 - */ 2416 - observeDeep(callback) { 2417 - const ret = wasm.ytext_observeDeep(this.__wbg_ptr, callback); 2418 - if (ret[1]) { 2419 - throw takeFromExternrefTable0(ret[0]); 2420 - } 2421 - } 2422 - /** 2423 - * Unsubscribes a callback previously subscribed with `observeDeep` method. 2424 - * @param {Function} callback 2425 - * @returns {boolean} 2426 - */ 2427 - unobserveDeep(callback) { 2428 - const ret = wasm.ytext_unobserveDeep(this.__wbg_ptr, callback); 2429 - if (ret[2]) { 2430 - throw takeFromExternrefTable0(ret[1]); 2431 - } 2432 - return ret[0] !== 0; 2433 - } 2434 - } 2435 - module.exports.YText = YText; 2436 - 2437 - const YTextEventFinalization = 2438 - typeof FinalizationRegistry === "undefined" 2439 - ? { register: () => {}, unregister: () => {} } 2440 - : new FinalizationRegistry((ptr) => 2441 - wasm.__wbg_ytextevent_free(ptr >>> 0, 1), 2442 - ); 2443 - /** 2444 - * Event generated by `YYText.observe` method. Emitted during transaction commit phase. 2445 - */ 2446 - class YTextEvent { 2447 - static __wrap(ptr) { 2448 - ptr = ptr >>> 0; 2449 - const obj = Object.create(YTextEvent.prototype); 2450 - obj.__wbg_ptr = ptr; 2451 - YTextEventFinalization.register(obj, obj.__wbg_ptr, obj); 2452 - return obj; 2453 - } 2454 - 2455 - __destroy_into_raw() { 2456 - const ptr = this.__wbg_ptr; 2457 - this.__wbg_ptr = 0; 2458 - YTextEventFinalization.unregister(this); 2459 - return ptr; 2460 - } 2461 - 2462 - free() { 2463 - const ptr = this.__destroy_into_raw(); 2464 - wasm.__wbg_ytextevent_free(ptr, 0); 2465 - } 2466 - /** 2467 - * Returns an array of keys and indexes creating a path from root type down to current instance 2468 - * of shared type (accessible via `target` getter). 2469 - * @returns {any} 2470 - */ 2471 - path() { 2472 - const ret = wasm.ytextevent_path(this.__wbg_ptr); 2473 - return ret; 2474 - } 2475 - /** 2476 - * Returns a current shared type instance, that current event changes refer to. 2477 - * @returns {any} 2478 - */ 2479 - get target() { 2480 - const ret = wasm.ytextevent_target(this.__wbg_ptr); 2481 - return ret; 2482 - } 2483 - /** 2484 - * @returns {any} 2485 - */ 2486 - get origin() { 2487 - const ret = wasm.ytextevent_origin(this.__wbg_ptr); 2488 - return ret; 2489 - } 2490 - /** 2491 - * Returns a list of text changes made over corresponding `YText` collection within 2492 - * bounds of current transaction. These changes follow a format: 2493 - * 2494 - * - { insert: string, attributes: any|undefined } 2495 - * - { delete: number } 2496 - * - { retain: number, attributes: any|undefined } 2497 - * @returns {any} 2498 - */ 2499 - get delta() { 2500 - const ret = wasm.ytextevent_delta(this.__wbg_ptr); 2501 - if (ret[2]) { 2502 - throw takeFromExternrefTable0(ret[1]); 2503 - } 2504 - return takeFromExternrefTable0(ret[0]); 2505 - } 2506 - } 2507 - module.exports.YTextEvent = YTextEvent; 2508 - 2509 - const YTransactionFinalization = 2510 - typeof FinalizationRegistry === "undefined" 2511 - ? { register: () => {}, unregister: () => {} } 2512 - : new FinalizationRegistry((ptr) => 2513 - wasm.__wbg_ytransaction_free(ptr >>> 0, 1), 2514 - ); 2515 - 2516 - class YTransaction { 2517 - static __wrap(ptr) { 2518 - ptr = ptr >>> 0; 2519 - const obj = Object.create(YTransaction.prototype); 2520 - obj.__wbg_ptr = ptr; 2521 - YTransactionFinalization.register(obj, obj.__wbg_ptr, obj); 2522 - return obj; 2523 - } 2524 - 2525 - __destroy_into_raw() { 2526 - const ptr = this.__wbg_ptr; 2527 - this.__wbg_ptr = 0; 2528 - YTransactionFinalization.unregister(this); 2529 - return ptr; 2530 - } 2531 - 2532 - free() { 2533 - const ptr = this.__destroy_into_raw(); 2534 - wasm.__wbg_ytransaction_free(ptr, 0); 2535 - } 2536 - /** 2537 - * Returns state vector describing the state of the document 2538 - * at the moment when the transaction began. 2539 - * @returns {Map<any, any>} 2540 - */ 2541 - get beforeState() { 2542 - const ret = wasm.ytransaction_beforeState(this.__wbg_ptr); 2543 - return ret; 2544 - } 2545 - /** 2546 - * Returns state vector describing the current state of 2547 - * the document. 2548 - * @returns {Map<any, any>} 2549 - */ 2550 - get afterState() { 2551 - const ret = wasm.ytransaction_afterState(this.__wbg_ptr); 2552 - return ret; 2553 - } 2554 - /** 2555 - * @returns {any} 2556 - */ 2557 - get pendingStructs() { 2558 - const ret = wasm.ytransaction_pendingStructs(this.__wbg_ptr); 2559 - if (ret[2]) { 2560 - throw takeFromExternrefTable0(ret[1]); 2561 - } 2562 - return takeFromExternrefTable0(ret[0]); 2563 - } 2564 - /** 2565 - * Returns a unapplied delete set, that was received in one of the previous remote updates. 2566 - * This DeleteSet is waiting for a missing updates to arrive in order to be applied. 2567 - * @returns {Map<any, any> | undefined} 2568 - */ 2569 - get pendingDeleteSet() { 2570 - const ret = wasm.ytransaction_pendingDeleteSet(this.__wbg_ptr); 2571 - return ret; 2572 - } 2573 - /** 2574 - * Returns a delete set containing information about 2575 - * all blocks removed as part of a current transaction. 2576 - * @returns {Map<any, any>} 2577 - */ 2578 - get deleteSet() { 2579 - const ret = wasm.ytransaction_deleteSet(this.__wbg_ptr); 2580 - return ret; 2581 - } 2582 - /** 2583 - * @returns {any} 2584 - */ 2585 - get origin() { 2586 - const ret = wasm.ytransaction_origin(this.__wbg_ptr); 2587 - return ret; 2588 - } 2589 - /** 2590 - * Given a logical identifier of the collection (obtained via `YText.id`, `YArray.id` etc.), 2591 - * attempts to return an instance of that collection in the scope of current document. 2592 - * 2593 - * Returns `undefined` if an instance was not defined locally, haven't been integrated or 2594 - * has been deleted. 2595 - * @param {any} id 2596 - * @returns {any} 2597 - */ 2598 - get(id) { 2599 - const ret = wasm.ytransaction_get(this.__wbg_ptr, id); 2600 - if (ret[2]) { 2601 - throw takeFromExternrefTable0(ret[1]); 2602 - } 2603 - return takeFromExternrefTable0(ret[0]); 2604 - } 2605 - /** 2606 - * Triggers a post-update series of operations without `free`ing the transaction. This includes 2607 - * compaction and optimization of internal representation of updates, triggering events etc. 2608 - * ywasm transactions are auto-committed when they are `free`d. 2609 - */ 2610 - commit() { 2611 - const ret = wasm.ytransaction_commit(this.__wbg_ptr); 2612 - if (ret[1]) { 2613 - throw takeFromExternrefTable0(ret[0]); 2614 - } 2615 - } 2616 - /** 2617 - * Encodes a state vector of a given transaction document into its binary representation using 2618 - * lib0 v1 encoding. State vector is a compact representation of updates performed on a given 2619 - * document and can be used by `encode_state_as_update` on remote peer to generate a delta 2620 - * update payload to synchronize changes between peers. 2621 - * 2622 - * Example: 2623 - * 2624 - * ```javascript 2625 - * import YDoc from 'ywasm' 2626 - * 2627 - * /// document on machine A 2628 - * const localDoc = new YDoc() 2629 - * const localTxn = localDoc.beginTransaction() 2630 - * 2631 - * // document on machine B 2632 - * const remoteDoc = new YDoc() 2633 - * const remoteTxn = localDoc.beginTransaction() 2634 - * 2635 - * try { 2636 - * const localSV = localTxn.stateVectorV1() 2637 - * const remoteDelta = remoteTxn.diffV1(localSv) 2638 - * localTxn.applyV1(remoteDelta) 2639 - * } finally { 2640 - * localTxn.free() 2641 - * remoteTxn.free() 2642 - * } 2643 - * ``` 2644 - * @returns {Uint8Array} 2645 - */ 2646 - stateVectorV1() { 2647 - const ret = wasm.ytransaction_stateVectorV1(this.__wbg_ptr); 2648 - return ret; 2649 - } 2650 - /** 2651 - * Encodes all updates that have happened since a given version `vector` into a compact delta 2652 - * representation using lib0 v1 encoding. If `vector` parameter has not been provided, generated 2653 - * delta payload will contain all changes of a current ywasm document, working effectively as 2654 - * its state snapshot. 2655 - * 2656 - * Example: 2657 - * 2658 - * ```javascript 2659 - * import YDoc from 'ywasm' 2660 - * 2661 - * /// document on machine A 2662 - * const localDoc = new YDoc() 2663 - * const localTxn = localDoc.beginTransaction() 2664 - * 2665 - * // document on machine B 2666 - * const remoteDoc = new YDoc() 2667 - * const remoteTxn = localDoc.beginTransaction() 2668 - * 2669 - * try { 2670 - * const localSV = localTxn.stateVectorV1() 2671 - * const remoteDelta = remoteTxn.diffV1(localSv) 2672 - * localTxn.applyV1(remoteDelta) 2673 - * } finally { 2674 - * localTxn.free() 2675 - * remoteTxn.free() 2676 - * } 2677 - * ``` 2678 - * @param {Uint8Array | null} [vector] 2679 - * @returns {Uint8Array} 2680 - */ 2681 - diffV1(vector) { 2682 - const ret = wasm.ytransaction_diffV1( 2683 - this.__wbg_ptr, 2684 - isLikeNone(vector) ? 0 : addToExternrefTable0(vector), 2685 - ); 2686 - if (ret[2]) { 2687 - throw takeFromExternrefTable0(ret[1]); 2688 - } 2689 - return takeFromExternrefTable0(ret[0]); 2690 - } 2691 - /** 2692 - * Encodes all updates that have happened since a given version `vector` into a compact delta 2693 - * representation using lib0 v1 encoding. If `vector` parameter has not been provided, generated 2694 - * delta payload will contain all changes of a current ywasm document, working effectively as 2695 - * its state snapshot. 2696 - * 2697 - * Example: 2698 - * 2699 - * ```javascript 2700 - * import YDoc from 'ywasm' 2701 - * 2702 - * /// document on machine A 2703 - * const localDoc = new YDoc() 2704 - * const localTxn = localDoc.beginTransaction() 2705 - * 2706 - * // document on machine B 2707 - * const remoteDoc = new YDoc() 2708 - * const remoteTxn = localDoc.beginTransaction() 2709 - * 2710 - * try { 2711 - * const localSV = localTxn.stateVectorV1() 2712 - * const remoteDelta = remoteTxn.diffV2(localSv) 2713 - * localTxn.applyV2(remoteDelta) 2714 - * } finally { 2715 - * localTxn.free() 2716 - * remoteTxn.free() 2717 - * } 2718 - * ``` 2719 - * @param {Uint8Array | null} [vector] 2720 - * @returns {Uint8Array} 2721 - */ 2722 - diffV2(vector) { 2723 - const ret = wasm.ytransaction_diffV2( 2724 - this.__wbg_ptr, 2725 - isLikeNone(vector) ? 0 : addToExternrefTable0(vector), 2726 - ); 2727 - if (ret[2]) { 2728 - throw takeFromExternrefTable0(ret[1]); 2729 - } 2730 - return takeFromExternrefTable0(ret[0]); 2731 - } 2732 - /** 2733 - * Applies delta update generated by the remote document replica to a current transaction's 2734 - * document. This method assumes that a payload maintains lib0 v1 encoding format. 2735 - * 2736 - * Example: 2737 - * 2738 - * ```javascript 2739 - * import YDoc from 'ywasm' 2740 - * 2741 - * /// document on machine A 2742 - * const localDoc = new YDoc() 2743 - * const localTxn = localDoc.beginTransaction() 2744 - * 2745 - * // document on machine B 2746 - * const remoteDoc = new YDoc() 2747 - * const remoteTxn = localDoc.beginTransaction() 2748 - * 2749 - * try { 2750 - * const localSV = localTxn.stateVectorV1() 2751 - * const remoteDelta = remoteTxn.diffV1(localSv) 2752 - * localTxn.applyV1(remoteDelta) 2753 - * } finally { 2754 - * localTxn.free() 2755 - * remoteTxn.free() 2756 - * } 2757 - * ``` 2758 - * @param {Uint8Array} diff 2759 - */ 2760 - applyV1(diff) { 2761 - const ret = wasm.ytransaction_applyV1(this.__wbg_ptr, diff); 2762 - if (ret[1]) { 2763 - throw takeFromExternrefTable0(ret[0]); 2764 - } 2765 - } 2766 - /** 2767 - * Applies delta update generated by the remote document replica to a current transaction's 2768 - * document. This method assumes that a payload maintains lib0 v2 encoding format. 2769 - * 2770 - * Example: 2771 - * 2772 - * ```javascript 2773 - * import YDoc from 'ywasm' 2774 - * 2775 - * /// document on machine A 2776 - * const localDoc = new YDoc() 2777 - * const localTxn = localDoc.beginTransaction() 2778 - * 2779 - * // document on machine B 2780 - * const remoteDoc = new YDoc() 2781 - * const remoteTxn = localDoc.beginTransaction() 2782 - * 2783 - * try { 2784 - * const localSV = localTxn.stateVectorV1() 2785 - * const remoteDelta = remoteTxn.diffV2(localSv) 2786 - * localTxn.applyV2(remoteDelta) 2787 - * } finally { 2788 - * localTxn.free() 2789 - * remoteTxn.free() 2790 - * } 2791 - * ``` 2792 - * @param {Uint8Array} diff 2793 - */ 2794 - applyV2(diff) { 2795 - const ret = wasm.ytransaction_applyV2(this.__wbg_ptr, diff); 2796 - if (ret[1]) { 2797 - throw takeFromExternrefTable0(ret[0]); 2798 - } 2799 - } 2800 - /** 2801 - * @returns {Uint8Array} 2802 - */ 2803 - encodeUpdate() { 2804 - const ret = wasm.ytransaction_encodeUpdate(this.__wbg_ptr); 2805 - return ret; 2806 - } 2807 - /** 2808 - * @returns {Uint8Array} 2809 - */ 2810 - encodeUpdateV2() { 2811 - const ret = wasm.ytransaction_encodeUpdateV2(this.__wbg_ptr); 2812 - return ret; 2813 - } 2814 - /** 2815 - * Force garbage collection of the deleted elements, regardless of a parent doc was created 2816 - * with `gc` option turned on or off. 2817 - */ 2818 - gc() { 2819 - const ret = wasm.ytransaction_gc(this.__wbg_ptr); 2820 - if (ret[1]) { 2821 - throw takeFromExternrefTable0(ret[0]); 2822 - } 2823 - } 2824 - /** 2825 - * Evaluates a JSON path expression (see: https://en.wikipedia.org/wiki/JSONPath) on 2826 - * the document and returns an array of values matching that query. 2827 - * 2828 - * Currently, this method supports the following syntax: 2829 - * - `$` - root object 2830 - * - `@` - current object 2831 - * - `.field` or `['field']` - member accessor 2832 - * - `[1]` - array index (also supports negative indices) 2833 - * - `.*` or `[*]` - wildcard (matches all members of an object or array) 2834 - * - `..` - recursive descent (matches all descendants not only direct children) 2835 - * - `[start:end:step]` - array slice operator (requires positive integer arguments) 2836 - * - `['a', 'b', 'c']` - union operator (returns an array of values for each query) 2837 - * - `[1, -1, 3]` - multiple indices operator (returns an array of values for each index) 2838 - * 2839 - * At the moment, JSON Path does not support filter predicates. 2840 - * @param {string} json_path 2841 - * @returns {Array<any>} 2842 - */ 2843 - selectAll(json_path) { 2844 - const ptr0 = passStringToWasm0( 2845 - json_path, 2846 - wasm.__wbindgen_malloc, 2847 - wasm.__wbindgen_realloc, 2848 - ); 2849 - const len0 = WASM_VECTOR_LEN; 2850 - const ret = wasm.ytransaction_selectAll(this.__wbg_ptr, ptr0, len0); 2851 - if (ret[2]) { 2852 - throw takeFromExternrefTable0(ret[1]); 2853 - } 2854 - return takeFromExternrefTable0(ret[0]); 2855 - } 2856 - /** 2857 - * Evaluates a JSON path expression (see: https://en.wikipedia.org/wiki/JSONPath) on 2858 - * the document and returns first value matching that query. 2859 - * 2860 - * Currently, this method supports the following syntax: 2861 - * - `$` - root object 2862 - * - `@` - current object 2863 - * - `.field` or `['field']` - member accessor 2864 - * - `[1]` - array index (also supports negative indices) 2865 - * - `.*` or `[*]` - wildcard (matches all members of an object or array) 2866 - * - `..` - recursive descent (matches all descendants not only direct children) 2867 - * - `[start:end:step]` - array slice operator (requires positive integer arguments) 2868 - * - `['a', 'b', 'c']` - union operator (returns an array of values for each query) 2869 - * - `[1, -1, 3]` - multiple indices operator (returns an array of values for each index) 2870 - * 2871 - * At the moment, JSON Path does not support filter predicates. 2872 - * @param {string} json_path 2873 - * @returns {any} 2874 - */ 2875 - selectOne(json_path) { 2876 - const ptr0 = passStringToWasm0( 2877 - json_path, 2878 - wasm.__wbindgen_malloc, 2879 - wasm.__wbindgen_realloc, 2880 - ); 2881 - const len0 = WASM_VECTOR_LEN; 2882 - const ret = wasm.ytransaction_selectOne(this.__wbg_ptr, ptr0, len0); 2883 - if (ret[2]) { 2884 - throw takeFromExternrefTable0(ret[1]); 2885 - } 2886 - return takeFromExternrefTable0(ret[0]); 2887 - } 2888 - } 2889 - module.exports.YTransaction = YTransaction; 2890 - 2891 - const YUndoEventFinalization = 2892 - typeof FinalizationRegistry === "undefined" 2893 - ? { register: () => {}, unregister: () => {} } 2894 - : new FinalizationRegistry((ptr) => 2895 - wasm.__wbg_yundoevent_free(ptr >>> 0, 1), 2896 - ); 2897 - 2898 - class YUndoEvent { 2899 - static __wrap(ptr) { 2900 - ptr = ptr >>> 0; 2901 - const obj = Object.create(YUndoEvent.prototype); 2902 - obj.__wbg_ptr = ptr; 2903 - YUndoEventFinalization.register(obj, obj.__wbg_ptr, obj); 2904 - return obj; 2905 - } 2906 - 2907 - __destroy_into_raw() { 2908 - const ptr = this.__wbg_ptr; 2909 - this.__wbg_ptr = 0; 2910 - YUndoEventFinalization.unregister(this); 2911 - return ptr; 2912 - } 2913 - 2914 - free() { 2915 - const ptr = this.__destroy_into_raw(); 2916 - wasm.__wbg_yundoevent_free(ptr, 0); 2917 - } 2918 - /** 2919 - * @returns {any} 2920 - */ 2921 - get origin() { 2922 - const ret = wasm.yundoevent_origin(this.__wbg_ptr); 2923 - return ret; 2924 - } 2925 - /** 2926 - * @returns {any} 2927 - */ 2928 - get kind() { 2929 - const ret = wasm.yundoevent_kind(this.__wbg_ptr); 2930 - return ret; 2931 - } 2932 - /** 2933 - * @returns {any} 2934 - */ 2935 - get meta() { 2936 - const ret = wasm.yundoevent_meta(this.__wbg_ptr); 2937 - return ret; 2938 - } 2939 - /** 2940 - * @param {any} value 2941 - */ 2942 - set meta(value) { 2943 - wasm.yundoevent_set_meta(this.__wbg_ptr, value); 2944 - } 2945 - } 2946 - module.exports.YUndoEvent = YUndoEvent; 2947 - 2948 - const YUndoManagerFinalization = 2949 - typeof FinalizationRegistry === "undefined" 2950 - ? { register: () => {}, unregister: () => {} } 2951 - : new FinalizationRegistry((ptr) => 2952 - wasm.__wbg_yundomanager_free(ptr >>> 0, 1), 2953 - ); 2954 - 2955 - class YUndoManager { 2956 - __destroy_into_raw() { 2957 - const ptr = this.__wbg_ptr; 2958 - this.__wbg_ptr = 0; 2959 - YUndoManagerFinalization.unregister(this); 2960 - return ptr; 2961 - } 2962 - 2963 - free() { 2964 - const ptr = this.__destroy_into_raw(); 2965 - wasm.__wbg_yundomanager_free(ptr, 0); 2966 - } 2967 - /** 2968 - * @param {YDoc} doc 2969 - * @param {any} scope 2970 - * @param {any} options 2971 - */ 2972 - constructor(doc, scope, options) { 2973 - _assertClass(doc, YDoc); 2974 - const ret = wasm.yundomanager_new(doc.__wbg_ptr, scope, options); 2975 - if (ret[2]) { 2976 - throw takeFromExternrefTable0(ret[1]); 2977 - } 2978 - this.__wbg_ptr = ret[0] >>> 0; 2979 - YUndoManagerFinalization.register(this, this.__wbg_ptr, this); 2980 - return this; 2981 - } 2982 - /** 2983 - * @param {Array<any>} ytypes 2984 - */ 2985 - addToScope(ytypes) { 2986 - const ret = wasm.yundomanager_addToScope(this.__wbg_ptr, ytypes); 2987 - if (ret[1]) { 2988 - throw takeFromExternrefTable0(ret[0]); 2989 - } 2990 - } 2991 - /** 2992 - * @param {any} origin 2993 - */ 2994 - addTrackedOrigin(origin) { 2995 - wasm.yundomanager_addTrackedOrigin(this.__wbg_ptr, origin); 2996 - } 2997 - /** 2998 - * @param {any} origin 2999 - */ 3000 - removeTrackedOrigin(origin) { 3001 - wasm.yundomanager_removeTrackedOrigin(this.__wbg_ptr, origin); 3002 - } 3003 - clear() { 3004 - wasm.yundomanager_clear(this.__wbg_ptr); 3005 - } 3006 - stopCapturing() { 3007 - wasm.yundomanager_stopCapturing(this.__wbg_ptr); 3008 - } 3009 - undo() { 3010 - const ret = wasm.yundomanager_undo(this.__wbg_ptr); 3011 - if (ret[1]) { 3012 - throw takeFromExternrefTable0(ret[0]); 3013 - } 3014 - } 3015 - redo() { 3016 - const ret = wasm.yundomanager_redo(this.__wbg_ptr); 3017 - if (ret[1]) { 3018 - throw takeFromExternrefTable0(ret[0]); 3019 - } 3020 - } 3021 - /** 3022 - * @returns {boolean} 3023 - */ 3024 - get canUndo() { 3025 - const ret = wasm.yundomanager_canUndo(this.__wbg_ptr); 3026 - return ret !== 0; 3027 - } 3028 - /** 3029 - * @returns {boolean} 3030 - */ 3031 - get canRedo() { 3032 - const ret = wasm.yundomanager_canRedo(this.__wbg_ptr); 3033 - return ret !== 0; 3034 - } 3035 - /** 3036 - * @param {string} event 3037 - * @param {Function} callback 3038 - */ 3039 - on(event, callback) { 3040 - const ptr0 = passStringToWasm0( 3041 - event, 3042 - wasm.__wbindgen_malloc, 3043 - wasm.__wbindgen_realloc, 3044 - ); 3045 - const len0 = WASM_VECTOR_LEN; 3046 - const ret = wasm.yundomanager_on(this.__wbg_ptr, ptr0, len0, callback); 3047 - if (ret[1]) { 3048 - throw takeFromExternrefTable0(ret[0]); 3049 - } 3050 - } 3051 - /** 3052 - * @param {string} event 3053 - * @param {Function} callback 3054 - * @returns {boolean} 3055 - */ 3056 - off(event, callback) { 3057 - const ptr0 = passStringToWasm0( 3058 - event, 3059 - wasm.__wbindgen_malloc, 3060 - wasm.__wbindgen_realloc, 3061 - ); 3062 - const len0 = WASM_VECTOR_LEN; 3063 - const ret = wasm.yundomanager_off(this.__wbg_ptr, ptr0, len0, callback); 3064 - if (ret[2]) { 3065 - throw takeFromExternrefTable0(ret[1]); 3066 - } 3067 - return ret[0] !== 0; 3068 - } 3069 - } 3070 - module.exports.YUndoManager = YUndoManager; 3071 - 3072 - const YWeakLinkFinalization = 3073 - typeof FinalizationRegistry === "undefined" 3074 - ? { register: () => {}, unregister: () => {} } 3075 - : new FinalizationRegistry((ptr) => 3076 - wasm.__wbg_yweaklink_free(ptr >>> 0, 1), 3077 - ); 3078 - 3079 - class YWeakLink { 3080 - static __wrap(ptr) { 3081 - ptr = ptr >>> 0; 3082 - const obj = Object.create(YWeakLink.prototype); 3083 - obj.__wbg_ptr = ptr; 3084 - YWeakLinkFinalization.register(obj, obj.__wbg_ptr, obj); 3085 - return obj; 3086 - } 3087 - 3088 - __destroy_into_raw() { 3089 - const ptr = this.__wbg_ptr; 3090 - this.__wbg_ptr = 0; 3091 - YWeakLinkFinalization.unregister(this); 3092 - return ptr; 3093 - } 3094 - 3095 - free() { 3096 - const ptr = this.__destroy_into_raw(); 3097 - wasm.__wbg_yweaklink_free(ptr, 0); 3098 - } 3099 - /** 3100 - * Returns true if this is a preliminary instance of `YWeakLink`. 3101 - * 3102 - * Preliminary instances can be nested into other shared data types such as `YArray` and `YMap`. 3103 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 3104 - * document store and cannot be nested again: attempt to do so will result in an exception. 3105 - * @returns {boolean} 3106 - */ 3107 - get prelim() { 3108 - const ret = wasm.yweaklink_prelim(this.__wbg_ptr); 3109 - return ret !== 0; 3110 - } 3111 - /** 3112 - * @returns {number} 3113 - */ 3114 - get type() { 3115 - const ret = wasm.yweaklink_type(this.__wbg_ptr); 3116 - return ret; 3117 - } 3118 - /** 3119 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 3120 - * document. 3121 - * @returns {any} 3122 - */ 3123 - get id() { 3124 - const ret = wasm.yweaklink_id(this.__wbg_ptr); 3125 - if (ret[2]) { 3126 - throw takeFromExternrefTable0(ret[1]); 3127 - } 3128 - return takeFromExternrefTable0(ret[0]); 3129 - } 3130 - /** 3131 - * Checks if current YWeakLink reference is alive and has not been deleted by its parent collection. 3132 - * This method only works on already integrated shared types and will return false is current 3133 - * type is preliminary (has not been integrated into document). 3134 - * @param {YTransaction} txn 3135 - * @returns {boolean} 3136 - */ 3137 - alive(txn) { 3138 - _assertClass(txn, YTransaction); 3139 - const ret = wasm.yweaklink_alive(this.__wbg_ptr, txn.__wbg_ptr); 3140 - return ret !== 0; 3141 - } 3142 - /** 3143 - * @param {YTransaction | undefined} txn 3144 - * @returns {any} 3145 - */ 3146 - deref(txn) { 3147 - const ret = wasm.yweaklink_deref(this.__wbg_ptr, txn); 3148 - if (ret[2]) { 3149 - throw takeFromExternrefTable0(ret[1]); 3150 - } 3151 - return takeFromExternrefTable0(ret[0]); 3152 - } 3153 - /** 3154 - * @param {YTransaction | undefined} txn 3155 - * @returns {Array<any>} 3156 - */ 3157 - unquote(txn) { 3158 - const ret = wasm.yweaklink_unquote(this.__wbg_ptr, txn); 3159 - if (ret[2]) { 3160 - throw takeFromExternrefTable0(ret[1]); 3161 - } 3162 - return takeFromExternrefTable0(ret[0]); 3163 - } 3164 - /** 3165 - * @param {YTransaction | undefined} txn 3166 - * @returns {string} 3167 - */ 3168 - toString(txn) { 3169 - let deferred2_0; 3170 - let deferred2_1; 3171 - try { 3172 - const ret = wasm.yweaklink_toString(this.__wbg_ptr, txn); 3173 - var ptr1 = ret[0]; 3174 - var len1 = ret[1]; 3175 - if (ret[3]) { 3176 - ptr1 = 0; 3177 - len1 = 0; 3178 - throw takeFromExternrefTable0(ret[2]); 3179 - } 3180 - deferred2_0 = ptr1; 3181 - deferred2_1 = len1; 3182 - return getStringFromWasm0(ptr1, len1); 3183 - } finally { 3184 - wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); 3185 - } 3186 - } 3187 - /** 3188 - * Subscribes to all operations happening over this instance of `YMap`. All changes are 3189 - * batched and eventually triggered during transaction commit phase. 3190 - * @param {Function} callback 3191 - */ 3192 - observe(callback) { 3193 - const ret = wasm.yweaklink_observe(this.__wbg_ptr, callback); 3194 - if (ret[1]) { 3195 - throw takeFromExternrefTable0(ret[0]); 3196 - } 3197 - } 3198 - /** 3199 - * Unsubscribes a callback previously subscribed with `observe` method. 3200 - * @param {Function} callback 3201 - * @returns {boolean} 3202 - */ 3203 - unobserve(callback) { 3204 - const ret = wasm.yweaklink_unobserve(this.__wbg_ptr, callback); 3205 - if (ret[2]) { 3206 - throw takeFromExternrefTable0(ret[1]); 3207 - } 3208 - return ret[0] !== 0; 3209 - } 3210 - /** 3211 - * Subscribes to all operations happening over this Y shared type, as well as events in 3212 - * shared types stored within this one. All changes are batched and eventually triggered 3213 - * during transaction commit phase. 3214 - * @param {Function} callback 3215 - */ 3216 - observeDeep(callback) { 3217 - const ret = wasm.yweaklink_observeDeep(this.__wbg_ptr, callback); 3218 - if (ret[1]) { 3219 - throw takeFromExternrefTable0(ret[0]); 3220 - } 3221 - } 3222 - /** 3223 - * Unsubscribes a callback previously subscribed with `observeDeep` method. 3224 - * @param {Function} callback 3225 - * @returns {boolean} 3226 - */ 3227 - unobserveDeep(callback) { 3228 - const ret = wasm.yweaklink_unobserveDeep(this.__wbg_ptr, callback); 3229 - if (ret[2]) { 3230 - throw takeFromExternrefTable0(ret[1]); 3231 - } 3232 - return ret[0] !== 0; 3233 - } 3234 - } 3235 - module.exports.YWeakLink = YWeakLink; 3236 - 3237 - const YWeakLinkEventFinalization = 3238 - typeof FinalizationRegistry === "undefined" 3239 - ? { register: () => {}, unregister: () => {} } 3240 - : new FinalizationRegistry((ptr) => 3241 - wasm.__wbg_yweaklinkevent_free(ptr >>> 0, 1), 3242 - ); 3243 - /** 3244 - * Event generated by `YXmlElement.observe` method. Emitted during transaction commit phase. 3245 - */ 3246 - class YWeakLinkEvent { 3247 - static __wrap(ptr) { 3248 - ptr = ptr >>> 0; 3249 - const obj = Object.create(YWeakLinkEvent.prototype); 3250 - obj.__wbg_ptr = ptr; 3251 - YWeakLinkEventFinalization.register(obj, obj.__wbg_ptr, obj); 3252 - return obj; 3253 - } 3254 - 3255 - __destroy_into_raw() { 3256 - const ptr = this.__wbg_ptr; 3257 - this.__wbg_ptr = 0; 3258 - YWeakLinkEventFinalization.unregister(this); 3259 - return ptr; 3260 - } 3261 - 3262 - free() { 3263 - const ptr = this.__destroy_into_raw(); 3264 - wasm.__wbg_yweaklinkevent_free(ptr, 0); 3265 - } 3266 - /** 3267 - * @returns {any} 3268 - */ 3269 - get origin() { 3270 - const ret = wasm.yweaklinkevent_origin(this.__wbg_ptr); 3271 - return ret; 3272 - } 3273 - /** 3274 - * Returns a current shared type instance, that current event changes refer to. 3275 - * @returns {any} 3276 - */ 3277 - get target() { 3278 - const ret = wasm.yweaklinkevent_target(this.__wbg_ptr); 3279 - return ret; 3280 - } 3281 - /** 3282 - * Returns an array of keys and indexes creating a path from root type down to current instance 3283 - * of shared type (accessible via `target` getter). 3284 - * @returns {any} 3285 - */ 3286 - path() { 3287 - const ret = wasm.yweaklinkevent_path(this.__wbg_ptr); 3288 - return ret; 3289 - } 3290 - } 3291 - module.exports.YWeakLinkEvent = YWeakLinkEvent; 3292 - 3293 - const YXmlElementFinalization = 3294 - typeof FinalizationRegistry === "undefined" 3295 - ? { register: () => {}, unregister: () => {} } 3296 - : new FinalizationRegistry((ptr) => 3297 - wasm.__wbg_yxmlelement_free(ptr >>> 0, 1), 3298 - ); 3299 - /** 3300 - * XML element data type. It represents an XML node, which can contain key-value attributes 3301 - * (interpreted as strings) as well as other nested XML elements or rich text (represented by 3302 - * `YXmlText` type). 3303 - * 3304 - * In terms of conflict resolution, `YXmlElement` uses following rules: 3305 - * 3306 - * - Attribute updates use logical last-write-wins principle, meaning the past updates are 3307 - * automatically overridden and discarded by newer ones, while concurrent updates made by 3308 - * different peers are resolved into a single value using document id seniority to establish 3309 - * an order. 3310 - * - Child node insertion uses sequencing rules from other Yrs collections - elements are inserted 3311 - * using interleave-resistant algorithm, where order of concurrent inserts at the same index 3312 - * is established using peer's document id seniority. 3313 - */ 3314 - class YXmlElement { 3315 - static __wrap(ptr) { 3316 - ptr = ptr >>> 0; 3317 - const obj = Object.create(YXmlElement.prototype); 3318 - obj.__wbg_ptr = ptr; 3319 - YXmlElementFinalization.register(obj, obj.__wbg_ptr, obj); 3320 - return obj; 3321 - } 3322 - 3323 - __destroy_into_raw() { 3324 - const ptr = this.__wbg_ptr; 3325 - this.__wbg_ptr = 0; 3326 - YXmlElementFinalization.unregister(this); 3327 - return ptr; 3328 - } 3329 - 3330 - free() { 3331 - const ptr = this.__destroy_into_raw(); 3332 - wasm.__wbg_yxmlelement_free(ptr, 0); 3333 - } 3334 - /** 3335 - * @param {string} name 3336 - * @param {any} attributes 3337 - * @param {any} children 3338 - */ 3339 - constructor(name, attributes, children) { 3340 - const ptr0 = passStringToWasm0( 3341 - name, 3342 - wasm.__wbindgen_malloc, 3343 - wasm.__wbindgen_realloc, 3344 - ); 3345 - const len0 = WASM_VECTOR_LEN; 3346 - const ret = wasm.yxmlelement_new(ptr0, len0, attributes, children); 3347 - if (ret[2]) { 3348 - throw takeFromExternrefTable0(ret[1]); 3349 - } 3350 - this.__wbg_ptr = ret[0] >>> 0; 3351 - YXmlElementFinalization.register(this, this.__wbg_ptr, this); 3352 - return this; 3353 - } 3354 - /** 3355 - * @returns {number} 3356 - */ 3357 - get type() { 3358 - const ret = wasm.yxmlelement_type(this.__wbg_ptr); 3359 - return ret; 3360 - } 3361 - /** 3362 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 3363 - * document. 3364 - * @returns {any} 3365 - */ 3366 - get id() { 3367 - const ret = wasm.yxmlelement_id(this.__wbg_ptr); 3368 - if (ret[2]) { 3369 - throw takeFromExternrefTable0(ret[1]); 3370 - } 3371 - return takeFromExternrefTable0(ret[0]); 3372 - } 3373 - /** 3374 - * Returns true if this is a preliminary instance of `YXmlElement`. 3375 - * 3376 - * Preliminary instances can be nested into other shared data types. 3377 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 3378 - * document store and cannot be nested again: attempt to do so will result in an exception. 3379 - * @returns {boolean} 3380 - */ 3381 - get prelim() { 3382 - const ret = wasm.yxmlelement_prelim(this.__wbg_ptr); 3383 - return ret !== 0; 3384 - } 3385 - /** 3386 - * Checks if current shared type reference is alive and has not been deleted by its parent collection. 3387 - * This method only works on already integrated shared types and will return false is current 3388 - * type is preliminary (has not been integrated into document). 3389 - * @param {YTransaction} txn 3390 - * @returns {boolean} 3391 - */ 3392 - alive(txn) { 3393 - _assertClass(txn, YTransaction); 3394 - const ret = wasm.yxmlelement_alive(this.__wbg_ptr, txn.__wbg_ptr); 3395 - return ret !== 0; 3396 - } 3397 - /** 3398 - * Returns a tag name of this XML node. 3399 - * @param {YTransaction | undefined} txn 3400 - * @returns {string} 3401 - */ 3402 - name(txn) { 3403 - let deferred2_0; 3404 - let deferred2_1; 3405 - try { 3406 - const ret = wasm.yxmlelement_name(this.__wbg_ptr, txn); 3407 - var ptr1 = ret[0]; 3408 - var len1 = ret[1]; 3409 - if (ret[3]) { 3410 - ptr1 = 0; 3411 - len1 = 0; 3412 - throw takeFromExternrefTable0(ret[2]); 3413 - } 3414 - deferred2_0 = ptr1; 3415 - deferred2_1 = len1; 3416 - return getStringFromWasm0(ptr1, len1); 3417 - } finally { 3418 - wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); 3419 - } 3420 - } 3421 - /** 3422 - * Returns a number of child XML nodes stored within this `YXMlElement` instance. 3423 - * @param {YTransaction | undefined} txn 3424 - * @returns {number} 3425 - */ 3426 - length(txn) { 3427 - const ret = wasm.yxmlelement_length(this.__wbg_ptr, txn); 3428 - if (ret[2]) { 3429 - throw takeFromExternrefTable0(ret[1]); 3430 - } 3431 - return ret[0] >>> 0; 3432 - } 3433 - /** 3434 - * @param {number} index 3435 - * @param {any} xml_node 3436 - * @param {YTransaction | undefined} txn 3437 - */ 3438 - insert(index, xml_node, txn) { 3439 - const ret = wasm.yxmlelement_insert(this.__wbg_ptr, index, xml_node, txn); 3440 - if (ret[1]) { 3441 - throw takeFromExternrefTable0(ret[0]); 3442 - } 3443 - } 3444 - /** 3445 - * @param {any} xml_node 3446 - * @param {YTransaction | undefined} txn 3447 - */ 3448 - push(xml_node, txn) { 3449 - const ret = wasm.yxmlelement_push(this.__wbg_ptr, xml_node, txn); 3450 - if (ret[1]) { 3451 - throw takeFromExternrefTable0(ret[0]); 3452 - } 3453 - } 3454 - /** 3455 - * @param {number} index 3456 - * @param {number | null | undefined} length 3457 - * @param {YTransaction | undefined} txn 3458 - */ 3459 - delete(index, length, txn) { 3460 - const ret = wasm.yxmlelement_delete( 3461 - this.__wbg_ptr, 3462 - index, 3463 - isLikeNone(length) ? 0x100000001 : length >>> 0, 3464 - txn, 3465 - ); 3466 - if (ret[1]) { 3467 - throw takeFromExternrefTable0(ret[0]); 3468 - } 3469 - } 3470 - /** 3471 - * Returns a first child of this XML node. 3472 - * It can be either `YXmlElement`, `YXmlText` or `undefined` if current node has not children. 3473 - * @param {YTransaction | undefined} txn 3474 - * @returns {any} 3475 - */ 3476 - firstChild(txn) { 3477 - const ret = wasm.yxmlelement_firstChild(this.__wbg_ptr, txn); 3478 - if (ret[2]) { 3479 - throw takeFromExternrefTable0(ret[1]); 3480 - } 3481 - return takeFromExternrefTable0(ret[0]); 3482 - } 3483 - /** 3484 - * Returns a next XML sibling node of this XMl node. 3485 - * It can be either `YXmlElement`, `YXmlText` or `undefined` if current node is a last child of 3486 - * parent XML node. 3487 - * @param {YTransaction | undefined} txn 3488 - * @returns {any} 3489 - */ 3490 - nextSibling(txn) { 3491 - const ret = wasm.yxmlelement_nextSibling(this.__wbg_ptr, txn); 3492 - if (ret[2]) { 3493 - throw takeFromExternrefTable0(ret[1]); 3494 - } 3495 - return takeFromExternrefTable0(ret[0]); 3496 - } 3497 - /** 3498 - * Returns a previous XML sibling node of this XMl node. 3499 - * It can be either `YXmlElement`, `YXmlText` or `undefined` if current node is a first child 3500 - * of parent XML node. 3501 - * @param {YTransaction | undefined} txn 3502 - * @returns {any} 3503 - */ 3504 - prevSibling(txn) { 3505 - const ret = wasm.yxmlelement_prevSibling(this.__wbg_ptr, txn); 3506 - if (ret[2]) { 3507 - throw takeFromExternrefTable0(ret[1]); 3508 - } 3509 - return takeFromExternrefTable0(ret[0]); 3510 - } 3511 - /** 3512 - * Returns a parent `YXmlElement` node or `undefined` if current node has no parent assigned. 3513 - * @param {YTransaction | undefined} txn 3514 - * @returns {any} 3515 - */ 3516 - parent(txn) { 3517 - const ret = wasm.yxmlelement_parent(this.__wbg_ptr, txn); 3518 - if (ret[2]) { 3519 - throw takeFromExternrefTable0(ret[1]); 3520 - } 3521 - return takeFromExternrefTable0(ret[0]); 3522 - } 3523 - /** 3524 - * Returns a string representation of this XML node. 3525 - * @param {YTransaction | undefined} txn 3526 - * @returns {string} 3527 - */ 3528 - toString(txn) { 3529 - let deferred2_0; 3530 - let deferred2_1; 3531 - try { 3532 - const ret = wasm.yxmlelement_toString(this.__wbg_ptr, txn); 3533 - var ptr1 = ret[0]; 3534 - var len1 = ret[1]; 3535 - if (ret[3]) { 3536 - ptr1 = 0; 3537 - len1 = 0; 3538 - throw takeFromExternrefTable0(ret[2]); 3539 - } 3540 - deferred2_0 = ptr1; 3541 - deferred2_1 = len1; 3542 - return getStringFromWasm0(ptr1, len1); 3543 - } finally { 3544 - wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); 3545 - } 3546 - } 3547 - /** 3548 - * Sets a `name` and `value` as new attribute for this XML node. If an attribute with the same 3549 - * `name` already existed on that node, its value with be overridden with a provided one. 3550 - * This method accepts any JavaScript value, not just strings. 3551 - * @param {string} name 3552 - * @param {any} value 3553 - * @param {YTransaction | undefined} txn 3554 - */ 3555 - setAttribute(name, value, txn) { 3556 - const ptr0 = passStringToWasm0( 3557 - name, 3558 - wasm.__wbindgen_malloc, 3559 - wasm.__wbindgen_realloc, 3560 - ); 3561 - const len0 = WASM_VECTOR_LEN; 3562 - const ret = wasm.yxmlelement_setAttribute( 3563 - this.__wbg_ptr, 3564 - ptr0, 3565 - len0, 3566 - value, 3567 - txn, 3568 - ); 3569 - if (ret[1]) { 3570 - throw takeFromExternrefTable0(ret[0]); 3571 - } 3572 - } 3573 - /** 3574 - * Returns a value of an attribute given its `name` as any JS value. If no attribute with such name existed, 3575 - * `undefined` will be returned. 3576 - * @param {string} name 3577 - * @param {YTransaction | undefined} txn 3578 - * @returns {any} 3579 - */ 3580 - getAttribute(name, txn) { 3581 - const ptr0 = passStringToWasm0( 3582 - name, 3583 - wasm.__wbindgen_malloc, 3584 - wasm.__wbindgen_realloc, 3585 - ); 3586 - const len0 = WASM_VECTOR_LEN; 3587 - const ret = wasm.yxmlelement_getAttribute(this.__wbg_ptr, ptr0, len0, txn); 3588 - if (ret[2]) { 3589 - throw takeFromExternrefTable0(ret[1]); 3590 - } 3591 - return takeFromExternrefTable0(ret[0]); 3592 - } 3593 - /** 3594 - * Removes an attribute from this XML node, given its `name`. 3595 - * @param {string} name 3596 - * @param {YTransaction | undefined} txn 3597 - */ 3598 - removeAttribute(name, txn) { 3599 - const ptr0 = passStringToWasm0( 3600 - name, 3601 - wasm.__wbindgen_malloc, 3602 - wasm.__wbindgen_realloc, 3603 - ); 3604 - const len0 = WASM_VECTOR_LEN; 3605 - const ret = wasm.yxmlelement_removeAttribute( 3606 - this.__wbg_ptr, 3607 - ptr0, 3608 - len0, 3609 - txn, 3610 - ); 3611 - if (ret[1]) { 3612 - throw takeFromExternrefTable0(ret[0]); 3613 - } 3614 - } 3615 - /** 3616 - * Returns an iterator that enables to traverse over all attributes of this XML node in 3617 - * unspecified order. This method returns attribute values as their original JS values, 3618 - * not just as strings. 3619 - * @param {YTransaction | undefined} txn 3620 - * @returns {any} 3621 - */ 3622 - attributes(txn) { 3623 - const ret = wasm.yxmlelement_attributes(this.__wbg_ptr, txn); 3624 - if (ret[2]) { 3625 - throw takeFromExternrefTable0(ret[1]); 3626 - } 3627 - return takeFromExternrefTable0(ret[0]); 3628 - } 3629 - /** 3630 - * Returns an iterator that enables a deep traversal of this XML node - starting from first 3631 - * child over this XML node successors using depth-first strategy. 3632 - * @param {YTransaction | undefined} txn 3633 - * @returns {Array<any>} 3634 - */ 3635 - treeWalker(txn) { 3636 - const ret = wasm.yxmlelement_treeWalker(this.__wbg_ptr, txn); 3637 - if (ret[2]) { 3638 - throw takeFromExternrefTable0(ret[1]); 3639 - } 3640 - return takeFromExternrefTable0(ret[0]); 3641 - } 3642 - /** 3643 - * Subscribes to all operations happening over this instance of `YXmlElement`. All changes are 3644 - * batched and eventually triggered during transaction commit phase. 3645 - * @param {Function} callback 3646 - */ 3647 - observe(callback) { 3648 - const ret = wasm.yxmlelement_observe(this.__wbg_ptr, callback); 3649 - if (ret[1]) { 3650 - throw takeFromExternrefTable0(ret[0]); 3651 - } 3652 - } 3653 - /** 3654 - * Unsubscribes a callback previously subscribed with `observe` method. 3655 - * @param {Function} callback 3656 - * @returns {boolean} 3657 - */ 3658 - unobserve(callback) { 3659 - const ret = wasm.yxmlelement_unobserve(this.__wbg_ptr, callback); 3660 - if (ret[2]) { 3661 - throw takeFromExternrefTable0(ret[1]); 3662 - } 3663 - return ret[0] !== 0; 3664 - } 3665 - /** 3666 - * Subscribes to all operations happening over this Y shared type, as well as events in 3667 - * shared types stored within this one. All changes are batched and eventually triggered 3668 - * during transaction commit phase. 3669 - * @param {Function} callback 3670 - */ 3671 - observeDeep(callback) { 3672 - const ret = wasm.yxmlelement_observeDeep(this.__wbg_ptr, callback); 3673 - if (ret[1]) { 3674 - throw takeFromExternrefTable0(ret[0]); 3675 - } 3676 - } 3677 - /** 3678 - * Unsubscribes a callback previously subscribed with `observeDeep` method. 3679 - * @param {Function} callback 3680 - * @returns {boolean} 3681 - */ 3682 - unobserveDeep(callback) { 3683 - const ret = wasm.yxmlelement_unobserveDeep(this.__wbg_ptr, callback); 3684 - if (ret[2]) { 3685 - throw takeFromExternrefTable0(ret[1]); 3686 - } 3687 - return ret[0] !== 0; 3688 - } 3689 - } 3690 - module.exports.YXmlElement = YXmlElement; 3691 - 3692 - const YXmlEventFinalization = 3693 - typeof FinalizationRegistry === "undefined" 3694 - ? { register: () => {}, unregister: () => {} } 3695 - : new FinalizationRegistry((ptr) => 3696 - wasm.__wbg_yxmlevent_free(ptr >>> 0, 1), 3697 - ); 3698 - /** 3699 - * Event generated by `YXmlElement.observe` method. Emitted during transaction commit phase. 3700 - */ 3701 - class YXmlEvent { 3702 - static __wrap(ptr) { 3703 - ptr = ptr >>> 0; 3704 - const obj = Object.create(YXmlEvent.prototype); 3705 - obj.__wbg_ptr = ptr; 3706 - YXmlEventFinalization.register(obj, obj.__wbg_ptr, obj); 3707 - return obj; 3708 - } 3709 - 3710 - __destroy_into_raw() { 3711 - const ptr = this.__wbg_ptr; 3712 - this.__wbg_ptr = 0; 3713 - YXmlEventFinalization.unregister(this); 3714 - return ptr; 3715 - } 3716 - 3717 - free() { 3718 - const ptr = this.__destroy_into_raw(); 3719 - wasm.__wbg_yxmlevent_free(ptr, 0); 3720 - } 3721 - /** 3722 - * Returns an array of keys and indexes creating a path from root type down to current instance 3723 - * of shared type (accessible via `target` getter). 3724 - * @returns {any} 3725 - */ 3726 - path() { 3727 - const ret = wasm.yxmlevent_path(this.__wbg_ptr); 3728 - return ret; 3729 - } 3730 - /** 3731 - * Returns a current shared type instance, that current event changes refer to. 3732 - * @returns {any} 3733 - */ 3734 - get target() { 3735 - const ret = wasm.yxmlevent_target(this.__wbg_ptr); 3736 - return ret; 3737 - } 3738 - /** 3739 - * @returns {any} 3740 - */ 3741 - get origin() { 3742 - const ret = wasm.yxmlevent_origin(this.__wbg_ptr); 3743 - return ret; 3744 - } 3745 - /** 3746 - * Returns a list of attribute changes made over corresponding `YXmlText` collection within 3747 - * bounds of current transaction. These changes follow a format: 3748 - * 3749 - * - { action: 'add'|'update'|'delete', oldValue: string|undefined, newValue: string|undefined } 3750 - * @returns {any} 3751 - */ 3752 - get keys() { 3753 - const ret = wasm.yxmlevent_keys(this.__wbg_ptr); 3754 - if (ret[2]) { 3755 - throw takeFromExternrefTable0(ret[1]); 3756 - } 3757 - return takeFromExternrefTable0(ret[0]); 3758 - } 3759 - /** 3760 - * Returns a list of XML child node changes made over corresponding `YXmlElement` collection 3761 - * within bounds of current transaction. These changes follow a format: 3762 - * 3763 - * - { insert: (YXmlText|YXmlElement)[] } 3764 - * - { delete: number } 3765 - * - { retain: number } 3766 - * @returns {any} 3767 - */ 3768 - get delta() { 3769 - const ret = wasm.yxmlevent_delta(this.__wbg_ptr); 3770 - return ret; 3771 - } 3772 - } 3773 - module.exports.YXmlEvent = YXmlEvent; 3774 - 3775 - const YXmlFragmentFinalization = 3776 - typeof FinalizationRegistry === "undefined" 3777 - ? { register: () => {}, unregister: () => {} } 3778 - : new FinalizationRegistry((ptr) => 3779 - wasm.__wbg_yxmlfragment_free(ptr >>> 0, 1), 3780 - ); 3781 - /** 3782 - * Represents a list of `YXmlElement` and `YXmlText` types. 3783 - * A `YXmlFragment` is similar to a `YXmlElement`, but it does not have a 3784 - * nodeName and it does not have attributes. Though it can be bound to a DOM 3785 - * element - in this case the attributes and the nodeName are not shared 3786 - */ 3787 - class YXmlFragment { 3788 - static __wrap(ptr) { 3789 - ptr = ptr >>> 0; 3790 - const obj = Object.create(YXmlFragment.prototype); 3791 - obj.__wbg_ptr = ptr; 3792 - YXmlFragmentFinalization.register(obj, obj.__wbg_ptr, obj); 3793 - return obj; 3794 - } 3795 - 3796 - __destroy_into_raw() { 3797 - const ptr = this.__wbg_ptr; 3798 - this.__wbg_ptr = 0; 3799 - YXmlFragmentFinalization.unregister(this); 3800 - return ptr; 3801 - } 3802 - 3803 - free() { 3804 - const ptr = this.__destroy_into_raw(); 3805 - wasm.__wbg_yxmlfragment_free(ptr, 0); 3806 - } 3807 - /** 3808 - * @param {any[]} children 3809 - */ 3810 - constructor(children) { 3811 - const ptr0 = passArrayJsValueToWasm0(children, wasm.__wbindgen_malloc); 3812 - const len0 = WASM_VECTOR_LEN; 3813 - const ret = wasm.yxmlfragment_new(ptr0, len0); 3814 - if (ret[2]) { 3815 - throw takeFromExternrefTable0(ret[1]); 3816 - } 3817 - this.__wbg_ptr = ret[0] >>> 0; 3818 - YXmlFragmentFinalization.register(this, this.__wbg_ptr, this); 3819 - return this; 3820 - } 3821 - /** 3822 - * @returns {number} 3823 - */ 3824 - get type() { 3825 - const ret = wasm.yxmlfragment_type(this.__wbg_ptr); 3826 - return ret; 3827 - } 3828 - /** 3829 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 3830 - * document. 3831 - * @returns {any} 3832 - */ 3833 - get id() { 3834 - const ret = wasm.yxmlfragment_id(this.__wbg_ptr); 3835 - if (ret[2]) { 3836 - throw takeFromExternrefTable0(ret[1]); 3837 - } 3838 - return takeFromExternrefTable0(ret[0]); 3839 - } 3840 - /** 3841 - * Returns true if this is a preliminary instance of `YXmlFragment`. 3842 - * 3843 - * Preliminary instances can be nested into other shared data types. 3844 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 3845 - * document store and cannot be nested again: attempt to do so will result in an exception. 3846 - * @returns {boolean} 3847 - */ 3848 - get prelim() { 3849 - const ret = wasm.yxmlfragment_prelim(this.__wbg_ptr); 3850 - return ret !== 0; 3851 - } 3852 - /** 3853 - * Checks if current shared type reference is alive and has not been deleted by its parent collection. 3854 - * This method only works on already integrated shared types and will return false is current 3855 - * type is preliminary (has not been integrated into document). 3856 - * @param {YTransaction} txn 3857 - * @returns {boolean} 3858 - */ 3859 - alive(txn) { 3860 - _assertClass(txn, YTransaction); 3861 - const ret = wasm.yxmlfragment_alive(this.__wbg_ptr, txn.__wbg_ptr); 3862 - return ret !== 0; 3863 - } 3864 - /** 3865 - * Returns a number of child XML nodes stored within this `YXMlElement` instance. 3866 - * @param {YTransaction | undefined} txn 3867 - * @returns {number} 3868 - */ 3869 - length(txn) { 3870 - const ret = wasm.yxmlfragment_length(this.__wbg_ptr, txn); 3871 - if (ret[2]) { 3872 - throw takeFromExternrefTable0(ret[1]); 3873 - } 3874 - return ret[0] >>> 0; 3875 - } 3876 - /** 3877 - * @param {number} index 3878 - * @param {any} xml_node 3879 - * @param {YTransaction | undefined} txn 3880 - */ 3881 - insert(index, xml_node, txn) { 3882 - const ret = wasm.yxmlfragment_insert(this.__wbg_ptr, index, xml_node, txn); 3883 - if (ret[1]) { 3884 - throw takeFromExternrefTable0(ret[0]); 3885 - } 3886 - } 3887 - /** 3888 - * @param {any} xml_node 3889 - * @param {YTransaction | undefined} txn 3890 - */ 3891 - push(xml_node, txn) { 3892 - const ret = wasm.yxmlfragment_push(this.__wbg_ptr, xml_node, txn); 3893 - if (ret[1]) { 3894 - throw takeFromExternrefTable0(ret[0]); 3895 - } 3896 - } 3897 - /** 3898 - * @param {number} index 3899 - * @param {number | null | undefined} length 3900 - * @param {YTransaction | undefined} txn 3901 - */ 3902 - delete(index, length, txn) { 3903 - const ret = wasm.yxmlfragment_delete( 3904 - this.__wbg_ptr, 3905 - index, 3906 - isLikeNone(length) ? 0x100000001 : length >>> 0, 3907 - txn, 3908 - ); 3909 - if (ret[1]) { 3910 - throw takeFromExternrefTable0(ret[0]); 3911 - } 3912 - } 3913 - /** 3914 - * Returns a first child of this XML node. 3915 - * It can be either `YXmlElement`, `YXmlText` or `undefined` if current node has not children. 3916 - * @param {YTransaction | undefined} txn 3917 - * @returns {any} 3918 - */ 3919 - firstChild(txn) { 3920 - const ret = wasm.yxmlfragment_firstChild(this.__wbg_ptr, txn); 3921 - if (ret[2]) { 3922 - throw takeFromExternrefTable0(ret[1]); 3923 - } 3924 - return takeFromExternrefTable0(ret[0]); 3925 - } 3926 - /** 3927 - * Returns a string representation of this XML node. 3928 - * @param {YTransaction | undefined} txn 3929 - * @returns {string} 3930 - */ 3931 - toString(txn) { 3932 - let deferred2_0; 3933 - let deferred2_1; 3934 - try { 3935 - const ret = wasm.yxmlfragment_toString(this.__wbg_ptr, txn); 3936 - var ptr1 = ret[0]; 3937 - var len1 = ret[1]; 3938 - if (ret[3]) { 3939 - ptr1 = 0; 3940 - len1 = 0; 3941 - throw takeFromExternrefTable0(ret[2]); 3942 - } 3943 - deferred2_0 = ptr1; 3944 - deferred2_1 = len1; 3945 - return getStringFromWasm0(ptr1, len1); 3946 - } finally { 3947 - wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); 3948 - } 3949 - } 3950 - /** 3951 - * Returns an iterator that enables a deep traversal of this XML node - starting from first 3952 - * child over this XML node successors using depth-first strategy. 3953 - * @param {YTransaction | undefined} txn 3954 - * @returns {Array<any>} 3955 - */ 3956 - treeWalker(txn) { 3957 - const ret = wasm.yxmlfragment_treeWalker(this.__wbg_ptr, txn); 3958 - if (ret[2]) { 3959 - throw takeFromExternrefTable0(ret[1]); 3960 - } 3961 - return takeFromExternrefTable0(ret[0]); 3962 - } 3963 - /** 3964 - * Subscribes to all operations happening over this instance of `YXmlFragment`. All changes are 3965 - * batched and eventually triggered during transaction commit phase. 3966 - * @param {Function} callback 3967 - */ 3968 - observe(callback) { 3969 - const ret = wasm.yxmlfragment_observe(this.__wbg_ptr, callback); 3970 - if (ret[1]) { 3971 - throw takeFromExternrefTable0(ret[0]); 3972 - } 3973 - } 3974 - /** 3975 - * Unsubscribes a callback previously subscribed with `observe` method. 3976 - * @param {Function} callback 3977 - * @returns {boolean} 3978 - */ 3979 - unobserve(callback) { 3980 - const ret = wasm.yxmlfragment_unobserve(this.__wbg_ptr, callback); 3981 - if (ret[2]) { 3982 - throw takeFromExternrefTable0(ret[1]); 3983 - } 3984 - return ret[0] !== 0; 3985 - } 3986 - /** 3987 - * Subscribes to all operations happening over this Y shared type, as well as events in 3988 - * shared types stored within this one. All changes are batched and eventually triggered 3989 - * during transaction commit phase. 3990 - * @param {Function} callback 3991 - */ 3992 - observeDeep(callback) { 3993 - const ret = wasm.yxmlfragment_observeDeep(this.__wbg_ptr, callback); 3994 - if (ret[1]) { 3995 - throw takeFromExternrefTable0(ret[0]); 3996 - } 3997 - } 3998 - /** 3999 - * Unsubscribes a callback previously subscribed with `observeDeep` method. 4000 - * @param {Function} callback 4001 - * @returns {boolean} 4002 - */ 4003 - unobserveDeep(callback) { 4004 - const ret = wasm.yxmlfragment_unobserveDeep(this.__wbg_ptr, callback); 4005 - if (ret[2]) { 4006 - throw takeFromExternrefTable0(ret[1]); 4007 - } 4008 - return ret[0] !== 0; 4009 - } 4010 - } 4011 - module.exports.YXmlFragment = YXmlFragment; 4012 - 4013 - const YXmlTextFinalization = 4014 - typeof FinalizationRegistry === "undefined" 4015 - ? { register: () => {}, unregister: () => {} } 4016 - : new FinalizationRegistry((ptr) => wasm.__wbg_yxmltext_free(ptr >>> 0, 1)); 4017 - /** 4018 - * A shared data type used for collaborative text editing, that can be used in a context of 4019 - * `YXmlElement` nodee. It enables multiple users to add and remove chunks of text in efficient 4020 - * manner. This type is internally represented as a mutable double-linked list of text chunks 4021 - * - an optimization occurs during `YTransaction.commit`, which allows to squash multiple 4022 - * consecutively inserted characters together as a single chunk of text even between transaction 4023 - * boundaries in order to preserve more efficient memory model. 4024 - * 4025 - * Just like `YXmlElement`, `YXmlText` can be marked with extra metadata in form of attributes. 4026 - * 4027 - * `YXmlText` structure internally uses UTF-8 encoding and its length is described in a number of 4028 - * bytes rather than individual characters (a single UTF-8 code point can consist of many bytes). 4029 - * 4030 - * Like all Yrs shared data types, `YXmlText` is resistant to the problem of interleaving (situation 4031 - * when characters inserted one after another may interleave with other peers concurrent inserts 4032 - * after merging all updates together). In case of Yrs conflict resolution is solved by using 4033 - * unique document id to determine correct and consistent ordering. 4034 - */ 4035 - class YXmlText { 4036 - static __wrap(ptr) { 4037 - ptr = ptr >>> 0; 4038 - const obj = Object.create(YXmlText.prototype); 4039 - obj.__wbg_ptr = ptr; 4040 - YXmlTextFinalization.register(obj, obj.__wbg_ptr, obj); 4041 - return obj; 4042 - } 4043 - 4044 - __destroy_into_raw() { 4045 - const ptr = this.__wbg_ptr; 4046 - this.__wbg_ptr = 0; 4047 - YXmlTextFinalization.unregister(this); 4048 - return ptr; 4049 - } 4050 - 4051 - free() { 4052 - const ptr = this.__destroy_into_raw(); 4053 - wasm.__wbg_yxmltext_free(ptr, 0); 4054 - } 4055 - /** 4056 - * @param {string | null | undefined} text 4057 - * @param {any} attributes 4058 - */ 4059 - constructor(text, attributes) { 4060 - var ptr0 = isLikeNone(text) 4061 - ? 0 4062 - : passStringToWasm0( 4063 - text, 4064 - wasm.__wbindgen_malloc, 4065 - wasm.__wbindgen_realloc, 4066 - ); 4067 - var len0 = WASM_VECTOR_LEN; 4068 - const ret = wasm.yxmltext_new(ptr0, len0, attributes); 4069 - if (ret[2]) { 4070 - throw takeFromExternrefTable0(ret[1]); 4071 - } 4072 - this.__wbg_ptr = ret[0] >>> 0; 4073 - YXmlTextFinalization.register(this, this.__wbg_ptr, this); 4074 - return this; 4075 - } 4076 - /** 4077 - * @returns {number} 4078 - */ 4079 - get type() { 4080 - const ret = wasm.yxmltext_type(this.__wbg_ptr); 4081 - return ret; 4082 - } 4083 - /** 4084 - * Gets unique logical identifier of this type, shared across peers collaborating on the same 4085 - * document. 4086 - * @returns {any} 4087 - */ 4088 - get id() { 4089 - const ret = wasm.yxmltext_id(this.__wbg_ptr); 4090 - if (ret[2]) { 4091 - throw takeFromExternrefTable0(ret[1]); 4092 - } 4093 - return takeFromExternrefTable0(ret[0]); 4094 - } 4095 - /** 4096 - * Returns true if this is a preliminary instance of `YXmlText`. 4097 - * 4098 - * Preliminary instances can be nested into other shared data types. 4099 - * Once a preliminary instance has been inserted this way, it becomes integrated into ywasm 4100 - * document store and cannot be nested again: attempt to do so will result in an exception. 4101 - * @returns {boolean} 4102 - */ 4103 - get prelim() { 4104 - const ret = wasm.yxmltext_prelim(this.__wbg_ptr); 4105 - return ret !== 0; 4106 - } 4107 - /** 4108 - * Checks if current shared type reference is alive and has not been deleted by its parent collection. 4109 - * This method only works on already integrated shared types and will return false is current 4110 - * type is preliminary (has not been integrated into document). 4111 - * @param {YTransaction} txn 4112 - * @returns {boolean} 4113 - */ 4114 - alive(txn) { 4115 - _assertClass(txn, YTransaction); 4116 - const ret = wasm.yxmltext_alive(this.__wbg_ptr, txn.__wbg_ptr); 4117 - return ret !== 0; 4118 - } 4119 - /** 4120 - * Returns length of an underlying string stored in this `YXmlText` instance, 4121 - * understood as a number of UTF-8 encoded bytes. 4122 - * @param {YTransaction | undefined} txn 4123 - * @returns {number} 4124 - */ 4125 - length(txn) { 4126 - const ret = wasm.yxmltext_length(this.__wbg_ptr, txn); 4127 - if (ret[2]) { 4128 - throw takeFromExternrefTable0(ret[1]); 4129 - } 4130 - return ret[0] >>> 0; 4131 - } 4132 - /** 4133 - * Inserts a given `chunk` of text into this `YXmlText` instance, starting at a given `index`. 4134 - * 4135 - * Optional object with defined `attributes` will be used to wrap provided text `chunk` 4136 - * with a formatting blocks. 4137 - * @param {number} index 4138 - * @param {string} chunk 4139 - * @param {any} attributes 4140 - * @param {YTransaction | undefined} txn 4141 - */ 4142 - insert(index, chunk, attributes, txn) { 4143 - const ptr0 = passStringToWasm0( 4144 - chunk, 4145 - wasm.__wbindgen_malloc, 4146 - wasm.__wbindgen_realloc, 4147 - ); 4148 - const len0 = WASM_VECTOR_LEN; 4149 - const ret = wasm.yxmltext_insert( 4150 - this.__wbg_ptr, 4151 - index, 4152 - ptr0, 4153 - len0, 4154 - attributes, 4155 - txn, 4156 - ); 4157 - if (ret[1]) { 4158 - throw takeFromExternrefTable0(ret[0]); 4159 - } 4160 - } 4161 - /** 4162 - * Formats text within bounds specified by `index` and `len` with a given formatting 4163 - * attributes. 4164 - * @param {number} index 4165 - * @param {number} length 4166 - * @param {any} attributes 4167 - * @param {YTransaction | undefined} txn 4168 - */ 4169 - format(index, length, attributes, txn) { 4170 - const ret = wasm.yxmltext_format( 4171 - this.__wbg_ptr, 4172 - index, 4173 - length, 4174 - attributes, 4175 - txn, 4176 - ); 4177 - if (ret[1]) { 4178 - throw takeFromExternrefTable0(ret[0]); 4179 - } 4180 - } 4181 - /** 4182 - * @param {number | null | undefined} lower 4183 - * @param {number | null | undefined} upper 4184 - * @param {boolean | null | undefined} lower_open 4185 - * @param {boolean | null | undefined} upper_open 4186 - * @param {YTransaction | undefined} txn 4187 - * @returns {YWeakLink} 4188 - */ 4189 - quote(lower, upper, lower_open, upper_open, txn) { 4190 - const ret = wasm.yxmltext_quote( 4191 - this.__wbg_ptr, 4192 - isLikeNone(lower) ? 0x100000001 : lower >>> 0, 4193 - isLikeNone(upper) ? 0x100000001 : upper >>> 0, 4194 - isLikeNone(lower_open) ? 0xffffff : lower_open ? 1 : 0, 4195 - isLikeNone(upper_open) ? 0xffffff : upper_open ? 1 : 0, 4196 - txn, 4197 - ); 4198 - if (ret[2]) { 4199 - throw takeFromExternrefTable0(ret[1]); 4200 - } 4201 - return YWeakLink.__wrap(ret[0]); 4202 - } 4203 - /** 4204 - * Returns the Delta representation of this YXmlText type. 4205 - * @param {any} snapshot 4206 - * @param {any} prev_snapshot 4207 - * @param {Function | null | undefined} compute_ychange 4208 - * @param {YTransaction | undefined} txn 4209 - * @returns {Array<any>} 4210 - */ 4211 - toDelta(snapshot, prev_snapshot, compute_ychange, txn) { 4212 - const ret = wasm.yxmltext_toDelta( 4213 - this.__wbg_ptr, 4214 - snapshot, 4215 - prev_snapshot, 4216 - isLikeNone(compute_ychange) ? 0 : addToExternrefTable0(compute_ychange), 4217 - txn, 4218 - ); 4219 - if (ret[2]) { 4220 - throw takeFromExternrefTable0(ret[1]); 4221 - } 4222 - return takeFromExternrefTable0(ret[0]); 4223 - } 4224 - /** 4225 - * Inserts a given `embed` object into this `YXmlText` instance, starting at a given `index`. 4226 - * 4227 - * Optional object with defined `attributes` will be used to wrap provided `embed` 4228 - * with a formatting blocks.`attributes` are only supported for a `YXmlText` instance which 4229 - * already has been integrated into document store. 4230 - * @param {number} index 4231 - * @param {any} embed 4232 - * @param {any} attributes 4233 - * @param {YTransaction | undefined} txn 4234 - */ 4235 - insertEmbed(index, embed, attributes, txn) { 4236 - const ret = wasm.yxmltext_insertEmbed( 4237 - this.__wbg_ptr, 4238 - index, 4239 - embed, 4240 - attributes, 4241 - txn, 4242 - ); 4243 - if (ret[1]) { 4244 - throw takeFromExternrefTable0(ret[0]); 4245 - } 4246 - } 4247 - /** 4248 - * Appends a given `chunk` of text at the end of `YXmlText` instance. 4249 - * 4250 - * Optional object with defined `attributes` will be used to wrap provided text `chunk` 4251 - * with a formatting blocks. 4252 - * @param {string} chunk 4253 - * @param {any} attributes 4254 - * @param {YTransaction | undefined} txn 4255 - */ 4256 - push(chunk, attributes, txn) { 4257 - const ptr0 = passStringToWasm0( 4258 - chunk, 4259 - wasm.__wbindgen_malloc, 4260 - wasm.__wbindgen_realloc, 4261 - ); 4262 - const len0 = WASM_VECTOR_LEN; 4263 - const ret = wasm.yxmltext_push(this.__wbg_ptr, ptr0, len0, attributes, txn); 4264 - if (ret[1]) { 4265 - throw takeFromExternrefTable0(ret[0]); 4266 - } 4267 - } 4268 - /** 4269 - * @param {Array<any>} delta 4270 - * @param {YTransaction | undefined} txn 4271 - */ 4272 - applyDelta(delta, txn) { 4273 - const ret = wasm.yxmltext_applyDelta(this.__wbg_ptr, delta, txn); 4274 - if (ret[1]) { 4275 - throw takeFromExternrefTable0(ret[0]); 4276 - } 4277 - } 4278 - /** 4279 - * Deletes a specified range of characters, starting at a given `index`. 4280 - * Both `index` and `length` are counted in terms of a number of UTF-8 character bytes. 4281 - * @param {number} index 4282 - * @param {number} length 4283 - * @param {YTransaction | undefined} txn 4284 - */ 4285 - delete(index, length, txn) { 4286 - const ret = wasm.yxmltext_delete(this.__wbg_ptr, index, length, txn); 4287 - if (ret[1]) { 4288 - throw takeFromExternrefTable0(ret[0]); 4289 - } 4290 - } 4291 - /** 4292 - * Returns a next XML sibling node of this XMl node. 4293 - * It can be either `YXmlElement`, `YXmlText` or `undefined` if current node is a last child of 4294 - * parent XML node. 4295 - * @param {YTransaction | undefined} txn 4296 - * @returns {any} 4297 - */ 4298 - nextSibling(txn) { 4299 - const ret = wasm.yxmltext_nextSibling(this.__wbg_ptr, txn); 4300 - if (ret[2]) { 4301 - throw takeFromExternrefTable0(ret[1]); 4302 - } 4303 - return takeFromExternrefTable0(ret[0]); 4304 - } 4305 - /** 4306 - * Returns a previous XML sibling node of this XMl node. 4307 - * It can be either `YXmlElement`, `YXmlText` or `undefined` if current node is a first child 4308 - * of parent XML node. 4309 - * @param {YTransaction | undefined} txn 4310 - * @returns {any} 4311 - */ 4312 - prevSibling(txn) { 4313 - const ret = wasm.yxmltext_prevSibling(this.__wbg_ptr, txn); 4314 - if (ret[2]) { 4315 - throw takeFromExternrefTable0(ret[1]); 4316 - } 4317 - return takeFromExternrefTable0(ret[0]); 4318 - } 4319 - /** 4320 - * Returns a parent `YXmlElement` node or `undefined` if current node has no parent assigned. 4321 - * @param {YTransaction | undefined} txn 4322 - * @returns {any} 4323 - */ 4324 - parent(txn) { 4325 - const ret = wasm.yxmltext_parent(this.__wbg_ptr, txn); 4326 - if (ret[2]) { 4327 - throw takeFromExternrefTable0(ret[1]); 4328 - } 4329 - return takeFromExternrefTable0(ret[0]); 4330 - } 4331 - /** 4332 - * Returns an underlying string stored in this `YXmlText` instance. 4333 - * @param {YTransaction | undefined} txn 4334 - * @returns {string} 4335 - */ 4336 - toString(txn) { 4337 - let deferred2_0; 4338 - let deferred2_1; 4339 - try { 4340 - const ret = wasm.yxmltext_toString(this.__wbg_ptr, txn); 4341 - var ptr1 = ret[0]; 4342 - var len1 = ret[1]; 4343 - if (ret[3]) { 4344 - ptr1 = 0; 4345 - len1 = 0; 4346 - throw takeFromExternrefTable0(ret[2]); 4347 - } 4348 - deferred2_0 = ptr1; 4349 - deferred2_1 = len1; 4350 - return getStringFromWasm0(ptr1, len1); 4351 - } finally { 4352 - wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); 4353 - } 4354 - } 4355 - /** 4356 - * Sets a `name` and `value` as new attribute for this XML node. If an attribute with the same 4357 - * `name` already existed on that node, its value with be overridden with a provided one. 4358 - * This method accepts any JavaScript value, not just strings. 4359 - * @param {string} name 4360 - * @param {any} value 4361 - * @param {YTransaction | undefined} txn 4362 - */ 4363 - setAttribute(name, value, txn) { 4364 - const ptr0 = passStringToWasm0( 4365 - name, 4366 - wasm.__wbindgen_malloc, 4367 - wasm.__wbindgen_realloc, 4368 - ); 4369 - const len0 = WASM_VECTOR_LEN; 4370 - const ret = wasm.yxmltext_setAttribute( 4371 - this.__wbg_ptr, 4372 - ptr0, 4373 - len0, 4374 - value, 4375 - txn, 4376 - ); 4377 - if (ret[1]) { 4378 - throw takeFromExternrefTable0(ret[0]); 4379 - } 4380 - } 4381 - /** 4382 - * Returns a value of an attribute given its `name` as any JS value. If no attribute with such name existed, 4383 - * `undefined` will be returned. 4384 - * @param {string} name 4385 - * @param {YTransaction | undefined} txn 4386 - * @returns {any} 4387 - */ 4388 - getAttribute(name, txn) { 4389 - const ptr0 = passStringToWasm0( 4390 - name, 4391 - wasm.__wbindgen_malloc, 4392 - wasm.__wbindgen_realloc, 4393 - ); 4394 - const len0 = WASM_VECTOR_LEN; 4395 - const ret = wasm.yxmltext_getAttribute(this.__wbg_ptr, ptr0, len0, txn); 4396 - if (ret[2]) { 4397 - throw takeFromExternrefTable0(ret[1]); 4398 - } 4399 - return takeFromExternrefTable0(ret[0]); 4400 - } 4401 - /** 4402 - * Removes an attribute from this XML node, given its `name`. 4403 - * @param {string} name 4404 - * @param {YTransaction | undefined} txn 4405 - */ 4406 - removeAttribute(name, txn) { 4407 - const ptr0 = passStringToWasm0( 4408 - name, 4409 - wasm.__wbindgen_malloc, 4410 - wasm.__wbindgen_realloc, 4411 - ); 4412 - const len0 = WASM_VECTOR_LEN; 4413 - const ret = wasm.yxmltext_removeAttribute(this.__wbg_ptr, ptr0, len0, txn); 4414 - if (ret[1]) { 4415 - throw takeFromExternrefTable0(ret[0]); 4416 - } 4417 - } 4418 - /** 4419 - * Returns an iterator that enables to traverse over all attributes of this XML node in 4420 - * unspecified order. This method returns attribute values as their original JS values, 4421 - * not just as strings. 4422 - * @param {YTransaction | undefined} txn 4423 - * @returns {any} 4424 - */ 4425 - attributes(txn) { 4426 - const ret = wasm.yxmltext_attributes(this.__wbg_ptr, txn); 4427 - if (ret[2]) { 4428 - throw takeFromExternrefTable0(ret[1]); 4429 - } 4430 - return takeFromExternrefTable0(ret[0]); 4431 - } 4432 - /** 4433 - * Subscribes to all operations happening over this instance of `YXmlText`. All changes are 4434 - * batched and eventually triggered during transaction commit phase. 4435 - * @param {Function} callback 4436 - */ 4437 - observe(callback) { 4438 - const ret = wasm.yxmltext_observe(this.__wbg_ptr, callback); 4439 - if (ret[1]) { 4440 - throw takeFromExternrefTable0(ret[0]); 4441 - } 4442 - } 4443 - /** 4444 - * Unsubscribes a callback previously subscribed with `observe` method. 4445 - * @param {Function} callback 4446 - * @returns {boolean} 4447 - */ 4448 - unobserve(callback) { 4449 - const ret = wasm.yxmltext_unobserve(this.__wbg_ptr, callback); 4450 - if (ret[2]) { 4451 - throw takeFromExternrefTable0(ret[1]); 4452 - } 4453 - return ret[0] !== 0; 4454 - } 4455 - /** 4456 - * Subscribes to all operations happening over this Y shared type, as well as events in 4457 - * shared types stored within this one. All changes are batched and eventually triggered 4458 - * during transaction commit phase. 4459 - * @param {Function} callback 4460 - */ 4461 - observeDeep(callback) { 4462 - const ret = wasm.yxmltext_observeDeep(this.__wbg_ptr, callback); 4463 - if (ret[1]) { 4464 - throw takeFromExternrefTable0(ret[0]); 4465 - } 4466 - } 4467 - /** 4468 - * Unsubscribes a callback previously subscribed with `observe` method. 4469 - * @param {Function} callback 4470 - * @returns {boolean} 4471 - */ 4472 - unobserveDeep(callback) { 4473 - const ret = wasm.yxmltext_unobserveDeep(this.__wbg_ptr, callback); 4474 - if (ret[2]) { 4475 - throw takeFromExternrefTable0(ret[1]); 4476 - } 4477 - return ret[0] !== 0; 4478 - } 4479 - } 4480 - module.exports.YXmlText = YXmlText; 4481 - 4482 - const YXmlTextEventFinalization = 4483 - typeof FinalizationRegistry === "undefined" 4484 - ? { register: () => {}, unregister: () => {} } 4485 - : new FinalizationRegistry((ptr) => 4486 - wasm.__wbg_yxmltextevent_free(ptr >>> 0, 1), 4487 - ); 4488 - /** 4489 - * Event generated by `YXmlText.observe` method. Emitted during transaction commit phase. 4490 - */ 4491 - class YXmlTextEvent { 4492 - static __wrap(ptr) { 4493 - ptr = ptr >>> 0; 4494 - const obj = Object.create(YXmlTextEvent.prototype); 4495 - obj.__wbg_ptr = ptr; 4496 - YXmlTextEventFinalization.register(obj, obj.__wbg_ptr, obj); 4497 - return obj; 4498 - } 4499 - 4500 - __destroy_into_raw() { 4501 - const ptr = this.__wbg_ptr; 4502 - this.__wbg_ptr = 0; 4503 - YXmlTextEventFinalization.unregister(this); 4504 - return ptr; 4505 - } 4506 - 4507 - free() { 4508 - const ptr = this.__destroy_into_raw(); 4509 - wasm.__wbg_yxmltextevent_free(ptr, 0); 4510 - } 4511 - /** 4512 - * Returns an array of keys and indexes creating a path from root type down to current instance 4513 - * of shared type (accessible via `target` getter). 4514 - * @returns {any} 4515 - */ 4516 - path() { 4517 - const ret = wasm.yxmltextevent_path(this.__wbg_ptr); 4518 - return ret; 4519 - } 4520 - /** 4521 - * Returns a current shared type instance, that current event changes refer to. 4522 - * @returns {any} 4523 - */ 4524 - get target() { 4525 - const ret = wasm.yxmltextevent_target(this.__wbg_ptr); 4526 - return ret; 4527 - } 4528 - /** 4529 - * @returns {any} 4530 - */ 4531 - get origin() { 4532 - const ret = wasm.yxmltextevent_origin(this.__wbg_ptr); 4533 - return ret; 4534 - } 4535 - /** 4536 - * Returns a list of text changes made over corresponding `YText` collection within 4537 - * bounds of current transaction. These changes follow a format: 4538 - * 4539 - * - { insert: string, attributes: any|undefined } 4540 - * - { delete: number } 4541 - * - { retain: number, attributes: any|undefined } 4542 - * @returns {any} 4543 - */ 4544 - get delta() { 4545 - const ret = wasm.yxmltextevent_delta(this.__wbg_ptr); 4546 - if (ret[2]) { 4547 - throw takeFromExternrefTable0(ret[1]); 4548 - } 4549 - return takeFromExternrefTable0(ret[0]); 4550 - } 4551 - /** 4552 - * Returns a list of attribute changes made over corresponding `YXmlText` collection within 4553 - * bounds of current transaction. These changes follow a format: 4554 - * 4555 - * - { action: 'add'|'update'|'delete', oldValue: string|undefined, newValue: string|undefined } 4556 - * @returns {any} 4557 - */ 4558 - get keys() { 4559 - const ret = wasm.yxmltextevent_keys(this.__wbg_ptr); 4560 - if (ret[2]) { 4561 - throw takeFromExternrefTable0(ret[1]); 4562 - } 4563 - return takeFromExternrefTable0(ret[0]); 4564 - } 4565 - } 4566 - module.exports.YXmlTextEvent = YXmlTextEvent; 4567 - 4568 - module.exports.__wbg_buffer_609cc3eee51ed158 = function (arg0) { 4569 - const ret = arg0.buffer; 4570 - return ret; 4571 - }; 4572 - 4573 - module.exports.__wbg_call_672a4d21634d4a24 = function () { 4574 - return handleError(function (arg0, arg1) { 4575 - const ret = arg0.call(arg1); 4576 - return ret; 4577 - }, arguments); 4578 - }; 4579 - 4580 - module.exports.__wbg_call_7cccdd69e0791ae2 = function () { 4581 - return handleError(function (arg0, arg1, arg2) { 4582 - const ret = arg0.call(arg1, arg2); 4583 - return ret; 4584 - }, arguments); 4585 - }; 4586 - 4587 - module.exports.__wbg_call_833bed5770ea2041 = function () { 4588 - return handleError(function (arg0, arg1, arg2, arg3) { 4589 - const ret = arg0.call(arg1, arg2, arg3); 4590 - return ret; 4591 - }, arguments); 4592 - }; 4593 - 4594 - module.exports.__wbg_crypto_574e78ad8b13b65f = function (arg0) { 4595 - const ret = arg0.crypto; 4596 - return ret; 4597 - }; 4598 - 4599 - module.exports.__wbg_entries_3265d4158b33e5dc = function (arg0) { 4600 - const ret = Object.entries(arg0); 4601 - return ret; 4602 - }; 4603 - 4604 - module.exports.__wbg_error_7534b8e9a36f1ab4 = function (arg0, arg1) { 4605 - let deferred0_0; 4606 - let deferred0_1; 4607 - try { 4608 - deferred0_0 = arg0; 4609 - deferred0_1 = arg1; 4610 - console.error(getStringFromWasm0(arg0, arg1)); 4611 - } finally { 4612 - wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); 4613 - } 4614 - }; 4615 - 4616 - module.exports.__wbg_from_2a5d3e218e67aa85 = function (arg0) { 4617 - const ret = Array.from(arg0); 4618 - return ret; 4619 - }; 4620 - 4621 - module.exports.__wbg_getRandomValues_b8f5dbd5f3995a9e = function () { 4622 - return handleError(function (arg0, arg1) { 4623 - arg0.getRandomValues(arg1); 4624 - }, arguments); 4625 - }; 4626 - 4627 - module.exports.__wbg_get_67b2ba62fc30de12 = function () { 4628 - return handleError(function (arg0, arg1) { 4629 - const ret = Reflect.get(arg0, arg1); 4630 - return ret; 4631 - }, arguments); 4632 - }; 4633 - 4634 - module.exports.__wbg_get_b9b93047fe3cf45b = function (arg0, arg1) { 4635 - const ret = arg0[arg1 >>> 0]; 4636 - return ret; 4637 - }; 4638 - 4639 - module.exports.__wbg_isArray_a1eab7e0d067391b = function (arg0) { 4640 - const ret = Array.isArray(arg0); 4641 - return ret; 4642 - }; 4643 - 4644 - module.exports.__wbg_length_a446193dc22c12f8 = function (arg0) { 4645 - const ret = arg0.length; 4646 - return ret; 4647 - }; 4648 - 4649 - module.exports.__wbg_length_e2d2a49132c1b256 = function (arg0) { 4650 - const ret = arg0.length; 4651 - return ret; 4652 - }; 4653 - 4654 - module.exports.__wbg_msCrypto_a61aeb35a24c1329 = function (arg0) { 4655 - const ret = arg0.msCrypto; 4656 - return ret; 4657 - }; 4658 - 4659 - module.exports.__wbg_new_405e22f390576ce2 = function () { 4660 - const ret = new Object(); 4661 - return ret; 4662 - }; 4663 - 4664 - module.exports.__wbg_new_5e0be73521bc8c17 = function () { 4665 - const ret = new Map(); 4666 - return ret; 4667 - }; 4668 - 4669 - module.exports.__wbg_new_78feb108b6472713 = function () { 4670 - const ret = new Array(); 4671 - return ret; 4672 - }; 4673 - 4674 - module.exports.__wbg_new_8a6f238a6ece86ea = function () { 4675 - const ret = new Error(); 4676 - return ret; 4677 - }; 4678 - 4679 - module.exports.__wbg_new_a12002a7f91c75be = function (arg0) { 4680 - const ret = new Uint8Array(arg0); 4681 - return ret; 4682 - }; 4683 - 4684 - module.exports.__wbg_new_a239edaa1dc2968f = function (arg0) { 4685 - const ret = new Set(arg0); 4686 - return ret; 4687 - }; 4688 - 4689 - module.exports.__wbg_newnoargs_105ed471475aaf50 = function (arg0, arg1) { 4690 - const ret = new Function(getStringFromWasm0(arg0, arg1)); 4691 - return ret; 4692 - }; 4693 - 4694 - module.exports.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function ( 4695 - arg0, 4696 - arg1, 4697 - arg2, 4698 - ) { 4699 - const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0); 4700 - return ret; 4701 - }; 4702 - 4703 - module.exports.__wbg_newwithlength_a381634e90c276d4 = function (arg0) { 4704 - const ret = new Uint8Array(arg0 >>> 0); 4705 - return ret; 4706 - }; 4707 - 4708 - module.exports.__wbg_node_905d3e251edff8a2 = function (arg0) { 4709 - const ret = arg0.node; 4710 - return ret; 4711 - }; 4712 - 4713 - module.exports.__wbg_now_807e54c39636c349 = function () { 4714 - const ret = Date.now(); 4715 - return ret; 4716 - }; 4717 - 4718 - module.exports.__wbg_parse_def2e24ef1252aff = function () { 4719 - return handleError(function (arg0, arg1) { 4720 - const ret = JSON.parse(getStringFromWasm0(arg0, arg1)); 4721 - return ret; 4722 - }, arguments); 4723 - }; 4724 - 4725 - module.exports.__wbg_process_dc0fbacc7c1c06f7 = function (arg0) { 4726 - const ret = arg0.process; 4727 - return ret; 4728 - }; 4729 - 4730 - module.exports.__wbg_push_737cfc8c1432c2c6 = function (arg0, arg1) { 4731 - const ret = arg0.push(arg1); 4732 - return ret; 4733 - }; 4734 - 4735 - module.exports.__wbg_randomFillSync_ac0988aba3254290 = function () { 4736 - return handleError(function (arg0, arg1) { 4737 - arg0.randomFillSync(arg1); 4738 - }, arguments); 4739 - }; 4740 - 4741 - module.exports.__wbg_require_60cc747a6bc5215a = function () { 4742 - return handleError(function () { 4743 - const ret = module.require; 4744 - return ret; 4745 - }, arguments); 4746 - }; 4747 - 4748 - module.exports.__wbg_set_65595bdd868b3009 = function (arg0, arg1, arg2) { 4749 - arg0.set(arg1, arg2 >>> 0); 4750 - }; 4751 - 4752 - module.exports.__wbg_set_8fc6bf8a5b1071d1 = function (arg0, arg1, arg2) { 4753 - const ret = arg0.set(arg1, arg2); 4754 - return ret; 4755 - }; 4756 - 4757 - module.exports.__wbg_set_bb8cecf6a62b9f46 = function () { 4758 - return handleError(function (arg0, arg1, arg2) { 4759 - const ret = Reflect.set(arg0, arg1, arg2); 4760 - return ret; 4761 - }, arguments); 4762 - }; 4763 - 4764 - module.exports.__wbg_stack_0ed75d68575b0f3c = function (arg0, arg1) { 4765 - const ret = arg1.stack; 4766 - const ptr1 = passStringToWasm0( 4767 - ret, 4768 - wasm.__wbindgen_malloc, 4769 - wasm.__wbindgen_realloc, 4770 - ); 4771 - const len1 = WASM_VECTOR_LEN; 4772 - getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); 4773 - getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); 4774 - }; 4775 - 4776 - module.exports.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function () { 4777 - const ret = typeof global === "undefined" ? null : global; 4778 - return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); 4779 - }; 4780 - 4781 - module.exports.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = 4782 - function () { 4783 - const ret = typeof globalThis === "undefined" ? null : globalThis; 4784 - return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); 4785 - }; 4786 - 4787 - module.exports.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function () { 4788 - const ret = typeof self === "undefined" ? null : self; 4789 - return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); 4790 - }; 4791 - 4792 - module.exports.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function () { 4793 - const ret = typeof window === "undefined" ? null : window; 4794 - return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); 4795 - }; 4796 - 4797 - module.exports.__wbg_stringify_f7ed6987935b4a24 = function () { 4798 - return handleError(function (arg0) { 4799 - const ret = JSON.stringify(arg0); 4800 - return ret; 4801 - }, arguments); 4802 - }; 4803 - 4804 - module.exports.__wbg_subarray_aa9065fa9dc5df96 = function (arg0, arg1, arg2) { 4805 - const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0); 4806 - return ret; 4807 - }; 4808 - 4809 - module.exports.__wbg_versions_c01dfd4722a88165 = function (arg0) { 4810 - const ret = arg0.versions; 4811 - return ret; 4812 - }; 4813 - 4814 - module.exports.__wbg_yarray_new = function (arg0) { 4815 - const ret = YArray.__wrap(arg0); 4816 - return ret; 4817 - }; 4818 - 4819 - module.exports.__wbg_yarrayevent_new = function (arg0) { 4820 - const ret = YArrayEvent.__wrap(arg0); 4821 - return ret; 4822 - }; 4823 - 4824 - module.exports.__wbg_ydoc_new = function (arg0) { 4825 - const ret = YDoc.__wrap(arg0); 4826 - return ret; 4827 - }; 4828 - 4829 - module.exports.__wbg_ymap_new = function (arg0) { 4830 - const ret = YMap.__wrap(arg0); 4831 - return ret; 4832 - }; 4833 - 4834 - module.exports.__wbg_ymapevent_new = function (arg0) { 4835 - const ret = YMapEvent.__wrap(arg0); 4836 - return ret; 4837 - }; 4838 - 4839 - module.exports.__wbg_ysubdocsevent_new = function (arg0) { 4840 - const ret = YSubdocsEvent.__wrap(arg0); 4841 - return ret; 4842 - }; 4843 - 4844 - module.exports.__wbg_ytext_new = function (arg0) { 4845 - const ret = YText.__wrap(arg0); 4846 - return ret; 4847 - }; 4848 - 4849 - module.exports.__wbg_ytextevent_new = function (arg0) { 4850 - const ret = YTextEvent.__wrap(arg0); 4851 - return ret; 4852 - }; 4853 - 4854 - module.exports.__wbg_ytransaction_new = function (arg0) { 4855 - const ret = YTransaction.__wrap(arg0); 4856 - return ret; 4857 - }; 4858 - 4859 - module.exports.__wbg_yundoevent_new = function (arg0) { 4860 - const ret = YUndoEvent.__wrap(arg0); 4861 - return ret; 4862 - }; 4863 - 4864 - module.exports.__wbg_yweaklink_new = function (arg0) { 4865 - const ret = YWeakLink.__wrap(arg0); 4866 - return ret; 4867 - }; 4868 - 4869 - module.exports.__wbg_yweaklinkevent_new = function (arg0) { 4870 - const ret = YWeakLinkEvent.__wrap(arg0); 4871 - return ret; 4872 - }; 4873 - 4874 - module.exports.__wbg_yxmlelement_new = function (arg0) { 4875 - const ret = YXmlElement.__wrap(arg0); 4876 - return ret; 4877 - }; 4878 - 4879 - module.exports.__wbg_yxmlevent_new = function (arg0) { 4880 - const ret = YXmlEvent.__wrap(arg0); 4881 - return ret; 4882 - }; 4883 - 4884 - module.exports.__wbg_yxmlfragment_new = function (arg0) { 4885 - const ret = YXmlFragment.__wrap(arg0); 4886 - return ret; 4887 - }; 4888 - 4889 - module.exports.__wbg_yxmltext_new = function (arg0) { 4890 - const ret = YXmlText.__wrap(arg0); 4891 - return ret; 4892 - }; 4893 - 4894 - module.exports.__wbg_yxmltextevent_new = function (arg0) { 4895 - const ret = YXmlTextEvent.__wrap(arg0); 4896 - return ret; 4897 - }; 4898 - 4899 - module.exports.__wbindgen_bigint_from_i64 = function (arg0) { 4900 - const ret = arg0; 4901 - return ret; 4902 - }; 4903 - 4904 - module.exports.__wbindgen_bigint_from_u64 = function (arg0) { 4905 - const ret = BigInt.asUintN(64, arg0); 4906 - return ret; 4907 - }; 4908 - 4909 - module.exports.__wbindgen_boolean_get = function (arg0) { 4910 - const v = arg0; 4911 - const ret = typeof v === "boolean" ? (v ? 1 : 0) : 2; 4912 - return ret; 4913 - }; 4914 - 4915 - module.exports.__wbindgen_debug_string = function (arg0, arg1) { 4916 - const ret = debugString(arg1); 4917 - const ptr1 = passStringToWasm0( 4918 - ret, 4919 - wasm.__wbindgen_malloc, 4920 - wasm.__wbindgen_realloc, 4921 - ); 4922 - const len1 = WASM_VECTOR_LEN; 4923 - getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); 4924 - getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); 4925 - }; 4926 - 4927 - module.exports.__wbindgen_init_externref_table = function () { 4928 - const table = wasm.__wbindgen_export_2; 4929 - const offset = table.grow(4); 4930 - table.set(0, undefined); 4931 - table.set(offset + 0, undefined); 4932 - table.set(offset + 1, null); 4933 - table.set(offset + 2, true); 4934 - table.set(offset + 3, false); 4935 - }; 4936 - 4937 - module.exports.__wbindgen_is_bigint = function (arg0) { 4938 - const ret = typeof arg0 === "bigint"; 4939 - return ret; 4940 - }; 4941 - 4942 - module.exports.__wbindgen_is_function = function (arg0) { 4943 - const ret = typeof arg0 === "function"; 4944 - return ret; 4945 - }; 4946 - 4947 - module.exports.__wbindgen_is_null = function (arg0) { 4948 - const ret = arg0 === null; 4949 - return ret; 4950 - }; 4951 - 4952 - module.exports.__wbindgen_is_object = function (arg0) { 4953 - const val = arg0; 4954 - const ret = typeof val === "object" && val !== null; 4955 - return ret; 4956 - }; 4957 - 4958 - module.exports.__wbindgen_is_string = function (arg0) { 4959 - const ret = typeof arg0 === "string"; 4960 - return ret; 4961 - }; 4962 - 4963 - module.exports.__wbindgen_is_undefined = function (arg0) { 4964 - const ret = arg0 === undefined; 4965 - return ret; 4966 - }; 4967 - 4968 - module.exports.__wbindgen_memory = function () { 4969 - const ret = wasm.memory; 4970 - return ret; 4971 - }; 4972 - 4973 - module.exports.__wbindgen_number_get = function (arg0, arg1) { 4974 - const obj = arg1; 4975 - const ret = typeof obj === "number" ? obj : undefined; 4976 - getDataViewMemory0().setFloat64( 4977 - arg0 + 8 * 1, 4978 - isLikeNone(ret) ? 0 : ret, 4979 - true, 4980 - ); 4981 - getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true); 4982 - }; 4983 - 4984 - module.exports.__wbindgen_number_new = function (arg0) { 4985 - const ret = arg0; 4986 - return ret; 4987 - }; 4988 - 4989 - module.exports.__wbindgen_string_get = function (arg0, arg1) { 4990 - const obj = arg1; 4991 - const ret = typeof obj === "string" ? obj : undefined; 4992 - var ptr1 = isLikeNone(ret) 4993 - ? 0 4994 - : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); 4995 - var len1 = WASM_VECTOR_LEN; 4996 - getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); 4997 - getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); 4998 - }; 4999 - 5000 - module.exports.__wbindgen_string_new = function (arg0, arg1) { 5001 - const ret = getStringFromWasm0(arg0, arg1); 5002 - return ret; 5003 - }; 5004 - 5005 - module.exports.__wbindgen_throw = function (arg0, arg1) { 5006 - throw new Error(getStringFromWasm0(arg0, arg1)); 5007 - }; 5008 - 5009 - const path = require("path").join( 5010 - process.cwd(), 5011 - "public", 5012 - "wasm", 5013 - "ywasm_bg.wasm", 5014 - ); 5015 - const bytes = require("fs").readFileSync(path); 5016 - 5017 - const wasmModule = new WebAssembly.Module(bytes); 5018 - const wasmInstance = new WebAssembly.Instance(wasmModule, imports); 5019 - wasm = wasmInstance.exports; 5020 - module.exports.__wasm = wasm; 5021 - 5022 - wasm.__wbindgen_start();