@tldraw/tlschema 4.5.0-next.dad6df23ab1f → 4.5.0

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.
@@ -35,7 +35,8 @@ const imageAssetValidator = (0, import_TLBaseAsset.createAssetValidator)(
35
35
  isAnimated: import_validate.T.boolean,
36
36
  mimeType: import_validate.T.string.nullable(),
37
37
  src: import_validate.T.srcUrl.nullable(),
38
- fileSize: import_validate.T.nonZeroNumber.optional()
38
+ fileSize: import_validate.T.nonZeroNumber.optional(),
39
+ pixelRatio: import_validate.T.positiveNumber.optional()
39
40
  })
40
41
  );
41
42
  const Versions = (0, import_store.createMigrationIds)("com.tldraw.asset.image", {
@@ -43,7 +44,8 @@ const Versions = (0, import_store.createMigrationIds)("com.tldraw.asset.image",
43
44
  RenameWidthHeight: 2,
44
45
  MakeUrlsValid: 3,
45
46
  AddFileSize: 4,
46
- MakeFileSizeOptional: 5
47
+ MakeFileSizeOptional: 5,
48
+ AddPixelRatio: 6
47
49
  });
48
50
  const imageAssetMigrations = (0, import_store.createRecordMigrationSequence)({
49
51
  sequenceId: "com.tldraw.asset.image",
@@ -105,6 +107,14 @@ const imageAssetMigrations = (0, import_store.createRecordMigrationSequence)({
105
107
  asset.props.fileSize = -1;
106
108
  }
107
109
  }
110
+ },
111
+ {
112
+ id: Versions.AddPixelRatio,
113
+ up: (_asset) => {
114
+ },
115
+ down: (asset) => {
116
+ delete asset.props.pixelRatio;
117
+ }
108
118
  }
109
119
  ]
110
120
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/assets/TLImageAsset.ts"],
4
- "sourcesContent": ["import { createMigrationIds, createRecordMigrationSequence } from '@tldraw/store'\nimport { T } from '@tldraw/validate'\nimport { TLAsset } from '../records/TLAsset'\nimport { TLBaseAsset, createAssetValidator } from './TLBaseAsset'\n\n/**\n * An asset for images such as PNGs and JPEGs, used by the TLImageShape.\n *\n * @public */\nexport type TLImageAsset = TLBaseAsset<\n\t'image',\n\t{\n\t\tw: number\n\t\th: number\n\t\tname: string\n\t\tisAnimated: boolean\n\t\tmimeType: string | null\n\t\tsrc: string | null\n\t\tfileSize?: number\n\t}\n>\n\n/**\n * Validator for image assets. Validates the structure and properties of TLImageAsset records\n * to ensure data integrity when image assets are stored or retrieved from the tldraw store.\n *\n * @example\n * ```ts\n * import { imageAssetValidator } from '@tldraw/tlschema'\n *\n * const imageAsset = {\n * id: 'asset:image123',\n * typeName: 'asset',\n * type: 'image',\n * props: {\n * w: 800,\n * h: 600,\n * name: 'photo.jpg',\n * isAnimated: false,\n * mimeType: 'image/jpeg',\n * src: 'https://example.com/photo.jpg',\n * fileSize: 156000\n * },\n * meta: {}\n * }\n *\n * // Validate the asset\n * const isValid = imageAssetValidator.validate(imageAsset)\n * ```\n *\n * @public\n */\nexport const imageAssetValidator: T.Validator<TLImageAsset> = createAssetValidator(\n\t'image',\n\tT.object({\n\t\tw: T.number,\n\t\th: T.number,\n\t\tname: T.string,\n\t\tisAnimated: T.boolean,\n\t\tmimeType: T.string.nullable(),\n\t\tsrc: T.srcUrl.nullable(),\n\t\tfileSize: T.nonZeroNumber.optional(),\n\t})\n)\n\nconst Versions = createMigrationIds('com.tldraw.asset.image', {\n\tAddIsAnimated: 1,\n\tRenameWidthHeight: 2,\n\tMakeUrlsValid: 3,\n\tAddFileSize: 4,\n\tMakeFileSizeOptional: 5,\n} as const)\n\n/**\n * Migration version identifiers for image assets. These define the different schema versions\n * that image assets have gone through during the evolution of the tldraw data model.\n *\n * @example\n * ```ts\n * import { imageAssetVersions } from '@tldraw/tlschema'\n *\n * // Access specific version IDs\n * console.log(imageAssetVersions.AddIsAnimated) // Version when isAnimated was added\n * console.log(imageAssetVersions.RenameWidthHeight) // Version when width/height became w/h\n * ```\n *\n * @public\n */\nexport { Versions as imageAssetVersions }\n\n/**\n * Migration sequence for image assets. Handles the evolution of the image asset schema\n * over time, providing both forward (up) and backward (down) migration functions to\n * maintain compatibility across different versions of the tldraw data model.\n *\n * The sequence includes migrations for:\n * - Adding the `isAnimated` property to track animated images\n * - Renaming `width`/`height` properties to shorter `w`/`h` names\n * - Ensuring URLs are valid format\n * - Adding file size tracking\n * - Making file size optional\n *\n *\n * @public\n */\nexport const imageAssetMigrations = createRecordMigrationSequence({\n\tsequenceId: 'com.tldraw.asset.image',\n\trecordType: 'asset',\n\tfilter: (asset) => (asset as TLAsset).type === 'image',\n\tsequence: [\n\t\t{\n\t\t\tid: Versions.AddIsAnimated,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.isAnimated = false\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.isAnimated\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.RenameWidthHeight,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.w = asset.props.width\n\t\t\t\tasset.props.h = asset.props.height\n\t\t\t\tdelete asset.props.width\n\t\t\t\tdelete asset.props.height\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tasset.props.width = asset.props.w\n\t\t\t\tasset.props.height = asset.props.h\n\t\t\t\tdelete asset.props.w\n\t\t\t\tdelete asset.props.h\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeUrlsValid,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (!T.srcUrl.isValid(asset.props.src)) {\n\t\t\t\t\tasset.props.src = ''\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (_asset) => {\n\t\t\t\t// noop\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddFileSize,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.fileSize = -1\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.fileSize\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeFileSizeOptional,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (asset.props.fileSize === -1) {\n\t\t\t\t\tasset.props.fileSize = undefined\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tif (asset.props.fileSize === undefined) {\n\t\t\t\t\tasset.props.fileSize = -1\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t],\n})\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkE;AAClE,sBAAkB;AAElB,yBAAkD;AAiD3C,MAAM,0BAAiD;AAAA,EAC7D;AAAA,EACA,kBAAE,OAAO;AAAA,IACR,GAAG,kBAAE;AAAA,IACL,GAAG,kBAAE;AAAA,IACL,MAAM,kBAAE;AAAA,IACR,YAAY,kBAAE;AAAA,IACd,UAAU,kBAAE,OAAO,SAAS;AAAA,IAC5B,KAAK,kBAAE,OAAO,SAAS;AAAA,IACvB,UAAU,kBAAE,cAAc,SAAS;AAAA,EACpC,CAAC;AACF;AAEA,MAAM,eAAW,iCAAmB,0BAA0B;AAAA,EAC7D,eAAe;AAAA,EACf,mBAAmB;AAAA,EACnB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,sBAAsB;AACvB,CAAU;AAkCH,MAAM,2BAAuB,4CAA8B;AAAA,EACjE,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ,CAAC,UAAW,MAAkB,SAAS;AAAA,EAC/C,UAAU;AAAA,IACT;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,cAAM,MAAM,aAAa;AAAA,MAC1B;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,cAAM,MAAM,IAAI,MAAM,MAAM;AAC5B,cAAM,MAAM,IAAI,MAAM,MAAM;AAC5B,eAAO,MAAM,MAAM;AACnB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,cAAM,MAAM,QAAQ,MAAM,MAAM;AAChC,cAAM,MAAM,SAAS,MAAM,MAAM;AACjC,eAAO,MAAM,MAAM;AACnB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,YAAI,CAAC,kBAAE,OAAO,QAAQ,MAAM,MAAM,GAAG,GAAG;AACvC,gBAAM,MAAM,MAAM;AAAA,QACnB;AAAA,MACD;AAAA,MACA,MAAM,CAAC,WAAW;AAAA,MAElB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,cAAM,MAAM,WAAW;AAAA,MACxB;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,YAAI,MAAM,MAAM,aAAa,IAAI;AAChC,gBAAM,MAAM,WAAW;AAAA,QACxB;AAAA,MACD;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,YAAI,MAAM,MAAM,aAAa,QAAW;AACvC,gBAAM,MAAM,WAAW;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD,CAAC;",
4
+ "sourcesContent": ["import { createMigrationIds, createRecordMigrationSequence } from '@tldraw/store'\nimport { T } from '@tldraw/validate'\nimport { TLAsset } from '../records/TLAsset'\nimport { TLBaseAsset, createAssetValidator } from './TLBaseAsset'\n\n/**\n * An asset for images such as PNGs and JPEGs, used by the TLImageShape.\n *\n * @public */\nexport type TLImageAsset = TLBaseAsset<\n\t'image',\n\t{\n\t\tw: number\n\t\th: number\n\t\tname: string\n\t\tisAnimated: boolean\n\t\tmimeType: string | null\n\t\tsrc: string | null\n\t\tfileSize?: number\n\t\tpixelRatio?: number\n\t}\n>\n\n/**\n * Validator for image assets. Validates the structure and properties of TLImageAsset records\n * to ensure data integrity when image assets are stored or retrieved from the tldraw store.\n *\n * @example\n * ```ts\n * import { imageAssetValidator } from '@tldraw/tlschema'\n *\n * const imageAsset = {\n * id: 'asset:image123',\n * typeName: 'asset',\n * type: 'image',\n * props: {\n * w: 800,\n * h: 600,\n * name: 'photo.jpg',\n * isAnimated: false,\n * mimeType: 'image/jpeg',\n * src: 'https://example.com/photo.jpg',\n * fileSize: 156000\n * },\n * meta: {}\n * }\n *\n * // Validate the asset\n * const isValid = imageAssetValidator.validate(imageAsset)\n * ```\n *\n * @public\n */\nexport const imageAssetValidator: T.Validator<TLImageAsset> = createAssetValidator(\n\t'image',\n\tT.object({\n\t\tw: T.number,\n\t\th: T.number,\n\t\tname: T.string,\n\t\tisAnimated: T.boolean,\n\t\tmimeType: T.string.nullable(),\n\t\tsrc: T.srcUrl.nullable(),\n\t\tfileSize: T.nonZeroNumber.optional(),\n\t\tpixelRatio: T.positiveNumber.optional(),\n\t})\n)\n\nconst Versions = createMigrationIds('com.tldraw.asset.image', {\n\tAddIsAnimated: 1,\n\tRenameWidthHeight: 2,\n\tMakeUrlsValid: 3,\n\tAddFileSize: 4,\n\tMakeFileSizeOptional: 5,\n\tAddPixelRatio: 6,\n} as const)\n\n/**\n * Migration version identifiers for image assets. These define the different schema versions\n * that image assets have gone through during the evolution of the tldraw data model.\n *\n * @example\n * ```ts\n * import { imageAssetVersions } from '@tldraw/tlschema'\n *\n * // Access specific version IDs\n * console.log(imageAssetVersions.AddIsAnimated) // Version when isAnimated was added\n * console.log(imageAssetVersions.RenameWidthHeight) // Version when width/height became w/h\n * ```\n *\n * @public\n */\nexport { Versions as imageAssetVersions }\n\n/**\n * Migration sequence for image assets. Handles the evolution of the image asset schema\n * over time, providing both forward (up) and backward (down) migration functions to\n * maintain compatibility across different versions of the tldraw data model.\n *\n * The sequence includes migrations for:\n * - Adding the `isAnimated` property to track animated images\n * - Renaming `width`/`height` properties to shorter `w`/`h` names\n * - Ensuring URLs are valid format\n * - Adding file size tracking\n * - Making file size optional\n *\n *\n * @public\n */\nexport const imageAssetMigrations = createRecordMigrationSequence({\n\tsequenceId: 'com.tldraw.asset.image',\n\trecordType: 'asset',\n\tfilter: (asset) => (asset as TLAsset).type === 'image',\n\tsequence: [\n\t\t{\n\t\t\tid: Versions.AddIsAnimated,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.isAnimated = false\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.isAnimated\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.RenameWidthHeight,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.w = asset.props.width\n\t\t\t\tasset.props.h = asset.props.height\n\t\t\t\tdelete asset.props.width\n\t\t\t\tdelete asset.props.height\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tasset.props.width = asset.props.w\n\t\t\t\tasset.props.height = asset.props.h\n\t\t\t\tdelete asset.props.w\n\t\t\t\tdelete asset.props.h\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeUrlsValid,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (!T.srcUrl.isValid(asset.props.src)) {\n\t\t\t\t\tasset.props.src = ''\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (_asset) => {\n\t\t\t\t// noop\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddFileSize,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.fileSize = -1\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.fileSize\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeFileSizeOptional,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (asset.props.fileSize === -1) {\n\t\t\t\t\tasset.props.fileSize = undefined\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tif (asset.props.fileSize === undefined) {\n\t\t\t\t\tasset.props.fileSize = -1\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddPixelRatio,\n\t\t\tup: (_asset: any) => {\n\t\t\t\t// noop \u2014 pixelRatio is optional and undefined by default\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.pixelRatio\n\t\t\t},\n\t\t},\n\t],\n})\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkE;AAClE,sBAAkB;AAElB,yBAAkD;AAkD3C,MAAM,0BAAiD;AAAA,EAC7D;AAAA,EACA,kBAAE,OAAO;AAAA,IACR,GAAG,kBAAE;AAAA,IACL,GAAG,kBAAE;AAAA,IACL,MAAM,kBAAE;AAAA,IACR,YAAY,kBAAE;AAAA,IACd,UAAU,kBAAE,OAAO,SAAS;AAAA,IAC5B,KAAK,kBAAE,OAAO,SAAS;AAAA,IACvB,UAAU,kBAAE,cAAc,SAAS;AAAA,IACnC,YAAY,kBAAE,eAAe,SAAS;AAAA,EACvC,CAAC;AACF;AAEA,MAAM,eAAW,iCAAmB,0BAA0B;AAAA,EAC7D,eAAe;AAAA,EACf,mBAAmB;AAAA,EACnB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,sBAAsB;AAAA,EACtB,eAAe;AAChB,CAAU;AAkCH,MAAM,2BAAuB,4CAA8B;AAAA,EACjE,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ,CAAC,UAAW,MAAkB,SAAS;AAAA,EAC/C,UAAU;AAAA,IACT;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,cAAM,MAAM,aAAa;AAAA,MAC1B;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAA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sset<'image', {
4612
4612
  isAnimated: boolean;
4613
4613
  mimeType: null | string;
4614
4614
  name: string;
4615
+ pixelRatio?: number;
4615
4616
  src: null | string;
4616
4617
  w: number;
4617
4618
  }>;
package/dist-cjs/index.js CHANGED
@@ -181,7 +181,7 @@ var import_translations = require("./translations/translations");
181
181
  var import_b64Vecs = require("./misc/b64Vecs");
182
182
  (0, import_utils.registerTldrawLibraryVersion)(
183
183
  "@tldraw/tlschema",
184
- "4.5.0-next.dad6df23ab1f",
184
+ "4.5.0",
185
185
  "cjs"
186
186
  );
187
187
  //# sourceMappingURL=index.js.map
@@ -10,7 +10,8 @@ const imageAssetValidator = createAssetValidator(
10
10
  isAnimated: T.boolean,
11
11
  mimeType: T.string.nullable(),
12
12
  src: T.srcUrl.nullable(),
13
- fileSize: T.nonZeroNumber.optional()
13
+ fileSize: T.nonZeroNumber.optional(),
14
+ pixelRatio: T.positiveNumber.optional()
14
15
  })
15
16
  );
