@tldraw/tlschema 4.1.0-canary.e653ec63c99b → 4.1.0-canary.f2f81cd6fe2c

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 (214) hide show
  1. package/dist-cjs/TLStore.js +3 -10
  2. package/dist-cjs/TLStore.js.map +2 -2
  3. package/dist-cjs/assets/TLBaseAsset.js.map +2 -2
  4. package/dist-cjs/assets/TLBookmarkAsset.js.map +2 -2
  5. package/dist-cjs/assets/TLImageAsset.js.map +2 -2
  6. package/dist-cjs/assets/TLVideoAsset.js.map +2 -2
  7. package/dist-cjs/bindings/TLArrowBinding.js.map +2 -2
  8. package/dist-cjs/bindings/TLBaseBinding.js.map +2 -2
  9. package/dist-cjs/createPresenceStateDerivation.js.map +2 -2
  10. package/dist-cjs/createTLSchema.js.map +2 -2
  11. package/dist-cjs/index.d.ts +4416 -223
  12. package/dist-cjs/index.js +1 -1
  13. package/dist-cjs/index.js.map +2 -2
  14. package/dist-cjs/misc/TLColor.js.map +2 -2
  15. package/dist-cjs/misc/TLCursor.js.map +2 -2
  16. package/dist-cjs/misc/TLHandle.js.map +2 -2
  17. package/dist-cjs/misc/TLOpacity.js.map +2 -2
  18. package/dist-cjs/misc/TLRichText.js.map +2 -2
  19. package/dist-cjs/misc/TLScribble.js.map +2 -2
  20. package/dist-cjs/misc/geometry-types.js.map +2 -2
  21. package/dist-cjs/misc/id-validator.js.map +2 -2
  22. package/dist-cjs/records/TLAsset.js.map +2 -2
  23. package/dist-cjs/records/TLBinding.js.map +2 -2
  24. package/dist-cjs/records/TLCamera.js.map +2 -2
  25. package/dist-cjs/records/TLDocument.js.map +2 -2
  26. package/dist-cjs/records/TLInstance.js.map +2 -2
  27. package/dist-cjs/records/TLPage.js.map +2 -2
  28. package/dist-cjs/records/TLPageState.js.map +2 -2
  29. package/dist-cjs/records/TLPointer.js.map +2 -2
  30. package/dist-cjs/records/TLPresence.js.map +2 -2
  31. package/dist-cjs/records/TLRecord.js.map +1 -1
  32. package/dist-cjs/records/TLShape.js.map +2 -2
  33. package/dist-cjs/recordsWithProps.js.map +2 -2
  34. package/dist-cjs/shapes/ShapeWithCrop.js.map +1 -1
  35. package/dist-cjs/shapes/TLArrowShape.js.map +2 -2
  36. package/dist-cjs/shapes/TLBaseShape.js.map +2 -2
  37. package/dist-cjs/shapes/TLBookmarkShape.js.map +2 -2
  38. package/dist-cjs/shapes/TLDrawShape.js.map +2 -2
  39. package/dist-cjs/shapes/TLEmbedShape.js +0 -10
  40. package/dist-cjs/shapes/TLEmbedShape.js.map +2 -2
  41. package/dist-cjs/shapes/TLFrameShape.js.map +2 -2
  42. package/dist-cjs/shapes/TLGeoShape.js.map +2 -2
  43. package/dist-cjs/shapes/TLGroupShape.js.map +2 -2
  44. package/dist-cjs/shapes/TLHighlightShape.js.map +2 -2
  45. package/dist-cjs/shapes/TLImageShape.js.map +2 -2
  46. package/dist-cjs/shapes/TLLineShape.js.map +2 -2
  47. package/dist-cjs/shapes/TLNoteShape.js.map +2 -2
  48. package/dist-cjs/shapes/TLTextShape.js.map +2 -2
  49. package/dist-cjs/shapes/TLVideoShape.js.map +2 -2
  50. package/dist-cjs/store-migrations.js.map +2 -2
  51. package/dist-cjs/styles/TLColorStyle.js.map +2 -2
  52. package/dist-cjs/styles/TLDashStyle.js.map +2 -2
  53. package/dist-cjs/styles/TLFillStyle.js.map +2 -2
  54. package/dist-cjs/styles/TLFontStyle.js.map +2 -2
  55. package/dist-cjs/styles/TLHorizontalAlignStyle.js.map +2 -2
  56. package/dist-cjs/styles/TLSizeStyle.js.map +2 -2
  57. package/dist-cjs/styles/TLTextAlignStyle.js.map +2 -2
  58. package/dist-cjs/styles/TLVerticalAlignStyle.js.map +2 -2
  59. package/dist-cjs/translations/translations.js +1 -1
  60. package/dist-cjs/translations/translations.js.map +2 -2
  61. package/dist-cjs/util-types.js.map +1 -1
  62. package/dist-esm/TLStore.mjs +3 -10
  63. package/dist-esm/TLStore.mjs.map +2 -2
  64. package/dist-esm/assets/TLBaseAsset.mjs.map +2 -2
  65. package/dist-esm/assets/TLBookmarkAsset.mjs.map +2 -2
  66. package/dist-esm/assets/TLImageAsset.mjs.map +2 -2
  67. package/dist-esm/assets/TLVideoAsset.mjs.map +2 -2
  68. package/dist-esm/bindings/TLArrowBinding.mjs.map +2 -2
  69. package/dist-esm/bindings/TLBaseBinding.mjs.map +2 -2
  70. package/dist-esm/createPresenceStateDerivation.mjs.map +2 -2
  71. package/dist-esm/createTLSchema.mjs.map +2 -2
  72. package/dist-esm/index.d.mts +4416 -223
  73. package/dist-esm/index.mjs +1 -1
  74. package/dist-esm/index.mjs.map +2 -2
  75. package/dist-esm/misc/TLColor.mjs.map +2 -2
  76. package/dist-esm/misc/TLCursor.mjs.map +2 -2
  77. package/dist-esm/misc/TLHandle.mjs.map +2 -2
  78. package/dist-esm/misc/TLOpacity.mjs.map +2 -2
  79. package/dist-esm/misc/TLRichText.mjs.map +2 -2
  80. package/dist-esm/misc/TLScribble.mjs.map +2 -2
  81. package/dist-esm/misc/geometry-types.mjs.map +2 -2
  82. package/dist-esm/misc/id-validator.mjs.map +2 -2
  83. package/dist-esm/records/TLAsset.mjs.map +2 -2
  84. package/dist-esm/records/TLBinding.mjs.map +2 -2
  85. package/dist-esm/records/TLCamera.mjs.map +2 -2
  86. package/dist-esm/records/TLDocument.mjs.map +2 -2
  87. package/dist-esm/records/TLInstance.mjs.map +2 -2
  88. package/dist-esm/records/TLPage.mjs.map +2 -2
  89. package/dist-esm/records/TLPageState.mjs.map +2 -2
  90. package/dist-esm/records/TLPointer.mjs.map +2 -2
  91. package/dist-esm/records/TLPresence.mjs.map +2 -2
  92. package/dist-esm/records/TLShape.mjs.map +2 -2
  93. package/dist-esm/recordsWithProps.mjs.map +2 -2
  94. package/dist-esm/shapes/TLArrowShape.mjs.map +2 -2
  95. package/dist-esm/shapes/TLBaseShape.mjs.map +2 -2
  96. package/dist-esm/shapes/TLBookmarkShape.mjs.map +2 -2
  97. package/dist-esm/shapes/TLDrawShape.mjs.map +2 -2
  98. package/dist-esm/shapes/TLEmbedShape.mjs +0 -10
  99. package/dist-esm/shapes/TLEmbedShape.mjs.map +2 -2
  100. package/dist-esm/shapes/TLFrameShape.mjs.map +2 -2
  101. package/dist-esm/shapes/TLGeoShape.mjs.map +2 -2
  102. package/dist-esm/shapes/TLGroupShape.mjs.map +2 -2
  103. package/dist-esm/shapes/TLHighlightShape.mjs.map +2 -2
  104. package/dist-esm/shapes/TLImageShape.mjs.map +2 -2
  105. package/dist-esm/shapes/TLLineShape.mjs.map +2 -2
  106. package/dist-esm/shapes/TLNoteShape.mjs.map +2 -2
  107. package/dist-esm/shapes/TLTextShape.mjs.map +2 -2
  108. package/dist-esm/shapes/TLVideoShape.mjs.map +2 -2
  109. package/dist-esm/store-migrations.mjs.map +2 -2
  110. package/dist-esm/styles/TLColorStyle.mjs.map +2 -2
  111. package/dist-esm/styles/TLDashStyle.mjs.map +2 -2
  112. package/dist-esm/styles/TLFillStyle.mjs.map +2 -2
  113. package/dist-esm/styles/TLFontStyle.mjs.map +2 -2
  114. package/dist-esm/styles/TLHorizontalAlignStyle.mjs.map +2 -2
  115. package/dist-esm/styles/TLSizeStyle.mjs.map +2 -2
  116. package/dist-esm/styles/TLTextAlignStyle.mjs.map +2 -2
  117. package/dist-esm/styles/TLVerticalAlignStyle.mjs.map +2 -2
  118. package/dist-esm/translations/translations.mjs +1 -1
  119. package/dist-esm/translations/translations.mjs.map +2 -2
  120. package/package.json +5 -5
  121. package/src/TLStore.test.ts +644 -0
  122. package/src/TLStore.ts +205 -20
  123. package/src/assets/TLBaseAsset.ts +90 -7
  124. package/src/assets/TLBookmarkAsset.test.ts +96 -0
  125. package/src/assets/TLBookmarkAsset.ts +52 -2
  126. package/src/assets/TLImageAsset.test.ts +213 -0
  127. package/src/assets/TLImageAsset.ts +60 -2
  128. package/src/assets/TLVideoAsset.test.ts +105 -0
  129. package/src/assets/TLVideoAsset.ts +93 -4
  130. package/src/bindings/TLArrowBinding.test.ts +55 -0
  131. package/src/bindings/TLArrowBinding.ts +132 -10
  132. package/src/bindings/TLBaseBinding.ts +140 -3
  133. package/src/createPresenceStateDerivation.test.ts +158 -0
  134. package/src/createPresenceStateDerivation.ts +71 -2
  135. package/src/createTLSchema.test.ts +181 -0
  136. package/src/createTLSchema.ts +164 -7
  137. package/src/index.ts +32 -0
  138. package/src/misc/TLColor.ts +50 -6
  139. package/src/misc/TLCursor.ts +110 -8
  140. package/src/misc/TLHandle.ts +86 -6
  141. package/src/misc/TLOpacity.ts +51 -2
  142. package/src/misc/TLRichText.ts +56 -3
  143. package/src/misc/TLScribble.ts +105 -5
  144. package/src/misc/geometry-types.ts +30 -2
  145. package/src/misc/id-validator.test.ts +50 -0
  146. package/src/misc/id-validator.ts +20 -1
  147. package/src/records/TLAsset.test.ts +234 -0
  148. package/src/records/TLAsset.ts +165 -8
  149. package/src/records/TLBinding.test.ts +22 -0
  150. package/src/records/TLBinding.ts +277 -11
  151. package/src/records/TLCamera.test.ts +19 -0
  152. package/src/records/TLCamera.ts +118 -7
  153. package/src/records/TLDocument.test.ts +35 -0
  154. package/src/records/TLDocument.ts +148 -8
  155. package/src/records/TLInstance.test.ts +201 -0
  156. package/src/records/TLInstance.ts +117 -9
  157. package/src/records/TLPage.test.ts +110 -0
  158. package/src/records/TLPage.ts +106 -8
  159. package/src/records/TLPageState.test.ts +228 -0
  160. package/src/records/TLPageState.ts +88 -7
  161. package/src/records/TLPointer.test.ts +63 -0
  162. package/src/records/TLPointer.ts +105 -7
  163. package/src/records/TLPresence.test.ts +190 -0
  164. package/src/records/TLPresence.ts +99 -5
  165. package/src/records/TLRecord.test.ts +70 -0
  166. package/src/records/TLRecord.ts +43 -1
  167. package/src/records/TLShape.test.ts +232 -0
  168. package/src/records/TLShape.ts +289 -12
  169. package/src/recordsWithProps.test.ts +188 -0
  170. package/src/recordsWithProps.ts +131 -2
  171. package/src/shapes/ShapeWithCrop.test.ts +18 -0
  172. package/src/shapes/ShapeWithCrop.ts +64 -2
  173. package/src/shapes/TLArrowShape.test.ts +505 -0
  174. package/src/shapes/TLArrowShape.ts +188 -10
  175. package/src/shapes/TLBaseShape.test.ts +142 -0
  176. package/src/shapes/TLBaseShape.ts +103 -4
  177. package/src/shapes/TLBookmarkShape.test.ts +122 -0
  178. package/src/shapes/TLBookmarkShape.ts +58 -4
  179. package/src/shapes/TLDrawShape.test.ts +177 -0
  180. package/src/shapes/TLDrawShape.ts +97 -6
  181. package/src/shapes/TLEmbedShape.test.ts +286 -0
  182. package/src/shapes/TLEmbedShape.ts +57 -14
  183. package/src/shapes/TLFrameShape.test.ts +71 -0
  184. package/src/shapes/TLFrameShape.ts +59 -4
  185. package/src/shapes/TLGeoShape.test.ts +247 -0
  186. package/src/shapes/TLGeoShape.ts +103 -7
  187. package/src/shapes/TLGroupShape.test.ts +59 -0
  188. package/src/shapes/TLGroupShape.ts +52 -4
  189. package/src/shapes/TLHighlightShape.test.ts +325 -0
  190. package/src/shapes/TLHighlightShape.ts +79 -4
  191. package/src/shapes/TLImageShape.test.ts +534 -0
  192. package/src/shapes/TLImageShape.ts +105 -5
  193. package/src/shapes/TLLineShape.test.ts +269 -0
  194. package/src/shapes/TLLineShape.ts +128 -8
  195. package/src/shapes/TLNoteShape.test.ts +1568 -0
  196. package/src/shapes/TLNoteShape.ts +97 -4
  197. package/src/shapes/TLTextShape.test.ts +407 -0
  198. package/src/shapes/TLTextShape.ts +94 -4
  199. package/src/shapes/TLVideoShape.test.ts +112 -0
  200. package/src/shapes/TLVideoShape.ts +99 -4
  201. package/src/store-migrations.test.ts +88 -0
  202. package/src/store-migrations.ts +47 -1
  203. package/src/styles/TLColorStyle.test.ts +439 -0
  204. package/src/styles/TLColorStyle.ts +228 -10
  205. package/src/styles/TLDashStyle.ts +54 -2
  206. package/src/styles/TLFillStyle.ts +54 -2
  207. package/src/styles/TLFontStyle.ts +72 -3
  208. package/src/styles/TLHorizontalAlignStyle.ts +55 -2
  209. package/src/styles/TLSizeStyle.ts +54 -2
  210. package/src/styles/TLTextAlignStyle.ts +52 -2
  211. package/src/styles/TLVerticalAlignStyle.ts +52 -2
  212. package/src/translations/translations.test.ts +378 -35
  213. package/src/translations/translations.ts +157 -10
  214. package/src/util-types.ts +51 -1
