@tldraw/editor 3.16.0-canary.1647ca5bba28 → 3.16.0-canary.1e91d2e19e07

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 (66) hide show
  1. package/dist-cjs/index.d.ts +17 -0
  2. package/dist-cjs/index.js +3 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +1 -1
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/editor/Editor.js +3 -2
  7. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  8. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +4 -0
  9. package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
  10. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +10 -0
  11. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  12. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +4 -1
  13. package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +2 -2
  14. package/dist-cjs/lib/license/LicenseManager.js +128 -35
  15. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  16. package/dist-cjs/lib/license/LicenseProvider.js +36 -3
  17. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  18. package/dist-cjs/lib/license/Watermark.js +68 -6
  19. package/dist-cjs/lib/license/Watermark.js.map +3 -3
  20. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +24 -2
  21. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  22. package/dist-cjs/lib/primitives/geometry/Group2d.js +5 -1
  23. package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
  24. package/dist-cjs/version.js +3 -3
  25. package/dist-cjs/version.js.map +1 -1
  26. package/dist-esm/index.d.mts +17 -0
  27. package/dist-esm/index.mjs +3 -1
  28. package/dist-esm/index.mjs.map +2 -2
  29. package/dist-esm/lib/TldrawEditor.mjs +1 -1
  30. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  31. package/dist-esm/lib/editor/Editor.mjs +3 -2
  32. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  33. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +4 -0
  34. package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
  35. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +10 -0
  36. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  37. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +4 -1
  38. package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +2 -2
  39. package/dist-esm/lib/license/LicenseManager.mjs +129 -36
  40. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  41. package/dist-esm/lib/license/LicenseProvider.mjs +36 -4
  42. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  43. package/dist-esm/lib/license/Watermark.mjs +68 -6
  44. package/dist-esm/lib/license/Watermark.mjs.map +3 -3
  45. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +24 -2
  46. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  47. package/dist-esm/lib/primitives/geometry/Group2d.mjs +5 -1
  48. package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
  49. package/dist-esm/version.mjs +3 -3
  50. package/dist-esm/version.mjs.map +1 -1
  51. package/editor.css +8 -3
  52. package/package.json +7 -7
  53. package/src/index.ts +1 -0
  54. package/src/lib/TldrawEditor.tsx +1 -2
  55. package/src/lib/editor/Editor.ts +4 -2
  56. package/src/lib/editor/derivations/notVisibleShapes.ts +6 -0
  57. package/src/lib/editor/shapes/ShapeUtil.ts +11 -0
  58. package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
  59. package/src/lib/license/LicenseManager.test.ts +687 -387
  60. package/src/lib/license/LicenseManager.ts +180 -44
  61. package/src/lib/license/LicenseProvider.tsx +69 -5
  62. package/src/lib/license/Watermark.tsx +73 -6
  63. package/src/lib/primitives/geometry/Geometry2d.test.ts +420 -0
  64. package/src/lib/primitives/geometry/Geometry2d.ts +29 -2
  65. package/src/lib/primitives/geometry/Group2d.ts +6 -1
  66. package/src/version.ts +3 -3
@@ -1,16 +1,27 @@
1
1
  import { atom } from '@tldraw/state'
2
- import { fetch } from '@tldraw/utils'
3
- import { publishDates } from '../../version'
2
+ import { publishDates, version } from '../../version'
4
3
  import { getDefaultCdnBaseUrl } from '../utils/assets'
5
4
  import { importPublicKey, str2ab } from '../utils/licensing'
6
5
 
7
- const GRACE_PERIOD_DAYS = 5
6
+ const GRACE_PERIOD_DAYS = 30
8
7
 
