@tldraw/editor 3.16.0-canary.c1bcdabc9513 → 3.16.0-canary.c7d3f7d5729d

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 (80) hide show
  1. package/dist-cjs/index.d.ts +47 -0
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +5 -1
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/Shape.js +7 -10
  7. package/dist-cjs/lib/components/Shape.js.map +2 -2
  8. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +4 -23
  9. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  10. package/dist-cjs/lib/editor/Editor.js +28 -10
  11. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  12. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +13 -0
  13. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  14. package/dist-cjs/lib/exports/getSvgJsx.js +34 -14
  15. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  16. package/dist-cjs/lib/hooks/useCanvasEvents.js +7 -5
  17. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  18. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -1
  19. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  20. package/dist-cjs/lib/license/LicenseManager.js +17 -22
  21. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  22. package/dist-cjs/lib/license/LicenseProvider.js +5 -0
  23. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  24. package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
  25. package/dist-cjs/lib/primitives/Box.js +3 -0
  26. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  27. package/dist-cjs/version.js +3 -3
  28. package/dist-cjs/version.js.map +1 -1
  29. package/dist-esm/index.d.mts +47 -0
  30. package/dist-esm/index.mjs +1 -1
  31. package/dist-esm/index.mjs.map +2 -2
  32. package/dist-esm/lib/TldrawEditor.mjs +5 -1
  33. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  34. package/dist-esm/lib/components/Shape.mjs +7 -10
  35. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  36. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +4 -23
  37. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  38. package/dist-esm/lib/editor/Editor.mjs +28 -10
  39. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  40. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +13 -0
  41. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  42. package/dist-esm/lib/exports/getSvgJsx.mjs +34 -14
  43. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  44. package/dist-esm/lib/hooks/useCanvasEvents.mjs +7 -5
  45. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  46. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -1
  47. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  48. package/dist-esm/lib/license/LicenseManager.mjs +17 -22
  49. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  50. package/dist-esm/lib/license/LicenseProvider.mjs +5 -0
  51. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  52. package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
  53. package/dist-esm/lib/primitives/Box.mjs +4 -1
  54. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  55. package/dist-esm/version.mjs +3 -3
  56. package/dist-esm/version.mjs.map +1 -1
  57. package/editor.css +8 -0
  58. package/package.json +7 -7
  59. package/src/index.ts +1 -0
  60. package/src/lib/TldrawEditor.tsx +6 -1
  61. package/src/lib/components/Shape.tsx +6 -12
  62. package/src/lib/components/default-components/DefaultCanvas.tsx +5 -22
  63. package/src/lib/editor/Editor.ts +37 -21
  64. package/src/lib/editor/shapes/ShapeUtil.ts +35 -0
  65. package/src/lib/exports/getSvgJsx.test.ts +868 -0
  66. package/src/lib/exports/getSvgJsx.tsx +76 -19
  67. package/src/lib/hooks/useCanvasEvents.ts +6 -6
  68. package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
  69. package/src/lib/license/LicenseManager.test.ts +58 -51
  70. package/src/lib/license/LicenseManager.ts +32 -24
  71. package/src/lib/license/LicenseProvider.tsx +8 -0
  72. package/src/lib/license/useLicenseManagerState.ts +2 -2
  73. package/src/lib/primitives/Box.test.ts +126 -0
  74. package/src/lib/primitives/Box.ts +10 -1
  75. package/src/version.ts +3 -3
  76. package/dist-cjs/lib/utils/nearestMultiple.js +0 -34
  77. package/dist-cjs/lib/utils/nearestMultiple.js.map +0 -7
  78. package/dist-esm/lib/utils/nearestMultiple.mjs +0 -14
  79. package/dist-esm/lib/utils/nearestMultiple.mjs.map +0 -7
  80. package/src/lib/utils/nearestMultiple.ts +0 -13
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/license/LicenseManager.ts"],
4
- "sourcesContent": ["import { atom } from '@tldraw/state'\nimport { fetch } from '@tldraw/utils'\nimport { publishDates } from '../../version'\nimport { getDefaultCdnBaseUrl } from '../utils/assets'\nimport { importPublicKey, str2ab } from '../utils/licensing'\n\nconst GRACE_PERIOD_DAYS = 5\n\nexport const FLAGS = {\n\tANNUAL_LICENSE: 0x1,\n\tPERPETUAL_LICENSE: 0x2,\n\tINTERNAL_LICENSE: 0x4,\n\tWITH_WATERMARK: 0x8,\n}\nconst HIGHEST_FLAG = Math.max(...Object.values(FLAGS))\n\nexport const PROPERTIES = {\n\tID: 0,\n\tHOSTS: 1,\n\tFLAGS: 2,\n\tEXPIRY_DATE: 3,\n}\nconst NUMBER_OF_KNOWN_PROPERTIES = Object.keys(PROPERTIES).length\n\nconst LICENSE_EMAIL = 'sales@tldraw.com'\n\nconst WATERMARK_TRACK_SRC = `${getDefaultCdnBaseUrl()}/watermarks/watermark-track.svg`\n\n/** @internal */\nexport interface LicenseInfo {\n\tid: string\n\thosts: string[]\n\tflags: number\n\texpiryDate: string\n}\n/** @internal */\nexport type InvalidLicenseReason =\n\t| 'invalid-license-key'\n\t| 'no-key-provided'\n\t| 'has-key-development-mode'\n\n/** @internal */\nexport type LicenseFromKeyResult = InvalidLicenseKeyResult | ValidLicenseKeyResult\n\n/** @internal */\nexport interface InvalidLicenseKeyResult {\n\tisLicenseParseable: false\n\treason: InvalidLicenseReason\n}\n\n/** @internal */\nexport interface ValidLicenseKeyResult {\n\tisLicenseParseable: true\n\tlicense: LicenseInfo\n\tisDevelopment: boolean\n\tisDomainValid: boolean\n\texpiryDate: Date\n\tisAnnualLicense: boolean\n\tisAnnualLicenseExpired: boolean\n\tisPerpetualLicense: boolean\n\tisPerpetualLicenseExpired: boolean\n\tisInternalLicense: boolean\n\tisLicensedWithWatermark: boolean\n}\n\n/** @internal */\nexport type TestEnvironment = 'development' | 'production'\n\n/** @internal */\nexport class LicenseManager {\n\tprivate publicKey =\n\t\t'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ'\n\tpublic isDevelopment: boolean\n\tpublic isTest: boolean\n\tpublic isCryptoAvailable: boolean\n\tstate = atom<'pending' | 'licensed' | 'licensed-with-watermark' | 'unlicensed'>(\n\t\t'license state',\n\t\t'pending'\n\t)\n\tpublic verbose = true\n\n\tconstructor(\n\t\tlicenseKey: string | undefined,\n\t\ttestPublicKey?: string,\n\t\ttestEnvironment?: TestEnvironment\n\t) {\n\t\tthis.isTest = process.env.NODE_ENV === 'test'\n\t\tthis.isDevelopment = this.getIsDevelopment(testEnvironment)\n\t\tthis.publicKey = testPublicKey || this.publicKey\n\t\tthis.isCryptoAvailable = !!crypto.subtle\n\n\t\tthis.getLicenseFromKey(licenseKey).then((result) => {\n\t\t\tconst isUnlicensed = isEditorUnlicensed(result)\n\n\t\t\tif (!this.isDevelopment && isUnlicensed) {\n\t\t\t\tfetch(WATERMARK_TRACK_SRC)\n\t\t\t}\n\n\t\t\tif (isUnlicensed) {\n\t\t\t\tthis.state.set('unlicensed')\n\t\t\t} else if ((result as ValidLicenseKeyResult).isLicensedWithWatermark) {\n\t\t\t\tthis.state.set('licensed-with-watermark')\n\t\t\t} else {\n\t\t\t\tthis.state.set('licensed')\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate getIsDevelopment(testEnvironment?: TestEnvironment) {\n\t\tif (testEnvironment === 'development') return true\n\t\tif (testEnvironment === 'production') return false\n\n\t\t// If we are using https on a non-localhost domain we assume it's a production env and a development one otherwise\n\t\treturn (\n\t\t\t!['https:', 'vscode-webview:'].includes(window.location.protocol) ||\n\t\t\twindow.location.hostname === 'localhost'\n\t\t)\n\t}\n\n\tprivate async extractLicenseKey(licenseKey: string): Promise<LicenseInfo> {\n\t\tconst [data, signature] = licenseKey.split('.')\n\t\tconst [prefix, encodedData] = data.split('/')\n\n\t\tif (!prefix.startsWith('tldraw-')) {\n\t\t\tthrow new Error(`Unsupported prefix '${prefix}'`)\n\t\t}\n\n\t\tconst publicCryptoKey = await importPublicKey(this.publicKey)\n\n\t\tlet isVerified\n\t\ttry {\n\t\t\tisVerified = await crypto.subtle.verify(\n\t\t\t\t{\n\t\t\t\t\tname: 'ECDSA',\n\t\t\t\t\thash: { name: 'SHA-256' },\n\t\t\t\t},\n\t\t\t\tpublicCryptoKey,\n\t\t\t\tnew Uint8Array(str2ab(atob(signature))),\n\t\t\t\tnew Uint8Array(str2ab(atob(encodedData)))\n\t\t\t)\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tthrow new Error('Could not perform signature validation')\n\t\t}\n\n\t\tif (!isVerified) {\n\t\t\tthrow new Error('Invalid signature')\n\t\t}\n\n\t\tlet decodedData: any\n\t\ttry {\n\t\t\tdecodedData = JSON.parse(atob(encodedData))\n\t\t} catch {\n\t\t\tthrow new Error('Could not parse object')\n\t\t}\n\t\tif (decodedData.length > NUMBER_OF_KNOWN_PROPERTIES) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'License key contains some unknown properties.',\n\t\t\t\t'You may want to update tldraw packages to a newer version to get access to new functionality.',\n\t\t\t])\n\t\t}\n\n\t\treturn {\n\t\t\tid: decodedData[PROPERTIES.ID],\n\t\t\thosts: decodedData[PROPERTIES.HOSTS],\n\t\t\tflags: decodedData[PROPERTIES.FLAGS],\n\t\t\texpiryDate: decodedData[PROPERTIES.EXPIRY_DATE],\n\t\t}\n\t}\n\n\tasync getLicenseFromKey(licenseKey?: string): Promise<LicenseFromKeyResult> {\n\t\tif (!licenseKey) {\n\t\t\tif (!this.isDevelopment) {\n\t\t\t\tthis.outputNoLicenseKeyProvided()\n\t\t\t}\n\n\t\t\treturn { isLicenseParseable: false, reason: 'no-key-provided' }\n\t\t}\n\n\t\tif (this.isDevelopment && !this.isCryptoAvailable) {\n\t\t\tif (this.verbose) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(\n\t\t\t\t\t'tldraw: you seem to be in a development environment that does not support crypto. License not verified.'\n\t\t\t\t)\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log('You should check that this works in production separately.')\n\t\t\t}\n\t\t\t// We can't parse the license if we are in development mode since crypto\n\t\t\t// is not available on http\n\t\t\treturn { isLicenseParseable: false, reason: 'has-key-development-mode' }\n\t\t}\n\n\t\t// Borrowed idea from AG Grid:\n\t\t// Copying from various sources (like PDFs) can include zero-width characters.\n\t\t// This helps makes sure the key validation doesn't fail.\n\t\tlet cleanedLicenseKey = licenseKey.replace(/[\\u200B-\\u200D\\uFEFF]/g, '')\n\t\tcleanedLicenseKey = cleanedLicenseKey.replace(/\\r?\\n|\\r/g, '')\n\n\t\ttry {\n\t\t\tconst licenseInfo = await this.extractLicenseKey(cleanedLicenseKey)\n\t\t\tconst expiryDate = new Date(licenseInfo.expiryDate)\n\t\t\tconst isAnnualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.ANNUAL_LICENSE)\n\t\t\tconst isPerpetualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.PERPETUAL_LICENSE)\n\n\t\t\tconst result: ValidLicenseKeyResult = {\n\t\t\t\tlicense: licenseInfo,\n\t\t\t\tisLicenseParseable: true,\n\t\t\t\tisDevelopment: this.isDevelopment,\n\t\t\t\tisDomainValid: this.isDomainValid(licenseInfo),\n\t\t\t\texpiryDate,\n\t\t\t\tisAnnualLicense,\n\t\t\t\tisAnnualLicenseExpired: isAnnualLicense && this.isAnnualLicenseExpired(expiryDate),\n\t\t\t\tisPerpetualLicense,\n\t\t\t\tisPerpetualLicenseExpired: isPerpetualLicense && this.isPerpetualLicenseExpired(expiryDate),\n\t\t\t\tisInternalLicense: this.isFlagEnabled(licenseInfo.flags, FLAGS.INTERNAL_LICENSE),\n\t\t\t\tisLicensedWithWatermark: this.isFlagEnabled(licenseInfo.flags, FLAGS.WITH_WATERMARK),\n\t\t\t}\n\t\t\tthis.outputLicenseInfoIfNeeded(result)\n\n\t\t\treturn result\n\t\t} catch (e: any) {\n\t\t\tthis.outputInvalidLicenseKey(e.message)\n\t\t\t// If the license can't be parsed, it's invalid\n\t\t\treturn { isLicenseParseable: false, reason: 'invalid-license-key' }\n\t\t}\n\t}\n\n\tprivate isDomainValid(licenseInfo: LicenseInfo) {\n\t\tconst currentHostname = window.location.hostname.toLowerCase()\n\n\t\treturn licenseInfo.hosts.some((host) => {\n\t\t\tconst normalizedHost = host.toLowerCase().trim()\n\n\t\t\t// Allow the domain if listed and www variations, 'example.com' allows 'example.com' and 'www.example.com'\n\t\t\tif (\n\t\t\t\tnormalizedHost === currentHostname ||\n\t\t\t\t`www.${normalizedHost}` === currentHostname ||\n\t\t\t\tnormalizedHost === `www.${currentHostname}`\n\t\t\t) {\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// If host is '*', we allow all domains.\n\t\t\tif (host === '*') {\n\t\t\t\t// All domains allowed.\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// Glob testing, we only support '*.somedomain.com' right now.\n\t\t\tif (host.includes('*')) {\n\t\t\t\tconst globToRegex = new RegExp(host.replace(/\\*/g, '.*?'))\n\t\t\t\treturn globToRegex.test(currentHostname) || globToRegex.test(`www.${currentHostname}`)\n\t\t\t}\n\n\t\t\t// VSCode support\n\t\t\tif (window.location.protocol === 'vscode-webview:') {\n\t\t\t\tconst currentUrl = new URL(window.location.href)\n\t\t\t\tconst extensionId = currentUrl.searchParams.get('extensionId')\n\t\t\t\tif (normalizedHost === extensionId) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn false\n\t\t})\n\t}\n\n\tprivate getExpirationDateWithoutGracePeriod(expiryDate: Date) {\n\t\treturn new Date(expiryDate.getFullYear(), expiryDate.getMonth(), expiryDate.getDate())\n\t}\n\n\tprivate getExpirationDateWithGracePeriod(expiryDate: Date) {\n\t\treturn new Date(\n\t\t\texpiryDate.getFullYear(),\n\t\t\texpiryDate.getMonth(),\n\t\t\texpiryDate.getDate() + GRACE_PERIOD_DAYS + 1 // Add 1 day to include the expiration day\n\t\t)\n\t}\n\n\tprivate isAnnualLicenseExpired(expiryDate: Date) {\n\t\tconst expiration = this.getExpirationDateWithGracePeriod(expiryDate)\n\t\tconst isExpired = new Date() >= expiration\n\t\t// If it is not expired yet (including the grace period), but after the expiry date we warn the users\n\t\tif (!isExpired && new Date() >= this.getExpirationDateWithoutGracePeriod(expiryDate)) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'tldraw license is about to expire, you are in a grace period.',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} if you would like to renew your license.`,\n\t\t\t])\n\t\t}\n\t\treturn isExpired\n\t}\n\n\tprivate isPerpetualLicenseExpired(expiryDate: Date) {\n\t\tconst expiration = this.getExpirationDateWithGracePeriod(expiryDate)\n\t\tconst dates = {\n\t\t\tmajor: new Date(publishDates.major),\n\t\t\tminor: new Date(publishDates.minor),\n\t\t}\n\t\t// We allow patch releases, but the major and minor releases should be within the expiration date\n\t\treturn dates.major >= expiration || dates.minor >= expiration\n\t}\n\n\tprivate isFlagEnabled(flags: number, flag: number) {\n\t\treturn (flags & flag) === flag\n\t}\n\n\tprivate outputNoLicenseKeyProvided() {\n\t\t// Noop, we don't need to show this message.\n\t\t// this.outputMessages([\n\t\t// \t'No tldraw license key provided!',\n\t\t// \t`Please reach out to ${LICENSE_EMAIL} if you would like to license tldraw or if you'd like a trial.`,\n\t\t// ])\n\t}\n\n\tprivate outputInvalidLicenseKey(msg: string) {\n\t\tthis.outputMessages(['Invalid tldraw license key', `Reason: ${msg}`])\n\t}\n\n\tprivate outputLicenseInfoIfNeeded(result: ValidLicenseKeyResult) {\n\t\tif (result.isAnnualLicenseExpired) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'Your tldraw license has expired!',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} to renew.`,\n\t\t\t])\n\t\t}\n\n\t\tif (!result.isDomainValid && !result.isDevelopment) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'This tldraw license key is not valid for this domain!',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} if you would like to use tldraw on other domains.`,\n\t\t\t])\n\t\t}\n\t\t// If we added a new flag it will be twice the value of the currently highest flag.\n\t\t// 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.\n\t\tif (result.license.flags >= HIGHEST_FLAG * 2) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'This tldraw license contains some unknown flags.',\n\t\t\t\t'You may want to update tldraw packages to a newer version to get access to new functionality.',\n\t\t\t])\n\t\t}\n\t}\n\n\tprivate outputMessages(messages: string[]) {\n\t\tif (this.isTest) return\n\t\tif (this.verbose) {\n\t\t\tthis.outputDelimiter()\n\t\t\tfor (const message of messages) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(\n\t\t\t\t\t`%c${message}`,\n\t\t\t\t\t`color: white; background: crimson; padding: 2px; border-radius: 3px;`\n\t\t\t\t)\n\t\t\t}\n\t\t\tthis.outputDelimiter()\n\t\t}\n\t}\n\n\tprivate outputDelimiter() {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.log(\n\t\t\t'%c-------------------------------------------------------------------',\n\t\t\t`color: white; background: crimson; padding: 2px; border-radius: 3px;`\n\t\t)\n\t}\n\n\tstatic className = 'tl-watermark_SEE-LICENSE'\n}\n\nexport function isEditorUnlicensed(result: LicenseFromKeyResult) {\n\tif (!result.isLicenseParseable) return true\n\tif (!result.isDomainValid && !result.isDevelopment) return true\n\tif (result.isPerpetualLicenseExpired || result.isAnnualLicenseExpired) {\n\t\tif (result.isInternalLicense) {\n\t\t\tthrow new Error('License: Internal license expired.')\n\t\t}\n\t\treturn true\n\t}\n\n\treturn false\n}\n"],
5
- "mappings": "AAAA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,SAAS,oBAAoB;AAC7B,SAAS,4BAA4B;AACrC,SAAS,iBAAiB,cAAc;AAExC,MAAM,oBAAoB;AAEnB,MAAM,QAAQ;AAAA,EACpB,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,gBAAgB;AACjB;AACA,MAAM,eAAe,KAAK,IAAI,GAAG,OAAO,OAAO,KAAK,CAAC;AAE9C,MAAM,aAAa;AAAA,EACzB,IAAI;AAAA,EACJ,OAAO;AAAA,EACP,OAAO;AAAA,EACP,aAAa;AACd;AACA,MAAM,6BAA6B,OAAO,KAAK,UAAU,EAAE;AAE3D,MAAM,gBAAgB;AAEtB,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AA2C9C,MAAM,eAAe;AAAA,EACnB,YACP;AAAA,EACM;AAAA,EACA;AAAA,EACA;AAAA,EACP,QAAQ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I,OAAO,wBAAwB;AAClC,WAAK,eAAe;AAAA,QACnB;AAAA,QACA,uBAAuB,aAAa;AAAA,MACrC,CAAC;AAAA,IACF;AAEA,QAAI,CAAC,OAAO,iBAAiB,CAAC,OAAO,eAAe;AACnD,WAAK,eAAe;AAAA,QACnB;AAAA,QACA,uBAAuB,aAAa;AAAA,MACrC,CAAC;AAAA,IACF;AAGA,QAAI,OAAO,QAAQ,SAAS,eAAe,GAAG;AAC7C,WAAK,eAAe;AAAA,QACnB;AAAA,QACA;AAAA,MACD,CAAC;AAAA,IACF;AAAA,EACD;AAAA,EAEQ,eAAe,UAAoB;AAC1C,QAAI,KAAK,OAAQ;AACjB,QAAI,KAAK,SAAS;AACjB,WAAK,gBAAgB;AACrB,iBAAW,WAAW,UAAU;AAE/B,gBAAQ;AAAA,UACP,KAAK,OAAO;AAAA,UACZ;AAAA,QACD;AAAA,MACD;AACA,WAAK,gBAAgB;AAAA,IACtB;AAAA,EACD;AAAA,EAEQ,kBAAkB;AAEzB,YAAQ;AAAA,MACP;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EAEA,OAAO,YAAY;AACpB;AAEO,SAAS,mBAAmB,QAA8B;AAChE,MAAI,CAAC,OAAO,mBAAoB,QAAO;AACvC,MAAI,CAAC,OAAO,iBAAiB,CAAC,OAAO,cAAe,QAAO;AAC3D,MAAI,OAAO,6BAA6B,OAAO,wBAAwB;AACtE,QAAI,OAAO,mBAAmB;AAC7B,YAAM,IAAI,MAAM,oCAAoC;AAAA,IACrD;AACA,WAAO;AAAA,EACR;AAEA,SAAO;AACR;",
4
+ "sourcesContent": ["import { atom } from '@tldraw/state'\nimport { fetch } from '@tldraw/utils'\nimport { publishDates } from '../../version'\nimport { getDefaultCdnBaseUrl } from '../utils/assets'\nimport { importPublicKey, str2ab } from '../utils/licensing'\n\nconst GRACE_PERIOD_DAYS = 5\n\nexport const FLAGS = {\n\tANNUAL_LICENSE: 0x1,\n\tPERPETUAL_LICENSE: 0x2,\n\tINTERNAL_LICENSE: 0x4,\n\tWITH_WATERMARK: 0x8,\n}\nconst HIGHEST_FLAG = Math.max(...Object.values(FLAGS))\n\nexport const PROPERTIES = {\n\tID: 0,\n\tHOSTS: 1,\n\tFLAGS: 2,\n\tEXPIRY_DATE: 3,\n}\nconst NUMBER_OF_KNOWN_PROPERTIES = Object.keys(PROPERTIES).length\n\nconst LICENSE_EMAIL = 'sales@tldraw.com'\n\nconst WATERMARK_TRACK_SRC = `${getDefaultCdnBaseUrl()}/watermarks/watermark-track.svg`\n\n/** @internal */\nexport interface LicenseInfo {\n\tid: string\n\thosts: string[]\n\tflags: number\n\texpiryDate: string\n}\n\n/** @internal */\nexport type LicenseState =\n\t| 'pending'\n\t| 'licensed'\n\t| 'licensed-with-watermark'\n\t| 'unlicensed'\n\t| 'internal-expired'\n/** @internal */\nexport type InvalidLicenseReason =\n\t| 'invalid-license-key'\n\t| 'no-key-provided'\n\t| 'has-key-development-mode'\n\n/** @internal */\nexport type LicenseFromKeyResult = InvalidLicenseKeyResult | ValidLicenseKeyResult\n\n/** @internal */\nexport interface InvalidLicenseKeyResult {\n\tisLicenseParseable: false\n\treason: InvalidLicenseReason\n}\n\n/** @internal */\nexport interface ValidLicenseKeyResult {\n\tisLicenseParseable: true\n\tlicense: LicenseInfo\n\tisDevelopment: boolean\n\tisDomainValid: boolean\n\texpiryDate: Date\n\tisAnnualLicense: boolean\n\tisAnnualLicenseExpired: boolean\n\tisPerpetualLicense: boolean\n\tisPerpetualLicenseExpired: boolean\n\tisInternalLicense: boolean\n\tisLicensedWithWatermark: boolean\n}\n\n/** @internal */\nexport type TestEnvironment = 'development' | 'production'\n\n/** @internal */\nexport class LicenseManager {\n\tprivate publicKey =\n\t\t'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ'\n\tpublic isDevelopment: boolean\n\tpublic isTest: boolean\n\tpublic isCryptoAvailable: boolean\n\tstate = atom<LicenseState>('license state', 'pending')\n\tpublic verbose = true\n\n\tconstructor(\n\t\tlicenseKey: string | undefined,\n\t\ttestPublicKey?: string,\n\t\ttestEnvironment?: TestEnvironment\n\t) {\n\t\tthis.isTest = process.env.NODE_ENV === 'test'\n\t\tthis.isDevelopment = this.getIsDevelopment(testEnvironment)\n\t\tthis.publicKey = testPublicKey || this.publicKey\n\t\tthis.isCryptoAvailable = !!crypto.subtle\n\n\t\tthis.getLicenseFromKey(licenseKey)\n\t\t\t.then((result) => {\n\t\t\t\tconst licenseState = getLicenseState(result)\n\n\t\t\t\tif (!this.isDevelopment && licenseState === 'unlicensed') {\n\t\t\t\t\tfetch(WATERMARK_TRACK_SRC)\n\t\t\t\t}\n\n\t\t\t\tthis.state.set(licenseState)\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.error('License validation failed:', error)\n\t\t\t\tthis.state.set('unlicensed')\n\t\t\t})\n\t}\n\n\tprivate getIsDevelopment(testEnvironment?: TestEnvironment) {\n\t\tif (testEnvironment === 'development') return true\n\t\tif (testEnvironment === 'production') return false\n\n\t\t// If we are using https on a non-localhost domain we assume it's a production env and a development one otherwise\n\t\treturn (\n\t\t\t!['https:', 'vscode-webview:'].includes(window.location.protocol) ||\n\t\t\twindow.location.hostname === 'localhost'\n\t\t)\n\t}\n\n\tprivate async extractLicenseKey(licenseKey: string): Promise<LicenseInfo> {\n\t\tconst [data, signature] = licenseKey.split('.')\n\t\tconst [prefix, encodedData] = data.split('/')\n\n\t\tif (!prefix.startsWith('tldraw-')) {\n\t\t\tthrow new Error(`Unsupported prefix '${prefix}'`)\n\t\t}\n\n\t\tconst publicCryptoKey = await importPublicKey(this.publicKey)\n\n\t\tlet isVerified\n\t\ttry {\n\t\t\tisVerified = await crypto.subtle.verify(\n\t\t\t\t{\n\t\t\t\t\tname: 'ECDSA',\n\t\t\t\t\thash: { name: 'SHA-256' },\n\t\t\t\t},\n\t\t\t\tpublicCryptoKey,\n\t\t\t\tnew Uint8Array(str2ab(atob(signature))),\n\t\t\t\tnew Uint8Array(str2ab(atob(encodedData)))\n\t\t\t)\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tthrow new Error('Could not perform signature validation')\n\t\t}\n\n\t\tif (!isVerified) {\n\t\t\tthrow new Error('Invalid signature')\n\t\t}\n\n\t\tlet decodedData: any\n\t\ttry {\n\t\t\tdecodedData = JSON.parse(atob(encodedData))\n\t\t} catch {\n\t\t\tthrow new Error('Could not parse object')\n\t\t}\n\t\tif (decodedData.length > NUMBER_OF_KNOWN_PROPERTIES) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'License key contains some unknown properties.',\n\t\t\t\t'You may want to update tldraw packages to a newer version to get access to new functionality.',\n\t\t\t])\n\t\t}\n\n\t\treturn {\n\t\t\tid: decodedData[PROPERTIES.ID],\n\t\t\thosts: decodedData[PROPERTIES.HOSTS],\n\t\t\tflags: decodedData[PROPERTIES.FLAGS],\n\t\t\texpiryDate: decodedData[PROPERTIES.EXPIRY_DATE],\n\t\t}\n\t}\n\n\tasync getLicenseFromKey(licenseKey?: string): Promise<LicenseFromKeyResult> {\n\t\tif (!licenseKey) {\n\t\t\tif (!this.isDevelopment) {\n\t\t\t\tthis.outputNoLicenseKeyProvided()\n\t\t\t}\n\n\t\t\treturn { isLicenseParseable: false, reason: 'no-key-provided' }\n\t\t}\n\n\t\tif (this.isDevelopment && !this.isCryptoAvailable) {\n\t\t\tif (this.verbose) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(\n\t\t\t\t\t'tldraw: you seem to be in a development environment that does not support crypto. License not verified.'\n\t\t\t\t)\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log('You should check that this works in production separately.')\n\t\t\t}\n\t\t\t// We can't parse the license if we are in development mode since crypto\n\t\t\t// is not available on http\n\t\t\treturn { isLicenseParseable: false, reason: 'has-key-development-mode' }\n\t\t}\n\n\t\t// Borrowed idea from AG Grid:\n\t\t// Copying from various sources (like PDFs) can include zero-width characters.\n\t\t// This helps makes sure the key validation doesn't fail.\n\t\tlet cleanedLicenseKey = licenseKey.replace(/[\\u200B-\\u200D\\uFEFF]/g, '')\n\t\tcleanedLicenseKey = cleanedLicenseKey.replace(/\\r?\\n|\\r/g, '')\n\n\t\ttry {\n\t\t\tconst licenseInfo = await this.extractLicenseKey(cleanedLicenseKey)\n\t\t\tconst expiryDate = new Date(licenseInfo.expiryDate)\n\t\t\tconst isAnnualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.ANNUAL_LICENSE)\n\t\t\tconst isPerpetualLicense = this.isFlagEnabled(licenseInfo.flags, FLAGS.PERPETUAL_LICENSE)\n\n\t\t\tconst result: ValidLicenseKeyResult = {\n\t\t\t\tlicense: licenseInfo,\n\t\t\t\tisLicenseParseable: true,\n\t\t\t\tisDevelopment: this.isDevelopment,\n\t\t\t\tisDomainValid: this.isDomainValid(licenseInfo),\n\t\t\t\texpiryDate,\n\t\t\t\tisAnnualLicense,\n\t\t\t\tisAnnualLicenseExpired: isAnnualLicense && this.isAnnualLicenseExpired(expiryDate),\n\t\t\t\tisPerpetualLicense,\n\t\t\t\tisPerpetualLicenseExpired: isPerpetualLicense && this.isPerpetualLicenseExpired(expiryDate),\n\t\t\t\tisInternalLicense: this.isFlagEnabled(licenseInfo.flags, FLAGS.INTERNAL_LICENSE),\n\t\t\t\tisLicensedWithWatermark: this.isFlagEnabled(licenseInfo.flags, FLAGS.WITH_WATERMARK),\n\t\t\t}\n\t\t\tthis.outputLicenseInfoIfNeeded(result)\n\n\t\t\treturn result\n\t\t} catch (e: any) {\n\t\t\tthis.outputInvalidLicenseKey(e.message)\n\t\t\t// If the license can't be parsed, it's invalid\n\t\t\treturn { isLicenseParseable: false, reason: 'invalid-license-key' }\n\t\t}\n\t}\n\n\tprivate isDomainValid(licenseInfo: LicenseInfo) {\n\t\tconst currentHostname = window.location.hostname.toLowerCase()\n\n\t\treturn licenseInfo.hosts.some((host) => {\n\t\t\tconst normalizedHost = host.toLowerCase().trim()\n\n\t\t\t// Allow the domain if listed and www variations, 'example.com' allows 'example.com' and 'www.example.com'\n\t\t\tif (\n\t\t\t\tnormalizedHost === currentHostname ||\n\t\t\t\t`www.${normalizedHost}` === currentHostname ||\n\t\t\t\tnormalizedHost === `www.${currentHostname}`\n\t\t\t) {\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// If host is '*', we allow all domains.\n\t\t\tif (host === '*') {\n\t\t\t\t// All domains allowed.\n\t\t\t\treturn true\n\t\t\t}\n\n\t\t\t// Glob testing, we only support '*.somedomain.com' right now.\n\t\t\tif (host.includes('*')) {\n\t\t\t\tconst globToRegex = new RegExp(host.replace(/\\*/g, '.*?'))\n\t\t\t\treturn globToRegex.test(currentHostname) || globToRegex.test(`www.${currentHostname}`)\n\t\t\t}\n\n\t\t\t// VSCode support\n\t\t\tif (window.location.protocol === 'vscode-webview:') {\n\t\t\t\tconst currentUrl = new URL(window.location.href)\n\t\t\t\tconst extensionId = currentUrl.searchParams.get('extensionId')\n\t\t\t\tif (normalizedHost === extensionId) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn false\n\t\t})\n\t}\n\n\tprivate getExpirationDateWithoutGracePeriod(expiryDate: Date) {\n\t\treturn new Date(expiryDate.getFullYear(), expiryDate.getMonth(), expiryDate.getDate())\n\t}\n\n\tprivate getExpirationDateWithGracePeriod(expiryDate: Date) {\n\t\treturn new Date(\n\t\t\texpiryDate.getFullYear(),\n\t\t\texpiryDate.getMonth(),\n\t\t\texpiryDate.getDate() + GRACE_PERIOD_DAYS + 1 // Add 1 day to include the expiration day\n\t\t)\n\t}\n\n\tprivate isAnnualLicenseExpired(expiryDate: Date) {\n\t\tconst expiration = this.getExpirationDateWithGracePeriod(expiryDate)\n\t\tconst isExpired = new Date() >= expiration\n\t\t// If it is not expired yet (including the grace period), but after the expiry date we warn the users\n\t\tif (!isExpired && new Date() >= this.getExpirationDateWithoutGracePeriod(expiryDate)) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'tldraw license is about to expire, you are in a grace period.',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} if you would like to renew your license.`,\n\t\t\t])\n\t\t}\n\t\treturn isExpired\n\t}\n\n\tprivate isPerpetualLicenseExpired(expiryDate: Date) {\n\t\tconst expiration = this.getExpirationDateWithGracePeriod(expiryDate)\n\t\tconst dates = {\n\t\t\tmajor: new Date(publishDates.major),\n\t\t\tminor: new Date(publishDates.minor),\n\t\t}\n\t\t// We allow patch releases, but the major and minor releases should be within the expiration date\n\t\treturn dates.major >= expiration || dates.minor >= expiration\n\t}\n\n\tprivate isFlagEnabled(flags: number, flag: number) {\n\t\treturn (flags & flag) === flag\n\t}\n\n\tprivate outputNoLicenseKeyProvided() {\n\t\t// Noop, we don't need to show this message.\n\t\t// this.outputMessages([\n\t\t// \t'No tldraw license key provided!',\n\t\t// \t`Please reach out to ${LICENSE_EMAIL} if you would like to license tldraw or if you'd like a trial.`,\n\t\t// ])\n\t}\n\n\tprivate outputInvalidLicenseKey(msg: string) {\n\t\tthis.outputMessages(['Invalid tldraw license key', `Reason: ${msg}`])\n\t}\n\n\tprivate outputLicenseInfoIfNeeded(result: ValidLicenseKeyResult) {\n\t\tif (result.isAnnualLicenseExpired) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'Your tldraw license has expired!',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} to renew.`,\n\t\t\t])\n\t\t}\n\n\t\tif (!result.isDomainValid && !result.isDevelopment) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'This tldraw license key is not valid for this domain!',\n\t\t\t\t`Please reach out to ${LICENSE_EMAIL} if you would like to use tldraw on other domains.`,\n\t\t\t])\n\t\t}\n\t\t// If we added a new flag it will be twice the value of the currently highest flag.\n\t\t// 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.\n\t\tif (result.license.flags >= HIGHEST_FLAG * 2) {\n\t\t\tthis.outputMessages([\n\t\t\t\t'This tldraw license contains some unknown flags.',\n\t\t\t\t'You may want to update tldraw packages to a newer version to get access to new functionality.',\n\t\t\t])\n\t\t}\n\t}\n\n\tprivate outputMessages(messages: string[]) {\n\t\tif (this.isTest) return\n\t\tif (this.verbose) {\n\t\t\tthis.outputDelimiter()\n\t\t\tfor (const message of messages) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(\n\t\t\t\t\t`%c${message}`,\n\t\t\t\t\t`color: white; background: crimson; padding: 2px; border-radius: 3px;`\n\t\t\t\t)\n\t\t\t}\n\t\t\tthis.outputDelimiter()\n\t\t}\n\t}\n\n\tprivate outputDelimiter() {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.log(\n\t\t\t'%c-------------------------------------------------------------------',\n\t\t\t`color: white; background: crimson; padding: 2px; border-radius: 3px;`\n\t\t)\n\t}\n\n\tstatic className = 'tl-watermark_SEE-LICENSE'\n}\n\nexport function getLicenseState(result: LicenseFromKeyResult): LicenseState {\n\tif (!result.isLicenseParseable) return 'unlicensed'\n\tif (!result.isDomainValid && !result.isDevelopment) return 'unlicensed'\n\tif (result.isPerpetualLicenseExpired || result.isAnnualLicenseExpired) {\n\t\t// Check if it's an expired internal license with valid domain\n\t\tconst internalExpired = result.isInternalLicense && result.isDomainValid\n\t\treturn internalExpired ? 'internal-expired' : 'unlicensed'\n\t}\n\n\t// License is valid, determine if it has watermark\n\tif (result.isLicensedWithWatermark) {\n\t\treturn 'licensed-with-watermark'\n\t}\n\n\treturn 'licensed'\n}\n"],
5
+ "mappings": "AAAA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,SAAS,oBAAoB;AAC7B,SAAS,4BAA4B;AACrC,SAAS,iBAAiB,cAAc;AAExC,MAAM,oBAAoB;AAEnB,MAAM,QAAQ;AAAA,EACpB,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,kBAAkB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AAO,qBAAqB,OAAO;AAC3D,WAAO,kBAAkB,qBAAqB;AAAA,EAC/C;AAGA,MAAI,OAAO,yBAAyB;AACnC,WAAO;AAAA,EACR;AAEA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
+ import { useValue } from "@tldraw/state-react";
2
3
  import { createContext, useContext, useState } from "react";
