@liveblocks/emails 3.13.1-hackathon → 3.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-emails/dist/index.cjs","../src/index.ts","../src/version.ts","../src/text-mention-notification.tsx","../src/lexical-editor.ts","../../../node_modules/lib0/map.js","../../../node_modules/lib0/set.js","../../../node_modules/lib0/array.js","../../../node_modules/lib0/observable.js","../../../node_modules/lib0/math.js","../../../node_modules/lib0/binary.js","../../../node_modules/lib0/number.js","../../../node_modules/lib0/string.js","../../../node_modules/lib0/encoding.js","../../../node_modules/lib0/error.js","../../../node_modules/lib0/decoding.js","../../../node_modules/lib0/webcrypto.node.js","../../../node_modules/lib0/random.js","../../../node_modules/lib0/time.js","../../../node_modules/lib0/promise.js","../../../node_modules/lib0/conditions.js","../../../node_modules/lib0/storage.js","../../../node_modules/lib0/object.js","../../../node_modules/lib0/function.js","../../../node_modules/lib0/environment.js","../../../node_modules/lib0/buffer.js","../../../node_modules/lib0/symbol.js","../../../node_modules/lib0/logging.common.js","../../../node_modules/lib0/logging.node.js","../../../node_modules/lib0/iterator.js","../../../node_modules/yjs/src/utils/DeleteSet.js","../../../node_modules/yjs/src/utils/Doc.js","../../../node_modules/yjs/src/utils/UpdateDecoder.js","../../../node_modules/yjs/src/utils/UpdateEncoder.js","../../../node_modules/yjs/src/utils/encoding.js","../../../node_modules/yjs/src/utils/EventHandler.js","../../../node_modules/yjs/src/utils/ID.js","../../../node_modules/yjs/src/utils/Snapshot.js","../../../node_modules/yjs/src/utils/StructStore.js","../../../node_modules/yjs/src/utils/Transaction.js","../../../node_modules/yjs/src/utils/updates.js","../../../node_modules/yjs/src/utils/YEvent.js","../../../node_modules/yjs/src/types/AbstractType.js","../../../node_modules/yjs/src/types/YArray.js","../../../node_modules/yjs/src/types/YMap.js","../../../node_modules/yjs/src/types/YText.js","../../../node_modules/yjs/src/types/YXmlFragment.js","../../../node_modules/yjs/src/types/YXmlElement.js","../../../node_modules/yjs/src/types/YXmlEvent.js","../../../node_modules/yjs/src/types/YXmlHook.js","../../../node_modules/yjs/src/types/YXmlText.js","../../../node_modules/yjs/src/structs/AbstractStruct.js","../../../node_modules/yjs/src/structs/GC.js","../../../node_modules/yjs/src/structs/ContentBinary.js","../../../node_modules/yjs/src/structs/ContentDeleted.js","../../../node_modules/yjs/src/structs/ContentDoc.js","../../../node_modules/yjs/src/structs/ContentEmbed.js","../../../node_modules/yjs/src/structs/ContentFormat.js","../../../node_modules/yjs/src/structs/ContentJSON.js","../../../node_modules/yjs/src/structs/ContentAny.js","../../../node_modules/yjs/src/structs/ContentString.js","../../../node_modules/yjs/src/structs/ContentType.js","../../../node_modules/yjs/src/structs/Item.js","../../../node_modules/yjs/src/structs/Skip.js","../../../node_modules/yjs/src/index.js","../src/lib/utils.ts","../src/lib/batch-resolvers.ts","../src/lib/css-properties.ts","../src/tiptap-editor.ts","../../../node_modules/y-prosemirror/src/plugins/sync-plugin.js","../../../node_modules/y-prosemirror/src/lib.js","../src/liveblocks-text-editor.ts","../src/text-mention-content.tsx","../src/thread-notification.tsx","../src/comment-body.tsx","../src/comment-with-body.ts"],"names":["create","args","isNaN","struct","keys","length","id","html","htmlSafe","MENTION_CHARACTER","jsx"],"mappings":"AAAA;ACAA,wCAA4B;ADE5B;AACA;AEAO,IAAM,SAAA,EAAW,oBAAA;AACjB,IAAM,YAAA,EAAiD,kBAAA;AACvD,IAAM,WAAA,EAAgD,KAAA;AFE7D;AACA;AGRA;AAME;AACA;AACA;AAAA;AHMF;AACA;AIdA;AJgBA;AACA;AKJO,IAAM,OAAA,EAAS,CAAA,EAAA,mBAAM,IAAI,GAAA,CAAI,CAAA;AAU7B,IAAM,K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AC3D,EAAA;A9C8hKyF;AACA;AACA;A8C3hK7E,EAAA;AACY,IAAA;AACxB,EAAA;A9C6hKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8C1hKrC,EAAA;AACC,IAAA;AACtB,IAAA;AACgB,MAAA;AAC/C,IAAA;AACqC,IAAA;AACqC,MAAA;AACrE,IAAA;AACM,IAAA;AACX,EAAA;A9C4hKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8CzhK/D,EAAA;AACC,IAAA;AACa,MAAA;AACwB,QAAA;AACzD,MAAA;AACI,IAAA;AAE0C,MAAA;AACrD,IAAA;AACA,EAAA;A9C0hKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8CvhK5D,EAAA;AACF,IAAA;AACa,MAAA;AACmC,QAAA;AACJ,QAAA;AAChE,MAAA;AACI,IAAA;AACC,MAAA;A9CyhK6E;A8CzhKxC,QAAA;A9C2hKwC,MAAA;A8C1hKjB,MAAA;AACjC,MAAA;AACc,QAAA;AACrD,MAAA;AACoC,MAAA;AACpC,IAAA;AACA,EAAA;A9C4hKyF;AACA;AACA;AACA;AACA;AACA;A8CzhK5D,EAAA;AACF,IAAA;AACa,MAAA;AACe,QAAA;AAChD,MAAA;AACI,IAAA;AAEmC,MAAA;AAC9C,IAAA;AACA,EAAA;A9C0hKyF;AACA;AACA;AACA;AACA;A8CvhK5E,EAAA;AACkB,IAAA;AAC/B,EAAA;A9CyhKyF;AACA;AACA;AACA;AACA;A8CthKxE,EAAA;AACmB,IAAA;AACpC,EAAA;A9CwhKyF;AACA;AACA;AACA;AACA;A8CrhKrE,EAAA;AACM,IAAA;AAC1B,EAAA;A9CuhKyF;AACA;AACA;AACA;AACA;AACA;A8CphK3E,EAAA;AACoB,IAAA;AAClC,EAAA;A9CshKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8CnhKlD,EAAA;AACE,IAAA;AACzC,EAAA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E,MAAA;AAC7E,IAAA;AACA,EAAA;A/C06KyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A+Cv6K1C,EAAA;AACpB,IAAA;AACa,MAAA;AAC2B,QAAA;AAC5D,MAAA;AACI,IAAA;AACgF,MAAA;AAC3F,IAAA;AACA,EAAA;A/Cy6KyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A+Ct6K1D,EAAA;AAC3B,IAAA;A/Cw6KqF;A+Cx6K5B,MAAA;A/C06K4B,IAAA;A+Cz6KzF,EAAA;A/C26KyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A+Cx6K1D,EAAA;AAC3B,IAAA;A/C06KqF;A+C16K5B,MAAA;A/C46K4B,IAAA;A+C36KzF,EAAA;A/C66KyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A+C16K9D,EAAA;AACvB,IAAA;A/C46KqF;A+C56KW,MAAA;A/C86KX,IAAA;A+C76KzF,EAAA;A/C+6KyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A+C56KrC,EAAA;AACC,IAAA;AACjB,IAAA;AACP,IAAA;AACA,MAAA;AACQ,MAAA;AACF,QAAA;AACnC,MAAA;AACA,IAAA;AACkC,IAAA;AACyB,MAAA;AACtD,IAAA;AAC0B,IAAA;AACW,MAAA;AAC1C,IAAA;AACW,IAAA;AACX,EAAA;A/C86KyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A+C36KtE,EAAA;AACsB,IAAA;AACP,IAAA;AAClC,EAAA;AACA;AAQ2E;AC5PrC;AhDmqLmD;AACA;AACA;AACA;AACA;AACA;AACA;AgDjqL/C,EAAA;AACb,IAAA;AAMD,IAAA;AAKQ,IAAA;AACV,IAAA;AACF,MAAA;AACQ,QAAA;AACnB,MAAA;AACyB,QAAA;AACtC,MAAA;AACK,IAAA;AACL,EAAA;AACA;AC3BmC;AjDsrLsD;AACA;AACA;AiDprLhE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;AAC5C,EAAA;AACjB,IAAA;AACA,IAAA;AACA,IAAA;AACwB,MAAA;AACK,MAAA;AACF,MAAA;AAC3B,IAAA;AACA,IAAA;AAGO,MAAA;AAKA,MAAA;AAIHC,MAAAA;AAAY,QAAA;AAAX,QAAA;AAEC,UAAA;AAAA,QAAA;AADkC,QAAA;AAEpC,MAAA;AAGAA,MAAAA;AAAY,QAAA;AAAX,QAAA;AAEC,UAAA;AACA,UAAA;AAAA,QAAA;AAFkC,QAAA;AAGpC,MAAA;AAIEA,MAAAA;AAAY,QAAA;AAAX,QAAA;AAEC,UAAA;AACA,UAAA;AACA,UAAA;AAAA,QAAA;AAHqC,QAAA;AAKrC,MAAA;AACR,IAAA;AACA,IAAA;AACF,EAAA;AAEmB,EAAA;AACV,IAAA;AACT,EAAA;AAEO,EAAA;AACT;AzEk6PyF;AACA;AC5rR5C;AD8rR4C;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/liveblocks/liveblocks/packages/liveblocks-emails/dist/index.cjs","sourcesContent":[null,"import { detectDupes } from \"@liveblocks/core\";\n\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type { ResolveRoomInfoArgs } from \"./lib/types\";\nexport type {\n ConvertTextEditorNodesAsHtmlStyles,\n ConvertTextEditorNodesAsReactComponents,\n MentionEmailAsHtmlData,\n MentionEmailAsReactData,\n PrepareTextMentionNotificationEmailAsHtmlOptions,\n PrepareTextMentionNotificationEmailAsReactOptions,\n TextEditorContainerComponentProps,\n TextEditorMentionComponentProps,\n TextEditorTextComponentProps,\n TextMentionNotificationEmailDataAsHtml,\n TextMentionNotificationEmailDataAsReact,\n} from \"./text-mention-notification\";\nexport {\n prepareTextMentionNotificationEmailAsHtml,\n prepareTextMentionNotificationEmailAsReact,\n} from \"./text-mention-notification\";\nexport type {\n CommentBodyContainerComponentProps,\n CommentBodyLinkComponentProps,\n CommentBodyMentionComponentProps,\n CommentBodyParagraphComponentProps,\n CommentBodyTextComponentProps,\n CommentEmailAsHtmlData,\n CommentEmailAsReactData,\n ConvertCommentBodyAsHtmlStyles,\n ConvertCommentBodyAsReactComponents,\n PrepareThreadNotificationEmailAsHtmlOptions,\n PrepareThreadNotificationEmailAsReactOptions,\n ThreadNotificationEmailDataAsHtml,\n ThreadNotificationEmailDataAsReact,\n} from \"./thread-notification\";\nexport {\n prepareThreadNotificationEmailAsHtml,\n prepareThreadNotificationEmailAsReact,\n} from \"./thread-notification\";\nexport type { ResolveGroupsInfoArgs, ResolveUsersArgs } from \"@liveblocks/core\";\n","declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/emails\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n","import {\n type Awaitable,\n type BaseUserMeta,\n type DGI,\n type DRI,\n type DU,\n html,\n htmlSafe,\n MENTION_CHARACTER,\n type MentionData,\n type ResolveGroupsInfoArgs,\n type ResolveUsersArgs,\n} from \"@liveblocks/core\";\nimport type {\n Liveblocks,\n TextMentionNotificationEvent,\n} from \"@liveblocks/node\";\nimport type { ComponentType, ReactNode } from \"react\";\n\nimport type { LexicalMentionNodeWithContext } from \"./lexical-editor\";\nimport {\n findLexicalMentionNodeWithContext,\n getMentionDataFromLexicalNode,\n getSerializedLexicalState,\n} from \"./lexical-editor\";\nimport {\n createBatchGroupsInfoResolver,\n createBatchUsersResolver,\n getResolvedForId,\n} from \"./lib/batch-resolvers\";\nimport type { CSSProperties } from \"./lib/css-properties\";\nimport { toInlineCSSString } from \"./lib/css-properties\";\nimport type { ResolveRoomInfoArgs } from \"./lib/types\";\nimport type {\n LiveblocksTextEditorMentionNode,\n LiveblocksTextEditorNode,\n LiveblocksTextEditorTextNode,\n} from \"./liveblocks-text-editor\";\nimport { transformAsLiveblocksTextEditorNodes } from \"./liveblocks-text-editor\";\nimport {\n convertTextMentionContent,\n type ConvertTextMentionContentElements,\n} from \"./text-mention-content\";\nimport type { TiptapMentionNodeWithContext } from \"./tiptap-editor\";\nimport {\n findTiptapMentionNodeWithContext,\n getMentionDataFromTiptapNode,\n getSerializedTiptapState,\n} from \"./tiptap-editor\";\n\n/** @internal hidden types */\ntype RoomTextEditor = {\n type: \"lexical\" | \"tiptap\";\n rootKey: string[];\n};\n\nexport type TextMentionNotificationData = (\n | {\n editor: \"lexical\";\n mentionNodeWithContext: LexicalMentionNodeWithContext;\n }\n | {\n editor: \"tiptap\";\n mentionNodeWithContext: TiptapMentionNodeWithContext;\n }\n) & {\n createdAt: Date;\n createdBy: string;\n mentionData: MentionData;\n};\n\n/** @internal */\nexport const extractTextMentionNotificationData = async ({\n client,\n event,\n}: {\n client: Liveblocks;\n event: TextMentionNotificationEvent;\n}): Promise<TextMentionNotificationData | null> => {\n const { roomId, userId, inboxNotificationId } = event.data;\n\n const [room, inboxNotification] = await Promise.all([\n client.getRoom(roomId),\n client.getInboxNotification({ inboxNotificationId, userId }),\n ]);\n\n // Check for notification kind\n if (inboxNotification.kind !== \"textMention\") {\n console.warn('Inbox notification is not of kind \"textMention\"');\n return null;\n }\n\n // Aligned behaviors w/ `@liveblocks/react-ui`.\n const isUnread =\n inboxNotification.readAt === null ||\n inboxNotification.notifiedAt > inboxNotification.readAt;\n\n // Notification read so do nothing\n if (!isUnread) {\n return null;\n }\n\n // Do nothing if the room as no text editor associated.\n // We do not throw not to impact the final developer experience.\n // @ts-expect-error - Hidden property\n const textEditor = room.experimental_textEditor as RoomTextEditor | undefined;\n if (!textEditor) {\n console.warn(`Room \"${room.id}\" does not a text editor associated with it`);\n return null;\n }\n\n // For now we use the `notifiedAt` inbox notification data\n // to represent the creation date as we have currently\n // a 1 - 1 notification <> activity\n const mentionCreatedAt = inboxNotification.notifiedAt;\n // In context of a text mention notification `createdBy` is a user ID\n const mentionAuthorUserId = inboxNotification.createdBy;\n\n const buffer = await client.getYjsDocumentAsBinaryUpdate(roomId);\n const editorKey = textEditor.rootKey;\n // TODO: temporarily grab the first entrance, later we will handle multiple editors\n const key = Array.isArray(editorKey) ? editorKey[0]! : editorKey;\n\n switch (textEditor.type) {\n case \"lexical\": {\n const state = getSerializedLexicalState({ buffer, key });\n const mentionNodeWithContext = findLexicalMentionNodeWithContext({\n root: state,\n textMentionId: inboxNotification.mentionId,\n });\n\n // The mention node did not exists so we do not have to send an email.\n if (mentionNodeWithContext === null) {\n return null;\n }\n\n const mentionData = getMentionDataFromLexicalNode(\n mentionNodeWithContext.mention\n );\n\n return {\n editor: \"lexical\",\n mentionNodeWithContext,\n mentionData,\n createdAt: mentionCreatedAt,\n createdBy: mentionAuthorUserId,\n };\n }\n case \"tiptap\": {\n const state = getSerializedTiptapState({ buffer, key });\n const mentionNodeWithContext = findTiptapMentionNodeWithContext({\n root: state,\n textMentionId: inboxNotification.mentionId,\n });\n\n // The mention node did not exists so we do not have to send an email.\n if (mentionNodeWithContext === null) {\n return null;\n }\n\n const mentionData = getMentionDataFromTiptapNode(\n mentionNodeWithContext.mention\n );\n\n return {\n editor: \"tiptap\",\n mentionNodeWithContext,\n mentionData,\n createdAt: mentionCreatedAt,\n createdBy: mentionAuthorUserId,\n };\n }\n }\n};\n\nexport type MentionEmailData<\n ContentType,\n U extends BaseUserMeta = DU,\n> = MentionData & {\n textMentionId: string;\n roomId: string;\n author: U; // Author of the mention\n createdAt: Date;\n content: ContentType;\n};\n\nexport type MentionEmailAsHtmlData<U extends BaseUserMeta = DU> =\n MentionEmailData<string, U>;\n\nexport type MentionEmailAsReactData<U extends BaseUserMeta = DU> =\n MentionEmailData<ReactNode, U>;\n\nexport type TextMentionNotificationEmailData<\n ContentType,\n U extends BaseUserMeta = DU,\n M extends MentionEmailData<ContentType, U> = MentionEmailData<ContentType, U>,\n> = {\n mention: M;\n roomInfo: DRI;\n};\n\ntype PrepareTextMentionNotificationEmailOptions<U extends BaseUserMeta = DU> = {\n /**\n * A function that returns room info from room IDs.\n */\n resolveRoomInfo?: (args: ResolveRoomInfoArgs) => Awaitable<DRI | undefined>;\n\n /**\n * A function that returns user info from user IDs.\n * You should return a list of user objects of the same size, in the same order.\n */\n resolveUsers?: (\n args: ResolveUsersArgs\n ) => Awaitable<(U[\"info\"] | undefined)[] | undefined>;\n\n /**\n * A function that returns group info from group IDs.\n * You should return a list of group info objects of the same size, in the same order.\n */\n resolveGroupsInfo?: (\n args: ResolveGroupsInfoArgs\n ) => Awaitable<(DGI | undefined)[] | undefined>;\n};\n\n/**\n * @internal\n * exported for testing purposes.\n */\nexport async function prepareTextMentionNotificationEmail<\n ContentType,\n U extends BaseUserMeta = DU,\n>(\n client: Liveblocks,\n event: TextMentionNotificationEvent,\n options: PrepareTextMentionNotificationEmailOptions<U>,\n elements: ConvertTextMentionContentElements<ContentType, U>,\n callerName: string\n): Promise<TextMentionNotificationEmailData<ContentType, U> | null> {\n const { roomId, mentionId } = event.data;\n\n const data = await extractTextMentionNotificationData({ client, event });\n if (data === null) {\n return null;\n }\n\n const roomInfo = options.resolveRoomInfo\n ? await options.resolveRoomInfo({ roomId: event.data.roomId })\n : undefined;\n\n const resolvedRoomInfo: DRI = {\n ...roomInfo,\n name: roomInfo?.name ?? event.data.roomId,\n };\n\n const batchUsersResolver = createBatchUsersResolver<U>({\n resolveUsers: options.resolveUsers,\n callerName,\n });\n const batchGroupsInfoResolver = createBatchGroupsInfoResolver({\n resolveGroupsInfo: options.resolveGroupsInfo,\n callerName,\n });\n\n const authorsIds = [data.createdBy];\n const authorsInfoPromise = batchUsersResolver.get(authorsIds);\n\n let textEditorNodes: LiveblocksTextEditorNode[] = [];\n\n switch (data.editor) {\n case \"lexical\": {\n textEditorNodes = transformAsLiveblocksTextEditorNodes({\n editor: \"lexical\",\n mention: data.mentionNodeWithContext,\n });\n break;\n }\n case \"tiptap\": {\n textEditorNodes = transformAsLiveblocksTextEditorNodes({\n editor: \"tiptap\",\n mention: data.mentionNodeWithContext,\n });\n break;\n }\n }\n\n const contentPromise = convertTextMentionContent<ContentType, U>(\n textEditorNodes,\n {\n resolveUsers: ({ userIds }) => batchUsersResolver.get(userIds),\n resolveGroupsInfo: ({ groupIds }) =>\n batchGroupsInfoResolver.get(groupIds),\n elements,\n }\n );\n\n await batchUsersResolver.resolve();\n await batchGroupsInfoResolver.resolve();\n\n const [authorsInfo, content] = await Promise.all([\n authorsInfoPromise,\n contentPromise,\n ]);\n\n const authorInfo = getResolvedForId(data.createdBy, authorsIds, authorsInfo);\n\n return {\n mention: {\n ...data.mentionData,\n textMentionId: mentionId,\n roomId,\n author: {\n id: data.createdBy,\n info: authorInfo ?? { name: data.createdBy },\n } as U,\n content,\n createdAt: data.createdAt,\n },\n roomInfo: resolvedRoomInfo,\n };\n}\n\nexport type TextEditorContainerComponentProps = {\n /**\n * The nodes of the text editor\n */\n children: ReactNode;\n};\n\nexport type TextEditorMentionComponentProps<U extends BaseUserMeta = DU> = {\n /**\n * The mention element.\n */\n element: LiveblocksTextEditorMentionNode;\n\n /**\n * The mention's user info, if the mention is a user mention and the `resolvedUsers` option was provided.\n */\n user?: U[\"info\"];\n\n /**\n * The mention's group info, if the mention is a group mention and the `resolvedGroupsInfo` option was provided.\n */\n group?: DGI;\n};\n\nexport type TextEditorTextComponentProps = {\n /**\n * The text element.\n */\n element: LiveblocksTextEditorTextNode;\n};\n\nexport type ConvertTextEditorNodesAsReactComponents<\n U extends BaseUserMeta = DU,\n> = {\n /**\n *\n * The component used to act as a container to wrap text editor nodes,\n */\n Container: ComponentType<TextEditorContainerComponentProps>;\n\n /**\n * The component used to display mentions.\n */\n Mention: ComponentType<TextEditorMentionComponentProps<U>>;\n\n /**\n * The component used to display text nodes.\n */\n Text: ComponentType<TextEditorTextComponentProps>;\n};\n\nconst baseComponents: ConvertTextEditorNodesAsReactComponents<BaseUserMeta> = {\n Container: ({ children }) => <div>{children}</div>,\n Mention: ({ element, user, group }) => (\n <span data-mention>\n {MENTION_CHARACTER}\n {user?.name ?? group?.name ?? element.id}\n </span>\n ),\n Text: ({ element }) => {\n // Note: construction following the schema 👇\n // <code><s><em><strong>{element.text}</strong></s></em></code>\n let children: ReactNode = element.text;\n\n if (element.bold) {\n children = <strong>{children}</strong>;\n }\n\n if (element.italic) {\n children = <em>{children}</em>;\n }\n\n if (element.strikethrough) {\n children = <s>{children}</s>;\n }\n\n if (element.code) {\n children = <code>{children}</code>;\n }\n\n return <span>{children}</span>;\n },\n};\n\nexport type PrepareTextMentionNotificationEmailAsReactOptions<\n U extends BaseUserMeta = DU,\n> = PrepareTextMentionNotificationEmailOptions & {\n /**\n * The components used to customize the resulting React nodes. Each components has\n * priority over the base components inherited.\n */\n components?: Partial<ConvertTextEditorNodesAsReactComponents<U>>;\n};\n\nexport type TextMentionNotificationEmailDataAsReact<\n U extends BaseUserMeta = DU,\n> = TextMentionNotificationEmailData<ReactNode, U, MentionEmailAsReactData<U>>;\n\n/**\n * Prepares data from a `TextMentionNotificationEvent` and convert content as React nodes.\n *\n * @param client The `Liveblocks` node client\n * @param event The `TextMentionNotificationEvent` received in the webhook handler\n * @param options The optional options to provide to resolve users, resolve room info and customize comment bodies React components.\n *\n * It returns a `TextMentionNotificationEmailDataAsReact` or `null` if there are no existing text mention.\n *\n * @example\n * import { Liveblocks} from \"@liveblocks/node\"\n * import { prepareTextMentionNotificationEmailAsReact } from \"@liveblocks/emails\"\n *\n * const liveblocks = new Liveblocks({ secret: \"sk_...\" })\n * const emailData = prepareTextMentionNotificationEmailAsReact(\n * liveblocks,\n * event,\n * {\n * resolveUsers,\n * resolveRoomInfo,\n * components,\n * }\n * )\n */\nexport async function prepareTextMentionNotificationEmailAsReact(\n client: Liveblocks,\n event: TextMentionNotificationEvent,\n options: PrepareTextMentionNotificationEmailAsReactOptions<BaseUserMeta> = {}\n): Promise<TextMentionNotificationEmailDataAsReact | null> {\n const Components = { ...baseComponents, ...options.components };\n const data = await prepareTextMentionNotificationEmail<\n ReactNode,\n BaseUserMeta\n >(\n client,\n event,\n {\n resolveRoomInfo: options.resolveRoomInfo,\n resolveUsers: options.resolveUsers,\n },\n {\n container: ({ children }) => (\n <Components.Container key=\"lb-text-editor-container\">\n {children}\n </Components.Container>\n ),\n mention: ({ node, user }, index) => (\n <Components.Mention\n key={`lb-text-editor-mention-${index}`}\n element={node}\n user={user}\n />\n ),\n text: ({ node }, index) => (\n <Components.Text key={`lb-text-editor-text-${index}`} element={node} />\n ),\n },\n \"prepareTextMentionNotificationEmailAsReact\"\n );\n\n if (data === null) {\n return null;\n }\n\n return data;\n}\n\nexport type ConvertTextEditorNodesAsHtmlStyles = {\n /**\n * The default inline CSS styles used to display container element.\n */\n container: CSSProperties;\n /**\n * The default inline CSS styles used to display text `<strong />` elements.\n */\n strong: CSSProperties;\n /**\n * The default inline CSS styles used to display text `<code />` elements.\n */\n code: CSSProperties;\n /**\n * The default inline CSS styles used to display mentions.\n */\n mention: CSSProperties;\n};\n\nexport const baseStyles: ConvertTextEditorNodesAsHtmlStyles = {\n container: {\n fontSize: \"14px\",\n },\n strong: {\n fontWeight: 500,\n },\n code: {\n fontFamily:\n 'ui-monospace, Menlo, Monaco, \"Cascadia Mono\", \"Segoe UI Mono\", \"Roboto Mono\", \"Oxygen Mono\", \"Ubuntu Mono\", \"Source Code Pro\", \"Fira Mono\", \"Droid Sans Mono\", \"Consolas\", \"Courier New\", monospace',\n backgroundColor: \"rgba(0,0,0,0.05)\",\n border: \"solid 1px rgba(0,0,0,0.1)\",\n borderRadius: \"4px\",\n },\n mention: {\n color: \"blue\",\n },\n};\n\nexport type PrepareTextMentionNotificationEmailAsHtmlOptions =\n PrepareTextMentionNotificationEmailOptions & {\n /**\n * The styles used to customize the html elements in the resulting html safe string.\n * Each styles has priority over the base styles inherited.\n */\n styles?: Partial<ConvertTextEditorNodesAsHtmlStyles>;\n };\n\nexport type TextMentionNotificationEmailDataAsHtml<\n U extends BaseUserMeta = DU,\n> = TextMentionNotificationEmailData<string, U, MentionEmailAsHtmlData<U>>;\n\n/**\n * Prepares data from a `TextMentionNotificationEvent` and convert content as an html safe string.\n *\n * @param client The `Liveblocks` node client\n * @param event The `TextMentionNotificationEvent` received in the webhook handler\n * @param options The optional options to provide to resolve users, resolve room info and customize comment bodies React components.\n *\n * It returns a `TextMentionNotificationEmailDataAsReact` or `null` if there are no existing text mention.\n *\n * @example\n * import { Liveblocks} from \"@liveblocks/node\"\n * import { prepareTextMentionNotificationEmailAsHtml } from \"@liveblocks/emails\"\n *\n * const liveblocks = new Liveblocks({ secret: \"sk_...\" })\n * const emailData = prepareTextMentionNotificationEmailAsHtml(\n * liveblocks,\n * event,\n * {\n * resolveUsers,\n * resolveRoomInfo,\n * styles,\n * }\n * )\n */\nexport async function prepareTextMentionNotificationEmailAsHtml(\n client: Liveblocks,\n event: TextMentionNotificationEvent,\n options: PrepareTextMentionNotificationEmailAsHtmlOptions = {}\n): Promise<TextMentionNotificationEmailDataAsHtml | null> {\n const styles = { ...baseStyles, ...options.styles };\n const data = await prepareTextMentionNotificationEmail<string, BaseUserMeta>(\n client,\n event,\n {\n resolveRoomInfo: options.resolveRoomInfo,\n resolveUsers: options.resolveUsers,\n },\n {\n container: ({ children }) => {\n const content = [\n // prettier-ignore\n html`<div style=\"${toInlineCSSString(styles.container)}\">${htmlSafe(children.join(\"\"))}</div>`,\n ];\n\n return content.join(\"\\n\"); //NOTE: to represent a valid HTML string\n },\n mention: ({ node, user, group }) => {\n // prettier-ignore\n return html`<span data-mention style=\"${toInlineCSSString(styles.mention)}\">${MENTION_CHARACTER}${user?.name ? html`${user?.name}` : group?.name ? html`${group?.name}` : node.id}</span>`\n },\n text: ({ node }) => {\n // Note: construction following the schema 👇\n // <code><s><em><strong>{node.text}</strong></s></em></code>\n let children = node.text;\n if (!children) {\n return html`${children}`;\n }\n\n if (node.bold) {\n // prettier-ignore\n children = html`<strong style=\"${toInlineCSSString(styles.strong)}\">${children}</strong>`;\n }\n\n if (node.italic) {\n // prettier-ignore\n children = html`<em>${children}</em>`;\n }\n\n if (node.strikethrough) {\n // prettier-ignore\n children = html`<s>${children}</s>`;\n }\n\n if (node.code) {\n // prettier-ignore\n children = html`<code style=\"${toInlineCSSString(styles.code)}\">${children}</code>`;\n }\n\n return html`${children}`;\n },\n },\n \"prepareTextMentionNotificationEmailAsHtml\"\n );\n\n if (data === null) {\n return null;\n }\n\n return data;\n}\n","import type { Json, JsonObject, MentionData } from \"@liveblocks/core\";\nimport { assertNever } from \"@liveblocks/core\";\nimport * as Y from \"yjs\";\n\nimport { isMentionNodeAttributeId, isString } from \"./lib/utils\";\n\nexport interface SerializedBaseLexicalNode {\n type: string;\n attributes: JsonObject;\n}\n\nexport interface SerializedLexicalTextNode extends SerializedBaseLexicalNode {\n text: string;\n group: \"text\";\n}\n\nexport interface SerializedLexicalElementNode<\n T extends SerializedBaseLexicalNode,\n> extends SerializedBaseLexicalNode {\n children: Array<T>;\n group: \"element\";\n}\n\nexport interface SerializedLexicalDecoratorNode\n extends SerializedBaseLexicalNode {\n group: \"decorator\";\n}\n\nexport interface SerializedLexicalMentionNode\n extends SerializedLexicalDecoratorNode {\n type: \"lb-mention\";\n attributes: {\n __id: string;\n __type: \"lb-mention\";\n __userId: string;\n };\n}\n\nexport interface SerializedLexicalGroupMentionNode\n extends SerializedLexicalDecoratorNode {\n type: \"lb-group-mention\";\n attributes: {\n __id: string;\n __type: \"lb-group-mention\";\n __groupId: string;\n __userIds: string[] | undefined;\n };\n}\n\nexport interface SerializedLexicalLineBreakNode\n extends SerializedBaseLexicalNode {\n group: \"linebreak\";\n}\n\nexport type SerializedLexicalNode =\n | SerializedLexicalTextNode\n | SerializedLexicalLineBreakNode\n | SerializedLexicalDecoratorNode\n | SerializedLexicalElementNode<SerializedLexicalNode>;\n\nexport type SerializedLexicalRootNodeChildren = Array<\n Readonly<\n | SerializedLexicalElementNode<Readonly<SerializedLexicalNode>>\n | SerializedLexicalDecoratorNode\n | SerializedLexicalLineBreakNode\n >\n>;\n\nexport interface SerializedLexicalRootNode\n extends Readonly<SerializedBaseLexicalNode> {\n readonly type: \"root\";\n readonly children: SerializedLexicalRootNodeChildren;\n}\n\n/**\n * Create a serialized Lexical Map node.\n * Y.Map shared types are used to represent text nodes and line break nodes in Lexical.js\n */\nfunction createSerializedLexicalMapNode(\n item: Y.Map<Json>\n): SerializedLexicalTextNode | SerializedLexicalLineBreakNode {\n const type = item.get(\"__type\");\n if (typeof type !== \"string\") {\n throw new Error(\n `Expected ${item.constructor.name} to include type attribute`\n );\n }\n\n // Y.Map in Lexical stores all attributes defined in Lexical TextNode and LineBreakNode class.\n const attributes = Object.fromEntries(item.entries());\n if (type === \"linebreak\") {\n return {\n type,\n attributes,\n group: \"linebreak\",\n };\n }\n\n return {\n type,\n attributes,\n text: \"\",\n group: \"text\",\n };\n}\n\n/**\n * Create a serialized Lexical decorator node.\n * Y.XmlElement shared types are used to represent decorator nodes in Lexical.js\n */\nfunction createSerializedLexicalDecoratorNode(\n item: Y.XmlElement\n): SerializedLexicalDecoratorNode {\n const type = item.getAttribute(\"__type\");\n if (typeof type !== \"string\") {\n throw new Error(\n `Expected ${item.constructor.name} to include type attribute`\n );\n }\n const attributes = item.getAttributes();\n\n return {\n type,\n attributes,\n group: \"decorator\",\n };\n}\n\n/**\n * Create a serialized Lexical element node.\n * Y.XmlText shared types are used to represent element nodes (e.g. paragraph, blockquote) in Lexical.js\n */\nfunction createSerializedLexicalElementNode(\n item: Y.XmlText\n): SerializedLexicalElementNode<SerializedLexicalNode> {\n // Note: disabling eslint rule as `getAttribute` returns `any` by default on `Y.XmlText` items.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const type = item.getAttribute(\"__type\");\n if (typeof type !== \"string\") {\n throw new Error(\n `Expected ${item.constructor.name} to include type attribute`\n );\n }\n const attributes = item.getAttributes();\n\n let start = item._start;\n const children: SerializedLexicalNode[] = [];\n while (start !== null) {\n // If the item is deleted, skip it.\n if (start.deleted) {\n start = start.right;\n continue;\n }\n\n if (start.content instanceof Y.ContentType) {\n const content = start.content.type as Y.AbstractType<Json>;\n if (content instanceof Y.XmlText) {\n children.push(createSerializedLexicalElementNode(content));\n } else if (content instanceof Y.Map) {\n children.push(createSerializedLexicalMapNode(content as Y.Map<Json>));\n } else if (content instanceof Y.XmlElement) {\n children.push(\n createSerializedLexicalDecoratorNode(content as Y.XmlElement)\n );\n }\n }\n // ContentString is used to store text content of a text node in the Y.js doc.\n else if (start.content instanceof Y.ContentString) {\n if (children.length > 0) {\n const last = children[children.length - 1];\n if (last && last.group === \"text\") {\n last.text += start.content.str;\n }\n }\n }\n\n start = start.right;\n }\n\n return {\n type,\n attributes,\n children,\n group: \"element\",\n };\n}\n\n/**\n * Create a serialized Lexical root node.\n */\nexport function createSerializedLexicalRootNode(\n root: Y.XmlText\n): SerializedLexicalRootNode {\n try {\n const children: Array<\n | SerializedLexicalElementNode<SerializedLexicalNode>\n | SerializedLexicalDecoratorNode\n > = [];\n let start = root._start;\n while (start !== null && start !== undefined) {\n // If the item is deleted, skip it.\n if (start.deleted) {\n start = start.right;\n continue;\n }\n\n if (start.content instanceof Y.ContentType) {\n const content = start.content.type as Y.AbstractType<Json>;\n\n // Immediate children of root must be XmlText (element nodes) or XmlElement (decorator nodes).\n if (content instanceof Y.XmlText) {\n children.push(createSerializedLexicalElementNode(content));\n } else if (content instanceof Y.XmlElement) {\n children.push(\n createSerializedLexicalDecoratorNode(content as Y.XmlElement)\n );\n }\n }\n\n start = start.right;\n }\n\n return {\n children,\n type: \"root\",\n attributes: root.getAttributes(),\n };\n } catch (err) {\n console.error(err);\n return {\n children: [],\n type: \"root\",\n attributes: root.getAttributes(),\n };\n }\n}\n\n/**\n * Convert a document as binaries to a\n * serialized lexical state\n */\nexport function getSerializedLexicalState({\n buffer,\n key,\n}: {\n buffer: ArrayBuffer;\n key: string;\n}): SerializedLexicalRootNode {\n const update = new Uint8Array(buffer);\n\n // Construct a Y.js document from the binary update\n const document = new Y.Doc();\n Y.applyUpdate(document, update);\n\n // Convert the Y.js document to a serializable Lexical state\n const root = document.get(key, Y.XmlText);\n const state = createSerializedLexicalRootNode(root);\n\n // Destroy the Y.js document after the conversion\n document.destroy();\n\n return state;\n}\n\n/**\n * Linebreaks in the `Lexical` world are equivalent to\n * hard breaks (like we can have in `tiptap`).\n * They are created by using keys like `shift+enter` or `mod+enter`.\n */\nconst isSerializedLineBreakNode = (\n node: SerializedLexicalNode\n): node is SerializedLexicalLineBreakNode => {\n return node.group === \"linebreak\";\n};\n\nconst isSerializedElementNode = (\n node: SerializedLexicalNode\n): node is SerializedLexicalElementNode<Readonly<SerializedLexicalNode>> => {\n return node.group === \"element\" && node.children !== undefined;\n};\n\nconst isEmptySerializedElementNode = (node: SerializedLexicalNode): boolean => {\n return isSerializedElementNode(node) && node.children.length === 0;\n};\n\nconst isMentionNodeType = (type: string): type is \"lb-mention\" => {\n return type === \"lb-mention\";\n};\n\nconst isMentionNodeAttributeType = (type: unknown): type is \"lb-mention\" => {\n return isString(type) && type === \"lb-mention\";\n};\n\nexport const isSerializedMentionNode = (\n node: SerializedLexicalDecoratorNode\n): node is SerializedLexicalMentionNode => {\n const attributes = node.attributes;\n\n return (\n isMentionNodeType(node.type) &&\n isMentionNodeAttributeType(attributes.__type) &&\n isMentionNodeAttributeId(attributes.__id) &&\n isString(attributes.__userId)\n );\n};\n\nconst isGroupMentionNodeType = (type: string): type is \"lb-group-mention\" => {\n return type === \"lb-group-mention\";\n};\n\nconst isGroupMentionNodeAttributeType = (\n type: unknown\n): type is \"lb-group-mention\" => {\n return isString(type) && type === \"lb-group-mention\";\n};\n\nexport const isSerializedGroupMentionNode = (\n node: SerializedLexicalDecoratorNode\n): node is SerializedLexicalGroupMentionNode => {\n const attributes = node.attributes;\n\n return (\n isGroupMentionNodeType(node.type) &&\n isGroupMentionNodeAttributeType(attributes.__type) &&\n isMentionNodeAttributeId(attributes.__id) &&\n isString(attributes.__groupId) &&\n (attributes.__userIds === undefined || Array.isArray(attributes.__userIds))\n );\n};\n\n/**\n * Internal type helper when flattening nodes.\n * It helps to better extract mention node with context by marking\n * start and ends of paragraph and by handling specific use cases such as\n * using twice the `enter` key which will create an empty paragraph\n * at the first `enter`:\n *\n * \"\n * Hey @charlie what's up?\n * _enter_once_\n * _enter_twice_\n * \"\n */\ninterface FlattenedLexicalElementNodeMarker {\n group: \"element-marker\";\n marker: \"start\" | \"end\";\n}\n\nconst isFlattenedLexicalElementNodeMarker = (\n node: SerializedLexicalNode | FlattenedLexicalElementNodeMarker\n): node is FlattenedLexicalElementNodeMarker => {\n return node.group === \"element-marker\";\n};\n\n/** @internal */\ntype FlattenedSerializedLexicalNodes = Array<\n SerializedLexicalNode | FlattenedLexicalElementNodeMarker\n>;\n\n/** @internal - export for testing only */\nexport const flattenLexicalTree = (\n nodes: SerializedLexicalNode[]\n): FlattenedSerializedLexicalNodes => {\n let flattenNodes: FlattenedSerializedLexicalNodes = [];\n for (const node of nodes) {\n if (\n [\"text\", \"linebreak\", \"decorator\"].includes(node.group) ||\n isEmptySerializedElementNode(node)\n ) {\n flattenNodes = [...flattenNodes, node];\n } else if (node.group === \"element\") {\n flattenNodes = [\n ...flattenNodes,\n {\n group: \"element-marker\",\n marker: \"start\",\n },\n ...flattenLexicalTree(node.children),\n {\n group: \"element-marker\",\n marker: \"end\",\n },\n ];\n }\n }\n\n return flattenNodes;\n};\n\n/**\n * Lexical Mention Node with context\n */\nexport type LexicalMentionNodeWithContext = {\n before: SerializedLexicalNode[];\n after: SerializedLexicalNode[];\n mention: SerializedLexicalMentionNode | SerializedLexicalGroupMentionNode;\n};\n\n/**\n * Find a Lexical mention node\n * and returns it with contextual surrounding text\n */\nexport function findLexicalMentionNodeWithContext({\n root,\n textMentionId,\n}: {\n root: SerializedLexicalRootNode;\n textMentionId: string;\n}): LexicalMentionNodeWithContext | null {\n const nodes = flattenLexicalTree(root.children);\n\n // Find mention node\n let mentionNodeIndex = -1;\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i]!;\n if (\n node.group === \"decorator\" &&\n (isSerializedMentionNode(node) || isSerializedGroupMentionNode(node)) &&\n node.attributes.__id === textMentionId\n ) {\n mentionNodeIndex = i;\n break;\n }\n }\n\n // No mention node found\n if (mentionNodeIndex === -1) {\n return null;\n }\n\n // Collect nodes before and after\n const mentionNode = nodes[mentionNodeIndex] as\n | SerializedLexicalMentionNode\n | SerializedLexicalGroupMentionNode;\n\n // Apply surrounding text guesses\n // For now let's stay simple just stop at nearest line break or element\n const beforeNodes: SerializedLexicalNode[] = [];\n const afterNodes: SerializedLexicalNode[] = [];\n\n // Nodes before mention node\n for (let i = mentionNodeIndex - 1; i >= 0; i--) {\n const node = nodes[i]!;\n\n // Stop if nodes are markers, line breaks or empty elements\n if (\n isFlattenedLexicalElementNodeMarker(node) ||\n isSerializedLineBreakNode(node)\n ) {\n break;\n }\n\n // Stop if decorator node isn't a mention\n if (node.group === \"decorator\" && !isMentionNodeType(node.type)) {\n break;\n }\n\n beforeNodes.unshift(node);\n }\n\n // Nodes after mention node\n for (let i = mentionNodeIndex + 1; i < nodes.length; i++) {\n const node = nodes[i]!;\n\n // Stop if nodes are markers, line breaks or empty elements\n if (\n isFlattenedLexicalElementNodeMarker(node) ||\n isSerializedLineBreakNode(node)\n ) {\n break;\n }\n\n // Stop if decorator node isn't a mention\n if (node.group === \"decorator\" && !isMentionNodeType(node.type)) {\n break;\n }\n\n afterNodes.push(node);\n }\n\n return {\n before: beforeNodes,\n after: afterNodes,\n mention: mentionNode,\n };\n}\n\nexport function getMentionDataFromLexicalNode(\n node: SerializedLexicalMentionNode | SerializedLexicalGroupMentionNode\n): MentionData {\n if (isSerializedMentionNode(node)) {\n return {\n kind: \"user\",\n id: node.attributes.__userId,\n };\n } else if (isSerializedGroupMentionNode(node)) {\n return {\n kind: \"group\",\n id: node.attributes.__groupId,\n userIds: node.attributes.__userIds,\n };\n }\n\n assertNever(node, \"Unknown mention kind\");\n}\n","/**\n * Utility module to work with key-value stores.\n *\n * @module map\n */\n\n/**\n * Creates a new Map instance.\n *\n * @function\n * @return {Map<any, any>}\n *\n * @function\n */\nexport const create = () => new Map()\n\n/**\n * Copy a Map object into a fresh Map object.\n *\n * @function\n * @template K,V\n * @param {Map<K,V>} m\n * @return {Map<K,V>}\n */\nexport const copy = m => {\n const r = create()\n m.forEach((v, k) => { r.set(k, v) })\n return r\n}\n\n/**\n * Get map property. Create T if property is undefined and set T on map.\n *\n * ```js\n * const listeners = map.setIfUndefined(events, 'eventName', set.create)\n * listeners.add(listener)\n * ```\n *\n * @function\n * @template {Map<any, any>} MAP\n * @template {MAP extends Map<any,infer V> ? function():V : unknown} CF\n * @param {MAP} map\n * @param {MAP extends Map<infer K,any> ? K : unknown} key\n * @param {CF} createT\n * @return {ReturnType<CF>}\n */\nexport const setIfUndefined = (map, key, createT) => {\n let set = map.get(key)\n if (set === undefined) {\n map.set(key, set = createT())\n }\n return set\n}\n\n/**\n * Creates an Array and populates it with the content of all key-value pairs using the `f(value, key)` function.\n *\n * @function\n * @template K\n * @template V\n * @template R\n * @param {Map<K,V>} m\n * @param {function(V,K):R} f\n * @return {Array<R>}\n */\nexport const map = (m, f) => {\n const res = []\n for (const [key, value] of m) {\n res.push(f(value, key))\n }\n return res\n}\n\n/**\n * Tests whether any key-value pairs pass the test implemented by `f(value, key)`.\n *\n * @todo should rename to some - similarly to Array.some\n *\n * @function\n * @template K\n * @template V\n * @param {Map<K,V>} m\n * @param {function(V,K):boolean} f\n * @return {boolean}\n */\nexport const any = (m, f) => {\n for (const [key, value] of m) {\n if (f(value, key)) {\n return true\n }\n }\n return false\n}\n\n/**\n * Tests whether all key-value pairs pass the test implemented by `f(value, key)`.\n *\n * @function\n * @template K\n * @template V\n * @param {Map<K,V>} m\n * @param {function(V,K):boolean} f\n * @return {boolean}\n */\nexport const all = (m, f) => {\n for (const [key, value] of m) {\n if (!f(value, key)) {\n return false\n }\n }\n return true\n}\n","/**\n * Utility module to work with sets.\n *\n * @module set\n */\n\nexport const create = () => new Set()\n\n/**\n * @template T\n * @param {Set<T>} set\n * @return {Array<T>}\n */\nexport const toArray = set => Array.from(set)\n\n/**\n * @template T\n * @param {Set<T>} set\n * @return {T|undefined}\n */\nexport const first = set => set.values().next().value\n\n/**\n * @template T\n * @param {Iterable<T>} entries\n * @return {Set<T>}\n */\nexport const from = entries => new Set(entries)\n","/**\n * Utility module to work with Arrays.\n *\n * @module array\n */\n\nimport * as set from './set.js'\n\n/**\n * Return the last element of an array. The element must exist\n *\n * @template L\n * @param {ArrayLike<L>} arr\n * @return {L}\n */\nexport const last = arr => arr[arr.length - 1]\n\n/**\n * @template C\n * @return {Array<C>}\n */\nexport const create = () => /** @type {Array<C>} */ ([])\n\n/**\n * @template D\n * @param {Array<D>} a\n * @return {Array<D>}\n */\nexport const copy = a => /** @type {Array<D>} */ (a.slice())\n\n/**\n * Append elements from src to dest\n *\n * @template M\n * @param {Array<M>} dest\n * @param {Array<M>} src\n */\nexport const appendTo = (dest, src) => {\n for (let i = 0; i < src.length; i++) {\n dest.push(src[i])\n }\n}\n\n/**\n * Transforms something array-like to an actual Array.\n *\n * @function\n * @template T\n * @param {ArrayLike<T>|Iterable<T>} arraylike\n * @return {T}\n */\nexport const from = Array.from\n\n/**\n * True iff condition holds on every element in the Array.\n *\n * @function\n * @template {ArrayLike<any>} ARR\n *\n * @param {ARR} arr\n * @param {ARR extends ArrayLike<infer S> ? ((value:S, index:number, arr:ARR) => boolean) : any} f\n * @return {boolean}\n */\nexport const every = (arr, f) => {\n for (let i = 0; i < arr.length; i++) {\n if (!f(arr[i], i, arr)) {\n return false\n }\n }\n return true\n}\n\n/**\n * True iff condition holds on some element in the Array.\n *\n * @function\n * @template {ArrayLike<any>} ARR\n *\n * @param {ARR} arr\n * @param {ARR extends ArrayLike<infer S> ? ((value:S, index:number, arr:ARR) => boolean) : never} f\n * @return {boolean}\n */\nexport const some = (arr, f) => {\n for (let i = 0; i < arr.length; i++) {\n if (f(arr[i], i, arr)) {\n return true\n }\n }\n return false\n}\n\n/**\n * @template ELEM\n *\n * @param {ArrayLike<ELEM>} a\n * @param {ArrayLike<ELEM>} b\n * @return {boolean}\n */\nexport const equalFlat = (a, b) => a.length === b.length && every(a, (item, index) => item === b[index])\n\n/**\n * @template ELEM\n * @param {Array<Array<ELEM>>} arr\n * @return {Array<ELEM>}\n */\nexport const flatten = arr => fold(arr, /** @type {Array<ELEM>} */ ([]), (acc, val) => acc.concat(val))\n\n/**\n * @template T\n * @param {number} len\n * @param {function(number, Array<T>):T} f\n * @return {Array<T>}\n */\nexport const unfold = (len, f) => {\n const array = new Array(len)\n for (let i = 0; i < len; i++) {\n array[i] = f(i, array)\n }\n return array\n}\n\n/**\n * @template T\n * @template RESULT\n * @param {Array<T>} arr\n * @param {RESULT} seed\n * @param {function(RESULT, T, number):RESULT} folder\n */\nexport const fold = (arr, seed, folder) => arr.reduce(folder, seed)\n\nexport const isArray = Array.isArray\n\n/**\n * @template T\n * @param {Array<T>} arr\n * @return {Array<T>}\n */\nexport const unique = arr => from(set.from(arr))\n\n/**\n * @template T\n * @template M\n * @param {ArrayLike<T>} arr\n * @param {function(T):M} mapper\n * @return {Array<T>}\n */\nexport const uniqueBy = (arr, mapper) => {\n /**\n * @type {Set<M>}\n */\n const happened = set.create()\n /**\n * @type {Array<T>}\n */\n const result = []\n for (let i = 0; i < arr.length; i++) {\n const el = arr[i]\n const mapped = mapper(el)\n if (!happened.has(mapped)) {\n happened.add(mapped)\n result.push(el)\n }\n }\n return result\n}\n\n/**\n * @template {ArrayLike<any>} ARR\n * @template {function(ARR extends ArrayLike<infer T> ? T : never, number, ARR):any} MAPPER\n * @param {ARR} arr\n * @param {MAPPER} mapper\n * @return {Array<MAPPER extends function(...any): infer M ? M : never>}\n */\nexport const map = (arr, mapper) => {\n /**\n * @type {Array<any>}\n */\n const res = Array(arr.length)\n for (let i = 0; i < arr.length; i++) {\n res[i] = mapper(/** @type {any} */ (arr[i]), i, /** @type {any} */ (arr))\n }\n return /** @type {any} */ (res)\n}\n\n/**\n * This function bubble-sorts a single item to the correct position. The sort happens in-place and\n * might be useful to ensure that a single item is at the correct position in an otherwise sorted\n * array.\n *\n * @example\n * const arr = [3, 2, 5]\n * arr.sort((a, b) => a - b)\n * arr // => [2, 3, 5]\n * arr.splice(1, 0, 7)\n * array.bubbleSortItem(arr, 1, (a, b) => a - b)\n * arr // => [2, 3, 5, 7]\n *\n * @template T\n * @param {Array<T>} arr\n * @param {number} i\n * @param {(a:T,b:T) => number} compareFn\n */\nexport const bubblesortItem = (arr, i, compareFn) => {\n const n = arr[i]\n let j = i\n // try to sort to the right\n while (j + 1 < arr.length && compareFn(n, arr[j + 1]) > 0) {\n arr[j] = arr[j + 1]\n arr[++j] = n\n }\n if (i === j && j > 0) { // no change yet\n // sort to the left\n while (j > 0 && compareFn(arr[j - 1], n) > 0) {\n arr[j] = arr[j - 1]\n arr[--j] = n\n }\n }\n return j\n}\n","/**\n * Observable class prototype.\n *\n * @module observable\n */\n\nimport * as map from './map.js'\nimport * as set from './set.js'\nimport * as array from './array.js'\n\n/**\n * Handles named events.\n * @experimental\n *\n * This is basically a (better typed) duplicate of Observable, which will replace Observable in the\n * next release.\n *\n * @template {{[key in keyof EVENTS]: function(...any):void}} EVENTS\n */\nexport class ObservableV2 {\n constructor () {\n /**\n * Some desc.\n * @type {Map<string, Set<any>>}\n */\n this._observers = map.create()\n }\n\n /**\n * @template {keyof EVENTS & string} NAME\n * @param {NAME} name\n * @param {EVENTS[NAME]} f\n */\n on (name, f) {\n map.setIfUndefined(this._observers, /** @type {string} */ (name), set.create).add(f)\n return f\n }\n\n /**\n * @template {keyof EVENTS & string} NAME\n * @param {NAME} name\n * @param {EVENTS[NAME]} f\n */\n once (name, f) {\n /**\n * @param {...any} args\n */\n const _f = (...args) => {\n this.off(name, /** @type {any} */ (_f))\n f(...args)\n }\n this.on(name, /** @type {any} */ (_f))\n }\n\n /**\n * @template {keyof EVENTS & string} NAME\n * @param {NAME} name\n * @param {EVENTS[NAME]} f\n */\n off (name, f) {\n const observers = this._observers.get(name)\n if (observers !== undefined) {\n observers.delete(f)\n if (observers.size === 0) {\n this._observers.delete(name)\n }\n }\n }\n\n /**\n * Emit a named event. All registered event listeners that listen to the\n * specified name will receive the event.\n *\n * @todo This should catch exceptions\n *\n * @template {keyof EVENTS & string} NAME\n * @param {NAME} name The event name.\n * @param {Parameters<EVENTS[NAME]>} args The arguments that are applied to the event listener.\n */\n emit (name, args) {\n // copy all listeners to an array first to make sure that no event is emitted to listeners that are subscribed while the event handler is called.\n return array.from((this._observers.get(name) || map.create()).values()).forEach(f => f(...args))\n }\n\n destroy () {\n this._observers = map.create()\n }\n}\n\n/* c8 ignore start */\n/**\n * Handles named events.\n *\n * @deprecated\n * @template N\n */\nexport class Observable {\n constructor () {\n /**\n * Some desc.\n * @type {Map<N, any>}\n */\n this._observers = map.create()\n }\n\n /**\n * @param {N} name\n * @param {function} f\n */\n on (name, f) {\n map.setIfUndefined(this._observers, name, set.create).add(f)\n }\n\n /**\n * @param {N} name\n * @param {function} f\n */\n once (name, f) {\n /**\n * @param {...any} args\n */\n const _f = (...args) => {\n this.off(name, _f)\n f(...args)\n }\n this.on(name, _f)\n }\n\n /**\n * @param {N} name\n * @param {function} f\n */\n off (name, f) {\n const observers = this._observers.get(name)\n if (observers !== undefined) {\n observers.delete(f)\n if (observers.size === 0) {\n this._observers.delete(name)\n }\n }\n }\n\n /**\n * Emit a named event. All registered event listeners that listen to the\n * specified name will receive the event.\n *\n * @todo This should catch exceptions\n *\n * @param {N} name The event name.\n * @param {Array<any>} args The arguments that are applied to the event listener.\n */\n emit (name, args) {\n // copy all listeners to an array first to make sure that no event is emitted to listeners that are subscribed while the event handler is called.\n return array.from((this._observers.get(name) || map.create()).values()).forEach(f => f(...args))\n }\n\n destroy () {\n this._observers = map.create()\n }\n}\n/* c8 ignore end */\n","/**\n * Common Math expressions.\n *\n * @module math\n */\n\nexport const floor = Math.floor\nexport const ceil = Math.ceil\nexport const abs = Math.abs\nexport const imul = Math.imul\nexport const round = Math.round\nexport const log10 = Math.log10\nexport const log2 = Math.log2\nexport const log = Math.log\nexport const sqrt = Math.sqrt\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The sum of a and b\n */\nexport const add = (a, b) => a + b\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The smaller element of a and b\n */\nexport const min = (a, b) => a < b ? a : b\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The bigger element of a and b\n */\nexport const max = (a, b) => a > b ? a : b\n\nexport const isNaN = Number.isNaN\n\nexport const pow = Math.pow\n/**\n * Base 10 exponential function. Returns the value of 10 raised to the power of pow.\n *\n * @param {number} exp\n * @return {number}\n */\nexport const exp10 = exp => Math.pow(10, exp)\n\nexport const sign = Math.sign\n\n/**\n * @param {number} n\n * @return {boolean} Wether n is negative. This function also differentiates between -0 and +0\n */\nexport const isNegativeZero = n => n !== 0 ? n < 0 : 1 / n < 0\n","/* eslint-env browser */\n\n/**\n * Binary data constants.\n *\n * @module binary\n */\n\n/**\n * n-th bit activated.\n *\n * @type {number}\n */\nexport const BIT1 = 1\nexport const BIT2 = 2\nexport const BIT3 = 4\nexport const BIT4 = 8\nexport const BIT5 = 16\nexport const BIT6 = 32\nexport const BIT7 = 64\nexport const BIT8 = 128\nexport const BIT9 = 256\nexport const BIT10 = 512\nexport const BIT11 = 1024\nexport const BIT12 = 2048\nexport const BIT13 = 4096\nexport const BIT14 = 8192\nexport const BIT15 = 16384\nexport const BIT16 = 32768\nexport const BIT17 = 65536\nexport const BIT18 = 1 << 17\nexport const BIT19 = 1 << 18\nexport const BIT20 = 1 << 19\nexport const BIT21 = 1 << 20\nexport const BIT22 = 1 << 21\nexport const BIT23 = 1 << 22\nexport const BIT24 = 1 << 23\nexport const BIT25 = 1 << 24\nexport const BIT26 = 1 << 25\nexport const BIT27 = 1 << 26\nexport const BIT28 = 1 << 27\nexport const BIT29 = 1 << 28\nexport const BIT30 = 1 << 29\nexport const BIT31 = 1 << 30\nexport const BIT32 = 1 << 31\n\n/**\n * First n bits activated.\n *\n * @type {number}\n */\nexport const BITS0 = 0\nexport const BITS1 = 1\nexport const BITS2 = 3\nexport const BITS3 = 7\nexport const BITS4 = 15\nexport const BITS5 = 31\nexport const BITS6 = 63\nexport const BITS7 = 127\nexport const BITS8 = 255\nexport const BITS9 = 511\nexport const BITS10 = 1023\nexport const BITS11 = 2047\nexport const BITS12 = 4095\nexport const BITS13 = 8191\nexport const BITS14 = 16383\nexport const BITS15 = 32767\nexport const BITS16 = 65535\nexport const BITS17 = BIT18 - 1\nexport const BITS18 = BIT19 - 1\nexport const BITS19 = BIT20 - 1\nexport const BITS20 = BIT21 - 1\nexport const BITS21 = BIT22 - 1\nexport const BITS22 = BIT23 - 1\nexport const BITS23 = BIT24 - 1\nexport const BITS24 = BIT25 - 1\nexport const BITS25 = BIT26 - 1\nexport const BITS26 = BIT27 - 1\nexport const BITS27 = BIT28 - 1\nexport const BITS28 = BIT29 - 1\nexport const BITS29 = BIT30 - 1\nexport const BITS30 = BIT31 - 1\n/**\n * @type {number}\n */\nexport const BITS31 = 0x7FFFFFFF\n/**\n * @type {number}\n */\nexport const BITS32 = 0xFFFFFFFF\n","/**\n * Utility helpers for working with numbers.\n *\n * @module number\n */\n\nimport * as math from './math.js'\nimport * as binary from './binary.js'\n\nexport const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER\nexport const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER\n\nexport const LOWEST_INT32 = 1 << 31\nexport const HIGHEST_INT32 = binary.BITS31\nexport const HIGHEST_UINT32 = binary.BITS32\n\n/* c8 ignore next */\nexport const isInteger = Number.isInteger || (num => typeof num === 'number' && isFinite(num) && math.floor(num) === num)\nexport const isNaN = Number.isNaN\nexport const parseInt = Number.parseInt\n\n/**\n * Count the number of \"1\" bits in an unsigned 32bit number.\n *\n * Super fun bitcount algorithm by Brian Kernighan.\n *\n * @param {number} n\n */\nexport const countBits = n => {\n n &= binary.BITS32\n let count = 0\n while (n) {\n n &= (n - 1)\n count++\n }\n return count\n}\n","import * as array from './array.js'\n\n/**\n * Utility module to work with strings.\n *\n * @module string\n */\n\nexport const fromCharCode = String.fromCharCode\nexport const fromCodePoint = String.fromCodePoint\n\n/**\n * The largest utf16 character.\n * Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)\n */\nexport const MAX_UTF16_CHARACTER = fromCharCode(65535)\n\n/**\n * @param {string} s\n * @return {string}\n */\nconst toLowerCase = s => s.toLowerCase()\n\nconst trimLeftRegex = /^\\s*/g\n\n/**\n * @param {string} s\n * @return {string}\n */\nexport const trimLeft = s => s.replace(trimLeftRegex, '')\n\nconst fromCamelCaseRegex = /([A-Z])/g\n\n/**\n * @param {string} s\n * @param {string} separator\n * @return {string}\n */\nexport const fromCamelCase = (s, separator) => trimLeft(s.replace(fromCamelCaseRegex, match => `${separator}${toLowerCase(match)}`))\n\n/**\n * Compute the utf8ByteLength\n * @param {string} str\n * @return {number}\n */\nexport const utf8ByteLength = str => unescape(encodeURIComponent(str)).length\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\nexport const _encodeUtf8Polyfill = str => {\n const encodedString = unescape(encodeURIComponent(str))\n const len = encodedString.length\n const buf = new Uint8Array(len)\n for (let i = 0; i < len; i++) {\n buf[i] = /** @type {number} */ (encodedString.codePointAt(i))\n }\n return buf\n}\n\n/* c8 ignore next */\nexport const utf8TextEncoder = /** @type {TextEncoder} */ (typeof TextEncoder !== 'undefined' ? new TextEncoder() : null)\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\nexport const _encodeUtf8Native = str => utf8TextEncoder.encode(str)\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\n/* c8 ignore next */\nexport const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\nexport const _decodeUtf8Polyfill = buf => {\n let remainingLen = buf.length\n let encodedString = ''\n let bufPos = 0\n while (remainingLen > 0) {\n const nextLen = remainingLen < 10000 ? remainingLen : 10000\n const bytes = buf.subarray(bufPos, bufPos + nextLen)\n bufPos += nextLen\n // Starting with ES5.1 we can supply a generic array-like object as arguments\n encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes))\n remainingLen -= nextLen\n }\n return decodeURIComponent(escape(encodedString))\n}\n\n/* c8 ignore next */\nexport let utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })\n\n/* c8 ignore start */\nif (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {\n // Safari doesn't handle BOM correctly.\n // This fixes a bug in Safari 13.0.5 where it produces a BOM the first time it is called.\n // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the first call and\n // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the second call\n // Another issue is that from then on no BOM chars are recognized anymore\n /* c8 ignore next */\n utf8TextDecoder = null\n}\n/* c8 ignore stop */\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\nexport const _decodeUtf8Native = buf => /** @type {TextDecoder} */ (utf8TextDecoder).decode(buf)\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\n/* c8 ignore next */\nexport const decodeUtf8 = utf8TextDecoder ? _decodeUtf8Native : _decodeUtf8Polyfill\n\n/**\n * @param {string} str The initial string\n * @param {number} index Starting position\n * @param {number} remove Number of characters to remove\n * @param {string} insert New content to insert\n */\nexport const splice = (str, index, remove, insert = '') => str.slice(0, index) + insert + str.slice(index + remove)\n\n/**\n * @param {string} source\n * @param {number} n\n */\nexport const repeat = (source, n) => array.unfold(n, () => source).join('')\n\n/**\n * Escape HTML characters &,<,>,',\" to their respective HTML entities &,<,>,',"\n *\n * @param {string} str\n */\nexport const escapeHTML = str =>\n str.replace(/[&<>'\"]/g, r => /** @type {string} */ ({\n '&': '&',\n '<': '<',\n '>': '>',\n \"'\": ''',\n '\"': '"'\n }[r]))\n\n/**\n * Reverse of `escapeHTML`\n *\n * @param {string} str\n */\nexport const unescapeHTML = str =>\n str.replace(/&|<|>|'|"/g, r => /** @type {string} */ ({\n '&': '&',\n '<': '<',\n '>': '>',\n ''': \"'\",\n '"': '\"'\n }[r]))\n","/**\n * Efficient schema-less binary encoding with support for variable length encoding.\n *\n * Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function.\n *\n * Encodes numbers in little-endian order (least to most significant byte order)\n * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)\n * which is also used in Protocol Buffers.\n *\n * ```js\n * // encoding step\n * const encoder = encoding.createEncoder()\n * encoding.writeVarUint(encoder, 256)\n * encoding.writeVarString(encoder, 'Hello world!')\n * const buf = encoding.toUint8Array(encoder)\n * ```\n *\n * ```js\n * // decoding step\n * const decoder = decoding.createDecoder(buf)\n * decoding.readVarUint(decoder) // => 256\n * decoding.readVarString(decoder) // => 'Hello world!'\n * decoding.hasContent(decoder) // => false - all data is read\n * ```\n *\n * @module encoding\n */\n\nimport * as math from './math.js'\nimport * as number from './number.js'\nimport * as binary from './binary.js'\nimport * as string from './string.js'\nimport * as array from './array.js'\n\n/**\n * A BinaryEncoder handles the encoding to an Uint8Array.\n */\nexport class Encoder {\n constructor () {\n this.cpos = 0\n this.cbuf = new Uint8Array(100)\n /**\n * @type {Array<Uint8Array>}\n */\n this.bufs = []\n }\n}\n\n/**\n * @function\n * @return {Encoder}\n */\nexport const createEncoder = () => new Encoder()\n\n/**\n * @param {function(Encoder):void} f\n */\nexport const encode = (f) => {\n const encoder = createEncoder()\n f(encoder)\n return toUint8Array(encoder)\n}\n\n/**\n * The current length of the encoded data.\n *\n * @function\n * @param {Encoder} encoder\n * @return {number}\n */\nexport const length = encoder => {\n let len = encoder.cpos\n for (let i = 0; i < encoder.bufs.length; i++) {\n len += encoder.bufs[i].length\n }\n return len\n}\n\n/**\n * Check whether encoder is empty.\n *\n * @function\n * @param {Encoder} encoder\n * @return {boolean}\n */\nexport const hasContent = encoder => encoder.cpos > 0 || encoder.bufs.length > 0\n\n/**\n * Transform to Uint8Array.\n *\n * @function\n * @param {Encoder} encoder\n * @return {Uint8Array} The created ArrayBuffer.\n */\nexport const toUint8Array = encoder => {\n const uint8arr = new Uint8Array(length(encoder))\n let curPos = 0\n for (let i = 0; i < encoder.bufs.length; i++) {\n const d = encoder.bufs[i]\n uint8arr.set(d, curPos)\n curPos += d.length\n }\n uint8arr.set(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos), curPos)\n return uint8arr\n}\n\n/**\n * Verify that it is possible to write `len` bytes wtihout checking. If\n * necessary, a new Buffer with the required length is attached.\n *\n * @param {Encoder} encoder\n * @param {number} len\n */\nexport const verifyLen = (encoder, len) => {\n const bufferLen = encoder.cbuf.length\n if (bufferLen - encoder.cpos < len) {\n encoder.bufs.push(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos))\n encoder.cbuf = new Uint8Array(math.max(bufferLen, len) * 2)\n encoder.cpos = 0\n }\n}\n\n/**\n * Write one byte to the encoder.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The byte that is to be encoded.\n */\nexport const write = (encoder, num) => {\n const bufferLen = encoder.cbuf.length\n if (encoder.cpos === bufferLen) {\n encoder.bufs.push(encoder.cbuf)\n encoder.cbuf = new Uint8Array(bufferLen * 2)\n encoder.cpos = 0\n }\n encoder.cbuf[encoder.cpos++] = num\n}\n\n/**\n * Write one byte at a specific position.\n * Position must already be written (i.e. encoder.length > pos)\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos Position to which to write data\n * @param {number} num Unsigned 8-bit integer\n */\nexport const set = (encoder, pos, num) => {\n let buffer = null\n // iterate all buffers and adjust position\n for (let i = 0; i < encoder.bufs.length && buffer === null; i++) {\n const b = encoder.bufs[i]\n if (pos < b.length) {\n buffer = b // found buffer\n } else {\n pos -= b.length\n }\n }\n if (buffer === null) {\n // use current buffer\n buffer = encoder.cbuf\n }\n buffer[pos] = num\n}\n\n/**\n * Write one byte as an unsigned integer.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint8 = write\n\n/**\n * Write one byte as an unsigned Integer at a specific location.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos The location where the data will be written.\n * @param {number} num The number that is to be encoded.\n */\nexport const setUint8 = set\n\n/**\n * Write two bytes as an unsigned integer.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint16 = (encoder, num) => {\n write(encoder, num & binary.BITS8)\n write(encoder, (num >>> 8) & binary.BITS8)\n}\n/**\n * Write two bytes as an unsigned integer at a specific location.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos The location where the data will be written.\n * @param {number} num The number that is to be encoded.\n */\nexport const setUint16 = (encoder, pos, num) => {\n set(encoder, pos, num & binary.BITS8)\n set(encoder, pos + 1, (num >>> 8) & binary.BITS8)\n}\n\n/**\n * Write two bytes as an unsigned integer\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint32 = (encoder, num) => {\n for (let i = 0; i < 4; i++) {\n write(encoder, num & binary.BITS8)\n num >>>= 8\n }\n}\n\n/**\n * Write two bytes as an unsigned integer in big endian order.\n * (most significant byte first)\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint32BigEndian = (encoder, num) => {\n for (let i = 3; i >= 0; i--) {\n write(encoder, (num >>> (8 * i)) & binary.BITS8)\n }\n}\n\n/**\n * Write two bytes as an unsigned integer at a specific location.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos The location where the data will be written.\n * @param {number} num The number that is to be encoded.\n */\nexport const setUint32 = (encoder, pos, num) => {\n for (let i = 0; i < 4; i++) {\n set(encoder, pos + i, num & binary.BITS8)\n num >>>= 8\n }\n}\n\n/**\n * Write a variable length unsigned integer. Max encodable integer is 2^53.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeVarUint = (encoder, num) => {\n while (num > binary.BITS7) {\n write(encoder, binary.BIT8 | (binary.BITS7 & num))\n num = math.floor(num / 128) // shift >>> 7\n }\n write(encoder, binary.BITS7 & num)\n}\n\n/**\n * Write a variable length integer.\n *\n * We use the 7th bit instead for signaling that this is a negative number.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeVarInt = (encoder, num) => {\n const isNegative = math.isNegativeZero(num)\n if (isNegative) {\n num = -num\n }\n // |- whether to continue reading |- whether is negative |- number\n write(encoder, (num > binary.BITS6 ? binary.BIT8 : 0) | (isNegative ? binary.BIT7 : 0) | (binary.BITS6 & num))\n num = math.floor(num / 64) // shift >>> 6\n // We don't need to consider the case of num === 0 so we can use a different\n // pattern here than above.\n while (num > 0) {\n write(encoder, (num > binary.BITS7 ? binary.BIT8 : 0) | (binary.BITS7 & num))\n num = math.floor(num / 128) // shift >>> 7\n }\n}\n\n/**\n * A cache to store strings temporarily\n */\nconst _strBuffer = new Uint8Array(30000)\nconst _maxStrBSize = _strBuffer.length / 3\n\n/**\n * Write a variable length string.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\nexport const _writeVarStringNative = (encoder, str) => {\n if (str.length < _maxStrBSize) {\n // We can encode the string into the existing buffer\n /* c8 ignore next */\n const written = string.utf8TextEncoder.encodeInto(str, _strBuffer).written || 0\n writeVarUint(encoder, written)\n for (let i = 0; i < written; i++) {\n write(encoder, _strBuffer[i])\n }\n } else {\n writeVarUint8Array(encoder, string.encodeUtf8(str))\n }\n}\n\n/**\n * Write a variable length string.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\nexport const _writeVarStringPolyfill = (encoder, str) => {\n const encodedString = unescape(encodeURIComponent(str))\n const len = encodedString.length\n writeVarUint(encoder, len)\n for (let i = 0; i < len; i++) {\n write(encoder, /** @type {number} */ (encodedString.codePointAt(i)))\n }\n}\n\n/**\n * Write a variable length string.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\n/* c8 ignore next */\nexport const writeVarString = (string.utf8TextEncoder && /** @type {any} */ (string.utf8TextEncoder).encodeInto) ? _writeVarStringNative : _writeVarStringPolyfill\n\n/**\n * Write a string terminated by a special byte sequence. This is not very performant and is\n * generally discouraged. However, the resulting byte arrays are lexiographically ordered which\n * makes this a nice feature for databases.\n *\n * The string will be encoded using utf8 and then terminated and escaped using writeTerminatingUint8Array.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\nexport const writeTerminatedString = (encoder, str) =>\n writeTerminatedUint8Array(encoder, string.encodeUtf8(str))\n\n/**\n * Write a terminating Uint8Array. Note that this is not performant and is generally\n * discouraged. There are few situations when this is needed.\n *\n * We use 0x0 as a terminating character. 0x1 serves as an escape character for 0x0 and 0x1.\n *\n * Example: [0,1,2] is encoded to [1,0,1,1,2,0]. 0x0, and 0x1 needed to be escaped using 0x1. Then\n * the result is terminated using the 0x0 character.\n *\n * This is basically how many systems implement null terminated strings. However, we use an escape\n * character 0x1 to avoid issues and potenial attacks on our database (if this is used as a key\n * encoder for NoSql databases).\n *\n * @function\n * @param {Encoder} encoder\n * @param {Uint8Array} buf The string that is to be encoded.\n */\nexport const writeTerminatedUint8Array = (encoder, buf) => {\n for (let i = 0; i < buf.length; i++) {\n const b = buf[i]\n if (b === 0 || b === 1) {\n write(encoder, 1)\n }\n write(encoder, buf[i])\n }\n write(encoder, 0)\n}\n\n/**\n * Write the content of another Encoder.\n *\n * @TODO: can be improved!\n * - Note: Should consider that when appending a lot of small Encoders, we should rather clone than referencing the old structure.\n * Encoders start with a rather big initial buffer.\n *\n * @function\n * @param {Encoder} encoder The enUint8Arr\n * @param {Encoder} append The BinaryEncoder to be written.\n */\nexport const writeBinaryEncoder = (encoder, append) => writeUint8Array(encoder, toUint8Array(append))\n\n/**\n * Append fixed-length Uint8Array to the encoder.\n *\n * @function\n * @param {Encoder} encoder\n * @param {Uint8Array} uint8Array\n */\nexport const writeUint8Array = (encoder, uint8Array) => {\n const bufferLen = encoder.cbuf.length\n const cpos = encoder.cpos\n const leftCopyLen = math.min(bufferLen - cpos, uint8Array.length)\n const rightCopyLen = uint8Array.length - leftCopyLen\n encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos)\n encoder.cpos += leftCopyLen\n if (rightCopyLen > 0) {\n // Still something to write, write right half..\n // Append new buffer\n encoder.bufs.push(encoder.cbuf)\n // must have at least size of remaining buffer\n encoder.cbuf = new Uint8Array(math.max(bufferLen * 2, rightCopyLen))\n // copy array\n encoder.cbuf.set(uint8Array.subarray(leftCopyLen))\n encoder.cpos = rightCopyLen\n }\n}\n\n/**\n * Append an Uint8Array to Encoder.\n *\n * @function\n * @param {Encoder} encoder\n * @param {Uint8Array} uint8Array\n */\nexport const writeVarUint8Array = (encoder, uint8Array) => {\n writeVarUint(encoder, uint8Array.byteLength)\n writeUint8Array(encoder, uint8Array)\n}\n\n/**\n * Create an DataView of the next `len` bytes. Use it to write data after\n * calling this function.\n *\n * ```js\n * // write float32 using DataView\n * const dv = writeOnDataView(encoder, 4)\n * dv.setFloat32(0, 1.1)\n * // read float32 using DataView\n * const dv = readFromDataView(encoder, 4)\n * dv.getFloat32(0) // => 1.100000023841858 (leaving it to the reader to find out why this is the correct result)\n * ```\n *\n * @param {Encoder} encoder\n * @param {number} len\n * @return {DataView}\n */\nexport const writeOnDataView = (encoder, len) => {\n verifyLen(encoder, len)\n const dview = new DataView(encoder.cbuf.buffer, encoder.cpos, len)\n encoder.cpos += len\n return dview\n}\n\n/**\n * @param {Encoder} encoder\n * @param {number} num\n */\nexport const writeFloat32 = (encoder, num) => writeOnDataView(encoder, 4).setFloat32(0, num, false)\n\n/**\n * @param {Encoder} encoder\n * @param {number} num\n */\nexport const writeFloat64 = (encoder, num) => writeOnDataView(encoder, 8).setFloat64(0, num, false)\n\n/**\n * @param {Encoder} encoder\n * @param {bigint} num\n */\nexport const writeBigInt64 = (encoder, num) => /** @type {any} */ (writeOnDataView(encoder, 8)).setBigInt64(0, num, false)\n\n/**\n * @param {Encoder} encoder\n * @param {bigint} num\n */\nexport const writeBigUint64 = (encoder, num) => /** @type {any} */ (writeOnDataView(encoder, 8)).setBigUint64(0, num, false)\n\nconst floatTestBed = new DataView(new ArrayBuffer(4))\n/**\n * Check if a number can be encoded as a 32 bit float.\n *\n * @param {number} num\n * @return {boolean}\n */\nconst isFloat32 = num => {\n floatTestBed.setFloat32(0, num)\n return floatTestBed.getFloat32(0) === num\n}\n\n/**\n * Encode data with efficient binary format.\n *\n * Differences to JSON:\n * • Transforms data to a binary format (not to a string)\n * • Encodes undefined, NaN, and ArrayBuffer (these can't be represented in JSON)\n * • Numbers are efficiently encoded either as a variable length integer, as a\n * 32 bit float, as a 64 bit float, or as a 64 bit bigint.\n *\n * Encoding table:\n *\n * | Data Type | Prefix | Encoding Method | Comment |\n * | ------------------- | -------- | ------------------ | ------- |\n * | undefined | 127 | | Functions, symbol, and everything that cannot be identified is encoded as undefined |\n * | null | 126 | | |\n * | integer | 125 | writeVarInt | Only encodes 32 bit signed integers |\n * | float32 | 124 | writeFloat32 | |\n * | float64 | 123 | writeFloat64 | |\n * | bigint | 122 | writeBigInt64 | |\n * | boolean (false) | 121 | | True and false are different data types so we save the following byte |\n * | boolean (true) | 120 | | - 0b01111000 so the last bit determines whether true or false |\n * | string | 119 | writeVarString | |\n * | object<string,any> | 118 | custom | Writes {length} then {length} key-value pairs |\n * | array<any> | 117 | custom | Writes {length} then {length} json values |\n * | Uint8Array | 116 | writeVarUint8Array | We use Uint8Array for any kind of binary data |\n *\n * Reasons for the decreasing prefix:\n * We need the first bit for extendability (later we may want to encode the\n * prefix with writeVarUint). The remaining 7 bits are divided as follows:\n * [0-30] the beginning of the data range is used for custom purposes\n * (defined by the function that uses this library)\n * [31-127] the end of the data range is used for data encoding by\n * lib0/encoding.js\n *\n * @param {Encoder} encoder\n * @param {undefined|null|number|bigint|boolean|string|Object<string,any>|Array<any>|Uint8Array} data\n */\nexport const writeAny = (encoder, data) => {\n switch (typeof data) {\n case 'string':\n // TYPE 119: STRING\n write(encoder, 119)\n writeVarString(encoder, data)\n break\n case 'number':\n if (number.isInteger(data) && math.abs(data) <= binary.BITS31) {\n // TYPE 125: INTEGER\n write(encoder, 125)\n writeVarInt(encoder, data)\n } else if (isFloat32(data)) {\n // TYPE 124: FLOAT32\n write(encoder, 124)\n writeFloat32(encoder, data)\n } else {\n // TYPE 123: FLOAT64\n write(encoder, 123)\n writeFloat64(encoder, data)\n }\n break\n case 'bigint':\n // TYPE 122: BigInt\n write(encoder, 122)\n writeBigInt64(encoder, data)\n break\n case 'object':\n if (data === null) {\n // TYPE 126: null\n write(encoder, 126)\n } else if (array.isArray(data)) {\n // TYPE 117: Array\n write(encoder, 117)\n writeVarUint(encoder, data.length)\n for (let i = 0; i < data.length; i++) {\n writeAny(encoder, data[i])\n }\n } else if (data instanceof Uint8Array) {\n // TYPE 116: ArrayBuffer\n write(encoder, 116)\n writeVarUint8Array(encoder, data)\n } else {\n // TYPE 118: Object\n write(encoder, 118)\n const keys = Object.keys(data)\n writeVarUint(encoder, keys.length)\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]\n writeVarString(encoder, key)\n writeAny(encoder, data[key])\n }\n }\n break\n case 'boolean':\n // TYPE 120/121: boolean (true/false)\n write(encoder, data ? 120 : 121)\n break\n default:\n // TYPE 127: undefined\n write(encoder, 127)\n }\n}\n\n/**\n * Now come a few stateful encoder that have their own classes.\n */\n\n/**\n * Basic Run Length Encoder - a basic compression implementation.\n *\n * Encodes [1,1,1,7] to [1,3,7,1] (3 times 1, 1 time 7). This encoder might do more harm than good if there are a lot of values that are not repeated.\n *\n * It was originally used for image compression. Cool .. article http://csbruce.com/cbm/transactor/pdfs/trans_v7_i06.pdf\n *\n * @note T must not be null!\n *\n * @template T\n */\nexport class RleEncoder extends Encoder {\n /**\n * @param {function(Encoder, T):void} writer\n */\n constructor (writer) {\n super()\n /**\n * The writer\n */\n this.w = writer\n /**\n * Current state\n * @type {T|null}\n */\n this.s = null\n this.count = 0\n }\n\n /**\n * @param {T} v\n */\n write (v) {\n if (this.s === v) {\n this.count++\n } else {\n if (this.count > 0) {\n // flush counter, unless this is the first value (count = 0)\n writeVarUint(this, this.count - 1) // since count is always > 0, we can decrement by one. non-standard encoding ftw\n }\n this.count = 1\n // write first value\n this.w(this, v)\n this.s = v\n }\n }\n}\n\n/**\n * Basic diff decoder using variable length encoding.\n *\n * Encodes the values [3, 1100, 1101, 1050, 0] to [3, 1097, 1, -51, -1050] using writeVarInt.\n */\nexport class IntDiffEncoder extends Encoder {\n /**\n * @param {number} start\n */\n constructor (start) {\n super()\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n writeVarInt(this, v - this.s)\n this.s = v\n }\n}\n\n/**\n * A combination of IntDiffEncoder and RleEncoder.\n *\n * Basically first writes the IntDiffEncoder and then counts duplicate diffs using RleEncoding.\n *\n * Encodes the values [1,1,1,2,3,4,5,6] as [1,1,0,2,1,5] (RLE([1,0,0,1,1,1,1,1]) ⇒ RleIntDiff[1,1,0,2,1,5])\n */\nexport class RleIntDiffEncoder extends Encoder {\n /**\n * @param {number} start\n */\n constructor (start) {\n super()\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n this.count = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.s === v && this.count > 0) {\n this.count++\n } else {\n if (this.count > 0) {\n // flush counter, unless this is the first value (count = 0)\n writeVarUint(this, this.count - 1) // since count is always > 0, we can decrement by one. non-standard encoding ftw\n }\n this.count = 1\n // write first value\n writeVarInt(this, v - this.s)\n this.s = v\n }\n }\n}\n\n/**\n * @param {UintOptRleEncoder} encoder\n */\nconst flushUintOptRleEncoder = encoder => {\n if (encoder.count > 0) {\n // flush counter, unless this is the first value (count = 0)\n // case 1: just a single value. set sign to positive\n // case 2: write several values. set sign to negative to indicate that there is a length coming\n writeVarInt(encoder.encoder, encoder.count === 1 ? encoder.s : -encoder.s)\n if (encoder.count > 1) {\n writeVarUint(encoder.encoder, encoder.count - 2) // since count is always > 1, we can decrement by one. non-standard encoding ftw\n }\n }\n}\n\n/**\n * Optimized Rle encoder that does not suffer from the mentioned problem of the basic Rle encoder.\n *\n * Internally uses VarInt encoder to write unsigned integers. If the input occurs multiple times, we write\n * write it as a negative number. The UintOptRleDecoder then understands that it needs to read a count.\n *\n * Encodes [1,2,3,3,3] as [1,2,-3,3] (once 1, once 2, three times 3)\n */\nexport class UintOptRleEncoder {\n constructor () {\n this.encoder = new Encoder()\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.s === v) {\n this.count++\n } else {\n flushUintOptRleEncoder(this)\n this.count = 1\n this.s = v\n }\n }\n\n /**\n * Flush the encoded state and transform this to a Uint8Array.\n *\n * Note that this should only be called once.\n */\n toUint8Array () {\n flushUintOptRleEncoder(this)\n return toUint8Array(this.encoder)\n }\n}\n\n/**\n * Increasing Uint Optimized RLE Encoder\n *\n * The RLE encoder counts the number of same occurences of the same value.\n * The IncUintOptRle encoder counts if the value increases.\n * I.e. 7, 8, 9, 10 will be encoded as [-7, 4]. 1, 3, 5 will be encoded\n * as [1, 3, 5].\n */\nexport class IncUintOptRleEncoder {\n constructor () {\n this.encoder = new Encoder()\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.s + this.count === v) {\n this.count++\n } else {\n flushUintOptRleEncoder(this)\n this.count = 1\n this.s = v\n }\n }\n\n /**\n * Flush the encoded state and transform this to a Uint8Array.\n *\n * Note that this should only be called once.\n */\n toUint8Array () {\n flushUintOptRleEncoder(this)\n return toUint8Array(this.encoder)\n }\n}\n\n/**\n * @param {IntDiffOptRleEncoder} encoder\n */\nconst flushIntDiffOptRleEncoder = encoder => {\n if (encoder.count > 0) {\n // 31 bit making up the diff | wether to write the counter\n // const encodedDiff = encoder.diff << 1 | (encoder.count === 1 ? 0 : 1)\n const encodedDiff = encoder.diff * 2 + (encoder.count === 1 ? 0 : 1)\n // flush counter, unless this is the first value (count = 0)\n // case 1: just a single value. set first bit to positive\n // case 2: write several values. set first bit to negative to indicate that there is a length coming\n writeVarInt(encoder.encoder, encodedDiff)\n if (encoder.count > 1) {\n writeVarUint(encoder.encoder, encoder.count - 2) // since count is always > 1, we can decrement by one. non-standard encoding ftw\n }\n }\n}\n\n/**\n * A combination of the IntDiffEncoder and the UintOptRleEncoder.\n *\n * The count approach is similar to the UintDiffOptRleEncoder, but instead of using the negative bitflag, it encodes\n * in the LSB whether a count is to be read. Therefore this Encoder only supports 31 bit integers!\n *\n * Encodes [1, 2, 3, 2] as [3, 1, 6, -1] (more specifically [(1 << 1) | 1, (3 << 0) | 0, -1])\n *\n * Internally uses variable length encoding. Contrary to normal UintVar encoding, the first byte contains:\n * * 1 bit that denotes whether the next value is a count (LSB)\n * * 1 bit that denotes whether this value is negative (MSB - 1)\n * * 1 bit that denotes whether to continue reading the variable length integer (MSB)\n *\n * Therefore, only five bits remain to encode diff ranges.\n *\n * Use this Encoder only when appropriate. In most cases, this is probably a bad idea.\n */\nexport class IntDiffOptRleEncoder {\n constructor () {\n this.encoder = new Encoder()\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n this.diff = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.diff === v - this.s) {\n this.s = v\n this.count++\n } else {\n flushIntDiffOptRleEncoder(this)\n this.count = 1\n this.diff = v - this.s\n this.s = v\n }\n }\n\n /**\n * Flush the encoded state and transform this to a Uint8Array.\n *\n * Note that this should only be called once.\n */\n toUint8Array () {\n flushIntDiffOptRleEncoder(this)\n return toUint8Array(this.encoder)\n }\n}\n\n/**\n * Optimized String Encoder.\n *\n * Encoding many small strings in a simple Encoder is not very efficient. The function call to decode a string takes some time and creates references that must be eventually deleted.\n * In practice, when decoding several million small strings, the GC will kick in more and more often to collect orphaned string objects (or maybe there is another reason?).\n *\n * This string encoder solves the above problem. All strings are concatenated and written as a single string using a single encoding call.\n *\n * The lengths are encoded using a UintOptRleEncoder.\n */\nexport class StringEncoder {\n constructor () {\n /**\n * @type {Array<string>}\n */\n this.sarr = []\n this.s = ''\n this.lensE = new UintOptRleEncoder()\n }\n\n /**\n * @param {string} string\n */\n write (string) {\n this.s += string\n if (this.s.length > 19) {\n this.sarr.push(this.s)\n this.s = ''\n }\n this.lensE.write(string.length)\n }\n\n toUint8Array () {\n const encoder = new Encoder()\n this.sarr.push(this.s)\n this.s = ''\n writeVarString(encoder, this.sarr.join(''))\n writeUint8Array(encoder, this.lensE.toUint8Array())\n return toUint8Array(encoder)\n }\n}\n","/**\n * Error helpers.\n *\n * @module error\n */\n\n/**\n * @param {string} s\n * @return {Error}\n */\n/* c8 ignore next */\nexport const create = s => new Error(s)\n\n/**\n * @throws {Error}\n * @return {never}\n */\n/* c8 ignore next 3 */\nexport const methodUnimplemented = () => {\n throw create('Method unimplemented')\n}\n\n/**\n * @throws {Error}\n * @return {never}\n */\n/* c8 ignore next 3 */\nexport const unexpectedCase = () => {\n throw create('Unexpected case')\n}\n","/**\n * Efficient schema-less binary decoding with support for variable length encoding.\n *\n * Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.\n *\n * Encodes numbers in little-endian order (least to most significant byte order)\n * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)\n * which is also used in Protocol Buffers.\n *\n * ```js\n * // encoding step\n * const encoder = encoding.createEncoder()\n * encoding.writeVarUint(encoder, 256)\n * encoding.writeVarString(encoder, 'Hello world!')\n * const buf = encoding.toUint8Array(encoder)\n * ```\n *\n * ```js\n * // decoding step\n * const decoder = decoding.createDecoder(buf)\n * decoding.readVarUint(decoder) // => 256\n * decoding.readVarString(decoder) // => 'Hello world!'\n * decoding.hasContent(decoder) // => false - all data is read\n * ```\n *\n * @module decoding\n */\n\nimport * as binary from './binary.js'\nimport * as math from './math.js'\nimport * as number from './number.js'\nimport * as string from './string.js'\nimport * as error from './error.js'\nimport * as encoding from './encoding.js'\n\nconst errorUnexpectedEndOfArray = error.create('Unexpected end of array')\nconst errorIntegerOutOfRange = error.create('Integer out of Range')\n\n/**\n * A Decoder handles the decoding of an Uint8Array.\n */\nexport class Decoder {\n /**\n * @param {Uint8Array} uint8Array Binary data to decode\n */\n constructor (uint8Array) {\n /**\n * Decoding target.\n *\n * @type {Uint8Array}\n */\n this.arr = uint8Array\n /**\n * Current decoding position.\n *\n * @type {number}\n */\n this.pos = 0\n }\n}\n\n/**\n * @function\n * @param {Uint8Array} uint8Array\n * @return {Decoder}\n */\nexport const createDecoder = uint8Array => new Decoder(uint8Array)\n\n/**\n * @function\n * @param {Decoder} decoder\n * @return {boolean}\n */\nexport const hasContent = decoder => decoder.pos !== decoder.arr.length\n\n/**\n * Clone a decoder instance.\n * Optionally set a new position parameter.\n *\n * @function\n * @param {Decoder} decoder The decoder instance\n * @param {number} [newPos] Defaults to current position\n * @return {Decoder} A clone of `decoder`\n */\nexport const clone = (decoder, newPos = decoder.pos) => {\n const _decoder = createDecoder(decoder.arr)\n _decoder.pos = newPos\n return _decoder\n}\n\n/**\n * Create an Uint8Array view of the next `len` bytes and advance the position by `len`.\n *\n * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.\n * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.\n *\n * @function\n * @param {Decoder} decoder The decoder instance\n * @param {number} len The length of bytes to read\n * @return {Uint8Array}\n */\nexport const readUint8Array = (decoder, len) => {\n const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len)\n decoder.pos += len\n return view\n}\n\n/**\n * Read variable length Uint8Array.\n *\n * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.\n * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.\n *\n * @function\n * @param {Decoder} decoder\n * @return {Uint8Array}\n */\nexport const readVarUint8Array = decoder => readUint8Array(decoder, readVarUint(decoder))\n\n/**\n * Read the rest of the content as an ArrayBuffer\n * @function\n * @param {Decoder} decoder\n * @return {Uint8Array}\n */\nexport const readTailAsUint8Array = decoder => readUint8Array(decoder, decoder.arr.length - decoder.pos)\n\n/**\n * Skip one byte, jump to the next position.\n * @function\n * @param {Decoder} decoder The decoder instance\n * @return {number} The next position\n */\nexport const skip8 = decoder => decoder.pos++\n\n/**\n * Read one byte as unsigned integer.\n * @function\n * @param {Decoder} decoder The decoder instance\n * @return {number} Unsigned 8-bit integer\n */\nexport const readUint8 = decoder => decoder.arr[decoder.pos++]\n\n/**\n * Read 2 bytes as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const readUint16 = decoder => {\n const uint =\n decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8)\n decoder.pos += 2\n return uint\n}\n\n/**\n * Read 4 bytes as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const readUint32 = decoder => {\n const uint =\n (decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8) +\n (decoder.arr[decoder.pos + 2] << 16) +\n (decoder.arr[decoder.pos + 3] << 24)) >>> 0\n decoder.pos += 4\n return uint\n}\n\n/**\n * Read 4 bytes as unsigned integer in big endian order.\n * (most significant byte first)\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const readUint32BigEndian = decoder => {\n const uint =\n (decoder.arr[decoder.pos + 3] +\n (decoder.arr[decoder.pos + 2] << 8) +\n (decoder.arr[decoder.pos + 1] << 16) +\n (decoder.arr[decoder.pos] << 24)) >>> 0\n decoder.pos += 4\n return uint\n}\n\n/**\n * Look ahead without incrementing the position\n * to the next byte and read it as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const peekUint8 = decoder => decoder.arr[decoder.pos]\n\n/**\n * Look ahead without incrementing the position\n * to the next byte and read it as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const peekUint16 = decoder =>\n decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8)\n\n/**\n * Look ahead without incrementing the position\n * to the next byte and read it as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const peekUint32 = decoder => (\n decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8) +\n (decoder.arr[decoder.pos + 2] << 16) +\n (decoder.arr[decoder.pos + 3] << 24)\n) >>> 0\n\n/**\n * Read unsigned integer (32bit) with variable length.\n * 1/8th of the storage is used as encoding overhead.\n * * numbers < 2^7 is stored in one bytlength\n * * numbers < 2^14 is stored in two bylength\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.length\n */\nexport const readVarUint = decoder => {\n let num = 0\n let mult = 1\n const len = decoder.arr.length\n while (decoder.pos < len) {\n const r = decoder.arr[decoder.pos++]\n // num = num | ((r & binary.BITS7) << len)\n num = num + (r & binary.BITS7) * mult // shift $r << (7*#iterations) and add it to num\n mult *= 128 // next iteration, shift 7 \"more\" to the left\n if (r < binary.BIT8) {\n return num\n }\n /* c8 ignore start */\n if (num > number.MAX_SAFE_INTEGER) {\n throw errorIntegerOutOfRange\n }\n /* c8 ignore stop */\n }\n throw errorUnexpectedEndOfArray\n}\n\n/**\n * Read signed integer (32bit) with variable length.\n * 1/8th of the storage is used as encoding overhead.\n * * numbers < 2^7 is stored in one bytlength\n * * numbers < 2^14 is stored in two bylength\n * @todo This should probably create the inverse ~num if number is negative - but this would be a breaking change.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.length\n */\nexport const readVarInt = decoder => {\n let r = decoder.arr[decoder.pos++]\n let num = r & binary.BITS6\n let mult = 64\n const sign = (r & binary.BIT7) > 0 ? -1 : 1\n if ((r & binary.BIT8) === 0) {\n // don't continue reading\n return sign * num\n }\n const len = decoder.arr.length\n while (decoder.pos < len) {\n r = decoder.arr[decoder.pos++]\n // num = num | ((r & binary.BITS7) << len)\n num = num + (r & binary.BITS7) * mult\n mult *= 128\n if (r < binary.BIT8) {\n return sign * num\n }\n /* c8 ignore start */\n if (num > number.MAX_SAFE_INTEGER) {\n throw errorIntegerOutOfRange\n }\n /* c8 ignore stop */\n }\n throw errorUnexpectedEndOfArray\n}\n\n/**\n * Look ahead and read varUint without incrementing position\n *\n * @function\n * @param {Decoder} decoder\n * @return {number}\n */\nexport const peekVarUint = decoder => {\n const pos = decoder.pos\n const s = readVarUint(decoder)\n decoder.pos = pos\n return s\n}\n\n/**\n * Look ahead and read varUint without incrementing position\n *\n * @function\n * @param {Decoder} decoder\n * @return {number}\n */\nexport const peekVarInt = decoder => {\n const pos = decoder.pos\n const s = readVarInt(decoder)\n decoder.pos = pos\n return s\n}\n\n/**\n * We don't test this function anymore as we use native decoding/encoding by default now.\n * Better not modify this anymore..\n *\n * Transforming utf8 to a string is pretty expensive. The code performs 10x better\n * when String.fromCodePoint is fed with all characters as arguments.\n * But most environments have a maximum number of arguments per functions.\n * For effiency reasons we apply a maximum of 10000 characters at once.\n *\n * @function\n * @param {Decoder} decoder\n * @return {String} The read String.\n */\n/* c8 ignore start */\nexport const _readVarStringPolyfill = decoder => {\n let remainingLen = readVarUint(decoder)\n if (remainingLen === 0) {\n return ''\n } else {\n let encodedString = String.fromCodePoint(readUint8(decoder)) // remember to decrease remainingLen\n if (--remainingLen < 100) { // do not create a Uint8Array for small strings\n while (remainingLen--) {\n encodedString += String.fromCodePoint(readUint8(decoder))\n }\n } else {\n while (remainingLen > 0) {\n const nextLen = remainingLen < 10000 ? remainingLen : 10000\n // this is dangerous, we create a fresh array view from the existing buffer\n const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen)\n decoder.pos += nextLen\n // Starting with ES5.1 we can supply a generic array-like object as arguments\n encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes))\n remainingLen -= nextLen\n }\n }\n return decodeURIComponent(escape(encodedString))\n }\n}\n/* c8 ignore stop */\n\n/**\n * @function\n * @param {Decoder} decoder\n * @return {String} The read String\n */\nexport const _readVarStringNative = decoder =>\n /** @type any */ (string.utf8TextDecoder).decode(readVarUint8Array(decoder))\n\n/**\n * Read string of variable length\n * * varUint is used to store the length of the string\n *\n * @function\n * @param {Decoder} decoder\n * @return {String} The read String\n *\n */\n/* c8 ignore next */\nexport const readVarString = string.utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill\n\n/**\n * @param {Decoder} decoder\n * @return {Uint8Array}\n */\nexport const readTerminatedUint8Array = decoder => {\n const encoder = encoding.createEncoder()\n let b\n while (true) {\n b = readUint8(decoder)\n if (b === 0) {\n return encoding.toUint8Array(encoder)\n }\n if (b === 1) {\n b = readUint8(decoder)\n }\n encoding.write(encoder, b)\n }\n}\n\n/**\n * @param {Decoder} decoder\n * @return {string}\n */\nexport const readTerminatedString = decoder => string.decodeUtf8(readTerminatedUint8Array(decoder))\n\n/**\n * Look ahead and read varString without incrementing position\n *\n * @function\n * @param {Decoder} decoder\n * @return {string}\n */\nexport const peekVarString = decoder => {\n const pos = decoder.pos\n const s = readVarString(decoder)\n decoder.pos = pos\n return s\n}\n\n/**\n * @param {Decoder} decoder\n * @param {number} len\n * @return {DataView}\n */\nexport const readFromDataView = (decoder, len) => {\n const dv = new DataView(decoder.arr.buffer, decoder.arr.byteOffset + decoder.pos, len)\n decoder.pos += len\n return dv\n}\n\n/**\n * @param {Decoder} decoder\n */\nexport const readFloat32 = decoder => readFromDataView(decoder, 4).getFloat32(0, false)\n\n/**\n * @param {Decoder} decoder\n */\nexport const readFloat64 = decoder => readFromDataView(decoder, 8).getFloat64(0, false)\n\n/**\n * @param {Decoder} decoder\n */\nexport const readBigInt64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigInt64(0, false)\n\n/**\n * @param {Decoder} decoder\n */\nexport const readBigUint64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigUint64(0, false)\n\n/**\n * @type {Array<function(Decoder):any>}\n */\nconst readAnyLookupTable = [\n decoder => undefined, // CASE 127: undefined\n decoder => null, // CASE 126: null\n readVarInt, // CASE 125: integer\n readFloat32, // CASE 124: float32\n readFloat64, // CASE 123: float64\n readBigInt64, // CASE 122: bigint\n decoder => false, // CASE 121: boolean (false)\n decoder => true, // CASE 120: boolean (true)\n readVarString, // CASE 119: string\n decoder => { // CASE 118: object<string,any>\n const len = readVarUint(decoder)\n /**\n * @type {Object<string,any>}\n */\n const obj = {}\n for (let i = 0; i < len; i++) {\n const key = readVarString(decoder)\n obj[key] = readAny(decoder)\n }\n return obj\n },\n decoder => { // CASE 117: array<any>\n const len = readVarUint(decoder)\n const arr = []\n for (let i = 0; i < len; i++) {\n arr.push(readAny(decoder))\n }\n return arr\n },\n readVarUint8Array // CASE 116: Uint8Array\n]\n\n/**\n * @param {Decoder} decoder\n */\nexport const readAny = decoder => readAnyLookupTable[127 - readUint8(decoder)](decoder)\n\n/**\n * T must not be null.\n *\n * @template T\n */\nexport class RleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n * @param {function(Decoder):T} reader\n */\n constructor (uint8Array, reader) {\n super(uint8Array)\n /**\n * The reader\n */\n this.reader = reader\n /**\n * Current state\n * @type {T|null}\n */\n this.s = null\n this.count = 0\n }\n\n read () {\n if (this.count === 0) {\n this.s = this.reader(this)\n if (hasContent(this)) {\n this.count = readVarUint(this) + 1 // see encoder implementation for the reason why this is incremented\n } else {\n this.count = -1 // read the current value forever\n }\n }\n this.count--\n return /** @type {T} */ (this.s)\n }\n}\n\nexport class IntDiffDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n * @param {number} start\n */\n constructor (uint8Array, start) {\n super(uint8Array)\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n }\n\n /**\n * @return {number}\n */\n read () {\n this.s += readVarInt(this)\n return this.s\n }\n}\n\nexport class RleIntDiffDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n * @param {number} start\n */\n constructor (uint8Array, start) {\n super(uint8Array)\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n this.count = 0\n }\n\n /**\n * @return {number}\n */\n read () {\n if (this.count === 0) {\n this.s += readVarInt(this)\n if (hasContent(this)) {\n this.count = readVarUint(this) + 1 // see encoder implementation for the reason why this is incremented\n } else {\n this.count = -1 // read the current value forever\n }\n }\n this.count--\n return /** @type {number} */ (this.s)\n }\n}\n\nexport class UintOptRleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n super(uint8Array)\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n read () {\n if (this.count === 0) {\n this.s = readVarInt(this)\n // if the sign is negative, we read the count too, otherwise count is 1\n const isNegative = math.isNegativeZero(this.s)\n this.count = 1\n if (isNegative) {\n this.s = -this.s\n this.count = readVarUint(this) + 2\n }\n }\n this.count--\n return /** @type {number} */ (this.s)\n }\n}\n\nexport class IncUintOptRleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n super(uint8Array)\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n read () {\n if (this.count === 0) {\n this.s = readVarInt(this)\n // if the sign is negative, we read the count too, otherwise count is 1\n const isNegative = math.isNegativeZero(this.s)\n this.count = 1\n if (isNegative) {\n this.s = -this.s\n this.count = readVarUint(this) + 2\n }\n }\n this.count--\n return /** @type {number} */ (this.s++)\n }\n}\n\nexport class IntDiffOptRleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n super(uint8Array)\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n this.diff = 0\n }\n\n /**\n * @return {number}\n */\n read () {\n if (this.count === 0) {\n const diff = readVarInt(this)\n // if the first bit is set, we read more data\n const hasCount = diff & 1\n this.diff = math.floor(diff / 2) // shift >> 1\n this.count = 1\n if (hasCount) {\n this.count = readVarUint(this) + 2\n }\n }\n this.s += this.diff\n this.count--\n return this.s\n }\n}\n\nexport class StringDecoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n this.decoder = new UintOptRleDecoder(uint8Array)\n this.str = readVarString(this.decoder)\n /**\n * @type {number}\n */\n this.spos = 0\n }\n\n /**\n * @return {string}\n */\n read () {\n const end = this.spos + this.decoder.read()\n const res = this.str.slice(this.spos, end)\n this.spos = end\n return res\n }\n}\n","import { webcrypto } from 'node:crypto'\n\nexport const subtle = /** @type {any} */ (webcrypto).subtle\nexport const getRandomValues = /** @type {any} */ (webcrypto).getRandomValues.bind(webcrypto)\n","/**\n * Isomorphic module for true random numbers / buffers / uuids.\n *\n * Attention: falls back to Math.random if the browser does not support crypto.\n *\n * @module random\n */\n\nimport * as math from './math.js'\nimport * as binary from './binary.js'\nimport { getRandomValues } from 'lib0/webcrypto'\n\nexport const rand = Math.random\n\nexport const uint32 = () => getRandomValues(new Uint32Array(1))[0]\n\nexport const uint53 = () => {\n const arr = getRandomValues(new Uint32Array(8))\n return (arr[0] & binary.BITS21) * (binary.BITS32 + 1) + (arr[1] >>> 0)\n}\n\n/**\n * @template T\n * @param {Array<T>} arr\n * @return {T}\n */\nexport const oneOf = arr => arr[math.floor(rand() * arr.length)]\n\n// @ts-ignore\nconst uuidv4Template = [1e7] + -1e3 + -4e3 + -8e3 + -1e11\n\n/**\n * @return {string}\n */\nexport const uuidv4 = () => uuidv4Template.replace(/[018]/g, /** @param {number} c */ c =>\n (c ^ uint32() & 15 >> c / 4).toString(16)\n)\n","/**\n * Utility module to work with time.\n *\n * @module time\n */\n\nimport * as metric from './metric.js'\nimport * as math from './math.js'\n\n/**\n * Return current time.\n *\n * @return {Date}\n */\nexport const getDate = () => new Date()\n\n/**\n * Return current unix time.\n *\n * @return {number}\n */\nexport const getUnixTime = Date.now\n\n/**\n * Transform time (in ms) to a human readable format. E.g. 1100 => 1.1s. 60s => 1min. .001 => 10μs.\n *\n * @param {number} d duration in milliseconds\n * @return {string} humanized approximation of time\n */\nexport const humanizeDuration = d => {\n if (d < 60000) {\n const p = metric.prefix(d, -1)\n return math.round(p.n * 100) / 100 + p.prefix + 's'\n }\n d = math.floor(d / 1000)\n const seconds = d % 60\n const minutes = math.floor(d / 60) % 60\n const hours = math.floor(d / 3600) % 24\n const days = math.floor(d / 86400)\n if (days > 0) {\n return days + 'd' + ((hours > 0 || minutes > 30) ? ' ' + (minutes > 30 ? hours + 1 : hours) + 'h' : '')\n }\n if (hours > 0) {\n /* c8 ignore next */\n return hours + 'h' + ((minutes > 0 || seconds > 30) ? ' ' + (seconds > 30 ? minutes + 1 : minutes) + 'min' : '')\n }\n return minutes + 'min' + (seconds > 0 ? ' ' + seconds + 's' : '')\n}\n","/**\n * Utility helpers to work with promises.\n *\n * @module promise\n */\n\nimport * as time from './time.js'\n\n/**\n * @template T\n * @callback PromiseResolve\n * @param {T|PromiseLike<T>} [result]\n */\n\n/**\n * @template T\n * @param {function(PromiseResolve<T>,function(Error):void):any} f\n * @return {Promise<T>}\n */\nexport const create = f => /** @type {Promise<T>} */ (new Promise(f))\n\n/**\n * @param {function(function():void,function(Error):void):void} f\n * @return {Promise<void>}\n */\nexport const createEmpty = f => new Promise(f)\n\n/**\n * `Promise.all` wait for all promises in the array to resolve and return the result\n * @template {unknown[] | []} PS\n *\n * @param {PS} ps\n * @return {Promise<{ -readonly [P in keyof PS]: Awaited<PS[P]> }>}\n */\nexport const all = Promise.all.bind(Promise)\n\n/**\n * @param {Error} [reason]\n * @return {Promise<never>}\n */\nexport const reject = reason => Promise.reject(reason)\n\n/**\n * @template T\n * @param {T|void} res\n * @return {Promise<T|void>}\n */\nexport const resolve = res => Promise.resolve(res)\n\n/**\n * @template T\n * @param {T} res\n * @return {Promise<T>}\n */\nexport const resolveWith = res => Promise.resolve(res)\n\n/**\n * @todo Next version, reorder parameters: check, [timeout, [intervalResolution]]\n * @deprecated use untilAsync instead\n *\n * @param {number} timeout\n * @param {function():boolean} check\n * @param {number} [intervalResolution]\n * @return {Promise<void>}\n */\nexport const until = (timeout, check, intervalResolution = 10) => create((resolve, reject) => {\n const startTime = time.getUnixTime()\n const hasTimeout = timeout > 0\n const untilInterval = () => {\n if (check()) {\n clearInterval(intervalHandle)\n resolve()\n } else if (hasTimeout) {\n /* c8 ignore else */\n if (time.getUnixTime() - startTime > timeout) {\n clearInterval(intervalHandle)\n reject(new Error('Timeout'))\n }\n }\n }\n const intervalHandle = setInterval(untilInterval, intervalResolution)\n})\n\n/**\n * @param {()=>Promise<boolean>|boolean} check\n * @param {number} timeout\n * @param {number} intervalResolution\n * @return {Promise<void>}\n */\nexport const untilAsync = async (check, timeout = 0, intervalResolution = 10) => {\n const startTime = time.getUnixTime()\n const noTimeout = timeout <= 0\n // eslint-disable-next-line no-unmodified-loop-condition\n while (noTimeout || time.getUnixTime() - startTime <= timeout) {\n if (await check()) return\n await wait(intervalResolution)\n }\n throw new Error('Timeout')\n}\n\n/**\n * @param {number} timeout\n * @return {Promise<undefined>}\n */\nexport const wait = timeout => create((resolve, _reject) => setTimeout(resolve, timeout))\n\n/**\n * Checks if an object is a promise using ducktyping.\n *\n * Promises are often polyfilled, so it makes sense to add some additional guarantees if the user of this\n * library has some insane environment where global Promise objects are overwritten.\n *\n * @param {any} p\n * @return {boolean}\n */\nexport const isPromise = p => p instanceof Promise || (p && p.then && p.catch && p.finally)\n","/**\n * Often used conditions.\n *\n * @module conditions\n */\n\n/**\n * @template T\n * @param {T|null|undefined} v\n * @return {T|null}\n */\n/* c8 ignore next */\nexport const undefinedToNull = v => v === undefined ? null : v\n","/* eslint-env browser */\n\n/**\n * Isomorphic variable storage.\n *\n * Uses LocalStorage in the browser and falls back to in-memory storage.\n *\n * @module storage\n */\n\n/* c8 ignore start */\nclass VarStoragePolyfill {\n constructor () {\n this.map = new Map()\n }\n\n /**\n * @param {string} key\n * @param {any} newValue\n */\n setItem (key, newValue) {\n this.map.set(key, newValue)\n }\n\n /**\n * @param {string} key\n */\n getItem (key) {\n return this.map.get(key)\n }\n}\n/* c8 ignore stop */\n\n/**\n * @type {any}\n */\nlet _localStorage = new VarStoragePolyfill()\nlet usePolyfill = true\n\n/* c8 ignore start */\ntry {\n // if the same-origin rule is violated, accessing localStorage might thrown an error\n if (typeof localStorage !== 'undefined' && localStorage) {\n _localStorage = localStorage\n usePolyfill = false\n }\n} catch (e) { }\n/* c8 ignore stop */\n\n/**\n * This is basically localStorage in browser, or a polyfill in nodejs\n */\n/* c8 ignore next */\nexport const varStorage = _localStorage\n\n/**\n * A polyfill for `addEventListener('storage', event => {..})` that does nothing if the polyfill is being used.\n *\n * @param {function({ key: string, newValue: string, oldValue: string }): void} eventHandler\n * @function\n */\n/* c8 ignore next */\nexport const onChange = eventHandler => usePolyfill || addEventListener('storage', /** @type {any} */ (eventHandler))\n\n/**\n * A polyfill for `removeEventListener('storage', event => {..})` that does nothing if the polyfill is being used.\n *\n * @param {function({ key: string, newValue: string, oldValue: string }): void} eventHandler\n * @function\n */\n/* c8 ignore next */\nexport const offChange = eventHandler => usePolyfill || removeEventListener('storage', /** @type {any} */ (eventHandler))\n","/**\n * Utility functions for working with EcmaScript objects.\n *\n * @module object\n */\n\n/**\n * @return {Object<string,any>} obj\n */\nexport const create = () => Object.create(null)\n\n/**\n * Object.assign\n */\nexport const assign = Object.assign\n\n/**\n * @param {Object<string,any>} obj\n */\nexport const keys = Object.keys\n\n/**\n * @template V\n * @param {{[key:string]: V}} obj\n * @return {Array<V>}\n */\nexport const values = Object.values\n\n/**\n * @template V\n * @param {{[k:string]:V}} obj\n * @param {function(V,string):any} f\n */\nexport const forEach = (obj, f) => {\n for (const key in obj) {\n f(obj[key], key)\n }\n}\n\n/**\n * @todo implement mapToArray & map\n *\n * @template R\n * @param {Object<string,any>} obj\n * @param {function(any,string):R} f\n * @return {Array<R>}\n */\nexport const map = (obj, f) => {\n const results = []\n for (const key in obj) {\n results.push(f(obj[key], key))\n }\n return results\n}\n\n/**\n * @deprecated use object.size instead\n * @param {Object<string,any>} obj\n * @return {number}\n */\nexport const length = obj => keys(obj).length\n\n/**\n * @param {Object<string,any>} obj\n * @return {number}\n */\nexport const size = obj => keys(obj).length\n\n/**\n * @template {{ [key:string|number|symbol]: any }} T\n * @param {T} obj\n * @param {(v:T[keyof T],k:keyof T)=>boolean} f\n * @return {boolean}\n */\nexport const some = (obj, f) => {\n for (const key in obj) {\n if (f(obj[key], key)) {\n return true\n }\n }\n return false\n}\n\n/**\n * @param {Object|null|undefined} obj\n */\nexport const isEmpty = obj => {\n // eslint-disable-next-line no-unreachable-loop\n for (const _k in obj) {\n return false\n }\n return true\n}\n\n/**\n * @template {{ [key:string|number|symbol]: any }} T\n * @param {T} obj\n * @param {(v:T[keyof T],k:keyof T)=>boolean} f\n * @return {boolean}\n */\nexport const every = (obj, f) => {\n for (const key in obj) {\n if (!f(obj[key], key)) {\n return false\n }\n }\n return true\n}\n\n/**\n * Calls `Object.prototype.hasOwnProperty`.\n *\n * @param {any} obj\n * @param {string|number|symbol} key\n * @return {boolean}\n */\nexport const hasProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key)\n\n/**\n * @param {Object<string,any>} a\n * @param {Object<string,any>} b\n * @return {boolean}\n */\nexport const equalFlat = (a, b) => a === b || (size(a) === size(b) && every(a, (val, key) => (val !== undefined || hasProperty(b, key)) && b[key] === val))\n\n/**\n * Make an object immutable. This hurts performance and is usually not needed if you perform good\n * coding practices.\n */\nexport const freeze = Object.freeze\n\n/**\n * Make an object and all its children immutable.\n * This *really* hurts performance and is usually not needed if you perform good coding practices.\n *\n * @template {any} T\n * @param {T} o\n * @return {Readonly<T>}\n */\nexport const deepFreeze = (o) => {\n for (const key in o) {\n const c = o[key]\n if (typeof c === 'object' || typeof c === 'function') {\n deepFreeze(o[key])\n }\n }\n return freeze(o)\n}\n\n/**\n * Get object property. Create T if property is undefined and set T on object.\n *\n * @function\n * @template {object} KV\n * @template {keyof KV} [K=keyof KV]\n * @param {KV} o\n * @param {K} key\n * @param {() => KV[K]} createT\n * @return {KV[K]}\n */\nexport const setIfUndefined = (o, key, createT) => hasProperty(o, key) ? o[key] : (o[key] = createT())\n","/**\n * Common functions and function call helpers.\n *\n * @module function\n */\n\nimport * as array from './array.js'\nimport * as object from './object.js'\nimport * as traits from './traits.js'\n\n/**\n * Calls all functions in `fs` with args. Only throws after all functions were called.\n *\n * @param {Array<function>} fs\n * @param {Array<any>} args\n */\nexport const callAll = (fs, args, i = 0) => {\n try {\n for (; i < fs.length; i++) {\n fs[i](...args)\n }\n } finally {\n if (i < fs.length) {\n callAll(fs, args, i + 1)\n }\n }\n}\n\nexport const nop = () => {}\n\n/**\n * @template T\n * @param {function():T} f\n * @return {T}\n */\nexport const apply = f => f()\n\n/**\n * @template A\n *\n * @param {A} a\n * @return {A}\n */\nexport const id = a => a\n\n/**\n * @template T\n *\n * @param {T} a\n * @param {T} b\n * @return {boolean}\n */\nexport const equalityStrict = (a, b) => a === b\n\n/**\n * @template T\n *\n * @param {Array<T>|object} a\n * @param {Array<T>|object} b\n * @return {boolean}\n */\nexport const equalityFlat = (a, b) => a === b || (a != null && b != null && a.constructor === b.constructor && ((array.isArray(a) && array.equalFlat(a, /** @type {Array<T>} */ (b))) || (typeof a === 'object' && object.equalFlat(a, b))))\n\n/* c8 ignore start */\n\n/**\n * @param {any} a\n * @param {any} b\n * @return {boolean}\n */\nexport const equalityDeep = (a, b) => {\n if (a === b) {\n return true\n }\n if (a == null || b == null || a.constructor !== b.constructor) {\n return false\n }\n if (a[traits.EqualityTraitSymbol] != null) {\n return a[traits.EqualityTraitSymbol](b)\n }\n switch (a.constructor) {\n case ArrayBuffer:\n a = new Uint8Array(a)\n b = new Uint8Array(b)\n // eslint-disable-next-line no-fallthrough\n case Uint8Array: {\n if (a.byteLength !== b.byteLength) {\n return false\n }\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) {\n return false\n }\n }\n break\n }\n case Set: {\n if (a.size !== b.size) {\n return false\n }\n for (const value of a) {\n if (!b.has(value)) {\n return false\n }\n }\n break\n }\n case Map: {\n if (a.size !== b.size) {\n return false\n }\n for (const key of a.keys()) {\n if (!b.has(key) || !equalityDeep(a.get(key), b.get(key))) {\n return false\n }\n }\n break\n }\n case Object:\n if (object.length(a) !== object.length(b)) {\n return false\n }\n for (const key in a) {\n if (!object.hasProperty(a, key) || !equalityDeep(a[key], b[key])) {\n return false\n }\n }\n break\n case Array:\n if (a.length !== b.length) {\n return false\n }\n for (let i = 0; i < a.length; i++) {\n if (!equalityDeep(a[i], b[i])) {\n return false\n }\n }\n break\n default:\n return false\n }\n return true\n}\n\n/**\n * @template V\n * @template {V} OPTS\n *\n * @param {V} value\n * @param {Array<OPTS>} options\n */\n// @ts-ignore\nexport const isOneOf = (value, options) => options.includes(value)\n/* c8 ignore stop */\n\nexport const isArray = array.isArray\n\n/**\n * @param {any} s\n * @return {s is String}\n */\nexport const isString = (s) => s && s.constructor === String\n\n/**\n * @param {any} n\n * @return {n is Number}\n */\nexport const isNumber = n => n != null && n.constructor === Number\n\n/**\n * @template {abstract new (...args: any) => any} TYPE\n * @param {any} n\n * @param {TYPE} T\n * @return {n is InstanceType<TYPE>}\n */\nexport const is = (n, T) => n && n.constructor === T\n\n/**\n * @template {abstract new (...args: any) => any} TYPE\n * @param {TYPE} T\n */\nexport const isTemplate = (T) =>\n /**\n * @param {any} n\n * @return {n is InstanceType<TYPE>}\n **/\n n => n && n.constructor === T\n","/**\n * Isomorphic module to work access the environment (query params, env variables).\n *\n * @module environment\n */\n\nimport * as map from './map.js'\nimport * as string from './string.js'\nimport * as conditions from './conditions.js'\nimport * as storage from './storage.js'\nimport * as f from './function.js'\n\n/* c8 ignore next 2 */\n// @ts-ignore\nexport const isNode = typeof process !== 'undefined' && process.release && /node|io\\.js/.test(process.release.name) && Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]'\n\n/* c8 ignore next */\nexport const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && !isNode\n/* c8 ignore next 3 */\nexport const isMac = typeof navigator !== 'undefined'\n ? /Mac/.test(navigator.platform)\n : false\n\n/**\n * @type {Map<string,string>}\n */\nlet params\nconst args = []\n\n/* c8 ignore start */\nconst computeParams = () => {\n if (params === undefined) {\n if (isNode) {\n params = map.create()\n const pargs = process.argv\n let currParamName = null\n for (let i = 0; i < pargs.length; i++) {\n const parg = pargs[i]\n if (parg[0] === '-') {\n if (currParamName !== null) {\n params.set(currParamName, '')\n }\n currParamName = parg\n } else {\n if (currParamName !== null) {\n params.set(currParamName, parg)\n currParamName = null\n } else {\n args.push(parg)\n }\n }\n }\n if (currParamName !== null) {\n params.set(currParamName, '')\n }\n // in ReactNative for example this would not be true (unless connected to the Remote Debugger)\n } else if (typeof location === 'object') {\n params = map.create(); // eslint-disable-next-line no-undef\n (location.search || '?').slice(1).split('&').forEach((kv) => {\n if (kv.length !== 0) {\n const [key, value] = kv.split('=')\n params.set(`--${string.fromCamelCase(key, '-')}`, value)\n params.set(`-${string.fromCamelCase(key, '-')}`, value)\n }\n })\n } else {\n params = map.create()\n }\n }\n return params\n}\n/* c8 ignore stop */\n\n/**\n * @param {string} name\n * @return {boolean}\n */\n/* c8 ignore next */\nexport const hasParam = (name) => computeParams().has(name)\n\n/**\n * @param {string} name\n * @param {string} defaultVal\n * @return {string}\n */\n/* c8 ignore next 2 */\nexport const getParam = (name, defaultVal) =>\n computeParams().get(name) || defaultVal\n\n/**\n * @param {string} name\n * @return {string|null}\n */\n/* c8 ignore next 4 */\nexport const getVariable = (name) =>\n isNode\n ? conditions.undefinedToNull(process.env[name.toUpperCase().replaceAll('-', '_')])\n : conditions.undefinedToNull(storage.varStorage.getItem(name))\n\n/**\n * @param {string} name\n * @return {string|null}\n */\n/* c8 ignore next 2 */\nexport const getConf = (name) =>\n computeParams().get('--' + name) || getVariable(name)\n\n/**\n * @param {string} name\n * @return {string}\n */\n/* c8 ignore next 5 */\nexport const ensureConf = (name) => {\n const c = getConf(name)\n if (c == null) throw new Error(`Expected configuration \"${name.toUpperCase().replaceAll('-', '_')}\"`)\n return c\n}\n\n/**\n * @param {string} name\n * @return {boolean}\n */\n/* c8 ignore next 2 */\nexport const hasConf = (name) =>\n hasParam('--' + name) || getVariable(name) !== null\n\n/* c8 ignore next */\nexport const production = hasConf('production')\n\n/* c8 ignore next 2 */\nconst forceColor = isNode &&\n f.isOneOf(process.env.FORCE_COLOR, ['true', '1', '2'])\n\n/* c8 ignore start */\n/**\n * Color is enabled by default if the terminal supports it.\n *\n * Explicitly enable color using `--color` parameter\n * Disable color using `--no-color` parameter or using `NO_COLOR=1` environment variable.\n * `FORCE_COLOR=1` enables color and takes precedence over all.\n */\nexport const supportsColor = forceColor || (\n !hasParam('--no-colors') && // @todo deprecate --no-colors\n !hasConf('no-color') &&\n (!isNode || process.stdout.isTTY) && (\n !isNode ||\n hasParam('--color') ||\n getVariable('COLORTERM') !== null ||\n (getVariable('TERM') || '').includes('color')\n )\n)\n/* c8 ignore stop */\n","/**\n * Utility functions to work with buffers (Uint8Array).\n *\n * @module buffer\n */\n\nimport * as string from './string.js'\nimport * as env from './environment.js'\nimport * as array from './array.js'\nimport * as math from './math.js'\nimport * as encoding from './encoding.js'\nimport * as decoding from './decoding.js'\n\n/**\n * @param {number} len\n */\nexport const createUint8ArrayFromLen = len => new Uint8Array(len)\n\n/**\n * Create Uint8Array with initial content from buffer\n *\n * @param {ArrayBuffer} buffer\n * @param {number} byteOffset\n * @param {number} length\n */\nexport const createUint8ArrayViewFromArrayBuffer = (buffer, byteOffset, length) => new Uint8Array(buffer, byteOffset, length)\n\n/**\n * Create Uint8Array with initial content from buffer\n *\n * @param {ArrayBuffer} buffer\n */\nexport const createUint8ArrayFromArrayBuffer = buffer => new Uint8Array(buffer)\n\n/* c8 ignore start */\n/**\n * @param {Uint8Array} bytes\n * @return {string}\n */\nconst toBase64Browser = bytes => {\n let s = ''\n for (let i = 0; i < bytes.byteLength; i++) {\n s += string.fromCharCode(bytes[i])\n }\n // eslint-disable-next-line no-undef\n return btoa(s)\n}\n/* c8 ignore stop */\n\n/**\n * @param {Uint8Array} bytes\n * @return {string}\n */\nconst toBase64Node = bytes => Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('base64')\n\n/* c8 ignore start */\n/**\n * @param {string} s\n * @return {Uint8Array}\n */\nconst fromBase64Browser = s => {\n // eslint-disable-next-line no-undef\n const a = atob(s)\n const bytes = createUint8ArrayFromLen(a.length)\n for (let i = 0; i < a.length; i++) {\n bytes[i] = a.charCodeAt(i)\n }\n return bytes\n}\n/* c8 ignore stop */\n\n/**\n * @param {string} s\n */\nconst fromBase64Node = s => {\n const buf = Buffer.from(s, 'base64')\n return createUint8ArrayViewFromArrayBuffer(buf.buffer, buf.byteOffset, buf.byteLength)\n}\n\n/* c8 ignore next */\nexport const toBase64 = env.isBrowser ? toBase64Browser : toBase64Node\n\n/* c8 ignore next */\nexport const fromBase64 = env.isBrowser ? fromBase64Browser : fromBase64Node\n\n/**\n * Implements base64url - see https://datatracker.ietf.org/doc/html/rfc4648#section-5\n * @param {Uint8Array} buf\n */\nexport const toBase64UrlEncoded = buf => toBase64(buf).replaceAll('+', '-').replaceAll('/', '_').replaceAll('=', '')\n\n/**\n * @param {string} base64\n */\nexport const fromBase64UrlEncoded = base64 => fromBase64(base64.replaceAll('-', '+').replaceAll('_', '/'))\n\n/**\n * Base64 is always a more efficient choice. This exists for utility purposes only.\n *\n * @param {Uint8Array} buf\n */\nexport const toHexString = buf => array.map(buf, b => b.toString(16).padStart(2, '0')).join('')\n\n/**\n * Note: This function expects that the hex doesn't start with 0x..\n *\n * @param {string} hex\n */\nexport const fromHexString = hex => {\n const hlen = hex.length\n const buf = new Uint8Array(math.ceil(hlen / 2))\n for (let i = 0; i < hlen; i += 2) {\n buf[buf.length - i / 2 - 1] = Number.parseInt(hex.slice(hlen - i - 2, hlen - i), 16)\n }\n return buf\n}\n\n/**\n * Copy the content of an Uint8Array view to a new ArrayBuffer.\n *\n * @param {Uint8Array} uint8Array\n * @return {Uint8Array}\n */\nexport const copyUint8Array = uint8Array => {\n const newBuf = createUint8ArrayFromLen(uint8Array.byteLength)\n newBuf.set(uint8Array)\n return newBuf\n}\n\n/**\n * Encode anything as a UInt8Array. It's a pun on typescripts's `any` type.\n * See encoding.writeAny for more information.\n *\n * @param {any} data\n * @return {Uint8Array}\n */\nexport const encodeAny = data =>\n encoding.encode(encoder => encoding.writeAny(encoder, data))\n\n/**\n * Decode an any-encoded value.\n *\n * @param {Uint8Array} buf\n * @return {any}\n */\nexport const decodeAny = buf => decoding.readAny(decoding.createDecoder(buf))\n\n/**\n * Shift Byte Array {N} bits to the left. Does not expand byte array.\n *\n * @param {Uint8Array} bs\n * @param {number} N should be in the range of [0-7]\n */\nexport const shiftNBitsLeft = (bs, N) => {\n if (N === 0) return bs\n bs = new Uint8Array(bs)\n bs[0] <<= N\n for (let i = 1; i < bs.length; i++) {\n bs[i - 1] |= bs[i] >>> (8 - N)\n bs[i] <<= N\n }\n return bs\n}\n","/**\n * Utility module to work with EcmaScript Symbols.\n *\n * @module symbol\n */\n\n/**\n * Return fresh symbol.\n */\nexport const create = Symbol\n\n/**\n * @param {any} s\n * @return {boolean}\n */\nexport const isSymbol = s => typeof s === 'symbol'\n","import * as symbol from './symbol.js'\nimport * as time from './time.js'\nimport * as env from './environment.js'\nimport * as func from './function.js'\nimport * as json from './json.js'\n\nexport const BOLD = symbol.create()\nexport const UNBOLD = symbol.create()\nexport const BLUE = symbol.create()\nexport const GREY = symbol.create()\nexport const GREEN = symbol.create()\nexport const RED = symbol.create()\nexport const PURPLE = symbol.create()\nexport const ORANGE = symbol.create()\nexport const UNCOLOR = symbol.create()\n\n/* c8 ignore start */\n/**\n * @param {Array<undefined|string|Symbol|Object|number|function():any>} args\n * @return {Array<string|object|number|undefined>}\n */\nexport const computeNoColorLoggingArgs = args => {\n if (args.length === 1 && args[0]?.constructor === Function) {\n args = /** @type {Array<string|Symbol|Object|number>} */ (/** @type {[function]} */ (args)[0]())\n }\n const strBuilder = []\n const logArgs = []\n // try with formatting until we find something unsupported\n let i = 0\n for (; i < args.length; i++) {\n const arg = args[i]\n if (arg === undefined) {\n break\n } else if (arg.constructor === String || arg.constructor === Number) {\n strBuilder.push(arg)\n } else if (arg.constructor === Object) {\n break\n }\n }\n if (i > 0) {\n // create logArgs with what we have so far\n logArgs.push(strBuilder.join(''))\n }\n // append the rest\n for (; i < args.length; i++) {\n const arg = args[i]\n if (!(arg instanceof Symbol)) {\n logArgs.push(arg)\n }\n }\n return logArgs\n}\n/* c8 ignore stop */\n\nconst loggingColors = [GREEN, PURPLE, ORANGE, BLUE]\nlet nextColor = 0\nlet lastLoggingTime = time.getUnixTime()\n\n/* c8 ignore start */\n/**\n * @param {function(...any):void} _print\n * @param {string} moduleName\n * @return {function(...any):void}\n */\nexport const createModuleLogger = (_print, moduleName) => {\n const color = loggingColors[nextColor]\n const debugRegexVar = env.getVariable('log')\n const doLogging = debugRegexVar !== null &&\n (debugRegexVar === '*' || debugRegexVar === 'true' ||\n new RegExp(debugRegexVar, 'gi').test(moduleName))\n nextColor = (nextColor + 1) % loggingColors.length\n moduleName += ': '\n return !doLogging\n ? func.nop\n : (...args) => {\n if (args.length === 1 && args[0]?.constructor === Function) {\n args = args[0]()\n }\n const timeNow = time.getUnixTime()\n const timeDiff = timeNow - lastLoggingTime\n lastLoggingTime = timeNow\n _print(\n color,\n moduleName,\n UNCOLOR,\n ...args.map((arg) => {\n if (arg != null && arg.constructor === Uint8Array) {\n arg = Array.from(arg)\n }\n const t = typeof arg\n switch (t) {\n case 'string':\n case 'symbol':\n return arg\n default: {\n return json.stringify(arg)\n }\n }\n }),\n color,\n ' +' + timeDiff + 'ms'\n )\n }\n}\n/* c8 ignore stop */\n","/**\n * Isomorphic logging module with support for colors!\n *\n * @module logging\n */\n\nimport * as env from './environment.js'\nimport * as common from './logging.common.js'\n\nexport { BOLD, UNBOLD, BLUE, GREY, GREEN, RED, PURPLE, ORANGE, UNCOLOR } from './logging.common.js'\n\nconst _nodeStyleMap = {\n [common.BOLD]: '\\u001b[1m',\n [common.UNBOLD]: '\\u001b[2m',\n [common.BLUE]: '\\x1b[34m',\n [common.GREEN]: '\\x1b[32m',\n [common.GREY]: '\\u001b[37m',\n [common.RED]: '\\x1b[31m',\n [common.PURPLE]: '\\x1b[35m',\n [common.ORANGE]: '\\x1b[38;5;208m',\n [common.UNCOLOR]: '\\x1b[0m'\n}\n\n/* c8 ignore start */\n/**\n * @param {Array<string|undefined|Symbol|Object|number|function():Array<any>>} args\n * @return {Array<string|object|number|undefined>}\n */\nconst computeNodeLoggingArgs = (args) => {\n if (args.length === 1 && args[0]?.constructor === Function) {\n args = /** @type {Array<string|Symbol|Object|number>} */ (/** @type {[function]} */ (args)[0]())\n }\n const strBuilder = []\n const logArgs = []\n // try with formatting until we find something unsupported\n let i = 0\n for (; i < args.length; i++) {\n const arg = args[i]\n // @ts-ignore\n const style = _nodeStyleMap[arg]\n if (style !== undefined) {\n strBuilder.push(style)\n } else {\n if (arg === undefined) {\n break\n } else if (arg.constructor === String || arg.constructor === Number) {\n strBuilder.push(arg)\n } else {\n break\n }\n }\n }\n if (i > 0) {\n // create logArgs with what we have so far\n strBuilder.push('\\x1b[0m')\n logArgs.push(strBuilder.join(''))\n }\n // append the rest\n for (; i < args.length; i++) {\n const arg = args[i]\n if (!(arg instanceof Symbol)) {\n logArgs.push(arg)\n }\n }\n return logArgs\n}\n/* c8 ignore stop */\n\n/* c8 ignore start */\nconst computeLoggingArgs = env.supportsColor\n ? computeNodeLoggingArgs\n : common.computeNoColorLoggingArgs\n/* c8 ignore stop */\n\n/**\n * @param {Array<string|Symbol|Object|number|undefined>} args\n */\nexport const print = (...args) => {\n console.log(...computeLoggingArgs(args))\n}\n\n/* c8 ignore start */\n/**\n * @param {Array<string|Symbol|Object|number>} args\n */\nexport const warn = (...args) => {\n console.warn(...computeLoggingArgs(args))\n}\n/* c8 ignore stop */\n\n/**\n * @param {Error} err\n */\n/* c8 ignore start */\nexport const printError = (err) => {\n console.error(err)\n}\n/* c8 ignore stop */\n\n/**\n * @param {string} _url image location\n * @param {number} _height height of the image in pixel\n */\n/* c8 ignore start */\nexport const printImg = (_url, _height) => {\n // console.log('%c ', `font-size: ${height}x; background: url(${url}) no-repeat;`)\n}\n/* c8 ignore stop */\n\n/**\n * @param {string} base64\n * @param {number} height\n */\n/* c8 ignore next 2 */\nexport const printImgBase64 = (base64, height) =>\n printImg(`data:image/gif;base64,${base64}`, height)\n\n/**\n * @param {Array<string|Symbol|Object|number>} args\n */\n/* c8 ignore next 3 */\nexport const group = (...args) => {\n console.group(...computeLoggingArgs(args))\n}\n\n/**\n * @param {Array<string|Symbol|Object|number>} args\n */\n/* c8 ignore next 3 */\nexport const groupCollapsed = (...args) => {\n console.groupCollapsed(...computeLoggingArgs(args))\n}\n\n/* c8 ignore next 3 */\nexport const groupEnd = () => {\n console.groupEnd()\n}\n\n/**\n * @param {function():Node} _createNode\n */\n/* c8 ignore next 2 */\nexport const printDom = (_createNode) => {}\n\n/**\n * @param {HTMLCanvasElement} canvas\n * @param {number} height\n */\n/* c8 ignore next 2 */\nexport const printCanvas = (canvas, height) =>\n printImg(canvas.toDataURL(), height)\n\n/**\n * @param {Element} _dom\n */\n/* c8 ignore next */\nexport const createVConsole = (_dom) => {}\n\n/**\n * @param {string} moduleName\n * @return {function(...any):void}\n */\n/* c8 ignore next */\nexport const createModuleLogger = (moduleName) => common.createModuleLogger(print, moduleName)\n","/**\n * Utility module to create and manipulate Iterators.\n *\n * @module iterator\n */\n\n/**\n * @template T,R\n * @param {Iterator<T>} iterator\n * @param {function(T):R} f\n * @return {IterableIterator<R>}\n */\nexport const mapIterator = (iterator, f) => ({\n [Symbol.iterator] () {\n return this\n },\n // @ts-ignore\n next () {\n const r = iterator.next()\n return { value: r.done ? undefined : f(r.value), done: r.done }\n }\n})\n\n/**\n * @template T\n * @param {function():IteratorResult<T>} next\n * @return {IterableIterator<T>}\n */\nexport const createIterator = next => ({\n /**\n * @return {IterableIterator<T>}\n */\n [Symbol.iterator] () {\n return this\n },\n // @ts-ignore\n next\n})\n\n/**\n * @template T\n * @param {Iterator<T>} iterator\n * @param {function(T):boolean} filter\n */\nexport const iteratorFilter = (iterator, filter) => createIterator(() => {\n let res\n do {\n res = iterator.next()\n } while (!res.done && !filter(res.value))\n return res\n})\n\n/**\n * @template T,M\n * @param {Iterator<T>} iterator\n * @param {function(T):M} fmap\n */\nexport const iteratorMap = (iterator, fmap) => createIterator(() => {\n const { done, value } = iterator.next()\n return { done, value: done ? undefined : fmap(value) }\n})\n","import {\n findIndexSS,\n getState,\n splitItem,\n iterateStructs,\n UpdateEncoderV2,\n DSDecoderV1, DSEncoderV1, DSDecoderV2, DSEncoderV2, Item, GC, StructStore, Transaction, ID // eslint-disable-line\n} from '../internals.js'\n\nimport * as array from 'lib0/array'\nimport * as math from 'lib0/math'\nimport * as map from 'lib0/map'\nimport * as encoding from 'lib0/encoding'\nimport * as decoding from 'lib0/decoding'\n\nexport class DeleteItem {\n /**\n * @param {number} clock\n * @param {number} len\n */\n constructor (clock, len) {\n /**\n * @type {number}\n */\n this.clock = clock\n /**\n * @type {number}\n */\n this.len = len\n }\n}\n\n/**\n * We no longer maintain a DeleteStore. DeleteSet is a temporary object that is created when needed.\n * - When created in a transaction, it must only be accessed after sorting, and merging\n * - This DeleteSet is send to other clients\n * - We do not create a DeleteSet when we send a sync message. The DeleteSet message is created directly from StructStore\n * - We read a DeleteSet as part of a sync/update message. In this case the DeleteSet is already sorted and merged.\n */\nexport class DeleteSet {\n constructor () {\n /**\n * @type {Map<number,Array<DeleteItem>>}\n */\n this.clients = new Map()\n }\n}\n\n/**\n * Iterate over all structs that the DeleteSet gc's.\n *\n * @param {Transaction} transaction\n * @param {DeleteSet} ds\n * @param {function(GC|Item):void} f\n *\n * @function\n */\nexport const iterateDeletedStructs = (transaction, ds, f) =>\n ds.clients.forEach((deletes, clientid) => {\n const structs = /** @type {Array<GC|Item>} */ (transaction.doc.store.clients.get(clientid))\n if (structs != null) {\n const lastStruct = structs[structs.length - 1]\n const clockState = lastStruct.id.clock + lastStruct.length\n for (let i = 0, del = deletes[i]; i < deletes.length && del.clock < clockState; del = deletes[++i]) {\n iterateStructs(transaction, structs, del.clock, del.len, f)\n }\n }\n })\n\n/**\n * @param {Array<DeleteItem>} dis\n * @param {number} clock\n * @return {number|null}\n *\n * @private\n * @function\n */\nexport const findIndexDS = (dis, clock) => {\n let left = 0\n let right = dis.length - 1\n while (left <= right) {\n const midindex = math.floor((left + right) / 2)\n const mid = dis[midindex]\n const midclock = mid.clock\n if (midclock <= clock) {\n if (clock < midclock + mid.len) {\n return midindex\n }\n left = midindex + 1\n } else {\n right = midindex - 1\n }\n }\n return null\n}\n\n/**\n * @param {DeleteSet} ds\n * @param {ID} id\n * @return {boolean}\n *\n * @private\n * @function\n */\nexport const isDeleted = (ds, id) => {\n const dis = ds.clients.get(id.client)\n return dis !== undefined && findIndexDS(dis, id.clock) !== null\n}\n\n/**\n * @param {DeleteSet} ds\n *\n * @private\n * @function\n */\nexport const sortAndMergeDeleteSet = ds => {\n ds.clients.forEach(dels => {\n dels.sort((a, b) => a.clock - b.clock)\n // merge items without filtering or splicing the array\n // i is the current pointer\n // j refers to the current insert position for the pointed item\n // try to merge dels[i] into dels[j-1] or set dels[j]=dels[i]\n let i, j\n for (i = 1, j = 1; i < dels.length; i++) {\n const left = dels[j - 1]\n const right = dels[i]\n if (left.clock + left.len >= right.clock) {\n left.len = math.max(left.len, right.clock + right.len - left.clock)\n } else {\n if (j < i) {\n dels[j] = right\n }\n j++\n }\n }\n dels.length = j\n })\n}\n\n/**\n * @param {Array<DeleteSet>} dss\n * @return {DeleteSet} A fresh DeleteSet\n */\nexport const mergeDeleteSets = dss => {\n const merged = new DeleteSet()\n for (let dssI = 0; dssI < dss.length; dssI++) {\n dss[dssI].clients.forEach((delsLeft, client) => {\n if (!merged.clients.has(client)) {\n // Write all missing keys from current ds and all following.\n // If merged already contains `client` current ds has already been added.\n /**\n * @type {Array<DeleteItem>}\n */\n const dels = delsLeft.slice()\n for (let i = dssI + 1; i < dss.length; i++) {\n array.appendTo(dels, dss[i].clients.get(client) || [])\n }\n merged.clients.set(client, dels)\n }\n })\n }\n sortAndMergeDeleteSet(merged)\n return merged\n}\n\n/**\n * @param {DeleteSet} ds\n * @param {number} client\n * @param {number} clock\n * @param {number} length\n *\n * @private\n * @function\n */\nexport const addToDeleteSet = (ds, client, clock, length) => {\n map.setIfUndefined(ds.clients, client, () => /** @type {Array<DeleteItem>} */ ([])).push(new DeleteItem(clock, length))\n}\n\nexport const createDeleteSet = () => new DeleteSet()\n\n/**\n * @param {StructStore} ss\n * @return {DeleteSet} Merged and sorted DeleteSet\n *\n * @private\n * @function\n */\nexport const createDeleteSetFromStructStore = ss => {\n const ds = createDeleteSet()\n ss.clients.forEach((structs, client) => {\n /**\n * @type {Array<DeleteItem>}\n */\n const dsitems = []\n for (let i = 0; i < structs.length; i++) {\n const struct = structs[i]\n if (struct.deleted) {\n const clock = struct.id.clock\n let len = struct.length\n if (i + 1 < structs.length) {\n for (let next = structs[i + 1]; i + 1 < structs.length && next.deleted; next = structs[++i + 1]) {\n len += next.length\n }\n }\n dsitems.push(new DeleteItem(clock, len))\n }\n }\n if (dsitems.length > 0) {\n ds.clients.set(client, dsitems)\n }\n })\n return ds\n}\n\n/**\n * @param {DSEncoderV1 | DSEncoderV2} encoder\n * @param {DeleteSet} ds\n *\n * @private\n * @function\n */\nexport const writeDeleteSet = (encoder, ds) => {\n encoding.writeVarUint(encoder.restEncoder, ds.clients.size)\n\n // Ensure that the delete set is written in a deterministic order\n array.from(ds.clients.entries())\n .sort((a, b) => b[0] - a[0])\n .forEach(([client, dsitems]) => {\n encoder.resetDsCurVal()\n encoding.writeVarUint(encoder.restEncoder, client)\n const len = dsitems.length\n encoding.writeVarUint(encoder.restEncoder, len)\n for (let i = 0; i < len; i++) {\n const item = dsitems[i]\n encoder.writeDsClock(item.clock)\n encoder.writeDsLen(item.len)\n }\n })\n}\n\n/**\n * @param {DSDecoderV1 | DSDecoderV2} decoder\n * @return {DeleteSet}\n *\n * @private\n * @function\n */\nexport const readDeleteSet = decoder => {\n const ds = new DeleteSet()\n const numClients = decoding.readVarUint(decoder.restDecoder)\n for (let i = 0; i < numClients; i++) {\n decoder.resetDsCurVal()\n const client = decoding.readVarUint(decoder.restDecoder)\n const numberOfDeletes = decoding.readVarUint(decoder.restDecoder)\n if (numberOfDeletes > 0) {\n const dsField = map.setIfUndefined(ds.clients, client, () => /** @type {Array<DeleteItem>} */ ([]))\n for (let i = 0; i < numberOfDeletes; i++) {\n dsField.push(new DeleteItem(decoder.readDsClock(), decoder.readDsLen()))\n }\n }\n }\n return ds\n}\n\n/**\n * @todo YDecoder also contains references to String and other Decoders. Would make sense to exchange YDecoder.toUint8Array for YDecoder.DsToUint8Array()..\n */\n\n/**\n * @param {DSDecoderV1 | DSDecoderV2} decoder\n * @param {Transaction} transaction\n * @param {StructStore} store\n * @return {Uint8Array|null} Returns a v2 update containing all deletes that couldn't be applied yet; or null if all deletes were applied successfully.\n *\n * @private\n * @function\n */\nexport const readAndApplyDeleteSet = (decoder, transaction, store) => {\n const unappliedDS = new DeleteSet()\n const numClients = decoding.readVarUint(decoder.restDecoder)\n for (let i = 0; i < numClients; i++) {\n decoder.resetDsCurVal()\n const client = decoding.readVarUint(decoder.restDecoder)\n const numberOfDeletes = decoding.readVarUint(decoder.restDecoder)\n const structs = store.clients.get(client) || []\n const state = getState(store, client)\n for (let i = 0; i < numberOfDeletes; i++) {\n const clock = decoder.readDsClock()\n const clockEnd = clock + decoder.readDsLen()\n if (clock < state) {\n if (state < clockEnd) {\n addToDeleteSet(unappliedDS, client, state, clockEnd - state)\n }\n let index = findIndexSS(structs, clock)\n /**\n * We can ignore the case of GC and Delete structs, because we are going to skip them\n * @type {Item}\n */\n // @ts-ignore\n let struct = structs[index]\n // split the first item if necessary\n if (!struct.deleted && struct.id.clock < clock) {\n structs.splice(index + 1, 0, splitItem(transaction, struct, clock - struct.id.clock))\n index++ // increase we now want to use the next struct\n }\n while (index < structs.length) {\n // @ts-ignore\n struct = structs[index++]\n if (struct.id.clock < clockEnd) {\n if (!struct.deleted) {\n if (clockEnd < struct.id.clock + struct.length) {\n structs.splice(index, 0, splitItem(transaction, struct, clockEnd - struct.id.clock))\n }\n struct.delete(transaction)\n }\n } else {\n break\n }\n }\n } else {\n addToDeleteSet(unappliedDS, client, clock, clockEnd - clock)\n }\n }\n }\n if (unappliedDS.clients.size > 0) {\n const ds = new UpdateEncoderV2()\n encoding.writeVarUint(ds.restEncoder, 0) // encode 0 structs\n writeDeleteSet(ds, unappliedDS)\n return ds.toUint8Array()\n }\n return null\n}\n\n/**\n * @param {DeleteSet} ds1\n * @param {DeleteSet} ds2\n */\nexport const equalDeleteSets = (ds1, ds2) => {\n if (ds1.clients.size !== ds2.clients.size) return false\n for (const [client, deleteItems1] of ds1.clients.entries()) {\n const deleteItems2 = /** @type {Array<import('../internals.js').DeleteItem>} */ (ds2.clients.get(client))\n if (deleteItems2 === undefined || deleteItems1.length !== deleteItems2.length) return false\n for (let i = 0; i < deleteItems1.length; i++) {\n const di1 = deleteItems1[i]\n const di2 = deleteItems2[i]\n if (di1.clock !== di2.clock || di1.len !== di2.len) {\n return false\n }\n }\n }\n return true\n}\n","/**\n * @module Y\n */\n\nimport {\n StructStore,\n AbstractType,\n YArray,\n YText,\n YMap,\n YXmlElement,\n YXmlFragment,\n transact,\n ContentDoc, Item, Transaction, YEvent // eslint-disable-line\n} from '../internals.js'\n\nimport { ObservableV2 } from 'lib0/observable'\nimport * as random from 'lib0/random'\nimport * as map from 'lib0/map'\nimport * as array from 'lib0/array'\nimport * as promise from 'lib0/promise'\n\nexport const generateNewClientId = random.uint32\n\n/**\n * @typedef {Object} DocOpts\n * @property {boolean} [DocOpts.gc=true] Disable garbage collection (default: gc=true)\n * @property {function(Item):boolean} [DocOpts.gcFilter] Will be called before an Item is garbage collected. Return false to keep the Item.\n * @property {string} [DocOpts.guid] Define a globally unique identifier for this document\n * @property {string | null} [DocOpts.collectionid] Associate this document with a collection. This only plays a role if your provider has a concept of collection.\n * @property {any} [DocOpts.meta] Any kind of meta information you want to associate with this document. If this is a subdocument, remote peers will store the meta information as well.\n * @property {boolean} [DocOpts.autoLoad] If a subdocument, automatically load document. If this is a subdocument, remote peers will load the document as well automatically.\n * @property {boolean} [DocOpts.shouldLoad] Whether the document should be synced by the provider now. This is toggled to true when you call ydoc.load()\n */\n\n/**\n * @typedef {Object} DocEvents\n * @property {function(Doc):void} DocEvents.destroy\n * @property {function(Doc):void} DocEvents.load\n * @property {function(boolean, Doc):void} DocEvents.sync\n * @property {function(Uint8Array, any, Doc, Transaction):void} DocEvents.update\n * @property {function(Uint8Array, any, Doc, Transaction):void} DocEvents.updateV2\n * @property {function(Doc):void} DocEvents.beforeAllTransactions\n * @property {function(Transaction, Doc):void} DocEvents.beforeTransaction\n * @property {function(Transaction, Doc):void} DocEvents.beforeObserverCalls\n * @property {function(Transaction, Doc):void} DocEvents.afterTransaction\n * @property {function(Transaction, Doc):void} DocEvents.afterTransactionCleanup\n * @property {function(Doc, Array<Transaction>):void} DocEvents.afterAllTransactions\n * @property {function({ loaded: Set<Doc>, added: Set<Doc>, removed: Set<Doc> }, Doc, Transaction):void} DocEvents.subdocs\n */\n\n/**\n * A Yjs instance handles the state of shared data.\n * @extends ObservableV2<DocEvents>\n */\nexport class Doc extends ObservableV2 {\n /**\n * @param {DocOpts} opts configuration\n */\n constructor ({ guid = random.uuidv4(), collectionid = null, gc = true, gcFilter = () => true, meta = null, autoLoad = false, shouldLoad = true } = {}) {\n super()\n this.gc = gc\n this.gcFilter = gcFilter\n this.clientID = generateNewClientId()\n this.guid = guid\n this.collectionid = collectionid\n /**\n * @type {Map<string, AbstractType<YEvent<any>>>}\n */\n this.share = new Map()\n this.store = new StructStore()\n /**\n * @type {Transaction | null}\n */\n this._transaction = null\n /**\n * @type {Array<Transaction>}\n */\n this._transactionCleanups = []\n /**\n * @type {Set<Doc>}\n */\n this.subdocs = new Set()\n /**\n * If this document is a subdocument - a document integrated into another document - then _item is defined.\n * @type {Item?}\n */\n this._item = null\n this.shouldLoad = shouldLoad\n this.autoLoad = autoLoad\n this.meta = meta\n /**\n * This is set to true when the persistence provider loaded the document from the database or when the `sync` event fires.\n * Note that not all providers implement this feature. Provider authors are encouraged to fire the `load` event when the doc content is loaded from the database.\n *\n * @type {boolean}\n */\n this.isLoaded = false\n /**\n * This is set to true when the connection provider has successfully synced with a backend.\n * Note that when using peer-to-peer providers this event may not provide very useful.\n * Also note that not all providers implement this feature. Provider authors are encouraged to fire\n * the `sync` event when the doc has been synced (with `true` as a parameter) or if connection is\n * lost (with false as a parameter).\n */\n this.isSynced = false\n this.isDestroyed = false\n /**\n * Promise that resolves once the document has been loaded from a persistence provider.\n */\n this.whenLoaded = promise.create(resolve => {\n this.on('load', () => {\n this.isLoaded = true\n resolve(this)\n })\n })\n const provideSyncedPromise = () => promise.create(resolve => {\n /**\n * @param {boolean} isSynced\n */\n const eventHandler = (isSynced) => {\n if (isSynced === undefined || isSynced === true) {\n this.off('sync', eventHandler)\n resolve()\n }\n }\n this.on('sync', eventHandler)\n })\n this.on('sync', isSynced => {\n if (isSynced === false && this.isSynced) {\n this.whenSynced = provideSyncedPromise()\n }\n this.isSynced = isSynced === undefined || isSynced === true\n if (this.isSynced && !this.isLoaded) {\n this.emit('load', [this])\n }\n })\n /**\n * Promise that resolves once the document has been synced with a backend.\n * This promise is recreated when the connection is lost.\n * Note the documentation about the `isSynced` property.\n */\n this.whenSynced = provideSyncedPromise()\n }\n\n /**\n * Notify the parent document that you request to load data into this subdocument (if it is a subdocument).\n *\n * `load()` might be used in the future to request any provider to load the most current data.\n *\n * It is safe to call `load()` multiple times.\n */\n load () {\n const item = this._item\n if (item !== null && !this.shouldLoad) {\n transact(/** @type {any} */ (item.parent).doc, transaction => {\n transaction.subdocsLoaded.add(this)\n }, null, true)\n }\n this.shouldLoad = true\n }\n\n getSubdocs () {\n return this.subdocs\n }\n\n getSubdocGuids () {\n return new Set(array.from(this.subdocs).map(doc => doc.guid))\n }\n\n /**\n * Changes that happen inside of a transaction are bundled. This means that\n * the observer fires _after_ the transaction is finished and that all changes\n * that happened inside of the transaction are sent as one message to the\n * other peers.\n *\n * @template T\n * @param {function(Transaction):T} f The function that should be executed as a transaction\n * @param {any} [origin] Origin of who started the transaction. Will be stored on transaction.origin\n * @return T\n *\n * @public\n */\n transact (f, origin = null) {\n return transact(this, f, origin)\n }\n\n /**\n * Define a shared data type.\n *\n * Multiple calls of `ydoc.get(name, TypeConstructor)` yield the same result\n * and do not overwrite each other. I.e.\n * `ydoc.get(name, Y.Array) === ydoc.get(name, Y.Array)`\n *\n * After this method is called, the type is also available on `ydoc.share.get(name)`.\n *\n * *Best Practices:*\n * Define all types right after the Y.Doc instance is created and store them in a separate object.\n * Also use the typed methods `getText(name)`, `getArray(name)`, ..\n *\n * @template {typeof AbstractType<any>} Type\n * @example\n * const ydoc = new Y.Doc(..)\n * const appState = {\n * document: ydoc.getText('document')\n * comments: ydoc.getArray('comments')\n * }\n *\n * @param {string} name\n * @param {Type} TypeConstructor The constructor of the type definition. E.g. Y.Text, Y.Array, Y.Map, ...\n * @return {InstanceType<Type>} The created type. Constructed with TypeConstructor\n *\n * @public\n */\n get (name, TypeConstructor = /** @type {any} */ (AbstractType)) {\n const type = map.setIfUndefined(this.share, name, () => {\n // @ts-ignore\n const t = new TypeConstructor()\n t._integrate(this, null)\n return t\n })\n const Constr = type.constructor\n if (TypeConstructor !== AbstractType && Constr !== TypeConstructor) {\n if (Constr === AbstractType) {\n // @ts-ignore\n const t = new TypeConstructor()\n t._map = type._map\n type._map.forEach(/** @param {Item?} n */ n => {\n for (; n !== null; n = n.left) {\n // @ts-ignore\n n.parent = t\n }\n })\n t._start = type._start\n for (let n = t._start; n !== null; n = n.right) {\n n.parent = t\n }\n t._length = type._length\n this.share.set(name, t)\n t._integrate(this, null)\n return /** @type {InstanceType<Type>} */ (t)\n } else {\n throw new Error(`Type with the name ${name} has already been defined with a different constructor`)\n }\n }\n return /** @type {InstanceType<Type>} */ (type)\n }\n\n /**\n * @template T\n * @param {string} [name]\n * @return {YArray<T>}\n *\n * @public\n */\n getArray (name = '') {\n return /** @type {YArray<T>} */ (this.get(name, YArray))\n }\n\n /**\n * @param {string} [name]\n * @return {YText}\n *\n * @public\n */\n getText (name = '') {\n return this.get(name, YText)\n }\n\n /**\n * @template T\n * @param {string} [name]\n * @return {YMap<T>}\n *\n * @public\n */\n getMap (name = '') {\n return /** @type {YMap<T>} */ (this.get(name, YMap))\n }\n\n /**\n * @param {string} [name]\n * @return {YXmlElement}\n *\n * @public\n */\n getXmlElement (name = '') {\n return /** @type {YXmlElement<{[key:string]:string}>} */ (this.get(name, YXmlElement))\n }\n\n /**\n * @param {string} [name]\n * @return {YXmlFragment}\n *\n * @public\n */\n getXmlFragment (name = '') {\n return this.get(name, YXmlFragment)\n }\n\n /**\n * Converts the entire document into a js object, recursively traversing each yjs type\n * Doesn't log types that have not been defined (using ydoc.getType(..)).\n *\n * @deprecated Do not use this method and rather call toJSON directly on the shared types.\n *\n * @return {Object<string, any>}\n */\n toJSON () {\n /**\n * @type {Object<string, any>}\n */\n const doc = {}\n\n this.share.forEach((value, key) => {\n doc[key] = value.toJSON()\n })\n\n return doc\n }\n\n /**\n * Emit `destroy` event and unregister all event handlers.\n */\n destroy () {\n this.isDestroyed = true\n array.from(this.subdocs).forEach(subdoc => subdoc.destroy())\n const item = this._item\n if (item !== null) {\n this._item = null\n const content = /** @type {ContentDoc} */ (item.content)\n content.doc = new Doc({ guid: this.guid, ...content.opts, shouldLoad: false })\n content.doc._item = item\n transact(/** @type {any} */ (item).parent.doc, transaction => {\n const doc = content.doc\n if (!item.deleted) {\n transaction.subdocsAdded.add(doc)\n }\n transaction.subdocsRemoved.add(this)\n }, null, true)\n }\n // @ts-ignore\n this.emit('destroyed', [true]) // DEPRECATED!\n this.emit('destroy', [this])\n super.destroy()\n }\n}\n","import * as buffer from 'lib0/buffer'\nimport * as decoding from 'lib0/decoding'\nimport {\n ID, createID\n} from '../internals.js'\n\nexport class DSDecoderV1 {\n /**\n * @param {decoding.Decoder} decoder\n */\n constructor (decoder) {\n this.restDecoder = decoder\n }\n\n resetDsCurVal () {\n // nop\n }\n\n /**\n * @return {number}\n */\n readDsClock () {\n return decoding.readVarUint(this.restDecoder)\n }\n\n /**\n * @return {number}\n */\n readDsLen () {\n return decoding.readVarUint(this.restDecoder)\n }\n}\n\nexport class UpdateDecoderV1 extends DSDecoderV1 {\n /**\n * @return {ID}\n */\n readLeftID () {\n return createID(decoding.readVarUint(this.restDecoder), decoding.readVarUint(this.restDecoder))\n }\n\n /**\n * @return {ID}\n */\n readRightID () {\n return createID(decoding.readVarUint(this.restDecoder), decoding.readVarUint(this.restDecoder))\n }\n\n /**\n * Read the next client id.\n * Use this in favor of readID whenever possible to reduce the number of objects created.\n */\n readClient () {\n return decoding.readVarUint(this.restDecoder)\n }\n\n /**\n * @return {number} info An unsigned 8-bit integer\n */\n readInfo () {\n return decoding.readUint8(this.restDecoder)\n }\n\n /**\n * @return {string}\n */\n readString () {\n return decoding.readVarString(this.restDecoder)\n }\n\n /**\n * @return {boolean} isKey\n */\n readParentInfo () {\n return decoding.readVarUint(this.restDecoder) === 1\n }\n\n /**\n * @return {number} info An unsigned 8-bit integer\n */\n readTypeRef () {\n return decoding.readVarUint(this.restDecoder)\n }\n\n /**\n * Write len of a struct - well suited for Opt RLE encoder.\n *\n * @return {number} len\n */\n readLen () {\n return decoding.readVarUint(this.restDecoder)\n }\n\n /**\n * @return {any}\n */\n readAny () {\n return decoding.readAny(this.restDecoder)\n }\n\n /**\n * @return {Uint8Array}\n */\n readBuf () {\n return buffer.copyUint8Array(decoding.readVarUint8Array(this.restDecoder))\n }\n\n /**\n * Legacy implementation uses JSON parse. We use any-decoding in v2.\n *\n * @return {any}\n */\n readJSON () {\n return JSON.parse(decoding.readVarString(this.restDecoder))\n }\n\n /**\n * @return {string}\n */\n readKey () {\n return decoding.readVarString(this.restDecoder)\n }\n}\n\nexport class DSDecoderV2 {\n /**\n * @param {decoding.Decoder} decoder\n */\n constructor (decoder) {\n /**\n * @private\n */\n this.dsCurrVal = 0\n this.restDecoder = decoder\n }\n\n resetDsCurVal () {\n this.dsCurrVal = 0\n }\n\n /**\n * @return {number}\n */\n readDsClock () {\n this.dsCurrVal += decoding.readVarUint(this.restDecoder)\n return this.dsCurrVal\n }\n\n /**\n * @return {number}\n */\n readDsLen () {\n const diff = decoding.readVarUint(this.restDecoder) + 1\n this.dsCurrVal += diff\n return diff\n }\n}\n\nexport class UpdateDecoderV2 extends DSDecoderV2 {\n /**\n * @param {decoding.Decoder} decoder\n */\n constructor (decoder) {\n super(decoder)\n /**\n * List of cached keys. If the keys[id] does not exist, we read a new key\n * from stringEncoder and push it to keys.\n *\n * @type {Array<string>}\n */\n this.keys = []\n decoding.readVarUint(decoder) // read feature flag - currently unused\n this.keyClockDecoder = new decoding.IntDiffOptRleDecoder(decoding.readVarUint8Array(decoder))\n this.clientDecoder = new decoding.UintOptRleDecoder(decoding.readVarUint8Array(decoder))\n this.leftClockDecoder = new decoding.IntDiffOptRleDecoder(decoding.readVarUint8Array(decoder))\n this.rightClockDecoder = new decoding.IntDiffOptRleDecoder(decoding.readVarUint8Array(decoder))\n this.infoDecoder = new decoding.RleDecoder(decoding.readVarUint8Array(decoder), decoding.readUint8)\n this.stringDecoder = new decoding.StringDecoder(decoding.readVarUint8Array(decoder))\n this.parentInfoDecoder = new decoding.RleDecoder(decoding.readVarUint8Array(decoder), decoding.readUint8)\n this.typeRefDecoder = new decoding.UintOptRleDecoder(decoding.readVarUint8Array(decoder))\n this.lenDecoder = new decoding.UintOptRleDecoder(decoding.readVarUint8Array(decoder))\n }\n\n /**\n * @return {ID}\n */\n readLeftID () {\n return new ID(this.clientDecoder.read(), this.leftClockDecoder.read())\n }\n\n /**\n * @return {ID}\n */\n readRightID () {\n return new ID(this.clientDecoder.read(), this.rightClockDecoder.read())\n }\n\n /**\n * Read the next client id.\n * Use this in favor of readID whenever possible to reduce the number of objects created.\n */\n readClient () {\n return this.clientDecoder.read()\n }\n\n /**\n * @return {number} info An unsigned 8-bit integer\n */\n readInfo () {\n return /** @type {number} */ (this.infoDecoder.read())\n }\n\n /**\n * @return {string}\n */\n readString () {\n return this.stringDecoder.read()\n }\n\n /**\n * @return {boolean}\n */\n readParentInfo () {\n return this.parentInfoDecoder.read() === 1\n }\n\n /**\n * @return {number} An unsigned 8-bit integer\n */\n readTypeRef () {\n return this.typeRefDecoder.read()\n }\n\n /**\n * Write len of a struct - well suited for Opt RLE encoder.\n *\n * @return {number}\n */\n readLen () {\n return this.lenDecoder.read()\n }\n\n /**\n * @return {any}\n */\n readAny () {\n return decoding.readAny(this.restDecoder)\n }\n\n /**\n * @return {Uint8Array}\n */\n readBuf () {\n return decoding.readVarUint8Array(this.restDecoder)\n }\n\n /**\n * This is mainly here for legacy purposes.\n *\n * Initial we incoded objects using JSON. Now we use the much faster lib0/any-encoder. This method mainly exists for legacy purposes for the v1 encoder.\n *\n * @return {any}\n */\n readJSON () {\n return decoding.readAny(this.restDecoder)\n }\n\n /**\n * @return {string}\n */\n readKey () {\n const keyClock = this.keyClockDecoder.read()\n if (keyClock < this.keys.length) {\n return this.keys[keyClock]\n } else {\n const key = this.stringDecoder.read()\n this.keys.push(key)\n return key\n }\n }\n}\n","import * as error from 'lib0/error'\nimport * as encoding from 'lib0/encoding'\n\nimport {\n ID // eslint-disable-line\n} from '../internals.js'\n\nexport class DSEncoderV1 {\n constructor () {\n this.restEncoder = encoding.createEncoder()\n }\n\n toUint8Array () {\n return encoding.toUint8Array(this.restEncoder)\n }\n\n resetDsCurVal () {\n // nop\n }\n\n /**\n * @param {number} clock\n */\n writeDsClock (clock) {\n encoding.writeVarUint(this.restEncoder, clock)\n }\n\n /**\n * @param {number} len\n */\n writeDsLen (len) {\n encoding.writeVarUint(this.restEncoder, len)\n }\n}\n\nexport class UpdateEncoderV1 extends DSEncoderV1 {\n /**\n * @param {ID} id\n */\n writeLeftID (id) {\n encoding.writeVarUint(this.restEncoder, id.client)\n encoding.writeVarUint(this.restEncoder, id.clock)\n }\n\n /**\n * @param {ID} id\n */\n writeRightID (id) {\n encoding.writeVarUint(this.restEncoder, id.client)\n encoding.writeVarUint(this.restEncoder, id.clock)\n }\n\n /**\n * Use writeClient and writeClock instead of writeID if possible.\n * @param {number} client\n */\n writeClient (client) {\n encoding.writeVarUint(this.restEncoder, client)\n }\n\n /**\n * @param {number} info An unsigned 8-bit integer\n */\n writeInfo (info) {\n encoding.writeUint8(this.restEncoder, info)\n }\n\n /**\n * @param {string} s\n */\n writeString (s) {\n encoding.writeVarString(this.restEncoder, s)\n }\n\n /**\n * @param {boolean} isYKey\n */\n writeParentInfo (isYKey) {\n encoding.writeVarUint(this.restEncoder, isYKey ? 1 : 0)\n }\n\n /**\n * @param {number} info An unsigned 8-bit integer\n */\n writeTypeRef (info) {\n encoding.writeVarUint(this.restEncoder, info)\n }\n\n /**\n * Write len of a struct - well suited for Opt RLE encoder.\n *\n * @param {number} len\n */\n writeLen (len) {\n encoding.writeVarUint(this.restEncoder, len)\n }\n\n /**\n * @param {any} any\n */\n writeAny (any) {\n encoding.writeAny(this.restEncoder, any)\n }\n\n /**\n * @param {Uint8Array} buf\n */\n writeBuf (buf) {\n encoding.writeVarUint8Array(this.restEncoder, buf)\n }\n\n /**\n * @param {any} embed\n */\n writeJSON (embed) {\n encoding.writeVarString(this.restEncoder, JSON.stringify(embed))\n }\n\n /**\n * @param {string} key\n */\n writeKey (key) {\n encoding.writeVarString(this.restEncoder, key)\n }\n}\n\nexport class DSEncoderV2 {\n constructor () {\n this.restEncoder = encoding.createEncoder() // encodes all the rest / non-optimized\n this.dsCurrVal = 0\n }\n\n toUint8Array () {\n return encoding.toUint8Array(this.restEncoder)\n }\n\n resetDsCurVal () {\n this.dsCurrVal = 0\n }\n\n /**\n * @param {number} clock\n */\n writeDsClock (clock) {\n const diff = clock - this.dsCurrVal\n this.dsCurrVal = clock\n encoding.writeVarUint(this.restEncoder, diff)\n }\n\n /**\n * @param {number} len\n */\n writeDsLen (len) {\n if (len === 0) {\n error.unexpectedCase()\n }\n encoding.writeVarUint(this.restEncoder, len - 1)\n this.dsCurrVal += len\n }\n}\n\nexport class UpdateEncoderV2 extends DSEncoderV2 {\n constructor () {\n super()\n /**\n * @type {Map<string,number>}\n */\n this.keyMap = new Map()\n /**\n * Refers to the next unique key-identifier to me used.\n * See writeKey method for more information.\n *\n * @type {number}\n */\n this.keyClock = 0\n this.keyClockEncoder = new encoding.IntDiffOptRleEncoder()\n this.clientEncoder = new encoding.UintOptRleEncoder()\n this.leftClockEncoder = new encoding.IntDiffOptRleEncoder()\n this.rightClockEncoder = new encoding.IntDiffOptRleEncoder()\n this.infoEncoder = new encoding.RleEncoder(encoding.writeUint8)\n this.stringEncoder = new encoding.StringEncoder()\n this.parentInfoEncoder = new encoding.RleEncoder(encoding.writeUint8)\n this.typeRefEncoder = new encoding.UintOptRleEncoder()\n this.lenEncoder = new encoding.UintOptRleEncoder()\n }\n\n toUint8Array () {\n const encoder = encoding.createEncoder()\n encoding.writeVarUint(encoder, 0) // this is a feature flag that we might use in the future\n encoding.writeVarUint8Array(encoder, this.keyClockEncoder.toUint8Array())\n encoding.writeVarUint8Array(encoder, this.clientEncoder.toUint8Array())\n encoding.writeVarUint8Array(encoder, this.leftClockEncoder.toUint8Array())\n encoding.writeVarUint8Array(encoder, this.rightClockEncoder.toUint8Array())\n encoding.writeVarUint8Array(encoder, encoding.toUint8Array(this.infoEncoder))\n encoding.writeVarUint8Array(encoder, this.stringEncoder.toUint8Array())\n encoding.writeVarUint8Array(encoder, encoding.toUint8Array(this.parentInfoEncoder))\n encoding.writeVarUint8Array(encoder, this.typeRefEncoder.toUint8Array())\n encoding.writeVarUint8Array(encoder, this.lenEncoder.toUint8Array())\n // @note The rest encoder is appended! (note the missing var)\n encoding.writeUint8Array(encoder, encoding.toUint8Array(this.restEncoder))\n return encoding.toUint8Array(encoder)\n }\n\n /**\n * @param {ID} id\n */\n writeLeftID (id) {\n this.clientEncoder.write(id.client)\n this.leftClockEncoder.write(id.clock)\n }\n\n /**\n * @param {ID} id\n */\n writeRightID (id) {\n this.clientEncoder.write(id.client)\n this.rightClockEncoder.write(id.clock)\n }\n\n /**\n * @param {number} client\n */\n writeClient (client) {\n this.clientEncoder.write(client)\n }\n\n /**\n * @param {number} info An unsigned 8-bit integer\n */\n writeInfo (info) {\n this.infoEncoder.write(info)\n }\n\n /**\n * @param {string} s\n */\n writeString (s) {\n this.stringEncoder.write(s)\n }\n\n /**\n * @param {boolean} isYKey\n */\n writeParentInfo (isYKey) {\n this.parentInfoEncoder.write(isYKey ? 1 : 0)\n }\n\n /**\n * @param {number} info An unsigned 8-bit integer\n */\n writeTypeRef (info) {\n this.typeRefEncoder.write(info)\n }\n\n /**\n * Write len of a struct - well suited for Opt RLE encoder.\n *\n * @param {number} len\n */\n writeLen (len) {\n this.lenEncoder.write(len)\n }\n\n /**\n * @param {any} any\n */\n writeAny (any) {\n encoding.writeAny(this.restEncoder, any)\n }\n\n /**\n * @param {Uint8Array} buf\n */\n writeBuf (buf) {\n encoding.writeVarUint8Array(this.restEncoder, buf)\n }\n\n /**\n * This is mainly here for legacy purposes.\n *\n * Initial we incoded objects using JSON. Now we use the much faster lib0/any-encoder. This method mainly exists for legacy purposes for the v1 encoder.\n *\n * @param {any} embed\n */\n writeJSON (embed) {\n encoding.writeAny(this.restEncoder, embed)\n }\n\n /**\n * Property keys are often reused. For example, in y-prosemirror the key `bold` might\n * occur very often. For a 3d application, the key `position` might occur very often.\n *\n * We cache these keys in a Map and refer to them via a unique number.\n *\n * @param {string} key\n */\n writeKey (key) {\n const clock = this.keyMap.get(key)\n if (clock === undefined) {\n /**\n * @todo uncomment to introduce this feature finally\n *\n * Background. The ContentFormat object was always encoded using writeKey, but the decoder used to use readString.\n * Furthermore, I forgot to set the keyclock. So everything was working fine.\n *\n * However, this feature here is basically useless as it is not being used (it actually only consumes extra memory).\n *\n * I don't know yet how to reintroduce this feature..\n *\n * Older clients won't be able to read updates when we reintroduce this feature. So this should probably be done using a flag.\n *\n */\n // this.keyMap.set(key, this.keyClock)\n this.keyClockEncoder.write(this.keyClock++)\n this.stringEncoder.write(key)\n } else {\n this.keyClockEncoder.write(clock)\n }\n }\n}\n","/**\n * @module encoding\n */\n/*\n * We use the first five bits in the info flag for determining the type of the struct.\n *\n * 0: GC\n * 1: Item with Deleted content\n * 2: Item with JSON content\n * 3: Item with Binary content\n * 4: Item with String content\n * 5: Item with Embed content (for richtext content)\n * 6: Item with Format content (a formatting marker for richtext content)\n * 7: Item with Type\n */\n\nimport {\n findIndexSS,\n getState,\n createID,\n getStateVector,\n readAndApplyDeleteSet,\n writeDeleteSet,\n createDeleteSetFromStructStore,\n transact,\n readItemContent,\n UpdateDecoderV1,\n UpdateDecoderV2,\n UpdateEncoderV1,\n UpdateEncoderV2,\n DSEncoderV2,\n DSDecoderV1,\n DSEncoderV1,\n mergeUpdates,\n mergeUpdatesV2,\n Skip,\n diffUpdateV2,\n convertUpdateFormatV2ToV1,\n DSDecoderV2, Doc, Transaction, GC, Item, StructStore // eslint-disable-line\n} from '../internals.js'\n\nimport * as encoding from 'lib0/encoding'\nimport * as decoding from 'lib0/decoding'\nimport * as binary from 'lib0/binary'\nimport * as map from 'lib0/map'\nimport * as math from 'lib0/math'\nimport * as array from 'lib0/array'\n\n/**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {Array<GC|Item>} structs All structs by `client`\n * @param {number} client\n * @param {number} clock write structs starting with `ID(client,clock)`\n *\n * @function\n */\nconst writeStructs = (encoder, structs, client, clock) => {\n // write first id\n clock = math.max(clock, structs[0].id.clock) // make sure the first id exists\n const startNewStructs = findIndexSS(structs, clock)\n // write # encoded structs\n encoding.writeVarUint(encoder.restEncoder, structs.length - startNewStructs)\n encoder.writeClient(client)\n encoding.writeVarUint(encoder.restEncoder, clock)\n const firstStruct = structs[startNewStructs]\n // write first struct with an offset\n firstStruct.write(encoder, clock - firstStruct.id.clock)\n for (let i = startNewStructs + 1; i < structs.length; i++) {\n structs[i].write(encoder, 0)\n }\n}\n\n/**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {StructStore} store\n * @param {Map<number,number>} _sm\n *\n * @private\n * @function\n */\nexport const writeClientsStructs = (encoder, store, _sm) => {\n // we filter all valid _sm entries into sm\n const sm = new Map()\n _sm.forEach((clock, client) => {\n // only write if new structs are available\n if (getState(store, client) > clock) {\n sm.set(client, clock)\n }\n })\n getStateVector(store).forEach((_clock, client) => {\n if (!_sm.has(client)) {\n sm.set(client, 0)\n }\n })\n // write # states that were updated\n encoding.writeVarUint(encoder.restEncoder, sm.size)\n // Write items with higher client ids first\n // This heavily improves the conflict algorithm.\n array.from(sm.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => {\n writeStructs(encoder, /** @type {Array<GC|Item>} */ (store.clients.get(client)), client, clock)\n })\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder The decoder object to read data from.\n * @param {Doc} doc\n * @return {Map<number, { i: number, refs: Array<Item | GC> }>}\n *\n * @private\n * @function\n */\nexport const readClientsStructRefs = (decoder, doc) => {\n /**\n * @type {Map<number, { i: number, refs: Array<Item | GC> }>}\n */\n const clientRefs = map.create()\n const numOfStateUpdates = decoding.readVarUint(decoder.restDecoder)\n for (let i = 0; i < numOfStateUpdates; i++) {\n const numberOfStructs = decoding.readVarUint(decoder.restDecoder)\n /**\n * @type {Array<GC|Item>}\n */\n const refs = new Array(numberOfStructs)\n const client = decoder.readClient()\n let clock = decoding.readVarUint(decoder.restDecoder)\n // const start = performance.now()\n clientRefs.set(client, { i: 0, refs })\n for (let i = 0; i < numberOfStructs; i++) {\n const info = decoder.readInfo()\n switch (binary.BITS5 & info) {\n case 0: { // GC\n const len = decoder.readLen()\n refs[i] = new GC(createID(client, clock), len)\n clock += len\n break\n }\n case 10: { // Skip Struct (nothing to apply)\n // @todo we could reduce the amount of checks by adding Skip struct to clientRefs so we know that something is missing.\n const len = decoding.readVarUint(decoder.restDecoder)\n refs[i] = new Skip(createID(client, clock), len)\n clock += len\n break\n }\n default: { // Item with content\n /**\n * The optimized implementation doesn't use any variables because inlining variables is faster.\n * Below a non-optimized version is shown that implements the basic algorithm with\n * a few comments\n */\n const cantCopyParentInfo = (info & (binary.BIT7 | binary.BIT8)) === 0\n // If parent = null and neither left nor right are defined, then we know that `parent` is child of `y`\n // and we read the next string as parentYKey.\n // It indicates how we store/retrieve parent from `y.share`\n // @type {string|null}\n const struct = new Item(\n createID(client, clock),\n null, // left\n (info & binary.BIT8) === binary.BIT8 ? decoder.readLeftID() : null, // origin\n null, // right\n (info & binary.BIT7) === binary.BIT7 ? decoder.readRightID() : null, // right origin\n cantCopyParentInfo ? (decoder.readParentInfo() ? doc.get(decoder.readString()) : decoder.readLeftID()) : null, // parent\n cantCopyParentInfo && (info & binary.BIT6) === binary.BIT6 ? decoder.readString() : null, // parentSub\n readItemContent(decoder, info) // item content\n )\n /* A non-optimized implementation of the above algorithm:\n\n // The item that was originally to the left of this item.\n const origin = (info & binary.BIT8) === binary.BIT8 ? decoder.readLeftID() : null\n // The item that was originally to the right of this item.\n const rightOrigin = (info & binary.BIT7) === binary.BIT7 ? decoder.readRightID() : null\n const cantCopyParentInfo = (info & (binary.BIT7 | binary.BIT8)) === 0\n const hasParentYKey = cantCopyParentInfo ? decoder.readParentInfo() : false\n // If parent = null and neither left nor right are defined, then we know that `parent` is child of `y`\n // and we read the next string as parentYKey.\n // It indicates how we store/retrieve parent from `y.share`\n // @type {string|null}\n const parentYKey = cantCopyParentInfo && hasParentYKey ? decoder.readString() : null\n\n const struct = new Item(\n createID(client, clock),\n null, // left\n origin, // origin\n null, // right\n rightOrigin, // right origin\n cantCopyParentInfo && !hasParentYKey ? decoder.readLeftID() : (parentYKey !== null ? doc.get(parentYKey) : null), // parent\n cantCopyParentInfo && (info & binary.BIT6) === binary.BIT6 ? decoder.readString() : null, // parentSub\n readItemContent(decoder, info) // item content\n )\n */\n refs[i] = struct\n clock += struct.length\n }\n }\n }\n // console.log('time to read: ', performance.now() - start) // @todo remove\n }\n return clientRefs\n}\n\n/**\n * Resume computing structs generated by struct readers.\n *\n * While there is something to do, we integrate structs in this order\n * 1. top element on stack, if stack is not empty\n * 2. next element from current struct reader (if empty, use next struct reader)\n *\n * If struct causally depends on another struct (ref.missing), we put next reader of\n * `ref.id.client` on top of stack.\n *\n * At some point we find a struct that has no causal dependencies,\n * then we start emptying the stack.\n *\n * It is not possible to have circles: i.e. struct1 (from client1) depends on struct2 (from client2)\n * depends on struct3 (from client1). Therefore the max stack size is equal to `structReaders.length`.\n *\n * This method is implemented in a way so that we can resume computation if this update\n * causally depends on another update.\n *\n * @param {Transaction} transaction\n * @param {StructStore} store\n * @param {Map<number, { i: number, refs: (GC | Item)[] }>} clientsStructRefs\n * @return { null | { update: Uint8Array, missing: Map<number,number> } }\n *\n * @private\n * @function\n */\nconst integrateStructs = (transaction, store, clientsStructRefs) => {\n /**\n * @type {Array<Item | GC>}\n */\n const stack = []\n // sort them so that we take the higher id first, in case of conflicts the lower id will probably not conflict with the id from the higher user.\n let clientsStructRefsIds = array.from(clientsStructRefs.keys()).sort((a, b) => a - b)\n if (clientsStructRefsIds.length === 0) {\n return null\n }\n const getNextStructTarget = () => {\n if (clientsStructRefsIds.length === 0) {\n return null\n }\n let nextStructsTarget = /** @type {{i:number,refs:Array<GC|Item>}} */ (clientsStructRefs.get(clientsStructRefsIds[clientsStructRefsIds.length - 1]))\n while (nextStructsTarget.refs.length === nextStructsTarget.i) {\n clientsStructRefsIds.pop()\n if (clientsStructRefsIds.length > 0) {\n nextStructsTarget = /** @type {{i:number,refs:Array<GC|Item>}} */ (clientsStructRefs.get(clientsStructRefsIds[clientsStructRefsIds.length - 1]))\n } else {\n return null\n }\n }\n return nextStructsTarget\n }\n let curStructsTarget = getNextStructTarget()\n if (curStructsTarget === null) {\n return null\n }\n\n /**\n * @type {StructStore}\n */\n const restStructs = new StructStore()\n const missingSV = new Map()\n /**\n * @param {number} client\n * @param {number} clock\n */\n const updateMissingSv = (client, clock) => {\n const mclock = missingSV.get(client)\n if (mclock == null || mclock > clock) {\n missingSV.set(client, clock)\n }\n }\n /**\n * @type {GC|Item}\n */\n let stackHead = /** @type {any} */ (curStructsTarget).refs[/** @type {any} */ (curStructsTarget).i++]\n // caching the state because it is used very often\n const state = new Map()\n\n const addStackToRestSS = () => {\n for (const item of stack) {\n const client = item.id.client\n const inapplicableItems = clientsStructRefs.get(client)\n if (inapplicableItems) {\n // decrement because we weren't able to apply previous operation\n inapplicableItems.i--\n restStructs.clients.set(client, inapplicableItems.refs.slice(inapplicableItems.i))\n clientsStructRefs.delete(client)\n inapplicableItems.i = 0\n inapplicableItems.refs = []\n } else {\n // item was the last item on clientsStructRefs and the field was already cleared. Add item to restStructs and continue\n restStructs.clients.set(client, [item])\n }\n // remove client from clientsStructRefsIds to prevent users from applying the same update again\n clientsStructRefsIds = clientsStructRefsIds.filter(c => c !== client)\n }\n stack.length = 0\n }\n\n // iterate over all struct readers until we are done\n while (true) {\n if (stackHead.constructor !== Skip) {\n const localClock = map.setIfUndefined(state, stackHead.id.client, () => getState(store, stackHead.id.client))\n const offset = localClock - stackHead.id.clock\n if (offset < 0) {\n // update from the same client is missing\n stack.push(stackHead)\n updateMissingSv(stackHead.id.client, stackHead.id.clock - 1)\n // hid a dead wall, add all items from stack to restSS\n addStackToRestSS()\n } else {\n const missing = stackHead.getMissing(transaction, store)\n if (missing !== null) {\n stack.push(stackHead)\n // get the struct reader that has the missing struct\n /**\n * @type {{ refs: Array<GC|Item>, i: number }}\n */\n const structRefs = clientsStructRefs.get(/** @type {number} */ (missing)) || { refs: [], i: 0 }\n if (structRefs.refs.length === structRefs.i) {\n // This update message causally depends on another update message that doesn't exist yet\n updateMissingSv(/** @type {number} */ (missing), getState(store, missing))\n addStackToRestSS()\n } else {\n stackHead = structRefs.refs[structRefs.i++]\n continue\n }\n } else if (offset === 0 || offset < stackHead.length) {\n // all fine, apply the stackhead\n stackHead.integrate(transaction, offset)\n state.set(stackHead.id.client, stackHead.id.clock + stackHead.length)\n }\n }\n }\n // iterate to next stackHead\n if (stack.length > 0) {\n stackHead = /** @type {GC|Item} */ (stack.pop())\n } else if (curStructsTarget !== null && curStructsTarget.i < curStructsTarget.refs.length) {\n stackHead = /** @type {GC|Item} */ (curStructsTarget.refs[curStructsTarget.i++])\n } else {\n curStructsTarget = getNextStructTarget()\n if (curStructsTarget === null) {\n // we are done!\n break\n } else {\n stackHead = /** @type {GC|Item} */ (curStructsTarget.refs[curStructsTarget.i++])\n }\n }\n }\n if (restStructs.clients.size > 0) {\n const encoder = new UpdateEncoderV2()\n writeClientsStructs(encoder, restStructs, new Map())\n // write empty deleteset\n // writeDeleteSet(encoder, new DeleteSet())\n encoding.writeVarUint(encoder.restEncoder, 0) // => no need for an extra function call, just write 0 deletes\n return { missing: missingSV, update: encoder.toUint8Array() }\n }\n return null\n}\n\n/**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {Transaction} transaction\n *\n * @private\n * @function\n */\nexport const writeStructsFromTransaction = (encoder, transaction) => writeClientsStructs(encoder, transaction.doc.store, transaction.beforeState)\n\n/**\n * Read and apply a document update.\n *\n * This function has the same effect as `applyUpdate` but accepts a decoder.\n *\n * @param {decoding.Decoder} decoder\n * @param {Doc} ydoc\n * @param {any} [transactionOrigin] This will be stored on `transaction.origin` and `.on('update', (update, origin))`\n * @param {UpdateDecoderV1 | UpdateDecoderV2} [structDecoder]\n *\n * @function\n */\nexport const readUpdateV2 = (decoder, ydoc, transactionOrigin, structDecoder = new UpdateDecoderV2(decoder)) =>\n transact(ydoc, transaction => {\n // force that transaction.local is set to non-local\n transaction.local = false\n let retry = false\n const doc = transaction.doc\n const store = doc.store\n // let start = performance.now()\n const ss = readClientsStructRefs(structDecoder, doc)\n // console.log('time to read structs: ', performance.now() - start) // @todo remove\n // start = performance.now()\n // console.log('time to merge: ', performance.now() - start) // @todo remove\n // start = performance.now()\n const restStructs = integrateStructs(transaction, store, ss)\n const pending = store.pendingStructs\n if (pending) {\n // check if we can apply something\n for (const [client, clock] of pending.missing) {\n if (clock < getState(store, client)) {\n retry = true\n break\n }\n }\n if (restStructs) {\n // merge restStructs into store.pending\n for (const [client, clock] of restStructs.missing) {\n const mclock = pending.missing.get(client)\n if (mclock == null || mclock > clock) {\n pending.missing.set(client, clock)\n }\n }\n pending.update = mergeUpdatesV2([pending.update, restStructs.update])\n }\n } else {\n store.pendingStructs = restStructs\n }\n // console.log('time to integrate: ', performance.now() - start) // @todo remove\n // start = performance.now()\n const dsRest = readAndApplyDeleteSet(structDecoder, transaction, store)\n if (store.pendingDs) {\n // @todo we could make a lower-bound state-vector check as we do above\n const pendingDSUpdate = new UpdateDecoderV2(decoding.createDecoder(store.pendingDs))\n decoding.readVarUint(pendingDSUpdate.restDecoder) // read 0 structs, because we only encode deletes in pendingdsupdate\n const dsRest2 = readAndApplyDeleteSet(pendingDSUpdate, transaction, store)\n if (dsRest && dsRest2) {\n // case 1: ds1 != null && ds2 != null\n store.pendingDs = mergeUpdatesV2([dsRest, dsRest2])\n } else {\n // case 2: ds1 != null\n // case 3: ds2 != null\n // case 4: ds1 == null && ds2 == null\n store.pendingDs = dsRest || dsRest2\n }\n } else {\n // Either dsRest == null && pendingDs == null OR dsRest != null\n store.pendingDs = dsRest\n }\n // console.log('time to cleanup: ', performance.now() - start) // @todo remove\n // start = performance.now()\n\n // console.log('time to resume delete readers: ', performance.now() - start) // @todo remove\n // start = performance.now()\n if (retry) {\n const update = /** @type {{update: Uint8Array}} */ (store.pendingStructs).update\n store.pendingStructs = null\n applyUpdateV2(transaction.doc, update)\n }\n }, transactionOrigin, false)\n\n/**\n * Read and apply a document update.\n *\n * This function has the same effect as `applyUpdate` but accepts a decoder.\n *\n * @param {decoding.Decoder} decoder\n * @param {Doc} ydoc\n * @param {any} [transactionOrigin] This will be stored on `transaction.origin` and `.on('update', (update, origin))`\n *\n * @function\n */\nexport const readUpdate = (decoder, ydoc, transactionOrigin) => readUpdateV2(decoder, ydoc, transactionOrigin, new UpdateDecoderV1(decoder))\n\n/**\n * Apply a document update created by, for example, `y.on('update', update => ..)` or `update = encodeStateAsUpdate()`.\n *\n * This function has the same effect as `readUpdate` but accepts an Uint8Array instead of a Decoder.\n *\n * @param {Doc} ydoc\n * @param {Uint8Array} update\n * @param {any} [transactionOrigin] This will be stored on `transaction.origin` and `.on('update', (update, origin))`\n * @param {typeof UpdateDecoderV1 | typeof UpdateDecoderV2} [YDecoder]\n *\n * @function\n */\nexport const applyUpdateV2 = (ydoc, update, transactionOrigin, YDecoder = UpdateDecoderV2) => {\n const decoder = decoding.createDecoder(update)\n readUpdateV2(decoder, ydoc, transactionOrigin, new YDecoder(decoder))\n}\n\n/**\n * Apply a document update created by, for example, `y.on('update', update => ..)` or `update = encodeStateAsUpdate()`.\n *\n * This function has the same effect as `readUpdate` but accepts an Uint8Array instead of a Decoder.\n *\n * @param {Doc} ydoc\n * @param {Uint8Array} update\n * @param {any} [transactionOrigin] This will be stored on `transaction.origin` and `.on('update', (update, origin))`\n *\n * @function\n */\nexport const applyUpdate = (ydoc, update, transactionOrigin) => applyUpdateV2(ydoc, update, transactionOrigin, UpdateDecoderV1)\n\n/**\n * Write all the document as a single update message. If you specify the state of the remote client (`targetStateVector`) it will\n * only write the operations that are missing.\n *\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {Doc} doc\n * @param {Map<number,number>} [targetStateVector] The state of the target that receives the update. Leave empty to write all known structs\n *\n * @function\n */\nexport const writeStateAsUpdate = (encoder, doc, targetStateVector = new Map()) => {\n writeClientsStructs(encoder, doc.store, targetStateVector)\n writeDeleteSet(encoder, createDeleteSetFromStructStore(doc.store))\n}\n\n/**\n * Write all the document as a single update message that can be applied on the remote document. If you specify the state of the remote client (`targetState`) it will\n * only write the operations that are missing.\n *\n * Use `writeStateAsUpdate` instead if you are working with lib0/encoding.js#Encoder\n *\n * @param {Doc} doc\n * @param {Uint8Array} [encodedTargetStateVector] The state of the target that receives the update. Leave empty to write all known structs\n * @param {UpdateEncoderV1 | UpdateEncoderV2} [encoder]\n * @return {Uint8Array}\n *\n * @function\n */\nexport const encodeStateAsUpdateV2 = (doc, encodedTargetStateVector = new Uint8Array([0]), encoder = new UpdateEncoderV2()) => {\n const targetStateVector = decodeStateVector(encodedTargetStateVector)\n writeStateAsUpdate(encoder, doc, targetStateVector)\n const updates = [encoder.toUint8Array()]\n // also add the pending updates (if there are any)\n if (doc.store.pendingDs) {\n updates.push(doc.store.pendingDs)\n }\n if (doc.store.pendingStructs) {\n updates.push(diffUpdateV2(doc.store.pendingStructs.update, encodedTargetStateVector))\n }\n if (updates.length > 1) {\n if (encoder.constructor === UpdateEncoderV1) {\n return mergeUpdates(updates.map((update, i) => i === 0 ? update : convertUpdateFormatV2ToV1(update)))\n } else if (encoder.constructor === UpdateEncoderV2) {\n return mergeUpdatesV2(updates)\n }\n }\n return updates[0]\n}\n\n/**\n * Write all the document as a single update message that can be applied on the remote document. If you specify the state of the remote client (`targetState`) it will\n * only write the operations that are missing.\n *\n * Use `writeStateAsUpdate` instead if you are working with lib0/encoding.js#Encoder\n *\n * @param {Doc} doc\n * @param {Uint8Array} [encodedTargetStateVector] The state of the target that receives the update. Leave empty to write all known structs\n * @return {Uint8Array}\n *\n * @function\n */\nexport const encodeStateAsUpdate = (doc, encodedTargetStateVector) => encodeStateAsUpdateV2(doc, encodedTargetStateVector, new UpdateEncoderV1())\n\n/**\n * Read state vector from Decoder and return as Map\n *\n * @param {DSDecoderV1 | DSDecoderV2} decoder\n * @return {Map<number,number>} Maps `client` to the number next expected `clock` from that client.\n *\n * @function\n */\nexport const readStateVector = decoder => {\n const ss = new Map()\n const ssLength = decoding.readVarUint(decoder.restDecoder)\n for (let i = 0; i < ssLength; i++) {\n const client = decoding.readVarUint(decoder.restDecoder)\n const clock = decoding.readVarUint(decoder.restDecoder)\n ss.set(client, clock)\n }\n return ss\n}\n\n/**\n * Read decodedState and return State as Map.\n *\n * @param {Uint8Array} decodedState\n * @return {Map<number,number>} Maps `client` to the number next expected `clock` from that client.\n *\n * @function\n */\n// export const decodeStateVectorV2 = decodedState => readStateVector(new DSDecoderV2(decoding.createDecoder(decodedState)))\n\n/**\n * Read decodedState and return State as Map.\n *\n * @param {Uint8Array} decodedState\n * @return {Map<number,number>} Maps `client` to the number next expected `clock` from that client.\n *\n * @function\n */\nexport const decodeStateVector = decodedState => readStateVector(new DSDecoderV1(decoding.createDecoder(decodedState)))\n\n/**\n * @param {DSEncoderV1 | DSEncoderV2} encoder\n * @param {Map<number,number>} sv\n * @function\n */\nexport const writeStateVector = (encoder, sv) => {\n encoding.writeVarUint(encoder.restEncoder, sv.size)\n array.from(sv.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => {\n encoding.writeVarUint(encoder.restEncoder, client) // @todo use a special client decoder that is based on mapping\n encoding.writeVarUint(encoder.restEncoder, clock)\n })\n return encoder\n}\n\n/**\n * @param {DSEncoderV1 | DSEncoderV2} encoder\n * @param {Doc} doc\n *\n * @function\n */\nexport const writeDocumentStateVector = (encoder, doc) => writeStateVector(encoder, getStateVector(doc.store))\n\n/**\n * Encode State as Uint8Array.\n *\n * @param {Doc|Map<number,number>} doc\n * @param {DSEncoderV1 | DSEncoderV2} [encoder]\n * @return {Uint8Array}\n *\n * @function\n */\nexport const encodeStateVectorV2 = (doc, encoder = new DSEncoderV2()) => {\n if (doc instanceof Map) {\n writeStateVector(encoder, doc)\n } else {\n writeDocumentStateVector(encoder, doc)\n }\n return encoder.toUint8Array()\n}\n\n/**\n * Encode State as Uint8Array.\n *\n * @param {Doc|Map<number,number>} doc\n * @return {Uint8Array}\n *\n * @function\n */\nexport const encodeStateVector = doc => encodeStateVectorV2(doc, new DSEncoderV1())\n","import * as f from 'lib0/function'\n\n/**\n * General event handler implementation.\n *\n * @template ARG0, ARG1\n *\n * @private\n */\nexport class EventHandler {\n constructor () {\n /**\n * @type {Array<function(ARG0, ARG1):void>}\n */\n this.l = []\n }\n}\n\n/**\n * @template ARG0,ARG1\n * @returns {EventHandler<ARG0,ARG1>}\n *\n * @private\n * @function\n */\nexport const createEventHandler = () => new EventHandler()\n\n/**\n * Adds an event listener that is called when\n * {@link EventHandler#callEventListeners} is called.\n *\n * @template ARG0,ARG1\n * @param {EventHandler<ARG0,ARG1>} eventHandler\n * @param {function(ARG0,ARG1):void} f The event handler.\n *\n * @private\n * @function\n */\nexport const addEventHandlerListener = (eventHandler, f) =>\n eventHandler.l.push(f)\n\n/**\n * Removes an event listener.\n *\n * @template ARG0,ARG1\n * @param {EventHandler<ARG0,ARG1>} eventHandler\n * @param {function(ARG0,ARG1):void} f The event handler that was added with\n * {@link EventHandler#addEventListener}\n *\n * @private\n * @function\n */\nexport const removeEventHandlerListener = (eventHandler, f) => {\n const l = eventHandler.l\n const len = l.length\n eventHandler.l = l.filter(g => f !== g)\n if (len === eventHandler.l.length) {\n console.error('[yjs] Tried to remove event handler that doesn\\'t exist.')\n }\n}\n\n/**\n * Removes all event listeners.\n * @template ARG0,ARG1\n * @param {EventHandler<ARG0,ARG1>} eventHandler\n *\n * @private\n * @function\n */\nexport const removeAllEventHandlerListeners = eventHandler => {\n eventHandler.l.length = 0\n}\n\n/**\n * Call all event listeners that were added via\n * {@link EventHandler#addEventListener}.\n *\n * @template ARG0,ARG1\n * @param {EventHandler<ARG0,ARG1>} eventHandler\n * @param {ARG0} arg0\n * @param {ARG1} arg1\n *\n * @private\n * @function\n */\nexport const callEventHandlerListeners = (eventHandler, arg0, arg1) =>\n f.callAll(eventHandler.l, [arg0, arg1])\n","import { AbstractType } from '../internals.js' // eslint-disable-line\n\nimport * as decoding from 'lib0/decoding'\nimport * as encoding from 'lib0/encoding'\nimport * as error from 'lib0/error'\n\nexport class ID {\n /**\n * @param {number} client client id\n * @param {number} clock unique per client id, continuous number\n */\n constructor (client, clock) {\n /**\n * Client id\n * @type {number}\n */\n this.client = client\n /**\n * unique per client id, continuous number\n * @type {number}\n */\n this.clock = clock\n }\n}\n\n/**\n * @param {ID | null} a\n * @param {ID | null} b\n * @return {boolean}\n *\n * @function\n */\nexport const compareIDs = (a, b) => a === b || (a !== null && b !== null && a.client === b.client && a.clock === b.clock)\n\n/**\n * @param {number} client\n * @param {number} clock\n *\n * @private\n * @function\n */\nexport const createID = (client, clock) => new ID(client, clock)\n\n/**\n * @param {encoding.Encoder} encoder\n * @param {ID} id\n *\n * @private\n * @function\n */\nexport const writeID = (encoder, id) => {\n encoding.writeVarUint(encoder, id.client)\n encoding.writeVarUint(encoder, id.clock)\n}\n\n/**\n * Read ID.\n * * If first varUint read is 0xFFFFFF a RootID is returned.\n * * Otherwise an ID is returned\n *\n * @param {decoding.Decoder} decoder\n * @return {ID}\n *\n * @private\n * @function\n */\nexport const readID = decoder =>\n createID(decoding.readVarUint(decoder), decoding.readVarUint(decoder))\n\n/**\n * The top types are mapped from y.share.get(keyname) => type.\n * `type` does not store any information about the `keyname`.\n * This function finds the correct `keyname` for `type` and throws otherwise.\n *\n * @param {AbstractType<any>} type\n * @return {string}\n *\n * @private\n * @function\n */\nexport const findRootTypeKey = type => {\n // @ts-ignore _y must be defined, otherwise unexpected case\n for (const [key, value] of type.doc.share.entries()) {\n if (value === type) {\n return key\n }\n }\n throw error.unexpectedCase()\n}\n","import {\n isDeleted,\n createDeleteSetFromStructStore,\n getStateVector,\n getItemCleanStart,\n iterateDeletedStructs,\n writeDeleteSet,\n writeStateVector,\n readDeleteSet,\n readStateVector,\n createDeleteSet,\n createID,\n getState,\n findIndexSS,\n UpdateEncoderV2,\n applyUpdateV2,\n LazyStructReader,\n equalDeleteSets,\n UpdateDecoderV1, UpdateDecoderV2, DSEncoderV1, DSEncoderV2, DSDecoderV1, DSDecoderV2, Transaction, Doc, DeleteSet, Item, // eslint-disable-line\n mergeDeleteSets\n} from '../internals.js'\n\nimport * as map from 'lib0/map'\nimport * as set from 'lib0/set'\nimport * as decoding from 'lib0/decoding'\nimport * as encoding from 'lib0/encoding'\n\nexport class Snapshot {\n /**\n * @param {DeleteSet} ds\n * @param {Map<number,number>} sv state map\n */\n constructor (ds, sv) {\n /**\n * @type {DeleteSet}\n */\n this.ds = ds\n /**\n * State Map\n * @type {Map<number,number>}\n */\n this.sv = sv\n }\n}\n\n/**\n * @param {Snapshot} snap1\n * @param {Snapshot} snap2\n * @return {boolean}\n */\nexport const equalSnapshots = (snap1, snap2) => {\n const ds1 = snap1.ds.clients\n const ds2 = snap2.ds.clients\n const sv1 = snap1.sv\n const sv2 = snap2.sv\n if (sv1.size !== sv2.size || ds1.size !== ds2.size) {\n return false\n }\n for (const [key, value] of sv1.entries()) {\n if (sv2.get(key) !== value) {\n return false\n }\n }\n for (const [client, dsitems1] of ds1.entries()) {\n const dsitems2 = ds2.get(client) || []\n if (dsitems1.length !== dsitems2.length) {\n return false\n }\n for (let i = 0; i < dsitems1.length; i++) {\n const dsitem1 = dsitems1[i]\n const dsitem2 = dsitems2[i]\n if (dsitem1.clock !== dsitem2.clock || dsitem1.len !== dsitem2.len) {\n return false\n }\n }\n }\n return true\n}\n\n/**\n * @param {Snapshot} snapshot\n * @param {DSEncoderV1 | DSEncoderV2} [encoder]\n * @return {Uint8Array}\n */\nexport const encodeSnapshotV2 = (snapshot, encoder = new DSEncoderV2()) => {\n writeDeleteSet(encoder, snapshot.ds)\n writeStateVector(encoder, snapshot.sv)\n return encoder.toUint8Array()\n}\n\n/**\n * @param {Snapshot} snapshot\n * @return {Uint8Array}\n */\nexport const encodeSnapshot = snapshot => encodeSnapshotV2(snapshot, new DSEncoderV1())\n\n/**\n * @param {Uint8Array} buf\n * @param {DSDecoderV1 | DSDecoderV2} [decoder]\n * @return {Snapshot}\n */\nexport const decodeSnapshotV2 = (buf, decoder = new DSDecoderV2(decoding.createDecoder(buf))) => {\n return new Snapshot(readDeleteSet(decoder), readStateVector(decoder))\n}\n\n/**\n * @param {Uint8Array} buf\n * @return {Snapshot}\n */\nexport const decodeSnapshot = buf => decodeSnapshotV2(buf, new DSDecoderV1(decoding.createDecoder(buf)))\n\n/**\n * @param {DeleteSet} ds\n * @param {Map<number,number>} sm\n * @return {Snapshot}\n */\nexport const createSnapshot = (ds, sm) => new Snapshot(ds, sm)\n\nexport const emptySnapshot = createSnapshot(createDeleteSet(), new Map())\n\n/**\n * @param {Doc} doc\n * @return {Snapshot}\n */\nexport const snapshot = doc => createSnapshot(createDeleteSetFromStructStore(doc.store), getStateVector(doc.store))\n\n/**\n * @param {Item} item\n * @param {Snapshot|undefined} snapshot\n *\n * @protected\n * @function\n */\nexport const isVisible = (item, snapshot) => snapshot === undefined\n ? !item.deleted\n : snapshot.sv.has(item.id.client) && (snapshot.sv.get(item.id.client) || 0) > item.id.clock && !isDeleted(snapshot.ds, item.id)\n\n/**\n * @param {Transaction} transaction\n * @param {Snapshot} snapshot\n */\nexport const splitSnapshotAffectedStructs = (transaction, snapshot) => {\n const meta = map.setIfUndefined(transaction.meta, splitSnapshotAffectedStructs, set.create)\n const store = transaction.doc.store\n // check if we already split for this snapshot\n if (!meta.has(snapshot)) {\n snapshot.sv.forEach((clock, client) => {\n if (clock < getState(store, client)) {\n getItemCleanStart(transaction, createID(client, clock))\n }\n })\n iterateDeletedStructs(transaction, snapshot.ds, _item => {})\n meta.add(snapshot)\n }\n}\n\n/**\n * @example\n * const ydoc = new Y.Doc({ gc: false })\n * ydoc.getText().insert(0, 'world!')\n * const snapshot = Y.snapshot(ydoc)\n * ydoc.getText().insert(0, 'hello ')\n * const restored = Y.createDocFromSnapshot(ydoc, snapshot)\n * assert(restored.getText().toString() === 'world!')\n *\n * @param {Doc} originDoc\n * @param {Snapshot} snapshot\n * @param {Doc} [newDoc] Optionally, you may define the Yjs document that receives the data from originDoc\n * @return {Doc}\n */\nexport const createDocFromSnapshot = (originDoc, snapshot, newDoc = new Doc()) => {\n if (originDoc.gc) {\n // we should not try to restore a GC-ed document, because some of the restored items might have their content deleted\n throw new Error('Garbage-collection must be disabled in `originDoc`!')\n }\n const { sv, ds } = snapshot\n\n const encoder = new UpdateEncoderV2()\n originDoc.transact(transaction => {\n let size = 0\n sv.forEach(clock => {\n if (clock > 0) {\n size++\n }\n })\n encoding.writeVarUint(encoder.restEncoder, size)\n // splitting the structs before writing them to the encoder\n for (const [client, clock] of sv) {\n if (clock === 0) {\n continue\n }\n if (clock < getState(originDoc.store, client)) {\n getItemCleanStart(transaction, createID(client, clock))\n }\n const structs = originDoc.store.clients.get(client) || []\n const lastStructIndex = findIndexSS(structs, clock - 1)\n // write # encoded structs\n encoding.writeVarUint(encoder.restEncoder, lastStructIndex + 1)\n encoder.writeClient(client)\n // first clock written is 0\n encoding.writeVarUint(encoder.restEncoder, 0)\n for (let i = 0; i <= lastStructIndex; i++) {\n structs[i].write(encoder, 0)\n }\n }\n writeDeleteSet(encoder, ds)\n })\n\n applyUpdateV2(newDoc, encoder.toUint8Array(), 'snapshot')\n return newDoc\n}\n\n/**\n * @param {Snapshot} snapshot\n * @param {Uint8Array} update\n * @param {typeof UpdateDecoderV2 | typeof UpdateDecoderV1} [YDecoder]\n */\nexport const snapshotContainsUpdateV2 = (snapshot, update, YDecoder = UpdateDecoderV2) => {\n const structs = []\n const updateDecoder = new YDecoder(decoding.createDecoder(update))\n const lazyDecoder = new LazyStructReader(updateDecoder, false)\n for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {\n structs.push(curr)\n if ((snapshot.sv.get(curr.id.client) || 0) < curr.id.clock + curr.length) {\n return false\n }\n }\n const mergedDS = mergeDeleteSets([snapshot.ds, readDeleteSet(updateDecoder)])\n return equalDeleteSets(snapshot.ds, mergedDS)\n}\n\n/**\n * @param {Snapshot} snapshot\n * @param {Uint8Array} update\n */\nexport const snapshotContainsUpdate = (snapshot, update) => snapshotContainsUpdateV2(snapshot, update, UpdateDecoderV1)\n","import {\n GC,\n splitItem,\n Transaction, ID, Item, DSDecoderV2 // eslint-disable-line\n} from '../internals.js'\n\nimport * as math from 'lib0/math'\nimport * as error from 'lib0/error'\n\nexport class StructStore {\n constructor () {\n /**\n * @type {Map<number,Array<GC|Item>>}\n */\n this.clients = new Map()\n /**\n * @type {null | { missing: Map<number, number>, update: Uint8Array }}\n */\n this.pendingStructs = null\n /**\n * @type {null | Uint8Array}\n */\n this.pendingDs = null\n }\n}\n\n/**\n * Return the states as a Map<client,clock>.\n * Note that clock refers to the next expected clock id.\n *\n * @param {StructStore} store\n * @return {Map<number,number>}\n *\n * @public\n * @function\n */\nexport const getStateVector = store => {\n const sm = new Map()\n store.clients.forEach((structs, client) => {\n const struct = structs[structs.length - 1]\n sm.set(client, struct.id.clock + struct.length)\n })\n return sm\n}\n\n/**\n * @param {StructStore} store\n * @param {number} client\n * @return {number}\n *\n * @public\n * @function\n */\nexport const getState = (store, client) => {\n const structs = store.clients.get(client)\n if (structs === undefined) {\n return 0\n }\n const lastStruct = structs[structs.length - 1]\n return lastStruct.id.clock + lastStruct.length\n}\n\n/**\n * @param {StructStore} store\n *\n * @private\n * @function\n */\nexport const integrityCheck = store => {\n store.clients.forEach(structs => {\n for (let i = 1; i < structs.length; i++) {\n const l = structs[i - 1]\n const r = structs[i]\n if (l.id.clock + l.length !== r.id.clock) {\n throw new Error('StructStore failed integrity check')\n }\n }\n })\n}\n\n/**\n * @param {StructStore} store\n * @param {GC|Item} struct\n *\n * @private\n * @function\n */\nexport const addStruct = (store, struct) => {\n let structs = store.clients.get(struct.id.client)\n if (structs === undefined) {\n structs = []\n store.clients.set(struct.id.client, structs)\n } else {\n const lastStruct = structs[structs.length - 1]\n if (lastStruct.id.clock + lastStruct.length !== struct.id.clock) {\n throw error.unexpectedCase()\n }\n }\n structs.push(struct)\n}\n\n/**\n * Perform a binary search on a sorted array\n * @param {Array<Item|GC>} structs\n * @param {number} clock\n * @return {number}\n *\n * @private\n * @function\n */\nexport const findIndexSS = (structs, clock) => {\n let left = 0\n let right = structs.length - 1\n let mid = structs[right]\n let midclock = mid.id.clock\n if (midclock === clock) {\n return right\n }\n // @todo does it even make sense to pivot the search?\n // If a good split misses, it might actually increase the time to find the correct item.\n // Currently, the only advantage is that search with pivoting might find the item on the first try.\n let midindex = math.floor((clock / (midclock + mid.length - 1)) * right) // pivoting the search\n while (left <= right) {\n mid = structs[midindex]\n midclock = mid.id.clock\n if (midclock <= clock) {\n if (clock < midclock + mid.length) {\n return midindex\n }\n left = midindex + 1\n } else {\n right = midindex - 1\n }\n midindex = math.floor((left + right) / 2)\n }\n // Always check state before looking for a struct in StructStore\n // Therefore the case of not finding a struct is unexpected\n throw error.unexpectedCase()\n}\n\n/**\n * Expects that id is actually in store. This function throws or is an infinite loop otherwise.\n *\n * @param {StructStore} store\n * @param {ID} id\n * @return {GC|Item}\n *\n * @private\n * @function\n */\nexport const find = (store, id) => {\n /**\n * @type {Array<GC|Item>}\n */\n // @ts-ignore\n const structs = store.clients.get(id.client)\n return structs[findIndexSS(structs, id.clock)]\n}\n\n/**\n * Expects that id is actually in store. This function throws or is an infinite loop otherwise.\n * @private\n * @function\n */\nexport const getItem = /** @type {function(StructStore,ID):Item} */ (find)\n\n/**\n * @param {Transaction} transaction\n * @param {Array<Item|GC>} structs\n * @param {number} clock\n */\nexport const findIndexCleanStart = (transaction, structs, clock) => {\n const index = findIndexSS(structs, clock)\n const struct = structs[index]\n if (struct.id.clock < clock && struct instanceof Item) {\n structs.splice(index + 1, 0, splitItem(transaction, struct, clock - struct.id.clock))\n return index + 1\n }\n return index\n}\n\n/**\n * Expects that id is actually in store. This function throws or is an infinite loop otherwise.\n *\n * @param {Transaction} transaction\n * @param {ID} id\n * @return {Item}\n *\n * @private\n * @function\n */\nexport const getItemCleanStart = (transaction, id) => {\n const structs = /** @type {Array<Item>} */ (transaction.doc.store.clients.get(id.client))\n return structs[findIndexCleanStart(transaction, structs, id.clock)]\n}\n\n/**\n * Expects that id is actually in store. This function throws or is an infinite loop otherwise.\n *\n * @param {Transaction} transaction\n * @param {StructStore} store\n * @param {ID} id\n * @return {Item}\n *\n * @private\n * @function\n */\nexport const getItemCleanEnd = (transaction, store, id) => {\n /**\n * @type {Array<Item>}\n */\n // @ts-ignore\n const structs = store.clients.get(id.client)\n const index = findIndexSS(structs, id.clock)\n const struct = structs[index]\n if (id.clock !== struct.id.clock + struct.length - 1 && struct.constructor !== GC) {\n structs.splice(index + 1, 0, splitItem(transaction, struct, id.clock - struct.id.clock + 1))\n }\n return struct\n}\n\n/**\n * Replace `item` with `newitem` in store\n * @param {StructStore} store\n * @param {GC|Item} struct\n * @param {GC|Item} newStruct\n *\n * @private\n * @function\n */\nexport const replaceStruct = (store, struct, newStruct) => {\n const structs = /** @type {Array<GC|Item>} */ (store.clients.get(struct.id.client))\n structs[findIndexSS(structs, struct.id.clock)] = newStruct\n}\n\n/**\n * Iterate over a range of structs\n *\n * @param {Transaction} transaction\n * @param {Array<Item|GC>} structs\n * @param {number} clockStart Inclusive start\n * @param {number} len\n * @param {function(GC|Item):void} f\n *\n * @function\n */\nexport const iterateStructs = (transaction, structs, clockStart, len, f) => {\n if (len === 0) {\n return\n }\n const clockEnd = clockStart + len\n let index = findIndexCleanStart(transaction, structs, clockStart)\n let struct\n do {\n struct = structs[index++]\n if (clockEnd < struct.id.clock + struct.length) {\n findIndexCleanStart(transaction, structs, clockEnd)\n }\n f(struct)\n } while (index < structs.length && structs[index].id.clock < clockEnd)\n}\n","import {\n getState,\n writeStructsFromTransaction,\n writeDeleteSet,\n DeleteSet,\n sortAndMergeDeleteSet,\n getStateVector,\n findIndexSS,\n callEventHandlerListeners,\n Item,\n generateNewClientId,\n createID,\n cleanupYTextAfterTransaction,\n UpdateEncoderV1, UpdateEncoderV2, GC, StructStore, AbstractType, AbstractStruct, YEvent, Doc // eslint-disable-line\n} from '../internals.js'\n\nimport * as map from 'lib0/map'\nimport * as math from 'lib0/math'\nimport * as set from 'lib0/set'\nimport * as logging from 'lib0/logging'\nimport { callAll } from 'lib0/function'\n\n/**\n * A transaction is created for every change on the Yjs model. It is possible\n * to bundle changes on the Yjs model in a single transaction to\n * minimize the number on messages sent and the number of observer calls.\n * If possible the user of this library should bundle as many changes as\n * possible. Here is an example to illustrate the advantages of bundling:\n *\n * @example\n * const ydoc = new Y.Doc()\n * const map = ydoc.getMap('map')\n * // Log content when change is triggered\n * map.observe(() => {\n * console.log('change triggered')\n * })\n * // Each change on the map type triggers a log message:\n * map.set('a', 0) // => \"change triggered\"\n * map.set('b', 0) // => \"change triggered\"\n * // When put in a transaction, it will trigger the log after the transaction:\n * ydoc.transact(() => {\n * map.set('a', 1)\n * map.set('b', 1)\n * }) // => \"change triggered\"\n *\n * @public\n */\nexport class Transaction {\n /**\n * @param {Doc} doc\n * @param {any} origin\n * @param {boolean} local\n */\n constructor (doc, origin, local) {\n /**\n * The Yjs instance.\n * @type {Doc}\n */\n this.doc = doc\n /**\n * Describes the set of deleted items by ids\n * @type {DeleteSet}\n */\n this.deleteSet = new DeleteSet()\n /**\n * Holds the state before the transaction started.\n * @type {Map<Number,Number>}\n */\n this.beforeState = getStateVector(doc.store)\n /**\n * Holds the state after the transaction.\n * @type {Map<Number,Number>}\n */\n this.afterState = new Map()\n /**\n * All types that were directly modified (property added or child\n * inserted/deleted). New types are not included in this Set.\n * Maps from type to parentSubs (`item.parentSub = null` for YArray)\n * @type {Map<AbstractType<YEvent<any>>,Set<String|null>>}\n */\n this.changed = new Map()\n /**\n * Stores the events for the types that observe also child elements.\n * It is mainly used by `observeDeep`.\n * @type {Map<AbstractType<YEvent<any>>,Array<YEvent<any>>>}\n */\n this.changedParentTypes = new Map()\n /**\n * @type {Array<AbstractStruct>}\n */\n this._mergeStructs = []\n /**\n * @type {any}\n */\n this.origin = origin\n /**\n * Stores meta information on the transaction\n * @type {Map<any,any>}\n */\n this.meta = new Map()\n /**\n * Whether this change originates from this doc.\n * @type {boolean}\n */\n this.local = local\n /**\n * @type {Set<Doc>}\n */\n this.subdocsAdded = new Set()\n /**\n * @type {Set<Doc>}\n */\n this.subdocsRemoved = new Set()\n /**\n * @type {Set<Doc>}\n */\n this.subdocsLoaded = new Set()\n /**\n * @type {boolean}\n */\n this._needFormattingCleanup = false\n }\n}\n\n/**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {Transaction} transaction\n * @return {boolean} Whether data was written.\n */\nexport const writeUpdateMessageFromTransaction = (encoder, transaction) => {\n if (transaction.deleteSet.clients.size === 0 && !map.any(transaction.afterState, (clock, client) => transaction.beforeState.get(client) !== clock)) {\n return false\n }\n sortAndMergeDeleteSet(transaction.deleteSet)\n writeStructsFromTransaction(encoder, transaction)\n writeDeleteSet(encoder, transaction.deleteSet)\n return true\n}\n\n/**\n * @param {Transaction} transaction\n *\n * @private\n * @function\n */\nexport const nextID = transaction => {\n const y = transaction.doc\n return createID(y.clientID, getState(y.store, y.clientID))\n}\n\n/**\n * If `type.parent` was added in current transaction, `type` technically\n * did not change, it was just added and we should not fire events for `type`.\n *\n * @param {Transaction} transaction\n * @param {AbstractType<YEvent<any>>} type\n * @param {string|null} parentSub\n */\nexport const addChangedTypeToTransaction = (transaction, type, parentSub) => {\n const item = type._item\n if (item === null || (item.id.clock < (transaction.beforeState.get(item.id.client) || 0) && !item.deleted)) {\n map.setIfUndefined(transaction.changed, type, set.create).add(parentSub)\n }\n}\n\n/**\n * @param {Array<AbstractStruct>} structs\n * @param {number} pos\n * @return {number} # of merged structs\n */\nconst tryToMergeWithLefts = (structs, pos) => {\n let right = structs[pos]\n let left = structs[pos - 1]\n let i = pos\n for (; i > 0; right = left, left = structs[--i - 1]) {\n if (left.deleted === right.deleted && left.constructor === right.constructor) {\n if (left.mergeWith(right)) {\n if (right instanceof Item && right.parentSub !== null && /** @type {AbstractType<any>} */ (right.parent)._map.get(right.parentSub) === right) {\n /** @type {AbstractType<any>} */ (right.parent)._map.set(right.parentSub, /** @type {Item} */ (left))\n }\n continue\n }\n }\n break\n }\n const merged = pos - i\n if (merged) {\n // remove all merged structs from the array\n structs.splice(pos + 1 - merged, merged)\n }\n return merged\n}\n\n/**\n * @param {DeleteSet} ds\n * @param {StructStore} store\n * @param {function(Item):boolean} gcFilter\n */\nconst tryGcDeleteSet = (ds, store, gcFilter) => {\n for (const [client, deleteItems] of ds.clients.entries()) {\n const structs = /** @type {Array<GC|Item>} */ (store.clients.get(client))\n for (let di = deleteItems.length - 1; di >= 0; di--) {\n const deleteItem = deleteItems[di]\n const endDeleteItemClock = deleteItem.clock + deleteItem.len\n for (\n let si = findIndexSS(structs, deleteItem.clock), struct = structs[si];\n si < structs.length && struct.id.clock < endDeleteItemClock;\n struct = structs[++si]\n ) {\n const struct = structs[si]\n if (deleteItem.clock + deleteItem.len <= struct.id.clock) {\n break\n }\n if (struct instanceof Item && struct.deleted && !struct.keep && gcFilter(struct)) {\n struct.gc(store, false)\n }\n }\n }\n }\n}\n\n/**\n * @param {DeleteSet} ds\n * @param {StructStore} store\n */\nconst tryMergeDeleteSet = (ds, store) => {\n // try to merge deleted / gc'd items\n // merge from right to left for better efficiency and so we don't miss any merge targets\n ds.clients.forEach((deleteItems, client) => {\n const structs = /** @type {Array<GC|Item>} */ (store.clients.get(client))\n for (let di = deleteItems.length - 1; di >= 0; di--) {\n const deleteItem = deleteItems[di]\n // start with merging the item next to the last deleted item\n const mostRightIndexToCheck = math.min(structs.length - 1, 1 + findIndexSS(structs, deleteItem.clock + deleteItem.len - 1))\n for (\n let si = mostRightIndexToCheck, struct = structs[si];\n si > 0 && struct.id.clock >= deleteItem.clock;\n struct = structs[si]\n ) {\n si -= 1 + tryToMergeWithLefts(structs, si)\n }\n }\n })\n}\n\n/**\n * @param {DeleteSet} ds\n * @param {StructStore} store\n * @param {function(Item):boolean} gcFilter\n */\nexport const tryGc = (ds, store, gcFilter) => {\n tryGcDeleteSet(ds, store, gcFilter)\n tryMergeDeleteSet(ds, store)\n}\n\n/**\n * @param {Array<Transaction>} transactionCleanups\n * @param {number} i\n */\nconst cleanupTransactions = (transactionCleanups, i) => {\n if (i < transactionCleanups.length) {\n const transaction = transactionCleanups[i]\n const doc = transaction.doc\n const store = doc.store\n const ds = transaction.deleteSet\n const mergeStructs = transaction._mergeStructs\n try {\n sortAndMergeDeleteSet(ds)\n transaction.afterState = getStateVector(transaction.doc.store)\n doc.emit('beforeObserverCalls', [transaction, doc])\n /**\n * An array of event callbacks.\n *\n * Each callback is called even if the other ones throw errors.\n *\n * @type {Array<function():void>}\n */\n const fs = []\n // observe events on changed types\n transaction.changed.forEach((subs, itemtype) =>\n fs.push(() => {\n if (itemtype._item === null || !itemtype._item.deleted) {\n itemtype._callObserver(transaction, subs)\n }\n })\n )\n fs.push(() => {\n // deep observe events\n transaction.changedParentTypes.forEach((events, type) => {\n // We need to think about the possibility that the user transforms the\n // Y.Doc in the event.\n if (type._dEH.l.length > 0 && (type._item === null || !type._item.deleted)) {\n events = events\n .filter(event =>\n event.target._item === null || !event.target._item.deleted\n )\n events\n .forEach(event => {\n event.currentTarget = type\n // path is relative to the current target\n event._path = null\n })\n // sort events by path length so that top-level events are fired first.\n events\n .sort((event1, event2) => event1.path.length - event2.path.length)\n // We don't need to check for events.length\n // because we know it has at least one element\n callEventHandlerListeners(type._dEH, events, transaction)\n }\n })\n })\n fs.push(() => doc.emit('afterTransaction', [transaction, doc]))\n callAll(fs, [])\n if (transaction._needFormattingCleanup) {\n cleanupYTextAfterTransaction(transaction)\n }\n } finally {\n // Replace deleted items with ItemDeleted / GC.\n // This is where content is actually remove from the Yjs Doc.\n if (doc.gc) {\n tryGcDeleteSet(ds, store, doc.gcFilter)\n }\n tryMergeDeleteSet(ds, store)\n\n // on all affected store.clients props, try to merge\n transaction.afterState.forEach((clock, client) => {\n const beforeClock = transaction.beforeState.get(client) || 0\n if (beforeClock !== clock) {\n const structs = /** @type {Array<GC|Item>} */ (store.clients.get(client))\n // we iterate from right to left so we can safely remove entries\n const firstChangePos = math.max(findIndexSS(structs, beforeClock), 1)\n for (let i = structs.length - 1; i >= firstChangePos;) {\n i -= 1 + tryToMergeWithLefts(structs, i)\n }\n }\n })\n // try to merge mergeStructs\n // @todo: it makes more sense to transform mergeStructs to a DS, sort it, and merge from right to left\n // but at the moment DS does not handle duplicates\n for (let i = mergeStructs.length - 1; i >= 0; i--) {\n const { client, clock } = mergeStructs[i].id\n const structs = /** @type {Array<GC|Item>} */ (store.clients.get(client))\n const replacedStructPos = findIndexSS(structs, clock)\n if (replacedStructPos + 1 < structs.length) {\n if (tryToMergeWithLefts(structs, replacedStructPos + 1) > 1) {\n continue // no need to perform next check, both are already merged\n }\n }\n if (replacedStructPos > 0) {\n tryToMergeWithLefts(structs, replacedStructPos)\n }\n }\n if (!transaction.local && transaction.afterState.get(doc.clientID) !== transaction.beforeState.get(doc.clientID)) {\n logging.print(logging.ORANGE, logging.BOLD, '[yjs] ', logging.UNBOLD, logging.RED, 'Changed the client-id because another client seems to be using it.')\n doc.clientID = generateNewClientId()\n }\n // @todo Merge all the transactions into one and provide send the data as a single update message\n doc.emit('afterTransactionCleanup', [transaction, doc])\n if (doc._observers.has('update')) {\n const encoder = new UpdateEncoderV1()\n const hasContent = writeUpdateMessageFromTransaction(encoder, transaction)\n if (hasContent) {\n doc.emit('update', [encoder.toUint8Array(), transaction.origin, doc, transaction])\n }\n }\n if (doc._observers.has('updateV2')) {\n const encoder = new UpdateEncoderV2()\n const hasContent = writeUpdateMessageFromTransaction(encoder, transaction)\n if (hasContent) {\n doc.emit('updateV2', [encoder.toUint8Array(), transaction.origin, doc, transaction])\n }\n }\n const { subdocsAdded, subdocsLoaded, subdocsRemoved } = transaction\n if (subdocsAdded.size > 0 || subdocsRemoved.size > 0 || subdocsLoaded.size > 0) {\n subdocsAdded.forEach(subdoc => {\n subdoc.clientID = doc.clientID\n if (subdoc.collectionid == null) {\n subdoc.collectionid = doc.collectionid\n }\n doc.subdocs.add(subdoc)\n })\n subdocsRemoved.forEach(subdoc => doc.subdocs.delete(subdoc))\n doc.emit('subdocs', [{ loaded: subdocsLoaded, added: subdocsAdded, removed: subdocsRemoved }, doc, transaction])\n subdocsRemoved.forEach(subdoc => subdoc.destroy())\n }\n\n if (transactionCleanups.length <= i + 1) {\n doc._transactionCleanups = []\n doc.emit('afterAllTransactions', [doc, transactionCleanups])\n } else {\n cleanupTransactions(transactionCleanups, i + 1)\n }\n }\n }\n}\n\n/**\n * Implements the functionality of `y.transact(()=>{..})`\n *\n * @template T\n * @param {Doc} doc\n * @param {function(Transaction):T} f\n * @param {any} [origin=true]\n * @return {T}\n *\n * @function\n */\nexport const transact = (doc, f, origin = null, local = true) => {\n const transactionCleanups = doc._transactionCleanups\n let initialCall = false\n /**\n * @type {any}\n */\n let result = null\n if (doc._transaction === null) {\n initialCall = true\n doc._transaction = new Transaction(doc, origin, local)\n transactionCleanups.push(doc._transaction)\n if (transactionCleanups.length === 1) {\n doc.emit('beforeAllTransactions', [doc])\n }\n doc.emit('beforeTransaction', [doc._transaction, doc])\n }\n try {\n result = f(doc._transaction)\n } finally {\n if (initialCall) {\n const finishCleanup = doc._transaction === transactionCleanups[0]\n doc._transaction = null\n if (finishCleanup) {\n // The first transaction ended, now process observer calls.\n // Observer call may create new transactions for which we need to call the observers and do cleanup.\n // We don't want to nest these calls, so we execute these calls one after\n // another.\n // Also we need to ensure that all cleanups are called, even if the\n // observes throw errors.\n // This file is full of hacky try {} finally {} blocks to ensure that an\n // event can throw errors and also that the cleanup is called.\n cleanupTransactions(transactionCleanups, 0)\n }\n }\n }\n return result\n}\n","import * as binary from 'lib0/binary'\nimport * as decoding from 'lib0/decoding'\nimport * as encoding from 'lib0/encoding'\nimport * as error from 'lib0/error'\nimport * as f from 'lib0/function'\nimport * as logging from 'lib0/logging'\nimport * as map from 'lib0/map'\nimport * as math from 'lib0/math'\nimport * as string from 'lib0/string'\n\nimport {\n ContentAny,\n ContentBinary,\n ContentDeleted,\n ContentDoc,\n ContentEmbed,\n ContentFormat,\n ContentJSON,\n ContentString,\n ContentType,\n createID,\n decodeStateVector,\n DSEncoderV1,\n DSEncoderV2,\n GC,\n Item,\n mergeDeleteSets,\n readDeleteSet,\n readItemContent,\n Skip,\n UpdateDecoderV1,\n UpdateDecoderV2,\n UpdateEncoderV1,\n UpdateEncoderV2,\n writeDeleteSet,\n YXmlElement,\n YXmlHook\n} from '../internals.js'\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n */\nfunction * lazyStructReaderGenerator (decoder) {\n const numOfStateUpdates = decoding.readVarUint(decoder.restDecoder)\n for (let i = 0; i < numOfStateUpdates; i++) {\n const numberOfStructs = decoding.readVarUint(decoder.restDecoder)\n const client = decoder.readClient()\n let clock = decoding.readVarUint(decoder.restDecoder)\n for (let i = 0; i < numberOfStructs; i++) {\n const info = decoder.readInfo()\n // @todo use switch instead of ifs\n if (info === 10) {\n const len = decoding.readVarUint(decoder.restDecoder)\n yield new Skip(createID(client, clock), len)\n clock += len\n } else if ((binary.BITS5 & info) !== 0) {\n const cantCopyParentInfo = (info & (binary.BIT7 | binary.BIT8)) === 0\n // If parent = null and neither left nor right are defined, then we know that `parent` is child of `y`\n // and we read the next string as parentYKey.\n // It indicates how we store/retrieve parent from `y.share`\n // @type {string|null}\n const struct = new Item(\n createID(client, clock),\n null, // left\n (info & binary.BIT8) === binary.BIT8 ? decoder.readLeftID() : null, // origin\n null, // right\n (info & binary.BIT7) === binary.BIT7 ? decoder.readRightID() : null, // right origin\n // @ts-ignore Force writing a string here.\n cantCopyParentInfo ? (decoder.readParentInfo() ? decoder.readString() : decoder.readLeftID()) : null, // parent\n cantCopyParentInfo && (info & binary.BIT6) === binary.BIT6 ? decoder.readString() : null, // parentSub\n readItemContent(decoder, info) // item content\n )\n yield struct\n clock += struct.length\n } else {\n const len = decoder.readLen()\n yield new GC(createID(client, clock), len)\n clock += len\n }\n }\n }\n}\n\nexport class LazyStructReader {\n /**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @param {boolean} filterSkips\n */\n constructor (decoder, filterSkips) {\n this.gen = lazyStructReaderGenerator(decoder)\n /**\n * @type {null | Item | Skip | GC}\n */\n this.curr = null\n this.done = false\n this.filterSkips = filterSkips\n this.next()\n }\n\n /**\n * @return {Item | GC | Skip |null}\n */\n next () {\n // ignore \"Skip\" structs\n do {\n this.curr = this.gen.next().value || null\n } while (this.filterSkips && this.curr !== null && this.curr.constructor === Skip)\n return this.curr\n }\n}\n\n/**\n * @param {Uint8Array} update\n *\n */\nexport const logUpdate = update => logUpdateV2(update, UpdateDecoderV1)\n\n/**\n * @param {Uint8Array} update\n * @param {typeof UpdateDecoderV2 | typeof UpdateDecoderV1} [YDecoder]\n *\n */\nexport const logUpdateV2 = (update, YDecoder = UpdateDecoderV2) => {\n const structs = []\n const updateDecoder = new YDecoder(decoding.createDecoder(update))\n const lazyDecoder = new LazyStructReader(updateDecoder, false)\n for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {\n structs.push(curr)\n }\n logging.print('Structs: ', structs)\n const ds = readDeleteSet(updateDecoder)\n logging.print('DeleteSet: ', ds)\n}\n\n/**\n * @param {Uint8Array} update\n *\n */\nexport const decodeUpdate = (update) => decodeUpdateV2(update, UpdateDecoderV1)\n\n/**\n * @param {Uint8Array} update\n * @param {typeof UpdateDecoderV2 | typeof UpdateDecoderV1} [YDecoder]\n *\n */\nexport const decodeUpdateV2 = (update, YDecoder = UpdateDecoderV2) => {\n const structs = []\n const updateDecoder = new YDecoder(decoding.createDecoder(update))\n const lazyDecoder = new LazyStructReader(updateDecoder, false)\n for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {\n structs.push(curr)\n }\n return {\n structs,\n ds: readDeleteSet(updateDecoder)\n }\n}\n\nexport class LazyStructWriter {\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n */\n constructor (encoder) {\n this.currClient = 0\n this.startClock = 0\n this.written = 0\n this.encoder = encoder\n /**\n * We want to write operations lazily, but also we need to know beforehand how many operations we want to write for each client.\n *\n * This kind of meta-information (#clients, #structs-per-client-written) is written to the restEncoder.\n *\n * We fragment the restEncoder and store a slice of it per-client until we know how many clients there are.\n * When we flush (toUint8Array) we write the restEncoder using the fragments and the meta-information.\n *\n * @type {Array<{ written: number, restEncoder: Uint8Array }>}\n */\n this.clientStructs = []\n }\n}\n\n/**\n * @param {Array<Uint8Array>} updates\n * @return {Uint8Array}\n */\nexport const mergeUpdates = updates => mergeUpdatesV2(updates, UpdateDecoderV1, UpdateEncoderV1)\n\n/**\n * @param {Uint8Array} update\n * @param {typeof DSEncoderV1 | typeof DSEncoderV2} YEncoder\n * @param {typeof UpdateDecoderV1 | typeof UpdateDecoderV2} YDecoder\n * @return {Uint8Array}\n */\nexport const encodeStateVectorFromUpdateV2 = (update, YEncoder = DSEncoderV2, YDecoder = UpdateDecoderV2) => {\n const encoder = new YEncoder()\n const updateDecoder = new LazyStructReader(new YDecoder(decoding.createDecoder(update)), false)\n let curr = updateDecoder.curr\n if (curr !== null) {\n let size = 0\n let currClient = curr.id.client\n let stopCounting = curr.id.clock !== 0 // must start at 0\n let currClock = stopCounting ? 0 : curr.id.clock + curr.length\n for (; curr !== null; curr = updateDecoder.next()) {\n if (currClient !== curr.id.client) {\n if (currClock !== 0) {\n size++\n // We found a new client\n // write what we have to the encoder\n encoding.writeVarUint(encoder.restEncoder, currClient)\n encoding.writeVarUint(encoder.restEncoder, currClock)\n }\n currClient = curr.id.client\n currClock = 0\n stopCounting = curr.id.clock !== 0\n }\n // we ignore skips\n if (curr.constructor === Skip) {\n stopCounting = true\n }\n if (!stopCounting) {\n currClock = curr.id.clock + curr.length\n }\n }\n // write what we have\n if (currClock !== 0) {\n size++\n encoding.writeVarUint(encoder.restEncoder, currClient)\n encoding.writeVarUint(encoder.restEncoder, currClock)\n }\n // prepend the size of the state vector\n const enc = encoding.createEncoder()\n encoding.writeVarUint(enc, size)\n encoding.writeBinaryEncoder(enc, encoder.restEncoder)\n encoder.restEncoder = enc\n return encoder.toUint8Array()\n } else {\n encoding.writeVarUint(encoder.restEncoder, 0)\n return encoder.toUint8Array()\n }\n}\n\n/**\n * @param {Uint8Array} update\n * @return {Uint8Array}\n */\nexport const encodeStateVectorFromUpdate = update => encodeStateVectorFromUpdateV2(update, DSEncoderV1, UpdateDecoderV1)\n\n/**\n * @param {Uint8Array} update\n * @param {typeof UpdateDecoderV1 | typeof UpdateDecoderV2} YDecoder\n * @return {{ from: Map<number,number>, to: Map<number,number> }}\n */\nexport const parseUpdateMetaV2 = (update, YDecoder = UpdateDecoderV2) => {\n /**\n * @type {Map<number, number>}\n */\n const from = new Map()\n /**\n * @type {Map<number, number>}\n */\n const to = new Map()\n const updateDecoder = new LazyStructReader(new YDecoder(decoding.createDecoder(update)), false)\n let curr = updateDecoder.curr\n if (curr !== null) {\n let currClient = curr.id.client\n let currClock = curr.id.clock\n // write the beginning to `from`\n from.set(currClient, currClock)\n for (; curr !== null; curr = updateDecoder.next()) {\n if (currClient !== curr.id.client) {\n // We found a new client\n // write the end to `to`\n to.set(currClient, currClock)\n // write the beginning to `from`\n from.set(curr.id.client, curr.id.clock)\n // update currClient\n currClient = curr.id.client\n }\n currClock = curr.id.clock + curr.length\n }\n // write the end to `to`\n to.set(currClient, currClock)\n }\n return { from, to }\n}\n\n/**\n * @param {Uint8Array} update\n * @return {{ from: Map<number,number>, to: Map<number,number> }}\n */\nexport const parseUpdateMeta = update => parseUpdateMetaV2(update, UpdateDecoderV1)\n\n/**\n * This method is intended to slice any kind of struct and retrieve the right part.\n * It does not handle side-effects, so it should only be used by the lazy-encoder.\n *\n * @param {Item | GC | Skip} left\n * @param {number} diff\n * @return {Item | GC}\n */\nconst sliceStruct = (left, diff) => {\n if (left.constructor === GC) {\n const { client, clock } = left.id\n return new GC(createID(client, clock + diff), left.length - diff)\n } else if (left.constructor === Skip) {\n const { client, clock } = left.id\n return new Skip(createID(client, clock + diff), left.length - diff)\n } else {\n const leftItem = /** @type {Item} */ (left)\n const { client, clock } = leftItem.id\n return new Item(\n createID(client, clock + diff),\n null,\n createID(client, clock + diff - 1),\n null,\n leftItem.rightOrigin,\n leftItem.parent,\n leftItem.parentSub,\n leftItem.content.splice(diff)\n )\n }\n}\n\n/**\n *\n * This function works similarly to `readUpdateV2`.\n *\n * @param {Array<Uint8Array>} updates\n * @param {typeof UpdateDecoderV1 | typeof UpdateDecoderV2} [YDecoder]\n * @param {typeof UpdateEncoderV1 | typeof UpdateEncoderV2} [YEncoder]\n * @return {Uint8Array}\n */\nexport const mergeUpdatesV2 = (updates, YDecoder = UpdateDecoderV2, YEncoder = UpdateEncoderV2) => {\n if (updates.length === 1) {\n return updates[0]\n }\n const updateDecoders = updates.map(update => new YDecoder(decoding.createDecoder(update)))\n let lazyStructDecoders = updateDecoders.map(decoder => new LazyStructReader(decoder, true))\n\n /**\n * @todo we don't need offset because we always slice before\n * @type {null | { struct: Item | GC | Skip, offset: number }}\n */\n let currWrite = null\n\n const updateEncoder = new YEncoder()\n // write structs lazily\n const lazyStructEncoder = new LazyStructWriter(updateEncoder)\n\n // Note: We need to ensure that all lazyStructDecoders are fully consumed\n // Note: Should merge document updates whenever possible - even from different updates\n // Note: Should handle that some operations cannot be applied yet ()\n\n while (true) {\n // Write higher clients first ⇒ sort by clientID & clock and remove decoders without content\n lazyStructDecoders = lazyStructDecoders.filter(dec => dec.curr !== null)\n lazyStructDecoders.sort(\n /** @type {function(any,any):number} */ (dec1, dec2) => {\n if (dec1.curr.id.client === dec2.curr.id.client) {\n const clockDiff = dec1.curr.id.clock - dec2.curr.id.clock\n if (clockDiff === 0) {\n // @todo remove references to skip since the structDecoders must filter Skips.\n return dec1.curr.constructor === dec2.curr.constructor\n ? 0\n : dec1.curr.constructor === Skip ? 1 : -1 // we are filtering skips anyway.\n } else {\n return clockDiff\n }\n } else {\n return dec2.curr.id.client - dec1.curr.id.client\n }\n }\n )\n if (lazyStructDecoders.length === 0) {\n break\n }\n const currDecoder = lazyStructDecoders[0]\n // write from currDecoder until the next operation is from another client or if filler-struct\n // then we need to reorder the decoders and find the next operation to write\n const firstClient = /** @type {Item | GC} */ (currDecoder.curr).id.client\n\n if (currWrite !== null) {\n let curr = /** @type {Item | GC | null} */ (currDecoder.curr)\n let iterated = false\n\n // iterate until we find something that we haven't written already\n // remember: first the high client-ids are written\n while (curr !== null && curr.id.clock + curr.length <= currWrite.struct.id.clock + currWrite.struct.length && curr.id.client >= currWrite.struct.id.client) {\n curr = currDecoder.next()\n iterated = true\n }\n if (\n curr === null || // current decoder is empty\n curr.id.client !== firstClient || // check whether there is another decoder that has has updates from `firstClient`\n (iterated && curr.id.clock > currWrite.struct.id.clock + currWrite.struct.length) // the above while loop was used and we are potentially missing updates\n ) {\n continue\n }\n\n if (firstClient !== currWrite.struct.id.client) {\n writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset)\n currWrite = { struct: curr, offset: 0 }\n currDecoder.next()\n } else {\n if (currWrite.struct.id.clock + currWrite.struct.length < curr.id.clock) {\n // @todo write currStruct & set currStruct = Skip(clock = currStruct.id.clock + currStruct.length, length = curr.id.clock - self.clock)\n if (currWrite.struct.constructor === Skip) {\n // extend existing skip\n currWrite.struct.length = curr.id.clock + curr.length - currWrite.struct.id.clock\n } else {\n writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset)\n const diff = curr.id.clock - currWrite.struct.id.clock - currWrite.struct.length\n /**\n * @type {Skip}\n */\n const struct = new Skip(createID(firstClient, currWrite.struct.id.clock + currWrite.struct.length), diff)\n currWrite = { struct, offset: 0 }\n }\n } else { // if (currWrite.struct.id.clock + currWrite.struct.length >= curr.id.clock) {\n const diff = currWrite.struct.id.clock + currWrite.struct.length - curr.id.clock\n if (diff > 0) {\n if (currWrite.struct.constructor === Skip) {\n // prefer to slice Skip because the other struct might contain more information\n currWrite.struct.length -= diff\n } else {\n curr = sliceStruct(curr, diff)\n }\n }\n if (!currWrite.struct.mergeWith(/** @type {any} */ (curr))) {\n writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset)\n currWrite = { struct: curr, offset: 0 }\n currDecoder.next()\n }\n }\n }\n } else {\n currWrite = { struct: /** @type {Item | GC} */ (currDecoder.curr), offset: 0 }\n currDecoder.next()\n }\n for (\n let next = currDecoder.curr;\n next !== null && next.id.client === firstClient && next.id.clock === currWrite.struct.id.clock + currWrite.struct.length && next.constructor !== Skip;\n next = currDecoder.next()\n ) {\n writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset)\n currWrite = { struct: next, offset: 0 }\n }\n }\n if (currWrite !== null) {\n writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset)\n currWrite = null\n }\n finishLazyStructWriting(lazyStructEncoder)\n\n const dss = updateDecoders.map(decoder => readDeleteSet(decoder))\n const ds = mergeDeleteSets(dss)\n writeDeleteSet(updateEncoder, ds)\n return updateEncoder.toUint8Array()\n}\n\n/**\n * @param {Uint8Array} update\n * @param {Uint8Array} sv\n * @param {typeof UpdateDecoderV1 | typeof UpdateDecoderV2} [YDecoder]\n * @param {typeof UpdateEncoderV1 | typeof UpdateEncoderV2} [YEncoder]\n */\nexport const diffUpdateV2 = (update, sv, YDecoder = UpdateDecoderV2, YEncoder = UpdateEncoderV2) => {\n const state = decodeStateVector(sv)\n const encoder = new YEncoder()\n const lazyStructWriter = new LazyStructWriter(encoder)\n const decoder = new YDecoder(decoding.createDecoder(update))\n const reader = new LazyStructReader(decoder, false)\n while (reader.curr) {\n const curr = reader.curr\n const currClient = curr.id.client\n const svClock = state.get(currClient) || 0\n if (reader.curr.constructor === Skip) {\n // the first written struct shouldn't be a skip\n reader.next()\n continue\n }\n if (curr.id.clock + curr.length > svClock) {\n writeStructToLazyStructWriter(lazyStructWriter, curr, math.max(svClock - curr.id.clock, 0))\n reader.next()\n while (reader.curr && reader.curr.id.client === currClient) {\n writeStructToLazyStructWriter(lazyStructWriter, reader.curr, 0)\n reader.next()\n }\n } else {\n // read until something new comes up\n while (reader.curr && reader.curr.id.client === currClient && reader.curr.id.clock + reader.curr.length <= svClock) {\n reader.next()\n }\n }\n }\n finishLazyStructWriting(lazyStructWriter)\n // write ds\n const ds = readDeleteSet(decoder)\n writeDeleteSet(encoder, ds)\n return encoder.toUint8Array()\n}\n\n/**\n * @param {Uint8Array} update\n * @param {Uint8Array} sv\n */\nexport const diffUpdate = (update, sv) => diffUpdateV2(update, sv, UpdateDecoderV1, UpdateEncoderV1)\n\n/**\n * @param {LazyStructWriter} lazyWriter\n */\nconst flushLazyStructWriter = lazyWriter => {\n if (lazyWriter.written > 0) {\n lazyWriter.clientStructs.push({ written: lazyWriter.written, restEncoder: encoding.toUint8Array(lazyWriter.encoder.restEncoder) })\n lazyWriter.encoder.restEncoder = encoding.createEncoder()\n lazyWriter.written = 0\n }\n}\n\n/**\n * @param {LazyStructWriter} lazyWriter\n * @param {Item | GC} struct\n * @param {number} offset\n */\nconst writeStructToLazyStructWriter = (lazyWriter, struct, offset) => {\n // flush curr if we start another client\n if (lazyWriter.written > 0 && lazyWriter.currClient !== struct.id.client) {\n flushLazyStructWriter(lazyWriter)\n }\n if (lazyWriter.written === 0) {\n lazyWriter.currClient = struct.id.client\n // write next client\n lazyWriter.encoder.writeClient(struct.id.client)\n // write startClock\n encoding.writeVarUint(lazyWriter.encoder.restEncoder, struct.id.clock + offset)\n }\n struct.write(lazyWriter.encoder, offset)\n lazyWriter.written++\n}\n/**\n * Call this function when we collected all parts and want to\n * put all the parts together. After calling this method,\n * you can continue using the UpdateEncoder.\n *\n * @param {LazyStructWriter} lazyWriter\n */\nconst finishLazyStructWriting = (lazyWriter) => {\n flushLazyStructWriter(lazyWriter)\n\n // this is a fresh encoder because we called flushCurr\n const restEncoder = lazyWriter.encoder.restEncoder\n\n /**\n * Now we put all the fragments together.\n * This works similarly to `writeClientsStructs`\n */\n\n // write # states that were updated - i.e. the clients\n encoding.writeVarUint(restEncoder, lazyWriter.clientStructs.length)\n\n for (let i = 0; i < lazyWriter.clientStructs.length; i++) {\n const partStructs = lazyWriter.clientStructs[i]\n /**\n * Works similarly to `writeStructs`\n */\n // write # encoded structs\n encoding.writeVarUint(restEncoder, partStructs.written)\n // write the rest of the fragment\n encoding.writeUint8Array(restEncoder, partStructs.restEncoder)\n }\n}\n\n/**\n * @param {Uint8Array} update\n * @param {function(Item|GC|Skip):Item|GC|Skip} blockTransformer\n * @param {typeof UpdateDecoderV2 | typeof UpdateDecoderV1} YDecoder\n * @param {typeof UpdateEncoderV2 | typeof UpdateEncoderV1 } YEncoder\n */\nexport const convertUpdateFormat = (update, blockTransformer, YDecoder, YEncoder) => {\n const updateDecoder = new YDecoder(decoding.createDecoder(update))\n const lazyDecoder = new LazyStructReader(updateDecoder, false)\n const updateEncoder = new YEncoder()\n const lazyWriter = new LazyStructWriter(updateEncoder)\n for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {\n writeStructToLazyStructWriter(lazyWriter, blockTransformer(curr), 0)\n }\n finishLazyStructWriting(lazyWriter)\n const ds = readDeleteSet(updateDecoder)\n writeDeleteSet(updateEncoder, ds)\n return updateEncoder.toUint8Array()\n}\n\n/**\n * @typedef {Object} ObfuscatorOptions\n * @property {boolean} [ObfuscatorOptions.formatting=true]\n * @property {boolean} [ObfuscatorOptions.subdocs=true]\n * @property {boolean} [ObfuscatorOptions.yxml=true] Whether to obfuscate nodeName / hookName\n */\n\n/**\n * @param {ObfuscatorOptions} obfuscator\n */\nconst createObfuscator = ({ formatting = true, subdocs = true, yxml = true } = {}) => {\n let i = 0\n const mapKeyCache = map.create()\n const nodeNameCache = map.create()\n const formattingKeyCache = map.create()\n const formattingValueCache = map.create()\n formattingValueCache.set(null, null) // end of a formatting range should always be the end of a formatting range\n /**\n * @param {Item|GC|Skip} block\n * @return {Item|GC|Skip}\n */\n return block => {\n switch (block.constructor) {\n case GC:\n case Skip:\n return block\n case Item: {\n const item = /** @type {Item} */ (block)\n const content = item.content\n switch (content.constructor) {\n case ContentDeleted:\n break\n case ContentType: {\n if (yxml) {\n const type = /** @type {ContentType} */ (content).type\n if (type instanceof YXmlElement) {\n type.nodeName = map.setIfUndefined(nodeNameCache, type.nodeName, () => 'node-' + i)\n }\n if (type instanceof YXmlHook) {\n type.hookName = map.setIfUndefined(nodeNameCache, type.hookName, () => 'hook-' + i)\n }\n }\n break\n }\n case ContentAny: {\n const c = /** @type {ContentAny} */ (content)\n c.arr = c.arr.map(() => i)\n break\n }\n case ContentBinary: {\n const c = /** @type {ContentBinary} */ (content)\n c.content = new Uint8Array([i])\n break\n }\n case ContentDoc: {\n const c = /** @type {ContentDoc} */ (content)\n if (subdocs) {\n c.opts = {}\n c.doc.guid = i + ''\n }\n break\n }\n case ContentEmbed: {\n const c = /** @type {ContentEmbed} */ (content)\n c.embed = {}\n break\n }\n case ContentFormat: {\n const c = /** @type {ContentFormat} */ (content)\n if (formatting) {\n c.key = map.setIfUndefined(formattingKeyCache, c.key, () => i + '')\n c.value = map.setIfUndefined(formattingValueCache, c.value, () => ({ i }))\n }\n break\n }\n case ContentJSON: {\n const c = /** @type {ContentJSON} */ (content)\n c.arr = c.arr.map(() => i)\n break\n }\n case ContentString: {\n const c = /** @type {ContentString} */ (content)\n c.str = string.repeat((i % 10) + '', c.str.length)\n break\n }\n default:\n // unknown content type\n error.unexpectedCase()\n }\n if (item.parentSub) {\n item.parentSub = map.setIfUndefined(mapKeyCache, item.parentSub, () => i + '')\n }\n i++\n return block\n }\n default:\n // unknown block-type\n error.unexpectedCase()\n }\n }\n}\n\n/**\n * This function obfuscates the content of a Yjs update. This is useful to share\n * buggy Yjs documents while significantly limiting the possibility that a\n * developer can on the user. Note that it might still be possible to deduce\n * some information by analyzing the \"structure\" of the document or by analyzing\n * the typing behavior using the CRDT-related metadata that is still kept fully\n * intact.\n *\n * @param {Uint8Array} update\n * @param {ObfuscatorOptions} [opts]\n */\nexport const obfuscateUpdate = (update, opts) => convertUpdateFormat(update, createObfuscator(opts), UpdateDecoderV1, UpdateEncoderV1)\n\n/**\n * @param {Uint8Array} update\n * @param {ObfuscatorOptions} [opts]\n */\nexport const obfuscateUpdateV2 = (update, opts) => convertUpdateFormat(update, createObfuscator(opts), UpdateDecoderV2, UpdateEncoderV2)\n\n/**\n * @param {Uint8Array} update\n */\nexport const convertUpdateFormatV1ToV2 = update => convertUpdateFormat(update, f.id, UpdateDecoderV1, UpdateEncoderV2)\n\n/**\n * @param {Uint8Array} update\n */\nexport const convertUpdateFormatV2ToV1 = update => convertUpdateFormat(update, f.id, UpdateDecoderV2, UpdateEncoderV1)\n","import {\n isDeleted,\n Item, AbstractType, Transaction, AbstractStruct // eslint-disable-line\n} from '../internals.js'\n\nimport * as set from 'lib0/set'\nimport * as array from 'lib0/array'\nimport * as error from 'lib0/error'\n\nconst errorComputeChanges = 'You must not compute changes after the event-handler fired.'\n\n/**\n * @template {AbstractType<any>} T\n * YEvent describes the changes on a YType.\n */\nexport class YEvent {\n /**\n * @param {T} target The changed type.\n * @param {Transaction} transaction\n */\n constructor (target, transaction) {\n /**\n * The type on which this event was created on.\n * @type {T}\n */\n this.target = target\n /**\n * The current target on which the observe callback is called.\n * @type {AbstractType<any>}\n */\n this.currentTarget = target\n /**\n * The transaction that triggered this event.\n * @type {Transaction}\n */\n this.transaction = transaction\n /**\n * @type {Object|null}\n */\n this._changes = null\n /**\n * @type {null | Map<string, { action: 'add' | 'update' | 'delete', oldValue: any, newValue: any }>}\n */\n this._keys = null\n /**\n * @type {null | Array<{ insert?: string | Array<any> | object | AbstractType<any>, retain?: number, delete?: number, attributes?: Object<string, any> }>}\n */\n this._delta = null\n /**\n * @type {Array<string|number>|null}\n */\n this._path = null\n }\n\n /**\n * Computes the path from `y` to the changed type.\n *\n * @todo v14 should standardize on path: Array<{parent, index}> because that is easier to work with.\n *\n * The following property holds:\n * @example\n * let type = y\n * event.path.forEach(dir => {\n * type = type.get(dir)\n * })\n * type === event.target // => true\n */\n get path () {\n return this._path || (this._path = getPathTo(this.currentTarget, this.target))\n }\n\n /**\n * Check if a struct is deleted by this event.\n *\n * In contrast to change.deleted, this method also returns true if the struct was added and then deleted.\n *\n * @param {AbstractStruct} struct\n * @return {boolean}\n */\n deletes (struct) {\n return isDeleted(this.transaction.deleteSet, struct.id)\n }\n\n /**\n * @type {Map<string, { action: 'add' | 'update' | 'delete', oldValue: any, newValue: any }>}\n */\n get keys () {\n if (this._keys === null) {\n if (this.transaction.doc._transactionCleanups.length === 0) {\n throw error.create(errorComputeChanges)\n }\n const keys = new Map()\n const target = this.target\n const changed = /** @type Set<string|null> */ (this.transaction.changed.get(target))\n changed.forEach(key => {\n if (key !== null) {\n const item = /** @type {Item} */ (target._map.get(key))\n /**\n * @type {'delete' | 'add' | 'update'}\n */\n let action\n let oldValue\n if (this.adds(item)) {\n let prev = item.left\n while (prev !== null && this.adds(prev)) {\n prev = prev.left\n }\n if (this.deletes(item)) {\n if (prev !== null && this.deletes(prev)) {\n action = 'delete'\n oldValue = array.last(prev.content.getContent())\n } else {\n return\n }\n } else {\n if (prev !== null && this.deletes(prev)) {\n action = 'update'\n oldValue = array.last(prev.content.getContent())\n } else {\n action = 'add'\n oldValue = undefined\n }\n }\n } else {\n if (this.deletes(item)) {\n action = 'delete'\n oldValue = array.last(/** @type {Item} */ item.content.getContent())\n } else {\n return // nop\n }\n }\n keys.set(key, { action, oldValue })\n }\n })\n this._keys = keys\n }\n return this._keys\n }\n\n /**\n * This is a computed property. Note that this can only be safely computed during the\n * event call. Computing this property after other changes happened might result in\n * unexpected behavior (incorrect computation of deltas). A safe way to collect changes\n * is to store the `changes` or the `delta` object. Avoid storing the `transaction` object.\n *\n * @type {Array<{insert?: string | Array<any> | object | AbstractType<any>, retain?: number, delete?: number, attributes?: Object<string, any>}>}\n */\n get delta () {\n return this.changes.delta\n }\n\n /**\n * Check if a struct is added by this event.\n *\n * In contrast to change.deleted, this method also returns true if the struct was added and then deleted.\n *\n * @param {AbstractStruct} struct\n * @return {boolean}\n */\n adds (struct) {\n return struct.id.clock >= (this.transaction.beforeState.get(struct.id.client) || 0)\n }\n\n /**\n * This is a computed property. Note that this can only be safely computed during the\n * event call. Computing this property after other changes happened might result in\n * unexpected behavior (incorrect computation of deltas). A safe way to collect changes\n * is to store the `changes` or the `delta` object. Avoid storing the `transaction` object.\n *\n * @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert?:Array<any>|string, delete?:number, retain?:number}>}}\n */\n get changes () {\n let changes = this._changes\n if (changes === null) {\n if (this.transaction.doc._transactionCleanups.length === 0) {\n throw error.create(errorComputeChanges)\n }\n const target = this.target\n const added = set.create()\n const deleted = set.create()\n /**\n * @type {Array<{insert:Array<any>}|{delete:number}|{retain:number}>}\n */\n const delta = []\n changes = {\n added,\n deleted,\n delta,\n keys: this.keys\n }\n const changed = /** @type Set<string|null> */ (this.transaction.changed.get(target))\n if (changed.has(null)) {\n /**\n * @type {any}\n */\n let lastOp = null\n const packOp = () => {\n if (lastOp) {\n delta.push(lastOp)\n }\n }\n for (let item = target._start; item !== null; item = item.right) {\n if (item.deleted) {\n if (this.deletes(item) && !this.adds(item)) {\n if (lastOp === null || lastOp.delete === undefined) {\n packOp()\n lastOp = { delete: 0 }\n }\n lastOp.delete += item.length\n deleted.add(item)\n } // else nop\n } else {\n if (this.adds(item)) {\n if (lastOp === null || lastOp.insert === undefined) {\n packOp()\n lastOp = { insert: [] }\n }\n lastOp.insert = lastOp.insert.concat(item.content.getContent())\n added.add(item)\n } else {\n if (lastOp === null || lastOp.retain === undefined) {\n packOp()\n lastOp = { retain: 0 }\n }\n lastOp.retain += item.length\n }\n }\n }\n if (lastOp !== null && lastOp.retain === undefined) {\n packOp()\n }\n }\n this._changes = changes\n }\n return /** @type {any} */ (changes)\n }\n}\n\n/**\n * Compute the path from this type to the specified target.\n *\n * @example\n * // `child` should be accessible via `type.get(path[0]).get(path[1])..`\n * const path = type.getPathTo(child)\n * // assuming `type instanceof YArray`\n * console.log(path) // might look like => [2, 'key1']\n * child === type.get(path[0]).get(path[1])\n *\n * @param {AbstractType<any>} parent\n * @param {AbstractType<any>} child target\n * @return {Array<string|number>} Path to the target\n *\n * @private\n * @function\n */\nconst getPathTo = (parent, child) => {\n const path = []\n while (child._item !== null && child !== parent) {\n if (child._item.parentSub !== null) {\n // parent is map-ish\n path.unshift(child._item.parentSub)\n } else {\n // parent is array-ish\n let i = 0\n let c = /** @type {AbstractType<any>} */ (child._item.parent)._start\n while (c !== child._item && c !== null) {\n if (!c.deleted && c.countable) {\n i += c.length\n }\n c = c.right\n }\n path.unshift(i)\n }\n child = /** @type {AbstractType<any>} */ (child._item.parent)\n }\n return path\n}\n","import {\n removeEventHandlerListener,\n callEventHandlerListeners,\n addEventHandlerListener,\n createEventHandler,\n getState,\n isVisible,\n ContentType,\n createID,\n ContentAny,\n ContentBinary,\n getItemCleanStart,\n ContentDoc, YText, YArray, UpdateEncoderV1, UpdateEncoderV2, Doc, Snapshot, Transaction, EventHandler, YEvent, Item, // eslint-disable-line\n} from '../internals.js'\n\nimport * as map from 'lib0/map'\nimport * as iterator from 'lib0/iterator'\nimport * as error from 'lib0/error'\nimport * as math from 'lib0/math'\nimport * as log from 'lib0/logging'\n\n/**\n * https://docs.yjs.dev/getting-started/working-with-shared-types#caveats\n */\nexport const warnPrematureAccess = () => { log.warn('Invalid access: Add Yjs type to a document before reading data.') }\n\nconst maxSearchMarker = 80\n\n/**\n * A unique timestamp that identifies each marker.\n *\n * Time is relative,.. this is more like an ever-increasing clock.\n *\n * @type {number}\n */\nlet globalSearchMarkerTimestamp = 0\n\nexport class ArraySearchMarker {\n /**\n * @param {Item} p\n * @param {number} index\n */\n constructor (p, index) {\n p.marker = true\n this.p = p\n this.index = index\n this.timestamp = globalSearchMarkerTimestamp++\n }\n}\n\n/**\n * @param {ArraySearchMarker} marker\n */\nconst refreshMarkerTimestamp = marker => { marker.timestamp = globalSearchMarkerTimestamp++ }\n\n/**\n * This is rather complex so this function is the only thing that should overwrite a marker\n *\n * @param {ArraySearchMarker} marker\n * @param {Item} p\n * @param {number} index\n */\nconst overwriteMarker = (marker, p, index) => {\n marker.p.marker = false\n marker.p = p\n p.marker = true\n marker.index = index\n marker.timestamp = globalSearchMarkerTimestamp++\n}\n\n/**\n * @param {Array<ArraySearchMarker>} searchMarker\n * @param {Item} p\n * @param {number} index\n */\nconst markPosition = (searchMarker, p, index) => {\n if (searchMarker.length >= maxSearchMarker) {\n // override oldest marker (we don't want to create more objects)\n const marker = searchMarker.reduce((a, b) => a.timestamp < b.timestamp ? a : b)\n overwriteMarker(marker, p, index)\n return marker\n } else {\n // create new marker\n const pm = new ArraySearchMarker(p, index)\n searchMarker.push(pm)\n return pm\n }\n}\n\n/**\n * Search marker help us to find positions in the associative array faster.\n *\n * They speed up the process of finding a position without much bookkeeping.\n *\n * A maximum of `maxSearchMarker` objects are created.\n *\n * This function always returns a refreshed marker (updated timestamp)\n *\n * @param {AbstractType<any>} yarray\n * @param {number} index\n */\nexport const findMarker = (yarray, index) => {\n if (yarray._start === null || index === 0 || yarray._searchMarker === null) {\n return null\n }\n const marker = yarray._searchMarker.length === 0 ? null : yarray._searchMarker.reduce((a, b) => math.abs(index - a.index) < math.abs(index - b.index) ? a : b)\n let p = yarray._start\n let pindex = 0\n if (marker !== null) {\n p = marker.p\n pindex = marker.index\n refreshMarkerTimestamp(marker) // we used it, we might need to use it again\n }\n // iterate to right if possible\n while (p.right !== null && pindex < index) {\n if (!p.deleted && p.countable) {\n if (index < pindex + p.length) {\n break\n }\n pindex += p.length\n }\n p = p.right\n }\n // iterate to left if necessary (might be that pindex > index)\n while (p.left !== null && pindex > index) {\n p = p.left\n if (!p.deleted && p.countable) {\n pindex -= p.length\n }\n }\n // we want to make sure that p can't be merged with left, because that would screw up everything\n // in that cas just return what we have (it is most likely the best marker anyway)\n // iterate to left until p can't be merged with left\n while (p.left !== null && p.left.id.client === p.id.client && p.left.id.clock + p.left.length === p.id.clock) {\n p = p.left\n if (!p.deleted && p.countable) {\n pindex -= p.length\n }\n }\n\n // @todo remove!\n // assure position\n // {\n // let start = yarray._start\n // let pos = 0\n // while (start !== p) {\n // if (!start.deleted && start.countable) {\n // pos += start.length\n // }\n // start = /** @type {Item} */ (start.right)\n // }\n // if (pos !== pindex) {\n // debugger\n // throw new Error('Gotcha position fail!')\n // }\n // }\n // if (marker) {\n // if (window.lengths == null) {\n // window.lengths = []\n // window.getLengths = () => window.lengths.sort((a, b) => a - b)\n // }\n // window.lengths.push(marker.index - pindex)\n // console.log('distance', marker.index - pindex, 'len', p && p.parent.length)\n // }\n if (marker !== null && math.abs(marker.index - pindex) < /** @type {YText|YArray<any>} */ (p.parent).length / maxSearchMarker) {\n // adjust existing marker\n overwriteMarker(marker, p, pindex)\n return marker\n } else {\n // create new marker\n return markPosition(yarray._searchMarker, p, pindex)\n }\n}\n\n/**\n * Update markers when a change happened.\n *\n * This should be called before doing a deletion!\n *\n * @param {Array<ArraySearchMarker>} searchMarker\n * @param {number} index\n * @param {number} len If insertion, len is positive. If deletion, len is negative.\n */\nexport const updateMarkerChanges = (searchMarker, index, len) => {\n for (let i = searchMarker.length - 1; i >= 0; i--) {\n const m = searchMarker[i]\n if (len > 0) {\n /**\n * @type {Item|null}\n */\n let p = m.p\n p.marker = false\n // Ideally we just want to do a simple position comparison, but this will only work if\n // search markers don't point to deleted items for formats.\n // Iterate marker to prev undeleted countable position so we know what to do when updating a position\n while (p && (p.deleted || !p.countable)) {\n p = p.left\n if (p && !p.deleted && p.countable) {\n // adjust position. the loop should break now\n m.index -= p.length\n }\n }\n if (p === null || p.marker === true) {\n // remove search marker if updated position is null or if position is already marked\n searchMarker.splice(i, 1)\n continue\n }\n m.p = p\n p.marker = true\n }\n if (index < m.index || (len > 0 && index === m.index)) { // a simple index <= m.index check would actually suffice\n m.index = math.max(index, m.index + len)\n }\n }\n}\n\n/**\n * Accumulate all (list) children of a type and return them as an Array.\n *\n * @param {AbstractType<any>} t\n * @return {Array<Item>}\n */\nexport const getTypeChildren = t => {\n t.doc ?? warnPrematureAccess()\n let s = t._start\n const arr = []\n while (s) {\n arr.push(s)\n s = s.right\n }\n return arr\n}\n\n/**\n * Call event listeners with an event. This will also add an event to all\n * parents (for `.observeDeep` handlers).\n *\n * @template EventType\n * @param {AbstractType<EventType>} type\n * @param {Transaction} transaction\n * @param {EventType} event\n */\nexport const callTypeObservers = (type, transaction, event) => {\n const changedType = type\n const changedParentTypes = transaction.changedParentTypes\n while (true) {\n // @ts-ignore\n map.setIfUndefined(changedParentTypes, type, () => []).push(event)\n if (type._item === null) {\n break\n }\n type = /** @type {AbstractType<any>} */ (type._item.parent)\n }\n callEventHandlerListeners(changedType._eH, event, transaction)\n}\n\n/**\n * @template EventType\n * Abstract Yjs Type class\n */\nexport class AbstractType {\n constructor () {\n /**\n * @type {Item|null}\n */\n this._item = null\n /**\n * @type {Map<string,Item>}\n */\n this._map = new Map()\n /**\n * @type {Item|null}\n */\n this._start = null\n /**\n * @type {Doc|null}\n */\n this.doc = null\n this._length = 0\n /**\n * Event handlers\n * @type {EventHandler<EventType,Transaction>}\n */\n this._eH = createEventHandler()\n /**\n * Deep event handlers\n * @type {EventHandler<Array<YEvent<any>>,Transaction>}\n */\n this._dEH = createEventHandler()\n /**\n * @type {null | Array<ArraySearchMarker>}\n */\n this._searchMarker = null\n }\n\n /**\n * @return {AbstractType<any>|null}\n */\n get parent () {\n return this._item ? /** @type {AbstractType<any>} */ (this._item.parent) : null\n }\n\n /**\n * Integrate this type into the Yjs instance.\n *\n * * Save this struct in the os\n * * This type is sent to other client\n * * Observer functions are fired\n *\n * @param {Doc} y The Yjs instance\n * @param {Item|null} item\n */\n _integrate (y, item) {\n this.doc = y\n this._item = item\n }\n\n /**\n * @return {AbstractType<EventType>}\n */\n _copy () {\n throw error.methodUnimplemented()\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {AbstractType<EventType>}\n */\n clone () {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} _encoder\n */\n _write (_encoder) { }\n\n /**\n * The first non-deleted item\n */\n get _first () {\n let n = this._start\n while (n !== null && n.deleted) {\n n = n.right\n }\n return n\n }\n\n /**\n * Creates YEvent and calls all type observers.\n * Must be implemented by each type.\n *\n * @param {Transaction} transaction\n * @param {Set<null|string>} _parentSubs Keys changed on this type. `null` if list was modified.\n */\n _callObserver (transaction, _parentSubs) {\n if (!transaction.local && this._searchMarker) {\n this._searchMarker.length = 0\n }\n }\n\n /**\n * Observe all events that are created on this type.\n *\n * @param {function(EventType, Transaction):void} f Observer function\n */\n observe (f) {\n addEventHandlerListener(this._eH, f)\n }\n\n /**\n * Observe all events that are created by this type and its children.\n *\n * @param {function(Array<YEvent<any>>,Transaction):void} f Observer function\n */\n observeDeep (f) {\n addEventHandlerListener(this._dEH, f)\n }\n\n /**\n * Unregister an observer function.\n *\n * @param {function(EventType,Transaction):void} f Observer function\n */\n unobserve (f) {\n removeEventHandlerListener(this._eH, f)\n }\n\n /**\n * Unregister an observer function.\n *\n * @param {function(Array<YEvent<any>>,Transaction):void} f Observer function\n */\n unobserveDeep (f) {\n removeEventHandlerListener(this._dEH, f)\n }\n\n /**\n * @abstract\n * @return {any}\n */\n toJSON () {}\n}\n\n/**\n * @param {AbstractType<any>} type\n * @param {number} start\n * @param {number} end\n * @return {Array<any>}\n *\n * @private\n * @function\n */\nexport const typeListSlice = (type, start, end) => {\n type.doc ?? warnPrematureAccess()\n if (start < 0) {\n start = type._length + start\n }\n if (end < 0) {\n end = type._length + end\n }\n let len = end - start\n const cs = []\n let n = type._start\n while (n !== null && len > 0) {\n if (n.countable && !n.deleted) {\n const c = n.content.getContent()\n if (c.length <= start) {\n start -= c.length\n } else {\n for (let i = start; i < c.length && len > 0; i++) {\n cs.push(c[i])\n len--\n }\n start = 0\n }\n }\n n = n.right\n }\n return cs\n}\n\n/**\n * @param {AbstractType<any>} type\n * @return {Array<any>}\n *\n * @private\n * @function\n */\nexport const typeListToArray = type => {\n type.doc ?? warnPrematureAccess()\n const cs = []\n let n = type._start\n while (n !== null) {\n if (n.countable && !n.deleted) {\n const c = n.content.getContent()\n for (let i = 0; i < c.length; i++) {\n cs.push(c[i])\n }\n }\n n = n.right\n }\n return cs\n}\n\n/**\n * @param {AbstractType<any>} type\n * @param {Snapshot} snapshot\n * @return {Array<any>}\n *\n * @private\n * @function\n */\nexport const typeListToArraySnapshot = (type, snapshot) => {\n const cs = []\n let n = type._start\n while (n !== null) {\n if (n.countable && isVisible(n, snapshot)) {\n const c = n.content.getContent()\n for (let i = 0; i < c.length; i++) {\n cs.push(c[i])\n }\n }\n n = n.right\n }\n return cs\n}\n\n/**\n * Executes a provided function on once on every element of this YArray.\n *\n * @param {AbstractType<any>} type\n * @param {function(any,number,any):void} f A function to execute on every element of this YArray.\n *\n * @private\n * @function\n */\nexport const typeListForEach = (type, f) => {\n let index = 0\n let n = type._start\n type.doc ?? warnPrematureAccess()\n while (n !== null) {\n if (n.countable && !n.deleted) {\n const c = n.content.getContent()\n for (let i = 0; i < c.length; i++) {\n f(c[i], index++, type)\n }\n }\n n = n.right\n }\n}\n\n/**\n * @template C,R\n * @param {AbstractType<any>} type\n * @param {function(C,number,AbstractType<any>):R} f\n * @return {Array<R>}\n *\n * @private\n * @function\n */\nexport const typeListMap = (type, f) => {\n /**\n * @type {Array<any>}\n */\n const result = []\n typeListForEach(type, (c, i) => {\n result.push(f(c, i, type))\n })\n return result\n}\n\n/**\n * @param {AbstractType<any>} type\n * @return {IterableIterator<any>}\n *\n * @private\n * @function\n */\nexport const typeListCreateIterator = type => {\n let n = type._start\n /**\n * @type {Array<any>|null}\n */\n let currentContent = null\n let currentContentIndex = 0\n return {\n [Symbol.iterator] () {\n return this\n },\n next: () => {\n // find some content\n if (currentContent === null) {\n while (n !== null && n.deleted) {\n n = n.right\n }\n // check if we reached the end, no need to check currentContent, because it does not exist\n if (n === null) {\n return {\n done: true,\n value: undefined\n }\n }\n // we found n, so we can set currentContent\n currentContent = n.content.getContent()\n currentContentIndex = 0\n n = n.right // we used the content of n, now iterate to next\n }\n const value = currentContent[currentContentIndex++]\n // check if we need to empty currentContent\n if (currentContent.length <= currentContentIndex) {\n currentContent = null\n }\n return {\n done: false,\n value\n }\n }\n }\n}\n\n/**\n * Executes a provided function on once on every element of this YArray.\n * Operates on a snapshotted state of the document.\n *\n * @param {AbstractType<any>} type\n * @param {function(any,number,AbstractType<any>):void} f A function to execute on every element of this YArray.\n * @param {Snapshot} snapshot\n *\n * @private\n * @function\n */\nexport const typeListForEachSnapshot = (type, f, snapshot) => {\n let index = 0\n let n = type._start\n while (n !== null) {\n if (n.countable && isVisible(n, snapshot)) {\n const c = n.content.getContent()\n for (let i = 0; i < c.length; i++) {\n f(c[i], index++, type)\n }\n }\n n = n.right\n }\n}\n\n/**\n * @param {AbstractType<any>} type\n * @param {number} index\n * @return {any}\n *\n * @private\n * @function\n */\nexport const typeListGet = (type, index) => {\n type.doc ?? warnPrematureAccess()\n const marker = findMarker(type, index)\n let n = type._start\n if (marker !== null) {\n n = marker.p\n index -= marker.index\n }\n for (; n !== null; n = n.right) {\n if (!n.deleted && n.countable) {\n if (index < n.length) {\n return n.content.getContent()[index]\n }\n index -= n.length\n }\n }\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {Item?} referenceItem\n * @param {Array<Object<string,any>|Array<any>|boolean|number|null|string|Uint8Array>} content\n *\n * @private\n * @function\n */\nexport const typeListInsertGenericsAfter = (transaction, parent, referenceItem, content) => {\n let left = referenceItem\n const doc = transaction.doc\n const ownClientId = doc.clientID\n const store = doc.store\n const right = referenceItem === null ? parent._start : referenceItem.right\n /**\n * @type {Array<Object|Array<any>|number|null>}\n */\n let jsonContent = []\n const packJsonContent = () => {\n if (jsonContent.length > 0) {\n left = new Item(createID(ownClientId, getState(store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentAny(jsonContent))\n left.integrate(transaction, 0)\n jsonContent = []\n }\n }\n content.forEach(c => {\n if (c === null) {\n jsonContent.push(c)\n } else {\n switch (c.constructor) {\n case Number:\n case Object:\n case Boolean:\n case Array:\n case String:\n jsonContent.push(c)\n break\n default:\n packJsonContent()\n switch (c.constructor) {\n case Uint8Array:\n case ArrayBuffer:\n left = new Item(createID(ownClientId, getState(store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentBinary(new Uint8Array(/** @type {Uint8Array} */ (c))))\n left.integrate(transaction, 0)\n break\n case Doc:\n left = new Item(createID(ownClientId, getState(store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentDoc(/** @type {Doc} */ (c)))\n left.integrate(transaction, 0)\n break\n default:\n if (c instanceof AbstractType) {\n left = new Item(createID(ownClientId, getState(store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentType(c))\n left.integrate(transaction, 0)\n } else {\n throw new Error('Unexpected content type in insert operation')\n }\n }\n }\n }\n })\n packJsonContent()\n}\n\nconst lengthExceeded = () => error.create('Length exceeded!')\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {number} index\n * @param {Array<Object<string,any>|Array<any>|number|null|string|Uint8Array>} content\n *\n * @private\n * @function\n */\nexport const typeListInsertGenerics = (transaction, parent, index, content) => {\n if (index > parent._length) {\n throw lengthExceeded()\n }\n if (index === 0) {\n if (parent._searchMarker) {\n updateMarkerChanges(parent._searchMarker, index, content.length)\n }\n return typeListInsertGenericsAfter(transaction, parent, null, content)\n }\n const startIndex = index\n const marker = findMarker(parent, index)\n let n = parent._start\n if (marker !== null) {\n n = marker.p\n index -= marker.index\n // we need to iterate one to the left so that the algorithm works\n if (index === 0) {\n // @todo refactor this as it actually doesn't consider formats\n n = n.prev // important! get the left undeleted item so that we can actually decrease index\n index += (n && n.countable && !n.deleted) ? n.length : 0\n }\n }\n for (; n !== null; n = n.right) {\n if (!n.deleted && n.countable) {\n if (index <= n.length) {\n if (index < n.length) {\n // insert in-between\n getItemCleanStart(transaction, createID(n.id.client, n.id.clock + index))\n }\n break\n }\n index -= n.length\n }\n }\n if (parent._searchMarker) {\n updateMarkerChanges(parent._searchMarker, startIndex, content.length)\n }\n return typeListInsertGenericsAfter(transaction, parent, n, content)\n}\n\n/**\n * Pushing content is special as we generally want to push after the last item. So we don't have to update\n * the search marker.\n *\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {Array<Object<string,any>|Array<any>|number|null|string|Uint8Array>} content\n *\n * @private\n * @function\n */\nexport const typeListPushGenerics = (transaction, parent, content) => {\n // Use the marker with the highest index and iterate to the right.\n const marker = (parent._searchMarker || []).reduce((maxMarker, currMarker) => currMarker.index > maxMarker.index ? currMarker : maxMarker, { index: 0, p: parent._start })\n let n = marker.p\n if (n) {\n while (n.right) {\n n = n.right\n }\n }\n return typeListInsertGenericsAfter(transaction, parent, n, content)\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {number} index\n * @param {number} length\n *\n * @private\n * @function\n */\nexport const typeListDelete = (transaction, parent, index, length) => {\n if (length === 0) { return }\n const startIndex = index\n const startLength = length\n const marker = findMarker(parent, index)\n let n = parent._start\n if (marker !== null) {\n n = marker.p\n index -= marker.index\n }\n // compute the first item to be deleted\n for (; n !== null && index > 0; n = n.right) {\n if (!n.deleted && n.countable) {\n if (index < n.length) {\n getItemCleanStart(transaction, createID(n.id.client, n.id.clock + index))\n }\n index -= n.length\n }\n }\n // delete all items until done\n while (length > 0 && n !== null) {\n if (!n.deleted) {\n if (length < n.length) {\n getItemCleanStart(transaction, createID(n.id.client, n.id.clock + length))\n }\n n.delete(transaction)\n length -= n.length\n }\n n = n.right\n }\n if (length > 0) {\n throw lengthExceeded()\n }\n if (parent._searchMarker) {\n updateMarkerChanges(parent._searchMarker, startIndex, -startLength + length /* in case we remove the above exception */)\n }\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {string} key\n *\n * @private\n * @function\n */\nexport const typeMapDelete = (transaction, parent, key) => {\n const c = parent._map.get(key)\n if (c !== undefined) {\n c.delete(transaction)\n }\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {string} key\n * @param {Object|number|null|Array<any>|string|Uint8Array|AbstractType<any>} value\n *\n * @private\n * @function\n */\nexport const typeMapSet = (transaction, parent, key, value) => {\n const left = parent._map.get(key) || null\n const doc = transaction.doc\n const ownClientId = doc.clientID\n let content\n if (value == null) {\n content = new ContentAny([value])\n } else {\n switch (value.constructor) {\n case Number:\n case Object:\n case Boolean:\n case Array:\n case String:\n case Date:\n case BigInt:\n content = new ContentAny([value])\n break\n case Uint8Array:\n content = new ContentBinary(/** @type {Uint8Array} */ (value))\n break\n case Doc:\n content = new ContentDoc(/** @type {Doc} */ (value))\n break\n default:\n if (value instanceof AbstractType) {\n content = new ContentType(value)\n } else {\n throw new Error('Unexpected content type')\n }\n }\n }\n new Item(createID(ownClientId, getState(doc.store, ownClientId)), left, left && left.lastId, null, null, parent, key, content).integrate(transaction, 0)\n}\n\n/**\n * @param {AbstractType<any>} parent\n * @param {string} key\n * @return {Object<string,any>|number|null|Array<any>|string|Uint8Array|AbstractType<any>|undefined}\n *\n * @private\n * @function\n */\nexport const typeMapGet = (parent, key) => {\n parent.doc ?? warnPrematureAccess()\n const val = parent._map.get(key)\n return val !== undefined && !val.deleted ? val.content.getContent()[val.length - 1] : undefined\n}\n\n/**\n * @param {AbstractType<any>} parent\n * @return {Object<string,Object<string,any>|number|null|Array<any>|string|Uint8Array|AbstractType<any>|undefined>}\n *\n * @private\n * @function\n */\nexport const typeMapGetAll = (parent) => {\n /**\n * @type {Object<string,any>}\n */\n const res = {}\n parent.doc ?? warnPrematureAccess()\n parent._map.forEach((value, key) => {\n if (!value.deleted) {\n res[key] = value.content.getContent()[value.length - 1]\n }\n })\n return res\n}\n\n/**\n * @param {AbstractType<any>} parent\n * @param {string} key\n * @return {boolean}\n *\n * @private\n * @function\n */\nexport const typeMapHas = (parent, key) => {\n parent.doc ?? warnPrematureAccess()\n const val = parent._map.get(key)\n return val !== undefined && !val.deleted\n}\n\n/**\n * @param {AbstractType<any>} parent\n * @param {string} key\n * @param {Snapshot} snapshot\n * @return {Object<string,any>|number|null|Array<any>|string|Uint8Array|AbstractType<any>|undefined}\n *\n * @private\n * @function\n */\nexport const typeMapGetSnapshot = (parent, key, snapshot) => {\n let v = parent._map.get(key) || null\n while (v !== null && (!snapshot.sv.has(v.id.client) || v.id.clock >= (snapshot.sv.get(v.id.client) || 0))) {\n v = v.left\n }\n return v !== null && isVisible(v, snapshot) ? v.content.getContent()[v.length - 1] : undefined\n}\n\n/**\n * @param {AbstractType<any>} parent\n * @param {Snapshot} snapshot\n * @return {Object<string,Object<string,any>|number|null|Array<any>|string|Uint8Array|AbstractType<any>|undefined>}\n *\n * @private\n * @function\n */\nexport const typeMapGetAllSnapshot = (parent, snapshot) => {\n /**\n * @type {Object<string,any>}\n */\n const res = {}\n parent._map.forEach((value, key) => {\n /**\n * @type {Item|null}\n */\n let v = value\n while (v !== null && (!snapshot.sv.has(v.id.client) || v.id.clock >= (snapshot.sv.get(v.id.client) || 0))) {\n v = v.left\n }\n if (v !== null && isVisible(v, snapshot)) {\n res[key] = v.content.getContent()[v.length - 1]\n }\n })\n return res\n}\n\n/**\n * @param {AbstractType<any> & { _map: Map<string, Item> }} type\n * @return {IterableIterator<Array<any>>}\n *\n * @private\n * @function\n */\nexport const createMapIterator = type => {\n type.doc ?? warnPrematureAccess()\n return iterator.iteratorFilter(type._map.entries(), /** @param {any} entry */ entry => !entry[1].deleted)\n}\n","/**\n * @module YArray\n */\n\nimport {\n YEvent,\n AbstractType,\n typeListGet,\n typeListToArray,\n typeListForEach,\n typeListCreateIterator,\n typeListInsertGenerics,\n typeListPushGenerics,\n typeListDelete,\n typeListMap,\n YArrayRefID,\n callTypeObservers,\n transact,\n warnPrematureAccess,\n ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item // eslint-disable-line\n} from '../internals.js'\nimport { typeListSlice } from './AbstractType.js'\n\n/**\n * Event that describes the changes on a YArray\n * @template T\n * @extends YEvent<YArray<T>>\n */\nexport class YArrayEvent extends YEvent {}\n\n/**\n * A shared Array implementation.\n * @template T\n * @extends AbstractType<YArrayEvent<T>>\n * @implements {Iterable<T>}\n */\nexport class YArray extends AbstractType {\n constructor () {\n super()\n /**\n * @type {Array<any>?}\n * @private\n */\n this._prelimContent = []\n /**\n * @type {Array<ArraySearchMarker>}\n */\n this._searchMarker = []\n }\n\n /**\n * Construct a new YArray containing the specified items.\n * @template {Object<string,any>|Array<any>|number|null|string|Uint8Array} T\n * @param {Array<T>} items\n * @return {YArray<T>}\n */\n static from (items) {\n /**\n * @type {YArray<T>}\n */\n const a = new YArray()\n a.push(items)\n return a\n }\n\n /**\n * Integrate this type into the Yjs instance.\n *\n * * Save this struct in the os\n * * This type is sent to other client\n * * Observer functions are fired\n *\n * @param {Doc} y The Yjs instance\n * @param {Item} item\n */\n _integrate (y, item) {\n super._integrate(y, item)\n this.insert(0, /** @type {Array<any>} */ (this._prelimContent))\n this._prelimContent = null\n }\n\n /**\n * @return {YArray<T>}\n */\n _copy () {\n return new YArray()\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YArray<T>}\n */\n clone () {\n /**\n * @type {YArray<T>}\n */\n const arr = new YArray()\n arr.insert(0, this.toArray().map(el =>\n el instanceof AbstractType ? /** @type {typeof el} */ (el.clone()) : el\n ))\n return arr\n }\n\n get length () {\n this.doc ?? warnPrematureAccess()\n return this._length\n }\n\n /**\n * Creates YArrayEvent and calls observers.\n *\n * @param {Transaction} transaction\n * @param {Set<null|string>} parentSubs Keys changed on this type. `null` if list was modified.\n */\n _callObserver (transaction, parentSubs) {\n super._callObserver(transaction, parentSubs)\n callTypeObservers(this, transaction, new YArrayEvent(this, transaction))\n }\n\n /**\n * Inserts new content at an index.\n *\n * Important: This function expects an array of content. Not just a content\n * object. The reason for this \"weirdness\" is that inserting several elements\n * is very efficient when it is done as a single operation.\n *\n * @example\n * // Insert character 'a' at position 0\n * yarray.insert(0, ['a'])\n * // Insert numbers 1, 2 at position 1\n * yarray.insert(1, [1, 2])\n *\n * @param {number} index The index to insert content at.\n * @param {Array<T>} content The array of content\n */\n insert (index, content) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeListInsertGenerics(transaction, this, index, /** @type {any} */ (content))\n })\n } else {\n /** @type {Array<any>} */ (this._prelimContent).splice(index, 0, ...content)\n }\n }\n\n /**\n * Appends content to this YArray.\n *\n * @param {Array<T>} content Array of content to append.\n *\n * @todo Use the following implementation in all types.\n */\n push (content) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeListPushGenerics(transaction, this, /** @type {any} */ (content))\n })\n } else {\n /** @type {Array<any>} */ (this._prelimContent).push(...content)\n }\n }\n\n /**\n * Prepends content to this YArray.\n *\n * @param {Array<T>} content Array of content to prepend.\n */\n unshift (content) {\n this.insert(0, content)\n }\n\n /**\n * Deletes elements starting from an index.\n *\n * @param {number} index Index at which to start deleting elements\n * @param {number} length The number of elements to remove. Defaults to 1.\n */\n delete (index, length = 1) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeListDelete(transaction, this, index, length)\n })\n } else {\n /** @type {Array<any>} */ (this._prelimContent).splice(index, length)\n }\n }\n\n /**\n * Returns the i-th element from a YArray.\n *\n * @param {number} index The index of the element to return from the YArray\n * @return {T}\n */\n get (index) {\n return typeListGet(this, index)\n }\n\n /**\n * Transforms this YArray to a JavaScript Array.\n *\n * @return {Array<T>}\n */\n toArray () {\n return typeListToArray(this)\n }\n\n /**\n * Returns a portion of this YArray into a JavaScript Array selected\n * from start to end (end not included).\n *\n * @param {number} [start]\n * @param {number} [end]\n * @return {Array<T>}\n */\n slice (start = 0, end = this.length) {\n return typeListSlice(this, start, end)\n }\n\n /**\n * Transforms this Shared Type to a JSON object.\n *\n * @return {Array<any>}\n */\n toJSON () {\n return this.map(c => c instanceof AbstractType ? c.toJSON() : c)\n }\n\n /**\n * Returns an Array with the result of calling a provided function on every\n * element of this YArray.\n *\n * @template M\n * @param {function(T,number,YArray<T>):M} f Function that produces an element of the new Array\n * @return {Array<M>} A new array with each element being the result of the\n * callback function\n */\n map (f) {\n return typeListMap(this, /** @type {any} */ (f))\n }\n\n /**\n * Executes a provided function once on every element of this YArray.\n *\n * @param {function(T,number,YArray<T>):void} f A function to execute on every element of this YArray.\n */\n forEach (f) {\n typeListForEach(this, f)\n }\n\n /**\n * @return {IterableIterator<T>}\n */\n [Symbol.iterator] () {\n return typeListCreateIterator(this)\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n */\n _write (encoder) {\n encoder.writeTypeRef(YArrayRefID)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder\n *\n * @private\n * @function\n */\nexport const readYArray = _decoder => new YArray()\n","/**\n * @module YMap\n */\n\nimport {\n YEvent,\n AbstractType,\n typeMapDelete,\n typeMapSet,\n typeMapGet,\n typeMapHas,\n createMapIterator,\n YMapRefID,\n callTypeObservers,\n transact,\n warnPrematureAccess,\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item // eslint-disable-line\n} from '../internals.js'\n\nimport * as iterator from 'lib0/iterator'\n\n/**\n * @template T\n * @extends YEvent<YMap<T>>\n * Event that describes the changes on a YMap.\n */\nexport class YMapEvent extends YEvent {\n /**\n * @param {YMap<T>} ymap The YArray that changed.\n * @param {Transaction} transaction\n * @param {Set<any>} subs The keys that changed.\n */\n constructor (ymap, transaction, subs) {\n super(ymap, transaction)\n this.keysChanged = subs\n }\n}\n\n/**\n * @template MapType\n * A shared Map implementation.\n *\n * @extends AbstractType<YMapEvent<MapType>>\n * @implements {Iterable<[string, MapType]>}\n */\nexport class YMap extends AbstractType {\n /**\n *\n * @param {Iterable<readonly [string, any]>=} entries - an optional iterable to initialize the YMap\n */\n constructor (entries) {\n super()\n /**\n * @type {Map<string,any>?}\n * @private\n */\n this._prelimContent = null\n\n if (entries === undefined) {\n this._prelimContent = new Map()\n } else {\n this._prelimContent = new Map(entries)\n }\n }\n\n /**\n * Integrate this type into the Yjs instance.\n *\n * * Save this struct in the os\n * * This type is sent to other client\n * * Observer functions are fired\n *\n * @param {Doc} y The Yjs instance\n * @param {Item} item\n */\n _integrate (y, item) {\n super._integrate(y, item)\n ;/** @type {Map<string, any>} */ (this._prelimContent).forEach((value, key) => {\n this.set(key, value)\n })\n this._prelimContent = null\n }\n\n /**\n * @return {YMap<MapType>}\n */\n _copy () {\n return new YMap()\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YMap<MapType>}\n */\n clone () {\n /**\n * @type {YMap<MapType>}\n */\n const map = new YMap()\n this.forEach((value, key) => {\n map.set(key, value instanceof AbstractType ? /** @type {typeof value} */ (value.clone()) : value)\n })\n return map\n }\n\n /**\n * Creates YMapEvent and calls observers.\n *\n * @param {Transaction} transaction\n * @param {Set<null|string>} parentSubs Keys changed on this type. `null` if list was modified.\n */\n _callObserver (transaction, parentSubs) {\n callTypeObservers(this, transaction, new YMapEvent(this, transaction, parentSubs))\n }\n\n /**\n * Transforms this Shared Type to a JSON object.\n *\n * @return {Object<string,any>}\n */\n toJSON () {\n this.doc ?? warnPrematureAccess()\n /**\n * @type {Object<string,MapType>}\n */\n const map = {}\n this._map.forEach((item, key) => {\n if (!item.deleted) {\n const v = item.content.getContent()[item.length - 1]\n map[key] = v instanceof AbstractType ? v.toJSON() : v\n }\n })\n return map\n }\n\n /**\n * Returns the size of the YMap (count of key/value pairs)\n *\n * @return {number}\n */\n get size () {\n return [...createMapIterator(this)].length\n }\n\n /**\n * Returns the keys for each element in the YMap Type.\n *\n * @return {IterableIterator<string>}\n */\n keys () {\n return iterator.iteratorMap(createMapIterator(this), /** @param {any} v */ v => v[0])\n }\n\n /**\n * Returns the values for each element in the YMap Type.\n *\n * @return {IterableIterator<MapType>}\n */\n values () {\n return iterator.iteratorMap(createMapIterator(this), /** @param {any} v */ v => v[1].content.getContent()[v[1].length - 1])\n }\n\n /**\n * Returns an Iterator of [key, value] pairs\n *\n * @return {IterableIterator<[string, MapType]>}\n */\n entries () {\n return iterator.iteratorMap(createMapIterator(this), /** @param {any} v */ v => /** @type {any} */ ([v[0], v[1].content.getContent()[v[1].length - 1]]))\n }\n\n /**\n * Executes a provided function on once on every key-value pair.\n *\n * @param {function(MapType,string,YMap<MapType>):void} f A function to execute on every element of this YArray.\n */\n forEach (f) {\n this.doc ?? warnPrematureAccess()\n this._map.forEach((item, key) => {\n if (!item.deleted) {\n f(item.content.getContent()[item.length - 1], key, this)\n }\n })\n }\n\n /**\n * Returns an Iterator of [key, value] pairs\n *\n * @return {IterableIterator<[string, MapType]>}\n */\n [Symbol.iterator] () {\n return this.entries()\n }\n\n /**\n * Remove a specified element from this YMap.\n *\n * @param {string} key The key of the element to remove.\n */\n delete (key) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeMapDelete(transaction, this, key)\n })\n } else {\n /** @type {Map<string, any>} */ (this._prelimContent).delete(key)\n }\n }\n\n /**\n * Adds or updates an element with a specified key and value.\n * @template {MapType} VAL\n *\n * @param {string} key The key of the element to add to this YMap\n * @param {VAL} value The value of the element to add\n * @return {VAL}\n */\n set (key, value) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeMapSet(transaction, this, key, /** @type {any} */ (value))\n })\n } else {\n /** @type {Map<string, any>} */ (this._prelimContent).set(key, value)\n }\n return value\n }\n\n /**\n * Returns a specified element from this YMap.\n *\n * @param {string} key\n * @return {MapType|undefined}\n */\n get (key) {\n return /** @type {any} */ (typeMapGet(this, key))\n }\n\n /**\n * Returns a boolean indicating whether the specified key exists or not.\n *\n * @param {string} key The key to test.\n * @return {boolean}\n */\n has (key) {\n return typeMapHas(this, key)\n }\n\n /**\n * Removes all elements from this YMap.\n */\n clear () {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n this.forEach(function (_value, key, map) {\n typeMapDelete(transaction, map, key)\n })\n })\n } else {\n /** @type {Map<string, any>} */ (this._prelimContent).clear()\n }\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n */\n _write (encoder) {\n encoder.writeTypeRef(YMapRefID)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder\n *\n * @private\n * @function\n */\nexport const readYMap = _decoder => new YMap()\n","/**\n * @module YText\n */\n\nimport {\n YEvent,\n AbstractType,\n getItemCleanStart,\n getState,\n isVisible,\n createID,\n YTextRefID,\n callTypeObservers,\n transact,\n ContentEmbed,\n GC,\n ContentFormat,\n ContentString,\n splitSnapshotAffectedStructs,\n iterateDeletedStructs,\n iterateStructs,\n findMarker,\n typeMapDelete,\n typeMapSet,\n typeMapGet,\n typeMapGetAll,\n updateMarkerChanges,\n ContentType,\n warnPrematureAccess,\n ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ID, Doc, Item, Snapshot, Transaction // eslint-disable-line\n} from '../internals.js'\n\nimport * as object from 'lib0/object'\nimport * as map from 'lib0/map'\nimport * as error from 'lib0/error'\n\n/**\n * @param {any} a\n * @param {any} b\n * @return {boolean}\n */\nconst equalAttrs = (a, b) => a === b || (typeof a === 'object' && typeof b === 'object' && a && b && object.equalFlat(a, b))\n\nexport class ItemTextListPosition {\n /**\n * @param {Item|null} left\n * @param {Item|null} right\n * @param {number} index\n * @param {Map<string,any>} currentAttributes\n */\n constructor (left, right, index, currentAttributes) {\n this.left = left\n this.right = right\n this.index = index\n this.currentAttributes = currentAttributes\n }\n\n /**\n * Only call this if you know that this.right is defined\n */\n forward () {\n if (this.right === null) {\n error.unexpectedCase()\n }\n switch (this.right.content.constructor) {\n case ContentFormat:\n if (!this.right.deleted) {\n updateCurrentAttributes(this.currentAttributes, /** @type {ContentFormat} */ (this.right.content))\n }\n break\n default:\n if (!this.right.deleted) {\n this.index += this.right.length\n }\n break\n }\n this.left = this.right\n this.right = this.right.right\n }\n}\n\n/**\n * @param {Transaction} transaction\n * @param {ItemTextListPosition} pos\n * @param {number} count steps to move forward\n * @return {ItemTextListPosition}\n *\n * @private\n * @function\n */\nconst findNextPosition = (transaction, pos, count) => {\n while (pos.right !== null && count > 0) {\n switch (pos.right.content.constructor) {\n case ContentFormat:\n if (!pos.right.deleted) {\n updateCurrentAttributes(pos.currentAttributes, /** @type {ContentFormat} */ (pos.right.content))\n }\n break\n default:\n if (!pos.right.deleted) {\n if (count < pos.right.length) {\n // split right\n getItemCleanStart(transaction, createID(pos.right.id.client, pos.right.id.clock + count))\n }\n pos.index += pos.right.length\n count -= pos.right.length\n }\n break\n }\n pos.left = pos.right\n pos.right = pos.right.right\n // pos.forward() - we don't forward because that would halve the performance because we already do the checks above\n }\n return pos\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {number} index\n * @param {boolean} useSearchMarker\n * @return {ItemTextListPosition}\n *\n * @private\n * @function\n */\nconst findPosition = (transaction, parent, index, useSearchMarker) => {\n const currentAttributes = new Map()\n const marker = useSearchMarker ? findMarker(parent, index) : null\n if (marker) {\n const pos = new ItemTextListPosition(marker.p.left, marker.p, marker.index, currentAttributes)\n return findNextPosition(transaction, pos, index - marker.index)\n } else {\n const pos = new ItemTextListPosition(null, parent._start, 0, currentAttributes)\n return findNextPosition(transaction, pos, index)\n }\n}\n\n/**\n * Negate applied formats\n *\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {ItemTextListPosition} currPos\n * @param {Map<string,any>} negatedAttributes\n *\n * @private\n * @function\n */\nconst insertNegatedAttributes = (transaction, parent, currPos, negatedAttributes) => {\n // check if we really need to remove attributes\n while (\n currPos.right !== null && (\n currPos.right.deleted === true || (\n currPos.right.content.constructor === ContentFormat &&\n equalAttrs(negatedAttributes.get(/** @type {ContentFormat} */ (currPos.right.content).key), /** @type {ContentFormat} */ (currPos.right.content).value)\n )\n )\n ) {\n if (!currPos.right.deleted) {\n negatedAttributes.delete(/** @type {ContentFormat} */ (currPos.right.content).key)\n }\n currPos.forward()\n }\n const doc = transaction.doc\n const ownClientId = doc.clientID\n negatedAttributes.forEach((val, key) => {\n const left = currPos.left\n const right = currPos.right\n const nextFormat = new Item(createID(ownClientId, getState(doc.store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentFormat(key, val))\n nextFormat.integrate(transaction, 0)\n currPos.right = nextFormat\n currPos.forward()\n })\n}\n\n/**\n * @param {Map<string,any>} currentAttributes\n * @param {ContentFormat} format\n *\n * @private\n * @function\n */\nconst updateCurrentAttributes = (currentAttributes, format) => {\n const { key, value } = format\n if (value === null) {\n currentAttributes.delete(key)\n } else {\n currentAttributes.set(key, value)\n }\n}\n\n/**\n * @param {ItemTextListPosition} currPos\n * @param {Object<string,any>} attributes\n *\n * @private\n * @function\n */\nconst minimizeAttributeChanges = (currPos, attributes) => {\n // go right while attributes[right.key] === right.value (or right is deleted)\n while (true) {\n if (currPos.right === null) {\n break\n } else if (currPos.right.deleted || (currPos.right.content.constructor === ContentFormat && equalAttrs(attributes[(/** @type {ContentFormat} */ (currPos.right.content)).key] ?? null, /** @type {ContentFormat} */ (currPos.right.content).value))) {\n //\n } else {\n break\n }\n currPos.forward()\n }\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {ItemTextListPosition} currPos\n * @param {Object<string,any>} attributes\n * @return {Map<string,any>}\n *\n * @private\n * @function\n **/\nconst insertAttributes = (transaction, parent, currPos, attributes) => {\n const doc = transaction.doc\n const ownClientId = doc.clientID\n const negatedAttributes = new Map()\n // insert format-start items\n for (const key in attributes) {\n const val = attributes[key]\n const currentVal = currPos.currentAttributes.get(key) ?? null\n if (!equalAttrs(currentVal, val)) {\n // save negated attribute (set null if currentVal undefined)\n negatedAttributes.set(key, currentVal)\n const { left, right } = currPos\n currPos.right = new Item(createID(ownClientId, getState(doc.store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentFormat(key, val))\n currPos.right.integrate(transaction, 0)\n currPos.forward()\n }\n }\n return negatedAttributes\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {ItemTextListPosition} currPos\n * @param {string|object|AbstractType<any>} text\n * @param {Object<string,any>} attributes\n *\n * @private\n * @function\n **/\nconst insertText = (transaction, parent, currPos, text, attributes) => {\n currPos.currentAttributes.forEach((_val, key) => {\n if (attributes[key] === undefined) {\n attributes[key] = null\n }\n })\n const doc = transaction.doc\n const ownClientId = doc.clientID\n minimizeAttributeChanges(currPos, attributes)\n const negatedAttributes = insertAttributes(transaction, parent, currPos, attributes)\n // insert content\n const content = text.constructor === String ? new ContentString(/** @type {string} */ (text)) : (text instanceof AbstractType ? new ContentType(text) : new ContentEmbed(text))\n let { left, right, index } = currPos\n if (parent._searchMarker) {\n updateMarkerChanges(parent._searchMarker, currPos.index, content.getLength())\n }\n right = new Item(createID(ownClientId, getState(doc.store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, content)\n right.integrate(transaction, 0)\n currPos.right = right\n currPos.index = index\n currPos.forward()\n insertNegatedAttributes(transaction, parent, currPos, negatedAttributes)\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {ItemTextListPosition} currPos\n * @param {number} length\n * @param {Object<string,any>} attributes\n *\n * @private\n * @function\n */\nconst formatText = (transaction, parent, currPos, length, attributes) => {\n const doc = transaction.doc\n const ownClientId = doc.clientID\n minimizeAttributeChanges(currPos, attributes)\n const negatedAttributes = insertAttributes(transaction, parent, currPos, attributes)\n // iterate until first non-format or null is found\n // delete all formats with attributes[format.key] != null\n // also check the attributes after the first non-format as we do not want to insert redundant negated attributes there\n // eslint-disable-next-line no-labels\n iterationLoop: while (\n currPos.right !== null &&\n (length > 0 ||\n (\n negatedAttributes.size > 0 &&\n (currPos.right.deleted || currPos.right.content.constructor === ContentFormat)\n )\n )\n ) {\n if (!currPos.right.deleted) {\n switch (currPos.right.content.constructor) {\n case ContentFormat: {\n const { key, value } = /** @type {ContentFormat} */ (currPos.right.content)\n const attr = attributes[key]\n if (attr !== undefined) {\n if (equalAttrs(attr, value)) {\n negatedAttributes.delete(key)\n } else {\n if (length === 0) {\n // no need to further extend negatedAttributes\n // eslint-disable-next-line no-labels\n break iterationLoop\n }\n negatedAttributes.set(key, value)\n }\n currPos.right.delete(transaction)\n } else {\n currPos.currentAttributes.set(key, value)\n }\n break\n }\n default:\n if (length < currPos.right.length) {\n getItemCleanStart(transaction, createID(currPos.right.id.client, currPos.right.id.clock + length))\n }\n length -= currPos.right.length\n break\n }\n }\n currPos.forward()\n }\n // Quill just assumes that the editor starts with a newline and that it always\n // ends with a newline. We only insert that newline when a new newline is\n // inserted - i.e when length is bigger than type.length\n if (length > 0) {\n let newlines = ''\n for (; length > 0; length--) {\n newlines += '\\n'\n }\n currPos.right = new Item(createID(ownClientId, getState(doc.store, ownClientId)), currPos.left, currPos.left && currPos.left.lastId, currPos.right, currPos.right && currPos.right.id, parent, null, new ContentString(newlines))\n currPos.right.integrate(transaction, 0)\n currPos.forward()\n }\n insertNegatedAttributes(transaction, parent, currPos, negatedAttributes)\n}\n\n/**\n * Call this function after string content has been deleted in order to\n * clean up formatting Items.\n *\n * @param {Transaction} transaction\n * @param {Item} start\n * @param {Item|null} curr exclusive end, automatically iterates to the next Content Item\n * @param {Map<string,any>} startAttributes\n * @param {Map<string,any>} currAttributes\n * @return {number} The amount of formatting Items deleted.\n *\n * @function\n */\nconst cleanupFormattingGap = (transaction, start, curr, startAttributes, currAttributes) => {\n /**\n * @type {Item|null}\n */\n let end = start\n /**\n * @type {Map<string,ContentFormat>}\n */\n const endFormats = map.create()\n while (end && (!end.countable || end.deleted)) {\n if (!end.deleted && end.content.constructor === ContentFormat) {\n const cf = /** @type {ContentFormat} */ (end.content)\n endFormats.set(cf.key, cf)\n }\n end = end.right\n }\n let cleanups = 0\n let reachedCurr = false\n while (start !== end) {\n if (curr === start) {\n reachedCurr = true\n }\n if (!start.deleted) {\n const content = start.content\n switch (content.constructor) {\n case ContentFormat: {\n const { key, value } = /** @type {ContentFormat} */ (content)\n const startAttrValue = startAttributes.get(key) ?? null\n if (endFormats.get(key) !== content || startAttrValue === value) {\n // Either this format is overwritten or it is not necessary because the attribute already existed.\n start.delete(transaction)\n cleanups++\n if (!reachedCurr && (currAttributes.get(key) ?? null) === value && startAttrValue !== value) {\n if (startAttrValue === null) {\n currAttributes.delete(key)\n } else {\n currAttributes.set(key, startAttrValue)\n }\n }\n }\n if (!reachedCurr && !start.deleted) {\n updateCurrentAttributes(currAttributes, /** @type {ContentFormat} */ (content))\n }\n break\n }\n }\n }\n start = /** @type {Item} */ (start.right)\n }\n return cleanups\n}\n\n/**\n * @param {Transaction} transaction\n * @param {Item | null} item\n */\nconst cleanupContextlessFormattingGap = (transaction, item) => {\n // iterate until item.right is null or content\n while (item && item.right && (item.right.deleted || !item.right.countable)) {\n item = item.right\n }\n const attrs = new Set()\n // iterate back until a content item is found\n while (item && (item.deleted || !item.countable)) {\n if (!item.deleted && item.content.constructor === ContentFormat) {\n const key = /** @type {ContentFormat} */ (item.content).key\n if (attrs.has(key)) {\n item.delete(transaction)\n } else {\n attrs.add(key)\n }\n }\n item = item.left\n }\n}\n\n/**\n * This function is experimental and subject to change / be removed.\n *\n * Ideally, we don't need this function at all. Formatting attributes should be cleaned up\n * automatically after each change. This function iterates twice over the complete YText type\n * and removes unnecessary formatting attributes. This is also helpful for testing.\n *\n * This function won't be exported anymore as soon as there is confidence that the YText type works as intended.\n *\n * @param {YText} type\n * @return {number} How many formatting attributes have been cleaned up.\n */\nexport const cleanupYTextFormatting = type => {\n let res = 0\n transact(/** @type {Doc} */ (type.doc), transaction => {\n let start = /** @type {Item} */ (type._start)\n let end = type._start\n let startAttributes = map.create()\n const currentAttributes = map.copy(startAttributes)\n while (end) {\n if (end.deleted === false) {\n switch (end.content.constructor) {\n case ContentFormat:\n updateCurrentAttributes(currentAttributes, /** @type {ContentFormat} */ (end.content))\n break\n default:\n res += cleanupFormattingGap(transaction, start, end, startAttributes, currentAttributes)\n startAttributes = map.copy(currentAttributes)\n start = end\n break\n }\n }\n end = end.right\n }\n })\n return res\n}\n\n/**\n * This will be called by the transaction once the event handlers are called to potentially cleanup\n * formatting attributes.\n *\n * @param {Transaction} transaction\n */\nexport const cleanupYTextAfterTransaction = transaction => {\n /**\n * @type {Set<YText>}\n */\n const needFullCleanup = new Set()\n // check if another formatting item was inserted\n const doc = transaction.doc\n for (const [client, afterClock] of transaction.afterState.entries()) {\n const clock = transaction.beforeState.get(client) || 0\n if (afterClock === clock) {\n continue\n }\n iterateStructs(transaction, /** @type {Array<Item|GC>} */ (doc.store.clients.get(client)), clock, afterClock, item => {\n if (\n !item.deleted && /** @type {Item} */ (item).content.constructor === ContentFormat && item.constructor !== GC\n ) {\n needFullCleanup.add(/** @type {any} */ (item).parent)\n }\n })\n }\n // cleanup in a new transaction\n transact(doc, (t) => {\n iterateDeletedStructs(transaction, transaction.deleteSet, item => {\n if (item instanceof GC || !(/** @type {YText} */ (item.parent)._hasFormatting) || needFullCleanup.has(/** @type {YText} */ (item.parent))) {\n return\n }\n const parent = /** @type {YText} */ (item.parent)\n if (item.content.constructor === ContentFormat) {\n needFullCleanup.add(parent)\n } else {\n // If no formatting attribute was inserted or deleted, we can make due with contextless\n // formatting cleanups.\n // Contextless: it is not necessary to compute currentAttributes for the affected position.\n cleanupContextlessFormattingGap(t, item)\n }\n })\n // If a formatting item was inserted, we simply clean the whole type.\n // We need to compute currentAttributes for the current position anyway.\n for (const yText of needFullCleanup) {\n cleanupYTextFormatting(yText)\n }\n })\n}\n\n/**\n * @param {Transaction} transaction\n * @param {ItemTextListPosition} currPos\n * @param {number} length\n * @return {ItemTextListPosition}\n *\n * @private\n * @function\n */\nconst deleteText = (transaction, currPos, length) => {\n const startLength = length\n const startAttrs = map.copy(currPos.currentAttributes)\n const start = currPos.right\n while (length > 0 && currPos.right !== null) {\n if (currPos.right.deleted === false) {\n switch (currPos.right.content.constructor) {\n case ContentType:\n case ContentEmbed:\n case ContentString:\n if (length < currPos.right.length) {\n getItemCleanStart(transaction, createID(currPos.right.id.client, currPos.right.id.clock + length))\n }\n length -= currPos.right.length\n currPos.right.delete(transaction)\n break\n }\n }\n currPos.forward()\n }\n if (start) {\n cleanupFormattingGap(transaction, start, currPos.right, startAttrs, currPos.currentAttributes)\n }\n const parent = /** @type {AbstractType<any>} */ (/** @type {Item} */ (currPos.left || currPos.right).parent)\n if (parent._searchMarker) {\n updateMarkerChanges(parent._searchMarker, currPos.index, -startLength + length)\n }\n return currPos\n}\n\n/**\n * The Quill Delta format represents changes on a text document with\n * formatting information. For more information visit {@link https://quilljs.com/docs/delta/|Quill Delta}\n *\n * @example\n * {\n * ops: [\n * { insert: 'Gandalf', attributes: { bold: true } },\n * { insert: ' the ' },\n * { insert: 'Grey', attributes: { color: '#cccccc' } }\n * ]\n * }\n *\n */\n\n/**\n * Attributes that can be assigned to a selection of text.\n *\n * @example\n * {\n * bold: true,\n * font-size: '40px'\n * }\n *\n * @typedef {Object} TextAttributes\n */\n\n/**\n * @extends YEvent<YText>\n * Event that describes the changes on a YText type.\n */\nexport class YTextEvent extends YEvent {\n /**\n * @param {YText} ytext\n * @param {Transaction} transaction\n * @param {Set<any>} subs The keys that changed\n */\n constructor (ytext, transaction, subs) {\n super(ytext, transaction)\n /**\n * Whether the children changed.\n * @type {Boolean}\n * @private\n */\n this.childListChanged = false\n /**\n * Set of all changed attributes.\n * @type {Set<string>}\n */\n this.keysChanged = new Set()\n subs.forEach((sub) => {\n if (sub === null) {\n this.childListChanged = true\n } else {\n this.keysChanged.add(sub)\n }\n })\n }\n\n /**\n * @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert?:Array<any>|string, delete?:number, retain?:number}>}}\n */\n get changes () {\n if (this._changes === null) {\n /**\n * @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert?:Array<any>|string|AbstractType<any>|object, delete?:number, retain?:number}>}}\n */\n const changes = {\n keys: this.keys,\n delta: this.delta,\n added: new Set(),\n deleted: new Set()\n }\n this._changes = changes\n }\n return /** @type {any} */ (this._changes)\n }\n\n /**\n * Compute the changes in the delta format.\n * A {@link https://quilljs.com/docs/delta/|Quill Delta}) that represents the changes on the document.\n *\n * @type {Array<{insert?:string|object|AbstractType<any>, delete?:number, retain?:number, attributes?: Object<string,any>}>}\n *\n * @public\n */\n get delta () {\n if (this._delta === null) {\n const y = /** @type {Doc} */ (this.target.doc)\n /**\n * @type {Array<{insert?:string|object|AbstractType<any>, delete?:number, retain?:number, attributes?: Object<string,any>}>}\n */\n const delta = []\n transact(y, transaction => {\n const currentAttributes = new Map() // saves all current attributes for insert\n const oldAttributes = new Map()\n let item = this.target._start\n /**\n * @type {string?}\n */\n let action = null\n /**\n * @type {Object<string,any>}\n */\n const attributes = {} // counts added or removed new attributes for retain\n /**\n * @type {string|object}\n */\n let insert = ''\n let retain = 0\n let deleteLen = 0\n const addOp = () => {\n if (action !== null) {\n /**\n * @type {any}\n */\n let op = null\n switch (action) {\n case 'delete':\n if (deleteLen > 0) {\n op = { delete: deleteLen }\n }\n deleteLen = 0\n break\n case 'insert':\n if (typeof insert === 'object' || insert.length > 0) {\n op = { insert }\n if (currentAttributes.size > 0) {\n op.attributes = {}\n currentAttributes.forEach((value, key) => {\n if (value !== null) {\n op.attributes[key] = value\n }\n })\n }\n }\n insert = ''\n break\n case 'retain':\n if (retain > 0) {\n op = { retain }\n if (!object.isEmpty(attributes)) {\n op.attributes = object.assign({}, attributes)\n }\n }\n retain = 0\n break\n }\n if (op) delta.push(op)\n action = null\n }\n }\n while (item !== null) {\n switch (item.content.constructor) {\n case ContentType:\n case ContentEmbed:\n if (this.adds(item)) {\n if (!this.deletes(item)) {\n addOp()\n action = 'insert'\n insert = item.content.getContent()[0]\n addOp()\n }\n } else if (this.deletes(item)) {\n if (action !== 'delete') {\n addOp()\n action = 'delete'\n }\n deleteLen += 1\n } else if (!item.deleted) {\n if (action !== 'retain') {\n addOp()\n action = 'retain'\n }\n retain += 1\n }\n break\n case ContentString:\n if (this.adds(item)) {\n if (!this.deletes(item)) {\n if (action !== 'insert') {\n addOp()\n action = 'insert'\n }\n insert += /** @type {ContentString} */ (item.content).str\n }\n } else if (this.deletes(item)) {\n if (action !== 'delete') {\n addOp()\n action = 'delete'\n }\n deleteLen += item.length\n } else if (!item.deleted) {\n if (action !== 'retain') {\n addOp()\n action = 'retain'\n }\n retain += item.length\n }\n break\n case ContentFormat: {\n const { key, value } = /** @type {ContentFormat} */ (item.content)\n if (this.adds(item)) {\n if (!this.deletes(item)) {\n const curVal = currentAttributes.get(key) ?? null\n if (!equalAttrs(curVal, value)) {\n if (action === 'retain') {\n addOp()\n }\n if (equalAttrs(value, (oldAttributes.get(key) ?? null))) {\n delete attributes[key]\n } else {\n attributes[key] = value\n }\n } else if (value !== null) {\n item.delete(transaction)\n }\n }\n } else if (this.deletes(item)) {\n oldAttributes.set(key, value)\n const curVal = currentAttributes.get(key) ?? null\n if (!equalAttrs(curVal, value)) {\n if (action === 'retain') {\n addOp()\n }\n attributes[key] = curVal\n }\n } else if (!item.deleted) {\n oldAttributes.set(key, value)\n const attr = attributes[key]\n if (attr !== undefined) {\n if (!equalAttrs(attr, value)) {\n if (action === 'retain') {\n addOp()\n }\n if (value === null) {\n delete attributes[key]\n } else {\n attributes[key] = value\n }\n } else if (attr !== null) { // this will be cleaned up automatically by the contextless cleanup function\n item.delete(transaction)\n }\n }\n }\n if (!item.deleted) {\n if (action === 'insert') {\n addOp()\n }\n updateCurrentAttributes(currentAttributes, /** @type {ContentFormat} */ (item.content))\n }\n break\n }\n }\n item = item.right\n }\n addOp()\n while (delta.length > 0) {\n const lastOp = delta[delta.length - 1]\n if (lastOp.retain !== undefined && lastOp.attributes === undefined) {\n // retain delta's if they don't assign attributes\n delta.pop()\n } else {\n break\n }\n }\n })\n this._delta = delta\n }\n return /** @type {any} */ (this._delta)\n }\n}\n\n/**\n * Type that represents text with formatting information.\n *\n * This type replaces y-richtext as this implementation is able to handle\n * block formats (format information on a paragraph), embeds (complex elements\n * like pictures and videos), and text formats (**bold**, *italic*).\n *\n * @extends AbstractType<YTextEvent>\n */\nexport class YText extends AbstractType {\n /**\n * @param {String} [string] The initial value of the YText.\n */\n constructor (string) {\n super()\n /**\n * Array of pending operations on this type\n * @type {Array<function():void>?}\n */\n this._pending = string !== undefined ? [() => this.insert(0, string)] : []\n /**\n * @type {Array<ArraySearchMarker>|null}\n */\n this._searchMarker = []\n /**\n * Whether this YText contains formatting attributes.\n * This flag is updated when a formatting item is integrated (see ContentFormat.integrate)\n */\n this._hasFormatting = false\n }\n\n /**\n * Number of characters of this text type.\n *\n * @type {number}\n */\n get length () {\n this.doc ?? warnPrematureAccess()\n return this._length\n }\n\n /**\n * @param {Doc} y\n * @param {Item} item\n */\n _integrate (y, item) {\n super._integrate(y, item)\n try {\n /** @type {Array<function>} */ (this._pending).forEach(f => f())\n } catch (e) {\n console.error(e)\n }\n this._pending = null\n }\n\n _copy () {\n return new YText()\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YText}\n */\n clone () {\n const text = new YText()\n text.applyDelta(this.toDelta())\n return text\n }\n\n /**\n * Creates YTextEvent and calls observers.\n *\n * @param {Transaction} transaction\n * @param {Set<null|string>} parentSubs Keys changed on this type. `null` if list was modified.\n */\n _callObserver (transaction, parentSubs) {\n super._callObserver(transaction, parentSubs)\n const event = new YTextEvent(this, transaction, parentSubs)\n callTypeObservers(this, transaction, event)\n // If a remote change happened, we try to cleanup potential formatting duplicates.\n if (!transaction.local && this._hasFormatting) {\n transaction._needFormattingCleanup = true\n }\n }\n\n /**\n * Returns the unformatted string representation of this YText type.\n *\n * @public\n */\n toString () {\n this.doc ?? warnPrematureAccess()\n let str = ''\n /**\n * @type {Item|null}\n */\n let n = this._start\n while (n !== null) {\n if (!n.deleted && n.countable && n.content.constructor === ContentString) {\n str += /** @type {ContentString} */ (n.content).str\n }\n n = n.right\n }\n return str\n }\n\n /**\n * Returns the unformatted string representation of this YText type.\n *\n * @return {string}\n * @public\n */\n toJSON () {\n return this.toString()\n }\n\n /**\n * Apply a {@link Delta} on this shared YText type.\n *\n * @param {Array<any>} delta The changes to apply on this element.\n * @param {object} opts\n * @param {boolean} [opts.sanitize] Sanitize input delta. Removes ending newlines if set to true.\n *\n *\n * @public\n */\n applyDelta (delta, { sanitize = true } = {}) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n const currPos = new ItemTextListPosition(null, this._start, 0, new Map())\n for (let i = 0; i < delta.length; i++) {\n const op = delta[i]\n if (op.insert !== undefined) {\n // Quill assumes that the content starts with an empty paragraph.\n // Yjs/Y.Text assumes that it starts empty. We always hide that\n // there is a newline at the end of the content.\n // If we omit this step, clients will see a different number of\n // paragraphs, but nothing bad will happen.\n const ins = (!sanitize && typeof op.insert === 'string' && i === delta.length - 1 && currPos.right === null && op.insert.slice(-1) === '\\n') ? op.insert.slice(0, -1) : op.insert\n if (typeof ins !== 'string' || ins.length > 0) {\n insertText(transaction, this, currPos, ins, op.attributes || {})\n }\n } else if (op.retain !== undefined) {\n formatText(transaction, this, currPos, op.retain, op.attributes || {})\n } else if (op.delete !== undefined) {\n deleteText(transaction, currPos, op.delete)\n }\n }\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.applyDelta(delta))\n }\n }\n\n /**\n * Returns the Delta representation of this YText type.\n *\n * @param {Snapshot} [snapshot]\n * @param {Snapshot} [prevSnapshot]\n * @param {function('removed' | 'added', ID):any} [computeYChange]\n * @return {any} The Delta representation of this type.\n *\n * @public\n */\n toDelta (snapshot, prevSnapshot, computeYChange) {\n this.doc ?? warnPrematureAccess()\n /**\n * @type{Array<any>}\n */\n const ops = []\n const currentAttributes = new Map()\n const doc = /** @type {Doc} */ (this.doc)\n let str = ''\n let n = this._start\n function packStr () {\n if (str.length > 0) {\n // pack str with attributes to ops\n /**\n * @type {Object<string,any>}\n */\n const attributes = {}\n let addAttributes = false\n currentAttributes.forEach((value, key) => {\n addAttributes = true\n attributes[key] = value\n })\n /**\n * @type {Object<string,any>}\n */\n const op = { insert: str }\n if (addAttributes) {\n op.attributes = attributes\n }\n ops.push(op)\n str = ''\n }\n }\n const computeDelta = () => {\n while (n !== null) {\n if (isVisible(n, snapshot) || (prevSnapshot !== undefined && isVisible(n, prevSnapshot))) {\n switch (n.content.constructor) {\n case ContentString: {\n const cur = currentAttributes.get('ychange')\n if (snapshot !== undefined && !isVisible(n, snapshot)) {\n if (cur === undefined || cur.user !== n.id.client || cur.type !== 'removed') {\n packStr()\n currentAttributes.set('ychange', computeYChange ? computeYChange('removed', n.id) : { type: 'removed' })\n }\n } else if (prevSnapshot !== undefined && !isVisible(n, prevSnapshot)) {\n if (cur === undefined || cur.user !== n.id.client || cur.type !== 'added') {\n packStr()\n currentAttributes.set('ychange', computeYChange ? computeYChange('added', n.id) : { type: 'added' })\n }\n } else if (cur !== undefined) {\n packStr()\n currentAttributes.delete('ychange')\n }\n str += /** @type {ContentString} */ (n.content).str\n break\n }\n case ContentType:\n case ContentEmbed: {\n packStr()\n /**\n * @type {Object<string,any>}\n */\n const op = {\n insert: n.content.getContent()[0]\n }\n if (currentAttributes.size > 0) {\n const attrs = /** @type {Object<string,any>} */ ({})\n op.attributes = attrs\n currentAttributes.forEach((value, key) => {\n attrs[key] = value\n })\n }\n ops.push(op)\n break\n }\n case ContentFormat:\n if (isVisible(n, snapshot)) {\n packStr()\n updateCurrentAttributes(currentAttributes, /** @type {ContentFormat} */ (n.content))\n }\n break\n }\n }\n n = n.right\n }\n packStr()\n }\n if (snapshot || prevSnapshot) {\n // snapshots are merged again after the transaction, so we need to keep the\n // transaction alive until we are done\n transact(doc, transaction => {\n if (snapshot) {\n splitSnapshotAffectedStructs(transaction, snapshot)\n }\n if (prevSnapshot) {\n splitSnapshotAffectedStructs(transaction, prevSnapshot)\n }\n computeDelta()\n }, 'cleanup')\n } else {\n computeDelta()\n }\n return ops\n }\n\n /**\n * Insert text at a given index.\n *\n * @param {number} index The index at which to start inserting.\n * @param {String} text The text to insert at the specified position.\n * @param {TextAttributes} [attributes] Optionally define some formatting\n * information to apply on the inserted\n * Text.\n * @public\n */\n insert (index, text, attributes) {\n if (text.length <= 0) {\n return\n }\n const y = this.doc\n if (y !== null) {\n transact(y, transaction => {\n const pos = findPosition(transaction, this, index, !attributes)\n if (!attributes) {\n attributes = {}\n // @ts-ignore\n pos.currentAttributes.forEach((v, k) => { attributes[k] = v })\n }\n insertText(transaction, this, pos, text, attributes)\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.insert(index, text, attributes))\n }\n }\n\n /**\n * Inserts an embed at a index.\n *\n * @param {number} index The index to insert the embed at.\n * @param {Object | AbstractType<any>} embed The Object that represents the embed.\n * @param {TextAttributes} [attributes] Attribute information to apply on the\n * embed\n *\n * @public\n */\n insertEmbed (index, embed, attributes) {\n const y = this.doc\n if (y !== null) {\n transact(y, transaction => {\n const pos = findPosition(transaction, this, index, !attributes)\n insertText(transaction, this, pos, embed, attributes || {})\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.insertEmbed(index, embed, attributes || {}))\n }\n }\n\n /**\n * Deletes text starting from an index.\n *\n * @param {number} index Index at which to start deleting.\n * @param {number} length The number of characters to remove. Defaults to 1.\n *\n * @public\n */\n delete (index, length) {\n if (length === 0) {\n return\n }\n const y = this.doc\n if (y !== null) {\n transact(y, transaction => {\n deleteText(transaction, findPosition(transaction, this, index, true), length)\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.delete(index, length))\n }\n }\n\n /**\n * Assigns properties to a range of text.\n *\n * @param {number} index The position where to start formatting.\n * @param {number} length The amount of characters to assign properties to.\n * @param {TextAttributes} attributes Attribute information to apply on the\n * text.\n *\n * @public\n */\n format (index, length, attributes) {\n if (length === 0) {\n return\n }\n const y = this.doc\n if (y !== null) {\n transact(y, transaction => {\n const pos = findPosition(transaction, this, index, false)\n if (pos.right === null) {\n return\n }\n formatText(transaction, this, pos, length, attributes)\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.format(index, length, attributes))\n }\n }\n\n /**\n * Removes an attribute.\n *\n * @note Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.\n *\n * @param {String} attributeName The attribute name that is to be removed.\n *\n * @public\n */\n removeAttribute (attributeName) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeMapDelete(transaction, this, attributeName)\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.removeAttribute(attributeName))\n }\n }\n\n /**\n * Sets or updates an attribute.\n *\n * @note Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.\n *\n * @param {String} attributeName The attribute name that is to be set.\n * @param {any} attributeValue The attribute value that is to be set.\n *\n * @public\n */\n setAttribute (attributeName, attributeValue) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeMapSet(transaction, this, attributeName, attributeValue)\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.setAttribute(attributeName, attributeValue))\n }\n }\n\n /**\n * Returns an attribute value that belongs to the attribute name.\n *\n * @note Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.\n *\n * @param {String} attributeName The attribute name that identifies the\n * queried value.\n * @return {any} The queried attribute value.\n *\n * @public\n */\n getAttribute (attributeName) {\n return /** @type {any} */ (typeMapGet(this, attributeName))\n }\n\n /**\n * Returns all attribute name/value pairs in a JSON Object.\n *\n * @note Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.\n *\n * @return {Object<string, any>} A JSON Object that describes the attributes.\n *\n * @public\n */\n getAttributes () {\n return typeMapGetAll(this)\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n */\n _write (encoder) {\n encoder.writeTypeRef(YTextRefID)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder\n * @return {YText}\n *\n * @private\n * @function\n */\nexport const readYText = _decoder => new YText()\n","/**\n * @module YXml\n */\n\nimport {\n YXmlEvent,\n YXmlElement,\n AbstractType,\n typeListMap,\n typeListForEach,\n typeListInsertGenerics,\n typeListInsertGenericsAfter,\n typeListDelete,\n typeListToArray,\n YXmlFragmentRefID,\n callTypeObservers,\n transact,\n typeListGet,\n typeListSlice,\n warnPrematureAccess,\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, ContentType, Transaction, Item, YXmlText, YXmlHook // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\nimport * as array from 'lib0/array'\n\n/**\n * Define the elements to which a set of CSS queries apply.\n * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors|CSS_Selectors}\n *\n * @example\n * query = '.classSelector'\n * query = 'nodeSelector'\n * query = '#idSelector'\n *\n * @typedef {string} CSS_Selector\n */\n\n/**\n * Dom filter function.\n *\n * @callback domFilter\n * @param {string} nodeName The nodeName of the element\n * @param {Map} attributes The map of attributes.\n * @return {boolean} Whether to include the Dom node in the YXmlElement.\n */\n\n/**\n * Represents a subset of the nodes of a YXmlElement / YXmlFragment and a\n * position within them.\n *\n * Can be created with {@link YXmlFragment#createTreeWalker}\n *\n * @public\n * @implements {Iterable<YXmlElement|YXmlText|YXmlElement|YXmlHook>}\n */\nexport class YXmlTreeWalker {\n /**\n * @param {YXmlFragment | YXmlElement} root\n * @param {function(AbstractType<any>):boolean} [f]\n */\n constructor (root, f = () => true) {\n this._filter = f\n this._root = root\n /**\n * @type {Item}\n */\n this._currentNode = /** @type {Item} */ (root._start)\n this._firstCall = true\n root.doc ?? warnPrematureAccess()\n }\n\n [Symbol.iterator] () {\n return this\n }\n\n /**\n * Get the next node.\n *\n * @return {IteratorResult<YXmlElement|YXmlText|YXmlHook>} The next node.\n *\n * @public\n */\n next () {\n /**\n * @type {Item|null}\n */\n let n = this._currentNode\n let type = n && n.content && /** @type {any} */ (n.content).type\n if (n !== null && (!this._firstCall || n.deleted || !this._filter(type))) { // if first call, we check if we can use the first item\n do {\n type = /** @type {any} */ (n.content).type\n if (!n.deleted && (type.constructor === YXmlElement || type.constructor === YXmlFragment) && type._start !== null) {\n // walk down in the tree\n n = type._start\n } else {\n // walk right or up in the tree\n while (n !== null) {\n /**\n * @type {Item | null}\n */\n const nxt = n.next\n if (nxt !== null) {\n n = nxt\n break\n } else if (n.parent === this._root) {\n n = null\n } else {\n n = /** @type {AbstractType<any>} */ (n.parent)._item\n }\n }\n }\n } while (n !== null && (n.deleted || !this._filter(/** @type {ContentType} */ (n.content).type)))\n }\n this._firstCall = false\n if (n === null) {\n // @ts-ignore\n return { value: undefined, done: true }\n }\n this._currentNode = n\n return { value: /** @type {any} */ (n.content).type, done: false }\n }\n}\n\n/**\n * Represents a list of {@link YXmlElement}.and {@link YXmlText} types.\n * A YxmlFragment is similar to a {@link YXmlElement}, but it does not have a\n * nodeName and it does not have attributes. Though it can be bound to a DOM\n * element - in this case the attributes and the nodeName are not shared.\n *\n * @public\n * @extends AbstractType<YXmlEvent>\n */\nexport class YXmlFragment extends AbstractType {\n constructor () {\n super()\n /**\n * @type {Array<any>|null}\n */\n this._prelimContent = []\n }\n\n /**\n * @type {YXmlElement|YXmlText|null}\n */\n get firstChild () {\n const first = this._first\n return first ? first.content.getContent()[0] : null\n }\n\n /**\n * Integrate this type into the Yjs instance.\n *\n * * Save this struct in the os\n * * This type is sent to other client\n * * Observer functions are fired\n *\n * @param {Doc} y The Yjs instance\n * @param {Item} item\n */\n _integrate (y, item) {\n super._integrate(y, item)\n this.insert(0, /** @type {Array<any>} */ (this._prelimContent))\n this._prelimContent = null\n }\n\n _copy () {\n return new YXmlFragment()\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YXmlFragment}\n */\n clone () {\n const el = new YXmlFragment()\n // @ts-ignore\n el.insert(0, this.toArray().map(item => item instanceof AbstractType ? item.clone() : item))\n return el\n }\n\n get length () {\n this.doc ?? warnPrematureAccess()\n return this._prelimContent === null ? this._length : this._prelimContent.length\n }\n\n /**\n * Create a subtree of childNodes.\n *\n * @example\n * const walker = elem.createTreeWalker(dom => dom.nodeName === 'div')\n * for (let node in walker) {\n * // `node` is a div node\n * nop(node)\n * }\n *\n * @param {function(AbstractType<any>):boolean} filter Function that is called on each child element and\n * returns a Boolean indicating whether the child\n * is to be included in the subtree.\n * @return {YXmlTreeWalker} A subtree and a position within it.\n *\n * @public\n */\n createTreeWalker (filter) {\n return new YXmlTreeWalker(this, filter)\n }\n\n /**\n * Returns the first YXmlElement that matches the query.\n * Similar to DOM's {@link querySelector}.\n *\n * Query support:\n * - tagname\n * TODO:\n * - id\n * - attribute\n *\n * @param {CSS_Selector} query The query on the children.\n * @return {YXmlElement|YXmlText|YXmlHook|null} The first element that matches the query or null.\n *\n * @public\n */\n querySelector (query) {\n query = query.toUpperCase()\n // @ts-ignore\n const iterator = new YXmlTreeWalker(this, element => element.nodeName && element.nodeName.toUpperCase() === query)\n const next = iterator.next()\n if (next.done) {\n return null\n } else {\n return next.value\n }\n }\n\n /**\n * Returns all YXmlElements that match the query.\n * Similar to Dom's {@link querySelectorAll}.\n *\n * @todo Does not yet support all queries. Currently only query by tagName.\n *\n * @param {CSS_Selector} query The query on the children\n * @return {Array<YXmlElement|YXmlText|YXmlHook|null>} The elements that match this query.\n *\n * @public\n */\n querySelectorAll (query) {\n query = query.toUpperCase()\n // @ts-ignore\n return array.from(new YXmlTreeWalker(this, element => element.nodeName && element.nodeName.toUpperCase() === query))\n }\n\n /**\n * Creates YXmlEvent and calls observers.\n *\n * @param {Transaction} transaction\n * @param {Set<null|string>} parentSubs Keys changed on this type. `null` if list was modified.\n */\n _callObserver (transaction, parentSubs) {\n callTypeObservers(this, transaction, new YXmlEvent(this, parentSubs, transaction))\n }\n\n /**\n * Get the string representation of all the children of this YXmlFragment.\n *\n * @return {string} The string representation of all children.\n */\n toString () {\n return typeListMap(this, xml => xml.toString()).join('')\n }\n\n /**\n * @return {string}\n */\n toJSON () {\n return this.toString()\n }\n\n /**\n * Creates a Dom Element that mirrors this YXmlElement.\n *\n * @param {Document} [_document=document] The document object (you must define\n * this when calling this method in\n * nodejs)\n * @param {Object<string, any>} [hooks={}] Optional property to customize how hooks\n * are presented in the DOM\n * @param {any} [binding] You should not set this property. This is\n * used if DomBinding wants to create a\n * association to the created DOM type.\n * @return {Node} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element}\n *\n * @public\n */\n toDOM (_document = document, hooks = {}, binding) {\n const fragment = _document.createDocumentFragment()\n if (binding !== undefined) {\n binding._createAssociation(fragment, this)\n }\n typeListForEach(this, xmlType => {\n fragment.insertBefore(xmlType.toDOM(_document, hooks, binding), null)\n })\n return fragment\n }\n\n /**\n * Inserts new content at an index.\n *\n * @example\n * // Insert character 'a' at position 0\n * xml.insert(0, [new Y.XmlText('text')])\n *\n * @param {number} index The index to insert content at\n * @param {Array<YXmlElement|YXmlText>} content The array of content\n */\n insert (index, content) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeListInsertGenerics(transaction, this, index, content)\n })\n } else {\n // @ts-ignore _prelimContent is defined because this is not yet integrated\n this._prelimContent.splice(index, 0, ...content)\n }\n }\n\n /**\n * Inserts new content at an index.\n *\n * @example\n * // Insert character 'a' at position 0\n * xml.insert(0, [new Y.XmlText('text')])\n *\n * @param {null|Item|YXmlElement|YXmlText} ref The index to insert content at\n * @param {Array<YXmlElement|YXmlText>} content The array of content\n */\n insertAfter (ref, content) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n const refItem = (ref && ref instanceof AbstractType) ? ref._item : ref\n typeListInsertGenericsAfter(transaction, this, refItem, content)\n })\n } else {\n const pc = /** @type {Array<any>} */ (this._prelimContent)\n const index = ref === null ? 0 : pc.findIndex(el => el === ref) + 1\n if (index === 0 && ref !== null) {\n throw error.create('Reference item not found')\n }\n pc.splice(index, 0, ...content)\n }\n }\n\n /**\n * Deletes elements starting from an index.\n *\n * @param {number} index Index at which to start deleting elements\n * @param {number} [length=1] The number of elements to remove. Defaults to 1.\n */\n delete (index, length = 1) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeListDelete(transaction, this, index, length)\n })\n } else {\n // @ts-ignore _prelimContent is defined because this is not yet integrated\n this._prelimContent.splice(index, length)\n }\n }\n\n /**\n * Transforms this YArray to a JavaScript Array.\n *\n * @return {Array<YXmlElement|YXmlText|YXmlHook>}\n */\n toArray () {\n return typeListToArray(this)\n }\n\n /**\n * Appends content to this YArray.\n *\n * @param {Array<YXmlElement|YXmlText>} content Array of content to append.\n */\n push (content) {\n this.insert(this.length, content)\n }\n\n /**\n * Prepends content to this YArray.\n *\n * @param {Array<YXmlElement|YXmlText>} content Array of content to prepend.\n */\n unshift (content) {\n this.insert(0, content)\n }\n\n /**\n * Returns the i-th element from a YArray.\n *\n * @param {number} index The index of the element to return from the YArray\n * @return {YXmlElement|YXmlText}\n */\n get (index) {\n return typeListGet(this, index)\n }\n\n /**\n * Returns a portion of this YXmlFragment into a JavaScript Array selected\n * from start to end (end not included).\n *\n * @param {number} [start]\n * @param {number} [end]\n * @return {Array<YXmlElement|YXmlText>}\n */\n slice (start = 0, end = this.length) {\n return typeListSlice(this, start, end)\n }\n\n /**\n * Executes a provided function on once on every child element.\n *\n * @param {function(YXmlElement|YXmlText,number, typeof self):void} f A function to execute on every element of this YArray.\n */\n forEach (f) {\n typeListForEach(this, f)\n }\n\n /**\n * Transform the properties of this type to binary and write it to an\n * BinaryEncoder.\n *\n * This is called when this Item is sent to a remote peer.\n *\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.\n */\n _write (encoder) {\n encoder.writeTypeRef(YXmlFragmentRefID)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder\n * @return {YXmlFragment}\n *\n * @private\n * @function\n */\nexport const readYXmlFragment = _decoder => new YXmlFragment()\n","import * as object from 'lib0/object'\n\nimport {\n YXmlFragment,\n transact,\n typeMapDelete,\n typeMapHas,\n typeMapSet,\n typeMapGet,\n typeMapGetAll,\n typeMapGetAllSnapshot,\n typeListForEach,\n YXmlElementRefID,\n Snapshot, YXmlText, ContentType, AbstractType, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Item // eslint-disable-line\n} from '../internals.js'\n\n/**\n * @typedef {Object|number|null|Array<any>|string|Uint8Array|AbstractType<any>} ValueTypes\n */\n\n/**\n * An YXmlElement imitates the behavior of a\n * https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element\n *\n * * An YXmlElement has attributes (key value pairs)\n * * An YXmlElement has childElements that must inherit from YXmlElement\n *\n * @template {{ [key: string]: ValueTypes }} [KV={ [key: string]: string }]\n */\nexport class YXmlElement extends YXmlFragment {\n constructor (nodeName = 'UNDEFINED') {\n super()\n this.nodeName = nodeName\n /**\n * @type {Map<string, any>|null}\n */\n this._prelimAttrs = new Map()\n }\n\n /**\n * @type {YXmlElement|YXmlText|null}\n */\n get nextSibling () {\n const n = this._item ? this._item.next : null\n return n ? /** @type {YXmlElement|YXmlText} */ (/** @type {ContentType} */ (n.content).type) : null\n }\n\n /**\n * @type {YXmlElement|YXmlText|null}\n */\n get prevSibling () {\n const n = this._item ? this._item.prev : null\n return n ? /** @type {YXmlElement|YXmlText} */ (/** @type {ContentType} */ (n.content).type) : null\n }\n\n /**\n * Integrate this type into the Yjs instance.\n *\n * * Save this struct in the os\n * * This type is sent to other client\n * * Observer functions are fired\n *\n * @param {Doc} y The Yjs instance\n * @param {Item} item\n */\n _integrate (y, item) {\n super._integrate(y, item)\n ;(/** @type {Map<string, any>} */ (this._prelimAttrs)).forEach((value, key) => {\n this.setAttribute(key, value)\n })\n this._prelimAttrs = null\n }\n\n /**\n * Creates an Item with the same effect as this Item (without position effect)\n *\n * @return {YXmlElement}\n */\n _copy () {\n return new YXmlElement(this.nodeName)\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YXmlElement<KV>}\n */\n clone () {\n /**\n * @type {YXmlElement<KV>}\n */\n const el = new YXmlElement(this.nodeName)\n const attrs = this.getAttributes()\n object.forEach(attrs, (value, key) => {\n if (typeof value === 'string') {\n el.setAttribute(key, value)\n }\n })\n // @ts-ignore\n el.insert(0, this.toArray().map(item => item instanceof AbstractType ? item.clone() : item))\n return el\n }\n\n /**\n * Returns the XML serialization of this YXmlElement.\n * The attributes are ordered by attribute-name, so you can easily use this\n * method to compare YXmlElements\n *\n * @return {string} The string representation of this type.\n *\n * @public\n */\n toString () {\n const attrs = this.getAttributes()\n const stringBuilder = []\n const keys = []\n for (const key in attrs) {\n keys.push(key)\n }\n keys.sort()\n const keysLen = keys.length\n for (let i = 0; i < keysLen; i++) {\n const key = keys[i]\n stringBuilder.push(key + '=\"' + attrs[key] + '\"')\n }\n const nodeName = this.nodeName.toLocaleLowerCase()\n const attrsString = stringBuilder.length > 0 ? ' ' + stringBuilder.join(' ') : ''\n return `<${nodeName}${attrsString}>${super.toString()}</${nodeName}>`\n }\n\n /**\n * Removes an attribute from this YXmlElement.\n *\n * @param {string} attributeName The attribute name that is to be removed.\n *\n * @public\n */\n removeAttribute (attributeName) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeMapDelete(transaction, this, attributeName)\n })\n } else {\n /** @type {Map<string,any>} */ (this._prelimAttrs).delete(attributeName)\n }\n }\n\n /**\n * Sets or updates an attribute.\n *\n * @template {keyof KV & string} KEY\n *\n * @param {KEY} attributeName The attribute name that is to be set.\n * @param {KV[KEY]} attributeValue The attribute value that is to be set.\n *\n * @public\n */\n setAttribute (attributeName, attributeValue) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeMapSet(transaction, this, attributeName, attributeValue)\n })\n } else {\n /** @type {Map<string, any>} */ (this._prelimAttrs).set(attributeName, attributeValue)\n }\n }\n\n /**\n * Returns an attribute value that belongs to the attribute name.\n *\n * @template {keyof KV & string} KEY\n *\n * @param {KEY} attributeName The attribute name that identifies the\n * queried value.\n * @return {KV[KEY]|undefined} The queried attribute value.\n *\n * @public\n */\n getAttribute (attributeName) {\n return /** @type {any} */ (typeMapGet(this, attributeName))\n }\n\n /**\n * Returns whether an attribute exists\n *\n * @param {string} attributeName The attribute name to check for existence.\n * @return {boolean} whether the attribute exists.\n *\n * @public\n */\n hasAttribute (attributeName) {\n return /** @type {any} */ (typeMapHas(this, attributeName))\n }\n\n /**\n * Returns all attribute name/value pairs in a JSON Object.\n *\n * @param {Snapshot} [snapshot]\n * @return {{ [Key in Extract<keyof KV,string>]?: KV[Key]}} A JSON Object that describes the attributes.\n *\n * @public\n */\n getAttributes (snapshot) {\n return /** @type {any} */ (snapshot ? typeMapGetAllSnapshot(this, snapshot) : typeMapGetAll(this))\n }\n\n /**\n * Creates a Dom Element that mirrors this YXmlElement.\n *\n * @param {Document} [_document=document] The document object (you must define\n * this when calling this method in\n * nodejs)\n * @param {Object<string, any>} [hooks={}] Optional property to customize how hooks\n * are presented in the DOM\n * @param {any} [binding] You should not set this property. This is\n * used if DomBinding wants to create a\n * association to the created DOM type.\n * @return {Node} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element}\n *\n * @public\n */\n toDOM (_document = document, hooks = {}, binding) {\n const dom = _document.createElement(this.nodeName)\n const attrs = this.getAttributes()\n for (const key in attrs) {\n const value = attrs[key]\n if (typeof value === 'string') {\n dom.setAttribute(key, value)\n }\n }\n typeListForEach(this, yxml => {\n dom.appendChild(yxml.toDOM(_document, hooks, binding))\n })\n if (binding !== undefined) {\n binding._createAssociation(dom, this)\n }\n return dom\n }\n\n /**\n * Transform the properties of this type to binary and write it to an\n * BinaryEncoder.\n *\n * This is called when this Item is sent to a remote peer.\n *\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.\n */\n _write (encoder) {\n encoder.writeTypeRef(YXmlElementRefID)\n encoder.writeKey(this.nodeName)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {YXmlElement}\n *\n * @function\n */\nexport const readYXmlElement = decoder => new YXmlElement(decoder.readKey())\n","import {\n YEvent,\n YXmlText, YXmlElement, YXmlFragment, Transaction // eslint-disable-line\n} from '../internals.js'\n\n/**\n * @extends YEvent<YXmlElement|YXmlText|YXmlFragment>\n * An Event that describes changes on a YXml Element or Yxml Fragment\n */\nexport class YXmlEvent extends YEvent {\n /**\n * @param {YXmlElement|YXmlText|YXmlFragment} target The target on which the event is created.\n * @param {Set<string|null>} subs The set of changed attributes. `null` is included if the\n * child list changed.\n * @param {Transaction} transaction The transaction instance with which the\n * change was created.\n */\n constructor (target, subs, transaction) {\n super(target, transaction)\n /**\n * Whether the children changed.\n * @type {Boolean}\n * @private\n */\n this.childListChanged = false\n /**\n * Set of all changed attributes.\n * @type {Set<string>}\n */\n this.attributesChanged = new Set()\n subs.forEach((sub) => {\n if (sub === null) {\n this.childListChanged = true\n } else {\n this.attributesChanged.add(sub)\n }\n })\n }\n}\n","import {\n YMap,\n YXmlHookRefID,\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2 // eslint-disable-line\n} from '../internals.js'\n\n/**\n * You can manage binding to a custom type with YXmlHook.\n *\n * @extends {YMap<any>}\n */\nexport class YXmlHook extends YMap {\n /**\n * @param {string} hookName nodeName of the Dom Node.\n */\n constructor (hookName) {\n super()\n /**\n * @type {string}\n */\n this.hookName = hookName\n }\n\n /**\n * Creates an Item with the same effect as this Item (without position effect)\n */\n _copy () {\n return new YXmlHook(this.hookName)\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YXmlHook}\n */\n clone () {\n const el = new YXmlHook(this.hookName)\n this.forEach((value, key) => {\n el.set(key, value)\n })\n return el\n }\n\n /**\n * Creates a Dom Element that mirrors this YXmlElement.\n *\n * @param {Document} [_document=document] The document object (you must define\n * this when calling this method in\n * nodejs)\n * @param {Object.<string, any>} [hooks] Optional property to customize how hooks\n * are presented in the DOM\n * @param {any} [binding] You should not set this property. This is\n * used if DomBinding wants to create a\n * association to the created DOM type\n * @return {Element} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element}\n *\n * @public\n */\n toDOM (_document = document, hooks = {}, binding) {\n const hook = hooks[this.hookName]\n let dom\n if (hook !== undefined) {\n dom = hook.createDom(this)\n } else {\n dom = document.createElement(this.hookName)\n }\n dom.setAttribute('data-yjs-hook', this.hookName)\n if (binding !== undefined) {\n binding._createAssociation(dom, this)\n }\n return dom\n }\n\n /**\n * Transform the properties of this type to binary and write it to an\n * BinaryEncoder.\n *\n * This is called when this Item is sent to a remote peer.\n *\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.\n */\n _write (encoder) {\n encoder.writeTypeRef(YXmlHookRefID)\n encoder.writeKey(this.hookName)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {YXmlHook}\n *\n * @private\n * @function\n */\nexport const readYXmlHook = decoder =>\n new YXmlHook(decoder.readKey())\n","import {\n YText,\n YXmlTextRefID,\n ContentType, YXmlElement, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, // eslint-disable-line\n} from '../internals.js'\n\n/**\n * Represents text in a Dom Element. In the future this type will also handle\n * simple formatting information like bold and italic.\n */\nexport class YXmlText extends YText {\n /**\n * @type {YXmlElement|YXmlText|null}\n */\n get nextSibling () {\n const n = this._item ? this._item.next : null\n return n ? /** @type {YXmlElement|YXmlText} */ (/** @type {ContentType} */ (n.content).type) : null\n }\n\n /**\n * @type {YXmlElement|YXmlText|null}\n */\n get prevSibling () {\n const n = this._item ? this._item.prev : null\n return n ? /** @type {YXmlElement|YXmlText} */ (/** @type {ContentType} */ (n.content).type) : null\n }\n\n _copy () {\n return new YXmlText()\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YXmlText}\n */\n clone () {\n const text = new YXmlText()\n text.applyDelta(this.toDelta())\n return text\n }\n\n /**\n * Creates a Dom Element that mirrors this YXmlText.\n *\n * @param {Document} [_document=document] The document object (you must define\n * this when calling this method in\n * nodejs)\n * @param {Object<string, any>} [hooks] Optional property to customize how hooks\n * are presented in the DOM\n * @param {any} [binding] You should not set this property. This is\n * used if DomBinding wants to create a\n * association to the created DOM type.\n * @return {Text} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element}\n *\n * @public\n */\n toDOM (_document = document, hooks, binding) {\n const dom = _document.createTextNode(this.toString())\n if (binding !== undefined) {\n binding._createAssociation(dom, this)\n }\n return dom\n }\n\n toString () {\n // @ts-ignore\n return this.toDelta().map(delta => {\n const nestedNodes = []\n for (const nodeName in delta.attributes) {\n const attrs = []\n for (const key in delta.attributes[nodeName]) {\n attrs.push({ key, value: delta.attributes[nodeName][key] })\n }\n // sort attributes to get a unique order\n attrs.sort((a, b) => a.key < b.key ? -1 : 1)\n nestedNodes.push({ nodeName, attrs })\n }\n // sort node order to get a unique order\n nestedNodes.sort((a, b) => a.nodeName < b.nodeName ? -1 : 1)\n // now convert to dom string\n let str = ''\n for (let i = 0; i < nestedNodes.length; i++) {\n const node = nestedNodes[i]\n str += `<${node.nodeName}`\n for (let j = 0; j < node.attrs.length; j++) {\n const attr = node.attrs[j]\n str += ` ${attr.key}=\"${attr.value}\"`\n }\n str += '>'\n }\n str += delta.insert\n for (let i = nestedNodes.length - 1; i >= 0; i--) {\n str += `</${nestedNodes[i].nodeName}>`\n }\n return str\n }).join('')\n }\n\n /**\n * @return {string}\n */\n toJSON () {\n return this.toString()\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n */\n _write (encoder) {\n encoder.writeTypeRef(YXmlTextRefID)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {YXmlText}\n *\n * @private\n * @function\n */\nexport const readYXmlText = decoder => new YXmlText()\n","import {\n UpdateEncoderV1, UpdateEncoderV2, ID, Transaction // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\n\nexport class AbstractStruct {\n /**\n * @param {ID} id\n * @param {number} length\n */\n constructor (id, length) {\n this.id = id\n this.length = length\n }\n\n /**\n * @type {boolean}\n */\n get deleted () {\n throw error.methodUnimplemented()\n }\n\n /**\n * Merge this struct with the item to the right.\n * This method is already assuming that `this.id.clock + this.length === this.id.clock`.\n * Also this method does *not* remove right from StructStore!\n * @param {AbstractStruct} right\n * @return {boolean} whether this merged with right\n */\n mergeWith (right) {\n return false\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.\n * @param {number} offset\n * @param {number} encodingRef\n */\n write (encoder, offset, encodingRef) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {Transaction} transaction\n * @param {number} offset\n */\n integrate (transaction, offset) {\n throw error.methodUnimplemented()\n }\n}\n","import {\n AbstractStruct,\n addStruct,\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, ID // eslint-disable-line\n} from '../internals.js'\n\nexport const structGCRefNumber = 0\n\n/**\n * @private\n */\nexport class GC extends AbstractStruct {\n get deleted () {\n return true\n }\n\n delete () {}\n\n /**\n * @param {GC} right\n * @return {boolean}\n */\n mergeWith (right) {\n if (this.constructor !== right.constructor) {\n return false\n }\n this.length += right.length\n return true\n }\n\n /**\n * @param {Transaction} transaction\n * @param {number} offset\n */\n integrate (transaction, offset) {\n if (offset > 0) {\n this.id.clock += offset\n this.length -= offset\n }\n addStruct(transaction.doc.store, this)\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeInfo(structGCRefNumber)\n encoder.writeLen(this.length - offset)\n }\n\n /**\n * @param {Transaction} transaction\n * @param {StructStore} store\n * @return {null | number}\n */\n getMissing (transaction, store) {\n return null\n }\n}\n","import {\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Item, Transaction // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\n\nexport class ContentBinary {\n /**\n * @param {Uint8Array} content\n */\n constructor (content) {\n this.content = content\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return 1\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return [this.content]\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentBinary}\n */\n copy () {\n return new ContentBinary(this.content)\n }\n\n /**\n * @param {number} offset\n * @return {ContentBinary}\n */\n splice (offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {ContentBinary} right\n * @return {boolean}\n */\n mergeWith (right) {\n return false\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {}\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeBuf(this.content)\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 3\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2 } decoder\n * @return {ContentBinary}\n */\nexport const readContentBinary = decoder => new ContentBinary(decoder.readBuf())\n","import {\n addToDeleteSet,\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Item, Transaction // eslint-disable-line\n} from '../internals.js'\n\nexport class ContentDeleted {\n /**\n * @param {number} len\n */\n constructor (len) {\n this.len = len\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return this.len\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return []\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return false\n }\n\n /**\n * @return {ContentDeleted}\n */\n copy () {\n return new ContentDeleted(this.len)\n }\n\n /**\n * @param {number} offset\n * @return {ContentDeleted}\n */\n splice (offset) {\n const right = new ContentDeleted(this.len - offset)\n this.len = offset\n return right\n }\n\n /**\n * @param {ContentDeleted} right\n * @return {boolean}\n */\n mergeWith (right) {\n this.len += right.len\n return true\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {\n addToDeleteSet(transaction.deleteSet, item.id.client, item.id.clock, this.len)\n item.markDeleted()\n }\n\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeLen(this.len - offset)\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 1\n }\n}\n\n/**\n * @private\n *\n * @param {UpdateDecoderV1 | UpdateDecoderV2 } decoder\n * @return {ContentDeleted}\n */\nexport const readContentDeleted = decoder => new ContentDeleted(decoder.readLen())\n","import {\n Doc, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, Item // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\n\n/**\n * @param {string} guid\n * @param {Object<string, any>} opts\n */\nconst createDocFromOpts = (guid, opts) => new Doc({ guid, ...opts, shouldLoad: opts.shouldLoad || opts.autoLoad || false })\n\n/**\n * @private\n */\nexport class ContentDoc {\n /**\n * @param {Doc} doc\n */\n constructor (doc) {\n if (doc._item) {\n console.error('This document was already integrated as a sub-document. You should create a second instance instead with the same guid.')\n }\n /**\n * @type {Doc}\n */\n this.doc = doc\n /**\n * @type {any}\n */\n const opts = {}\n this.opts = opts\n if (!doc.gc) {\n opts.gc = false\n }\n if (doc.autoLoad) {\n opts.autoLoad = true\n }\n if (doc.meta !== null) {\n opts.meta = doc.meta\n }\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return 1\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return [this.doc]\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentDoc}\n */\n copy () {\n return new ContentDoc(createDocFromOpts(this.doc.guid, this.opts))\n }\n\n /**\n * @param {number} offset\n * @return {ContentDoc}\n */\n splice (offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {ContentDoc} right\n * @return {boolean}\n */\n mergeWith (right) {\n return false\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {\n // this needs to be reflected in doc.destroy as well\n this.doc._item = item\n transaction.subdocsAdded.add(this.doc)\n if (this.doc.shouldLoad) {\n transaction.subdocsLoaded.add(this.doc)\n }\n }\n\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {\n if (transaction.subdocsAdded.has(this.doc)) {\n transaction.subdocsAdded.delete(this.doc)\n } else {\n transaction.subdocsRemoved.add(this.doc)\n }\n }\n\n /**\n * @param {StructStore} store\n */\n gc (store) { }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeString(this.doc.guid)\n encoder.writeAny(this.opts)\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 9\n }\n}\n\n/**\n * @private\n *\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentDoc}\n */\nexport const readContentDoc = decoder => new ContentDoc(createDocFromOpts(decoder.readString(), decoder.readAny()))\n","import {\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Item, Transaction // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\n\n/**\n * @private\n */\nexport class ContentEmbed {\n /**\n * @param {Object} embed\n */\n constructor (embed) {\n this.embed = embed\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return 1\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return [this.embed]\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentEmbed}\n */\n copy () {\n return new ContentEmbed(this.embed)\n }\n\n /**\n * @param {number} offset\n * @return {ContentEmbed}\n */\n splice (offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {ContentEmbed} right\n * @return {boolean}\n */\n mergeWith (right) {\n return false\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {}\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeJSON(this.embed)\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 5\n }\n}\n\n/**\n * @private\n *\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentEmbed}\n */\nexport const readContentEmbed = decoder => new ContentEmbed(decoder.readJSON())\n","import {\n YText, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Item, StructStore, Transaction // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\n\n/**\n * @private\n */\nexport class ContentFormat {\n /**\n * @param {string} key\n * @param {Object} value\n */\n constructor (key, value) {\n this.key = key\n this.value = value\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return 1\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return []\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return false\n }\n\n /**\n * @return {ContentFormat}\n */\n copy () {\n return new ContentFormat(this.key, this.value)\n }\n\n /**\n * @param {number} _offset\n * @return {ContentFormat}\n */\n splice (_offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {ContentFormat} _right\n * @return {boolean}\n */\n mergeWith (_right) {\n return false\n }\n\n /**\n * @param {Transaction} _transaction\n * @param {Item} item\n */\n integrate (_transaction, item) {\n // @todo searchmarker are currently unsupported for rich text documents\n const p = /** @type {YText} */ (item.parent)\n p._searchMarker = null\n p._hasFormatting = true\n }\n\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeKey(this.key)\n encoder.writeJSON(this.value)\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 6\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentFormat}\n */\nexport const readContentFormat = decoder => new ContentFormat(decoder.readKey(), decoder.readJSON())\n","import {\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Transaction, Item, StructStore // eslint-disable-line\n} from '../internals.js'\n\n/**\n * @private\n */\nexport class ContentJSON {\n /**\n * @param {Array<any>} arr\n */\n constructor (arr) {\n /**\n * @type {Array<any>}\n */\n this.arr = arr\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return this.arr.length\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return this.arr\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentJSON}\n */\n copy () {\n return new ContentJSON(this.arr)\n }\n\n /**\n * @param {number} offset\n * @return {ContentJSON}\n */\n splice (offset) {\n const right = new ContentJSON(this.arr.slice(offset))\n this.arr = this.arr.slice(0, offset)\n return right\n }\n\n /**\n * @param {ContentJSON} right\n * @return {boolean}\n */\n mergeWith (right) {\n this.arr = this.arr.concat(right.arr)\n return true\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {}\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n const len = this.arr.length\n encoder.writeLen(len - offset)\n for (let i = offset; i < len; i++) {\n const c = this.arr[i]\n encoder.writeString(c === undefined ? 'undefined' : JSON.stringify(c))\n }\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 2\n }\n}\n\n/**\n * @private\n *\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentJSON}\n */\nexport const readContentJSON = decoder => {\n const len = decoder.readLen()\n const cs = []\n for (let i = 0; i < len; i++) {\n const c = decoder.readString()\n if (c === 'undefined') {\n cs.push(undefined)\n } else {\n cs.push(JSON.parse(c))\n }\n }\n return new ContentJSON(cs)\n}\n","import {\n UpdateEncoderV1, UpdateEncoderV2, UpdateDecoderV1, UpdateDecoderV2, Transaction, Item, StructStore // eslint-disable-line\n} from '../internals.js'\n\nimport * as env from 'lib0/environment'\nimport * as object from 'lib0/object'\n\nconst isDevMode = env.getVariable('node_env') === 'development'\n\nexport class ContentAny {\n /**\n * @param {Array<any>} arr\n */\n constructor (arr) {\n /**\n * @type {Array<any>}\n */\n this.arr = arr\n isDevMode && object.deepFreeze(arr)\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return this.arr.length\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return this.arr\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentAny}\n */\n copy () {\n return new ContentAny(this.arr)\n }\n\n /**\n * @param {number} offset\n * @return {ContentAny}\n */\n splice (offset) {\n const right = new ContentAny(this.arr.slice(offset))\n this.arr = this.arr.slice(0, offset)\n return right\n }\n\n /**\n * @param {ContentAny} right\n * @return {boolean}\n */\n mergeWith (right) {\n this.arr = this.arr.concat(right.arr)\n return true\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {}\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n const len = this.arr.length\n encoder.writeLen(len - offset)\n for (let i = offset; i < len; i++) {\n const c = this.arr[i]\n encoder.writeAny(c)\n }\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 8\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentAny}\n */\nexport const readContentAny = decoder => {\n const len = decoder.readLen()\n const cs = []\n for (let i = 0; i < len; i++) {\n cs.push(decoder.readAny())\n }\n return new ContentAny(cs)\n}\n","import {\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Transaction, Item, StructStore // eslint-disable-line\n} from '../internals.js'\n\n/**\n * @private\n */\nexport class ContentString {\n /**\n * @param {string} str\n */\n constructor (str) {\n /**\n * @type {string}\n */\n this.str = str\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return this.str.length\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return this.str.split('')\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentString}\n */\n copy () {\n return new ContentString(this.str)\n }\n\n /**\n * @param {number} offset\n * @return {ContentString}\n */\n splice (offset) {\n const right = new ContentString(this.str.slice(offset))\n this.str = this.str.slice(0, offset)\n\n // Prevent encoding invalid documents because of splitting of surrogate pairs: https://github.com/yjs/yjs/issues/248\n const firstCharCode = this.str.charCodeAt(offset - 1)\n if (firstCharCode >= 0xD800 && firstCharCode <= 0xDBFF) {\n // Last character of the left split is the start of a surrogate utf16/ucs2 pair.\n // We don't support splitting of surrogate pairs because this may lead to invalid documents.\n // Replace the invalid character with a unicode replacement character (� / U+FFFD)\n this.str = this.str.slice(0, offset - 1) + '�'\n // replace right as well\n right.str = '�' + right.str.slice(1)\n }\n return right\n }\n\n /**\n * @param {ContentString} right\n * @return {boolean}\n */\n mergeWith (right) {\n this.str += right.str\n return true\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {}\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeString(offset === 0 ? this.str : this.str.slice(offset))\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 4\n }\n}\n\n/**\n * @private\n *\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentString}\n */\nexport const readContentString = decoder => new ContentString(decoder.readString())\n","import {\n readYArray,\n readYMap,\n readYText,\n readYXmlElement,\n readYXmlFragment,\n readYXmlHook,\n readYXmlText,\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, Item, YEvent, AbstractType // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\n\n/**\n * @type {Array<function(UpdateDecoderV1 | UpdateDecoderV2):AbstractType<any>>}\n * @private\n */\nexport const typeRefs = [\n readYArray,\n readYMap,\n readYText,\n readYXmlElement,\n readYXmlFragment,\n readYXmlHook,\n readYXmlText\n]\n\nexport const YArrayRefID = 0\nexport const YMapRefID = 1\nexport const YTextRefID = 2\nexport const YXmlElementRefID = 3\nexport const YXmlFragmentRefID = 4\nexport const YXmlHookRefID = 5\nexport const YXmlTextRefID = 6\n\n/**\n * @private\n */\nexport class ContentType {\n /**\n * @param {AbstractType<any>} type\n */\n constructor (type) {\n /**\n * @type {AbstractType<any>}\n */\n this.type = type\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return 1\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return [this.type]\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentType}\n */\n copy () {\n return new ContentType(this.type._copy())\n }\n\n /**\n * @param {number} offset\n * @return {ContentType}\n */\n splice (offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {ContentType} right\n * @return {boolean}\n */\n mergeWith (right) {\n return false\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {\n this.type._integrate(transaction.doc, item)\n }\n\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {\n let item = this.type._start\n while (item !== null) {\n if (!item.deleted) {\n item.delete(transaction)\n } else if (item.id.clock < (transaction.beforeState.get(item.id.client) || 0)) {\n // This will be gc'd later and we want to merge it if possible\n // We try to merge all deleted items after each transaction,\n // but we have no knowledge about that this needs to be merged\n // since it is not in transaction.ds. Hence we add it to transaction._mergeStructs\n transaction._mergeStructs.push(item)\n }\n item = item.right\n }\n this.type._map.forEach(item => {\n if (!item.deleted) {\n item.delete(transaction)\n } else if (item.id.clock < (transaction.beforeState.get(item.id.client) || 0)) {\n // same as above\n transaction._mergeStructs.push(item)\n }\n })\n transaction.changed.delete(this.type)\n }\n\n /**\n * @param {StructStore} store\n */\n gc (store) {\n let item = this.type._start\n while (item !== null) {\n item.gc(store, true)\n item = item.right\n }\n this.type._start = null\n this.type._map.forEach(/** @param {Item | null} item */ (item) => {\n while (item !== null) {\n item.gc(store, true)\n item = item.left\n }\n })\n this.type._map = new Map()\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n this.type._write(encoder)\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 7\n }\n}\n\n/**\n * @private\n *\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentType}\n */\nexport const readContentType = decoder => new ContentType(typeRefs[decoder.readTypeRef()](decoder))\n","import {\n GC,\n getState,\n AbstractStruct,\n replaceStruct,\n addStruct,\n addToDeleteSet,\n findRootTypeKey,\n compareIDs,\n getItem,\n getItemCleanEnd,\n getItemCleanStart,\n readContentDeleted,\n readContentBinary,\n readContentJSON,\n readContentAny,\n readContentString,\n readContentEmbed,\n readContentDoc,\n createID,\n readContentFormat,\n readContentType,\n addChangedTypeToTransaction,\n isDeleted,\n StackItem, DeleteSet, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ContentType, ContentDeleted, StructStore, ID, AbstractType, Transaction // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\nimport * as binary from 'lib0/binary'\nimport * as array from 'lib0/array'\n\n/**\n * @todo This should return several items\n *\n * @param {StructStore} store\n * @param {ID} id\n * @return {{item:Item, diff:number}}\n */\nexport const followRedone = (store, id) => {\n /**\n * @type {ID|null}\n */\n let nextID = id\n let diff = 0\n let item\n do {\n if (diff > 0) {\n nextID = createID(nextID.client, nextID.clock + diff)\n }\n item = getItem(store, nextID)\n diff = nextID.clock - item.id.clock\n nextID = item.redone\n } while (nextID !== null && item instanceof Item)\n return {\n item, diff\n }\n}\n\n/**\n * Make sure that neither item nor any of its parents is ever deleted.\n *\n * This property does not persist when storing it into a database or when\n * sending it to other peers\n *\n * @param {Item|null} item\n * @param {boolean} keep\n */\nexport const keepItem = (item, keep) => {\n while (item !== null && item.keep !== keep) {\n item.keep = keep\n item = /** @type {AbstractType<any>} */ (item.parent)._item\n }\n}\n\n/**\n * Split leftItem into two items\n * @param {Transaction} transaction\n * @param {Item} leftItem\n * @param {number} diff\n * @return {Item}\n *\n * @function\n * @private\n */\nexport const splitItem = (transaction, leftItem, diff) => {\n // create rightItem\n const { client, clock } = leftItem.id\n const rightItem = new Item(\n createID(client, clock + diff),\n leftItem,\n createID(client, clock + diff - 1),\n leftItem.right,\n leftItem.rightOrigin,\n leftItem.parent,\n leftItem.parentSub,\n leftItem.content.splice(diff)\n )\n if (leftItem.deleted) {\n rightItem.markDeleted()\n }\n if (leftItem.keep) {\n rightItem.keep = true\n }\n if (leftItem.redone !== null) {\n rightItem.redone = createID(leftItem.redone.client, leftItem.redone.clock + diff)\n }\n // update left (do not set leftItem.rightOrigin as it will lead to problems when syncing)\n leftItem.right = rightItem\n // update right\n if (rightItem.right !== null) {\n rightItem.right.left = rightItem\n }\n // right is more specific.\n transaction._mergeStructs.push(rightItem)\n // update parent._map\n if (rightItem.parentSub !== null && rightItem.right === null) {\n /** @type {AbstractType<any>} */ (rightItem.parent)._map.set(rightItem.parentSub, rightItem)\n }\n leftItem.length = diff\n return rightItem\n}\n\n/**\n * @param {Array<StackItem>} stack\n * @param {ID} id\n */\nconst isDeletedByUndoStack = (stack, id) => array.some(stack, /** @param {StackItem} s */ s => isDeleted(s.deletions, id))\n\n/**\n * Redoes the effect of this operation.\n *\n * @param {Transaction} transaction The Yjs instance.\n * @param {Item} item\n * @param {Set<Item>} redoitems\n * @param {DeleteSet} itemsToDelete\n * @param {boolean} ignoreRemoteMapChanges\n * @param {import('../utils/UndoManager.js').UndoManager} um\n *\n * @return {Item|null}\n *\n * @private\n */\nexport const redoItem = (transaction, item, redoitems, itemsToDelete, ignoreRemoteMapChanges, um) => {\n const doc = transaction.doc\n const store = doc.store\n const ownClientID = doc.clientID\n const redone = item.redone\n if (redone !== null) {\n return getItemCleanStart(transaction, redone)\n }\n let parentItem = /** @type {AbstractType<any>} */ (item.parent)._item\n /**\n * @type {Item|null}\n */\n let left = null\n /**\n * @type {Item|null}\n */\n let right\n // make sure that parent is redone\n if (parentItem !== null && parentItem.deleted === true) {\n // try to undo parent if it will be undone anyway\n if (parentItem.redone === null && (!redoitems.has(parentItem) || redoItem(transaction, parentItem, redoitems, itemsToDelete, ignoreRemoteMapChanges, um) === null)) {\n return null\n }\n while (parentItem.redone !== null) {\n parentItem = getItemCleanStart(transaction, parentItem.redone)\n }\n }\n const parentType = parentItem === null ? /** @type {AbstractType<any>} */ (item.parent) : /** @type {ContentType} */ (parentItem.content).type\n\n if (item.parentSub === null) {\n // Is an array item. Insert at the old position\n left = item.left\n right = item\n // find next cloned_redo items\n while (left !== null) {\n /**\n * @type {Item|null}\n */\n let leftTrace = left\n // trace redone until parent matches\n while (leftTrace !== null && /** @type {AbstractType<any>} */ (leftTrace.parent)._item !== parentItem) {\n leftTrace = leftTrace.redone === null ? null : getItemCleanStart(transaction, leftTrace.redone)\n }\n if (leftTrace !== null && /** @type {AbstractType<any>} */ (leftTrace.parent)._item === parentItem) {\n left = leftTrace\n break\n }\n left = left.left\n }\n while (right !== null) {\n /**\n * @type {Item|null}\n */\n let rightTrace = right\n // trace redone until parent matches\n while (rightTrace !== null && /** @type {AbstractType<any>} */ (rightTrace.parent)._item !== parentItem) {\n rightTrace = rightTrace.redone === null ? null : getItemCleanStart(transaction, rightTrace.redone)\n }\n if (rightTrace !== null && /** @type {AbstractType<any>} */ (rightTrace.parent)._item === parentItem) {\n right = rightTrace\n break\n }\n right = right.right\n }\n } else {\n right = null\n if (item.right && !ignoreRemoteMapChanges) {\n left = item\n // Iterate right while right is in itemsToDelete\n // If it is intended to delete right while item is redone, we can expect that item should replace right.\n while (left !== null && left.right !== null && (left.right.redone || isDeleted(itemsToDelete, left.right.id) || isDeletedByUndoStack(um.undoStack, left.right.id) || isDeletedByUndoStack(um.redoStack, left.right.id))) {\n left = left.right\n // follow redone\n while (left.redone) left = getItemCleanStart(transaction, left.redone)\n }\n if (left && left.right !== null) {\n // It is not possible to redo this item because it conflicts with a\n // change from another client\n return null\n }\n } else {\n left = parentType._map.get(item.parentSub) || null\n }\n }\n const nextClock = getState(store, ownClientID)\n const nextId = createID(ownClientID, nextClock)\n const redoneItem = new Item(\n nextId,\n left, left && left.lastId,\n right, right && right.id,\n parentType,\n item.parentSub,\n item.content.copy()\n )\n item.redone = nextId\n keepItem(redoneItem, true)\n redoneItem.integrate(transaction, 0)\n return redoneItem\n}\n\n/**\n * Abstract class that represents any content.\n */\nexport class Item extends AbstractStruct {\n /**\n * @param {ID} id\n * @param {Item | null} left\n * @param {ID | null} origin\n * @param {Item | null} right\n * @param {ID | null} rightOrigin\n * @param {AbstractType<any>|ID|null} parent Is a type if integrated, is null if it is possible to copy parent from left or right, is ID before integration to search for it.\n * @param {string | null} parentSub\n * @param {AbstractContent} content\n */\n constructor (id, left, origin, right, rightOrigin, parent, parentSub, content) {\n super(id, content.getLength())\n /**\n * The item that was originally to the left of this item.\n * @type {ID | null}\n */\n this.origin = origin\n /**\n * The item that is currently to the left of this item.\n * @type {Item | null}\n */\n this.left = left\n /**\n * The item that is currently to the right of this item.\n * @type {Item | null}\n */\n this.right = right\n /**\n * The item that was originally to the right of this item.\n * @type {ID | null}\n */\n this.rightOrigin = rightOrigin\n /**\n * @type {AbstractType<any>|ID|null}\n */\n this.parent = parent\n /**\n * If the parent refers to this item with some kind of key (e.g. YMap, the\n * key is specified here. The key is then used to refer to the list in which\n * to insert this item. If `parentSub = null` type._start is the list in\n * which to insert to. Otherwise it is `parent._map`.\n * @type {String | null}\n */\n this.parentSub = parentSub\n /**\n * If this type's effect is redone this type refers to the type that undid\n * this operation.\n * @type {ID | null}\n */\n this.redone = null\n /**\n * @type {AbstractContent}\n */\n this.content = content\n /**\n * bit1: keep\n * bit2: countable\n * bit3: deleted\n * bit4: mark - mark node as fast-search-marker\n * @type {number} byte\n */\n this.info = this.content.isCountable() ? binary.BIT2 : 0\n }\n\n /**\n * This is used to mark the item as an indexed fast-search marker\n *\n * @type {boolean}\n */\n set marker (isMarked) {\n if (((this.info & binary.BIT4) > 0) !== isMarked) {\n this.info ^= binary.BIT4\n }\n }\n\n get marker () {\n return (this.info & binary.BIT4) > 0\n }\n\n /**\n * If true, do not garbage collect this Item.\n */\n get keep () {\n return (this.info & binary.BIT1) > 0\n }\n\n set keep (doKeep) {\n if (this.keep !== doKeep) {\n this.info ^= binary.BIT1\n }\n }\n\n get countable () {\n return (this.info & binary.BIT2) > 0\n }\n\n /**\n * Whether this item was deleted or not.\n * @type {Boolean}\n */\n get deleted () {\n return (this.info & binary.BIT3) > 0\n }\n\n set deleted (doDelete) {\n if (this.deleted !== doDelete) {\n this.info ^= binary.BIT3\n }\n }\n\n markDeleted () {\n this.info |= binary.BIT3\n }\n\n /**\n * Return the creator clientID of the missing op or define missing items and return null.\n *\n * @param {Transaction} transaction\n * @param {StructStore} store\n * @return {null | number}\n */\n getMissing (transaction, store) {\n if (this.origin && this.origin.client !== this.id.client && this.origin.clock >= getState(store, this.origin.client)) {\n return this.origin.client\n }\n if (this.rightOrigin && this.rightOrigin.client !== this.id.client && this.rightOrigin.clock >= getState(store, this.rightOrigin.client)) {\n return this.rightOrigin.client\n }\n if (this.parent && this.parent.constructor === ID && this.id.client !== this.parent.client && this.parent.clock >= getState(store, this.parent.client)) {\n return this.parent.client\n }\n\n // We have all missing ids, now find the items\n\n if (this.origin) {\n this.left = getItemCleanEnd(transaction, store, this.origin)\n this.origin = this.left.lastId\n }\n if (this.rightOrigin) {\n this.right = getItemCleanStart(transaction, this.rightOrigin)\n this.rightOrigin = this.right.id\n }\n if ((this.left && this.left.constructor === GC) || (this.right && this.right.constructor === GC)) {\n this.parent = null\n } else if (!this.parent) {\n // only set parent if this shouldn't be garbage collected\n if (this.left && this.left.constructor === Item) {\n this.parent = this.left.parent\n this.parentSub = this.left.parentSub\n } else if (this.right && this.right.constructor === Item) {\n this.parent = this.right.parent\n this.parentSub = this.right.parentSub\n }\n } else if (this.parent.constructor === ID) {\n const parentItem = getItem(store, this.parent)\n if (parentItem.constructor === GC) {\n this.parent = null\n } else {\n this.parent = /** @type {ContentType} */ (parentItem.content).type\n }\n }\n return null\n }\n\n /**\n * @param {Transaction} transaction\n * @param {number} offset\n */\n integrate (transaction, offset) {\n if (offset > 0) {\n this.id.clock += offset\n this.left = getItemCleanEnd(transaction, transaction.doc.store, createID(this.id.client, this.id.clock - 1))\n this.origin = this.left.lastId\n this.content = this.content.splice(offset)\n this.length -= offset\n }\n\n if (this.parent) {\n if ((!this.left && (!this.right || this.right.left !== null)) || (this.left && this.left.right !== this.right)) {\n /**\n * @type {Item|null}\n */\n let left = this.left\n\n /**\n * @type {Item|null}\n */\n let o\n // set o to the first conflicting item\n if (left !== null) {\n o = left.right\n } else if (this.parentSub !== null) {\n o = /** @type {AbstractType<any>} */ (this.parent)._map.get(this.parentSub) || null\n while (o !== null && o.left !== null) {\n o = o.left\n }\n } else {\n o = /** @type {AbstractType<any>} */ (this.parent)._start\n }\n // TODO: use something like DeleteSet here (a tree implementation would be best)\n // @todo use global set definitions\n /**\n * @type {Set<Item>}\n */\n const conflictingItems = new Set()\n /**\n * @type {Set<Item>}\n */\n const itemsBeforeOrigin = new Set()\n // Let c in conflictingItems, b in itemsBeforeOrigin\n // ***{origin}bbbb{this}{c,b}{c,b}{o}***\n // Note that conflictingItems is a subset of itemsBeforeOrigin\n while (o !== null && o !== this.right) {\n itemsBeforeOrigin.add(o)\n conflictingItems.add(o)\n if (compareIDs(this.origin, o.origin)) {\n // case 1\n if (o.id.client < this.id.client) {\n left = o\n conflictingItems.clear()\n } else if (compareIDs(this.rightOrigin, o.rightOrigin)) {\n // this and o are conflicting and point to the same integration points. The id decides which item comes first.\n // Since this is to the left of o, we can break here\n break\n } // else, o might be integrated before an item that this conflicts with. If so, we will find it in the next iterations\n } else if (o.origin !== null && itemsBeforeOrigin.has(getItem(transaction.doc.store, o.origin))) { // use getItem instead of getItemCleanEnd because we don't want / need to split items.\n // case 2\n if (!conflictingItems.has(getItem(transaction.doc.store, o.origin))) {\n left = o\n conflictingItems.clear()\n }\n } else {\n break\n }\n o = o.right\n }\n this.left = left\n }\n // reconnect left/right + update parent map/start if necessary\n if (this.left !== null) {\n const right = this.left.right\n this.right = right\n this.left.right = this\n } else {\n let r\n if (this.parentSub !== null) {\n r = /** @type {AbstractType<any>} */ (this.parent)._map.get(this.parentSub) || null\n while (r !== null && r.left !== null) {\n r = r.left\n }\n } else {\n r = /** @type {AbstractType<any>} */ (this.parent)._start\n ;/** @type {AbstractType<any>} */ (this.parent)._start = this\n }\n this.right = r\n }\n if (this.right !== null) {\n this.right.left = this\n } else if (this.parentSub !== null) {\n // set as current parent value if right === null and this is parentSub\n /** @type {AbstractType<any>} */ (this.parent)._map.set(this.parentSub, this)\n if (this.left !== null) {\n // this is the current attribute value of parent. delete right\n this.left.delete(transaction)\n }\n }\n // adjust length of parent\n if (this.parentSub === null && this.countable && !this.deleted) {\n /** @type {AbstractType<any>} */ (this.parent)._length += this.length\n }\n addStruct(transaction.doc.store, this)\n this.content.integrate(transaction, this)\n // add parent to transaction.changed\n addChangedTypeToTransaction(transaction, /** @type {AbstractType<any>} */ (this.parent), this.parentSub)\n if ((/** @type {AbstractType<any>} */ (this.parent)._item !== null && /** @type {AbstractType<any>} */ (this.parent)._item.deleted) || (this.parentSub !== null && this.right !== null)) {\n // delete if parent is deleted or if this is not the current attribute value of parent\n this.delete(transaction)\n }\n } else {\n // parent is not defined. Integrate GC struct instead\n new GC(this.id, this.length).integrate(transaction, 0)\n }\n }\n\n /**\n * Returns the next non-deleted item\n */\n get next () {\n let n = this.right\n while (n !== null && n.deleted) {\n n = n.right\n }\n return n\n }\n\n /**\n * Returns the previous non-deleted item\n */\n get prev () {\n let n = this.left\n while (n !== null && n.deleted) {\n n = n.left\n }\n return n\n }\n\n /**\n * Computes the last content address of this Item.\n */\n get lastId () {\n // allocating ids is pretty costly because of the amount of ids created, so we try to reuse whenever possible\n return this.length === 1 ? this.id : createID(this.id.client, this.id.clock + this.length - 1)\n }\n\n /**\n * Try to merge two items\n *\n * @param {Item} right\n * @return {boolean}\n */\n mergeWith (right) {\n if (\n this.constructor === right.constructor &&\n compareIDs(right.origin, this.lastId) &&\n this.right === right &&\n compareIDs(this.rightOrigin, right.rightOrigin) &&\n this.id.client === right.id.client &&\n this.id.clock + this.length === right.id.clock &&\n this.deleted === right.deleted &&\n this.redone === null &&\n right.redone === null &&\n this.content.constructor === right.content.constructor &&\n this.content.mergeWith(right.content)\n ) {\n const searchMarker = /** @type {AbstractType<any>} */ (this.parent)._searchMarker\n if (searchMarker) {\n searchMarker.forEach(marker => {\n if (marker.p === right) {\n // right is going to be \"forgotten\" so we need to update the marker\n marker.p = this\n // adjust marker index\n if (!this.deleted && this.countable) {\n marker.index -= this.length\n }\n }\n })\n }\n if (right.keep) {\n this.keep = true\n }\n this.right = right.right\n if (this.right !== null) {\n this.right.left = this\n }\n this.length += right.length\n return true\n }\n return false\n }\n\n /**\n * Mark this Item as deleted.\n *\n * @param {Transaction} transaction\n */\n delete (transaction) {\n if (!this.deleted) {\n const parent = /** @type {AbstractType<any>} */ (this.parent)\n // adjust the length of parent\n if (this.countable && this.parentSub === null) {\n parent._length -= this.length\n }\n this.markDeleted()\n addToDeleteSet(transaction.deleteSet, this.id.client, this.id.clock, this.length)\n addChangedTypeToTransaction(transaction, parent, this.parentSub)\n this.content.delete(transaction)\n }\n }\n\n /**\n * @param {StructStore} store\n * @param {boolean} parentGCd\n */\n gc (store, parentGCd) {\n if (!this.deleted) {\n throw error.unexpectedCase()\n }\n this.content.gc(store)\n if (parentGCd) {\n replaceStruct(store, this, new GC(this.id, this.length))\n } else {\n this.content = new ContentDeleted(this.length)\n }\n }\n\n /**\n * Transform the properties of this type to binary and write it to an\n * BinaryEncoder.\n *\n * This is called when this Item is sent to a remote peer.\n *\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.\n * @param {number} offset\n */\n write (encoder, offset) {\n const origin = offset > 0 ? createID(this.id.client, this.id.clock + offset - 1) : this.origin\n const rightOrigin = this.rightOrigin\n const parentSub = this.parentSub\n const info = (this.content.getRef() & binary.BITS5) |\n (origin === null ? 0 : binary.BIT8) | // origin is defined\n (rightOrigin === null ? 0 : binary.BIT7) | // right origin is defined\n (parentSub === null ? 0 : binary.BIT6) // parentSub is non-null\n encoder.writeInfo(info)\n if (origin !== null) {\n encoder.writeLeftID(origin)\n }\n if (rightOrigin !== null) {\n encoder.writeRightID(rightOrigin)\n }\n if (origin === null && rightOrigin === null) {\n const parent = /** @type {AbstractType<any>} */ (this.parent)\n if (parent._item !== undefined) {\n const parentItem = parent._item\n if (parentItem === null) {\n // parent type on y._map\n // find the correct key\n const ykey = findRootTypeKey(parent)\n encoder.writeParentInfo(true) // write parentYKey\n encoder.writeString(ykey)\n } else {\n encoder.writeParentInfo(false) // write parent id\n encoder.writeLeftID(parentItem.id)\n }\n } else if (parent.constructor === String) { // this edge case was added by differential updates\n encoder.writeParentInfo(true) // write parentYKey\n encoder.writeString(parent)\n } else if (parent.constructor === ID) {\n encoder.writeParentInfo(false) // write parent id\n encoder.writeLeftID(parent)\n } else {\n error.unexpectedCase()\n }\n if (parentSub !== null) {\n encoder.writeString(parentSub)\n }\n }\n this.content.write(encoder, offset)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @param {number} info\n */\nexport const readItemContent = (decoder, info) => contentRefs[info & binary.BITS5](decoder)\n\n/**\n * A lookup map for reading Item content.\n *\n * @type {Array<function(UpdateDecoderV1 | UpdateDecoderV2):AbstractContent>}\n */\nexport const contentRefs = [\n () => { error.unexpectedCase() }, // GC is not ItemContent\n readContentDeleted, // 1\n readContentJSON, // 2\n readContentBinary, // 3\n readContentString, // 4\n readContentEmbed, // 5\n readContentFormat, // 6\n readContentType, // 7\n readContentAny, // 8\n readContentDoc, // 9\n () => { error.unexpectedCase() } // 10 - Skip is not ItemContent\n]\n\n/**\n * Do not implement this class!\n */\nexport class AbstractContent {\n /**\n * @return {number}\n */\n getLength () {\n throw error.methodUnimplemented()\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n throw error.methodUnimplemented()\n }\n\n /**\n * Should return false if this Item is some kind of meta information\n * (e.g. format information).\n *\n * * Whether this Item should be addressable via `yarray.get(i)`\n * * Whether this Item should be counted when computing yarray.length\n *\n * @return {boolean}\n */\n isCountable () {\n throw error.methodUnimplemented()\n }\n\n /**\n * @return {AbstractContent}\n */\n copy () {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {number} _offset\n * @return {AbstractContent}\n */\n splice (_offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {AbstractContent} _right\n * @return {boolean}\n */\n mergeWith (_right) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {Transaction} _transaction\n * @param {Item} _item\n */\n integrate (_transaction, _item) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {Transaction} _transaction\n */\n delete (_transaction) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {StructStore} _store\n */\n gc (_store) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} _encoder\n * @param {number} _offset\n */\n write (_encoder, _offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @return {number}\n */\n getRef () {\n throw error.methodUnimplemented()\n }\n}\n","import {\n AbstractStruct,\n UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, ID // eslint-disable-line\n} from '../internals.js'\nimport * as error from 'lib0/error'\nimport * as encoding from 'lib0/encoding'\n\nexport const structSkipRefNumber = 10\n\n/**\n * @private\n */\nexport class Skip extends AbstractStruct {\n get deleted () {\n return true\n }\n\n delete () {}\n\n /**\n * @param {Skip} right\n * @return {boolean}\n */\n mergeWith (right) {\n if (this.constructor !== right.constructor) {\n return false\n }\n this.length += right.length\n return true\n }\n\n /**\n * @param {Transaction} transaction\n * @param {number} offset\n */\n integrate (transaction, offset) {\n // skip structs cannot be integrated\n error.unexpectedCase()\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeInfo(structSkipRefNumber)\n // write as VarUint because Skips can't make use of predictable length-encoding\n encoding.writeVarUint(encoder.restEncoder, this.length - offset)\n }\n\n /**\n * @param {Transaction} transaction\n * @param {StructStore} store\n * @return {null | number}\n */\n getMissing (transaction, store) {\n return null\n }\n}\n","/** eslint-env browser */\n\nexport {\n Doc,\n Transaction,\n YArray as Array,\n YMap as Map,\n YText as Text,\n YXmlText as XmlText,\n YXmlHook as XmlHook,\n YXmlElement as XmlElement,\n YXmlFragment as XmlFragment,\n YXmlEvent,\n YMapEvent,\n YArrayEvent,\n YTextEvent,\n YEvent,\n Item,\n AbstractStruct,\n GC,\n Skip,\n ContentBinary,\n ContentDeleted,\n ContentDoc,\n ContentEmbed,\n ContentFormat,\n ContentJSON,\n ContentAny,\n ContentString,\n ContentType,\n AbstractType,\n getTypeChildren,\n createRelativePositionFromTypeIndex,\n createRelativePositionFromJSON,\n createAbsolutePositionFromRelativePosition,\n compareRelativePositions,\n AbsolutePosition,\n RelativePosition,\n ID,\n createID,\n compareIDs,\n getState,\n Snapshot,\n createSnapshot,\n createDeleteSet,\n createDeleteSetFromStructStore,\n cleanupYTextFormatting,\n snapshot,\n emptySnapshot,\n findRootTypeKey,\n findIndexSS,\n getItem,\n getItemCleanStart,\n getItemCleanEnd,\n typeListToArraySnapshot,\n typeMapGetSnapshot,\n typeMapGetAllSnapshot,\n createDocFromSnapshot,\n iterateDeletedStructs,\n applyUpdate,\n applyUpdateV2,\n readUpdate,\n readUpdateV2,\n encodeStateAsUpdate,\n encodeStateAsUpdateV2,\n encodeStateVector,\n UndoManager,\n decodeSnapshot,\n encodeSnapshot,\n decodeSnapshotV2,\n encodeSnapshotV2,\n decodeStateVector,\n logUpdate,\n logUpdateV2,\n decodeUpdate,\n decodeUpdateV2,\n relativePositionToJSON,\n isDeleted,\n isParentOf,\n equalSnapshots,\n PermanentUserData, // @TODO experimental\n tryGc,\n transact,\n AbstractConnector,\n logType,\n mergeUpdates,\n mergeUpdatesV2,\n parseUpdateMeta,\n parseUpdateMetaV2,\n encodeStateVectorFromUpdate,\n encodeStateVectorFromUpdateV2,\n encodeRelativePosition,\n decodeRelativePosition,\n diffUpdate,\n diffUpdateV2,\n convertUpdateFormatV1ToV2,\n convertUpdateFormatV2ToV1,\n obfuscateUpdate,\n obfuscateUpdateV2,\n UpdateEncoderV1,\n UpdateEncoderV2,\n UpdateDecoderV1,\n UpdateDecoderV2,\n equalDeleteSets,\n mergeDeleteSets,\n snapshotContainsUpdate\n} from './internals.js'\n\nconst glo = /** @type {any} */ (typeof globalThis !== 'undefined'\n ? globalThis\n : typeof window !== 'undefined'\n ? window\n // @ts-ignore\n : typeof global !== 'undefined' ? global : {})\n\nconst importIdentifier = '__ $YJS$ __'\n\nif (glo[importIdentifier] === true) {\n /**\n * Dear reader of this message. Please take this seriously.\n *\n * If you see this message, make sure that you only import one version of Yjs. In many cases,\n * your package manager installs two versions of Yjs that are used by different packages within your project.\n * Another reason for this message is that some parts of your project use the commonjs version of Yjs\n * and others use the EcmaScript version of Yjs.\n *\n * This often leads to issues that are hard to debug. We often need to perform constructor checks,\n * e.g. `struct instanceof GC`. If you imported different versions of Yjs, it is impossible for us to\n * do the constructor checks anymore - which might break the CRDT algorithm.\n *\n * https://github.com/yjs/yjs/issues/438\n */\n console.error('Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438')\n}\nglo[importIdentifier] = true\n","export const isString = (value: unknown): value is string => {\n return typeof value === \"string\";\n};\n\nexport const isMentionNodeAttributeId = (\n value: unknown\n): value is `in_${string}` => {\n return isString(value) && value.startsWith(\"in_\");\n};\n\nexport const exists = <T>(input: null | undefined | T): input is T => {\n return input !== null && input !== undefined;\n};\n","import type {\n Awaitable,\n BaseUserMeta,\n DGI,\n DU,\n ResolveGroupsInfoArgs,\n ResolveUsersArgs,\n} from \"@liveblocks/core\";\nimport { Promise_withResolvers, warnOnce } from \"@liveblocks/core\";\n\n/**\n * Utility to get the resolved result coming from a batch resolver for a given ID.\n */\nexport function getResolvedForId<T>(\n id: string,\n ids: string[],\n results: T[] | undefined\n): T | undefined {\n const index = ids.indexOf(id);\n\n return results?.[index];\n}\n\n/**\n * Batch calls to a resolver callback (which expects an array of IDs\n * and returns an array of results) into a single call.\n */\nexport class BatchResolver<T> {\n private ids = new Set<string>();\n private results = new Map<string, T | undefined>();\n private isResolved = false;\n private promise: Promise<void>;\n private resolvePromise: () => void;\n private missingCallbackWarning: string;\n private callback?: (\n ids: string[]\n ) => Awaitable<(T | undefined)[] | undefined>;\n\n constructor(\n callback:\n | ((ids: string[]) => Awaitable<(T | undefined)[] | undefined>)\n | undefined,\n missingCallbackWarning: string\n ) {\n this.callback = callback;\n\n const { promise, resolve } = Promise_withResolvers<void>();\n this.promise = promise;\n this.resolvePromise = resolve;\n this.missingCallbackWarning = missingCallbackWarning;\n }\n\n /**\n * Add IDs to the batch and return a promise that resolves when the entire batch is resolved.\n * It can't be called after the batch is resolved.\n */\n async get(ids: string[]): Promise<(T | undefined)[] | undefined> {\n if (this.isResolved) {\n throw new Error(\"Batch has already been resolved.\");\n }\n\n ids.forEach((id) => this.ids.add(id));\n\n // Wait for the batch to be resolved\n await this.promise;\n\n return ids.map((id) => this.results.get(id));\n }\n\n #resolveBatch() {\n this.isResolved = true;\n this.resolvePromise();\n }\n\n /**\n * Resolve all the IDs in the batch.\n * It can only be called once.\n */\n async resolve(): Promise<void> {\n if (this.isResolved) {\n throw new Error(\"Batch has already been resolved.\");\n }\n\n if (!this.callback) {\n // Warn about the missing callback and resolve the batch early\n warnOnce(this.missingCallbackWarning);\n this.#resolveBatch();\n\n return;\n }\n\n const ids = Array.from(this.ids);\n\n // Call the callback once with all IDs\n try {\n const results = this.callback ? await this.callback(ids) : undefined;\n\n if (results !== undefined) {\n if (!Array.isArray(results)) {\n throw new Error(\"Callback must return an array.\");\n } else if (ids.length !== results.length) {\n throw new Error(\n `Callback must return an array of the same length as the number of provided items. Expected ${ids.length}, but got ${results.length}.`\n );\n }\n }\n\n ids.forEach((id, index) => {\n this.results.set(id, results?.[index]);\n });\n } catch (error) {\n // Still mark as resolved to prevent reuse\n this.#resolveBatch();\n\n throw error;\n }\n\n this.#resolveBatch();\n }\n}\n\nexport function createBatchUsersResolver<U extends BaseUserMeta = DU>({\n resolveUsers,\n callerName,\n}: {\n resolveUsers?: (\n args: ResolveUsersArgs\n ) => Awaitable<(U[\"info\"] | undefined)[] | undefined>;\n callerName: string;\n}): BatchResolver<U[\"info\"]> {\n return new BatchResolver<U[\"info\"]>(\n resolveUsers ? (userIds) => resolveUsers({ userIds }) : undefined,\n `Set \"resolveUsers\" in \"${callerName}\" to specify users info`\n );\n}\n\nexport function createBatchGroupsInfoResolver({\n resolveGroupsInfo,\n callerName,\n}: {\n resolveGroupsInfo?: (\n args: ResolveGroupsInfoArgs\n ) => Awaitable<(DGI | undefined)[] | undefined>;\n callerName: string;\n}): BatchResolver<DGI> {\n return new BatchResolver<DGI>(\n resolveGroupsInfo\n ? (groupIds) => resolveGroupsInfo({ groupIds })\n : undefined,\n `Set \"resolveGroupsInfo\" in \"${callerName}\" to specify groups info`\n );\n}\n","import type { Properties } from \"csstype\";\n\n/**\n * CSS properties object.\n * Type alias for DX purposes.\n *\n */\nexport type CSSProperties = Properties;\n\n/**\n * Vendors\n */\nconst VENDORS_PREFIXES = new RegExp(/^(webkit|moz|ms|o)-/);\n\n/**\n * CSS properties which accept numbers but are not in units of \"px\".\n * Based on: https://github.com/facebook/react/blob/bfe91fbecf183f85fc1c4f909e12a6833a247319/packages/react-dom-bindings/src/shared/isUnitlessNumber.js\n */\nconst UNITLESS_PROPERTIES = [\n \"animationIterationCount\",\n \"aspectRatio\",\n \"borderImageOutset\",\n \"borderImageSlice\",\n \"borderImageWidth\",\n \"boxFlex\",\n \"boxFlexGroup\",\n \"boxOrdinalGroup\",\n \"columnCount\",\n \"columns\",\n \"flex\",\n \"flexGrow\",\n \"flexPositive\",\n \"flexShrink\",\n \"flexNegative\",\n \"flexOrder\",\n \"gridArea\",\n \"gridRow\",\n \"gridRowEnd\",\n \"gridRowSpan\",\n \"gridRowStart\",\n \"gridColumn\",\n \"gridColumnEnd\",\n \"gridColumnSpan\",\n \"gridColumnStart\",\n \"fontWeight\",\n \"lineClamp\",\n \"lineHeight\",\n \"opacity\",\n \"order\",\n \"orphans\",\n \"scale\",\n \"tabSize\",\n \"widows\",\n \"zIndex\",\n \"zoom\",\n \"fillOpacity\",\n \"floodOpacity\",\n \"stopOpacity\",\n \"strokeDasharray\",\n \"strokeDashoffset\",\n \"strokeMiterlimit\",\n \"strokeOpacity\",\n \"strokeWidth\",\n \"MozAnimationIterationCount\",\n \"MozBoxFlex\",\n \"MozBoxFlexGroup\",\n \"MozLineClamp\",\n \"msAnimationIterationCount\",\n \"msFlex\",\n \"msZoom\",\n \"msFlexPositive\",\n \"msGridColumns\",\n \"msGridRows\",\n \"WebkitAnimationIterationCount\",\n \"WebkitBoxFlex\",\n \"WebKitBoxFlexGroup\",\n \"WebkitBoxOrdinalGroup\",\n \"WebkitColumnCount\",\n \"WebkitColumns\",\n \"WebkitFlex\",\n \"WebkitFlexGrow\",\n \"WebkitFlexPositive\",\n \"WebkitFlexShrink\",\n \"WebkitLineClamp\",\n];\n\n/**\n * Convert a `CSSProperties` style object into a inline CSS string.\n */\nexport function toInlineCSSString(styles: CSSProperties): string {\n const entries = Object.entries(styles);\n const inline = entries\n .map(([key, value]): string | null => {\n // Return an empty string if `value` is not acceptable\n if (\n value === null ||\n typeof value === \"boolean\" ||\n value === \"\" ||\n typeof value === \"undefined\"\n ) {\n return \"\";\n }\n\n // Convert key from camelCase to kebab-case\n let property = key.replace(/([A-Z])/g, \"-$1\").toLowerCase();\n\n // Manage vendors prefixes\n if (VENDORS_PREFIXES.test(property)) {\n property = `-${property}`;\n }\n\n // Add `px` if needed for properties which aren't unitless\n if (typeof value === \"number\" && !UNITLESS_PROPERTIES.includes(key)) {\n return `${property}:${value}px;`;\n }\n\n return `${property}:${String(value).trim()};`;\n })\n .filter(Boolean)\n .join(\"\");\n\n return inline;\n}\n","import { assertNever, type MentionData } from \"@liveblocks/core\";\nimport { yXmlFragmentToProsemirrorJSON } from \"y-prosemirror\";\nimport * as Y from \"yjs\";\n\nimport { isMentionNodeAttributeId } from \"./lib/utils\";\n\nexport interface SerializedTiptapBaseNode {\n type: string;\n content?: Array<SerializedTiptapBaseNode>;\n}\n\nexport interface SerializedTiptapBaseMark {\n type: string;\n attrs: Record<string, string>;\n}\n\nexport interface SerializedTiptapBoldMark extends SerializedTiptapBaseMark {\n type: \"bold\";\n}\n\nexport interface SerializedTiptapItalicMark extends SerializedTiptapBaseMark {\n type: \"italic\";\n}\n\nexport interface SerializedTiptapStrikethroughMark\n extends SerializedTiptapBaseMark {\n type: \"strike\";\n}\n\nexport interface SerializedTiptapCodeMark extends SerializedTiptapBaseMark {\n type: \"code\";\n}\n\nexport interface SerializedTiptapCommentMark extends SerializedTiptapBaseMark {\n type: \"liveblocksCommentMark\";\n attrs: {\n threadId: string;\n };\n}\n\nexport type SerializedTiptapMark =\n | SerializedTiptapBoldMark\n | SerializedTiptapItalicMark\n | SerializedTiptapStrikethroughMark\n | SerializedTiptapCodeMark\n | SerializedTiptapCommentMark;\n\nexport type SerializedTiptapMarkType = SerializedTiptapMark[\"type\"];\n\nexport interface SerializedTiptapTextNode extends SerializedTiptapBaseNode {\n type: \"text\";\n text: string;\n marks?: Array<SerializedTiptapMark>;\n}\n\nexport interface SerializedTiptapMentionNode extends SerializedTiptapBaseNode {\n type: \"liveblocksMention\";\n attrs: {\n id: string;\n notificationId: string;\n };\n}\n\nexport interface SerializedTiptapGroupMentionNode\n extends SerializedTiptapBaseNode {\n type: \"liveblocksGroupMention\";\n attrs: {\n id: string;\n notificationId: string;\n userIds: string | undefined;\n };\n}\n\nexport interface SerializedTiptapEmptyParagraphNode\n extends SerializedTiptapBaseNode {\n type: \"paragraph\";\n content?: undefined;\n}\n\n/**\n * Hard breaks are created by using keys like\n * `shift+enter` or `mod+enter`\n */\nexport interface SerializedTiptapHardBreakNode\n extends SerializedTiptapBaseNode {\n type: \"hardBreak\";\n content?: undefined;\n}\n\nexport interface SerializedTiptapParagraphNode\n extends SerializedTiptapBaseNode {\n type: \"paragraph\";\n content: Array<SerializedTiptapNode>;\n}\n\nexport type SerializedTiptapNode =\n | SerializedTiptapParagraphNode\n | SerializedTiptapEmptyParagraphNode\n | SerializedTiptapHardBreakNode\n | SerializedTiptapMentionNode\n | SerializedTiptapGroupMentionNode\n | SerializedTiptapTextNode;\n\nexport type SerializedTiptapRootNodeContent = Array<\n Readonly<SerializedTiptapNode>\n>;\n\nexport interface SerializedTiptapRootNode\n extends Readonly<SerializedTiptapBaseNode> {\n readonly type: \"doc\";\n readonly content: SerializedTiptapRootNodeContent;\n}\n\n/**\n * Convert a document as binaries to\n * serialized tiptap state\n */\nexport function getSerializedTiptapState({\n buffer,\n key,\n}: {\n buffer: ArrayBuffer;\n key: string;\n}): SerializedTiptapRootNode {\n const update = new Uint8Array(buffer);\n // Construct a Y.js document from the binary update\n const document = new Y.Doc();\n Y.applyUpdate(document, update);\n\n // Convert the Y.js document to a serializable tiptap state\n const fragment = document.getXmlFragment(key);\n const state = yXmlFragmentToProsemirrorJSON(fragment);\n\n // Destroy the Y.js document after the conversion\n document.destroy();\n\n // Not ideal but pragmatic enough as the typing is based\n // on real data we provide\n return state as SerializedTiptapRootNode;\n}\n\nconst isSerializedEmptyParagraphNode = (\n node: SerializedTiptapNode\n): node is SerializedTiptapEmptyParagraphNode => {\n return node.type === \"paragraph\" && typeof node.content === \"undefined\";\n};\n\nconst isSerializedHardBreakNode = (\n node: SerializedTiptapNode\n): node is SerializedTiptapHardBreakNode => {\n return node.type === \"hardBreak\" && typeof node.content === \"undefined\";\n};\n\nconst isSerializedTextNode = (\n node: SerializedTiptapNode\n): node is SerializedTiptapTextNode => {\n return node.type === \"text\";\n};\n\nexport const isSerializedMentionNode = (\n node: SerializedTiptapNode\n): node is SerializedTiptapMentionNode => {\n return (\n node.type === \"liveblocksMention\" &&\n isMentionNodeAttributeId(node.attrs.notificationId)\n );\n};\n\nexport const isSerializedGroupMentionNode = (\n node: SerializedTiptapNode\n): node is SerializedTiptapGroupMentionNode => {\n return (\n node.type === \"liveblocksGroupMention\" &&\n isMentionNodeAttributeId(node.attrs.notificationId)\n );\n};\n\nconst isSerializedParagraphNode = (\n node: SerializedTiptapNode\n): node is SerializedTiptapParagraphNode => {\n return node.type === \"paragraph\" && typeof node.content !== \"undefined\";\n};\n\n/**\n * Internal type helper when flattening nodes.\n * It helps to better extract mention node with context by marking\n * start and ends of paragraph and by handling specific use cases such as\n * using twice the `enter` key which will create an empty paragraph\n * at the first `enter`:\n *\n * \"\n * Hey @charlie what's up?\n * _enter_once_\n * _enter_twice_\n * \"\n */\ninterface FlattenedTiptapParagraphNodeMarker {\n type: \"paragraph-marker\";\n marker: \"start\" | \"end\";\n}\n\nconst isFlattenedTiptapParagraphNodeMarker = (\n node: SerializedTiptapNode | FlattenedTiptapParagraphNodeMarker\n): node is FlattenedTiptapParagraphNodeMarker => {\n return node.type === \"paragraph-marker\";\n};\n\n/** @internal */\ntype FlattenedSerializedTiptapNodes = Array<\n SerializedTiptapNode | FlattenedTiptapParagraphNodeMarker\n>;\n\n/** @internal - export for testing only */\nexport const flattenTiptapTree = (\n nodes: SerializedTiptapNode[]\n): FlattenedSerializedTiptapNodes => {\n let flattenNodes: FlattenedSerializedTiptapNodes = [];\n\n for (const node of nodes) {\n if (\n isSerializedEmptyParagraphNode(node) ||\n isSerializedHardBreakNode(node) ||\n isSerializedTextNode(node) ||\n isSerializedMentionNode(node) ||\n isSerializedGroupMentionNode(node)\n ) {\n flattenNodes = [...flattenNodes, node];\n } else if (isSerializedParagraphNode(node)) {\n flattenNodes = [\n ...flattenNodes,\n {\n type: \"paragraph-marker\",\n marker: \"start\",\n },\n ...flattenTiptapTree(node.content),\n {\n type: \"paragraph-marker\",\n marker: \"end\",\n },\n ];\n }\n }\n\n return flattenNodes;\n};\n\n/**\n * Tiptap Mention Node with context\n */\nexport type TiptapMentionNodeWithContext = {\n before: SerializedTiptapNode[];\n after: SerializedTiptapNode[];\n mention: SerializedTiptapMentionNode | SerializedTiptapGroupMentionNode;\n};\n\n/**\n * Find a Tiptap mention\n * and returns it with contextual surrounding text\n */\nexport function findTiptapMentionNodeWithContext({\n root,\n textMentionId,\n}: {\n root: SerializedTiptapRootNode;\n textMentionId: string;\n}): TiptapMentionNodeWithContext | null {\n const nodes = flattenTiptapTree(root.content);\n\n // Find mention node\n let mentionNodeIndex = -1;\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i]!;\n\n if (\n !isFlattenedTiptapParagraphNodeMarker(node) &&\n (isSerializedMentionNode(node) || isSerializedGroupMentionNode(node)) &&\n node.attrs.notificationId === textMentionId\n ) {\n mentionNodeIndex = i;\n break;\n }\n }\n\n // No mention node found\n if (mentionNodeIndex === -1) {\n return null;\n }\n\n // Collect nodes before and after\n const mentionNode = nodes[mentionNodeIndex] as\n | SerializedTiptapMentionNode\n | SerializedTiptapGroupMentionNode;\n\n // Apply surrounding text guesses\n // For now let's stay simple just stop at nearest line break or paragraph\n const beforeNodes: SerializedTiptapNode[] = [];\n const afterNodes: SerializedTiptapNode[] = [];\n\n // Nodes before mention node\n for (let i = mentionNodeIndex - 1; i >= 0; i--) {\n const node = nodes[i]!;\n\n // Stop if nodes are markers, hard breaks or empty paragraph\n if (\n isFlattenedTiptapParagraphNodeMarker(node) ||\n isSerializedEmptyParagraphNode(node) ||\n isSerializedHardBreakNode(node)\n ) {\n break;\n }\n\n beforeNodes.unshift(node);\n }\n\n // Nodes after mention node\n for (let i = mentionNodeIndex + 1; i < nodes.length; i++) {\n const node = nodes[i]!;\n\n // Stop if nodes are markers, hard breaks or empty paragraph\n if (\n isFlattenedTiptapParagraphNodeMarker(node) ||\n isSerializedEmptyParagraphNode(node) ||\n isSerializedHardBreakNode(node)\n ) {\n break;\n }\n\n afterNodes.push(node);\n }\n\n return {\n before: beforeNodes,\n after: afterNodes,\n mention: mentionNode,\n };\n}\n\nfunction deserializeGroupUserIds(\n userIds: string | undefined\n): string[] | undefined {\n if (typeof userIds !== \"string\") {\n return undefined;\n }\n\n try {\n const parsedUserIds = JSON.parse(userIds) as string[];\n\n if (Array.isArray(parsedUserIds)) {\n return parsedUserIds;\n }\n\n return undefined;\n } catch {\n return undefined;\n }\n}\n\nexport function getMentionDataFromTiptapNode(\n node: SerializedTiptapMentionNode | SerializedTiptapGroupMentionNode\n): MentionData {\n if (isSerializedMentionNode(node)) {\n return {\n kind: \"user\",\n id: node.attrs.id,\n };\n } else if (isSerializedGroupMentionNode(node)) {\n return {\n kind: \"group\",\n id: node.attrs.id,\n userIds: deserializeGroupUserIds(node.attrs.userIds),\n };\n }\n\n assertNever(node, \"Unknown mention kind\");\n}\n","/**\n * @module bindings/prosemirror\n */\n\nimport { createMutex } from 'lib0/mutex'\nimport * as PModel from 'prosemirror-model'\nimport { AllSelection, Plugin, TextSelection, NodeSelection } from \"prosemirror-state\"; // eslint-disable-line\nimport * as math from 'lib0/math'\nimport * as object from 'lib0/object'\nimport * as set from 'lib0/set'\nimport { simpleDiff } from 'lib0/diff'\nimport * as error from 'lib0/error'\nimport { ySyncPluginKey, yUndoPluginKey } from './keys.js'\nimport * as Y from 'yjs'\nimport {\n absolutePositionToRelativePosition,\n relativePositionToAbsolutePosition\n} from '../lib.js'\nimport * as random from 'lib0/random'\nimport * as environment from 'lib0/environment'\nimport * as dom from 'lib0/dom'\nimport * as eventloop from 'lib0/eventloop'\nimport * as map from 'lib0/map'\nimport * as utils from '../utils.js'\n\n/**\n * @typedef {Object} BindingMetadata\n * @property {ProsemirrorMapping} BindingMetadata.mapping\n * @property {Map<import('prosemirror-model').MarkType, boolean>} BindingMetadata.isOMark - is overlapping mark\n */\n\n/**\n * @return {BindingMetadata}\n */\nexport const createEmptyMeta = () => ({\n mapping: new Map(),\n isOMark: new Map()\n})\n\n/**\n * @param {Y.Item} item\n * @param {Y.Snapshot} [snapshot]\n */\nexport const isVisible = (item, snapshot) =>\n snapshot === undefined\n ? !item.deleted\n : (snapshot.sv.has(item.id.client) && /** @type {number} */\n (snapshot.sv.get(item.id.client)) > item.id.clock &&\n !Y.isDeleted(snapshot.ds, item.id))\n\n/**\n * Either a node if type is YXmlElement or an Array of text nodes if YXmlText\n * @typedef {Map<Y.AbstractType<any>, PModel.Node | Array<PModel.Node>>} ProsemirrorMapping\n */\n\n/**\n * @typedef {Object} ColorDef\n * @property {string} ColorDef.light\n * @property {string} ColorDef.dark\n */\n\n/**\n * @typedef {Object} YSyncOpts\n * @property {Array<ColorDef>} [YSyncOpts.colors]\n * @property {Map<string,ColorDef>} [YSyncOpts.colorMapping]\n * @property {Y.PermanentUserData|null} [YSyncOpts.permanentUserData]\n * @property {ProsemirrorMapping} [YSyncOpts.mapping]\n * @property {function} [YSyncOpts.onFirstRender] Fired when the content from Yjs is initially rendered to ProseMirror\n */\n\n/**\n * @type {Array<ColorDef>}\n */\nconst defaultColors = [{ light: '#ecd44433', dark: '#ecd444' }]\n\n/**\n * @param {Map<string,ColorDef>} colorMapping\n * @param {Array<ColorDef>} colors\n * @param {string} user\n * @return {ColorDef}\n */\nconst getUserColor = (colorMapping, colors, user) => {\n // @todo do not hit the same color twice if possible\n if (!colorMapping.has(user)) {\n if (colorMapping.size < colors.length) {\n const usedColors = set.create()\n colorMapping.forEach((color) => usedColors.add(color))\n colors = colors.filter((color) => !usedColors.has(color))\n }\n colorMapping.set(user, random.oneOf(colors))\n }\n return /** @type {ColorDef} */ (colorMapping.get(user))\n}\n\n/**\n * This plugin listens to changes in prosemirror view and keeps yXmlState and view in sync.\n *\n * This plugin also keeps references to the type and the shared document so other plugins can access it.\n * @param {Y.XmlFragment} yXmlFragment\n * @param {YSyncOpts} opts\n * @return {any} Returns a prosemirror plugin that binds to this type\n */\nexport const ySyncPlugin = (yXmlFragment, {\n colors = defaultColors,\n colorMapping = new Map(),\n permanentUserData = null,\n onFirstRender = () => {},\n mapping\n} = {}) => {\n let initialContentChanged = false\n const binding = new ProsemirrorBinding(yXmlFragment, mapping)\n const plugin = new Plugin({\n props: {\n editable: (state) => {\n const syncState = ySyncPluginKey.getState(state)\n return syncState.snapshot == null && syncState.prevSnapshot == null\n }\n },\n key: ySyncPluginKey,\n state: {\n /**\n * @returns {any}\n */\n init: (_initargs, _state) => {\n return {\n type: yXmlFragment,\n doc: yXmlFragment.doc,\n binding,\n snapshot: null,\n prevSnapshot: null,\n isChangeOrigin: false,\n isUndoRedoOperation: false,\n addToHistory: true,\n colors,\n colorMapping,\n permanentUserData\n }\n },\n apply: (tr, pluginState) => {\n const change = tr.getMeta(ySyncPluginKey)\n if (change !== undefined) {\n pluginState = Object.assign({}, pluginState)\n for (const key in change) {\n pluginState[key] = change[key]\n }\n }\n pluginState.addToHistory = tr.getMeta('addToHistory') !== false\n // always set isChangeOrigin. If undefined, this is not change origin.\n pluginState.isChangeOrigin = change !== undefined &&\n !!change.isChangeOrigin\n pluginState.isUndoRedoOperation = change !== undefined && !!change.isChangeOrigin && !!change.isUndoRedoOperation\n if (binding.prosemirrorView !== null) {\n if (\n change !== undefined &&\n (change.snapshot != null || change.prevSnapshot != null)\n ) {\n // snapshot changed, rerender next\n eventloop.timeout(0, () => {\n if (binding.prosemirrorView == null) {\n return\n }\n if (change.restore == null) {\n binding._renderSnapshot(\n change.snapshot,\n change.prevSnapshot,\n pluginState\n )\n } else {\n binding._renderSnapshot(\n change.snapshot,\n change.snapshot,\n pluginState\n )\n // reset to current prosemirror state\n delete pluginState.restore\n delete pluginState.snapshot\n delete pluginState.prevSnapshot\n binding.mux(() => {\n binding._prosemirrorChanged(\n binding.prosemirrorView.state.doc\n )\n })\n }\n })\n }\n }\n return pluginState\n }\n },\n view: (view) => {\n binding.initView(view)\n if (mapping == null) {\n // force rerender to update the bindings mapping\n binding._forceRerender()\n }\n onFirstRender()\n return {\n update: () => {\n const pluginState = plugin.getState(view.state)\n if (\n pluginState.snapshot == null && pluginState.prevSnapshot == null\n ) {\n if (\n // If the content doesn't change initially, we don't render anything to Yjs\n // If the content was cleared by a user action, we want to catch the change and\n // represent it in Yjs\n initialContentChanged ||\n view.state.doc.content.findDiffStart(\n view.state.doc.type.createAndFill().content\n ) !== null\n ) {\n initialContentChanged = true\n if (\n pluginState.addToHistory === false &&\n !pluginState.isChangeOrigin\n ) {\n const yUndoPluginState = yUndoPluginKey.getState(view.state)\n /**\n * @type {Y.UndoManager}\n */\n const um = yUndoPluginState && yUndoPluginState.undoManager\n if (um) {\n um.stopCapturing()\n }\n }\n binding.mux(() => {\n /** @type {Y.Doc} */ (pluginState.doc).transact((tr) => {\n tr.meta.set('addToHistory', pluginState.addToHistory)\n binding._prosemirrorChanged(view.state.doc)\n }, ySyncPluginKey)\n })\n }\n }\n },\n destroy: () => {\n binding.destroy()\n }\n }\n }\n })\n return plugin\n}\n\n/**\n * @param {import('prosemirror-state').Transaction} tr\n * @param {ReturnType<typeof getRelativeSelection>} relSel\n * @param {ProsemirrorBinding} binding\n */\nconst restoreRelativeSelection = (tr, relSel, binding) => {\n if (relSel !== null && relSel.anchor !== null && relSel.head !== null) {\n if (relSel.type === 'all') {\n tr.setSelection(new AllSelection(tr.doc))\n } else if (relSel.type === 'node') {\n const anchor = relativePositionToAbsolutePosition(\n binding.doc,\n binding.type,\n relSel.anchor,\n binding.mapping\n )\n tr.setSelection(NodeSelection.create(tr.doc, anchor))\n } else {\n const anchor = relativePositionToAbsolutePosition(\n binding.doc,\n binding.type,\n relSel.anchor,\n binding.mapping\n )\n const head = relativePositionToAbsolutePosition(\n binding.doc,\n binding.type,\n relSel.head,\n binding.mapping\n )\n if (anchor !== null && head !== null) {\n const sel = TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head))\n tr.setSelection(sel)\n }\n }\n }\n}\n\n/**\n * @param {ProsemirrorBinding} pmbinding\n * @param {import('prosemirror-state').EditorState} state\n */\nexport const getRelativeSelection = (pmbinding, state) => ({\n type: /** @type {any} */ (state.selection).jsonID,\n anchor: absolutePositionToRelativePosition(\n state.selection.anchor,\n pmbinding.type,\n pmbinding.mapping\n ),\n head: absolutePositionToRelativePosition(\n state.selection.head,\n pmbinding.type,\n pmbinding.mapping\n )\n})\n\n/**\n * Binding for prosemirror.\n *\n * @protected\n */\nexport class ProsemirrorBinding {\n /**\n * @param {Y.XmlFragment} yXmlFragment The bind source\n * @param {ProsemirrorMapping} mapping\n */\n constructor (yXmlFragment, mapping = new Map()) {\n this.type = yXmlFragment\n /**\n * this will be set once the view is created\n * @type {any}\n */\n this.prosemirrorView = null\n this.mux = createMutex()\n this.mapping = mapping\n /**\n * Is overlapping mark - i.e. mark does not exclude itself.\n *\n * @type {Map<import('prosemirror-model').MarkType, boolean>}\n */\n this.isOMark = new Map()\n this._observeFunction = this._typeChanged.bind(this)\n /**\n * @type {Y.Doc}\n */\n // @ts-ignore\n this.doc = yXmlFragment.doc\n /**\n * current selection as relative positions in the Yjs model\n */\n this.beforeTransactionSelection = null\n this.beforeAllTransactions = () => {\n if (this.beforeTransactionSelection === null && this.prosemirrorView != null) {\n this.beforeTransactionSelection = getRelativeSelection(\n this,\n this.prosemirrorView.state\n )\n }\n }\n this.afterAllTransactions = () => {\n this.beforeTransactionSelection = null\n }\n this._domSelectionInView = null\n }\n\n /**\n * Create a transaction for changing the prosemirror state.\n *\n * @returns\n */\n get _tr () {\n return this.prosemirrorView.state.tr.setMeta('addToHistory', false)\n }\n\n _isLocalCursorInView () {\n if (!this.prosemirrorView.hasFocus()) return false\n if (environment.isBrowser && this._domSelectionInView === null) {\n // Calculate the domSelectionInView and clear by next tick after all events are finished\n eventloop.timeout(0, () => {\n this._domSelectionInView = null\n })\n this._domSelectionInView = this._isDomSelectionInView()\n }\n return this._domSelectionInView\n }\n\n _isDomSelectionInView () {\n const selection = this.prosemirrorView._root.getSelection()\n\n if (selection == null || selection.anchorNode == null) return false\n\n const range = this.prosemirrorView._root.createRange()\n range.setStart(selection.anchorNode, selection.anchorOffset)\n range.setEnd(selection.focusNode, selection.focusOffset)\n\n // This is a workaround for an edgecase where getBoundingClientRect will\n // return zero values if the selection is collapsed at the start of a newline\n // see reference here: https://stackoverflow.com/a/59780954\n const rects = range.getClientRects()\n if (rects.length === 0) {\n // probably buggy newline behavior, explicitly select the node contents\n if (range.startContainer && range.collapsed) {\n range.selectNodeContents(range.startContainer)\n }\n }\n\n const bounding = range.getBoundingClientRect()\n const documentElement = dom.doc.documentElement\n\n return bounding.bottom >= 0 && bounding.right >= 0 &&\n bounding.left <=\n (window.innerWidth || documentElement.clientWidth || 0) &&\n bounding.top <= (window.innerHeight || documentElement.clientHeight || 0)\n }\n\n /**\n * @param {Y.Snapshot} snapshot\n * @param {Y.Snapshot} prevSnapshot\n */\n renderSnapshot (snapshot, prevSnapshot) {\n if (!prevSnapshot) {\n prevSnapshot = Y.createSnapshot(Y.createDeleteSet(), new Map())\n }\n this.prosemirrorView.dispatch(\n this._tr.setMeta(ySyncPluginKey, { snapshot, prevSnapshot })\n )\n }\n\n unrenderSnapshot () {\n this.mapping.clear()\n this.mux(() => {\n const fragmentContent = this.type.toArray().map((t) =>\n createNodeFromYElement(\n /** @type {Y.XmlElement} */ (t),\n this.prosemirrorView.state.schema,\n this\n )\n ).filter((n) => n !== null)\n // @ts-ignore\n const tr = this._tr.replace(\n 0,\n this.prosemirrorView.state.doc.content.size,\n new PModel.Slice(PModel.Fragment.from(fragmentContent), 0, 0)\n )\n tr.setMeta(ySyncPluginKey, { snapshot: null, prevSnapshot: null })\n this.prosemirrorView.dispatch(tr)\n })\n }\n\n _forceRerender () {\n this.mapping.clear()\n this.mux(() => {\n // If this is a forced rerender, this might neither happen as a pm change nor within a Yjs\n // transaction. Then the \"before selection\" doesn't exist. In this case, we need to create a\n // relative position before replacing content. Fixes #126\n const sel = this.beforeTransactionSelection !== null ? null : this.prosemirrorView.state.selection\n const fragmentContent = this.type.toArray().map((t) =>\n createNodeFromYElement(\n /** @type {Y.XmlElement} */ (t),\n this.prosemirrorView.state.schema,\n this\n )\n ).filter((n) => n !== null)\n // @ts-ignore\n const tr = this._tr.replace(\n 0,\n this.prosemirrorView.state.doc.content.size,\n new PModel.Slice(PModel.Fragment.from(fragmentContent), 0, 0)\n )\n if (sel) {\n /**\n * If the Prosemirror document we just created from this.type is\n * smaller than the previous document, the selection might be\n * out of bound, which would make Prosemirror throw an error.\n */\n const clampedAnchor = math.min(math.max(sel.anchor, 0), tr.doc.content.size)\n const clampedHead = math.min(math.max(sel.head, 0), tr.doc.content.size)\n\n tr.setSelection(TextSelection.create(tr.doc, clampedAnchor, clampedHead))\n }\n this.prosemirrorView.dispatch(\n tr.setMeta(ySyncPluginKey, { isChangeOrigin: true, binding: this })\n )\n })\n }\n\n /**\n * @param {Y.Snapshot|Uint8Array} snapshot\n * @param {Y.Snapshot|Uint8Array} prevSnapshot\n * @param {Object} pluginState\n */\n _renderSnapshot (snapshot, prevSnapshot, pluginState) {\n /**\n * The document that contains the full history of this document.\n * @type {Y.Doc}\n */\n let historyDoc = this.doc\n let historyType = this.type\n if (!snapshot) {\n snapshot = Y.snapshot(this.doc)\n }\n if (snapshot instanceof Uint8Array || prevSnapshot instanceof Uint8Array) {\n if (!(snapshot instanceof Uint8Array) || !(prevSnapshot instanceof Uint8Array)) {\n // expected both snapshots to be v2 updates\n error.unexpectedCase()\n }\n historyDoc = new Y.Doc({ gc: false })\n Y.applyUpdateV2(historyDoc, prevSnapshot)\n prevSnapshot = Y.snapshot(historyDoc)\n Y.applyUpdateV2(historyDoc, snapshot)\n snapshot = Y.snapshot(historyDoc)\n if (historyType._item === null) {\n /**\n * If is a root type, we need to find the root key in the initial document\n * and use it to get the history type.\n */\n const rootKey = Array.from(this.doc.share.keys()).find(\n (key) => this.doc.share.get(key) === this.type\n )\n historyType = historyDoc.getXmlFragment(rootKey)\n } else {\n /**\n * If it is a sub type, we use the item id to find the history type.\n */\n const historyStructs =\n historyDoc.store.clients.get(historyType._item.id.client) ?? []\n const itemIndex = Y.findIndexSS(\n historyStructs,\n historyType._item.id.clock\n )\n const item = /** @type {Y.Item} */ (historyStructs[itemIndex])\n const content = /** @type {Y.ContentType} */ (item.content)\n historyType = /** @type {Y.XmlFragment} */ (content.type)\n }\n }\n // clear mapping because we are going to rerender\n this.mapping.clear()\n this.mux(() => {\n historyDoc.transact((transaction) => {\n // before rendering, we are going to sanitize ops and split deleted ops\n // if they were deleted by seperate users.\n /**\n * @type {Y.PermanentUserData}\n */\n const pud = pluginState.permanentUserData\n if (pud) {\n pud.dss.forEach((ds) => {\n Y.iterateDeletedStructs(transaction, ds, (_item) => {})\n })\n }\n /**\n * @param {'removed'|'added'} type\n * @param {Y.ID} id\n */\n const computeYChange = (type, id) => {\n const user = type === 'added'\n ? pud.getUserByClientId(id.client)\n : pud.getUserByDeletedId(id)\n return {\n user,\n type,\n color: getUserColor(\n pluginState.colorMapping,\n pluginState.colors,\n user\n )\n }\n }\n // Create document fragment and render\n const fragmentContent = Y.typeListToArraySnapshot(\n historyType,\n new Y.Snapshot(prevSnapshot.ds, snapshot.sv)\n ).map((t) => {\n if (\n !t._item.deleted || isVisible(t._item, snapshot) ||\n isVisible(t._item, prevSnapshot)\n ) {\n return createNodeFromYElement(\n t,\n this.prosemirrorView.state.schema,\n { mapping: new Map(), isOMark: new Map() },\n snapshot,\n prevSnapshot,\n computeYChange\n )\n } else {\n // No need to render elements that are not visible by either snapshot.\n // If a client adds and deletes content in the same snapshot the element is not visible by either snapshot.\n return null\n }\n }).filter((n) => n !== null)\n // @ts-ignore\n const tr = this._tr.replace(\n 0,\n this.prosemirrorView.state.doc.content.size,\n new PModel.Slice(PModel.Fragment.from(fragmentContent), 0, 0)\n )\n this.prosemirrorView.dispatch(\n tr.setMeta(ySyncPluginKey, { isChangeOrigin: true })\n )\n }, ySyncPluginKey)\n })\n }\n\n /**\n * @param {Array<Y.YEvent<any>>} events\n * @param {Y.Transaction} transaction\n */\n _typeChanged (events, transaction) {\n if (this.prosemirrorView == null) return\n const syncState = ySyncPluginKey.getState(this.prosemirrorView.state)\n if (\n events.length === 0 || syncState.snapshot != null ||\n syncState.prevSnapshot != null\n ) {\n // drop out if snapshot is active\n this.renderSnapshot(syncState.snapshot, syncState.prevSnapshot)\n return\n }\n this.mux(() => {\n /**\n * @param {any} _\n * @param {Y.AbstractType<any>} type\n */\n const delType = (_, type) => this.mapping.delete(type)\n Y.iterateDeletedStructs(\n transaction,\n transaction.deleteSet,\n (struct) => {\n if (struct.constructor === Y.Item) {\n const type = /** @type {Y.ContentType} */ (/** @type {Y.Item} */ (struct).content).type\n type && this.mapping.delete(type)\n }\n }\n )\n transaction.changed.forEach(delType)\n transaction.changedParentTypes.forEach(delType)\n const fragmentContent = this.type.toArray().map((t) =>\n createNodeIfNotExists(\n /** @type {Y.XmlElement | Y.XmlHook} */ (t),\n this.prosemirrorView.state.schema,\n this\n )\n ).filter((n) => n !== null)\n // @ts-ignore\n let tr = this._tr.replace(\n 0,\n this.prosemirrorView.state.doc.content.size,\n new PModel.Slice(PModel.Fragment.from(fragmentContent), 0, 0)\n )\n restoreRelativeSelection(tr, this.beforeTransactionSelection, this)\n tr = tr.setMeta(ySyncPluginKey, { isChangeOrigin: true, isUndoRedoOperation: transaction.origin instanceof Y.UndoManager })\n if (\n this.beforeTransactionSelection !== null && this._isLocalCursorInView()\n ) {\n tr.scrollIntoView()\n }\n this.prosemirrorView.dispatch(tr)\n })\n }\n\n /**\n * @param {import('prosemirror-model').Node} doc\n */\n _prosemirrorChanged (doc) {\n this.doc.transact(() => {\n updateYFragment(this.doc, this.type, doc, this)\n this.beforeTransactionSelection = getRelativeSelection(\n this,\n this.prosemirrorView.state\n )\n }, ySyncPluginKey)\n }\n\n /**\n * View is ready to listen to changes. Register observers.\n * @param {any} prosemirrorView\n */\n initView (prosemirrorView) {\n if (this.prosemirrorView != null) this.destroy()\n this.prosemirrorView = prosemirrorView\n this.doc.on('beforeAllTransactions', this.beforeAllTransactions)\n this.doc.on('afterAllTransactions', this.afterAllTransactions)\n this.type.observeDeep(this._observeFunction)\n }\n\n destroy () {\n if (this.prosemirrorView == null) return\n this.prosemirrorView = null\n this.type.unobserveDeep(this._observeFunction)\n this.doc.off('beforeAllTransactions', this.beforeAllTransactions)\n this.doc.off('afterAllTransactions', this.afterAllTransactions)\n }\n}\n\n/**\n * @private\n * @param {Y.XmlElement | Y.XmlHook} el\n * @param {PModel.Schema} schema\n * @param {BindingMetadata} meta\n * @param {Y.Snapshot} [snapshot]\n * @param {Y.Snapshot} [prevSnapshot]\n * @param {function('removed' | 'added', Y.ID):any} [computeYChange]\n * @return {PModel.Node | null}\n */\nconst createNodeIfNotExists = (\n el,\n schema,\n meta,\n snapshot,\n prevSnapshot,\n computeYChange\n) => {\n const node = /** @type {PModel.Node} */ (meta.mapping.get(el))\n if (node === undefined) {\n if (el instanceof Y.XmlElement) {\n return createNodeFromYElement(\n el,\n schema,\n meta,\n snapshot,\n prevSnapshot,\n computeYChange\n )\n } else {\n throw error.methodUnimplemented() // we are currently not handling hooks\n }\n }\n return node\n}\n\n/**\n * @private\n * @param {Y.XmlElement} el\n * @param {any} schema\n * @param {BindingMetadata} meta\n * @param {Y.Snapshot} [snapshot]\n * @param {Y.Snapshot} [prevSnapshot]\n * @param {function('removed' | 'added', Y.ID):any} [computeYChange]\n * @return {PModel.Node | null} Returns node if node could be created. Otherwise it deletes the yjs type and returns null\n */\nexport const createNodeFromYElement = (\n el,\n schema,\n meta,\n snapshot,\n prevSnapshot,\n computeYChange\n) => {\n const children = []\n /**\n * @param {Y.XmlElement | Y.XmlText} type\n */\n const createChildren = (type) => {\n if (type instanceof Y.XmlElement) {\n const n = createNodeIfNotExists(\n type,\n schema,\n meta,\n snapshot,\n prevSnapshot,\n computeYChange\n )\n if (n !== null) {\n children.push(n)\n }\n } else {\n // If the next ytext exists and was created by us, move the content to the current ytext.\n // This is a fix for #160 -- duplication of characters when two Y.Text exist next to each\n // other.\n const nextytext = /** @type {Y.ContentType} */ (type._item.right?.content)?.type\n if (nextytext instanceof Y.Text && !nextytext._item.deleted && nextytext._item.id.client === nextytext.doc.clientID) {\n type.applyDelta([\n { retain: type.length },\n ...nextytext.toDelta()\n ])\n nextytext.doc.transact(tr => {\n nextytext._item.delete(tr)\n })\n }\n // now create the prosemirror text nodes\n const ns = createTextNodesFromYText(\n type,\n schema,\n meta,\n snapshot,\n prevSnapshot,\n computeYChange\n )\n if (ns !== null) {\n ns.forEach((textchild) => {\n if (textchild !== null) {\n children.push(textchild)\n }\n })\n }\n }\n }\n if (snapshot === undefined || prevSnapshot === undefined) {\n el.toArray().forEach(createChildren)\n } else {\n Y.typeListToArraySnapshot(el, new Y.Snapshot(prevSnapshot.ds, snapshot.sv))\n .forEach(createChildren)\n }\n try {\n const attrs = el.getAttributes(snapshot)\n if (snapshot !== undefined) {\n if (!isVisible(/** @type {Y.Item} */ (el._item), snapshot)) {\n attrs.ychange = computeYChange\n ? computeYChange('removed', /** @type {Y.Item} */ (el._item).id)\n : { type: 'removed' }\n } else if (!isVisible(/** @type {Y.Item} */ (el._item), prevSnapshot)) {\n attrs.ychange = computeYChange\n ? computeYChange('added', /** @type {Y.Item} */ (el._item).id)\n : { type: 'added' }\n }\n }\n const node = schema.node(el.nodeName, attrs, children)\n meta.mapping.set(el, node)\n return node\n } catch (e) {\n // an error occured while creating the node. This is probably a result of a concurrent action.\n /** @type {Y.Doc} */ (el.doc).transact((transaction) => {\n /** @type {Y.Item} */ (el._item).delete(transaction)\n }, ySyncPluginKey)\n meta.mapping.delete(el)\n return null\n }\n}\n\n/**\n * @private\n * @param {Y.XmlText} text\n * @param {import('prosemirror-model').Schema} schema\n * @param {BindingMetadata} _meta\n * @param {Y.Snapshot} [snapshot]\n * @param {Y.Snapshot} [prevSnapshot]\n * @param {function('removed' | 'added', Y.ID):any} [computeYChange]\n * @return {Array<PModel.Node>|null}\n */\nconst createTextNodesFromYText = (\n text,\n schema,\n _meta,\n snapshot,\n prevSnapshot,\n computeYChange\n) => {\n const nodes = []\n const deltas = text.toDelta(snapshot, prevSnapshot, computeYChange)\n try {\n for (let i = 0; i < deltas.length; i++) {\n const delta = deltas[i]\n nodes.push(schema.text(delta.insert, attributesToMarks(delta.attributes, schema)))\n }\n } catch (e) {\n // an error occured while creating the node. This is probably a result of a concurrent action.\n /** @type {Y.Doc} */ (text.doc).transact((transaction) => {\n /** @type {Y.Item} */ (text._item).delete(transaction)\n }, ySyncPluginKey)\n return null\n }\n // @ts-ignore\n return nodes\n}\n\n/**\n * @private\n * @param {Array<any>} nodes prosemirror node\n * @param {BindingMetadata} meta\n * @return {Y.XmlText}\n */\nconst createTypeFromTextNodes = (nodes, meta) => {\n const type = new Y.XmlText()\n const delta = nodes.map((node) => ({\n // @ts-ignore\n insert: node.text,\n attributes: marksToAttributes(node.marks, meta)\n }))\n type.applyDelta(delta)\n meta.mapping.set(type, nodes)\n return type\n}\n\n/**\n * @private\n * @param {any} node prosemirror node\n * @param {BindingMetadata} meta\n * @return {Y.XmlElement}\n */\nconst createTypeFromElementNode = (node, meta) => {\n const type = new Y.XmlElement(node.type.name)\n for (const key in node.attrs) {\n const val = node.attrs[key]\n if (val !== null && key !== 'ychange') {\n type.setAttribute(key, val)\n }\n }\n type.insert(\n 0,\n normalizePNodeContent(node).map((n) =>\n createTypeFromTextOrElementNode(n, meta)\n )\n )\n meta.mapping.set(type, node)\n return type\n}\n\n/**\n * @private\n * @param {PModel.Node|Array<PModel.Node>} node prosemirror text node\n * @param {BindingMetadata} meta\n * @return {Y.XmlElement|Y.XmlText}\n */\nconst createTypeFromTextOrElementNode = (node, meta) =>\n node instanceof Array\n ? createTypeFromTextNodes(node, meta)\n : createTypeFromElementNode(node, meta)\n\n/**\n * @param {any} val\n */\nconst isObject = (val) => typeof val === 'object' && val !== null\n\n/**\n * @param {any} pattrs\n * @param {any} yattrs\n */\nconst equalAttrs = (pattrs, yattrs) => {\n const keys = Object.keys(pattrs).filter((key) => pattrs[key] !== null)\n let eq =\n keys.length ===\n (yattrs == null ? 0 : Object.keys(yattrs).filter((key) => yattrs[key] !== null).length)\n for (let i = 0; i < keys.length && eq; i++) {\n const key = keys[i]\n const l = pattrs[key]\n const r = yattrs[key]\n eq = key === 'ychange' || l === r ||\n (isObject(l) && isObject(r) && equalAttrs(l, r))\n }\n return eq\n}\n\n/**\n * @typedef {Array<Array<PModel.Node>|PModel.Node>} NormalizedPNodeContent\n */\n\n/**\n * @param {any} pnode\n * @return {NormalizedPNodeContent}\n */\nconst normalizePNodeContent = (pnode) => {\n const c = pnode.content.content\n const res = []\n for (let i = 0; i < c.length; i++) {\n const n = c[i]\n if (n.isText) {\n const textNodes = []\n for (let tnode = c[i]; i < c.length && tnode.isText; tnode = c[++i]) {\n textNodes.push(tnode)\n }\n i--\n res.push(textNodes)\n } else {\n res.push(n)\n }\n }\n return res\n}\n\n/**\n * @param {Y.XmlText} ytext\n * @param {Array<any>} ptexts\n */\nconst equalYTextPText = (ytext, ptexts) => {\n const delta = ytext.toDelta()\n return delta.length === ptexts.length &&\n delta.every(/** @type {(d:any,i:number) => boolean} */ (d, i) =>\n d.insert === /** @type {any} */ (ptexts[i]).text &&\n object.keys(d.attributes || {}).length === ptexts[i].marks.length &&\n object.every(d.attributes, (attr, yattrname) => {\n const markname = yattr2markname(yattrname)\n const pmarks = ptexts[i].marks\n return equalAttrs(attr, pmarks.find(/** @param {any} mark */ mark => mark.type.name === markname)?.attrs)\n })\n )\n}\n\n/**\n * @param {Y.XmlElement|Y.XmlText|Y.XmlHook} ytype\n * @param {any|Array<any>} pnode\n */\nconst equalYTypePNode = (ytype, pnode) => {\n if (\n ytype instanceof Y.XmlElement && !(pnode instanceof Array) &&\n matchNodeName(ytype, pnode)\n ) {\n const normalizedContent = normalizePNodeContent(pnode)\n return ytype._length === normalizedContent.length &&\n equalAttrs(ytype.getAttributes(), pnode.attrs) &&\n ytype.toArray().every((ychild, i) =>\n equalYTypePNode(ychild, normalizedContent[i])\n )\n }\n return ytype instanceof Y.XmlText && pnode instanceof Array &&\n equalYTextPText(ytype, pnode)\n}\n\n/**\n * @param {PModel.Node | Array<PModel.Node> | undefined} mapped\n * @param {PModel.Node | Array<PModel.Node>} pcontent\n */\nconst mappedIdentity = (mapped, pcontent) =>\n mapped === pcontent ||\n (mapped instanceof Array && pcontent instanceof Array &&\n mapped.length === pcontent.length && mapped.every((a, i) =>\n pcontent[i] === a\n ))\n\n/**\n * @param {Y.XmlElement} ytype\n * @param {PModel.Node} pnode\n * @param {BindingMetadata} meta\n * @return {{ foundMappedChild: boolean, equalityFactor: number }}\n */\nconst computeChildEqualityFactor = (ytype, pnode, meta) => {\n const yChildren = ytype.toArray()\n const pChildren = normalizePNodeContent(pnode)\n const pChildCnt = pChildren.length\n const yChildCnt = yChildren.length\n const minCnt = math.min(yChildCnt, pChildCnt)\n let left = 0\n let right = 0\n let foundMappedChild = false\n for (; left < minCnt; left++) {\n const leftY = yChildren[left]\n const leftP = pChildren[left]\n if (mappedIdentity(meta.mapping.get(leftY), leftP)) {\n foundMappedChild = true // definite (good) match!\n } else if (!equalYTypePNode(leftY, leftP)) {\n break\n }\n }\n for (; left + right < minCnt; right++) {\n const rightY = yChildren[yChildCnt - right - 1]\n const rightP = pChildren[pChildCnt - right - 1]\n if (mappedIdentity(meta.mapping.get(rightY), rightP)) {\n foundMappedChild = true\n } else if (!equalYTypePNode(rightY, rightP)) {\n break\n }\n }\n return {\n equalityFactor: left + right,\n foundMappedChild\n }\n}\n\n/**\n * @param {Y.Text} ytext\n */\nconst ytextTrans = (ytext) => {\n let str = ''\n /**\n * @type {Y.Item|null}\n */\n let n = ytext._start\n const nAttrs = {}\n while (n !== null) {\n if (!n.deleted) {\n if (n.countable && n.content instanceof Y.ContentString) {\n str += n.content.str\n } else if (n.content instanceof Y.ContentFormat) {\n nAttrs[n.content.key] = null\n }\n }\n n = n.right\n }\n return {\n str,\n nAttrs\n }\n}\n\n/**\n * @todo test this more\n *\n * @param {Y.Text} ytext\n * @param {Array<any>} ptexts\n * @param {BindingMetadata} meta\n */\nconst updateYText = (ytext, ptexts, meta) => {\n meta.mapping.set(ytext, ptexts)\n const { nAttrs, str } = ytextTrans(ytext)\n const content = ptexts.map((p) => ({\n insert: /** @type {any} */ (p).text,\n attributes: Object.assign({}, nAttrs, marksToAttributes(p.marks, meta))\n }))\n const { insert, remove, index } = simpleDiff(\n str,\n content.map((c) => c.insert).join('')\n )\n ytext.delete(index, remove)\n ytext.insert(index, insert)\n ytext.applyDelta(\n content.map((c) => ({ retain: c.insert.length, attributes: c.attributes }))\n )\n}\n\nconst hashedMarkNameRegex = /(.*)(--[a-zA-Z0-9+/=]{8})$/\n/**\n * @param {string} attrName\n */\nexport const yattr2markname = attrName => hashedMarkNameRegex.exec(attrName)?.[1] ?? attrName\n\n/**\n * @todo move this to markstoattributes\n *\n * @param {Object<string, any>} attrs\n * @param {import('prosemirror-model').Schema} schema\n */\nexport const attributesToMarks = (attrs, schema) => {\n /**\n * @type {Array<import('prosemirror-model').Mark>}\n */\n const marks = []\n for (const markName in attrs) {\n // remove hashes if necessary\n marks.push(schema.mark(yattr2markname(markName), attrs[markName]))\n }\n return marks\n}\n\n/**\n * @param {Array<import('prosemirror-model').Mark>} marks\n * @param {BindingMetadata} meta\n */\nconst marksToAttributes = (marks, meta) => {\n const pattrs = {}\n marks.forEach((mark) => {\n if (mark.type.name !== 'ychange') {\n const isOverlapping = map.setIfUndefined(meta.isOMark, mark.type, () => !mark.type.excludes(mark.type))\n pattrs[isOverlapping ? `${mark.type.name}--${utils.hashOfJSON(mark.toJSON())}` : mark.type.name] = mark.attrs\n }\n })\n return pattrs\n}\n\n/**\n * Update a yDom node by syncing the current content of the prosemirror node.\n *\n * This is a y-prosemirror internal feature that you can use at your own risk.\n *\n * @private\n * @unstable\n *\n * @param {{transact: Function}} y\n * @param {Y.XmlFragment} yDomFragment\n * @param {any} pNode\n * @param {BindingMetadata} meta\n */\nexport const updateYFragment = (y, yDomFragment, pNode, meta) => {\n if (\n yDomFragment instanceof Y.XmlElement &&\n yDomFragment.nodeName !== pNode.type.name\n ) {\n throw new Error('node name mismatch!')\n }\n meta.mapping.set(yDomFragment, pNode)\n // update attributes\n if (yDomFragment instanceof Y.XmlElement) {\n const yDomAttrs = yDomFragment.getAttributes()\n const pAttrs = pNode.attrs\n for (const key in pAttrs) {\n if (pAttrs[key] !== null) {\n if (yDomAttrs[key] !== pAttrs[key] && key !== 'ychange') {\n yDomFragment.setAttribute(key, pAttrs[key])\n }\n } else {\n yDomFragment.removeAttribute(key)\n }\n }\n // remove all keys that are no longer in pAttrs\n for (const key in yDomAttrs) {\n if (pAttrs[key] === undefined) {\n yDomFragment.removeAttribute(key)\n }\n }\n }\n // update children\n const pChildren = normalizePNodeContent(pNode)\n const pChildCnt = pChildren.length\n const yChildren = yDomFragment.toArray()\n const yChildCnt = yChildren.length\n const minCnt = math.min(pChildCnt, yChildCnt)\n let left = 0\n let right = 0\n // find number of matching elements from left\n for (; left < minCnt; left++) {\n const leftY = yChildren[left]\n const leftP = pChildren[left]\n if (!mappedIdentity(meta.mapping.get(leftY), leftP)) {\n if (equalYTypePNode(leftY, leftP)) {\n // update mapping\n meta.mapping.set(leftY, leftP)\n } else {\n break\n }\n }\n }\n // find number of matching elements from right\n for (; right + left < minCnt; right++) {\n const rightY = yChildren[yChildCnt - right - 1]\n const rightP = pChildren[pChildCnt - right - 1]\n if (!mappedIdentity(meta.mapping.get(rightY), rightP)) {\n if (equalYTypePNode(rightY, rightP)) {\n // update mapping\n meta.mapping.set(rightY, rightP)\n } else {\n break\n }\n }\n }\n y.transact(() => {\n // try to compare and update\n while (yChildCnt - left - right > 0 && pChildCnt - left - right > 0) {\n const leftY = yChildren[left]\n const leftP = pChildren[left]\n const rightY = yChildren[yChildCnt - right - 1]\n const rightP = pChildren[pChildCnt - right - 1]\n if (leftY instanceof Y.XmlText && leftP instanceof Array) {\n if (!equalYTextPText(leftY, leftP)) {\n updateYText(leftY, leftP, meta)\n }\n left += 1\n } else {\n let updateLeft = leftY instanceof Y.XmlElement &&\n matchNodeName(leftY, leftP)\n let updateRight = rightY instanceof Y.XmlElement &&\n matchNodeName(rightY, rightP)\n if (updateLeft && updateRight) {\n // decide which which element to update\n const equalityLeft = computeChildEqualityFactor(\n /** @type {Y.XmlElement} */ (leftY),\n /** @type {PModel.Node} */ (leftP),\n meta\n )\n const equalityRight = computeChildEqualityFactor(\n /** @type {Y.XmlElement} */ (rightY),\n /** @type {PModel.Node} */ (rightP),\n meta\n )\n if (\n equalityLeft.foundMappedChild && !equalityRight.foundMappedChild\n ) {\n updateRight = false\n } else if (\n !equalityLeft.foundMappedChild && equalityRight.foundMappedChild\n ) {\n updateLeft = false\n } else if (\n equalityLeft.equalityFactor < equalityRight.equalityFactor\n ) {\n updateLeft = false\n } else {\n updateRight = false\n }\n }\n if (updateLeft) {\n updateYFragment(\n y,\n /** @type {Y.XmlFragment} */ (leftY),\n /** @type {PModel.Node} */ (leftP),\n meta\n )\n left += 1\n } else if (updateRight) {\n updateYFragment(\n y,\n /** @type {Y.XmlFragment} */ (rightY),\n /** @type {PModel.Node} */ (rightP),\n meta\n )\n right += 1\n } else {\n meta.mapping.delete(yDomFragment.get(left))\n yDomFragment.delete(left, 1)\n yDomFragment.insert(left, [\n createTypeFromTextOrElementNode(leftP, meta)\n ])\n left += 1\n }\n }\n }\n const yDelLen = yChildCnt - left - right\n if (\n yChildCnt === 1 && pChildCnt === 0 && yChildren[0] instanceof Y.XmlText\n ) {\n meta.mapping.delete(yChildren[0])\n // Edge case handling https://github.com/yjs/y-prosemirror/issues/108\n // Only delete the content of the Y.Text to retain remote changes on the same Y.Text object\n yChildren[0].delete(0, yChildren[0].length)\n } else if (yDelLen > 0) {\n yDomFragment.slice(left, left + yDelLen).forEach(type => meta.mapping.delete(type))\n yDomFragment.delete(left, yDelLen)\n }\n if (left + right < pChildCnt) {\n const ins = []\n for (let i = left; i < pChildCnt - right; i++) {\n ins.push(createTypeFromTextOrElementNode(pChildren[i], meta))\n }\n yDomFragment.insert(left, ins)\n }\n }, ySyncPluginKey)\n}\n\n/**\n * @function\n * @param {Y.XmlElement} yElement\n * @param {any} pNode Prosemirror Node\n */\nconst matchNodeName = (yElement, pNode) =>\n !(pNode instanceof Array) && yElement.nodeName === pNode.type.name\n","import { updateYFragment, createNodeFromYElement, yattr2markname, createEmptyMeta } from './plugins/sync-plugin.js' // eslint-disable-line\nimport { ySyncPluginKey } from './plugins/keys.js'\nimport * as Y from 'yjs'\nimport { EditorView } from 'prosemirror-view' // eslint-disable-line\nimport { Node, Schema, Fragment } from 'prosemirror-model' // eslint-disable-line\nimport * as error from 'lib0/error'\nimport * as map from 'lib0/map'\nimport * as eventloop from 'lib0/eventloop'\n\n/**\n * Either a node if type is YXmlElement or an Array of text nodes if YXmlText\n * @typedef {Map<Y.AbstractType, Node | Array<Node>>} ProsemirrorMapping\n */\n\n/**\n * Is null if no timeout is in progress.\n * Is defined if a timeout is in progress.\n * Maps from view\n * @type {Map<EditorView, Map<any, any>>|null}\n */\nlet viewsToUpdate = null\n\nconst updateMetas = () => {\n const ups = /** @type {Map<EditorView, Map<any, any>>} */ (viewsToUpdate)\n viewsToUpdate = null\n ups.forEach((metas, view) => {\n const tr = view.state.tr\n const syncState = ySyncPluginKey.getState(view.state)\n if (syncState && syncState.binding && !syncState.binding.isDestroyed) {\n metas.forEach((val, key) => {\n tr.setMeta(key, val)\n })\n view.dispatch(tr)\n }\n })\n}\n\nexport const setMeta = (view, key, value) => {\n if (!viewsToUpdate) {\n viewsToUpdate = new Map()\n eventloop.timeout(0, updateMetas)\n }\n map.setIfUndefined(viewsToUpdate, view, map.create).set(key, value)\n}\n\n/**\n * Transforms a Prosemirror based absolute position to a Yjs Cursor (relative position in the Yjs model).\n *\n * @param {number} pos\n * @param {Y.XmlFragment} type\n * @param {ProsemirrorMapping} mapping\n * @return {any} relative position\n */\nexport const absolutePositionToRelativePosition = (pos, type, mapping) => {\n if (pos === 0) {\n // if the type is later populated, we want to retain the 0 position (hence assoc=-1)\n return Y.createRelativePositionFromTypeIndex(type, 0, type.length === 0 ? -1 : 0)\n }\n /**\n * @type {any}\n */\n let n = type._first === null ? null : /** @type {Y.ContentType} */ (type._first.content).type\n while (n !== null && type !== n) {\n if (n instanceof Y.XmlText) {\n if (n._length >= pos) {\n return Y.createRelativePositionFromTypeIndex(n, pos, type.length === 0 ? -1 : 0)\n } else {\n pos -= n._length\n }\n if (n._item !== null && n._item.next !== null) {\n n = /** @type {Y.ContentType} */ (n._item.next.content).type\n } else {\n do {\n n = n._item === null ? null : n._item.parent\n pos--\n } while (n !== type && n !== null && n._item !== null && n._item.next === null)\n if (n !== null && n !== type) {\n // @ts-gnore we know that n.next !== null because of above loop conditition\n n = n._item === null ? null : /** @type {Y.ContentType} */ (/** @type Y.Item */ (n._item.next).content).type\n }\n }\n } else {\n const pNodeSize = /** @type {any} */ (mapping.get(n) || { nodeSize: 0 }).nodeSize\n if (n._first !== null && pos < pNodeSize) {\n n = /** @type {Y.ContentType} */ (n._first.content).type\n pos--\n } else {\n if (pos === 1 && n._length === 0 && pNodeSize > 1) {\n // edge case, should end in this paragraph\n return new Y.RelativePosition(n._item === null ? null : n._item.id, n._item === null ? Y.findRootTypeKey(n) : null, null)\n }\n pos -= pNodeSize\n if (n._item !== null && n._item.next !== null) {\n n = /** @type {Y.ContentType} */ (n._item.next.content).type\n } else {\n if (pos === 0) {\n // set to end of n.parent\n n = n._item === null ? n : n._item.parent\n return new Y.RelativePosition(n._item === null ? null : n._item.id, n._item === null ? Y.findRootTypeKey(n) : null, null)\n }\n do {\n n = /** @type {Y.Item} */ (n._item).parent\n pos--\n } while (n !== type && /** @type {Y.Item} */ (n._item).next === null)\n // if n is null at this point, we have an unexpected case\n if (n !== type) {\n // We know that n._item.next is defined because of above loop condition\n n = /** @type {Y.ContentType} */ (/** @type {Y.Item} */ (/** @type {Y.Item} */ (n._item).next).content).type\n }\n }\n }\n }\n if (n === null) {\n throw error.unexpectedCase()\n }\n if (pos === 0 && n.constructor !== Y.XmlText && n !== type) { // TODO: set to <= 0\n return createRelativePosition(n._item.parent, n._item)\n }\n }\n return Y.createRelativePositionFromTypeIndex(type, type._length, type.length === 0 ? -1 : 0)\n}\n\nconst createRelativePosition = (type, item) => {\n let typeid = null\n let tname = null\n if (type._item === null) {\n tname = Y.findRootTypeKey(type)\n } else {\n typeid = Y.createID(type._item.id.client, type._item.id.clock)\n }\n return new Y.RelativePosition(typeid, tname, item.id)\n}\n\n/**\n * @param {Y.Doc} y\n * @param {Y.XmlFragment} documentType Top level type that is bound to pView\n * @param {any} relPos Encoded Yjs based relative position\n * @param {ProsemirrorMapping} mapping\n * @return {null|number}\n */\nexport const relativePositionToAbsolutePosition = (y, documentType, relPos, mapping) => {\n const decodedPos = Y.createAbsolutePositionFromRelativePosition(relPos, y)\n if (decodedPos === null || (decodedPos.type !== documentType && !Y.isParentOf(documentType, decodedPos.type._item))) {\n return null\n }\n let type = decodedPos.type\n let pos = 0\n if (type.constructor === Y.XmlText) {\n pos = decodedPos.index\n } else if (type._item === null || !type._item.deleted) {\n let n = type._first\n let i = 0\n while (i < type._length && i < decodedPos.index && n !== null) {\n if (!n.deleted) {\n const t = /** @type {Y.ContentType} */ (n.content).type\n i++\n if (t instanceof Y.XmlText) {\n pos += t._length\n } else {\n pos += /** @type {any} */ (mapping.get(t)).nodeSize\n }\n }\n n = /** @type {Y.Item} */ (n.right)\n }\n pos += 1 // increase because we go out of n\n }\n while (type !== documentType && type._item !== null) {\n // @ts-ignore\n const parent = type._item.parent\n // @ts-ignore\n if (parent._item === null || !parent._item.deleted) {\n pos += 1 // the start tag\n let n = /** @type {Y.AbstractType} */ (parent)._first\n // now iterate until we found type\n while (n !== null) {\n const contentType = /** @type {Y.ContentType} */ (n.content).type\n if (contentType === type) {\n break\n }\n if (!n.deleted) {\n if (contentType instanceof Y.XmlText) {\n pos += contentType._length\n } else {\n pos += /** @type {any} */ (mapping.get(contentType)).nodeSize\n }\n }\n n = n.right\n }\n }\n type = /** @type {Y.AbstractType} */ (parent)\n }\n return pos - 1 // we don't count the most outer tag, because it is a fragment\n}\n\n/**\n * Utility function for converting an Y.Fragment to a ProseMirror fragment.\n *\n * @param {Y.XmlFragment} yXmlFragment\n * @param {Schema} schema\n */\nexport const yXmlFragmentToProseMirrorFragment = (yXmlFragment, schema) => {\n const fragmentContent = yXmlFragment.toArray().map((t) =>\n createNodeFromYElement(\n /** @type {Y.XmlElement} */ (t),\n schema,\n createEmptyMeta()\n )\n ).filter((n) => n !== null)\n return Fragment.fromArray(fragmentContent)\n}\n\n/**\n * Utility function for converting an Y.Fragment to a ProseMirror node.\n *\n * @param {Y.XmlFragment} yXmlFragment\n * @param {Schema} schema\n */\nexport const yXmlFragmentToProseMirrorRootNode = (yXmlFragment, schema) =>\n schema.topNodeType.create(null, yXmlFragmentToProseMirrorFragment(yXmlFragment, schema))\n\n/**\n * The initial ProseMirror content should be supplied by Yjs. This function transforms a Y.Fragment\n * to a ProseMirror Doc node and creates a mapping that is used by the sync plugin.\n *\n * @param {Y.XmlFragment} yXmlFragment\n * @param {Schema} schema\n *\n * @todo deprecate mapping property\n */\nexport const initProseMirrorDoc = (yXmlFragment, schema) => {\n const meta = createEmptyMeta()\n const fragmentContent = yXmlFragment.toArray().map((t) =>\n createNodeFromYElement(\n /** @type {Y.XmlElement} */ (t),\n schema,\n meta\n )\n ).filter((n) => n !== null)\n const doc = schema.topNodeType.create(null, Fragment.fromArray(fragmentContent))\n return { doc, meta, mapping: meta.mapping }\n}\n\n/**\n * Utility method to convert a Prosemirror Doc Node into a Y.Doc.\n *\n * This can be used when importing existing content to Y.Doc for the first time,\n * note that this should not be used to rehydrate a Y.Doc from a database once\n * collaboration has begun as all history will be lost\n *\n * @param {Node} doc\n * @param {string} xmlFragment\n * @return {Y.Doc}\n */\nexport function prosemirrorToYDoc (doc, xmlFragment = 'prosemirror') {\n const ydoc = new Y.Doc()\n const type = /** @type {Y.XmlFragment} */ (ydoc.get(xmlFragment, Y.XmlFragment))\n if (!type.doc) {\n return ydoc\n }\n\n prosemirrorToYXmlFragment(doc, type)\n return type.doc\n}\n\n/**\n * Utility method to update an empty Y.XmlFragment with content from a Prosemirror Doc Node.\n *\n * This can be used when importing existing content to Y.Doc for the first time,\n * note that this should not be used to rehydrate a Y.Doc from a database once\n * collaboration has begun as all history will be lost\n *\n * Note: The Y.XmlFragment does not need to be part of a Y.Doc document at the time that this\n * method is called, but it must be added before any other operations are performed on it.\n *\n * @param {Node} doc prosemirror document.\n * @param {Y.XmlFragment} [xmlFragment] If supplied, an xml fragment to be\n * populated from the prosemirror state; otherwise a new XmlFragment will be created.\n * @return {Y.XmlFragment}\n */\nexport function prosemirrorToYXmlFragment (doc, xmlFragment) {\n const type = xmlFragment || new Y.XmlFragment()\n const ydoc = type.doc ? type.doc : { transact: (transaction) => transaction(undefined) }\n updateYFragment(ydoc, type, doc, { mapping: new Map(), isOMark: new Map() })\n return type\n}\n\n/**\n * Utility method to convert Prosemirror compatible JSON into a Y.Doc.\n *\n * This can be used when importing existing content to Y.Doc for the first time,\n * note that this should not be used to rehydrate a Y.Doc from a database once\n * collaboration has begun as all history will be lost\n *\n * @param {Schema} schema\n * @param {any} state\n * @param {string} xmlFragment\n * @return {Y.Doc}\n */\nexport function prosemirrorJSONToYDoc (schema, state, xmlFragment = 'prosemirror') {\n const doc = Node.fromJSON(schema, state)\n return prosemirrorToYDoc(doc, xmlFragment)\n}\n\n/**\n * Utility method to convert Prosemirror compatible JSON to a Y.XmlFragment\n *\n * This can be used when importing existing content to Y.Doc for the first time,\n * note that this should not be used to rehydrate a Y.Doc from a database once\n * collaboration has begun as all history will be lost\n *\n * @param {Schema} schema\n * @param {any} state\n * @param {Y.XmlFragment} [xmlFragment] If supplied, an xml fragment to be\n * populated from the prosemirror state; otherwise a new XmlFragment will be created.\n * @return {Y.XmlFragment}\n */\nexport function prosemirrorJSONToYXmlFragment (schema, state, xmlFragment) {\n const doc = Node.fromJSON(schema, state)\n return prosemirrorToYXmlFragment(doc, xmlFragment)\n}\n\n/**\n * @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead\n *\n * Utility method to convert a Y.Doc to a Prosemirror Doc node.\n *\n * @param {Schema} schema\n * @param {Y.Doc} ydoc\n * @return {Node}\n */\nexport function yDocToProsemirror (schema, ydoc) {\n const state = yDocToProsemirrorJSON(ydoc)\n return Node.fromJSON(schema, state)\n}\n\n/**\n *\n * @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead\n *\n * Utility method to convert a Y.XmlFragment to a Prosemirror Doc node.\n *\n * @param {Schema} schema\n * @param {Y.XmlFragment} xmlFragment\n * @return {Node}\n */\nexport function yXmlFragmentToProsemirror (schema, xmlFragment) {\n const state = yXmlFragmentToProsemirrorJSON(xmlFragment)\n return Node.fromJSON(schema, state)\n}\n\n/**\n *\n * @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead\n *\n * Utility method to convert a Y.Doc to Prosemirror compatible JSON.\n *\n * @param {Y.Doc} ydoc\n * @param {string} xmlFragment\n * @return {Record<string, any>}\n */\nexport function yDocToProsemirrorJSON (\n ydoc,\n xmlFragment = 'prosemirror'\n) {\n return yXmlFragmentToProsemirrorJSON(ydoc.getXmlFragment(xmlFragment))\n}\n\n/**\n * @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead\n *\n * Utility method to convert a Y.Doc to Prosemirror compatible JSON.\n *\n * @param {Y.XmlFragment} xmlFragment The fragment, which must be part of a Y.Doc.\n * @return {Record<string, any>}\n */\nexport function yXmlFragmentToProsemirrorJSON (xmlFragment) {\n const items = xmlFragment.toArray()\n\n /**\n * @param {Y.AbstractType} item\n */\n const serialize = item => {\n /**\n * @type {Object} NodeObject\n * @property {string} NodeObject.type\n * @property {Record<string, string>=} NodeObject.attrs\n * @property {Array<NodeObject>=} NodeObject.content\n */\n let response\n\n // TODO: Must be a better way to detect text nodes than this\n if (item instanceof Y.XmlText) {\n const delta = item.toDelta()\n response = delta.map(/** @param {any} d */ (d) => {\n const text = {\n type: 'text',\n text: d.insert\n }\n if (d.attributes) {\n text.marks = Object.keys(d.attributes).map((type_) => {\n const attrs = d.attributes[type_]\n const type = yattr2markname(type_)\n const mark = {\n type\n }\n if (Object.keys(attrs)) {\n mark.attrs = attrs\n }\n return mark\n })\n }\n return text\n })\n } else if (item instanceof Y.XmlElement) {\n response = {\n type: item.nodeName\n }\n\n const attrs = item.getAttributes()\n if (Object.keys(attrs).length) {\n response.attrs = attrs\n }\n\n const children = item.toArray()\n if (children.length) {\n response.content = children.map(serialize).flat()\n }\n } else {\n // expected either Y.XmlElement or Y.XmlText\n error.unexpectedCase()\n }\n\n return response\n }\n\n return {\n type: 'doc',\n content: items.map(serialize)\n }\n}\n","/**\n * Liveblocks Text Editor\n *\n * Expose common types to transform nodes from different editors like `Lexical` or `TipTap`\n * and then convert them more easily as React or as html.\n */\n\nimport type {\n Awaitable,\n BaseUserMeta,\n DGI,\n Relax,\n ResolveGroupsInfoArgs,\n ResolveUsersArgs,\n} from \"@liveblocks/core\";\n\nimport type {\n LexicalMentionNodeWithContext,\n SerializedLexicalNode,\n SerializedLexicalTextNode,\n} from \"./lexical-editor\";\nimport {\n isSerializedGroupMentionNode as isSerializedLexicalGroupMentionNode,\n isSerializedMentionNode as isSerializedLexicalMentionNode,\n} from \"./lexical-editor\";\nimport type {\n SerializedTiptapMark,\n SerializedTiptapMarkType,\n SerializedTiptapNode,\n SerializedTiptapTextNode,\n TiptapMentionNodeWithContext,\n} from \"./tiptap-editor\";\nimport {\n isSerializedGroupMentionNode as isSerializedTiptapGroupMentionNode,\n isSerializedMentionNode as isSerializedTiptapMentionNode,\n} from \"./tiptap-editor\";\n\ntype LiveblocksTextEditorTextFormat = {\n bold: boolean;\n italic: boolean;\n strikethrough: boolean;\n code: boolean;\n};\n\nexport type LiveblocksTextEditorTextNode = {\n type: \"text\";\n text: string;\n} & LiveblocksTextEditorTextFormat;\n\nexport type LiveblocksTextEditorMentionNode = Relax<\n LiveblocksTextEditorUserMentionNode | LiveblocksTextEditorGroupMentionNode\n>;\n\ntype LiveblocksTextEditorUserMentionNode = {\n type: \"mention\";\n kind: \"user\";\n id: string;\n};\n\nexport type LiveblocksTextEditorGroupMentionNode = {\n type: \"mention\";\n kind: \"group\";\n id: string;\n userIds?: string[];\n};\n\n/**\n * -------------------------------------------------------------------------------------------------\n * `LiveblocksTextEditorNode` is common structure to represents text editor nodes coming from\n * like `Lexical`, `TipTap` or so.\n *\n * This (simple) structure is made to be scalable and to accommodate with other text editors we could potentially\n * want to support in the future.\n *\n * It allows to manipulate nodes more easily and converts them with ease either as React nodes or as an html safe string.\n * From a DX standpoint it provides to developers the same structure to use when using custom React components or inline css\n * to represents a text mention with its surrounding text.\n * -------------------------------------------------------------------------------------------------\n */\nexport type LiveblocksTextEditorNode =\n | LiveblocksTextEditorTextNode\n | LiveblocksTextEditorMentionNode;\n\nconst baseLiveblocksTextEditorTextFormat: LiveblocksTextEditorTextFormat = {\n bold: false,\n italic: false,\n strikethrough: false,\n code: false,\n};\n\n/**\n * -------------------------------------------------------------------------------------------------\n * Lexical use bitwise operators to represent text formatting:\n * → https://github.com/facebook/lexical/blob/e423c6888dbf2dbd0b5ef68f781efadda20d34f3/packages/lexical/src/LexicalConstants.ts#L39\n *\n * It allows to combine multiple flags into one single integer such as:\n * 00000001 (bold)\n * 00000010 (italic)\n * --------\n * 0000011 (bold + italic)\n *\n * For now we're copying only the bitwise flags we need to provide a consistent DX with\n * `ThreadNotificationEvent` comments:\n * - BOLD\n * - ITALIC\n * - STRIKETHROUGH\n * - CODE\n *\n * and `transformLexicalTextNodeFormatBitwiseInteger` transforms these flags\n * into a object of booleans `LiveblocksTextEditorTextFormat`:\n * ```ts\n * {\n * bold: boolean;\n * italic: boolean;\n * strikethrough: boolean;\n * code: boolean;\n * }\n * ```\n * -------------------------------------------------------------------------------------------------\n */\n\nconst IS_LEXICAL_BOLD = 1;\nconst IS_LEXICAL_ITALIC = 1 << 1;\nconst IS_LEXICAL_STRIKETHROUGH = 1 << 2;\nconst IS_LEXICAL_CODE = 1 << 4;\n\n/** @internal */\nconst transformLexicalTextNodeFormatBitwiseInteger = (\n node: SerializedLexicalTextNode\n): LiveblocksTextEditorTextFormat => {\n const attributes = node.attributes;\n\n if (\"__format\" in attributes && typeof attributes.__format === \"number\") {\n const format = attributes.__format;\n return {\n bold: (format & IS_LEXICAL_BOLD) !== 0,\n italic: (format & IS_LEXICAL_ITALIC) !== 0,\n strikethrough: (format & IS_LEXICAL_STRIKETHROUGH) !== 0,\n code: (format & IS_LEXICAL_CODE) !== 0,\n };\n }\n\n return baseLiveblocksTextEditorTextFormat;\n};\n\n/**\n * @internal\n *\n * Transform Lexical serialized nodes\n * as Liveblocks Text Editor nodes\n */\nconst transformLexicalMentionNodeWithContext = (\n mentionNodeWithContext: LexicalMentionNodeWithContext\n): LiveblocksTextEditorNode[] => {\n const textEditorNodes: LiveblocksTextEditorNode[] = [];\n const { before, after, mention } = mentionNodeWithContext;\n\n const transform = (nodes: SerializedLexicalNode[]) => {\n for (const node of nodes) {\n if (node.group === \"text\") {\n const format = transformLexicalTextNodeFormatBitwiseInteger(node);\n textEditorNodes.push({\n type: \"text\",\n text: node.text,\n ...format,\n });\n } else if (\n node.group === \"decorator\" &&\n isSerializedLexicalMentionNode(node)\n ) {\n textEditorNodes.push({\n type: \"mention\",\n kind: \"user\",\n id: node.attributes.__userId,\n });\n } else if (\n node.group === \"decorator\" &&\n isSerializedLexicalGroupMentionNode(node)\n ) {\n textEditorNodes.push({\n type: \"mention\",\n kind: \"group\",\n id: node.attributes.__groupId,\n });\n }\n }\n };\n\n transform(before);\n textEditorNodes.push({\n type: \"mention\",\n kind: mention.type === \"lb-group-mention\" ? \"group\" : \"user\",\n id:\n mention.type === \"lb-group-mention\"\n ? mention.attributes.__groupId\n : mention.attributes.__userId,\n });\n transform(after);\n\n return textEditorNodes;\n};\n\n/** @internal */\nconst hasTiptapSerializedTextNodeMark = (\n marks: Array<SerializedTiptapMark>,\n type: SerializedTiptapMarkType\n): boolean => marks.findIndex((mark) => mark.type === type) !== -1;\n\n/** @internal */\nconst transformTiptapTextNodeFormatMarks = (\n node: SerializedTiptapTextNode\n): LiveblocksTextEditorTextFormat => {\n if (!node.marks) {\n return baseLiveblocksTextEditorTextFormat;\n }\n\n const marks = node.marks;\n return {\n bold: hasTiptapSerializedTextNodeMark(marks, \"bold\"),\n italic: hasTiptapSerializedTextNodeMark(marks, \"italic\"),\n strikethrough: hasTiptapSerializedTextNodeMark(marks, \"strike\"),\n code: hasTiptapSerializedTextNodeMark(marks, \"code\"),\n };\n};\n\n/**\n *\n * @internal\n *\n * Transform Tiptap serialized nodes\n * as Liveblocks Text Editor nodes\n */\nconst transformTiptapMentionNodeWithContext = (\n mentionNodeWithContext: TiptapMentionNodeWithContext\n): LiveblocksTextEditorNode[] => {\n const textEditorNodes: LiveblocksTextEditorNode[] = [];\n const { before, after, mention } = mentionNodeWithContext;\n\n const transform = (nodes: SerializedTiptapNode[]) => {\n for (const node of nodes) {\n if (node.type === \"text\") {\n const format = transformTiptapTextNodeFormatMarks(node);\n textEditorNodes.push({\n type: \"text\",\n text: node.text,\n ...format,\n });\n } else if (isSerializedTiptapMentionNode(node)) {\n textEditorNodes.push({\n type: \"mention\",\n kind: \"user\",\n id: node.attrs.id,\n });\n } else if (isSerializedTiptapGroupMentionNode(node)) {\n textEditorNodes.push({\n type: \"mention\",\n kind: \"group\",\n id: node.attrs.id,\n });\n }\n }\n };\n\n transform(before);\n textEditorNodes.push({\n type: \"mention\",\n kind: mention.type === \"liveblocksGroupMention\" ? \"group\" : \"user\",\n id: mention.attrs.id,\n });\n transform(after);\n\n return textEditorNodes;\n};\n\ntype TransformableMentionNodeWithContext =\n | {\n editor: \"lexical\";\n mention: LexicalMentionNodeWithContext;\n }\n | {\n editor: \"tiptap\";\n mention: TiptapMentionNodeWithContext;\n };\n\n/**\n * @internal\n *\n * Transforms either Lexical or TipTap nodes into a common structure\n * of Liveblocks Text Editor nodes to ease conversion into\n * React Nodes or html safe strings\n */\nexport function transformAsLiveblocksTextEditorNodes(\n transformableMention: TransformableMentionNodeWithContext\n): LiveblocksTextEditorNode[] {\n switch (transformableMention.editor) {\n case \"lexical\": {\n return transformLexicalMentionNodeWithContext(\n transformableMention.mention\n );\n }\n case \"tiptap\": {\n return transformTiptapMentionNodeWithContext(\n transformableMention.mention\n );\n }\n }\n}\n\n/**\n * @internal\n * Resolves mentions (users or groups) in Liveblocks Text Editor nodes.\n */\nexport const resolveMentionsInLiveblocksTextEditorNodes = async <\n U extends BaseUserMeta,\n>(\n nodes: LiveblocksTextEditorNode[],\n resolveUsers?: (\n args: ResolveUsersArgs\n ) => Awaitable<(U[\"info\"] | undefined)[] | undefined>,\n resolveGroupsInfo?: (\n args: ResolveGroupsInfoArgs\n ) => Awaitable<(DGI | undefined)[] | undefined>\n): Promise<{\n users: Map<string, U[\"info\"]>;\n groups: Map<string, DGI>;\n}> => {\n const resolvedUsers = new Map<string, U[\"info\"]>();\n const resolvedGroupsInfo = new Map<string, DGI>();\n\n if (!resolveUsers && !resolveGroupsInfo) {\n return {\n users: resolvedUsers,\n groups: resolvedGroupsInfo,\n };\n }\n\n const mentionedUserIds = new Set<string>();\n const mentionedGroupIds = new Set<string>();\n\n for (const node of nodes) {\n if (node.type === \"mention\") {\n if (node.kind === \"user\") {\n mentionedUserIds.add(node.id);\n } else if (node.kind === \"group\") {\n mentionedGroupIds.add(node.id);\n }\n }\n }\n\n const userIds = Array.from(mentionedUserIds);\n const groupIds = Array.from(mentionedGroupIds);\n\n const [users, groups] = await Promise.all([\n resolveUsers && userIds.length > 0 ? resolveUsers({ userIds }) : undefined,\n resolveGroupsInfo && groupIds.length > 0\n ? resolveGroupsInfo({ groupIds })\n : undefined,\n ]);\n\n if (users) {\n for (const [index, userId] of userIds.entries()) {\n const user = users[index];\n if (user) {\n resolvedUsers.set(userId, user);\n }\n }\n }\n\n if (groups) {\n for (const [index, groupId] of groupIds.entries()) {\n const group = groups[index];\n if (group) {\n resolvedGroupsInfo.set(groupId, group);\n }\n }\n }\n\n return {\n users: resolvedUsers,\n groups: resolvedGroupsInfo,\n };\n};\n","import type {\n Awaitable,\n BaseUserMeta,\n DGI,\n DU,\n ResolveGroupsInfoArgs,\n ResolveUsersArgs,\n} from \"@liveblocks/core\";\n\nimport {\n type LiveblocksTextEditorMentionNode,\n type LiveblocksTextEditorNode,\n type LiveblocksTextEditorTextNode,\n resolveMentionsInLiveblocksTextEditorNodes,\n} from \"./liveblocks-text-editor\";\n\nexport type TextMentionContentContainerElementArgs<T> = {\n /**\n * The blocks of the text mention content\n */\n children: T[];\n};\n\nexport type TextMentionContentMentionElementArgs<U extends BaseUserMeta = DU> =\n {\n /**\n * The text mention node.\n */\n node: LiveblocksTextEditorMentionNode;\n\n /**\n * The mention's user info, if the mention is a user mention and the `resolvedUsers` option was provided.\n */\n user?: U[\"info\"];\n\n /**\n * The mention's group info, if the mention is a group mention and the `resolvedGroupsInfo` option was provided.\n */\n group?: DGI;\n };\n\nexport type TextMentionContentTextElementArgs = {\n /**\n * The text element.\n */\n node: LiveblocksTextEditorTextNode;\n};\n\n/**\n * Protocol:\n * Text mention content elements to be converted to a custom format `T`\n */\nexport type ConvertTextMentionContentElements<\n T,\n U extends BaseUserMeta = DU,\n> = {\n /**\n * The container element used to display text mention content blocks\n */\n container: (args: TextMentionContentContainerElementArgs<T>) => T;\n /**\n * The mention element used to display the mention itself.\n */\n mention: (args: TextMentionContentMentionElementArgs<U>, index: number) => T;\n /**\n * The text element used to display the text surrounding the mention.\n */\n text: (args: TextMentionContentTextElementArgs, index: number) => T;\n};\n\nexport type ConvertTextMentionContentOptions<T, U extends BaseUserMeta = DU> = {\n /**\n * A function that returns user info from user IDs.\n * You should return a list of user objects of the same size, in the same order.\n */\n resolveUsers?: (\n args: ResolveUsersArgs\n ) => Awaitable<(U[\"info\"] | undefined)[] | undefined>;\n\n /**\n * A function that returns group info from group IDs.\n * You should return a list of group info objects of the same size, in the same order.\n */\n resolveGroupsInfo?: (\n args: ResolveGroupsInfoArgs\n ) => Awaitable<(DGI | undefined)[] | undefined>;\n\n /**\n * The elements used to customize the resulting format `T`.\n */\n elements: ConvertTextMentionContentElements<T, U>;\n};\n\n/**\n * Convert a text mention content nodes to a custom format `T`.\n */\nexport async function convertTextMentionContent<T, U extends BaseUserMeta = DU>(\n nodes: LiveblocksTextEditorNode[],\n options: ConvertTextMentionContentOptions<T, U>\n): Promise<T> {\n const { users: resolvedUsers, groups: resolvedGroupsInfo } =\n await resolveMentionsInLiveblocksTextEditorNodes(\n nodes,\n options?.resolveUsers,\n options?.resolveGroupsInfo\n );\n\n const blocks: T[] = nodes.map((node, index) => {\n switch (node.type) {\n case \"mention\": {\n return options.elements.mention(\n {\n node,\n user: node.kind === \"user\" ? resolvedUsers.get(node.id) : undefined,\n group:\n node.kind === \"group\"\n ? resolvedGroupsInfo.get(node.id)\n : undefined,\n },\n index\n );\n }\n case \"text\": {\n return options.elements.text({ node }, index);\n }\n }\n });\n\n return options.elements.container({ children: blocks });\n}\n","import type {\n Awaitable,\n BaseUserMeta,\n CommentBodyLink,\n CommentBodyMention,\n CommentBodyText,\n CommentData,\n DGI,\n DRI,\n DU,\n GroupData,\n InboxNotificationData,\n ResolveGroupsInfoArgs,\n ResolveUsersArgs,\n} from \"@liveblocks/core\";\nimport {\n generateUrl,\n getMentionsFromCommentBody,\n html,\n htmlSafe,\n MENTION_CHARACTER,\n} from \"@liveblocks/core\";\nimport type { Liveblocks, ThreadNotificationEvent } from \"@liveblocks/node\";\nimport type { ComponentType, ReactNode } from \"react\";\n\nimport type { ConvertCommentBodyElements } from \"./comment-body\";\nimport { convertCommentBody } from \"./comment-body\";\nimport type { CommentDataWithBody } from \"./comment-with-body\";\nimport { filterCommentsWithBody } from \"./comment-with-body\";\nimport {\n createBatchGroupsInfoResolver,\n createBatchUsersResolver,\n getResolvedForId,\n} from \"./lib/batch-resolvers\";\nimport type { CSSProperties } from \"./lib/css-properties\";\nimport { toInlineCSSString } from \"./lib/css-properties\";\nimport type { ResolveRoomInfoArgs } from \"./lib/types\";\n\n/** @internal */\nexport const getUnreadComments = ({\n comments,\n inboxNotification,\n notificationTriggerAt,\n userId,\n}: {\n comments: CommentData[];\n inboxNotification: InboxNotificationData;\n notificationTriggerAt: Date;\n userId: string;\n}): CommentDataWithBody[] => {\n // Let's get only not deleted comments with a body.\n const commentsWithBody = filterCommentsWithBody(comments);\n // Let's filter out comments written by the user that received the notification.\n const notAuthoredComments = commentsWithBody.filter(\n (c) => c.userId !== userId\n );\n\n const readAt = inboxNotification.readAt;\n // This behavior is different from the `InboxNotificationThread` component\n // because we in the front-end we want the always the last activity.\n // In this case then we want to do a sequential reading of the activity.\n // It allow us to determine much more precisely which comments was created between\n // the moment the inbox notification is created and the moment the webhook event is received.\n return notAuthoredComments.filter((c) => {\n // If the inbox notification is read, because of the 1:1 relationship between an\n // and inbox notification and a thread, we must not include comments created\n // strictly after the `readAt` date. It means the inbox notification can be updated\n // in the db after the `readAt` date.\n if (readAt !== null) {\n return (\n c.createdAt > readAt &&\n c.createdAt >= notificationTriggerAt &&\n c.createdAt <= inboxNotification.notifiedAt\n );\n }\n // Otherwise we can include all comments created between the inbox notification\n // creation date (`triggeredAt`) and the inbox notification `notifiedAt` date.\n return (\n c.createdAt >= notificationTriggerAt &&\n c.createdAt <= inboxNotification.notifiedAt\n );\n });\n};\n\n/** @internal */\nasync function getAllUserGroups(\n client: Liveblocks,\n userId: string\n): Promise<Map<string, GroupData>> {\n const groups = new Map<string, GroupData>();\n let cursor: string | undefined = undefined;\n\n while (true) {\n const { nextCursor, data } = await client.getUserGroups({\n userId,\n startingAfter: cursor,\n });\n\n for (const group of data) {\n groups.set(group.id, group);\n }\n\n if (!nextCursor) {\n break;\n }\n\n cursor = nextCursor;\n }\n\n return groups;\n}\n\n/** @internal */\nexport const getLastUnreadCommentWithMention = ({\n comments,\n groups,\n mentionedUserId,\n}: {\n comments: CommentDataWithBody[];\n mentionedUserId: string;\n groups: Map<string, GroupData>;\n}): CommentDataWithBody | null => {\n if (!comments.length) {\n return null;\n }\n\n for (let i = comments.length - 1; i >= 0; i--) {\n const comment = comments[i]!;\n\n if (comment.userId === mentionedUserId) {\n continue;\n }\n\n const mentions = getMentionsFromCommentBody(comment.body);\n\n for (const mention of mentions) {\n // 1. The comment contains a user mention for the current user.\n if (mention.kind === \"user\" && mention.id === mentionedUserId) {\n return comment;\n }\n\n // 2. The comment contains a group mention including the current user in its `userIds` array.\n if (\n mention.kind === \"group\" &&\n mention.userIds?.includes(mentionedUserId)\n ) {\n return comment;\n }\n\n // 3. The comment contains a group mention including the current user in its managed group members.\n if (mention.kind === \"group\" && mention.userIds === undefined) {\n // Synchronously look up the group data for this group ID.\n const group = groups.get(mention.id);\n\n if (group?.members.some((member) => member.id === mentionedUserId)) {\n return comment;\n }\n }\n }\n }\n\n return null;\n};\n\nexport type ThreadNotificationData =\n | { type: \"unreadMention\"; comment: CommentDataWithBody }\n | { type: \"unreadReplies\"; comments: CommentDataWithBody[] };\n\n/** @internal */\nexport const extractThreadNotificationData = async ({\n client,\n event,\n}: {\n client: Liveblocks;\n event: ThreadNotificationEvent;\n}): Promise<ThreadNotificationData | null> => {\n const { threadId, roomId, userId, inboxNotificationId } = event.data;\n const [thread, inboxNotification] = await Promise.all([\n client.getThread({ roomId, threadId }),\n client.getInboxNotification({ inboxNotificationId, userId }),\n ]);\n\n const notificationTriggerAt = new Date(event.data.triggeredAt);\n const unreadComments = getUnreadComments({\n comments: thread.comments,\n inboxNotification,\n userId,\n notificationTriggerAt,\n });\n\n if (unreadComments.length <= 0) {\n return null;\n }\n\n const userGroups = await getAllUserGroups(client, userId);\n\n const lastUnreadCommentWithMention = getLastUnreadCommentWithMention({\n comments: unreadComments,\n groups: userGroups,\n mentionedUserId: userId,\n });\n\n if (lastUnreadCommentWithMention !== null) {\n return { type: \"unreadMention\", comment: lastUnreadCommentWithMention };\n }\n\n return {\n type: \"unreadReplies\",\n comments: unreadComments,\n };\n};\n\n/**\n * @internal\n * Set the comment ID as the URL hash.\n */\nfunction generateCommentUrl({\n roomUrl,\n commentId,\n}: {\n roomUrl: string | undefined;\n commentId: string;\n}): string | undefined {\n if (!roomUrl) {\n return;\n }\n\n return generateUrl(roomUrl, undefined, commentId);\n}\n\nexport type CommentEmailData<BodyType, U extends BaseUserMeta = DU> = {\n id: string;\n threadId: string;\n roomId: string;\n createdAt: Date;\n url?: string;\n author: U;\n body: BodyType;\n};\n\nexport type ThreadNotificationEmailData<\n BodyType,\n U extends BaseUserMeta = DU,\n C extends CommentEmailData<BodyType, U> = CommentEmailData<BodyType, U>,\n> = (\n | {\n type: \"unreadReplies\";\n comments: C[];\n }\n | {\n type: \"unreadMention\";\n comment: C;\n }\n) & { roomInfo: DRI };\n\nexport type CommentEmailAsHtmlData<U extends BaseUserMeta = DU> =\n CommentEmailData<string, U>;\n\nexport type CommentEmailAsReactData<U extends BaseUserMeta = DU> =\n CommentEmailData<ReactNode, U>;\n\ntype PrepareThreadNotificationEmailOptions<U extends BaseUserMeta = DU> = {\n /**\n * A function that returns room info from room IDs.\n */\n resolveRoomInfo?: (args: ResolveRoomInfoArgs) => Awaitable<DRI | undefined>;\n\n /**\n * A function that returns user info from user IDs.\n * You should return a list of user objects of the same size, in the same order.\n */\n resolveUsers?: (\n args: ResolveUsersArgs\n ) => Awaitable<(U[\"info\"] | undefined)[] | undefined>;\n\n /**\n * A function that returns group info from group IDs.\n * You should return a list of group info objects of the same size, in the same order.\n */\n resolveGroupsInfo?: (\n args: ResolveGroupsInfoArgs\n ) => Awaitable<(DGI | undefined)[] | undefined>;\n};\n\n/**\n * @internal\n * exported for testing purposes.\n */\nexport async function prepareThreadNotificationEmail<\n BodyType,\n U extends BaseUserMeta = DU,\n>(\n client: Liveblocks,\n event: ThreadNotificationEvent,\n options: PrepareThreadNotificationEmailOptions<U>,\n elements: ConvertCommentBodyElements<BodyType, U>,\n callerName: string\n): Promise<ThreadNotificationEmailData<BodyType, U> | null> {\n const data = await extractThreadNotificationData({ client, event });\n if (data === null) {\n return null;\n }\n\n const roomInfo = options.resolveRoomInfo\n ? await options.resolveRoomInfo({ roomId: event.data.roomId })\n : undefined;\n\n const resolvedRoomInfo: DRI = {\n ...roomInfo,\n name: roomInfo?.name ?? event.data.roomId,\n };\n\n const batchUsersResolver = createBatchUsersResolver<U>({\n resolveUsers: options.resolveUsers,\n callerName,\n });\n const batchGroupsInfoResolver = createBatchGroupsInfoResolver({\n resolveGroupsInfo: options.resolveGroupsInfo,\n callerName,\n });\n\n switch (data.type) {\n case \"unreadMention\": {\n const { comment } = data;\n\n const authorsIds = [comment.userId];\n const authorsInfoPromise = batchUsersResolver.get(authorsIds);\n const commentBodyPromise = convertCommentBody<BodyType, U>(comment.body, {\n resolveUsers: ({ userIds }) => batchUsersResolver.get(userIds),\n resolveGroupsInfo: ({ groupIds }) =>\n batchGroupsInfoResolver.get(groupIds),\n elements,\n });\n\n await batchUsersResolver.resolve();\n await batchGroupsInfoResolver.resolve();\n\n const [authorsInfo, commentBody] = await Promise.all([\n authorsInfoPromise,\n commentBodyPromise,\n ]);\n\n const authorInfo = getResolvedForId(\n comment.userId,\n authorsIds,\n authorsInfo\n );\n const url = roomInfo?.url\n ? generateCommentUrl({\n roomUrl: roomInfo?.url,\n commentId: comment.id,\n })\n : undefined;\n\n return {\n type: \"unreadMention\",\n comment: {\n id: comment.id,\n threadId: comment.threadId,\n roomId: comment.roomId,\n author: {\n id: comment.userId,\n info: authorInfo ?? { name: comment.userId },\n } as U,\n createdAt: comment.createdAt,\n url,\n body: commentBody as BodyType,\n },\n roomInfo: resolvedRoomInfo,\n };\n }\n case \"unreadReplies\": {\n const { comments } = data;\n\n const authorsIds = comments.map((c) => c.userId);\n const authorsInfoPromise = batchUsersResolver.get(authorsIds);\n\n const commentBodiesPromises = comments.map((c) =>\n convertCommentBody<BodyType, U>(c.body, {\n resolveUsers: ({ userIds }) => batchUsersResolver.get(userIds),\n resolveGroupsInfo: ({ groupIds }) =>\n batchGroupsInfoResolver.get(groupIds),\n elements,\n })\n );\n\n await batchUsersResolver.resolve();\n await batchGroupsInfoResolver.resolve();\n\n const [authorsInfo, ...commentBodies] = await Promise.all([\n authorsInfoPromise,\n ...commentBodiesPromises,\n ]);\n\n return {\n type: \"unreadReplies\",\n comments: comments.map((comment, index) => {\n const authorInfo = getResolvedForId(\n comment.userId,\n authorsIds,\n authorsInfo\n );\n const commentBody = commentBodies[index] as BodyType;\n\n const url = generateCommentUrl({\n roomUrl: roomInfo?.url,\n commentId: comment.id,\n });\n\n return {\n id: comment.id,\n threadId: comment.threadId,\n roomId: comment.roomId,\n author: {\n id: comment.userId,\n info: authorInfo ?? { name: comment.userId },\n } as U,\n createdAt: comment.createdAt,\n url,\n body: commentBody,\n };\n }),\n roomInfo: resolvedRoomInfo,\n };\n }\n }\n}\n\n/**\n * The styles used to customize the html elements in the resulting html safe string.\n * Each styles has priority over the base styles inherited.\n */\nexport type ConvertCommentBodyAsHtmlStyles = {\n /**\n * The default inline CSS styles used to display paragraphs.\n */\n paragraph: CSSProperties;\n /**\n * The default inline CSS styles used to display text `<strong />` elements.\n */\n strong: CSSProperties;\n /**\n * The default inline CSS styles used to display text `<code />` elements.\n */\n code: CSSProperties;\n /**\n * The default inline CSS styles used to display links.\n */\n mention: CSSProperties;\n /**\n * The default inline CSS styles used to display mentions.\n */\n link: CSSProperties;\n};\n\nconst baseStyles: ConvertCommentBodyAsHtmlStyles = {\n paragraph: {\n fontSize: \"14px\",\n },\n strong: {\n fontWeight: 500,\n },\n code: {\n fontFamily:\n 'ui-monospace, Menlo, Monaco, \"Cascadia Mono\", \"Segoe UI Mono\", \"Roboto Mono\", \"Oxygen Mono\", \"Ubuntu Mono\", \"Source Code Pro\", \"Fira Mono\", \"Droid Sans Mono\", \"Consolas\", \"Courier New\", monospace',\n backgroundColor: \"rgba(0,0,0,0.05)\",\n border: \"solid 1px rgba(0,0,0,0.1)\",\n borderRadius: \"4px\",\n },\n mention: {\n color: \"blue\",\n },\n link: {\n textDecoration: \"underline\",\n },\n};\n\nexport type PrepareThreadNotificationEmailAsHtmlOptions<\n U extends BaseUserMeta = DU,\n> = PrepareThreadNotificationEmailOptions<U> & {\n /**\n * The styles used to customize the html elements in the resulting html safe string inside a comment body.\n * Each styles has priority over the base styles inherited.\n */\n styles?: Partial<ConvertCommentBodyAsHtmlStyles>;\n};\n\nexport type ThreadNotificationEmailDataAsHtml<U extends BaseUserMeta = DU> =\n ThreadNotificationEmailData<string, U, CommentEmailAsHtmlData<U>>;\n\n/**\n * Prepares data from a `ThreadNotificationEvent` and convert comment bodies as an html safe string.\n *\n * @param client The `Liveblocks` node client\n * @param event The `ThreadNotificationEvent` received in the webhook handler\n * @param options The optional options to provide to resolve users, resolve room info\n * and customize comment bodies html elements styles with inline CSS.\n *\n * It returns a `ThreadNotificationEmailDataAsHtml` or `null` if there are no unread comments (mention or replies).\n *\n * @example\n * import { Liveblocks} from \"@liveblocks/node\"\n * import { prepareThreadNotificationEmailAsHtml } from \"@liveblocks/emails\"\n *\n * const liveblocks = new Liveblocks({ secret: \"sk_...\" })\n * const emailData = prepareThreadNotificationEmailAsHtml(\n * liveblocks,\n * event,\n * {\n * resolveUsers,\n * resolveRoomInfo,\n * styles,\n * }\n * )\n *\n */\nexport async function prepareThreadNotificationEmailAsHtml(\n client: Liveblocks,\n event: ThreadNotificationEvent,\n options: PrepareThreadNotificationEmailAsHtmlOptions<BaseUserMeta> = {}\n): Promise<ThreadNotificationEmailDataAsHtml | null> {\n const styles = { ...baseStyles, ...options?.styles };\n const data = await prepareThreadNotificationEmail<string, BaseUserMeta>(\n client,\n event,\n {\n resolveUsers: options.resolveUsers,\n resolveGroupsInfo: options.resolveGroupsInfo,\n resolveRoomInfo: options.resolveRoomInfo,\n },\n {\n container: ({ children }) => children.join(\"\\n\"),\n paragraph: ({ children }) => {\n const unsafe = children.join(\"\");\n // prettier-ignore\n return unsafe ? html`<p style=\"${toInlineCSSString(styles.paragraph)}\">${htmlSafe(unsafe)}</p>` : unsafe;\n },\n text: ({ element }) => {\n // Note: construction following the schema 👇\n // <code><s><em><strong>{element.text}</strong></s></em></code>\n let children = element.text;\n\n if (!children) {\n return html`${children}`;\n }\n\n if (element.bold) {\n // prettier-ignore\n children = html`<strong style=\"${toInlineCSSString(styles.strong)}\">${children}</strong>`;\n }\n\n if (element.italic) {\n // prettier-ignore\n children = html`<em>${children}</em>`;\n }\n\n if (element.strikethrough) {\n // prettier-ignore\n children = html`<s>${children}</s>`;\n }\n\n if (element.code) {\n // prettier-ignore\n children = html`<code style=\"${toInlineCSSString(styles.code)}\">${children}</code>`;\n }\n\n return html`${children}`;\n },\n link: ({ element, href }) => {\n // prettier-ignore\n return html`<a href=\"${href}\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"${toInlineCSSString(styles.link)}\">${element.text ? html`${element.text}` : element.url}</a>`;\n },\n mention: ({ element, user, group }) => {\n // prettier-ignore\n return html`<span data-mention style=\"${toInlineCSSString(styles.mention)}\">${MENTION_CHARACTER}${user?.name ? html`${user?.name}` : group?.name ? html`${group?.name}` : element.id}</span>`;\n },\n },\n \"prepareThreadNotificationEmailAsHtml\"\n );\n\n if (data === null) {\n return null;\n }\n\n return data;\n}\n\nexport type CommentBodyContainerComponentProps = {\n /**\n * The blocks of the comment body\n */\n children: ReactNode;\n};\n\nexport type CommentBodyParagraphComponentProps = {\n /**\n * The text content of the paragraph.\n */\n children: ReactNode;\n};\n\nexport type CommentBodyTextComponentProps = {\n /**\n * The text element.\n */\n element: CommentBodyText;\n};\n\nexport type CommentBodyLinkComponentProps = {\n /**\n * The link element.\n */\n element: CommentBodyLink;\n\n /**\n * The absolute URL of the link.\n */\n href: string;\n};\n\nexport type CommentBodyMentionComponentProps<U extends BaseUserMeta = DU> = {\n /**\n * The mention element.\n */\n element: CommentBodyMention;\n\n /**\n * The mention's user info, if the mention is a user mention and the `resolvedUsers` option was provided.\n */\n user?: U[\"info\"];\n\n /**\n * The mention's group info, if the mention is a group mention and the `resolvedGroupsInfo` option was provided.\n */\n group?: DGI;\n};\n\nexport type ConvertCommentBodyAsReactComponents<U extends BaseUserMeta = DU> = {\n /**\n *\n * The component used to act as a container to wrap comment body blocks,\n */\n Container: ComponentType<CommentBodyContainerComponentProps>;\n /**\n * The component used to display paragraphs.\n */\n Paragraph: ComponentType<CommentBodyParagraphComponentProps>;\n\n /**\n * The component used to display text elements.\n */\n Text: ComponentType<CommentBodyTextComponentProps>;\n\n /**\n * The component used to display links.\n */\n Link: ComponentType<CommentBodyLinkComponentProps>;\n\n /**\n * The component used to display mentions.\n */\n Mention: ComponentType<CommentBodyMentionComponentProps<U>>;\n};\n\nconst baseComponents: ConvertCommentBodyAsReactComponents<BaseUserMeta> = {\n Container: ({ children }) => <div>{children}</div>,\n Paragraph: ({ children }) => <p>{children}</p>,\n Text: ({ element }) => {\n // Note: construction following the schema 👇\n // <code><s><em><strong>{element.text}</strong></s></em></code>\n let children: ReactNode = element.text;\n\n if (element.bold) {\n children = <strong>{children}</strong>;\n }\n\n if (element.italic) {\n children = <em>{children}</em>;\n }\n\n if (element.strikethrough) {\n children = <s>{children}</s>;\n }\n\n if (element.code) {\n children = <code>{children}</code>;\n }\n\n return <span>{children}</span>;\n },\n Link: ({ element, href }) => (\n <a href={href} target=\"_blank\" rel=\"noopener noreferrer\">\n {element.text ?? element.url}\n </a>\n ),\n Mention: ({ element, user, group }) => (\n <span data-mention>\n {MENTION_CHARACTER}\n {user?.name ?? group?.name ?? element.id}\n </span>\n ),\n};\n\nexport type PrepareThreadNotificationEmailAsReactOptions<\n U extends BaseUserMeta = DU,\n> = PrepareThreadNotificationEmailOptions<U> & {\n /**\n * The components used to customize the resulting React nodes inside a comment body.\n * Each components has priority over the base components inherited internally defined.\n */\n components?: Partial<ConvertCommentBodyAsReactComponents<U>>;\n};\n\nexport type ThreadNotificationEmailDataAsReact<U extends BaseUserMeta = DU> =\n ThreadNotificationEmailData<ReactNode, U, CommentEmailAsReactData<U>>;\n\n/**\n * Prepares data from a `ThreadNotificationEvent` and convert comment bodies as React nodes.\n *\n * @param client The `Liveblocks` node client\n * @param event The `ThreadNotificationEvent` received in the webhook handler\n * @param options The optional options to provide to resolve users, resolve room info and customize comment bodies React components.\n *\n * It returns a `ThreadNotificationEmailDataAsReact` or `null` if there are no unread comments (mention or replies).\n *\n * @example\n * import { Liveblocks} from \"@liveblocks/node\"\n * import { prepareThreadNotificationEmailAsReact } from \"@liveblocks/emails\"\n *\n * const liveblocks = new Liveblocks({ secret: \"sk_...\" })\n * const emailData = prepareThreadNotificationEmailAsReact(\n * liveblocks,\n * event,\n * {\n * resolveUsers,\n * resolveRoomInfo,\n * components,\n * }\n * )\n *\n */\nexport async function prepareThreadNotificationEmailAsReact(\n client: Liveblocks,\n event: ThreadNotificationEvent,\n options: PrepareThreadNotificationEmailAsReactOptions<BaseUserMeta> = {}\n): Promise<ThreadNotificationEmailDataAsReact | null> {\n const Components = { ...baseComponents, ...options?.components };\n const data = await prepareThreadNotificationEmail<ReactNode, BaseUserMeta>(\n client,\n event,\n {\n resolveUsers: options.resolveUsers,\n resolveGroupsInfo: options.resolveGroupsInfo,\n resolveRoomInfo: options.resolveRoomInfo,\n },\n {\n container: ({ children }) => (\n <Components.Container key=\"lb-comment-body-container\">\n {children}\n </Components.Container>\n ),\n paragraph: ({ children }, index) => (\n <Components.Paragraph key={`lb-comment-body-paragraph-${index}`}>\n {children}\n </Components.Paragraph>\n ),\n text: ({ element }, index) => (\n <Components.Text\n key={`lb-comment-body-text-${index}`}\n element={element}\n />\n ),\n link: ({ element, href }, index) => (\n <Components.Link\n key={`lb-comment-body-link-${index}`}\n element={element}\n href={href}\n />\n ),\n mention: ({ element, user, group }, index) =>\n element.id ? (\n <Components.Mention\n key={`lb-comment-body-mention-${index}`}\n element={element}\n user={user}\n group={group}\n />\n ) : null,\n },\n \"prepareThreadNotificationEmailAsReact\"\n );\n\n if (data === null) {\n return null;\n }\n\n return data;\n}\n","import type {\n Awaitable,\n BaseUserMeta,\n CommentBody,\n CommentBodyLink,\n CommentBodyMention,\n CommentBodyParagraph,\n CommentBodyText,\n DGI,\n DU,\n ResolveGroupsInfoArgs,\n ResolveUsersArgs,\n} from \"@liveblocks/core\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n isCommentBodyText,\n resolveMentionsInCommentBody,\n sanitizeUrl,\n} from \"@liveblocks/core\";\n\nimport { exists } from \"./lib/utils\";\n\nexport type CommentBodyContainerElementArgs<T> = {\n /**\n * The blocks of the comment body\n */\n children: T[];\n};\n\nexport type CommentBodyParagraphElementArgs<T> = {\n /**\n * The paragraph element.\n */\n element: CommentBodyParagraph;\n /**\n * The text content of the paragraph.\n */\n children: T[];\n};\n\nexport type CommentBodyTextElementArgs = {\n /**\n * The text element.\n */\n element: CommentBodyText;\n};\n\nexport type CommentBodyLinkElementArgs = {\n /**\n * The link element.\n */\n element: CommentBodyLink;\n\n /**\n * The absolute URL of the link.\n */\n href: string;\n};\n\nexport type CommentBodyMentionElementArgs<U extends BaseUserMeta = DU> = {\n /**\n * The mention element.\n */\n element: CommentBodyMention;\n\n /**\n * The mention's user info, if the mention is a user mention and the `resolveUsers` option was provided.\n */\n user?: U[\"info\"];\n\n /**\n * The mention's group info, if the mention is a group mention and the `resolveGroupsInfo` option was provided.\n */\n group?: DGI;\n};\n\n/**\n * Protocol:\n * Comment body elements to be converted to a custom format `T`\n */\nexport type ConvertCommentBodyElements<T, U extends BaseUserMeta = DU> = {\n /**\n * The container element used to display comment body blocks.\n */\n container: (args: CommentBodyContainerElementArgs<T>) => T;\n /**\n * The paragraph element used to display paragraphs.\n */\n paragraph: (args: CommentBodyParagraphElementArgs<T>, index: number) => T;\n /**\n * The text element used to display text elements.\n */\n text: (args: CommentBodyTextElementArgs, index: number) => T;\n /**\n * The link element used to display links.\n */\n link: (args: CommentBodyLinkElementArgs, index: number) => T;\n /**\n * The mention element used to display mentions.\n */\n mention: (args: CommentBodyMentionElementArgs<U>, index: number) => T;\n};\n\nexport type ConvertCommentBodyOptions<T, U extends BaseUserMeta = DU> = {\n /**\n * A function that returns user info from user IDs.\n * You should return a list of user objects of the same size, in the same order.\n */\n resolveUsers?: (\n args: ResolveUsersArgs\n ) => Awaitable<(U[\"info\"] | undefined)[] | undefined>;\n\n /**\n * A function that returns group info from group IDs.\n * You should return a list of group info objects of the same size, in the same order.\n */\n resolveGroupsInfo?: (\n args: ResolveGroupsInfoArgs\n ) => Awaitable<(DGI | undefined)[] | undefined>;\n\n /**\n * The elements used to customize the resulting format `T`.\n */\n elements: ConvertCommentBodyElements<T, U>;\n};\n\n/**\n * Convert a `CommentBody` into a custom format `T`\n */\nexport async function convertCommentBody<T, U extends BaseUserMeta = DU>(\n body: CommentBody,\n options: ConvertCommentBodyOptions<T, U>\n): Promise<T> {\n const { users: resolvedUsers, groups: resolvedGroupsInfo } =\n await resolveMentionsInCommentBody(\n body,\n options?.resolveUsers,\n options?.resolveGroupsInfo\n );\n\n const blocks: T[] = body.content\n .map((block, index) => {\n switch (block.type) {\n case \"paragraph\": {\n const children: T[] = block.children\n .map((inline, inlineIndex) => {\n if (isCommentBodyMention(inline)) {\n return options.elements.mention(\n {\n element: inline,\n user:\n inline.kind === \"user\"\n ? resolvedUsers.get(inline.id)\n : undefined,\n group:\n inline.kind === \"group\"\n ? resolvedGroupsInfo.get(inline.id)\n : undefined,\n },\n inlineIndex\n );\n }\n\n if (isCommentBodyLink(inline)) {\n const href = sanitizeUrl(inline.url);\n\n // If the URL is invalid, its text/URL are used as plain text.\n if (href === null) {\n return options.elements.text(\n {\n element: { text: inline.text ?? inline.url },\n },\n inlineIndex\n );\n }\n\n return options.elements.link(\n {\n element: inline,\n href,\n },\n inlineIndex\n );\n }\n\n if (isCommentBodyText(inline)) {\n return options.elements.text({ element: inline }, inlineIndex);\n }\n\n return null;\n })\n .filter(exists);\n\n return options.elements.paragraph(\n { element: block, children },\n index\n );\n }\n default:\n console.warn(\n `Unsupported comment body block type: \"${JSON.stringify(block.type)}\"`\n );\n return null;\n }\n })\n .filter(exists);\n\n return options.elements.container({ children: blocks });\n}\n","import type { CommentBody, CommentData } from \"@liveblocks/core\";\n\nexport type CommentDataWithBody = Omit<CommentData, \"body\" | \"deletedAt\"> & {\n body: CommentBody;\n deletedAt?: never;\n};\n\nconst isCommentDataWithBody = (\n comment: CommentData\n): comment is CommentDataWithBody => {\n return comment.body !== undefined && comment.deletedAt === undefined;\n};\n\nexport function filterCommentsWithBody(\n comments: CommentData[]\n): CommentDataWithBody[] {\n const commentsWithBody: CommentDataWithBody[] = [];\n for (const comment of comments) {\n if (isCommentDataWithBody(comment)) {\n commentsWithBody.push(comment);\n }\n }\n return commentsWithBody;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-emails/dist/index.cjs","../src/index.ts","../src/version.ts","../src/text-mention-notification.tsx","../src/lexical-editor.ts","../../../node_modules/lib0/map.js","../../../node_modules/lib0/set.js","../../../node_modules/lib0/array.js","../../../node_modules/lib0/observable.js","../../../node_modules/lib0/math.js","../../../node_modules/lib0/binary.js","../../../node_modules/lib0/number.js","../../../node_modules/lib0/string.js","../../../node_modules/lib0/encoding.js","../../../node_modules/lib0/error.js","../../../node_modules/lib0/decoding.js","../../../node_modules/lib0/webcrypto.node.js","../../../node_modules/lib0/random.js","../../../node_modules/lib0/time.js","../../../node_modules/lib0/promise.js","../../../node_modules/lib0/conditions.js","../../../node_modules/lib0/storage.js","../../../node_modules/lib0/object.js","../../../node_modules/lib0/function.js","../../../node_modules/lib0/environment.js","../../../node_modules/lib0/buffer.js","../../../node_modules/lib0/symbol.js","../../../node_modules/lib0/logging.common.js","../../../node_modules/lib0/logging.node.js","../../../node_modules/lib0/iterator.js","../../../node_modules/yjs/src/utils/DeleteSet.js","../../../node_modules/yjs/src/utils/Doc.js","../../../node_modules/yjs/src/utils/UpdateDecoder.js","../../../node_modules/yjs/src/utils/UpdateEncoder.js","../../../node_modules/yjs/src/utils/encoding.js","../../../node_modules/yjs/src/utils/EventHandler.js","../../../node_modules/yjs/src/utils/ID.js","../../../node_modules/yjs/src/utils/Snapshot.js","../../../node_modules/yjs/src/utils/StructStore.js","../../../node_modules/yjs/src/utils/Transaction.js","../../../node_modules/yjs/src/utils/updates.js","../../../node_modules/yjs/src/utils/YEvent.js","../../../node_modules/yjs/src/types/AbstractType.js","../../../node_modules/yjs/src/types/YArray.js","../../../node_modules/yjs/src/types/YMap.js","../../../node_modules/yjs/src/types/YText.js","../../../node_modules/yjs/src/types/YXmlFragment.js","../../../node_modules/yjs/src/types/YXmlElement.js","../../../node_modules/yjs/src/types/YXmlEvent.js","../../../node_modules/yjs/src/types/YXmlHook.js","../../../node_modules/yjs/src/types/YXmlText.js","../../../node_modules/yjs/src/structs/AbstractStruct.js","../../../node_modules/yjs/src/structs/GC.js","../../../node_modules/yjs/src/structs/ContentBinary.js","../../../node_modules/yjs/src/structs/ContentDeleted.js","../../../node_modules/yjs/src/structs/ContentDoc.js","../../../node_modules/yjs/src/structs/ContentEmbed.js","../../../node_modules/yjs/src/structs/ContentFormat.js","../../../node_modules/yjs/src/structs/ContentJSON.js","../../../node_modules/yjs/src/structs/ContentAny.js","../../../node_modules/yjs/src/structs/ContentString.js","../../../node_modules/yjs/src/structs/ContentType.js","../../../node_modules/yjs/src/structs/Item.js","../../../node_modules/yjs/src/structs/Skip.js","../../../node_modules/yjs/src/index.js","../src/lib/utils.ts","../src/lib/batch-resolvers.ts","../src/lib/css-properties.ts","../src/tiptap-editor.ts","../../../node_modules/y-prosemirror/src/plugins/sync-plugin.js","../../../node_modules/y-prosemirror/src/lib.js","../src/liveblocks-text-editor.ts","../src/text-mention-content.tsx","../src/thread-notification.tsx","../src/comment-body.tsx","../src/comment-with-body.ts"],"names":["create","args","isNaN","struct","keys","length","id","html","htmlSafe","MENTION_CHARACTER","jsx"],"mappings":"AAAA;ACAA,wCAA4B;ADE5B;AACA;AEAO,IAAM,SAAA,EAAW,oBAAA;AACjB,IAAM,YAAA,EAAiD,QAAA;AACvD,IAAM,WAAA,EAAgD,KAAA;AFE7D;AACA;AGRA;AAME;AACA;AACA;AAAA;AHMF;AACA;AIdA;AJgBA;AACA;AKJO,IAAM,OAAA,EAAS,CAAA,EAAA,mBAAM,IAAI,GAAA,CAAI,CAAA;AAU7B,IAAM,KAAA,EAAO,CAAA,CAAA,EAAA,GAAK;AACvB,EAAA,MAAM,EAAA,EAAI,MAAA,CAAO,CAAA;AACjB,EAAA,CAAA,CAAE,OAAA,CAAQ,CAAC,CAAA,EAAG,CAAA,EAAA,GAAM;AAAE,IAAA,CAAA,CAAE,GAAA,CAAI,CAAA,EAAG,CAAC,CAAA;AAAA,EAAE,CAAC,CAAA;AACnC,EAAA,OAAO,CAAA;AACT,CAAA;AAkBO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ACnD,EAAA;A9CsiKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8CniKlE,EAAA;AACK,IAAA;AACnB,IAAA;AAAO,MAAA;A9CsiKyE;A8CtiKtC,MAAA;AAAc,IAAA;AACvC,IAAA;AAC1B,EAAA;AAEW,EAAA;AACgB,IAAA;AAC3B,EAAA;A9CwiKyF;AACA;AACA;AACA;AACA;AACA;AACA;A8CriK9E,EAAA;AACoB,IAAA;AAEsD,IAAA;AAC1E,IAAA;AACX,EAAA;AAEgB,EAAA;AACmB,qBAAA;AAC0C,IAAA;AAC7E,EAAA;A9CqiKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8CliK7D,EAAA;AACc,IAAA;AAC1C,EAAA;A9CoiKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8CjiKjE,EAAA;AACK,IAAA;AAEwD,IAAA;AACvD,IAAA;AACX,IAAA;AACN,MAAA;AACF,IAAA;AACO,MAAA;AAClB,IAAA;AACA,EAAA;A9CkiKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8C/hK9D,EAAA;AACE,IAAA;AAEyD,IAAA;AACtF,EAAA;A9CgiKyF;AACA;AACA;AACA;AACA;AACA;A8C7hK/C,EAAA;AAC2C,IAAA;AACrF,EAAA;A9C+hKyF;AACA;AACA;AACA;AACA;A8C5hK3E,EAAA;AAC6C,IAAA;AAC3D,EAAA;A9C8hKyF;AACA;AACA;A8C3hK7E,EAAA;AACY,IAAA;AACxB,EAAA;A9C6hKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8C1hKrC,EAAA;AACC,IAAA;AACtB,IAAA;AACgB,MAAA;AAC/C,IAAA;AACqC,IAAA;AACqC,MAAA;AACrE,IAAA;AACM,IAAA;AACX,EAAA;A9C4hKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8CzhK/D,EAAA;AACC,IAAA;AACa,MAAA;AACwB,QAAA;AACzD,MAAA;AACI,IAAA;AAE0C,MAAA;AACrD,IAAA;AACA,EAAA;A9C0hKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8CvhK5D,EAAA;AACF,IAAA;AACa,MAAA;AACmC,QAAA;AACJ,QAAA;AAChE,MAAA;AACI,IAAA;AACC,MAAA;A9CyhK6E;A8CzhKxC,QAAA;A9C2hKwC,MAAA;A8C1hKjB,MAAA;AACjC,MAAA;AACc,QAAA;AACrD,MAAA;AACoC,MAAA;AACpC,IAAA;AACA,EAAA;A9C4hKyF;AACA;AACA;AACA;AACA;AACA;A8CzhK5D,EAAA;AACF,IAAA;AACa,MAAA;AACe,QAAA;AAChD,MAAA;AACI,IAAA;AAEmC,MAAA;AAC9C,IAAA;AACA,EAAA;A9C0hKyF;AACA;AACA;AACA;AACA;A8CvhK5E,EAAA;AACkB,IAAA;AAC/B,EAAA;A9CyhKyF;AACA;AACA;AACA;AACA;A8CthKxE,EAAA;AACmB,IAAA;AACpC,EAAA;A9CwhKyF;AACA;AACA;AACA;AACA;A8CrhKrE,EAAA;AACM,IAAA;AAC1B,EAAA;A9CuhKyF;AACA;AACA;AACA;AACA;AACA;A8CphK3E,EAAA;AACoB,IAAA;AAClC,EAAA;A9CshKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8CnhKlD,EAAA;AACE,IAAA;AACzC,EAAA;A9CqhKyF;AACA;AACA;AACA;AACA;A8ClhK3E,EAAA;AACa,IAAA;AAC3B,EAAA;A9CohKyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A8CjhKtE,EAAA;AACuB,IAAA;AAC1C,EAAA;AACA;AAS4D;ACnad;AACP,EAAA;AAC9B,IAAA;AACW,IAAA;AAIW,IAAA;AAC/B,EAAA;A/C46KyF;AACA;AACA;A+Cz6KpE,EAAA;AACwB,IA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3B,IAAA;A/Cw6KqF;A+Cx6K5B,MAAA;A/C06K4B,IAAA;A+Cz6KzF,EAAA;A/C26KyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A+Cx6K1D,EAAA;AAC3B,IAAA;A/C06KqF;A+C16K5B,MAAA;A/C46K4B,IAAA;A+C36KzF,EAAA;A/C66KyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A+C16K9D,EAAA;AACvB,IAAA;A/C46KqF;A+C56KW,MAAA;A/C86KX,IAAA;A+C76KzF,EAAA;A/C+6KyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A+C56KrC,EAAA;AACC,IAAA;AACjB,IAAA;AACP,IAAA;AACA,MAAA;AACQ,MAAA;AACF,QAAA;AACnC,MAAA;AACA,IAAA;AACkC,IAAA;AACyB,MAAA;AACtD,IAAA;AAC0B,IAAA;AACW,MAAA;AAC1C,IAAA;AACW,IAAA;AACX,EAAA;A/C86KyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A+C36KtE,EAAA;AACsB,IAAA;AACP,IAAA;AAClC,EAAA;AACA;AAQ2E;AC5PrC;AhDmqLmD;AACA;AACA;AACA;AACA;AACA;AACA;AgDjqL/C,EAAA;AACb,IAAA;AAMD,IAAA;AAKQ,IAAA;AACV,IAAA;AACF,MAAA;AACQ,QAAA;AACnB,MAAA;AACyB,QAAA;AACtC,MAAA;AACK,IAAA;AACL,EAAA;AACA;AC3BmC;AjDsrLsD;AACA;AACA;AiDprLhE,EAAA;AAChB,IAAA;AAIW,IAAA;AACpB,EAAA;AjDmrLyF;AACA;AACA;AiDhrL9E,EAAA;AAC0B,IAAA;AACrC,EAAA;AjDkrLyF;AACA;AACA;AACA;AACA;AACA;AACA;AiD/qL9E,EAAA;AAC8B,IAAA;AACR,IAAA;AACV,MAAA;AAClB,IAAA;AACM,IAAA;AACX,EAAA;AjDirLyF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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ACY,IAAA;AACxB,EAAA;AlD4vLyF;AACA;AACA;AkDzvLtE,EAAA;AACmB,IAAA;AACtC,EAAA;AACA;AASmD;ACrHvB;AnDy2L6D;AACA;AACA;AACA;AmDv2L9D,EAAA;AACbC,IAAAA;AACID,IAAAA;AAClB,EAAA;AnDy2LyF;AACA;AACA;AmDt2LxE,EAAA;AACkB,IAAA;AACnC,EAAA;AnDw2LyF;AACA;AACA;AACA;AACA;AACA;AACA;AmDr2LrE,EAAA;AACT,IAAA;AACX,EAAA;AnDu2LyF;AACA;AACA;AACA;AACA;AmDp2LlD,EAAA;AACJ,IAAA;AACnC,EAAA;AnDs2LyF;AACA;AACA;AACA;AmDn2LvD,EAAA;AACC,IAAA;AACnC,EAAA;AACA;AC5CiC;AAKM;AACtB,EAAA;AACN,IAAA;AACX,EAAA;AAEY,EAAA;AAAA,EAAA;ApD84L6E;AACA;AACA;AACA;AoD34LrE,EAAA;AAC4B,IAAA;AACnC,MAAA;AACb,IAAA;AACyB,IAAA;AACd,IAAA;AACX,EAAA;ApD64LyF;AACA;AACA;AACA;AoD14LvD,EAAA;AACd,IAAA;AACG,MAAA;AACF,MAAA;AACrB,IAAA;AACyC,IAAA;AACzC,EAAA;ApD44LyF;AACA;AACA;AACA;AoDz4L/D,EAAA;AACa,IAAA;AACE,IAAA;AACzC,EAAA;ApD24LyF;AACA;AACA;AACA;AACA;AoDx4LvD,EAAA;AACvB,IAAA;AACX,EAAA;AACA;ACrD2B;ArDg8L8D;AACA;AACA;AqD97LjE,EAAA;AACL,IAAA;AACnB,EAAA;ArDg8LyF;AACA;AACA;AqD77L1E,EAAA;AACJ,IAAA;AACX,EAAA;ArD+7LyF;AACA;AACA;AqD57LzE,EAAA;AACQ,IAAA;AACxB,EAAA;ArD87LyF;AACA;AACA;AqD37LxE,EAAA;AACN,IAAA;AACX,EAAA;ArD67LyF;AACA;AACA;AqD17L/E,EAAA;AAC+B,IAAA;AACzC,EAAA;ArD47LyF;AACA;AACA;AACA;AqDz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AA,QAAA;AAFkC,QAAA;AAGpC,MAAA;AAIEA,MAAAA;AAAY,QAAA;AAAX,QAAA;AAEC,UAAA;AACA,UAAA;AACA,UAAA;AAAA,QAAA;AAHqC,QAAA;AAKrC,MAAA;AACR,IAAA;AACA,IAAA;AACF,EAAA;AAEmB,EAAA;AACV,IAAA;AACT,EAAA;AAEO,EAAA;AACT;AzEk6PyF;AACA;AC5rR5C;AD8rR4C;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/liveblocks/liveblocks/packages/liveblocks-emails/dist/index.cjs","sourcesContent":[null,"import { detectDupes } from \"@liveblocks/core\";\n\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type { ResolveRoomInfoArgs } from \"./lib/types\";\nexport type {\n ConvertTextEditorNodesAsHtmlStyles,\n ConvertTextEditorNodesAsReactComponents,\n MentionEmailAsHtmlData,\n MentionEmailAsReactData,\n PrepareTextMentionNotificationEmailAsHtmlOptions,\n PrepareTextMentionNotificationEmailAsReactOptions,\n TextEditorContainerComponentProps,\n TextEditorMentionComponentProps,\n TextEditorTextComponentProps,\n TextMentionNotificationEmailDataAsHtml,\n TextMentionNotificationEmailDataAsReact,\n} from \"./text-mention-notification\";\nexport {\n prepareTextMentionNotificationEmailAsHtml,\n prepareTextMentionNotificationEmailAsReact,\n} from \"./text-mention-notification\";\nexport type {\n CommentBodyContainerComponentProps,\n CommentBodyLinkComponentProps,\n CommentBodyMentionComponentProps,\n CommentBodyParagraphComponentProps,\n CommentBodyTextComponentProps,\n CommentEmailAsHtmlData,\n CommentEmailAsReactData,\n ConvertCommentBodyAsHtmlStyles,\n ConvertCommentBodyAsReactComponents,\n PrepareThreadNotificationEmailAsHtmlOptions,\n PrepareThreadNotificationEmailAsReactOptions,\n ThreadNotificationEmailDataAsHtml,\n ThreadNotificationEmailDataAsReact,\n} from \"./thread-notification\";\nexport {\n prepareThreadNotificationEmailAsHtml,\n prepareThreadNotificationEmailAsReact,\n} from \"./thread-notification\";\nexport type { ResolveGroupsInfoArgs, ResolveUsersArgs } from \"@liveblocks/core\";\n","declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/emails\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n","import {\n type Awaitable,\n type BaseUserMeta,\n type DGI,\n type DRI,\n type DU,\n html,\n htmlSafe,\n MENTION_CHARACTER,\n type MentionData,\n type ResolveGroupsInfoArgs,\n type ResolveUsersArgs,\n} from \"@liveblocks/core\";\nimport type {\n Liveblocks,\n TextMentionNotificationEvent,\n} from \"@liveblocks/node\";\nimport type { ComponentType, ReactNode } from \"react\";\n\nimport type { LexicalMentionNodeWithContext } from \"./lexical-editor\";\nimport {\n findLexicalMentionNodeWithContext,\n getMentionDataFromLexicalNode,\n getSerializedLexicalState,\n} from \"./lexical-editor\";\nimport {\n createBatchGroupsInfoResolver,\n createBatchUsersResolver,\n getResolvedForId,\n} from \"./lib/batch-resolvers\";\nimport type { CSSProperties } from \"./lib/css-properties\";\nimport { toInlineCSSString } from \"./lib/css-properties\";\nimport type { ResolveRoomInfoArgs } from \"./lib/types\";\nimport type {\n LiveblocksTextEditorMentionNode,\n LiveblocksTextEditorNode,\n LiveblocksTextEditorTextNode,\n} from \"./liveblocks-text-editor\";\nimport { transformAsLiveblocksTextEditorNodes } from \"./liveblocks-text-editor\";\nimport {\n convertTextMentionContent,\n type ConvertTextMentionContentElements,\n} from \"./text-mention-content\";\nimport type { TiptapMentionNodeWithContext } from \"./tiptap-editor\";\nimport {\n findTiptapMentionNodeWithContext,\n getMentionDataFromTiptapNode,\n getSerializedTiptapState,\n} from \"./tiptap-editor\";\n\n/** @internal hidden types */\ntype RoomTextEditor = {\n type: \"lexical\" | \"tiptap\";\n rootKey: string[];\n};\n\nexport type TextMentionNotificationData = (\n | {\n editor: \"lexical\";\n mentionNodeWithContext: LexicalMentionNodeWithContext;\n }\n | {\n editor: \"tiptap\";\n mentionNodeWithContext: TiptapMentionNodeWithContext;\n }\n) & {\n createdAt: Date;\n createdBy: string;\n mentionData: MentionData;\n};\n\n/** @internal */\nexport const extractTextMentionNotificationData = async ({\n client,\n event,\n}: {\n client: Liveblocks;\n event: TextMentionNotificationEvent;\n}): Promise<TextMentionNotificationData | null> => {\n const { roomId, userId, inboxNotificationId } = event.data;\n\n const [room, inboxNotification] = await Promise.all([\n client.getRoom(roomId),\n client.getInboxNotification({ inboxNotificationId, userId }),\n ]);\n\n // Check for notification kind\n if (inboxNotification.kind !== \"textMention\") {\n console.warn('Inbox notification is not of kind \"textMention\"');\n return null;\n }\n\n // Aligned behaviors w/ `@liveblocks/react-ui`.\n const isUnread =\n inboxNotification.readAt === null ||\n inboxNotification.notifiedAt > inboxNotification.readAt;\n\n // Notification read so do nothing\n if (!isUnread) {\n return null;\n }\n\n // Do nothing if the room as no text editor associated.\n // We do not throw not to impact the final developer experience.\n // @ts-expect-error - Hidden property\n const textEditor = room.experimental_textEditor as RoomTextEditor | undefined;\n if (!textEditor) {\n console.warn(`Room \"${room.id}\" does not a text editor associated with it`);\n return null;\n }\n\n // For now we use the `notifiedAt` inbox notification data\n // to represent the creation date as we have currently\n // a 1 - 1 notification <> activity\n const mentionCreatedAt = inboxNotification.notifiedAt;\n // In context of a text mention notification `createdBy` is a user ID\n const mentionAuthorUserId = inboxNotification.createdBy;\n\n const buffer = await client.getYjsDocumentAsBinaryUpdate(roomId);\n const editorKey = textEditor.rootKey;\n // TODO: temporarily grab the first entrance, later we will handle multiple editors\n const key = Array.isArray(editorKey) ? editorKey[0]! : editorKey;\n\n switch (textEditor.type) {\n case \"lexical\": {\n const state = getSerializedLexicalState({ buffer, key });\n const mentionNodeWithContext = findLexicalMentionNodeWithContext({\n root: state,\n textMentionId: inboxNotification.mentionId,\n });\n\n // The mention node did not exists so we do not have to send an email.\n if (mentionNodeWithContext === null) {\n return null;\n }\n\n const mentionData = getMentionDataFromLexicalNode(\n mentionNodeWithContext.mention\n );\n\n return {\n editor: \"lexical\",\n mentionNodeWithContext,\n mentionData,\n createdAt: mentionCreatedAt,\n createdBy: mentionAuthorUserId,\n };\n }\n case \"tiptap\": {\n const state = getSerializedTiptapState({ buffer, key });\n const mentionNodeWithContext = findTiptapMentionNodeWithContext({\n root: state,\n textMentionId: inboxNotification.mentionId,\n });\n\n // The mention node did not exists so we do not have to send an email.\n if (mentionNodeWithContext === null) {\n return null;\n }\n\n const mentionData = getMentionDataFromTiptapNode(\n mentionNodeWithContext.mention\n );\n\n return {\n editor: \"tiptap\",\n mentionNodeWithContext,\n mentionData,\n createdAt: mentionCreatedAt,\n createdBy: mentionAuthorUserId,\n };\n }\n }\n};\n\nexport type MentionEmailData<\n ContentType,\n U extends BaseUserMeta = DU,\n> = MentionData & {\n textMentionId: string;\n roomId: string;\n author: U; // Author of the mention\n createdAt: Date;\n content: ContentType;\n};\n\nexport type MentionEmailAsHtmlData<U extends BaseUserMeta = DU> =\n MentionEmailData<string, U>;\n\nexport type MentionEmailAsReactData<U extends BaseUserMeta = DU> =\n MentionEmailData<ReactNode, U>;\n\nexport type TextMentionNotificationEmailData<\n ContentType,\n U extends BaseUserMeta = DU,\n M extends MentionEmailData<ContentType, U> = MentionEmailData<ContentType, U>,\n> = {\n mention: M;\n roomInfo: DRI;\n};\n\ntype PrepareTextMentionNotificationEmailOptions<U extends BaseUserMeta = DU> = {\n /**\n * A function that returns room info from room IDs.\n */\n resolveRoomInfo?: (args: ResolveRoomInfoArgs) => Awaitable<DRI | undefined>;\n\n /**\n * A function that returns user info from user IDs.\n * You should return a list of user objects of the same size, in the same order.\n */\n resolveUsers?: (\n args: ResolveUsersArgs\n ) => Awaitable<(U[\"info\"] | undefined)[] | undefined>;\n\n /**\n * A function that returns group info from group IDs.\n * You should return a list of group info objects of the same size, in the same order.\n */\n resolveGroupsInfo?: (\n args: ResolveGroupsInfoArgs\n ) => Awaitable<(DGI | undefined)[] | undefined>;\n};\n\n/**\n * @internal\n * exported for testing purposes.\n */\nexport async function prepareTextMentionNotificationEmail<\n ContentType,\n U extends BaseUserMeta = DU,\n>(\n client: Liveblocks,\n event: TextMentionNotificationEvent,\n options: PrepareTextMentionNotificationEmailOptions<U>,\n elements: ConvertTextMentionContentElements<ContentType, U>,\n callerName: string\n): Promise<TextMentionNotificationEmailData<ContentType, U> | null> {\n const { roomId, mentionId } = event.data;\n\n const data = await extractTextMentionNotificationData({ client, event });\n if (data === null) {\n return null;\n }\n\n const roomInfo = options.resolveRoomInfo\n ? await options.resolveRoomInfo({ roomId: event.data.roomId })\n : undefined;\n\n const resolvedRoomInfo: DRI = {\n ...roomInfo,\n name: roomInfo?.name ?? event.data.roomId,\n };\n\n const batchUsersResolver = createBatchUsersResolver<U>({\n resolveUsers: options.resolveUsers,\n callerName,\n });\n const batchGroupsInfoResolver = createBatchGroupsInfoResolver({\n resolveGroupsInfo: options.resolveGroupsInfo,\n callerName,\n });\n\n const authorsIds = [data.createdBy];\n const authorsInfoPromise = batchUsersResolver.get(authorsIds);\n\n let textEditorNodes: LiveblocksTextEditorNode[] = [];\n\n switch (data.editor) {\n case \"lexical\": {\n textEditorNodes = transformAsLiveblocksTextEditorNodes({\n editor: \"lexical\",\n mention: data.mentionNodeWithContext,\n });\n break;\n }\n case \"tiptap\": {\n textEditorNodes = transformAsLiveblocksTextEditorNodes({\n editor: \"tiptap\",\n mention: data.mentionNodeWithContext,\n });\n break;\n }\n }\n\n const contentPromise = convertTextMentionContent<ContentType, U>(\n textEditorNodes,\n {\n resolveUsers: ({ userIds }) => batchUsersResolver.get(userIds),\n resolveGroupsInfo: ({ groupIds }) =>\n batchGroupsInfoResolver.get(groupIds),\n elements,\n }\n );\n\n await batchUsersResolver.resolve();\n await batchGroupsInfoResolver.resolve();\n\n const [authorsInfo, content] = await Promise.all([\n authorsInfoPromise,\n contentPromise,\n ]);\n\n const authorInfo = getResolvedForId(data.createdBy, authorsIds, authorsInfo);\n\n return {\n mention: {\n ...data.mentionData,\n textMentionId: mentionId,\n roomId,\n author: {\n id: data.createdBy,\n info: authorInfo ?? { name: data.createdBy },\n } as U,\n content,\n createdAt: data.createdAt,\n },\n roomInfo: resolvedRoomInfo,\n };\n}\n\nexport type TextEditorContainerComponentProps = {\n /**\n * The nodes of the text editor\n */\n children: ReactNode;\n};\n\nexport type TextEditorMentionComponentProps<U extends BaseUserMeta = DU> = {\n /**\n * The mention element.\n */\n element: LiveblocksTextEditorMentionNode;\n\n /**\n * The mention's user info, if the mention is a user mention and the `resolvedUsers` option was provided.\n */\n user?: U[\"info\"];\n\n /**\n * The mention's group info, if the mention is a group mention and the `resolvedGroupsInfo` option was provided.\n */\n group?: DGI;\n};\n\nexport type TextEditorTextComponentProps = {\n /**\n * The text element.\n */\n element: LiveblocksTextEditorTextNode;\n};\n\nexport type ConvertTextEditorNodesAsReactComponents<\n U extends BaseUserMeta = DU,\n> = {\n /**\n *\n * The component used to act as a container to wrap text editor nodes,\n */\n Container: ComponentType<TextEditorContainerComponentProps>;\n\n /**\n * The component used to display mentions.\n */\n Mention: ComponentType<TextEditorMentionComponentProps<U>>;\n\n /**\n * The component used to display text nodes.\n */\n Text: ComponentType<TextEditorTextComponentProps>;\n};\n\nconst baseComponents: ConvertTextEditorNodesAsReactComponents<BaseUserMeta> = {\n Container: ({ children }) => <div>{children}</div>,\n Mention: ({ element, user, group }) => (\n <span data-mention>\n {MENTION_CHARACTER}\n {user?.name ?? group?.name ?? element.id}\n </span>\n ),\n Text: ({ element }) => {\n // Note: construction following the schema 👇\n // <code><s><em><strong>{element.text}</strong></s></em></code>\n let children: ReactNode = element.text;\n\n if (element.bold) {\n children = <strong>{children}</strong>;\n }\n\n if (element.italic) {\n children = <em>{children}</em>;\n }\n\n if (element.strikethrough) {\n children = <s>{children}</s>;\n }\n\n if (element.code) {\n children = <code>{children}</code>;\n }\n\n return <span>{children}</span>;\n },\n};\n\nexport type PrepareTextMentionNotificationEmailAsReactOptions<\n U extends BaseUserMeta = DU,\n> = PrepareTextMentionNotificationEmailOptions & {\n /**\n * The components used to customize the resulting React nodes. Each components has\n * priority over the base components inherited.\n */\n components?: Partial<ConvertTextEditorNodesAsReactComponents<U>>;\n};\n\nexport type TextMentionNotificationEmailDataAsReact<\n U extends BaseUserMeta = DU,\n> = TextMentionNotificationEmailData<ReactNode, U, MentionEmailAsReactData<U>>;\n\n/**\n * Prepares data from a `TextMentionNotificationEvent` and convert content as React nodes.\n *\n * @param client The `Liveblocks` node client\n * @param event The `TextMentionNotificationEvent` received in the webhook handler\n * @param options The optional options to provide to resolve users, resolve room info and customize comment bodies React components.\n *\n * It returns a `TextMentionNotificationEmailDataAsReact` or `null` if there are no existing text mention.\n *\n * @example\n * import { Liveblocks} from \"@liveblocks/node\"\n * import { prepareTextMentionNotificationEmailAsReact } from \"@liveblocks/emails\"\n *\n * const liveblocks = new Liveblocks({ secret: \"sk_...\" })\n * const emailData = prepareTextMentionNotificationEmailAsReact(\n * liveblocks,\n * event,\n * {\n * resolveUsers,\n * resolveRoomInfo,\n * components,\n * }\n * )\n */\nexport async function prepareTextMentionNotificationEmailAsReact(\n client: Liveblocks,\n event: TextMentionNotificationEvent,\n options: PrepareTextMentionNotificationEmailAsReactOptions<BaseUserMeta> = {}\n): Promise<TextMentionNotificationEmailDataAsReact | null> {\n const Components = { ...baseComponents, ...options.components };\n const data = await prepareTextMentionNotificationEmail<\n ReactNode,\n BaseUserMeta\n >(\n client,\n event,\n {\n resolveRoomInfo: options.resolveRoomInfo,\n resolveUsers: options.resolveUsers,\n },\n {\n container: ({ children }) => (\n <Components.Container key=\"lb-text-editor-container\">\n {children}\n </Components.Container>\n ),\n mention: ({ node, user }, index) => (\n <Components.Mention\n key={`lb-text-editor-mention-${index}`}\n element={node}\n user={user}\n />\n ),\n text: ({ node }, index) => (\n <Components.Text key={`lb-text-editor-text-${index}`} element={node} />\n ),\n },\n \"prepareTextMentionNotificationEmailAsReact\"\n );\n\n if (data === null) {\n return null;\n }\n\n return data;\n}\n\nexport type ConvertTextEditorNodesAsHtmlStyles = {\n /**\n * The default inline CSS styles used to display container element.\n */\n container: CSSProperties;\n /**\n * The default inline CSS styles used to display text `<strong />` elements.\n */\n strong: CSSProperties;\n /**\n * The default inline CSS styles used to display text `<code />` elements.\n */\n code: CSSProperties;\n /**\n * The default inline CSS styles used to display mentions.\n */\n mention: CSSProperties;\n};\n\nexport const baseStyles: ConvertTextEditorNodesAsHtmlStyles = {\n container: {\n fontSize: \"14px\",\n },\n strong: {\n fontWeight: 500,\n },\n code: {\n fontFamily:\n 'ui-monospace, Menlo, Monaco, \"Cascadia Mono\", \"Segoe UI Mono\", \"Roboto Mono\", \"Oxygen Mono\", \"Ubuntu Mono\", \"Source Code Pro\", \"Fira Mono\", \"Droid Sans Mono\", \"Consolas\", \"Courier New\", monospace',\n backgroundColor: \"rgba(0,0,0,0.05)\",\n border: \"solid 1px rgba(0,0,0,0.1)\",\n borderRadius: \"4px\",\n },\n mention: {\n color: \"blue\",\n },\n};\n\nexport type PrepareTextMentionNotificationEmailAsHtmlOptions =\n PrepareTextMentionNotificationEmailOptions & {\n /**\n * The styles used to customize the html elements in the resulting html safe string.\n * Each styles has priority over the base styles inherited.\n */\n styles?: Partial<ConvertTextEditorNodesAsHtmlStyles>;\n };\n\nexport type TextMentionNotificationEmailDataAsHtml<\n U extends BaseUserMeta = DU,\n> = TextMentionNotificationEmailData<string, U, MentionEmailAsHtmlData<U>>;\n\n/**\n * Prepares data from a `TextMentionNotificationEvent` and convert content as an html safe string.\n *\n * @param client The `Liveblocks` node client\n * @param event The `TextMentionNotificationEvent` received in the webhook handler\n * @param options The optional options to provide to resolve users, resolve room info and customize comment bodies React components.\n *\n * It returns a `TextMentionNotificationEmailDataAsReact` or `null` if there are no existing text mention.\n *\n * @example\n * import { Liveblocks} from \"@liveblocks/node\"\n * import { prepareTextMentionNotificationEmailAsHtml } from \"@liveblocks/emails\"\n *\n * const liveblocks = new Liveblocks({ secret: \"sk_...\" })\n * const emailData = prepareTextMentionNotificationEmailAsHtml(\n * liveblocks,\n * event,\n * {\n * resolveUsers,\n * resolveRoomInfo,\n * styles,\n * }\n * )\n */\nexport async function prepareTextMentionNotificationEmailAsHtml(\n client: Liveblocks,\n event: TextMentionNotificationEvent,\n options: PrepareTextMentionNotificationEmailAsHtmlOptions = {}\n): Promise<TextMentionNotificationEmailDataAsHtml | null> {\n const styles = { ...baseStyles, ...options.styles };\n const data = await prepareTextMentionNotificationEmail<string, BaseUserMeta>(\n client,\n event,\n {\n resolveRoomInfo: options.resolveRoomInfo,\n resolveUsers: options.resolveUsers,\n },\n {\n container: ({ children }) => {\n const content = [\n // prettier-ignore\n html`<div style=\"${toInlineCSSString(styles.container)}\">${htmlSafe(children.join(\"\"))}</div>`,\n ];\n\n return content.join(\"\\n\"); //NOTE: to represent a valid HTML string\n },\n mention: ({ node, user, group }) => {\n // prettier-ignore\n return html`<span data-mention style=\"${toInlineCSSString(styles.mention)}\">${MENTION_CHARACTER}${user?.name ? html`${user?.name}` : group?.name ? html`${group?.name}` : node.id}</span>`\n },\n text: ({ node }) => {\n // Note: construction following the schema 👇\n // <code><s><em><strong>{node.text}</strong></s></em></code>\n let children = node.text;\n if (!children) {\n return html`${children}`;\n }\n\n if (node.bold) {\n // prettier-ignore\n children = html`<strong style=\"${toInlineCSSString(styles.strong)}\">${children}</strong>`;\n }\n\n if (node.italic) {\n // prettier-ignore\n children = html`<em>${children}</em>`;\n }\n\n if (node.strikethrough) {\n // prettier-ignore\n children = html`<s>${children}</s>`;\n }\n\n if (node.code) {\n // prettier-ignore\n children = html`<code style=\"${toInlineCSSString(styles.code)}\">${children}</code>`;\n }\n\n return html`${children}`;\n },\n },\n \"prepareTextMentionNotificationEmailAsHtml\"\n );\n\n if (data === null) {\n return null;\n }\n\n return data;\n}\n","import type { Json, JsonObject, MentionData } from \"@liveblocks/core\";\nimport { assertNever } from \"@liveblocks/core\";\nimport * as Y from \"yjs\";\n\nimport { isMentionNodeAttributeId, isString } from \"./lib/utils\";\n\nexport interface SerializedBaseLexicalNode {\n type: string;\n attributes: JsonObject;\n}\n\nexport interface SerializedLexicalTextNode extends SerializedBaseLexicalNode {\n text: string;\n group: \"text\";\n}\n\nexport interface SerializedLexicalElementNode<\n T extends SerializedBaseLexicalNode,\n> extends SerializedBaseLexicalNode {\n children: Array<T>;\n group: \"element\";\n}\n\nexport interface SerializedLexicalDecoratorNode\n extends SerializedBaseLexicalNode {\n group: \"decorator\";\n}\n\nexport interface SerializedLexicalMentionNode\n extends SerializedLexicalDecoratorNode {\n type: \"lb-mention\";\n attributes: {\n __id: string;\n __type: \"lb-mention\";\n __userId: string;\n };\n}\n\nexport interface SerializedLexicalGroupMentionNode\n extends SerializedLexicalDecoratorNode {\n type: \"lb-group-mention\";\n attributes: {\n __id: string;\n __type: \"lb-group-mention\";\n __groupId: string;\n __userIds: string[] | undefined;\n };\n}\n\nexport interface SerializedLexicalLineBreakNode\n extends SerializedBaseLexicalNode {\n group: \"linebreak\";\n}\n\nexport type SerializedLexicalNode =\n | SerializedLexicalTextNode\n | SerializedLexicalLineBreakNode\n | SerializedLexicalDecoratorNode\n | SerializedLexicalElementNode<SerializedLexicalNode>;\n\nexport type SerializedLexicalRootNodeChildren = Array<\n Readonly<\n | SerializedLexicalElementNode<Readonly<SerializedLexicalNode>>\n | SerializedLexicalDecoratorNode\n | SerializedLexicalLineBreakNode\n >\n>;\n\nexport interface SerializedLexicalRootNode\n extends Readonly<SerializedBaseLexicalNode> {\n readonly type: \"root\";\n readonly children: SerializedLexicalRootNodeChildren;\n}\n\n/**\n * Create a serialized Lexical Map node.\n * Y.Map shared types are used to represent text nodes and line break nodes in Lexical.js\n */\nfunction createSerializedLexicalMapNode(\n item: Y.Map<Json>\n): SerializedLexicalTextNode | SerializedLexicalLineBreakNode {\n const type = item.get(\"__type\");\n if (typeof type !== \"string\") {\n throw new Error(\n `Expected ${item.constructor.name} to include type attribute`\n );\n }\n\n // Y.Map in Lexical stores all attributes defined in Lexical TextNode and LineBreakNode class.\n const attributes = Object.fromEntries(item.entries());\n if (type === \"linebreak\") {\n return {\n type,\n attributes,\n group: \"linebreak\",\n };\n }\n\n return {\n type,\n attributes,\n text: \"\",\n group: \"text\",\n };\n}\n\n/**\n * Create a serialized Lexical decorator node.\n * Y.XmlElement shared types are used to represent decorator nodes in Lexical.js\n */\nfunction createSerializedLexicalDecoratorNode(\n item: Y.XmlElement\n): SerializedLexicalDecoratorNode {\n const type = item.getAttribute(\"__type\");\n if (typeof type !== \"string\") {\n throw new Error(\n `Expected ${item.constructor.name} to include type attribute`\n );\n }\n const attributes = item.getAttributes();\n\n return {\n type,\n attributes,\n group: \"decorator\",\n };\n}\n\n/**\n * Create a serialized Lexical element node.\n * Y.XmlText shared types are used to represent element nodes (e.g. paragraph, blockquote) in Lexical.js\n */\nfunction createSerializedLexicalElementNode(\n item: Y.XmlText\n): SerializedLexicalElementNode<SerializedLexicalNode> {\n // Note: disabling eslint rule as `getAttribute` returns `any` by default on `Y.XmlText` items.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const type = item.getAttribute(\"__type\");\n if (typeof type !== \"string\") {\n throw new Error(\n `Expected ${item.constructor.name} to include type attribute`\n );\n }\n const attributes = item.getAttributes();\n\n let start = item._start;\n const children: SerializedLexicalNode[] = [];\n while (start !== null) {\n // If the item is deleted, skip it.\n if (start.deleted) {\n start = start.right;\n continue;\n }\n\n if (start.content instanceof Y.ContentType) {\n const content = start.content.type as Y.AbstractType<Json>;\n if (content instanceof Y.XmlText) {\n children.push(createSerializedLexicalElementNode(content));\n } else if (content instanceof Y.Map) {\n children.push(createSerializedLexicalMapNode(content as Y.Map<Json>));\n } else if (content instanceof Y.XmlElement) {\n children.push(\n createSerializedLexicalDecoratorNode(content as Y.XmlElement)\n );\n }\n }\n // ContentString is used to store text content of a text node in the Y.js doc.\n else if (start.content instanceof Y.ContentString) {\n if (children.length > 0) {\n const last = children[children.length - 1];\n if (last && last.group === \"text\") {\n last.text += start.content.str;\n }\n }\n }\n\n start = start.right;\n }\n\n return {\n type,\n attributes,\n children,\n group: \"element\",\n };\n}\n\n/**\n * Create a serialized Lexical root node.\n */\nexport function createSerializedLexicalRootNode(\n root: Y.XmlText\n): SerializedLexicalRootNode {\n try {\n const children: Array<\n | SerializedLexicalElementNode<SerializedLexicalNode>\n | SerializedLexicalDecoratorNode\n > = [];\n let start = root._start;\n while (start !== null && start !== undefined) {\n // If the item is deleted, skip it.\n if (start.deleted) {\n start = start.right;\n continue;\n }\n\n if (start.content instanceof Y.ContentType) {\n const content = start.content.type as Y.AbstractType<Json>;\n\n // Immediate children of root must be XmlText (element nodes) or XmlElement (decorator nodes).\n if (content instanceof Y.XmlText) {\n children.push(createSerializedLexicalElementNode(content));\n } else if (content instanceof Y.XmlElement) {\n children.push(\n createSerializedLexicalDecoratorNode(content as Y.XmlElement)\n );\n }\n }\n\n start = start.right;\n }\n\n return {\n children,\n type: \"root\",\n attributes: root.getAttributes(),\n };\n } catch (err) {\n console.error(err);\n return {\n children: [],\n type: \"root\",\n attributes: root.getAttributes(),\n };\n }\n}\n\n/**\n * Convert a document as binaries to a\n * serialized lexical state\n */\nexport function getSerializedLexicalState({\n buffer,\n key,\n}: {\n buffer: ArrayBuffer;\n key: string;\n}): SerializedLexicalRootNode {\n const update = new Uint8Array(buffer);\n\n // Construct a Y.js document from the binary update\n const document = new Y.Doc();\n Y.applyUpdate(document, update);\n\n // Convert the Y.js document to a serializable Lexical state\n const root = document.get(key, Y.XmlText);\n const state = createSerializedLexicalRootNode(root);\n\n // Destroy the Y.js document after the conversion\n document.destroy();\n\n return state;\n}\n\n/**\n * Linebreaks in the `Lexical` world are equivalent to\n * hard breaks (like we can have in `tiptap`).\n * They are created by using keys like `shift+enter` or `mod+enter`.\n */\nconst isSerializedLineBreakNode = (\n node: SerializedLexicalNode\n): node is SerializedLexicalLineBreakNode => {\n return node.group === \"linebreak\";\n};\n\nconst isSerializedElementNode = (\n node: SerializedLexicalNode\n): node is SerializedLexicalElementNode<Readonly<SerializedLexicalNode>> => {\n return node.group === \"element\" && node.children !== undefined;\n};\n\nconst isEmptySerializedElementNode = (node: SerializedLexicalNode): boolean => {\n return isSerializedElementNode(node) && node.children.length === 0;\n};\n\nconst isMentionNodeType = (type: string): type is \"lb-mention\" => {\n return type === \"lb-mention\";\n};\n\nconst isMentionNodeAttributeType = (type: unknown): type is \"lb-mention\" => {\n return isString(type) && type === \"lb-mention\";\n};\n\nexport const isSerializedMentionNode = (\n node: SerializedLexicalDecoratorNode\n): node is SerializedLexicalMentionNode => {\n const attributes = node.attributes;\n\n return (\n isMentionNodeType(node.type) &&\n isMentionNodeAttributeType(attributes.__type) &&\n isMentionNodeAttributeId(attributes.__id) &&\n isString(attributes.__userId)\n );\n};\n\nconst isGroupMentionNodeType = (type: string): type is \"lb-group-mention\" => {\n return type === \"lb-group-mention\";\n};\n\nconst isGroupMentionNodeAttributeType = (\n type: unknown\n): type is \"lb-group-mention\" => {\n return isString(type) && type === \"lb-group-mention\";\n};\n\nexport const isSerializedGroupMentionNode = (\n node: SerializedLexicalDecoratorNode\n): node is SerializedLexicalGroupMentionNode => {\n const attributes = node.attributes;\n\n return (\n isGroupMentionNodeType(node.type) &&\n isGroupMentionNodeAttributeType(attributes.__type) &&\n isMentionNodeAttributeId(attributes.__id) &&\n isString(attributes.__groupId) &&\n (attributes.__userIds === undefined || Array.isArray(attributes.__userIds))\n );\n};\n\n/**\n * Internal type helper when flattening nodes.\n * It helps to better extract mention node with context by marking\n * start and ends of paragraph and by handling specific use cases such as\n * using twice the `enter` key which will create an empty paragraph\n * at the first `enter`:\n *\n * \"\n * Hey @charlie what's up?\n * _enter_once_\n * _enter_twice_\n * \"\n */\ninterface FlattenedLexicalElementNodeMarker {\n group: \"element-marker\";\n marker: \"start\" | \"end\";\n}\n\nconst isFlattenedLexicalElementNodeMarker = (\n node: SerializedLexicalNode | FlattenedLexicalElementNodeMarker\n): node is FlattenedLexicalElementNodeMarker => {\n return node.group === \"element-marker\";\n};\n\n/** @internal */\ntype FlattenedSerializedLexicalNodes = Array<\n SerializedLexicalNode | FlattenedLexicalElementNodeMarker\n>;\n\n/** @internal - export for testing only */\nexport const flattenLexicalTree = (\n nodes: SerializedLexicalNode[]\n): FlattenedSerializedLexicalNodes => {\n let flattenNodes: FlattenedSerializedLexicalNodes = [];\n for (const node of nodes) {\n if (\n [\"text\", \"linebreak\", \"decorator\"].includes(node.group) ||\n isEmptySerializedElementNode(node)\n ) {\n flattenNodes = [...flattenNodes, node];\n } else if (node.group === \"element\") {\n flattenNodes = [\n ...flattenNodes,\n {\n group: \"element-marker\",\n marker: \"start\",\n },\n ...flattenLexicalTree(node.children),\n {\n group: \"element-marker\",\n marker: \"end\",\n },\n ];\n }\n }\n\n return flattenNodes;\n};\n\n/**\n * Lexical Mention Node with context\n */\nexport type LexicalMentionNodeWithContext = {\n before: SerializedLexicalNode[];\n after: SerializedLexicalNode[];\n mention: SerializedLexicalMentionNode | SerializedLexicalGroupMentionNode;\n};\n\n/**\n * Find a Lexical mention node\n * and returns it with contextual surrounding text\n */\nexport function findLexicalMentionNodeWithContext({\n root,\n textMentionId,\n}: {\n root: SerializedLexicalRootNode;\n textMentionId: string;\n}): LexicalMentionNodeWithContext | null {\n const nodes = flattenLexicalTree(root.children);\n\n // Find mention node\n let mentionNodeIndex = -1;\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i]!;\n if (\n node.group === \"decorator\" &&\n (isSerializedMentionNode(node) || isSerializedGroupMentionNode(node)) &&\n node.attributes.__id === textMentionId\n ) {\n mentionNodeIndex = i;\n break;\n }\n }\n\n // No mention node found\n if (mentionNodeIndex === -1) {\n return null;\n }\n\n // Collect nodes before and after\n const mentionNode = nodes[mentionNodeIndex] as\n | SerializedLexicalMentionNode\n | SerializedLexicalGroupMentionNode;\n\n // Apply surrounding text guesses\n // For now let's stay simple just stop at nearest line break or element\n const beforeNodes: SerializedLexicalNode[] = [];\n const afterNodes: SerializedLexicalNode[] = [];\n\n // Nodes before mention node\n for (let i = mentionNodeIndex - 1; i >= 0; i--) {\n const node = nodes[i]!;\n\n // Stop if nodes are markers, line breaks or empty elements\n if (\n isFlattenedLexicalElementNodeMarker(node) ||\n isSerializedLineBreakNode(node)\n ) {\n break;\n }\n\n // Stop if decorator node isn't a mention\n if (node.group === \"decorator\" && !isMentionNodeType(node.type)) {\n break;\n }\n\n beforeNodes.unshift(node);\n }\n\n // Nodes after mention node\n for (let i = mentionNodeIndex + 1; i < nodes.length; i++) {\n const node = nodes[i]!;\n\n // Stop if nodes are markers, line breaks or empty elements\n if (\n isFlattenedLexicalElementNodeMarker(node) ||\n isSerializedLineBreakNode(node)\n ) {\n break;\n }\n\n // Stop if decorator node isn't a mention\n if (node.group === \"decorator\" && !isMentionNodeType(node.type)) {\n break;\n }\n\n afterNodes.push(node);\n }\n\n return {\n before: beforeNodes,\n after: afterNodes,\n mention: mentionNode,\n };\n}\n\nexport function getMentionDataFromLexicalNode(\n node: SerializedLexicalMentionNode | SerializedLexicalGroupMentionNode\n): MentionData {\n if (isSerializedMentionNode(node)) {\n return {\n kind: \"user\",\n id: node.attributes.__userId,\n };\n } else if (isSerializedGroupMentionNode(node)) {\n return {\n kind: \"group\",\n id: node.attributes.__groupId,\n userIds: node.attributes.__userIds,\n };\n }\n\n assertNever(node, \"Unknown mention kind\");\n}\n","/**\n * Utility module to work with key-value stores.\n *\n * @module map\n */\n\n/**\n * Creates a new Map instance.\n *\n * @function\n * @return {Map<any, any>}\n *\n * @function\n */\nexport const create = () => new Map()\n\n/**\n * Copy a Map object into a fresh Map object.\n *\n * @function\n * @template K,V\n * @param {Map<K,V>} m\n * @return {Map<K,V>}\n */\nexport const copy = m => {\n const r = create()\n m.forEach((v, k) => { r.set(k, v) })\n return r\n}\n\n/**\n * Get map property. Create T if property is undefined and set T on map.\n *\n * ```js\n * const listeners = map.setIfUndefined(events, 'eventName', set.create)\n * listeners.add(listener)\n * ```\n *\n * @function\n * @template {Map<any, any>} MAP\n * @template {MAP extends Map<any,infer V> ? function():V : unknown} CF\n * @param {MAP} map\n * @param {MAP extends Map<infer K,any> ? K : unknown} key\n * @param {CF} createT\n * @return {ReturnType<CF>}\n */\nexport const setIfUndefined = (map, key, createT) => {\n let set = map.get(key)\n if (set === undefined) {\n map.set(key, set = createT())\n }\n return set\n}\n\n/**\n * Creates an Array and populates it with the content of all key-value pairs using the `f(value, key)` function.\n *\n * @function\n * @template K\n * @template V\n * @template R\n * @param {Map<K,V>} m\n * @param {function(V,K):R} f\n * @return {Array<R>}\n */\nexport const map = (m, f) => {\n const res = []\n for (const [key, value] of m) {\n res.push(f(value, key))\n }\n return res\n}\n\n/**\n * Tests whether any key-value pairs pass the test implemented by `f(value, key)`.\n *\n * @todo should rename to some - similarly to Array.some\n *\n * @function\n * @template K\n * @template V\n * @param {Map<K,V>} m\n * @param {function(V,K):boolean} f\n * @return {boolean}\n */\nexport const any = (m, f) => {\n for (const [key, value] of m) {\n if (f(value, key)) {\n return true\n }\n }\n return false\n}\n\n/**\n * Tests whether all key-value pairs pass the test implemented by `f(value, key)`.\n *\n * @function\n * @template K\n * @template V\n * @param {Map<K,V>} m\n * @param {function(V,K):boolean} f\n * @return {boolean}\n */\nexport const all = (m, f) => {\n for (const [key, value] of m) {\n if (!f(value, key)) {\n return false\n }\n }\n return true\n}\n","/**\n * Utility module to work with sets.\n *\n * @module set\n */\n\nexport const create = () => new Set()\n\n/**\n * @template T\n * @param {Set<T>} set\n * @return {Array<T>}\n */\nexport const toArray = set => Array.from(set)\n\n/**\n * @template T\n * @param {Set<T>} set\n * @return {T|undefined}\n */\nexport const first = set => set.values().next().value\n\n/**\n * @template T\n * @param {Iterable<T>} entries\n * @return {Set<T>}\n */\nexport const from = entries => new Set(entries)\n","/**\n * Utility module to work with Arrays.\n *\n * @module array\n */\n\nimport * as set from './set.js'\n\n/**\n * Return the last element of an array. The element must exist\n *\n * @template L\n * @param {ArrayLike<L>} arr\n * @return {L}\n */\nexport const last = arr => arr[arr.length - 1]\n\n/**\n * @template C\n * @return {Array<C>}\n */\nexport const create = () => /** @type {Array<C>} */ ([])\n\n/**\n * @template D\n * @param {Array<D>} a\n * @return {Array<D>}\n */\nexport const copy = a => /** @type {Array<D>} */ (a.slice())\n\n/**\n * Append elements from src to dest\n *\n * @template M\n * @param {Array<M>} dest\n * @param {Array<M>} src\n */\nexport const appendTo = (dest, src) => {\n for (let i = 0; i < src.length; i++) {\n dest.push(src[i])\n }\n}\n\n/**\n * Transforms something array-like to an actual Array.\n *\n * @function\n * @template T\n * @param {ArrayLike<T>|Iterable<T>} arraylike\n * @return {T}\n */\nexport const from = Array.from\n\n/**\n * True iff condition holds on every element in the Array.\n *\n * @function\n * @template {ArrayLike<any>} ARR\n *\n * @param {ARR} arr\n * @param {ARR extends ArrayLike<infer S> ? ((value:S, index:number, arr:ARR) => boolean) : any} f\n * @return {boolean}\n */\nexport const every = (arr, f) => {\n for (let i = 0; i < arr.length; i++) {\n if (!f(arr[i], i, arr)) {\n return false\n }\n }\n return true\n}\n\n/**\n * True iff condition holds on some element in the Array.\n *\n * @function\n * @template {ArrayLike<any>} ARR\n *\n * @param {ARR} arr\n * @param {ARR extends ArrayLike<infer S> ? ((value:S, index:number, arr:ARR) => boolean) : never} f\n * @return {boolean}\n */\nexport const some = (arr, f) => {\n for (let i = 0; i < arr.length; i++) {\n if (f(arr[i], i, arr)) {\n return true\n }\n }\n return false\n}\n\n/**\n * @template ELEM\n *\n * @param {ArrayLike<ELEM>} a\n * @param {ArrayLike<ELEM>} b\n * @return {boolean}\n */\nexport const equalFlat = (a, b) => a.length === b.length && every(a, (item, index) => item === b[index])\n\n/**\n * @template ELEM\n * @param {Array<Array<ELEM>>} arr\n * @return {Array<ELEM>}\n */\nexport const flatten = arr => fold(arr, /** @type {Array<ELEM>} */ ([]), (acc, val) => acc.concat(val))\n\n/**\n * @template T\n * @param {number} len\n * @param {function(number, Array<T>):T} f\n * @return {Array<T>}\n */\nexport const unfold = (len, f) => {\n const array = new Array(len)\n for (let i = 0; i < len; i++) {\n array[i] = f(i, array)\n }\n return array\n}\n\n/**\n * @template T\n * @template RESULT\n * @param {Array<T>} arr\n * @param {RESULT} seed\n * @param {function(RESULT, T, number):RESULT} folder\n */\nexport const fold = (arr, seed, folder) => arr.reduce(folder, seed)\n\nexport const isArray = Array.isArray\n\n/**\n * @template T\n * @param {Array<T>} arr\n * @return {Array<T>}\n */\nexport const unique = arr => from(set.from(arr))\n\n/**\n * @template T\n * @template M\n * @param {ArrayLike<T>} arr\n * @param {function(T):M} mapper\n * @return {Array<T>}\n */\nexport const uniqueBy = (arr, mapper) => {\n /**\n * @type {Set<M>}\n */\n const happened = set.create()\n /**\n * @type {Array<T>}\n */\n const result = []\n for (let i = 0; i < arr.length; i++) {\n const el = arr[i]\n const mapped = mapper(el)\n if (!happened.has(mapped)) {\n happened.add(mapped)\n result.push(el)\n }\n }\n return result\n}\n\n/**\n * @template {ArrayLike<any>} ARR\n * @template {function(ARR extends ArrayLike<infer T> ? T : never, number, ARR):any} MAPPER\n * @param {ARR} arr\n * @param {MAPPER} mapper\n * @return {Array<MAPPER extends function(...any): infer M ? M : never>}\n */\nexport const map = (arr, mapper) => {\n /**\n * @type {Array<any>}\n */\n const res = Array(arr.length)\n for (let i = 0; i < arr.length; i++) {\n res[i] = mapper(/** @type {any} */ (arr[i]), i, /** @type {any} */ (arr))\n }\n return /** @type {any} */ (res)\n}\n\n/**\n * This function bubble-sorts a single item to the correct position. The sort happens in-place and\n * might be useful to ensure that a single item is at the correct position in an otherwise sorted\n * array.\n *\n * @example\n * const arr = [3, 2, 5]\n * arr.sort((a, b) => a - b)\n * arr // => [2, 3, 5]\n * arr.splice(1, 0, 7)\n * array.bubbleSortItem(arr, 1, (a, b) => a - b)\n * arr // => [2, 3, 5, 7]\n *\n * @template T\n * @param {Array<T>} arr\n * @param {number} i\n * @param {(a:T,b:T) => number} compareFn\n */\nexport const bubblesortItem = (arr, i, compareFn) => {\n const n = arr[i]\n let j = i\n // try to sort to the right\n while (j + 1 < arr.length && compareFn(n, arr[j + 1]) > 0) {\n arr[j] = arr[j + 1]\n arr[++j] = n\n }\n if (i === j && j > 0) { // no change yet\n // sort to the left\n while (j > 0 && compareFn(arr[j - 1], n) > 0) {\n arr[j] = arr[j - 1]\n arr[--j] = n\n }\n }\n return j\n}\n","/**\n * Observable class prototype.\n *\n * @module observable\n */\n\nimport * as map from './map.js'\nimport * as set from './set.js'\nimport * as array from './array.js'\n\n/**\n * Handles named events.\n * @experimental\n *\n * This is basically a (better typed) duplicate of Observable, which will replace Observable in the\n * next release.\n *\n * @template {{[key in keyof EVENTS]: function(...any):void}} EVENTS\n */\nexport class ObservableV2 {\n constructor () {\n /**\n * Some desc.\n * @type {Map<string, Set<any>>}\n */\n this._observers = map.create()\n }\n\n /**\n * @template {keyof EVENTS & string} NAME\n * @param {NAME} name\n * @param {EVENTS[NAME]} f\n */\n on (name, f) {\n map.setIfUndefined(this._observers, /** @type {string} */ (name), set.create).add(f)\n return f\n }\n\n /**\n * @template {keyof EVENTS & string} NAME\n * @param {NAME} name\n * @param {EVENTS[NAME]} f\n */\n once (name, f) {\n /**\n * @param {...any} args\n */\n const _f = (...args) => {\n this.off(name, /** @type {any} */ (_f))\n f(...args)\n }\n this.on(name, /** @type {any} */ (_f))\n }\n\n /**\n * @template {keyof EVENTS & string} NAME\n * @param {NAME} name\n * @param {EVENTS[NAME]} f\n */\n off (name, f) {\n const observers = this._observers.get(name)\n if (observers !== undefined) {\n observers.delete(f)\n if (observers.size === 0) {\n this._observers.delete(name)\n }\n }\n }\n\n /**\n * Emit a named event. All registered event listeners that listen to the\n * specified name will receive the event.\n *\n * @todo This should catch exceptions\n *\n * @template {keyof EVENTS & string} NAME\n * @param {NAME} name The event name.\n * @param {Parameters<EVENTS[NAME]>} args The arguments that are applied to the event listener.\n */\n emit (name, args) {\n // copy all listeners to an array first to make sure that no event is emitted to listeners that are subscribed while the event handler is called.\n return array.from((this._observers.get(name) || map.create()).values()).forEach(f => f(...args))\n }\n\n destroy () {\n this._observers = map.create()\n }\n}\n\n/* c8 ignore start */\n/**\n * Handles named events.\n *\n * @deprecated\n * @template N\n */\nexport class Observable {\n constructor () {\n /**\n * Some desc.\n * @type {Map<N, any>}\n */\n this._observers = map.create()\n }\n\n /**\n * @param {N} name\n * @param {function} f\n */\n on (name, f) {\n map.setIfUndefined(this._observers, name, set.create).add(f)\n }\n\n /**\n * @param {N} name\n * @param {function} f\n */\n once (name, f) {\n /**\n * @param {...any} args\n */\n const _f = (...args) => {\n this.off(name, _f)\n f(...args)\n }\n this.on(name, _f)\n }\n\n /**\n * @param {N} name\n * @param {function} f\n */\n off (name, f) {\n const observers = this._observers.get(name)\n if (observers !== undefined) {\n observers.delete(f)\n if (observers.size === 0) {\n this._observers.delete(name)\n }\n }\n }\n\n /**\n * Emit a named event. All registered event listeners that listen to the\n * specified name will receive the event.\n *\n * @todo This should catch exceptions\n *\n * @param {N} name The event name.\n * @param {Array<any>} args The arguments that are applied to the event listener.\n */\n emit (name, args) {\n // copy all listeners to an array first to make sure that no event is emitted to listeners that are subscribed while the event handler is called.\n return array.from((this._observers.get(name) || map.create()).values()).forEach(f => f(...args))\n }\n\n destroy () {\n this._observers = map.create()\n }\n}\n/* c8 ignore end */\n","/**\n * Common Math expressions.\n *\n * @module math\n */\n\nexport const floor = Math.floor\nexport const ceil = Math.ceil\nexport const abs = Math.abs\nexport const imul = Math.imul\nexport const round = Math.round\nexport const log10 = Math.log10\nexport const log2 = Math.log2\nexport const log = Math.log\nexport const sqrt = Math.sqrt\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The sum of a and b\n */\nexport const add = (a, b) => a + b\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The smaller element of a and b\n */\nexport const min = (a, b) => a < b ? a : b\n\n/**\n * @function\n * @param {number} a\n * @param {number} b\n * @return {number} The bigger element of a and b\n */\nexport const max = (a, b) => a > b ? a : b\n\nexport const isNaN = Number.isNaN\n\nexport const pow = Math.pow\n/**\n * Base 10 exponential function. Returns the value of 10 raised to the power of pow.\n *\n * @param {number} exp\n * @return {number}\n */\nexport const exp10 = exp => Math.pow(10, exp)\n\nexport const sign = Math.sign\n\n/**\n * @param {number} n\n * @return {boolean} Wether n is negative. This function also differentiates between -0 and +0\n */\nexport const isNegativeZero = n => n !== 0 ? n < 0 : 1 / n < 0\n","/* eslint-env browser */\n\n/**\n * Binary data constants.\n *\n * @module binary\n */\n\n/**\n * n-th bit activated.\n *\n * @type {number}\n */\nexport const BIT1 = 1\nexport const BIT2 = 2\nexport const BIT3 = 4\nexport const BIT4 = 8\nexport const BIT5 = 16\nexport const BIT6 = 32\nexport const BIT7 = 64\nexport const BIT8 = 128\nexport const BIT9 = 256\nexport const BIT10 = 512\nexport const BIT11 = 1024\nexport const BIT12 = 2048\nexport const BIT13 = 4096\nexport const BIT14 = 8192\nexport const BIT15 = 16384\nexport const BIT16 = 32768\nexport const BIT17 = 65536\nexport const BIT18 = 1 << 17\nexport const BIT19 = 1 << 18\nexport const BIT20 = 1 << 19\nexport const BIT21 = 1 << 20\nexport const BIT22 = 1 << 21\nexport const BIT23 = 1 << 22\nexport const BIT24 = 1 << 23\nexport const BIT25 = 1 << 24\nexport const BIT26 = 1 << 25\nexport const BIT27 = 1 << 26\nexport const BIT28 = 1 << 27\nexport const BIT29 = 1 << 28\nexport const BIT30 = 1 << 29\nexport const BIT31 = 1 << 30\nexport const BIT32 = 1 << 31\n\n/**\n * First n bits activated.\n *\n * @type {number}\n */\nexport const BITS0 = 0\nexport const BITS1 = 1\nexport const BITS2 = 3\nexport const BITS3 = 7\nexport const BITS4 = 15\nexport const BITS5 = 31\nexport const BITS6 = 63\nexport const BITS7 = 127\nexport const BITS8 = 255\nexport const BITS9 = 511\nexport const BITS10 = 1023\nexport const BITS11 = 2047\nexport const BITS12 = 4095\nexport const BITS13 = 8191\nexport const BITS14 = 16383\nexport const BITS15 = 32767\nexport const BITS16 = 65535\nexport const BITS17 = BIT18 - 1\nexport const BITS18 = BIT19 - 1\nexport const BITS19 = BIT20 - 1\nexport const BITS20 = BIT21 - 1\nexport const BITS21 = BIT22 - 1\nexport const BITS22 = BIT23 - 1\nexport const BITS23 = BIT24 - 1\nexport const BITS24 = BIT25 - 1\nexport const BITS25 = BIT26 - 1\nexport const BITS26 = BIT27 - 1\nexport const BITS27 = BIT28 - 1\nexport const BITS28 = BIT29 - 1\nexport const BITS29 = BIT30 - 1\nexport const BITS30 = BIT31 - 1\n/**\n * @type {number}\n */\nexport const BITS31 = 0x7FFFFFFF\n/**\n * @type {number}\n */\nexport const BITS32 = 0xFFFFFFFF\n","/**\n * Utility helpers for working with numbers.\n *\n * @module number\n */\n\nimport * as math from './math.js'\nimport * as binary from './binary.js'\n\nexport const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER\nexport const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER\n\nexport const LOWEST_INT32 = 1 << 31\nexport const HIGHEST_INT32 = binary.BITS31\nexport const HIGHEST_UINT32 = binary.BITS32\n\n/* c8 ignore next */\nexport const isInteger = Number.isInteger || (num => typeof num === 'number' && isFinite(num) && math.floor(num) === num)\nexport const isNaN = Number.isNaN\nexport const parseInt = Number.parseInt\n\n/**\n * Count the number of \"1\" bits in an unsigned 32bit number.\n *\n * Super fun bitcount algorithm by Brian Kernighan.\n *\n * @param {number} n\n */\nexport const countBits = n => {\n n &= binary.BITS32\n let count = 0\n while (n) {\n n &= (n - 1)\n count++\n }\n return count\n}\n","import * as array from './array.js'\n\n/**\n * Utility module to work with strings.\n *\n * @module string\n */\n\nexport const fromCharCode = String.fromCharCode\nexport const fromCodePoint = String.fromCodePoint\n\n/**\n * The largest utf16 character.\n * Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)\n */\nexport const MAX_UTF16_CHARACTER = fromCharCode(65535)\n\n/**\n * @param {string} s\n * @return {string}\n */\nconst toLowerCase = s => s.toLowerCase()\n\nconst trimLeftRegex = /^\\s*/g\n\n/**\n * @param {string} s\n * @return {string}\n */\nexport const trimLeft = s => s.replace(trimLeftRegex, '')\n\nconst fromCamelCaseRegex = /([A-Z])/g\n\n/**\n * @param {string} s\n * @param {string} separator\n * @return {string}\n */\nexport const fromCamelCase = (s, separator) => trimLeft(s.replace(fromCamelCaseRegex, match => `${separator}${toLowerCase(match)}`))\n\n/**\n * Compute the utf8ByteLength\n * @param {string} str\n * @return {number}\n */\nexport const utf8ByteLength = str => unescape(encodeURIComponent(str)).length\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\nexport const _encodeUtf8Polyfill = str => {\n const encodedString = unescape(encodeURIComponent(str))\n const len = encodedString.length\n const buf = new Uint8Array(len)\n for (let i = 0; i < len; i++) {\n buf[i] = /** @type {number} */ (encodedString.codePointAt(i))\n }\n return buf\n}\n\n/* c8 ignore next */\nexport const utf8TextEncoder = /** @type {TextEncoder} */ (typeof TextEncoder !== 'undefined' ? new TextEncoder() : null)\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\nexport const _encodeUtf8Native = str => utf8TextEncoder.encode(str)\n\n/**\n * @param {string} str\n * @return {Uint8Array}\n */\n/* c8 ignore next */\nexport const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\nexport const _decodeUtf8Polyfill = buf => {\n let remainingLen = buf.length\n let encodedString = ''\n let bufPos = 0\n while (remainingLen > 0) {\n const nextLen = remainingLen < 10000 ? remainingLen : 10000\n const bytes = buf.subarray(bufPos, bufPos + nextLen)\n bufPos += nextLen\n // Starting with ES5.1 we can supply a generic array-like object as arguments\n encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes))\n remainingLen -= nextLen\n }\n return decodeURIComponent(escape(encodedString))\n}\n\n/* c8 ignore next */\nexport let utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })\n\n/* c8 ignore start */\nif (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {\n // Safari doesn't handle BOM correctly.\n // This fixes a bug in Safari 13.0.5 where it produces a BOM the first time it is called.\n // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the first call and\n // utf8TextDecoder.decode(new Uint8Array()).length === 1 on the second call\n // Another issue is that from then on no BOM chars are recognized anymore\n /* c8 ignore next */\n utf8TextDecoder = null\n}\n/* c8 ignore stop */\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\nexport const _decodeUtf8Native = buf => /** @type {TextDecoder} */ (utf8TextDecoder).decode(buf)\n\n/**\n * @param {Uint8Array} buf\n * @return {string}\n */\n/* c8 ignore next */\nexport const decodeUtf8 = utf8TextDecoder ? _decodeUtf8Native : _decodeUtf8Polyfill\n\n/**\n * @param {string} str The initial string\n * @param {number} index Starting position\n * @param {number} remove Number of characters to remove\n * @param {string} insert New content to insert\n */\nexport const splice = (str, index, remove, insert = '') => str.slice(0, index) + insert + str.slice(index + remove)\n\n/**\n * @param {string} source\n * @param {number} n\n */\nexport const repeat = (source, n) => array.unfold(n, () => source).join('')\n\n/**\n * Escape HTML characters &,<,>,',\" to their respective HTML entities &,<,>,',"\n *\n * @param {string} str\n */\nexport const escapeHTML = str =>\n str.replace(/[&<>'\"]/g, r => /** @type {string} */ ({\n '&': '&',\n '<': '<',\n '>': '>',\n \"'\": ''',\n '\"': '"'\n }[r]))\n\n/**\n * Reverse of `escapeHTML`\n *\n * @param {string} str\n */\nexport const unescapeHTML = str =>\n str.replace(/&|<|>|'|"/g, r => /** @type {string} */ ({\n '&': '&',\n '<': '<',\n '>': '>',\n ''': \"'\",\n '"': '\"'\n }[r]))\n","/**\n * Efficient schema-less binary encoding with support for variable length encoding.\n *\n * Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function.\n *\n * Encodes numbers in little-endian order (least to most significant byte order)\n * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)\n * which is also used in Protocol Buffers.\n *\n * ```js\n * // encoding step\n * const encoder = encoding.createEncoder()\n * encoding.writeVarUint(encoder, 256)\n * encoding.writeVarString(encoder, 'Hello world!')\n * const buf = encoding.toUint8Array(encoder)\n * ```\n *\n * ```js\n * // decoding step\n * const decoder = decoding.createDecoder(buf)\n * decoding.readVarUint(decoder) // => 256\n * decoding.readVarString(decoder) // => 'Hello world!'\n * decoding.hasContent(decoder) // => false - all data is read\n * ```\n *\n * @module encoding\n */\n\nimport * as math from './math.js'\nimport * as number from './number.js'\nimport * as binary from './binary.js'\nimport * as string from './string.js'\nimport * as array from './array.js'\n\n/**\n * A BinaryEncoder handles the encoding to an Uint8Array.\n */\nexport class Encoder {\n constructor () {\n this.cpos = 0\n this.cbuf = new Uint8Array(100)\n /**\n * @type {Array<Uint8Array>}\n */\n this.bufs = []\n }\n}\n\n/**\n * @function\n * @return {Encoder}\n */\nexport const createEncoder = () => new Encoder()\n\n/**\n * @param {function(Encoder):void} f\n */\nexport const encode = (f) => {\n const encoder = createEncoder()\n f(encoder)\n return toUint8Array(encoder)\n}\n\n/**\n * The current length of the encoded data.\n *\n * @function\n * @param {Encoder} encoder\n * @return {number}\n */\nexport const length = encoder => {\n let len = encoder.cpos\n for (let i = 0; i < encoder.bufs.length; i++) {\n len += encoder.bufs[i].length\n }\n return len\n}\n\n/**\n * Check whether encoder is empty.\n *\n * @function\n * @param {Encoder} encoder\n * @return {boolean}\n */\nexport const hasContent = encoder => encoder.cpos > 0 || encoder.bufs.length > 0\n\n/**\n * Transform to Uint8Array.\n *\n * @function\n * @param {Encoder} encoder\n * @return {Uint8Array} The created ArrayBuffer.\n */\nexport const toUint8Array = encoder => {\n const uint8arr = new Uint8Array(length(encoder))\n let curPos = 0\n for (let i = 0; i < encoder.bufs.length; i++) {\n const d = encoder.bufs[i]\n uint8arr.set(d, curPos)\n curPos += d.length\n }\n uint8arr.set(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos), curPos)\n return uint8arr\n}\n\n/**\n * Verify that it is possible to write `len` bytes wtihout checking. If\n * necessary, a new Buffer with the required length is attached.\n *\n * @param {Encoder} encoder\n * @param {number} len\n */\nexport const verifyLen = (encoder, len) => {\n const bufferLen = encoder.cbuf.length\n if (bufferLen - encoder.cpos < len) {\n encoder.bufs.push(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos))\n encoder.cbuf = new Uint8Array(math.max(bufferLen, len) * 2)\n encoder.cpos = 0\n }\n}\n\n/**\n * Write one byte to the encoder.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The byte that is to be encoded.\n */\nexport const write = (encoder, num) => {\n const bufferLen = encoder.cbuf.length\n if (encoder.cpos === bufferLen) {\n encoder.bufs.push(encoder.cbuf)\n encoder.cbuf = new Uint8Array(bufferLen * 2)\n encoder.cpos = 0\n }\n encoder.cbuf[encoder.cpos++] = num\n}\n\n/**\n * Write one byte at a specific position.\n * Position must already be written (i.e. encoder.length > pos)\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos Position to which to write data\n * @param {number} num Unsigned 8-bit integer\n */\nexport const set = (encoder, pos, num) => {\n let buffer = null\n // iterate all buffers and adjust position\n for (let i = 0; i < encoder.bufs.length && buffer === null; i++) {\n const b = encoder.bufs[i]\n if (pos < b.length) {\n buffer = b // found buffer\n } else {\n pos -= b.length\n }\n }\n if (buffer === null) {\n // use current buffer\n buffer = encoder.cbuf\n }\n buffer[pos] = num\n}\n\n/**\n * Write one byte as an unsigned integer.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint8 = write\n\n/**\n * Write one byte as an unsigned Integer at a specific location.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos The location where the data will be written.\n * @param {number} num The number that is to be encoded.\n */\nexport const setUint8 = set\n\n/**\n * Write two bytes as an unsigned integer.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint16 = (encoder, num) => {\n write(encoder, num & binary.BITS8)\n write(encoder, (num >>> 8) & binary.BITS8)\n}\n/**\n * Write two bytes as an unsigned integer at a specific location.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos The location where the data will be written.\n * @param {number} num The number that is to be encoded.\n */\nexport const setUint16 = (encoder, pos, num) => {\n set(encoder, pos, num & binary.BITS8)\n set(encoder, pos + 1, (num >>> 8) & binary.BITS8)\n}\n\n/**\n * Write two bytes as an unsigned integer\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint32 = (encoder, num) => {\n for (let i = 0; i < 4; i++) {\n write(encoder, num & binary.BITS8)\n num >>>= 8\n }\n}\n\n/**\n * Write two bytes as an unsigned integer in big endian order.\n * (most significant byte first)\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeUint32BigEndian = (encoder, num) => {\n for (let i = 3; i >= 0; i--) {\n write(encoder, (num >>> (8 * i)) & binary.BITS8)\n }\n}\n\n/**\n * Write two bytes as an unsigned integer at a specific location.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} pos The location where the data will be written.\n * @param {number} num The number that is to be encoded.\n */\nexport const setUint32 = (encoder, pos, num) => {\n for (let i = 0; i < 4; i++) {\n set(encoder, pos + i, num & binary.BITS8)\n num >>>= 8\n }\n}\n\n/**\n * Write a variable length unsigned integer. Max encodable integer is 2^53.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeVarUint = (encoder, num) => {\n while (num > binary.BITS7) {\n write(encoder, binary.BIT8 | (binary.BITS7 & num))\n num = math.floor(num / 128) // shift >>> 7\n }\n write(encoder, binary.BITS7 & num)\n}\n\n/**\n * Write a variable length integer.\n *\n * We use the 7th bit instead for signaling that this is a negative number.\n *\n * @function\n * @param {Encoder} encoder\n * @param {number} num The number that is to be encoded.\n */\nexport const writeVarInt = (encoder, num) => {\n const isNegative = math.isNegativeZero(num)\n if (isNegative) {\n num = -num\n }\n // |- whether to continue reading |- whether is negative |- number\n write(encoder, (num > binary.BITS6 ? binary.BIT8 : 0) | (isNegative ? binary.BIT7 : 0) | (binary.BITS6 & num))\n num = math.floor(num / 64) // shift >>> 6\n // We don't need to consider the case of num === 0 so we can use a different\n // pattern here than above.\n while (num > 0) {\n write(encoder, (num > binary.BITS7 ? binary.BIT8 : 0) | (binary.BITS7 & num))\n num = math.floor(num / 128) // shift >>> 7\n }\n}\n\n/**\n * A cache to store strings temporarily\n */\nconst _strBuffer = new Uint8Array(30000)\nconst _maxStrBSize = _strBuffer.length / 3\n\n/**\n * Write a variable length string.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\nexport const _writeVarStringNative = (encoder, str) => {\n if (str.length < _maxStrBSize) {\n // We can encode the string into the existing buffer\n /* c8 ignore next */\n const written = string.utf8TextEncoder.encodeInto(str, _strBuffer).written || 0\n writeVarUint(encoder, written)\n for (let i = 0; i < written; i++) {\n write(encoder, _strBuffer[i])\n }\n } else {\n writeVarUint8Array(encoder, string.encodeUtf8(str))\n }\n}\n\n/**\n * Write a variable length string.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\nexport const _writeVarStringPolyfill = (encoder, str) => {\n const encodedString = unescape(encodeURIComponent(str))\n const len = encodedString.length\n writeVarUint(encoder, len)\n for (let i = 0; i < len; i++) {\n write(encoder, /** @type {number} */ (encodedString.codePointAt(i)))\n }\n}\n\n/**\n * Write a variable length string.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\n/* c8 ignore next */\nexport const writeVarString = (string.utf8TextEncoder && /** @type {any} */ (string.utf8TextEncoder).encodeInto) ? _writeVarStringNative : _writeVarStringPolyfill\n\n/**\n * Write a string terminated by a special byte sequence. This is not very performant and is\n * generally discouraged. However, the resulting byte arrays are lexiographically ordered which\n * makes this a nice feature for databases.\n *\n * The string will be encoded using utf8 and then terminated and escaped using writeTerminatingUint8Array.\n *\n * @function\n * @param {Encoder} encoder\n * @param {String} str The string that is to be encoded.\n */\nexport const writeTerminatedString = (encoder, str) =>\n writeTerminatedUint8Array(encoder, string.encodeUtf8(str))\n\n/**\n * Write a terminating Uint8Array. Note that this is not performant and is generally\n * discouraged. There are few situations when this is needed.\n *\n * We use 0x0 as a terminating character. 0x1 serves as an escape character for 0x0 and 0x1.\n *\n * Example: [0,1,2] is encoded to [1,0,1,1,2,0]. 0x0, and 0x1 needed to be escaped using 0x1. Then\n * the result is terminated using the 0x0 character.\n *\n * This is basically how many systems implement null terminated strings. However, we use an escape\n * character 0x1 to avoid issues and potenial attacks on our database (if this is used as a key\n * encoder for NoSql databases).\n *\n * @function\n * @param {Encoder} encoder\n * @param {Uint8Array} buf The string that is to be encoded.\n */\nexport const writeTerminatedUint8Array = (encoder, buf) => {\n for (let i = 0; i < buf.length; i++) {\n const b = buf[i]\n if (b === 0 || b === 1) {\n write(encoder, 1)\n }\n write(encoder, buf[i])\n }\n write(encoder, 0)\n}\n\n/**\n * Write the content of another Encoder.\n *\n * @TODO: can be improved!\n * - Note: Should consider that when appending a lot of small Encoders, we should rather clone than referencing the old structure.\n * Encoders start with a rather big initial buffer.\n *\n * @function\n * @param {Encoder} encoder The enUint8Arr\n * @param {Encoder} append The BinaryEncoder to be written.\n */\nexport const writeBinaryEncoder = (encoder, append) => writeUint8Array(encoder, toUint8Array(append))\n\n/**\n * Append fixed-length Uint8Array to the encoder.\n *\n * @function\n * @param {Encoder} encoder\n * @param {Uint8Array} uint8Array\n */\nexport const writeUint8Array = (encoder, uint8Array) => {\n const bufferLen = encoder.cbuf.length\n const cpos = encoder.cpos\n const leftCopyLen = math.min(bufferLen - cpos, uint8Array.length)\n const rightCopyLen = uint8Array.length - leftCopyLen\n encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos)\n encoder.cpos += leftCopyLen\n if (rightCopyLen > 0) {\n // Still something to write, write right half..\n // Append new buffer\n encoder.bufs.push(encoder.cbuf)\n // must have at least size of remaining buffer\n encoder.cbuf = new Uint8Array(math.max(bufferLen * 2, rightCopyLen))\n // copy array\n encoder.cbuf.set(uint8Array.subarray(leftCopyLen))\n encoder.cpos = rightCopyLen\n }\n}\n\n/**\n * Append an Uint8Array to Encoder.\n *\n * @function\n * @param {Encoder} encoder\n * @param {Uint8Array} uint8Array\n */\nexport const writeVarUint8Array = (encoder, uint8Array) => {\n writeVarUint(encoder, uint8Array.byteLength)\n writeUint8Array(encoder, uint8Array)\n}\n\n/**\n * Create an DataView of the next `len` bytes. Use it to write data after\n * calling this function.\n *\n * ```js\n * // write float32 using DataView\n * const dv = writeOnDataView(encoder, 4)\n * dv.setFloat32(0, 1.1)\n * // read float32 using DataView\n * const dv = readFromDataView(encoder, 4)\n * dv.getFloat32(0) // => 1.100000023841858 (leaving it to the reader to find out why this is the correct result)\n * ```\n *\n * @param {Encoder} encoder\n * @param {number} len\n * @return {DataView}\n */\nexport const writeOnDataView = (encoder, len) => {\n verifyLen(encoder, len)\n const dview = new DataView(encoder.cbuf.buffer, encoder.cpos, len)\n encoder.cpos += len\n return dview\n}\n\n/**\n * @param {Encoder} encoder\n * @param {number} num\n */\nexport const writeFloat32 = (encoder, num) => writeOnDataView(encoder, 4).setFloat32(0, num, false)\n\n/**\n * @param {Encoder} encoder\n * @param {number} num\n */\nexport const writeFloat64 = (encoder, num) => writeOnDataView(encoder, 8).setFloat64(0, num, false)\n\n/**\n * @param {Encoder} encoder\n * @param {bigint} num\n */\nexport const writeBigInt64 = (encoder, num) => /** @type {any} */ (writeOnDataView(encoder, 8)).setBigInt64(0, num, false)\n\n/**\n * @param {Encoder} encoder\n * @param {bigint} num\n */\nexport const writeBigUint64 = (encoder, num) => /** @type {any} */ (writeOnDataView(encoder, 8)).setBigUint64(0, num, false)\n\nconst floatTestBed = new DataView(new ArrayBuffer(4))\n/**\n * Check if a number can be encoded as a 32 bit float.\n *\n * @param {number} num\n * @return {boolean}\n */\nconst isFloat32 = num => {\n floatTestBed.setFloat32(0, num)\n return floatTestBed.getFloat32(0) === num\n}\n\n/**\n * Encode data with efficient binary format.\n *\n * Differences to JSON:\n * • Transforms data to a binary format (not to a string)\n * • Encodes undefined, NaN, and ArrayBuffer (these can't be represented in JSON)\n * • Numbers are efficiently encoded either as a variable length integer, as a\n * 32 bit float, as a 64 bit float, or as a 64 bit bigint.\n *\n * Encoding table:\n *\n * | Data Type | Prefix | Encoding Method | Comment |\n * | ------------------- | -------- | ------------------ | ------- |\n * | undefined | 127 | | Functions, symbol, and everything that cannot be identified is encoded as undefined |\n * | null | 126 | | |\n * | integer | 125 | writeVarInt | Only encodes 32 bit signed integers |\n * | float32 | 124 | writeFloat32 | |\n * | float64 | 123 | writeFloat64 | |\n * | bigint | 122 | writeBigInt64 | |\n * | boolean (false) | 121 | | True and false are different data types so we save the following byte |\n * | boolean (true) | 120 | | - 0b01111000 so the last bit determines whether true or false |\n * | string | 119 | writeVarString | |\n * | object<string,any> | 118 | custom | Writes {length} then {length} key-value pairs |\n * | array<any> | 117 | custom | Writes {length} then {length} json values |\n * | Uint8Array | 116 | writeVarUint8Array | We use Uint8Array for any kind of binary data |\n *\n * Reasons for the decreasing prefix:\n * We need the first bit for extendability (later we may want to encode the\n * prefix with writeVarUint). The remaining 7 bits are divided as follows:\n * [0-30] the beginning of the data range is used for custom purposes\n * (defined by the function that uses this library)\n * [31-127] the end of the data range is used for data encoding by\n * lib0/encoding.js\n *\n * @param {Encoder} encoder\n * @param {undefined|null|number|bigint|boolean|string|Object<string,any>|Array<any>|Uint8Array} data\n */\nexport const writeAny = (encoder, data) => {\n switch (typeof data) {\n case 'string':\n // TYPE 119: STRING\n write(encoder, 119)\n writeVarString(encoder, data)\n break\n case 'number':\n if (number.isInteger(data) && math.abs(data) <= binary.BITS31) {\n // TYPE 125: INTEGER\n write(encoder, 125)\n writeVarInt(encoder, data)\n } else if (isFloat32(data)) {\n // TYPE 124: FLOAT32\n write(encoder, 124)\n writeFloat32(encoder, data)\n } else {\n // TYPE 123: FLOAT64\n write(encoder, 123)\n writeFloat64(encoder, data)\n }\n break\n case 'bigint':\n // TYPE 122: BigInt\n write(encoder, 122)\n writeBigInt64(encoder, data)\n break\n case 'object':\n if (data === null) {\n // TYPE 126: null\n write(encoder, 126)\n } else if (array.isArray(data)) {\n // TYPE 117: Array\n write(encoder, 117)\n writeVarUint(encoder, data.length)\n for (let i = 0; i < data.length; i++) {\n writeAny(encoder, data[i])\n }\n } else if (data instanceof Uint8Array) {\n // TYPE 116: ArrayBuffer\n write(encoder, 116)\n writeVarUint8Array(encoder, data)\n } else {\n // TYPE 118: Object\n write(encoder, 118)\n const keys = Object.keys(data)\n writeVarUint(encoder, keys.length)\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]\n writeVarString(encoder, key)\n writeAny(encoder, data[key])\n }\n }\n break\n case 'boolean':\n // TYPE 120/121: boolean (true/false)\n write(encoder, data ? 120 : 121)\n break\n default:\n // TYPE 127: undefined\n write(encoder, 127)\n }\n}\n\n/**\n * Now come a few stateful encoder that have their own classes.\n */\n\n/**\n * Basic Run Length Encoder - a basic compression implementation.\n *\n * Encodes [1,1,1,7] to [1,3,7,1] (3 times 1, 1 time 7). This encoder might do more harm than good if there are a lot of values that are not repeated.\n *\n * It was originally used for image compression. Cool .. article http://csbruce.com/cbm/transactor/pdfs/trans_v7_i06.pdf\n *\n * @note T must not be null!\n *\n * @template T\n */\nexport class RleEncoder extends Encoder {\n /**\n * @param {function(Encoder, T):void} writer\n */\n constructor (writer) {\n super()\n /**\n * The writer\n */\n this.w = writer\n /**\n * Current state\n * @type {T|null}\n */\n this.s = null\n this.count = 0\n }\n\n /**\n * @param {T} v\n */\n write (v) {\n if (this.s === v) {\n this.count++\n } else {\n if (this.count > 0) {\n // flush counter, unless this is the first value (count = 0)\n writeVarUint(this, this.count - 1) // since count is always > 0, we can decrement by one. non-standard encoding ftw\n }\n this.count = 1\n // write first value\n this.w(this, v)\n this.s = v\n }\n }\n}\n\n/**\n * Basic diff decoder using variable length encoding.\n *\n * Encodes the values [3, 1100, 1101, 1050, 0] to [3, 1097, 1, -51, -1050] using writeVarInt.\n */\nexport class IntDiffEncoder extends Encoder {\n /**\n * @param {number} start\n */\n constructor (start) {\n super()\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n writeVarInt(this, v - this.s)\n this.s = v\n }\n}\n\n/**\n * A combination of IntDiffEncoder and RleEncoder.\n *\n * Basically first writes the IntDiffEncoder and then counts duplicate diffs using RleEncoding.\n *\n * Encodes the values [1,1,1,2,3,4,5,6] as [1,1,0,2,1,5] (RLE([1,0,0,1,1,1,1,1]) ⇒ RleIntDiff[1,1,0,2,1,5])\n */\nexport class RleIntDiffEncoder extends Encoder {\n /**\n * @param {number} start\n */\n constructor (start) {\n super()\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n this.count = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.s === v && this.count > 0) {\n this.count++\n } else {\n if (this.count > 0) {\n // flush counter, unless this is the first value (count = 0)\n writeVarUint(this, this.count - 1) // since count is always > 0, we can decrement by one. non-standard encoding ftw\n }\n this.count = 1\n // write first value\n writeVarInt(this, v - this.s)\n this.s = v\n }\n }\n}\n\n/**\n * @param {UintOptRleEncoder} encoder\n */\nconst flushUintOptRleEncoder = encoder => {\n if (encoder.count > 0) {\n // flush counter, unless this is the first value (count = 0)\n // case 1: just a single value. set sign to positive\n // case 2: write several values. set sign to negative to indicate that there is a length coming\n writeVarInt(encoder.encoder, encoder.count === 1 ? encoder.s : -encoder.s)\n if (encoder.count > 1) {\n writeVarUint(encoder.encoder, encoder.count - 2) // since count is always > 1, we can decrement by one. non-standard encoding ftw\n }\n }\n}\n\n/**\n * Optimized Rle encoder that does not suffer from the mentioned problem of the basic Rle encoder.\n *\n * Internally uses VarInt encoder to write unsigned integers. If the input occurs multiple times, we write\n * write it as a negative number. The UintOptRleDecoder then understands that it needs to read a count.\n *\n * Encodes [1,2,3,3,3] as [1,2,-3,3] (once 1, once 2, three times 3)\n */\nexport class UintOptRleEncoder {\n constructor () {\n this.encoder = new Encoder()\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.s === v) {\n this.count++\n } else {\n flushUintOptRleEncoder(this)\n this.count = 1\n this.s = v\n }\n }\n\n /**\n * Flush the encoded state and transform this to a Uint8Array.\n *\n * Note that this should only be called once.\n */\n toUint8Array () {\n flushUintOptRleEncoder(this)\n return toUint8Array(this.encoder)\n }\n}\n\n/**\n * Increasing Uint Optimized RLE Encoder\n *\n * The RLE encoder counts the number of same occurences of the same value.\n * The IncUintOptRle encoder counts if the value increases.\n * I.e. 7, 8, 9, 10 will be encoded as [-7, 4]. 1, 3, 5 will be encoded\n * as [1, 3, 5].\n */\nexport class IncUintOptRleEncoder {\n constructor () {\n this.encoder = new Encoder()\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.s + this.count === v) {\n this.count++\n } else {\n flushUintOptRleEncoder(this)\n this.count = 1\n this.s = v\n }\n }\n\n /**\n * Flush the encoded state and transform this to a Uint8Array.\n *\n * Note that this should only be called once.\n */\n toUint8Array () {\n flushUintOptRleEncoder(this)\n return toUint8Array(this.encoder)\n }\n}\n\n/**\n * @param {IntDiffOptRleEncoder} encoder\n */\nconst flushIntDiffOptRleEncoder = encoder => {\n if (encoder.count > 0) {\n // 31 bit making up the diff | wether to write the counter\n // const encodedDiff = encoder.diff << 1 | (encoder.count === 1 ? 0 : 1)\n const encodedDiff = encoder.diff * 2 + (encoder.count === 1 ? 0 : 1)\n // flush counter, unless this is the first value (count = 0)\n // case 1: just a single value. set first bit to positive\n // case 2: write several values. set first bit to negative to indicate that there is a length coming\n writeVarInt(encoder.encoder, encodedDiff)\n if (encoder.count > 1) {\n writeVarUint(encoder.encoder, encoder.count - 2) // since count is always > 1, we can decrement by one. non-standard encoding ftw\n }\n }\n}\n\n/**\n * A combination of the IntDiffEncoder and the UintOptRleEncoder.\n *\n * The count approach is similar to the UintDiffOptRleEncoder, but instead of using the negative bitflag, it encodes\n * in the LSB whether a count is to be read. Therefore this Encoder only supports 31 bit integers!\n *\n * Encodes [1, 2, 3, 2] as [3, 1, 6, -1] (more specifically [(1 << 1) | 1, (3 << 0) | 0, -1])\n *\n * Internally uses variable length encoding. Contrary to normal UintVar encoding, the first byte contains:\n * * 1 bit that denotes whether the next value is a count (LSB)\n * * 1 bit that denotes whether this value is negative (MSB - 1)\n * * 1 bit that denotes whether to continue reading the variable length integer (MSB)\n *\n * Therefore, only five bits remain to encode diff ranges.\n *\n * Use this Encoder only when appropriate. In most cases, this is probably a bad idea.\n */\nexport class IntDiffOptRleEncoder {\n constructor () {\n this.encoder = new Encoder()\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n this.diff = 0\n }\n\n /**\n * @param {number} v\n */\n write (v) {\n if (this.diff === v - this.s) {\n this.s = v\n this.count++\n } else {\n flushIntDiffOptRleEncoder(this)\n this.count = 1\n this.diff = v - this.s\n this.s = v\n }\n }\n\n /**\n * Flush the encoded state and transform this to a Uint8Array.\n *\n * Note that this should only be called once.\n */\n toUint8Array () {\n flushIntDiffOptRleEncoder(this)\n return toUint8Array(this.encoder)\n }\n}\n\n/**\n * Optimized String Encoder.\n *\n * Encoding many small strings in a simple Encoder is not very efficient. The function call to decode a string takes some time and creates references that must be eventually deleted.\n * In practice, when decoding several million small strings, the GC will kick in more and more often to collect orphaned string objects (or maybe there is another reason?).\n *\n * This string encoder solves the above problem. All strings are concatenated and written as a single string using a single encoding call.\n *\n * The lengths are encoded using a UintOptRleEncoder.\n */\nexport class StringEncoder {\n constructor () {\n /**\n * @type {Array<string>}\n */\n this.sarr = []\n this.s = ''\n this.lensE = new UintOptRleEncoder()\n }\n\n /**\n * @param {string} string\n */\n write (string) {\n this.s += string\n if (this.s.length > 19) {\n this.sarr.push(this.s)\n this.s = ''\n }\n this.lensE.write(string.length)\n }\n\n toUint8Array () {\n const encoder = new Encoder()\n this.sarr.push(this.s)\n this.s = ''\n writeVarString(encoder, this.sarr.join(''))\n writeUint8Array(encoder, this.lensE.toUint8Array())\n return toUint8Array(encoder)\n }\n}\n","/**\n * Error helpers.\n *\n * @module error\n */\n\n/**\n * @param {string} s\n * @return {Error}\n */\n/* c8 ignore next */\nexport const create = s => new Error(s)\n\n/**\n * @throws {Error}\n * @return {never}\n */\n/* c8 ignore next 3 */\nexport const methodUnimplemented = () => {\n throw create('Method unimplemented')\n}\n\n/**\n * @throws {Error}\n * @return {never}\n */\n/* c8 ignore next 3 */\nexport const unexpectedCase = () => {\n throw create('Unexpected case')\n}\n","/**\n * Efficient schema-less binary decoding with support for variable length encoding.\n *\n * Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.\n *\n * Encodes numbers in little-endian order (least to most significant byte order)\n * and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)\n * which is also used in Protocol Buffers.\n *\n * ```js\n * // encoding step\n * const encoder = encoding.createEncoder()\n * encoding.writeVarUint(encoder, 256)\n * encoding.writeVarString(encoder, 'Hello world!')\n * const buf = encoding.toUint8Array(encoder)\n * ```\n *\n * ```js\n * // decoding step\n * const decoder = decoding.createDecoder(buf)\n * decoding.readVarUint(decoder) // => 256\n * decoding.readVarString(decoder) // => 'Hello world!'\n * decoding.hasContent(decoder) // => false - all data is read\n * ```\n *\n * @module decoding\n */\n\nimport * as binary from './binary.js'\nimport * as math from './math.js'\nimport * as number from './number.js'\nimport * as string from './string.js'\nimport * as error from './error.js'\nimport * as encoding from './encoding.js'\n\nconst errorUnexpectedEndOfArray = error.create('Unexpected end of array')\nconst errorIntegerOutOfRange = error.create('Integer out of Range')\n\n/**\n * A Decoder handles the decoding of an Uint8Array.\n */\nexport class Decoder {\n /**\n * @param {Uint8Array} uint8Array Binary data to decode\n */\n constructor (uint8Array) {\n /**\n * Decoding target.\n *\n * @type {Uint8Array}\n */\n this.arr = uint8Array\n /**\n * Current decoding position.\n *\n * @type {number}\n */\n this.pos = 0\n }\n}\n\n/**\n * @function\n * @param {Uint8Array} uint8Array\n * @return {Decoder}\n */\nexport const createDecoder = uint8Array => new Decoder(uint8Array)\n\n/**\n * @function\n * @param {Decoder} decoder\n * @return {boolean}\n */\nexport const hasContent = decoder => decoder.pos !== decoder.arr.length\n\n/**\n * Clone a decoder instance.\n * Optionally set a new position parameter.\n *\n * @function\n * @param {Decoder} decoder The decoder instance\n * @param {number} [newPos] Defaults to current position\n * @return {Decoder} A clone of `decoder`\n */\nexport const clone = (decoder, newPos = decoder.pos) => {\n const _decoder = createDecoder(decoder.arr)\n _decoder.pos = newPos\n return _decoder\n}\n\n/**\n * Create an Uint8Array view of the next `len` bytes and advance the position by `len`.\n *\n * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.\n * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.\n *\n * @function\n * @param {Decoder} decoder The decoder instance\n * @param {number} len The length of bytes to read\n * @return {Uint8Array}\n */\nexport const readUint8Array = (decoder, len) => {\n const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len)\n decoder.pos += len\n return view\n}\n\n/**\n * Read variable length Uint8Array.\n *\n * Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.\n * Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.\n *\n * @function\n * @param {Decoder} decoder\n * @return {Uint8Array}\n */\nexport const readVarUint8Array = decoder => readUint8Array(decoder, readVarUint(decoder))\n\n/**\n * Read the rest of the content as an ArrayBuffer\n * @function\n * @param {Decoder} decoder\n * @return {Uint8Array}\n */\nexport const readTailAsUint8Array = decoder => readUint8Array(decoder, decoder.arr.length - decoder.pos)\n\n/**\n * Skip one byte, jump to the next position.\n * @function\n * @param {Decoder} decoder The decoder instance\n * @return {number} The next position\n */\nexport const skip8 = decoder => decoder.pos++\n\n/**\n * Read one byte as unsigned integer.\n * @function\n * @param {Decoder} decoder The decoder instance\n * @return {number} Unsigned 8-bit integer\n */\nexport const readUint8 = decoder => decoder.arr[decoder.pos++]\n\n/**\n * Read 2 bytes as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const readUint16 = decoder => {\n const uint =\n decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8)\n decoder.pos += 2\n return uint\n}\n\n/**\n * Read 4 bytes as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const readUint32 = decoder => {\n const uint =\n (decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8) +\n (decoder.arr[decoder.pos + 2] << 16) +\n (decoder.arr[decoder.pos + 3] << 24)) >>> 0\n decoder.pos += 4\n return uint\n}\n\n/**\n * Read 4 bytes as unsigned integer in big endian order.\n * (most significant byte first)\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const readUint32BigEndian = decoder => {\n const uint =\n (decoder.arr[decoder.pos + 3] +\n (decoder.arr[decoder.pos + 2] << 8) +\n (decoder.arr[decoder.pos + 1] << 16) +\n (decoder.arr[decoder.pos] << 24)) >>> 0\n decoder.pos += 4\n return uint\n}\n\n/**\n * Look ahead without incrementing the position\n * to the next byte and read it as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const peekUint8 = decoder => decoder.arr[decoder.pos]\n\n/**\n * Look ahead without incrementing the position\n * to the next byte and read it as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const peekUint16 = decoder =>\n decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8)\n\n/**\n * Look ahead without incrementing the position\n * to the next byte and read it as unsigned integer.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.\n */\nexport const peekUint32 = decoder => (\n decoder.arr[decoder.pos] +\n (decoder.arr[decoder.pos + 1] << 8) +\n (decoder.arr[decoder.pos + 2] << 16) +\n (decoder.arr[decoder.pos + 3] << 24)\n) >>> 0\n\n/**\n * Read unsigned integer (32bit) with variable length.\n * 1/8th of the storage is used as encoding overhead.\n * * numbers < 2^7 is stored in one bytlength\n * * numbers < 2^14 is stored in two bylength\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.length\n */\nexport const readVarUint = decoder => {\n let num = 0\n let mult = 1\n const len = decoder.arr.length\n while (decoder.pos < len) {\n const r = decoder.arr[decoder.pos++]\n // num = num | ((r & binary.BITS7) << len)\n num = num + (r & binary.BITS7) * mult // shift $r << (7*#iterations) and add it to num\n mult *= 128 // next iteration, shift 7 \"more\" to the left\n if (r < binary.BIT8) {\n return num\n }\n /* c8 ignore start */\n if (num > number.MAX_SAFE_INTEGER) {\n throw errorIntegerOutOfRange\n }\n /* c8 ignore stop */\n }\n throw errorUnexpectedEndOfArray\n}\n\n/**\n * Read signed integer (32bit) with variable length.\n * 1/8th of the storage is used as encoding overhead.\n * * numbers < 2^7 is stored in one bytlength\n * * numbers < 2^14 is stored in two bylength\n * @todo This should probably create the inverse ~num if number is negative - but this would be a breaking change.\n *\n * @function\n * @param {Decoder} decoder\n * @return {number} An unsigned integer.length\n */\nexport const readVarInt = decoder => {\n let r = decoder.arr[decoder.pos++]\n let num = r & binary.BITS6\n let mult = 64\n const sign = (r & binary.BIT7) > 0 ? -1 : 1\n if ((r & binary.BIT8) === 0) {\n // don't continue reading\n return sign * num\n }\n const len = decoder.arr.length\n while (decoder.pos < len) {\n r = decoder.arr[decoder.pos++]\n // num = num | ((r & binary.BITS7) << len)\n num = num + (r & binary.BITS7) * mult\n mult *= 128\n if (r < binary.BIT8) {\n return sign * num\n }\n /* c8 ignore start */\n if (num > number.MAX_SAFE_INTEGER) {\n throw errorIntegerOutOfRange\n }\n /* c8 ignore stop */\n }\n throw errorUnexpectedEndOfArray\n}\n\n/**\n * Look ahead and read varUint without incrementing position\n *\n * @function\n * @param {Decoder} decoder\n * @return {number}\n */\nexport const peekVarUint = decoder => {\n const pos = decoder.pos\n const s = readVarUint(decoder)\n decoder.pos = pos\n return s\n}\n\n/**\n * Look ahead and read varUint without incrementing position\n *\n * @function\n * @param {Decoder} decoder\n * @return {number}\n */\nexport const peekVarInt = decoder => {\n const pos = decoder.pos\n const s = readVarInt(decoder)\n decoder.pos = pos\n return s\n}\n\n/**\n * We don't test this function anymore as we use native decoding/encoding by default now.\n * Better not modify this anymore..\n *\n * Transforming utf8 to a string is pretty expensive. The code performs 10x better\n * when String.fromCodePoint is fed with all characters as arguments.\n * But most environments have a maximum number of arguments per functions.\n * For effiency reasons we apply a maximum of 10000 characters at once.\n *\n * @function\n * @param {Decoder} decoder\n * @return {String} The read String.\n */\n/* c8 ignore start */\nexport const _readVarStringPolyfill = decoder => {\n let remainingLen = readVarUint(decoder)\n if (remainingLen === 0) {\n return ''\n } else {\n let encodedString = String.fromCodePoint(readUint8(decoder)) // remember to decrease remainingLen\n if (--remainingLen < 100) { // do not create a Uint8Array for small strings\n while (remainingLen--) {\n encodedString += String.fromCodePoint(readUint8(decoder))\n }\n } else {\n while (remainingLen > 0) {\n const nextLen = remainingLen < 10000 ? remainingLen : 10000\n // this is dangerous, we create a fresh array view from the existing buffer\n const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen)\n decoder.pos += nextLen\n // Starting with ES5.1 we can supply a generic array-like object as arguments\n encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes))\n remainingLen -= nextLen\n }\n }\n return decodeURIComponent(escape(encodedString))\n }\n}\n/* c8 ignore stop */\n\n/**\n * @function\n * @param {Decoder} decoder\n * @return {String} The read String\n */\nexport const _readVarStringNative = decoder =>\n /** @type any */ (string.utf8TextDecoder).decode(readVarUint8Array(decoder))\n\n/**\n * Read string of variable length\n * * varUint is used to store the length of the string\n *\n * @function\n * @param {Decoder} decoder\n * @return {String} The read String\n *\n */\n/* c8 ignore next */\nexport const readVarString = string.utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill\n\n/**\n * @param {Decoder} decoder\n * @return {Uint8Array}\n */\nexport const readTerminatedUint8Array = decoder => {\n const encoder = encoding.createEncoder()\n let b\n while (true) {\n b = readUint8(decoder)\n if (b === 0) {\n return encoding.toUint8Array(encoder)\n }\n if (b === 1) {\n b = readUint8(decoder)\n }\n encoding.write(encoder, b)\n }\n}\n\n/**\n * @param {Decoder} decoder\n * @return {string}\n */\nexport const readTerminatedString = decoder => string.decodeUtf8(readTerminatedUint8Array(decoder))\n\n/**\n * Look ahead and read varString without incrementing position\n *\n * @function\n * @param {Decoder} decoder\n * @return {string}\n */\nexport const peekVarString = decoder => {\n const pos = decoder.pos\n const s = readVarString(decoder)\n decoder.pos = pos\n return s\n}\n\n/**\n * @param {Decoder} decoder\n * @param {number} len\n * @return {DataView}\n */\nexport const readFromDataView = (decoder, len) => {\n const dv = new DataView(decoder.arr.buffer, decoder.arr.byteOffset + decoder.pos, len)\n decoder.pos += len\n return dv\n}\n\n/**\n * @param {Decoder} decoder\n */\nexport const readFloat32 = decoder => readFromDataView(decoder, 4).getFloat32(0, false)\n\n/**\n * @param {Decoder} decoder\n */\nexport const readFloat64 = decoder => readFromDataView(decoder, 8).getFloat64(0, false)\n\n/**\n * @param {Decoder} decoder\n */\nexport const readBigInt64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigInt64(0, false)\n\n/**\n * @param {Decoder} decoder\n */\nexport const readBigUint64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigUint64(0, false)\n\n/**\n * @type {Array<function(Decoder):any>}\n */\nconst readAnyLookupTable = [\n decoder => undefined, // CASE 127: undefined\n decoder => null, // CASE 126: null\n readVarInt, // CASE 125: integer\n readFloat32, // CASE 124: float32\n readFloat64, // CASE 123: float64\n readBigInt64, // CASE 122: bigint\n decoder => false, // CASE 121: boolean (false)\n decoder => true, // CASE 120: boolean (true)\n readVarString, // CASE 119: string\n decoder => { // CASE 118: object<string,any>\n const len = readVarUint(decoder)\n /**\n * @type {Object<string,any>}\n */\n const obj = {}\n for (let i = 0; i < len; i++) {\n const key = readVarString(decoder)\n obj[key] = readAny(decoder)\n }\n return obj\n },\n decoder => { // CASE 117: array<any>\n const len = readVarUint(decoder)\n const arr = []\n for (let i = 0; i < len; i++) {\n arr.push(readAny(decoder))\n }\n return arr\n },\n readVarUint8Array // CASE 116: Uint8Array\n]\n\n/**\n * @param {Decoder} decoder\n */\nexport const readAny = decoder => readAnyLookupTable[127 - readUint8(decoder)](decoder)\n\n/**\n * T must not be null.\n *\n * @template T\n */\nexport class RleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n * @param {function(Decoder):T} reader\n */\n constructor (uint8Array, reader) {\n super(uint8Array)\n /**\n * The reader\n */\n this.reader = reader\n /**\n * Current state\n * @type {T|null}\n */\n this.s = null\n this.count = 0\n }\n\n read () {\n if (this.count === 0) {\n this.s = this.reader(this)\n if (hasContent(this)) {\n this.count = readVarUint(this) + 1 // see encoder implementation for the reason why this is incremented\n } else {\n this.count = -1 // read the current value forever\n }\n }\n this.count--\n return /** @type {T} */ (this.s)\n }\n}\n\nexport class IntDiffDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n * @param {number} start\n */\n constructor (uint8Array, start) {\n super(uint8Array)\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n }\n\n /**\n * @return {number}\n */\n read () {\n this.s += readVarInt(this)\n return this.s\n }\n}\n\nexport class RleIntDiffDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n * @param {number} start\n */\n constructor (uint8Array, start) {\n super(uint8Array)\n /**\n * Current state\n * @type {number}\n */\n this.s = start\n this.count = 0\n }\n\n /**\n * @return {number}\n */\n read () {\n if (this.count === 0) {\n this.s += readVarInt(this)\n if (hasContent(this)) {\n this.count = readVarUint(this) + 1 // see encoder implementation for the reason why this is incremented\n } else {\n this.count = -1 // read the current value forever\n }\n }\n this.count--\n return /** @type {number} */ (this.s)\n }\n}\n\nexport class UintOptRleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n super(uint8Array)\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n read () {\n if (this.count === 0) {\n this.s = readVarInt(this)\n // if the sign is negative, we read the count too, otherwise count is 1\n const isNegative = math.isNegativeZero(this.s)\n this.count = 1\n if (isNegative) {\n this.s = -this.s\n this.count = readVarUint(this) + 2\n }\n }\n this.count--\n return /** @type {number} */ (this.s)\n }\n}\n\nexport class IncUintOptRleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n super(uint8Array)\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n }\n\n read () {\n if (this.count === 0) {\n this.s = readVarInt(this)\n // if the sign is negative, we read the count too, otherwise count is 1\n const isNegative = math.isNegativeZero(this.s)\n this.count = 1\n if (isNegative) {\n this.s = -this.s\n this.count = readVarUint(this) + 2\n }\n }\n this.count--\n return /** @type {number} */ (this.s++)\n }\n}\n\nexport class IntDiffOptRleDecoder extends Decoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n super(uint8Array)\n /**\n * @type {number}\n */\n this.s = 0\n this.count = 0\n this.diff = 0\n }\n\n /**\n * @return {number}\n */\n read () {\n if (this.count === 0) {\n const diff = readVarInt(this)\n // if the first bit is set, we read more data\n const hasCount = diff & 1\n this.diff = math.floor(diff / 2) // shift >> 1\n this.count = 1\n if (hasCount) {\n this.count = readVarUint(this) + 2\n }\n }\n this.s += this.diff\n this.count--\n return this.s\n }\n}\n\nexport class StringDecoder {\n /**\n * @param {Uint8Array} uint8Array\n */\n constructor (uint8Array) {\n this.decoder = new UintOptRleDecoder(uint8Array)\n this.str = readVarString(this.decoder)\n /**\n * @type {number}\n */\n this.spos = 0\n }\n\n /**\n * @return {string}\n */\n read () {\n const end = this.spos + this.decoder.read()\n const res = this.str.slice(this.spos, end)\n this.spos = end\n return res\n }\n}\n","import { webcrypto } from 'node:crypto'\n\nexport const subtle = /** @type {any} */ (webcrypto).subtle\nexport const getRandomValues = /** @type {any} */ (webcrypto).getRandomValues.bind(webcrypto)\n","/**\n * Isomorphic module for true random numbers / buffers / uuids.\n *\n * Attention: falls back to Math.random if the browser does not support crypto.\n *\n * @module random\n */\n\nimport * as math from './math.js'\nimport * as binary from './binary.js'\nimport { getRandomValues } from 'lib0/webcrypto'\n\nexport const rand = Math.random\n\nexport const uint32 = () => getRandomValues(new Uint32Array(1))[0]\n\nexport const uint53 = () => {\n const arr = getRandomValues(new Uint32Array(8))\n return (arr[0] & binary.BITS21) * (binary.BITS32 + 1) + (arr[1] >>> 0)\n}\n\n/**\n * @template T\n * @param {Array<T>} arr\n * @return {T}\n */\nexport const oneOf = arr => arr[math.floor(rand() * arr.length)]\n\n// @ts-ignore\nconst uuidv4Template = [1e7] + -1e3 + -4e3 + -8e3 + -1e11\n\n/**\n * @return {string}\n */\nexport const uuidv4 = () => uuidv4Template.replace(/[018]/g, /** @param {number} c */ c =>\n (c ^ uint32() & 15 >> c / 4).toString(16)\n)\n","/**\n * Utility module to work with time.\n *\n * @module time\n */\n\nimport * as metric from './metric.js'\nimport * as math from './math.js'\n\n/**\n * Return current time.\n *\n * @return {Date}\n */\nexport const getDate = () => new Date()\n\n/**\n * Return current unix time.\n *\n * @return {number}\n */\nexport const getUnixTime = Date.now\n\n/**\n * Transform time (in ms) to a human readable format. E.g. 1100 => 1.1s. 60s => 1min. .001 => 10μs.\n *\n * @param {number} d duration in milliseconds\n * @return {string} humanized approximation of time\n */\nexport const humanizeDuration = d => {\n if (d < 60000) {\n const p = metric.prefix(d, -1)\n return math.round(p.n * 100) / 100 + p.prefix + 's'\n }\n d = math.floor(d / 1000)\n const seconds = d % 60\n const minutes = math.floor(d / 60) % 60\n const hours = math.floor(d / 3600) % 24\n const days = math.floor(d / 86400)\n if (days > 0) {\n return days + 'd' + ((hours > 0 || minutes > 30) ? ' ' + (minutes > 30 ? hours + 1 : hours) + 'h' : '')\n }\n if (hours > 0) {\n /* c8 ignore next */\n return hours + 'h' + ((minutes > 0 || seconds > 30) ? ' ' + (seconds > 30 ? minutes + 1 : minutes) + 'min' : '')\n }\n return minutes + 'min' + (seconds > 0 ? ' ' + seconds + 's' : '')\n}\n","/**\n * Utility helpers to work with promises.\n *\n * @module promise\n */\n\nimport * as time from './time.js'\n\n/**\n * @template T\n * @callback PromiseResolve\n * @param {T|PromiseLike<T>} [result]\n */\n\n/**\n * @template T\n * @param {function(PromiseResolve<T>,function(Error):void):any} f\n * @return {Promise<T>}\n */\nexport const create = f => /** @type {Promise<T>} */ (new Promise(f))\n\n/**\n * @param {function(function():void,function(Error):void):void} f\n * @return {Promise<void>}\n */\nexport const createEmpty = f => new Promise(f)\n\n/**\n * `Promise.all` wait for all promises in the array to resolve and return the result\n * @template {unknown[] | []} PS\n *\n * @param {PS} ps\n * @return {Promise<{ -readonly [P in keyof PS]: Awaited<PS[P]> }>}\n */\nexport const all = Promise.all.bind(Promise)\n\n/**\n * @param {Error} [reason]\n * @return {Promise<never>}\n */\nexport const reject = reason => Promise.reject(reason)\n\n/**\n * @template T\n * @param {T|void} res\n * @return {Promise<T|void>}\n */\nexport const resolve = res => Promise.resolve(res)\n\n/**\n * @template T\n * @param {T} res\n * @return {Promise<T>}\n */\nexport const resolveWith = res => Promise.resolve(res)\n\n/**\n * @todo Next version, reorder parameters: check, [timeout, [intervalResolution]]\n * @deprecated use untilAsync instead\n *\n * @param {number} timeout\n * @param {function():boolean} check\n * @param {number} [intervalResolution]\n * @return {Promise<void>}\n */\nexport const until = (timeout, check, intervalResolution = 10) => create((resolve, reject) => {\n const startTime = time.getUnixTime()\n const hasTimeout = timeout > 0\n const untilInterval = () => {\n if (check()) {\n clearInterval(intervalHandle)\n resolve()\n } else if (hasTimeout) {\n /* c8 ignore else */\n if (time.getUnixTime() - startTime > timeout) {\n clearInterval(intervalHandle)\n reject(new Error('Timeout'))\n }\n }\n }\n const intervalHandle = setInterval(untilInterval, intervalResolution)\n})\n\n/**\n * @param {()=>Promise<boolean>|boolean} check\n * @param {number} timeout\n * @param {number} intervalResolution\n * @return {Promise<void>}\n */\nexport const untilAsync = async (check, timeout = 0, intervalResolution = 10) => {\n const startTime = time.getUnixTime()\n const noTimeout = timeout <= 0\n // eslint-disable-next-line no-unmodified-loop-condition\n while (noTimeout || time.getUnixTime() - startTime <= timeout) {\n if (await check()) return\n await wait(intervalResolution)\n }\n throw new Error('Timeout')\n}\n\n/**\n * @param {number} timeout\n * @return {Promise<undefined>}\n */\nexport const wait = timeout => create((resolve, _reject) => setTimeout(resolve, timeout))\n\n/**\n * Checks if an object is a promise using ducktyping.\n *\n * Promises are often polyfilled, so it makes sense to add some additional guarantees if the user of this\n * library has some insane environment where global Promise objects are overwritten.\n *\n * @param {any} p\n * @return {boolean}\n */\nexport const isPromise = p => p instanceof Promise || (p && p.then && p.catch && p.finally)\n","/**\n * Often used conditions.\n *\n * @module conditions\n */\n\n/**\n * @template T\n * @param {T|null|undefined} v\n * @return {T|null}\n */\n/* c8 ignore next */\nexport const undefinedToNull = v => v === undefined ? null : v\n","/* eslint-env browser */\n\n/**\n * Isomorphic variable storage.\n *\n * Uses LocalStorage in the browser and falls back to in-memory storage.\n *\n * @module storage\n */\n\n/* c8 ignore start */\nclass VarStoragePolyfill {\n constructor () {\n this.map = new Map()\n }\n\n /**\n * @param {string} key\n * @param {any} newValue\n */\n setItem (key, newValue) {\n this.map.set(key, newValue)\n }\n\n /**\n * @param {string} key\n */\n getItem (key) {\n return this.map.get(key)\n }\n}\n/* c8 ignore stop */\n\n/**\n * @type {any}\n */\nlet _localStorage = new VarStoragePolyfill()\nlet usePolyfill = true\n\n/* c8 ignore start */\ntry {\n // if the same-origin rule is violated, accessing localStorage might thrown an error\n if (typeof localStorage !== 'undefined' && localStorage) {\n _localStorage = localStorage\n usePolyfill = false\n }\n} catch (e) { }\n/* c8 ignore stop */\n\n/**\n * This is basically localStorage in browser, or a polyfill in nodejs\n */\n/* c8 ignore next */\nexport const varStorage = _localStorage\n\n/**\n * A polyfill for `addEventListener('storage', event => {..})` that does nothing if the polyfill is being used.\n *\n * @param {function({ key: string, newValue: string, oldValue: string }): void} eventHandler\n * @function\n */\n/* c8 ignore next */\nexport const onChange = eventHandler => usePolyfill || addEventListener('storage', /** @type {any} */ (eventHandler))\n\n/**\n * A polyfill for `removeEventListener('storage', event => {..})` that does nothing if the polyfill is being used.\n *\n * @param {function({ key: string, newValue: string, oldValue: string }): void} eventHandler\n * @function\n */\n/* c8 ignore next */\nexport const offChange = eventHandler => usePolyfill || removeEventListener('storage', /** @type {any} */ (eventHandler))\n","/**\n * Utility functions for working with EcmaScript objects.\n *\n * @module object\n */\n\n/**\n * @return {Object<string,any>} obj\n */\nexport const create = () => Object.create(null)\n\n/**\n * Object.assign\n */\nexport const assign = Object.assign\n\n/**\n * @param {Object<string,any>} obj\n */\nexport const keys = Object.keys\n\n/**\n * @template V\n * @param {{[key:string]: V}} obj\n * @return {Array<V>}\n */\nexport const values = Object.values\n\n/**\n * @template V\n * @param {{[k:string]:V}} obj\n * @param {function(V,string):any} f\n */\nexport const forEach = (obj, f) => {\n for (const key in obj) {\n f(obj[key], key)\n }\n}\n\n/**\n * @todo implement mapToArray & map\n *\n * @template R\n * @param {Object<string,any>} obj\n * @param {function(any,string):R} f\n * @return {Array<R>}\n */\nexport const map = (obj, f) => {\n const results = []\n for (const key in obj) {\n results.push(f(obj[key], key))\n }\n return results\n}\n\n/**\n * @deprecated use object.size instead\n * @param {Object<string,any>} obj\n * @return {number}\n */\nexport const length = obj => keys(obj).length\n\n/**\n * @param {Object<string,any>} obj\n * @return {number}\n */\nexport const size = obj => keys(obj).length\n\n/**\n * @template {{ [key:string|number|symbol]: any }} T\n * @param {T} obj\n * @param {(v:T[keyof T],k:keyof T)=>boolean} f\n * @return {boolean}\n */\nexport const some = (obj, f) => {\n for (const key in obj) {\n if (f(obj[key], key)) {\n return true\n }\n }\n return false\n}\n\n/**\n * @param {Object|null|undefined} obj\n */\nexport const isEmpty = obj => {\n // eslint-disable-next-line no-unreachable-loop\n for (const _k in obj) {\n return false\n }\n return true\n}\n\n/**\n * @template {{ [key:string|number|symbol]: any }} T\n * @param {T} obj\n * @param {(v:T[keyof T],k:keyof T)=>boolean} f\n * @return {boolean}\n */\nexport const every = (obj, f) => {\n for (const key in obj) {\n if (!f(obj[key], key)) {\n return false\n }\n }\n return true\n}\n\n/**\n * Calls `Object.prototype.hasOwnProperty`.\n *\n * @param {any} obj\n * @param {string|number|symbol} key\n * @return {boolean}\n */\nexport const hasProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key)\n\n/**\n * @param {Object<string,any>} a\n * @param {Object<string,any>} b\n * @return {boolean}\n */\nexport const equalFlat = (a, b) => a === b || (size(a) === size(b) && every(a, (val, key) => (val !== undefined || hasProperty(b, key)) && b[key] === val))\n\n/**\n * Make an object immutable. This hurts performance and is usually not needed if you perform good\n * coding practices.\n */\nexport const freeze = Object.freeze\n\n/**\n * Make an object and all its children immutable.\n * This *really* hurts performance and is usually not needed if you perform good coding practices.\n *\n * @template {any} T\n * @param {T} o\n * @return {Readonly<T>}\n */\nexport const deepFreeze = (o) => {\n for (const key in o) {\n const c = o[key]\n if (typeof c === 'object' || typeof c === 'function') {\n deepFreeze(o[key])\n }\n }\n return freeze(o)\n}\n\n/**\n * Get object property. Create T if property is undefined and set T on object.\n *\n * @function\n * @template {object} KV\n * @template {keyof KV} [K=keyof KV]\n * @param {KV} o\n * @param {K} key\n * @param {() => KV[K]} createT\n * @return {KV[K]}\n */\nexport const setIfUndefined = (o, key, createT) => hasProperty(o, key) ? o[key] : (o[key] = createT())\n","/**\n * Common functions and function call helpers.\n *\n * @module function\n */\n\nimport * as array from './array.js'\nimport * as object from './object.js'\nimport * as traits from './traits.js'\n\n/**\n * Calls all functions in `fs` with args. Only throws after all functions were called.\n *\n * @param {Array<function>} fs\n * @param {Array<any>} args\n */\nexport const callAll = (fs, args, i = 0) => {\n try {\n for (; i < fs.length; i++) {\n fs[i](...args)\n }\n } finally {\n if (i < fs.length) {\n callAll(fs, args, i + 1)\n }\n }\n}\n\nexport const nop = () => {}\n\n/**\n * @template T\n * @param {function():T} f\n * @return {T}\n */\nexport const apply = f => f()\n\n/**\n * @template A\n *\n * @param {A} a\n * @return {A}\n */\nexport const id = a => a\n\n/**\n * @template T\n *\n * @param {T} a\n * @param {T} b\n * @return {boolean}\n */\nexport const equalityStrict = (a, b) => a === b\n\n/**\n * @template T\n *\n * @param {Array<T>|object} a\n * @param {Array<T>|object} b\n * @return {boolean}\n */\nexport const equalityFlat = (a, b) => a === b || (a != null && b != null && a.constructor === b.constructor && ((array.isArray(a) && array.equalFlat(a, /** @type {Array<T>} */ (b))) || (typeof a === 'object' && object.equalFlat(a, b))))\n\n/* c8 ignore start */\n\n/**\n * @param {any} a\n * @param {any} b\n * @return {boolean}\n */\nexport const equalityDeep = (a, b) => {\n if (a === b) {\n return true\n }\n if (a == null || b == null || a.constructor !== b.constructor) {\n return false\n }\n if (a[traits.EqualityTraitSymbol] != null) {\n return a[traits.EqualityTraitSymbol](b)\n }\n switch (a.constructor) {\n case ArrayBuffer:\n a = new Uint8Array(a)\n b = new Uint8Array(b)\n // eslint-disable-next-line no-fallthrough\n case Uint8Array: {\n if (a.byteLength !== b.byteLength) {\n return false\n }\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) {\n return false\n }\n }\n break\n }\n case Set: {\n if (a.size !== b.size) {\n return false\n }\n for (const value of a) {\n if (!b.has(value)) {\n return false\n }\n }\n break\n }\n case Map: {\n if (a.size !== b.size) {\n return false\n }\n for (const key of a.keys()) {\n if (!b.has(key) || !equalityDeep(a.get(key), b.get(key))) {\n return false\n }\n }\n break\n }\n case Object:\n if (object.length(a) !== object.length(b)) {\n return false\n }\n for (const key in a) {\n if (!object.hasProperty(a, key) || !equalityDeep(a[key], b[key])) {\n return false\n }\n }\n break\n case Array:\n if (a.length !== b.length) {\n return false\n }\n for (let i = 0; i < a.length; i++) {\n if (!equalityDeep(a[i], b[i])) {\n return false\n }\n }\n break\n default:\n return false\n }\n return true\n}\n\n/**\n * @template V\n * @template {V} OPTS\n *\n * @param {V} value\n * @param {Array<OPTS>} options\n */\n// @ts-ignore\nexport const isOneOf = (value, options) => options.includes(value)\n/* c8 ignore stop */\n\nexport const isArray = array.isArray\n\n/**\n * @param {any} s\n * @return {s is String}\n */\nexport const isString = (s) => s && s.constructor === String\n\n/**\n * @param {any} n\n * @return {n is Number}\n */\nexport const isNumber = n => n != null && n.constructor === Number\n\n/**\n * @template {abstract new (...args: any) => any} TYPE\n * @param {any} n\n * @param {TYPE} T\n * @return {n is InstanceType<TYPE>}\n */\nexport const is = (n, T) => n && n.constructor === T\n\n/**\n * @template {abstract new (...args: any) => any} TYPE\n * @param {TYPE} T\n */\nexport const isTemplate = (T) =>\n /**\n * @param {any} n\n * @return {n is InstanceType<TYPE>}\n **/\n n => n && n.constructor === T\n","/**\n * Isomorphic module to work access the environment (query params, env variables).\n *\n * @module environment\n */\n\nimport * as map from './map.js'\nimport * as string from './string.js'\nimport * as conditions from './conditions.js'\nimport * as storage from './storage.js'\nimport * as f from './function.js'\n\n/* c8 ignore next 2 */\n// @ts-ignore\nexport const isNode = typeof process !== 'undefined' && process.release && /node|io\\.js/.test(process.release.name) && Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]'\n\n/* c8 ignore next */\nexport const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && !isNode\n/* c8 ignore next 3 */\nexport const isMac = typeof navigator !== 'undefined'\n ? /Mac/.test(navigator.platform)\n : false\n\n/**\n * @type {Map<string,string>}\n */\nlet params\nconst args = []\n\n/* c8 ignore start */\nconst computeParams = () => {\n if (params === undefined) {\n if (isNode) {\n params = map.create()\n const pargs = process.argv\n let currParamName = null\n for (let i = 0; i < pargs.length; i++) {\n const parg = pargs[i]\n if (parg[0] === '-') {\n if (currParamName !== null) {\n params.set(currParamName, '')\n }\n currParamName = parg\n } else {\n if (currParamName !== null) {\n params.set(currParamName, parg)\n currParamName = null\n } else {\n args.push(parg)\n }\n }\n }\n if (currParamName !== null) {\n params.set(currParamName, '')\n }\n // in ReactNative for example this would not be true (unless connected to the Remote Debugger)\n } else if (typeof location === 'object') {\n params = map.create(); // eslint-disable-next-line no-undef\n (location.search || '?').slice(1).split('&').forEach((kv) => {\n if (kv.length !== 0) {\n const [key, value] = kv.split('=')\n params.set(`--${string.fromCamelCase(key, '-')}`, value)\n params.set(`-${string.fromCamelCase(key, '-')}`, value)\n }\n })\n } else {\n params = map.create()\n }\n }\n return params\n}\n/* c8 ignore stop */\n\n/**\n * @param {string} name\n * @return {boolean}\n */\n/* c8 ignore next */\nexport const hasParam = (name) => computeParams().has(name)\n\n/**\n * @param {string} name\n * @param {string} defaultVal\n * @return {string}\n */\n/* c8 ignore next 2 */\nexport const getParam = (name, defaultVal) =>\n computeParams().get(name) || defaultVal\n\n/**\n * @param {string} name\n * @return {string|null}\n */\n/* c8 ignore next 4 */\nexport const getVariable = (name) =>\n isNode\n ? conditions.undefinedToNull(process.env[name.toUpperCase().replaceAll('-', '_')])\n : conditions.undefinedToNull(storage.varStorage.getItem(name))\n\n/**\n * @param {string} name\n * @return {string|null}\n */\n/* c8 ignore next 2 */\nexport const getConf = (name) =>\n computeParams().get('--' + name) || getVariable(name)\n\n/**\n * @param {string} name\n * @return {string}\n */\n/* c8 ignore next 5 */\nexport const ensureConf = (name) => {\n const c = getConf(name)\n if (c == null) throw new Error(`Expected configuration \"${name.toUpperCase().replaceAll('-', '_')}\"`)\n return c\n}\n\n/**\n * @param {string} name\n * @return {boolean}\n */\n/* c8 ignore next 2 */\nexport const hasConf = (name) =>\n hasParam('--' + name) || getVariable(name) !== null\n\n/* c8 ignore next */\nexport const production = hasConf('production')\n\n/* c8 ignore next 2 */\nconst forceColor = isNode &&\n f.isOneOf(process.env.FORCE_COLOR, ['true', '1', '2'])\n\n/* c8 ignore start */\n/**\n * Color is enabled by default if the terminal supports it.\n *\n * Explicitly enable color using `--color` parameter\n * Disable color using `--no-color` parameter or using `NO_COLOR=1` environment variable.\n * `FORCE_COLOR=1` enables color and takes precedence over all.\n */\nexport const supportsColor = forceColor || (\n !hasParam('--no-colors') && // @todo deprecate --no-colors\n !hasConf('no-color') &&\n (!isNode || process.stdout.isTTY) && (\n !isNode ||\n hasParam('--color') ||\n getVariable('COLORTERM') !== null ||\n (getVariable('TERM') || '').includes('color')\n )\n)\n/* c8 ignore stop */\n","/**\n * Utility functions to work with buffers (Uint8Array).\n *\n * @module buffer\n */\n\nimport * as string from './string.js'\nimport * as env from './environment.js'\nimport * as array from './array.js'\nimport * as math from './math.js'\nimport * as encoding from './encoding.js'\nimport * as decoding from './decoding.js'\n\n/**\n * @param {number} len\n */\nexport const createUint8ArrayFromLen = len => new Uint8Array(len)\n\n/**\n * Create Uint8Array with initial content from buffer\n *\n * @param {ArrayBuffer} buffer\n * @param {number} byteOffset\n * @param {number} length\n */\nexport const createUint8ArrayViewFromArrayBuffer = (buffer, byteOffset, length) => new Uint8Array(buffer, byteOffset, length)\n\n/**\n * Create Uint8Array with initial content from buffer\n *\n * @param {ArrayBuffer} buffer\n */\nexport const createUint8ArrayFromArrayBuffer = buffer => new Uint8Array(buffer)\n\n/* c8 ignore start */\n/**\n * @param {Uint8Array} bytes\n * @return {string}\n */\nconst toBase64Browser = bytes => {\n let s = ''\n for (let i = 0; i < bytes.byteLength; i++) {\n s += string.fromCharCode(bytes[i])\n }\n // eslint-disable-next-line no-undef\n return btoa(s)\n}\n/* c8 ignore stop */\n\n/**\n * @param {Uint8Array} bytes\n * @return {string}\n */\nconst toBase64Node = bytes => Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('base64')\n\n/* c8 ignore start */\n/**\n * @param {string} s\n * @return {Uint8Array}\n */\nconst fromBase64Browser = s => {\n // eslint-disable-next-line no-undef\n const a = atob(s)\n const bytes = createUint8ArrayFromLen(a.length)\n for (let i = 0; i < a.length; i++) {\n bytes[i] = a.charCodeAt(i)\n }\n return bytes\n}\n/* c8 ignore stop */\n\n/**\n * @param {string} s\n */\nconst fromBase64Node = s => {\n const buf = Buffer.from(s, 'base64')\n return createUint8ArrayViewFromArrayBuffer(buf.buffer, buf.byteOffset, buf.byteLength)\n}\n\n/* c8 ignore next */\nexport const toBase64 = env.isBrowser ? toBase64Browser : toBase64Node\n\n/* c8 ignore next */\nexport const fromBase64 = env.isBrowser ? fromBase64Browser : fromBase64Node\n\n/**\n * Implements base64url - see https://datatracker.ietf.org/doc/html/rfc4648#section-5\n * @param {Uint8Array} buf\n */\nexport const toBase64UrlEncoded = buf => toBase64(buf).replaceAll('+', '-').replaceAll('/', '_').replaceAll('=', '')\n\n/**\n * @param {string} base64\n */\nexport const fromBase64UrlEncoded = base64 => fromBase64(base64.replaceAll('-', '+').replaceAll('_', '/'))\n\n/**\n * Base64 is always a more efficient choice. This exists for utility purposes only.\n *\n * @param {Uint8Array} buf\n */\nexport const toHexString = buf => array.map(buf, b => b.toString(16).padStart(2, '0')).join('')\n\n/**\n * Note: This function expects that the hex doesn't start with 0x..\n *\n * @param {string} hex\n */\nexport const fromHexString = hex => {\n const hlen = hex.length\n const buf = new Uint8Array(math.ceil(hlen / 2))\n for (let i = 0; i < hlen; i += 2) {\n buf[buf.length - i / 2 - 1] = Number.parseInt(hex.slice(hlen - i - 2, hlen - i), 16)\n }\n return buf\n}\n\n/**\n * Copy the content of an Uint8Array view to a new ArrayBuffer.\n *\n * @param {Uint8Array} uint8Array\n * @return {Uint8Array}\n */\nexport const copyUint8Array = uint8Array => {\n const newBuf = createUint8ArrayFromLen(uint8Array.byteLength)\n newBuf.set(uint8Array)\n return newBuf\n}\n\n/**\n * Encode anything as a UInt8Array. It's a pun on typescripts's `any` type.\n * See encoding.writeAny for more information.\n *\n * @param {any} data\n * @return {Uint8Array}\n */\nexport const encodeAny = data =>\n encoding.encode(encoder => encoding.writeAny(encoder, data))\n\n/**\n * Decode an any-encoded value.\n *\n * @param {Uint8Array} buf\n * @return {any}\n */\nexport const decodeAny = buf => decoding.readAny(decoding.createDecoder(buf))\n\n/**\n * Shift Byte Array {N} bits to the left. Does not expand byte array.\n *\n * @param {Uint8Array} bs\n * @param {number} N should be in the range of [0-7]\n */\nexport const shiftNBitsLeft = (bs, N) => {\n if (N === 0) return bs\n bs = new Uint8Array(bs)\n bs[0] <<= N\n for (let i = 1; i < bs.length; i++) {\n bs[i - 1] |= bs[i] >>> (8 - N)\n bs[i] <<= N\n }\n return bs\n}\n","/**\n * Utility module to work with EcmaScript Symbols.\n *\n * @module symbol\n */\n\n/**\n * Return fresh symbol.\n */\nexport const create = Symbol\n\n/**\n * @param {any} s\n * @return {boolean}\n */\nexport const isSymbol = s => typeof s === 'symbol'\n","import * as symbol from './symbol.js'\nimport * as time from './time.js'\nimport * as env from './environment.js'\nimport * as func from './function.js'\nimport * as json from './json.js'\n\nexport const BOLD = symbol.create()\nexport const UNBOLD = symbol.create()\nexport const BLUE = symbol.create()\nexport const GREY = symbol.create()\nexport const GREEN = symbol.create()\nexport const RED = symbol.create()\nexport const PURPLE = symbol.create()\nexport const ORANGE = symbol.create()\nexport const UNCOLOR = symbol.create()\n\n/* c8 ignore start */\n/**\n * @param {Array<undefined|string|Symbol|Object|number|function():any>} args\n * @return {Array<string|object|number|undefined>}\n */\nexport const computeNoColorLoggingArgs = args => {\n if (args.length === 1 && args[0]?.constructor === Function) {\n args = /** @type {Array<string|Symbol|Object|number>} */ (/** @type {[function]} */ (args)[0]())\n }\n const strBuilder = []\n const logArgs = []\n // try with formatting until we find something unsupported\n let i = 0\n for (; i < args.length; i++) {\n const arg = args[i]\n if (arg === undefined) {\n break\n } else if (arg.constructor === String || arg.constructor === Number) {\n strBuilder.push(arg)\n } else if (arg.constructor === Object) {\n break\n }\n }\n if (i > 0) {\n // create logArgs with what we have so far\n logArgs.push(strBuilder.join(''))\n }\n // append the rest\n for (; i < args.length; i++) {\n const arg = args[i]\n if (!(arg instanceof Symbol)) {\n logArgs.push(arg)\n }\n }\n return logArgs\n}\n/* c8 ignore stop */\n\nconst loggingColors = [GREEN, PURPLE, ORANGE, BLUE]\nlet nextColor = 0\nlet lastLoggingTime = time.getUnixTime()\n\n/* c8 ignore start */\n/**\n * @param {function(...any):void} _print\n * @param {string} moduleName\n * @return {function(...any):void}\n */\nexport const createModuleLogger = (_print, moduleName) => {\n const color = loggingColors[nextColor]\n const debugRegexVar = env.getVariable('log')\n const doLogging = debugRegexVar !== null &&\n (debugRegexVar === '*' || debugRegexVar === 'true' ||\n new RegExp(debugRegexVar, 'gi').test(moduleName))\n nextColor = (nextColor + 1) % loggingColors.length\n moduleName += ': '\n return !doLogging\n ? func.nop\n : (...args) => {\n if (args.length === 1 && args[0]?.constructor === Function) {\n args = args[0]()\n }\n const timeNow = time.getUnixTime()\n const timeDiff = timeNow - lastLoggingTime\n lastLoggingTime = timeNow\n _print(\n color,\n moduleName,\n UNCOLOR,\n ...args.map((arg) => {\n if (arg != null && arg.constructor === Uint8Array) {\n arg = Array.from(arg)\n }\n const t = typeof arg\n switch (t) {\n case 'string':\n case 'symbol':\n return arg\n default: {\n return json.stringify(arg)\n }\n }\n }),\n color,\n ' +' + timeDiff + 'ms'\n )\n }\n}\n/* c8 ignore stop */\n","/**\n * Isomorphic logging module with support for colors!\n *\n * @module logging\n */\n\nimport * as env from './environment.js'\nimport * as common from './logging.common.js'\n\nexport { BOLD, UNBOLD, BLUE, GREY, GREEN, RED, PURPLE, ORANGE, UNCOLOR } from './logging.common.js'\n\nconst _nodeStyleMap = {\n [common.BOLD]: '\\u001b[1m',\n [common.UNBOLD]: '\\u001b[2m',\n [common.BLUE]: '\\x1b[34m',\n [common.GREEN]: '\\x1b[32m',\n [common.GREY]: '\\u001b[37m',\n [common.RED]: '\\x1b[31m',\n [common.PURPLE]: '\\x1b[35m',\n [common.ORANGE]: '\\x1b[38;5;208m',\n [common.UNCOLOR]: '\\x1b[0m'\n}\n\n/* c8 ignore start */\n/**\n * @param {Array<string|undefined|Symbol|Object|number|function():Array<any>>} args\n * @return {Array<string|object|number|undefined>}\n */\nconst computeNodeLoggingArgs = (args) => {\n if (args.length === 1 && args[0]?.constructor === Function) {\n args = /** @type {Array<string|Symbol|Object|number>} */ (/** @type {[function]} */ (args)[0]())\n }\n const strBuilder = []\n const logArgs = []\n // try with formatting until we find something unsupported\n let i = 0\n for (; i < args.length; i++) {\n const arg = args[i]\n // @ts-ignore\n const style = _nodeStyleMap[arg]\n if (style !== undefined) {\n strBuilder.push(style)\n } else {\n if (arg === undefined) {\n break\n } else if (arg.constructor === String || arg.constructor === Number) {\n strBuilder.push(arg)\n } else {\n break\n }\n }\n }\n if (i > 0) {\n // create logArgs with what we have so far\n strBuilder.push('\\x1b[0m')\n logArgs.push(strBuilder.join(''))\n }\n // append the rest\n for (; i < args.length; i++) {\n const arg = args[i]\n if (!(arg instanceof Symbol)) {\n logArgs.push(arg)\n }\n }\n return logArgs\n}\n/* c8 ignore stop */\n\n/* c8 ignore start */\nconst computeLoggingArgs = env.supportsColor\n ? computeNodeLoggingArgs\n : common.computeNoColorLoggingArgs\n/* c8 ignore stop */\n\n/**\n * @param {Array<string|Symbol|Object|number|undefined>} args\n */\nexport const print = (...args) => {\n console.log(...computeLoggingArgs(args))\n}\n\n/* c8 ignore start */\n/**\n * @param {Array<string|Symbol|Object|number>} args\n */\nexport const warn = (...args) => {\n console.warn(...computeLoggingArgs(args))\n}\n/* c8 ignore stop */\n\n/**\n * @param {Error} err\n */\n/* c8 ignore start */\nexport const printError = (err) => {\n console.error(err)\n}\n/* c8 ignore stop */\n\n/**\n * @param {string} _url image location\n * @param {number} _height height of the image in pixel\n */\n/* c8 ignore start */\nexport const printImg = (_url, _height) => {\n // console.log('%c ', `font-size: ${height}x; background: url(${url}) no-repeat;`)\n}\n/* c8 ignore stop */\n\n/**\n * @param {string} base64\n * @param {number} height\n */\n/* c8 ignore next 2 */\nexport const printImgBase64 = (base64, height) =>\n printImg(`data:image/gif;base64,${base64}`, height)\n\n/**\n * @param {Array<string|Symbol|Object|number>} args\n */\n/* c8 ignore next 3 */\nexport const group = (...args) => {\n console.group(...computeLoggingArgs(args))\n}\n\n/**\n * @param {Array<string|Symbol|Object|number>} args\n */\n/* c8 ignore next 3 */\nexport const groupCollapsed = (...args) => {\n console.groupCollapsed(...computeLoggingArgs(args))\n}\n\n/* c8 ignore next 3 */\nexport const groupEnd = () => {\n console.groupEnd()\n}\n\n/**\n * @param {function():Node} _createNode\n */\n/* c8 ignore next 2 */\nexport const printDom = (_createNode) => {}\n\n/**\n * @param {HTMLCanvasElement} canvas\n * @param {number} height\n */\n/* c8 ignore next 2 */\nexport const printCanvas = (canvas, height) =>\n printImg(canvas.toDataURL(), height)\n\n/**\n * @param {Element} _dom\n */\n/* c8 ignore next */\nexport const createVConsole = (_dom) => {}\n\n/**\n * @param {string} moduleName\n * @return {function(...any):void}\n */\n/* c8 ignore next */\nexport const createModuleLogger = (moduleName) => common.createModuleLogger(print, moduleName)\n","/**\n * Utility module to create and manipulate Iterators.\n *\n * @module iterator\n */\n\n/**\n * @template T,R\n * @param {Iterator<T>} iterator\n * @param {function(T):R} f\n * @return {IterableIterator<R>}\n */\nexport const mapIterator = (iterator, f) => ({\n [Symbol.iterator] () {\n return this\n },\n // @ts-ignore\n next () {\n const r = iterator.next()\n return { value: r.done ? undefined : f(r.value), done: r.done }\n }\n})\n\n/**\n * @template T\n * @param {function():IteratorResult<T>} next\n * @return {IterableIterator<T>}\n */\nexport const createIterator = next => ({\n /**\n * @return {IterableIterator<T>}\n */\n [Symbol.iterator] () {\n return this\n },\n // @ts-ignore\n next\n})\n\n/**\n * @template T\n * @param {Iterator<T>} iterator\n * @param {function(T):boolean} filter\n */\nexport const iteratorFilter = (iterator, filter) => createIterator(() => {\n let res\n do {\n res = iterator.next()\n } while (!res.done && !filter(res.value))\n return res\n})\n\n/**\n * @template T,M\n * @param {Iterator<T>} iterator\n * @param {function(T):M} fmap\n */\nexport const iteratorMap = (iterator, fmap) => createIterator(() => {\n const { done, value } = iterator.next()\n return { done, value: done ? undefined : fmap(value) }\n})\n","import {\n findIndexSS,\n getState,\n splitItem,\n iterateStructs,\n UpdateEncoderV2,\n DSDecoderV1, DSEncoderV1, DSDecoderV2, DSEncoderV2, Item, GC, StructStore, Transaction, ID // eslint-disable-line\n} from '../internals.js'\n\nimport * as array from 'lib0/array'\nimport * as math from 'lib0/math'\nimport * as map from 'lib0/map'\nimport * as encoding from 'lib0/encoding'\nimport * as decoding from 'lib0/decoding'\n\nexport class DeleteItem {\n /**\n * @param {number} clock\n * @param {number} len\n */\n constructor (clock, len) {\n /**\n * @type {number}\n */\n this.clock = clock\n /**\n * @type {number}\n */\n this.len = len\n }\n}\n\n/**\n * We no longer maintain a DeleteStore. DeleteSet is a temporary object that is created when needed.\n * - When created in a transaction, it must only be accessed after sorting, and merging\n * - This DeleteSet is send to other clients\n * - We do not create a DeleteSet when we send a sync message. The DeleteSet message is created directly from StructStore\n * - We read a DeleteSet as part of a sync/update message. In this case the DeleteSet is already sorted and merged.\n */\nexport class DeleteSet {\n constructor () {\n /**\n * @type {Map<number,Array<DeleteItem>>}\n */\n this.clients = new Map()\n }\n}\n\n/**\n * Iterate over all structs that the DeleteSet gc's.\n *\n * @param {Transaction} transaction\n * @param {DeleteSet} ds\n * @param {function(GC|Item):void} f\n *\n * @function\n */\nexport const iterateDeletedStructs = (transaction, ds, f) =>\n ds.clients.forEach((deletes, clientid) => {\n const structs = /** @type {Array<GC|Item>} */ (transaction.doc.store.clients.get(clientid))\n if (structs != null) {\n const lastStruct = structs[structs.length - 1]\n const clockState = lastStruct.id.clock + lastStruct.length\n for (let i = 0, del = deletes[i]; i < deletes.length && del.clock < clockState; del = deletes[++i]) {\n iterateStructs(transaction, structs, del.clock, del.len, f)\n }\n }\n })\n\n/**\n * @param {Array<DeleteItem>} dis\n * @param {number} clock\n * @return {number|null}\n *\n * @private\n * @function\n */\nexport const findIndexDS = (dis, clock) => {\n let left = 0\n let right = dis.length - 1\n while (left <= right) {\n const midindex = math.floor((left + right) / 2)\n const mid = dis[midindex]\n const midclock = mid.clock\n if (midclock <= clock) {\n if (clock < midclock + mid.len) {\n return midindex\n }\n left = midindex + 1\n } else {\n right = midindex - 1\n }\n }\n return null\n}\n\n/**\n * @param {DeleteSet} ds\n * @param {ID} id\n * @return {boolean}\n *\n * @private\n * @function\n */\nexport const isDeleted = (ds, id) => {\n const dis = ds.clients.get(id.client)\n return dis !== undefined && findIndexDS(dis, id.clock) !== null\n}\n\n/**\n * @param {DeleteSet} ds\n *\n * @private\n * @function\n */\nexport const sortAndMergeDeleteSet = ds => {\n ds.clients.forEach(dels => {\n dels.sort((a, b) => a.clock - b.clock)\n // merge items without filtering or splicing the array\n // i is the current pointer\n // j refers to the current insert position for the pointed item\n // try to merge dels[i] into dels[j-1] or set dels[j]=dels[i]\n let i, j\n for (i = 1, j = 1; i < dels.length; i++) {\n const left = dels[j - 1]\n const right = dels[i]\n if (left.clock + left.len >= right.clock) {\n left.len = math.max(left.len, right.clock + right.len - left.clock)\n } else {\n if (j < i) {\n dels[j] = right\n }\n j++\n }\n }\n dels.length = j\n })\n}\n\n/**\n * @param {Array<DeleteSet>} dss\n * @return {DeleteSet} A fresh DeleteSet\n */\nexport const mergeDeleteSets = dss => {\n const merged = new DeleteSet()\n for (let dssI = 0; dssI < dss.length; dssI++) {\n dss[dssI].clients.forEach((delsLeft, client) => {\n if (!merged.clients.has(client)) {\n // Write all missing keys from current ds and all following.\n // If merged already contains `client` current ds has already been added.\n /**\n * @type {Array<DeleteItem>}\n */\n const dels = delsLeft.slice()\n for (let i = dssI + 1; i < dss.length; i++) {\n array.appendTo(dels, dss[i].clients.get(client) || [])\n }\n merged.clients.set(client, dels)\n }\n })\n }\n sortAndMergeDeleteSet(merged)\n return merged\n}\n\n/**\n * @param {DeleteSet} ds\n * @param {number} client\n * @param {number} clock\n * @param {number} length\n *\n * @private\n * @function\n */\nexport const addToDeleteSet = (ds, client, clock, length) => {\n map.setIfUndefined(ds.clients, client, () => /** @type {Array<DeleteItem>} */ ([])).push(new DeleteItem(clock, length))\n}\n\nexport const createDeleteSet = () => new DeleteSet()\n\n/**\n * @param {StructStore} ss\n * @return {DeleteSet} Merged and sorted DeleteSet\n *\n * @private\n * @function\n */\nexport const createDeleteSetFromStructStore = ss => {\n const ds = createDeleteSet()\n ss.clients.forEach((structs, client) => {\n /**\n * @type {Array<DeleteItem>}\n */\n const dsitems = []\n for (let i = 0; i < structs.length; i++) {\n const struct = structs[i]\n if (struct.deleted) {\n const clock = struct.id.clock\n let len = struct.length\n if (i + 1 < structs.length) {\n for (let next = structs[i + 1]; i + 1 < structs.length && next.deleted; next = structs[++i + 1]) {\n len += next.length\n }\n }\n dsitems.push(new DeleteItem(clock, len))\n }\n }\n if (dsitems.length > 0) {\n ds.clients.set(client, dsitems)\n }\n })\n return ds\n}\n\n/**\n * @param {DSEncoderV1 | DSEncoderV2} encoder\n * @param {DeleteSet} ds\n *\n * @private\n * @function\n */\nexport const writeDeleteSet = (encoder, ds) => {\n encoding.writeVarUint(encoder.restEncoder, ds.clients.size)\n\n // Ensure that the delete set is written in a deterministic order\n array.from(ds.clients.entries())\n .sort((a, b) => b[0] - a[0])\n .forEach(([client, dsitems]) => {\n encoder.resetDsCurVal()\n encoding.writeVarUint(encoder.restEncoder, client)\n const len = dsitems.length\n encoding.writeVarUint(encoder.restEncoder, len)\n for (let i = 0; i < len; i++) {\n const item = dsitems[i]\n encoder.writeDsClock(item.clock)\n encoder.writeDsLen(item.len)\n }\n })\n}\n\n/**\n * @param {DSDecoderV1 | DSDecoderV2} decoder\n * @return {DeleteSet}\n *\n * @private\n * @function\n */\nexport const readDeleteSet = decoder => {\n const ds = new DeleteSet()\n const numClients = decoding.readVarUint(decoder.restDecoder)\n for (let i = 0; i < numClients; i++) {\n decoder.resetDsCurVal()\n const client = decoding.readVarUint(decoder.restDecoder)\n const numberOfDeletes = decoding.readVarUint(decoder.restDecoder)\n if (numberOfDeletes > 0) {\n const dsField = map.setIfUndefined(ds.clients, client, () => /** @type {Array<DeleteItem>} */ ([]))\n for (let i = 0; i < numberOfDeletes; i++) {\n dsField.push(new DeleteItem(decoder.readDsClock(), decoder.readDsLen()))\n }\n }\n }\n return ds\n}\n\n/**\n * @todo YDecoder also contains references to String and other Decoders. Would make sense to exchange YDecoder.toUint8Array for YDecoder.DsToUint8Array()..\n */\n\n/**\n * @param {DSDecoderV1 | DSDecoderV2} decoder\n * @param {Transaction} transaction\n * @param {StructStore} store\n * @return {Uint8Array|null} Returns a v2 update containing all deletes that couldn't be applied yet; or null if all deletes were applied successfully.\n *\n * @private\n * @function\n */\nexport const readAndApplyDeleteSet = (decoder, transaction, store) => {\n const unappliedDS = new DeleteSet()\n const numClients = decoding.readVarUint(decoder.restDecoder)\n for (let i = 0; i < numClients; i++) {\n decoder.resetDsCurVal()\n const client = decoding.readVarUint(decoder.restDecoder)\n const numberOfDeletes = decoding.readVarUint(decoder.restDecoder)\n const structs = store.clients.get(client) || []\n const state = getState(store, client)\n for (let i = 0; i < numberOfDeletes; i++) {\n const clock = decoder.readDsClock()\n const clockEnd = clock + decoder.readDsLen()\n if (clock < state) {\n if (state < clockEnd) {\n addToDeleteSet(unappliedDS, client, state, clockEnd - state)\n }\n let index = findIndexSS(structs, clock)\n /**\n * We can ignore the case of GC and Delete structs, because we are going to skip them\n * @type {Item}\n */\n // @ts-ignore\n let struct = structs[index]\n // split the first item if necessary\n if (!struct.deleted && struct.id.clock < clock) {\n structs.splice(index + 1, 0, splitItem(transaction, struct, clock - struct.id.clock))\n index++ // increase we now want to use the next struct\n }\n while (index < structs.length) {\n // @ts-ignore\n struct = structs[index++]\n if (struct.id.clock < clockEnd) {\n if (!struct.deleted) {\n if (clockEnd < struct.id.clock + struct.length) {\n structs.splice(index, 0, splitItem(transaction, struct, clockEnd - struct.id.clock))\n }\n struct.delete(transaction)\n }\n } else {\n break\n }\n }\n } else {\n addToDeleteSet(unappliedDS, client, clock, clockEnd - clock)\n }\n }\n }\n if (unappliedDS.clients.size > 0) {\n const ds = new UpdateEncoderV2()\n encoding.writeVarUint(ds.restEncoder, 0) // encode 0 structs\n writeDeleteSet(ds, unappliedDS)\n return ds.toUint8Array()\n }\n return null\n}\n\n/**\n * @param {DeleteSet} ds1\n * @param {DeleteSet} ds2\n */\nexport const equalDeleteSets = (ds1, ds2) => {\n if (ds1.clients.size !== ds2.clients.size) return false\n for (const [client, deleteItems1] of ds1.clients.entries()) {\n const deleteItems2 = /** @type {Array<import('../internals.js').DeleteItem>} */ (ds2.clients.get(client))\n if (deleteItems2 === undefined || deleteItems1.length !== deleteItems2.length) return false\n for (let i = 0; i < deleteItems1.length; i++) {\n const di1 = deleteItems1[i]\n const di2 = deleteItems2[i]\n if (di1.clock !== di2.clock || di1.len !== di2.len) {\n return false\n }\n }\n }\n return true\n}\n","/**\n * @module Y\n */\n\nimport {\n StructStore,\n AbstractType,\n YArray,\n YText,\n YMap,\n YXmlElement,\n YXmlFragment,\n transact,\n ContentDoc, Item, Transaction, YEvent // eslint-disable-line\n} from '../internals.js'\n\nimport { ObservableV2 } from 'lib0/observable'\nimport * as random from 'lib0/random'\nimport * as map from 'lib0/map'\nimport * as array from 'lib0/array'\nimport * as promise from 'lib0/promise'\n\nexport const generateNewClientId = random.uint32\n\n/**\n * @typedef {Object} DocOpts\n * @property {boolean} [DocOpts.gc=true] Disable garbage collection (default: gc=true)\n * @property {function(Item):boolean} [DocOpts.gcFilter] Will be called before an Item is garbage collected. Return false to keep the Item.\n * @property {string} [DocOpts.guid] Define a globally unique identifier for this document\n * @property {string | null} [DocOpts.collectionid] Associate this document with a collection. This only plays a role if your provider has a concept of collection.\n * @property {any} [DocOpts.meta] Any kind of meta information you want to associate with this document. If this is a subdocument, remote peers will store the meta information as well.\n * @property {boolean} [DocOpts.autoLoad] If a subdocument, automatically load document. If this is a subdocument, remote peers will load the document as well automatically.\n * @property {boolean} [DocOpts.shouldLoad] Whether the document should be synced by the provider now. This is toggled to true when you call ydoc.load()\n */\n\n/**\n * @typedef {Object} DocEvents\n * @property {function(Doc):void} DocEvents.destroy\n * @property {function(Doc):void} DocEvents.load\n * @property {function(boolean, Doc):void} DocEvents.sync\n * @property {function(Uint8Array, any, Doc, Transaction):void} DocEvents.update\n * @property {function(Uint8Array, any, Doc, Transaction):void} DocEvents.updateV2\n * @property {function(Doc):void} DocEvents.beforeAllTransactions\n * @property {function(Transaction, Doc):void} DocEvents.beforeTransaction\n * @property {function(Transaction, Doc):void} DocEvents.beforeObserverCalls\n * @property {function(Transaction, Doc):void} DocEvents.afterTransaction\n * @property {function(Transaction, Doc):void} DocEvents.afterTransactionCleanup\n * @property {function(Doc, Array<Transaction>):void} DocEvents.afterAllTransactions\n * @property {function({ loaded: Set<Doc>, added: Set<Doc>, removed: Set<Doc> }, Doc, Transaction):void} DocEvents.subdocs\n */\n\n/**\n * A Yjs instance handles the state of shared data.\n * @extends ObservableV2<DocEvents>\n */\nexport class Doc extends ObservableV2 {\n /**\n * @param {DocOpts} opts configuration\n */\n constructor ({ guid = random.uuidv4(), collectionid = null, gc = true, gcFilter = () => true, meta = null, autoLoad = false, shouldLoad = true } = {}) {\n super()\n this.gc = gc\n this.gcFilter = gcFilter\n this.clientID = generateNewClientId()\n this.guid = guid\n this.collectionid = collectionid\n /**\n * @type {Map<string, AbstractType<YEvent<any>>>}\n */\n this.share = new Map()\n this.store = new StructStore()\n /**\n * @type {Transaction | null}\n */\n this._transaction = null\n /**\n * @type {Array<Transaction>}\n */\n this._transactionCleanups = []\n /**\n * @type {Set<Doc>}\n */\n this.subdocs = new Set()\n /**\n * If this document is a subdocument - a document integrated into another document - then _item is defined.\n * @type {Item?}\n */\n this._item = null\n this.shouldLoad = shouldLoad\n this.autoLoad = autoLoad\n this.meta = meta\n /**\n * This is set to true when the persistence provider loaded the document from the database or when the `sync` event fires.\n * Note that not all providers implement this feature. Provider authors are encouraged to fire the `load` event when the doc content is loaded from the database.\n *\n * @type {boolean}\n */\n this.isLoaded = false\n /**\n * This is set to true when the connection provider has successfully synced with a backend.\n * Note that when using peer-to-peer providers this event may not provide very useful.\n * Also note that not all providers implement this feature. Provider authors are encouraged to fire\n * the `sync` event when the doc has been synced (with `true` as a parameter) or if connection is\n * lost (with false as a parameter).\n */\n this.isSynced = false\n this.isDestroyed = false\n /**\n * Promise that resolves once the document has been loaded from a persistence provider.\n */\n this.whenLoaded = promise.create(resolve => {\n this.on('load', () => {\n this.isLoaded = true\n resolve(this)\n })\n })\n const provideSyncedPromise = () => promise.create(resolve => {\n /**\n * @param {boolean} isSynced\n */\n const eventHandler = (isSynced) => {\n if (isSynced === undefined || isSynced === true) {\n this.off('sync', eventHandler)\n resolve()\n }\n }\n this.on('sync', eventHandler)\n })\n this.on('sync', isSynced => {\n if (isSynced === false && this.isSynced) {\n this.whenSynced = provideSyncedPromise()\n }\n this.isSynced = isSynced === undefined || isSynced === true\n if (this.isSynced && !this.isLoaded) {\n this.emit('load', [this])\n }\n })\n /**\n * Promise that resolves once the document has been synced with a backend.\n * This promise is recreated when the connection is lost.\n * Note the documentation about the `isSynced` property.\n */\n this.whenSynced = provideSyncedPromise()\n }\n\n /**\n * Notify the parent document that you request to load data into this subdocument (if it is a subdocument).\n *\n * `load()` might be used in the future to request any provider to load the most current data.\n *\n * It is safe to call `load()` multiple times.\n */\n load () {\n const item = this._item\n if (item !== null && !this.shouldLoad) {\n transact(/** @type {any} */ (item.parent).doc, transaction => {\n transaction.subdocsLoaded.add(this)\n }, null, true)\n }\n this.shouldLoad = true\n }\n\n getSubdocs () {\n return this.subdocs\n }\n\n getSubdocGuids () {\n return new Set(array.from(this.subdocs).map(doc => doc.guid))\n }\n\n /**\n * Changes that happen inside of a transaction are bundled. This means that\n * the observer fires _after_ the transaction is finished and that all changes\n * that happened inside of the transaction are sent as one message to the\n * other peers.\n *\n * @template T\n * @param {function(Transaction):T} f The function that should be executed as a transaction\n * @param {any} [origin] Origin of who started the transaction. Will be stored on transaction.origin\n * @return T\n *\n * @public\n */\n transact (f, origin = null) {\n return transact(this, f, origin)\n }\n\n /**\n * Define a shared data type.\n *\n * Multiple calls of `ydoc.get(name, TypeConstructor)` yield the same result\n * and do not overwrite each other. I.e.\n * `ydoc.get(name, Y.Array) === ydoc.get(name, Y.Array)`\n *\n * After this method is called, the type is also available on `ydoc.share.get(name)`.\n *\n * *Best Practices:*\n * Define all types right after the Y.Doc instance is created and store them in a separate object.\n * Also use the typed methods `getText(name)`, `getArray(name)`, ..\n *\n * @template {typeof AbstractType<any>} Type\n * @example\n * const ydoc = new Y.Doc(..)\n * const appState = {\n * document: ydoc.getText('document')\n * comments: ydoc.getArray('comments')\n * }\n *\n * @param {string} name\n * @param {Type} TypeConstructor The constructor of the type definition. E.g. Y.Text, Y.Array, Y.Map, ...\n * @return {InstanceType<Type>} The created type. Constructed with TypeConstructor\n *\n * @public\n */\n get (name, TypeConstructor = /** @type {any} */ (AbstractType)) {\n const type = map.setIfUndefined(this.share, name, () => {\n // @ts-ignore\n const t = new TypeConstructor()\n t._integrate(this, null)\n return t\n })\n const Constr = type.constructor\n if (TypeConstructor !== AbstractType && Constr !== TypeConstructor) {\n if (Constr === AbstractType) {\n // @ts-ignore\n const t = new TypeConstructor()\n t._map = type._map\n type._map.forEach(/** @param {Item?} n */ n => {\n for (; n !== null; n = n.left) {\n // @ts-ignore\n n.parent = t\n }\n })\n t._start = type._start\n for (let n = t._start; n !== null; n = n.right) {\n n.parent = t\n }\n t._length = type._length\n this.share.set(name, t)\n t._integrate(this, null)\n return /** @type {InstanceType<Type>} */ (t)\n } else {\n throw new Error(`Type with the name ${name} has already been defined with a different constructor`)\n }\n }\n return /** @type {InstanceType<Type>} */ (type)\n }\n\n /**\n * @template T\n * @param {string} [name]\n * @return {YArray<T>}\n *\n * @public\n */\n getArray (name = '') {\n return /** @type {YArray<T>} */ (this.get(name, YArray))\n }\n\n /**\n * @param {string} [name]\n * @return {YText}\n *\n * @public\n */\n getText (name = '') {\n return this.get(name, YText)\n }\n\n /**\n * @template T\n * @param {string} [name]\n * @return {YMap<T>}\n *\n * @public\n */\n getMap (name = '') {\n return /** @type {YMap<T>} */ (this.get(name, YMap))\n }\n\n /**\n * @param {string} [name]\n * @return {YXmlElement}\n *\n * @public\n */\n getXmlElement (name = '') {\n return /** @type {YXmlElement<{[key:string]:string}>} */ (this.get(name, YXmlElement))\n }\n\n /**\n * @param {string} [name]\n * @return {YXmlFragment}\n *\n * @public\n */\n getXmlFragment (name = '') {\n return this.get(name, YXmlFragment)\n }\n\n /**\n * Converts the entire document into a js object, recursively traversing each yjs type\n * Doesn't log types that have not been defined (using ydoc.getType(..)).\n *\n * @deprecated Do not use this method and rather call toJSON directly on the shared types.\n *\n * @return {Object<string, any>}\n */\n toJSON () {\n /**\n * @type {Object<string, any>}\n */\n const doc = {}\n\n this.share.forEach((value, key) => {\n doc[key] = value.toJSON()\n })\n\n return doc\n }\n\n /**\n * Emit `destroy` event and unregister all event handlers.\n */\n destroy () {\n this.isDestroyed = true\n array.from(this.subdocs).forEach(subdoc => subdoc.destroy())\n const item = this._item\n if (item !== null) {\n this._item = null\n const content = /** @type {ContentDoc} */ (item.content)\n content.doc = new Doc({ guid: this.guid, ...content.opts, shouldLoad: false })\n content.doc._item = item\n transact(/** @type {any} */ (item).parent.doc, transaction => {\n const doc = content.doc\n if (!item.deleted) {\n transaction.subdocsAdded.add(doc)\n }\n transaction.subdocsRemoved.add(this)\n }, null, true)\n }\n // @ts-ignore\n this.emit('destroyed', [true]) // DEPRECATED!\n this.emit('destroy', [this])\n super.destroy()\n }\n}\n","import * as buffer from 'lib0/buffer'\nimport * as decoding from 'lib0/decoding'\nimport {\n ID, createID\n} from '../internals.js'\n\nexport class DSDecoderV1 {\n /**\n * @param {decoding.Decoder} decoder\n */\n constructor (decoder) {\n this.restDecoder = decoder\n }\n\n resetDsCurVal () {\n // nop\n }\n\n /**\n * @return {number}\n */\n readDsClock () {\n return decoding.readVarUint(this.restDecoder)\n }\n\n /**\n * @return {number}\n */\n readDsLen () {\n return decoding.readVarUint(this.restDecoder)\n }\n}\n\nexport class UpdateDecoderV1 extends DSDecoderV1 {\n /**\n * @return {ID}\n */\n readLeftID () {\n return createID(decoding.readVarUint(this.restDecoder), decoding.readVarUint(this.restDecoder))\n }\n\n /**\n * @return {ID}\n */\n readRightID () {\n return createID(decoding.readVarUint(this.restDecoder), decoding.readVarUint(this.restDecoder))\n }\n\n /**\n * Read the next client id.\n * Use this in favor of readID whenever possible to reduce the number of objects created.\n */\n readClient () {\n return decoding.readVarUint(this.restDecoder)\n }\n\n /**\n * @return {number} info An unsigned 8-bit integer\n */\n readInfo () {\n return decoding.readUint8(this.restDecoder)\n }\n\n /**\n * @return {string}\n */\n readString () {\n return decoding.readVarString(this.restDecoder)\n }\n\n /**\n * @return {boolean} isKey\n */\n readParentInfo () {\n return decoding.readVarUint(this.restDecoder) === 1\n }\n\n /**\n * @return {number} info An unsigned 8-bit integer\n */\n readTypeRef () {\n return decoding.readVarUint(this.restDecoder)\n }\n\n /**\n * Write len of a struct - well suited for Opt RLE encoder.\n *\n * @return {number} len\n */\n readLen () {\n return decoding.readVarUint(this.restDecoder)\n }\n\n /**\n * @return {any}\n */\n readAny () {\n return decoding.readAny(this.restDecoder)\n }\n\n /**\n * @return {Uint8Array}\n */\n readBuf () {\n return buffer.copyUint8Array(decoding.readVarUint8Array(this.restDecoder))\n }\n\n /**\n * Legacy implementation uses JSON parse. We use any-decoding in v2.\n *\n * @return {any}\n */\n readJSON () {\n return JSON.parse(decoding.readVarString(this.restDecoder))\n }\n\n /**\n * @return {string}\n */\n readKey () {\n return decoding.readVarString(this.restDecoder)\n }\n}\n\nexport class DSDecoderV2 {\n /**\n * @param {decoding.Decoder} decoder\n */\n constructor (decoder) {\n /**\n * @private\n */\n this.dsCurrVal = 0\n this.restDecoder = decoder\n }\n\n resetDsCurVal () {\n this.dsCurrVal = 0\n }\n\n /**\n * @return {number}\n */\n readDsClock () {\n this.dsCurrVal += decoding.readVarUint(this.restDecoder)\n return this.dsCurrVal\n }\n\n /**\n * @return {number}\n */\n readDsLen () {\n const diff = decoding.readVarUint(this.restDecoder) + 1\n this.dsCurrVal += diff\n return diff\n }\n}\n\nexport class UpdateDecoderV2 extends DSDecoderV2 {\n /**\n * @param {decoding.Decoder} decoder\n */\n constructor (decoder) {\n super(decoder)\n /**\n * List of cached keys. If the keys[id] does not exist, we read a new key\n * from stringEncoder and push it to keys.\n *\n * @type {Array<string>}\n */\n this.keys = []\n decoding.readVarUint(decoder) // read feature flag - currently unused\n this.keyClockDecoder = new decoding.IntDiffOptRleDecoder(decoding.readVarUint8Array(decoder))\n this.clientDecoder = new decoding.UintOptRleDecoder(decoding.readVarUint8Array(decoder))\n this.leftClockDecoder = new decoding.IntDiffOptRleDecoder(decoding.readVarUint8Array(decoder))\n this.rightClockDecoder = new decoding.IntDiffOptRleDecoder(decoding.readVarUint8Array(decoder))\n this.infoDecoder = new decoding.RleDecoder(decoding.readVarUint8Array(decoder), decoding.readUint8)\n this.stringDecoder = new decoding.StringDecoder(decoding.readVarUint8Array(decoder))\n this.parentInfoDecoder = new decoding.RleDecoder(decoding.readVarUint8Array(decoder), decoding.readUint8)\n this.typeRefDecoder = new decoding.UintOptRleDecoder(decoding.readVarUint8Array(decoder))\n this.lenDecoder = new decoding.UintOptRleDecoder(decoding.readVarUint8Array(decoder))\n }\n\n /**\n * @return {ID}\n */\n readLeftID () {\n return new ID(this.clientDecoder.read(), this.leftClockDecoder.read())\n }\n\n /**\n * @return {ID}\n */\n readRightID () {\n return new ID(this.clientDecoder.read(), this.rightClockDecoder.read())\n }\n\n /**\n * Read the next client id.\n * Use this in favor of readID whenever possible to reduce the number of objects created.\n */\n readClient () {\n return this.clientDecoder.read()\n }\n\n /**\n * @return {number} info An unsigned 8-bit integer\n */\n readInfo () {\n return /** @type {number} */ (this.infoDecoder.read())\n }\n\n /**\n * @return {string}\n */\n readString () {\n return this.stringDecoder.read()\n }\n\n /**\n * @return {boolean}\n */\n readParentInfo () {\n return this.parentInfoDecoder.read() === 1\n }\n\n /**\n * @return {number} An unsigned 8-bit integer\n */\n readTypeRef () {\n return this.typeRefDecoder.read()\n }\n\n /**\n * Write len of a struct - well suited for Opt RLE encoder.\n *\n * @return {number}\n */\n readLen () {\n return this.lenDecoder.read()\n }\n\n /**\n * @return {any}\n */\n readAny () {\n return decoding.readAny(this.restDecoder)\n }\n\n /**\n * @return {Uint8Array}\n */\n readBuf () {\n return decoding.readVarUint8Array(this.restDecoder)\n }\n\n /**\n * This is mainly here for legacy purposes.\n *\n * Initial we incoded objects using JSON. Now we use the much faster lib0/any-encoder. This method mainly exists for legacy purposes for the v1 encoder.\n *\n * @return {any}\n */\n readJSON () {\n return decoding.readAny(this.restDecoder)\n }\n\n /**\n * @return {string}\n */\n readKey () {\n const keyClock = this.keyClockDecoder.read()\n if (keyClock < this.keys.length) {\n return this.keys[keyClock]\n } else {\n const key = this.stringDecoder.read()\n this.keys.push(key)\n return key\n }\n }\n}\n","import * as error from 'lib0/error'\nimport * as encoding from 'lib0/encoding'\n\nimport {\n ID // eslint-disable-line\n} from '../internals.js'\n\nexport class DSEncoderV1 {\n constructor () {\n this.restEncoder = encoding.createEncoder()\n }\n\n toUint8Array () {\n return encoding.toUint8Array(this.restEncoder)\n }\n\n resetDsCurVal () {\n // nop\n }\n\n /**\n * @param {number} clock\n */\n writeDsClock (clock) {\n encoding.writeVarUint(this.restEncoder, clock)\n }\n\n /**\n * @param {number} len\n */\n writeDsLen (len) {\n encoding.writeVarUint(this.restEncoder, len)\n }\n}\n\nexport class UpdateEncoderV1 extends DSEncoderV1 {\n /**\n * @param {ID} id\n */\n writeLeftID (id) {\n encoding.writeVarUint(this.restEncoder, id.client)\n encoding.writeVarUint(this.restEncoder, id.clock)\n }\n\n /**\n * @param {ID} id\n */\n writeRightID (id) {\n encoding.writeVarUint(this.restEncoder, id.client)\n encoding.writeVarUint(this.restEncoder, id.clock)\n }\n\n /**\n * Use writeClient and writeClock instead of writeID if possible.\n * @param {number} client\n */\n writeClient (client) {\n encoding.writeVarUint(this.restEncoder, client)\n }\n\n /**\n * @param {number} info An unsigned 8-bit integer\n */\n writeInfo (info) {\n encoding.writeUint8(this.restEncoder, info)\n }\n\n /**\n * @param {string} s\n */\n writeString (s) {\n encoding.writeVarString(this.restEncoder, s)\n }\n\n /**\n * @param {boolean} isYKey\n */\n writeParentInfo (isYKey) {\n encoding.writeVarUint(this.restEncoder, isYKey ? 1 : 0)\n }\n\n /**\n * @param {number} info An unsigned 8-bit integer\n */\n writeTypeRef (info) {\n encoding.writeVarUint(this.restEncoder, info)\n }\n\n /**\n * Write len of a struct - well suited for Opt RLE encoder.\n *\n * @param {number} len\n */\n writeLen (len) {\n encoding.writeVarUint(this.restEncoder, len)\n }\n\n /**\n * @param {any} any\n */\n writeAny (any) {\n encoding.writeAny(this.restEncoder, any)\n }\n\n /**\n * @param {Uint8Array} buf\n */\n writeBuf (buf) {\n encoding.writeVarUint8Array(this.restEncoder, buf)\n }\n\n /**\n * @param {any} embed\n */\n writeJSON (embed) {\n encoding.writeVarString(this.restEncoder, JSON.stringify(embed))\n }\n\n /**\n * @param {string} key\n */\n writeKey (key) {\n encoding.writeVarString(this.restEncoder, key)\n }\n}\n\nexport class DSEncoderV2 {\n constructor () {\n this.restEncoder = encoding.createEncoder() // encodes all the rest / non-optimized\n this.dsCurrVal = 0\n }\n\n toUint8Array () {\n return encoding.toUint8Array(this.restEncoder)\n }\n\n resetDsCurVal () {\n this.dsCurrVal = 0\n }\n\n /**\n * @param {number} clock\n */\n writeDsClock (clock) {\n const diff = clock - this.dsCurrVal\n this.dsCurrVal = clock\n encoding.writeVarUint(this.restEncoder, diff)\n }\n\n /**\n * @param {number} len\n */\n writeDsLen (len) {\n if (len === 0) {\n error.unexpectedCase()\n }\n encoding.writeVarUint(this.restEncoder, len - 1)\n this.dsCurrVal += len\n }\n}\n\nexport class UpdateEncoderV2 extends DSEncoderV2 {\n constructor () {\n super()\n /**\n * @type {Map<string,number>}\n */\n this.keyMap = new Map()\n /**\n * Refers to the next unique key-identifier to me used.\n * See writeKey method for more information.\n *\n * @type {number}\n */\n this.keyClock = 0\n this.keyClockEncoder = new encoding.IntDiffOptRleEncoder()\n this.clientEncoder = new encoding.UintOptRleEncoder()\n this.leftClockEncoder = new encoding.IntDiffOptRleEncoder()\n this.rightClockEncoder = new encoding.IntDiffOptRleEncoder()\n this.infoEncoder = new encoding.RleEncoder(encoding.writeUint8)\n this.stringEncoder = new encoding.StringEncoder()\n this.parentInfoEncoder = new encoding.RleEncoder(encoding.writeUint8)\n this.typeRefEncoder = new encoding.UintOptRleEncoder()\n this.lenEncoder = new encoding.UintOptRleEncoder()\n }\n\n toUint8Array () {\n const encoder = encoding.createEncoder()\n encoding.writeVarUint(encoder, 0) // this is a feature flag that we might use in the future\n encoding.writeVarUint8Array(encoder, this.keyClockEncoder.toUint8Array())\n encoding.writeVarUint8Array(encoder, this.clientEncoder.toUint8Array())\n encoding.writeVarUint8Array(encoder, this.leftClockEncoder.toUint8Array())\n encoding.writeVarUint8Array(encoder, this.rightClockEncoder.toUint8Array())\n encoding.writeVarUint8Array(encoder, encoding.toUint8Array(this.infoEncoder))\n encoding.writeVarUint8Array(encoder, this.stringEncoder.toUint8Array())\n encoding.writeVarUint8Array(encoder, encoding.toUint8Array(this.parentInfoEncoder))\n encoding.writeVarUint8Array(encoder, this.typeRefEncoder.toUint8Array())\n encoding.writeVarUint8Array(encoder, this.lenEncoder.toUint8Array())\n // @note The rest encoder is appended! (note the missing var)\n encoding.writeUint8Array(encoder, encoding.toUint8Array(this.restEncoder))\n return encoding.toUint8Array(encoder)\n }\n\n /**\n * @param {ID} id\n */\n writeLeftID (id) {\n this.clientEncoder.write(id.client)\n this.leftClockEncoder.write(id.clock)\n }\n\n /**\n * @param {ID} id\n */\n writeRightID (id) {\n this.clientEncoder.write(id.client)\n this.rightClockEncoder.write(id.clock)\n }\n\n /**\n * @param {number} client\n */\n writeClient (client) {\n this.clientEncoder.write(client)\n }\n\n /**\n * @param {number} info An unsigned 8-bit integer\n */\n writeInfo (info) {\n this.infoEncoder.write(info)\n }\n\n /**\n * @param {string} s\n */\n writeString (s) {\n this.stringEncoder.write(s)\n }\n\n /**\n * @param {boolean} isYKey\n */\n writeParentInfo (isYKey) {\n this.parentInfoEncoder.write(isYKey ? 1 : 0)\n }\n\n /**\n * @param {number} info An unsigned 8-bit integer\n */\n writeTypeRef (info) {\n this.typeRefEncoder.write(info)\n }\n\n /**\n * Write len of a struct - well suited for Opt RLE encoder.\n *\n * @param {number} len\n */\n writeLen (len) {\n this.lenEncoder.write(len)\n }\n\n /**\n * @param {any} any\n */\n writeAny (any) {\n encoding.writeAny(this.restEncoder, any)\n }\n\n /**\n * @param {Uint8Array} buf\n */\n writeBuf (buf) {\n encoding.writeVarUint8Array(this.restEncoder, buf)\n }\n\n /**\n * This is mainly here for legacy purposes.\n *\n * Initial we incoded objects using JSON. Now we use the much faster lib0/any-encoder. This method mainly exists for legacy purposes for the v1 encoder.\n *\n * @param {any} embed\n */\n writeJSON (embed) {\n encoding.writeAny(this.restEncoder, embed)\n }\n\n /**\n * Property keys are often reused. For example, in y-prosemirror the key `bold` might\n * occur very often. For a 3d application, the key `position` might occur very often.\n *\n * We cache these keys in a Map and refer to them via a unique number.\n *\n * @param {string} key\n */\n writeKey (key) {\n const clock = this.keyMap.get(key)\n if (clock === undefined) {\n /**\n * @todo uncomment to introduce this feature finally\n *\n * Background. The ContentFormat object was always encoded using writeKey, but the decoder used to use readString.\n * Furthermore, I forgot to set the keyclock. So everything was working fine.\n *\n * However, this feature here is basically useless as it is not being used (it actually only consumes extra memory).\n *\n * I don't know yet how to reintroduce this feature..\n *\n * Older clients won't be able to read updates when we reintroduce this feature. So this should probably be done using a flag.\n *\n */\n // this.keyMap.set(key, this.keyClock)\n this.keyClockEncoder.write(this.keyClock++)\n this.stringEncoder.write(key)\n } else {\n this.keyClockEncoder.write(clock)\n }\n }\n}\n","/**\n * @module encoding\n */\n/*\n * We use the first five bits in the info flag for determining the type of the struct.\n *\n * 0: GC\n * 1: Item with Deleted content\n * 2: Item with JSON content\n * 3: Item with Binary content\n * 4: Item with String content\n * 5: Item with Embed content (for richtext content)\n * 6: Item with Format content (a formatting marker for richtext content)\n * 7: Item with Type\n */\n\nimport {\n findIndexSS,\n getState,\n createID,\n getStateVector,\n readAndApplyDeleteSet,\n writeDeleteSet,\n createDeleteSetFromStructStore,\n transact,\n readItemContent,\n UpdateDecoderV1,\n UpdateDecoderV2,\n UpdateEncoderV1,\n UpdateEncoderV2,\n DSEncoderV2,\n DSDecoderV1,\n DSEncoderV1,\n mergeUpdates,\n mergeUpdatesV2,\n Skip,\n diffUpdateV2,\n convertUpdateFormatV2ToV1,\n DSDecoderV2, Doc, Transaction, GC, Item, StructStore // eslint-disable-line\n} from '../internals.js'\n\nimport * as encoding from 'lib0/encoding'\nimport * as decoding from 'lib0/decoding'\nimport * as binary from 'lib0/binary'\nimport * as map from 'lib0/map'\nimport * as math from 'lib0/math'\nimport * as array from 'lib0/array'\n\n/**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {Array<GC|Item>} structs All structs by `client`\n * @param {number} client\n * @param {number} clock write structs starting with `ID(client,clock)`\n *\n * @function\n */\nconst writeStructs = (encoder, structs, client, clock) => {\n // write first id\n clock = math.max(clock, structs[0].id.clock) // make sure the first id exists\n const startNewStructs = findIndexSS(structs, clock)\n // write # encoded structs\n encoding.writeVarUint(encoder.restEncoder, structs.length - startNewStructs)\n encoder.writeClient(client)\n encoding.writeVarUint(encoder.restEncoder, clock)\n const firstStruct = structs[startNewStructs]\n // write first struct with an offset\n firstStruct.write(encoder, clock - firstStruct.id.clock)\n for (let i = startNewStructs + 1; i < structs.length; i++) {\n structs[i].write(encoder, 0)\n }\n}\n\n/**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {StructStore} store\n * @param {Map<number,number>} _sm\n *\n * @private\n * @function\n */\nexport const writeClientsStructs = (encoder, store, _sm) => {\n // we filter all valid _sm entries into sm\n const sm = new Map()\n _sm.forEach((clock, client) => {\n // only write if new structs are available\n if (getState(store, client) > clock) {\n sm.set(client, clock)\n }\n })\n getStateVector(store).forEach((_clock, client) => {\n if (!_sm.has(client)) {\n sm.set(client, 0)\n }\n })\n // write # states that were updated\n encoding.writeVarUint(encoder.restEncoder, sm.size)\n // Write items with higher client ids first\n // This heavily improves the conflict algorithm.\n array.from(sm.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => {\n writeStructs(encoder, /** @type {Array<GC|Item>} */ (store.clients.get(client)), client, clock)\n })\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder The decoder object to read data from.\n * @param {Doc} doc\n * @return {Map<number, { i: number, refs: Array<Item | GC> }>}\n *\n * @private\n * @function\n */\nexport const readClientsStructRefs = (decoder, doc) => {\n /**\n * @type {Map<number, { i: number, refs: Array<Item | GC> }>}\n */\n const clientRefs = map.create()\n const numOfStateUpdates = decoding.readVarUint(decoder.restDecoder)\n for (let i = 0; i < numOfStateUpdates; i++) {\n const numberOfStructs = decoding.readVarUint(decoder.restDecoder)\n /**\n * @type {Array<GC|Item>}\n */\n const refs = new Array(numberOfStructs)\n const client = decoder.readClient()\n let clock = decoding.readVarUint(decoder.restDecoder)\n // const start = performance.now()\n clientRefs.set(client, { i: 0, refs })\n for (let i = 0; i < numberOfStructs; i++) {\n const info = decoder.readInfo()\n switch (binary.BITS5 & info) {\n case 0: { // GC\n const len = decoder.readLen()\n refs[i] = new GC(createID(client, clock), len)\n clock += len\n break\n }\n case 10: { // Skip Struct (nothing to apply)\n // @todo we could reduce the amount of checks by adding Skip struct to clientRefs so we know that something is missing.\n const len = decoding.readVarUint(decoder.restDecoder)\n refs[i] = new Skip(createID(client, clock), len)\n clock += len\n break\n }\n default: { // Item with content\n /**\n * The optimized implementation doesn't use any variables because inlining variables is faster.\n * Below a non-optimized version is shown that implements the basic algorithm with\n * a few comments\n */\n const cantCopyParentInfo = (info & (binary.BIT7 | binary.BIT8)) === 0\n // If parent = null and neither left nor right are defined, then we know that `parent` is child of `y`\n // and we read the next string as parentYKey.\n // It indicates how we store/retrieve parent from `y.share`\n // @type {string|null}\n const struct = new Item(\n createID(client, clock),\n null, // left\n (info & binary.BIT8) === binary.BIT8 ? decoder.readLeftID() : null, // origin\n null, // right\n (info & binary.BIT7) === binary.BIT7 ? decoder.readRightID() : null, // right origin\n cantCopyParentInfo ? (decoder.readParentInfo() ? doc.get(decoder.readString()) : decoder.readLeftID()) : null, // parent\n cantCopyParentInfo && (info & binary.BIT6) === binary.BIT6 ? decoder.readString() : null, // parentSub\n readItemContent(decoder, info) // item content\n )\n /* A non-optimized implementation of the above algorithm:\n\n // The item that was originally to the left of this item.\n const origin = (info & binary.BIT8) === binary.BIT8 ? decoder.readLeftID() : null\n // The item that was originally to the right of this item.\n const rightOrigin = (info & binary.BIT7) === binary.BIT7 ? decoder.readRightID() : null\n const cantCopyParentInfo = (info & (binary.BIT7 | binary.BIT8)) === 0\n const hasParentYKey = cantCopyParentInfo ? decoder.readParentInfo() : false\n // If parent = null and neither left nor right are defined, then we know that `parent` is child of `y`\n // and we read the next string as parentYKey.\n // It indicates how we store/retrieve parent from `y.share`\n // @type {string|null}\n const parentYKey = cantCopyParentInfo && hasParentYKey ? decoder.readString() : null\n\n const struct = new Item(\n createID(client, clock),\n null, // left\n origin, // origin\n null, // right\n rightOrigin, // right origin\n cantCopyParentInfo && !hasParentYKey ? decoder.readLeftID() : (parentYKey !== null ? doc.get(parentYKey) : null), // parent\n cantCopyParentInfo && (info & binary.BIT6) === binary.BIT6 ? decoder.readString() : null, // parentSub\n readItemContent(decoder, info) // item content\n )\n */\n refs[i] = struct\n clock += struct.length\n }\n }\n }\n // console.log('time to read: ', performance.now() - start) // @todo remove\n }\n return clientRefs\n}\n\n/**\n * Resume computing structs generated by struct readers.\n *\n * While there is something to do, we integrate structs in this order\n * 1. top element on stack, if stack is not empty\n * 2. next element from current struct reader (if empty, use next struct reader)\n *\n * If struct causally depends on another struct (ref.missing), we put next reader of\n * `ref.id.client` on top of stack.\n *\n * At some point we find a struct that has no causal dependencies,\n * then we start emptying the stack.\n *\n * It is not possible to have circles: i.e. struct1 (from client1) depends on struct2 (from client2)\n * depends on struct3 (from client1). Therefore the max stack size is equal to `structReaders.length`.\n *\n * This method is implemented in a way so that we can resume computation if this update\n * causally depends on another update.\n *\n * @param {Transaction} transaction\n * @param {StructStore} store\n * @param {Map<number, { i: number, refs: (GC | Item)[] }>} clientsStructRefs\n * @return { null | { update: Uint8Array, missing: Map<number,number> } }\n *\n * @private\n * @function\n */\nconst integrateStructs = (transaction, store, clientsStructRefs) => {\n /**\n * @type {Array<Item | GC>}\n */\n const stack = []\n // sort them so that we take the higher id first, in case of conflicts the lower id will probably not conflict with the id from the higher user.\n let clientsStructRefsIds = array.from(clientsStructRefs.keys()).sort((a, b) => a - b)\n if (clientsStructRefsIds.length === 0) {\n return null\n }\n const getNextStructTarget = () => {\n if (clientsStructRefsIds.length === 0) {\n return null\n }\n let nextStructsTarget = /** @type {{i:number,refs:Array<GC|Item>}} */ (clientsStructRefs.get(clientsStructRefsIds[clientsStructRefsIds.length - 1]))\n while (nextStructsTarget.refs.length === nextStructsTarget.i) {\n clientsStructRefsIds.pop()\n if (clientsStructRefsIds.length > 0) {\n nextStructsTarget = /** @type {{i:number,refs:Array<GC|Item>}} */ (clientsStructRefs.get(clientsStructRefsIds[clientsStructRefsIds.length - 1]))\n } else {\n return null\n }\n }\n return nextStructsTarget\n }\n let curStructsTarget = getNextStructTarget()\n if (curStructsTarget === null) {\n return null\n }\n\n /**\n * @type {StructStore}\n */\n const restStructs = new StructStore()\n const missingSV = new Map()\n /**\n * @param {number} client\n * @param {number} clock\n */\n const updateMissingSv = (client, clock) => {\n const mclock = missingSV.get(client)\n if (mclock == null || mclock > clock) {\n missingSV.set(client, clock)\n }\n }\n /**\n * @type {GC|Item}\n */\n let stackHead = /** @type {any} */ (curStructsTarget).refs[/** @type {any} */ (curStructsTarget).i++]\n // caching the state because it is used very often\n const state = new Map()\n\n const addStackToRestSS = () => {\n for (const item of stack) {\n const client = item.id.client\n const inapplicableItems = clientsStructRefs.get(client)\n if (inapplicableItems) {\n // decrement because we weren't able to apply previous operation\n inapplicableItems.i--\n restStructs.clients.set(client, inapplicableItems.refs.slice(inapplicableItems.i))\n clientsStructRefs.delete(client)\n inapplicableItems.i = 0\n inapplicableItems.refs = []\n } else {\n // item was the last item on clientsStructRefs and the field was already cleared. Add item to restStructs and continue\n restStructs.clients.set(client, [item])\n }\n // remove client from clientsStructRefsIds to prevent users from applying the same update again\n clientsStructRefsIds = clientsStructRefsIds.filter(c => c !== client)\n }\n stack.length = 0\n }\n\n // iterate over all struct readers until we are done\n while (true) {\n if (stackHead.constructor !== Skip) {\n const localClock = map.setIfUndefined(state, stackHead.id.client, () => getState(store, stackHead.id.client))\n const offset = localClock - stackHead.id.clock\n if (offset < 0) {\n // update from the same client is missing\n stack.push(stackHead)\n updateMissingSv(stackHead.id.client, stackHead.id.clock - 1)\n // hid a dead wall, add all items from stack to restSS\n addStackToRestSS()\n } else {\n const missing = stackHead.getMissing(transaction, store)\n if (missing !== null) {\n stack.push(stackHead)\n // get the struct reader that has the missing struct\n /**\n * @type {{ refs: Array<GC|Item>, i: number }}\n */\n const structRefs = clientsStructRefs.get(/** @type {number} */ (missing)) || { refs: [], i: 0 }\n if (structRefs.refs.length === structRefs.i) {\n // This update message causally depends on another update message that doesn't exist yet\n updateMissingSv(/** @type {number} */ (missing), getState(store, missing))\n addStackToRestSS()\n } else {\n stackHead = structRefs.refs[structRefs.i++]\n continue\n }\n } else if (offset === 0 || offset < stackHead.length) {\n // all fine, apply the stackhead\n stackHead.integrate(transaction, offset)\n state.set(stackHead.id.client, stackHead.id.clock + stackHead.length)\n }\n }\n }\n // iterate to next stackHead\n if (stack.length > 0) {\n stackHead = /** @type {GC|Item} */ (stack.pop())\n } else if (curStructsTarget !== null && curStructsTarget.i < curStructsTarget.refs.length) {\n stackHead = /** @type {GC|Item} */ (curStructsTarget.refs[curStructsTarget.i++])\n } else {\n curStructsTarget = getNextStructTarget()\n if (curStructsTarget === null) {\n // we are done!\n break\n } else {\n stackHead = /** @type {GC|Item} */ (curStructsTarget.refs[curStructsTarget.i++])\n }\n }\n }\n if (restStructs.clients.size > 0) {\n const encoder = new UpdateEncoderV2()\n writeClientsStructs(encoder, restStructs, new Map())\n // write empty deleteset\n // writeDeleteSet(encoder, new DeleteSet())\n encoding.writeVarUint(encoder.restEncoder, 0) // => no need for an extra function call, just write 0 deletes\n return { missing: missingSV, update: encoder.toUint8Array() }\n }\n return null\n}\n\n/**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {Transaction} transaction\n *\n * @private\n * @function\n */\nexport const writeStructsFromTransaction = (encoder, transaction) => writeClientsStructs(encoder, transaction.doc.store, transaction.beforeState)\n\n/**\n * Read and apply a document update.\n *\n * This function has the same effect as `applyUpdate` but accepts a decoder.\n *\n * @param {decoding.Decoder} decoder\n * @param {Doc} ydoc\n * @param {any} [transactionOrigin] This will be stored on `transaction.origin` and `.on('update', (update, origin))`\n * @param {UpdateDecoderV1 | UpdateDecoderV2} [structDecoder]\n *\n * @function\n */\nexport const readUpdateV2 = (decoder, ydoc, transactionOrigin, structDecoder = new UpdateDecoderV2(decoder)) =>\n transact(ydoc, transaction => {\n // force that transaction.local is set to non-local\n transaction.local = false\n let retry = false\n const doc = transaction.doc\n const store = doc.store\n // let start = performance.now()\n const ss = readClientsStructRefs(structDecoder, doc)\n // console.log('time to read structs: ', performance.now() - start) // @todo remove\n // start = performance.now()\n // console.log('time to merge: ', performance.now() - start) // @todo remove\n // start = performance.now()\n const restStructs = integrateStructs(transaction, store, ss)\n const pending = store.pendingStructs\n if (pending) {\n // check if we can apply something\n for (const [client, clock] of pending.missing) {\n if (clock < getState(store, client)) {\n retry = true\n break\n }\n }\n if (restStructs) {\n // merge restStructs into store.pending\n for (const [client, clock] of restStructs.missing) {\n const mclock = pending.missing.get(client)\n if (mclock == null || mclock > clock) {\n pending.missing.set(client, clock)\n }\n }\n pending.update = mergeUpdatesV2([pending.update, restStructs.update])\n }\n } else {\n store.pendingStructs = restStructs\n }\n // console.log('time to integrate: ', performance.now() - start) // @todo remove\n // start = performance.now()\n const dsRest = readAndApplyDeleteSet(structDecoder, transaction, store)\n if (store.pendingDs) {\n // @todo we could make a lower-bound state-vector check as we do above\n const pendingDSUpdate = new UpdateDecoderV2(decoding.createDecoder(store.pendingDs))\n decoding.readVarUint(pendingDSUpdate.restDecoder) // read 0 structs, because we only encode deletes in pendingdsupdate\n const dsRest2 = readAndApplyDeleteSet(pendingDSUpdate, transaction, store)\n if (dsRest && dsRest2) {\n // case 1: ds1 != null && ds2 != null\n store.pendingDs = mergeUpdatesV2([dsRest, dsRest2])\n } else {\n // case 2: ds1 != null\n // case 3: ds2 != null\n // case 4: ds1 == null && ds2 == null\n store.pendingDs = dsRest || dsRest2\n }\n } else {\n // Either dsRest == null && pendingDs == null OR dsRest != null\n store.pendingDs = dsRest\n }\n // console.log('time to cleanup: ', performance.now() - start) // @todo remove\n // start = performance.now()\n\n // console.log('time to resume delete readers: ', performance.now() - start) // @todo remove\n // start = performance.now()\n if (retry) {\n const update = /** @type {{update: Uint8Array}} */ (store.pendingStructs).update\n store.pendingStructs = null\n applyUpdateV2(transaction.doc, update)\n }\n }, transactionOrigin, false)\n\n/**\n * Read and apply a document update.\n *\n * This function has the same effect as `applyUpdate` but accepts a decoder.\n *\n * @param {decoding.Decoder} decoder\n * @param {Doc} ydoc\n * @param {any} [transactionOrigin] This will be stored on `transaction.origin` and `.on('update', (update, origin))`\n *\n * @function\n */\nexport const readUpdate = (decoder, ydoc, transactionOrigin) => readUpdateV2(decoder, ydoc, transactionOrigin, new UpdateDecoderV1(decoder))\n\n/**\n * Apply a document update created by, for example, `y.on('update', update => ..)` or `update = encodeStateAsUpdate()`.\n *\n * This function has the same effect as `readUpdate` but accepts an Uint8Array instead of a Decoder.\n *\n * @param {Doc} ydoc\n * @param {Uint8Array} update\n * @param {any} [transactionOrigin] This will be stored on `transaction.origin` and `.on('update', (update, origin))`\n * @param {typeof UpdateDecoderV1 | typeof UpdateDecoderV2} [YDecoder]\n *\n * @function\n */\nexport const applyUpdateV2 = (ydoc, update, transactionOrigin, YDecoder = UpdateDecoderV2) => {\n const decoder = decoding.createDecoder(update)\n readUpdateV2(decoder, ydoc, transactionOrigin, new YDecoder(decoder))\n}\n\n/**\n * Apply a document update created by, for example, `y.on('update', update => ..)` or `update = encodeStateAsUpdate()`.\n *\n * This function has the same effect as `readUpdate` but accepts an Uint8Array instead of a Decoder.\n *\n * @param {Doc} ydoc\n * @param {Uint8Array} update\n * @param {any} [transactionOrigin] This will be stored on `transaction.origin` and `.on('update', (update, origin))`\n *\n * @function\n */\nexport const applyUpdate = (ydoc, update, transactionOrigin) => applyUpdateV2(ydoc, update, transactionOrigin, UpdateDecoderV1)\n\n/**\n * Write all the document as a single update message. If you specify the state of the remote client (`targetStateVector`) it will\n * only write the operations that are missing.\n *\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {Doc} doc\n * @param {Map<number,number>} [targetStateVector] The state of the target that receives the update. Leave empty to write all known structs\n *\n * @function\n */\nexport const writeStateAsUpdate = (encoder, doc, targetStateVector = new Map()) => {\n writeClientsStructs(encoder, doc.store, targetStateVector)\n writeDeleteSet(encoder, createDeleteSetFromStructStore(doc.store))\n}\n\n/**\n * Write all the document as a single update message that can be applied on the remote document. If you specify the state of the remote client (`targetState`) it will\n * only write the operations that are missing.\n *\n * Use `writeStateAsUpdate` instead if you are working with lib0/encoding.js#Encoder\n *\n * @param {Doc} doc\n * @param {Uint8Array} [encodedTargetStateVector] The state of the target that receives the update. Leave empty to write all known structs\n * @param {UpdateEncoderV1 | UpdateEncoderV2} [encoder]\n * @return {Uint8Array}\n *\n * @function\n */\nexport const encodeStateAsUpdateV2 = (doc, encodedTargetStateVector = new Uint8Array([0]), encoder = new UpdateEncoderV2()) => {\n const targetStateVector = decodeStateVector(encodedTargetStateVector)\n writeStateAsUpdate(encoder, doc, targetStateVector)\n const updates = [encoder.toUint8Array()]\n // also add the pending updates (if there are any)\n if (doc.store.pendingDs) {\n updates.push(doc.store.pendingDs)\n }\n if (doc.store.pendingStructs) {\n updates.push(diffUpdateV2(doc.store.pendingStructs.update, encodedTargetStateVector))\n }\n if (updates.length > 1) {\n if (encoder.constructor === UpdateEncoderV1) {\n return mergeUpdates(updates.map((update, i) => i === 0 ? update : convertUpdateFormatV2ToV1(update)))\n } else if (encoder.constructor === UpdateEncoderV2) {\n return mergeUpdatesV2(updates)\n }\n }\n return updates[0]\n}\n\n/**\n * Write all the document as a single update message that can be applied on the remote document. If you specify the state of the remote client (`targetState`) it will\n * only write the operations that are missing.\n *\n * Use `writeStateAsUpdate` instead if you are working with lib0/encoding.js#Encoder\n *\n * @param {Doc} doc\n * @param {Uint8Array} [encodedTargetStateVector] The state of the target that receives the update. Leave empty to write all known structs\n * @return {Uint8Array}\n *\n * @function\n */\nexport const encodeStateAsUpdate = (doc, encodedTargetStateVector) => encodeStateAsUpdateV2(doc, encodedTargetStateVector, new UpdateEncoderV1())\n\n/**\n * Read state vector from Decoder and return as Map\n *\n * @param {DSDecoderV1 | DSDecoderV2} decoder\n * @return {Map<number,number>} Maps `client` to the number next expected `clock` from that client.\n *\n * @function\n */\nexport const readStateVector = decoder => {\n const ss = new Map()\n const ssLength = decoding.readVarUint(decoder.restDecoder)\n for (let i = 0; i < ssLength; i++) {\n const client = decoding.readVarUint(decoder.restDecoder)\n const clock = decoding.readVarUint(decoder.restDecoder)\n ss.set(client, clock)\n }\n return ss\n}\n\n/**\n * Read decodedState and return State as Map.\n *\n * @param {Uint8Array} decodedState\n * @return {Map<number,number>} Maps `client` to the number next expected `clock` from that client.\n *\n * @function\n */\n// export const decodeStateVectorV2 = decodedState => readStateVector(new DSDecoderV2(decoding.createDecoder(decodedState)))\n\n/**\n * Read decodedState and return State as Map.\n *\n * @param {Uint8Array} decodedState\n * @return {Map<number,number>} Maps `client` to the number next expected `clock` from that client.\n *\n * @function\n */\nexport const decodeStateVector = decodedState => readStateVector(new DSDecoderV1(decoding.createDecoder(decodedState)))\n\n/**\n * @param {DSEncoderV1 | DSEncoderV2} encoder\n * @param {Map<number,number>} sv\n * @function\n */\nexport const writeStateVector = (encoder, sv) => {\n encoding.writeVarUint(encoder.restEncoder, sv.size)\n array.from(sv.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => {\n encoding.writeVarUint(encoder.restEncoder, client) // @todo use a special client decoder that is based on mapping\n encoding.writeVarUint(encoder.restEncoder, clock)\n })\n return encoder\n}\n\n/**\n * @param {DSEncoderV1 | DSEncoderV2} encoder\n * @param {Doc} doc\n *\n * @function\n */\nexport const writeDocumentStateVector = (encoder, doc) => writeStateVector(encoder, getStateVector(doc.store))\n\n/**\n * Encode State as Uint8Array.\n *\n * @param {Doc|Map<number,number>} doc\n * @param {DSEncoderV1 | DSEncoderV2} [encoder]\n * @return {Uint8Array}\n *\n * @function\n */\nexport const encodeStateVectorV2 = (doc, encoder = new DSEncoderV2()) => {\n if (doc instanceof Map) {\n writeStateVector(encoder, doc)\n } else {\n writeDocumentStateVector(encoder, doc)\n }\n return encoder.toUint8Array()\n}\n\n/**\n * Encode State as Uint8Array.\n *\n * @param {Doc|Map<number,number>} doc\n * @return {Uint8Array}\n *\n * @function\n */\nexport const encodeStateVector = doc => encodeStateVectorV2(doc, new DSEncoderV1())\n","import * as f from 'lib0/function'\n\n/**\n * General event handler implementation.\n *\n * @template ARG0, ARG1\n *\n * @private\n */\nexport class EventHandler {\n constructor () {\n /**\n * @type {Array<function(ARG0, ARG1):void>}\n */\n this.l = []\n }\n}\n\n/**\n * @template ARG0,ARG1\n * @returns {EventHandler<ARG0,ARG1>}\n *\n * @private\n * @function\n */\nexport const createEventHandler = () => new EventHandler()\n\n/**\n * Adds an event listener that is called when\n * {@link EventHandler#callEventListeners} is called.\n *\n * @template ARG0,ARG1\n * @param {EventHandler<ARG0,ARG1>} eventHandler\n * @param {function(ARG0,ARG1):void} f The event handler.\n *\n * @private\n * @function\n */\nexport const addEventHandlerListener = (eventHandler, f) =>\n eventHandler.l.push(f)\n\n/**\n * Removes an event listener.\n *\n * @template ARG0,ARG1\n * @param {EventHandler<ARG0,ARG1>} eventHandler\n * @param {function(ARG0,ARG1):void} f The event handler that was added with\n * {@link EventHandler#addEventListener}\n *\n * @private\n * @function\n */\nexport const removeEventHandlerListener = (eventHandler, f) => {\n const l = eventHandler.l\n const len = l.length\n eventHandler.l = l.filter(g => f !== g)\n if (len === eventHandler.l.length) {\n console.error('[yjs] Tried to remove event handler that doesn\\'t exist.')\n }\n}\n\n/**\n * Removes all event listeners.\n * @template ARG0,ARG1\n * @param {EventHandler<ARG0,ARG1>} eventHandler\n *\n * @private\n * @function\n */\nexport const removeAllEventHandlerListeners = eventHandler => {\n eventHandler.l.length = 0\n}\n\n/**\n * Call all event listeners that were added via\n * {@link EventHandler#addEventListener}.\n *\n * @template ARG0,ARG1\n * @param {EventHandler<ARG0,ARG1>} eventHandler\n * @param {ARG0} arg0\n * @param {ARG1} arg1\n *\n * @private\n * @function\n */\nexport const callEventHandlerListeners = (eventHandler, arg0, arg1) =>\n f.callAll(eventHandler.l, [arg0, arg1])\n","import { AbstractType } from '../internals.js' // eslint-disable-line\n\nimport * as decoding from 'lib0/decoding'\nimport * as encoding from 'lib0/encoding'\nimport * as error from 'lib0/error'\n\nexport class ID {\n /**\n * @param {number} client client id\n * @param {number} clock unique per client id, continuous number\n */\n constructor (client, clock) {\n /**\n * Client id\n * @type {number}\n */\n this.client = client\n /**\n * unique per client id, continuous number\n * @type {number}\n */\n this.clock = clock\n }\n}\n\n/**\n * @param {ID | null} a\n * @param {ID | null} b\n * @return {boolean}\n *\n * @function\n */\nexport const compareIDs = (a, b) => a === b || (a !== null && b !== null && a.client === b.client && a.clock === b.clock)\n\n/**\n * @param {number} client\n * @param {number} clock\n *\n * @private\n * @function\n */\nexport const createID = (client, clock) => new ID(client, clock)\n\n/**\n * @param {encoding.Encoder} encoder\n * @param {ID} id\n *\n * @private\n * @function\n */\nexport const writeID = (encoder, id) => {\n encoding.writeVarUint(encoder, id.client)\n encoding.writeVarUint(encoder, id.clock)\n}\n\n/**\n * Read ID.\n * * If first varUint read is 0xFFFFFF a RootID is returned.\n * * Otherwise an ID is returned\n *\n * @param {decoding.Decoder} decoder\n * @return {ID}\n *\n * @private\n * @function\n */\nexport const readID = decoder =>\n createID(decoding.readVarUint(decoder), decoding.readVarUint(decoder))\n\n/**\n * The top types are mapped from y.share.get(keyname) => type.\n * `type` does not store any information about the `keyname`.\n * This function finds the correct `keyname` for `type` and throws otherwise.\n *\n * @param {AbstractType<any>} type\n * @return {string}\n *\n * @private\n * @function\n */\nexport const findRootTypeKey = type => {\n // @ts-ignore _y must be defined, otherwise unexpected case\n for (const [key, value] of type.doc.share.entries()) {\n if (value === type) {\n return key\n }\n }\n throw error.unexpectedCase()\n}\n","import {\n isDeleted,\n createDeleteSetFromStructStore,\n getStateVector,\n getItemCleanStart,\n iterateDeletedStructs,\n writeDeleteSet,\n writeStateVector,\n readDeleteSet,\n readStateVector,\n createDeleteSet,\n createID,\n getState,\n findIndexSS,\n UpdateEncoderV2,\n applyUpdateV2,\n LazyStructReader,\n equalDeleteSets,\n UpdateDecoderV1, UpdateDecoderV2, DSEncoderV1, DSEncoderV2, DSDecoderV1, DSDecoderV2, Transaction, Doc, DeleteSet, Item, // eslint-disable-line\n mergeDeleteSets\n} from '../internals.js'\n\nimport * as map from 'lib0/map'\nimport * as set from 'lib0/set'\nimport * as decoding from 'lib0/decoding'\nimport * as encoding from 'lib0/encoding'\n\nexport class Snapshot {\n /**\n * @param {DeleteSet} ds\n * @param {Map<number,number>} sv state map\n */\n constructor (ds, sv) {\n /**\n * @type {DeleteSet}\n */\n this.ds = ds\n /**\n * State Map\n * @type {Map<number,number>}\n */\n this.sv = sv\n }\n}\n\n/**\n * @param {Snapshot} snap1\n * @param {Snapshot} snap2\n * @return {boolean}\n */\nexport const equalSnapshots = (snap1, snap2) => {\n const ds1 = snap1.ds.clients\n const ds2 = snap2.ds.clients\n const sv1 = snap1.sv\n const sv2 = snap2.sv\n if (sv1.size !== sv2.size || ds1.size !== ds2.size) {\n return false\n }\n for (const [key, value] of sv1.entries()) {\n if (sv2.get(key) !== value) {\n return false\n }\n }\n for (const [client, dsitems1] of ds1.entries()) {\n const dsitems2 = ds2.get(client) || []\n if (dsitems1.length !== dsitems2.length) {\n return false\n }\n for (let i = 0; i < dsitems1.length; i++) {\n const dsitem1 = dsitems1[i]\n const dsitem2 = dsitems2[i]\n if (dsitem1.clock !== dsitem2.clock || dsitem1.len !== dsitem2.len) {\n return false\n }\n }\n }\n return true\n}\n\n/**\n * @param {Snapshot} snapshot\n * @param {DSEncoderV1 | DSEncoderV2} [encoder]\n * @return {Uint8Array}\n */\nexport const encodeSnapshotV2 = (snapshot, encoder = new DSEncoderV2()) => {\n writeDeleteSet(encoder, snapshot.ds)\n writeStateVector(encoder, snapshot.sv)\n return encoder.toUint8Array()\n}\n\n/**\n * @param {Snapshot} snapshot\n * @return {Uint8Array}\n */\nexport const encodeSnapshot = snapshot => encodeSnapshotV2(snapshot, new DSEncoderV1())\n\n/**\n * @param {Uint8Array} buf\n * @param {DSDecoderV1 | DSDecoderV2} [decoder]\n * @return {Snapshot}\n */\nexport const decodeSnapshotV2 = (buf, decoder = new DSDecoderV2(decoding.createDecoder(buf))) => {\n return new Snapshot(readDeleteSet(decoder), readStateVector(decoder))\n}\n\n/**\n * @param {Uint8Array} buf\n * @return {Snapshot}\n */\nexport const decodeSnapshot = buf => decodeSnapshotV2(buf, new DSDecoderV1(decoding.createDecoder(buf)))\n\n/**\n * @param {DeleteSet} ds\n * @param {Map<number,number>} sm\n * @return {Snapshot}\n */\nexport const createSnapshot = (ds, sm) => new Snapshot(ds, sm)\n\nexport const emptySnapshot = createSnapshot(createDeleteSet(), new Map())\n\n/**\n * @param {Doc} doc\n * @return {Snapshot}\n */\nexport const snapshot = doc => createSnapshot(createDeleteSetFromStructStore(doc.store), getStateVector(doc.store))\n\n/**\n * @param {Item} item\n * @param {Snapshot|undefined} snapshot\n *\n * @protected\n * @function\n */\nexport const isVisible = (item, snapshot) => snapshot === undefined\n ? !item.deleted\n : snapshot.sv.has(item.id.client) && (snapshot.sv.get(item.id.client) || 0) > item.id.clock && !isDeleted(snapshot.ds, item.id)\n\n/**\n * @param {Transaction} transaction\n * @param {Snapshot} snapshot\n */\nexport const splitSnapshotAffectedStructs = (transaction, snapshot) => {\n const meta = map.setIfUndefined(transaction.meta, splitSnapshotAffectedStructs, set.create)\n const store = transaction.doc.store\n // check if we already split for this snapshot\n if (!meta.has(snapshot)) {\n snapshot.sv.forEach((clock, client) => {\n if (clock < getState(store, client)) {\n getItemCleanStart(transaction, createID(client, clock))\n }\n })\n iterateDeletedStructs(transaction, snapshot.ds, _item => {})\n meta.add(snapshot)\n }\n}\n\n/**\n * @example\n * const ydoc = new Y.Doc({ gc: false })\n * ydoc.getText().insert(0, 'world!')\n * const snapshot = Y.snapshot(ydoc)\n * ydoc.getText().insert(0, 'hello ')\n * const restored = Y.createDocFromSnapshot(ydoc, snapshot)\n * assert(restored.getText().toString() === 'world!')\n *\n * @param {Doc} originDoc\n * @param {Snapshot} snapshot\n * @param {Doc} [newDoc] Optionally, you may define the Yjs document that receives the data from originDoc\n * @return {Doc}\n */\nexport const createDocFromSnapshot = (originDoc, snapshot, newDoc = new Doc()) => {\n if (originDoc.gc) {\n // we should not try to restore a GC-ed document, because some of the restored items might have their content deleted\n throw new Error('Garbage-collection must be disabled in `originDoc`!')\n }\n const { sv, ds } = snapshot\n\n const encoder = new UpdateEncoderV2()\n originDoc.transact(transaction => {\n let size = 0\n sv.forEach(clock => {\n if (clock > 0) {\n size++\n }\n })\n encoding.writeVarUint(encoder.restEncoder, size)\n // splitting the structs before writing them to the encoder\n for (const [client, clock] of sv) {\n if (clock === 0) {\n continue\n }\n if (clock < getState(originDoc.store, client)) {\n getItemCleanStart(transaction, createID(client, clock))\n }\n const structs = originDoc.store.clients.get(client) || []\n const lastStructIndex = findIndexSS(structs, clock - 1)\n // write # encoded structs\n encoding.writeVarUint(encoder.restEncoder, lastStructIndex + 1)\n encoder.writeClient(client)\n // first clock written is 0\n encoding.writeVarUint(encoder.restEncoder, 0)\n for (let i = 0; i <= lastStructIndex; i++) {\n structs[i].write(encoder, 0)\n }\n }\n writeDeleteSet(encoder, ds)\n })\n\n applyUpdateV2(newDoc, encoder.toUint8Array(), 'snapshot')\n return newDoc\n}\n\n/**\n * @param {Snapshot} snapshot\n * @param {Uint8Array} update\n * @param {typeof UpdateDecoderV2 | typeof UpdateDecoderV1} [YDecoder]\n */\nexport const snapshotContainsUpdateV2 = (snapshot, update, YDecoder = UpdateDecoderV2) => {\n const structs = []\n const updateDecoder = new YDecoder(decoding.createDecoder(update))\n const lazyDecoder = new LazyStructReader(updateDecoder, false)\n for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {\n structs.push(curr)\n if ((snapshot.sv.get(curr.id.client) || 0) < curr.id.clock + curr.length) {\n return false\n }\n }\n const mergedDS = mergeDeleteSets([snapshot.ds, readDeleteSet(updateDecoder)])\n return equalDeleteSets(snapshot.ds, mergedDS)\n}\n\n/**\n * @param {Snapshot} snapshot\n * @param {Uint8Array} update\n */\nexport const snapshotContainsUpdate = (snapshot, update) => snapshotContainsUpdateV2(snapshot, update, UpdateDecoderV1)\n","import {\n GC,\n splitItem,\n Transaction, ID, Item, DSDecoderV2 // eslint-disable-line\n} from '../internals.js'\n\nimport * as math from 'lib0/math'\nimport * as error from 'lib0/error'\n\nexport class StructStore {\n constructor () {\n /**\n * @type {Map<number,Array<GC|Item>>}\n */\n this.clients = new Map()\n /**\n * @type {null | { missing: Map<number, number>, update: Uint8Array }}\n */\n this.pendingStructs = null\n /**\n * @type {null | Uint8Array}\n */\n this.pendingDs = null\n }\n}\n\n/**\n * Return the states as a Map<client,clock>.\n * Note that clock refers to the next expected clock id.\n *\n * @param {StructStore} store\n * @return {Map<number,number>}\n *\n * @public\n * @function\n */\nexport const getStateVector = store => {\n const sm = new Map()\n store.clients.forEach((structs, client) => {\n const struct = structs[structs.length - 1]\n sm.set(client, struct.id.clock + struct.length)\n })\n return sm\n}\n\n/**\n * @param {StructStore} store\n * @param {number} client\n * @return {number}\n *\n * @public\n * @function\n */\nexport const getState = (store, client) => {\n const structs = store.clients.get(client)\n if (structs === undefined) {\n return 0\n }\n const lastStruct = structs[structs.length - 1]\n return lastStruct.id.clock + lastStruct.length\n}\n\n/**\n * @param {StructStore} store\n *\n * @private\n * @function\n */\nexport const integrityCheck = store => {\n store.clients.forEach(structs => {\n for (let i = 1; i < structs.length; i++) {\n const l = structs[i - 1]\n const r = structs[i]\n if (l.id.clock + l.length !== r.id.clock) {\n throw new Error('StructStore failed integrity check')\n }\n }\n })\n}\n\n/**\n * @param {StructStore} store\n * @param {GC|Item} struct\n *\n * @private\n * @function\n */\nexport const addStruct = (store, struct) => {\n let structs = store.clients.get(struct.id.client)\n if (structs === undefined) {\n structs = []\n store.clients.set(struct.id.client, structs)\n } else {\n const lastStruct = structs[structs.length - 1]\n if (lastStruct.id.clock + lastStruct.length !== struct.id.clock) {\n throw error.unexpectedCase()\n }\n }\n structs.push(struct)\n}\n\n/**\n * Perform a binary search on a sorted array\n * @param {Array<Item|GC>} structs\n * @param {number} clock\n * @return {number}\n *\n * @private\n * @function\n */\nexport const findIndexSS = (structs, clock) => {\n let left = 0\n let right = structs.length - 1\n let mid = structs[right]\n let midclock = mid.id.clock\n if (midclock === clock) {\n return right\n }\n // @todo does it even make sense to pivot the search?\n // If a good split misses, it might actually increase the time to find the correct item.\n // Currently, the only advantage is that search with pivoting might find the item on the first try.\n let midindex = math.floor((clock / (midclock + mid.length - 1)) * right) // pivoting the search\n while (left <= right) {\n mid = structs[midindex]\n midclock = mid.id.clock\n if (midclock <= clock) {\n if (clock < midclock + mid.length) {\n return midindex\n }\n left = midindex + 1\n } else {\n right = midindex - 1\n }\n midindex = math.floor((left + right) / 2)\n }\n // Always check state before looking for a struct in StructStore\n // Therefore the case of not finding a struct is unexpected\n throw error.unexpectedCase()\n}\n\n/**\n * Expects that id is actually in store. This function throws or is an infinite loop otherwise.\n *\n * @param {StructStore} store\n * @param {ID} id\n * @return {GC|Item}\n *\n * @private\n * @function\n */\nexport const find = (store, id) => {\n /**\n * @type {Array<GC|Item>}\n */\n // @ts-ignore\n const structs = store.clients.get(id.client)\n return structs[findIndexSS(structs, id.clock)]\n}\n\n/**\n * Expects that id is actually in store. This function throws or is an infinite loop otherwise.\n * @private\n * @function\n */\nexport const getItem = /** @type {function(StructStore,ID):Item} */ (find)\n\n/**\n * @param {Transaction} transaction\n * @param {Array<Item|GC>} structs\n * @param {number} clock\n */\nexport const findIndexCleanStart = (transaction, structs, clock) => {\n const index = findIndexSS(structs, clock)\n const struct = structs[index]\n if (struct.id.clock < clock && struct instanceof Item) {\n structs.splice(index + 1, 0, splitItem(transaction, struct, clock - struct.id.clock))\n return index + 1\n }\n return index\n}\n\n/**\n * Expects that id is actually in store. This function throws or is an infinite loop otherwise.\n *\n * @param {Transaction} transaction\n * @param {ID} id\n * @return {Item}\n *\n * @private\n * @function\n */\nexport const getItemCleanStart = (transaction, id) => {\n const structs = /** @type {Array<Item>} */ (transaction.doc.store.clients.get(id.client))\n return structs[findIndexCleanStart(transaction, structs, id.clock)]\n}\n\n/**\n * Expects that id is actually in store. This function throws or is an infinite loop otherwise.\n *\n * @param {Transaction} transaction\n * @param {StructStore} store\n * @param {ID} id\n * @return {Item}\n *\n * @private\n * @function\n */\nexport const getItemCleanEnd = (transaction, store, id) => {\n /**\n * @type {Array<Item>}\n */\n // @ts-ignore\n const structs = store.clients.get(id.client)\n const index = findIndexSS(structs, id.clock)\n const struct = structs[index]\n if (id.clock !== struct.id.clock + struct.length - 1 && struct.constructor !== GC) {\n structs.splice(index + 1, 0, splitItem(transaction, struct, id.clock - struct.id.clock + 1))\n }\n return struct\n}\n\n/**\n * Replace `item` with `newitem` in store\n * @param {StructStore} store\n * @param {GC|Item} struct\n * @param {GC|Item} newStruct\n *\n * @private\n * @function\n */\nexport const replaceStruct = (store, struct, newStruct) => {\n const structs = /** @type {Array<GC|Item>} */ (store.clients.get(struct.id.client))\n structs[findIndexSS(structs, struct.id.clock)] = newStruct\n}\n\n/**\n * Iterate over a range of structs\n *\n * @param {Transaction} transaction\n * @param {Array<Item|GC>} structs\n * @param {number} clockStart Inclusive start\n * @param {number} len\n * @param {function(GC|Item):void} f\n *\n * @function\n */\nexport const iterateStructs = (transaction, structs, clockStart, len, f) => {\n if (len === 0) {\n return\n }\n const clockEnd = clockStart + len\n let index = findIndexCleanStart(transaction, structs, clockStart)\n let struct\n do {\n struct = structs[index++]\n if (clockEnd < struct.id.clock + struct.length) {\n findIndexCleanStart(transaction, structs, clockEnd)\n }\n f(struct)\n } while (index < structs.length && structs[index].id.clock < clockEnd)\n}\n","import {\n getState,\n writeStructsFromTransaction,\n writeDeleteSet,\n DeleteSet,\n sortAndMergeDeleteSet,\n getStateVector,\n findIndexSS,\n callEventHandlerListeners,\n Item,\n generateNewClientId,\n createID,\n cleanupYTextAfterTransaction,\n UpdateEncoderV1, UpdateEncoderV2, GC, StructStore, AbstractType, AbstractStruct, YEvent, Doc // eslint-disable-line\n} from '../internals.js'\n\nimport * as map from 'lib0/map'\nimport * as math from 'lib0/math'\nimport * as set from 'lib0/set'\nimport * as logging from 'lib0/logging'\nimport { callAll } from 'lib0/function'\n\n/**\n * A transaction is created for every change on the Yjs model. It is possible\n * to bundle changes on the Yjs model in a single transaction to\n * minimize the number on messages sent and the number of observer calls.\n * If possible the user of this library should bundle as many changes as\n * possible. Here is an example to illustrate the advantages of bundling:\n *\n * @example\n * const ydoc = new Y.Doc()\n * const map = ydoc.getMap('map')\n * // Log content when change is triggered\n * map.observe(() => {\n * console.log('change triggered')\n * })\n * // Each change on the map type triggers a log message:\n * map.set('a', 0) // => \"change triggered\"\n * map.set('b', 0) // => \"change triggered\"\n * // When put in a transaction, it will trigger the log after the transaction:\n * ydoc.transact(() => {\n * map.set('a', 1)\n * map.set('b', 1)\n * }) // => \"change triggered\"\n *\n * @public\n */\nexport class Transaction {\n /**\n * @param {Doc} doc\n * @param {any} origin\n * @param {boolean} local\n */\n constructor (doc, origin, local) {\n /**\n * The Yjs instance.\n * @type {Doc}\n */\n this.doc = doc\n /**\n * Describes the set of deleted items by ids\n * @type {DeleteSet}\n */\n this.deleteSet = new DeleteSet()\n /**\n * Holds the state before the transaction started.\n * @type {Map<Number,Number>}\n */\n this.beforeState = getStateVector(doc.store)\n /**\n * Holds the state after the transaction.\n * @type {Map<Number,Number>}\n */\n this.afterState = new Map()\n /**\n * All types that were directly modified (property added or child\n * inserted/deleted). New types are not included in this Set.\n * Maps from type to parentSubs (`item.parentSub = null` for YArray)\n * @type {Map<AbstractType<YEvent<any>>,Set<String|null>>}\n */\n this.changed = new Map()\n /**\n * Stores the events for the types that observe also child elements.\n * It is mainly used by `observeDeep`.\n * @type {Map<AbstractType<YEvent<any>>,Array<YEvent<any>>>}\n */\n this.changedParentTypes = new Map()\n /**\n * @type {Array<AbstractStruct>}\n */\n this._mergeStructs = []\n /**\n * @type {any}\n */\n this.origin = origin\n /**\n * Stores meta information on the transaction\n * @type {Map<any,any>}\n */\n this.meta = new Map()\n /**\n * Whether this change originates from this doc.\n * @type {boolean}\n */\n this.local = local\n /**\n * @type {Set<Doc>}\n */\n this.subdocsAdded = new Set()\n /**\n * @type {Set<Doc>}\n */\n this.subdocsRemoved = new Set()\n /**\n * @type {Set<Doc>}\n */\n this.subdocsLoaded = new Set()\n /**\n * @type {boolean}\n */\n this._needFormattingCleanup = false\n }\n}\n\n/**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {Transaction} transaction\n * @return {boolean} Whether data was written.\n */\nexport const writeUpdateMessageFromTransaction = (encoder, transaction) => {\n if (transaction.deleteSet.clients.size === 0 && !map.any(transaction.afterState, (clock, client) => transaction.beforeState.get(client) !== clock)) {\n return false\n }\n sortAndMergeDeleteSet(transaction.deleteSet)\n writeStructsFromTransaction(encoder, transaction)\n writeDeleteSet(encoder, transaction.deleteSet)\n return true\n}\n\n/**\n * @param {Transaction} transaction\n *\n * @private\n * @function\n */\nexport const nextID = transaction => {\n const y = transaction.doc\n return createID(y.clientID, getState(y.store, y.clientID))\n}\n\n/**\n * If `type.parent` was added in current transaction, `type` technically\n * did not change, it was just added and we should not fire events for `type`.\n *\n * @param {Transaction} transaction\n * @param {AbstractType<YEvent<any>>} type\n * @param {string|null} parentSub\n */\nexport const addChangedTypeToTransaction = (transaction, type, parentSub) => {\n const item = type._item\n if (item === null || (item.id.clock < (transaction.beforeState.get(item.id.client) || 0) && !item.deleted)) {\n map.setIfUndefined(transaction.changed, type, set.create).add(parentSub)\n }\n}\n\n/**\n * @param {Array<AbstractStruct>} structs\n * @param {number} pos\n * @return {number} # of merged structs\n */\nconst tryToMergeWithLefts = (structs, pos) => {\n let right = structs[pos]\n let left = structs[pos - 1]\n let i = pos\n for (; i > 0; right = left, left = structs[--i - 1]) {\n if (left.deleted === right.deleted && left.constructor === right.constructor) {\n if (left.mergeWith(right)) {\n if (right instanceof Item && right.parentSub !== null && /** @type {AbstractType<any>} */ (right.parent)._map.get(right.parentSub) === right) {\n /** @type {AbstractType<any>} */ (right.parent)._map.set(right.parentSub, /** @type {Item} */ (left))\n }\n continue\n }\n }\n break\n }\n const merged = pos - i\n if (merged) {\n // remove all merged structs from the array\n structs.splice(pos + 1 - merged, merged)\n }\n return merged\n}\n\n/**\n * @param {DeleteSet} ds\n * @param {StructStore} store\n * @param {function(Item):boolean} gcFilter\n */\nconst tryGcDeleteSet = (ds, store, gcFilter) => {\n for (const [client, deleteItems] of ds.clients.entries()) {\n const structs = /** @type {Array<GC|Item>} */ (store.clients.get(client))\n for (let di = deleteItems.length - 1; di >= 0; di--) {\n const deleteItem = deleteItems[di]\n const endDeleteItemClock = deleteItem.clock + deleteItem.len\n for (\n let si = findIndexSS(structs, deleteItem.clock), struct = structs[si];\n si < structs.length && struct.id.clock < endDeleteItemClock;\n struct = structs[++si]\n ) {\n const struct = structs[si]\n if (deleteItem.clock + deleteItem.len <= struct.id.clock) {\n break\n }\n if (struct instanceof Item && struct.deleted && !struct.keep && gcFilter(struct)) {\n struct.gc(store, false)\n }\n }\n }\n }\n}\n\n/**\n * @param {DeleteSet} ds\n * @param {StructStore} store\n */\nconst tryMergeDeleteSet = (ds, store) => {\n // try to merge deleted / gc'd items\n // merge from right to left for better efficiency and so we don't miss any merge targets\n ds.clients.forEach((deleteItems, client) => {\n const structs = /** @type {Array<GC|Item>} */ (store.clients.get(client))\n for (let di = deleteItems.length - 1; di >= 0; di--) {\n const deleteItem = deleteItems[di]\n // start with merging the item next to the last deleted item\n const mostRightIndexToCheck = math.min(structs.length - 1, 1 + findIndexSS(structs, deleteItem.clock + deleteItem.len - 1))\n for (\n let si = mostRightIndexToCheck, struct = structs[si];\n si > 0 && struct.id.clock >= deleteItem.clock;\n struct = structs[si]\n ) {\n si -= 1 + tryToMergeWithLefts(structs, si)\n }\n }\n })\n}\n\n/**\n * @param {DeleteSet} ds\n * @param {StructStore} store\n * @param {function(Item):boolean} gcFilter\n */\nexport const tryGc = (ds, store, gcFilter) => {\n tryGcDeleteSet(ds, store, gcFilter)\n tryMergeDeleteSet(ds, store)\n}\n\n/**\n * @param {Array<Transaction>} transactionCleanups\n * @param {number} i\n */\nconst cleanupTransactions = (transactionCleanups, i) => {\n if (i < transactionCleanups.length) {\n const transaction = transactionCleanups[i]\n const doc = transaction.doc\n const store = doc.store\n const ds = transaction.deleteSet\n const mergeStructs = transaction._mergeStructs\n try {\n sortAndMergeDeleteSet(ds)\n transaction.afterState = getStateVector(transaction.doc.store)\n doc.emit('beforeObserverCalls', [transaction, doc])\n /**\n * An array of event callbacks.\n *\n * Each callback is called even if the other ones throw errors.\n *\n * @type {Array<function():void>}\n */\n const fs = []\n // observe events on changed types\n transaction.changed.forEach((subs, itemtype) =>\n fs.push(() => {\n if (itemtype._item === null || !itemtype._item.deleted) {\n itemtype._callObserver(transaction, subs)\n }\n })\n )\n fs.push(() => {\n // deep observe events\n transaction.changedParentTypes.forEach((events, type) => {\n // We need to think about the possibility that the user transforms the\n // Y.Doc in the event.\n if (type._dEH.l.length > 0 && (type._item === null || !type._item.deleted)) {\n events = events\n .filter(event =>\n event.target._item === null || !event.target._item.deleted\n )\n events\n .forEach(event => {\n event.currentTarget = type\n // path is relative to the current target\n event._path = null\n })\n // sort events by path length so that top-level events are fired first.\n events\n .sort((event1, event2) => event1.path.length - event2.path.length)\n // We don't need to check for events.length\n // because we know it has at least one element\n callEventHandlerListeners(type._dEH, events, transaction)\n }\n })\n })\n fs.push(() => doc.emit('afterTransaction', [transaction, doc]))\n callAll(fs, [])\n if (transaction._needFormattingCleanup) {\n cleanupYTextAfterTransaction(transaction)\n }\n } finally {\n // Replace deleted items with ItemDeleted / GC.\n // This is where content is actually remove from the Yjs Doc.\n if (doc.gc) {\n tryGcDeleteSet(ds, store, doc.gcFilter)\n }\n tryMergeDeleteSet(ds, store)\n\n // on all affected store.clients props, try to merge\n transaction.afterState.forEach((clock, client) => {\n const beforeClock = transaction.beforeState.get(client) || 0\n if (beforeClock !== clock) {\n const structs = /** @type {Array<GC|Item>} */ (store.clients.get(client))\n // we iterate from right to left so we can safely remove entries\n const firstChangePos = math.max(findIndexSS(structs, beforeClock), 1)\n for (let i = structs.length - 1; i >= firstChangePos;) {\n i -= 1 + tryToMergeWithLefts(structs, i)\n }\n }\n })\n // try to merge mergeStructs\n // @todo: it makes more sense to transform mergeStructs to a DS, sort it, and merge from right to left\n // but at the moment DS does not handle duplicates\n for (let i = mergeStructs.length - 1; i >= 0; i--) {\n const { client, clock } = mergeStructs[i].id\n const structs = /** @type {Array<GC|Item>} */ (store.clients.get(client))\n const replacedStructPos = findIndexSS(structs, clock)\n if (replacedStructPos + 1 < structs.length) {\n if (tryToMergeWithLefts(structs, replacedStructPos + 1) > 1) {\n continue // no need to perform next check, both are already merged\n }\n }\n if (replacedStructPos > 0) {\n tryToMergeWithLefts(structs, replacedStructPos)\n }\n }\n if (!transaction.local && transaction.afterState.get(doc.clientID) !== transaction.beforeState.get(doc.clientID)) {\n logging.print(logging.ORANGE, logging.BOLD, '[yjs] ', logging.UNBOLD, logging.RED, 'Changed the client-id because another client seems to be using it.')\n doc.clientID = generateNewClientId()\n }\n // @todo Merge all the transactions into one and provide send the data as a single update message\n doc.emit('afterTransactionCleanup', [transaction, doc])\n if (doc._observers.has('update')) {\n const encoder = new UpdateEncoderV1()\n const hasContent = writeUpdateMessageFromTransaction(encoder, transaction)\n if (hasContent) {\n doc.emit('update', [encoder.toUint8Array(), transaction.origin, doc, transaction])\n }\n }\n if (doc._observers.has('updateV2')) {\n const encoder = new UpdateEncoderV2()\n const hasContent = writeUpdateMessageFromTransaction(encoder, transaction)\n if (hasContent) {\n doc.emit('updateV2', [encoder.toUint8Array(), transaction.origin, doc, transaction])\n }\n }\n const { subdocsAdded, subdocsLoaded, subdocsRemoved } = transaction\n if (subdocsAdded.size > 0 || subdocsRemoved.size > 0 || subdocsLoaded.size > 0) {\n subdocsAdded.forEach(subdoc => {\n subdoc.clientID = doc.clientID\n if (subdoc.collectionid == null) {\n subdoc.collectionid = doc.collectionid\n }\n doc.subdocs.add(subdoc)\n })\n subdocsRemoved.forEach(subdoc => doc.subdocs.delete(subdoc))\n doc.emit('subdocs', [{ loaded: subdocsLoaded, added: subdocsAdded, removed: subdocsRemoved }, doc, transaction])\n subdocsRemoved.forEach(subdoc => subdoc.destroy())\n }\n\n if (transactionCleanups.length <= i + 1) {\n doc._transactionCleanups = []\n doc.emit('afterAllTransactions', [doc, transactionCleanups])\n } else {\n cleanupTransactions(transactionCleanups, i + 1)\n }\n }\n }\n}\n\n/**\n * Implements the functionality of `y.transact(()=>{..})`\n *\n * @template T\n * @param {Doc} doc\n * @param {function(Transaction):T} f\n * @param {any} [origin=true]\n * @return {T}\n *\n * @function\n */\nexport const transact = (doc, f, origin = null, local = true) => {\n const transactionCleanups = doc._transactionCleanups\n let initialCall = false\n /**\n * @type {any}\n */\n let result = null\n if (doc._transaction === null) {\n initialCall = true\n doc._transaction = new Transaction(doc, origin, local)\n transactionCleanups.push(doc._transaction)\n if (transactionCleanups.length === 1) {\n doc.emit('beforeAllTransactions', [doc])\n }\n doc.emit('beforeTransaction', [doc._transaction, doc])\n }\n try {\n result = f(doc._transaction)\n } finally {\n if (initialCall) {\n const finishCleanup = doc._transaction === transactionCleanups[0]\n doc._transaction = null\n if (finishCleanup) {\n // The first transaction ended, now process observer calls.\n // Observer call may create new transactions for which we need to call the observers and do cleanup.\n // We don't want to nest these calls, so we execute these calls one after\n // another.\n // Also we need to ensure that all cleanups are called, even if the\n // observes throw errors.\n // This file is full of hacky try {} finally {} blocks to ensure that an\n // event can throw errors and also that the cleanup is called.\n cleanupTransactions(transactionCleanups, 0)\n }\n }\n }\n return result\n}\n","import * as binary from 'lib0/binary'\nimport * as decoding from 'lib0/decoding'\nimport * as encoding from 'lib0/encoding'\nimport * as error from 'lib0/error'\nimport * as f from 'lib0/function'\nimport * as logging from 'lib0/logging'\nimport * as map from 'lib0/map'\nimport * as math from 'lib0/math'\nimport * as string from 'lib0/string'\n\nimport {\n ContentAny,\n ContentBinary,\n ContentDeleted,\n ContentDoc,\n ContentEmbed,\n ContentFormat,\n ContentJSON,\n ContentString,\n ContentType,\n createID,\n decodeStateVector,\n DSEncoderV1,\n DSEncoderV2,\n GC,\n Item,\n mergeDeleteSets,\n readDeleteSet,\n readItemContent,\n Skip,\n UpdateDecoderV1,\n UpdateDecoderV2,\n UpdateEncoderV1,\n UpdateEncoderV2,\n writeDeleteSet,\n YXmlElement,\n YXmlHook\n} from '../internals.js'\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n */\nfunction * lazyStructReaderGenerator (decoder) {\n const numOfStateUpdates = decoding.readVarUint(decoder.restDecoder)\n for (let i = 0; i < numOfStateUpdates; i++) {\n const numberOfStructs = decoding.readVarUint(decoder.restDecoder)\n const client = decoder.readClient()\n let clock = decoding.readVarUint(decoder.restDecoder)\n for (let i = 0; i < numberOfStructs; i++) {\n const info = decoder.readInfo()\n // @todo use switch instead of ifs\n if (info === 10) {\n const len = decoding.readVarUint(decoder.restDecoder)\n yield new Skip(createID(client, clock), len)\n clock += len\n } else if ((binary.BITS5 & info) !== 0) {\n const cantCopyParentInfo = (info & (binary.BIT7 | binary.BIT8)) === 0\n // If parent = null and neither left nor right are defined, then we know that `parent` is child of `y`\n // and we read the next string as parentYKey.\n // It indicates how we store/retrieve parent from `y.share`\n // @type {string|null}\n const struct = new Item(\n createID(client, clock),\n null, // left\n (info & binary.BIT8) === binary.BIT8 ? decoder.readLeftID() : null, // origin\n null, // right\n (info & binary.BIT7) === binary.BIT7 ? decoder.readRightID() : null, // right origin\n // @ts-ignore Force writing a string here.\n cantCopyParentInfo ? (decoder.readParentInfo() ? decoder.readString() : decoder.readLeftID()) : null, // parent\n cantCopyParentInfo && (info & binary.BIT6) === binary.BIT6 ? decoder.readString() : null, // parentSub\n readItemContent(decoder, info) // item content\n )\n yield struct\n clock += struct.length\n } else {\n const len = decoder.readLen()\n yield new GC(createID(client, clock), len)\n clock += len\n }\n }\n }\n}\n\nexport class LazyStructReader {\n /**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @param {boolean} filterSkips\n */\n constructor (decoder, filterSkips) {\n this.gen = lazyStructReaderGenerator(decoder)\n /**\n * @type {null | Item | Skip | GC}\n */\n this.curr = null\n this.done = false\n this.filterSkips = filterSkips\n this.next()\n }\n\n /**\n * @return {Item | GC | Skip |null}\n */\n next () {\n // ignore \"Skip\" structs\n do {\n this.curr = this.gen.next().value || null\n } while (this.filterSkips && this.curr !== null && this.curr.constructor === Skip)\n return this.curr\n }\n}\n\n/**\n * @param {Uint8Array} update\n *\n */\nexport const logUpdate = update => logUpdateV2(update, UpdateDecoderV1)\n\n/**\n * @param {Uint8Array} update\n * @param {typeof UpdateDecoderV2 | typeof UpdateDecoderV1} [YDecoder]\n *\n */\nexport const logUpdateV2 = (update, YDecoder = UpdateDecoderV2) => {\n const structs = []\n const updateDecoder = new YDecoder(decoding.createDecoder(update))\n const lazyDecoder = new LazyStructReader(updateDecoder, false)\n for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {\n structs.push(curr)\n }\n logging.print('Structs: ', structs)\n const ds = readDeleteSet(updateDecoder)\n logging.print('DeleteSet: ', ds)\n}\n\n/**\n * @param {Uint8Array} update\n *\n */\nexport const decodeUpdate = (update) => decodeUpdateV2(update, UpdateDecoderV1)\n\n/**\n * @param {Uint8Array} update\n * @param {typeof UpdateDecoderV2 | typeof UpdateDecoderV1} [YDecoder]\n *\n */\nexport const decodeUpdateV2 = (update, YDecoder = UpdateDecoderV2) => {\n const structs = []\n const updateDecoder = new YDecoder(decoding.createDecoder(update))\n const lazyDecoder = new LazyStructReader(updateDecoder, false)\n for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {\n structs.push(curr)\n }\n return {\n structs,\n ds: readDeleteSet(updateDecoder)\n }\n}\n\nexport class LazyStructWriter {\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n */\n constructor (encoder) {\n this.currClient = 0\n this.startClock = 0\n this.written = 0\n this.encoder = encoder\n /**\n * We want to write operations lazily, but also we need to know beforehand how many operations we want to write for each client.\n *\n * This kind of meta-information (#clients, #structs-per-client-written) is written to the restEncoder.\n *\n * We fragment the restEncoder and store a slice of it per-client until we know how many clients there are.\n * When we flush (toUint8Array) we write the restEncoder using the fragments and the meta-information.\n *\n * @type {Array<{ written: number, restEncoder: Uint8Array }>}\n */\n this.clientStructs = []\n }\n}\n\n/**\n * @param {Array<Uint8Array>} updates\n * @return {Uint8Array}\n */\nexport const mergeUpdates = updates => mergeUpdatesV2(updates, UpdateDecoderV1, UpdateEncoderV1)\n\n/**\n * @param {Uint8Array} update\n * @param {typeof DSEncoderV1 | typeof DSEncoderV2} YEncoder\n * @param {typeof UpdateDecoderV1 | typeof UpdateDecoderV2} YDecoder\n * @return {Uint8Array}\n */\nexport const encodeStateVectorFromUpdateV2 = (update, YEncoder = DSEncoderV2, YDecoder = UpdateDecoderV2) => {\n const encoder = new YEncoder()\n const updateDecoder = new LazyStructReader(new YDecoder(decoding.createDecoder(update)), false)\n let curr = updateDecoder.curr\n if (curr !== null) {\n let size = 0\n let currClient = curr.id.client\n let stopCounting = curr.id.clock !== 0 // must start at 0\n let currClock = stopCounting ? 0 : curr.id.clock + curr.length\n for (; curr !== null; curr = updateDecoder.next()) {\n if (currClient !== curr.id.client) {\n if (currClock !== 0) {\n size++\n // We found a new client\n // write what we have to the encoder\n encoding.writeVarUint(encoder.restEncoder, currClient)\n encoding.writeVarUint(encoder.restEncoder, currClock)\n }\n currClient = curr.id.client\n currClock = 0\n stopCounting = curr.id.clock !== 0\n }\n // we ignore skips\n if (curr.constructor === Skip) {\n stopCounting = true\n }\n if (!stopCounting) {\n currClock = curr.id.clock + curr.length\n }\n }\n // write what we have\n if (currClock !== 0) {\n size++\n encoding.writeVarUint(encoder.restEncoder, currClient)\n encoding.writeVarUint(encoder.restEncoder, currClock)\n }\n // prepend the size of the state vector\n const enc = encoding.createEncoder()\n encoding.writeVarUint(enc, size)\n encoding.writeBinaryEncoder(enc, encoder.restEncoder)\n encoder.restEncoder = enc\n return encoder.toUint8Array()\n } else {\n encoding.writeVarUint(encoder.restEncoder, 0)\n return encoder.toUint8Array()\n }\n}\n\n/**\n * @param {Uint8Array} update\n * @return {Uint8Array}\n */\nexport const encodeStateVectorFromUpdate = update => encodeStateVectorFromUpdateV2(update, DSEncoderV1, UpdateDecoderV1)\n\n/**\n * @param {Uint8Array} update\n * @param {typeof UpdateDecoderV1 | typeof UpdateDecoderV2} YDecoder\n * @return {{ from: Map<number,number>, to: Map<number,number> }}\n */\nexport const parseUpdateMetaV2 = (update, YDecoder = UpdateDecoderV2) => {\n /**\n * @type {Map<number, number>}\n */\n const from = new Map()\n /**\n * @type {Map<number, number>}\n */\n const to = new Map()\n const updateDecoder = new LazyStructReader(new YDecoder(decoding.createDecoder(update)), false)\n let curr = updateDecoder.curr\n if (curr !== null) {\n let currClient = curr.id.client\n let currClock = curr.id.clock\n // write the beginning to `from`\n from.set(currClient, currClock)\n for (; curr !== null; curr = updateDecoder.next()) {\n if (currClient !== curr.id.client) {\n // We found a new client\n // write the end to `to`\n to.set(currClient, currClock)\n // write the beginning to `from`\n from.set(curr.id.client, curr.id.clock)\n // update currClient\n currClient = curr.id.client\n }\n currClock = curr.id.clock + curr.length\n }\n // write the end to `to`\n to.set(currClient, currClock)\n }\n return { from, to }\n}\n\n/**\n * @param {Uint8Array} update\n * @return {{ from: Map<number,number>, to: Map<number,number> }}\n */\nexport const parseUpdateMeta = update => parseUpdateMetaV2(update, UpdateDecoderV1)\n\n/**\n * This method is intended to slice any kind of struct and retrieve the right part.\n * It does not handle side-effects, so it should only be used by the lazy-encoder.\n *\n * @param {Item | GC | Skip} left\n * @param {number} diff\n * @return {Item | GC}\n */\nconst sliceStruct = (left, diff) => {\n if (left.constructor === GC) {\n const { client, clock } = left.id\n return new GC(createID(client, clock + diff), left.length - diff)\n } else if (left.constructor === Skip) {\n const { client, clock } = left.id\n return new Skip(createID(client, clock + diff), left.length - diff)\n } else {\n const leftItem = /** @type {Item} */ (left)\n const { client, clock } = leftItem.id\n return new Item(\n createID(client, clock + diff),\n null,\n createID(client, clock + diff - 1),\n null,\n leftItem.rightOrigin,\n leftItem.parent,\n leftItem.parentSub,\n leftItem.content.splice(diff)\n )\n }\n}\n\n/**\n *\n * This function works similarly to `readUpdateV2`.\n *\n * @param {Array<Uint8Array>} updates\n * @param {typeof UpdateDecoderV1 | typeof UpdateDecoderV2} [YDecoder]\n * @param {typeof UpdateEncoderV1 | typeof UpdateEncoderV2} [YEncoder]\n * @return {Uint8Array}\n */\nexport const mergeUpdatesV2 = (updates, YDecoder = UpdateDecoderV2, YEncoder = UpdateEncoderV2) => {\n if (updates.length === 1) {\n return updates[0]\n }\n const updateDecoders = updates.map(update => new YDecoder(decoding.createDecoder(update)))\n let lazyStructDecoders = updateDecoders.map(decoder => new LazyStructReader(decoder, true))\n\n /**\n * @todo we don't need offset because we always slice before\n * @type {null | { struct: Item | GC | Skip, offset: number }}\n */\n let currWrite = null\n\n const updateEncoder = new YEncoder()\n // write structs lazily\n const lazyStructEncoder = new LazyStructWriter(updateEncoder)\n\n // Note: We need to ensure that all lazyStructDecoders are fully consumed\n // Note: Should merge document updates whenever possible - even from different updates\n // Note: Should handle that some operations cannot be applied yet ()\n\n while (true) {\n // Write higher clients first ⇒ sort by clientID & clock and remove decoders without content\n lazyStructDecoders = lazyStructDecoders.filter(dec => dec.curr !== null)\n lazyStructDecoders.sort(\n /** @type {function(any,any):number} */ (dec1, dec2) => {\n if (dec1.curr.id.client === dec2.curr.id.client) {\n const clockDiff = dec1.curr.id.clock - dec2.curr.id.clock\n if (clockDiff === 0) {\n // @todo remove references to skip since the structDecoders must filter Skips.\n return dec1.curr.constructor === dec2.curr.constructor\n ? 0\n : dec1.curr.constructor === Skip ? 1 : -1 // we are filtering skips anyway.\n } else {\n return clockDiff\n }\n } else {\n return dec2.curr.id.client - dec1.curr.id.client\n }\n }\n )\n if (lazyStructDecoders.length === 0) {\n break\n }\n const currDecoder = lazyStructDecoders[0]\n // write from currDecoder until the next operation is from another client or if filler-struct\n // then we need to reorder the decoders and find the next operation to write\n const firstClient = /** @type {Item | GC} */ (currDecoder.curr).id.client\n\n if (currWrite !== null) {\n let curr = /** @type {Item | GC | null} */ (currDecoder.curr)\n let iterated = false\n\n // iterate until we find something that we haven't written already\n // remember: first the high client-ids are written\n while (curr !== null && curr.id.clock + curr.length <= currWrite.struct.id.clock + currWrite.struct.length && curr.id.client >= currWrite.struct.id.client) {\n curr = currDecoder.next()\n iterated = true\n }\n if (\n curr === null || // current decoder is empty\n curr.id.client !== firstClient || // check whether there is another decoder that has has updates from `firstClient`\n (iterated && curr.id.clock > currWrite.struct.id.clock + currWrite.struct.length) // the above while loop was used and we are potentially missing updates\n ) {\n continue\n }\n\n if (firstClient !== currWrite.struct.id.client) {\n writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset)\n currWrite = { struct: curr, offset: 0 }\n currDecoder.next()\n } else {\n if (currWrite.struct.id.clock + currWrite.struct.length < curr.id.clock) {\n // @todo write currStruct & set currStruct = Skip(clock = currStruct.id.clock + currStruct.length, length = curr.id.clock - self.clock)\n if (currWrite.struct.constructor === Skip) {\n // extend existing skip\n currWrite.struct.length = curr.id.clock + curr.length - currWrite.struct.id.clock\n } else {\n writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset)\n const diff = curr.id.clock - currWrite.struct.id.clock - currWrite.struct.length\n /**\n * @type {Skip}\n */\n const struct = new Skip(createID(firstClient, currWrite.struct.id.clock + currWrite.struct.length), diff)\n currWrite = { struct, offset: 0 }\n }\n } else { // if (currWrite.struct.id.clock + currWrite.struct.length >= curr.id.clock) {\n const diff = currWrite.struct.id.clock + currWrite.struct.length - curr.id.clock\n if (diff > 0) {\n if (currWrite.struct.constructor === Skip) {\n // prefer to slice Skip because the other struct might contain more information\n currWrite.struct.length -= diff\n } else {\n curr = sliceStruct(curr, diff)\n }\n }\n if (!currWrite.struct.mergeWith(/** @type {any} */ (curr))) {\n writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset)\n currWrite = { struct: curr, offset: 0 }\n currDecoder.next()\n }\n }\n }\n } else {\n currWrite = { struct: /** @type {Item | GC} */ (currDecoder.curr), offset: 0 }\n currDecoder.next()\n }\n for (\n let next = currDecoder.curr;\n next !== null && next.id.client === firstClient && next.id.clock === currWrite.struct.id.clock + currWrite.struct.length && next.constructor !== Skip;\n next = currDecoder.next()\n ) {\n writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset)\n currWrite = { struct: next, offset: 0 }\n }\n }\n if (currWrite !== null) {\n writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset)\n currWrite = null\n }\n finishLazyStructWriting(lazyStructEncoder)\n\n const dss = updateDecoders.map(decoder => readDeleteSet(decoder))\n const ds = mergeDeleteSets(dss)\n writeDeleteSet(updateEncoder, ds)\n return updateEncoder.toUint8Array()\n}\n\n/**\n * @param {Uint8Array} update\n * @param {Uint8Array} sv\n * @param {typeof UpdateDecoderV1 | typeof UpdateDecoderV2} [YDecoder]\n * @param {typeof UpdateEncoderV1 | typeof UpdateEncoderV2} [YEncoder]\n */\nexport const diffUpdateV2 = (update, sv, YDecoder = UpdateDecoderV2, YEncoder = UpdateEncoderV2) => {\n const state = decodeStateVector(sv)\n const encoder = new YEncoder()\n const lazyStructWriter = new LazyStructWriter(encoder)\n const decoder = new YDecoder(decoding.createDecoder(update))\n const reader = new LazyStructReader(decoder, false)\n while (reader.curr) {\n const curr = reader.curr\n const currClient = curr.id.client\n const svClock = state.get(currClient) || 0\n if (reader.curr.constructor === Skip) {\n // the first written struct shouldn't be a skip\n reader.next()\n continue\n }\n if (curr.id.clock + curr.length > svClock) {\n writeStructToLazyStructWriter(lazyStructWriter, curr, math.max(svClock - curr.id.clock, 0))\n reader.next()\n while (reader.curr && reader.curr.id.client === currClient) {\n writeStructToLazyStructWriter(lazyStructWriter, reader.curr, 0)\n reader.next()\n }\n } else {\n // read until something new comes up\n while (reader.curr && reader.curr.id.client === currClient && reader.curr.id.clock + reader.curr.length <= svClock) {\n reader.next()\n }\n }\n }\n finishLazyStructWriting(lazyStructWriter)\n // write ds\n const ds = readDeleteSet(decoder)\n writeDeleteSet(encoder, ds)\n return encoder.toUint8Array()\n}\n\n/**\n * @param {Uint8Array} update\n * @param {Uint8Array} sv\n */\nexport const diffUpdate = (update, sv) => diffUpdateV2(update, sv, UpdateDecoderV1, UpdateEncoderV1)\n\n/**\n * @param {LazyStructWriter} lazyWriter\n */\nconst flushLazyStructWriter = lazyWriter => {\n if (lazyWriter.written > 0) {\n lazyWriter.clientStructs.push({ written: lazyWriter.written, restEncoder: encoding.toUint8Array(lazyWriter.encoder.restEncoder) })\n lazyWriter.encoder.restEncoder = encoding.createEncoder()\n lazyWriter.written = 0\n }\n}\n\n/**\n * @param {LazyStructWriter} lazyWriter\n * @param {Item | GC} struct\n * @param {number} offset\n */\nconst writeStructToLazyStructWriter = (lazyWriter, struct, offset) => {\n // flush curr if we start another client\n if (lazyWriter.written > 0 && lazyWriter.currClient !== struct.id.client) {\n flushLazyStructWriter(lazyWriter)\n }\n if (lazyWriter.written === 0) {\n lazyWriter.currClient = struct.id.client\n // write next client\n lazyWriter.encoder.writeClient(struct.id.client)\n // write startClock\n encoding.writeVarUint(lazyWriter.encoder.restEncoder, struct.id.clock + offset)\n }\n struct.write(lazyWriter.encoder, offset)\n lazyWriter.written++\n}\n/**\n * Call this function when we collected all parts and want to\n * put all the parts together. After calling this method,\n * you can continue using the UpdateEncoder.\n *\n * @param {LazyStructWriter} lazyWriter\n */\nconst finishLazyStructWriting = (lazyWriter) => {\n flushLazyStructWriter(lazyWriter)\n\n // this is a fresh encoder because we called flushCurr\n const restEncoder = lazyWriter.encoder.restEncoder\n\n /**\n * Now we put all the fragments together.\n * This works similarly to `writeClientsStructs`\n */\n\n // write # states that were updated - i.e. the clients\n encoding.writeVarUint(restEncoder, lazyWriter.clientStructs.length)\n\n for (let i = 0; i < lazyWriter.clientStructs.length; i++) {\n const partStructs = lazyWriter.clientStructs[i]\n /**\n * Works similarly to `writeStructs`\n */\n // write # encoded structs\n encoding.writeVarUint(restEncoder, partStructs.written)\n // write the rest of the fragment\n encoding.writeUint8Array(restEncoder, partStructs.restEncoder)\n }\n}\n\n/**\n * @param {Uint8Array} update\n * @param {function(Item|GC|Skip):Item|GC|Skip} blockTransformer\n * @param {typeof UpdateDecoderV2 | typeof UpdateDecoderV1} YDecoder\n * @param {typeof UpdateEncoderV2 | typeof UpdateEncoderV1 } YEncoder\n */\nexport const convertUpdateFormat = (update, blockTransformer, YDecoder, YEncoder) => {\n const updateDecoder = new YDecoder(decoding.createDecoder(update))\n const lazyDecoder = new LazyStructReader(updateDecoder, false)\n const updateEncoder = new YEncoder()\n const lazyWriter = new LazyStructWriter(updateEncoder)\n for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {\n writeStructToLazyStructWriter(lazyWriter, blockTransformer(curr), 0)\n }\n finishLazyStructWriting(lazyWriter)\n const ds = readDeleteSet(updateDecoder)\n writeDeleteSet(updateEncoder, ds)\n return updateEncoder.toUint8Array()\n}\n\n/**\n * @typedef {Object} ObfuscatorOptions\n * @property {boolean} [ObfuscatorOptions.formatting=true]\n * @property {boolean} [ObfuscatorOptions.subdocs=true]\n * @property {boolean} [ObfuscatorOptions.yxml=true] Whether to obfuscate nodeName / hookName\n */\n\n/**\n * @param {ObfuscatorOptions} obfuscator\n */\nconst createObfuscator = ({ formatting = true, subdocs = true, yxml = true } = {}) => {\n let i = 0\n const mapKeyCache = map.create()\n const nodeNameCache = map.create()\n const formattingKeyCache = map.create()\n const formattingValueCache = map.create()\n formattingValueCache.set(null, null) // end of a formatting range should always be the end of a formatting range\n /**\n * @param {Item|GC|Skip} block\n * @return {Item|GC|Skip}\n */\n return block => {\n switch (block.constructor) {\n case GC:\n case Skip:\n return block\n case Item: {\n const item = /** @type {Item} */ (block)\n const content = item.content\n switch (content.constructor) {\n case ContentDeleted:\n break\n case ContentType: {\n if (yxml) {\n const type = /** @type {ContentType} */ (content).type\n if (type instanceof YXmlElement) {\n type.nodeName = map.setIfUndefined(nodeNameCache, type.nodeName, () => 'node-' + i)\n }\n if (type instanceof YXmlHook) {\n type.hookName = map.setIfUndefined(nodeNameCache, type.hookName, () => 'hook-' + i)\n }\n }\n break\n }\n case ContentAny: {\n const c = /** @type {ContentAny} */ (content)\n c.arr = c.arr.map(() => i)\n break\n }\n case ContentBinary: {\n const c = /** @type {ContentBinary} */ (content)\n c.content = new Uint8Array([i])\n break\n }\n case ContentDoc: {\n const c = /** @type {ContentDoc} */ (content)\n if (subdocs) {\n c.opts = {}\n c.doc.guid = i + ''\n }\n break\n }\n case ContentEmbed: {\n const c = /** @type {ContentEmbed} */ (content)\n c.embed = {}\n break\n }\n case ContentFormat: {\n const c = /** @type {ContentFormat} */ (content)\n if (formatting) {\n c.key = map.setIfUndefined(formattingKeyCache, c.key, () => i + '')\n c.value = map.setIfUndefined(formattingValueCache, c.value, () => ({ i }))\n }\n break\n }\n case ContentJSON: {\n const c = /** @type {ContentJSON} */ (content)\n c.arr = c.arr.map(() => i)\n break\n }\n case ContentString: {\n const c = /** @type {ContentString} */ (content)\n c.str = string.repeat((i % 10) + '', c.str.length)\n break\n }\n default:\n // unknown content type\n error.unexpectedCase()\n }\n if (item.parentSub) {\n item.parentSub = map.setIfUndefined(mapKeyCache, item.parentSub, () => i + '')\n }\n i++\n return block\n }\n default:\n // unknown block-type\n error.unexpectedCase()\n }\n }\n}\n\n/**\n * This function obfuscates the content of a Yjs update. This is useful to share\n * buggy Yjs documents while significantly limiting the possibility that a\n * developer can on the user. Note that it might still be possible to deduce\n * some information by analyzing the \"structure\" of the document or by analyzing\n * the typing behavior using the CRDT-related metadata that is still kept fully\n * intact.\n *\n * @param {Uint8Array} update\n * @param {ObfuscatorOptions} [opts]\n */\nexport const obfuscateUpdate = (update, opts) => convertUpdateFormat(update, createObfuscator(opts), UpdateDecoderV1, UpdateEncoderV1)\n\n/**\n * @param {Uint8Array} update\n * @param {ObfuscatorOptions} [opts]\n */\nexport const obfuscateUpdateV2 = (update, opts) => convertUpdateFormat(update, createObfuscator(opts), UpdateDecoderV2, UpdateEncoderV2)\n\n/**\n * @param {Uint8Array} update\n */\nexport const convertUpdateFormatV1ToV2 = update => convertUpdateFormat(update, f.id, UpdateDecoderV1, UpdateEncoderV2)\n\n/**\n * @param {Uint8Array} update\n */\nexport const convertUpdateFormatV2ToV1 = update => convertUpdateFormat(update, f.id, UpdateDecoderV2, UpdateEncoderV1)\n","import {\n isDeleted,\n Item, AbstractType, Transaction, AbstractStruct // eslint-disable-line\n} from '../internals.js'\n\nimport * as set from 'lib0/set'\nimport * as array from 'lib0/array'\nimport * as error from 'lib0/error'\n\nconst errorComputeChanges = 'You must not compute changes after the event-handler fired.'\n\n/**\n * @template {AbstractType<any>} T\n * YEvent describes the changes on a YType.\n */\nexport class YEvent {\n /**\n * @param {T} target The changed type.\n * @param {Transaction} transaction\n */\n constructor (target, transaction) {\n /**\n * The type on which this event was created on.\n * @type {T}\n */\n this.target = target\n /**\n * The current target on which the observe callback is called.\n * @type {AbstractType<any>}\n */\n this.currentTarget = target\n /**\n * The transaction that triggered this event.\n * @type {Transaction}\n */\n this.transaction = transaction\n /**\n * @type {Object|null}\n */\n this._changes = null\n /**\n * @type {null | Map<string, { action: 'add' | 'update' | 'delete', oldValue: any, newValue: any }>}\n */\n this._keys = null\n /**\n * @type {null | Array<{ insert?: string | Array<any> | object | AbstractType<any>, retain?: number, delete?: number, attributes?: Object<string, any> }>}\n */\n this._delta = null\n /**\n * @type {Array<string|number>|null}\n */\n this._path = null\n }\n\n /**\n * Computes the path from `y` to the changed type.\n *\n * @todo v14 should standardize on path: Array<{parent, index}> because that is easier to work with.\n *\n * The following property holds:\n * @example\n * let type = y\n * event.path.forEach(dir => {\n * type = type.get(dir)\n * })\n * type === event.target // => true\n */\n get path () {\n return this._path || (this._path = getPathTo(this.currentTarget, this.target))\n }\n\n /**\n * Check if a struct is deleted by this event.\n *\n * In contrast to change.deleted, this method also returns true if the struct was added and then deleted.\n *\n * @param {AbstractStruct} struct\n * @return {boolean}\n */\n deletes (struct) {\n return isDeleted(this.transaction.deleteSet, struct.id)\n }\n\n /**\n * @type {Map<string, { action: 'add' | 'update' | 'delete', oldValue: any, newValue: any }>}\n */\n get keys () {\n if (this._keys === null) {\n if (this.transaction.doc._transactionCleanups.length === 0) {\n throw error.create(errorComputeChanges)\n }\n const keys = new Map()\n const target = this.target\n const changed = /** @type Set<string|null> */ (this.transaction.changed.get(target))\n changed.forEach(key => {\n if (key !== null) {\n const item = /** @type {Item} */ (target._map.get(key))\n /**\n * @type {'delete' | 'add' | 'update'}\n */\n let action\n let oldValue\n if (this.adds(item)) {\n let prev = item.left\n while (prev !== null && this.adds(prev)) {\n prev = prev.left\n }\n if (this.deletes(item)) {\n if (prev !== null && this.deletes(prev)) {\n action = 'delete'\n oldValue = array.last(prev.content.getContent())\n } else {\n return\n }\n } else {\n if (prev !== null && this.deletes(prev)) {\n action = 'update'\n oldValue = array.last(prev.content.getContent())\n } else {\n action = 'add'\n oldValue = undefined\n }\n }\n } else {\n if (this.deletes(item)) {\n action = 'delete'\n oldValue = array.last(/** @type {Item} */ item.content.getContent())\n } else {\n return // nop\n }\n }\n keys.set(key, { action, oldValue })\n }\n })\n this._keys = keys\n }\n return this._keys\n }\n\n /**\n * This is a computed property. Note that this can only be safely computed during the\n * event call. Computing this property after other changes happened might result in\n * unexpected behavior (incorrect computation of deltas). A safe way to collect changes\n * is to store the `changes` or the `delta` object. Avoid storing the `transaction` object.\n *\n * @type {Array<{insert?: string | Array<any> | object | AbstractType<any>, retain?: number, delete?: number, attributes?: Object<string, any>}>}\n */\n get delta () {\n return this.changes.delta\n }\n\n /**\n * Check if a struct is added by this event.\n *\n * In contrast to change.deleted, this method also returns true if the struct was added and then deleted.\n *\n * @param {AbstractStruct} struct\n * @return {boolean}\n */\n adds (struct) {\n return struct.id.clock >= (this.transaction.beforeState.get(struct.id.client) || 0)\n }\n\n /**\n * This is a computed property. Note that this can only be safely computed during the\n * event call. Computing this property after other changes happened might result in\n * unexpected behavior (incorrect computation of deltas). A safe way to collect changes\n * is to store the `changes` or the `delta` object. Avoid storing the `transaction` object.\n *\n * @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert?:Array<any>|string, delete?:number, retain?:number}>}}\n */\n get changes () {\n let changes = this._changes\n if (changes === null) {\n if (this.transaction.doc._transactionCleanups.length === 0) {\n throw error.create(errorComputeChanges)\n }\n const target = this.target\n const added = set.create()\n const deleted = set.create()\n /**\n * @type {Array<{insert:Array<any>}|{delete:number}|{retain:number}>}\n */\n const delta = []\n changes = {\n added,\n deleted,\n delta,\n keys: this.keys\n }\n const changed = /** @type Set<string|null> */ (this.transaction.changed.get(target))\n if (changed.has(null)) {\n /**\n * @type {any}\n */\n let lastOp = null\n const packOp = () => {\n if (lastOp) {\n delta.push(lastOp)\n }\n }\n for (let item = target._start; item !== null; item = item.right) {\n if (item.deleted) {\n if (this.deletes(item) && !this.adds(item)) {\n if (lastOp === null || lastOp.delete === undefined) {\n packOp()\n lastOp = { delete: 0 }\n }\n lastOp.delete += item.length\n deleted.add(item)\n } // else nop\n } else {\n if (this.adds(item)) {\n if (lastOp === null || lastOp.insert === undefined) {\n packOp()\n lastOp = { insert: [] }\n }\n lastOp.insert = lastOp.insert.concat(item.content.getContent())\n added.add(item)\n } else {\n if (lastOp === null || lastOp.retain === undefined) {\n packOp()\n lastOp = { retain: 0 }\n }\n lastOp.retain += item.length\n }\n }\n }\n if (lastOp !== null && lastOp.retain === undefined) {\n packOp()\n }\n }\n this._changes = changes\n }\n return /** @type {any} */ (changes)\n }\n}\n\n/**\n * Compute the path from this type to the specified target.\n *\n * @example\n * // `child` should be accessible via `type.get(path[0]).get(path[1])..`\n * const path = type.getPathTo(child)\n * // assuming `type instanceof YArray`\n * console.log(path) // might look like => [2, 'key1']\n * child === type.get(path[0]).get(path[1])\n *\n * @param {AbstractType<any>} parent\n * @param {AbstractType<any>} child target\n * @return {Array<string|number>} Path to the target\n *\n * @private\n * @function\n */\nconst getPathTo = (parent, child) => {\n const path = []\n while (child._item !== null && child !== parent) {\n if (child._item.parentSub !== null) {\n // parent is map-ish\n path.unshift(child._item.parentSub)\n } else {\n // parent is array-ish\n let i = 0\n let c = /** @type {AbstractType<any>} */ (child._item.parent)._start\n while (c !== child._item && c !== null) {\n if (!c.deleted && c.countable) {\n i += c.length\n }\n c = c.right\n }\n path.unshift(i)\n }\n child = /** @type {AbstractType<any>} */ (child._item.parent)\n }\n return path\n}\n","import {\n removeEventHandlerListener,\n callEventHandlerListeners,\n addEventHandlerListener,\n createEventHandler,\n getState,\n isVisible,\n ContentType,\n createID,\n ContentAny,\n ContentBinary,\n getItemCleanStart,\n ContentDoc, YText, YArray, UpdateEncoderV1, UpdateEncoderV2, Doc, Snapshot, Transaction, EventHandler, YEvent, Item, // eslint-disable-line\n} from '../internals.js'\n\nimport * as map from 'lib0/map'\nimport * as iterator from 'lib0/iterator'\nimport * as error from 'lib0/error'\nimport * as math from 'lib0/math'\nimport * as log from 'lib0/logging'\n\n/**\n * https://docs.yjs.dev/getting-started/working-with-shared-types#caveats\n */\nexport const warnPrematureAccess = () => { log.warn('Invalid access: Add Yjs type to a document before reading data.') }\n\nconst maxSearchMarker = 80\n\n/**\n * A unique timestamp that identifies each marker.\n *\n * Time is relative,.. this is more like an ever-increasing clock.\n *\n * @type {number}\n */\nlet globalSearchMarkerTimestamp = 0\n\nexport class ArraySearchMarker {\n /**\n * @param {Item} p\n * @param {number} index\n */\n constructor (p, index) {\n p.marker = true\n this.p = p\n this.index = index\n this.timestamp = globalSearchMarkerTimestamp++\n }\n}\n\n/**\n * @param {ArraySearchMarker} marker\n */\nconst refreshMarkerTimestamp = marker => { marker.timestamp = globalSearchMarkerTimestamp++ }\n\n/**\n * This is rather complex so this function is the only thing that should overwrite a marker\n *\n * @param {ArraySearchMarker} marker\n * @param {Item} p\n * @param {number} index\n */\nconst overwriteMarker = (marker, p, index) => {\n marker.p.marker = false\n marker.p = p\n p.marker = true\n marker.index = index\n marker.timestamp = globalSearchMarkerTimestamp++\n}\n\n/**\n * @param {Array<ArraySearchMarker>} searchMarker\n * @param {Item} p\n * @param {number} index\n */\nconst markPosition = (searchMarker, p, index) => {\n if (searchMarker.length >= maxSearchMarker) {\n // override oldest marker (we don't want to create more objects)\n const marker = searchMarker.reduce((a, b) => a.timestamp < b.timestamp ? a : b)\n overwriteMarker(marker, p, index)\n return marker\n } else {\n // create new marker\n const pm = new ArraySearchMarker(p, index)\n searchMarker.push(pm)\n return pm\n }\n}\n\n/**\n * Search marker help us to find positions in the associative array faster.\n *\n * They speed up the process of finding a position without much bookkeeping.\n *\n * A maximum of `maxSearchMarker` objects are created.\n *\n * This function always returns a refreshed marker (updated timestamp)\n *\n * @param {AbstractType<any>} yarray\n * @param {number} index\n */\nexport const findMarker = (yarray, index) => {\n if (yarray._start === null || index === 0 || yarray._searchMarker === null) {\n return null\n }\n const marker = yarray._searchMarker.length === 0 ? null : yarray._searchMarker.reduce((a, b) => math.abs(index - a.index) < math.abs(index - b.index) ? a : b)\n let p = yarray._start\n let pindex = 0\n if (marker !== null) {\n p = marker.p\n pindex = marker.index\n refreshMarkerTimestamp(marker) // we used it, we might need to use it again\n }\n // iterate to right if possible\n while (p.right !== null && pindex < index) {\n if (!p.deleted && p.countable) {\n if (index < pindex + p.length) {\n break\n }\n pindex += p.length\n }\n p = p.right\n }\n // iterate to left if necessary (might be that pindex > index)\n while (p.left !== null && pindex > index) {\n p = p.left\n if (!p.deleted && p.countable) {\n pindex -= p.length\n }\n }\n // we want to make sure that p can't be merged with left, because that would screw up everything\n // in that cas just return what we have (it is most likely the best marker anyway)\n // iterate to left until p can't be merged with left\n while (p.left !== null && p.left.id.client === p.id.client && p.left.id.clock + p.left.length === p.id.clock) {\n p = p.left\n if (!p.deleted && p.countable) {\n pindex -= p.length\n }\n }\n\n // @todo remove!\n // assure position\n // {\n // let start = yarray._start\n // let pos = 0\n // while (start !== p) {\n // if (!start.deleted && start.countable) {\n // pos += start.length\n // }\n // start = /** @type {Item} */ (start.right)\n // }\n // if (pos !== pindex) {\n // debugger\n // throw new Error('Gotcha position fail!')\n // }\n // }\n // if (marker) {\n // if (window.lengths == null) {\n // window.lengths = []\n // window.getLengths = () => window.lengths.sort((a, b) => a - b)\n // }\n // window.lengths.push(marker.index - pindex)\n // console.log('distance', marker.index - pindex, 'len', p && p.parent.length)\n // }\n if (marker !== null && math.abs(marker.index - pindex) < /** @type {YText|YArray<any>} */ (p.parent).length / maxSearchMarker) {\n // adjust existing marker\n overwriteMarker(marker, p, pindex)\n return marker\n } else {\n // create new marker\n return markPosition(yarray._searchMarker, p, pindex)\n }\n}\n\n/**\n * Update markers when a change happened.\n *\n * This should be called before doing a deletion!\n *\n * @param {Array<ArraySearchMarker>} searchMarker\n * @param {number} index\n * @param {number} len If insertion, len is positive. If deletion, len is negative.\n */\nexport const updateMarkerChanges = (searchMarker, index, len) => {\n for (let i = searchMarker.length - 1; i >= 0; i--) {\n const m = searchMarker[i]\n if (len > 0) {\n /**\n * @type {Item|null}\n */\n let p = m.p\n p.marker = false\n // Ideally we just want to do a simple position comparison, but this will only work if\n // search markers don't point to deleted items for formats.\n // Iterate marker to prev undeleted countable position so we know what to do when updating a position\n while (p && (p.deleted || !p.countable)) {\n p = p.left\n if (p && !p.deleted && p.countable) {\n // adjust position. the loop should break now\n m.index -= p.length\n }\n }\n if (p === null || p.marker === true) {\n // remove search marker if updated position is null or if position is already marked\n searchMarker.splice(i, 1)\n continue\n }\n m.p = p\n p.marker = true\n }\n if (index < m.index || (len > 0 && index === m.index)) { // a simple index <= m.index check would actually suffice\n m.index = math.max(index, m.index + len)\n }\n }\n}\n\n/**\n * Accumulate all (list) children of a type and return them as an Array.\n *\n * @param {AbstractType<any>} t\n * @return {Array<Item>}\n */\nexport const getTypeChildren = t => {\n t.doc ?? warnPrematureAccess()\n let s = t._start\n const arr = []\n while (s) {\n arr.push(s)\n s = s.right\n }\n return arr\n}\n\n/**\n * Call event listeners with an event. This will also add an event to all\n * parents (for `.observeDeep` handlers).\n *\n * @template EventType\n * @param {AbstractType<EventType>} type\n * @param {Transaction} transaction\n * @param {EventType} event\n */\nexport const callTypeObservers = (type, transaction, event) => {\n const changedType = type\n const changedParentTypes = transaction.changedParentTypes\n while (true) {\n // @ts-ignore\n map.setIfUndefined(changedParentTypes, type, () => []).push(event)\n if (type._item === null) {\n break\n }\n type = /** @type {AbstractType<any>} */ (type._item.parent)\n }\n callEventHandlerListeners(changedType._eH, event, transaction)\n}\n\n/**\n * @template EventType\n * Abstract Yjs Type class\n */\nexport class AbstractType {\n constructor () {\n /**\n * @type {Item|null}\n */\n this._item = null\n /**\n * @type {Map<string,Item>}\n */\n this._map = new Map()\n /**\n * @type {Item|null}\n */\n this._start = null\n /**\n * @type {Doc|null}\n */\n this.doc = null\n this._length = 0\n /**\n * Event handlers\n * @type {EventHandler<EventType,Transaction>}\n */\n this._eH = createEventHandler()\n /**\n * Deep event handlers\n * @type {EventHandler<Array<YEvent<any>>,Transaction>}\n */\n this._dEH = createEventHandler()\n /**\n * @type {null | Array<ArraySearchMarker>}\n */\n this._searchMarker = null\n }\n\n /**\n * @return {AbstractType<any>|null}\n */\n get parent () {\n return this._item ? /** @type {AbstractType<any>} */ (this._item.parent) : null\n }\n\n /**\n * Integrate this type into the Yjs instance.\n *\n * * Save this struct in the os\n * * This type is sent to other client\n * * Observer functions are fired\n *\n * @param {Doc} y The Yjs instance\n * @param {Item|null} item\n */\n _integrate (y, item) {\n this.doc = y\n this._item = item\n }\n\n /**\n * @return {AbstractType<EventType>}\n */\n _copy () {\n throw error.methodUnimplemented()\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {AbstractType<EventType>}\n */\n clone () {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} _encoder\n */\n _write (_encoder) { }\n\n /**\n * The first non-deleted item\n */\n get _first () {\n let n = this._start\n while (n !== null && n.deleted) {\n n = n.right\n }\n return n\n }\n\n /**\n * Creates YEvent and calls all type observers.\n * Must be implemented by each type.\n *\n * @param {Transaction} transaction\n * @param {Set<null|string>} _parentSubs Keys changed on this type. `null` if list was modified.\n */\n _callObserver (transaction, _parentSubs) {\n if (!transaction.local && this._searchMarker) {\n this._searchMarker.length = 0\n }\n }\n\n /**\n * Observe all events that are created on this type.\n *\n * @param {function(EventType, Transaction):void} f Observer function\n */\n observe (f) {\n addEventHandlerListener(this._eH, f)\n }\n\n /**\n * Observe all events that are created by this type and its children.\n *\n * @param {function(Array<YEvent<any>>,Transaction):void} f Observer function\n */\n observeDeep (f) {\n addEventHandlerListener(this._dEH, f)\n }\n\n /**\n * Unregister an observer function.\n *\n * @param {function(EventType,Transaction):void} f Observer function\n */\n unobserve (f) {\n removeEventHandlerListener(this._eH, f)\n }\n\n /**\n * Unregister an observer function.\n *\n * @param {function(Array<YEvent<any>>,Transaction):void} f Observer function\n */\n unobserveDeep (f) {\n removeEventHandlerListener(this._dEH, f)\n }\n\n /**\n * @abstract\n * @return {any}\n */\n toJSON () {}\n}\n\n/**\n * @param {AbstractType<any>} type\n * @param {number} start\n * @param {number} end\n * @return {Array<any>}\n *\n * @private\n * @function\n */\nexport const typeListSlice = (type, start, end) => {\n type.doc ?? warnPrematureAccess()\n if (start < 0) {\n start = type._length + start\n }\n if (end < 0) {\n end = type._length + end\n }\n let len = end - start\n const cs = []\n let n = type._start\n while (n !== null && len > 0) {\n if (n.countable && !n.deleted) {\n const c = n.content.getContent()\n if (c.length <= start) {\n start -= c.length\n } else {\n for (let i = start; i < c.length && len > 0; i++) {\n cs.push(c[i])\n len--\n }\n start = 0\n }\n }\n n = n.right\n }\n return cs\n}\n\n/**\n * @param {AbstractType<any>} type\n * @return {Array<any>}\n *\n * @private\n * @function\n */\nexport const typeListToArray = type => {\n type.doc ?? warnPrematureAccess()\n const cs = []\n let n = type._start\n while (n !== null) {\n if (n.countable && !n.deleted) {\n const c = n.content.getContent()\n for (let i = 0; i < c.length; i++) {\n cs.push(c[i])\n }\n }\n n = n.right\n }\n return cs\n}\n\n/**\n * @param {AbstractType<any>} type\n * @param {Snapshot} snapshot\n * @return {Array<any>}\n *\n * @private\n * @function\n */\nexport const typeListToArraySnapshot = (type, snapshot) => {\n const cs = []\n let n = type._start\n while (n !== null) {\n if (n.countable && isVisible(n, snapshot)) {\n const c = n.content.getContent()\n for (let i = 0; i < c.length; i++) {\n cs.push(c[i])\n }\n }\n n = n.right\n }\n return cs\n}\n\n/**\n * Executes a provided function on once on every element of this YArray.\n *\n * @param {AbstractType<any>} type\n * @param {function(any,number,any):void} f A function to execute on every element of this YArray.\n *\n * @private\n * @function\n */\nexport const typeListForEach = (type, f) => {\n let index = 0\n let n = type._start\n type.doc ?? warnPrematureAccess()\n while (n !== null) {\n if (n.countable && !n.deleted) {\n const c = n.content.getContent()\n for (let i = 0; i < c.length; i++) {\n f(c[i], index++, type)\n }\n }\n n = n.right\n }\n}\n\n/**\n * @template C,R\n * @param {AbstractType<any>} type\n * @param {function(C,number,AbstractType<any>):R} f\n * @return {Array<R>}\n *\n * @private\n * @function\n */\nexport const typeListMap = (type, f) => {\n /**\n * @type {Array<any>}\n */\n const result = []\n typeListForEach(type, (c, i) => {\n result.push(f(c, i, type))\n })\n return result\n}\n\n/**\n * @param {AbstractType<any>} type\n * @return {IterableIterator<any>}\n *\n * @private\n * @function\n */\nexport const typeListCreateIterator = type => {\n let n = type._start\n /**\n * @type {Array<any>|null}\n */\n let currentContent = null\n let currentContentIndex = 0\n return {\n [Symbol.iterator] () {\n return this\n },\n next: () => {\n // find some content\n if (currentContent === null) {\n while (n !== null && n.deleted) {\n n = n.right\n }\n // check if we reached the end, no need to check currentContent, because it does not exist\n if (n === null) {\n return {\n done: true,\n value: undefined\n }\n }\n // we found n, so we can set currentContent\n currentContent = n.content.getContent()\n currentContentIndex = 0\n n = n.right // we used the content of n, now iterate to next\n }\n const value = currentContent[currentContentIndex++]\n // check if we need to empty currentContent\n if (currentContent.length <= currentContentIndex) {\n currentContent = null\n }\n return {\n done: false,\n value\n }\n }\n }\n}\n\n/**\n * Executes a provided function on once on every element of this YArray.\n * Operates on a snapshotted state of the document.\n *\n * @param {AbstractType<any>} type\n * @param {function(any,number,AbstractType<any>):void} f A function to execute on every element of this YArray.\n * @param {Snapshot} snapshot\n *\n * @private\n * @function\n */\nexport const typeListForEachSnapshot = (type, f, snapshot) => {\n let index = 0\n let n = type._start\n while (n !== null) {\n if (n.countable && isVisible(n, snapshot)) {\n const c = n.content.getContent()\n for (let i = 0; i < c.length; i++) {\n f(c[i], index++, type)\n }\n }\n n = n.right\n }\n}\n\n/**\n * @param {AbstractType<any>} type\n * @param {number} index\n * @return {any}\n *\n * @private\n * @function\n */\nexport const typeListGet = (type, index) => {\n type.doc ?? warnPrematureAccess()\n const marker = findMarker(type, index)\n let n = type._start\n if (marker !== null) {\n n = marker.p\n index -= marker.index\n }\n for (; n !== null; n = n.right) {\n if (!n.deleted && n.countable) {\n if (index < n.length) {\n return n.content.getContent()[index]\n }\n index -= n.length\n }\n }\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {Item?} referenceItem\n * @param {Array<Object<string,any>|Array<any>|boolean|number|null|string|Uint8Array>} content\n *\n * @private\n * @function\n */\nexport const typeListInsertGenericsAfter = (transaction, parent, referenceItem, content) => {\n let left = referenceItem\n const doc = transaction.doc\n const ownClientId = doc.clientID\n const store = doc.store\n const right = referenceItem === null ? parent._start : referenceItem.right\n /**\n * @type {Array<Object|Array<any>|number|null>}\n */\n let jsonContent = []\n const packJsonContent = () => {\n if (jsonContent.length > 0) {\n left = new Item(createID(ownClientId, getState(store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentAny(jsonContent))\n left.integrate(transaction, 0)\n jsonContent = []\n }\n }\n content.forEach(c => {\n if (c === null) {\n jsonContent.push(c)\n } else {\n switch (c.constructor) {\n case Number:\n case Object:\n case Boolean:\n case Array:\n case String:\n jsonContent.push(c)\n break\n default:\n packJsonContent()\n switch (c.constructor) {\n case Uint8Array:\n case ArrayBuffer:\n left = new Item(createID(ownClientId, getState(store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentBinary(new Uint8Array(/** @type {Uint8Array} */ (c))))\n left.integrate(transaction, 0)\n break\n case Doc:\n left = new Item(createID(ownClientId, getState(store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentDoc(/** @type {Doc} */ (c)))\n left.integrate(transaction, 0)\n break\n default:\n if (c instanceof AbstractType) {\n left = new Item(createID(ownClientId, getState(store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentType(c))\n left.integrate(transaction, 0)\n } else {\n throw new Error('Unexpected content type in insert operation')\n }\n }\n }\n }\n })\n packJsonContent()\n}\n\nconst lengthExceeded = () => error.create('Length exceeded!')\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {number} index\n * @param {Array<Object<string,any>|Array<any>|number|null|string|Uint8Array>} content\n *\n * @private\n * @function\n */\nexport const typeListInsertGenerics = (transaction, parent, index, content) => {\n if (index > parent._length) {\n throw lengthExceeded()\n }\n if (index === 0) {\n if (parent._searchMarker) {\n updateMarkerChanges(parent._searchMarker, index, content.length)\n }\n return typeListInsertGenericsAfter(transaction, parent, null, content)\n }\n const startIndex = index\n const marker = findMarker(parent, index)\n let n = parent._start\n if (marker !== null) {\n n = marker.p\n index -= marker.index\n // we need to iterate one to the left so that the algorithm works\n if (index === 0) {\n // @todo refactor this as it actually doesn't consider formats\n n = n.prev // important! get the left undeleted item so that we can actually decrease index\n index += (n && n.countable && !n.deleted) ? n.length : 0\n }\n }\n for (; n !== null; n = n.right) {\n if (!n.deleted && n.countable) {\n if (index <= n.length) {\n if (index < n.length) {\n // insert in-between\n getItemCleanStart(transaction, createID(n.id.client, n.id.clock + index))\n }\n break\n }\n index -= n.length\n }\n }\n if (parent._searchMarker) {\n updateMarkerChanges(parent._searchMarker, startIndex, content.length)\n }\n return typeListInsertGenericsAfter(transaction, parent, n, content)\n}\n\n/**\n * Pushing content is special as we generally want to push after the last item. So we don't have to update\n * the search marker.\n *\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {Array<Object<string,any>|Array<any>|number|null|string|Uint8Array>} content\n *\n * @private\n * @function\n */\nexport const typeListPushGenerics = (transaction, parent, content) => {\n // Use the marker with the highest index and iterate to the right.\n const marker = (parent._searchMarker || []).reduce((maxMarker, currMarker) => currMarker.index > maxMarker.index ? currMarker : maxMarker, { index: 0, p: parent._start })\n let n = marker.p\n if (n) {\n while (n.right) {\n n = n.right\n }\n }\n return typeListInsertGenericsAfter(transaction, parent, n, content)\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {number} index\n * @param {number} length\n *\n * @private\n * @function\n */\nexport const typeListDelete = (transaction, parent, index, length) => {\n if (length === 0) { return }\n const startIndex = index\n const startLength = length\n const marker = findMarker(parent, index)\n let n = parent._start\n if (marker !== null) {\n n = marker.p\n index -= marker.index\n }\n // compute the first item to be deleted\n for (; n !== null && index > 0; n = n.right) {\n if (!n.deleted && n.countable) {\n if (index < n.length) {\n getItemCleanStart(transaction, createID(n.id.client, n.id.clock + index))\n }\n index -= n.length\n }\n }\n // delete all items until done\n while (length > 0 && n !== null) {\n if (!n.deleted) {\n if (length < n.length) {\n getItemCleanStart(transaction, createID(n.id.client, n.id.clock + length))\n }\n n.delete(transaction)\n length -= n.length\n }\n n = n.right\n }\n if (length > 0) {\n throw lengthExceeded()\n }\n if (parent._searchMarker) {\n updateMarkerChanges(parent._searchMarker, startIndex, -startLength + length /* in case we remove the above exception */)\n }\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {string} key\n *\n * @private\n * @function\n */\nexport const typeMapDelete = (transaction, parent, key) => {\n const c = parent._map.get(key)\n if (c !== undefined) {\n c.delete(transaction)\n }\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {string} key\n * @param {Object|number|null|Array<any>|string|Uint8Array|AbstractType<any>} value\n *\n * @private\n * @function\n */\nexport const typeMapSet = (transaction, parent, key, value) => {\n const left = parent._map.get(key) || null\n const doc = transaction.doc\n const ownClientId = doc.clientID\n let content\n if (value == null) {\n content = new ContentAny([value])\n } else {\n switch (value.constructor) {\n case Number:\n case Object:\n case Boolean:\n case Array:\n case String:\n case Date:\n case BigInt:\n content = new ContentAny([value])\n break\n case Uint8Array:\n content = new ContentBinary(/** @type {Uint8Array} */ (value))\n break\n case Doc:\n content = new ContentDoc(/** @type {Doc} */ (value))\n break\n default:\n if (value instanceof AbstractType) {\n content = new ContentType(value)\n } else {\n throw new Error('Unexpected content type')\n }\n }\n }\n new Item(createID(ownClientId, getState(doc.store, ownClientId)), left, left && left.lastId, null, null, parent, key, content).integrate(transaction, 0)\n}\n\n/**\n * @param {AbstractType<any>} parent\n * @param {string} key\n * @return {Object<string,any>|number|null|Array<any>|string|Uint8Array|AbstractType<any>|undefined}\n *\n * @private\n * @function\n */\nexport const typeMapGet = (parent, key) => {\n parent.doc ?? warnPrematureAccess()\n const val = parent._map.get(key)\n return val !== undefined && !val.deleted ? val.content.getContent()[val.length - 1] : undefined\n}\n\n/**\n * @param {AbstractType<any>} parent\n * @return {Object<string,Object<string,any>|number|null|Array<any>|string|Uint8Array|AbstractType<any>|undefined>}\n *\n * @private\n * @function\n */\nexport const typeMapGetAll = (parent) => {\n /**\n * @type {Object<string,any>}\n */\n const res = {}\n parent.doc ?? warnPrematureAccess()\n parent._map.forEach((value, key) => {\n if (!value.deleted) {\n res[key] = value.content.getContent()[value.length - 1]\n }\n })\n return res\n}\n\n/**\n * @param {AbstractType<any>} parent\n * @param {string} key\n * @return {boolean}\n *\n * @private\n * @function\n */\nexport const typeMapHas = (parent, key) => {\n parent.doc ?? warnPrematureAccess()\n const val = parent._map.get(key)\n return val !== undefined && !val.deleted\n}\n\n/**\n * @param {AbstractType<any>} parent\n * @param {string} key\n * @param {Snapshot} snapshot\n * @return {Object<string,any>|number|null|Array<any>|string|Uint8Array|AbstractType<any>|undefined}\n *\n * @private\n * @function\n */\nexport const typeMapGetSnapshot = (parent, key, snapshot) => {\n let v = parent._map.get(key) || null\n while (v !== null && (!snapshot.sv.has(v.id.client) || v.id.clock >= (snapshot.sv.get(v.id.client) || 0))) {\n v = v.left\n }\n return v !== null && isVisible(v, snapshot) ? v.content.getContent()[v.length - 1] : undefined\n}\n\n/**\n * @param {AbstractType<any>} parent\n * @param {Snapshot} snapshot\n * @return {Object<string,Object<string,any>|number|null|Array<any>|string|Uint8Array|AbstractType<any>|undefined>}\n *\n * @private\n * @function\n */\nexport const typeMapGetAllSnapshot = (parent, snapshot) => {\n /**\n * @type {Object<string,any>}\n */\n const res = {}\n parent._map.forEach((value, key) => {\n /**\n * @type {Item|null}\n */\n let v = value\n while (v !== null && (!snapshot.sv.has(v.id.client) || v.id.clock >= (snapshot.sv.get(v.id.client) || 0))) {\n v = v.left\n }\n if (v !== null && isVisible(v, snapshot)) {\n res[key] = v.content.getContent()[v.length - 1]\n }\n })\n return res\n}\n\n/**\n * @param {AbstractType<any> & { _map: Map<string, Item> }} type\n * @return {IterableIterator<Array<any>>}\n *\n * @private\n * @function\n */\nexport const createMapIterator = type => {\n type.doc ?? warnPrematureAccess()\n return iterator.iteratorFilter(type._map.entries(), /** @param {any} entry */ entry => !entry[1].deleted)\n}\n","/**\n * @module YArray\n */\n\nimport {\n YEvent,\n AbstractType,\n typeListGet,\n typeListToArray,\n typeListForEach,\n typeListCreateIterator,\n typeListInsertGenerics,\n typeListPushGenerics,\n typeListDelete,\n typeListMap,\n YArrayRefID,\n callTypeObservers,\n transact,\n warnPrematureAccess,\n ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item // eslint-disable-line\n} from '../internals.js'\nimport { typeListSlice } from './AbstractType.js'\n\n/**\n * Event that describes the changes on a YArray\n * @template T\n * @extends YEvent<YArray<T>>\n */\nexport class YArrayEvent extends YEvent {}\n\n/**\n * A shared Array implementation.\n * @template T\n * @extends AbstractType<YArrayEvent<T>>\n * @implements {Iterable<T>}\n */\nexport class YArray extends AbstractType {\n constructor () {\n super()\n /**\n * @type {Array<any>?}\n * @private\n */\n this._prelimContent = []\n /**\n * @type {Array<ArraySearchMarker>}\n */\n this._searchMarker = []\n }\n\n /**\n * Construct a new YArray containing the specified items.\n * @template {Object<string,any>|Array<any>|number|null|string|Uint8Array} T\n * @param {Array<T>} items\n * @return {YArray<T>}\n */\n static from (items) {\n /**\n * @type {YArray<T>}\n */\n const a = new YArray()\n a.push(items)\n return a\n }\n\n /**\n * Integrate this type into the Yjs instance.\n *\n * * Save this struct in the os\n * * This type is sent to other client\n * * Observer functions are fired\n *\n * @param {Doc} y The Yjs instance\n * @param {Item} item\n */\n _integrate (y, item) {\n super._integrate(y, item)\n this.insert(0, /** @type {Array<any>} */ (this._prelimContent))\n this._prelimContent = null\n }\n\n /**\n * @return {YArray<T>}\n */\n _copy () {\n return new YArray()\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YArray<T>}\n */\n clone () {\n /**\n * @type {YArray<T>}\n */\n const arr = new YArray()\n arr.insert(0, this.toArray().map(el =>\n el instanceof AbstractType ? /** @type {typeof el} */ (el.clone()) : el\n ))\n return arr\n }\n\n get length () {\n this.doc ?? warnPrematureAccess()\n return this._length\n }\n\n /**\n * Creates YArrayEvent and calls observers.\n *\n * @param {Transaction} transaction\n * @param {Set<null|string>} parentSubs Keys changed on this type. `null` if list was modified.\n */\n _callObserver (transaction, parentSubs) {\n super._callObserver(transaction, parentSubs)\n callTypeObservers(this, transaction, new YArrayEvent(this, transaction))\n }\n\n /**\n * Inserts new content at an index.\n *\n * Important: This function expects an array of content. Not just a content\n * object. The reason for this \"weirdness\" is that inserting several elements\n * is very efficient when it is done as a single operation.\n *\n * @example\n * // Insert character 'a' at position 0\n * yarray.insert(0, ['a'])\n * // Insert numbers 1, 2 at position 1\n * yarray.insert(1, [1, 2])\n *\n * @param {number} index The index to insert content at.\n * @param {Array<T>} content The array of content\n */\n insert (index, content) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeListInsertGenerics(transaction, this, index, /** @type {any} */ (content))\n })\n } else {\n /** @type {Array<any>} */ (this._prelimContent).splice(index, 0, ...content)\n }\n }\n\n /**\n * Appends content to this YArray.\n *\n * @param {Array<T>} content Array of content to append.\n *\n * @todo Use the following implementation in all types.\n */\n push (content) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeListPushGenerics(transaction, this, /** @type {any} */ (content))\n })\n } else {\n /** @type {Array<any>} */ (this._prelimContent).push(...content)\n }\n }\n\n /**\n * Prepends content to this YArray.\n *\n * @param {Array<T>} content Array of content to prepend.\n */\n unshift (content) {\n this.insert(0, content)\n }\n\n /**\n * Deletes elements starting from an index.\n *\n * @param {number} index Index at which to start deleting elements\n * @param {number} length The number of elements to remove. Defaults to 1.\n */\n delete (index, length = 1) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeListDelete(transaction, this, index, length)\n })\n } else {\n /** @type {Array<any>} */ (this._prelimContent).splice(index, length)\n }\n }\n\n /**\n * Returns the i-th element from a YArray.\n *\n * @param {number} index The index of the element to return from the YArray\n * @return {T}\n */\n get (index) {\n return typeListGet(this, index)\n }\n\n /**\n * Transforms this YArray to a JavaScript Array.\n *\n * @return {Array<T>}\n */\n toArray () {\n return typeListToArray(this)\n }\n\n /**\n * Returns a portion of this YArray into a JavaScript Array selected\n * from start to end (end not included).\n *\n * @param {number} [start]\n * @param {number} [end]\n * @return {Array<T>}\n */\n slice (start = 0, end = this.length) {\n return typeListSlice(this, start, end)\n }\n\n /**\n * Transforms this Shared Type to a JSON object.\n *\n * @return {Array<any>}\n */\n toJSON () {\n return this.map(c => c instanceof AbstractType ? c.toJSON() : c)\n }\n\n /**\n * Returns an Array with the result of calling a provided function on every\n * element of this YArray.\n *\n * @template M\n * @param {function(T,number,YArray<T>):M} f Function that produces an element of the new Array\n * @return {Array<M>} A new array with each element being the result of the\n * callback function\n */\n map (f) {\n return typeListMap(this, /** @type {any} */ (f))\n }\n\n /**\n * Executes a provided function once on every element of this YArray.\n *\n * @param {function(T,number,YArray<T>):void} f A function to execute on every element of this YArray.\n */\n forEach (f) {\n typeListForEach(this, f)\n }\n\n /**\n * @return {IterableIterator<T>}\n */\n [Symbol.iterator] () {\n return typeListCreateIterator(this)\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n */\n _write (encoder) {\n encoder.writeTypeRef(YArrayRefID)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder\n *\n * @private\n * @function\n */\nexport const readYArray = _decoder => new YArray()\n","/**\n * @module YMap\n */\n\nimport {\n YEvent,\n AbstractType,\n typeMapDelete,\n typeMapSet,\n typeMapGet,\n typeMapHas,\n createMapIterator,\n YMapRefID,\n callTypeObservers,\n transact,\n warnPrematureAccess,\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item // eslint-disable-line\n} from '../internals.js'\n\nimport * as iterator from 'lib0/iterator'\n\n/**\n * @template T\n * @extends YEvent<YMap<T>>\n * Event that describes the changes on a YMap.\n */\nexport class YMapEvent extends YEvent {\n /**\n * @param {YMap<T>} ymap The YArray that changed.\n * @param {Transaction} transaction\n * @param {Set<any>} subs The keys that changed.\n */\n constructor (ymap, transaction, subs) {\n super(ymap, transaction)\n this.keysChanged = subs\n }\n}\n\n/**\n * @template MapType\n * A shared Map implementation.\n *\n * @extends AbstractType<YMapEvent<MapType>>\n * @implements {Iterable<[string, MapType]>}\n */\nexport class YMap extends AbstractType {\n /**\n *\n * @param {Iterable<readonly [string, any]>=} entries - an optional iterable to initialize the YMap\n */\n constructor (entries) {\n super()\n /**\n * @type {Map<string,any>?}\n * @private\n */\n this._prelimContent = null\n\n if (entries === undefined) {\n this._prelimContent = new Map()\n } else {\n this._prelimContent = new Map(entries)\n }\n }\n\n /**\n * Integrate this type into the Yjs instance.\n *\n * * Save this struct in the os\n * * This type is sent to other client\n * * Observer functions are fired\n *\n * @param {Doc} y The Yjs instance\n * @param {Item} item\n */\n _integrate (y, item) {\n super._integrate(y, item)\n ;/** @type {Map<string, any>} */ (this._prelimContent).forEach((value, key) => {\n this.set(key, value)\n })\n this._prelimContent = null\n }\n\n /**\n * @return {YMap<MapType>}\n */\n _copy () {\n return new YMap()\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YMap<MapType>}\n */\n clone () {\n /**\n * @type {YMap<MapType>}\n */\n const map = new YMap()\n this.forEach((value, key) => {\n map.set(key, value instanceof AbstractType ? /** @type {typeof value} */ (value.clone()) : value)\n })\n return map\n }\n\n /**\n * Creates YMapEvent and calls observers.\n *\n * @param {Transaction} transaction\n * @param {Set<null|string>} parentSubs Keys changed on this type. `null` if list was modified.\n */\n _callObserver (transaction, parentSubs) {\n callTypeObservers(this, transaction, new YMapEvent(this, transaction, parentSubs))\n }\n\n /**\n * Transforms this Shared Type to a JSON object.\n *\n * @return {Object<string,any>}\n */\n toJSON () {\n this.doc ?? warnPrematureAccess()\n /**\n * @type {Object<string,MapType>}\n */\n const map = {}\n this._map.forEach((item, key) => {\n if (!item.deleted) {\n const v = item.content.getContent()[item.length - 1]\n map[key] = v instanceof AbstractType ? v.toJSON() : v\n }\n })\n return map\n }\n\n /**\n * Returns the size of the YMap (count of key/value pairs)\n *\n * @return {number}\n */\n get size () {\n return [...createMapIterator(this)].length\n }\n\n /**\n * Returns the keys for each element in the YMap Type.\n *\n * @return {IterableIterator<string>}\n */\n keys () {\n return iterator.iteratorMap(createMapIterator(this), /** @param {any} v */ v => v[0])\n }\n\n /**\n * Returns the values for each element in the YMap Type.\n *\n * @return {IterableIterator<MapType>}\n */\n values () {\n return iterator.iteratorMap(createMapIterator(this), /** @param {any} v */ v => v[1].content.getContent()[v[1].length - 1])\n }\n\n /**\n * Returns an Iterator of [key, value] pairs\n *\n * @return {IterableIterator<[string, MapType]>}\n */\n entries () {\n return iterator.iteratorMap(createMapIterator(this), /** @param {any} v */ v => /** @type {any} */ ([v[0], v[1].content.getContent()[v[1].length - 1]]))\n }\n\n /**\n * Executes a provided function on once on every key-value pair.\n *\n * @param {function(MapType,string,YMap<MapType>):void} f A function to execute on every element of this YArray.\n */\n forEach (f) {\n this.doc ?? warnPrematureAccess()\n this._map.forEach((item, key) => {\n if (!item.deleted) {\n f(item.content.getContent()[item.length - 1], key, this)\n }\n })\n }\n\n /**\n * Returns an Iterator of [key, value] pairs\n *\n * @return {IterableIterator<[string, MapType]>}\n */\n [Symbol.iterator] () {\n return this.entries()\n }\n\n /**\n * Remove a specified element from this YMap.\n *\n * @param {string} key The key of the element to remove.\n */\n delete (key) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeMapDelete(transaction, this, key)\n })\n } else {\n /** @type {Map<string, any>} */ (this._prelimContent).delete(key)\n }\n }\n\n /**\n * Adds or updates an element with a specified key and value.\n * @template {MapType} VAL\n *\n * @param {string} key The key of the element to add to this YMap\n * @param {VAL} value The value of the element to add\n * @return {VAL}\n */\n set (key, value) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeMapSet(transaction, this, key, /** @type {any} */ (value))\n })\n } else {\n /** @type {Map<string, any>} */ (this._prelimContent).set(key, value)\n }\n return value\n }\n\n /**\n * Returns a specified element from this YMap.\n *\n * @param {string} key\n * @return {MapType|undefined}\n */\n get (key) {\n return /** @type {any} */ (typeMapGet(this, key))\n }\n\n /**\n * Returns a boolean indicating whether the specified key exists or not.\n *\n * @param {string} key The key to test.\n * @return {boolean}\n */\n has (key) {\n return typeMapHas(this, key)\n }\n\n /**\n * Removes all elements from this YMap.\n */\n clear () {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n this.forEach(function (_value, key, map) {\n typeMapDelete(transaction, map, key)\n })\n })\n } else {\n /** @type {Map<string, any>} */ (this._prelimContent).clear()\n }\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n */\n _write (encoder) {\n encoder.writeTypeRef(YMapRefID)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder\n *\n * @private\n * @function\n */\nexport const readYMap = _decoder => new YMap()\n","/**\n * @module YText\n */\n\nimport {\n YEvent,\n AbstractType,\n getItemCleanStart,\n getState,\n isVisible,\n createID,\n YTextRefID,\n callTypeObservers,\n transact,\n ContentEmbed,\n GC,\n ContentFormat,\n ContentString,\n splitSnapshotAffectedStructs,\n iterateDeletedStructs,\n iterateStructs,\n findMarker,\n typeMapDelete,\n typeMapSet,\n typeMapGet,\n typeMapGetAll,\n updateMarkerChanges,\n ContentType,\n warnPrematureAccess,\n ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ID, Doc, Item, Snapshot, Transaction // eslint-disable-line\n} from '../internals.js'\n\nimport * as object from 'lib0/object'\nimport * as map from 'lib0/map'\nimport * as error from 'lib0/error'\n\n/**\n * @param {any} a\n * @param {any} b\n * @return {boolean}\n */\nconst equalAttrs = (a, b) => a === b || (typeof a === 'object' && typeof b === 'object' && a && b && object.equalFlat(a, b))\n\nexport class ItemTextListPosition {\n /**\n * @param {Item|null} left\n * @param {Item|null} right\n * @param {number} index\n * @param {Map<string,any>} currentAttributes\n */\n constructor (left, right, index, currentAttributes) {\n this.left = left\n this.right = right\n this.index = index\n this.currentAttributes = currentAttributes\n }\n\n /**\n * Only call this if you know that this.right is defined\n */\n forward () {\n if (this.right === null) {\n error.unexpectedCase()\n }\n switch (this.right.content.constructor) {\n case ContentFormat:\n if (!this.right.deleted) {\n updateCurrentAttributes(this.currentAttributes, /** @type {ContentFormat} */ (this.right.content))\n }\n break\n default:\n if (!this.right.deleted) {\n this.index += this.right.length\n }\n break\n }\n this.left = this.right\n this.right = this.right.right\n }\n}\n\n/**\n * @param {Transaction} transaction\n * @param {ItemTextListPosition} pos\n * @param {number} count steps to move forward\n * @return {ItemTextListPosition}\n *\n * @private\n * @function\n */\nconst findNextPosition = (transaction, pos, count) => {\n while (pos.right !== null && count > 0) {\n switch (pos.right.content.constructor) {\n case ContentFormat:\n if (!pos.right.deleted) {\n updateCurrentAttributes(pos.currentAttributes, /** @type {ContentFormat} */ (pos.right.content))\n }\n break\n default:\n if (!pos.right.deleted) {\n if (count < pos.right.length) {\n // split right\n getItemCleanStart(transaction, createID(pos.right.id.client, pos.right.id.clock + count))\n }\n pos.index += pos.right.length\n count -= pos.right.length\n }\n break\n }\n pos.left = pos.right\n pos.right = pos.right.right\n // pos.forward() - we don't forward because that would halve the performance because we already do the checks above\n }\n return pos\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {number} index\n * @param {boolean} useSearchMarker\n * @return {ItemTextListPosition}\n *\n * @private\n * @function\n */\nconst findPosition = (transaction, parent, index, useSearchMarker) => {\n const currentAttributes = new Map()\n const marker = useSearchMarker ? findMarker(parent, index) : null\n if (marker) {\n const pos = new ItemTextListPosition(marker.p.left, marker.p, marker.index, currentAttributes)\n return findNextPosition(transaction, pos, index - marker.index)\n } else {\n const pos = new ItemTextListPosition(null, parent._start, 0, currentAttributes)\n return findNextPosition(transaction, pos, index)\n }\n}\n\n/**\n * Negate applied formats\n *\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {ItemTextListPosition} currPos\n * @param {Map<string,any>} negatedAttributes\n *\n * @private\n * @function\n */\nconst insertNegatedAttributes = (transaction, parent, currPos, negatedAttributes) => {\n // check if we really need to remove attributes\n while (\n currPos.right !== null && (\n currPos.right.deleted === true || (\n currPos.right.content.constructor === ContentFormat &&\n equalAttrs(negatedAttributes.get(/** @type {ContentFormat} */ (currPos.right.content).key), /** @type {ContentFormat} */ (currPos.right.content).value)\n )\n )\n ) {\n if (!currPos.right.deleted) {\n negatedAttributes.delete(/** @type {ContentFormat} */ (currPos.right.content).key)\n }\n currPos.forward()\n }\n const doc = transaction.doc\n const ownClientId = doc.clientID\n negatedAttributes.forEach((val, key) => {\n const left = currPos.left\n const right = currPos.right\n const nextFormat = new Item(createID(ownClientId, getState(doc.store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentFormat(key, val))\n nextFormat.integrate(transaction, 0)\n currPos.right = nextFormat\n currPos.forward()\n })\n}\n\n/**\n * @param {Map<string,any>} currentAttributes\n * @param {ContentFormat} format\n *\n * @private\n * @function\n */\nconst updateCurrentAttributes = (currentAttributes, format) => {\n const { key, value } = format\n if (value === null) {\n currentAttributes.delete(key)\n } else {\n currentAttributes.set(key, value)\n }\n}\n\n/**\n * @param {ItemTextListPosition} currPos\n * @param {Object<string,any>} attributes\n *\n * @private\n * @function\n */\nconst minimizeAttributeChanges = (currPos, attributes) => {\n // go right while attributes[right.key] === right.value (or right is deleted)\n while (true) {\n if (currPos.right === null) {\n break\n } else if (currPos.right.deleted || (currPos.right.content.constructor === ContentFormat && equalAttrs(attributes[(/** @type {ContentFormat} */ (currPos.right.content)).key] ?? null, /** @type {ContentFormat} */ (currPos.right.content).value))) {\n //\n } else {\n break\n }\n currPos.forward()\n }\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {ItemTextListPosition} currPos\n * @param {Object<string,any>} attributes\n * @return {Map<string,any>}\n *\n * @private\n * @function\n **/\nconst insertAttributes = (transaction, parent, currPos, attributes) => {\n const doc = transaction.doc\n const ownClientId = doc.clientID\n const negatedAttributes = new Map()\n // insert format-start items\n for (const key in attributes) {\n const val = attributes[key]\n const currentVal = currPos.currentAttributes.get(key) ?? null\n if (!equalAttrs(currentVal, val)) {\n // save negated attribute (set null if currentVal undefined)\n negatedAttributes.set(key, currentVal)\n const { left, right } = currPos\n currPos.right = new Item(createID(ownClientId, getState(doc.store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, new ContentFormat(key, val))\n currPos.right.integrate(transaction, 0)\n currPos.forward()\n }\n }\n return negatedAttributes\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {ItemTextListPosition} currPos\n * @param {string|object|AbstractType<any>} text\n * @param {Object<string,any>} attributes\n *\n * @private\n * @function\n **/\nconst insertText = (transaction, parent, currPos, text, attributes) => {\n currPos.currentAttributes.forEach((_val, key) => {\n if (attributes[key] === undefined) {\n attributes[key] = null\n }\n })\n const doc = transaction.doc\n const ownClientId = doc.clientID\n minimizeAttributeChanges(currPos, attributes)\n const negatedAttributes = insertAttributes(transaction, parent, currPos, attributes)\n // insert content\n const content = text.constructor === String ? new ContentString(/** @type {string} */ (text)) : (text instanceof AbstractType ? new ContentType(text) : new ContentEmbed(text))\n let { left, right, index } = currPos\n if (parent._searchMarker) {\n updateMarkerChanges(parent._searchMarker, currPos.index, content.getLength())\n }\n right = new Item(createID(ownClientId, getState(doc.store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, content)\n right.integrate(transaction, 0)\n currPos.right = right\n currPos.index = index\n currPos.forward()\n insertNegatedAttributes(transaction, parent, currPos, negatedAttributes)\n}\n\n/**\n * @param {Transaction} transaction\n * @param {AbstractType<any>} parent\n * @param {ItemTextListPosition} currPos\n * @param {number} length\n * @param {Object<string,any>} attributes\n *\n * @private\n * @function\n */\nconst formatText = (transaction, parent, currPos, length, attributes) => {\n const doc = transaction.doc\n const ownClientId = doc.clientID\n minimizeAttributeChanges(currPos, attributes)\n const negatedAttributes = insertAttributes(transaction, parent, currPos, attributes)\n // iterate until first non-format or null is found\n // delete all formats with attributes[format.key] != null\n // also check the attributes after the first non-format as we do not want to insert redundant negated attributes there\n // eslint-disable-next-line no-labels\n iterationLoop: while (\n currPos.right !== null &&\n (length > 0 ||\n (\n negatedAttributes.size > 0 &&\n (currPos.right.deleted || currPos.right.content.constructor === ContentFormat)\n )\n )\n ) {\n if (!currPos.right.deleted) {\n switch (currPos.right.content.constructor) {\n case ContentFormat: {\n const { key, value } = /** @type {ContentFormat} */ (currPos.right.content)\n const attr = attributes[key]\n if (attr !== undefined) {\n if (equalAttrs(attr, value)) {\n negatedAttributes.delete(key)\n } else {\n if (length === 0) {\n // no need to further extend negatedAttributes\n // eslint-disable-next-line no-labels\n break iterationLoop\n }\n negatedAttributes.set(key, value)\n }\n currPos.right.delete(transaction)\n } else {\n currPos.currentAttributes.set(key, value)\n }\n break\n }\n default:\n if (length < currPos.right.length) {\n getItemCleanStart(transaction, createID(currPos.right.id.client, currPos.right.id.clock + length))\n }\n length -= currPos.right.length\n break\n }\n }\n currPos.forward()\n }\n // Quill just assumes that the editor starts with a newline and that it always\n // ends with a newline. We only insert that newline when a new newline is\n // inserted - i.e when length is bigger than type.length\n if (length > 0) {\n let newlines = ''\n for (; length > 0; length--) {\n newlines += '\\n'\n }\n currPos.right = new Item(createID(ownClientId, getState(doc.store, ownClientId)), currPos.left, currPos.left && currPos.left.lastId, currPos.right, currPos.right && currPos.right.id, parent, null, new ContentString(newlines))\n currPos.right.integrate(transaction, 0)\n currPos.forward()\n }\n insertNegatedAttributes(transaction, parent, currPos, negatedAttributes)\n}\n\n/**\n * Call this function after string content has been deleted in order to\n * clean up formatting Items.\n *\n * @param {Transaction} transaction\n * @param {Item} start\n * @param {Item|null} curr exclusive end, automatically iterates to the next Content Item\n * @param {Map<string,any>} startAttributes\n * @param {Map<string,any>} currAttributes\n * @return {number} The amount of formatting Items deleted.\n *\n * @function\n */\nconst cleanupFormattingGap = (transaction, start, curr, startAttributes, currAttributes) => {\n /**\n * @type {Item|null}\n */\n let end = start\n /**\n * @type {Map<string,ContentFormat>}\n */\n const endFormats = map.create()\n while (end && (!end.countable || end.deleted)) {\n if (!end.deleted && end.content.constructor === ContentFormat) {\n const cf = /** @type {ContentFormat} */ (end.content)\n endFormats.set(cf.key, cf)\n }\n end = end.right\n }\n let cleanups = 0\n let reachedCurr = false\n while (start !== end) {\n if (curr === start) {\n reachedCurr = true\n }\n if (!start.deleted) {\n const content = start.content\n switch (content.constructor) {\n case ContentFormat: {\n const { key, value } = /** @type {ContentFormat} */ (content)\n const startAttrValue = startAttributes.get(key) ?? null\n if (endFormats.get(key) !== content || startAttrValue === value) {\n // Either this format is overwritten or it is not necessary because the attribute already existed.\n start.delete(transaction)\n cleanups++\n if (!reachedCurr && (currAttributes.get(key) ?? null) === value && startAttrValue !== value) {\n if (startAttrValue === null) {\n currAttributes.delete(key)\n } else {\n currAttributes.set(key, startAttrValue)\n }\n }\n }\n if (!reachedCurr && !start.deleted) {\n updateCurrentAttributes(currAttributes, /** @type {ContentFormat} */ (content))\n }\n break\n }\n }\n }\n start = /** @type {Item} */ (start.right)\n }\n return cleanups\n}\n\n/**\n * @param {Transaction} transaction\n * @param {Item | null} item\n */\nconst cleanupContextlessFormattingGap = (transaction, item) => {\n // iterate until item.right is null or content\n while (item && item.right && (item.right.deleted || !item.right.countable)) {\n item = item.right\n }\n const attrs = new Set()\n // iterate back until a content item is found\n while (item && (item.deleted || !item.countable)) {\n if (!item.deleted && item.content.constructor === ContentFormat) {\n const key = /** @type {ContentFormat} */ (item.content).key\n if (attrs.has(key)) {\n item.delete(transaction)\n } else {\n attrs.add(key)\n }\n }\n item = item.left\n }\n}\n\n/**\n * This function is experimental and subject to change / be removed.\n *\n * Ideally, we don't need this function at all. Formatting attributes should be cleaned up\n * automatically after each change. This function iterates twice over the complete YText type\n * and removes unnecessary formatting attributes. This is also helpful for testing.\n *\n * This function won't be exported anymore as soon as there is confidence that the YText type works as intended.\n *\n * @param {YText} type\n * @return {number} How many formatting attributes have been cleaned up.\n */\nexport const cleanupYTextFormatting = type => {\n let res = 0\n transact(/** @type {Doc} */ (type.doc), transaction => {\n let start = /** @type {Item} */ (type._start)\n let end = type._start\n let startAttributes = map.create()\n const currentAttributes = map.copy(startAttributes)\n while (end) {\n if (end.deleted === false) {\n switch (end.content.constructor) {\n case ContentFormat:\n updateCurrentAttributes(currentAttributes, /** @type {ContentFormat} */ (end.content))\n break\n default:\n res += cleanupFormattingGap(transaction, start, end, startAttributes, currentAttributes)\n startAttributes = map.copy(currentAttributes)\n start = end\n break\n }\n }\n end = end.right\n }\n })\n return res\n}\n\n/**\n * This will be called by the transaction once the event handlers are called to potentially cleanup\n * formatting attributes.\n *\n * @param {Transaction} transaction\n */\nexport const cleanupYTextAfterTransaction = transaction => {\n /**\n * @type {Set<YText>}\n */\n const needFullCleanup = new Set()\n // check if another formatting item was inserted\n const doc = transaction.doc\n for (const [client, afterClock] of transaction.afterState.entries()) {\n const clock = transaction.beforeState.get(client) || 0\n if (afterClock === clock) {\n continue\n }\n iterateStructs(transaction, /** @type {Array<Item|GC>} */ (doc.store.clients.get(client)), clock, afterClock, item => {\n if (\n !item.deleted && /** @type {Item} */ (item).content.constructor === ContentFormat && item.constructor !== GC\n ) {\n needFullCleanup.add(/** @type {any} */ (item).parent)\n }\n })\n }\n // cleanup in a new transaction\n transact(doc, (t) => {\n iterateDeletedStructs(transaction, transaction.deleteSet, item => {\n if (item instanceof GC || !(/** @type {YText} */ (item.parent)._hasFormatting) || needFullCleanup.has(/** @type {YText} */ (item.parent))) {\n return\n }\n const parent = /** @type {YText} */ (item.parent)\n if (item.content.constructor === ContentFormat) {\n needFullCleanup.add(parent)\n } else {\n // If no formatting attribute was inserted or deleted, we can make due with contextless\n // formatting cleanups.\n // Contextless: it is not necessary to compute currentAttributes for the affected position.\n cleanupContextlessFormattingGap(t, item)\n }\n })\n // If a formatting item was inserted, we simply clean the whole type.\n // We need to compute currentAttributes for the current position anyway.\n for (const yText of needFullCleanup) {\n cleanupYTextFormatting(yText)\n }\n })\n}\n\n/**\n * @param {Transaction} transaction\n * @param {ItemTextListPosition} currPos\n * @param {number} length\n * @return {ItemTextListPosition}\n *\n * @private\n * @function\n */\nconst deleteText = (transaction, currPos, length) => {\n const startLength = length\n const startAttrs = map.copy(currPos.currentAttributes)\n const start = currPos.right\n while (length > 0 && currPos.right !== null) {\n if (currPos.right.deleted === false) {\n switch (currPos.right.content.constructor) {\n case ContentType:\n case ContentEmbed:\n case ContentString:\n if (length < currPos.right.length) {\n getItemCleanStart(transaction, createID(currPos.right.id.client, currPos.right.id.clock + length))\n }\n length -= currPos.right.length\n currPos.right.delete(transaction)\n break\n }\n }\n currPos.forward()\n }\n if (start) {\n cleanupFormattingGap(transaction, start, currPos.right, startAttrs, currPos.currentAttributes)\n }\n const parent = /** @type {AbstractType<any>} */ (/** @type {Item} */ (currPos.left || currPos.right).parent)\n if (parent._searchMarker) {\n updateMarkerChanges(parent._searchMarker, currPos.index, -startLength + length)\n }\n return currPos\n}\n\n/**\n * The Quill Delta format represents changes on a text document with\n * formatting information. For more information visit {@link https://quilljs.com/docs/delta/|Quill Delta}\n *\n * @example\n * {\n * ops: [\n * { insert: 'Gandalf', attributes: { bold: true } },\n * { insert: ' the ' },\n * { insert: 'Grey', attributes: { color: '#cccccc' } }\n * ]\n * }\n *\n */\n\n/**\n * Attributes that can be assigned to a selection of text.\n *\n * @example\n * {\n * bold: true,\n * font-size: '40px'\n * }\n *\n * @typedef {Object} TextAttributes\n */\n\n/**\n * @extends YEvent<YText>\n * Event that describes the changes on a YText type.\n */\nexport class YTextEvent extends YEvent {\n /**\n * @param {YText} ytext\n * @param {Transaction} transaction\n * @param {Set<any>} subs The keys that changed\n */\n constructor (ytext, transaction, subs) {\n super(ytext, transaction)\n /**\n * Whether the children changed.\n * @type {Boolean}\n * @private\n */\n this.childListChanged = false\n /**\n * Set of all changed attributes.\n * @type {Set<string>}\n */\n this.keysChanged = new Set()\n subs.forEach((sub) => {\n if (sub === null) {\n this.childListChanged = true\n } else {\n this.keysChanged.add(sub)\n }\n })\n }\n\n /**\n * @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert?:Array<any>|string, delete?:number, retain?:number}>}}\n */\n get changes () {\n if (this._changes === null) {\n /**\n * @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert?:Array<any>|string|AbstractType<any>|object, delete?:number, retain?:number}>}}\n */\n const changes = {\n keys: this.keys,\n delta: this.delta,\n added: new Set(),\n deleted: new Set()\n }\n this._changes = changes\n }\n return /** @type {any} */ (this._changes)\n }\n\n /**\n * Compute the changes in the delta format.\n * A {@link https://quilljs.com/docs/delta/|Quill Delta}) that represents the changes on the document.\n *\n * @type {Array<{insert?:string|object|AbstractType<any>, delete?:number, retain?:number, attributes?: Object<string,any>}>}\n *\n * @public\n */\n get delta () {\n if (this._delta === null) {\n const y = /** @type {Doc} */ (this.target.doc)\n /**\n * @type {Array<{insert?:string|object|AbstractType<any>, delete?:number, retain?:number, attributes?: Object<string,any>}>}\n */\n const delta = []\n transact(y, transaction => {\n const currentAttributes = new Map() // saves all current attributes for insert\n const oldAttributes = new Map()\n let item = this.target._start\n /**\n * @type {string?}\n */\n let action = null\n /**\n * @type {Object<string,any>}\n */\n const attributes = {} // counts added or removed new attributes for retain\n /**\n * @type {string|object}\n */\n let insert = ''\n let retain = 0\n let deleteLen = 0\n const addOp = () => {\n if (action !== null) {\n /**\n * @type {any}\n */\n let op = null\n switch (action) {\n case 'delete':\n if (deleteLen > 0) {\n op = { delete: deleteLen }\n }\n deleteLen = 0\n break\n case 'insert':\n if (typeof insert === 'object' || insert.length > 0) {\n op = { insert }\n if (currentAttributes.size > 0) {\n op.attributes = {}\n currentAttributes.forEach((value, key) => {\n if (value !== null) {\n op.attributes[key] = value\n }\n })\n }\n }\n insert = ''\n break\n case 'retain':\n if (retain > 0) {\n op = { retain }\n if (!object.isEmpty(attributes)) {\n op.attributes = object.assign({}, attributes)\n }\n }\n retain = 0\n break\n }\n if (op) delta.push(op)\n action = null\n }\n }\n while (item !== null) {\n switch (item.content.constructor) {\n case ContentType:\n case ContentEmbed:\n if (this.adds(item)) {\n if (!this.deletes(item)) {\n addOp()\n action = 'insert'\n insert = item.content.getContent()[0]\n addOp()\n }\n } else if (this.deletes(item)) {\n if (action !== 'delete') {\n addOp()\n action = 'delete'\n }\n deleteLen += 1\n } else if (!item.deleted) {\n if (action !== 'retain') {\n addOp()\n action = 'retain'\n }\n retain += 1\n }\n break\n case ContentString:\n if (this.adds(item)) {\n if (!this.deletes(item)) {\n if (action !== 'insert') {\n addOp()\n action = 'insert'\n }\n insert += /** @type {ContentString} */ (item.content).str\n }\n } else if (this.deletes(item)) {\n if (action !== 'delete') {\n addOp()\n action = 'delete'\n }\n deleteLen += item.length\n } else if (!item.deleted) {\n if (action !== 'retain') {\n addOp()\n action = 'retain'\n }\n retain += item.length\n }\n break\n case ContentFormat: {\n const { key, value } = /** @type {ContentFormat} */ (item.content)\n if (this.adds(item)) {\n if (!this.deletes(item)) {\n const curVal = currentAttributes.get(key) ?? null\n if (!equalAttrs(curVal, value)) {\n if (action === 'retain') {\n addOp()\n }\n if (equalAttrs(value, (oldAttributes.get(key) ?? null))) {\n delete attributes[key]\n } else {\n attributes[key] = value\n }\n } else if (value !== null) {\n item.delete(transaction)\n }\n }\n } else if (this.deletes(item)) {\n oldAttributes.set(key, value)\n const curVal = currentAttributes.get(key) ?? null\n if (!equalAttrs(curVal, value)) {\n if (action === 'retain') {\n addOp()\n }\n attributes[key] = curVal\n }\n } else if (!item.deleted) {\n oldAttributes.set(key, value)\n const attr = attributes[key]\n if (attr !== undefined) {\n if (!equalAttrs(attr, value)) {\n if (action === 'retain') {\n addOp()\n }\n if (value === null) {\n delete attributes[key]\n } else {\n attributes[key] = value\n }\n } else if (attr !== null) { // this will be cleaned up automatically by the contextless cleanup function\n item.delete(transaction)\n }\n }\n }\n if (!item.deleted) {\n if (action === 'insert') {\n addOp()\n }\n updateCurrentAttributes(currentAttributes, /** @type {ContentFormat} */ (item.content))\n }\n break\n }\n }\n item = item.right\n }\n addOp()\n while (delta.length > 0) {\n const lastOp = delta[delta.length - 1]\n if (lastOp.retain !== undefined && lastOp.attributes === undefined) {\n // retain delta's if they don't assign attributes\n delta.pop()\n } else {\n break\n }\n }\n })\n this._delta = delta\n }\n return /** @type {any} */ (this._delta)\n }\n}\n\n/**\n * Type that represents text with formatting information.\n *\n * This type replaces y-richtext as this implementation is able to handle\n * block formats (format information on a paragraph), embeds (complex elements\n * like pictures and videos), and text formats (**bold**, *italic*).\n *\n * @extends AbstractType<YTextEvent>\n */\nexport class YText extends AbstractType {\n /**\n * @param {String} [string] The initial value of the YText.\n */\n constructor (string) {\n super()\n /**\n * Array of pending operations on this type\n * @type {Array<function():void>?}\n */\n this._pending = string !== undefined ? [() => this.insert(0, string)] : []\n /**\n * @type {Array<ArraySearchMarker>|null}\n */\n this._searchMarker = []\n /**\n * Whether this YText contains formatting attributes.\n * This flag is updated when a formatting item is integrated (see ContentFormat.integrate)\n */\n this._hasFormatting = false\n }\n\n /**\n * Number of characters of this text type.\n *\n * @type {number}\n */\n get length () {\n this.doc ?? warnPrematureAccess()\n return this._length\n }\n\n /**\n * @param {Doc} y\n * @param {Item} item\n */\n _integrate (y, item) {\n super._integrate(y, item)\n try {\n /** @type {Array<function>} */ (this._pending).forEach(f => f())\n } catch (e) {\n console.error(e)\n }\n this._pending = null\n }\n\n _copy () {\n return new YText()\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YText}\n */\n clone () {\n const text = new YText()\n text.applyDelta(this.toDelta())\n return text\n }\n\n /**\n * Creates YTextEvent and calls observers.\n *\n * @param {Transaction} transaction\n * @param {Set<null|string>} parentSubs Keys changed on this type. `null` if list was modified.\n */\n _callObserver (transaction, parentSubs) {\n super._callObserver(transaction, parentSubs)\n const event = new YTextEvent(this, transaction, parentSubs)\n callTypeObservers(this, transaction, event)\n // If a remote change happened, we try to cleanup potential formatting duplicates.\n if (!transaction.local && this._hasFormatting) {\n transaction._needFormattingCleanup = true\n }\n }\n\n /**\n * Returns the unformatted string representation of this YText type.\n *\n * @public\n */\n toString () {\n this.doc ?? warnPrematureAccess()\n let str = ''\n /**\n * @type {Item|null}\n */\n let n = this._start\n while (n !== null) {\n if (!n.deleted && n.countable && n.content.constructor === ContentString) {\n str += /** @type {ContentString} */ (n.content).str\n }\n n = n.right\n }\n return str\n }\n\n /**\n * Returns the unformatted string representation of this YText type.\n *\n * @return {string}\n * @public\n */\n toJSON () {\n return this.toString()\n }\n\n /**\n * Apply a {@link Delta} on this shared YText type.\n *\n * @param {Array<any>} delta The changes to apply on this element.\n * @param {object} opts\n * @param {boolean} [opts.sanitize] Sanitize input delta. Removes ending newlines if set to true.\n *\n *\n * @public\n */\n applyDelta (delta, { sanitize = true } = {}) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n const currPos = new ItemTextListPosition(null, this._start, 0, new Map())\n for (let i = 0; i < delta.length; i++) {\n const op = delta[i]\n if (op.insert !== undefined) {\n // Quill assumes that the content starts with an empty paragraph.\n // Yjs/Y.Text assumes that it starts empty. We always hide that\n // there is a newline at the end of the content.\n // If we omit this step, clients will see a different number of\n // paragraphs, but nothing bad will happen.\n const ins = (!sanitize && typeof op.insert === 'string' && i === delta.length - 1 && currPos.right === null && op.insert.slice(-1) === '\\n') ? op.insert.slice(0, -1) : op.insert\n if (typeof ins !== 'string' || ins.length > 0) {\n insertText(transaction, this, currPos, ins, op.attributes || {})\n }\n } else if (op.retain !== undefined) {\n formatText(transaction, this, currPos, op.retain, op.attributes || {})\n } else if (op.delete !== undefined) {\n deleteText(transaction, currPos, op.delete)\n }\n }\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.applyDelta(delta))\n }\n }\n\n /**\n * Returns the Delta representation of this YText type.\n *\n * @param {Snapshot} [snapshot]\n * @param {Snapshot} [prevSnapshot]\n * @param {function('removed' | 'added', ID):any} [computeYChange]\n * @return {any} The Delta representation of this type.\n *\n * @public\n */\n toDelta (snapshot, prevSnapshot, computeYChange) {\n this.doc ?? warnPrematureAccess()\n /**\n * @type{Array<any>}\n */\n const ops = []\n const currentAttributes = new Map()\n const doc = /** @type {Doc} */ (this.doc)\n let str = ''\n let n = this._start\n function packStr () {\n if (str.length > 0) {\n // pack str with attributes to ops\n /**\n * @type {Object<string,any>}\n */\n const attributes = {}\n let addAttributes = false\n currentAttributes.forEach((value, key) => {\n addAttributes = true\n attributes[key] = value\n })\n /**\n * @type {Object<string,any>}\n */\n const op = { insert: str }\n if (addAttributes) {\n op.attributes = attributes\n }\n ops.push(op)\n str = ''\n }\n }\n const computeDelta = () => {\n while (n !== null) {\n if (isVisible(n, snapshot) || (prevSnapshot !== undefined && isVisible(n, prevSnapshot))) {\n switch (n.content.constructor) {\n case ContentString: {\n const cur = currentAttributes.get('ychange')\n if (snapshot !== undefined && !isVisible(n, snapshot)) {\n if (cur === undefined || cur.user !== n.id.client || cur.type !== 'removed') {\n packStr()\n currentAttributes.set('ychange', computeYChange ? computeYChange('removed', n.id) : { type: 'removed' })\n }\n } else if (prevSnapshot !== undefined && !isVisible(n, prevSnapshot)) {\n if (cur === undefined || cur.user !== n.id.client || cur.type !== 'added') {\n packStr()\n currentAttributes.set('ychange', computeYChange ? computeYChange('added', n.id) : { type: 'added' })\n }\n } else if (cur !== undefined) {\n packStr()\n currentAttributes.delete('ychange')\n }\n str += /** @type {ContentString} */ (n.content).str\n break\n }\n case ContentType:\n case ContentEmbed: {\n packStr()\n /**\n * @type {Object<string,any>}\n */\n const op = {\n insert: n.content.getContent()[0]\n }\n if (currentAttributes.size > 0) {\n const attrs = /** @type {Object<string,any>} */ ({})\n op.attributes = attrs\n currentAttributes.forEach((value, key) => {\n attrs[key] = value\n })\n }\n ops.push(op)\n break\n }\n case ContentFormat:\n if (isVisible(n, snapshot)) {\n packStr()\n updateCurrentAttributes(currentAttributes, /** @type {ContentFormat} */ (n.content))\n }\n break\n }\n }\n n = n.right\n }\n packStr()\n }\n if (snapshot || prevSnapshot) {\n // snapshots are merged again after the transaction, so we need to keep the\n // transaction alive until we are done\n transact(doc, transaction => {\n if (snapshot) {\n splitSnapshotAffectedStructs(transaction, snapshot)\n }\n if (prevSnapshot) {\n splitSnapshotAffectedStructs(transaction, prevSnapshot)\n }\n computeDelta()\n }, 'cleanup')\n } else {\n computeDelta()\n }\n return ops\n }\n\n /**\n * Insert text at a given index.\n *\n * @param {number} index The index at which to start inserting.\n * @param {String} text The text to insert at the specified position.\n * @param {TextAttributes} [attributes] Optionally define some formatting\n * information to apply on the inserted\n * Text.\n * @public\n */\n insert (index, text, attributes) {\n if (text.length <= 0) {\n return\n }\n const y = this.doc\n if (y !== null) {\n transact(y, transaction => {\n const pos = findPosition(transaction, this, index, !attributes)\n if (!attributes) {\n attributes = {}\n // @ts-ignore\n pos.currentAttributes.forEach((v, k) => { attributes[k] = v })\n }\n insertText(transaction, this, pos, text, attributes)\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.insert(index, text, attributes))\n }\n }\n\n /**\n * Inserts an embed at a index.\n *\n * @param {number} index The index to insert the embed at.\n * @param {Object | AbstractType<any>} embed The Object that represents the embed.\n * @param {TextAttributes} [attributes] Attribute information to apply on the\n * embed\n *\n * @public\n */\n insertEmbed (index, embed, attributes) {\n const y = this.doc\n if (y !== null) {\n transact(y, transaction => {\n const pos = findPosition(transaction, this, index, !attributes)\n insertText(transaction, this, pos, embed, attributes || {})\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.insertEmbed(index, embed, attributes || {}))\n }\n }\n\n /**\n * Deletes text starting from an index.\n *\n * @param {number} index Index at which to start deleting.\n * @param {number} length The number of characters to remove. Defaults to 1.\n *\n * @public\n */\n delete (index, length) {\n if (length === 0) {\n return\n }\n const y = this.doc\n if (y !== null) {\n transact(y, transaction => {\n deleteText(transaction, findPosition(transaction, this, index, true), length)\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.delete(index, length))\n }\n }\n\n /**\n * Assigns properties to a range of text.\n *\n * @param {number} index The position where to start formatting.\n * @param {number} length The amount of characters to assign properties to.\n * @param {TextAttributes} attributes Attribute information to apply on the\n * text.\n *\n * @public\n */\n format (index, length, attributes) {\n if (length === 0) {\n return\n }\n const y = this.doc\n if (y !== null) {\n transact(y, transaction => {\n const pos = findPosition(transaction, this, index, false)\n if (pos.right === null) {\n return\n }\n formatText(transaction, this, pos, length, attributes)\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.format(index, length, attributes))\n }\n }\n\n /**\n * Removes an attribute.\n *\n * @note Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.\n *\n * @param {String} attributeName The attribute name that is to be removed.\n *\n * @public\n */\n removeAttribute (attributeName) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeMapDelete(transaction, this, attributeName)\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.removeAttribute(attributeName))\n }\n }\n\n /**\n * Sets or updates an attribute.\n *\n * @note Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.\n *\n * @param {String} attributeName The attribute name that is to be set.\n * @param {any} attributeValue The attribute value that is to be set.\n *\n * @public\n */\n setAttribute (attributeName, attributeValue) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeMapSet(transaction, this, attributeName, attributeValue)\n })\n } else {\n /** @type {Array<function>} */ (this._pending).push(() => this.setAttribute(attributeName, attributeValue))\n }\n }\n\n /**\n * Returns an attribute value that belongs to the attribute name.\n *\n * @note Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.\n *\n * @param {String} attributeName The attribute name that identifies the\n * queried value.\n * @return {any} The queried attribute value.\n *\n * @public\n */\n getAttribute (attributeName) {\n return /** @type {any} */ (typeMapGet(this, attributeName))\n }\n\n /**\n * Returns all attribute name/value pairs in a JSON Object.\n *\n * @note Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.\n *\n * @return {Object<string, any>} A JSON Object that describes the attributes.\n *\n * @public\n */\n getAttributes () {\n return typeMapGetAll(this)\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n */\n _write (encoder) {\n encoder.writeTypeRef(YTextRefID)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder\n * @return {YText}\n *\n * @private\n * @function\n */\nexport const readYText = _decoder => new YText()\n","/**\n * @module YXml\n */\n\nimport {\n YXmlEvent,\n YXmlElement,\n AbstractType,\n typeListMap,\n typeListForEach,\n typeListInsertGenerics,\n typeListInsertGenericsAfter,\n typeListDelete,\n typeListToArray,\n YXmlFragmentRefID,\n callTypeObservers,\n transact,\n typeListGet,\n typeListSlice,\n warnPrematureAccess,\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, ContentType, Transaction, Item, YXmlText, YXmlHook // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\nimport * as array from 'lib0/array'\n\n/**\n * Define the elements to which a set of CSS queries apply.\n * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors|CSS_Selectors}\n *\n * @example\n * query = '.classSelector'\n * query = 'nodeSelector'\n * query = '#idSelector'\n *\n * @typedef {string} CSS_Selector\n */\n\n/**\n * Dom filter function.\n *\n * @callback domFilter\n * @param {string} nodeName The nodeName of the element\n * @param {Map} attributes The map of attributes.\n * @return {boolean} Whether to include the Dom node in the YXmlElement.\n */\n\n/**\n * Represents a subset of the nodes of a YXmlElement / YXmlFragment and a\n * position within them.\n *\n * Can be created with {@link YXmlFragment#createTreeWalker}\n *\n * @public\n * @implements {Iterable<YXmlElement|YXmlText|YXmlElement|YXmlHook>}\n */\nexport class YXmlTreeWalker {\n /**\n * @param {YXmlFragment | YXmlElement} root\n * @param {function(AbstractType<any>):boolean} [f]\n */\n constructor (root, f = () => true) {\n this._filter = f\n this._root = root\n /**\n * @type {Item}\n */\n this._currentNode = /** @type {Item} */ (root._start)\n this._firstCall = true\n root.doc ?? warnPrematureAccess()\n }\n\n [Symbol.iterator] () {\n return this\n }\n\n /**\n * Get the next node.\n *\n * @return {IteratorResult<YXmlElement|YXmlText|YXmlHook>} The next node.\n *\n * @public\n */\n next () {\n /**\n * @type {Item|null}\n */\n let n = this._currentNode\n let type = n && n.content && /** @type {any} */ (n.content).type\n if (n !== null && (!this._firstCall || n.deleted || !this._filter(type))) { // if first call, we check if we can use the first item\n do {\n type = /** @type {any} */ (n.content).type\n if (!n.deleted && (type.constructor === YXmlElement || type.constructor === YXmlFragment) && type._start !== null) {\n // walk down in the tree\n n = type._start\n } else {\n // walk right or up in the tree\n while (n !== null) {\n /**\n * @type {Item | null}\n */\n const nxt = n.next\n if (nxt !== null) {\n n = nxt\n break\n } else if (n.parent === this._root) {\n n = null\n } else {\n n = /** @type {AbstractType<any>} */ (n.parent)._item\n }\n }\n }\n } while (n !== null && (n.deleted || !this._filter(/** @type {ContentType} */ (n.content).type)))\n }\n this._firstCall = false\n if (n === null) {\n // @ts-ignore\n return { value: undefined, done: true }\n }\n this._currentNode = n\n return { value: /** @type {any} */ (n.content).type, done: false }\n }\n}\n\n/**\n * Represents a list of {@link YXmlElement}.and {@link YXmlText} types.\n * A YxmlFragment is similar to a {@link YXmlElement}, but it does not have a\n * nodeName and it does not have attributes. Though it can be bound to a DOM\n * element - in this case the attributes and the nodeName are not shared.\n *\n * @public\n * @extends AbstractType<YXmlEvent>\n */\nexport class YXmlFragment extends AbstractType {\n constructor () {\n super()\n /**\n * @type {Array<any>|null}\n */\n this._prelimContent = []\n }\n\n /**\n * @type {YXmlElement|YXmlText|null}\n */\n get firstChild () {\n const first = this._first\n return first ? first.content.getContent()[0] : null\n }\n\n /**\n * Integrate this type into the Yjs instance.\n *\n * * Save this struct in the os\n * * This type is sent to other client\n * * Observer functions are fired\n *\n * @param {Doc} y The Yjs instance\n * @param {Item} item\n */\n _integrate (y, item) {\n super._integrate(y, item)\n this.insert(0, /** @type {Array<any>} */ (this._prelimContent))\n this._prelimContent = null\n }\n\n _copy () {\n return new YXmlFragment()\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YXmlFragment}\n */\n clone () {\n const el = new YXmlFragment()\n // @ts-ignore\n el.insert(0, this.toArray().map(item => item instanceof AbstractType ? item.clone() : item))\n return el\n }\n\n get length () {\n this.doc ?? warnPrematureAccess()\n return this._prelimContent === null ? this._length : this._prelimContent.length\n }\n\n /**\n * Create a subtree of childNodes.\n *\n * @example\n * const walker = elem.createTreeWalker(dom => dom.nodeName === 'div')\n * for (let node in walker) {\n * // `node` is a div node\n * nop(node)\n * }\n *\n * @param {function(AbstractType<any>):boolean} filter Function that is called on each child element and\n * returns a Boolean indicating whether the child\n * is to be included in the subtree.\n * @return {YXmlTreeWalker} A subtree and a position within it.\n *\n * @public\n */\n createTreeWalker (filter) {\n return new YXmlTreeWalker(this, filter)\n }\n\n /**\n * Returns the first YXmlElement that matches the query.\n * Similar to DOM's {@link querySelector}.\n *\n * Query support:\n * - tagname\n * TODO:\n * - id\n * - attribute\n *\n * @param {CSS_Selector} query The query on the children.\n * @return {YXmlElement|YXmlText|YXmlHook|null} The first element that matches the query or null.\n *\n * @public\n */\n querySelector (query) {\n query = query.toUpperCase()\n // @ts-ignore\n const iterator = new YXmlTreeWalker(this, element => element.nodeName && element.nodeName.toUpperCase() === query)\n const next = iterator.next()\n if (next.done) {\n return null\n } else {\n return next.value\n }\n }\n\n /**\n * Returns all YXmlElements that match the query.\n * Similar to Dom's {@link querySelectorAll}.\n *\n * @todo Does not yet support all queries. Currently only query by tagName.\n *\n * @param {CSS_Selector} query The query on the children\n * @return {Array<YXmlElement|YXmlText|YXmlHook|null>} The elements that match this query.\n *\n * @public\n */\n querySelectorAll (query) {\n query = query.toUpperCase()\n // @ts-ignore\n return array.from(new YXmlTreeWalker(this, element => element.nodeName && element.nodeName.toUpperCase() === query))\n }\n\n /**\n * Creates YXmlEvent and calls observers.\n *\n * @param {Transaction} transaction\n * @param {Set<null|string>} parentSubs Keys changed on this type. `null` if list was modified.\n */\n _callObserver (transaction, parentSubs) {\n callTypeObservers(this, transaction, new YXmlEvent(this, parentSubs, transaction))\n }\n\n /**\n * Get the string representation of all the children of this YXmlFragment.\n *\n * @return {string} The string representation of all children.\n */\n toString () {\n return typeListMap(this, xml => xml.toString()).join('')\n }\n\n /**\n * @return {string}\n */\n toJSON () {\n return this.toString()\n }\n\n /**\n * Creates a Dom Element that mirrors this YXmlElement.\n *\n * @param {Document} [_document=document] The document object (you must define\n * this when calling this method in\n * nodejs)\n * @param {Object<string, any>} [hooks={}] Optional property to customize how hooks\n * are presented in the DOM\n * @param {any} [binding] You should not set this property. This is\n * used if DomBinding wants to create a\n * association to the created DOM type.\n * @return {Node} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element}\n *\n * @public\n */\n toDOM (_document = document, hooks = {}, binding) {\n const fragment = _document.createDocumentFragment()\n if (binding !== undefined) {\n binding._createAssociation(fragment, this)\n }\n typeListForEach(this, xmlType => {\n fragment.insertBefore(xmlType.toDOM(_document, hooks, binding), null)\n })\n return fragment\n }\n\n /**\n * Inserts new content at an index.\n *\n * @example\n * // Insert character 'a' at position 0\n * xml.insert(0, [new Y.XmlText('text')])\n *\n * @param {number} index The index to insert content at\n * @param {Array<YXmlElement|YXmlText>} content The array of content\n */\n insert (index, content) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeListInsertGenerics(transaction, this, index, content)\n })\n } else {\n // @ts-ignore _prelimContent is defined because this is not yet integrated\n this._prelimContent.splice(index, 0, ...content)\n }\n }\n\n /**\n * Inserts new content at an index.\n *\n * @example\n * // Insert character 'a' at position 0\n * xml.insert(0, [new Y.XmlText('text')])\n *\n * @param {null|Item|YXmlElement|YXmlText} ref The index to insert content at\n * @param {Array<YXmlElement|YXmlText>} content The array of content\n */\n insertAfter (ref, content) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n const refItem = (ref && ref instanceof AbstractType) ? ref._item : ref\n typeListInsertGenericsAfter(transaction, this, refItem, content)\n })\n } else {\n const pc = /** @type {Array<any>} */ (this._prelimContent)\n const index = ref === null ? 0 : pc.findIndex(el => el === ref) + 1\n if (index === 0 && ref !== null) {\n throw error.create('Reference item not found')\n }\n pc.splice(index, 0, ...content)\n }\n }\n\n /**\n * Deletes elements starting from an index.\n *\n * @param {number} index Index at which to start deleting elements\n * @param {number} [length=1] The number of elements to remove. Defaults to 1.\n */\n delete (index, length = 1) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeListDelete(transaction, this, index, length)\n })\n } else {\n // @ts-ignore _prelimContent is defined because this is not yet integrated\n this._prelimContent.splice(index, length)\n }\n }\n\n /**\n * Transforms this YArray to a JavaScript Array.\n *\n * @return {Array<YXmlElement|YXmlText|YXmlHook>}\n */\n toArray () {\n return typeListToArray(this)\n }\n\n /**\n * Appends content to this YArray.\n *\n * @param {Array<YXmlElement|YXmlText>} content Array of content to append.\n */\n push (content) {\n this.insert(this.length, content)\n }\n\n /**\n * Prepends content to this YArray.\n *\n * @param {Array<YXmlElement|YXmlText>} content Array of content to prepend.\n */\n unshift (content) {\n this.insert(0, content)\n }\n\n /**\n * Returns the i-th element from a YArray.\n *\n * @param {number} index The index of the element to return from the YArray\n * @return {YXmlElement|YXmlText}\n */\n get (index) {\n return typeListGet(this, index)\n }\n\n /**\n * Returns a portion of this YXmlFragment into a JavaScript Array selected\n * from start to end (end not included).\n *\n * @param {number} [start]\n * @param {number} [end]\n * @return {Array<YXmlElement|YXmlText>}\n */\n slice (start = 0, end = this.length) {\n return typeListSlice(this, start, end)\n }\n\n /**\n * Executes a provided function on once on every child element.\n *\n * @param {function(YXmlElement|YXmlText,number, typeof self):void} f A function to execute on every element of this YArray.\n */\n forEach (f) {\n typeListForEach(this, f)\n }\n\n /**\n * Transform the properties of this type to binary and write it to an\n * BinaryEncoder.\n *\n * This is called when this Item is sent to a remote peer.\n *\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.\n */\n _write (encoder) {\n encoder.writeTypeRef(YXmlFragmentRefID)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder\n * @return {YXmlFragment}\n *\n * @private\n * @function\n */\nexport const readYXmlFragment = _decoder => new YXmlFragment()\n","import * as object from 'lib0/object'\n\nimport {\n YXmlFragment,\n transact,\n typeMapDelete,\n typeMapHas,\n typeMapSet,\n typeMapGet,\n typeMapGetAll,\n typeMapGetAllSnapshot,\n typeListForEach,\n YXmlElementRefID,\n Snapshot, YXmlText, ContentType, AbstractType, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Item // eslint-disable-line\n} from '../internals.js'\n\n/**\n * @typedef {Object|number|null|Array<any>|string|Uint8Array|AbstractType<any>} ValueTypes\n */\n\n/**\n * An YXmlElement imitates the behavior of a\n * https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element\n *\n * * An YXmlElement has attributes (key value pairs)\n * * An YXmlElement has childElements that must inherit from YXmlElement\n *\n * @template {{ [key: string]: ValueTypes }} [KV={ [key: string]: string }]\n */\nexport class YXmlElement extends YXmlFragment {\n constructor (nodeName = 'UNDEFINED') {\n super()\n this.nodeName = nodeName\n /**\n * @type {Map<string, any>|null}\n */\n this._prelimAttrs = new Map()\n }\n\n /**\n * @type {YXmlElement|YXmlText|null}\n */\n get nextSibling () {\n const n = this._item ? this._item.next : null\n return n ? /** @type {YXmlElement|YXmlText} */ (/** @type {ContentType} */ (n.content).type) : null\n }\n\n /**\n * @type {YXmlElement|YXmlText|null}\n */\n get prevSibling () {\n const n = this._item ? this._item.prev : null\n return n ? /** @type {YXmlElement|YXmlText} */ (/** @type {ContentType} */ (n.content).type) : null\n }\n\n /**\n * Integrate this type into the Yjs instance.\n *\n * * Save this struct in the os\n * * This type is sent to other client\n * * Observer functions are fired\n *\n * @param {Doc} y The Yjs instance\n * @param {Item} item\n */\n _integrate (y, item) {\n super._integrate(y, item)\n ;(/** @type {Map<string, any>} */ (this._prelimAttrs)).forEach((value, key) => {\n this.setAttribute(key, value)\n })\n this._prelimAttrs = null\n }\n\n /**\n * Creates an Item with the same effect as this Item (without position effect)\n *\n * @return {YXmlElement}\n */\n _copy () {\n return new YXmlElement(this.nodeName)\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YXmlElement<KV>}\n */\n clone () {\n /**\n * @type {YXmlElement<KV>}\n */\n const el = new YXmlElement(this.nodeName)\n const attrs = this.getAttributes()\n object.forEach(attrs, (value, key) => {\n if (typeof value === 'string') {\n el.setAttribute(key, value)\n }\n })\n // @ts-ignore\n el.insert(0, this.toArray().map(item => item instanceof AbstractType ? item.clone() : item))\n return el\n }\n\n /**\n * Returns the XML serialization of this YXmlElement.\n * The attributes are ordered by attribute-name, so you can easily use this\n * method to compare YXmlElements\n *\n * @return {string} The string representation of this type.\n *\n * @public\n */\n toString () {\n const attrs = this.getAttributes()\n const stringBuilder = []\n const keys = []\n for (const key in attrs) {\n keys.push(key)\n }\n keys.sort()\n const keysLen = keys.length\n for (let i = 0; i < keysLen; i++) {\n const key = keys[i]\n stringBuilder.push(key + '=\"' + attrs[key] + '\"')\n }\n const nodeName = this.nodeName.toLocaleLowerCase()\n const attrsString = stringBuilder.length > 0 ? ' ' + stringBuilder.join(' ') : ''\n return `<${nodeName}${attrsString}>${super.toString()}</${nodeName}>`\n }\n\n /**\n * Removes an attribute from this YXmlElement.\n *\n * @param {string} attributeName The attribute name that is to be removed.\n *\n * @public\n */\n removeAttribute (attributeName) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeMapDelete(transaction, this, attributeName)\n })\n } else {\n /** @type {Map<string,any>} */ (this._prelimAttrs).delete(attributeName)\n }\n }\n\n /**\n * Sets or updates an attribute.\n *\n * @template {keyof KV & string} KEY\n *\n * @param {KEY} attributeName The attribute name that is to be set.\n * @param {KV[KEY]} attributeValue The attribute value that is to be set.\n *\n * @public\n */\n setAttribute (attributeName, attributeValue) {\n if (this.doc !== null) {\n transact(this.doc, transaction => {\n typeMapSet(transaction, this, attributeName, attributeValue)\n })\n } else {\n /** @type {Map<string, any>} */ (this._prelimAttrs).set(attributeName, attributeValue)\n }\n }\n\n /**\n * Returns an attribute value that belongs to the attribute name.\n *\n * @template {keyof KV & string} KEY\n *\n * @param {KEY} attributeName The attribute name that identifies the\n * queried value.\n * @return {KV[KEY]|undefined} The queried attribute value.\n *\n * @public\n */\n getAttribute (attributeName) {\n return /** @type {any} */ (typeMapGet(this, attributeName))\n }\n\n /**\n * Returns whether an attribute exists\n *\n * @param {string} attributeName The attribute name to check for existence.\n * @return {boolean} whether the attribute exists.\n *\n * @public\n */\n hasAttribute (attributeName) {\n return /** @type {any} */ (typeMapHas(this, attributeName))\n }\n\n /**\n * Returns all attribute name/value pairs in a JSON Object.\n *\n * @param {Snapshot} [snapshot]\n * @return {{ [Key in Extract<keyof KV,string>]?: KV[Key]}} A JSON Object that describes the attributes.\n *\n * @public\n */\n getAttributes (snapshot) {\n return /** @type {any} */ (snapshot ? typeMapGetAllSnapshot(this, snapshot) : typeMapGetAll(this))\n }\n\n /**\n * Creates a Dom Element that mirrors this YXmlElement.\n *\n * @param {Document} [_document=document] The document object (you must define\n * this when calling this method in\n * nodejs)\n * @param {Object<string, any>} [hooks={}] Optional property to customize how hooks\n * are presented in the DOM\n * @param {any} [binding] You should not set this property. This is\n * used if DomBinding wants to create a\n * association to the created DOM type.\n * @return {Node} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element}\n *\n * @public\n */\n toDOM (_document = document, hooks = {}, binding) {\n const dom = _document.createElement(this.nodeName)\n const attrs = this.getAttributes()\n for (const key in attrs) {\n const value = attrs[key]\n if (typeof value === 'string') {\n dom.setAttribute(key, value)\n }\n }\n typeListForEach(this, yxml => {\n dom.appendChild(yxml.toDOM(_document, hooks, binding))\n })\n if (binding !== undefined) {\n binding._createAssociation(dom, this)\n }\n return dom\n }\n\n /**\n * Transform the properties of this type to binary and write it to an\n * BinaryEncoder.\n *\n * This is called when this Item is sent to a remote peer.\n *\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.\n */\n _write (encoder) {\n encoder.writeTypeRef(YXmlElementRefID)\n encoder.writeKey(this.nodeName)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {YXmlElement}\n *\n * @function\n */\nexport const readYXmlElement = decoder => new YXmlElement(decoder.readKey())\n","import {\n YEvent,\n YXmlText, YXmlElement, YXmlFragment, Transaction // eslint-disable-line\n} from '../internals.js'\n\n/**\n * @extends YEvent<YXmlElement|YXmlText|YXmlFragment>\n * An Event that describes changes on a YXml Element or Yxml Fragment\n */\nexport class YXmlEvent extends YEvent {\n /**\n * @param {YXmlElement|YXmlText|YXmlFragment} target The target on which the event is created.\n * @param {Set<string|null>} subs The set of changed attributes. `null` is included if the\n * child list changed.\n * @param {Transaction} transaction The transaction instance with which the\n * change was created.\n */\n constructor (target, subs, transaction) {\n super(target, transaction)\n /**\n * Whether the children changed.\n * @type {Boolean}\n * @private\n */\n this.childListChanged = false\n /**\n * Set of all changed attributes.\n * @type {Set<string>}\n */\n this.attributesChanged = new Set()\n subs.forEach((sub) => {\n if (sub === null) {\n this.childListChanged = true\n } else {\n this.attributesChanged.add(sub)\n }\n })\n }\n}\n","import {\n YMap,\n YXmlHookRefID,\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2 // eslint-disable-line\n} from '../internals.js'\n\n/**\n * You can manage binding to a custom type with YXmlHook.\n *\n * @extends {YMap<any>}\n */\nexport class YXmlHook extends YMap {\n /**\n * @param {string} hookName nodeName of the Dom Node.\n */\n constructor (hookName) {\n super()\n /**\n * @type {string}\n */\n this.hookName = hookName\n }\n\n /**\n * Creates an Item with the same effect as this Item (without position effect)\n */\n _copy () {\n return new YXmlHook(this.hookName)\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YXmlHook}\n */\n clone () {\n const el = new YXmlHook(this.hookName)\n this.forEach((value, key) => {\n el.set(key, value)\n })\n return el\n }\n\n /**\n * Creates a Dom Element that mirrors this YXmlElement.\n *\n * @param {Document} [_document=document] The document object (you must define\n * this when calling this method in\n * nodejs)\n * @param {Object.<string, any>} [hooks] Optional property to customize how hooks\n * are presented in the DOM\n * @param {any} [binding] You should not set this property. This is\n * used if DomBinding wants to create a\n * association to the created DOM type\n * @return {Element} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element}\n *\n * @public\n */\n toDOM (_document = document, hooks = {}, binding) {\n const hook = hooks[this.hookName]\n let dom\n if (hook !== undefined) {\n dom = hook.createDom(this)\n } else {\n dom = document.createElement(this.hookName)\n }\n dom.setAttribute('data-yjs-hook', this.hookName)\n if (binding !== undefined) {\n binding._createAssociation(dom, this)\n }\n return dom\n }\n\n /**\n * Transform the properties of this type to binary and write it to an\n * BinaryEncoder.\n *\n * This is called when this Item is sent to a remote peer.\n *\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.\n */\n _write (encoder) {\n encoder.writeTypeRef(YXmlHookRefID)\n encoder.writeKey(this.hookName)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {YXmlHook}\n *\n * @private\n * @function\n */\nexport const readYXmlHook = decoder =>\n new YXmlHook(decoder.readKey())\n","import {\n YText,\n YXmlTextRefID,\n ContentType, YXmlElement, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, // eslint-disable-line\n} from '../internals.js'\n\n/**\n * Represents text in a Dom Element. In the future this type will also handle\n * simple formatting information like bold and italic.\n */\nexport class YXmlText extends YText {\n /**\n * @type {YXmlElement|YXmlText|null}\n */\n get nextSibling () {\n const n = this._item ? this._item.next : null\n return n ? /** @type {YXmlElement|YXmlText} */ (/** @type {ContentType} */ (n.content).type) : null\n }\n\n /**\n * @type {YXmlElement|YXmlText|null}\n */\n get prevSibling () {\n const n = this._item ? this._item.prev : null\n return n ? /** @type {YXmlElement|YXmlText} */ (/** @type {ContentType} */ (n.content).type) : null\n }\n\n _copy () {\n return new YXmlText()\n }\n\n /**\n * Makes a copy of this data type that can be included somewhere else.\n *\n * Note that the content is only readable _after_ it has been included somewhere in the Ydoc.\n *\n * @return {YXmlText}\n */\n clone () {\n const text = new YXmlText()\n text.applyDelta(this.toDelta())\n return text\n }\n\n /**\n * Creates a Dom Element that mirrors this YXmlText.\n *\n * @param {Document} [_document=document] The document object (you must define\n * this when calling this method in\n * nodejs)\n * @param {Object<string, any>} [hooks] Optional property to customize how hooks\n * are presented in the DOM\n * @param {any} [binding] You should not set this property. This is\n * used if DomBinding wants to create a\n * association to the created DOM type.\n * @return {Text} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element}\n *\n * @public\n */\n toDOM (_document = document, hooks, binding) {\n const dom = _document.createTextNode(this.toString())\n if (binding !== undefined) {\n binding._createAssociation(dom, this)\n }\n return dom\n }\n\n toString () {\n // @ts-ignore\n return this.toDelta().map(delta => {\n const nestedNodes = []\n for (const nodeName in delta.attributes) {\n const attrs = []\n for (const key in delta.attributes[nodeName]) {\n attrs.push({ key, value: delta.attributes[nodeName][key] })\n }\n // sort attributes to get a unique order\n attrs.sort((a, b) => a.key < b.key ? -1 : 1)\n nestedNodes.push({ nodeName, attrs })\n }\n // sort node order to get a unique order\n nestedNodes.sort((a, b) => a.nodeName < b.nodeName ? -1 : 1)\n // now convert to dom string\n let str = ''\n for (let i = 0; i < nestedNodes.length; i++) {\n const node = nestedNodes[i]\n str += `<${node.nodeName}`\n for (let j = 0; j < node.attrs.length; j++) {\n const attr = node.attrs[j]\n str += ` ${attr.key}=\"${attr.value}\"`\n }\n str += '>'\n }\n str += delta.insert\n for (let i = nestedNodes.length - 1; i >= 0; i--) {\n str += `</${nestedNodes[i].nodeName}>`\n }\n return str\n }).join('')\n }\n\n /**\n * @return {string}\n */\n toJSON () {\n return this.toString()\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n */\n _write (encoder) {\n encoder.writeTypeRef(YXmlTextRefID)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {YXmlText}\n *\n * @private\n * @function\n */\nexport const readYXmlText = decoder => new YXmlText()\n","import {\n UpdateEncoderV1, UpdateEncoderV2, ID, Transaction // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\n\nexport class AbstractStruct {\n /**\n * @param {ID} id\n * @param {number} length\n */\n constructor (id, length) {\n this.id = id\n this.length = length\n }\n\n /**\n * @type {boolean}\n */\n get deleted () {\n throw error.methodUnimplemented()\n }\n\n /**\n * Merge this struct with the item to the right.\n * This method is already assuming that `this.id.clock + this.length === this.id.clock`.\n * Also this method does *not* remove right from StructStore!\n * @param {AbstractStruct} right\n * @return {boolean} whether this merged with right\n */\n mergeWith (right) {\n return false\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.\n * @param {number} offset\n * @param {number} encodingRef\n */\n write (encoder, offset, encodingRef) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {Transaction} transaction\n * @param {number} offset\n */\n integrate (transaction, offset) {\n throw error.methodUnimplemented()\n }\n}\n","import {\n AbstractStruct,\n addStruct,\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, ID // eslint-disable-line\n} from '../internals.js'\n\nexport const structGCRefNumber = 0\n\n/**\n * @private\n */\nexport class GC extends AbstractStruct {\n get deleted () {\n return true\n }\n\n delete () {}\n\n /**\n * @param {GC} right\n * @return {boolean}\n */\n mergeWith (right) {\n if (this.constructor !== right.constructor) {\n return false\n }\n this.length += right.length\n return true\n }\n\n /**\n * @param {Transaction} transaction\n * @param {number} offset\n */\n integrate (transaction, offset) {\n if (offset > 0) {\n this.id.clock += offset\n this.length -= offset\n }\n addStruct(transaction.doc.store, this)\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeInfo(structGCRefNumber)\n encoder.writeLen(this.length - offset)\n }\n\n /**\n * @param {Transaction} transaction\n * @param {StructStore} store\n * @return {null | number}\n */\n getMissing (transaction, store) {\n return null\n }\n}\n","import {\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Item, Transaction // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\n\nexport class ContentBinary {\n /**\n * @param {Uint8Array} content\n */\n constructor (content) {\n this.content = content\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return 1\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return [this.content]\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentBinary}\n */\n copy () {\n return new ContentBinary(this.content)\n }\n\n /**\n * @param {number} offset\n * @return {ContentBinary}\n */\n splice (offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {ContentBinary} right\n * @return {boolean}\n */\n mergeWith (right) {\n return false\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {}\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeBuf(this.content)\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 3\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2 } decoder\n * @return {ContentBinary}\n */\nexport const readContentBinary = decoder => new ContentBinary(decoder.readBuf())\n","import {\n addToDeleteSet,\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Item, Transaction // eslint-disable-line\n} from '../internals.js'\n\nexport class ContentDeleted {\n /**\n * @param {number} len\n */\n constructor (len) {\n this.len = len\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return this.len\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return []\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return false\n }\n\n /**\n * @return {ContentDeleted}\n */\n copy () {\n return new ContentDeleted(this.len)\n }\n\n /**\n * @param {number} offset\n * @return {ContentDeleted}\n */\n splice (offset) {\n const right = new ContentDeleted(this.len - offset)\n this.len = offset\n return right\n }\n\n /**\n * @param {ContentDeleted} right\n * @return {boolean}\n */\n mergeWith (right) {\n this.len += right.len\n return true\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {\n addToDeleteSet(transaction.deleteSet, item.id.client, item.id.clock, this.len)\n item.markDeleted()\n }\n\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeLen(this.len - offset)\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 1\n }\n}\n\n/**\n * @private\n *\n * @param {UpdateDecoderV1 | UpdateDecoderV2 } decoder\n * @return {ContentDeleted}\n */\nexport const readContentDeleted = decoder => new ContentDeleted(decoder.readLen())\n","import {\n Doc, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, Item // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\n\n/**\n * @param {string} guid\n * @param {Object<string, any>} opts\n */\nconst createDocFromOpts = (guid, opts) => new Doc({ guid, ...opts, shouldLoad: opts.shouldLoad || opts.autoLoad || false })\n\n/**\n * @private\n */\nexport class ContentDoc {\n /**\n * @param {Doc} doc\n */\n constructor (doc) {\n if (doc._item) {\n console.error('This document was already integrated as a sub-document. You should create a second instance instead with the same guid.')\n }\n /**\n * @type {Doc}\n */\n this.doc = doc\n /**\n * @type {any}\n */\n const opts = {}\n this.opts = opts\n if (!doc.gc) {\n opts.gc = false\n }\n if (doc.autoLoad) {\n opts.autoLoad = true\n }\n if (doc.meta !== null) {\n opts.meta = doc.meta\n }\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return 1\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return [this.doc]\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentDoc}\n */\n copy () {\n return new ContentDoc(createDocFromOpts(this.doc.guid, this.opts))\n }\n\n /**\n * @param {number} offset\n * @return {ContentDoc}\n */\n splice (offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {ContentDoc} right\n * @return {boolean}\n */\n mergeWith (right) {\n return false\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {\n // this needs to be reflected in doc.destroy as well\n this.doc._item = item\n transaction.subdocsAdded.add(this.doc)\n if (this.doc.shouldLoad) {\n transaction.subdocsLoaded.add(this.doc)\n }\n }\n\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {\n if (transaction.subdocsAdded.has(this.doc)) {\n transaction.subdocsAdded.delete(this.doc)\n } else {\n transaction.subdocsRemoved.add(this.doc)\n }\n }\n\n /**\n * @param {StructStore} store\n */\n gc (store) { }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeString(this.doc.guid)\n encoder.writeAny(this.opts)\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 9\n }\n}\n\n/**\n * @private\n *\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentDoc}\n */\nexport const readContentDoc = decoder => new ContentDoc(createDocFromOpts(decoder.readString(), decoder.readAny()))\n","import {\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Item, Transaction // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\n\n/**\n * @private\n */\nexport class ContentEmbed {\n /**\n * @param {Object} embed\n */\n constructor (embed) {\n this.embed = embed\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return 1\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return [this.embed]\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentEmbed}\n */\n copy () {\n return new ContentEmbed(this.embed)\n }\n\n /**\n * @param {number} offset\n * @return {ContentEmbed}\n */\n splice (offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {ContentEmbed} right\n * @return {boolean}\n */\n mergeWith (right) {\n return false\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {}\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeJSON(this.embed)\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 5\n }\n}\n\n/**\n * @private\n *\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentEmbed}\n */\nexport const readContentEmbed = decoder => new ContentEmbed(decoder.readJSON())\n","import {\n YText, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Item, StructStore, Transaction // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\n\n/**\n * @private\n */\nexport class ContentFormat {\n /**\n * @param {string} key\n * @param {Object} value\n */\n constructor (key, value) {\n this.key = key\n this.value = value\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return 1\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return []\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return false\n }\n\n /**\n * @return {ContentFormat}\n */\n copy () {\n return new ContentFormat(this.key, this.value)\n }\n\n /**\n * @param {number} _offset\n * @return {ContentFormat}\n */\n splice (_offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {ContentFormat} _right\n * @return {boolean}\n */\n mergeWith (_right) {\n return false\n }\n\n /**\n * @param {Transaction} _transaction\n * @param {Item} item\n */\n integrate (_transaction, item) {\n // @todo searchmarker are currently unsupported for rich text documents\n const p = /** @type {YText} */ (item.parent)\n p._searchMarker = null\n p._hasFormatting = true\n }\n\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeKey(this.key)\n encoder.writeJSON(this.value)\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 6\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentFormat}\n */\nexport const readContentFormat = decoder => new ContentFormat(decoder.readKey(), decoder.readJSON())\n","import {\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Transaction, Item, StructStore // eslint-disable-line\n} from '../internals.js'\n\n/**\n * @private\n */\nexport class ContentJSON {\n /**\n * @param {Array<any>} arr\n */\n constructor (arr) {\n /**\n * @type {Array<any>}\n */\n this.arr = arr\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return this.arr.length\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return this.arr\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentJSON}\n */\n copy () {\n return new ContentJSON(this.arr)\n }\n\n /**\n * @param {number} offset\n * @return {ContentJSON}\n */\n splice (offset) {\n const right = new ContentJSON(this.arr.slice(offset))\n this.arr = this.arr.slice(0, offset)\n return right\n }\n\n /**\n * @param {ContentJSON} right\n * @return {boolean}\n */\n mergeWith (right) {\n this.arr = this.arr.concat(right.arr)\n return true\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {}\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n const len = this.arr.length\n encoder.writeLen(len - offset)\n for (let i = offset; i < len; i++) {\n const c = this.arr[i]\n encoder.writeString(c === undefined ? 'undefined' : JSON.stringify(c))\n }\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 2\n }\n}\n\n/**\n * @private\n *\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentJSON}\n */\nexport const readContentJSON = decoder => {\n const len = decoder.readLen()\n const cs = []\n for (let i = 0; i < len; i++) {\n const c = decoder.readString()\n if (c === 'undefined') {\n cs.push(undefined)\n } else {\n cs.push(JSON.parse(c))\n }\n }\n return new ContentJSON(cs)\n}\n","import {\n UpdateEncoderV1, UpdateEncoderV2, UpdateDecoderV1, UpdateDecoderV2, Transaction, Item, StructStore // eslint-disable-line\n} from '../internals.js'\n\nimport * as env from 'lib0/environment'\nimport * as object from 'lib0/object'\n\nconst isDevMode = env.getVariable('node_env') === 'development'\n\nexport class ContentAny {\n /**\n * @param {Array<any>} arr\n */\n constructor (arr) {\n /**\n * @type {Array<any>}\n */\n this.arr = arr\n isDevMode && object.deepFreeze(arr)\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return this.arr.length\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return this.arr\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentAny}\n */\n copy () {\n return new ContentAny(this.arr)\n }\n\n /**\n * @param {number} offset\n * @return {ContentAny}\n */\n splice (offset) {\n const right = new ContentAny(this.arr.slice(offset))\n this.arr = this.arr.slice(0, offset)\n return right\n }\n\n /**\n * @param {ContentAny} right\n * @return {boolean}\n */\n mergeWith (right) {\n this.arr = this.arr.concat(right.arr)\n return true\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {}\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n const len = this.arr.length\n encoder.writeLen(len - offset)\n for (let i = offset; i < len; i++) {\n const c = this.arr[i]\n encoder.writeAny(c)\n }\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 8\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentAny}\n */\nexport const readContentAny = decoder => {\n const len = decoder.readLen()\n const cs = []\n for (let i = 0; i < len; i++) {\n cs.push(decoder.readAny())\n }\n return new ContentAny(cs)\n}\n","import {\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Transaction, Item, StructStore // eslint-disable-line\n} from '../internals.js'\n\n/**\n * @private\n */\nexport class ContentString {\n /**\n * @param {string} str\n */\n constructor (str) {\n /**\n * @type {string}\n */\n this.str = str\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return this.str.length\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return this.str.split('')\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentString}\n */\n copy () {\n return new ContentString(this.str)\n }\n\n /**\n * @param {number} offset\n * @return {ContentString}\n */\n splice (offset) {\n const right = new ContentString(this.str.slice(offset))\n this.str = this.str.slice(0, offset)\n\n // Prevent encoding invalid documents because of splitting of surrogate pairs: https://github.com/yjs/yjs/issues/248\n const firstCharCode = this.str.charCodeAt(offset - 1)\n if (firstCharCode >= 0xD800 && firstCharCode <= 0xDBFF) {\n // Last character of the left split is the start of a surrogate utf16/ucs2 pair.\n // We don't support splitting of surrogate pairs because this may lead to invalid documents.\n // Replace the invalid character with a unicode replacement character (� / U+FFFD)\n this.str = this.str.slice(0, offset - 1) + '�'\n // replace right as well\n right.str = '�' + right.str.slice(1)\n }\n return right\n }\n\n /**\n * @param {ContentString} right\n * @return {boolean}\n */\n mergeWith (right) {\n this.str += right.str\n return true\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {}\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {}\n /**\n * @param {StructStore} store\n */\n gc (store) {}\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeString(offset === 0 ? this.str : this.str.slice(offset))\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 4\n }\n}\n\n/**\n * @private\n *\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentString}\n */\nexport const readContentString = decoder => new ContentString(decoder.readString())\n","import {\n readYArray,\n readYMap,\n readYText,\n readYXmlElement,\n readYXmlFragment,\n readYXmlHook,\n readYXmlText,\n UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, Item, YEvent, AbstractType // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\n\n/**\n * @type {Array<function(UpdateDecoderV1 | UpdateDecoderV2):AbstractType<any>>}\n * @private\n */\nexport const typeRefs = [\n readYArray,\n readYMap,\n readYText,\n readYXmlElement,\n readYXmlFragment,\n readYXmlHook,\n readYXmlText\n]\n\nexport const YArrayRefID = 0\nexport const YMapRefID = 1\nexport const YTextRefID = 2\nexport const YXmlElementRefID = 3\nexport const YXmlFragmentRefID = 4\nexport const YXmlHookRefID = 5\nexport const YXmlTextRefID = 6\n\n/**\n * @private\n */\nexport class ContentType {\n /**\n * @param {AbstractType<any>} type\n */\n constructor (type) {\n /**\n * @type {AbstractType<any>}\n */\n this.type = type\n }\n\n /**\n * @return {number}\n */\n getLength () {\n return 1\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n return [this.type]\n }\n\n /**\n * @return {boolean}\n */\n isCountable () {\n return true\n }\n\n /**\n * @return {ContentType}\n */\n copy () {\n return new ContentType(this.type._copy())\n }\n\n /**\n * @param {number} offset\n * @return {ContentType}\n */\n splice (offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {ContentType} right\n * @return {boolean}\n */\n mergeWith (right) {\n return false\n }\n\n /**\n * @param {Transaction} transaction\n * @param {Item} item\n */\n integrate (transaction, item) {\n this.type._integrate(transaction.doc, item)\n }\n\n /**\n * @param {Transaction} transaction\n */\n delete (transaction) {\n let item = this.type._start\n while (item !== null) {\n if (!item.deleted) {\n item.delete(transaction)\n } else if (item.id.clock < (transaction.beforeState.get(item.id.client) || 0)) {\n // This will be gc'd later and we want to merge it if possible\n // We try to merge all deleted items after each transaction,\n // but we have no knowledge about that this needs to be merged\n // since it is not in transaction.ds. Hence we add it to transaction._mergeStructs\n transaction._mergeStructs.push(item)\n }\n item = item.right\n }\n this.type._map.forEach(item => {\n if (!item.deleted) {\n item.delete(transaction)\n } else if (item.id.clock < (transaction.beforeState.get(item.id.client) || 0)) {\n // same as above\n transaction._mergeStructs.push(item)\n }\n })\n transaction.changed.delete(this.type)\n }\n\n /**\n * @param {StructStore} store\n */\n gc (store) {\n let item = this.type._start\n while (item !== null) {\n item.gc(store, true)\n item = item.right\n }\n this.type._start = null\n this.type._map.forEach(/** @param {Item | null} item */ (item) => {\n while (item !== null) {\n item.gc(store, true)\n item = item.left\n }\n })\n this.type._map = new Map()\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n this.type._write(encoder)\n }\n\n /**\n * @return {number}\n */\n getRef () {\n return 7\n }\n}\n\n/**\n * @private\n *\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @return {ContentType}\n */\nexport const readContentType = decoder => new ContentType(typeRefs[decoder.readTypeRef()](decoder))\n","import {\n GC,\n getState,\n AbstractStruct,\n replaceStruct,\n addStruct,\n addToDeleteSet,\n findRootTypeKey,\n compareIDs,\n getItem,\n getItemCleanEnd,\n getItemCleanStart,\n readContentDeleted,\n readContentBinary,\n readContentJSON,\n readContentAny,\n readContentString,\n readContentEmbed,\n readContentDoc,\n createID,\n readContentFormat,\n readContentType,\n addChangedTypeToTransaction,\n isDeleted,\n StackItem, DeleteSet, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ContentType, ContentDeleted, StructStore, ID, AbstractType, Transaction // eslint-disable-line\n} from '../internals.js'\n\nimport * as error from 'lib0/error'\nimport * as binary from 'lib0/binary'\nimport * as array from 'lib0/array'\n\n/**\n * @todo This should return several items\n *\n * @param {StructStore} store\n * @param {ID} id\n * @return {{item:Item, diff:number}}\n */\nexport const followRedone = (store, id) => {\n /**\n * @type {ID|null}\n */\n let nextID = id\n let diff = 0\n let item\n do {\n if (diff > 0) {\n nextID = createID(nextID.client, nextID.clock + diff)\n }\n item = getItem(store, nextID)\n diff = nextID.clock - item.id.clock\n nextID = item.redone\n } while (nextID !== null && item instanceof Item)\n return {\n item, diff\n }\n}\n\n/**\n * Make sure that neither item nor any of its parents is ever deleted.\n *\n * This property does not persist when storing it into a database or when\n * sending it to other peers\n *\n * @param {Item|null} item\n * @param {boolean} keep\n */\nexport const keepItem = (item, keep) => {\n while (item !== null && item.keep !== keep) {\n item.keep = keep\n item = /** @type {AbstractType<any>} */ (item.parent)._item\n }\n}\n\n/**\n * Split leftItem into two items\n * @param {Transaction} transaction\n * @param {Item} leftItem\n * @param {number} diff\n * @return {Item}\n *\n * @function\n * @private\n */\nexport const splitItem = (transaction, leftItem, diff) => {\n // create rightItem\n const { client, clock } = leftItem.id\n const rightItem = new Item(\n createID(client, clock + diff),\n leftItem,\n createID(client, clock + diff - 1),\n leftItem.right,\n leftItem.rightOrigin,\n leftItem.parent,\n leftItem.parentSub,\n leftItem.content.splice(diff)\n )\n if (leftItem.deleted) {\n rightItem.markDeleted()\n }\n if (leftItem.keep) {\n rightItem.keep = true\n }\n if (leftItem.redone !== null) {\n rightItem.redone = createID(leftItem.redone.client, leftItem.redone.clock + diff)\n }\n // update left (do not set leftItem.rightOrigin as it will lead to problems when syncing)\n leftItem.right = rightItem\n // update right\n if (rightItem.right !== null) {\n rightItem.right.left = rightItem\n }\n // right is more specific.\n transaction._mergeStructs.push(rightItem)\n // update parent._map\n if (rightItem.parentSub !== null && rightItem.right === null) {\n /** @type {AbstractType<any>} */ (rightItem.parent)._map.set(rightItem.parentSub, rightItem)\n }\n leftItem.length = diff\n return rightItem\n}\n\n/**\n * @param {Array<StackItem>} stack\n * @param {ID} id\n */\nconst isDeletedByUndoStack = (stack, id) => array.some(stack, /** @param {StackItem} s */ s => isDeleted(s.deletions, id))\n\n/**\n * Redoes the effect of this operation.\n *\n * @param {Transaction} transaction The Yjs instance.\n * @param {Item} item\n * @param {Set<Item>} redoitems\n * @param {DeleteSet} itemsToDelete\n * @param {boolean} ignoreRemoteMapChanges\n * @param {import('../utils/UndoManager.js').UndoManager} um\n *\n * @return {Item|null}\n *\n * @private\n */\nexport const redoItem = (transaction, item, redoitems, itemsToDelete, ignoreRemoteMapChanges, um) => {\n const doc = transaction.doc\n const store = doc.store\n const ownClientID = doc.clientID\n const redone = item.redone\n if (redone !== null) {\n return getItemCleanStart(transaction, redone)\n }\n let parentItem = /** @type {AbstractType<any>} */ (item.parent)._item\n /**\n * @type {Item|null}\n */\n let left = null\n /**\n * @type {Item|null}\n */\n let right\n // make sure that parent is redone\n if (parentItem !== null && parentItem.deleted === true) {\n // try to undo parent if it will be undone anyway\n if (parentItem.redone === null && (!redoitems.has(parentItem) || redoItem(transaction, parentItem, redoitems, itemsToDelete, ignoreRemoteMapChanges, um) === null)) {\n return null\n }\n while (parentItem.redone !== null) {\n parentItem = getItemCleanStart(transaction, parentItem.redone)\n }\n }\n const parentType = parentItem === null ? /** @type {AbstractType<any>} */ (item.parent) : /** @type {ContentType} */ (parentItem.content).type\n\n if (item.parentSub === null) {\n // Is an array item. Insert at the old position\n left = item.left\n right = item\n // find next cloned_redo items\n while (left !== null) {\n /**\n * @type {Item|null}\n */\n let leftTrace = left\n // trace redone until parent matches\n while (leftTrace !== null && /** @type {AbstractType<any>} */ (leftTrace.parent)._item !== parentItem) {\n leftTrace = leftTrace.redone === null ? null : getItemCleanStart(transaction, leftTrace.redone)\n }\n if (leftTrace !== null && /** @type {AbstractType<any>} */ (leftTrace.parent)._item === parentItem) {\n left = leftTrace\n break\n }\n left = left.left\n }\n while (right !== null) {\n /**\n * @type {Item|null}\n */\n let rightTrace = right\n // trace redone until parent matches\n while (rightTrace !== null && /** @type {AbstractType<any>} */ (rightTrace.parent)._item !== parentItem) {\n rightTrace = rightTrace.redone === null ? null : getItemCleanStart(transaction, rightTrace.redone)\n }\n if (rightTrace !== null && /** @type {AbstractType<any>} */ (rightTrace.parent)._item === parentItem) {\n right = rightTrace\n break\n }\n right = right.right\n }\n } else {\n right = null\n if (item.right && !ignoreRemoteMapChanges) {\n left = item\n // Iterate right while right is in itemsToDelete\n // If it is intended to delete right while item is redone, we can expect that item should replace right.\n while (left !== null && left.right !== null && (left.right.redone || isDeleted(itemsToDelete, left.right.id) || isDeletedByUndoStack(um.undoStack, left.right.id) || isDeletedByUndoStack(um.redoStack, left.right.id))) {\n left = left.right\n // follow redone\n while (left.redone) left = getItemCleanStart(transaction, left.redone)\n }\n if (left && left.right !== null) {\n // It is not possible to redo this item because it conflicts with a\n // change from another client\n return null\n }\n } else {\n left = parentType._map.get(item.parentSub) || null\n }\n }\n const nextClock = getState(store, ownClientID)\n const nextId = createID(ownClientID, nextClock)\n const redoneItem = new Item(\n nextId,\n left, left && left.lastId,\n right, right && right.id,\n parentType,\n item.parentSub,\n item.content.copy()\n )\n item.redone = nextId\n keepItem(redoneItem, true)\n redoneItem.integrate(transaction, 0)\n return redoneItem\n}\n\n/**\n * Abstract class that represents any content.\n */\nexport class Item extends AbstractStruct {\n /**\n * @param {ID} id\n * @param {Item | null} left\n * @param {ID | null} origin\n * @param {Item | null} right\n * @param {ID | null} rightOrigin\n * @param {AbstractType<any>|ID|null} parent Is a type if integrated, is null if it is possible to copy parent from left or right, is ID before integration to search for it.\n * @param {string | null} parentSub\n * @param {AbstractContent} content\n */\n constructor (id, left, origin, right, rightOrigin, parent, parentSub, content) {\n super(id, content.getLength())\n /**\n * The item that was originally to the left of this item.\n * @type {ID | null}\n */\n this.origin = origin\n /**\n * The item that is currently to the left of this item.\n * @type {Item | null}\n */\n this.left = left\n /**\n * The item that is currently to the right of this item.\n * @type {Item | null}\n */\n this.right = right\n /**\n * The item that was originally to the right of this item.\n * @type {ID | null}\n */\n this.rightOrigin = rightOrigin\n /**\n * @type {AbstractType<any>|ID|null}\n */\n this.parent = parent\n /**\n * If the parent refers to this item with some kind of key (e.g. YMap, the\n * key is specified here. The key is then used to refer to the list in which\n * to insert this item. If `parentSub = null` type._start is the list in\n * which to insert to. Otherwise it is `parent._map`.\n * @type {String | null}\n */\n this.parentSub = parentSub\n /**\n * If this type's effect is redone this type refers to the type that undid\n * this operation.\n * @type {ID | null}\n */\n this.redone = null\n /**\n * @type {AbstractContent}\n */\n this.content = content\n /**\n * bit1: keep\n * bit2: countable\n * bit3: deleted\n * bit4: mark - mark node as fast-search-marker\n * @type {number} byte\n */\n this.info = this.content.isCountable() ? binary.BIT2 : 0\n }\n\n /**\n * This is used to mark the item as an indexed fast-search marker\n *\n * @type {boolean}\n */\n set marker (isMarked) {\n if (((this.info & binary.BIT4) > 0) !== isMarked) {\n this.info ^= binary.BIT4\n }\n }\n\n get marker () {\n return (this.info & binary.BIT4) > 0\n }\n\n /**\n * If true, do not garbage collect this Item.\n */\n get keep () {\n return (this.info & binary.BIT1) > 0\n }\n\n set keep (doKeep) {\n if (this.keep !== doKeep) {\n this.info ^= binary.BIT1\n }\n }\n\n get countable () {\n return (this.info & binary.BIT2) > 0\n }\n\n /**\n * Whether this item was deleted or not.\n * @type {Boolean}\n */\n get deleted () {\n return (this.info & binary.BIT3) > 0\n }\n\n set deleted (doDelete) {\n if (this.deleted !== doDelete) {\n this.info ^= binary.BIT3\n }\n }\n\n markDeleted () {\n this.info |= binary.BIT3\n }\n\n /**\n * Return the creator clientID of the missing op or define missing items and return null.\n *\n * @param {Transaction} transaction\n * @param {StructStore} store\n * @return {null | number}\n */\n getMissing (transaction, store) {\n if (this.origin && this.origin.client !== this.id.client && this.origin.clock >= getState(store, this.origin.client)) {\n return this.origin.client\n }\n if (this.rightOrigin && this.rightOrigin.client !== this.id.client && this.rightOrigin.clock >= getState(store, this.rightOrigin.client)) {\n return this.rightOrigin.client\n }\n if (this.parent && this.parent.constructor === ID && this.id.client !== this.parent.client && this.parent.clock >= getState(store, this.parent.client)) {\n return this.parent.client\n }\n\n // We have all missing ids, now find the items\n\n if (this.origin) {\n this.left = getItemCleanEnd(transaction, store, this.origin)\n this.origin = this.left.lastId\n }\n if (this.rightOrigin) {\n this.right = getItemCleanStart(transaction, this.rightOrigin)\n this.rightOrigin = this.right.id\n }\n if ((this.left && this.left.constructor === GC) || (this.right && this.right.constructor === GC)) {\n this.parent = null\n } else if (!this.parent) {\n // only set parent if this shouldn't be garbage collected\n if (this.left && this.left.constructor === Item) {\n this.parent = this.left.parent\n this.parentSub = this.left.parentSub\n } else if (this.right && this.right.constructor === Item) {\n this.parent = this.right.parent\n this.parentSub = this.right.parentSub\n }\n } else if (this.parent.constructor === ID) {\n const parentItem = getItem(store, this.parent)\n if (parentItem.constructor === GC) {\n this.parent = null\n } else {\n this.parent = /** @type {ContentType} */ (parentItem.content).type\n }\n }\n return null\n }\n\n /**\n * @param {Transaction} transaction\n * @param {number} offset\n */\n integrate (transaction, offset) {\n if (offset > 0) {\n this.id.clock += offset\n this.left = getItemCleanEnd(transaction, transaction.doc.store, createID(this.id.client, this.id.clock - 1))\n this.origin = this.left.lastId\n this.content = this.content.splice(offset)\n this.length -= offset\n }\n\n if (this.parent) {\n if ((!this.left && (!this.right || this.right.left !== null)) || (this.left && this.left.right !== this.right)) {\n /**\n * @type {Item|null}\n */\n let left = this.left\n\n /**\n * @type {Item|null}\n */\n let o\n // set o to the first conflicting item\n if (left !== null) {\n o = left.right\n } else if (this.parentSub !== null) {\n o = /** @type {AbstractType<any>} */ (this.parent)._map.get(this.parentSub) || null\n while (o !== null && o.left !== null) {\n o = o.left\n }\n } else {\n o = /** @type {AbstractType<any>} */ (this.parent)._start\n }\n // TODO: use something like DeleteSet here (a tree implementation would be best)\n // @todo use global set definitions\n /**\n * @type {Set<Item>}\n */\n const conflictingItems = new Set()\n /**\n * @type {Set<Item>}\n */\n const itemsBeforeOrigin = new Set()\n // Let c in conflictingItems, b in itemsBeforeOrigin\n // ***{origin}bbbb{this}{c,b}{c,b}{o}***\n // Note that conflictingItems is a subset of itemsBeforeOrigin\n while (o !== null && o !== this.right) {\n itemsBeforeOrigin.add(o)\n conflictingItems.add(o)\n if (compareIDs(this.origin, o.origin)) {\n // case 1\n if (o.id.client < this.id.client) {\n left = o\n conflictingItems.clear()\n } else if (compareIDs(this.rightOrigin, o.rightOrigin)) {\n // this and o are conflicting and point to the same integration points. The id decides which item comes first.\n // Since this is to the left of o, we can break here\n break\n } // else, o might be integrated before an item that this conflicts with. If so, we will find it in the next iterations\n } else if (o.origin !== null && itemsBeforeOrigin.has(getItem(transaction.doc.store, o.origin))) { // use getItem instead of getItemCleanEnd because we don't want / need to split items.\n // case 2\n if (!conflictingItems.has(getItem(transaction.doc.store, o.origin))) {\n left = o\n conflictingItems.clear()\n }\n } else {\n break\n }\n o = o.right\n }\n this.left = left\n }\n // reconnect left/right + update parent map/start if necessary\n if (this.left !== null) {\n const right = this.left.right\n this.right = right\n this.left.right = this\n } else {\n let r\n if (this.parentSub !== null) {\n r = /** @type {AbstractType<any>} */ (this.parent)._map.get(this.parentSub) || null\n while (r !== null && r.left !== null) {\n r = r.left\n }\n } else {\n r = /** @type {AbstractType<any>} */ (this.parent)._start\n ;/** @type {AbstractType<any>} */ (this.parent)._start = this\n }\n this.right = r\n }\n if (this.right !== null) {\n this.right.left = this\n } else if (this.parentSub !== null) {\n // set as current parent value if right === null and this is parentSub\n /** @type {AbstractType<any>} */ (this.parent)._map.set(this.parentSub, this)\n if (this.left !== null) {\n // this is the current attribute value of parent. delete right\n this.left.delete(transaction)\n }\n }\n // adjust length of parent\n if (this.parentSub === null && this.countable && !this.deleted) {\n /** @type {AbstractType<any>} */ (this.parent)._length += this.length\n }\n addStruct(transaction.doc.store, this)\n this.content.integrate(transaction, this)\n // add parent to transaction.changed\n addChangedTypeToTransaction(transaction, /** @type {AbstractType<any>} */ (this.parent), this.parentSub)\n if ((/** @type {AbstractType<any>} */ (this.parent)._item !== null && /** @type {AbstractType<any>} */ (this.parent)._item.deleted) || (this.parentSub !== null && this.right !== null)) {\n // delete if parent is deleted or if this is not the current attribute value of parent\n this.delete(transaction)\n }\n } else {\n // parent is not defined. Integrate GC struct instead\n new GC(this.id, this.length).integrate(transaction, 0)\n }\n }\n\n /**\n * Returns the next non-deleted item\n */\n get next () {\n let n = this.right\n while (n !== null && n.deleted) {\n n = n.right\n }\n return n\n }\n\n /**\n * Returns the previous non-deleted item\n */\n get prev () {\n let n = this.left\n while (n !== null && n.deleted) {\n n = n.left\n }\n return n\n }\n\n /**\n * Computes the last content address of this Item.\n */\n get lastId () {\n // allocating ids is pretty costly because of the amount of ids created, so we try to reuse whenever possible\n return this.length === 1 ? this.id : createID(this.id.client, this.id.clock + this.length - 1)\n }\n\n /**\n * Try to merge two items\n *\n * @param {Item} right\n * @return {boolean}\n */\n mergeWith (right) {\n if (\n this.constructor === right.constructor &&\n compareIDs(right.origin, this.lastId) &&\n this.right === right &&\n compareIDs(this.rightOrigin, right.rightOrigin) &&\n this.id.client === right.id.client &&\n this.id.clock + this.length === right.id.clock &&\n this.deleted === right.deleted &&\n this.redone === null &&\n right.redone === null &&\n this.content.constructor === right.content.constructor &&\n this.content.mergeWith(right.content)\n ) {\n const searchMarker = /** @type {AbstractType<any>} */ (this.parent)._searchMarker\n if (searchMarker) {\n searchMarker.forEach(marker => {\n if (marker.p === right) {\n // right is going to be \"forgotten\" so we need to update the marker\n marker.p = this\n // adjust marker index\n if (!this.deleted && this.countable) {\n marker.index -= this.length\n }\n }\n })\n }\n if (right.keep) {\n this.keep = true\n }\n this.right = right.right\n if (this.right !== null) {\n this.right.left = this\n }\n this.length += right.length\n return true\n }\n return false\n }\n\n /**\n * Mark this Item as deleted.\n *\n * @param {Transaction} transaction\n */\n delete (transaction) {\n if (!this.deleted) {\n const parent = /** @type {AbstractType<any>} */ (this.parent)\n // adjust the length of parent\n if (this.countable && this.parentSub === null) {\n parent._length -= this.length\n }\n this.markDeleted()\n addToDeleteSet(transaction.deleteSet, this.id.client, this.id.clock, this.length)\n addChangedTypeToTransaction(transaction, parent, this.parentSub)\n this.content.delete(transaction)\n }\n }\n\n /**\n * @param {StructStore} store\n * @param {boolean} parentGCd\n */\n gc (store, parentGCd) {\n if (!this.deleted) {\n throw error.unexpectedCase()\n }\n this.content.gc(store)\n if (parentGCd) {\n replaceStruct(store, this, new GC(this.id, this.length))\n } else {\n this.content = new ContentDeleted(this.length)\n }\n }\n\n /**\n * Transform the properties of this type to binary and write it to an\n * BinaryEncoder.\n *\n * This is called when this Item is sent to a remote peer.\n *\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.\n * @param {number} offset\n */\n write (encoder, offset) {\n const origin = offset > 0 ? createID(this.id.client, this.id.clock + offset - 1) : this.origin\n const rightOrigin = this.rightOrigin\n const parentSub = this.parentSub\n const info = (this.content.getRef() & binary.BITS5) |\n (origin === null ? 0 : binary.BIT8) | // origin is defined\n (rightOrigin === null ? 0 : binary.BIT7) | // right origin is defined\n (parentSub === null ? 0 : binary.BIT6) // parentSub is non-null\n encoder.writeInfo(info)\n if (origin !== null) {\n encoder.writeLeftID(origin)\n }\n if (rightOrigin !== null) {\n encoder.writeRightID(rightOrigin)\n }\n if (origin === null && rightOrigin === null) {\n const parent = /** @type {AbstractType<any>} */ (this.parent)\n if (parent._item !== undefined) {\n const parentItem = parent._item\n if (parentItem === null) {\n // parent type on y._map\n // find the correct key\n const ykey = findRootTypeKey(parent)\n encoder.writeParentInfo(true) // write parentYKey\n encoder.writeString(ykey)\n } else {\n encoder.writeParentInfo(false) // write parent id\n encoder.writeLeftID(parentItem.id)\n }\n } else if (parent.constructor === String) { // this edge case was added by differential updates\n encoder.writeParentInfo(true) // write parentYKey\n encoder.writeString(parent)\n } else if (parent.constructor === ID) {\n encoder.writeParentInfo(false) // write parent id\n encoder.writeLeftID(parent)\n } else {\n error.unexpectedCase()\n }\n if (parentSub !== null) {\n encoder.writeString(parentSub)\n }\n }\n this.content.write(encoder, offset)\n }\n}\n\n/**\n * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder\n * @param {number} info\n */\nexport const readItemContent = (decoder, info) => contentRefs[info & binary.BITS5](decoder)\n\n/**\n * A lookup map for reading Item content.\n *\n * @type {Array<function(UpdateDecoderV1 | UpdateDecoderV2):AbstractContent>}\n */\nexport const contentRefs = [\n () => { error.unexpectedCase() }, // GC is not ItemContent\n readContentDeleted, // 1\n readContentJSON, // 2\n readContentBinary, // 3\n readContentString, // 4\n readContentEmbed, // 5\n readContentFormat, // 6\n readContentType, // 7\n readContentAny, // 8\n readContentDoc, // 9\n () => { error.unexpectedCase() } // 10 - Skip is not ItemContent\n]\n\n/**\n * Do not implement this class!\n */\nexport class AbstractContent {\n /**\n * @return {number}\n */\n getLength () {\n throw error.methodUnimplemented()\n }\n\n /**\n * @return {Array<any>}\n */\n getContent () {\n throw error.methodUnimplemented()\n }\n\n /**\n * Should return false if this Item is some kind of meta information\n * (e.g. format information).\n *\n * * Whether this Item should be addressable via `yarray.get(i)`\n * * Whether this Item should be counted when computing yarray.length\n *\n * @return {boolean}\n */\n isCountable () {\n throw error.methodUnimplemented()\n }\n\n /**\n * @return {AbstractContent}\n */\n copy () {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {number} _offset\n * @return {AbstractContent}\n */\n splice (_offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {AbstractContent} _right\n * @return {boolean}\n */\n mergeWith (_right) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {Transaction} _transaction\n * @param {Item} _item\n */\n integrate (_transaction, _item) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {Transaction} _transaction\n */\n delete (_transaction) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {StructStore} _store\n */\n gc (_store) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} _encoder\n * @param {number} _offset\n */\n write (_encoder, _offset) {\n throw error.methodUnimplemented()\n }\n\n /**\n * @return {number}\n */\n getRef () {\n throw error.methodUnimplemented()\n }\n}\n","import {\n AbstractStruct,\n UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, ID // eslint-disable-line\n} from '../internals.js'\nimport * as error from 'lib0/error'\nimport * as encoding from 'lib0/encoding'\n\nexport const structSkipRefNumber = 10\n\n/**\n * @private\n */\nexport class Skip extends AbstractStruct {\n get deleted () {\n return true\n }\n\n delete () {}\n\n /**\n * @param {Skip} right\n * @return {boolean}\n */\n mergeWith (right) {\n if (this.constructor !== right.constructor) {\n return false\n }\n this.length += right.length\n return true\n }\n\n /**\n * @param {Transaction} transaction\n * @param {number} offset\n */\n integrate (transaction, offset) {\n // skip structs cannot be integrated\n error.unexpectedCase()\n }\n\n /**\n * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder\n * @param {number} offset\n */\n write (encoder, offset) {\n encoder.writeInfo(structSkipRefNumber)\n // write as VarUint because Skips can't make use of predictable length-encoding\n encoding.writeVarUint(encoder.restEncoder, this.length - offset)\n }\n\n /**\n * @param {Transaction} transaction\n * @param {StructStore} store\n * @return {null | number}\n */\n getMissing (transaction, store) {\n return null\n }\n}\n","/** eslint-env browser */\n\nexport {\n Doc,\n Transaction,\n YArray as Array,\n YMap as Map,\n YText as Text,\n YXmlText as XmlText,\n YXmlHook as XmlHook,\n YXmlElement as XmlElement,\n YXmlFragment as XmlFragment,\n YXmlEvent,\n YMapEvent,\n YArrayEvent,\n YTextEvent,\n YEvent,\n Item,\n AbstractStruct,\n GC,\n Skip,\n ContentBinary,\n ContentDeleted,\n ContentDoc,\n ContentEmbed,\n ContentFormat,\n ContentJSON,\n ContentAny,\n ContentString,\n ContentType,\n AbstractType,\n getTypeChildren,\n createRelativePositionFromTypeIndex,\n createRelativePositionFromJSON,\n createAbsolutePositionFromRelativePosition,\n compareRelativePositions,\n AbsolutePosition,\n RelativePosition,\n ID,\n createID,\n compareIDs,\n getState,\n Snapshot,\n createSnapshot,\n createDeleteSet,\n createDeleteSetFromStructStore,\n cleanupYTextFormatting,\n snapshot,\n emptySnapshot,\n findRootTypeKey,\n findIndexSS,\n getItem,\n getItemCleanStart,\n getItemCleanEnd,\n typeListToArraySnapshot,\n typeMapGetSnapshot,\n typeMapGetAllSnapshot,\n createDocFromSnapshot,\n iterateDeletedStructs,\n applyUpdate,\n applyUpdateV2,\n readUpdate,\n readUpdateV2,\n encodeStateAsUpdate,\n encodeStateAsUpdateV2,\n encodeStateVector,\n UndoManager,\n decodeSnapshot,\n encodeSnapshot,\n decodeSnapshotV2,\n encodeSnapshotV2,\n decodeStateVector,\n logUpdate,\n logUpdateV2,\n decodeUpdate,\n decodeUpdateV2,\n relativePositionToJSON,\n isDeleted,\n isParentOf,\n equalSnapshots,\n PermanentUserData, // @TODO experimental\n tryGc,\n transact,\n AbstractConnector,\n logType,\n mergeUpdates,\n mergeUpdatesV2,\n parseUpdateMeta,\n parseUpdateMetaV2,\n encodeStateVectorFromUpdate,\n encodeStateVectorFromUpdateV2,\n encodeRelativePosition,\n decodeRelativePosition,\n diffUpdate,\n diffUpdateV2,\n convertUpdateFormatV1ToV2,\n convertUpdateFormatV2ToV1,\n obfuscateUpdate,\n obfuscateUpdateV2,\n UpdateEncoderV1,\n UpdateEncoderV2,\n UpdateDecoderV1,\n UpdateDecoderV2,\n equalDeleteSets,\n mergeDeleteSets,\n snapshotContainsUpdate\n} from './internals.js'\n\nconst glo = /** @type {any} */ (typeof globalThis !== 'undefined'\n ? globalThis\n : typeof window !== 'undefined'\n ? window\n // @ts-ignore\n : typeof global !== 'undefined' ? global : {})\n\nconst importIdentifier = '__ $YJS$ __'\n\nif (glo[importIdentifier] === true) {\n /**\n * Dear reader of this message. Please take this seriously.\n *\n * If you see this message, make sure that you only import one version of Yjs. In many cases,\n * your package manager installs two versions of Yjs that are used by different packages within your project.\n * Another reason for this message is that some parts of your project use the commonjs version of Yjs\n * and others use the EcmaScript version of Yjs.\n *\n * This often leads to issues that are hard to debug. We often need to perform constructor checks,\n * e.g. `struct instanceof GC`. If you imported different versions of Yjs, it is impossible for us to\n * do the constructor checks anymore - which might break the CRDT algorithm.\n *\n * https://github.com/yjs/yjs/issues/438\n */\n console.error('Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438')\n}\nglo[importIdentifier] = true\n","export const isString = (value: unknown): value is string => {\n return typeof value === \"string\";\n};\n\nexport const isMentionNodeAttributeId = (\n value: unknown\n): value is `in_${string}` => {\n return isString(value) && value.startsWith(\"in_\");\n};\n\nexport const exists = <T>(input: null | undefined | T): input is T => {\n return input !== null && input !== undefined;\n};\n","import type {\n Awaitable,\n BaseUserMeta,\n DGI,\n DU,\n ResolveGroupsInfoArgs,\n ResolveUsersArgs,\n} from \"@liveblocks/core\";\nimport { Promise_withResolvers, warnOnce } from \"@liveblocks/core\";\n\n/**\n * Utility to get the resolved result coming from a batch resolver for a given ID.\n */\nexport function getResolvedForId<T>(\n id: string,\n ids: string[],\n results: T[] | undefined\n): T | undefined {\n const index = ids.indexOf(id);\n\n return results?.[index];\n}\n\n/**\n * Batch calls to a resolver callback (which expects an array of IDs\n * and returns an array of results) into a single call.\n */\nexport class BatchResolver<T> {\n private ids = new Set<string>();\n private results = new Map<string, T | undefined>();\n private isResolved = false;\n private promise: Promise<void>;\n private resolvePromise: () => void;\n private missingCallbackWarning: string;\n private callback?: (\n ids: string[]\n ) => Awaitable<(T | undefined)[] | undefined>;\n\n constructor(\n callback:\n | ((ids: string[]) => Awaitable<(T | undefined)[] | undefined>)\n | undefined,\n missingCallbackWarning: string\n ) {\n this.callback = callback;\n\n const { promise, resolve } = Promise_withResolvers<void>();\n this.promise = promise;\n this.resolvePromise = resolve;\n this.missingCallbackWarning = missingCallbackWarning;\n }\n\n /**\n * Add IDs to the batch and return a promise that resolves when the entire batch is resolved.\n * It can't be called after the batch is resolved.\n */\n async get(ids: string[]): Promise<(T | undefined)[] | undefined> {\n if (this.isResolved) {\n throw new Error(\"Batch has already been resolved.\");\n }\n\n ids.forEach((id) => this.ids.add(id));\n\n // Wait for the batch to be resolved\n await this.promise;\n\n return ids.map((id) => this.results.get(id));\n }\n\n #resolveBatch() {\n this.isResolved = true;\n this.resolvePromise();\n }\n\n /**\n * Resolve all the IDs in the batch.\n * It can only be called once.\n */\n async resolve(): Promise<void> {\n if (this.isResolved) {\n throw new Error(\"Batch has already been resolved.\");\n }\n\n if (!this.callback) {\n // Warn about the missing callback and resolve the batch early\n warnOnce(this.missingCallbackWarning);\n this.#resolveBatch();\n\n return;\n }\n\n const ids = Array.from(this.ids);\n\n // Call the callback once with all IDs\n try {\n const results = this.callback ? await this.callback(ids) : undefined;\n\n if (results !== undefined) {\n if (!Array.isArray(results)) {\n throw new Error(\"Callback must return an array.\");\n } else if (ids.length !== results.length) {\n throw new Error(\n `Callback must return an array of the same length as the number of provided items. Expected ${ids.length}, but got ${results.length}.`\n );\n }\n }\n\n ids.forEach((id, index) => {\n this.results.set(id, results?.[index]);\n });\n } catch (error) {\n // Still mark as resolved to prevent reuse\n this.#resolveBatch();\n\n throw error;\n }\n\n this.#resolveBatch();\n }\n}\n\nexport function createBatchUsersResolver<U extends BaseUserMeta = DU>({\n resolveUsers,\n callerName,\n}: {\n resolveUsers?: (\n args: ResolveUsersArgs\n ) => Awaitable<(U[\"info\"] | undefined)[] | undefined>;\n callerName: string;\n}): BatchResolver<U[\"info\"]> {\n return new BatchResolver<U[\"info\"]>(\n resolveUsers ? (userIds) => resolveUsers({ userIds }) : undefined,\n `Set \"resolveUsers\" in \"${callerName}\" to specify users info`\n );\n}\n\nexport function createBatchGroupsInfoResolver({\n resolveGroupsInfo,\n callerName,\n}: {\n resolveGroupsInfo?: (\n args: ResolveGroupsInfoArgs\n ) => Awaitable<(DGI | undefined)[] | undefined>;\n callerName: string;\n}): BatchResolver<DGI> {\n return new BatchResolver<DGI>(\n resolveGroupsInfo\n ? (groupIds) => resolveGroupsInfo({ groupIds })\n : undefined,\n `Set \"resolveGroupsInfo\" in \"${callerName}\" to specify groups info`\n );\n}\n","import type { Properties } from \"csstype\";\n\n/**\n * CSS properties object.\n * Type alias for DX purposes.\n *\n */\nexport type CSSProperties = Properties;\n\n/**\n * Vendors\n */\nconst VENDORS_PREFIXES = new RegExp(/^(webkit|moz|ms|o)-/);\n\n/**\n * CSS properties which accept numbers but are not in units of \"px\".\n * Based on: https://github.com/facebook/react/blob/bfe91fbecf183f85fc1c4f909e12a6833a247319/packages/react-dom-bindings/src/shared/isUnitlessNumber.js\n */\nconst UNITLESS_PROPERTIES = [\n \"animationIterationCount\",\n \"aspectRatio\",\n \"borderImageOutset\",\n \"borderImageSlice\",\n \"borderImageWidth\",\n \"boxFlex\",\n \"boxFlexGroup\",\n \"boxOrdinalGroup\",\n \"columnCount\",\n \"columns\",\n \"flex\",\n \"flexGrow\",\n \"flexPositive\",\n \"flexShrink\",\n \"flexNegative\",\n \"flexOrder\",\n \"gridArea\",\n \"gridRow\",\n \"gridRowEnd\",\n \"gridRowSpan\",\n \"gridRowStart\",\n \"gridColumn\",\n \"gridColumnEnd\",\n \"gridColumnSpan\",\n \"gridColumnStart\",\n \"fontWeight\",\n \"lineClamp\",\n \"lineHeight\",\n \"opacity\",\n \"order\",\n \"orphans\",\n \"scale\",\n \"tabSize\",\n \"widows\",\n \"zIndex\",\n \"zoom\",\n \"fillOpacity\",\n \"floodOpacity\",\n \"stopOpacity\",\n \"strokeDasharray\",\n \"strokeDashoffset\",\n \"strokeMiterlimit\",\n \"strokeOpacity\",\n \"strokeWidth\",\n \"MozAnimationIterationCount\",\n \"MozBoxFlex\",\n \"MozBoxFlexGroup\",\n \"MozLineClamp\",\n \"msAnimationIterationCount\",\n \"msFlex\",\n \"msZoom\",\n \"msFlexPositive\",\n \"msGridColumns\",\n \"msGridRows\",\n \"WebkitAnimationIterationCount\",\n \"WebkitBoxFlex\",\n \"WebKitBoxFlexGroup\",\n \"WebkitBoxOrdinalGroup\",\n \"WebkitColumnCount\",\n \"WebkitColumns\",\n \"WebkitFlex\",\n \"WebkitFlexGrow\",\n \"WebkitFlexPositive\",\n \"WebkitFlexShrink\",\n \"WebkitLineClamp\",\n];\n\n/**\n * Convert a `CSSProperties` style object into a inline CSS string.\n */\nexport function toInlineCSSString(styles: CSSProperties): string {\n const entries = Object.entries(styles);\n const inline = entries\n .map(([key, value]): string | null => {\n // Return an empty string if `value` is not acceptable\n if (\n value === null ||\n typeof value === \"boolean\" ||\n value === \"\" ||\n typeof value === \"undefined\"\n ) {\n return \"\";\n }\n\n // Convert key from camelCase to kebab-case\n let property = key.replace(/([A-Z])/g, \"-$1\").toLowerCase();\n\n // Manage vendors prefixes\n if (VENDORS_PREFIXES.test(property)) {\n property = `-${property}`;\n }\n\n // Add `px` if needed for properties which aren't unitless\n if (typeof value === \"number\" && !UNITLESS_PROPERTIES.includes(key)) {\n return `${property}:${value}px;`;\n }\n\n return `${property}:${String(value).trim()};`;\n })\n .filter(Boolean)\n .join(\"\");\n\n return inline;\n}\n","import { assertNever, type MentionData } from \"@liveblocks/core\";\nimport { yXmlFragmentToProsemirrorJSON } from \"y-prosemirror\";\nimport * as Y from \"yjs\";\n\nimport { isMentionNodeAttributeId } from \"./lib/utils\";\n\nexport interface SerializedTiptapBaseNode {\n type: string;\n content?: Array<SerializedTiptapBaseNode>;\n}\n\nexport interface SerializedTiptapBaseMark {\n type: string;\n attrs: Record<string, string>;\n}\n\nexport interface SerializedTiptapBoldMark extends SerializedTiptapBaseMark {\n type: \"bold\";\n}\n\nexport interface SerializedTiptapItalicMark extends SerializedTiptapBaseMark {\n type: \"italic\";\n}\n\nexport interface SerializedTiptapStrikethroughMark\n extends SerializedTiptapBaseMark {\n type: \"strike\";\n}\n\nexport interface SerializedTiptapCodeMark extends SerializedTiptapBaseMark {\n type: \"code\";\n}\n\nexport interface SerializedTiptapCommentMark extends SerializedTiptapBaseMark {\n type: \"liveblocksCommentMark\";\n attrs: {\n threadId: string;\n };\n}\n\nexport type SerializedTiptapMark =\n | SerializedTiptapBoldMark\n | SerializedTiptapItalicMark\n | SerializedTiptapStrikethroughMark\n | SerializedTiptapCodeMark\n | SerializedTiptapCommentMark;\n\nexport type SerializedTiptapMarkType = SerializedTiptapMark[\"type\"];\n\nexport interface SerializedTiptapTextNode extends SerializedTiptapBaseNode {\n type: \"text\";\n text: string;\n marks?: Array<SerializedTiptapMark>;\n}\n\nexport interface SerializedTiptapMentionNode extends SerializedTiptapBaseNode {\n type: \"liveblocksMention\";\n attrs: {\n id: string;\n notificationId: string;\n };\n}\n\nexport interface SerializedTiptapGroupMentionNode\n extends SerializedTiptapBaseNode {\n type: \"liveblocksGroupMention\";\n attrs: {\n id: string;\n notificationId: string;\n userIds: string | undefined;\n };\n}\n\nexport interface SerializedTiptapEmptyParagraphNode\n extends SerializedTiptapBaseNode {\n type: \"paragraph\";\n content?: undefined;\n}\n\n/**\n * Hard breaks are created by using keys like\n * `shift+enter` or `mod+enter`\n */\nexport interface SerializedTiptapHardBreakNode\n extends SerializedTiptapBaseNode {\n type: \"hardBreak\";\n content?: undefined;\n}\n\nexport interface SerializedTiptapParagraphNode\n extends SerializedTiptapBaseNode {\n type: \"paragraph\";\n content: Array<SerializedTiptapNode>;\n}\n\nexport type SerializedTiptapNode =\n | SerializedTiptapParagraphNode\n | SerializedTiptapEmptyParagraphNode\n | SerializedTiptapHardBreakNode\n | SerializedTiptapMentionNode\n | SerializedTiptapGroupMentionNode\n | SerializedTiptapTextNode;\n\nexport type SerializedTiptapRootNodeContent = Array<\n Readonly<SerializedTiptapNode>\n>;\n\nexport interface SerializedTiptapRootNode\n extends Readonly<SerializedTiptapBaseNode> {\n readonly type: \"doc\";\n readonly content: SerializedTiptapRootNodeContent;\n}\n\n/**\n * Convert a document as binaries to\n * serialized tiptap state\n */\nexport function getSerializedTiptapState({\n buffer,\n key,\n}: {\n buffer: ArrayBuffer;\n key: string;\n}): SerializedTiptapRootNode {\n const update = new Uint8Array(buffer);\n // Construct a Y.js document from the binary update\n const document = new Y.Doc();\n Y.applyUpdate(document, update);\n\n // Convert the Y.js document to a serializable tiptap state\n const fragment = document.getXmlFragment(key);\n const state = yXmlFragmentToProsemirrorJSON(fragment);\n\n // Destroy the Y.js document after the conversion\n document.destroy();\n\n // Not ideal but pragmatic enough as the typing is based\n // on real data we provide\n return state as SerializedTiptapRootNode;\n}\n\nconst isSerializedEmptyParagraphNode = (\n node: SerializedTiptapNode\n): node is SerializedTiptapEmptyParagraphNode => {\n return node.type === \"paragraph\" && typeof node.content === \"undefined\";\n};\n\nconst isSerializedHardBreakNode = (\n node: SerializedTiptapNode\n): node is SerializedTiptapHardBreakNode => {\n return node.type === \"hardBreak\" && typeof node.content === \"undefined\";\n};\n\nconst isSerializedTextNode = (\n node: SerializedTiptapNode\n): node is SerializedTiptapTextNode => {\n return node.type === \"text\";\n};\n\nexport const isSerializedMentionNode = (\n node: SerializedTiptapNode\n): node is SerializedTiptapMentionNode => {\n return (\n node.type === \"liveblocksMention\" &&\n isMentionNodeAttributeId(node.attrs.notificationId)\n );\n};\n\nexport const isSerializedGroupMentionNode = (\n node: SerializedTiptapNode\n): node is SerializedTiptapGroupMentionNode => {\n return (\n node.type === \"liveblocksGroupMention\" &&\n isMentionNodeAttributeId(node.attrs.notificationId)\n );\n};\n\nconst isSerializedParagraphNode = (\n node: SerializedTiptapNode\n): node is SerializedTiptapParagraphNode => {\n return node.type === \"paragraph\" && typeof node.content !== \"undefined\";\n};\n\n/**\n * Internal type helper when flattening nodes.\n * It helps to better extract mention node with context by marking\n * start and ends of paragraph and by handling specific use cases such as\n * using twice the `enter` key which will create an empty paragraph\n * at the first `enter`:\n *\n * \"\n * Hey @charlie what's up?\n * _enter_once_\n * _enter_twice_\n * \"\n */\ninterface FlattenedTiptapParagraphNodeMarker {\n type: \"paragraph-marker\";\n marker: \"start\" | \"end\";\n}\n\nconst isFlattenedTiptapParagraphNodeMarker = (\n node: SerializedTiptapNode | FlattenedTiptapParagraphNodeMarker\n): node is FlattenedTiptapParagraphNodeMarker => {\n return node.type === \"paragraph-marker\";\n};\n\n/** @internal */\ntype FlattenedSerializedTiptapNodes = Array<\n SerializedTiptapNode | FlattenedTiptapParagraphNodeMarker\n>;\n\n/** @internal - export for testing only */\nexport const flattenTiptapTree = (\n nodes: SerializedTiptapNode[]\n): FlattenedSerializedTiptapNodes => {\n let flattenNodes: FlattenedSerializedTiptapNodes = [];\n\n for (const node of nodes) {\n if (\n isSerializedEmptyParagraphNode(node) ||\n isSerializedHardBreakNode(node) ||\n isSerializedTextNode(node) ||\n isSerializedMentionNode(node) ||\n isSerializedGroupMentionNode(node)\n ) {\n flattenNodes = [...flattenNodes, node];\n } else if (isSerializedParagraphNode(node)) {\n flattenNodes = [\n ...flattenNodes,\n {\n type: \"paragraph-marker\",\n marker: \"start\",\n },\n ...flattenTiptapTree(node.content),\n {\n type: \"paragraph-marker\",\n marker: \"end\",\n },\n ];\n }\n }\n\n return flattenNodes;\n};\n\n/**\n * Tiptap Mention Node with context\n */\nexport type TiptapMentionNodeWithContext = {\n before: SerializedTiptapNode[];\n after: SerializedTiptapNode[];\n mention: SerializedTiptapMentionNode | SerializedTiptapGroupMentionNode;\n};\n\n/**\n * Find a Tiptap mention\n * and returns it with contextual surrounding text\n */\nexport function findTiptapMentionNodeWithContext({\n root,\n textMentionId,\n}: {\n root: SerializedTiptapRootNode;\n textMentionId: string;\n}): TiptapMentionNodeWithContext | null {\n const nodes = flattenTiptapTree(root.content);\n\n // Find mention node\n let mentionNodeIndex = -1;\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i]!;\n\n if (\n !isFlattenedTiptapParagraphNodeMarker(node) &&\n (isSerializedMentionNode(node) || isSerializedGroupMentionNode(node)) &&\n node.attrs.notificationId === textMentionId\n ) {\n mentionNodeIndex = i;\n break;\n }\n }\n\n // No mention node found\n if (mentionNodeIndex === -1) {\n return null;\n }\n\n // Collect nodes before and after\n const mentionNode = nodes[mentionNodeIndex] as\n | SerializedTiptapMentionNode\n | SerializedTiptapGroupMentionNode;\n\n // Apply surrounding text guesses\n // For now let's stay simple just stop at nearest line break or paragraph\n const beforeNodes: SerializedTiptapNode[] = [];\n const afterNodes: SerializedTiptapNode[] = [];\n\n // Nodes before mention node\n for (let i = mentionNodeIndex - 1; i >= 0; i--) {\n const node = nodes[i]!;\n\n // Stop if nodes are markers, hard breaks or empty paragraph\n if (\n isFlattenedTiptapParagraphNodeMarker(node) ||\n isSerializedEmptyParagraphNode(node) ||\n isSerializedHardBreakNode(node)\n ) {\n break;\n }\n\n beforeNodes.unshift(node);\n }\n\n // Nodes after mention node\n for (let i = mentionNodeIndex + 1; i < nodes.length; i++) {\n const node = nodes[i]!;\n\n // Stop if nodes are markers, hard breaks or empty paragraph\n if (\n isFlattenedTiptapParagraphNodeMarker(node) ||\n isSerializedEmptyParagraphNode(node) ||\n isSerializedHardBreakNode(node)\n ) {\n break;\n }\n\n afterNodes.push(node);\n }\n\n return {\n before: beforeNodes,\n after: afterNodes,\n mention: mentionNode,\n };\n}\n\nfunction deserializeGroupUserIds(\n userIds: string | undefined\n): string[] | undefined {\n if (typeof userIds !== \"string\") {\n return undefined;\n }\n\n try {\n const parsedUserIds = JSON.parse(userIds) as string[];\n\n if (Array.isArray(parsedUserIds)) {\n return parsedUserIds;\n }\n\n return undefined;\n } catch {\n return undefined;\n }\n}\n\nexport function getMentionDataFromTiptapNode(\n node: SerializedTiptapMentionNode | SerializedTiptapGroupMentionNode\n): MentionData {\n if (isSerializedMentionNode(node)) {\n return {\n kind: \"user\",\n id: node.attrs.id,\n };\n } else if (isSerializedGroupMentionNode(node)) {\n return {\n kind: \"group\",\n id: node.attrs.id,\n userIds: deserializeGroupUserIds(node.attrs.userIds),\n };\n }\n\n assertNever(node, \"Unknown mention kind\");\n}\n","/**\n * @module bindings/prosemirror\n */\n\nimport { createMutex } from 'lib0/mutex'\nimport * as PModel from 'prosemirror-model'\nimport { AllSelection, Plugin, TextSelection, NodeSelection } from \"prosemirror-state\"; // eslint-disable-line\nimport * as math from 'lib0/math'\nimport * as object from 'lib0/object'\nimport * as set from 'lib0/set'\nimport { simpleDiff } from 'lib0/diff'\nimport * as error from 'lib0/error'\nimport { ySyncPluginKey, yUndoPluginKey } from './keys.js'\nimport * as Y from 'yjs'\nimport {\n absolutePositionToRelativePosition,\n relativePositionToAbsolutePosition\n} from '../lib.js'\nimport * as random from 'lib0/random'\nimport * as environment from 'lib0/environment'\nimport * as dom from 'lib0/dom'\nimport * as eventloop from 'lib0/eventloop'\nimport * as map from 'lib0/map'\nimport * as utils from '../utils.js'\n\n/**\n * @typedef {Object} BindingMetadata\n * @property {ProsemirrorMapping} BindingMetadata.mapping\n * @property {Map<import('prosemirror-model').MarkType, boolean>} BindingMetadata.isOMark - is overlapping mark\n */\n\n/**\n * @return {BindingMetadata}\n */\nexport const createEmptyMeta = () => ({\n mapping: new Map(),\n isOMark: new Map()\n})\n\n/**\n * @param {Y.Item} item\n * @param {Y.Snapshot} [snapshot]\n */\nexport const isVisible = (item, snapshot) =>\n snapshot === undefined\n ? !item.deleted\n : (snapshot.sv.has(item.id.client) && /** @type {number} */\n (snapshot.sv.get(item.id.client)) > item.id.clock &&\n !Y.isDeleted(snapshot.ds, item.id))\n\n/**\n * Either a node if type is YXmlElement or an Array of text nodes if YXmlText\n * @typedef {Map<Y.AbstractType<any>, PModel.Node | Array<PModel.Node>>} ProsemirrorMapping\n */\n\n/**\n * @typedef {Object} ColorDef\n * @property {string} ColorDef.light\n * @property {string} ColorDef.dark\n */\n\n/**\n * @typedef {Object} YSyncOpts\n * @property {Array<ColorDef>} [YSyncOpts.colors]\n * @property {Map<string,ColorDef>} [YSyncOpts.colorMapping]\n * @property {Y.PermanentUserData|null} [YSyncOpts.permanentUserData]\n * @property {ProsemirrorMapping} [YSyncOpts.mapping]\n * @property {function} [YSyncOpts.onFirstRender] Fired when the content from Yjs is initially rendered to ProseMirror\n */\n\n/**\n * @type {Array<ColorDef>}\n */\nconst defaultColors = [{ light: '#ecd44433', dark: '#ecd444' }]\n\n/**\n * @param {Map<string,ColorDef>} colorMapping\n * @param {Array<ColorDef>} colors\n * @param {string} user\n * @return {ColorDef}\n */\nconst getUserColor = (colorMapping, colors, user) => {\n // @todo do not hit the same color twice if possible\n if (!colorMapping.has(user)) {\n if (colorMapping.size < colors.length) {\n const usedColors = set.create()\n colorMapping.forEach((color) => usedColors.add(color))\n colors = colors.filter((color) => !usedColors.has(color))\n }\n colorMapping.set(user, random.oneOf(colors))\n }\n return /** @type {ColorDef} */ (colorMapping.get(user))\n}\n\n/**\n * This plugin listens to changes in prosemirror view and keeps yXmlState and view in sync.\n *\n * This plugin also keeps references to the type and the shared document so other plugins can access it.\n * @param {Y.XmlFragment} yXmlFragment\n * @param {YSyncOpts} opts\n * @return {any} Returns a prosemirror plugin that binds to this type\n */\nexport const ySyncPlugin = (yXmlFragment, {\n colors = defaultColors,\n colorMapping = new Map(),\n permanentUserData = null,\n onFirstRender = () => {},\n mapping\n} = {}) => {\n let initialContentChanged = false\n const binding = new ProsemirrorBinding(yXmlFragment, mapping)\n const plugin = new Plugin({\n props: {\n editable: (state) => {\n const syncState = ySyncPluginKey.getState(state)\n return syncState.snapshot == null && syncState.prevSnapshot == null\n }\n },\n key: ySyncPluginKey,\n state: {\n /**\n * @returns {any}\n */\n init: (_initargs, _state) => {\n return {\n type: yXmlFragment,\n doc: yXmlFragment.doc,\n binding,\n snapshot: null,\n prevSnapshot: null,\n isChangeOrigin: false,\n isUndoRedoOperation: false,\n addToHistory: true,\n colors,\n colorMapping,\n permanentUserData\n }\n },\n apply: (tr, pluginState) => {\n const change = tr.getMeta(ySyncPluginKey)\n if (change !== undefined) {\n pluginState = Object.assign({}, pluginState)\n for (const key in change) {\n pluginState[key] = change[key]\n }\n }\n pluginState.addToHistory = tr.getMeta('addToHistory') !== false\n // always set isChangeOrigin. If undefined, this is not change origin.\n pluginState.isChangeOrigin = change !== undefined &&\n !!change.isChangeOrigin\n pluginState.isUndoRedoOperation = change !== undefined && !!change.isChangeOrigin && !!change.isUndoRedoOperation\n if (binding.prosemirrorView !== null) {\n if (\n change !== undefined &&\n (change.snapshot != null || change.prevSnapshot != null)\n ) {\n // snapshot changed, rerender next\n eventloop.timeout(0, () => {\n if (binding.prosemirrorView == null) {\n return\n }\n if (change.restore == null) {\n binding._renderSnapshot(\n change.snapshot,\n change.prevSnapshot,\n pluginState\n )\n } else {\n binding._renderSnapshot(\n change.snapshot,\n change.snapshot,\n pluginState\n )\n // reset to current prosemirror state\n delete pluginState.restore\n delete pluginState.snapshot\n delete pluginState.prevSnapshot\n binding.mux(() => {\n binding._prosemirrorChanged(\n binding.prosemirrorView.state.doc\n )\n })\n }\n })\n }\n }\n return pluginState\n }\n },\n view: (view) => {\n binding.initView(view)\n if (mapping == null) {\n // force rerender to update the bindings mapping\n binding._forceRerender()\n }\n onFirstRender()\n return {\n update: () => {\n const pluginState = plugin.getState(view.state)\n if (\n pluginState.snapshot == null && pluginState.prevSnapshot == null\n ) {\n if (\n // If the content doesn't change initially, we don't render anything to Yjs\n // If the content was cleared by a user action, we want to catch the change and\n // represent it in Yjs\n initialContentChanged ||\n view.state.doc.content.findDiffStart(\n view.state.doc.type.createAndFill().content\n ) !== null\n ) {\n initialContentChanged = true\n if (\n pluginState.addToHistory === false &&\n !pluginState.isChangeOrigin\n ) {\n const yUndoPluginState = yUndoPluginKey.getState(view.state)\n /**\n * @type {Y.UndoManager}\n */\n const um = yUndoPluginState && yUndoPluginState.undoManager\n if (um) {\n um.stopCapturing()\n }\n }\n binding.mux(() => {\n /** @type {Y.Doc} */ (pluginState.doc).transact((tr) => {\n tr.meta.set('addToHistory', pluginState.addToHistory)\n binding._prosemirrorChanged(view.state.doc)\n }, ySyncPluginKey)\n })\n }\n }\n },\n destroy: () => {\n binding.destroy()\n }\n }\n }\n })\n return plugin\n}\n\n/**\n * @param {import('prosemirror-state').Transaction} tr\n * @param {ReturnType<typeof getRelativeSelection>} relSel\n * @param {ProsemirrorBinding} binding\n */\nconst restoreRelativeSelection = (tr, relSel, binding) => {\n if (relSel !== null && relSel.anchor !== null && relSel.head !== null) {\n if (relSel.type === 'all') {\n tr.setSelection(new AllSelection(tr.doc))\n } else if (relSel.type === 'node') {\n const anchor = relativePositionToAbsolutePosition(\n binding.doc,\n binding.type,\n relSel.anchor,\n binding.mapping\n )\n tr.setSelection(NodeSelection.create(tr.doc, anchor))\n } else {\n const anchor = relativePositionToAbsolutePosition(\n binding.doc,\n binding.type,\n relSel.anchor,\n binding.mapping\n )\n const head = relativePositionToAbsolutePosition(\n binding.doc,\n binding.type,\n relSel.head,\n binding.mapping\n )\n if (anchor !== null && head !== null) {\n const sel = TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head))\n tr.setSelection(sel)\n }\n }\n }\n}\n\n/**\n * @param {ProsemirrorBinding} pmbinding\n * @param {import('prosemirror-state').EditorState} state\n */\nexport const getRelativeSelection = (pmbinding, state) => ({\n type: /** @type {any} */ (state.selection).jsonID,\n anchor: absolutePositionToRelativePosition(\n state.selection.anchor,\n pmbinding.type,\n pmbinding.mapping\n ),\n head: absolutePositionToRelativePosition(\n state.selection.head,\n pmbinding.type,\n pmbinding.mapping\n )\n})\n\n/**\n * Binding for prosemirror.\n *\n * @protected\n */\nexport class ProsemirrorBinding {\n /**\n * @param {Y.XmlFragment} yXmlFragment The bind source\n * @param {ProsemirrorMapping} mapping\n */\n constructor (yXmlFragment, mapping = new Map()) {\n this.type = yXmlFragment\n /**\n * this will be set once the view is created\n * @type {any}\n */\n this.prosemirrorView = null\n this.mux = createMutex()\n this.mapping = mapping\n /**\n * Is overlapping mark - i.e. mark does not exclude itself.\n *\n * @type {Map<import('prosemirror-model').MarkType, boolean>}\n */\n this.isOMark = new Map()\n this._observeFunction = this._typeChanged.bind(this)\n /**\n * @type {Y.Doc}\n */\n // @ts-ignore\n this.doc = yXmlFragment.doc\n /**\n * current selection as relative positions in the Yjs model\n */\n this.beforeTransactionSelection = null\n this.beforeAllTransactions = () => {\n if (this.beforeTransactionSelection === null && this.prosemirrorView != null) {\n this.beforeTransactionSelection = getRelativeSelection(\n this,\n this.prosemirrorView.state\n )\n }\n }\n this.afterAllTransactions = () => {\n this.beforeTransactionSelection = null\n }\n this._domSelectionInView = null\n }\n\n /**\n * Create a transaction for changing the prosemirror state.\n *\n * @returns\n */\n get _tr () {\n return this.prosemirrorView.state.tr.setMeta('addToHistory', false)\n }\n\n _isLocalCursorInView () {\n if (!this.prosemirrorView.hasFocus()) return false\n if (environment.isBrowser && this._domSelectionInView === null) {\n // Calculate the domSelectionInView and clear by next tick after all events are finished\n eventloop.timeout(0, () => {\n this._domSelectionInView = null\n })\n this._domSelectionInView = this._isDomSelectionInView()\n }\n return this._domSelectionInView\n }\n\n _isDomSelectionInView () {\n const selection = this.prosemirrorView._root.getSelection()\n\n if (selection == null || selection.anchorNode == null) return false\n\n const range = this.prosemirrorView._root.createRange()\n range.setStart(selection.anchorNode, selection.anchorOffset)\n range.setEnd(selection.focusNode, selection.focusOffset)\n\n // This is a workaround for an edgecase where getBoundingClientRect will\n // return zero values if the selection is collapsed at the start of a newline\n // see reference here: https://stackoverflow.com/a/59780954\n const rects = range.getClientRects()\n if (rects.length === 0) {\n // probably buggy newline behavior, explicitly select the node contents\n if (range.startContainer && range.collapsed) {\n range.selectNodeContents(range.startContainer)\n }\n }\n\n const bounding = range.getBoundingClientRect()\n const documentElement = dom.doc.documentElement\n\n return bounding.bottom >= 0 && bounding.right >= 0 &&\n bounding.left <=\n (window.innerWidth || documentElement.clientWidth || 0) &&\n bounding.top <= (window.innerHeight || documentElement.clientHeight || 0)\n }\n\n /**\n * @param {Y.Snapshot} snapshot\n * @param {Y.Snapshot} prevSnapshot\n */\n renderSnapshot (snapshot, prevSnapshot) {\n if (!prevSnapshot) {\n prevSnapshot = Y.createSnapshot(Y.createDeleteSet(), new Map())\n }\n this.prosemirrorView.dispatch(\n this._tr.setMeta(ySyncPluginKey, { snapshot, prevSnapshot })\n )\n }\n\n unrenderSnapshot () {\n this.mapping.clear()\n this.mux(() => {\n const fragmentContent = this.type.toArray().map((t) =>\n createNodeFromYElement(\n /** @type {Y.XmlElement} */ (t),\n this.prosemirrorView.state.schema,\n this\n )\n ).filter((n) => n !== null)\n // @ts-ignore\n const tr = this._tr.replace(\n 0,\n this.prosemirrorView.state.doc.content.size,\n new PModel.Slice(PModel.Fragment.from(fragmentContent), 0, 0)\n )\n tr.setMeta(ySyncPluginKey, { snapshot: null, prevSnapshot: null })\n this.prosemirrorView.dispatch(tr)\n })\n }\n\n _forceRerender () {\n this.mapping.clear()\n this.mux(() => {\n // If this is a forced rerender, this might neither happen as a pm change nor within a Yjs\n // transaction. Then the \"before selection\" doesn't exist. In this case, we need to create a\n // relative position before replacing content. Fixes #126\n const sel = this.beforeTransactionSelection !== null ? null : this.prosemirrorView.state.selection\n const fragmentContent = this.type.toArray().map((t) =>\n createNodeFromYElement(\n /** @type {Y.XmlElement} */ (t),\n this.prosemirrorView.state.schema,\n this\n )\n ).filter((n) => n !== null)\n // @ts-ignore\n const tr = this._tr.replace(\n 0,\n this.prosemirrorView.state.doc.content.size,\n new PModel.Slice(PModel.Fragment.from(fragmentContent), 0, 0)\n )\n if (sel) {\n /**\n * If the Prosemirror document we just created from this.type is\n * smaller than the previous document, the selection might be\n * out of bound, which would make Prosemirror throw an error.\n */\n const clampedAnchor = math.min(math.max(sel.anchor, 0), tr.doc.content.size)\n const clampedHead = math.min(math.max(sel.head, 0), tr.doc.content.size)\n\n tr.setSelection(TextSelection.create(tr.doc, clampedAnchor, clampedHead))\n }\n this.prosemirrorView.dispatch(\n tr.setMeta(ySyncPluginKey, { isChangeOrigin: true, binding: this })\n )\n })\n }\n\n /**\n * @param {Y.Snapshot|Uint8Array} snapshot\n * @param {Y.Snapshot|Uint8Array} prevSnapshot\n * @param {Object} pluginState\n */\n _renderSnapshot (snapshot, prevSnapshot, pluginState) {\n /**\n * The document that contains the full history of this document.\n * @type {Y.Doc}\n */\n let historyDoc = this.doc\n let historyType = this.type\n if (!snapshot) {\n snapshot = Y.snapshot(this.doc)\n }\n if (snapshot instanceof Uint8Array || prevSnapshot instanceof Uint8Array) {\n if (!(snapshot instanceof Uint8Array) || !(prevSnapshot instanceof Uint8Array)) {\n // expected both snapshots to be v2 updates\n error.unexpectedCase()\n }\n historyDoc = new Y.Doc({ gc: false })\n Y.applyUpdateV2(historyDoc, prevSnapshot)\n prevSnapshot = Y.snapshot(historyDoc)\n Y.applyUpdateV2(historyDoc, snapshot)\n snapshot = Y.snapshot(historyDoc)\n if (historyType._item === null) {\n /**\n * If is a root type, we need to find the root key in the initial document\n * and use it to get the history type.\n */\n const rootKey = Array.from(this.doc.share.keys()).find(\n (key) => this.doc.share.get(key) === this.type\n )\n historyType = historyDoc.getXmlFragment(rootKey)\n } else {\n /**\n * If it is a sub type, we use the item id to find the history type.\n */\n const historyStructs =\n historyDoc.store.clients.get(historyType._item.id.client) ?? []\n const itemIndex = Y.findIndexSS(\n historyStructs,\n historyType._item.id.clock\n )\n const item = /** @type {Y.Item} */ (historyStructs[itemIndex])\n const content = /** @type {Y.ContentType} */ (item.content)\n historyType = /** @type {Y.XmlFragment} */ (content.type)\n }\n }\n // clear mapping because we are going to rerender\n this.mapping.clear()\n this.mux(() => {\n historyDoc.transact((transaction) => {\n // before rendering, we are going to sanitize ops and split deleted ops\n // if they were deleted by seperate users.\n /**\n * @type {Y.PermanentUserData}\n */\n const pud = pluginState.permanentUserData\n if (pud) {\n pud.dss.forEach((ds) => {\n Y.iterateDeletedStructs(transaction, ds, (_item) => {})\n })\n }\n /**\n * @param {'removed'|'added'} type\n * @param {Y.ID} id\n */\n const computeYChange = (type, id) => {\n const user = type === 'added'\n ? pud.getUserByClientId(id.client)\n : pud.getUserByDeletedId(id)\n return {\n user,\n type,\n color: getUserColor(\n pluginState.colorMapping,\n pluginState.colors,\n user\n )\n }\n }\n // Create document fragment and render\n const fragmentContent = Y.typeListToArraySnapshot(\n historyType,\n new Y.Snapshot(prevSnapshot.ds, snapshot.sv)\n ).map((t) => {\n if (\n !t._item.deleted || isVisible(t._item, snapshot) ||\n isVisible(t._item, prevSnapshot)\n ) {\n return createNodeFromYElement(\n t,\n this.prosemirrorView.state.schema,\n { mapping: new Map(), isOMark: new Map() },\n snapshot,\n prevSnapshot,\n computeYChange\n )\n } else {\n // No need to render elements that are not visible by either snapshot.\n // If a client adds and deletes content in the same snapshot the element is not visible by either snapshot.\n return null\n }\n }).filter((n) => n !== null)\n // @ts-ignore\n const tr = this._tr.replace(\n 0,\n this.prosemirrorView.state.doc.content.size,\n new PModel.Slice(PModel.Fragment.from(fragmentContent), 0, 0)\n )\n this.prosemirrorView.dispatch(\n tr.setMeta(ySyncPluginKey, { isChangeOrigin: true })\n )\n }, ySyncPluginKey)\n })\n }\n\n /**\n * @param {Array<Y.YEvent<any>>} events\n * @param {Y.Transaction} transaction\n */\n _typeChanged (events, transaction) {\n if (this.prosemirrorView == null) return\n const syncState = ySyncPluginKey.getState(this.prosemirrorView.state)\n if (\n events.length === 0 || syncState.snapshot != null ||\n syncState.prevSnapshot != null\n ) {\n // drop out if snapshot is active\n this.renderSnapshot(syncState.snapshot, syncState.prevSnapshot)\n return\n }\n this.mux(() => {\n /**\n * @param {any} _\n * @param {Y.AbstractType<any>} type\n */\n const delType = (_, type) => this.mapping.delete(type)\n Y.iterateDeletedStructs(\n transaction,\n transaction.deleteSet,\n (struct) => {\n if (struct.constructor === Y.Item) {\n const type = /** @type {Y.ContentType} */ (/** @type {Y.Item} */ (struct).content).type\n type && this.mapping.delete(type)\n }\n }\n )\n transaction.changed.forEach(delType)\n transaction.changedParentTypes.forEach(delType)\n const fragmentContent = this.type.toArray().map((t) =>\n createNodeIfNotExists(\n /** @type {Y.XmlElement | Y.XmlHook} */ (t),\n this.prosemirrorView.state.schema,\n this\n )\n ).filter((n) => n !== null)\n // @ts-ignore\n let tr = this._tr.replace(\n 0,\n this.prosemirrorView.state.doc.content.size,\n new PModel.Slice(PModel.Fragment.from(fragmentContent), 0, 0)\n )\n restoreRelativeSelection(tr, this.beforeTransactionSelection, this)\n tr = tr.setMeta(ySyncPluginKey, { isChangeOrigin: true, isUndoRedoOperation: transaction.origin instanceof Y.UndoManager })\n if (\n this.beforeTransactionSelection !== null && this._isLocalCursorInView()\n ) {\n tr.scrollIntoView()\n }\n this.prosemirrorView.dispatch(tr)\n })\n }\n\n /**\n * @param {import('prosemirror-model').Node} doc\n */\n _prosemirrorChanged (doc) {\n this.doc.transact(() => {\n updateYFragment(this.doc, this.type, doc, this)\n this.beforeTransactionSelection = getRelativeSelection(\n this,\n this.prosemirrorView.state\n )\n }, ySyncPluginKey)\n }\n\n /**\n * View is ready to listen to changes. Register observers.\n * @param {any} prosemirrorView\n */\n initView (prosemirrorView) {\n if (this.prosemirrorView != null) this.destroy()\n this.prosemirrorView = prosemirrorView\n this.doc.on('beforeAllTransactions', this.beforeAllTransactions)\n this.doc.on('afterAllTransactions', this.afterAllTransactions)\n this.type.observeDeep(this._observeFunction)\n }\n\n destroy () {\n if (this.prosemirrorView == null) return\n this.prosemirrorView = null\n this.type.unobserveDeep(this._observeFunction)\n this.doc.off('beforeAllTransactions', this.beforeAllTransactions)\n this.doc.off('afterAllTransactions', this.afterAllTransactions)\n }\n}\n\n/**\n * @private\n * @param {Y.XmlElement | Y.XmlHook} el\n * @param {PModel.Schema} schema\n * @param {BindingMetadata} meta\n * @param {Y.Snapshot} [snapshot]\n * @param {Y.Snapshot} [prevSnapshot]\n * @param {function('removed' | 'added', Y.ID):any} [computeYChange]\n * @return {PModel.Node | null}\n */\nconst createNodeIfNotExists = (\n el,\n schema,\n meta,\n snapshot,\n prevSnapshot,\n computeYChange\n) => {\n const node = /** @type {PModel.Node} */ (meta.mapping.get(el))\n if (node === undefined) {\n if (el instanceof Y.XmlElement) {\n return createNodeFromYElement(\n el,\n schema,\n meta,\n snapshot,\n prevSnapshot,\n computeYChange\n )\n } else {\n throw error.methodUnimplemented() // we are currently not handling hooks\n }\n }\n return node\n}\n\n/**\n * @private\n * @param {Y.XmlElement} el\n * @param {any} schema\n * @param {BindingMetadata} meta\n * @param {Y.Snapshot} [snapshot]\n * @param {Y.Snapshot} [prevSnapshot]\n * @param {function('removed' | 'added', Y.ID):any} [computeYChange]\n * @return {PModel.Node | null} Returns node if node could be created. Otherwise it deletes the yjs type and returns null\n */\nexport const createNodeFromYElement = (\n el,\n schema,\n meta,\n snapshot,\n prevSnapshot,\n computeYChange\n) => {\n const children = []\n /**\n * @param {Y.XmlElement | Y.XmlText} type\n */\n const createChildren = (type) => {\n if (type instanceof Y.XmlElement) {\n const n = createNodeIfNotExists(\n type,\n schema,\n meta,\n snapshot,\n prevSnapshot,\n computeYChange\n )\n if (n !== null) {\n children.push(n)\n }\n } else {\n // If the next ytext exists and was created by us, move the content to the current ytext.\n // This is a fix for #160 -- duplication of characters when two Y.Text exist next to each\n // other.\n const nextytext = /** @type {Y.ContentType} */ (type._item.right?.content)?.type\n if (nextytext instanceof Y.Text && !nextytext._item.deleted && nextytext._item.id.client === nextytext.doc.clientID) {\n type.applyDelta([\n { retain: type.length },\n ...nextytext.toDelta()\n ])\n nextytext.doc.transact(tr => {\n nextytext._item.delete(tr)\n })\n }\n // now create the prosemirror text nodes\n const ns = createTextNodesFromYText(\n type,\n schema,\n meta,\n snapshot,\n prevSnapshot,\n computeYChange\n )\n if (ns !== null) {\n ns.forEach((textchild) => {\n if (textchild !== null) {\n children.push(textchild)\n }\n })\n }\n }\n }\n if (snapshot === undefined || prevSnapshot === undefined) {\n el.toArray().forEach(createChildren)\n } else {\n Y.typeListToArraySnapshot(el, new Y.Snapshot(prevSnapshot.ds, snapshot.sv))\n .forEach(createChildren)\n }\n try {\n const attrs = el.getAttributes(snapshot)\n if (snapshot !== undefined) {\n if (!isVisible(/** @type {Y.Item} */ (el._item), snapshot)) {\n attrs.ychange = computeYChange\n ? computeYChange('removed', /** @type {Y.Item} */ (el._item).id)\n : { type: 'removed' }\n } else if (!isVisible(/** @type {Y.Item} */ (el._item), prevSnapshot)) {\n attrs.ychange = computeYChange\n ? computeYChange('added', /** @type {Y.Item} */ (el._item).id)\n : { type: 'added' }\n }\n }\n const node = schema.node(el.nodeName, attrs, children)\n meta.mapping.set(el, node)\n return node\n } catch (e) {\n // an error occured while creating the node. This is probably a result of a concurrent action.\n /** @type {Y.Doc} */ (el.doc).transact((transaction) => {\n /** @type {Y.Item} */ (el._item).delete(transaction)\n }, ySyncPluginKey)\n meta.mapping.delete(el)\n return null\n }\n}\n\n/**\n * @private\n * @param {Y.XmlText} text\n * @param {import('prosemirror-model').Schema} schema\n * @param {BindingMetadata} _meta\n * @param {Y.Snapshot} [snapshot]\n * @param {Y.Snapshot} [prevSnapshot]\n * @param {function('removed' | 'added', Y.ID):any} [computeYChange]\n * @return {Array<PModel.Node>|null}\n */\nconst createTextNodesFromYText = (\n text,\n schema,\n _meta,\n snapshot,\n prevSnapshot,\n computeYChange\n) => {\n const nodes = []\n const deltas = text.toDelta(snapshot, prevSnapshot, computeYChange)\n try {\n for (let i = 0; i < deltas.length; i++) {\n const delta = deltas[i]\n nodes.push(schema.text(delta.insert, attributesToMarks(delta.attributes, schema)))\n }\n } catch (e) {\n // an error occured while creating the node. This is probably a result of a concurrent action.\n /** @type {Y.Doc} */ (text.doc).transact((transaction) => {\n /** @type {Y.Item} */ (text._item).delete(transaction)\n }, ySyncPluginKey)\n return null\n }\n // @ts-ignore\n return nodes\n}\n\n/**\n * @private\n * @param {Array<any>} nodes prosemirror node\n * @param {BindingMetadata} meta\n * @return {Y.XmlText}\n */\nconst createTypeFromTextNodes = (nodes, meta) => {\n const type = new Y.XmlText()\n const delta = nodes.map((node) => ({\n // @ts-ignore\n insert: node.text,\n attributes: marksToAttributes(node.marks, meta)\n }))\n type.applyDelta(delta)\n meta.mapping.set(type, nodes)\n return type\n}\n\n/**\n * @private\n * @param {any} node prosemirror node\n * @param {BindingMetadata} meta\n * @return {Y.XmlElement}\n */\nconst createTypeFromElementNode = (node, meta) => {\n const type = new Y.XmlElement(node.type.name)\n for (const key in node.attrs) {\n const val = node.attrs[key]\n if (val !== null && key !== 'ychange') {\n type.setAttribute(key, val)\n }\n }\n type.insert(\n 0,\n normalizePNodeContent(node).map((n) =>\n createTypeFromTextOrElementNode(n, meta)\n )\n )\n meta.mapping.set(type, node)\n return type\n}\n\n/**\n * @private\n * @param {PModel.Node|Array<PModel.Node>} node prosemirror text node\n * @param {BindingMetadata} meta\n * @return {Y.XmlElement|Y.XmlText}\n */\nconst createTypeFromTextOrElementNode = (node, meta) =>\n node instanceof Array\n ? createTypeFromTextNodes(node, meta)\n : createTypeFromElementNode(node, meta)\n\n/**\n * @param {any} val\n */\nconst isObject = (val) => typeof val === 'object' && val !== null\n\n/**\n * @param {any} pattrs\n * @param {any} yattrs\n */\nconst equalAttrs = (pattrs, yattrs) => {\n const keys = Object.keys(pattrs).filter((key) => pattrs[key] !== null)\n let eq =\n keys.length ===\n (yattrs == null ? 0 : Object.keys(yattrs).filter((key) => yattrs[key] !== null).length)\n for (let i = 0; i < keys.length && eq; i++) {\n const key = keys[i]\n const l = pattrs[key]\n const r = yattrs[key]\n eq = key === 'ychange' || l === r ||\n (isObject(l) && isObject(r) && equalAttrs(l, r))\n }\n return eq\n}\n\n/**\n * @typedef {Array<Array<PModel.Node>|PModel.Node>} NormalizedPNodeContent\n */\n\n/**\n * @param {any} pnode\n * @return {NormalizedPNodeContent}\n */\nconst normalizePNodeContent = (pnode) => {\n const c = pnode.content.content\n const res = []\n for (let i = 0; i < c.length; i++) {\n const n = c[i]\n if (n.isText) {\n const textNodes = []\n for (let tnode = c[i]; i < c.length && tnode.isText; tnode = c[++i]) {\n textNodes.push(tnode)\n }\n i--\n res.push(textNodes)\n } else {\n res.push(n)\n }\n }\n return res\n}\n\n/**\n * @param {Y.XmlText} ytext\n * @param {Array<any>} ptexts\n */\nconst equalYTextPText = (ytext, ptexts) => {\n const delta = ytext.toDelta()\n return delta.length === ptexts.length &&\n delta.every(/** @type {(d:any,i:number) => boolean} */ (d, i) =>\n d.insert === /** @type {any} */ (ptexts[i]).text &&\n object.keys(d.attributes || {}).length === ptexts[i].marks.length &&\n object.every(d.attributes, (attr, yattrname) => {\n const markname = yattr2markname(yattrname)\n const pmarks = ptexts[i].marks\n return equalAttrs(attr, pmarks.find(/** @param {any} mark */ mark => mark.type.name === markname)?.attrs)\n })\n )\n}\n\n/**\n * @param {Y.XmlElement|Y.XmlText|Y.XmlHook} ytype\n * @param {any|Array<any>} pnode\n */\nconst equalYTypePNode = (ytype, pnode) => {\n if (\n ytype instanceof Y.XmlElement && !(pnode instanceof Array) &&\n matchNodeName(ytype, pnode)\n ) {\n const normalizedContent = normalizePNodeContent(pnode)\n return ytype._length === normalizedContent.length &&\n equalAttrs(ytype.getAttributes(), pnode.attrs) &&\n ytype.toArray().every((ychild, i) =>\n equalYTypePNode(ychild, normalizedContent[i])\n )\n }\n return ytype instanceof Y.XmlText && pnode instanceof Array &&\n equalYTextPText(ytype, pnode)\n}\n\n/**\n * @param {PModel.Node | Array<PModel.Node> | undefined} mapped\n * @param {PModel.Node | Array<PModel.Node>} pcontent\n */\nconst mappedIdentity = (mapped, pcontent) =>\n mapped === pcontent ||\n (mapped instanceof Array && pcontent instanceof Array &&\n mapped.length === pcontent.length && mapped.every((a, i) =>\n pcontent[i] === a\n ))\n\n/**\n * @param {Y.XmlElement} ytype\n * @param {PModel.Node} pnode\n * @param {BindingMetadata} meta\n * @return {{ foundMappedChild: boolean, equalityFactor: number }}\n */\nconst computeChildEqualityFactor = (ytype, pnode, meta) => {\n const yChildren = ytype.toArray()\n const pChildren = normalizePNodeContent(pnode)\n const pChildCnt = pChildren.length\n const yChildCnt = yChildren.length\n const minCnt = math.min(yChildCnt, pChildCnt)\n let left = 0\n let right = 0\n let foundMappedChild = false\n for (; left < minCnt; left++) {\n const leftY = yChildren[left]\n const leftP = pChildren[left]\n if (mappedIdentity(meta.mapping.get(leftY), leftP)) {\n foundMappedChild = true // definite (good) match!\n } else if (!equalYTypePNode(leftY, leftP)) {\n break\n }\n }\n for (; left + right < minCnt; right++) {\n const rightY = yChildren[yChildCnt - right - 1]\n const rightP = pChildren[pChildCnt - right - 1]\n if (mappedIdentity(meta.mapping.get(rightY), rightP)) {\n foundMappedChild = true\n } else if (!equalYTypePNode(rightY, rightP)) {\n break\n }\n }\n return {\n equalityFactor: left + right,\n foundMappedChild\n }\n}\n\n/**\n * @param {Y.Text} ytext\n */\nconst ytextTrans = (ytext) => {\n let str = ''\n /**\n * @type {Y.Item|null}\n */\n let n = ytext._start\n const nAttrs = {}\n while (n !== null) {\n if (!n.deleted) {\n if (n.countable && n.content instanceof Y.ContentString) {\n str += n.content.str\n } else if (n.content instanceof Y.ContentFormat) {\n nAttrs[n.content.key] = null\n }\n }\n n = n.right\n }\n return {\n str,\n nAttrs\n }\n}\n\n/**\n * @todo test this more\n *\n * @param {Y.Text} ytext\n * @param {Array<any>} ptexts\n * @param {BindingMetadata} meta\n */\nconst updateYText = (ytext, ptexts, meta) => {\n meta.mapping.set(ytext, ptexts)\n const { nAttrs, str } = ytextTrans(ytext)\n const content = ptexts.map((p) => ({\n insert: /** @type {any} */ (p).text,\n attributes: Object.assign({}, nAttrs, marksToAttributes(p.marks, meta))\n }))\n const { insert, remove, index } = simpleDiff(\n str,\n content.map((c) => c.insert).join('')\n )\n ytext.delete(index, remove)\n ytext.insert(index, insert)\n ytext.applyDelta(\n content.map((c) => ({ retain: c.insert.length, attributes: c.attributes }))\n )\n}\n\nconst hashedMarkNameRegex = /(.*)(--[a-zA-Z0-9+/=]{8})$/\n/**\n * @param {string} attrName\n */\nexport const yattr2markname = attrName => hashedMarkNameRegex.exec(attrName)?.[1] ?? attrName\n\n/**\n * @todo move this to markstoattributes\n *\n * @param {Object<string, any>} attrs\n * @param {import('prosemirror-model').Schema} schema\n */\nexport const attributesToMarks = (attrs, schema) => {\n /**\n * @type {Array<import('prosemirror-model').Mark>}\n */\n const marks = []\n for (const markName in attrs) {\n // remove hashes if necessary\n marks.push(schema.mark(yattr2markname(markName), attrs[markName]))\n }\n return marks\n}\n\n/**\n * @param {Array<import('prosemirror-model').Mark>} marks\n * @param {BindingMetadata} meta\n */\nconst marksToAttributes = (marks, meta) => {\n const pattrs = {}\n marks.forEach((mark) => {\n if (mark.type.name !== 'ychange') {\n const isOverlapping = map.setIfUndefined(meta.isOMark, mark.type, () => !mark.type.excludes(mark.type))\n pattrs[isOverlapping ? `${mark.type.name}--${utils.hashOfJSON(mark.toJSON())}` : mark.type.name] = mark.attrs\n }\n })\n return pattrs\n}\n\n/**\n * Update a yDom node by syncing the current content of the prosemirror node.\n *\n * This is a y-prosemirror internal feature that you can use at your own risk.\n *\n * @private\n * @unstable\n *\n * @param {{transact: Function}} y\n * @param {Y.XmlFragment} yDomFragment\n * @param {any} pNode\n * @param {BindingMetadata} meta\n */\nexport const updateYFragment = (y, yDomFragment, pNode, meta) => {\n if (\n yDomFragment instanceof Y.XmlElement &&\n yDomFragment.nodeName !== pNode.type.name\n ) {\n throw new Error('node name mismatch!')\n }\n meta.mapping.set(yDomFragment, pNode)\n // update attributes\n if (yDomFragment instanceof Y.XmlElement) {\n const yDomAttrs = yDomFragment.getAttributes()\n const pAttrs = pNode.attrs\n for (const key in pAttrs) {\n if (pAttrs[key] !== null) {\n if (yDomAttrs[key] !== pAttrs[key] && key !== 'ychange') {\n yDomFragment.setAttribute(key, pAttrs[key])\n }\n } else {\n yDomFragment.removeAttribute(key)\n }\n }\n // remove all keys that are no longer in pAttrs\n for (const key in yDomAttrs) {\n if (pAttrs[key] === undefined) {\n yDomFragment.removeAttribute(key)\n }\n }\n }\n // update children\n const pChildren = normalizePNodeContent(pNode)\n const pChildCnt = pChildren.length\n const yChildren = yDomFragment.toArray()\n const yChildCnt = yChildren.length\n const minCnt = math.min(pChildCnt, yChildCnt)\n let left = 0\n let right = 0\n // find number of matching elements from left\n for (; left < minCnt; left++) {\n const leftY = yChildren[left]\n const leftP = pChildren[left]\n if (!mappedIdentity(meta.mapping.get(leftY), leftP)) {\n if (equalYTypePNode(leftY, leftP)) {\n // update mapping\n meta.mapping.set(leftY, leftP)\n } else {\n break\n }\n }\n }\n // find number of matching elements from right\n for (; right + left < minCnt; right++) {\n const rightY = yChildren[yChildCnt - right - 1]\n const rightP = pChildren[pChildCnt - right - 1]\n if (!mappedIdentity(meta.mapping.get(rightY), rightP)) {\n if (equalYTypePNode(rightY, rightP)) {\n // update mapping\n meta.mapping.set(rightY, rightP)\n } else {\n break\n }\n }\n }\n y.transact(() => {\n // try to compare and update\n while (yChildCnt - left - right > 0 && pChildCnt - left - right > 0) {\n const leftY = yChildren[left]\n const leftP = pChildren[left]\n const rightY = yChildren[yChildCnt - right - 1]\n const rightP = pChildren[pChildCnt - right - 1]\n if (leftY instanceof Y.XmlText && leftP instanceof Array) {\n if (!equalYTextPText(leftY, leftP)) {\n updateYText(leftY, leftP, meta)\n }\n left += 1\n } else {\n let updateLeft = leftY instanceof Y.XmlElement &&\n matchNodeName(leftY, leftP)\n let updateRight = rightY instanceof Y.XmlElement &&\n matchNodeName(rightY, rightP)\n if (updateLeft && updateRight) {\n // decide which which element to update\n const equalityLeft = computeChildEqualityFactor(\n /** @type {Y.XmlElement} */ (leftY),\n /** @type {PModel.Node} */ (leftP),\n meta\n )\n const equalityRight = computeChildEqualityFactor(\n /** @type {Y.XmlElement} */ (rightY),\n /** @type {PModel.Node} */ (rightP),\n meta\n )\n if (\n equalityLeft.foundMappedChild && !equalityRight.foundMappedChild\n ) {\n updateRight = false\n } else if (\n !equalityLeft.foundMappedChild && equalityRight.foundMappedChild\n ) {\n updateLeft = false\n } else if (\n equalityLeft.equalityFactor < equalityRight.equalityFactor\n ) {\n updateLeft = false\n } else {\n updateRight = false\n }\n }\n if (updateLeft) {\n updateYFragment(\n y,\n /** @type {Y.XmlFragment} */ (leftY),\n /** @type {PModel.Node} */ (leftP),\n meta\n )\n left += 1\n } else if (updateRight) {\n updateYFragment(\n y,\n /** @type {Y.XmlFragment} */ (rightY),\n /** @type {PModel.Node} */ (rightP),\n meta\n )\n right += 1\n } else {\n meta.mapping.delete(yDomFragment.get(left))\n yDomFragment.delete(left, 1)\n yDomFragment.insert(left, [\n createTypeFromTextOrElementNode(leftP, meta)\n ])\n left += 1\n }\n }\n }\n const yDelLen = yChildCnt - left - right\n if (\n yChildCnt === 1 && pChildCnt === 0 && yChildren[0] instanceof Y.XmlText\n ) {\n meta.mapping.delete(yChildren[0])\n // Edge case handling https://github.com/yjs/y-prosemirror/issues/108\n // Only delete the content of the Y.Text to retain remote changes on the same Y.Text object\n yChildren[0].delete(0, yChildren[0].length)\n } else if (yDelLen > 0) {\n yDomFragment.slice(left, left + yDelLen).forEach(type => meta.mapping.delete(type))\n yDomFragment.delete(left, yDelLen)\n }\n if (left + right < pChildCnt) {\n const ins = []\n for (let i = left; i < pChildCnt - right; i++) {\n ins.push(createTypeFromTextOrElementNode(pChildren[i], meta))\n }\n yDomFragment.insert(left, ins)\n }\n }, ySyncPluginKey)\n}\n\n/**\n * @function\n * @param {Y.XmlElement} yElement\n * @param {any} pNode Prosemirror Node\n */\nconst matchNodeName = (yElement, pNode) =>\n !(pNode instanceof Array) && yElement.nodeName === pNode.type.name\n","import { updateYFragment, createNodeFromYElement, yattr2markname, createEmptyMeta } from './plugins/sync-plugin.js' // eslint-disable-line\nimport { ySyncPluginKey } from './plugins/keys.js'\nimport * as Y from 'yjs'\nimport { EditorView } from 'prosemirror-view' // eslint-disable-line\nimport { Node, Schema, Fragment } from 'prosemirror-model' // eslint-disable-line\nimport * as error from 'lib0/error'\nimport * as map from 'lib0/map'\nimport * as eventloop from 'lib0/eventloop'\n\n/**\n * Either a node if type is YXmlElement or an Array of text nodes if YXmlText\n * @typedef {Map<Y.AbstractType, Node | Array<Node>>} ProsemirrorMapping\n */\n\n/**\n * Is null if no timeout is in progress.\n * Is defined if a timeout is in progress.\n * Maps from view\n * @type {Map<EditorView, Map<any, any>>|null}\n */\nlet viewsToUpdate = null\n\nconst updateMetas = () => {\n const ups = /** @type {Map<EditorView, Map<any, any>>} */ (viewsToUpdate)\n viewsToUpdate = null\n ups.forEach((metas, view) => {\n const tr = view.state.tr\n const syncState = ySyncPluginKey.getState(view.state)\n if (syncState && syncState.binding && !syncState.binding.isDestroyed) {\n metas.forEach((val, key) => {\n tr.setMeta(key, val)\n })\n view.dispatch(tr)\n }\n })\n}\n\nexport const setMeta = (view, key, value) => {\n if (!viewsToUpdate) {\n viewsToUpdate = new Map()\n eventloop.timeout(0, updateMetas)\n }\n map.setIfUndefined(viewsToUpdate, view, map.create).set(key, value)\n}\n\n/**\n * Transforms a Prosemirror based absolute position to a Yjs Cursor (relative position in the Yjs model).\n *\n * @param {number} pos\n * @param {Y.XmlFragment} type\n * @param {ProsemirrorMapping} mapping\n * @return {any} relative position\n */\nexport const absolutePositionToRelativePosition = (pos, type, mapping) => {\n if (pos === 0) {\n // if the type is later populated, we want to retain the 0 position (hence assoc=-1)\n return Y.createRelativePositionFromTypeIndex(type, 0, type.length === 0 ? -1 : 0)\n }\n /**\n * @type {any}\n */\n let n = type._first === null ? null : /** @type {Y.ContentType} */ (type._first.content).type\n while (n !== null && type !== n) {\n if (n instanceof Y.XmlText) {\n if (n._length >= pos) {\n return Y.createRelativePositionFromTypeIndex(n, pos, type.length === 0 ? -1 : 0)\n } else {\n pos -= n._length\n }\n if (n._item !== null && n._item.next !== null) {\n n = /** @type {Y.ContentType} */ (n._item.next.content).type\n } else {\n do {\n n = n._item === null ? null : n._item.parent\n pos--\n } while (n !== type && n !== null && n._item !== null && n._item.next === null)\n if (n !== null && n !== type) {\n // @ts-gnore we know that n.next !== null because of above loop conditition\n n = n._item === null ? null : /** @type {Y.ContentType} */ (/** @type Y.Item */ (n._item.next).content).type\n }\n }\n } else {\n const pNodeSize = /** @type {any} */ (mapping.get(n) || { nodeSize: 0 }).nodeSize\n if (n._first !== null && pos < pNodeSize) {\n n = /** @type {Y.ContentType} */ (n._first.content).type\n pos--\n } else {\n if (pos === 1 && n._length === 0 && pNodeSize > 1) {\n // edge case, should end in this paragraph\n return new Y.RelativePosition(n._item === null ? null : n._item.id, n._item === null ? Y.findRootTypeKey(n) : null, null)\n }\n pos -= pNodeSize\n if (n._item !== null && n._item.next !== null) {\n n = /** @type {Y.ContentType} */ (n._item.next.content).type\n } else {\n if (pos === 0) {\n // set to end of n.parent\n n = n._item === null ? n : n._item.parent\n return new Y.RelativePosition(n._item === null ? null : n._item.id, n._item === null ? Y.findRootTypeKey(n) : null, null)\n }\n do {\n n = /** @type {Y.Item} */ (n._item).parent\n pos--\n } while (n !== type && /** @type {Y.Item} */ (n._item).next === null)\n // if n is null at this point, we have an unexpected case\n if (n !== type) {\n // We know that n._item.next is defined because of above loop condition\n n = /** @type {Y.ContentType} */ (/** @type {Y.Item} */ (/** @type {Y.Item} */ (n._item).next).content).type\n }\n }\n }\n }\n if (n === null) {\n throw error.unexpectedCase()\n }\n if (pos === 0 && n.constructor !== Y.XmlText && n !== type) { // TODO: set to <= 0\n return createRelativePosition(n._item.parent, n._item)\n }\n }\n return Y.createRelativePositionFromTypeIndex(type, type._length, type.length === 0 ? -1 : 0)\n}\n\nconst createRelativePosition = (type, item) => {\n let typeid = null\n let tname = null\n if (type._item === null) {\n tname = Y.findRootTypeKey(type)\n } else {\n typeid = Y.createID(type._item.id.client, type._item.id.clock)\n }\n return new Y.RelativePosition(typeid, tname, item.id)\n}\n\n/**\n * @param {Y.Doc} y\n * @param {Y.XmlFragment} documentType Top level type that is bound to pView\n * @param {any} relPos Encoded Yjs based relative position\n * @param {ProsemirrorMapping} mapping\n * @return {null|number}\n */\nexport const relativePositionToAbsolutePosition = (y, documentType, relPos, mapping) => {\n const decodedPos = Y.createAbsolutePositionFromRelativePosition(relPos, y)\n if (decodedPos === null || (decodedPos.type !== documentType && !Y.isParentOf(documentType, decodedPos.type._item))) {\n return null\n }\n let type = decodedPos.type\n let pos = 0\n if (type.constructor === Y.XmlText) {\n pos = decodedPos.index\n } else if (type._item === null || !type._item.deleted) {\n let n = type._first\n let i = 0\n while (i < type._length && i < decodedPos.index && n !== null) {\n if (!n.deleted) {\n const t = /** @type {Y.ContentType} */ (n.content).type\n i++\n if (t instanceof Y.XmlText) {\n pos += t._length\n } else {\n pos += /** @type {any} */ (mapping.get(t)).nodeSize\n }\n }\n n = /** @type {Y.Item} */ (n.right)\n }\n pos += 1 // increase because we go out of n\n }\n while (type !== documentType && type._item !== null) {\n // @ts-ignore\n const parent = type._item.parent\n // @ts-ignore\n if (parent._item === null || !parent._item.deleted) {\n pos += 1 // the start tag\n let n = /** @type {Y.AbstractType} */ (parent)._first\n // now iterate until we found type\n while (n !== null) {\n const contentType = /** @type {Y.ContentType} */ (n.content).type\n if (contentType === type) {\n break\n }\n if (!n.deleted) {\n if (contentType instanceof Y.XmlText) {\n pos += contentType._length\n } else {\n pos += /** @type {any} */ (mapping.get(contentType)).nodeSize\n }\n }\n n = n.right\n }\n }\n type = /** @type {Y.AbstractType} */ (parent)\n }\n return pos - 1 // we don't count the most outer tag, because it is a fragment\n}\n\n/**\n * Utility function for converting an Y.Fragment to a ProseMirror fragment.\n *\n * @param {Y.XmlFragment} yXmlFragment\n * @param {Schema} schema\n */\nexport const yXmlFragmentToProseMirrorFragment = (yXmlFragment, schema) => {\n const fragmentContent = yXmlFragment.toArray().map((t) =>\n createNodeFromYElement(\n /** @type {Y.XmlElement} */ (t),\n schema,\n createEmptyMeta()\n )\n ).filter((n) => n !== null)\n return Fragment.fromArray(fragmentContent)\n}\n\n/**\n * Utility function for converting an Y.Fragment to a ProseMirror node.\n *\n * @param {Y.XmlFragment} yXmlFragment\n * @param {Schema} schema\n */\nexport const yXmlFragmentToProseMirrorRootNode = (yXmlFragment, schema) =>\n schema.topNodeType.create(null, yXmlFragmentToProseMirrorFragment(yXmlFragment, schema))\n\n/**\n * The initial ProseMirror content should be supplied by Yjs. This function transforms a Y.Fragment\n * to a ProseMirror Doc node and creates a mapping that is used by the sync plugin.\n *\n * @param {Y.XmlFragment} yXmlFragment\n * @param {Schema} schema\n *\n * @todo deprecate mapping property\n */\nexport const initProseMirrorDoc = (yXmlFragment, schema) => {\n const meta = createEmptyMeta()\n const fragmentContent = yXmlFragment.toArray().map((t) =>\n createNodeFromYElement(\n /** @type {Y.XmlElement} */ (t),\n schema,\n meta\n )\n ).filter((n) => n !== null)\n const doc = schema.topNodeType.create(null, Fragment.fromArray(fragmentContent))\n return { doc, meta, mapping: meta.mapping }\n}\n\n/**\n * Utility method to convert a Prosemirror Doc Node into a Y.Doc.\n *\n * This can be used when importing existing content to Y.Doc for the first time,\n * note that this should not be used to rehydrate a Y.Doc from a database once\n * collaboration has begun as all history will be lost\n *\n * @param {Node} doc\n * @param {string} xmlFragment\n * @return {Y.Doc}\n */\nexport function prosemirrorToYDoc (doc, xmlFragment = 'prosemirror') {\n const ydoc = new Y.Doc()\n const type = /** @type {Y.XmlFragment} */ (ydoc.get(xmlFragment, Y.XmlFragment))\n if (!type.doc) {\n return ydoc\n }\n\n prosemirrorToYXmlFragment(doc, type)\n return type.doc\n}\n\n/**\n * Utility method to update an empty Y.XmlFragment with content from a Prosemirror Doc Node.\n *\n * This can be used when importing existing content to Y.Doc for the first time,\n * note that this should not be used to rehydrate a Y.Doc from a database once\n * collaboration has begun as all history will be lost\n *\n * Note: The Y.XmlFragment does not need to be part of a Y.Doc document at the time that this\n * method is called, but it must be added before any other operations are performed on it.\n *\n * @param {Node} doc prosemirror document.\n * @param {Y.XmlFragment} [xmlFragment] If supplied, an xml fragment to be\n * populated from the prosemirror state; otherwise a new XmlFragment will be created.\n * @return {Y.XmlFragment}\n */\nexport function prosemirrorToYXmlFragment (doc, xmlFragment) {\n const type = xmlFragment || new Y.XmlFragment()\n const ydoc = type.doc ? type.doc : { transact: (transaction) => transaction(undefined) }\n updateYFragment(ydoc, type, doc, { mapping: new Map(), isOMark: new Map() })\n return type\n}\n\n/**\n * Utility method to convert Prosemirror compatible JSON into a Y.Doc.\n *\n * This can be used when importing existing content to Y.Doc for the first time,\n * note that this should not be used to rehydrate a Y.Doc from a database once\n * collaboration has begun as all history will be lost\n *\n * @param {Schema} schema\n * @param {any} state\n * @param {string} xmlFragment\n * @return {Y.Doc}\n */\nexport function prosemirrorJSONToYDoc (schema, state, xmlFragment = 'prosemirror') {\n const doc = Node.fromJSON(schema, state)\n return prosemirrorToYDoc(doc, xmlFragment)\n}\n\n/**\n * Utility method to convert Prosemirror compatible JSON to a Y.XmlFragment\n *\n * This can be used when importing existing content to Y.Doc for the first time,\n * note that this should not be used to rehydrate a Y.Doc from a database once\n * collaboration has begun as all history will be lost\n *\n * @param {Schema} schema\n * @param {any} state\n * @param {Y.XmlFragment} [xmlFragment] If supplied, an xml fragment to be\n * populated from the prosemirror state; otherwise a new XmlFragment will be created.\n * @return {Y.XmlFragment}\n */\nexport function prosemirrorJSONToYXmlFragment (schema, state, xmlFragment) {\n const doc = Node.fromJSON(schema, state)\n return prosemirrorToYXmlFragment(doc, xmlFragment)\n}\n\n/**\n * @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead\n *\n * Utility method to convert a Y.Doc to a Prosemirror Doc node.\n *\n * @param {Schema} schema\n * @param {Y.Doc} ydoc\n * @return {Node}\n */\nexport function yDocToProsemirror (schema, ydoc) {\n const state = yDocToProsemirrorJSON(ydoc)\n return Node.fromJSON(schema, state)\n}\n\n/**\n *\n * @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead\n *\n * Utility method to convert a Y.XmlFragment to a Prosemirror Doc node.\n *\n * @param {Schema} schema\n * @param {Y.XmlFragment} xmlFragment\n * @return {Node}\n */\nexport function yXmlFragmentToProsemirror (schema, xmlFragment) {\n const state = yXmlFragmentToProsemirrorJSON(xmlFragment)\n return Node.fromJSON(schema, state)\n}\n\n/**\n *\n * @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead\n *\n * Utility method to convert a Y.Doc to Prosemirror compatible JSON.\n *\n * @param {Y.Doc} ydoc\n * @param {string} xmlFragment\n * @return {Record<string, any>}\n */\nexport function yDocToProsemirrorJSON (\n ydoc,\n xmlFragment = 'prosemirror'\n) {\n return yXmlFragmentToProsemirrorJSON(ydoc.getXmlFragment(xmlFragment))\n}\n\n/**\n * @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead\n *\n * Utility method to convert a Y.Doc to Prosemirror compatible JSON.\n *\n * @param {Y.XmlFragment} xmlFragment The fragment, which must be part of a Y.Doc.\n * @return {Record<string, any>}\n */\nexport function yXmlFragmentToProsemirrorJSON (xmlFragment) {\n const items = xmlFragment.toArray()\n\n /**\n * @param {Y.AbstractType} item\n */\n const serialize = item => {\n /**\n * @type {Object} NodeObject\n * @property {string} NodeObject.type\n * @property {Record<string, string>=} NodeObject.attrs\n * @property {Array<NodeObject>=} NodeObject.content\n */\n let response\n\n // TODO: Must be a better way to detect text nodes than this\n if (item instanceof Y.XmlText) {\n const delta = item.toDelta()\n response = delta.map(/** @param {any} d */ (d) => {\n const text = {\n type: 'text',\n text: d.insert\n }\n if (d.attributes) {\n text.marks = Object.keys(d.attributes).map((type_) => {\n const attrs = d.attributes[type_]\n const type = yattr2markname(type_)\n const mark = {\n type\n }\n if (Object.keys(attrs)) {\n mark.attrs = attrs\n }\n return mark\n })\n }\n return text\n })\n } else if (item instanceof Y.XmlElement) {\n response = {\n type: item.nodeName\n }\n\n const attrs = item.getAttributes()\n if (Object.keys(attrs).length) {\n response.attrs = attrs\n }\n\n const children = item.toArray()\n if (children.length) {\n response.content = children.map(serialize).flat()\n }\n } else {\n // expected either Y.XmlElement or Y.XmlText\n error.unexpectedCase()\n }\n\n return response\n }\n\n return {\n type: 'doc',\n content: items.map(serialize)\n }\n}\n","/**\n * Liveblocks Text Editor\n *\n * Expose common types to transform nodes from different editors like `Lexical` or `TipTap`\n * and then convert them more easily as React or as html.\n */\n\nimport type {\n Awaitable,\n BaseUserMeta,\n DGI,\n Relax,\n ResolveGroupsInfoArgs,\n ResolveUsersArgs,\n} from \"@liveblocks/core\";\n\nimport type {\n LexicalMentionNodeWithContext,\n SerializedLexicalNode,\n SerializedLexicalTextNode,\n} from \"./lexical-editor\";\nimport {\n isSerializedGroupMentionNode as isSerializedLexicalGroupMentionNode,\n isSerializedMentionNode as isSerializedLexicalMentionNode,\n} from \"./lexical-editor\";\nimport type {\n SerializedTiptapMark,\n SerializedTiptapMarkType,\n SerializedTiptapNode,\n SerializedTiptapTextNode,\n TiptapMentionNodeWithContext,\n} from \"./tiptap-editor\";\nimport {\n isSerializedGroupMentionNode as isSerializedTiptapGroupMentionNode,\n isSerializedMentionNode as isSerializedTiptapMentionNode,\n} from \"./tiptap-editor\";\n\ntype LiveblocksTextEditorTextFormat = {\n bold: boolean;\n italic: boolean;\n strikethrough: boolean;\n code: boolean;\n};\n\nexport type LiveblocksTextEditorTextNode = {\n type: \"text\";\n text: string;\n} & LiveblocksTextEditorTextFormat;\n\nexport type LiveblocksTextEditorMentionNode = Relax<\n LiveblocksTextEditorUserMentionNode | LiveblocksTextEditorGroupMentionNode\n>;\n\ntype LiveblocksTextEditorUserMentionNode = {\n type: \"mention\";\n kind: \"user\";\n id: string;\n};\n\nexport type LiveblocksTextEditorGroupMentionNode = {\n type: \"mention\";\n kind: \"group\";\n id: string;\n userIds?: string[];\n};\n\n/**\n * -------------------------------------------------------------------------------------------------\n * `LiveblocksTextEditorNode` is common structure to represents text editor nodes coming from\n * like `Lexical`, `TipTap` or so.\n *\n * This (simple) structure is made to be scalable and to accommodate with other text editors we could potentially\n * want to support in the future.\n *\n * It allows to manipulate nodes more easily and converts them with ease either as React nodes or as an html safe string.\n * From a DX standpoint it provides to developers the same structure to use when using custom React components or inline css\n * to represents a text mention with its surrounding text.\n * -------------------------------------------------------------------------------------------------\n */\nexport type LiveblocksTextEditorNode =\n | LiveblocksTextEditorTextNode\n | LiveblocksTextEditorMentionNode;\n\nconst baseLiveblocksTextEditorTextFormat: LiveblocksTextEditorTextFormat = {\n bold: false,\n italic: false,\n strikethrough: false,\n code: false,\n};\n\n/**\n * -------------------------------------------------------------------------------------------------\n * Lexical use bitwise operators to represent text formatting:\n * → https://github.com/facebook/lexical/blob/e423c6888dbf2dbd0b5ef68f781efadda20d34f3/packages/lexical/src/LexicalConstants.ts#L39\n *\n * It allows to combine multiple flags into one single integer such as:\n * 00000001 (bold)\n * 00000010 (italic)\n * --------\n * 0000011 (bold + italic)\n *\n * For now we're copying only the bitwise flags we need to provide a consistent DX with\n * `ThreadNotificationEvent` comments:\n * - BOLD\n * - ITALIC\n * - STRIKETHROUGH\n * - CODE\n *\n * and `transformLexicalTextNodeFormatBitwiseInteger` transforms these flags\n * into a object of booleans `LiveblocksTextEditorTextFormat`:\n * ```ts\n * {\n * bold: boolean;\n * italic: boolean;\n * strikethrough: boolean;\n * code: boolean;\n * }\n * ```\n * -------------------------------------------------------------------------------------------------\n */\n\nconst IS_LEXICAL_BOLD = 1;\nconst IS_LEXICAL_ITALIC = 1 << 1;\nconst IS_LEXICAL_STRIKETHROUGH = 1 << 2;\nconst IS_LEXICAL_CODE = 1 << 4;\n\n/** @internal */\nconst transformLexicalTextNodeFormatBitwiseInteger = (\n node: SerializedLexicalTextNode\n): LiveblocksTextEditorTextFormat => {\n const attributes = node.attributes;\n\n if (\"__format\" in attributes && typeof attributes.__format === \"number\") {\n const format = attributes.__format;\n return {\n bold: (format & IS_LEXICAL_BOLD) !== 0,\n italic: (format & IS_LEXICAL_ITALIC) !== 0,\n strikethrough: (format & IS_LEXICAL_STRIKETHROUGH) !== 0,\n code: (format & IS_LEXICAL_CODE) !== 0,\n };\n }\n\n return baseLiveblocksTextEditorTextFormat;\n};\n\n/**\n * @internal\n *\n * Transform Lexical serialized nodes\n * as Liveblocks Text Editor nodes\n */\nconst transformLexicalMentionNodeWithContext = (\n mentionNodeWithContext: LexicalMentionNodeWithContext\n): LiveblocksTextEditorNode[] => {\n const textEditorNodes: LiveblocksTextEditorNode[] = [];\n const { before, after, mention } = mentionNodeWithContext;\n\n const transform = (nodes: SerializedLexicalNode[]) => {\n for (const node of nodes) {\n if (node.group === \"text\") {\n const format = transformLexicalTextNodeFormatBitwiseInteger(node);\n textEditorNodes.push({\n type: \"text\",\n text: node.text,\n ...format,\n });\n } else if (\n node.group === \"decorator\" &&\n isSerializedLexicalMentionNode(node)\n ) {\n textEditorNodes.push({\n type: \"mention\",\n kind: \"user\",\n id: node.attributes.__userId,\n });\n } else if (\n node.group === \"decorator\" &&\n isSerializedLexicalGroupMentionNode(node)\n ) {\n textEditorNodes.push({\n type: \"mention\",\n kind: \"group\",\n id: node.attributes.__groupId,\n });\n }\n }\n };\n\n transform(before);\n textEditorNodes.push({\n type: \"mention\",\n kind: mention.type === \"lb-group-mention\" ? \"group\" : \"user\",\n id:\n mention.type === \"lb-group-mention\"\n ? mention.attributes.__groupId\n : mention.attributes.__userId,\n });\n transform(after);\n\n return textEditorNodes;\n};\n\n/** @internal */\nconst hasTiptapSerializedTextNodeMark = (\n marks: Array<SerializedTiptapMark>,\n type: SerializedTiptapMarkType\n): boolean => marks.findIndex((mark) => mark.type === type) !== -1;\n\n/** @internal */\nconst transformTiptapTextNodeFormatMarks = (\n node: SerializedTiptapTextNode\n): LiveblocksTextEditorTextFormat => {\n if (!node.marks) {\n return baseLiveblocksTextEditorTextFormat;\n }\n\n const marks = node.marks;\n return {\n bold: hasTiptapSerializedTextNodeMark(marks, \"bold\"),\n italic: hasTiptapSerializedTextNodeMark(marks, \"italic\"),\n strikethrough: hasTiptapSerializedTextNodeMark(marks, \"strike\"),\n code: hasTiptapSerializedTextNodeMark(marks, \"code\"),\n };\n};\n\n/**\n *\n * @internal\n *\n * Transform Tiptap serialized nodes\n * as Liveblocks Text Editor nodes\n */\nconst transformTiptapMentionNodeWithContext = (\n mentionNodeWithContext: TiptapMentionNodeWithContext\n): LiveblocksTextEditorNode[] => {\n const textEditorNodes: LiveblocksTextEditorNode[] = [];\n const { before, after, mention } = mentionNodeWithContext;\n\n const transform = (nodes: SerializedTiptapNode[]) => {\n for (const node of nodes) {\n if (node.type === \"text\") {\n const format = transformTiptapTextNodeFormatMarks(node);\n textEditorNodes.push({\n type: \"text\",\n text: node.text,\n ...format,\n });\n } else if (isSerializedTiptapMentionNode(node)) {\n textEditorNodes.push({\n type: \"mention\",\n kind: \"user\",\n id: node.attrs.id,\n });\n } else if (isSerializedTiptapGroupMentionNode(node)) {\n textEditorNodes.push({\n type: \"mention\",\n kind: \"group\",\n id: node.attrs.id,\n });\n }\n }\n };\n\n transform(before);\n textEditorNodes.push({\n type: \"mention\",\n kind: mention.type === \"liveblocksGroupMention\" ? \"group\" : \"user\",\n id: mention.attrs.id,\n });\n transform(after);\n\n return textEditorNodes;\n};\n\ntype TransformableMentionNodeWithContext =\n | {\n editor: \"lexical\";\n mention: LexicalMentionNodeWithContext;\n }\n | {\n editor: \"tiptap\";\n mention: TiptapMentionNodeWithContext;\n };\n\n/**\n * @internal\n *\n * Transforms either Lexical or TipTap nodes into a common structure\n * of Liveblocks Text Editor nodes to ease conversion into\n * React Nodes or html safe strings\n */\nexport function transformAsLiveblocksTextEditorNodes(\n transformableMention: TransformableMentionNodeWithContext\n): LiveblocksTextEditorNode[] {\n switch (transformableMention.editor) {\n case \"lexical\": {\n return transformLexicalMentionNodeWithContext(\n transformableMention.mention\n );\n }\n case \"tiptap\": {\n return transformTiptapMentionNodeWithContext(\n transformableMention.mention\n );\n }\n }\n}\n\n/**\n * @internal\n * Resolves mentions (users or groups) in Liveblocks Text Editor nodes.\n */\nexport const resolveMentionsInLiveblocksTextEditorNodes = async <\n U extends BaseUserMeta,\n>(\n nodes: LiveblocksTextEditorNode[],\n resolveUsers?: (\n args: ResolveUsersArgs\n ) => Awaitable<(U[\"info\"] | undefined)[] | undefined>,\n resolveGroupsInfo?: (\n args: ResolveGroupsInfoArgs\n ) => Awaitable<(DGI | undefined)[] | undefined>\n): Promise<{\n users: Map<string, U[\"info\"]>;\n groups: Map<string, DGI>;\n}> => {\n const resolvedUsers = new Map<string, U[\"info\"]>();\n const resolvedGroupsInfo = new Map<string, DGI>();\n\n if (!resolveUsers && !resolveGroupsInfo) {\n return {\n users: resolvedUsers,\n groups: resolvedGroupsInfo,\n };\n }\n\n const mentionedUserIds = new Set<string>();\n const mentionedGroupIds = new Set<string>();\n\n for (const node of nodes) {\n if (node.type === \"mention\") {\n if (node.kind === \"user\") {\n mentionedUserIds.add(node.id);\n } else if (node.kind === \"group\") {\n mentionedGroupIds.add(node.id);\n }\n }\n }\n\n const userIds = Array.from(mentionedUserIds);\n const groupIds = Array.from(mentionedGroupIds);\n\n const [users, groups] = await Promise.all([\n resolveUsers && userIds.length > 0 ? resolveUsers({ userIds }) : undefined,\n resolveGroupsInfo && groupIds.length > 0\n ? resolveGroupsInfo({ groupIds })\n : undefined,\n ]);\n\n if (users) {\n for (const [index, userId] of userIds.entries()) {\n const user = users[index];\n if (user) {\n resolvedUsers.set(userId, user);\n }\n }\n }\n\n if (groups) {\n for (const [index, groupId] of groupIds.entries()) {\n const group = groups[index];\n if (group) {\n resolvedGroupsInfo.set(groupId, group);\n }\n }\n }\n\n return {\n users: resolvedUsers,\n groups: resolvedGroupsInfo,\n };\n};\n","import type {\n Awaitable,\n BaseUserMeta,\n DGI,\n DU,\n ResolveGroupsInfoArgs,\n ResolveUsersArgs,\n} from \"@liveblocks/core\";\n\nimport {\n type LiveblocksTextEditorMentionNode,\n type LiveblocksTextEditorNode,\n type LiveblocksTextEditorTextNode,\n resolveMentionsInLiveblocksTextEditorNodes,\n} from \"./liveblocks-text-editor\";\n\nexport type TextMentionContentContainerElementArgs<T> = {\n /**\n * The blocks of the text mention content\n */\n children: T[];\n};\n\nexport type TextMentionContentMentionElementArgs<U extends BaseUserMeta = DU> =\n {\n /**\n * The text mention node.\n */\n node: LiveblocksTextEditorMentionNode;\n\n /**\n * The mention's user info, if the mention is a user mention and the `resolvedUsers` option was provided.\n */\n user?: U[\"info\"];\n\n /**\n * The mention's group info, if the mention is a group mention and the `resolvedGroupsInfo` option was provided.\n */\n group?: DGI;\n };\n\nexport type TextMentionContentTextElementArgs = {\n /**\n * The text element.\n */\n node: LiveblocksTextEditorTextNode;\n};\n\n/**\n * Protocol:\n * Text mention content elements to be converted to a custom format `T`\n */\nexport type ConvertTextMentionContentElements<\n T,\n U extends BaseUserMeta = DU,\n> = {\n /**\n * The container element used to display text mention content blocks\n */\n container: (args: TextMentionContentContainerElementArgs<T>) => T;\n /**\n * The mention element used to display the mention itself.\n */\n mention: (args: TextMentionContentMentionElementArgs<U>, index: number) => T;\n /**\n * The text element used to display the text surrounding the mention.\n */\n text: (args: TextMentionContentTextElementArgs, index: number) => T;\n};\n\nexport type ConvertTextMentionContentOptions<T, U extends BaseUserMeta = DU> = {\n /**\n * A function that returns user info from user IDs.\n * You should return a list of user objects of the same size, in the same order.\n */\n resolveUsers?: (\n args: ResolveUsersArgs\n ) => Awaitable<(U[\"info\"] | undefined)[] | undefined>;\n\n /**\n * A function that returns group info from group IDs.\n * You should return a list of group info objects of the same size, in the same order.\n */\n resolveGroupsInfo?: (\n args: ResolveGroupsInfoArgs\n ) => Awaitable<(DGI | undefined)[] | undefined>;\n\n /**\n * The elements used to customize the resulting format `T`.\n */\n elements: ConvertTextMentionContentElements<T, U>;\n};\n\n/**\n * Convert a text mention content nodes to a custom format `T`.\n */\nexport async function convertTextMentionContent<T, U extends BaseUserMeta = DU>(\n nodes: LiveblocksTextEditorNode[],\n options: ConvertTextMentionContentOptions<T, U>\n): Promise<T> {\n const { users: resolvedUsers, groups: resolvedGroupsInfo } =\n await resolveMentionsInLiveblocksTextEditorNodes(\n nodes,\n options?.resolveUsers,\n options?.resolveGroupsInfo\n );\n\n const blocks: T[] = nodes.map((node, index) => {\n switch (node.type) {\n case \"mention\": {\n return options.elements.mention(\n {\n node,\n user: node.kind === \"user\" ? resolvedUsers.get(node.id) : undefined,\n group:\n node.kind === \"group\"\n ? resolvedGroupsInfo.get(node.id)\n : undefined,\n },\n index\n );\n }\n case \"text\": {\n return options.elements.text({ node }, index);\n }\n }\n });\n\n return options.elements.container({ children: blocks });\n}\n","import type {\n Awaitable,\n BaseUserMeta,\n CommentBodyLink,\n CommentBodyMention,\n CommentBodyText,\n CommentData,\n DGI,\n DRI,\n DU,\n GroupData,\n InboxNotificationData,\n ResolveGroupsInfoArgs,\n ResolveUsersArgs,\n} from \"@liveblocks/core\";\nimport {\n generateUrl,\n getMentionsFromCommentBody,\n html,\n htmlSafe,\n MENTION_CHARACTER,\n} from \"@liveblocks/core\";\nimport type { Liveblocks, ThreadNotificationEvent } from \"@liveblocks/node\";\nimport type { ComponentType, ReactNode } from \"react\";\n\nimport type { ConvertCommentBodyElements } from \"./comment-body\";\nimport { convertCommentBody } from \"./comment-body\";\nimport type { CommentDataWithBody } from \"./comment-with-body\";\nimport { filterCommentsWithBody } from \"./comment-with-body\";\nimport {\n createBatchGroupsInfoResolver,\n createBatchUsersResolver,\n getResolvedForId,\n} from \"./lib/batch-resolvers\";\nimport type { CSSProperties } from \"./lib/css-properties\";\nimport { toInlineCSSString } from \"./lib/css-properties\";\nimport type { ResolveRoomInfoArgs } from \"./lib/types\";\n\n/** @internal */\nexport const getUnreadComments = ({\n comments,\n inboxNotification,\n notificationTriggerAt,\n userId,\n}: {\n comments: CommentData[];\n inboxNotification: InboxNotificationData;\n notificationTriggerAt: Date;\n userId: string;\n}): CommentDataWithBody[] => {\n // Let's get only not deleted comments with a body.\n const commentsWithBody = filterCommentsWithBody(comments);\n // Let's filter out comments written by the user that received the notification.\n const notAuthoredComments = commentsWithBody.filter(\n (c) => c.userId !== userId\n );\n\n const readAt = inboxNotification.readAt;\n // This behavior is different from the `InboxNotificationThread` component\n // because we in the front-end we want the always the last activity.\n // In this case then we want to do a sequential reading of the activity.\n // It allow us to determine much more precisely which comments was created between\n // the moment the inbox notification is created and the moment the webhook event is received.\n return notAuthoredComments.filter((c) => {\n // If the inbox notification is read, because of the 1:1 relationship between an\n // and inbox notification and a thread, we must not include comments created\n // strictly after the `readAt` date. It means the inbox notification can be updated\n // in the db after the `readAt` date.\n if (readAt !== null) {\n return (\n c.createdAt > readAt &&\n c.createdAt >= notificationTriggerAt &&\n c.createdAt <= inboxNotification.notifiedAt\n );\n }\n // Otherwise we can include all comments created between the inbox notification\n // creation date (`triggeredAt`) and the inbox notification `notifiedAt` date.\n return (\n c.createdAt >= notificationTriggerAt &&\n c.createdAt <= inboxNotification.notifiedAt\n );\n });\n};\n\n/** @internal */\nasync function getAllUserGroups(\n client: Liveblocks,\n userId: string\n): Promise<Map<string, GroupData>> {\n const groups = new Map<string, GroupData>();\n let cursor: string | undefined = undefined;\n\n while (true) {\n const { nextCursor, data } = await client.getUserGroups({\n userId,\n startingAfter: cursor,\n });\n\n for (const group of data) {\n groups.set(group.id, group);\n }\n\n if (!nextCursor) {\n break;\n }\n\n cursor = nextCursor;\n }\n\n return groups;\n}\n\n/** @internal */\nexport const getLastUnreadCommentWithMention = ({\n comments,\n groups,\n mentionedUserId,\n}: {\n comments: CommentDataWithBody[];\n mentionedUserId: string;\n groups: Map<string, GroupData>;\n}): CommentDataWithBody | null => {\n if (!comments.length) {\n return null;\n }\n\n for (let i = comments.length - 1; i >= 0; i--) {\n const comment = comments[i]!;\n\n if (comment.userId === mentionedUserId) {\n continue;\n }\n\n const mentions = getMentionsFromCommentBody(comment.body);\n\n for (const mention of mentions) {\n // 1. The comment contains a user mention for the current user.\n if (mention.kind === \"user\" && mention.id === mentionedUserId) {\n return comment;\n }\n\n // 2. The comment contains a group mention including the current user in its `userIds` array.\n if (\n mention.kind === \"group\" &&\n mention.userIds?.includes(mentionedUserId)\n ) {\n return comment;\n }\n\n // 3. The comment contains a group mention including the current user in its managed group members.\n if (mention.kind === \"group\" && mention.userIds === undefined) {\n // Synchronously look up the group data for this group ID.\n const group = groups.get(mention.id);\n\n if (group?.members.some((member) => member.id === mentionedUserId)) {\n return comment;\n }\n }\n }\n }\n\n return null;\n};\n\nexport type ThreadNotificationData =\n | { type: \"unreadMention\"; comment: CommentDataWithBody }\n | { type: \"unreadReplies\"; comments: CommentDataWithBody[] };\n\n/** @internal */\nexport const extractThreadNotificationData = async ({\n client,\n event,\n}: {\n client: Liveblocks;\n event: ThreadNotificationEvent;\n}): Promise<ThreadNotificationData | null> => {\n const { threadId, roomId, userId, inboxNotificationId } = event.data;\n const [thread, inboxNotification] = await Promise.all([\n client.getThread({ roomId, threadId }),\n client.getInboxNotification({ inboxNotificationId, userId }),\n ]);\n\n const notificationTriggerAt = new Date(event.data.triggeredAt);\n const unreadComments = getUnreadComments({\n comments: thread.comments,\n inboxNotification,\n userId,\n notificationTriggerAt,\n });\n\n if (unreadComments.length <= 0) {\n return null;\n }\n\n const userGroups = await getAllUserGroups(client, userId);\n\n const lastUnreadCommentWithMention = getLastUnreadCommentWithMention({\n comments: unreadComments,\n groups: userGroups,\n mentionedUserId: userId,\n });\n\n if (lastUnreadCommentWithMention !== null) {\n return { type: \"unreadMention\", comment: lastUnreadCommentWithMention };\n }\n\n return {\n type: \"unreadReplies\",\n comments: unreadComments,\n };\n};\n\n/**\n * @internal\n * Set the comment ID as the URL hash.\n */\nfunction generateCommentUrl({\n roomUrl,\n commentId,\n}: {\n roomUrl: string | undefined;\n commentId: string;\n}): string | undefined {\n if (!roomUrl) {\n return;\n }\n\n return generateUrl(roomUrl, undefined, commentId);\n}\n\nexport type CommentEmailData<BodyType, U extends BaseUserMeta = DU> = {\n id: string;\n threadId: string;\n roomId: string;\n createdAt: Date;\n url?: string;\n author: U;\n body: BodyType;\n};\n\nexport type ThreadNotificationEmailData<\n BodyType,\n U extends BaseUserMeta = DU,\n C extends CommentEmailData<BodyType, U> = CommentEmailData<BodyType, U>,\n> = (\n | {\n type: \"unreadReplies\";\n comments: C[];\n }\n | {\n type: \"unreadMention\";\n comment: C;\n }\n) & { roomInfo: DRI };\n\nexport type CommentEmailAsHtmlData<U extends BaseUserMeta = DU> =\n CommentEmailData<string, U>;\n\nexport type CommentEmailAsReactData<U extends BaseUserMeta = DU> =\n CommentEmailData<ReactNode, U>;\n\ntype PrepareThreadNotificationEmailOptions<U extends BaseUserMeta = DU> = {\n /**\n * A function that returns room info from room IDs.\n */\n resolveRoomInfo?: (args: ResolveRoomInfoArgs) => Awaitable<DRI | undefined>;\n\n /**\n * A function that returns user info from user IDs.\n * You should return a list of user objects of the same size, in the same order.\n */\n resolveUsers?: (\n args: ResolveUsersArgs\n ) => Awaitable<(U[\"info\"] | undefined)[] | undefined>;\n\n /**\n * A function that returns group info from group IDs.\n * You should return a list of group info objects of the same size, in the same order.\n */\n resolveGroupsInfo?: (\n args: ResolveGroupsInfoArgs\n ) => Awaitable<(DGI | undefined)[] | undefined>;\n};\n\n/**\n * @internal\n * exported for testing purposes.\n */\nexport async function prepareThreadNotificationEmail<\n BodyType,\n U extends BaseUserMeta = DU,\n>(\n client: Liveblocks,\n event: ThreadNotificationEvent,\n options: PrepareThreadNotificationEmailOptions<U>,\n elements: ConvertCommentBodyElements<BodyType, U>,\n callerName: string\n): Promise<ThreadNotificationEmailData<BodyType, U> | null> {\n const data = await extractThreadNotificationData({ client, event });\n if (data === null) {\n return null;\n }\n\n const roomInfo = options.resolveRoomInfo\n ? await options.resolveRoomInfo({ roomId: event.data.roomId })\n : undefined;\n\n const resolvedRoomInfo: DRI = {\n ...roomInfo,\n name: roomInfo?.name ?? event.data.roomId,\n };\n\n const batchUsersResolver = createBatchUsersResolver<U>({\n resolveUsers: options.resolveUsers,\n callerName,\n });\n const batchGroupsInfoResolver = createBatchGroupsInfoResolver({\n resolveGroupsInfo: options.resolveGroupsInfo,\n callerName,\n });\n\n switch (data.type) {\n case \"unreadMention\": {\n const { comment } = data;\n\n const authorsIds = [comment.userId];\n const authorsInfoPromise = batchUsersResolver.get(authorsIds);\n const commentBodyPromise = convertCommentBody<BodyType, U>(comment.body, {\n resolveUsers: ({ userIds }) => batchUsersResolver.get(userIds),\n resolveGroupsInfo: ({ groupIds }) =>\n batchGroupsInfoResolver.get(groupIds),\n elements,\n });\n\n await batchUsersResolver.resolve();\n await batchGroupsInfoResolver.resolve();\n\n const [authorsInfo, commentBody] = await Promise.all([\n authorsInfoPromise,\n commentBodyPromise,\n ]);\n\n const authorInfo = getResolvedForId(\n comment.userId,\n authorsIds,\n authorsInfo\n );\n const url = roomInfo?.url\n ? generateCommentUrl({\n roomUrl: roomInfo?.url,\n commentId: comment.id,\n })\n : undefined;\n\n return {\n type: \"unreadMention\",\n comment: {\n id: comment.id,\n threadId: comment.threadId,\n roomId: comment.roomId,\n author: {\n id: comment.userId,\n info: authorInfo ?? { name: comment.userId },\n } as U,\n createdAt: comment.createdAt,\n url,\n body: commentBody as BodyType,\n },\n roomInfo: resolvedRoomInfo,\n };\n }\n case \"unreadReplies\": {\n const { comments } = data;\n\n const authorsIds = comments.map((c) => c.userId);\n const authorsInfoPromise = batchUsersResolver.get(authorsIds);\n\n const commentBodiesPromises = comments.map((c) =>\n convertCommentBody<BodyType, U>(c.body, {\n resolveUsers: ({ userIds }) => batchUsersResolver.get(userIds),\n resolveGroupsInfo: ({ groupIds }) =>\n batchGroupsInfoResolver.get(groupIds),\n elements,\n })\n );\n\n await batchUsersResolver.resolve();\n await batchGroupsInfoResolver.resolve();\n\n const [authorsInfo, ...commentBodies] = await Promise.all([\n authorsInfoPromise,\n ...commentBodiesPromises,\n ]);\n\n return {\n type: \"unreadReplies\",\n comments: comments.map((comment, index) => {\n const authorInfo = getResolvedForId(\n comment.userId,\n authorsIds,\n authorsInfo\n );\n const commentBody = commentBodies[index] as BodyType;\n\n const url = generateCommentUrl({\n roomUrl: roomInfo?.url,\n commentId: comment.id,\n });\n\n return {\n id: comment.id,\n threadId: comment.threadId,\n roomId: comment.roomId,\n author: {\n id: comment.userId,\n info: authorInfo ?? { name: comment.userId },\n } as U,\n createdAt: comment.createdAt,\n url,\n body: commentBody,\n };\n }),\n roomInfo: resolvedRoomInfo,\n };\n }\n }\n}\n\n/**\n * The styles used to customize the html elements in the resulting html safe string.\n * Each styles has priority over the base styles inherited.\n */\nexport type ConvertCommentBodyAsHtmlStyles = {\n /**\n * The default inline CSS styles used to display paragraphs.\n */\n paragraph: CSSProperties;\n /**\n * The default inline CSS styles used to display text `<strong />` elements.\n */\n strong: CSSProperties;\n /**\n * The default inline CSS styles used to display text `<code />` elements.\n */\n code: CSSProperties;\n /**\n * The default inline CSS styles used to display links.\n */\n mention: CSSProperties;\n /**\n * The default inline CSS styles used to display mentions.\n */\n link: CSSProperties;\n};\n\nconst baseStyles: ConvertCommentBodyAsHtmlStyles = {\n paragraph: {\n fontSize: \"14px\",\n },\n strong: {\n fontWeight: 500,\n },\n code: {\n fontFamily:\n 'ui-monospace, Menlo, Monaco, \"Cascadia Mono\", \"Segoe UI Mono\", \"Roboto Mono\", \"Oxygen Mono\", \"Ubuntu Mono\", \"Source Code Pro\", \"Fira Mono\", \"Droid Sans Mono\", \"Consolas\", \"Courier New\", monospace',\n backgroundColor: \"rgba(0,0,0,0.05)\",\n border: \"solid 1px rgba(0,0,0,0.1)\",\n borderRadius: \"4px\",\n },\n mention: {\n color: \"blue\",\n },\n link: {\n textDecoration: \"underline\",\n },\n};\n\nexport type PrepareThreadNotificationEmailAsHtmlOptions<\n U extends BaseUserMeta = DU,\n> = PrepareThreadNotificationEmailOptions<U> & {\n /**\n * The styles used to customize the html elements in the resulting html safe string inside a comment body.\n * Each styles has priority over the base styles inherited.\n */\n styles?: Partial<ConvertCommentBodyAsHtmlStyles>;\n};\n\nexport type ThreadNotificationEmailDataAsHtml<U extends BaseUserMeta = DU> =\n ThreadNotificationEmailData<string, U, CommentEmailAsHtmlData<U>>;\n\n/**\n * Prepares data from a `ThreadNotificationEvent` and convert comment bodies as an html safe string.\n *\n * @param client The `Liveblocks` node client\n * @param event The `ThreadNotificationEvent` received in the webhook handler\n * @param options The optional options to provide to resolve users, resolve room info\n * and customize comment bodies html elements styles with inline CSS.\n *\n * It returns a `ThreadNotificationEmailDataAsHtml` or `null` if there are no unread comments (mention or replies).\n *\n * @example\n * import { Liveblocks} from \"@liveblocks/node\"\n * import { prepareThreadNotificationEmailAsHtml } from \"@liveblocks/emails\"\n *\n * const liveblocks = new Liveblocks({ secret: \"sk_...\" })\n * const emailData = prepareThreadNotificationEmailAsHtml(\n * liveblocks,\n * event,\n * {\n * resolveUsers,\n * resolveRoomInfo,\n * styles,\n * }\n * )\n *\n */\nexport async function prepareThreadNotificationEmailAsHtml(\n client: Liveblocks,\n event: ThreadNotificationEvent,\n options: PrepareThreadNotificationEmailAsHtmlOptions<BaseUserMeta> = {}\n): Promise<ThreadNotificationEmailDataAsHtml | null> {\n const styles = { ...baseStyles, ...options?.styles };\n const data = await prepareThreadNotificationEmail<string, BaseUserMeta>(\n client,\n event,\n {\n resolveUsers: options.resolveUsers,\n resolveGroupsInfo: options.resolveGroupsInfo,\n resolveRoomInfo: options.resolveRoomInfo,\n },\n {\n container: ({ children }) => children.join(\"\\n\"),\n paragraph: ({ children }) => {\n const unsafe = children.join(\"\");\n // prettier-ignore\n return unsafe ? html`<p style=\"${toInlineCSSString(styles.paragraph)}\">${htmlSafe(unsafe)}</p>` : unsafe;\n },\n text: ({ element }) => {\n // Note: construction following the schema 👇\n // <code><s><em><strong>{element.text}</strong></s></em></code>\n let children = element.text;\n\n if (!children) {\n return html`${children}`;\n }\n\n if (element.bold) {\n // prettier-ignore\n children = html`<strong style=\"${toInlineCSSString(styles.strong)}\">${children}</strong>`;\n }\n\n if (element.italic) {\n // prettier-ignore\n children = html`<em>${children}</em>`;\n }\n\n if (element.strikethrough) {\n // prettier-ignore\n children = html`<s>${children}</s>`;\n }\n\n if (element.code) {\n // prettier-ignore\n children = html`<code style=\"${toInlineCSSString(styles.code)}\">${children}</code>`;\n }\n\n return html`${children}`;\n },\n link: ({ element, href }) => {\n // prettier-ignore\n return html`<a href=\"${href}\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"${toInlineCSSString(styles.link)}\">${element.text ? html`${element.text}` : element.url}</a>`;\n },\n mention: ({ element, user, group }) => {\n // prettier-ignore\n return html`<span data-mention style=\"${toInlineCSSString(styles.mention)}\">${MENTION_CHARACTER}${user?.name ? html`${user?.name}` : group?.name ? html`${group?.name}` : element.id}</span>`;\n },\n },\n \"prepareThreadNotificationEmailAsHtml\"\n );\n\n if (data === null) {\n return null;\n }\n\n return data;\n}\n\nexport type CommentBodyContainerComponentProps = {\n /**\n * The blocks of the comment body\n */\n children: ReactNode;\n};\n\nexport type CommentBodyParagraphComponentProps = {\n /**\n * The text content of the paragraph.\n */\n children: ReactNode;\n};\n\nexport type CommentBodyTextComponentProps = {\n /**\n * The text element.\n */\n element: CommentBodyText;\n};\n\nexport type CommentBodyLinkComponentProps = {\n /**\n * The link element.\n */\n element: CommentBodyLink;\n\n /**\n * The absolute URL of the link.\n */\n href: string;\n};\n\nexport type CommentBodyMentionComponentProps<U extends BaseUserMeta = DU> = {\n /**\n * The mention element.\n */\n element: CommentBodyMention;\n\n /**\n * The mention's user info, if the mention is a user mention and the `resolvedUsers` option was provided.\n */\n user?: U[\"info\"];\n\n /**\n * The mention's group info, if the mention is a group mention and the `resolvedGroupsInfo` option was provided.\n */\n group?: DGI;\n};\n\nexport type ConvertCommentBodyAsReactComponents<U extends BaseUserMeta = DU> = {\n /**\n *\n * The component used to act as a container to wrap comment body blocks,\n */\n Container: ComponentType<CommentBodyContainerComponentProps>;\n /**\n * The component used to display paragraphs.\n */\n Paragraph: ComponentType<CommentBodyParagraphComponentProps>;\n\n /**\n * The component used to display text elements.\n */\n Text: ComponentType<CommentBodyTextComponentProps>;\n\n /**\n * The component used to display links.\n */\n Link: ComponentType<CommentBodyLinkComponentProps>;\n\n /**\n * The component used to display mentions.\n */\n Mention: ComponentType<CommentBodyMentionComponentProps<U>>;\n};\n\nconst baseComponents: ConvertCommentBodyAsReactComponents<BaseUserMeta> = {\n Container: ({ children }) => <div>{children}</div>,\n Paragraph: ({ children }) => <p>{children}</p>,\n Text: ({ element }) => {\n // Note: construction following the schema 👇\n // <code><s><em><strong>{element.text}</strong></s></em></code>\n let children: ReactNode = element.text;\n\n if (element.bold) {\n children = <strong>{children}</strong>;\n }\n\n if (element.italic) {\n children = <em>{children}</em>;\n }\n\n if (element.strikethrough) {\n children = <s>{children}</s>;\n }\n\n if (element.code) {\n children = <code>{children}</code>;\n }\n\n return <span>{children}</span>;\n },\n Link: ({ element, href }) => (\n <a href={href} target=\"_blank\" rel=\"noopener noreferrer\">\n {element.text ?? element.url}\n </a>\n ),\n Mention: ({ element, user, group }) => (\n <span data-mention>\n {MENTION_CHARACTER}\n {user?.name ?? group?.name ?? element.id}\n </span>\n ),\n};\n\nexport type PrepareThreadNotificationEmailAsReactOptions<\n U extends BaseUserMeta = DU,\n> = PrepareThreadNotificationEmailOptions<U> & {\n /**\n * The components used to customize the resulting React nodes inside a comment body.\n * Each components has priority over the base components inherited internally defined.\n */\n components?: Partial<ConvertCommentBodyAsReactComponents<U>>;\n};\n\nexport type ThreadNotificationEmailDataAsReact<U extends BaseUserMeta = DU> =\n ThreadNotificationEmailData<ReactNode, U, CommentEmailAsReactData<U>>;\n\n/**\n * Prepares data from a `ThreadNotificationEvent` and convert comment bodies as React nodes.\n *\n * @param client The `Liveblocks` node client\n * @param event The `ThreadNotificationEvent` received in the webhook handler\n * @param options The optional options to provide to resolve users, resolve room info and customize comment bodies React components.\n *\n * It returns a `ThreadNotificationEmailDataAsReact` or `null` if there are no unread comments (mention or replies).\n *\n * @example\n * import { Liveblocks} from \"@liveblocks/node\"\n * import { prepareThreadNotificationEmailAsReact } from \"@liveblocks/emails\"\n *\n * const liveblocks = new Liveblocks({ secret: \"sk_...\" })\n * const emailData = prepareThreadNotificationEmailAsReact(\n * liveblocks,\n * event,\n * {\n * resolveUsers,\n * resolveRoomInfo,\n * components,\n * }\n * )\n *\n */\nexport async function prepareThreadNotificationEmailAsReact(\n client: Liveblocks,\n event: ThreadNotificationEvent,\n options: PrepareThreadNotificationEmailAsReactOptions<BaseUserMeta> = {}\n): Promise<ThreadNotificationEmailDataAsReact | null> {\n const Components = { ...baseComponents, ...options?.components };\n const data = await prepareThreadNotificationEmail<ReactNode, BaseUserMeta>(\n client,\n event,\n {\n resolveUsers: options.resolveUsers,\n resolveGroupsInfo: options.resolveGroupsInfo,\n resolveRoomInfo: options.resolveRoomInfo,\n },\n {\n container: ({ children }) => (\n <Components.Container key=\"lb-comment-body-container\">\n {children}\n </Components.Container>\n ),\n paragraph: ({ children }, index) => (\n <Components.Paragraph key={`lb-comment-body-paragraph-${index}`}>\n {children}\n </Components.Paragraph>\n ),\n text: ({ element }, index) => (\n <Components.Text\n key={`lb-comment-body-text-${index}`}\n element={element}\n />\n ),\n link: ({ element, href }, index) => (\n <Components.Link\n key={`lb-comment-body-link-${index}`}\n element={element}\n href={href}\n />\n ),\n mention: ({ element, user, group }, index) =>\n element.id ? (\n <Components.Mention\n key={`lb-comment-body-mention-${index}`}\n element={element}\n user={user}\n group={group}\n />\n ) : null,\n },\n \"prepareThreadNotificationEmailAsReact\"\n );\n\n if (data === null) {\n return null;\n }\n\n return data;\n}\n","import type {\n Awaitable,\n BaseUserMeta,\n CommentBody,\n CommentBodyLink,\n CommentBodyMention,\n CommentBodyParagraph,\n CommentBodyText,\n DGI,\n DU,\n ResolveGroupsInfoArgs,\n ResolveUsersArgs,\n} from \"@liveblocks/core\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n isCommentBodyText,\n resolveMentionsInCommentBody,\n sanitizeUrl,\n} from \"@liveblocks/core\";\n\nimport { exists } from \"./lib/utils\";\n\nexport type CommentBodyContainerElementArgs<T> = {\n /**\n * The blocks of the comment body\n */\n children: T[];\n};\n\nexport type CommentBodyParagraphElementArgs<T> = {\n /**\n * The paragraph element.\n */\n element: CommentBodyParagraph;\n /**\n * The text content of the paragraph.\n */\n children: T[];\n};\n\nexport type CommentBodyTextElementArgs = {\n /**\n * The text element.\n */\n element: CommentBodyText;\n};\n\nexport type CommentBodyLinkElementArgs = {\n /**\n * The link element.\n */\n element: CommentBodyLink;\n\n /**\n * The absolute URL of the link.\n */\n href: string;\n};\n\nexport type CommentBodyMentionElementArgs<U extends BaseUserMeta = DU> = {\n /**\n * The mention element.\n */\n element: CommentBodyMention;\n\n /**\n * The mention's user info, if the mention is a user mention and the `resolveUsers` option was provided.\n */\n user?: U[\"info\"];\n\n /**\n * The mention's group info, if the mention is a group mention and the `resolveGroupsInfo` option was provided.\n */\n group?: DGI;\n};\n\n/**\n * Protocol:\n * Comment body elements to be converted to a custom format `T`\n */\nexport type ConvertCommentBodyElements<T, U extends BaseUserMeta = DU> = {\n /**\n * The container element used to display comment body blocks.\n */\n container: (args: CommentBodyContainerElementArgs<T>) => T;\n /**\n * The paragraph element used to display paragraphs.\n */\n paragraph: (args: CommentBodyParagraphElementArgs<T>, index: number) => T;\n /**\n * The text element used to display text elements.\n */\n text: (args: CommentBodyTextElementArgs, index: number) => T;\n /**\n * The link element used to display links.\n */\n link: (args: CommentBodyLinkElementArgs, index: number) => T;\n /**\n * The mention element used to display mentions.\n */\n mention: (args: CommentBodyMentionElementArgs<U>, index: number) => T;\n};\n\nexport type ConvertCommentBodyOptions<T, U extends BaseUserMeta = DU> = {\n /**\n * A function that returns user info from user IDs.\n * You should return a list of user objects of the same size, in the same order.\n */\n resolveUsers?: (\n args: ResolveUsersArgs\n ) => Awaitable<(U[\"info\"] | undefined)[] | undefined>;\n\n /**\n * A function that returns group info from group IDs.\n * You should return a list of group info objects of the same size, in the same order.\n */\n resolveGroupsInfo?: (\n args: ResolveGroupsInfoArgs\n ) => Awaitable<(DGI | undefined)[] | undefined>;\n\n /**\n * The elements used to customize the resulting format `T`.\n */\n elements: ConvertCommentBodyElements<T, U>;\n};\n\n/**\n * Convert a `CommentBody` into a custom format `T`\n */\nexport async function convertCommentBody<T, U extends BaseUserMeta = DU>(\n body: CommentBody,\n options: ConvertCommentBodyOptions<T, U>\n): Promise<T> {\n const { users: resolvedUsers, groups: resolvedGroupsInfo } =\n await resolveMentionsInCommentBody(\n body,\n options?.resolveUsers,\n options?.resolveGroupsInfo\n );\n\n const blocks: T[] = body.content\n .map((block, index) => {\n switch (block.type) {\n case \"paragraph\": {\n const children: T[] = block.children\n .map((inline, inlineIndex) => {\n if (isCommentBodyMention(inline)) {\n return options.elements.mention(\n {\n element: inline,\n user:\n inline.kind === \"user\"\n ? resolvedUsers.get(inline.id)\n : undefined,\n group:\n inline.kind === \"group\"\n ? resolvedGroupsInfo.get(inline.id)\n : undefined,\n },\n inlineIndex\n );\n }\n\n if (isCommentBodyLink(inline)) {\n const href = sanitizeUrl(inline.url);\n\n // If the URL is invalid, its text/URL are used as plain text.\n if (href === null) {\n return options.elements.text(\n {\n element: { text: inline.text ?? inline.url },\n },\n inlineIndex\n );\n }\n\n return options.elements.link(\n {\n element: inline,\n href,\n },\n inlineIndex\n );\n }\n\n if (isCommentBodyText(inline)) {\n return options.elements.text({ element: inline }, inlineIndex);\n }\n\n return null;\n })\n .filter(exists);\n\n return options.elements.paragraph(\n { element: block, children },\n index\n );\n }\n default:\n console.warn(\n `Unsupported comment body block type: \"${JSON.stringify(block.type)}\"`\n );\n return null;\n }\n })\n .filter(exists);\n\n return options.elements.container({ children: blocks });\n}\n","import type { CommentBody, CommentData } from \"@liveblocks/core\";\n\nexport type CommentDataWithBody = Omit<CommentData, \"body\" | \"deletedAt\"> & {\n body: CommentBody;\n deletedAt?: never;\n};\n\nconst isCommentDataWithBody = (\n comment: CommentData\n): comment is CommentDataWithBody => {\n return comment.body !== undefined && comment.deletedAt === undefined;\n};\n\nexport function filterCommentsWithBody(\n comments: CommentData[]\n): CommentDataWithBody[] {\n const commentsWithBody: CommentDataWithBody[] = [];\n for (const comment of comments) {\n if (isCommentDataWithBody(comment)) {\n commentsWithBody.push(comment);\n }\n }\n return commentsWithBody;\n}\n"]}
|