9
8
  export const FLAGS = {
10
- ANNUAL_LICENSE: 0x1,
11
- PERPETUAL_LICENSE: 0x2,
12
- INTERNAL_LICENSE: 0x4,
13
- WITH_WATERMARK: 0x8,
9
+ // -- MUTUALLY EXCLUSIVE FLAGS --
10
+ // Annual means the license expires after a time period, usually 1 year.
11
+ ANNUAL_LICENSE: 1,
12
+ // Perpetual means the license never expires up to the max supported version.
13
+ PERPETUAL_LICENSE: 1 << 1,
14
+
15
+ // -- ADDITIVE FLAGS --
16
+ // Internal means the license is for internal use only.
17
+ INTERNAL_LICENSE: 1 << 2,
18
+ // Watermark means the product is watermarked.
19
+ WITH_WATERMARK: 1 << 3,
20
+ // Evaluation means the license is for evaluation purposes only.
21
+ EVALUATION_LICENSE: 1 << 4,
22
+ // Native means the license is for native apps which switches
23
+ // on special-case logic.
24
+ NATIVE_LICENSE: 1 << 5,
14
25
  }
15
26
  const HIGHEST_FLAG = Math.max(...Object.values(FLAGS))
16
27
 
@@ -36,11 +47,12 @@ export interface LicenseInfo {
36
47
 
37
48
  /** @internal */
38
49
  export type LicenseState =
39
- | 'pending'
40
- | 'licensed'
41
- | 'licensed-with-watermark'
42
- | 'unlicensed'
43
- | 'internal-expired'
50
+ | 'pending' // License validation is in progress
51
+ | 'licensed' // License is valid and active (no restrictions)
52
+ | 'licensed-with-watermark' // License is valid but shows watermark (evaluation licenses, WITH_WATERMARK licenses)
53
+ | 'unlicensed' // No valid license found or license is invalid (development)
54
+ | 'unlicensed-production' // No valid license in production deployment (missing, invalid, or wrong domain)
55
+ | 'expired' // License has been expired (30 days past expiration for regular licenses, immediately for evaluation licenses)
44
56
  /** @internal */
45
57
  export type InvalidLicenseReason =
46
58
  | 'invalid-license-key'
@@ -68,12 +80,19 @@ export interface ValidLicenseKeyResult {
68
80
  isPerpetualLicense: boolean
69
81
  isPerpetualLicenseExpired: boolean
70
82
  isInternalLicense: boolean
83
+ isNativeLicense: boolean
71
84
  isLicensedWithWatermark: boolean
85
+ isEvaluationLicense: boolean
86
+ isEvaluationLicenseExpired: boolean
87
+ daysSinceExpiry: number
72
88
  }
73
89
 
74
90
  /** @internal */
75
91
  export type TestEnvironment = 'development' | 'production'
76
92
 
93
+ /** @internal */
94
+ export type TrackType = 'unlicensed' | 'with_watermark' | 'evaluation' | null
95
+
77
96
  /** @internal */
78
97
  export class LicenseManager {
79
98
  private publicKey =
@@ -96,11 +115,13 @@ export class LicenseManager {
96
115
 
97
116
  this.getLicenseFromKey(licenseKey)
98
117
  .then((result) => {
99
- const licenseState = getLicenseState(result)
118
+ const licenseState = getLicenseState(
119
+ result,
120
+ (messages: string[]) => this.outputMessages(messages),
121
+ this.isDevelopment
122
+ )
100
123
 
101
- if (!this.isDevelopment && licenseState === 'unlicensed') {
102
- fetch(WATERMARK_TRACK_SRC)
103
- }
124
+ this.maybeTrack(result, licenseState)
104
125
 
105
126
  this.state.set(licenseState)
106
127
  })
@@ -121,6 +142,47 @@ export class LicenseManager {
121
142
  )
122
143
  }
123
144
 
145
+ private getTrackType(result: LicenseFromKeyResult, licenseState: LicenseState): TrackType {
146
+ // Track watermark for unlicensed production deployments
147
+ if (licenseState === 'unlicensed-production') {
148
+ return 'unlicensed'
149
+ }
150
+
151
+ if (this.isDevelopment) {
152
+ return null
153
+ }
154
+
155
+ if (!result.isLicenseParseable) {
156
+ return null
157
+ }
158
+
159
+ // Track evaluation licenses (for analytics, even though no watermark is shown)
160
+ if (result.isEvaluationLicense) {
161
+ return 'evaluation'
162
+ }
163
+
164
+ // Track licenses that show watermarks
165
+ if (licenseState === 'licensed-with-watermark') {
166
+ return 'with_watermark'
167
+ }
168
+
169
+ return null
170
+ }
171
+
172
+ private maybeTrack(result: LicenseFromKeyResult, licenseState: LicenseState): void {
173
+ const trackType = this.getTrackType(result, licenseState)
174
+ if (!trackType) {
175
+ return
176
+ }
177
+
178
+ const url = new URL(WATERMARK_TRACK_SRC)
179
+ url.searchParams.set('version', version)
180
+ url.searchParams.set('license_type', trackType)
181
+
182
+ // eslint-disable-next-line no-restricted-globals
183
+ fetch(url.toString())
184
+ }
185
+
124
186
  private async extractLicenseKey(licenseKey: string): Promise<LicenseInfo> {
125
187
  const [data, signature] = licenseKey.split('.')
126
188
  const [prefix, encodedData] = data.split('/')
@@ -207,6 +269,9 @@ export class LicenseManager {
207
269
  const isAnnualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.ANNUAL_LICENSE)
208
270
  const isPerpetualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.PERPETUAL_LICENSE)
209
271
 
272
+ const isEvaluationLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.EVALUATION_LICENSE)
273
+ const daysSinceExpiry = this.getDaysSinceExpiry(expiryDate)
274
+
210
275
  const result: ValidLicenseKeyResult = {
211
276
  license: licenseInfo,
212
277
  isLicenseParseable: true,
@@ -218,7 +283,12 @@ export class LicenseManager {
218
283
  isPerpetualLicense,
219
284
  isPerpetualLicenseExpired: isPerpetualLicense && this.isPerpetualLicenseExpired(expiryDate),
220
285
  isInternalLicense: this.isFlagEnabled(licenseInfo.flags, FLAGS.INTERNAL_LICENSE),
286
+ isNativeLicense: this.isNativeLicense(licenseInfo),
221
287
  isLicensedWithWatermark: this.isFlagEnabled(licenseInfo.flags, FLAGS.WITH_WATERMARK),
288
+ isEvaluationLicense,
289
+ isEvaluationLicenseExpired:
290
+ isEvaluationLicense && this.isEvaluationLicenseExpired(expiryDate),
291
+ daysSinceExpiry,
222
292
  }
223
293
  this.outputLicenseInfoIfNeeded(result)
224
294
 
@@ -235,6 +305,7 @@ export class LicenseManager {
235
305
 
236
306
  return licenseInfo.hosts.some((host) => {
237
307
  const normalizedHost = host.toLowerCase().trim()
308
+ const maybeProtocol = normalizedHost.endsWith(':') ? normalizedHost : undefined
238
309
 
239
310
  // Allow the domain if listed and www variations, 'example.com' allows 'example.com' and 'www.example.com'
240
311
  if (
@@ -266,10 +337,20 @@ export class LicenseManager {
266
337
  }
267
338
  }
268
339
 
340
+ // Native license support
341
+ // In this case, `normalizedHost` is actually a protocol, e.g. `app-bundle:`
342
+ if (this.isNativeLicense(licenseInfo) && window.location.protocol === maybeProtocol) {
343
+ return true
344
+ }
345
+
269
346
  return false
270
347
  })
271
348
  }
272
349
 
350
+ private isNativeLicense(licenseInfo: LicenseInfo) {
351
+ return this.isFlagEnabled(licenseInfo.flags, FLAGS.NATIVE_LICENSE)
352
+ }
353
+
273
354
  private getExpirationDateWithoutGracePeriod(expiryDate: Date) {
274
355
  return new Date(expiryDate.getFullYear(), expiryDate.getMonth(), expiryDate.getDate())
275
356
  }
@@ -284,15 +365,7 @@ export class LicenseManager {
284
365
 
285
366
  private isAnnualLicenseExpired(expiryDate: Date) {
286
367
  const expiration = this.getExpirationDateWithGracePeriod(expiryDate)
287
- const isExpired = new Date() >= expiration
288
- // If it is not expired yet (including the grace period), but after the expiry date we warn the users
289
- if (!isExpired && new Date() >= this.getExpirationDateWithoutGracePeriod(expiryDate)) {
290
- this.outputMessages([
291
- 'tldraw license is about to expire, you are in a grace period.',
292
- `Please reach out to ${LICENSE_EMAIL} if you would like to renew your license.`,
293
- ])
294
- }
295
- return isExpired
368
+ return new Date() >= expiration
296
369
  }
297
370
 
298
371
  private isPerpetualLicenseExpired(expiryDate: Date) {
@@ -305,6 +378,21 @@ export class LicenseManager {
305
378
  return dates.major >= expiration || dates.minor >= expiration
306
379
  }
307
380
 
381
+ private getDaysSinceExpiry(expiryDate: Date): number {
382
+ const now = new Date()
383
+ const expiration = this.getExpirationDateWithoutGracePeriod(expiryDate)
384
+ const diffTime = now.getTime() - expiration.getTime()
385
+ const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24))
386
+ return Math.max(0, diffDays)
387
+ }
388
+
389
+ private isEvaluationLicenseExpired(expiryDate: Date): boolean {
390
+ // Evaluation licenses have no grace period - they expire immediately
391
+ const now = new Date()
392
+ const expiration = this.getExpirationDateWithoutGracePeriod(expiryDate)
393
+ return now >= expiration
394
+ }
395
+
308
396
  private isFlagEnabled(flags: number, flag: number) {
309
397
  return (flags & flag) === flag
310
398
  }
@@ -322,19 +410,6 @@ export class LicenseManager {
322
410
  }
323
411
 
324
412
  private outputLicenseInfoIfNeeded(result: ValidLicenseKeyResult) {
325
- if (result.isAnnualLicenseExpired) {
326
- this.outputMessages([
327
- 'Your tldraw license has expired!',
328
- `Please reach out to ${LICENSE_EMAIL} to renew.`,
329
- ])
330
- }
331
-
332
- if (!result.isDomainValid && !result.isDevelopment) {
333
- this.outputMessages([
334
- 'This tldraw license key is not valid for this domain!',
335
- `Please reach out to ${LICENSE_EMAIL} if you would like to use tldraw on other domains.`,
336
- ])
337
- }
338
413
  // If we added a new flag it will be twice the value of the currently highest flag.
339
414
  // 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.
340
415
  if (result.license.flags >= HIGHEST_FLAG * 2) {
@@ -371,13 +446,74 @@ export class LicenseManager {
371
446
  static className = 'tl-watermark_SEE-LICENSE'
372
447
  }
373
448
 
374
- export function getLicenseState(result: LicenseFromKeyResult): LicenseState {
375
- if (!result.isLicenseParseable) return 'unlicensed'
376
- if (!result.isDomainValid && !result.isDevelopment) return 'unlicensed'
449
+ export function getLicenseState(
450
+ result: LicenseFromKeyResult,
451
+ outputMessages: (messages: string[]) => void,
452
+ isDevelopment: boolean
453
+ ): LicenseState {
454
+ if (!result.isLicenseParseable) {
455
+ if (isDevelopment) {
456
+ return 'unlicensed'
457
+ }
458
+
459
+ // All unlicensed scenarios should not work in production
460
+ if (result.reason === 'no-key-provided') {
461
+ outputMessages([
462
+ 'No tldraw license key provided!',
463
+ 'A license is required for production deployments.',
464
+ `Please reach out to ${LICENSE_EMAIL} to purchase a license.`,
465
+ ])
466
+ } else {
467
+ outputMessages([
468
+ 'Invalid license key. tldraw requires a valid license for production use.',
469
+ `Please reach out to ${LICENSE_EMAIL} to purchase a license.`,
470
+ ])
471
+ }
472
+ return 'unlicensed-production'
473
+ }
474
+
475
+ if (!result.isDomainValid && !result.isDevelopment) {
476
+ outputMessages([
477
+ 'License key is not valid for this domain.',
478
+ 'A license is required for production deployments.',
479
+ `Please reach out to ${LICENSE_EMAIL} to purchase a license.`,
480
+ ])
481
+ return 'unlicensed-production'
482
+ }
483
+
484
+ // Handle evaluation licenses - they expire immediately with no grace period
485
+ if (result.isEvaluationLicense) {
486
+ if (result.isEvaluationLicenseExpired) {
487
+ outputMessages([
488
+ 'Your tldraw evaluation license has expired!',
489
+ `Please reach out to ${LICENSE_EMAIL} to purchase a full license.`,
490
+ ])
491
+ return 'expired'
492
+ } else {
493
+ // Valid evaluation license - tracked but no watermark shown
494
+ return 'licensed'
495
+ }
496
+ }
497
+
498
+ // Handle expired regular licenses (both annual and perpetual)
377
499
  if (result.isPerpetualLicenseExpired || result.isAnnualLicenseExpired) {
378
- // Check if it's an expired internal license with valid domain
379
- const internalExpired = result.isInternalLicense && result.isDomainValid
380
- return internalExpired ? 'internal-expired' : 'unlicensed'
500
+ outputMessages([
501
+ 'Your tldraw license has been expired for more than 30 days!',
502
+ `Please reach out to ${LICENSE_EMAIL} to renew your license.`,
503
+ ])
504
+ return 'expired'
505
+ }
506
+
507
+ // Check if license is past expiry date but within grace period
508
+ const daysSinceExpiry = result.daysSinceExpiry
509
+ if (daysSinceExpiry > 0 && !result.isEvaluationLicense) {
510
+ outputMessages([
511
+ 'Your tldraw license has expired.',
512
+ `License expired ${daysSinceExpiry} days ago.`,
513
+ `Please reach out to ${LICENSE_EMAIL} to renew your license.`,
514
+ ])
515
+ // Within 30-day grace period: still licensed (no watermark)
516
+ return 'licensed'
381
517
  }
382
518
 
383
519
  // License is valid, determine if it has watermark
@@ -1,5 +1,5 @@
1
1
  import { useValue } from '@tldraw/state-react'
2
- import { createContext, ReactNode, useContext, useState } from 'react'
2
+ import { createContext, ReactNode, useContext, useEffect, useState } from 'react'
3
3
  import { LicenseManager } from './LicenseManager'
4
4
 
5
5
  /** @internal */
@@ -8,9 +8,16 @@ export const LicenseContext = createContext({} as LicenseManager)
8
8
  /** @internal */
9
9
  export const useLicenseContext = () => useContext(LicenseContext)
10
10
 
11
+ function shouldHideEditorAfterDelay(licenseState: string): boolean {
12
+ return licenseState === 'expired' || licenseState === 'unlicensed-production'
13
+ }
14
+
15
+ /** @internal */
16
+ export const LICENSE_TIMEOUT = 5000
17
+
11
18
  /** @internal */
12
19
  export function LicenseProvider({
13
- licenseKey,
20
+ licenseKey = getLicenseKeyFromEnv() ?? undefined,
14
21
  children,
15
22
  }: {
16
23
  licenseKey?: string
@@ -18,11 +25,68 @@ export function LicenseProvider({
18
25
  }) {
19
26
  const [licenseManager] = useState(() => new LicenseManager(licenseKey))
20
27
  const licenseState = useValue(licenseManager.state)
28
+ const [showEditor, setShowEditor] = useState(true)
21
29
 
22
- // If internal license has expired, don't render the editor at all
23
- if (licenseState === 'internal-expired') {
24
- return <div data-testid="tl-license-expired" style={{ display: 'none' }} />
30
+ // When license expires or no license in production, show for 5 seconds then hide
31
+ useEffect(() => {
32
+ if (shouldHideEditorAfterDelay(licenseState) && showEditor) {
33
+ // eslint-disable-next-line no-restricted-globals
34
+ const timer = setTimeout(() => {
35
+ setShowEditor(false)
36
+ }, LICENSE_TIMEOUT)
37
+
38
+ return () => clearTimeout(timer)
39
+ }
40
+ }, [licenseState, showEditor])
41
+
42
+ // If license is expired or no license in production and 5 seconds have passed, don't render anything (blank screen)
43
+ if (shouldHideEditorAfterDelay(licenseState) && !showEditor) {
44
+ return <LicenseGate />
25
45
  }
26
46
 
27
47
  return <LicenseContext.Provider value={licenseManager}>{children}</LicenseContext.Provider>
28
48
  }
49
+
50
+ // Renders as a hidden div that can be detected by tests
51
+ function LicenseGate() {
52
+ return <div data-testid="tl-license-expired" style={{ display: 'none' }} />
53
+ }
54
+
55
+ let envLicenseKey: string | undefined | null = undefined
56
+ function getLicenseKeyFromEnv() {
57
+ if (envLicenseKey !== undefined) {
58
+ return envLicenseKey
59
+ }
60
+ // it's important here that we write out the full process.env.WHATEVER expression instead of
61
+ // doing something like process.env[someVariable]. This is because most bundlers do something
62
+ // like a find-replace inject environment variables, and so won't pick up on dynamic ones. It
63
+ // also means we can't do checks like `process.env && process.env.WHATEVER`, which is why we use
64
+ // the `getEnv` try/catch approach.
65
+
66
+ // framework-specific prefixes borrowed from the ones vercel uses, but trimmed down to just the
67
+ // react-y ones: https://vercel.com/docs/environment-variables/framework-environment-variables
68
+ envLicenseKey =
69
+ getEnv(() => process.env.TLDRAW_LICENSE_KEY) ||
70
+ getEnv(() => process.env.NEXT_PUBLIC_TLDRAW_LICENSE_KEY) ||
71
+ getEnv(() => process.env.REACT_APP_TLDRAW_LICENSE_KEY) ||
72
+ getEnv(() => process.env.GATSBY_TLDRAW_LICENSE_KEY) ||
73
+ getEnv(() => process.env.VITE_TLDRAW_LICENSE_KEY) ||
74
+ getEnv(() => process.env.PUBLIC_TLDRAW_LICENSE_KEY) ||
75
+ getEnv(() => (import.meta as any).env.TLDRAW_LICENSE_KEY) ||
76
+ getEnv(() => (import.meta as any).env.NEXT_PUBLIC_TLDRAW_LICENSE_KEY) ||
77
+ getEnv(() => (import.meta as any).env.REACT_APP_TLDRAW_LICENSE_KEY) ||
78
+ getEnv(() => (import.meta as any).env.GATSBY_TLDRAW_LICENSE_KEY) ||
79
+ getEnv(() => (import.meta as any).env.VITE_TLDRAW_LICENSE_KEY) ||
80
+ getEnv(() => (import.meta as any).env.PUBLIC_TLDRAW_LICENSE_KEY) ||
81
+ null
82
+
83
+ return envLicenseKey
84
+ }
85
+
86
+ function getEnv(cb: () => string | undefined) {
87
+ try {
88
+ return cb()
89
+ } catch {
90
+ return undefined
91
+ }
92
+ }
@@ -28,12 +28,74 @@ export const Watermark = memo(function Watermark() {
28
28
  return (
29
29
  <>
30
30
  <LicenseStyles />
31
- <WatermarkInner src={isMobile ? WATERMARK_MOBILE_LOCAL_SRC : WATERMARK_DESKTOP_LOCAL_SRC} />
31
+ <WatermarkInner
32
+ src={isMobile ? WATERMARK_MOBILE_LOCAL_SRC : WATERMARK_DESKTOP_LOCAL_SRC}
33
+ isUnlicensed={licenseManagerState === 'unlicensed'}
34
+ />
32
35
  </>
33
36
  )
34
37
  })
35
38
 
36
- const WatermarkInner = memo(function WatermarkInner({ src }: { src: string }) {
39
+ const UnlicensedWatermark = memo(function UnlicensedWatermark({
40
+ isDebugMode,
41
+ isMobile,
42
+ }: {
43
+ isDebugMode: boolean
44
+ isMobile: boolean
45
+ }) {
46
+ const events = useCanvasEvents()
47
+ const ref = useRef<HTMLDivElement>(null)
48
+ usePassThroughWheelEvents(ref)
49
+
50
+ const url = 'https://tldraw.dev/?utm_source=dotcom&utm_medium=organic&utm_campaign=watermark'
51
+
52
+ return (
53
+ <div
54
+ ref={ref}
55
+ className={LicenseManager.className}
56
+ data-debug={isDebugMode}
57
+ data-mobile={isMobile}
58
+ data-unlicensed={true}
59
+ data-testid="tl-watermark-unlicensed"
60
+ draggable={false}
61
+ {...events}
62
+ >
63
+ <button
64
+ draggable={false}
65
+ role="button"
66
+ onPointerDown={(e) => {
67
+ stopEventPropagation(e)
68
+ preventDefault(e)
69
+ }}
70
+ title="Unlicensed - click to get a license"
71
+ onClick={() => runtime.openWindow(url, '_blank')}
72
+ style={{
73
+ position: 'absolute',
74
+ pointerEvents: 'all',
75
+ cursor: 'pointer',
76
+ color: 'var(--tl-color-text)',
77
+ opacity: 0.8,
78
+ border: 0,
79
+ padding: 0,
80
+ backgroundColor: 'transparent',
81
+ fontSize: '11px',
82
+ fontWeight: '600',
83
+ textAlign: 'center',
84
+ }}
85
+ >
86
+ Unlicensed
87
+ </button>
88
+ </div>
89
+ )
90
+ })
91
+
92
+ const WatermarkInner = memo(function WatermarkInner({
93
+ src,
94
+ isUnlicensed,
95
+ }: {
96
+ src: string
97
+ isUnlicensed: boolean
98
+ }) {
37
99
  const editor = useEditor()
38
100
  const isDebugMode = useValue('debug mode', () => editor.getInstanceState().isDebugMode, [editor])
39
101
  const isMobile = useValue('is mobile', () => editor.getViewportScreenBounds().width < 700, [
@@ -47,12 +109,17 @@ const WatermarkInner = memo(function WatermarkInner({ src }: { src: string }) {
47
109
  const maskCss = `url('${src}') center 100% / 100% no-repeat`
48
110
  const url = 'https://tldraw.dev/?utm_source=dotcom&utm_medium=organic&utm_campaign=watermark'
49
111
 
112
+ if (isUnlicensed) {
113
+ return <UnlicensedWatermark isDebugMode={isDebugMode} isMobile={isMobile} />
114
+ }
115
+
50
116
  return (
51
117
  <div
52
118
  ref={ref}
53
119
  className={LicenseManager.className}
54
120
  data-debug={isDebugMode}
55
121
  data-mobile={isMobile}
122
+ data-testid="tl-watermark-licensed"
56
123
  draggable={false}
57
124
  {...events}
58
125
  >
@@ -86,8 +153,8 @@ To remove the watermark, please purchase a license at tldraw.dev.
86
153
 
87
154
  .${className} {
88
155
  position: absolute;
89
- bottom: var(--tl-space-2);
90
- right: var(--tl-space-2);
156
+ bottom: max(var(--tl-space-2), env(safe-area-inset-bottom));
157
+ right: max(var(--tl-space-2), env(safe-area-inset-right));
91
158
  width: 96px;
92
159
  height: 32px;
93
160
  display: flex;
@@ -116,12 +183,12 @@ To remove the watermark, please purchase a license at tldraw.dev.
116
183
  }
117
184
 
118
185
  .${className}[data-debug='true'] {
119
- bottom: 46px;
186
+ bottom: max(46px, env(safe-area-inset-bottom));
120
187
  }
121
188
 
122
189
  .${className}[data-mobile='true'] {
123
190
  border-radius: 4px 0px 0px 4px;
124
- right: -2px;
191
+ right: max(-2px, calc(env(safe-area-inset-right) - 2px));
125
192
  width: 8px;
126
193
  height: 48px;
127
194
  }