16
17
  const Versions = createMigrationIds("com.tldraw.asset.image", {
@@ -18,7 +19,8 @@ const Versions = createMigrationIds("com.tldraw.asset.image", {
18
19
  RenameWidthHeight: 2,
19
20
  MakeUrlsValid: 3,
20
21
  AddFileSize: 4,
21
- MakeFileSizeOptional: 5
22
+ MakeFileSizeOptional: 5,
23
+ AddPixelRatio: 6
22
24
  });
23
25
  const imageAssetMigrations = createRecordMigrationSequence({
24
26
  sequenceId: "com.tldraw.asset.image",
@@ -80,6 +82,14 @@ const imageAssetMigrations = createRecordMigrationSequence({
80
82
  asset.props.fileSize = -1;
81
83
  }
82
84
  }
85
+ },
86
+ {
87
+ id: Versions.AddPixelRatio,
88
+ up: (_asset) => {
89
+ },
90
+ down: (asset) => {
91
+ delete asset.props.pixelRatio;
92
+ }
83
93
  }
84
94
  ]
85
95
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/assets/TLImageAsset.ts"],
4
- "sourcesContent": ["import { createMigrationIds, createRecordMigrationSequence } from '@tldraw/store'\nimport { T } from '@tldraw/validate'\nimport { TLAsset } from '../records/TLAsset'\nimport { TLBaseAsset, createAssetValidator } from './TLBaseAsset'\n\n/**\n * An asset for images such as PNGs and JPEGs, used by the TLImageShape.\n *\n * @public */\nexport type TLImageAsset = TLBaseAsset<\n\t'image',\n\t{\n\t\tw: number\n\t\th: number\n\t\tname: string\n\t\tisAnimated: boolean\n\t\tmimeType: string | null\n\t\tsrc: string | null\n\t\tfileSize?: number\n\t}\n>\n\n/**\n * Validator for image assets. Validates the structure and properties of TLImageAsset records\n * to ensure data integrity when image assets are stored or retrieved from the tldraw store.\n *\n * @example\n * ```ts\n * import { imageAssetValidator } from '@tldraw/tlschema'\n *\n * const imageAsset = {\n * id: 'asset:image123',\n * typeName: 'asset',\n * type: 'image',\n * props: {\n * w: 800,\n * h: 600,\n * name: 'photo.jpg',\n * isAnimated: false,\n * mimeType: 'image/jpeg',\n * src: 'https://example.com/photo.jpg',\n * fileSize: 156000\n * },\n * meta: {}\n * }\n *\n * // Validate the asset\n * const isValid = imageAssetValidator.validate(imageAsset)\n * ```\n *\n * @public\n */\nexport const imageAssetValidator: T.Validator<TLImageAsset> = createAssetValidator(\n\t'image',\n\tT.object({\n\t\tw: T.number,\n\t\th: T.number,\n\t\tname: T.string,\n\t\tisAnimated: T.boolean,\n\t\tmimeType: T.string.nullable(),\n\t\tsrc: T.srcUrl.nullable(),\n\t\tfileSize: T.nonZeroNumber.optional(),\n\t})\n)\n\nconst Versions = createMigrationIds('com.tldraw.asset.image', {\n\tAddIsAnimated: 1,\n\tRenameWidthHeight: 2,\n\tMakeUrlsValid: 3,\n\tAddFileSize: 4,\n\tMakeFileSizeOptional: 5,\n} as const)\n\n/**\n * Migration version identifiers for image assets. These define the different schema versions\n * that image assets have gone through during the evolution of the tldraw data model.\n *\n * @example\n * ```ts\n * import { imageAssetVersions } from '@tldraw/tlschema'\n *\n * // Access specific version IDs\n * console.log(imageAssetVersions.AddIsAnimated) // Version when isAnimated was added\n * console.log(imageAssetVersions.RenameWidthHeight) // Version when width/height became w/h\n * ```\n *\n * @public\n */\nexport { Versions as imageAssetVersions }\n\n/**\n * Migration sequence for image assets. Handles the evolution of the image asset schema\n * over time, providing both forward (up) and backward (down) migration functions to\n * maintain compatibility across different versions of the tldraw data model.\n *\n * The sequence includes migrations for:\n * - Adding the `isAnimated` property to track animated images\n * - Renaming `width`/`height` properties to shorter `w`/`h` names\n * - Ensuring URLs are valid format\n * - Adding file size tracking\n * - Making file size optional\n *\n *\n * @public\n */\nexport const imageAssetMigrations = createRecordMigrationSequence({\n\tsequenceId: 'com.tldraw.asset.image',\n\trecordType: 'asset',\n\tfilter: (asset) => (asset as TLAsset).type === 'image',\n\tsequence: [\n\t\t{\n\t\t\tid: Versions.AddIsAnimated,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.isAnimated = false\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.isAnimated\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.RenameWidthHeight,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.w = asset.props.width\n\t\t\t\tasset.props.h = asset.props.height\n\t\t\t\tdelete asset.props.width\n\t\t\t\tdelete asset.props.height\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tasset.props.width = asset.props.w\n\t\t\t\tasset.props.height = asset.props.h\n\t\t\t\tdelete asset.props.w\n\t\t\t\tdelete asset.props.h\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeUrlsValid,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (!T.srcUrl.isValid(asset.props.src)) {\n\t\t\t\t\tasset.props.src = ''\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (_asset) => {\n\t\t\t\t// noop\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddFileSize,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.fileSize = -1\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.fileSize\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeFileSizeOptional,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (asset.props.fileSize === -1) {\n\t\t\t\t\tasset.props.fileSize = undefined\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tif (asset.props.fileSize === undefined) {\n\t\t\t\t\tasset.props.fileSize = -1\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t],\n})\n"],
5
- "mappings": "AAAA,SAAS,oBAAoB,qCAAqC;AAClE,SAAS,SAAS;AAElB,SAAsB,4BAA4B;AAiD3C,MAAM,sBAAiD;AAAA,EAC7D;AAAA,EACA,EAAE,OAAO;AAAA,IACR,GAAG,EAAE;AAAA,IACL,GAAG,EAAE;AAAA,IACL,MAAM,EAAE;AAAA,IACR,YAAY,EAAE;AAAA,IACd,UAAU,EAAE,OAAO,SAAS;AAAA,IAC5B,KAAK,EAAE,OAAO,SAAS;AAAA,IACvB,UAAU,EAAE,cAAc,SAAS;AAAA,EACpC,CAAC;AACF;AAEA,MAAM,WAAW,mBAAmB,0BAA0B;AAAA,EAC7D,eAAe;AAAA,EACf,mBAAmB;AAAA,EACnB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,sBAAsB;AACvB,CAAU;AAkCH,MAAM,uBAAuB,8BAA8B;AAAA,EACjE,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ,CAAC,UAAW,MAAkB,SAAS;AAAA,EAC/C,UAAU;AAAA,IACT;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,cAAM,MAAM,aAAa;AAAA,MAC1B;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,cAAM,MAAM,IAAI,MAAM,MAAM;AAC5B,cAAM,MAAM,IAAI,MAAM,MAAM;AAC5B,eAAO,MAAM,MAAM;AACnB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,cAAM,MAAM,QAAQ,MAAM,MAAM;AAChC,cAAM,MAAM,SAAS,MAAM,MAAM;AACjC,eAAO,MAAM,MAAM;AACnB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,YAAI,CAAC,EAAE,OAAO,QAAQ,MAAM,MAAM,GAAG,GAAG;AACvC,gBAAM,MAAM,MAAM;AAAA,QACnB;AAAA,MACD;AAAA,MACA,MAAM,CAAC,WAAW;AAAA,MAElB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,cAAM,MAAM,WAAW;AAAA,MACxB;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,YAAI,MAAM,MAAM,aAAa,IAAI;AAChC,gBAAM,MAAM,WAAW;AAAA,QACxB;AAAA,MACD;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,YAAI,MAAM,MAAM,aAAa,QAAW;AACvC,gBAAM,MAAM,WAAW;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD,CAAC;",
4
+ "sourcesContent": ["import { createMigrationIds, createRecordMigrationSequence } from '@tldraw/store'\nimport { T } from '@tldraw/validate'\nimport { TLAsset } from '../records/TLAsset'\nimport { TLBaseAsset, createAssetValidator } from './TLBaseAsset'\n\n/**\n * An asset for images such as PNGs and JPEGs, used by the TLImageShape.\n *\n * @public */\nexport type TLImageAsset = TLBaseAsset<\n\t'image',\n\t{\n\t\tw: number\n\t\th: number\n\t\tname: string\n\t\tisAnimated: boolean\n\t\tmimeType: string | null\n\t\tsrc: string | null\n\t\tfileSize?: number\n\t\tpixelRatio?: number\n\t}\n>\n\n/**\n * Validator for image assets. Validates the structure and properties of TLImageAsset records\n * to ensure data integrity when image assets are stored or retrieved from the tldraw store.\n *\n * @example\n * ```ts\n * import { imageAssetValidator } from '@tldraw/tlschema'\n *\n * const imageAsset = {\n * id: 'asset:image123',\n * typeName: 'asset',\n * type: 'image',\n * props: {\n * w: 800,\n * h: 600,\n * name: 'photo.jpg',\n * isAnimated: false,\n * mimeType: 'image/jpeg',\n * src: 'https://example.com/photo.jpg',\n * fileSize: 156000\n * },\n * meta: {}\n * }\n *\n * // Validate the asset\n * const isValid = imageAssetValidator.validate(imageAsset)\n * ```\n *\n * @public\n */\nexport const imageAssetValidator: T.Validator<TLImageAsset> = createAssetValidator(\n\t'image',\n\tT.object({\n\t\tw: T.number,\n\t\th: T.number,\n\t\tname: T.string,\n\t\tisAnimated: T.boolean,\n\t\tmimeType: T.string.nullable(),\n\t\tsrc: T.srcUrl.nullable(),\n\t\tfileSize: T.nonZeroNumber.optional(),\n\t\tpixelRatio: T.positiveNumber.optional(),\n\t})\n)\n\nconst Versions = createMigrationIds('com.tldraw.asset.image', {\n\tAddIsAnimated: 1,\n\tRenameWidthHeight: 2,\n\tMakeUrlsValid: 3,\n\tAddFileSize: 4,\n\tMakeFileSizeOptional: 5,\n\tAddPixelRatio: 6,\n} as const)\n\n/**\n * Migration version identifiers for image assets. These define the different schema versions\n * that image assets have gone through during the evolution of the tldraw data model.\n *\n * @example\n * ```ts\n * import { imageAssetVersions } from '@tldraw/tlschema'\n *\n * // Access specific version IDs\n * console.log(imageAssetVersions.AddIsAnimated) // Version when isAnimated was added\n * console.log(imageAssetVersions.RenameWidthHeight) // Version when width/height became w/h\n * ```\n *\n * @public\n */\nexport { Versions as imageAssetVersions }\n\n/**\n * Migration sequence for image assets. Handles the evolution of the image asset schema\n * over time, providing both forward (up) and backward (down) migration functions to\n * maintain compatibility across different versions of the tldraw data model.\n *\n * The sequence includes migrations for:\n * - Adding the `isAnimated` property to track animated images\n * - Renaming `width`/`height` properties to shorter `w`/`h` names\n * - Ensuring URLs are valid format\n * - Adding file size tracking\n * - Making file size optional\n *\n *\n * @public\n */\nexport const imageAssetMigrations = createRecordMigrationSequence({\n\tsequenceId: 'com.tldraw.asset.image',\n\trecordType: 'asset',\n\tfilter: (asset) => (asset as TLAsset).type === 'image',\n\tsequence: [\n\t\t{\n\t\t\tid: Versions.AddIsAnimated,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.isAnimated = false\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.isAnimated\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.RenameWidthHeight,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.w = asset.props.width\n\t\t\t\tasset.props.h = asset.props.height\n\t\t\t\tdelete asset.props.width\n\t\t\t\tdelete asset.props.height\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tasset.props.width = asset.props.w\n\t\t\t\tasset.props.height = asset.props.h\n\t\t\t\tdelete asset.props.w\n\t\t\t\tdelete asset.props.h\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeUrlsValid,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (!T.srcUrl.isValid(asset.props.src)) {\n\t\t\t\t\tasset.props.src = ''\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (_asset) => {\n\t\t\t\t// noop\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddFileSize,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.fileSize = -1\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.fileSize\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeFileSizeOptional,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (asset.props.fileSize === -1) {\n\t\t\t\t\tasset.props.fileSize = undefined\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tif (asset.props.fileSize === undefined) {\n\t\t\t\t\tasset.props.fileSize = -1\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddPixelRatio,\n\t\t\tup: (_asset: any) => {\n\t\t\t\t// noop \u2014 pixelRatio is optional and undefined by default\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.pixelRatio\n\t\t\t},\n\t\t},\n\t],\n})\n"],
5
+ "mappings": "AAAA,SAAS,oBAAoB,qCAAqC;AAClE,SAAS,SAAS;AAElB,SAAsB,4BAA4B;AAkD3C,MAAM,sBAAiD;AAAA,EAC7D;AAAA,EACA,EAAE,OAAO;AAAA,IACR,GAAG,EAAE;AAAA,IACL,GAAG,EAAE;AAAA,IACL,MAAM,EAAE;AAAA,IACR,YAAY,EAAE;AAAA,IACd,UAAU,EAAE,OAAO,SAAS;AAAA,IAC5B,KAAK,EAAE,OAAO,SAAS;AAAA,IACvB,UAAU,EAAE,cAAc,SAAS;AAAA,IACnC,YAAY,EAAE,eAAe,SAAS;AAAA,EACvC,CAAC;AACF;AAEA,MAAM,WAAW,mBAAmB,0BAA0B;AAAA,EAC7D,eAAe;AAAA,EACf,mBAAmB;AAAA,EACnB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,sBAAsB;AAAA,EACtB,eAAe;AAChB,CAAU;AAkCH,MAAM,uBAAuB,8BAA8B;AAAA,EACjE,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ,CAAC,UAAW,MAAkB,SAAS;AAAA,EAC/C,UAAU;AAAA,IACT;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,cAAM,MAAM,aAAa;AAAA,MAC1B;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,eAAO,MAAM,MAAM;AAAA,MACpB;AAA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[]
7
7
  }
@@ -4612,6 +4612,7 @@ export declare type TLImageAsset = TLBaseAsset<'image', {
4612
4612
  isAnimated: boolean;
4613
4613
  mimeType: null | string;
4614
4614
  name: string;
4615
+ pixelRatio?: number;
4615
4616
  src: null | string;
4616
4617
  w: number;
4617
4618
  }>;
@@ -174,7 +174,7 @@ import {
174
174
  } from "./translations/translations.mjs";
175
175
  registerTldrawLibraryVersion(
176
176
  "@tldraw/tlschema",
177
- "4.5.0-next.dad6df23ab1f",
177
+ "4.5.0",
178
178
  "esm"
179
179
  );
180
180
  import { b64Vecs } from "./misc/b64Vecs.mjs";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tldraw/tlschema",
3
3
  "description": "tldraw infinite canvas SDK (schema).",
4
- "version": "4.5.0-next.dad6df23ab1f",
4
+ "version": "4.5.0",
5
5
  "author": {
6
6
  "name": "tldraw Inc.",
7
7
  "email": "hello@tldraw.com"
@@ -50,10 +50,10 @@
50
50
  "vitest": "^3.2.4"
51
51
  },
52
52
  "dependencies": {
53
- "@tldraw/state": "4.5.0-next.dad6df23ab1f",
54
- "@tldraw/store": "4.5.0-next.dad6df23ab1f",
55
- "@tldraw/utils": "4.5.0-next.dad6df23ab1f",
56
- "@tldraw/validate": "4.5.0-next.dad6df23ab1f"
53
+ "@tldraw/state": "4.5.0",
54
+ "@tldraw/store": "4.5.0",
55
+ "@tldraw/utils": "4.5.0",
56
+ "@tldraw/validate": "4.5.0"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "react": "^18.2.0 || ^19.2.1",
@@ -17,6 +17,7 @@ export type TLImageAsset = TLBaseAsset<
17
17
  mimeType: string | null
18
18
  src: string | null
19
19
  fileSize?: number
20
+ pixelRatio?: number
20
21
  }
21
22
  >
22
23
 
@@ -60,6 +61,7 @@ export const imageAssetValidator: T.Validator<TLImageAsset> = createAssetValidat
60
61
  mimeType: T.string.nullable(),
61
62
  src: T.srcUrl.nullable(),
62
63
  fileSize: T.nonZeroNumber.optional(),
64
+ pixelRatio: T.positiveNumber.optional(),
63
65
  })
