{
  "version": 3,
  "sources": ["../../src/records/TLShape.ts"],
  "sourcesContent": ["import { createRecordType, defineMigrations, RecordId, UnknownRecord } from '@bigbluebutton/store'\nimport { mapObjectMapValues } from '@bigbluebutton/utils'\nimport { T } from '@bigbluebutton/validate'\nimport { nanoid } from 'nanoid'\nimport { SchemaShapeInfo } from '../createTLSchema'\nimport { TLArrowShape } from '../shapes/TLArrowShape'\nimport { createShapeValidator, TLBaseShape } from '../shapes/TLBaseShape'\nimport { TLBookmarkShape } from '../shapes/TLBookmarkShape'\nimport { TLDrawShape } from '../shapes/TLDrawShape'\nimport { TLEmbedShape } from '../shapes/TLEmbedShape'\nimport { TLFrameShape } from '../shapes/TLFrameShape'\nimport { TLGeoShape } from '../shapes/TLGeoShape'\nimport { TLGroupShape } from '../shapes/TLGroupShape'\nimport { TLHighlightShape } from '../shapes/TLHighlightShape'\nimport { TLImageShape } from '../shapes/TLImageShape'\nimport { TLLineShape } from '../shapes/TLLineShape'\nimport { TLNoteShape } from '../shapes/TLNoteShape'\nimport { TLTextShape } from '../shapes/TLTextShape'\nimport { TLVideoShape } from '../shapes/TLVideoShape'\nimport { StyleProp } from '../styles/StyleProp'\nimport { TLPageId } from './TLPage'\n\n/**\n * The default set of shapes that are available in the editor.\n *\n * @public */\nexport type TLDefaultShape =\n\t| TLArrowShape\n\t| TLBookmarkShape\n\t| TLDrawShape\n\t| TLEmbedShape\n\t| TLFrameShape\n\t| TLGeoShape\n\t| TLGroupShape\n\t| TLImageShape\n\t| TLLineShape\n\t| TLNoteShape\n\t| TLTextShape\n\t| TLVideoShape\n\t| TLHighlightShape\n\n/**\n * A type for a shape that is available in the editor but whose type is\n * unknown\u2014either one of the editor's default shapes or else a custom shape.\n *\n * @public */\nexport type TLUnknownShape = TLBaseShape<string, object>\n\n/**\n * The set of all shapes that are available in the editor, including unknown shapes.\n *\n * @public\n */\nexport type TLShape = TLDefaultShape | TLUnknownShape\n\n/** @public */\nexport type TLShapePartial<T extends TLShape = TLShape> = T extends T\n\t? {\n\t\t\tid: TLShapeId\n\t\t\ttype: T['type']\n\t\t\tprops?: Partial<T['props']>\n\t\t\tmeta?: Partial<T['meta']>\n\t  } & Partial<Omit<T, 'type' | 'id' | 'props' | 'meta'>>\n\t: never\n\n/** @public */\nexport type TLShapeId = RecordId<TLUnknownShape>\n\n// evil type shit that will get deleted in the next PR\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void\n\t? I\n\t: never\n\ntype Identity<T> = { [K in keyof T]: T[K] }\n\n/** @public */\nexport type TLShapeProps = Identity<UnionToIntersection<TLDefaultShape['props']>>\n\n/** @public */\nexport type TLShapeProp = keyof TLShapeProps\n\n/** @public */\nexport type TLParentId = TLPageId | TLShapeId\n\n/** @internal */\nexport const rootShapeVersions = {\n\tAddIsLocked: 1,\n\tHoistOpacity: 2,\n\tAddMeta: 3,\n} as const\n\n/** @internal */\nexport const rootShapeMigrations = defineMigrations({\n\tcurrentVersion: rootShapeVersions.AddMeta,\n\tmigrators: {\n\t\t[rootShapeVersions.AddIsLocked]: {\n\t\t\tup: (record) => {\n\t\t\t\treturn {\n\t\t\t\t\t...record,\n\t\t\t\t\tisLocked: false,\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (record) => {\n\t\t\t\tconst { isLocked: _, ...rest } = record\n\t\t\t\treturn {\n\t\t\t\t\t...rest,\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t[rootShapeVersions.HoistOpacity]: {\n\t\t\tup: ({ props: { opacity, ...props }, ...record }) => {\n\t\t\t\treturn {\n\t\t\t\t\t...record,\n\t\t\t\t\topacity: Number(opacity ?? '1'),\n\t\t\t\t\tprops,\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: ({ opacity, ...record }) => {\n\t\t\t\treturn {\n\t\t\t\t\t...record,\n\t\t\t\t\tprops: {\n\t\t\t\t\t\t...record.props,\n\t\t\t\t\t\topacity:\n\t\t\t\t\t\t\topacity < 0.175\n\t\t\t\t\t\t\t\t? '0.1'\n\t\t\t\t\t\t\t\t: opacity < 0.375\n\t\t\t\t\t\t\t\t? '0.25'\n\t\t\t\t\t\t\t\t: opacity < 0.625\n\t\t\t\t\t\t\t\t? '0.5'\n\t\t\t\t\t\t\t\t: opacity < 0.875\n\t\t\t\t\t\t\t\t? '0.75'\n\t\t\t\t\t\t\t\t: '1',\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t[rootShapeVersions.AddMeta]: {\n\t\t\tup: (record) => {\n\t\t\t\treturn {\n\t\t\t\t\t...record,\n\t\t\t\t\tmeta: {},\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: ({ meta: _, ...record }) => {\n\t\t\t\treturn {\n\t\t\t\t\t...record,\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t},\n})\n\n/** @public */\nexport function isShape(record?: UnknownRecord): record is TLShape {\n\tif (!record) return false\n\treturn record.typeName === 'shape'\n}\n\n/** @public */\nexport function isShapeId(id?: string): id is TLShapeId {\n\tif (!id) return false\n\treturn id.startsWith('shape:')\n}\n\n/** @public */\nexport function createShapeId(id?: string): TLShapeId {\n\treturn `shape:${id ?? nanoid()}` as TLShapeId\n}\n\n/** @internal */\nexport function getShapePropKeysByStyle(props: Record<string, T.Validatable<any>>) {\n\tconst propKeysByStyle = new Map<StyleProp<unknown>, string>()\n\tfor (const [key, prop] of Object.entries(props)) {\n\t\tif (prop instanceof StyleProp) {\n\t\t\tif (propKeysByStyle.has(prop)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Duplicate style prop ${prop.id}. Each style prop can only be used once within a shape.`\n\t\t\t\t)\n\t\t\t}\n\t\t\tpropKeysByStyle.set(prop, key)\n\t\t}\n\t}\n\treturn propKeysByStyle\n}\n\n/** @internal */\nexport function createShapeRecordType(shapes: Record<string, SchemaShapeInfo>) {\n\treturn createRecordType<TLShape>('shape', {\n\t\tmigrations: defineMigrations({\n\t\t\tcurrentVersion: rootShapeMigrations.currentVersion,\n\t\t\tfirstVersion: rootShapeMigrations.firstVersion,\n\t\t\tmigrators: rootShapeMigrations.migrators,\n\t\t\tsubTypeKey: 'type',\n\t\t\tsubTypeMigrations: mapObjectMapValues(shapes, (_, v) => v.migrations ?? defineMigrations({})),\n\t\t}),\n\t\tscope: 'document',\n\t\tvalidator: T.model(\n\t\t\t'shape',\n\t\t\tT.union(\n\t\t\t\t'type',\n\t\t\t\tmapObjectMapValues(shapes, (type, { props, meta }) =>\n\t\t\t\t\tcreateShapeValidator(type, props, meta)\n\t\t\t\t)\n\t\t\t)\n\t\t),\n\t}).withDefaultProperties(() => ({\n\t\tx: 0,\n\t\ty: 0,\n\t\trotation: 0,\n\t\tisLocked: false,\n\t\topacity: 1,\n\t\tmeta: {},\n\t}))\n}\n"],
  "mappings": "AAAA,SAAS,kBAAkB,wBAAiD;AAC5E,SAAS,0BAA0B;AACnC,SAAS,SAAS;AAClB,SAAS,cAAc;AAGvB,SAAS,4BAAyC;AAalD,SAAS,iBAAiB;AAkEnB,MAAM,oBAAoB;AAAA,EAChC,aAAa;AAAA,EACb,cAAc;AAAA,EACd,SAAS;AACV;AAGO,MAAM,sBAAsB,iBAAiB;AAAA,EACnD,gBAAgB,kBAAkB;AAAA,EAClC,WAAW;AAAA,IACV,CAAC,kBAAkB,WAAW,GAAG;AAAA,MAChC,IAAI,CAAC,WAAW;AACf,eAAO;AAAA,UACN,GAAG;AAAA,UACH,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,MAAM,CAAC,WAAW;AACjB,cAAM,EAAE,UAAU,GAAG,GAAG,KAAK,IAAI;AACjC,eAAO;AAAA,UACN,GAAG;AAAA,QACJ;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAC,kBAAkB,YAAY,GAAG;AAAA,MACjC,IAAI,CAAC,EAAE,OAAO,EAAE,SAAS,GAAG,MAAM,GAAG,GAAG,OAAO,MAAM;AACpD,eAAO;AAAA,UACN,GAAG;AAAA,UACH,SAAS,OAAO,WAAW,GAAG;AAAA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