3
4
  import { LicenseManager } from "./LicenseManager.mjs";
4
5
  const LicenseContext = createContext({});
@@ -8,6 +9,10 @@ function LicenseProvider({
8
9
  children
9
10
  }) {
10
11
  const [licenseManager] = useState(() => new LicenseManager(licenseKey));
12
+ const licenseState = useValue(licenseManager.state);
13
+ if (licenseState === "internal-expired") {
14
+ return /* @__PURE__ */ jsx("div", { "data-testid": "tl-license-expired", style: { display: "none" } });
15
+ }
11
16
  return /* @__PURE__ */ jsx(LicenseContext.Provider, { value: licenseManager, children });
12
17
  }
13
18
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/license/LicenseProvider.tsx"],
4
- "sourcesContent": ["import { createContext, ReactNode, useContext, useState } from 'react'\nimport { LicenseManager } from './LicenseManager'\n\n/** @internal */\nexport const LicenseContext = createContext({} as LicenseManager)\n\n/** @internal */\nexport const useLicenseContext = () => useContext(LicenseContext)\n\n/** @internal */\nexport function LicenseProvider({\n\tlicenseKey,\n\tchildren,\n}: {\n\tlicenseKey?: string\n\tchildren: ReactNode\n}) {\n\tconst [licenseManager] = useState(() => new LicenseManager(licenseKey))\n\treturn <LicenseContext.Provider value={licenseManager}>{children}</LicenseContext.Provider>\n}\n"],
5
- "mappings": "AAkBQ;AAlBR,SAAS,eAA0B,YAAY,gBAAgB;AAC/D,SAAS,sBAAsB;AAGxB,MAAM,iBAAiB,cAAc,CAAC,CAAmB;AAGzD,MAAM,oBAAoB,MAAM,WAAW,cAAc;AAGzD,SAAS,gBAAgB;AAAA,EAC/B;AAAA,EACA;AACD,GAGG;AACF,QAAM,CAAC,cAAc,IAAI,SAAS,MAAM,IAAI,eAAe,UAAU,CAAC;AACtE,SAAO,oBAAC,eAAe,UAAf,EAAwB,OAAO,gBAAiB,UAAS;AAClE;",
4
+ "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { createContext, ReactNode, useContext, useState } from 'react'\nimport { LicenseManager } from './LicenseManager'\n\n/** @internal */\nexport const LicenseContext = createContext({} as LicenseManager)\n\n/** @internal */\nexport const useLicenseContext = () => useContext(LicenseContext)\n\n/** @internal */\nexport function LicenseProvider({\n\tlicenseKey,\n\tchildren,\n}: {\n\tlicenseKey?: string\n\tchildren: ReactNode\n}) {\n\tconst [licenseManager] = useState(() => new LicenseManager(licenseKey))\n\tconst licenseState = useValue(licenseManager.state)\n\n\t// If internal license has expired, don't render the editor at all\n\tif (licenseState === 'internal-expired') {\n\t\treturn <div data-testid=\"tl-license-expired\" style={{ display: 'none' }} />\n\t}\n\n\treturn <LicenseContext.Provider value={licenseManager}>{children}</LicenseContext.Provider>\n}\n"],
5
+ "mappings": "AAuBS;AAvBT,SAAS,gBAAgB;AACzB,SAAS,eAA0B,YAAY,gBAAgB;AAC/D,SAAS,sBAAsB;AAGxB,MAAM,iBAAiB,cAAc,CAAC,CAAmB;AAGzD,MAAM,oBAAoB,MAAM,WAAW,cAAc;AAGzD,SAAS,gBAAgB;AAAA,EAC/B;AAAA,EACA;AACD,GAGG;AACF,QAAM,CAAC,cAAc,IAAI,SAAS,MAAM,IAAI,eAAe,UAAU,CAAC;AACtE,QAAM,eAAe,SAAS,eAAe,KAAK;AAGlD,MAAI,iBAAiB,oBAAoB;AACxC,WAAO,oBAAC,SAAI,eAAY,sBAAqB,OAAO,EAAE,SAAS,OAAO,GAAG;AAAA,EAC1E;AAEA,SAAO,oBAAC,eAAe,UAAf,EAAwB,OAAO,gBAAiB,UAAS;AAClE;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/license/useLicenseManagerState.ts"],
4
- "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { LicenseManager } from './LicenseManager'\n\n/** @internal */\nexport function useLicenseManagerState(licenseManager: LicenseManager) {\n\treturn useValue('watermarkState', () => licenseManager.state.get(), [licenseManager])\n}\n"],
5
- "mappings": "AAAA,SAAS,gBAAgB;AAIlB,SAAS,uBAAuB,gBAAgC;AACtE,SAAO,SAAS,kBAAkB,MAAM,eAAe,MAAM,IAAI,GAAG,CAAC,cAAc,CAAC;AACrF;",
4
+ "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { LicenseManager, LicenseState } from './LicenseManager'\n\n/** @internal */\nexport function useLicenseManagerState(licenseManager: LicenseManager): LicenseState {\n\treturn useValue('watermarkState', () => licenseManager.state.get(), [licenseManager])\n}\n"],
5
+ "mappings": "AAAA,SAAS,gBAAgB;AAIlB,SAAS,uBAAuB,gBAA8C;AACpF,SAAO,SAAS,kBAAkB,MAAM,eAAe,MAAM,IAAI,GAAG,CAAC,cAAc,CAAC;AACrF;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,5 @@
1
1
  import { Vec } from "./Vec.mjs";
