{
  "version": 3,
  "sources": ["../../src/shapes/TLImageShape.ts"],
  "sourcesContent": ["import { T } from '@tldraw/validate'\nimport { assetIdValidator } from '../assets/TLBaseAsset'\nimport { vecModelValidator } from '../misc/geometry-types'\nimport { TLAssetId } from '../records/TLAsset'\nimport { createShapePropsMigrationIds, createShapePropsMigrationSequence } from '../records/TLShape'\nimport { RecordProps } from '../recordsWithProps'\nimport { TLShapeCrop } from './ShapeWithCrop'\nimport { TLBaseShape } from './TLBaseShape'\n\n/**\n * Validator for image shape crop data. Defines the structure for cropping an image,\n * specifying the visible region within the original image bounds.\n *\n * @public\n * @example\n * ```ts\n * const cropData: TLShapeCrop = {\n *   topLeft: { x: 0.1, y: 0.1 },\n *   bottomRight: { x: 0.9, y: 0.9 },\n *   isCircle: false\n * }\n *\n * const isValid = ImageShapeCrop.isValid(cropData)\n * ```\n */\nexport const ImageShapeCrop: T.ObjectValidator<TLShapeCrop> = T.object({\n\ttopLeft: vecModelValidator,\n\tbottomRight: vecModelValidator,\n\tisCircle: T.boolean.optional(),\n})\n\n/**\n * Properties for an image shape. Image shapes display raster images on the canvas,\n * with support for cropping, flipping, and asset management.\n *\n * @public\n * @example\n * ```ts\n * const imageProps: TLImageShapeProps = {\n *   w: 300,\n *   h: 200,\n *   playing: true,\n *   url: 'https://example.com/image.jpg',\n *   assetId: 'asset:image123',\n *   crop: null,\n *   flipX: false,\n *   flipY: false,\n *   altText: 'A sample image'\n * }\n * ```\n */\nexport interface TLImageShapeProps {\n\t/** Width of the image shape in canvas units */\n\tw: number\n\t/** Height of the image shape in canvas units */\n\th: number\n\t/** Whether animated images (like GIFs) should play */\n\tplaying: boolean\n\t/** URL of the image resource */\n\turl: string\n\t/** ID of the associated asset record, null if no asset */\n\tassetId: TLAssetId | null\n\t/** Crop data defining visible region of the image, null for no cropping */\n\tcrop: TLShapeCrop | null\n\t/** Whether to flip the image horizontally */\n\tflipX: boolean\n\t/** Whether to flip the image vertically */\n\tflipY: boolean\n\t/** Alternative text for accessibility and when image fails to load */\n\taltText: string\n}\n\n/**\n * An image shape representing a raster image on the canvas. Image shapes can display\n * various image formats and support features like cropping, flipping, and asset management.\n *\n * @public\n * @example\n * ```ts\n * const imageShape: TLImageShape = {\n *   id: 'shape:image1',\n *   type: 'image',\n *   x: 100,\n *   y: 100,\n *   rotation: 0,\n *   index: 'a1',\n *   parentId: 'page:main',\n *   isLocked: false,\n *   opacity: 1,\n *   props: {\n *     w: 400,\n *     h: 300,\n *     playing: true,\n *     url: '',\n *     assetId: 'asset:photo1',\n *     crop: null,\n *     flipX: false,\n *     flipY: false,\n *     altText: 'Sample photo'\n *   },\n *   meta: {},\n *   typeName: 'shape'\n * }\n * ```\n */\nexport type TLImageShape = TLBaseShape<'image', TLImageShapeProps>\n\n/**\n * Validation schema for image shape properties. Defines the runtime validation rules\n * for all properties of image shapes, ensuring data integrity and type safety.\n *\n * @public\n * @example\n * ```ts\n * import { imageShapeProps } from '@tldraw/tlschema'\n *\n * // Used internally by the validation system\n * const validator = T.object(imageShapeProps)\n * const validatedProps = validator.validate(someImageProps)\n * ```\n */\nexport const imageShapeProps: RecordProps<TLImageShape> = {\n\tw: T.nonZeroNumber,\n\th: T.nonZeroNumber,\n\tplaying: T.boolean,\n\turl: T.linkUrl,\n\tassetId: assetIdValidator.nullable(),\n\tcrop: ImageShapeCrop.nullable(),\n\tflipX: T.boolean,\n\tflipY: T.boolean,\n\taltText: T.string,\n}\n\nconst Versions = createShapePropsMigrationIds('image', {\n\tAddUrlProp: 1,\n\tAddCropProp: 2,\n\tMakeUrlsValid: 3,\n\tAddFlipProps: 4,\n\tAddAltText: 5,\n})\n\n/**\n * Version identifiers for image shape migrations. These version numbers track\n * schema changes over time to enable proper data migration between versions.\n *\n * @public\n */\nexport { Versions as imageShapeVersions }\n\n/**\n * Migration sequence for image shapes. Handles schema evolution over time by defining\n * how to upgrade and downgrade image shape data between different versions. Includes\n * migrations for URL properties, crop functionality, flip properties, and accessibility features.\n *\n * @public\n */\nexport const imageShapeMigrations = createShapePropsMigrationSequence({\n\tsequence: [\n\t\t{\n\t\t\tid: Versions.AddUrlProp,\n\t\t\tup: (props) => {\n\t\t\t\tprops.url = ''\n\t\t\t},\n\t\t\tdown: 'retired',\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddCropProp,\n\t\t\tup: (props) => {\n\t\t\t\tprops.crop = null\n\t\t\t},\n\t\t\tdown: (props) => {\n\t\t\t\tdelete props.crop\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeUrlsValid,\n\t\t\tup: (props) => {\n\t\t\t\tif (!T.linkUrl.isValid(props.url)) {\n\t\t\t\t\tprops.url = ''\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (_props) => {\n\t\t\t\t// noop\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddFlipProps,\n\t\t\tup: (props) => {\n\t\t\t\tprops.flipX = false\n\t\t\t\tprops.flipY = false\n\t\t\t},\n\t\t\tdown: (props) => {\n\t\t\t\tdelete props.flipX\n\t\t\t\tdelete props.flipY\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddAltText,\n\t\t\tup: (props) => {\n\t\t\t\tprops.altText = ''\n\t\t\t},\n\t\t\tdown: (props) => {\n\t\t\t\tdelete props.altText\n\t\t\t},\n\t\t},\n\t],\n})\n"],
  "mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAElC,SAAS,8BAA8B,yCAAyC;AAqBzE,MAAM,iBAAiD,EAAE,OAAO;AAAA,EACtE,SAAS;AAAA,EACT,aAAa;AAAA,EACb,UAAU,EAAE,QAAQ,SAAS;AAC9B,CAAC;AA4FM,MAAM,kBAA6C;AAAA,EACzD,GAAG,EAAE;AAAA,EACL,GAAG,EAAE;AAAA,EACL,SAAS,EAAE;AAAA,EACX,KAAK,EAAE;AAAA,EACP,SAAS,iBAAiB,SAAS;AAAA,EACnC,MAAM,eAAe,SAAS;AAAA,E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