@tldraw/editor 4.1.0-canary.26ae045fbc36 → 4.1.0-canary.28a22fbe3d17

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 (69) hide show
  1. package/dist-cjs/index.d.ts +16 -3
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +2 -2
  5. package/dist-cjs/lib/components/ErrorBoundary.js +1 -1
  6. package/dist-cjs/lib/components/HTMLContainer.js +1 -1
  7. package/dist-cjs/lib/components/SVGContainer.js +1 -1
  8. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -1
  9. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
  10. package/dist-cjs/lib/components/default-components/DefaultCursor.js +1 -1
  11. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
  12. package/dist-cjs/lib/components/default-components/DefaultHandle.js +1 -1
  13. package/dist-cjs/lib/components/default-components/DefaultScribble.js +1 -1
  14. package/dist-cjs/lib/components/default-components/DefaultSelectionBackground.js +1 -1
  15. package/dist-cjs/lib/components/default-components/DefaultSelectionForeground.js +1 -1
  16. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +1 -1
  17. package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js +1 -1
  18. package/dist-cjs/lib/components/default-components/DefaultSnapIndictor.js +2 -2
  19. package/dist-cjs/lib/components/default-components/DefaultSpinner.js +1 -1
  20. package/dist-cjs/lib/editor/Editor.js +5 -3
  21. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  22. package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js +67 -2
  23. package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +2 -2
  24. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  25. package/dist-cjs/lib/hooks/useCanvasEvents.js +2 -1
  26. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  27. package/dist-cjs/lib/hooks/useDarkMode.js +1 -1
  28. package/dist-cjs/lib/hooks/useEditor.js +1 -1
  29. package/dist-cjs/lib/hooks/useGestureEvents.js +1 -1
  30. package/dist-cjs/lib/hooks/useHandleEvents.js +1 -1
  31. package/dist-cjs/lib/hooks/useZoomCss.js +1 -1
  32. package/dist-cjs/lib/license/LicenseManager.js +20 -12
  33. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  34. package/dist-cjs/lib/license/Watermark.js +4 -4
  35. package/dist-cjs/lib/license/Watermark.js.map +1 -1
  36. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +5 -0
  37. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  38. package/dist-cjs/version.js +3 -3
  39. package/dist-cjs/version.js.map +1 -1
  40. package/dist-esm/index.d.mts +16 -3
  41. package/dist-esm/index.mjs +1 -1
  42. package/dist-esm/index.mjs.map +2 -2
  43. package/dist-esm/lib/editor/Editor.mjs +5 -2
  44. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  45. package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs +67 -2
  46. package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +2 -2
  47. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  48. package/dist-esm/lib/hooks/useCanvasEvents.mjs +2 -1
  49. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  50. package/dist-esm/lib/license/LicenseManager.mjs +20 -12
  51. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  52. package/dist-esm/lib/license/Watermark.mjs +4 -4
  53. package/dist-esm/lib/license/Watermark.mjs.map +1 -1
  54. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +5 -0
  55. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  56. package/dist-esm/version.mjs +3 -3
  57. package/dist-esm/version.mjs.map +1 -1
  58. package/editor.css +7 -2
  59. package/package.json +7 -7
  60. package/src/index.ts +0 -1
  61. package/src/lib/editor/Editor.ts +5 -2
  62. package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +91 -4
  63. package/src/lib/editor/shapes/ShapeUtil.ts +10 -0
  64. package/src/lib/hooks/useCanvasEvents.ts +8 -1
  65. package/src/lib/license/LicenseManager.test.ts +68 -4
  66. package/src/lib/license/LicenseManager.ts +27 -20
  67. package/src/lib/license/Watermark.tsx +4 -4
  68. package/src/lib/primitives/geometry/Geometry2d.ts +6 -0
  69. package/src/version.ts +3 -3
@@ -87,9 +87,6 @@ export interface ValidLicenseKeyResult {
87
87
  daysSinceExpiry: number
88
88
  }
