@tldraw/tlschema 4.3.0-next.2d181ae353a2 → 4.3.0-next.40e4536afc8e

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.
Files changed (97) hide show
  1. package/dist-cjs/index.d.ts +82 -34
  2. package/dist-cjs/index.js +4 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/misc/TLOpacity.js +1 -5
  5. package/dist-cjs/misc/TLOpacity.js.map +2 -2
  6. package/dist-cjs/misc/TLRichText.js +5 -1
  7. package/dist-cjs/misc/TLRichText.js.map +2 -2
  8. package/dist-cjs/misc/b64Vecs.js +224 -0
  9. package/dist-cjs/misc/b64Vecs.js.map +7 -0
  10. package/dist-cjs/shapes/TLArrowShape.js +30 -13
  11. package/dist-cjs/shapes/TLArrowShape.js.map +2 -2
  12. package/dist-cjs/shapes/TLDrawShape.js +37 -4
  13. package/dist-cjs/shapes/TLDrawShape.js.map +2 -2
  14. package/dist-cjs/shapes/TLEmbedShape.js +17 -0
  15. package/dist-cjs/shapes/TLEmbedShape.js.map +2 -2
  16. package/dist-cjs/shapes/TLGeoShape.js +12 -1
  17. package/dist-cjs/shapes/TLGeoShape.js.map +2 -2
  18. package/dist-cjs/shapes/TLHighlightShape.js +29 -2
  19. package/dist-cjs/shapes/TLHighlightShape.js.map +2 -2
  20. package/dist-cjs/shapes/TLNoteShape.js +12 -1
  21. package/dist-cjs/shapes/TLNoteShape.js.map +2 -2
  22. package/dist-cjs/shapes/TLTextShape.js +12 -1
  23. package/dist-cjs/shapes/TLTextShape.js.map +2 -2
  24. package/dist-cjs/store-migrations.js +14 -14
  25. package/dist-cjs/store-migrations.js.map +2 -2
  26. package/dist-esm/index.d.mts +82 -34
  27. package/dist-esm/index.mjs +5 -1
  28. package/dist-esm/index.mjs.map +2 -2
  29. package/dist-esm/misc/TLOpacity.mjs +1 -5
  30. package/dist-esm/misc/TLOpacity.mjs.map +2 -2
  31. package/dist-esm/misc/TLRichText.mjs +5 -1
  32. package/dist-esm/misc/TLRichText.mjs.map +2 -2
  33. package/dist-esm/misc/b64Vecs.mjs +204 -0
  34. package/dist-esm/misc/b64Vecs.mjs.map +7 -0
  35. package/dist-esm/shapes/TLArrowShape.mjs +30 -13
  36. package/dist-esm/shapes/TLArrowShape.mjs.map +2 -2
  37. package/dist-esm/shapes/TLDrawShape.mjs +37 -4
  38. package/dist-esm/shapes/TLDrawShape.mjs.map +2 -2
  39. package/dist-esm/shapes/TLEmbedShape.mjs +17 -0
  40. package/dist-esm/shapes/TLEmbedShape.mjs.map +2 -2
  41. package/dist-esm/shapes/TLGeoShape.mjs +12 -1
  42. package/dist-esm/shapes/TLGeoShape.mjs.map +2 -2
  43. package/dist-esm/shapes/TLHighlightShape.mjs +29 -2
  44. package/dist-esm/shapes/TLHighlightShape.mjs.map +2 -2
  45. package/dist-esm/shapes/TLNoteShape.mjs +12 -1
  46. package/dist-esm/shapes/TLNoteShape.mjs.map +2 -2
  47. package/dist-esm/shapes/TLTextShape.mjs +12 -1
  48. package/dist-esm/shapes/TLTextShape.mjs.map +2 -2
  49. package/dist-esm/store-migrations.mjs +14 -14
  50. package/dist-esm/store-migrations.mjs.map +2 -2
  51. package/package.json +8 -8
  52. package/src/__tests__/migrationTestUtils.ts +9 -3
  53. package/src/index.ts +3 -0
  54. package/src/migrations.test.ts +149 -1
  55. package/src/misc/TLOpacity.ts +1 -5
  56. package/src/misc/TLRichText.ts +6 -1
  57. package/src/misc/b64Vecs.ts +308 -0
  58. package/src/shapes/TLArrowShape.ts +36 -13
  59. package/src/shapes/TLDrawShape.ts +59 -12
  60. package/src/shapes/TLEmbedShape.ts +17 -0
  61. package/src/shapes/TLGeoShape.ts +14 -1
  62. package/src/shapes/TLHighlightShape.ts +37 -0
  63. package/src/shapes/TLNoteShape.ts +15 -1
  64. package/src/shapes/TLTextShape.ts +16 -2
  65. package/src/store-migrations.ts +15 -15
  66. package/src/assets/TLBookmarkAsset.test.ts +0 -96
  67. package/src/assets/TLImageAsset.test.ts +0 -213
  68. package/src/assets/TLVideoAsset.test.ts +0 -105
  69. package/src/bindings/TLArrowBinding.test.ts +0 -55
  70. package/src/misc/id-validator.test.ts +0 -50
  71. package/src/records/TLAsset.test.ts +0 -234
  72. package/src/records/TLBinding.test.ts +0 -22
  73. package/src/records/TLCamera.test.ts +0 -19
  74. package/src/records/TLDocument.test.ts +0 -35
  75. package/src/records/TLInstance.test.ts +0 -201
  76. package/src/records/TLPage.test.ts +0 -110
  77. package/src/records/TLPageState.test.ts +0 -228
  78. package/src/records/TLPointer.test.ts +0 -63
  79. package/src/records/TLPresence.test.ts +0 -190
  80. package/src/records/TLRecord.test.ts +0 -82
  81. package/src/records/TLShape.test.ts +0 -232
  82. package/src/shapes/ShapeWithCrop.test.ts +0 -18
  83. package/src/shapes/TLArrowShape.test.ts +0 -505
  84. package/src/shapes/TLBaseShape.test.ts +0 -142
  85. package/src/shapes/TLBookmarkShape.test.ts +0 -122
  86. package/src/shapes/TLDrawShape.test.ts +0 -177
  87. package/src/shapes/TLEmbedShape.test.ts +0 -286
  88. package/src/shapes/TLFrameShape.test.ts +0 -71
  89. package/src/shapes/TLGeoShape.test.ts +0 -247
  90. package/src/shapes/TLGroupShape.test.ts +0 -59
  91. package/src/shapes/TLHighlightShape.test.ts +0 -325
  92. package/src/shapes/TLImageShape.test.ts +0 -534
  93. package/src/shapes/TLLineShape.test.ts +0 -269
  94. package/src/shapes/TLNoteShape.test.ts +0 -1568
  95. package/src/shapes/TLTextShape.test.ts +0 -407
  96. package/src/shapes/TLVideoShape.test.ts +0 -112
  97. package/src/styles/TLColorStyle.test.ts +0 -439