@@ -0,0 +1,269 @@
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
+ })
@@ -8,20 +8,57 @@ import { DefaultDashStyle, TLDefaultDashStyle } from '../styles/TLDashStyle'
8
8
  import { DefaultSizeStyle, TLDefaultSizeStyle } from '../styles/TLSizeStyle'
9
9
  import { TLBaseShape } from './TLBaseShape'
10
10
 
11
- /** @public */
11
+ /**
12
+ * Style property for line shape spline interpolation. Determines how the line is rendered
13
+ * between points - either as straight line segments or smooth cubic curves.
14
+ *
15
+ * @public
16
+ * @example
17
+ * ```ts
18
+ * // Create a shape with cubic spline interpolation
19
+ * const lineProps = {
20
+ * spline: 'cubic' as TLLineShapeSplineStyle,
21
+ * // other props...
22
+ * }
23
+ * ```
24
+ */
12
25
  export const LineShapeSplineStyle = StyleProp.defineEnum('tldraw:spline', {
13
26
  defaultValue: 'line',
14
27
  values: ['cubic', 'line'],
15
28
  })
16
29
 
17
- /** @public */
30
+ /**
31
+ * Type representing the spline style options for line shapes.
32
+ * - 'line': Straight line segments between points
33
+ * - 'cubic': Smooth cubic bezier curves between points
34
+ *
35
+ * @public
36
+ */
18
37
  export type TLLineShapeSplineStyle = T.TypeOf<typeof LineShapeSplineStyle>
