{
  "version": 3,
  "sources": ["../../src/records/TLPresence.ts"],
  "sourcesContent": ["import {\n\tBaseRecord,\n\tcreateMigrationIds,\n\tcreateRecordMigrationSequence,\n\tcreateRecordType,\n\tRecordId,\n} from '@tldraw/store'\nimport { JsonObject } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\nimport { BoxModel, boxModelValidator } from '../misc/geometry-types'\nimport { idValidator } from '../misc/id-validator'\nimport { cursorTypeValidator, TLCursor } from '../misc/TLCursor'\nimport { scribbleValidator, TLScribble } from '../misc/TLScribble'\nimport { TLPageId } from './TLPage'\nimport { TLShapeId } from './TLShape'\n\n/**\n * Represents the presence state of a user in a collaborative tldraw session.\n * This record tracks what another user is doing: their cursor position, selected\n * shapes, current page, and other real-time activity indicators.\n *\n * Instance presence records are used in multiplayer environments to show\n * where other collaborators are working and what they're doing.\n *\n * @example\n * ```ts\n * const presence: TLInstancePresence = {\n *   id: 'instance_presence:user123',\n *   typeName: 'instance_presence',\n *   userId: 'user123',\n *   userName: 'Alice',\n *   color: '#FF6B6B',\n *   cursor: { x: 100, y: 150, type: 'default', rotation: 0 },\n *   currentPageId: 'page:main',\n *   selectedShapeIds: ['shape:rect1']\n * }\n * ```\n *\n * @public\n */\nexport interface TLInstancePresence extends BaseRecord<'instance_presence', TLInstancePresenceID> {\n\tuserId: string\n\tuserName: string\n\tlastActivityTimestamp: number | null\n\tcolor: string // can be any hex color\n\tcamera: { x: number; y: number; z: number } | null\n\tselectedShapeIds: TLShapeId[]\n\tcurrentPageId: TLPageId\n\tbrush: BoxModel | null\n\tscribbles: TLScribble[]\n\tscreenBounds: BoxModel | null\n\tfollowingUserId: string | null\n\tcursor: {\n\t\tx: number\n\t\ty: number\n\t\ttype: TLCursor['type']\n\t\trotation: number\n\t} | null\n\tchatMessage: string\n\tmeta: JsonObject\n}\n\n/**\n * A unique identifier for TLInstancePresence records.\n *\n * Instance presence IDs follow the format 'instance_presence:' followed\n * by a unique identifier, typically the user ID.\n *\n * @example\n * ```ts\n * const presenceId: TLInstancePresenceID = 'instance_presence:user123'\n * ```\n *\n * @public\n */\nexport type TLInstancePresenceID = RecordId<TLInstancePresence>\n\n/**\n * Runtime validator for TLInstancePresence records. Validates the structure\n * and types of all instance presence properties to ensure data integrity.\n *\n * @example\n * ```ts\n * const presence = {\n *   id: 'instance_presence:user1',\n *   typeName: 'instance_presence',\n *   userId: 'user1',\n *   userName: 'John',\n *   color: '#007AFF',\n *   cursor: { x: 0, y: 0, type: 'default', rotation: 0 },\n *   currentPageId: 'page:main',\n *   selectedShapeIds: []\n * }\n * const isValid = instancePresenceValidator.isValid(presence) // true\n * ```\n *\n * @public\n */\nexport const instancePresenceValidator: T.Validator<TLInstancePresence> = T.model(\n\t'instance_presence',\n\tT.object({\n\t\ttypeName: T.literal('instance_presence'),\n\t\tid: idValidator<TLInstancePresenceID>('instance_presence'),\n\t\tuserId: T.string,\n\t\tuserName: T.string,\n\t\tlastActivityTimestamp: T.number.nullable(),\n\t\tfollowingUserId: T.string.nullable(),\n\t\tcursor: T.object({\n\t\t\tx: T.number,\n\t\t\ty: T.number,\n\t\t\ttype: cursorTypeValidator,\n\t\t\trotation: T.number,\n\t\t}).nullable(),\n\t\tcolor: T.string,\n\t\tcamera: T.object({\n\t\t\tx: T.number,\n\t\t\ty: T.number,\n\t\t\tz: T.number,\n\t\t}).nullable(),\n\t\tscreenBounds: boxModelValidator.nullable(),\n\t\tselectedShapeIds: T.arrayOf(idValidator<TLShapeId>('shape')),\n\t\tcurrentPageId: idValidator<TLPageId>('page'),\n\t\tbrush: boxModelValidator.nullable(),\n\t\tscribbles: T.arrayOf(scribbleValidator),\n\t\tchatMessage: T.string,\n\t\tmeta: T.jsonValue as T.ObjectValidator<JsonObject>,\n\t})\n)\n\n/**\n * Migration version identifiers for TLInstancePresence records. Each version\n * represents a schema change that requires data transformation when loading\n * older documents.\n *\n * @public\n */\nexport const instancePresenceVersions = createMigrationIds('com.tldraw.instance_presence', {\n\tAddScribbleDelay: 1,\n\tRemoveInstanceId: 2,\n\tAddChatMessage: 3,\n\tAddMeta: 4,\n\tRenameSelectedShapeIds: 5,\n\tNullableCameraCursor: 6,\n} as const)\n\n/**\n * Migration sequence for TLInstancePresence records. Defines how to transform\n * instance presence records between different schema versions, ensuring data\n * compatibility when loading documents created with different versions.\n *\n * @example\n * ```ts\n * // Migrations are applied automatically when loading documents\n * const migrated = instancePresenceMigrations.migrate(oldPresence, targetVersion)\n * ```\n *\n * @public\n */\nexport const instancePresenceMigrations = createRecordMigrationSequence({\n\tsequenceId: 'com.tldraw.instance_presence',\n\trecordType: 'instance_presence',\n\tsequence: [\n\t\t{\n\t\t\tid: instancePresenceVersions.AddScribbleDelay,\n\t\t\tup: (instance: any) => {\n\t\t\t\tif (instance.scribble !== null) {\n\t\t\t\t\tinstance.scribble.delay = 0\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: instancePresenceVersions.RemoveInstanceId,\n\t\t\tup: (instance: any) => {\n\t\t\t\tdelete instance.instanceId\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: instancePresenceVersions.AddChatMessage,\n\t\t\tup: (instance: any) => {\n\t\t\t\tinstance.chatMessage = ''\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: instancePresenceVersions.AddMeta,\n\t\t\tup: (record: any) => {\n\t\t\t\trecord.meta = {}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: instancePresenceVersions.RenameSelectedShapeIds,\n\t\t\tup: (_record) => {\n\t\t\t\t// noop, whoopsie\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: instancePresenceVersions.NullableCameraCursor,\n\t\t\tup: (_record: any) => {\n\t\t\t\t// noop\n\t\t\t},\n\t\t\tdown: (record: any) => {\n\t\t\t\tif (record.camera === null) {\n\t\t\t\t\trecord.camera = { x: 0, y: 0, z: 1 }\n\t\t\t\t}\n\t\t\t\tif (record.lastActivityTimestamp === null) {\n\t\t\t\t\trecord.lastActivityTimestamp = 0\n\t\t\t\t}\n\t\t\t\tif (record.cursor === null) {\n\t\t\t\t\trecord.cursor = { type: 'default', x: 0, y: 0, rotation: 0 }\n\t\t\t\t}\n\t\t\t\tif (record.screenBounds === null) {\n\t\t\t\t\trecord.screenBounds = { x: 0, y: 0, w: 1, h: 1 }\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t],\n})\n\n/**\n * The RecordType definition for TLInstancePresence records. Defines validation,\n * scope, and default properties for instance presence records.\n *\n * Instance presence records are scoped to the presence level, meaning they\n * represent real-time collaborative state that is ephemeral and tied to\n * active user sessions.\n *\n * @example\n * ```ts\n * const presence = InstancePresenceRecordType.create({\n *   id: 'instance_presence:user1',\n *   userId: 'user1',\n *   userName: 'Alice',\n *   color: '#FF6B6B',\n *   currentPageId: 'page:main'\n * })\n * ```\n *\n * @public\n */\nexport const InstancePresenceRecordType = createRecordType<TLInstancePresence>(\n\t'instance_presence',\n\t{\n\t\tvalidator: instancePresenceValidator,\n\t\tscope: 'presence',\n\t}\n).withDefaultProperties(() => ({\n\tlastActivityTimestamp: null,\n\tfollowingUserId: null,\n\tcolor: '#FF0000',\n\tcamera: null,\n\tcursor: null,\n\tscreenBounds: null,\n\tselectedShapeIds: [],\n\tbrush: null,\n\tscribbles: [],\n\tchatMessage: '',\n\tmeta: {},\n}))\n"],
  "mappings": "AAAA;AAAA,EAEC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AAEP,SAAS,SAAS;AAClB,SAAmB,yBAAyB;AAC5C,SAAS,mBAAmB;AAC5B,SAAS,2BAAqC;AAC9C,SAAS,yBAAqC;AAsFvC,MAAM,4BAA6D,EAAE;AAAA,EAC3E;AAAA,EACA,EAAE,OAAO;AAAA,IACR,UAAU,EAAE,QAAQ,mBAAmB;AAAA,IACvC,IAAI,YAAkC,mBAAmB;AAAA,IACzD,QAAQ,EAAE;AAAA,IACV,UAAU,EAAE;AAAA,IACZ,uBAAuB,EAAE,OAAO,SAAS;AAAA,IACzC,iBAAiB,EAAE,OAAO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