@@ -1,269 +0,0 @@
1
- import { IndexKey } from '@tldraw/utils'
2
- import { T } from '@tldraw/validate'
3
- import { describe, expect, it } from 'vitest'
4
- import { getTestMigration } from '../__tests__/migrationTestUtils'
5
- import {
6
- lineShapeMigrations,
7
- lineShapeProps,
8
- LineShapeSplineStyle,
9
- lineShapeVersions,
10
- } from './TLLineShape'
11
-
12
- describe('TLLineShape', () => {
13
- describe('LineShapeSplineStyle', () => {
14
- it('should validate correct spline values', () => {
15
- expect(() => LineShapeSplineStyle.validate('cubic')).not.toThrow()
16
- expect(() => LineShapeSplineStyle.validate('line')).not.toThrow()
17
- })
18
-
19
- it('should reject invalid spline values', () => {
20
- expect(() => LineShapeSplineStyle.validate('bezier')).toThrow()
21
- expect(() => LineShapeSplineStyle.validate('')).toThrow()
22
- expect(() => LineShapeSplineStyle.validate(null)).toThrow()
23
- })
24
- })
25
-
26
- describe('lineShapeProps validation schema', () => {
27
- it('should validate complete props object', () => {
28
- const fullValidator = T.object(lineShapeProps)
29
- const validProps = {
30
- color: 'red' as const,
31
- dash: 'dotted' as const,
32
- size: 's' as const,
33
- spline: 'line' as const,
34
- points: {
35
- start: { id: 'start', index: 'a1' as IndexKey, x: 0, y: 0 },
36
- end: { id: 'end', index: 'a2' as IndexKey, x: 100, y: 50 },
37
- },
38
- scale: 1.5,
39
- }
40
-
41
- expect(() => fullValidator.validate(validProps)).not.toThrow()
42
- })
43
-
44
- it('should validate points dictionary structure', () => {
45
- const validPoints = {
46
- a: { id: 'a', index: 'a1' as IndexKey, x: 0, y: 0 },
47
- b: { id: 'b', index: 'a2' as IndexKey, x: 100, y: 50 },
48
- }
49
- expect(() => lineShapeProps.points.validate(validPoints)).not.toThrow()
50
-
51
- // Invalid point structures
52
- expect(() => lineShapeProps.points.validate({ a: { id: 'a', x: 0, y: 0 } })).toThrow() // Missing index
53
- expect(() => lineShapeProps.points.validate({ a: { index: 'a1', x: 0, y: 0 } })).toThrow() // Missing id
54
- })
55
-
56
- it('should validate scale as nonZeroNumber', () => {
57
- expect(() => lineShapeProps.scale.validate(1.5)).not.toThrow()
58
- expect(() => lineShapeProps.scale.validate(0)).toThrow() // Zero should be invalid
59
- expect(() => lineShapeProps.scale.validate(-1)).toThrow() // Negative should be invalid
60
- })
61
- })
62
-
63
- describe('lineShapeMigrations - AddSnapHandles migration', () => {
64
- const { up } = getTestMigration(lineShapeVersions.AddSnapHandles)
65
-
66
- it('should add canSnap property to all handles', () => {
67
- const oldRecord = {
68
- id: 'shape:line1',
69
- props: {
70
- handles: {
71
- start: { x: 0, y: 0 },
72
- end: { x: 100, y: 100 },
73
- },
74
- },
75
- }
76
-
77
- const result = up(oldRecord)
78
- expect(result.props.handles.start.canSnap).toBe(true)
79
- expect(result.props.handles.end.canSnap).toBe(true)
80
- })
81
- })
82
-
83
- describe('lineShapeMigrations - RemoveExtraHandleProps migration', () => {
84
- const { up, down } = getTestMigration(lineShapeVersions.RemoveExtraHandleProps)
85
-
86
- it('should preserve only x and y properties from handles', () => {
87
- const oldRecord = {
88
- id: 'shape:line1',
89
- props: {
90
- handles: {
91
- a1: {
92
- x: 10,
93
- y: 20,
94
- canSnap: true,
95
- id: 'start',
96
- type: 'vertex',
97
- index: 'a1',
98
- extraProp: 'remove this',
99
- },
100
- },
101
- },
102
- }
103
-
104
- const result = up(oldRecord)
105
- expect(result.props.handles.a1).toEqual({ x: 10, y: 20 })
106
- })
107
-
108
- it('should restore full handle structure in down migration', () => {
109
- const newRecord = {
110
- id: 'shape:line1',
111
- props: {
112
- handles: {
113
- a1: { x: 0, y: 0 },
114
- a2: { x: 100, y: 100 },
115
- },
116
- },
117
- }
118
-
119
- const result = down(newRecord)
120
- expect(result.props.handles.start).toEqual({
121
- id: 'start',
122
- type: 'vertex',
123
- canBind: false,
124
- canSnap: true,
125
- index: 'a1',
126
- x: 0,
127
- y: 0,
128
- })
129
- })
130
- })
131
-
132
- describe('lineShapeMigrations - HandlesToPoints migration', () => {
133
- const { up, down } = getTestMigration(lineShapeVersions.HandlesToPoints)
134
-
135
- it('should convert handles to points array', () => {
136
- const oldRecord = {
137
- id: 'shape:line1',
138
- props: {
139
- handles: {
140
- a1: { x: 0, y: 0 },
141
- a2: { x: 50, y: 25 },
142
- },
143
- },
144
- }
145
-
146
- const result = up(oldRecord)
147
- expect(result.props.handles).toBeUndefined()
148
- expect(result.props.points).toEqual([
149
- { x: 0, y: 0 },
150
- { x: 50, y: 25 },
151
- ])
152
- })
153
-
154
- it('should convert points back to handles', () => {
155
- const newRecord = {
156
- id: 'shape:line1',
157
- props: {
158
- points: [
159
- { x: 0, y: 0 },
160
- { x: 100, y: 50 },
161
- ],
162
- },
163
- }
164
-
165
- const result = down(newRecord)
166
- expect(result.props.points).toBeUndefined()
167
- expect(result.props.handles).toBeDefined()
168
- expect(Object.keys(result.props.handles)).toHaveLength(2)
169
- })
170
- })
171
-
172
- describe('lineShapeMigrations - PointIndexIds migration', () => {
173
- const { up, down } = getTestMigration(lineShapeVersions.PointIndexIds)
174
-
175
- it('should convert points array to indexed points object', () => {
176
- const oldRecord = {
177
- id: 'shape:line1',
178
- props: {
179
- points: [
180
- { x: 0, y: 0 },
181
- { x: 50, y: 25 },
182
- ],
183
- },
184
- }
185
-
186
- const result = up(oldRecord)
187
- expect(Array.isArray(result.props.points)).toBe(false)
188
- expect(typeof result.props.points).toBe('object')
189
-
190
- const pointKeys = Object.keys(result.props.points)
191
- expect(pointKeys).toHaveLength(2)
192
-
193
- // Each point should have id, index, x, y
194
- pointKeys.forEach((key) => {
195
- const point = result.props.points[key]
196
- expect(point.id).toBe(key)
197
- expect(point.index).toBe(key)
198
- })
199
- })
200
-
201
- it('should convert indexed points object back to points array', () => {
202
- const newRecord = {
203
- id: 'shape:line1',
204
- props: {
205
- points: {
206
- a1: { id: 'a1', index: 'a1' as IndexKey, x: 0, y: 0 },
207
- a2: { id: 'a2', index: 'a2' as IndexKey, x: 50, y: 25 },
208
- },
209
- },
210
- }
211
-
212
- const result = down(newRecord)
213
- expect(Array.isArray(result.props.points)).toBe(true)
214
- expect(result.props.points).toEqual([
215
- { x: 0, y: 0 },
216
- { x: 50, y: 25 },
217
- ])
218
- })
219
- })
220
-
221
- describe('lineShapeMigrations - AddScale migration', () => {
222
- const { up, down } = getTestMigration(lineShapeVersions.AddScale)
223
-
224
- it('should add scale property with default value 1', () => {
225
- const oldRecord = {
226
- id: 'shape:line1',
227
- props: {
228
- color: 'blue',
229
- points: {
230
- a1: { id: 'a1', index: 'a1' as IndexKey, x: 0, y: 0 },
231
- },
232
- },
233
- }
234
-
235
- const result = up(oldRecord)
236
- expect(result.props.scale).toBe(1)
237
- expect(result.props.color).toBe('blue')
238
- })
239
-
240
- it('should remove scale property in down migration', () => {
241
- const newRecord = {
242
- id: 'shape:line1',
243
- props: {
244
- color: 'blue',
245
- scale: 1.5,
246
- points: {},
247
- },
248
- }
249
-
250
- const result = down(newRecord)
251
- expect(result.props.scale).toBeUndefined()
252
- expect(result.props.color).toBe('blue')
253
- })
254
- })
255
-
256
- describe('migration integration', () => {
257
- it('should have migrations for all version IDs', () => {
258
- const migrationIds = lineShapeMigrations.sequence
259
- .filter((migration) => 'id' in migration)
260
- .map((migration) => ('id' in migration ? migration.id : ''))
261
- .filter(Boolean)
262
-
263
- const versionIds = Object.values(lineShapeVersions)
264
- versionIds.forEach((versionId) => {
265
- expect(migrationIds).toContain(versionId)
266
- })
267
- })
268
- })
269
- })