19
38
 
20
- /** @public */
39
+ /**
40
+ * Represents a single point in a line shape. Line shapes are made up of multiple points
41
+ * that define the path of the line, with each point having coordinates and ordering information.
42
+ *
43
+ * @public
44
+ * @example
45
+ * ```ts
46
+ * const linePoint: TLLineShapePoint = {
47
+ * id: 'a1',
48
+ * index: 'a1' as IndexKey,
49
+ * x: 100,
50
+ * y: 50
51
+ * }
52
+ * ```
53
+ */
21
54
  export interface TLLineShapePoint {
55
+ /** Unique identifier for this point, used for tracking and ordering */
22
56
  id: string
57
+ /** Fractional index key used for ordering points along the line */
23
58
  index: IndexKey
59
+ /** X coordinate of the point relative to the line shape's origin */
24
60
  x: number
61
+ /** Y coordinate of the point relative to the line shape's origin */
25
62
  y: number
26
63
  }
27
64
 
@@ -32,20 +69,91 @@ const lineShapePointValidator: T.ObjectValidator<TLLineShapePoint> = T.object({
32
69
  y: T.number,
33
70
  })
34
71
 
35
- /** @public */
72
+ /**
73
+ * Properties for a line shape. Line shapes represent multi-point lines or splines
74
+ * that can be drawn by connecting multiple points with either straight segments or curves.
75
+ *
76
+ * @public
77
+ * @example
78
+ * ```ts
79
+ * const lineProps: TLLineShapeProps = {
80
+ * color: 'black',
81
+ * dash: 'solid',
82
+ * size: 'm',
83
+ * spline: 'line',
84
+ * points: {
85
+ * 'a1': { id: 'a1', index: 'a1', x: 0, y: 0 },
86
+ * 'a2': { id: 'a2', index: 'a2', x: 100, y: 50 }
87
+ * },
88
+ * scale: 1
89
+ * }
90
+ * ```
91
+ */
36
92
  export interface TLLineShapeProps {
93
+ /** Color style of the line stroke */
37
94
  color: TLDefaultColorStyle
95
+ /** Dash pattern style for the line (solid, dashed, dotted) */
38
96
  dash: TLDefaultDashStyle
97
+ /** Size/thickness style of the line stroke */
39
98
  size: TLDefaultSizeStyle
99
+ /** Interpolation style between points (straight lines or curved splines) */
40
100
  spline: TLLineShapeSplineStyle
101
+ /** Dictionary of points that make up the line, keyed by point ID */
41
102
  points: Record<string, TLLineShapePoint>
103
+ /** Scale factor applied to the line shape for display */
42
104
  scale: number
43
105
  }