2
- import { PI, PI2, toPrecision } from "./utils.mjs";
2
+ import { approximatelyLte, PI, PI2, toPrecision } from "./utils.mjs";
3
3
  class Box {
4
4
  constructor(x = 0, y = 0, w = 0, h = 0) {
5
5
  this.x = x;
@@ -329,6 +329,9 @@ class Box {
329
329
  static Contains(A, B) {
330
330
  return A.minX < B.minX && A.minY < B.minY && A.maxY > B.maxY && A.maxX > B.maxX;
331
331
  }
332
+ static ContainsApproximately(A, B, precision) {
333
+ return approximatelyLte(A.minX, B.minX, precision) && approximatelyLte(A.minY, B.minY, precision) && approximatelyLte(B.maxX, A.maxX, precision) && approximatelyLte(B.maxY, A.maxY, precision);
334
+ }
332
335
  static Includes(A, B) {
333
336
  return Box.Collides(A, B) || Box.Contains(A, B);
334
337
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/primitives/Box.ts"],
4
- "sourcesContent": ["import { BoxModel } from '@tldraw/tlschema'\nimport { Vec, VecLike } from './Vec'\nimport { PI, PI2, toPrecision } from './utils'\n\n/** @public */\nexport type BoxLike = BoxModel | Box\n\n/** @public */\nexport type SelectionEdge = 'top' | 'right' | 'bottom' | 'left'\n\n/** @public */\nexport type SelectionCorner = 'top_left' | 'top_right' | 'bottom_right' | 'bottom_left'\n\n/** @public */\nexport type SelectionHandle = SelectionEdge | SelectionCorner\n\n/** @public */\nexport type RotateCorner =\n\t| 'top_left_rotate'\n\t| 'top_right_rotate'\n\t| 'bottom_right_rotate'\n\t| 'bottom_left_rotate'\n\t| 'mobile_rotate'\n\n/** @public */\nexport class Box {\n\tconstructor(x = 0, y = 0, w = 0, h = 0) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.w = w\n\t\tthis.h = h\n\t}\n\n\tx = 0\n\ty = 0\n\tw = 0\n\th = 0\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget point() {\n\t\treturn new Vec(this.x, this.y)\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset point(val: Vec) {\n\t\tthis.x = val.x\n\t\tthis.y = val.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget minX() {\n\t\treturn this.x\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset minX(n: number) {\n\t\tthis.x = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget left() {\n\t\treturn this.x\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget midX() {\n\t\treturn this.x + this.w / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget maxX() {\n\t\treturn this.x + this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget right() {\n\t\treturn this.x + this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget minY() {\n\t\treturn this.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset minY(n: number) {\n\t\tthis.y = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget top() {\n\t\treturn this.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget midY() {\n\t\treturn this.y + this.h / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget maxY() {\n\t\treturn this.y + this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget bottom() {\n\t\treturn this.y + this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget width() {\n\t\treturn this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset width(n: number) {\n\t\tthis.w = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget height() {\n\t\treturn this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset height(n: number) {\n\t\tthis.h = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget aspectRatio() {\n\t\treturn this.width / this.height\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget center() {\n\t\treturn new Vec(this.x + this.w / 2, this.y + this.h / 2)\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset center(v: Vec) {\n\t\tthis.x = v.x - this.w / 2\n\t\tthis.y = v.y - this.h / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget corners() {\n\t\treturn [\n\t\t\tnew Vec(this.x, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y + this.h),\n\t\t\tnew Vec(this.x, this.y + this.h),\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget cornersAndCenter() {\n\t\treturn [\n\t\t\tnew Vec(this.x, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y + this.h),\n\t\t\tnew Vec(this.x, this.y + this.h),\n\t\t\tnew Vec(this.x + this.w / 2, this.y + this.h / 2),\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget sides(): Array<[Vec, Vec]> {\n\t\tconst { corners } = this\n\t\treturn [\n\t\t\t[corners[0], corners[1]],\n\t\t\t[corners[1], corners[2]],\n\t\t\t[corners[2], corners[3]],\n\t\t\t[corners[3], corners[0]],\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget size(): Vec {\n\t\treturn new Vec(this.w, this.h)\n\t}\n\n\ttoFixed() {\n\t\tthis.x = toPrecision(this.x)\n\t\tthis.y = toPrecision(this.y)\n\t\tthis.w = toPrecision(this.w)\n\t\tthis.h = toPrecision(this.h)\n\t\treturn this\n\t}\n\n\tsetTo(B: Box) {\n\t\tthis.x = B.x\n\t\tthis.y = B.y\n\t\tthis.w = B.w\n\t\tthis.h = B.h\n\t\treturn this\n\t}\n\n\tset(x = 0, y = 0, w = 0, h = 0) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.w = w\n\t\tthis.h = h\n\t\treturn this\n\t}\n\n\texpand(A: Box) {\n\t\tconst minX = Math.min(this.x, A.x)\n\t\tconst minY = Math.min(this.y, A.y)\n\t\tconst maxX = Math.max(this.x + this.w, A.x + A.w)\n\t\tconst maxY = Math.max(this.y + this.h, A.y + A.h)\n\n\t\tthis.x = minX\n\t\tthis.y = minY\n\t\tthis.w = maxX - minX\n\t\tthis.h = maxY - minY\n\t\treturn this\n\t}\n\n\texpandBy(n: number) {\n\t\tthis.x -= n\n\t\tthis.y -= n\n\t\tthis.w += n * 2\n\t\tthis.h += n * 2\n\t\treturn this\n\t}\n\n\tscale(n: number) {\n\t\tthis.x /= n\n\t\tthis.y /= n\n\t\tthis.w /= n\n\t\tthis.h /= n\n\t\treturn this\n\t}\n\n\tclone() {\n\t\tconst { x, y, w, h } = this\n\t\treturn new Box(x, y, w, h)\n\t}\n\n\ttranslate(delta: VecLike) {\n\t\tthis.x += delta.x\n\t\tthis.y += delta.y\n\t\treturn this\n\t}\n\n\tsnapToGrid(size: number) {\n\t\tconst minX = Math.round(this.x / size) * size\n\t\tconst minY = Math.round(this.y / size) * size\n\t\tconst maxX = Math.round((this.x + this.w) / size) * size\n\t\tconst maxY = Math.round((this.y + this.h) / size) * size\n\t\tthis.minX = minX\n\t\tthis.minY = minY\n\t\tthis.width = Math.max(1, maxX - minX)\n\t\tthis.height = Math.max(1, maxY - minY)\n\t}\n\n\tcollides(B: Box) {\n\t\treturn Box.Collides(this, B)\n\t}\n\n\tcontains(B: Box) {\n\t\treturn Box.Contains(this, B)\n\t}\n\n\tincludes(B: Box) {\n\t\treturn Box.Includes(this, B)\n\t}\n\n\tcontainsPoint(V: VecLike, margin = 0) {\n\t\treturn Box.ContainsPoint(this, V, margin)\n\t}\n\n\tgetHandlePoint(handle: SelectionCorner | SelectionEdge) {\n\t\tswitch (handle) {\n\t\t\tcase 'top_left':\n\t\t\t\treturn new Vec(this.x, this.y)\n\t\t\tcase 'top_right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y)\n\t\t\tcase 'bottom_left':\n\t\t\t\treturn new Vec(this.x, this.y + this.h)\n\t\t\tcase 'bottom_right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y + this.h)\n\t\t\tcase 'top':\n\t\t\t\treturn new Vec(this.x + this.w / 2, this.y)\n\t\t\tcase 'right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y + this.h / 2)\n\t\t\tcase 'bottom':\n\t\t\t\treturn new Vec(this.x + this.w / 2, this.y + this.h)\n\t\t\tcase 'left':\n\t\t\t\treturn new Vec(this.x, this.y + this.h / 2)\n\t\t}\n\t}\n\n\ttoJson(): BoxModel {\n\t\treturn { x: this.x, y: this.y, w: this.w, h: this.h }\n\t}\n\n\tresize(handle: SelectionCorner | SelectionEdge | string, dx: number, dy: number) {\n\t\tconst { minX: a0x, minY: a0y, maxX: a1x, maxY: a1y } = this\n\t\tlet { minX: b0x, minY: b0y, maxX: b1x, maxY: b1y } = this\n\n\t\t// Use the delta to adjust the new box by changing its corners.\n\t\t// The dragging handle (corner or edge) will determine which\n\t\t// corners should change.\n\t\tswitch (handle) {\n\t\t\tcase 'left':\n\t\t\tcase 'top_left':\n\t\t\tcase 'bottom_left': {\n\t\t\t\tb0x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'right':\n\t\t\tcase 'top_right':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (handle) {\n\t\t\tcase 'top':\n\t\t\tcase 'top_left':\n\t\t\tcase 'top_right': {\n\t\t\t\tb0y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'bottom':\n\t\t\tcase 'bottom_left':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst scaleX = (b1x - b0x) / (a1x - a0x)\n\t\tconst scaleY = (b1y - b0y) / (a1y - a0y)\n\n\t\tconst flipX = scaleX < 0\n\t\tconst flipY = scaleY < 0\n\n\t\tif (flipX) {\n\t\t\tconst t = b1x\n\t\t\tb1x = b0x\n\t\t\tb0x = t\n\t\t}\n\n\t\tif (flipY) {\n\t\t\tconst t = b1y\n\t\t\tb1y = b0y\n\t\t\tb0y = t\n\t\t}\n\n\t\tthis.minX = b0x\n\t\tthis.minY = b0y\n\t\tthis.width = Math.abs(b1x - b0x)\n\t\tthis.height = Math.abs(b1y - b0y)\n\t}\n\n\tunion(box: BoxModel) {\n\t\tconst minX = Math.min(this.x, box.x)\n\t\tconst minY = Math.min(this.y, box.y)\n\t\tconst maxX = Math.max(this.x + this.w, box.x + box.w)\n\t\tconst maxY = Math.max(this.y + this.h, box.y + box.h)\n\n\t\tthis.x = minX\n\t\tthis.y = minY\n\t\tthis.width = maxX - minX\n\t\tthis.height = maxY - minY\n\n\t\treturn this\n\t}\n\n\tstatic From(box: BoxModel) {\n\t\treturn new Box(box.x, box.y, box.w, box.h)\n\t}\n\n\tstatic FromCenter(center: VecLike, size: VecLike) {\n\t\treturn new Box(center.x - size.x / 2, center.y - size.y / 2, size.x, size.y)\n\t}\n\n\tstatic FromPoints(points: VecLike[]) {\n\t\tif (points.length === 0) return new Box()\n\t\tlet minX = Infinity\n\t\tlet minY = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet maxY = -Infinity\n\t\tlet point: VecLike\n\t\tfor (let i = 0, n = points.length; i < n; i++) {\n\t\t\tpoint = points[i]\n\t\t\tminX = Math.min(point.x, minX)\n\t\t\tminY = Math.min(point.y, minY)\n\t\t\tmaxX = Math.max(point.x, maxX)\n\t\t\tmaxY = Math.max(point.y, maxY)\n\t\t}\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic Expand(A: Box, B: Box) {\n\t\tconst minX = Math.min(B.minX, A.minX)\n\t\tconst minY = Math.min(B.minY, A.minY)\n\t\tconst maxX = Math.max(B.maxX, A.maxX)\n\t\tconst maxY = Math.max(B.maxY, A.maxY)\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic ExpandBy(A: Box, n: number) {\n\t\treturn new Box(A.minX - n, A.minY - n, A.width + n * 2, A.height + n * 2)\n\t}\n\n\tstatic Collides(A: Box, B: Box) {\n\t\treturn !(A.maxX < B.minX || A.minX > B.maxX || A.maxY < B.minY || A.minY > B.maxY)\n\t}\n\n\tstatic Contains(A: Box, B: Box) {\n\t\treturn A.minX < B.minX && A.minY < B.minY && A.maxY > B.maxY && A.maxX > B.maxX\n\t}\n\n\tstatic Includes(A: Box, B: Box) {\n\t\treturn Box.Collides(A, B) || Box.Contains(A, B)\n\t}\n\n\tstatic ContainsPoint(A: Box, B: VecLike, margin = 0) {\n\t\treturn !(\n\t\t\tB.x < A.minX - margin ||\n\t\t\tB.y < A.minY - margin ||\n\t\t\tB.x > A.maxX + margin ||\n\t\t\tB.y > A.maxY + margin\n\t\t)\n\t}\n\n\tstatic Common(boxes: Box[]) {\n\t\tlet minX = Infinity\n\t\tlet minY = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet maxY = -Infinity\n\n\t\tfor (let i = 0; i < boxes.length; i++) {\n\t\t\tconst B = boxes[i]\n\t\t\tminX = Math.min(minX, B.minX)\n\t\t\tminY = Math.min(minY, B.minY)\n\t\t\tmaxX = Math.max(maxX, B.maxX)\n\t\t\tmaxY = Math.max(maxY, B.maxY)\n\t\t}\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic Sides(A: Box, inset = 0) {\n\t\tconst { corners } = A\n\t\tif (inset) {\n\t\t\t// TODO: Inset the corners by the inset amount.\n\t\t}\n\n\t\treturn [\n\t\t\t[corners[0], corners[1]],\n\t\t\t[corners[1], corners[2]],\n\t\t\t[corners[2], corners[3]],\n\t\t\t[corners[3], corners[0]],\n\t\t]\n\t}\n\n\tstatic Resize(\n\t\tbox: Box,\n\t\thandle: SelectionCorner | SelectionEdge | string,\n\t\tdx: number,\n\t\tdy: number,\n\t\tisAspectRatioLocked = false\n\t) {\n\t\tconst { minX: a0x, minY: a0y, maxX: a1x, maxY: a1y } = box\n\t\tlet { minX: b0x, minY: b0y, maxX: b1x, maxY: b1y } = box\n\n\t\t// Use the delta to adjust the new box by changing its corners.\n\t\t// The dragging handle (corner or edge) will determine which\n\t\t// corners should change.\n\t\tswitch (handle) {\n\t\t\tcase 'left':\n\t\t\tcase 'top_left':\n\t\t\tcase 'bottom_left': {\n\t\t\t\tb0x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'right':\n\t\t\tcase 'top_right':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (handle) {\n\t\t\tcase 'top':\n\t\t\tcase 'top_left':\n\t\t\tcase 'top_right': {\n\t\t\t\tb0y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'bottom':\n\t\t\tcase 'bottom_left':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst scaleX = (b1x - b0x) / (a1x - a0x)\n\t\tconst scaleY = (b1y - b0y) / (a1y - a0y)\n\n\t\tconst flipX = scaleX < 0\n\t\tconst flipY = scaleY < 0\n\n\t\t/*\n 2. Aspect ratio\n If the aspect ratio is locked, adjust the corners so that the\n new box's aspect ratio matches the original aspect ratio.\n */\n\t\tif (isAspectRatioLocked) {\n\t\t\tconst aspectRatio = (a1x - a0x) / (a1y - a0y)\n\t\t\tconst bw = Math.abs(b1x - b0x)\n\t\t\tconst bh = Math.abs(b1y - b0y)\n\t\t\tconst tw = bw * (scaleY < 0 ? 1 : -1) * (1 / aspectRatio)\n\t\t\tconst th = bh * (scaleX < 0 ? 1 : -1) * aspectRatio\n\t\t\tconst isTall = aspectRatio < bw / bh\n\n\t\t\tswitch (handle) {\n\t\t\t\tcase 'top_left': {\n\t\t\t\t\tif (isTall) b0y = b1y + tw\n\t\t\t\t\telse b0x = b1x + th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'top_right': {\n\t\t\t\t\tif (isTall) b0y = b1y + tw\n\t\t\t\t\telse b1x = b0x - th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom_right': {\n\t\t\t\t\tif (isTall) b1y = b0y - tw\n\t\t\t\t\telse b1x = b0x - th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom_left': {\n\t\t\t\t\tif (isTall) b1y = b0y - tw\n\t\t\t\t\telse b0x = b1x + th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom':\n\t\t\t\tcase 'top': {\n\t\t\t\t\tconst m = (b0x + b1x) / 2\n\t\t\t\t\tconst w = bh * aspectRatio\n\t\t\t\t\tb0x = m - w / 2\n\t\t\t\t\tb1x = m + w / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'left':\n\t\t\t\tcase 'right': {\n\t\t\t\t\tconst m = (b0y + b1y) / 2\n\t\t\t\t\tconst h = bw / aspectRatio\n\t\t\t\t\tb0y = m - h / 2\n\t\t\t\t\tb1y = m + h / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (flipX) {\n\t\t\tconst t = b1x\n\t\t\tb1x = b0x\n\t\t\tb0x = t\n\t\t}\n\n\t\tif (flipY) {\n\t\t\tconst t = b1y\n\t\t\tb1y = b0y\n\t\t\tb0y = t\n\t\t}\n\n\t\tconst final = new Box(b0x, b0y, Math.abs(b1x - b0x), Math.abs(b1y - b0y))\n\n\t\treturn {\n\t\t\tbox: final,\n\t\t\tscaleX: +((final.width / box.width) * (scaleX > 0 ? 1 : -1)).toFixed(5),\n\t\t\tscaleY: +((final.height / box.height) * (scaleY > 0 ? 1 : -1)).toFixed(5),\n\t\t}\n\t}\n\n\tequals(other: Box | BoxModel) {\n\t\treturn Box.Equals(this, other)\n\t}\n\n\tstatic Equals(a: Box | BoxModel, b: Box | BoxModel) {\n\t\treturn b.x === a.x && b.y === a.y && b.w === a.w && b.h === a.h\n\t}\n\n\tzeroFix() {\n\t\tthis.w = Math.max(1, this.w)\n\t\tthis.h = Math.max(1, this.h)\n\t\treturn this\n\t}\n\n\tstatic ZeroFix(other: Box | BoxModel) {\n\t\treturn new Box(other.x, other.y, Math.max(1, other.w), Math.max(1, other.h))\n\t}\n}\n\n/** @public */\nexport function flipSelectionHandleY(handle: SelectionHandle) {\n\tswitch (handle) {\n\t\tcase 'top':\n\t\t\treturn 'bottom'\n\t\tcase 'bottom':\n\t\t\treturn 'top'\n\t\tcase 'top_left':\n\t\t\treturn 'bottom_left'\n\t\tcase 'top_right':\n\t\t\treturn 'bottom_right'\n\t\tcase 'bottom_left':\n\t\t\treturn 'top_left'\n\t\tcase 'bottom_right':\n\t\t\treturn 'top_right'\n\t\tdefault:\n\t\t\treturn handle\n\t}\n}\n\n/** @public */\nexport function flipSelectionHandleX(handle: SelectionHandle) {\n\tswitch (handle) {\n\t\tcase 'left':\n\t\t\treturn 'right'\n\t\tcase 'right':\n\t\t\treturn 'left'\n\t\tcase 'top_left':\n\t\t\treturn 'top_right'\n\t\tcase 'top_right':\n\t\t\treturn 'top_left'\n\t\tcase 'bottom_left':\n\t\t\treturn 'bottom_right'\n\t\tcase 'bottom_right':\n\t\t\treturn 'bottom_left'\n\t\tdefault:\n\t\t\treturn handle\n\t}\n}\n\nconst ORDERED_SELECTION_HANDLES = [\n\t'top',\n\t'top_right',\n\t'right',\n\t'bottom_right',\n\t'bottom',\n\t'bottom_left',\n\t'left',\n\t'top_left',\n] as const\n\n/** @public */\nexport function rotateSelectionHandle(handle: SelectionHandle, rotation: number): SelectionHandle {\n\t// first find out how many tau we need to rotate by\n\trotation = rotation % PI2\n\tconst numSteps = Math.round(rotation / (PI / 4))\n\n\tconst currentIndex = ORDERED_SELECTION_HANDLES.indexOf(handle)\n\treturn ORDERED_SELECTION_HANDLES[(currentIndex + numSteps) % ORDERED_SELECTION_HANDLES.length]\n}\n\n/** @public */\nexport function isSelectionCorner(selection: string): selection is SelectionCorner {\n\treturn (\n\t\tselection === 'top_left' ||\n\t\tselection === 'top_right' ||\n\t\tselection === 'bottom_right' ||\n\t\tselection === 'bottom_left'\n\t)\n}\n\n/** @public */\nexport const ROTATE_CORNER_TO_SELECTION_CORNER = {\n\ttop_left_rotate: 'top_left',\n\ttop_right_rotate: 'top_right',\n\tbottom_right_rotate: 'bottom_right',\n\tbottom_left_rotate: 'bottom_left',\n\tmobile_rotate: 'top_left',\n} as const\n"],
5
- "mappings": "AACA,SAAS,WAAoB;AAC7B,SAAS,IAAI,KAAK,mBAAmB;AAuB9B,MAAM,IAAI;AAAA,EAChB,YAAY,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG;AACvC,SAAK,IAAI;AACT,SAAK,IAAI;AACT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,EAClB,qBAAqB;AAAA,EACrB,oBAAoB;AAAA,EACpB,eAAe;AAChB;",
4
+ "sourcesContent": ["import { BoxModel } from '@tldraw/tlschema'\nimport { Vec, VecLike } from './Vec'\nimport { approximatelyLte, PI, PI2, toPrecision } from './utils'\n\n/** @public */\nexport type BoxLike = BoxModel | Box\n\n/** @public */\nexport type SelectionEdge = 'top' | 'right' | 'bottom' | 'left'\n\n/** @public */\nexport type SelectionCorner = 'top_left' | 'top_right' | 'bottom_right' | 'bottom_left'\n\n/** @public */\nexport type SelectionHandle = SelectionEdge | SelectionCorner\n\n/** @public */\nexport type RotateCorner =\n\t| 'top_left_rotate'\n\t| 'top_right_rotate'\n\t| 'bottom_right_rotate'\n\t| 'bottom_left_rotate'\n\t| 'mobile_rotate'\n\n/** @public */\nexport class Box {\n\tconstructor(x = 0, y = 0, w = 0, h = 0) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.w = w\n\t\tthis.h = h\n\t}\n\n\tx = 0\n\ty = 0\n\tw = 0\n\th = 0\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget point() {\n\t\treturn new Vec(this.x, this.y)\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset point(val: Vec) {\n\t\tthis.x = val.x\n\t\tthis.y = val.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget minX() {\n\t\treturn this.x\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset minX(n: number) {\n\t\tthis.x = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget left() {\n\t\treturn this.x\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget midX() {\n\t\treturn this.x + this.w / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget maxX() {\n\t\treturn this.x + this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget right() {\n\t\treturn this.x + this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget minY() {\n\t\treturn this.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset minY(n: number) {\n\t\tthis.y = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget top() {\n\t\treturn this.y\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget midY() {\n\t\treturn this.y + this.h / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget maxY() {\n\t\treturn this.y + this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget bottom() {\n\t\treturn this.y + this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget width() {\n\t\treturn this.w\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset width(n: number) {\n\t\tthis.w = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget height() {\n\t\treturn this.h\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset height(n: number) {\n\t\tthis.h = n\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget aspectRatio() {\n\t\treturn this.width / this.height\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget center() {\n\t\treturn new Vec(this.x + this.w / 2, this.y + this.h / 2)\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tset center(v: Vec) {\n\t\tthis.x = v.x - this.w / 2\n\t\tthis.y = v.y - this.h / 2\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget corners() {\n\t\treturn [\n\t\t\tnew Vec(this.x, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y + this.h),\n\t\t\tnew Vec(this.x, this.y + this.h),\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget cornersAndCenter() {\n\t\treturn [\n\t\t\tnew Vec(this.x, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y),\n\t\t\tnew Vec(this.x + this.w, this.y + this.h),\n\t\t\tnew Vec(this.x, this.y + this.h),\n\t\t\tnew Vec(this.x + this.w / 2, this.y + this.h / 2),\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget sides(): Array<[Vec, Vec]> {\n\t\tconst { corners } = this\n\t\treturn [\n\t\t\t[corners[0], corners[1]],\n\t\t\t[corners[1], corners[2]],\n\t\t\t[corners[2], corners[3]],\n\t\t\t[corners[3], corners[0]],\n\t\t]\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget size(): Vec {\n\t\treturn new Vec(this.w, this.h)\n\t}\n\n\ttoFixed() {\n\t\tthis.x = toPrecision(this.x)\n\t\tthis.y = toPrecision(this.y)\n\t\tthis.w = toPrecision(this.w)\n\t\tthis.h = toPrecision(this.h)\n\t\treturn this\n\t}\n\n\tsetTo(B: Box) {\n\t\tthis.x = B.x\n\t\tthis.y = B.y\n\t\tthis.w = B.w\n\t\tthis.h = B.h\n\t\treturn this\n\t}\n\n\tset(x = 0, y = 0, w = 0, h = 0) {\n\t\tthis.x = x\n\t\tthis.y = y\n\t\tthis.w = w\n\t\tthis.h = h\n\t\treturn this\n\t}\n\n\texpand(A: Box) {\n\t\tconst minX = Math.min(this.x, A.x)\n\t\tconst minY = Math.min(this.y, A.y)\n\t\tconst maxX = Math.max(this.x + this.w, A.x + A.w)\n\t\tconst maxY = Math.max(this.y + this.h, A.y + A.h)\n\n\t\tthis.x = minX\n\t\tthis.y = minY\n\t\tthis.w = maxX - minX\n\t\tthis.h = maxY - minY\n\t\treturn this\n\t}\n\n\texpandBy(n: number) {\n\t\tthis.x -= n\n\t\tthis.y -= n\n\t\tthis.w += n * 2\n\t\tthis.h += n * 2\n\t\treturn this\n\t}\n\n\tscale(n: number) {\n\t\tthis.x /= n\n\t\tthis.y /= n\n\t\tthis.w /= n\n\t\tthis.h /= n\n\t\treturn this\n\t}\n\n\tclone() {\n\t\tconst { x, y, w, h } = this\n\t\treturn new Box(x, y, w, h)\n\t}\n\n\ttranslate(delta: VecLike) {\n\t\tthis.x += delta.x\n\t\tthis.y += delta.y\n\t\treturn this\n\t}\n\n\tsnapToGrid(size: number) {\n\t\tconst minX = Math.round(this.x / size) * size\n\t\tconst minY = Math.round(this.y / size) * size\n\t\tconst maxX = Math.round((this.x + this.w) / size) * size\n\t\tconst maxY = Math.round((this.y + this.h) / size) * size\n\t\tthis.minX = minX\n\t\tthis.minY = minY\n\t\tthis.width = Math.max(1, maxX - minX)\n\t\tthis.height = Math.max(1, maxY - minY)\n\t}\n\n\tcollides(B: Box) {\n\t\treturn Box.Collides(this, B)\n\t}\n\n\tcontains(B: Box) {\n\t\treturn Box.Contains(this, B)\n\t}\n\n\tincludes(B: Box) {\n\t\treturn Box.Includes(this, B)\n\t}\n\n\tcontainsPoint(V: VecLike, margin = 0) {\n\t\treturn Box.ContainsPoint(this, V, margin)\n\t}\n\n\tgetHandlePoint(handle: SelectionCorner | SelectionEdge) {\n\t\tswitch (handle) {\n\t\t\tcase 'top_left':\n\t\t\t\treturn new Vec(this.x, this.y)\n\t\t\tcase 'top_right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y)\n\t\t\tcase 'bottom_left':\n\t\t\t\treturn new Vec(this.x, this.y + this.h)\n\t\t\tcase 'bottom_right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y + this.h)\n\t\t\tcase 'top':\n\t\t\t\treturn new Vec(this.x + this.w / 2, this.y)\n\t\t\tcase 'right':\n\t\t\t\treturn new Vec(this.x + this.w, this.y + this.h / 2)\n\t\t\tcase 'bottom':\n\t\t\t\treturn new Vec(this.x + this.w / 2, this.y + this.h)\n\t\t\tcase 'left':\n\t\t\t\treturn new Vec(this.x, this.y + this.h / 2)\n\t\t}\n\t}\n\n\ttoJson(): BoxModel {\n\t\treturn { x: this.x, y: this.y, w: this.w, h: this.h }\n\t}\n\n\tresize(handle: SelectionCorner | SelectionEdge | string, dx: number, dy: number) {\n\t\tconst { minX: a0x, minY: a0y, maxX: a1x, maxY: a1y } = this\n\t\tlet { minX: b0x, minY: b0y, maxX: b1x, maxY: b1y } = this\n\n\t\t// Use the delta to adjust the new box by changing its corners.\n\t\t// The dragging handle (corner or edge) will determine which\n\t\t// corners should change.\n\t\tswitch (handle) {\n\t\t\tcase 'left':\n\t\t\tcase 'top_left':\n\t\t\tcase 'bottom_left': {\n\t\t\t\tb0x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'right':\n\t\t\tcase 'top_right':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (handle) {\n\t\t\tcase 'top':\n\t\t\tcase 'top_left':\n\t\t\tcase 'top_right': {\n\t\t\t\tb0y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'bottom':\n\t\t\tcase 'bottom_left':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst scaleX = (b1x - b0x) / (a1x - a0x)\n\t\tconst scaleY = (b1y - b0y) / (a1y - a0y)\n\n\t\tconst flipX = scaleX < 0\n\t\tconst flipY = scaleY < 0\n\n\t\tif (flipX) {\n\t\t\tconst t = b1x\n\t\t\tb1x = b0x\n\t\t\tb0x = t\n\t\t}\n\n\t\tif (flipY) {\n\t\t\tconst t = b1y\n\t\t\tb1y = b0y\n\t\t\tb0y = t\n\t\t}\n\n\t\tthis.minX = b0x\n\t\tthis.minY = b0y\n\t\tthis.width = Math.abs(b1x - b0x)\n\t\tthis.height = Math.abs(b1y - b0y)\n\t}\n\n\tunion(box: BoxModel) {\n\t\tconst minX = Math.min(this.x, box.x)\n\t\tconst minY = Math.min(this.y, box.y)\n\t\tconst maxX = Math.max(this.x + this.w, box.x + box.w)\n\t\tconst maxY = Math.max(this.y + this.h, box.y + box.h)\n\n\t\tthis.x = minX\n\t\tthis.y = minY\n\t\tthis.width = maxX - minX\n\t\tthis.height = maxY - minY\n\n\t\treturn this\n\t}\n\n\tstatic From(box: BoxModel) {\n\t\treturn new Box(box.x, box.y, box.w, box.h)\n\t}\n\n\tstatic FromCenter(center: VecLike, size: VecLike) {\n\t\treturn new Box(center.x - size.x / 2, center.y - size.y / 2, size.x, size.y)\n\t}\n\n\tstatic FromPoints(points: VecLike[]) {\n\t\tif (points.length === 0) return new Box()\n\t\tlet minX = Infinity\n\t\tlet minY = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet maxY = -Infinity\n\t\tlet point: VecLike\n\t\tfor (let i = 0, n = points.length; i < n; i++) {\n\t\t\tpoint = points[i]\n\t\t\tminX = Math.min(point.x, minX)\n\t\t\tminY = Math.min(point.y, minY)\n\t\t\tmaxX = Math.max(point.x, maxX)\n\t\t\tmaxY = Math.max(point.y, maxY)\n\t\t}\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic Expand(A: Box, B: Box) {\n\t\tconst minX = Math.min(B.minX, A.minX)\n\t\tconst minY = Math.min(B.minY, A.minY)\n\t\tconst maxX = Math.max(B.maxX, A.maxX)\n\t\tconst maxY = Math.max(B.maxY, A.maxY)\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic ExpandBy(A: Box, n: number) {\n\t\treturn new Box(A.minX - n, A.minY - n, A.width + n * 2, A.height + n * 2)\n\t}\n\n\tstatic Collides(A: Box, B: Box) {\n\t\treturn !(A.maxX < B.minX || A.minX > B.maxX || A.maxY < B.minY || A.minY > B.maxY)\n\t}\n\n\tstatic Contains(A: Box, B: Box) {\n\t\treturn A.minX < B.minX && A.minY < B.minY && A.maxY > B.maxY && A.maxX > B.maxX\n\t}\n\n\tstatic ContainsApproximately(A: Box, B: Box, precision?: number) {\n\t\treturn (\n\t\t\tapproximatelyLte(A.minX, B.minX, precision) &&\n\t\t\tapproximatelyLte(A.minY, B.minY, precision) &&\n\t\t\tapproximatelyLte(B.maxX, A.maxX, precision) &&\n\t\t\tapproximatelyLte(B.maxY, A.maxY, precision)\n\t\t)\n\t}\n\n\tstatic Includes(A: Box, B: Box) {\n\t\treturn Box.Collides(A, B) || Box.Contains(A, B)\n\t}\n\n\tstatic ContainsPoint(A: Box, B: VecLike, margin = 0) {\n\t\treturn !(\n\t\t\tB.x < A.minX - margin ||\n\t\t\tB.y < A.minY - margin ||\n\t\t\tB.x > A.maxX + margin ||\n\t\t\tB.y > A.maxY + margin\n\t\t)\n\t}\n\n\tstatic Common(boxes: Box[]) {\n\t\tlet minX = Infinity\n\t\tlet minY = Infinity\n\t\tlet maxX = -Infinity\n\t\tlet maxY = -Infinity\n\n\t\tfor (let i = 0; i < boxes.length; i++) {\n\t\t\tconst B = boxes[i]\n\t\t\tminX = Math.min(minX, B.minX)\n\t\t\tminY = Math.min(minY, B.minY)\n\t\t\tmaxX = Math.max(maxX, B.maxX)\n\t\t\tmaxY = Math.max(maxY, B.maxY)\n\t\t}\n\n\t\treturn new Box(minX, minY, maxX - minX, maxY - minY)\n\t}\n\n\tstatic Sides(A: Box, inset = 0) {\n\t\tconst { corners } = A\n\t\tif (inset) {\n\t\t\t// TODO: Inset the corners by the inset amount.\n\t\t}\n\n\t\treturn [\n\t\t\t[corners[0], corners[1]],\n\t\t\t[corners[1], corners[2]],\n\t\t\t[corners[2], corners[3]],\n\t\t\t[corners[3], corners[0]],\n\t\t]\n\t}\n\n\tstatic Resize(\n\t\tbox: Box,\n\t\thandle: SelectionCorner | SelectionEdge | string,\n\t\tdx: number,\n\t\tdy: number,\n\t\tisAspectRatioLocked = false\n\t) {\n\t\tconst { minX: a0x, minY: a0y, maxX: a1x, maxY: a1y } = box\n\t\tlet { minX: b0x, minY: b0y, maxX: b1x, maxY: b1y } = box\n\n\t\t// Use the delta to adjust the new box by changing its corners.\n\t\t// The dragging handle (corner or edge) will determine which\n\t\t// corners should change.\n\t\tswitch (handle) {\n\t\t\tcase 'left':\n\t\t\tcase 'top_left':\n\t\t\tcase 'bottom_left': {\n\t\t\t\tb0x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'right':\n\t\t\tcase 'top_right':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1x += dx\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tswitch (handle) {\n\t\t\tcase 'top':\n\t\t\tcase 'top_left':\n\t\t\tcase 'top_right': {\n\t\t\t\tb0y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'bottom':\n\t\t\tcase 'bottom_left':\n\t\t\tcase 'bottom_right': {\n\t\t\t\tb1y += dy\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tconst scaleX = (b1x - b0x) / (a1x - a0x)\n\t\tconst scaleY = (b1y - b0y) / (a1y - a0y)\n\n\t\tconst flipX = scaleX < 0\n\t\tconst flipY = scaleY < 0\n\n\t\t/*\n 2. Aspect ratio\n If the aspect ratio is locked, adjust the corners so that the\n new box's aspect ratio matches the original aspect ratio.\n */\n\t\tif (isAspectRatioLocked) {\n\t\t\tconst aspectRatio = (a1x - a0x) / (a1y - a0y)\n\t\t\tconst bw = Math.abs(b1x - b0x)\n\t\t\tconst bh = Math.abs(b1y - b0y)\n\t\t\tconst tw = bw * (scaleY < 0 ? 1 : -1) * (1 / aspectRatio)\n\t\t\tconst th = bh * (scaleX < 0 ? 1 : -1) * aspectRatio\n\t\t\tconst isTall = aspectRatio < bw / bh\n\n\t\t\tswitch (handle) {\n\t\t\t\tcase 'top_left': {\n\t\t\t\t\tif (isTall) b0y = b1y + tw\n\t\t\t\t\telse b0x = b1x + th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'top_right': {\n\t\t\t\t\tif (isTall) b0y = b1y + tw\n\t\t\t\t\telse b1x = b0x - th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom_right': {\n\t\t\t\t\tif (isTall) b1y = b0y - tw\n\t\t\t\t\telse b1x = b0x - th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom_left': {\n\t\t\t\t\tif (isTall) b1y = b0y - tw\n\t\t\t\t\telse b0x = b1x + th\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'bottom':\n\t\t\t\tcase 'top': {\n\t\t\t\t\tconst m = (b0x + b1x) / 2\n\t\t\t\t\tconst w = bh * aspectRatio\n\t\t\t\t\tb0x = m - w / 2\n\t\t\t\t\tb1x = m + w / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'left':\n\t\t\t\tcase 'right': {\n\t\t\t\t\tconst m = (b0y + b1y) / 2\n\t\t\t\t\tconst h = bw / aspectRatio\n\t\t\t\t\tb0y = m - h / 2\n\t\t\t\t\tb1y = m + h / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (flipX) {\n\t\t\tconst t = b1x\n\t\t\tb1x = b0x\n\t\t\tb0x = t\n\t\t}\n\n\t\tif (flipY) {\n\t\t\tconst t = b1y\n\t\t\tb1y = b0y\n\t\t\tb0y = t\n\t\t}\n\n\t\tconst final = new Box(b0x, b0y, Math.abs(b1x - b0x), Math.abs(b1y - b0y))\n\n\t\treturn {\n\t\t\tbox: final,\n\t\t\tscaleX: +((final.width / box.width) * (scaleX > 0 ? 1 : -1)).toFixed(5),\n\t\t\tscaleY: +((final.height / box.height) * (scaleY > 0 ? 1 : -1)).toFixed(5),\n\t\t}\n\t}\n\n\tequals(other: Box | BoxModel) {\n\t\treturn Box.Equals(this, other)\n\t}\n\n\tstatic Equals(a: Box | BoxModel, b: Box | BoxModel) {\n\t\treturn b.x === a.x && b.y === a.y && b.w === a.w && b.h === a.h\n\t}\n\n\tzeroFix() {\n\t\tthis.w = Math.max(1, this.w)\n\t\tthis.h = Math.max(1, this.h)\n\t\treturn this\n\t}\n\n\tstatic ZeroFix(other: Box | BoxModel) {\n\t\treturn new Box(other.x, other.y, Math.max(1, other.w), Math.max(1, other.h))\n\t}\n}\n\n/** @public */\nexport function flipSelectionHandleY(handle: SelectionHandle) {\n\tswitch (handle) {\n\t\tcase 'top':\n\t\t\treturn 'bottom'\n\t\tcase 'bottom':\n\t\t\treturn 'top'\n\t\tcase 'top_left':\n\t\t\treturn 'bottom_left'\n\t\tcase 'top_right':\n\t\t\treturn 'bottom_right'\n\t\tcase 'bottom_left':\n\t\t\treturn 'top_left'\n\t\tcase 'bottom_right':\n\t\t\treturn 'top_right'\n\t\tdefault:\n\t\t\treturn handle\n\t}\n}\n\n/** @public */\nexport function flipSelectionHandleX(handle: SelectionHandle) {\n\tswitch (handle) {\n\t\tcase 'left':\n\t\t\treturn 'right'\n\t\tcase 'right':\n\t\t\treturn 'left'\n\t\tcase 'top_left':\n\t\t\treturn 'top_right'\n\t\tcase 'top_right':\n\t\t\treturn 'top_left'\n\t\tcase 'bottom_left':\n\t\t\treturn 'bottom_right'\n\t\tcase 'bottom_right':\n\t\t\treturn 'bottom_left'\n\t\tdefault:\n\t\t\treturn handle\n\t}\n}\n\nconst ORDERED_SELECTION_HANDLES = [\n\t'top',\n\t'top_right',\n\t'right',\n\t'bottom_right',\n\t'bottom',\n\t'bottom_left',\n\t'left',\n\t'top_left',\n] as const\n\n/** @public */\nexport function rotateSelectionHandle(handle: SelectionHandle, rotation: number): SelectionHandle {\n\t// first find out how many tau we need to rotate by\n\trotation = rotation % PI2\n\tconst numSteps = Math.round(rotation / (PI / 4))\n\n\tconst currentIndex = ORDERED_SELECTION_HANDLES.indexOf(handle)\n\treturn ORDERED_SELECTION_HANDLES[(currentIndex + numSteps) % ORDERED_SELECTION_HANDLES.length]\n}\n\n/** @public */\nexport function isSelectionCorner(selection: string): selection is SelectionCorner {\n\treturn (\n\t\tselection === 'top_left' ||\n\t\tselection === 'top_right' ||\n\t\tselection === 'bottom_right' ||\n\t\tselection === 'bottom_left'\n\t)\n}\n\n/** @public */\nexport const ROTATE_CORNER_TO_SELECTION_CORNER = {\n\ttop_left_rotate: 'top_left',\n\ttop_right_rotate: 'top_right',\n\tbottom_right_rotate: 'bottom_right',\n\t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AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAEA,MAAM,4BAA4B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAGO,SAAS,sBAAsB,QAAyB,UAAmC;AAEjG,aAAW,WAAW;AACtB,QAAM,WAAW,KAAK,MAAM,YAAY,KAAK,EAAE;AAE/C,QAAM,eAAe,0BAA0B,QAAQ,MAAM;AAC7D,SAAO,2BAA2B,eAAe,YAAY,0BAA0B,MAAM;AAC9F;AAGO,SAAS,kBAAkB,WAAiD;AAClF,SACC,cAAc,cACd,cAAc,eACd,cAAc,kBACd,cAAc;AAEhB;AAGO,MAAM,oCAAoC;AAAA,EAChD,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,qBAAqB;AAAA,EACrB,oBAAoB;AAAA,EACpB,eAAe;AAChB;",
6
6
  "names": []
7
7
  }
@@ -1,8 +1,8 @@
1
- const version = "3.16.0-canary.c1bcdabc9513";
1
+ const version = "3.16.0-canary.c7d3f7d5729d";
2
2
  const publishDates = {
3
3
  major: "2024-09-13T14:36:29.063Z",
4
- minor: "2025-08-17T08:02:22.032Z",
5
- patch: "2025-08-17T08:02:22.032Z"
4
+ minor: "2025-08-28T15:31:21.677Z",
5
+ patch: "2025-08-28T15:31:21.677Z"
6
6
  };
7
7
  export {
8
8
  publishDates,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/version.ts"],
4
- "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '3.16.0-canary.c1bcdabc9513'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-08-17T08:02:22.032Z',\n\tpatch: '2025-08-17T08:02:22.032Z',\n}\n"],
4
+ "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '3.16.0-canary.c7d3f7d5729d'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-08-28T15:31:21.677Z',\n\tpatch: '2025-08-28T15:31:21.677Z',\n}\n"],
5
5
  "mappings": "AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
6
6
  "names": []
7
7
  }
package/editor.css CHANGED
@@ -29,6 +29,7 @@
29
29
  --tl-layer-watermark: 200;
30
30
  --tl-layer-canvas-shapes: 300;
31
31
  --tl-layer-canvas-overlays: 500;
32
+ --tl-layer-canvas-in-front: 600;
32
33
  --tl-layer-canvas-blocker: 10000;
33
34
 
34
35
  /* Canvas overlays z-index */
@@ -297,6 +298,13 @@ input,
297
298
  contain: strict;
298
299
  }
299
300
 
301
+ .tl-canvas__in-front {
302
+ position: absolute;
303
+ inset: 0;
304
+ pointer-events: none;
305
+ z-index: var(--tl-layer-canvas-in-front);
306
+ }
307
+
300
308
  .tl-shapes {
301
309
  position: relative;
302
310
  z-index: var(--tl-layer-canvas-shapes);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tldraw/editor",
3
3
  "description": "tldraw infinite canvas SDK (editor).",
4
- "version": "3.16.0-canary.c1bcdabc9513",
4
+ "version": "3.16.0-canary.c7d3f7d5729d",
5
5
  "author": {
6
6
  "name": "tldraw Inc.",
7
7
  "email": "hello@tldraw.com"
@@ -50,12 +50,12 @@
50
50
  "@tiptap/core": "^2.9.1",
51
51
  "@tiptap/pm": "^2.9.1",
52
52
  "@tiptap/react": "^2.9.1",
53
- "@tldraw/state": "3.16.0-canary.c1bcdabc9513",
54
- "@tldraw/state-react": "3.16.0-canary.c1bcdabc9513",
55
- "@tldraw/store": "3.16.0-canary.c1bcdabc9513",
56
- "@tldraw/tlschema": "3.16.0-canary.c1bcdabc9513",
57
- "@tldraw/utils": "3.16.0-canary.c1bcdabc9513",
58
- "@tldraw/validate": "3.16.0-canary.c1bcdabc9513",
53
+ "@tldraw/state": "3.16.0-canary.c7d3f7d5729d",
54
+ "@tldraw/state-react": "3.16.0-canary.c7d3f7d5729d",
55
+ "@tldraw/store": "3.16.0-canary.c7d3f7d5729d",
56
+ "@tldraw/tlschema": "3.16.0-canary.c7d3f7d5729d",
57
+ "@tldraw/utils": "3.16.0-canary.c7d3f7d5729d",
58
+ "@tldraw/validate": "3.16.0-canary.c7d3f7d5729d",
59
59
  "@types/core-js": "^2.5.8",
60
60
  "@use-gesture/react": "^10.3.1",
61
61
  "classnames": "^2.5.1",
package/src/index.ts CHANGED
@@ -331,6 +331,7 @@ export {
331
331
  type InvalidLicenseReason,
332
332
  type LicenseFromKeyResult,
333
333
  type LicenseInfo,
334
+ type LicenseState,
334
335
  type TestEnvironment,
335
336
  type ValidLicenseKeyResult,
336
337
  } from './lib/license/LicenseManager'
@@ -586,8 +586,13 @@ function TldrawEditorWithReadyStore({
586
586
  if (editor !== fontLoadingState?.editor) {
587
587
  fontLoadingState = null
588
588
  }
589
- useEffect(() => {
589
+ useLayoutEffect(() => {
590
590
  if (!editor) return
591
+ if (editor.options.maxFontsToLoadBeforeRender === 0) {
592
+ setFontLoadingState({ editor, isLoaded: true })
593
+ return
594
+ }
595
+
591
596
  let isCancelled = false
592
597
 
593
598
  setFontLoadingState({ editor, isLoaded: false })
@@ -28,7 +28,6 @@ export const Shape = memo(function Shape({
28
28
  index,
29
29
  backgroundIndex,
30
30
  opacity,
31
- dprMultiple,
32
31
  }: {
33
32
  id: TLShapeId
34
33
  shape: TLShape
@@ -36,7 +35,6 @@ export const Shape = memo(function Shape({
36
35
  index: number
37
36
  backgroundIndex: number
38
37
  opacity: number
39
- dprMultiple: number
40
38
  }) {
41
39
  const editor = useEditor()
42
40
 
@@ -91,18 +89,14 @@ export const Shape = memo(function Shape({
91
89
  }
92
90
 
93
91
  // Width / Height
94
- // We round the shape width and height up to the nearest multiple of dprMultiple
95
- // to avoid the browser making miscalculations when applying the transform.
96
- const widthRemainder = bounds.w % dprMultiple
97
- const heightRemainder = bounds.h % dprMultiple
98
- const width = widthRemainder === 0 ? bounds.w : bounds.w + (dprMultiple - widthRemainder)
99
- const height = heightRemainder === 0 ? bounds.h : bounds.h + (dprMultiple - heightRemainder)
92
+ const width = Math.max(bounds.width, 1)
93
+ const height = Math.max(bounds.height, 1)
100
94
 
101
95
  if (width !== prev.width || height !== prev.height) {
102
- setStyleProperty(containerRef.current, 'width', Math.max(width, dprMultiple) + 'px')
103
- setStyleProperty(containerRef.current, 'height', Math.max(height, dprMultiple) + 'px')
104
- setStyleProperty(bgContainerRef.current, 'width', Math.max(width, dprMultiple) + 'px')
105
- setStyleProperty(bgContainerRef.current, 'height', Math.max(height, dprMultiple) + 'px')
96
+ setStyleProperty(containerRef.current, 'width', width + 'px')
97
+ setStyleProperty(containerRef.current, 'height', height + 'px')
98
+ setStyleProperty(bgContainerRef.current, 'width', width + 'px')
99
+ setStyleProperty(bgContainerRef.current, 'height', height + 'px')
106
100
  prev.width = width
107
101
  prev.height = height
108
102
  }
@@ -22,7 +22,6 @@ import { Vec } from '../../primitives/Vec'
22
22
  import { toDomPrecision } from '../../primitives/utils'
23
23
  import { debugFlags } from '../../utils/debug-flags'
24
24
  import { setStyleProperty } from '../../utils/dom'
25
- import { nearestMultiple } from '../../utils/nearestMultiple'
26
25
  import { GeometryDebuggingView } from '../GeometryDebuggingView'
27
26
  import { LiveCollaborators } from '../LiveCollaborators'
28
27
  import { MenuClickCapture } from '../MenuClickCapture'
@@ -173,10 +172,12 @@ export function DefaultCanvas({ className }: TLCanvasComponentProps) {
173
172
  <LiveCollaborators />
174
173
  </div>
175
174
  </div>
175
+ <div className="tl-canvas__in-front">
176
+ <InFrontOfTheCanvasWrapper />
177
+ </div>
176
178
  <MovingCameraHitTestBlocker />
177
179
  </div>
178
180
  <MenuClickCapture />
179
- <InFrontOfTheCanvasWrapper />
180
181
  </>
181
182
  )
182
183
  }
@@ -390,18 +391,9 @@ function ShapesWithSVGs() {
390
391
 
391
392
  const renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])
392
393
 
393
- const dprMultiple = useValue(
394
- 'dpr multiple',
395
- () =>
396
- // dprMultiple is the smallest number we can multiply dpr by to get an integer
397
- // it's usually 1, 2, or 4 (for e.g. dpr of 2, 2.5 and 2.25 respectively)
398
- nearestMultiple(Math.floor(editor.getInstanceState().devicePixelRatio * 100) / 100),
399
- [editor]
400
- )
401
-
402
394
  return renderingShapes.map((result) => (
403
395
  <Fragment key={result.id + '_fragment'}>
404
- <Shape {...result} dprMultiple={dprMultiple} />
396
+ <Shape {...result} />
405
397
  <DebugSvgCopy id={result.id} mode="iframe" />
406
398
  </Fragment>
407
399
  ))
@@ -436,19 +428,10 @@ function ShapesToDisplay() {
436
428
 
437
429
  const renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])
438
430
 
439
- const dprMultiple = useValue(
440
- 'dpr multiple',
441
- () =>
442
- // dprMultiple is the smallest number we can multiply dpr by to get an integer
443
- // it's usually 1, 2, or 4 (for e.g. dpr of 2, 2.5 and 2.25 respectively)
444
- nearestMultiple(Math.floor(editor.getInstanceState().devicePixelRatio * 100) / 100),
445
- [editor]
446
- )
447
-
448
431
  return (
449
432
  <>
450
433
  {renderingShapes.map((result) => (
451
- <Shape key={result.id + '_shape'} {...result} dprMultiple={dprMultiple} />
434
+ <Shape key={result.id + '_shape'} {...result} />
452
435
  ))}
453
436
  {tlenv.isSafari && <ReflowIfNeeded />}
454
437
  </>
@@ -4860,27 +4860,25 @@ export class Editor extends EventEmitter<TLEventMap> {
4860
4860
  return this.store.createComputedCache('pageMaskCache', (shape) => {
4861
4861
  if (isPageId(shape.parentId)) return undefined
4862
4862
 
4863
- const frameAncestors = this.getShapeAncestors(shape.id).filter((shape) =>
4864
- this.isShapeOfType<TLFrameShape>(shape, 'frame')
4865
- )
4866
-
4867
- if (frameAncestors.length === 0) return undefined
4868
-
4869
- const pageMask = frameAncestors
4870
- .map<Vec[] | undefined>((s) => {
4871
- // Apply the frame transform to the frame outline to get the frame outline in the current page space
4872
- const geometry = this.getShapeGeometry(s.id)
4873
- const pageTransform = this.getShapePageTransform(s.id)
4874
- return pageTransform.applyToPoints(geometry.vertices)
4875
- })
4876
- .reduce((acc, b) => {
4877
- if (!(b && acc)) return undefined
4878
- const intersection = intersectPolygonPolygon(acc, b)
4879
- if (intersection) {
4880
- return intersection.map(Vec.Cast)
4881
- }
4882
- return []
4883
- })
4863
+ const clipPaths: Vec[][] = []
4864
+ // Get all ancestors that can potentially clip this shape
4865
+ for (const ancestor of this.getShapeAncestors(shape.id)) {
4866
+ const util = this.getShapeUtil(ancestor)
4867
+ const clipPath = util.getClipPath?.(ancestor)
4868
+ if (!clipPath) continue
4869
+ if (util.shouldClipChild?.(shape) === false) continue
4870
+ const pageTransform = this.getShapePageTransform(ancestor.id)
4871
+ clipPaths.push(pageTransform.applyToPoints(clipPath))
4872
+ }
4873
+ if (clipPaths.length === 0) return undefined
4874
+
4875
+ const pageMask = clipPaths.reduce((acc, b) => {
4876
+ const intersection = intersectPolygonPolygon(acc, b)
4877
+ if (intersection) {
4878
+ return intersection.map(Vec.Cast)
4879
+ }
4880
+ return []
4881
+ })
4884
4882
 
4885
4883
  return pageMask
4886
4884
  })
@@ -9519,6 +9517,24 @@ export class Editor extends EventEmitter<TLEventMap> {
9519
9517
  }
9520
9518
  }
9521
9519
 
9520
+ /**
9521
+ * Get an exported image of the given shapes as a data URL.
9522
+ *
9523
+ * @param shapes - The shapes (or shape ids) to export.
9524
+ * @param opts - Options for the export.
9525
+ *
9526
+ * @returns A data URL of the image.
9527
+ * @public
9528
+ */
9529
+ async toImageDataUrl(shapes: TLShapeId[] | TLShape[], opts: TLImageExportOptions = {}) {
9530
+ const { blob, width, height } = await this.toImage(shapes, opts)
9531
+ return {
9532
+ url: await FileHelpers.blobToDataUrl(blob),
9533
+ width,
9534
+ height,
9535
+ }
9536
+ }
9537
+
9522
9538
  /* --------------------- Events --------------------- */
9523
9539
 
9524
9540
  /**