@tldraw/tlschema 5.2.0-canary.cfef7b16ad41 → 5.2.0-canary.d28cf4347708

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.
@@ -1,5 +1,5 @@
1
1
  import { T } from '@tldraw/validate'
2
- import { b64Vecs } from '../misc/b64Vecs'
2
+ import { DIM_2D, DIM_3D, b64Vecs } from '../misc/b64Vecs'
3
3
  import { VecModel } from '../misc/geometry-types'
4
4
  import { createShapePropsMigrationIds, createShapePropsMigrationSequence } from '../records/TLShape'
5
5
  import { RecordProps } from '../recordsWithProps'
@@ -22,6 +22,12 @@ export interface TLDrawShapeSegment {
22
22
  * First point stored as Float32 (12 bytes) for precision, subsequent points as Float16 deltas (6 bytes each).
23
23
  */
24
24
  path: string
25
+ /**
26
+ * Encoding dimension of `path`. `2` means (x, y) only — the constant 0.5 pressure
27
+ * was omitted, for input from devices that don't report pressure. `3` or absent
28
+ * (the legacy default) means (x, y, z). Added in the `OmitNonPressureZ` migration.
29
+ */
30
+ dim?: 2 | 3
25
31
  }
26
32
 
27
33
  /**
@@ -32,6 +38,7 @@ export interface TLDrawShapeSegment {
32
38
  export const DrawShapeSegment: T.ObjectValidator<TLDrawShapeSegment> = T.object({
33
39
  type: T.literalEnum('free', 'straight'),
34
40
  path: T.string,
41
+ dim: T.literalEnum(DIM_2D, DIM_3D).optional(),
35
42
  })
36
43
 
37
44
  /**
@@ -138,6 +145,7 @@ const Versions = createShapePropsMigrationIds('draw', {
138
145
  AddScale: 2,
139
146
  Base64: 3,
140
147
  LegacyPointsConversion: 4,
148
+ OmitNonPressureZ: 5,
141
149
  })
142
150
 
143
151
  /**
@@ -239,6 +247,27 @@ export const drawShapeMigrations = createShapePropsMigrationSequence({
239
247
  // handled by the previous down migration
240
248
  },
241
249
  },
250
+ {
251
+ id: Versions.OmitNonPressureZ,
252
+ up: (_props) => {
253
+ // No-op. Pre-existing segments have no `dim` field, which is exactly how
254
+ // the new schema reads them (3D). The validator now accepts the optional
255
+ // `dim`, so newer 2D segments validate as well — nothing to rewrite here.
256
+ },
257
+ down: (props) => {
258
+ // Older clients only understand 3D paths and reject the unknown `dim` field.
259
+ // Strip `dim` from every segment that carries it; a 2D segment is also
260
+ // re-encoded back to 3D (decode supplies z = 0.5), while a `dim: 3` segment
261
+ // already has a 3D path so we just drop the field.
262
+ props.segments = props.segments.map((segment: any) => {
263
+ if (segment.dim === undefined) return segment
264
+ const { dim, ...rest } = segment
265
+ return dim === DIM_2D
266
+ ? { ...rest, path: b64Vecs.encodePoints(b64Vecs.decodePoints(segment.path, DIM_2D)) }
267
+ : rest
268
+ })
269
+ },
270
+ },
242
271
  ],
243
272
  })
244
273
 
@@ -1,5 +1,5 @@
1
1
  import { T } from '@tldraw/validate'
2
- import { b64Vecs } from '../misc/b64Vecs'
2
+ import { DIM_2D, b64Vecs } from '../misc/b64Vecs'
3
3
  import { createShapePropsMigrationIds, createShapePropsMigrationSequence } from '../records/TLShape'
4
4
  import { RecordProps } from '../recordsWithProps'
5
5
  import { DefaultColorStyle, TLDefaultColorStyle } from '../styles/TLColorStyle'
@@ -105,6 +105,7 @@ const Versions = createShapePropsMigrationIds('highlight', {
105
105
  AddScale: 1,
106
106
  Base64: 2,
107
107
  LegacyPointsConversion: 3,
108
+ OmitNonPressureZ: 4,
108
109
  })
109
110
 
110
111
  /**
@@ -182,5 +183,22 @@ export const highlightShapeMigrations = createShapePropsMigrationSequence({
182
183
  // handled by the previous down migration
183
184
  },
184
185
  },
186
+ {
187
+ id: Versions.OmitNonPressureZ,
188
+ up: (_props) => {
189
+ // No-op — see the matching draw-shape migration. Absent `dim` reads as 3D.
190
+ },
191
+ down: (props) => {
192
+ // Strip `dim` from every segment that carries it (older clients reject the
193
+ // unknown field); 2D segments are re-encoded to 3D, dim: 3 just loses the field.
194
+ props.segments = props.segments.map((segment: any) => {
195
+ if (segment.dim === undefined) return segment
196
+ const { dim, ...rest } = segment
197
+ return dim === DIM_2D
198
+ ? { ...rest, path: b64Vecs.encodePoints(b64Vecs.decodePoints(segment.path, DIM_2D)) }
199
+ : rest
200
+ })
201
+ },
202
+ },
185
203
  ],
186
204
  })