44
106
 
45
- /** @public */
107
+ /**
108
+ * A line shape that represents a multi-point line or spline on the canvas. Line shapes
109
+ * allow users to draw connected paths with multiple points, supporting both straight
110
+ * line segments and smooth curved splines.
111
+ *
112
+ * @public
113
+ * @example
114
+ * ```ts
115
+ * const lineShape: TLLineShape = {
116
+ * id: 'shape:line1',
117
+ * type: 'line',
118
+ * x: 100,
119
+ * y: 100,
120
+ * rotation: 0,
121
+ * index: 'a1',
122
+ * parentId: 'page:main',
123
+ * isLocked: false,
124
+ * opacity: 1,
125
+ * props: {
126
+ * color: 'red',
127
+ * dash: 'dashed',
128
+ * size: 'l',
129
+ * spline: 'cubic',
130
+ * points: {
131
+ * 'start': { id: 'start', index: 'a1', x: 0, y: 0 },
132
+ * 'end': { id: 'end', index: 'a2', x: 200, y: 100 }
133
+ * },
134
+ * scale: 1
135
+ * },
136
+ * meta: {},
137
+ * typeName: 'shape'
138
+ * }
139
+ * ```
140
+ */
46
141
  export type TLLineShape = TLBaseShape<'line', TLLineShapeProps>
