@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,232 +0,0 @@
1
- import { T } from '@tldraw/validate'
2
- import { describe, expect, it } from 'vitest'
3
- import { StyleProp } from '../styles/StyleProp'
4
- import {
5
- createShapeId,
6
- createShapePropsMigrationIds,
7
- createShapeRecordType,
8
- getShapePropKeysByStyle,
9
- isShape,
10
- isShapeId,
11
- rootShapeMigrations,
12
- rootShapeVersions,
13
- TLShapeId,
14
- } from './TLShape'
15
-
16
- describe('rootShapeMigrations', () => {
17
- it('should migrate AddIsLocked correctly', () => {
18
- const migration = rootShapeMigrations.sequence.find(
19
- (m) => m.id === rootShapeVersions.AddIsLocked
20
- )!
21
- expect(migration.up).toBeDefined()
22
- expect(migration.down).toBeDefined()
23
-
24
- const record: any = { id: 'shape:test', typeName: 'shape', type: 'geo' }
25
- migration.up(record)
26
- expect(record.isLocked).toBe(false)
27
-
28
- migration.down!(record)
29
- expect(record.isLocked).toBeUndefined()
30
- })
31
-
32
- it('should migrate HoistOpacity correctly', () => {
33
- const migration = rootShapeMigrations.sequence.find(
34
- (m) => m.id === rootShapeVersions.HoistOpacity
35
- )!
36
- expect(migration.up).toBeDefined()
37
- expect(migration.down).toBeDefined()
38
-
39
- // Test up migration
40
- const record: any = {
41
- id: 'shape:test',
42
- typeName: 'shape',
43
- type: 'geo',
44
- props: { opacity: '0.5', color: 'red' },
45
- }
46
- migration.up(record)
47
- expect(record.opacity).toBe(0.5)
48
- expect(record.props.opacity).toBeUndefined()
49
- expect(record.props.color).toBe('red')
50
-
51
- // Test down migration
52
- migration.down!(record)
53
- expect(record.props.opacity).toBe('0.5')
54
- expect(record.opacity).toBeUndefined()
55
- })
56
-
57
- it('should migrate AddMeta correctly', () => {
58
- const migration = rootShapeMigrations.sequence.find((m) => m.id === rootShapeVersions.AddMeta)!
59
- const record: any = { id: 'shape:test', typeName: 'shape', type: 'geo' }
60
- migration.up(record)
61
- expect(record.meta).toEqual({})
62
- })
63
-
64
- it('should handle AddWhite migration', () => {
65
- const migration = rootShapeMigrations.sequence.find((m) => m.id === rootShapeVersions.AddWhite)!
66
- expect(migration.up).toBeDefined()
67
- expect(migration.down).toBeDefined()
68
-
69
- // Up migration is noop
70
- const record: any = { props: { color: 'white' } }
71
- const original = { ...record }
72
- migration.up(record)
73
- expect(record).toEqual(original)
74
-
75
- // Down migration converts white to black
76
- migration.down!(record)
77
- expect(record.props.color).toBe('black')
78
- })
79
- })
80
-
81
- describe('isShape', () => {
82
- it('should return true for shape records', () => {
83
- const shape = {
84
- id: 'shape:test' as TLShapeId,
85
- typeName: 'shape',
86
- type: 'geo',
87
- x: 0,
88
- y: 0,
89
- rotation: 0,
90
- index: 'a1' as any,
91
- parentId: 'page:main' as any,
92
- isLocked: false,
93
- opacity: 1,
94
- props: {},
95
- meta: {},
96
- }
97
-
98
- expect(isShape(shape)).toBe(true)
99
- })
100
-
101
- it('should return false for non-shape records', () => {
102
- const notShape = {
103
- id: 'page:test',
104
- typeName: 'page',
105
- name: 'Test Page',
106
- }
107
-
108
- expect(isShape(notShape as any)).toBe(false)
109
- })
110
- })
111
-
112
- describe('isShapeId', () => {
113
- it('should return true for valid shape IDs', () => {
114
- expect(isShapeId('shape:test')).toBe(true)
115
- expect(isShapeId('shape:abc123')).toBe(true)
116
- expect(isShapeId('shape:')).toBe(true)
117
- })
118
-
119
- it('should return false for invalid shape IDs', () => {
120
- expect(isShapeId('page:test')).toBe(false)
121
- expect(isShapeId('asset:test')).toBe(false)
122
- expect(isShapeId('invalid')).toBe(false)
123
- expect(isShapeId('')).toBe(false)
124
- })
125
- })
126
-
127
- describe('createShapeId', () => {
128
- it('should create shape IDs with auto-generated suffix', () => {
129
- const id1 = createShapeId()
130
- const id2 = createShapeId()
131
-
132
- expect(id1.startsWith('shape:')).toBe(true)
133
- expect(id2.startsWith('shape:')).toBe(true)
134
- expect(id1).not.toBe(id2)
135
- expect(id1.length).toBeGreaterThan(6) // 'shape:' + some ID
136
- expect(id2.length).toBeGreaterThan(6)
137
- })
138
-
139
- it('should create shape IDs with custom suffix', () => {
140
- const customId = createShapeId('my-custom-id')
141
- expect(customId).toBe('shape:my-custom-id')
142
- })
143
- })
144
-
145
- describe('getShapePropKeysByStyle', () => {
146
- it('should map style props to their keys', () => {
147
- const colorStyle = StyleProp.define('color', { defaultValue: 'black' })
148
- const sizeStyle = StyleProp.define('size', { defaultValue: 'm' })
149
-
150
- const props = {
151
- color: colorStyle,
152
- size: sizeStyle,
153
- width: T.number,
154
- height: T.number,
155
- }
156
-
157
- const styleMap = getShapePropKeysByStyle(props)
158
- expect(styleMap.get(colorStyle)).toBe('color')
159
- expect(styleMap.get(sizeStyle)).toBe('size')
160
- expect(styleMap.size).toBe(2) // Only style props
161
- })
162
-
163
- it('should throw error for duplicate style props', () => {
164
- const colorStyle = StyleProp.define('color', { defaultValue: 'black' })
165
- const props = {
166
- color1: colorStyle,
167
- color2: colorStyle, // Same style prop used twice
168
- width: T.number,
169
- }
170
-
171
- expect(() => getShapePropKeysByStyle(props)).toThrow('Duplicate style prop')
172
- })
173
- })
174
-
175
- describe('createShapePropsMigrationIds', () => {
176
- it('should create formatted migration IDs', () => {
177
- const ids = createShapePropsMigrationIds('custom', {
178
- AddColor: 1,
179
- AddSize: 2,
180
- RefactorProps: 3,
181
- })
182
-
183
- expect(ids.AddColor).toBe('com.tldraw.shape.custom/1')
184
- expect(ids.AddSize).toBe('com.tldraw.shape.custom/2')
185
- expect(ids.RefactorProps).toBe('com.tldraw.shape.custom/3')
186
- })
187
- })
188
-
189
- describe('createShapeRecordType', () => {
190
- it('should create a record type for shapes', () => {
191
- const shapes = {
192
- geo: {
193
- props: {
194
- w: T.number,
195
- h: T.number,
196
- color: StyleProp.define('color', { defaultValue: 'black' }),
197
- },
198
- meta: {},
199
- },
200
- text: {
201
- props: {
202
- text: T.string,
203
- size: StyleProp.define('size', { defaultValue: 'm' }),
204
- },
205
- meta: {},
206
- },
207
- }
208
-
209
- const ShapeRecordType = createShapeRecordType(shapes)
210
-
211
- expect(ShapeRecordType.typeName).toBe('shape')
212
- expect(ShapeRecordType.scope).toBe('document')
213
-
214
- // Should be able to create shapes
215
- const geoShape = ShapeRecordType.create({
216
- id: createShapeId(),
217
- type: 'geo',
218
- parentId: 'page:main' as any,
219
- index: 'a1' as any,
220
- props: {},
221
- })
222
-
223
- expect(geoShape.typeName).toBe('shape')
224
- expect(geoShape.type).toBe('geo')
225
- expect(geoShape.x).toBe(0) // Default
226
- expect(geoShape.y).toBe(0) // Default
227
- expect(geoShape.rotation).toBe(0) // Default
228
- expect(geoShape.isLocked).toBe(false) // Default
229
- expect(geoShape.opacity).toBe(1) // Default
230
- expect(geoShape.meta).toEqual({}) // Default
231
- })
232
- })
@@ -1,18 +0,0 @@
1
- import { describe, expect, test } from 'vitest'
2
- import { TLShapeCrop } from './ShapeWithCrop'
3
-
4
- describe('TLShapeCrop', () => {
5
- test('should calculate crop dimensions correctly', () => {
6
- const crop: TLShapeCrop = {
7
- topLeft: { x: 0.2, y: 0.3 },
8
- bottomRight: { x: 0.8, y: 0.7 },
9
- }
10
-
11
- // This tests the actual utility of the crop interface - calculating dimensions
12
- const width = crop.bottomRight.x - crop.topLeft.x
13
- const height = crop.bottomRight.y - crop.topLeft.y
14
-
15
- expect(width).toBeCloseTo(0.6)
16
- expect(height).toBeCloseTo(0.4)
17
- })
18
- })