89
89
 
90
- /** @internal */
91
- export type TestEnvironment = 'development' | 'production'
92
-
93
90
  /** @internal */
94
91
  export type TrackType = 'unlicensed' | 'with_watermark' | 'evaluation' | null
95
92
 
@@ -103,13 +100,9 @@ export class LicenseManager {
103
100
  state = atom<LicenseState>('license state', 'pending')
104
101
  public verbose = true
105
102
 
106
- constructor(
107
- licenseKey: string | undefined,
108
- testPublicKey?: string,
109
- testEnvironment?: TestEnvironment
110
- ) {
103
+ constructor(licenseKey: string | undefined, testPublicKey?: string) {
111
104
  this.isTest = process.env.NODE_ENV === 'test'
112
- this.isDevelopment = this.getIsDevelopment(testEnvironment)
105
+ this.isDevelopment = this.getIsDevelopment()
113
106
  this.publicKey = testPublicKey || this.publicKey
114
107
  this.isCryptoAvailable = !!crypto.subtle
115
108
 
@@ -131,14 +124,12 @@ export class LicenseManager {
131
124
  })
132
125
  }
133
126
 
134
- private getIsDevelopment(testEnvironment?: TestEnvironment) {
135
- if (testEnvironment === 'development') return true
136
- if (testEnvironment === 'production') return false
137
-
127
+ private getIsDevelopment() {
138
128
  // If we are using https on a non-localhost domain we assume it's a production env and a development one otherwise
139
129
  return (
140
130
  !['https:', 'vscode-webview:'].includes(window.location.protocol) ||
141
- window.location.hostname === 'localhost'
131
+ window.location.hostname === 'localhost' ||
132
+ process.env.NODE_ENV !== 'production'
142
133
  )
143
134
  }
144
135
 
@@ -180,6 +171,17 @@ export class LicenseManager {
180
171
  url.searchParams.set('license_type', trackType)
181
172
  if ('license' in result) {
182
173
  url.searchParams.set('license_id', result.license.id)
174
+ const sku = this.isFlagEnabled(result.license.flags, FLAGS.EVALUATION_LICENSE)
175
+ ? 'evaluation'
176
+ : this.isFlagEnabled(result.license.flags, FLAGS.ANNUAL_LICENSE)
177
+ ? 'annual'
178
+ : this.isFlagEnabled(result.license.flags, FLAGS.PERPETUAL_LICENSE)
179
+ ? 'perpetual'
180
+ : 'unknown'
181
+ url.searchParams.set('sku', sku)
182
+ }
183
+ if (process.env.NODE_ENV) {
184
+ url.searchParams.set('environment', process.env.NODE_ENV)
183
185
  }
184
186
 
185
187
  // eslint-disable-next-line no-restricted-globals
@@ -415,22 +417,27 @@ export class LicenseManager {
415
417
  // If we added a new flag it will be twice the value of the currently highest flag.
416
418
  // And if all the current flags are on we would get the `HIGHEST_FLAG * 2 - 1`, so anything higher than that means there are new flags.
417
419
  if (result.license.flags >= HIGHEST_FLAG * 2) {
418
- this.outputMessages([
419
- 'This tldraw license contains some unknown flags.',
420
- 'You may want to update tldraw packages to a newer version to get access to new functionality.',
421
- ])
420
+ this.outputMessages(
421
+ [
422
+ 'Warning: This tldraw license contains some unknown flags.',
423
+ 'This will still work, however, you may want to update tldraw packages to a newer version to get access to new functionality.',
424
+ ],
425
+ 'warning'
426
+ )
422
427
  }
423
428
  }
424
429
 
425
- private outputMessages(messages: string[]) {
430
+ private outputMessages(messages: string[], type: 'warning' | 'error' = 'error') {
426
431
  if (this.isTest) return
427
432
  if (this.verbose) {
428
433
  this.outputDelimiter()
429
434
  for (const message of messages) {
435
+ const color = type === 'warning' ? 'orange' : 'crimson'
436
+ const bgColor = type === 'warning' ? 'orange' : 'crimson'
430
437
  // eslint-disable-next-line no-console
431
438
  console.log(
432
439
  `%c${message}`,
433
- `color: white; background: crimson; padding: 2px; border-radius: 3px;`
440
+ `color: ${color}; background: ${bgColor}; padding: 2px; border-radius: 3px;`
434
441
  )
435
442
  }
436
443
  this.outputDelimiter()
@@ -208,22 +208,22 @@ To remove the watermark, please purchase a license at tldraw.dev.
208
208
  }
209
209
 
210
210
  @media (hover: hover) {
211
- .${className}[data-licensed='false'] > button {
211
+ .${className} > button {
212
212
  pointer-events: none;
213
213
  }
214
214
 
215
- .${className}[data-licensed='false']:hover {
215
+ .${className}:hover {
216
216
  background-color: var(--tl-color-background);
217
217
  transition: background-color 0.2s ease-in-out;
218
218
  transition-delay: 0.32s;
219
219
  }
220
220
 
221
- .${className}[data-licensed='false']:hover > button {
221
+ .${className}:hover > button {
222
222
  animation: ${className}_delayed_link 0.2s forwards ease-in-out;
223
223
  animation-delay: 0.32s;
224
224
  }
225
225
 
226
- .${className}[data-licensed='false'] > button:focus-visible {
226
+ .${className} > button:focus-visible {
227
227
  opacity: 1;
228
228
  }
229
229
  }
@@ -120,6 +120,8 @@ export abstract class Geometry2d {
120
120
  distanceToLineSegment(A: VecLike, B: VecLike, filters?: Geometry2dFilters) {
121
121
  if (Vec.Equals(A, B)) return this.distanceToPoint(A, false, filters)
122
122
  const { vertices } = this
123
+ if (vertices.length === 0) throw Error('nearest point not found')
124
+ if (vertices.length === 1) return Vec.Dist(A, vertices[0])
123
125
  let nearest: Vec | undefined
124
126
  let dist = Infinity
125
127
  let d: number, p: Vec, q: Vec
@@ -175,6 +177,8 @@ export abstract class Geometry2d {
175
177
  interpolateAlongEdge(t: number, _filters?: Geometry2dFilters): Vec {
176
178
  const { vertices } = this
177
179
 
180
+ if (vertices.length === 0) return new Vec(0, 0)
181
+ if (vertices.length === 1) return vertices[0]
178
182
  if (t <= 0) return vertices[0]
179
183
 
180
184
  const distanceToTravel = t * this.length
@@ -209,6 +213,8 @@ export abstract class Geometry2d {
209
213
  let closestDistance = Infinity
210
214
  let distanceTraveled = 0
211
215
 
216
+ if (vertices.length === 0 || vertices.length === 1) return 0
217
+
212
218
  for (let i = 0; i < (this.isClosed ? vertices.length : vertices.length - 1); i++) {
213
219
  const curr = vertices[i]
214
220
  const next = vertices[(i + 1) % vertices.length]
package/src/version.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  // This file is automatically generated by internal/scripts/refresh-assets.ts.
2
2
  // Do not edit manually. Or do, I'm a comment, not a cop.
3
3
 
4
- export const version = '4.1.0-canary.26ae045fbc36'
4
+ export const version = '4.1.0-canary.28a22fbe3d17'
5
5
  export const publishDates = {
6
6
  major: '2025-09-18T14:39:22.803Z',
7
- minor: '2025-09-18T15:36:46.069Z',
8
- patch: '2025-09-18T15:36:46.069Z',
7
+ minor: '2025-10-15T09:33:34.956Z',
8
+ patch: '2025-10-15T09:33:34.956Z',
9
9
  }