47
142
 
48
- /** @public */
143
+ /**
144
+ * Validation schema for line shape properties. Defines the runtime validation rules
145
+ * for all properties of line shapes, ensuring data integrity and type safety.
146
+ *
147
+ * @public
148
+ * @example
149
+ * ```ts
150
+ * import { lineShapeProps } from '@tldraw/tlschema'
151
+ *
152
+ * // Used internally by the validation system
153
+ * const validator = T.object(lineShapeProps)
154
+ * const validatedProps = validator.validate(someLineProps)
155
+ * ```
156
+ */
49
157
  export const lineShapeProps: RecordProps<TLLineShape> = {
50
158
  color: DefaultColorStyle,
51
159
  dash: DefaultDashStyle,
@@ -55,7 +163,12 @@ export const lineShapeProps: RecordProps<TLLineShape> = {
55
163
  scale: T.nonZeroNumber,
56
164
  }
57
165
 
58
- /** @public */
166
+ /**
167
+ * Version identifiers for line shape migrations. These version numbers track
168
+ * significant schema changes over time, enabling proper data migration between versions.
169
+ *
170
+ * @public
171
+ */
59
172
  export const lineShapeVersions = createShapePropsMigrationIds('line', {
60
173
  AddSnapHandles: 1,
61
174
  RemoveExtraHandleProps: 2,
@@ -64,7 +177,14 @@ export const lineShapeVersions = createShapePropsMigrationIds('line', {
64
177
  AddScale: 5,
65
178
  })
66
179
 
67
- /** @public */
180
+ /**
181
+ * Migration sequence for line shapes. Handles schema evolution over time by defining
182
+ * how to upgrade and downgrade line shape data between different versions. Includes
183
+ * major structural changes like the transition from handles to points and the addition
184
+ * of scaling support.
185
+ *
186
+ * @public
187
+ */
68
188
  export const lineShapeMigrations = createShapePropsMigrationSequence({
69
189
  sequence: [
70
190
  {