64
66
  )
65
67
 
@@ -69,6 +71,7 @@ const Versions = createMigrationIds('com.tldraw.asset.image', {
69
71
  MakeUrlsValid: 3,
70
72
  AddFileSize: 4,
71
73
  MakeFileSizeOptional: 5,
74
+ AddPixelRatio: 6,
72
75
  } as const)
73
76
 
74
77
  /**
@@ -165,5 +168,14 @@ export const imageAssetMigrations = createRecordMigrationSequence({
165
168
  }
166
169
  },
167
170
  },
171
+ {
172
+ id: Versions.AddPixelRatio,
173
+ up: (_asset: any) => {
174
+ // noop — pixelRatio is optional and undefined by default
175
+ },
176
+ down: (asset: any) => {
177
+ delete asset.props.pixelRatio
178
+ },
179
+ },
168
180
  ],
169
181
  })
@@ -2102,6 +2102,21 @@ describe('Make image asset file size optional', () => {
2102
2102
  })
2103
2103
  })
2104
2104
 
2105
+ describe('Add pixelRatio to image asset', () => {
2106
+ const { up, down } = getTestMigration(imageAssetVersions.AddPixelRatio)
2107
+
2108
+ test('up works as expected', () => {
2109
+ expect(up({ props: { w: 100, h: 100 } })).toEqual({ props: { w: 100, h: 100 } })
2110
+ })
2111
+
2112
+ test('down works as expected', () => {
2113
+ expect(down({ props: { w: 100, h: 100, pixelRatio: 2 } })).toEqual({
2114
+ props: { w: 100, h: 100 },
2115
+ })
2116
+ expect(down({ props: { w: 100, h: 100 } })).toEqual({ props: { w: 100, h: 100 } })
2117
+ })
2118
+ })
2119
+
2105
2120
  describe('Add flipX, flipY to image shape', () => {
2106
2121
  const { up, down } = getTestMigration(imageShapeVersions.AddFlipProps)
2107
2122