@baique/pi-web-sky 0.1.39 → 0.1.41

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 (381) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +7 -12
  3. package/.next/build-manifest.json +3 -3
  4. package/.next/prerender-manifest.json +3 -3
  5. package/.next/react-loadable-manifest.json +51 -51
  6. package/.next/required-server-files.js +1 -1
  7. package/.next/required-server-files.json +1 -1
  8. package/.next/routes-manifest.json +3 -45
  9. package/.next/server/app/_global-error/page.js +2 -2
  10. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  11. package/.next/server/app/_global-error.html +1 -1
  12. package/.next/server/app/_global-error.rsc +1 -1
  13. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  14. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  15. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  16. package/.next/server/app/_not-found/page.js +1 -1
  17. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  18. package/.next/server/app/_not-found.html +1 -1
  19. package/.next/server/app/_not-found.rsc +3 -3
  20. package/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
  21. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +3 -3
  22. package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  23. package/.next/server/app/api/agent/[id]/bash-output/route.js +2 -2
  24. package/.next/server/app/api/agent/[id]/events/route.js +2 -2
  25. package/.next/server/app/api/agent/[id]/route.js +2 -2
  26. package/.next/server/app/api/agent/new/route.js +1 -1
  27. package/.next/server/app/api/agent/new/route.js.nft.json +1 -1
  28. package/.next/server/app/api/agent/running/route.js +1 -1
  29. package/.next/server/app/api/app-update/route.js +1 -1
  30. package/.next/server/app/api/auth/all-providers/route.js +1 -1
  31. package/.next/server/app/api/auth/api-key/[provider]/route.js +1 -1
  32. package/.next/server/app/api/auth/login/[provider]/route.js +1 -1
  33. package/.next/server/app/api/auth/logout/[provider]/route.js +1 -1
  34. package/.next/server/app/api/auth/providers/route.js +1 -1
  35. package/.next/server/app/api/boards/[id]/reconcile/route.js +1 -0
  36. package/.next/server/app/api/boards/[id]/reconcile/route_client-reference-manifest.js +1 -0
  37. package/.next/server/app/api/boards/[id]/route.js +1 -1
  38. package/.next/server/app/api/boards/purge-orphans/route.js +1 -1
  39. package/.next/server/app/api/boards/reorder/route.js +1 -1
  40. package/.next/server/app/api/boards/route.js +1 -1
  41. package/.next/server/app/api/cwd/browse/route.js +1 -1
  42. package/.next/server/app/api/cwd/validate/route.js +2 -2
  43. package/.next/server/app/api/default-cwd/route.js +2 -2
  44. package/.next/server/app/api/file-index/route.js +2 -2
  45. package/.next/server/app/api/files/[...path]/route.js +3 -3
  46. package/.next/server/app/api/files/[...path]/route.js.nft.json +1 -1
  47. package/.next/server/app/api/git/diff/route.js +1 -1
  48. package/.next/server/app/api/git/status/route.js +1 -1
  49. package/.next/server/app/api/home/route.js +1 -1
  50. package/.next/server/app/api/mcp/route.js +1 -1
  51. package/.next/server/app/api/models/route.js +2 -2
  52. package/.next/server/app/api/models-config/catalog/route.js +1 -1
  53. package/.next/server/app/api/models-config/discover/route.js +1 -1
  54. package/.next/server/app/api/models-config/route.js +1 -1
  55. package/.next/server/app/api/models-config/test/route.js +1 -1
  56. package/.next/server/app/api/plugins/route.js +2 -2
  57. package/.next/server/app/api/project-trust/route.js +2 -2
  58. package/.next/server/app/api/quota/route.js +1 -1
  59. package/.next/server/app/api/search/route.js +2 -2
  60. package/.next/server/app/api/sessions/[id]/auto-name/route.js +3 -3
  61. package/.next/server/app/api/sessions/[id]/context/route.js +2 -2
  62. package/.next/server/app/api/sessions/[id]/entries/[entryId]/thinking/route.js +2 -2
  63. package/.next/server/app/api/sessions/[id]/export/route.js +2 -2
  64. package/.next/server/app/api/sessions/[id]/route.js +1 -1
  65. package/.next/server/app/api/sessions/[id]/state/route.js +2 -2
  66. package/.next/server/app/api/sessions/[id]/todos/route.js +2 -2
  67. package/.next/server/app/api/sessions/route.js +2 -2
  68. package/.next/server/app/api/skills/check/route.js +1 -1
  69. package/.next/server/app/api/skills/install/route.js +2 -2
  70. package/.next/server/app/api/skills/route.js +1 -1
  71. package/.next/server/app/api/skills/search/route.js +1 -1
  72. package/.next/server/app/api/skills/update/route.js +1 -1
  73. package/.next/server/app/api/task-card-questions/[id]/answer/route.js +1 -1
  74. package/.next/server/app/api/task-card-questions/route.js +1 -1
  75. package/.next/server/app/api/task-cards/[id]/route.js +1 -1
  76. package/.next/server/app/api/task-cards/route.js +1 -1
  77. package/.next/server/app/api/task-scheduler/status/route.js +1 -1
  78. package/.next/server/app/api/tasks/[id]/board/route.js +1 -1
  79. package/.next/server/app/api/tasks/[id]/route.js +1 -1
  80. package/.next/server/app/api/tasks/reorder/route.js +1 -1
  81. package/.next/server/app/api/tasks/route.js +1 -1
  82. package/.next/server/app/api/terminal/[id]/events/route.js +2 -2
  83. package/.next/server/app/api/terminal/[id]/route.js +2 -2
  84. package/.next/server/app/api/terminal/route.js +2 -2
  85. package/.next/server/app/api/worktrees/route.js +2 -2
  86. package/.next/server/app/favicon.ico/route.js +1 -1
  87. package/.next/server/app/index.html +1 -1
  88. package/.next/server/app/index.rsc +5 -5
  89. package/.next/server/app/index.segments/__PAGE__.segment.rsc +5 -5
  90. package/.next/server/app/index.segments/_full.segment.rsc +5 -5
  91. package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  92. package/.next/server/app/manifest.webmanifest/route.js +2 -2
  93. package/.next/server/app/page.js +7 -7
  94. package/.next/server/app/page_client-reference-manifest.js +1 -1
  95. package/.next/server/app-paths-manifest.json +7 -12
  96. package/.next/server/chunks/1094.js +2 -2
  97. package/.next/server/chunks/1601.js +1 -1
  98. package/.next/server/chunks/1860.js +1 -1
  99. package/.next/server/chunks/2075.js +1 -1
  100. package/.next/server/chunks/2169.js +1 -1
  101. package/.next/server/chunks/2404.js +1 -1
  102. package/.next/server/chunks/2524.js +1 -0
  103. package/.next/server/chunks/3012.js +1 -1
  104. package/.next/server/chunks/{5760.js → 3379.js} +1 -1
  105. package/.next/server/chunks/3500.js +1 -1
  106. package/.next/server/chunks/4226.js +5 -2
  107. package/.next/server/chunks/4267.js +1 -1
  108. package/.next/server/chunks/4563.js +1 -1
  109. package/.next/server/chunks/5318.js +1 -1
  110. package/.next/server/chunks/542.js +3 -44
  111. package/.next/server/chunks/5794.js +1 -1
  112. package/.next/server/chunks/6052.js +1 -1
  113. package/.next/server/chunks/6253.js +1 -1
  114. package/.next/server/chunks/6288.js +1 -1
  115. package/.next/server/chunks/6366.js +1 -1
  116. package/.next/server/chunks/673.js +1 -1
  117. package/.next/server/chunks/6916.js +2 -2
  118. package/.next/server/chunks/7128.js +43 -0
  119. package/.next/server/chunks/7265.js +2 -2
  120. package/.next/server/chunks/7799.js +1 -1
  121. package/.next/server/chunks/8106.js +1 -1
  122. package/.next/server/chunks/8333.js +1 -1
  123. package/.next/server/chunks/8604.js +1 -1
  124. package/.next/server/chunks/861.js +1 -0
  125. package/.next/server/chunks/8713.js +1 -1
  126. package/.next/server/chunks/8782.js +2 -2
  127. package/.next/server/chunks/898.js +1 -1
  128. package/.next/server/chunks/922.js +2 -2
  129. package/.next/server/chunks/9280.js +6 -6
  130. package/.next/server/chunks/9510.js +1 -1
  131. package/.next/server/instrumentation.js +1 -1
  132. package/.next/server/instrumentation.js.nft.json +1 -1
  133. package/.next/server/middleware-build-manifest.js +1 -1
  134. package/.next/server/middleware-react-loadable-manifest.js +1 -1
  135. package/.next/server/pages/404.html +1 -1
  136. package/.next/server/pages/500.html +1 -1
  137. package/.next/server/server-reference-manifest.json +1 -1
  138. package/.next/static/chunks/{103.23142a67b02246a8.js → 103.6c91a059aa01d92c.js} +2 -2
  139. package/.next/static/chunks/{1032.12b382a9096ab2a4.js → 1032.9e8f793d46f463f8.js} +1 -1
  140. package/.next/static/chunks/{1063.775c442bdbeef08b.js → 1063.470df8a037dc8409.js} +1 -1
  141. package/.next/static/chunks/1a258343.f4fc2c133917ded8.js +2 -0
  142. package/.next/static/chunks/{1ba63609.b2ae90f43319a29e.js → 1ba63609.569928c7234f832c.js} +1 -1
  143. package/.next/static/chunks/{2181.ba21239d3ac39f81.js → 2181.b8dda21843ef5e74.js} +1 -1
  144. package/.next/static/chunks/{2325.23caf22075e51aa5.js → 2325.23e538886331cf64.js} +1 -1
  145. package/.next/static/chunks/{2356.523277bb8c6bf72a.js → 2356.b7312589c345edec.js} +1 -1
  146. package/.next/static/chunks/{268.72794ee2773c2060.js → 268.a1d90aca268be18a.js} +1 -1
  147. package/.next/static/chunks/{2695.6f49435bae1e6f33.js → 2695.5624aa3aae540e87.js} +1 -1
  148. package/.next/static/chunks/{2703.495a65ed14b2f094.js → 2703.097bc88286733740.js} +1 -1
  149. package/.next/static/chunks/{2821.934bcf60fbdc28c6.js → 2821.d2392a93d192fe92.js} +1 -1
  150. package/.next/static/chunks/3308.2cd6f20e6c0f4e92.js +73 -0
  151. package/.next/static/chunks/{3336.a76f9485fe7cb762.js → 3336.9b1dc9ec3507d64f.js} +1 -1
  152. package/.next/static/chunks/3546.779d2c7646aa77cc.js +1 -0
  153. package/.next/static/chunks/{370.8e8f3cf8eb0e29dd.js → 370.cde2a84caa84054f.js} +1 -1
  154. package/.next/static/chunks/{3716.72bf4c9d7325debd.js → 3716.5bac496cea32ca8f.js} +1 -1
  155. package/.next/static/chunks/{3995.eca0f5bef1fc3ae5.js → 3995.cd112debcd64c610.js} +1 -1
  156. package/.next/static/chunks/{4004.74b9bcf5478b1663.js → 4004.a8f79ef62f32aa30.js} +2 -2
  157. package/.next/static/chunks/{4202.8440832386f023c7.js → 4202.96f5b1beb8b3e3f5.js} +1 -1
  158. package/.next/static/chunks/{4238.6f102dcbcf2ae339.js → 4238.28efbf9aa0c82d90.js} +1 -1
  159. package/.next/static/chunks/{4405.7a19458960a1058e.js → 4405.cda46a596a02aef7.js} +1 -1
  160. package/.next/static/chunks/54a60aa6.5e4421e7afde4de8.js +78 -0
  161. package/.next/static/chunks/{6121.eb9023b1cbc78ee2.js → 6121.5e650e714b402b6f.js} +1 -1
  162. package/.next/static/chunks/{6195.1153369f5f8b13a2.js → 6195.1b7f9dc127381bbc.js} +1 -1
  163. package/.next/static/chunks/6380.d148a8e2c701ad78.js +68 -0
  164. package/.next/static/chunks/6582.fb2c709abc2c5981.js +1 -0
  165. package/.next/static/chunks/6be7e44c.00d0163f409986f0.js +1 -0
  166. package/.next/static/chunks/{7331.2add3c4e125a2dba.js → 7331.4afa66d6353c8e07.js} +1 -1
  167. package/.next/static/chunks/752.a05a2904b96af4d0.js +1 -0
  168. package/.next/static/chunks/{8200.a36b9f8c983c6b9e.js → 8200.350d650649b977eb.js} +1 -1
  169. package/.next/static/chunks/{8885.cf60cac98bf8b70c.js → 8885.2c060cb45c85547b.js} +1 -1
  170. package/.next/static/chunks/{918.6a9bbe564e4a2d0f.js → 918.593eb466d35cb8ad.js} +1 -1
  171. package/.next/static/chunks/{9698.4d09a99b9d99f3e5.js → 9698.758755d0387e0e22.js} +2 -2
  172. package/.next/static/chunks/97.fb73c551e14b3612.js +2 -0
  173. package/.next/static/chunks/{993e5495.8797001fcfcf2889.js → 993e5495.12cdfbc3af5c79e9.js} +1 -1
  174. package/.next/static/chunks/{9974.9a0f79beca65e8c4.js → 9974.5ee982e074ad047e.js} +1 -1
  175. package/.next/static/chunks/app/_global-error/page-bb8f79f321e26750.js +1 -0
  176. package/.next/static/chunks/app/api/agent/[id]/bash-output/route-bb8f79f321e26750.js +1 -0
  177. package/.next/static/chunks/app/api/agent/[id]/events/route-bb8f79f321e26750.js +1 -0
  178. package/.next/static/chunks/app/api/agent/[id]/route-bb8f79f321e26750.js +1 -0
  179. package/.next/static/chunks/app/api/agent/new/route-bb8f79f321e26750.js +1 -0
  180. package/.next/static/chunks/app/api/agent/running/route-bb8f79f321e26750.js +1 -0
  181. package/.next/static/chunks/app/api/app-update/route-bb8f79f321e26750.js +1 -0
  182. package/.next/static/chunks/app/api/auth/all-providers/route-bb8f79f321e26750.js +1 -0
  183. package/.next/static/chunks/app/api/auth/api-key/[provider]/route-bb8f79f321e26750.js +1 -0
  184. package/.next/static/chunks/app/api/auth/login/[provider]/route-bb8f79f321e26750.js +1 -0
  185. package/.next/static/chunks/app/api/auth/logout/[provider]/route-bb8f79f321e26750.js +1 -0
  186. package/.next/static/chunks/app/api/auth/providers/route-bb8f79f321e26750.js +1 -0
  187. package/.next/static/chunks/app/api/boards/[id]/reconcile/route-bb8f79f321e26750.js +1 -0
  188. package/.next/static/chunks/app/api/boards/[id]/route-bb8f79f321e26750.js +1 -0
  189. package/.next/static/chunks/app/api/boards/purge-orphans/route-bb8f79f321e26750.js +1 -0
  190. package/.next/static/chunks/app/api/boards/reorder/route-bb8f79f321e26750.js +1 -0
  191. package/.next/static/chunks/app/api/boards/route-bb8f79f321e26750.js +1 -0
  192. package/.next/static/chunks/app/api/cwd/browse/route-bb8f79f321e26750.js +1 -0
  193. package/.next/static/chunks/app/api/cwd/validate/route-bb8f79f321e26750.js +1 -0
  194. package/.next/static/chunks/app/api/default-cwd/route-bb8f79f321e26750.js +1 -0
  195. package/.next/static/chunks/app/api/file-index/route-bb8f79f321e26750.js +1 -0
  196. package/.next/static/chunks/app/api/files/[...path]/route-bb8f79f321e26750.js +1 -0
  197. package/.next/static/chunks/app/api/git/diff/route-bb8f79f321e26750.js +1 -0
  198. package/.next/static/chunks/app/api/git/status/route-bb8f79f321e26750.js +1 -0
  199. package/.next/static/chunks/app/api/home/route-bb8f79f321e26750.js +1 -0
  200. package/.next/static/chunks/app/api/mcp/route-bb8f79f321e26750.js +1 -0
  201. package/.next/static/chunks/app/api/models/route-bb8f79f321e26750.js +1 -0
  202. package/.next/static/chunks/app/api/models-config/catalog/route-bb8f79f321e26750.js +1 -0
  203. package/.next/static/chunks/app/api/models-config/discover/route-bb8f79f321e26750.js +1 -0
  204. package/.next/static/chunks/app/api/models-config/route-bb8f79f321e26750.js +1 -0
  205. package/.next/static/chunks/app/api/models-config/test/route-bb8f79f321e26750.js +1 -0
  206. package/.next/static/chunks/app/api/plugins/route-bb8f79f321e26750.js +1 -0
  207. package/.next/static/chunks/app/api/project-trust/route-bb8f79f321e26750.js +1 -0
  208. package/.next/static/chunks/app/api/quota/route-bb8f79f321e26750.js +1 -0
  209. package/.next/static/chunks/app/api/search/route-bb8f79f321e26750.js +1 -0
  210. package/.next/static/chunks/app/api/sessions/[id]/auto-name/route-bb8f79f321e26750.js +1 -0
  211. package/.next/static/chunks/app/api/sessions/[id]/context/route-bb8f79f321e26750.js +1 -0
  212. package/.next/static/chunks/app/api/sessions/[id]/entries/[entryId]/thinking/route-bb8f79f321e26750.js +1 -0
  213. package/.next/static/chunks/app/api/sessions/[id]/export/route-bb8f79f321e26750.js +1 -0
  214. package/.next/static/chunks/app/api/sessions/[id]/route-bb8f79f321e26750.js +1 -0
  215. package/.next/static/chunks/app/api/sessions/[id]/state/route-bb8f79f321e26750.js +1 -0
  216. package/.next/static/chunks/app/api/sessions/[id]/todos/route-bb8f79f321e26750.js +1 -0
  217. package/.next/static/chunks/app/api/sessions/route-bb8f79f321e26750.js +1 -0
  218. package/.next/static/chunks/app/api/skills/check/route-bb8f79f321e26750.js +1 -0
  219. package/.next/static/chunks/app/api/skills/install/route-bb8f79f321e26750.js +1 -0
  220. package/.next/static/chunks/app/api/skills/route-bb8f79f321e26750.js +1 -0
  221. package/.next/static/chunks/app/api/skills/search/route-bb8f79f321e26750.js +1 -0
  222. package/.next/static/chunks/app/api/skills/update/route-bb8f79f321e26750.js +1 -0
  223. package/.next/static/chunks/app/api/task-card-questions/[id]/answer/route-bb8f79f321e26750.js +1 -0
  224. package/.next/static/chunks/app/api/task-card-questions/route-bb8f79f321e26750.js +1 -0
  225. package/.next/static/chunks/app/api/task-cards/[id]/route-bb8f79f321e26750.js +1 -0
  226. package/.next/static/chunks/app/api/task-cards/route-bb8f79f321e26750.js +1 -0
  227. package/.next/static/chunks/app/api/task-scheduler/status/route-bb8f79f321e26750.js +1 -0
  228. package/.next/static/chunks/app/api/tasks/[id]/board/route-bb8f79f321e26750.js +1 -0
  229. package/.next/static/chunks/app/api/tasks/[id]/route-bb8f79f321e26750.js +1 -0
  230. package/.next/static/chunks/app/api/tasks/reorder/route-bb8f79f321e26750.js +1 -0
  231. package/.next/static/chunks/app/api/tasks/route-bb8f79f321e26750.js +1 -0
  232. package/.next/static/chunks/app/api/terminal/[id]/events/route-bb8f79f321e26750.js +1 -0
  233. package/.next/static/chunks/app/api/terminal/[id]/route-bb8f79f321e26750.js +1 -0
  234. package/.next/static/chunks/app/api/terminal/route-bb8f79f321e26750.js +1 -0
  235. package/.next/static/chunks/app/api/worktrees/route-bb8f79f321e26750.js +1 -0
  236. package/.next/static/chunks/app/{layout-7761e430ed68b347.js → layout-2bec2662143a3d1b.js} +1 -1
  237. package/.next/static/chunks/app/manifest.webmanifest/route-bb8f79f321e26750.js +1 -0
  238. package/.next/static/chunks/app/page-e38c6cf3174fa143.js +89 -0
  239. package/.next/static/chunks/next/dist/client/components/builtin/app-error-bb8f79f321e26750.js +1 -0
  240. package/.next/static/chunks/next/dist/client/components/builtin/forbidden-bb8f79f321e26750.js +1 -0
  241. package/.next/static/chunks/next/dist/client/components/builtin/not-found-bb8f79f321e26750.js +1 -0
  242. package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-bb8f79f321e26750.js +1 -0
  243. package/.next/static/chunks/webpack-b4924d2a22ad3650.js +1 -0
  244. package/.next/static/css/0c7244f7214af81f.css +1 -0
  245. package/.next/static/css/12456255969ac8de.css +31 -0
  246. package/.next/trace +8 -49
  247. package/.next/trace-build +1 -1
  248. package/.next/types/app/api/boards/[id]/{reconcile-task-edges → reconcile}/route.ts +3 -3
  249. package/.next/types/routes.d.ts +2 -7
  250. package/.next/types/validator.ts +3 -48
  251. package/README.md +6 -9
  252. package/THIRD_PARTY_NOTICES.md +10 -82
  253. package/bin/pi-web-sky.js +3 -3
  254. package/lib/board-reconcile-scheduler.ts +56 -0
  255. package/lib/board-reconcile.test.mjs +252 -0
  256. package/lib/board-reconcile.ts +421 -0
  257. package/lib/board-store.test.mjs +26 -4
  258. package/lib/board-store.ts +44 -6
  259. package/lib/board-types.ts +7 -2
  260. package/lib/i18n/messages/en.ts +1 -1
  261. package/lib/i18n/messages/zh-CN.ts +1 -1
  262. package/lib/session-delete.ts +5 -0
  263. package/lib/sqlite-db.ts +13 -1
  264. package/lib/task-card-store.test.mjs +16 -1
  265. package/lib/task-card-store.ts +37 -1
  266. package/lib/task-scheduler.test.mjs +79 -0
  267. package/lib/task-scheduler.ts +195 -21
  268. package/lib/yjs-room-server.mjs +139 -0
  269. package/package.json +12 -9
  270. package/server.mjs +7 -7
  271. package/.next/server/app/api/boards/[id]/canvas/route.js +0 -1
  272. package/.next/server/app/api/boards/[id]/canvas/route_client-reference-manifest.js +0 -1
  273. package/.next/server/app/api/boards/[id]/edges/[eid]/route.js +0 -1
  274. package/.next/server/app/api/boards/[id]/edges/[eid]/route.js.nft.json +0 -1
  275. package/.next/server/app/api/boards/[id]/edges/[eid]/route_client-reference-manifest.js +0 -1
  276. package/.next/server/app/api/boards/[id]/edges/route.js +0 -1
  277. package/.next/server/app/api/boards/[id]/edges/route.js.nft.json +0 -1
  278. package/.next/server/app/api/boards/[id]/edges/route_client-reference-manifest.js +0 -1
  279. package/.next/server/app/api/boards/[id]/nodes/[nid]/route.js +0 -1
  280. package/.next/server/app/api/boards/[id]/nodes/[nid]/route.js.nft.json +0 -1
  281. package/.next/server/app/api/boards/[id]/nodes/[nid]/route_client-reference-manifest.js +0 -1
  282. package/.next/server/app/api/boards/[id]/nodes/route.js +0 -1
  283. package/.next/server/app/api/boards/[id]/nodes/route.js.nft.json +0 -1
  284. package/.next/server/app/api/boards/[id]/nodes/route_client-reference-manifest.js +0 -1
  285. package/.next/server/app/api/boards/[id]/reconcile-task-edges/route.js +0 -1
  286. package/.next/server/app/api/boards/[id]/reconcile-task-edges/route.js.nft.json +0 -1
  287. package/.next/server/app/api/boards/[id]/reconcile-task-edges/route_client-reference-manifest.js +0 -1
  288. package/.next/static/chunks/3308.857c554428b3294e.js +0 -73
  289. package/.next/static/chunks/333.bf0651c789b2eb33.js +0 -1
  290. package/.next/static/chunks/5315.dba7515ae6e139ae.js +0 -4
  291. package/.next/static/chunks/54a60aa6.0e43cde7298ebcb7.js +0 -78
  292. package/.next/static/chunks/7999.879d5a20e8641752.js +0 -259
  293. package/.next/static/chunks/app/_global-error/page-d6f52627eddf9119.js +0 -1
  294. package/.next/static/chunks/app/api/agent/[id]/bash-output/route-d6f52627eddf9119.js +0 -1
  295. package/.next/static/chunks/app/api/agent/[id]/events/route-d6f52627eddf9119.js +0 -1
  296. package/.next/static/chunks/app/api/agent/[id]/route-d6f52627eddf9119.js +0 -1
  297. package/.next/static/chunks/app/api/agent/new/route-d6f52627eddf9119.js +0 -1
  298. package/.next/static/chunks/app/api/agent/running/route-d6f52627eddf9119.js +0 -1
  299. package/.next/static/chunks/app/api/app-update/route-d6f52627eddf9119.js +0 -1
  300. package/.next/static/chunks/app/api/auth/all-providers/route-d6f52627eddf9119.js +0 -1
  301. package/.next/static/chunks/app/api/auth/api-key/[provider]/route-d6f52627eddf9119.js +0 -1
  302. package/.next/static/chunks/app/api/auth/login/[provider]/route-d6f52627eddf9119.js +0 -1
  303. package/.next/static/chunks/app/api/auth/logout/[provider]/route-d6f52627eddf9119.js +0 -1
  304. package/.next/static/chunks/app/api/auth/providers/route-d6f52627eddf9119.js +0 -1
  305. package/.next/static/chunks/app/api/boards/[id]/canvas/route-d6f52627eddf9119.js +0 -1
  306. package/.next/static/chunks/app/api/boards/[id]/edges/[eid]/route-d6f52627eddf9119.js +0 -1
  307. package/.next/static/chunks/app/api/boards/[id]/edges/route-d6f52627eddf9119.js +0 -1
  308. package/.next/static/chunks/app/api/boards/[id]/nodes/[nid]/route-d6f52627eddf9119.js +0 -1
  309. package/.next/static/chunks/app/api/boards/[id]/nodes/route-d6f52627eddf9119.js +0 -1
  310. package/.next/static/chunks/app/api/boards/[id]/reconcile-task-edges/route-d6f52627eddf9119.js +0 -1
  311. package/.next/static/chunks/app/api/boards/[id]/route-d6f52627eddf9119.js +0 -1
  312. package/.next/static/chunks/app/api/boards/purge-orphans/route-d6f52627eddf9119.js +0 -1
  313. package/.next/static/chunks/app/api/boards/reorder/route-d6f52627eddf9119.js +0 -1
  314. package/.next/static/chunks/app/api/boards/route-d6f52627eddf9119.js +0 -1
  315. package/.next/static/chunks/app/api/cwd/browse/route-d6f52627eddf9119.js +0 -1
  316. package/.next/static/chunks/app/api/cwd/validate/route-d6f52627eddf9119.js +0 -1
  317. package/.next/static/chunks/app/api/default-cwd/route-d6f52627eddf9119.js +0 -1
  318. package/.next/static/chunks/app/api/file-index/route-d6f52627eddf9119.js +0 -1
  319. package/.next/static/chunks/app/api/files/[...path]/route-d6f52627eddf9119.js +0 -1
  320. package/.next/static/chunks/app/api/git/diff/route-d6f52627eddf9119.js +0 -1
  321. package/.next/static/chunks/app/api/git/status/route-d6f52627eddf9119.js +0 -1
  322. package/.next/static/chunks/app/api/home/route-d6f52627eddf9119.js +0 -1
  323. package/.next/static/chunks/app/api/mcp/route-d6f52627eddf9119.js +0 -1
  324. package/.next/static/chunks/app/api/models/route-d6f52627eddf9119.js +0 -1
  325. package/.next/static/chunks/app/api/models-config/catalog/route-d6f52627eddf9119.js +0 -1
  326. package/.next/static/chunks/app/api/models-config/discover/route-d6f52627eddf9119.js +0 -1
  327. package/.next/static/chunks/app/api/models-config/route-d6f52627eddf9119.js +0 -1
  328. package/.next/static/chunks/app/api/models-config/test/route-d6f52627eddf9119.js +0 -1
  329. package/.next/static/chunks/app/api/plugins/route-d6f52627eddf9119.js +0 -1
  330. package/.next/static/chunks/app/api/project-trust/route-d6f52627eddf9119.js +0 -1
  331. package/.next/static/chunks/app/api/quota/route-d6f52627eddf9119.js +0 -1
  332. package/.next/static/chunks/app/api/search/route-d6f52627eddf9119.js +0 -1
  333. package/.next/static/chunks/app/api/sessions/[id]/auto-name/route-d6f52627eddf9119.js +0 -1
  334. package/.next/static/chunks/app/api/sessions/[id]/context/route-d6f52627eddf9119.js +0 -1
  335. package/.next/static/chunks/app/api/sessions/[id]/entries/[entryId]/thinking/route-d6f52627eddf9119.js +0 -1
  336. package/.next/static/chunks/app/api/sessions/[id]/export/route-d6f52627eddf9119.js +0 -1
  337. package/.next/static/chunks/app/api/sessions/[id]/route-d6f52627eddf9119.js +0 -1
  338. package/.next/static/chunks/app/api/sessions/[id]/state/route-d6f52627eddf9119.js +0 -1
  339. package/.next/static/chunks/app/api/sessions/[id]/todos/route-d6f52627eddf9119.js +0 -1
  340. package/.next/static/chunks/app/api/sessions/route-d6f52627eddf9119.js +0 -1
  341. package/.next/static/chunks/app/api/skills/check/route-d6f52627eddf9119.js +0 -1
  342. package/.next/static/chunks/app/api/skills/install/route-d6f52627eddf9119.js +0 -1
  343. package/.next/static/chunks/app/api/skills/route-d6f52627eddf9119.js +0 -1
  344. package/.next/static/chunks/app/api/skills/search/route-d6f52627eddf9119.js +0 -1
  345. package/.next/static/chunks/app/api/skills/update/route-d6f52627eddf9119.js +0 -1
  346. package/.next/static/chunks/app/api/task-card-questions/[id]/answer/route-d6f52627eddf9119.js +0 -1
  347. package/.next/static/chunks/app/api/task-card-questions/route-d6f52627eddf9119.js +0 -1
  348. package/.next/static/chunks/app/api/task-cards/[id]/route-d6f52627eddf9119.js +0 -1
  349. package/.next/static/chunks/app/api/task-cards/route-d6f52627eddf9119.js +0 -1
  350. package/.next/static/chunks/app/api/task-scheduler/status/route-d6f52627eddf9119.js +0 -1
  351. package/.next/static/chunks/app/api/tasks/[id]/board/route-d6f52627eddf9119.js +0 -1
  352. package/.next/static/chunks/app/api/tasks/[id]/route-d6f52627eddf9119.js +0 -1
  353. package/.next/static/chunks/app/api/tasks/reorder/route-d6f52627eddf9119.js +0 -1
  354. package/.next/static/chunks/app/api/tasks/route-d6f52627eddf9119.js +0 -1
  355. package/.next/static/chunks/app/api/terminal/[id]/events/route-d6f52627eddf9119.js +0 -1
  356. package/.next/static/chunks/app/api/terminal/[id]/route-d6f52627eddf9119.js +0 -1
  357. package/.next/static/chunks/app/api/terminal/route-d6f52627eddf9119.js +0 -1
  358. package/.next/static/chunks/app/api/worktrees/route-d6f52627eddf9119.js +0 -1
  359. package/.next/static/chunks/app/manifest.webmanifest/route-d6f52627eddf9119.js +0 -1
  360. package/.next/static/chunks/app/page-2c87c41e7f848f45.js +0 -89
  361. package/.next/static/chunks/e3e7ddb2.a35db430b3564999.js +0 -1
  362. package/.next/static/chunks/next/dist/client/components/builtin/app-error-d6f52627eddf9119.js +0 -1
  363. package/.next/static/chunks/next/dist/client/components/builtin/forbidden-d6f52627eddf9119.js +0 -1
  364. package/.next/static/chunks/next/dist/client/components/builtin/not-found-d6f52627eddf9119.js +0 -1
  365. package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-d6f52627eddf9119.js +0 -1
  366. package/.next/static/chunks/webpack-4bbf04891e910713.js +0 -1
  367. package/.next/static/css/80c818c5781fbadc.css +0 -4
  368. package/.next/static/css/d3a2b5077b52c727.css +0 -1
  369. package/.next/types/app/api/boards/[id]/canvas/route.ts +0 -353
  370. package/.next/types/app/api/boards/[id]/edges/[eid]/route.ts +0 -353
  371. package/.next/types/app/api/boards/[id]/edges/route.ts +0 -353
  372. package/.next/types/app/api/boards/[id]/nodes/[nid]/route.ts +0 -353
  373. package/.next/types/app/api/boards/[id]/nodes/route.ts +0 -353
  374. package/lib/board-search.test.mjs +0 -110
  375. package/lib/board-search.ts +0 -63
  376. package/lib/file-explorer-state.test.mjs +0 -63
  377. package/lib/file-explorer-state.ts +0 -36
  378. package/lib/sync-room-server.mjs +0 -137
  379. /package/.next/server/app/api/boards/[id]/{canvas → reconcile}/route.js.nft.json +0 -0
  380. /package/.next/static/{IzmOG04jJst1VpUvr_fr5 → 8V884w_cp5HEp_rRpjnCR}/_buildManifest.js +0 -0
  381. /package/.next/static/{IzmOG04jJst1VpUvr_fr5 → 8V884w_cp5HEp_rRpjnCR}/_ssgManifest.js +0 -0
@@ -1,259 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7999],{1015:(e,t,n)=>{"use strict";n.d(t,{p:()=>a,t:()=>s});var r=n(95155),i=n(12115);let o={error:null};class s extends i.Component{static getDerivedStateFromError(e){return{error:e}}state=o;componentDidCatch(e){this.props.onError?.(e)}render(){let{error:e}=this.state;if(null!==e){let{fallback:t}=this.props;return(0,r.jsx)(t,{error:e})}return this.props.children}}function a({children:e,fallback:t,...n}){return null===t?e:(0,r.jsx)(s,{fallback:t,...n,children:e})}},1793:(e,t,n)=>{"use strict";n.d(t,{V:()=>s});var r=n(83102),i=n(24167);function o(e){let t=e.get(),n=new Map;for(let e of t){let{fromId:t,toId:r}=e,i=n.get(t);i?i.push(e):n.set(t,[e]);let o=n.get(r);o?o.push(e):n.set(r,[e])}return n}function s(e){let{store:t}=e,n=t.query.filterHistory("binding"),s=t.query.records("binding");return(0,r.EW)("arrowBindingsIndex",(e,t)=>{let a;if((0,r._O)(e))return o(s);let l=n.getDiffSince(t);if(l===r.c2)return o(s);function d(t){let n=(a??=new Map(e)).get(t.fromId),r=n?.filter(e=>e.id!==t.id);r?.length?a.set(t.fromId,r):a.delete(t.fromId);let i=a.get(t.toId),o=i?.filter(e=>e.id!==t.id);o?.length?a.set(t.toId,o):a.delete(t.toId)}function c(t){let n=(a??=new Map(e)).get(t);return n?n===e.get(t)&&(n=n.slice(0),a.set(t,n)):(n=[],a.set(t,n)),n}function h(e){c(e.fromId).push(e),c(e.toId).push(e)}for(let e of l){for(let t of(0,i.Ic)(e.added))h(t);for(let[t,n]of(0,i.Ic)(e.updated))d(t),h(n);for(let t of(0,i.Ic)(e.removed))d(t)}return a??e})}},1933:(e,t,n)=>{"use strict";n.d(t,{jH:()=>s});var r=n(12115);n(95155);var i=Object.defineProperty,o=r.createContext(void 0);function s(e){let t=r.useContext(o);return e||t||"ltr"}i(s,"name",{value:"useDirection",configurable:!0})},2311:(e,t,n)=>{"use strict";let r;n.d(t,{W:()=>ei});var i=n(24167),o=n(47650),s=n(12669),a=n(48077);function l(e,t){let n=new i.Qn(100);return async function(r){let o=n.get(r);if(o)return o;let s=(async()=>{try{let n=await (0,i.hd)(r,t);return(0,i.vA)(n.ok),await e(n)}catch(e){return console.error(e),null}})();return n.set(r,s),s}}let d=l(async e=>await i.Sm.blobToDataUrl(await e.blob()));function c(e,t){return e.replaceWith(t),t}async function h(e,t,n){let r=e.createElement("img");n&&Array.from(n.attributes).forEach(e=>{r.setAttribute(e.name,e.value)}),r.setAttribute("src",t??"data:"),r.setAttribute("decoding","sync"),r.setAttribute("loading","eager");try{await r.decode()}catch{}return r}async function u(e){let t=e.ownerDocument;try{let n=e.toDataURL();return await h(t,n,e)}catch{return await h(t,null,e)}}async function p(e){let t=e.ownerDocument;try{let n=await i.K4.getVideoFrameAsDataUrl(e);return h(t,n,e)}catch(e){console.error("Could not get video frame",e)}return e.poster?h(t,await d(e.poster),e):h(t,null,e)}async function f(e){let t=(0,a.mD)(e);if(e instanceof t.HTMLCanvasElement)return c(e,await u(e));if(e instanceof t.HTMLVideoElement)return c(e,await p(e));if(e instanceof t.HTMLImageElement){let t=e.currentSrc||e.src,n=await d(t);e.setAttribute("src",n??"data:"),e.setAttribute("decoding","sync"),e.setAttribute("loading","eager");try{await e.decode()}catch{}return e}e instanceof t.HTMLInputElement?e.setAttribute("value",e.value):e instanceof t.HTMLTextAreaElement&&(e.textContent=e.value);await Promise.all(Array.from((0,a.$3)(e),e=>f(e)))}let g=/@import\s+(?:"([^"]+)"|'([^']+)'|url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\))([^;]+);/gi,m=/@font-face\s*{([^}]+)}/gi,y=/url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\)/gi,b=/(?:^|;)\s*font-family\s*:\s*(?:([^'"][^;\n]+)|"([^"]+)"|'([^']+)')\s*(?:;|$)/gi;function x(e,t){return Array.from(e.matchAll(m),e=>{let n=e[1],r=Array.from(n.matchAll(y),e=>{let n=e[1]||e[2]||e[3];return{original:n,resolved:(0,i.yC)(n,t)?.href??null}}),o=new Set(Array.from(n.matchAll(b),e=>(e[1]||e[2]||e[3]).toLowerCase()));return{fontFace:n,urls:r,fontFamilies:o}})}function w(e){return!(e.startsWith("-")||e.startsWith("animation")||e.startsWith("transition"))&&"cursor"!==e&&"pointer-events"!==e&&"user-select"!==e&&"touch-action"!==e}var v=Object.defineProperty,S=Object.getOwnPropertyDescriptor;let C="tldraw-svg-export";class k{fontFacesPromise=null;foundFontNames=new Set;fontFacesToEmbed=new Set;pendingPromises=[];startFindingDocumentFontFaces(e){(0,i.vA)(!this.fontFacesPromise,"FontEmbedder already started"),this.fontFacesPromise=P(e)}onFontFamilyValue(e){for(let t of((0,i.vA)(this.fontFacesPromise,"FontEmbedder not started"),function(e){let t=/\s*(?:([^'"][^;\n\s,]+)|"([^"]+)"|'([^']+)')\s*/gi,n=/\s*,\s*/gi,r=new Set;for(;;){let i=t.exec(e);if(!i)break;let o=i[1]||i[2]||i[3];if(r.add(o.toLowerCase()),n.lastIndex=t.lastIndex,!n.exec(e))break;t.lastIndex=n.lastIndex}return r}(e))){if(this.foundFontNames.has(t))return;this.foundFontNames.add(t),this.pendingPromises.push(this.fontFacesPromise.then(e=>{for(let n of e.filter(e=>e.fontFamilies.has(t)))if(!this.fontFacesToEmbed.has(n))for(let e of(this.fontFacesToEmbed.add(n),n.urls))e.resolved&&!e.embedded&&(e.embedded=d(e.resolved))}))}}async createCss(){await Promise.all(this.pendingPromises);let e="";for(let t of this.fontFacesToEmbed){let n=`@font-face {${t.fontFace}}`;for(let e of t.urls){if(!e.embedded)continue;let t=await e.embedded;t&&(n=n.replace(e.original,t))}e+=n}return e}}async function P(e){let t=e.defaultView??globalThis,n=[];for(let r of Array.from(e.styleSheets).filter(e=>!e.ownerNode?.closest(`.${C}`))){let i;try{i=r.cssRules}catch{}if(i){for(let i of r.cssRules)if(i instanceof t.CSSFontFaceRule)n.push(x(i.cssText,r.href??e.baseURI));else if(i instanceof t.CSSImportRule){let t=new URL(i.href,i.parentStyleSheet?.href??e.baseURI);n.push(T(t.href))}}else r.href&&n.push(T(r.href))}return(0,i.oE)(await Promise.all(n)).flat()}((e,t,n)=>{for(var r,i=S(t,n),o=e.length-1;o>=0;o--)(r=e[o])&&(i=r(t,n,i)||i);return i&&v(t,n,i)})([i.oI],k.prototype,"onFontFamilyValue");let T=l(async e=>{var t,n;let r=(t=await e.text(),n=e.url,{imports:Array.from(t.matchAll(g),e=>({url:e[1]||e[2]||e[3]||e[4]||e[5],extras:e[6]})),fontFaces:x(t,n)}),o=await Promise.all(r.imports.map(({url:t})=>T(new URL(t,e.url).href)));return[...r.fontFaces,...(0,i.oE)(o).flat()]});var E=n(95155),I=n(27394),_=n(12115),M=n(1015),A=n(22036),j=n(19743),O=n(50585),D=n(67863),L=n(18314),R=n(73352),F=n(59830),z=n(54939),N=Object.defineProperty,$=Object.getOwnPropertyDescriptor;class B{constructor(e){this.maxDelayTimeMs=e}maxDelayTimeMs;isResolved=!1;promisesToWaitFor=[];waitUntil(e){if(this.isResolved)throw Error("Cannot `waitUntil` - the export has already been resolved. Make sure to call `waitUntil` as soon as possible during an export - ie within the first react effect after rendering.");this.promisesToWaitFor.push(e.catch(e=>console.error("Error while waiting for export:",e)))}async resolvePromises(){let e=null;for(;this.promisesToWaitFor.length!==e;)e=this.promisesToWaitFor.length,await Promise.allSettled(this.promisesToWaitFor),await (0,i.yy)(0)}async resolve(){let e=(0,i.yy)(this.maxDelayTimeMs).then(()=>"timeout"),t=this.resolvePromises().then(()=>"resolved");"timeout"===await Promise.race([e,t])&&console.warn("[tldraw] Export delay timed out after ${this.maxDelayTimeMs}ms"),this.isResolved=!0}}function H({editor:e,preserveAspectRatio:t,scale:n,pixelRatio:r,bbox:s,background:a,singleFrameShapeId:l,isDarkMode:d,colorMode:c,renderingShapes:h,onMount:u,waitUntil:p}){let f=(0,R.Ls)(),g=e.getCurrentTheme(),m=(0,I.fp)("export state",{defsById:{},shapeElements:null}),{defsById:y,shapeElements:b}=(0,I.h)(m),x=(0,L._)(e=>{m.update(t=>{if((0,i.mQ)(t.defsById,e.key))return t;let n=Promise.resolve(e.getElement());return p(n.then(t=>{m.update(n=>({...n,defsById:{...n.defsById,[e.key]:{pending:!1,element:t}}}))})),{...t,defsById:{...t.defsById,[e.key]:{pending:!0,element:n}}}})}),w=(0,_.useMemo)(()=>({isDarkMode:d,colorMode:c,waitUntil:p,addExportDef:x,scale:n,pixelRatio:r,async resolveAssetUrl(t,i){let o=e.getAsset(t);return o&&("image"===o.type||"video"===o.type)?await e.resolveAssetUrl(t,{screenScale:n*(i/o.props.w),shouldResolveToOriginal:null===r,dpr:r??void 0}):null}}),[d,c,p,x,n,r,e]),v=(0,_.useRef)(!1);(0,_.useLayoutEffect)(()=>{if(v.current)throw Error("SvgExport should only render once - do not use with react strict mode");v.current=!0,(async()=>{let t={},n=h.map(async({id:n,opacity:r,index:i,backgroundIndex:o})=>{if(n===l)return[];let a=e.getShape(n);if(e.isShapeOfType(a,"group"))return[];let d=[],c=e.getShapeUtil(a);if(c.toSvg||c.toBackgroundSvg){let[n,s]=await Promise.all([c.toSvg?.(a,w),c.toBackgroundSvg?.(a,w)]),l=e.getShapePageTransform(a),h=l.toCssString(),u=1;"scale"in a.props&&1!==a.props.scale&&(u=a.props.scale,h=`${h} scale(${a.props.scale}, ${a.props.scale})`);let p=e.getShapeMask(a.id),g=p?z.V.From(z.V.Inverse(l)).applyToPoints(p):null,m=(0,R.oX)(f,a.id);g&&(t[m]={pending:!1,element:(0,E.jsx)("clipPath",{id:m,children:(0,E.jsx)("path",{d:`M${g.map(({x:e,y:t})=>`${e/u},${t/u}`).join("L")}Z`})})}),n&&d.push({zIndex:i,element:(0,E.jsx)("g",{transform:h,opacity:r,clipPath:p?`url(#${m})`:void 0,children:n},`fg_${a.id}`)}),s&&d.push({zIndex:o,element:(0,E.jsx)("g",{transform:h,opacity:r,clipPath:p?`url(#${m})`:void 0,children:s},`bg_${a.id}`)})}else d.push({zIndex:i,element:(0,E.jsx)(U,{shape:a,util:c,component:A.Gq,className:"tl-shape",bbox:s,opacity:r},`fg_${a.id}`)}),c.backgroundComponent&&d.push({zIndex:o,element:(0,E.jsx)(U,{shape:a,util:c,component:A.u0,className:"tl-shape tl-shape-background",bbox:s,opacity:r},`bg_${a.id}`)});return d}),r=(await Promise.all(n)).flat();(0,o.flushSync)(()=>{m.update(e=>({...e,shapeElements:r.sort((e,t)=>e.zIndex-t.zIndex).map(({element:e})=>e),defsById:{...e.defsById,...t}}))})})()},[s,e,w,f,h,l,m]),(0,_.useEffect)(()=>{let t=new Set;for(let{id:n}of h)for(let r of e.fonts.getShapeFontFaces(n))t.add(r);for(let n of t)x({key:(0,i.NF)(),getElement:async()=>{let t=await e.fonts.toEmbeddedCssDeclaration(n);return(0,E.jsx)("style",{nonce:e.options.nonce,children:t})}})},[e,h,x]),(0,_.useEffect)(()=>{null!==b&&u()},[u,b]);let S=g.colors[c],C=a?S.background:"transparent";if(l&&a){let t=e.getShapeUtil("frame");if(t?.options.showColors){let t=e.getShape(l);C=(0,j.F)(S,t.props.color,"frameFill")}else C=S.solid}return(0,E.jsx)(O.Bb,{editor:e,context:w,children:(0,E.jsxs)("svg",{preserveAspectRatio:t,direction:"ltr",width:s.width*n,height:s.height*n,viewBox:`${s.minX} ${s.minY} ${s.width} ${s.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:C},"data-color-mode":d?"dark":"light",className:`tl-container tl-theme__force-sRGB ${d?"tl-theme__dark":"tl-theme__light"}`,children:[(0,E.jsx)("defs",{children:Object.entries(y).map(([e,t])=>t.pending?null:(0,E.jsx)(_.Fragment,{children:t.element},e))}),b]})})}function U({shape:e,util:t,className:n,component:r,bbox:i,opacity:o}){let s=(0,D.hG)(),a=z.V.Translate(-i.minX,-i.minY).multiply(s.getShapePageTransform(e.id)),l=s.getShapeGeometry(e.id).bounds,d=Math.max(l.width,1),c=Math.max(l.height,1);return(0,E.jsx)(M.t,{fallback:()=>null,children:(0,E.jsx)("foreignObject",{x:i.minX,y:i.minY,width:i.w,height:i.h,className:"tl-shape-foreign-object tl-export-embed-styles",children:(0,E.jsx)("div",{className:n,"data-shape-type":e.type,style:{clipPath:s.getShapeClipPath(e.id),transform:a.toCssString(),width:d,height:c,opacity:o},children:(0,E.jsx)(r,{shape:e,util:t})})})})}((e,t,n)=>{for(var r,i=$(t,n),o=e.length-1;o>=0;o--)(r=e[o])&&(i=r(t,n,i)||i);return i&&N(t,n,i)})([i.oI],B.prototype,"waitUntil");let K=(e,t,{currentColor:n})=>"currentColor"===e||e===n,W=(e,t,{parentStyles:n})=>n[t]===e,V=e=>(t,n,{getStyle:r})=>{let i=r(`border-${e}-width`),o=r(`border-${e}-style`);return"0px"===i||"none"===o},Y={"border-block-end-color":K,"border-block-start-color":K,"border-bottom-color":K,"border-inline-end-color":K,"border-inline-start-color":K,"border-left-color":K,"border-right-color":K,"border-top-color":K,"caret-color":K,"column-rule-color":K,"outline-color":K,"text-decoration":(e,t,{currentColor:n})=>"none solid currentColor"===e||e==="none solid "+n,"text-decoration-color":K,"text-emphasis-color":K,"border-collapse":W,"border-spacing":W,"caption-side":W,cursor:W,direction:W,"empty-cells":W,"font-family":W,"font-size":W,"font-style":W,"font-variant":W,"font-weight":W,"font-size-adjust":W,"font-stretch":W,font:W,"letter-spacing":W,"line-height":W,"list-style-image":W,"list-style-position":W,"list-style-type":W,"list-style":W,orphans:W,"overflow-wrap":W,quotes:W,"stroke-linecap":W,"stroke-linejoin":W,"tab-size":W,"text-align":W,"text-align-last":W,"text-indent":W,"text-justify":W,"text-shadow":W,"text-transform":W,visibility:W,"white-space":W,"white-space-collapse":W,widows:W,"word-break":W,"word-spacing":W,"word-wrap":W,"border-top":V("top"),"border-right":V("right"),"border-bottom":V("bottom"),"border-left":V("left"),"border-block-end":V("block-end"),"border-block-start":V("block-start"),"border-inline-end":V("inline-end"),"border-inline-start":V("inline-start"),"border-top-style":V("top"),"border-right-style":V("right"),"border-bottom-style":V("bottom"),"border-left-style":V("left"),"border-block-end-style":V("block-end"),"border-block-start-style":V("block-start"),"border-inline-end-style":V("inline-end"),"border-inline-start-style":V("inline-start"),"border-top-width":V("top"),"border-right-width":V("right"),"border-bottom-width":V("bottom"),"border-left-width":V("left"),"border-block-end-width":V("block-end"),"border-block-start-width":V("block-start"),"border-inline-end-width":V("inline-end")},G={};class q{constructor(e){this.root=e}root;styles=new Map;fonts=new k;readRootElementStyles(e){this.readElementStyles(e,{shouldRespectDefaults:!1,shouldSkipInheritedParentStyles:!1});let t=Array.from((0,a.$3)(e));for(;t.length;){let e=t.pop();t.push(...(0,a.$3)(e)),this.readElementStyles(e,{shouldRespectDefaults:!0,shouldSkipInheritedParentStyles:!0})}}readElementStyles(e,{shouldRespectDefaults:t=!0,shouldSkipInheritedParentStyles:n=!0}){let o=t?function(e,t){let n=ee[t];if(!n){let{foreignObject:o,document:s}=function(e){if(!r||r.ownerDocument!==e){et();let t=e.createElement("iframe");t.style.display="none",e.body.appendChild(t);let n=(0,i.Z1)(t.contentDocument,"frame must have a document"),o=n.createElementNS("http://www.w3.org/2000/svg","svg"),s=n.createElementNS("http://www.w3.org/2000/svg","foreignObject");o.appendChild(s),n.body.appendChild(o),r={iframe:t,foreignObject:s,document:n,ownerDocument:e}}return r}(e),l=s.createElement(t);o.appendChild(l),n=l.computedStyleMap?J(l.computedStyleMap(),en):Z((0,a.L9)(l),en),o.removeChild(l),ee[t]=n}return n}(e.ownerDocument,e.tagName.toLowerCase()):G,s=Object.assign({},G);if(n){let t=e.parentElement;for(;t;){let e=this.styles.get(t)?.self;for(let t in e)s[t]||(s[t]=e[t]);t=t.parentElement}}let l={self:function(e,{defaultStyles:t,parentStyles:n}){return e.computedStyleMap?J(e.computedStyleMap(),{defaultStyles:t,parentStyles:n}):Z((0,a.L9)(e),{defaultStyles:t,parentStyles:n})}(e,{defaultStyles:o,parentStyles:s}),before:X(e,"::before"),after:X(e,"::after")};this.styles.set(e,l)}fetchResources(){let e=[];for(let t of this.styles.values())for(let n of(0,i.Ic)(t))if(n)for(let[t,r]of Object.entries(n)){if(!r)continue;"font-family"===t&&this.fonts.onFontFamilyValue(r);let i=Array.from(r.matchAll(y),e=>({original:e[0],url:e[1]||e[2]||e[3]})).filter(e=>!e.url.startsWith("#"));0!==i.length&&e.push(...i.map(async({url:e,original:i})=>{let o=await d(e)??"data:";n[t]=r.replace(i,`url("${o}")`)}))}return Promise.all(e)}unwrapCustomElements(){let e=new Set,t=(n,r)=>{if(e.has(n))return;e.add(n);let i=n.shadowRoot;if(i){let e=n.ownerDocument.createElement("div");for(let o of(this.styles.set(e,this.styles.get(n)),e.setAttribute("data-tl-custom-element",n.tagName),(r??n.parentElement).appendChild(e),i.childNodes))(0,a.vq)(o)?t(o,e):e.appendChild(o.cloneNode(!0));n.remove()}else if(r){if("style"===n.tagName.toLowerCase())return;let e=n.cloneNode(!1);for(let i of(this.styles.set(e,this.styles.get(n)),r.appendChild(e),(0,a.XH)(n)))(0,a.vq)(i)?t(i,e):e.appendChild(i.cloneNode(!0))}};for(let e of this.styles.keys())t(e,null)}embedStyles(){let e="";for(let[t,n]of this.styles){if(n.after||n.before){let r=`pseudo-${(0,i.NF)()}`;t.classList.add(r),n.before&&(e+=`.${r}::before {${Q(n.before)}}
2
- `),n.after&&(e+=`.${r}::after {${Q(n.after)}}
3
- `)}let r=(0,a.EV)(t);for(let[e,t]of Object.entries(n.self))t&&r.setProperty(e,t);"auto"===r.fontKerning&&(r.fontKerning="normal")}return e}async getFontFaceCss(){return await this.fonts.createCss()}dispose(){et()}}function X(e,t){let n=(0,a.L9)(e,t),r=n.getPropertyValue("content");if(""!==r&&"none"!==r)return Z(n,{defaultStyles:G,parentStyles:G})}function J(e,{defaultStyles:t,parentStyles:n}){let r={},o={currentColor:e.get("color")?.toString()||"",parentStyles:n,defaultStyles:t,getStyle:t=>e.get(t)?.toString()??""};for(let n of e.keys()){if(!w(n))continue;let s=e.get(n).toString();if(t[n]===s)continue;let a=(0,i.g5)(Y,n);a&&a(s,n,o)||(r[n]=s)}return r}function Z(e,{defaultStyles:t,parentStyles:n}){let r={},o={currentColor:e.color,parentStyles:n,defaultStyles:t,getStyle:t=>e.getPropertyValue(t)};for(let n in e){if(!w(n))continue;let s=e.getPropertyValue(n);if(t[n]===s)continue;let a=(0,i.g5)(Y,n);a&&a(s,n,o)||(r[n]=s)}return r}function Q(e){let t="";for(let[n,r]of Object.entries(e))t+=`${n}: ${r};`;return t}let ee={};function et(){for(let e in r&&(r.iframe.remove(),r=void 0),ee)delete ee[e]}let en={defaultStyles:G,parentStyles:G},er=1;async function ei(e,t,n={}){let r=function(e,t,n={}){let r=e.getContainerDocument();if(!r)throw Error("No document");let{scale:o=1,background:s=e.getInstanceState().exportBackground,preserveAspectRatio:a}=n,l="number"!=typeof n.padding,d="number"==typeof n.padding?n.padding:e.options.defaultSvgPadding,c=void 0!==n.darkMode?n.darkMode?"dark":"light":e.getColorMode(),h=e.getShapeAndDescendantIds(t),u=e.getUnorderedRenderingShapes(!1).filter(({id:e})=>h.has(e)),p=1===t.length?e.getShape(t[0]):null,f=p&&e.isShapeFrameLike(p)?t[0]:null,g=null,m=!1;if(n.bounds)g=l?n.bounds.clone():n.bounds.clone().expandBy(d);else{let t=function(e,t,n,r){let i=!1,o=null;for(let{id:n}of t){let t=e.getShapeMaskedPageBounds(n);if(!t)continue;let r=e.getShape(n),s=e.getShapeUtil(r).isExportBoundsContainer(r);o?s&&F.az.ContainsApproximately(t,o)?(i=!0,o=t.clone()):(i&&!F.az.ContainsApproximately(o,t)&&(i=!1),o.union(t)):(i=s,o=t.clone())}if(!o)return{box:null,paddingApplied:!1};let s=!r&&!i;return s&&o.expandBy(n),{box:o,paddingApplied:s}}(e,u,d,f);g=t.box,m=t.paddingApplied}if(!g)return;let y=l&&m?d:0,b=g.width*o,x=g.height*o;try{r.body.focus?.()}catch{}let w=new B(e.options.maxExportDelayMs),v=(0,i.il)();return w.waitUntil(v),{jsx:(0,E.jsx)(H,{editor:e,preserveAspectRatio:a,scale:o,pixelRatio:n.pixelRatio??null,bbox:g,background:s,singleFrameShapeId:f,isDarkMode:"dark"===c,colorMode:c,renderingShapes:u,onMount:v.resolve,waitUntil:w.waitUntil}),width:b,height:x,exportDelay:w,trimPadding:y}}(e,t,n);if(!r)return;let l=e.getContainer(),d=l.ownerDocument.createElement("div");d.className=C,d.inert=!0,d.tabIndex=-1,Object.assign(d.style,{position:"absolute",top:"0px",left:"0px",width:r.width+"px",height:r.height+"px",pointerEvents:"none",opacity:0}),l.appendChild(d);let c=(0,s.createRoot)(d,{identifierPrefix:`export_${er++}_`});try{await Promise.resolve(),(0,o.flushSync)(()=>{c.render(r.jsx)}),await r.exportDelay.resolve();let e=d.firstElementChild;return(0,i.vA)(e instanceof(0,a.mD)(l).SVGSVGElement,"Expected an SVG element"),await eo(e),{svg:e,width:r.width,height:r.height,trimPadding:r.trimPadding}}finally{setTimeout(()=>{c.unmount(),l.removeChild(d)},0)}}async function eo(e){let t=[...e.querySelectorAll("foreignObject.tl-export-embed-styles > *")];if(!t.length)return;let n=new q(e);try{for(let r of(n.fonts.startFindingDocumentFontFaces(e.ownerDocument),await Promise.all(t.map(e=>f(e))),t))n.readRootElementStyles(r);await n.fetchResources();let r=await n.getFontFaceCss();n.unwrapCustomElements();let i=n.embedStyles();if(r||i){let t=e.ownerDocument.createElementNS("http://www.w3.org/2000/svg","style");t.textContent=`${r}
4
- ${i}`,e.prepend(t)}}finally{n.dispose()}}},2642:(e,t,n)=>{"use strict";n.d(t,{i:()=>c});var r=n(83102),i=n(81467),o=n(24167),s=n(59830),a=n(82246);class l extends a{}class d{rBush;elementsInTree;constructor(){this.rBush=new l,this.elementsInTree=new Map}search(e){return new Set(this.rBush.search({minX:e.minX,minY:e.minY,maxX:e.maxX,maxY:e.maxY}).map(e=>e.id))}remove(e){let t=this.elementsInTree.get(e);t&&(this.rBush.remove(t),this.elementsInTree.delete(e))}applyBatch(e,t){for(let t of e)this.remove(t);for(let e of t){let t=this.elementsInTree.get(e.id);t&&this.rBush.remove(t),this.rBush.insert(e),this.elementsInTree.set(e.id,e)}}bulkLoad(e){for(let t of(this.rBush.load(e),e))this.elementsInTree.set(t.id,t)}clear(){this.rBush.clear(),this.elementsInTree.clear()}has(e){return this.elementsInTree.has(e)}getSize(){return this.elementsInTree.size}getElement(e){return this.elementsInTree.get(e)}dispose(){this.clear()}}class c{constructor(e){this.editor=e,this.rbush=new d,this.spatialIndexComputed=this.createSpatialIndexComputed()}editor;rbush;spatialIndexComputed;lastPageId=null;_boundsEpoch=0;rebuildAndBumpEpoch(){return this.buildFromScratch(),this._boundsEpoch++,this._boundsEpoch}createSpatialIndexComputed(){let e=this.editor.store.query.filterHistory("shape"),t=this.editor.store.query.filterHistory("binding");return(0,r.EW)("spatialIndex",(n,i)=>{let o=e.getDiffSince(i),s=t.getDiffSince(i),a=this.editor.getCurrentPageId();return(0,r._O)(n)||o===r.c2||s===r.c2||this.lastPageId!==a?(0,r.Pm)(()=>this.rebuildAndBumpEpoch()):(0===o.length&&0===s.length||(0,r.Pm)(()=>this.processIncrementalUpdate(o,s))&&this._boundsEpoch++,this._boundsEpoch)})}buildFromScratch(){this.rbush.clear(),this.lastPageId=this.editor.getCurrentPageId();let e=[];for(let t of this.editor.getCurrentPageShapes()){let n=this.editor.getShapePageBounds(t.id);n&&n.isValid()&&e.push({minX:n.minX,minY:n.minY,maxX:n.maxX,maxY:n.maxY,id:t.id})}this.rbush.bulkLoad(e)}processIncrementalUpdate(e,t){let n=new Set,r=[],s=new Set,a=new Set,l=[],d=e=>{a.has(e)||(a.add(e),l.push(e))};for(let t of e){for(let e of(0,o.Ic)(t.added))(0,i.o2)(e)&&(s.add(e.id),d(e.id));for(let e of(0,o.Ic)(t.removed))(0,i.o2)(e)&&(this.rbush.has(e.id)&&n.add(e.id),(0,i.xh)(e.parentId)||d(e.parentId));for(let[e,n]of(0,o.Ic)(t.updated))(0,i.o2)(n)&&(s.add(n.id),d(n.id),(0,i.o2)(e)&&e.parentId!==n.parentId&&!(0,i.xh)(e.parentId)&&d(e.parentId))}for(let e of t){for(let t of(0,o.Ic)(e.added))(0,i.OT)(t)&&(d(t.fromId),d(t.toId));for(let t of(0,o.Ic)(e.removed))(0,i.OT)(t)&&(d(t.fromId),d(t.toId));for(let[t,n]of(0,o.Ic)(e.updated))(0,i.OT)(n)&&(d(n.fromId),d(n.toId),(0,i.OT)(t)&&(t.fromId!==n.fromId||t.toId!==n.toId)&&(d(t.fromId),d(t.toId)))}let c=[...s];for(;c.length;){let e=c.pop();for(let t of this.editor.getSortedChildIdsForParent(e))s.has(t)||(s.add(t),c.push(t)),d(t)}for(;l.length;){let e=l.pop(),t=this.editor.store.unsafeGetWithoutCapture(e);for(let n of(t&&(0,i.o2)(t)&&!(0,i.xh)(t.parentId)&&d(t.parentId),this.editor.getBindingsInvolvingShape(e)))d(n.fromId),d(n.toId)}for(let e of a){let t=n.has(e)?void 0:this.rbush.getElement(e),o=this.editor.store.unsafeGetWithoutCapture(e);if(!o||!(0,i.o2)(o)||this.editor.getAncestorPageId(o)!==this.lastPageId){this.rbush.has(e)&&n.add(e);continue}let s=this.editor.getShapePageBounds(e);s&&s.isValid()?this.areBoundsEqualToSpatialElement(s,t)||(n.delete(e),r.push({minX:s.minX,minY:s.minY,maxX:s.maxX,maxY:s.maxY,id:e})):this.rbush.has(e)&&n.add(e)}return(0!==n.size||0!==r.length)&&(this.rbush.applyBatch(n,r),!0)}areBoundsEqualToSpatialElement(e,t){return!e&&!t||!!e&&!!t&&e.minX===t.minX&&e.minY===t.minY&&e.maxX===t.maxX&&e.maxY===t.maxY}getShapeIdsInsideBounds(e){return this.spatialIndexComputed.get(),this.rbush.search(e)}getShapeIdsAtPoint(e,t=0){return this.spatialIndexComputed.get(),this.rbush.search(new s.az(e.x-t,e.y-t,2*t,2*t))}dispose(){this.rbush.dispose(),this.lastPageId=null}}},3510:(e,t,n)=>{"use strict";n.d(t,{D:()=>r});var r=!1},4343:(e,t,n)=>{"use strict";n.d(t,{H:()=>a,w:()=>s});var r=n(81467),i=n(24167),o=n(59830);function s(e){switch(e.type){case"shapes":{let t=e.shapeIds.map(e=>l(e.slice(6)));return`s${t.join(".")}`}case"page":return"p"+l(r.tv.parseId(e.pageId));case"viewport":{let{bounds:t,pageId:n}=e,i=`v${Math.round(t.x)}.${Math.round(t.y)}.${Math.round(t.w)}.${Math.round(t.h)}`;return n&&(i+="."+l(r.tv.parseId(n))),i}default:(0,i.h6)(e)}}function a(e){switch(e[0]){case"s":return{type:"shapes",shapeIds:e.slice(1).split(".").filter(Boolean).map(e=>(0,r.n6)(decodeURIComponent(e)))};case"p":return{type:"page",pageId:r.tv.createId(decodeURIComponent(e.slice(1)))};case"v":{let[t,n,i,s,a]=e.slice(1).split(".");return{type:"viewport",bounds:new o.az(Number(t),Number(n),Number(i),Number(s)),pageId:a?r.tv.createId(decodeURIComponent(a)):void 0}}default:throw Error("Invalid deep link string")}}function l(e){return encodeURIComponent(e).replace(/\./g,"%2E")}},4467:(e,t,n)=>{var r,i=function(){var e=String.fromCharCode,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",r={};function i(e,t){if(!r[e]){r[e]={};for(var n=0;n<e.length;n++)r[e][e.charAt(n)]=n}return r[e][t]}var o={compressToBase64:function(e){if(null==e)return"";var n=o._compress(e,6,function(e){return t.charAt(e)});switch(n.length%4){default:case 0:return n;case 1:return n+"===";case 2:return n+"==";case 3:return n+"="}},decompressFromBase64:function(e){return null==e?"":""==e?null:o._decompress(e.length,32,function(n){return i(t,e.charAt(n))})},compressToUTF16:function(t){return null==t?"":o._compress(t,15,function(t){return e(t+32)})+" "},decompressFromUTF16:function(e){return null==e?"":""==e?null:o._decompress(e.length,16384,function(t){return e.charCodeAt(t)-32})},compressToUint8Array:function(e){for(var t=o.compress(e),n=new Uint8Array(2*t.length),r=0,i=t.length;r<i;r++){var s=t.charCodeAt(r);n[2*r]=s>>>8,n[2*r+1]=s%256}return n},decompressFromUint8Array:function(t){if(null==t)return o.decompress(t);for(var n=Array(t.length/2),r=0,i=n.length;r<i;r++)n[r]=256*t[2*r]+t[2*r+1];var s=[];return n.forEach(function(t){s.push(e(t))}),o.decompress(s.join(""))},compressToEncodedURIComponent:function(e){return null==e?"":o._compress(e,6,function(e){return n.charAt(e)})},decompressFromEncodedURIComponent:function(e){return null==e?"":""==e?null:(e=e.replace(/ /g,"+"),o._decompress(e.length,32,function(t){return i(n,e.charAt(t))}))},compress:function(t){return o._compress(t,16,function(t){return e(t)})},_compress:function(e,t,n){if(null==e)return"";var r,i,o,s={},a={},l="",d="",c="",h=2,u=3,p=2,f=[],g=0,m=0;for(o=0;o<e.length;o+=1)if(l=e.charAt(o),Object.prototype.hasOwnProperty.call(s,l)||(s[l]=u++,a[l]=!0),d=c+l,Object.prototype.hasOwnProperty.call(s,d))c=d;else{if(Object.prototype.hasOwnProperty.call(a,c)){if(256>c.charCodeAt(0)){for(r=0;r<p;r++)g<<=1,m==t-1?(m=0,f.push(n(g)),g=0):m++;for(i=c.charCodeAt(0),r=0;r<8;r++)g=g<<1|1&i,m==t-1?(m=0,f.push(n(g)),g=0):m++,i>>=1}else{for(r=0,i=1;r<p;r++)g=g<<1|i,m==t-1?(m=0,f.push(n(g)),g=0):m++,i=0;for(i=c.charCodeAt(0),r=0;r<16;r++)g=g<<1|1&i,m==t-1?(m=0,f.push(n(g)),g=0):m++,i>>=1}0==--h&&(h=Math.pow(2,p),p++),delete a[c]}else for(i=s[c],r=0;r<p;r++)g=g<<1|1&i,m==t-1?(m=0,f.push(n(g)),g=0):m++,i>>=1;0==--h&&(h=Math.pow(2,p),p++),s[d]=u++,c=String(l)}if(""!==c){if(Object.prototype.hasOwnProperty.call(a,c)){if(256>c.charCodeAt(0)){for(r=0;r<p;r++)g<<=1,m==t-1?(m=0,f.push(n(g)),g=0):m++;for(i=c.charCodeAt(0),r=0;r<8;r++)g=g<<1|1&i,m==t-1?(m=0,f.push(n(g)),g=0):m++,i>>=1}else{for(r=0,i=1;r<p;r++)g=g<<1|i,m==t-1?(m=0,f.push(n(g)),g=0):m++,i=0;for(i=c.charCodeAt(0),r=0;r<16;r++)g=g<<1|1&i,m==t-1?(m=0,f.push(n(g)),g=0):m++,i>>=1}0==--h&&(h=Math.pow(2,p),p++),delete a[c]}else for(i=s[c],r=0;r<p;r++)g=g<<1|1&i,m==t-1?(m=0,f.push(n(g)),g=0):m++,i>>=1;0==--h&&(h=Math.pow(2,p),p++)}for(r=0,i=2;r<p;r++)g=g<<1|1&i,m==t-1?(m=0,f.push(n(g)),g=0):m++,i>>=1;for(;;){if(g<<=1,m==t-1){f.push(n(g));break}m++}return f.join("")},decompress:function(e){return null==e?"":""==e?null:o._decompress(e.length,32768,function(t){return e.charCodeAt(t)})},_decompress:function(t,n,r){var i,o,s,a,l,d,c,h=[],u=4,p=4,f=3,g="",m=[],y={val:r(0),position:n,index:1};for(i=0;i<3;i+=1)h[i]=i;for(s=0,l=4,d=1;d!=l;)a=y.val&y.position,y.position>>=1,0==y.position&&(y.position=n,y.val=r(y.index++)),s|=(a>0)*d,d<<=1;switch(s){case 0:for(s=0,l=256,d=1;d!=l;)a=y.val&y.position,y.position>>=1,0==y.position&&(y.position=n,y.val=r(y.index++)),s|=(a>0)*d,d<<=1;c=e(s);break;case 1:for(s=0,l=65536,d=1;d!=l;)a=y.val&y.position,y.position>>=1,0==y.position&&(y.position=n,y.val=r(y.index++)),s|=(a>0)*d,d<<=1;c=e(s);break;case 2:return""}for(h[3]=c,o=c,m.push(c);;){if(y.index>t)return"";for(s=0,l=Math.pow(2,f),d=1;d!=l;)a=y.val&y.position,y.position>>=1,0==y.position&&(y.position=n,y.val=r(y.index++)),s|=(a>0)*d,d<<=1;switch(c=s){case 0:for(s=0,l=256,d=1;d!=l;)a=y.val&y.position,y.position>>=1,0==y.position&&(y.position=n,y.val=r(y.index++)),s|=(a>0)*d,d<<=1;h[p++]=e(s),c=p-1,u--;break;case 1:for(s=0,l=65536,d=1;d!=l;)a=y.val&y.position,y.position>>=1,0==y.position&&(y.position=n,y.val=r(y.index++)),s|=(a>0)*d,d<<=1;h[p++]=e(s),c=p-1,u--;break;case 2:return m.join("")}if(0==u&&(u=Math.pow(2,f),f++),h[c])g=h[c];else{if(c!==p)return null;g=o+o.charAt(0)}m.push(g),h[p++]=o+g.charAt(0),u--,o=g,0==u&&(u=Math.pow(2,f),f++)}}};return o}();void 0===(r=(function(){return i}).call(t,n,t,e))||(e.exports=r)},4599:(e,t,n)=>{"use strict";n.d(t,{I:()=>s,d:()=>a});var r=n(83102),i=n(24167),o=n(81962);function s(e,t,n){let s=new Set;for(let n of t){let t=e.getShape(n);if(!t)continue;s.add(t);let r=e.getShape(t.parentId);r&&s.add(r)}let l=new Map;for(let t of s){let i=e.getSortedChildIdsForParent(t);if(n?.filter&&!n.filter(t))l.set(t,i);else{let n=function(e,t,n){if(0===n.length)return r.Ml;let i=e.getShapePageBounds(t);if(!i)return r.Ml;let s=e.getShape(t);if(!s)return r.Ml;let a=e.getShapeGeometry(t),l=e.getShapePageTransform(t),d=l.applyToPoints(a.vertices),c=e.getShapeUtil(s.type).getClipPath?.(s),h=c?l.applyToPoints(c):void 0,u=h?(0,o.oQ)(h,d):d;return u?n.filter(t=>{let n=e.getShapePageBounds(t);if(!n||!i.includes(n))return!1;let r=e.getShapePageTransform(t).clone().invert().applyToPoints(u);return e.getShapeGeometry(t).overlapsPolygon(r)}):r.Ml}(e,t.id,i);if(n.length<i.length){let r=e.getShapeUtil(t),o=i.filter(i=>{if(n.includes(i))return!1;let o=e.getShape(i);return!!o&&r.canRemoveChildrenOfType(t,o.type)});o.length>0&&l.set(t,o)}}}let d=e.getCurrentPageShapesSorted().map(e=>e.id),c={};for(let[t,r]of l){let o=(0,i.oE)(r.map(t=>e.getShape(t))),{reparenting:s,remainingShapesToReparent:l}=a(e,o,(e,r)=>(!n?.filter||!!n.filter(r))&&r.id!==t.id&&d.indexOf(r.id)<d.indexOf(e.id));if(s.forEach((e,t)=>{0!==e.length&&(c[t]||(c[t]={parentId:t,shapeIds:[]}),c[t].shapeIds.push(...e.map(e=>e.id)))}),l.size>0){let n=e.findShapeAncestor(t,t=>e.isShapeOfType(t,"group"))?.id??e.getCurrentPageId();l.forEach(r=>{if(!c[n]){let r,o=e.getSortedChildIdsForParent(n),s=o.indexOf(t.id);if(s>-1){let n=o[s+1],a=n?e.getShape(n).index:void 0,l=a&&a>t.index?a:(0,i.AQ)(t.index);r=(0,i.HE)(t.index,l)}c[n]={parentId:n,shapeIds:[],index:r}}c[n].shapeIds.push(r.id)})}}e.run(()=>{Object.values(c).forEach(({parentId:t,shapeIds:n,index:r})=>{0!==n.length&&(n.sort((e,t)=>d.indexOf(e)<d.indexOf(t)?-1:1),e.reparentShapes(n,t,r))})})}function a(e,t,n){let r=new Set(t),s=new Set;for(let n of t){let t=e.getShapeParent(n);t&&e.isShapeOfType(t,"group")&&!s.has(t)&&s.add(t)}for(let t of s){for(let n of(0,i.oE)(e.getSortedChildIdsForParent(t).map(t=>e.getShape(t))))r.delete(n);r.add(t)}let a=new Map,l=new Map,d=new Set(r),c=e.getCurrentPageShapesSorted().filter(t=>{if(d.has(t))return!1;let n=e.getShapeUtil(t);for(let e of d)if(n.canReceiveNewChildrenOfType(t,e.type))return!0;return!1});for(let t=c.length-1;t>=0;t--){let r=c[t],i=e.findShapeAncestor(r,t=>e.isShapeOfType(t,"group"))?.id,s=e.getShapeGeometry(r),h=e.getShapePageTransform(r),u=e.getShapeMask(r),p=h.applyToPoints(s.vertices),f=u?(0,o.oQ)(u,p):p;if(!f)continue;let g=[];for(let t of d){if(r.id===t.id||n&&!n(t,r)||(a.has(t.id)||a.set(t.id,e.findShapeAncestor(t,t=>e.isShapeOfType(t,"group"))?.id),a.get(t.id)!==i||e.findShapeAncestor(r,e=>t.id===e.id)))continue;let o=e.getShapePageTransform(t).clone().invert().applyToPoints(f);if(e.getShapeGeometry(t).overlapsPolygon(o)){if(!e.getShapeUtil(r).canReceiveNewChildrenOfType?.(r,t.type))continue;t.parentId!==r.id&&g.push(t),d.delete(t);continue}}g.length&&l.set(r.id,g)}return{reparenting:l,remainingShapesToReparent:d}}},5174:(e,t,n)=>{"use strict";n.d(t,{A:()=>X});var r,i,o,s,a,l,d,c=function(){return(c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function h(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&0>t.indexOf(r)&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)0>t.indexOf(r[i])&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}var u=("function"==typeof SuppressedError&&SuppressedError,n(12115)),p="right-scroll-bar-position",f="width-before-scroll-bar";function g(e,t){return"function"==typeof e?e(t):e&&(e.current=t),e}var m="u">typeof window?u.useLayoutEffect:u.useEffect,y=new WeakMap,b=(void 0===r&&(r={}),(void 0===i&&(i=function(e){return e}),o=[],s=!1,a={read:function(){if(s)throw Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return o.length?o[o.length-1]:null},useMedium:function(e){var t=i(e,s);return o.push(t),function(){o=o.filter(function(e){return e!==t})}},assignSyncMedium:function(e){for(s=!0;o.length;){var t=o;o=[],t.forEach(e)}o={push:function(t){return e(t)},filter:function(){return o}}},assignMedium:function(e){s=!0;var t=[];if(o.length){var n=o;o=[],n.forEach(e),t=o}var r=function(){var n=t;t=[],n.forEach(e)},i=function(){return Promise.resolve().then(r)};i(),o={push:function(e){t.push(e),i()},filter:function(e){return t=t.filter(e),o}}}}).options=c({async:!0,ssr:!1},r),a),x=function(){},w=u.forwardRef(function(e,t){var n,r,i,o,s=u.useRef(null),a=u.useState({onScrollCapture:x,onWheelCapture:x,onTouchMoveCapture:x}),l=a[0],d=a[1],p=e.forwardProps,f=e.children,w=e.className,v=e.removeScrollBar,S=e.enabled,C=e.shards,k=e.sideCar,P=e.noRelative,T=e.noIsolation,E=e.inert,I=e.allowPinchZoom,_=e.as,M=e.gapMode,A=h(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),j=(n=[s,t],r=function(e){return n.forEach(function(t){return g(t,e)})},(i=(0,u.useState)(function(){return{value:null,callback:r,facade:{get current(){return i.value},set current(value){var e=i.value;e!==value&&(i.value=value,i.callback(value,e))}}}})[0]).callback=r,o=i.facade,m(function(){var e=y.get(o);if(e){var t=new Set(e),r=new Set(n),i=o.current;t.forEach(function(e){r.has(e)||g(e,null)}),r.forEach(function(e){t.has(e)||g(e,i)})}y.set(o,n)},[n]),o),O=c(c({},A),l);return u.createElement(u.Fragment,null,S&&u.createElement(k,{sideCar:b,removeScrollBar:v,shards:C,noRelative:P,noIsolation:T,inert:E,setCallbacks:d,allowPinchZoom:!!I,lockRef:s,gapMode:M}),p?u.cloneElement(u.Children.only(f),c(c({},O),{ref:j})):u.createElement(void 0===_?"div":_,c({},O,{className:w,ref:j}),f))});w.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},w.classNames={fullWidth:f,zeroRight:p};var v=function(e){var t=e.sideCar,n=h(e,["sideCar"]);if(!t)throw Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw Error("Sidecar medium not found");return u.createElement(r,c({},n))};v.isSideCarExport=!0;var S=function(){var e=0,t=null;return{add:function(r){if(0==e&&(t=function(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=d||n.nc;return t&&e.setAttribute("nonce",t),e}())){var i,o;(i=t).styleSheet?i.styleSheet.cssText=r:i.appendChild(document.createTextNode(r)),o=t,(document.head||document.getElementsByTagName("head")[0]).appendChild(o)}e++},remove:function(){--e||!t||(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},C=function(){var e=S();return function(t,n){u.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},k=function(){var e=C();return function(t){return e(t.styles,t.dynamic),null}},P={left:0,top:0,right:0,gap:0},T=function(e){return parseInt(e||"",10)||0},E=function(e){var t=window.getComputedStyle(document.body),n=t["padding"===e?"paddingLeft":"marginLeft"],r=t["padding"===e?"paddingTop":"marginTop"],i=t["padding"===e?"paddingRight":"marginRight"];return[T(n),T(r),T(i)]},I=function(e){if(void 0===e&&(e="margin"),"u"<typeof window)return P;var t=E(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},_=k(),M="data-scroll-locked",A=function(e,t,n,r){var i=e.left,o=e.top,s=e.right,a=e.gap;return void 0===n&&(n="margin"),"\n .".concat("with-scroll-bars-hidden"," {\n overflow: hidden ").concat(r,";\n padding-right: ").concat(a,"px ").concat(r,";\n }\n body[").concat(M,"] {\n overflow: hidden ").concat(r,";\n overscroll-behavior: contain;\n ").concat([t&&"position: relative ".concat(r,";"),"margin"===n&&"\n padding-left: ".concat(i,"px;\n padding-top: ").concat(o,"px;\n padding-right: ").concat(s,"px;\n margin-left:0;\n margin-top:0;\n margin-right: ").concat(a,"px ").concat(r,";\n "),"padding"===n&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),"\n }\n \n .").concat(p," {\n right: ").concat(a,"px ").concat(r,";\n }\n \n .").concat(f," {\n margin-right: ").concat(a,"px ").concat(r,";\n }\n \n .").concat(p," .").concat(p," {\n right: 0 ").concat(r,";\n }\n \n .").concat(f," .").concat(f," {\n margin-right: 0 ").concat(r,";\n }\n \n body[").concat(M,"] {\n ").concat("--removed-body-scroll-bar-size",": ").concat(a,"px;\n }\n")},j=function(){var e=parseInt(document.body.getAttribute(M)||"0",10);return isFinite(e)?e:0},O=function(){u.useEffect(function(){return document.body.setAttribute(M,(j()+1).toString()),function(){var e=j()-1;e<=0?document.body.removeAttribute(M):document.body.setAttribute(M,e.toString())}},[])},D=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=void 0===r?"margin":r;O();var o=u.useMemo(function(){return I(i)},[i]);return u.createElement(_,{styles:A(o,!t,i,n?"":"!important")})},L=!1;if("u">typeof window)try{var R=Object.defineProperty({},"passive",{get:function(){return L=!0,!0}});window.addEventListener("test",R,R),window.removeEventListener("test",R,R)}catch(e){L=!1}var F=!!L&&{passive:!1},z=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return"hidden"!==n[t]&&(n.overflowY!==n.overflowX||"TEXTAREA"===e.tagName||"visible"!==n[t])},N=function(e,t){var n=t.ownerDocument,r=t;do{if("u">typeof ShadowRoot&&r instanceof ShadowRoot&&(r=r.host),$(e,r)){var i=B(e,r);if(i[1]>i[2])return!0}r=r.parentNode}while(r&&r!==n.body);return!1},$=function(e,t){return"v"===e?z(t,"overflowY"):z(t,"overflowX")},B=function(e,t){return"v"===e?[t.scrollTop,t.scrollHeight,t.clientHeight]:[t.scrollLeft,t.scrollWidth,t.clientWidth]},H=function(e,t,n,r,i){var o,s=(o=window.getComputedStyle(t).direction,"h"===e&&"rtl"===o?-1:1),a=s*r,l=n.target,d=t.contains(l),c=!1,h=a>0,u=0,p=0;do{if(!l)break;var f=B(e,l),g=f[0],m=f[1]-f[2]-s*g;(g||m)&&$(e,l)&&(u+=m,p+=g);var y=l.parentNode;l=y&&y.nodeType===Node.DOCUMENT_FRAGMENT_NODE?y.host:y}while(!d&&l!==document.body||d&&(t.contains(l)||t===l));return h&&(i&&1>Math.abs(u)||!i&&a>u)?c=!0:!h&&(i&&1>Math.abs(p)||!i&&-a>p)&&(c=!0),c},U=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},K=function(e){return[e.deltaX,e.deltaY]},W=function(e){return e&&"current"in e?e.current:e},V=0,Y=[];let G=(l=function(e){var t=u.useRef([]),n=u.useRef([0,0]),r=u.useRef(),i=u.useState(V++)[0],o=u.useState(k)[0],s=u.useRef(e);u.useEffect(function(){s.current=e},[e]),u.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var t=(function(e,t,n){if(n||2==arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))})([e.lockRef.current],(e.shards||[]).map(W),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),t.forEach(function(e){return e.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var a=u.useCallback(function(e,t){if("touches"in e&&2===e.touches.length||"wheel"===e.type&&e.ctrlKey)return!s.current.allowPinchZoom;var i,o=U(e),a=n.current,l="deltaX"in e?e.deltaX:a[0]-o[0],d="deltaY"in e?e.deltaY:a[1]-o[1],c=e.target,h=Math.abs(l)>Math.abs(d)?"h":"v";if("touches"in e&&"h"===h&&"range"===c.type)return!1;var u=window.getSelection(),p=u&&u.anchorNode;if(p&&(p===c||p.contains(c)))return!1;var f=N(h,c);if(!f)return!0;if(f?i=h:(i="v"===h?"h":"v",f=N(h,c)),!f)return!1;if(!r.current&&"changedTouches"in e&&(l||d)&&(r.current=i),!i)return!0;var g=r.current||i;return H(g,t,e,"h"===g?l:d,!0)},[]),l=u.useCallback(function(e){if(Y.length&&Y[Y.length-1]===o){var n="deltaY"in e?K(e):U(e),r=t.current.filter(function(t){var r;return t.name===e.type&&(t.target===e.target||e.target===t.shadowParent)&&(r=t.delta,r[0]===n[0]&&r[1]===n[1])})[0];if(r&&r.should){e.cancelable&&e.preventDefault();return}if(!r){var i=(s.current.shards||[]).map(W).filter(Boolean).filter(function(t){return t.contains(e.target)});(i.length>0?a(e,i[0]):!s.current.noIsolation)&&e.cancelable&&e.preventDefault()}}},[]),d=u.useCallback(function(e,n,r,i){var o={name:e,delta:n,target:r,should:i,shadowParent:function(e){for(var t=null;null!==e;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}(r)};t.current.push(o),setTimeout(function(){t.current=t.current.filter(function(e){return e!==o})},1)},[]),c=u.useCallback(function(e){n.current=U(e),r.current=void 0},[]),h=u.useCallback(function(t){d(t.type,K(t),t.target,a(t,e.lockRef.current))},[]),p=u.useCallback(function(t){d(t.type,U(t),t.target,a(t,e.lockRef.current))},[]);u.useEffect(function(){return Y.push(o),e.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:p}),document.addEventListener("wheel",l,F),document.addEventListener("touchmove",l,F),document.addEventListener("touchstart",c,F),function(){Y=Y.filter(function(e){return e!==o}),document.removeEventListener("wheel",l,F),document.removeEventListener("touchmove",l,F),document.removeEventListener("touchstart",c,F)}},[]);var f=e.removeScrollBar,g=e.inert;return u.createElement(u.Fragment,null,g?u.createElement(o,{styles:"\n .block-interactivity-".concat(i," {pointer-events: none;}\n .allow-interactivity-").concat(i," {pointer-events: all;}\n")}):null,f?u.createElement(D,{noRelative:e.noRelative,gapMode:e.gapMode}):null)},b.useMedium(l),v);var q=u.forwardRef(function(e,t){return u.createElement(w,c({},e,{ref:t,sideCar:G}))});q.classNames=w.classNames;let X=q},8242:(e,t,n)=>{"use strict";n.d(t,{$L:()=>_,Ln:()=>g,N0:()=>E,Um:()=>I,Wg:()=>m,X9:()=>s,Ys:()=>u,dL:()=>$,jP:()=>x,n9:()=>P,oM:()=>w,zy:()=>k});var r=n(27050);class i{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class o{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&o.empty)return o.empty}recover(e){let t=0,n=65535&e;if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[3*e+2]-this.ranges[3*e+1];return this.ranges[3*n]+t+(e-(65535&e))/65536}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,o=this.inverted?2:1,s=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let l=this.ranges[a]-(this.inverted?r:0);if(l>e)break;let d=this.ranges[a+o],c=this.ranges[a+s],h=l+d;if(e<=h){let o=d?e==l?-1:e==h?1:t:t,s=l+r+(o<0?0:c);if(n)return s;let u=e==(t<0?l:h)?null:a/3+(e-l)*65536,p=e==l?2:e==h?1:4;return(t<0?e!=l:e!=h)&&(p|=8),new i(s,p,u)}r+=c-d}return n?e+r:new i(e+r,0,null)}touches(e,t){let n=0,r=65535&t,i=this.inverted?2:1,o=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let s=this.ranges[t]-(this.inverted?n:0);if(s>e)break;let a=this.ranges[t+i];if(e<=s+a&&t==3*r)return!0;n+=this.ranges[t+o]-a}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let o=this.ranges[r],s=o-(this.inverted?i:0),a=o+(this.inverted?0:i),l=this.ranges[r+t],d=this.ranges[r+n];e(s,s+l,a,a+d),i+=d-l}}invert(){return new o(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?o.empty:new o(e<0?[0,-e,0]:[0,0,e])}}o.empty=new o([]);class s{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new s(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),null!=t&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],null!=r&&r<t?n+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),null!=r&&r>t?n-r-1:void 0)}}invert(){let e=new s;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let n=this.from;n<this.to;n++){let i=this._maps[n].mapResult(e,t);if(null!=i.recover){let t=this.getMirror(n);if(null!=t&&t>n&&t<this.to){n=t,e=this._maps[t].recover(i.recover);continue}}r|=i.delInfo,e=i.pos}return n?e:new i(e,r,null)}}let a=Object.create(null);class l{getMap(){return o.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError("Invalid input for Step.fromJSON");let n=a[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in a)throw RangeError("Duplicate use of step JSON ID "+e);return a[e]=t,t.prototype.jsonID=e,t}}class d{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new d(e,null)}static fail(e){return new d(null,e)}static fromReplace(e,t,n,i){try{return d.ok(e.replace(t,n,i))}catch(e){if(e instanceof r.vI)return d.fail(e.message);throw e}}}function c(e,t,n){let i=[];for(let r=0;r<e.childCount;r++){let o=e.child(r);o.content.size&&(o=o.copy(c(o.content,t,o))),o.isInline&&(o=t(o,n,r)),i.push(o)}return r.FK.fromArray(i)}class h extends l{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),i=n.node(n.sharedDepth(this.to)),o=new r.Ji(c(t.content,(e,t)=>e.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e,i),t.openStart,t.openEnd);return d.fromReplace(e,this.from,this.to,o)}invert(){return new u(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new h(t.pos,n.pos,this.mark)}merge(e){return e instanceof h&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new h(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for AddMarkStep.fromJSON");return new h(t.from,t.to,e.markFromJSON(t.mark))}}l.jsonID("addMark",h);class u extends l{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new r.Ji(c(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return d.fromReplace(e,this.from,this.to,n)}invert(){return new h(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new u(t.pos,n.pos,this.mark)}merge(e){return e instanceof u&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new u(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for RemoveMarkStep.fromJSON");return new u(t.from,t.to,e.markFromJSON(t.mark))}}l.jsonID("removeMark",u);class p extends l{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return d.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return d.fromReplace(e,this.pos,this.pos+1,new r.Ji(r.FK.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);if(t){let e=this.mark.addToSet(t.marks);if(e.length==t.marks.length){for(let n=0;n<t.marks.length;n++)if(!t.marks[n].isInSet(e))return new p(this.pos,t.marks[n]);return new p(this.pos,this.mark)}}return new f(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new p(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new p(t.pos,e.markFromJSON(t.mark))}}l.jsonID("addNodeMark",p);class f extends l{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return d.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return d.fromReplace(e,this.pos,this.pos+1,new r.Ji(r.FK.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new p(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new f(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new f(t.pos,e.markFromJSON(t.mark))}}l.jsonID("removeNodeMark",f);class g extends l{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&y(e,this.from,this.to)?d.fail("Structure replace would overwrite content"):d.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new o([this.from,this.to-this.from,this.slice.size])}invert(e){return new g(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.to,-1),n=this.from==this.to&&g.MAP_BIAS<0?t:e.mapResult(this.from,1);return n.deletedAcross&&t.deletedAcross?null:new g(n.pos,Math.max(n.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof g)||e.structure||this.structure)return null;if(this.from+this.slice.size!=e.from||this.slice.openEnd||e.slice.openStart)if(e.to!=this.from||this.slice.openStart||e.slice.openEnd)return null;else{let t=this.slice.size+e.slice.size==0?r.Ji.empty:new r.Ji(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new g(e.from,this.to,t,this.structure)}{let t=this.slice.size+e.slice.size==0?r.Ji.empty:new r.Ji(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new g(this.from,this.to+(e.to-e.from),t,this.structure)}}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for ReplaceStep.fromJSON");return new g(t.from,t.to,r.Ji.fromJSON(e,t.slice),!!t.structure)}}g.MAP_BIAS=1,l.jsonID("replace",g);class m extends l{constructor(e,t,n,r,i,o,s=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=o,this.structure=s}apply(e){if(this.structure&&(y(e,this.from,this.gapFrom)||y(e,this.gapTo,this.to)))return d.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return d.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?d.fromReplace(e,this.from,this.to,n):d.fail("Content does not fit in gap")}getMap(){return new o([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new m(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),r=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),i=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||r<t.pos||i>n.pos?null:new m(t.pos,n.pos,r,i,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to||"number"!=typeof t.gapFrom||"number"!=typeof t.gapTo||"number"!=typeof t.insert)throw RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new m(t.from,t.to,t.gapFrom,t.gapTo,r.Ji.fromJSON(e,t.slice),t.insert,!!t.structure)}}function y(e,t,n){let r=e.resolve(t),i=n-t,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let e=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function b(e,t,n,i=n.contentMatch,o=!0){let s=e.doc.nodeAt(t),a=[],l=t+1;for(let t=0;t<s.childCount;t++){let d=s.child(t),c=l+d.nodeSize,h=i.matchType(d.type);if(h){i=h;for(let t=0;t<d.marks.length;t++)n.allowsMarkType(d.marks[t].type)||e.step(new u(l,c,d.marks[t]));if(o&&d.isText&&"pre"!=n.whitespace){let e,t=/\r?\n|\r/g,i;for(;e=t.exec(d.text);)i||(i=new r.Ji(r.FK.from(n.schema.text(" ",n.allowedMarks(d.marks))),0,0)),a.push(new g(l+e.index,l+e.index+e[0].length,i))}}else a.push(new g(l,c,r.Ji.empty));l=c}if(!i.validEnd){let t=i.fillBefore(r.FK.empty,!0);e.replace(l,l,new r.Ji(t,0,0))}for(let t=a.length-1;t>=0;t--)e.step(a[t])}function x(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let o=e.$from.node(n),s=e.$from.index(n)+r,a=e.$to.indexAfter(n)-i;if(n<e.depth&&o.canReplace(s,a,t))return n;if(0==n||o.type.spec.isolating||!((0==s||o.canReplace(s,o.childCount))&&(a==o.childCount||o.canReplace(0,a))))break;s&&(r=1),a<o.childCount&&(i=1)}return null}function w(e,t,n=null,r=e){let i=function(e,t){let{parent:n,startIndex:r,endIndex:i}=e,o=n.contentMatchAt(r).findWrapping(t);if(!o)return null;let s=o.length?o[0]:t;return n.canReplaceWith(r,i,s)?o:null}(e,t),o=i&&function(e,t){let{parent:n,startIndex:r,endIndex:i}=e,o=n.child(r),s=t.contentMatch.findWrapping(o.type);if(!s)return null;let a=(s.length?s[s.length-1]:t).contentMatch;for(let e=r;a&&e<i;e++)a=a.matchType(n.child(e).type);return a&&a.validEnd?s:null}(r,t);return o?i.map(v).concat({type:t,attrs:n}).concat(o.map(v)):null}function v(e){return{type:e,attrs:null}}function S(e,t,n,r){t.forEach((i,o)=>{if(i.isText){let s,a=/\r?\n|\r/g;for(;s=a.exec(i.text);){let i=e.mapping.slice(r).map(n+1+o+s.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function C(e,t,n,r){t.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+o);e.replaceWith(i,i+1,t.type.schema.text("\n"))}})}function k(e,t,n=1,r){let i=e.resolve(t),o=i.depth-n,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>o;e--,t--){let n=i.node(e),o=i.index(e);if(n.type.spec.isolating)return!1;let s=n.content.cutByIndex(o,n.childCount),a=r&&r[t+1];a&&(s=s.replaceChild(0,a.type.create(a.attrs)));let l=r&&r[t]||n;if(!n.canReplace(o+1,n.childCount)||!l.type.validContent(s))return!1}let a=i.indexAfter(o),l=r&&r[0];return i.node(o).canReplaceWith(a,a,l?l.type:i.node(o+1).type)}function P(e,t){let n=e.resolve(t),r=n.index();return T(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function T(e,t){return!!(e&&t&&!e.isLeaf&&function(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i<t.childCount;i++){let o=t.child(i),s=o.type==r?e.type.schema.nodes.text:o.type;if(!(n=n.matchType(s))||!e.type.allowsMarks(o.marks))return!1}return n.validEnd}(e,t))}function E(e,t,n=-1){let r=e.resolve(t);for(let e=r.depth;;e--){let i,o,s=r.index(e);if(e==r.depth?(i=r.nodeBefore,o=r.nodeAfter):n>0?(i=r.node(e+1),s++,o=r.node(e).maybeChild(s)):(i=r.node(e).maybeChild(s-1),o=r.node(e+1)),i&&!i.isTextblock&&T(i,o)&&r.node(e).canReplace(s,s+1))return t;if(0==e)break;t=n<0?r.before(e):r.after(e)}}function I(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let i=n.content;for(let e=0;e<n.openStart;e++)i=i.firstChild.content;for(let e=1;e<=(0==n.openStart&&n.size?2:1);e++)for(let t=r.depth;t>=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,o=r.index(t)+ +(n>0),s=r.node(t),a=!1;if(1==e)a=s.canReplace(o,o,i);else{let e=s.contentMatchAt(o).findWrapping(i.firstChild.type);a=e&&s.canReplaceWith(o,o,e[0])}if(a)return 0==n?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function _(e,t,n=t,i=r.Ji.empty){if(t==n&&!i.size)return null;let o=e.resolve(t),s=e.resolve(n);return M(o,s,i)?new g(t,n,i):new A(o,s,i).fit()}function M(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}l.jsonID("replaceAround",m);class A{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=r.FK.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=r.FK.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,i=this.close(e<0?this.$to:n.doc.resolve(e));if(!i)return null;let o=this.placed,s=n.depth,a=i.depth;for(;s&&a&&1==o.childCount;)o=o.firstChild.content,s--,a--;let l=new r.Ji(o,s,a);return e>-1?new m(n.pos,e,this.$to.pos,this.$to.end(),l,t):l.size||n.pos!=this.$to.pos?new g(n.pos,i.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let i=t.firstChild;if(t.childCount>1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=1==t?e:this.unplaced.openStart;n>=0;n--){let e=null,i=(n?(e=D(this.unplaced.content,n-1).firstChild).content:this.unplaced.content).firstChild;for(let o=this.depth;o>=0;o--){let{type:s,match:a}=this.frontier[o],l,d=null;if(1==t&&(i?a.matchType(i.type)||(d=a.fillBefore(r.FK.from(i),!1)):e&&s.compatibleContent(e.type)))return{sliceDepth:n,frontierDepth:o,parent:e,inject:d};if(2==t&&i&&(l=a.findWrapping(i.type)))return{sliceDepth:n,frontierDepth:o,parent:e,wrap:l};if(e&&a.matchType(e.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=D(e,t);return!!i.childCount&&!i.firstChild.isLeaf&&(this.unplaced=new r.Ji(e,t+1,Math.max(n,i.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=D(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new r.Ji(j(e,t-1,1),t-1,o?t-1:n)}else this.unplaced=new r.Ji(j(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let e=0;e<o.length;e++)this.openFrontierNode(o[e]);let s=this.unplaced,a=n?n.content:s.content,l=s.openStart-e,d=0,c=[],{match:h,type:u}=this.frontier[t];if(i){for(let e=0;e<i.childCount;e++)c.push(i.child(e));h=h.matchFragment(i)}let p=a.size+e-(s.content.size-s.openEnd);for(;d<a.childCount;){let e=a.child(d),t=h.matchType(e.type);if(!t)break;(++d>1||0==l||e.content.size)&&(h=t,c.push(function e(t,n,i){if(n<=0)return t;let o=t.content;return n>1&&(o=o.replaceChild(0,e(o.firstChild,n-1,1==o.childCount?i-1:0))),n>0&&(o=t.type.contentMatch.fillBefore(o).append(o),i<=0&&(o=o.append(t.type.contentMatch.matchFragment(o).fillBefore(r.FK.empty,!0)))),t.copy(o)}(e.mark(u.allowedMarks(e.marks)),1==d?l:0,d==a.childCount?p:-1)))}let f=d==a.childCount;f||(p=-1),this.placed=O(this.placed,t,r.FK.from(c)),this.frontier[t].match=h,f&&p<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=a;e<p;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=f?0==e?r.Ji.empty:new r.Ji(j(s.content,e-1,1),e-1,p<0?s.openEnd:e-1):new r.Ji(j(s.content,e,d),s.openStart,s.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return -1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!L(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return -1;let{depth:n}=this.$to,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),o=L(e,t,r,n,i);if(o){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],i=L(e,n,r,t,!0);if(!i||i.childCount)continue e}return{depth:t,fit:o,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=O(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=O(this.placed,this.depth,r.FK.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(r.FK.empty,!0);e.childCount&&(this.placed=O(this.placed,this.frontier.length,e))}}function j(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(j(e.firstChild.content,t-1,n)))}function O(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(O(e.lastChild.content,t-1,n)))}function D(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function L(e,t,n,r,i){let o=e.node(t),s=i?e.indexAfter(t):e.index(t);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let a=r.fillBefore(o.content,!0,s);return a&&!function(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}(n,o.content,s)?a:null}function R(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(r<e.pos-(e.depth-i)||t.end(i)>t.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}class F extends l{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return d.fail("No node at attribute step's position");let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let i=t.type.create(n,null,t.marks);return d.fromReplace(e,this.pos,this.pos+1,new r.Ji(r.FK.from(i),0,+!t.isLeaf))}getMap(){return o.empty}invert(e){return new F(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new F(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if("number"!=typeof t.pos||"string"!=typeof t.attr)throw RangeError("Invalid input for AttrStep.fromJSON");return new F(t.pos,t.attr,t.value)}}l.jsonID("attr",F);class z extends l{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return d.ok(n)}getMap(){return o.empty}invert(e){return new z(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if("string"!=typeof t.attr)throw RangeError("Invalid input for DocAttrStep.fromJSON");return new z(t.attr,t.value)}}l.jsonID("docAttr",z);let N=class extends Error{};(N=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n}).prototype=Object.create(Error.prototype),N.prototype.constructor=N,N.prototype.name="TransformError";class ${constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new s}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new N(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let r=this.mapping.maps[n];n&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((n,r,i,o)=>{e=Math.min(e,i),t=Math.max(t,o)})}return 1e9==e?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=r.Ji.empty){let i=_(this.doc,e,t,n);return i&&this.step(i),this}replaceWith(e,t,n){return this.replace(e,t,new r.Ji(r.FK.from(n),0,0))}delete(e,t){return this.replace(e,t,r.Ji.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return!function(e,t,n,i){if(!i.size)return e.deleteRange(t,n);let o=e.doc.resolve(t),s=e.doc.resolve(n);if(M(o,s,i))return e.step(new g(t,n,i));let a=R(o,s);0==a[a.length-1]&&a.pop();let l=-(o.depth+1);a.unshift(l);for(let e=o.depth,t=o.pos-1;e>0;e--,t--){let n=o.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;a.indexOf(e)>-1?l=e:o.before(e)==t&&a.splice(1,0,-e)}let d=a.indexOf(l),c=[],h=i.openStart;for(let e=i.content,t=0;;t++){let n=e.firstChild;if(c.push(n),t==i.openStart)break;e=n.content}for(let e=h-1;e>=0;e--){var u;let t=c[e],n=(u=t.type).spec.defining||u.spec.definingForContent;if(n&&!t.sameMarkup(o.node(Math.abs(l)-1)))h=e;else if(n||!t.type.isTextblock)break}for(let t=i.openStart;t>=0;t--){let l=(t+h+1)%(i.openStart+1),u=c[l];if(u)for(let t=0;t<a.length;t++){let c=a[(t+d)%a.length],h=!0;c<0&&(h=!1,c=-c);let p=o.node(c-1),f=o.index(c-1);if(p.canReplaceWith(f,f,u.type,u.marks))return e.replace(o.before(c),h?s.after(c):n,new r.Ji(function e(t,n,i,o,s){if(n<i){let r=t.firstChild;t=t.replaceChild(0,r.copy(e(r.content,n+1,i,o,r)))}if(n>o){let e=s.contentMatchAt(0),n=e.fillBefore(t).append(t);t=n.append(e.matchFragment(n).fillBefore(r.FK.empty,!0))}return t}(i.content,0,i.openStart,l),l,i.openEnd))}}let p=e.steps.length;for(let r=a.length-1;r>=0&&(e.replace(t,n,i),!(e.steps.length>p));r--){let e=a[r];e<0||(t=o.before(e),n=s.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){var i=e,o=t;if(!n.isInline&&i==o&&this.doc.resolve(i).parent.content.size){let e=function(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(0==r.parentOffset)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t<r.node(e).childCount)break}return null}(this.doc,i,n.type);null!=e&&(i=o=e)}return this.replaceRange(i,o,new r.Ji(r.FK.from(n),0,0)),this}deleteRange(e,t){return!function(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&0==r.parentOffset&&0==i.parentOffset){let o=r.sharedDepth(n),s=!1;for(let e=r.depth;e>o;e--)r.node(e).type.spec.isolating&&(s=!0);for(let e=i.depth;e>o;e--)i.node(e).type.spec.isolating&&(s=!0);if(!s){for(let e=r.depth;e>0&&t==r.start(e);e--)t=r.before(e);for(let e=i.depth;e>0&&n==i.start(e);e--)n=i.before(e);r=e.doc.resolve(t),i=e.doc.resolve(n)}}let o=R(r,i);for(let t=0;t<o.length;t++){let n=o[t],s=t==o.length-1;if(s&&0==n||r.node(n).type.contentMatch.validEnd)return e.delete(r.start(n),i.end(n));if(n>0&&(s||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(t-r.start(o)==r.depth-o&&n>r.end(o)&&i.end(o)-n!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return e.delete(r.before(o),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return!function(e,t,n){let{$from:i,$to:o,depth:s}=t,a=i.before(s+1),l=o.after(s+1),d=a,c=l,h=r.FK.empty,u=0;for(let e=s,t=!1;e>n;e--)t||i.index(e)>0?(t=!0,h=r.FK.from(i.node(e).copy(h)),u++):d--;let p=r.FK.empty,f=0;for(let e=s,t=!1;e>n;e--)t||o.after(e+1)<o.end(e)?(t=!0,p=r.FK.from(o.node(e).copy(p)),f++):c++;e.step(new m(d,c,a,l,new r.Ji(h.append(p),u,f),h.size-u,!0))}(this,e,t),this}join(e,t=1){return!function(e,t,n){let i=null,{linebreakReplacement:o}=e.doc.type.schema,s=e.doc.resolve(t-n),a=s.node().type;if(o&&a.inlineContent){let e="pre"==a.whitespace,t=!!a.contentMatch.matchType(o);e&&!t?i=!1:!e&&t&&(i=!0)}let l=e.steps.length;if(!1===i){let r=e.doc.resolve(t+n);C(e,r.node(),r.before(),l)}a.inlineContent&&b(e,t+n-1,a,s.node().contentMatchAt(s.index()),null==i);let d=e.mapping.slice(l),c=d.map(t-n);if(e.step(new g(c,d.map(t+n,-1),r.Ji.empty,!0)),!0===i){let t=e.doc.resolve(c);S(e,t.node(),t.before(),e.steps.length)}}(this,e,t),this}wrap(e,t){return!function(e,t,n){let i=r.FK.empty;for(let e=n.length-1;e>=0;e--){if(i.size){let t=n[e].type.contentMatch.matchFragment(i);if(!t||!t.validEnd)throw RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}i=r.FK.from(n[e].type.create(n[e].attrs,i))}let o=t.start,s=t.end;e.step(new m(o,s,o,s,new r.Ji(i,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,i=null){var o=this;if(!n.isTextblock)throw RangeError("Type given to setBlockType should be a textblock");let s=o.steps.length;return o.doc.nodesBetween(e,t,(e,t)=>{var a,l,d;let c,h,u="function"==typeof i?i(e):i;if(e.isTextblock&&!e.hasMarkup(n,u)&&(a=o.doc,l=o.mapping.slice(s).map(t),d=n,h=(c=a.resolve(l)).index(),c.parent.canReplaceWith(h,h+1,d))){let i=null;if(n.schema.linebreakReplacement){let e="pre"==n.whitespace,t=!!n.contentMatch.matchType(n.schema.linebreakReplacement);e&&!t?i=!1:!e&&t&&(i=!0)}!1===i&&C(o,e,t,s),b(o,o.mapping.slice(s).map(t,1),n,void 0,null===i);let a=o.mapping.slice(s),l=a.map(t,1),d=a.map(t+e.nodeSize,1);return o.step(new m(l,d,l+1,d-1,new r.Ji(r.FK.from(n.create(u,null,e.marks)),0,0),1,!0)),!0===i&&S(o,e,t,s),!1}}),this}setNodeMarkup(e,t,n=null,i){return!function(e,t,n,i,o){let s=e.doc.nodeAt(t);if(!s)throw RangeError("No node at given position");n||(n=s.type);let a=n.create(i,null,o||s.marks);if(s.isLeaf)return e.replaceWith(t,t+s.nodeSize,a);if(!n.validContent(s.content))throw RangeError("Invalid content for node type "+n.name);e.step(new m(t,t+s.nodeSize,t+1,t+s.nodeSize-1,new r.Ji(r.FK.from(a),0,0),1,!0))}(this,e,t,n,i),this}setNodeAttribute(e,t,n){return this.step(new F(e,t,n)),this}setDocAttribute(e,t){return this.step(new z(e,t)),this}addNodeMark(e,t){return this.step(new p(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError("No node at position "+e);if(t instanceof r.CU)t.isInSet(n.marks)&&this.step(new f(e,t));else{let r=n.marks,i,o=[];for(;i=t.isInSet(r);)o.push(new f(e,i)),r=i.removeFromSet(r);for(let e=o.length-1;e>=0;e--)this.step(o[e])}return this}split(e,t=1,n){return!function(e,t,n=1,i){let o=e.doc.resolve(t),s=r.FK.empty,a=r.FK.empty;for(let e=o.depth,t=o.depth-n,l=n-1;e>t;e--,l--){s=r.FK.from(o.node(e).copy(s));let t=i&&i[l];a=r.FK.from(t?t.type.create(t.attrs,a):o.node(e).copy(a))}e.step(new g(t,t,new r.Ji(s.append(a),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){var r;let i,o,s,a;return r=this,s=[],a=[],r.doc.nodesBetween(e,t,(r,l,d)=>{if(!r.isInline)return;let c=r.marks;if(!n.isInSet(c)&&d.type.allowsMarkType(n.type)){let d=Math.max(l,e),p=Math.min(l+r.nodeSize,t),f=n.addToSet(c);for(let e=0;e<c.length;e++)c[e].isInSet(f)||(i&&i.to==d&&i.mark.eq(c[e])?i.to=p:s.push(i=new u(d,p,c[e])));o&&o.to==d?o.to=p:a.push(o=new h(d,p,n))}}),s.forEach(e=>r.step(e)),a.forEach(e=>r.step(e)),this}removeMark(e,t,n){var i;let o,s;return i=this,o=[],s=0,i.doc.nodesBetween(e,t,(i,a)=>{if(!i.isInline)return;s++;let l=null;if(n instanceof r.sX){let e=i.marks,t;for(;t=n.isInSet(e);)(l||(l=[])).push(t),e=t.removeFromSet(e)}else n?n.isInSet(i.marks)&&(l=[n]):l=i.marks;if(l&&l.length){let n=Math.min(a+i.nodeSize,t);for(let t=0;t<l.length;t++){let r=l[t],i;for(let e=0;e<o.length;e++){let t=o[e];t.step==s-1&&r.eq(o[e].style)&&(i=t)}i?(i.to=n,i.step=s):o.push({style:r,from:Math.max(a,e),to:n,step:s})}}}),o.forEach(e=>i.step(new u(e.from,e.to,e.style))),this}clearIncompatible(e,t,n){return b(this,e,t,n),this}}},8810:(e,t,n)=>{"use strict";n.d(t,{c:()=>d});var r=n(83102),i=n(54530),o=n(24167);let s="recording",a="recordingPreserveRedoStack",l="paused";class d{store;dispose;state=s;pendingDiff=new h;stacks=(0,r.eU)("HistoryManager.stacks",{undos:f,redos:f},{isEqual:(e,t)=>e.undos===t.undos&&e.redos===t.redos});annotateError;constructor(e){this.store=e.store,this.annotateError=e.annotateError??o.lQ,this.dispose=this.store.addHistoryInterceptor((e,t)=>{if("user"===t)switch(this.state){case s:this.pendingDiff.apply(e.changes),this.stacks.get().redos.length>0&&this.stacks.update(({undos:e})=>({undos:e,redos:f}));break;case a:this.pendingDiff.apply(e.changes);break;case l:break;default:(0,o.h6)(this.state)}})}flushPendingDiff(){if(this.pendingDiff.isEmpty())return;let e=this.pendingDiff.clear();this.stacks.update(({undos:t,redos:n})=>({undos:t.push({type:"diff",diff:e}),redos:n}))}getNumUndos(){return this.stacks.get().undos.length+ +!this.pendingDiff.isEmpty()}getNumRedos(){return this.stacks.get().redos.length}_isReplaying=!1;isReplaying(){return this._isReplaying}_isInBatch=!1;batch(e,t){let n=this.state;n!==l&&t?.history&&(this.state=c[t.history]);try{if(this._isInBatch)return(0,r.hL)(e),this;this._isInBatch=!0;try{(0,r.hL)(e)}catch(e){throw this.annotateError(e),e}finally{this._isInBatch=!1}return this}finally{this.state=n}}_undo({pushToRedoStack:e,toMark:t}){let n=this.state,r=this._isReplaying;this.state=l,this._isReplaying=!0;try{let{undos:n,redos:r}=this.stacks.get(),s=this.pendingDiff.clear(),a=(0,i.RF)(s),l=(0,i.E8)(s);e&&!a&&(r=r.push({type:"diff",diff:s}));let d=!1;if(a)for(;n.head?.type==="stop";){let i=n.head;if(n=n.tail,e&&(r=r.push(i)),i.id===t){d=!0;break}}if(!d)t:for(;n.head;){let s=n.head;switch(n=n.tail,e&&(r=r.push(s)),s.type){case"diff":(0,i.Fl)(l,[(0,i.E8)(s.diff)]);break;case"stop":if(!t)break t;if(s.id===t){d=!0;break t}break;default:(0,o.h6)(s)}}if(!d&&t)return this.pendingDiff.restore(s),this;this.store.applyDiff(l,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:n,redos:r})}finally{this._isReplaying=r,this.state=n}return this}undo(){return this._undo({pushToRedoStack:!0}),this}redo(){let e=this.state,t=this._isReplaying;this.state=l,this._isReplaying=!0;try{this.flushPendingDiff();let{undos:e,redos:t}=this.stacks.get();if(0===t.length)return this;for(;t.head?.type==="stop";)e=e.push(t.head),t=t.tail;let n=(0,i.L4)();for(;t.head;){let r=t.head;if(e=e.push(r),t=t.tail,"diff"===r.type)(0,i.Fl)(n,[r.diff]);else break}this.store.applyDiff(n,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:e,redos:t})}finally{this._isReplaying=t,this.state=e}return this}bail(){return this._undo({pushToRedoStack:!1}),this}bailToMark(e){return e&&this._undo({pushToRedoStack:!1,toMark:e}),this}squashToMark(e){let t=this.stacks.get().undos,n=[];for(;t.head&&("stop"!==t.head.type||t.head.id!==e);)"diff"===t.head.type&&n.push(t.head.diff),t=t.tail;if(!t.head||t.head?.id!==e)return console.error("Could not find mark to squash to: ",e),this;if(0===n.length)return this;let r=(0,i.L4)();return(0,i.Fl)(r,n.reverse()),this.stacks.update(({redos:e})=>({undos:t.push({type:"diff",diff:r}),redos:e})),this}_mark(e){(0,r.hL)(()=>{this.flushPendingDiff(),this.stacks.update(({undos:t,redos:n})=>({undos:t.push({type:"stop",id:e}),redos:n}))})}clear(){this.stacks.set({undos:f,redos:f}),this.pendingDiff.clear()}getMarkIdMatching(e){let t=this.stacks.get().undos;for(;t.head;){if("stop"===t.head.type&&t.head.id.includes(e))return t.head.id;t=t.tail}return null}debug(){let{undos:e,redos:t}=this.stacks.get();return{undos:m(e),redos:m(t),pendingDiff:this.pendingDiff.debug(),state:this.state}}}let c={record:s,"record-preserveRedoStack":a,ignore:l};class h{diff=(0,i.L4)();isEmptyAtom=(0,r.eU)("PendingDiff.isEmpty",!0);clear(){let e=this.diff;return this.diff=(0,i.L4)(),this.isEmptyAtom.set(!0),e}restore(e){this.diff=e,this.isEmptyAtom.set((0,i.RF)(e))}isEmpty(){return this.isEmptyAtom.get()}apply(e){(0,i.Fl)(this.diff,[e]),u(e.added)||u(e.removed)?this.isEmptyAtom.set((0,i.RF)(this.diff)):this.isEmptyAtom.__unsafe__getWithoutCapture()&&this.isEmptyAtom.set(!u(e.updated))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}function u(e){for(let t in e)return!0;return!1}class p{length=0;head=null;tail=this;push(e){return new g(e,this)}}let f=new p;class g{constructor(e,t){this.head=e,this.tail=t,this.length=t.length+1}head;tail;length;push(e){return new g(e,this)}}function m(e){if(!e.length)return r.Ml;let t=[];for(;e.length;)t.push(e.head),e=e.tail;return t}},11421:(e,t,n)=>{"use strict";n.d(t,{YO:()=>a,bG:()=>l,of:()=>s});var r=n(83102),i=n(24167),o=n(41463);let s={},a=d("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),l={logPreventDefaults:d("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:d("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:d("logElementRemoves",{defaults:{all:!1}}),debugSvg:d("debugSvg",{defaults:{all:!1}}),showFps:d("showFps",{defaults:{all:!1}}),measurePerformance:d("measurePerformance",{defaults:{all:!1}}),throwToBlob:d("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:d("reconnectOnPing",{defaults:{all:!1}}),debugCursors:d("debugCursors",{defaults:{all:!1}}),forceSrgb:d("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:d("debugGeometry",{defaults:{all:!1}}),hideShapes:d("hideShapes",{defaults:{all:!1}}),editOnType:d("editOnType",{defaults:{all:!1}}),a11y:d("a11y",{defaults:{all:!1}}),debugElbowArrows:d("debugElbowArrows",{defaults:{all:!1}})};if("u">typeof Element){let e=Element.prototype.removeChild;(0,r.wv)("element removal logging",()=>{l.logElementRemoves.get()?Element.prototype.removeChild=function(t){return console.warn("[tldraw] removing child:",t),e.call(this,t)}:Element.prototype.removeChild=e})}function d(e,{defaults:t,shouldStoreForSession:n=!0}){var s;let a,l,h;return a=function(e){switch(c(()=>o.env.TLDRAW_ENV)??c(()=>o.env.VERCEL_PUBLIC_TLDRAW_ENV)??c(()=>o.env.NEXT_PUBLIC_TLDRAW_ENV)??"production"){case"production":return e.defaults.production??e.defaults.all;case"preview":case"staging":return e.defaults.staging??e.defaults.all;default:return e.defaults.development??e.defaults.all}}(s={name:e,defaults:t,shouldStoreForSession:n}),l=s.shouldStoreForSession?function(e){try{return JSON.parse((0,i._9)(`tldraw_debug:${e}`)??"null")}catch{return null}}(s.name):null,h=(0,r.eU)(`debug:${s.name}`,l??a),"u">typeof window&&(s.shouldStoreForSession&&(0,r.wv)(`debug:${s.name}`,()=>{let e=h.get();e===a?(0,i.ZJ)(`tldraw_debug:${s.name}`):(0,i.dQ)(`tldraw_debug:${s.name}`,JSON.stringify(e))}),Object.defineProperty(window,`tldraw${s.name.replace(/^[a-z]/,e=>e.toUpperCase())}`,{get:()=>h.get(),set(e){h.set(e)},configurable:!0})),Object.assign(h,s,{reset:()=>h.set(a)})}function c(e){try{return e()}catch{return null}}},12318:(e,t,n)=>{"use strict";n.d(t,{v:()=>f});var r=n(83102),i=n(54530),o=n(81467),s=n(24167),a=n(15727),l=n(46195),d=n(50139),c=n(38335),h=Object.defineProperty,u=Object.getOwnPropertyDescriptor,p=(e,t,n,r)=>{for(var i,o=r>1?void 0:r?u(t,n):t,s=e.length-1;s>=0;s--)(i=e[s])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&h(t,n,o),o};class f extends c.r{constructor(e){super(e),this.addEditorEvent("frame",this._onFrame)}_onFrame(e){this.updatePointerVelocity(e)}_originPagePoint=(0,r.eU)("originPagePoint",new l.l);getOriginPagePoint(){return this._originPagePoint.get()}get originPagePoint(){return this.getOriginPagePoint()}_originScreenPoint=(0,r.eU)("originScreenPoint",new l.l);getOriginScreenPoint(){return this._originScreenPoint.get()}get originScreenPoint(){return this.getOriginScreenPoint()}_previousPagePoint=(0,r.eU)("previousPagePoint",new l.l);getPreviousPagePoint(){return this._previousPagePoint.get()}get previousPagePoint(){return this.getPreviousPagePoint()}_previousScreenPoint=(0,r.eU)("previousScreenPoint",new l.l);getPreviousScreenPoint(){return this._previousScreenPoint.get()}get previousScreenPoint(){return this.getPreviousScreenPoint()}_currentPagePoint=(0,r.eU)("currentPagePoint",new l.l);getCurrentPagePoint(){return this._currentPagePoint.get()}get currentPagePoint(){return this.getCurrentPagePoint()}_currentScreenPoint=(0,r.eU)("currentScreenPoint",new l.l);getCurrentScreenPoint(){return this._currentScreenPoint.get()}get currentScreenPoint(){return this.getCurrentScreenPoint()}_pointerVelocity=(0,r.eU)("pointerVelocity",new l.l);getPointerVelocity(){return this._pointerVelocity.get()}get pointerVelocity(){return this.getPointerVelocity()}setPointerVelocity(e){this._pointerVelocity.set(e)}keys=new i.uw("keys");buttons=new i.uw("buttons");_isPen=(0,r.eU)("isPen",!1);getIsPen(){return this._isPen.get()}get isPen(){return this.getIsPen()}set isPen(e){this.setIsPen(e)}setIsPen(e){this._isPen.set(e)}_shiftKey=(0,r.eU)("shiftKey",!1);getShiftKey(){return this._shiftKey.get()}get shiftKey(){return this.getShiftKey()}set shiftKey(e){this.setShiftKey(e)}setShiftKey(e){this._shiftKey.set(e)}_metaKey=(0,r.eU)("metaKey",!1);getMetaKey(){return this._metaKey.get()}get metaKey(){return this.getMetaKey()}set metaKey(e){this.setMetaKey(e)}setMetaKey(e){this._metaKey.set(e)}_ctrlKey=(0,r.eU)("ctrlKey",!1);getCtrlKey(){return this._ctrlKey.get()}get ctrlKey(){return this.getCtrlKey()}set ctrlKey(e){this.setCtrlKey(e)}setCtrlKey(e){this._ctrlKey.set(e)}_altKey=(0,r.eU)("altKey",!1);getAltKey(){return this._altKey.get()}get altKey(){return this.getAltKey()}set altKey(e){this.setAltKey(e)}setAltKey(e){this._altKey.set(e)}getAccelKey(){return(0,d.g)({metaKey:this.getMetaKey(),ctrlKey:this.getCtrlKey()})}get accelKey(){return this.getAccelKey()}_isDragging=(0,r.eU)("isDragging",!1);getIsDragging(){return this._isDragging.get()}get isDragging(){return this.getIsDragging()}set isDragging(e){this.setIsDragging(e)}setIsDragging(e){this._isDragging.set(e)}_isPointing=(0,r.eU)("isPointing",!1);getIsPointing(){return this._isPointing.get()}get isPointing(){return this.getIsPointing()}set isPointing(e){this.setIsPointing(e)}setIsPointing(e){this._isPointing.set(e)}_isRightPointing=(0,r.eU)("isRightPointing",!1);getIsRightPointing(){return this._isRightPointing.get()}setIsRightPointing(e){this._isRightPointing.set(e)}_isPinching=(0,r.eU)("isPinching",!1);getIsPinching(){return this._isPinching.get()}get isPinching(){return this.getIsPinching()}set isPinching(e){this.setIsPinching(e)}setIsPinching(e){this._isPinching.set(e)}_isEditing=(0,r.eU)("isEditing",!1);getIsEditing(){return this._isEditing.get()}get isEditing(){return this.getIsEditing()}set isEditing(e){this.setIsEditing(e)}setIsEditing(e){this._isEditing.set(e)}_isPanning=(0,r.eU)("isPanning",!1);getIsPanning(){return this._isPanning.get()}get isPanning(){return this.getIsPanning()}set isPanning(e){this.setIsPanning(e)}setIsPanning(e){this._isPanning.set(e)}_isSpacebarPanning=(0,r.eU)("isSpacebarPanning",!1);getIsSpacebarPanning(){return this._isSpacebarPanning.get()}get isSpacebarPanning(){return this.getIsSpacebarPanning()}set isSpacebarPanning(e){this.setIsSpacebarPanning(e)}setIsSpacebarPanning(e){this._isSpacebarPanning.set(e)}_getHasCollaborators(){return this.editor.getCollaborators().length>0}_velocityPrevPoint=new l.l;updatePointerVelocity(e){let t=this.getCurrentScreenPoint(),n=this.getPointerVelocity();if(0===e)return;let r=l.l.Sub(t,this._velocityPrevPoint);this._velocityPrevPoint=t.clone();let i=r.len(),o=i?r.div(i):new l.l(0,0),s=1-Math.pow(.5,e/16),a=n.clone().lrp(o.mul(i/e),s);.01>Math.abs(a.x)&&(a.x=0),.01>Math.abs(a.y)&&(a.y=0),n.equals(a)||this._pointerVelocity.set(a)}updateFromEvent(e){let t=this._currentScreenPoint.__unsafe__getWithoutCapture(),n=this._currentPagePoint.__unsafe__getWithoutCapture(),i=this._isPinching.__unsafe__getWithoutCapture(),{screenBounds:s}=this.editor.store.unsafeGetWithoutCapture(o.O9),{x:d,y:c,z:h}=(0,r.Pm)(()=>this.editor.getCamera()),u=e.point.x-s.x,p=e.point.y-s.y,f=e.point.z??.5;this._previousScreenPoint.set(t),this._previousPagePoint.set(n),this._currentScreenPoint.set(new l.l(u,p));let g=u/h-d,m=p/h-c;isFinite(g)&&isFinite(m)&&this._currentPagePoint.set(new l.l(g,m,f)),this._isPen.set("pointer"===e.type&&e.isPen),("pointer_down"===e.name||i)&&(this._pointerVelocity.set(new l.l),this._originScreenPoint.set(this._currentScreenPoint.__unsafe__getWithoutCapture()),this._originPagePoint.set(this._currentPagePoint.__unsafe__getWithoutCapture())),this._getHasCollaborators()&&this.editor.run(()=>{let t=this._currentPagePoint.__unsafe__getWithoutCapture();this.editor.store.put([{id:o.G1,typeName:"pointer",x:t.x,y:t.y,lastActivityTimestamp:"pointer"===e.type&&e.pointerId===a.zm.CAMERA_MOVE?this.editor.store.unsafeGetWithoutCapture(o.G1)?.lastActivityTimestamp??Date.now():Date.now(),meta:{}}])},{history:"ignore"})}toJson(){return{originPagePoint:this._originPagePoint.get().toJson(),originScreenPoint:this._originScreenPoint.get().toJson(),previousPagePoint:this._previousPagePoint.get().toJson(),previousScreenPoint:this._previousScreenPoint.get().toJson(),currentPagePoint:this._currentPagePoint.get().toJson(),currentScreenPoint:this._currentScreenPoint.get().toJson(),pointerVelocity:this._pointerVelocity.get().toJson(),shiftKey:this._shiftKey.get(),metaKey:this._metaKey.get(),ctrlKey:this._ctrlKey.get(),altKey:this._altKey.get(),isPen:this._isPen.get(),isDragging:this._isDragging.get(),isPointing:this._isPointing.get(),isPinching:this._isPinching.get(),isEditing:this._isEditing.get(),isPanning:this._isPanning.get(),isSpacebarPanning:this._isSpacebarPanning.get(),keys:Array.from(this.keys.keys()),buttons:Array.from(this.buttons.keys())}}}p([s.oI],f.prototype,"_onFrame",1),p([r.EW],f.prototype,"_getHasCollaborators",1)},12894:(e,t,n)=>{"use strict";n.d(t,{K:()=>f,w:()=>p});for(var r={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},i={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},o="u">typeof navigator&&/Mac/.test(navigator.platform),s="u">typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),a=0;a<10;a++)r[48+a]=r[96+a]=String(a);for(var a=1;a<=24;a++)r[a+111]="F"+a;for(var a=65;a<=90;a++)r[a]=String.fromCharCode(a+32),i[a]=String.fromCharCode(a);for(var l in r)i.hasOwnProperty(l)||(i[l]=r[l]);var d=n(76865);let c="u">typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),h="u">typeof navigator&&/Win/.test(navigator.platform);function u(e,t,n=!0){return t.altKey&&(e="Alt-"+e),t.ctrlKey&&(e="Ctrl-"+e),t.metaKey&&(e="Meta-"+e),n&&t.shiftKey&&(e="Shift-"+e),e}function p(e){return new d.k_({props:{handleKeyDown:f(e)}})}function f(e){let t=function(e){let t=Object.create(null);for(let n in e)t[function(e){let t,n,r,i,o=e.split(/-(?!$)/),s=o[o.length-1];"Space"==s&&(s=" ");for(let e=0;e<o.length-1;e++){let s=o[e];if(/^(cmd|meta|m)$/i.test(s))i=!0;else if(/^a(lt)?$/i.test(s))t=!0;else if(/^(c|ctrl|control)$/i.test(s))n=!0;else if(/^s(hift)?$/i.test(s))r=!0;else if(/^mod$/i.test(s))c?i=!0:n=!0;else throw Error("Unrecognized modifier name: "+s)}return t&&(s="Alt-"+s),n&&(s="Ctrl-"+s),i&&(s="Meta-"+s),r&&(s="Shift-"+s),s}(n)]=e[n];return t}(e);return function(e,n){var a;let l=("Esc"==(a=!(o&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||s&&n.shiftKey&&n.key&&1==n.key.length||"Unidentified"==n.key)&&n.key||(n.shiftKey?i:r)[n.keyCode]||n.key||"Unidentified")&&(a="Escape"),"Del"==a&&(a="Delete"),"Left"==a&&(a="ArrowLeft"),"Up"==a&&(a="ArrowUp"),"Right"==a&&(a="ArrowRight"),"Down"==a&&(a="ArrowDown"),a),d,c=t[u(l,n)];if(c&&c(e.state,e.dispatch,e))return!0;if(1==l.length&&" "!=l){if(n.shiftKey){let r=t[u(l,n,!1)];if(r&&r(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(h&&n.ctrlKey&&n.altKey)&&(d=r[n.keyCode])&&d!=l){let r=t[u(d,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}},13004:(e,t,n)=>{"use strict";n.d(t,{f:()=>c});var r=n(83102),i=n(81467),o=n(97156),s=n(16038),a=Object.defineProperty,l=Object.getOwnPropertyDescriptor,d=(e,t,n,r)=>{for(var i,o=r>1?void 0:r?l(t,n):t,s=e.length-1;s>=0;s--)(i=e[s])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&a(t,n,o),o};class c{constructor(e,t){if(this.user=e,this.colorScheme=t,"u"<typeof window||!(0,s.CM)().matchMedia)return;const n=(0,s.CM)().matchMedia("(prefers-color-scheme: dark)");n?.matches&&this.systemColorScheme.set("dark");const r=e=>{e.matches?this.systemColorScheme.set("dark"):this.systemColorScheme.set("light")};n?.addEventListener("change",r),this.disposables.add(()=>n?.removeEventListener("change",r))}user;colorScheme;systemColorScheme=(0,r.eU)("systemColorScheme","light");disposables=new Set;dispose(){this.disposables.forEach(e=>e())}updateUserPreferences(e){this.user.setUserPreferences({...this.user.userPreferences.get(),...e})}getUserPreferences(){return{id:this.getExternalId(),name:this.getName(),locale:this.getLocale(),color:this.getColor(),animationSpeed:this.getAnimationSpeed(),areKeyboardShortcutsEnabled:this.getAreKeyboardShortcutsEnabled(),isSnapMode:this.getIsSnapMode(),colorScheme:this.user.userPreferences.get().colorScheme,isDarkMode:this.getIsDarkMode(),isWrapMode:this.getIsWrapMode(),isDynamicResizeMode:this.getIsDynamicResizeMode(),enhancedA11yMode:this.getEnhancedA11yMode(),inputMode:this.getInputMode(),isZoomDirectionInverted:this.getIsZoomDirectionInverted()}}getIsDarkMode(){switch(this.user.userPreferences.get().colorScheme??this.colorScheme){case"dark":return!0;case"light":default:return!1;case"system":return"dark"===this.systemColorScheme.get()}}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??o.Tj.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??o.Tj.animationSpeed}getAreKeyboardShortcutsEnabled(){return this.user.userPreferences.get().areKeyboardShortcutsEnabled??o.Tj.areKeyboardShortcutsEnabled}getExternalId(){return this.user.userPreferences.get().id}getId(){return this.getExternalId()}getRecordId(){return(0,i.dB)(this.getExternalId())}getName(){return this.user.userPreferences.get().name?.trim()??o.Tj.name}getLocale(){return this.user.userPreferences.get().locale??o.Tj.locale}getColor(){return this.user.userPreferences.get().color??o.Tj.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??o.Tj.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??o.Tj.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??o.Tj.isDynamicSizeMode}getIsPasteAtCursorMode(){return this.user.userPreferences.get().isPasteAtCursorMode??o.Tj.isPasteAtCursorMode}getEnhancedA11yMode(){return this.user.userPreferences.get().enhancedA11yMode??o.Tj.enhancedA11yMode}getInputMode(){return this.user.userPreferences.get().inputMode??o.Tj.inputMode}getIsZoomDirectionInverted(){return this.user.userPreferences.get().isZoomDirectionInverted??o.Tj.isZoomDirectionInverted}}d([r.EW],c.prototype,"getUserPreferences",1),d([r.EW],c.prototype,"getIsDarkMode",1),d([r.EW],c.prototype,"getEdgeScrollSpeed",1),d([r.EW],c.prototype,"getAnimationSpeed",1),d([r.EW],c.prototype,"getAreKeyboardShortcutsEnabled",1),d([r.EW],c.prototype,"getExternalId",1),d([r.EW],c.prototype,"getId",1),d([r.EW],c.prototype,"getRecordId",1),d([r.EW],c.prototype,"getName",1),d([r.EW],c.prototype,"getLocale",1),d([r.EW],c.prototype,"getColor",1),d([r.EW],c.prototype,"getIsSnapMode",1),d([r.EW],c.prototype,"getIsWrapMode",1),d([r.EW],c.prototype,"getIsDynamicResizeMode",1),d([r.EW],c.prototype,"getIsPasteAtCursorMode",1),d([r.EW],c.prototype,"getEnhancedA11yMode",1),d([r.EW],c.prototype,"getInputMode",1),d([r.EW],c.prototype,"getIsZoomDirectionInverted",1)},13248:(e,t,n)=>{"use strict";n.d(t,{sanitizeSvg:()=>k});let r=new Set(["svg","a","altglyph","altglyphdef","altglyphitem","animate","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","feblend","fecolormatrix","fecomponenttransfer","fecomposite","feconvolvematrix","fediffuselighting","fedisplacementmap","fedistantlight","fedropshadow","feflood","fefunca","fefuncb","fefuncg","fefuncr","fegaussianblur","feimage","femerge","femergenode","femorphology","feoffset","fepointlight","fespecularlighting","fespotlight","fetile","feturbulence","filter","font","foreignobject","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","set","stop","style","switch","symbol","text","textpath","title","tref","tspan","use","view","vkern"]),i=new Set(["a","b","blockquote","body","br","code","del","div","em","h1","h2","h3","h4","h5","h6","i","li","mark","ol","p","pre","span","strong","s","sub","sup","table","tbody","td","th","thead","tr","u","ul"]),o=new Set(["script","iframe","object","embed","form","input","textarea","select","button","link","meta","base","img","video","audio","source","picture","svg"]),s=new Set(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clip-path","clip-rule","clippathunits","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","diffuseconstant","direction","display","divisor","dominant-baseline","dur","dx","dy","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","from","fx","fy","g1","g2","glyph-name","glyphref","gradienttransform","gradientunits","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","kernelmatrix","kernelunitlength","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","mask","mask-type","maskcontentunits","maskunits","max","media","method","min","mode","name","numoctaves","offset","opacity","operator","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","pointer-events","points","preservealpha","preserveaspectratio","primitiveunits","r","radius","refx","refy","repeatcount","repeatdur","requiredfeatures","restart","result","role","rotate","rx","ry","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","text-anchor","text-decoration","text-rendering","textlength","to","transform","transform-origin","type","u1","u2","unicode","values","version","vert-adv-y","vert-origin-x","vert-origin-y","viewbox","visibility","width","word-spacing","wrap","writing-mode","x","x1","x2","xchannelselector","xlink:href","xml:id","xml:space","xlink:title","xmlns","xmlns:xlink","y","y1","y2","z","zoomandpan"]),a=new Set(["class","dir","href","id","lang","role","style","tabindex","title"]),l=/^data-/,d=/^aria-/,c=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g,h=/^(?:https?:|mailto:)/i,u=/^data:/i,p=/^data:image\/(?:png|jpeg|jpg|gif|webp|avif|bmp|tiff|x-icon|vnd\.microsoft\.icon)[;,]/i,f=/^data:image\/svg\+xml[;,]/i,g=/^#/,m=/^data:(?:image\/(?:png|jpeg|jpg|gif|webp|avif)|font\/(?:woff2?|opentype|truetype|sfnt)|application\/(?:x-font-woff|font-woff2?|x-font-ttf|x-font-opentype|font-sfnt))[;,]/i;function y(e){let t=e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\([^\n])/g,(e,t,n)=>{if(t){let e=parseInt(t,16);return e>1114111||0===e?"�":String.fromCodePoint(e)}return n});return(t=(t=(t=(t=t.replace(/@import\s+(?:url\s*\([^)]*\)|"[^"]*"|'[^']*')[^;]*;?|@import\b[^;]*;?/gi,"")).replace(/expression\s*\([^)]*\)/gi,"")).replace(/-moz-binding\s*:[^;]*/gi,"")).replace(/behavior\s*:[^;]*/gi,"")).replace(/url\s*\(\s*(['"]?)(.*?)\1\s*\)/gis,(e,t,n)=>{let r=n.replace(c,"");return m.test(r)||g.test(r)?e:""})}let b=new Set(["animate","set","animatecolor","animatetransform"]),x=/^(?:href|xlink:href|on)/i,w=/^on/i,v=new Set(["clip-path","cursor","fill","filter","marker-end","marker-mid","marker-start","mask","stroke"]);function S(e,t){for(let n=e.attributes.length-1;n>=0;n--){let r=e.attributes[n],i=r.name.toLowerCase(),o=i.replace(c,"");if(w.test(o)){e.removeAttribute(r.name);continue}if(!(l.test(i)||d.test(i))){if(!s.has(i)){e.removeAttribute(r.name);continue}if("href"===i||"xlink:href"===i){let n=function(e,t,n){let r=t.replace(c,""),i=e.tagName.toLowerCase();if("image"===i||"feimage"===i){if(p.test(r))return t;if(f.test(r)){let e;if(n>=10)return console.warn("Embedded SVG data URI recursion depth limit (10) reached"),null;try{let t=function(e){let t=e.search(/;base64,/i);if(t>=0){let n=e.slice(t+8),r=Uint8Array.from(atob(n),e=>e.charCodeAt(0));return new TextDecoder().decode(r)}let n=e.indexOf(",");return n<0?null:decodeURIComponent(e.slice(n+1))}(r);if(null===t)return null;e=t}catch{return null}let t=C(e,n+1);return t?"data:image/svg+xml;base64,"+btoa(Array.from(new TextEncoder().encode(t),e=>String.fromCharCode(e)).join("")):null}return null}return"use"===i?g.test(r)?t:null:"a"===i?h.test(r)?t:null:u.test(r)||g.test(r)?t:null}(e,r.value,t);null===n?e.removeAttribute(r.name):n!==r.value&&(r.value=n);continue}if("style"===i){r.value=y(r.value);continue}v.has(i)&&/url\s*\(/i.test(r.value)&&(r.value=y(r.value))}}}function C(e,t){let n=new DOMParser().parseFromString(e,"image/svg+xml");if(n.querySelector("parsererror"))return"";let s=n.documentElement;return"svg"!==s.tagName.toLowerCase()||(S(s,t),!function e(t,n,s){for(let u=t.children.length-1;u>=0;u--){let p=t.children[u],f=p.tagName.toLowerCase();"svg"===n?"foreignobject"===f?(S(p,s),e(p,"html",s)):"style"===f?(S(p,s),p.textContent&&(p.textContent=y(p.textContent))):b.has(f)&&function(e){let t=e.getAttribute("attributeName");return!!t&&x.test(t.replace(c,""))}(p)?p.remove():r.has(f)?(S(p,s),e(p,"svg",s)):p.remove():o.has(f)?p.remove():i.has(f)?(!function(e){let t=e.tagName.toLowerCase();for(let n=e.attributes.length-1;n>=0;n--){let r=e.attributes[n],i=r.name.toLowerCase(),o=i.replace(c,"");if(w.test(o)){e.removeAttribute(r.name);continue}if(!(l.test(i)||d.test(i))){if(!a.has(i)){e.removeAttribute(r.name);continue}if("href"===i){if("a"!==t){e.removeAttribute(r.name);continue}let n=r.value.replace(c,"");h.test(n)||e.removeAttribute(r.name);continue}"style"===i&&(r.value=y(r.value))}}}(p),e(p,"html",s)):p.remove()}}(s,"svg",t),0===s.children.length)?"":new XMLSerializer().serializeToString(s)}function k(e){return C(e,0)}},13656:(e,t,n)=>{"use strict";n.d(t,{p:()=>i,r:()=>r});let r="5.3.2",i={major:"2026-05-06T16:28:18.473Z",minor:"2026-08-05T11:39:54.978Z",patch:"2026-08-18T09:59:40.172Z"}},13982:(e,t,n)=>{"use strict";n.d(t,{$:()=>a,Y:()=>o});var r=n(83102),i=n(16038);let o={isSafari:!1,isIos:!1,isChromeForIos:!1,isFirefox:!1,isAndroid:!1,isWebview:!1,isDarwin:!1,hasCanvasSupport:!1,isTouchDevice:!1},s=!1;"u">typeof window&&("navigator"in window&&(o.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),o.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),o.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),o.isFirefox=/firefox/i.test(navigator.userAgent),o.isAndroid=/android/i.test(navigator.userAgent),o.isDarwin=(0,i.CM)().navigator.userAgent.toLowerCase().indexOf("mac")>-1),o.hasCanvasSupport="Promise"in window&&"HTMLCanvasElement"in window,s=o.isFirefox&&!o.isAndroid&&!o.isIos,o.isTouchDevice="navigator"in window&&window.navigator.maxTouchPoints>0||"function"==typeof window.matchMedia&&window.matchMedia("(any-pointer: coarse)").matches);let a=(0,r.eU)("tlenvReactive",{isCoarsePointer:!1,supportsP3ColorSpace:!1});if("u">typeof window&&"u">typeof CSS&&CSS.supports("color","color(display-p3 1 1 1)")){let e=window.matchMedia("(color-gamut: p3)"),t=()=>{let t=e.matches;t!==a.__unsafe__getWithoutCapture().supportsP3ColorSpace&&a.update(e=>({...e,supportsP3ColorSpace:t}))};t(),e.addEventListener("change",t)}if("u">typeof window&&!s){let e=(0,i.CM)().matchMedia&&(0,i.CM)().matchMedia("(any-pointer: coarse)");if(e){let t=()=>{let t=e.matches;t!==a.__unsafe__getWithoutCapture().isCoarsePointer&&a.update(e=>({...e,isCoarsePointer:t}))};t(),e.addEventListener("change",t)}(0,i.CM)().addEventListener("pointerdown",e=>{let t="mouse"!==e.pointerType;t!==a.__unsafe__getWithoutCapture().isCoarsePointer&&a.update(e=>({...e,isCoarsePointer:t}))},{capture:!0})}},15727:(e,t,n)=>{"use strict";n.d(t,{BV:()=>a,EI:()=>d,R_:()=>c,Tf:()=>h,bH:()=>l,mp:()=>o,zd:()=>i,zm:()=>s});var r=n(58347);let i={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.05,.1,.25,.5,1,2,4,8]},o={duration:0,easing:r.Z.easeInOutCubic},s={CAMERA_MOVE:-10},a=["top","right","bottom","left"],l=0,d=2,c=1,h=5},16038:(e,t,n)=>{"use strict";n.d(t,{$h:()=>a,CM:()=>h,MM:()=>l,YY:()=>o,gh:()=>u,hP:()=>s,jL:()=>c,oO:()=>d,wo:()=>i});var r=n(11421);function i(e){"cancelable"in e&&!e.cancelable||(e.preventDefault(),r.bG.logPreventDefaults.get()&&console.warn("preventDefault called on event:",e))}function o(e,t){if(e.setPointerCapture(t.pointerId),r.bG.logPointerCaptures.get()){let n=r.YO.get();n.set(e,(n.get(e)??0)+1),console.warn("setPointerCapture called on element:",e,t)}}function s(e,t){if(e.hasPointerCapture(t.pointerId)&&(e.releasePointerCapture(t.pointerId),r.bG.logPointerCaptures.get())){let n=r.YO.get();1===n.get(e)?n.delete(e):n.has(e)?n.set(e,n.get(e)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",e,t)}}function a(e,t,n){e&&e.style.setProperty(t,String(n))}function l(e,t){if(t.isConnected&&e.isConnected&&"function"==typeof e.moveBefore&&t.ownerDocument===e.ownerDocument)try{e.moveBefore(t,null);return}catch{}e.appendChild(t)}function d(e,t=!0){if(!e)return!1;let n=e.tagName.toLowerCase();return e.isContentEditable||"input"===n||"textarea"===n||t&&"select"===n||t&&"button"===n||e.classList.contains("tlui-slider__thumb")}function c(){return"u">typeof document?document:globalThis.document}function h(){return"u">typeof window?window:globalThis}function u(e=!0,t){return d((t??c()).activeElement,e)}},16398:(e,t,n)=>{"use strict";n.d(t,{O:()=>r});let r={wheel:"onWheel",pointer_down:"onPointerDown",pointer_move:"onPointerMove",long_press:"onLongPress",pointer_up:"onPointerUp",right_click:"onRightClick",middle_click:"onMiddleClick",key_down:"onKeyDown",key_up:"onKeyUp",key_repeat:"onKeyRepeat",cancel:"onCancel",complete:"onComplete",interrupt:"onInterrupt",double_click:"onDoubleClick",tick:"onTick"}},17347:(e,t,n)=>{"use strict";n.d(t,{c:()=>i});var r=n(12115);function i(e){let t=r.useRef(e);return r.useEffect(()=>{t.current=e}),r.useMemo(()=>(...e)=>t.current?.(...e),[])}(0,Object.defineProperty)(i,"name",{value:"useCallbackRef",configurable:!0})},17357:(e,t,n)=>{"use strict";n.d(t,{pX:()=>T});var r=n(24167),i=n(83102),o=n(54530);let s="patch",a="remove";function l(e){let t=null;for(let[n,i]of(0,r.iA)(e.added))t||(t={}),t[n]=["put",i];for(let[n,i]of(0,r.Ic)(e.updated)){let e=u(n,i);e&&(t||(t={}),t[i.id]=[s,e])}for(let n of Object.keys(e.removed))t||(t={}),t[n]=[a];return t}let d="delete",c="append",h="patch";function u(e,t,n=!1){return p(e,t,new Set(["props","meta"]),n)}function p(e,t,n,i){if(e===t)return null;let o=null;for(let s of Object.keys(e)){if(!(s in t)){o||(o={}),o[s]=[d];continue}let a=e[s],l=t[s];if(n?.has(s)||Array.isArray(a)&&Array.isArray(l)||"string"==typeof a&&"string"==typeof l){let e=function e(t,n,i){if(Object.is(t,n))return null;if(Array.isArray(t)&&Array.isArray(n))return function(t,n,i){if(Object.is(t,n))return null;if(t.length===n.length){let o=Math.max(t.length/5,1),s=[];for(let e=0;e<t.length;e++)if(!(0,r.n4)(t[e],n[e])&&(s.push(e),s.length>o))return["put",n];if(0===s.length)return null;let a={};for(let r of s){let o=t[r],s=n[r];if(o&&s)if("object"==typeof o&&"object"==typeof s){let t=e(o,s,i);t&&(a[r]=t)}else a[r]=["put",s];else a[r]=["put",s]}return[h,a]}for(let e=0;e<t.length;e++)if(!(0,r.n4)(t[e],n[e]))return["put",n];return[c,n.slice(t.length),t.length]}(t,n,i);if("string"==typeof t&&"string"==typeof n)return!i&&n.startsWith(t)?[c,n.slice(t.length),t.length]:["put",n];{if(!t||!n||"object"!=typeof t||"object"!=typeof n)return(0,r.n4)(t,n)?null:["put",n];let e=p(t,n,void 0,i);return e?[h,e]:null}}(a,l,i);e&&(o||(o={}),o[s]=e)}else(0,r.n4)(a,l)||(o||(o={}),o[s]=["put",l])}for(let n of Object.keys(t))n in e||(o||(o={}),o[n]=["put",t[n]]);return o}function f(e,t){let n=setInterval(e,t);return()=>clearInterval(n)}class g{lastServerClock=-1;lastServerInteractionTimestamp=Date.now();pendingPushRequests=[];unsentChanges={nextDiff:void 0,nextPresence:void 0};speculativeChanges={added:{},updated:{},removed:{}};disposables=[];fpsScheduler;sendUnsentChanges;scheduleRebase;store;socket;presenceState;presenceMode;isConnectedToRoom=!1;clientClock=0;onAfterConnect;onCustomMessageReceived;isDebugging=!1;debug(...e){this.isDebugging&&console.debug(...e)}presenceType;didCancel;constructor(e){this.didCancel=e.didCancel,this.presenceType=e.store.scopedTypes.presence.values().next().value??null,this.fpsScheduler=new r.$3(30),this.sendUnsentChanges=this.fpsScheduler.fpsThrottle(()=>{if(this.debug("sending unsent changes",{isConnectedToRoom:this.isConnectedToRoom,unsentChanges:this.unsentChanges}),!this.isConnectedToRoom||this.store.isPossiblyCorrupted()||!this.unsentChanges.nextDiff&&!this.unsentChanges.nextPresence)return;let e=this.unsentChanges.nextDiff?l(this.unsentChanges.nextDiff)??void 0:void 0,t=this.unsentChanges.nextPresence?function(e,t){if(!e&&t)return["put",t];if(e&&t){let n=u(e,t);if(!n)return;return[s,n]}}(this.lastPushedPresenceState,this.unsentChanges.nextPresence):void 0;if(!e&&!t)return;let n={type:"push",clientClock:this.clientClock,diff:e,presence:t};this.debug("sending push request",n),this.socket.sendMessage(n),this.unsentChanges.nextPresence&&(this.lastPushedPresenceState=this.unsentChanges.nextPresence),this.clientClock++,this.pendingPushRequests.push(n),this.unsentChanges.nextDiff=void 0,this.unsentChanges.nextPresence=void 0}),this.scheduleRebase=this.fpsScheduler.fpsThrottle(this.rebase),"u">typeof window&&(window.tlsync=this),this.store=e.store,this.socket=e.socket,this.onAfterConnect=e.onAfterConnect,this.onCustomMessageReceived=e.onCustomMessageReceived;let t=!1;this.presenceState=e.presence,this.presenceMode=e.presenceMode,this.disposables.push(this.store.listen(({changes:e})=>{if(this.didCancel?.())return this.close();this.debug("received store changes",{changes:e}),this.push(e)},{source:"user",scope:"document"}),this.socket.onReceiveMessage(n=>{if(this.didCancel?.())return this.close();this.debug("received message from server",n),this.handleServerEvent(n),t||(t=!0,e.onLoad(this))}),this.socket.onStatusChange(n=>{if(this.didCancel?.())return this.close();this.debug("socket status changed",n.status),"online"===n.status?this.sendConnectMessage():(this.resetConnection(),"error"===n.status&&(t=!0,e.onSyncError(n.reason),this.close()))}),f(()=>{if(this.didCancel?.())return this.close();if(this.debug("ping loop",{isConnectedToRoom:this.isConnectedToRoom}),this.isConnectedToRoom)try{this.socket.sendMessage({type:"ping"})}catch(e){console.warn("ping failed, resetting",e),this.resetConnection()}},5e3),f(()=>{if(this.didCancel?.())return this.close();if(this.debug("health check loop",{isConnectedToRoom:this.isConnectedToRoom}),!this.isConnectedToRoom)return;let e=Date.now()-this.lastServerInteractionTimestamp;e<1e4?this.debug("health check passed",{timeSinceLastServerInteraction:e}):(console.warn("Haven't heard from the server in a while, resetting connection..."),this.resetConnection())},1e4)),this.presenceState&&this.disposables.push((0,i.wv)("pushPresence",()=>{if(this.didCancel?.())return this.close();let e=this.presenceMode?.get();this.fpsScheduler.updateTargetFps(this.getSyncFps()),"full"===e&&this.pushPresence(this.presenceState.get())})),"online"===this.socket.connectionStatus&&this.sendConnectMessage()}latestConnectRequestId=null;sendConnectMessage(){this.isConnectedToRoom?console.error("sendConnectMessage called while already connected"):(this.debug("sending connect message"),this.latestConnectRequestId=(0,r.NF)(),this.socket.sendMessage({type:"connect",connectRequestId:this.latestConnectRequestId,schema:this.store.schema.serialize(),protocolVersion:8,lastServerClock:this.lastServerClock}))}resetConnection(e=!1){this.debug("resetting connection"),e&&(this.lastServerClock=0);let t=Object.keys(this.store.serialize("presence"));t.length>0&&this.store.mergeRemoteChanges(()=>{this.store.remove(t)}),this.lastPushedPresenceState=null,this.isConnectedToRoom=!1,this.pendingPushRequests=[],this.incomingDiffBuffer=[],this.unsentChanges.nextDiff=void 0,this.unsentChanges.nextPresence=void 0,"online"===this.socket.connectionStatus&&this.socket.restart()}didReconnect(e){if(this.debug("did reconnect",e),e.connectRequestId===this.latestConnectRequestId){if(this.latestConnectRequestId=null,this.isConnectedToRoom){console.error("didReconnect called while already connected"),this.resetConnection(!0);return}if(this.pendingPushRequests.length>0){console.error("pendingPushRequests should already be empty when we reconnect"),this.resetConnection(!0);return}(0,i.hL)(()=>{let t=this.speculativeChanges;this.speculativeChanges={added:{},updated:{},removed:{}},this.store.mergeRemoteChanges(()=>{let n={},i="wipe_all"===e.hydrationType;for(let[e,s]of(i||this.store.applyDiff((0,o.E8)(t),{runCallbacks:!1}),(0,r.iA)(this.store.serialize("all"))))(i&&this.store.scopedTypes.document.has(s.typeName)||s.typeName===this.presenceType)&&(n[e]=[a]);this.applyNetworkDiff({...n,...e.diff},!0),this.isConnectedToRoom=!0;let s=l(t);if(!s)return;let d=this.store.filterChangesByScope(this.store.extractingChanges(()=>{this.applyNetworkDiff(s,!0)}),"document");d&&this.push(d)}),this.onAfterConnect?.(this,{isReadonly:e.isReadonly,objectAccess:e.objectAccess??"write"});let n=this.presenceState?.get();n&&this.pushPresence(n)}),this.lastServerClock=e.serverClock}}incomingDiffBuffer=[];handleServerEvent(e){switch(this.debug("received server event",e),this.lastServerInteractionTimestamp=Date.now(),e.type){case"connect":this.didReconnect(e);break;case"patch":case"push_result":if(!this.isConnectedToRoom)break;this.incomingDiffBuffer.push(e),this.scheduleRebase();break;case"data":if(!this.isConnectedToRoom)break;this.incomingDiffBuffer.push(...e.data),this.scheduleRebase();break;case"incompatibility_error":console.error("incompatibility error is legacy and should no longer be sent by the server");break;case"pong":break;case"custom":this.onCustomMessageReceived?.call(null,e.data);break;default:(0,r.h6)(e)}}close(){this.debug("closing"),this.disposables.forEach(e=>e()),this.sendUnsentChanges.cancel?.(),this.scheduleRebase.cancel?.(),"u">typeof window&&window.tlsync===this&&delete window.tlsync}lastPushedPresenceState=null;pushPresence(e){this.store._flushHistory(),this.isConnectedToRoom&&(this.unsentChanges.nextPresence=e,this.sendUnsentChanges())}push(e){this.debug("push",e),(0,o.Fl)(this.speculativeChanges,[e]),this.isConnectedToRoom&&(this.unsentChanges.nextDiff||(this.unsentChanges.nextDiff={added:{},updated:{},removed:{}}),(0,o.Fl)(this.unsentChanges.nextDiff,[e]),this.sendUnsentChanges())}getSyncFps(){return this.presenceMode?.get()==="solo"?1:30}applyNetworkDiff(e,t){this.debug("applyNetworkDiff",e);let n={added:{},updated:{},removed:{}},i=!1;for(let[t,o]of(0,r.iA)(e))if("put"===o[0]){let e=this.store.get(t);e&&!(0,r.n4)(e,o[1])?(i=!0,n.updated[t]=[e,o[1]]):(i=!0,n.added[t]=o[1])}else if(o[0]===s){let e=this.store.get(t);if(!e)continue;let s=function e(t,n){let i;if(!t||"object"!=typeof t)return t;let o=Array.isArray(t),s=(e,n)=>{i||(i=o?[...t]:{...t}),o?i[Number(e)]=n:i[e]=n};for(let[a,l]of Object.entries(n))switch(l[0]){case"put":{let e=l[1];(0,r.n4)(t[a],e)||s(a,e);break}case c:{let e=l[1],n=l[2],r=t[a];Array.isArray(r)&&Array.isArray(e)&&r.length===n?s(a,[...r,...e]):"string"==typeof r&&"string"==typeof e&&r.length===n&&s(a,r+e);break}case h:if(t[a]&&"object"==typeof t[a]){let n=l[1],r=e(t[a],n);r!==t[a]&&s(a,r)}break;case d:a in t&&(i||(o?(console.error("Can't delete array item yet (this should never happen)"),i=[...t]):i={...t}),delete i[a])}return i??t}(e,o[1]);i=!0,n.updated[t]=[e,s]}else o[0]===a&&this.store.has(t)&&(i=!0,n.removed[t]=this.store.get(t));i&&this.store.applyDiff(n,{runCallbacks:t})}rebase=()=>{if(this.store._flushHistory(),0===this.incomingDiffBuffer.length)return;let e=this.incomingDiffBuffer;this.incomingDiffBuffer=[];try{this.store.mergeRemoteChanges(()=>{for(let t of(this.store.applyDiff((0,o.E8)(this.speculativeChanges),{runCallbacks:!1}),e)){if("patch"===t.type){this.applyNetworkDiff(t.diff,!0);continue}if(0===this.pendingPushRequests.length)throw Error("Received push_result but there are no pending push requests");if(this.pendingPushRequests[0].clientClock!==t.clientClock)throw Error("Received push_result for a push request that is not at the front of the queue");if("discard"===t.action)this.pendingPushRequests.shift();else if("commit"===t.action){let e=this.pendingPushRequests.shift();"diff"in e&&e.diff&&this.applyNetworkDiff(e.diff,!0)}else this.applyNetworkDiff(t.action.rebaseWithDiff,!0),this.pendingPushRequests.shift()}try{this.speculativeChanges=this.store.extractingChanges(()=>{for(let e of this.pendingPushRequests)"diff"in e&&e.diff&&this.applyNetworkDiff(e.diff,!0);if(!this.unsentChanges.nextDiff)return;let e=l(this.unsentChanges.nextDiff);e&&this.applyNetworkDiff(e,!0)})}catch(e){console.error(e),this.speculativeChanges={added:{},updated:{},removed:{}},this.resetConnection()}}),this.lastServerClock=e.at(-1)?.serverClock??this.lastServerClock}catch(e){console.error(e),this.store.ensureStoreIsUsable(),this.resetConnection()}}}function m(e,t,n){return e.addEventListener(t,n),()=>{e.removeEventListener(t,n)}}function y(...e){if("u">typeof window&&window.__tldraw_socket_debug){let t=new Date;console.log(`${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}.${t.getMilliseconds()}`,...e)}}class b{_ws=null;isDisposed=!1;_reconnectManager;close(){this.isDisposed=!0,this._reconnectManager.close(),this._ws?.close()}constructor(e){this._reconnectManager=new x(this,e)}_handleConnect(){y("handleConnect"),this._connectionStatus.set("online"),this.statusListeners.forEach(e=>e({status:"online"})),this._reconnectManager.connected()}_handleDisconnect(e,t,n,i){let o;switch(i=i||"UNKNOWN_ERROR",y("handleDisconnect",{currentStatus:this.connectionStatus,closeCode:t,reason:e}),e){case"closed":o=4099===t?"error":"offline";break;case"manual":o="offline"}1006!==t||n||(0,r.mc)("Could not open WebSocket connection. This might be because you're trying to load a URL that doesn't support websockets. Check the URL you're trying to connect to."),this.connectionStatus!==o&&("error"!==o||"offline"!==this.connectionStatus)&&(this._connectionStatus.set(o),this.statusListeners.forEach(e=>e("error"===o?{status:"error",reason:i}:{status:o}))),this._reconnectManager.disconnected()}_setNewSocket(e){(0,r.vA)(!this.isDisposed,"Tried to set a new websocket on a disposed socket"),(0,r.vA)(null===this._ws||this._ws.readyState===WebSocket.CLOSED||this._ws.readyState===WebSocket.CLOSING,`Tried to set a new websocket in when the existing one was ${this._ws?.readyState}`);let t=!1;e.onopen=()=>{y("ws.onopen"),(0,r.vA)(this._ws===e,"sockets must only be orphaned when they are CLOSING or CLOSED, so they can't open"),t=!0,this._handleConnect()},e.onclose=n=>{y("ws.onclose",n),this._ws===e?this._handleDisconnect("closed",n.code,t,n.reason):y("ignoring onclose for an orphaned socket")},e.onerror=t=>{y("ws.onerror",t),this._ws===e?this._handleDisconnect("closed"):y("ignoring onerror for an orphaned socket")},e.onmessage=t=>{let n;(0,r.vA)(this._ws===e,"sockets must only be orphaned when they are CLOSING or CLOSED, so they can't receive messages");try{n=JSON.parse(t.data.toString())}catch{(0,r.mc)("Received malformed WebSocket message. Restarting the connection."),this.restart();return}this.messageListeners.forEach(e=>e(n))},this._ws=e}_closeSocket(){null!==this._ws&&(this._ws.close(),this._ws=null,this._handleDisconnect("manual"))}_connectionStatus=(0,i.eU)("websocket connection status","initial");get connectionStatus(){let e=this._connectionStatus.get();return"initial"===e?"offline":e}sendMessage(e){if((0,r.vA)(!this.isDisposed,"Tried to send message on a disposed socket"),this._ws)if("online"===this.connectionStatus)for(let t of function(e,t=262144){if(e.length<t)return[e];{let n=[],r=0,i=e.length;for(;i>0;){let o=`${r}_`,s=Math.max(Math.min(t-o.length,i),1);n.unshift(o+e.slice(i-s,i)),i-=s,r++}return n}}(JSON.stringify(e)))this._ws.send(t);else console.warn("Tried to send message while "+this.connectionStatus)}messageListeners=new Set;onReceiveMessage(e){return(0,r.vA)(!this.isDisposed,"Tried to add message listener on a disposed socket"),this.messageListeners.add(e),()=>{this.messageListeners.delete(e)}}statusListeners=new Set;onStatusChange(e){return(0,r.vA)(!this.isDisposed,"Tried to add status listener on a disposed socket"),this.statusListeners.add(e),()=>{this.statusListeners.delete(e)}}restart(){(0,r.vA)(!this.isDisposed,"Tried to restart a disposed socket"),y("restarting"),this._closeSocket(),this._reconnectManager.maybeReconnected()}}class x{constructor(e,t){this.socketAdapter=e,this.getUri=t,this.subscribeToReconnectHints(),this.disposables.push(m(window,"offline",()=>{y("window went offline"),this.socketAdapter._closeSocket()})),this.state="pendingAttempt",this.intendedDelay=500,this.scheduleAttempt()}socketAdapter;getUri;isDisposed=!1;disposables=[()=>{this.reconnectTimeout&&clearTimeout(this.reconnectTimeout),this.recheckConnectingTimeout&&clearTimeout(this.recheckConnectingTimeout)}];reconnectTimeout=null;recheckConnectingTimeout=null;lastAttemptStart=null;intendedDelay=500;state;subscribeToReconnectHints(){if(this.disposables.push(m(window,"online",()=>{y("window went online"),this.maybeReconnected()}),m(document,"visibilitychange",()=>{document.hidden||(y("document became visible"),this.maybeReconnected())})),Object.prototype.hasOwnProperty.call(navigator,"connection")){let e=navigator.connection;this.disposables.push(m(e,"change",()=>{y("navigator.connection change"),this.maybeReconnected()}))}}scheduleAttempt(){(0,r.vA)("pendingAttempt"===this.state),y("scheduling a connection attempt"),Promise.resolve(this.getUri()).then(e=>{"pendingAttempt"!==this.state||this.isDisposed||((0,r.vA)(this.socketAdapter._ws?.readyState!==WebSocket.OPEN,"There should be no connection attempts while already connected"),this.lastAttemptStart=Date.now(),this.socketAdapter._setNewSocket(new WebSocket(e.replace(/^http(s)?:/,"ws$1:"))),this.state="pendingAttemptResult")})}getMaxDelay(){return document.hidden?3e5:2e3}getMinDelay(){return document.hidden?1e3:500}clearReconnectTimeout(){this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null)}clearRecheckConnectingTimeout(){this.recheckConnectingTimeout&&(clearTimeout(this.recheckConnectingTimeout),this.recheckConnectingTimeout=null)}maybeReconnected(){if(y("ReconnectManager.maybeReconnected"),this.clearRecheckConnectingTimeout(),this.socketAdapter._ws?.readyState===WebSocket.OPEN)return void y("ReconnectManager.maybeReconnected: already connected");if(this.socketAdapter._ws?.readyState===WebSocket.CONNECTING){y("ReconnectManager.maybeReconnected: connecting"),(0,r.vA)(this.lastAttemptStart,"ReadyState=CONNECTING without lastAttemptStart should be impossible");let e=Date.now()-this.lastAttemptStart;e<1e3?(y("ReconnectManager.maybeReconnected: connecting, rechecking later"),this.recheckConnectingTimeout=setTimeout(()=>this.maybeReconnected(),1e3-e)):(y("ReconnectManager.maybeReconnected: connecting, but for too long, retry now"),this.clearRecheckConnectingTimeout(),this.socketAdapter._closeSocket());return}y("ReconnectManager.maybeReconnected: closing/closed/null, retry now"),this.intendedDelay=500,this.disconnected()}disconnected(){if(y("ReconnectManager.disconnected"),this.socketAdapter._ws?.readyState!==WebSocket.OPEN&&this.socketAdapter._ws?.readyState!==WebSocket.CONNECTING){let e;y("ReconnectManager.disconnected: websocket is not OPEN or CONNECTING"),this.clearReconnectTimeout(),"connected"===this.state?(this.intendedDelay=this.getMinDelay(),e=this.intendedDelay):e=null!==this.lastAttemptStart?this.lastAttemptStart+this.intendedDelay-Date.now():0,e>0?(y("ReconnectManager.disconnected: delaying, delayLeft",e),this.state="delay",this.reconnectTimeout=setTimeout(()=>this.disconnected(),e)):(this.state="pendingAttempt",this.intendedDelay=Math.min(this.getMaxDelay(),1.5*Math.max(this.getMinDelay(),this.intendedDelay)),y("ReconnectManager.disconnected: attempting a connection, next delay",this.intendedDelay),this.scheduleAttempt())}}connected(){y("ReconnectManager.connected"),this.socketAdapter._ws?.readyState===WebSocket.OPEN&&(y("ReconnectManager.connected: websocket is OPEN"),this.state="connected",this.clearReconnectTimeout(),this.intendedDelay=500)}close(){this.disposables.forEach(e=>e()),this.isDisposed=!0}}var w=n(81467);(0,w.Wt)().serialize(),w.tS.create({id:w.yI}),w.tv.create({id:"page:page",name:"Page 1",index:"a1"});new TextEncoder,new TextDecoder;class v extends Error{constructor(e){super(`sync error: ${e}`),this.reason=e}reason;name="RemoteSyncError"}(0,r.lF)("@tldraw/sync-core","5.3.2","esm");var S=n(12115),C=n(23312);let k="multiplayer.client",P=()=>{};function T(e){let[t,n]=(0,C.oqt)(null),{uri:r,roomId:o="default",assets:s,users:a,onMount:l,connect:d,trackAnalyticsEvent:c,getUserPresence:h,onCustomMessageReceived:u,themes:p,...f}=e,m=(0,C.P1V)(p);(0,C.Mcl)(m),(0,C.AFA)(m);let y=(0,C.K4z)(f),x=(0,C.lIP)(h??C.Cho),w=(0,C._q_)(u??P);return(0,S.useEffect)(()=>{let e,t=(0,C.NF7)(),h=a?{currentUser:a.currentUser,resolve:a.resolve??(0,C.gP_)(e=>{let t=a.currentUser.get();return t&&t.id===(0,C.dBl)(e)?t:null})}:{currentUser:C.iPZ.currentUser,resolve:(0,C.gP_)(e=>{let t=C.iPZ.currentUser.get();if(t&&t.id===(0,C.dBl)(e))return t;let n=T.query.records("instance_presence").get().find(t=>t.userId===(0,C.dBl)(e));return n?C.XAu.create({id:(0,C.dBl)(e),name:n.userName,color:n.color}):null})},u=(0,C.EWP)("currentUser",()=>{let e=h.currentUser.get();if(e)return e;let t=(0,C.oEU)();return C.XAu.create({id:(0,C.dBl)(t.id),name:t.name??"",color:t.color??C.TjI.color})});if(d){if(r)throw Error("uri and connect cannot be used together");e=d({sessionId:C.OsR,storeId:t})}else if(r){if(d)throw Error("uri and connect cannot be used together");e=new b(async()=>{let e=new URL("string"==typeof r?r:await r());if(e.searchParams.has("sessionId"))throw Error('useSync. "sessionId" is a reserved query param name. Please use a different name');if(e.searchParams.has("storeId"))throw Error('useSync. "storeId" is a reserved query param name. Please use a different name');return e.searchParams.set("sessionId",C.OsR),e.searchParams.set("storeId",t),e.toString()})}else throw Error("uri or connect must be provided");let p=!1;function f(){return"error"===e.connectionStatus?"offline":e.connectionStatus}let m=(0,i.eU)("collaboration status",f()),S=e.onStatusChange(()=>{m.set(f())}),P=(0,i.eU)("sync mode","readwrite"),T=(0,C._zD)({id:t,schema:y,assets:s,users:h,onMount:l,collaboration:{status:m,mode:P}}),E=(0,C.S6A)(u,{getUserPresence:x})(T),I=T.query.ids("instance_presence"),_=(0,C.EWP)("presenceMode",()=>0===I.get().size?"solo":"full"),M=new g({store:T,socket:e,didCancel:()=>p,onLoad(e){c?.(k,{name:"load",roomId:o}),n(t=>({...t,readyClient:e}))},onSyncError(t){switch(console.error("sync error",t),t){case"NOT_FOUND":c?.(k,{name:"room-not-found",roomId:o});break;case"FORBIDDEN":c?.(k,{name:"forbidden",roomId:o});break;case"NOT_AUTHENTICATED":c?.(k,{name:"not-authenticated",roomId:o});break;case"RATE_LIMITED":c?.(k,{name:"rate-limited",roomId:o});break;default:c?.(k,{name:"sync-error:"+t,roomId:o})}n({error:new v(t)}),e.close()},onAfterConnect(e,{isReadonly:t,objectAccess:r}){n(e=>({...e,objectAccess:r})),(0,i.hL)(()=>{P.set(t?"readonly":"readwrite"),T.ensureStoreIsUsable()})},onCustomMessageReceived:w,presence:E,presenceMode:_});return()=>{p=!0,S(),M.close(),e.close()}},[s,l,d,a,o,y,n,c,r,x,w]),(0,C.hau)("remote synced store",()=>{if(!t)return{status:"loading"};if(t.error)return{status:"error",error:t.error};if(!t.readyClient)return{status:"loading"};let e=t.readyClient.socket.connectionStatus;return{status:"synced-remote",connectionStatus:"error"===e?"offline":e,store:t.readyClient.store,objectAccess:t.objectAccess??"write"}},[t])}var E=n(41463);function I(e){try{return e()}catch{return}}I(()=>"https://demo.tldraw.xyz"),I(()=>E.env.TLDRAW_IMAGE_URL),(0,r.lF)("@tldraw/sync","5.3.2","esm")},17858:(e,t,n)=>{"use strict";n.d(t,{m:()=>c});var r=n(83102),i=n(81467),o=n(58929),s=n(66122),a=Object.defineProperty,l=Object.getOwnPropertyDescriptor,d=(e,t,n,r)=>{for(var i,o=r>1?void 0:r?l(t,n):t,s=e.length-1;s>=0;s--)(i=e[s])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&a(t,n,o),o};class c{constructor(e){this.editor=e,this.shapeBounds=new o.N(this),this.handles=new s.O(this)}editor;shapeBounds;handles;_snapIndicators=(0,r.eU)("snapLines",void 0);getIndicators(){return this._snapIndicators.get()??r.Ml}clearIndicators(){this.getIndicators().length&&this._snapIndicators.set(void 0)}setIndicators(e){this._snapIndicators.set(e)}getSnapThreshold(){return this.editor.options.snapThreshold/this.editor.getZoomLevel()}getSnappableShapes(){let{editor:e}=this,t=e.getViewportPageBounds(),n=e.getSelectedShapeIds(),r=new Set,o=s=>{if((0,i.vc)(s)){let t=e.getShape(s);t&&e.isShapeFrameLike(t)&&r.add(s)}for(let i of e.getSortedChildIdsForParent(s)){if(n.includes(i))continue;let s=e.getShape(i);if(!s||!e.getShapeUtil(s).canSnap(s))continue;let a=e.getShapePageBounds(i);if(a&&t.includes(a)){if(e.isShapeOfType(s,"group")){o(i);continue}r.add(i)}}};return o(this.getCurrentCommonAncestor()??e.getCurrentPageId()),r}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}d([r.EW],c.prototype,"getSnapThreshold",1),d([r.EW],c.prototype,"getSnappableShapes",1),d([r.EW],c.prototype,"getCurrentCommonAncestor",1)},18314:(e,t,n)=>{"use strict";n.d(t,{_:()=>s,l:()=>a});var r=n(27394),i=n(24167),o=n(12115);function s(e){let t=(0,o.useRef)(void 0);return(0,o.useLayoutEffect)(()=>{t.current=e}),(0,o.useDebugValue)(e),(0,o.useCallback)((...e)=>{let n=t.current;return(0,i.vA)(n,"fn does not exist"),n(...e)},[])}function a(e){let t=(0,r.fp)("useReactiveEvent",()=>e);return(0,o.useLayoutEffect)(()=>{t.set(e)}),(0,o.useDebugValue)(e),(0,o.useCallback)((...e)=>{let n=t.get();return(0,i.vA)(n,"fn does not exist"),n(...e)},[t])}},19040:(e,t,n)=>{"use strict";n.d(t,{Z:()=>d});var r=n(12115),i=n(47650),o=n(55897),s=n(66294),a=n(95155),l=Object.defineProperty,d=r.forwardRef(l(function(e,t){let{container:n,...l}=e,[d,c]=r.useState(!1);(0,s.N)(()=>c(!0),[]);let h=n||d&&globalThis?.document?.body;return h?i.createPortal((0,a.jsx)(o.sG.div,{...l,ref:t}),h):null},"name",{value:"Portal",configurable:!0}))},19065:(e,t,n)=>{"use strict";n.d(t,{XN:()=>h,q1:()=>l});var r=n(24167),i=n(13982),o=n(65009),s=n(11421),a=n(16038);async function l(e,t){let{type:n,width:i,height:l,quality:h=1,pixelRatio:u=2,trimPadding:p=0,scale:f=1}=t;if(i<=0||l<=0)return null;let[g,m]=(0,o.A)(i*u,l*u);g=Math.floor(g),m=Math.floor(m);let y=g/i,b=await d(e,g,m);if(!b)return null;let x=p>0?function(e,t){let n=e.width,r=e.height,i=c(e,t);if(!i)return{canvas:e,width:n,height:r};let{cropLeft:o,cropTop:s,cropRight:l,cropBottom:d}=i,h=l-o,u=d-s,p=(0,a.jL)().createElement("canvas");return p.width=h,p.height=u,p.getContext("2d").drawImage(e,o,s,h,u,0,0,h,u),{canvas:p,width:h,height:u}}(b,p*f*y):{canvas:b,width:g,height:m},w=await new Promise(e=>x.canvas.toBlob(t=>{(!t||s.bG.throwToBlob.get())&&e(null),e(t)},"image/"+n,h));return w?{blob:"png"===n?r.ZA.setPhysChunk(new DataView(await w.arrayBuffer()),y,{type:"image/"+n}):w,width:x.width/y,height:x.height/y}:null}async function d(e,t,n){let o=await r.Sm.blobToDataUrl(new Blob([e],{type:"image/svg+xml"}));return new Promise(e=>{let s=(0,r._V)();s.crossOrigin="anonymous",s.onload=async()=>{i.Y.isSafari&&await (0,r.yy)(250);let o=(0,a.jL)().createElement("canvas"),l=o.getContext("2d");o.width=t,o.height=n,l.imageSmoothingEnabled=!0,l.imageSmoothingQuality="high",l.drawImage(s,0,0,t,n),e(o)},s.onerror=()=>{e(null)},s.src=o})}function c(e,t){let n=e.width,r=e.height,i=e.getContext("2d"),o=Math.ceil(t);if(o<=0||2*o>=n||2*o>=r)return null;let s=i.getImageData(0,0,n,r).data,a=s[0],l=s[1],d=s[2],c=s[3],h=0===c;function u(e){if(h)return s[e+3]>0;{if(s[e+3]!==c)return!0;let t=s[e],n=s[e+1],r=s[e+2];return t!==a||n!==l||r!==d}}let p=n-o,f=r-o,g=o;for(let e=0;e<o;e++){let t=!1;for(let r=0;r<n;r++)if(u((e*n+r)*4)){t=!0;break}if(t){g=e;break}}let m=f;for(let e=r-1;e>=f;e--){let t=!1;for(let r=0;r<n;r++)if(u((e*n+r)*4)){t=!0;break}if(t){m=e+1;break}}let y=o;for(let e=0;e<o;e++){let t=!1;for(let r=g;r<m;r++)if(u((r*n+e)*4)){t=!0;break}if(t){y=e;break}}let b=p;for(let e=n-1;e>=p;e--){let t=!1;for(let r=g;r<m;r++)if(u((r*n+e)*4)){t=!0;break}if(t){b=e+1;break}}return 0===y&&0===g&&b===n&&m===r?null:{cropLeft:y,cropTop:g,cropRight:b,cropBottom:m}}async function h(e,t){let{width:n,height:r,trimPadding:i,scale:o}=t;if(i<=0)return null;let s=Math.floor(n),a=Math.floor(r);if(s<=0||a<=0)return null;let l=await d(e,s,a);if(!l)return null;let h=c(l,i*o);if(!h)return null;let{cropLeft:u,cropTop:p,cropRight:f,cropBottom:g}=h,m=new DOMParser().parseFromString(e,"image/svg+xml").documentElement,y=m.getAttribute("viewBox");if(!y)return null;let[b,x,w,v]=y.split(/\s+/).map(Number),S=b+u/s*w,C=x+p/a*v,k=(f-u)/s*w,P=(g-p)/a*v,T=k*o,E=P*o;return m.setAttribute("viewBox",`${S} ${C} ${k} ${P}`),m.setAttribute("width",String(T)),m.setAttribute("height",String(E)),{svg:new XMLSerializer().serializeToString(m),width:T,height:E}}},19416:(e,t,n)=>{"use strict";n.d(t,{bL:()=>S,e0:()=>m,lg:()=>C,qW:()=>f});var r,i=n(12115),o=n(70379),s=n(55897),a=n(47527),l=n(17347),d=n(95155),c=Object.defineProperty,h=(e,t)=>c(e,"name",{value:t,configurable:!0}),u="dismissableLayer.update",p=i.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),f=i.forwardRef(h(function(e,t){let{disableOutsidePointerEvents:n=!1,deferPointerDownOutside:c=!1,onEscapeKeyDown:f,onPointerDownOutside:g,onFocusOutside:m,onInteractOutside:y,onDismiss:v,...S}=e,C=i.useContext(p),[k,P]=i.useState(null),T=k?.ownerDocument??globalThis?.document,[,E]=i.useState({}),I=(0,a.s)(t,P),_=Array.from(C.layers),[M]=[...C.layersWithOutsidePointerEventsDisabled].slice(-1),A=M?_.indexOf(M):-1,j=k?_.indexOf(k):-1,O=C.layersWithOutsidePointerEventsDisabled.size>0,D=j>=A,L=i.useRef(!1),R=b(e=>{g?.(e),y?.(e),e.defaultPrevented||v?.()},{ownerDocument:T,deferPointerDownOutside:c,isDeferredPointerDownOutsideRef:L,dismissableSurfaces:C.dismissableSurfaces,shouldHandlePointerDownOutside:i.useCallback(e=>{if(!(e instanceof Node))return!1;let t=[...C.branches].some(t=>t.contains(e));return D&&!t},[C.branches,D])}),F=x(e=>{if(c&&L.current)return;let t=e.target;![...C.branches].some(e=>e.contains(t))&&(m?.(e),y?.(e),e.defaultPrevented||v?.())},T),z=!!k&&j===_.length-1,N=(0,l.c)(e=>{"Escape"===e.key&&(f?.(e),!e.defaultPrevented&&v&&(e.preventDefault(),v()))});return i.useEffect(()=>{if(z)return T.addEventListener("keydown",N,{capture:!0}),()=>T.removeEventListener("keydown",N,{capture:!0})},[T,z,N]),i.useEffect(()=>{if(k)return n&&(0===C.layersWithOutsidePointerEventsDisabled.size&&(r=T.body.style.pointerEvents,T.body.style.pointerEvents="none"),C.layersWithOutsidePointerEventsDisabled.add(k)),C.layers.add(k),w(),()=>{n&&(C.layersWithOutsidePointerEventsDisabled.delete(k),0===C.layersWithOutsidePointerEventsDisabled.size&&(T.body.style.pointerEvents=r))}},[k,T,n,C]),i.useEffect(()=>()=>{k&&(C.layers.delete(k),C.layersWithOutsidePointerEventsDisabled.delete(k),w())},[k,C]),i.useEffect(()=>{let e=h(()=>E({}),"handleUpdate");return document.addEventListener(u,e),()=>document.removeEventListener(u,e)},[]),(0,d.jsx)(s.sG.div,{...S,ref:I,style:{pointerEvents:O?D?"auto":"none":void 0,...e.style},onFocusCapture:(0,o.mK)(e.onFocusCapture,F.onFocusCapture),onBlurCapture:(0,o.mK)(e.onBlurCapture,F.onBlurCapture),onPointerDownCapture:(0,o.mK)(e.onPointerDownCapture,R.onPointerDownCapture)})},"DismissableLayer")),g=i.forwardRef(h(function(e,t){let n=i.useContext(p),r=i.useRef(null),o=(0,a.s)(t,r);return i.useEffect(()=>{let e=r.current;if(e)return n.branches.add(e),()=>{n.branches.delete(e)}},[n.branches]),(0,d.jsx)(s.sG.div,{...e,ref:o})},"DismissableLayerBranch"));function m(){let e=i.useContext(p),[t,n]=i.useState(null);return i.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}h(m,"useDismissableLayerSurface");var y=h(()=>!0,"IS_TRUE");function b(e,t){let{ownerDocument:n=globalThis?.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:o,dismissableSurfaces:s,shouldHandlePointerDownOutside:a=y}=t,d=(0,l.c)(e),c=i.useRef(!1),u=i.useRef(!1),p=i.useRef(new Map),f=i.useRef(()=>{});return i.useEffect(()=>{function e(){u.current=!1,o.current=!1,p.current.clear()}function t(){return Array.from(p.current.values()).some(Boolean)}function i(e){if(!u.current)return;let t=e.target;t instanceof Node&&[...s].some(e=>e.contains(t))||p.current.set(e.type,!0),"click"===e.type&&window.setTimeout(()=>{u.current&&f.current()},0)}function l(e){u.current&&p.current.set(e.type,!1)}h(e,"resetOutsideInteraction"),h(t,"isOutsideInteractionIntercepted"),h(i,"handleInteractionCapture"),h(l,"handleInteractionBubble");let g=h(i=>{if(i.target&&!c.current){let s=function(){n.removeEventListener("click",f.current);let r=t();e(),r||v("dismissableLayer.pointerDownOutside",d,l,{discrete:!0})};if(h(s,"handleAndDispatchPointerDownOutsideEvent"),!a(i.target)){n.removeEventListener("click",f.current),e(),c.current=!1;return}let l={originalEvent:i};u.current=!0,o.current=r&&0===i.button,p.current.clear(),r&&0===i.button?(n.removeEventListener("click",f.current),f.current=s,n.addEventListener("click",f.current,{once:!0})):s()}else n.removeEventListener("click",f.current),e();c.current=!1},"handlePointerDown"),m=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(let e of m)n.addEventListener(e,i,!0),n.addEventListener(e,l);let y=window.setTimeout(()=>{n.addEventListener("pointerdown",g)},0);return()=>{for(let e of(window.clearTimeout(y),n.removeEventListener("pointerdown",g),n.removeEventListener("click",f.current),m))n.removeEventListener(e,i,!0),n.removeEventListener(e,l)}},[n,d,r,o,s,a]),{onPointerDownCapture:h(()=>c.current=!0,"onPointerDownCapture")}}function x(e,t=globalThis?.document){let n=(0,l.c)(e),r=i.useRef(!1);return i.useEffect(()=>{let e=h(e=>{e.target&&!r.current&&v("dismissableLayer.focusOutside",n,{originalEvent:e},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",e),()=>t.removeEventListener("focusin",e)},[t,n]),{onFocusCapture:h(()=>r.current=!0,"onFocusCapture"),onBlurCapture:h(()=>r.current=!1,"onBlurCapture")}}function w(){let e=new CustomEvent(u);document.dispatchEvent(e)}function v(e,t,n,{discrete:r}){let i=n.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&i.addEventListener(e,t,{once:!0}),r?(0,s.hO)(i,o):i.dispatchEvent(o)}h(b,"usePointerDownOutside"),h(x,"useFocusOutside"),h(w,"dispatchUpdate"),h(v,"handleAndDispatchCustomEvent");var S=f,C=g},19743:(e,t,n)=>{"use strict";n.d(t,{F:()=>o,S:()=>i});var r=n(81467);let i={id:"default",fontSize:16,lineHeight:1.35,strokeWidth:2,fonts:{draw:{fontFamily:r.xX.draw,faces:[{family:"tldraw_draw",src:{url:"tldraw_draw",format:"woff2"},weight:"normal"},{family:"tldraw_draw",src:{url:"tldraw_draw_bold",format:"woff2"},weight:"bold"},{family:"tldraw_draw",src:{url:"tldraw_draw_italic",format:"woff2"},weight:"normal",style:"italic"},{family:"tldraw_draw",src:{url:"tldraw_draw_italic_bold",format:"woff2"},weight:"bold",style:"italic"}]},sans:{fontFamily:r.xX.sans,faces:[{family:"tldraw_sans",src:{url:"tldraw_sans",format:"woff2"},weight:"normal",style:"normal"},{family:"tldraw_sans",src:{url:"tldraw_sans_bold",format:"woff2"},weight:"bold",style:"normal"},{family:"tldraw_sans",src:{url:"tldraw_sans_italic",format:"woff2"},weight:"normal",style:"italic"},{family:"tldraw_sans",src:{url:"tldraw_sans_italic_bold",format:"woff2"},weight:"bold",style:"italic"}]},serif:{fontFamily:r.xX.serif,faces:[{family:"tldraw_serif",src:{url:"tldraw_serif",format:"woff2"},weight:"normal",style:"normal"},{family:"tldraw_serif",src:{url:"tldraw_serif_bold",format:"woff2"},weight:"bold",style:"normal"},{family:"tldraw_serif",src:{url:"tldraw_serif_italic",format:"woff2"},weight:"normal",style:"italic"},{family:"tldraw_serif",src:{url:"tldraw_serif_italic_bold",format:"woff2"},weight:"bold",style:"italic"}]},mono:{fontFamily:r.xX.mono,faces:[{family:"tldraw_mono",src:{url:"tldraw_mono",format:"woff2"},weight:"normal",style:"normal"},{family:"tldraw_mono",src:{url:"tldraw_mono_bold",format:"woff2"},weight:"bold",style:"normal"},{family:"tldraw_mono",src:{url:"tldraw_mono_italic",format:"woff2"},weight:"normal",style:"italic"},{family:"tldraw_mono",src:{url:"tldraw_mono_italic_bold",format:"woff2"},weight:"bold",style:"italic"}]}},colors:{light:{text:"#000000",background:"#f9fafb",negativeSpace:"#f9fafb",solid:"#fcfffe",cursor:"black",noteBorder:"rgb(144, 144, 144)",snap:"hsl(0, 76%, 60%)",selectionStroke:"hsl(214, 84%, 56%)",selectionFill:"hsl(210, 100%, 56%, 24%)",brushFill:"hsl(0, 0%, 56%, 10.2%)",brushStroke:"hsl(0, 0%, 56%, 25.1%)",selectedContrast:"#ffffff",laser:"hsl(0, 100%, 50%)",black:{solid:"#1d1d1d",fill:"#1d1d1d",linedFill:"#363636",frameHeadingStroke:"#717171",frameHeadingFill:"#ffffff",frameStroke:"#717171",frameFill:"#ffffff",frameText:"#000000",noteFill:"#FCE19C",noteText:"#000000",semi:"#e8e8e8",pattern:"#494949",highlightSrgb:"#fddd00",highlightP3:"color(display-p3 0.972 0.8205 0.05)"},blue:{solid:"#4465e9",fill:"#4465e9",linedFill:"#6580ec",frameHeadingStroke:"#6681ec",frameHeadingFill:"#f9fafe",frameStroke:"#6681ec",frameFill:"#f9fafe",frameText:"#000000",noteFill:"#8AA3FF",noteText:"#000000",semi:"#dce1f8",pattern:"#6681ee",highlightSrgb:"#10acff",highlightP3:"color(display-p3 0.308 0.6632 0.9996)"},green:{solid:"#099268",fill:"#099268",linedFill:"#0bad7c",frameHeadingStroke:"#37a684",frameHeadingFill:"#f8fcfa",frameStroke:"#37a684",frameFill:"#f8fcfa",frameText:"#000000",noteFill:"#6FC896",noteText:"#000000",semi:"#d3e9e3",pattern:"#39a785",highlightSrgb:"#00ffc8",highlightP3:"color(display-p3 0.2536 0.984 0.7981)"},grey:{solid:"#9fa8b2",fill:"#9fa8b2",linedFill:"#bbc1c9",frameHeadingStroke:"#aaaaab",frameHeadingFill:"#fbfcfc",frameStroke:"#aaaaab",frameFill:"#fcfcfd",frameText:"#000000",noteFill:"#C0CAD3",noteText:"#000000",semi:"#eceef0",pattern:"#bcc3c9",highlightSrgb:"#cbe7f1",highlightP3:"color(display-p3 0.8163 0.9023 0.9416)"},"light-blue":{solid:"#4ba1f1",fill:"#4ba1f1",linedFill:"#7abaf5",frameHeadingStroke:"#6cb2f3",frameHeadingFill:"#f8fbfe",frameStroke:"#6cb2f3",frameFill:"#fafcff",frameText:"#000000",noteFill:"#9BC4FD",noteText:"#000000",semi:"#ddedfa",pattern:"#6fbbf8",highlightSrgb:"#00f4ff",highlightP3:"color(display-p3 0.1512 0.9414 0.9996)"},"light-green":{solid:"#4cb05e",fill:"#4cb05e",linedFill:"#7ec88c",frameHeadingStroke:"#6dbe7c",frameHeadingFill:"#f8fcf9",frameStroke:"#6dbe7c",frameFill:"#fafdfa",frameText:"#000000",noteFill:"#98D08A",noteText:"#000000",semi:"#dbf0e0",pattern:"#65cb78",highlightSrgb:"#65f641",highlightP3:"color(display-p3 0.563 0.9495 0.3857)"},"light-red":{solid:"#f87777",fill:"#f87777",linedFill:"#f99a9a",frameHeadingStroke:"#f89090",frameHeadingFill:"#fffafa",frameStroke:"#f89090",frameFill:"#fffbfb",frameText:"#000000",noteFill:"#F7A5A1",noteText:"#000000",semi:"#f4dadb",pattern:"#fe9e9e",highlightSrgb:"#ff7fa3",highlightP3:"color(display-p3 0.9988 0.5301 0.6397)"},"light-violet":{solid:"#e085f4",fill:"#e085f4",linedFill:"#e9abf7",frameHeadingStroke:"#e59bf5",frameHeadingFill:"#fefaff",frameStroke:"#e59bf5",frameFill:"#fefbff",frameText:"#000000",noteFill:"#DFB0F9",noteText:"#000000",semi:"#f5eafa",pattern:"#e9acf8",highlightSrgb:"#ff88ff",highlightP3:"color(display-p3 0.9676 0.5652 0.9999)"},orange:{solid:"#e16919",fill:"#e16919",linedFill:"#ea8643",frameHeadingStroke:"#e68544",frameHeadingFill:"#fef9f6",frameStroke:"#e68544",frameFill:"#fef9f6",frameText:"#000000",noteFill:"#FAA475",noteText:"#000000",semi:"#f8e2d4",pattern:"#f78438",highlightSrgb:"#ffa500",highlightP3:"color(display-p3 0.9988 0.6905 0.266)"},red:{solid:"#e03131",fill:"#e03131",linedFill:"#e75f5f",frameHeadingStroke:"#e55757",frameHeadingFill:"#fef7f7",frameStroke:"#e55757",frameFill:"#fef9f9",frameText:"#000000",noteFill:"#FC8282",noteText:"#000000",semi:"#f4dadb",pattern:"#e55959",highlightSrgb:"#ff636e",highlightP3:"color(display-p3 0.9992 0.4376 0.45)"},violet:{solid:"#ae3ec9",fill:"#ae3ec9",linedFill:"#be68d4",frameHeadingStroke:"#bc62d3",frameHeadingFill:"#fcf7fd",frameStroke:"#bc62d3",frameFill:"#fdf9fd",frameText:"#000000",noteFill:"#DB91FD",noteText:"#000000",semi:"#ecdcf2",pattern:"#bd63d3",highlightSrgb:"#c77cff",highlightP3:"color(display-p3 0.7469 0.5089 0.9995)"},yellow:{solid:"#f1ac4b",fill:"#f1ac4b",linedFill:"#f5c27a",frameHeadingStroke:"#f3bb6c",frameHeadingFill:"#fefcf8",frameStroke:"#f3bb6c",frameFill:"#fffdfa",frameText:"#000000",noteFill:"#FED49A",noteText:"#000000",semi:"#f9f0e6",pattern:"#fecb92",highlightSrgb:"#fddd00",highlightP3:"color(display-p3 0.972 0.8705 0.05)"},white:{solid:"#FFFFFF",fill:"#FFFFFF",linedFill:"#ffffff",semi:"#f5f5f5",pattern:"#f9f9f9",frameHeadingStroke:"#7d7d7d",frameHeadingFill:"#ffffff",frameStroke:"#7d7d7d",frameFill:"#ffffff",frameText:"#000000",noteFill:"#FFFFFF",noteText:"#000000",highlightSrgb:"#ffffff",highlightP3:"color(display-p3 1 1 1)"}},dark:{text:"hsl(210, 17%, 98%)",background:"hsl(240, 5%, 6.5%)",negativeSpace:"hsl(240, 5%, 6.5%)",solid:"#010403",cursor:"white",snap:"hsl(0, 76%, 60%)",selectionStroke:"hsl(214, 84%, 56%)",selectionFill:"hsl(209, 100%, 57%, 20%)",brushFill:"hsl(0, 0%, 56%, 10.2%)",brushStroke:"hsl(0, 0%, 56%, 25.1%)",selectedContrast:"#ffffff",laser:"hsl(0, 100%, 50%)",noteBorder:"rgb(20, 20, 20)",black:{solid:"#f2f2f2",fill:"#f2f2f2",linedFill:"#ffffff",frameHeadingStroke:"#5c5c5c",frameHeadingFill:"#252525",frameStroke:"#5c5c5c",frameFill:"#0c0c0c",frameText:"#f2f2f2",noteFill:"#2c2c2c",noteText:"#f2f2f2",semi:"#2c3036",pattern:"#989898",highlightSrgb:"#d2b700",highlightP3:"color(display-p3 0.8078 0.6225 0.0312)"},blue:{solid:"#4f72fc",fill:"#4f72fc",linedFill:"#3c5cdd",frameHeadingStroke:"#384994",frameHeadingFill:"#1C2036",frameStroke:"#384994",frameFill:"#11141f",frameText:"#f2f2f2",noteFill:"#2A3F98",noteText:"#f2f2f2",semi:"#262d40",pattern:"#3a4b9e",highlightSrgb:"#0079d2",highlightP3:"color(display-p3 0.0032 0.4655 0.7991)"},green:{solid:"#099268",fill:"#099268",linedFill:"#087856",frameHeadingStroke:"#10513C",frameHeadingFill:"#14241f",frameStroke:"#10513C",frameFill:"#0E1614",frameText:"#f2f2f2",noteFill:"#014429",noteText:"#f2f2f2",semi:"#253231",pattern:"#366a53",highlightSrgb:"#009774",highlightP3:"color(display-p3 0.0085 0.582 0.4604)"},grey:{solid:"#9398b0",fill:"#9398b0",linedFill:"#8388a5",frameHeadingStroke:"#42474D",frameHeadingFill:"#23262A",frameStroke:"#42474D",frameFill:"#151719",frameText:"#f2f2f2",noteFill:"#56595F",noteText:"#f2f2f2",semi:"#33373c",pattern:"#7c8187",highlightSrgb:"#9cb4cb",highlightP3:"color(display-p3 0.6299 0.7012 0.7856)"},"light-blue":{solid:"#4dabf7",fill:"#4dabf7",linedFill:"#2793ec",frameHeadingStroke:"#075797",frameHeadingFill:"#142839",frameStroke:"#075797",frameFill:"#0B1823",frameText:"#f2f2f2",noteFill:"#1F5495",noteText:"#f2f2f2",semi:"#2a3642",pattern:"#4d7aa9",highlightSrgb:"#00bdc8",highlightP3:"color(display-p3 0.0023 0.7259 0.7735)"},"light-green":{solid:"#40c057",fill:"#40c057",linedFill:"#37a44b",frameHeadingStroke:"#1C5427",frameHeadingFill:"#18251A",frameStroke:"#1C5427",frameFill:"#0F1911",frameText:"#f2f2f2",noteFill:"#21581D",noteText:"#f2f2f2",semi:"#2a3830",pattern:"#4e874e",highlightSrgb:"#00a000",highlightP3:"color(display-p3 0.2711 0.6172 0.0195)"},"light-red":{solid:"#ff8787",fill:"#ff8787",linedFill:"#ff6666",frameHeadingStroke:"#6f3232",frameHeadingFill:"#341818",frameStroke:"#6f3232",frameFill:"#181212",frameText:"#f2f2f2",noteFill:"#7a3333",noteText:"#f2f2f2",semi:"#3c2b2b",pattern:"#a56767",highlightSrgb:"#db005b",highlightP3:"color(display-p3 0.7849 0.0585 0.3589)"},"light-violet":{solid:"#e599f7",fill:"#e599f7",linedFill:"#dc71f4",frameHeadingStroke:"#6c367a",frameHeadingFill:"#2D2230",frameStroke:"#6c367a",frameFill:"#1C151E",frameText:"#f2f2f2",noteFill:"#762F8E",noteText:"#f2f2f2",semi:"#383442",pattern:"#9770a9",highlightSrgb:"#c400c7",highlightP3:"color(display-p3 0.7024 0.0403 0.753)"},orange:{solid:"#f76707",fill:"#f76707",linedFill:"#f54900",frameHeadingStroke:"#773a0e",frameHeadingFill:"#2f1d13",frameStroke:"#773a0e",frameFill:"#1c1512",frameText:"#f2f2f2",noteFill:"#7c3905",noteText:"#f2f2f2",semi:"#3b2e27",pattern:"#9f552d",highlightSrgb:"#d07a00",highlightP3:"color(display-p3 0.7699 0.4937 0.0085)"},red:{solid:"#e03131",fill:"#e03131",linedFill:"#c31d1d",frameHeadingStroke:"#701e1e",frameHeadingFill:"#301616",frameStroke:"#701e1e",frameFill:"#1b1313",frameText:"#f2f2f2",noteFill:"#7e201f",noteText:"#f2f2f2",semi:"#382726",pattern:"#8f3734",highlightSrgb:"#de002c",highlightP3:"color(display-p3 0.7978 0.0509 0.2035)"},violet:{solid:"#ae3ec9",fill:"#ae3ec9",linedFill:"#8f2fa7",frameHeadingStroke:"#6d1583",frameHeadingFill:"#27152e",frameStroke:"#6d1583",frameFill:"#1b0f21",frameText:"#f2f2f2",noteFill:"#5f1c70",noteText:"#f2f2f2",semi:"#342938",pattern:"#763a8b",highlightSrgb:"#9e00ee",highlightP3:"color(display-p3 0.5651 0.0079 0.8986)"},yellow:{solid:"#ffc034",fill:"#ffc034",linedFill:"#ffae00",frameHeadingStroke:"#684e12",frameHeadingFill:"#2a2113",frameStroke:"#684e12",frameFill:"#1e1911",frameText:"#f2f2f2",noteFill:"#8a5e1c",noteText:"#f2f2f2",semi:"#3b352b",pattern:"#fecb92",highlightSrgb:"#d2b700",highlightP3:"color(display-p3 0.8078 0.7225 0.0312)"},white:{solid:"#f3f3f3",fill:"#f3f3f3",linedFill:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",frameHeadingStroke:"#ffffff",frameHeadingFill:"#ffffff",frameStroke:"#ffffff",frameFill:"#ffffff",frameText:"#000000",noteFill:"#eaeaea",noteText:"#1d1d1d",highlightSrgb:"#ffffff",highlightP3:"color(display-p3 1 1 1)"}}}};function o(e,t,n){let r=e[t];return r&&"string"!=typeof r?r[n]:t}},20026:(e,t,n)=>{"use strict";n.d(t,{_:()=>d,f:()=>l});var r=n(81467),i=n(24167),o=n(54939),s=n(93286),a=n(46195);function l({editor:e,ids:t}){let n=(0,i.oE)(t.map(t=>e.getShape(t))),r=e.getShapesSharedRotation(t),o=e.getShapesRotatedPageBounds(t);if(!o)return null;let s=o.center.clone().rotWith(o.point,r);return{initialPageCenter:s,initialCursorAngle:s.angle(e.inputs.getOriginPagePoint()),initialShapesRotation:r,shapeSnapshots:n.map(t=>({shape:t,initialPagePoint:e.getShapePageTransform(t.id).point()}))}}function d({delta:e,editor:t,snapshot:n,stage:i,centerOverride:l}){let{initialPageCenter:c,shapeSnapshots:h}=n;t.updateShapes(h.map(({shape:n,initialPagePoint:i})=>{let d=(0,r.vc)(n.parentId)?t.getShapePageTransform(n.parentId):o.V.Identity(),h=a.l.RotWith(i,l??c,e),u=o.V.applyToPoint(o.V.Inverse(d),h),p=(0,s.rg)(n.rotation+e);return{id:n.id,type:n.type,x:u.x,y:u.y,rotation:p}}));let u=[];h.forEach(({shape:e})=>{let n=t.getShape(e.id);if(!n)return;let r=t.getShapeUtil(e);if("start"===i||"one-off"===i){let t=r.onRotateStart?.(e);t&&u.push(t)}let o=r.onRotate?.(e,n);if(o&&u.push(o),"end"===i||"one-off"===i){let t=r.onRotateEnd?.(e,n);t&&u.push(t)}}),u.length>0&&t.updateShapes(u)}},20172:(e,t,n)=>{"use strict";n.d(t,{U:()=>o});var r=n(95155),i=n(69730);function o({children:e,className:t="",...n}){return(0,r.jsx)("svg",{...n,className:i("tl-svg-container",t),"aria-hidden":"true",children:e})}},22036:(e,t,n)=>{"use strict";n.d(t,{Gq:()=>m,u0:()=>y,yp:()=>f});var r=n(95155),i=n(83102),o=n(27394);n(24167);var s=n(12115),a=n(67877),l=n(67863),d=n(26065),c=n(54939),h=n(28879),u=n(16038),p=n(1015);let f=(0,s.memo)(function({id:e,shape:t,util:n,index:h,backgroundIndex:f,opacity:b}){let x=(0,l.hG)(),{ShapeErrorFallback:w,ShapeWrapper:v}=(0,a.B)(),S=(0,s.useRef)(null),C=(0,s.useRef)(null);(0,s.useEffect)(()=>(0,i.wv)("load fonts",()=>{let t=x.fonts.getShapeFontFaces(e);x.fonts.requestFonts(t)}),[x,e]);let k=(0,s.useRef)({transform:"",clipPath:"none",width:0,height:0,x:0,y:0});(0,o.lX)("set shape stuff",()=>{let t=x.getShape(e);if(!t)return;let n=k.current,r=x.getShapeClipPath(e)??"none";r!==n.clipPath&&((0,u.$h)(S.current,"clip-path",r),(0,u.$h)(C.current,"clip-path",r),n.clipPath=r);let i=x.getShapePageTransform(e),o=c.V.toCssString(i),s=x.getShapeGeometry(t).bounds;o!==n.transform&&((0,u.$h)(S.current,"transform",o),(0,u.$h)(C.current,"transform",o),n.transform=o);let a=Math.max(s.width,1),l=Math.max(s.height,1);(a!==n.width||l!==n.height)&&((0,u.$h)(S.current,"width",a+"px"),(0,u.$h)(S.current,"height",l+"px"),(0,u.$h)(C.current,"width",a+"px"),(0,u.$h)(C.current,"height",l+"px"),n.width=a,n.height=l)},[x]),(0,s.useLayoutEffect)(()=>{let e=S.current,t=C.current;(0,u.$h)(e,"opacity",b),(0,u.$h)(t,"opacity",b),(0,u.$h)(e,"z-index",h),(0,u.$h)(t,"z-index",f)},[b,h,f]);let{register:P,unregister:T}=(0,d.R)();(0,s.useLayoutEffect)(()=>{let t=S.current;if(!t)return;let n=x.getCulledShapes().has(e);return P(e,t,C.current,n),()=>{T(e)}},[x,e,P,T]);let E=(0,s.useCallback)(e=>x.annotateError(e,{origin:"shape",willCrashApp:!1}),[x]);return t&&v?(0,r.jsxs)(r.Fragment,{children:[n.backgroundComponent&&(0,r.jsx)(v,{ref:C,shape:t,isBackground:!0,children:(0,r.jsx)(p.p,{fallback:w,onError:E,children:(0,r.jsx)(y,{shape:t,util:n})})}),(0,r.jsxs)(v,{ref:S,shape:t,isBackground:!1,children:[(0,r.jsx)(p.p,{fallback:w,onError:E,children:(0,r.jsx)(m,{shape:t,util:n})}),n.getAppOwnedElement&&(0,r.jsx)(g,{id:e,util:n})]})]}):null}),g=(0,s.memo)(function({id:e,util:t}){let n=(0,l.hG)(),i=(0,s.useRef)(null);return(0,s.useLayoutEffect)(()=>{let r=i.current;if(!r)return;let o=n.getShape(e);if(!o)return;let s=t.getAppOwnedElement?.(o);if(s)return s.isConnected,s.parentNode!==r&&(0,u.MM)(r,s),()=>{let r=n.getShape(e)??o;t.onReleaseAppOwnedElement?.(r,s)}},[n,e,t]),(0,r.jsx)("div",{ref:i,className:"tl-content-slot",draggable:!1})}),m=(0,s.memo)(function({shape:e,util:t}){return(0,o.A1)("InnerShape:"+e.type,()=>t.component(t.editor.store.unsafeGetWithoutCapture(e.id)),[t,e.id])},(e,t)=>(0,h.E)(e.shape,t.shape)&&e.util===t.util),y=(0,s.memo)(function({shape:e,util:t}){return(0,o.A1)("InnerShape:"+e.type,()=>t.backgroundComponent?.(t.editor.store.unsafeGetWithoutCapture(e.id)),[t,e.id])},(e,t)=>e.shape.props===t.shape.props&&e.shape.meta===t.shape.meta&&e.util===t.util)},22690:(e,t,n)=>{"use strict";n.d(t,{T:()=>r});var r={};n.r(r),n.d(r,{ArrayOfValidator:()=>d,DictValidator:()=>u,ObjectValidator:()=>c,UnionValidator:()=>h,ValidationError:()=>o,Validator:()=>l,any:()=>g,array:()=>I,arrayOf:()=>_,bigint:()=>T,boolean:()=>P,dict:()=>L,httpUrl:()=>G,indexKey:()=>q,integer:()=>S,jsonDict:()=>D,jsonValue:()=>O,linkUrl:()=>W,literal:()=>E,literalEnum:()=>H,model:()=>z,nonZeroFiniteNumber:()=>w,nonZeroInteger:()=>k,nonZeroNumber:()=>x,nullable:()=>B,number:()=>y,numberUnion:()=>F,object:()=>A,optional:()=>$,or:()=>X,positiveInteger:()=>C,positiveNumber:()=>b,setEnum:()=>N,srcUrl:()=>Y,string:()=>m,union:()=>R,unitInterval:()=>v,unknown:()=>f,unknownObject:()=>M});var i=n(24167);class o extends Error{constructor(e,t=[]){const n=function(e){if(!e.length)return null;let t="";for(let n of e)"number"==typeof n?t+=`.${n}`:n.startsWith("(")?t.endsWith(")")?t=`${t.slice(0,-1)}, ${n.slice(1)}`:t+=n:t+=`.${n}`;return(t=t.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,"")).startsWith(".")?t.slice(1):t}(t),r=e.split("\n").map((e,t)=>0===t?e:` ${e}`).join("\n");super(n?`At ${n}: ${r}`:r),this.rawMessage=e,this.path=t}rawMessage;path;name="ValidationError"}function s(e,t){if(t instanceof o)throw new o(t.rawMessage,[e,...t.path]);throw new o(t.toString(),[e])}function a(e){if(null===e)return"null";if(Array.isArray(e))return"an array";let t=typeof e;switch(t){case"bigint":case"boolean":case"function":case"number":case"string":case"symbol":return`a ${t}`;case"object":return`an ${t}`;case"undefined":return"undefined";default:(0,i.h6)(t)}}class l{constructor(e,t,n=!1){this.validationFn=e,this.validateUsingKnownGoodVersionFn=t,this.skipSameValueCheck=n}validationFn;validateUsingKnownGoodVersionFn;skipSameValueCheck;validate(e){let t=this.validationFn(e);return t}validateUsingKnownGoodVersion(e,t){return Object.is(e,t)?e:this.validateUsingKnownGoodVersionFn?this.validateUsingKnownGoodVersionFn(e,t):this.validate(t)}isValid(e){try{return this.validate(e),!0}catch{return!1}}nullable(){return B(this)}optional(){return $(this)}refine(e){return new l(t=>e(this.validate(t)),(t,n)=>{let r=this.validateUsingKnownGoodVersion(t,n);return Object.is(t,r)?t:e(r)},!0)}check(e,t){return"string"==typeof e?this.refine(n=>{try{t(n)}catch(t){s(`(check ${e})`,t)}return n}):this.refine(t=>(e(t),t))}}class d extends l{constructor(e){super(t=>{let n=I.validate(t);for(let t=0;t<n.length;t++)try{e.validate(n[t])}catch(e){s(t,e)}return n},(t,n)=>{if(Object.is(t,n))return t;if(!e.validateUsingKnownGoodVersion)return this.validate(n);let r=I.validate(n),i=t.length!==r.length;for(let n=0;n<r.length;n++){let o=r[n];if(n>=t.length){i=!0;try{e.validate(o)}catch(e){s(n,e)}continue}if(!Object.is(t[n],o))try{let r=e.validateUsingKnownGoodVersion(t[n],o);Object.is(r,t[n])||(i=!0)}catch(e){s(n,e)}}return i?n:t}),this.itemValidator=e}itemValidator;nonEmpty(){return this.check(e=>{if(0===e.length)throw new o("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(e=>{if(e.length<=1)throw new o("Expected an array with length greater than 1")})}}class c extends l{constructor(e,t=!1){const n=[],r=[];for(const[t,i]of Object.entries(e))n.push(t),r.push(i);super(l=>{if("object"!=typeof l||null===l)throw new o(`Expected object, got ${a(l)}`);for(let e=0;e<n.length;e++){let t=n[e];try{r[e].validate((0,i.g5)(l,t))}catch(e){s(t,e)}}if(!t){for(let t in l)if((0,i.mQ)(l,t)&&!(0,i.mQ)(e,t))throw new o("Unexpected property",[t])}return l},(l,d)=>{if(Object.is(l,d))return l;if("object"!=typeof d||null===d)throw new o(`Expected object, got ${a(d)}`);let c=!1;for(let e=0;e<n.length;e++){let t=n[e],o=(0,i.g5)(l,t),a=(0,i.g5)(d,t);if(!Object.is(o,a))try{let t=r[e],n=t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(o,a):t.validate(a);Object.is(n,o)||(c=!0)}catch(e){s(t,e)}}if(t){if(!c){for(let t of Object.keys(d))if(!(0,i.mQ)(e,t)&&!Object.is((0,i.g5)(l,t),(0,i.g5)(d,t))){c=!0;break}}}else for(let t in d)if((0,i.mQ)(d,t)&&!(0,i.mQ)(e,t))throw new o("Unexpected property",[t]);if(!c){for(let e in l)if((0,i.mQ)(l,e)&&!(0,i.mQ)(d,e)){c=!0;break}}return c?d:l}),this.config=e,this.shouldAllowUnknownProperties=t}config;shouldAllowUnknownProperties;allowUnknownProperties(){return new c(this.config,!0)}extend(e){return new c({...this.config,...e})}}class h extends l{constructor(e,t,n,r){super(t=>{this.expectObject(t);let n=this.getMatchingSchema(t);if(void 0===n)return this.unknownValueValidation(t,this.getVariant(t));try{return n.validate(t)}catch(n){s(`(${e} = ${this.getVariant(t)})`,n)}},(t,n)=>{this.expectObject(n),this.expectObject(t);let r=this.getMatchingSchema(n);if(void 0===r)return this.unknownValueValidation(n,this.getVariant(n));try{if((0,i.g5)(t,e)!==(0,i.g5)(n,e))return r.validate(n);if(r.validateUsingKnownGoodVersion)return r.validateUsingKnownGoodVersion(t,n);return r.validate(n)}catch(t){s(`(${e} = ${this.getVariant(n)})`,t)}}),this.key=e,this.config=t,this.unknownValueValidation=n,this.useNumberKeys=r}key;config;unknownValueValidation;useNumberKeys;expectObject(e){if("object"!=typeof e||null===e)throw new o(`Expected an object, got ${a(e)}`,[])}getVariant(e){return(0,i.g5)(e,this.key)}getMatchingSchema(e){let t=(0,i.g5)(e,this.key);if(this.useNumberKeys||"string"==typeof t){if(this.useNumberKeys){let e=Number(t);if(e-e!=0)throw new o(`Expected a number for key "${this.key}", got "${t}"`)}}else throw new o(`Expected a string for key "${this.key}", got ${a(t)}`);return(0,i.mQ)(this.config,t)?this.config[t]:void 0}validateUnknownVariants(e){return new h(this.key,this.config,e,this.useNumberKeys)}}class u extends l{constructor(e,t){super(n=>{if("object"!=typeof n||null===n)throw new o(`Expected object, got ${a(n)}`);for(let r in n)if((0,i.mQ)(n,r))try{e.validate(r),t.validate(n[r])}catch(e){s(r,e)}return n},(n,r)=>{if("object"!=typeof r||null===r)throw new o(`Expected object, got ${a(r)}`);let l=!1,d=0;for(let o in r){if(!(0,i.mQ)(r,o))continue;d++;let a=r[o];if(!(0,i.mQ)(n,o)){l=!0;try{e.validate(o),t.validate(a)}catch(e){s(o,e)}continue}let c=n[o];if(!Object.is(c,a))try{let e=t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(c,a):t.validate(a);Object.is(e,c)||(l=!0)}catch(e){s(o,e)}}if(!l){let e=0;for(let t in n)(0,i.mQ)(n,t)&&e++;e!==d&&(l=!0)}return l?r:n}),this.keyValidator=e,this.valueValidator=t}keyValidator;valueValidator}function p(e){return new l(t=>{if(typeof t!==e)throw new o(`Expected ${e}, got ${a(t)}`);return t})}let f=new l(e=>e),g=new l(e=>e),m=p("string"),y=new l(e=>{if(Number.isFinite(e))return e;if("number"!=typeof e)throw new o(`Expected number, got ${a(e)}`);if(e!=e)throw new o("Expected a number, got NaN");throw new o(`Expected a finite number, got ${e}`)}),b=new l(e=>{if(Number.isFinite(e)&&e>=0)return e;if("number"!=typeof e)throw new o(`Expected number, got ${a(e)}`);if(e!=e)throw new o("Expected a number, got NaN");if(e<0)throw new o(`Expected a positive number, got ${e}`);throw new o(`Expected a finite number, got ${e}`)}),x=new l(e=>{if(Number.isFinite(e)&&e>0)return e;if("number"!=typeof e)throw new o(`Expected number, got ${a(e)}`);if(e!=e)throw new o("Expected a number, got NaN");if(e<=0)throw new o(`Expected a non-zero positive number, got ${e}`);throw new o(`Expected a finite number, got ${e}`)}),w=new l(e=>{if(Number.isFinite(e)&&0!==e)return e;if("number"!=typeof e)throw new o(`Expected number, got ${a(e)}`);if(e!=e)throw new o("Expected a number, got NaN");if(0===e)throw new o("Expected a non-zero number, got 0");throw new o(`Expected a finite number, got ${e}`)}),v=new l(e=>{if(Number.isFinite(e)&&e>=0&&e<=1)return e;if("number"!=typeof e)throw new o(`Expected number, got ${a(e)}`);if(e!=e)throw new o("Expected a number, got NaN");throw new o(`Expected a number between 0 and 1, got ${e}`)}),S=new l(e=>{if(Number.isInteger(e))return e;if("number"!=typeof e)throw new o(`Expected number, got ${a(e)}`);if(e!=e)throw new o("Expected a number, got NaN");if(e-e!=0)throw new o(`Expected a finite number, got ${e}`);throw new o(`Expected an integer, got ${e}`)}),C=new l(e=>{if(Number.isInteger(e)&&e>=0)return e;if("number"!=typeof e)throw new o(`Expected number, got ${a(e)}`);if(e!=e)throw new o("Expected a number, got NaN");if(e-e!=0)throw new o(`Expected a finite number, got ${e}`);if(e<0)throw new o(`Expected a positive integer, got ${e}`);throw new o(`Expected an integer, got ${e}`)}),k=new l(e=>{if(Number.isInteger(e)&&e>0)return e;if("number"!=typeof e)throw new o(`Expected number, got ${a(e)}`);if(e!=e)throw new o("Expected a number, got NaN");if(e-e!=0)throw new o(`Expected a finite number, got ${e}`);if(e<=0)throw new o(`Expected a non-zero positive integer, got ${e}`);throw new o(`Expected an integer, got ${e}`)}),P=p("boolean"),T=p("bigint");function E(e){return new l(t=>{if(t!==e)throw new o(`Expected ${e}, got ${JSON.stringify(t)}`);return e})}let I=new l(e=>{if(!Array.isArray(e))throw new o(`Expected an array, got ${a(e)}`);return e});function _(e){return new d(e)}let M=new l(e=>{if("object"!=typeof e||null===e)throw new o(`Expected object, got ${a(e)}`);return e});function A(e){return new c(e)}function j(e){return"object"==typeof e&&null!==e&&(Object.getPrototypeOf(e)===Object.prototype||null===Object.getPrototypeOf(e)||Object.getPrototypeOf(e)===i.DM)}let O=new l(e=>{if(function e(t){if(null===t||"number"==typeof t||"string"==typeof t||"boolean"==typeof t)return!0;if(Array.isArray(t)){for(let n=0;n<t.length;n++)if(!e(t[n]))return!1;return!0}if(j(t)){for(let n in t)if((0,i.mQ)(t,n)&&!e(t[n]))return!1;return!0}return!1}(e))return e;throw new o(`Expected json serializable value, got ${typeof e}`)},(e,t)=>{if(Array.isArray(e)&&Array.isArray(t)){let n=e.length!==t.length;for(let r=0;r<t.length;r++){if(r>=e.length){n=!0,O.validate(t[r]);continue}let i=e[r],o=t[r];!Object.is(i,o)&&(Object.is(O.validateUsingKnownGoodVersion(i,o),i)||(n=!0))}return n?t:e}if(!(j(e)&&j(t)))return O.validate(t);{let n=!1;for(let r in t){if(!(0,i.mQ)(t,r))continue;if(!(0,i.mQ)(e,r)){n=!0,O.validate(t[r]);continue}let o=e[r],s=t[r];!Object.is(o,s)&&(Object.is(O.validateUsingKnownGoodVersion(o,s),o)||(n=!0))}if(!n){for(let r in e)if((0,i.mQ)(e,r)&&!(0,i.mQ)(t,r)){n=!0;break}}return n?t:e}});function D(){return L(m,O)}function L(e,t){return new u(e,t)}function R(e,t){return new h(e,t,(n,r)=>{throw new o(`Expected one of ${Object.keys(t).map(e=>JSON.stringify(e)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!1)}function F(e,t){return new h(e,t,(n,r)=>{throw new o(`Expected one of ${Object.keys(t).map(e=>JSON.stringify(e)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!0)}function z(e,t){return new l(n=>{try{return t.validate(n)}catch(t){s(e,t)}},(n,r)=>{try{if(t.validateUsingKnownGoodVersion)return t.validateUsingKnownGoodVersion(n,r);return t.validate(r)}catch(t){s(e,t)}})}function N(e){return new l(t=>{if(!e.has(t)){let n=Array.from(e,e=>JSON.stringify(e)).join(" or ");throw new o(`Expected ${n}, got ${t}`)}return t})}function $(e){return new l(t=>{if(void 0!==t)return e.validate(t)},(t,n)=>{if(void 0!==n)return e.validateUsingKnownGoodVersion&&void 0!==t?e.validateUsingKnownGoodVersion(t,n):e.validate(n)},e instanceof l&&e.skipSameValueCheck)}function B(e){return new l(t=>null===t?null:e.validate(t),(t,n)=>null===n?null:e.validateUsingKnownGoodVersion&&null!==t?e.validateUsingKnownGoodVersion(t,n):e.validate(n),e instanceof l&&e.skipSameValueCheck)}function H(...e){return N(new Set(e))}function U(e){try{return new URL(e)}catch{if(e.startsWith("/")||e.startsWith("./"))try{return new URL(e,"http://example.com")}catch{}throw new o(`Expected a valid url, got ${JSON.stringify(e)}`)}}let K=new Set(["http:","https:","mailto:"]),W=m.check(e=>{if(""===e)return;let t=U(e);if(!K.has(t.protocol.toLowerCase()))throw new o(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),V=new Set(["http:","https:","data:","asset:"]),Y=m.check(e=>{if(""===e)return;let t=U(e);if(!V.has(t.protocol.toLowerCase()))throw new o(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),G=m.check(e=>{if(""!==e&&!U(e).protocol.toLowerCase().match(/^https?:$/))throw new o(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),q=m.refine(e=>{try{return(0,i.fb)(e),e}catch{throw new o(`Expected an index key, got ${JSON.stringify(e)}`)}});function X(e,t){return new l(n=>{try{return e.validate(n)}catch{return t.validate(n)}})}(0,i.lF)("@tldraw/validate","5.3.2","esm")},22954:(e,t,n)=>{"use strict";n.d(t,{Eq:()=>d});var r=new WeakMap,i=new WeakMap,o={},s=0,a=function(e){return e&&(e.host||a(e.parentNode))},l=function(e,t,n,l){var d=(Array.isArray(e)?e:[e]).map(function(e){if(t.contains(e))return e;var n=a(e);return n&&t.contains(n)?n:(console.error("aria-hidden",e,"in not contained inside",t,". Doing nothing"),null)}).filter(function(e){return!!e});o[n]||(o[n]=new WeakMap);var c=o[n],h=[],u=new Set,p=new Set(d),f=function(e){!e||u.has(e)||(u.add(e),f(e.parentNode))};d.forEach(f);var g=function(e){!e||p.has(e)||Array.prototype.forEach.call(e.children,function(e){if(u.has(e))g(e);else try{var t=e.getAttribute(l),o=null!==t&&"false"!==t,s=(r.get(e)||0)+1,a=(c.get(e)||0)+1;r.set(e,s),c.set(e,a),h.push(e),1===s&&o&&i.set(e,!0),1===a&&e.setAttribute(n,"true"),o||e.setAttribute(l,"true")}catch(t){console.error("aria-hidden: cannot operate on ",e,t)}})};return g(t),u.clear(),s++,function(){h.forEach(function(e){var t=r.get(e)-1,o=c.get(e)-1;r.set(e,t),c.set(e,o),t||(i.has(e)||e.removeAttribute(l),i.delete(e)),o||e.removeAttribute(n)}),--s||(r=new WeakMap,r=new WeakMap,i=new WeakMap,o={})}},d=function(e,t,n){void 0===n&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=t||("u"<typeof document?null:(Array.isArray(e)?e[0]:e).ownerDocument.body);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),l(r,i,n,"aria-hidden")):function(){return null}}},23312:(e,t,n)=>{"use strict";n.d(t,{cee:()=>pO,ZCT:()=>pA,EF7:()=>pD,_LY:()=>pg,P3o:()=>pj,jhL:()=>pb,QVi:()=>r.QVi,A8:()=>r.A8,Unq:()=>pM,Yem:()=>pT,HQo:()=>cS,Hif:()=>u5,F0h:()=>p1,h4e:()=>pv,fPn:()=>pp,foZ:()=>pw,L4x:()=>pf,Gto:()=>pF,hDc:()=>r.hDc,ikG:()=>pu,hUo:()=>pk,fnc:()=>pP,RIo:()=>pR,Yby:()=>pz,dEX:()=>pL,V8r:()=>r.V8r,l7k:()=>py,jkh:()=>pI,GN7:()=>px,D7F:()=>pC,bIq:()=>ph,bKc:()=>pE,dGg:()=>u1,JGv:()=>u2,pY9:()=>uW,Isx:()=>uq,tJe:()=>uG,$EK:()=>uJ,C_T:()=>u0,f1t:()=>uQ,pPo:()=>uX,hLL:()=>u3,k2C:()=>uZ,T:()=>r.T,OsR:()=>r.OsR,SDB:()=>pm,Z1z:()=>x5,Cgn:()=>so,FUD:()=>aE,LRd:()=>ak,Tme:()=>pc,jY:()=>pS,XAu:()=>r.XAu,gPO:()=>p_,EWP:()=>r.EWP,gP_:()=>r.gP_,S6A:()=>r.S6A,n6Y:()=>r.n6Y,_zD:()=>r._zD,dBl:()=>r.dBl,Ats:()=>bY,TjI:()=>r.TjI,iPZ:()=>r.iPZ,Cho:()=>r.Cho,oEU:()=>r.oEU,woC:()=>r.woC,Mcl:()=>r.Mcl,AFA:()=>r.AFA,mfH:()=>r.mfH,P1V:()=>r.P1V,NF7:()=>r.NF7,NFA:()=>r.NFA,jH7:()=>A,hGv:()=>r.hGv,BSi:()=>r.BSi,_q_:()=>r._q_,FxY:()=>sz,lIP:()=>r.lIP,oqt:()=>r.oqt,K4z:()=>r.K4z,Bdt:()=>M,hau:()=>r.hau});var r=n(93647);let i=e=>.65*e+.35*(0,r.dwc)(e*r.PI/2),o=e=>({size:e,thinning:0,streamline:(0,r.wwY)(e,[9,16],[.64,.74],!0),smoothing:.62,simulatePressure:!1,easing:r.Z4H.linear});function s({strokeWidth:e,showAsComplete:t}){return{size:1+e,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:r.Z4H.easeOutSine,last:t}}function a(e,t,n,s){let a=e.isComplete||n;if(s)if(!e.isPen)return{...o(t),last:a};else return{...{size:t,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:r.Z4H.linear},last:a};if("draw"===e.dash)if(e.isPen)return{size:1+1.2*t,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:i,last:a};else return{...{size:t,thinning:.5,streamline:(0,r.wwY)(t,[9,16],[.64,.74],!0),smoothing:.62,easing:r.Z4H.easeOutSine,simulatePressure:!0},last:a};return{...o(t),last:a}}function l(e,t=1,n=1){let i=[];for(let o of e)!function(e,t,n,i=[]){let o=r.K6A.decodePoints(e.path,e.dim);if(1!==t||1!==n)for(let e of o)e.x*=t,e.y*=n;if("free"===e.type||o.length<2)i.push(...o.map(r.l2P.From));else{let e=r.l2P.From(o[0]),t=r.l2P.From(o[1]),n=r.l2P.Dist(t,e);if(0===n)i.push(e);else{let o=r.l2P.Tan(t,e),s=Math.min(1,Math.floor(n/4)),a=r.l2P.Add(e,r.l2P.Mul(o,s)),l=r.l2P.Add(t,r.l2P.Mul(o,-s)),d=Math.max(4,Math.floor(n/16));i.push(e,...r.l2P.PointsBetween(a,l,d,r.Z4H.easeInOutCubic),t)}}}(o,t,n,i);return i}var d=n(95155);class c{static lineThroughPoints(e,t){let n=new c;n.moveTo(e[0].x,e[0].y,{...t,offset:t?.endOffsets??t?.offset});for(let r=1;r<e.length;r++){let i=r===e.length-1;n.lineTo(e[r].x,e[r].y,i?{offset:t?.endOffsets}:void 0)}return n}static cubicSplineThroughPoints(e,t){let n=new c,r=e.length,i=r-2;n.moveTo(e[0].x,e[0].y,{...t,offset:t?.endOffsets??t?.offset});for(let o=0;o<r-1;o++){let r,s,a,l,d,c=0===o?e[0]:e[o-1],h=e[o],u=e[o+1],p=o===i?u:e[o+2];0===o?(r=c.x,s=c.y):(r=h.x+(u.x-c.x)/6*1.25,s=h.y+(u.y-c.y)/6*1.25),o===i?(a=u.x,l=u.y,d={offset:t?.endOffsets}):(a=u.x-(p.x-h.x)/6*1.25,l=u.y-(p.y-h.y)/6*1.25),n.cubicBezierTo(u.x,u.y,r,s,a,l,d)}return n}commands=[];lastMoveTo=null;assertHasMoveTo(){return(0,r.vAR)(this.lastMoveTo,"Start an SVGPathBuilder with `.moveTo()`"),this.lastMoveTo}moveTo(e,t,n){return this.lastMoveTo={type:"move",x:e,y:t,closeIdx:null,isClose:!1,opts:n},this.commands.push(this.lastMoveTo),this}lineTo(e,t,n){return this.assertHasMoveTo(),this.commands.push({type:"line",x:e,y:t,isClose:!1,opts:n}),this}circularArcTo(e,t,n,r,i,o){return this.arcTo(e,e,t,n,0,r,i,o)}arcTo(e,t,n,i,o,s,a,l){this.assertHasMoveTo();let d=this.commands[this.commands.length-1].x,c=this.commands[this.commands.length-1].y;if(d===s&&c===a)return this;if(0===e||0===t)return this.lineTo(s,a,l);let h=Math.sin(o),u=Math.cos(o),p=Math.abs(e),f=Math.abs(t),g=(d-s)/2,m=(c-a)/2,y=u*g+h*m,b=-h*g+u*m,x=y*y/(p*p)+b*b/(f*f);if(x>1){let e=Math.sqrt(x);p*=e,f*=e}let w=(p*p*f*f-p*p*b*b-f*f*y*y)/(p*p*b*b+f*f*y*y),v=(n!==i?1:-1)*Math.sqrt(w=w<0?0:w),S=p*b/f*v,C=-(f*y)/p*v,k=u*S-h*C+(d+s)/2,P=h*S+u*C+(c+a)/2,T=Math.atan2((b-C)/f,(y-S)/p),E=Math.atan2((-b-C)/f,(-y-S)/p);!i&&E>T?E-=2*Math.PI:i&&E<T&&(E+=2*Math.PI);let I=E-T,_=Math.max(p,f)*Math.abs(I),M=Math.min(4,Math.ceil(Math.abs(I)/(Math.PI/2))),A=Math.ceil((0,r.qnK)(_)/M),j=I/M,O=e=>({x:k+p*Math.cos(e)*u-f*Math.sin(e)*h,y:P+p*Math.cos(e)*h+f*Math.sin(e)*u}),D=e=>({x:-p*Math.sin(e)*u-f*Math.cos(e)*h,y:-p*Math.sin(e)*h+f*Math.cos(e)*u});for(let e=0;e<M;e++){let t=T+e*j,n=T+(e+1)*j,r=n-t,i=O(t),o=O(n),s=D(t),a=D(n),d=4/3*Math.tan(r/4),c=i.x+d*s.x,h=i.y+d*s.y,u=o.x-d*a.x,p=o.y-d*a.y,f=0===e?l:{...l,mergeWithPrevious:!0};this.cubicBezierToWithResolution(o.x,o.y,c,h,u,p,f,A)}return this}cubicBezierTo(e,t,n,r,i,o,s){return this.cubicBezierToWithResolution(e,t,n,r,i,o,s)}cubicBezierToWithResolution(e,t,n,r,i,o,s,a){return this.assertHasMoveTo(),this.commands.push({type:"cubic",x:e,y:t,cp1:{x:n,y:r},cp2:{x:i,y:o},isClose:!1,opts:s,resolution:a}),this}close(){let e=this.assertHasMoveTo(),t=this.commands[this.commands.length-1];return(0,r.YY0)(e.x,t.x)&&(0,r.YY0)(e.y,t.y)?t.isClose=!0:this.commands.push({type:"line",x:e.x,y:e.y,isClose:!0}),e.closeIdx=this.commands.length-1,this.lastMoveTo=null,this}transform(e){let t=new c;for(let n of this.commands){let[i,o]=r.V8r.applyToXY(e,n.x,n.y);switch(n.type){case"move":case"line":t.commands.push({...n,x:i,y:o,_info:void 0});break;case"cubic":{let[s,a]=r.V8r.applyToXY(e,n.cp1.x,n.cp1.y),[l,d]=r.V8r.applyToXY(e,n.cp2.x,n.cp2.y);t.commands.push({...n,x:i,y:o,cp1:{x:s,y:a},cp2:{x:l,y:d},_info:void 0});break}default:(0,r.h6G)(n,"type")}}return t}toD(e={}){let{startIdx:t=0,endIdx:n=this.commands.length,onlyFilled:i=!1}=e,o=[],s=!1,a=!1,l=!1,d=e=>{if(a||0===e)return;a=!0;let t=this.commands[e-1];o.push("M",(0,r.WMC)(t.x),(0,r.WMC)(t.y))};for(let e=t;e<n;e++){let t=this.commands[e];switch(t.type){case"move":{let e=t.opts?.geometry!==!1&&(t.opts?.geometry?.isFilled??!1);i&&!e?s=!0:(s=!1,a=!0,l=!0,o.push("M",(0,r.WMC)(t.x),(0,r.WMC)(t.y)));break}case"line":if(s)break;d(e),t.isClose&&l?o.push("Z"):o.push("L",(0,r.WMC)(t.x),(0,r.WMC)(t.y));break;case"cubic":if(s)break;d(e),o.push("C",(0,r.WMC)(t.cp1.x),(0,r.WMC)(t.cp1.y),(0,r.WMC)(t.cp2.x),(0,r.WMC)(t.cp2.y),(0,r.WMC)(t.x),(0,r.WMC)(t.y));break;default:(0,r.h6G)(t,"type")}}return o.join(" ")}toSvg(e){if("none"===e.style)return null;if(e.forceSolid)return this.toSolidSvg(e);switch(e.style){case"solid":return this.toSolidSvg(e);case"dashed":case"dotted":return this.toDashedSvg(e);case"draw":return this.toDrawSvg(e);default:(0,r.h6G)(e,"style")}}toPath2D(e){return"none"===e.style?new Path2D:new Path2D(e.forceSolid||"solid"===e.style?this.toD({onlyFilled:e.onlyFilled}):"draw"===e.style?this.toDrawD(e):this.toD({onlyFilled:e.onlyFilled}))}toGeometry(){let e=[],t=null;for(let n=0;n<this.commands.length;n++){let i=this.commands[n];"move"===i.type&&(t&&t.opts?.geometry!==!1&&e.push(new u(this,t.startIdx,n,{...t.opts?.geometry,isFilled:t.opts?.geometry?.isFilled??!1,isClosed:null!==t.moveCommand.closeIdx})),t={startIdx:n,moveCommand:i,opts:i.opts,isClosed:!1}),i.isClose&&((0,r.vAR)(t,"No current move command"),t.isClosed=!0)}return(t&&t.opts?.geometry!==!1&&e.push(new u(this,t.startIdx,this.commands.length,{...t.opts?.geometry,isFilled:t.opts?.geometry?.isFilled??!1,isClosed:null!==t.moveCommand.closeIdx})),(0,r.vAR)(e.length>0),1===e.length)?e[0]:new r.IQE({children:e})}toSolidSvg(e){let{strokeWidth:t,props:n}=e;return(0,d.jsx)("path",{strokeWidth:t,d:this.toD({onlyFilled:e.onlyFilled}),...n})}toDashedSvg(e){let t,{style:n,strokeWidth:i,snap:o,lengthRatio:s,props:{markerStart:a,markerEnd:l,...c}={}}=e,h=[],u=!1,p=!1,f=null,g=()=>{if(!f)return;let{startIdx:t,endIdx:c,isFirst:u,isLast:p,length:g,lineOpts:m,pathIsClosed:y}=f;if(f=null,t===c&&"move"===this.commands[t].type)return;let b=m?.dashStart??e.start,x=m?.dashEnd??e.end,{strokeDasharray:w,strokeDashoffset:v}=(0,r.EK8)(g,i,{style:n,snap:o,lengthRatio:s,start:u?b??(y?"outset":"none"):"outset",end:p?x??(y?"outset":"none"):"outset"}),S=this.toD({startIdx:t,endIdx:c+1});h.push((0,d.jsx)("path",{d:S,strokeDasharray:w,strokeDashoffset:v,markerStart:u?a:void 0,markerEnd:p?l:void 0},h.length))};for(let n=0;n<this.commands.length;n++){let r=this.commands[n],i=this.commands[n-1];if("move"===r.type){u=null!==r.closeIdx;let n=r.opts?.geometry!==!1&&(r.opts?.geometry?.isFilled??!1);e.onlyFilled&&!n?p=!0:(p=!1,t=r.opts);continue}if(p)continue;let o=this.calculateSegmentLength(i,r),s="move"===i.type,a=r.isClose||n===this.commands.length-1||this.commands[n+1]?.type==="move";f&&r.opts?.mergeWithPrevious?(f.length+=o,f.endIdx=n,f.isLast=a):(g(),f={startIdx:n,endIdx:n,isFirst:s,isLast:a,length:o,lineOpts:t,pathIsClosed:u})}return g(),(0,d.jsx)("g",{strokeWidth:i,...c,children:h})}toDrawSvg(e){return(0,d.jsx)("path",{strokeWidth:e.strokeWidth,d:this.toDrawD(e),...e.props})}toDrawD(e){let{strokeWidth:t,randomSeed:n,offset:i=t/3,roundness:o=2*t,passes:s=2,onlyFilled:a=!1}=e,l=[],d=this.getCommandInfo(),c=[],u=null;for(let e=0;e<this.commands.length;e++){let t=this.commands[e],n=t.opts?.offset??i,s=t.opts?.roundness??o;"move"===t.type&&(u=e);let a=t.isClose?(0,r.Z1O)(u)+1:this.commands[e+1]&&"move"!==this.commands[e+1].type?e+1:void 0,l=void 0!==a&&this.commands[a]&&this.commands[a]?.type!=="move"?d[a]:void 0,p=h[t.type],f=void 0!==a&&h[this.commands[a].type],g=d[e],m=g?.tangentEnd,y=l?.tangentStart,b=p&&f&&m&&y&&r.l2P.Len2(m)>.01&&r.l2P.Len2(y)>.01?(0,r.wwY)(Math.abs(r.l2P.AngleBetween(m,y)),[Math.PI/2,Math.PI],[s,0],!0):0,x=Math.min(g?.length??1/0,l?.length??1/0)-2*b,w=(0,r.qE8)(n,0,x/4),v=Math.min(b,(g?.length??1/0)/4),S=Math.min(b,(l?.length??1/0)/4),C={command:t,offsetAmount:w,roundnessBefore:v,roundnessAfter:S,tangentToPrev:d[e]?.tangentEnd,tangentToNext:l?.tangentStart,moveDidClose:!1};if(c.push(C),t.isClose&&null!==u){let e=c[u];e.moveDidClose=!0,e.roundnessAfter=S}else"move"===t.type&&(u=e)}for(let e=0;e<s;e++){let t=(0,r.She)(n+e),i={x:0,y:0},o=!1;for(let{command:e,offsetAmount:n,roundnessBefore:s,roundnessAfter:d,tangentToNext:h,tangentToPrev:u}of c){let c;if(e.isClose)c=i;else{let e=new r.l2P(t(),t()).uni(),i=Math.sqrt(Math.abs(t()))*n;c=r.l2P.Mul(e,i)}if("move"===e.type){i=c;let t=e.opts?.geometry!==!1&&(e.opts?.geometry?.isFilled??!1);o=!!a&&!t}if(o)continue;let p=r.l2P.Add(e,c),f=h&&d>0?r.l2P.Mul(h,-d).add(p):p,g=u&&s>0?r.l2P.Mul(u,s).add(p):p;if(f===p||g===p)switch(e.type){case"move":l.push("M",(0,r.WMC)(f.x),(0,r.WMC)(f.y));break;case"line":l.push("L",(0,r.WMC)(f.x),(0,r.WMC)(f.y));break;case"cubic":{let t=r.l2P.Add(e.cp1,c),n=r.l2P.Add(e.cp2,c);l.push("C",(0,r.WMC)(t.x),(0,r.WMC)(t.y),(0,r.WMC)(n.x),(0,r.WMC)(n.y),(0,r.WMC)(f.x),(0,r.WMC)(f.y));break}default:(0,r.h6G)(e,"type")}else switch(e.type){case"move":l.push("M",(0,r.WMC)(f.x),(0,r.WMC)(f.y));break;case"line":l.push("L",(0,r.WMC)(g.x),(0,r.WMC)(g.y),"Q",(0,r.WMC)(p.x),(0,r.WMC)(p.y),(0,r.WMC)(f.x),(0,r.WMC)(f.y));break;case"cubic":{let t=r.l2P.Add(e.cp1,c),n=r.l2P.Add(e.cp2,c);l.push("C",(0,r.WMC)(t.x),(0,r.WMC)(t.y),(0,r.WMC)(n.x),(0,r.WMC)(n.y),(0,r.WMC)(p.x),(0,r.WMC)(p.y));break}default:(0,r.h6G)(e,"type")}}}return l.join(" ")}calculateSegmentLength(e,t){switch(t.type){case"move":return 0;case"line":return r.l2P.Dist(e,t);case"cubic":return p.length(e.x,e.y,t.cp1.x,t.cp1.y,t.cp2.x,t.cp2.y,t.x,t.y);default:(0,r.h6G)(t,"type")}}getCommands(){return this.commands}getCommandInfo(){let e=[];for(let t=1;t<this.commands.length;t++){let n,i,o=this.commands[t-1],s=this.commands[t];if(s._info){e[t]=s._info;continue}if("move"!==s.type){switch(s.type){case"line":n=i=r.l2P.Sub(o,s).uni();break;case"cubic":n=r.l2P.Sub(s.cp1,o).uni(),i=r.l2P.Sub(s.cp2,s).uni();break;default:(0,r.h6G)(s,"type")}s._info={tangentStart:n,tangentEnd:i,length:this.calculateSegmentLength(o,s)},e[t]=s._info}}return e}}let h={line:!0,move:!0,cubic:!1};class u extends r.vqJ{constructor(e,t,n,r){super(r),this.path=e,this.startIdx=t,this.endIdx=n}path;startIdx;endIdx;_segments=null;getSegments(){if(this._segments)return this._segments;this._segments=[];let e=this.path.commands[this.startIdx];(0,r.vAR)("move"===e.type);for(let t=this.startIdx+1;t<this.endIdx;t++){let n=this.path.commands[t];switch((0,r.vAR)("move"!==n.type),n.type){case"line":this._segments.push(new r.AoN({start:r.l2P.From(e),end:r.l2P.From(n)}));break;case"cubic":this._segments.push(new r.iON({start:r.l2P.From(e),cp1:r.l2P.From(n.cp1),cp2:r.l2P.From(n.cp2),end:r.l2P.From(n),resolution:n.resolution}));break;default:(0,r.h6G)(n,"type")}e=n}return this._segments}getVertices(e){let t=this.getSegments().flatMap(t=>t.getVertices(e)).filter((e,t,n)=>{let i=n[t-1];return!i||!r.l2P.Equals(i,e)});if(this.isClosed){let e=t[t.length-1],n=t[0];r.l2P.Equals(e,n)||t.push(n)}return t}nearestPoint(e,t){let n=null,i=1/0;for(let t of this.getSegments()){let o=t.nearestPoint(e),s=r.l2P.Dist2(e,o);s<i&&(i=s,n=o)}return(0,r.vAR)(n,"No nearest point found"),n}hitTestLineSegment(e,t,n=0,r){return super.hitTestLineSegment(e,t,n,r)}getSvgPathData(){return this.path.toD({startIdx:this.startIdx,endIdx:this.endIdx})}}let p={base3(e,t,n,r,i){let o=e*(-3*t+9*n-9*r+3*i)+6*t-12*n+6*r;return e*o-3*t+3*n},length(e,t,n,r,i,o,s,a,l=1){let d=(l=l>1?1:l<0?0:l)/2,c=0;c=0;for(let l=0;l<12;l++){let h=d*p.Tvalues[l]+d,u=p.base3(h,e,n,i,s),f=p.base3(h,t,r,o,a),g=u*u+f*f;c+=p.Cvalues[l]*Math.sqrt(g)}return d*c},Tvalues:[-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816],Cvalues:[.2491,.2491,.2335,.2335,.2032,.2032,.1601,.1601,.1069,.1069,.0472,.0472]};var f=n(12115);function g(){let e=(0,r.frr)(),t=(0,r.hau)("animationSpeed",()=>e?.user.getAnimationSpeed(),[e]),[n,i]=(0,f.useState)(!1);return(0,f.useEffect)(()=>{if(void 0!==t)return void i(0===t);let n=e?.getContainerWindow()??window;if(!("matchMedia"in n))return;let r=n.matchMedia("(prefers-reduced-motion: reduce)"),o=()=>{i(r.matches)};return o(),r.addEventListener("change",o),()=>r.removeEventListener("change",o)},[t,e]),n}function m(e){return"richText"in e.props&&r.eHF.isValid(e.props.richText)}function y(e,t,n={}){let r="string"==typeof t?e.getShape(t):t;if(r&&e.canEditShape(r)){if(!m(r))throw Error("Shape does not have rich text");e.setEditingShape(r),e.setCurrentTool("select.editing_shape",{...n.info,target:"shape",shape:r}),n.selectAll&&e.emit("select-all-text",{shapeId:r.id})}}let b=(0,f.createContext)(null);function x({children:e}){let t=(0,r.fpl)("a11y",{msg:"",priority:"assertive"}),n=(0,f.useContext)(b),i=(0,f.useMemo)(()=>({currentMsg:t,announce(e){e&&t.set(e)}}),[t]);return n?(0,d.jsx)(d.Fragment,{children:e}):(0,d.jsx)(b.Provider,{value:i,children:e})}function w(){let e=(0,f.useContext)(b);if(!e)throw Error("useA11y must be used within a A11yContext.Provider");return e}let v=(0,f.createContext)(null);function S({assetUrls:e,children:t}){return(0,f.useEffect)(()=>{let t=new Set;for(let n of[...Object.values(e.icons),...Object.values(e.embedIcons)]){if(!n)continue;let e=n.split("#")[0];if(t.has(e))continue;t.add(e);let i=(0,r._V3)();i.crossOrigin="anonymous",i.src=n,i.decode().catch(r.lQ1)}},[e]),(0,d.jsx)(v.Provider,{value:e,children:t})}function C(){let e=(0,f.useContext)(v);if(!e)throw Error("useAssetUrls must be used within an AssetUrlsProvider");return e}let k={"action.toggle-auto-pan":"Auto (trackpad)","action.toggle-auto-zoom":"Auto (mouse)","action.toggle-auto-none":"Auto","action.toggle-mouse":"Mouse","action.toggle-trackpad":"Trackpad","action.convert-to-bookmark":"Convert to bookmark","action.convert-to-embed":"Convert to embed","action.open-embed-link":"Open link","action.align-bottom":"Align bottom","action.align-center-horizontal":"Align horizontally","action.align-center-vertical":"Align vertically","action.align-center-horizontal.short":"Align H","action.align-center-vertical.short":"Align V","action.align-left":"Align left","action.align-right":"Align right","action.align-top":"Align top","action.back-to-content":"Back to content","action.bring-forward":"Bring forward","action.bring-to-front":"Bring to front","action.copy-as-json.short":"JSON","action.copy-as-json":"Copy as JSON","action.copy-as-png.short":"PNG","action.copy-as-png":"Copy as PNG","action.copy-as-svg.short":"SVG","action.copy-as-svg":"Copy as SVG","action.copy":"Copy","action.copy-hovered-styles":"Copy hovered styles","action.cut":"Cut","action.delete":"Delete","action.unlock-all":"Unlock all","action.distribute-horizontal":"Distribute horizontally","action.distribute-vertical":"Distribute vertically","action.distribute-horizontal.short":"Distribute H","action.distribute-vertical.short":"Distribute V","action.download-original":"Download original","action.duplicate":"Duplicate","action.edit-link":"Edit link…","action.exit-pen-mode":"Exit pen mode","action.export-as-png.short":"PNG","action.export-as-png":"Export as PNG","action.export-as-svg.short":"SVG","action.export-as-svg":"Export as SVG","action.export-all-as-png.short":"PNG","action.export-all-as-png":"Export as PNG","action.export-all-as-svg.short":"SVG","action.export-all-as-svg":"Export as SVG","action.fit-frame-to-content":"Fit to content","action.flip-horizontal":"Flip horizontally","action.flip-vertical":"Flip vertically","action.flip-horizontal.short":"Flip H","action.flip-vertical.short":"Flip V","action.fork-project":"Fork this project","action.fork-project-on-tldraw":"Fork project on tldraw","action.frame-selection":"Frame selection","action.group":"Group","action.insert-embed":"Insert embed…","action.insert-media":"Upload media…","action.leave-shared-project":"Leave shared project","action.new-project":"New project","action.new-shared-project":"New shared project","action.open-cursor-chat":"Cursor chat","action.open-kbd-shortcuts":"Keyboard shortcuts","action.open-file":"Open file","action.pack":"Pack","action.paste":"Paste","action.paste-error-title":"Pasting failed","action.paste-error-description":"Could not paste due to missing clipboard permissions. Please enable the permissions and try again.","action.print":"Print…","action.redo":"Redo","action.remove-frame":"Remove frame","action.rename":"Rename","action.rotate-ccw":"Rotate counterclockwise","action.rotate-cw":"Rotate clockwise","action.save-copy":"Save a copy","action.select-all":"Select all","action.select-none":"Select none","action.send-backward":"Send backward","action.send-to-back":"Send to back","action.share-project":"Share this project","action.stack-horizontal":"Stack horizontally","action.stack-vertical":"Stack vertically","action.stack-horizontal.short":"Stack H","action.stack-vertical.short":"Stack V","action.stop-following":"Stop following","action.stretch-horizontal":"Stretch horizontally","action.stretch-vertical":"Stretch vertically","action.stretch-horizontal.short":"Stretch H","action.stretch-vertical.short":"Stretch V","action.toggle-auto-size":"Toggle auto size","action.toggle-dark-mode.menu":"Dark mode","action.toggle-dark-mode":"Toggle dark mode","action.toggle-paste-at-cursor.menu":"Paste at cursor","action.toggle-paste-at-cursor":"Toggle paste at cursor","action.toggle-wrap-mode.menu":"Select on wrap","action.toggle-wrap-mode":"Toggle select on wrap","action.toggle-reduce-motion.menu":"Reduce motion","action.toggle-reduce-motion":"Toggle reduce motion","action.toggle-keyboard-shortcuts.menu":"Enable keyboard shortcuts","action.toggle-keyboard-shortcuts":"Toggle keyboard shortcuts","action.enhanced-a11y-mode.menu":"Enhanced accessibility mode","action.enhanced-a11y-mode":"Toggle enhanced accessibility mode","action.toggle-edge-scrolling.menu":"Edge scrolling","action.toggle-edge-scrolling":"Toggle edge scrolling","action.toggle-invert-zoom.menu":"Invert mouse zoom","action.toggle-invert-zoom":"Toggle invert mouse zoom","action.toggle-debug-mode.menu":"Debug mode","action.toggle-debug-mode":"Toggle debug mode","action.toggle-focus-mode.menu":"Focus mode","action.toggle-focus-mode":"Toggle focus mode","action.toggle-dynamic-size-mode.menu":"Dynamic size","action.toggle-dynamic-size-mode":"Toggle dynamic size","action.toggle-grid.menu":"Show grid","action.toggle-grid":"Toggle grid","action.toggle-lock":"Toggle locked","action.flatten-to-image":"Flatten","action.toggle-snap-mode.menu":"Always snap","action.toggle-snap-mode":"Toggle always snap","action.toggle-tool-lock.menu":"Tool lock","action.toggle-tool-lock":"Toggle tool lock","action.toggle-transparent.context-menu":"Transparent","action.toggle-transparent.menu":"Transparent","action.toggle-transparent":"Toggle transparent background","action.undo":"Undo","action.ungroup":"Ungroup","action.zoom-in":"Zoom in","action.zoom-out":"Zoom out","action.zoom-to-100":"Zoom to 100%","action.zoom-to-fit":"Zoom to fit","action.zoom-to-selection":"Zoom to selection","action.zoom-quick":"Quick zoom","action.select-zoom-tool":"Zoom","assets.files.size-too-big":"File size is too big","assets.files.maximum-size":"Maximum file size is {size}","assets.files.type-not-allowed":"File type is not allowed","assets.files.upload-failed":"Upload failed","assets.files.amount-too-many":"Too many files","assets.url.failed":"Couldn’t load URL preview","theme.dark":"Dark","theme.light":"Light","theme.system":"System","color-style.white":"White","color-style.black":"Black","color-style.blue":"Blue","color-style.green":"Green","color-style.grey":"Grey","color-style.light-blue":"Light blue","color-style.light-green":"Light green","color-style.light-red":"Light red","color-style.light-violet":"Light violet","color-style.orange":"Orange","color-style.red":"Red","color-style.violet":"Violet","color-style.yellow":"Yellow","fill-style.none":"None","document.default-name":"Untitled","fill-style.semi":"Semi","fill-style.solid":"Solid","fill-style.pattern":"Pattern","fill-style.fill":"Fill","fill-style.lined-fill":"Lined fill","dash-style.dashed":"Dashed","dash-style.dotted":"Dotted","dash-style.draw":"Draw","dash-style.solid":"Solid","size-style.s":"Small","size-style.m":"Medium","size-style.l":"Large","size-style.xl":"Extra large","opacity-style.0.1":"10%","opacity-style.0.25":"25%","opacity-style.0.5":"50%","opacity-style.0.75":"75%","opacity-style.1":"100%","font-style.draw":"Draw","font-style.sans":"Sans","font-style.serif":"Serif","font-style.mono":"Mono","align-style.start":"Start","align-style.middle":"Middle","align-style.end":"End","align-style.justify":"Justify","verticalAlign-style.start":"Top","verticalAlign-style.middle":"Middle","verticalAlign-style.end":"Bottom","geo-style.arrow-down":"Arrow down","geo-style.arrow-left":"Arrow left","geo-style.arrow-right":"Arrow right","geo-style.arrow-up":"Arrow up","geo-style.cloud":"Cloud","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.heart":"Heart","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","geo-style.rhombus":"Rhombus","geo-style.rhombus-2":"Rhombus left","geo-style.star":"Star","geo-style.trapezoid":"Trapezoid","geo-style.triangle":"Triangle","geo-style.x-box":"X box","geo-style.check-box":"Check box","arrowheadStart-style.none":"None","arrowheadStart-style.arrow":"Arrow","arrowheadStart-style.bar":"Bar","arrowheadStart-style.diamond":"Diamond","arrowheadStart-style.dot":"Dot","arrowheadStart-style.inverted":"Inverted","arrowheadStart-style.pipe":"Pipe","arrowheadStart-style.square":"Square","arrowheadStart-style.triangle":"Triangle","arrowheadEnd-style.none":"None","arrowheadEnd-style.arrow":"Arrow","arrowheadEnd-style.bar":"Bar","arrowheadEnd-style.diamond":"Diamond","arrowheadEnd-style.dot":"Dot","arrowheadEnd-style.inverted":"Inverted","arrowheadEnd-style.pipe":"Pipe","arrowheadEnd-style.square":"Square","arrowheadEnd-style.triangle":"Triangle","spline-style.line":"Line","spline-style.cubic":"Cubic","arrow-kind-style.arc":"Arc","arrow-kind-style.elbow":"Elbow","tool.select":"Select","tool.hand":"Hand","tool.draw":"Draw","tool.eraser":"Eraser","tool.arrow-down":"Arrow down","tool.arrow-left":"Arrow left","tool.arrow-right":"Arrow right","tool.arrow-up":"Arrow up","tool.arrow":"Arrow","tool.cloud":"Cloud","tool.diamond":"Diamond","tool.ellipse":"Ellipse","tool.heart":"Heart","tool.hexagon":"Hexagon","tool.highlight":"Highlight","tool.line":"Line","tool.octagon":"Octagon","tool.oval":"Oval","tool.pentagon":"Pentagon","tool.rectangle":"Rectangle","tool.rhombus":"Rhombus","tool.star":"Star","tool.trapezoid":"Trapezoid","tool.triangle":"Triangle","tool.x-box":"X box","tool.check-box":"Check box","tool.media":"Media","tool.frame":"Frame","tool.note":"Note","tool.laser":"Laser","tool.embed":"Embed","tool.text":"Text","tool.pointer-down":"Pointer down","tool.image-zoom":"Zoom","tool.replace-media":"Replace media…","tool.flip-horz":"Flip horizontally","tool.flip-vert":"Flip vertically","tool.rotate-cw":"Rotate","tool.aspect-ratio":"Aspect ratio","tool.aspect-ratio.original":"Original","tool.aspect-ratio.square":"Square (1:1)","tool.aspect-ratio.circle":"Circle (1:1)","tool.aspect-ratio.landscape":"Landscape (4:3)","tool.aspect-ratio.portrait":"Portrait (3:4)","tool.aspect-ratio.wide":"Wide (16:9)","tool.image-toolbar-title":"Image tools","tool.image-crop":"Crop image","tool.image-crop-confirm":"Confirm","tool.media-alt-text":"Alternative text","tool.media-alt-text-desc":"Give a description…","tool.media-alt-text-confirm":"Confirm","tool.rich-text-bold":"Bold","tool.rich-text-italic":"Italic","tool.rich-text-code":"Code","tool.rich-text-highlight":"Highlight","tool.rich-text-strikethrough":"Strikethrough","tool.rich-text-link":"Link","tool.rich-text-link-visit":"Visit link","tool.rich-text-link-remove":"Remove link","tool.rich-text-header":"Header","tool.rich-text-bulletList":"Bulleted list","tool.rich-text-toolbar-title":"Text formatting","tool.rich-text-orderedList":"Ordered list","tool.bookmark":"Bookmark","a11y.status":"Status","a11y.skip-to-main-content":"Move focus to canvas","a11y.shape-index":"{num} of {total}","a11y.shape-image":"Image","a11y.shape-video":"Video","a11y.multiple-shapes":"{num} shapes selected","a11y.select-shape":"Select next shape","a11y.select-shape-direction":"Select shape in direction","a11y.enter-leave-container":"Enter/leave container","a11y.repeat-shape":"Repeat shape","a11y.move-shape":"Move shape","a11y.move-shape-faster":"Move shape faster","a11y.rotate-shape-cw":"Rotate shape clockwise","a11y.rotate-shape-ccw":"Rotate shape counterclockwise","a11y.rotate-shape-cw-fine":"Rotate shape clockwise (fine)","a11y.rotate-shape-ccw-fine":"Rotate shape counterclockwise (fine)","a11y.enlarge-shape":"Enlarge shape","a11y.shrink-shape":"Shrink shape","a11y.pan-camera":"Pan camera","a11y.adjust-shape-styles":"Adjust shape styles","a11y.open-context-menu":"Context menu…","a11y.open-keyboard-shortcuts":"Keyboard shortcuts","menu.title":"Menu","menu.theme":"Theme","menu.color-theme":"Color theme","menu.accessibility":"Accessibility","menu.copy-as":"Copy as","menu.edit":"Edit","menu.export-as":"Export as","menu.file":"File","menu.language":"Language","menu.preferences":"Preferences","menu.view":"View","menu.input-device":"Input device","context-menu.title":"Context menu","context-menu.edit":"Edit","context-menu.arrange":"Arrange","context-menu.copy-as":"Copy as","context-menu.export-as":"Export as","context-menu.export-all-as":"Export","context-menu.move-to-page":"Move to page","context-menu.reorder":"Reorder","page-menu.title":"Pages","page-menu.create-new-page":"Create new page","page-menu.max-pages-reached":"Maximum pages reached","page-menu.new-page-initial-name":"Page 1","page-menu.edit-start":"Edit","page-menu.edit-done":"Done","page-menu.go-to-page":"Go to page","page-menu.resize":"Resize page list","page-menu.submenu.rename":"Rename","page-menu.submenu.duplicate-page":"Duplicate","page-menu.submenu.title":"Menu","page-menu.submenu.move-down":"Move down","page-menu.submenu.move-up":"Move up","page-menu.submenu.delete":"Delete","share-menu.title":"Share","share-menu.save-note":"Download this project to your computer as a .tldr file.","share-menu.fork-note":"Create a new shared project based on this snapshot.","share-menu.share-project":"Share this project","share-menu.copy-link":"Copy editor link","share-menu.create-snapshot-link":"Copy snapshot link","share-menu.snapshot-link-note":"Capture and share this project as a read-only snapshot link.","share-menu.copy-readonly-link":"Copy viewer link","share-menu.offline-note":"Create a new shared project based on your current project.","share-menu.copy-link-note":"Anyone with the link will be able to view and edit this project.","share-menu.copy-readonly-link-note":"Anyone with the link will be able to access this project.","share-menu.project-too-large":"Sorry, this project can’t be shared because it’s too large. We’re working on it!","share-menu.upload-failed":"Sorry, we couldn’t upload your project at the moment. Please try again or let us know if the problem persists.","share-menu.creating-project":"Creating the new project…","share-menu.copied":"Copied link","document-name-menu.copy-link":"Copy link","status.offline":"Offline","people-menu.title":"People","people-menu.change-name":"Change name","people-menu.avatar-color":"Avatar color","people-menu.change-color":"Change color","people-menu.follow":"Following","people-menu.following":"Following","people-menu.leading":"Following you","people-menu.user":"(You)","people-menu.invite":"Invite others","people-menu.anonymous-user":"New user","help-menu.import-tldr-file":"Import file…","help-menu.title":"Help and resources","help-menu.about":"About tldraw","help-menu.discord":"Discord","help-menu.github":"GitHub","help-menu.keyboard-shortcuts":"Keyboard shortcuts","help-menu.twitter":"Twitter","help-menu.terms":"Terms of service","help-menu.privacy":"Privacy policy","actions-menu.title":"Actions","edit-link-dialog.title":"Edit link","edit-link-dialog.invalid-url":"A link must be a valid URL.","edit-link-dialog.detail":"Links will open in a new tab.","edit-link-dialog.url":"URL","edit-link-dialog.clear":"Clear","edit-link-dialog.save":"Continue","edit-link-dialog.cancel":"Cancel","edit-link-dialog.external-link":"External link","embed-dialog.title":"Insert embed","embed-dialog.back":"Back","embed-dialog.create":"Create","embed-dialog.cancel":"Cancel","embed-dialog.url":"URL","embed-dialog.instruction":"Paste in the site’s URL to create the embed.","embed-dialog.invalid-url":"We could not create an embed from that URL.","shortcuts-dialog.title":"Keyboard shortcuts","shortcuts-dialog.edit":"Edit","shortcuts-dialog.file":"File","shortcuts-dialog.preferences":"Preferences","shortcuts-dialog.tools":"Tools","shortcuts-dialog.transform":"Transform","shortcuts-dialog.view":"View","shortcuts-dialog.collaboration":"Collaboration","shortcuts-dialog.a11y":"Accessibility","shortcuts-dialog.text-formatting":"Text formatting","style-panel.title":"Styles","style-panel.align":"Align","style-panel.label-align":"Label align","style-panel.vertical-align":"Vertical align","style-panel.position":"Position","style-panel.arrowheads":"Arrows","style-panel.arrowhead-start":"Start","style-panel.arrowhead-end":"End","style-panel.arrow-kind":"Line","style-panel.color":"Color","style-panel.dash":"Dash","style-panel.fill":"Fill","style-panel.font":"Font","style-panel.geo":"Shape","style-panel.mixed":"Mixed","style-panel.opacity":"Opacity","style-panel.size":"Size","style-panel.spline":"Spline","style-panel.selected":"selected","tool-panel.title":"Tools","tool-panel.more":"More","navigation-zone.title":"Navigation","navigation-zone.minimap":"Minimap","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","toast.success":"Success","toast.error":"Error","toast.info":"Info","toast.warning":"Warning","file-system.file-open-error.title":"Could not open file","file-system.file-open-error.not-a-tldraw-file":"The file you tried to open doesn’t look like a tldraw file.","file-system.file-open-error.file-format-version-too-new":"The file you tried to open is from a newer version of tldraw. Please reload the page and try again.","file-system.file-open-error.generic-corrupted-file":"The file you tried to open is corrupted.","file-system.confirm-open.title":"Overwrite current project?","file-system.confirm-open.description":"Opening a file will replace your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-open.cancel":"Cancel","file-system.confirm-open.open":"Open file","file-system.confirm-open.dont-show-again":"Don’t ask again","file-system.confirm-clear.title":"Clear current project?","file-system.confirm-clear.description":"Creating a new project will clear your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-clear.cancel":"Cancel","file-system.confirm-clear.continue":"Continue","file-system.confirm-clear.dont-show-again":"Don’t ask again","file-system.shared-document-file-open-error.title":"Could not open file","file-system.shared-document-file-open-error.description":"Opening files from shared projects is not supported.","sharing.confirm-leave.title":"Leave current project?","sharing.confirm-leave.description":"Are you sure you want to leave this shared project? You can return to it by navigating to its URL.","sharing.confirm-leave.cancel":"Cancel","sharing.confirm-leave.leave":"Leave","sharing.confirm-leave.dont-show-again":"Don’t ask again","toast.error.export-fail.title":"Failed export","toast.error.export-fail.desc":"Failed to export image","toast.error.copy-fail.title":"Failed copy","toast.error.copy-fail.desc":"Failed to copy image","context.pages.new-page":"New page","vscode.file-open.desc":"We’ve updated this document to work with the current version of tldraw. If you’d like to keep the original version (which will work on old.tldraw.com), click below to create a backup.","vscode.file-open.open":"Continue","vscode.file-open.backup":"Backup","vscode.file-open.backup-saved":"Backup saved","vscode.file-open.backup-failed":"Backup failed: this is not a .tldr file.","vscode.file-open.dont-show-again":"Don’t ask again","cursor-chat.type-to-chat":"Type to chat…","app.loading":"Loading tldraw…","handle.resize-top":"Resize top","handle.resize-bottom":"Resize bottom","handle.resize-left":"Resize left","handle.resize-right":"Resize right","handle.resize-top-left":"Resize top left","handle.resize-top-right":"Resize top right","handle.resize-bottom-left":"Resize bottom left","handle.resize-bottom-right":"Resize bottom right","handle.rotate.top_left_rotate":"Rotate top left","handle.rotate.top_right_rotate":"Rotate top right","handle.rotate.bottom_left_rotate":"Rotate bottom left","handle.rotate.bottom_right_rotate":"Rotate bottom right","handle.rotate.mobile_rotate":"Rotate","handle.crop.top":"Crop top","handle.crop.bottom":"Crop bottom","handle.crop.left":"Crop left","handle.crop.right":"Crop right","handle.crop.top-left":"Crop top left","handle.crop.top-right":"Crop top right","handle.crop.bottom-left":"Crop bottom left","handle.crop.bottom-right":"Crop bottom right","ui.close":"Close","ui.checked":"Checked","ui.unchecked":"Unchecked","comments.title":"Comments","comments.empty":"No comments on this page yet.","comments.empty-filtered":"No comments match your filters.","comments.thread-title":"Comment","comments.resolved":"Resolved","comments.filter":"Filter comments","comments.show-resolved":"Show resolved comments","comments.only-my-comments":"Only my comments","comments.only-unread":"Only unread","comments.show-all-pages":"Show all pages","comments.more-options":"More options","comments.hide":"Hide comments","comments.show":"Show comments","comments.reply-placeholder":"Reply…","comments.edit-placeholder":"Edit comment…","comments.add-placeholder":"Add a comment…","comments.save":"Save","comments.edit":"Edit","comments.resolve":"Resolve","comments.reopen":"Reopen","comments.delete":"Delete thread","comments.edit-comment":"Edit comment","comments.delete-comment":"Delete comment","comments.dismiss":"Dismiss","comments.copy-link":"Copy link","comments.link-copied":"Link copied","comments.send":"Send","comments.resolved-by":"Resolved by {name}","comments.add-reaction":"Add reaction","comments.reacted-1":"{a} reacted","comments.reacted-2":"{a} and {b} reacted","comments.reacted-3":"{a}, {b} and {c} reacted","comments.reacted-more":"{a}, {b}, {c} and {count} others reacted","comments.reacted-more-one":"{a}, {b}, {c} and 1 other reacted","comments.mention-you":"You","comments.mention-no-matches":"No matches","comments.preview-more":"{count} more","comments.replies-one":"1 reply","comments.replies":"{count} replies","comments.pin-label":"Comment by {name}","comments.pin-label-resolved":"Resolved comment by {name}","comments.cluster-label":"{count} comments here","comments.stack-label":"{count} comments at this spot"},P=new Set(["ar","fa","he","ur","ku"]),T={locale:"en",label:"English",messages:k,dir:"ltr"};async function E(e,t){if(!(await (0,r.hdJ)(t.translations.en)).ok)return console.warn("No main translations found."),T;if("en"===e)return T;let n=r.Yjb.find(t=>t.locale===e);if(!n)return console.warn(`No translation found for locale ${e}`),T;let i=await (0,r.hdJ)(t.translations[n.locale]),o=await i.json();if(!o)return console.warn(`No messages found for locale ${e}`),T;let s=[];for(let e in T.messages)o[e]||s.push(e);return s.length,{locale:e,label:n.label,dir:P.has(n.locale)?"rtl":"ltr",messages:{...T.messages,...o}}}let I=f.createContext(null);function _({overrides:e,locale:t,children:n}){let r=C(),[i,o]=f.useState(()=>e&&e.en?{locale:"en",label:"English",dir:"ltr",messages:{...k,...e.en}}:{locale:"en",label:"English",dir:"ltr",messages:k});return f.useEffect(()=>{let n=!1;return async function(){let i=await E(t,r);i&&!n&&(e&&e[t]?o({...i,messages:{...i.messages,...e[t]}}):o(i))}(),()=>{n=!0}},[r,t,e]),(0,d.jsx)(I.Provider,{value:i,children:n})}function M(){let e=f.useContext(I),t=e?.messages??k;return f.useEffect(()=>{e?.messages||(0,r.mcG)("No translation messages found, falling back to default translation. Wrap your app in <TldrawUiContextProvider>, or in both <AssetUrlsProvider> and <TldrawUiTranslationProvider>, to provide translations.")},[e?.messages]),f.useCallback(function(e){return t[e]??e},[t])}function A(){let e=f.useContext(I);return e?.dir??"ltr"}function j(e,t){let n=t?e.getAsset(t):null;if(n&&!n.props.image)if(!n.props.title)return 46;else return 101;return 320}function O(e,t){return{...t,props:{...t.props,h:j(e,t.props.assetId)}}}function D(e,t,n){if(t)return t;if(!n)return null;let i=r.Kx3.createId((0,r.xpx)(n));return e.getAsset(i)?i:null}function L(e,t){let n=D(e,t.props.assetId,t.props.url);return n===t.props.assetId?t.props.h:j(e,n)}async function R(e,t){if(e.isDisposed)return;let{url:n}=t.props,r=await e.getAssetForExternalContent({type:"url",url:n});r&&e.run(()=>{e.createAssets([r]),e.updateShapes([{id:t.id,type:t.type,props:{assetId:r.id}}])})}let F=new WeakMap;async function z(e,{url:t,center:n=e.getViewportPageBounds().center}){try{let i=r.Kx3.createId((0,r.xpx)(t)),o=e.getAsset(i),s=(0,r.n6Y)(),a={id:s,type:"bookmark",x:n.x-150,y:n.y-160,rotation:0,opacity:1,props:{url:t,assetId:o?.id??null,w:300,h:j(e,o?.id)}};e.run(()=>{e.createShapes([a])});let l=e.getShape(s);if(!l)return r.Q7C.err("Failed to create bookmark shape");if(o)return r.Q7C.ok(l);return N(e,s,t),r.Q7C.ok(l)}catch(e){return r.Q7C.err(e instanceof Error?e.message:"Failed to create bookmark")}}async function N(e,t,n){let r;try{r=await e.getAssetForExternalContent({type:"url",url:n})}catch(e){console.error(e);return}if(e.isDisposed||!r)return;let i=e.getShape(t);!i||i.props.url!==n||i.props.assetId||e.run(()=>{e.getAsset(r.id)||e.createAssets([r]),e.updateShapes([{id:t,type:"bookmark",props:{assetId:r.id}}])},{history:"ignore"})}function $(){return{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}}let B=["original","square","circle","landscape","portrait","wide"],H={original:0,square:1,circle:1,landscape:4/3,portrait:3/4,wide:16/9};function U(e,t){return t?{w:e.w/(t.bottomRight.x-t.topLeft.x),h:e.h/(t.bottomRight.y-t.topLeft.y)}:{w:e.w,h:e.h}}function K(e){return{width:e.bottomRight.x-e.topLeft.x,height:e.bottomRight.y-e.topLeft.y}}function W(e){let{width:t,height:n}=K(e);return{x:e.topLeft.x+t/2,y:e.topLeft.y+n/2}}function V(e,t,n,r,i){let o=Math.max(0,Math.min(1-n,e-n/2)),s=Math.max(0,Math.min(1-r,t-r/2));return{topLeft:{x:o,y:s},bottomRight:{x:o+n,y:s+r},isCircle:i}}let Y={fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},G={s:1,m:1.75,l:2.5,xl:5},q={s:1.125,m:1.5,l:2.25,xl:2.75},X={s:1.125,m:1.375,l:1.625,xl:2},J={s:1.125,m:1.25,l:1.5,xl:1.75},Z={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"};function Q(e,t){let n=e.fonts[t];return n?n.fontFamily:Z[t]??t}async function ee(e,t,n){let{elements:i,files:o}=t,s={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:e.store.schema.serialize()},a=new Map,l=new Map,d=e.getCurrentPageId(),c=new Map,h=[],u=new Set;i.forEach(e=>{if(c.set(e.id,(0,r.n6Y)()),null!==e.boundElements)for(let t of e.boundElements)"text"===t.type&&u.add(t.id)});let p=r.as9;for(let t of i){if(u.has(t.id))continue;let n=c.get(t.id),f={id:n,typeName:"shape",parentId:d,index:p,x:t.x,y:t.y,rotation:0,isLocked:t.locked,opacity:et(t.opacity),meta:{}};switch(0!==t.angle&&l.set(n,t.angle),t.groupIds&&t.groupIds.length>0?a.has(t.groupIds[0])?a.get(t.groupIds[0])?.push(n):a.set(t.groupIds[0],[n]):h.push(n),t.type){case"rectangle":case"ellipse":case"diamond":{let n="",o="middle";if(null!==t.boundElements){for(let e of t.boundElements)if("text"===e.type){let t=i.find(t=>t.id===e.id);t&&(n=t.text,o=ec[t.textAlign])}}let a="transparent"===t.backgroundColor?t.strokeColor:t.backgroundColor;s.shapes.push({...f,type:"geo",props:{...e.getShapeUtil("geo").getDefaultProps(),geo:t.type,url:t.link??"",w:t.width,h:t.height,size:en[t.strokeWidth]??"draw",color:ea[a]??"black",richText:(0,r.TP3)(n),align:o,dash:ep(t),fill:ef(t)}});break}case"freedraw":{let n=t.points.map(([e,t,n=.5])=>({x:e,y:t,z:n})),i=r.K6A.encodePoints(n);s.shapes.push({...f,type:"draw",props:{...e.getShapeUtil("draw").getDefaultProps(),dash:ep(t),size:en[t.strokeWidth],color:ea[t.strokeColor]??"black",segments:[{type:"free",path:i}]}});break}case"line":{if(t.points.slice().length<2)break;let n=(0,r.uud)(t.points.length);s.shapes.push({...f,type:"line",props:{...e.getShapeUtil("line").getDefaultProps(),dash:ep(t),size:en[t.strokeWidth],color:ea[t.strokeColor]??"black",spline:t.roundness?"cubic":"line",points:{...Object.fromEntries(t.points.map(([e,t],r)=>{let i=n[r];return[i,{id:i,index:i,x:e,y:t}]}))}}});break}case"arrow":{let o="";if(null!==t.boundElements){for(let e of t.boundElements)if("text"===e.type){let t=i.find(t=>t.id===e.id);t&&(o=t.text)}}let a=t.points[0],l=t.points[t.points.length-1],d=c.get(t.startBinding?.elementId),h=c.get(t.endBinding?.elementId);s.shapes.push({...f,type:"arrow",props:{...e.getShapeUtil("arrow").getDefaultProps(),richText:(0,r.TP3)(o),kind:t.elbowed?"elbow":"arc",bend:function(e,t,n){let i=0;if(e.points.length>2){let o=new r.l2P(t[0],t[1]),s=new r.l2P(n[0],n[1]),a=new r.l2P(e.points[1][0],e.points[1][1]),l=r.l2P.Sub(s,o),d=r.l2P.Per(l),c=r.l2P.Med(s,o),h=r.l2P.Sub(c,d),u=r.l2P.Add(c,d),p=r.l2P.NearestPointOnLineSegment(h,u,a,!1);i=r.l2P.Dist(p,c),r.l2P.Clockwise(p,s,c)&&(i*=-1)}return i}(t,a,l),dash:ep(t),size:en[t.strokeWidth]??"m",color:ea[t.strokeColor]??"black",start:{x:a[0],y:a[1]},end:{x:l[0],y:l[1]},arrowheadEnd:eu[t.endArrowhead]??"none",arrowheadStart:eu[t.startArrowhead]??"none"}}),d&&s.bindings.push({id:(0,r.BNi)(),typeName:"binding",type:"arrow",fromId:n,toId:d,props:{terminal:"start",snap:"none",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),h&&s.bindings.push({id:(0,r.BNi)(),typeName:"binding",type:"arrow",fromId:n,toId:h,props:{terminal:"end",snap:"none",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{let{size:n,scale:i}=function(e){let t=er[e];return t?{size:t,scale:1}:e<16?{size:"s",scale:e/16}:e>36?{size:"xl",scale:e/36}:{size:"m",scale:1}}(t.fontSize);s.shapes.push({...f,type:"text",props:{...e.getShapeUtil("text").getDefaultProps(),size:n,scale:i,font:ei[t.fontFamily]??"draw",color:ea[t.strokeColor]??"black",richText:(0,r.TP3)(t.text),textAlign:eh[t.textAlign]}});break}case"image":{let n=o[t.fileId];if(!n)break;let i=r.Kx3.createId();s.assets.push({id:i,typeName:"asset",type:"image",props:{w:t.width,h:t.height,fileSize:n.size,name:t.id??"Untitled",isAnimated:!1,mimeType:n.mimeType,src:n.dataURL},meta:{}}),s.shapes.push({...f,type:"image",props:{...e.getShapeUtil("image").getDefaultProps(),w:t.width,h:t.height,assetId:i}})}}p=(0,r.AQy)(p)}let f=n??(e.inputs.getShiftKey()?e.inputs.getCurrentPagePoint():void 0);for(let t of(e.putContentOntoCurrentPage(s,{point:f,select:!1,preserveIds:!0}),a.values()))if(t.length>1){e.groupShapes(t);let n=e.getShape(t[0]);n?.parentId&&(0,r.vc4)(n.parentId)&&h.push(n.parentId)}for(let[t,n]of l)e.select(t),e.rotateShapesBy([t],n);let g=(0,r.oE7)(h.map(t=>e.getShape(t))),m=r.azJ.Common(g.map(t=>e.getShapePageBounds(t))),y=e.getViewportPageBounds().center;e.updateShapes(g.map(e=>{let t={x:(e.x??0)-(m.x+m.w/2),y:(e.y??0)-(m.y+m.h/2)};return{id:e.id,type:e.type,x:y.x+t.x,y:y.y+t.y}})),e.setSelectedShapes(h)}let et=e=>{let t=e/100;return t<.2?.1:t<.4?.25:t<.6?.5:t<.8?.75:1},en={1:"s",2:"m",3:"l",4:"xl"},er={16:"s",20:"m",28:"l",36:"xl"},ei={1:"draw",2:"sans",3:"mono"},eo={gray:["#f8f9fa","#e9ecef","#ced4da","#868e96","#343a40"],red:["#fff5f5","#ffc9c9","#ff8787","#fa5252","#e03131"],pink:["#fff0f6","#fcc2d7","#f783ac","#e64980","#c2255c"],grape:["#f8f0fc","#eebefa","#da77f2","#be4bdb","#9c36b5"],violet:["#f3f0ff","#d0bfff","#9775fa","#7950f2","#6741d9"],indigo:["#edf2ff","#bac8ff","#748ffc","#4c6ef5","#3b5bdb"],blue:["#e7f5ff","#a5d8ff","#4dabf7","#228be6","#1971c2"],cyan:["#e3fafc","#99e9f2","#3bc9db","#15aabf","#0c8599"],teal:["#e6fcf5","#96f2d7","#38d9a9","#12b886","#099268"],green:["#ebfbee","#b2f2bb","#69db7c","#40c057","#2f9e44"],lime:["#f4fce3","#d8f5a2","#a9e34b","#82c91e","#66a80f"],yellow:["#fff9db","#ffec99","#ffd43b","#fab005","#f08c00"],orange:["#fff4e6","#ffd8a8","#ffa94d","#fd7e14","#e8590c"]};function es(e,t,n){return Object.fromEntries([0,1,2,3,4].map(t=>eo[e][t]).map((e,r)=>[e,r<3?t:n]))}let ea={...es("gray","grey","black"),...es("red","light-red","red"),...es("pink","light-red","red"),...es("grape","light-violet","violet"),...es("blue","light-blue","blue"),...es("cyan","light-blue","blue"),...es("teal","light-green","green"),...es("green","light-green","green"),...es("yellow","yellow","orange"),...es("orange","yellow","orange"),"#ffffff":"white","#000000":"black"},el={solid:"draw",dashed:"dashed",dotted:"dotted"},ed={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},ec={left:"start",center:"middle",right:"end"},eh={left:"start",center:"middle",right:"end"},eu={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"},ep=e=>{let t=el[e.strokeStyle]??"draw";return"draw"===t&&0===e.roughness&&(t="solid"),t},ef=e=>"transparent"===e.backgroundColor?"none":ed[e.fillStyle]??"solid";var eg=n(82159);let em=e=>{let t=/`([^`]+)`(?!`)$/.exec(e);return!t||t.index>0&&"`"===e[t.index-1]?null:{index:t.index,text:t[0],replaceWith:t[1]}},ey=e=>{let t,n=/`([^`]+)`(?!`)/g,r=[];for(;null!==(t=n.exec(e));)t.index>0&&"`"===e[t.index-1]||r.push({index:t.index,text:t[0],replaceWith:t[1]});return r},eb=eg.CU.create({name:"code",addOptions:()=>({HTMLAttributes:{}}),excludes:"_",code:!0,exitable:!0,parseHTML:()=>[{tag:"code"}],renderHTML({HTMLAttributes:e}){return["code",(0,eg.KV)(this.options.HTMLAttributes,e),0]},markdownTokenName:"codespan",parseMarkdown:(e,t)=>t.applyMark("code",[{type:"text",text:e.text||""}]),renderMarkdown:(e,t)=>e.content?`\`${t.renderChildren(e.content)}\``:"",addCommands(){return{setCode:()=>({commands:e})=>e.setMark(this.name),toggleCode:()=>({commands:e})=>e.toggleMark(this.name),unsetCode:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[(0,eg.OX)({find:em,type:this.type})]},addPasteRules(){return[(0,eg.Zc)({find:ey,type:this.type})]}}),ex=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,ew=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,ev=eg.CU.create({name:"highlight",addOptions:()=>({multicolor:!1,HTMLAttributes:{}}),addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:e=>e.getAttribute("data-color")||(0,eg.hs)(e,"background-color")||e.style.backgroundColor,renderHTML:e=>e.color?{"data-color":e.color,style:`background-color: ${e.color}; color: inherit`}:{}}}:{}},parseHTML:()=>[{tag:"mark"}],renderHTML({HTMLAttributes:e}){return["mark",(0,eg.KV)(this.options.HTMLAttributes,e),0]},renderMarkdown:(e,t)=>`==${t.renderChildren(e)}==`,parseMarkdown:(e,t)=>t.applyMark("highlight",t.parseInline(e.tokens||[])),markdownTokenizer:{name:"highlight",level:"inline",start:e=>e.indexOf("=="),tokenize(e,t,n){let r=/^(==)([^=]+)(==)/.exec(e);if(r){let e=r[2].trim(),t=n.inlineTokens(e);return{type:"highlight",raw:r[0],text:e,tokens:t}}}},addCommands(){return{setHighlight:e=>({commands:t})=>t.setMark(this.name,e),toggleHighlight:e=>({commands:t})=>t.toggleMark(this.name,e),unsetHighlight:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[(0,eg.OX)({find:ex,type:this.type})]},addPasteRules(){return[(0,eg.Zc)({find:ew,type:this.type})]}});var eS=n(27050),eC=n(76865);let ek=new WeakSet,eP=new WeakSet;function eT(e){return ek.add(e),e}function eE(e){return Array.isArray(e)&&ek.has(e)}let eI=(e,t)=>(function(e,t){if("slot"===e)return 0;if(e instanceof Function){let n=e(t);return!Array.isArray(n)||eE(n)||eP.has(n)?n:eT(n)}let{children:n,...r}=null!=t?t:{};if("svg"===e)throw Error("SVG elements are not supported in the JSX syntax, use the array syntax instead");if(Array.isArray(n)){if(eE(n))return eT([e,r,n]);if(0===n.length)return eT([e,r]);let t=function e(t){return t.flatMap(t=>null==t?[]:Array.isArray(t)&&eP.has(t)&&!eE(t)?e(t):[t])}(n);return 0===t.length?eT([e,r]):eT([e,r,...t])}return null!=n?eT([e,r,n]):eT([e,r])})(e,t),e_=/^\s*>\s$/,eM=eg.bP.create({name:"blockquote",addOptions:()=>({HTMLAttributes:{}}),content:"block+",group:"block",defining:!0,parseHTML:()=>[{tag:"blockquote"}],renderHTML({HTMLAttributes:e}){return eI("blockquote",{...(0,eg.KV)(this.options.HTMLAttributes,e),children:eI("slot",{})})},parseMarkdown:(e,t)=>{var n;let r=null!=(n=t.parseBlockChildren)?n:t.parseChildren;return t.createNode("blockquote",void 0,r(e.tokens||[]))},renderMarkdown:(e,t)=>{if(!e.content)return"";let n=[];return e.content.forEach((e,r)=>{var i,o;let s=(null!=(i=null==(o=t.renderChild)?void 0:o.call(t,e,r))?i:t.renderChildren([e])).split("\n").map(e=>""===e.trim()?">":`> ${e}`);n.push(s.join("\n"))}),n.join(`
5
- >
6
- `)},addCommands(){return{setBlockquote:()=>({commands:e})=>e.wrapIn(this.name),toggleBlockquote:()=>({commands:e})=>e.toggleWrap(this.name),unsetBlockquote:()=>({commands:e})=>e.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote(),Backspace:()=>((e,t)=>{var n;let{state:r}=e,{selection:i}=r;if(!i.empty)return!1;let{$from:o}=i;if(0!==o.parentOffset)return!1;let s=o.depth-1;if(s<0)return!1;let a=o.node(s),l=o.index(s);if(0===l)return!1;if(a.type===t)return e.commands.lift(t.name);let d=a.child(l-1);if(d.type!==t||!(null==(n=d.lastChild)?void 0:n.isTextblock))return!1;let c=o.before()-1-1;return e.commands.command(({tr:e,dispatch:t})=>{if(!t)return!0;let n=o.parent.content,r=new eS.Ji(n,0,0);return e.replace(c,o.after(),r),e.setSelection(eC.U3.create(e.doc,c+n.size)),e.scrollIntoView(),t(e),!0})})(this.editor,this.type)}},addInputRules(){return[(0,eg.tG)({find:e_,type:this.type})]}}),eA=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,ej=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,eO=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,eD=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,eL=eg.CU.create({name:"bold",addOptions:()=>({HTMLAttributes:{}}),parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:e=>"normal"!==e.style.fontWeight&&null},{style:"font-weight=400",clearMark:e=>e.type.name===this.name},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}]},renderHTML({HTMLAttributes:e}){return eI("strong",{...(0,eg.KV)(this.options.HTMLAttributes,e),children:eI("slot",{})})},markdownTokenName:"strong",parseMarkdown:(e,t)=>t.applyMark("bold",t.parseInline(e.tokens||[])),markdownOptions:{htmlReopen:{open:"<strong>",close:"</strong>"}},renderMarkdown:(e,t)=>`**${t.renderChildren(e)}**`,addCommands(){return{setBold:()=>({commands:e})=>e.setMark(this.name),toggleBold:()=>({commands:e})=>e.toggleMark(this.name),unsetBold:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[(0,eg.OX)({find:eA,type:this.type}),(0,eg.OX)({find:eO,type:this.type})]},addPasteRules(){return[(0,eg.Zc)({find:ej,type:this.type}),(0,eg.Zc)({find:eD,type:this.type})]}}),eR=/^```([a-z]+)?[\s\n]$/,eF=/^~~~([a-z]+)?[\s\n]$/,ez=eg.bP.create({name:"codeBlock",addOptions:()=>({languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,exitOnArrowUp:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:4,HTMLAttributes:{}}),content:"text*",marks:"",group:"block",code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:e=>{var t;let{languageClassPrefix:n}=this.options;if(!n)return null;let r=[...(null==(t=e.firstElementChild)?void 0:t.classList)||[]].filter(e=>e.startsWith(n)).map(e=>e.replace(n,""))[0];return r||null},rendered:!1}}},parseHTML:()=>[{tag:"pre",preserveWhitespace:"full"}],renderHTML({node:e,HTMLAttributes:t}){return["pre",(0,eg.KV)(this.options.HTMLAttributes,t),["code",{class:e.attrs.language?this.options.languageClassPrefix+e.attrs.language:null},0]]},markdownTokenName:"code",parseMarkdown:(e,t)=>{var n,r;return(null==(n=e.raw)?void 0:n.startsWith("```"))===!1&&(null==(r=e.raw)?void 0:r.startsWith("~~~"))===!1&&"indented"!==e.codeBlockStyle?[]:t.createNode("codeBlock",{language:e.lang||null},e.text?[t.createTextNode(e.text)]:[])},renderMarkdown:(e,t)=>{var n;let r=(null==(n=e.attrs)?void 0:n.language)||"";return e.content?[`\`\`\`${r}`,t.renderChildren(e.content),"```"].join("\n"):`\`\`\`${r}
7
-
8
- \`\`\``},addCommands(){return{setCodeBlock:e=>({commands:t})=>t.setNode(this.name,e),toggleCodeBlock:e=>({commands:t})=>t.toggleNode(this.name,"paragraph",e)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{let{empty:e,$anchor:t}=this.editor.state.selection,n=1===t.pos;return!!e&&t.parent.type.name===this.name&&(!!n||!t.parent.textContent.length)&&this.editor.commands.clearNodes()},Tab:({editor:e})=>{var t;if(!this.options.enableTabIndentation)return!1;let n=null!=(t=this.options.tabSize)?t:4,{state:r}=e,{selection:i}=r,{$from:o,empty:s}=i;if(o.parent.type!==this.type)return!1;let a=" ".repeat(n);return s?e.commands.insertContent(a):e.commands.command(({tr:e})=>{let{from:t,to:n}=i,o=r.doc.textBetween(t,n,"\n","\n").split("\n").map(e=>a+e).join("\n");return e.replaceWith(t,n,r.schema.text(o)),!0})},"Shift-Tab":({editor:e})=>{var t;if(!this.options.enableTabIndentation)return!1;let n=null!=(t=this.options.tabSize)?t:4,{state:r}=e,{selection:i}=r,{$from:o,empty:s}=i;return o.parent.type===this.type&&(s?e.commands.command(({tr:e})=>{var t;let{pos:i}=o,s=o.start(),a=o.end(),l=r.doc.textBetween(s,a,"\n","\n").split("\n"),d=0,c=0,h=i-s;for(let e=0;e<l.length;e+=1){if(c+l[e].length>=h){d=e;break}c+=l[e].length+1}let u=Math.min(((null==(t=l[d].match(/^ */))?void 0:t[0])||"").length,n);if(0===u)return!0;let p=s;for(let e=0;e<d;e+=1)p+=l[e].length+1;return e.delete(p,p+u),i-p<=u&&e.setSelection(eC.U3.create(e.doc,p)),!0}):e.commands.command(({tr:e})=>{let{from:t,to:o}=i,s=r.doc.textBetween(t,o,"\n","\n").split("\n").map(e=>{var t;let r=Math.min(((null==(t=e.match(/^ */))?void 0:t[0])||"").length,n);return e.slice(r)}).join("\n");return e.replaceWith(t,o,r.schema.text(s)),!0}))},Enter:({editor:e})=>{if(!this.options.exitOnTripleEnter)return!1;let{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type)return!1;let o=r.parentOffset===r.parent.nodeSize-2,s=r.parent.textContent.endsWith("\n\n");return!!o&&!!s&&e.chain().command(({tr:e})=>(e.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowUp:({editor:e})=>{if(!this.options.exitOnArrowUp)return!1;let{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type||0!==r.parentOffset)return!1;let o=r.before();return!(o>0)&&e.commands.insertDefaultBlock({pos:o})},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;let{state:t}=e,{selection:n,doc:r}=t,{$from:i,empty:o}=n;if(!o||i.parent.type!==this.type||i.parentOffset!==i.parent.nodeSize-2)return!1;let s=i.after();return void 0!==s&&(r.nodeAt(s)?e.commands.command(({tr:e})=>(e.setSelection(eC.LN.near(r.resolve(s))),!0)):e.commands.exitCode())}}},addInputRules(){return[(0,eg.JJ)({find:eR,type:this.type,getAttributes:e=>({language:e[1]})}),(0,eg.JJ)({find:eF,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new eC.k_({key:new eC.hs("codeBlockVSCodeHandler"),props:{handlePaste:(e,t)=>{if(!t.clipboardData||this.editor.isActive(this.type.name))return!1;let n=t.clipboardData.getData("text/plain"),r=t.clipboardData.getData("vscode-editor-data"),i=r?JSON.parse(r):void 0,o=null==i?void 0:i.mode;if(!n||!o)return!1;let{tr:s,schema:a}=e.state,l=a.text(n.replace(/\r\n?/g,"\n"));return s.replaceSelectionWith(this.type.create({language:o},l)),s.selection.$from.parent.type!==this.type&&s.setSelection(eC.U3.near(s.doc.resolve(Math.max(0,s.selection.from-2)))),s.setMeta("paste",!0),e.dispatch(s),!0}}})]}}),eN=eg.bP.create({name:"doc",topNode:!0,content:"block+",renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,"\n\n"):""}),e$=eg.bP.create({name:"hardBreak",markdownTokenName:"br",addOptions:()=>({keepMarks:!0,HTMLAttributes:{}}),inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,parseHTML:()=>[{tag:"br"}],renderHTML({HTMLAttributes:e}){return["br",(0,eg.KV)(this.options.HTMLAttributes,e)]},renderText:()=>"\n",renderMarkdown:()=>`
9
- `,parseMarkdown:()=>({type:"hardBreak"}),addCommands(){return{setHardBreak:()=>({commands:e,chain:t,state:n,editor:r})=>e.first([()=>e.exitCode(),()=>e.command(()=>{let{selection:e,storedMarks:i}=n;if(e.$from.parent.type.spec.isolating)return!1;let{keepMarks:o}=this.options,{splittableMarks:s}=r.extensionManager,a=i||e.$to.parentOffset&&e.$from.marks();return t().insertContent({type:this.name}).command(({tr:e,dispatch:t})=>{if(t&&a&&o){let t=a.filter(e=>s.includes(e.type.name));e.ensureMarks(t)}return!0}).scrollIntoView().run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),eB=eg.bP.create({name:"heading",addOptions:()=>({levels:[1,2,3,4,5,6],HTMLAttributes:{}}),content:"inline*",group:"block",defining:!0,addAttributes:()=>({level:{default:1,rendered:!1}}),parseHTML(){return this.options.levels.map(e=>({tag:`h${e}`,attrs:{level:e}}))},renderHTML({node:e,HTMLAttributes:t}){return[`h${this.options.levels.includes(e.attrs.level)?e.attrs.level:this.options.levels[0]}`,(0,eg.KV)(this.options.HTMLAttributes,t),0]},parseMarkdown:(e,t)=>t.createNode("heading",{level:e.depth||1},t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>{var n;let r=(null==(n=e.attrs)?void 0:n.level)?parseInt(e.attrs.level,10):1,i="#".repeat(r);return e.content?`${i} ${t.renderChildren(e.content)}`:""},addCommands(){return{setHeading:e=>({commands:t})=>!!this.options.levels.includes(e.level)&&t.setNode(this.name,e),toggleHeading:e=>({commands:t})=>!!this.options.levels.includes(e.level)&&t.toggleNode(this.name,"paragraph",e)}},addKeyboardShortcuts(){return this.options.levels.reduce((e,t)=>({...e,[`Mod-Alt-${t}`]:()=>this.editor.commands.toggleHeading({level:t})}),{})},addInputRules(){return this.options.levels.map(e=>(0,eg.JJ)({find:RegExp(`^(#{${Math.min(...this.options.levels)},${e}})\\s$`),type:this.type,getAttributes:{level:e}}))}}),eH=eg.bP.create({name:"horizontalRule",addOptions:()=>({HTMLAttributes:{},nextNodeType:"paragraph"}),group:"block",parseHTML:()=>[{tag:"hr"}],renderHTML({HTMLAttributes:e}){return["hr",(0,eg.KV)(this.options.HTMLAttributes,e)]},markdownTokenName:"hr",parseMarkdown:(e,t)=>t.createNode("horizontalRule"),renderMarkdown:()=>"---",addCommands(){return{setHorizontalRule:()=>({chain:e,state:t})=>{if(!(0,eg.AB)(t,t.schema.nodes[this.name]))return!1;let{selection:n}=t,{$to:r}=n,i=e();return(0,eg.BQ)(n)?i.insertContentAt(r.pos,{type:this.name}):i.insertContent({type:this.name}),i.command(({state:e,tr:t,dispatch:n})=>{if(n){let{$to:n}=t.selection,r=n.end();if(n.nodeAfter)n.nodeAfter.isTextblock?t.setSelection(eC.U3.create(t.doc,n.pos+1)):n.nodeAfter.isBlock?t.setSelection(eC.nh.create(t.doc,n.pos)):t.setSelection(eC.U3.create(t.doc,n.pos));else{let i=e.schema.nodes[this.options.nextNodeType]||n.parent.type.contentMatch.defaultType,o=null==i?void 0:i.create();o&&(t.insert(r,o),t.setSelection(eC.U3.create(t.doc,r+1)))}t.scrollIntoView()}return!0}).run()}}},addInputRules(){return[(0,eg.Ce)({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),eU=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,eK=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,eW=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,eV=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,eY=eg.CU.create({name:"italic",addOptions:()=>({HTMLAttributes:{}}),parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:e=>"normal"!==e.style.fontStyle&&null},{style:"font-style=normal",clearMark:e=>e.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:e}){return["em",(0,eg.KV)(this.options.HTMLAttributes,e),0]},addCommands(){return{setItalic:()=>({commands:e})=>e.setMark(this.name),toggleItalic:()=>({commands:e})=>e.toggleMark(this.name),unsetItalic:()=>({commands:e})=>e.unsetMark(this.name)}},markdownTokenName:"em",parseMarkdown:(e,t)=>t.applyMark("italic",t.parseInline(e.tokens||[])),markdownOptions:{htmlReopen:{open:"<em>",close:"</em>"}},renderMarkdown:(e,t)=>`*${t.renderChildren(e)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[(0,eg.OX)({find:eU,type:this.type}),(0,eg.OX)({find:eW,type:this.type})]},addPasteRules(){return[(0,eg.Zc)({find:eK,type:this.type}),(0,eg.Zc)({find:eV,type:this.type})]}}),eG="numeric",eq="ascii",eX="alpha",eJ="asciinumeric",eZ="alphanumeric",eQ="domain",e0="emoji",e1="whitespace";function e2(e,t,n){for(let r in t[eG]&&(t[eJ]=!0,t[eZ]=!0),t[eq]&&(t[eJ]=!0,t[eX]=!0),t[eJ]&&(t[eZ]=!0),t[eX]&&(t[eZ]=!0),t[eZ]&&(t[eQ]=!0),t[e0]&&(t[eQ]=!0),t){let t=(r in n||(n[r]=[]),n[r]);0>t.indexOf(e)&&t.push(e)}}function e3(e=null){this.j={},this.jr=[],this.jd=null,this.t=e}e3.groups={},e3.prototype={accepts(){return!!this.t},go(e){let t=this.j[e];if(t)return t;for(let t=0;t<this.jr.length;t++){let n=this.jr[t][0],r=this.jr[t][1];if(r&&n.test(e))return r}return this.jd},has(e,t=!1){return t?e in this.j:!!this.go(e)},ta(e,t,n,r){for(let i=0;i<e.length;i++)this.tt(e[i],t,n,r)},tr(e,t,n,r){let i;return r=r||e3.groups,t&&t.j?i=t:(i=new e3(t),n&&r&&e2(t,n,r)),this.jr.push([e,i]),i},ts(e,t,n,r){let i=this,o=e.length;if(!o)return i;for(let t=0;t<o-1;t++)i=i.tt(e[t]);return i.tt(e[o-1],t,n,r)},tt(e,t,n,r){if(r=r||e3.groups,t&&t.j)return this.j[e]=t,t;let i,o=this.go(e);return o?(Object.assign((i=new e3).j,o.j),i.jr.push.apply(i.jr,o.jr),i.jd=o.jd,i.t=o.t):i=new e3,t&&(r&&(i.t&&"string"==typeof i.t?e2(t,Object.assign(function(e,t){let n={};for(let r in t)t[r].indexOf(e)>=0&&(n[r]=!0);return n}(i.t,r),n),r):n&&e2(t,n,r)),i.t=t),this.j[e]=i,i}};let e5=(e,t,n,r,i)=>e.ta(t,n,r,i),e6=(e,t,n,r,i)=>e.tr(t,n,r,i),e4=(e,t,n,r,i)=>e.ts(t,n,r,i),e8=(e,t,n,r,i)=>e.tt(t,n,r,i),e9="WORD",e7="UWORD",te="ASCIINUMERICAL",tt="ALPHANUMERICAL",tn="LOCALHOST",tr="UTLD",ti="SCHEME",to="SLASH_SCHEME",ts="OPENBRACE",ta="CLOSEBRACE",tl="OPENBRACKET",td="CLOSEBRACKET",tc="OPENPAREN",th="CLOSEPAREN",tu="OPENANGLEBRACKET",tp="CLOSEANGLEBRACKET",tf="FULLWIDTHLEFTPAREN",tg="FULLWIDTHRIGHTPAREN",tm="LEFTCORNERBRACKET",ty="RIGHTCORNERBRACKET",tb="LEFTWHITECORNERBRACKET",tx="RIGHTWHITECORNERBRACKET",tw="FULLWIDTHLESSTHAN",tv="FULLWIDTHGREATERTHAN",tS="AMPERSAND",tC="APOSTROPHE",tk="ASTERISK",tP="BACKSLASH",tT="BACKTICK",tE="CARET",tI="COLON",t_="COMMA",tM="DOLLAR",tA="EQUALS",tj="EXCLAMATION",tO="HYPHEN",tD="PERCENT",tL="PIPE",tR="PLUS",tF="POUND",tz="QUERY",tN="QUOTE",t$="FULLWIDTHMIDDLEDOT",tB="SEMI",tH="SLASH",tU="TILDE",tK="UNDERSCORE",tW="EMOJI";var tV=Object.freeze({__proto__:null,ALPHANUMERICAL:tt,AMPERSAND:tS,APOSTROPHE:tC,ASCIINUMERICAL:te,ASTERISK:tk,AT:"AT",BACKSLASH:tP,BACKTICK:tT,CARET:tE,CLOSEANGLEBRACKET:tp,CLOSEBRACE:ta,CLOSEBRACKET:td,CLOSEPAREN:th,COLON:tI,COMMA:t_,DOLLAR:tM,DOT:"DOT",EMOJI:tW,EQUALS:tA,EXCLAMATION:tj,FULLWIDTHGREATERTHAN:tv,FULLWIDTHLEFTPAREN:tf,FULLWIDTHLESSTHAN:tw,FULLWIDTHMIDDLEDOT:t$,FULLWIDTHRIGHTPAREN:tg,HYPHEN:tO,LEFTCORNERBRACKET:tm,LEFTWHITECORNERBRACKET:tb,LOCALHOST:tn,NL:"NL",NUM:"NUM",OPENANGLEBRACKET:tu,OPENBRACE:ts,OPENBRACKET:tl,OPENPAREN:tc,PERCENT:tD,PIPE:tL,PLUS:tR,POUND:tF,QUERY:tz,QUOTE:tN,RIGHTCORNERBRACKET:ty,RIGHTWHITECORNERBRACKET:tx,SCHEME:ti,SEMI:tB,SLASH:tH,SLASH_SCHEME:to,SYM:"SYM",TILDE:tU,TLD:"TLD",UNDERSCORE:tK,UTLD:tr,UWORD:e7,WORD:e9,WS:"WS"});let tY=/[a-z]/,tG=/\p{L}/u,tq=/\p{Emoji}/u,tX=/\d/,tJ=/\s/,tZ=null,tQ=null;function t0(e,t){let n=function(e){let t=[],n=e.length,r=0;for(;r<n;){let i,o=e.charCodeAt(r),s=o<55296||o>56319||r+1===n||(i=e.charCodeAt(r+1))<56320||i>57343?e[r]:e.slice(r,r+2);t.push(s),r+=s.length}return t}(t.replace(/[A-Z]/g,e=>e.toLowerCase())),r=n.length,i=[],o=0,s=0;for(;s<r;){let a=e,l=null,d=0,c=null,h=-1,u=-1;for(;s<r&&(l=a.go(n[s]));)(a=l).accepts()?(h=0,u=0,c=a):h>=0&&(h+=n[s].length,u++),d+=n[s].length,o+=n[s].length,s++;o-=h,s-=u,d-=h,i.push({t:c.t,v:t.slice(o-d,o),s:o-d,e:o})}return i}function t1(e,t,n,r,i){let o,s=t.length;for(let n=0;n<s-1;n++){let s=t[n];e.j[s]?o=e.j[s]:((o=new e3(r)).jr=i.slice(),e.j[s]=o),e=o}return(o=new e3(n)).jr=i.slice(),e.j[t[s-1]]=o,o}function t2(e){let t=[],n=[],r=0;for(;r<e.length;){let i=0;for(;"0123456789".indexOf(e[r+i])>=0;)i++;if(i>0){t.push(n.join(""));for(let t=parseInt(e.substring(r,r+i),10);t>0;t--)n.pop();r+=i}else n.push(e[r]),r++}return t}let t3={defaultProtocol:"http",events:null,format:t6,formatHref:t6,nl2br:!1,tagName:"a",target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function t5(e,t=null){let n=Object.assign({},t3);e&&(n=Object.assign(n,e instanceof t5?e.o:e));let r=n.ignoreTags,i=[];for(let e=0;e<r.length;e++)i.push(r[e].toUpperCase());this.o=n,t&&(this.defaultRender=t),this.ignoreTags=i}function t6(e){return e}function t4(e,t){this.t="token",this.v=e,this.tk=t}function t8(e,t){class n extends t4{constructor(t,n){super(t,n),this.t=e}}for(let e in t)n.prototype[e]=t[e];return n.t=e,n}t5.prototype={o:t3,ignoreTags:[],defaultRender:e=>e,check(e){return this.get("validate",e.toString(),e)},get(e,t,n){let r=null!=t,i=this.o[e];return i&&("object"==typeof i?"function"==typeof(i=n.t in i?i[n.t]:t3[e])&&r&&(i=i(t,n)):"function"==typeof i&&r&&(i=i(t,n.t,n))),i},getObj(e,t,n){let r=this.o[e];return"function"==typeof r&&null!=t&&(r=r(t,n.t,n)),r},render(e){let t=e.render(this);return(this.get("render",null,e)||this.defaultRender)(t,e.t,e)}},t4.prototype={isLink:!1,toString(){return this.v},toHref(e){return this.toString()},toFormattedString(e){let t=this.toString(),n=e.get("truncate",t,this),r=e.get("format",t,this);return n&&r.length>n?r.substring(0,n)+"…":r},toFormattedHref(e){return e.get("formatHref",this.toHref(e.get("defaultProtocol")),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(e=t3.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(e),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(e){return{type:this.t,value:this.toFormattedString(e),isLink:this.isLink,href:this.toFormattedHref(e),start:this.startIndex(),end:this.endIndex()}},validate(e){return e.get("validate",this.toString(),this)},render(e){let t=this.toHref(e.get("defaultProtocol")),n=e.get("formatHref",t,this),r=e.get("tagName",t,this),i=this.toFormattedString(e),o={},s=e.get("className",t,this),a=e.get("target",t,this),l=e.get("rel",t,this),d=e.getObj("attributes",t,this),c=e.getObj("events",t,this);return o.href=n,s&&(o.class=s),a&&(o.target=a),l&&(o.rel=l),d&&Object.assign(o,d),{tagName:r,attributes:o,content:i,eventListeners:c}}};let t9=t8("email",{isLink:!0,toHref(){return"mailto:"+this.toString()}}),t7=t8("text"),ne=t8("nl"),nt=t8("url",{isLink:!0,toHref(e=t3.defaultProtocol){return this.hasProtocol()?this.v:`${e}://${this.v}`},hasProtocol(){let e=this.tk;return e.length>=2&&e[0].t!==tn&&e[1].t===tI}}),nn=e=>new e3(e);function nr(e,t,n){let r=n[0].s,i=n[n.length-1].e;return new e(t.slice(r,i),n)}let ni="u">typeof console&&console&&console.warn||(()=>{}),no={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function ns(e,t=!1){if(no.initialized&&ni(`linkifyjs: already initialized - will not register custom scheme "${e}" until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(e))throw Error(`linkifyjs: incorrect scheme format.
10
- 1. Must only contain digits, lowercase ASCII letters or "-"
11
- 2. Cannot start or end with "-"
12
- 3. "-" cannot repeat`);no.customSchemes.push([e,t])}function na(e){return no.initialized||function(){no.scanner=function(e=[]){let t={};e3.groups=t;let n=new e3;null==tZ&&(tZ=t2("aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2odyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rck0msd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5m\xf6gensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2oodside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2")),null==tQ&&(tQ=t2("ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2")),e8(n,"'",tC),e8(n,"{",ts),e8(n,"}",ta),e8(n,"[",tl),e8(n,"]",td),e8(n,"(",tc),e8(n,")",th),e8(n,"<",tu),e8(n,">",tp),e8(n,"(",tf),e8(n,")",tg),e8(n,"「",tm),e8(n,"」",ty),e8(n,"『",tb),e8(n,"』",tx),e8(n,"<",tw),e8(n,">",tv),e8(n,"&",tS),e8(n,"*",tk),e8(n,"@","AT"),e8(n,"`",tT),e8(n,"^",tE),e8(n,":",tI),e8(n,",",t_),e8(n,"$",tM),e8(n,".","DOT"),e8(n,"=",tA),e8(n,"!",tj),e8(n,"-",tO),e8(n,"%",tD),e8(n,"|",tL),e8(n,"+",tR),e8(n,"#",tF),e8(n,"?",tz),e8(n,'"',tN),e8(n,"/",tH),e8(n,";",tB),e8(n,"~",tU),e8(n,"_",tK),e8(n,"\\",tP),e8(n,"・",t$);let r=e6(n,tX,"NUM",{[eG]:!0});e6(r,tX,r);let i=e6(r,tY,te,{[eJ]:!0}),o=e6(r,tG,tt,{[eZ]:!0}),s=e6(n,tY,e9,{[eq]:!0});e6(s,tX,i),e6(s,tY,s),e6(i,tX,i),e6(i,tY,i);let a=e6(n,tG,e7,{[eX]:!0});e6(a,tY),e6(a,tX,o),e6(a,tG,a),e6(o,tX,o),e6(o,tY),e6(o,tG,o);let l=e8(n,"\n","NL",{[e1]:!0}),d=e8(n,"\r","WS",{[e1]:!0}),c=e6(n,tJ,"WS",{[e1]:!0});e8(n,"",c),e8(d,"\n",l),e8(d,"",c),e6(d,tJ,c),e8(c,"\r"),e8(c,"\n"),e6(c,tJ,c),e8(c,"",c);let h=e6(n,tq,tW,{[e0]:!0});e8(h,"#"),e6(h,tq,h),e8(h,"️",h);let u=e8(h,"‍");e8(u,"#"),e6(u,tq,h);let p=[[tY,s],[tX,i]],f=[[tY,null],[tG,a],[tX,o]];for(let e=0;e<tZ.length;e++)t1(n,tZ[e],"TLD",e9,p);for(let e=0;e<tQ.length;e++)t1(n,tQ[e],tr,e7,f);e2("TLD",{tld:!0,ascii:!0},t),e2(tr,{utld:!0,alpha:!0},t),t1(n,"file",ti,e9,p),t1(n,"mailto",ti,e9,p),t1(n,"http",to,e9,p),t1(n,"https",to,e9,p),t1(n,"ftp",to,e9,p),t1(n,"ftps",to,e9,p),e2(ti,{scheme:!0,ascii:!0},t),e2(to,{slashscheme:!0,ascii:!0},t),e=e.sort((e,t)=>e[0]>t[0]?1:-1);for(let t=0;t<e.length;t++){let r=e[t][0],i=e[t][1]?{scheme:!0}:{slashscheme:!0};r.indexOf("-")>=0?i[eQ]=!0:tY.test(r)?tX.test(r)?i[eJ]=!0:i[eq]=!0:i[eG]=!0,e4(n,r,r,i)}return e4(n,"localhost",tn,{ascii:!0}),n.jd=new e3("SYM"),{start:n,tokens:Object.assign({groups:t},tV)}}(no.customSchemes);for(let e=0;e<no.tokenQueue.length;e++)no.tokenQueue[e][1]({scanner:no.scanner});no.parser=function({groups:e}){let t=e.domain.concat([tS,tk,"AT",tP,tT,tE,tM,tA,tO,"NUM",tD,tL,tR,tF,tH,"SYM",tU,tK]),n=[tC,tI,t_,"DOT",tj,tD,tz,tN,tB,tu,tp,ts,ta,td,tl,tc,th,tf,tg,tm,ty,tb,tx,tw,tv],r=[tS,tC,tk,tP,tT,tE,tM,tA,tO,ts,ta,tD,tL,tR,tF,tz,tH,"SYM",tU,tK],i=nn(),o=e8(i,tU);e5(o,r,o),e5(o,e.domain,o);let s=nn(),a=nn(),l=nn();e5(i,e.domain,s),e5(i,e.scheme,a),e5(i,e.slashscheme,l),e5(s,r,o),e5(s,e.domain,s);let d=e8(s,"AT");e8(o,"AT",d),e8(a,"AT",d),e8(l,"AT",d);let c=e8(o,"DOT");e5(c,r,o),e5(c,e.domain,o);let h=nn();e5(d,e.domain,h),e5(h,e.domain,h);let u=e8(h,"DOT");e5(u,e.domain,h);let p=nn(t9);e5(u,e.tld,p),e5(u,e.utld,p),e8(d,tn,p);let f=e8(h,tO);e8(f,tO,f),e5(f,e.domain,h),e5(p,e.domain,h),e8(p,"DOT",u),e8(p,tO,f);let g=e8(s,tO),m=e8(s,"DOT");e8(g,tO,g),e5(g,e.domain,s),e5(m,r,o),e5(m,e.domain,s);let y=nn(nt);e5(m,e.tld,y),e5(m,e.utld,y),e5(y,e.domain,s),e5(y,r,o),e8(y,"DOT",m),e8(y,tO,g),e8(y,"AT",d);let b=e8(y,tI),x=nn(nt);e5(b,e.numeric,x);let w=nn(nt),v=nn();e5(w,t,w),e5(w,n,v),e5(v,t,w),e5(v,n,v),e8(y,tH,w),e8(x,tH,w);let S=e8(a,tI),C=e8(l,tI),k=e8(C,tH),P=e8(k,tH);e5(a,e.domain,s),e8(a,"DOT",m),e8(a,tO,g),e5(l,e.domain,s),e8(l,"DOT",m),e8(l,tO,g),e5(S,e.domain,w),e8(S,tH,w),e8(S,tz,w),e5(P,e.domain,w),e5(P,t,w),e8(P,tH,w);let T=[[ts,ta],[tl,td],[tc,th],[tu,tp],[tf,tg],[tm,ty],[tb,tx],[tw,tv]];for(let e=0;e<T.length;e++){let[r,i]=T[e],o=e8(w,r);e8(v,r,o);let s=nn(nt);e5(o,t,s);let a=nn();e5(o,n,a),e8(o,i,w),e5(s,t,s),e5(s,n,a),e5(a,t,s),e5(a,n,a),e8(s,i,w),e8(a,i,w)}return e8(i,tn,y),e8(i,"NL",ne),{start:i,tokens:tV}}(no.scanner.tokens);for(let e=0;e<no.pluginQueue.length;e++)no.pluginQueue[e][1]({scanner:no.scanner,parser:no.parser});no.initialized=!0}(),function(e,t,n){let r=n.length,i=0,o=[],s=[];for(;i<r;){let a=e,l=null,d=null,c=0,h=null,u=-1;for(;i<r&&!(l=a.go(n[i].t));)s.push(n[i++]);for(;i<r&&(d=l||a.go(n[i].t));)l=null,(a=d).accepts()?(u=0,h=a):u>=0&&u++,i++,c++;if(u<0)(i-=c)<r&&(s.push(n[i]),i++);else{s.length>0&&(o.push(nr(t7,t,s)),s=[]),i-=u,c-=u;let e=h.t,r=n.slice(i-c,i);o.push(nr(e,t,r))}}return s.length>0&&o.push(nr(t7,t,s)),o}(no.parser.start,e,t0(no.scanner.start,e))}function nl(e,t=null,n=null){if(t&&"object"==typeof t){if(n)throw Error(`linkifyjs: Invalid link type ${t}; must be a string`);n=t,t=null}let r=new t5(n),i=na(e),o=[];for(let e=0;e<i.length;e++){let n=i[e];n.isLink&&(!t||n.t===t)&&r.check(n)&&o.push(n.toFormattedObject(r))}return o}na.scan=t0;let nd="[\0- \xa0 ᠎ -\u2029  ]",nc=new RegExp(nd),nh=RegExp(`${nd}$`),nu=RegExp(nd,"g"),np=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)$/,nf=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)/g;function ng(e,t){let n=0;for(let r=t-1;r>=0&&"\\"===e[r];r-=1)n+=1;return n%2==1}function nm(e,t,n){var r,i;let[,o,s]=t;return!((t.index?e[t.index-1]:void 0)==="!"||ng(e,null!=(r=t.index)?r:0)||function(e,t){let n=0,r=0;for(;r<t;){if("`"!==e[r]||0===n&&ng(e,r)){r+=1;continue}let i=0;for(;r<t&&"`"===e[r];)i+=1,r+=1;0===n?n=i:i===n&&(n=0)}return n>0}(e,null!=(i=t.index)?i:0))&&!!o.trim()&&n(s)}function ny(e){var t,n;let[r,i,o,,s,a,l]=e,d=null!=(t=null!=s?s:a)?t:l;return{index:null!=(n=e.index)?n:0,text:r,replaceWith:i,data:{href:o,title:d||null,markdown:!0}}}function nb(e){var t,n,r;return{href:null==(t=e.data)?void 0:t.href,title:null!=(n=null==(r=e.data)?void 0:r.title)?n:null}}function nx(e,t){let n=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"];return t&&t.forEach(e=>{let t="string"==typeof e?e:e.scheme;t&&n.push(t)}),!e||e.replace(nu,"").match(RegExp(`^(?:(?:${n.map(e=>e.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")).join("|")}):|[^a-z]|[a-z0-9+.\\-]+(?:[^a-z+.\\-:]|$))`,"i"))}let nw=eg.CU.create({name:"link",priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(e=>{"string"==typeof e?ns(e):ns(e.scheme,e.optionalSlashes)})},onDestroy(){e3.groups={},no.scanner=null,no.parser=null,no.tokenQueue=[],no.pluginQueue=[],no.customSchemes=[],no.initialized=!1},inclusive(){return this.options.autolink},addOptions:()=>({openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,markdownLinks:!1,autolink:!0,protocols:[],defaultProtocol:"http",HTMLAttributes:{target:"_blank",rel:"noopener noreferrer nofollow",class:null},isAllowedUri:(e,t)=>!!nx(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e),n=/^[a-z][a-z0-9+.-]*:/i.test(e);if(t||n&&!e.includes("@"))return!0;let r=(e.includes("@")?e.split("@").pop():e).split(/[/?#:]/)[0];return!/^\d{1,3}(\.\d{1,3}){3}$/.test(r)&&!!/\./.test(r)}}),addAttributes(){var e,t,n;return{href:{default:null,parseHTML:e=>e.getAttribute("href")},target:{default:null!=(e=this.options.HTMLAttributes.target)?e:null},rel:{default:null!=(t=this.options.HTMLAttributes.rel)?t:null},class:{default:null!=(n=this.options.HTMLAttributes.class)?n:null},title:{default:null}}},parseHTML(){return[{tag:"a[href]",getAttrs:e=>{let t=e.getAttribute("href");return!!t&&!!this.options.isAllowedUri(t,{defaultValidate:e=>!!nx(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})&&null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!nx(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",(0,eg.KV)(this.options.HTMLAttributes,e),0]:["a",(0,eg.KV)(this.options.HTMLAttributes,{...e,href:""}),0]},markdownTokenName:"link",parseMarkdown:(e,t)=>t.applyMark("link",t.parseInline(e.tokens||[]),{href:e.href,title:e.title||null}),renderMarkdown:(e,t)=>{var n,r,i,o;let s=null!=(n=null==(r=e.attrs)?void 0:r.href)?n:"",a=null!=(i=null==(o=e.attrs)?void 0:o.title)?i:"",l=t.renderChildren(e);return a?`[${l}](${s} "${a}")`:`[${l}](${s})`},addCommands(){return{setLink:e=>({chain:t})=>{let{href:n}=e;return!!this.options.isAllowedUri(n,{defaultValidate:e=>!!nx(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})&&t().setMark(this.name,e).setMeta("preventAutolink",!0).run()},toggleLink:e=>({chain:t})=>{let{href:n}=e||{};return(!n||!!this.options.isAllowedUri(n,{defaultValidate:e=>!!nx(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol}))&&t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}},addInputRules(){var e;let t;return this.options.markdownLinks?[(e={type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!nx(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})},t=(0,eg.OX)({find:t=>{let n=np.exec(t);return n&&nm(t,n,e.isAllowedHref)?ny(n):null},type:e.type,getAttributes:nb}),new eg.fV({find:t.find,handler:e=>{let n=t.handler(e);return null!==n&&e.state.tr.steps.length&&e.state.tr.setMeta("preventAutolink",!0),n}}))]:[]},addPasteRules(){let e=e=>{let t=[];if(e){let{protocols:n,defaultProtocol:r}=this.options;nl(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!nx(e,n),protocols:n,defaultProtocol:r})).forEach(e=>{this.options.shouldAutoLink(e.value)&&t.push({text:e.value,data:{href:e.href},index:e.start})})}return t};if(this.options.markdownLinks){var t;let n;return[(t={type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!nx(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol}),findPlainUrls:e},n=(0,eg.Zc)({find:e=>{var n,r;let i=[];for(let n of e.matchAll(nf))nm(e,n,t.isAllowedHref)&&i.push(ny(n));let o=(null!=(n=null==(r=t.findPlainUrls)?void 0:r.call(t,e))?n:[]).filter(e=>!i.some(t=>t.index<e.index+e.text.length&&e.index<t.index+t.text.length));return[...i,...o]},type:t.type,getAttributes:nb}),new eg._n({find:n.find,handler:e=>{var t;let r=n.handler(e);return null!==r&&e.state.tr.steps.length&&(null==(t=e.match.data)?void 0:t.markdown)&&e.state.tr.setMeta("preventAutolink",!0),r}}))]}return[(0,eg.Zc)({find:e,type:this.type,getAttributes:e=>{var t;return{href:null==(t=e.data)?void 0:t.href}}})]},addProseMirrorPlugins(){var e,t,n;let r=[],{protocols:i,defaultProtocol:o}=this.options;return this.options.autolink&&r.push((e={type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!nx(e,i),protocols:i,defaultProtocol:o}),shouldAutoLink:this.options.shouldAutoLink},new eC.k_({key:new eC.hs("autolink"),appendTransaction:(t,n,r)=>{let i=t.some(e=>e.docChanged)&&!n.doc.eq(r.doc),o=t.some(e=>e.getMeta("preventAutolink"));if(!i||o)return;let{tr:s}=r,a=(0,eg.T7)(n.doc,[...t]);if((0,eg.FF)(a).forEach(({newRange:t})=>{let n,i,o=(0,eg.Nx)(r.doc,t,e=>e.isTextblock);if(o.length>1)n=o[0],i=r.doc.textBetween(n.pos,n.pos+n.node.nodeSize,void 0," ");else if(o.length){let e=r.doc.textBetween(t.from,t.to," "," ");if(!nh.test(e))return;n=o[0],i=r.doc.textBetween(n.pos,t.to,void 0," ")}if(n&&i){let t=i.split(nc).filter(Boolean);if(t.length<=0)return!1;let o=t[t.length-1],a=n.pos+i.lastIndexOf(o);if(!o)return!1;let l=na(o).map(t=>t.toObject(e.defaultProtocol));if(!(1===l.length?l[0].isLink:3===l.length&&!!l[1].isLink&&["()","[]"].includes(l[0].value+l[2].value)))return!1;l.filter(e=>e.isLink).map(e=>({...e,from:a+e.start+1,to:a+e.end+1})).filter(e=>!r.schema.marks.code||!r.doc.rangeHasMark(e.from,e.to,r.schema.marks.code)).filter(t=>e.validate(t.value)).filter(t=>e.shouldAutoLink(t.value)).forEach(t=>{(0,eg.hO)(t.from,t.to,r.doc).some(t=>t.mark.type===e.type)||s.addMark(t.from,t.to,e.type.create({href:t.href}))})}}),s.steps.length)return s}}))),r.push((t={type:this.type,editor:this.editor,openOnClick:"whenNotEditable"===this.options.openOnClick||this.options.openOnClick,enableClickSelection:this.options.enableClickSelection},new eC.k_({key:new eC.hs("handleClickLink"),props:{handleClick:(e,n,r)=>{if(0!==r.button||!e.editable)return!1;let i=null;if(r.target instanceof HTMLAnchorElement)i=r.target;else{let e=r.target;if(!e)return!1;let n=t.editor.view.dom;(i=e.closest("a"))&&!n.contains(i)&&(i=null)}if(!i)return!1;let o=!1;if(t.enableClickSelection&&(o=t.editor.commands.extendMarkRange(t.type.name)),t.openOnClick){var s,a;let n=(0,eg.gu)(e.state,t.type.name),r=null!=(s=i.href)?s:n.href,l=null!=(a=i.target)?a:n.target;r&&(window.open(r,l),o=!0)}return o}}}))),this.options.linkOnPaste&&r.push((n={editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink},new eC.k_({key:new eC.hs("handlePasteLink"),props:{handlePaste:(e,t,r)=>{let{shouldAutoLink:i}=n,{state:o}=e,{selection:s}=o,{empty:a}=s;if(a)return!1;let l="";r.content.forEach(e=>{l+=e.textContent});let d=nl(l,{defaultProtocol:n.defaultProtocol}).find(e=>e.isLink&&e.value===l);return!!l&&!!d&&(void 0===i||!!i(d.value))&&n.editor.commands.setMark(n.type,{href:d.href})}}}))),r}}),nv="textStyle",nS=/^\s*([-+*])\s$/,nC=eg.bP.create({name:"bulletList",addOptions:()=>({itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}),group:"block list",content(){return`${this.options.itemTypeName}+`},parseHTML:()=>[{tag:"ul"}],renderHTML({HTMLAttributes:e}){return["ul",(0,eg.KV)(this.options.HTMLAttributes,e),0]},markdownTokenName:"list",parseMarkdown:(e,t)=>"list"!==e.type||e.ordered?[]:{type:"bulletList",content:e.items?t.parseChildren(e.items):[]},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,"\n"):"",markdownOptions:{indentsContent:!0},addCommands(){return{toggleBulletList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes("listItem",this.editor.getAttributes(nv)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let e=(0,eg.tG)({find:nS,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(e=(0,eg.tG)({find:nS,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(nv),editor:this.editor})),[e]}}),nk=(e,t)=>eg.YY.create({name:`${e}BranchingDeleteKeymap`,priority:101,addKeyboardShortcuts(){let n=()=>{let n;return n=this.editor,((e,t,n,r)=>{let i=((e,t,n)=>{let{selection:r}=e;if(!r.empty)return null;let{$from:i}=r;if(!i.parent.isTextblock||i.parentOffset!==i.parent.content.size)return null;let o=-1;for(let e=i.depth;e>0;e-=1)if(i.node(e).type.name===t){o=e;break}if(o<0)return null;let s=i.node(o),a=i.index(o);if(a+1>=s.childCount)return null;let l=s.child(a+1);if(!n.includes(l.type.name))return null;let d=e.schema.nodes[t],c=!1;if(l.forEach(e=>{e.type===d&&e.childCount>1&&(c=!0)}),!c)return null;let h=e.doc.resolve(i.after()).nodeAfter;if(!h||!n.includes(h.type.name))return null;let u=[];return(h.forEach(e=>{u.push(e)}),0===u.length)?null:{listItemDepth:o,nestedList:h,nestedListPos:i.after(),insertPos:i.after(o),items:u}})(e,n,r);if(!i)return!1;let{selection:o}=e,{nestedList:s,nestedListPos:a,insertPos:l,items:d}=i,c=e.tr;c.delete(a,a+s.nodeSize);let h=c.mapping.map(l);return c.insert(h,eS.FK.from(d)),c.setSelection(o.map(c.doc,c.mapping)),t&&t(c),!0})(n.state,n.view.dispatch,e,t)};return{Delete:n,"Mod-Delete":n}}}),nP=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]],nT="abcdefghijklmnopqrstuvwxyz",nE=String.raw`\d+|[ivxlcdmIVXLCDM]+|${"[a-zA-Z]{1,2}"}`;function nI(e){let t=e,n="";for(let[e,r]of nP)for(;t>=e;)n+=r,t-=e;return n}function n_(e){return nI(e).toUpperCase()}function nM(e){let t=e.toLowerCase(),n=0,r=0;for(;n<t.length;){let e=!1;for(let[i,o]of nP)if(t.startsWith(o,n)){r+=i,n+=o.length,e=!0;break}if(!e)return 0}return r}function nA(e){if(e<=26)return nT[e-1];let t=Math.floor((e-1)/26)-1,n=(e-1)%26;return t<0?nT[n]:nT[t]+nT[n]}function nj(e){if(!(!e||/^\d+$/.test(e))){if(function(e){if(!/^[ivxlcdmIVXLCDM]+$/.test(e))return!1;let t=nM(e);return!(t<=0)&&(e===e.toLowerCase()?nI(t):n_(t))===e}(e))return e===e.toLowerCase()?"i":"I";if(/^[a-z]{1,2}$/.test(e))return"a";if(/^[A-Z]{1,2}$/.test(e))return"A"}}function nO(e){if(/^\d+$/.test(e))return parseInt(e,10);let t=nj(e);if("i"===t||"I"===t)return nM(e);if("a"===t||"A"===t){let t,n=1===(t=e.toLowerCase()).length?t.charCodeAt(0)-97+1:2===t.length?(t.charCodeAt(0)-97+1)*26+(t.charCodeAt(1)-97)+1:0;return n>0?n:1}let n=parseInt(e,10);return Number.isNaN(n)?1:n}let nD=eg.bP.create({name:"listItem",addOptions:()=>({HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}),content:"paragraph block*",defining:!0,parseHTML:()=>[{tag:"li"}],renderHTML({HTMLAttributes:e}){return["li",(0,eg.KV)(this.options.HTMLAttributes,e),0]},markdownTokenName:"list_item",parseMarkdown:(e,t)=>{var n,r,i,o;if("list_item"!==e.type)return[];let s=null!=(n=t.parseBlockChildren)?n:t.parseChildren,a=[];if(e.tokens&&e.tokens.length>0){let n;if(n=null==(r=e.tokens)?void 0:r[0],e.text&&(null==(i=e.tokens)?void 0:i.length)===1&&(null==n?void 0:n.type)==="list"&&n.ordered&&n.raw===e.text)return{type:"listItem",content:[{type:"paragraph",content:(o=e.text||"",t.tokenizeInline?t.parseInline(t.tokenizeInline(o)):t.parseInline([{type:"text",raw:o,text:o}]))}]};if(e.tokens.some(e=>"paragraph"===e.type))a=s(e.tokens);else{let n=e.tokens[0];if(n&&"text"===n.type&&n.tokens&&n.tokens.length>0){if(a=[{type:"paragraph",content:t.parseInline(n.tokens)}],e.tokens.length>1){let t=s(e.tokens.slice(1));a.push(...t)}}else a=s(e.tokens)}}return 0===a.length&&(a=[{type:"paragraph",content:[]}]),{type:"listItem",content:a}},renderMarkdown:(e,t,n)=>(0,eg.kj)(e,t,e=>{if("bulletList"===e.parentType)return"- ";if("orderedList"===e.parentType){var t,n;let r=(null==(t=e.meta)||null==(t=t.parentAttrs)?void 0:t.start)||1;return function(e,t,n=". "){let r=t+1;if(!e||"1"===e)return`${r}${n}`;switch(e){case"a":return`${nA(r)}${n}`;case"A":return`${nA(r).toUpperCase()}${n}`;case"i":return`${nI(r)}${n}`;case"I":return`${n_(r)}${n}`;default:return`${r}${n}`}}(null==(n=e.meta)||null==(n=n.parentAttrs)?void 0:n.type,r-1+(e.index||0),". ")}return"- "},n),addExtensions(){return[nk(this.name,[this.options.bulletListTypeName,this.options.orderedListTypeName])]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),nL=(e,t)=>{let{$from:n}=t.selection,r=(0,eg.Pg)(e,t.schema),i=n.depth,o=n.pos,s=null;for(;i>0&&null===s;)n.node(i).type===r?s=i:(i-=1,o-=1);return null===s?null:{$pos:t.doc.resolve(o),depth:s}},nR=(e,t)=>{let n=nL(e,t);if(!n)return!1;let[,r]=(0,eg.fl)(t,e,n.$pos.pos+4);return r},nF=(e,t,n)=>{if(e.commands.undoInputRule())return!0;if(e.state.selection.from!==e.state.selection.to)return!1;if(!(0,eg.rU)(e.state,t)&&((e,t)=>{let{$anchor:n}=e.selection,r=Math.max(0,n.pos-2),i=e.doc.resolve(r).node();return!!i&&!!t.includes(i.type.name)})(e.state,n)){let{$anchor:n}=e.state.selection,r=e.state.doc.resolve(n.before()-1),i=[];r.node().descendants((e,n)=>{e.type.name===t&&i.push({node:e,pos:n})});let o=i.at(-1);if(!o)return!1;let s=e.state.doc.resolve(r.start()+o.pos+1);return e.chain().cut({from:n.start()-1,to:n.end()+1},s.end()).joinForward().run()}if(!(0,eg.rU)(e.state,t)||!(0,eg.J_)(e.state))return!1;let{$from:r}=e.state.selection,i=r.depth-1;return r.node(i).type===e.schema.nodes[t]&&0===r.index(i)&&e.chain().liftListItem(t).run()},nz=(e,t)=>{var n,r;let i,o,s,a;if(!(0,eg.rU)(e.state,t)||!(0,eg.QN)(e.state,t))return!1;let{selection:l}=e.state,{$from:d,$to:c}=l;return!(!l.empty&&d.sameParent(c))&&((i=nR(t,n=e.state),(o=nL(t,n))&&i&&(i>o.depth||0))?e.chain().focus(e.state.selection.from+4).lift(t).joinBackward().run():(s=nR(t,r=e.state),(a=nL(t,r))&&s&&(s<a.depth||0))?e.chain().joinForward().joinBackward().run():e.commands.joinItemForward())},nN=(e,t,n)=>{let{state:r}=e,{selection:i}=r;if(!i.empty)return!1;let{$from:o}=i;if(0!==o.parentOffset||!o.parent.isTextblock||(0,eg.rU)(r,t))return!1;let s=(0,eg.H_)(o);if(!s||!n.includes(s.type.name))return!1;let a=s.lastChild;if(!a||a.type.name!==t)return!1;let l=o.parent;if(!a.canReplace(a.childCount,a.childCount,eS.FK.from(l)))return!1;let d=o.before(),c=o.after(),h=d-2;return e.commands.command(({tr:e,dispatch:t})=>(t&&(e.delete(d,c).insert(h,eS.FK.from(l)),e.setSelection(eC.U3.create(e.doc,h+1)),e.scrollIntoView()),!0))},n$=eg.YY.create({name:"listKeymap",addOptions:()=>({listTypes:[{itemName:"listItem",wrapperNames:["bulletList","orderedList"]},{itemName:"taskItem",wrapperNames:["taskList"]}]}),addKeyboardShortcuts(){return{Delete:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{void 0!==e.state.schema.nodes[n]&&nz(e,n)&&(t=!0)}),t},"Mod-Delete":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{void 0!==e.state.schema.nodes[n]&&nz(e,n)&&(t=!0)}),t},Backspace:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{void 0!==e.state.schema.nodes[n]&&nF(e,n,r)&&(t=!0)}),t},"Mod-Backspace":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{void 0!==e.state.schema.nodes[n]&&nF(e,n,r)&&(t=!0)}),t},Tab:({editor:e})=>{for(let{itemName:t,wrapperNames:n}of this.options.listTypes)if(void 0!==e.state.schema.nodes[t]&&nN(e,t,n))return!0;return!1}}}}),nB=RegExp(`^(\\s*)(${nE})([.)])\\s+(.*)$`),nH=/^\s/,nU={heading:/^#{1,6}(?:\s|$)/,bulletItem:/^[-+*]\s+/,codeFence:/^(?:```|~~~)/,blockMath:/^\$\$/,thematicBreak:/^(?:(?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})$/},nK=RegExp(`^(${nE})([.)])\\s+(.+)$`),nW="textStyle",nV=/^(\d+)\.\s$/;function nY(e){let t=e.match(/list-style-type\s*:\s*([^;]+)/i);if(!t)return null;switch(t[1].trim().toLowerCase()){case"upper-roman":return"I";case"lower-roman":return"i";case"upper-alpha":case"upper-latin":return"A";case"lower-alpha":case"lower-latin":return"a";default:return null}}let nG=eg.bP.create({name:"orderedList",addOptions:()=>({itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}),group:"block list",content(){return`${this.options.itemTypeName}+`},addAttributes:()=>({start:{default:1,parseHTML:e=>e.hasAttribute("start")?parseInt(e.getAttribute("start")||"",10):1},type:{default:null,parseHTML:e=>{let t=e.getAttribute("type");if(t)return t;let n=e.getAttribute("style");if(n){let e=nY(n);if(e)return e}let r=e.querySelector("li");if(r){let e=r.getAttribute("style");if(e){let t=nY(e);if(t)return t}}return null}}}),parseHTML:()=>[{tag:"ol"}],renderHTML({HTMLAttributes:e}){let{start:t,type:n,...r}=e,i=(0,eg.KV)(this.options.HTMLAttributes,r);return 1!==t&&(i.start=t),n&&"1"!==n&&(i.type=n),["ol",i,0]},markdownTokenName:"list",parseMarkdown:(e,t)=>{var n;if("list"!==e.type||!e.ordered)return[];let r=e.start||1,i=e.typeMarker,o=e.items?(n=e.items,n.map(e=>{if("list_item"!==e.type)return t.parseChildren([e])[0];let n=[];return e.tokens&&e.tokens.length>0&&e.tokens.forEach(e=>{if("paragraph"===e.type||"list"===e.type||"blockquote"===e.type||"code"===e.type)n.push(...t.parseChildren([e]));else if("text"===e.type&&e.tokens){let r=t.parseChildren([e]);n.push({type:"paragraph",content:r})}else{let r=t.parseChildren([e]);r.length>0&&n.push(...r)}}),{type:"listItem",content:n}})):[],s={};return(1!==r&&(s.start=r),i&&(s.type=i),Object.keys(s).length>0)?{type:"orderedList",attrs:s,content:o}:{type:"orderedList",content:o}},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,"\n"):"",markdownTokenizer:{name:"orderedList",level:"block",start:()=>-1,tokenize:(e,t,n)=>{var r,i;let o=e.split("\n"),[s,a]=function(e){let t=[],n=0,r=0;for(;n<e.length;){let i=e[n],o=i.match(nB);if(!o)break;let[,s,a,l,d]=o,c=s.length,h=parseInt(a,10),u=isNaN(h)?nj(a):void 0,p=isNaN(h)?nO(a):h,f=[d],g=n+1,m=[i],y=!1;for(;g<e.length;){let t=e[g];if(t.match(nB))break;if(""===t.trim())m.push(t),f.push(""),y=!0,g+=1;else if(t.match(nH)){let e=t.length-t.trimStart().length,n=c+a.length+1;m.push(t),f.push(t.slice(Math.min(e,n))),g+=1}else{if(y||function(e){return Object.values(nU).some(t=>t.test(e))}(t))break;m.push(t),f.push(t),g+=1}}t.push({indent:c,number:p,type:u,content:f.join("\n").trim(),contentLines:f,raw:m.join("\n")}),r=g,n=g}return[t,r]}(o);if(0===s.length)return;let l=function e(t,n,r){let i=[],o=0;for(;o<t.length;){let s=t[o];if(s.indent===n){let{paragraphLines:a,blockLines:l}=function(e){let t=[],n=[],r=!1;return e.forEach(e=>{let i;if(r)return void n.push(e);if(""===e.trim()||t.length>0&&(i=e.trimStart(),nU.bulletItem.test(i)||nB.test(i.trimStart())||nU.heading.test(i)||nU.thematicBreak.test(i)&&!i.startsWith("-")||/^>\s?/.test(i)||nU.codeFence.test(i)||nU.blockMath.test(i))){r=!0,n.push(e);return}t.push(e)}),{paragraphLines:t,blockLines:n}}(s.contentLines),d=a.join("\n").trim(),c=[];d&&c.push({type:"paragraph",raw:d,tokens:r.inlineTokens(d)});let h=l.join("\n").trim();if(h){let e=r.blockTokens(h);c.push(...e)}let u=o+1,p=[];for(;u<t.length&&t[u].indent>n;)p.push(t[u]),u+=1;if(p.length>0){let t=e(p,Math.min(...p.map(e=>e.indent)),r);c.push({type:"list",ordered:!0,start:p[0].number,typeMarker:p[0].type,items:t,raw:p.map(e=>e.raw).join("\n")})}i.push({type:"list_item",raw:s.raw,tokens:c}),o=u}else o+=1}return i}(s,s[0].indent,n);if(0!==l.length)return{type:"list",ordered:!0,start:(null==(r=s[0])?void 0:r.number)||1,typeMarker:null==(i=s[0])?void 0:i.type,items:l,raw:o.slice(0,a).join("\n")}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes("listItem",this.editor.getAttributes(nW)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addProseMirrorPlugins:()=>[new eC.k_({props:{handlePaste:(e,t)=>{var n,r;let i=null==(n=t.clipboardData)?void 0:n.getData("text/html");if(null==i?void 0:i.trim())return!1;let o=null==(r=t.clipboardData)?void 0:r.getData("text/plain");if(!o)return!1;let s=function(e){let t=e.split("\n").filter(e=>e.trim().length>0);if(0===t.length)return null;let n=[];for(let e of t){let t=e.trim().match(nK);if(!t)return null;n.push({marker:t[1],content:t[3]})}return!function(e){var t;if(0===e.length)return!1;let n=null!=(t=nj(e[0]))?t:"numeric",r=nO(e[0]);if(r<1)return!1;for(let t=0;t<e.length;t++){let i=function(e,t){if("numeric"===e)return String(t);switch(e){case"a":return nA(t);case"A":return nA(t).toUpperCase();case"i":return nI(t);case"I":return n_(t);default:return String(t)}}(n,r+t);if(e[t]!==i)return!1}return!0}(n.map(e=>e.marker))?null:{type:"orderedList",attrs:function(e){let{type:t,start:n}={type:nj(e),start:nO(e)},r={};return t&&(r.type=t),1!==n&&(r.start=n),r}(n[0].marker),content:n.map(e=>({type:"listItem",content:[{type:"paragraph",content:[{type:"text",text:e.content}]}]}))}}(o);if(!s)return!1;try{let t=e.state.schema.nodeFromJSON(s),n=e.state.tr.replaceSelectionWith(t);return e.dispatch(n),!0}catch{return!1}}}})],addInputRules(){let e=(e,t)=>(!t.attrs.type||"1"===t.attrs.type)&&t.childCount+t.attrs.start===+e[1],t=(0,eg.tG)({find:nV,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:e});return(this.options.keepMarks||this.options.keepAttributes)&&(t=(0,eg.tG)({find:nV,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(nW)}),joinPredicate:e,editor:this.editor})),[t]}}),nq=/^\s*(\[([( |x])?\])\s$/,nX=eg.bP.create({name:"taskItem",addOptions:()=>({nested:!1,HTMLAttributes:{},taskListTypeName:"taskList",a11y:void 0}),content(){return this.options.nested?"paragraph block*":"paragraph+"},defining:!0,addAttributes:()=>({checked:{default:!1,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute("data-checked");return""===t||"true"===t},renderHTML:e=>({"data-checked":e.checked})}}),parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51,contentElement:e=>{var t;return null!=(t=e.querySelector("div"))?t:e}}]},renderHTML({node:e,HTMLAttributes:t}){return["li",(0,eg.KV)(this.options.HTMLAttributes,t,{"data-type":this.name}),["label",["input",{type:"checkbox",checked:e.attrs.checked?"checked":null}],["span"]],["div",0]]},parseMarkdown:(e,t)=>{let n=[];if(e.tokens&&e.tokens.length>0?n.push(t.createNode("paragraph",{},t.parseInline(e.tokens))):e.text?n.push(t.createNode("paragraph",{},[t.createNode("text",{text:e.text})])):n.push(t.createNode("paragraph",{},[])),e.nestedTokens&&e.nestedTokens.length>0){let r=t.parseChildren(e.nestedTokens);n.push(...r)}return t.createNode("taskItem",{checked:e.checked||!1},n)},renderMarkdown:(e,t)=>{var n;let r=`- [${(null==(n=e.attrs)?void 0:n.checked)?"x":" "}] `;return(0,eg.kj)(e,t,r)},addExtensions(){return this.options.nested?[nk(this.name,[this.options.taskListTypeName])]:[]},addKeyboardShortcuts(){let e={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...e,Tab:()=>this.editor.commands.sinkListItem(this.name)}:e},addNodeView(){return({node:e,HTMLAttributes:t,getPos:n,editor:r})=>{let i=document.createElement("li"),o=document.createElement("label"),s=document.createElement("span"),a=document.createElement("input"),l=document.createElement("div");s.style.cssText="position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0";let d=e=>{var t,n,r;let i=(t=e.attrs.checked,(null==(n=this.options.a11y)||null==(r=n.checkboxLabel)?void 0:r.call(n,e,t))||`Task item checkbox for ${e.textContent||"empty task item"}`);a.setAttribute("aria-label",i),s.textContent=i};d(e),o.contentEditable="false",a.type="checkbox",a.addEventListener("mousedown",e=>e.preventDefault()),a.addEventListener("change",t=>{if(!r.isEditable&&!this.options.onReadOnlyChecked){a.checked=!a.checked;return}let{checked:i}=t.target;r.isEditable&&"function"==typeof n&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=n();if("number"!=typeof t)return!1;let r=e.doc.nodeAt(t);return e.setNodeMarkup(t,void 0,{...null==r?void 0:r.attrs,checked:i}),!0}).run(),r.isEditable||!this.options.onReadOnlyChecked||this.options.onReadOnlyChecked(e,i)||(a.checked=!a.checked)}),Object.entries(this.options.HTMLAttributes).forEach(([e,t])=>{i.setAttribute(e,t)}),i.dataset.checked=e.attrs.checked,a.checked=e.attrs.checked,o.append(a,s),i.append(o,l),Object.entries(t).forEach(([e,t])=>{i.setAttribute(e,t)});let c=new Set(Object.keys(t));return{dom:i,contentDOM:l,update:e=>{if(e.type!==this.type)return!1;i.dataset.checked=e.attrs.checked,a.checked=e.attrs.checked,d(e);let t=r.extensionManager.attributes,n=(0,eg.zU)(e,t),o=new Set(Object.keys(n)),s=this.options.HTMLAttributes;return c.forEach(e=>{o.has(e)||(e in s?i.setAttribute(e,s[e]):i.removeAttribute(e))}),Object.entries(n).forEach(([e,t])=>{null==t?e in s?i.setAttribute(e,s[e]):i.removeAttribute(e):i.setAttribute(e,t)}),c=o,!0}}}},addInputRules(){return[(0,eg.tG)({find:nq,type:this.type,getAttributes:e=>({checked:"x"===e[e.length-1]})})]}}),nJ=eg.bP.create({name:"taskList",addOptions:()=>({itemTypeName:"taskItem",HTMLAttributes:{}}),group:"block list",content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:e}){return["ul",(0,eg.KV)(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},parseMarkdown:(e,t)=>t.createNode("taskList",{},t.parseChildren(e.items||[])),renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,"\n"):"",markdownTokenizer:{name:"taskList",level:"block",start(e){var t;let n=null==(t=e.match(/^\s*[-+*]\s+\[([ xX])\]\s+/))?void 0:t.index;return void 0!==n?n:-1},tokenize(e,t,n){let r=e=>{let t=(0,eg.Dd)(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:"x"===e[3].toLowerCase()}),createToken:(e,t)=>({type:"taskItem",raw:"",mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(t){let r={type:"taskList",raw:t.raw,items:t.items},i=e.slice(t.raw.length);return i.trim()?[r,...n.blockTokens(i)]:[r]}return n.blockTokens(e)},i=(0,eg.Dd)(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:"x"===e[3].toLowerCase()}),createToken:(e,t)=>({type:"taskItem",raw:"",mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(i)return{type:"taskList",raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});eg.YY.create({name:"listKit",addExtensions(){let e=[];return!1!==this.options.bulletList&&e.push(nC.configure(this.options.bulletList)),!1!==this.options.listItem&&e.push(nD.configure(this.options.listItem)),!1!==this.options.listKeymap&&e.push(n$.configure(this.options.listKeymap)),!1!==this.options.orderedList&&e.push(nG.configure(this.options.orderedList)),!1!==this.options.taskItem&&e.push(nX.configure(this.options.taskItem)),!1!==this.options.taskList&&e.push(nJ.configure(this.options.taskList)),e}});let nZ="&nbsp;",nQ=eg.bP.create({name:"paragraph",priority:1e3,addOptions:()=>({HTMLAttributes:{}}),group:"block",content:"inline*",parseHTML:()=>[{tag:"p"}],renderHTML({HTMLAttributes:e}){return["p",(0,eg.KV)(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{let n=e.tokens||[];if(1===n.length&&"image"===n[0].type)return t.parseChildren([n[0]]);let r=t.parseInline(n);return 1===n.length&&"text"===n[0].type&&(n[0].raw===nZ||n[0].text===nZ||"\xa0"===n[0].raw||"\xa0"===n[0].text)&&1===r.length&&"text"===r[0].type&&(r[0].text===nZ||"\xa0"===r[0].text)?t.createNode("paragraph",void 0,[]):t.createNode("paragraph",void 0,r)},renderMarkdown:(e,t,n)=>{if(!e)return"";let r=Array.isArray(e.content)?e.content:[];if(0===r.length){var i,o;let e=Array.isArray(null==n||null==(i=n.previousNode)?void 0:i.content)?n.previousNode.content:[];return(null==n||null==(o=n.previousNode)?void 0:o.type)==="paragraph"&&0===e.length?nZ:""}return t.renderChildren(r)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),n0=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,n1=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,n2=eg.CU.create({name:"strike",addOptions:()=>({HTMLAttributes:{}}),parseHTML:()=>[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:e=>!!e.includes("line-through")&&{}}],renderHTML({HTMLAttributes:e}){return["s",(0,eg.KV)(this.options.HTMLAttributes,e),0]},markdownTokenName:"del",parseMarkdown:(e,t)=>t.applyMark("strike",t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`~~${t.renderChildren(e)}~~`,addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[(0,eg.OX)({find:n0,type:this.type})]},addPasteRules(){return[(0,eg.Zc)({find:n1,type:this.type})]}}),n3=eg.bP.create({name:"text",group:"inline",parseMarkdown:e=>({type:"text",text:e.text||""}),renderMarkdown:e=>e.text||""}),n5=eg.CU.create({name:"underline",addOptions:()=>({HTMLAttributes:{}}),parseHTML:()=>[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:e=>!!e.includes("underline")&&{}}],renderHTML({HTMLAttributes:e}){return["u",(0,eg.KV)(this.options.HTMLAttributes,e),0]},parseMarkdown(e,t){return t.applyMark(this.name||"underline",t.parseInline(e.tokens||[]))},renderMarkdown:(e,t)=>`++${t.renderChildren(e)}++`,markdownTokenizer:{name:"underline",level:"inline",start:e=>e.indexOf("++"),tokenize(e,t,n){let r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(e);if(!r)return;let i=r[2].trim();return{type:"underline",raw:r[0],text:i,tokens:n.inlineTokens(i)}}},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}});var n6=n(8242);class n4{constructor(e,t){var n;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.lastDragEvent=null,this.width=null!=(n=t.width)?n:1,this.color=!1===t.color?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){if(null!=this.cursorPos&&t.doc!=e.state.doc)if(this.lastDragEvent){let e=this.computeTarget(this.lastDragEvent);e==this.cursorPos?this.updateOverlay():this.setCursor(e)}else this.updateOverlay()}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,null==e?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e,t,n=this.editorView.state.doc.resolve(this.cursorPos),r=!n.parent.inlineContent,i,o=this.editorView.dom,s=o.getBoundingClientRect(),a=s.width/o.offsetWidth,l=s.height/o.offsetHeight;if(r){let e=n.nodeBefore,t=n.nodeAfter;if(e||t){let n=this.editorView.nodeDOM(this.cursorPos-(e?e.nodeSize:0));if(n){let r=n.getBoundingClientRect(),o=e?r.bottom:r.top;e&&t&&(o=(o+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let s=this.width/2*l;i={left:r.left,right:r.right,top:o-s,bottom:o+s}}}}if(!i){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*a;i={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let d=this.editorView.dom.offsetParent;if(!this.element&&(this.element=d.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",r),this.element.classList.toggle("prosemirror-dropcursor-inline",!r),d&&(d!=document.body||"static"!=getComputedStyle(d).position)){let n=d.getBoundingClientRect(),r=n.width/d.offsetWidth,i=n.height/d.offsetHeight;e=n.left-d.scrollLeft*r,t=n.top-d.scrollTop*i}else e=-pageXOffset,t=-pageYOffset;this.element.style.left=(i.left-e)/a+"px",this.element.style.top=(i.top-t)/l+"px",this.element.style.width=(i.right-i.left)/a+"px",this.element.style.height=(i.bottom-i.top)/l+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}computeTarget(e){let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i="function"==typeof r?r(this.editorView,t,e):r;if(!t||i)return null;let o=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let e=(0,n6.Um)(this.editorView.state.doc,o,this.editorView.dragging.slice);null!=e&&(o=e)}return o}dragover(e){if(!this.editorView.editable)return;this.lastDragEvent=e;let t=this.computeTarget(e);null!=t&&(this.setCursor(t),this.scheduleRemoval(5e3))}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}var n8=n(63197),n9=n(12894);class n7 extends eC.LN{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return n7.valid(n)?new n7(n):eC.LN.near(n)}content(){return eS.Ji.empty}eq(e){return e instanceof n7&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if("number"!=typeof t.pos)throw RangeError("Invalid input for GapCursor.fromJSON");return new n7(e.resolve(t.pos))}getBookmark(){return new re(this.anchor)}static valid(e){let t=e.parent;if(t.inlineContent||!function(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(0==n){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n-1);;e=e.lastChild){if(0==e.childCount&&!e.inlineContent||rt(e.type))return!0;if(e.inlineContent)return!1}}return!0}(e)||!function(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n);;e=e.firstChild){if(0==e.childCount&&!e.inlineContent||rt(e.type))return!0;if(e.inlineContent)return!1}}return!0}(e))return!1;let n=t.type.spec.allowGapCursor;if(null!=n)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(e,t,n=!1){n:for(;;){if(!n&&n7.valid(e))return e;let r=e.pos,i=null;for(let n=e.depth;;n--){let o=e.node(n);if(t>0?e.indexAfter(n)<o.childCount:e.index(n)>0){i=o.child(t>0?e.indexAfter(n):e.index(n)-1);break}if(0==n)return null;r+=t;let s=e.doc.resolve(r);if(n7.valid(s))return s}for(;;){let o=t>0?i.firstChild:i.lastChild;if(!o){if(i.isAtom&&!i.isText&&!eC.nh.isSelectable(i)){e=e.doc.resolve(r+i.nodeSize*t),n=!1;continue n}break}i=o,r+=t;let s=e.doc.resolve(r);if(n7.valid(s))return s}return null}}}n7.prototype.visible=!1,n7.findFrom=n7.findGapCursorFrom,eC.LN.jsonID("gapcursor",n7);class re{constructor(e){this.pos=e}map(e){return new re(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return n7.valid(t)?new n7(t):eC.LN.near(t)}}function rt(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}let rn=(0,n9.K)({ArrowLeft:rr("horiz",-1),ArrowRight:rr("horiz",1),ArrowUp:rr("vert",-1),ArrowDown:rr("vert",1)});function rr(e,t){let n="vert"==e?t>0?"down":"up":t>0?"right":"left";return function(e,r,i){let o=e.selection,s=t>0?o.$to:o.$from,a=o.empty;if(o instanceof eC.U3){if(!i.endOfTextblock(n)||0==s.depth)return!1;a=!1,s=e.doc.resolve(t>0?s.after():s.before())}let l=n7.findGapCursorFrom(s,t,a);return!!l&&(r&&r(e.tr.setSelection(new n7(l))),!0)}}function ri(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!n7.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return!(i&&i.inside>-1&&eC.nh.isSelectable(e.state.doc.nodeAt(i.inside)))&&(e.dispatch(e.state.tr.setSelection(new n7(r))),!0)}function ro(e,t){if("insertCompositionText"!=t.inputType||!(e.state.selection instanceof n7))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=eS.FK.empty;for(let e=r.length-1;e>=0;e--)i=eS.FK.from(r[e].createAndFill(null,i));let o=e.state.tr.replace(n.pos,n.pos,new eS.Ji(i,0,0));return o.setSelection(eC.U3.near(o.doc.resolve(n.pos+1))),e.dispatch(o),!1}function rs(e){if(!(e.selection instanceof n7))return null;let t=document.createElement("div");return t.className="ProseMirror-gapcursor",n8.zF.create(e.doc,[n8.NZ.widget(e.selection.head,t,{key:"gapcursor"})])}var ra=function(){};ra.prototype.append=function(e){return e.length?(e=ra.from(e),!this.length&&e||e.length<200&&this.leafAppend(e)||this.length<200&&e.leafPrepend(this)||this.appendInner(e)):this},ra.prototype.prepend=function(e){return e.length?ra.from(e).append(this):this},ra.prototype.appendInner=function(e){return new rd(this,e)},ra.prototype.slice=function(e,t){return(void 0===e&&(e=0),void 0===t&&(t=this.length),e>=t)?ra.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},ra.prototype.get=function(e){if(!(e<0)&&!(e>=this.length))return this.getInner(e)},ra.prototype.forEach=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},ra.prototype.map=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},ra.from=function(e){return e instanceof ra?e:e&&e.length?new rl(e):ra.empty};var rl=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return 0==e&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i<n;i++)if(!1===e(this.values[i],r+i))return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){for(var i=t-1;i>=n;i--)if(!1===e(this.values[i],r+i))return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=200)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=200)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(ra);ra.empty=new rl([]);var rd=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return e<this.left.length?this.left.get(e):this.right.get(e-this.left.length)},t.prototype.forEachInner=function(e,t,n,r){var i=this.left.length;if(t<i&&!1===this.left.forEachInner(e,t,Math.min(n,i),r)||n>i&&!1===this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i))return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&!1===this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)||n<i&&!1===this.left.forEachInvertedInner(e,Math.min(t,i),n,r))return!1},t.prototype.sliceInner=function(e,t){if(0==e&&t==this.length)return this;var n=this.left.length;return t<=n?this.left.slice(e,t):e>=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(ra);class rc{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){let n,r,i,o;if(0==this.eventCount)return null;let s=this.items.length;for(;;s--)if(this.items.get(s-1).selection){--s;break}t&&(r=(n=this.remapping(s,this.items.length)).maps.length);let a=e.tr,l=[],d=[];return this.items.forEach((e,t)=>{if(!e.step){n||(r=(n=this.remapping(s,t+1)).maps.length),r--,d.push(e);return}if(n){d.push(new rh(e.map));let t=e.step.map(n.slice(r)),i;t&&a.maybeStep(t).doc&&(i=a.mapping.maps[a.mapping.maps.length-1],l.push(new rh(i,void 0,void 0,l.length+d.length))),r--,i&&n.appendMap(i,r)}else a.maybeStep(e.step);if(e.selection)return i=n?e.selection.map(n.slice(r)):e.selection,o=new rc(this.items.slice(0,s).append(d.reverse().concat(l)),this.eventCount-1),!1},this.items.length,0),{remaining:o,transform:a,selection:i}}addTransform(e,t,n,r){var i,o;let s,a=[],l=this.eventCount,d=this.items,c=!r&&d.length?d.get(d.length-1):null;for(let n=0;n<e.steps.length;n++){let i=e.steps[n].invert(e.docs[n]),o=new rh(e.mapping.maps[n],i,t),s;(s=c&&c.merge(o))&&(o=s,n?a.pop():d=d.slice(0,d.length-1)),a.push(o),t&&(l++,t=void 0),r||(c=o)}let h=l-n.depth;return h>rp&&(i=d,o=h,i.forEach((e,t)=>{if(e.selection&&0==o--)return s=t,!1}),d=i.slice(s),l-=h),new rc(d.append(a),l)}remapping(e,t){let n=new n6.X9;return this.items.forEach((t,r)=>{let i=null!=t.mirrorOffset&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(e){return 0==this.eventCount?this:new rc(this.items.append(e.map(e=>new rh(e))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],r=Math.max(0,this.items.length-t),i=e.mapping,o=e.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},r);let a=t;this.items.forEach(t=>{let r=i.getMirror(--a);if(null==r)return;o=Math.min(o,r);let l=i.maps[r];if(t.step){let o=e.steps[r].invert(e.docs[r]),d=t.selection&&t.selection.map(i.slice(a+1,r));d&&s++,n.push(new rh(l,o,d))}else n.push(new rh(l))},r);let l=[];for(let e=t;e<o;e++)l.push(new rh(i.maps[e]));let d=new rc(this.items.slice(0,r).append(l).append(n),s);return d.emptyItemCount()>500&&(d=d.compress(this.items.length-n.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{!t.step&&e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,r=[],i=0;return this.items.forEach((o,s)=>{if(s>=e)r.push(o),o.selection&&i++;else if(o.step){let e=o.step.map(t.slice(n)),s=e&&e.getMap();if(n--,s&&t.appendMap(s,n),e){let a=o.selection&&o.selection.map(t.slice(n));a&&i++;let l=new rh(s.invert(),e,a),d,c=r.length-1;(d=r.length&&r[c].merge(l))?r[c]=d:r.push(l)}}else o.map&&n--},this.items.length,0),new rc(ra.from(r.reverse()),i)}}rc.empty=new rc(ra.empty,0);class rh{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new rh(t.getMap().invert(),t,this.selection)}}}class ru{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}}let rp=20;function rf(e){let t=[];for(let n=e.length-1;n>=0&&0==t.length;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function rg(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let i=t.map(e[r],1),o=t.map(e[r+1],-1);i<=o&&n.push(i,o)}return n}let rm=!1,ry=null;function rb(e){let t=e.plugins;if(ry!=t){rm=!1,ry=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){rm=!0;break}}return rm}let rx=new eC.hs("history"),rw=new eC.hs("closeHistory");function rv(e,t){return(n,r)=>{let i=rx.getState(n);if(!i||0==(e?i.undone:i.done).eventCount)return!1;if(r){let o=function(e,t,n){let r=rb(t),i=rx.get(t).spec.config,o=(n?e.undone:e.done).popEvent(t,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),a=(n?e.done:e.undone).addTransform(o.transform,t.selection.getBookmark(),i,r),l=new ru(n?a:o.remaining,n?o.remaining:a,null,0,-1);return o.transform.setSelection(s).setMeta(rx,{redo:n,historyState:l})}(i,n,e);o&&r(t?o.scrollIntoView():o)}return!0}}let rS=rv(!1,!0),rC=rv(!0,!0);rv(!1,!1),rv(!0,!1),eg.YY.create({name:"characterCount",addOptions:()=>({limit:null,autoTrim:!0,mode:"textSize",textCounter:e=>e.length,wordCounter:e=>e.split(" ").filter(e=>""!==e).length}),addStorage:()=>({characters:()=>0,words:()=>0}),onBeforeCreate(){this.storage.characters=e=>{let t=(null==e?void 0:e.node)||this.editor.state.doc;if("textSize"===((null==e?void 0:e.mode)||this.options.mode)){let e=t.textBetween(0,t.content.size,void 0," ");return this.options.textCounter(e)}return t.nodeSize},this.storage.words=e=>{let t=(null==e?void 0:e.node)||this.editor.state.doc,n=t.textBetween(0,t.content.size," "," ");return this.options.wordCounter(n)}},addProseMirrorPlugins(){let e=!1;return[new eC.k_({key:new eC.hs("characterCount"),appendTransaction:(t,n,r)=>{if(e)return;let i=this.options.limit,o=this.options.autoTrim;if(null==i||0===i||!1===o){e=!0;return}let s=this.storage.characters({node:r.doc});if(s>i){console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);let t=r.tr.deleteRange(0,s-i);return e=!0,t}e=!0},filterTransaction:(e,t)=>{let n=this.options.limit;if(!e.docChanged||0===n||null==n)return!0;let r=this.storage.characters({node:t.doc}),i=this.storage.characters({node:e.doc});if(i<=n||r>n&&i>n&&i<=r)return!0;if(r>n&&i>n&&i>r||!e.getMeta("paste"))return!1;let o=e.selection.$head.pos;return e.deleteRange(o-(i-n),o),!(this.storage.characters({node:e.doc})>n)}})]}});let rk=eg.YY.create({name:"dropCursor",addOptions:()=>({color:"currentColor",width:1,class:void 0}),addProseMirrorPlugins(){return[function(e={}){return new eC.k_({view:t=>new n4(t,e)})}(this.options)]}});eg.YY.create({name:"focus",addOptions:()=>({className:"has-focus",mode:"all"}),addProseMirrorPlugins(){return[new eC.k_({key:new eC.hs("focus"),props:{decorations:({doc:e,selection:t})=>{let{isEditable:n,isFocused:r}=this.editor,{anchor:i}=t,o=[];if(!n||!r)return n8.zF.create(e,[]);let s=0;"deepest"===this.options.mode&&e.descendants((e,t)=>{if(!e.isText){if(!(i>=t&&i<=t+e.nodeSize-1))return!1;s+=1}});let a=0;return e.descendants((e,t)=>!e.isText&&!!(i>=t&&i<=t+e.nodeSize-1)&&((a+=1,"deepest"===this.options.mode&&s-a>0||"shallowest"===this.options.mode&&a>1)?"deepest"===this.options.mode:void o.push(n8.NZ.node(t,t+e.nodeSize,{class:this.options.className})))),n8.zF.create(e,o)}}})]}});let rP=eg.YY.create({name:"gapCursor",addProseMirrorPlugins:()=>[new eC.k_({props:{decorations:rs,createSelectionBetween:(e,t,n)=>t.pos==n.pos&&n7.valid(n)?new n7(n):null,handleClick:ri,handleKeyDown:rn,handleDOMEvents:{beforeinput:ro}}})],extendNodeSchema(e){var t;let n={name:e.name,options:e.options,storage:e.storage};return{allowGapCursor:null!=(t=(0,eg.gk)((0,eg.iI)(e,"allowGapCursor",n)))?t:null}}}),rT="placeholder",rE=new eC.hs("tiptap__placeholder");function rI(e){let{editor:t,placeholder:n,dataAttribute:r,pos:i,node:o,isEmptyDoc:s,hasAnchor:a,classes:{emptyNode:l,emptyEditor:d}}=e,c=[l];return s&&c.push(d),n8.NZ.node(i,i+o.nodeSize,{class:c.join(" "),[r]:"function"==typeof n?n({editor:t,node:o,pos:i,hasAnchor:a}):n})}function r_(e,t){return"function"==typeof e?e(t):e}function rM({editor:e,options:t,dataAttribute:n,doc:r,selection:i,from:o,to:s}){let{anchor:a}=i,l=[],d=e.isEmpty;return r.nodesBetween(o,s,(r,i)=>{let o=a>=i&&a<=i+r.nodeSize,s=!r.isLeaf&&(0,eg.Op)(r);return r.type.isTextblock&&(o||!t.showOnlyCurrent)&&s&&l.push(rI({editor:e,isEmptyDoc:d,dataAttribute:n,hasAnchor:o,placeholder:t.placeholder,classes:{emptyEditor:t.emptyEditorClass,emptyNode:r_(t.emptyNodeClass,{editor:e,node:r,pos:i,hasAnchor:o})},node:r,pos:i})),t.includeChildren}),l}function rA({editor:e,options:t,dataAttribute:n,doc:r,selection:i}){if(!(e.isEditable||!t.showOnlyWhenEditable))return null;let{anchor:o}=i,s=[],a=e.isEmpty;if(t.showOnlyCurrent&&!t.includeChildren){let i=r.resolve(o),l=i.depth>0?i.node(1):i.nodeAfter,d=i.depth>0?i.before(1):o;if(l&&l.type.isTextblock&&(0,eg.Op)(l)){let r=o>=d&&o<=d+l.nodeSize;s.push(rI({editor:e,isEmptyDoc:a,dataAttribute:n,hasAnchor:r,placeholder:t.placeholder,classes:{emptyEditor:t.emptyEditorClass,emptyNode:r_(t.emptyNodeClass,{editor:e,node:l,pos:d,hasAnchor:r})},node:l,pos:d}))}}else s.push(...rM({editor:e,options:t,dataAttribute:n,doc:r,selection:i,from:0,to:r.content.size}));return n8.zF.create(r,s)}function rj(e,t){let n=e.resolve(t);if(0===n.depth){var r;let e=null!=(r=n.nodeAfter)?r:n.nodeBefore;if(!e)return{from:t,to:t};let i=n.nodeAfter?t:t-e.nodeSize;return{from:i,to:i+e.nodeSize}}let i=n.before(1);return{from:i,to:i+n.node(1).nodeSize}}function rO(e,t){return{from:Math.max(0,t.from-1),to:Math.min(e.content.size,t.to-1)}}function rD(e,t){return!e.selection.empty&&!(0,eg.BQ)(e.selection)&&t.isEditable}function rL({types:e,node:t}){return t&&Array.isArray(e)&&e.includes(t.type)||(null==t?void 0:t.type)===e}eg.YY.create({name:"placeholder",addOptions:()=>({emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",dataAttribute:rT,placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}),addProseMirrorPlugins(){return[function({editor:e,options:t}){let n=t.dataAttribute?`data-${t.dataAttribute.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/^[0-9-]+/,"").replace(/^-+/,"").toLowerCase()}`:`data-${rT}`,r=t.showOnlyCurrent&&!t.includeChildren;return new eC.k_({key:rE,...r?{}:{state:function({editor:e,options:t,dataAttribute:n}){return{init(r,i){let o=rA({editor:e,options:t,dataAttribute:n,doc:i.doc,selection:i.selection});return null!=o?o:n8.zF.empty},apply:(r,i,o,s)=>r.docChanged||r.selectionSet?function({decorations:e,ranges:t,editor:n,options:r,dataAttribute:i,doc:o,selection:s}){let a=e;for(let e of t){let{from:t,to:l}=function(e,t,n){let r=Math.max(0,Math.min(e,n.content.size));return{from:r,to:Math.max(r,Math.min(t,n.content.size))}}(e.from,e.to,o),d=a.find(t,l).filter(e=>e.from>=t&&e.to<=l);d.length&&(a=a.remove(d));let c=rM({editor:n,options:r,dataAttribute:i,doc:o,selection:s,from:t,to:l});c.length&&(a=a.add(o,c))}return a}({decorations:i.map(r.mapping,r.doc),ranges:function(e,t,n){let r=[];if(e.docChanged)for(let t of(0,eg.FF)(e))r.push(...function(e,t){var n,r;let i,o=(n=t.from,r=t.to,i=[],e.forEach((e,t)=>{let o=t+e.nodeSize,s=o+1;t+1<r&&s>n&&i.push({from:t,to:o})}),i);return o.push(rO(e,rj(e,t.from))),t.to>t.from?o.push(rO(e,rj(e,Math.min(t.to,e.content.size+1)-1))):t.from<e.content.size+1&&o.push(rO(e,rj(e,Math.min(t.from+1,e.content.size)))),o}(n.doc,t.newRange));return e.selectionSet&&(r.push(rO(n.doc,rj(n.doc,e.mapping.map(t.selection.anchor)))),r.push(rO(n.doc,rj(n.doc,n.selection.anchor)))),function(e){if(0===e.length)return[];let t=[...e].sort((e,t)=>e.from-t.from),n=[{...t[0]}];for(let e=1;e<t.length;e+=1){let r=n[n.length-1],i=t[e];i.from<=r.to?r.to=Math.max(r.to,i.to):n.push({...i})}return n}(r)}(r,o,s),editor:e,options:t,dataAttribute:n,doc:s.doc,selection:s.selection}):i}}({editor:e,options:t,dataAttribute:n})},props:{decorations:r?({doc:r,selection:i})=>rA({editor:e,options:t,dataAttribute:n,doc:r,selection:i}):n=>{var r;return t.showOnlyWhenEditable&&!e.isEditable?n8.zF.empty:null!=(r=rE.getState(n))?r:n8.zF.empty}}})}({editor:this.editor,options:this.options})]}}),eg.YY.create({name:"selection",addOptions:()=>({className:"selection"}),addProseMirrorPlugins(){let{editor:e,options:t}=this;return[new eC.k_({key:new eC.hs("selection"),props:{decorations:n=>!rD(n,e)||e.isFocused||e.view.dragging?null:n8.zF.create(n.doc,[n8.NZ.inline(n.selection.from,n.selection.to,{class:t.className})]),handleDOMEvents:{blur(t){var n;return!!rD(t.state,e)&&(null==(n=window.getSelection())||n.removeAllRanges(),!1)},focus:t=>!!rD(t.state,e)&&(requestAnimationFrame(()=>{!e.isDestroyed&&t.hasFocus()&&t.focus()}),!1)}}})]}});let rR=eg.YY.create({name:"trailingNode",addOptions:()=>({node:void 0,notAfter:[]}),addProseMirrorPlugins(){var e;let t=new eC.hs(this.name),n=this.options.node||(null==(e=this.editor.schema.topNodeType.contentMatch.defaultType)?void 0:e.name)||"paragraph",r=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>(this.options.notAfter||[]).concat(n).includes(e.name));return[new eC.k_({key:t,appendTransaction:(e,r,i)=>{let{doc:o,tr:s,schema:a}=i,l=t.getState(i),d=o.content.size,c=a.nodes[n];if(!e.some(e=>e.getMeta("skipTrailingNode"))&&l)return s.insert(d,c.create())},state:{init:(e,t)=>!rL({node:t.tr.doc.lastChild,types:r}),apply:(e,t)=>!e.docChanged||e.getMeta("__uniqueIDTransaction")?t:!rL({node:e.doc.lastChild,types:r})}})]}}),rF=eg.YY.create({name:"undoRedo",addOptions:()=>({depth:100,newGroupDelay:500}),addCommands:()=>({undo:()=>({state:e,dispatch:t})=>rS(e,t),redo:()=>({state:e,dispatch:t})=>rC(e,t)}),addProseMirrorPlugins(){return[function(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new eC.k_({key:rx,state:{init:()=>new ru(rc.empty,rc.empty,null,0,-1),apply:(t,n,r)=>(function(e,t,n,r){let i=n.getMeta(rx),o;if(i)return i.historyState;n.getMeta(rw)&&(e=new ru(e.done,e.undone,null,0,-1));let s=n.getMeta("appendedTransaction");if(0==n.steps.length)return e;if(s&&s.getMeta(rx))if(s.getMeta(rx).redo)return new ru(e.done.addTransform(n,void 0,r,rb(t)),e.undone,rf(n.mapping.maps),e.prevTime,e.prevComposition);else return new ru(e.done,e.undone.addTransform(n,void 0,r,rb(t)),null,e.prevTime,e.prevComposition);if(!1===n.getMeta("addToHistory")||s&&!1===s.getMeta("addToHistory"))if(o=n.getMeta("rebased"))return new ru(e.done.rebased(n,o),e.undone.rebased(n,o),rg(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);else return new ru(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),rg(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);{let i=n.getMeta("composition"),o=0==e.prevTime||!s&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!function(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i<t.length;i+=2)e<=t[i+1]&&r>=t[i]&&(n=!0)}),n}(n,e.prevRanges)),a=s?rg(e.prevRanges,n.mapping):rf(n.mapping.maps);return new ru(e.done.addTransform(n,o?t.selection.getBookmark():void 0,r,rb(t)),rc.empty,a,n.time,null==i?e.prevComposition:i)}})(n,r,t,e)},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,r="historyUndo"==n?rS:"historyRedo"==n?rC:null;return!!r&&!!e.editable&&(t.preventDefault(),r(e.state,e.dispatch))}}}})}(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),rz=eg.YY.create({name:"starterKit",addExtensions(){var e,t,n,r;let i=[];return!1!==this.options.bold&&i.push(eL.configure(this.options.bold)),!1!==this.options.blockquote&&i.push(eM.configure(this.options.blockquote)),!1!==this.options.bulletList&&i.push(nC.configure(this.options.bulletList)),!1!==this.options.code&&i.push(eb.configure(this.options.code)),!1!==this.options.codeBlock&&i.push(ez.configure(this.options.codeBlock)),!1!==this.options.document&&i.push(eN.configure(this.options.document)),!1!==this.options.dropcursor&&i.push(rk.configure(this.options.dropcursor)),!1!==this.options.gapcursor&&i.push(rP.configure(this.options.gapcursor)),!1!==this.options.hardBreak&&i.push(e$.configure(this.options.hardBreak)),!1!==this.options.heading&&i.push(eB.configure(this.options.heading)),!1!==this.options.undoRedo&&i.push(rF.configure(this.options.undoRedo)),!1!==this.options.horizontalRule&&i.push(eH.configure(this.options.horizontalRule)),!1!==this.options.italic&&i.push(eY.configure(this.options.italic)),!1!==this.options.listItem&&i.push(nD.configure(this.options.listItem)),!1!==this.options.listKeymap&&i.push(n$.configure(null==(e=this.options)?void 0:e.listKeymap)),!1!==this.options.link&&i.push(nw.configure(null==(t=this.options)?void 0:t.link)),!1!==this.options.orderedList&&i.push(nG.configure(this.options.orderedList)),!1!==this.options.paragraph&&i.push(nQ.configure(this.options.paragraph)),!1!==this.options.strike&&i.push(n2.configure(this.options.strike)),!1!==this.options.text&&i.push(n3.configure(this.options.text)),!1!==this.options.underline&&i.push(n5.configure(null==(n=this.options)?void 0:n.underline)),!1!==this.options.trailingNode&&i.push(rR.configure(null==(r=this.options)?void 0:r.trailingNode)),i}}),rN={tldraw_draw:{normal:{normal:{family:"tldraw_draw",src:{url:"tldraw_draw",format:"woff2"},weight:"normal"},bold:{family:"tldraw_draw",src:{url:"tldraw_draw_bold",format:"woff2"},weight:"bold"}},italic:{normal:{family:"tldraw_draw",src:{url:"tldraw_draw_italic",format:"woff2"},weight:"normal",style:"italic"},bold:{family:"tldraw_draw",src:{url:"tldraw_draw_italic_bold",format:"woff2"},weight:"bold",style:"italic"}}},tldraw_sans:{normal:{normal:{family:"tldraw_sans",src:{url:"tldraw_sans",format:"woff2"},weight:"normal",style:"normal"},bold:{family:"tldraw_sans",src:{url:"tldraw_sans_bold",format:"woff2"},weight:"bold",style:"normal"}},italic:{normal:{family:"tldraw_sans",src:{url:"tldraw_sans_italic",format:"woff2"},weight:"normal",style:"italic"},bold:{family:"tldraw_sans",src:{url:"tldraw_sans_italic_bold",format:"woff2"},weight:"bold",style:"italic"}}},tldraw_serif:{normal:{normal:{family:"tldraw_serif",src:{url:"tldraw_serif",format:"woff2"},weight:"normal",style:"normal"},bold:{family:"tldraw_serif",src:{url:"tldraw_serif_bold",format:"woff2"},weight:"bold",style:"normal"}},italic:{normal:{family:"tldraw_serif",src:{url:"tldraw_serif_italic",format:"woff2"},weight:"normal",style:"italic"},bold:{family:"tldraw_serif",src:{url:"tldraw_serif_italic_bold",format:"woff2"},weight:"bold",style:"italic"}}},tldraw_mono:{normal:{normal:{family:"tldraw_mono",src:{url:"tldraw_mono",format:"woff2"},weight:"normal",style:"normal"},bold:{family:"tldraw_mono",src:{url:"tldraw_mono_bold",format:"woff2"},weight:"bold",style:"normal"}},italic:{normal:{family:"tldraw_mono",src:{url:"tldraw_mono_italic",format:"woff2"},weight:"normal",style:"italic"},bold:{family:"tldraw_mono",src:{url:"tldraw_mono_italic_bold",format:"woff2"},weight:"bold",style:"italic"}}}},r$=(0,r.Ics)(rN).flatMap(e=>(0,r.Ics)(e).flatMap(e=>Object.values(e)));function rB(e,t){if(`tldraw_${t}`in rN)return;let n=e.fonts[t];return n?.faces??r.Mlv}let rH=eg.YY.create({name:"keyboardShiftEnterHandler",addKeyboardShortcuts:()=>({"Shift-Enter":({editor:e})=>e.commands.enter()})});eb.config.excludes=void 0,ev.config.priority=1100;let rU=[rz.configure({blockquote:!1,codeBlock:!1,horizontalRule:!1,link:{openOnClick:!1,autolink:!0},trailingNode:{notAfter:["paragraph","bulletList","orderedList","listItem"]},...void 0}),ev,rH,eg.XO.TextDirection.configure({direction:"auto"})],rK=new r.laH;function rW(e,t){return rK.get(t,()=>{let n=e.getTextOptions().tipTapConfig?.extensions??rU;return(0,eg.Zx)(t,n).replace(/<p([^>]*)><\/p>/g,"<p$1><br /></p>")})}function rV(e,t){let n=rW(e,t);return`<div class="tl-rich-text">${n}</div>`}let rY=new r.laH;function rG(e){if(0===e.content.length)return!0;if(1===e.content.length){let t=e.content[0];if(!t.content||0===t.content.length)return!0}return!1}function rq(e){let t=e.getRichTextEditor();return!!(t?.isActive("bulletList")||t?.isActive("orderedList"))}function rX(e,t){return rG(t)?"":rY.get(t,()=>{let n=e.getTextOptions().tipTapConfig?.extensions??rU;return(0,eg.Df)(t,n,{blockSeparator:"\n"})})}function rJ(e,t,n){for(let n of e.marks)"bold"===n.type.name&&"bold"!==t.weight&&(t={...t,weight:"bold"}),"italic"===n.type.name&&"italic"!==t.style&&(t={...t,style:"italic"}),"code"===n.type.name&&"tldraw_mono"!==t.family&&(t={...t,family:"tldraw_mono"});let i=(0,r.g50)(rN,t.family);if(!i)return t;let o=(0,r.g50)(i,t.style);if(!o)return t;let s=(0,r.g50)(o,t.weight);return s&&n(s),t}class rZ{static fixNewLines=/\r?\n|\r/g;static normalizeText(e){return e.replace(rZ.fixNewLines,"\n")}static normalizeTextForDom(e){return e.replace(rZ.fixNewLines,"\n").split("\n").map(e=>e||" ").join("\n")}}let rQ=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/,r0={"&amp;":"&","&quot;":'"',"&apos;":"'","&#27;":"'","&#34;":'"',"&#38;":"&","&#39;":"'","&#8211;":"–","&#8212;":"—","&#8216;":"‘","&#8217;":"’","&#8220;":"“","&#8221;":"”","&#8230;":"…"},r1=RegExp(Object.keys(r0).join("|"),"g");function r2(e){return e.replace(r1,e=>r0[e])}async function r3(e,{file:t,assetId:n},i){io(e,t,i)||(0,r.vAR)(!1,"File checks failed");let o=await ii(t);o||(0,r.vAR)(!1,"SVG file contained no safe content");let s=await is(e,o,n);s||(0,r.vAR)(!1,`No asset util found for MIME type "${t.type}"`);let a=await e.uploadAsset(s,o);return s.props.src=a.src,a.meta&&(s.meta={...s.meta,...a.meta}),r.Kx3.create(s)}async function r5(e,{file:t,shapeId:n},i){io(e,t,i)||(0,r.vAR)(!1,"File checks failed");let o=await ii(t);if(!o)return;let s=e.getShape(n);s||(0,r.vAR)(!1,"Shape not found");let a=(0,r.Gwq)(await o.arrayBuffer()),l=r.Kx3.createId(a);e.createTemporaryAssetPreview(l,o);let d=await is(e,o,l);if(!d)return;if(e.createAssets([d]),"image"===s.type){let t=s.props.crop,n=d.props.w,i=d.props.h,o=s.x,a=s.y,c=t;if(t){let e=function(e,t,n){let i=$(),o=e.props.crop||i,s=e.props.w,a=e.props.h,l=i,d=s,c=a;if((0,r.n4T)(e.props.crop,i))d=s,c=s*n/t;else{let r,i,{w:s,h:a}=U(e.props,e.props.crop||$()),{width:d,height:c}=K(o),h=d/c,u=W(o),p=t/n/(s/a)/h;if(i=(r=d)*p,p>1.5)if(1/i<1/r){let e=i/.3333333333333333;i/=e,r/=e}else{let e=r/.3333333333333333;r/=e,i/=e}r=Math.max(0,Math.min(1,r)),i=Math.max(0,Math.min(1,i)),l=V(u.x,u.y,r,i,o.isCircle)}let h=e.x+s/2,u=e.y+a/2,p=h-d/2,f=u-c/2;return{crop:l,w:d,h:c,x:p,y:f}}(s,d.props.w,d.props.h);c=e.crop,n=e.w,i=e.h,o=e.x,a=e.y}e.updateShapes([{id:s.id,type:s.type,props:{assetId:l,crop:c,w:n,h:i},x:o,y:a}])}else"video"===s.type&&e.updateShapes([{id:s.id,type:s.type,props:{assetId:l,w:d.props.w,h:d.props.h}}]);let c=await e.getAssetForExternalContent({type:"file",file:o,assetId:l});return e.updateAssets([{...c,id:l}]),c}async function r6(e,{url:t},{toasts:n,msg:i}){let o;try{let e=await (0,r.hdJ)(t,{method:"GET",mode:"no-cors"}),n=await e.text(),i=new DOMParser().parseFromString(n,"text/html");(o={image:i.head.querySelector('meta[property="og:image"]')?.getAttribute("content")??"",favicon:i.head.querySelector('link[rel="apple-touch-icon"]')?.getAttribute("href")??i.head.querySelector('link[rel="icon"]')?.getAttribute("href")??"",title:i.head.querySelector('meta[property="og:title"]')?.getAttribute("content")??t,description:i.head.querySelector('meta[property="og:description"]')?.getAttribute("content")??""}).image.startsWith("http")||(o.image=new URL(o.image,t).href),o.favicon.startsWith("http")||(o.favicon=new URL(o.favicon,t).href)}catch(e){console.error(e),n.addToast({title:i("assets.url.failed"),severity:"error"}),o={image:"",favicon:"",title:"",description:""}}return{id:r.Kx3.createId((0,r.xpx)(t)),typeName:"asset",type:"bookmark",props:{src:t,description:o.description,image:o.image,favicon:o.favicon,title:o.title},meta:{}}}async function r4(e,{point:t,text:r}){let{sanitizeSvg:i}=await Promise.resolve().then(n.bind(n,13248));if(!(r=i(r)))return;let o=t??(e.inputs.getShiftKey()?e.inputs.getCurrentPagePoint():e.getViewportPageBounds().center),s=new DOMParser().parseFromString(r,"image/svg+xml").querySelector("svg");if(!s)throw Error("No <svg/> element present");let a=parseFloat(s.getAttribute("width")||"0"),l=parseFloat(s.getAttribute("height")||"0");if(!(a&&l)){let t=e.getContainerDocument();t.body.appendChild(s);let n=s.getBoundingClientRect();t.body.removeChild(s),a=n.width,l=n.height}let d=await e.getAssetForExternalContent({type:"file",file:new File([r],"asset.svg",{type:"image/svg+xml"})});if(!d)throw Error("Could not create an asset");ir(e,[d],o)}async function r8(e,{point:t,files:n},i){let{toasts:o,msg:s}=i;if(n.length>e.options.maxFilesAtOnce)return void o.addToast({title:s("assets.files.amount-too-many"),severity:"error"});let a=t??(e.inputs.getShiftKey()?e.inputs.getCurrentPagePoint():e.getViewportPageBounds().center),l=new r.l2P(a.x,a.y),d=[],c=[];for(let t of n){if(!io(e,t,i))continue;let n=await ii(t);if(!n){o.addToast({title:s("assets.files.upload-failed"),severity:"error"});continue}let r=await is(e,n);r&&("image"===r.type&&e.createTemporaryAssetPreview(r.id,n),d.push(r),c.push({asset:r,file:n}))}Promise.allSettled(c.map(async t=>{try{let n=await e.getAssetForExternalContent({type:"file",file:t.file});if(!n)throw Error("Could not create an asset");e.updateAssets([{...n,id:t.asset.id}])}catch(n){o.addToast({title:s("assets.files.upload-failed"),severity:"error"}),console.error(n),e.deleteAssets([t.asset.id]);return}})),ir(e,d,l)}async function r9(e,{point:t,text:n,html:i}){let o,s,a,l,d=t??(e.inputs.getShiftKey()?e.inputs.getCurrentPagePoint():e.getViewportPageBounds().center),c=e.getShapeUtil("text").getDefaultProps(),h=(function(e){let t=e.split("\n");for(;t[0]&&0===t[0].trim().length;)t.shift();let n=1/0;for(let e of t)if(e.trim().length>0){let t=e.length-e.trimStart().length;n=Math.min(n,t)}return t.map(e=>e.slice(n)).join("\n")})(n.replace(/\t/g," ")).replace(/[ \t]+$/gm,"").replace(/\n+$/,""),u=i?(l=e.getTextOptions().tipTapConfig?.extensions??rU,(0,eg.yQ)(i,l)):(0,r.TP3)(h),p="middle",f=rV(e,u),g=u.content.length>1,m=rQ.test(h);g&&(p=g?m?"end":"start":"middle");let y=e.getCurrentTheme(),b=e.textMeasure.measureHtml(f,{...Y,lineHeight:y.lineHeight,fontFamily:Q(y,c.font),fontSize:y.fontSize*q[c.size],maxWidth:null}),x=Math.min(g?.9*e.getViewportPageBounds().width:920,Math.max(200,.9*e.getViewportPageBounds().width));if(b.w>x){let t=e.textMeasure.measureHtml(f,{...Y,lineHeight:y.lineHeight,fontFamily:Q(y,c.font),fontSize:y.fontSize*q[c.size],maxWidth:x});o=t.w,s=t.h,a=!1,p=m?"end":"start"}else o=Math.max(b.w,10),s=Math.max(b.h,10),a=!0;d.y-s/2<e.getViewportPageBounds().minY+40&&(d.y=e.getViewportPageBounds().minY+40+s/2);let w=(0,r.Y8F)(new r.l2P(d.x-o/2,d.y-s/2),e),v=(0,r.n6Y)();e.createShapes([{id:v,type:"text",x:w.x,y:w.y,props:{richText:u,textAlign:p,autoSize:a,w:o}}])}async function r7(e,{point:t,url:n},{toasts:i,msg:o}){if(!r.T.linkUrl.isValid(n)){console.warn(`Could not create a bookmark from an invalid url: ${JSON.stringify(n)}`),i.addToast({title:o("assets.url.failed"),severity:"error"});return}let s=e.getShapeUtil("embed"),a=s?.getEmbedDefinition(n);if(a&&!1!==a.definition.embedOnPaste)return e.putExternalContent({type:"embed",url:a.url,point:t,embed:a.definition});let l=t??(e.inputs.getShiftKey()?e.inputs.getCurrentPagePoint():e.getViewportPageBounds().center);if(!(await z(e,{url:n,center:l})).ok)return void i.addToast({title:o("assets.url.failed"),severity:"error"})}async function ie(e,{point:t,content:n}){e.run(()=>{let r=e.getSelectionPageBounds();for(let t of(e.markHistoryStoppingPoint("paste"),n.shapes))n.rootShapeIds.includes(t.id)&&(t.isLocked=!1);let i=e.isInAny("select.dragging_handle","select.translating","select.resizing","select.rotating");e.putContentOntoCurrentPage(n,{point:t,select:!i});let o=e.getSelectionPageBounds();!i&&r&&o&&r?.collides(o)&&(e.updateInstanceState({isChangingStyle:!0}),e.timers.setTimeout(()=>{e.updateInstanceState({isChangingStyle:!1})},150))})}async function it(e,{point:t,content:n}){e.run(()=>{ee(e,n,t)})}async function ir(e,t,n){if(!t.length)return[];let i=r.l2P.From(n),o=[];for(let n=0;n<t.length;n++){let r=t[n],s=e.getShapeUtilForAssetType(r.type),a=s?.createShapeForAsset?.(r,i)??null;a&&(o.push(a),"w"in r.props&&"number"==typeof r.props.w&&(i.x+=r.props.w))}return e.run(()=>{let i=t.filter(t=>!e.getAsset(t.id));e.store.atomic(()=>{e.canCreateShapes(o)&&(i.length&&e.createAssets(i),e.createShapes(o).select(...o.map(e=>e.id)),function(e,t){let n=e.getViewportPageBounds(),i=e.getSelectionPageBounds();if(i){let n=i.center.sub(t);e.updateShapes(e.getSelectedShapes().map(t=>{let i=e.getShapeParentTransform(t).decompose().rotation,o=r.l2P.Rot(n,-i);return{id:t.id,type:t.type,x:t.x-o.x,y:t.y-o.y}}))}if((i=e.getSelectionPageBounds())&&e.getInstanceState().isGridMode){let t=e.getDocumentSettings().gridSize,n=new r.l2P(i.minX,i.minY),o=n.clone().snapToGrid(t),s=r.l2P.Sub(n,o);e.updateShapes(e.getSelectedShapes().map(e=>{let t={x:e.x-s.x,y:e.y-s.y};return{id:e.id,type:e.type,x:t.x,y:t.y}}))}(i=e.getSelectionPageBounds())&&!n.contains(i)&&e.zoomToSelection({animation:{duration:e.options.animationMediumMs}})}(e,n))})}),o.map(e=>e.id)}async function ii(e){if("image/svg+xml"!==e.type)return e;try{let t=await e.text(),{sanitizeSvg:r}=await Promise.resolve().then(n.bind(n,13248)),i=r(t);if(!i)return null;return new File([i],e.name,{type:e.type,lastModified:e.lastModified})}catch{return null}}function io(e,t,n){let{maxAssetSize:r=0xa00000,acceptedImageMimeTypes:i,acceptedVideoMimeTypes:o,toasts:s,msg:a}=n;return e.getAssetUtilForMimeType(t.type)||i?.includes(t.type)||o?.includes(t.type)?t.size>r?(s.addToast({title:a("assets.files.size-too-big"),description:a("assets.files.maximum-size").replace("{size}",(e=>{if(0===e)return"0 bytes";let t=Math.floor(Math.log(e)/Math.log(1024)),n=e/Math.pow(1024,t),r=n%1==0?n.toString():n.toFixed(1);return`${r} ${["bytes","KB","MB","GB","TB","PB"][t]}`})(r)),severity:"error"}),!1):!!t.type||(s.addToast({title:a("assets.files.upload-failed"),severity:"error"}),console.error("No mime type"),!1):(s.addToast({title:a("assets.files.type-not-allowed"),severity:"error"}),!1)}async function is(e,t,n){if(!n){let e=(0,r.Gwq)(await t.arrayBuffer());n=r.Kx3.createId(e)}let i=e.getAssetUtilForMimeType(t.type);return i?await i.getAssetFromFile(t,n):null}async function ia(e,t,n){let i=n.name;if(!i&&(i=`shapes at ${il()}`,1===t.length)){let n=e.getShape(t[0]);i=e.isShapeOfType(n,"frame")?n.props.name||"frame":`${(0,r.ni0)(n.id)} at ${il()}`}i+=`.${n.format}`;let{blob:o}=await e.toImage(t,n);id(new File([o],i,{type:o.type}),e.getContainerDocument())}function il(){let e=new Date,t=String(e.getFullYear()).slice(2),n=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0"),i=String(e.getHours()).padStart(2,"0"),o=String(e.getMinutes()).padStart(2,"0"),s=String(e.getSeconds()).padStart(2,"0");return`${t}-${n}-${r} ${i}.${o}.${s}`}function id(e,t){let n=(t??(0,r.jLo)()).createElement("a"),i=URL.createObjectURL(e);n.href=i,n.download=e.name,n.click(),URL.revokeObjectURL(i)}function ic(e,t){let n=(0,r.oE7)(t.map(t=>e.getShape(t)).filter(t=>t&&e.isShapeFrameLike(t)));if(!n.length)return;let i=[];e.run(()=>{n.map(t=>{let o=e.getSortedChildIdsForParent(t.id);o.length&&((0,r.IeP)(e,o,{filter:e=>!n.find(t=>t.id===e.id)}),i.push(...o))}),e.setSelectedShapes(i),e.deleteShapes(t)})}function ih(e,t,n={padding:50}){let i=r.azJ.FromPoints(e.flatMap(e=>{if(!e)return[];let n=t.getShapeGeometry(e.id),r=t.getShapeLocalTransform(e);return r?.applyToPoints(n.vertices)??[]})),o=n.padding??50,s=i.w+2*o,a=i.h+2*o;return{w:s,h:a,dx:o-i.minX,dy:o-i.minY}}function iu(e,t,n={}){let i=e.getShape(t);if(!i||!e.isShapeFrameLike(i))return;let o=e.getSortedChildIdsForParent(i.id),s=(0,r.oE7)(o.map(t=>e.getShape(t)));if(!s.length)return;let{w:a,h:l,dx:d,dy:c}=ih(s,e,n);if(0===d&&0===c&&i.props.w===a&&i.props.h===l)return;let h=new r.l2P(d,c).rot(i.rotation);e.run(()=>{let t=o.map(t=>{let n=e.getShape(t);return{id:n.id,type:n.type,x:n.x+d,y:n.y+c}});t.push({id:i.id,type:i.type,x:i.x-h.x,y:i.y-h.y,props:{w:a,h:l}}),e.updateShapes(t)})}var ip=n(69730),ig=n(70379),im=n(47527),iy=n(68599),ib=n(19416),ix=n(89971),iw=n(80878),iv=n(83935),iS=n(55897),iC=n(42442),ik=n(54498),iP=n(66294),iT=Object.defineProperty,iE=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),iI=f.forwardRef(iT(function(e,t){return(0,d.jsx)(iS.sG.span,{...e,ref:t,style:{...iE,...e.style}})},"name",{value:"VisuallyHidden",configurable:!0})),i_=Object.defineProperty,iM=(e,t)=>i_(e,"name",{value:t,configurable:!0}),[iA,ij]=(0,iy.A)("Tooltip",[iw.Bk]),iO=(0,iw.Bk)(),iD="tooltip.open",[iL,iR]=iA("TooltipProvider"),iF=iM(e=>{let{__scopeTooltip:t,delayDuration:n=700,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:o}=e,s=f.useRef(!0),a=f.useRef(!1),l=f.useRef(0);return f.useEffect(()=>{let e=l.current;return()=>window.clearTimeout(e)},[]),(0,d.jsx)(iL,{scope:t,isOpenDelayedRef:s,delayDuration:n,onOpen:f.useCallback(()=>{r<=0||(window.clearTimeout(l.current),s.current=!1)},[r]),onClose:f.useCallback(()=>{r<=0||(window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.current=!0,r))},[r]),isPointerInTransitRef:a,onPointerInTransitChange:f.useCallback(e=>{a.current=e},[]),disableHoverableContent:i,children:o})},"TooltipProvider"),iz="Tooltip",[iN,i$]=iA(iz),iB=iM(e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:o,disableHoverableContent:s,delayDuration:a}=e,l=iR(iz,e.__scopeTooltip),c=iO(t),[h,u]=f.useState(null),[p,g]=f.useState(void 0),m=(0,ix.B)(),y=f.useRef(0),b=s??l.disableHoverableContent,x=a??l.delayDuration,w=f.useRef(!1),[v,S]=(0,ik.i)({prop:r,defaultProp:i??!1,onChange:iM(e=>{e?(l.onOpen(),document.dispatchEvent(new CustomEvent(iD))):l.onClose(),o?.(e)},"onChange"),caller:iz}),C=f.useMemo(()=>v?w.current?"delayed-open":"instant-open":"closed",[v]),k=f.useCallback(()=>{window.clearTimeout(y.current),y.current=0,w.current=!1,S(!0)},[S]),P=f.useCallback(()=>{window.clearTimeout(y.current),y.current=0,S(!1)},[S]),T=f.useCallback(()=>{window.clearTimeout(y.current),y.current=window.setTimeout(()=>{w.current=!0,S(!0),y.current=0},x)},[x,S]);return f.useEffect(()=>()=>{y.current&&(window.clearTimeout(y.current),y.current=0)},[]),(0,d.jsx)(iw.bL,{...c,children:(0,d.jsx)(iN,{scope:t,contentId:p??m,setContentId:g,open:v,stateAttribute:C,trigger:h,onTriggerChange:u,onTriggerEnter:f.useCallback(()=>{l.isOpenDelayedRef.current?T():k()},[l.isOpenDelayedRef,T,k]),onTriggerLeave:f.useCallback(()=>{b?P():(window.clearTimeout(y.current),y.current=0)},[P,b]),onOpen:k,onClose:P,disableHoverableContent:b,children:n})})},"Tooltip"),iH="TooltipTrigger",iU=f.forwardRef(iM(function(e,t){let{__scopeTooltip:n,...r}=e,i=i$(iH,n),o=iR(iH,n),s=iO(n),a=f.useRef(null),l=(0,im.s)(t,a,i.onTriggerChange),c=f.useRef(!1),h=f.useRef(!1),u=f.useCallback(()=>c.current=!1,[]);return f.useEffect(()=>()=>document.removeEventListener("pointerup",u),[u]),(0,d.jsx)(iw.Mz,{asChild:!0,...s,children:(0,d.jsx)(iS.sG.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:l,onPointerMove:(0,ig.mK)(e.onPointerMove,e=>{"touch"!==e.pointerType&&(h.current||o.isPointerInTransitRef.current||(i.onTriggerEnter(),h.current=!0))}),onPointerLeave:(0,ig.mK)(e.onPointerLeave,()=>{i.onTriggerLeave(),h.current=!1}),onPointerDown:(0,ig.mK)(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener("pointerup",u,{once:!0})}),onFocus:(0,ig.mK)(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:(0,ig.mK)(e.onBlur,i.onClose),onClick:(0,ig.mK)(e.onClick,i.onClose)})})},"TooltipTrigger")),[iK,iW]=iA("TooltipPortal",{forceMount:void 0}),iV="TooltipContent",iY=f.forwardRef(iM(function(e,t){let n=iW(iV,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...o}=e,s=i$(iV,e.__scopeTooltip);return(0,d.jsx)(iv.C,{present:r||s.open,children:s.disableHoverableContent?(0,d.jsx)(iX,{side:i,...o,ref:t}):(0,d.jsx)(iG,{side:i,...o,ref:t})})},"TooltipContent")),iG=f.forwardRef(iM(function(e,t){let n=i$(iV,e.__scopeTooltip),r=iR(iV,e.__scopeTooltip),i=f.useRef(null),o=(0,im.s)(t,i),[s,a]=f.useState(null),{trigger:l,onClose:c}=n,h=i.current,{onPointerInTransitChange:u}=r,p=f.useCallback(()=>{a(null),u(!1)},[u]),g=f.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=iZ(r,n.getBoundingClientRect());a(i2([...iQ(r,i),...i0(t.getBoundingClientRect())])),u(!0)},[u]);return f.useEffect(()=>()=>p(),[p]),f.useEffect(()=>{if(l&&h){let e=iM(e=>g(e,h),"handleTriggerLeave"),t=iM(e=>g(e,l),"handleContentLeave");return l.addEventListener("pointerleave",e),h.addEventListener("pointerleave",t),()=>{l.removeEventListener("pointerleave",e),h.removeEventListener("pointerleave",t)}}},[l,h,g,p]),f.useEffect(()=>{if(s){let e=iM(e=>{let t=e.target,n={x:e.clientX,y:e.clientY},r=l?.contains(t)||h?.contains(t),i=!i1(n,s);r?p():i&&(p(),c())},"handleTrackPointerGrace");return document.addEventListener("pointermove",e),()=>document.removeEventListener("pointermove",e)}},[l,h,s,c,p]),(0,d.jsx)(iX,{...e,ref:o})},"TooltipContentHoverable")),iq=(0,iC.Dc)("TooltipContent"),iX=f.forwardRef(iM(function(e,t){let{__scopeTooltip:n,children:r,"aria-label":i,id:o,onEscapeKeyDown:s,onPointerDownOutside:a,...l}=e,c=i$(iV,n),h=iO(n),{onClose:u}=c;f.useEffect(()=>(document.addEventListener(iD,u),()=>document.removeEventListener(iD,u)),[u]),f.useEffect(()=>{if(c.trigger){let e=iM(e=>{e.target instanceof Node&&e.target.contains(c.trigger)&&u()},"handleScroll");return window.addEventListener("scroll",e,{capture:!0}),()=>window.removeEventListener("scroll",e,{capture:!0})}},[c.trigger,u]);let{setContentId:p}=c;return(0,iP.N)(()=>(p(o),()=>{p(void 0)}),[o,p]),(0,d.jsx)(ib.qW,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:a,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,d.jsxs)(iw.UC,{"data-state":c.stateAttribute,role:i?void 0:"tooltip",id:i?void 0:c.contentId,...h,...l,ref:t,style:{...l.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[(0,d.jsx)(iq,{children:r}),i?(0,d.jsx)(iI,{id:c.contentId,role:"tooltip",children:i}):null]})})},"TooltipContentImpl")),iJ=f.forwardRef(iM(function(e,t){let{__scopeTooltip:n,...r}=e,i=iO(n);return(0,d.jsx)(iw.i3,{...i,...r,ref:t})},"TooltipArrow"));function iZ(e,t){let n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),o=Math.abs(t.left-e.x);switch(Math.min(n,r,i,o)){case o:return"left";case i:return"right";case n:return"top";case r:return"bottom";default:throw Error("unreachable")}}function iQ(e,t,n=5){let r=[];switch(t){case"top":r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n})}return r}function i0(e){let{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function i1(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,o=t.length-1;e<t.length;o=e++){let s=t[e],a=t[o],l=s.x,d=s.y,c=a.x,h=a.y;d>r!=h>r&&n<(c-l)*(r-d)/(h-d)+l&&(i=!i)}return i}function i2(e){let t=e.slice();return t.sort((e,t)=>e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:1*!!(e.y>t.y)),i3(t)}function i3(e){if(e.length<=1)return e.slice();let t=[];for(let n=0;n<e.length;n++){let r=e[n];for(;t.length>=2;){let e=t[t.length-1],n=t[t.length-2];if((e.x-n.x)*(r.y-n.y)>=(e.y-n.y)*(r.x-n.x))t.pop();else break}t.push(r)}t.pop();let n=[];for(let t=e.length-1;t>=0;t--){let r=e[t];for(;n.length>=2;){let e=n[n.length-1],t=n[n.length-2];if((e.x-t.x)*(r.y-t.y)>=(e.y-t.y)*(r.x-t.x))n.pop();else break}n.push(r)}return(n.pop(),1===t.length&&1===n.length&&t[0].x===n[0].x&&t[0].y===n[0].y)?t:t.concat(n)}iM(iZ,"getExitSideFromRect"),iM(iQ,"getPaddedExitPoints"),iM(i0,"getPointsFromRect"),iM(i1,"isPointInPolygon"),iM(i2,"getHull"),iM(i3,"getHullPresorted");let i5=(0,f.createContext)({orientation:"horizontal",tooltipSide:"bottom"});function i6({children:e,orientation:t,tooltipSide:n}){let r=i4(),i=n??(t===r.orientation?r.tooltipSide:"horizontal"===t?"bottom":"right");return(0,d.jsx)(i5.Provider,{value:{orientation:t,tooltipSide:i},children:e})}function i4(){return(0,f.useContext)(i5)}let i8=(0,f.forwardRef)(({asChild:e,className:t,tooltipSide:n,...r},i)=>{let o=e?iC.bL:"div";return(0,d.jsx)(i6,{orientation:"horizontal",tooltipSide:n,children:(0,d.jsx)(o,{ref:i,className:ip("tlui-row",t),...r})})}),i9=(0,f.forwardRef)(({asChild:e,className:t,tooltipSide:n,...r},i)=>{let o=e?iC.bL:"div";return(0,d.jsx)(i6,{orientation:"vertical",tooltipSide:n,children:(0,d.jsx)(o,{ref:i,className:ip("tlui-column",t),...r})})}),i7=(0,f.forwardRef)(({asChild:e,className:t,tooltipSide:n,...r},i)=>{let o=e?iC.bL:"div";return(0,d.jsx)(i6,{orientation:"horizontal",tooltipSide:n,children:(0,d.jsx)(o,{ref:i,className:ip("tlui-grid",t),...r})})});class oe{static instance=null;state=(0,r.eUv)("tooltip state",{name:"idle"});static getInstance(){return oe.instance||(oe.instance=new oe),oe.instance}hideAllTooltips(){this.handleEvent({type:"hide_all"})}handleEvent(e){let t=this.state.get();switch(e.type){case"pointer_down":"waiting_to_hide"===t.name&&clearTimeout(t.timeoutId),this.state.set({name:"pointer_down"});break;case"pointer_up":"pointer_down"===t.name&&this.state.set({name:"idle"});break;case"show":if("pointer_down"===t.name)return;"waiting_to_hide"===t.name&&clearTimeout(t.timeoutId),this.state.set({name:"showing",tooltip:e.tooltip});break;case"hide":{let{tooltipId:n,editor:r,instant:i}=e;if("showing"===t.name&&t.tooltip.id===n)if(r&&!i){let e=r.timers.setTimeout(()=>{let e=this.state.get();"waiting_to_hide"===e.name&&e.tooltip.id===n&&this.state.set({name:"idle"})},300);this.state.set({name:"waiting_to_hide",tooltip:t.tooltip,timeoutId:e})}else this.state.set({name:"idle"});else"waiting_to_hide"===t.name&&t.tooltip.id===n&&i&&(clearTimeout(t.timeoutId),this.state.set({name:"idle"}));break}case"hide_all":if("waiting_to_hide"===t.name&&clearTimeout(t.timeoutId),"pointer_down"===t.name)return;this.state.set({name:"idle"})}}getCurrentTooltipData(){let e=this.state.get(),t=null;return("showing"===e.name?t=e.tooltip:"waiting_to_hide"===e.name&&(t=e.tooltip),t&&(!r.$Gt.get().isCoarsePointer||t.showOnMobile))?t:null}}let ot=oe.getInstance();function on(){ot.hideAllTooltips()}let or=(0,f.createContext)(!1);function oi({children:e}){return(0,d.jsx)(iF,{skipDelayDuration:700,children:(0,d.jsxs)(or.Provider,{value:!0,children:[e,(0,d.jsx)(oo,{})]})})}function oo(){let[e,t]=(0,f.useState)(!1),n=(0,f.useRef)(null),i=(0,f.useRef)(!0),o=(0,r.frr)(),s=A(),a=(0,r.hau)("current tooltip",()=>ot.getCurrentTooltipData(),[]),l=(0,r.hau)("camera state",()=>o?.getCameraState(),[o]);return((0,f.useEffect)(()=>{"moving"===l&&e&&a&&ot.handleEvent({type:"hide",tooltipId:a.id,editor:o,instant:!0})},[l,e,a,o]),(0,f.useEffect)(()=>{let t=o?.getContainerDocument()??(0,r.jLo)();function n(t){"Escape"===t.key&&a&&e&&(on(),t.stopPropagation())}return t.addEventListener("keydown",n,{capture:!0}),()=>{t.removeEventListener("keydown",n,{capture:!0})}},[o,a,e]),(0,f.useEffect)(()=>{let e=o?.getContainerDocument()??(0,r.jLo)();function t(){ot.handleEvent({type:"pointer_down"})}function n(){ot.handleEvent({type:"pointer_up"})}return e.addEventListener("pointerdown",t,{capture:!0}),e.addEventListener("pointerup",n,{capture:!0}),e.addEventListener("pointercancel",n,{capture:!0}),()=>{e.removeEventListener("pointerdown",t,{capture:!0}),e.removeEventListener("pointerup",n,{capture:!0}),e.removeEventListener("pointercancel",n,{capture:!0}),ot.handleEvent({type:"pointer_up"})}},[o]),(0,f.useEffect)(()=>{let e=null;if(a&&n.current){let r=a.targetElement.getBoundingClientRect(),o=n.current;o.style.position="fixed",o.style.left="0px",o.style.top="0px";let s=o.getBoundingClientRect();o.style.left=`${r.left-s.left}px`,o.style.top=`${r.top-s.top}px`,o.style.width=`${r.width}px`,o.style.height=`${r.height}px`,o.style.pointerEvents="none",o.style.zIndex="9999",i.current?e=setTimeout(()=>{t(!0),i.current=!1},a.delayDuration):t(!0)}else t(!1),i.current=!0;return()=>{null!==e&&clearTimeout(e)}},[a]),a)?(0,d.jsxs)(iB,{open:e,delayDuration:0,children:[(0,d.jsx)(iU,{asChild:!0,children:(0,d.jsx)("div",{ref:n})}),(0,d.jsxs)(iY,{className:"tlui-tooltip",side:a.side,sideOffset:a.sideOffset,avoidCollisions:!0,collisionPadding:8,dir:s,children:[a.content,(0,d.jsx)(iJ,{className:"tlui-tooltip__arrow"})]})]}):null}let oa=(0,f.forwardRef)(({children:e,content:t,side:n,sideOffset:i=5,disabled:o=!1,showOnMobile:s=!1,delayDuration:a},l)=>{let c,h=(0,r.frr)(),u=A(),p=(0,f.useRef)((0,r.NF7)()),g=(0,f.useContext)(or),m=(0,r.hau)("enhancedA11yMode",()=>h?.user.getEnhancedA11yMode(),[h]),y=i4(),b=n??y.tooltipSide;if((0,f.useEffect)(()=>{let e=p.current;return()=>{g&&ot.handleEvent({type:"hide",tooltipId:e,editor:h,instant:!0})}},[h,g]),o||!t)return(0,d.jsx)(d.Fragment,{children:e});if(c=m?0:a??(h?.options.tooltipDelayMs||700),!g||m)return(0,d.jsxs)(iB,{delayDuration:c,disableHoverableContent:!m,children:[(0,d.jsx)(iU,{asChild:!0,ref:l,children:e}),(0,d.jsxs)(iY,{className:"tlui-tooltip",side:b,sideOffset:i,avoidCollisions:!0,collisionPadding:8,dir:u,children:[t,(0,d.jsx)(iJ,{className:"tlui-tooltip__arrow"})]})]});let x=f.Children.only(e);return(0,r.vAR)(f.isValidElement(x),"TldrawUiTooltip children must be a single element"),f.cloneElement(x,{onMouseEnter:e=>{x.props.onMouseEnter?.(e),ot.handleEvent({type:"show",tooltip:{id:p.current,content:t,targetElement:e.currentTarget,side:b,sideOffset:i,showOnMobile:s,delayDuration:c}})},onMouseLeave:e=>{x.props.onMouseLeave?.(e),ot.handleEvent({type:"hide",tooltipId:p.current,editor:h,instant:!1})},onFocus:e=>{x.props.onFocus?.(e),ot.handleEvent({type:"show",tooltip:{id:p.current,content:t,targetElement:e.currentTarget,side:b,sideOffset:i,showOnMobile:s,delayDuration:c}})},onBlur:e=>{x.props.onBlur?.(e),ot.handleEvent({type:"hide",tooltipId:p.current,editor:h,instant:!1})}})}),ol={normal:"tlui-button__normal",primary:"tlui-button__primary",danger:"tlui-button__danger",low:"tlui-button__low",icon:"tlui-button__icon",tool:"tlui-button__tool",menu:"tlui-button__menu",help:"tlui-button__help"},od=f.forwardRef(function({children:e,type:t,htmlButtonType:n,isActive:r,tooltip:i,...o},s){let a=(0,d.jsx)("button",{ref:s,type:n||"button",draggable:!1,"data-isactive":r,...o,className:ip("tlui-button",ol[t],o.className),"aria-label":o["aria-label"]??o.title,title:i?void 0:o.title,children:e});return i?(0,d.jsx)(oa,{content:i,children:a}):a});function oc({children:e}){return(0,d.jsx)("span",{className:"tlui-button__label",children:e})}var oh=n(69885),ou=n(19040),op=n(32007),of=n(5174),og=n(22954),om=Object.defineProperty,oy=(e,t)=>om(e,"name",{value:t,configurable:!0}),ob="Dialog",[ox,ow]=(0,iy.A)(ob),[ov,oS]=ox(ob),oC=oy(e=>{let{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:o,modal:s=!0}=e,a=f.useRef(null),l=f.useRef(null),[c,h]=(0,ik.i)({prop:r,defaultProp:i??!1,onChange:o,caller:ob}),[u,p]=f.useState(0),[g,m]=f.useState(0);return(0,d.jsx)(ov,{scope:t,triggerRef:a,contentRef:l,contentId:(0,ix.B)(),titleId:(0,ix.B)(),descriptionId:(0,ix.B)(),titlePresent:u>0,descriptionPresent:g>0,setTitleCount:p,setDescriptionCount:m,open:c,onOpenChange:h,onOpenToggle:f.useCallback(()=>h(e=>!e),[h]),modal:s,children:n})},"Dialog"),ok="DialogPortal",[oP,oT]=ox(ok,{forceMount:void 0}),oE=oy(e=>{let{__scopeDialog:t,forceMount:n,children:r,container:i}=e,o=oS(ok,t);return(0,d.jsx)(oP,{scope:t,forceMount:n,children:f.Children.map(r,e=>(0,d.jsx)(iv.C,{present:n||o.open,children:(0,d.jsx)(ou.Z,{asChild:!0,container:i,children:e})}))})},"DialogPortal"),oI="DialogOverlay",o_=f.forwardRef(oy(function(e,t){let n=oT(oI,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,o=oS(oI,e.__scopeDialog);return o.modal?(0,d.jsx)(iv.C,{present:r||o.open,children:(0,d.jsx)(oA,{...i,ref:t})}):null},"DialogOverlay")),oM=(0,iC.TL)("DialogOverlay.RemoveScroll"),oA=f.forwardRef(oy(function(e,t){let{__scopeDialog:n,...r}=e,i=oS(oI,n),o=(0,ib.e0)(),s=(0,im.s)(t,o);return(0,d.jsx)(of.A,{as:oM,allowPinchZoom:!0,shards:[i.contentRef],children:(0,d.jsx)(iS.sG.div,{"data-state":oN(i.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})},"DialogOverlayImpl")),oj="DialogContent",oO=f.forwardRef(oy(function(e,t){let n=oT(oj,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,o=oS(oj,e.__scopeDialog);return(0,d.jsx)(iv.C,{present:r||o.open,children:o.modal?(0,d.jsx)(oD,{...i,ref:t}):(0,d.jsx)(oL,{...i,ref:t})})},"DialogContent")),oD=f.forwardRef(oy(function(e,t){let n=oS(oj,e.__scopeDialog),r=f.useRef(null),i=(0,im.s)(t,n.contentRef,r);return f.useEffect(()=>{let e=r.current;if(e)return(0,og.Eq)(e)},[]),(0,d.jsx)(oR,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:(0,ig.mK)(e.onCloseAutoFocus,e=>{e.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:(0,ig.mK)(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=0===t.button&&!0===t.ctrlKey;(2===t.button||n)&&e.preventDefault()}),onFocusOutside:(0,ig.mK)(e.onFocusOutside,e=>e.preventDefault())})},"DialogContentModal")),oL=f.forwardRef(oy(function(e,t){let n=oS(oj,e.__scopeDialog),r=f.useRef(!1),i=f.useRef(!1);return(0,d.jsx)(oR,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,"pointerdown"===t.detail.originalEvent.type&&(i.current=!0));let o=t.target;n.triggerRef.current?.contains(o)&&t.preventDefault(),"focusin"===t.detail.originalEvent.type&&i.current&&t.preventDefault()}})},"DialogContentNonModal")),oR=f.forwardRef(oy(function(e,t){let{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:o,...s}=e,a=oS(oj,n);return(0,op.Oh)(),(0,d.jsx)(d.Fragment,{children:(0,d.jsx)(oh.n,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:o,children:(0,d.jsx)(ib.qW,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionPresent?a.descriptionId:void 0,"aria-labelledby":a.titlePresent?a.titleId:void 0,"data-state":oN(a.open),...s,ref:t,deferPointerDownOutside:!0,onDismiss:()=>a.onOpenChange(!1)})})})},"DialogContentImpl")),oF=f.forwardRef(oy(function(e,t){let{__scopeDialog:n,...r}=e,i=oS("DialogTitle",n),{setTitleCount:o}=i;return(0,iP.N)(()=>(o(e=>e+1),()=>o(e=>e-1)),[o]),(0,d.jsx)(iS.sG.h2,{id:i.titleId,...r,ref:t})},"DialogTitle")),oz=f.forwardRef(oy(function(e,t){let{__scopeDialog:n,...r}=e,i=oS("DialogClose",n);return(0,d.jsx)(iS.sG.button,{type:"button",...r,ref:t,onClick:(0,ig.mK)(e.onClick,()=>i.onOpenChange(!1))})},"DialogClose"));function oN(e){return e?"open":"closed"}oy(oN,"getState");let o$=(0,f.memo)(function({label:e,small:t,invertIcon:n,icon:r,tiny:i,color:o,className:s,...a}){return"string"==typeof r?(0,d.jsx)(oB,{label:e,small:t,tiny:i,invertIcon:n,icon:r,color:o,className:s,...a}):(0,f.cloneElement)(r,{...a,className:ip({"tlui-icon__small":t,"tlui-icon__tiny":i},s,r.props.className),"aria-label":e,style:{color:o,transform:n?"scale(-1, 1)":void 0,...r.props.style}})});function oB({label:e,small:t,tiny:n,invertIcon:r,icon:i,color:o,className:s,...a}){let l=C(),c=l.icons[i]??l.icons["question-mark-circle"],h=(0,f.useRef)(null);return((0,f.useLayoutEffect)(()=>{c||console.error(`Icon not found: ${i}. Add it to the assetUrls.icons object.`),h?.current&&(h.current.style.webkitMask=`url(${c}) center 100% / 100% no-repeat`)},[h,c,i]),"none"===i)?(0,d.jsx)("div",{className:ip("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":t,"tlui-icon__tiny":n},s),...a}):(0,d.jsx)("div",{...a,ref:h,"aria-label":e,role:"img",className:ip("tlui-icon",{"tlui-icon__small":t,"tlui-icon__tiny":n},s),style:{color:o,mask:`url(${c}) center 100% / 100% no-repeat`,transform:r?"scale(-1, 1)":void 0}})}function oH({icon:e,small:t,invertIcon:n}){return(0,d.jsx)(o$,{"aria-hidden":"true",label:"",className:"tlui-button__icon",icon:e,small:t,invertIcon:n})}function oU({className:e,children:t}){return(0,d.jsx)("div",{className:ip("tlui-dialog__header",e),children:t})}function oK({className:e,children:t,style:n}){let r=A();return(0,d.jsx)(oF,{dir:r,className:ip("tlui-dialog__header__title",e),style:n,children:t})}function oW(){let e=M(),t=A();return(0,d.jsx)("div",{className:"tlui-dialog__header__close",children:(0,d.jsx)(oz,{"data-testid":"dialog.close",dir:t,asChild:!0,children:(0,d.jsx)(od,{type:"icon","aria-label":e("ui.close"),onTouchEnd:e=>e.target.click(),children:(0,d.jsx)(oH,{small:!0,icon:"cross-2"})})})})}function oV({className:e,children:t,style:n}){return(0,d.jsx)("div",{className:ip("tlui-dialog__body",e),style:n,tabIndex:0,children:t})}function oY({className:e,children:t}){return(0,d.jsx)("div",{className:ip("tlui-dialog__footer",e),children:t})}let oG=f.forwardRef(function({className:e,label:t,icon:n,iconLeft:i,iconLabel:o,autoSelect:s=!1,autoFocus:a=!1,defaultValue:l,maxLength:c,placeholder:h,onComplete:u,onValueChange:p,onCancel:g,onFocus:m,onBlur:y,shouldManuallyMaintainScrollPositionWhenFocused:b=!1,children:x,value:w,"data-testid":v,disabled:S,"aria-label":C},k){let P=(0,r.frr)(),T=f.useRef(null);f.useImperativeHandle(k,()=>T.current);let E=M(),I=f.useRef(l??""),_=f.useRef(l??""),A=f.useRef(!1),[j,O]=f.useState(!1),D=f.useCallback(e=>{O(!0);let t=e.currentTarget;_.current=t.value,P?P.timers.requestAnimationFrame(()=>{s&&t.select()}):r.slq.requestAnimationFrame("anon",()=>{s&&t.select()}),m?.()},[s,P,m]),L=f.useCallback(e=>{let t=e.currentTarget.value;_.current=t,p?.(t)},[p]),R=f.useCallback(e=>{switch(e.key){case"Enter":if(A.current)return;e.currentTarget.blur(),e.stopPropagation(),u?.(e.currentTarget.value);break;case"Escape":e.currentTarget.value=I.current,g?.(e.currentTarget.value),e.currentTarget.blur(),e.stopPropagation()}},[u,g]),F=f.useCallback(e=>{O(!1);let t=e.currentTarget.value;y?.(t)},[y]),z=f.useCallback(()=>A.current=!0,[]),N=f.useCallback(()=>A.current=!1,[]);return f.useEffect(()=>{if(!r.YZA.isIos)return;let e=(P?.getContainerWindow()??window).visualViewport;if(j&&b&&e){let t=()=>{T.current?.scrollIntoView({block:"center"})};return e.addEventListener("resize",t),e.addEventListener("scroll",t),P?P.timers.requestAnimationFrame(()=>{T.current?.scrollIntoView({block:"center"})}):r.slq.requestAnimationFrame("anon",()=>{T.current?.scrollIntoView({block:"center"})}),()=>{e.removeEventListener("resize",t),e.removeEventListener("scroll",t)}}},[j,P,b]),(0,d.jsxs)("div",{draggable:!1,className:"tlui-input__wrapper",children:[x,t&&(0,d.jsx)("label",{children:E(t)}),i&&(0,d.jsx)(o$,{label:o?E(o):"",icon:i,className:"tlui-icon-left",small:!0}),(0,d.jsx)("input",{ref:T,className:ip("tlui-input",e),type:"text",defaultValue:l,maxLength:c,onKeyDownCapture:R,onChange:L,onFocus:D,onBlur:F,onCompositionStart:z,onCompositionEnd:N,autoFocus:a,"aria-label":C,placeholder:h,value:w,"data-testid":v,disabled:S}),n&&(0,d.jsx)(o$,{label:o?E(o):"",icon:n,small:!!t})]})});function oq(e){return r.T.linkUrl.isValid(e)?{isValid:!0,hasProtocol:!0}:r.T.linkUrl.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}function oX(e){return!!(e&&"url"in e.props&&"string"==typeof e.props.url)}function oJ(e){if(!oX(e))throw Error("Shape is not a valid ShapeWithUrl")}let oZ=(0,r.u4I)(function({onClose:e}){let t=(0,r.hGv)().getOnlySelectedShape();return oX(t)?(0,d.jsx)(oQ,{onClose:e,selectedShape:t}):null}),oQ=(0,r.u4I)(function({onClose:e,selectedShape:t}){let n=(0,r.hGv)(),i=M(),o=(0,f.useRef)(null);(0,f.useEffect)(()=>{n.timers.requestAnimationFrame(()=>o.current?.focus())},[n]);let s=(0,f.useRef)(t.props.url),[a,l]=(0,f.useState)(()=>{let e=oq(t.props.url),n=!0===e.isValid?e.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:n,safe:n,valid:!0}}),c=(0,f.useCallback)(e=>{let t=e.replace(/https?:\/\/(https?:\/\/)/,(e,t)=>t),n=oq(t),r=!0===n.isValid?n.hasProtocol?t:"https://"+t:"https://";l({actual:t,safe:r,valid:n.isValid})},[]),h=(0,f.useCallback)(()=>{let t=n.getOnlySelectedShape();t&&(oJ(t),n.updateShapes([{id:t.id,type:t.type,props:{url:""}}]),e())},[n,e]),u=(0,f.useCallback)(()=>{let t=n.getOnlySelectedShape();t&&(oJ(t),t&&"url"in t.props&&t.props.url!==a.safe&&n.updateShapes([{id:t.id,type:t.type,props:{url:a.safe}}]),e())},[n,e,a]),p=(0,f.useCallback)(()=>{e()},[e]);if(!t)return e(),null;let g=s.current&&!a.valid;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(oU,{children:[(0,d.jsx)(oK,{children:i("edit-link-dialog.title")}),(0,d.jsx)(oW,{})]}),(0,d.jsx)(oV,{children:(0,d.jsxs)("div",{className:"tlui-edit-link-dialog",children:[(0,d.jsx)(oG,{ref:o,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,autoSelect:!0,placeholder:"https://example.com",value:a.actual,onValueChange:c,onComplete:u,onCancel:p}),(0,d.jsx)("div",{children:i(a.valid?"edit-link-dialog.detail":"edit-link-dialog.invalid-url")})]})}),(0,d.jsxs)(oY,{className:"tlui-dialog__footer__actions",children:[(0,d.jsx)(od,{type:"normal",onClick:p,onTouchEnd:p,children:(0,d.jsx)(oc,{children:i("edit-link-dialog.cancel")})}),g?(0,d.jsx)(od,{type:"danger",onTouchEnd:h,onClick:h,children:(0,d.jsx)(oc,{children:i("edit-link-dialog.clear")})}):(0,d.jsx)(od,{type:"primary",disabled:!a.valid,onTouchEnd:u,onClick:u,children:(0,d.jsx)(oc,{children:i("edit-link-dialog.save")})})]})]})});var o0=n(41463);let o1=/(^\/[f|p|r|ro|s|v]\/[^/]+\/?$)/,o2=[{type:"tldraw",title:"tldraw",hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,overridePermissions:{"allow-top-navigation":!0},toEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(o1))return t.searchParams.append("embed","true"),e},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(o1))return t.searchParams.delete("embed"),e},embedOnPaste:!1},{type:"figma",title:"Figma",hostnames:["figma.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{if(e.match(/https:\/\/([\w\.-]+\.)?figma.com\/(file|proto|design)\/([0-9a-zA-Z]{22,128})(?:\/.*)?$/)&&!e.includes("figma.com/embed"))return`https://www.figma.com/embed?embed_host=share&url=${e}`},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/^\/embed\/?$/)){let e=t.searchParams.get("url");if(e)return e}},embedOnPaste:!0},{type:"canva",title:"Canva",hostnames:["canva.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/^\/design\/([^/]+)\/.+/)&&!t.searchParams.has("embed"))return t.searchParams.set("embed",""),t.href},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/^\/design\/([^/]+)\/.+/)&&t.searchParams.has("embed"))return t.searchParams.delete("embed"),t.href},embedOnPaste:!0},{type:"google_maps",title:"Google Maps",hostnames:["google.*"],width:720,height:500,doesResize:!0,overridePermissions:{"allow-presentation":!0},toEmbedUrl:(e,t)=>{if(e.includes("/maps/embed?"))return e;if(e.includes("/maps/")){let n,r=e.match(/@(.*?),(.*?),(.*?)(z|m)/);if(r){let[,i,o,s,a]=r,l="z"===a?"roadmap":"satellite",d="roadmap"===l?s:-Math.log2(parseInt(s)/0xe16861)/.8,c=new URL(e).host.replace("www.",""),h=t?.apiKey??o0.env.NEXT_PUBLIC_GC_API_KEY;n=`https://${c}/maps/embed/v1/view?key=${h}&center=${i},${o}&zoom=${d}&maptype=${l}`}else n="";return n}},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&t.searchParams.has("center")&&t.searchParams.get("zoom")){let e=t.searchParams.get("zoom")??"12",n=t.searchParams.get("maptype")??"roadmap",r="roadmap"===n?e:0xe16861*Math.pow(2,-.8*parseInt(e)),[i,o]=t.searchParams.get("center").split(",");return`https://www.google.com/maps/@${i},${o},${r}${"roadmap"===n?"z":"m"}`}},embedOnPaste:!0},{type:"val_town",title:"Val Town",hostnames:["val.town"],minWidth:260,minHeight:100,width:720,height:500,doesResize:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e),n=t&&t.pathname.match(/\/v\/(.+)\/?/);if(n)return`https://www.val.town/embed/${n[1]}`},fromEmbedUrl:e=>{let t=(0,r.yCG)(e),n=t&&t.pathname.match(/\/embed\/(.+)\/?/);if(n)return`https://www.val.town/v/${n[1]}`},embedOnPaste:!0},{type:"codesandbox",title:"CodeSandbox",hostnames:["codesandbox.io"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e),n=t&&t.pathname.match(/\/s\/([^/]+)\/?/);if(n)return`https://codesandbox.io/embed/${n[1]}`},fromEmbedUrl:e=>{let t=(0,r.yCG)(e),n=t&&t.pathname.match(/\/embed\/([^/]+)\/?/);if(n)return`https://codesandbox.io/s/${n[1]}`},embedOnPaste:!0},{type:"codepen",title:"Codepen",hostnames:["codepen.io"],minWidth:300,minHeight:300,width:520,height:400,doesResize:!0,toEmbedUrl:e=>{let t=e.match(/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/);if(t){let[e,n,r]=t;return`https://codepen.io/${n}/embed/${r}`}},fromEmbedUrl:e=>{let t=e.match(/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/);if(t){let[e,n,r]=t;return`https://codepen.io/${n}/pen/${r}`}},embedOnPaste:!0},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,embedOnPaste:!0,toEmbedUrl:e=>{let t=e.match(/https?:\/\/scratch.mit.edu\/projects\/([^/]+)/);if(t){let[e,n]=t;return`https://scratch.mit.edu/projects/embed/${n}`}},fromEmbedUrl:e=>{let t=e.match(/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/);if(t){let[e,n]=t;return`https://scratch.mit.edu/projects/${n}`}}},{type:"youtube",title:"YouTube",hostnames:["*.youtube.com","youtube.com","youtu.be"],width:800,height:450,doesResize:!0,overridePermissions:{"allow-presentation":!0,"allow-popups-to-escape-sandbox":!0},isAspectRatioLocked:!0,embedOnPaste:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e);if(!t)return;let n=t.hostname.replace(/^www./,"");if("youtu.be"===n){let e=t.pathname.split("/").filter(Boolean)[0],n=new URLSearchParams(t.search),r=n.get("t");r&&(n.set("start",r),n.delete("t"));let i=n.toString()?"?"+n.toString():"";return`https://www.youtube.com/embed/${e}${i}`}if(("youtube.com"===n||"m.youtube.com"===n)&&t.pathname.match(/^\/watch/)){let e=t.searchParams.get("v"),n=new URLSearchParams(t.search);n.delete("v");let r=n.get("t");r&&(n.set("start",r),n.delete("t"));let i=n.toString()?"?"+n.toString():"";return`https://www.youtube.com/embed/${e}${i}`}},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&"youtube.com"===t.hostname.replace(/^www./,"")){let e=t.pathname.match(/^\/embed\/([^/]+)\/?/);if(e){let n=new URLSearchParams(t.search);n.set("v",e?.[1]??"");let r=n.get("start");return r&&(n.set("t",r),n.delete("start")),`https://www.youtube.com/watch?${n.toString()}`}}}},{type:"google_calendar",title:"Google Calendar",hostnames:["calendar.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,instructionLink:"https://support.google.com/calendar/answer/41207?hl=en",overridePermissions:{"allow-popups-to-escape-sandbox":!0},embedOnPaste:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e),n=t?.searchParams.get("cid");if(t?.pathname.match(/\/calendar\/u\/0/)&&n){for(let e of(t.pathname="/calendar/embed",Array.from(t.searchParams.keys())))t.searchParams.delete(e);return t.searchParams.set("src",n),t.href}},fromEmbedUrl:e=>{let t=(0,r.yCG)(e),n=t?.searchParams.get("src");if(t?.pathname.match(/\/calendar\/embed/)&&n){for(let e of(t.pathname="/calendar/u/0",Array.from(t.searchParams.keys())))t.searchParams.delete(e);return t.searchParams.set("cid",n),t.href}}},{type:"google_slides",title:"Google Slides",hostnames:["docs.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,overridePermissions:{"allow-popups-to-escape-sandbox":!0},embedOnPaste:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t?.pathname.match(/^\/presentation/)&&t?.pathname.match(/\/pub\/?$/)){for(let e of(t.pathname=t.pathname.replace(/\/pub$/,"/embed"),Array.from(t.searchParams.keys())))t.searchParams.delete(e);return t.href}},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t?.pathname.match(/^\/presentation/)&&t?.pathname.match(/\/embed\/?$/)){for(let e of(t.pathname=t.pathname.replace(/\/embed$/,"/pub"),Array.from(t.searchParams.keys())))t.searchParams.delete(e);return t.href}}},{type:"github_gist",title:"GitHub Gist",hostnames:["gist.github.com"],width:720,height:500,doesResize:!0,embedOnPaste:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/\/([^/]+)\/([0-9a-f]+)$/)){if(!e.split("/").pop())return;return e}},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/\/([^/]+)\/([0-9a-f]+)$/)){if(!e.split("/").pop())return;return e}}},{type:"replit",title:"Replit",hostnames:["replit.com"],width:720,height:500,doesResize:!0,embedOnPaste:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/\/@([^/]+)\/([^/]+)/))return t.searchParams.append("embed","true"),t.href},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/\/@([^/]+)\/([^/]+)/)&&t.searchParams.has("embed"))return t.searchParams.delete("embed"),t.href}},{type:"felt",title:"Felt",hostnames:["felt.com"],width:720,height:500,doesResize:!0,embedOnPaste:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/^\/map\//))return t.origin+"/embed"+t.pathname},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/^\/embed\/map\//))return t.pathname=t.pathname.replace(/^\/embed/,""),t.href}},{type:"spotify",title:"Spotify",hostnames:["open.spotify.com"],width:720,height:500,minHeight:500,overrideOutlineRadius:12,doesResize:!0,embedOnPaste:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/^\/(artist|album)\//))return t.origin+"/embed"+t.pathname},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/^\/embed\/(artist|album)\//))return t.origin+t.pathname.replace(/^\/embed/,"")}},{type:"vimeo",title:"Vimeo",hostnames:["vimeo.com","player.vimeo.com"],width:640,height:360,doesResize:!0,isAspectRatioLocked:!0,embedOnPaste:!0,sizeToContentAspectRatio:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&"vimeo.com"===t.hostname&&t.pathname.match(/^\/[0-9]+/))return"https://player.vimeo.com/video/"+t.pathname.split("/")[1]+"?title=0&byline=0"},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&"player.vimeo.com"===t.hostname){let e=t.pathname.match(/^\/video\/([^/]+)\/?$/);if(e)return"https://vimeo.com/"+e[1]}}},{type:"observable",title:"Observable",hostnames:["observablehq.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!1,backgroundColor:"#fff",embedOnPaste:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&t.pathname.match(/^\/@([^/]+)\/([^/]+)\/?$/))return`${t.origin}/embed${t.pathname}?cell=*`;if(t&&t.pathname.match(/^\/d\/([^/]+)\/?$/)){let e=t.pathname.replace(/^\/d/,"");return`${t.origin}/embed${e}?cell=*`}},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);return t&&t.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/)?`${t.origin}${t.pathname.replace("/embed","")}#cell-*`:t&&t.pathname.match(/^\/embed\/([^/]+)\/?$/)?`${t.origin}${t.pathname.replace("/embed","/d")}#cell-*`:void 0}},{type:"desmos",title:"Desmos",hostnames:["desmos.com"],width:700,height:450,doesResize:!0,embedOnPaste:!0,toEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&"www.desmos.com"===t.hostname&&t.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&""===t.search&&""===t.hash)return`${e}?embed`},fromEmbedUrl:e=>{let t=(0,r.yCG)(e);if(t&&"www.desmos.com"===t.hostname&&t.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&"?embed"===t.search&&""===t.hash)return e.replace("?embed","")}}],o3={"allow-downloads-without-user-activation":!1,"allow-downloads":!1,"allow-modals":!1,"allow-orientation-lock":!1,"allow-pointer-lock":!1,"allow-popups":!0,"allow-popups-to-escape-sandbox":!1,"allow-presentation":!1,"allow-storage-access-by-user-activation":!1,"allow-top-navigation":!1,"allow-top-navigation-by-user-activation":!1,"allow-scripts":!0,"allow-same-origin":!0,"allow-forms":!0},o5={"allow-same-origin":!1,"allow-forms":!1,"allow-popups":!1},o6=o2.map(e=>e.type);function o4(){let e=(0,r.frr)();if(e&&e.hasShapeUtil("embed"))return e.getShapeUtil("embed")}function o8(){let e=o4();return t=>e?e.getEmbedDefinition(t):void 0}let o9=(0,r.u4I)(function({onClose:e}){let t,n=(0,r.hGv)(),i=M(),o=C(),[s,a]=(0,f.useState)(null),[l,c]=(0,f.useState)(""),[h,u]=(0,f.useState)(null),[p,g]=(0,f.useState)(!1),m=(0,f.useRef)(-1),y=(t=o4())?t.getEmbedDefinitions():[],b=o8();return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(oU,{children:[(0,d.jsx)(oK,{children:s?`${i("embed-dialog.title")} \u2014 ${s.title}`:i("embed-dialog.title")}),(0,d.jsx)(oW,{})]}),s?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(oV,{className:"tlui-embed-dialog__enter",children:[(0,d.jsx)(oG,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"https://example.com",autoFocus:!0,onValueChange:e=>{c(e);let t=b(e);u(t&&t.definition.type===s.type?t:null),g(!1),clearTimeout(m.current),m.current=n.timers.setTimeout(()=>g(!t),320)}}),""===l?(0,d.jsxs)("div",{className:"tlui-embed-dialog__instruction",children:[(0,d.jsx)("span",{children:i("embed-dialog.instruction")})," ",s.instructionLink&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:"Learn more"}),"."]})]}):(0,d.jsx)("div",{className:"tlui-embed-dialog__warning",children:p?i("embed-dialog.invalid-url"):"\xa0"})]}),(0,d.jsxs)(oY,{className:"tlui-dialog__footer__actions",children:[(0,d.jsx)(od,{type:"normal",onClick:()=>{a(null),u(null),c("")},children:(0,d.jsx)(oc,{children:i("embed-dialog.back")})}),(0,d.jsx)("div",{className:"tlui-embed__spacer"}),(0,d.jsx)(od,{type:"normal",onClick:e,children:(0,d.jsx)(oc,{children:i("embed-dialog.cancel")})}),(0,d.jsx)(od,{type:"primary",disabled:!h,onClick:()=>{h&&(n.putExternalContent({type:"embed",url:l,point:n.getViewportPageBounds().center,embed:h.definition}),e())},children:(0,d.jsx)(oc,{children:i("embed-dialog.create")})})]})]}):(0,d.jsx)(d.Fragment,{children:(0,d.jsx)(oV,{className:"tlui-embed-dialog__list",children:y.map(e=>{var t;let n=(t=e.type,o6.includes(t))?o.embedIcons[e.type]:"icon"in e?e.icon:void 0;return(0,d.jsxs)(od,{type:"menu",onClick:()=>a(e),children:[(0,d.jsx)(oc,{children:e.title}),n&&(0,d.jsx)("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${n})`}})]},e.type)})})})]})}),o7=[0,389,436,476,580,640,840,1023],se=f.createContext(null);function st({forceMobile:e=!1,children:t}){let n=(0,r.frr)(),i=(0,r.hau)("breakpoint",()=>{let{width:t}=n?.getViewportScreenBounds()??{width:(0,r.CMG)().innerWidth},i=e?3:o7.length-1;for(let e=0;e<i;e++)if(t>o7[e]&&t<=o7[e+1])return e;return i},[n]);return(0,d.jsx)(se.Provider,{value:i,children:t})}function sn(){let e=(0,f.useContext)(se);if(null===e)throw Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return e}let sr=(0,f.createContext)(null);function si(){let e=(0,f.useContext)(sr);if(!e)throw Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return e}function so({type:e,sourceId:t,children:n}){return(0,d.jsx)(sr.Provider,{value:{type:e,sourceId:t},children:n})}function ss(){let e=(0,r.frr)();return e?.store.props.collaboration!==void 0}var sa=n(94119);function sl(){let e=(0,r.frr)();return(0,r.hau)("isReadonlyMode",()=>!!e?.getIsReadonly(),[e])}let sd=r.YZA.isDarwin?"⌘":"__CTRL__",sc=r.YZA.isDarwin?"⌃":"__CTRL__",sh=r.YZA.isDarwin?"⌥":"__ALT__";function su(e){return","===e?[","]:e.split(",")[0].split(/(\[\[[^\]]+\]\])/g).map(e=>e.startsWith("[[")?e.replace(/[[\]]/g,""):e.replace(/cmd\+/g,sd).replace(/ctrl\+/g,sc).replace(/alt\+/g,sh).replace(/shift\+/g,"⇧").replace(/\$/g,sd).replace(/\?/g,sh).replace(/!/g,"⇧").match(/__CTRL__|__ALT__|./g)||[]).flat().map((e,t)=>{let n;return"+"===e[0]?[]:(n="__CTRL__"===e?"Ctrl":"__ALT__"===e?"Alt":e[0].toUpperCase()+e.slice(1),r.YZA.isDarwin||!t?n:["+",n])}).flat()}function sp(e){return"— "+su(e).join(" ")}function sf(e){let t=M();return(0,d.jsx)(r.z6X,{"aria-label":t("app.loading"),...e})}var sg=n(69445),sm=Object.defineProperty,sy=(e,t)=>sm(e,"name",{value:t,configurable:!0}),sb="DropdownMenu",[sx,sw]=(0,iy.A)(sb,[sg.UE]),sv=(0,sg.UE)(),[sS,sC]=sx(sb),sk=sy(e=>{let{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:o,onOpenChange:s,modal:a=!0}=e,l=sv(t),c=f.useRef(null),[h,u]=(0,ik.i)({prop:i,defaultProp:o??!1,onChange:s,caller:sb});return(0,d.jsx)(sS,{scope:t,triggerId:(0,ix.B)(),triggerRef:c,contentId:(0,ix.B)(),open:h,onOpenChange:u,onOpenToggle:f.useCallback(()=>u(e=>!e),[u]),modal:a,children:(0,d.jsx)(sg.bL,{...l,open:h,onOpenChange:u,dir:r,modal:a,children:n})})},"DropdownMenu"),sP=f.forwardRef(sy(function(e,t){let{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,o=sC("DropdownMenuTrigger",n),s=sv(n),a=(0,im.s)(t,o.triggerRef);return(0,d.jsx)(sg.Mz,{asChild:!0,...s,children:(0,d.jsx)(iS.sG.button,{type:"button",id:o.triggerId,"aria-haspopup":"menu","aria-expanded":o.open,"aria-controls":o.open?o.contentId:void 0,"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...i,ref:a,onPointerDown:(0,ig.mK)(e.onPointerDown,e=>{!r&&0===e.button&&!1===e.ctrlKey&&(o.onOpenToggle(),o.open||e.preventDefault())}),onKeyDown:(0,ig.mK)(e.onKeyDown,e=>{!r&&(["Enter"," "].includes(e.key)&&o.onOpenToggle(),"ArrowDown"===e.key&&o.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(e.key)&&e.preventDefault())})})})},"DropdownMenuTrigger")),sT=sy(e=>{let{__scopeDropdownMenu:t,...n}=e,r=sv(t);return(0,d.jsx)(sg.ZL,{...r,...n})},"DropdownMenuPortal"),sE=f.forwardRef(sy(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=sC("DropdownMenuContent",n),o=sv(n),s=f.useRef(!1);return(0,d.jsx)(sg.UC,{id:i.contentId,"aria-labelledby":i.triggerId,...o,...r,ref:t,onCloseAutoFocus:(0,ig.mK)(e.onCloseAutoFocus,e=>{s.current||i.triggerRef.current?.focus(),s.current=!1,e.preventDefault()}),onInteractOutside:(0,ig.mK)(e.onInteractOutside,e=>{let t=e.detail.originalEvent,n=0===t.button&&!0===t.ctrlKey,r=2===t.button||n;(!i.modal||r)&&(s.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),sI=f.forwardRef(sy(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=sv(n);return(0,d.jsx)(sg.q7,{...i,...r,ref:t})},"DropdownMenuItem")),s_=f.forwardRef(sy(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=sv(n);return(0,d.jsx)(sg.H_,{...i,...r,ref:t})},"DropdownMenuCheckboxItem")),sM=f.forwardRef(sy(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=sv(n);return(0,d.jsx)(sg.VF,{...i,...r,ref:t})},"DropdownMenuItemIndicator")),sA=sy(e=>{let{__scopeDropdownMenu:t,children:n,open:r,onOpenChange:i,defaultOpen:o}=e,s=sv(t),[a,l]=(0,ik.i)({prop:r,defaultProp:o??!1,onChange:i,caller:"DropdownMenuSub"});return(0,d.jsx)(sg.Pb,{...s,open:a,onOpenChange:l,children:n})},"DropdownMenuSub"),sj=f.forwardRef(sy(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=sv(n);return(0,d.jsx)(sg.ZP,{...i,...r,ref:t})},"DropdownMenuSubTrigger")),sO=f.forwardRef(sy(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=sv(n);return(0,d.jsx)(sg.G5,{...i,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuSubContent"));let sD=()=>void 0,sL=f.createContext(null);function sR({onEvent:e,children:t}){return(0,d.jsx)(sL.Provider,{value:e??sD,children:t})}function sF(){return f.useContext(sL)??sD}function sz(e,t){let n=(0,r.frr)(),i=(0,f.useCallback)(e=>{e&&n?.complete(),t?.(e)},[n,t]),o=sF(),s=(0,f.useCallback)(t=>{o(t,{source:"unknown",id:e})},[e,o]);return(0,r.ofB)(n?`${e}-${n.contextId}`:e,i,s)}function sN({id:e,children:t,modal:n=!1,debugOpen:r=!1}){let[i,o]=sz(e),s=A();return(0,d.jsx)(sk,{open:r||i,dir:s,modal:n,onOpenChange:o,children:t})}function s$({children:e,...t}){let n=A();return(0,d.jsx)(sP,{dir:n,asChild:!0,onTouchEnd:e=>(0,r.woC)(e),...t,children:e})}function sB({className:e,side:t="bottom",align:n="start",sideOffset:i=8,alignOffset:o=8,collisionPadding:s=4,children:a}){let l=(0,r.NFA)();return(0,d.jsx)(sT,{container:l,children:(0,d.jsx)(sE,{className:ip("tlui-menu",e),side:t,sideOffset:i,align:n,alignOffset:o,collisionPadding:s,children:a})})}function sH({id:e,children:t}){let[n,r]=sz(e);return(0,d.jsx)(sA,{open:n,onOpenChange:r,children:t})}function sU({id:e,label:t,title:n,disabled:r}){let i=A();return(0,d.jsx)(sj,{dir:i,asChild:!0,disabled:r,children:(0,d.jsxs)(od,{"data-testid":e,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:n,children:[(0,d.jsx)(oc,{children:t}),(0,d.jsx)(oH,{icon:"rtl"===i?"chevron-left":"chevron-right",small:!0})]})})}function sK({id:e,alignOffset:t=-1,sideOffset:n=-6,size:i="small",children:o}){let s=(0,r.NFA)();return(0,d.jsx)(sT,{container:s,children:(0,d.jsx)(sO,{"data-testid":e,className:"tlui-menu tlui-menu__submenu__content",alignOffset:t,sideOffset:n,collisionPadding:4,"data-size":i,children:o})})}function sW({className:e,children:t}){let n=A();return(0,d.jsx)("div",{dir:n,className:ip("tlui-menu__group",e),children:t})}function sV({noClose:e,children:t}){let n=A();return(0,d.jsx)(sI,{dir:n,asChild:!0,onClick:e?r.woC:void 0,children:t})}function sY({children:e,onSelect:t,...n}){let i=M(),o=A();return(0,d.jsxs)(s_,{dir:o,className:"tlui-button tlui-button__menu tlui-button__checkbox",onSelect:e=>{t?.(e),(0,r.woC)(e)},...n,children:[(0,d.jsx)("div",{className:"tlui-button__checkbox__indicator",children:(0,d.jsx)(sM,{dir:o,children:(0,d.jsx)(o$,{label:i("ui.checked"),icon:"check",small:!0})})}),e]})}function sG({children:e,visibleOnMobileLayout:t=!1}){let n=sn();return!t&&n<4?null:(0,d.jsx)("kbd",{className:"tlui-kbd",children:su(e).map((e,t)=>(0,d.jsx)("span",{children:e},t))})}var sq=n(69245),sX=Object.defineProperty,sJ=f.forwardRef(sX(function(e,t){let{pressed:n,defaultPressed:r,onPressedChange:i,...o}=e,[s,a]=(0,ik.i)({prop:n,onChange:i,defaultProp:r??!1,caller:"Toggle"});return(0,d.jsx)(iS.sG.button,{type:"button","aria-pressed":s,"data-state":s?"on":"off","data-disabled":e.disabled?"":void 0,...o,ref:t,onClick:(0,ig.mK)(e.onClick,()=>{e.disabled||a(!s)})})},"name",{value:"Toggle",configurable:!0})),sZ=n(1933),sQ=Object.defineProperty,s0=(e,t)=>sQ(e,"name",{value:t,configurable:!0}),s1="ToggleGroup",[s2,s3]=(0,iy.A)(s1,[sq.RG]),s5=(0,sq.RG)(),s6=f.forwardRef(s0(function(e,t){let{type:n,...r}=e;if("single"===n)return(0,d.jsx)(s9,{role:"radiogroup",...r,ref:t});if("multiple"===n)return(0,d.jsx)(s7,{role:"toolbar",...r,ref:t});throw Error(`Missing prop \`type\` expected on \`${s1}\``)},"ToggleGroup")),[s4,s8]=s2(s1),s9=f.forwardRef(s0(function(e,t){let{value:n,defaultValue:r,onValueChange:i=s0(()=>{},"onValueChange"),...o}=e,[s,a]=(0,ik.i)({prop:n,defaultProp:r??"",onChange:i,caller:s1});return(0,d.jsx)(s4,{scope:e.__scopeToggleGroup,type:"single",value:f.useMemo(()=>s?[s]:[],[s]),onItemActivate:a,onItemDeactivate:f.useCallback(()=>a(""),[a]),children:(0,d.jsx)(an,{...o,ref:t})})},"ToggleGroupImplSingle")),s7=f.forwardRef(s0(function(e,t){let{value:n,defaultValue:r,onValueChange:i=s0(()=>{},"onValueChange"),...o}=e,[s,a]=(0,ik.i)({prop:n,defaultProp:r??[],onChange:i,caller:s1}),l=f.useCallback(e=>a((t=[])=>[...t,e]),[a]),c=f.useCallback(e=>a((t=[])=>t.filter(t=>t!==e)),[a]);return(0,d.jsx)(s4,{scope:e.__scopeToggleGroup,type:"multiple",value:s,onItemActivate:l,onItemDeactivate:c,children:(0,d.jsx)(an,{...o,ref:t})})},"ToggleGroupImplMultiple")),[ae,at]=s2(s1),an=f.forwardRef(s0(function(e,t){let{__scopeToggleGroup:n,disabled:r=!1,rovingFocus:i=!0,orientation:o,dir:s,loop:a=!0,...l}=e,c=s5(n),h=(0,sZ.jH)(s),u={dir:h,...l};return(0,d.jsx)(ae,{scope:n,rovingFocus:i,disabled:r,children:i?(0,d.jsx)(sq.bL,{asChild:!0,...c,orientation:o,dir:h,loop:a,children:(0,d.jsx)(iS.sG.div,{...u,ref:t})}):(0,d.jsx)(iS.sG.div,{...u,ref:t})})},"ToggleGroupImpl")),ar="ToggleGroupItem",ai=f.forwardRef(s0(function(e,t){let n=s8(ar,e.__scopeToggleGroup),r=at(ar,e.__scopeToggleGroup),i=s5(e.__scopeToggleGroup),o=n.value.includes(e.value),s=r.disabled||e.disabled,a={...e,pressed:o,disabled:s},l=f.useRef(null);return r.rovingFocus?(0,d.jsx)(sq.q7,{asChild:!0,...i,focusable:!s,active:o,ref:l,children:(0,d.jsx)(ao,{...a,ref:t})}):(0,d.jsx)(ao,{...a,ref:t})},"ToggleGroupItem")),ao=f.forwardRef(s0(function(e,t){let{__scopeToggleGroup:n,value:r,...i}=e,o=s8(ar,n),s={role:"radio","aria-checked":e.pressed,"aria-pressed":void 0},a="single"===o.type?s:void 0;return(0,d.jsx)(sJ,{...a,...i,ref:t,onPressedChange:e=>{e?o.onItemActivate(r):o.onItemDeactivate(r)}})},"ToggleGroupItemImpl")),as=Object.defineProperty,aa=(e,t)=>as(e,"name",{value:t,configurable:!0}),al="Toolbar",[ad,ac]=(0,iy.A)(al,[sq.RG,s3]),ah=(0,sq.RG)(),au=s3(),[ap,af]=ad(al),ag=f.forwardRef(aa(function(e,t){let{__scopeToolbar:n,orientation:r="horizontal",dir:i,loop:o=!0,...s}=e,a=ah(n),l=(0,sZ.jH)(i);return(0,d.jsx)(ap,{scope:n,orientation:r,dir:l,children:(0,d.jsx)(sq.bL,{asChild:!0,...a,orientation:r,dir:l,loop:o,children:(0,d.jsx)(iS.sG.div,{role:"toolbar","aria-orientation":r,dir:l,...s,ref:t})})})},"Toolbar")),am=f.forwardRef(aa(function(e,t){let{__scopeToolbar:n,...r}=e,i=ah(n);return(0,d.jsx)(sq.q7,{asChild:!0,...i,focusable:!e.disabled,children:(0,d.jsx)(iS.sG.button,{type:"button",...r,ref:t})})},"ToolbarButton")),ay=f.forwardRef(aa(function(e,t){let{__scopeToolbar:n,...r}=e,i=af("ToolbarToggleGroup",n),o=au(n);return(0,d.jsx)(s6,{"data-orientation":i.orientation,dir:i.dir,...o,...r,ref:t,rovingFocus:!1})},"ToolbarToggleGroup")),ab=f.forwardRef(aa(function(e,t){let{__scopeToolbar:n,...r}=e,i=au(n),o={__scopeToolbar:e.__scopeToolbar};return(0,d.jsx)(am,{asChild:!0,...o,children:(0,d.jsx)(ai,{...i,...r,ref:t})})},"ToolbarToggleItem"));let ax={horizontal:i8,vertical:i9,grid:i7},aw=f.forwardRef(({children:e,className:t,label:n,orientation:r="horizontal",tooltipSide:i,...o},s)=>{let a=ax[r];return(0,d.jsx)(a,{asChild:!0,tooltipSide:i,children:(0,d.jsx)(ag,{ref:s,...o,className:ip("tlui-toolbar",t),"aria-label":n,orientation:"grid"===r?"horizontal":r,children:e})})}),av=f.forwardRef(({asChild:e,children:t,type:n,isActive:r,tooltip:i,...o},s)=>{let a=(0,d.jsx)(am,{ref:s,asChild:e,draggable:!1,"data-isactive":r,...o,"aria-label":o.title,title:void 0,className:ip("tlui-button",`tlui-button__${n}`,o.className),children:t}),l=i||o.title;return(0,d.jsx)(oa,{content:l,children:a})});function aS({children:e,className:t,type:n,asChild:r,...i}){return(0,d.jsx)(ay,{asChild:r,type:n,...i,role:"radiogroup",className:ip("tlui-toolbar-toggle-group",t),children:e})}function aC({children:e,className:t,type:n,value:r,tooltip:i,...o}){let s=(0,d.jsx)(ab,{...o,title:void 0,className:ip("tlui-button",`tlui-button__${n}`,"tlui-toolbar-toggle-group-item",t),value:r,children:e}),a=i||o.title;return(0,d.jsx)(oa,{content:a,children:s})}function ak({disabled:e=!1,spinner:t=!1,readonlyOk:n=!1,id:i,kbd:o,label:s,icon:a,iconLeft:l,onSelect:c,noClose:h,isSelected:u,onDragStart:p}){let{type:g,sourceId:m}=si(),y=M(),b=A(),[x,w]=(0,f.useState)(!1);if(sl()&&!n)return null;let v=fs(s,g),S=o?sp(o):void 0,C=v?y(v):void 0,k=C&&S?`${C} ${S}`:C;switch(g){case"menu":return(0,d.jsx)(sV,{children:(0,d.jsxs)(od,{type:"menu","data-testid":`${m}.${i}`,disabled:e,onClick:e=>{h&&(0,r.woC)(e),x?w(!1):c(m)},children:[l&&(0,d.jsx)(oH,{icon:l,small:!0}),(0,d.jsx)(oc,{children:C}),o&&(0,d.jsx)(sG,{children:o})]})});case"context-menu":if(e)return null;return(0,d.jsxs)(sa.q7,{dir:b,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${m}.${i}`,onPointerUp:e=>{0!==e.button&&(0,r.woC)(e)},onSelect:e=>{h&&(0,r.woC)(e),x?w(!1):c(m)},children:[(0,d.jsx)("span",{className:"tlui-button__label",draggable:!1,children:C}),l&&(0,d.jsx)(oH,{icon:l,small:!0}),o&&(0,d.jsx)(sG,{children:o}),t&&(0,d.jsx)(sf,{})]});case"small-icons":case"icons":return(0,d.jsx)(av,{"aria-pressed":void 0===u?void 0:u?"true":"false","data-testid":`${m}.${i}`,isActive:u,type:"icon",title:k,disabled:e,onClick:()=>c(m),children:(0,d.jsx)(oH,{icon:a,small:!0})});case"keyboard-shortcuts":if(!o)return console.warn(`Menu item '${s}' isn't shown in the keyboard shortcuts dialog because it doesn't have a keyboard shortcut.`),null;return(0,d.jsxs)("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${m}.${i}`,children:[(0,d.jsx)("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:C}),(0,d.jsx)("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:(0,d.jsx)(sG,{visibleOnMobileLayout:!0,children:o})})]});case"helper-buttons":return(0,d.jsxs)(od,{type:"low","data-testid":`${m}.${i}`,onClick:()=>c(m),children:[(0,d.jsx)(oH,{icon:a}),(0,d.jsx)(oc,{children:C})]});case"toolbar":if(p)return(0,d.jsx)(aP,{id:i,icon:a,onSelect:c,onDragStart:p,labelStr:C,titleStr:k,disabled:e,isSelected:u});return(0,d.jsx)(av,{"aria-label":C,"aria-pressed":u?"true":"false","data-testid":`tools.${i}`,"data-value":i,disabled:e,onClick:()=>c("toolbar"),onTouchStart:e=>{(0,r.woC)(e),c("toolbar")},title:k,type:"tool",children:(0,d.jsx)(oH,{icon:a})});case"toolbar-overflow":if(p)return(0,d.jsx)(aP,{id:i,icon:a,onSelect:c,onDragStart:p,labelStr:C,titleStr:k,disabled:e,isSelected:u,overflow:!0});return(0,d.jsx)(av,{"aria-label":C,"aria-pressed":u?"true":"false",isActive:u,"data-testid":`tools.more.${i}`,"data-value":i,disabled:e,onClick:()=>c("toolbar"),title:k,type:"icon",children:(0,d.jsx)(oH,{icon:a})});default:throw(0,r.h6G)(g)}}function aP({id:e,labelStr:t,titleStr:n,disabled:i,isSelected:o,icon:s,onSelect:a,onDragStart:l,overflow:c}){let h,u=(h=(0,r.hGv)(),(0,f.useMemo)(()=>{let e={name:"idle"};return{onPointerDown:function(t){e={name:"pointing",screenSpaceStart:{x:t.clientX,y:t.clientY}},t.currentTarget.setPointerCapture(t.pointerId)},onPointerMove:function(t){if(!t.isSpecialRedispatchedEvent&&"pointing"===e.name&&r.l2P.Dist2(e.screenSpaceStart,{x:t.clientX,y:t.clientY})>(h.getInstanceState().isCoarsePointer?h.options.uiCoarseDragDistanceSquared:h.options.uiDragDistanceSquared)){let n=e.screenSpaceStart;e={name:"dragging",screenSpaceStart:n},h.run(()=>{h.setCurrentTool("select"),h.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...(0,r.yGT)(h,t),point:n}),h.selectNone(),l?.("toolbar",{type:"pointer",target:"canvas",name:"pointer_move",...(0,r.yGT)(h,t),point:n}),on(),h.getContainer().focus()})}},onPointerUp:function(e){e.isSpecialRedispatchedEvent||(e.currentTarget.releasePointerCapture(e.pointerId),h.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...(0,r.yGT)(h,e)}))},onClick:function(){return"dragging"===e.name||"dragged"===e.name?(e={name:"idle"},!0):(e={name:"idle"},a?.("toolbar"),!1)}}},[l,h,a]));return c?(0,d.jsx)(av,{"aria-label":t,"aria-pressed":o?"true":"false",isActive:o,className:"tlui-button-grid__button","data-testid":`tools.more.${e}`,"data-value":e,disabled:i,title:n,type:"icon",...u,children:(0,d.jsx)(oH,{icon:s})}):(0,d.jsx)(av,{"aria-label":t,"aria-pressed":o?"true":"false","data-testid":`tools.${e}`,"data-value":e,disabled:i,onTouchStart:e=>{(0,r.woC)(e),a("toolbar")},title:n,type:"tool",...u,children:(0,d.jsx)(oH,{icon:s})})}function aT({actionId:e="",...t}){let n=fo()[e];return n?(0,d.jsx)(ak,{...n,...t}):null}function aE({id:e,label:t,className:n,children:r}){let i=si(),{orientation:o}=i4(),s=M(),a=A(),l=fs(t,i.type),c=l?s(l):void 0;switch(i.type){case"menu":return(0,d.jsx)(sW,{className:n,"data-testid":`${i.sourceId}-group.${e}`,children:r});case"context-menu":return(0,d.jsx)("div",{dir:a,className:ip("tlui-menu__group",n),"data-testid":`${i.sourceId}-group.${e}`,children:r});case"keyboard-shortcuts":return(0,d.jsxs)("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${i.sourceId}-group.${e}`,children:[(0,d.jsx)("h2",{className:"tlui-shortcuts-dialog__group__title",children:c}),(0,d.jsx)("div",{className:"tlui-shortcuts-dialog__group__content",children:r})]});case"toolbar":return(0,d.jsx)("horizontal"===o?i8:i9,{className:"tlui-main-toolbar__group","data-testid":`${i.sourceId}-group.${e}`,children:r});case"toolbar-overflow":return(0,d.jsx)(i7,{className:"tlui-main-toolbar__group","data-testid":`${i.sourceId}-group.${e}`,children:r});default:return r}}let aI=(0,f.createContext)(null);function a_({context:e,children:t}){let n=(0,f.useContext)(aI),i=sF(),o=(0,r.fpl)("dialogs",[]),s=(0,f.useMemo)(()=>({dialogs:o,addDialog(t){let n=t.id??(0,r.NF7)();return o.update(e=>[...e.filter(e=>e.id!==t.id),{...t,id:n}]),i("open-menu",{source:"dialog",id:n}),r.NlK.addOpenMenu(n,e),n},removeDialog(t){let n=o.get().find(e=>e.id===t);return n&&(n.onClose?.(),i("close-menu",{source:"dialog",id:t}),r.NlK.deleteOpenMenu(t,e),o.update(e=>e.filter(e=>e!==n))),t},clearDialogs(){let t=o.get();0!==t.length&&(t.forEach(t=>{t.onClose?.(),i("close-menu",{source:"dialog",id:t.id}),r.NlK.deleteOpenMenu(t.id,e)}),o.set([]))}}),[i,o,e]);return n?(0,d.jsx)(d.Fragment,{children:t}):(0,d.jsx)(aI.Provider,{value:s,children:t})}function aM(){let e=(0,f.useContext)(aI);if(!e)throw Error("useDialogs must be used within a DialogsProvider");return e}var aA=n(47650),aj=n(76094),aO=n(17347),aD=Object.defineProperty,aL=(e,t)=>aD(e,"name",{value:t,configurable:!0}),aR="ToastProvider",[aF,az,aN]=(0,aj.N)("Toast"),[a$,aB]=(0,iy.A)("Toast",[aN]),[aH,aU]=a$(aR),aK=aL(e=>{let{__scopeToast:t,label:n="Notification",duration:r=5e3,swipeDirection:i="right",swipeThreshold:o=50,announcerContainer:s,children:a}=e,[l,c]=f.useState(null),[h,u]=f.useState(0),p=f.useRef(!1);return n.trim()||console.error(`Invalid prop \`label\` supplied to \`${aR}\`. Expected non-empty \`string\`.`),(0,d.jsx)(aF.Provider,{scope:t,children:(0,d.jsx)(aH,{scope:t,label:n,duration:r,swipeDirection:i,swipeThreshold:o,toastCount:h,viewport:l,onViewportChange:c,onToastAdd:f.useCallback(()=>u(e=>e+1),[]),onToastRemove:f.useCallback(()=>u(e=>e-1),[]),isClosePausedRef:p,announcerContainer:s,children:a})})},"ToastProvider"),aW=["F8"],aV="toast.viewportPause",aY="toast.viewportResume",aG=f.forwardRef(aL(function(e,t){let{__scopeToast:n,hotkey:r=aW,label:i="Notifications ({hotkey})",...o}=e,s=aU("ToastViewport",n),a=az(n),l=f.useRef(null),c=f.useRef(null),h=f.useRef(null),u=f.useRef(null),p=(0,im.s)(t,u,s.onViewportChange),g=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),m=s.toastCount>0;f.useEffect(()=>{let e=aL(e=>{0!==r.length&&r.every(t=>e[t]||e.code===t)&&u.current?.focus()},"handleKeyDown");return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[r]),f.useEffect(()=>{let e=l.current,t=u.current;if(m&&e&&t){let n=aL(()=>{if(!s.isClosePausedRef.current){let e=new CustomEvent(aV);t.dispatchEvent(e),s.isClosePausedRef.current=!0}},"handlePause"),r=aL(()=>{if(s.isClosePausedRef.current){let e=new CustomEvent(aY);t.dispatchEvent(e),s.isClosePausedRef.current=!1}},"handleResume"),i=aL(t=>{e.contains(t.relatedTarget)||r()},"handleFocusOutResume"),o=aL(()=>{e.contains(document.activeElement)||r()},"handlePointerLeaveResume");return e.addEventListener("focusin",n),e.addEventListener("focusout",i),e.addEventListener("pointermove",n),e.addEventListener("pointerleave",o),window.addEventListener("blur",n),window.addEventListener("focus",r),()=>{e.removeEventListener("focusin",n),e.removeEventListener("focusout",i),e.removeEventListener("pointermove",n),e.removeEventListener("pointerleave",o),window.removeEventListener("blur",n),window.removeEventListener("focus",r)}}},[m,s.isClosePausedRef]);let y=f.useCallback(({tabbingDirection:e})=>{let t=a().map(t=>{let n=t.ref.current,r=[n,...ln(n)];return"forwards"===e?r:r.reverse()});return("forwards"===e?t.reverse():t).flat()},[a]);return f.useEffect(()=>{let e=u.current;if(e){let t=aL(t=>{let n=t.altKey||t.ctrlKey||t.metaKey;if("Tab"===t.key&&!n){let n=document.activeElement,r=t.shiftKey;if(t.target===e&&r)return void c.current?.focus();let i=y({tabbingDirection:r?"backwards":"forwards"}),o=i.findIndex(e=>e===n);lr(i.slice(o+1))?t.preventDefault():r?c.current?.focus():h.current?.focus()}},"handleKeyDown");return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t)}},[a,y]),(0,d.jsxs)(ib.lg,{ref:l,role:"region","aria-label":i.replace("{hotkey}",g),tabIndex:-1,style:{pointerEvents:m?void 0:"none"},children:[m&&(0,d.jsx)(aq,{ref:c,onFocusFromOutsideViewport:()=>{lr(y({tabbingDirection:"forwards"}))}}),(0,d.jsx)(aF.Slot,{scope:n,children:(0,d.jsx)(iS.sG.ol,{tabIndex:-1,...o,ref:p})}),m&&(0,d.jsx)(aq,{ref:h,onFocusFromOutsideViewport:()=>{lr(y({tabbingDirection:"backwards"}))}})]})},"ToastViewport")),aq=f.forwardRef(aL(function(e,t){let{__scopeToast:n,onFocusFromOutsideViewport:r,...i}=e,o=aU("ToastFocusProxy",n);return(0,d.jsx)(iI,{tabIndex:0,...i,ref:t,style:{position:"fixed"},onFocus:e=>{let t=e.relatedTarget;o.viewport?.contains(t)||r()}})},"ToastFocusProxy")),aX="Toast",aJ=f.forwardRef(aL(function(e,t){let{forceMount:n,open:r,defaultOpen:i,onOpenChange:o,...s}=e,[a,l]=(0,ik.i)({prop:r,defaultProp:i??!0,onChange:o,caller:aX});return(0,d.jsx)(iv.C,{present:n||a,children:(0,d.jsx)(a0,{open:a,...s,ref:t,onClose:()=>l(!1),onPause:(0,aO.c)(e.onPause),onResume:(0,aO.c)(e.onResume),onSwipeStart:(0,ig.mK)(e.onSwipeStart,e=>{e.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:(0,ig.mK)(e.onSwipeMove,e=>{let{x:t,y:n}=e.detail.delta;e.currentTarget.setAttribute("data-swipe","move"),e.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${t}px`),e.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${n}px`)}),onSwipeCancel:(0,ig.mK)(e.onSwipeCancel,e=>{e.currentTarget.setAttribute("data-swipe","cancel"),e.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),e.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),e.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),e.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:(0,ig.mK)(e.onSwipeEnd,e=>{let{x:t,y:n}=e.detail.delta;e.currentTarget.setAttribute("data-swipe","end"),e.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),e.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),e.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${t}px`),e.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${n}px`),l(!1)})})})},"Toast")),[aZ,aQ]=a$(aX,{onClose(){}}),a0=f.forwardRef(aL(function(e,t){let{__scopeToast:n,type:r="foreground",duration:i,open:o,onClose:s,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:h,onSwipeMove:u,onSwipeCancel:p,onSwipeEnd:g,...m}=e,y=aU(aX,n),b=az(n),[x,w]=f.useState(null),v=(0,im.s)(t,w),S=f.useRef(null),C=f.useRef(null),k=i||y.duration,P=f.useRef(0),T=f.useRef(k),E=f.useRef(0),{onToastAdd:I,onToastRemove:_}=y,M=(0,aO.c)(()=>{x?.contains(document.activeElement)&&y.viewport?.focus(),s()}),A=f.useCallback(e=>{e&&e!==1/0&&(window.clearTimeout(E.current),P.current=new Date().getTime(),E.current=window.setTimeout(M,e))},[M]);f.useEffect(()=>{let e=y.viewport;if(e){let t=aL(()=>{A(T.current),c?.()},"handleResume"),n=aL(()=>{let e=new Date().getTime()-P.current;T.current=T.current-e,window.clearTimeout(E.current),l?.()},"handlePause");return e.addEventListener(aV,n),e.addEventListener(aY,t),()=>{e.removeEventListener(aV,n),e.removeEventListener(aY,t)}}},[y.viewport,k,l,c,A]),f.useEffect(()=>{o&&!y.isClosePausedRef.current&&A(k)},[o,k,y.isClosePausedRef,A]),f.useEffect(()=>()=>{window.clearTimeout(E.current)},[]),f.useEffect(()=>(I(),()=>_()),[I,_]);let j=f.useMemo(()=>x?a8(x):null,[x]);return y.viewport?(0,d.jsxs)(d.Fragment,{children:[j&&(0,d.jsx)(a1,{__scopeToast:n,role:"status","aria-live":"foreground"===r?"assertive":"polite",children:j}),(0,d.jsx)(aZ,{scope:n,onClose:M,children:aA.createPortal((0,d.jsx)(aF.ItemSlot,{scope:n,children:(0,d.jsx)(ib.bL,{asChild:!0,onEscapeKeyDown:(0,ig.mK)(a,e=>{b().some(t=>t.ref.current?.contains(e.target))||M()}),children:(0,d.jsx)(iS.sG.li,{tabIndex:0,"data-state":o?"open":"closed","data-swipe-direction":y.swipeDirection,...m,ref:v,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:(0,ig.mK)(e.onKeyDown,e=>{"Escape"===e.key&&(a?.(e.nativeEvent),e.nativeEvent.defaultPrevented||M())}),onPointerDown:(0,ig.mK)(e.onPointerDown,e=>{0===e.button&&(S.current={x:e.clientX,y:e.clientY})}),onPointerMove:(0,ig.mK)(e.onPointerMove,e=>{if(!S.current)return;let t=e.clientX-S.current.x,n=e.clientY-S.current.y,r=!!C.current,i=["left","right"].includes(y.swipeDirection),o=["left","up"].includes(y.swipeDirection)?Math.min:Math.max,s=i?o(0,t):0,a=i?0:o(0,n),l="touch"===e.pointerType?10:2,d={x:s,y:a},c={originalEvent:e,delta:d};r?(C.current=d,a9("toast.swipeMove",u,c,{discrete:!1})):a7(d,y.swipeDirection,l)?(C.current=d,a9("toast.swipeStart",h,c,{discrete:!1}),e.target.setPointerCapture(e.pointerId)):(Math.abs(t)>l||Math.abs(n)>l)&&(S.current=null)}),onPointerUp:(0,ig.mK)(e.onPointerUp,e=>{let t=C.current,n=e.target;if(n.hasPointerCapture(e.pointerId)&&n.releasePointerCapture(e.pointerId),C.current=null,S.current=null,t){let n=e.currentTarget,r={originalEvent:e,delta:t};a7(t,y.swipeDirection,y.swipeThreshold)?a9("toast.swipeEnd",g,r,{discrete:!0}):a9("toast.swipeCancel",p,r,{discrete:!0}),n.addEventListener("click",e=>e.preventDefault(),{once:!0})}})})})}),y.viewport)})]}):null},"ToastImpl")),a1=aL(e=>{let{__scopeToast:t,children:n,...r}=e,i=aU(aX,t),[o,s]=f.useState(!1),[a,l]=f.useState(!1);return le(()=>s(!0)),f.useEffect(()=>{let e=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(e)},[]),a?null:(0,d.jsx)(ou.Z,{asChild:!0,container:i.announcerContainer||void 0,children:(0,d.jsx)(iI,{...r,children:o&&(0,d.jsxs)(d.Fragment,{children:[i.label," ",n]})})})},"ToastAnnounce"),a2=f.forwardRef(aL(function(e,t){let{__scopeToast:n,...r}=e;return(0,d.jsx)(iS.sG.div,{...r,ref:t})},"ToastTitle")),a3=f.forwardRef(aL(function(e,t){let{__scopeToast:n,...r}=e;return(0,d.jsx)(iS.sG.div,{...r,ref:t})},"ToastDescription")),a5=f.forwardRef(aL(function(e,t){let{altText:n,...r}=e;return n.trim()?(0,d.jsx)(a4,{altText:n,asChild:!0,children:(0,d.jsx)(a6,{...r,ref:t})}):(console.error("Invalid prop `altText` supplied to `ToastAction`. Expected non-empty `string`."),null)},"ToastAction")),a6=f.forwardRef(aL(function(e,t){let{__scopeToast:n,...r}=e,i=aQ("ToastClose",n);return(0,d.jsx)(a4,{asChild:!0,children:(0,d.jsx)(iS.sG.button,{type:"button",...r,ref:t,onClick:(0,ig.mK)(e.onClick,i.onClose)})})},"ToastClose")),a4=f.forwardRef(aL(function(e,t){let{__scopeToast:n,altText:r,...i}=e;return(0,d.jsx)(iS.sG.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...i,ref:t})},"ToastAnnounceExclude"));function a8(e){let t=[];return Array.from(e.childNodes).forEach(e=>{if(e.nodeType===e.TEXT_NODE&&e.textContent&&t.push(e.textContent),lt(e)){let n=e.ariaHidden||e.hidden||"none"===e.style.display,r=""===e.dataset.radixToastAnnounceExclude;if(!n)if(r){let n=e.dataset.radixToastAnnounceAlt;n&&t.push(n)}else t.push(...a8(e))}}),t}function a9(e,t,n,{discrete:r}){let i=n.originalEvent.currentTarget,o=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n});t&&i.addEventListener(e,t,{once:!0}),r?(0,iS.hO)(i,o):i.dispatchEvent(o)}aL(a8,"getAnnounceTextContent"),aL(a9,"handleAndDispatchCustomEvent");var a7=aL((e,t,n=0)=>{let r=Math.abs(e.x),i=Math.abs(e.y),o=r>i;return"left"===t||"right"===t?o&&r>n:!o&&i>n},"isDeltaInDirection");function le(e=()=>{}){let t=(0,aO.c)(e);(0,iP.N)(()=>{let e=0,n=0;return e=window.requestAnimationFrame(()=>n=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(e),window.cancelAnimationFrame(n)}},[t])}function lt(e){return e.nodeType===e.ELEMENT_NODE}function ln(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:aL(e=>{let t="INPUT"===e.tagName&&"hidden"===e.type;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;n.nextNode();)t.push(n.currentNode);return t}function lr(e){let t=document.activeElement;return e.some(e=>e===t||(e.focus(),document.activeElement!==t))}aL(le,"useNextFrame"),aL(lt,"isHTMLElement"),aL(ln,"getTabbableCandidates"),aL(lr,"focusFirst");let li=(0,f.createContext)(null);function lo({children:e}){let t=(0,r.fpl)("toasts",[]),n=(0,f.useContext)(li),i=(0,f.useMemo)(()=>({toasts:t,addToast(e){let n=e.id??(0,r.NF7)();return t.update(t=>[...t.filter(t=>t.id!==e.id),{...e,id:n}]),n},removeToast:e=>(t.update(t=>t.filter(t=>t.id!==e)),e),clearToasts(){t.set([])}}),[t]);return n?(0,d.jsx)(d.Fragment,{children:e}):(0,d.jsx)(aK,{children:(0,d.jsx)(li.Provider,{value:i,children:e})})}function ls(){let e=(0,f.useContext)(li);if(!e)throw Error("useToasts must be used within a ToastsProvider");return e}function la(e){return new Promise(t=>{let{allowMultiple:n=!0,mimeTypes:i=[],document:o=(0,r.jLo)()}=e||{},s=o.createElement("input");function a(){s.removeEventListener("change",l),s.removeEventListener("cancel",d),s.remove()}async function l(e){let n=e.target.files;if(!n||0===n.length){t([]),a();return}let r=Array.from(n);s.value="",t(r),a()}function d(){t([]),a()}s.type="file",s.accept=i?.join(","),s.multiple=n,s.style.display="none",o.body.appendChild(s),s.addEventListener("cancel",d),s.addEventListener("change",l),s?.click()})}var ll=n(4467);let ld="web image/vnd.tldraw+png",lc={png:ld},lh={[ld]:"image/png"};async function lu(e,t,n){let r=n.point??("point"in t?t.point:void 0);if(e.options.onBeforePasteFromClipboard){let i=await e.options.onBeforePasteFromClipboard({editor:e,content:t,source:n.source,point:r});if(!1===i)return;null!=i&&(t=i)}return e.putExternalContent(t)}async function lp(e,t,n,r,i="native-event"){let o=t.map(e=>e instanceof File?e:new File([e],"tldrawFile",{type:e.type}));e.markHistoryStoppingPoint("paste"),await lu(e,{type:"files",files:o,point:n,sources:r},{source:i,point:n})}async function lf(e,t,n,r,i="native-event"){return e.markHistoryStoppingPoint("paste"),await lu(e,{type:"url",point:n,url:t,sources:r},{source:i,point:n})}let lg=[ld,"image/png","image/jpeg","image/webp","image/svg+xml"];function lm(e){let t=(0,r.jLo)().implementation.createHTMLDocument("");return t.documentElement.innerHTML=e.trim(),t.body.textContent||t.body.innerText||""}function ly(e){if(!e.includes("<iframe"))return null;let t=new DOMParser().parseFromString(e,"text/html").querySelector("iframe");if(!t)return null;let n=t.getAttribute("src");if(!n||!lb(n))return null;let r=parseInt(t.getAttribute("width")||"",10),i=parseInt(t.getAttribute("height")||"",10),o=NaN,s=NaN,a=t.getAttribute("style");if(a){let e=a.match(/\bwidth:\s*(\d+)px/),t=a.match(/\bheight:\s*(\d+)px/);e&&(o=parseInt(e[1],10)),t&&(s=parseInt(t[1],10))}return{src:n,width:r||o||425,height:i||s||350}}function lb(e){try{let t=new URL(e);return"http:"===t.protocol||"https:"===t.protocol}catch{return!1}}function lx(e){return e.menus.hasAnyOpenMenus()||(0,r.ghB)(!1,e.getContainerDocument())}let lw=(e,t,n,i,o="native-event")=>{let s=(e=>{let t=e.split(/[\n\s]/);for(let e of t)try{let t=new URL(e);if("http:"!==t.protocol&&"https:"!==t.protocol)return}catch{return}return(0,r.sbv)(t)})(t);if(s)for(let t of s)lf(e,t,n,i,o);else if(lb(t))lf(e,t,n,i,o);else/^<svg/.test(t)?(e.markHistoryStoppingPoint("paste"),lu(e,{type:"svg-text",text:t,point:n,sources:i},{source:o,point:n})):(e.markHistoryStoppingPoint("paste"),lu(e,{type:"text",text:t,point:n,sources:i},{source:o,point:n}))};async function lv(e,t,n){if(null!==e.getEditingShapeId())return;if(!t)throw Error("No clipboard data");let r=[];for(let e of Object.values(t.items))switch(e.kind){case"file":r.push({type:"file",source:new Promise(t=>t(e.getAsFile()))});break;case"string":"text/html"===e.type?r.push({type:"html",source:new Promise(t=>e.getAsString(t))}):"text/plain"===e.type?r.push({type:"text",source:new Promise(t=>e.getAsString(t))}):r.push({type:e.type,source:new Promise(t=>e.getAsString(t))})}return await lC(e,r,n,"native-event")}async function lS({editor:e,clipboardItems:t,point:n,fallbackFiles:i,clipboardPasteSource:o}){let s=[];for(let e of t){let t=lg.filter(t=>e.types.includes(t));t.length>0&&s.push({type:"blob",source:(async()=>{for(let n of t){let t=await e.getType(n);if(0!==t.size)return r.SmQ.rewriteMimeType(t,(0,r.g50)(lh,n)??n)}return null})()}),e.types.includes("text/html")&&s.push({type:"html",source:(async()=>{let t=await e.getType("text/html");return await r.SmQ.blobToText(t)})()}),e.types.includes("text/uri-list")&&s.push({type:"url",source:(async()=>{let t=await e.getType("text/uri-list");return await r.SmQ.blobToText(t)})()}),e.types.includes("text/plain")&&s.push({type:"text",source:(async()=>{let t=await e.getType("text/plain");return await r.SmQ.blobToText(t)})()})}return i?.length&&1===s.length&&"text"===s[0].type?(s.pop(),s.push(...i.map(e=>({type:"file",source:Promise.resolve(e)})))):i?.length&&0===s.length&&s.push(...i.map(e=>({type:"file",source:Promise.resolve(e)}))),await lC(e,s,n,o)}async function lC(e,t,n,i){let o=await Promise.all(t.filter(e=>"file"!==e.type&&"blob"!==e.type).map(e=>new Promise(t=>{e.source.then(n=>{let r=n.match(/<div data-tldraw[^>]*>(.*)<\/div>/)?.[1];if(r)try{let e;try{e=JSON.parse(r)}catch{let n=ll.decompressFromBase64(r);if(null===n)return void t({type:"error",data:null,reason:"found tldraw data comment but could not parse"});e=JSON.parse(n)}if("application/tldraw"!==e.type)return void t({type:"error",data:e,reason:`found tldraw data comment but JSON was of a different type: ${e.type}`});if(3===e.version)try{let n=JSON.parse(ll.decompressFromBase64(e.data.otherCompressed)||"{}"),r={assets:e.data.assets||[],...n};t({type:"tldraw",data:r});return}catch(n){t({type:"error",data:e,reason:`failed to decompress version 2 clipboard data: ${n}`});return}if(2===e.version)t({type:"tldraw",data:e.data});else{if("string"==typeof e.data)return void t({type:"error",data:e,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});t({type:"tldraw",data:e.data});return}}catch{t({type:"error",data:r,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if("html"===e.type)return void t({type:"text",data:n,subtype:"html"});if("url"===e.type)return void t({type:"text",data:n,subtype:"url"});try{let e=JSON.parse(n);if("excalidraw/clipboard"===e.type)return void t({type:"excalidraw",data:e});return void t({type:"text",data:n,subtype:"json"})}catch{t({type:"text",data:n,subtype:"text"});return}}t({type:"error",data:n,reason:"unhandled case"})}).catch(e=>{t({type:"error",data:null,reason:`error reading clipboard data: ${e}`})})}))),s=t.filter(e=>"file"===e.type||"blob"===e.type);if(s.length){if(s.length>e.options.maxFilesAtOnce)throw Error("Too many files");let t=(0,r.oE7)(await Promise.all(s.map(e=>e.source)));return await lp(e,t,n,o,i)}for(let t of o)if("tldraw"===t.type){e.markHistoryStoppingPoint("paste"),lu(e,{type:"tldraw",content:t.data,point:n},{source:i,point:n});return}for(let t of o)if("excalidraw"===t.type){e.markHistoryStoppingPoint("paste"),lu(e,{type:"excalidraw",content:t.data,point:n},{source:i,point:n});return}for(let t of o){if("text"===t.type&&"html"===t.subtype){let r=new DOMParser().parseFromString(t.data,"text/html").querySelector("body"),s=ly(t.data);if(s){e.markHistoryStoppingPoint("paste"),e.putExternalContent({type:"embed",url:s.src,point:n,embed:{width:s.width,height:s.height,doesResize:!0}});return}if(r&&1===Array.from(r.children).filter(e=>1===e.nodeType).length&&r.firstElementChild&&"A"===r.firstElementChild.tagName&&r.firstElementChild.hasAttribute("href")&&""!==r.firstElementChild.getAttribute("href"))return void lw(e,r.firstElementChild.getAttribute("href"),n,o,i);if(!o.some(e=>"text"===e.type&&"html"!==e.subtype)&&t.data.trim()&&lm(t.data))return void lw(e,lm(t.data),n,o,i);if(o.some(e=>"text"===e.type&&"html"!==e.subtype)){let r=lm(t.data)??"";if(r){e.markHistoryStoppingPoint("paste"),lu(e,{type:"text",text:r,html:t.data,point:n,sources:o},{source:i,point:n});return}}}if("text"===t.type&&"text"===t.subtype){let r=ly(t.data);if(r){e.markHistoryStoppingPoint("paste"),e.putExternalContent({type:"embed",url:r.src,point:n,embed:{width:r.width,height:r.height,doesResize:!0}});return}}}for(let t of o)if("text"===t.type&&"url"===t.subtype)return void lf(e,t.data,n,o,i);for(let t of o)if("text"===t.type&&"text"===t.subtype&&t.data.trim())return void lw(e,t.data,n,o,i)}async function lk(e,t={operation:"copy",source:"menu"}){let n=e.getContainerWindow().navigator,i=await e.resolveAssetsInContent(e.getContentFromCurrentPage(e.getSelectedShapeIds()));if(!i)return n?.clipboard?.writeText?.(""),!0;if(e.options.onBeforeCopyToClipboard){let n=await e.options.onBeforeCopyToClipboard({editor:e,content:i,...t});if(!1===n)return!1;null!=n&&(i=n)}let{assets:o,...s}=i,a=JSON.stringify({type:"application/tldraw",kind:"content",version:3,data:{assets:o||[],otherCompressed:ll.compressToBase64(JSON.stringify(s))}});if(void 0===n)return!0;let l=i.shapes.map(t=>e.getShapeUtil(t).getText(t)).filter(r.O9V);if(n.clipboard?.write){let t=new Blob([`<div data-tldraw>${a}</div>`],{type:"text/html"}),r=l.join(" ");""===r&&(r=" ");let i=e.getContainerWindow().ClipboardItem;n.clipboard.write([new i({"text/html":t,"text/plain":new Blob([r],{type:"text/plain"})})])}else n.clipboard?.writeText&&n.clipboard.writeText(`<div data-tldraw>${a}</div>`);return!0}let lP={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",svg:"text/plain"};async function lT(e){await navigator.clipboard?.writeText?.(await e())}let lE=(0,f.createContext)([]);function lI(){let e,t,n,i,o,s,a,l,d=(0,r.frr)(),{addToast:c,removeToast:h,clearToasts:u}=ls(),{addDialog:p,clearDialogs:g,removeDialog:m}=aM(),y=M(),b=(e=(0,r.frr)(),t=(0,f.useRef)(null),n=(0,f.useRef)(null),(0,f.useCallback)(async function(){(0,r.vAR)(e,"usePrint: editor is required");let i=e.getContainerDocument(),o=e.getContainerWindow(),s=i.createElement("div"),a=i.createElement("style"),l=(e,t)=>{e&&(e.innerHTML=""),t&&i.head.contains(t)&&i.head.removeChild(t),e&&i.body.contains(e)&&i.body.removeChild(e)};l(t.current,n.current),t.current=s,n.current=a;let d=`tl-print-surface-${(0,r.NF7)()}`;s.className=d,a.innerHTML=`
13
- .${d} {
14
- display: none;
15
- }
16
-
17
- .${d} svg {
18
- max-width: 100%;
19
- height: 100%;
20
- display: block;
21
- }
22
-
23
- @media print {
24
- html, body {
25
- min-height: 100%;
26
- height: 100%;
27
- margin: 0;
28
- }
29
-
30
- body {
31
- position: relative;
32
- }
33
-
34
- body > * {
35
- display: none;
36
- }
37
-
38
- .tldraw__editor {
39
- display: none;
40
- }
41
-
42
- .${d} {
43
- display: block !important;
44
- background: white;
45
- min-height: 100%;
46
- height: 100%;
47
- max-width: 100%;
48
- }
49
-
50
- .${d}__item {
51
- padding: 10mm;
52
- display: flex;
53
- min-height: 100%;
54
- flex-direction: column;
55
- page-break-after: always;
56
- position: relative;
57
- overflow: hidden;
58
- height: 100%;
59
- }
60
-
61
- .${d}__item__main {
62
- flex: 1;
63
- display: flex;
64
- align-items: center;
65
- justify-content: center;
66
- max-height: 100%;
67
- }
68
-
69
- .${d}__item__header {
70
- display: none;
71
- }
72
-
73
- .${d}__item__footer {
74
- display: none;
75
- text-align: right;
76
- }
77
-
78
- .${d}__item__footer__hide {
79
- display: none;
80
- }
81
-
82
-
83
- }
84
-
85
- `;let c=()=>{i.head.appendChild(a),i.body.appendChild(s)},h=()=>{e.once("tick",()=>{l(s,a)})};function u(e,t,n){try{s.innerHTML+=`<div class="${d}__item">
86
- <div class="${d}__item__header">
87
- ${e.replace(/</g,"&lt;").replace(/>/g,"&gt;")}
88
- </div>
89
- <div class="${d}__item__main">
90
- ${n}
91
- </div>
92
- <div class="${d}__item__footer ${d}__item__footer__${t?"":"hide"}">
93
- ${t??""}
94
- </div>
95
- </div>`}catch(e){console.error(e)}}function p(){r.YZA.isChromeForIos?(c(),o.print()):r.YZA.isSafari?(c(),i.execCommand("print",!1)):o.print()}o.addEventListener("beforeprint",c),o.addEventListener("afterprint",h);let f=e.getSelectedShapeIds(),g=e.getCurrentPageId(),m=e.getPages(),y={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){let t=await e.getSvgString(f,y);if(t){let e=m.find(e=>e.id===g);u(`tldraw \u2014 ${e?.name}`,null,t.svg),p()}}else if(1){let t=e.getCurrentPage(),n=await e.getSvgString(e.getSortedChildIdsForParent(t.id),y);n&&(u(`tldraw \u2014 ${t.name}`,null,n.svg),p())}else{for(let t=0;t<m.length;t++){let n=m[t],r=await e.getSvgString(e.getSortedChildIdsForParent(n.id),y);r&&u(`tldraw \u2014 ${n.name}`,`${t}/${m.length}`,r.svg)}p()}o.removeEventListener("beforeprint",c),o.removeEventListener("afterprint",h)},[e])),{cut:x,copy:w,paste:v}=(i=(0,r.frr)(),o=sF(),s=(0,f.useCallback)(async function(e){(0,r.vAR)(i,"editor is required for copy"),0===i.getSelectedShapeIds().length||await lk(i,{operation:"copy",source:"menu"})&&o("copy",{source:e})},[i,o]),a=(0,f.useCallback)(async function(e){!i||0===i.getSelectedShapeIds().length||await lk(i,{operation:"cut",source:"menu"})&&(i.deleteShapes(i.getSelectedShapeIds()),o("cut",{source:e}))},[i,o]),{copy:s,cut:a,paste:l=(0,f.useCallback)(async function(e,t,n){if(!i||null!==i.getEditingShapeId())return;let r=i.getContainerWindow();if(Array.isArray(e)&&e[0]instanceof r.ClipboardItem){if(i.options.onClipboardPasteRaw?.({editor:i,source:"clipboard-read",clipboardItems:e,point:n})===!1)return void o("paste",{source:"menu"});lS({editor:i,clipboardItems:e,point:n,clipboardPasteSource:"clipboard-read"}),o("paste",{source:"menu"})}else r.navigator.clipboard.read().then(e=>{l(e,t,n)})},[i,o])}),S=function(){let e=(0,r.frr)(),{addToast:t}=ls(),n=M();return(0,f.useCallback)((i,o="svg")=>{(0,r.vAR)(e,"useCopyAs: editor is required"),(function(e,t,n){if(!navigator.clipboard)return Promise.reject(Error("Copy not supported"));if("json"===n.format){let n=JSON.stringify(e.getContentFromCurrentPage(t),null," ");return navigator.clipboard.writeText(n)}let i={...n,format:n.format};if(navigator.clipboard.write){var o;let{blobPromise:s,mimeType:a}=function(e,t,n={}){let i=t?.length?t:[...e.getCurrentPageShapeIds()],o=n.format??"png";return{blobPromise:e.toImage(i,n).then(e=>r.SmQ.rewriteMimeType(e.blob,lP[o])),mimeType:lP[o]}}(e,t,i),l={[a]:s},d=(o=n.format,(0,r.g50)(lc,o)??null);d&&"u">typeof ClipboardItem&&"supports"in ClipboardItem&&ClipboardItem.supports(d)&&(l[d]=s.then(e=>r.SmQ.rewriteMimeType(e,d)));let c=Object.entries(l);for(let[e,t]of c)t.catch(e=>console.error(e));return navigator.clipboard.write([new ClipboardItem(l)]).catch(e=>(console.error(e),Promise.all(c.map(async([e,t])=>[e,await t])).then(e=>{let t=(0,r._ed)(e);return navigator.clipboard.write([new ClipboardItem(t)])})))}switch(n.format){case"svg":return lT(async()=>{let n=await e.getSvgString(t,i);if(!n)throw Error("Failed to copy");return n.svg});case"png":throw Error("Copy not supported");default:(0,r.h6G)(n.format)}})(e,i,{format:o}).catch(()=>{t({id:"copy-fail",severity:"warning",title:n("toast.error.copy-fail.title"),description:n("toast.error.copy-fail.desc")})})},[e,t,n])}(),C=function(){let e=(0,r.frr)(),{addToast:t}=ls(),n=M();return(0,f.useCallback)((i,o={})=>{(0,r.vAR)(e,"useExportAs: editor is required");let{format:s="png",name:a,scale:l=1}=o;ia(e,i,{format:s,name:a,scale:l}).catch(e=>{console.error(e.message),t({id:"export-fail",title:n("toast.error.export-fail.title"),description:n("toast.error.export-fail.desc"),severity:"error"})})},[e,t,n])}(),k=o8(),P=5>sn(),T=(0,r.H80)((0,f.useContext)(lE)),E=(0,f.useCallback)(async()=>{if(!d)return;let e=await la({allowMultiple:!0,mimeTypes:T,document:d.getContainerDocument()});e.length&&(d.markHistoryStoppingPoint("insert media"),d.putExternalContent({type:"files",files:e,point:d.getViewportPageBounds().center}))},[d,T]),I=(0,f.useCallback)(async e=>{if(!d)return;let t=await la({allowMultiple:!1,mimeTypes:T?.filter(t=>e?t.startsWith("image/"):t.startsWith("video/")),document:d.getContainerDocument()});if(!t.length)return;let n=d.getOnlySelectedShape();if(!n||e&&"image"!==n.type||!e&&"video"!==n.type)return;d.markHistoryStoppingPoint("replace media");let r=t[0];d.replaceExternalContent({type:"file-replace",file:r,shapeId:n.id,isImage:e})},[d,T]),_=(0,f.useCallback)(()=>I(!0),[I]),A=(0,f.useCallback)(()=>I(!1),[I]);return(0,f.useMemo)(()=>({addToast:c,removeToast:h,clearToasts:u,addDialog:p,removeDialog:m,clearDialogs:g,msg:y,isMobile:P,insertMedia:E,replaceImage:_,replaceVideo:A,printSelectionOrPages:b,cut:x,copy:w,paste:v,copyAs:S,exportAs:C,getEmbedDefinition:k}),[c,h,u,p,m,g,y,P,E,_,A,b,x,w,v,S,C,k])}function l_(e){return(0,f.useMemo)(()=>e,e)}function lM(e){let t=l_(null==e?[]:Array.isArray(e)?e:[e]);return(0,f.useMemo)(()=>{let e={};for(let n of t)if(n.translations)for(let[t,i]of(0,r.iAN)(n.translations)){let n=e[t];n||(n=e[t]={}),Object.assign(n,i)}return e},[t])}let lA=f.createContext(null);function lj({overrides:e,children:t}){let n=(0,r.frr)(),i=sF(),o=w(),s=M(),a=lI(),l=f.useCallback((e,t,n)=>{o.announce({msg:s(t.label)}),i("select-tool",{source:e,id:n??t.id})},[o,s,i]),c=f.useMemo(()=>{if(!n)return{};let t=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(e){if(n.isIn("select")){let e=n.root.getCurrent();e.exit({},e.id),e.enter({},e.id)}n.setCurrentTool("select"),l(e,this)}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(e){n.setCurrentTool("hand"),l(e,this)}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(e){n.setCurrentTool("eraser"),l(e,this)}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(e){n.setCurrentTool("draw"),l(e,this)}},...[...r.tg8.values].map(e=>({id:e,label:`tool.${e}`,meta:{geo:e},kbd:"rectangle"===e?"r":"ellipse"===e?"o":void 0,icon:"geo-"+e,onSelect(t){n.run(()=>{n.setStyleForNextShapes(r.tg8,e),n.setCurrentTool("geo"),l(t,this,`geo-${e}`)})},onDragStart(t,r){let o=n.getResizeScaleFactor();lD(n,r,{createShape:t=>n.createShape({id:t,type:"geo",props:{w:200*o,h:200*o,geo:e,scale:o}})}),i("drag-tool",{source:t,id:"geo"})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(e){n.setCurrentTool("arrow"),l(e,this)},onDragStart(e,t){let r=n.getResizeScaleFactor();lD(n,t,{createShape:e=>n.createShape({id:e,type:"arrow",props:{start:{x:0,y:200*r},end:{x:200*r,y:0},scale:r}})}),i("drag-tool",{source:e,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(e){n.setCurrentTool("line"),l(e,this)},onDragStart(e,t){let o=n.getResizeScaleFactor();lD(n,t,{createShape:e=>{let[t,i]=(0,r.MTM)(null,null,2);n.createShape({id:e,type:"line",props:{points:{[t]:{id:t,index:t,x:0,y:200*o},[i]:{id:i,index:i,x:200*o,y:0}},scale:o}})}}),i("drag-tool",{source:e,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(e){n.setCurrentTool("frame"),l(e,this)},onDragStart(e,t){let r=n.getResizeScaleFactor();lD(n,t,{createShape:e=>n.createShape({id:e,type:"frame",props:{w:320*r,h:180*r}})}),i("drag-tool",{source:e,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(e){n.setCurrentTool("text"),l(e,this)},onDragStart(e,t){let o=n.getResizeScaleFactor();lD(n,t,{createShape:e=>n.createShape({id:e,type:"text",props:{richText:(0,r.TP3)("Text"),scale:o}}),onDragEnd:e=>{y(n,e,{selectAll:!0})}}),i("drag-tool",{source:e,id:"text"})}},{id:"asset",label:"tool.media",icon:"tool-media",kbd:"cmd+u,ctrl+u",onSelect(e){a.insertMedia(),l(e,this,"media")}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(e){n.setCurrentTool("note"),l(e,this)},onDragStart(e,t){let r=n.getResizeScaleFactor();lD(n,t,{createShape:e=>n.createShape({id:e,type:"note",props:{scale:r}}),onDragEnd:e=>{y(n,e,{selectAll:!0})}}),i("drag-tool",{source:e,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(e){n.setCurrentTool("laser"),l(e,this)}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(e){a.addDialog({component:o9}),l(e,this)}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"shift+d",onSelect(e){n.setCurrentTool("highlight"),l(e,this)}}];t.forEach(e=>e.onSelect=e.onSelect.bind(e));let o=Object.fromEntries(t.map(e=>[e.id,e]));return e?e(n,o,a):o},[e,n,a,l,i]);return(0,d.jsx)(lA.Provider,{value:c,children:t})}function lO(){let e=f.useContext(lA);if(!e)throw Error("useTools must be used within a ToolProvider");return e}function lD(e,t,n){if(e.getIsReadonly())return;let{x:i,y:o}=e.inputs.getCurrentPagePoint(),s=e.markHistoryStoppingPoint("drag shape tool"),a=(0,r.n6Y)();n.createShape(a);let l=e.getShape(a);if(!l){(0,r.mcG)("onDragFromToolbarToCreateShape: createShape did not create a shape, ignoring drag."),e.setCurrentTool("select.idle");return}let{w:d,h:c}=e.getShapePageBounds(a);e.updateShape({id:a,type:l.type,x:i-d/2,y:o-c/2}),e.select(a),e.setCurrentTool("select.translating",{...t,target:"shape",shape:e.getShape(a),isCreating:!0,creatingMarkId:s,onCreate(){e.setCurrentTool("select.idle"),e.select(a),n.onDragEnd?.(a)}}),e.getCurrentTool().setCurrentToolIdMask(n.maskedToolId??l.type)}function lL({toolId:e="",...t}){let n=lO()[e];return n?(0,d.jsx)(ak,{...n,...t}):null}function lR(){let e=ss();return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(aE,{label:"shortcuts-dialog.tools",id:"tools",children:[(0,d.jsx)(aT,{actionId:"toggle-tool-lock"}),(0,d.jsx)(aT,{actionId:"insert-media"}),(0,d.jsx)(aT,{actionId:"insert-embed"}),(0,d.jsx)(lL,{toolId:"select"}),(0,d.jsx)(lL,{toolId:"draw"}),(0,d.jsx)(lL,{toolId:"highlight"}),(0,d.jsx)(lL,{toolId:"eraser"}),(0,d.jsx)(lL,{toolId:"hand"}),(0,d.jsx)(lL,{toolId:"rectangle"}),(0,d.jsx)(lL,{toolId:"ellipse"}),(0,d.jsx)(lL,{toolId:"arrow"}),(0,d.jsx)(lL,{toolId:"line"}),(0,d.jsx)(lL,{toolId:"text"}),(0,d.jsx)(lL,{toolId:"frame"}),(0,d.jsx)(lL,{toolId:"note"}),(0,d.jsx)(lL,{toolId:"laser"}),(0,d.jsx)(ak,{id:"pointer-down",label:"tool.pointer-down",kbd:",",onSelect:()=>{}})]}),(0,d.jsxs)(aE,{label:"shortcuts-dialog.preferences",id:"preferences",children:[(0,d.jsx)(aT,{actionId:"toggle-dark-mode"}),(0,d.jsx)(aT,{actionId:"toggle-focus-mode"}),(0,d.jsx)(aT,{actionId:"toggle-grid"})]}),(0,d.jsxs)(aE,{label:"shortcuts-dialog.edit",id:"edit",children:[(0,d.jsx)(aT,{actionId:"undo"}),(0,d.jsx)(aT,{actionId:"redo"}),(0,d.jsx)(aT,{actionId:"cut"}),(0,d.jsx)(aT,{actionId:"copy"}),(0,d.jsx)(aT,{actionId:"copy-as-png"}),(0,d.jsx)(aT,{actionId:"copy-hovered-styles"}),(0,d.jsx)(aT,{actionId:"paste"}),(0,d.jsx)(aT,{actionId:"select-all"}),(0,d.jsx)(aT,{actionId:"delete"}),(0,d.jsx)(aT,{actionId:"duplicate"}),(0,d.jsx)(aT,{actionId:"print"})]}),(0,d.jsxs)(aE,{label:"shortcuts-dialog.view",id:"view",children:[(0,d.jsx)(aT,{actionId:"select-zoom-tool"}),(0,d.jsx)(aT,{actionId:"zoom-in"}),(0,d.jsx)(aT,{actionId:"zoom-out"}),(0,d.jsx)(aT,{actionId:"zoom-to-100"}),(0,d.jsx)(aT,{actionId:"zoom-to-fit"}),(0,d.jsx)(aT,{actionId:"zoom-to-selection"}),(0,d.jsx)(ak,{id:"zoom-quick",label:"action.zoom-quick",kbd:"shift+z",onSelect:()=>{}})]}),(0,d.jsxs)(aE,{label:"shortcuts-dialog.transform",id:"transform",children:[(0,d.jsx)(aT,{actionId:"bring-to-front"}),(0,d.jsx)(aT,{actionId:"bring-forward"}),(0,d.jsx)(aT,{actionId:"send-backward"}),(0,d.jsx)(aT,{actionId:"send-to-back"}),(0,d.jsx)(aT,{actionId:"group"}),(0,d.jsx)(aT,{actionId:"ungroup"}),(0,d.jsx)(aT,{actionId:"frame-selection"}),(0,d.jsx)(aT,{actionId:"flatten-to-image"}),(0,d.jsx)(aT,{actionId:"toggle-lock"}),(0,d.jsx)(aT,{actionId:"flip-horizontal"}),(0,d.jsx)(aT,{actionId:"flip-vertical"}),(0,d.jsx)(aT,{actionId:"align-top"}),(0,d.jsx)(aT,{actionId:"align-center-vertical"}),(0,d.jsx)(aT,{actionId:"align-bottom"}),(0,d.jsx)(aT,{actionId:"align-left"}),(0,d.jsx)(aT,{actionId:"align-center-horizontal"}),(0,d.jsx)(aT,{actionId:"align-right"}),(0,d.jsx)(aT,{actionId:"distribute-horizontal"}),(0,d.jsx)(aT,{actionId:"distribute-vertical"})]}),(0,d.jsxs)(aE,{label:"shortcuts-dialog.text-formatting",id:"text",children:[(0,d.jsx)(ak,{id:"text-bold",label:"tool.rich-text-bold",kbd:"cmd+b",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"text-italic",label:"tool.rich-text-italic",kbd:"cmd+i",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"text-code",label:"tool.rich-text-code",kbd:"cmd+e",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"text-highlight",label:"tool.rich-text-highlight",kbd:"cmd+shift+h",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"text-strikethrough",label:"tool.rich-text-strikethrough",kbd:"cmd+shift+s",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"text-link",label:"tool.rich-text-link",kbd:"cmd+shift+k",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"text-header",label:"tool.rich-text-header",kbd:"cmd+alt+[[1-6]]",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"text-orderedList",label:"tool.rich-text-orderedList",kbd:"cmd+shift+7",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"text-bulletedlist",label:"tool.rich-text-bulletList",kbd:"cmd+shift+8",onSelect:()=>{}})]}),(0,d.jsxs)(aE,{label:"shortcuts-dialog.a11y",id:"a11y",children:[(0,d.jsx)(ak,{id:"a11y-select-next-shape",label:"a11y.select-shape",kbd:"[[Tab]]",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"a11y-select-next-shape-direction",label:"a11y.select-shape-direction",kbd:"cmd+[[↑→↓←]]",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"a11y-select-next-shape-container",label:"a11y.enter-leave-container",kbd:"cmd+shift+[[↑↓]]",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"a11y-pan-camera",label:"a11y.pan-camera",kbd:"[[Space]]+[[↑→↓←]]",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"adjust-shape-styles",label:"a11y.adjust-shape-styles",kbd:"cmd+[[Enter]]",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"open-context-menu",label:"a11y.open-context-menu",kbd:"cmd+shift+[[Enter]]",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"a11y-move-shape",label:"a11y.move-shape",kbd:"[[↑→↓←]]",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"a11y-move-shape-faster",label:"a11y.move-shape-faster",kbd:"shift+[[↑→↓←]]",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"a11y-rotate-shape-cw",label:"a11y.rotate-shape-cw",kbd:"shift+﹥",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"a11y-rotate-shape-cw-fine",label:"a11y.rotate-shape-cw-fine",kbd:"shift+alt+﹥",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"a11y-rotate-shape-ccw",label:"a11y.rotate-shape-ccw",kbd:"shift+﹤",onSelect:()=>{}}),(0,d.jsx)(ak,{id:"a11y-rotate-shape-ccw-fine",label:"a11y.rotate-shape-ccw-fine",kbd:"shift+alt+﹤",onSelect:()=>{}}),(0,d.jsx)(aT,{actionId:"enlarge-shapes"}),(0,d.jsx)(aT,{actionId:"shrink-shapes"}),(0,d.jsx)(aT,{actionId:"a11y-repeat-shape-announce"}),(0,d.jsx)(ak,{id:"a11y-open-keyboard-shortcuts",label:"a11y.open-keyboard-shortcuts",kbd:"cmd+alt+/",onSelect:()=>{}})]}),e&&(0,d.jsx)(aE,{label:"shortcuts-dialog.collaboration",id:"collaboration",children:(0,d.jsx)(aT,{actionId:"open-cursor-chat"})})]})}let lF=(0,f.memo)(function({children:e}){let t=M(),n=sn(),r=e??(0,d.jsx)(lR,{});return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(oU,{className:"tlui-shortcuts-dialog__header",children:[(0,d.jsx)(oK,{children:t("shortcuts-dialog.title")}),(0,d.jsx)(oW,{})]}),(0,d.jsx)(oV,{className:ip("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":n<=2,"tlui-shortcuts-dialog__body__tablet":n<=6}),children:(0,d.jsx)(so,{type:"keyboard-shortcuts",sourceId:"kbd",children:r})}),(0,d.jsx)("div",{className:"tlui-dialog__scrim"})]})});async function lz(e,t,n){let i=(0,r.oE7)(t.map(t=>{let n=e.getShape(t);if(n&&void 0!==e.getShapeUtil(n.type).toSvg)return n}));if(0===i.length)return;if(1===i.length){let t=i[0];if(!t||e.isShapeOfType(t,"image"))return}let o=[];if(void 0!==n){let t=i.map(t=>({shape:t,bounds:e.getShapeMaskedPageBounds(t).clone().expandBy(n)}));for(let e=0;e<t.length;e++){let n=t[e];if(0===e){o[0]={shapes:[n.shape],bounds:n.bounds};continue}let r=!1;for(let e of o)if(e.bounds.includes(n.bounds)){e.shapes.push(n.shape),e.bounds.expand(n.bounds),r=!0;break}r||o.push({shapes:[n.shape],bounds:n.bounds})}}else{let t=r.azJ.Common(i.map(t=>e.getShapeMaskedPageBounds(t)));o.push({shapes:i,bounds:t})}let s=e.options.flattenImageBoundsPadding;for(let t of o){void 0!==n&&t.bounds.expandBy(-n);let r=await e.getSvgString(t.shapes,{padding:s,background:!1});if(!r?.svg)continue;let i=await e.getAssetForExternalContent({type:"file",file:new File([r.svg],"asset.svg",{type:"image/svg+xml"})});i&&(t.asset=i)}let a=[];return(0,r.hLc)(()=>{for(let t of o){let n,i,o,{asset:l,bounds:d,shapes:c}=t;if(!l)continue;let h=e.findCommonAncestor(c)??e.getCurrentPageId();if(!h)continue;let u="a1";for(let e of c)if(e.parentId===h){e.index>u&&(u=e.index);break}if((0,r.vc4)(h)){let t=e.getShape(h);if(!t)continue;let a=e.getPointInShapeSpace(t,{x:d.x,y:d.y});o=e.getShapePageTransform(h).rotation(),a.sub(new r.l2P(s,s).rot(-o)),n=a.x,i=a.y}else n=d.x-s,i=d.y-s,o=0;e.deleteShapes(c),e.createAssets([{...l,id:l.id}]);let p=(0,r.n6Y)();e.createShape({id:p,type:"image",index:u,parentId:h,x:n,y:i,rotation:-o,props:{assetId:l.id,w:d.w+2*s,h:d.h+2*s}}),a.push(p)}}),a}var lN=Object.defineProperty,l$=(e,t)=>lN(e,"name",{value:t,configurable:!0}),lB="Popover",[lH,lU]=(0,iy.A)(lB,[iw.Bk]),lK=(0,iw.Bk)(),[lW,lV]=lH(lB),lY=l$(e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:o,modal:s=!1}=e,a=lK(t),l=f.useRef(null),[c,h]=f.useState(!1),[u,p]=(0,ik.i)({prop:r,defaultProp:i??!1,onChange:o,caller:lB});return(0,d.jsx)(iw.bL,{...a,children:(0,d.jsx)(lW,{scope:t,contentId:(0,ix.B)(),triggerRef:l,open:u,onOpenChange:p,onOpenToggle:f.useCallback(()=>p(e=>!e),[p]),hasCustomAnchor:c,onCustomAnchorAdd:f.useCallback(()=>h(!0),[]),onCustomAnchorRemove:f.useCallback(()=>h(!1),[]),modal:s,children:n})})},"Popover"),lG=f.forwardRef(l$(function(e,t){let{__scopePopover:n,...r}=e,i=lV("PopoverTrigger",n),o=lK(n),s=(0,im.s)(t,i.triggerRef),a=(0,d.jsx)(iS.sG.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":l6(i.open),...r,ref:s,onClick:(0,ig.mK)(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?a:(0,d.jsx)(iw.Mz,{asChild:!0,...o,children:a})},"PopoverTrigger")),lq="PopoverPortal",[lX,lJ]=lH(lq,{forceMount:void 0}),lZ=l$(e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,o=lV(lq,t);return(0,d.jsx)(lX,{scope:t,forceMount:n,children:(0,d.jsx)(iv.C,{present:n||o.open,children:(0,d.jsx)(ou.Z,{asChild:!0,container:i,children:r})})})},"PopoverPortal"),lQ="PopoverContent",l0=f.forwardRef(l$(function(e,t){let n=lJ(lQ,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,o=lV(lQ,e.__scopePopover);return(0,d.jsx)(iv.C,{present:r||o.open,children:o.modal?(0,d.jsx)(l2,{...i,ref:t}):(0,d.jsx)(l3,{...i,ref:t})})},"PopoverContent")),l1=(0,iC.TL)("PopoverContent.RemoveScroll"),l2=f.forwardRef(l$(function(e,t){let n=lV(lQ,e.__scopePopover),r=f.useRef(null),i=(0,im.s)(t,r),o=f.useRef(!1);return f.useEffect(()=>{let e=r.current;if(e)return(0,og.Eq)(e)},[]),(0,d.jsx)(of.A,{as:l1,allowPinchZoom:!0,children:(0,d.jsx)(l5,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:(0,ig.mK)(e.onCloseAutoFocus,e=>{e.preventDefault(),o.current||n.triggerRef.current?.focus()}),onPointerDownOutside:(0,ig.mK)(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=0===t.button&&!0===t.ctrlKey;o.current=2===t.button||n},{checkForDefaultPrevented:!1}),onFocusOutside:(0,ig.mK)(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})},"PopoverContentModal")),l3=f.forwardRef(l$(function(e,t){let n=lV(lQ,e.__scopePopover),r=f.useRef(!1),i=f.useRef(!1);return(0,d.jsx)(l5,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,"pointerdown"===t.detail.originalEvent.type&&(i.current=!0));let o=t.target;n.triggerRef.current?.contains(o)&&t.preventDefault(),"focusin"===t.detail.originalEvent.type&&i.current&&t.preventDefault()}})},"PopoverContentNonModal")),l5=f.forwardRef(l$(function(e,t){let{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:o,disableOutsidePointerEvents:s,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:h,...u}=e,p=lV(lQ,n),f=lK(n);return(0,op.Oh)(),(0,d.jsx)(oh.n,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:o,children:(0,d.jsx)(ib.qW,{asChild:!0,disableOutsidePointerEvents:s,onInteractOutside:h,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>p.onOpenChange(!1),deferPointerDownOutside:!0,children:(0,d.jsx)(iw.UC,{"data-state":l6(p.open),role:"dialog",id:p.contentId,...f,...u,ref:t,style:{...u.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})},"PopoverContentImpl"));function l6(e){return e?"open":"closed"}function l4({id:e,children:t,onOpenChange:n,open:r,className:i}){let[o,s]=sz(e,n);return(0,d.jsx)(lY,{onOpenChange:s,open:r||o,children:(0,d.jsx)("div",{className:ip("tlui-popover",i),children:t})})}function l8({children:e}){let t=A();return(0,d.jsx)(lG,{asChild:!0,dir:t,children:e})}function l9({side:e,children:t,align:n="center",sideOffset:i=8,alignOffset:o=0,collisionPadding:s,disableEscapeKeyDown:a=!1,autoFocusFirstButton:l=!0}){let c=(0,r.NFA)(),h=A(),u=f.useRef(null),p=f.useCallback(()=>{if(!l)return;let e=[...u.current?.querySelectorAll("button:not([disabled])")??[]].filter(e=>e.offsetWidth||e.offsetHeight)[0];e&&e.focus()},[l]);return(0,d.jsx)(lZ,{container:c,children:(0,d.jsx)(l0,{className:"tlui-popover__content",side:e,sideOffset:i,align:n,alignOffset:o,collisionPadding:s,dir:h,ref:u,onOpenAutoFocus:p,onEscapeKeyDown:e=>a&&e.preventDefault(),children:t})})}l$(l6,"getState");var l7=n(54530);function de(e,t,n){let r=e.getBindingsFromShape(t,"arrow").find(e=>e.props.terminal===n);if(!r)return;let i=e.getShape(r.toId);if(!i)return;let o=e.getShapePageTransform(i),s="start"===n?"none"!==t.props.arrowheadStart:"none"!==t.props.arrowheadEnd,a=e.getShapeGeometry(i,s?void 0:{context:"@tldraw/arrow-without-arrowhead"});return{shape:i,transform:o,isClosed:a.isClosed,isExact:r.props.isExact,didIntersect:!1,geometry:a}}function dt(e,t,n,i){let o=e.getShape(n.toId);if(!o)return new r.l2P(0,0);{var s;let a,{point:l,size:d}=e.getShapeGeometry(o).bounds,c=n.props.isPrecise||i?(s=n.props.normalizedAnchor,{x:(a=e=>Math.max(.001,Math.min(.999,e)))(s.x),y:a(s.y)}):{x:.5,y:.5},h=r.l2P.Add(l,r.l2P.MulV(c,d)),u=r.V8r.applyToPoint(e.getShapePageTransform(o),h);return r.V8r.applyToPoint(r.V8r.Inverse(t),u)}}let dn=(0,l7.uY)("arrow bindings",(e,t)=>{let n=e.getBindingsFromShape(t.id,"arrow");return{start:n.find(e=>"start"===e.props.terminal),end:n.find(e=>"end"===e.props.terminal)}},{areRecordsEqual:(e,t)=>e.id===t.id,areResultsEqual:(e,t)=>e.start===t.start&&e.end===t.end});function dr(e,t){return dn.get(e,t.id)}function di(e,t,n){let i=e.getShapePageTransform(t),o=dl(e,n.start?.toId,n.end?.toId);return{start:n.start?dt(e,i,n.start,"double-bound"===o||"start-contains-end"===o):r.l2P.From(t.props.start),end:n.end?dt(e,i,n.end,"double-bound"===o||"end-contains-start"===o):r.l2P.From(t.props.end)}}function ds(e,t,n,r){let i="string"==typeof t?t:t.id,o="string"==typeof n?n:n.id,s=e.getBindingsFromShape(i,"arrow").filter(e=>e.props.terminal===r.terminal);s.length>1&&e.deleteBindings(s.slice(1));let a=s[0];a?e.updateBinding({...a,toId:o,props:r}):e.createBinding({type:"arrow",fromId:i,toId:o,props:r})}function da(e,t,n){let r=e.getBindingsFromShape(t,"arrow").filter(e=>e.props.terminal===n);e.deleteBindings(r)}function dl(e,t,n){if(!t||!n)return"safe";if(t===n)return"double-bound";let r=e.getShapePageBounds(t),i=e.getShapePageBounds(n);if(r&&i){if(r.contains(i))return"start-contains-end";if(i.contains(r))return"end-contains-start"}return"safe"}function dd(e,t,n,i,o){if(!o)return;let s=e.getShapeMask(o.shape.id);if(!s)return;let a=r.V8r.applyToPoint(i,t);if((0,r.s3y)(a,s))return;let l=r.V8r.applyToPoint(i,n),d=r.l2P.Sub(l,a).uni(),c=r.l2P.Add(l,r.l2P.Mul(d,1)),h=(0,r.lqI)(c,a,s);if(!h||0===h.length)return;let u=h[0],p=r.l2P.Dist2(u,a);for(let e=1;e<h.length;e++){let t=r.l2P.Dist2(h[e],a);t<p&&(u=h[e],p=t)}let f=r.V8r.applyToPoint(r.V8r.Inverse(i),u);t.setTo(f)}function dc(){let e=(0,r.hGv)();return(0,r.hau)("threeStackableItems",()=>e.getSelectedShapeIds().map(t=>e.getShape(t)).filter(t=>{if(!t)return!1;if(e.isShapeOfType(t,"arrow")){let n=dr(e,t);if(n.start||n.end)return!1}return!0}).length>2,[e])}function dh(){let e=(0,r.hGv)();return(0,r.hau)("isInSelectState",()=>e.isIn("select"),[e])}function du(){let e=(0,r.hGv)();return(0,r.hau)("allow group",()=>{let t=e.getSelectedShapes();if(t.length<2)return!1;for(let n of t)if(e.isShapeOfType(n,"arrow")){let r=dr(e,n);if(r.start&&!t.some(e=>e.id===r.start.toId)||r.end&&!t.some(e=>e.id===r.end.toId))return!1}return!0},[e])}function dp(){let e=(0,r.hGv)();return(0,r.hau)("allowUngroup",()=>e.getSelectedShapeIds().some(t=>e.getShape(t)?.type==="group"),[e])}let df="u">typeof window&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function dg(e,t){let n=(0,r.hGv)();return(0,r.hau)("selectedShapes",()=>{let r=n.getSelectedShapes().length;if(void 0===e)if(void 0===t)return r;else return r<=t;return void 0===t?r>=e:r>=e&&r<=t},[n,e,t])}function dm(e,t){let n=(0,r.hGv)();return(0,r.hau)("selectedShapes",()=>{let r=n.getSelectedShapes().filter(e=>!n.isShapeOrAncestorLocked(e)).length;if(void 0===e)if(void 0===t)return r;else return r<=t;return void 0===t?r>=e:r>=e&&r<=t},[n])}function dy(){let e=(0,r.hGv)();return(0,r.hau)("hasLinkShapeSelected",()=>{let t=e.getOnlySelectedShape();return!!(t&&"embed"!==t.type&&"url"in t.props&&!t.isLocked)},[e])}function db(){let e=(0,r.hGv)();return(0,r.hau)("useCanRedo",()=>e.getCanRedo(),[e])}function dx(){let e=(0,r.hGv)();return(0,r.hau)("useCanUndo",()=>e.getCanUndo(),[e])}function dw(){let e=(0,r.hGv)();return(0,r.hau)("hasShapesOnPage",()=>e.getCurrentPageShapeIds().size>0,[e])}function dv(){let e=(0,r.hGv)();return(0,r.hau)("canApplySelectionAction",()=>e.isIn("select")&&e.getSelectedShapeIds().length>0,[e])}function dS({id:e,kbd:t,label:n,lang:i,readonlyOk:o,onSelect:s,toggle:a=!1,disabled:l=!1,checked:c=!1}){let{type:h,sourceId:u}=si(),p=sl(),f=M(),g=A();if(p&&!o)return null;let m=fs(n,h),y=m?f(m):void 0;switch(h){case"menu":return(0,d.jsxs)(s_,{dir:g,lang:i,className:"tlui-button tlui-button__menu tlui-button__checkbox",onSelect:e=>{s?.(u),(0,r.woC)(e)},disabled:l,checked:c,children:[(0,d.jsx)(o$,{small:!0,label:f(c?"ui.checked":"ui.unchecked"),icon:a?c?"toggle-on":"toggle-off":c?"check":"none"}),y&&(0,d.jsx)("span",{className:"tlui-button__label",draggable:!1,children:y}),t&&(0,d.jsx)(sG,{children:t})]});case"context-menu":return(0,d.jsxs)(sa.H_,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:g,lang:i,onSelect:e=>{s(u),(0,r.woC)(e)},disabled:l,checked:c,children:[(0,d.jsx)(o$,{small:!0,label:f(c?"ui.checked":"ui.unchecked"),icon:a?c?"toggle-on":"toggle-off":c?"check":"none"}),y&&(0,d.jsx)("span",{className:"tlui-button__label",draggable:!1,children:y}),t&&(0,d.jsx)(sG,{children:t})]},e);default:return null}}function dC({actionId:e="",...t}){let n=fo()[e];return n?(0,d.jsx)(dS,{...n,...t}):null}function dk({id:e,disabled:t=!1,label:n,size:i="small",children:o}){let{type:s,sourceId:a}=si(),l=(0,r.NFA)(),c=M(),h=A(),u=n?"string"==typeof n?n:n[s]??n.default:void 0,p=u?c(u):void 0;switch(s){case"menu":return(0,d.jsxs)(sH,{id:`${a}-sub.${e}`,children:[(0,d.jsx)(sU,{id:`${a}-sub.${e}-button`,disabled:t,label:p}),(0,d.jsx)(sK,{id:`${a}-sub.${e}-content`,size:i,children:o})]});case"context-menu":if(t)return null;return(0,d.jsxs)(dP,{id:`${a}-sub.${e}`,children:[(0,d.jsx)(sa.Pd,{dir:h,disabled:t,asChild:!0,children:(0,d.jsxs)(od,{"data-testid":`${a}-sub.${e}-button`,type:"menu",className:"tlui-menu__submenu__trigger",children:[(0,d.jsx)(oc,{children:p}),(0,d.jsx)(oH,{icon:"rtl"===h?"chevron-left":"chevron-right",small:!0})]})}),(0,d.jsx)(sa.JW,{container:l,children:(0,d.jsx)(sa.es,{"data-testid":`${a}-sub.${e}-content`,className:"tlui-menu tlui-menu__submenu__content",alignOffset:-1,sideOffset:-4,collisionPadding:4,"data-size":i,children:o})})]});default:return o}}function dP({id:e,children:t}){let[n,r]=sz(e);return(0,d.jsx)(sa.Fj,{open:n,onOpenChange:r,children:t})}function dT(){let e;return(e=(0,r.hGv)(),(0,r.hau)("showAutoSizeToggle",()=>{let t=e.getSelectedShapes();return 1===t.length&&e.isShapeOfType(t[0],"text")&&!1===t[0].props.autoSize},[e]))?(0,d.jsx)(aT,{actionId:"toggle-auto-size"}):null}function dE(){return dy()?(0,d.jsx)(aT,{actionId:"edit-link"}):null}function dI(){return dm(1)?(0,d.jsx)(aT,{actionId:"duplicate"}):null}function d_(){let e=(0,r.hGv)();return(0,r.hau)("should display flatten option",()=>{if(0===e.getSelectedShapeIds().length)return!1;let t=e.getOnlySelectedShape();return!(t&&e.isShapeOfType(t,"image"))},[e])?(0,d.jsx)(aT,{actionId:"flatten-to-image"}):null}function dM(){let e=(0,r.hGv)();return(0,r.hau)("should display download original option",()=>{let t=e.getSelectedShapes();return 0!==t.length&&t.some(t=>fn(t,e))},[e])?(0,d.jsx)(aT,{actionId:"download-original"}):null}function dA(){return du()?(0,d.jsx)(aT,{actionId:"group"}):null}function dj(){return dp()?(0,d.jsx)(aT,{actionId:"ungroup"}):null}function dO(){return du()?(0,d.jsx)(aT,{actionId:"frame-selection"}):null}function dD(){let e=(0,r.hGv)();return(0,r.hau)("allow unframe",()=>{let t=e.getSelectedShapes();return 0!==t.length&&t.every(t=>e.isShapeFrameLike(t))},[e])?(0,d.jsx)(aT,{actionId:"remove-frame"}):null}function dL(){let e=(0,r.hGv)();return(0,r.hau)("allow fit frame to content",()=>{let t=e.getOnlySelectedShape();return!!t&&e.isShapeFrameLike(t)&&e.getSortedChildIdsForParent(t).length>0},[e])?(0,d.jsx)(aT,{actionId:"fit-frame-to-content"}):null}function dR(){return dg(1)?(0,d.jsx)(aT,{actionId:"toggle-lock"}):null}function dF(){let e=(0,r.hGv)(),t=(0,r.hau)("isTransparentBg",()=>!e.getInstanceState().exportBackground,[e]);return(0,d.jsx)(dC,{actionId:"toggle-transparent",checked:t,toggle:!0})}function dz(){let e=dw();return(0,d.jsx)(aT,{actionId:"unlock-all",disabled:!e})}function dN(){let e=(0,r.hGv)(),t=(0,r.hau)("zoomed to 100",()=>1===e.getEfficientZoomLevel(),[e]);return(0,d.jsx)(aT,{actionId:"zoom-to-100",noClose:!0,disabled:t})}function d$(){let e=dw();return(0,d.jsx)(aT,{actionId:"zoom-to-fit",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function dB(){let e=dv();return(0,d.jsx)(aT,{actionId:"zoom-to-selection",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function dH(){return(0,d.jsxs)(aE,{id:"clipboard",children:[(0,d.jsx)(dW,{}),(0,d.jsx)(dV,{}),(0,d.jsx)(dY,{}),(0,d.jsx)(dI,{}),(0,d.jsx)(dX,{})]})}function dU(){let e=(0,r.hGv)(),t=fo(),n=dw(),i=(0,r.hau)("isDebugMode",()=>e.getInstanceState().isDebugMode,[e]),o=!!t["copy-as-json"]&&i;return t["copy-as-svg"]||t["copy-as-png"]||o?(0,d.jsxs)(dk,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!n,children:[(0,d.jsxs)(aE,{id:"copy-as-group",children:[(0,d.jsx)(aT,{actionId:"copy-as-svg"}),!!e.getContainerWindow().navigator.clipboard?.write&&(0,d.jsx)(aT,{actionId:"copy-as-png"}),o&&(0,d.jsx)(aT,{actionId:"copy-as-json"})]}),(0,d.jsx)(aE,{id:"copy-as-bg",children:(0,d.jsx)(dF,{})})]}):null}function dK(){let e=fo();return e["export-as-svg"]||e["export-as-png"]?(0,d.jsxs)(dk,{id:"export-as",label:"context-menu.export-as",size:"small",children:[(0,d.jsxs)(aE,{id:"export-as-group",children:[(0,d.jsx)(aT,{actionId:"export-as-svg"}),(0,d.jsx)(aT,{actionId:"export-as-png"})]}),(0,d.jsx)(aE,{id:"export-as-bg",children:(0,d.jsx)(dF,{})})]}):null}function dW(){let e=dv(),t=dm(1);return(0,d.jsx)(aT,{actionId:"cut",disabled:!e||!t})}function dV(){let e=dv();return(0,d.jsx)(aT,{actionId:"copy",disabled:!e})}function dY(){return(0,d.jsx)(aT,{actionId:"paste",disabled:!df})}function dG(){return dw()?(0,d.jsxs)(aE,{id:"conversions",children:[(0,d.jsx)(dU,{}),(0,d.jsx)(dK,{}),(0,d.jsx)(dM,{})]}):null}function dq(){let e=dw();return(0,d.jsx)(aT,{actionId:"select-all",disabled:!e})}function dX(){let e=dv(),t=dm(1);return(0,d.jsx)(aT,{actionId:"delete",disabled:!e||!t})}function dJ(){let e=sl();return!dg(1)||e?null:(0,d.jsxs)(dk,{id:"edit",label:"context-menu.edit",size:"small",children:[(0,d.jsx)(dA,{}),(0,d.jsx)(dj,{}),(0,d.jsx)(d_,{}),(0,d.jsx)(dO,{}),(0,d.jsx)(dE,{}),(0,d.jsx)(dL,{}),(0,d.jsx)(dD,{}),(0,d.jsx)(d5,{}),(0,d.jsx)(d3,{}),(0,d.jsx)(dT,{}),(0,d.jsx)(dR,{})]})}function dZ(){let e,t=dm(2),n=(e=(0,r.hGv)(),(0,r.hau)("onlyFlippableShape",()=>{let t=e.getOnlySelectedShape();return t&&(e.isShapeOfType(t,"group")||e.isShapeOfType(t,"image")||e.isShapeOfType(t,"arrow")||e.isShapeOfType(t,"line")||e.isShapeOfType(t,"draw")||e.isShapeOfType(t,"geo"))},[e]));return sl()||!(t||n)?null:(0,d.jsxs)(dk,{id:"arrange",label:"context-menu.arrange",size:"small",children:[t&&(0,d.jsxs)(aE,{id:"align",children:[(0,d.jsx)(aT,{actionId:"align-left"}),(0,d.jsx)(aT,{actionId:"align-center-horizontal"}),(0,d.jsx)(aT,{actionId:"align-right"}),(0,d.jsx)(aT,{actionId:"align-top"}),(0,d.jsx)(aT,{actionId:"align-center-vertical"}),(0,d.jsx)(aT,{actionId:"align-bottom"})]}),(0,d.jsx)(dQ,{}),t&&(0,d.jsxs)(aE,{id:"stretch",children:[(0,d.jsx)(aT,{actionId:"stretch-horizontal"}),(0,d.jsx)(aT,{actionId:"stretch-vertical"})]}),(t||n)&&(0,d.jsxs)(aE,{id:"flip",children:[(0,d.jsx)(aT,{actionId:"flip-horizontal"}),(0,d.jsx)(aT,{actionId:"flip-vertical"})]}),(0,d.jsx)(d0,{})]})}function dQ(){return dm(3)?(0,d.jsxs)(aE,{id:"distribute",children:[(0,d.jsx)(aT,{actionId:"distribute-horizontal"}),(0,d.jsx)(aT,{actionId:"distribute-vertical"})]}):null}function d0(){let e=dm(2),t=dc();return e?(0,d.jsxs)(aE,{id:"order",children:[(0,d.jsx)(aT,{actionId:"pack"}),t&&(0,d.jsx)(aT,{actionId:"stack-horizontal"}),t&&(0,d.jsx)(aT,{actionId:"stack-vertical"})]}):null}function d1(){let e=sl(),t=dm(1);return e||!t?null:(0,d.jsx)(dk,{id:"reorder",label:"context-menu.reorder",size:"small",children:(0,d.jsxs)(aE,{id:"reorder",children:[(0,d.jsx)(aT,{actionId:"bring-to-front"}),(0,d.jsx)(aT,{actionId:"bring-forward"}),(0,d.jsx)(aT,{actionId:"send-backward"}),(0,d.jsx)(aT,{actionId:"send-to-back"})]})})}function d2(){let e=(0,r.hGv)(),t=(0,r.hau)("pages",()=>e.getPages(),[e]),n=(0,r.hau)("current page id",()=>e.getCurrentPageId(),[e]),{addToast:i}=ls(),o=sF(),s=sl();return!dm(1)||s?null:(0,d.jsxs)(dk,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[(0,d.jsx)(aE,{id:"pages",children:t.map(t=>(0,d.jsx)(ak,{id:t.id,disabled:n===t.id,label:t.name.length>30?`${t.name.slice(0,30)}\u2026`:t.name,onSelect:()=>{e.markHistoryStoppingPoint("move_shapes_to_page"),e.moveShapesToPage(e.getSelectedShapeIds(),t.id);let r=e.getPage(t.id);r&&i({title:"Changed page",description:`Moved to ${r.name}.`,actions:[{label:"Go back",type:"primary",onClick:()=>{e.markHistoryStoppingPoint("change-page"),e.setCurrentPage(n)}}]}),o("move-to-page",{source:"context-menu"})}},t.id))}),(0,d.jsx)(aE,{id:"new-page",children:(0,d.jsx)(aT,{actionId:"move-to-new-page"})})]})}function d3(){let e=(0,r.hGv)();return(0,r.hau)("oneEmbedSelected",()=>{let t=e.getOnlySelectedShape();return!!t&&!!(e.isShapeOfType(t,"embed")&&t.props.url&&!e.isShapeOrAncestorLocked(t))},[e])?(0,d.jsx)(aT,{actionId:"convert-to-bookmark"}):null}function d5(){let e=(0,r.hGv)(),t=o8();return(0,r.hau)("oneEmbeddableBookmarkSelected",()=>{let n=e.getOnlySelectedShape();return!!n&&!!(e.isShapeOfType(n,"bookmark")&&n.props.url&&t(n.props.url)&&!e.isShapeOrAncestorLocked(n))},[e])?(0,d.jsx)(aT,{actionId:"convert-to-embed"}):null}function d6(){let e=(0,r.hGv)(),t=(0,r.hau)("isSnapMode",()=>e.user.getIsSnapMode(),[e]);return(0,d.jsx)(dC,{actionId:"toggle-snap-mode",checked:t})}function d4(){let e=(0,r.hGv)(),t=(0,r.hau)("isToolLock",()=>e.getInstanceState().isToolLocked,[e]);return(0,d.jsx)(dC,{actionId:"toggle-tool-lock",checked:t})}function d8(){let e=(0,r.hGv)(),t=(0,r.hau)("isGridMode",()=>e.getInstanceState().isGridMode,[e]);return(0,d.jsx)(dC,{actionId:"toggle-grid",checked:t})}function d9(){let e=(0,r.hGv)(),t=(0,r.hau)("isWrapMode",()=>e.user.getIsWrapMode(),[e]);return(0,d.jsx)(dC,{actionId:"toggle-wrap-mode",checked:t})}function d7(){let e=(0,r.hGv)(),t=(0,r.hau)("isFocusMode",()=>e.getInstanceState().isFocusMode,[e]);return(0,d.jsx)(dC,{actionId:"toggle-focus-mode",checked:t})}function ce(){let e=(0,r.hGv)(),t=(0,r.hau)("edgeScrollSpeed",()=>e.user.getEdgeScrollSpeed(),[e]);return(0,d.jsx)(dC,{actionId:"toggle-edge-scrolling",checked:1===t})}function ct(){let e=(0,r.hGv)(),t=(0,r.hau)("inputMode",()=>"mouse"===e.user.getUserPreferences().inputMode,[e]),n=(0,r.hau)("isZoomDirectionInverted",()=>e.user.getIsZoomDirectionInverted(),[e]);return(0,d.jsx)(dC,{actionId:"toggle-invert-zoom",checked:n,disabled:!t})}function cn(){let e=(0,r.hGv)(),t=(0,r.hau)("animationSpeed",()=>e.user.getAnimationSpeed(),[e]);return(0,d.jsx)(dC,{actionId:"toggle-reduce-motion",checked:0===t})}function cr(){let e=(0,r.hGv)(),t=(0,r.hau)("keyboardShortcuts",()=>e.user.getAreKeyboardShortcutsEnabled(),[e]);return(0,d.jsx)(dC,{actionId:"toggle-keyboard-shortcuts",checked:t})}function ci(){let e=(0,r.hGv)(),t=(0,r.hau)("enhancedA11yMode",()=>e.user.getEnhancedA11yMode(),[e]);return(0,d.jsx)(dC,{actionId:"enhanced-a11y-mode",checked:t})}function co(){let e=(0,r.hGv)(),t=(0,r.hau)("isDebugMode",()=>e.getInstanceState().isDebugMode,[e]);return(0,d.jsx)(dC,{actionId:"toggle-debug-mode",checked:t})}function cs(){let e=(0,r.hGv)(),t=(0,r.hau)("dynamic resize",()=>e.user.getIsDynamicResizeMode(),[e]);return(0,d.jsx)(dC,{actionId:"toggle-dynamic-size-mode",checked:t})}function ca(){let e=(0,r.hGv)(),t=(0,r.hau)("paste at cursor",()=>e.user.getIsPasteAtCursorMode(),[e]);return(0,d.jsx)(dC,{actionId:"toggle-paste-at-cursor",checked:t})}function cl(){let e=(0,r.hGv)();return(0,r.hau)("show cursor chat",()=>"select"===e.getCurrentToolId()&&!e.getInstanceState().isCoarsePointer,[e])?(0,d.jsx)(aT,{actionId:"open-cursor-chat"}):null}function cd(){return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(cc,{}),(0,d.jsx)(ch,{}),(0,d.jsx)(cu,{}),(0,d.jsx)(cp,{}),(0,d.jsx)(cf,{}),(0,d.jsx)(cm,{}),(0,d.jsx)(cy,{}),(0,d.jsx)(cb,{})]})}function cc(){let e=dm(2),t=dh(),n=e&&t;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aT,{actionId:"align-left",disabled:!n}),(0,d.jsx)(aT,{actionId:"align-center-horizontal",disabled:!n}),(0,d.jsx)(aT,{actionId:"align-right",disabled:!n}),(0,d.jsx)(aT,{actionId:"stretch-horizontal",disabled:!n}),(0,d.jsx)(aT,{actionId:"align-top",disabled:!n}),(0,d.jsx)(aT,{actionId:"align-center-vertical",disabled:!n}),(0,d.jsx)(aT,{actionId:"align-bottom",disabled:!n}),(0,d.jsx)(aT,{actionId:"stretch-vertical",disabled:!n})]})}function ch(){let e=dm(3),t=dh(),n=e&&t;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aT,{actionId:"distribute-horizontal",disabled:!n}),(0,d.jsx)(aT,{actionId:"distribute-vertical",disabled:!n})]})}function cu(){let e=dc(),t=dh(),n=e&&t;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aT,{actionId:"stack-horizontal",disabled:!n}),(0,d.jsx)(aT,{actionId:"stack-vertical",disabled:!n})]})}function cp(){let e=dm(1),t=dh(),n=e&&t;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aT,{actionId:"send-to-back",disabled:!n}),(0,d.jsx)(aT,{actionId:"send-backward",disabled:!n}),(0,d.jsx)(aT,{actionId:"bring-forward",disabled:!n}),(0,d.jsx)(aT,{actionId:"bring-to-front",disabled:!n})]})}function cf(){return 5>sn()?(0,d.jsx)(dN,{}):(0,d.jsx)(cg,{})}function cg(){let e=dm(1),t=dh();return(0,d.jsx)(aT,{actionId:"rotate-ccw",disabled:!(e&&t)})}function cm(){let e=dm(1),t=dh();return(0,d.jsx)(aT,{actionId:"rotate-cw",disabled:!(e&&t)})}function cy(){let e=dy(),t=dh();return(0,d.jsx)(aT,{actionId:"edit-link",disabled:!(e&&t)})}function cb(){let e=du(),t=dp();return e?(0,d.jsx)(cx,{}):t?(0,d.jsx)(cw,{}):(0,d.jsx)(cx,{})}function cx(){let e=dm(2),t=dh();return(0,d.jsx)(aT,{actionId:"group",disabled:!(e&&t)})}function cw(){return(0,d.jsx)(aT,{actionId:"ungroup"})}let cv=(0,f.memo)(function({children:e}){let t=M(),n=sn(),i=sl(),{orientation:o}=i4(),s=(0,f.useRef)(null);(0,r.I9L)(s);let a=(0,r.hGv)(),l=(0,r.hau)("should display quick actions when in readonly",()=>a.isInAny("hand","zoom"),[a]),c=e??(0,d.jsx)(cd,{});if(!i||l)return(0,d.jsxs)(l4,{id:"actions-menu",children:[(0,d.jsx)(l8,{children:(0,d.jsx)(av,{type:"icon","data-testid":"actions-menu.button",title:t("actions-menu.title"),children:(0,d.jsx)(oH,{icon:"horizontal"===o?"dots-vertical":"dots-horizontal",small:!0})})}),(0,d.jsx)(l9,{side:"horizontal"===o?n>=6?"bottom":"top":"right",sideOffset:6,children:(0,d.jsx)(aw,{ref:s,label:t("actions-menu.title"),className:"tlui-actions-menu","data-testid":"actions-menu.content",orientation:"grid",children:(0,d.jsx)(so,{type:"icons",sourceId:"actions-menu",children:c})})})]})});function cS(){let e=(0,r.hGv)(),t=ss(),n=(0,r.hau)("isSinglePageMode",()=>e.options.maxPages<=1,[e]);return(0,d.jsxs)(d.Fragment,{children:[t&&(0,d.jsx)(cl,{}),(0,d.jsxs)(aE,{id:"modify",children:[(0,d.jsx)(dJ,{}),(0,d.jsx)(dZ,{}),(0,d.jsx)(d1,{}),!n&&(0,d.jsx)(d2,{})]}),(0,d.jsx)(dH,{}),(0,d.jsx)(dG,{}),(0,d.jsx)(aE,{id:"select-all",children:(0,d.jsx)(dq,{})})]})}let cC=(0,f.memo)(function({children:e,disabled:t=!1}){let n=(0,r.hGv)(),i=M(),{Canvas:o}=(0,r.BSi)(),s=(0,r.hau)("context menu can open",()=>!n.getInstanceState().isCoarsePointer||n.isIn("select"),[n]),a=(0,f.useCallback)(e=>{"Escape"===e.key&&(e.stopPropagation(),n.getContainer().focus())},[n]);(0,f.useEffect)(()=>{let e=n.getContainerDocument().body;return()=>{e.removeEventListener("keydown",a,{capture:!0})}},[n,a]);let l=(0,f.useRef)(0),c=(0,f.useCallback)(e=>{let t=n.getContainerDocument().body;if(e){if(t.addEventListener("keydown",a,{capture:!0}),n.getInstanceState().isCoarsePointer){l.current=Date.now()+500;let e=n.getSelectedShapes(),t=n.inputs.getCurrentPagePoint(),r=n.getShapesAtPoint(t);if(!n.getSelectedShapes().length||!r.some(t=>e.includes(t))){let e=r.filter(e=>n.isShapeOrAncestorLocked(e));e.length&&n.select(...e.map(e=>e.id))}}}else{let e=n.getOnlySelectedShape();e&&n.isShapeOrAncestorLocked(e)&&n.setSelectedShapes([]),n.timers.requestAnimationFrame(()=>{t.removeEventListener("keydown",a,{capture:!0})})}},[n,a]),h=(0,r.NFA)(),u=A(),[p,g]=sz("context menu",c),m=e??(0,d.jsx)(cS,{});return(0,d.jsxs)(sa.bL,{dir:u,onOpenChange:g,modal:!1,children:[(0,d.jsx)(sa.l9,{onContextMenu:s?void 0:r.woC,dir:"ltr",disabled:t||!s,children:o?(0,d.jsx)(o,{}):null}),p&&(0,d.jsx)(sa.ZL,{container:h,children:(0,d.jsx)(sa.UC,{className:"tlui-menu tlui-scrollable","data-testid":"context-menu","aria-label":i("context-menu.title"),alignOffset:-4,collisionPadding:4,onContextMenu:r.woC,onPointerDownOutside:e=>{Date.now()<l.current&&e.preventDefault()},onInteractOutside:e=>{Date.now()<l.current&&e.preventDefault()},onFocusOutside:e=>{Date.now()<l.current&&e.preventDefault()},children:(0,d.jsx)(so,{type:"context-menu",sourceId:"context-menu",children:m})})})]})}),ck=(0,r.u4I)(function(){let e=(0,r.hGv)(),{isChatting:t,chatMessage:n}=e.getInstanceState(),i=(0,f.useRef)(-1),[o,s]=(0,f.useState)("");return((0,f.useEffect)(()=>((!t&&n||t)&&(i.current=e.timers.setTimeout(()=>{e.updateInstanceState({chatMessage:"",isChatting:!1}),s(""),e.focus()},t?5e3:2e3)),()=>{clearTimeout(i.current)}),[e,n,t]),t)?(0,d.jsx)(cE,{value:o,setValue:s,chatMessage:n}):n.trim()?(0,d.jsx)(cT,{chatMessage:n}):null});function cP(e){let t=(0,r.hGv)();(0,f.useLayoutEffect)(()=>{if(!e.current)return;let{x:n,y:r}=t.inputs.getCurrentScreenPoint();function i(n){let{minX:r,minY:i}=t.getViewportScreenBounds();e.current?.style.setProperty("transform",`translate(${n.clientX-r}px, ${n.clientY-i}px)`)}e.current?.style.setProperty("transform",`translate(${n}px, ${r}px)`);let o=t.getContainerWindow();return o.addEventListener("pointermove",i),()=>{o.removeEventListener("pointermove",i)}},[e,t])}let cT=({chatMessage:e})=>{let t=(0,r.hGv)(),n=(0,f.useRef)(null);return cP(n),(0,d.jsx)("div",{ref:n,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:t.user.getColor()},children:e})},cE=(0,r.u4I)(function({chatMessage:e,value:t,setValue:n}){let i=(0,r.hGv)(),o=M(),s=(0,f.useRef)(null),a=e||o("cursor-chat.type-to-chat");cP(s),(0,f.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let n=i.textMeasure.measureText(t||a,{fontFamily:"inherit",fontSize:12,fontWeight:"500",fontStyle:"normal",maxWidth:null,lineHeight:1,padding:"6px"});e.style.setProperty("width",n.w+"px")},[i,t,a]),(0,f.useLayoutEffect)(()=>{let e=i.timers.requestAnimationFrame(()=>{s.current?.focus()});return()=>{cancelAnimationFrame(e)}},[i]);let l=(0,f.useCallback)(()=>{i.updateInstanceState({isChatting:!1}),i.focus()},[i]),c=(0,f.useCallback)(e=>{let{value:t}=e.target;n(t.slice(0,64)),i.updateInstanceState({chatMessage:t})},[i,n]),h=(0,f.useCallback)(e=>{let t=s.current;if(!t)return;let{value:i}=t;switch(e.key){case"Enter":if((0,r.woC)(e),e.stopPropagation(),!i)return void l();n("");break;case"Escape":(0,r.woC)(e),e.stopPropagation(),l()}},[l,n]),u=(0,f.useCallback)(e=>{e.stopPropagation()},[]);return(0,d.jsx)("input",{ref:s,className:"tl-cursor-chat",style:{backgroundColor:i.user.getColor()},onBlur:l,onChange:c,onKeyDown:h,onPaste:u,value:t,placeholder:a,spellCheck:!1})});function cI({checked:e}){let t=M();return(0,d.jsx)(o$,{"data-checked":!!e,label:t(e?"ui.checked":"ui.unchecked"),icon:e?"check":"none",className:"tlui-button__icon",small:!0})}function c_({customDebugFlags:e,customFeatureFlags:t}){let n=(0,r.hGv)(),{addToast:i}=ls(),{addDialog:o}=aM(),[s,a]=f.useState(!1);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(aE,{id:"items",children:[(0,d.jsx)(ak,{id:"hard-reset",onSelect:r.W$r,label:"Hard reset"}),(0,d.jsx)(ak,{id:"add-toast",onSelect:()=>{i({id:(0,r.NF7)(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),i({id:(0,r.NF7)(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"info",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),i({id:(0,r.NF7)(),title:"Something maybe bad happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"warning",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),i({id:(0,r.NF7)(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),(0,d.jsx)(ak,{id:"show-dialog",label:"Show dialog",onSelect:()=>{o({component:({onClose:e})=>(0,d.jsx)(cj,{displayDontShowAgain:!0,onCancel:()=>e(),onContinue:()=>e()}),onClose:()=>{}})}}),(0,d.jsx)(ak,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>(function(e){let t=e.options.adjacentShapeMargin,n=Array(100),i=Math.floor(Math.sqrt(100));for(let e=0;e<100;e++)cD++,n[e]={id:(0,r.n6Y)("box"+cD),type:"geo",x:e%i*(100+t),y:Math.floor(e/i)*(100+t)};e.run(()=>{e.createShapes(n).setSelectedShapes(n.map(e=>e.id))})})(n)}),(0,d.jsx)(ak,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{let e=n.getSelectedShapes(),t=0===e.length?n.getRenderingShapes():e;window.alert(`Shapes ${t.length}, DOM nodes:${n.getContainerDocument().querySelector(".tl-shapes").querySelectorAll("*")?.length}`)}}),(()=>{if(s)throw Error("oh no!");return null})(),(0,d.jsx)(ak,{id:"throw-error",onSelect:()=>a(!0),label:"Throw error"})]}),(0,d.jsxs)(aE,{id:"flags",children:[(0,d.jsx)(cM,{customDebugFlags:e}),(0,d.jsx)(cA,{customFeatureFlags:t})]})]})}function cM(e){let t=Object.values(e.customDebugFlags??r.bGJ);return t.length?(0,d.jsx)(dk,{id:"debug flags",label:"Debug flags",children:(0,d.jsx)(aE,{id:"debug flags",children:t.map(e=>(0,d.jsx)(cO,{flag:e},e.name))})}):null}function cA(e){let t=Object.values(e.customFeatureFlags??r.ofH);return t.length?(0,d.jsx)(dk,{id:"feature flags",label:"Feature flags",children:(0,d.jsx)(aE,{id:"feature flags",children:t.map(e=>(0,d.jsx)(cO,{flag:e},e.name))})}):null}function cj({title:e="title",body:t="hello hello hello",cancel:n="Cancel",confirm:r="Continue",displayDontShowAgain:i=!1,maxWidth:o="350",onCancel:s,onContinue:a}){let[l,c]=f.useState(!1);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(oU,{children:[(0,d.jsx)(oK,{children:e}),(0,d.jsx)(oW,{})]}),(0,d.jsx)(oV,{style:{maxWidth:o},children:t}),(0,d.jsxs)(oY,{className:"tlui-dialog__footer__actions",children:[i&&(0,d.jsxs)(od,{type:"normal",onClick:()=>c(!l),style:{marginRight:"auto"},children:[(0,d.jsx)(cI,{checked:l}),(0,d.jsx)(oc,{children:"Don’t show again"})]}),(0,d.jsx)(od,{type:"normal",onClick:s,children:(0,d.jsx)(oc,{children:n})}),(0,d.jsx)(od,{type:"primary",onClick:async()=>a(),children:(0,d.jsx)(oc,{children:r})})]})]})}let cO=(0,r.u4I)(function({flag:e,onChange:t}){let n=e.get();return(0,d.jsx)(dS,{id:e.name,title:e.name,label:e.name.replace(/([a-z0-9])([A-Z])/g,e=>`${e[0]} ${e[1].toLowerCase()}`).replace(/^[a-z]/,e=>e.toUpperCase()),checked:n,onSelect:()=>{e.set(!n),t?.(!n)}})}),cD=0;function cL({children:e}){let t=(0,r.hGv)(),n=e??(0,d.jsx)(c_,{});return(0,f.useEffect)(()=>{let e=window;return e.editor=t,()=>{e.editor===t&&delete e.editor}},[t]),(0,d.jsxs)(sN,{id:"debug",children:[(0,d.jsx)(s$,{children:(0,d.jsx)(od,{type:"icon",title:"Debug menu",children:(0,d.jsx)(oH,{icon:"dots-horizontal"})})}),(0,d.jsx)(sB,{side:"top",align:"end",alignOffset:0,children:(0,d.jsx)(so,{type:"menu",sourceId:"debug-panel",children:n})})]})}let cR=(0,f.memo)(function(){let{DebugMenu:e}=fe(),t=(0,f.useRef)(null);return(0,r.I9L)(t),(0,d.jsxs)("footer",{ref:t,className:"tlui-debug-panel",children:[(0,d.jsx)(cF,{}),(0,d.jsx)(cz,{}),e&&(0,d.jsx)(e,{})]})}),cF=(0,r.u4I)(function(){let e=(0,r.hGv)().getPath();return(0,d.jsx)("div",{className:"tlui-debug-panel__current-state",children:`${e}`})});function cz(){let e=(0,r.hGv)(),t=(0,r.hau)("show_fps",()=>r.bGJ.showFps.get(),[r.bGJ]),n=(0,f.useRef)(null);return((0,f.useEffect)(()=>{if(!t)return;let r=0,i=-1,o=performance.now(),s=0,a=0,l=!1;return!function t(){if(a++,(s=performance.now()-o)>250){let e=Math.round(250/s*a*4);e>r&&(r=e);let t=.75*r;(e<t&&!l||e>=t&&l)&&(l=!l),n.current.innerHTML=`FPS ${e.toString()} (max: ${r})`,n.current.className="tlui-debug-panel__fps"+(l?" tlui-debug-panel__fps__slow":""),s-=250,a=0,o=performance.now()}i=e.timers.requestAnimationFrame(t)}(),()=>{cancelAnimationFrame(i)}},[t,e]),t)?(0,d.jsx)("div",{ref:n}):null}function cN(){let e=(0,r.hGv)(),t=(0,r.hau)("follow",()=>e.getInstanceState().followingUserId,[e]);return t?(0,d.jsx)(c$,{userId:t}):null}function c$({userId:e}){let t=(0,r.xQ_)(e);return t?(0,d.jsx)("div",{className:"tlui-following-indicator",style:{borderColor:t.color}}):null}let cB=(0,f.memo)(function(){let e=sn(),t=M(),n=(0,f.useRef)(null);(0,r.I9L)(n);let{MainMenu:i,QuickActions:o,ActionsMenu:s,PageMenu:a}=fe(),l=(0,r.hGv)(),c=(0,r.hau)("isSinglePageMode",()=>l.options.maxPages<=1,[l]),h="menu"===l.options.actionShortcutsLocation||"toolbar"!==l.options.actionShortcutsLocation&&e>=6;return i||a||h?(0,d.jsx)("nav",{ref:n,className:"tlui-menu-zone",children:(0,d.jsxs)(i8,{children:[i&&(0,d.jsx)(i,{}),a&&!c&&(0,d.jsx)(a,{}),h?(0,d.jsxs)(aw,{orientation:"horizontal",label:t("actions-menu.title"),children:[o&&(0,d.jsx)(o,{}),s&&(0,d.jsx)(s,{})]}):null]})}):null}),cH=({id:e,component:t,preventBackgroundClose:n})=>{let{removeDialog:i}=aM(),o=(0,r.NFA)(),s=A(),a=(0,f.useCallback)(t=>{t||i(e)},[e,i]);return(0,d.jsx)(oC,{onOpenChange:a,defaultOpen:!0,children:(0,d.jsxs)(oE,{container:o,children:[(0,d.jsx)(o_,{dir:s,className:"tlui-dialog__overlay"}),(0,d.jsx)("div",{dir:s,className:"tlui-dialog__positioner",children:(0,d.jsx)(oO,{dir:s,className:"tlui-dialog__content","aria-describedby":void 0,onInteractOutside:e=>{n&&e.preventDefault()},children:(0,d.jsx)(t,{onClose:()=>a(!1)})})})]})})},cU=(0,f.memo)(function(){let{dialogs:e}=aM();return(0,r.hau)("dialogs",()=>e.get(),[e]).map(e=>(0,d.jsx)(cH,{...e},e.id))});function cK(){let e=(0,r.hGv)();return(0,r.hau)("is pen mode",()=>e.getInstanceState().isPenMode,[e])?(0,d.jsx)(aT,{actionId:"exit-pen-mode"}):null}function cW(){let e=(0,r.hGv)(),t=fo();return(0,r.hau)("is following user",()=>!!e.getInstanceState().followingUserId,[e])?(0,d.jsx)(ak,{...t["stop-following"]}):null}function cV(){return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(cK,{}),(0,d.jsx)(fd,{}),(0,d.jsx)(cW,{})]})}function cY({children:e}){let t=e??(0,d.jsx)(cV,{});return(0,d.jsx)("div",{className:"tlui-helper-buttons",children:(0,d.jsx)(so,{type:"helper-buttons",sourceId:"helper-buttons",children:t})})}function cG(){return(0,d.jsx)(dk,{id:"help menu accessibility",label:"menu.accessibility",children:(0,d.jsxs)(aE,{id:"accessibility",children:[(0,d.jsx)(cn,{}),(0,d.jsx)(cr,{}),(0,d.jsx)(ci,{})]})})}let cq=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function cX(){let e=(0,r.hGv)(),t=sF(),n=(0,r.hau)("colorScheme",()=>e.user.getUserPreferences().colorScheme??(e.user.getIsDarkMode()?"dark":"light"),[e]);return(0,d.jsx)(dk,{id:"help menu color-scheme",label:"menu.theme",children:(0,d.jsx)(aE,{id:"theme",children:cq.map(({colorScheme:r,label:i})=>(0,d.jsx)(dS,{id:`color-scheme-${r}`,label:i,checked:r===n,readonlyOk:!0,onSelect:()=>{e.user.updateUserPreferences({colorScheme:r}),t("color-scheme",{source:"menu",value:r})}},r))})})}function cJ(){let e=(0,r.frr)(),t=sF(),n=(0,r.hau)("locale",()=>e?.user.getLocale(),[e]);return e?(0,d.jsx)(dk,{id:"help menu language",label:"menu.language",children:(0,d.jsx)(aE,{id:"languages",className:"tlui-language-menu",children:r.Yjb.map(({locale:r,label:i})=>(0,d.jsx)(dS,{id:`language-${r}`,lang:r,title:r,label:i,checked:r===n,readonlyOk:!0,onSelect:()=>{e.user.updateUserPreferences({locale:r}),t("change-language",{source:"menu",locale:r})}},r))})}):null}function cZ(){return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(cJ,{}),(0,d.jsx)(cQ,{})]})}function cQ(){let{KeyboardShortcutsDialog:e}=fe(),{addDialog:t}=aM(),n=(0,f.useCallback)(()=>{e&&t({component:e})},[t,e]);return e?(0,d.jsx)(ak,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:n}):null}let c0=["auto","trackpad","mouse"];function c1(){let e=(0,r.hGv)(),t=sF(),n=(0,r.hau)("inputMode",()=>e.user.getUserPreferences().inputMode,[e]),i=(0,r.hau)("wheelBehavior",()=>e.getCameraOptions().wheelBehavior,[e]);return(0,d.jsxs)(dk,{id:"help menu input-mode",label:"menu.input-device",children:[(0,d.jsx)(aE,{id:"peripheral-mode",children:c0.map(r=>(0,d.jsx)(dS,{id:`peripheral-mode-${r}`,label:"auto"===r?`action.toggle-auto-${i}`:"trackpad"===r?"action.toggle-trackpad":"action.toggle-mouse",checked:"auto"===r?null===n:n===r,readonlyOk:!0,onSelect:()=>{switch(t("input-mode",{source:"menu",value:r}),r){case"auto":e.user.updateUserPreferences({inputMode:null});break;case"trackpad":e.user.updateUserPreferences({inputMode:"trackpad"});break;case"mouse":e.user.updateUserPreferences({inputMode:"mouse"})}}},r))}),(0,d.jsx)(aE,{id:"invert-zoom-group",children:(0,d.jsx)(ct,{})})]})}function c2(){return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(aE,{id:"basic",children:[(0,d.jsx)(c5,{}),(0,d.jsx)(c9,{}),(0,d.jsx)(c3,{}),(0,d.jsx)(c7,{})]}),(0,d.jsx)(he,{})]})}function c3(){let e=fo();return e["export-all-as-svg"]||e["export-all-as-png"]?(0,d.jsxs)(dk,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[(0,d.jsxs)(aE,{id:"export-all-as-group",children:[(0,d.jsx)(aT,{actionId:"export-all-as-svg"}),(0,d.jsx)(aT,{actionId:"export-all-as-png"})]}),(0,d.jsx)(aE,{id:"export-all-as-bg",children:(0,d.jsx)(dF,{})})]}):null}function c5(){return(0,d.jsxs)(dk,{id:"edit",label:"menu.edit",children:[(0,d.jsx)(c8,{}),(0,d.jsx)(dH,{}),(0,d.jsx)(dG,{}),(0,d.jsx)(c6,{}),(0,d.jsx)(c4,{}),(0,d.jsx)(aE,{id:"select-all",children:(0,d.jsx)(dq,{})})]})}function c6(){return(0,d.jsxs)(aE,{id:"misc",children:[(0,d.jsx)(dA,{}),(0,d.jsx)(dj,{}),(0,d.jsx)(dE,{}),(0,d.jsx)(dT,{}),(0,d.jsx)(dD,{}),(0,d.jsx)(dL,{}),(0,d.jsx)(d5,{}),(0,d.jsx)(d3,{}),(0,d.jsx)(d_,{})]})}function c4(){return(0,d.jsxs)(aE,{id:"lock",children:[(0,d.jsx)(dR,{}),(0,d.jsx)(dz,{})]})}function c8(){let e=dx(),t=db();return(0,d.jsxs)(aE,{id:"undo-redo",children:[(0,d.jsx)(aT,{actionId:"undo",disabled:!e}),(0,d.jsx)(aT,{actionId:"redo",disabled:!t})]})}function c9(){return(0,d.jsx)(dk,{id:"view",label:"menu.view",children:(0,d.jsxs)(aE,{id:"view-actions",children:[(0,d.jsx)(aT,{actionId:"zoom-in"}),(0,d.jsx)(aT,{actionId:"zoom-out"}),(0,d.jsx)(dN,{}),(0,d.jsx)(d$,{}),(0,d.jsx)(dB,{})]})})}function c7(){return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aT,{actionId:"insert-embed"}),(0,d.jsx)(aT,{actionId:"insert-media"})]})}function he(){return(0,d.jsxs)(aE,{id:"preferences",children:[(0,d.jsxs)(dk,{id:"preferences",label:"menu.preferences",children:[(0,d.jsxs)(aE,{id:"preferences-actions",children:[(0,d.jsx)(d6,{}),(0,d.jsx)(d4,{}),(0,d.jsx)(d8,{}),(0,d.jsx)(d9,{}),(0,d.jsx)(d7,{}),(0,d.jsx)(ce,{}),(0,d.jsx)(cs,{}),(0,d.jsx)(ca,{}),(0,d.jsx)(co,{})]}),(0,d.jsxs)(aE,{id:"user-interface-submenus",children:[(0,d.jsx)(cG,{}),(0,d.jsx)(c1,{}),(0,d.jsx)(cX,{})]})]}),(0,d.jsx)(cJ,{}),(0,d.jsx)(cQ,{})]})}let ht=(0,f.memo)(function({children:e}){let t=(0,r.NFA)(),[n,i]=sz("main menu"),o=M(),s=A(),a=e??(0,d.jsx)(c2,{});return(0,d.jsxs)(sk,{dir:s,open:n,onOpenChange:i,modal:!1,children:[(0,d.jsx)(sP,{asChild:!0,dir:s,children:(0,d.jsx)(od,{type:"icon","data-testid":"main-menu.button",title:o("menu.title"),children:(0,d.jsx)(oH,{icon:"menu",small:!0})})}),(0,d.jsx)(sT,{container:t,children:(0,d.jsx)(sE,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:(0,d.jsx)(so,{type:"menu",sourceId:"main-menu",children:a})})})]})});var hn=Object.defineProperty,hr=Object.getOwnPropertyDescriptor,hi=(e,t,n,r)=>{for(var i,o=r>1?void 0:r?hr(t,n):t,s=e.length-1;s>=0;s--)(i=e[s])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&hn(t,n,o),o};class ho{constructor(e,t,n){this.editor=e,this.elem=t,this.container=n;const i=t.getContext("2d");if(!i)throw Error("Minimap: could not get 2D canvas context");this.ctx=i,this.shapeRectCache=e.store.createComputedCache("minimap-shape-rect",t=>{let n=e.getShapeUtil(t.type);return n.hideInMinimap?.(t)?null:e.getShapeMaskedPageBounds(t.id)??null}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),(0,r.wvh)("minimap render",this.render))}editor;elem;container;disposables=[];close(){this.disposables.forEach(e=>e())}ctx;shapeRectCache;_getColors(){let e=this.editor.getContainerWindow().getComputedStyle(this.editor.getContainer());return{shapeFill:e.getPropertyValue("--tl-color-text-3").trim(),selectFill:e.getPropertyValue("--tl-color-selected").trim(),viewportFill:e.getPropertyValue("--tl-color-muted-1").trim(),background:e.getPropertyValue("--tl-color-low").trim()}}colors;updateColors(){this.colors=this._getColors()}id=(0,r.NF7)();getDpr(){return this.editor.getInstanceState().devicePixelRatio}getContentPageBounds(){let e=this.editor.getViewportPageBounds(),t=this.editor.getCurrentPageBounds();return t?r.azJ.Expand(t,e):e}_getCanvasBoundingRect(){let{x:e,y:t,width:n,height:i}=this.elem.getBoundingClientRect();return new r.azJ(e,t,n,i)}canvasBoundingClientRect=(0,r.eUv)("canvasBoundingClientRect",new r.azJ);getCanvasScreenBounds(){return this.canvasBoundingClientRect.get()}_listenForCanvasResize(){let e=new ResizeObserver(()=>{let e=this._getCanvasBoundingRect();this.canvasBoundingClientRect.set(e)});return e.observe(this.elem),e.observe(this.container),()=>e.disconnect()}getCanvasSize(){let e=this.canvasBoundingClientRect.get(),t=this.getDpr();return new r.l2P(e.width*t,e.height*t)}originPagePoint=new r.l2P;originPageCenter=new r.l2P;isInViewport=!1;getCanvasPageBounds(){let e=this.getCanvasScreenBounds(),t=this.getContentPageBounds(),n=e.width/e.height,i=t.width,o=i/n;o<t.height&&(i=(o=t.height)*n);let s=new r.azJ(0,0,i,o);return s.center=t.center,s}getZoom(){return this.getCanvasScreenBounds().width/this.getCanvasPageBounds().width}getMinimapPagePoint(e,t){let n=this.getCanvasPageBounds(),i=this.getCanvasScreenBounds(),o=e-i.x,s=t-i.y;return o*=n.width/i.width,s*=n.height/i.height,o+=n.minX,s+=n.minY,new r.l2P(o,s,1)}minimapScreenPointToPagePoint(e,t,n=!1,i=!1){let{editor:o}=this,s=o.getViewportPageBounds(),{x:a,y:l}=this.getMinimapPagePoint(e,t);if(i){let e=this.editor.getCurrentPageBounds()??new r.azJ,t=e.minX-s.width/2,n=e.maxX+s.width/2,i=e.minY-s.height/2,o=e.maxY+s.height/2,d=Math.max(0,t+s.width-a),c=Math.max(0,-(n-s.width-a)),h=Math.max(0,i+s.height-l),u=Math.max(0,-(o-s.height-l));a+=(d-c)/2,l+=(h-u)/2,a=(0,r.qE8)(a,t,n),l=(0,r.qE8)(l,i,o)}if(n){let{originPagePoint:e}=this;Math.abs(a-e.x)>Math.abs(l-e.y)?l=e.y:a=e.x}return new r.l2P(a,l)}getShapePaths(){let{editor:e}=this,t=new Set(e.getSelectedShapeIds()),n=e.getCurrentPageShapeIdsSorted(),r=new Path2D,i=new Path2D;for(let e=0,o=n.length;e<o;e++){let o=n[e],s=this.shapeRectCache.get(o);s&&(t.has(o)?i:r).rect(s.x,s.y,s.w,s.h)}return{shapes:r,selected:i}}render(){let{ctx:e,editor:t,elem:n}=this,i=this.getCanvasSize(),o=this.getCanvasPageBounds(),s=this.getDpr(),a=this.getZoom();(n.width!==i.x||n.height!==i.y)&&(n.width=i.x,n.height=i.y),e.resetTransform(),e.fillStyle=this.colors.background,e.fillRect(0,0,i.x,i.y),e.scale(s*a,s*a),e.translate(-o.minX,-o.minY);let{shapes:l,selected:d}=this.getShapePaths();e.fillStyle=this.colors.shapeFill,e.fill(l),e.fillStyle=this.colors.selectFill,e.fill(d);let{minX:c,minY:h,width:u,height:p}=t.getViewportPageBounds(),f=Math.min(u/4,p/4,4/a);for(let{util:n,overlays:r}of(e.beginPath(),f*a<1?e.rect(c,h,u,p):e.roundRect(c,h,u,p,f),e.fillStyle=this.colors.viewportFill,e.fill(),t.overlays.getActiveOverlayEntries()))e.save(),n.renderMinimap(e,r,a),e.restore();let g=3/a;for(let n of t.getVisibleCollaboratorsOnCurrentPage())n.cursor&&(e.beginPath(),e.arc(n.cursor.x,n.cursor.y,g,0,r.uAR),e.fillStyle=n.color,e.fill())}}function hs(){let e=(0,r.hGv)(),t=(0,r.NFA)(),n=M(),i=f.useRef(null),o=f.useRef(!1),s=f.useRef(null),a=f.useRef(new r.l2P),l=f.useRef(void 0);f.useEffect(()=>{try{return l.current=new ho(e,i.current,t),l.current.close}catch(t){e.annotateError(t,{origin:"minimap",willCrashApp:!1}),e.timers.setTimeout(()=>{throw t});return}},[e,t]);let c=f.useCallback(t=>{if(!e.getCurrentPageShapeIds().size)return;let n=l.current;if(!n)return;let{clientX:r,clientY:i}=t,o=n.minimapScreenPointToPagePoint(r,i,!1,!0);n.originPagePoint.setTo(o),n.originPageCenter.setTo(e.getViewportPageBounds().center);let s=n.minimapScreenPointToPagePoint(r,i,!1,!1);e.centerOnPoint(s,{animation:{duration:e.options.animationMediumMs}})},[e]),h=f.useCallback(t=>{let n=l.current;if(!n||0!==t.button)return;let i=t.currentTarget;if((0,r.YYG)(i,t),!e.getCurrentPageShapeIds().size)return;let{clientX:d,clientY:c}=t;o.current=!0,s.current=t.pointerId,a.current=new r.l2P(d,c),n.isInViewport=!1;let h=n.minimapScreenPointToPagePoint(d,c,!1,!1),u=e.getViewportPageBounds(),p=n.getContentPageBounds();if(new r.azJ(p.x-u.width/2,p.y-u.height/2,p.width+u.width,p.height+u.height).containsPoint(h)&&!u.containsPoint(h)){let t=r.l2P.Sub(u.center,u.point),i=r.l2P.Add(h,t);n.originPagePoint.setTo(i),n.originPageCenter.setTo(h),e.centerOnPoint(h,{animation:{duration:e.options.animationMediumMs}})}else{let e=n.minimapScreenPointToPagePoint(d,c,!1,!0);n.isInViewport=u.containsPoint(e),n.originPagePoint.setTo(e),n.originPageCenter.setTo(u.center)}let f=e.getContainerDocument().body;function g(){null!==s.current&&i.hasPointerCapture(s.current)&&i.releasePointerCapture(s.current),o.current=!1,s.current=null,f.removeEventListener("pointerup",g),f.removeEventListener("pointercancel",g),f.removeEventListener("contextmenu",g,!0)}f.addEventListener("pointerup",g),f.addEventListener("pointercancel",g),f.addEventListener("contextmenu",g,!0)},[e]),u=f.useCallback(t=>{let n=l.current;if(!n)return;let{clientX:i,clientY:s}=t,d=n.minimapScreenPointToPagePoint(i,s,t.shiftKey,!0);if(o.current){if(4>=r.l2P.Dist2(a.current,new r.l2P(i,s)))return;if(n.isInViewport){let t=n.originPagePoint.clone().sub(n.originPageCenter);e.centerOnPoint(r.l2P.Sub(d,t));return}e.centerOnPoint(d)}let c=n.getMinimapPagePoint(i,s),h=e.pageToScreen(c),u={type:"pointer",target:"canvas",name:"pointer_move",...(0,r.yGT)(e,t),point:h,isPen:e.getInstanceState().isPenMode};e.dispatch(u)},[e]),p=f.useCallback(t=>{let n=(0,r.jaC)(t);e.dispatch({type:"wheel",name:"wheel",delta:n,point:new r.l2P(t.clientX,t.clientY),shiftKey:t.shiftKey,altKey:t.altKey,ctrlKey:t.metaKey||t.ctrlKey,metaKey:t.metaKey,accelKey:(0,r.gu7)(t)})},[e]),g=(0,r.G67)(),m=(0,r.hau)("current theme id",()=>e.getCurrentThemeId(),[e]);return f.useEffect(()=>{e.timers.setTimeout(()=>{l.current?.updateColors(),l.current?.render()})},[g,m,e]),(0,d.jsx)("div",{className:"tlui-minimap",children:(0,d.jsx)("canvas",{ref:i,role:"img","aria-label":n("navigation-zone.minimap"),"data-testid":"minimap.canvas",className:"tlui-minimap__canvas",onDoubleClick:c,onPointerMove:u,onPointerDown:h,onWheelCapture:p})})}hi([r.oIE],ho.prototype,"close",1),hi([r.EWP],ho.prototype,"getDpr",1),hi([r.EWP],ho.prototype,"getContentPageBounds",1),hi([r.EWP],ho.prototype,"getCanvasSize",1),hi([r.EWP],ho.prototype,"getCanvasPageBounds",1),hi([r.EWP],ho.prototype,"getZoom",1),hi([r.EWP],ho.prototype,"getShapePaths",1),hi([r.oIE],ho.prototype,"render",1);let ha=(0,f.memo)(function(){let e=fo(),t=M(),n=A(),i=sn(),o=(0,f.useRef)(null);(0,r.I9L)(o);let[s,a]=function(e,t){let[n,i]=f.useState(t);return f.useLayoutEffect(()=>{let t=(0,r.zMQ)(e);if(t)try{i(JSON.parse(t))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]),[n,f.useCallback(t=>{i(n=>{let i="function"==typeof t?t(n):t;return(0,r.Yz5)(e,JSON.stringify(i)),i})},[e])]}("minimap",!0),l=(0,f.useCallback)(()=>{a(e=>!e)},[a]),{ZoomMenu:c,Minimap:h}=fe();return i<4?null:(0,d.jsxs)("div",{ref:o,className:"tlui-navigation-panel",children:[(0,d.jsx)(aw,{orientation:"horizontal",label:t("navigation-zone.title"),children:c&&i<6?(0,d.jsx)(c,{}):(0,d.jsxs)(d.Fragment,{children:[h&&"rtl"===n&&(0,d.jsx)(av,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),onClick:l,children:(0,d.jsx)(oH,{small:!0,icon:s?"chevron-left":"chevron-right"})}),!s&&(0,d.jsx)(av,{type:"icon","data-testid":"minimap.zoom-out",title:`${t(fs(e["zoom-out"].label))} ${sp(e["zoom-out"].kbd)}`,onClick:()=>e["zoom-out"].onSelect("navigation-zone"),children:(0,d.jsx)(oH,{small:!0,icon:"minus"})}),c&&(0,d.jsx)(c,{},"zoom-menu"),!s&&(0,d.jsx)(av,{type:"icon","data-testid":"minimap.zoom-in",title:`${t(fs(e["zoom-in"].label))} ${sp(e["zoom-in"].kbd)}`,onClick:()=>e["zoom-in"].onSelect("navigation-zone"),children:(0,d.jsx)(oH,{small:!0,icon:"plus"})}),h&&"rtl"!==n&&(0,d.jsx)(av,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),onClick:l,children:(0,d.jsx)(oH,{small:!0,icon:s?"chevron-right":"chevron-left"})})]})}),h&&i>=6&&!s&&(0,d.jsx)(h,{})]})});function hl(e,t,n,i,o){let s;if(n===i)return;let a=e.getPages(),l=n>i?a[i-1]:a[i],d=n>i?a[i]:a[i+1];(s=l&&!d?(0,r.AQy)(l.index):!l&&d?(0,r.SBu)(a[0].index):(0,r.HEt)(l.index,d.index))!==a[n].index&&(e.markHistoryStoppingPoint("moving page"),e.updatePage({id:t,index:s}),o("move-page",{source:"page-menu"}))}let hd=function({name:e,id:t,isCurrentPage:n,onCancel:i,onComplete:o}){let s=(0,r.hGv)(),a=sF(),l=(0,f.useRef)(null),c=(0,f.useCallback)(()=>{l.current=s.markHistoryStoppingPoint("rename page")},[s]),h=(0,f.useCallback)(e=>{s.renamePage(t,e||"New Page"),a("rename-page",{source:"page-menu"})},[s,t,a]),u=(0,f.useCallback)(()=>{l.current&&s.bailToMark(l.current),i()},[s,i]),p=(0,f.useCallback)(()=>{o?.()},[o]);return(0,d.jsx)(oG,{className:"tlui-page-menu__item__input",defaultValue:e,onValueChange:h,onComplete:o,onCancel:u,onFocus:c,onBlur:p,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:!0,autoSelect:!0})},hc=(0,r.u4I)(function({index:e,listSize:t,item:n,onRename:i}){let o=(0,r.hGv)(),s=M(),a=sF(),l=(0,f.useCallback)(()=>{o.markHistoryStoppingPoint("creating page");let e=r.tvM.createId();o.duplicatePage(n.id,e),a("duplicate-page",{source:"page-menu"})},[o,n,a]),c=(0,f.useCallback)(()=>{hl(o,n.id,e,e-1,a)},[o,n,e,a]),h=(0,f.useCallback)(()=>{hl(o,n.id,e,e+1,a)},[o,n,e,a]),u=(0,f.useCallback)(()=>{o.markHistoryStoppingPoint("deleting page"),o.deletePage(n.id),a("delete-page",{source:"page-menu"})},[o,n,a]);return(0,d.jsxs)(sN,{id:`page item submenu ${e}`,children:[(0,d.jsx)(s$,{children:(0,d.jsx)(od,{type:"icon",tooltip:s("page-menu.submenu.title"),title:s("page-menu.submenu.title"),"data-testid":"page-menu.item-submenu",children:(0,d.jsx)(oH,{icon:"dots-vertical",small:!0})})}),(0,d.jsx)(sB,{side:"bottom",align:"start",alignOffset:0,sideOffset:0,children:(0,d.jsxs)(so,{type:"menu",sourceId:"page-menu",children:[(0,d.jsxs)(aE,{id:"modify",children:[i&&(0,d.jsx)(ak,{id:"rename",label:"page-menu.submenu.rename",onSelect:i}),(0,d.jsx)(ak,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:l,disabled:t>=o.options.maxPages}),e>0&&(0,d.jsx)(ak,{id:"move-up",onSelect:c,label:"page-menu.submenu.move-up"}),e<t-1&&(0,d.jsx)(ak,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:h})]}),t>1&&(0,d.jsx)(aE,{id:"delete",children:(0,d.jsx)(ak,{id:"delete",onSelect:u,label:"page-menu.submenu.delete"})})]})})]})}),hh="tldraw_page_menu_list_height";function hu(){if("u"<typeof window)return null;try{let e=window.localStorage.getItem(hh);if(!e)return null;let t=Number(e);return Number.isFinite(t)&&t>=40?t:null}catch{return null}}let hp=(0,f.memo)(function(){let e=(0,r.hGv)(),t=sF(),n=M(),i=sn(),[o,s]=(0,f.useState)(null),a=(0,f.useCallback)(t=>{let n=`-${e.contextId}`;for(let r of e.menus.getOpenMenus()){let i=r.endsWith(n)?r.slice(0,-n.length):r;i.startsWith("page item submenu ")&&(void 0===t||i!==`page item submenu ${t}`)&&e.menus.deleteOpenMenu(i)}},[e]),[l,c]=sz("page-menu",(0,f.useCallback)(e=>{s(null),e||a()},[a])),h=(0,f.useRef)(null),u=(0,r.hau)("pages",()=>e.getPages(),[e]),p=(0,r.hau)("currentPage",()=>e.getCurrentPage(),[e]),g=sl(),m=(0,r.hau)("isCoarsePointer",()=>e.getInstanceState().isCoarsePointer,[e]),[y,b]=(0,f.useState)(hu),[x,w]=(0,f.useState)(!1),[v,S]=(0,f.useState)(()=>"u"<typeof window?800:window.innerHeight),C=(0,f.useCallback)(()=>{if("u"<typeof window)return;let e=h.current?.closest(".tlui-popover__content"),t=e?Number.parseFloat(getComputedStyle(e).getPropertyValue("--radix-popover-content-available-height")):NaN;S(Number.isFinite(t)?t:window.innerHeight)},[]);(0,f.useEffect)(()=>{let e=()=>C();return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[C]),(0,f.useEffect)(()=>{l&&e.timers.requestAnimationFrame(C)},[e,l,C]);let k=Math.max(40,Math.min(800,.62*v)-41),P=Math.max(40,36*u.length+4),T=Math.min(y??P,k),E=u.length>=e.options.maxPages,I=n(E?"page-menu.max-pages-reached":"page-menu.create-new-page"),_=(0,f.useCallback)(e=>{e.preventDefault();let t=e.currentTarget;t.setPointerCapture(e.pointerId);let n=e.clientY,r=t.previousElementSibling?.getBoundingClientRect().height??0,i=r;w(!0);let o=e=>{b(i=Math.max(40,r+(e.clientY-n)))},s=()=>{t.removeEventListener("pointermove",o),t.removeEventListener("pointerup",s),t.removeEventListener("pointercancel",s),w(!1);try{window.localStorage.setItem(hh,String(i))}catch{}};t.addEventListener("pointermove",o),t.addEventListener("pointerup",s,{once:!0}),t.addEventListener("pointercancel",s,{once:!0})},[]),A=(0,f.useCallback)(()=>{b(null);try{window.localStorage.removeItem(hh)}catch{}},[]);(0,f.useEffect)(function(){let t=e.getContainerDocument();function n(){o||t.activeElement===t.body&&e.menus.clearOpenMenus()}return t.addEventListener("keydown",n,{passive:!0}),()=>{t.removeEventListener("keydown",n)}},[e,o]);let j=(0,f.useRef)({status:"idle",id:null,startIndex:0,dragIndex:0,startY:0,startScrollTop:0,lastClientY:0,justDragged:!1,startedOnDragHandle:!1,autoScrollScheduled:!1}),[O,D]=(0,f.useState)(null);(0,f.useEffect)(()=>{l&&e.timers.requestAnimationFrame(()=>{let t=h.current;if(!t)return;let n=e.getPages().findIndex(e=>e.id===p.id);if(-1===n)return;let r=e.getContainerDocument().querySelector(`[data-pageid="${p.id}"]`);r?.querySelector("button.tlui-page-menu__item__button")?.focus();let i=36*n,o=i+36,s=t.scrollTop,a=s+t.clientHeight;i<s?t.scrollTo({top:i}):o>a&&t.scrollTo({top:o-t.clientHeight})})},[p.id,l,e]);let L=(0,f.useCallback)(e=>{let t=j.current;if("dragging"!==t.status||!t.id)return;let n=h.current?.scrollTop??0,r=e-t.startY+(n-t.startScrollTop),i=Math.max(0,Math.min((u.length-1)*36,36*t.startIndex+r)),o=i-36*t.startIndex,s=Math.max(0,Math.min(Math.round(i/36),u.length-1));t.dragIndex=s,t.lastClientY=e,D({id:t.id,startIndex:t.startIndex,dragIndex:s,offsetY:o})},[u.length]);(0,f.useEffect)(()=>{if(!l)return;let e=h.current;if(e)return e.addEventListener("wheel",t,{passive:!1}),()=>e.removeEventListener("wheel",t);function t(e){"dragging"===j.current.status&&e.preventDefault()}},[l]);let R=(0,f.useCallback)(()=>{let t=j.current,n=h.current;if("dragging"!==t.status||!n){t.autoScrollScheduled=!1;return}let r=n.getBoundingClientRect(),i=t.lastClientY-r.top,o=r.bottom-t.lastClientY,s=n.scrollHeight-n.clientHeight,a=16-i,l=16-o,d=0;if(a>0&&n.scrollTop>0?d=-Math.ceil(1+5*Math.min(1,a/48)):l>0&&n.scrollTop<s&&(d=Math.ceil(1+5*Math.min(1,l/48))),0!==d){let e=n.scrollTop;n.scrollTop=Math.max(0,Math.min(s,e+d)),n.scrollTop!==e&&L(t.lastClientY)}e.timers.requestAnimationFrame(R)},[e,L]),F=(0,f.useCallback)(()=>{let t=j.current;t.autoScrollScheduled||(t.autoScrollScheduled=!0,e.timers.requestAnimationFrame(R))},[e,R]),z=(0,f.useCallback)(e=>{if(0!==e.button)return;let{clientY:t,currentTarget:n}=e,{id:i,index:o}=n.dataset;if(!i||void 0===o)return;let s="true"===n.dataset.dragHandle;s&&(e.preventDefault(),e.stopPropagation());let a=j.current;(0,r.YYG)(n,e),a.status="pointing",a.id=i,a.startIndex=+o,a.dragIndex=+o,a.startY=t,a.lastClientY=t,a.startScrollTop=h.current?.scrollTop??0,a.startedOnDragHandle=s},[]),N=(0,f.useCallback)(e=>{let t=j.current,{clientY:n}=e;if("pointing"===t.status){if(5>=Math.abs(n-t.startY))return;t.status="dragging",t.lastClientY=n,F()}"dragging"===t.status&&(e.preventDefault(),L(n))},[F,L]),$=(0,f.useCallback)(n=>{let i=j.current;"dragging"===i.status&&i.id&&(hl(e,i.id,i.startIndex,i.dragIndex,t),i.startedOnDragHandle||(i.justDragged=!0)),(0,r.hPm)(n.currentTarget,n),i.status="idle",i.id=null,i.startedOnDragHandle=!1,D(null)},[e,t]),B=(0,f.useCallback)((t,n)=>{t.preventDefault(),t.stopPropagation(),a(n),e.menus.addOpenMenu(`page item submenu ${n}`)},[a,e]),H=(0,f.useCallback)(e=>{let t=j.current;(0,r.hPm)(e.currentTarget,e),t.status="idle",t.id=null,t.startedOnDragHandle=!1,D(null)},[]),U=(0,f.useCallback)(e=>{let t=j.current;"Escape"===e.key&&"idle"!==t.status&&(t.status="idle",t.id=null,t.startedOnDragHandle=!1,D(null))},[]),K=i<5&&m,W=!g&&m,V=(0,f.useCallback)((r,i)=>{if(!g){if(K){let o=window.prompt(n("action.rename"),i);o&&o!==i&&(e.renamePage(r,o),t("rename-page",{source:"page-menu"}));return}s(r)}},[e,n,g,K,t]),Y=(0,f.useCallback)(()=>{if(g)return;let i=r.tvM.createId(),o=n("page-menu.new-page-initial-name"),s=o;if(K){let e=window.prompt(n("page-menu.create-new-page"),o);if(null===e)return;s=e||o}e.run(()=>{e.markHistoryStoppingPoint("creating page"),e.createPage({name:s,id:i}),e.setCurrentPage(i)}),K||V(i,o),t("new-page",{source:"page-menu"})},[e,n,g,K,V,t]),G=(0,f.useCallback)(n=>{e.setCurrentPage(n),t("change-page",{source:"page-menu"})},[e,t]);return(0,d.jsxs)(l4,{id:"pages",onOpenChange:c,open:l,children:[(0,d.jsx)(l8,{"data-testid":"main.page-menu",children:(0,d.jsxs)(od,{type:"menu",tooltip:p.name,title:p.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[(0,d.jsx)(oc,{children:p.name}),(0,d.jsx)(oH,{icon:"chevron-down",small:!0})]})}),(0,d.jsx)(l9,{side:"bottom",align:"start",sideOffset:0,disableEscapeKeyDown:null!==o,children:(0,d.jsxs)("div",{className:"tlui-page-menu__wrapper",children:[(0,d.jsx)("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list",ref:h,style:{height:T},children:(0,d.jsx)("div",{className:"tlui-page-menu__list__content","data-dragging":null!==O,style:{height:P},children:u.map((t,r)=>{let i=t.id===p.id,a=o===t.id,l=O?.id===t.id,c=36*r;if(O)if(l)c=36*O.startIndex+O.offsetY;else{let{startIndex:e,dragIndex:t}=O;t<e&&r>=t&&r<e?c=(r+1)*36:t>e&&r>e&&r<=t&&(c=(r-1)*36)}return(0,d.jsxs)("div",{"data-pageid":t.id,"data-testid":"page-menu.item","data-iscurrent":i,"data-dragging":l,"data-editing":a,className:"tlui-page-menu__item",onContextMenu:g||a?void 0:e=>B(e,r),style:{zIndex:l?u.length+2:i?u.length+1:r,transform:`translateY(${c}px)`},children:[a?(0,d.jsx)("div",{className:"tlui-page-menu__item__title",children:(0,d.jsx)(hd,{id:t.id,name:t.name,isCurrentPage:i,onComplete:()=>s(null),onCancel:()=>s(null)})}):(0,d.jsxs)(d.Fragment,{children:[W&&(0,d.jsx)(od,{type:"icon",className:"tlui-page-menu__item__drag-handle","data-testid":"page-menu.item-drag-handle","data-id":t.id,"data-index":r,"data-drag-handle":"true",onPointerDown:z,onPointerMove:N,onPointerUp:$,onPointerCancel:H,onKeyDown:U,tooltip:n("context-menu.reorder"),title:n("context-menu.reorder"),children:(0,d.jsx)(oH,{icon:"drag-handle-dots",small:!0})}),(0,d.jsx)(od,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{if(j.current.justDragged){j.current.justDragged=!1;return}G(t.id)},onDoubleClick:()=>V(t.id,t.name),onPointerDown:g||W?void 0:z,onPointerMove:g||W?void 0:N,onPointerUp:g||W?void 0:$,onPointerCancel:g||W?void 0:H,tooltip:n("page-menu.go-to-page"),title:n("page-menu.go-to-page"),"data-id":t.id,"data-index":r,onKeyDown:n=>{"Escape"===n.key?U(n):"Enter"===n.key&&i&&(V(t.id,t.name),e.markEventAsHandled(n))},children:(0,d.jsx)(oc,{children:t.name})})]}),!g&&!a&&(0,d.jsx)("div",{className:"tlui-page-menu__item__submenu",children:(0,d.jsx)(hc,{index:r,item:t,listSize:u.length,onRename:()=>V(t.id,t.name)})})]},t.id)})})}),(0,d.jsx)("div",{className:"tlui-page-menu__resize-handle","data-resizing":x,onPointerDown:_,onDoubleClick:A,role:"separator","aria-orientation":"horizontal","aria-label":n("page-menu.resize")}),(0,d.jsxs)(od,{type:"menu",className:"tlui-page-menu__create-button","data-testid":"page-menu.create",tooltip:I,title:I,disabled:g||E,onClick:Y,children:[(0,d.jsx)(oc,{children:I}),!E&&(0,d.jsx)(oH,{icon:"plus",small:!0})]})]})})]})});function hf(){return(0,r.VKK)((0,r.YgL)(),"commenting")}function hg(){let e=(0,r.hGv)(),t=sl(),n=(0,r.hau)("should display quick actions",()=>e.isInAny("select","hand","zoom"),[e]);if(!t||n)return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(hb,{}),(0,d.jsx)(hm,{}),(0,d.jsx)(hy,{})]})}function hm(){let e=dm(1),t=dh(),n=e&&t;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aT,{actionId:"delete",disabled:!n}),(0,d.jsx)(aT,{actionId:"duplicate",disabled:!n})]})}function hy(){let e=(0,r.hGv)(),t=hf(),n=(0,r.hau)("is comment tool selected",()=>"comment"===e.getCurrentToolId(),[e]);return t?(0,d.jsx)(lL,{toolId:"comment",isSelected:n}):null}function hb(){let e=dx(),t=db();return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aT,{actionId:"undo",disabled:!e}),(0,d.jsx)(aT,{actionId:"redo",disabled:!t})]})}let hx=(0,f.memo)(function({children:e}){let t=e??(0,d.jsx)(hg,{});return(0,d.jsx)(so,{type:"small-icons",sourceId:"quick-actions",children:t})});function hw(){let e=M();return(0,d.jsx)(oa,{content:e("status.offline"),children:(0,d.jsx)("div",{className:"tlui-offline-indicator",children:(0,d.jsx)(o$,{icon:"status-offline",label:e("status.offline"),small:!0})})})}function hv({userIds:e}){let{PeopleMenuItem:t,UserPresenceEditor:n}=fe();return(0,d.jsxs)(d.Fragment,{children:[n&&(0,d.jsx)("div",{className:"tlui-people-menu__section",children:(0,d.jsx)(n,{})}),t&&e.length>0&&(0,d.jsx)("div",{className:"tlui-people-menu__section",children:e.map(e=>(0,d.jsx)(t,{userId:e},e+"_presence"))})]})}function hS({children:e}){let t,n=M(),i=A(),o=(0,r.NFA)(),s=(0,r.hGv)(),a=(0,r.oKA)(),l=(0,r.hau)("user",()=>s.user.getColor(),[s]),c=(0,r.hau)("user",()=>s.user.getName(),[s]),[h,u]=sz("people menu"),p=(t=(0,r.frr)(),(0,r.hau)("sync status",()=>t?.store.props.collaboration?.status?t.store.props.collaboration.status.get():null,[t])),{PeopleMenuFacePile:f}=fe();if("offline"===p)return(0,d.jsx)(hw,{});if(!a.length||!e&&!f)return null;let g=e??(0,d.jsx)(hv,{userIds:a});return(0,d.jsxs)(lY,{onOpenChange:u,open:h,children:[(0,d.jsx)(lG,{dir:i,asChild:!0,children:(0,d.jsx)("button",{className:"tlui-people-menu__avatars-button",title:n("people-menu.title"),children:f?(0,d.jsx)(f,{userColor:l,userIds:a,userName:c}):null})}),(0,d.jsx)(lZ,{container:o,children:(0,d.jsx)(l0,{dir:i,className:"tlui-menu",side:"bottom",sideOffset:2,collisionPadding:4,children:(0,d.jsx)("div",{className:"tlui-people-menu__wrapper",children:g})})})]})}function hC({userId:e}){let t=(0,r.xQ_)(e);return t?(0,d.jsx)("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:t.color},children:(0,r.C$h)(t.userName??"")}):null}function hk({userIds:e,userName:t,userColor:n}){let{PeopleMenuAvatar:i}=fe(),o=2>=sn()?1:5;return(0,d.jsxs)("div",{className:"tlui-people-menu__avatars",children:[i&&e.slice(-o).map(e=>(0,d.jsx)(i,{userId:e},e)),e.length>0&&(0,d.jsx)("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:n},children:(0,r.C$h)(t??"")}),e.length>o&&(0,d.jsx)("div",{className:"tlui-people-menu__avatar tlui-people-menu__more",children:Math.abs(e.length-o)})]})}let hP=(0,r.u4I)(function({userId:e}){let t=(0,r.hGv)(),n=M(),i=sF(),o=(0,r.xQ_)(e),s=(0,f.useCallback)(()=>{t.getInstanceState().followingUserId===e?(t.stopFollowingUser(),i("stop-following",{source:"people-menu"})):(t.startFollowingUser(e),i("start-following",{source:"people-menu"}))},[t,e,i]),a=o?.followingUserId===t.user.getRecordId(),l=t.getInstanceState().followingUserId===e;return o?(0,d.jsxs)(i8,{className:"tlui-people-menu__item","data-follow":l||a,children:[(0,d.jsxs)(od,{type:"menu",className:"tlui-people-menu__item__button",onClick:()=>t.zoomToUser(e),onDoubleClick:s,children:[(0,d.jsx)(o$,{label:n("people-menu.avatar-color"),icon:"color",color:o.color}),(0,d.jsx)("div",{className:"tlui-people-menu__name",children:o.userName?.trim()||n("people-menu.anonymous-user")})]}),(0,d.jsx)(od,{type:"icon",className:"tlui-people-menu__item__follow",title:n(a?"people-menu.leading":l?"people-menu.following":"people-menu.follow"),onClick:s,disabled:a,children:(0,d.jsx)(oH,{icon:a?"leading":l?"following":"follow"})})]}):null});function hT(){let{PeopleMenu:e}=fe();return e?(0,d.jsx)("div",{className:"tlui-share-zone",draggable:!1,children:(0,d.jsx)(e,{})}):null}let hE=(0,r.u4I)(function(){let e=(0,r.hGv)(),t=(0,r.NFA)(),n=M(),i=A(),o=sF(),s=(0,f.useRef)(!1),[a,l]=(0,f.useState)(!1),c=(0,f.useCallback)(e=>{l(e)},[]),h=e.user.getColor(),u=(0,f.useCallback)(t=>{e.user.updateUserPreferences({color:t}),o("set-color",{source:"people-menu"})},[e,o]),{handleButtonClick:p,handleButtonPointerDown:g,handleButtonPointerEnter:m,handleButtonPointerUp:y}=f.useMemo(()=>{let e=()=>{s.current=!1,(0,r.mDw)(t).removeEventListener("pointerup",e)};return{handleButtonClick:e=>{let{id:t}=e.currentTarget.dataset;t&&h!==t&&u(t)},handleButtonPointerDown:n=>{let{id:i}=n.currentTarget.dataset;i&&(u(i),s.current=!0,(0,r.mDw)(t).addEventListener("pointerup",e))},handleButtonPointerEnter:e=>{if(!s.current)return;let{id:t}=e.currentTarget.dataset;t&&u(t)},handleButtonPointerUp:e=>{let{id:t}=e.currentTarget.dataset;t&&u(t)}}},[t,h,u]);return(0,d.jsxs)(lY,{onOpenChange:c,open:a,children:[(0,d.jsx)(lG,{dir:i,asChild:!0,children:(0,d.jsx)(od,{type:"icon",className:"tlui-people-menu__user__color",style:{color:e.user.getColor()},title:n("people-menu.change-color"),children:(0,d.jsx)(oH,{icon:"color"})})}),(0,d.jsx)(lZ,{container:t,children:(0,d.jsx)(l0,{dir:i,className:"tlui-menu tlui-people-menu__user__color-picker",align:"start",side:"left",sideOffset:8,children:(0,d.jsx)(i7,{children:r.xXO.map(e=>(0,d.jsx)(od,{type:"icon","data-id":e,"data-testid":e,"aria-label":e,isActive:h===e,title:e,style:{color:e},onPointerEnter:m,onPointerDown:g,onPointerUp:y,onClick:p,children:(0,d.jsx)(oH,{icon:"color"})},e))})})})]})});function hI(){let e=(0,r.hGv)(),t=sF(),n=(0,r.hau)("userName",()=>e.user.getName(),[]),i=M(),o=(0,f.useRef)(n),s=(0,f.useRef)(n),[a,l]=(0,f.useState)(!1),c=(0,f.useCallback)(()=>{l(e=>!e)},[]),h=(0,f.useCallback)(t=>{s.current=t,e.user.updateUserPreferences({name:t})},[e]),u=(0,f.useCallback)(()=>{o.current!==s.current&&(t("change-user-name",{source:"people-menu"}),o.current=s.current)},[t]),p=(0,f.useCallback)(()=>{l(!1),e.user.updateUserPreferences({name:o.current}),e.menus.clearOpenMenus()},[e]);return(0,d.jsxs)("div",{className:"tlui-people-menu__user",children:[(0,d.jsx)(hE,{}),a?(0,d.jsx)(oG,{className:"tlui-people-menu__user__input",defaultValue:n,onValueChange:h,onComplete:c,onCancel:p,onBlur:u,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:!0,autoSelect:!0}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:"tlui-people-menu__user__name",onDoubleClick:()=>{a||l(!0)},children:n||i("people-menu.anonymous-user")}),n?null:(0,d.jsx)("div",{className:"tlui-people-menu__user__label",children:i("people-menu.user")})]}),(0,d.jsx)(od,{type:"icon",className:"tlui-people-menu__user__edit","data-testid":"people-menu.change-name",title:i("people-menu.change-name"),onClick:c,children:(0,d.jsx)(oH,{icon:a?"check":"edit"})})]})}let h_=Object.freeze([r.ive,r.Pe6,r.u8f,r.Sg3]);function hM(e=h_){let t=(0,r.hGv)();return(0,r.hau)("getRelevantStyles",()=>{let n=new r.bDP(t.getSharedStyles()),i=!!t.root.getCurrent()?.shapeType,o=t.isIn("select")&&t.getSelectedShapeIds().length>0;if(0===n.size&&t.isIn("select")&&0===t.getSelectedShapeIds().length)for(let r of e)n.applyValue(r,t.getStyleForNextShape(r));return i||o||n.size>0?n:null},[t])}function hA(e,t){return{flipX:t.scaleX<0!==e.flipX,flipY:t.scaleY<0!==e.flipY}}let hj={rectangle:{snapType:"polygon",icon:"geo-rectangle",getPath(e,t,n){let r="none"!==n.props.fill;return new c().moveTo(0,0,{geometry:{isFilled:r}}).lineTo(e,0).lineTo(e,t).lineTo(0,t).close()}},ellipse:{snapType:"blobby",icon:"geo-ellipse",getPath(e,t,n){let r="none"!==n.props.fill,i=e/2,o=t/2;return new c().moveTo(0,o,{geometry:{isFilled:r}}).arcTo(i,o,!1,!0,0,e,o).arcTo(i,o,!1,!0,0,0,o).close()}},triangle:{snapType:"polygon",icon:"geo-triangle",getPath(e,t,n){let r="none"!==n.props.fill;return new c().moveTo(e/2,0,{geometry:{isFilled:r}}).lineTo(e,t).lineTo(0,t).close()}},diamond:{snapType:"polygon",icon:"geo-diamond",getPath(e,t,n){let r="none"!==n.props.fill,i=e/2,o=t/2;return new c().moveTo(i,0,{geometry:{isFilled:r}}).lineTo(e,o).lineTo(i,t).lineTo(0,o).close()}},star:{snapType:"polygon",icon:"geo-star",defaultSize:{w:200,h:190},getPath:(e,t,n)=>{var i,o,s;let a,l,d,h,u,p,f,g,m,y,b,x,w,v,S;return i=e,o=t,s="none"!==n.props.fill,a=r.uAR/5/2,l=2*Math.floor(5/4),d=2*Math.floor(2.5),h=Math.cos(-r.sKG+l*a)*i/2,u=Math.cos(-r.sKG+(10-l)*a)*i/2,p=Math.sin(-r.sKG+0*a)*o/2,f=Math.sin(-r.sKG+d*a)*o/2,g=i-Math.abs(h-u),m=o-Math.abs(f-p),y=(i-(i/2+u-(i/2-h)))/2,b=(o-(o/2+p-(o/2-f)))/2,x=(i+g)/2,w=(o+m)/2,v=x/2,S=w/2,c.lineThroughPoints(Array.from(Array(10),(e,t)=>{let n=-r.sKG+t*a;return new r.l2P(y+(t%2?v:x)*Math.cos(n),b+(t%2?S:w)*Math.sin(n))}),{geometry:{isFilled:s}}).close()}},pentagon:{snapType:"polygon",icon:"geo-pentagon",getPath(e,t,n){let i="none"!==n.props.fill;return c.lineThroughPoints((0,r.yeN)(e,t,5),{geometry:{isFilled:i}}).close()}},hexagon:{snapType:"polygon",icon:"geo-hexagon",getPath(e,t,n){let i="none"!==n.props.fill;return c.lineThroughPoints((0,r.yeN)(e,t,6),{geometry:{isFilled:i}}).close()}},octagon:{snapType:"polygon",icon:"geo-octagon",getPath(e,t,n){let i="none"!==n.props.fill;return c.lineThroughPoints((0,r.yeN)(e,t,8),{geometry:{isFilled:i}}).close()}},rhombus:{snapType:"polygon",icon:"geo-rhombus",getPath(e,t,n){let r="none"!==n.props.fill,i=Math.min(.38*e,.38*t);return new c().moveTo(i,0,{geometry:{isFilled:r}}).lineTo(e,0).lineTo(e-i,t).lineTo(0,t).close()}},"rhombus-2":{snapType:"polygon",icon:"geo-rhombus-2",getPath(e,t,n){let r="none"!==n.props.fill,i=Math.min(.38*e,.38*t);return new c().moveTo(0,0,{geometry:{isFilled:r}}).lineTo(e-i,0).lineTo(e,t).lineTo(i,t).close()}},oval:{snapType:"blobby",icon:"geo-oval",getPath:(e,t,n)=>(function(e,t,n){if(t>e){let r=e/2;return new c().moveTo(0,r,{geometry:{isFilled:n}}).arcTo(r,r,!1,!0,0,e,r).lineTo(e,t-r).arcTo(r,r,!1,!0,0,0,t-r).close()}let r=t/2;return new c().moveTo(r,t,{geometry:{isFilled:n}}).arcTo(r,r,!1,!0,0,r,0).lineTo(e-r,0).arcTo(r,r,!1,!0,0,e-r,t).close()})(e,t,"none"!==n.props.fill)},trapezoid:{snapType:"polygon",icon:"geo-trapezoid",getPath(e,t,n){let r="none"!==n.props.fill,i=Math.min(.38*e,.38*t);return new c().moveTo(i,0,{geometry:{isFilled:r}}).lineTo(e-i,0).lineTo(e,t).lineTo(0,t).close()}},"arrow-left":{snapType:"polygon",icon:"geo-arrow-left",getPath(e,t,n){let r="none"!==n.props.fill,i=.38*Math.min(e,t),o=.16*t;return new c().moveTo(i,0,{geometry:{isFilled:r}}).lineTo(i,o).lineTo(e,o).lineTo(e,t-o).lineTo(i,t-o).lineTo(i,t).lineTo(0,t/2).close()}},"arrow-up":{snapType:"polygon",icon:"geo-arrow-up",getPath(e,t,n){let r="none"!==n.props.fill,i=.16*e,o=.38*Math.min(e,t);return new c().moveTo(e/2,0,{geometry:{isFilled:r}}).lineTo(e,o).lineTo(e-i,o).lineTo(e-i,t).lineTo(i,t).lineTo(i,o).lineTo(0,o).close()}},"arrow-down":{snapType:"polygon",icon:"geo-arrow-down",getPath(e,t,n){let r="none"!==n.props.fill,i=.16*e,o=.38*Math.min(e,t);return new c().moveTo(i,0,{geometry:{isFilled:r}}).lineTo(e-i,0).lineTo(e-i,t-o).lineTo(e,t-o).lineTo(e/2,t).lineTo(0,t-o).lineTo(i,t-o).close()}},"arrow-right":{snapType:"polygon",icon:"geo-arrow-right",getPath(e,t,n){let r="none"!==n.props.fill,i=.38*Math.min(e,t),o=.16*t;return new c().moveTo(0,o,{geometry:{isFilled:r}}).lineTo(e-i,o).lineTo(e-i,0).lineTo(e,t/2).lineTo(e-i,t).lineTo(e-i,t-o).lineTo(0,t-o).close()}},cloud:{snapType:"blobby",icon:"geo-cloud",defaultSize:{w:300,h:180},getPath(e,t,n){let i="none"!==n.props.fill;return function(e,t,n,i,o,s){let a=new c,l=(0,r.She)(n),d=hR(e,t),h=Math.max(Math.ceil(d/hF[i]),6,Math.ceil(d/Math.min(e,t))),u=d/h*.2,p=Math.max(e-2*u,1),f=Math.max(t-2*u,1),g=hR(p,f)/h,m=(e-p)/2,y=(t-f)/2,b=(function(e,t,n){let i=Math.min(e,t)/2,o=Math.max(e,t)-2*i,s=(2*i*Math.PI+2*o)/n,a=e>t?[{type:"straight",start:new r.l2P(i,0),delta:new r.l2P(1,0)},{type:"arc",center:new r.l2P(e-i,i),startAngle:-r.PI/2},{type:"straight",start:new r.l2P(e-i,t),delta:new r.l2P(-1,0)},{type:"arc",center:new r.l2P(i,i),startAngle:r.PI/2}]:[{type:"straight",start:new r.l2P(e,i),delta:new r.l2P(0,1)},{type:"arc",center:new r.l2P(i,t-i),startAngle:0},{type:"straight",start:new r.l2P(0,t-i),delta:new r.l2P(0,-1)},{type:"arc",center:new r.l2P(i,i),startAngle:r.PI}],l=0,d=[];for(let e=0;e<n;e++){let e=a[0];"straight"===e.type?d.push(r.l2P.Add(e.start,r.l2P.Mul(e.delta,l))):d.push((0,r.AQe)(e.center,i,e.startAngle+l/i)),l+=s;let t="straight"===e.type?o:r.PI*i;for(;l>t;)l-=t,a.push(a.shift()),t="straight"===a[0].type?o:r.PI*i}return d})(p,f,h).map(e=>e.addXY(m,y)),x=e<20?0:.3*u,w=t<20?0:.3*u,v=b.slice(0);for(let e=0;e<Math.floor(h/2);e++)v[e]=r.l2P.AddXY(v[e],l()*x*o,l()*w*o),v[h-e-1]=r.l2P.AddXY(v[h-e-1],l()*x*o,l()*w*o);for(let n=0;n<v.length;n++){let i=n===v.length-1?0:n+1,o=v[n],l=v[i],d=b[n],c=b[i],h=r.l2P.Dist(d,c),u=(Math.max(m,y)+(g-h))*(r.l2P.Dist(o,l)/h),p=r.l2P.Lrp(d,c,.5).add(r.l2P.Sub(c,d).uni().per().mul(u));p.x<0?p.x=0:p.x>e&&(p.x=e),p.y<0?p.y=0:p.y>t&&(p.y=t);let f=(0,r.oj6)(o,l,p),x=r.l2P.Dist(f||r.l2P.Average([o,l]),o);0===n&&a.moveTo(o.x,o.y,{geometry:{isFilled:s}}),a.circularArcTo(x,!1,!0,l.x,l.y)}return a.close()}(e,t,n.id,n.props.size,n.props.scale,i)}},"x-box":{snapType:"polygon",icon:"geo-x-box",getPath(e,t,n,i){let o="none"!==n.props.fill;return function(e,t,n,i,o){let s=e/2,a=t/2,l=new c().moveTo(0,0,{geometry:{isFilled:o}}).lineTo(e,0).lineTo(e,t).lineTo(0,t).close();if("none"===i)return l;if("dashed"===i||"dotted"===i)return l.moveTo(0,0,{geometry:{isInternal:!0,isFilled:!1},dashStart:"skip",dashEnd:"outset"}).lineTo(s,a).moveTo(e,t,{geometry:{isInternal:!0,isFilled:!1},dashStart:"skip",dashEnd:"outset"}).lineTo(s,a).moveTo(0,t,{geometry:{isInternal:!0,isFilled:!1},dashStart:"skip",dashEnd:"outset"}).lineTo(s,a).moveTo(e,0,{geometry:{isInternal:!0,isFilled:!1},dashStart:"skip",dashEnd:"outset"}).lineTo(s,a);let d=.62*("draw"===i);return l.moveTo((0,r.qE8)(n*d,0,e),(0,r.qE8)(n*d,0,t),{geometry:{isInternal:!0,isFilled:!1}}).lineTo((0,r.qE8)(e-n*d,0,e),(0,r.qE8)(t-n*d,0,t)).moveTo((0,r.qE8)(e-n*d,0,e),(0,r.qE8)(n*d,0,t)).lineTo((0,r.qE8)(n*d,0,e),(0,r.qE8)(t-n*d,0,t)),l}(e,t,i,n.props.dash,o)}},"check-box":{snapType:"polygon",icon:"geo-check-box",getPath(e,t,n){let i="none"!==n.props.fill,o=.82*Math.min(e,t),s=(e-o)/2,a=(t-o)/2;return new c().moveTo(0,0,{geometry:{isFilled:i}}).lineTo(e,0).lineTo(e,t).lineTo(0,t).close().moveTo((0,r.qE8)(s+.25*o,0,e),(0,r.qE8)(a+.52*o,0,t),{geometry:{isInternal:!0,isFilled:!1},offset:0}).lineTo((0,r.qE8)(s+.45*o,0,e),(0,r.qE8)(a+.82*o,0,t)).lineTo((0,r.qE8)(s+.82*o,0,e),(0,r.qE8)(a+.22*o,0,t),{offset:0})}},heart:{snapType:"blobby",icon:"geo-heart",getPath(e,t,n){let r="none"!==n.props.fill,i=e/2,o=e/4,s=t/4;return new c().moveTo(i,t,{geometry:{isFilled:r}}).cubicBezierTo(0,1.2*s,1.5*o,3*s,0,2.5*s).cubicBezierTo(i,.9*s,0,-(.32*s),1.85*o,-(.32*s)).cubicBezierTo(e,1.2*s,2.15*o,-(.32*s),e,-(.32*s)).cubicBezierTo(i,t,e,2.5*s,2.5*o,3*s).close()}}};function hO(e,t){return t?.[e]??hj[e]}let hD=new r.laH;function hL(e,t,n){return hD.get(e,e=>(function(e,t,n){let r=Math.max(1,e.props.w),i=Math.max(1,e.props.h+e.props.growY),o=t*e.props.scale,s=hO(e.props.geo,n);if(!s)throw Error(`Unknown geo type: ${e.props.geo}`);let a=s.getPath(r,i,e,o),{flipX:l,flipY:d}=e.props;if(l||d){var c;return a.transform({a:(c={flipX:l,flipY:d}).flipX?-1:1,b:0,c:0,d:c.flipY?-1:1,e:c.flipX?r:0,f:c.flipY?i:0})}return a})(e,t,n))}function hR(e,t){return e>t?(r.PI*(t/2)+(e-t))*2:(r.PI*(e/2)+(t-e))*2}let hF={s:50,m:70,l:100,xl:130};function hz(e){return"object"==typeof e&&null!==e&&"solid"in e}let hN={draw:"font-draw",sans:"font-sans",serif:"font-serif",mono:"font-mono"};function h$(e,t){return null!=e.icon?e.icon:hN[t]??"font-draw"}let hB=[{value:"none",icon:"fill-none"},{value:"semi",icon:"fill-semi"},{value:"solid",icon:"fill-solid"}],hH=[{value:"pattern",icon:"fill-pattern"},{value:"lined-fill",icon:"fill-lined-fill"},{value:"fill",icon:"fill-fill"}],hU=[{value:"draw",icon:"dash-draw"},{value:"dashed",icon:"dash-dashed"},{value:"dotted",icon:"dash-dotted"},{value:"solid",icon:"dash-solid"}],hK=[{value:"s",icon:"size-small"},{value:"m",icon:"size-medium"},{value:"l",icon:"size-large"},{value:"xl",icon:"size-extra-large"}],hW=[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],hV=[{value:"start",icon:"horizontal-align-start"},{value:"middle",icon:"horizontal-align-middle"},{value:"end",icon:"horizontal-align-end"}],hY=[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-middle"},{value:"end",icon:"vertical-align-end"}],hG=[{value:"arc",icon:"arrow-arc"},{value:"elbow",icon:"arrow-elbow"}],hq=[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],hX=[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],hJ=[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}];function hZ(e,[t,n]){return Math.min(n,Math.max(t,e))}function hQ(e){let t=f.useRef({value:e,previous:e});return f.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}(0,Object.defineProperty)(hZ,"name",{value:"clamp",configurable:!0}),(0,Object.defineProperty)(hQ,"name",{value:"usePrevious",configurable:!0});var h0=n(63509),h1=Object.defineProperty,h2=(e,t)=>h1(e,"name",{value:t,configurable:!0}),h3=["PageUp","PageDown"],h5=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],h6={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},h4="Slider",[h8,h9,h7]=(0,aj.N)(h4),[ue,ut]=(0,iy.A)(h4,[h7]),[un,ur]=ue(h4),ui=f.forwardRef(h2(function(e,t){let{name:n,min:r=0,max:i=100,step:o=1,orientation:s="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:h,onValueChange:u=h2(()=>{},"onValueChange"),onValueCommit:p=h2(()=>{},"onValueCommit"),inverted:g=!1,form:m,...y}=e,b=f.useRef(new Set),x=f.useRef(0),w=f.useRef(!1),v="horizontal"===s,[S,C]=f.useState(null),k=(0,im.s)(t,C),[P=[],T]=(0,ik.i)({prop:h,defaultProp:c,onChange:h2(e=>{let t=[...b.current];t[x.current]?.focus({preventScroll:!0,focusVisible:w.current}),w.current=!1,u(e)},"onChange")}),E=f.useRef(P),I=f.useRef(P);function _(e){let t=uC(P,e);j(e,t)}function M(e){j(e,x.current)}function A(){String(P)!==String(E.current)&&p(P)}function j(e,t,{commit:n}={commit:!1}){let s=uI(o),a=hZ(u_(Math.round((e-r)/o)*o+r,s),[r,i]);T((e=[])=>{let r=uw(e,a,t);if(!uT(r,l*o))return e;{x.current=r.indexOf(a);let t=String(r)!==String(e);return t&&n&&p(r),t?r:e}})}return f.useEffect(()=>{let e=m?S?.ownerDocument.getElementById(m):S?.closest("form");if(e instanceof HTMLFormElement){let t=h2(()=>T(I.current),"reset");return e.addEventListener("reset",t),()=>e.removeEventListener("reset",t)}},[S,m,T]),h2(_,"handleSlideStart"),h2(M,"handleSlideMove"),h2(A,"handleSlideEnd"),h2(j,"updateValues"),(0,d.jsx)(un,{scope:e.__scopeSlider,name:n,disabled:a,min:r,max:i,valueIndexToChangeRef:x,thumbs:b.current,values:P,orientation:s,form:m,children:(0,d.jsx)(h8.Provider,{scope:e.__scopeSlider,children:(0,d.jsx)(h8.Slot,{scope:e.__scopeSlider,children:(0,d.jsx)(v?ua:ul,{"aria-disabled":a,"data-disabled":a?"":void 0,...y,ref:k,onPointerDown:(0,ig.mK)(y.onPointerDown,()=>{a||(E.current=P,w.current=!1)}),min:r,max:i,inverted:g,onSlideStart:a?void 0:_,onSlideMove:a?void 0:M,onSlideEnd:a?void 0:A,onHomeKeyDown:()=>{a||(w.current=!0,j(r,0,{commit:!0}))},onEndKeyDown:()=>{a||(w.current=!0,j(i,P.length-1,{commit:!0}))},onStepKeyDown:({event:e,direction:t})=>{if(!a){w.current=!0;let n=h3.includes(e.key)||e.shiftKey&&h5.includes(e.key),i=x.current;j(uM(P[i],{min:r,step:o,direction:t,multiplier:n?10:1}),i,{commit:!0})}}})})})})},"Slider")),[uo,us]=ue(h4,{startEdge:"left",endEdge:"right",size:"width",direction:1}),ua=f.forwardRef(h2(function(e,t){let{min:n,max:r,dir:i,inverted:o,onSlideStart:s,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...h}=e,[u,p]=f.useState(null),g=(0,im.s)(t,p),m=f.useRef(void 0),y=(0,sZ.jH)(i),b="ltr"===y,x=b&&!o||!b&&o;function w(e){let t=m.current||u.getBoundingClientRect(),i=uE([0,t.width],x?[n,r]:[r,n]);return m.current=t,i(e-t.left)}return h2(w,"getValueFromPointer"),(0,d.jsx)(uo,{scope:e.__scopeSlider,startEdge:x?"left":"right",endEdge:x?"right":"left",direction:x?1:-1,size:"width",children:(0,d.jsx)(ud,{dir:y,"data-orientation":"horizontal",...h,ref:g,style:{...h.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:e=>{let t=w(e.clientX);s?.(t)},onSlideMove:e=>{let t=w(e.clientX);a?.(t)},onSlideEnd:()=>{m.current=void 0,l?.()},onStepKeyDown:e=>{let t=h6[x?"from-left":"from-right"].includes(e.key);c?.({event:e,direction:t?-1:1})}})})},"SliderHorizontal")),ul=f.forwardRef(h2(function(e,t){let{min:n,max:r,inverted:i,onSlideStart:o,onSlideMove:s,onSlideEnd:a,onStepKeyDown:l,...c}=e,h=f.useRef(null),u=(0,im.s)(t,h),p=f.useRef(void 0),g=!i;function m(e){let t=p.current||h.current.getBoundingClientRect(),i=uE([0,t.height],g?[r,n]:[n,r]);return p.current=t,i(e-t.top)}return h2(m,"getValueFromPointer"),(0,d.jsx)(uo,{scope:e.__scopeSlider,startEdge:g?"bottom":"top",endEdge:g?"top":"bottom",size:"height",direction:g?1:-1,children:(0,d.jsx)(ud,{"data-orientation":"vertical",...c,ref:u,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:e=>{let t=m(e.clientY);o?.(t)},onSlideMove:e=>{let t=m(e.clientY);s?.(t)},onSlideEnd:()=>{p.current=void 0,a?.()},onStepKeyDown:e=>{let t=h6[g?"from-bottom":"from-top"].includes(e.key);l?.({event:e,direction:t?-1:1})}})})},"SliderVertical")),ud=f.forwardRef(h2(function(e,t){let{__scopeSlider:n,onSlideStart:r,onSlideMove:i,onSlideEnd:o,onHomeKeyDown:s,onEndKeyDown:a,onStepKeyDown:l,...c}=e,h=ur(h4,n);return(0,d.jsx)(iS.sG.span,{...c,ref:t,onKeyDown:(0,ig.mK)(e.onKeyDown,e=>{"Home"===e.key?(s(e),e.preventDefault()):"End"===e.key?(a(e),e.preventDefault()):h3.concat(h5).includes(e.key)&&(l(e),e.preventDefault())}),onPointerDown:(0,ig.mK)(e.onPointerDown,e=>{let t=e.target;t.setPointerCapture(e.pointerId),e.preventDefault(),h.thumbs.has(t)?t.focus({preventScroll:!0,focusVisible:!1}):r(e)}),onPointerMove:(0,ig.mK)(e.onPointerMove,e=>{e.target.hasPointerCapture(e.pointerId)&&i(e)}),onPointerUp:(0,ig.mK)(e.onPointerUp,e=>{let t=e.target;t.hasPointerCapture(e.pointerId)&&(t.releasePointerCapture(e.pointerId),o(e))})})},"SliderImpl")),uc=f.forwardRef(h2(function(e,t){let{__scopeSlider:n,...r}=e,i=ur("SliderTrack",n);return(0,d.jsx)(iS.sG.span,{"data-disabled":i.disabled?"":void 0,"data-orientation":i.orientation,...r,ref:t})},"SliderTrack")),uh="SliderRange",uu=f.forwardRef(h2(function(e,t){let{__scopeSlider:n,...r}=e,i=ur(uh,n),o=us(uh,n),s=f.useRef(null),a=(0,im.s)(t,s),l=i.values.length,c=i.values.map(e=>uv(e,i.min,i.max)),h=l>1?Math.min(...c):0,u=100-Math.max(...c);return(0,d.jsx)(iS.sG.span,{"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,...r,ref:a,style:{...e.style,[o.startEdge]:h+"%",[o.endEdge]:u+"%"}})},"SliderRange")),[up,uf]=ue("SliderThumb");function ug(e){let{__scopeSlider:t,name:n,children:r,internal_do_not_use_render:i}=e,o=ur("SliderThumbProvider",t),s=h9(t),[a,l]=f.useState(null),c=f.useMemo(()=>a?s().findIndex(e=>e.ref.current===a):-1,[s,a]),h=(0,h0.X)(a),u=!a||!!o.form||!!a.closest("form"),p=o.values[c],g=n??(o.name?o.name+(o.values.length>1?"[]":""):void 0),m=void 0===p?0:uv(p,o.min,o.max);f.useEffect(()=>{if(a)return o.thumbs.add(a),()=>{o.thumbs.delete(a)}},[a,o.thumbs]);let y={value:p,name:g,form:o.form,isFormControl:u,index:c,thumb:a,onThumbChange:l,percent:m,size:h};return(0,d.jsx)(up,{scope:t,...y,children:uA(i)?i(y):r})}h2(ug,"SliderThumbProvider");var um="SliderThumbTrigger",uy=f.forwardRef(h2(function(e,t){let{__scopeSlider:n,...r}=e,i=ur(um,n),o=us(um,n),{index:s,value:a,percent:l,size:c,onThumbChange:h}=uf(um,n),u=(0,im.s)(t,h),p=uS(s,i.values.length),f=c?.[o.size],g=f?uk(f,l,o.direction):0;return(0,d.jsx)("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[o.startEdge]:`calc(${l}% + ${g}px)`},children:(0,d.jsx)(h8.ItemSlot,{scope:n,children:(0,d.jsx)(iS.sG.span,{role:"slider","aria-label":e["aria-label"]||p,"aria-valuemin":i.min,"aria-valuenow":a,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...r,ref:u,style:void 0===a?{display:"none"}:e.style,onFocus:(0,ig.mK)(e.onFocus,()=>{i.valueIndexToChangeRef.current=s})})})})},"SliderThumbTrigger")),ub=f.forwardRef(h2(function(e,t){let{__scopeSlider:n,name:r,...i}=e;return(0,d.jsx)(ug,{__scopeSlider:n,name:r,internal_do_not_use_render:({index:e,isFormControl:r})=>(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(uy,{...i,ref:t,__scopeSlider:n}),r?(0,d.jsx)(ux,{__scopeSlider:n},e):null]})})},"SliderThumb")),ux=f.forwardRef(h2(function({__scopeSlider:e,...t},n){let{value:r,name:i,form:o}=uf("SliderBubbleInput",e),s=f.useRef(null),a=(0,im.s)(s,n),l=hQ(r);return f.useEffect(()=>{let e=s.current;if(!e)return;let t=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value").set;if(l!==r&&t){let n=new Event("input",{bubbles:!0});t.call(e,r),e.dispatchEvent(n)}},[l,r]),(0,d.jsx)(iS.sG.input,{style:{display:"none"},name:i,form:o,...t,ref:a,defaultValue:r})},"SliderBubbleInput"));function uw(e=[],t,n){let r=[...e];return r[n]=t,r.sort((e,t)=>e-t)}function uv(e,t,n){return hZ(100/(n-t)*(e-t),[0,100])}function uS(e,t){return t>2?`Value ${e+1} of ${t}`:2===t?["Minimum","Maximum"][e]:void 0}function uC(e,t){if(1===e.length)return 0;let n=e.map(e=>Math.abs(e-t)),r=Math.min(...n);return n.indexOf(r)}function uk(e,t,n){let r=e/2,i=uE([0,50],[0,r]);return(r-i(t)*n)*n}function uP(e){return e.slice(0,-1).map((t,n)=>e[n+1]-t)}function uT(e,t){return!(t>0)||Math.min(...uP(e))>=t}function uE(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];let r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function uI(e){if(!Number.isFinite(e))return 0;let t=e.toString();if(t.includes("e")){let[e,n]=t.split("e"),r=e.split(".")[1]||"",i=Number(n);return Math.max(0,r.length-i)}let n=t.split(".")[1];return n?n.length:0}function u_(e,t){let n=Math.pow(10,t);return Math.round(e*n)/n}function uM(e,{min:t,step:n,direction:r,multiplier:i}){let o,s=uI(n),a=(e-t)/n,l=Math.round(a);return o=u_(l*n+t,s)===u_(e,s)?l+i*r:r>0?Math.ceil(a):Math.floor(a),u_(o*n+t,s)}function uA(e){return"function"==typeof e}h2(uw,"getNextSortedValues"),h2(uv,"convertValueToPercentage"),h2(uS,"getLabel"),h2(uC,"getClosestValueIndex"),h2(uk,"getThumbInBoundsOffset"),h2(uP,"getStepsBetweenValues"),h2(uT,"hasMinStepsBetweenValues"),h2(uE,"linearScale"),h2(uI,"getDecimalCount"),h2(u_,"roundValue"),h2(uM,"getNextStepValue"),h2(uA,"isFunction");let uj=f.forwardRef(function({onHistoryMark:e,title:t,min:n,steps:i,value:o,label:s,onValueChange:a,"data-testid":l,ariaValueModifier:c=1},h){let u=M(),p=A(),[g,m]=(0,f.useState)(""),[y,b]=(0,f.useState)(-1);(0,f.useEffect)(()=>{b(0)},[]);let x=(0,f.useCallback)(e=>{a(e[0])},[a]),w=(0,f.useCallback)(()=>{on(),e?.("click slider")},[e]);(0,f.useEffect)(()=>{let e=r.slq.setTimeout("set title and label",()=>{m(t+" — "+u(s))},0);return()=>clearTimeout(e)},[s,u,t]);let v=(0,f.useCallback)(e=>{"Tab"===e.key&&e.stopPropagation()},[]);return(0,d.jsx)("div",{className:"tlui-slider__container",children:(0,d.jsx)(oa,{content:g,children:(0,d.jsxs)(ui,{"data-testid":l,className:"tlui-slider",dir:p,min:n??0,max:i,step:1,value:null!==o?[o]:void 0,onPointerDown:w,onValueChange:x,onKeyDownCapture:v,onKeyUpCapture:v,children:[(0,d.jsx)(uc,{className:"tlui-slider__track",dir:p,children:null!==o&&(0,d.jsx)(uu,{className:"tlui-slider__range",dir:p})}),null!==o&&(0,d.jsx)(ub,{"aria-valuemin":(n??0)*c,"aria-valuenow":o*c,"aria-valuemax":i*c,"aria-label":g,className:"tlui-slider__thumb",dir:p,ref:h,tabIndex:y})]})})})}),uO=(0,f.createContext)(null);function uD({children:e,styles:t}){let n=(0,r.hGv)(),i=sF(),o=(0,f.useCallback)(e=>n.markHistoryStoppingPoint(e),[n]),s=(0,r.hau)("enhancedA11yMode",()=>n.user.getEnhancedA11yMode(),[n]),a=(0,f.useCallback)(function(e,t){let o=(0,r.PmD)(()=>n.getSelectedShapeIds().length>0&&n.inputs.getAccelKey());n.run(()=>{n.isIn("select")&&n.setStyleForSelectedShapes(e,t),o||n.setStyleForNextShapes(e,t),n.updateInstanceState({isChangingStyle:!0})}),i("set-style",{source:"style-panel",id:e.id,value:t})},[n,i]),l=(0,f.useCallback)(function(e){let t=(0,r.PmD)(()=>n.getSelectedShapeIds().length>0&&n.inputs.getAccelKey());n.run(()=>{n.isIn("select")&&n.setOpacityForSelectedShapes(e),t||n.setOpacityForNextShapes(e),n.updateInstanceState({isChangingStyle:!0})}),i("set-style",{source:"style-panel",id:"opacity",value:e})},[n,i]);return(0,d.jsx)(uO.Provider,{value:{styles:t,enhancedA11yMode:s,onHistoryMark:o,onValueChange:a,onOpacityChange:l},children:e})}function uL(){let e=(0,f.useContext)(uO);if(!e)throw Error("useStylePanelContext must be used within a StylePanelContextProvider");return e}function uR({children:e}){return(0,d.jsx)("h3",{className:"tlui-style-panel__subheading",children:e})}let uF=(0,f.memo)(function(e){let{enhancedA11yMode:t}=uL();return(0,d.jsxs)(d.Fragment,{children:[t&&(0,d.jsx)(uR,{children:e.title}),(0,d.jsx)(aw,{label:e.title,children:(0,d.jsx)(uz,{...e})})]})}),uz=(0,f.memo)(function(e){let t=uL(),{uiType:n,items:i,title:o,style:s,value:a,onValueChange:l=t.onValueChange,onHistoryMark:c=t.onHistoryMark}=e,h=(0,r.hGv)(),u=(0,r.hau)("style panel button picker colors",()=>h.getCurrentTheme().colors[h.getColorMode()],[h]),p=M(),g=sn(),m=(0,f.useRef)(!1),y=(0,f.useRef)(null),{handleButtonClick:b,handleButtonPointerDown:x,handleButtonPointerEnter:w,handleButtonPointerUp:v}=(0,f.useMemo)(()=>{let e=()=>{m.current=!1,h.getContainerWindow().removeEventListener("pointerup",e);let t=y.current;t&&(0,r.oOb)(t,!1)?t.focus():g>=5&&h.getContainer().focus(),y.current=null};return{handleButtonClick:e=>{let{id:t}=e.currentTarget.dataset;("shared"!==a.type||a.value!==t)&&(c?.("point picker item"),l(s,t))},handleButtonPointerDown:t=>{let{id:n}=t.currentTarget.dataset;c?.("point picker item"),l(s,n),m.current=!0,y.current=h.getContainerDocument().activeElement,h.getContainerWindow().addEventListener("pointerup",e)},handleButtonPointerEnter:e=>{if(!m.current)return;let{id:t}=e.currentTarget.dataset;l(s,t)},handleButtonPointerUp:e=>{if(!m.current)return;let{id:t}=e.currentTarget.dataset;("shared"!==a.type||a.value!==t)&&l(s,t)}}},[h,g,a,c,l,s]),S=i.length>4?i7:i8;return(0,d.jsx)(aS,{"data-testid":`style.${n}`,type:"single",value:"shared"===a.type?a.value:null,asChild:!0,children:(0,d.jsx)(S,{children:i.map(e=>{let t="shared"===a.type&&a.value===e.value,i=o+" — "+p(`${n}-style.${e.value}`);return(0,d.jsx)(aC,{type:"icon","data-id":e.value,"data-testid":`style.${n}.${e.value}`,"aria-label":i+(t?` (${p("style-panel.selected")})`:""),tooltip:(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{children:i}),t?(0,d.jsxs)("div",{children:["(",p("style-panel.selected"),")"]}):null]}),value:e.value,"data-state":"shared"===a.type&&a.value===e.value?"on":"off","data-isactive":t,title:i,style:s===r.ive?{color:(0,r.FHQ)(u,e.value,"solid")}:void 0,onPointerEnter:w,onPointerDown:x,onPointerUp:v,onClick:b,children:(0,d.jsx)(oH,{icon:e.icon})},e.value)})})})}),uN=f.memo(function(e){let t=M();return(0,d.jsxs)("div",{className:"tlui-style-panel__double-select-picker",children:[(0,d.jsx)("div",{title:t(e.label),className:"tlui-style-panel__double-select-picker-label",children:t(e.label)}),(0,d.jsx)(aw,{orientation:"horizontal",label:t(e.label),children:(0,d.jsx)(u$,{...e})})]})}),u$=f.memo(function(e){let t=uL(),{uiTypeA:n,uiTypeB:i,labelA:o,labelB:s,itemsA:a,itemsB:l,styleA:c,styleB:h,valueA:u,valueB:p,onValueChange:g=t.onValueChange}=e,m=(0,r.hGv)(),y=M(),[b,x]=f.useState(!1),[w,v]=f.useState(!1),S=f.useMemo(()=>a.find(e=>"shared"===u.type&&u.value===e.value)?.icon??"mixed",[a,u]),C=f.useMemo(()=>l.find(e=>"shared"===p.type&&p.value===e.value)?.icon??"mixed",[l,p]);if(void 0===u&&void 0===p)return null;let k=`style panel ${n} A`,P=`style panel ${i} B`;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(l4,{id:k,open:b,onOpenChange:x,children:[(0,d.jsx)(l8,{children:(0,d.jsx)(av,{type:"icon","data-testid":`style.${n}`,title:y(o)+" — "+(null===u||"mixed"===u.type?y("style-panel.mixed"):y(`${n}-style.${u.value}`)),children:(0,d.jsx)(oH,{icon:S,small:!0,invertIcon:!0})})}),(0,d.jsx)(l9,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:(0,d.jsx)(aw,{orientation:"grid",label:y(o),children:(0,d.jsx)(so,{type:"icons",sourceId:"style-panel",children:a.map(e=>(0,d.jsx)(av,{"data-testid":`style.${n}.${e.value}`,type:"icon",onClick:()=>{g(c,e.value),r.NlK.deleteOpenMenu(k,m.contextId),x(!1)},title:`${y(o)} \u2014 ${y(`${n}-style.${e.value}`)}`,children:(0,d.jsx)(oH,{icon:e.icon,invertIcon:!0})},e.value))})})})]}),(0,d.jsxs)(l4,{id:P,open:w,onOpenChange:v,children:[(0,d.jsx)(l8,{children:(0,d.jsx)(av,{type:"icon","data-testid":`style.${i}`,title:y(s)+" — "+(null===p||"mixed"===p.type?y("style-panel.mixed"):y(`${i}-style.${p.value}`)),children:(0,d.jsx)(oH,{icon:C,small:!0})})}),(0,d.jsx)(l9,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:(0,d.jsx)(aw,{orientation:"grid",label:y(s),children:(0,d.jsx)(so,{type:"icons",sourceId:"style-panel",children:l.map(e=>(0,d.jsx)(av,{type:"icon",title:`${y(s)} \u2014 ${y(`${i}-style.${e.value}`)}`,"data-testid":`style.${i}.${e.value}`,onClick:()=>{g(h,e.value),r.NlK.deleteOpenMenu(P,m.contextId),v(!1)},children:(0,d.jsx)(oH,{icon:e.icon})},e.value))})})})]})]})}),uB=f.memo(function(e){let t=M()(e.label?e.label:`style-panel.${e.stylePanelType}`);return(0,d.jsx)(aw,{label:t,children:(0,d.jsx)(uH,{...e})})}),uH=f.memo(function(e){let t=uL(),{id:n,label:i,uiType:o,stylePanelType:s,isOverflow:a,style:l,items:c,type:h,value:u,onValueChange:p=t.onValueChange,testIdType:g=o,sideOffset:m=8}=e,y=M(),b=(0,r.hGv)(),[x,w]=f.useState(!1),v=f.useMemo(()=>"mixed"===u.type?"mixed":c.find(e=>e.value===u.value)?.icon??c[0]?.icon,[c,u]),S=y(`style-panel.${s}`),C="mixed"!==u.type&&c.some(e=>e.value===u.value),k="mixed"===u.type?y("style-panel.mixed"):C?S+" — "+y(`${o}-style.${u.value}`):S,P=i?y(i):"",T=`style panel ${n}`;return(0,d.jsxs)(l4,{id:T,open:x,onOpenChange:w,className:"tlui-style-panel__dropdown-picker",children:[(0,d.jsx)(l8,{children:(0,d.jsxs)(av,{type:h,"data-testid":`style.${g}`,"data-direction":"left",isActive:a&&C,title:k,children:[P&&(0,d.jsx)(oc,{children:P}),(0,d.jsx)(oH,{icon:v})]})}),(0,d.jsx)(l9,{side:"left",align:"center",sideOffset:m,children:(0,d.jsx)(aw,{orientation:c.length>4?"grid":"horizontal",label:P,children:(0,d.jsx)(so,{type:"icons",sourceId:"style-panel",children:c.map(e=>(0,d.jsx)(av,{type:"icon","data-testid":`style.${g}.${e.value}`,title:S+" — "+y(`${o}-style.${e.value}`),isActive:C&&v===e.icon,onClick:()=>{t.onHistoryMark("select style dropdown item"),p(l,e.value),r.NlK.deleteOpenMenu(T,b.contextId),w(!1)},children:(0,d.jsx)(oH,{icon:e.icon})},e.value))})})})]})});function uU(){return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(uK,{children:[(0,d.jsx)(uW,{}),(0,d.jsx)(uY,{})]}),(0,d.jsxs)(uK,{children:[(0,d.jsx)(uG,{}),(0,d.jsx)(uq,{}),(0,d.jsx)(uX,{})]}),(0,d.jsxs)(uK,{children:[(0,d.jsx)(uJ,{}),(0,d.jsx)(uZ,{}),(0,d.jsx)(uQ,{})]}),(0,d.jsxs)(uK,{children:[(0,d.jsx)(u0,{}),(0,d.jsx)(u1,{}),(0,d.jsx)(u2,{}),(0,d.jsx)(u3,{})]})]})}function uK({children:e}){return(0,d.jsx)("div",{className:"tlui-style-panel__section",children:e})}function uW(){let e=(0,r.hGv)(),{styles:t}=uL(),n=M(),i=t.get(r.ive),o=(0,r.hau)("style panel color items",()=>(function(e){let t=[],n=new Set;for(let i of r.ive.values)if(i in e&&hz(e[i])){if("white"===i)continue;t.push({value:i,icon:"color"}),n.add(i)}for(let[r,i]of Object.entries(e))!n.has(r)&&"white"!==r&&hz(i)&&t.push({value:r,icon:"color"});return t})(e.getCurrentTheme().colors[e.getColorMode()]),[e]);return void 0===i?null:(0,d.jsx)(uF,{title:n("style-panel.color"),uiType:"color",style:r.ive,items:o,value:i})}let uV=[.1,.25,.5,.75,1];function uY(){let e=(0,r.hGv)(),{onHistoryMark:t,onOpacityChange:n,enhancedA11yMode:i}=uL(),o=(0,r.hau)("opacity",()=>e.getSharedOpacity(),[e]),s=M(),a=f.useCallback(e=>{n(uV[e])},[n]);if(void 0===o)return null;let l="mixed"===o.type?-1:uV.indexOf((0,r.wql)(uV,e=>Math.abs(e-o.value)));return(0,d.jsxs)(d.Fragment,{children:[i&&(0,d.jsx)(uR,{children:s("style-panel.opacity")}),(0,d.jsx)(uj,{"data-testid":"style.opacity",value:l>=0?l:uV.length-1,label:"mixed"===o.type?"style-panel.mixed":`opacity-style.${o.value}`,onValueChange:a,steps:uV.length-1,title:s("style-panel.opacity"),onHistoryMark:t,ariaValueModifier:25})]})}function uG(){let{styles:e,enhancedA11yMode:t}=uL(),n=M(),i=e.get(r.u8f);if(void 0===i)return null;let o=n("style-panel.fill");return(0,d.jsxs)(d.Fragment,{children:[t&&(0,d.jsx)(uR,{children:o}),(0,d.jsxs)(aw,{orientation:"horizontal",label:o,children:[(0,d.jsx)(uz,{title:o,uiType:"fill",style:r.u8f,items:hB,value:i}),(0,d.jsx)(uH,{type:"icon",id:"fill-extra",uiType:"fill",testIdType:"fill-extra",stylePanelType:"fill",style:r.u8f,items:hH,value:i,sideOffset:116,isOverflow:!0})]})]})}function uq(){let{styles:e}=uL(),t=M(),n=e.get(r.Pe6);return void 0===n?null:(0,d.jsx)(uF,{title:t("style-panel.dash"),uiType:"dash",style:r.Pe6,items:hU,value:n})}function uX(){let e=(0,r.hGv)(),{styles:t,onValueChange:n}=uL(),i=M(),o=t.get(r.Sg3);return void 0===o?null:(0,d.jsx)(uF,{title:i("style-panel.size"),uiType:"size",style:r.Sg3,items:hK,value:o,onValueChange:(t,i)=>{n(t,i);let o=e.getSelectedShapeIds();o.length>0&&(0,r.IeP)(e,o)}})}function uJ(){let e=(0,r.hGv)(),{styles:t}=uL(),n=M(),i=t.get(r.yes),o=(0,r.hau)("style panel font items",()=>(function(e){let t=[],n=new Set;for(let i of r.yes.values){let o=e.fonts[i];i in e.fonts&&(0,r.GYP)(o)&&(t.push({value:i,icon:h$(o,i)}),n.add(i))}for(let[i,o]of Object.entries(e.fonts))!n.has(i)&&(0,r.GYP)(o)&&t.push({value:i,icon:h$(o,i)});return t})(e.getCurrentTheme()),[e]);return void 0===i?null:(0,d.jsx)(uF,{title:n("style-panel.font"),uiType:"font",style:r.yes,items:o,value:i})}function uZ(){let{styles:e,enhancedA11yMode:t}=uL(),n=M(),i=e.get(r.nM1);if(void 0===i)return null;let o=n("style-panel.align");return(0,d.jsxs)(d.Fragment,{children:[t&&(0,d.jsx)(uR,{children:o}),(0,d.jsxs)(aw,{orientation:"horizontal",label:o,children:[(0,d.jsx)(uz,{title:o,uiType:"align",style:r.nM1,items:hW,value:i}),(0,d.jsx)(av,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:(0,d.jsx)(oH,{icon:"vertical-align-middle"})})]})]})}function uQ(){let{styles:e,enhancedA11yMode:t}=uL(),n=M(),i=e.get(r.yMj),o=e.get(r.YUb);if(void 0===i)return null;let s=n("style-panel.label-align");return(0,d.jsxs)(d.Fragment,{children:[t&&(0,d.jsx)(uR,{children:s}),(0,d.jsxs)(aw,{orientation:"horizontal",label:s,children:[(0,d.jsx)(uz,{title:s,uiType:"align",style:r.yMj,items:hV,value:i}),void 0===o?(0,d.jsx)(av,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:(0,d.jsx)(oH,{icon:"vertical-align-middle"})}):(0,d.jsx)(uH,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",stylePanelType:"vertical-align",style:r.YUb,items:hY,value:o,sideOffset:116})]})]})}function u0(){let e=(0,r.hGv)(),{styles:t}=uL(),n=t.get(r.tg8);if(void 0===n)return null;let i=e.getShapeUtil("geo").options.customGeoTypes,o=Object.entries({...hj,...i}).map(([e,t])=>({value:e,icon:t.icon}));return(0,d.jsx)(uB,{label:"style-panel.geo",type:"menu",id:"geo",uiType:"geo",stylePanelType:"geo",style:r.tg8,items:o,value:n})}function u1(){let{styles:e}=uL(),t=e.get(r.qfG);return void 0===t?null:(0,d.jsx)(uB,{id:"arrow-kind",type:"menu",label:"style-panel.arrow-kind",uiType:"arrow-kind",stylePanelType:"arrow-kind",style:r.qfG,items:hG,value:t})}function u2(){let{styles:e}=uL(),t=e.get(r.srS),n=e.get(r.roz);return void 0===t||void 0===n?null:(0,d.jsx)(uN,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:r.roz,itemsA:hq,valueA:n,uiTypeB:"arrowheadEnd",styleB:r.srS,itemsB:hX,valueB:t,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}function u3(){let{styles:e}=uL(),t=e.get(r.eBK);return void 0===t?null:(0,d.jsx)(uB,{type:"menu",id:"spline",uiType:"spline",stylePanelType:"spline",label:"style-panel.spline",style:r.eBK,items:hJ,value:t})}let u5=(0,f.memo)(function({isMobile:e,styles:t,children:n}){let i=(0,r.hGv)(),o=(0,r.hau)("enhancedA11yMode",()=>i.user.getEnhancedA11yMode(),[i]),s=(0,f.useRef)(null);(0,r.I9L)(s);let a=hM();return void 0===t&&(t=a),(0,f.useEffect)(()=>{let e=s.current;if(e)return e.addEventListener("pointermove",t),e.addEventListener("keydown",n,{capture:!0}),()=>{e.removeEventListener("pointermove",t),e.removeEventListener("keydown",n,{capture:!0})};function t(e){i.markEventAsHandled(e)}function n(e){"Escape"===e.key&&s.current?.contains(i.getContainerDocument().activeElement)&&(e.stopPropagation(),i.getContainer().focus())}},[i]),t&&(0,d.jsx)("div",{ref:s,"data-testid":"style.panel",className:ip("tlui-style-panel",{"tlui-style-panel__wrapper":!e}),"data-ismobile":e,"data-enhanced-a11y-mode":o,children:(0,d.jsx)(uD,{styles:t,children:n??(0,d.jsx)(uU,{})})})}),u6={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function u4({toast:e}){let{removeToast:t}=ls(),n=M(),r=e.actions&&e.actions.length>0,i=e.icon||e.severity&&u6[e.severity],o=e.iconLabel||(e.severity?n(`toast.${e.severity}`):"");return(0,d.jsxs)(aJ,{onOpenChange:n=>{n||t(e.id)},className:"tlui-toast__container",duration:e.keepOpen?1/0:4e3,"data-severity":e.severity,children:[i&&(0,d.jsx)("div",{className:"tlui-toast__icon",children:(0,d.jsx)(o$,{label:o,icon:i})}),(0,d.jsxs)("div",{className:"tlui-toast__main","data-title":!!e.title,"data-description":!!e.description,"data-actions":!!e.actions,children:[(0,d.jsxs)("div",{className:"tlui-toast__content",children:[e.title&&(0,d.jsx)(a2,{className:"tlui-toast__title",children:e.title}),e.description&&(0,d.jsx)(a3,{className:"tlui-toast__description",children:e.description})]}),e.actions&&(0,d.jsxs)("div",{className:"tlui-toast__actions",children:[e.actions.map((e,t)=>(0,d.jsx)(a5,{altText:e.label,asChild:!0,onClick:e.onClick,children:(0,d.jsx)(od,{type:e.type,children:(0,d.jsx)(oc,{children:e.label})})},t)),(0,d.jsx)(a6,{asChild:!0,children:(0,d.jsx)(od,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:(0,d.jsx)(oc,{children:e.closeLabel??n("toast.close")})})})]})]}),!r&&(0,d.jsx)(a6,{asChild:!0,children:(0,d.jsx)(od,{type:"normal",className:"tlui-toast__close",children:(0,d.jsx)(oc,{children:e.closeLabel??n("toast.close")})})})]})}let u8=(0,f.memo)(function(){let{toasts:e}=ls(),t=(0,r.hau)("toasts",()=>e.get(),[]);return(0,d.jsxs)(d.Fragment,{children:[t.map(e=>(0,d.jsx)(u4,{toast:e},e.id)),(0,d.jsx)(aG,{className:"tlui-toast__viewport"})]})});function u9({children:e,className:t,isMousingDown:n,getSelectionBounds:i,changeOnlyWhenYChanges:o=!1,label:s}){let a=(0,r.hGv)(),l=(0,f.useRef)(null);(0,r.I9L)(l);let{isVisible:c,isInteractive:h,hide:u,show:p,position:g,move:m}=function(e){let t=(0,r.hGv)(),n=(0,f.useRef)({name:"hidden"}),[i,o]=(0,f.useState)(!1),[s,a]=(0,f.useState)(!1),[l,d]=(0,f.useState)({x:-1e3,y:-1e3}),c=(0,f.useRef)(new r.l2P(-1e3,-1e3)),h=(0,f.useRef)(new r.l2P(-1e3,-1e3)),u=(0,f.useRef)(-1),p=(0,f.useRef)(-1),g=(0,f.useCallback)((i,o,s=!1)=>{if(h.current.x=i,h.current.y=o,"hidden"===n.current.name||"showing"===n.current.name)return;clearTimeout(p.current);let a=()=>{var t,i;if("shown"===n.current.name&&(t=h.current,i=c.current,e?r.l2P.Sub(i,t).y**2>=256:r.l2P.Len2(r.l2P.Sub(i,t))>=256)){let{x:e,y:t}=h.current;c.current=new r.l2P(e,t),s?(0,aA.flushSync)(()=>d({x:e,y:t})):d({x:e,y:t})}};s?a():p.current=t.timers.setTimeout(a,150)},[t,e]),m=(0,f.useCallback)((e=!1)=>{switch(n.current.name){case"showing":clearTimeout(u.current),n.current={name:"hidden"};break;case"shown":n.current={name:"hiding"},o(!1),e?(n.current={name:"hidden"},a(!1)):u.current=t.timers.setTimeout(()=>{n.current={name:"hidden"},a(!1)},16)}},[t]);return{isVisible:s,isInteractive:i,show:(0,f.useCallback)(()=>{switch(n.current.name){case"hidden":n.current={name:"showing"},u.current=t.timers.setTimeout(()=>{let{x:e,y:t}=h.current;c.current=new r.l2P(e,t),d({x:e,y:t}),n.current={name:"shown"},a(!0),o(!0)},16);break;case"hiding":clearTimeout(u.current),n.current={name:"shown"},o(!0),g(h.current.x,h.current.y)}},[t,g]),hide:m,move:g,position:l}}(o),y=(0,f.useRef)(!1),[b,x]=(0,f.useState)(!1),w=(0,r.fpl)("content size update counter",0);(0,f.useEffect)(()=>{(0,r.vAR)(l.current);let e=new ResizeObserver(()=>{w.update(e=>e+1)});return e.observe(l.current),()=>e.disconnect()},[w]),(0,f.useEffect)(()=>{let e=w.get();return(0,r.wvh)("toolbar position",function(){let t=l.current;if(!t)return;let n=w.get();a.getCamera(),w.get();let o=function(e,t,n){let i=n()?.clone();if(!i)return;let o=e.getViewportScreenBounds();if(i.x-=o.x,i.y-=o.y,i.midY<16||i.midY>o.h-16||i.midX<16||i.midX>o.w-16)return;let s=u7(t.getBoundingClientRect());if(!s.width||!s.height)return;let{scrollLeft:a,scrollTop:l}=e.getContainer(),d=i.midX-s.w/2,c=i.y-s.h-8;return d=(0,r.qE8)(d,16,o.w-s.w-16),c=(0,r.qE8)(c,16,o.h-s.h-16),d+=a,c+=l,{x:d=Math.round(d),y:c=Math.round(c)}}(a,t,i);if(o){if("moving"===a.getCameraState()){let e=l.current;e&&e.style.setProperty("transform",`translate(${o.x}px, ${o.y}px)`)}else{let t=e!==n;m(o.x,o.y,t)}y.current||(y.current=!0,x(!0))}else y.current&&(y.current=!1,x(!1));e=n})},[a,i,w,m]);let v=(0,r.hau)("camera state",()=>a.getCameraState(),[a]);return(0,f.useEffect)(()=>{n||!b?u():p()},[b,v,n,p,u]),(0,f.useLayoutEffect)(()=>{let e=l.current;e&&(e.dataset.visible=`${c}`)},[c,g]),(0,f.useLayoutEffect)(()=>{let e=l.current;e&&e.style.setProperty("transform",`translate(${g.x}px, ${g.y}px)`)},[g]),(0,f.useLayoutEffect)(()=>{let e=l.current;e&&(e.dataset.interactive=`${h}`)},[h]),(0,d.jsx)("div",{ref:l,"data-interactive":!1,"data-visible":!1,"data-testid":"contextual-toolbar",className:ip("tlui-contextual-toolbar",t),onPointerDown:a.markEventAsHandled,children:(0,d.jsx)(aw,{orientation:"horizontal",className:"tlui-menu",label:s,tooltipSide:"top",children:e})})}function u7(e){return new r.azJ(e.x,e.y,e.width,e.height)}function pe({shapeId:e,onClose:t,source:n}){let i=(0,r.hGv)(),[o,s]=(0,f.useState)(()=>{let t=i.getShape(e);if(!t)return"";if(!("altText"in t.props))throw Error("Shape does not have altText property");return t.props.altText||""}),a=M(),l=(0,f.useRef)(null),c=sF(),h=i.getIsReadonly(),u=(0,f.useCallback)(()=>{c("set-alt-text",{source:n});let r=i.getShape(e);r&&(i.updateShapes([{id:r.id,type:r.type,props:{altText:o}}]),t())},[c,n,i,e,o,t]),p=(0,f.useCallback)(()=>t(),[t]);return(0,f.useEffect)(()=>{let e=i.getContainerDocument();function t(e){"Escape"===e.key&&(e.stopPropagation(),p())}return l.current?.select(),e.addEventListener("keydown",t,{capture:!0}),()=>{e.removeEventListener("keydown",t,{capture:!0})}},[i,p]),(0,f.useEffect)(()=>{let e=i.getContainerDocument(),t=t=>{let n=e.querySelector(".tlui-media__toolbar");n?.contains(t.target)||u()};return e.addEventListener("pointerdown",t,{capture:!0}),()=>{e.removeEventListener("pointerdown",t,{capture:!0})}},[i,u]),(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(oG,{ref:l,className:"tlui-media__toolbar-alt-text-input","data-testid":"media-toolbar.alt-text-input",value:o,placeholder:a("tool.media-alt-text-desc"),"aria-label":a("tool.media-alt-text-desc"),onValueChange:e=>s(e),onComplete:u,onCancel:p,disabled:h}),!h&&(0,d.jsx)(od,{title:a("tool.media-alt-text-confirm"),"data-testid":"tool.media-alt-text-confirm",type:"icon",onPointerDown:r.woC,onClick:()=>u(),children:(0,d.jsx)(oH,{small:!0,icon:"check"})})]})}let pt=(0,r.u4I)(function({imageShapeId:e,isManipulating:t,onEditAltTextStart:n,onManipulatingStart:i,onManipulatingEnd:o}){let s=(0,r.hGv)(),a=sF(),l=M(),c=(0,f.useRef)(null),h=s.getIsReadonly(),u=(0,r.hau)("crop",()=>s.getShape(e).props.crop,[s,e]),p=u?Math.min(1-(u.bottomRight.x-u.topLeft.x),1-(u.bottomRight.y-u.topLeft.y)):0,[g,m]=(0,f.useState)(u?Math.max(p,1-.3333333333333333):3),y=fo();(0,f.useEffect)(()=>{m(u?Math.max(p,1-.3333333333333333):3)},[u,p,g]);let b=(0,f.useCallback)(e=>s.markHistoryStoppingPoint(e),[s]),x=(0,f.useCallback)((e,t)=>Math.pow(e/t,1.5)*t,[]),w=u&&g?(0,r.wwY)(x(p,g),[0,g],[0,100],!0):0,v=(0,f.useCallback)(t=>{s.setCurrentTool("select.crop.idle");let n=Math.pow(t/100,.6666666666666666)*Math.min(1-.3333333333333333,g??1-.3333333333333333),r=s.getShape(e);if(!r)return;let i=function(e,t,n){let r,i,o=t.props.crop||$(),{width:s,height:a}=K(o),l=s/a,d=1+e*((n?1/(1-n):3)-1);l>1?i=(r=Math.min(1,1/d))/l:r=(i=Math.min(1,1/d))*l;let c=function(e,t,n,r=!0,i=!1){let o,s,{w:a,h:l}=U(e.props,e.props.crop??$()),d=e.props.crop||$(),c=e.x+e.props.w/2,h=e.y+e.props.h/2;if(r){let{x:e,y:t}=W(d);o=e,s=t}else o=.5,s=.5;let u=V(o,s,t,n,i),p=t*a,f=n*l;return{crop:u,w:p,h:f,x:c-p/2,y:h-f/2}}(t,r,i,!0,o.isCircle),h=Math.min(3,s/r);c.w*=h,c.h*=h;let u=t.x+t.props.w/2,p=t.y+t.props.h/2;return c.x=u-c.w/2,c.y=p-c.h/2,c}(n>=1?1:n/(2*(1-n)),r,g);s.updateShape({id:r.id,type:r.type,x:i.x,y:i.y,props:{w:i.w,h:i.h,crop:i.crop}}),a("set-style",{source:"image-toolbar",id:"zoom",value:t})},[s,a,e,g]),S=(0,f.useCallback)(()=>y["image-replace"].onSelect("image-toolbar"),[y]),C=(0,f.useCallback)(()=>y["download-original"].onSelect("image-toolbar"),[y]),k=(0,r.hau)("altText",()=>s.getShape(e).props.altText,[s,e]),P=(0,r.hau)("shapeAspectRatio",()=>{let t=s.getShape(e);return t.props.w/t.props.h},[s,e]),T=!u||(0,r.n4T)(u,$());return((0,f.useEffect)(()=>{t&&s.timers.setTimeout(()=>c.current?.focus(),0)},[s,t]),(0,f.useEffect)(()=>{function e(e){t&&("Escape"===e.key?(s.cancel(),o()):"Enter"===e.key&&(s.complete(),o()))}let n=c.current;return n&&n.addEventListener("keydown",e),()=>{n&&n.removeEventListener("keydown",e)}},[s,t,o]),t)?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(uj,{ref:c,value:w,label:"tool.image-zoom",onValueChange:v,onHistoryMark:b,min:0,steps:100,"data-testid":"tool.image-zoom",title:l("tool.image-zoom")}),(0,d.jsxs)(sN,{id:"image-toolbar-aspect-ratio",children:[(0,d.jsx)(s$,{children:(0,d.jsx)(av,{title:l("tool.aspect-ratio"),type:"icon","data-testid":"tool.image-aspect-ratio",children:(0,d.jsx)(oH,{icon:"corners"})})}),(0,d.jsx)(sB,{side:"top",align:"center",children:B.map(t=>{let n=!1;return T?"original"===t&&(n=!0):n="circle"===t?!!u.isCircle:"square"===t?!u?.isCircle&&(0,r.YY0)(P,H[t],.1):"original"!==t&&!T&&(0,r.YY0)(P,H[t],.01),(0,d.jsx)(sY,{onSelect:()=>{let n;(n=s.getShape(e))&&s.run(()=>{s.setCurrentTool("select.crop.idle");let i=function(e,t){let n,r;if("original"===e){let{w:e,h:n}=U(t.props,t.props.crop??$()),r=t.x+t.props.w/2,i=t.y+t.props.h/2;return{crop:$(),w:e,h:n,x:r-e/2,y:i-n/2}}let i=H[e],{w:o,h:s}=U(t.props,t.props.crop||$()),a=o/s,l=t.props.crop||$(),{width:d,height:c}=K(l),h=W(l),u=Math.min(1/d,1/c);if(0!==a&&Number.isFinite(a)&&0!==i){let e,t,l=d*o,h=c*s,u=Math.max(l,h);l>=h?t=(e=u)/i:e=(t=u)*i,n=e/o,r=t/s,n>1&&(n=1,r=a/i),r>1&&(r=1,n=i/a),n=Math.max(0,Math.min(1,n)),r=Math.max(0,Math.min(1,r))}else n=1,r=1;let p=Math.min(1/n,1/r);n*=p/u,r*=p/u,n=Math.max(0,Math.min(1,n)),r=Math.max(0,Math.min(1,r));let f=V(h.x,h.y,n,r,"circle"===e),g=f.bottomRight.x-f.topLeft.x,m=f.bottomRight.y-f.topLeft.y,y=1;d>0?y=t.props.w/(d*o):c>0&&(y=t.props.h/(c*s));let b=g*o*y,x=m*s*y;return{crop:f,w:b,h:x,x:t.x+t.props.w/2-b/2,y:t.y+t.props.h/2-x/2}}(t,n);s.markHistoryStoppingPoint("aspect ratio"),s.updateShape({id:e,type:"image",x:i.x,y:i.y,props:{crop:i.crop,w:i.w,h:i.h}}),(0,r.IeP)(s,[e])})},checked:n,title:l(`tool.aspect-ratio.${t}`),children:(0,d.jsx)(oc,{children:l(`tool.aspect-ratio.${t}`)})},t)})})]}),(0,d.jsx)(av,{type:"icon",onClick:o,"data-testid":"tool.image-crop-confirm",style:{borderLeft:"1px solid var(--tl-color-divider)",marginLeft:"2px"},title:l("tool.image-crop-confirm"),children:(0,d.jsx)(oH,{small:!0,icon:"check"})})]}):(0,d.jsxs)(d.Fragment,{children:[!h&&(0,d.jsx)(av,{type:"icon","data-testid":"tool.image-replace",onClick:S,title:l("tool.replace-media"),children:(0,d.jsx)(oH,{small:!0,icon:"tool-media"})}),!h&&(0,d.jsx)(av,{type:"icon",title:l("tool.image-crop"),onClick:i,"data-testid":"tool.image-crop",children:(0,d.jsx)(oH,{small:!0,icon:"crop"})}),(0,d.jsx)(av,{type:"icon",title:l("action.download-original"),onClick:C,"data-testid":"tool.image-download",children:(0,d.jsx)(oH,{small:!0,icon:"download"})}),(k||!h)&&(0,d.jsx)(av,{type:"icon",title:l("tool.media-alt-text"),"data-testid":"tool.image-alt-text",onClick:()=>{a("alt-text-start",{source:"image-toolbar"}),n()},children:(0,d.jsx)(oH,{small:!0,icon:"alt"})})]})});function pn({children:e}){let t=(0,r.hGv)(),n=(0,r.hau)("imageShape",()=>{let e=t.getOnlySelectedShape();return e&&"image"===e.type?e.id:null},[t]),i=(0,r.hau)("showToolbar",()=>t.isInAny("select.idle","select.pointing_shape","select.crop"),[t]),o=(0,r.hau)("locked",()=>!!n&&t.getShape(n)?.isLocked,[t,n]);return n&&i&&!o?(0,d.jsx)(pr,{imageShapeId:n,children:e},n):null}function pr({children:e,imageShapeId:t}){let n=(0,r.hGv)(),i=M(),o=(0,r.hau)("editor path",()=>n.isInAny("select.crop.cropping","select.crop.pointing_crop_handle","select.crop.translating_crop"),[n]),s=(0,r.hau)("camera",()=>n.getCamera(),[n]),a=(0,r.hau)("editor path",()=>n.isIn("select.crop."),[n]),l=(0,f.useRef)(void 0),c=(0,f.useCallback)(()=>{n.setCroppingShape(null),n.setCurrentTool("select.idle")},[n]),[h,u]=(0,f.useState)(!1),p=(0,f.useCallback)(()=>u(!0),[]),g=(0,f.useCallback)(()=>n.setCurrentTool("select.crop.idle"),[n]),m=(0,f.useCallback)(()=>u(!1),[]);(0,f.useEffect)(()=>{l.current=void 0},[s]);let y=(0,f.useCallback)(()=>{if(a&&l.current)return l.current;let e=n.getSelectionScreenBounds();if(!e)return;let t=new r.azJ(e.x,e.y,e.width,0);return l.current=t,t},[n,a]);return o?(l.current=void 0,null):(0,d.jsx)(u9,{className:"tlui-media__toolbar tlui-image__toolbar",getSelectionBounds:y,label:i("tool.image-toolbar-title"),children:e||(h?(0,d.jsx)(pe,{shapeId:t,onClose:m,source:"image-toolbar"}):(0,d.jsx)(pt,{imageShapeId:t,isManipulating:a,onEditAltTextStart:p,onManipulatingStart:g,onManipulatingEnd:c}))})}function pi({textEditor:e,onEditLinkStart:t}){let n=(0,r.hGv)(),i=sF(),o=M(),[s,a]=(0,f.useState)(0);return(0,f.useEffect)(function(){function t(){a(e=>e+1)}e.on("update",t),e.on("selectionUpdate",t)},[e]),(0,f.useEffect)(()=>{function e(e){t&&(0,r.gu7)(e)&&e.shiftKey&&"k"===e.key&&(e.preventDefault(),t())}let i=n.getContainerDocument();return i.addEventListener("keydown",e),()=>{i.removeEventListener("keydown",e)}},[n,t]),(0,f.useMemo)(()=>{function n(t,n){e.view&&(i("rich-text",{operation:t,source:"rich-text-menu"}),e.chain().focus()[n]().run())}return[{name:"bold",onSelect(){n("bold","toggleBold")}},{name:"italic",onSelect(){n("bold","toggleItalic")}},{name:"code",onSelect(){n("bold","toggleCode")}},t?{name:"link",onSelect(){t()}}:void 0,{name:"bulletList",onSelect(){n("bulletList","toggleBulletList")}},{name:"highlight",onSelect(){n("bulletList","toggleHighlight")}}].filter(Boolean)},[e,i,t]).map(({name:t,attrs:n,onSelect:i})=>{let s=!!e.view&&e.isActive(t,n);return(0,d.jsx)(av,{title:o(`tool.rich-text-${t}`),"data-testid":`rich-text.${t}`,type:"icon",isActive:s,onPointerDown:r.woC,onClick:i,role:"option","aria-pressed":s,children:(0,d.jsx)(oH,{small:!0,icon:t})},t)})}function po({textEditor:e,value:t,onClose:n}){let i=(0,r.hGv)(),[o,s]=(0,f.useState)(t),a=M(),l=(0,f.useRef)(null),c=sF(),h="rich-text-menu",u=o.startsWith("http")?o:`https://${o}`,p=(0,f.useCallback)(t=>{c("rich-text",{operation:"link-edit",source:h}),t.startsWith("http://")||t.startsWith("https://")||(t=`https://${t}`),e.chain().setLink({href:t}).run(),i.getInstanceState().isCoarsePointer?e.commands.blur():e.commands.focus(),n()},[c,h,e,i,n]),g=(0,f.useCallback)(()=>{c("rich-text",{operation:"link-remove",source:h}),e.chain().unsetLink().focus().run(),n()},[c,h,e,n]);return(0,f.useEffect)(()=>{let e=i.getContainerDocument(),t=t=>{let n=e.querySelector(".tlui-rich-text__toolbar");n?.contains(t.target)||(o?p(o):g())};return e.addEventListener("pointerdown",t,{capture:!0}),()=>{e.removeEventListener("pointerdown",t,{capture:!0})}},[i,p,g,o]),(0,f.useEffect)(()=>{l.current?.focus()},[o]),(0,f.useEffect)(()=>{s(t)},[t]),(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(oG,{ref:l,"data-testid":"rich-text.link-input",className:"tlui-rich-text__toolbar-link-input",value:o,onValueChange:e=>s(e),onComplete:p,onCancel:()=>n(),placeholder:"example.com","aria-label":"example.com"}),(0,d.jsx)(od,{className:"tlui-rich-text__toolbar-link-visit",title:a("tool.rich-text-link-visit"),type:"icon",onPointerDown:r.woC,onClick:()=>{c("rich-text",{operation:"link-visit",source:h}),(0,r.D1x)(u,"_blank"),n()},disabled:!o,children:(0,d.jsx)(oH,{small:!0,icon:"external-link"})}),(0,d.jsx)(od,{className:"tlui-rich-text__toolbar-link-remove",title:a("tool.rich-text-link-remove"),"data-testid":"rich-text.link-remove",type:"icon",onPointerDown:r.woC,onClick:g,children:(0,d.jsx)(oH,{small:!0,icon:"trash"})})]})}let ps=(0,r.u4I)(function({children:e}){let t=(0,r.hGv)(),n=(0,r.hau)("textEditor",()=>t.getRichTextEditor(),[t]);return t.getInstanceState().isCoarsePointer||!n?null:(0,d.jsx)(pa,{textEditor:n,children:e})});function pa({textEditor:e,children:t}){let n=(0,r.hGv)(),{isEditingLink:i,onEditLinkStart:o,onEditLinkClose:s}=function(e){let[t,n]=(0,f.useState)(!1);(0,f.useEffect)(()=>{if(!e)return void n(!1);let t=()=>{n(e.isActive("link"))};return e.view.dom.addEventListener("click",t),()=>{e.isInitialized&&e.view.dom.removeEventListener("click",t)}},[e,t]),(0,f.useEffect)(()=>{if(e&&e.isActive("link"))try{let{from:t,to:n}=(0,eg.ve)(e.state.doc.resolve(e.state.selection.from),e.schema.marks.link);e.state.selection.empty&&e.commands.setTextSelection({from:t,to:n})}catch{}},[e,t]);let r=(0,f.useCallback)(()=>{n(!0)},[]),i=(0,f.useCallback)(()=>{n(!1)},[]);return{isEditingLink:t,onEditLinkStart:r,onEditLinkClose:(0,f.useCallback)(()=>{if(n(!1),!e)return;let t=e.state.selection.from;e.commands.setTextSelection({from:t,to:t})},[e]),onEditLinkCancel:i}}(e),[a,l]=(0,f.useState)(null),c=(0,f.useRef)(void 0),h=function(e){let[t,n]=(0,f.useState)(!1);return(0,f.useEffect)(()=>{if(!e)return;let t=(0,r.sg1)(({isPointing:e})=>{n(e)},16),i=()=>t({isPointing:!0}),o=()=>t({isPointing:!1}),s=["touchstart","pointerdown","mousedown"],a=["touchend","pointerup","mouseup"];s.forEach(t=>{e.view.dom.addEventListener(t,i)});let l=e.view.dom.ownerDocument;return a.forEach(e=>{l.body.addEventListener(e,o)}),()=>{s.forEach(t=>{e.isInitialized&&e.view.dom.removeEventListener(t,i)}),a.forEach(e=>{l.body.removeEventListener(e,o)})}},[e]),t}(e),u=M(),p=(0,f.useCallback)(()=>{if(i)return c.current;let e=n.getContainerWindow().getSelection();if(!a||!e||0===e.rangeCount||e.isCollapsed)return;let t=[];for(let n=0;n<e.rangeCount;n++){let r=e.getRangeAt(n);t.push(u7(r.getBoundingClientRect()))}let o=r.azJ.Common(t);return c.current=o,o},[n,a,i]);return(0,f.useEffect)(()=>{let t=({editor:e})=>l(e.state.selection);return e.on("selectionUpdate",t),t({editor:e}),()=>{e.off("selectionUpdate",t)}},[e]),(0,d.jsx)(u9,{className:"tlui-rich-text__toolbar",getSelectionBounds:p,isMousingDown:h,changeOnlyWhenYChanges:!0,label:u("tool.rich-text-toolbar-title"),children:t||(i?(0,d.jsx)(po,{textEditor:e,value:e.isActive("link")?e.getAttributes("link").href:"",onClose:s}):(0,d.jsx)(pi,{textEditor:e,onEditLinkStart:o}))})}function pl(){let e=(0,r.hGv)(),t=M(),{orientation:n}=i4(),i=hM(),o=i?.get(r.ive),s=(0,r.hau)("mobile style panel current color",()=>{let t=e.getCurrentTheme().colors[e.getColorMode()];return o?.type==="shared"?(0,r.FHQ)(t,o.value,"solid"):(0,r.FHQ)(t,"black","solid")},[e,o]),a=(0,r.hau)("disable style panel",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),l=(0,f.useCallback)(t=>{t||e.updateInstanceState({isChangingStyle:!1})},[e]),{StylePanel:c}=fe();return c?(0,d.jsxs)(l4,{id:"mobile style menu",onOpenChange:l,children:[(0,d.jsx)(l8,{children:(0,d.jsx)(od,{type:"tool","data-testid":"mobile-styles.button",style:{color:a?"var(--tl-color-muted-1)":s},title:t("style-panel.title"),disabled:a,children:(0,d.jsx)(oH,{icon:a?"blob":o?.type==="mixed"?"mixed":"blob"})})}),(0,d.jsx)(l9,{side:"horizontal"===n?"top":"right",align:"end",children:c&&(0,d.jsx)(c,{isMobile:!0})})]}):null}function pd(){return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(ph,{}),(0,d.jsx)(pu,{}),(0,d.jsx)(pp,{}),(0,d.jsx)(pf,{}),(0,d.jsx)(pg,{}),(0,d.jsx)(pm,{}),(0,d.jsx)(py,{}),(0,d.jsx)(pb,{}),(0,d.jsx)(px,{}),(0,d.jsx)(pw,{}),(0,d.jsx)(pS,{}),(0,d.jsx)(pv,{}),(0,d.jsx)(pP,{}),(0,d.jsx)(pI,{}),(0,d.jsx)(pC,{}),(0,d.jsx)(pE,{}),(0,d.jsx)(pT,{}),(0,d.jsx)(pk,{}),(0,d.jsx)(p_,{}),(0,d.jsx)(pM,{}),(0,d.jsx)(pA,{}),(0,d.jsx)(pj,{}),(0,d.jsx)(pO,{}),(0,d.jsx)(pD,{}),(0,d.jsx)(pL,{}),(0,d.jsx)(pR,{}),(0,d.jsx)(pz,{}),(0,d.jsx)(pF,{})]})}function pc({tool:e}){var t;let n,i,o=(t=lO()[e],n=(0,r.hGv)(),i=t?.meta?.geo,(0,r.hau)("is tool selected",()=>{if(!t)return!1;let e=n.getCurrentToolId();return"geo"===e?i===n.getSharedStyles().getAsKnownValue(r.tg8):e===t.id},[n,t?.id,i]));return(0,d.jsx)(lL,{toolId:e,isSelected:o})}function ph(){return(0,d.jsx)(pc,{tool:"select"})}function pu(){return(0,d.jsx)(pc,{tool:"hand"})}function pp(){return(0,d.jsx)(pc,{tool:"draw"})}function pf(){return(0,d.jsx)(pc,{tool:"eraser"})}function pg(){return(0,d.jsx)(pc,{tool:"arrow"})}function pm(){return(0,d.jsx)(pc,{tool:"text"})}function py(){return(0,d.jsx)(pc,{tool:"note"})}function pb(){return(0,d.jsx)(lL,{toolId:"asset"})}function px(){return(0,d.jsx)(pc,{tool:"rectangle"})}function pw(){return(0,d.jsx)(pc,{tool:"ellipse"})}function pv(){return(0,d.jsx)(pc,{tool:"diamond"})}function pS(){return(0,d.jsx)(pc,{tool:"triangle"})}function pC(){return(0,d.jsx)(pc,{tool:"rhombus"})}function pk(){return(0,d.jsx)(pc,{tool:"heart"})}function pP(){return(0,d.jsx)(pc,{tool:"hexagon"})}function pT(){return(0,d.jsx)(pc,{tool:"cloud"})}function pE(){return(0,d.jsx)(pc,{tool:"star"})}function pI(){return(0,d.jsx)(pc,{tool:"oval"})}function p_(){return(0,d.jsx)(pc,{tool:"x-box"})}function pM(){return(0,d.jsx)(pc,{tool:"check-box"})}function pA(){return(0,d.jsx)(pc,{tool:"arrow-left"})}function pj(){return(0,d.jsx)(pc,{tool:"arrow-up"})}function pO(){return(0,d.jsx)(pc,{tool:"arrow-down"})}function pD(){return(0,d.jsx)(pc,{tool:"arrow-right"})}function pL(){return(0,d.jsx)(pc,{tool:"line"})}function pR(){return(0,d.jsx)(pc,{tool:"highlight"})}function pF(){return(0,d.jsx)(pc,{tool:"frame"})}function pz(){return(0,d.jsx)(pc,{tool:"laser"})}let pN=["copy","cut","paste","asset"];function p$(e){return e.menus.hasAnyOpenMenus()||null!==e.getEditingShapeId()||e.getCrashingError()||!e.user.getAreKeyboardShortcutsEnabled()}let pB={shift:"shift","⇧":"shift",alt:"alt",option:"alt","⌥":"alt",ctrl:"ctrl",control:"ctrl","⌃":"ctrl",cmd:"meta",command:"meta",meta:"meta","⌘":"meta"},pH={"⌫":"backspace","↩":"enter",return:"enter",esc:"escape",del:"delete",ins:"insert",left:"arrowleft",right:"arrowright",up:"arrowup",down:"arrowdown",space:" "},pU={"<":",",">":".","?":"/",":":";",'"':"'","{":"[","}":"]","|":"\\",_:"-","+":"=","~":"`","!":"1","@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0"},pK={KeyA:"a",KeyB:"b",KeyC:"c",KeyD:"d",KeyE:"e",KeyF:"f",KeyG:"g",KeyH:"h",KeyI:"i",KeyJ:"j",KeyK:"k",KeyL:"l",KeyM:"m",KeyN:"n",KeyO:"o",KeyP:"p",KeyQ:"q",KeyR:"r",KeyS:"s",KeyT:"t",KeyU:"u",KeyV:"v",KeyW:"w",KeyX:"x",KeyY:"y",KeyZ:"z",Digit0:"0",Digit1:"1",Digit2:"2",Digit3:"3",Digit4:"4",Digit5:"5",Digit6:"6",Digit7:"7",Digit8:"8",Digit9:"9",Comma:",",Period:".",Slash:"/",Semicolon:";",Quote:"'",BracketLeft:"[",BracketRight:"]",Backslash:"\\",Minus:"-",Equal:"=",Backquote:"`"};function pW(e,t){let n;if(e.shiftKey!==t.shift||e.altKey!==t.alt||e.ctrlKey!==t.ctrl||e.metaKey!==t.meta)return!1;if(e.shiftKey){let n=/^Digit([0-9])$/.exec(e.code);if(n)return t.key===n[1]}let r=(n=e.key.toLowerCase(),e.shiftKey&&pU[n]&&(n=pU[n]),n);return r===t.key||!(1===r.length&&/^[\x20-\x7e]$/.test(r))&&pK[e.code]===t.key}function pV(e){if(e.isComposing)return!0;let t=e.target;if(!t)return!1;if(t.isContentEditable)return!0;let n=t.tagName;return"SELECT"===n||("TEXTAREA"===n?!t.readOnly:"INPUT"===n&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type)&&!t.readOnly)}function pY(e){return pG(e).map(e=>{let t=e.includes("!"),n=e.includes("?"),r=e.includes("$"),i=e.replace(/[!?$]/g,"");return t&&n&&r?`cmd+shift+alt+${i},ctrl+shift+alt+${i}`:t&&r?`cmd+shift+${i},ctrl+shift+${i}`:n&&r?`cmd+alt+${i},ctrl+alt+${i}`:n&&t?`shift+alt+${i}`:t?`shift+${i}`:n?`alt+${i}`:r?`cmd+${i},ctrl+${i}`:i}).join(",")}function pG(e){"string"!=typeof e&&(e="");let t=(e=e.replace(/\s/g,"")).split(","),n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}let pq=(0,f.createContext)(!1),pX={1:0,2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,0:9};function pJ({children:e,orientation:t,sizingParentClassName:n,minItems:i,minSizePx:o,maxItems:s,maxSizePx:a}){let l=(0,r.hGv)(),c=(0,r.LsA)(),h=sn(),u=M(),p=(0,f.useRef)([]),[g,m]=(0,f.useState)(!1),y=(0,f.useRef)(null),[b,x]=(0,f.useState)(null),[w,v]=(0,f.useState)(null),[S,C]=(0,f.useState)(!1),k=(0,r._q_)(()=>{if(!y.current)return;let e="horizontal"===t?"offsetWidth":"offsetHeight",l=c(y.current.children),d=b?c(b.children):null;function c(e){let t=[];for(let n of e)n.classList.contains("tlui-main-toolbar__group")?t.push({type:"group",items:c(n.children),element:n}):n.hasAttribute("data-radix-popper-content-wrapper")||t.push({type:"item",element:n});return t}let h=pZ(y.current,n)[e],u=Math.floor((0,r.wwY)(h,[o,a],[i,s],!0)),f=0,g=null,m=!1,x=[],{didShowAnyInOverflow:S}=function e(t,n){n&&(0,r.vAR)(t.length===n.length);let i=!1,o=!1;for(let s=0;s<t.length;s++){let a=t[s],l=n?.[s];if("item"===a.type){let e,t=a.element.getAttribute("data-value")===w;e=w?f<u||t:f<=u;let n=f>=u;i||=e,o||=n,pQ(a.element,"data-toolbar-visible",e?"true":"false"),l&&((0,r.vAR)("item"===l.type),pQ(l.element,"data-toolbar-visible",n?"true":"false")),n&&"true"===a.element.getAttribute("aria-pressed")&&(g=a.element.getAttribute("data-value")),e&&"BUTTON"===a.element.tagName&&x.push(a.element),!n&&t&&(m=!0),f++}else{let t,n;l?((0,r.vAR)("group"===l.type),n=l,t=e(a.items,n.items)):t=e(a.items,null),i||=t.didShowAnyInMain,o||=t.didShowAnyInOverflow,pQ(a.element,"data-toolbar-visible",t.didShowAnyInMain?"true":"false"),n&&pQ(n.element,"data-toolbar-visible",t.didShowAnyInOverflow?"true":"false")}}return{didShowAnyInMain:i,didShowAnyInOverflow:o}}(l,d);C(S),g?v(g):m&&v(null),p.current=x});(0,f.useLayoutEffect)(()=>{k()}),(0,f.useLayoutEffect)(()=>{if(!y.current)return;let e=new MutationObserver(k);e.observe(y.current,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["aria-pressed","data-value"]});let t=pZ(y.current,n),r=new ResizeObserver(k);return r.observe(t),()=>{e.disconnect(),r.disconnect()}},[k,n]),(0,f.useEffect)(()=>{if(!l.options.enableToolbarKeyboardShortcuts)return;function e(e){if(p$(l)||(0,r.ghB)(!1,l.getContainerDocument())||e.ctrlKey||e.metaKey||e.altKey||e.shiftKey)return;let t=pX[e.key];"number"==typeof t&&((0,r.woC)(e),p.current[t]?.click())}let t=l.getContainerDocument();return t.addEventListener("keydown",e),()=>{t.removeEventListener("keydown",e)}},[l]);let P="toolbar overflow";return(0,d.jsx)(d.Fragment,{children:(0,d.jsxs)(aw,{orientation:t,className:ip("tlui-main-toolbar__tools",{"tlui-main-toolbar__tools__mobile":h<5}),label:u("tool-panel.title"),children:[(0,d.jsx)("horizontal"===t?i8:i9,{id:`${c}_main`,ref:y,children:(0,d.jsx)(so,{type:"toolbar",sourceId:"toolbar",children:e})}),S&&(0,d.jsx)(pq.Provider,{value:!0,children:(0,d.jsxs)(l4,{id:P,open:g,onOpenChange:m,children:[(0,d.jsx)(l8,{children:(0,d.jsx)(av,{title:u("tool-panel.more"),type:"tool",className:"tlui-main-toolbar__overflow","data-testid":"tools.more-button",children:(0,d.jsx)(oH,{icon:"horizontal"===t?"chevron-up":"chevron-right"})})}),(0,d.jsx)(l9,{side:"horizontal"===t?"top":"right",align:"horizontal"===t?"center":"end",children:(0,d.jsx)(aw,{orientation:"grid",className:"tlui-main-toolbar__overflow-content",ref:x,"data-testid":"tools.more-content",label:u("tool-panel.more"),id:`${c}_more`,onClick:()=>{r.NlK.deleteOpenMenu(P,l.contextId),m(!1)},children:(0,d.jsx)(so,{type:"toolbar-overflow",sourceId:"toolbar",children:e})})})]})})]})})}function pZ(e,t){let n=e;for(;n;){if(n.classList.contains(t))return n;n=n.parentElement}throw Error("Could not find parent with class name "+t)}function pQ(e,t,n){e.getAttribute(t)!==n&&e.setAttribute(t,n)}function p0({activeToolId:e}){let t=(0,r.hGv)(),n=sn(),i=M(),o=fo(),s=(0,r.hau)("is tool locked",()=>t.getInstanceState().isToolLocked,[t]),a=(0,r.hau)("current tool",()=>t.getCurrentTool(),[t]);if(!e||!a.isLockable)return null;let l=o["toggle-tool-lock"],c=l?.kbd?`${i("action.toggle-tool-lock")} ${sp(l.kbd)}`:i("action.toggle-tool-lock");return(0,d.jsx)(oa,{content:c,children:(0,d.jsx)(od,{type:"normal","data-testid":"tool-lock",className:ip("tlui-main-toolbar__lock-button",{"tlui-main-toolbar__lock-button__mobile":n<5}),onClick:()=>t.updateInstanceState({isToolLocked:!s}),children:(0,d.jsx)(oH,{icon:s?"lock":"unlock",small:!0})})})}let p1=(0,f.memo)(function({children:e,orientation:t="horizontal",minItems:n=4,minSizePx:i=310,maxItems:o,maxSizePx:s}){let a=(0,r.hGv)(),l=M(),c=sn(),h=sl(),u=(0,r.hau)("current tool id",()=>a.getCurrentToolId(),[a]),p=(0,f.useRef)(null);(0,r.I9L)(p);let{ActionsMenu:g,QuickActions:m}=fe(),y="menu"!==a.options.actionShortcutsLocation&&("toolbar"===a.options.actionShortcutsLocation||c<6);return(0,d.jsx)(i6,{orientation:t,tooltipSide:"horizontal"===t?"top":"right",children:(0,d.jsx)("div",{ref:p,className:ip("tlui-main-toolbar",`tlui-main-toolbar--${t}`),children:(0,d.jsxs)("div",{className:"tlui-main-toolbar__inner",children:[(0,d.jsxs)("div",{className:"tlui-main-toolbar__left",children:[!h&&(0,d.jsxs)("div",{className:"tlui-main-toolbar__extras",children:[y&&(0,d.jsxs)(aw,{orientation:t,className:"tlui-main-toolbar__extras__controls",label:l("actions-menu.title"),children:[m&&(0,d.jsx)(m,{}),g&&(0,d.jsx)(g,{})]}),(0,d.jsx)(p0,{activeToolId:u})]}),(0,d.jsx)(pJ,{orientation:t,sizingParentClassName:"tlui-main-toolbar",minItems:n,maxItems:o??8,minSizePx:i,maxSizePx:s??470,children:e??(0,d.jsx)(pd,{})})]}),c<5&&!h&&(0,d.jsx)("div",{className:"tlui-main-toolbar__tools tlui-main-toolbar__mobile-style-panel",children:(0,d.jsx)(pl,{})})]})})})}),p2=(0,r.u4I)(function({videoShapeId:e,onEditAltTextStart:t}){let n=(0,r.hGv)(),i=sF(),o=M(),s=n.getIsReadonly(),a=fo(),l=(0,f.useCallback)(()=>a["video-replace"].onSelect("video-toolbar"),[a]),c=(0,f.useCallback)(()=>a["download-original"].onSelect("video-toolbar"),[a]),h=(0,r.hau)("altText",()=>n.getShape(e).props.altText,[n,e]);return(0,d.jsxs)(d.Fragment,{children:[!s&&(0,d.jsx)(av,{type:"icon",title:o("tool.replace-media"),onClick:l,"data-testid":"tool.video-replace",children:(0,d.jsx)(oH,{small:!0,icon:"tool-media"})}),(0,d.jsx)(av,{type:"icon",title:o("action.download-original"),onClick:c,"data-testid":"tool.video-download",children:(0,d.jsx)(oH,{small:!0,icon:"download"})}),(h||!s)&&(0,d.jsx)(av,{type:"icon",isActive:!!h,title:o("tool.media-alt-text"),"data-testid":"tool.video-alt-text",onClick:()=>{i("alt-text-start",{source:"video-toolbar"}),t()},children:(0,d.jsx)(oH,{small:!0,icon:"alt"})})]})}),p3=(0,r.u4I)(function({children:e}){let t=(0,r.hGv)(),n=(0,r.hau)("videoShape",()=>{let e=t.getOnlySelectedShape();return e&&"video"===e.type?e.id:null},[t]),i=t.isInAny("select.idle","select.pointing_shape"),o=(0,r.hau)("locked",()=>!!n&&t.getShape(n)?.isLocked,[t,n]);return n&&i&&!o?(0,d.jsx)(p5,{videoShapeId:n,children:e},n):null});function p5({children:e,videoShapeId:t}){let n=(0,r.hGv)(),i=M(),[o,s]=(0,f.useState)(!1),a=(0,f.useCallback)(()=>s(!0),[]),l=(0,f.useCallback)(()=>s(!1),[]),c=(0,f.useCallback)(()=>{let e=n.getSelectionScreenBounds();if(e)return new r.azJ(e.x,e.y,e.width,0)},[n]);return(0,d.jsx)(u9,{className:"tlui-media__toolbar tlui-video__toolbar",getSelectionBounds:c,label:i("tool.video-toolbar-title"),children:e||(o?(0,d.jsx)(pe,{shapeId:t,onClose:l,source:"video-toolbar"}):(0,d.jsx)(p2,{videoShapeId:t,onEditAltTextStart:a}))})}function p6(){return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(aT,{actionId:"zoom-in",noClose:!0}),(0,d.jsx)(aT,{actionId:"zoom-out",noClose:!0}),(0,d.jsx)(dN,{}),(0,d.jsx)(d$,{}),(0,d.jsx)(dB,{})]})}let p4=(0,f.memo)(function({children:e}){let t=(0,r.NFA)(),[n,i]=sz("zoom menu"),o=A(),s=e??(0,d.jsx)(p6,{});return(0,d.jsxs)(sk,{dir:o,open:n,onOpenChange:i,modal:!1,children:[(0,d.jsx)(p8,{}),(0,d.jsx)(sT,{container:t,children:(0,d.jsx)(sE,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:(0,d.jsx)(so,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),p8=()=>{let e=(0,r.hGv)(),t=sn(),n=(0,r.hau)("zoom",()=>e.getZoomLevel(),[e]),i=M(),o=A(),s=(0,f.useCallback)(()=>{e.resetZoom(e.getViewportScreenCenter(),{animation:{duration:e.options.animationMediumMs}})},[e]),a=`${Math.floor(100*n)}%`;return(0,d.jsx)(av,{asChild:!0,type:"icon","aria-label":`${i("navigation-zone.zoom")} \u2014 ${a}`,title:`${i("navigation-zone.zoom")} \u2014 ${a}`,"data-testid":"minimap.zoom-menu-button",className:"tlui-zoom-menu__button",onDoubleClick:s,children:(0,d.jsx)(sP,{dir:o,children:t<4?null:(0,d.jsx)("span",{style:{flexGrow:0,textAlign:"center"},children:a})})})},p9=(0,f.createContext)(null);function p7({overrides:e={},children:t}){let n=(0,r.dSk)(e),i=ss();return(0,d.jsx)(p9.Provider,{value:(0,f.useMemo)(()=>({ContextMenu:cC,ActionsMenu:cv,HelpMenu:null,ZoomMenu:p4,MainMenu:ht,Minimap:hs,StylePanel:u5,PageMenu:hp,NavigationPanel:ha,Toolbar:p1,RichTextToolbar:ps,ImageToolbar:pn,VideoToolbar:p3,KeyboardShortcutsDialog:lF,QuickActions:hx,HelperButtons:cY,DebugPanel:cR,DebugMenu:cL,MenuPanel:cB,SharePanel:i?hT:null,CursorChatBubble:i?ck:null,TopPanel:null,Dialogs:cU,Toasts:u8,A11y:fh,FollowingIndicator:cN,PeopleMenu:hS,PeopleMenuAvatar:hC,PeopleMenuItem:hP,PeopleMenuFacePile:hk,UserPresenceEditor:hI,...n}),[n,i]),children:t})}function fe(){let e=(0,f.useContext)(p9);if(!e)throw Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return e}let ft=f.createContext(null);function fn(e,t){return(t.isShapeOfType(e,"image")||t.isShapeOfType(e,"video"))&&!!e.props.assetId}function fr(e,t){if(0===e.getSelectedShapes().length)return e.getDocumentSettings().name||t}function fi({overrides:e,children:t}){let n=(0,r.frr)(),i=ss(),o=lI(),s=fe(),a=sF(),l=w(),c=M(),h=o.msg("document.default-name"),u=f.useMemo(()=>{if(!n)return{};function t(){return n.isIn("select")||(n.complete(),n.setCurrentTool("select")),!1}function d(){return n.isIn("select")&&n.getSelectedShapeIds().length>0}function u(e){if(!d()||t())return;n.markHistoryStoppingPoint("resize shapes");let i=n.getSelectedShapeIds();0!==i.length&&n.run(()=>{i.map(e=>n.getShape(e)).filter(Boolean).forEach(t=>{n.resizeShape(t.id,new r.l2P(e,e),{scaleOrigin:n.getSelectionPageBounds()?.center})})})}let p=[{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(e){!d()||t()||(a("edit-link",{source:e}),n.markHistoryStoppingPoint("edit-link"),o.addDialog({component:oZ}))}},{id:"insert-embed",label:"action.insert-embed",kbd:"cmd+i,ctrl+i",onSelect(e){a("insert-embed",{source:e}),o.addDialog({component:o9})}},{id:"open-kbd-shortcuts",label:"action.open-kbd-shortcuts",kbd:"cmd+alt+/,ctrl+alt+/",onSelect(e){a("open-kbd-shortcuts",{source:e}),o.addDialog({component:s.KeyboardShortcutsDialog??lF})}},{id:"insert-media",label:"action.insert-media",kbd:"cmd+u,ctrl+u",onSelect(e){a("insert-media",{source:e}),o.insertMedia()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"cmd+z,ctrl+z",onSelect(e){a("undo",{source:e}),n.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"cmd+shift+z,ctrl+shift+z",onSelect(e){a("redo",{source:e}),n.redo()}},{id:"export-as-svg",label:{default:"action.export-as-svg",menu:"action.export-as-svg.short","context-menu":"action.export-as-svg.short"},readonlyOk:!0,onSelect(e){let t=n.getSelectedShapeIds();0===t.length&&(t=Array.from(n.getCurrentPageShapeIds().values())),0!==t.length&&(a("export-as",{format:"svg",source:e}),o.exportAs(t,{format:"svg",name:fr(n,h)}))}},{id:"export-as-png",label:{default:"action.export-as-png",menu:"action.export-as-png.short","context-menu":"action.export-as-png.short"},readonlyOk:!0,onSelect(e){let t=n.getSelectedShapeIds();0===t.length&&(t=Array.from(n.getCurrentPageShapeIds().values())),0!==t.length&&(a("export-as",{format:"png",source:e}),o.exportAs(t,{format:"png",name:fr(n,h)}))}},{id:"export-all-as-svg",label:{default:"action.export-all-as-svg",menu:"action.export-all-as-svg.short","context-menu":"action.export-all-as-svg.short"},readonlyOk:!0,onSelect(e){let t=n.getSelectedShapeIds();0===t.length&&(t=Array.from(n.getCurrentPageShapeIds().values())),0!==t.length&&(a("export-all-as",{format:"svg",source:e}),o.exportAs(Array.from(n.getCurrentPageShapeIds()),{format:"svg",name:fr(n,h)}))}},{id:"export-all-as-png",label:{default:"action.export-all-as-png",menu:"action.export-all-as-png.short","context-menu":"action.export-all-as-png.short"},readonlyOk:!0,onSelect(e){let t=Array.from(n.getCurrentPageShapeIds().values());0!==t.length&&(a("export-all-as",{format:"png",source:e}),o.exportAs(t,{format:"png",name:fr(n,h)}))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},readonlyOk:!0,onSelect(e){let t=n.getSelectedShapeIds();0===t.length&&(t=Array.from(n.getCurrentPageShapeIds().values())),0!==t.length&&(a("copy-as",{format:"svg",source:e}),o.copyAs(t,"svg"))}},{id:"copy-as-png",label:{default:"action.copy-as-png",menu:"action.copy-as-png.short","context-menu":"action.copy-as-png.short"},readonlyOk:!0,kbd:"cmd+shift+c,ctrl+shift+c",onSelect(e){let t=n.getSelectedShapeIds();0===t.length&&(t=Array.from(n.getCurrentPageShapeIds().values())),0!==t.length&&(a("copy-as",{format:"png",source:e}),o.copyAs(t,"png"))}},{id:"copy-as-json",label:{default:"action.copy-as-json",menu:"action.copy-as-json.short","context-menu":"action.copy-as-json.short"},readonlyOk:!0,onSelect(e){let t=n.getSelectedShapeIds();0===t.length&&(t=Array.from(n.getCurrentPageShapeIds().values())),0!==t.length&&(a("copy-as",{format:"json",source:e}),o.copyAs(t,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(e){!d()||t()||(a("toggle-auto-size",{source:e}),n.markHistoryStoppingPoint("toggling auto size"),n.run(()=>{let e=n.getSelectedShapes().filter(e=>n.isShapeOfType(e,"text")&&!1===e.props.autoSize);n.updateShapes(e.map(e=>({id:e.id,type:e.type,props:{...e.props,w:8,autoSize:!0}}))),(0,r.IeP)(n,e.map(e=>e.id))}))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(e){a("open-embed-link",{source:e});let t=n.getSelectedShapeIds(),i="No embed shapes selected";if(1!==t.length)return void console.error(i);let o=n.getShape(t[0]);o&&n.isShapeOfType(o,"embed")?(0,r.D1x)(o.props.url,"_blank"):console.error(i)}},{id:"select-zoom-tool",label:"action.select-zoom-tool",readonlyOk:!0,kbd:"z, !z",onSelect(e){if(n.inputs.getAccelKey())return;let t=n.getPath();t.endsWith(".idle")&&n.root.getCurrent()?.id!=="zoom"&&(a("zoom-tool",{source:e}),n.setCurrentTool("zoom",{onInteractionEnd:t,maskAs:"zoom"}))}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",async onSelect(e){if(!d()||t())return;a("convert-to-bookmark",{source:e});let r=n.getSelectedShapes(),i=n.markHistoryStoppingPoint("convert shapes to bookmark"),o=[];for(let e of r){if(!e||!n.isShapeOfType(e,"embed")||!e.props.url)continue;let t=n.getShapePageBounds(e)?.center;t&&(n.deleteShapes([e.id]),o.push(z(n,{url:e.props.url,center:t}).then(e=>{if(!e.ok)throw Error(e.error);return e})))}await Promise.all(o).catch(e=>{n.bailToMark(i),console.error(e)})}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(e){!d()||t()||(a("convert-to-embed",{source:e}),n.run(()=>{let e=n.getSelectedShapeIds(),t=(0,r.oE7)(e.map(e=>n.getShape(e))),i=[],s=[];for(let e of t){if(!n.isShapeOfType(e,"bookmark"))continue;let{url:t}=e.props,a=o.getEmbedDefinition(t);if(!a||!a.definition)continue;let{width:l,height:d}=a.definition,c=new r.l2P(e.x,e.y);c.rot(-e.rotation),c.add(new r.l2P(e.props.w/2-l/2,e.props.h/2-d/2)),c.rot(e.rotation);let h={id:(0,r.n6Y)(),type:"embed",x:c.x,y:c.y,rotation:e.rotation,props:{url:t,w:l,h:d}};i.push(h),s.push(e.id)}n.markHistoryStoppingPoint("convert shapes to embed"),n.deleteShapes(s),n.createShapes(i)}))}},{id:"duplicate",kbd:"cmd+d,ctrl+d",label:"action.duplicate",icon:"duplicate",onSelect(e){let i,o;if(!d()||t())return;a("duplicate-shapes",{source:e});let s=n.getInstanceState();if(s.duplicateProps)i=s.duplicateProps.shapeIds,o=s.duplicateProps.offset;else{i=n.getSelectedShapeIds();let e=r.azJ.Common((0,r.oE7)(i.map(e=>n.getShapePageBounds(e))));o=n.getCameraOptions().isLocked?{x:n.options.adjacentShapeMargin,y:n.options.adjacentShapeMargin}:{x:e.width+n.options.adjacentShapeMargin,y:0}}n.markHistoryStoppingPoint("duplicate shapes"),n.duplicateShapes(i,o),s.duplicateProps&&n.updateInstanceState({duplicateProps:{...s.duplicateProps,shapeIds:n.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"cmd+shift+g,ctrl+shift+g",icon:"ungroup",onSelect(e){!d()||t()||(a("ungroup-shapes",{source:e}),n.markHistoryStoppingPoint("ungroup"),n.ungroupShapes(n.getSelectedShapeIds()))}},{id:"group",label:"action.group",kbd:"cmd+g,ctrl+g",icon:"group",onSelect(e){if(!d()||t())return;a("group-shapes",{source:e});let r=n.getOnlySelectedShape();r&&n.isShapeOfType(r,"group")?(n.markHistoryStoppingPoint("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())):(n.markHistoryStoppingPoint("group"),n.groupShapes(n.getSelectedShapeIds()))}},{id:"frame-selection",label:"action.frame-selection",kbd:"cmd+alt+g",onSelect(e){if(!d()||t())return;let i=n.getSelectedShapes();if(i.length>0&&i.every(e=>n.isShapeOfType(e,"frame"))){a("remove-frame",{source:e}),n.markHistoryStoppingPoint("remove-frame"),ic(n,i.map(e=>e.id));return}let o=n.getSelectedShapeIds();if(o.length<2)return;let s=(0,r.oE7)(o.map(e=>n.getShape(e))),l=n.getSelectionPageBounds();if(!l)return;a("frame-selection",{source:e}),n.markHistoryStoppingPoint("frame-selection");let c=n.findCommonAncestor(s)??n.getCurrentPageId(),h=(0,r.n6Y)(),u=25/n.getZoomLevel();n.run(()=>{n.createShapes([{id:h,type:"frame",parentId:c,x:l.x,y:l.y,props:{w:l.w,h:l.h}}]),n.reparentShapes(o,h),iu(n,h,{padding:u}),n.select(h)})}},{id:"remove-frame",label:"action.remove-frame",onSelect(e){if(!d())return;a("remove-frame",{source:e});let t=n.getSelectedShapes();t.length>0&&t.every(e=>n.isShapeFrameLike(e))&&(n.markHistoryStoppingPoint("remove-frame"),ic(n,t.map(e=>e.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(e){if(!d())return;a("fit-frame-to-content",{source:e});let t=n.getOnlySelectedShape();t&&n.isShapeFrameLike(t)&&(n.markHistoryStoppingPoint("fit-frame-to-content"),iu(n,t.id))}},{id:"align-left",label:"action.align-left",kbd:"alt+A",icon:"align-left",onSelect(e){!d()||t()||(a("align-shapes",{operation:"left",source:e}),n.markHistoryStoppingPoint("align left"),n.run(()=>{let e=n.getSelectedShapeIds();n.alignShapes(e,"left"),(0,r.IeP)(n,e)}))}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"alt+H",icon:"align-center-horizontal",onSelect(e){!d()||t()||(a("align-shapes",{operation:"center-horizontal",source:e}),n.markHistoryStoppingPoint("align center horizontal"),n.run(()=>{let e=n.getSelectedShapeIds();n.alignShapes(e,"center-horizontal"),(0,r.IeP)(n,e)}))}},{id:"align-right",label:"action.align-right",kbd:"alt+D",icon:"align-right",onSelect(e){!d()||t()||(a("align-shapes",{operation:"right",source:e}),n.markHistoryStoppingPoint("align right"),n.run(()=>{let e=n.getSelectedShapeIds();n.alignShapes(e,"right"),(0,r.IeP)(n,e)}))}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"alt+V",icon:"align-center-vertical",onSelect(e){!d()||t()||(a("align-shapes",{operation:"center-vertical",source:e}),n.markHistoryStoppingPoint("align center vertical"),n.run(()=>{let e=n.getSelectedShapeIds();n.alignShapes(e,"center-vertical"),(0,r.IeP)(n,e)}))}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"alt+W",onSelect(e){!d()||t()||(a("align-shapes",{operation:"top",source:e}),n.markHistoryStoppingPoint("align top"),n.run(()=>{let e=n.getSelectedShapeIds();n.alignShapes(e,"top"),(0,r.IeP)(n,e)}))}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"alt+S",onSelect(e){!d()||t()||(a("align-shapes",{operation:"bottom",source:e}),n.markHistoryStoppingPoint("align bottom"),n.run(()=>{let e=n.getSelectedShapeIds();n.alignShapes(e,"bottom"),(0,r.IeP)(n,e)}))}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"alt+shift+h",onSelect(e){!d()||t()||(a("distribute-shapes",{operation:"horizontal",source:e}),n.markHistoryStoppingPoint("distribute horizontal"),n.run(()=>{let e=n.getSelectedShapeIds();n.distributeShapes(e,"horizontal"),(0,r.IeP)(n,e)}))}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"alt+shift+V",onSelect(e){!d()||t()||(a("distribute-shapes",{operation:"vertical",source:e}),n.markHistoryStoppingPoint("distribute vertical"),n.run(()=>{let e=n.getSelectedShapeIds();n.distributeShapes(e,"vertical"),(0,r.IeP)(n,e)}))}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(e){!d()||t()||(a("stretch-shapes",{operation:"horizontal",source:e}),n.markHistoryStoppingPoint("stretch horizontal"),n.run(()=>{let e=n.getSelectedShapeIds();n.stretchShapes(e,"horizontal"),(0,r.IeP)(n,e)}))}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(e){!d()||t()||(a("stretch-shapes",{operation:"vertical",source:e}),n.markHistoryStoppingPoint("stretch vertical"),n.run(()=>{let e=n.getSelectedShapeIds();n.stretchShapes(e,"vertical"),(0,r.IeP)(n,e)}))}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"shift+h",onSelect(e){!d()||t()||(a("flip-shapes",{operation:"horizontal",source:e}),n.markHistoryStoppingPoint("flip horizontal"),n.run(()=>{let e=n.getSelectedShapeIds();n.flipShapes(e,"horizontal"),(0,r.IeP)(n,e)}))}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"shift+v",onSelect(e){!d()||t()||(a("flip-shapes",{operation:"vertical",source:e}),n.markHistoryStoppingPoint("flip vertical"),n.run(()=>{let e=n.getSelectedShapeIds();n.flipShapes(e,"vertical"),(0,r.IeP)(n,e)}))}},{id:"pack",label:"action.pack",icon:"pack",onSelect(e){!d()||t()||(a("pack-shapes",{source:e}),n.markHistoryStoppingPoint("pack"),n.run(()=>{let e=n.getSelectedShapeIds();n.packShapes(e,n.options.adjacentShapeMargin),(0,r.IeP)(n,e)}))}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(e){!d()||t()||(a("stack-shapes",{operation:"vertical",source:e}),n.markHistoryStoppingPoint("stack-vertical"),n.run(()=>{let e=n.getSelectedShapeIds();n.stackShapes(e,"vertical",n.options.adjacentShapeMargin),(0,r.IeP)(n,e)}))}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(e){!d()||t()||(a("stack-shapes",{operation:"horizontal",source:e}),n.markHistoryStoppingPoint("stack-horizontal"),n.run(()=>{let e=n.getSelectedShapeIds();n.stackShapes(e,"horizontal",n.options.adjacentShapeMargin),(0,r.IeP)(n,e)}))}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(e){!d()||t()||(a("reorder-shapes",{operation:"toFront",source:e}),n.markHistoryStoppingPoint("bring to front"),n.bringToFront(n.getSelectedShapeIds()))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"alt+]",onSelect(e){!d()||t()||(a("reorder-shapes",{operation:"forward",source:e}),n.markHistoryStoppingPoint("bring forward"),n.bringForward(n.getSelectedShapeIds()))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"alt+[",onSelect(e){!d()||t()||(a("reorder-shapes",{operation:"backward",source:e}),n.markHistoryStoppingPoint("send backward"),n.sendBackward(n.getSelectedShapeIds()))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(e){!d()||t()||(a("reorder-shapes",{operation:"toBack",source:e}),n.markHistoryStoppingPoint("send to back"),n.sendToBack(n.getSelectedShapeIds()))}},{id:"cut",label:"action.cut",kbd:"cmd+x,ctrl+x",onSelect(e){!d()||t()||(n.markHistoryStoppingPoint("cut"),o.cut(e))}},{id:"copy",label:"action.copy",kbd:"cmd+c,ctrl+c",readonlyOk:!0,onSelect(e){!d()||t()||o.copy(e)}},{id:"paste",label:"action.paste",kbd:"cmd+v,ctrl+v",onSelect(e){navigator.clipboard?.read().then(t=>{o.paste(t,e,"context-menu"===e?n.inputs.getCurrentPagePoint():void 0)}).catch(()=>{o.addToast({title:o.msg("action.paste-error-title"),description:o.msg("action.paste-error-description"),severity:"error"})})}},{id:"paste-at-cursor",label:"action.paste",kbd:"$?v",onSelect(e){let t=n.user.getIsPasteAtCursorMode()?void 0:n.inputs.getCurrentPagePoint();navigator.clipboard?.read().then(n=>{o.paste(n,e,t)}).catch(()=>{o.addToast({title:o.msg("action.paste-error-title"),description:o.msg("action.paste-error-description"),severity:"error"})})}},{id:"paste-plain-text-at-cursor",label:"action.paste",kbd:"$!?v",onSelect(){let e=n.user.getIsPasteAtCursorMode()?n.getViewportPageBounds().center:n.inputs.getCurrentPagePoint();navigator.clipboard?.readText().then(t=>{t?.trim()&&(n.markHistoryStoppingPoint("paste"),r9(n,{text:t,point:e}))}).catch(()=>{o.addToast({title:o.msg("action.paste-error-title"),description:o.msg("action.paste-error-description"),severity:"error"})})}},{id:"select-all",label:"action.select-all",kbd:"cmd+a,ctrl+a",readonlyOk:!0,onSelect(e){n.run(()=>{t()||(a("select-all-shapes",{source:e}),n.markHistoryStoppingPoint("select all kbd"),n.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(e){!d()||t()||(a("select-none-shapes",{source:e}),n.markHistoryStoppingPoint("select none"),n.selectNone())}},{id:"delete",label:"action.delete",kbd:"⌫,del",icon:"trash",onSelect(e){!d()||t()||(a("delete-shapes",{source:e}),n.markHistoryStoppingPoint("delete"),n.deleteShapes(n.getSelectedShapeIds()))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",kbd:"shift+.,shift+alt+.",onSelect(e){if(!d()||t())return;let i=n.inputs.getAltKey();a("rotate-cw",{source:e,fine:i}),n.markHistoryStoppingPoint("rotate-cw"),n.run(()=>{let e=r.sKG/(i?96:6),t=n.getSelectionRotation()%e,o=(0,r.YY0)(t,0)||(0,r.YY0)(t,e),s=n.getSelectedShapeIds();n.rotateShapesBy(s,e-(o?0:t)),(0,r.IeP)(n,s)})}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",kbd:"shift+,,shift+alt+,",onSelect(e){if(!d()||t())return;let i=n.inputs.getAltKey();a("rotate-ccw",{source:e,fine:i}),n.markHistoryStoppingPoint("rotate-ccw"),n.run(()=>{let e=r.sKG/(i?96:6),t=n.getSelectionRotation()%e,o=(0,r.YY0)(t,0),s=n.getSelectedShapeIds();n.rotateShapesBy(s,o?-e:-t),(0,r.IeP)(n,s)})}},{id:"zoom-in",label:"action.zoom-in",kbd:"cmd+=,ctrl+=,=",readonlyOk:!0,onSelect(e){a("zoom-in",{source:e,towardsCursor:!1}),n.zoomIn(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-in-on-cursor",label:"action.zoom-in",kbd:"shift+cmd+=,shift+ctrl+=,shift+=",readonlyOk:!0,onSelect(e){a("zoom-in",{source:e,towardsCursor:!0}),n.zoomIn(n.inputs.getCurrentScreenPoint(),{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"cmd+-,ctrl+-,-",readonlyOk:!0,onSelect(e){a("zoom-out",{source:e,towardsCursor:!1}),n.zoomOut(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-out-on-cursor",label:"action.zoom-out",kbd:"shift+cmd+-,shift+ctrl+-,shift+-",readonlyOk:!0,onSelect(e){a("zoom-out",{source:e,towardsCursor:!0}),n.zoomOut(n.inputs.getCurrentScreenPoint(),{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"shift+0",readonlyOk:!0,onSelect(e){a("reset-zoom",{source:e}),n.resetZoom(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"shift+1",readonlyOk:!0,onSelect(e){a("zoom-to-fit",{source:e}),n.zoomToFit({animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"shift+2",readonlyOk:!0,onSelect(e){!d()||t()||(a("zoom-to-selection",{source:e}),n.zoomToSelection({animation:{duration:n.options.animationMediumMs}}))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(e){a("toggle-snap-mode",{source:e}),n.user.updateUserPreferences({isSnapMode:!n.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"cmd+/,ctrl+/",readonlyOk:!0,onSelect(e){let t=n.user.getIsDarkMode()?"light":"dark";a("color-scheme",{source:e,value:t}),n.user.updateUserPreferences({colorScheme:t})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(e){a("toggle-wrap-mode",{source:e}),n.user.updateUserPreferences({isWrapMode:!n.user.getIsWrapMode()})},checkbox:!0},{id:"toggle-dynamic-size-mode",label:{default:"action.toggle-dynamic-size-mode",menu:"action.toggle-dynamic-size-mode.menu"},readonlyOk:!1,onSelect(e){a("toggle-dynamic-size-mode",{source:e}),n.user.updateUserPreferences({isDynamicSizeMode:!n.user.getIsDynamicResizeMode()})},checkbox:!0},{id:"toggle-paste-at-cursor",label:{default:"action.toggle-paste-at-cursor",menu:"action.toggle-paste-at-cursor.menu"},readonlyOk:!1,onSelect(e){a("toggle-paste-at-cursor",{source:e}),n.user.updateUserPreferences({isPasteAtCursorMode:!n.user.getIsPasteAtCursorMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(e){a("toggle-reduce-motion",{source:e}),n.user.updateUserPreferences({animationSpeed:+(0===n.user.getAnimationSpeed())})},checkbox:!0},{id:"toggle-keyboard-shortcuts",label:{default:"action.toggle-keyboard-shortcuts",menu:"action.toggle-keyboard-shortcuts.menu"},readonlyOk:!0,onSelect(e){a("toggle-keyboard-shortcuts",{source:e}),n.user.updateUserPreferences({areKeyboardShortcutsEnabled:!n.user.getAreKeyboardShortcutsEnabled()})},checkbox:!0},{id:"enhanced-a11y-mode",label:{default:"action.enhanced-a11y-mode",menu:"action.enhanced-a11y-mode.menu"},readonlyOk:!0,onSelect(e){a("enhanced-a11y-mode",{source:e}),n.user.updateUserPreferences({enhancedA11yMode:!n.user.getEnhancedA11yMode()})},checkbox:!0},{id:"toggle-edge-scrolling",label:{default:"action.toggle-edge-scrolling",menu:"action.toggle-edge-scrolling.menu"},readonlyOk:!0,onSelect(e){a("toggle-edge-scrolling",{source:e}),n.user.updateUserPreferences({edgeScrollSpeed:+(0===n.user.getEdgeScrollSpeed())})},checkbox:!0},{id:"toggle-invert-zoom",label:{default:"action.toggle-invert-zoom",menu:"action.toggle-invert-zoom.menu"},readonlyOk:!0,onSelect(e){a("toggle-invert-zoom",{source:e}),n.user.updateUserPreferences({isZoomDirectionInverted:!n.user.getIsZoomDirectionInverted()})},checkbox:!0},{id:"toggle-transparent",label:{default:"action.toggle-transparent",menu:"action.toggle-transparent.menu","context-menu":"action.toggle-transparent.context-menu"},readonlyOk:!0,onSelect(e){a("toggle-transparent",{source:e}),n.updateInstanceState({exportBackground:!n.getInstanceState().exportBackground})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(e){a("toggle-tool-lock",{source:e}),n.updateInstanceState({isToolLocked:!n.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(e){a("unlock-all",{source:e});let t=[];for(let e of n.getCurrentPageShapes())e.isLocked&&t.push({id:e.id,type:e.type,isLocked:!1});t.length>0&&n.updateShapes(t)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"cmd+.,ctrl+.",checkbox:!0,onSelect(e){n.timers.requestAnimationFrame(()=>{n.run(()=>{a("toggle-focus-mode",{source:e}),o.clearDialogs(),o.clearToasts(),n.updateInstanceState({isFocusMode:!n.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"cmd+',ctrl+'",onSelect(e){a("toggle-grid-mode",{source:e}),n.updateInstanceState({isGridMode:!n.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(e){a("toggle-debug-mode",{source:e}),n.updateInstanceState({isDebugMode:!n.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"cmd+p,ctrl+p",readonlyOk:!0,onSelect(e){a("print",{source:e}),o.printSelectionOrPages()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(e){a("exit-pen-mode",{source:e}),n.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(e){a("stop-following",{source:e}),n.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(e){a("zoom-to-content",{source:e});let t=n.getSelectionPageBounds()??n.getCurrentPageBounds();t&&n.zoomToBounds(t,{targetZoom:Math.min(1,n.getZoomLevel()),animation:{duration:220}})}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"shift+l",onSelect(e){d()&&(n.markHistoryStoppingPoint("locking"),a("toggle-lock",{source:e}),n.toggleLock(n.getSelectedShapeIds()))}},{id:"move-to-new-page",label:"context.pages.new-page",onSelect(e){let t=r.tvM.createId(),i=n.getSelectedShapeIds();n.run(()=>{n.markHistoryStoppingPoint("move_shapes_to_page"),n.createPage({name:o.msg("page-menu.new-page-initial-name"),id:t}),n.moveShapesToPage(i,t)}),a("move-to-new-page",{source:e})}},{id:"select-white-color",label:"color-style.white",kbd:"alt+t",onSelect(e){let t=r.ive;n.run(()=>{n.updateInstanceState({isChangingStyle:!0}),n.markHistoryStoppingPoint("change-color"),n.isIn("select")&&n.setStyleForSelectedShapes(t,"white"),n.setStyleForNextShapes(t,"white")}),a("set-style",{source:e,id:t.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"alt+f",onSelect(e){let t=r.u8f;n.run(()=>{n.updateInstanceState({isChangingStyle:!0}),n.markHistoryStoppingPoint("change-fill"),n.isIn("select")&&n.setStyleForSelectedShapes(t,"fill"),n.setStyleForNextShapes(t,"fill")}),a("set-style",{source:e,id:t.id,value:"fill"})}},{id:"select-fill-lined-fill",label:"fill-style.lined-fill",kbd:"alt+shift+f",onSelect(e){let t=r.u8f;n.run(()=>{n.updateInstanceState({isChangingStyle:!0}),n.markHistoryStoppingPoint("change-fill"),n.isIn("select")&&n.setStyleForSelectedShapes(t,"lined-fill"),n.setStyleForNextShapes(t,"lined-fill")}),a("set-style",{source:e,id:t.id,value:"lined-fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"shift+f",onSelect:async e=>{let t=n.getSelectedShapeIds();if(0===t.length)return;n.markHistoryStoppingPoint("flattening to image"),a("flatten-to-image",{source:e});let r=await lz(n,t,n.options.flattenImageBoundsExpand);r?.length&&n.setSelectedShapes(r)}},{id:"select-geo-tool",kbd:"g",onSelect:async e=>{a("select-tool",{source:e,id:"geo-previous"}),n.setCurrentTool("geo")}},{id:"change-page-prev",kbd:"alt+left,alt+up",readonlyOk:!0,onSelect:async e=>{let t=n.getPages(),r=t.findIndex(e=>e.id===n.getCurrentPageId());r<1||(a("change-page",{source:e,direction:"prev"}),n.setCurrentPage(t[r-1].id))}},{id:"change-page-next",kbd:"alt+right,alt+down",readonlyOk:!0,onSelect:async e=>{let t=n.getPages(),i=t.findIndex(e=>e.id===n.getCurrentPageId());if(-1===i||i>=t.length-1){if(n.getCurrentPageShapes().length<=0||n.getIsReadonly())return;a("new-page",{source:e}),n.run(()=>{n.markHistoryStoppingPoint("creating page");let e=r.tvM.createId();n.createPage({name:o.msg("page-menu.new-page-initial-name"),id:e}),n.setCurrentPage(e)});return}n.setCurrentPage(t[i+1].id),a("change-page",{source:e,direction:"next"})}},{id:"adjust-shape-styles",label:"a11y.adjust-shape-styles",kbd:"cmd+Enter,ctrl+Enter",isRequiredA11yAction:!0,onSelect:async e=>{if(!d())return;let t=n.getOnlySelectedShape();if(t&&(n.isShapeOfType(t,"image")||n.isShapeOfType(t,"video"))){let e=n.getContainer().querySelector(".tlui-contextual-toolbar button:first-child");e?.focus();return}let r=n.getContainer().querySelector(".tlui-style-panel button");r?.focus(),a("adjust-shape-styles",{source:e})}},{id:"a11y-open-context-menu",kbd:"cmd+shift+Enter,ctrl+shift+Enter",isRequiredA11yAction:!0,readonlyOk:!0,onSelect:async e=>{if(!d())return;let t=n.getSelectionPageBounds();if(!t)return;let i=t.x+t.width/2,o=t.y+t.height/2,s=n.pageToScreen(new r.l2P(i,o));n.getContainer().querySelector(".tl-canvas")?.dispatchEvent(new PointerEvent("contextmenu",{clientX:s.x,clientY:s.y,bubbles:!0})),a("open-context-menu",{source:e})}},{id:"enlarge-shapes",label:"a11y.enlarge-shape",kbd:"cmd+alt+shift+=,ctrl+alt+shift+=",onSelect:async e=>{d()&&(u(1.1),a("enlarge-shapes",{source:e}))}},{id:"shrink-shapes",label:"a11y.shrink-shape",kbd:"cmd+alt+shift+-,ctrl+alt+shift+-",onSelect:async e=>{d()&&(u(1/1.1),a("shrink-shapes",{source:e}))}},{id:"a11y-repeat-shape-announce",kbd:"alt+r",label:"a11y.repeat-shape",isRequiredA11yAction:!0,readonlyOk:!0,onSelect:async e=>{let t=n.getSelectedShapeIds();if(!t.length)return;let r=fu({editor:n,selectedShapeIds:t,msg:c});r&&(l.announce({msg:""}),n.timers.requestAnimationFrame(()=>{l.announce({msg:r})}),a("a11y-repeat-shape-announce",{source:e}))}},{id:"image-replace",label:"tool.replace-media",icon:"arrow-cycle",readonlyOk:!1,onSelect:async e=>{a("image-replace",{source:e}),o.replaceImage()}},{id:"video-replace",label:"tool.replace-media",icon:"arrow-cycle",readonlyOk:!1,onSelect:async e=>{a("video-replace",{source:e}),o.replaceVideo()}},{id:"download-original",label:"action.download-original",readonlyOk:!0,onSelect:async e=>{let t=n.getSelectedShapes();if(0===t.length)return;let i=t.filter(e=>fn(e,n));if(0!==i.length){for(let e of i){let t=n.getAsset(e.props.assetId);if(!t||!t.props.src)continue;let i=await n.resolveAssetUrl(t.id,{shouldResolveToOriginal:!0});if(!i)continue;let o="video"!==t.type&&"image"!==t.type||t.props.src.startsWith("asset:")?"download":t.props.name;try{let e=await (0,r.hdJ)(i);if(!e.ok)throw Error(`Failed to fetch asset: ${e.status}`);let t=await e.blob();id(new File([t],o,{type:t.type}),n.getContainerDocument())}catch{(0,r.D1x)(i,"_blank")}}a("download-original",{source:e})}}},{id:"copy-hovered-styles",label:"action.copy-hovered-styles",kbd:"shift+q",async onSelect(e){let t=n.getShapeAtPoint(n.inputs.getCurrentPagePoint(),{hitInside:!1,hitLabels:!1,hitLocked:n.options.selectLockedShapes,margin:n.getHitTestMargin()}),i=n.getPath();t&&i.endsWith(".idle")&&(n.run(()=>{for(let e of n.styleProps[t.type].keys()){let i=n.getShapeStyleIfExists(t,e);void 0!==i&&e!==r.tg8&&n.setStyleForNextShapes(e,i)}}),a("copy-hovered-styles",{source:e}))}}];i&&p.push({id:"open-cursor-chat",label:"action.open-cursor-chat",readonlyOk:!0,kbd:"/",onSelect(e){a("open-cursor-chat",{source:e}),n.getInstanceState().isCoarsePointer||n.timers.requestAnimationFrame(()=>{n.updateInstanceState({isChatting:!0})})}});let f=Object.fromEntries(p.map(e=>[e.id,e]));return e?e(n,f,o):f},[o,n,a,e,h,i,c,l,s]);return(0,d.jsx)(ft.Provider,{value:u,children:t})}function fo(){let e=f.useContext(ft);if(!e)throw Error("useTools must be used within a ToolProvider");return e}function fs(e,t){return e?"string"==typeof e?e:t?e[t]??e.default:void 0:void 0}let fa=new r.bZT("backToContentSuppressed",()=>!1),fl=new r.bZT("backToContentSuppressTimeout",()=>null);function fd(){let e=(0,r.hGv)(),t=fo(),[n,i]=(0,f.useState)(!1),o=(0,f.useRef)(!1),s=(0,f.useRef)(null);return((0,r.lXS)("toggle showback to content",()=>{let t=!1;if(!fa.get(e)){let n=e.getCurrentPageShapeIds();n.size&&(t=n.size===e.getNotVisibleShapes().size)}if(t===o.current){null!==s.current&&(clearTimeout(s.current),s.current=null);return}t?null===s.current&&(s.current=e.timers.setTimeout(()=>{s.current=null,o.current=!0,i(!0)},1e3)):(null!==s.current&&(clearTimeout(s.current),s.current=null),o.current=!1,i(!1))},[e]),(0,f.useEffect)(()=>()=>{null!==s.current&&(clearTimeout(s.current),s.current=null)},[]),n)?(0,d.jsx)(aT,{actionId:"back-to-content",onSelect:()=>{t["back-to-content"].onSelect("helper-buttons"),i(!1)}}):null}function fc(){let e=(0,r.hGv)(),t=M(),n=(0,f.useRef)(null),i=(0,f.useCallback)(t=>{e.markEventAsHandled(t),n.current?.blur();let r=e.getCurrentPageShapesInReadingOrder();if(r.length){var i;let t,n;e.setSelectedShapes([r[0].id]),i=e.options.animationMediumMs,fa.set(e,!0),null!==(t=fl.get(e))&&clearTimeout(t),n=e.timers.setTimeout(()=>{fa.set(e,!1),fl.set(e,null)},i),fl.set(e,n),e.zoomToSelectionIfOffscreen(256,{animation:{duration:e.options.animationMediumMs},inset:0}),e.timers.setTimeout(()=>e.getContainer().focus(),100)}},[e]);return(0,d.jsx)(od,{ref:n,type:"low",tabIndex:0,className:"tl-skip-to-main-content",onClick:i,children:t("a11y.skip-to-main-content")})}let fh=(0,f.memo)(function(){let e,t,n,i,o=w(),s=M(),a=(0,r.hau)("a11y-msg",()=>o.currentMsg.get(),[]);return fp(a.msg),e=(0,r.frr)(),t=w(),n=M(),i=(0,f.useRef)([]),(0,r.a1r)("announce selection",()=>{if(e&&e.isIn("select.idle")){let o=e.getSelectedShapeIds();o!==i.current&&(i.current=o,(0,r.PmD)(()=>{let r=fu({editor:e,selectedShapeIds:o,msg:n});r&&t.announce({msg:r})}))}},[e,t,n]),a.msg&&(0,d.jsx)("div",{"aria-label":s("a11y.status"),"aria-live":a.priority||"assertive",role:"status","aria-hidden":"false",style:{position:"absolute",top:"-10000px",left:"-10000px"},children:a.msg})});function fu(e){let{editor:t,selectedShapeIds:n,msg:r}=e,i="",o=n.length;if(o>1)i=r("a11y.multiple-shapes").replace("{num}",o.toString());else if(1===o){let e=n[0],o=t.getShape(e);if(!o)return"";let s=t.getShapeUtil(o.type),a=["image","video"].includes(o.type),l="";l=r("geo"===o.type?`geo-style.${o.props.geo}`:a?`a11y.shape-${o.type}`:`tool.${o.type}`);let d=t.getCurrentPageShapesInReadingOrder(),c=(d.findIndex(t=>t.id===e)+1).toString(),h=d.length.toString(),u=r("a11y.shape-index").replace("{num}",c).replace("{total}",h),p=s.getAriaDescriptor(o)||s.getText(o)||"";i=(p?`${p}, `:"")+`${l}. ${u}`}return i}let fp=e=>{let t=(0,r.NFA)();(0,f.useEffect)(()=>{if(r.bGJ.a11y.get()){let n=e=>{console.debug(`%ca11y%c: ${e}`,"color: white; background: #40C057; padding: 2px;border-radius: 3px;","font-weight: normal")},r=t.ownerDocument,i=e=>{let t=r.activeElement;if("Tab"===e.key&&t&&t!==r.body&&!t.classList.contains("tl-container")){let e=t.getAttribute("aria-label")||t.getAttribute("title")||t.textContent;e&&n(e)}};return e&&n(e),r.addEventListener("keyup",i),()=>r.removeEventListener("keyup",i)}},[t,e])};class ff extends r.$mH{static type="bookmark";static props=r.VtT;static migrations=r.Esp;getDefaultProps(){return{title:"",description:"",image:"",favicon:"",src:null}}}class fg extends r.$mH{static type="image";static props=r._8g;static migrations=r.h1I;options={maxDimension:5e3,supportedMimeTypes:null};getDefaultProps(){return{w:0,h:0,name:"",isAnimated:!1,mimeType:null,src:null}}getSupportedMimeTypes(){return this.options.supportedMimeTypes??r.RBp}async getAssetFromFile(e,t){let n=this.editor.getContainerDocument(),i=await r.K4L.getImageSize(e,n),o=await r.K4L.isAnimated(e),s="pixelRatio"in i&&1!==i.pixelRatio?i.pixelRatio:void 0,a={id:t,type:"image",typeName:"asset",props:{name:e.name,src:"",w:i.w,h:i.h,fileSize:e.size,mimeType:e.type,isAnimated:o,...s?{pixelRatio:s}:void 0},meta:{}},l=this.options.maxDimension;if(l&&isFinite(l)){var d;let t,n,i={w:a.props.w,h:a.props.h},o=(d={w:l,h:l},t=i.w/d.w,n=i.h/d.h,t<=1&&n<=1?i:t>n?{w:i.w/t,h:i.h/t}:{w:i.w/n,h:i.h/n});i!==o&&r.K4L.isStaticImageType(e.type)&&(a.props.w=o.w,a.props.h=o.h)}return a}}class fm extends r.$mH{static type="video";static props=r.EOG;static migrations=r.jhO;options={supportedMimeTypes:null};getDefaultProps(){return{w:0,h:0,name:"",isAnimated:!0,mimeType:null,src:null}}getSupportedMimeTypes(){return this.options.supportedMimeTypes??r.qSO}async getAssetFromFile(e,t){let n=e.type;"video/quicktime"===n&&(n="video/mp4");let i=this.editor.getContainerDocument(),o=await r.K4L.getVideoSize(e,i);return{id:t,type:"video",typeName:"asset",props:{name:e.name,src:"",w:o.w,h:o.h,fileSize:e.size,mimeType:n,isAnimated:!0},meta:{}}}}let fy=new WeakMap;function fb(e,t,n){let r=e.editor.getCurrentTheme(),i=n??e.editor.getColorMode(),o=fy.get(t);if(o&&o.theme===r&&o.colorMode===i)return o.values;let s={...e.options.getDefaultDisplayValues(e.editor,t,r,i),...e.options.getCustomDisplayValues(e.editor,t,r,i)};return fy.set(t,{theme:r,colorMode:i,values:s}),s}function fx(e,t,n,i){let{arrowheadStart:o,arrowheadEnd:s}=t.props,a=di(e,t,n),l=a.start.clone(),d=a.end.clone(),c=r.l2P.Med(l,d);if(r.l2P.Equals(l,d))return{bindings:n,type:"straight",start:{handle:l,point:l,arrowhead:t.props.arrowheadStart},end:{handle:d,point:d,arrowhead:t.props.arrowheadEnd},middle:c,isValid:!1,length:0};let h=r.l2P.Sub(d,l).uni(),u=de(e,t,"start"),p=de(e,t,"end"),f=e.getShapePageTransform(t);fw(d,a.start,f,p),fw(l,a.end,f,u),dd(e,d,a.end,f,p),dd(e,l,a.start,f,u);let g=0,m=0,y=0,b=0,x=10*t.props.scale,w=e.getCurrentTheme(),v=i??w.strokeWidth*G[t.props.size],S=u&&p&&u.shape===p.shape,C=u&&p?dl(e,u.shape.id,p.shape.id):"safe";"safe"===C&&u&&p&&!S&&!u.isExact&&!p.isExact&&(p.didIntersect&&!u.didIntersect?u.isClosed&&l.setTo(d.clone().add(h.clone().mul(10*t.props.scale))):!p.didIntersect&&p.isClosed&&d.setTo(l.clone().sub(h.clone().mul(10*t.props.scale))));let k=r.l2P.Sub(d,l),P=r.l2P.Len(k)?k.uni():r.l2P.From(k),T=!r.l2P.Equals(P,h);S||("start-contains-end"!==C&&u&&"none"!==o&&!u.isExact&&(g=(10+(y=v/2+("size"in u.shape.props?w.strokeWidth*G[u.shape.props.size]/2:0)))*t.props.scale,x+=y*t.props.scale),"end-contains-start"!==C&&p&&"none"!==s&&!p.isExact&&(m=(10+(b=v/2+("size"in p.shape.props?w.strokeWidth*G[p.shape.props.size]/2:0)))*t.props.scale,x+=b*t.props.scale));let E=l.clone().add(P.clone().mul(g*(T?-1:1))),I=d.clone().sub(P.clone().mul(m*(T?-1:1)));r.l2P.DistMin(E,I,x)&&(0!==g&&0!==m?(g*=-1.5,m*=-1.5):0!==g?g*=-1:0!==m&&(m*=-1)),l.add(P.clone().mul(g*(T?-1:1))),d.sub(P.clone().mul(m*(T?-1:1))),T?(u&&p&&d.setTo(r.l2P.Add(l,P.clone().mul(-10*t.props.scale))),c.setTo(r.l2P.Med(a.start,a.end))):c.setTo(r.l2P.Med(l,d));let _=r.l2P.Dist(l,d);return{bindings:n,type:"straight",start:{handle:a.start,point:l,arrowhead:t.props.arrowheadStart},end:{handle:a.end,point:d,arrowhead:t.props.arrowheadEnd},middle:c,isValid:_>0,length:_}}function fw(e,t,n,i){let o;if(void 0===i||i.isExact)return;let s=r.V8r.applyToPoint(n,t),a=r.V8r.applyToPoint(n,e),l=r.V8r.applyToPoint(r.V8r.Inverse(i.transform),s),d=r.V8r.applyToPoint(r.V8r.Inverse(i.transform),a),c=Array.from(i.geometry.intersectLineSegment(l,d,{includeLabels:!1,includeInternal:!1}));if(c.length&&(o=c.sort((e,t)=>r.l2P.Dist2(e,l)-r.l2P.Dist2(t,l))[0]??(i.isClosed?void 0:d)),void 0===o&&(o=i.geometry.nearestPoint(d,{includeLabels:!1,includeInternal:!1}),!r.l2P.DistMin(o,d,1)))return;let h=r.V8r.applyToPoint(i.transform,o),u=r.V8r.applyToPoint(r.V8r.Inverse(n),h);e.setTo(u),i.didIntersect=!0}function fv(e,t,n){let i=(0,r.oj6)(e,t,n)??r.l2P.Med(e,t),o=r.l2P.Dist(i,e),s=+r.l2P.Clockwise(e,n,t),a=((e.y-t.y)**2+(e.x-t.x)**2)**.5,l=((t.y-n.y)**2+(t.x-n.x)**2)**.5,d=((n.y-e.y)**2+(n.x-e.x)**2)**.5,c=2*Math.acos((l*l+d*d-a*a)/(2*l*d)),h=+(r.PI>c),u=(r.uAR-c)*(s?1:-1);return{center:i,radius:o,size:u,length:u*o,largeArcFlag:h,sweepFlag:s}}let fS=["right","bottom","left","top"],fC={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}},fk={left:"x",right:"x",top:"y",bottom:"y"},fP={top:"bottom",right:"left",bottom:"top",left:"right"},fT={x:{v:(e,t)=>new r.l2P(e,t),loEdge:"left",hiEdge:"right",crossMid:"midY",gap:"gapX",midRange:"midXRange",self:"x",cross:"y",size:"width"},y:{v:(e,t)=>new r.l2P(t,e),loEdge:"top",hiEdge:"bottom",crossMid:"midX",gap:"gapY",midRange:"midYRange",self:"y",cross:"x",size:"height"}};function fE(e,t){return{min:Math.min(e,t),max:Math.max(e,t)}}function fI(e,t){return e>=t.min&&e<=t.max}function f_(e){if(!e)return;let t=e.cross.min;e.cross.min=-e.cross.max,e.cross.max=-t,e.crossTarget=-e.crossTarget}function fM(e){e&&(e.value=-e.value,e.expanded=null===e.expanded?null:-e.expanded)}let fA={x:1,y:1,transpose:!1},fj={x:-1,y:1,transpose:!0},fO={x:-1,y:-1,transpose:!1},fD={x:1,y:-1,transpose:!0},fL={x:1,y:-1,transpose:!1};function fR(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function fF(e,t){t.x=e.x*t.x,t.y=e.y*t.y,e.transpose&&fR(t,"x","y")}function fz(e,t){-1===e.x&&(t.x=-(t.x+t.width)),-1===e.y&&(t.y=-(t.y+t.height)),e.transpose&&(fR(t,"x","y"),fR(t,"width","height"))}function fN(e,t){-1===e.x&&(fR(t,"left","right"),f_(t.top),f_(t.bottom),fM(t.left),fM(t.right)),-1===e.y&&(fR(t,"top","bottom"),f_(t.left),f_(t.right),fM(t.top),fM(t.bottom)),e.transpose&&(fR(t,"left","top"),fR(t,"right","bottom"))}class f${options;A;B;common;gapX;gapY;midX;midY;bias;constructor(e){this.options=e.options,this.A=e.A,this.B=e.B,this.common=e.common,this.midX=e.midX,this.midY=e.midY,this.gapX=e.gapX,this.gapY=e.gapY,this.bias=new r.l2P(1,1)}transform=fA;inverse=fA;apply(e){var t,n;let r;if(this.transform=(t=this.transform,r={...e},t.transpose&&(fR(r,"x","y"),r.transpose=!r.transpose),-1===t.x&&(r.x=-r.x),-1===t.y&&(r.y=-r.y),r),this.inverse=(n=this.transform).transpose?{x:n.y,y:n.x,transpose:!0}:n,fz(e,this.A.original),fz(e,this.B.original),fz(e,this.common.original),fz(e,this.A.expanded),fz(e,this.B.expanded),fz(e,this.common.expanded),fN(e,this.A.edges),fN(e,this.B.edges),fF(e,this.bias),-1===e.x&&(this.gapX=-this.gapX,this.midX=null===this.midX?null:-this.midX),-1===e.y&&(this.gapY=-this.gapY,this.midY=null===this.midY?null:-this.midY),e.transpose){let e=this.midX;this.midX=this.midY,this.midY=e,e=this.gapX,this.gapX=this.gapY,this.gapY=e}}reset(){this.apply(this.inverse)}vec(e,t){let n=new r.l2P(e,t);return fF(this.inverse,n),n}}class fB{constructor(e,t){this.info=e,this.name=t}info;name;points=[];add(e,t){return this.points.push(this.info.vec(e,t)),this}_midpointHandle=null;midpointHandle(e){(0,r.vAR)(null===this._midpointHandle,"midX/midY called multiple times");let t=r.l2P.Lrp(this.points[this.points.length-2],this.points[this.points.length-1],.5);return this._midpointHandle={axis:this.info.transform.transpose?"x"===e?"y":"x":e,point:t,segmentStart:this.points[this.points.length-2].clone(),segmentEnd:this.points[this.points.length-1].clone()},this}build(){let e=[];for(let t=0;t<this.points.length;t++){let n=this.points[t],r=e[e.length-1],i=e[e.length-2];if(r&&i){let t=Math.abs(n.x-r.x),o=Math.abs(n.y-r.y),s=Math.abs(n.x-i.x),a=Math.abs(n.y-i.y);t<.01&&o<.01||(t<.01&&s<.01?r.y=n.y:o<.01&&a<.01?r.x=n.x:e.push(n))}else e.push(n)}return{name:this.name,points:e,distance:function(e){let t=0;for(let n=0;n<e.length-1;n++){let r=e[n],i=e[n+1];t+=Math.abs(i.x-r.x)+Math.abs(i.y-r.y)}return t}(e),aEdgePicking:"manual",bEdgePicking:"manual",skipPointsWhenDrawing:new Set,midpointHandle:this._midpointHandle}}}function fH(e){let t=e.A.edges.right,n=e.B.edges.left;if(!t||!n)return null;if(t.crossTarget>n.crossTarget&&e.apply(fL),e.gapX>0&&null!==e.midX)return new fB(e,"to left 1").add(t.value,t.crossTarget).add(e.midX,t.crossTarget).add(e.midX,n.crossTarget).midpointHandle("x").add(n.value,n.crossTarget).build();if(null===t.expanded||null===n.expanded)return null;if(null!==e.midY)return new fB(e,"to left 2").add(t.value,t.crossTarget).add(t.expanded,t.crossTarget).add(t.expanded,e.midY).add(n.expanded,e.midY).midpointHandle("y").add(n.expanded,n.crossTarget).add(n.value,n.crossTarget).build();let r=Math.abs(t.value-e.common.expanded.right)+Math.abs(t.crossTarget-e.common.expanded.bottom)+Math.abs(e.common.expanded.right-n.expanded)+Math.abs(e.common.expanded.bottom-n.crossTarget)+e.options.expandElbowLegLength+6,i=e.options.expandElbowLegLength+Math.abs(t.crossTarget-e.common.expanded.top)+Math.abs(t.expanded-e.common.expanded.left)+Math.abs(e.common.expanded.top-n.crossTarget)+Math.abs(e.common.expanded.left-n.value)+6+e.bias.y,o=e.gapX<0&&null!==e.midX?e.options.expandElbowLegLength+Math.abs(t.crossTarget-e.A.expanded.bottom)+e.common.expanded.width+Math.abs(e.A.expanded.bottom-e.B.expanded.top)+Math.abs(e.B.expanded.top-n.crossTarget)+e.options.expandElbowLegLength+8:1/0;return r<i&&r<o?new fB(e,"to left 3").add(t.value,t.crossTarget).add(e.common.expanded.right,t.crossTarget).add(e.common.expanded.right,e.common.expanded.bottom).add(n.expanded,e.common.expanded.bottom).add(n.expanded,n.crossTarget).add(n.value,n.crossTarget).build():i<o?new fB(e,"to left 4").add(t.value,t.crossTarget).add(t.expanded,t.crossTarget).add(t.expanded,e.common.expanded.top).add(e.common.expanded.left,e.common.expanded.top).add(e.common.expanded.left,n.crossTarget).add(n.value,n.crossTarget).build():null!==e.midX?new fB(e,"to left 5").add(t.value,t.crossTarget).add(t.expanded,t.crossTarget).add(t.expanded,e.A.expanded.bottom).add(e.midX,e.A.expanded.bottom).add(e.midX,e.B.expanded.top).midpointHandle("y").add(n.expanded,e.B.expanded.top).add(n.expanded,n.crossTarget).add(n.value,n.crossTarget).build():null}function fU(e){let t=e.A.edges.right,n=e.B.edges.top;if(!t||!n)return null;if(t.crossTarget<(n.expanded??n.value)&&n.crossTarget>(t.expanded??t.value)||e.A.isPoint&&e.B.expanded.containsPoint(e.A.original.center))return new fB(e,"to top 1").add(t.value,t.crossTarget).add(n.crossTarget,t.crossTarget).add(n.crossTarget,n.value).build();if(e.gapX>0&&null!==e.midX&&null!==n.expanded)return new fB(e,"to top 2").add(t.value,t.crossTarget).add(e.midX,t.crossTarget).add(e.midX,n.expanded).midpointHandle("x").add(n.crossTarget,n.expanded).add(n.crossTarget,n.value).build();if(e.gapY>0&&null!==t.expanded&&n.crossTarget<t.expanded&&null!==e.midY)return new fB(e,"to top 3").add(t.value,t.crossTarget).add(t.expanded,t.crossTarget).add(t.expanded,e.midY).add(n.crossTarget,e.midY).midpointHandle("y").add(n.crossTarget,n.value).build();let r=Math.abs(t.value-e.common.expanded.right)+Math.abs(t.crossTarget-e.common.expanded.top)+Math.abs(n.crossTarget-e.common.expanded.right)+Math.abs(n.value-e.common.expanded.top),i=null!==t.expanded&&null!==e.midY&&null!==n.expanded?Math.abs(t.value-t.expanded)+Math.abs(e.B.expanded.left-t.expanded)+Math.abs(e.B.expanded.left-n.crossTarget)+Math.abs(t.crossTarget-e.B.expanded.top)+Math.abs(n.value-n.expanded):1/0,o=null!==t.expanded&&null!==e.midX&&null!==n.expanded?Math.abs(t.value-e.common.expanded.right)+Math.abs(t.crossTarget-e.A.expanded.bottom)+Math.abs(t.expanded-n.crossTarget)+Math.abs(e.A.expanded.bottom-n.expanded)+Math.abs(n.expanded-n.value):1/0;return r<i&&r<o?new fB(e,"to top 4").add(t.value,t.crossTarget).add(e.common.expanded.right,t.crossTarget).add(e.common.expanded.right,e.common.expanded.top).add(n.crossTarget,e.common.expanded.top).add(n.crossTarget,n.value).build():null!==n.expanded&&null!==t.expanded&&null!==e.midY&&i<o?new fB(e,"to top 5").add(t.value,t.crossTarget).add(t.expanded,t.crossTarget).add(t.expanded,e.midY).add(e.B.expanded.left,e.midY).midpointHandle("y").add(e.B.expanded.left,n.expanded).add(n.crossTarget,n.expanded).add(n.crossTarget,n.value).build():null!==n.expanded&&null!==t.expanded&&null!==e.midX?new fB(e,"to top 6").add(t.value,t.crossTarget).add(t.expanded,t.crossTarget).add(t.expanded,e.A.expanded.bottom).add(e.midX,e.A.expanded.bottom).add(e.midX,n.expanded).midpointHandle("x").add(n.crossTarget,n.expanded).add(n.crossTarget,n.value).build():null}function fK(e){return e.apply(fL),fU(e)}function fW(e){let t=e.A.edges.right,n=e.B.edges.right;if(!t||!n)return null;if((e.gapX<=0||t.crossTarget>e.B.expanded.bottom||t.crossTarget<e.B.expanded.top)&&(n.value>e.A.original.left||n.crossTarget>e.A.expanded.bottom||n.crossTarget<e.A.expanded.top))return new fB(e,"to right 1").add(t.value,t.crossTarget).add(e.common.expanded.right,t.crossTarget).add(e.common.expanded.right,n.crossTarget).add(n.value,n.crossTarget).build();if(null===e.midX)return null;if(null!==n.expanded&&e.gapX>=0){let r=Math.abs(n.crossTarget-e.B.expanded.bottom)+Math.abs(t.crossTarget-e.B.expanded.bottom)<Math.abs(n.crossTarget-e.B.expanded.top)+Math.abs(t.crossTarget-e.B.expanded.top)?"bottom":"top";return new fB(e,`to right 2 via ${r}`).add(t.value,t.crossTarget).add(e.midX,t.crossTarget).add(e.midX,e.B.expanded[r]).midpointHandle("x").add(n.expanded,e.B.expanded[r]).add(n.expanded,n.crossTarget).add(n.value,n.crossTarget).build()}if(null!==t.expanded&&e.gapX<=0){let r=Math.abs(n.crossTarget-e.A.expanded.bottom)+Math.abs(t.crossTarget-e.A.expanded.bottom)<Math.abs(n.crossTarget-e.A.expanded.top)+Math.abs(t.crossTarget-e.A.expanded.top)?"bottom":"top";return new fB(e,`to right 3 via ${r}`).add(t.value,t.crossTarget).add(t.expanded,t.crossTarget).add(t.expanded,e.A.expanded[r]).add(e.midX,e.A.expanded[r]).add(e.midX,n.crossTarget).midpointHandle("x").add(n.value,n.crossTarget).build()}return null}let fV={top:{top:[fD,fW],left:[fD,fU],bottom:[fD,fH],right:[fD,fK]},right:{top:[fA,fU],right:[fA,fW],bottom:[fA,fK],left:[fA,fH]},bottom:{top:[fj,fH],left:[fj,fK],bottom:[fj,fW],right:[fj,fU]},left:{top:[fO,fK],left:[fO,fW],bottom:[fO,fU],right:[fO,fH]}};function fY(e,t,n){let[r,i]=fV[t][n];e.apply(r);let o=i(e);return e.reset(),o}function fG(e,t){let n=null,r=1/0,i=1/0,o=0;for(let[s,a,l,d]of t){o+=1;let t=fY(e,s,a);t&&(t.aEdgePicking=l,t.bEdgePicking=d,t.points.length<r?(r=t.points.length,i=t.distance,n=t):t.points.length===r&&t.distance+o<i&&(i=t.distance,n=t))}return n}function fq(e,t,n,i){var o,s,a;let l,d,c=e.getShapeUtil(t.type).options,h={elbowMidpoint:t.props.elbowMidPoint,expandElbowLegLength:c.expandElbowLegLength[t.props.size]*t.props.scale,minElbowLegLength:c.minElbowLegLength[t.props.size]*t.props.scale},u=fX(e,t,n.start,t.props.start,i),p=fX(e,t,n.end,t.props.end,i);u=f3(u,p,h),p=f3(p,u,h);let f=!!(!u.side&&p.side),{aTerminal:g,bTerminal:m}=f?{aTerminal:p,bTerminal:u}:{aTerminal:u,bTerminal:p},y={top:fZ(g,m,"top",h),right:fZ(g,m,"right",h),bottom:fZ(g,m,"bottom",h),left:fZ(g,m,"left",h)},b={top:fZ(m,g,"top",h),right:fZ(m,g,"right",h),bottom:fZ(m,g,"bottom",h),left:fZ(m,g,"left",h)},x=fQ(y,g.side),w=fQ(b,m.side),v=!1;x&&w||(v=!0,x||(m=f1(m)),w||(g=f1(g)),m.bounds.containsPoint(g.target,h.expandElbowLegLength)&&(m=f1(m)),g.bounds.containsPoint(m.target,h.expandElbowLegLength)&&(g=f1(g))),v&&(y={top:fZ(g,m,"top",h),right:fZ(g,m,"right",h),bottom:fZ(g,m,"bottom",h),left:fZ(g,m,"left",h)},b={top:fZ(m,g,"top",h),right:fZ(m,g,"right",h),bottom:fZ(m,g,"bottom",h),left:fZ(m,g,"left",h)});let S=g.isPoint?g.bounds:g.bounds.clone().expandBy(h.expandElbowLegLength),C=m.isPoint?m.bounds:m.bounds.clone().expandBy(h.expandElbowLegLength),k={original:r.azJ.Common([g.bounds,m.bounds]),expanded:r.azJ.Common([S,C])},P=m.bounds.minX-g.bounds.maxX;P<0&&((P=g.bounds.minX-m.bounds.maxX)<0&&(P=0),P=-P);let T=m.bounds.minY-g.bounds.maxY;T<0&&((T=g.bounds.minY-m.bounds.maxY)<0&&(T=0),T=-T);let E=3*g.minEndSegmentLength,I=3*m.minEndSegmentLength,_=(g.isPoint?E:h.minElbowLegLength)+(m.isPoint?I:h.minElbowLegLength),M=null;P>_?M={a:g.isPoint?g.bounds.maxX+E:S.maxX,b:m.isPoint?m.bounds.minX-I:C.minX}:P<-_&&(M={a:g.isPoint?g.bounds.minX-E:S.minX,b:m.isPoint?m.bounds.maxX+I:C.maxX});let A=null;T>_?A={a:g.isPoint?g.bounds.maxY+E:S.maxY,b:m.isPoint?m.bounds.minY-I:C.minY}:T<-_&&(A={a:g.isPoint?g.bounds.minY-E:S.minY,b:m.isPoint?m.bounds.maxY+I:C.maxY});let j=f?1-h.elbowMidpoint:h.elbowMidpoint,O=M?(0,r.CcK)(M.a,M.b,j):null,D=A?(0,r.CcK)(A.a,A.b,j):null,L={options:h,swapOrder:f,A:{isPoint:g.isPoint,target:g.target,isExact:g.isExact,arrowheadOffset:g.arrowheadOffset,minEndSegmentLength:g.minEndSegmentLength,original:g.bounds,expanded:S,edges:y,geometry:g.geometry},B:{isPoint:m.isPoint,target:m.target,isExact:m.isExact,arrowheadOffset:m.arrowheadOffset,minEndSegmentLength:m.minEndSegmentLength,original:m.bounds,expanded:C,edges:b,geometry:m.geometry},common:k,gapX:P,gapY:T,midX:O,midY:D},R=new f$(L),F=f0(g,m,L.A.edges),z=f0(m,g,L.B.edges);return F&&z?d=(l=fY(o=R,s=F,a=z))?l:o.A.isPoint&&o.B.isPoint?fG(o,[[fP[s],fP[a],"manual","manual"],[s,fP[a],"manual","auto"],[fP[s],a,"auto","manual"]]):o.A.isPoint?fY(o,fP[s],a):o.B.isPoint?fY(o,s,fP[a]):null:F&&!z&&(d=function(e,t){let n=null,i=e.A.edges.right,o=e.A.edges.left,s=e.B.edges.top,a=e.B.edges.bottom;switch(t){case"right":e.gapX>0&&e.gapX>Math.abs(e.gapY)&&null!==e.midX?n=fY(e,"right","left"):i&&s&&(i.expanded??i.value)<=s.crossTarget&&i.crossTarget<=(s.expanded??s.value)?n=fY(e,"right","top"):i&&a&&(i.expanded??i.value)<=a.crossTarget&&i.crossTarget>=(a.expanded??a.value)&&(n=fY(e,"right","bottom"));break;case"left":e.gapX<0&&Math.abs(e.gapX)>Math.abs(e.gapY)&&null!==e.midX?n=fY(e,"left","right"):o&&s&&(o.expanded??o.value)>=s.crossTarget&&o.crossTarget<=(s.expanded??s.value)?n=fY(e,"left","top"):o&&a&&(o.expanded??o.value)>=a.crossTarget&&o.crossTarget>=(a.expanded??a.value)&&(n=fY(e,"left","bottom"));break;case"top":case"bottom":break;default:(0,r.h6G)(t)}if(n)return n.aEdgePicking="manual",n.bEdgePicking="auto",n;switch(t){case"top":return fG(e,[["top","bottom","manual","auto"],["top","right","manual","auto"],["top","left","manual","auto"],["top","top","manual","auto"]]);case"bottom":return fG(e,[["bottom","top","manual","auto"],["bottom","right","manual","auto"],["bottom","left","manual","auto"],["bottom","bottom","manual","auto"]]);case"left":return fG(e,[["left","right","manual","auto"],["left","bottom","manual","auto"],["left","left","manual","auto"],["left","top","manual","auto"]]);case"right":return fG(e,[["right","left","manual","auto"],["right","bottom","manual","auto"],["right","right","manual","auto"],["right","top","manual","auto"]])}}(R,F)),d||(d=function(e,t){let n=null;if(Math.abs(e.gapX)+1>Math.abs(e.gapY)&&null!==e.midX)n=e.gapX>0?fY(e,"right","left"):fY(e,"left","right");else{let t=e.A.edges.right,r=e.A.edges.left,i=e.B.edges.top,o=e.B.edges.bottom;e.A.isPoint&&e.B.isPoint?n=e.gapY>0?fY(e,"bottom","top"):fY(e,"top","bottom"):t&&i&&(t.expanded??t.value)<=i.crossTarget&&t.crossTarget<=(i.expanded??i.value)?n=fY(e,"right","top"):t&&o&&(t.expanded??t.value)<=o.crossTarget&&t.crossTarget>=(o.expanded??o.value)?n=fY(e,"right","bottom"):r&&i&&(r.expanded??r.value)>=i.crossTarget&&r.crossTarget<=(i.expanded??i.value)?n=fY(e,"left","top"):r&&o&&(r.expanded??r.value)>=o.crossTarget&&r.crossTarget>=(o.expanded??o.value)?n=fY(e,"left","bottom"):e.gapY>0&&null!==e.midY?n=fY(e,"bottom","top"):e.gapY<0&&null!==e.midY&&(n=fY(e,"top","bottom"))}if(n)return n.aEdgePicking=t,n.bEdgePicking=t,n;let r=fS.filter(t=>e.A.edges[t]),i=fS.filter(t=>e.B.edges[t]);return fG(e,r.flatMap(e=>i.map(n=>[e,n,t,t])))}(R,F||z?"fallback":"auto")),d&&(f2("first",L.A,L.B,d),f2("last",L.B,L.A,d),function(e,t,n){if(e){if(e.points.length>=3){let n=e.points[0],i=e.points[1];if(r.l2P.ManhattanDist(n,i)<t.minEndSegmentLength&&(e.points.splice(1,1),e.points.length>=3)){let t=(0,r.YY0)(n.x,i.x)?"y":"x";e.points[1][t]=n[t]}}if(e.points.length>=3){let t=e.points[e.points.length-1],i=e.points[e.points.length-2];if(r.l2P.ManhattanDist(t,i)<n.minEndSegmentLength&&(e.points.splice(e.points.length-2,1),e.points.length>=3)){let n=(0,r.YY0)(t.x,i.x)?"y":"x";e.points[e.points.length-2][n]=t[n]}}}}(d,g,m),f&&d.points.reverse()),{...L,route:d,midXRange:M?f?{lo:M.b,hi:M.a}:{lo:M.a,hi:M.b}:null,midYRange:A?f?{lo:A.b,hi:A.a}:{lo:A.a,hi:A.b}:null}}function fX(e,t,n,i,o){let s=e.getCurrentTheme(),a=(o??s.strokeWidth*G[t.props.size])*t.props.scale/2,l=3*a;if(n){let i=e.getShape(n.toId),o=function(e,t,n,i){let o="start"===i.terminal?"none"!==t.props.arrowheadStart:"none"!==t.props.arrowheadEnd,s=e.getShapeGeometry(n,o?void 0:{context:"@tldraw/arrow-without-arrowhead"});if(!s)return null;let a=e.getShapePageTransform(t.id),l=e.getShapePageTransform(n),d=a.clone().invert().multiply(l),c=s.transform(d),h={x:.5,y:.5},u=i.isPrecise?i.normalizedAnchor:h,p={x:(0,r.CcK)(s.bounds.minX,s.bounds.maxX,u.x),y:(0,r.CcK)(s.bounds.minY,s.bounds.maxY,u.y)},f={x:(0,r.CcK)(s.bounds.minX,s.bounds.maxX,h.x),y:(0,r.CcK)(s.bounds.minY,s.bounds.maxY,h.y)},g=r.V8r.applyToPoint(d,p),m=r.V8r.applyToPoint(d,f);return{bounds:c.bounds,geometry:c,target:g,center:m,shapeToArrowTransform:d}}(e,t,n.toId,n.props);if(o&&i){var d;let e=0,c="start"===n.props.terminal?"arrowheadStart":"arrowheadEnd";if("none"!==t.props[c]){let n="scale"in i.props?i.props.scale:1;e=a+("size"in i.props?s.strokeWidth*(G[i.props.size]??0)*n/2:0)+10*t.props.scale}let h=null,u=o.target;return n.props.isPrecise&&(d=r.l2P.RotWith(n.props.normalizedAnchor,{x:.5,y:.5},o.shapeToArrowTransform.rotation()),h=(0,r.YY0)(d.x,.5)&&(0,r.YY0)(d.y,.5)?null:Math.abs(d.x-.5)>Math.abs(d.y-.5)-1e-4?d.x<.5?"left":"right":d.y<.5?"top":"bottom"),{targetShapeId:n.toId,isPoint:!1,isExact:n.props.isExact,bounds:o.bounds,geometry:o.geometry,target:u,arrowheadOffset:e,minEndSegmentLength:l,side:h,snap:n.props.snap}}}return{targetShapeId:null,bounds:r.azJ.FromCenter(i,{x:0,y:0}),geometry:null,isExact:!1,isPoint:!0,target:r.l2P.From(i),arrowheadOffset:0,minEndSegmentLength:l,side:null,snap:"none"}}let fJ={top:{expand:-1,main:"minY",opposite:"maxY",crossMid:"midX",crossMin:"minX",crossMax:"maxX",bRangeExpand:"max",crossAxis:"x"},bottom:{expand:1,main:"maxY",opposite:"minY",crossMid:"midX",crossMin:"minX",crossMax:"maxX",bRangeExpand:"min",crossAxis:"x"},left:{expand:-1,main:"minX",opposite:"maxX",crossMid:"midY",crossMin:"minY",crossMax:"maxY",bRangeExpand:"max",crossAxis:"y"},right:{expand:1,main:"maxX",opposite:"minX",crossMid:"midY",crossMin:"minY",crossMax:"maxY",bRangeExpand:"min",crossAxis:"y"}};function fZ(e,t,n,i){var o,s,a,l,d;let c,h=fJ[n],u=e.targetShapeId===t.targetShapeId&&null!==e.targetShapeId&&("edge"===e.snap||"edge-point"===e.snap)&&("edge"===t.snap||"edge-point"===t.snap),p=e.bounds[h.main],f=e.isPoint?null:p+h.expand*i.expandElbowLegLength,g=fE(e.bounds[h.crossMin],e.bounds[h.crossMax]),m=g;if(!m)return null;(0,r.vAR)(g);let y=fE(t.bounds[h.main],t.bounds[h.opposite]);t.isPoint||(y[h.bRangeExpand]-=2*i.minElbowLegLength*h.expand);let b=(o=fE(t.bounds[h.crossMin],t.bounds[h.crossMax]),s=i.expandElbowLegLength,(c={min:o.min-s,max:o.max+s}).min>c.max?null:c);(0,r.vAR)(y&&b);let x=!1;if(fI(p,y)&&!e.isPoint&&!t.isPoint&&!u){let e=(a=m,((0,r.vAR)(a.min<=a.max&&b.min<=b.max),a.min<=b.min&&b.max<=a.max)?[{min:a.min,max:b.min},{min:b.max,max:a.max}]:b.max<=a.min||b.min>=a.max?[a]:b.min<=a.min&&a.max<=b.max?[]:fI(a.min,b)?[{min:b.max,max:a.max}]:fI(a.max,b)?[{min:a.min,max:b.min}]:[]);switch(e.length){case 0:return null;case 1:x=e[0]!==m,m=e[0];break;case 2:x=!0,m=(l=e[0]).max-l.min>(d=e[1]).max-d.min?e[0]:e[1];break;default:(0,r.h6G)(e)}}return fI(e.target[h.crossAxis],m)?{value:p,expanded:f,cross:m,crossTarget:e.target[h.crossAxis],isPartial:x}:null}function fQ(e,t){return null===t?!!(e.bottom||e.left||e.right||e.top):"x"===t?!!e.left||!!e.right:"y"===t?!!e.top||!!e.bottom:!!e[t]}function f0(e,t,n){switch(e.side){case null:return null;case"x":if(e.bounds.center.x>t.bounds.center.x&&n?.left)return"left";if(n?.right)return"right";return null;case"y":if(e.bounds.center.y>t.bounds.center.y&&n?.top)return"top";if(n?.bottom)return"bottom";return null;default:return e.side}}function f1(e){if(e.isPoint)return e;let t=null,n=0;return("edge"===e.snap||"edge-point"===e.snap)&&(n=e.arrowheadOffset,("x"===e.side||"left"===e.side||"right"===e.side)&&(t="x"),("y"===e.side||"top"===e.side||"bottom"===e.side)&&(t="y")),{targetShapeId:e.targetShapeId,side:t,bounds:new r.azJ(e.target.x,e.target.y,0,0),geometry:e.geometry,target:e.target,arrowheadOffset:n,minEndSegmentLength:e.minEndSegmentLength,isExact:e.isExact,isPoint:!0,snap:e.snap}}function f2(e,t,n,i){if(!t.geometry)return;let o="first"===e?i.points[0]:i.points[i.points.length-1],s="first"===e?i.points[1]:i.points[i.points.length-2],a=t.geometry.isClosed?s:t.target,l=r.l2P.ManhattanDist(o,a),d=null,c=1/0;if(t.isExact)d=t.target;else if(t.geometry){let e=t.geometry.intersectLineSegment(s,t.target,{includeLabels:!1,includeInternal:!1});for(let n of(t.geometry.hitTestPoint(t.target,Math.max(1,t.arrowheadOffset),!0,r.MI8.EXCLUDE_NON_STANDARD)&&e.push(t.target),e)){let e=r.l2P.ManhattanDist(a,n);e<c&&(c=e,d=n)}}if(d){let a=t.arrowheadOffset,c=r.l2P.ManhattanDist(s,d),h=2*t.arrowheadOffset;c<h&&(a=c-(h-t.arrowheadOffset)),a<t.minEndSegmentLength&&(a=t.geometry.bounds.containsPoint(n.target)?Math.max(0,a):-t.arrowheadOffset);let u=d,p=!1;if(!t.isExact&&0!==a){let e=r.l2P.Nudge(d,s,a);u=e,a<0&&!t.geometry.hitTestPoint(e,0,!0,r.MI8.EXCLUDE_NON_STANDARD)?u=d:(a<0&&(p=!0),u=e)}let f=r.l2P.ManhattanDist(s,u);if(i.distance+=f-l,o.x=u.x,o.y=u.y,p){let t=r.l2P.Lrp(s,o,.5);i.skipPointsWhenDrawing.add(t),i.points.splice("first"===e?1:i.points.length-1,0,t)}}}function f3(e,t,n){if(!e.geometry||e.geometry.isClosed)return e;let i=e.geometry.uninterpolateAlongEdge(e.target,r.MI8.EXCLUDE_NON_STANDARD),o=e.geometry.interpolateAlongEdge(i-.01/e.geometry.length),s=e.geometry.interpolateAlongEdge(i+.01/e.geometry.length).sub(o).per().uni(),a=Math.abs(s.x)>Math.abs(s.y)?fT.x:fT.y;if(e.geometry.bounds.containsPoint(t.target,n.expandElbowLegLength))return e.side=a.self,f1(e);let l=a.v(e.target[a.self]-2*e.bounds[a.size],e.target[a.cross]),d=a.v(e.target[a.self]+2*e.bounds[a.size],e.target[a.cross]),c=null,h=0,u=null,p=0,f=a.self;for(let t of e.geometry.intersectLineSegment(l,d,r.MI8.EXCLUDE_NON_STANDARD))!(1>Math.abs(t[a.self]-e.target[a.self]))&&(t[a.self]<e.target[a.self]?r.l2P.ManhattanDist(t,e.target)>h&&(h=r.l2P.ManhattanDist(t,e.target),c=t):r.l2P.ManhattanDist(t,e.target)>p&&(p=r.l2P.ManhattanDist(t,e.target),u=t));return c&&u?f=h>p?a.hiEdge:a.loEdge:c&&!u?f=a.hiEdge:!c&&u&&(f=a.loEdge),e.side=f,e}let f5=(0,l7.uY)("arrow info",(e,t)=>{let n=dr(e,t),i=e.getShapeUtil(t),o="getDisplayValues"in i.options?fb(i,t).strokeWidth:e.getCurrentTheme().strokeWidth*G[t.props.size];if("elbow"===t.props.kind){let r=fq(e,t,n,o);if(!r?.route)return fx(e,t,n,o);let i=r.swapOrder?r.B:r.A,s=r.swapOrder?r.A:r.B;return{type:"elbow",bindings:n,start:{handle:i.target,point:r.route.points[0],arrowhead:t.props.arrowheadStart},end:{handle:s.target,point:r.route.points[r.route.points.length-1],arrowhead:t.props.arrowheadEnd},elbow:r,route:r.route,isValid:!0}}return"arc"===t.props.kind&&Math.abs(t.props.bend)<8*t.props.scale?fx(e,t,n,o):function(e,t,n,i){let{arrowheadEnd:o,arrowheadStart:s}=t.props,a=t.props.bend;if(Math.abs(a)>Math.abs(t.props.bend*(10*t.props.scale)))return fx(e,t,n,i);let l=di(e,t,n),d=r.l2P.Med(l.start,l.end),c=r.l2P.Sub(l.end,l.start),h=r.l2P.Len(c)?c.uni():r.l2P.From(c),u=r.l2P.Add(d,h.per().mul(-a)),p=e.getCurrentTheme(),f=i??p.strokeWidth*G[t.props.size],g=de(e,t,"start"),m=de(e,t,"end"),y=l.start.clone(),b=l.end.clone(),x=u.clone();if(r.l2P.Equals(y,b))return{bindings:n,type:"straight",start:{handle:y,point:y,arrowhead:t.props.arrowheadStart},end:{handle:b,point:b,arrowhead:t.props.arrowheadEnd},middle:x,isValid:!1,length:0};let w=t.props.bend<0,v=w?r.KMq:r.IM4,S=fv(y,b,x),C=r.l2P.Angle(S.center,y),k=r.l2P.Angle(S.center,b),P=v(C,k);if(0===S.length||0===S.size||!(0,r._Bd)(S.length)||!(0,r._Bd)(S.size))return fx(e,t,n,i);let T=y.clone(),E=b.clone(),I=x.clone(),_=e.getShapePageTransform(t),M=0,A=0,j=10*t.props.scale;if(g&&!g.isExact){let n,i=r.V8r.applyToPoint(_,T),o=r.V8r.applyToPoint(_,S.center),a=r.V8r.applyToPoint(_,E),l=r.V8r.Inverse(g.transform),d=r.V8r.applyToPoint(l,i),c=r.V8r.applyToPoint(l,o),h=r.V8r.applyToPoint(l,a),{isClosed:u}=g,m=Array.from(g.geometry.intersectCircle(c,S.radius,{includeLabels:!1,includeInternal:!1}));if(m.length){let e=c.angle(d),t=v(e,c.angle(h));m=m.filter(n=>v(e,c.angle(n))<=t);let r=.25*t;m.sort(u?(t,n)=>Math.abs(v(e,c.angle(t))-r)<Math.abs(v(e,c.angle(n))-r)?-1:1:(t,n)=>v(e,c.angle(t))<v(e,c.angle(n))?-1:1),n=m[0]}if(!n)if(u){let e=g.geometry.nearestPoint(d,{includeInternal:!1,includeLabels:!1});r.l2P.DistMin(e,d,1)&&(n=e)}else n=d;if(n&&(T.setTo(e.getPointInShapeSpace(t,r.V8r.applyToPoint(g.transform,n))),g.didIntersect=!0,"none"!==s)){let e=f/2+("size"in g.shape.props?p.strokeWidth*G[g.shape.props.size]/2:0);M=(10+e)*t.props.scale,j+=e*t.props.scale}}if(m&&!m.isExact){let n,i=r.V8r.applyToPoint(_,T),s=r.V8r.applyToPoint(_,E),a=r.V8r.applyToPoint(_,S.center),l=r.V8r.Inverse(m.transform),d=r.V8r.applyToPoint(l,i),c=r.V8r.applyToPoint(l,a),h=r.V8r.applyToPoint(l,s),u=m.isClosed,g=Array.from(m.geometry.intersectCircle(c,S.radius,{includeLabels:!1,includeInternal:!1}));if(g.length){let e=c.angle(d),t=v(e,c.angle(h)),r=.75*t;(g=g.filter(n=>v(e,c.angle(n))<=t)).sort(u?(t,n)=>Math.abs(v(e,c.angle(t))-r)<Math.abs(v(e,c.angle(n))-r)?-1:1:(t,n)=>v(e,c.angle(t))<v(e,c.angle(n))?-1:1),n=g[0]}if(!n)if(u){let e=m.geometry.nearestPoint(h,{includeInternal:!1,includeLabels:!1});r.l2P.DistMin(e,h,1)&&(n=e)}else n=h;if(n&&(E.setTo(e.getPointInShapeSpace(t,r.V8r.applyToPoint(m.transform,n))),m.didIntersect=!0,"none"!==o)){let e=f/2+("size"in m.shape.props?p.strokeWidth*G[m.shape.props.size]/2:0);A=(10+e)*t.props.scale,j+=e*t.props.scale}}dd(e,T,y,_,g),dd(e,E,b,_,m);let O=r.l2P.Angle(S.center,T),D=r.l2P.Angle(S.center,E),L=v(O,D),R=L*S.radius,F=T.clone(),z=E.clone();if(0!==M&&F.setTo(S.center).add(r.l2P.FromAngle(O+M/R*(w?1:-1)*L).mul(S.radius)),0!==A&&z.setTo(S.center).add(r.l2P.FromAngle(D+A/R*(w?-1:1)*L).mul(S.radius)),r.l2P.DistMin(F,z,j)){0!==M&&0!==A?(M*=-1.5,A*=-1.5):0!==M?M*=-2:0!==A&&(A*=-2);let e=.1-v(C,O)*S.radius,t=.1-v(D,k)*S.radius;M=Math.max(M,e),A=Math.max(A,t)}if(0!==M&&T.setTo(S.center).add(r.l2P.FromAngle(O+M/R*(w?1:-1)*L).mul(S.radius)),0!==A&&E.setTo(S.center).add(r.l2P.FromAngle(D+A/R*(w?-1:1)*L).mul(S.radius)),g&&m&&!g.isExact&&!m.isExact){R=(L=v(O=r.l2P.Angle(S.center,T),D=r.l2P.Angle(S.center,E)))*S.radius;let n=dl(e,g.shape.id,m.shape.id);"double-bound"===n&&R<30?(T.setTo(y),E.setTo(b),I.setTo(x)):"safe"===n&&(g&&!g.didIntersect&&T.setTo(y),(m&&!m.didIntersect||v(C,O)>v(C,D))&&E.setTo(S.center).add(r.l2P.FromAngle(O+L*(Math.min(.9,10*t.props.scale/R)*(w?1:-1))).mul(S.radius)))}(function(e,t,n,i,o,s,a){let l=r.l2P.Angle(e,n),d=r.l2P.Angle(e,i),c=(0,r.KMq)(l,d);if(a||(c=r.uAR-c),o.setTo(e).add(r.l2P.FromAngle(l+.5*(a?1:-1)*c).mul(t)),c>s){o.rotWith(e,r.PI);let t=i.clone();i.setTo(n),n.setTo(t)}})(S.center,S.radius,T,E,I,P,w),T.equals(E)&&(T.setTo(I.clone().addXY(1,1)),E.setTo(I.clone().subXY(1,1))),y.setTo(T),b.setTo(E),x.setTo(I);let N=fv(y,b,x);return{bindings:n,type:"arc",start:{point:y,handle:l.start,arrowhead:t.props.arrowheadStart},end:{point:b,handle:l.end,arrowhead:t.props.arrowheadEnd},middle:x,handleArc:S,bodyArc:N,isValid:0!==N.length&&isFinite(N.center.x)&&isFinite(N.center.y)}}(e,t,n,o)},{areRecordsEqual:(e,t)=>e.props===t.props,areResultsEqual:r.Ao2});function f6(e,t){let n="string"==typeof t?t:t.id;return f5.get(e,n)}class f4 extends r.bU{static type="arrow_binding_hint";options={zIndex:150,strokeWidth:2,opacity:.16,dashLengthRatio:2.5,dotRadius:4,crossSize:6,dashedMinZoom:.2};isActive(){let e=this.editor;if(e.getIsReadonly())return!1;let t=e.getOnlySelectedShapeId();if(!t)return!1;let n=e.getShape(t);if(!n||"arrow"!==n.type||!e.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging"))return!1;let r=dr(e,n);return!!(r.start||r.end)}getOverlays(){let e=this.editor.getOnlySelectedShapeId();return e?[{id:"arrow_binding_hint",type:"arrow_binding_hint",props:{arrowId:e}}]:[]}render(e,t){let n=t[0];if(!n)return;let r=this.editor,i=r.getShape(n.props.arrowId);if(!i)return;let o=f6(r,i);if(!o?.isValid)return;let s=dr(r,i);if(!s.start&&!s.end)return;let a=r.getShapePageTransform(i);if(!a)return;let l=r.getZoomLevel(),d=r.getCurrentTheme().colors[r.getColorMode()],c=this.options.strokeWidth/l;e.save(),e.transform(a.a,a.b,a.c,a.d,a.e,a.f),e.strokeStyle=d.text,e.fillStyle=d.text,e.lineWidth=c,e.lineCap="round",e.lineJoin="round",e.globalAlpha=this.options.opacity,s.start&&this.drawEndpoint(e,o,"start",s.start.props.isExact,s.start.props.isPrecise,c,l),s.end&&this.drawEndpoint(e,o,"end",s.end.props.isExact,s.end.props.isPrecise,c,l),e.restore()}drawEndpoint(e,t,n,i,o,s,a){let l=t[n].handle,d=t[n].point,c=r.l2P.Dist(l,d),h=(o?this.options.crossSize/2*Math.SQRT2:this.options.dotRadius)/a;if(c>h+.5){let i;if(e.save(),e.beginPath(),"arc"===t.type){let{center:o,radius:s,sweepFlag:a}=t.bodyArc,c=Math.atan2(d.y-o.y,d.x-o.x),u=Math.atan2(l.y-o.y,l.x-o.x),p=!a,f=u+h/s*((a?1:-1)*("start"===n?1:-1)),g=c-u;g>Math.PI?g-=r.uAR:g<-Math.PI&&(g+=r.uAR),i=Math.max(0,s*Math.abs(g)-h),"start"===n?e.arc(o.x,o.y,s,f,c,p):e.arc(o.x,o.y,s,c,f,p)}else{i=c-h;let t=h/c,n={x:l.x+(d.x-l.x)*t,y:l.y+(d.y-l.y)*t};e.moveTo(n.x,n.y),e.lineTo(d.x,d.y)}if(a>=this.options.dashedMinZoom){let{strokeDasharray:t,strokeDashoffset:n}=(0,r.EK8)(i,s,{style:"dashed",end:"skip",start:"skip"});if("none"!==t){let[r,i]=t.split(" ").map(Number);e.setLineDash([r,i]),e.lineDashOffset=Number(n)}}e.stroke(),e.restore()}if(i)return;let u=c>.5?this.getMarkerAngle(t,n,l,d):0;if(o){let t=this.options.crossSize/a/2;e.save(),e.translate(l.x,l.y),e.rotate(u),e.beginPath(),e.moveTo(-t,-t),e.lineTo(t,t),e.moveTo(-t,t),e.lineTo(t,-t),e.stroke(),e.restore()}else{let t=this.options.dotRadius/a;e.beginPath(),e.arc(l.x,l.y,t,0,r.uAR),e.stroke()}}getMarkerAngle(e,t,n,r){if("arc"===e.type){let{center:r,sweepFlag:i}=e.bodyArc;return Math.atan2(n.y-r.y,n.x-r.x)+(i?1:-1)*("start"===t?1:-1)*Math.PI/2}return Math.atan2(r.y-n.y,r.x-n.x)}}class f8 extends r.mbh{static type="arrow";static props=r.P_i;static migrations=r.g8l;getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5},snap:"none"}}onAfterCreate({binding:e}){let t=this.editor.getShape(e.fromId);t&&f7(this.editor,t)}onAfterChange({bindingAfter:e}){let t=this.editor.getShape(e.fromId);t&&f7(this.editor,t)}onAfterChangeFromShape({shapeBefore:e,shapeAfter:t,reason:n}){("ancestry"===n||e.parentId!==t.parentId||e.index!==t.index)&&f7(this.editor,t)}onAfterChangeToShape({binding:e,shapeBefore:t,shapeAfter:n,reason:i}){e.props.isPrecise&&"geo"===t.type&&"geo"===n.type&&t.props.geo!==n.props.geo&&this.editor.isIn("select.idle")&&!this.editor.isReplayingHistory()&&function(e,t,n){let i=e.getShapeGeometry(n);if(!i.isClosed)return;let{point:o,size:s}=i.bounds;if(0===s.x||0===s.y)return;let a=r.l2P.Add(o,r.l2P.MulV(t.props.normalizedAnchor,s));if(i.hitTestPoint(a,0,!0))return;let l=i.nearestPoint(a,r.MI8.EXCLUDE_LABELS);e.updateBinding({id:t.id,type:t.type,props:{normalizedAnchor:{x:(l.x-o.x)/s.x,y:(l.y-o.y)/s.y}}})}(this.editor,e,n),("ancestry"===i||t.parentId!==n.parentId||t.index!==n.index)&&f9(this.editor,e.fromId)}onBeforeIsolateFromShape({binding:e}){if(this.editor.isReplayingHistory())return;let t=this.editor.getShape(e.fromId);t&&ge({editor:this.editor,arrow:t,terminal:e.props.terminal})}}function f9(e,t){let n,i,o,s=e.getShape(t);if(!s)return;let{start:a,end:l}=dr(e,s),d=a?e.getShape(a.toId):void 0,c=l?e.getShape(l.toId):void 0,h=e.getAncestorPageId(s);if(!h)return;if(d&&c){var u,p,f;let t;n=(u=e,p=d,f=c,p.id===f.id?t=p:u.hasAncestor(p,f.id)?t=f:u.hasAncestor(f,p.id)&&(t=p),(t&&u.isShapeFrameLike(t)?t.id:void 0)??e.findCommonAncestor([d,c])??h)}else{if(!d&&!c)return;let e=(d||c)?.parentId;n=e&&e===s.parentId?s.parentId:h}n&&n!==s.parentId&&e.reparentShapes([t],n);let g=e.getShape(t);if(!g)throw Error("no reparented arrow");let m=e.getShapeNearestSibling(g,d),y=e.getShapeNearestSibling(g,c);if(m&&y)i=m.index>y.index?m:y;else if(m&&!y)i=m;else{if(!y||m)return;i=y}let b=e.getSortedChildIdsForParent(i.parentId).map(t=>e.getShape(t)).filter(e=>e.index>i.index);if(b.length){let e=b.find(e=>"arrow"!==e.type);if(g.index>i.index&&(!e||g.index<e.index))return;o=(0,r.HEt)(i.index,b[0].index)}else o=(0,r.AQy)(i.index);o!==g.index&&e.updateShapes([{id:t,type:"arrow",index:o}])}function f7(e,t){let n=dr(e,t);for(let r of["start","end"]){let i=n[r];if(!i)continue;let o=e.getShape(i.toId),s=e.getAncestorPageId(t)===e.getAncestorPageId(o);o&&s||ge({editor:e,arrow:t,terminal:r,unbind:!0})}f9(e,t.id)}function ge({editor:e,arrow:t,terminal:n,unbind:i=!1,useHandle:o=!1}){let s=f6(e,t);if(!s)throw Error("expected arrow info");let a=gt(o?s.start.handle:s.start.point,t.props.start),l=gt(o?s.end.handle:s.end.point,t.props.end),d="start"===n?a:l,c={id:t.id,type:"arrow",props:{[n]:{x:d.x,y:d.y},bend:t.props.bend}};if("arc"===s.type){let o="start"===n?a:gt(s.start.handle,t.props.start),d="end"===n?l:gt(s.end.handle,t.props.end),h=r.l2P.Med(o,d),u=r.l2P.Sub(o,d);if((0,r.YY0)(r.l2P.Len2(u),0)){e.updateShape(c),i&&da(e,t,n);return}let p=u.per().uni().mul(2*s.handleArc.radius*Math.sign(t.props.bend)),f=r.l2P.Add(h,p);if(!r.l2P.IsFinite(s.handleArc.center)||!Number.isFinite(s.handleArc.radius)||!r.l2P.IsFinite(f)){e.updateShape(c),i&&da(e,t,n);return}let g=(0,r.vrM)(s.handleArc.center,f,s.handleArc.center,s.handleArc.radius);if(g?.length){let e=g.reduce((e,t)=>r.l2P.Dist2(t,f)<r.l2P.Dist2(e,f)?t:e),n=r.l2P.Dist(h,e)*Math.sign(t.props.bend);(0,r.YY0)(n,c.props.bend)||(c.props.bend=n)}}e.updateShape(c),i&&da(e,t,n)}function gt(e,t){return r.l2P.From(r.l2P.IsFinite(e)?e:t)}let gn=new r.laH;function gr(e){return gn.get(e,()=>(0,r.eUv)("arrowTarget",null))}function gi(e){gr(e).set(null)}function go({editor:e,pointInPageSpace:t,arrow:n,isPrecise:i,currentBinding:o,oppositeBinding:s}){let a=e.getShapeUtil("arrow");if(a.options.shouldIgnoreTargets(e))return gr(e).set(null),null;let l=n?n.props.kind:e.getStyleForNextShape(r.qfG),d=e.getShapeAtPoint(t,{hitInside:!0,hitFrameInside:!0,margin:"elbow"===l?8:[8,0],filter:t=>!t.isLocked&&e.canBindShapes({fromShape:n??gs,toShape:t,binding:"arrow"})});if(!d)return gr(e).set(null),null;let c=e.getShapeGeometry(d),h=r.azJ.ZeroFix(c.bounds),u=c.center,p=e.getShapePageTransform(d),f=e.getPointInShapeSpace(d,t),g=Math.max(c.bounds.width,c.bounds.height),m=(0,r._Hz)(fC,(e,t)=>{let n=fT[fk[e]],i=r.l2P.Mul(t,g).add(u),o=!1,s=n.v(h[e],h[n.crossMid]),a=0;for(let e of c.intersectLineSegment(u,i,r.MI8.EXCLUDE_NON_STANDARD)){let t=r.l2P.Dist2(e,u);t>a&&(a=t,s=e,o=c.isClosed)}return{point:p.applyToPoint(s),isEnabled:o,far:p.applyToPoint(i)}}),y=e.getZoomLevel(),b=a.options.minElbowHandleDistance/y,x=p.applyToPoint(u);for(let e of(0,r.w$g)(m)){let t=m[e];r.l2P.DistMin(t.point,x,b)&&(t.isEnabled=!1)}let w=i;w||o&&(!o||d.id===o.toId)||(w=.5>e.inputs.getPointerVelocity().len()),!i&&(c.isClosed||(w=!0),s&&d.id===s.toId&&s.props.isPrecise&&(w=!0));let v=a.options.shouldBeExact(e,w);v&&(w=!0);let S=!v&&w&&c.isClosed,C=!v&&(w&&"elbow"===l||!c.isClosed),k=!v&&w&&"elbow"===l&&c.isClosed,P=w&&(c.isClosed||v),T=!v&&w&&"elbow"===l&&c.isClosed,E="none",I=t;if(P||(E="center",I=x),C){let n=P?ga(e,h,a.options.elbowArrowEdgeSnapDistance):1/0,i=c.nearestPoint(f,{includeLabels:!1,includeInternal:!1}),o=p.applyToPoint(i);r.l2P.Dist(o,t)<n&&(E="edge",I=o)}if(T){let n=ga(e,h,a.options.elbowArrowAxisSnapDistance),i=r.l2P.DistanceToLineSegment(m.left.far,m.right.far,t),o=r.l2P.DistanceToLineSegment(m.top.far,m.bottom.far,t),s=i<o&&i<n?"x":o<n?"y":null;if(s){let e=fT[s],n=r.l2P.Dist2(m[e.loEdge].far,t)<r.l2P.Dist2(m[e.hiEdge].far,t)?e.loEdge:e.hiEdge;m[n].isEnabled&&(E="edge-point",I=m[n].point)}}if(k){let n=ga(e,h,a.options.elbowArrowPointSnapDistance),i=null,o=1/0;for(let[e,s]of(0,r.iAN)(m)){if(!s.isEnabled)continue;let a=r.l2P.Dist(s.point,t);a<n&&a<o&&(o=a,i=e)}i&&(E="edge-point",I=m[i].point)}if(S){let t=ga(e,h,"elbow"===l?a.options.elbowArrowCenterSnapDistance:a.options.arcArrowCenterSnapDistance);r.l2P.Dist(f,h.center)<t&&(E="center",I=x)}let _=e.getPointInShapeSpace(d,I),M={target:d,arrowKind:l,handlesInPageSpace:m,centerInPageSpace:x,anchorInPageSpace:I,isExact:v,isPrecise:w,snap:E,normalizedAnchor:{x:(0,r.Fg_)(h.minX,h.maxX,_.x),y:(0,r.Fg_)(h.minY,h.maxY,_.y)}};return gr(e).set(M),M}let gs={type:"arrow"};function ga(e,t,n){return(0,r.qE8)(.15*Math.min(t.width,t.height),4,n)/e.getZoomLevel()}let gl=(0,r.uYT)("arrowHintIndicatorPath",(e,t)=>e.getShapeUtil(t).getIndicatorPath(t),{areRecordsEqual:(e,t)=>e.props===t.props});class gd extends r.bU{static type="arrow_hint";options={zIndex:1e3,lineWidth:1.5,edgeRadius:8,edgePointRadius:12,handleRadius:4};isActive(){let e=this.editor;if(e.isInAny("arrow.idle","arrow.pointing"))return!0;if(e.isIn("select.pointing_handle")){let t=e.getStateDescendant("select.pointing_handle");if("arrow"===t.info.shape.type&&("start"===t.info.handle.id||"end"===t.info.handle.id))return!0}if(e.isIn("select.dragging_handle")){let t=e.getStateDescendant("select.dragging_handle");if("arrow"===t.info.shape.type&&("start"===t.info.handle.id||"end"===t.info.handle.id))return!0}return!1}getOverlays(){let e=gr(this.editor).get();if(!e)return[];let{handlesInPageSpace:t,snap:n,anchorInPageSpace:r,arrowKind:i,isExact:o,isPrecise:s}=e;return[{id:"arrow_hint",type:"arrow_hint",props:{targetId:e.target.id,handles:{top:{x:t.top.point.x,y:t.top.point.y,isEnabled:t.top.isEnabled},bottom:{x:t.bottom.point.x,y:t.bottom.point.y,isEnabled:t.bottom.isEnabled},left:{x:t.left.point.x,y:t.left.point.y,isEnabled:t.left.isEnabled},right:{x:t.right.point.x,y:t.right.point.y,isEnabled:t.right.isEnabled}},anchorX:r.x,anchorY:r.y,snap:n,isExact:o,isPrecise:s,arrowKind:i,showEdgeHints:!o&&"elbow"===i}}]}render(e,t){let n=t[0];if(!n)return;let r=this.editor,i=r.getZoomLevel(),o=r.getCurrentTheme().colors[r.getColorMode()],{targetId:s,handles:a,anchorX:l,anchorY:d,snap:c,showEdgeHints:h}=n.props,u=r.getShape(s);if(u){let t=r.getShapePageTransform(u),n=gl.get(r,s);t&&n&&(e.save(),e.transform(t.a,t.b,t.c,t.d,t.e,t.f),e.strokeStyle=o.selectionStroke,e.lineWidth=this.options.lineWidth/i,e.lineCap="round",e.lineJoin="round",this._renderIndicatorPath(e,n),e.restore())}if(!h)return;if("edge"===c||"edge-point"===c){let t=("edge-point"===c?this.options.edgePointRadius:this.options.edgeRadius)/i;e.beginPath(),e.arc(l,d,t,0,2*Math.PI),e.fillStyle=o.selectionFill,e.fill()}let p=this.options.handleRadius/i;for(let t of(e.fillStyle=o.selectedContrast,e.strokeStyle=o.selectionStroke,e.lineWidth=this.options.lineWidth/i,e.beginPath(),Object.values(a)))t.isEnabled&&(e.moveTo(t.x+p,t.y),e.arc(t.x,t.y,p,0,2*Math.PI));e.fill(),e.stroke()}_renderIndicatorPath(e,t){if(t instanceof Path2D)e.stroke(t);else{let{path:n,clipPath:r,additionalPaths:i}=t;if(r?(e.save(),e.clip(r,"evenodd"),e.stroke(n),e.restore()):e.stroke(n),i)for(let t of i)e.stroke(t)}}}class gc extends r.bU{static type="brush";options={zIndex:300,getDefaultDisplayValues(e,t,n,r){let i=n.colors[r];return{fillColor:i.brushFill,strokeColor:i.brushStroke,lineWidth:1}},getCustomDisplayValues:()=>({})};isActive(){return null!==this.editor.getInstanceState().brush}getOverlays(){let e=this.editor.getInstanceState().brush;return e?[{id:"brush",type:"brush",props:{x:e.x,y:e.y,w:Math.max(1,e.w),h:Math.max(1,e.h)}}]:[]}render(e,t){let n=t[0];if(!n)return;let{x:i,y:o,w:s,h:a}=n.props,l=this.editor.getZoomLevel(),d=(0,r.tjK)(this,n);e.fillStyle=d.fillColor,e.fillRect(i,o,s,a),e.lineWidth=d.lineWidth/l,e.strokeStyle=d.strokeColor,e.strokeRect(i,o,s,a)}renderMinimap(e,t,n){let i=t[0];if(!i)return;let{x:o,y:s,w:a,h:l}=i.props,d=(0,r.tjK)(this,i);e.fillStyle=d.fillColor,e.fillRect(o,s,a,l),e.lineWidth=d.lineWidth/n,e.strokeStyle=d.strokeColor,e.strokeRect(o,s,a,l)}}class gh extends r.bU{static type="zoom_brush";options={zIndex:400,lineWidth:1};isActive(){return null!==this.editor.getInstanceState().zoomBrush}getOverlays(){let e=this.editor.getInstanceState().zoomBrush;return e?[{id:"zoom_brush",type:"zoom_brush",props:{x:e.x,y:e.y,w:Math.max(1,e.w),h:Math.max(1,e.h)}}]:[]}render(e,t){let n=t[0];if(!n)return;let{x:r,y:i,w:o,h:s}=n.props,a=this.editor.getZoomLevel(),l=this.editor.getCurrentTheme().colors[this.editor.getColorMode()];e.fillStyle=l.brushFill,e.fillRect(r,i,o,s),e.lineWidth=this.options.lineWidth/a,e.strokeStyle=l.brushStroke,e.strokeRect(r,i,o,s)}renderMinimap(e,t,n){let r=t[0];if(!r)return;let{x:i,y:o,w:s,h:a}=r.props,l=this.editor.getCurrentTheme().colors[this.editor.getColorMode()];e.fillStyle=l.brushFill,e.fillRect(i,o,s,a),e.lineWidth=this.options.lineWidth/n,e.strokeStyle=l.brushStroke,e.strokeRect(i,o,s,a)}}let gu=e=>e*(2-e),gp=e=>--e*e*e+1,{min:gf}=Math,gg=256,gm=new Float64Array(256),gy=new Float64Array(gg),gb=new Float64Array(gg),gx=new Float64Array(gg),gw=new Float64Array(gg),gv=new Float64Array(gg),gS=new Float64Array(gg),gC=new Float64Array(gg),gk=new Float64Array(gg),gP=0,gT=256,gE=new Float64Array(256),gI=new Float64Array(gT),g_=new Float64Array(gT);function gM(e,t){let n=void 0===e.z?1:e.z;return t&&n<.025?.025:n}function gA(e,t={}){let{streamline:n=.5,size:r=16,simulatePressure:i=!1}=t;gP=0;let o=e.length;if(0===o)return;let s=.15+(1-n)*.85;var a=o+8;if(!(a<=gT)){for(;gT<a;)gT*=2;gE=new Float64Array(gT),gI=new Float64Array(gT),g_=new Float64Array(gT)}var l=o+8;if(!(l<=gg)){for(;gg<l;)gg*=2;gm=new Float64Array(gg),gy=new Float64Array(gg),gb=new Float64Array(gg),gx=new Float64Array(gg),gw=new Float64Array(gg),gv=new Float64Array(gg),gS=new Float64Array(gg),gC=new Float64Array(gg),gk=new Float64Array(gg)}let d=gE,c=gI,h=g_,u=(r/3)**2,p=!i,f=e[0],g=gM(f,p),m=1;for(;m<o;){let t=e[m],n=t.x-f.x,r=t.y-f.y;if(n*n+r*r>u)break;g=Math.max(g,gM(t,p)),m++}d[0]=f.x,c[0]=f.y,h[0]=g;let y=1;for(let t=m;t<o;t++){let n=e[t];d[y]=n.x,c[y]=n.y,h[y]=gM(n,p),y++}let b=0;if(y>1){let e=d[y-1],t=c[y-1],n=y-2;for(;n>=0;){let r=d[n]-e,i=c[n]-t;if(r*r+i*i>u)break;n--,b++}n<y-2&&(d[n+1]=e,c[n+1]=t,h[n+1]=h[y-1],y=n+2)}let x=t.last||!t.simulatePressure||y>1&&(d[y-1]-d[y-2])*(d[y-1]-d[y-2])+(c[y-1]-c[y-2])*(c[y-1]-c[y-2])<r**2||b>0;if(2===y&&t.simulatePressure){let e=d[0],t=c[0],n=h[0],r=d[1],i=c[1],o=h[1];for(let s=1;s<5;s++){let a=s/4;d[s]=e+(r-e)*a,c[s]=t+(i-t)*a,h[s]=(n+(o-n))*s/4}y=5}let w=gm,v=gy,S=gb,C=gx,k=gw,P=gv,T=gS,E=gC,I=gk;w[0]=d[0],v[0]=c[0],S[0]=d[0],C[0]=c[0],k[0]=h[0],P[0]=i?.5:h[0],T[0]=0,E[0]=0,I[0]=1;let _=1;x&&n>0&&(d[y]=d[y-1],c[y]=c[y-1],h[y]=h[y-1],y++);let M=0,A=d[0],j=c[0],O=1-s,D=t.last;for(let e=1;e<y;e++){let t,n;if(!s||D&&e===y-1?(t=d[e],n=c[e]):(t=d[e]+(A-d[e])*O,n=c[e]+(j-c[e])*O),1e-4>Math.abs(A-t)&&1e-4>Math.abs(j-n))continue;let o=((n-j)**2+(t-A)**2)**.5;M+=o,e<4&&M<r||(w[_]=t,v[_]=n,S[_]=d[e],C[_]=c[e],k[_]=h[e],P[_]=i?.5:h[e],T[_]=o,E[_]=M,I[_]=1,_++,A=t,j=n)}if(M<1){let e=.5;for(let t=0;t<_;t++)e=Math.max(e,P[t]);for(let t=0;t<_;t++)P[t]=e}gP=_}function gj(e,t,n){return e?!0===e?Math.max(t,n):e:0}function gO(e){let{size:t=16,thinning:n=.5,simulatePressure:r=!0,easing:i=e=>e,start:o={},end:s={}}=e,{easing:a=gu}=o,{easing:l=gp}=s,d=gP,c=gv,h=gS,u=gC,p=gk,f=u[d-1];if(!r&&f<t){let e=.5;for(let t=0;t<d;t++)e=Math.max(e,c[t]);for(let r=0;r<d;r++)c[r]=e,p[r]=t*i(.5-n*(.5-e));return}let g=c[0];for(let e=0;e<d;e++){let n;if(u[e]>5*t)break;let i=gf(1,h[e]/t);if(r){let e=gf(1,1-i);n=gf(1,g+.275*i*(e-g))}else n=gf(1,g+(c[e]-g)*.5);g+=(n-g)*.5}let m=gj(o.taper,t,f),y=gj(s.taper,t,f),b=m||y;for(let e=0;e<d;e++){let o;if(n){let s=c[e],a=gf(1,h[e]/t);if(r){let e=gf(1,1-a);s=gf(1,g+.275*a*(e-g))}else s=gf(1,g+.275*a*(s-g));o=t*i(.5-n*(.5-s)),g=s}else o=t/2;if(b){let t=u[e];o=Math.max(.01,o*Math.min(t<m?a(t/m):1,f-t<y?l((f-t)/y):1))}p[e]=o}}let gD=256,gL=new Float64Array(256),gR=new Float64Array(gD),gF=new Float64Array(gD),gz=new Float64Array(gD),gN=new Float64Array(gD),g$=new Float64Array(gD),gB=new Float64Array(gD),gH=new Uint8Array(gD),gU=0;function gK(e){if(!(e<=gD)){for(;gD<e;)gD*=2;gL=new Float64Array(gD),gR=new Float64Array(gD),gF=new Float64Array(gD),gz=new Float64Array(gD),gN=new Float64Array(gD),g$=new Float64Array(gD),gB=new Float64Array(gD),gH=new Uint8Array(gD)}}function gW(){let e=gP;gK(e);let t=gL,n=gR,r=gF,i=gz,o=gN,s=g$,a=gB,l=gH,d=gm,c=gy,h=gb,u=gx,p=gw,f=gC,g=gk;for(let m=0;m<e;m++)t[m]=d[m],n[m]=c[m],r[m]=p[m],i[m]=h[m],o[m]=u[m],s[m]=g[m],a[m]=f[m],l[m]=+(0===m||m===e-1);gU=e}let{PI:gV}=Math,gY=gV+1e-4,gG=1024,gq=new Float64Array(1024),gX=new Float64Array(gG),gJ=new Float64Array(gG),gZ=new Float64Array(gG),gQ=0,g0=0;function g1(e,t,n,r){if(n<=2||r<=0)return n;let i=r*r,o=1,s=0,a=n-1;for(;s<a;){let n=s+1,r=s+8>a?a:s+8,l=e[s],d=t[s];r:for(let o=s+2;o<=r;o++){let r=e[o]-l,a=t[o]-d,c=r*r+a*a;for(let n=s+1;n<o;n++){let o=0===c?0:((e[n]-l)*r+(t[n]-d)*a)/c;o=o<0?0:o>1?1:o;let s=e[n]-(l+r*o),h=t[n]-(d+a*o);if(s*s+h*h>i)break r}n=o}e[o]=e[n],t[o]=t[n],o++,s=n}return o}function g2(e,t,n,r){let{size:i=16,smoothing:o=.5}=e,s=0,a=0;gQ=0,g0=0;let l=gU;if(0===l||i<=0)return;let d=gL,c=gR,h=gz,u=gN,p=g$,f=gB,g=gH,m=gq,y=gX,b=gJ,x=gZ,w=f[l-1],v=Math.pow(i*o,2),S=1,C=1;if(l>1){let e=d[0]-d[1],t=c[0]-c[1],n=(e*e+t*t)**.5;0===n?(S=e,C=t):(S=e/n,C=t/n)}let k=S,P=C,T=d[0],E=c[0],I=T,_=E,M=T,A=E,j=I,O=_,D=!1;for(let e=0;e<l;e++){let i=d[e],o=c[e],L=p[e],R=S,F=C,z=R,N=F;if(e<l-1){let s=0===e&&l>2&&t?n:i,a=0===e&&l>2&&t?r:o,h=s-d[e+1],u=a-c[e+1],p=(h*h+u*u)**.5;0===p?(z=h,N=u):(z=h/p,N=u/p)}S=z,C=N,(s+13+1>gG||a+13+1>gG)&&(!function(){let e=new Float64Array(gG*=2);e.set(gq),gq=e;let t=new Float64Array(gG);t.set(gX),gX=t;let n=new Float64Array(gG);n.set(gJ),gJ=n;let r=new Float64Array(gG);r.set(gZ),gZ=r}(),m=gq,y=gX,b=gJ,x=gZ);let $=R*k+F*P,B=e<l-1?z*R+N*F:1,H=B<.2;if($<0&&!D||H){if(B>-.62&&w-f[e]>L){let e=k*L,t=P*L;k*N-P*z<0?(M=i+e,A=o+t,j=i-e,O=o-t):(M=i-e,A=o-t,j=i+e,O=o+t),m[s]=M,y[s]=A,s++,b[a]=j,x[a]=O,a++}else{let t=h[e],n=u[e],r=-P*L,i=k*L;for(let e=0;e<1;e+=.07692307692307693){let o=gY*e,l=Math.sin(o),d=Math.cos(o);M=t+(r*d-i*l),A=n+(r*l+i*d),m[s]=M,y[s]=A,s++,l=Math.sin(o=gY+-(gY*e)),j=t+(r*(d=Math.cos(o))-i*l),O=n+(r*l+i*d),b[a]=j,x[a]=O,a++}}T=M,E=A,I=j,_=O,H&&(D=!0);continue}if(D=!1,g[e]){let e=F*L,t=-R*L;m[s]=i-e,y[s]=o-t,s++,b[a]=i+e,x[a]=o+t,a++;continue}let U=z+(R-z)*B,K=(N+(F-N)*B)*L,W=-U*L;M=i-K,A=o-W,(e<=1||(T-M)**2+(E-A)**2>v)&&(m[s]=M,y[s]=A,s++,T=M,E=A),j=i+K,O=o+W,(e<=1||(I-j)**2+(_-O)**2>v)&&(b[a]=j,x[a]=O,a++,I=j,_=O),k=R,P=F}let L=.05*i;gQ=g1(gq,gX,s,L),g0=g1(gJ,gZ,a,L)}function g3(e,t,n,r,i){if(e<=n)return r;let o=Math.ceil(t/(2*Math.acos(1-n/e)));return o<r?r:o>i?i:o}function g5(e,t={}){return(gA(e,t),0===gP)?[]:(gO(t),gW(),function(e={}){let{size:t=16,start:n={},end:i={},last:o=!1}=e,{cap:s=!0}=n,{cap:a=!0}=i,l=gU;if(0===l||t<=0)return[];let d=gB[l-1],c=gj(n.taper,t,d),h=gj(i.taper,t,d);g2(e,!1,0,0);let u=Math.max(.05,.02*t),p=g$[0],f=new r.l2P(gL[0],gR[0],gF[0]),g=l>1?new r.l2P(gL[l-1],gR[l-1],gF[l-1]):r.l2P.AddXY(f,1,1);if(1===l&&(!(c||h)||o)){let e=r.l2P.Add(f,r.l2P.Sub(f,g).uni().per().mul(-p)),t=[],n=g3(p,2*gY,u,8,13);for(let i=1/n,o=i;o<=1;o+=i)t.push(r.l2P.RotWith(e,f,2*gY*o));return t}let m=[];if(c||h&&1===l);else if(s){let e=new r.l2P(gJ[0],gZ[0]),t=g3(p,gY,u,4,8);for(let n=1/t,i=n;i<=1;i+=n){let t=r.l2P.RotWith(e,f,gY*i);m.push(t)}}else{let e=new r.l2P(gq[0]-gJ[0],gX[0]-gZ[0]),t=r.l2P.Mul(e,.5),n=r.l2P.Mul(e,.51);m.push(r.l2P.Sub(f,t),r.l2P.Sub(f,n),r.l2P.Add(f,n),r.l2P.Add(f,t))}let y=[],b=g$[l-1],x=1,w=1;if(l>1){let e=gL[l-2]-gL[l-1],t=gR[l-2]-gR[l-1],n=(e*e+t*t)**.5;0===n?(x=e,w=t):(x=e/n,w=t/n)}let v=new r.l2P(-w,x);if(h||c&&1===l)y.push(g);else if(a){let e=r.l2P.Add(g,r.l2P.Mul(v,b)),t=g3(b,3*gY,u,8,29);for(let n=1/t,i=n;i<1;i+=n)y.push(r.l2P.RotWith(e,g,3*gY*i))}else y.push(r.l2P.Add(g,r.l2P.Mul(v,b)),r.l2P.Add(g,r.l2P.Mul(v,.99*b)),r.l2P.Sub(g,r.l2P.Mul(v,.99*b)),r.l2P.Sub(g,r.l2P.Mul(v,b)));let S=gq,C=gX,k=gJ,P=gZ,T=Array(gQ);for(let e=0;e<gQ;e++)T[e]=new r.l2P(S[e],C[e]);let E=Array(g0);for(let e=0;e<g0;e++)E[e]=new r.l2P(k[g0-1-e],P[g0-1-e]);return T.concat(y,E,m)}(t))}class g6 extends r.bU{static type="scribble";options={zIndex:600,streamline:.32,cacheSize:500};_scribblePathCache=new Map;isActive(){return this.editor.getInstanceState().scribbles.length>0}getOverlays(){return this.editor.getInstanceState().scribbles.map(e=>({id:`scribble:${e.id}`,type:"scribble",props:{scribble:e}}))}render(e,t){let n=this.editor.getZoomLevel(),i=this.editor.getCurrentTheme().colors[this.editor.getColorMode()];for(let o of t){let t,{scribble:s}=o.props,a=s.points.length;if(!a)continue;let l=s.points[a-1],d=this._scribblePathCache.get(s.id);if(d&&d.len===a&&d.lastX===l.x&&d.lastY===l.y&&d.zoom===n&&d.size===s.size&&d.taper===s.taper&&d.state===s.state)t=d.path;else{let e,i=g5(s.points,{size:s.size/n,start:{taper:s.taper,easing:r.Z4H.linear},last:"complete"===s.state||"stopping"===s.state,simulatePressure:!1,streamline:this.options.streamline});if(i.length<4){let t=s.size/n/2,{x:r,y:i}=l;e=`M ${r-t},${i} a ${t},${t} 0 1,0 ${2*t},0 a ${t},${t} 0 1,0 ${-(2*t)},0`}else e=(0,r.JDT)(i);t=new Path2D(e),this._scribblePathCache.set(s.id,{len:a,lastX:l.x,lastY:l.y,zoom:n,size:s.size,taper:s.taper,state:s.state,path:t}),this._scribblePathCache.size>this.options.cacheSize&&this._scribblePathCache.clear()}e.fillStyle=function(e,t){switch(t){case"accent":case"selection-stroke":return e.selectionStroke;case"selection-fill":return e.selectionFill;case"white":return e.selectedContrast;case"black":default:return e.text;case"laser":return e.laser;case"muted-1":return e.brushFill}}(i,s.color),e.globalAlpha=s.opacity,e.fill(t),e.globalAlpha=1}}}let g4=null;class g8 extends r.bU{static type="collaborator_hint";options={zIndex:900,lineWidth:3,viewportPadding:5};isActive(){let e=this.editor.getViewportPageBounds(),t=this.editor.getZoomLevel();return this.editor.getVisibleCollaboratorsOnCurrentPage().some(n=>{let{cursor:i}=n;return!!i&&!(0,r.KHk)(i,e,t)})}getOverlays(){let e=[],t=this.editor.getViewportPageBounds(),n=this.editor.getZoomLevel();for(let i of this.editor.getVisibleCollaboratorsOnCurrentPage()){let{cursor:o,color:s,userId:a}=i;if(!o||(0,r.KHk)(o,t,n))continue;let l=this.options.viewportPadding/n,d=(0,r.qE8)(o.x,t.minX+l,t.maxX-l),c=(0,r.qE8)(o.y,t.minY+l,t.maxY-l),h=r.l2P.Angle(t.center,o);e.push({id:`collaborator_hint:${a}`,type:"collaborator_hint",props:{x:d,y:c,rotation:h,color:s}})}return e}render(e,t){let n=1/this.editor.getZoomLevel();for(let r of t){let{x:t,y:i,rotation:o,color:s}=r.props;e.save(),e.translate(t,i),e.scale(n,n),e.rotate(o);let a=(g4||(g4=new Path2D("M -2 -5 L 2 0 L -2 5 Z")),g4);e.lineWidth=this.options.lineWidth,e.strokeStyle="#ffffff",e.stroke(a),e.fillStyle=s,e.fill(a),e.restore()}}}class g9 extends r.bU{static type="collaborator_brush";options={zIndex:700,lineWidth:1};isActive(){return this.editor.getVisibleCollaboratorsOnCurrentPage().some(e=>null!==e.brush)}getOverlays(){let e=[];for(let t of this.editor.getVisibleCollaboratorsOnCurrentPage()){let{brush:n,color:r,userId:i}=t;n&&e.push({id:`collaborator_brush:${i}`,type:"collaborator_brush",props:{x:n.x,y:n.y,w:Math.max(1,n.w),h:Math.max(1,n.h),color:r}})}return e}render(e,t){let n=this.editor.getZoomLevel();for(let r of t){let{x:t,y:i,w:o,h:s,color:a}=r.props;e.globalAlpha=.075,e.fillStyle=a,e.fillRect(t,i,o,s),e.globalAlpha=.1,e.strokeStyle=a,e.lineWidth=this.options.lineWidth/n,e.strokeRect(t,i,o,s),e.globalAlpha=1}}renderMinimap(e,t){for(let n of t){let{x:t,y:r,w:i,h:o,color:s}=n.props;e.globalAlpha=.75,e.fillStyle=s,e.fillRect(t,r,i,o)}e.globalAlpha=1}}class g7 extends r.bU{static type="collaborator_scribble";options={zIndex:800,streamline:.32,cacheSize:500};_collabScribblePathCache=new Map;isActive(){return this.editor.getVisibleCollaboratorsOnCurrentPage().some(e=>e.scribbles.length>0)}getOverlays(){let e=[];for(let t of this.editor.getVisibleCollaboratorsOnCurrentPage()){let{scribbles:n,color:r,userId:i}=t;for(let t of n)e.push({id:`collaborator_scribble:${i}:${t.id}`,type:"collaborator_scribble",props:{scribble:t,color:r}})}return e}render(e,t){let n=this.editor.getZoomLevel();for(let i of t){let t,{scribble:o,color:s}=i.props,a=o.points.length;if(!a)continue;let l=o.points[a-1],d=i.id,c=this._collabScribblePathCache.get(d);if(c&&c.len===a&&c.lastX===l.x&&c.lastY===l.y&&c.zoom===n&&c.size===o.size&&c.taper===o.taper&&c.state===o.state)t=c.path;else{let e,i=g5(o.points,{size:o.size/n,start:{taper:o.taper,easing:r.Z4H.linear},last:"complete"===o.state||"stopping"===o.state,simulatePressure:!1,streamline:this.options.streamline});if(i.length<4){let t=o.size/n/2,{x:r,y:i}=l;e=`M ${r-t},${i} a ${t},${t} 0 1,0 ${2*t},0 a ${t},${t} 0 1,0 ${-(2*t)},0`}else e=(0,r.JDT)(i);t=new Path2D(e),this._collabScribblePathCache.set(d,{len:a,lastX:l.x,lastY:l.y,zoom:n,size:o.size,taper:o.taper,state:o.state,path:t}),this._collabScribblePathCache.size>this.options.cacheSize&&this._collabScribblePathCache.clear()}e.fillStyle=s,e.globalAlpha="laser"===o.color?.5:.1,e.fill(t),e.globalAlpha=1}}}class me extends r.bU{static type="collaborator_shape_indicator";options={zIndex:49,lineWidth:1.5,alpha:.7};isActive(){return this.editor.getVisibleCollaboratorsOnCurrentPage().some(e=>e.selectedShapeIds.length>0)}getOverlays(){let e=this.editor,t=e.getVisibleCollaboratorsOnCurrentPage().filter(e=>e.selectedShapeIds.length>0);if(0===t.length)return[];let n=new Set(e.getRenderingShapes().map(e=>e.id)),r=[];for(let i of t){let t=i.selectedShapeIds.filter(t=>n.has(t)&&!e.isShapeHidden(t));0!==t.length&&r.push({color:i.color,shapeIds:t})}return 0===r.length?[]:[{id:"collaborator_shape_indicator",type:"collaborator_shape_indicator",props:{indicators:r}}]}render(e,t){let n=t[0];if(!n)return;let i=this.editor,o=i.getZoomLevel();for(let{color:t,shapeIds:s}of(e.lineCap="round",e.lineJoin="round",e.lineWidth=this.options.lineWidth/o,e.globalAlpha=this.options.alpha,n.props.indicators))e.strokeStyle=t,(0,r.APM)(i,e,s);e.globalAlpha=1}}class mt extends r.bU{static type="shape_handle";options={zIndex:200,lineWidth:1.5};isActive(){let e=this.editor;if(e.getIsReadonly()||e.getInstanceState().isChangingStyle)return!1;let t=e.getOnlySelectedShape();return!!t&&!!e.getShapeHandles(t)&&(!!e.isInAny("select.idle","select.pointing_handle")||!!e.isIn("select.editing_shape")&&e.isShapeOfType(t,"note"))}getOverlays(){let e=this.editor,t=e.getOnlySelectedShape();if(!t)return[];let n=e.getShapeHandles(t);if(!n||e.isShapeHidden(t))return[];let i=e.getZoomLevel(),o=(e.getInstanceState().isCoarsePointer?e.options.coarseHandleRadius:e.options.handleRadius)/i*2,s=n.filter(e=>"vertex"===e.type),a=[],l=[];for(let e of n)"virtual"===e.type&&s.some(t=>r.l2P.Dist(e,t)<o)||("vertex"===e.type?a.push(e):l.push(e));return a.concat(l).map(e=>({id:`handle:${t.id}:${e.id}`,type:"shape_handle",props:{shapeId:t.id,handle:e}}))}getGeometry(e){let t=this.editor,{shapeId:n,handle:i}=e.props,o=t.getShapePageTransform(n);if(!o)return null;let s=t.getZoomLevel(),a=(t.getInstanceState().isCoarsePointer?t.options.coarseHandleRadius:t.options.handleRadius)/s,l=r.V8r.applyToPoint(o,{x:i.x,y:i.y});return new r.PUi({x:l.x-a,y:l.y-a,radius:a,isFilled:!0})}getCursor(e){return"grab"}render(e,t){if(0===t.length)return;let n=this.editor,i=t[0].props.shapeId,o=n.getShapePageTransform(i);if(!o)return;let s=n.getZoomLevel(),a=n.getInstanceState().isCoarsePointer,l=n.getCurrentTheme().colors[n.getColorMode()],d=l.selectedContrast,c=l.selectionStroke,h=l.selectionFill,u=n.overlays.getHoveredOverlayId(),p=(a?n.options.coarseHandleRadius:n.options.handleRadius)/s;e.save(),e.transform(o.a,o.b,o.c,o.d,o.e,o.f),e.strokeStyle=c,e.lineWidth=this.options.lineWidth/s;for(let n=t.length-1;n>=0;n--){let i=t[n],{handle:o}=i.props,l=i.id===u;if("create"===o.type&&!a&&!l)continue;if(l&&(e.fillStyle=h,e.beginPath(),e.arc(o.x,o.y,p,0,2*Math.PI),e.fill()),"clone"===o.type){let t=3/s,n=-Math.PI/2*(1-r.BV.indexOf(o.id));e.save(),e.translate(o.x,o.y),e.rotate(n),e.fillStyle=c,e.beginPath(),e.moveTo(0,-t),e.arc(0,0,t,-Math.PI/2,Math.PI/2),e.closePath(),e.fill(),e.restore();continue}let f=("create"===o.type&&a?3:4)/Math.max(s,.25);e.fillStyle=d,e.beginPath(),e.arc(o.x,o.y,f,0,2*Math.PI),e.fill(),e.stroke()}e.restore()}}var mn=n(83102);class mr extends r.bU{static type="shape_indicator";options={zIndex:50,lineWidth:1.5,hintedLineWidth:2.5};_instanceFlags$=(0,mn.EW)("shape indicator instance flags",()=>{let e=this.editor.getInstanceState();return{isChangingStyle:e.isChangingStyle,isHoveringCanvas:e.isHoveringCanvas,isCoarsePointer:e.isCoarsePointer}},{isEqual:(e,t)=>e.isChangingStyle===t.isChangingStyle&&e.isHoveringCanvas===t.isHoveringCanvas&&e.isCoarsePointer===t.isCoarsePointer});isActive(){return!0}getOverlays(){let e=this.editor,t=new Set(e.getRenderingShapes().map(e=>e.id)),n=[],{isChangingStyle:r,isHoveringCanvas:i,isCoarsePointer:o}=this._instanceFlags$.get(),s=e.isInAny("select.idle","select.editing_shape"),a=e.isInAny("select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","select.pointing_handle","select.pointing_resize_handle","select.pointing_rotate_handle");if(!r&&(s||a)){for(let r of e.getSelectedShapeIds())t.has(r)&&n.push(r);if(s&&i&&!o){let r=e.getHoveredShapeId();r&&t.has(r)&&!n.includes(r)&&n.push(r)}}let l=[];for(let n of e.getHintingShapeIds())t.has(n)&&l.push(n);return 0===n.length&&0===l.length?[]:[{id:"shape_indicator",type:"shape_indicator",props:{idsToDisplay:n,hintingShapeIds:l}}]}render(e,t){let n=t[0];if(!n)return;let i=this.editor,o=i.getZoomLevel(),{idsToDisplay:s,hintingShapeIds:a}=n.props;e.lineCap="round",e.lineJoin="round",e.strokeStyle=i.getCurrentTheme().colors[i.getColorMode()].selectionStroke,e.lineWidth=this.options.lineWidth/o,(0,r.APM)(i,e,s),a.length>0&&(e.lineWidth=this.options.hintedLineWidth/o,(0,r.APM)(i,e,a))}}let mi=Math.sqrt(Math.PI),mo={top_left_rotate:"nwse-rotate",top_right_rotate:"nesw-rotate",bottom_left_rotate:"swne-rotate",bottom_right_rotate:"senw-rotate"},ms={top_left:"nwse-resize",top_right:"nesw-resize",bottom_right:"nwse-resize",bottom_left:"nesw-resize",top:"ns-resize",bottom:"ns-resize",left:"ew-resize",right:"ew-resize"};class ma extends r.bU{static type="selection_foreground";options={zIndex:100,lineWidth:1.5};isActive(){return!!this.editor.getSelectionRotatedPageBounds()&&this.editor.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_canvas","select.pointing_selection","select.pointing_shape","select.pointing_resize_handle","select.pointing_rotate_handle","select.resizing","select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")}getOverlays(){let e=this._computeSelectionState();if(!e)return[];let t=[];return this._collectResizeCornerOverlays(e,t),this._collectResizeEdgeOverlays(e,t),this._collectRotateOverlays(e,t),t}getGeometry(e){let t=this._computeSelectionState();if(!t)return null;let n=r.V8r.Compose(r.V8r.Translate(t.bounds.x,t.bounds.y),r.V8r.Rotate(t.rotation),r.V8r.Translate(t.expandOffsetX,t.expandOffsetY)),{overlayType:i,handle:o}=e.props;switch(i){case"resize_handle":return this._getResizeHandleGeometry(o,t,n);case"rotate_handle":return this._getRotateHandleGeometry(o,t,n);case"mobile_rotate":return this._getMobileRotateGeometry(t,n);default:return null}}render(e,t){let n=this._computeSelectionState();if(!n)return;e.save(),e.translate(n.bounds.x,n.bounds.y),e.rotate(n.rotation),e.translate(n.expandOffsetX,n.expandOffsetY);let r=this._getThemeColors();this._renderSelectionBox(e,n,r),this._renderResizeCorners(e,n,r),this._renderCropHandles(e,n,r),this._renderMobileRotateHandle(e,n,r),this._renderTextResizeHandles(e,n,r),e.restore()}getCursor(e){let{overlayType:t,handle:n}=e.props;switch(t){case"rotate_handle":return mo[n];case"mobile_rotate":return"grab";case"resize_handle":return ms[n];default:return}}_collectResizeCornerOverlays(e,t){e.showHandles&&(t.push(this._makeOverlay("resize_handle","top_left")),e.hideAlternateCornerHandles||(t.push(this._makeOverlay("resize_handle","top_right")),t.push(this._makeOverlay("resize_handle","bottom_left"))),(!e.showOnlyOneHandle||e.showCropHandles)&&t.push(this._makeOverlay("resize_handle","bottom_right")))}_collectResizeEdgeOverlays(e,t){if(!e.showHandles)return;let{showCropHandles:n,hideAlternateCropHandles:r,hideAlternateCornerHandles:i,showOnlyOneHandle:o,isCoarsePointer:s,onlyShape:a}=e,l=n?r:i||o||s,d=s&&!!a&&"text"===a.type;l||(t.push(this._makeOverlay("resize_handle","top")),t.push(this._makeOverlay("resize_handle","bottom"))),(n?r:l&&!d)||(t.push(this._makeOverlay("resize_handle","right")),t.push(this._makeOverlay("resize_handle","left")))}_collectRotateOverlays(e,t){e.showCornerRotateHandles&&(t.push(this._makeOverlay("rotate_handle","top_left_rotate")),t.push(this._makeOverlay("rotate_handle","top_right_rotate")),t.push(this._makeOverlay("rotate_handle","bottom_left_rotate")),t.push(this._makeOverlay("rotate_handle","bottom_right_rotate"))),e.showMobileRotateHandle&&t.push(this._makeOverlay("mobile_rotate","mobile_rotate"))}_getResizeHandleGeometry(e,t,n){if("top"===e||"bottom"===e||"left"===e||"right"===e){let i=this._getEdgeLocalRect(e,t);return new r.dxv({points:this._localRectToPoints(i.x,i.y,i.w,i.h).map(e=>r.V8r.applyToPoint(n,e)),isFilled:!0})}let i=this._getCornerLocalPoint(e,t.width,t.height),o=1.5*Math.max(t.hitTargetSizeX,t.hitTargetSizeY);return new r.dxv({points:this._localRectToPoints(i.x-o,i.y-o,2*o,2*o).map(e=>r.V8r.applyToPoint(n,e)),isFilled:!0})}_getRotateHandleGeometry(e,t,n){let i=1.62*Math.max(t.hitTargetSizeX,t.hitTargetSizeY),o=this._getRotateHandleLocalCenter(e,t.width,t.height,i);return new r.krb({x:o.x-i,y:o.y-i,width:2*i,height:2*i,isFilled:!0}).transform(n)}_getMobileRotateGeometry(e,t){let n=Math.max(14*(1/e.zoom),20/Math.max(1,e.zoom)),{cx:i,cy:o}=this._getMobileRotateCenter(e);return new r.dxv({points:this._localRectToPoints(i-n,o-n,2*n,2*n).map(e=>r.V8r.applyToPoint(t,e)),isFilled:!0})}_renderSelectionBox(e,t,n){t.shouldDisplayBox&&(e.strokeStyle=n.strokeColor,e.lineWidth=this.options.lineWidth/t.zoom,e.strokeRect(0,0,t.width,t.height))}_renderResizeCorners(e,t,n){if(!t.showResizeHandles)return;let{handleSize:r,width:i,height:o,hideAlternateCornerHandles:s,showOnlyOneHandle:a,zoom:l}=t;e.fillStyle=n.bgColor,e.strokeStyle=n.strokeColor,e.lineWidth=this.options.lineWidth/l;let d=(t,n,i)=>{i||(e.fillRect(t-r/2,n-r/2,r,r),e.strokeRect(t-r/2,n-r/2,r,r))};d(0,0,!1),d(i,0,s),d(i,o,a),d(0,o,s)}_renderCropHandles(e,t,n){if(!t.showCropHandles)return;let{handleSize:r,width:i,height:o,hideAlternateCropHandles:s}=t,a=r/3,l=a/2;e.beginPath(),e.strokeStyle=n.strokeColor,e.lineWidth=a,e.lineCap="butt",e.lineJoin="miter",e.moveTo(-l,r),e.lineTo(-l,-l),e.lineTo(r,-l),e.moveTo(i+l,o-r),e.lineTo(i+l,o+l),e.lineTo(i-r,o+l),s||(e.moveTo(i-r,-l),e.lineTo(i+l,-l),e.lineTo(i+l,r),e.moveTo(r,o+l),e.lineTo(-l,o+l),e.lineTo(-l,o-r),e.moveTo(i/2-r,-l),e.lineTo(i/2+r,-l),e.moveTo(i+l,o/2-r),e.lineTo(i+l,o/2+r),e.moveTo(i/2-r,o+l),e.lineTo(i/2+r,o+l),e.moveTo(-l,o/2-r),e.lineTo(-l,o/2+r)),e.stroke()}_renderMobileRotateHandle(e,t,n){if(!t.showMobileRotateHandle)return;let{cx:r,cy:i}=this._getMobileRotateCenter(t),o=t.handleSize/mi;e.fillStyle=n.bgColor,e.strokeStyle=n.strokeColor,e.lineWidth=this.options.lineWidth/t.zoom,e.beginPath(),e.arc(r,i,o,0,2*Math.PI),e.fill(),e.stroke()}_renderTextResizeHandles(e,t,n){let{shouldDisplayControls:r,isCoarsePointer:i,onlyShape:o,zoom:s,width:a,height:l,handleSize:d,hitTargetSizeY:c}=t;if(!r||!i||!o||"text"!==o.type)return;let h=Math.min(24/s,l-3*c);if(h*s<4)return;let u=d/2,p=d/4;e.fillStyle=n.strokeColor,e.beginPath(),e.roundRect(0-u/2,l/2-h/2,u,h,p),e.fill(),e.beginPath(),e.roundRect(a-u/2,l/2-h/2,u,h,p),e.fill()}_computeSelectionState(){let e=this.editor,t=e.getSelectionRotatedPageBounds();if(!t)return null;let n=e.getOnlySelectedShape();if(n&&e.isShapeHidden(n))return null;let i=n?e.getShapeUtil(n):null,o=!!(n&&e.isShapeOrAncestorLocked(n)),s=n&&i?i.expandSelectionOutlinePx(n):0,a=s instanceof r.azJ?t.clone().expand(s).zeroFix():t.clone().expandBy(s).zeroFix(),l=e.getInstanceState(),d=l.isCoarsePointer,c=l.isChangingStyle,h=e.getIsReadonly(),u=e.getZoomLevel(),p=e.getSelectionRotation(),f=a.width,g=a.height,m=8/u,y=f<2*m,b=g<2*m,x=f<4*m,w=g<4*m,v=d?1.75:1,S=6/u*v,C=a.x-t.x,k=a.y-t.y,P=e.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.pointing_resize_handle","select.pointing_rotate_handle","select.crop.idle")&&!c&&!h,T=e.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!h,E=!n||!i||i.canResize(n)&&!i.hideResizeHandles(n),I=!!n&&!!i&&i.hideRotateHandle(n),_=!!n&&!!i&&i.hideSelectionBoundsFg(n),M=P&&!o&&!T&&E,A=!_&&!c,j=A&&e.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_canvas","select.pointing_selection","select.pointing_shape","select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle","select.pointing_resize_handle","select.pointing_rotate_handle")||A&&e.isIn("select.resizing")&&!!(n&&e.isShapeOfType(n,"text"));return{bounds:t,onlyShape:n,isCoarsePointer:d,zoom:u,rotation:p,width:f,height:g,handleSize:m,hitTargetSize:S,hitTargetSizeX:.75*v*(x?S/2:S),hitTargetSizeY:.75*v*(w?S/2:S),expandOffsetX:C,expandOffsetY:k,isSmallX:x,shouldDisplayControls:P,shouldDisplayBox:j,showCropHandles:T,showResizeHandles:M,showCornerRotateHandles:P&&!o&&!d&&!(y||b)&&!I,showMobileRotateHandle:P&&!o&&d&&(!x||!w)&&!I,showHandles:M||T,hideAlternateCornerHandles:y||b,hideAlternateCropHandles:f<5*m||g<5*m,showOnlyOneHandle:y&&b}}_getMobileRotateCenter(e){let{width:t,height:n,hitTargetSize:i,isSmallX:o,onlyShape:s,rotation:a}=e,l=this.editor,d=!!s&&(l.isShapeOfType(s,"image")||l.isShapeOfType(s,"video")),c=a/r.sKG>1.6&&a/r.sKG<2.4;return{cx:o?-(1.5*i):t/2,cy:o?n/2:d&&!c?n+1.5*i:-(1.5*i)}}_getThemeColors(){let e=this.editor,t=e.getCurrentTheme().colors[e.getColorMode()];return{strokeColor:t.selectionStroke,bgColor:t.background}}_makeOverlay(e,t){return{id:`selection_fg:${t}`,type:"selection_foreground",props:{overlayType:e,handle:t}}}_getEdgeLocalRect(e,t){let{width:n,height:r,hitTargetSizeX:i,hitTargetSizeY:o}=t;switch(e){case"top":return{x:0,y:-o,w:n,h:2*o};case"right":return{x:n-i,y:0,w:2*i,h:r};case"bottom":return{x:0,y:r-o,w:n,h:2*o};case"left":return{x:-i,y:0,w:2*i,h:r}}}_getRotateHandleLocalCenter(e,t,n,i){switch(e){case"top_left_rotate":return new r.l2P(-i,-i);case"top_right_rotate":return new r.l2P(t+i,-i);case"bottom_left_rotate":return new r.l2P(-i,n+i);case"bottom_right_rotate":return new r.l2P(t+i,n+i);default:return new r.l2P(0,0)}}_getCornerLocalPoint(e,t,n){switch(e){case"top_left":return new r.l2P(0,0);case"top_right":return new r.l2P(t,0);case"bottom_right":return new r.l2P(t,n);case"bottom_left":return new r.l2P(0,n)}}_localRectToPoints(e,t,n,i){return[new r.l2P(e,t),new r.l2P(e+n,t),new r.l2P(e+n,t+i),new r.l2P(e,t+i)]}}class ml extends r.bU{static type="snap_indicator";options={zIndex:500,lineWidth:1};isActive(){return this.editor.snaps.getIndicators().length>0}getOverlays(){return this.editor.snaps.getIndicators().map(e=>({id:`snap:${e.id}`,type:"snap_indicator",props:{line:e}}))}render(e,t){let n=this.editor.getZoomLevel(),r=this.editor.getCurrentTheme().colors[this.editor.getColorMode()].snap;for(let i of t){let{line:t}=i.props;"points"===t.type?this._renderPoints(e,t,n,r):"gaps"===t.type&&this._renderGaps(e,t,n,r)}}_renderPoints(e,t,n,r){let i,o,s,a,{points:l}=t;if(0===l.length)return;let d=2.5/n,c=1/0,h=-1/0,u=1/0,p=-1/0;for(let e of l)e.x<c&&(c=e.x),e.x>h&&(h=e.x),e.y<u&&(u=e.y),e.y>p&&(p=e.y);let f=!1;for(let e of l)if(e.x===c&&e.y===u){f=!0;break}for(let t of(f?(i=c,o=u,s=h,a=p):(i=c,o=p,s=h,a=u),e.strokeStyle=r,e.lineWidth=this.options.lineWidth/n,e.beginPath(),e.moveTo(i,o),e.lineTo(s,a),e.stroke(),e.beginPath(),l))e.moveTo(t.x-d,t.y-d),e.lineTo(t.x+d,t.y+d),e.moveTo(t.x-d,t.y+d),e.lineTo(t.x+d,t.y-d);e.stroke()}_renderGaps(e,t,n,i){let{gaps:o,direction:s}=t;if(0===o.length)return;let a=3.5/n,l=2*a,d="horizontal"===s,c=[-1/0,1/0],h=null;for(let e of o){if(h=(0,r.$Cz)(c[0],c[1],d?e.startEdge[0].y:e.startEdge[0].x,d?e.startEdge[1].y:e.startEdge[1].x))c=h,(h=(0,r.$Cz)(c[0],c[1],d?e.endEdge[0].y:e.endEdge[0].x,d?e.endEdge[1].y:e.endEdge[1].x))&&(c=h)}let u=(c[0]+c[1])/2;for(let{startEdge:t,endEdge:r}of(e.strokeStyle=i,e.lineWidth=this.options.lineWidth/n,e.beginPath(),o))if(d){e.moveTo(t[0].x,u-l),e.lineTo(t[1].x,u+l),e.moveTo(r[0].x,u-l),e.lineTo(r[1].x,u+l),e.moveTo(t[0].x,u),e.lineTo(r[0].x,u);let n=(t[0].x+r[0].x)/2;e.moveTo(n,u-a),e.lineTo(n,u+a)}else{e.moveTo(u-l,t[0].y),e.lineTo(u+l,t[1].y),e.moveTo(u-l,r[0].y),e.lineTo(u+l,r[1].y),e.moveTo(u,t[0].y),e.lineTo(u,r[0].y);let n=(t[0].y+r[0].y)/2;e.moveTo(u-a,n),e.lineTo(u+a,n)}e.stroke()}}let md=[fg,fm,ff],mc=[f8],mh=[f4,gd,gc,g9,g8,g7,me,g6,ma,mt,mr,ml,gh];class mu extends r.YM5{static id="idle";isPrecise=!1;isPreciseTimerId=null;preciseTargetId=null;onPointerMove(){this.update()}onPointerDown(e){this.parent.transition("pointing",{...e,isPrecise:this.isPrecise})}onEnter(){this.editor.setCursor({type:"cross",rotation:0}),this.update()}onCancel(){this.editor.setCurrentTool("select")}onExit(){gi(this.editor),null!==this.isPreciseTimerId&&clearTimeout(this.isPreciseTimerId)}onKeyDown(){this.update()}onKeyUp(e){if(this.update(),"Enter"===e.key){let e=this.editor.getOnlySelectedShape();this.editor.canEditShape(e)&&y(this.editor,e,{selectAll:!0})}}update(){let e=this.editor.getShapeUtil("arrow"),t=go({editor:this.editor,pointInPageSpace:this.editor.inputs.getCurrentPagePoint(),arrow:void 0,isPrecise:this.isPrecise,currentBinding:void 0,oppositeBinding:void 0});t&&t.target.id!==this.preciseTargetId?(null!==this.isPreciseTimerId&&clearTimeout(this.isPreciseTimerId),this.preciseTargetId=t.target.id,this.isPreciseTimerId=this.editor.timers.setTimeout(()=>{this.isPrecise=!0,this.update()},e.options.hoverPreciseTimeout)):!t&&this.preciseTargetId&&(this.isPrecise=!1,this.preciseTargetId=null,null!==this.isPreciseTimerId&&clearTimeout(this.isPreciseTimerId))}}class mp extends r.YM5{static id="pointing";shape;isPrecise=!1;isPreciseTimerId=null;markId="";onEnter(e){(this.markId="",this.isPrecise=!!e.isPrecise,go({editor:this.editor,pointInPageSpace:this.editor.inputs.getCurrentPagePoint(),arrow:void 0,isPrecise:this.isPrecise,currentBinding:void 0,oppositeBinding:void 0})||(this.createArrowShape(),this.shape))?this.startPreciseTimeout():this.cancel()}onExit(){this.shape=void 0,gi(this.editor),this.clearPreciseTimeout()}onPointerMove(){if(this.editor.inputs.getIsDragging()){if(this.shape||this.createArrowShape(),!this.shape)return void this.cancel();this.updateArrowShapeEndHandle(),this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,handle:{id:"end",type:"vertex",index:"a3",x:0,y:0},isCreating:!0,creatingMarkId:this.markId||void 0,onInteractionEnd:"arrow"})}}onPointerUp(){this.cancel()}onLongPress(){this.editor.getInstanceState().isCoarsePointer&&this.cancel()}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.shape&&this.editor.bailToMark(this.markId),this.parent.transition("idle")}createArrowShape(){let e=this.editor.inputs.getOriginPagePoint(),t=(0,r.n6Y)();this.markId=this.editor.markHistoryStoppingPoint(`creating_arrow:${t}`);let n=(0,r.Y8F)(e,this.editor);this.editor.createShape({id:t,type:"arrow",x:n.x,y:n.y,props:{scale:this.editor.getResizeScaleFactor()}});let i=this.editor.getShape(t);if(!i)return;let o=this.editor.getShapeHandles(i);if(!o)throw Error("expected handles for arrow");let s=this.editor.getShapeUtil("arrow"),a=this.shape,l=o.find(e=>"start"===e.id),d=s.onHandleDrag?.(i,{handle:{...l,x:0,y:0},isPrecise:!0,isCreatingShape:!0,initial:a});d&&this.editor.updateShapes([d]),this.shape=this.editor.getShape(t),this.editor.select(t)}updateArrowShapeEndHandle(){let e=this.shape;if(!e)throw Error("expected shape");let t=this.editor.getShapeHandles(e);if(!t)throw Error("expected handles for arrow");{let n=this.editor.getShapeUtil("arrow"),r=this.shape,i=t.find(e=>"start"===e.id),o=n.onHandleDrag?.(e,{handle:{...i,x:0,y:0},isPrecise:this.isPrecise,isCreatingShape:!0,initial:r});o&&this.editor.updateShapes([o])}{let n=this.editor.getShapeUtil("arrow"),r=this.shape,i=this.editor.getPointInShapeSpace(e,this.editor.inputs.getCurrentPagePoint()),o=t.find(e=>"end"===e.id),s=n.onHandleDrag?.(this.editor.getShape(e),{handle:{...o,x:i.x,y:i.y},isPrecise:this.isPrecise,isCreatingShape:!0,initial:r});s&&this.editor.updateShapes([s])}this.shape=this.editor.getShape(e.id)}startPreciseTimeout(){let e=this.editor.getShapeUtil("arrow");this.isPreciseTimerId=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.isPrecise=!0)},e.options.pointingPreciseTimeout)}clearPreciseTimeout(){null!==this.isPreciseTimerId&&clearTimeout(this.isPreciseTimerId)}}class mf extends r.YM5{static id="arrow";static initial="idle";static children(){return[mu,mp]}shapeType="arrow"}class mg extends r.YM5{static id="drawing";static trackPerformance=!0;info={};initialShape;shapeType="highlight"===this.parent.id?"highlight":"draw";util=this.editor.getShapeUtil(this.shapeType);isPen=!1;isPenOrStylus=!1;segmentDim=void 0;segmentMode="free";didJustShiftClickToExtendPreviousShapeLine=!1;pagePointWhereCurrentSegmentChanged={};pagePointWhereNextSegmentChanged=null;lastRecordedPoint={};mergeNextPoint=!1;currentLineLength=0;zoomOnEnter=1;currentSegmentPoints=[];markId=null;onEnter(e){this.markId=null,this.info=e,this.lastRecordedPoint=this.editor.inputs.getCurrentPagePoint().clone(),this.zoomOnEnter=this.editor.getZoomLevel(),this.startShape()}onPointerMove(){let{inputs:e}=this.editor,t=e.getIsPen();if(this.isPen&&!t&&this.markId){this.editor.bailToMark(this.markId),this.startShape();return}if(this.isPenOrStylus){let t=e.getCurrentPagePoint();r.l2P.Dist(t,this.lastRecordedPoint)>=1/this.zoomOnEnter?(this.lastRecordedPoint=t.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0}else this.mergeNextPoint=!1;this.updateDrawingShape()}onKeyDown(e){if("Shift"===e.key)switch(this.segmentMode){case"free":this.segmentMode="starting_straight",this.pagePointWhereNextSegmentChanged=this.editor.inputs.getCurrentPagePoint().clone();break;case"starting_free":this.segmentMode="starting_straight"}this.updateDrawingShape()}onKeyUp(e){if("Shift"===e.key)switch(this.editor.snaps.clearIndicators(),this.segmentMode){case"straight":this.segmentMode="starting_free",this.pagePointWhereNextSegmentChanged=this.editor.inputs.getCurrentPagePoint().clone();break;case"starting_straight":this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free"}this.updateDrawingShape()}onExit(){this.editor.snaps.clearIndicators(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.getCurrentPagePoint().clone()}canClose(){return"highlight"!==this.shapeType}getIsClosed(e,t,n,i){if(!this.canClose())return!1;void 0===i&&(i=this.editor.getCurrentTheme().strokeWidth*G[t]);let o=r.K6A.decodeFirstPoint(e[0].path,e[0].dim),s=e[e.length-1],a=r.K6A.decodeLastPoint(s.path,s.dim),l=this.editor.user.getIsDynamicResizeMode()?(i+2)*n:6+2*Math.sqrt(.8*i)+100/(1+Math.pow(this.zoomOnEnter/.18,3));return null!==o&&null!==a&&o!==a&&this.currentLineLength>4*i*n&&r.l2P.DistMin(o,a,l)}makeSegment(e,t){let n=r.K6A.encodePoints(t,this.segmentDim);return this.segmentDim===r.sdu?{type:e,path:n,dim:r.sdu}:{type:e,path:n}}startShape(){let e=this.editor.inputs,t=e.getOriginPagePoint(),n=e.getIsPen();this.markId=this.editor.markHistoryStoppingPoint("draw start");let{z:i=.5}=this.info.point;this.isPen=n,this.isPenOrStylus=n&&0!==i||i>0&&i<.5||i>.5&&i<1,this.segmentDim=this.isPenOrStylus?void 0:r.sdu;let o=this.isPenOrStylus?1.25*i:.5;if(this.segmentMode=this.editor.inputs.getShiftKey()?"straight":"free",this.didJustShiftClickToExtendPreviousShapeLine=!1,this.lastRecordedPoint=t.clone(),this.initialShape){let e=this.editor.getShape(this.initialShape.id);if(e&&"straight"===this.segmentMode){this.didJustShiftClickToExtendPreviousShapeLine=!0;let n=(0,r.HVh)(e.props.segments);if(!n)throw Error("Expected a previous segment!");let i=r.K6A.decodeLastPoint(n.path,n.dim);if(!i)throw Error("Expected a previous point!");let{x:s,y:a}=this.editor.getPointInShapeSpace(e,t).toFixed(),l=this.makeSegment(this.segmentMode,[{x:i.x,y:i.y,z:+o.toFixed(2)},{x:s,y:a,z:+o.toFixed(2)}]),d=r.V8r.applyToPoint(this.editor.getShapePageTransform(e.id),i);this.pagePointWhereCurrentSegmentChanged=d,this.pagePointWhereNextSegmentChanged=null;let c=[...e.props.segments,l],h=fb(this.util,e).strokeWidth;this.currentLineLength<4*h&&(this.currentLineLength=this.getLineLength(c));let u={id:e.id,type:this.shapeType,props:{segments:c}};this.canClose()&&(u.props.isClosed=this.getIsClosed(c,e.props.size,e.props.scale)),this.editor.updateShapes([u]);return}}this.pagePointWhereCurrentSegmentChanged=t.clone();let s=(0,r.n6Y)(),a=new r.l2P(0,0,+o.toFixed(2));(this.currentSegmentPoints=[a],this.editor.createShape({id:s,type:this.shapeType,x:t.x,y:t.y,props:{isPen:this.isPenOrStylus,scale:this.editor.getResizeScaleFactor(),segments:[this.makeSegment(this.segmentMode,[a])]}}),this.editor.getShape(s))?(this.currentLineLength=0,this.initialShape=this.editor.getShape(s)):this.cancel()}updateDrawingShape(){let{initialShape:e}=this,{inputs:t}=this.editor;if(!e)return;let{id:n,props:{size:i,scale:o}}=e,s=this.editor.getShape(n);if(!s)return;let{segments:a}=s.props,l=t.getCurrentPagePoint(),{x:d,y:c,z:h}=this.editor.getPointInShapeSpace(s,l).toFixed(),u={x:d,y:c,z:this.isPenOrStylus?+(1.25*l.z).toFixed(2):.5};switch(this.segmentMode){case"starting_straight":{let{pagePointWhereNextSegmentChanged:e}=this;if(null===e)throw Error("We should have a point where the segment changed");if(r.l2P.Dist2(e,t.getCurrentPagePoint())>this.editor.options.dragDistanceSquared){let e;this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";let t=(0,r.HVh)(a);if(!t)throw Error("Expected a previous segment!");let l=r.K6A.decodeLastPoint(t.path,t.dim);if(!l)throw Error("Expected a previous last point!");let d=this.editor.getPointInShapeSpace(s,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if("straight"===t.type){this.currentLineLength+=r.l2P.Dist(l,d),e=this.makeSegment("straight",[l,d]);let t=this.editor.getShapePageTransform(s);this.pagePointWhereCurrentSegmentChanged=r.V8r.applyToPoint(t,l)}else e=this.makeSegment("straight",[d,u]);let c={id:n,type:this.shapeType,props:{segments:[...a,e]}};this.canClose()&&(c.props.isClosed=this.getIsClosed(a,i,o)),this.editor.updateShapes([c])}break}case"starting_free":{let{pagePointWhereNextSegmentChanged:e}=this;if(null===e)throw Error("We should have a point where the segment changed");if(r.l2P.Dist2(e,t.getCurrentPagePoint())>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";let e=a.slice(),t=e[e.length-1],l=r.K6A.decodeLastPoint(t.path,t.dim);if(!l)throw Error("No previous point!");let d=r.l2P.PointsBetween(l,u,6).map(e=>new r.l2P((0,r.Mg8)(e.x),(0,r.Mg8)(e.y),(0,r.Mg8)(e.z)));this.currentSegmentPoints=d;let c=[...e,this.makeSegment("free",d)],h=fb(this.util,s).strokeWidth;this.currentLineLength<4*h&&(this.currentLineLength=this.getLineLength(c));let p={id:n,type:this.shapeType,props:{segments:c}};this.canClose()&&(p.props.isClosed=this.getIsClosed(c,i,o)),this.editor.updateShapes([p])}break}case"straight":{let e,t,l=a.slice(),d=l[l.length-1],{pagePointWhereCurrentSegmentChanged:c}=this,h=this.editor.inputs,u=h.getCtrlKey(),p=h.getCurrentPagePoint();if(!c)throw Error("We should have a point where the segment changed");let f=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.getIsDragging()&&(f=!u,this.didJustShiftClickToExtendPreviousShapeLine=!1):f=!u;let g=this.editor.getPointInShapeSpace(s,p).toFixed().toJson(),m=!1;if((this.editor.user.getIsSnapMode()?!u:u)&&l.length>2){let e,n=8/this.zoomOnEnter;for(let i=0,o=a.length-2;i<o;i++){let o=a[i];if(!o)break;if("free"===o.type)continue;let s=r.K6A.decodeFirstPoint(o.path,o.dim),l=r.K6A.decodeLastPoint(o.path,o.dim);if(!(s&&l))continue;let d=r.l2P.NearestPointOnLineSegment(s,l,g);if(r.l2P.DistMin(d,g,n)){e=d.toFixed().toJson(),n=r.l2P.Dist(d,g),t=o;break}}e&&(m=!0,g=e)}if(m&&t){let e=this.editor.getShapePageTransform(s),n=r.K6A.decodeFirstPoint(t.path,t.dim),i=r.K6A.decodeLastPoint(t.path,t.dim);if(!n||!i)throw Error("Expected a last point!");let o=r.V8r.applyToPoint(e,n),a=r.V8r.applyToPoint(e,i),l=r.V8r.applyToPoint(e,g);this.editor.snaps.setIndicators([{id:(0,r.NF7)(),type:"points",points:[o,l,a]}])}else{if(this.editor.snaps.clearIndicators(),f){let t=r.l2P.Angle(c,p),n=(0,r.cL9)(t,24);e=r.l2P.RotWith(p,c,n-t)}else e=p.clone();g=this.editor.getPointInShapeSpace(s,e).toFixed().toJson()}this.currentLineLength+=l.length&&r.K6A.decodeFirstPoint(d.path,d.dim)?r.l2P.Dist(r.K6A.decodeFirstPoint(d.path,d.dim),r.l2P.From(g)):0,l[l.length-1]={...d,type:"straight",path:r.K6A.encodePoints([r.K6A.decodeFirstPoint(d.path,d.dim),r.l2P.From(g)],d.dim)};let y={id:n,type:this.shapeType,props:{segments:l}};this.canClose()&&(y.props.isClosed=this.getIsClosed(a,i,o)),this.editor.updateShapes([y]);break}case"free":{let e=this.currentSegmentPoints;if(e.length&&this.mergeNextPoint){let t=e[e.length-1];t.x=u.x,t.y=u.y,t.z=t.z?Math.max(t.z,u.z):u.z}else this.currentLineLength+=e.length?r.l2P.Dist(e[e.length-1],u):0,e.push(new r.l2P(u.x,u.y,u.z));let l=a.slice(),d=l[l.length-1];l[l.length-1]={...d,path:r.K6A.encodePoints(e,d.dim)};let c=fb(this.util,s).strokeWidth;this.currentLineLength<4*c&&(this.currentLineLength=this.getLineLength(l));let p={id:n,type:this.shapeType,props:{segments:l}};if(this.canClose()&&(p.props.isClosed=this.getIsClosed(l,i,o)),this.editor.updateShapes([p]),e.length>this.util.options.maxPointsPerShape){this.editor.updateShapes([{id:n,type:this.shapeType,props:{isComplete:!0}}]);let e=(0,r.n6Y)(),i=this.editor.getShape(n).props;if(!this.editor.canCreateShapes([e]))return this.cancel();let o=t.getCurrentPagePoint(),s=new r.l2P(0,0,this.isPenOrStylus?+(1.25*h).toFixed():.5);this.currentSegmentPoints=[s],this.editor.createShape({id:e,type:this.shapeType,x:(0,r.Mg8)(o.x),y:(0,r.Mg8)(o.y),props:{isPen:this.isPenOrStylus,scale:i.scale,segments:[this.makeSegment("free",[s])]}});let a=this.editor.getShape(e);if(!a)return this.cancel();this.initialShape=(0,r.pN9)(a),this.mergeNextPoint=!1,this.lastRecordedPoint=o.clone(),this.currentLineLength=0}}}}getLineLength(e){let t=0;for(let n=0;n<e.length;n++){let i=r.K6A.decodePoints(e[n].path,e[n].dim);for(let e=0;e<i.length-1;e++)t+=r.l2P.Dist2(i[e],i[e+1])}return Math.sqrt(t)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.editor.inputs.getIsDragging()||(this.markId&&this.editor.bailToMark(this.markId),this.cancel())}complete(){let{initialShape:e}=this;e&&(this.editor.updateShapes([{id:e.id,type:e.type,props:{isComplete:!0}}]),this.parent.transition("idle"))}cancel(){this.parent.transition("idle",this.info)}}class mm extends r.YM5{static id="idle";onPointerDown(e){e.accelKey&&!e.shiftKey?this.editor.setCurrentTool("eraser.pointing",{...e,onInteractionEnd:this.parent.id}):this.parent.transition("drawing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}}class my extends r.YM5{static id="draw";static initial="idle";static isLockable=!1;static useCoalescedEvents=!0;static children(){return[mm,mg]}shapeType="draw";onExit(){this.children.drawing.initialShape=void 0}}class mb extends r.QVi{static id="frame";static initial="idle";shapeType="frame";onCreate(e){e&&(this.editor.reparentShapes(mx(this.editor,e),e.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle"))}}function mx(e,t){let n=e.getShapePageBounds(t);if(!n)return[];let r=[],i=e.getShapeAncestors(t).map(e=>e.id);return e.getSortedChildIdsForParent(t.parentId).map(o=>{var s,a,l;let d=e.getShape(o);if(!d||d.id===t.id||d.isLocked)return;let c=e.getShapePageBounds(d);c&&n.contains(c)&&(s=d,a=i,l=t,!a.includes(s.id)&&s.parentId===l.parentId)&&r.push(d.id)}),r}class mw extends r.YM5{static id="idle";onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onKeyUp(e){let{editor:t}=this;if("Enter"===e.key){let e=t.getOnlySelectedShape();t.canEditShape(e)&&y(t,e,{selectAll:!0})}}onCancel(){this.editor.setCurrentTool("select")}}class mv extends r.YM5{static id="pointing";onPointerUp(){this.complete()}onLongPress(){this.editor.getInstanceState().isCoarsePointer&&this.cancel()}onPointerMove(e){if(this.editor.inputs.getIsDragging()){let t=this.editor.inputs.getOriginPagePoint(),n=(0,r.n6Y)(),i=this.editor.markHistoryStoppingPoint(`creating_geo:${n}`),o=(0,r.Y8F)(t,this.editor);if(this.editor.createShapes([{id:n,type:"geo",x:o.x,y:o.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(r.tg8),scale:this.editor.getResizeScaleFactor()}}]).select(n),!this.editor.getShape(n))return void this.cancel();this.editor.setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:i,creationCursorOffset:{x:1,y:1},onInteractionEnd:"geo"})}}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){let e=this.editor.inputs.getOriginPagePoint(),t=(0,r.n6Y)();this.editor.markHistoryStoppingPoint(`creating_geo:${t}`);let n=this.editor.getResizeScaleFactor(),i=hO(this.editor.getStyleForNextShape(r.tg8),this.editor.getShapeUtil("geo").options.customGeoTypes),o=i?.defaultSize??{w:200,h:200};this.editor.createShapes([{id:t,type:"geo",x:e.x,y:e.y,props:{geo:this.editor.getStyleForNextShape(r.tg8),scale:n,...o}}]);let s=this.editor.getShape(t);if(!s)return void this.cancel();let{w:a,h:l}=s.props,d=new r.l2P(a/2,l/2).mul(n),c=this.editor.getShapeParentTransform(s);c&&d.rot(-c.rotation());let h=(0,r.Y8F)(new r.l2P(s.x-d.x,s.y-d.y),this.editor);this.editor.select(t),this.editor.updateShape({id:s.id,type:"geo",x:h.x,y:h.y,props:{geo:this.editor.getStyleForNextShape(r.tg8),w:a*n,h:l*n}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}}class mS extends r.YM5{static id="geo";static initial="idle";static children(){return[mw,mv]}shapeType="geo"}class mC extends r.YM5{static id="highlight";static initial="idle";static useCoalescedEvents=!0;static children(){return[mm,mg]}static isLockable=!1;shapeType="highlight";onExit(){this.children.drawing.initialShape=void 0}}class mk extends r.YM5{static id="idle";shapeId="";onEnter(e){this.shapeId=e.shapeId,this.editor.setCursor({type:"cross",rotation:0})}onPointerDown(){this.parent.transition("pointing",{shapeId:this.shapeId})}onCancel(){this.editor.setCurrentTool("select")}}class mP extends r.YM5{static id="pointing";shape={};markId;onEnter(e){let{inputs:t}=this.editor,n=t.getCurrentPagePoint();this.markId=void 0;let i=e.shapeId&&this.editor.getShape(e.shapeId);if(i&&t.getShiftKey()){this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${i.id}`),this.shape=i;let e=this.editor.getShapeHandles(this.shape);if(!e)return;let t=e.filter(e=>"vertex"===e.type).sort(r.Ky),o=t[t.length-1],s=t[t.length-2],a=r.V8r.applyToPoint(this.editor.getShapeParentTransform(this.shape),new r.l2P(this.shape.x,this.shape.y)),l=r.l2P.Sub(n,a).addXY(.1,.1),d=(0,r.Y8F)(l,this.editor),c=(0,r.pN9)(this.shape.props.points),h=2/this.editor.getZoomLevel();if(r.l2P.DistMin(o,s,h)||r.l2P.DistMin(d,o,h))c[o.id]={id:o.id,index:o.index,x:d.x,y:d.y};else{let e=(0,r.AQy)(o.index);c[e]={id:e,index:e,x:d.x,y:d.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:c}}])}else{let e=(0,r.n6Y)();this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${e}`);let t=(0,r.Y8F)(n,this.editor);if(this.editor.createShapes([{id:e,type:"line",x:t.x,y:t.y,props:{scale:this.editor.getResizeScaleFactor()}}]),!this.editor.getShape(e))return void this.cancel();this.editor.select(e),this.shape=this.editor.getShape(e)}}onPointerMove(){if(this.shape&&this.editor.inputs.getIsDragging()){let e=this.editor.getShapeHandles(this.shape);if(!e)throw this.markId&&this.editor.bailToMark(this.markId),Error("No handles found");let t=(0,r.HVh)(e);this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,isCreating:!0,creatingMarkId:this.markId,handle:{...t,x:t.x-.1,y:t.y-.1},onInteractionEnd:"line"})}}onPointerUp(){this.complete()}onLongPress(){this.editor.getInstanceState().isCoarsePointer&&this.cancel()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle"),this.markId&&this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators()}complete(){this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}cancel(){this.markId&&this.editor.bailToMark(this.markId),this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}}class mT extends r.YM5{static id="line";static initial="idle";static children(){return[mk,mP]}shapeType="line"}class mE extends r.YM5{static id="idle";onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}}function mI(e,t){let{pagePoint:n,pageRotation:i,growY:o,extraHeight:s,scale:a,noteWidth:l,noteHeight:d}=t;return Object.fromEntries((function(e,t,n,i){if(1===t)return[[["a1"],new r.l2P(.5*n,-.5*i-e.options.adjacentShapeMargin)],[["a2"],new r.l2P(1.5*n+e.options.adjacentShapeMargin,.5*i)],[["a3"],new r.l2P(.5*n,1.5*i+e.options.adjacentShapeMargin)],[["a4"],new r.l2P(-.5*n-e.options.adjacentShapeMargin,.5*i)]];let o=n*t,s=i*t,a=e.options.adjacentShapeMargin*t;return[[["a1"],new r.l2P(.5*o,-.5*s-a)],[["a2"],new r.l2P(1.5*o+a,.5*s)],[["a3"],new r.l2P(.5*o,1.5*s+a)],[["a4"],new r.l2P(-.5*o-a,.5*s)]]})(e,a,l,d).map(([e,t],r)=>{let a=t.clone();return 0===r&&s?a.y-=s:2===r&&o&&(a.y+=o),[e,a.rot(i).add(n)]}))}function m_(e,t){let n,{rotation:i,scale:o,extraHeight:s,noteWidth:a,noteHeight:l}=t,d=new Set(e.getSelectedShapeIds()),c=(Math.max(a,l)+e.options.adjacentShapeMargin+s)**2,h=new Map,u=[];for(let t of e.getCurrentPageShapes()){if(!e.isShapeOfType(t,"note")||o!==t.props.scale||d.has(t.id))continue;let n=e.getShapePageTransform(t.id);i===n.rotation()&&(h.set(t,e.getShapePageBounds(t).center),u.push(...Object.values(mI(e,{pagePoint:n.point(),pageRotation:i,growY:t.props.growY,extraHeight:s,scale:o,noteWidth:a,noteHeight:l}))))}let p=u.length;for(let[t,i]of h)for(let o=0;o<p;o++)(n=u[o])&&!(r.l2P.Dist2(i,n)>c)&&e.isPointInShape(t,n)&&(u[o]=void 0);return(0,r.oE7)(u)}function mM(e,t){let n,{shape:i,center:o,pageRotation:s,noteWidth:a,noteHeight:l,forceNew:d=!1}=t,c=e.getCurrentPageShapesSorted(),h=(Math.max(a,l)+e.options.adjacentShapeMargin**2)**i.props.scale;for(let t=c.length-1;t>=0;t--){let s=c[t];if("note"===s.type&&s.id!==i.id){let t=e.getShapePageBounds(s);if(t&&r.l2P.Dist2(t.center,o)<h&&e.isPointInShape(s,o)){n=s;break}}}if(e.complete(),!n||d){e.markHistoryStoppingPoint("creating note shape");let t=(0,r.n6Y)();e.createShape({id:t,type:"note",x:o.x,y:o.y,rotation:s,opacity:i.opacity,props:{...i.props,richText:(0,r.TP3)(""),growY:0,fontSizeAdjustment:1,url:"",textLastEditedBy:null}});let d=e.getShape(t);if(!d)return;let c=e.getPointInParentSpace(d,r.l2P.Sub(o,r.l2P.Rot(new r.l2P(a/2,l/2).mul(d.props.scale),s)));e.updateShape({id:t,type:"note",x:c.x,y:c.y}),n=e.getShape(t)}return e.zoomToSelectionIfOffscreen(16,{animation:{duration:e.options.animationMediumMs},inset:0}),n}class mA extends r.YM5{static id="pointing";dragged=!1;info={};markId="";shape={};shapeId;shapeCenter=new r.l2P;hasCreatedShape=!1;onEnter(){let{editor:e}=this;this.hasCreatedShape=!1,this.shapeId=(0,r.n6Y)(),this.markId=e.markHistoryStoppingPoint(`creating_note:${this.shapeId}`);let t=e.getShapeUtil("note"),n=fb(t,{props:t.getDefaultProps()}),i=e.inputs.getOriginPagePoint().clone(),o=function(e,t,n,i,o){let s,a=10/e.getZoomLevel();for(let l of m_(e,{rotation:0,scale:n,extraHeight:0,noteWidth:i,noteHeight:o})){let e=r.l2P.Sub(t,l),n=e.len();n<a&&(a=n,s=e)}return s}(e,i,e.getResizeScaleFactor(),n.noteWidth,n.noteHeight);o&&i.sub(o),this.shapeCenter=i,e.getInstanceState().isCoarsePointer||this.ensureShapeCreated()}ensureShapeCreated(){if(this.hasCreatedShape)return;let e=function(e,t,n){e.createShape({id:t,type:"note",x:n.x,y:n.y,props:{scale:e.getResizeScaleFactor()}});let i=e.getShape(t);if(!i)return;e.select(t);let o=e.getShapeGeometry(i).bounds,s=(0,r.Y8F)(new r.l2P(i.x-o.width/2,i.y-o.height/2),e);return e.updateShapes([{id:t,type:"note",x:s.x,y:s.y}]),e.getShape(t)}(this.editor,this.shapeId,this.shapeCenter);e?(this.shape=e,this.hasCreatedShape=!0):this.cancel()}onPointerMove(e){this.editor.inputs.getIsDragging()&&(this.ensureShapeCreated(),this.hasCreatedShape&&this.editor.setCurrentTool("select.translating",{...e,target:"shape",shape:this.shape,onInteractionEnd:"note",isCreating:!0,creatingMarkId:this.markId,onCreate:()=>{y(this.editor,this.shape.id)}}))}onPointerUp(){this.complete()}onLongPress(){this.editor.getInstanceState().isCoarsePointer&&this.cancel()}onInterrupt(){this.cancel()}onComplete(){this.complete()}onCancel(){this.cancel()}complete(){this.ensureShapeCreated(),this.hasCreatedShape&&(this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):y(this.editor,this.shape.id,{info:this.info}))}cancel(){this.editor.bailToMark(this.markId),this.parent.transition("idle",this.info)}}class mj extends r.YM5{static id="note";static initial="idle";static children(){return[mE,mA]}shapeType="note"}let mO=new WeakMap;function mD(e){let t=e.getShapeAtPoint(e.inputs.getCurrentPagePoint(),{hitInside:!1,hitLabels:!1,hitLocked:e.options.selectLockedShapes,margin:e.getHitTestMargin(),renderingOnly:!0});if(!t)return null;let n=e.getOutermostSelectableShape(t);return(n===t||n.id===e.getFocusedGroupId()||e.getSelectedShapeIds().includes(n.id)?t:n).id}function mL(e){if(e.isDisposed)return;if("moving"!==e.getCameraState()){mO.set(e,!1);let t=mD(e);return e.setHoveredShape(t)}if(mO.get(e))return;let t=e.getHoveredShapeId();t?mD(e)!==t&&(e.setHoveredShape(null),mO.set(e,!0)):mO.set(e,!0)}let mR=new WeakMap;function mF(e){let t;((t=mR.get(e))||(t=(0,r.nFR)(mL,32),mR.set(e,t)),t)(e)}function mz(e){mR.get(e)?.cancel()}class mN extends r.YM5{static id="idle";onPointerMove(e){switch(e.target){case"shape":case"canvas":mF(this.editor)}}onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onExit(){mz(this.editor)}onKeyDown(e){if("Enter"===e.key){let t=this.editor.getOnlySelectedShape();this.editor.canEditShape(t)&&(this.editor.setCurrentTool("select"),y(this.editor,t.id,{info:e}))}}onCancel(){this.editor.setCurrentTool("select")}}class m$ extends r.YM5{static id="pointing";shape;markId="";enterTime=0;onEnter(){this.enterTime=Date.now()}onExit(){this.editor.setHintingShapes([])}onPointerMove(e){if(Date.now()-this.enterTime<150)return;let{editor:t}=this;if(!t.inputs.getIsPointing())return;let n=t.inputs.getOriginPagePoint(),i=t.inputs.getCurrentPagePoint(),o=Math.abs(n.x-i.x);if(o>6*Math.sqrt(t.getInstanceState().isCoarsePointer?t.options.coarseDragDistanceSquared:t.options.dragDistanceSquared)/t.getZoomLevel()){let i=(0,r.n6Y)();this.markId=t.markHistoryStoppingPoint(`creating_text:${i}`);let s=this.createTextShape(i,n,!1,o);if(!s)return void this.cancel();this.shape=t.getShape(s),t.select(i);let a=this.editor.getResizeScaleFactor();t.setCurrentTool("select.resizing",{...e,target:"selection",handle:"right",isCreating:!0,creatingMarkId:this.markId,creationCursorOffset:{x:o*a,y:1},onInteractionEnd:"text",onCreate:()=>{y(t,s.id)}})}}onPointerUp(){this.complete()}onLongPress(){this.editor.getInstanceState().isCoarsePointer&&this.cancel()}onComplete(){this.cancel()}onCancel(){this.cancel()}onInterrupt(){this.cancel()}complete(){this.editor.markHistoryStoppingPoint("creating text shape");let e=(0,r.n6Y)(),t=this.editor.inputs.getOriginPagePoint();this.createTextShape(e,t,!0,20)&&(this.editor.select(e),y(this.editor,e))}cancel(){this.parent.transition("idle"),this.editor.bailToMark(this.markId)}createTextShape(e,t,n,i){this.editor.createShape({id:e,type:"text",x:t.x,y:t.y,props:{richText:(0,r.TP3)(""),autoSize:n,w:i,scale:this.editor.getResizeScaleFactor()}});let o=this.editor.getShape(e);if(!o)return void this.cancel();let s=this.editor.getShapePageBounds(o),a=new r.l2P;if(n)switch(o.props.textAlign){case"start":a.x=0;break;case"middle":a.x=-s.width/2;break;case"end":a.x=-s.width}else a.x=0;if(a.y=-s.height/2,(0,r.vc4)(o.parentId)){let e=this.editor.getShapeParentTransform(o);a.rot(-e.rotation())}let l=o.x+a.x,d=o.y+a.y;if(this.editor.getInstanceState().isGridMode){let e=new r.l2P(l,d),t=(0,r.Y8F)(e,this.editor),n=r.l2P.Sub(e,t);this.editor.updateShape({...o,x:l-n.x,y:d-n.y})}else this.editor.updateShape({...o,x:l,y:d});return o}}class mB extends r.YM5{static id="text";static initial="idle";static children(){return[mN,m$]}shapeType="text"}let mH={solid:"semi",pattern:"pattern",fill:"fill","lined-fill":"linedFill"};function mU(e){return{key:`${r.yes.id}:${e}`,getElement:async()=>"pattern"!==e?null:(0,d.jsx)(mK,{})}}function mK(){let e=mJ(),t=(0,r.LsA)(),n=(0,r.hGv)(),i=(0,r.G67)(),o=n.getCurrentTheme().colors[i],s=8/12;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("mask",{id:t,children:[(0,d.jsx)("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),(0,d.jsxs)("g",{strokeLinecap:"round",stroke:"black",children:[(0,d.jsx)("line",{x1:+s,y1:3*s,x2:3*s,y2:+s}),(0,d.jsx)("line",{x1:5*s,y1:7*s,x2:7*s,y2:5*s}),(0,d.jsx)("line",{x1:9*s,y1:11*s,x2:11*s,y2:9*s})]})]}),(0,d.jsx)("pattern",{id:e(1,i),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:(0,d.jsx)("rect",{x:"0",y:"0",width:"8",height:"8",fill:o.solid,mask:`url(#${t})`})})]})}function mW(){return{key:`${r.yes.id}:pattern`,component:mQ}}let mV=new Map;function mY(e,t,n){let i=`${e}_${t}_${n}`,o=mV.get(i);!o&&((o=new Promise((i,o)=>{let s=8*t*e,a=(0,r.jLo)().createElement("canvas");a.width=s,a.height=s;let l=a.getContext("2d");if(!l)return void o();l.fillStyle=n,l.fillRect(0,0,s,s),l.globalCompositeOperation="destination-out",l.lineCap="round",l.lineWidth=1.25*t*e;let d=8/12;l.beginPath(),l.moveTo(d*t*e,3*d*t*e),l.lineTo(3*d*t*e,d*t*e),l.moveTo(5*d*t*e,7*d*t*e),l.lineTo(7*d*t*e,5*d*t*e),l.moveTo(9*d*t*e,11*d*t*e),l.lineTo(11*d*t*e,9*d*t*e),l.stroke(),a.toBlob(e=>{!e||r.bGJ.throwToBlob.get()?o():i(e)})})).catch(()=>mV.delete(i)),mV.set(i,o));return o}let mG=(e,t)=>{let n=(0,r.jLo)().createElement("canvas");n.width=e[0],n.height=e[1];let i=n.getContext("2d");return i?(t(i),n.toDataURL()):""},mq=null;function mX(e){return Math.ceil(Math.log2(Math.max(1,e)))}function mJ(){let e=(0,r.Xhk)("hash_pattern");return(0,f.useCallback)((t,n)=>{let i=mX(t);return(0,r.oX2)(e,`${n}_${i}`)},[e])}function mZ(e){let t=[],n=mX(e);for(let e=0;e<=n;e++)t.push(Math.pow(2,e));return t}function mQ(){let e=(0,r.hGv)(),t=(0,f.useRef)(null),{defs:n,isReady:i}=function(){let e=(0,r.hGv)(),t=(0,r.hau)("devicePixelRatio",()=>e.getInstanceState().devicePixelRatio,[e]),n=(0,r.hau)("maxEffectiveZoom",()=>{let t=e.getCameraOptions().zoomSteps;return(0,r.HVh)(t)/t[0]},[e]),[i,o]=(0,f.useState)(!1),[s,a]=(0,f.useState)(()=>{let e;return mq||(mq={white:mG([1,1],e=>{e.fillStyle="#f8f9fa",e.fillRect(0,0,1,1)}),black:mG([1,1],e=>{e.fillStyle="#212529",e.fillRect(0,0,1,1)})}),e=mq,mZ(n).flatMap(t=>[{zoom:t,url:e.white,theme:"light"},{zoom:t,url:e.black,theme:"dark"}])}),l=mJ();return(0,f.useEffect)(()=>{let r=e.getCurrentTheme(),i=r.colors.light.solid,s=r.colors.dark.solid,l=Promise.all(mZ(n).flatMap(e=>[mY(t,e,i).then(t=>({zoom:e,theme:"light",url:URL.createObjectURL(t)})),mY(t,e,s).then(t=>({zoom:e,theme:"dark",url:URL.createObjectURL(t)}))])),d=!1;return l.then(e=>{d||(a(e),o(!0))}),()=>{d=!0,o(!1),l.then(e=>{for(let{url:t}of e)URL.revokeObjectURL(t)})}},[t,n,e]),{defs:(0,d.jsx)(d.Fragment,{children:s.map(e=>{let t=l(e.zoom,e.theme);return(0,d.jsx)("pattern",{id:t,width:8,height:8,patternUnits:"userSpaceOnUse",children:(0,d.jsx)("image",{href:e.url,width:8,height:8})},t)})}),isReady:i}}();return(0,f.useEffect)(()=>{if(i&&r.YZA.isSafari){let n=function e(t){return t.classList.contains("tl-html-layer")?t:t.parentElement?e(t.parentElement):null}(t.current);n&&e.timers.requestAnimationFrame(()=>{n.style.display="none",e.timers.requestAnimationFrame(()=>{n.style.display=""})})}},[e,i]),(0,d.jsx)("g",{ref:t,"data-testid":i?"ready-pattern-fill-defs":void 0,children:n})}function m0({d:e,fillColor:t,patternFillFallbackColor:n,scale:i=1}){let o=(0,r.hGv)(),s=(0,r.Jf5)(),a=(0,r.hau)("zoomLevel",()=>o.getEfficientZoomLevel(),[o]),l=(0,r.G67)(),c=mJ(),h=(0,r.LsA)(),u=a*i,p=u<=.18,f=c(u,l);return(0,d.jsxs)(d.Fragment,{children:[!s&&!p&&1!==i&&(0,d.jsx)("pattern",{id:h,href:`#${f}`,patternTransform:`scale(${i})`}),(0,d.jsx)("path",{fill:t,d:e}),(0,d.jsx)("path",{fill:s?`url(#${c(1,l)})`:p?n:1!==i?`url(#${h})`:`url(#${f})`,d:e})]})}let m1=f.forwardRef(function({shapeId:e,isEditing:t,richText:n,handleFocus:i,handleChange:o,handleBlur:s,handleKeyDown:a,handleDoubleClick:l,hasCustomTabBehavior:c,handlePaste:h},u){let p=(0,r.hGv)(),g=(0,r.LsA)("tip-tap-editor"),m=p.getTextOptions().tipTapConfig,y=(0,f.useRef)(n),b=(0,f.useRef)(null),x=(0,f.useRef)(null);(0,f.useLayoutEffect)(()=>{b.current?(0,r.n4T)(y.current,n)||b.current.commands.setContent(n):y.current=n},[n]);let w=(0,f.useRef)({selectAll:!1,caretPosition:null});(0,f.useLayoutEffect)(()=>{function e(e){e.shapeId===p.getEditingShapeId()&&(w.current.selectAll=!0)}function t(e){e.shapeId===p.getEditingShapeId()&&(w.current.caretPosition=e.point)}return p.on("select-all-text",e),p.on("place-caret",t),()=>{p.off("select-all-text",e),p.off("place-caret",t)}},[p,t]);let v=(0,r._q_)(o),S=(0,r._q_)(a),C=(0,r._q_)(i),k=(0,r._q_)(s),P=(0,r._q_)(l),T=(0,r._q_)(h);return((0,f.useLayoutEffect)(()=>{if(!t||!m||!x.current)return;let{editorProps:n,...r}=m,i=new eg.KE({element:x.current,autofocus:!0,editable:t,onUpdate:e=>{let t=e.editor.state.doc.toJSON();y.current=t,v({richText:t})},onFocus:C,onBlur:k,onCreate:t=>{if(p.getEditingShapeId()!==e)return;let n=t.editor;p.setRichTextEditor(n);let{selectAll:r,caretPosition:i}=w.current;if(r)n.chain().focus().selectAll().run();else if(i){let e=n.view.posAtCoords({left:i.x,top:i.y})?.pos;e?n.chain().focus().setTextSelection(e).run():n.chain().focus().selectAll().run()}},editorProps:{handleKeyDown:(e,t)=>{c||"Tab"!==t.key||function(e,t,n){if(n.preventDefault(),rq(e))return;let{state:r,dispatch:i}=t,{$from:o,$to:s}=r.selection,a=n.shiftKey,l=r.tr,d=s.end();for(;d>=o.start();){let e=r.doc.resolve(d).blockRange();if(!e)break;let t=e.start,n=e.end,i=r.doc.textBetween(t,n,"\n"),o=!1;r.doc.nodesBetween(t,n,e=>"bulletList"!==e.type.name&&"orderedList"!==e.type.name||(o=!0,!1)),!o&&(a?i.startsWith(" ")&&(l=l.delete(t+1,t+2)):l=l.insertText(" ",t+1)),d=t-1}let c=r.selection.map(l.doc,l.mapping);l.setSelection(c),l.docChanged&&i(l)}(p,e,t),S(t)},handlePaste:(e,t)=>(T(t),!!t.defaultPrevented),handleDoubleClick:(e,t,n)=>P(n),...n},coreExtensionOptions:{clipboardTextSerializer:{blockSeparator:"\n"}},enableCoreExtensions:{textDirection:!1},textDirection:"auto",...r,content:y.current}),o=p.timers.setTimeout(()=>{w.current.caretPosition||w.current.selectAll?i.commands.focus():i.commands.focus("end"),w.current.selectAll=!1,w.current.caretPosition=null},100);return b.current=i,()=>{b.current=null,clearTimeout(o),i.destroy()}},[t,m,C,k,P,v,T,S,p,e,c]),t&&m)?(0,d.jsx)("div",{id:g,ref:u,tabIndex:-1,"data-testid":"rich-text-area",className:"tl-rich-text tl-text tl-text-input",onContextMenu:t?e=>e.stopPropagation():void 0,onPointerDownCapture:e=>e.stopPropagation(),onTouchEnd:e=>e.stopPropagation(),onDragStart:r.woC,children:(0,d.jsx)("div",{className:"tl-rich-text",ref:x})}):null});function m2(e){return"start-legacy"===e||"middle-legacy"===e||"end-legacy"===e}function m3(e,t){return(0,r.hau)("isReadyForEditing",()=>{let n=e.getEditingShapeId();return null!==n&&(n===t||e.getHoveredShapeId()===t)},[e,t])}function m5(e){let t=(0,r.hGv)(),n=(0,r.hau)("isEditing",()=>t.getEditingShapeId()===e,[t]),i=m3(t,e),o=(0,f.useCallback)(n=>{t.dispatch({...(0,r.yGT)(t,n),type:"pointer",name:"pointer_down",target:"shape",shape:t.getShape(e)}),n.stopPropagation()},[t,e]),s=(0,f.useCallback)(n=>{if(t.getEditingShapeId()===e&&n.clipboardData){let e=n.clipboardData.getData("text/html");if(e&&e.includes("<div data-tldraw")){let e=n.clipboardData.getData("text/plain");(0,r.woC)(n),e&&t.getContainerDocument().execCommand("insertText",!1,e)}}},[t,e]);return{handleFocus:()=>{},handleBlur:()=>{},handleInputPointerDown:o,handleDoubleClick:t.markEventAsHandled,handlePaste:s,isEditing:n,isReadyForEditing:i}}let m6=f.memo(function({shapeId:e,type:t,richText:n,labelColor:i,fontFamily:o,fontSize:s,lineHeight:a,textAlign:l,verticalAlign:c,wrap:h,isSelected:u,padding:p=0,onKeyDown:g,classNamePrefix:m,style:y,textWidth:b,textHeight:x,hasCustomTabBehavior:w,showTextOutline:v=!0}){let S,C,k,P,T,E=(0,r.hGv)(),I=f.useRef(!1),_=m2(l),{rInput:M,isEmpty:A,isEditing:j,isReadyForEditing:O,...D}=(C=(S=m5(e)).isEditing,k=(0,r.hGv)(),P=(0,f.useRef)(null),T=n&&rG(n),(0,f.useEffect)(()=>{if(!C)return;let e=P.current?.querySelector("[contenteditable]");e&&k.getContainerDocument().activeElement!==P.current&&e.focus()},[k,C]),{rInput:P,handleKeyDown:(0,f.useCallback)(t=>{k.getEditingShapeId()===e&&"Enter"===t.key&&(0,r.gu7)(t)&&k.complete()},[k,e]),handleChange:(0,f.useCallback)(({richText:n})=>{k.getEditingShapeId()===e&&k.updateShape({id:e,type:t,props:{richText:n}})},[k,e,t]),isEmpty:T,...S}),L=(0,f.useMemo)(()=>{if(n)return rW(E,n)},[E,n]),R=(0,r.hau)("isSelectToolActive",()=>"select"===E.getCurrentToolId(),[E]);if((0,r.a1r)("isDragging",()=>{E.getInstanceState(),I.current=E.inputs.getIsDragging()},[E]),!j&&A)return null;let F=m||"tl-text";return(0,d.jsx)("div",{className:ip(`${F}-label tl-text-wrapper tl-rich-text-wrapper`,v?"tl-text__outline":"tl-text__no-outline"),"aria-hidden":!j,"data-hastext":!A,"data-isediting":j,"data-textwrap":!!h,"data-isselected":u,style:{fontFamily:o,textAlign:l,justifyContent:"center"===l||_?"center":"end"===l?"flex-end":"flex-start",alignItems:"middle"===c?"center":"end"===c?"flex-end":"flex-start",padding:p,...y},children:(0,d.jsxs)("div",{className:`${F}-label__inner tl-text-content__wrapper`,style:{fontSize:s,lineHeight:`${(0,r.OVI)(s,a)}px`,minHeight:`${(0,r.OVI)(s,a)}px`,"--tl-rich-text-heading-line-height":a,minWidth:Math.ceil(b||0),color:i,width:b?Math.ceil(b):void 0,height:x?Math.ceil(x):void 0},children:[(0,d.jsx)("div",{className:`${F} tl-text tl-text-content`,dir:"auto",children:n&&(0,d.jsx)("div",{className:"tl-rich-text","data-is-select-tool-active":R,dangerouslySetInnerHTML:{__html:L||""},onPointerDown:e=>{let t=E.getContainerWindow().HTMLElement;if(e.target instanceof t&&("A"===e.target.tagName||e.target.closest("a"))){if((0,r.woC)(e),!R)return;let t=e.target.closest("a")?.getAttribute("href")??"",n=e=>{"pointer_up"===e.name&&t&&(I.current||(0,r.D1x)(t,"_blank",!1),E.off("event",n))};E.on("event",n)}},"data-is-ready-for-editing":O})}),(O||u)&&(0,d.jsx)(m1,{ref:M,richText:n,isEditing:j,shapeId:e,...D,hasCustomTabBehavior:w,handleKeyDown:g??D.handleKeyDown})]})})});function m4({bounds:e,richText:t,fontSize:n,fontFamily:i,lineHeight:o,textAlign:s,verticalAlign:a,wrap:l,labelColor:c,padding:h,showTextOutline:u=!0}){let p=rW((0,r.hGv)(),t),f=m2(s),g={display:"flex",fontFamily:i,height:"100%",justifyContent:"center"===s||f?"center":"start"===s?"flex-start":"flex-end",alignItems:"middle"===a?"center":"start"===a?"flex-start":"flex-end",padding:`${h}px`},m={fontSize:`${n}px`,wrap:l?"wrap":"nowrap",color:c,lineHeight:`${(0,r.OVI)(n,o)}px`,"--tl-rich-text-heading-line-height":o,textAlign:s,width:"100%",wordWrap:"break-word",overflowWrap:"break-word",whiteSpace:"pre-wrap",textShadow:u?"var(--tl-text-outline)":"none",tabSize:"var(--tl-tab-size, 2)"};return(0,d.jsx)("foreignObject",{x:e.minX,y:e.minY,width:e.w,height:e.h,className:ip("tl-export-embed-styles tl-rich-text tl-rich-text-svg",u?"tl-text__outline":"tl-text__no-outline"),children:(0,d.jsx)("div",{style:g,children:(0,d.jsx)("div",{dangerouslySetInnerHTML:{__html:p},style:m})})})}function m8(e=.25){let t=(0,r.hGv)();return(0,r.hau)("efficient zoom threshold",()=>t.getEfficientZoomLevel()<e,[t,e])}function m9(e,t,n){let i="end"===t?e.end.arrowhead:e.start.arrowhead;if("none"===i)return;let o=function(e,t,n){let i,o="end"===t?e.end.point:e.start.point;switch(e.type){case"straight":{let s="end"===t?e.start.point:e.end.point,a=r.l2P.Dist(s,o),l=(0,r.qE8)(a/5,n,3*n);i=r.l2P.Nudge(o,s,l);break}case"arc":{let s=Math.abs(e.bodyArc.length),a=(0,r.qE8)(s/5,n,3*n),l=(0,r.OpZ)(o,a,e.handleArc.center,e.handleArc.radius);i="end"===t?e.handleArc.sweepFlag?l[0]:l[1]:e.handleArc.sweepFlag?l[1]:l[0];break}case"elbow":{let s="end"===t?e.route.points[e.route.points.length-2]:e.route.points[1],a=r.l2P.ManhattanDist(s,o),l=(0,r.qE8)(a/2,n,3*n);i=s?r.l2P.Nudge(o,s,l):o;break}default:(0,r.h6G)(e,"type")}return r.l2P.IsNaN(i)&&(i=o),{point:o,int:i}}(e,t,n);if(o){switch(i){case"bar":return function({int:e,point:t}){let n=r.l2P.Sub(e,t).div(2),i=r.l2P.Add(t,r.l2P.Rot(n,r.sKG)),o=r.l2P.Sub(t,r.l2P.Rot(n,r.sKG));return`M ${i.x} ${i.y} L ${o.x} ${o.y}`}(o);case"square":return function({int:e,point:t}){let n=r.l2P.Lrp(t,e,.85),i=r.l2P.Sub(n,t).div(2),o=r.l2P.Add(t,r.l2P.Rot(i,r.sKG)),s=r.l2P.Sub(t,r.l2P.Rot(i,r.sKG)),a=r.l2P.Add(n,r.l2P.Rot(i,r.sKG)),l=r.l2P.Sub(n,r.l2P.Rot(i,r.sKG));return`M ${o.x} ${o.y} L ${a.x} ${a.y} L ${l.x} ${l.y} L ${s.x} ${s.y} Z`}(o);case"diamond":return function({point:e,int:t}){let n=r.l2P.Lrp(e,t,.75),i=r.l2P.RotWith(n,e,r.PI/4),o=r.l2P.RotWith(n,e,-r.PI/4),s=r.l2P.Lrp(i,o,.5);return s.add(r.l2P.Sub(s,e)),`M ${s.x} ${s.y} L ${o.x} ${o.y} ${e.x} ${e.y} L ${i.x} ${i.y} Z`}(o);case"dot":return function({point:e,int:t}){let n=r.l2P.Lrp(e,t,.45),i=r.l2P.Dist(n,e);return`M ${n.x-i},${n.y}
96
- a ${i},${i} 0 1,0 ${2*i},0
97
- a ${i},${i} 0 1,0 -${2*i},0 `}(o);case"inverted":return function({point:e,int:t}){let n=r.l2P.Sub(t,e).div(2),i=r.l2P.Add(e,r.l2P.Rot(n,r.sKG)),o=r.l2P.Sub(e,r.l2P.Rot(n,r.sKG));return`M ${i.x} ${i.y} L ${t.x} ${t.y} L ${o.x} ${o.y} Z`}(o);case"arrow":return function({point:e,int:t}){let n=r.l2P.RotWith(t,e,r.PI/6),i=r.l2P.RotWith(t,e,-r.PI/6);return`M ${n.x} ${n.y} L ${e.x} ${e.y} L ${i.x} ${i.y}`}(o);case"triangle":return function({point:e,int:t}){let n=r.l2P.RotWith(t,e,r.PI/6),i=r.l2P.RotWith(t,e,-r.PI/6);return`M ${n.x} ${n.y} L ${i.x} ${i.y} L ${e.x} ${e.y} Z`}(o)}return""}}function m7(e,t){let n=f6(e,t);switch(n.type){case"straight":return new r.AoN({start:r.l2P.From(n.start.point),end:r.l2P.From(n.end.point)});case"arc":return new r.xGO({center:r.l2P.Cast(n.handleArc.center),start:r.l2P.Cast(n.start.point),end:r.l2P.Cast(n.end.point),sweepFlag:n.bodyArc.sweepFlag,largeArcFlag:n.bodyArc.largeArcFlag});case"elbow":return new r.Hes({points:n.route.points});default:(0,r.h6G)(n,"type")}}let ye=(0,r.uYT)("arrow label size",(e,t)=>{e.fonts.trackFontsForShape(t);let n=0,i=0,o=m7(e,t),s=rV(e,rG(t.props.richText)?(0,r.TP3)("i"):t.props.richText),a=o.bounds,l=fb(e.getShapeUtil("arrow"),t),d=l.labelFontSize*t.props.scale,{w:c,h}=e.textMeasure.measureHtml(s,{...Y,lineHeight:l.labelLineHeight,fontFamily:l.labelFontFamily,fontSize:d,maxWidth:null});n=c,i=h;let u=!1,p=f6(e,t),f=yn(t,e.getCurrentTheme()),g="elbow"===p.type?Math.max(p.elbow.A.arrowheadOffset+f,32)+Math.max(p.elbow.B.arrowheadOffset+f,32):64;if(a.width>a.height?(n=Math.max(Math.min(c,g),Math.min(a.width-g,c)),u=!0):n>16*d&&(n=16*d,u=!0),u){let{w:t,h:r}=e.textMeasure.measureHtml(s,{...Y,lineHeight:l.labelLineHeight,fontFamily:l.labelFontFamily,fontSize:d,maxWidth:n});n=t,i=r}return new r.l2P(n,i).addScalar(2*l.labelPadding*t.props.scale)},{areRecordsEqual:(e,t)=>{if(e.props===t.props)return!0;let n=(0,r.Xzd)(e.props,t.props);return 1===n.length&&"labelPosition"===n[0]}});function yt(e,t){return ye.get(e,t.id)??new r.l2P(0,0)}function yn(e,t){let n=t.strokeWidth*G[e.props.size];return(20+(n-t.strokeWidth*G.s)*2+20*(n>=t.strokeWidth*G.xl))*e.props.scale}function yr(e,t,n){if(!n&&rG(t.props.richText)){let n=m7(e,t).interpolateAlongEdge(.5);return{box:r.azJ.FromCenter(n,new r.l2P(0,0)),debugGeom:[]}}let i=[],o=f6(e,t),s={hasStartBinding:!!o.bindings.start,hasEndBinding:!!o.bindings.end,hasStartArrowhead:"none"!==o.start.arrowhead,hasEndArrowhead:"none"!==o.end.arrowhead},a=function(e,t,n){let i,o,s=m7(e,t),a=[],l=[new r.IQE({children:[s],debugColor:"lime"})],d=yt(e,t),c=yn(t,e.getCurrentTheme()),h=c/s.length;if("elbow"===n.type)a.push(n.start.point,n.end.point),i=r.azJ.FromCenter(n.start.point,d).expandBy(c),o=r.azJ.FromCenter(n.end.point,d).expandBy(c);else{let e=s.interpolateAlongEdge(h),t=s.interpolateAlongEdge(1-h);a.push(e,t),i=r.azJ.FromCenter(e,d),o=r.azJ.FromCenter(t,d)}let u=s.intersectPolygon(i.corners),p=s.intersectPolygon(o.corners),f=yi(n.start.point,u),g=yi(n.end.point,p),m=f?s.uninterpolateAlongEdge(f):.5,y=g?s.uninterpolateAlongEdge(g):.5;for(let e of(m>y&&(m=.5,y=.5),[...u,...p,...a]))l.push(new r.PUi({x:e.x-3,y:e.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));return l.push(new r.dxv({points:i.corners,debugColor:"lime",isFilled:!1,ignore:!0}),new r.dxv({points:o.corners,debugColor:"lime",isFilled:!1,ignore:!0})),{start:m,end:y,dbg:l}}(e,t,o);a.dbg&&i.push(...a.dbg);let l=function(e,t,n){let{hasEndArrowhead:i,hasEndBinding:o,hasStartBinding:s,hasStartArrowhead:a}=n;return(0,r.qE8)(e.props.labelPosition,a||s?t.start:0,i||o?t.end:1)}(t,a,s),d=m7(e,t).interpolateAlongEdge(l),c=yt(e,t);return{box:r.azJ.FromCenter(d,c),debugGeom:i}}function yi(e,t){let n=null,i=-1/0;for(let o of t){let t=r.l2P.Dist2(e,o);t>i&&(n=o,i=t)}return n}function yo(e,t){let n=f6(e,t);switch(n.type){case"straight":case"arc":return .5;case"elbow":{let r=n.route.midpointHandle,i=m7(e,t);if(r&&i)return i.uninterpolateAlongEdge(r.point);return .5}default:(0,r.h6G)(n,"type")}}function ys(e,t){if(!e.isShapeOfType(t,"arrow"))return!1;let n=e.getPointInShapeSpace(t,e.inputs.getCurrentPagePoint()),i=e.getShapeGeometry(t).children[1];return i&&(0,r.s3y)(n,i.vertices)}function ya(e){switch(e.type){case"straight":return new c().moveTo(e.start.point.x,e.start.point.y,{offset:0,roundness:0}).lineTo(e.end.point.x,e.end.point.y,{offset:0,roundness:0});case"arc":return new c().moveTo(e.start.point.x,e.start.point.y,{offset:0,roundness:0}).circularArcTo(e.bodyArc.radius,!!e.bodyArc.largeArcFlag,!!e.bodyArc.sweepFlag,e.end.point.x,e.end.point.y,{offset:0,roundness:0});case"elbow":{let t=new c;t.moveTo(e.start.point.x,e.start.point.y,{offset:0});for(let n=1;n<e.route.points.length;n++){let r=e.route.points[n];e.route.skipPointsWhenDrawing.has(r)||t.lineTo(r.x,r.y,{offset:n===e.route.points.length-1?0:void 0})}return t}default:(0,r.h6G)(e,"type")}}function yl({arrow:e}){let t=(0,r.hGv)(),n=(0,r.hau)("elbow arrow grid",()=>{try{return fq(t,t.getShape(e.id),dr(t,e))}catch(e){console.error(e);return}},[t,e.id]);if(!n)return null;let i=r.azJ.Common([n.A.original,n.B.original]).expandBy(50),o=n.route?.name??"",s=n.route?.midpointHandle;return(0,d.jsxs)(d.Fragment,{children:[null!==n.midX&&(0,d.jsx)(yd,{a:{x:n.midX,y:i.minY},b:{x:n.midX,y:i.maxY},stroke:"red"}),null!==n.midY&&(0,d.jsx)(yd,{a:{x:i.minX,y:n.midY},b:{x:i.maxX,y:n.midY},stroke:"blue"}),s?.axis==="x"&&n.midXRange&&(0,d.jsx)(yd,{a:{x:n.midXRange.lo,y:s.point.y},b:{x:n.midXRange.hi,y:s.point.y},stroke:"red",strokeDasharray:"0 2"}),s?.axis==="y"&&n.midYRange&&(0,d.jsx)(yd,{a:{x:s.point.x,y:n.midYRange.lo},b:{x:s.point.x,y:n.midYRange.hi},stroke:"blue",strokeDasharray:"0 2"}),(0,d.jsx)(yu,{box:n.A.original,stroke:"orange"}),(0,d.jsx)(yu,{box:n.A.expanded,stroke:"orange",strokeWidth:.5}),(0,d.jsx)(yu,{box:n.A.original.clone().expandBy(n.options.minElbowLegLength),stroke:"orange",strokeWidth:.5}),(0,d.jsx)(yu,{box:n.B.original,stroke:"lightskyblue"}),(0,d.jsx)(yu,{box:n.B.expanded,stroke:"lightskyblue",strokeWidth:.5}),(0,d.jsx)(yu,{box:n.B.original.clone().expandBy(n.options.minElbowLegLength),stroke:"lightskyblue",strokeWidth:.5}),(0,d.jsx)(yh,{edge:n.A.edges.top,axis:"x",stroke:"orange"}),(0,d.jsx)(yh,{edge:n.B.edges.top,axis:"x",stroke:"lightskyblue"}),(0,d.jsx)(yh,{edge:n.A.edges.right,axis:"y",stroke:"orange"}),(0,d.jsx)(yh,{edge:n.B.edges.right,axis:"y",stroke:"lightskyblue"}),(0,d.jsx)(yh,{edge:n.A.edges.bottom,axis:"x",stroke:"orange"}),(0,d.jsx)(yh,{edge:n.B.edges.bottom,axis:"x",stroke:"lightskyblue"}),(0,d.jsx)(yh,{edge:n.A.edges.left,axis:"y",stroke:"orange"}),(0,d.jsx)(yh,{edge:n.B.edges.left,axis:"y",stroke:"lightskyblue"}),n.route&&(0,d.jsx)(yc,{route:n.route.points,strokeWidth:10}),(0,d.jsx)("text",{x:i.minX+5,y:i.minY-3,fontSize:10,fill:"black",stroke:"var(--tl-color-background)",strokeWidth:2,paintOrder:"stroke",children:o}),(0,d.jsxs)("text",{x:n.A.expanded.x,y:n.A.expanded.y,fontSize:10,fill:"black",stroke:"var(--tl-color-background)",strokeWidth:2,paintOrder:"stroke",children:["A",n.route&&`, ${n.route.aEdgePicking}`,n.A.isPoint&&", point"]}),(0,d.jsxs)("text",{x:n.B.expanded.x,y:n.B.expanded.y,fontSize:10,fill:"black",stroke:"var(--tl-color-background)",strokeWidth:2,paintOrder:"stroke",children:["B",n.route&&`, ${n.route.bEdgePicking}`,n.B.isPoint&&", point"]})]})}function yd({a:e,b:t,...n}){return(0,d.jsx)("line",{fill:"none",strokeWidth:1,strokeDasharray:"4,4",stroke:"green",x1:e.x,y1:e.y,x2:t.x,y2:t.y,...n})}function yc({route:e,...t}){return(0,d.jsx)("polyline",{fill:"none",stroke:"darkorchid",strokeWidth:3,opacity:.5,points:e.map(e=>`${e.x},${e.y}`).join(" "),...t})}function yh({edge:e,axis:t,...n}){if(!e||null===e.expanded)return null;let r=e=>"x"===t?{x:e.y,y:e.x}:e;return(0,d.jsxs)("g",{children:[(0,d.jsx)(yd,{a:r({x:e.expanded,y:e.cross.min}),b:r({x:e.expanded,y:e.cross.max}),strokeDasharray:"0",strokeWidth:1.5,...n}),(0,d.jsx)(yd,{a:r({x:e.expanded-4,y:e.cross.min}),b:r({x:e.expanded+4,y:e.cross.min}),strokeDasharray:"0",strokeWidth:1.5,...n}),(0,d.jsx)(yd,{a:r({x:e.expanded-4,y:e.cross.max}),b:r({x:e.expanded+4,y:e.cross.max}),strokeDasharray:"0",strokeWidth:1.5,...n})]})}function yu({box:e,...t}){return(0,d.jsx)("rect",{x:e.minX,y:e.minY,width:e.width,height:e.height,strokeDasharray:"4,4",strokeWidth:1,fill:"none",...t})}let yp=new r.laH;function yf(e,t){let n=r.l2P.FromAngle(t).per();return r.l2P.Dpr(e,n)}let yg="start",ym="middle";function yy(e,t,n,r=!1){let i=Math.max(0,Math.min(n,t.w/2,t.h/2));if(0===i)return void e.rect(t.x,t.y,t.w,t.h);if(r){e.moveTo(t.x,t.y+i),e.lineTo(t.x,t.maxY-i),e.arcTo(t.x,t.maxY,t.x+i,t.maxY,i),e.lineTo(t.maxX-i,t.maxY),e.arcTo(t.maxX,t.maxY,t.maxX,t.maxY-i,i),e.lineTo(t.maxX,t.y+i),e.arcTo(t.maxX,t.y,t.maxX-i,t.y,i),e.lineTo(t.x+i,t.y),e.arcTo(t.x,t.y,t.x,t.y+i,i),e.closePath();return}e.moveTo(t.x+i,t.y),e.lineTo(t.maxX-i,t.y),e.arcTo(t.maxX,t.y,t.maxX,t.y+i,i),e.lineTo(t.maxX,t.maxY-i),e.arcTo(t.maxX,t.maxY,t.maxX-i,t.maxY,i),e.lineTo(t.x+i,t.maxY),e.arcTo(t.x,t.maxY,t.x,t.maxY-i,i),e.lineTo(t.x,t.y+i),e.arcTo(t.x,t.y,t.x+i,t.y,i),e.closePath()}class yb extends r.inY{static type="arrow";static props=r.FXh;static migrations=r.udf;options={expandElbowLegLength:{s:28,m:36,l:44,xl:66},minElbowLegLength:{s:6,m:10.5,l:15,xl:30},minElbowHandleDistance:16,arcArrowCenterSnapDistance:16,elbowArrowCenterSnapDistance:24,elbowArrowEdgeSnapDistance:20,elbowArrowPointSnapDistance:24,elbowArrowAxisSnapDistance:16,labelCenterSnapDistance:10,elbowMidpointSnapDistance:10,elbowMinSegmentLengthToShowMidpointHandle:20,hoverPreciseTimeout:600,pointingPreciseTimeout:320,shouldBeExact:e=>e.inputs.getAltKey(),shouldIgnoreTargets:e=>e.inputs.getCtrlKey(),showTextOutline:!0,getDefaultDisplayValues(e,t,n,i){let{color:o,fill:s,labelColor:a,size:l,font:d}=t.props,c=n.colors[i];return{strokeColor:(0,r.FHQ)(c,o,"solid"),strokeWidth:n.strokeWidth*G[l],fillColor:"none"===s?"transparent":"semi"===s?c.solid:(0,r.FHQ)(c,o,mH[s]),patternFillFallbackColor:(0,r.FHQ)(c,o,"semi"),labelColor:(0,r.FHQ)(c,a,"solid"),labelFontFamily:Q(n,d),labelFontSize:n.fontSize*J[l],labelLineHeight:n.lineHeight,labelPadding:4.25,labelBorderRadius:3.5}},getCustomDisplayValues:()=>({})};canEdit(e){return!0}canBind({toShape:e}){return"arrow"!==e.type}canSnap(e){return!1}hideResizeHandles(e){return!0}hideRotateHandle(e){return!0}hideSelectionBoundsBg(e){return!0}hideSelectionBoundsFg(e){return!0}hideInMinimap(){return!0}canBeLaidOut(e,t){if("flip"===t.type){let{start:n,end:r}=dr(this.editor,e),{shapes:i=[]}=t;if(n&&!i.find(e=>e.id===n.toId)||r&&!i.find(e=>e.id===r.toId))return!1}return!0}getFontFaces(e){if(rG(e.props.richText))return r.Mlv;let t=rB(this.editor.getCurrentTheme(),e.props.font);return t||(0,r.EYW)(this.editor,e.props.richText,{family:`tldraw_${e.props.font}`,weight:"normal",style:"normal"})}getDefaultProps(){return{kind:"arc",elbowMidPoint:.5,dash:"draw",size:"m",fill:"none",color:"black",labelColor:"black",bend:0,start:{x:0,y:0},end:{x:2,y:0},arrowheadStart:"none",arrowheadEnd:"arrow",richText:(0,r.TP3)(""),labelPosition:.5,font:"draw",scale:1}}getGeometry(e){let t,n=this.editor.getEditingShapeId()===e.id,i=f6(this.editor,e),o=[],s="straight"===i.type?new r.AoN({start:r.l2P.From(i.start.point),end:r.l2P.From(i.end.point)}):"arc"===i.type?new r.xGO({center:r.l2P.Cast(i.handleArc.center),start:r.l2P.Cast(i.start.point),end:r.l2P.Cast(i.end.point),sweepFlag:i.bodyArc.sweepFlag,largeArcFlag:i.bodyArc.largeArcFlag}):new r.Hes({points:i.route.points});if(i.isValid&&(n||!rG(e.props.richText))){let i=yr(this.editor,e,n);r.bGJ.debugGeometry.get()&&o.push(...i.debugGeom),t=new r.krb({x:i.box.x,y:i.box.y,width:i.box.w,height:i.box.h,isFilled:!0,isLabel:!0})}return new r.IQE({children:[...t?[s,t]:[s],...o]})}getHandles(e){let t=f6(this.editor,e),n=[{id:yg,type:"vertex",index:"a1",x:t.start.handle.x,y:t.start.handle.y},{id:"end",type:"vertex",index:"a3",x:t.end.handle.x,y:t.end.handle.y}];if("arc"===e.props.kind&&("straight"===t.type||"arc"===t.type)&&n.push({id:ym,type:"virtual",index:"a2",x:t.middle.x,y:t.middle.y}),"elbow"===e.props.kind&&"elbow"===t.type&&t.route.midpointHandle){let i=this.editor.getShapePageTransform(e.id),o=i.applyToPoint(t.route.midpointHandle.segmentStart),s=i.applyToPoint(t.route.midpointHandle.segmentEnd);r.l2P.Dist(o,s)*this.editor.getEfficientZoomLevel()>this.options.elbowMinSegmentLengthToShowMidpointHandle&&n.push({id:ym,type:"vertex",index:"a2",x:t.route.midpointHandle.point.x,y:t.route.midpointHandle.point.y})}return n}getText(e){return rX(this.editor,e.props.richText)}onHandleDrag(e,t){let n=t.handle.id;switch(n){case ym:switch(e.props.kind){case"arc":return this.onArcMidpointHandleDrag(e,t);case"elbow":return this.onElbowMidpointHandleDrag(e,t);default:(0,r.h6G)(e.props.kind)}case yg:case"end":return this.onTerminalHandleDrag(e,t,n);default:(0,r.h6G)(n)}}onArcMidpointHandleDrag(e,{handle:t}){let n=dr(this.editor,e),{start:i,end:o}=di(this.editor,e,n),s=r.l2P.Sub(o,i),a=r.l2P.Per(s),l=r.l2P.Med(o,i),d=r.l2P.Sub(l,a),c=r.l2P.Add(l,a),h=r.l2P.NearestPointOnLineSegment(d,c,t,!1),u=r.l2P.Dist(h,l);return r.l2P.Clockwise(h,o,l)&&(u*=-1),{id:e.id,type:e.type,props:{bend:u}}}onElbowMidpointHandleDrag(e,{handle:t}){var n;let i=f6(this.editor,e);if(i?.type!=="elbow")return;let o=this.editor.getShapePageTransform(e.id),s=o.applyToPoint(t),a=i.route.midpointHandle?.axis;if(!a)return;let l=fT[a],d=i.elbow[l.midRange];if(!d)return;let c=r.l2P.Angle(o.applyToPoint(l.v(0,0)),o.applyToPoint(l.v(0,1)));c<0&&(c+=Math.PI);let h=yf(s,c),u=yf(o.applyToPoint(l.v(d.lo,0)),c),p=yf(o.applyToPoint(l.v(d.hi,0)),c),f=this.options.elbowMidpointSnapDistance/this.editor.getEfficientZoomLevel(),g=yf(o.applyToPoint(l.v((0,r.CcK)(d.lo,d.hi,.5),0)),c),m=g,y=Math.abs(g-h);for(let[e,t]of(n=this.editor,yp.get(n,e=>{let t=(0,r.EWP)("current selected arrow shape",()=>{let t=e.getOnlySelectedShape();return t&&e.isShapeOfType(t,"arrow")?t.id:null}),n=e.store.query.ids("shape",()=>{let e=t.get();return e?{type:{eq:"arrow"},id:{neq:e}}:{type:{eq:"arrow"}}});return(0,r.EWP)("elbow arrow snap lines",()=>{let t=new Map,i=e.getCurrentPageShapeIds(),o=e.getViewportPageBounds();for(let s of n.get()){if(!i.has(s))continue;let n=e.getShape(s);if(n?.type!=="arrow")continue;let a=e.getShapePageBounds(s);if(!a||!o.includes(a))continue;let l=dr(e,n),d=e.getShapePageTransform(s);if(!d)continue;let c=e.getShapeGeometry(s),h=d.applyToPoints(c.vertices);for(let e=1;e<h.length;e++){let n=h[e-1],i=h[e],o=r.l2P.Angle(n,i);o<0&&(o+=Math.PI);let s=t.get(o);s||(s=new Set,t.set(o,s));let a=yf(n,o);s.add({perpDistance:a,startBoundShapeId:l.start?.toId,endBoundShapeId:l.end?.toId})}}return t})}).get())){let{isParallel:n,isFlippedParallel:o}=function(e,t,n=1e-4){let i=Math.abs(e-t),o=Math.abs(i-Math.PI)<n,s=Math.abs(i-r.uAR)<n;return{isParallel:i<n||s,isFlippedParallel:o}}(c,e);if(n||o)for(let e of t){let t=e.startBoundShapeId&&(e.startBoundShapeId===i.bindings.start?.toId||e.startBoundShapeId===i.bindings.end?.toId),n=e.endBoundShapeId&&(e.endBoundShapeId===i.bindings.start?.toId||e.endBoundShapeId===i.bindings.end?.toId);if(!t&&!n)continue;let r=o?-e.perpDistance:e.perpDistance,s=Math.abs(r-h);s<y&&(m=r,y=s)}}y>f&&(m=h);let b=(0,r.qE8)((0,r.Fg_)(u,p,m),0,1);return{id:e.id,type:e.type,props:{elbowMidPoint:b}}}onTerminalHandleDrag(e,{handle:t,isPrecise:n},i){let o=dr(this.editor,e),s={id:e.id,type:"arrow",props:{}},a=o[i],l=o[i===yg?"end":yg],d=go({editor:this.editor,pointInPageSpace:this.editor.getShapePageTransform(e.id).applyToPoint(t),arrow:e,isPrecise:n,currentBinding:a,oppositeBinding:l});if(!d){da(this.editor,e,i);let n=(0,r.Y8F)(new r.l2P(t.x,t.y),this.editor);return s.props[i]={x:n.x,y:n.y},s}let c={terminal:i,normalizedAnchor:d.normalizedAnchor,isPrecise:d.isPrecise,isExact:d.isExact,snap:d.snap};ds(this.editor,e,d.target.id,c);let h=dr(this.editor,e);return h.start&&h.end&&h.start.toId===h.end.toId&&r.l2P.Equals(h.start.props.normalizedAnchor,h.end.props.normalizedAnchor)&&ds(this.editor,e,h.end.toId,{...h.end.props,normalizedAnchor:{x:h.end.props.normalizedAnchor.x+.05,y:h.end.props.normalizedAnchor.y}}),s}onTranslateStart(e){let t=dr(this.editor,e);if("elbow"===e.props.kind&&this.editor.getOnlySelectedShapeId()===e.id){let n=f6(this.editor,e);if(!n)return;let r={id:e.id,type:"arrow",props:{}};return t.start&&(r.props.start={x:n.start.point.x,y:n.start.point.y},da(this.editor,e,"start")),t.end&&(r.props.end={x:n.end.point.x,y:n.end.point.y},da(this.editor,e,"end")),r}let n=di(this.editor,e,t),i=this.editor.getShapePageTransform(e.id),o=this.editor.getSelectedShapeIds();if(!(t.start&&(o.includes(t.start.toId)||this.editor.isAncestorSelected(t.start.toId))||t.end&&(o.includes(t.end.toId)||this.editor.isAncestorSelected(t.end.toId))))for(let o of(yv.set(e,{pagePosition:i.applyToPoint(e),terminalBindings:(0,r._Hz)(n,(e,n)=>{let r=t[e];return r?{binding:r,shapePosition:n,pagePosition:i.applyToPoint(n)}:null})}),t.start&&(ge({editor:this.editor,arrow:e,terminal:"start",useHandle:!0}),e=this.editor.getShape(e.id)),t.end&&ge({editor:this.editor,arrow:e,terminal:"end",useHandle:!0}),[yg,"end"])){let e=t[o];e&&this.editor.updateBinding({...e,props:{...e.props,isPrecise:!0}})}}onTranslate(e,t){let n=yv.get(e);if(!n)return;let i=this.editor.getShapePageTransform(t.id),o=r.l2P.Sub(i.applyToPoint(t),n.pagePosition);for(let e of Object.values(n.terminalBindings)){if(!e)continue;let n=r.l2P.Add(e.pagePosition,r.l2P.Mul(o,.5)),i=this.editor.getShapeAtPoint(n,{hitInside:!0,hitFrameInside:!0,margin:0,filter:e=>!e.isLocked&&this.editor.canBindShapes({fromShape:t,toShape:e,binding:"arrow"})});if(i?.id===e.binding.toId){let o=r.azJ.ZeroFix(this.editor.getShapeGeometry(i).bounds),s=this.editor.getPointInShapeSpace(i,n),a={x:(s.x-o.minX)/o.width,y:(s.y-o.minY)/o.height};ds(this.editor,t,i.id,{...e.binding.props,normalizedAnchor:a,isPrecise:!0})}else da(this.editor,t,e.binding.props.terminal)}}_resizeInitialBindings=new r.laH;onResize(e,t){let{scaleX:n,scaleY:i}=t,o=this._resizeInitialBindings.get(e,()=>dr(this.editor,e)),s=di(this.editor,e,o),{start:a,end:l}=(0,r.pN9)(e.props),{bend:d}=e.props;o.start||(a.x=s.start.x*n,a.y=s.start.y*i),o.end||(l.x=s.end.x*n,l.y=s.end.y*i);let c=Math.abs(n),h=Math.abs(i),u=o?.start?r.l2P.From(o.start.props.normalizedAnchor):null,p=o?.end?r.l2P.From(o.end.props.normalizedAnchor):null;return n<0&&i>=0?(0!==d&&(d*=-1*Math.max(c,h)),u&&(u.x=1-u.x),p&&(p.x=1-p.x)):n>=0&&i<0?(0!==d&&(d*=-1*Math.max(c,h)),u&&(u.y=1-u.y),p&&(p.y=1-p.y)):n>=0&&i>=0?0!==d&&(d*=Math.max(c,h)):n<0&&i<0&&(0!==d&&(d*=Math.max(c,h)),u&&(u.x=1-u.x,u.y=1-u.y),p&&(p.x=1-p.x,p.y=1-p.y)),o.start&&u&&ds(this.editor,e,o.start.toId,{...o.start.props,normalizedAnchor:u.toJson()}),o.end&&p&&ds(this.editor,e,o.end.toId,{...o.end.props,normalizedAnchor:p.toJson()}),{props:{start:a,end:l,bend:d}}}onDoubleClickHandle(e,t){switch(t.id){case yg:return{id:e.id,type:e.type,props:{...e.props,arrowheadStart:"none"===e.props.arrowheadStart?"arrow":"none"}};case"end":return{id:e.id,type:e.type,props:{...e.props,arrowheadEnd:"none"===e.props.arrowheadEnd?"arrow":"none"}}}}component(e){let{editor:t}=this,n=fb(this,e),i=(0,r.hau)("is selected",()=>t.getOnlySelectedShape()?.id===e.id,[t,e.id]),o=(0,r.hau)("is editing",()=>t.getEditingShapeId()===e.id,[t,e.id]),s=f6(t,e);if(!s?.isValid)return null;let a=yr(t,e,o),l=o||!rG(e.props.richText);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(r.ULM,{style:{minWidth:50,minHeight:50},children:[(0,d.jsx)(yx,{shape:e,strokeColor:n.strokeColor,strokeWidth:n.strokeWidth,fillColor:n.fillColor,patternFillFallbackColor:n.patternFillFallbackColor,labelBorderRadius:n.labelBorderRadius}),"elbow"===e.props.kind&&r.bGJ.debugElbowArrows.get()&&(0,d.jsx)(yl,{arrow:e})]}),l&&(0,d.jsx)(m6,{shapeId:e.id,type:"arrow",fontFamily:n.labelFontFamily,fontSize:n.labelFontSize,lineHeight:n.labelLineHeight,textAlign:"center",verticalAlign:"middle",labelColor:n.labelColor,richText:e.props.richText,textWidth:(a.box.w-2*n.labelPadding*e.props.scale)/e.props.scale,isSelected:i,padding:0,showTextOutline:this.options.showTextOutline,style:{transform:`translate(${a.box.center.x}px, ${a.box.center.y}px)${1!==e.props.scale?` scale(${e.props.scale})`:""}`}})]})}getIndicatorPath(e){let t=f6(this.editor,e);if(!t)return;let n=fb(this,e),i=this.editor.getEditingShapeId()===e.id,{start:o,end:s}=di(this.editor,e,t?.bindings),a=this.editor.getShapeGeometry(e),l=rG(e.props.richText),d=i||!l?a.children[1]:null;if(r.l2P.Equals(o,s))return;let c=n.strokeWidth*e.props.scale;if(i&&d){let t=d.getBounds(),r=new Path2D;return yy(r,t,n.labelBorderRadius*e.props.scale),r}let h=this.editor.getEfficientZoomLevel()<.25/e.props.scale,u=ya(t).toPath2D("draw"!==e.props.dash||h?{style:"solid",strokeWidth:1}:{style:"draw",randomSeed:e.id,strokeWidth:1,passes:1,offset:0,roundness:2*c}),p=t.start.arrowhead&&m9(t,"start",c),f=t.end.arrowhead&&m9(t,"end",c),g=!!(p&&"arrow"!==t.start.arrowhead),m=!!(f&&"arrow"!==t.end.arrowhead);if(d||g||m){let t=a.bounds,r=new Path2D;r.rect(t.minX-100,t.minY-100,t.width+200,t.height+200),d&&yy(r,d.getBounds(),n.labelBorderRadius*e.props.scale,!0),g&&p&&r.addPath(new Path2D(p)),m&&f&&r.addPath(new Path2D(f));let i=[];if(p&&i.push(new Path2D(p)),f&&i.push(new Path2D(f)),d){let t=d.getBounds(),r=new Path2D;yy(r,t,n.labelBorderRadius*e.props.scale),i.push(r)}return{path:u,clipPath:r,additionalPaths:i}}let y=new Path2D;return y.addPath(u),p&&y.addPath(new Path2D(p)),f&&y.addPath(new Path2D(f)),y}onEditStart(e){if(rG(e.props.richText)){let t=yo(this.editor,e);this.editor.updateShape({id:e.id,type:e.type,props:{labelPosition:t}})}}toSvg(e,t){t.addExportDef(mU(e.props.fill));let n=fb(this,e,t.colorMode),r=1/e.props.scale,i=!rG(e.props.richText);return(0,d.jsxs)("g",{transform:`scale(${r})`,children:[(0,d.jsx)(yx,{shape:e,strokeColor:n.strokeColor,strokeWidth:n.strokeWidth,fillColor:n.fillColor,patternFillFallbackColor:n.patternFillFallbackColor,labelBorderRadius:n.labelBorderRadius}),i&&(0,d.jsx)(m4,{fontSize:n.labelFontSize*e.props.scale,fontFamily:n.labelFontFamily,lineHeight:n.labelLineHeight,textAlign:"center",verticalAlign:"middle",labelColor:n.labelColor,richText:e.props.richText,bounds:yr(this.editor,e,!1).box.clone().expandBy(-n.labelPadding*e.props.scale),padding:0,showTextOutline:this.options.showTextOutline})]})}getCanvasSvgDefs(){return[mW()]}getInterpolatedProps(e,t,n){return{...n>.5?t.props:e.props,scale:(0,r.CcK)(e.props.scale,t.props.scale,n),start:{x:(0,r.CcK)(e.props.start.x,t.props.start.x,n),y:(0,r.CcK)(e.props.start.y,t.props.start.y,n)},end:{x:(0,r.CcK)(e.props.end.x,t.props.end.x,n),y:(0,r.CcK)(e.props.end.y,t.props.end.y,n)},bend:(0,r.CcK)(e.props.bend,t.props.bend,n),labelPosition:(0,r.CcK)(e.props.labelPosition,t.props.labelPosition,n)}}}let yx=(0,r.u4I)(function({shape:e,strokeColor:t,strokeWidth:n,fillColor:i,patternFillFallbackColor:o,labelBorderRadius:s=3.5}){var a;let l=(0,r.hGv)(),c=f6(l,e),h=m8(.25/e.props.scale),u=(0,r.Xhk)(e.id+"_clip"),p=(0,r._As)(e.id),f=l.getShapeGeometry(e);if(!f)return null;let g=r.azJ.ZeroFix(f.bounds),m=rG(e.props.richText);if(!c?.isValid)return null;let y=n*e.props.scale,b=c.start.arrowhead&&m9(c,"start",y),x=c.end.arrowhead&&m9(c,"end",y),w=yr(l,e,p),v="none"!==c.start.arrowhead&&"arrow"!==c.start.arrowhead,S="none"!==c.end.arrowhead&&"arrow"!==c.end.arrowhead;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("defs",{children:(0,d.jsx)("clipPath",{id:u,children:(0,d.jsx)(yw,{radius:s*e.props.scale,hasText:p||!m,bounds:g,labelBounds:w.box,as:v&&b?b:"",ae:S&&x?x:""})})}),(0,d.jsxs)("g",{fill:"none",stroke:t,strokeWidth:y,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[(0,d.jsxs)("g",{style:{clipPath:`url(#${u})`,WebkitClipPath:`url(#${u})`},children:[(0,d.jsx)("rect",{x:(0,r.WMC)(g.minX-100),y:(0,r.WMC)(g.minY-100),width:(0,r.WMC)(g.width+200),height:(0,r.WMC)(g.height+200),opacity:0}),(a={style:e.props.dash,strokeWidth:y,forceSolid:h,randomSeed:e.id},ya(c).toSvg(a))]}),b&&v&&"none"!==e.props.fill&&("pattern"===e.props.fill?(0,d.jsx)(m0,{d:b,fillColor:i,patternFillFallbackColor:o,scale:e.props.scale}):(0,d.jsx)("path",{fill:i,d:b})),x&&S&&"none"!==e.props.fill&&("pattern"===e.props.fill?(0,d.jsx)(m0,{d:x,fillColor:i,patternFillFallbackColor:o,scale:e.props.scale}):(0,d.jsx)("path",{fill:i,d:x})),b&&(0,d.jsx)("path",{d:b}),x&&(0,d.jsx)("path",{d:x})]})]})});function yw({radius:e,hasText:t,bounds:n,labelBounds:r,as:i,ae:o}){let s=(0,f.useMemo)(()=>{let i=new c;return i.moveTo(n.left-100,n.top-100).lineTo(n.right+100,n.top-100).lineTo(n.right+100,n.bottom+100).lineTo(n.left-100,n.bottom+100).close(),t&&i.moveTo(r.left,r.top+e).lineTo(r.left,r.bottom-e).circularArcTo(e,!1,!1,r.left+e,r.bottom).lineTo(r.right-e,r.bottom).circularArcTo(e,!1,!1,r.right,r.bottom-e).lineTo(r.right,r.top+e).circularArcTo(e,!1,!1,r.right-e,r.top).lineTo(r.left+e,r.top).circularArcTo(e,!1,!1,r.left,r.top+e).close(),i.toD()},[e,t,n.bottom,n.left,n.right,n.top,r.bottom,r.left,r.right,r.top]);return(0,d.jsx)("path",{d:`${s}${i}${o}`})}let yv=new WeakMap,yS="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' fill='none'%3E%3Cpath stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M13 5H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6M19 5h6m0 0v6m0-6L13 17'/%3E%3C/svg%3E";function yC({url:e}){let t=(0,r.hGv)(),n=m8(),i=(0,f.useCallback)(e=>{t.inputs.getShiftKey()||t.markEventAsHandled(e)},[t]);return(0,d.jsx)("a",{className:ip("tl-hyperlink-button",{"tl-hyperlink-button__hidden":n}),href:e,target:"_blank",rel:"noopener noreferrer",onPointerDown:i,onPointerUp:i,title:e,draggable:!1,children:(0,d.jsx)("div",{className:"tl-hyperlink__icon",style:{mask:`url("${yS}") center 100% / 100% no-repeat`,WebkitMask:`url("${yS}") center 100% / 100% no-repeat`}})})}let yk="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' fill='none'%3E%3Cpath stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M13 5H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6M19 5h6m0 0v6m0-6L13 17'/%3E%3C/svg%3E",yP=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function yT(e){return yP.map(t=>{let{offsetX:n,offsetY:i,blur:o,spread:s,color:a}=t,{x:l,y:d}=new r.l2P(n,i).rot(-e);return`${l}px ${d}px ${o}px ${s}px ${a}`}).join(", ")}class yE extends r.A8{static type="bookmark";static props=r.aWX;static migrations=r.hNn;options={getDefaultDisplayValues:()=>({}),getCustomDisplayValues:()=>({})};canResize(e){return!1}hideSelectionBoundsFg(e){return!0}getText(e){return e.props.url}getAriaDescriptor(e){let t=e.props.assetId?this.editor.getAsset(e.props.assetId):null;if(t?.props.title)return r2(t.props.title)+(t.props.description?", "+t.props.description:"")}getDefaultProps(){return{url:"",w:300,h:320,assetId:null}}getGeometry(e){return new r.krb({width:e.props.w,height:L(this.editor,e),isFilled:!0})}component(e){let{assetId:t,url:n}=e.props,r=L(this.editor,e),i=this.editor.getShapePageTransform(e).rotation();return(0,d.jsx)(yI,{assetId:t,url:n,h:r,rotation:i})}getIndicatorPath(e){let t=new Path2D;return t.rect(0,0,e.props.w,L(this.editor,e)),t}onBeforeCreate(e){return O(this.editor,e)}onBeforeUpdate(e,t){if(e.props.url!==t.props.url)if(!r.T.linkUrl.isValid(t.props.url))return{...t,props:{...t.props,url:e.props.url}};else!function(e,t){var n,i;let o,{url:s}=t.props,a=r.Kx3.createId((0,r.xpx)(s));e.getAsset(a)?t.props.assetId!==a&&e.updateShapes([{id:t.id,type:t.type,props:{assetId:a}}]):(e.updateShapes([{id:t.id,type:t.type,props:{assetId:null}}]),n=e,i=t,(o=F.get(n))||(o=(0,r.sg1)(R,500),F.set(n,o)),o(n,i))}(this.editor,t);if(e.props.assetId!==t.props.assetId)return O(this.editor,t)}getInterpolatedProps(e,t,n){return{...n>.5?t.props:e.props,w:(0,r.CcK)(e.props.w,t.props.w,n),h:(0,r.CcK)(e.props.h,t.props.h,n)}}}function yI({assetId:e,rotation:t,url:n,h:i,showImageContainer:o=!0}){let s=(0,r.hGv)(),a=D(s,e,n),l=a?s.getAsset(a):null,c=!!(0,r.Jf5)()&&r.YZA.isSafari,h=function(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}(n),[u,p]=(0,f.useState)(!0),g=(0,f.useCallback)(e=>{s.inputs.getShiftKey()||s.markEventAsHandled(e)},[s]);return(0,d.jsx)(r.hDc,{children:(0,d.jsxs)("div",{className:ip("tl-bookmark__container",c&&"tl-bookmark__container--safariExport"),style:{boxShadow:c?void 0:yT(t),maxHeight:i},children:[o&&(!l||l.props.image)&&(0,d.jsxs)("div",{className:"tl-bookmark__image_container",children:[l?(0,d.jsx)("img",{className:"tl-bookmark__image",draggable:!1,referrerPolicy:"strict-origin-when-cross-origin",src:l?.props.image,alt:l?.props.title||""}):(0,d.jsx)("div",{className:"tl-bookmark__placeholder"}),l?.props.image&&(0,d.jsx)(yC,{url:n})]}),(0,d.jsxs)("div",{className:"tl-bookmark__copy_container",children:[l?.props.title?(0,d.jsx)("a",{className:"tl-bookmark__link",href:n||"",target:"_blank",rel:"noopener noreferrer",draggable:!1,onPointerDown:g,onPointerUp:g,children:(0,d.jsx)("h2",{className:"tl-bookmark__heading",children:r2(l.props.title)})}):null,l?.props.description&&l?.props.image?(0,d.jsx)("p",{className:"tl-bookmark__description",children:l.props.description}):null,(0,d.jsxs)("a",{className:"tl-bookmark__link",href:n||"",target:"_blank",rel:"noopener noreferrer",draggable:!1,onPointerDown:g,onPointerUp:g,children:[u&&l?.props.favicon?(0,d.jsx)("img",{className:"tl-bookmark__favicon",src:l?.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",onError:()=>p(!1),alt:`favicon of ${h}`}):(0,d.jsx)("div",{className:"tl-hyperlink__icon",style:{mask:`url("${yk}") center 100% / 100% no-repeat`,WebkitMask:`url("${yk}") center 100% / 100% no-repeat`}}),(0,d.jsx)("span",{children:h})]})]})]})})}function y_(e,t={}){gA(e,t);let n=gP,i=gm,o=gy,s=gb,a=gx,l=gw,d=gv,c=gS,h=gC,u=Array(n);for(let e=0;e<n;e++){let t=new r.l2P(s[e],a[e],l[e]),n=0===e?t:new r.l2P(i[e],o[e],l[e]);u[e]={point:n,input:t,pressure:d[e],distance:c[e],runningLength:h[e],radius:1}}return u}let yM=new Uint8Array(65536),yA=0,yj=new TextDecoder;function yO(e){if(yA+e>yM.length){let e=new Uint8Array(2*yM.length);e.set(yM),yM=e}}function yD(e){yO(e.length);for(let t=0;t<e.length;t++)yM[yA++]=e.charCodeAt(t)}function yL(e){yO(16),e<0&&(yM[yA++]=45,e=-e);let t=e/100|0,n=e-100*t;if(0===t){if(0===n){yM[yA++]=48;return}}else if(t<10)yM[yA++]=48+t;else if(t<100)yM[yA++]=48+(t/10|0),yM[yA++]=48+t%10;else{let e=yA,n=t;for(;n>0;)yM[yA++]=48+n%10,n=n/10|0;let r=e,i=yA-1;for(;r<i;){let e=yM[r];yM[r]=yM[i],yM[i]=e,r++,i--}}if(0!==n){yM[yA++]=46;let e=n%10;yM[yA++]=48+(n/10|0),0!==e&&(yM[yA++]=48+e)}}function yR(e,t){yL(e),yM[yA++]=44,yL(t),yM[yA++]=32}function yF(){let e=yj.decode(yM.subarray(0,yA));return yA=0,e}function yz(e){return Math.round(100*e)}function yN(e,t=!1){let n=e.length;if(n<2)return"";if(yA=0,2===n){let t=e[0].point,n=e[1].point,r=yz(t.x),i=yz(t.y);return yD("M"),yR(r,i),yD("l"),yR(yz(n.x)-r,yz(n.y)-i),yF()}let r=e[0].point,i=e[1].point,o=e[2].point,s=yz(i.x),a=yz(i.y),l=Math.round((r.x+i.x)*50),d=Math.round((r.y+i.y)*50),c=Math.round((i.x+o.x)*50),h=Math.round((i.y+o.y)*50),u=c,p=h;if(t)yD("M"),yR(l,d),yD("q"),yR(s-l,a-d),yR(c-l,h-d),yD("t");else{let e=yz(r.x),t=yz(r.y);yD("M"),yR(e,t),yD("q"),yR(s-e,a-t),yR(c-e,h-t),n>3&&yD("t")}for(let t=2,r=n-1;t<r;t++){let n=e[t].point,r=e[t+1].point,i=Math.round((n.x+r.x)*50),o=Math.round((n.y+r.y)*50);yR(i-u,o-p),u=i,p=o}let f=e[n-1].point;if(t){let e=Math.round((f.x+r.x)*50),t=Math.round((f.y+r.y)*50);yR(e-u,t-p),yR(l-e,d-t),yD("Z")}else yD("l"),yR(yz(f.x)-u,yz(f.y)-p);return yF()}function y$(e,t,n,r,i,o,s,a,l){let d=gm,c=gy,h=gk,u=n-e+1+ +!!i,p=0,f=0,g=t?gb[e]:d[e],m=t?gx[e]:c[e],y=h[e];for(;u-p>2;){let t=e+1+p,n=g-d[t],r=m-c[t];if(n*n+r*r<((y+h[t])/2*.5)**2)o=!0,s=d[t],a=c[t],p++;else break}let b=r?gb[n]:d[n],x=r?gx[n]:c[n],w=h[n];for(;u-p-f>2;){let e=i?n-f:n-1-f,t=b-d[e],r=x-c[e];if(t*t+r*r<((w+h[e])/2*.5)**2)f++;else break}let v=e+1+p;!function(e,t,n,r,i,o,s){gK(r-n+3);let a=gL,l=gR,d=gF,c=gz,h=gN,u=g$,p=gB,f=gH,g=gm,m=gy,y=gb,b=gx,x=gw,w=gC,v=gk;a[0]=t?y[e]:g[e],l[0]=t?b[e]:m[e],d[0]=x[e],c[0]=y[e],h[0]=b[e],u[0]=v[e],p[0]=w[e],f[0]=1;let S=1;for(let e=n;e<=r;e++)a[S]=g[e],l[S]=m[e],d[S]=x[e],c[S]=y[e],h[S]=b[e],u[S]=v[e],p[S]=w[e],f[S]=0,S++;s&&(f[S-1]=1),a[S]=o?y[i]:g[i],l[S]=o?b[i]:m[i],d[S]=x[i],c[S]=y[i],h[S]=b[i],u[S]=v[i],p[S]=w[i],f[S]=1,gU=S+1}(e,t,v,i?n-f:n-1-f,n,r,i&&0===f),yH(l,o,s,a)}function yB(e,t,n){yD("a"),yL(e),yD(","),yL(e),yD(" 0 0 1 "),yR(t,n)}function yH(e,t,n,r){let i=gU;if(0===i)return;if(1===i){var o,s,a;let e,t,n;return void(o=gL[0],s=gR[0],a=g$[0],e=yz(o),t=yz(s),n=yz(a),yD("M "),yL(e),yD(" "),yL(t),yD(" m -"),yL(n),yD(", 0 a "),yL(n),yD(","),yL(n),yD(" 0 1,1 "),yL(2*n),yD(",0 a "),yL(n),yD(","),yL(n),yD(" 0 1,1 -"),yL(2*n),yD(",0"))}g2(e,t,n,r);let l=gq,d=gX,c=gJ,h=gZ,u=yz(l[0]),p=yz(d[0]);yD("M"),yR(u,p),yD("t");let f=l[0],g=d[0];for(let e=1;e<gQ;e++){let t=l[e],n=d[e],r=Math.round((f+t)*50),i=Math.round((g+n)*50);yR(r-u,i-p),u=r,p=i,f=t,g=n}{let e=gL[i-1],t=gR[i-1],n=g$[i-1],r=gL[i-2]-e,o=gR[i-2]-t,s=Math.sqrt(r*r+o*o),a=-o/s*n,l=r/s*n,d=yz(e+a),c=yz(t+l),h=yz(e-a),f=yz(t-l);yR(d-u,c-p),yB(yz(n),h-d,f-c),yD("t"),u=h,p=f}f=c[g0-1],g=h[g0-1];for(let e=g0-2;e>=0;e--){let t=c[e],n=h[e],r=Math.round((f+t)*50),i=Math.round((g+n)*50);yR(r-u,i-p),u=r,p=i,f=t,g=n}{let e=gL[0],t=gR[0],n=g$[0],r=e-gL[1],i=t-gR[1],o=Math.sqrt(r*r+i*i),s=i/o*n,a=-r/o*n,l=yz(e+s),d=yz(t+a),c=yz(e-s),h=yz(t-a);yR(l-u,d-p),yB(yz(n),c-l,h-d),yD("Z")}}function yU(e,t,n){let i=[],o=[];e.forEach(e=>i.push(...r.K6A.decodePoints(e.path,e.dim))),t.forEach(e=>o.push(...r.K6A.decodePoints(e.path,e.dim)));let s=Math.max(i.length,o.length),a=[],l=[];for(let e=0;e<s;e++)a.push(i[e]||i[i.length-1]),l.push(o[e]||o[o.length-1]);let d=a.map((e,t)=>{let i=.5;return void 0!==l[t].z&&void 0!==e.z&&(i=(0,r.CcK)(e.z,l[t].z,n)),{x:(0,r.CcK)(e.x,l[t].x,n),y:(0,r.CcK)(e.y,l[t].y,n),z:i}});return[{type:"free",path:r.K6A.encodePoints(d)}]}class yK extends r.inY{static type="draw";static props=r.KBL;static migrations=r.deR;options={maxPointsPerShape:600,getDefaultDisplayValues(e,t,n,i){let{color:o,fill:s,size:a}=t.props,l=n.colors[i];return{strokeColor:(0,r.FHQ)(l,o,"solid"),strokeWidth:n.strokeWidth*G[a],fillColor:"none"===s?"transparent":"semi"===s?l.solid:(0,r.FHQ)(l,o,mH[s]),patternFillFallbackColor:(0,r.FHQ)(l,o,"semi")}},getCustomDisplayValues:()=>({})};hideResizeHandles(e){return yV(e)}hideRotateHandle(e){return yV(e)}hideSelectionBoundsFg(e){return yV(e)}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1,scaleX:1,scaleY:1}}getGeometry(e){let t=l(e.props.segments,e.props.scaleX,e.props.scaleY),n=(fb(this,e).strokeWidth+1)*e.props.scale;if(1===e.props.segments.length){let e=r.azJ.FromPoints(t);if(e.width<2*n&&e.height<2*n)return new r.PUi({x:-n,y:-n,radius:n,isFilled:!0})}let i=y_(t,a(e.props,n,e.props.isPen,!0)).map(e=>e.point);return e.props.isClosed&&i.length>2?new r.dxv({points:i,isFilled:"none"!==e.props.fill}):1===i.length?new r.PUi({x:-n,y:-n,radius:n,isFilled:!0}):new r.Hes({points:i})}component(e){let t=fb(this,e);return(0,d.jsx)(r.ULM,{children:(0,d.jsx)(yY,{shape:e,strokeColor:t.strokeColor,strokeWidth:t.strokeWidth,fillColor:t.fillColor,patternFillFallbackColor:t.patternFillFallbackColor})})}getIndicatorPath(e){let t=l(e.props.segments,e.props.scaleX,e.props.scaleY),n=(fb(this,e).strokeWidth+1)*e.props.scale,i=this.editor.getEfficientZoomLevel();i<.5&&i<1.5/n||e.props.isPen||"draw"!==e.props.dash||1!==t.length||(n+=(0,r.She)(e.id)()*(n/6));let o=e.props.isComplete||(0,r.HVh)(e.props.segments)?.type==="straight",s=y_(t,a(e.props,n,o,!0));return new Path2D(s.length>1?yN(s,e.props.isClosed):yW(t[0],n))}toSvg(e,t){t.addExportDef(mU(e.props.fill));let n=fb(this,e,t.colorMode),r=1/e.props.scale;return(0,d.jsx)("g",{transform:`scale(${r})`,children:(0,d.jsx)(yY,{shape:e,zoomOverride:1,strokeColor:n.strokeColor,strokeWidth:n.strokeWidth,fillColor:n.fillColor,patternFillFallbackColor:n.patternFillFallbackColor})})}getCanvasSvgDefs(){return[mW()]}onResize(e,t){let n=t.scaleX*e.props.scaleX,r=t.scaleY*e.props.scaleY;if(0!==n&&0!==r)return{props:{scaleX:n,scaleY:r}}}expandSelectionOutlinePx(e){let t="draw"===e.props.dash?1.6:1;return fb(this,e).strokeWidth*t/2*e.props.scale}getInterpolatedProps(e,t,n){return{...n>.5?t.props:e.props,segments:yU(e.props.segments,t.props.segments,n),scale:(0,r.CcK)(e.props.scale,t.props.scale,n)}}}function yW(e,t){let n=(t+1)*.5;return`M ${e.x} ${e.y} m -${n}, 0 a ${n},${n} 0 1,0 ${2*n},0 a ${n},${n} 0 1,0 -${2*n},0`}function yV(e){let t=e.props.segments[0];return 1===e.props.segments.length&&r.K6A.isSinglePoint(t.path,t.dim)}function yY({shape:e,zoomOverride:t,strokeColor:n,strokeWidth:i,fillColor:o,patternFillFallbackColor:s}){var c;let h=(0,r.hGv)(),u=l(e.props.segments,e.props.scaleX,e.props.scaleY),p=e.props.isComplete||(0,r.HVh)(e.props.segments)?.type==="straight",f=(i+1)*e.props.scale,g=(0,r.hau)("force solid",()=>{let e=t??h.getEfficientZoomLevel();return e<.5&&e<1.5/f},[h,f,t]),m=(0,r.hau)("dot adjustment",()=>(t??h.getEfficientZoomLevel())<.2?9:.1,[h,t]);g||e.props.isPen||"draw"!==e.props.dash||1!==u.length||(f+=(0,r.She)(e.id)()*(f/6));let y=a(e.props,f,p,g);if(!g&&"draw"===e.props.dash)return(0,d.jsxs)(d.Fragment,{children:[e.props.isClosed&&"none"!==e.props.fill&&u.length>1&&("pattern"===e.props.fill?(0,d.jsx)(m0,{d:yN(y_(u,y),e.props.isClosed),fillColor:o,patternFillFallbackColor:s,scale:e.props.scale}):(0,d.jsx)("path",{fill:o,d:yN(y_(u,y),e.props.isClosed)})),(0,d.jsx)("path",{d:function(e,t={}){let{start:n={},end:i={}}=t,{cap:o=!0}=n,{cap:s=!0}=i;return(0,r.vAR)(!n.taper&&!i.taper,"cap taper not supported here"),(0,r.vAR)(!n.easing&&!i.easing,"cap easing not supported here"),(0,r.vAR)(o&&s,"cap must be true"),gA(e,t),gO(t),yA=0,function(e){let t=gP;if(0===t)return;if(t<=2){gW(),yH(e,!1,0,0);return}let n=gm,r=gy,i=gk,o=0,s=!1,a=!1,l=0,d=0,c=n[1]-n[0],h=r[1]-r[0],u=Math.sqrt(c*c+h*h),p=c/u,f=h/u;for(let g=1;g<t-1;g++){u=Math.sqrt((c=n[g+1]-n[g])*c+(h=r[g+1]-r[g])*h);let t=c/u,m=h/u,y=p*t+f*m;if(p=t,f=m,y<-.8){y$(o,s,g,!0,!1,a,l,d,e),o=g,s=!0,a=!0,l=n[g],d=r[g];continue}if(y>.7)continue;let b=n[g]-n[g-1],x=r[g]-r[g-1],w=n[g+1]-n[g],v=r[g+1]-r[g],S=(i[g-1]+i[g]+i[g+1])/3;if((b*b+x*x+w*w+v*v)/(S*S)<1.5){y$(o,s,g,!1,!0,a,l,d,e),o=g,s=!1,a=!1;continue}}y$(o,s,t-1,!1,!1,a,l,d,e)}(t),yF()}(u,y),strokeLinecap:"round",fill:n})]});let b=y_(u,y),x=b.length<2,w=x||e.props.isClosed?e.props.fill:"none",v=x?yW(u[0],0):yN(b,e.props.isClosed&&"none"!==w);return(0,d.jsxs)(d.Fragment,{children:[x||!e.props.isClosed||"none"===w?null:"pattern"===w?(0,d.jsx)(m0,{d:v,fillColor:o,patternFillFallbackColor:s,scale:e.props.scale}):(0,d.jsx)("path",{fill:o,d:v}),"none"!==e.props.dash&&(0,d.jsx)("path",{d:v,strokeLinecap:"round",fill:x?n:"none",stroke:n,strokeWidth:f,strokeDasharray:x?"none":(c=f,({draw:"none",solid:"none",dotted:`${m} ${2*c}`,dashed:`${2*c} ${2*c}`,none:"none"})[e.props.dash]),strokeDashoffset:"0"})]})}let yG=(e,t)=>!!e.find(e=>{let n=new RegExp(e.split("*").map(e=>(function(e){if("string"!=typeof e)throw TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")})(e)).join(".+"));return t.match(n)}),yq=e=>Object.entries(e).filter(([e,t])=>t).map(([e])=>e).join(" ");class yX extends r.A8{static type="embed";static props=r.Pwo;static migrations=r.upp;options={embedDefinitions:o2,embedConfig:{},getDefaultDisplayValues:()=>({showShadow:!0}),getCustomDisplayValues:()=>({})};canEditWhileLocked(e){let t=this.getEmbedDefinition(e.props.url);return!t||(t.definition.canEditWhileLocked??!0)}static legacyEmbedDefinitions=null;static setEmbedDefinitions(e){yX.legacyEmbedDefinitions=e}getEmbedDefs(){return yX.legacyEmbedDefinitions??this.options.embedDefinitions}getEmbedDefinitions(){return this.getEmbedDefs()}getEmbedDefinition(e){var t=this.getEmbedDefs(),n=this.options.embedConfig;try{return function(e,t,n){let i=(0,r.yCG)(t);if(!i)return;let o=i.host.replace("www.","");for(let r of e)if(yG(r.hostnames,o)){let e=r.toEmbedUrl(t,n?.[r.type]);if(e)return{definition:r,embedUrl:e,url:t}}}(t,e,n)??function(e,t){let n=(0,r.yCG)(t);if(!n)return;let i=n.host.replace("www.","");for(let n of e)if(yG(n.hostnames,i)){let e=n.fromEmbedUrl(t);if(e)return{definition:n,url:e,embedUrl:t}}}(t,e)}catch{return}}async resolveAspectRatio(e){let{url:t}=e.props,n=this.getEmbedDefinition(t)?.definition;if(!n?.sizeToContentAspectRatio||!t)return;let r=await this.getContentAspectRatio(t);if(this.editor.isDisposed)return;let i=this.editor.getShape(e.id);if(!i||i.props.url!==t)return;let o=function({w:e,h:t,resolvedRatio:n}){if(!n||n<=0||.001>=Math.abs(e/t-n))return null;let r=e*t;return{w:Math.sqrt(r*n),h:Math.sqrt(r/n)}}({w:i.props.w,h:i.props.h,resolvedRatio:r});if(!o)return;let{minWidth:s,minHeight:a}=this.getResizeMinBounds(i),l=Math.max(1,s/o.w,a/o.h),d=o.w*l,c=o.h*l;this.editor.run(()=>{this.editor.resizeShape(i.id,{x:d/i.props.w,y:c/i.props.h},{isAspectRatioLocked:!1})},{history:"ignore"})}async getContentAspectRatio(e){try{let t=await this.editor.getAssetForExternalContent({type:"url",url:e});if(!t||"bookmark"!==t.type)return;let n=t.meta.imageWidth,r=t.meta.imageHeight;if("number"==typeof n&&"number"==typeof r&&n>0&&r>0)return n/r}catch{}}getText(e){return e.props.url}getAriaDescriptor(e){let t=this.getEmbedDefinition(e.props.url);return t?.definition.title}hideSelectionBoundsFg(e){return!this.canResize(e)}canEdit(e){return!0}canResize(e){return this.getEmbedDefinition(e.props.url)?.definition?.doesResize??!0}canEditInReadonly(e){return!0}getDefaultProps(){return{w:300,h:300,url:""}}getGeometry(e){return super.getGeometry(e)}isAspectRatioLocked(e){let t=this.getEmbedDefinition(e.props.url);return t?.definition.isAspectRatioLocked??!1}getResizeMinBounds(e){let t=this.getEmbedDefinition(e.props.url),n=t?.definition.minWidth??200,r=t?.definition.minHeight??200;if(this.isAspectRatioLocked(e)){let t=e.props.w/e.props.h;t>1?n*=t:r/=t}return{minWidth:n,minHeight:r}}onResize(e,t){return(0,r.mfH)(e,t,this.getResizeMinBounds(e))}component(e){let t=(0,r.Jf5)(),{w:n,h:i,url:o}=e.props,s=(0,r._As)(e.id),a=fb(this,e,(0,r.G67)()),l=this.getEmbedDefinition(o),c=(0,r.hau)("is hovering",()=>{let{editingShapeId:e,hoveredShapeId:t}=this.editor.getCurrentPageState();if(e&&t!==e){let t=this.editor.getShape(e);if(t&&this.editor.isShapeOfType(t,"embed"))return!0}return!1},[]),h=this.editor.getShapePageTransform(e).rotation();if(t)return(0,d.jsx)(r.hDc,{className:"tl-embed-container",id:e.id,children:(0,d.jsx)("div",{className:"tl-embed",style:{border:0,boxShadow:a.showShadow?yT(h):"none",borderRadius:l?.definition.overrideOutlineRadius??8,background:l?.definition.backgroundColor??"var(--tl-color-background)",width:n,height:i}})});let u=s||c;if("u">typeof window&&(window!==window.top||window.self!==window.parent)&&l?.definition.type==="tldraw")return null;let p=yq({...o3,...l?l.definition.overridePermissions??{}:o5});if(l?.definition.type==="github_gist"){let t=l.url.split("/").pop();if(!t)throw Error("No gist id!");let o=yq({...o3,...l?.definition?.overridePermissions??{},"allow-same-origin":!1});return(0,d.jsx)(r.hDc,{className:"tl-embed-container",id:e.id,children:(0,d.jsx)(yJ,{id:t,sandbox:o,width:(0,r.WMC)(n),height:(0,r.WMC)(i),isInteractive:u,pageRotation:h,showShadow:a.showShadow})})}let f=l?.embedUrl??o;return(0,d.jsx)(r.hDc,{className:"tl-embed-container",id:e.id,children:f?(0,d.jsx)("iframe",{className:"tl-embed",sandbox:p,src:f,width:(0,r.WMC)(n),height:(0,r.WMC)(i),draggable:!1,frameBorder:"0",referrerPolicy:"strict-origin-when-cross-origin",tabIndex:s?0:-1,allowFullScreen:!0,style:{border:0,width:"100%",height:"100%",pointerEvents:u?"auto":"none",zIndex:u?"":"-1",boxShadow:a.showShadow?yT(h):"none",borderRadius:l?.definition?.overrideOutlineRadius??8,background:l?.definition?.backgroundColor}}):(0,d.jsx)(yI,{url:o,h:i,rotation:h,assetId:null,showImageContainer:!1})})}getIndicatorPath(e){let t=new Path2D;return t.rect(0,0,e.props.w,e.props.h),t}getInterpolatedProps(e,t,n){return{...n>.5?t.props:e.props,w:(0,r.CcK)(e.props.w,t.props.w,n),h:(0,r.CcK)(e.props.h,t.props.h,n)}}}function yJ({id:e,sandbox:t,isInteractive:n,width:i,height:o,style:s,pageRotation:a,showShadow:l}){if(!e.match(/^[0-9a-f]+$/))throw Error("No gist id!");return(0,d.jsx)("iframe",{className:"tl-embed",sandbox:t,draggable:!1,width:(0,r.WMC)(i),height:(0,r.WMC)(o),frameBorder:"0",scrolling:"no",referrerPolicy:"strict-origin-when-cross-origin",tabIndex:n?0:-1,style:{...s,pointerEvents:n?"all":"none",zIndex:n?"":"-1",boxShadow:l?yT(a):"none"},srcDoc:`
98
- <html>
99
- <head>
100
- <base target="_blank">
101
- </head>
102
- <body>
103
- <script src=https://gist.github.com/${e}.js></script>
104
- <style type="text/css">
105
- * { margin: 0px; }
106
- table { height: 100%; background-color: red; }
107
- .gist { background-color: none; height: 100%; }
108
- .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
109
- </style>
110
- </body>
111
- </html>`})}function yZ(e,t){return e.match(/^\s*$/)?t:e}function yQ(e,t){return Math.floor((2/Math.PI*((0,r.rgm)(e.getShapePageTransform(t.id).rotation())+Math.PI/4)+4)%4)}let y0=new WeakMap;function y1(e,t,n){let i=y0.get(t.props);if(!i){let o=yZ(t.props.name,"Frame")+String.fromCharCode(8203),s=e.textMeasure.measureTextSpans(o,n),a=s[0],l=(0,r.HVh)(s);i=l.box.w+l.box.x-a.box.x,y0.set(t.props,i)}return new r.azJ(0,-n.height,i,n.height)}function y2(e,t){return{fontSize:12,fontFamily:t?"Arial":"Inter, sans-serif",textAlign:"start",width:e,height:24,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle",offsetY:-34,offsetX:0}}function y3(e,t,n){let i,o=n?"":"px",s=n?"":"deg";switch(t){case 0:i="";break;case 3:i=`translate(${(0,r.WMC)(e.props.w)}${o}, 0${o}) rotate(90${s})`;break;case 2:i=`translate(${(0,r.WMC)(e.props.w)}${o}, ${(0,r.WMC)(e.props.h)}${o}) rotate(180${s})`;break;case 1:i=`translate(0${o}, ${(0,r.WMC)(e.props.h)}${o}) rotate(270${s})`;break;default:throw Error("labelSide out of bounds")}return i}let y5=(0,f.forwardRef)(({id:e,name:t,isEditing:n},i)=>{let o=(0,r.hGv)(),s=sn(),a=(0,r.hau)("isCoarsePointer",()=>o.getInstanceState().isCoarsePointer,[o]),l=s<5&&a,c=(0,f.useRef)(!1),h=M(),u=(0,f.useCallback)(e=>{n&&o.markEventAsHandled(e)},[o,n]),p=(0,f.useCallback)(e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(o.markEventAsHandled(e),e.currentTarget.blur(),o.setEditingShape(null))},[o]),g=(0,f.useCallback)(t=>{let n=o.getShape(e);n&&n.props.name!==t&&o.updateShapes([{id:e,type:"frame",props:{name:t}}])},[e,o]),m=(0,f.useCallback)(e=>{g(e.currentTarget.value)},[g]),y=(0,f.useCallback)(e=>{g(e.currentTarget.value)},[g]);return(0,f.useEffect)(()=>{if(!n){c.current=!1;return}if(n&&l&&!c.current){c.current=!0;let t=o.getShape(e),n=t?.props.name??"",r=window.prompt(h("action.rename"),n);c.current=!1,null!==r&&g(r),o.setEditingShape(null)}},[n,l,e,h,g,o]),(0,d.jsxs)("div",{className:`tl-frame-label ${n&&!l?"tl-frame-label__editing":""}`,children:[(0,d.jsx)("input",{className:"tl-frame-name-input",ref:i,disabled:!n||l,readOnly:!n||l,style:{display:n?void 0:"none"},value:t,autoFocus:!l,onKeyDown:p,onBlur:m,onChange:y,onPointerDown:u,draggable:!1}),yZ(t,"Frame")+String.fromCharCode(8203)]})}),y6=(0,f.memo)(function({id:e,name:t,width:n,height:i,fill:o,stroke:s,color:a,offsetX:l,showColors:c}){let h=(0,r.hGv)(),{side:u,translation:p}=(0,r.hau)("shape rotation",()=>{let t=h.getShape(e);if(!t)return{side:0,translation:"translate(0, 0)"};let n=yQ(h,t);return{side:n,translation:y3(t,n,!1)}},[h,l,e]),g=(0,f.useRef)(null),m=(0,r._As)(e);return(0,f.useEffect)(()=>{let e=g.current;e&&m&&(e.focus(),e.select())},[g,m]),(0,d.jsx)("div",{className:"tl-frame-heading",style:{overflow:m?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${0===u||2===u?Math.ceil(n):Math.ceil(i)}px + ${c?"0px":"var(--tl-frame-offset-width)"})`,bottom:"100%",transform:`${p} scale(min(var(--tl-scale), 3.5)) translateX(${l}px)`},children:(0,d.jsx)("div",{className:"tl-frame-heading-hit-area",style:{color:a,backgroundColor:o,boxShadow:`inset 0px 0px 0px 1px ${s}`},children:(0,d.jsx)(y5,{ref:g,id:e,name:t,isEditing:m})})})});class y4 extends r.B$v{static type="frame";static props=r.X24;static migrations=r.SpZ;options={showColors:!1,resizeChildren:!1,getDefaultDisplayValues(e,t,n,i){let{color:o}=t.props,s=n.colors[i];return{fillColor:(0,r.FHQ)(s,"black","frameFill"),strokeColor:(0,r.FHQ)(s,"black","frameStroke"),showColorsFillColor:(0,r.FHQ)(s,o,"frameFill"),showColorsStrokeColor:(0,r.FHQ)(s,o,"frameStroke"),headingFillColor:s.negativeSpace,headingStrokeColor:s.negativeSpace,headingTextColor:(0,r.FHQ)(s,"black","frameText"),showColorsHeadingFillColor:(0,r.FHQ)(s,o,"frameHeadingFill"),showColorsHeadingStrokeColor:(0,r.FHQ)(s,o,"frameHeadingStroke"),showColorsHeadingTextColor:(0,r.FHQ)(s,o,"frameText")}},getCustomDisplayValues:()=>({})};static configure(e){let t=super.configure.call(this,e);return e.showColors&&(t.props={...t.props,color:r.ive}),t}canEdit(e,t){return"click-header"===t.type||"unknown"===t.type}canResize(e){return!0}canResizeChildren(e){return this.options.resizeChildren}isExportBoundsContainer(){return!0}getDefaultProps(){return{w:320,h:180,name:"",color:"black"}}getAriaDescriptor(e){return e.props.name}getGeometry(e){let t,n,{editor:i}=this,o=i.getEfficientZoomLevel(),s=yQ(i,e),a=s%2==1,l=a?e.props.h:e.props.w,d=y1(i,e,y2(l,!1)),c=this.options.showColors,h=12/o,u=d.w/o,p=d.h/o,f=(0,r.qE8)(u+h,32/o,l+(c?1:h)),g=(c?-1:-7)/o,m=4/o,y=a?p:f,b=a?f:p;switch(s){case 0:t=g,n=-(p+m);break;case 1:t=-(p+m),n=e.props.h-(g+f);break;case 2:t=e.props.w-(g+f),n=e.props.h+m;break;case 3:t=e.props.w+m,n=g}return new r.IQE({children:[new r.krb({width:e.props.w,height:e.props.h,isFilled:!1}),new r.krb({x:t,y:n,width:y,height:b,isFilled:!0,isLabel:!0,excludeFromShapeBounds:!0})]})}getText(e){return e.props.name}component(e){let t=fb(this,e,(0,r.G67)()),n=(0,r.hau)("is creating this shape",()=>{let t=this.editor.getStateDescendant("select.resizing");if(!t||!t.getIsActive())return!1;let n=t?.info;return!!n&&n.isCreating&&this.editor.getOnlySelectedShapeId()===e.id},[e.id]),i=this.options.showColors;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(r.ULM,{children:(0,d.jsx)("rect",{className:ip("tl-frame__body",{"tl-frame__creating":n}),fill:i?t.showColorsFillColor:t.fillColor,stroke:i?t.showColorsStrokeColor:t.strokeColor,style:{width:`calc(${e.props.w}px + 1px / var(--tl-zoom))`,height:`calc(${e.props.h}px + 1px / var(--tl-zoom))`,transform:"translate(calc(-0.5px / var(--tl-zoom)), calc(-0.5px / var(--tl-zoom)))"}})}),n?null:(0,d.jsx)(y6,{id:e.id,name:e.props.name,fill:i?t.showColorsHeadingFillColor:t.headingFillColor,stroke:i?t.showColorsHeadingStrokeColor:t.headingStrokeColor,color:i?t.showColorsHeadingTextColor:t.headingTextColor,width:e.props.w,height:e.props.h,offsetX:i?-1:-7,showColors:this.options.showColors})]})}toSvg(e,t){let n=fb(this,e,t.colorMode),i=yQ(this.editor,e),o=i%2==1?e.props.h:e.props.w,s=y3(e,i,!0),a=y2(o-12,!0),l=yZ(e.props.name,"Frame")+String.fromCharCode(8203),c=y1(this.editor,e,a),h=this.editor.textMeasure.measureTextSpans(l,a),u=function(e,t,n){let{padding:i=0}=n;if(0===t.length)return null;let o=r.azJ.From(t[0].box);for(let{box:e}of t)o.union(e);let s=i+(n.offsetX??0),a=(n.offsetY??0)+n.fontSize/2+("start"===n.verticalTextAlign?i:"end"===n.verticalTextAlign?n.height-i-o.height:(Math.ceil(n.height)-o.height)/2),l=null,c=[];for(let{text:e,box:n}of t)null!==l&&n.y>l&&c.push((0,d.jsx)("tspan",{alignmentBaseline:"mathematical",x:s,y:n.y+a,children:"\n"},c.length)),c.push((0,d.jsx)("tspan",{alignmentBaseline:"mathematical",x:n.x+s,y:n.y+a,unicodeBidi:"plaintext",children:e.replace(/\s/g,"\xa0")},c.length)),l=n.y;return(0,d.jsx)("text",{fontSize:n.fontSize,fontFamily:n.fontFamily,fontStyle:n.fontStyle,fontWeight:n.fontWeight,dominantBaseline:"mathematical",alignmentBaseline:"mathematical",stroke:n.stroke,strokeWidth:n.strokeWidth,fill:n.fill,children:c})}(this.editor,h,a),p=this.options.showColors,f=p?n.showColorsHeadingStrokeColor:n.headingStrokeColor,g=p?n.showColorsHeadingFillColor:n.headingFillColor,m=p?n.showColorsHeadingTextColor:n.headingTextColor;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{width:e.props.w,height:e.props.h,fill:p?n.showColorsFillColor:n.fillColor,stroke:p?n.showColorsStrokeColor:n.strokeColor,strokeWidth:1,x:0,rx:0,ry:0}),(0,d.jsxs)("g",{fill:m,transform:s,children:[(0,d.jsx)("rect",{x:c.x-6*!p,y:c.y-6,width:Math.min(o,c.width+12),height:c.height,fill:g,stroke:f,rx:4,ry:4}),(0,d.jsx)("g",{transform:`translate(${8*!!p}, 4)`,children:u})]})]})}getIndicatorPath(e){let t=new Path2D;return t.rect(0,0,e.props.w,e.props.h),t}getInterpolatedProps(e,t,n){return{...n>.5?t.props:e.props,w:(0,r.CcK)(e.props.w,t.props.w,n),h:(0,r.CcK)(e.props.h,t.props.h,n)}}onDoubleClickEdge(e,t){if("selection"!==t.target)return;let{handle:n}=t;if(!n)return;let i="left"===n||"right"===n,o="top"===n||"bottom"===n,s=this.editor.getSortedChildIdsForParent(e.id),a=(0,r.oE7)(s.map(e=>this.editor.getShape(e)));if(!a.length)return;let{dx:l,dy:d,w:c,h}=ih(a,this.editor,{padding:10});return this.editor.run(()=>{let e=s.map(e=>{let t=this.editor.getShape(e);return{id:t.id,type:t.type,x:i?t.x+l:t.x,y:o?t.y+d:t.y}});this.editor.updateShapes(e)}),{id:e.id,type:e.type,props:{w:i?c:e.props.w,h:o?h:e.props.h}}}onDoubleClickCorner(e){return iu(this.editor,e.id,{padding:10}),{id:e.id,type:e.type}}}function y8({shape:e,shouldScale:t,forceSolid:n,strokeColor:r,strokeWidth:i,fillColor:o,patternFillFallbackColor:s,customGeoTypes:a}){let l=t?e.props.scale:1,c=i*l,{dash:h,fill:u}=e.props,p=hL(e,i,a),f="draw"!==h||n?p.toD({onlyFilled:!0}):p.toDrawD({strokeWidth:c,randomSeed:e.id,passes:1,offset:0,onlyFilled:!0});return(0,d.jsxs)(d.Fragment,{children:["none"===u?null:"pattern"===u?(0,d.jsx)(m0,{d:f,fillColor:o,patternFillFallbackColor:s,scale:l}):(0,d.jsx)("path",{fill:o,d:f}),p.toSvg({style:h,strokeWidth:c,forceSolid:n,randomSeed:e.id,props:{fill:"none",stroke:r}})]})}let y9=Object.freeze({s:12,m:14,l:16,xl:20}),y7=Object.freeze({start:"start",middle:"center",end:"end","start-legacy":"start","end-legacy":"end","middle-legacy":"center"}),be=Object.freeze({start:"start",middle:"middle",end:"end"}),bt=Object.freeze({w:0,h:0}),bn=new Set(Object.keys(hj));class br extends r.A8{static type="geo";static props=r.X8F;static migrations=r.s4L;static configure(e){if(e.customGeoTypes){let t=[];for(let[n,r]of Object.entries(e.customGeoTypes))bn.has(n)||t.push([n,r]);t.length>0&&r.tg8.addValues(...t.map(([e])=>e));let n={...e,customGeoTypes:Object.fromEntries(t)};return super.configure(n)}return super.configure(e)}options={showTextOutline:!0,getDefaultDisplayValues(e,t,n,i){let{color:o,size:s,labelColor:a,fill:l,align:d,verticalAlign:c,font:h}=t.props,u=n.colors[i];return{strokeColor:(0,r.FHQ)(u,o,"solid"),strokeRoundness:n.strokeWidth*G[s]*2,strokeWidth:n.strokeWidth*G[s],fillColor:"none"===l?"transparent":"semi"===l?u.solid:(0,r.FHQ)(u,o,mH[l]),patternFillFallbackColor:(0,r.FHQ)(u,o,"semi"),labelColor:(0,r.FHQ)(u,a,"solid"),labelFontFamily:Q(n,h),labelFontSize:n.fontSize*X[s],labelMinWidth:y9[s],labelExtraPadding:n.strokeWidth*G[s],labelLineHeight:n.lineHeight,labelFontWeight:"normal",labelFontVariant:"normal",labelFontStyle:"normal",labelHorizontalAlign:y7[d],labelVerticalAlign:be[c],labelPadding:16,labelEdgeMargin:8,minSizeWithLabel:51}},getCustomDisplayValues:(e,t)=>({})};canEdit(e){return!0}getDefaultProps(){return{w:100,h:100,geo:"rectangle",dash:"draw",growY:0,url:"",scale:1,flipX:!1,flipY:!1,color:"black",labelColor:"black",fill:"none",size:"m",font:"draw",align:"middle",verticalAlign:"middle",richText:(0,r.TP3)("")}}getGeometry(e){let{props:t}=e,{scale:n}=t,i=fb(this,e),o=hL(e,i.strokeWidth,this.options.customGeoTypes).toGeometry(),s=Math.max(1,t.w),a=Math.max(1,t.h+t.growY),l=s/n,d=a/n,c=rG(t.richText),h=c?bt:this.getUnscaledLabelSize(e),u=Math.min(100,l/2),p=Math.min((0,r.OVI)(i.labelFontSize,i.labelLineHeight)+2*i.labelPadding,d/2),f=Math.min(l,Math.max(h.w,Math.min(u,Math.max(1,l-i.labelEdgeMargin)))),g=Math.min(d,Math.max(h.h,Math.min(p,Math.max(1,d-i.labelEdgeMargin)))),m="start"===i.labelHorizontalAlign?0:"end"===i.labelHorizontalAlign?l-f:(l-f)/2,y="start"===i.labelVerticalAlign?0:"end"===i.labelVerticalAlign?d-g:(d-g)/2;return new r.IQE({children:[o,new r.krb({x:m*n,y:y*n,width:f*n,height:g*n,isFilled:!0,isLabel:!0,excludeFromShapeBounds:!0,isEmptyLabel:c})]})}getHandleSnapGeometry(e){let t=this.getGeometry(e),n=t.children[0],r=hO(e.props.geo,this.options.customGeoTypes);if(!r)throw Error(`Unknown geo type: ${e.props.geo}`);return"blobby"===r.snapType?{outline:n,points:[t.bounds.center]}:{outline:n,points:[...n.vertices,t.bounds.center]}}getText(e){return rX(this.editor,e.props.richText)}getFontFaces(e){if(rG(e.props.richText))return r.Mlv;let t=rB(this.editor.getCurrentTheme(),e.props.font);return t||(0,r.EYW)(this.editor,e.props.richText,{family:`tldraw_${e.props.font}`,weight:"normal",style:"normal"})}component(e){let{id:t,type:n,props:i}=e,{editor:o}=this,s=(0,r.hau)("isGeoOnlySelected",()=>e.id===o.getOnlySelectedShapeId(),[o]),a=m3(o,e.id),l=m8(.25/e.props.scale),c=fb(this,e,(0,r.G67)()),{w:h,h:u,richText:p,url:f}=i,g=rG(p);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(r.ULM,{children:(0,d.jsx)(y8,{shape:e,shouldScale:!0,forceSolid:l,strokeColor:c.strokeColor,strokeWidth:c.strokeWidth,fillColor:c.fillColor,patternFillFallbackColor:c.patternFillFallbackColor,customGeoTypes:this.options.customGeoTypes})}),(a||!g)&&(0,d.jsx)(r.hDc,{style:{overflow:"hidden",width:h,height:u+i.growY},children:(0,d.jsx)(m6,{shapeId:t,type:n,fontFamily:c.labelFontFamily,fontSize:c.labelFontSize,lineHeight:c.labelLineHeight,padding:c.labelPadding,textAlign:c.labelHorizontalAlign,verticalAlign:c.labelVerticalAlign,richText:p,isSelected:s,labelColor:c.labelColor,wrap:!0,showTextOutline:this.options.showTextOutline,style:1!==e.props.scale?{transform:`scale(${e.props.scale})`,transformOrigin:"top left",width:e.props.w/e.props.scale,height:(e.props.h+i.growY)/e.props.scale}:void 0})}),f&&(0,d.jsx)(yC,{url:f})]})}getIndicatorPath(e){let t=this.editor.getEfficientZoomLevel()<.25/e.props.scale,{dash:n,scale:r}=e.props,i=fb(this,e);return hL(e,i.strokeWidth,this.options.customGeoTypes).toPath2D({style:"draw"===n?"draw":"solid",strokeWidth:1,passes:1,randomSeed:e.id,offset:0,roundness:i.strokeRoundness*r,forceSolid:t})}toSvg(e,t){let n,i=fb(this,e,t.colorMode),{richText:o,fill:s,scale:a,growY:l,w:c,h}=e.props,u={...e,props:{...e.props,w:c/a,h:(h+l)/a,growY:0}};if(t.addExportDef(mU(s)),!rG(o)){let e=new r.azJ(0,0,u.props.w,(h+l)/a);n=(0,d.jsx)(m4,{fontSize:i.labelFontSize,fontFamily:i.labelFontFamily,lineHeight:i.labelLineHeight,textAlign:i.labelHorizontalAlign,verticalAlign:i.labelVerticalAlign,labelColor:i.labelColor,padding:i.labelPadding,showTextOutline:this.options.showTextOutline,bounds:e,richText:o})}return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(y8,{shouldScale:!1,shape:u,forceSolid:!1,strokeColor:i.strokeColor,strokeWidth:i.strokeWidth,fillColor:i.fillColor,patternFillFallbackColor:i.patternFillFallbackColor,customGeoTypes:this.options.customGeoTypes}),n]})}getCanvasSvgDefs(){return[mW()]}onResize(e,{handle:t,newPoint:n,scaleX:i,scaleY:o,initialShape:s}){let a=this.getUnscaledGeoProps(s.props),l=a.w*i,d=(a.h+a.growY)*o,c=0,h=0,u=fb(this,e);if(!rG(e.props.richText)){var p;let t,n=Math.abs(l),r=Math.abs(d),i=(p=this.editor,bi.get(p))?.get(e.id);if(i)t=i;else{let i=Math.max(n,u.minSizeWithLabel),o=Math.max(r,u.minSizeWithLabel);t=this.measureUnscaledLabelSize({...e,props:{...e.props,w:i*e.props.scale,h:o*e.props.scale}})}let o=Math.max(n,t.w),s=Math.max(r,t.h);c=o-n,h=s-r,l=o*Math.sign(l||1),d=s*Math.sign(d||1)}let f=l*e.props.scale,g=d*e.props.scale,m=new r.l2P(0,0);i<0&&(m.x+=f),("left"===t||"top_left"===t||"bottom_left"===t)&&(m.x+=i<0?c:-c),o<0&&(m.y+=g),("top"===t||"top_left"===t||"top_right"===t)&&(m.y+=o<0?h:-h);let{x:y,y:b}=m.rot(e.rotation).add(n);return{x:y,y:b,props:{w:Math.max(Math.abs(f),1),h:Math.max(Math.abs(g),1),growY:0,...hA(s.props,{scaleX:i,scaleY:o})}}}onBeforeCreate(e){let{props:t}=e;if(rG(t.richText))return 0!==t.growY?{...e,props:{...t,growY:0}}:void 0;let n=t.h/t.scale,r=this.getUnscaledLabelSize(e).h,i=this.calculateGrowY(n,r,t.growY/t.scale);if(null!==i)return{...e,props:{...t,growY:i*t.scale}}}onBeforeUpdate(e,t){let{props:n}=e,{props:i}=t;if((0,r.n4T)(n.richText,i.richText)&&n.font===i.font&&n.size===i.size)return;let o=rG(n.richText),s=rG(i.richText);if(o&&s)return;if(s)return 0!==i.growY?{...t,props:{...i,growY:0}}:void 0;let a=this.getUnscaledGeoProps(n),l=this.getUnscaledLabelSize(t),{scale:d}=i;if(o&&!s){let e=this.expandShapeForFirstLabel(t,a.w,a.h,l);return{...t,props:{...i,w:e.w*d,h:e.h*d,growY:0}}}let c=t.props.w/d,h=l.w>c,u=this.calculateGrowY(a.h,l.h,a.growY);if(null!==u||h)return{...t,props:{...i,growY:(u??a.growY)*d,w:Math.max(c,l.w)*d}}}onDoubleClick(e){if(this.editor.inputs.getAltKey())switch(e.props.geo){case"rectangle":return{...e,props:{geo:"check-box"}};case"check-box":return{...e,props:{geo:"rectangle"}}}let t=hO(e.props.geo,this.options.customGeoTypes);if(t?.onDoubleClick){let n=t.onDoubleClick(e);if(n)return{...e,props:{...e.props,...n.props}}}}getInterpolatedProps(e,t,n){return{...n>.5?t.props:e.props,w:(0,r.CcK)(e.props.w,t.props.w,n),h:(0,r.CcK)(e.props.h,t.props.h,n),scale:(0,r.CcK)(e.props.scale,t.props.scale,n)}}getUnscaledGeoProps(e){let{w:t,h:n,growY:r,scale:i}=e;return{w:t/i,h:n/i,growY:r/i}}calculateGrowY(e,t,n){return t>e?t-e:n>0?0:null}expandShapeForFirstLabel(e,t,n,r){let i=Math.max(t,r.w),o=Math.max(n,r.h),s=fb(this,e);if(t<s.minSizeWithLabel&&n<s.minSizeWithLabel){let e=Math.max(i=Math.max(i,s.minSizeWithLabel),o=Math.max(o,s.minSizeWithLabel));i=e,o=e}return{w:i,h:o}}_labelSizesForGeoCache=new r.laH;getUnscaledLabelSize(e){var t;let n=(t=this.editor,bi.get(t))?.get(e.id);return n||this._labelSizesForGeoCache.get(e,()=>this.measureUnscaledLabelSize(e))}measureUnscaledLabelSize(e){let t=fb(this,e),n=rV(this.editor,e.props.richText),r=this.editor.textMeasure.measureHtml(n,{...Y,fontFamily:t.labelFontFamily,fontSize:t.labelFontSize,lineHeight:t.labelLineHeight,minWidth:t.labelMinWidth,maxWidth:Math.max(0,Math.ceil(t.labelMinWidth+t.labelExtraPadding),Math.ceil(e.props.w/e.props.scale-2*t.labelPadding))});return{w:r.w+2*t.labelPadding,h:r.h+2*t.labelPadding}}}let bi=new WeakMap;function bo(e,t){t?bi.set(e,t):bi.delete(e)}class bs extends r.inY{static type="highlight";static props=r.M60;static migrations=r.REO;options={maxPointsPerShape:600,getDefaultDisplayValues(e,t,n,i){let{color:o,size:s}=t.props,a=n.colors[i];return{strokeColor:!r.bGJ.forceSrgb.get()&&r.$Gt.get().supportsP3ColorSpace?(0,r.FHQ)(a,o,"highlightP3"):(0,r.FHQ)(a,o,"highlightSrgb"),strokeWidth:n.fontSize*q[s]*1.12,underlayOpacity:.82,overlayOpacity:.35}},getCustomDisplayValues:()=>({})};hideResizeHandles(e){return ba(e)}hideRotateHandle(e){return ba(e)}hideSelectionBoundsFg(e){return ba(e)}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1,scaleX:1,scaleY:1}}getGeometry(e){let t=fb(this,e).strokeWidth*e.props.scale;if(ba(e))return new r.PUi({x:-t/2,y:-t/2,radius:t/2,isFilled:!0});let n=l(e.props.segments,e.props.scaleX,e.props.scaleY),i=s({strokeWidth:t,showAsComplete:e.props.isComplete||(0,r.HVh)(e.props.segments)?.type==="straight"});return new r.dxv({points:g5(n,i),isFilled:!0})}component(e){let t=fb(this,e),n=t.strokeWidth*e.props.scale,i=bd(this.editor,n);return(0,d.jsx)(r.ULM,{children:(0,d.jsx)(bl,{shape:e,forceSolid:i,strokeWidth:n,opacity:t.overlayOpacity,strokeColor:t.strokeColor})})}backgroundComponent(e){let t=fb(this,e,(0,r.G67)()),n=t.strokeWidth*e.props.scale,i=bd(this.editor,n);return(0,d.jsx)(r.ULM,{children:(0,d.jsx)(bl,{shape:e,forceSolid:i,strokeWidth:n,opacity:t.underlayOpacity,strokeColor:t.strokeColor})})}getIndicatorPath(e){var t,n,i,o;let a,d,c,h,u=fb(this,e).strokeWidth*e.props.scale,p=this.editor.getEfficientZoomLevel(),{strokePoints:f,sw:g}=(t=e,n=u,i=u/p<1.5,a=l(t.props.segments,t.props.scaleX,t.props.scaleY),d=t.props.isComplete||(0,r.HVh)(t.props.segments)?.type==="straight",c=n,i||t.props.isPen||1!==a.length||(c+=(0,r.She)(t.id)()*(n/6)),{strokePoints:y_(a,s({strokeWidth:c,showAsComplete:d})),sw:c}),m=l(e.props.segments,e.props.scaleX,e.props.scaleY);return new Path2D(f.length<2?(o=m[0],h=g/2,`M ${o.x} ${o.y} m -${h}, 0 a ${h},${h} 0 1,0 ${2*h},0 a ${h},${h} 0 1,0 -${2*h},0`):yN(f,!1))}toSvg(e,t){let n=fb(this,e,t.colorMode),r=n.strokeWidth*e.props.scale,i=1/e.props.scale;return(0,d.jsx)("g",{transform:`scale(${i})`,children:(0,d.jsx)(bl,{forceSolid:r<1.5,strokeWidth:r,shape:e,opacity:n.overlayOpacity,strokeColor:n.strokeColor})})}toBackgroundSvg(e,t){let n=fb(this,e,t.colorMode),r=n.strokeWidth*e.props.scale,i=1/e.props.scale;return(0,d.jsx)("g",{transform:`scale(${i})`,children:(0,d.jsx)(bl,{forceSolid:r<1.5,strokeWidth:r,shape:e,opacity:n.underlayOpacity,strokeColor:n.strokeColor})})}onResize(e,t){let n=t.scaleX*e.props.scaleX,r=t.scaleY*e.props.scaleY;if(0!==n&&0!==r)return{props:{scaleX:n,scaleY:r}}}getInterpolatedProps(e,t,n){return{...n>.5?t.props:e.props,...t.props,segments:yU(e.props.segments,t.props.segments,n),scale:(0,r.CcK)(e.props.scale,t.props.scale,n)}}}function ba(e){let t=e.props.segments[0];return 1===e.props.segments.length&&r.K6A.isSinglePoint(t.path,t.dim)}function bl({strokeWidth:e,forceSolid:t,shape:n,opacity:i,strokeColor:o}){var a;let c=l(n.props.segments,n.props.scaleX,n.props.scaleY),h=e;t||n.props.isPen||1!==c.length||(h+=(0,r.She)(n.id)()*(h/6));let u=y_(c,s({strokeWidth:h,showAsComplete:n.props.isComplete||(0,r.HVh)(n.props.segments)?.type==="straight"})),p=u.length>1?yN(u,!1):(a=c[0],`M ${a.x} ${a.y} m -0.1, 0 a 0.1,0.1 0 1,0 0.2,0 a 0.1,0.1 0 1,0 -0.2,0`);return(0,d.jsx)("path",{d:p,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:o,strokeWidth:h,opacity:i})}function bd(e,t){return(0,r.hau)("forceSolid",()=>t/e.getEfficientZoomLevel()<1.5,[e,t])}function bc(){return(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 30 30",xmlns:"http://www.w3.org/2000/svg",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),(0,d.jsx)("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),(0,d.jsx)("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}function bh({shapeId:e,assetId:t,width:n}){let i=(0,r.hGv)(),o=(0,r.Jf5)(),s=(0,r.lsV)(),[a,l]=(0,f.useState)(()=>({asset:t?i.getAsset(t)??null:null,url:null})),d=(0,f.useRef)(!1),c=(0,f.useRef)(null),h=(0,f.useRef)(!1),u=(0,f.useRef)(null);return(0,f.useEffect)(()=>{let a,p=c.current!==t;if(c.current=t,p&&(h.current=!0),!t)return;let f=!1,g=(0,r.wvh)("update state",()=>{if(!o&&e&&i.getCulledShapes().has(e))return;let r=i.getAsset(t);if(!r)return void l(e=>({...e,asset:null,url:null}));if(!r.props.src){let e=i.getTemporaryAssetPreview(r.id);if(e){u.current!==e&&(u.current=e,l(t=>({...t,isPlaceholder:!0,url:e})),s());return}}let c=o?o.scale*(n/r.props.w):i.getEfficientZoomLevel()*(n/r.props.w);function p(e,t){f||u.current!==t&&(d.current=!0,u.current=t,l({asset:e,url:t}),s())}if(d.current&&!h.current){let e=0,n=()=>{++e>31.25&&(bu(i,t,c,o,e=>p(r,e)),a?.())};a?.(),i.on("tick",n),a=()=>i.off("tick",n)}else a?.(),bu(i,t,c,o,e=>p(r,e)),h.current=!1});return()=>{g(),a?.(),f=!0}},[i,t,o,s,e,n]),a}function bu(e,t,n,r,i){e.resolveAssetUrl(t,{screenScale:n,shouldResolveToOriginal:!!r&&null===r.pixelRatio,dpr:r?.pixelRatio??void 0}).then(e=>{i(e)})}let bp=["image/png","image/webp","image/gif","image/avif"];function bf(e,t,n){let r=e.alphaDataGetter();if(!r)return!1;let{nx:i,ny:o}=function(e,t,n){let r=Math.max(0,Math.min(1,(t.x-n.minX)/n.w)),i=Math.max(0,Math.min(1,(t.y-n.minY)/n.h));if(e.crop){let{topLeft:t,bottomRight:n}=e.crop;r=t.x+r*(n.x-t.x),i=t.y+i*(n.y-t.y)}return e.flipX&&(r=1-r),e.flipY&&(i=1-i),{nx:r,ny:i}}(e,t,n);return function(e,t,n,r=10){let i=Math.min(Math.floor(t*e.width),e.width-1),o=Math.min(Math.floor(n*e.height),e.height-1);return e.alphas[o*e.width+i]<r}(r,i,o)}let bg=new r.Qnm(100),bm=new Set,by=null;function bb(e){return bg.get(e)??null}function bx(e){return{alphaDataGetter:e.alphaDataGetter,crop:e.crop,flipX:e.flipX,flipY:e.flipY}}class bw extends r.krb{alphaConfig;constructor(e){super(e),this.alphaConfig=bx(e)}hitTestPoint(e,t=0,n=!1){return!!super.hitTestPoint(e,t,n)&&!bf(this.alphaConfig,e,this.bounds)}ignoreHit(e){return bf(this.alphaConfig,e,this.bounds)}}class bv extends r.pPP{alphaConfig;constructor(e){super(e),this.alphaConfig=bx(e)}hitTestPoint(e,t=0,n=!1){return!!super.hitTestPoint(e,t,n)&&!bf(this.alphaConfig,e,this.bounds)}ignoreHit(e){return bf(this.alphaConfig,e,this.bounds)}}async function bS(e){let t=await (0,r.hdJ)(e),n=await t.blob();return r.SmQ.blobToDataUrl(n)}let bC=new r.laH;class bk extends r.A8{static type="image";static props=r.lXb;static migrations=r.UcL;static handledAssetTypes=["image"];options={getDefaultDisplayValues:()=>({}),getCustomDisplayValues:()=>({})};isAspectRatioLocked(e){return!0}canCrop(e){return!0}isExportBoundsContainer(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,playing:!0,url:"",crop:null,flipX:!1,flipY:!1,altText:""}}createShapeForAsset(e,t){return{id:(0,r.n6Y)(),type:"image",x:t.x,y:t.y,opacity:1,props:{assetId:e.id,w:e.props.w,h:e.props.h}}}getGeometry(e){let t=e.props.assetId?this.editor.getAsset(e.props.assetId):null,n=t&&"mimeType"in t.props?t.props.mimeType:null,i=null!=n&&bp.includes(n),o=t&&"src"in t.props?t.props.src:null;return e.props.crop?.isCircle?i&&o?new bv({width:e.props.w,height:e.props.h,isFilled:!0,alphaDataGetter:()=>bb(o),crop:e.props.crop,flipX:e.props.flipX,flipY:e.props.flipY}):new r.pPP({width:e.props.w,height:e.props.h,isFilled:!0}):i&&o?new bw({width:e.props.w,height:e.props.h,isFilled:!0,alphaDataGetter:()=>bb(o),crop:e.props.crop,flipX:e.props.flipX,flipY:e.props.flipY}):new r.krb({width:e.props.w,height:e.props.h,isFilled:!0})}getAriaDescriptor(e){return e.props.altText}onResize(e,t){let n=(0,r.mfH)(e,t),{scaleX:i,scaleY:o}=t;if(n={...n,props:{...n.props,...hA(t.initialShape.props,t)}},!e.props.crop)return n;let s=i<0,a=o<0,{topLeft:l,bottomRight:d}=e.props.crop;return n.props.crop={topLeft:{x:s?1-d.x:l.x,y:a?1-d.y:l.y},bottomRight:{x:s?1-l.x:d.x,y:a?1-l.y:d.y},isCircle:e.props.crop.isCircle},n}component(e){return(0,d.jsx)(bP,{shape:e})}getIndicatorPath(e){if(this.editor.getCroppingShapeId()===e.id)return;let t=new Path2D;if(e.props.crop?.isCircle){let n=e.props.w/2,r=e.props.h/2;t.ellipse(n,r,n,r,0,0,2*Math.PI)}else t.rect(0,0,e.props.w,e.props.h);return t}async toSvg(e,t){let n=e.props;if(!n.assetId)return null;let r=this.editor.getAsset(n.assetId);if(!r)return null;let{w:i}=U(e.props,n.crop),o=await bC.get(r,async()=>{let e=await t.resolveAssetUrl(r.id,i);if(!e)return null;if((e.startsWith("blob:")||e.startsWith("http")||e.startsWith("/")||e.startsWith("./"))&&(e=await bS(e)||""),bT(this.editor,r.id)){let{promise:t}=bM(e);e=await t}return e});return o?(0,d.jsx)(b_,{shape:e,src:o}):null}onDoubleClickEdge(e){let t=e.props;if(!t||this.editor.getCroppingShapeId()!==e.id)return;let n=(0,r.pN9)(t.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},{w:i,h:o}=U(e.props,n),s=new r.l2P(n.topLeft.x*i,n.topLeft.y*o).rot(e.rotation),a={id:e.id,type:e.type,x:e.x-s.x,y:e.y-s.y,props:{crop:{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},w:i,h:o}};this.editor.updateShapes([a])}getInterpolatedProps(e,t,n){return{...n>.5?t.props:e.props,w:(0,r.CcK)(e.props.w,t.props.w,n),h:(0,r.CcK)(e.props.h,t.props.h,n),crop:function(e,t){if(null===e.props.crop&&null===t.props.crop)return null;let i=e.props.crop?.topLeft||{x:0,y:0},o=e.props.crop?.bottomRight||{x:1,y:1},s=t.props.crop?.topLeft||{x:0,y:0},a=t.props.crop?.bottomRight||{x:1,y:1};return{topLeft:{x:(0,r.CcK)(i.x,s.x,n),y:(0,r.CcK)(i.y,s.y,n)},bottomRight:{x:(0,r.CcK)(o.x,a.x,n),y:(0,r.CcK)(o.y,a.y,n)}}}(e,t)}}}let bP=(0,f.memo)(function({shape:e}){let t=(0,r.hGv)(),{w:n}=U(e.props,e.props.crop),{asset:i,url:o}=bh({shapeId:e.id,assetId:e.props.assetId,width:n}),s=g(),[a,l]=(0,f.useState)(""),[c,h]=(0,f.useState)(null),u=i&&bT(t,i.id);(0,f.useEffect)(()=>{if(o&&u){let{promise:e,cancel:t}=bM(o);return e.then(e=>{l(e),h(o)}),()=>{t()}}},[t,u,s,o]);let p=i&&"mimeType"in i.props?i.props.mimeType:null,m=null!=p&&bp.includes(p),y=i&&"src"in i.props?i.props.src:null;(0,f.useEffect)(()=>{o&&m&&function(e,t){if("u"<typeof OffscreenCanvas)return;let n=t??e;if(bg.has(n)||bm.has(n))return;bm.add(n);let i=(0,r._V3)();i.crossOrigin="anonymous",i.onload=async()=>{bm.delete(n);let{width:e,height:t}=i;if(0===e||0===t)return;let r=Math.min(1,256/Math.max(e,t)),o=Math.max(1,Math.round(e*r)),s=Math.max(1,Math.round(t*r)),a=null;try{a=await createImageBitmap(i,{resizeWidth:o,resizeHeight:s,resizeQuality:"low"})}catch{}let l=(by?(by.width=o,by.height=s):by=new OffscreenCanvas(o,s),by).getContext("2d");l&&(a?(l.drawImage(a,0,0),a.close()):l.drawImage(i,0,0,o,s),bg.set(n,{width:o,height:s,alphas:function(e,t,n){let r=new Uint32Array(e.getImageData(0,0,t,n).data.buffer),i=new Uint8Array(t*n);for(let e=0;e<i.length;e++)i[e]=r[e]>>>24;return i}(l,o,s)}))},i.onerror=()=>{bm.delete(n)},i.src=e}(o,y??void 0)},[o,m,y]);let b=(0,r.hau)("show crop preview",()=>e.id===t.getOnlySelectedShapeId()&&t.getCroppingShapeId()===e.id&&t.isIn("select.crop"),[t,e.id]),x=s&&(i?.props.mimeType?.includes("video")||u),w=bE(e),v=o===c?null:o,S=x?a:c;if(!o&&!i?.props.src)return(0,d.jsxs)(r.hDc,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h,color:"var(--tl-color-text-3)",backgroundColor:"var(--tl-color-low)",border:"1px solid var(--tl-color-low-border)"},children:[(0,d.jsx)("div",{className:ip("tl-image-container",i&&"tl-image-container-loading"),style:w,children:i?null:(0,d.jsx)(bc,{})}),"url"in e.props&&e.props.url&&(0,d.jsx)(yC,{url:e.props.url})]});let C=u?"anonymous":void 0;return(0,d.jsxs)(d.Fragment,{children:[b&&S&&(0,d.jsx)("div",{style:w,children:(0,d.jsx)("img",{className:"tl-image",style:{...bI(e),opacity:.1},crossOrigin:C,src:S,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,alt:""})}),(0,d.jsxs)(r.hDc,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h,borderRadius:e.props.crop?.isCircle?"50%":void 0},children:[(0,d.jsxs)("div",{className:ip("tl-image-container"),style:w,children:[S&&(0,d.jsx)("img",{className:"tl-image",style:bI(e),crossOrigin:C,src:S,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,alt:e.props.altText},S),v&&(0,d.jsx)("img",{className:"tl-image",style:bI(e),crossOrigin:C,src:v,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,alt:e.props.altText,onLoad:()=>h(v)},v)]}),e.props.url&&(0,d.jsx)(yC,{url:e.props.url})]})]})});function bT(e,t){let n=t?e.getAsset(t):void 0;return!!n&&("mimeType"in n.props&&r.K4L.isAnimatedImageType(n?.props.mimeType)||"isAnimated"in n.props&&n.props.isAnimated)}function bE(e){let t=e.props.crop,n=t?.topLeft;if(!n)return{width:e.props.w,height:e.props.h};let{w:r,h:i}=U(e.props,t),o=-n.x*r,s=-n.y*i;return{transform:`translate(${o}px, ${s}px)`,width:r,height:i}}function bI(e,t){let n,i,{flipX:o,flipY:s,crop:a}=e.props;if(!o&&!s)return;if(a){let{w:t,h:o}=U(e.props,a),s=a.bottomRight.x-a.topLeft.x,l=a.bottomRight.y-a.topLeft.y;n=(0,r.wwY)(a.topLeft.x,[0,1-s],[0,t-e.props.w]),i=(0,r.wwY)(a.topLeft.y,[0,1-l],[0,o-e.props.h])}let l=`scale(${o?-1:1}, ${s?-1:1})`,d=t?`translate(${(o?t.width:0)-(n||0)}px,
112
- ${(s?t.height:0)-(i||0)}px)`:"";return{transform:`${d} ${l}`,transformOrigin:t?"0 0":"center center"}}function b_({shape:e,src:t}){let n=(0,r.LsA)(),i=bE(e),o=e.props.crop;if(!i.transform||!o)return(0,d.jsx)("image",{href:t,width:e.props.w,height:e.props.h,"aria-label":e.props.altText,style:bI(e,{width:e.props.w,height:e.props.h})});{let{transform:s,width:a,height:l}=i,c=(o.bottomRight.x-o.topLeft.x)*a,h=(o.bottomRight.y-o.topLeft.y)*l,u=[new r.l2P(0,0),new r.l2P(c,0),new r.l2P(c,h),new r.l2P(0,h)],p=bI(e,{width:a,height:l});return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("defs",{children:(0,d.jsx)("clipPath",{id:n,children:o.isCircle?(0,d.jsx)("ellipse",{cx:c/2,cy:h/2,rx:c/2,ry:h/2}):(0,d.jsx)("polygon",{points:u.map(e=>`${e.x},${e.y}`).join(" ")})})}),(0,d.jsx)("g",{clipPath:`url(#${n})`,children:(0,d.jsx)("image",{href:t,width:a,height:l,"aria-label":e.props.altText,style:p?{...p}:{transform:s}})})]})}}function bM(e){let t=!1;return{promise:new Promise(n=>{let i=(0,r._V3)();i.onload=()=>{if(t)return;let e=(0,r.jLo)().createElement("canvas");e.width=i.width,e.height=i.height;let o=e.getContext("2d");o&&(o.drawImage(i,0,0),n(e.toDataURL()))},i.crossOrigin="anonymous",i.src=e}),cancel:()=>t=!0}}let bA=new r.laH;class bj extends r.inY{static type="line";static props=r.e9l;static migrations=r.bT0;options={getDefaultDisplayValues(e,t,n,i){let{color:o,size:s}=t.props;return{strokeColor:(0,r.FHQ)(n.colors[i],o,"solid"),strokeWidth:n.strokeWidth*G[s]}},getCustomDisplayValues:()=>({})};hideResizeHandles(e){return!0}hideRotateHandle(e){return!0}hideSelectionBoundsFg(e){return!0}hideSelectionBoundsBg(e){return!0}hideInMinimap(){return!0}getDefaultProps(){let[e,t]=(0,r.uud)(2);return{dash:"draw",size:"m",color:"black",spline:"line",points:{[e]:{id:e,index:e,x:0,y:0},[t]:{id:t,index:t,x:.1,y:.1}},scale:1}}getGeometry(e){let t=bL(e).toGeometry();return(0,r.vAR)(t instanceof u),t}getHandles(e){return bA.get(e.props,()=>{let t=this.getGeometry(e),n=bO(e),i=n.map(e=>({...e,id:e.id,type:"vertex",canSnap:!0}));for(let e=0;e<n.length-1;e++){let o=(0,r.HEt)(n[e].index,n[e+1].index),s=t.getSegments()[e].interpolateAlongEdge(.5);i.push({id:o,type:"create",index:o,x:s.x,y:s.y,canSnap:!0})}return i.sort(r.Ky)})}onResize(e,t){let{scaleX:n,scaleY:i}=t;return{props:{points:(0,r._Hz)(e.props.points,(e,{id:t,index:r,x:o,y:s})=>({id:t,index:r,x:o*n,y:s*i}))}}}onBeforeCreate(e){let{props:{points:t}}=e,n=Object.keys(t);if(n.length<2)return;let r=t[n[0]];if(n.every(e=>{let n=t[e];return n.x===r.x&&n.y===r.y})){let r=n[n.length-1];return t[r]={...t[r],x:t[r].x+.1,y:t[r].y+.1},e}}onHandleDrag(e,{handle:t}){let n=(0,r.Y8F)(new r.l2P(t.x,t.y),this.editor);return{...e,props:{...e.props,points:{...e.props.points,[t.id]:{id:t.id,index:t.index,x:n.x,y:n.y}}}}}onHandleDragStart(e,{handle:t}){if("create"===t.type)return{...e,props:{...e.props,points:{...e.props.points,[t.index]:{id:t.index,index:t.index,x:t.x,y:t.y}}}}}component(e){let t=fb(this,e,(0,r.G67)());return(0,d.jsx)(r.ULM,{style:{minWidth:50,minHeight:50},children:(0,d.jsx)(bR,{shape:e,strokeColor:t.strokeColor,strokeWidth:t.strokeWidth})})}getIndicatorPath(e){let t=fb(this,e).strokeWidth*e.props.scale,n=bL(e),{dash:r}=e.props;return n.toPath2D({style:"draw"===r?"draw":"solid",strokeWidth:1,passes:1,randomSeed:e.id,offset:0,roundness:2*t})}toSvg(e,t){let n=fb(this,e,t.colorMode);return(0,d.jsx)(bR,{shouldScale:!0,shape:e,strokeColor:n.strokeColor,strokeWidth:n.strokeWidth})}getHandleSnapGeometry(e){let t=bO(e);return{points:t,getSelfSnapPoints:n=>{let i=this.getHandles(e).filter(e=>"vertex"===e.type).findIndex(e=>e.id===n.id);return t.filter((e,t)=>Math.abs(t-i)>1).map(r.l2P.From)},getSelfSnapOutline:t=>{let n=this.getHandles(e).filter(e=>"vertex"===e.type).findIndex(e=>e.id===t.id),i=this.getGeometry(e).getSegments().filter((e,t)=>t!==n-1&&t!==n);return i.length?new r.IQE({children:i}):null}}}getInterpolatedProps(e,t,n){let i=bO(e),o=bO(t),s=[],a=[],l=r.as9;if(i.length>o.length)for(let e=0;e<i.length;e++)s[e]={...i[e]},void 0===o[e]?a[e]={...o[o.length-1],id:l}:a[e]={...o[e],id:l},l=(0,r.AQy)(l);else if(o.length>i.length)for(let e=0;e<o.length;e++)a[e]={...o[e]},void 0===i[e]?s[e]={...i[i.length-1],id:l}:s[e]={...i[e],id:l},l=(0,r.AQy)(l);else for(let e=0;e<o.length;e++)s[e]=i[e],a[e]=o[e];return{...n>.5?t.props:e.props,points:Object.fromEntries(s.map((e,t)=>{let i=a[t];return[e.id,{...e,x:(0,r.CcK)(e.x,i.x,n),y:(0,r.CcK)(e.y,i.y,n)}]})),scale:(0,r.CcK)(e.props.scale,t.props.scale,n)}}}function bO(e){let t=Object.values(e.props.points).sort(r.Ky);return t.filter((e,n)=>0===n||e.index!==t[n-1].index)}let bD=new r.laH;function bL(e){return bD.get(e,()=>{let t=bO(e).map(r.l2P.From);switch(e.props.spline){case"cubic":return c.cubicSplineThroughPoints(t,{endOffsets:0});case"line":return c.lineThroughPoints(t,{endOffsets:0})}})}function bR({shape:e,shouldScale:t=!1,forceSolid:n=!1,strokeColor:r,strokeWidth:i}){let o=bL(e),{dash:s}=e.props,a=1/e.props.scale,l=i*e.props.scale;return o.toSvg({style:s,strokeWidth:l,forceSolid:n,randomSeed:e.id,props:{transform:`scale(${t?a:1})`,stroke:r,fill:"none"}})}let bF=Object.freeze({start:"start",middle:"center",end:"end","start-legacy":"start","end-legacy":"end","middle-legacy":"center"}),bz=Object.freeze({start:"start",middle:"middle",end:"end"});class bN extends r.inY{static type="note";static props=r.SWg;static migrations=r.fq3;options={resizeMode:"none",getDefaultDisplayValues(e,t,n,i){let{color:o,labelColor:s,font:a,size:l,align:d,verticalAlign:c}=t.props,h=n.colors[i];return{noteWidth:200,noteHeight:200,noteBackgroundColor:(0,r.FHQ)(h,o,"noteFill"),borderColor:h.noteBorder,borderWidth:2,labelColor:"black"===s?(0,r.FHQ)(h,o,"noteText"):(0,r.FHQ)(h,s,"fill"),labelFontFamily:Q(n,a),labelFontSize:n.fontSize*X[l],labelLineHeight:n.lineHeight,labelFontWeight:Y.fontWeight,labelFontVariant:Y.fontVariant,labelFontStyle:Y.fontStyle,labelPadding:16,labelHorizontalAlign:bF[d],labelVerticalAlign:bz[c]}},getCustomDisplayValues:()=>({})};canEdit(e){return!0}hideResizeHandles(e){let{resizeMode:t}=this.options;switch(t){case"none":return!0;case"scale":return!1;default:throw(0,r.h6G)(t)}}isAspectRatioLocked(e){return"scale"===this.options.resizeMode}hideSelectionBoundsFg(e){return!1}getDefaultProps(){return{color:"black",richText:(0,r.TP3)(""),size:"m",font:"draw",align:"middle",verticalAlign:"middle",labelColor:"black",growY:0,fontSizeAdjustment:1,url:"",scale:1,textLastEditedBy:null}}getGeometry(e){let{labelHeight:t,labelWidth:n}=this.getLabelSize(e),{scale:i}=e.props,o=fb(this,e),s=t*i,a=n*i,l=o.noteWidth*i,d=b$(e,o.noteHeight);return new r.IQE({children:[new r.krb({width:l,height:d,isFilled:!0}),new r.krb({x:"start"===o.labelHorizontalAlign?0:"end"===o.labelHorizontalAlign?l-a:(l-a)/2,y:"start"===o.labelVerticalAlign?0:"end"===o.labelVerticalAlign?d-s:(d-s)/2,width:a,height:s,isFilled:!0,isLabel:!0,excludeFromShapeBounds:!0})]})}getHandles(e){let{scale:t}=e.props;if(this.editor.getInstanceState().isCoarsePointer)return[];let n=this.editor.getEfficientZoomLevel();if(n*t<.25)return[];let r=fb(this,e),i=b$(e,r.noteHeight),o=r.noteWidth*t,s=0/n*t;return n*t<.5?[{id:"bottom",index:"a3",type:"clone",x:o/2,y:i+s}]:[{id:"top",index:"a1",type:"clone",x:o/2,y:-s},{id:"right",index:"a2",type:"clone",x:o+s,y:i/2},{id:"bottom",index:"a3",type:"clone",x:o/2,y:i+s},{id:"left",index:"a4",type:"clone",x:-s,y:i/2}]}onResize(e,t){let{resizeMode:n}=this.options;switch(n){case"none":return;case"scale":return(0,r.d5$)(e,t);default:throw(0,r.h6G)(n)}}getText(e){return rX(this.editor,e.props.richText)}getReferencedUserIds(e){return e.props.textLastEditedBy?[e.props.textLastEditedBy]:[]}getFontFaces(e){let t=rG(e.props.richText)?[]:(0,r.EYW)(this.editor,e.props.richText,{family:`tldraw_${e.props.font}`,weight:"normal",style:"normal"});if(e.props.textLastEditedBy&&!rG(e.props.richText))return[...t,rN.tldraw_sans.normal.normal];let n=rB(this.editor.getCurrentTheme(),e.props.font);return n?[...n,...t]:t.length?t:r.Mlv}component(e){var t,n,i,o;let s,a,l,c,h,u,p,g,m,{id:b,type:x,props:w}=e,{scale:v,richText:S,fontSizeAdjustment:C,textLastEditedBy:k}=w,P=(t=b,s=(0,r.hGv)(),a=(0,f.useContext)(I),(0,f.useCallback)(e=>{let n=s.getShape(t);if(!n)return;let i="Tab"===e.key,o=(e.metaKey||e.ctrlKey)&&"Enter"===e.key;if(i&&rq(s))return void e.preventDefault();if(i||o){var l;e.preventDefault();let d=s.getShapePageTransform(t),c=d.rotation(),h=!!(a?.dir==="rtl"||(l=rX(s,n.props.richText),rQ.test(l))),u=fb(s.getShapeUtil(n),n),p=(i?u.noteWidth+s.options.adjacentShapeMargin:u.noteHeight+s.options.adjacentShapeMargin+(o&&!e.shiftKey?n.props.growY:0))*n.props.scale,f=new r.l2P(i?e.shiftKey!=h?-1:1:0,o?e.shiftKey?-1:1:0).mul(p).add(new r.l2P(u.noteWidth/2,u.noteHeight/2).mul(n.props.scale)).rot(c).add(d.point()),g=mM(s,{shape:n,center:f,pageRotation:c,noteWidth:u.noteWidth,noteHeight:u.noteHeight});g&&y(s,g,{selectAll:!0})}},[t,s,a?.dir])),T=(0,r.hau)("shape rotation",()=>this.editor.getShapePageTransform(b)?.rotation()??0,[this.editor]),E=fb(this,e,(0,r.G67)()),_=E.noteWidth*v,M=b$(e,E.noteHeight),A=m8(.25/v),j=e.id===this.editor.getOnlySelectedShapeId(),O=m3(this.editor,e.id),D=rG(S),L=(0,r.hau)("attribution",()=>{if(!k||D)return null;let e=this.editor.getAttributionDisplayName(k);return e?{short:e.split(" ")[0],full:e}:null},[k,D,this.editor]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{id:b,className:"tl-note__container",style:{width:_,height:M,backgroundColor:E.noteBackgroundColor,borderBottom:A?`${E.borderWidth*v}px solid ${E.borderColor}`:"none",boxShadow:A?"none":(n=e.id,i=T,o=v,c=Math.abs((l=(0,r.She)(n))())+.5,h=Math.cos(i),u=5*o,p=4*o,g=6*o,m=7*o,`0px ${Math.max(0,u-c)}px ${u}px -${u}px rgba(15, 23, 31, .6),
113
- 0px ${(p+c*m)*Math.max(0,h)}px ${g+c*m}px -${p+c*g}px rgba(15, 23, 31, ${(.3+.1*c).toFixed(2)}),
114
- 0px ${48*o}px ${10*o}px -${10*o}px inset rgba(15, 23, 44, ${((.022+.005*l())*((1+h)/2)).toFixed(2)})`)},children:[L&&(0,d.jsx)(oa,{content:L.full,side:"bottom",children:(0,d.jsx)("div",{className:"tl-note__attribution",style:{"--note-attribution-scale":v,fontSize:11*v,color:E.labelColor,opacity:.6},children:L.short})}),(j||O||!D)&&(0,d.jsx)(m6,{shapeId:b,type:x,fontFamily:E.labelFontFamily,fontSize:(C??1)*E.labelFontSize,lineHeight:E.labelLineHeight,textAlign:E.labelHorizontalAlign,verticalAlign:E.labelVerticalAlign,richText:S,isSelected:j,labelColor:E.labelColor,wrap:!0,padding:E.labelPadding,hasCustomTabBehavior:!0,showTextOutline:!1,onKeyDown:P,style:1!==v?{transform:`scale(${v})`,transformOrigin:"top left",width:E.noteWidth,height:E.noteHeight+e.props.growY}:void 0})]}),"url"in e.props&&e.props.url&&(0,d.jsx)(yC,{url:e.props.url})]})}getIndicatorPath(e){let{scale:t}=e.props,n=fb(this,e),r=new Path2D;return r.rect(0,0,n.noteWidth*t,b$(e,n.noteHeight)),r}toSvg(e,t){let n=fb(this,e,t.colorMode),i=new r.azJ(0,0,n.noteWidth,n.noteHeight+e.props.growY),o=`note-shadow-${e.id.replace(/:/g,"_")}`;t.addExportDef({key:o,getElement:()=>(0,d.jsxs)("filter",{id:o,x:"-10%",y:"-10%",width:"130%",height:"150%",children:[(0,d.jsx)("feMorphology",{in:"SourceAlpha",operator:"erode",radius:"3",result:"erode1"}),(0,d.jsx)("feGaussianBlur",{in:"erode1",stdDeviation:"3",result:"blur1"}),(0,d.jsx)("feOffset",{in:"blur1",dy:"3",result:"offsetBlur1"}),(0,d.jsx)("feComponentTransfer",{in:"offsetBlur1",result:"shadow1",children:(0,d.jsx)("feFuncA",{type:"linear",slope:"0.5"})}),(0,d.jsx)("feMorphology",{in:"SourceAlpha",operator:"erode",radius:"10",result:"erode2"}),(0,d.jsx)("feGaussianBlur",{in:"erode2",stdDeviation:"6",result:"blur2"}),(0,d.jsx)("feOffset",{in:"blur2",dy:"6",result:"offsetBlur2"}),(0,d.jsx)("feComponentTransfer",{in:"offsetBlur2",result:"shadow2",children:(0,d.jsx)("feFuncA",{type:"linear",slope:"0.5"})}),(0,d.jsxs)("feMerge",{children:[(0,d.jsx)("feMergeNode",{in:"shadow1"}),(0,d.jsx)("feMergeNode",{in:"shadow2"}),(0,d.jsx)("feMergeNode",{in:"SourceGraphic"})]})]})});let{textLastEditedBy:s}=e.props,a=s&&!rG(e.props.richText)?this.editor.getAttributionDisplayName(s)?.split(" ")[0]??null:null;return(0,d.jsxs)(d.Fragment,{children:[t.isDarkMode?null:(0,d.jsx)("rect",{rx:1,width:n.noteWidth,height:i.h,fill:n.noteBackgroundColor,filter:`url(#${o})`}),(0,d.jsx)("rect",{rx:1,width:n.noteWidth,height:i.h,fill:n.noteBackgroundColor}),(0,d.jsx)(m4,{fontSize:(e.props.fontSizeAdjustment??1)*n.labelFontSize,fontFamily:n.labelFontFamily,lineHeight:n.labelLineHeight,textAlign:n.labelHorizontalAlign,verticalAlign:n.labelVerticalAlign,richText:e.props.richText,labelColor:n.labelColor,bounds:i,padding:n.labelPadding,showTextOutline:!1}),a&&(0,d.jsx)("foreignObject",{x:0,y:0,width:n.noteWidth,height:i.h,className:"tl-export-embed-styles",children:(0,d.jsx)("div",{style:{position:"relative",width:"100%",height:"100%"},children:(0,d.jsx)("div",{className:"tl-note__attribution",style:{fontSize:11,color:n.labelColor,opacity:.6},children:a})})})]})}onBeforeCreate(e){return this.getNoteSizeAdjustments(e)}onBeforeDuplicate(e,t){if(!rG(t.props.richText))return{...t,props:{...t.props,textLastEditedBy:this.editor.getAttributionUserId()}}}onBeforeUpdate(e,t){let n=!(0,r.n4T)(e.props.richText,t.props.richText);if(!n&&e.props.font===t.props.font&&e.props.size===t.props.size)return;let i=t;return n&&(i=rG(t.props.richText)?{...i,props:{...i.props,textLastEditedBy:null}}:{...i,props:{...i.props,textLastEditedBy:this.editor.getAttributionUserId()}}),this.getNoteSizeAdjustments(i)??(n?i:void 0)}getInterpolatedProps(e,t,n){return{...n>.5?t.props:e.props,scale:(0,r.CcK)(e.props.scale,t.props.scale,n)}}getNoteSizeAdjustments(e){let t=fb(this,e),{labelHeight:n,fontSizeAdjustment:r}=this.getLabelSize(e),i=Math.max(0,n-t.noteHeight);if(i!==e.props.growY||r!==e.props.fontSizeAdjustment)return{...e,props:{...e.props,growY:i,fontSizeAdjustment:r}}}_labelSizesForNoteCache=new r.laH;getLabelSize(e){return this._labelSizesForNoteCache.get(e,()=>this.measureNoteLabelSize(e))}measureNoteLabelSize(e){let t=fb(this,e),{richText:n}=e.props;if(rG(n))return{labelHeight:(0,r.OVI)(t.labelFontSize,t.labelLineHeight)+2*t.labelPadding,labelWidth:100,fontSizeAdjustment:1};let i=t.labelFontSize,o=i,s=0,a=t.noteHeight,l=t.noteWidth;do{o=Math.min(i,i-s);let e=rV(this.editor,n),r=this.editor.textMeasure.measureHtml(e,{...Y,lineHeight:t.labelLineHeight,fontFamily:t.labelFontFamily,fontSize:o,maxWidth:t.noteWidth-2*t.labelPadding-1,disableOverflowWrapBreaking:!0,measureScrollWidth:!0});if(a=r.h+2*t.labelPadding,l=r.w+2*t.labelPadding,o<=14){let e=rV(this.editor,n),r=this.editor.textMeasure.measureHtml(e,{...Y,lineHeight:t.labelLineHeight,fontFamily:t.labelFontFamily,fontSize:o,maxWidth:t.noteWidth-2*t.labelPadding-1});a=r.h+2*t.labelPadding,l=r.w+2*t.labelPadding;break}if(r.scrollWidth.toFixed(0)===r.w.toFixed(0))break}while(s++<50);return{labelHeight:a,labelWidth:l,fontSizeAdjustment:o===i?1:o/i}}}function b$(e,t){return(t+e.props.growY)*e.props.scale}let bB=(0,r.uYT)("text size",(e,t)=>{e.fonts.trackFontsForShape(t);let n=fb(e.getShapeUtil(t),t);return bU(e,t.props,n)},{areRecordsEqual:(e,t)=>e.props===t.props});class bH extends r.inY{static type="text";static props=r.xjg;static migrations=r.E4k;options={extraArrowHorizontalPadding:10,showTextOutline:!0,getDefaultDisplayValues(e,t,n,i){let{color:o,font:s,size:a}=t.props;return{color:(0,r.FHQ)(n.colors[i],o,"solid"),fontFamily:Q(n,s),fontSize:n.fontSize*q[a],lineHeight:n.lineHeight,fontWeight:Y.fontWeight,fontStyle:Y.fontStyle,fontVariant:Y.fontVariant}},getCustomDisplayValues:()=>({})};getDefaultProps(){return{color:"black",size:"m",w:8,font:"draw",textAlign:"start",autoSize:!0,scale:1,richText:(0,r.TP3)("")}}getMinDimensions(e){return bB.get(this.editor,e.id)}getGeometry(e,t){let{scale:n}=e.props,{width:i,height:o}=this.getMinDimensions(e),s=t?.context??"none";return new r.krb({x:("@tldraw/arrow-without-arrowhead"===s?-this.options.extraArrowHorizontalPadding:0)*n,width:(i+("@tldraw/arrow-without-arrowhead"===s?2*this.options.extraArrowHorizontalPadding:0))*n,height:o*n,isFilled:!0,isLabel:!0})}getFontFaces(e){let t=rB(this.editor.getCurrentTheme(),e.props.font);return t||(0,r.EYW)(this.editor,e.props.richText,{family:`tldraw_${e.props.font}`,weight:"normal",style:"normal"})}getText(e){return rX(this.editor,e.props.richText)}canEdit(e){return!0}isAspectRatioLocked(e){return!0}component(e){var t;let n,{id:i,props:{richText:o,scale:s,textAlign:a}}=e,{width:l,height:c}=this.getMinDimensions(e),h=e.id===this.editor.getOnlySelectedShapeId(),u=fb(this,e,(0,r.G67)()),p=(t=i,n=(0,r.hGv)(),(0,f.useCallback)(e=>{n.getEditingShapeId()===t&&"Enter"===e.key&&(e.ctrlKey||e.metaKey)&&n.complete()},[n,t]));return(0,d.jsx)(m6,{shapeId:i,classNamePrefix:"tl-text-shape",type:"text",fontFamily:u.fontFamily,fontSize:u.fontSize,lineHeight:u.lineHeight,textAlign:"middle"===a?"center":a,verticalAlign:"middle",richText:o,labelColor:u.color,isSelected:h,textWidth:l,textHeight:c,showTextOutline:this.options.showTextOutline,style:{transform:`scale(${s})`,transformOrigin:"top left"},wrap:!0,onKeyDown:p})}getIndicatorPath(e){if(e.props.autoSize&&this.editor.getEditingShapeId()===e.id)return;let t=this.editor.getShapeGeometry(e).bounds,n=new Path2D;return n.rect(0,0,t.width,t.height),n}toSvg(e,t){let n=this.editor.getShapeGeometry(e).bounds,i=n.width/(e.props.scale??1),o=n.height/(e.props.scale??1),s=fb(this,e,t.colorMode),a=Math.ceil(.3*s.fontSize),l=new r.azJ(-a,-a,i+2*a,o+2*a);return(0,d.jsx)(m4,{fontSize:s.fontSize,fontFamily:s.fontFamily,lineHeight:s.lineHeight,textAlign:"middle"===e.props.textAlign?"center":e.props.textAlign,verticalAlign:"middle",richText:e.props.richText,labelColor:s.color,bounds:l,padding:a,showTextOutline:this.options.showTextOutline})}onResize(e,t){let{newPoint:n,initialBounds:i,initialShape:o,scaleX:s,handle:a}=t;if("scale_shape"===t.mode||"right"!==a&&"left"!==a)return{id:e.id,type:e.type,...(0,r.d5$)(e,t)};{let t=Math.max(1,Math.abs(i.width*s)),{x:a,y:l}=s<0?r.l2P.Sub(n,r.l2P.FromAngle(e.rotation).mul(t)):n;return{id:e.id,type:e.type,x:a,y:l,props:{w:t/o.props.scale,autoSize:!1}}}}onEditEnd(e){0===rX(this.editor,e.props.richText).trimEnd().length&&this.editor.deleteShapes([e.id])}onBeforeUpdate(e,t){let n;if(!t.props.autoSize)return;let i=e.props.size!==t.props.size||e.props.textAlign!==t.props.textAlign||e.props.font!==t.props.font||1!==e.props.scale&&1===t.props.scale,o=!(0,r.n4T)(e.props.richText,t.props.richText);if(!i&&!o)return;let s=this.getMinDimensions(e),a=fb(this,t),l=bU(this.editor,t.props,a),d=s.width*e.props.scale,c=s.height*e.props.scale,h=l.width*t.props.scale,u=l.height*t.props.scale;switch(t.props.textAlign){case"middle":n=new r.l2P((h-d)/2,o?0:(u-c)/2);break;case"end":n=new r.l2P(h-d,o?0:(u-c)/2);break;default:if(o)break;n=new r.l2P(0,(u-c)/2)}if(!n)return{...t,props:{...t.props,w:h}};{n.rot(t.rotation);let{x:e,y:r}=t;return{...t,x:e-n.x,y:r-n.y,props:{...t.props,w:h}}}}}function bU(e,t,n){let{richText:r,w:i}=t,o=t.autoSize?null:Math.max(16,Math.floor(i)),s=rV(e,r),a=e.textMeasure.measureHtml(s,{lineHeight:n.lineHeight,fontWeight:n.fontWeight,fontStyle:n.fontStyle,padding:"0px",fontFamily:n.fontFamily,fontSize:n.fontSize,maxWidth:o});return{width:o??Math.max(16,a.w+1),height:Math.max(n.fontSize,a.h)}}let bK=new r.laH;class bW extends r.A8{static type="video";static props=r.ZMy;static migrations=r.w9f;static handledAssetTypes=["video"];options={autoplay:!0,getDefaultDisplayValues:()=>({}),getCustomDisplayValues:()=>({})};canEdit(e){return!0}isAspectRatioLocked(e){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,autoplay:this.options.autoplay,url:"",altText:"",time:0,playing:!0}}createShapeForAsset(e,t){return{id:(0,r.n6Y)(),type:"video",x:t.x,y:t.y,opacity:1,props:{assetId:e.id,w:e.props.w,h:e.props.h}}}getAriaDescriptor(e){return e.props.altText}component(e){return(0,d.jsx)(bV,{shape:e})}getIndicatorPath(e){let t=new Path2D;return t.rect(0,0,e.props.w,e.props.h),t}async toSvg(e,t){let n=e.props;if(!n.assetId)return null;let i=this.editor.getAsset(n.assetId);if(!i)return null;let o=await bK.get(i,async()=>{let e=await t.resolveAssetUrl(i.id,n.w);if(!e)return null;let o=await r.K4L.loadVideo(e,this.editor.getContainerDocument());return await r.K4L.getVideoFrameAsDataUrl(o,0)});return o?(0,d.jsx)("image",{href:o,width:n.w,height:n.h,"aria-label":e.props.altText}):null}}let bV=(0,f.memo)(function({shape:e}){let t=(0,r.hGv)(),n=t.getShapeGeometry(e).bounds.w*t.getEfficientZoomLevel()>=110,i=(0,r._As)(e.id),o=g(),{Spinner:s}=(0,r.BSi)(),{asset:a,url:l}=bh({shapeId:e.id,assetId:e.props.assetId,width:e.props.w}),c=(0,f.useRef)(null),[h,u]=(0,f.useState)(!1),p=(0,f.useCallback)(e=>{e.currentTarget&&u(!0)},[]),[m,y]=(0,f.useState)(!1);return(0,f.useEffect)(()=>{let e=c.current?.ownerDocument??t.getContainerDocument(),n=()=>y(e.fullscreenElement===c.current);return e.addEventListener("fullscreenchange",n),()=>e.removeEventListener("fullscreenchange",n)}),(0,f.useEffect)(()=>{let e=c.current;e&&i&&e.ownerDocument.activeElement!==e&&e.focus()},[i,h]),(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(r.hDc,{id:e.id,style:{color:"var(--tl-color-text-3)",backgroundColor:a?"transparent":"var(--tl-color-low)",border:a?"none":"1px solid var(--tl-color-low-border)"},children:(0,d.jsx)("div",{className:"tl-counter-scaled",children:(0,d.jsx)("div",{className:"tl-video-container",children:a?s&&!a.props.src?(0,d.jsx)(s,{}):l?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("video",{ref:c,style:i?{pointerEvents:"all"}:h?void 0:{display:"none"},className:ip("tl-video",`tl-video-shape-${e.id.split(":")[1]}`,{"tl-video-is-fullscreen":m}),width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:e.props.autoplay&&!o,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:i&&n,onLoadedData:p,hidden:!h,"aria-label":e.props.altText,children:(0,d.jsx)("source",{src:l})},l),!h&&s&&(0,d.jsx)(s,{})]}):null:(0,d.jsx)(bc,{})})})}),"url"in e.props&&e.props.url&&(0,d.jsx)(yC,{url:e.props.url})]})}),bY=[bH,yE,yK,br,bN,bj,y4,yb,bs,yX,bk,bW];class bG extends r.YM5{static id="erasing";static trackPerformance=!0;info={};scribbleId="id";markId="";excludedShapeIds=new Set;_erasingShapeIds=[];onEnter(e){this.markId=this.editor.markHistoryStoppingPoint("erase scribble begin"),this.info=e;let t=this.editor.inputs.getOriginPagePoint();this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(e=>{if(this.editor.isShapeOrAncestorLocked(e))return!0;if(this.editor.isShapeOfType(e,"group")||this.editor.isShapeFrameLike(e)){let n=this.editor.getPointInShapeSpace(e,t);return this.editor.getShapeGeometry(e).bounds.containsPoint(n)}return!1}).map(e=>e.id)),this._erasingShapeIds=this.editor.getShapesAtPoint(t).filter(e=>!this.excludedShapeIds.has(e.id)).map(e=>e.id),this.editor.setErasingShapes([...new Set([...this.editor.getErasingShapeIds(),...this._erasingShapeIds])]);let n=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=n.id,this.update()}pushPointToScribble(){let{x:e,y:t}=this.editor.inputs.getCurrentPagePoint();this.editor.scribbles.addPoint(this.scribbleId,e,t)}onExit(){this.editor.setErasingShapes([]),this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.update()}onPointerUp(e){this.complete(e)}onCancel(){this.cancel()}onComplete(){this.complete()}update(){let{editor:e,excludedShapeIds:t}=this,n=e.getErasingShapeIds(),i=e.inputs.getCurrentPagePoint(),o=e.inputs.getPreviousPagePoint();this.pushPointToScribble();let s=new Set(n),a=this.editor.getHitTestMargin(),l=r.azJ.FromPoints([o,i]).expandBy(a),d=e.getShapeIdsInsideBounds(l);if(0===d.size)return void e.setErasingShapes(Array.from(s));for(let n of e.getCurrentPageRenderingShapesSorted().filter(e=>d.has(e.id))){if(e.isShapeOfType(n,"group"))continue;let l=e.getShapeMask(n.id);if(l&&!(0,r.s3y)(i,l))continue;let d=e.getShapeGeometry(n),c=e.getShapePageTransform(n);if(!d||!c)continue;let h=c.clone().invert(),u=h.applyToPoint(o),p=h.applyToPoint(i),{bounds:f}=d;if(!(f.minX-a>Math.max(u.x,p.x)||f.minY-a>Math.max(u.y,p.y)||f.maxX+a<Math.min(u.x,p.x)||f.maxY+a<Math.min(u.y,p.y))){if(d.hitTestLineSegment(u,p,a)){let r=e.getOutermostSelectableShape(n);t.has(r.id)?s.add(e.getOutermostSelectableShape(n,e=>!t.has(e.id)).id):s.add(r.id)}this._erasingShapeIds=[...s]}}this.editor.setErasingShapes(this._erasingShapeIds.filter(e=>!t.has(e)))}complete(e){let{editor:t}=this;t.deleteShapes(t.getCurrentPageState().erasingShapeIds),this.parent.transition("idle",e),this._erasingShapeIds=[]}cancel(){let{editor:e}=this;e.bailToMark(this.markId),this.parent.transition("idle",this.info)}}class bq extends r.YM5{static id="idle";onEnter(e){(e?.accelKey??this.editor.inputs.getAccelKey())||this.parent.maybeReturnToOriginatingTool()}onKeyUp(e){(0,r.gu7)(e)||this.parent.maybeReturnToOriginatingTool()}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){let e=this.parent.info.onInteractionEnd;this.editor.setCurrentTool(e??"select")}}class bX extends r.YM5{static id="pointing";onEnter(e){let t=e.accelKey,n=this.editor.getCurrentPageRenderingShapesSorted(),r=this.editor.inputs.getCurrentPagePoint(),i=new Set,o=i.size;for(let e=n.length,s=e-1;s>=0;s--){let e=n[s];if(!(this.editor.isShapeOrAncestorLocked(e)||this.editor.isShapeOfType(e,"group"))&&this.editor.isPointInShape(e,r,{hitInside:!1,margin:this.editor.getHitTestMargin()})){let n=this.editor.getOutermostSelectableShape(e);if(this.editor.isShapeFrameLike(n)&&i.size>o||(i.add(n.id),t))break}}this.editor.setErasingShapes([...i])}onLongPress(e){e.accelKey||this.startErasing(e)}onExit(e,t){"erasing"!==t&&this.editor.setErasingShapes([])}onPointerMove(e){this.editor.inputs.getIsDragging()&&this.startErasing(e)}onPointerUp(e){this.complete(e)}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}startErasing(e){this.parent.transition("erasing",e)}complete(e){let t=this.editor.getErasingShapeIds();t.length&&(this.editor.markHistoryStoppingPoint("erase end"),this.editor.deleteShapes(t)),this.parent.transition("idle",e)}cancel(){this.parent.transition("idle")}}class bJ extends r.YM5{static id="eraser";static initial="idle";static isLockable=!1;static children(){return[bq,bX,bG]}info={};onEnter(e={}){this.info=e,e.onInteractionEnd&&this.setCurrentToolIdMask(e.onInteractionEnd),this.editor.setCursor({type:"cross",rotation:0})}onExit(){this.setCurrentToolIdMask(void 0),this.info={}}maybeReturnToOriginatingTool(){let{onInteractionEnd:e}=this.info;e&&this.editor.setCurrentTool(e)}}class bZ extends r.YM5{static id="dragging";static trackPerformance=!0;initialCamera=new r.l2P;onEnter(){this.initialCamera=r.l2P.From(this.editor.getCamera()),this.update()}onPointerMove(){this.update()}onPointerDown(){this.parent.transition("idle")}onPointerUp(){this.complete()}onInterrupt(){this.parent.transition("idle")}onCancel(){this.parent.transition("idle")}onComplete(){this.complete()}update(){let{initialCamera:e,editor:t}=this,n=t.inputs.getCurrentScreenPoint(),i=t.inputs.getOriginScreenPoint(),o=r.l2P.Sub(n,i).div(t.getZoomLevel());0!==o.len2()&&t.setCamera(e.clone().add(o))}complete(){let{editor:e}=this,t=e.inputs.getPointerVelocity(),n=Math.min(t.len(),2);n>.1&&this.editor.slideCamera({speed:n,direction:{x:t.x,y:t.y,z:0}}),this.parent.transition("idle")}}class bQ extends r.YM5{static id="idle";onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}}class b0 extends r.YM5{static id="one_finger_zooming";anchorScreenPoint=new r.l2P;initialCamera=new r.l2P;initialZoom=1;originScreenY=0;onEnter(e){let t=this.editor.getCamera();this.initialCamera=r.l2P.From(t),this.initialZoom=t.z,this.anchorScreenPoint=this.editor.inputs.getOriginScreenPoint().clone(),this.originScreenY=this.editor.inputs.getCurrentScreenPoint().y,this.editor.setCursor({type:"grab",rotation:0})}onPointerMove(e){this.editor.menus.clearOpenMenus();let t=this.editor.inputs.getCurrentScreenPoint().y,n=Math.pow(2,-((this.originScreenY-t)*1)/200),i=this.clampZoom(this.initialZoom*n),{x:o,y:s}=this.initialCamera,{x:a,y:l}=this.anchorScreenPoint;this.editor.setCamera(new r.l2P(o+a/i-a/this.initialZoom,s+l/i-l/this.initialZoom,i),{immediate:!0})}onPointerUp(e){this.complete()}onCancel(){this.parent.transition("idle")}onInterrupt(){this.parent.transition("idle")}complete(){let e=this.editor.inputs.getPointerVelocity(),t=Math.min(e.len(),2);t>.1&&this.editor.slideCamera({speed:t,direction:{x:0,y:0,z:.01*Math.sign(e.y)}}),this.parent.transition("idle")}clampZoom(e){let{zoomSteps:t}=this.editor.getCameraOptions(),n=this.editor.getBaseZoom(),i=t[0]*n,o=(0,r.HVh)(t)*n;return(0,r.qE8)(e,i,o)}}class b1 extends r.YM5{static id="pointing";onEnter(){this.editor.stopCameraAnimation(),this.editor.setCursor({type:"grabbing",rotation:0})}onLongPress(){this.startDragging()}onPointerMove(){this.editor.inputs.getIsDragging()&&this.startDragging()}startDragging(){this.parent.transition("dragging")}onPointerUp(){this.complete()}onCancel(){this.complete()}onComplete(){this.complete()}onInterrupt(){this.complete()}complete(){this.parent.transition("idle")}}class b2 extends r.YM5{static id="hand";static initial="idle";static isLockable=!1;static children(){return[bQ,b1,bZ,b0]}onDoubleClick(e){switch(e.phase){case"settle-down":this.editor.getInstanceState().isCoarsePointer&&this.transition("one_finger_zooming",e);break;case"settle-up":{let e=this.editor.inputs.getCurrentScreenPoint();this.editor.zoomIn(e,{animation:{duration:220,easing:r.Z4H.easeOutQuint}})}}}}class b3 extends r.YM5{static id="idle";onPointerDown(){let e=this.parent.getSessionId(),t=this.editor.scribbles.addScribbleToSession(e,{color:"laser",opacity:.7,size:4,taper:!1});this.parent.transition("lasering",{sessionId:e,scribbleId:t.id})}}class b5 extends r.YM5{static id="lasering";static trackPerformance=!0;scribbleId="";sessionId="";onEnter(e){this.sessionId=e.sessionId,this.scribbleId=e.scribbleId,this.pushPointToScribble()}onPointerMove(){this.pushPointToScribble()}pushPointToScribble(){let{x:e,y:t}=this.editor.inputs.getCurrentPagePoint();this.editor.scribbles.addPointToSession(this.sessionId,this.scribbleId,e,t)}onTick(){this.editor.scribbles.extendSession(this.sessionId)}onPointerUp(){this.complete()}onCancel(){this.onComplete()}onComplete(){this.complete()}complete(){this.editor.scribbles.complete(this.scribbleId),this.parent.transition("idle")}}class b6 extends r.YM5{static id="laser";static initial="idle";static children(){return[b3,b5]}static isLockable=!1;sessionId=null;onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onExit(){this.sessionId=null}onCancel(){this.sessionId&&this.editor.scribbles.isSessionActive(this.sessionId)?(this.editor.scribbles.clearSession(this.sessionId),this.sessionId=null,this.transition("idle")):this.editor.setCurrentTool("select")}getSessionId(){return this.sessionId&&this.editor.scribbles.isSessionActive(this.sessionId)||(this.sessionId=this.editor.scribbles.startSession({selfConsume:!1,idleTimeoutMs:this.editor.options.laserDelayMs,fadeMode:"grouped",fadeEasing:"ease-in"})),this.sessionId}}class b4 extends r.YM5{static id="brushing";static trackPerformance=!0;info={};initialSelectedShapeIds=[];excludedShapeIds=new Set;isWrapMode=!1;viewportDidChange=!1;cleanupViewportChangeReactor(){}onEnter(e){let{editor:t}=this,n=t.inputs.getAltKey();this.isWrapMode=t.user.getIsWrapMode(),this.viewportDidChange=!1;let i=!0;if(this.cleanupViewportChangeReactor=(0,r.wvh)("viewport change while brushing",()=>{t.getViewportPageBounds(),i||this.viewportDidChange||(this.viewportDidChange=!0)}),n)return void this.parent.transition("scribble_brushing",e);let o=t.options.selectLockedShapes;this.excludedShapeIds=new Set(t.getCurrentPageShapes().filter(e=>t.isShapeOfType(e,"group")||!o&&t.isShapeOrAncestorLocked(e)).map(e=>e.id)),this.info=e,this.initialSelectedShapeIds=t.getSelectedShapeIds().slice(),this.hitTestShapes(),i=!1}onExit(){this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null}),this.cleanupViewportChangeReactor()}onTick({elapsed:e}){let{editor:t}=this;!t.inputs.getIsDragging()||t.inputs.getIsPanning()||t.edgeScrollManager.updateEdgeScrolling(e)}onPointerMove(){this.hitTestShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(e){this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",e)}onKeyDown(e){this.editor.inputs.getAltKey()?this.parent.transition("scribble_brushing",e):this.hitTestShapes()}onKeyUp(){this.hitTestShapes()}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){let e,t,n,i,o,s,{editor:a,excludedShapeIds:l,isWrapMode:d}=this,c=a.inputs.getOriginPagePoint(),h=a.inputs.getCurrentPagePoint(),u=a.inputs.getShiftKey(),p=a.inputs.getCtrlKey(),f=new Set(u?this.initialSelectedShapeIds:[]),g=d?!p:p,m=r.azJ.FromPoints([c,h]),{corners:y}=m,b=a.getViewportPageBounds().contains(m),x=a.getCurrentPageId(),w=a.getShapeIdsInsideBounds(m);if(0===w.size){let e=a.getInstanceState().brush;e&&m.equals(e)||a.updateInstanceState({brush:{...m.toJson()}});let t=a.getSelectedShapeIds();(t.length!==f.size||t.some(e=>!f.has(e)))&&a.setSelectedShapes(Array.from(f));return}let v=(b&&!this.viewportDidChange?a.getCurrentPageRenderingShapesSorted():a.getCurrentPageShapesSorted()).filter(e=>w.has(e.id));for(let r=0,d=v.length;r<d;r++){if(n=v[r],!(l.has(n.id)||f.has(n.id))&&(i=a.getShapePageBounds(n))){if(m.contains(i)){this.handleHit(n,h,x,f,y);continue}if(!(g||a.isShapeFrameLike(n))&&m.collides(i)){if(!(o=a.getShapePageTransform(n)))continue;s=o.clone().invert().applyToPoints(y);let r=a.getShapeGeometry(n);for(let i=0;i<4;i++)if(e=s[i],t=s[(i+1)%4],r.hitTestLineSegment(e,t,0)){this.handleHit(n,h,x,f,y);break}}}}let S=a.getInstanceState().brush;S&&m.equals(S)||a.updateInstanceState({brush:{...m.toJson()}});let C=a.getSelectedShapeIds();(C.length!==f.size||C.some(e=>!f.has(e)))&&a.setSelectedShapes(Array.from(f))}onInterrupt(){this.editor.updateInstanceState({brush:null})}handleHit(e,t,n,i,o){if(e.parentId===n)return void i.add(e.id);let s=this.editor.getOutermostSelectableShape(e),a=this.editor.getShapeMask(s.id);(!a||(0,r.Rx2)(a,o)||(0,r.s3y)(t,a))&&i.add(s.id)}}let b8={bottom:"ns-resize",top:"ns-resize",left:"ew-resize",right:"ew-resize",bottom_left:"nesw-resize",bottom_right:"nwse-resize",top_left:"nwse-resize",top_right:"nesw-resize",bottom_left_rotate:"swne-rotate",bottom_right_rotate:"senw-rotate",top_left_rotate:"nwse-rotate",top_right_rotate:"nesw-rotate",mobile_rotate:"grabbing"};class b9 extends r.YM5{static id="pointing_resize_handle";info={};updateCursor(){let e=b8[this.info.handle];this.editor.setCursor({type:e,rotation:this.editor.getSelectionRotation()})}onEnter(e){this.info=e,"string"==typeof e.onInteractionEnd&&this.parent.setCurrentToolIdMask(e.onInteractionEnd),this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0)}onPointerMove(){this.editor.inputs.getIsDragging()&&this.startResizing()}onLongPress(){this.startResizing()}startResizing(){this.editor.getIsReadonly()||this.parent.transition("resizing",this.info)}onPointerUp(){this.complete()}onDoubleClick(e){this.editor.inputs.getShiftKey()||"down"!==e.phase||e.ctrlKey||e.shiftKey||(this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent(e))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}complete(){let{onInteractionEnd:e}=this.info;e?"string"==typeof e?this.editor.setCurrentTool(e,{}):e():this.parent.transition("idle")}cancel(){let{onInteractionEnd:e}=this.info;e?"string"==typeof e?this.editor.setCurrentTool(e,{}):e():this.parent.transition("idle")}}class b7 extends r.YM5{static id="cropping";static trackPerformance=!0;info={};markId="";snapshot={};onEnter(e){this.info=e,"string"==typeof e.onInteractionEnd&&this.parent.setCurrentToolIdMask(e.onInteractionEnd),this.markId=this.editor.markHistoryStoppingPoint("cropping"),this.snapshot=this.createSnapshot(),this.updateShapes()}onPointerMove(){this.updateShapes()}onKeyDown(){this.updateShapes()}onKeyUp(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.snaps.clearIndicators()}updateCursor(){if(!this.editor.getSelectedShapes()[0])return;let e=b8[this.info.handle];this.editor.setCursor({type:e,rotation:this.editor.getSelectionRotation()})}updateShapes(){let{editor:e}=this,{shape:t,cursorHandleOffset:n,initialSelectionPageBounds:i,selectionRotation:o}=this.snapshot;if(!t)return;let s=e.getShapeUtil(t.type);if(!s)return;let a=e.inputs.getShiftKey(),l=e.inputs.getAltKey(),d=(0,r.gu7)(e.inputs),c=e.inputs.getCurrentPagePoint().clone().sub(n),h=e.inputs.getOriginPagePoint().clone().sub(n);if(e.getInstanceState().isGridMode&&!d){let{gridSize:t}=e.getDocumentSettings();c.snapToGrid(t)}e.snaps.clearIndicators();let u=e.user.getIsSnapMode()?!d:d,p=!1;if(u&&i&&o%r.sKG==0){let{nudge:t}=e.snaps.shapeBounds.snapResizeShapes({dragDelta:r.l2P.Sub(c,h),initialSelectionPageBounds:i,handle:(0,r.Wj6)(this.info.handle,o),isAspectRatioLocked:a,isResizingFromCenter:l});c.add(t),p=!0}let f=c.clone().sub(h).rot(-t.rotation),g=t.props.crop??$(),m=U(t.props,g),y=(s.onCrop?.bind(s)??function(e,t,n={}){let{handle:i,change:o,crop:s,aspectRatioLocked:a,isResizingFromCenter:l}=t,{w:d,h:c}=t.uncroppedSize,{minWidth:h=8,minHeight:u=8}=n;if(d<h||c<u||0===o.x&&0===o.y)return;let p=new r.azJ(s.topLeft.x*d,s.topLeft.y*c,(s.bottomRight.x-s.topLeft.x)*d,(s.bottomRight.y-s.topLeft.y)*c),f=p.aspectRatio,g=p.clone(),m="top_left"===i||"bottom_left"===i||"left"===i,y="top_right"===i||"bottom_right"===i||"right"===i,b="top_left"===i||"top_right"===i||"top"===i,x="bottom_left"===i||"bottom_right"===i||"bottom"===i;if(l){let e=p.midX,t=p.midY,n=p.w/2,i=p.h/2;if(m?n=e-(p.x+o.x):y&&(n=p.maxX+o.x-e),b?i=t-(p.y+o.y):x&&(i=p.maxY+o.y-t),a){let o;o=(m||y)&&(b||x)?n/i>f?n:i*f:m||y?n:i*f;let s=Math.max(h/2,u/2*f),a=Math.min(e,d-e,t*f,(c-t)*f);if(a<s)return;i=(n=(0,r.qE8)(o,s,a))/f}else{if(m||y){let t=Math.min(e,d-e);if(t<h/2)return;n=(0,r.qE8)(n,h/2,t)}if(b||x){let e=Math.min(t,c-t);if(e<u/2)return;i=(0,r.qE8)(i,u/2,e)}}g.x=e-n,g.y=t-i,g.w=2*n,g.h=2*i}else{if(m)g.x=(0,r.qE8)(g.x+o.x,0,p.maxX-h),g.w=p.maxX-g.x;else if(y){let e=(0,r.qE8)(g.maxX+o.x,p.x+h,d);g.w=e-g.x}if(b)g.y=(0,r.qE8)(g.y+o.y,0,p.maxY-u),g.h=p.maxY-g.y;else if(x){let e=(0,r.qE8)(g.maxY+o.y,p.y+u,c);g.h=e-g.y}}if(a&&!l)switch(g.aspectRatio>f?g.h=g.w/f:g.w=g.h*f,i){case"top_left":g.x=p.maxX-g.w,g.y=p.maxY-g.h,g.x<=0&&(g.x=0,g.w=p.maxX-g.x,g.h=g.w/f,g.y=p.maxY-g.h),g.y<=0&&(g.y=0,g.h=p.maxY-g.y,g.w=g.h*f,g.x=p.maxX-g.w);break;case"top_right":g.x=p.x,g.y=p.maxY-g.h,g.maxX>=d&&(g.w=d-p.x,g.h=g.w/f,g.y=p.maxY-g.h),g.y<=0&&(g.y=0,g.h=p.maxY-g.y,g.w=g.h*f);break;case"bottom_left":g.x=p.maxX-g.w,g.y=p.y,g.x<=0&&(g.x=0,g.w=p.maxX-g.x,g.h=g.w/f),g.maxY>=c&&(g.h=c-p.y,g.w=g.h*f,g.x=p.maxX-g.w);break;case"bottom_right":g.x=p.x,g.y=p.y,g.maxX>=d&&(g.w=d-p.x,g.h=g.w/f),g.maxY>=c&&(g.h=c-p.y,g.w=g.h*f);break;case"top":g.h=p.maxY-g.y,g.w=g.h*f,g.x-=(g.w-p.w)/2,g.x<=0&&(g.w=2*p.midX,g.h=g.w/f,g.x=0),g.maxX>=d&&(g.w=2*(d-p.midX),g.h=g.w/f,g.x=d-g.w),g.y=p.maxY-g.h;break;case"right":g.w=g.maxX-p.x,g.h=g.w/f,g.y-=(g.h-p.h)/2,g.y<=0&&(g.h=2*p.midY,g.w=g.h*f,g.y=0),g.maxY>=c&&(g.h=2*(c-p.midY),g.w=g.h*f,g.y=c-g.h);break;case"bottom":g.h=g.maxY-p.y,g.w=g.h*f,g.x-=(g.w-p.w)/2,g.x<=0&&(g.w=2*p.midX,g.h=g.w/f,g.x=0),g.maxX>=d&&(g.w=2*(d-p.midX),g.h=g.w/f,g.x=d-g.w);break;case"left":g.w=p.maxX-g.x,g.h=g.w/f,g.y-=(g.h-p.h)/2,g.y<=0&&(g.h=2*p.midY,g.w=g.h*f,g.y=0),g.maxY>=c&&(g.h=2*(c-p.midY),g.w=g.h*f,g.y=c-g.h),g.x=p.maxX-g.w}let w={topLeft:{x:g.x/d,y:g.y/c},bottomRight:{x:g.maxX/d,y:g.maxY/c}};if(null!=s.isCircle&&(w.isCircle=s.isCircle),w.topLeft.x===s.topLeft.x&&w.topLeft.y===s.topLeft.y&&w.bottomRight.x===s.bottomRight.x&&w.bottomRight.y===s.bottomRight.y)return;let v=new r.l2P(g.x-s.topLeft.x*d,g.y-s.topLeft.y*c).rot(e.rotation).add(e);return{id:e.id,type:e.type,x:v.x,y:v.y,props:{...e.props,w:g.w,h:g.h,crop:w}}})(t,{handle:this.info.handle,change:f,crop:g,uncroppedSize:m,initialShape:this.snapshot.shape,aspectRatioLocked:a,isResizingFromCenter:l});y&&e.updateShapes([{id:t.id,type:t.type,...y}]),p&&i&&this.reconcileSnapIndicators(i,r.l2P.Sub(c,h),(0,r.Wj6)(this.info.handle,o),a,l),y&&this.updateCursor()}reconcileSnapIndicators(e,t,n,i,o){let{editor:s}=this;if(!s.snaps.getIndicators().length)return;let a=s.getShapePageBounds(this.snapshot.shape.id);if(!a)return;let{box:l}=r.azJ.Resize(e,n,o?2*t.x:t.x,o?2*t.y:t.y,i);o&&(l.center=e.center),(Math.abs(a.minX-l.minX)>1||Math.abs(a.maxX-l.maxX)>1||Math.abs(a.minY-l.minY)>1||Math.abs(a.maxY-l.maxY)>1)&&s.snaps.clearIndicators()}complete(){this.updateShapes(),(0,r.IeP)(this.editor,[this.snapshot.shape.id]);let{onInteractionEnd:e}=this.info;e?"string"==typeof e?this.editor.setCurrentTool(e,this.info):e():(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}cancel(){this.editor.bailToMark(this.markId);let{onInteractionEnd:e}=this.info;e?"string"==typeof e?this.editor.setCurrentTool(e,this.info):e():(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}createSnapshot(){let e=this.editor.getSelectionRotation(),t=this.editor.inputs.getOriginPagePoint(),n=this.editor.getOnlySelectedShape(),i=this.editor.getSelectionRotatedPageBounds(),o=r.l2P.RotWith(i.getHandlePoint(this.info.handle),i.point,e);return{shape:n,cursorHandleOffset:r.l2P.Sub(t,o),initialSelectionPageBounds:this.editor.getSelectionPageBounds(),selectionRotation:e}}}class xe extends r.YM5{static id="pointing_crop_handle";info={};onEnter(e){this.info=e,"string"==typeof e.onInteractionEnd&&this.parent.setCurrentToolIdMask(e.onInteractionEnd);let t=this.editor.getSelectedShapes()[0];if(!t)return;let n=b8[this.info.handle];this.editor.setCursor({type:n,rotation:this.editor.getSelectionRotation()}),this.editor.setCroppingShape(t.id)}onExit(){this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0)}onPointerMove(){this.editor.inputs.getIsDragging()&&this.startCropping()}onLongPress(){this.startCropping()}startCropping(){this.editor.getIsReadonly()||this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})}onPointerUp(){let{onInteractionEnd:e}=this.info;e?"string"==typeof e?this.editor.setCurrentTool(e,this.info):e():(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}onDoubleClick(e){this.editor.inputs.getShiftKey()||"down"!==e.phase||e.ctrlKey||e.shiftKey||(this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent(e))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){let{onInteractionEnd:e}=this.info;e?"string"==typeof e?this.editor.setCurrentTool(e,this.info):e():(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}}function xt(e,t=!1){let n=e.inputs.getCurrentPagePoint();return e.getShapeAtPoint(n,{hitInside:!1,hitLabels:t,hitLocked:e.options.selectLockedShapes,margin:e.getHitTestMargin(),renderingOnly:!0})??e.getSelectedShapeAtPoint(n)}function xn(e){if(e.isDisposed)return!1;let t=e.inputs.getCurrentPagePoint(),n=e.getHitTestMargin(),r=e.overlays.getOverlayAtPoint(t,n),i=e.overlays.getHoveredOverlayId();if(r){e.overlays.setHoveredOverlay(r.id),e.setHoveredShape(null);let t=e.overlays.getOverlayUtil(r).getCursor(r);return t&&e.setCursor({type:t,rotation:e.getSelectionRotation()}),!0}return i&&e.setCursor({type:"default",rotation:0}),e.overlays.setHoveredOverlay(null),!1}function xr(e,t,n){if(!t)throw Error("Needs to translate a cropped shape!");let{crop:i}=t.props;if(!i)return;let o=e.inputs.getShiftKey()?Math.abs(n.x)<Math.abs(n.y)?"x":"y":null;"x"===o?n.x=0:"y"===o&&(n.y=0),n.rot(-t.rotation);let{w:s,h:a}=U(t.props,i),l=i.bottomRight.x-i.topLeft.x,d=i.bottomRight.y-i.topLeft.y,c=(0,r.pN9)(i);return c.topLeft.x=(0,r.qE8)(c.topLeft.x-n.x/s,0,1-l),c.topLeft.y=(0,r.qE8)(c.topLeft.y-n.y/a,0,1-d),c.bottomRight.x=c.topLeft.x+l,c.bottomRight.y=c.topLeft.y+d,{id:t.id,type:t.type,props:{crop:c}}}class xi extends r.YM5{static id="idle";onEnter(){this.editor.setCursor({type:"default",rotation:0});let e=this.editor.getOnlySelectedShape();e&&this.editor.setCroppingShape(e.id),xn(this.editor)}onExit(){this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){xn(this.editor)}onCancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}onPointerDown(e){if(e.accelKey){this.cancel(),this.editor.root.handleEvent(e);return}switch(e.target){case"canvas":{let t=this.editor.inputs.getCurrentPagePoint(),n=this.editor.overlays.getOverlayAtPoint(t,this.editor.getHitTestMargin());if(n){let t=n.props.overlayType;if("resize_handle"===t||"rotate_handle"===t||"mobile_rotate"===t)return void this.onPointerDown({...e,target:"selection",handle:n.props.handle})}let r=xt(this.editor);if(r&&!this.editor.isShapeOfType(r,"group"))return void this.onPointerDown({...e,shape:r,target:"shape"});this.cancel(),this.editor.root.handleEvent(e);break}case"shape":if(e.shape.id===this.editor.getCroppingShapeId())return void this.editor.setCurrentTool("select.crop.pointing_crop",e);this.editor.getShapeUtil(e.shape)?.canCrop(e.shape)?(this.editor.setCroppingShape(e.shape.id),this.editor.setSelectedShapes([e.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",e)):(this.cancel(),this.editor.root.handleEvent(e));break;case"selection":switch(e.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":this.editor.setCurrentTool("select.pointing_rotate_handle",{...e,onInteractionEnd:"select.crop.idle"});break;case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":this.editor.setCurrentTool("select.crop.pointing_crop_handle",{...e,onInteractionEnd:"select.crop.idle"});break;default:this.cancel()}}}onDoubleClick(e){if(this.editor.inputs.getShiftKey()||"down"!==e.phase)return;let t=this.editor.getCroppingShapeId();if(!t)return;let n=this.editor.getShape(t);if(!n)return;let r=this.editor.getShapeUtil(n);if(r){if("canvas"===e.target){let t=this.editor.inputs.getCurrentPagePoint(),n=this.editor.overlays.getOverlayAtPoint(t,this.editor.getHitTestMargin());if(n){let t=n.props.overlayType;if("resize_handle"===t||"rotate_handle"===t||"mobile_rotate"===t)return void this.onDoubleClick({...e,target:"selection",handle:n.props.handle})}}if("selection"===e.target)return void r.onDoubleClickEdge?.(n,e);this.cancel(),this.editor.root.handleEvent(e)}}onKeyDown(){this.nudgeCroppingImage(!1)}onKeyRepeat(){this.nudgeCroppingImage(!0)}onKeyUp(e){"Enter"===e.key&&(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{}))}cancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}nudgeCroppingImage(e=!1){let{editor:{inputs:{keys:t}}}=this,n=t.has("ShiftLeft"),i=new r.l2P(0,0);if(t.has("ArrowLeft")&&(i.x+=1),t.has("ArrowRight")&&(i.x-=1),t.has("ArrowUp")&&(i.y+=1),t.has("ArrowDown")&&(i.y-=1),i.equals(new r.l2P(0,0)))return;n&&i.mul(10);let o=this.editor.getShape(this.editor.getCroppingShapeId());if(!o)return;let s=xr(this.editor,o,i);s&&(e||this.editor.markHistoryStoppingPoint("translate crop"),this.editor.updateShapes([s]))}}class xo extends r.YM5{static id="pointing_crop";onCancel(){this.editor.setCurrentTool("select.crop.idle",{})}onPointerMove(e){this.editor.inputs.getIsDragging()&&this.startDragging(e)}onLongPress(e){this.startDragging(e)}onPointerUp(e){this.editor.setCurrentTool("select.crop.idle",e)}onDoubleClick(e){this.editor.inputs.getShiftKey()||"down"!==e.phase||e.ctrlKey||e.shiftKey||(this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent(e))}startDragging(e){this.editor.setCurrentTool("select.crop.translating_crop",e)}}class xs extends r.YM5{static id="translating_crop";info={};markId="";snapshot={};onEnter(e){this.info=e,this.snapshot=this.createSnapshot(),this.markId=this.editor.markHistoryStoppingPoint("translating_crop"),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()}onExit(){this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}onKeyDown(e){switch(e.key){case"Alt":case"Shift":return void this.updateShapes()}}onKeyUp(e){switch(e.key){case"Enter":return void this.complete();case"Alt":case"Shift":this.updateShapes()}}complete(){this.updateShapes(),this.editor.setCurrentTool("select.crop.idle",this.info)}cancel(){this.editor.bailToMark(this.markId),this.editor.setCurrentTool("select.crop.idle",this.info)}createSnapshot(){return{shape:this.editor.getOnlySelectedShape()}}updateShapes(){let e=this.snapshot.shape;if(!e)return;let t=this.editor.inputs.getOriginPagePoint(),n=this.editor.inputs.getCurrentPagePoint().clone().sub(t),r=xr(this.editor,e,n);r&&this.editor.updateShapes([r])}}class xa extends r.YM5{static id="crop";static initial="idle";static children(){return[xi,xs,xo,xe,b7]}markId="";onEnter(){this.didExit=!1,this.markId=this.editor.markHistoryStoppingPoint("crop")}didExit=!1;onExit(){this.didExit||(this.didExit=!0,this.editor.getMarkIdMatching(this.markId)===this.markId&&this.editor.squashToMark(this.markId))}onCancel(){this.didExit||(this.didExit=!0,this.editor.bailToMark(this.markId))}}class xl extends r.YM5{static id="dragging_handle";static trackPerformance=!0;shapeId;initialHandle;initialAdjacentHandle;initialPagePoint;markId;initialPageTransform;initialPageRotation;info;isPrecise=!1;isPreciseId=null;pointingId=null;onEnter(e){let{shape:t,isCreating:n,creatingMarkId:i,handle:o}=e;if(this.info=e,"string"==typeof e.onInteractionEnd&&this.parent.setCurrentToolIdMask(e.onInteractionEnd),this.shapeId=t.id,this.markId="",n)if(i)this.markId=i;else{let e=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);e&&(this.markId=e)}else this.markId=this.editor.markHistoryStoppingPoint("dragging handle");this.initialHandle=(0,r.pN9)(o),this.initialPageTransform=this.editor.getShapePageTransform(t),this.initialPageRotation=this.initialPageTransform.rotation(),this.initialPagePoint=this.editor.inputs.getOriginPagePoint().clone(),this.editor.setCursor({type:n?"cross":"grabbing",rotation:0});let s=this.editor.getShapeHandles(t).sort(r.Ky),a=s.findIndex(t=>t.id===e.handle.id);if(this.initialAdjacentHandle=null,e.handle.snapReferenceHandleId){let t=s.find(t=>t.id===e.handle.snapReferenceHandleId);t&&(this.initialAdjacentHandle=t)}if(!this.initialAdjacentHandle){for(let t=a+1;t<s.length;t++){let n=s[t];if("vertex"===n.type&&"middle"!==n.id&&n.id!==e.handle.id){this.initialAdjacentHandle=n;break}}if(!this.initialAdjacentHandle)for(let t=s.length-1;t>=0;t--){let n=s[t];if("vertex"===n.type&&"middle"!==n.id&&n.id!==e.handle.id){this.initialAdjacentHandle=n;break}}}if(this.editor.isShapeOfType(t,"arrow")){let n=dr(this.editor,t)[e.handle.id];this.isPrecise=!1,n&&(this.isPrecise=n.props.isPrecise,this.isPrecise?this.isPreciseId=n.toId:this.resetExactTimeout())}let l={handle:this.initialHandle,isPrecise:this.isPrecise,isCreatingShape:!!this.info.isCreating,initial:t},d=this.editor.getShapeUtil(t),c=d.onHandleDragStart?.(t,l);c&&this.editor.updateShapes([{...c,id:t.id,type:t.type}]),this.update(),this.editor.select(this.shapeId)}exactTimeout=-1;resetExactTimeout(){let e=this.editor.getShapeUtil("arrow").options.pointingPreciseTimeout;-1!==this.exactTimeout&&this.clearExactTimeout(),this.exactTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},e)}clearExactTimeout(){-1!==this.exactTimeout&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}onPointerMove(){this.update()}onKeyDown(){this.update()}onKeyUp(){this.update()}onPointerUp(){this.complete()}onComplete(){this.update(),this.complete()}onCancel(){this.cancel()}onExit(){this.parent.setCurrentToolIdMask(void 0),gi(this.editor),this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0})}complete(){this.editor.snaps.clearIndicators(),(0,r.IeP)(this.editor,[this.shapeId]);let e=this.editor.getShape(this.shapeId);if(e){let t=this.editor.getShapeUtil(e),n={handle:this.initialHandle,isPrecise:this.isPrecise,isCreatingShape:!!this.info.isCreating,initial:this.info.shape},r=t.onHandleDragEnd?.(e,n);r&&this.editor.updateShapes([{...r,id:e.id}])}let{onInteractionEnd:t}=this.info;if(t){if("string"!=typeof t)return void t?.();else if(this.editor.getInstanceState().isToolLocked&&t)return void this.editor.setCurrentTool(t,{shapeId:this.shapeId})}this.parent.transition("idle")}cancel(){let e=this.editor.getShape(this.shapeId);if(e){let t=this.editor.getShapeUtil(e),n={handle:this.initialHandle,isPrecise:this.isPrecise,isCreatingShape:!!this.info.isCreating,initial:this.info.shape};t.onHandleDragCancel?.(e,n)}this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators();let{onInteractionEnd:t}=this.info;t?"string"==typeof t?this.editor.setCurrentTool(t,{shapeId:this.shapeId}):t?.():this.parent.transition("idle")}update(){let{editor:e,shapeId:t,initialPagePoint:n}=this,{initialHandle:i,initialPageRotation:o,initialAdjacentHandle:s}=this,a=this.editor.user.getIsSnapMode(),{snaps:l}=e,d=e.inputs.getCurrentPagePoint(),c=e.inputs.getShiftKey(),h=e.inputs.getCtrlKey(),u=e.inputs.getAltKey(),p=e.inputs.getPointerVelocity(),f=this.info.shape,g=e.getShape(t);if(!g)return;let m=e.getShapeUtil(g),y=e.isShapeOfType(g,"arrow")?dr(e,g)[i.id]:void 0,b=d.clone().sub(n).rot(-o).add(i);if(c&&s&&"middle"!==i.id){let e=r.l2P.Angle(s,b),t=(0,r.cL9)(e,24);b=r.l2P.RotWith(b,s,t-e)}e.snaps.clearIndicators();let x={...i,x:b.x,y:b.y},w=!1;if(i.canSnap&&i.snapType?(0,r.mcG)("canSnap is deprecated. Cannot use both canSnap and snapType together - snapping disabled. Please use only snapType."):w=i.canSnap||void 0!==i.snapType,w&&(a?!h:h)){if(!e.getShapePageTransform(g.id))throw Error("Expected a page transform");let n=l.handles.snapHandle({currentShapeId:t,handle:x});n&&(n.nudge.rot(-e.getShapeParentTransform(g).rotation()),b.add(n.nudge),x={...i,x:b.x,y:b.y})}let v=m.onHandleDrag?.(g,{handle:x,isPrecise:this.isPrecise||u,isCreatingShape:!!this.info.isCreating,initial:f}),S={id:g.id,type:g.type,...v};if("vertex"===i.type&&this.editor.isShapeOfType(g,"arrow")){let t=dr(e,g)[i.id];t?y?.toId!==t.toId&&(this.pointingId=t.toId,this.isPrecise=.5>p.len()||u,this.isPreciseId=this.isPrecise?t.toId:null,this.resetExactTimeout()):y&&(this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}v&&e.updateShapes([S])}}function xd(e){return e.isLabel?[e]:e instanceof r.IQE?e.children.filter(e=>e.isLabel):[]}class xc extends r.YM5{static id="editing_shape";hitLabelOnShapeForPointerUp=null;info={};didPointerDownOnEditingShape=!1;isTextInputFocused(){let e=this.editor.getContainer(),t=this.editor.getContainerDocument();return e.contains(t.activeElement)&&(0,r.ghB)(!1,t)}onEnter(e){let t=this.editor.getEditingShape();if(!t)throw Error("Entered editing state without an editing shape");this.hitLabelOnShapeForPointerUp=null,this.didPointerDownOnEditingShape=!1,this.info=e,e.isCreatingTextWhileToolLocked&&this.parent.setCurrentToolIdMask("text"),this.editor.setCursor({type:"default",rotation:0}),mF(this.editor),this.editor.select(t)}onExit(){let e=!!this.editor.getEditingShapeId();this.editor.setEditingShape(null),mz(this.editor),this.info.isCreatingTextWhileToolLocked&&e&&(this.parent.setCurrentToolIdMask(void 0),this.editor.setCurrentTool("text",{}))}onPointerMove(e){if(this.hitLabelOnShapeForPointerUp&&this.editor.inputs.getIsDragging()){if(this.editor.getIsReadonly()||this.hitLabelOnShapeForPointerUp.isLocked)return;this.editor.select(this.hitLabelOnShapeForPointerUp),this.parent.transition("translating",e),this.hitLabelOnShapeForPointerUp=null;return}if(this.didPointerDownOnEditingShape&&this.editor.inputs.isDragging){if(this.editor.getIsReadonly())return;let t=this.editor.getEditingShape();if(!t||t.isLocked)return;if(!this.isTextInputFocused()){this.editor.select(t),this.parent.transition("translating",e),this.didPointerDownOnEditingShape=!1;return}this.didPointerDownOnEditingShape=!1}switch(e.target){case"shape":case"canvas":return void mF(this.editor)}}onPointerDown(e){switch(this.hitLabelOnShapeForPointerUp=null,this.didPointerDownOnEditingShape=!1,e.target){case"canvas":{let t=xt(this.editor,!0);if(t)return void this.onPointerDown({...e,shape:t,target:"shape"});break}case"shape":{let{shape:t}=e,n=this.editor.getEditingShape();if(!n)throw Error("Expected an editing shape!");let r=xd(this.editor.getShapeUtil(t).getGeometry(t)),i=1===r.length?r[0]:void 0,o=this.editor.isShapeOfType(n,"text")&&""===rX(this.editor,n.props.richText).trim();if(i&&!o){let e=this.editor.getPointInShapeSpace(t,this.editor.inputs.getCurrentPagePoint());if(i.bounds.containsPoint(e,0)&&i.hitTestPoint(e))if(t.id===n.id){this.didPointerDownOnEditingShape=!0;return}else{this.hitLabelOnShapeForPointerUp=t,this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(t.id);return}}else{if(t.id!==n.id)return void this.parent.transition("pointing_shape",e);this.editor.isShapeFrameLike(t)&&(this.editor.setEditingShape(null),this.parent.transition("idle",e));return}}}this.parent.transition("idle",e),this.editor.root.handleEvent(e)}onPointerUp(e){if(this.didPointerDownOnEditingShape&&(this.didPointerDownOnEditingShape=!1,!this.isTextInputFocused()))return void this.editor.getRichTextEditor()?.commands.focus("all");let t=this.hitLabelOnShapeForPointerUp;if(!t)return;this.hitLabelOnShapeForPointerUp=null;let n=this.editor.getShapeUtil(t);if(t.isLocked)return;if(this.editor.getIsReadonly()&&!n.canEditInReadonly(t))return void this.parent.transition("pointing_shape",e);this.editor.select(t.id);let i=this.editor.getEditingShape(),o=i&&i.id!==t.id;this.editor.setEditingShape(t.id);let s=r.YZA.isIos||r.YZA.isAndroid;s&&o?s&&o&&this.editor.emit("select-all-text",{shapeId:t.id}):this.editor.emit("place-caret",{shapeId:t.id,point:e.point}),mF(this.editor)}onComplete(e){this.editor.getContainer().focus(),this.parent.transition("idle",e)}onCancel(e){this.editor.getContainer().focus(),this.parent.transition("idle",e)}}let xh=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];class xu extends r.YM5{static id="idle";selectedShapesOnKeyDown=[];onEnter(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),xn(this.editor)||mF(this.editor),this.selectedShapesOnKeyDown=[]}onExit(){this.editor.updateInstanceState({isChangingStyle:!1}),mz(this.editor)}onPointerMove(){xn(this.editor)||mF(this.editor),(0,r.PmD)(()=>this.editor.getInstanceState()).isChangingStyle&&this.editor.updateInstanceState({isChangingStyle:!1})}onPointerDown(e){switch(e.target){case"canvas":{let t=this.editor.inputs.getCurrentPagePoint(),n=this.editor.overlays.getOverlayAtPoint(t,this.editor.getHitTestMargin());if(n)return void this.onPointerDown({...e,target:"overlay",overlay:n});let r=xt(this.editor);if(r&&(this.editor.options.selectLockedShapes||!r.isLocked))return void this.onPointerDown({...e,shape:r,target:"shape"});let i=this.editor.getSelectedShapeIds(),o=this.editor.getOnlySelectedShape();if((i.length>1||o&&!this.editor.getShapeUtil(o).hideSelectionBoundsBg(o))&&xm(this.editor,t))return void this.onPointerDown({...e,target:"selection"});this.parent.transition("pointing_canvas",e);break}case"overlay":{let{overlay:t}=e,n=this.editor.overlays.getOverlayUtil(t);if(n.onPointerDown&&!1!==n.onPointerDown(t,e))return;let r=t.props.overlayType;if("shape_handle"===t.type){let n=this.editor.getShape(t.props.shapeId);n&&this.onPointerDown({...e,target:"handle",shape:n,handle:t.props.handle})}else switch(r){case"rotate_handle":case"mobile_rotate":case"resize_handle":this.onPointerDown({...e,target:"selection",handle:t.props.handle});break;default:this.onPointerDown({...e,target:"selection"})}break}case"shape":{let{shape:t}=e;if(!this.editor.options.selectLockedShapes&&this.editor.isShapeOrAncestorLocked(t)){this.parent.transition("pointing_canvas",e);break}this.parent.transition("pointing_shape",e);break}case"handle":if(this.editor.getIsReadonly())break;this.editor.inputs.getAltKey()?this.parent.transition("pointing_shape",e):this.parent.transition("pointing_handle",e);break;case"selection":switch(e.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":if(e.accelKey){this.parent.transition("brushing",e);break}this.parent.transition("pointing_rotate_handle",e);break;case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{let t=this.editor.getOnlySelectedShape();if(e.ctrlKey&&this.editor.canCropShape(t))this.parent.transition("crop.pointing_crop_handle",e);else{if(e.accelKey){this.parent.transition("brushing",e);break}this.parent.transition("pointing_resize_handle",e)}break}default:{let t=this.editor.getHoveredShape();if(t&&!this.editor.getSelectedShapeIds().includes(t.id)&&(this.editor.options.selectLockedShapes||!t.isLocked))return void this.onPointerDown({...e,shape:t,target:"shape"});this.parent.transition("pointing_selection",e)}}}}onDoubleClick(e){if(!this.editor.inputs.getShiftKey()&&"down"===e.phase&&!e.ctrlKey&&!e.shiftKey)switch(e.target){case"canvas":{let t=this.editor.inputs.getCurrentPagePoint(),n=this.editor.overlays.getOverlayAtPoint(t,this.editor.getHitTestMargin());if(n){if("shape_handle"===n.type){let t=this.editor.getShape(n.props.shapeId);if(t)return void this.onDoubleClick({...e,target:"handle",shape:t,handle:n.props.handle})}let t=n.props.overlayType;if("resize_handle"===t||"rotate_handle"===t||"mobile_rotate"===t)return void this.onDoubleClick({...e,target:"selection",handle:n.props.handle})}let r=this.editor.getHoveredShape(),i=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getSelectedShapeAtPoint(t)??this.editor.getShapeAtPoint(t,{margin:this.editor.getHitTestMargin(),hitInside:!1});if(i)return void this.onDoubleClick({...e,shape:i,target:"shape"});this.editor.inputs.getShiftKey()||this.handleDoubleClickOnCanvas(e);break}case"selection":{let t=this.editor.getOnlySelectedShape();if(t){let n=this.editor.getShapeUtil(t),i="right"===e.handle||"left"===e.handle||"top"===e.handle||"bottom"===e.handle,o="top_left"===e.handle||"top_right"===e.handle||"bottom_right"===e.handle||"bottom_left"===e.handle;if(this.editor.getIsReadonly()){this.editor.canEditShape(t,{type:o?"double-click-corner":i?"double-click-edge":"double-click"})&&this.startEditingShape(t,e,!0);break}if(i){let i=n.onDoubleClickEdge?.(t,e);if(i){this.editor.markHistoryStoppingPoint("double click edge"),this.editor.updateShapes([i]),(0,r.IeP)(this.editor,[t.id]);return}}if(o){let i=n.onDoubleClickCorner?.(t,e);if(i){this.editor.markHistoryStoppingPoint("double click corner"),this.editor.updateShapes([i]),(0,r.IeP)(this.editor,[t.id]);return}}if(this.editor.canCropShape(t))return void this.parent.transition("crop",e);this.editor.canEditShape(t)&&this.startEditingShape(t,e,!0)}break}case"shape":{let{shape:t}=e,n=this.editor.getSelectedShapeIds();if(this.editor.isShapeOfType(t,"group")||this.editor.getOutermostSelectableShape(t).id!==t.id){let e=this.editor.getOutermostSelectableShape(t,e=>!n.includes(e.id));n.includes(e.id)||(this.editor.markHistoryStoppingPoint("drilling into group on double click"),this.editor.select(e.id));return}let r=this.editor.getShapeUtil(t);if("video"!==t.type&&"embed"!==t.type&&this.editor.getIsReadonly())break;if(r.onDoubleClick){let e=r.onDoubleClick?.(t);if(e)return void this.editor.updateShapes([e])}if(r.canCrop(t)&&!this.editor.isShapeOrAncestorLocked(t)){this.editor.markHistoryStoppingPoint("select and crop"),this.editor.select(e.shape?.id),this.parent.transition("crop",e);return}this.editor.canEditShape(t)?this.startEditingShape(t,e,!0):this.handleDoubleClickOnCanvas(e);break}case"handle":{if(this.editor.getIsReadonly())break;let{shape:t,handle:n}=e,r=this.editor.getShapeUtil(t),i=r.onDoubleClickHandle?.(t,n);i?this.editor.updateShapes([i]):this.editor.canEditShape(t)&&this.startEditingShape(t,e,!0)}}}onRightClick(e){switch(e.target){case"canvas":{let t=this.editor.getSelectedShapeIds(),n=this.editor.getOnlySelectedShape(),r=this.editor.inputs.getCurrentPagePoint();if((t.length>1||n&&!this.editor.getShapeUtil(n).hideSelectionBoundsBg(n))&&xm(this.editor,r))return void this.onRightClick({...e,target:"selection"});let i=this.editor.getHoveredShape(),o=i&&!this.editor.isShapeOfType(i,"group")?i:this.editor.getShapeAtPoint(r,{margin:this.editor.getHitTestMargin(),hitInside:!1,hitLabels:!0,hitLocked:!0,hitFrameInside:!0,renderingOnly:!0});if(o)return void this.onRightClick({...e,shape:o,target:"shape"});this.editor.selectNone();break}case"shape":{let{selectedShapeIds:t}=this.editor.getCurrentPageState(),{shape:n}=e,r=this.editor.getOutermostSelectableShape(n,e=>!t.includes(e.id));t.includes(r.id)||this.editor.findShapeAncestor(r,e=>t.includes(e.id))||(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([r.id]))}}}onCancel(){this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.markHistoryStoppingPoint("clearing selection"),this.editor.selectNone())}onKeyDown(e){switch(this.selectedShapesOnKeyDown=this.editor.getSelectedShapes(),e.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":if(e.accelKey)return void(e.shiftKey?"ArrowDown"===e.code?this.editor.selectFirstChildShape():"ArrowUp"===e.code&&this.editor.selectParentShape():this.editor.selectAdjacentShape(e.code.replace("Arrow","").toLowerCase()));this.nudgeSelectedShapes(!1);return}if(r.bGJ.editOnType.get()&&!xh.includes(e.key)&&!e.altKey&&!e.ctrlKey){let t=this.editor.getOnlySelectedShape();if(t&&this.editor.isShapeOfType(t,"note")&&this.editor.canEditShape(t))return void this.startEditingShape(t,{...e,target:"shape",shape:t},!0)}}onKeyRepeat(e){switch(e.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":if(e.accelKey)return void this.editor.selectAdjacentShape(e.code.replace("Arrow","").toLowerCase());this.nudgeSelectedShapes(!0);break;case"Tab":this.editor.getSelectedShapes().length&&!e.altKey&&this.editor.selectAdjacentShape(e.shiftKey?"prev":"next")}}onKeyUp(e){switch(e.key){case"Enter":{if(!this.selectedShapesOnKeyDown.length)return;let t=this.editor.getSelectedShapes();if(t.every(e=>this.editor.isShapeOfType(e,"group")))return void this.editor.setSelectedShapes(t.flatMap(e=>this.editor.getSortedChildIdsForParent(e.id)));let n=this.editor.getOnlySelectedShape();if(n&&this.editor.canEditShape(n,{type:"press_enter"}))return void this.startEditingShape(n,{...e,target:"shape",shape:n},!0);this.editor.canCropShape(n)&&this.parent.transition("crop",e);break}case"Tab":this.editor.getSelectedShapes().length&&!e.altKey&&this.editor.selectAdjacentShape(e.shiftKey?"prev":"next")}}startEditingShape(e,t,n){let{editor:r}=this;this.editor.markHistoryStoppingPoint("editing shape"),m(e)?y(r,e,{selectAll:n}):r.setEditingShape(e),this.parent.transition("editing_shape",t)}isOverArrowLabelTest(e){return!!e&&ys(this.editor,e)}handleDoubleClickOnCanvas(e){if(this.editor.getIsReadonly()||!this.editor.options.createTextOnCanvasDoubleClick)return;this.editor.markHistoryStoppingPoint("creating text shape");let t=(0,r.n6Y)(),{x:n,y:i}=this.editor.inputs.getCurrentPagePoint();this.editor.createShapes([{id:t,type:"text",x:n,y:i,props:{richText:(0,r.TP3)(""),autoSize:!0}}]);let o=this.editor.getShape(t);!o||this.editor.canEditShape(o)&&y(this.editor,t,{info:e})}nudgeSelectedShapes(e=!1){let{editor:{inputs:{keys:t}}}=this,n=t.has("ShiftLeft"),i=new r.l2P(0,0);if(t.has("ArrowLeft")&&(i.x-=1),t.has("ArrowRight")&&(i.x+=1),t.has("ArrowUp")&&(i.y-=1),t.has("ArrowDown")&&(i.y+=1),i.equals(new r.l2P(0,0)))return;e||this.editor.markHistoryStoppingPoint("nudge shapes"),this.editor.updateInstanceState({isChangingStyle:!0});let{gridSize:o}=this.editor.getDocumentSettings(),s=this.editor.getInstanceState().isGridMode?n?o*xg:o:n?xp:xf,a=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(a,i.mul(s)),(0,r.IeP)(this.editor,a)}}let xp=10,xf=1,xg=5;function xm(e,t){let n=e.getSelectionRotatedPageBounds();if(!n)return!1;let i=e.getSelectionRotation();return i?(0,r.s3y)(t,n.corners.map(e=>r.l2P.RotWith(e,n.point,i))):n.containsPoint(t)}class xy extends r.YM5{static id="pointing_arrow_label";shapeId="";markId="";wasAlreadySelected=!1;didDrag=!1;didCtrlOnEnter=!1;info={};updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}onEnter(e){let{shape:t}=e;"string"==typeof e.onInteractionEnd&&this.parent.setCurrentToolIdMask(e.onInteractionEnd),this.info=e,this.shapeId=t.id,this.didDrag=!1,this.didCtrlOnEnter=e.accelKey,this.wasAlreadySelected=this.editor.getOnlySelectedShapeId()===t.id,this.updateCursor();let n=this.editor.getShapeGeometry(t).children[1];if(!n)throw Error(`Expected to find an arrow label geometry for shape: ${t.id}`);let i=this.editor.inputs.getCurrentPagePoint(),o=this.editor.getPointInShapeSpace(t,i);if(this._labelDragOffset=r.l2P.Sub(n.center,o),this.markId=this.editor.markHistoryStoppingPoint("label-drag start"),e.shiftKey||e.accelKey){let e=this.editor.getSelectedShapeIds();this.editor.setSelectedShapes([...e,this.shapeId]);return}this.editor.setSelectedShapes([this.shapeId])}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})}_labelDragOffset=new r.l2P(0,0);onPointerMove(){if(!this.editor.inputs.getIsDragging())return;if(this.didCtrlOnEnter)return void this.parent.transition("brushing",this.info);let e=this.editor.getShape(this.shapeId);if(!e)return;let t=this.editor.getShapeUtil("arrow").options,n=m7(this.editor,e),i=this.editor.getShapePageTransform(e.id),o=this.editor.getPointInShapeSpace(e,this.editor.inputs.getCurrentPagePoint()).add(this._labelDragOffset),s=yo(this.editor,e),a=n.uninterpolateAlongEdge(o);isNaN(a)&&(a=s);let l=i.applyToPoint(n.interpolateAlongEdge(a)),d=i.applyToPoint(n.interpolateAlongEdge(s));r.l2P.DistMin(l,d,t.labelCenterSnapDistance/this.editor.getZoomLevel())&&(a=s),this.didDrag=!0,this.editor.updateShape({id:e.id,type:e.type,props:{labelPosition:a}})}onPointerUp(){let e=this.editor.getShape(this.shapeId);e&&(this.didDrag||!this.wasAlreadySelected?this.complete():this.editor.canEditShape(e)&&y(this.editor,e.id))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}complete(){let{onInteractionEnd:e}=this.info;e?"string"==typeof e?this.editor.setCurrentTool(e,{}):e():this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId);let{onInteractionEnd:e}=this.info;e?"string"==typeof e?this.editor.setCurrentTool(e,{}):e():this.parent.transition("idle")}}function xb(e,t){let n=e.getSelectedShapeIds(),i=e.inputs.getCurrentPagePoint(),{shiftKey:o,altKey:s,accelKey:a}=t,l=o||a,d=e.options.selectLockedShapes,c=e.getShapeAtPoint(i,{hitInside:!1,margin:e.getHitTestMargin(),hitLabels:!0,hitLocked:d,renderingOnly:!0,filter:e=>d||!e.isLocked});if(c){let t=e.getOutermostSelectableShape(c);if(l&&!s)e.cancelDoubleClick(),n.includes(t.id)?(e.markHistoryStoppingPoint("deselecting shape"),e.deselect(t)):(e.markHistoryStoppingPoint("shift selecting shape"),e.setSelectedShapes([...n,t.id]));else{let r;(r=t===c||t.id===e.getFocusedGroupId()||n.includes(t.id)?c:t)&&!n.includes(r.id)&&(e.markHistoryStoppingPoint("selecting shape"),e.select(r.id))}}else{if(l)return;n.length>0&&(e.markHistoryStoppingPoint("selecting none"),e.selectNone());let t=e.getFocusedGroupId();if((0,r.vc4)(t)){let n=e.getShape(t);e.isPointInShape(n,i,{margin:0,hitInside:!0})||e.setFocusedGroup(null)}}}class xx extends r.YM5{static id="pointing_canvas";onEnter(e){!(e.shiftKey||e.accelKey)&&this.editor.getSelectedShapeIds().length>0&&(this.editor.markHistoryStoppingPoint("selecting none"),this.editor.selectNone())}onPointerMove(e){this.editor.inputs.getIsDragging()&&this.parent.transition("brushing",e)}onPointerUp(e){xb(this.editor,e),this.complete()}onDoubleClick(e){this.editor.inputs.getShiftKey()||"down"!==e.phase||e.ctrlKey||e.shiftKey||(this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent(e))}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle")}complete(){this.parent.transition("idle")}}class xw extends r.YM5{static id="pointing_handle";didCtrlOnEnter=!1;info={};isDoubleClick=!1;onEnter(e){this.info=e,this.isDoubleClick=!1,this.didCtrlOnEnter=e.accelKey;let{shape:t}=e;if(this.editor.isShapeOfType(t,"arrow")){let n=dr(this.editor,t),r=n[e.handle.id],i=n["start"===e.handle.id?"end":"start"],o=this.editor.getShapePageTransform(t.id);r&&go({editor:this.editor,pointInPageSpace:o.applyToPoint(e.handle),arrow:t,isPrecise:r.props.isPrecise,currentBinding:r,oppositeBinding:i})}this.editor.setCursor({type:"grabbing",rotation:0})}onExit(){this.editor.setHintingShapes([]),this.editor.setCursor({type:"default",rotation:0})}onPointerUp(){let{shape:e,handle:t}=this.info;if(this.isDoubleClick){this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent({...this.info,type:"click",name:"double_click",phase:"down"});return}if(this.editor.isShapeOfType(e,"note")){let{editor:n}=this,r=xv(n,e,t,!1);if(r)return void y(n,r,{selectAll:!0})}this.parent.transition("idle",this.info)}onDoubleClick(e){this.editor.inputs.getShiftKey()||"down"!==e.phase||e.ctrlKey||e.shiftKey||(this.isDoubleClick=!0)}onPointerMove(e){let{editor:t}=this;t.inputs.getIsDragging()&&(this.didCtrlOnEnter?this.parent.transition("brushing",e):this.startDraggingHandle())}onLongPress(){this.startDraggingHandle()}startDraggingHandle(){let{editor:e}=this;if(e.getIsReadonly())return;let{shape:t,handle:n}=this.info;if(e.isShapeOfType(t,"note")){let i=fb(e.getShapeUtil(t),t),o=xv(e,t,n,!0);if(o){let n=e.getPointInParentSpace(o,e.inputs.getOriginPagePoint()).sub(r.l2P.Rot(new r.l2P(i.noteWidth/2,i.noteHeight/2).mul(t.props.scale),o.rotation));e.updateShape({...o,x:n.x,y:n.y}),e.setHoveredShape(o.id).select(o.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:e.getShape(o),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{y(e,o,{selectAll:!0})}});return}}this.parent.transition("dragging_handle",this.info)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}function xv(e,t,n,r){let i=fb(e.getShapeUtil(t),t),o=e.getShapePageTransform(t.id),s=o.point(),a=o.rotation(),l=mI(e,{pagePoint:s,pageRotation:a,growY:t.props.growY*t.props.scale,extraHeight:0,scale:t.props.scale,noteWidth:i.noteWidth,noteHeight:i.noteHeight})[n.index];if(l)return mM(e,{shape:t,center:l,pageRotation:a,noteWidth:i.noteWidth,noteHeight:i.noteHeight,forceNew:r})}class xS extends r.YM5{static id="pointing_rotate_handle";info={};updateCursor(){this.editor.setCursor({type:b8[this.info.handle],rotation:this.editor.getSelectionRotation()})}onEnter(e){this.info=e,"string"==typeof e.onInteractionEnd&&this.parent.setCurrentToolIdMask(e.onInteractionEnd),this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){this.editor.inputs.getIsDragging()&&this.startRotating()}onLongPress(){this.startRotating()}startRotating(){this.editor.getIsReadonly()||this.parent.transition("rotating",this.info)}onPointerUp(){this.complete()}onDoubleClick(e){this.editor.inputs.getShiftKey()||"down"!==e.phase||e.ctrlKey||e.shiftKey||(this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent(e))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}complete(){let{onInteractionEnd:e}=this.info;e?"string"==typeof e?this.editor.setCurrentTool(e,{}):e?.():this.parent.transition("idle")}cancel(){let{onInteractionEnd:e}=this.info;e?"string"==typeof e?this.editor.setCurrentTool(e,{}):e():this.parent.transition("idle")}}class xC extends r.YM5{static id="pointing_selection";info={};onEnter(e){this.info=e}onPointerUp(e){xb(this.editor,e),this.parent.transition("idle",e)}onPointerMove(e){this.editor.inputs.getIsDragging()&&this.startTranslating(e)}onLongPress(e){this.startTranslating(e)}startTranslating(e){this.editor.getIsReadonly()||this.parent.transition("translating",e)}onDoubleClick(e){if(this.editor.inputs.getShiftKey()||"down"!==e.phase||e.ctrlKey||e.shiftKey)return;let t=this.editor.getHoveredShape(),n=t&&!this.editor.isShapeOfType(t,"group")?t:this.editor.getShapeAtPoint(this.editor.inputs.getCurrentPagePoint(),{hitInside:!0,margin:0,renderingOnly:!0});if(n){this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent({...e,target:"shape",shape:this.editor.getShape(n)});return}}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}class xk extends r.YM5{static id="pointing_shape";hitShape={};hitShapeForPointerUp={};isDoubleClick=!1;didCtrlOnEnter=!1;didSelectOnEnter=!1;onEnter(e){let t=this.editor.getSelectedShapeIds(),n=this.editor.getSelectionRotatedPageBounds(),r=this.editor.getFocusedGroupId(),i=this.editor.inputs.getCurrentPagePoint(),{shiftKey:o,altKey:s,accelKey:a}=e;this.hitShape=e.shape,this.isDoubleClick=!1,this.didCtrlOnEnter=a;let l=this.editor.getOutermostSelectableShape(e.shape),d=this.editor.findShapeAncestor(l,e=>t.includes(e.id));if(this.didCtrlOnEnter||this.editor.getShapeUtil(e.shape).onClick||l.id===r||t.includes(l.id)||d||t.length>1&&n?.containsPoint(i)){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=l;return}this.didSelectOnEnter=!0,o&&!s?(this.editor.cancelDoubleClick(),t.includes(l.id)||(this.editor.markHistoryStoppingPoint("shift selecting shape"),this.editor.setSelectedShapes([...t,l.id]))):(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([l.id]))}onPointerUp(e){let t=this.editor.getSelectedShapeIds(),n=this.editor.getFocusedGroupId(),r=this.editor.inputs.getCurrentPagePoint(),i=e.shiftKey||e.accelKey,o=this.editor.getShapeAtPoint(r,{margin:this.editor.getHitTestMargin(),hitInside:!0,renderingOnly:!0})??this.hitShape;if(!this.editor.getShape(o.id))return void this.parent.transition("idle",e);let s=o?this.editor.getOutermostSelectableShape(o):this.hitShapeForPointerUp;if(s){let r=this.editor.getShapeUtil(s);if(r.onClick){let t=r.onClick?.(s);if(t){this.editor.markHistoryStoppingPoint("shape on click"),this.editor.updateShapes([t]),this.parent.transition("idle",e);return}}if(s.id===n){t.length>0?(this.editor.markHistoryStoppingPoint("clearing shape ids"),this.editor.setSelectedShapes([])):this.editor.popFocusedGroupId(),this.parent.transition("idle",e);return}}if(!this.didSelectOnEnter){let n=this.editor.getOutermostSelectableShape(o,e=>!t.includes(e.id));if(t.includes(n.id))if(i)this.editor.markHistoryStoppingPoint("deselecting on pointer up"),this.editor.deselect(s);else if(t.includes(s.id)){if(1===t.length){let t=xd(this.editor.getShapeUtil(s).getGeometry(s)),n=1===t.length?t[0]:void 0;if(n){let t=this.editor.getPointInShapeSpace(s,r);if(n.bounds.containsPoint(t,0)&&n.hitTestPoint(t))return void this.editor.run(()=>{this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(s.id),this.editor.canEditShape(s)&&(this.editor.setEditingShape(s.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick?this.editor.emit("select-all-text",{shapeId:s.id}):this.editor.emit("place-caret",{shapeId:s.id,point:e.point}))})}}this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(s.id)}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(s);else if(i){let e=this.editor.getShapeAncestors(n);this.editor.markHistoryStoppingPoint("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(t=>!e.find(e=>e.id===t)),n.id])}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.setSelectedShapes([n.id])}this.parent.transition("idle",e)}onDoubleClick(e){if(this.isDoubleClick=!0,this.editor.inputs.getShiftKey()||"down"!==e.phase||e.ctrlKey||e.shiftKey)return;let{shape:t,...n}=e;this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent({...n,target:"canvas"})}onPointerMove(e){if(this.editor.inputs.getIsDragging()){if(ys(this.editor,this.hitShape))return void this.parent.transition("pointing_arrow_label",{...e,shape:this.hitShape});this.didCtrlOnEnter?this.parent.transition("brushing",e):this.startTranslating(e)}}onLongPress(e){this.startTranslating(e)}startTranslating(e){this.editor.getIsReadonly()||(this.didSelectOnEnter||this.editor.getSelectedShapeIds().length||(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([this.hitShapeForPointerUp.id])),this.editor.focus(),this.parent.transition("translating",e))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}class xP extends r.YM5{static id="resizing";static trackPerformance=!0;info={};markId="";didHoldCommand=!1;creationCursorOffset={x:0,y:0};snapshot={};onEnter(e){let{isCreating:t=!1,creatingMarkId:n,creationCursorOffset:r={x:0,y:0}}=e;this.info=e,this.didHoldCommand=!1,"string"==typeof e.onInteractionEnd&&this.parent.setCurrentToolIdMask(e.onInteractionEnd),this.creationCursorOffset=r;try{this.snapshot=this._createSnapshot()}catch(e){console.error(e),this.cancel();return}if(this.markId="",t)if(n)this.markId=n;else{let e=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);e&&(this.markId=e)}else this.markId=this.editor.markHistoryStoppingPoint("starting resizing");t&&this.editor.setCursor({type:"cross",rotation:0}),this.handleResizeStart(),this.updateShapes()}onTick({elapsed:e}){let{editor:t}=this;!t.inputs.getIsDragging()||t.inputs.getIsPanning()||t.edgeScrollManager.updateEdgeScrolling(e)}onPointerMove(){this.updateShapes()}onKeyDown(){this.updateShapes()}onKeyUp(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}cancel(){let{shapeSnapshots:e}=this.snapshot;e.forEach(({shape:e})=>{let t=this.editor.getShape(e.id);if(t){let n=this.editor.getShapeUtil(e);n.onResizeCancel?.(e,t)}}),this.editor.bailToMark(this.markId);let{onInteractionEnd:t}=this.info;t?"string"==typeof t?this.editor.setCurrentTool(t,{}):t():this.parent.transition("idle")}complete(){if((0,r.IeP)(this.editor,this.snapshot.selectedShapeIds),this.handleResizeEnd(),this.info.isCreating&&this.info.onCreate)return void this.info.onCreate?.(this.editor.getOnlySelectedShape());let{onInteractionEnd:e}=this.info;if(e){if("string"!=typeof e)return void e();else if(this.editor.getInstanceState().isToolLocked)return void this.editor.setCurrentTool(e,{})}this.parent.transition("idle")}handleResizeStart(){let{shapeSnapshots:e}=this.snapshot,t=[];e.forEach(({shape:e})=>{let n=this.editor.getShapeUtil(e),r=n.onResizeStart?.(e);r&&t.push(r)}),t.length>0&&this.editor.updateShapes(t)}handleResizeEnd(){let{shapeSnapshots:e}=this.snapshot,t=[];e.forEach(({shape:e})=>{let n=this.editor.getShape(e.id),r=this.editor.getShapeUtil(e),i=r.onResizeEnd?.(e,n);i&&t.push(i)}),t.length>0&&this.editor.updateShapes(t)}updateShapes(){let{editor:e,info:t,snapshot:{frames:n,shapeSnapshots:i,selectionBounds:o,cursorHandleOffset:s,selectedShapeIds:a,selectionRotation:l,canShapesDeform:d,initialSelectionPageBounds:c,resizeLevels:h}}=this,u=e.inputs.getAltKey(),p=e.inputs.getShiftKey()||!d;if(1===i.size){let n=[...i.values()][0];e.isShapeOfType(n.shape,"text")&&(p="left"!==t.handle&&"right"!==t.handle)}let f=(0,r.gu7)(e.inputs),g=e.inputs.getCurrentPagePoint().clone().sub(s).sub(this.creationCursorOffset),m=e.inputs.getOriginPagePoint().clone().sub(s);if(e.getInstanceState().isGridMode&&!f){let{gridSize:t}=e.getDocumentSettings();g.snapToGrid(t)}let y=t.handle,b=xE(y,Math.PI);if(e.snaps.clearIndicators(),(e.user.getIsSnapMode()?!f:f)&&l%r.sKG==0){let{nudge:t}=e.snaps.shapeBounds.snapResizeShapes({dragDelta:r.l2P.Sub(g,m),initialSelectionPageBounds:c,handle:xE(y,l),isAspectRatioLocked:p,isResizingFromCenter:u});g.add(t)}let x=r.l2P.RotWith(u?o.center:o.getHandlePoint(b),o.point,l),w=r.l2P.Sub(g,x).rot(-l),v=r.l2P.Sub(m,x).rot(-l),S=r.l2P.DivV(w,v);Number.isFinite(S.x)||(S.x=1),Number.isFinite(S.y)||(S.y=1);let C="top"===y||"bottom"===y,k="left"===y||"right"===y;for(let t of(p?k?S.y=Math.abs(S.x):C?S.x=Math.abs(S.y):Math.abs(S.x)>Math.abs(S.y)?S.y=Math.abs(S.x)*(S.y<0?-1:1):S.x=Math.abs(S.y)*(S.x<0?-1:1):(C&&(S.x=1),k&&(S.y=1)),this.info.isCreating||this.updateCursor({dragHandle:y,isFlippedX:S.x<0,isFlippedY:S.y<0,rotation:l}),i.size>1&&function(e,t,n,i,o){let s=[];for(let[l,d]of t){var a;let t;if(!e.isShapeOfType(d.shape,"geo"))continue;let c=d.shape;if(rG(c.props.richText)||!(0,r.jwY)(d.pageRotation,i))continue;let h=(0,r.YY0)((d.pageRotation-i)%Math.PI,0);t=o||d.isAspectRatioLocked?Math.max(Math.abs(n.x),Math.abs(n.y)):Math.abs(h?n.x:n.y);let u=(a=c.props,Math.max(Math.abs(a.w/a.scale*t),51)),{html:p,opts:f}=function(e,t){let{richText:n,font:r,size:i,w:o}=t.props,s=e.getCurrentTheme(),a=y9[i];return{html:rV(e,n),opts:{...Y,fontFamily:Q(s,r),fontSize:s.fontSize*X[i],lineHeight:s.lineHeight,minWidth:a,maxWidth:Math.max(0,Math.ceil(a+s.strokeWidth*G[i]),Math.ceil(o/t.props.scale-32))}}}(e,{...c,props:{...c.props,w:u*c.props.scale}});s.push({id:l,html:p,opts:f})}if(0===s.length)return;let l=e.textMeasure.measureHtmlBatch(s.map(({html:e,opts:t})=>({html:e,opts:t}))),d=new Map;for(let e=0;e<s.length;e++)d.set(s[e].id,{w:l[e].w+32,h:l[e].h+32});bo(e,d)}(this.editor,i,S,l,p),h)){let n=[];for(let r of t){let t=i.get(r),o=e.getResizeShapePartial(r,S,{initialShape:t.shape,initialBounds:t.bounds,initialPageTransform:t.pageTransform,dragHandle:y,mode:1===a.length&&r===a[0]?"resize_bounds":"scale_shape",scaleOrigin:x,isAspectRatioLocked:p,scaleAxisRotation:l,skipStartAndEndCallbacks:!0});o&&n.push(o)}n.length>0&&e.updateShapes(n)}if(f){this.didHoldCommand=!0;let e=[];for(let{id:t,children:o}of n){if(!o.length)continue;let n=i.get(t).shape,s=this.editor.getShape(t);if(!(n&&s))continue;let a=s.x-n.x,l=s.y-n.y,d=new r.l2P(a,l).rot(-n.rotation);if(0!==d.x||0!==d.y)for(let t of o)e.push({id:t.id,type:t.type,x:t.x-d.x,y:t.y-d.y})}e.length>0&&this.editor.updateShapes(e)}else if(this.didHoldCommand){this.didHoldCommand=!1;let e=[];for(let{children:t}of n)for(let n of t)e.push({id:n.id,type:n.type,x:n.x,y:n.y});e.length>0&&this.editor.updateShapes(e)}this.updateEnclosureHints()}updateEnclosureHints(){if(!this.info.isCreating)return;let e=this.editor.getOnlySelectedShape();if(!e||!this.editor.isShapeOfType(e,"frame"))return;let t=mx(this.editor,e),n=this.editor.getHintingShapeIds();t.length===n.length&&t.every((e,t)=>e===n[t])||this.editor.setHintingShapes(t)}updateCursor({dragHandle:e,isFlippedX:t,isFlippedY:n,rotation:r}){let i=this.editor.getInstanceState().cursor,o=i.type;switch(e){case"top_left":case"bottom_right":o="nwse-resize",t!==n&&(o="nesw-resize");break;case"top_right":case"bottom_left":o="nesw-resize",t!==n&&(o="nwse-resize")}(o!==i.type||r!==i.rotation)&&this.editor.setCursor({type:o,rotation:r})}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),this.editor.snaps.clearIndicators(),bo(this.editor,null),this.info.isCreating&&this.editor.getHintingShapeIds().length>0&&this.editor.setHintingShapes([])}_createSnapshot(){let{editor:e}=this,t=e.getSelectedShapeIds(),n=e.getSelectionRotation(),i=e.inputs.getOriginPagePoint(),o=e.getSelectionRotatedPageBounds();if(!o)throw Error("Resizing but nothing is selected");let s=r.l2P.RotWith(o.getHandlePoint(this.info.handle),o.point,n),a=r.l2P.Sub(i,s),l=new Map,d=[],c=t=>{let n=e.getShape(t);if(!n)return!1;let i=e.getShapeUtil(n);if(i.canResize(n)){let t=e.getShapePageTransform(n);l.set(n.id,{shape:n,bounds:e.getShapeGeometry(n).bounds,pageTransform:t,pageRotation:r.V8r.Decompose(t).rotation,isAspectRatioLocked:i.isAspectRatioLocked(n)})}if(e.isShapeFrameLike(n)&&d.push({id:n.id,children:(0,r.oE7)(e.getSortedChildIdsForParent(n).map(t=>e.getShape(t)))}),!i.canResizeChildren(n))return!1};t.forEach(t=>{!1!==c(t)&&e.visitDescendants(t,c)});let h=![...l.values()].some(e=>!(0,r.jwY)(e.pageRotation,n)||e.isAspectRatioLocked),u=[],p=new Map,f=t=>{let n=p.get(t);if(void 0!==n)return n;let i=0,o=e.getShape(t)?.parentId;for(;o&&(0,r.vc4)(o);){if(l.has(o)){i=f(o)+1;break}o=e.getShape(o)?.parentId}return p.set(t,i),i};for(let e of l.keys()){let t=f(e);for(;u.length<=t;)u.push([]);u[t].push(e)}return{shapeSnapshots:l,selectionBounds:o,cursorHandleOffset:a,selectionRotation:n,selectedShapeIds:t,canShapesDeform:h,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:d,resizeLevels:u}}}let xT=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function xE(e,t){let n=Math.round((t%=r.uAR)/(r.PI/4)),i=xT.indexOf(e);return xT[(i+n)%xT.length]}let xI=Math.PI/180;class x_ extends r.YM5{static id="rotating";static trackPerformance=!0;snapshot={};info={};markId="";onEnter(e){this.info=e,"string"==typeof e.onInteractionEnd&&this.parent.setCurrentToolIdMask(e.onInteractionEnd),this.markId=this.editor.markHistoryStoppingPoint("rotate start");let t=(0,r.fHb)({editor:this.editor,ids:this.editor.getSelectedShapeIds()});if(!t)return void this.parent.transition("idle",this.info);this.snapshot=t;let n=this._getRotationFromPointerPosition({snapToNearestDegree:!1});(0,r._Bx)({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:b8[this.info.handle],rotation:n+this.snapshot.initialShapesRotation})}onExit(){this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}}onPointerMove(){this.update()}onKeyDown(){this.update()}onKeyUp(){this.update()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}update(){let e=this._getRotationFromPointerPosition({snapToNearestDegree:!1});(0,r._Bx)({editor:this.editor,delta:e,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:b8[this.info.handle],rotation:e+this.snapshot.initialShapesRotation})}cancel(){let{shapeSnapshots:e}=this.snapshot;e.forEach(({shape:e})=>{let t=this.editor.getShape(e.id);if(t){let n=this.editor.getShapeUtil(e);n.onRotateCancel?.(e,t)}}),this.editor.bailToMark(this.markId);let{onInteractionEnd:t}=this.info;t?"string"==typeof t?this.editor.setCurrentTool(t,this.info):t():this.parent.transition("idle",this.info)}complete(){(0,r._Bx)({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),(0,r.IeP)(this.editor,this.snapshot.shapeSnapshots.map(e=>e.shape.id));let{onInteractionEnd:e}=this.info;e?"string"==typeof e?this.editor.setCurrentTool(e,this.info):e():this.parent.transition("idle",this.info)}_getRotationFromPointerPosition({snapToNearestDegree:e}){let t=this.editor.inputs.getShiftKey(),n=this.editor.inputs.getCurrentPagePoint(),{initialCursorAngle:i,initialShapesRotation:o,initialPageCenter:s}=this.snapshot,a=o+(s.angle(n)-i);if(t)a=(0,r.cL9)(a,24);else if(e&&(a=Math.round(a/xI)*xI,this.editor.getInstanceState().isCoarsePointer)){let e=(0,r.cL9)(a,4);Math.abs((0,r.qer)(a,e))<(0,r.tRv)(5)&&(a=e)}return a-o}}class xM extends r.YM5{static id="scribble_brushing";static trackPerformance=!0;hits=new Set;size=0;scribbleId="id";initialSelectedShapeIds=new Set;newlySelectedShapeIds=new Set;onEnter(){this.initialSelectedShapeIds=new Set(this.editor.inputs.getShiftKey()?this.editor.getSelectedShapeIds():[]),this.newlySelectedShapeIds=new Set,this.size=0,this.hits.clear();let e=this.editor.scribbles.addScribble({color:"selection-stroke",opacity:.32,size:12});this.scribbleId=e.id,this.updateScribbleSelection(!0),this.editor.updateInstanceState({brush:null})}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.updateScribbleSelection(!0)}onPointerUp(){this.complete()}onKeyDown(){this.updateScribbleSelection(!1)}onKeyUp(){this.editor.inputs.getAltKey()?this.updateScribbleSelection(!1):this.parent.transition("brushing")}onCancel(){this.cancel()}onComplete(){this.complete()}pushPointToScribble(){let{x:e,y:t}=this.editor.inputs.getCurrentPagePoint();this.editor.scribbles.addPoint(this.scribbleId,e,t)}updateScribbleSelection(e){let t,n,i,o,{editor:s}=this,a=this.editor.inputs.getShiftKey(),l=this.editor.inputs.getOriginPagePoint(),d=this.editor.inputs.getPreviousPagePoint(),c=this.editor.inputs.getCurrentPagePoint(),{newlySelectedShapeIds:h,initialSelectedShapeIds:u}=this;e&&this.pushPointToScribble();let p=r.azJ.FromPoints([d,c]).expandBy(0),f=s.getShapeIdsInsideBounds(p);if(0===f.size){let e=s.getSelectedShapeIds(),t=new Set(a?[...h,...u]:[...h]);(e.length!==t.size||e.some(e=>!t.has(e)))&&this.editor.setSelectedShapes(Array.from(t));return}let g=this.editor.getCurrentPageRenderingShapesSorted().filter(e=>f.has(e.id));for(let e=0,a=g.length;e<a;e++){if(t=g[e],s.isShapeOfType(t,"group")||h.has(t.id)||!s.options.selectLockedShapes&&s.isShapeOrAncestorLocked(t)||(n=s.getShapeGeometry(t),s.isShapeFrameLike(t)&&n.bounds.containsPoint(s.getPointInShapeSpace(t,l))))continue;let a=s.getShapePageTransform(t);if(!n||!a)continue;let u=a.clone().invert();i=u.applyToPoint(d),o=u.applyToPoint(c);let{bounds:p}=n;if(!(p.minX-0>Math.max(i.x,o.x)||p.minY-0>Math.max(i.y,o.y)||p.maxX+0<Math.min(i.x,o.x)||p.maxY+0<Math.min(i.y,o.y))&&n.hitTestLineSegment(i,o,0)){let e=this.editor.getOutermostSelectableShape(t),n=this.editor.getShapeMask(e.id);if(n&&null!==(0,r.lqI)(d,c,n)&&!(0,r.s3y)(c,n))continue;h.add(e.id)}}let m=s.getSelectedShapeIds(),y=new Set(a?[...h,...u]:[...h]);(m.length!==y.size||m.some(e=>!y.has(e)))&&this.editor.setSelectedShapes(Array.from(y))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}var xA=Object.defineProperty,xj=Object.getOwnPropertyDescriptor;class xO{constructor(e){this.editor=e,e.disposables.add(this.dispose)}editor;shapesToActuallyMove=[];draggedOverShapeIds=new Set;initialGroupIds=new Map;initialParentIds=new Map;initialIndices=new Map;initialDraggingOverShape;prevDraggingOverShape;prevPagePoint=new r.l2P;intervalTimerId=-1;startDraggingShapes(e,t,n){let{editor:i}=this;if(-1!==this.intervalTimerId)return;let o=new Set(e),s=new Set;for(let e of o){let t=i.getShapeParent(e);t&&i.isShapeOfType(t,"group")&&!s.has(t)&&s.add(t)}for(let e of s){let t=(0,r.oE7)(i.getSortedChildIdsForParent(e).map(e=>i.getShape(e)));for(let n of(o.add(e),t))o.delete(n)}for(let e of(this.initialParentIds.clear(),o)){let t=i.getShapeParent(e);t&&this.initialParentIds.set(e.id,t.id),this.initialIndices.set(e.id,e.index);let n=i.findShapeAncestor(e,e=>i.isShapeOfType(e,"group"));n&&this.initialGroupIds.set(e.id,n.id)}let a=i.getCurrentPageShapesSorted();this.shapesToActuallyMove=Array.from(o).filter(e=>!e.isLocked).sort((e,t)=>a.indexOf(e)-a.indexOf(t)),this.initialDraggingOverShape=i.getDraggingOverShape(t,this.shapesToActuallyMove),this.prevDraggingOverShape=void 0,this.updateDraggingShapes(t,n);let l=0;this.intervalTimerId=this.editor.timers.setInterval(()=>{++l%3&&this.editor.inputs.getPointerVelocity().len()>.5||this.updateDraggingShapes(i.inputs.getCurrentPagePoint(),n)},e.length>10?320:60)}dropShapes(e){let{editor:t}=this,n=t.inputs.getCurrentPagePoint();this.updateDraggingShapes(n);let r=t.getDraggingOverShape(n,e);if(r){let n=t.getShapeUtil(r),i=xD(t,r,e);i.length>0&&n.onDropShapesOver?.(r,i,{initialDraggingOverShapeId:this.initialDraggingOverShape?.id??null,initialParentIds:this.initialParentIds,initialIndices:this.initialIndices})}this.dispose()}clear(){clearInterval(this.intervalTimerId),this.intervalTimerId=-1,this.initialParentIds.clear(),this.initialIndices.clear(),this.shapesToActuallyMove=[],this.initialDraggingOverShape=void 0,this.prevDraggingOverShape=void 0,this.editor.setHintingShapes([])}dispose(){this.clear()}updateDraggingShapes(e,t){let{editor:n}=this,i=(0,r.oE7)(this.shapesToActuallyMove.map(e=>n.getShape(e)));if(!i.length)return;let o=n.getDraggingOverShape(e,this.shapesToActuallyMove),s=n.inputs.getCurrentPagePoint(),a=!this.prevPagePoint.equals(s);this.prevPagePoint.setTo(s),n.run(()=>{if(this.prevDraggingOverShape?.id===o?.id){if(a&&o&&(0,r.vc4)(o.id)&&!n.inputs.getPreviousPagePoint().equals(s)){let e=n.getShapeUtil(o);e.onDragShapesOver?.(o,i,{initialDraggingOverShapeId:this.initialDraggingOverShape?.id??null,initialParentIds:this.initialParentIds,initialIndices:this.initialIndices})}return}if(this.prevDraggingOverShape){var e,l,d;let t,r=n.getShapeUtil(this.prevDraggingOverShape),s=this.editor.getShape(this.prevDraggingOverShape),a=(e=n,l=s,d=i,t=e.getShapeUtil(l),d.filter(e=>t.canRemoveChildrenOfType(l,e.type)));a.length>0&&r.onDragShapesOut?.(s,a,{nextDraggingOverShapeId:o?.id??null,initialDraggingOverShapeId:this.initialDraggingOverShape?.id??null,initialParentIds:this.initialParentIds,initialIndices:this.initialIndices})}if(o){let e=n.getShapeUtil(o),t=xD(n,o,i);t.length>0?(e.onDragShapesIn?.(o,t,{initialDraggingOverShapeId:this.initialDraggingOverShape?.id??null,prevDraggingOverShapeId:this.prevDraggingOverShape?.id??null,initialParentIds:this.initialParentIds,initialIndices:this.initialIndices}),n.setHintingShapes([o.id])):this.prevDraggingOverShape&&n.setHintingShapes([])}else this.prevDraggingOverShape&&n.setHintingShapes([]);t?.()}),this.prevDraggingOverShape=o}}function xD(e,t,n){let r=e.getShapeUtil(t);return n.filter(e=>r.canReceiveNewChildrenOfType(t,e.type))}((e,t,n)=>{for(var r,i=xj(t,n),o=e.length-1;o>=0;o--)(r=e[o])&&(i=r(t,n,i)||i);return i&&xA(t,n,i)})([r.oIE],xO.prototype,"dispose");var xL=Object.defineProperty,xR=Object.getOwnPropertyDescriptor;class xF extends r.YM5{static id="translating";static trackPerformance=!0;info={};selectionSnapshot={};snapshot={};markId="";isCloning=!1;isCreating=!1;onCreate(e){}dragAndDropManager=new xO(this.editor);onEnter(e){let{isCreating:t=!1,creatingMarkId:n,onCreate:r=()=>void 0}=e;if(!this.editor.getSelectedShapeIds()?.length)return void this.parent.transition("idle");if(this.info=e,"string"==typeof e.onInteractionEnd&&this.parent.setCurrentToolIdMask(e.onInteractionEnd),this.isCreating=t,this.markId="",t)if(n)this.markId=n;else{let e=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);e&&(this.markId=e)}else this.markId=this.editor.markHistoryStoppingPoint("translating");this.onCreate=r,this.isCloning=!1,this.info=e,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=xz(this.editor),!this.isCreating&&this.editor.inputs.getAltKey()&&(this.startCloning(),this.isCloning)||(this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes())}onExit(){this.parent.setCurrentToolIdMask(void 0),this.selectionSnapshot={},this.snapshot={},this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0}),this.dragAndDropManager.clear()}onTick({elapsed:e}){let{editor:t}=this;!t.inputs.getIsDragging()||t.inputs.getIsPanning()||t.edgeScrollManager.updateEdgeScrolling(e)}onPointerMove(){this.updateShapes()}onKeyDown(){this.editor.inputs.getAltKey()&&!this.isCloning&&(this.startCloning(),this.isCloning)||this.updateShapes()}onKeyUp(){!this.editor.inputs.getAltKey()&&this.isCloning?this.stopCloning():this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}startCloning(){if(this.isCreating)return;let e=Array.from(this.editor.getSelectedShapeIds());this.editor.canCreateShapes(e)&&(this.isCloning=!0,this.reset(),this.markId=this.editor.markHistoryStoppingPoint("translate cloning"),this.editor.duplicateShapes(Array.from(this.editor.getSelectedShapeIds())),this.snapshot=xz(this.editor),this.handleStart(),this.updateShapes())}stopCloning(){this.isCloning=!1,this.snapshot=this.selectionSnapshot,this.reset(),this.markId=this.editor.markHistoryStoppingPoint("translate"),this.updateShapes()}reset(){this.editor.bailToMark(this.markId)}complete(){this.updateShapes(),this.dragAndDropManager.dropShapes(this.snapshot.movingShapes),this.handleEnd(),(0,r.IeP)(this.editor,this.snapshot.movingShapes.map(e=>e.id));let{onInteractionEnd:e}=this.info;if(e){if("string"!=typeof e)return void e();else if(this.editor.getInstanceState().isToolLocked)return void this.editor.setCurrentTool(e)}this.isCreating?this.onCreate?.(this.editor.getOnlySelectedShape()):this.parent.transition("idle")}cancel(){let{movingShapes:e}=this.snapshot;e.forEach(e=>{let t=this.editor.getShape(e.id);if(t){let n=this.editor.getShapeUtil(e);n.onTranslateCancel?.(e,t)}}),this.reset();let{onInteractionEnd:t}=this.info;t?"string"==typeof t?this.editor.setCurrentTool(t):t():this.parent.transition("idle",this.info)}handleStart(){let{movingShapes:e}=this.snapshot,t=[];e.forEach(e=>{let n=this.editor.getShapeUtil(e),r=n.onTranslateStart?.(e);r&&t.push(r)}),t.length>0&&this.editor.updateShapes(t),this.dragAndDropManager.startDraggingShapes((0,r.oE7)(this.snapshot.movingShapes.map(e=>this.editor.getShape(e.id))),this.editor.inputs.getOriginPagePoint(),this.updateParentTransforms),this.editor.setHoveredShape(null)}handleEnd(){let{movingShapes:e}=this.snapshot;if(this.isCloning&&e.length>0){let t=r.l2P.Average(e.map(e=>this.editor.getShapePageTransform(e.id).point())),n=r.l2P.Sub(t,this.selectionSnapshot.averagePagePoint);r.l2P.IsNaN(n)||this.editor.updateInstanceState({duplicateProps:{shapeIds:e.map(e=>e.id),offset:{x:n.x,y:n.y}}})}let t=[];e.forEach(e=>{let n=this.editor.getShape(e.id),r=this.editor.getShapeUtil(e),i=r.onTranslateEnd?.(e,n);i&&t.push(i)}),t.length>0&&this.editor.updateShapes(t)}updateShapes(){let{snapshot:e}=this;this.dragAndDropManager.startDraggingShapes(e.movingShapes,this.editor.inputs.getOriginPagePoint(),this.updateParentTransforms),function({editor:e,snapshot:t}){let{inputs:n}=e,{noteSnapshot:i,noteAdjacentPositions:o,noteCenterOffset:s,initialPageBounds:a,initialSnapPoints:l,shapeSnapshots:d,averagePagePoint:c}=t,h=e.inputs.getShiftKey(),u=e.inputs.getAccelKey(),p=e.getInstanceState().isGridMode,f=e.getDocumentSettings().gridSize,g=r.l2P.Sub(n.getCurrentPagePoint(),n.getOriginPagePoint()),m=h?Math.abs(g.x)<Math.abs(g.y)?"x":"y":null;"x"===m?g.x=0:"y"===m&&(g.y=0),e.snaps.clearIndicators();let y=e.user.getIsSnapMode()?!u:u,b=!1;if(y&&.5>e.inputs.getPointerVelocity().len()){let{nudge:t}=e.snaps.shapeBounds.snapTranslateShapes({dragDelta:g,initialSelectionPageBounds:a,lockedAxis:m,initialSelectionSnapPoints:l});g.add(t)}else if(i&&o&&s){let{scale:t}=i.shape.props,n=i.pagePoint.clone().add(g).add(s.clone().mul(t).rot(i.pageRotation)),a=10/e.getZoomLevel(),l=new r.l2P(0,0);for(let e of o){let t=r.l2P.Sub(n,e),i=t.len();i<a&&(b=!0,a=i,l=t)}g.sub(l)}let x=r.l2P.Add(c,g),w=e.snaps.getIndicators();!p||u||b||0!==w.length||x.snapToGrid(f);let v=r.l2P.Sub(x,c);e.updateShapes((0,r.oE7)(d.map(({shape:e,pagePoint:t,parentTransform:n})=>{let i=r.l2P.Add(t,v),o=n?r.V8r.applyToPoint(n,i):i;return{id:e.id,type:e.type,x:o.x,y:o.y}})))}({editor:this.editor,snapshot:e});let{movingShapes:t}=e,n=[];t.forEach(e=>{let t=this.editor.getShape(e.id),r=this.editor.getShapeUtil(e),i=r.onTranslate?.(e,t);i&&n.push(i)}),n.length>0&&this.editor.updateShapes(n)}updateParentTransforms(){let{editor:e,snapshot:{shapeSnapshots:t}}=this,n=[];t.forEach(t=>{let i=e.getShape(t.shape.id);i&&(n.push(i),t.parentTransform=(0,r.xhT)(i.parentId)?null:r.V8r.Inverse(e.getShapePageTransform(i.parentId)))})}}function xz(e){let t,n,i,o=[],s=[],a=e.getSelectedShapeIds(),l=(0,r.oE7)(a.map(t=>{let n=e.getShape(t);if(!n)return null;o.push(n);let i=e.getShapePageTransform(t),a=i.point(),l=i.rotation();s.push(a);let d=r.tvM.isId(n.parentId)?null:r.V8r.Inverse(e.getShapePageTransform(n.parentId));return{shape:n,pagePoint:a,pageRotation:l,parentTransform:d}})),d=e.getOnlySelectedShape(),c=[];if(d)c=e.snaps.shapeBounds.getSnapPoints(d.id);else{let t=e.getSelectionPageBounds();t&&(c=t.cornersAndCenter.map((e,t)=>({id:"selection:"+t,x:e.x,y:e.y})))}let h=e.inputs.getOriginPagePoint(),u=l.filter(t=>e.isShapeOfType(t.shape,"note")&&e.isPointInShape(t.shape,h));if(0===u.length);else if(1===u.length)n=u[0];else{let t=e.getCurrentPageShapesSorted();n=u.map(e=>({snapshot:e,index:t.findIndex(t=>t.id===e.shape.id)})).sort((e,t)=>t.index-e.index)[0]?.snapshot}if(n){let o=fb(e.getShapeUtil(n.shape),n.shape);t=m_(e,{rotation:n.pageRotation,scale:n.shape.props.scale,extraHeight:n.shape.props.growY??0,noteWidth:o.noteWidth,noteHeight:o.noteHeight}),i=new r.l2P(o.noteWidth/2,o.noteHeight/2)}return{averagePagePoint:r.l2P.Average(s),movingShapes:o,shapeSnapshots:l,initialPageBounds:e.getSelectionPageBounds(),initialSnapPoints:c,noteAdjacentPositions:t,noteSnapshot:n,noteCenterOffset:i}}((e,t,n)=>{for(var r,i=xR(t,n),o=e.length-1;o>=0;o--)(r=e[o])&&(i=r(t,n,i)||i);return i&&xL(t,n,i)})([r.oIE],xF.prototype,"updateParentTransforms"),n(41463);class xN extends r.YM5{static id="select";static initial="idle";static isLockable=!1;reactor=void 0;static children(){return[xa,b7,xu,xx,xk,xF,b4,xM,xe,xC,b9,xc,xP,x_,xS,xy,xw,xl]}cleanUpDuplicateProps(){let e=this.editor.getSelectedShapeIds(),t=this.editor.getInstanceState();if(!t.duplicateProps)return;let n=new Set(t.duplicateProps.shapeIds);e.length===n.size&&e.every(e=>n.has(e))||this.editor.updateInstanceState({duplicateProps:null})}onEnter(){this.reactor=(0,r.wvh)("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(e){console.error(e)}})}onExit(){this.reactor?.(),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)}}class x$ extends r.YM5{static id="idle";info={};onEnter(e){this.info=e}onPointerDown(){this.parent.transition("pointing",this.info)}onKeyDown(e){"Shift"===e.key&&this.parent.transition("zoom_quick",this.info)}}class xB extends r.YM5{static id="pointing";info={};onEnter(e){this.info=e}onPointerUp(){this.complete()}onPointerMove(){this.editor.inputs.getIsDragging()&&this.parent.transition("zoom_brushing",this.info)}onCancel(){this.cancel()}complete(){let e=this.editor.inputs.getCurrentScreenPoint();this.editor.inputs.getAltKey()?this.editor.zoomOut(e,{animation:{duration:220}}):this.editor.zoomIn(e,{animation:{duration:220}}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}class xH extends r.YM5{static id="zoom_brushing";info={};zoomBrush=new r.azJ;onEnter(e){this.info=e,this.update()}onExit(){this.editor.updateInstanceState({zoomBrush:null})}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}update(){let e=this.editor.inputs.getOriginPagePoint(),t=this.editor.inputs.getCurrentPagePoint();this.zoomBrush.setTo(r.azJ.FromPoints([e,t])),this.editor.updateInstanceState({zoomBrush:this.zoomBrush.toJson()})}cancel(){this.parent.transition("idle",this.info)}complete(){let{zoomBrush:e}=this,t=8/this.editor.getZoomLevel();if(e.width<t&&e.height<t){let e=this.editor.inputs.getCurrentScreenPoint();this.editor.inputs.getAltKey()?this.editor.zoomOut(e,{animation:{duration:220}}):this.editor.zoomIn(e,{animation:{duration:220}})}else{let t=this.editor.inputs.getAltKey()?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(e,{targetZoom:t,animation:{duration:220}})}this.parent.transition("idle",this.info)}}class xU extends r.YM5{static id="zoom_quick";info={};qzState="idle";initialVpb=new r.azJ;initialPp=new r.l2P;overviewZoom=1;cleanupZoomReactor(){}nextVpb=new r.azJ;onEnter(e){let{editor:t}=this;this.info=e,this.qzState="idle",this.initialVpb=t.getViewportPageBounds(),this.initialPp=r.l2P.From(t.inputs.getCurrentPagePoint()),t.setCursor({type:"zoom-in",rotation:0});let n=this.initialVpb,i=t.getCurrentPageBounds(),o=i?r.azJ.Expand(n,i):n.clone(),s=t.getViewportScreenBounds(),a=t.inputs.getCurrentScreenPoint(),l=a.x,d=a.y,{x:c,y:h}=this.initialPp,u=c-o.minX,p=o.maxX-c,f=h-o.minY,g=o.maxY-h,m=t.getCamera().z;u>0&&(m=Math.min(m,l/u)),p>0&&(m=Math.min(m,(s.w-l)/p)),f>0&&(m=Math.min(m,d/f)),g>0&&(m=Math.min(m,(s.h-d)/g)),m*=.85,m=Math.max(t.getCameraOptions().zoomSteps[0],m),this.overviewZoom=m,t.options.quickZoomPreservesScreenBounds&&(this.cleanupZoomReactor=(0,r.wvh)("zoom change in quick zoom",()=>{t.getZoomLevel(),this.updateBrush()}));let{x:y,y:b,z:x}=t.getCamera(),w=x/m;t.setCamera(new r.l2P((y+c)*w-c,(b+h)*w-h,m)),t.options.quickZoomPreservesScreenBounds||this.updateBrush()}onExit(){this.cleanupZoomReactor(),this.zoomToNewViewport(),this.editor.updateInstanceState({zoomBrush:null})}onPointerUp(){let e=this.info.onInteractionEnd?.split(".")[0]??"select";this.editor.setCurrentTool(e)}onCancel(){this.qzState="idle";let e=this.info.onInteractionEnd?.split(".")[0]??"select";this.editor.setCurrentTool(e)}onKeyUp(e){"Shift"===e.key&&this.parent.transition("idle",this.info)}updateBrush(){let{editor:e}=this,t=this.getNextVpb();this.nextVpb.setTo(t),e.updateInstanceState({zoomBrush:t.toJson()})}zoomToNewViewport(){let{editor:e}=this;switch(this.qzState){case"idle":e.zoomToBounds(this.initialVpb,{inset:0});break;case"moving":e.zoomToBounds(this.nextVpb,{inset:0})}}onPointerMove(){"moving"===this.qzState&&this.updateBrush()}onTick(){let{editor:e}=this;if("idle"===this.qzState){let t=e.getZoomLevel();r.l2P.Dist2(e.inputs.getCurrentPagePoint(),this.initialPp)*t>e.options.dragDistanceSquared/t&&(this.qzState="moving",this.updateBrush())}}getNextVpb(){let e,t,{editor:n}=this;if(n.options.quickZoomPreservesScreenBounds){let r=this.overviewZoom/n.getCamera().z;e=this.initialVpb.w*r,t=this.initialVpb.h*r}else e=this.initialVpb.w,t=this.initialVpb.h;let{x:i,y:o}=n.inputs.getCurrentPagePoint(),s=n.getViewportScreenBounds(),a=n.inputs.getCurrentScreenPoint(),{x:l,y:d}=new r.l2P(a.x/s.w,a.y/s.h);return new r.azJ(i-l*e,o-d*t,e,t)}}class xK extends r.YM5{static id="zoom";static initial="idle";static children(){return[x$,xB,xH,xU]}static isLockable=!1;info={};onEnter(e){this.info=e;let t=e.onInteractionEnd?.split(".")[0];this.parent.setCurrentToolIdMask(t),this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}})}onKeyDown(){this.updateCursor()}onKeyUp(e){this.updateCursor(),"z"===e.key.toLowerCase()&&this.complete()}onInterrupt(){this.complete()}complete(){let e=this.info.onInteractionEnd?.split(".")[0]??"select";this.editor.setCurrentTool(e)}updateCursor(){this.editor.inputs.getAltKey()&&!this.editor.isIn("zoom.zoom_quick")?this.editor.setCursor({type:"zoom-out",rotation:0}):this.editor.setCursor({type:"zoom-in",rotation:0})}}let xW=f.forwardRef(function({isEditing:e,text:t,handleFocus:n,handleChange:i,handleKeyDown:o,handlePaste:s,handleBlur:a,handleInputPointerDown:l,handleDoubleClick:c},h){let u=(0,r.hGv)();return(0,d.jsx)("textarea",{ref:h,className:"tl-text tl-text-input",name:"text",tabIndex:-1,disabled:!e,readOnly:!e,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",autoSave:"off",placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",defaultValue:t,onFocus:n,onChange:e=>{i({plaintext:e.target.value})},onKeyDown:e=>o(e.nativeEvent),onBlur:a,onTouchEnd:u.markEventAsHandled,onContextMenu:e?e=>e.stopPropagation():void 0,onPointerDown:l,onPaste:s,onDoubleClick:c,onDragStart:r.woC})});f.memo(function({shapeId:e,type:t,text:n,labelColor:i,fontFamily:o,fontSize:s,lineHeight:a,textAlign:l,verticalAlign:c,wrap:h,isSelected:u,padding:p=0,onKeyDown:g,classNamePrefix:m,style:y,textWidth:b,textHeight:x,showTextOutline:w=!0}){let v,S,C,k,P,{rInput:T,isEmpty:E,isEditing:I,isReadyForEditing:_,...M}=(S=(v=m5(e)).isEditing,C=(0,r.hGv)(),k=(0,f.useRef)(null),P=0===(n||"").trim().length,(0,f.useEffect)(()=>{function t(t){t.shapeId===e&&k.current?.select?.()}return C.on("select-all-text",t),()=>{C.off("select-all-text",t)}},[C,e,S]),(0,f.useEffect)(()=>{S&&(C.getContainerDocument().activeElement!==k.current&&k.current?.focus(),C.getInstanceState().isCoarsePointer&&k.current?.select(),r.YZA.isSafari&&(k.current?.blur(),k.current?.focus()))},[C,S]),{rInput:k,handleKeyDown:(0,f.useCallback)(t=>{C.getEditingShapeId()===e&&"Enter"===t.key&&(t.ctrlKey||t.metaKey)&&C.complete()},[C,e]),handleChange:(0,f.useCallback)(({plaintext:n})=>{if(C.getEditingShapeId()!==e)return;let r=rZ.normalizeText(n||"");C.updateShape({id:e,type:t,props:{text:r}})},[C,e,t]),isEmpty:P,...v}),A=rZ.normalizeTextForDom(n||""),j=A.length>0,O=m2(l);if(!I&&!j)return null;let D=m||"tl-text";return(0,d.jsx)("div",{className:`${D}-label tl-text-wrapper tl-plain-text-wrapper`,"aria-hidden":!I,"data-hastext":!E,"data-isediting":I,"data-is-ready-for-editing":_,"data-textwrap":!!h,"data-isselected":u,style:{fontFamily:o,textAlign:l,justifyContent:"center"===l||O?"center":"end"===l?"flex-end":"flex-start",alignItems:"middle"===c?"center":"end"===c?"flex-end":"flex-start",padding:p,...y},children:(0,d.jsxs)("div",{className:`${D}-label__inner tl-text-content__wrapper`,style:{fontSize:s,lineHeight:`${(0,r.OVI)(s,a)}px`,minHeight:`${(0,r.OVI)(s,a)}px`,minWidth:Math.ceil(b||0),color:i,width:b?Math.ceil(b):void 0,height:x?Math.ceil(x):void 0},children:[(0,d.jsx)("div",{className:ip(`${D} tl-text tl-text-content`,w?"tl-text__outline":"tl-text__no-outline"),dir:"auto",children:A.split("\n").map((e,t)=>(0,d.jsx)("div",{dir:"auto",children:e},t))}),(_||u)&&(0,d.jsx)(xW,{ref:T,text:n,isEditing:I,shapeId:e,...M,handleKeyDown:g??M.handleKeyDown})]})})});let xV={fonts:{tldraw_mono:`${(0,r.H__)()}/fonts/IBMPlexMono-Medium.woff2`,tldraw_mono_italic:`${(0,r.H__)()}/fonts/IBMPlexMono-MediumItalic.woff2`,tldraw_mono_bold:`${(0,r.H__)()}/fonts/IBMPlexMono-Bold.woff2`,tldraw_mono_italic_bold:`${(0,r.H__)()}/fonts/IBMPlexMono-BoldItalic.woff2`,tldraw_serif:`${(0,r.H__)()}/fonts/IBMPlexSerif-Medium.woff2`,tldraw_serif_italic:`${(0,r.H__)()}/fonts/IBMPlexSerif-MediumItalic.woff2`,tldraw_serif_bold:`${(0,r.H__)()}/fonts/IBMPlexSerif-Bold.woff2`,tldraw_serif_italic_bold:`${(0,r.H__)()}/fonts/IBMPlexSerif-BoldItalic.woff2`,tldraw_sans:`${(0,r.H__)()}/fonts/IBMPlexSans-Medium.woff2`,tldraw_sans_italic:`${(0,r.H__)()}/fonts/IBMPlexSans-MediumItalic.woff2`,tldraw_sans_bold:`${(0,r.H__)()}/fonts/IBMPlexSans-Bold.woff2`,tldraw_sans_italic_bold:`${(0,r.H__)()}/fonts/IBMPlexSans-BoldItalic.woff2`,tldraw_draw:`${(0,r.H__)()}/fonts/Shantell_Sans-Informal_Regular.woff2`,tldraw_draw_italic:`${(0,r.H__)()}/fonts/Shantell_Sans-Informal_Regular_Italic.woff2`,tldraw_draw_bold:`${(0,r.H__)()}/fonts/Shantell_Sans-Informal_Bold.woff2`,tldraw_draw_italic_bold:`${(0,r.H__)()}/fonts/Shantell_Sans-Informal_Bold_Italic.woff2`}};function xY(e){return(0,f.useMemo)(()=>e?{fonts:{...xV.fonts,...e?.fonts}}:xV,[e])}let xG={...xV,icons:Object.fromEntries(["align-bottom","align-center-horizontal","align-center-vertical","align-left","align-right","align-top","alt","arrow-arc","arrow-cycle","arrow-elbow","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","blob","bold","bookmark","bring-forward","bring-to-front","broken","bulletList","check-circle","check","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","closed","code","color","comment","corners","crop","cross-2","cross-circle","dash-dashed","dash-dotted","dash-draw","dash-solid","disconnected","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","download","drag-handle-dots","duplicate","edit","external-link","fill-fill","fill-lined-fill","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-heart","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","heading","help-circle","highlight","horizontal-align-end","horizontal-align-middle","horizontal-align-start","info-circle","italic","leading","link","list","lock","manual","menu","minus","mixed","pack","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","send-backward","send-to-back","share-1","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","status-offline","stretch-horizontal","stretch-vertical","strike","text-align-center","text-align-left","text-align-right","toggle-off","toggle-on","tool-arrow","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-screenshot","tool-text","trash","twitter","underline","undo","ungroup","unlock","vertical-align-end","vertical-align-middle","vertical-align-start","warning-triangle","zoom-in","zoom-out"].map(e=>[e,`${(0,r.H__)()}/icons/icon/0_merged.svg#${e}`])),translations:Object.fromEntries(r.Yjb.map(e=>[e.locale,`${(0,r.H__)()}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(o2.map(e=>[e.type,`${(0,r.H__)()}/embed-icons/${e.type}.png`]))};function xq(e){return(0,f.useMemo)(()=>e?{fonts:Object.assign({...xG.fonts},{...e?.fonts}),icons:Object.assign({...xG.icons},{...e?.icons}),embedIcons:Object.assign({...xG.embedIcons},{...e?.embedIcons}),translations:Object.assign({...xG.translations},{...e?.translations})}:xG,[e])}function xX(){let{Spinner:e}=(0,r.BSi)();return(0,d.jsx)(r.xxw,{children:e?(0,d.jsx)(e,{}):null})}let xJ=(0,r.u4I)(function({overrides:e,components:t,assetUrls:n,onUiEvent:i,forceMobile:o,mediaMimeTypes:s,children:a}){let l=(0,r.frr)();return(0,d.jsx)(lE.Provider,{value:s,children:(0,d.jsx)(S,{assetUrls:xq(n),children:(0,d.jsx)(_,{overrides:lM(e),locale:l?.user.getLocale()??r.TjI.locale,children:(0,d.jsx)(oi,{children:(0,d.jsx)(sR,{onEvent:i,children:(0,d.jsx)(lo,{children:(0,d.jsx)(a_,{context:"tla",children:(0,d.jsx)(x,{children:(0,d.jsx)(st,{forceMobile:o,children:(0,d.jsx)(p7,{overrides:t,children:(0,d.jsx)(xZ,{overrides:e,children:a})})})})})})})})})})})});function xZ({overrides:e,children:t}){let n,i,o=(n=lI(),i=l_(null==e?[]:Array.isArray(e)?e:[e]),(0,f.useMemo)(()=>(function(e,t){let n={};for(let t of e)if(t.translations)for(let[e,i]of(0,r.iAN)(t.translations)){let t=n[e];t||(t=n[e]={}),Object.assign(t,i)}return{actions:(t,n,r)=>{for(let i of e)i.actions&&(n=i.actions(t,n,r));return n},tools:(n,r,i)=>{for(let o of e)o.tools&&(r=o.tools(n,r,{...t,...i}));return r},translations:n}})(i,n),[i,n]));return(0,d.jsx)(fi,{overrides:o.actions,children:(0,d.jsx)(lj,{overrides:o.tools,children:t})})}let xQ=f.memo(function({renderDebugMenuItems:e,children:t,hideUi:n,components:r,...i}){return(0,d.jsx)(xJ,{...i,components:r,children:(0,d.jsx)(x0,{hideUi:n,renderDebugMenuItems:e,children:t})})}),x0=f.memo(function({children:e,hideUi:t,...n}){let i,o,s,a,l,c,h,u,p,g;return i=(0,r.hGv)(),o=sl(),s=fo(),a=lO(),l=hf(),c=(0,r.hau)("is focused",()=>i.getInstanceState().isFocused,[i]),(0,f.useEffect)(()=>{if(!c)return;let e=[],t=(t,n,r)=>{let i=function(e){let t=[];for(let n of pG(e)){let e=function(e){let t=e.split("+"),n={key:"",shift:!1,alt:!1,ctrl:!1,meta:!1},r="";for(let e=0;e<t.length;e++){let i=t[e];if(e===t.length-1)r=i;else{let e=pB[i.toLowerCase()];e&&(n[e]=!0)}}if(!r)return null;let i=r.toLowerCase();return pH[i]&&(i=pH[i]),n.key=i,n}(n);e&&t.push(e)}return t}(t);0!==i.length&&e.push({parsed:i,onKeyDown:n,onKeyUp:r})};for(let e of Object.values(s))e.kbd&&(!o||e.readonlyOk)&&(pN.includes(e.id)||t(pY(e.kbd),t=>{(!p$(i)||e.isRequiredA11yAction)&&((0,r.woC)(t),e.onSelect("kbd"))}));for(let e of Object.values(a))!(!e.kbd||!e.readonlyOk&&i.getIsReadonly()||pN.includes(e.id))&&("comment"!==e.id||l)&&t(pY(e.kbd),t=>{p$(i)||((0,r.woC)(t),e.onSelect("kbd"))});t(",",e=>{if(p$(i)||i.inputs.keys.has("Comma"))return;(0,r.woC)(e),i.focus(),i.inputs.keys.add("Comma");let{x:t,y:n,z:o}=i.inputs.getCurrentPagePoint(),s=i.pageToScreen({x:t,y:n}),a={type:"pointer",name:"pointer_down",point:{x:s.x,y:s.y,z:o},shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.metaKey||e.ctrlKey,metaKey:e.metaKey,accelKey:(0,r.gu7)(e),pointerId:0,button:0,isPen:i.getInstanceState().isPenMode,target:"canvas"};i.dispatch(a)},e=>{if(p$(i)||!i.inputs.keys.has("Comma"))return;i.inputs.keys.delete("Comma");let{x:t,y:n,z:o}=i.inputs.getCurrentPagePoint(),s=i.pageToScreen({x:t,y:n}),a={type:"pointer",name:"pointer_up",point:{x:s.x,y:s.y,z:o},shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.metaKey||e.ctrlKey,metaKey:e.metaKey,accelKey:(0,r.gu7)(e),pointerId:0,button:0,isPen:i.getInstanceState().isPenMode,target:"canvas"};i.dispatch(a)});let n=i.getContainerDocument().body,d=new Map,h=t=>{if(pV(t))return;let n=t.code;for(let r of e)if(r.onKeyDown){for(let e of r.parsed)if(pW(t,e)){if(n)if(t.repeat){let e=d.get(n);if(e&&e!==r)return}else d.set(n,r);r.onKeyDown(t);break}}},u=t=>{if(t.code&&d.delete(t.code),!pV(t)){for(let n of e)if(n.onKeyUp){for(let e of n.parsed)if(pW(t,e)){n.onKeyUp(t);break}}}};return n.addEventListener("keydown",h),n.addEventListener("keyup",u),()=>{n.removeEventListener("keydown",h),n.removeEventListener("keyup",u)}},[s,a,o,i,c,l]),u=(h=(0,r.hGv)()).getContainerDocument(),p=sF(),g=(0,r.hau)("editor.isFocused",()=>h.getInstanceState().isFocused,[h]),(0,f.useEffect)(()=>{if(!g)return;let e=async e=>{0===h.getSelectedShapeIds().length||null!==h.getEditingShapeId()||lx(h)||((0,r.woC)(e),await lk(h,{operation:"copy",source:"native"})&&p("copy",{source:"kbd"}))};async function t(e){0===h.getSelectedShapeIds().length||null!==h.getEditingShapeId()||lx(h)||((0,r.woC)(e),await lk(h,{operation:"cut",source:"native"})&&(h.deleteShapes(h.getSelectedShapeIds()),p("cut",{source:"kbd"})))}let n=!1,i=e=>{1===e.button&&(n=!0,h.timers.requestAnimationFrame(()=>{n=!1}))},o=!1,s=e=>{o=e.shiftKey},a=e=>{if(n)return void h.markEventAsHandled(e);if(null!==h.getEditingShapeId()||lx(h))return;if(o){let t=e.clipboardData?.getData("text/plain");if(t?.trim()){let n=h.user.getIsPasteAtCursorMode()?h.inputs.getCurrentPagePoint():h.getViewportPageBounds().center;h.markHistoryStoppingPoint("paste"),r9(h,{text:t,point:n}),(0,r.woC)(e),p("paste",{source:"kbd"});return}}let t=h.user.getIsPasteAtCursorMode()?h.inputs.getCurrentPagePoint():void 0;if(h.options.onClipboardPasteRaw?.({editor:h,source:"native-event",event:e,clipboardData:e.clipboardData,point:t})===!1){(0,r.woC)(e),p("paste",{source:"kbd"});return}let i=()=>{e.clipboardData&&lv(h,e.clipboardData,t)},s=h.getContainerWindow(),a=s.navigator;if(a.clipboard?.read){let n=Array.from(e.clipboardData?.files||[]);a.clipboard.read().then(e=>{Array.isArray(e)&&e[0]instanceof s.ClipboardItem&&lS({editor:h,clipboardItems:e,point:t,fallbackFiles:n,clipboardPasteSource:"native-event"})},()=>{i()})}else i();(0,r.woC)(e),p("paste",{source:"kbd"})};return u?.addEventListener("copy",e),u?.addEventListener("cut",t),u?.addEventListener("paste",a),u?.addEventListener("pointerup",i),u?.addEventListener("keydown",s,!0),u?.addEventListener("keyup",s,!0),()=>{u?.removeEventListener("copy",e),u?.removeEventListener("cut",t),u?.removeEventListener("paste",a),u?.removeEventListener("pointerup",i),u?.removeEventListener("keydown",s,!0),u?.removeEventListener("keyup",s,!0)}},[h,p,g,u]),(0,d.jsxs)(d.Fragment,{children:[e,t?null:(0,d.jsx)(x1,{...n})]})}),x1=f.memo(function(){let e=(0,r.hGv)(),t=M(),n=sn(),i=sl(),o=(0,r.hau)("focus",()=>e.getInstanceState().isFocusMode,[e]),s=(0,r.hau)("debug",()=>e.getInstanceState().isDebugMode,[e]),a=(0,r.NFA)(),l=A(),c=(0,r.hau)("locale",()=>e.user.getLocale(),[e]);(0,f.useEffect)(()=>{a.dir=l,a.lang=c},[a,l,c]);let{SharePanel:h,TopPanel:u,MenuPanel:p,StylePanel:g,Toolbar:m,HelpMenu:y,NavigationPanel:b,HelperButtons:x,DebugPanel:w,Toasts:v,Dialogs:S,A11y:C,FollowingIndicator:k}=fe();!function(){let e=(0,r.hGv)(),{addToast:t}=ls();(0,f.useEffect)(()=>{function n({name:e,count:r}){t({title:"Maximum shapes reached",description:`You've reached the maximum number of shapes allowed on ${e} (${r}). Please delete some shapes or move to a different page to continue.`,severity:"warning"})}return e.addListener("max-shapes",n),()=>{e.removeListener("max-shapes",n)}},[e,t])}();let P=(0,f.useRef)(!1),T=(0,f.useRef)(-1),[E,I]=(0,f.useState)(!1);(0,r.a1r)("update hide toolbar while delayed",()=>{if(r.YZA.isIos||r.YZA.isAndroid){if(null===e.getEditingShapeId()){P.current&&(P.current=!1,clearTimeout(T.current),r.YZA.isAndroid?T.current=e.timers.setTimeout(()=>{I(!1)},150):I(!1));return}P.current||(P.current=!0,clearTimeout(T.current),I(!0))}},[]);let{"toggle-focus-mode":_}=fo(),{breakpointsAbove:j,breakpointsBelow:O}=(0,f.useMemo)(()=>{let e=[],t=[];for(let r=0;r<o7.length;r++)r<=n?e.push(r):t.push(r);return{breakpointsAbove:e,breakpointsBelow:t}},[n]);return(0,d.jsxs)("div",{className:ip("tlui-layout",{"tlui-layout__mobile":n<5}),role:"document","data-iseditinganything":E,"data-breakpoint":n,"data-breakpoints-above":j.join(" "),"data-breakpoints-below":O.join(" "),children:[(0,d.jsx)(fc,{}),o?(0,d.jsx)("div",{className:"tlui-layout__top",children:(0,d.jsx)(od,{type:"icon",className:"tlui-focus-button",title:t("focus-mode.toggle-focus-mode"),onClick:()=>_.onSelect("menu"),children:(0,d.jsx)(oH,{icon:"dot"})})}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{className:"tlui-layout__top",children:[(0,d.jsxs)("div",{className:"tlui-layout__top__left",children:[p&&(0,d.jsx)(p,{}),x&&(0,d.jsx)(x,{})]}),(0,d.jsx)("div",{className:"tlui-layout__top__center",children:u&&(0,d.jsx)(u,{})}),(0,d.jsxs)("div",{className:"tlui-layout__top__right",children:[h&&(0,d.jsx)(h,{}),g&&n>=5&&!i&&(0,d.jsx)(g,{})]})]}),(0,d.jsxs)("div",{className:"tlui-layout__bottom",children:[(0,d.jsxs)("div",{className:"tlui-layout__bottom__main",children:[b&&(0,d.jsx)(b,{}),m&&(0,d.jsx)(m,{}),y&&(0,d.jsx)(y,{})]}),s&&w&&(0,d.jsx)(w,{}),C&&(0,d.jsx)(C,{})]})]}),k&&(0,d.jsx)(k,{}),v&&(0,d.jsx)(v,{}),S&&(0,d.jsx)(S,{})]})});function x2(){let{RichTextToolbar:e,ImageToolbar:t,VideoToolbar:n,CursorChatBubble:r}=fe();return(0,d.jsxs)(d.Fragment,{children:[e&&(0,d.jsx)(e,{}),t&&(0,d.jsx)(t,{}),n&&(0,d.jsx)(n,{}),r&&(0,d.jsx)(r,{})]})}let x3=[bJ,b2,b6,xK,xN,mB,my,mS,mj,mT,mb,mf,mC];function x5(e){let{children:t,maxImageDimension:n,maxAssetSize:i,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:a,components:l={},shapeUtils:c=[],bindingUtils:h=[],assetUtils:u=[],overlayUtils:p=[],tools:g=[],embeds:m,options:y,locale:b,textOptions:x,...w}=e,v=(0,r.dSk)(l),C=l?.InFrontOfTheCanvas,k=(0,f.useMemo)(()=>w.hideUi?C??null:C?()=>(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(x2,{}),(0,d.jsx)(C,{})]}):x2,[w.hideUi,C]),P=(0,f.useMemo)(()=>({Spinner:sf,LoadingScreen:xX,...v,InFrontOfTheCanvas:k}),[v,k]),T=(0,r.H80)(c),E=(0,f.useMemo)(()=>(0,r.OgJ)("type",T,bY),[T]),I=(0,r.H80)(h),M=(0,f.useMemo)(()=>(0,r.OgJ)("type",I,mc),[I]),A=(0,r.H80)(u),j=(0,f.useMemo)(()=>(function(e,t){let{maxImageDimension:n,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:i}=t,o=void 0!==n||void 0!==r,s=void 0!==i;return o||s?e.map(e=>o&&"image"===e.type?e.configure({...void 0!==n&&{maxDimension:n},...void 0!==r&&{supportedMimeTypes:r}}):s&&"video"===e.type?e.configure({...void 0!==i&&{supportedMimeTypes:i}}):e):e})((0,r.OgJ)("type",A,md),{maxImageDimension:n,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s}),[A,n,o,s]),O=(0,r.H80)(p),D=(0,f.useMemo)(()=>(0,r.OgJ)("type",O,mh),[O]),L=(0,r.H80)(g),R=(0,f.useMemo)(()=>(0,r.OgJ)("id",L,x3),[L]),F=(0,r.H80)(o??r.RBp),z=(0,r.H80)(s??r.qSO),N=y?.text??x,$=(0,f.useMemo)(()=>({addFontsFromNode:rJ,...N,tipTapConfig:{extensions:rU,...N?.tipTapConfig}}),[N]),B=(0,f.useMemo)(()=>({...y,text:$}),[y,$]),H=(0,f.useMemo)(()=>[...F,...z],[F,z]),U=xY(w.assetUrls);return E.find(e=>"embed"===e.type)&&m&&yX.setEmbedDefinitions(m),(0,d.jsx)(S,{assetUrls:xq(w.assetUrls),children:(0,d.jsx)(_,{overrides:lM(w.overrides),locale:b??w.user?.userPreferences.get().locale??r.TjI.locale,children:(0,d.jsx)(r.O75,{initialState:"select",...w,components:P,shapeUtils:E,bindingUtils:M,assetUtils:j,overlayUtils:D,tools:R,options:B,assetUrls:U,children:(0,d.jsxs)(xQ,{...w,components:P,mediaMimeTypes:H,children:[(0,d.jsx)(x6,{maxImageDimension:n,maxAssetSize:i,acceptedImageMimeTypes:F,acceptedVideoMimeTypes:z,onMount:a}),t]})})})})}function x6({maxImageDimension:e,maxAssetSize:t,acceptedImageMimeTypes:n,acceptedVideoMimeTypes:i,onMount:o}){let s=(0,r.hGv)(),a=ls(),l=M(),c=sF();(0,r.yfR)(()=>{var d;let h,u,p=[];for(let e of(p.push((h=e=>{s.getShapeUtil("embed").resolveAspectRatio(e)},u=s.sideEffects.register({shape:{afterCreate:(e,t)=>{"user"===t&&s.isShapeOfType(e,"embed")&&h(e)},afterChange:(e,t,n)=>{"user"===n&&s.isShapeOfType(t,"embed")&&e.props.url!==t.props.url&&h(t)}},instance:{afterChange:(e,t)=>{e.cameraState!==t.cameraState&&"idle"===t.cameraState&&mF(s)}},instance_page_state:{afterChange:(e,t)=>{if(e.croppingShapeId!==t.croppingShapeId){let n=s.isIn("select.crop");!e.croppingShapeId&&t.croppingShapeId?n||s.setCurrentTool("select.crop.idle"):e.croppingShapeId&&!t.croppingShapeId&&n&&s.setCurrentTool("select.idle")}if(e.editingShapeId!==t.editingShapeId)if(!e.editingShapeId&&t.editingShapeId){if(!s.isIn("select.editing_shape")){let e=s.getEditingShape();e&&"text"===e.type&&s.isInAny("text.pointing","select.resizing")&&s.getInstanceState().isToolLocked?s.setCurrentTool("select.editing_shape",{target:"shape",shape:e,isCreatingTextWhileToolLocked:!0}):s.setCurrentTool("select.editing_shape",{target:"shape",shape:e})}}else e.editingShapeId&&!t.editingShapeId&&s.isIn("select.editing_shape")&&s.setCurrentTool("select.idle")}}}),()=>{u(),mz(s)})),s.fonts.requestFonts(r$),Object.values(s.getThemes())))for(let t of Object.keys(e.fonts)){let n=e.fonts[t];n.faces?.length&&s.fonts.requestFonts(n.faces)}return s.once("edit",()=>c("edit",{source:"unknown"})),d={maxImageDimension:e,maxAssetSize:t,acceptedImageMimeTypes:n,acceptedVideoMimeTypes:i,toasts:a,msg:l},s.registerExternalAssetHandler("file",async e=>r3(s,e,d)),s.registerExternalAssetHandler("url",async e=>r6(s,e,d)),s.registerExternalContentHandler("svg-text",async e=>r4(s,e)),s.registerExternalContentHandler("embed",e=>(function(e,{point:t,url:n,embed:i}){let o=t??(e.inputs.getShiftKey()?e.inputs.getCurrentPagePoint():e.getViewportPageBounds().center),{width:s,height:a}=i,l=(0,r.n6Y)(),d=(0,r.Y8F)(new r.l2P(o.x-(s||450)/2,o.y-(a||450)/2),e),c={id:l,type:"embed",x:d.x,y:d.y,props:{w:s,h:a,url:n}};e.canCreateShape(c)&&e.createShape(c).select(l)})(s,e)),s.registerExternalContentHandler("files",async e=>r8(s,e,d)),s.registerExternalContentHandler("file-replace",async e=>r5(s,e,d)),s.registerExternalContentHandler("text",async e=>r9(s,e)),s.registerExternalContentHandler("url",async e=>r7(s,e,d)),s.registerExternalContentHandler("tldraw",async e=>ie(s,e)),s.registerExternalContentHandler("excalidraw",async e=>it(s,e)),p.push(s.store.props.onMount(s)),p.push(o?.(s)),()=>{p.forEach(e=>e?.())}});let{Canvas:h}=(0,r.BSi)(),{ContextMenu:u}=fe();return u?(0,d.jsx)(u,{}):h?(0,d.jsx)(h,{}):null}let x4={text:{tipTapConfig:{extensions:rU},addFontsFromNode:rJ}};(0,f.memo)(function(e){let[t,n]=(0,f.useState)(null),[i,o]=(0,f.useState)(null),s=(0,r.H80)(e.shapeUtils??[]),a=(0,f.useMemo)(()=>(0,r.OgJ)("type",s,bY),[s]),l=(0,r.H80)(e.bindingUtils??[]),c=(0,f.useMemo)(()=>(0,r.OgJ)("type",l,mc),[l]),h=(0,r.jXu)({snapshot:e.snapshot,shapeUtils:a,assets:e.assets}),{pageId:u,bounds:p,scale:g,pixelRatio:m,background:y,padding:b,darkMode:x,preserveAspectRatio:w,format:v="svg",licenseKey:S,assetUrls:C,options:k,textOptions:P}=e,T=(0,f.useMemo)(()=>({...x4,...k,text:{...x4.text,...k?.text??P}}),[k,P]),E=xY(C);return(0,f.useLayoutEffect)(()=>{if(!i||!h)return;let e=!1,t=i.ownerDocument.createElement("div");i.appendChild(t),i.classList.add("tl-container","tl-theme__light");let o=new r.KE6({store:h,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>t,licenseKey:S,fontAssetUrls:E.fonts,options:T});u&&o.setCurrentPage(u);let s=o.getCurrentPageShapeIds();return async function(){let t=await o.toImage([...s],{bounds:p,scale:g,background:y,padding:b,darkMode:x,preserveAspectRatio:w,format:v});!t||e||(n(URL.createObjectURL(t.blob)),o.dispose())}(),()=>{e=!0}},[v,i,h,a,c,u,p,g,y,b,x,w,S,m,E,T]),(0,f.useEffect)(()=>()=>{t&&URL.revokeObjectURL(t)},[t]),(0,d.jsx)("div",{ref:o,style:{position:"relative",width:"100%",height:"100%"},children:t&&(0,d.jsx)("img",{src:t,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})})}),(0,f.memo)(function({children:e}){let t=M(),n=sn(),i=(0,f.useRef)(null);(0,r.I9L)(i);let o=e??(0,d.jsx)(cZ,{});return n<4?null:(0,d.jsx)("div",{ref:i,className:"tlui-help-menu",children:(0,d.jsxs)(sN,{id:"help menu",children:[(0,d.jsx)(s$,{children:(0,d.jsx)(od,{type:"help",title:t("help-menu.title"),"data-testid":"help-menu.button",children:(0,d.jsx)(oH,{icon:"question-mark",small:!0})})}),(0,d.jsx)(sB,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:(0,d.jsx)(so,{type:"menu",sourceId:"help-menu",children:o})})]})})});var x8=Object.defineProperty,x9=(e,t)=>x8(e,"name",{value:t,configurable:!0}),x7=[" ","Enter","ArrowUp","ArrowDown"],we="Select",[wt,wn,wr]=(0,aj.N)(we),[wi,wo]=(0,iy.A)(we,[wr,iw.Bk]),ws=(0,iw.Bk)(),[wa,wl]=wi(we),[wd,wc]=wi(we);x9(function(e){let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:o,value:s,defaultValue:a,onValueChange:l,dir:c,name:h,autoComplete:u,disabled:p,required:g,form:m,internal_do_not_use_render:y}=e,b=ws(t),[x,w]=f.useState(null),[v,S]=f.useState(null),[C,k]=f.useState(!1),P=(0,sZ.jH)(c),[T,E]=(0,ik.i)({prop:r,defaultProp:i??!1,onChange:o,caller:we}),[I,_]=(0,ik.i)({prop:s,defaultProp:a,onChange:l,caller:we}),M=f.useRef(null),A=f.useRef(I);f.useEffect(()=>{let e=m?x?.ownerDocument.getElementById(m):x?.form;if(e instanceof HTMLFormElement){let t=x9(()=>_(A.current),"reset");return e.addEventListener("reset",t),()=>e.removeEventListener("reset",t)}},[m,x,_]);let j=!x||!!m||!!x.closest("form"),[O,D]=f.useState(new Set),L=(0,ix.B)(),R=Array.from(O).map(e=>e.props.value).join(";"),F=f.useCallback(e=>{D(t=>new Set(t).add(e))},[]),z=f.useCallback(e=>{D(t=>{let n=new Set(t);return n.delete(e),n})},[]),N={required:g,trigger:x,onTriggerChange:w,valueNode:v,onValueNodeChange:S,valueNodeHasChildren:C,onValueNodeHasChildrenChange:k,contentId:L,value:I,onValueChange:_,open:T,onOpenChange:E,dir:P,triggerPointerDownPosRef:M,disabled:p,name:h,autoComplete:u,form:m,nativeOptions:O,nativeSelectKey:R,isFormControl:j};return(0,d.jsx)(iw.bL,{...b,children:(0,d.jsx)(wa,{scope:t,...N,children:(0,d.jsx)(wt.Provider,{scope:t,children:(0,d.jsx)(wd,{scope:t,onNativeOptionAdd:F,onNativeOptionRemove:z,children:wk(y)?y(N):n})})})})},"SelectProvider");var wh=f.forwardRef(x9(function(e,t){let{__scopeSelect:n,disabled:r=!1,...i}=e,o=ws(n),s=wl("SelectTrigger",n),a=s.disabled||r,l=(0,im.s)(t,s.onTriggerChange),c=wn(n),h=f.useRef("touch"),[u,p,g]=wT(e=>{let t=c().filter(e=>!e.disabled),n=t.find(e=>e.value===s.value),r=wE(t,e,n);void 0!==r&&s.onValueChange(r.value)}),m=x9(e=>{a||(s.onOpenChange(!0),g()),e&&(s.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})},"handleOpen");return(0,d.jsx)(iw.Mz,{asChild:!0,...o,children:(0,d.jsx)(iS.sG.button,{type:"button",role:"combobox","aria-controls":s.open?s.contentId:void 0,"aria-expanded":s.open,"aria-required":s.required,"aria-autocomplete":"none",dir:s.dir,"data-state":s.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":wP(s.value)?"":void 0,...i,ref:l,onClick:(0,ig.mK)(i.onClick,e=>{e.currentTarget.focus(),"mouse"!==h.current&&m(e)}),onPointerDown:(0,ig.mK)(i.onPointerDown,e=>{h.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),0===e.button&&!1===e.ctrlKey&&"mouse"===e.pointerType&&(m(e),e.preventDefault())}),onKeyDown:(0,ig.mK)(i.onKeyDown,e=>{let t=""!==u.current;e.ctrlKey||e.altKey||e.metaKey||1!==e.key.length||p(e.key),(!t||" "!==e.key)&&x7.includes(e.key)&&(m(),e.preventDefault())})})})},"SelectTrigger")),wu=f.forwardRef(x9(function(e,t){let{__scopeSelect:n,children:r,...i}=e;return(0,d.jsx)(iS.sG.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})},"SelectIcon")),[wp,wf]=wi("SelectPortal",{forceMount:void 0}),wg="SelectContent",[wm,wy]=wi(wg);(0,iC.TL)("SelectContent.RemoveScroll");var[wb,wx]=wi(wg,{}),[ww,wv]=wi("SelectGroup"),[wS,wC]=wi("SelectItem");function wk(e){return"function"==typeof e}function wP(e){return""===e||void 0===e}function wT(e){let t=(0,aO.c)(e),n=f.useRef(""),r=f.useRef(0),i=f.useCallback(e=>{t(n.current+e)},[t]),o=f.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return f.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,o]}function wE(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,o=wI(e,Math.max(i,0));1===r.length&&(o=o.filter(e=>e!==n));let s=o.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return s!==n?s:void 0}function wI(e,t){return e.map((n,r)=>e[(t+r)%e.length])}x9(wk,"isFunction"),x9(wP,"shouldShowPlaceholder"),x9(wT,"useTypeaheadSearch"),x9(wE,"findNextItem"),x9(wI,"wrapArray"),f.forwardRef(function({children:e,className:t},n){return(0,d.jsxs)(wh,{ref:n,className:ip("tlui-button tlui-select__trigger",t),children:[e,(0,d.jsx)(wu,{className:"tlui-select__chevron",children:(0,d.jsx)(o$,{icon:"chevron-down",label:"",small:!0})})]})}),n(13248);let w_=r.T.object({schemaVersion:r.T.literal(1),storeVersion:r.T.positiveInteger,recordVersions:r.T.dict(r.T.string,r.T.object({version:r.T.positiveInteger,subTypeVersions:r.T.dict(r.T.string,r.T.positiveInteger).optional(),subTypeKey:r.T.string.optional()}))}),wM=r.T.object({schemaVersion:r.T.literal(2),sequences:r.T.dict(r.T.string,r.T.positiveInteger)});r.T.object({tldrawFileFormatVersion:r.T.nonZeroInteger,schema:r.T.numberUnion("schemaVersion",{1:w_,2:wM}),records:r.T.arrayOf(r.T.object({id:r.T.string,typeName:r.T.string}).allowUnknownProperties())}),(0,r.lFJ)("tldraw","5.3.2","esm")},23919:(e,t,n)=>{"use strict";n.d(t,{H:()=>s,b:()=>o});var r=n(24167),i=n(13656);async function o(e,t,n){let i=await (0,r.hd)(e);return new File([await i.arrayBuffer()],t,{type:n})}function s(){return`https://cdn.tldraw.com/${i.r}`}},24167:(e,t,n)=>{"use strict";let r,i,o;n.d(t,{RB:()=>Q,qS:()=>ee,Sm:()=>N,$3:()=>eZ,_V:()=>z,Qn:()=>W,K4:()=>et,f6:()=>ex,ZA:()=>q,Q7:()=>T,DM:()=>e4,xl:()=>e1,l:()=>O,as:()=>eA,TF:()=>R,vq:()=>S,zK:()=>ef,vA:()=>I,Z1:()=>_,oI:()=>j,sw:()=>eU,D6:()=>eY,oE:()=>b,sg:()=>D,Qq:()=>y,ZJ:()=>eV,h6:()=>E,hd:()=>F,J2:()=>eu,Xz:()=>eg,C$:()=>eG,zM:()=>eB,_9:()=>eK,Gw:()=>B,xp:()=>$,AQ:()=>eR,SB:()=>eF,HE:()=>eL,uu:()=>ez,Zo:()=>eD,MT:()=>eO,g5:()=>ea,mQ:()=>es,Fg:()=>er,O9:()=>e3,n4:()=>p,Ao:()=>em,HV:()=>x,Cc:()=>en,_H:()=>ep,Sk:()=>v,Og:()=>C,wq:()=>w,ww:()=>eo,lQ:()=>P,iA:()=>ec,_e:()=>eh,w$:()=>el,Ic:()=>ed,il:()=>M,lF:()=>a,Sh:()=>ei,yC:()=>e2,Yz:()=>eH,dQ:()=>eW,yy:()=>A,rb:()=>e$,Ky:()=>eN,pN:()=>e6,nF:()=>g,Uo:()=>e0,sb:()=>m,NF:()=>K,fb:()=>ej,mc:()=>e9});let s="__TLDRAW_LIBRARY_VERSIONS__";function a(e,t,n){if(!e||!t||!n)throw Error("Missing name/version/module system in built version of tldraw library");let r=function(){if(globalThis[s])return globalThis[s];let e={versions:[],didWarn:!1,scheduledNotice:null};return Object.defineProperty(globalThis,s,{value:e,writable:!1,configurable:!1,enumerable:!1}),e}();if(!(function(){try{return!1}catch{return!1}}()&&r.versions.some(r=>r.name===e&&r.version===t&&r.modules===n))&&(r.versions.push({name:e,version:t,modules:n}),!r.scheduledNotice))try{r.scheduledNotice=setTimeout(()=>{r.scheduledNotice=null,l(r)},100)}catch{l(r)}}function l(e){if(!e.versions.length||e.didWarn)return;let t=e.versions.sort((e,t)=>d(e.version,t.version)),n=t[t.length-1].version,r=new Set,i=new Map;for(let e of t){if(i.has(e.name)){r.delete(e.name),u(i,e.name,new Set).add(e.version);continue}e.version===n?r.add(e.name):(r.delete(e.name),u(i,e.name,new Set).add(e.version))}if(i.size>0){console.log([`${h("[tldraw]",["bold","bgRed","textWhite"])} ${h("You have multiple versions of tldraw libraries installed. This can lead to bugs and unexpected behavior.",["textRed","bold"])}`,"",`The latest version you have installed is ${h(`v${n}`,["bold","textBlue"])}. The following libraries are on the latest version:`,...Array.from(r,e=>` \u2022 \u2705 ${h(e,["bold"])}`),"","The following libraries are not on the latest version, or have multiple versions installed:",...Array.from(i,([e,t])=>{let r=Array.from(t).sort(d).map(e=>h(`v${e}`,e===n?["textGreen"]:["textRed"]));return` \u2022 \u274C ${h(e,["bold"])} (${r.join(", ")})`})].join("\n")),e.didWarn=!0;return}let o=new Map;for(let e of t)u(o,e.name,{version:e.version,modules:[]}).modules.push(e.modules);let s=new Map;for(let[e,t]of o)t.modules.length>1&&s.set(e,t);if(s.size>0){console.log([`${h("[tldraw]",["bold","bgRed","textWhite"])} ${h("You have multiple instances of some tldraw libraries active. This can lead to bugs and unexpected behavior. ",["textRed","bold"])}`,"","This usually means that your bundler is misconfigured, and is importing the same library multiple times - usually once as an ES Module, and once as a CommonJS module.","","The following libraries have been imported multiple times:",...Array.from(s,([e,t])=>{let n=t.modules.map((e,t)=>"esm"===e?` ${t+1}. ES Modules`:` ${t+1}. CommonJS`).join("\n");return` \u2022 \u274C ${h(e,["bold"])} v${t.version}:
115
- ${n}`}),"","You should configure your bundler to only import one version of each library."].join("\n")),e.didWarn=!0;return}}function d(e,t){let n=e.match(/^(\d+)\.(\d+)\.(\d+)(?:-(\w+))?$/),r=t.match(/^(\d+)\.(\d+)\.(\d+)(?:-(\w+))?$/);return n&&r?n[1]!==r[1]?Number(n[1])-Number(r[1]):n[2]!==r[2]?Number(n[2])-Number(r[2]):n[3]!==r[3]?Number(n[3])-Number(r[3]):n[4]&&r[4]?n[4].localeCompare(r[4]):n[4]?1:r[4]?-1:0:e.localeCompare(t)}let c={bold:"1",textBlue:"94",textRed:"31",textGreen:"32",bgRed:"41",textWhite:"97"};function h(e,t=[]){return`\x1b[${t.map(e=>c[e]).join(";")}m${e}\x1b[m`}function u(e,t,n){return e.has(t)?e.get(t):(e.set(t,n),n)}var p=n(94449),f=n(99017),g=n(71645),m=n(96116);function y(e,t){let n=[];i:for(let r of e){for(let e of n)if(t?t(r,e):r===e)continue i;n.push(r)}return n}function b(e){return e.filter(e=>null!=e)}function x(e){return e[e.length-1]}function w(e,t){let n,r=1/0;for(let i of e){let e=t(i);e<r&&(n=i,r=e)}return n}function v(e,t){let n,r=-1/0;for(let i of e){let e=t(i);e>r&&(n=i,r=e)}return n}function S(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0}function C(e,t,n){let r=new Set(t.map(t=>t[e])),i=[];for(let t of n)r.has(t[e])||i.push(t);for(let e of t)i.push(e);return i}function k(e){let t=(...n)=>{try{return e(...n)}catch(e){throw e instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(e,t),e}};return t}function P(){}let T={ok:e=>({ok:!0,value:e}),err:e=>({ok:!1,error:e}),all:e=>e.every(e=>e.ok)?T.ok(e.map(e=>e.value)):T.err(e.find(e=>!e.ok)?.error)};function E(e,t){let n=t&&e&&"object"==typeof e&&t in e?e[t]:e;throw Error(`Unknown switch case ${n}`)}let I=k((e,t)=>{if(!e)throw Error(t||"Assertion Error")}),_=k((e,t)=>{if(null==e)throw Error(t??"value must be defined");return e});function M(){let e,t;return Object.assign(new Promise((n,r)=>{e=n,t=r}),{resolve:e,reject:t})}function A(e){return new Promise(t=>setTimeout(t,e))}function j(...e){if(2===e.length){let[t,n]=e;n.addInitializer(function(){I(Reflect.isExtensible(this),"Cannot bind to a non-extensible class.");let e=t.bind(this);I(Reflect.defineProperty(this,n.name,{value:e,writable:!0,configurable:!0}),"Cannot bind a non-configurable class method.")})}else{let[t,n,r]=e;if(!r||"function"!=typeof r.value)throw TypeError(`Only methods can be decorated with @bind. <${n}> is not a method!`);return{configurable:!0,get(){let e=r.value.bind(this);return Object.defineProperty(this,n,{value:e,configurable:!0,writable:!0}),e}}}}class O{items=new WeakMap;get(e,t){return this.items.has(e)||this.items.set(e,t(e)),this.items.get(e)}}function D(e,t){let n,r=(...r)=>(n||((n={}).promise=new Promise((e,t)=>{n.resolve=e,n.reject=t})),clearTimeout(n.timeout),n.latestArgs=r,n.timeout=setTimeout(()=>{let t=n;n=void 0;try{t.resolve(e(...t.latestArgs))}catch(e){t.reject(e)}},t),n.promise);return r.cancel=()=>{if(!n)return;clearTimeout(n.timeout);let e=n;n=void 0,e.promise.catch(P),e.reject(Error("Debounced function was cancelled"))},r}let L=new WeakMap;function R(e,t){if("object"!=typeof e||null===e)return;let n=L.get(e);n||(n={tags:{},extras:{}},L.set(e,n)),t.tags&&(n.tags={...n.tags,...t.tags}),t.extras&&(n.extras={...n.extras,...t.extras})}async function F(e,t){return window.fetch(e,{referrerPolicy:"strict-origin-when-cross-origin",...t})}function z(e,t){let n=new window.Image(e,t);return n.referrerPolicy="strict-origin-when-cross-origin",n}class N{static async urlToArrayBuffer(e){let t=await F(e);return await t.arrayBuffer()}static async urlToBlob(e){let t=await F(e);return await t.blob()}static async urlToDataUrl(e){if(e.startsWith("data:"))return e;let t=await N.urlToBlob(e);return await N.blobToDataUrl(t)}static async blobToDataUrl(e){return await new Promise((t,n)=>{if(e){let r=new FileReader;r.onload=()=>t(r.result),r.onerror=e=>n(e),r.onabort=e=>n(e),r.readAsDataURL(e)}})}static async blobToText(e){return await new Promise((t,n)=>{if(e){let r=new FileReader;r.onload=()=>t(r.result),r.onerror=e=>n(e),r.onabort=e=>n(e),r.readAsText(e)}})}static rewriteMimeType(e,t){return e.type===t?e:e instanceof File?new File([e],e.name,{type:t}):new Blob([e],{type:t})}}function $(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return t+""}function B(e){let t=new DataView(e),n=0;for(let e=0;e<t.byteLength;e++)n=(n<<5)-n+t.getUint8(e)|0;return n+""}let H=globalThis.crypto,U=function(e=21){var t;t=e-=0,!r||r.length<t?(r=new Uint8Array(128*t),H.getRandomValues(r),i=0):i+t>r.length&&(H.getRandomValues(r),i=0),i+=t;let n="";for(let t=i-e;t<i;t++)n+="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[63&r[t]];return n};function K(e){return U(e)}class W{constructor(e){this.maxSize=e}maxSize;map=new Map;get(e){if(!this.map.has(e))return;let t=this.map.get(e);return this.map.delete(e),this.map.set(e,t),t}set(e,t){this.map.has(e)&&this.map.delete(e),this.map.set(e,t),this.map.size>this.maxSize&&this.map.delete(this.map.keys().next().value)}has(e){return this.map.has(e)}get size(){return this.map.size}}var V=n(92619).Buffer;function Y(e,t){let n=0;for(;e[t+n];)n+=e[t+n]+1;return n+1}let G=[0,0x77073096,0xee0e612c,0x990951ba,0x76dc419,0x706af48f,0xe963a535,0x9e6495a3,0xedb8832,0x79dcb8a4,0xe0d5e91e,0x97d2d988,0x9b64c2b,0x7eb17cbd,0xe7b82d07,0x90bf1d91,0x1db71064,0x6ab020f2,0xf3b97148,0x84be41de,0x1adad47d,0x6ddde4eb,0xf4d4b551,0x83d385c7,0x136c9856,0x646ba8c0,0xfd62f97a,0x8a65c9ec,0x14015c4f,0x63066cd9,0xfa0f3d63,0x8d080df5,0x3b6e20c8,0x4c69105e,0xd56041e4,0xa2677172,0x3c03e4d1,0x4b04d447,0xd20d85fd,0xa50ab56b,0x35b5a8fa,0x42b2986c,0xdbbbc9d6,0xacbcf940,0x32d86ce3,0x45df5c75,0xdcd60dcf,0xabd13d59,0x26d930ac,0x51de003a,0xc8d75180,0xbfd06116,0x21b4f4b5,0x56b3c423,0xcfba9599,0xb8bda50f,0x2802b89e,0x5f058808,0xc60cd9b2,0xb10be924,0x2f6f7c87,0x58684c11,0xc1611dab,0xb6662d3d,0x76dc4190,0x1db7106,0x98d220bc,0xefd5102a,0x71b18589,0x6b6b51f,0x9fbfe4a5,0xe8b8d433,0x7807c9a2,0xf00f934,0x9609a88e,0xe10e9818,0x7f6a0dbb,0x86d3d2d,0x91646c97,0xe6635c01,0x6b6b51f4,0x1c6c6162,0x856530d8,0xf262004e,0x6c0695ed,0x1b01a57b,0x8208f4c1,0xf50fc457,0x65b0d9c6,0x12b7e950,0x8bbeb8ea,0xfcb9887c,0x62dd1ddf,0x15da2d49,0x8cd37cf3,0xfbd44c65,0x4db26158,0x3ab551ce,0xa3bc0074,0xd4bb30e2,0x4adfa541,0x3dd895d7,0xa4d1c46d,0xd3d6f4fb,0x4369e96a,0x346ed9fc,0xad678846,0xda60b8d0,0x44042d73,0x33031de5,0xaa0a4c5f,0xdd0d7cc9,0x5005713c,0x270241aa,0xbe0b1010,0xc90c2086,0x5768b525,0x206f85b3,0xb966d409,0xce61e49f,0x5edef90e,0x29d9c998,0xb0d09822,0xc7d7a8b4,0x59b33d17,0x2eb40d81,0xb7bd5c3b,0xc0ba6cad,0xedb88320,0x9abfb3b6,0x3b6e20c,0x74b1d29a,0xead54739,0x9dd277af,0x4db2615,0x73dc1683,0xe3630b12,0x94643b84,0xd6d6a3e,0x7a6a5aa8,0xe40ecf0b,0x9309ff9d,0xa00ae27,0x7d079eb1,0xf00f9344,0x8708a3d2,0x1e01f268,0x6906c2fe,0xf762575d,0x806567cb,0x196c3671,0x6e6b06e7,0xfed41b76,0x89d32be0,0x10da7a5a,0x67dd4acc,0xf9b9df6f,0x8ebeeff9,0x17b7be43,0x60b08ed5,0xd6d6a3e8,0xa1d1937e,0x38d8c2c4,0x4fdff252,0xd1bb67f1,0xa6bc5767,0x3fb506dd,0x48b2364b,0xd80d2bda,0xaf0a1b4c,0x36034af6,0x41047a60,0xdf60efc3,0xa867df55,0x316e8eef,0x4669be79,0xcb61b38c,0xbc66831a,0x256fd2a0,0x5268e236,0xcc0c7795,0xbb0b4703,0x220216b9,0x5505262f,0xc5ba3bbe,0xb2bd0b28,0x2bb45a92,0x5cb36a04,0xc2d7ffa7,0xb5d0cf31,0x2cd99e8b,0x5bdeae1d,0x9b64c2b0,0xec63f226,0x756aa39c,0x26d930a,0x9c0906a9,0xeb0e363f,0x72076785,0x5005713,0x95bf4a82,0xe2b87a14,0x7bb12bae,0xcb61b38,0x92d28e9b,0xe5d5be0d,0x7cdcefb7,0xbdbdf21,0x86d3d2d4,0xf1d4e242,0x68ddb3f8,0x1fda836e,0x81be16cd,0xf6b9265b,0x6fb077e1,0x18b74777,0x88085ae6,0xff0f6a70,0x66063bca,0x11010b5c,0x8f659eff,0xf862ae69,0x616bffd3,0x166ccf45,0xa00ae278,0xd70dd2ee,0x4e048354,0x3903b3c2,0xa7672661,0xd06016f7,0x4969474d,0x3e6e77db,0xaed16a4a,0xd9d65adc,0x40df0b66,936918e3,0xa9bcae53,0xdebb9ec5,0x47b2cf7f,0x30b5ffe9,0xbdbdf21c,0xcabac28a,0x53b39330,0x24b4a3a6,0xbad03605,0xcdd70693,0x54de5729,0x23d967bf,0xb3667a2e,0xc4614ab8,0x5d681b02,0x2a6f2b94,0xb40bbe37,0xc30c8ea1,0x5a05df1b,0x2d02ef8d];"u">typeof Int32Array&&(G=new Int32Array(G));class q{static isPng(e,t){return 137===e.getUint8(t+0)&&80===e.getUint8(t+1)&&78===e.getUint8(t+2)&&71===e.getUint8(t+3)&&13===e.getUint8(t+4)&&10===e.getUint8(t+5)&&26===e.getUint8(t+6)&&10===e.getUint8(t+7)||!1}static getChunkType(e,t){return[String.fromCharCode(e.getUint8(t)),String.fromCharCode(e.getUint8(t+1)),String.fromCharCode(e.getUint8(t+2)),String.fromCharCode(e.getUint8(t+3))].join("")}static readChunks(e,t=0){let n={};if(!q.isPng(e,t))throw Error("Not a PNG");for(t+=8;t<=e.buffer.byteLength;){let r=t,i=e.getInt32(t);t+=4;let o=q.getChunkType(e,t);if("IDAT"===o&&n[o]){t+=i+4+4;continue}if("IEND"===o)break;n[o]={start:r,dataOffset:t+4,size:i},t+=i+4+4}return n}static parsePhys(e,t){return{ppux:e.getUint32(t),ppuy:e.getUint32(t+4),unit:e.getUint8(t+8)}}static findChunk(e,t){return q.readChunks(e)[t]}static setPhysChunk(e,t=1,n){let r=46,i=0,o=q.findChunk(e,"pHYs");o&&(r=o.start,i=o.size);let s=q.findChunk(e,"IDAT");s&&(r=s.start,i=0);let a=new ArrayBuffer(21),l=new DataView(a);l.setUint32(0,9),l.setUint8(4,112),l.setUint8(5,72),l.setUint8(6,89),l.setUint8(7,115),l.setInt32(8,2835.5*t),l.setInt32(12,2835.5*t),l.setInt8(16,1);let d=new Uint8Array(a.slice(4,17));return l.setInt32(17,(e=>{let t=-1^~~void 0;for(let n=0;n<e.length;n++)t=G[(t^e[n])&255]^t>>>8;return -1^t})(d)),new Blob([e.buffer.slice(0,r),a,e.buffer.slice(r+i)],n)}}let X=Object.freeze(["image/svg+xml"]),J=Object.freeze(["image/jpeg","image/png","image/webp"]),Z=Object.freeze(["image/gif","image/apng","image/avif"]),Q=Object.freeze([...J,...X,...Z]),ee=Object.freeze(["video/mp4","video/webm","video/quicktime"]);Object.freeze([...Q,...ee]).join(",");class et{static loadVideo(e,t){return new Promise((n,r)=>{let i=(t??document).createElement("video");i.onloadeddata=()=>n(i),i.onerror=e=>{console.error(e),r(Error("Could not load video"))},i.crossOrigin="anonymous",i.src=e})}static async getVideoFrameAsDataUrl(e,t=0){let n=M(),r=!1,i=()=>{if(!r)if(!(e.readyState>=e.HAVE_METADATA))return;else r=!0,e.currentTime=t;if(e.readyState>=e.HAVE_CURRENT_DATA){let t=(e.ownerDocument??document).createElement("canvas");t.width=e.videoWidth,t.height=e.videoHeight;let r=t.getContext("2d");if(!r)throw Error("Could not get 2d context");r.drawImage(e,0,0),n.resolve(t.toDataURL())}},o=e=>{console.error(e),n.reject(Error("Could not get video frame"))};e.addEventListener("loadedmetadata",i),e.addEventListener("loadeddata",i),e.addEventListener("canplay",i),e.addEventListener("seeked",i),e.addEventListener("error",o),e.addEventListener("stalled",o),i();try{return await n}finally{e.removeEventListener("loadedmetadata",i),e.removeEventListener("loadeddata",i),e.removeEventListener("canplay",i),e.removeEventListener("seeked",i),e.removeEventListener("error",o),e.removeEventListener("stalled",o)}}static getImageAndDimensions(e,t){return new Promise((n,r)=>{let i=z();i.onload=()=>{let e;if(i.naturalWidth)e={w:i.naturalWidth,h:i.naturalHeight};else{let n=(t??document).body;n.appendChild(i),e={w:i.clientWidth,h:i.clientHeight},n.removeChild(i)}n({...e,image:i})},i.onerror=e=>{console.error(e),r(Error("Could not load image"))},i.crossOrigin="anonymous",i.referrerPolicy="strict-origin-when-cross-origin",i.style.visibility="hidden",i.style.position="absolute",i.style.opacity="0",i.style.zIndex="-9999",i.src=e})}static async getVideoSize(e,t){return et.usingObjectURL(e,async e=>{let n=await et.loadVideo(e,t);return{w:n.videoWidth,h:n.videoHeight}})}static async getImageSize(e,t){let{w:n,h:r}=await et.usingObjectURL(e,e=>et.getImageAndDimensions(e,t));try{if("image/png"===e.type){let t=new DataView(await e.arrayBuffer());if(q.isPng(t,0)){let e=q.findChunk(t,"pHYs");if(e){let i=q.parsePhys(t,e.dataOffset);if(1===i.unit&&i.ppux===i.ppuy){let e=Math.round(.0254*i.ppux),t=e/96,o=e/72,s=1;if(Number.isInteger(t)&&t>1?s=t:Number.isInteger(o)&&o>1&&(s=o),s>1)return{w:Math.ceil(n/s),h:Math.ceil(r/s),pixelRatio:s}}}}}}catch(e){console.error(e)}return{w:n,h:r,pixelRatio:1}}static async isAnimated(e){if("image/gif"===e.type)return function(e){let t,n,r=new Uint8Array(e),i=0,o=0;if("GIF"!==new TextDecoder("ascii").decode(e.slice(0,3)))return!1;for(t=128&r[10],n=7&r[10],i+=6,i+=7,i+=t?3*Math.pow(2,n+1):0;o<2&&i<r.length;)switch(r[i]){case 44:o+=1,t=128&r[i+9],n=7&r[i+9],i+=10,i+=t?3*Math.pow(2,n+1):0,i+=Y(r,i+1)+1;break;case 33:i+=2,i+=Y(r,i);break;default:i=r.length}return o>1}(await e.arrayBuffer());if("image/avif"===e.type)return 44===new Uint8Array(await e.arrayBuffer())[3];if("image/webp"===e.type){let t;return t=new Uint8Array(await e.arrayBuffer()),!(t.length<12)&&87===t[8]&&69===t[9]&&66===t[10]&&80===t[11]&&!!t&&!(t.length<21)&&(t[20]>>1&1)==1}return"image/apng"===e.type&&function(e){let t=new Uint8Array(e);if(!t||!(void 0!==V&&V.isBuffer(t)||t instanceof Uint8Array)||t.length<16||137!==t[0]||80!==t[1]||78!==t[2]||71!==t[3]||13!==t[4]||10!==t[5]||26!==t[6]||10!==t[7])return!1;function n(e,t,r,i,o=1024){if(!t)return -1;let s=(t=RegExp(t,"g")).source.length,a=new TextDecoder,l=e.length;if(void 0===i&&(i=l),r>=l||i<=0||r>=i)return -1;e=e.subarray(r,i);let d=-1,c=0,h=0,u="";r:for(;c<e.length;){let n,r=c+o,i=e.subarray(c,r),l=a.decode(i,{stream:!0}),p=u+l,f=-1;for(;null!==(n=t.exec(p));){d=h+(f=n.index-u.length);break r}c=r,h+=l.length;let g=f>-1?f+s:l.length-s;u=l.slice(g)}return d>=0&&(d+=r>=0?r:l+r),d}let r=n(t,"IDAT",12);return r>=12&&n(t,"acTL",8,r)>=8}(await e.arrayBuffer())}static isAnimatedImageType(e){return Z.includes(e||"")}static isStaticImageType(e){return J.includes(e||"")}static isVectorImageType(e){return X.includes(e||"")}static isImageType(e){return Q.includes(e||"")}static async usingObjectURL(e,t){let n=URL.createObjectURL(e);try{return await t(n)}finally{URL.revokeObjectURL(n)}}}function en(e,t,n){return e+(t-e)*n}function er(e,t,n){return(n-e)/(t-e)}function ei(e=""){let t=0,n=0,r=0,i=0;function o(){let e=t^t<<11;return t=n,n=r,r=i,(i^=(i>>>19^e^e>>>8)>>>0)/0x100000000*2}for(let n=0;n<e.length+64;n++)t^=e.charCodeAt(n),o();return o}function eo(e,t,n,r=!1){let[i,o]=t,[s,a]=n,l=s+(e-i)/(o-i)*(a-s);return r?s<a?Math.max(Math.min(l,a),s):Math.max(Math.min(l,s),a):l}function es(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function ea(e,t){if(es(e,t))return e[t]}function el(e){return Object.keys(e)}function ed(e){return Object.values(e)}function ec(e){return Object.entries(e)}function eh(e){return Object.fromEntries(e)}function eu(e,t){let n={},r=!1;for(let i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;let o=e[i];t(i,o)?n[i]=o:r=!0}return r?n:e}function ep(e,t){let n={};for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=t(r,e[r]));return n}function ef(e,t){if(e===t)return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!es(t,r)||!Object.is(e[r],t[r]))return!1;return!0}function eg(e,t){let n=[];for(let r in e)Object.is(e[r],t[r])||n.push(r);return n}function em(e,t,n=1e-6){return f(e,t,(e,t)=>{if("number"==typeof e&&"number"==typeof t)return Math.abs(e-t)<n})}let ey="#40C057",eb="#FFC078";class ex{startTime=0;name="";frames=0;started=!1;frame=null;recordFrame=()=>{this.frames++,this.started&&(this.frame=requestAnimationFrame(this.recordFrame))};start(e){this.name=e,this.frames=0,this.started=!0,null!==this.frame&&cancelAnimationFrame(this.frame),this.frame=requestAnimationFrame(this.recordFrame),this.startTime=performance.now()}stop(){this.started=!1,null!==this.frame&&cancelAnimationFrame(this.frame);let e=(performance.now()-this.startTime)/1e3,t=0===e?0:Math.floor(this.frames/e),n=t>55?ey:t>30?eb:"#E03131",r=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${r} %c${t}%c fps`,`color: white; background: ${ey};padding: 2px;border-radius: 3px;`,"font-weight: normal",`font-weight: bold; padding: 2px; background: ${n};color: ${n===eb?"black":"white"};`,"font-weight: normal")}isStarted(){return this.started}}let ew="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",ev=ew[0],eS=ew[ew.length-1],eC="A"+ev.repeat(26);function ek(e){let t=function(e){if(e>="a"&&e<="z")return e.charCodeAt(0)-97+2;if(e>="A"&&e<="Z")return 90-e.charCodeAt(0)+2;throw Error("invalid order key head: "+e)}(e[0]);if(t>e.length)throw Error("invalid order key: "+e);return e.slice(0,t)}function eP(e){let t=e.charCodeAt(0);return t<=57?t-48:t<=90?t-55:t-61}function eT(e){if(e===eC)throw Error("invalid order key: "+e);let t=ek(e);if(e.length>t.length&&e[e.length-1]===ev)throw Error("invalid order key: "+e)}function eE(e,t){if(null!=t&&e>=t)throw Error(e+" >= "+t);if(e.slice(-1)===ev||t&&t.slice(-1)===ev)throw Error("trailing zero");if(t){let n=0;for(;(e[n]||ev)===t[n];)n++;if(n>0)return t.slice(0,n)+eE(e.slice(n),t.slice(n))}let n=e?eP(e[0]):0,r=null!=t?eP(t[0]):ew.length;return r-n>1?ew[Math.round(.5*(n+r))]:t&&t.length>1?t.slice(0,1):ew[n]+eE(e.slice(1),null)}function eI(e){let[t,...n]=e.split(""),r=!0;for(let e=n.length-1;r&&e>=0;e--){let t=eP(n[e])+1;t===ew.length?n[e]=ev:(n[e]=ew[t],r=!1)}if(r){if("Z"===t)return"a"+ev;if("z"===t)return null;let e=String.fromCharCode(t.charCodeAt(0)+1);return e>"a"?n.push(ev):n.pop(),e+n.join("")}return t+n.join("")}function e_(e,t){if(null!=e&&null!=t&&e>=t)throw Error(e+" >= "+t);if(null==e){if(null==t)return"a"+ev;let e=ek(t),n=t.slice(e.length);if(e===eC)return e+eE("",n);if(e<t)return e;let r=function(e){let[t,...n]=e.split(""),r=!0;for(let e=n.length-1;r&&e>=0;e--){let t=eP(n[e])-1;-1===t?n[e]=eS:(n[e]=ew[t],r=!1)}if(r){if("a"===t)return"Z"+eS;if("A"===t)return null;let e=String.fromCharCode(t.charCodeAt(0)-1);return e<"Z"?n.push(eS):n.pop(),e+n.join("")}return t+n.join("")}(e);if(null==r)throw Error("cannot decrement any more");return r}if(null==t){let t=ek(e),n=e.slice(t.length),r=eI(t);return null==r?t+eE(n,null):r}let n=ek(e),r=e.slice(n.length),i=ek(t),o=t.slice(i.length);if(n===i)return n+eE(r,o);let s=eI(n);if(null==s)throw Error("cannot increment any more");return s<t?s:n+eE(r,null)}let eM=function(e,t,n){if(0===n)return[];null!=e&&eT(e),null!=t&&eT(t);let r=function e(t,n,r){if(0===r)return[];if(1===r)return[e_(t,n)];if(null==n){let e=e_(t,n),i=[e];for(let t=0;t<r-1;t++)i.push(e=e_(e,n));return i}if(null==t){let e=e_(t,n),i=[e];for(let n=0;n<r-1;n++)i.push(e=e_(t,e));return i.reverse(),i}let i=Math.floor(r/2),o=e_(t,n);return[...e(t,o,i),o,...e(o,n,r-i-1)]}(e,t,n+1),i=Array(n);for(let e=0;e<n;e++)i[e]=function(e,t){let n=e_(e,t);for(let r=0;r<16;r++).5>Math.random()?e=n:t=n,n=e_(e,t);return n}(r[e],r[e+1]);return i},eA="a0";function ej(e){try{eT(e)}catch{throw Error("invalid index: "+e)}}function eO(e,t,n){return eM(e??null,t??null,n)}function eD(e,t){return eM(e??null,null,t)}function eL(e,t){return eM(e??null,t??null,1)[0]}function eR(e=null){return eM(e,null,1)[0]}function eF(e=null){return eM(null,e,1)[0]}function ez(e,t="a1"){return[t,...eM(t,null,e)]}function eN(e,t){return e.index<t.index?-1:+(e.index>t.index)}function e$(e,t){return e.id>t.id?1:-1}function eB(e){try{return localStorage.getItem(e)}catch{return null}}function eH(e,t){try{localStorage.setItem(e,t)}catch{}}function eU(){try{localStorage.clear()}catch{}}function eK(e){try{return sessionStorage.getItem(e)}catch{return null}}function eW(e,t){try{sessionStorage.setItem(e,t)}catch{}}function eV(e){try{sessionStorage.removeItem(e)}catch{}}function eY(){try{sessionStorage.clear()}catch{}}function eG(e){if(!e)return"";for(let{segment:t}of(o??=new Intl.Segmenter(void 0,{granularity:"grapheme"})).segment(e))return t;return""}var eq=n(41463);let eX=()=>void 0!==eq&&!1,eJ=e=>.9*Math.floor(1e3/e);class eZ{targetFps;targetTimePerFrame;fpsQueue=[];frameRaf;flushRaf;lastFlushTime;constructor(e=120){this.targetFps=e,this.targetTimePerFrame=eJ(e),this.lastFlushTime=-this.targetTimePerFrame}updateTargetFps(e){e!==this.targetFps&&(this.targetFps=e,this.targetTimePerFrame=eJ(e),this.lastFlushTime=-this.targetTimePerFrame)}flush(){for(let e of this.fpsQueue.splice(0,this.fpsQueue.length))e()}tick(e=!1){if(this.frameRaf)return;let t=Date.now();if(t-this.lastFlushTime<this.targetTimePerFrame){this.frameRaf=requestAnimationFrame(()=>{this.frameRaf=void 0,this.tick(!0)});return}if(e){if(this.flushRaf)return;this.lastFlushTime=t,this.flush()}else{if(this.flushRaf)return;this.flushRaf=requestAnimationFrame(()=>{this.flushRaf=void 0,this.lastFlushTime=Date.now(),this.flush()})}}fpsThrottle(e){if(eX())return e.cancel=()=>{this.frameRaf&&(cancelAnimationFrame(this.frameRaf),this.frameRaf=void 0),this.flushRaf&&(cancelAnimationFrame(this.flushRaf),this.flushRaf=void 0)},e;let t=()=>{this.fpsQueue.includes(e)||(this.fpsQueue.push(e),this.tick())};return t.cancel=()=>{let t=this.fpsQueue.indexOf(e);t>-1&&this.fpsQueue.splice(t,1)},t}throttleToNextFrame(e){return eX()?(e(),()=>void 0):(this.fpsQueue.includes(e)||(this.fpsQueue.push(e),this.tick()),()=>{let t=this.fpsQueue.indexOf(e);t>-1&&this.fpsQueue.splice(t,1)})}}let eQ=new eZ(120);function e0(e){return eQ.throttleToNextFrame(e)}class e1{timeouts=new Map;intervals=new Map;rafs=new Map;constructor(){this.setTimeout=this.setTimeout.bind(this),this.setInterval=this.setInterval.bind(this),this.requestAnimationFrame=this.requestAnimationFrame.bind(this),this.dispose=this.dispose.bind(this)}setTimeout(e,t,n,...r){let i=window.setTimeout(t,n,r),o=this.timeouts.get(e)??[];return this.timeouts.set(e,[...o,i]),i}setInterval(e,t,n,...r){let i=window.setInterval(t,n,r),o=this.intervals.get(e)??[];return this.intervals.set(e,[...o,i]),i}requestAnimationFrame(e,t){let n=window.requestAnimationFrame(t),r=this.rafs.get(e)??[];return this.rafs.set(e,[...r,n]),n}dispose(e){this.timeouts.get(e)?.forEach(e=>clearTimeout(e)),this.intervals.get(e)?.forEach(e=>clearInterval(e)),this.rafs.get(e)?.forEach(e=>cancelAnimationFrame(e)),this.timeouts.delete(e),this.intervals.delete(e),this.rafs.delete(e)}disposeAll(){for(let e of this.timeouts.keys())this.dispose(e)}forContext(e){return{setTimeout:(t,n,...r)=>this.setTimeout(e,t,n,r),setInterval:(t,n,...r)=>this.setInterval(e,t,n,r),requestAnimationFrame:t=>this.requestAnimationFrame(e,t),dispose:()=>this.dispose(e)}}}function e2(e,t){try{return new URL(e,t)}catch{return}}function e3(e){return void 0!==e}let e5="u">typeof globalThis&&globalThis.structuredClone?[globalThis.structuredClone,!0]:"u">typeof global&&global.structuredClone?[global.structuredClone,!0]:"u">typeof window&&window.structuredClone?[window.structuredClone,!0]:[e=>e?JSON.parse(JSON.stringify(e)):e,!1],e6=e5[0];e5[1];let e4=Object.getPrototypeOf(e6({})),e8=new Set;function e9(e){e8.has(e)||(e8.add(e),console.warn(`[tldraw] ${e}`))}a("@tldraw/utils","5.3.2","esm")},26065:(e,t,n)=>{"use strict";n.d(t,{R:()=>l,n:()=>a});var r=n(95155),i=n(12115),o=n(16038);let s=(0,i.createContext)(null);function a({children:e}){let t=(0,i.useRef)(new Map),n=(0,i.useCallback)((e,n,r,i)=>{let s=i?"none":"block";(0,o.$h)(n,"display",s),(0,o.$h)(r,"display",s),t.current.set(e,{container:n,bgContainer:r,isCulled:i})},[]),l=(0,i.useCallback)(e=>{t.current.delete(e)},[]),d=(0,i.useCallback)(e=>{let n;for(let[r,i]of t.current)if((n=e.has(r))!==i.isCulled){let e=n?"none":"block";(0,o.$h)(i.container,"display",e),(0,o.$h)(i.bgContainer,"display",e),i.isCulled=n}},[]),c=(0,i.useMemo)(()=>({register:n,unregister:l,updateCulling:d}),[n,l,d]);return(0,r.jsx)(s.Provider,{value:c,children:e})}function l(){let e=(0,i.useContext)(s);if(!e)throw Error("useShapeCulling must be used within ShapeCullingProvider");return e}},26614:(e,t,n)=>{"use strict";n.d(t,{i:()=>i});var r=n(83102);class i{constructor(e){this.editor=e}editor;static configure(e){return class extends this{options={...this.options,...e}}}options={};static props;static migrations;static type;static handledAssetTypes;indicator(e){return null}getFontFaces(e){return r.Ml}canSnap(e){return!0}canTabTo(e){return!0}canScroll(e){return!1}canBind(e){return!0}canEdit(e,t){return!1}canResize(e){return!0}canResizeChildren(e){return!0}canEditInReadonly(e){return!1}canEditWhileLocked(e){return!1}canCrop(e){return!1}canBeLaidOut(e,t){return!0}canCull(e){return!0}providesBackgroundForChildren(e){return!1}hideResizeHandles(e){return!1}hideRotateHandle(e){return!1}hideSelectionBoundsBg(e){return!1}hideSelectionBoundsFg(e){return!1}isAspectRatioLocked(e){return!1}isFrameLike(e){return!1}isExportBoundsContainer(e){return!1}canReceiveNewChildrenOfType(e,t){return!1}canRemoveChildrenOfType(e,t){return!0}expandSelectionOutlinePx(e){return 0}getCanvasSvgDefs(){return[]}getBoundsSnapGeometry(e){return{}}getHandleSnapGeometry(e){return{}}getText(e){}getReferencedUserIds(e){return r.Ml}getAriaDescriptor(e){}}},27050:(e,t,n)=>{"use strict";function r(e){this.content=e}function i(e){return e>=56320&&e<57344}function o(e){return e>=55296&&e<56320}n.d(t,{S4:()=>H,ZF:()=>J,FK:()=>s,CU:()=>c,sX:()=>N,bP:()=>P,u$:()=>C,vI:()=>h,Sj:()=>$,Ji:()=>u}),r.prototype={constructor:r,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return -1},get:function(e){var t=this.find(e);return -1==t?void 0:this.content[t+1]},update:function(e,t,n){var i=n&&n!=e?this.remove(n):this,o=i.find(e),s=i.content.slice();return -1==o?s.push(n||e,t):(s[o+1]=t,n&&(s[o]=n)),new r(s)},remove:function(e){var t=this.find(e);if(-1==t)return this;var n=this.content.slice();return n.splice(t,2),new r(n)},addToStart:function(e,t){return new r([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new r(n)},addBefore:function(e,t,n){var i=this.remove(t),o=i.content.slice(),s=i.find(e);return o.splice(-1==s?o.length:s,0,t,n),new r(o)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return(e=r.from(e)).size?new r(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=r.from(e)).size?new r(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=r.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},r.from=function(e){if(e instanceof r)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new r(t)};class s{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,i){for(let o=0,s=0;s<t;o++){let a=this.content[o],l=s+a.nodeSize;if(l>e&&!1!==n(a,r+s,i||null,o)&&a.content.size){let i=s+1;a.nodesBetween(Math.max(0,e-i),Math.min(a.content.size,t-i),n,r+i)}s=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i="",o=!0;return this.nodesBetween(e,t,(s,a)=>{let l=s.isText?s.text.slice(Math.max(e,a)-a,t-a):s.isLeaf?r?"function"==typeof r?r(s):r:s.type.spec.leafText?s.type.spec.leafText(s):"":"";s.isBlock&&(s.isLeaf&&l||s.isTextblock)&&n&&(o?o=!1:i+=n),i+=l},0),i}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,r=this.content.slice(),i=0;for(t.isText&&t.sameMarkup(n)&&(r[r.length-1]=t.withText(t.text+n.text),i=1);i<e.content.length;i++)r.push(e.content[i]);return new s(r,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],r=0;if(t>e)for(let i=0,o=0;o<t;i++){let s=this.content[i],a=o+s.nodeSize;a>e&&((o<e||a>t)&&(s=s.isText?s.cut(Math.max(0,e-o),Math.min(s.text.length,t-o)):s.cut(Math.max(0,e-o-1),Math.min(s.content.size,t-o-1))),n.push(s),r+=s.nodeSize),o=a}return new s(n,r)}cutByIndex(e,t){return e==t?s.empty:0==e&&t==this.content.length?this:new s(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let r=this.content.slice(),i=this.size+t.nodeSize-n.nodeSize;return r[e]=t,new s(r,i)}addToStart(e){return new s([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new s(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return function e(t,n,r){for(let s=0;;s++){if(s==t.childCount||s==n.childCount)return t.childCount==n.childCount?null:r;let a=t.child(s),l=n.child(s);if(a==l){r+=a.nodeSize;continue}if(!a.sameMarkup(l))return r;if(a.isText&&a.text!=l.text){let e=a.text,t=l.text,n=0;for(;e[n]==t[n];n++)r++;return n&&n<e.length&&n<t.length&&o(e.charCodeAt(n-1))&&i(e.charCodeAt(n))&&r--,r}if(a.content.size||l.content.size){let t=e(a.content,l.content,r+1);if(null!=t)return t}r+=a.nodeSize}}(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return function e(t,n,r,s){for(let a=t.childCount,l=n.childCount;;){if(0==a||0==l)return a==l?null:{a:r,b:s};let d=t.child(--a),c=n.child(--l),h=d.nodeSize;if(d==c){r-=h,s-=h;continue}if(!d.sameMarkup(c))return{a:r,b:s};if(d.isText&&d.text!=c.text){let e=d.text,t=c.text,n=e.length,a=t.length;for(;n>0&&a>0&&e[n-1]==t[a-1];)n--,a--,r--,s--;return n&&a&&n<e.length&&o(e.charCodeAt(n-1))&&i(e.charCodeAt(n))&&(r++,s++),{a:r,b:s}}if(d.content.size||c.content.size){let t=e(d.content,c.content,r-1,s-1);if(t)return t}r-=h,s-=h}}(this,e,t,n)}findIndex(e){if(0==e)return l(0,e);if(e==this.size)return l(this.content.length,e);if(e>this.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=n+this.child(t).nodeSize;if(r>=e){if(r==e)return l(t+1,r);return l(t,n)}n=r}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return s.empty;if(!Array.isArray(t))throw RangeError("Invalid input for Fragment.fromJSON");return s.fromArray(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return s.empty;let t,n=0;for(let r=0;r<e.length;r++){let i=e[r];n+=i.nodeSize,r&&i.isText&&e[r-1].sameMarkup(i)?(t||(t=e.slice(0,r)),t[t.length-1]=i.withText(t[t.length-1].text+i.text)):t&&t.push(i)}return new s(t||e,n)}static from(e){if(!e)return s.empty;if(e instanceof s)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new s([e],e.nodeSize);throw RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}s.empty=new s([],0);let a={index:0,offset:0};function l(e,t){return a.index=e,a.offset=t,a}function d(e,t){if(e===t)return!0;if(!(e&&"object"==typeof e)||!(t&&"object"==typeof t))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!d(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!d(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class c{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t||(t=e.slice(0,r));else{if(i.type.excludes(this.type))return e;!n&&i.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),n=!0),t&&t.push(i)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&d(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw RangeError(`There is no mark type ${t.type} in this schema`);let r=n.create(t.attrs);return n.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&0==e.length)return c.none;if(e instanceof c)return[e];let t=e.slice();return t.sort((e,t)=>e.type.rank-t.type.rank),t}}c.none=[];class h extends Error{}class u{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=function e(t,n,r,i,o,s){let{index:a,offset:l}=t.findIndex(n),d=t.maybeChild(a);if(l==n||d.isText)return s&&i<=0&&o<=0&&!s.canReplace(a,a,r)?null:t.cut(0,n).append(r).append(t.cut(n));let c=e(d.content,n-l-1,r,0==a?i-1:0,a==t.childCount-1?o-1:0,d);return c&&t.replaceChild(a,d.copy(c))}(this.content,e+this.openStart,t,this.openStart+1,this.openEnd+1);return n&&new u(n,this.openStart,this.openEnd)}removeBetween(e,t){return new u(function e(t,n,r){let{index:i,offset:o}=t.findIndex(n),s=t.maybeChild(i),{index:a,offset:l}=t.findIndex(r);if(o==n||s.isText){if(l!=r&&!t.child(a).isText)throw RangeError("Removing non-flat range");return t.cut(0,n).append(t.cut(r))}if(i!=a)throw RangeError("Removing non-flat range");return t.replaceChild(i,s.copy(e(s.content,n-o-1,r-o-1)))}(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return u.empty;let n=t.openStart||0,r=t.openEnd||0;if("number"!=typeof n||"number"!=typeof r)throw RangeError("Invalid input for Slice.fromJSON");return new u(s.fromJSON(e,t.content),n,r)}static maxOpen(e,t=!0){let n=0,r=0;for(let r=e.firstChild;r&&!r.isLeaf&&(t||!r.type.spec.isolating);r=r.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)r++;return new u(e,n,r)}}function p(e,t){if(!t.type.compatibleContent(e.type))throw new h("Cannot join "+t.type.name+" onto "+e.type.name)}function f(e,t,n){let r=e.node(n);return p(r,t.node(n)),r}function g(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function m(e,t,n,r){let i=(t||e).node(n),o=0,s=t?t.index(n):i.childCount;e&&(o=e.index(n),e.depth>n?o++:e.textOffset&&(g(e.nodeAfter,r),o++));for(let e=o;e<s;e++)g(i.child(e),r);t&&t.depth==n&&t.textOffset&&g(t.nodeBefore,r)}function y(e,t){if(!e.type.validContent(t))throw new h("Invalid content for node "+e.type.name);return e.copy(t)}function b(e,t,n){let r=[];return m(null,e,n,r),e.depth>n&&g(y(f(e,t,n+1),b(e,t,n+1)),r),m(t,null,n,r),new s(r)}u.empty=new u(s.empty,0,0);class x{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return null==e?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[3*this.resolveDepth(e)]}index(e){return this.path[3*this.resolveDepth(e)+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e!=this.depth||this.textOffset?1:0)}start(e){return 0==(e=this.resolveDepth(e))?0:this.path[3*e-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(!(e=this.resolveDepth(e)))throw RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]}after(e){if(!(e=this.resolveDepth(e)))throw RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]+this.path[3*e].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):0==e?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[3*t],r=0==t?0:this.path[3*t-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(0==e.content.size)return c.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let i=n.marks;for(var o=0;o<i.length;o++)!1!==i[o].type.spec.inclusive||r&&i[o].isInSet(r.marks)||(i=i[o--].removeFromSet(i));return i}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var i=0;i<n.length;i++)!1!==n[i].type.spec.inclusive||r&&n[i].isInSet(r.marks)||(n=n[i--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new C(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw RangeError("Position "+t+" out of range");let n=[],r=0,i=t;for(let t=e;;){let{index:e,offset:o}=t.content.findIndex(i),s=i-o;if(n.push(t,e,r+o),!s||(t=t.child(e)).isText)break;i=s-1,r+=o+1}return new x(t,n,i)}static resolveCached(e,t){let n=S.get(e);if(n)for(let e=0;e<n.elts.length;e++){let r=n.elts[e];if(r.pos==t)return r}else S.set(e,n=new w);let r=n.elts[n.i]=x.resolve(e,t);return n.i=(n.i+1)%v,r}}class w{constructor(){this.elts=[],this.i=0}}let v=12,S=new WeakMap;class C{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}let k=Object.create(null);class P{constructor(e,t,n,r=c.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||s.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&d(this.attrs,t||e.defaultAttrs||k)&&c.sameSet(this.marks,n||c.none)}copy(e=null){return e==this.content?this:new P(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new P(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return 0==e&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return u.empty;let r=this.resolve(e),i=this.resolve(t),o=n?0:r.sharedDepth(t),s=r.start(o);return new u(r.node(o).content.cut(r.pos-s,i.pos-s),r.depth-o,i.depth-o)}replace(e,t,n){var r=this.resolve(e),i=this.resolve(t);if(n.openStart>r.depth)throw new h("Inserted content deeper than insertion position");if(r.depth-n.openStart!=i.depth-n.openEnd)throw new h("Inconsistent open depths");return function e(t,n,r,i){let o=t.index(i),a=t.node(i);if(o==n.index(i)&&i<t.depth-r.openStart){let s=e(t,n,r,i+1);return a.copy(a.content.replaceChild(o,s))}if(!r.content.size)return y(a,b(t,n,i));if(r.openStart||r.openEnd||t.depth!=i||n.depth!=i){let{start:e,end:o}=function(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(s.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}(r,t);return y(a,function e(t,n,r,i,o){let a=t.depth>o&&f(t,n,o+1),l=i.depth>o&&f(r,i,o+1),d=[];return m(null,t,o,d),a&&l&&n.index(o)==r.index(o)?(p(a,l),g(y(a,e(t,n,r,i,o+1)),d)):(a&&g(y(a,b(t,n,o+1)),d),m(n,r,o,d),l&&g(y(l,b(r,i,o+1)),d)),m(i,null,o,d),new s(d)}(t,e,o,n,i))}{let e=t.parent,i=e.content;return y(e,i.cut(0,t.parentOffset).append(r.content).append(i.cut(n.parentOffset)))}}(r,i,n,0)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(!(t=t.maybeChild(n)))return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(0==e)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return x.resolveCached(this,e)}resolveNoCache(e){return x.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),E(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=s.empty,r=0,i=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,r,i),a=o&&o.matchFragment(this.content,t);if(!a||!a.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let i=this.contentMatchAt(e).matchType(n),o=i&&i.matchFragment(this.content,t);return!!o&&o.validEnd}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=c.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!c.sameSet(e,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){let n;if(!t)throw RangeError("Invalid input for Node.fromJSON");if(t.marks){if(!Array.isArray(t.marks))throw RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if("text"==t.type){if("string"!=typeof t.text)throw RangeError("Invalid text node in JSON");return e.text(t.text,n)}let r=s.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}}P.prototype.text=void 0;class T extends P{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):E(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new T(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new T(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return 0==e&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function E(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class I{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){var n;let r,i=new _(e,t);if(null==i.next)return I.empty;let o=function e(t){let n=[];do n.push(function(t){let n=[];do n.push(function(t){let n=function(t){if(t.eat("(")){let n=e(t);return t.eat(")")||t.err("Missing closing paren"),n}if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=(function(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return 0==i.length&&e.err("No node type or group '"+t+"' found"),i})(t,t.next).map(e=>(null==t.inline?t.inline=e.isInline:t.inline!=e.isInline&&t.err("Mixing inline and block content"),{type:"name",value:e}));return t.pos++,1==e.length?e[0]:{type:"choice",exprs:e}}}(t);for(;;)if(t.eat("+"))n={type:"plus",expr:n};else if(t.eat("*"))n={type:"star",expr:n};else if(t.eat("?"))n={type:"opt",expr:n};else if(t.eat("{"))n=function(e,t){let n=M(e),r=n;return e.eat(",")&&(r="}"!=e.next?M(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:t}}(t,n);else break;return n}(t));while(t.next&&")"!=t.next&&"|"!=t.next);return 1==n.length?n[0]:{type:"seq",exprs:n}}(t));while(t.eat("|"));return 1==n.length?n[0]:{type:"choice",exprs:n}}(i);i.next&&i.err("Unexpected trailing text");let s=(n=function(e){let t=[[]];return i(function e(t,o){if("choice"==t.type)return t.exprs.reduce((t,n)=>t.concat(e(n,o)),[]);if("seq"==t.type)for(let r=0;;r++){let s=e(t.exprs[r],o);if(r==t.exprs.length-1)return s;i(s,o=n())}else if("star"==t.type){let s=n();return r(o,s),i(e(t.expr,s),s),[r(s)]}else if("plus"==t.type){let s=n();return i(e(t.expr,o),s),i(e(t.expr,s),s),[r(s)]}else if("opt"==t.type)return[r(o)].concat(e(t.expr,o));else if("range"==t.type){let s=o;for(let r=0;r<t.min;r++){let r=n();i(e(t.expr,s),r),s=r}if(-1==t.max)i(e(t.expr,s),s);else for(let o=t.min;o<t.max;o++){let o=n();r(s,o),i(e(t.expr,s),o),s=o}return[r(s)]}else if("name"==t.type)return[r(o,void 0,t.value)];else throw Error("Unknown expr type")}(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}}(o),r=Object.create(null),function e(t){let i=[];t.forEach(e=>{n[e].forEach(({term:e,to:t})=>{let r;if(e){for(let t=0;t<i.length;t++)i[t][0]==e&&(r=i[t][1]);j(n,t).forEach(t=>{r||i.push([e,r=[]]),-1==r.indexOf(t)&&r.push(t)})}})});let o=r[t.join(",")]=new I(t.indexOf(n.length-1)>-1);for(let t=0;t<i.length;t++){let n=i[t][1].sort(A);o.next.push({type:i[t][0],next:r[n.join(",")]||e(n)})}return o}(j(n,0)));return function(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],i=!e.validEnd,o=[];for(let t=0;t<e.next.length;t++){let{type:n,next:s}=e.next[t];o.push(n.name),i&&!(n.isText||n.hasRequiredAttrs())&&(i=!1),-1==r.indexOf(s)&&r.push(s)}i&&t.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(s,i),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let r=this;for(let i=t;r&&i<n;i++)r=r.matchType(e.child(i).type);return r}get inlineContent(){return 0!=this.next.length&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];return function i(o,a){let l=o.matchFragment(e,n);if(l&&(!t||l.validEnd))return s.from(a.map(e=>e.createAndFill()));for(let e=0;e<o.next.length;e++){let{type:t,next:n}=o.next[e];if(!(t.isText||t.hasRequiredAttrs())&&-1==r.indexOf(n)){r.push(n);let e=i(n,a.concat(t));if(e)return e}}return null}(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),i=r.match;if(i.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<i.next.length;e++){let{type:o,next:s}=i.next[e];o.isLeaf||o.hasRequiredAttrs()||o.name in t||r.type&&!s.validEnd||(n.push({match:o.contentMatch,type:o,via:r}),t[o.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];return!function t(n){e.push(n);for(let r=0;r<n.next.length;r++)-1==e.indexOf(n.next[r].next)&&t(n.next[r].next)}(this),e.map((t,n)=>{let r=n+(t.validEnd?"*":" ")+" ";for(let n=0;n<t.next.length;n++)r+=(n?", ":"")+t.next[n].type.name+"->"+e.indexOf(t.next[n].next);return r}).join("\n")}}I.empty=new I(!0);class _{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw SyntaxError(e+" (in content expression '"+this.string+"')")}}function M(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function A(e,t){return t-e}function j(e,t){let n=[];return function t(r){let i=e[r];if(1==i.length&&!i[0].term)return t(i[0].to);n.push(r);for(let e=0;e<i.length;e++){let{term:r,to:o}=i[e];r||-1!=n.indexOf(o)||t(o)}}(t),n.sort(A)}function O(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function D(e,t){let n=Object.create(null);for(let r in e){let i=t&&t[r];if(void 0===i){let t=e[r];if(t.hasDefault)i=t.default;else throw RangeError("No value supplied for attribute "+r)}n[r]=i}return n}function L(e,t,n,r){for(let i in t)if(!(i in e))throw RangeError(`Unsupported attribute ${i} for ${n} of type ${r}`);for(let n in e)e[n].validate&&e[n].validate(t[n])}function R(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new z(e,r,t[r]);return n}class F{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(" "):[],this.attrs=R(e,n.attrs),this.defaultAttrs=O(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||"text"==e),this.isText="text"==e}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==I.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:D(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error("NodeType.create can't construct text nodes");return new P(this,this.computeAttrs(e),s.from(t),c.setFrom(n))}createChecked(e=null,t,n){return t=s.from(t),this.checkContent(t),new P(this,this.computeAttrs(e),t,c.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=s.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(s.empty,!0);return i?new P(this,e,t.append(i),c.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){L(this.attrs,e,"node",this.name)}allowsMarkType(e){return null==this.markSet||this.markSet.indexOf(e)>-1}allowsMarks(e){if(null==this.markSet)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){let t;if(null==this.markSet)return e;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:c.none:e}static compile(e,t){let n=Object.create(null);e.forEach((e,r)=>n[e]=new F(e,t,r));let r=t.spec.topNode||"doc";if(!n[r])throw RangeError("Schema is missing its top node type ('"+r+"')");if(!n.text)throw RangeError("Every schema needs a 'text' type");for(let e in n.text.attrs)throw RangeError("The text node type should not have attributes");return n}}class z{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate="string"==typeof n.validate?function(e,t,n){let r=n.split("|");return n=>{let i=null===n?"null":typeof n;if(0>r.indexOf(i))throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class N{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=R(e,r.attrs),this.excluded=null;let i=O(this.attrs);this.instance=i?new c(this,i):null}create(e=null){return!e&&this.instance?this.instance:new c(this,D(this.attrs,e))}static compile(e,t){let n=Object.create(null),r=0;return e.forEach((e,i)=>n[e]=new N(e,r++,t,i)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){L(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class ${constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=r.from(e.nodes),t.marks=r.from(e.marks||{}),this.nodes=F.compile(this.spec.nodes,this),this.marks=N.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+" can not be both a node and a mark");let t=this.nodes[e],r=t.spec.content||"",i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=I.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError("Multiple linebreak nodes defined");if(!t.isInline||!t.isLeaf)throw RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=t}t.markSet="_"==i?null:i?B(this,i.split(" ")):""!=i&&t.inlineContent?null:[]}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=null==n?[t]:""==n?[]:B(this,n.split(" "))}this.nodeFromJSON=e=>P.fromJSON(this,e),this.markFromJSON=e=>c.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if("string"==typeof e)e=this.nodeType(e);else if(e instanceof F){if(e.schema!=this)throw RangeError("Node type from different schema used ("+e.name+")")}else throw RangeError("Invalid node type: "+e);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new T(n,n.defaultAttrs,e,c.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError("Unknown node type: "+e);return t}}function B(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r],o=e.marks[i],s=o;if(o)n.push(o);else for(let t in e.marks){let r=e.marks[t];("_"==i||r.spec.group&&r.spec.group.split(" ").indexOf(i)>-1)&&n.push(s=r)}if(!s)throw SyntaxError("Unknown mark type: '"+t[r]+"'")}return n}class H{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(null!=e.tag)this.tags.push(e);else if(null!=e.style){let t=/[^=]*/.exec(e.style)[0];0>n.indexOf(t)&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new G(this,t,!1);return n.addAll(e,c.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new G(this,t,!0);return n.addAll(e,c.none,t.from,t.to),u.maxOpen(n.finish())}matchTag(e,t,n){for(let o=n?this.tags.indexOf(n)+1:0;o<this.tags.length;o++){var r,i;let n=this.tags[o];if(r=e,i=n.tag,(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,i)&&(void 0===n.namespace||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(!1===t)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let i=r?this.styles.indexOf(r)+1:0;i<this.styles.length;i++){let r=this.styles[i],o=r.style;if(0==o.indexOf(e)&&(!r.context||n.matchesContext(r.context))&&(!(o.length>e.length)||61==o.charCodeAt(e.length)&&o.slice(e.length+1)==t)){if(r.getAttrs){let e=r.getAttrs(t);if(!1===e)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((null==e.priority?50:e.priority)<n)break}t.splice(r,0,e)}for(let t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach(e=>{n(e=q(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=q(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new H(e,H.schemaRules(e)))}}let U={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},K={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},W={ol:!0,ul:!0};function V(e,t,n){return null!=t?!!t|2*("full"===t):e&&"pre"==e.whitespace?3:-5&n}class Y{constructor(e,t,n,r,i,o){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=o,this.content=[],this.activeMarks=c.none,this.match=i||(4&o?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(s.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e=this.content[this.content.length-1],t;e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))&&(e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=e.withText(e.text.slice(0,e.text.length-t[0].length)))}let t=s.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(s.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!U.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class G{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,o=V(null,t.preserveWhitespace,0)|4*!!n;i=r?new Y(r.type,r.attrs,c.none,!0,t.topMatch||r.type.contentMatch,o):n?new Y(null,null,c.none,!0,null,o):new Y(e.schema.topNodeType,null,c.none,!0,null,o),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){3==e.nodeType?this.addTextNode(e,t):1==e.nodeType&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,i=2&r.options?"full":this.localPreserveWS||(1&r.options)>0,{schema:o}=this.parser;if("full"===i||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(i)if("full"===i)n=n.replace(/\r\n?/g,"\n");else if(o.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(o.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(o.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(o.text(e[n]),t,!/\S/.test(e[n]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&"BR"==i.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(o.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,i=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),s;W.hasOwnProperty(o)&&this.parser.normalizeLists&&function(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=1==t.nodeType?t.nodeName.toLowerCase():null;e&&W.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,n));o:if(a?a.ignore:K.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let n,r=this.needsBlock;if(U.hasOwnProperty(o))i.content.length&&i.content[0].isInline&&this.open&&(this.open--,i=this.top),n=!0,i.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break o}let s=a&&a.skip?t:this.readStyles(e,t);s&&this.addAll(e,s),n&&this.sync(i),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,a,n,!1===a.consuming?s:void 0)}this.localPreserveWS=r}leafFallback(e,t){"BR"==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode("\n"),t)}ignoreFallback(e,t){"BR"!=e.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let e=0;e<this.parser.matchedStyles.length;e++){let r=this.parser.matchedStyles[e],i=n.getPropertyValue(r);if(i)for(let e;;){let n=this.parser.matchStyle(r,i,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),!1===n.consuming)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,o;if(t.node)if((o=this.parser.schema.nodes[t.node]).isLeaf)this.insertNode(o.create(t.attrs),n,"BR"==e.nodeName)||this.leafFallback(e,n);else{let e=this.enter(o,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let s=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;"string"==typeof t.contentElement?r=e.querySelector(t.contentElement):"function"==typeof t.contentElement?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(s)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let o=n?e.childNodes[n]:e.firstChild,s=null==r?null:e.childNodes[r];o!=s;o=o.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(o,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,o=0;t>=0;t--){let s=this.nodes[t],a=s.findWrapping(e);if(a&&(!r||r.length>a.length+o)&&(r=a,i=s,!a.length))break;if(s.solid){if(n)break;o+=2}}if(!r)return null;this.sync(i);for(let e=0;e<r.length;e++)t=this.enterInner(r[e],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let t=this.top;t.match&&(t.match=t.match.matchType(e.type));let n=c.none;for(let i of r.concat(e.marks))(t.type?t.type.allowsMarkType(i.type):X(i.type,e.type))&&(n=i.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let i=this.findPlace(e.create(t),n,!1);return i&&(i=this.enterInner(e,t,n,!0,r)),i}enterInner(e,t,n,r=!1,i){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let s=V(e,i,o.options);4&o.options&&0==o.content.length&&(s|=4);let a=c.none;return n=n.filter(t=>(o.type?!o.type.allowsMarkType(t.type):!X(t.type,e))||(a=t.addToSet(a),!1)),this.nodes.push(new Y(e,t,a,r,null,s)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=1);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)null==this.find[t].pos&&1==e.nodeType&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)null==this.find[r].pos&&1==e.nodeType&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+ +!r,o=(e,s)=>{for(;e>=0;e--){let a=t[e];if(""==a){if(e==t.length-1||0==e)continue;for(;s>=i;s--)if(o(e-1,s))return!0;return!1}{let e=s>0||0==s&&r?this.nodes[s].type:n&&s>=i?n.node(s-i).type:null;if(!e||e.name!=a&&!e.isInGroup(a))return!1;s--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}}function q(e){let t={};for(let n in e)t[n]=e[n];return t}function X(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let o=[],s=e=>{o.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:i}=e.edge(n);if(r==t||0>o.indexOf(i)&&s(i))return!0}};if(s(i.contentMatch))return!0}}class J{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=Q(t).createDocumentFragment());let r=n,i=[];return e.forEach(e=>{if(i.length||e.marks.length){let n=0,o=0;for(;n<i.length&&o<e.marks.length;){let t=e.marks[o];if(!this.marks[t.type.name]){o++;continue}if(!t.eq(i[n][0])||!1===t.type.spec.spanning)break;n++,o++}for(;n<i.length;)r=i.pop()[1];for(;o<e.marks.length;){let n=e.marks[o++],s=this.serializeMark(n,e.isInline,t);s&&(i.push([n,r]),r.appendChild(s.dom),r=s.contentDOM||s.dom)}}r.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){if(e.isText)return Q(t).createTextNode(e.text);let{dom:n,contentDOM:r}=et(Q(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&et(Q(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return"string"==typeof t?{dom:e.createTextNode(t)}:et(e,t,n,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new J(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Z(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return Z(e.marks)}}function Z(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function Q(e){return e.document||window.document}let ee=new WeakMap;function et(e,t,n,r){let i,o,s;if(1==t.nodeType)return{dom:t};if(t.dom&&1==t.dom.nodeType)return t;let a=t[0],l;if("string"!=typeof a)throw RangeError("Invalid array passed to renderSpec");if(r&&(void 0===(o=ee.get(r))&&ee.set(r,(s=null,!function e(t){if(t&&"object"==typeof t)if(Array.isArray(t))if("string"==typeof t[0])s||(s=[]),s.push(t);else for(let n=0;n<t.length;n++)e(t[n]);else for(let n in t)e(t[n])}(r),o=s)),l=o)&&l.indexOf(t)>-1)throw RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let d=a.indexOf(" ");d>0&&(n=a.slice(0,d),a=a.slice(d+1));let c=n?e.createElementNS(n,a):e.createElement(a),h=t[1],u=1;if(h&&"object"==typeof h&&null==h.nodeType&&!Array.isArray(h)){for(let e in u=2,h)if(null!=h[e]){let t=e.indexOf(" ");t>0?c.setAttributeNS(e.slice(0,t),e.slice(t+1),h[e]):"style"==e&&c.style?c.style.cssText=h[e]:c.setAttribute(e,h[e])}}for(let o=u;o<t.length;o++){let s=t[o];if(0===s){if(o<t.length-1||o>u)throw RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}if("string"==typeof s)c.appendChild(e.createTextNode(s));else{let{dom:t,contentDOM:o}=et(e,s,n,r);if(c.appendChild(t),o){if(i)throw RangeError("Multiple content holes");i=o}}}return{dom:c,contentDOM:i}}},27164:(e,t,n)=>{"use strict";n.d(t,{MI:()=>d,vq:()=>c});var r=n(24167),i=n(59830),o=n(81962),s=n(54939),a=n(93286),l=n(46195);let d={EXCLUDE_NON_STANDARD:{includeLabels:!1,includeInternal:!1},INCLUDE_ALL:{includeLabels:!0,includeInternal:!0},EXCLUDE_LABELS:{includeLabels:!1,includeInternal:!0},EXCLUDE_INTERNAL:{includeLabels:!0,includeInternal:!1}};class c{isFilled=!1;isClosed=!0;isLabel=!1;isEmptyLabel=!1;isInternal=!1;excludeFromShapeBounds=!1;debugColor;ignore;constructor(e){const{isLabel:t=!1,isEmptyLabel:n=!1,isInternal:r=!1,excludeFromShapeBounds:i=!1}=e;this.isFilled=e.isFilled,this.isClosed=e.isClosed,this.debugColor=e.debugColor,this.ignore=e.ignore,this.isLabel=t,this.isEmptyLabel=n,this.isInternal=r,this.excludeFromShapeBounds=i}isExcludedByFilter(e){return!!e&&(!!this.isLabel&&!e.includeLabels||!!this.isInternal&&!e.includeInternal)}hitTestPoint(e,t=0,n=!1,r){return!!(this.isClosed&&(this.isFilled||n)&&(0,a.s3)(e,this.vertices))||l.l.Dist2(e,this.nearestPoint(e))<=t*t}distanceToPoint(e,t=!1,n){return l.l.Dist(e,this.nearestPoint(e,n))*(this.isClosed&&(this.isFilled||t)&&(0,a.s3)(e,this.vertices)?-1:1)}distanceToLineSegment(e,t,n){let r,i,s,d;if(l.l.Equals(e,t))return this.distanceToPoint(e,!1,n);let{vertices:c}=this;if(0===c.length)throw Error("nearest point not found");if(1===c.length)return l.l.Dist(e,c[0]);let h=1/0,u=this.isClosed?c.length:c.length-1;for(let n=0;n<c.length;n++){if(s=c[n],n<u){let r=c[(n+1)%c.length];if((0,o.HV)(e,t,s,r))return 0}d=l.l.NearestPointOnLineSegment(e,t,s,!0),(i=l.l.Dist2(s,d))<h&&(h=i,r=d)}if(!r)throw Error("nearest point not found");return h=Math.sqrt(h),this.isClosed&&this.isFilled&&(0,a.s3)(r,this.vertices)?-h:h}hitTestLineSegment(e,t,n=0,r){return this.distanceToLineSegment(e,t,r)<=n}intersectLineSegment(e,t,n){return(this.isClosed?(0,o.lq)(e,t,this.vertices):(0,o.NC)(e,t,this.vertices))??[]}intersectCircle(e,t,n){return(this.isClosed?(0,o.SU)(e,t,this.vertices):(0,o.y5)(e,t,this.vertices))??[]}intersectPolygon(e,t){return(0,o.B8)(e,this.vertices,!0,this.isClosed)}intersectPolyline(e,t){return(0,o.B8)(e,this.vertices,!1,this.isClosed)}interpolateAlongEdge(e,t){let{vertices:n}=this;if(0===n.length)return new l.l(0,0);if(1===n.length||e<=0)return n[0];let i=e*this.length,o=0;for(let e=0;e<(this.isClosed?n.length:n.length-1);e++){let t=n[e],s=n[(e+1)%n.length],a=l.l.Dist(t,s),d=o+a;if(d>=i){if(0===a)return t;return l.l.Lrp(t,s,(0,r.Fg)(o,d,i))}o=d}return this.isClosed?n[0]:n[n.length-1]}uninterpolateAlongEdge(e,t){let{vertices:n,length:i}=this,o=null,s=1/0,a=0;if(0===n.length||1===n.length)return 0;for(let t=0;t<(this.isClosed?n.length:n.length-1);t++){let r=n[t],i=n[(t+1)%n.length],d=l.l.NearestPointOnLineSegment(r,i,e,!0),c=l.l.Dist(d,e);c<s&&(s=c,o={start:r,end:i,nearestPoint:d,distanceToStart:a}),a+=l.l.Dist(r,i)}(0,r.vA)(o);let d=o.distanceToStart+l.l.Dist(o.start,o.nearestPoint);return 0===i?0:d/i}isPointInBounds(e,t=0){let{bounds:n}=this;return!(e.x<n.minX-t||e.y<n.minY-t||e.x>n.maxX+t||e.y>n.maxY+t)}overlapsPolygon(e){let t=e.map(e=>l.l.From(e)),{vertices:n,center:r,isFilled:i,isEmptyLabel:s,isClosed:d}=this;if(s)return!1;if(n.some(e=>(0,a.s3)(e,t)))return!0;if(d){if(i&&((0,a.s3)(r,t)||t.every(e=>(0,a.s3)(e,n)))||(0,o.Rx)(t,n))return!0}else if((0,o.j0)(t,n))return!0;return!1}transform(e,t){return new h(this,e,t)}_vertices;get vertices(){return this._vertices||(this._vertices=this.getVertices(d.EXCLUDE_LABELS)),this._vertices}getBoundsVertices(){return this.excludeFromShapeBounds?[]:this.vertices}_boundsVertices;get boundsVertices(){return this._boundsVertices||(this._boundsVertices=this.getBoundsVertices()),this._boundsVertices}getBounds(){return i.az.FromPoints(this.boundsVertices)}_bounds;get bounds(){return this._bounds||(this._bounds=this.getBounds()),this._bounds}get center(){return this.bounds.center}_area;get area(){return this._area||(this._area=this.getArea()),this._area}getArea(){if(!this.isClosed)return 0;let{vertices:e}=this,t=0;for(let n=0,r=e.length;n<r;n++){let i=e[n],o=e[(n+1)%r];t+=i.x*o.y-o.x*i.y}return t/2}toSimpleSvgPath(){let e="",{vertices:t}=this,n=t.length;if(0===n)return e;e+=`M${t[0].x},${t[0].y}`;for(let r=1;r<n;r++)e+=`L${t[r].x},${t[r].y}`;return this.isClosed&&(e+="Z"),e}_length;get length(){return this._length||(this._length=this.getLength(d.EXCLUDE_LABELS)),this._length}getLength(e){let t=this.getVertices(e??d.EXCLUDE_LABELS);if(0===t.length)return 0;let n=t[0],r=0;for(let e=1;e<t.length;e++){let i=t[e];r+=l.l.Dist(n,i),n=i}return this.isClosed&&(r+=l.l.Dist(t[t.length-1],t[0])),r}ignoreHit(e){return!1}}class h extends c{constructor(e,t,n){super(e),this.geometry=e,this.matrix=t,this.inverse=s.V.Inverse(t),this.decomposed=s.V.Decompose(t),n&&(null!=n.isLabel&&(this.isLabel=n.isLabel),null!=n.isInternal&&(this.isInternal=n.isInternal),null!=n.debugColor&&(this.debugColor=n.debugColor),null!=n.ignore&&(this.ignore=n.ignore)),(0,r.vA)((0,a.YY)(this.decomposed.scaleX,this.decomposed.scaleY),"non-uniform scaling is not yet supported")}geometry;matrix;inverse;decomposed;getVertices(e){return this.geometry.getVertices(e).map(e=>s.V.applyToPoint(this.matrix,e))}getBoundsVertices(){return this.geometry.getBoundsVertices().map(e=>s.V.applyToPoint(this.matrix,e))}nearestPoint(e,t){return s.V.applyToPoint(this.matrix,this.geometry.nearestPoint(s.V.applyToPoint(this.inverse,e),t))}hitTestPoint(e,t=0,n,r){return this.geometry.hitTestPoint(s.V.applyToPoint(this.inverse,e),t/this.decomposed.scaleX,n,r)}distanceToPoint(e,t=!1,n){return this.geometry.distanceToPoint(s.V.applyToPoint(this.inverse,e),t,n)*this.decomposed.scaleX}distanceToLineSegment(e,t,n){return this.geometry.distanceToLineSegment(s.V.applyToPoint(this.inverse,e),s.V.applyToPoint(this.inverse,t),n)*this.decomposed.scaleX}hitTestLineSegment(e,t,n=0,r){return this.geometry.hitTestLineSegment(s.V.applyToPoint(this.inverse,e),s.V.applyToPoint(this.inverse,t),n/this.decomposed.scaleX,r)}intersectLineSegment(e,t,n){return s.V.applyToPoints(this.matrix,this.geometry.intersectLineSegment(s.V.applyToPoint(this.inverse,e),s.V.applyToPoint(this.inverse,t),n))}intersectCircle(e,t,n){return s.V.applyToPoints(this.matrix,this.geometry.intersectCircle(s.V.applyToPoint(this.inverse,e),t/this.decomposed.scaleX,n))}intersectPolygon(e,t){return s.V.applyToPoints(this.matrix,this.geometry.intersectPolygon(s.V.applyToPoints(this.inverse,e),t))}intersectPolyline(e,t){return s.V.applyToPoints(this.matrix,this.geometry.intersectPolyline(s.V.applyToPoints(this.inverse,e),t))}ignoreHit(e){return this.geometry.ignoreHit(s.V.applyToPoint(this.inverse,e))}transform(e,t){return new h(this.geometry,s.V.Multiply(e,this.matrix),{isLabel:t?.isLabel??this.isLabel,isInternal:t?.isInternal??this.isInternal,debugColor:t?.debugColor??this.debugColor,ignore:t?.ignore??this.ignore})}getSvgPathData(){throw Error("Cannot get SVG path data for transformed geometry.")}}},27394:(e,t,n)=>{"use strict";n.d(t,{u4:()=>c,fp:()=>h,HO:()=>u,lX:()=>p,a1:()=>f,A1:()=>s,h:()=>g});var r=n(24167),i=n(12115),o=n(83102);function s(e,t,n=[]){let r=i.useRef(t);r.current=t;let[a,l,d]=i.useMemo(()=>{let t=null,n=new o.VM(`useStateTracking(${e})`,()=>r.current?.(),{scheduleEffect(){t?.()}});return[n,e=>(t=e,()=>{t=null}),()=>n.scheduleCount]},[e,...n]);return i.useSyncExternalStore(l,d,d),i.useEffect(()=>(a.attach(),a.maybeScheduleEffect(),()=>{a.detach()}),[a]),a.execute()}let a={apply:(e,t,n)=>s(e.displayName??e.name??"tracked(???)",()=>e.apply(t,n))},l=Symbol.for("react.memo"),d=Symbol.for("react.forward_ref");function c(e){let t=null,n=e.$$typeof;return(n===l&&(t=(e=e.type).compare),n===d)?(0,i.memo)((0,i.forwardRef)(new Proxy(e.render,a))):(0,i.memo)(new Proxy(e,a),t)}function h(e,t,n){return(0,i.useState)(()=>{let r="function"==typeof t?t():t;return(0,o.eU)(`useAtom(${e})`,r,n)})[0]}function u(){let e=arguments[0],t=arguments[1],n=3==arguments.length?void 0:arguments[2],r=3==arguments.length?arguments[2]:arguments[3];return(0,i.useMemo)(()=>(0,o.EW)(`useComputed(${e})`,t,n),r)}function p(e,t,n=o.Ml){(0,i.useEffect)(()=>{let n=new o.VM(e,t);return n.attach(),n.execute(),()=>{n.detach()}},n)}function f(e,t,n=[]){(0,i.useEffect)(()=>{let n,i=new o.VM(e,t,{scheduleEffect:e=>{n=(0,r.Uo)(e)}});return i.attach(),i.execute(),()=>{i.detach(),n?.()}},n)}function g(){let e=arguments,t=3===e.length?e[2]:[e[0]],n=3===e.length?e[0]:`useValue(${e[0].name})`,{$val:r,subscribe:s,getSnapshot:a}=(0,i.useMemo)(()=>{let t=1===e.length?e[0]:(0,o.EW)(n,e[1]);return{$val:t,subscribe:e=>(0,o.wv)(`useValue(${n})`,()=>{try{t.get()}catch{}e()}),getSnapshot:()=>t.lastChangedEpoch}},t);return(0,i.useSyncExternalStore)(s,a,a),r.__unsafe__getWithoutCapture()}(0,r.lF)("@tldraw/state-react","5.3.2","esm")},28879:(e,t,n)=>{"use strict";function r(e,t){return e.props===t.props&&e.meta===t.meta}n.d(t,{E:()=>r})},31428:(e,t,n)=>{"use strict";n.d(t,{d:()=>i});var r=n(31796);class i extends r.H{constructor(e){if(super({...e}),this.isClosed=!0,e.points.length<3)throw Error("Polygon2d: points must be an array of at least 3 points")}}},31796:(e,t,n)=>{"use strict";n.d(t,{H:()=>a});var r=n(93286),i=n(46195),o=n(55667),s=n(27164);class a extends s.vq{_points;_segments;constructor(e){super({isClosed:!1,isFilled:!1,...e});const{points:t}=e;if(this._points=t,t.length<2)throw Error("Polyline2d: points must be an array of at least 2 points")}get segments(){if(!this._segments){this._segments=[];let{vertices:e}=this;for(let t=0,n=e.length-1;t<n;t++){let n=e[t],r=e[t+1];this._segments.push(new o.A({start:n,end:r}))}this.isClosed&&this._segments.push(new o.A({start:e[e.length-1],end:e[0]}))}return this._segments}getLength(){return this.segments.reduce((e,t)=>e+t.length,0)}getVertices(){return this._points}nearestPoint(e){let{vertices:t}=this,n=t[0].x,r=t[0].y,o=(e.x-n)*(e.x-n)+(e.y-r)*(e.y-r),s=this.isClosed?t.length:t.length-1;for(let i=0;i<s;i++){let s,a,l=t[i],d=t[(i+1)%t.length],c=d.x-l.x,h=d.y-l.y,u=c*c+h*h;if(0===u)s=l.x,a=l.y;else{let t=((e.x-l.x)*c+(e.y-l.y)*h)/u;t<=0?(s=l.x,a=l.y):t>=1?(s=d.x,a=d.y):(s=l.x+c*t,a=l.y+h*t)}let p=e.x-s,f=e.y-a,g=p*p+f*f;g<o&&(n=s,r=a,o=g)}return new i.l(n,r)}hitTestPoint(e,t=0,n=!1){return this.distanceToPoint(e,n)<=t}distanceToPoint(e,t=!1){let{segments:n}=this,i=1/0;for(let t=0;t<n.length;t++){let r=n[t].distanceToPoint(e);r<i&&(i=r)}return this.isClosed&&(this.isFilled||t)&&(0,r.s3)(e,this.vertices)?-i:i}hitTestLineSegment(e,t,n=0){let{segments:r}=this;for(let i=0,o=r.length;i<o;i++)if(r[i].hitTestLineSegment(e,t,n))return!0;return!1}getSvgPathData(){let{vertices:e}=this;return e.length<2?"":e.reduce((e,t,n)=>0===n?`M ${t.x} ${t.y}`:`${e} L ${t.x} ${t.y}`,"")}}},31832:(e,t,n)=>{"use strict";n.d(t,{N:()=>d,P:()=>l});var r=n(83102),i=n(24167),o=n(19743),s=Object.defineProperty,a=Object.getOwnPropertyDescriptor;function l(e){return{default:o.S,...e}}class d{constructor(e,t){this.editor=e,this._themes=(0,r.eU)("ThemeManager._definitions",t.themes),this._currentThemeId=(0,r.eU)("ThemeManager._currentThemeName",t.initial)}editor;_themes;_currentThemeId;getColorMode(){return this.editor.user.getIsDarkMode()?"dark":"light"}getThemes(){return this._themes.get()}getTheme(e){return this._themes.get()[e]}getCurrentThemeId(){return this._currentThemeId.get()}getCurrentTheme(){return this._themes.get()[this.getCurrentThemeId()]}setCurrentTheme(e){this._currentThemeId.set(e)}updateThemes(e){this._themes.update(t=>{let n="function"==typeof e?e((0,i.pN)(t)):e;return this._currentThemeId.get()in n||this._currentThemeId.set("default"),n})}updateTheme(e){this._themes.update(t=>({...t,[e.id]:e}))}dispose(){}}((e,t,n)=>{for(var r,i=a(t,n),o=e.length-1;o>=0;o--)(r=e[o])&&(i=r(t,n,i)||i);return i&&s(t,n,i)})([r.EW],d.prototype,"getColorMode")},32007:(e,t,n)=>{"use strict";n.d(t,{Oh:()=>l});var r=n(12115),i=Object.defineProperty,o=(e,t)=>i(e,"name",{value:t,configurable:!0}),s=0,a=null;function l(){r.useEffect(()=>{a||(a={start:d(),end:d()});let{start:e,end:t}=a;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),s++,()=>{1===s&&(a?.start.remove(),a?.end.remove(),a=null),s=Math.max(0,s-1)}},[])}function d(){let e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}o(function(e){return l(),e.children},"FocusGuards"),o(l,"useFocusGuards"),o(d,"createFocusGuard")},32314:(e,t,n)=>{"use strict";n.d(t,{s:()=>l});var r=n(24167),i=n(46195),o=Object.defineProperty,s=Object.getOwnPropertyDescriptor,a=(e,t,n,r)=>{for(var i,a=r>1?void 0:r?s(t,n):t,l=e.length-1;l>=0;l--)(i=e[l])&&(a=(r?i(t,n,a):i(a))||a);return r&&a&&o(t,n,a),a};class l{constructor(e){this.editor=e}editor;_clickId="";_clickTimeout;_clickScreenPoint;_previousScreenPoint;_isPressingWhilePending=!1;_getClickTimeout(e,t=(0,r.NF)()){this._clickId=t,clearTimeout(this._clickTimeout),this._clickTimeout=this.editor.timers.setTimeout(()=>{this._clickState===e&&this._clickId===t&&("pendingOverflow"===this._clickState&&this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"double_click",phase:this._isPressingWhilePending?"settle-down":"settle-up"}),this._clickState="idle")},"idle"===e||"pendingDouble"===e?this.editor.options.doubleClickDurationMs:this.editor.options.multiClickDurationMs)}_clickState="idle";get clickState(){return this._clickState}lastPointerInfo={};handlePointerEvent(e){switch(e.name){case"pointer_down":if(!this._clickState)break;switch(this._clickScreenPoint=i.l.From(e.point),this._isPressingWhilePending=!0,this._previousScreenPoint&&i.l.Dist2(this._previousScreenPoint,this._clickScreenPoint)>1600&&(this._clickState="idle"),this._previousScreenPoint=this._clickScreenPoint,this.lastPointerInfo=e,this._clickState){case"pendingDouble":return this._clickState="pendingOverflow",this._clickTimeout=this._getClickTimeout(this._clickState),{...e,type:"click",name:"double_click",phase:"down"};case"idle":this._clickState="pendingDouble";break;case"pendingOverflow":this._clickState="overflow"}this._clickTimeout=this._getClickTimeout(this._clickState);break;case"pointer_up":if(!this._clickState)break;if(this._clickScreenPoint=i.l.From(e.point),this._isPressingWhilePending=!1,"pendingOverflow"===this._clickState)return{...this.lastPointerInfo,type:"click",name:"double_click",phase:"up"};break;case"pointer_move":"idle"!==this._clickState&&this._clickScreenPoint&&i.l.Dist2(this._clickScreenPoint,this.editor.inputs.getCurrentScreenPoint())>(this.editor.getInstanceState().isCoarsePointer?this.editor.options.coarseDragDistanceSquared:this.editor.options.dragDistanceSquared)&&this.cancelDoubleClickTimeout()}return e}cancelDoubleClickTimeout(){this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle",this._isPressingWhilePending=!1}}a([r.oI],l.prototype,"_getClickTimeout",1),a([r.oI],l.prototype,"cancelDoubleClickTimeout",1)},36649:(e,t,n)=>{"use strict";function r(e){let t=[],n=new Set;for(let r of e){if(n.has(r.type))throw Error(`Asset type "${r.type}" is defined more than once`);t.push(r),n.add(r.type)}return t}n.d(t,{U:()=>r})},37920:(e,t,n)=>{"use strict";n.d(t,{L:()=>p});var r=n(95155),i=n(81467),o=n(20172),s=n(75567),a=n(93097),l=n(26614),d=n(71136),c=n(27394),h=n(67863);function u({bounds:e,className:t}){let n=(0,h.hG)(),i=(0,c.h)("zoom level",()=>n.getEfficientZoomLevel(),[n]);return(0,r.jsx)("g",{className:t,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:e.sides.map((e,t)=>{let{strokeDasharray:n,strokeDashoffset:o}=(0,d.E)(e[0].dist(e[1]),1/i,{style:"dashed",lengthRatio:4});return(0,r.jsx)("line",{x1:e[0].x,y1:e[0].y,x2:e[1].x,y2:e[1].y,strokeDasharray:n,strokeDashoffset:o},t)})})}class p extends l.i{static type="group";static props=i.h4;static migrations=i.gf;hideSelectionBoundsFg(e){return!0}canBind(){return!1}canResize(){return!0}canResizeChildren(){return!0}getDefaultProps(){return{}}getGeometry(e){let t=this.editor.getSortedChildIdsForParent(e.id);return 0===t.length?new a.k({width:1,height:1,isFilled:!1}):new s.I({children:t.map(e=>{let t=this.editor.getShape(e);return this.editor.getShapeGeometry(e).transform(this.editor.getShapeLocalTransform(t),{isLabel:!1})})})}component(e){let t=this.editor.getErasingShapeIds().includes(e.id),{hintingShapeIds:n}=this.editor.getCurrentPageState(),i=n.length>0&&n.some(t=>t!==e.id&&this.editor.isShapeOfType(this.editor.getShape(t),"group")),s=this.editor.getCurrentPageState().focusedGroupId!==e.id;if(!t&&(s||i))return null;let a=this.editor.getShapeGeometry(e).bounds;return(0,r.jsx)(o.U,{children:(0,r.jsx)(u,{className:"tl-group",bounds:a})})}getIndicatorPath(e){let t=this.editor.getShapeGeometry(e).bounds,n=this.editor.getEfficientZoomLevel(),r=new Path2D;for(let e of t.sides){let[t,i]=e,o=t.dist(i);if(o<=0)continue;let{strokeDasharray:s,strokeDashoffset:a}=(0,d.E)(o,1/n,{style:"dashed",lengthRatio:4});if("none"===s){r.moveTo(t.x,t.y),r.lineTo(i.x,i.y);continue}let[l,c]=s.split(" ").map(Number),h=Number(a),u=l+c;if(!Number.isFinite(u)||u<=0)continue;let p=(i.x-t.x)/o,f=(i.y-t.y)/o;for(let e=-h;e<o;e+=u){let n=Math.min(o,e+l),i=Math.max(0,e);n<=i||(r.moveTo(t.x+p*i,t.y+f*i),r.lineTo(t.x+p*n,t.y+f*n))}}return r}onChildrenChange(e){let t=this.editor.getSortedChildIdsForParent(e.id);if(0===t.length){this.editor.getCurrentPageState().focusedGroupId===e.id&&this.editor.popFocusedGroupId(),this.editor.deleteShapes([e.id]);return}if(1===t.length){this.editor.getCurrentPageState().focusedGroupId===e.id&&this.editor.popFocusedGroupId(),this.editor.reparentShapes(t,e.parentId,e.index),this.editor.deleteShapes([e.id]);return}}}},38335:(e,t,n)=>{"use strict";n.d(t,{r:()=>r});class r{constructor(e){this.editor=e}editor;disposables=new Set;register(e){return this.disposables.add(e),e}addEditorEvent(e,t){this.editor.on(e,t),this.register(()=>this.editor.off(e,t))}dispose(){this.disposables.forEach(e=>e()),this.disposables.clear()}}},40002:(e,t,n)=>{"use strict";n.d(t,{D:()=>l});var r=n(24167),i=n(38335);n(41463);var o=Object.defineProperty,s=Object.getOwnPropertyDescriptor;let a=r.Uo;class l extends i.r{constructor(e){super(e),this.start()}cancelRaf;isPaused=!0;now=0;start(){this.isPaused=!1,this.cancelRaf?.(),this.cancelRaf=a(this.tick),this.now=Date.now()}tick(){if(this.isPaused)return;let e=Date.now(),t=e-this.now;this.now=e,this.editor.emit("frame",t),this.editor.emit("tick",t),this.cancelRaf=a(this.tick)}dispose(){this.isPaused=!0,this.cancelRaf?.(),super.dispose()}}((e,t,n)=>{for(var r,i=s(t,n),a=e.length-1;a>=0;a--)(r=e[a])&&(i=r(t,n,i)||i);return i&&o(t,n,i)})([r.oI],l.prototype,"tick")},42080:(e,t,n)=>{"use strict";n.d(t,{$B:()=>a,Sd:()=>o,T2:()=>s});var r=n(8242),i=n(27050);function o(e,t=null){return function(n,o){let{$from:s,$to:a}=n.selection,l=s.blockRange(a);if(!l)return!1;let d=o?n.tr:null;return!!function(e,t,n,o=null){let s=!1,a=t,l=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&0==t.startIndex){if(0==t.$from.index(t.depth-1))return!1;let e=l.resolve(t.start-2);a=new i.u$(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new i.u$(t.$from,l.resolve(t.$to.end(t.depth)),t.depth)),s=!0}let d=(0,r.oM)(a,n,o,t);return!!d&&(e&&function(e,t,n,o,s){let a=i.FK.empty;for(let e=n.length-1;e>=0;e--)a=i.FK.from(n[e].type.create(n[e].attrs,a));e.step(new r.Wg(t.start-2*!!o,t.end,t.start,t.end,new i.Ji(a,0,0),n.length,!0));let l=0;for(let e=0;e<n.length;e++)n[e].type==s&&(l=e+1);let d=n.length-l,c=t.start+n.length-2*!!o,h=t.parent;for(let n=t.startIndex,i=t.endIndex,o=!0;n<i;n++,o=!1)!o&&(0,r.zy)(e.doc,c,d)&&(e.split(c,d),c+=2*d),c+=h.child(n).nodeSize}(e,t,d,s,n),!0)}(d,l,e,t)&&(o&&o(d.scrollIntoView()),!0)}}function s(e){return function(t,n){let{$from:o,$to:s}=t.selection,a=o.blockRange(s,t=>t.childCount>0&&t.firstChild.type==e);return!!a&&(!n||(o.node(a.depth-1).type==e?function(e,t,n,o){let s=e.tr,a=o.end,l=o.$to.end(o.depth);a<l&&(s.step(new r.Wg(a-1,l,a,l,new i.Ji(i.FK.from(n.create(null,o.parent.copy())),1,0),1,!0)),o=new i.u$(s.doc.resolve(o.$from.pos),s.doc.resolve(l),o.depth));let d=(0,r.jP)(o);if(null==d)return!1;s.lift(o,d);let c=s.doc.resolve(s.mapping.map(a,-1)-1);return(0,r.n9)(s.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&s.join(c.pos),t(s.scrollIntoView()),!0}(t,n,e,a):function(e,t,n){let o=e.tr,s=n.parent;for(let e=n.end,t=n.endIndex-1,r=n.startIndex;t>r;t--)e-=s.child(t).nodeSize,o.delete(e-1,e+1);let a=o.doc.resolve(n.start),l=a.nodeAfter;if(o.mapping.map(n.end)!=n.start+a.nodeAfter.nodeSize)return!1;let d=0==n.startIndex,c=n.endIndex==s.childCount,h=a.node(-1),u=a.index(-1);if(!h.canReplace(u+ +!d,u+1,l.content.append(c?i.FK.empty:i.FK.from(s))))return!1;let p=a.pos,f=p+l.nodeSize;return o.step(new r.Wg(p-!!d,f+ +!!c,p+1,f-1,new i.Ji((d?i.FK.empty:i.FK.from(s.copy(i.FK.empty))).append(c?i.FK.empty:i.FK.from(s.copy(i.FK.empty))),+!d,+!c),+!d)),t(o.scrollIntoView()),!0}(t,n,a)))}}function a(e){return function(t,n){let{$from:o,$to:s}=t.selection,a=o.blockRange(s,t=>t.childCount>0&&t.firstChild.type==e);if(!a)return!1;let l=a.startIndex;if(0==l)return!1;let d=a.parent,c=d.child(l-1);if(c.type!=e)return!1;if(n){let o=c.lastChild&&c.lastChild.type==d.type,s=i.FK.from(o?e.create():null),l=new i.Ji(i.FK.from(e.create(null,i.FK.from(d.type.create(null,s)))),o?3:1,0),h=a.start,u=a.end;n(t.tr.step(new r.Wg(h-(o?3:1),u,h,u,l,1,!0)).scrollIntoView())}return!0}}},42442:(e,t,n)=>{"use strict";n.d(t,{Dc:()=>h,TL:()=>l,bL:()=>d});var r,i=n(12115),o=n(47527),s=Object.defineProperty,a=(e,t)=>s(e,"name",{value:t,configurable:!0});function l(e){let t=i.forwardRef((t,n)=>{let{children:r,...s}=t,a=null,l=!1,d=[];y(r)&&"function"==typeof v&&(r=v(r._payload)),i.Children.forEach(r,e=>{if(g(e)){l=!0;let t="child"in e.props?e.props.child:e.props.children;y(t)&&"function"==typeof v&&(t=v(t._payload)),a=u(e,t),d.push(a?.props?.children)}else d.push(e)}),a?a=i.cloneElement(a,void 0,d):!l&&1===i.Children.count(r)&&i.isValidElement(r)&&(a=r);let c=a?f(a):void 0,h=(0,o.s)(n,c);if(!a){if(r||0===r)throw Error(l?w(e):x(e));return r}let m=p(s,a.props??{});return a.type!==i.Fragment&&(m.ref=n?h:c),i.cloneElement(a,m)});return t.displayName=`${e}.Slot`,t}a(l,"createSlot");var d=l("Slot"),c=Symbol.for("radix.slottable");function h(e){let t=a(e=>"child"in e?e.children(e.child):e.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=c,t}a(h,"createSlottable");var u=a((e,t)=>{if("child"in e.props){let t=e.props.child;return i.isValidElement(t)?i.cloneElement(t,void 0,e.props.children(t.props.children)):null}return i.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function p(e,t){let n={...t};for(let r in t){let i=e[r],o=t[r];/^on[A-Z]/.test(r)?i&&o?n[r]=(...e)=>{let t=o(...e);return i(...e),t}:i&&(n[r]=i):"style"===r?n[r]={...i,...o}:"className"===r&&(n[r]=[i,o].filter(Boolean).join(" "))}return{...e,...n}}function f(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(n=(t=Object.getOwnPropertyDescriptor(e,"ref")?.get)&&"isReactWarning"in t&&t.isReactWarning)?e.props.ref:e.props.ref||e.ref}function g(e){return i.isValidElement(e)&&"function"==typeof e.type&&"__radixId"in e.type&&e.type.__radixId===c}a(p,"mergeProps"),a(f,"getElementRef"),a(g,"isSlottable");var m=Symbol.for("react.lazy");function y(e){return null!=e&&"object"==typeof e&&"$$typeof"in e&&e.$$typeof===m&&"_payload"in e&&b(e._payload)}function b(e){return"object"==typeof e&&null!==e&&"then"in e}a(y,"isLazyComponent"),a(b,"isPromiseLike");var x=a(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),w=a(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),v=(r||(r=n.t(i,2)))[" use ".trim().toString()]},43336:(e,t,n)=>{"use strict";n.d(t,{u:()=>o});let r=[n(37920).L],i=new Set(r.map(e=>e.type));function o(e){let t=[...r],n=new Set;for(let r of e){if(i.has(r.type))throw Error(`Shape type "${r.type}" is a core shapes type and cannot be overridden`);if(n.has(r.type))throw Error(`Shape type "${r.type}" is defined more than once`);t.push(r),n.add(r.type)}return t}},43502:(e,t,n)=>{"use strict";n.d(t,{O:()=>o,T:()=>u});var r=n(24167),i=n(38335);function o(e,t){return Math.round(e*t)}let s=/\r?\n|\r/g;function a(e){return e.replace(s,"\n").split("\n").map(e=>e||" ").join("\n")}let l={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},d=/\s/,c=new Intl.Segmenter(void 0,{granularity:"grapheme"}),h=Object.freeze({"overflow-wrap":"break-word","word-break":"auto",width:null,height:null,"max-width":null,"min-width":null});class u extends i.r{elm;poolElms=[];constructor(e){super(e),this.elm=this.createMeasurementEl(),this.editor.getContainer().appendChild(this.elm),this.register(()=>{for(let{el:e}of(this.elm.remove(),this.poolElms))e.remove();this.poolElms.length=0})}createMeasurementEl(){let e=this.editor.getContainerDocument().createElement("div");for(let t of(e.classList.add("tl-text"),e.classList.add("tl-text-measure"),e.setAttribute("dir","auto"),e.tabIndex=-1,(0,r.w$)(h)))e.style.setProperty(t,h[t]);return e}resetElementStyles(e,t){for(let n of t)n in h?e.style.setProperty(n,h[n]):e.style.removeProperty(n)}setElementStyles(e,t){let n=[];for(let[r,i]of Object.entries(t)){let t=e.style.getPropertyValue(r);if("string"==typeof i){if(t===i)continue;n.push([r,t||null]),e.style.setProperty(r,i)}else{if(!t)continue;n.push([r,t]),e.style.removeProperty(r)}}return()=>{for(let[t,r]of n)null===r||""===r?e.style.removeProperty(t):e.style.setProperty(t,r)}}getMeasureStyles(e){return{"font-family":e.fontFamily,"font-style":e.fontStyle,"font-weight":e.fontWeight,"font-size":e.fontSize+"px","line-height":`${o(e.fontSize,e.lineHeight)}px`,"--tl-rich-text-heading-line-height":`${e.lineHeight}`,padding:e.padding,"max-width":e.maxWidth?e.maxWidth+"px":void 0,"min-width":e.minWidth?e.minWidth+"px":void 0,"overflow-wrap":e.disableOverflowWrapBreaking?"normal":"break-word",...e.otherStyles}}ensurePoolSize(e){if(this.poolElms.length>=e)return;let t=this.editor.getContainerDocument().createDocumentFragment();for(;this.poolElms.length<e;){let e=this.createMeasurementEl();this.poolElms.push({el:e,html:"",appliedStyleKeys:[]}),t.appendChild(e)}this.editor.getContainer().appendChild(t)}getPoolItem(e){return this.ensurePoolSize(e+1),this.poolElms[e]}measureHtmlBatch(e){if(0===e.length)return[];for(;this.poolElms.length>e.length;){let{el:e}=this.poolElms.pop();e.remove()}for(let t=0;t<e.length;t++){let{html:n,opts:r}=e[t],i=this.getPoolItem(t),{el:o}=i;this.resetElementStyles(o,i.appliedStyleKeys);let s=this.getMeasureStyles(r);this.setElementStyles(o,s),i.appliedStyleKeys=Object.keys(s),i.html!==n&&(o.innerHTML=n,i.html=n)}let t=[];for(let n=0;n<e.length;n++){let r=this.getPoolItem(n).el,i=e[n].opts.measureScrollWidth?r.scrollWidth:0,o=r.getBoundingClientRect();t.push({x:0,y:0,w:o.width,h:o.height,scrollWidth:i})}return t}measureText(e,t){let n=this.editor.getContainerDocument().createElement("div");return n.textContent=a(e),this.measureHtml(n.innerHTML,t)}measureHtml(e,t){let{elm:n}=this,r=this.setElementStyles(n,this.getMeasureStyles(t));try{n.innerHTML=e;let r=t.measureScrollWidth?n.scrollWidth:0,i=n.getBoundingClientRect();return{x:0,y:0,w:i.width,h:i.height,scrollWidth:r}}finally{r()}}measureElementTextNodeSpans(e,{shouldTruncateToFirstLine:t=!1}={}){let n=[],r=e.getBoundingClientRect(),i=-r.left,o=-r.top,s=new Range,a=e.childNodes[0],l=0,h=null,u=null,p=0,f=0,g=!1;for(let r of e.childNodes)if(r.nodeType===Node.TEXT_NODE)for(let{segment:e}of c.segment(r.textContent??"")){s.setStart(a,l),s.setEnd(a,l+e.length);let r=s.getClientRects(),c=r[r.length-1];if(!c){l+=e.length;continue}let m=c.top+o,y=c.left+i,b=c.right+i,x=y<f,w=d.test(e);if(w===u&&m===p&&h)x&&(h.box.x=y),h.box.w=x?h.box.w+c.width:b-h.box.x,h.text+=e;else{if(h){if(t&&m!==p){g=!0;break}n.push(h)}h={box:{x:y,y:m,w:c.width,h:c.height},text:e},f=y}"\n"===e&&(f=0),u=w,p=m,l+=e.length}return h&&n.push(h),{spans:n,didTruncate:g}}measureTextSpans(e,t){if(""===e)return[];let{elm:n}=this,r="truncate-ellipsis"===t.overflow||"truncate-clip"===t.overflow,i=Math.ceil(t.width-2*t.padding),s={"font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"font-size":t.fontSize+"px","line-height":`${o(t.fontSize,t.lineHeight)}px`,width:`${i}px`,height:"min-content","text-align":l[t.textAlign],"overflow-wrap":r?"anywhere":"break-word","word-break":r?"break-all":"normal",...t.otherStyles},d=this.setElementStyles(n,s);try{let o=a(e);n.textContent=o;let{spans:s,didTruncate:l}=this.measureElementTextNodeSpans(n,{shouldTruncateToFirstLine:r});if("truncate-ellipsis"===t.overflow&&l){n.textContent="…";let e=Math.ceil(this.measureElementTextNodeSpans(n).spans[0].box.w);n.style.setProperty("width",`${i-e}px`),n.textContent=o;let r=this.measureElementTextNodeSpans(n,{shouldTruncateToFirstLine:!0}).spans,s=r[r.length-1];return r.push({text:"…",box:{x:Math.min(s.box.x+s.box.w,t.width-t.padding-e),y:s.box.y,w:e,h:s.box.h}}),r}return s}finally{d()}}}},43631:(e,t,n)=>{"use strict";n.d(t,{b:()=>s});var r=n(83102);n(27394),n(12115),n(80614);var i=n(97156);let o=(0,r.EW)("defaultLocalStorageUserPrefs",()=>(0,i.oE)());function s(e={}){return{userPreferences:e.userPreferences??o,setUserPreferences:e.setUserPreferences??i.A2}}},46195:(e,t,n)=>{"use strict";n.d(t,{l:()=>s});let{easeInQuad:r,easeInOutQuad:i}=n(58347).Z;function o(e){return Math.round(100*e)/100}class s{constructor(e=0,t=0,n=1){this.x=e,this.y=t,this.z=n}x;y;z;get pressure(){return this.z}set(e=this.x,t=this.y,n=this.z){return this.x=e,this.y=t,this.z=n,this}setTo({x:e=0,y:t=0,z:n=1}){return this.x=e,this.y=t,this.z=n,this}rot(e){if(0===e)return this;let{x:t,y:n}=this,r=Math.sin(e),i=Math.cos(e);return this.x=t*i-n*r,this.y=t*r+n*i,this}rotWith(e,t){if(0===t)return this;let n=this.x-e.x,r=this.y-e.y,i=Math.sin(t),o=Math.cos(t);return this.x=e.x+(n*o-r*i),this.y=e.y+(n*i+r*o),this}clone(){let{x:e,y:t,z:n}=this;return new s(e,t,n)}sub(e){return this.x-=e.x,this.y-=e.y,this}subXY(e,t){return this.x-=e,this.y-=t,this}subScalar(e){return this.x-=e,this.y-=e,this}add(e){return this.x+=e.x,this.y+=e.y,this}addXY(e,t){return this.x+=e,this.y+=t,this}addScalar(e){return this.x+=e,this.y+=e,this}clamp(e,t){return this.x=Math.max(this.x,e),this.y=Math.max(this.y,e),void 0!==t&&(this.x=Math.min(this.x,t),this.y=Math.min(this.y,t)),this}div(e){return this.x/=e,this.y/=e,this}divV(e){return this.x/=e.x,this.y/=e.y,this}mul(e){return this.x*=e,this.y*=e,this}mulV(e){return this.x*=e.x,this.y*=e.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(e,t){let n=s.Tan(e,this);return this.add(n.mul(t))}neg(){return this.x*=-1,this.y*=-1,this}cross(e){return this.x=this.y*e.z-this.z*e.y,this.y=this.z*e.x-this.x*e.z,this}dpr(e){return s.Dpr(this,e)}cpr(e){return s.Cpr(this,e)}len2(){return s.Len2(this)}len(){return s.Len(this)}pry(e){return s.Pry(this,e)}per(){let{x:e,y:t}=this;return this.x=t,this.y=-e,this}uni(){let e=this.len();return 0===e||(this.x/=e,this.y/=e),this}tan(e){return this.sub(e).uni()}dist(e){return s.Dist(this,e)}distanceToLineSegment(e,t){return s.DistanceToLineSegment(e,t,this)}slope(e){return s.Slope(this,e)}snapToGrid(e){return this.x=Math.round(this.x/e)*e,this.y=Math.round(this.y/e)*e,this}angle(e){return s.Angle(this,e)}toAngle(){return s.ToAngle(this)}lrp(e,t){return this.x=this.x+(e.x-this.x)*t,this.y=this.y+(e.y-this.y)*t,this}equals(e){return s.Equals(this,e)}equalsXY(e,t){return s.EqualsXY(this,e,t)}toFixed(){return this.x=o(this.x),this.y=o(this.y),this}toString(){return s.ToString(s.ToFixed(this))}toJson(){return s.ToJson(this)}toArray(){return s.ToArray(this)}static Add(e,t){return new s(e.x+t.x,e.y+t.y)}static AddXY(e,t,n){return new s(e.x+t,e.y+n)}static Sub(e,t){return new s(e.x-t.x,e.y-t.y)}static SubXY(e,t,n){return new s(e.x-t,e.y-n)}static AddScalar(e,t){return new s(e.x+t,e.y+t)}static SubScalar(e,t){return new s(e.x-t,e.y-t)}static Div(e,t){return new s(e.x/t,e.y/t)}static Mul(e,t){return new s(e.x*t,e.y*t)}static DivV(e,t){return new s(e.x/t.x,e.y/t.y)}static MulV(e,t){return new s(e.x*t.x,e.y*t.y)}static Neg(e){return new s(-e.x,-e.y)}static Per(e){return new s(e.y,-e.x)}static Abs(e){return new s(Math.abs(e.x),Math.abs(e.y))}static Dist(e,t){return((e.y-t.y)**2+(e.x-t.x)**2)**.5}static ManhattanDist(e,t){return Math.abs(e.x-t.x)+Math.abs(e.y-t.y)}static DistMin(e,t,n){return(e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y)<n**2}static Dist2(e,t){return(e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y)}static Dpr(e,t){return e.x*t.x+e.y*t.y}static Cross(e,t){return new s(e.y*t.z-e.z*t.y,e.z*t.x-e.x*t.z)}static Cpr(e,t){return e.x*t.y-t.x*e.y}static Len2(e){return e.x*e.x+e.y*e.y}static Len(e){return(e.x*e.x+e.y*e.y)**.5}static Pry(e,t){return s.Dpr(e,t)/s.Len(t)}static Uni(e){let t=s.Len(e);return new s(0===t?0:e.x/t,0===t?0:e.y/t)}static Tan(e,t){return s.Uni(s.Sub(e,t))}static Min(e,t){return new s(Math.min(e.x,t.x),Math.min(e.y,t.y))}static Max(e,t){return new s(Math.max(e.x,t.x),Math.max(e.y,t.y))}static From({x:e,y:t,z:n=1}){return new s(e,t,n)}static FromArray(e){return new s(e[0],e[1])}static Rot(e,t=0){let n=Math.sin(t),r=Math.cos(t);return new s(e.x*r-e.y*n,e.x*n+e.y*r)}static RotWith(e,t,n){let r=e.x-t.x,i=e.y-t.y,o=Math.sin(n),a=Math.cos(n);return new s(t.x+(r*a-i*o),t.y+(r*o+i*a))}static NearestPointOnLineThroughPoint(e,t,n){let r=(n.x-e.x)*t.x+(n.y-e.y)*t.y;return new s(e.x+t.x*r,e.y+t.y*r)}static NearestPointOnLineSegment(e,t,n,r=!0){let i=t.x-e.x,o=t.y-e.y,a=i*i+o*o;if(0===a)return s.From(e);let l=((n.x-e.x)*i+(n.y-e.y)*o)/a;return r&&(l<0?l=0:l>1&&(l=1)),new s(e.x+l*i,e.y+l*o)}static DistanceToLineThroughPoint(e,t,n){let r=n.x-e.x,i=n.y-e.y;return Math.abs(r*t.y-i*t.x)}static DistanceToLineSegment(e,t,n,r=!0){let i=t.x-e.x,o=t.y-e.y,a=i*i+o*o;if(0===a)return s.Dist(e,n);let l=((n.x-e.x)*i+(n.y-e.y)*o)/a;r&&(l<0?l=0:l>1&&(l=1));let d=e.x+l*i-n.x,c=e.y+l*o-n.y;return Math.sqrt(d*d+c*c)}static Snap(e,t=1){return new s(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}static Cast(e){return e instanceof s?e:s.From(e)}static Slope(e,t){return e.x===t.y?NaN:(e.y-t.y)/(e.x-t.x)}static IsNaN(e){return isNaN(e.x)||isNaN(e.y)}static IsFinite(e){return Number.isFinite(e.x)&&Number.isFinite(e.y)}static Angle(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}static AngleBetween(e,t){let n=e.x*t.x+e.y*t.y,r=Math.sqrt((e.x*e.x+e.y*e.y)*(t.x*t.x+t.y*t.y));return(e.x*t.y-e.y*t.x<0?-1:1)*Math.acos(Math.max(-1,Math.min(n/r,1)))}static Lrp(e,t,n){return new s(e.x+(t.x-e.x)*n,e.y+(t.y-e.y)*n)}static Med(e,t){return new s((e.x+t.x)/2,(e.y+t.y)/2)}static Equals(e,t){return 1e-4>Math.abs(e.x-t.x)&&1e-4>Math.abs(e.y-t.y)}static EqualsXY(e,t,n){return e.x===t&&e.y===n}static Clockwise(e,t,n){return(n.x-e.x)*(t.y-e.y)-(t.x-e.x)*(n.y-e.y)<0}static Rescale(e,t){let n=s.Len(e);return new s(t*e.x/n,t*e.y/n)}static ScaleWithOrigin(e,t,n){return s.Sub(e,n).mul(t).add(n)}static ToFixed(e){return new s(o(e.x),o(e.y))}static ToInt(e){return new s(parseInt(e.x.toFixed(0)),parseInt(e.y.toFixed(0)),parseInt((e.z??0).toFixed(0)))}static ToCss(e){return`${e.x},${e.y}`}static Nudge(e,t,n){return s.Add(e,s.Tan(t,e).mul(n))}static ToString(e){return`${e.x}, ${e.y}`}static ToAngle(e){let t=Math.atan2(e.y,e.x);return t<0&&(t+=2*Math.PI),t}static FromAngle(e,t=1){return new s(Math.cos(e)*t,Math.sin(e)*t)}static ToArray(e){return[e.x,e.y,e.z]}static ToJson(e){let{x:t,y:n,z:r}=e;return{x:t,y:n,z:r}}static Average(e){let t=e.length,n=new s(0,0);if(0===t)return n;for(let r=0;r<t;r++)n.add(e[r]);return n.div(t)}static Clamp(e,t,n){return void 0===n?new s(Math.min(Math.max(e.x,t)),Math.min(Math.max(e.y,t))):new s(Math.min(Math.max(e.x,t),n),Math.min(Math.max(e.y,t),n))}static PointsBetween(e,t,n=6,o=r){let a=[];for(let r=0;r<n;r++){let l=o(r/(n-1)),d=s.Lrp(e,t,l);d.z=Math.min(1,.5+.65*Math.abs(.5-i(l))),a.push(d)}return a}static SnapToGrid(e,t=8){return new s(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}}},47527:(e,t,n)=>{"use strict";n.d(t,{s:()=>l});var r=n(12115),i=Object.defineProperty,o=(e,t)=>i(e,"name",{value:t,configurable:!0});function s(e,t){if("function"==typeof e)return e(t);null!=e&&(e.current=t)}function a(...e){return t=>{let n=!1,r=e.map(e=>{let r=s(e,t);return n||"function"!=typeof r||(n=!0),r});if(n)return()=>{for(let t=0;t<r.length;t++){let n=r[t];"function"==typeof n?n():s(e[t],null)}}}}function l(...e){return r.useCallback(a(...e),e)}o(s,"setRef"),o(a,"composeRefs"),o(l,"useComposedRefs")},48077:(e,t,n)=>{"use strict";function r(e){if(e.shadowRoot)return e.shadowRoot.childNodes;if(function(e){var t;return"getRootNode"in e&&(t=e.getRootNode())instanceof l(t).ShadowRoot&&e instanceof l(e).HTMLSlotElement}(e)){let t=e.assignedNodes();if(t?.length)return t}return e.childNodes}function*i(e){for(let t of r(e))d(t)&&(yield t)}function o(e){if(!e)return globalThis;let t=a(e)?e:e.ownerDocument;return t?.defaultView??globalThis}function s(e){return e?a(e)?e:e.ownerDocument??globalThis.document:globalThis.document}function a(e){return e.nodeType===Node.DOCUMENT_NODE}function l(e){return e.ownerDocument?.defaultView??globalThis}function d(e){return e instanceof l(e).Element}function c(e){return e.style}function h(e,t){return l(e).getComputedStyle(e,t)}n.d(t,{$3:()=>i,EV:()=>c,L9:()=>h,TW:()=>s,XH:()=>r,mD:()=>o,vq:()=>d})},48877:(e,t,n)=>{"use strict";function r(e,t){let n=e,r=new Set(t);for(;r.has(n);)n=/^.*(\d+)$/.exec(n)?.[1]?n.replace(/(\d+)$/,e=>(+e+1).toString()):`${n} 1`;return n}n.d(t,{g:()=>r})},49402:(e,t,n)=>{"use strict";n.d(t,{c:()=>l});var r=n(24167),i=n(38335),o=Object.defineProperty,s=Object.getOwnPropertyDescriptor,a=(e,t,n,r)=>{for(var i,a=r>1?void 0:r?s(t,n):t,l=e.length-1;l>=0;l--)(i=e[l])&&(a=(r?i(t,n,a):i(a))||a);return r&&a&&o(t,n,a),a};class l extends i.r{constructor(e,t){super(e);const n=e.sideEffects.registerAfterChangeHandler("instance",(e,t)=>{e.isFocused!==t.isFocused&&this.updateContainerClass()});this.register(()=>n?.()),t!==e.getInstanceState().isFocused&&e.updateInstanceState({isFocused:!!t}),this.updateContainerClass();const r=e.getContainerDocument().body;r.addEventListener("keydown",this.handleKeyDown),r.addEventListener("mousedown",this.handleMouseDown),this.register(()=>{r.removeEventListener("keydown",this.handleKeyDown),r.removeEventListener("mousedown",this.handleMouseDown)})}updateContainerClass(){let e=this.editor.getContainer();this.editor.getInstanceState().isFocused?e.classList.add("tl-container__focused"):e.classList.remove("tl-container__focused"),e.classList.add("tl-container__no-focus-ring")}handleKeyDown(e){let t=this.editor.getContainer(),n=t.ownerDocument.activeElement;this.editor.getEditingShapeId()&&!n?.closest(".tlui-contextual-toolbar")||(n!==t||!(this.editor.getSelectedShapeIds().length>0))&&["Tab","ArrowUp","ArrowDown"].includes(e.key)&&t.classList.remove("tl-container__no-focus-ring")}handleMouseDown(){this.editor.getContainer().classList.add("tl-container__no-focus-ring")}focus(){this.editor.getContainer().focus()}blur({blurContainer:e=!0}={}){this.editor.complete(),e&&this.editor.getContainer().blur()}}a([r.oI],l.prototype,"handleKeyDown",1),a([r.oI],l.prototype,"handleMouseDown",1)},49450:(e,t,n)=>{"use strict";n.d(t,{i:()=>a});var r=n(83102),i=n(81467),o=n(24167);function s(e,t){let n={};return Array.from(e.get(),e=>t.get(e)).sort(o.Ky).forEach(e=>{n[e.parentId]??=[],n[e.parentId].push(e.id)}),n}function a(e){let t=e.query.ids("shape"),n=e.query.filterHistory("shape");return(0,r.EW)("parentsToChildrenWithIndexes",(a,l)=>{let d;if((0,r._O)(a))return s(t,e);let c=n.getDiffSince(l);if(c===r.c2)return s(t,e);if(0===c.length)return a;let h=null,u=e=>{h||(h={...a}),h[e]?h[e]===a[e]&&(h[e]=[...h[e]]):h[e]=[]},p=new Set;for(let e=0,t=c.length;e<t;e++){for(let t of Object.values((d=c[e]).added))(0,i.o2)(t)&&(u(t.parentId),h[t.parentId].push(t.id),p.add(h[t.parentId]));for(let[e,t]of Object.values(d.updated))if((0,i.o2)(t)&&(0,i.o2)(e)){if(e.parentId!==t.parentId)u(e.parentId),u(t.parentId),h[e.parentId].splice(h[e.parentId].indexOf(t.id),1),h[t.parentId].push(t.id),p.add(h[t.parentId]);else if(e.index!==t.index){u(t.parentId);let e=h[t.parentId].indexOf(t.id);h[t.parentId][e]=t.id,p.add(h[t.parentId])}}for(let e of Object.values(d.removed))(0,i.o2)(e)&&(u(e.parentId),h[e.parentId].splice(h[e.parentId].indexOf(e.id),1))}for(let t of p){let n=0;for(let r=0;r<t.length;r++)e.get(t[r])&&(t[n++]=t[r]);t.length=n,t.sort((t,n)=>{let r=e.get(t),i=e.get(n);return(0,o.Ky)(r,i)})}return h??a})}},50139:(e,t,n)=>{"use strict";n.d(t,{g:()=>i});var r=n(13982);function i(e){return r.Y.isDarwin?e.metaKey:e.ctrlKey||e.metaKey}},50585:(e,t,n)=>{"use strict";n.d(t,{Bb:()=>c,Jf:()=>h,ls:()=>u});var r=n(95155),i=n(24167),o=n(12115),s=n(87767),a=n(67863),l=n(18314);let d=(0,o.createContext)(null);function c({context:e,editor:t,children:n}){let i=t.options.exportProvider;return(0,r.jsx)(a.zz,{editor:t,children:(0,r.jsx)(s.ts,{container:t.getContainer(),children:(0,r.jsx)(d.Provider,{value:e,children:(0,r.jsx)(i,{children:n})})})})}function h(){return(0,o.useContext)(d)}function u(){let e=(0,o.useContext)(d),[t]=(0,o.useState)(i.il);return(0,o.useEffect)(()=>(e?.waitUntil(t),()=>{t.resolve()}),[t,e]),(0,l._)(()=>{t.resolve()})}},51286:(e,t,n)=>{"use strict";n.d(t,{L:()=>l});var r=n(83102),i=n(54530),o=n(24167);let s={get:()=>void 0},a={get:()=>void 0};class l{constructor(e,t){this.editor=e,this.assetUrls=t,this.shapeFontFacesCache=e.store.createComputedCache("shape font faces",e=>this.editor.getShapeUtil(e).getFontFaces(e),{areResultsEqual:o.vq,areRecordsEqual:(e,t)=>e.props===t.props&&e.meta===t.meta}),this.shapeFontLoadStateCache=e.store.createCache(e=>{let t=(0,r.EW)("font faces",()=>this.getShapeFontFaces(e));return(0,r.EW)("font load state",()=>t.get().map(e=>this.getFontState(e)),{isEqual:o.vq})})}editor;assetUrls;dispose(){this.fontStates.clear(),this.fontsToLoad.clear(),this.shapeFontFacesCache=s,this.shapeFontLoadStateCache=a}shapeFontFacesCache;shapeFontLoadStateCache;getShapeFontFaces(e){let t="string"==typeof e?e:e.id;return this.shapeFontFacesCache.get(t)??r.Ml}trackFontsForShape(e){let t="string"==typeof e?e:e.id;this.shapeFontLoadStateCache.get(t)}async loadRequiredFontsForCurrentPage(e=1/0){let t=new Set;for(let e of this.editor.getCurrentPageShapeIds())for(let n of this.getShapeFontFaces(this.editor.getShape(e)))t.add(n);if(t.size>e)return;let n=Array.from(t,e=>this.ensureFontIsLoaded(e));await Promise.all(n)}fontStates=new i._j("font states");getFontState(e){return this.fontStates.get(e)??null}ensureFontIsLoaded(e){let t=this.getFontState(e);if(t)return t.loadingPromise;let n=this.findOrCreateFontFace(e),r=()=>this.fontStates.__unsafe__getWithoutCapture(e)!==i,i={state:"loading",instance:n,loadingPromise:n.load().then(()=>{r()?console.debug(`Font "${e.family}" load interrupted by editor dispose`):(this.editor.getContainerDocument().fonts.add(n),this.fontStates.update(e,e=>({...e,state:"ready"})))}).catch(t=>{r()?console.debug(`Font "${e.family}" load interrupted by editor dispose`,t):(console.error(t),this.fontStates.update(e,e=>({...e,state:"error"})))})};return this.fontStates.set(e,i),i.loadingPromise}fontsToLoad=new Set;requestFonts(e){for(let t of(this.fontsToLoad.size||queueMicrotask(()=>{if(this.editor.isDisposed)return;let e=this.fontsToLoad;this.fontsToLoad=new Set,(0,r.hL)(()=>{for(let t of e)this.ensureFontIsLoaded(t)})}),e))this.fontsToLoad.add(t)}findOrCreateFontFace(e){var t;let n=this.editor.getContainerDocument(),r=c.get(n);r||(r=new Map,c.set(n,r));let i=JSON.stringify([(t=e).family,...(0,o.iA)(d).map(([e,n])=>t[e]??n)]),s=r.get(i);if(s)return s;let a=n.fonts;for(let t of a)if(t.family===e.family&&(0,o.iA)(d).every(([n,r])=>t[n]===(e[n]??r)))return r.set(i,t),t;let l=this.assetUrls?.[e.src.url]??e.src.url,h=new FontFace(e.family,`url(${JSON.stringify(l)})`,{...(0,o._H)(d,t=>e[t]),display:"swap"});return a.add(h),r.set(i,h),h}async toEmbeddedCssDeclaration(e){let t=this.assetUrls?.[e.src.url]??e.src.url,n=await o.Sm.urlToDataUrl(t),r=(0,o.oE)([`url("${n}")`,e.src.format?`format(${e.src.format})`:null,e.src.tech?`tech(${e.src.tech})`:null]).join(" ");return(0,o.oE)(["@font-face {",` font-family: "${e.family}";`,e.ascentOverride?` ascent-override: ${e.ascentOverride};`:null,e.descentOverride?` descent-override: ${e.descentOverride};`:null,e.stretch?` font-stretch: ${e.stretch};`:null,e.style?` font-style: ${e.style};`:null,e.weight?` font-weight: ${e.weight};`:null,e.featureSettings?` font-feature-settings: ${e.featureSettings};`:null,e.lineGapOverride?` line-gap-override: ${e.lineGapOverride};`:null,e.unicodeRange?` unicode-range: ${e.unicodeRange};`:null,` src: ${r};`,"}"]).join("\n")}}let d={style:"normal",weight:"normal",stretch:"normal",unicodeRange:"U+0-10FFFF",featureSettings:"normal",ascentOverride:"normal",descentOverride:"normal",lineGapOverride:"normal"},c=new WeakMap},52800:(e,t,n)=>{"use strict";function r(e){let t=[],n=new Set;for(let r of e){if(n.has(r.type))throw Error(`Binding type "${r.type}" is defined more than once`);t.push(r),n.add(r.type)}return t}n.d(t,{t:()=>r})},54498:(e,t,n)=>{"use strict";n.d(t,{i:()=>f});var r=n(12115),i=n.t(r,2),o=n(3510),s=n(66294),a=Object.defineProperty,l=i[" useEffectEvent ".trim().toString()],d=i[" useInsertionEffect ".trim().toString()];function c(e){if("function"==typeof l)return l(e);let t=r.useRef(()=>{throw Error("Cannot call an event handler while rendering.")});return"function"==typeof d?d(()=>{t.current=e}):(0,s.N)(()=>{t.current=e}),r.useMemo(()=>(...e)=>t.current?.(...e),[])}a(c,"name",{value:"useEffectEvent",configurable:!0});var h=Object.defineProperty,u=(e,t)=>h(e,"name",{value:t,configurable:!0}),p=i[" useInsertionEffect ".trim().toString()]||s.N;function f({prop:e,defaultProp:t,onChange:n=u(()=>{},"onChange"),caller:i}){let[s,a,l]=g({defaultProp:t,onChange:n}),d=void 0!==e,c=d?e:s;if(o.D){let t=r.useRef(void 0!==e);r.useEffect(()=>{let e=t.current;if(e!==d){let t=d?"controlled":"uncontrolled";console.warn(`${i} is changing from ${e?"controlled":"uncontrolled"} to ${t}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`)}t.current=d},[d,i])}return[c,r.useCallback(t=>{if(d){let n=m(t)?t(e):t;n!==e&&l.current?.(n)}else a(t)},[d,e,a,l])]}function g({defaultProp:e,onChange:t}){let[n,i]=r.useState(e),o=r.useRef(n),s=r.useRef(t);return p(()=>{s.current=t},[t]),r.useEffect(()=>{o.current!==n&&(s.current?.(n),o.current=n)},[n,o]),[n,i,s]}function m(e){return"function"==typeof e}u(f,"useControllableState"),u(g,"useUncontrolledState"),u(m,"isFunction");var y=Symbol("RADIX:SYNC_STATE");u(function(e,t,n,i){let{prop:s,defaultProp:a,onChange:l,caller:d}=t,h=void 0!==s,u=c(l);if(o.D){let e=r.useRef(void 0!==s);r.useEffect(()=>{let t=e.current;if(t!==h){let e=h?"controlled":"uncontrolled";console.warn(`${d} is changing from ${t?"controlled":"uncontrolled"} to ${e}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`)}e.current=h},[h,d])}let p=[{...n,state:a}];i&&p.push(i);let[f,g]=r.useReducer((t,n)=>{if(n.type===y)return{...t,state:n.state};let r=e(t,n);return h&&!Object.is(r.state,t.state)&&u(r.state),r},...p),m=f.state,b=r.useRef(m);r.useEffect(()=>{b.current!==m&&(b.current=m,h||u(m))},[m,b,h]);let x=r.useMemo(()=>void 0!==s?{...f,state:s}:f,[f,s]);return r.useEffect(()=>{h&&!Object.is(s,f.state)&&g({type:y,state:s})},[s,f.state,h]),[x,g]},"useControllableStateReducer")},54530:(e,t,n)=>{"use strict";let r;n.d(t,{_j:()=>V,uw:()=>Y,zq:()=>X,ee:()=>eh,il:()=>ex,fX:()=>eS,uY:()=>ev,L4:()=>eo,bo:()=>Z,_B:()=>J,XD:()=>Q,WE:()=>eu,RF:()=>ea,E8:()=>es,Dm:()=>ed,Fl:()=>ec});var i=n(24167),o=n(83102);function s(e){return e>>>1&0x40000000|0xbfffffff&e}let a=Object.prototype.valueOf;function l(e){if(null==e)return d(e);if("function"==typeof e.hashCode)return s(e.hashCode(e));let t=(n=e).valueOf!==a&&"function"==typeof n.valueOf?n.valueOf(n):n;if(null==t)return d(t);switch(typeof t){case"boolean":return t?0x42108421:0x42108420;case"number":var n,r,i,o,l=t;if(l!=l||l===1/0)return 0;let f=0|l;for(f!==l&&(f^=0xffffffff*l);l>0xffffffff;)l/=0xffffffff,f^=l;return s(f);case"string":let b;return void 0===(b=g[r=t])&&(b=c(r),m===y&&(m=0,g={}),g[r]=b,m++),b;case"object":case"function":let x;return i=t,void 0!==(x=u.get(i))||(x=h(),u.set(i,x)),x;case"symbol":let w;return void 0!==(w=p[o=t])||(w=h(),p[o]=w),w;default:if("function"==typeof t.toString)return c(t.toString());throw Error("Value type "+typeof t+" cannot be hashed.")}}function d(e){return null===e?0x42108422:0x42108423}function c(e){let t=0;for(let n=0;n<e.length;n++)t=31*t+e.charCodeAt(n)|0;return s(t)}function h(){let e=++f;return 0x40000000&f&&(f=0),e}let u=new WeakMap,p=Object.create(null),f=0,g={},m=0,y=24e3,b={};function x(){return{value:!1}}function w(e){e&&(e.value=!0)}function v(e,t=0){return e.slice(t)}class S{}class C{_root;size;__ownerID;__hash;__altered;constructor(e){return null==e?R():e instanceof C?e:R().withMutations(t=>{for(let[n,r]of e)t.set(n,r)})}get(e,t){return this._root?this._root.get(0,void 0,e,t):t}set(e,t){return F(this,e,t)}delete(e){return F(this,e,b)}deleteAll(e){return this.withMutations(t=>{for(let n of e)t.delete(n)})}__ensureOwner(e){return e===this.__ownerID?this:e?L(this.size,this._root,e,this.__hash):0===this.size?R():(this.__ownerID=e,this.__altered=!1,this)}withMutations(e){let t=this.asMutable();return e(t),t.wasAltered()?t.__ensureOwner(this.__ownerID):this}wasAltered(){return this.__altered}asMutable(){return this.__ownerID?this:this.__ensureOwner(new S)}[Symbol.iterator](){return this.entries()[Symbol.iterator]()}entries(){return new _(this,D,!1)}keys(){return new _(this,j,!1)}values(){return new _(this,O,!1)}}class k{constructor(e,t){this.ownerID=e,this.entries=t}ownerID;entries;get(e,t,n,r){let i=this.entries;for(let e=0,t=i.length;e<t;e++)if(Object.is(n,i[e][0]))return i[e][1];return r}update(e,t,n,r,i,o,s){let a=i===b,d=this.entries,c=0,h=d.length;for(;c<h&&!Object.is(r,d[c][0]);c++);let u=c<h;if(u?d[c][1]===i:a)return this;if(w(s),(a||!u)&&w(o),a&&1===d.length)return;if(!u&&!a&&d.length>=U){var p=e,f=d,g=r,m=i;p||(p=new S);let t=new I(p,l(g),[g,m]);for(let e=0;e<f.length;e++){let n=f[e];t=t.update(p,0,void 0,n[0],n[1])}return t}let y=e&&e===this.ownerID,x=y?d:v(d);return(u?a?c===h-1?x.pop():x[c]=x.pop():x[c]=[r,i]:x.push([r,i]),y)?(this.entries=x,this):new k(e,x)}}class P{constructor(e,t,n){this.ownerID=e,this.bitmap=t,this.nodes=n}ownerID;bitmap;nodes;get(e,t,n,r){void 0===t&&(t=l(n));let i=1<<((0===e?t:t>>>e)&31),o=this.bitmap;return(o&i)==0?r:this.nodes[B(o&i-1)].get(e+5,t,n,r)}update(e,t,n,r,i,o,s){void 0===n&&(n=l(r));let a=(0===t?n:n>>>t)&31,d=1<<a,c=this.bitmap,h=(c&d)!=0;if(!h&&i===b)return this;let u=B(c&d-1),p=this.nodes,f=h?p[u]:void 0,g=z(f,e,t+5,n,r,i,o,s);if(g===f)return this;if(!h&&g&&p.length>=K){var m=e,y=p,x=c,w=a,v=g;let t=0,n=Array(32);for(let e=0;0!==x;e++,x>>>=1)n[e]=1&x?y[t++]:void 0;return n[w]=v,new T(m,t+1,n)}if(h&&!g&&2===p.length&&N(p[1^u]))return p[1^u];if(h&&g&&1===p.length&&N(g))return g;let S=e&&e===this.ownerID,C=h?g?c:c^d:c|d,k=h?g?H(p,u,g,S):function(e,t,n){let r=e.length-1;if(n&&t===r)return e.pop(),e;let i=Array(r),o=0;for(let n=0;n<r;n++)n===t&&(o=1),i[n]=e[n+o];return i}(p,u,S):function(e,t,n,r){let i=e.length+1;if(r&&t+1===i)return e[t]=n,e;let o=Array(i),s=0;for(let r=0;r<i;r++)r===t?(o[r]=n,s=-1):o[r]=e[r+s];return o}(p,u,g,S);return S?(this.bitmap=C,this.nodes=k,this):new P(e,C,k)}}class T{constructor(e,t,n){this.ownerID=e,this.count=t,this.nodes=n}ownerID;count;nodes;get(e,t,n,r){void 0===t&&(t=l(n));let i=(0===e?t:t>>>e)&31,o=this.nodes[i];return o?o.get(e+5,t,n,r):r}update(e,t,n,r,i,o,s){void 0===n&&(n=l(r));let a=(0===t?n:n>>>t)&31,d=i===b,c=this.nodes,h=c[a];if(d&&!h)return this;let u=z(h,e,t+5,n,r,i,o,s);if(u===h)return this;let p=this.count;if(h){if(!u&&--p<W)return function(e,t,n,r){let i=0,o=0,s=Array(n);for(let e=0,n=1,a=t.length;e<a;e++,n<<=1){let a=t[e];void 0!==a&&e!==r&&(i|=n,s[o++]=a)}return new P(e,i,s)}(e,c,p,a)}else p++;let f=e&&e===this.ownerID,g=H(c,a,u,f);return f?(this.count=p,this.nodes=g,this):new T(e,p,g)}}class E{constructor(e,t,n){this.ownerID=e,this.keyHash=t,this.entries=n}ownerID;keyHash;entries;get(e,t,n,r){let i=this.entries;for(let e=0,t=i.length;e<t;e++)if(Object.is(n,i[e][0]))return i[e][1];return r}update(e,t,n,r,i,o,s){void 0===n&&(n=l(r));let a=i===b;if(n!==this.keyHash)return a?this:(w(s),w(o),$(this,e,t,n,[r,i]));let d=this.entries,c=0,h=d.length;for(;c<h&&!Object.is(r,d[c][0]);c++);let u=c<h;if(u?d[c][1]===i:a)return this;if(w(s),(a||!u)&&w(o),a&&2===h)return new I(e,this.keyHash,d[1^c]);let p=e&&e===this.ownerID,f=p?d:v(d);return(u?a?c===h-1?f.pop():f[c]=f.pop():f[c]=[r,i]:f.push([r,i]),p)?(this.entries=f,this):new E(e,this.keyHash,f)}}class I{constructor(e,t,n){this.ownerID=e,this.keyHash=t,this.entry=n}ownerID;keyHash;entry;get(e,t,n,r){return Object.is(n,this.entry[0])?this.entry[1]:r}update(e,t,n,r,i,o,s){let a=i===b,d=Object.is(r,this.entry[0]);return(d?i===this.entry[1]:a)?this:(w(s),a)?void w(o):d?e&&e===this.ownerID?(this.entry[1]=i,this):new I(e,this.keyHash,[r,i]):(w(o),$(this,e,t,l(r),[r,i]))}}class _{constructor(e,t,n){this._type=t,this._reverse=n,this._stack=e._root&&A(e._root)}_type;_reverse;_stack;[Symbol.iterator](){return this}next(){let e=this._type,t=this._stack;for(;t;){let n,r=t.node,i=t.index++;if(r.entry){if(0===i)return M(e,r.entry)}else if("entries"in r&&r.entries){if(i<=(n=r.entries.length-1))return M(e,r.entries[this._reverse?n-i:i])}else if(i<=(n=r.nodes.length-1)){let o=r.nodes[this._reverse?n-i:i];if(o){if(o.entry)return M(e,o.entry);t=this._stack=A(o,t)}continue}t=this._stack=this._stack.__prev}return{value:void 0,done:!0}}}function M(e,t){var n,r,i,o;let s;return n=e,r=t[0],i=t[1],s=n===j?r:n===O?i:[r,i],o?o.value=s:o={value:s,done:!1},o}function A(e,t){return{node:e,index:0,__prev:t}}let j=0,O=1,D=2;function L(e,t,n,r){let i=Object.create(C.prototype);return i.size=e,i._root=t,i.__ownerID=n,i.__hash=r,i.__altered=!1,i}function R(){return r||(r=L(0))}function F(e,t,n){let r,i;if(e._root){let o=x(),s=x();if(r=z(e._root,e.__ownerID,0,void 0,t,n,o,s),!s.value)return e;i=e.size+(o.value?n===b?-1:1:0)}else{if(n===b)return e;i=1,r=new k(e.__ownerID,[[t,n]])}return e.__ownerID?(e.size=i,e._root=r,e.__hash=void 0,e.__altered=!0,e):r?L(i,r):R()}function z(e,t,n,r,i,o,s,a){return e?e.update(t,n,r,i,o,s,a):o===b?e:(w(a),w(s),new I(t,r,[i,o]))}function N(e){return e.constructor===I||e.constructor===E}function $(e,t,n,r,i){let o;if(e.keyHash===r)return new E(t,r,[e.entry,i]);let s=(0===n?e.keyHash:e.keyHash>>>n)&31,a=(0===n?r:r>>>n)&31,l=s===a?[$(e,t,n+5,r,i)]:(o=new I(t,r,i),s<a?[e,o]:[o,e]);return new P(t,1<<s|1<<a,l)}function B(e){return e-=e>>1&0x55555555,e=(e=(0x33333333&e)+(e>>2&0x33333333))+(e>>4)&0xf0f0f0f,e+=e>>8,127&(e+=e>>16)}function H(e,t,n,r){let i=r?e:v(e);return i[t]=n,i}let U=8,K=16,W=8;class V{constructor(e,t){this.name=e;let n=R();t&&(n=n.withMutations(n=>{for(let[r,i]of t)n.set(r,(0,o.eU)(`${e}:${String(r)}`,i))})),this.atoms=(0,o.eU)(`${e}:atoms`,n)}name;atoms;getAtom(e){let t=this.atoms.__unsafe__getWithoutCapture().get(e);return t||void this.atoms.get()}get(e){let t=this.getAtom(e)?.get();return(0,i.vA)(t!==o.UP),t}__unsafe__getWithoutCapture(e){let t=this.atoms.__unsafe__getWithoutCapture().get(e);if(!t)return;let n=t.__unsafe__getWithoutCapture();return(0,i.vA)(n!==o.UP),n}has(e){let t=this.getAtom(e);return!!t&&t.get()!==o.UP}__unsafe__hasWithoutCapture(e){let t=this.atoms.__unsafe__getWithoutCapture().get(e);return!!t&&((0,i.vA)(t.__unsafe__getWithoutCapture()!==o.UP),!0)}set(e,t){let n=this.atoms.__unsafe__getWithoutCapture().get(e);return n?n.set(t):this.atoms.update(n=>n.set(e,(0,o.eU)(`${this.name}:${String(e)}`,t))),this}update(e,t){let n=this.atoms.__unsafe__getWithoutCapture().get(e);if(!n)throw Error(`AtomMap: key ${e} not found`);let r=n.__unsafe__getWithoutCapture();(0,i.vA)(r!==o.UP),n.set(t(r))}delete(e){let t=this.atoms.__unsafe__getWithoutCapture().get(e);return!!t&&((0,o.hL)(()=>{t.set(o.UP),this.atoms.update(t=>t.delete(e))}),!0)}deleteMany(e){return(0,o.hL)(()=>{let t=[],n=this.atoms.get().withMutations(n=>{for(let r of e){let e=n.get(r);if(!e)continue;let s=e.get();(0,i.vA)(s!==o.UP),t.push([r,s]),n.delete(r),e.set(o.UP)}});return t.length&&this.atoms.set(n),t})}clear(){return(0,o.hL)(()=>{for(let e of this.atoms.__unsafe__getWithoutCapture().values())e.set(o.UP);this.atoms.set(R())})}*entries(){for(let[e,t]of this.atoms.get()){let n=t.get();(0,i.vA)(n!==o.UP),yield[e,n]}}*keys(){for(let e of this.atoms.get().keys())yield e}*values(){for(let e of this.atoms.get().values()){let t=e.get();(0,i.vA)(t!==o.UP),yield t}}get size(){return this.atoms.get().size}forEach(e,t){for(let[n,r]of this.entries())e.call(t,r,n,this)}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="AtomMap"}class Y{constructor(e,t){this.name=e;const n=t?Array.from(t,e=>[e,e]):void 0;this.map=new V(e,n)}name;map;add(e){return this.map.set(e,e),this}clear(){this.map.clear()}delete(e){return this.map.delete(e)}forEach(e,t){for(let n of this)e.call(t,n,n,this)}has(e){return this.map.has(e)}get size(){return this.map.size}entries(){return this.map.entries()}keys(){return this.map.keys()}values(){return this.map.keys()}[Symbol.iterator](){return this.map.keys()}[Symbol.toStringTag]="AtomSet"}let G=!1;try{G=!1}catch(e){}try{G=G||(void 0).DEV||(void 0).TEST||"development"===(void 0).MODE||"test"===(void 0).MODE}catch(e){}function q(e){if(!G)return e;let t=Object.getPrototypeOf(e);if(t&&!(Array.isArray(e)||t===Object.prototype||null===t||t===i.DM))throw console.error("cannot include non-js data in a record",e),Error("cannot include non-js data in a record");if(Object.isFrozen(e))return e;for(let t of Object.getOwnPropertyNames(e)){let n=e[t];n&&"object"==typeof n&&q(n)}return Object.freeze(e)}class X{constructor(e){this.previousValue=e}previousValue;nextValue;diff;get(){let e=this.diff?.removed?.size??0,t=this.diff?.added?.size??0;if(0!==e||0!==t)return{value:this.nextValue,diff:this.diff}}_add(e,t){this.nextValue??=new Set(this.previousValue),this.nextValue.add(e),this.diff??={},t?this.diff.removed?.delete(e):(this.diff.added??=new Set,this.diff.added.add(e))}add(e){let t=this.previousValue.has(e);if(t){if(!this.diff?.removed?.has(e))return;return this._add(e,t)}this.nextValue?.has(e)||this._add(e,t)}_remove(e,t){this.nextValue??=new Set(this.previousValue),this.nextValue.delete(e),this.diff??={},t?(this.diff.removed??=new Set,this.diff.removed.add(e)):this.diff.added?.delete(e)}remove(e){let t=this.previousValue.has(e);if(!t){if(!this.diff?.added?.has(e))return;return this._remove(e,t)}this.diff?.removed?.has(e)||this._remove(e,t)}}function J({sequence:e,sequenceId:t,retroactive:n=!0}){let r={sequenceId:t,retroactive:n,sequence:function(e){let t=[];for(let n=e.length-1;n>=0;n--){let r=e[n];if("id"in r)t.unshift(r);else{let e=r.dependsOn,n=t[0];n&&(t[0]={...n,dependsOn:e.concat(n.dependsOn??[])})}}return t}(e)};return en(r),r}function Z(e,t){return Object.fromEntries((0,i.iA)(t).map(([t,n])=>[t,`${e}/${n}`]))}function Q(e){return J({sequenceId:e.sequenceId,retroactive:e.retroactive??!0,sequence:e.sequence.map(t=>"id"in t?{...t,scope:"record",filter:n=>n.typeName===e.recordType&&(t.filter?.(n)??!0)&&(e.filter?.(n)??!0)}:t)})}function ee(e){let[t,n]=e.split("/");return{sequenceId:t,version:parseInt(n)}}function et(e,t){t&&(0,i.vA)(e.startsWith(t+"/"),`Every migration in sequence '${t}' must have an id starting with '${t}/'. Got invalid id: '${e}'`),(0,i.vA)(e.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${e}'`)}function en(e){if((0,i.vA)(!e.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${e.sequenceId}`),(0,i.vA)(e.sequenceId.length,"sequenceId must be a non-empty string"),0===e.sequence.length)return;et(e.sequence[0].id,e.sequenceId);let t=ee(e.sequence[0].id).version;(0,i.vA)(1===t,`Expected the first migrationId to be '${e.sequenceId}/1' but got '${e.sequence[0].id}'`);for(let n=1;n<e.sequence.length;n++){let r=e.sequence[n].id;et(r,e.sequenceId);let o=ee(r).version;(0,i.vA)(o===t+1,`Migration id numbers must increase in increments of 1, expected ${e.sequenceId}/${t+1} but got '${e.sequence[n].id}'`),t=o}}let er="target-version-too-old",ei="migration-error";function eo(){return{added:{},updated:{},removed:{}}}function es(e){let t={added:e.removed,removed:e.added,updated:{}};for(let[n,r]of Object.values(e.updated))t.updated[n.id]=[r,n];return t}function ea(e){return!el(e.added)&&!el(e.updated)&&!el(e.removed)}function el(e){for(let t in e)return!0;return!1}function ed(e,t){let n=t?.mutateFirstDiff?e[0]:{added:{},removed:{},updated:{}};return ec(n,t?.mutateFirstDiff?e.slice(1):e),n}function ec(e,t){for(let n of t){let t=el(e.removed);for(let r in n.added){let i=n.added[r];if(t&&e.removed[r]){let t=e.removed[r];delete e.removed[r],t!==i&&(e.updated[r]=[t,i])}else e.added[r]=i}let r=el(e.added);for(let i in n.updated){let o=n.updated[i][1];if(r&&e.added[i]){e.added[i]=o,delete e.updated[i],t&&delete e.removed[i];continue}let s=e.updated[i];if(s){s[1]=o,t&&delete e.removed[i];continue}e.updated[i]=[n.updated[i][0],o],t&&delete e.removed[i]}for(let t in n.removed)e.added[t]?delete e.added[t]:e.updated[t]?(e.removed[t]=e.updated[t][0],delete e.updated[t]):e.removed[t]=n.removed[t]}}class eh{constructor(e,t){this.typeName=e,this.createDefaultProperties=t.createDefaultProperties,this.validator=t.validator??{validate:e=>e},this.scope=t.scope??"document",this.ephemeralKeys=t.ephemeralKeys;const n=new Set;if(t.ephemeralKeys)for(const[e,r]of(0,i.iA)(t.ephemeralKeys))r&&n.add(e);this.ephemeralKeySet=n}typeName;createDefaultProperties;validator;ephemeralKeys;ephemeralKeySet;scope;create(e){let t={...this.createDefaultProperties(),id:e.id??this.createId()};for(let[n,r]of Object.entries(e))void 0!==r&&(t[n]=r);return t.typeName=this.typeName,t}clone(e){return{...(0,i.pN)(e),id:this.createId()}}createId(e){return this.typeName+":"+(e??(0,i.NF)())}parseId(e){if(!this.isId(e))throw Error(`ID "${e}" is not a valid ID for type "${this.typeName}"`);return e.slice(this.typeName.length+1)}isInstance(e){return e?.typeName===this.typeName}isId(e){if(!e)return!1;for(let t=0;t<this.typeName.length;t++)if(e[t]!==this.typeName[t])return!1;return":"===e[this.typeName.length]}withDefaultProperties(e){return new eh(this.typeName,{createDefaultProperties:e,validator:this.validator,scope:this.scope,ephemeralKeys:this.ephemeralKeys})}validate(e,t){return t&&this.validator.validateUsingKnownGoodVersion?this.validator.validateUsingKnownGoodVersion(t,e):this.validator.validate(e)}}function eu(e,t){return new eh(e,{createDefaultProperties:()=>({}),validator:t.validator,scope:t.scope,ephemeralKeys:t.ephemeralKeys})}function ep(e){return"object"==typeof e&&null!==e&&("eq"in e||"neq"in e||"gt"in e)}function ef(e,t){for(let[n,r]of Object.entries(e)){let e=t[n];if(ep(r)){if("eq"in r&&e!==r.eq||"neq"in r&&(e===r.neq||void 0===e)||"gt"in r&&("number"!=typeof e||e<=r.gt))return!1;continue}if("object"!=typeof e||null===e||!ef(r,e))return!1}return!0}function eg(e,t,n){let r=function e(t,n=""){let r=[];for(let[i,o]of Object.entries(t)){let t=n?`${n}\\${i}`:i;ep(o)?r.push({path:t,matcher:o}):"object"==typeof o&&null!==o&&r.push(...e(o,t))}return r}(n),i=Object.fromEntries(r.map(({path:e})=>[e,new Set]));for(let{path:n,matcher:o}of r){let r=e.index(t,n);if("eq"in o){let e=r.get().get(o.eq);if(e)for(let t of e)i[n].add(t)}else if("neq"in o){for(let[e,t]of r.get())if(e!==o.neq)for(let e of t)i[n].add(e)}else if("gt"in o){for(let[e,t]of r.get())if("number"==typeof e&&e>o.gt)for(let e of t)i[n].add(e)}if(0===i[n].size)return new Set}return function(e){if(0===e.length)return new Set;let t=e[0],n=e.slice(1),r=new Set;for(let e of t)n.every(t=>t.has(e))&&r.add(e);return r}(Object.values(i))}class em{constructor(e,t){this.recordMap=e,this.history=t}recordMap;history;indexCache=new Map;historyCache=new Map;getAllIdsForType(e){let t=new Set;for(let n of this.recordMap.values())n.typeName===e&&t.add(n.id);return t}getRecordById(e,t){let n=this.recordMap.get(t);if(n&&n.typeName===e)return n}getNestedValue(e,t){let n=e;for(let e of t){if(null==n||"object"!=typeof n)return;n=n[e]}return n}filterHistory(e){if(this.historyCache.has(e))return this.historyCache.get(e);let t=(0,o.EW)("filterHistory:"+e,(t,n)=>{if((0,o._O)(t))return this.history.get();let r=this.history.getDiffSince(n);if(r===o.c2)return this.history.get();let s={added:{},removed:{},updated:{}},a=0,l=0,d=0;for(let t of r){for(let n of(0,i.Ic)(t.added))if(n.typeName===e)if(s.removed[n.id]){let e=s.removed[n.id];delete s.removed[n.id],l--,e!==n&&(s.updated[n.id]=[e,n],d++)}else s.added[n.id]=n,a++;for(let[n,r]of(0,i.Ic)(t.updated))r.typeName===e&&(s.added[r.id]?s.added[r.id]=r:s.updated[r.id]?s.updated[r.id]=[s.updated[r.id][0],r]:(s.updated[r.id]=[n,r],d++));for(let n of(0,i.Ic)(t.removed))n.typeName===e&&(s.added[n.id]?(delete s.added[n.id],a--):(s.updated[n.id]?(s.removed[n.id]=s.updated[n.id][0],delete s.updated[n.id],d--):s.removed[n.id]=n,l++))}return a||l||d?(0,o._D)(this.history.get(),s):t},{historyLength:100});return this.historyCache.set(e,t),t}index(e,t){let n=e+":"+t;if(this.indexCache.has(n))return this.indexCache.get(n);let r=this.__uncached_createIndex(e,t);return this.indexCache.set(n,r),r}__uncached_createIndex(e,t){let n=this.filterHistory(e),r=t.split("\\"),s=r.length>1?e=>this.getNestedValue(e,r):e=>e[t],a=()=>{n.get();let t=new Map;for(let n of this.recordMap.values())if(n.typeName===e){let e=s(n);void 0!==e&&(t.has(e)||t.set(e,new Set),t.get(e).add(n.id))}return t};return(0,o.EW)("index:"+e+":"+t,(t,r)=>{let l,d;if((0,o._O)(t))return a();let c=n.getDiffSince(r);if(c===o.c2)return a();let h=new Map,u=(e,n)=>{let r=h.get(e);r||(r=new X(t.get(e)??new Set)),r.add(n),h.set(e,r)},p=(e,n)=>{let r=h.get(e);r||(r=new X(t.get(e)??new Set)),r.remove(n),h.set(e,r)};for(let t of c){for(let n of(0,i.Ic)(t.added))if(n.typeName===e){let e=s(n);void 0!==e&&u(e,n.id)}for(let[n,r]of(0,i.Ic)(t.updated))if(r.typeName===e){let e=s(n),t=s(r);e!==t&&(void 0!==e&&p(e,r.id),void 0!==t&&u(t,r.id))}for(let n of(0,i.Ic)(t.removed))if(n.typeName===e){let e=s(n);void 0!==e&&p(e,n.id)}}for(let[e,n]of h){let r=n.get();r&&(l||(l=new Map(t)),d||(d=new Map),0===r.value.size?l.delete(e):l.set(e,r.value),d.set(e,r.diff))}return l&&d?(0,o._D)(l,d):t},{historyLength:100})}record(e,t=()=>({}),n="record:"+e+(t?":"+t.toString():"")){let r=this.ids(e,t,n);return(0,o.EW)(n,()=>{for(let e of r.get())return this.recordMap.get(e)})}records(e,t=()=>({}),n="records:"+e+(t?":"+t.toString():"")){let r=this.ids(e,t,"ids:"+n);return(0,o.EW)(n,()=>Array.from(r.get(),e=>this.recordMap.get(e)),{isEqual:i.vq})}ids(e,t=()=>({}),n="ids:"+e+(t?":"+t.toString():"")){let r=this.filterHistory(e),s=()=>{r.get();let n=t();return 0===Object.keys(n).length?this.getAllIdsForType(e):eg(this,e,n)},a=e=>{let t=s(),n=function(e,t){let n={};for(let r of t)e.has(r)||(n.added??=new Set,n.added.add(r));for(let r of e)t.has(r)||(n.removed??=new Set,n.removed.add(r));return n.added||n.removed?n:void 0}(e,t);return n?(0,o._D)(t,n):e},l=(0,o.EW)("ids_query:"+n,t,{isEqual:i.n4});return(0,o.EW)("query:"+n,(t,n)=>{let d=l.get();if((0,o._O)(t))return s();if(n<l.lastChangedEpoch)return a(t);let c=r.getDiffSince(n);if(c===o.c2)return a(t);let h=new X(t);for(let t of c){for(let n of(0,i.Ic)(t.added))n.typeName===e&&ef(d,n)&&h.add(n.id);for(let[n,r]of(0,i.Ic)(t.updated))r.typeName===e&&(ef(d,r)?h.add(r.id):h.remove(r.id));for(let n of(0,i.Ic)(t.removed))n.typeName===e&&h.remove(n.id)}let u=h.get();return u?(0,o._D)(u.value,u.diff):t},{historyLength:50})}exec(e,t){let n=eg(this,e,t);return 0===n.size?o.Ml:Array.from(n,e=>this.recordMap.get(e))}}class ey{constructor(e){this.store=e}store;_beforeCreateHandlers={};_afterCreateHandlers={};_beforeChangeHandlers={};_afterChangeHandlers={};_beforeDeleteHandlers={};_afterDeleteHandlers={};_operationCompleteHandlers=[];_isEnabled=!0;isEnabled(){return this._isEnabled}setIsEnabled(e){this._isEnabled=e}handleBeforeCreate(e,t){if(!this._isEnabled)return e;let n=this._beforeCreateHandlers[e.typeName];if(n){let r=e;for(let e of n)r=e(r,t);return r}return e}handleAfterCreate(e,t){if(!this._isEnabled)return;let n=this._afterCreateHandlers[e.typeName];if(n)for(let r of n)r(e,t)}handleBeforeChange(e,t,n){if(!this._isEnabled)return t;let r=this._beforeChangeHandlers[t.typeName];if(r){let i=t;for(let t of r)i=t(e,i,n);return i}return t}handleAfterChange(e,t,n){if(!this._isEnabled)return;let r=this._afterChangeHandlers[t.typeName];if(r)for(let i of r)i(e,t,n)}handleBeforeDelete(e,t){if(!this._isEnabled)return!0;let n=this._beforeDeleteHandlers[e.typeName];if(n){for(let r of n)if(!1===r(e,t))return!1}return!0}handleAfterDelete(e,t){if(!this._isEnabled)return;let n=this._afterDeleteHandlers[e.typeName];if(n)for(let r of n)r(e,t)}handleOperationComplete(e){if(this._isEnabled)for(let t of this._operationCompleteHandlers)t(e)}register(e){let t=[];for(let[n,r]of Object.entries(e))r?.beforeCreate&&t.push(this.registerBeforeCreateHandler(n,r.beforeCreate)),r?.afterCreate&&t.push(this.registerAfterCreateHandler(n,r.afterCreate)),r?.beforeChange&&t.push(this.registerBeforeChangeHandler(n,r.beforeChange)),r?.afterChange&&t.push(this.registerAfterChangeHandler(n,r.afterChange)),r?.beforeDelete&&t.push(this.registerBeforeDeleteHandler(n,r.beforeDelete)),r?.afterDelete&&t.push(this.registerAfterDeleteHandler(n,r.afterDelete));return()=>{for(let e of t)e()}}registerBeforeCreateHandler(e,t){return this._beforeCreateHandlers[e]||(this._beforeCreateHandlers[e]=[]),this._beforeCreateHandlers[e].push(t),()=>eb(this._beforeCreateHandlers[e],t)}registerAfterCreateHandler(e,t){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(t),()=>eb(this._afterCreateHandlers[e],t)}registerBeforeChangeHandler(e,t){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(t),()=>eb(this._beforeChangeHandlers[e],t)}registerAfterChangeHandler(e,t){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(t),()=>eb(this._afterChangeHandlers[e],t)}registerBeforeDeleteHandler(e,t){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(t),()=>eb(this._beforeDeleteHandlers[e],t)}registerAfterDeleteHandler(e,t){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(t),()=>eb(this._afterDeleteHandlers[e],t)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>eb(this._operationCompleteHandlers,e)}}function eb(e,t){let n=e.indexOf(t);n>=0&&e.splice(n,1)}class ex{id;records;history=(0,o.eU)("history",0,{historyLength:1e3});query;listeners=new Set;historyAccumulator=new ew;historyReactor;cancelHistoryReactor(){}schema;props;scopedTypes;sideEffects=new ey(this);constructor(e){const{initialData:t,schema:n,id:r}=e;this.id=r??(0,i.NF)(),this.schema=n,this.props=e.props,t?this.records=new V("store",(0,i.iA)(t).map(([e,t])=>[e,q(this.schema.validateRecord(this,t,"initialize",null))])):this.records=new V("store"),this.query=new em(this.records,this.history),this.historyReactor=(0,o.Px)("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:e=>this.cancelHistoryReactor=(0,i.Uo)(e)}),this.scopedTypes={document:new Set((0,i.Ic)(this.schema.types).filter(e=>"document"===e.scope).map(e=>e.typeName)),session:new Set((0,i.Ic)(this.schema.types).filter(e=>"session"===e.scope).map(e=>e.typeName)),presence:new Set((0,i.Ic)(this.schema.types).filter(e=>"presence"===e.scope).map(e=>e.typeName))}}_flushHistory(){if(this.historyAccumulator.hasChanges())for(let{changes:e,source:t}of this.historyAccumulator.flush()){let n=null,r=null,i=null;for(let{onHistory:o,filters:s}of this.listeners)if("all"===s.source||s.source===t)if("all"!==s.scope)if("document"===s.scope){if(!(r??=this.filterChangesByScope(e,"document")))continue;o({changes:r,source:t})}else if("session"===s.scope){if(!(n??=this.filterChangesByScope(e,"session")))continue;o({changes:n,source:t})}else{if(!(i??=this.filterChangesByScope(e,"presence")))continue;o({changes:i,source:t})}else o({changes:e,source:t})}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(e,t){let n={added:(0,i.J2)(e.added,(e,n)=>this.scopedTypes[t].has(n.typeName)),updated:(0,i.J2)(e.updated,(e,n)=>this.scopedTypes[t].has(n[1].typeName)),removed:(0,i.J2)(e.removed,(e,n)=>this.scopedTypes[t].has(n.typeName))};return el(n.added)||el(n.updated)||el(n.removed)?n:null}updateHistory(e){this.historyAccumulator.add({changes:e,source:this.isMergingRemoteChanges?"remote":"user"}),0===this.listeners.size&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,e)}validate(e){this.allRecords().forEach(t=>this.schema.validateRecord(this,t,e,null))}put(e,t){this.atomic(()=>{let n,r={},i={},o=!1,s=this.isMergingRemoteChanges?"remote":"user";for(let a=0,l=e.length;a<l;a++){n=e[a];let l=this.records.__unsafe__getWithoutCapture(n.id);if(l){n=this.sideEffects.handleBeforeChange(l,n,s);let e=this.schema.validateRecord(this,n,t??"updateRecord",l);if(e===l)continue;n=q(e),this.records.set(n.id,n),o=!0,r[n.id]=[l,n],this.addDiffForAfterEvent(l,n)}else n=this.sideEffects.handleBeforeCreate(n,s),o=!0,i[(n=q(n=this.schema.validateRecord(this,n,t??"createRecord",null))).id]=n,this.addDiffForAfterEvent(null,n),this.records.set(n.id,n)}o&&this.updateHistory({added:i,updated:r,removed:{}})})}remove(e){this.atomic(()=>{let t=new Set(e),n=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(let r of e){let e=this.records.__unsafe__getWithoutCapture(r);e&&!1===this.sideEffects.handleBeforeDelete(e,n)&&t.delete(r)}let r=this.records.deleteMany(t);if(0===r.length)return;let i={};for(let[e,t]of r)i[e]=t,this.addDiffForAfterEvent(t,null);this.updateHistory({added:{},updated:{},removed:i})})}get(e){return this.records.get(e)}unsafeGetWithoutCapture(e){return this.records.__unsafe__getWithoutCapture(e)}serialize(e="document"){let t={};for(let[n,r]of this.records)("all"===e||this.scopedTypes[e].has(r.typeName))&&(t[n]=r);return t}getStoreSnapshot(e="document"){return{store:this.serialize(e),schema:this.schema.serialize()}}migrateSnapshot(e){let t=this.schema.migrateStoreSnapshot(e);if("error"===t.type)throw Error(`Failed to migrate snapshot: ${t.reason}`);return{store:t.value,schema:this.schema.serialize()}}loadStoreSnapshot(e){let t=this.schema.migrateStoreSnapshot(e);if("error"===t.type)throw Error(`Failed to migrate snapshot: ${t.reason}`);let n=this.sideEffects.isEnabled();try{this.sideEffects.setIsEnabled(!1),this.atomic(()=>{this.clear(),this.put(Object.values(t.value)),this.ensureStoreIsUsable()},!1)}finally{this.sideEffects.setIsEnabled(n)}}allRecords(){return Array.from(this.records.values())}clear(){this.remove(Array.from(this.records.keys()))}update(e,t){let n=this.unsafeGetWithoutCapture(e);n?this.put([t(n)]):console.error(`Record ${e} not found. This is probably an error`)}has(e){return this.records.has(e)}listen(e,t){this._flushHistory();let n={onHistory:e,filters:{source:t?.source??"all",scope:t?.scope??"all"}};return this.historyReactor.scheduler.isActivelyListening||(this.historyReactor.start(),this.historyReactor.scheduler.execute()),this.listeners.add(n),()=>{this.listeners.delete(n),0===this.listeners.size&&this.historyReactor.stop()}}isMergingRemoteChanges=!1;mergeRemoteChanges(e){if(this.isMergingRemoteChanges)return e();if(this._isInAtomicOp)throw Error("Cannot merge remote changes while in atomic operation");try{this.atomic(e,!0,!0)}finally{this.ensureStoreIsUsable()}}extractingChanges(e){let t=[],n=this.historyAccumulator.addInterceptor(e=>t.push(e.changes));try{return(0,o.hL)(e),ed(t)}finally{n()}}applyDiff(e,{runCallbacks:t=!0,ignoreEphemeralKeys:n=!1}={}){this.atomic(()=>{let t=(0,i.Ic)(e.added);for(let[r,o]of(0,i.Ic)(e.updated)){let e=this.schema.getType(o.typeName);if(n&&e.ephemeralKeySet.size){let n=this.get(o.id);if(!n){t.push(o);continue}let r=null;for(let[t,s]of Object.entries(o))e.ephemeralKeySet.has(t)||Object.is(s,(0,i.g5)(n,t))||(r||(r={...n}),r[t]=s);r&&t.push(r)}else t.push(o)}let r=(0,i.w$)(e.removed);t.length&&this.put(t),r.length&&this.remove(r)},t)}createCache(e){let t=new i.l;return{get:n=>{let r=this.records.getAtom(n);if(r)return t.get(r,()=>e(n,r)).get()}}}createComputedCache(e,t,n){return this.createCache((r,i)=>{let s=n?.areRecordsEqual?(0,o.EW)(`${e}:${r}:isEqual`,()=>i.get(),{isEqual:n.areRecordsEqual}):i;return(0,o.EW)(e+":"+r,()=>t(s.get()),{isEqual:n?.areResultsEqual})})}_integrityChecker;ensureStoreIsUsable(){this.atomic(()=>{this._integrityChecker??=this.schema.createIntegrityChecker(this),this._integrityChecker?.()})}_isPossiblyCorrupted=!1;markAsPossiblyCorrupted(){this._isPossiblyCorrupted=!0}isPossiblyCorrupted(){return this._isPossiblyCorrupted}pendingAfterEvents=null;addDiffForAfterEvent(e,t){if((0,i.vA)(this.pendingAfterEvents,"must be in event operation"),e===t||(e&&t&&(0,i.vA)(e.id===t.id),!e&&!t))return;let n=(e||t).id,r=this.pendingAfterEvents.get(n);r?r.after=t:this.pendingAfterEvents.set(n,{before:e,after:t})}flushAtomicCallbacks(e){let t=0,n=e?"remote":"user";for(;this.pendingAfterEvents;){let e=this.pendingAfterEvents;if(this.pendingAfterEvents=null,this.sideEffects.isEnabled()){if(++t>100)throw Error("Maximum store update depth exceeded, bailing out");for(let{before:t,after:r}of e.values())t&&r&&t!==r&&!(0,i.n4)(t,r)?this.sideEffects.handleAfterChange(t,r,n):t&&!r?this.sideEffects.handleAfterDelete(t,n):!t&&r&&this.sideEffects.handleAfterCreate(r,n);this.pendingAfterEvents?n="user":this.sideEffects.handleOperationComplete(n)}}}_isInAtomicOp=!1;atomic(e,t=!0,n=!1){return(0,o.hL)(()=>{if(this._isInAtomicOp){this.pendingAfterEvents||(this.pendingAfterEvents=new Map);let r=this.sideEffects.isEnabled();(0,i.vA)(!n,"cannot call mergeRemoteChanges while in atomic operation");try{return r&&!t&&this.sideEffects.setIsEnabled(!1),e()}finally{this.sideEffects.setIsEnabled(r)}}this.pendingAfterEvents=new Map;let r=this.sideEffects.isEnabled();this.sideEffects.setIsEnabled(t&&r),this._isInAtomicOp=!0,n&&(this.isMergingRemoteChanges=!0);try{let t=e();return this.isMergingRemoteChanges=!1,this.flushAtomicCallbacks(n),t}finally{this.pendingAfterEvents=null,this.sideEffects.setIsEnabled(r),this._isInAtomicOp=!1,this.isMergingRemoteChanges=!1}})}addHistoryInterceptor(e){return this.historyAccumulator.addInterceptor(t=>e(t,this.isMergingRemoteChanges?"remote":"user"))}}class ew{_history=[];_interceptors=new Set;addInterceptor(e){return this._interceptors.add(e),()=>{this._interceptors.delete(e)}}add(e){for(let t of(this._history.push(e),this._interceptors))t(e)}flush(){let e=function(e){let t;if(0===e.length)return[];let n=[],r=[e[0]];for(let i=1,o=e.length;i<o;i++)t=e[i],r[0].source!==t.source&&(n.push(r),r=[]),r.push(t);return n.push(r),q(n.map(e=>({source:e[0].source,changes:1===e.length?e[0].changes:ed(e.map(e=>e.changes))})))}(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function ev(e,t,n){let r=new i.l;return{get:(i,o)=>r.get(i,()=>(i instanceof ex?i:i.store).createComputedCache(e,e=>t(i,e),n)).get(o)}}class eS{constructor(e,t){for(const n of(this.types=e,this.options=t,t.migrations??[]))(0,i.vA)(!this.migrations[n.sequenceId],`Duplicate migration sequenceId ${n.sequenceId}`),en(n),this.migrations[n.sequenceId]=n;const n=Object.values(this.migrations).flatMap(e=>e.sequence);for(const e of(this.sortedMigrations=function(e){if(0===e.length)return[];let t=new Map(e.map(e=>[e.id,e])),n=new Map,r=new Map,o=new Map;for(let t of e)r.set(t.id,0),n.set(t.id,new Set),o.set(t.id,new Set);for(let i of e){let{version:e,sequenceId:s}=ee(i.id),a=`${s}/${e-1}`;if(t.has(a)&&(n.get(a).add(i.id),r.set(i.id,r.get(i.id)+1)),i.dependsOn)for(let e of i.dependsOn)t.has(e)&&(n.get(e).add(i.id),o.get(i.id).add(e),r.set(i.id,r.get(i.id)+1))}let s=e.filter(e=>0===r.get(e.id)),a=[],l=new Set;for(;s.length>0;){let e,i=-1/0;for(let t of s){let r=0;for(let e of n.get(t.id)||[])!l.has(e)&&(r+=1,o.get(e).has(t.id)&&(r+=100));(r>i||r===i&&0>t.id.localeCompare(e?.id??""))&&(e=t,i=r)}let d=e;for(let e of(s.splice(s.indexOf(d),1),a.push(d),l.add(d.id),n.get(d.id)||[]))l.has(e)||(r.set(e,r.get(e)-1),0===r.get(e)&&s.push(t.get(e)))}if(a.length!==e.length){let t=e.filter(e=>!l.has(e.id));(0,i.vA)(!1,`Circular dependency in migrations: ${t[0].id}`)}return a}(n),this.sortedMigrations))if(e.dependsOn?.length)for(const t of e.dependsOn){const r=n.find(e=>e.id===t);(0,i.vA)(r,`Migration '${e.id}' depends on missing migration '${t}'`)}}types;options;static create(e,t){return new eS(e,t??{})}migrations={};sortedMigrations;migrationCache=new WeakMap;validateRecord(e,t,n,r){try{let e=(0,i.g5)(this.types,t.typeName);if(!e)throw Error(`Missing definition for record type ${t.typeName}`);return e.validate(t,r??void 0)}catch(i){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:e,record:t,phase:n,recordBefore:r,error:i});throw i}}getMigrationsSince(e){let t=this.migrationCache.get(e);if(t)return t;let n=function(e){if(e.schemaVersion>2||e.schemaVersion<1)return i.Q7.err("Bad schema version");if(2===e.schemaVersion)return i.Q7.ok(e);let t={schemaVersion:2,sequences:{"com.tldraw.store":e.storeVersion}};for(let[n,r]of Object.entries(e.recordVersions))if(t.sequences[`com.tldraw.${n}`]=r.version,"subTypeKey"in r)for(let[e,i]of Object.entries(r.subTypeVersions))t.sequences[`com.tldraw.${n}.${e}`]=i;return i.Q7.ok(t)}(e);if(!n.ok)return this.migrationCache.set(e,n),n;let r=n.value,o=new Set(Object.keys(r.sequences).filter(e=>this.migrations[e]));for(let e in this.migrations)void 0===r.sequences[e]&&this.migrations[e].retroactive&&o.add(e);if(0===o.size){let t=i.Q7.ok([]);return this.migrationCache.set(e,t),t}let s=new Set;for(let t of o){let n=r.sequences[t];if("number"!=typeof n&&this.migrations[t].retroactive||0===n){for(let e of this.migrations[t].sequence)s.add(e.id);continue}let o=`${t}/${n}`,a=this.migrations[t].sequence.findIndex(e=>e.id===o);if(-1===a){let t=i.Q7.err("Incompatible schema?");return this.migrationCache.set(e,t),t}for(let e of this.migrations[t].sequence.slice(a+1))s.add(e.id)}let a=i.Q7.ok(this.sortedMigrations.filter(({id:e})=>s.has(e)));return this.migrationCache.set(e,a),a}migratePersistedRecord(e,t,n="up"){let r=this.getMigrationsSince(t);if(!r.ok)return console.error("Error migrating record",r.error),{type:"error",reason:ei};let o=r.value;if(0===o.length)return{type:"success",value:e};if(!o.every(e=>"record"===e.scope))return{type:"error",reason:"down"===n?er:"target-version-too-new"};if("down"===n){if(!o.every(e=>"record"===e.scope&&e.down))return{type:"error",reason:er};o=o.slice().reverse()}e=(0,i.pN)(e);try{for(let t of o){if("store"===t.scope||"storage"===t.scope)throw Error();if(!(!t.filter||t.filter(e)))continue;let r=t[n](e);r&&(e=(0,i.pN)(r))}}catch(e){return console.error("Error migrating record",e),{type:"error",reason:ei}}return{type:"success",value:e}}migrateStorage(e){let t=e.getSchema();(0,i.vA)(t,"Schema is missing.");let n=this.getMigrationsSince(t);if(!n.ok)throw console.error("Error migrating store",n.error),Error(n.error);let r=n.value;if(0!==r.length){for(let t of(e.setSchema(this.serialize()),r))if("record"===t.scope){let n=[];for(let[r,o]of e.entries()){if(!(!t.filter||t.filter(o)))continue;let e=(0,i.pN)(o),s=t.up(e)??e;(0,i.n4)(s,o)||n.push([r,s])}for(let[t,r]of n)e.set(t,r)}else if("store"===t.scope){let n=Object.fromEntries(e.entries()),r=(0,i.pN)(n);for(let[o,s]of Object.entries(r=t.up(r)??r))s&&((0,i.n4)(s,n[o])||e.set(o,s));for(let t of Object.keys(n))r[t]||e.delete(t)}else"storage"===t.scope?t.up(e):(0,i.h6)(t);for(let[t,n]of e.entries())"document"!==this.getType(n.typeName).scope&&e.delete(t)}}migrateStoreSnapshot(e,t){let n=this.getMigrationsSince(e.schema);if(!n.ok)return console.error("Error migrating store",n.error),{type:"error",reason:ei};if(0===n.value.length)return{type:"success",value:e.store};let r=Object.assign(new Map((0,i.iA)(e.store).map(q)),{getSchema:()=>e.schema,setSchema:e=>{}});try{if(this.migrateStorage(r),!t?.mutateInputStore)return{type:"success",value:Object.fromEntries(r.entries())};for(let[t,n]of r.entries())e.store[t]=n;for(let t of Object.keys(e.store))r.has(t)||delete e.store[t];return{type:"success",value:e.store}}catch(e){return console.error("Error migrating store",e),{type:"error",reason:ei}}}createIntegrityChecker(e){return this.options.createIntegrityChecker?.(e)??void 0}serialize(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e,sequence:t})=>[e,t.length?ee(t.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e})=>[e,0]))}}getType(e){let t=(0,i.g5)(this.types,e);return(0,i.vA)(t,"record type does not exist"),t}}(0,i.lF)("@tldraw/store","5.3.2","esm")},54939:(e,t,n)=>{"use strict";n.d(t,{V:()=>s});var r=n(59830),i=n(93286),o=n(46195);class s{constructor(e,t,n,r,i,o){this.a=e,this.b=t,this.c=n,this.d=r,this.e=i,this.f=o}a=1;b=0;c=0;d=1;e=0;f=0;equals(e){return this===e||this.a===e.a&&this.b===e.b&&this.c===e.c&&this.d===e.d&&this.e===e.e&&this.f===e.f}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}multiply(e){let{a:t,b:n,c:r,d:i,e:o,f:s}=this;return this.a=t*e.a+r*e.b,this.c=t*e.c+r*e.d,this.e=t*e.e+r*e.f+o,this.b=n*e.a+i*e.b,this.d=n*e.c+i*e.d,this.f=n*e.e+i*e.f+s,this}rotate(e,t,n){return 0===e?this:void 0===t?this.multiply(s.Rotate(e)):this.translate(t,n).multiply(s.Rotate(e)).translate(-t,-n)}translate(e,t){return this.multiply(s.Translate(e,t))}scale(e,t){return this.multiply(s.Scale(e,t))}invert(){let{a:e,b:t,c:n,d:r,e:i,f:o}=this,s=e*r-t*n;return this.a=r/s,this.b=-(t/s),this.c=-(n/s),this.d=e/s,this.e=-((r*i-n*o)/s),this.f=(t*i-e*o)/s,this}applyToPoint(e){return s.applyToPoint(this,e)}applyToPoints(e){return s.applyToPoints(this,e)}rotation(){return s.Rotation(this)}point(){return s.Point(this)}decomposed(){return s.Decompose(this)}toCssString(){return s.toCssString(this)}setTo(e){return Object.assign(this,e),this}decompose(){return s.Decompose(this)}clone(){return new s(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new s(1,0,0,1,0,0)}static Translate(e,t){return new s(1,0,0,1,e,t)}static Rotate(e,t,n){if(0===e)return s.Identity();let r=Math.cos(e),i=Math.sin(e),o=new s(r,i,-i,r,0,0);return void 0===t?o:s.Compose(s.Translate(t,n),o,s.Translate(-t,-n))}static Scale(e,t,n,r){let i=new s(e,0,0,t,0,0);return void 0===n?i:s.Translate(n,r).multiply(i).translate(-n,-r)}static Multiply(e,t){return{a:e.a*t.a+e.c*t.b,c:e.a*t.c+e.c*t.d,e:e.a*t.e+e.c*t.f+e.e,b:e.b*t.a+e.d*t.b,d:e.b*t.c+e.d*t.d,f:e.b*t.e+e.d*t.f+e.f}}static Inverse(e){let t=e.a*e.d-e.b*e.c;return{a:e.d/t,b:-(e.b/t),c:-(e.c/t),d:e.a/t,e:-((e.d*e.e-e.c*e.f)/t),f:(e.b*e.e-e.a*e.f)/t}}static Absolute(e){let t=e.a*e.d-e.b*e.c;return{a:e.d/t,b:-(e.b/t),c:-(e.c/t),d:e.a/t,e:(e.d*e.e-e.c*e.f)/t,f:-((e.b*e.e-e.a*e.f)/t)}}static Compose(...e){let t=s.Identity();for(let n=0,r=e.length;n<r;n++)t.multiply(e[n]);return t}static Point(e){return new o.l(e.e,e.f)}static Rotation(e){let t;if(0!==e.a||0!==e.c){let n=(e.a*e.a+e.c*e.c)**.5;t=Math.acos(e.a/n)*(e.c>0?-1:1)}else if(0!==e.b||0!==e.d){let n=(e.b*e.b+e.d*e.d)**.5;t=i.sK+Math.acos(e.b/n)*(e.d>0?-1:1)}else t=0;return(0,i.yD)(t)}static Decompose(e){let t,n,r;if(0!==e.a||0!==e.c){let i=(e.a*e.a+e.c*e.c)**.5;t=i,n=(e.a*e.d-e.b*e.c)/i,r=Math.acos(e.a/i)*(e.c>0?-1:1)}else if(0!==e.b||0!==e.d){let o=(e.b*e.b+e.d*e.d)**.5;t=(e.a*e.d-e.b*e.c)/o,n=o,r=i.sK+Math.acos(e.b/o)*(e.d>0?-1:1)}else t=0,n=0,r=0;return{x:e.e,y:e.f,scaleX:t,scaleY:n,rotation:(0,i.yD)(r)}}static Smooth(e,t=1e10){return e.a=Math.round(e.a*t)/t,e.b=Math.round(e.b*t)/t,e.c=Math.round(e.c*t)/t,e.d=Math.round(e.d*t)/t,e.e=Math.round(e.e*t)/t,e.f=Math.round(e.f*t)/t,e}static toCssString(e){return`matrix(${(0,i.WM)(e.a)}, ${(0,i.WM)(e.b)}, ${(0,i.WM)(e.c)}, ${(0,i.WM)(e.d)}, ${(0,i.WM)(e.e)}, ${(0,i.WM)(e.f)})`}static applyToPoint(e,t){return new o.l(e.a*t.x+e.c*t.y+e.e,e.b*t.x+e.d*t.y+e.f,t.z)}static applyToXY(e,t,n){return[e.a*t+e.c*n+e.e,e.b*t+e.d*n+e.f]}static applyToPoints(e,t){return t.map(t=>new o.l(e.a*t.x+e.c*t.y+e.e,e.b*t.x+e.d*t.y+e.f,t.z))}static applyToBounds(e,t){return new r.az(e.e+t.minX,e.f+t.minY,t.width,t.height)}static From(e){return new s(e.a,e.b,e.c,e.d,e.e,e.f)}static Cast(e){return e instanceof s?e:s.From(e)}}},55667:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(46195),i=n(27164);class o extends i.vq{_start;_end;_dx;_dy;_len2;constructor(e){super({...e,isClosed:!1,isFilled:!1});const{start:t,end:n}=e;this._start=t,this._end=n,this._dx=n.x-t.x,this._dy=n.y-t.y,this._len2=this._dx*this._dx+this._dy*this._dy}getLength(){return Math.sqrt(this._len2)}getVertices(){return[this._start,this._end]}nearestPoint(e){let{_start:t,_end:n,_dx:i,_dy:o,_len2:s}=this;if(0===s)return t;let a=((e.x-t.x)*i+(e.y-t.y)*o)/s;return a<=0?t:a>=1?n:new r.l(t.x+i*a,t.y+o*a)}distanceToPoint(e,t=!1){let n,i,{_start:o,_end:s,_dx:a,_dy:l,_len2:d}=this;if(0===d)return r.l.Dist(e,o);let c=((e.x-o.x)*a+(e.y-o.y)*l)/d;c<=0?(n=o.x,i=o.y):c>=1?(n=s.x,i=s.y):(n=o.x+a*c,i=o.y+l*c);let h=e.x-n,u=e.y-i;return Math.sqrt(h*h+u*u)}getSvgPathData(e=!0){let{_start:t,_end:n}=this;return`${e?`M${t.toFixed()}`:""} L${n.toFixed()}`}}},55897:(e,t,n)=>{"use strict";n.d(t,{hO:()=>d,sG:()=>l});var r=n(12115),i=n(47650),o=n(42442),s=n(95155),a=Object.defineProperty,l=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"].reduce((e,t)=>{let n=(0,o.TL)(`Primitive.${t}`),i=r.forwardRef((e,r)=>{let{asChild:i,...o}=e;return"u">typeof window&&(window[Symbol.for("radix-ui")]=!0),(0,s.jsx)(i?n:t,{...o,ref:r})});return i.displayName=`Primitive.${t}`,{...e,[t]:i}},{});function d(e,t){e&&i.flushSync(()=>e.dispatchEvent(t))}a(d,"name",{value:"dispatchDiscreteCustomEvent",configurable:!0})},58347:(e,t,n)=>{"use strict";n.d(t,{Z:()=>r});let r={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>e*(2-e),easeInOutQuad:e=>e<.5?2*e*e:-1+(4-2*e)*e,easeInCubic:e=>e*e*e,easeOutCubic:e=>--e*e*e+1,easeInOutCubic:e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1,easeInQuart:e=>e*e*e*e,easeOutQuart:e=>1- --e*e*e*e,easeInOutQuart:e=>e<.5?8*e*e*e*e:1-8*--e*e*e*e,easeInQuint:e=>e*e*e*e*e,easeOutQuint:e=>1+--e*e*e*e*e,easeInOutQuint:e=>e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e,easeInSine:e=>1-Math.cos(e*Math.PI/2),easeOutSine:e=>Math.sin(e*Math.PI/2),easeInOutSine:e=>-(Math.cos(Math.PI*e)-1)/2,easeInExpo:e=>e<=0?0:Math.pow(2,10*e-10),easeOutExpo:e=>e>=1?1:1-Math.pow(2,-10*e),easeInOutExpo:e=>e<=0?0:e>=1?1:e<.5?Math.pow(2,20*e-10)/2:(2-Math.pow(2,-20*e+10))/2}},58929:(e,t,n)=>{"use strict";n.d(t,{N:()=>f});var r=n(83102),i=n(24167),o=n(59830),s=n(54939),a=n(93286),l=n(46195),d=Object.defineProperty,c=Object.getOwnPropertyDescriptor,h=(e,t,n,r)=>{for(var i,o=r>1?void 0:r?c(t,n):t,s=e.length-1;s>=0;s--)(i=e[s])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&d(t,n,o),o};let u=e=>Math.round(1e8*e)/1e8;function p(e,t,n,r,i){let o=e.filter(e=>("forward"===r?e.startNode.id===t:e.endNode.id===t)&&u(e.length)===u(n)&&(0,a.$C)(e.breadthIntersection[0],e.breadthIntersection[1],i[0],i[1]));if(0===o.length)return[];let s=new Set;return o.forEach(t=>{let l="forward"===r?t.endNode.id:t.startNode.id;if(!s.has(l)){s.add(l);let d=p(e,l,n,r,(0,a.$C)(t.breadthIntersection[0],t.breadthIntersection[1],i[0],i[1]));o.push(...d)}}),o}class f{constructor(e){this.manager=e,this.editor=e.editor}manager;editor;getSnapPointsCache(){let{editor:e}=this;return e.store.createComputedCache("snapPoints",t=>{let n=e.getShapePageTransform(t.id);if(!n)return;let r=e.getShapeUtil(t).getBoundsSnapGeometry(t).points??e.getShapeGeometry(t).bounds.cornersAndCenter;if(n&&r)return r.map((e,r)=>{let{x:i,y:o}=s.V.applyToPoint(n,e);return{x:i,y:o,id:`${t.id}:${r}`}})})}getSnapPoints(e){return this.getSnapPointsCache().get(e)??[]}getSnappablePoints(){let e=this.getSnapPointsCache(),t=this.manager.getSnappableShapes(),n=[];for(let r of t){let t=e.get(r);t&&n.push(...t)}return n}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),e=>({id:e,pageBounds:(0,i.Z1)(this.editor.getShapePageBounds(e))}))}getVisibleGaps(){let e,t,n=[],r=[],i=this.getSnappableGapNodes().sort((e,t)=>e.pageBounds.minX-t.pageBounds.minX);for(let r=0;r<i.length;r++){e=i[r];for(let o=r+1;o<i.length;o++)t=i[o],e.pageBounds.maxX<t.pageBounds.minX&&(0,a.g6)(e.pageBounds.minY,e.pageBounds.maxY,t.pageBounds.minY,t.pageBounds.maxY)&&n.push({startNode:e,endNode:t,startEdge:[new l.l(e.pageBounds.maxX,e.pageBounds.minY),new l.l(e.pageBounds.maxX,e.pageBounds.maxY)],endEdge:[new l.l(t.pageBounds.minX,t.pageBounds.minY),new l.l(t.pageBounds.minX,t.pageBounds.maxY)],length:t.pageBounds.minX-e.pageBounds.maxX,breadthIntersection:(0,a.$C)(e.pageBounds.minY,e.pageBounds.maxY,t.pageBounds.minY,t.pageBounds.maxY)})}let o=i.sort((e,t)=>e.pageBounds.minY-t.pageBounds.minY);for(let n=0;n<o.length;n++){e=o[n];for(let i=n+1;i<o.length;i++)t=o[i],e.pageBounds.maxY<t.pageBounds.minY&&(0,a.g6)(e.pageBounds.minX,e.pageBounds.maxX,t.pageBounds.minX,t.pageBounds.maxX)&&r.push({startNode:e,endNode:t,startEdge:[new l.l(e.pageBounds.minX,e.pageBounds.maxY),new l.l(e.pageBounds.maxX,e.pageBounds.maxY)],endEdge:[new l.l(t.pageBounds.minX,t.pageBounds.minY),new l.l(t.pageBounds.maxX,t.pageBounds.minY)],length:t.pageBounds.minY-e.pageBounds.maxY,breadthIntersection:(0,a.$C)(e.pageBounds.minX,e.pageBounds.maxX,t.pageBounds.minX,t.pageBounds.maxX)})}return{horizontal:n,vertical:r}}snapTranslateShapes({lockedAxis:e,initialSelectionPageBounds:t,initialSelectionSnapPoints:n,dragDelta:r}){let i=this.manager.getSnapThreshold(),o=this.getSnappablePoints(),s=t.clone().translate(r),a=n.map(({x:e,y:t},n)=>({id:"selection:"+n,x:e+r.x,y:t+r.y})),d=[],c=[],h=new l.l(i,i);this.collectPointSnaps({minOffset:h,nearestSnapsX:d,nearestSnapsY:c,otherNodeSnapPoints:o,selectionSnapPoints:a}),this.collectGapSnaps({selectionPageBounds:s,nearestSnapsX:d,nearestSnapsY:c,minOffset:h});let u=new l.l("x"===e?0:d[0]?.nudge??0,"y"===e?0:c[0]?.nudge??0);h.x=0,h.y=0,d.length=0,c.length=0,a.forEach(e=>{e.x+=u.x,e.y+=u.y}),s.translate(u),this.collectPointSnaps({minOffset:h,nearestSnapsX:d,nearestSnapsY:c,otherNodeSnapPoints:o,selectionSnapPoints:a}),this.collectGapSnaps({selectionPageBounds:s,nearestSnapsX:d,nearestSnapsY:c,minOffset:h});let p=this.getPointSnapLines({nearestSnapsX:d,nearestSnapsY:c}),f=this.getGapSnapLines({selectionPageBounds:s,nearestSnapsX:d,nearestSnapsY:c});return this.manager.setIndicators([...f,...p]),{nudge:u}}snapResizeShapes({initialSelectionPageBounds:e,dragDelta:t,handle:n,isAspectRatioLocked:r,isResizingFromCenter:i}){let s=this.manager.getSnapThreshold(),{box:a,scaleX:d,scaleY:c}=o.az.Resize(e,n,i?2*t.x:t.x,i?2*t.y:t.y,r),h=n;d<0&&(h=(0,o.mB)(h)),c<0&&(h=(0,o.tU)(h)),i&&(a.center=e.center);let u="top"===h||"bottom"===h,p="left"===h||"right"===h,f=g(h,a),m=this.getSnappablePoints(),y=[],b=[],x=new l.l(s,s);this.collectPointSnaps({minOffset:x,nearestSnapsX:y,nearestSnapsY:b,otherNodeSnapPoints:m,selectionSnapPoints:f});let w=new l.l(u?0:y[0]?.nudge??0,p?0:b[0]?.nudge??0);if(r&&(0,o.UB)(h)&&0!==w.len()){let t=y.length&&b.length?Math.abs(w.x)<Math.abs(w.y)?"x":"y":y.length?"x":"y",n=e.aspectRatio;"x"===t?(b.length=0,w.y=w.x/n,("bottom_left"===h||"top_right"===h)&&(w.y=-w.y)):(y.length=0,w.x=w.y*n,("bottom_left"===h||"top_right"===h)&&(w.x=-w.x))}let v=l.l.Add(t,w),{box:S}=o.az.Resize(e,n,i?2*v.x:v.x,i?2*v.y:v.y,r);i&&(S.center=e.center);let C=g("any",S);y.length=0,b.length=0,x.x=0,x.y=0,this.collectPointSnaps({minOffset:x,nearestSnapsX:y,nearestSnapsY:b,otherNodeSnapPoints:m,selectionSnapPoints:C});let k=this.getPointSnapLines({nearestSnapsX:y,nearestSnapsY:b});return this.manager.setIndicators([...k]),{nudge:w}}collectPointSnaps({selectionSnapPoints:e,otherNodeSnapPoints:t,minOffset:n,nearestSnapsX:r,nearestSnapsY:i}){for(let o of e)for(let e of t){let t=l.l.Sub(o,e),s=Math.abs(t.x),a=Math.abs(t.y);u(s)<=u(n.x)&&(u(s)<u(n.x)&&(r.length=0),r.push({type:"points",points:{thisPoint:o,otherPoint:e},nudge:e.x-o.x}),n.x=s),u(a)<=u(n.y)&&(u(a)<u(n.y)&&(i.length=0),i.push({type:"points",points:{thisPoint:o,otherPoint:e},nudge:e.y-o.y}),n.y=a)}}collectGapSnaps({selectionPageBounds:e,minOffset:t,nearestSnapsX:n,nearestSnapsY:r}){let{horizontal:i,vertical:o}=this.getVisibleGaps();for(let r of i){if(!(0,a.g6)(r.breadthIntersection[0],r.breadthIntersection[1],e.minY,e.maxY))continue;let i=r.startEdge[0].x+r.length/2-e.center.x;if(r.length>e.width&&u(Math.abs(i))<=u(t.x)){u(Math.abs(i))<u(t.x)&&(n.length=0),t.x=Math.abs(i);let e={type:"gap_center",gap:r,nudge:i},o=n.find(({type:e})=>"gap_center"===e),s=o&&(0,a.$C)(r.breadthIntersection[0],r.breadthIntersection[1],o.gap.breadthIntersection[0],o.gap.breadthIntersection[1]);o&&o.gap.length>r.length&&s?n[n.indexOf(o)]=e:o&&s||n.push(e)}let o=r.startNode.pageBounds.minX-r.length-e.maxX;u(Math.abs(o))<=u(t.x)&&(u(Math.abs(o))<u(t.x)&&(n.length=0),t.x=Math.abs(o),n.push({type:"gap_duplicate",gap:r,protrusionDirection:"left",nudge:o}));let s=r.endNode.pageBounds.maxX+r.length-e.minX;u(Math.abs(s))<=u(t.x)&&(u(Math.abs(s))<u(t.x)&&(n.length=0),t.x=Math.abs(s),n.push({type:"gap_duplicate",gap:r,protrusionDirection:"right",nudge:s}))}for(let n of o){if(!(0,a.g6)(n.breadthIntersection[0],n.breadthIntersection[1],e.minX,e.maxX))continue;let i=n.startEdge[0].y+n.length/2-e.center.y;if(n.length>e.height&&u(Math.abs(i))<=u(t.y)){u(Math.abs(i))<u(t.y)&&(r.length=0),t.y=Math.abs(i);let e={type:"gap_center",gap:n,nudge:i},o=r.find(({type:e})=>"gap_center"===e),s=o&&(0,a.g6)(o.gap.breadthIntersection[0],o.gap.breadthIntersection[1],n.breadthIntersection[0],n.breadthIntersection[1]);o&&o.gap.length>n.length&&s?r[r.indexOf(o)]=e:o&&s||r.push(e);continue}let o=n.startNode.pageBounds.minY-n.length-e.maxY;u(Math.abs(o))<=u(t.y)&&(u(Math.abs(o))<u(t.y)&&(r.length=0),t.y=Math.abs(o),r.push({type:"gap_duplicate",gap:n,protrusionDirection:"top",nudge:o}));let s=n.endNode.pageBounds.maxY+n.length-e.minY;u(Math.abs(s))<=u(t.y)&&(u(Math.abs(s))<u(t.y)&&(r.length=0),t.y=Math.abs(s),r.push({type:"gap_duplicate",gap:n,protrusionDirection:"bottom",nudge:s}))}}getPointSnapLines({nearestSnapsX:e,nearestSnapsY:t}){let n={},r={};if(e.length>0){for(let t of e)if("points"===t.type){let e=u(t.points.otherPoint.x);n[e]||(n[e]=[]),n[e].push(t.points)}}if(t.length>0){for(let e of t)if("points"===e.type){let t=u(e.points.otherPoint.y);r[t]||(r[t]=[]),r[t].push(e.points)}}return Object.values(n).concat(Object.values(r)).map(e=>({id:(0,i.NF)(),type:"points",points:(0,i.Qq)(e.map(e=>l.l.From(e.otherPoint)).concat(e.map(e=>l.l.From(e.thisPoint))),(e,t)=>e.equals(t))}))}getGapSnapLines({selectionPageBounds:e,nearestSnapsX:t,nearestSnapsY:n}){let{vertical:r,horizontal:o}=this.getVisibleGaps(),s={top:e.sides[0],right:e.sides[1],bottom:[e.corners[3],e.corners[2]],left:[e.corners[0],e.corners[3]]},l=[];if(t.length>0)for(let n of t){if("points"===n.type)continue;let{gap:{breadthIntersection:t,startEdge:r,startNode:d,endNode:c,length:h,endEdge:u}}=n;switch(n.type){case"gap_center":{let n=(h-e.width)/2,f=(0,a.$C)(t[0],t[1],e.minY,e.maxY);l.push({type:"gaps",direction:"horizontal",id:(0,i.NF)(),gaps:[...p(o,d.id,n,"backward",f),{startEdge:r,endEdge:s.left},{startEdge:s.right,endEdge:u},...p(o,c.id,n,"forward",f)]});break}case"gap_duplicate":{let f=(0,a.$C)(t[0],t[1],e.minY,e.maxY);l.push({type:"gaps",direction:"horizontal",id:(0,i.NF)(),gaps:"left"===n.protrusionDirection?[{startEdge:s.right,endEdge:r.map(e=>e.clone().addXY(-d.pageBounds.width,0))},{startEdge:r,endEdge:u},...p(o,c.id,h,"forward",f)]:[...p(o,d.id,h,"backward",f),{startEdge:r,endEdge:u},{startEdge:u.map(e=>e.clone().addXY(n.gap.endNode.pageBounds.width,0)),endEdge:s.left}]})}}}if(n.length>0)for(let t of n){if("points"===t.type)continue;let{gap:{breadthIntersection:n,startEdge:o,startNode:d,endNode:c,length:h,endEdge:u}}=t;switch(t.type){case"gap_center":{let c=(h-e.height)/2,f=(0,a.$C)(n[0],n[1],e.minX,e.maxX);l.push({type:"gaps",direction:"vertical",id:(0,i.NF)(),gaps:[...p(r,d.id,c,"backward",f),{startEdge:o,endEdge:s.top},{startEdge:s.bottom,endEdge:u},...p(r,t.gap.endNode.id,c,"forward",f)]});break}case"gap_duplicate":{let f=(0,a.$C)(n[0],n[1],e.minX,e.maxX);l.push({type:"gaps",direction:"vertical",id:(0,i.NF)(),gaps:"top"===t.protrusionDirection?[{startEdge:s.bottom,endEdge:o.map(e=>e.clone().addXY(0,-d.pageBounds.height))},{startEdge:o,endEdge:u},...p(r,c.id,h,"forward",f)]:[...p(r,d.id,h,"backward",f),{startEdge:o,endEdge:u},{startEdge:u.map(e=>e.clone().addXY(0,c.pageBounds.height)),endEdge:s.top}]})}}}l.sort((e,t)=>t.gaps.length-e.gaps.length);for(let e=l.length-1;e>0;e--){let t=l[e];for(let n=e-1;n>=0;n--){let r=l[n];if(r.direction===t.direction&&t.gaps.every(e=>r.gaps.some(t=>u(e.startEdge[0].x)===u(t.startEdge[0].x)&&u(e.startEdge[0].y)===u(t.startEdge[0].y)&&u(e.startEdge[1].x)===u(t.startEdge[1].x)&&u(e.startEdge[1].y)===u(t.startEdge[1].y))&&r.gaps.some(t=>u(e.endEdge[0].x)===u(t.endEdge[0].x)&&u(e.endEdge[0].y)===u(t.endEdge[0].y)&&u(e.endEdge[1].x)===u(t.endEdge[1].x)&&u(e.endEdge[1].y)===u(t.endEdge[1].y)))){l.splice(e,1);break}}}return l}}function g(e,t){let{minX:n,maxX:r,minY:i,maxY:o}=t,s=[];switch(e){case"top":case"left":case"top_left":case"any":s.push({id:"top_left",handle:"top_left",x:n,y:i})}switch(e){case"top":case"right":case"top_right":case"any":s.push({id:"top_right",handle:"top_right",x:r,y:i})}switch(e){case"bottom":case"right":case"bottom_right":case"any":s.push({id:"bottom_right",handle:"bottom_right",x:r,y:o})}switch(e){case"bottom":case"left":case"bottom_left":case"any":s.push({id:"bottom_left",handle:"bottom_left",x:n,y:o})}return s}h([r.EW],f.prototype,"getSnapPointsCache",1),h([r.EW],f.prototype,"getSnappablePoints",1),h([r.EW],f.prototype,"getSnappableGapNodes",1),h([r.EW],f.prototype,"getVisibleGaps",1)},59466:(e,t,n)=>{"use strict";n.d(t,{Jr:()=>m,Os:()=>h,WK:()=>y,e6:()=>g});var r=n(83102),i=n(81467),o=n(24167),s=n(22690),a=n(13982),l=n(16038);let d="TLDRAW_TAB_ID_v2",c=globalThis.window,h=c?c[d]??(0,o._9)(d)??"TLDRAW_INSTANCE_STATE_V1_"+(0,o.NF)():"<error>";c&&(c[d]=h,c&&(["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes((0,l.CM)().navigator.platform)||a.Y.isDarwin&&"ontouchend"in(0,l.jL)())?(0,o.dQ)(d,h):(0,o.ZJ)(d)),void 0!==c&&(0,l.CM)().addEventListener("beforeunload",()=>{(0,o.dQ)(d,h)});let u={Initial:0},p=Math.max(...Object.values(u)),f=s.T.object({version:s.T.number,currentPageId:i.ny.optional(),isFocusMode:s.T.boolean.optional(),exportBackground:s.T.boolean.optional(),isDebugMode:s.T.boolean.optional(),isToolLocked:s.T.boolean.optional(),isGridMode:s.T.boolean.optional(),pageStates:s.T.arrayOf(s.T.object({pageId:i.ny,camera:s.T.object({x:s.T.number,y:s.T.number,z:s.T.number}).optional(),selectedShapeIds:s.T.arrayOf(i.zo).optional(),focusedGroupId:i.zo.nullable().optional()})).optional()});function g(e){let t=e.query.ids("page");return(0,r.EW)("sessionStateSnapshot",()=>{let n=e.get(i.O9);if(!n)return null;let r=[...t.get()];return{version:p,currentPageId:n.currentPageId,exportBackground:n.exportBackground,isFocusMode:n.isFocusMode,isDebugMode:n.isDebugMode,isToolLocked:n.isToolLocked,isGridMode:n.isGridMode,pageStates:r.map(t=>{let n=e.get(i.jA.createId(t)),r=e.get(i.Xu.createId(t));return{pageId:t,camera:{x:r?.x??0,y:r?.y??0,z:r?.z??1},selectedShapeIds:n?.selectedShapeIds??[],focusedGroupId:n?.focusedGroupId??null}})}},{isEqual:o.n4})}function m(e,t,n){let r=function(e){if(!e||"object"!=typeof e)return console.warn("Invalid instance state"),null;if(!("version"in e)||"number"!=typeof e.version)return console.warn("No version in instance state"),null;if(e.version!==p){var t;(t=e=(0,o.pN)(e)).version,u.Initial,t.version=p}try{return f.validate(e)}catch(e){return console.warn(e),null}}(t);if(!r)return;let s=e.get(i.O9),a=(0,i.Pu)(s),l=n?.forceOverwrite?r:a,d=n?.forceOverwrite?a:r,c=e.schema.types.instance.create({id:i.O9,...a,currentPageId:r.currentPageId??s?.currentPageId,isDebugMode:l?.isDebugMode??d?.isDebugMode,isFocusMode:l?.isFocusMode??d?.isFocusMode,isToolLocked:l?.isToolLocked??d?.isToolLocked,isGridMode:l?.isGridMode??d?.isGridMode,exportBackground:l?.exportBackground??d?.exportBackground});e.atomic(()=>{for(let t of r.pageStates??[]){if(!e.has(t.pageId))continue;let n=i.Xu.createId(t.pageId),r=i.jA.createId(t.pageId),o=e.get(n),s=e.get(r);e.put([i.Xu.create({id:n,x:t.camera?.x??o?.x,y:t.camera?.y??o?.y,z:t.camera?.z??o?.z}),i.jA.create({id:r,pageId:t.pageId,selectedShapeIds:t.selectedShapeIds??s?.selectedShapeIds,focusedGroupId:t.focusedGroupId??s?.focusedGroupId})])}e.put([c]),e.ensureStoreIsUsable()})}function y(e){let t=[];for(let n of Object.values(e))n.typeName?.match(/^(instance.*|pointer|camera)$/)&&t.push(n);let n=t.filter(e=>"instance"===e.typeName&&e.id!==i.O9)[0];if(!n)return null;let r={version:p,currentPageId:n.currentPageId,exportBackground:!!n.exportBackground,isFocusMode:!!n.isFocusMode,isDebugMode:!!n.isDebugMode,isToolLocked:!!n.isToolLocked,isGridMode:!1,pageStates:t.filter(e=>"instance_page_state"===e.typeName&&e.instanceId===n.id).map(t=>{let n=e[t.cameraId]??{x:0,y:0,z:1};return{pageId:t.pageId,camera:{x:n.x,y:n.y,z:n.z},selectedShapeIds:t.selectedShapeIds,focusedGroupId:t.focusedGroupId}})};try{return f.validate(r),r}catch{return null}}},59830:(e,t,n)=>{"use strict";n.d(t,{UB:()=>c,Wj:()=>d,az:()=>o,mB:()=>a,tU:()=>s});var r=n(93286),i=n(46195);class o{constructor(e=0,t=0,n=0,r=0){this.x=e,this.y=t,this.w=n,this.h=r}x=0;y=0;w=0;h=0;get point(){return new i.l(this.x,this.y)}set point(e){this.x=e.x,this.y=e.y}get minX(){return this.x}set minX(e){this.x=e}get left(){return this.x}get midX(){return this.x+this.w/2}get maxX(){return this.x+this.w}get right(){return this.x+this.w}get minY(){return this.y}set minY(e){this.y=e}get top(){return this.y}get midY(){return this.y+this.h/2}get maxY(){return this.y+this.h}get bottom(){return this.y+this.h}get width(){return this.w}set width(e){this.w=e}get height(){return this.h}set height(e){this.h=e}get aspectRatio(){return this.width/this.height}get center(){return new i.l(this.x+this.w/2,this.y+this.h/2)}set center(e){this.x=e.x-this.w/2,this.y=e.y-this.h/2}get corners(){return[new i.l(this.x,this.y),new i.l(this.x+this.w,this.y),new i.l(this.x+this.w,this.y+this.h),new i.l(this.x,this.y+this.h)]}get cornersAndCenter(){return[new i.l(this.x,this.y),new i.l(this.x+this.w,this.y),new i.l(this.x+this.w,this.y+this.h),new i.l(this.x,this.y+this.h),new i.l(this.x+this.w/2,this.y+this.h/2)]}get sides(){let{corners:e}=this;return[[e[0],e[1]],[e[1],e[2]],[e[2],e[3]],[e[3],e[0]]]}get size(){return new i.l(this.w,this.h)}isValid(){return Number.isFinite(this.x)&&Number.isFinite(this.y)&&Number.isFinite(this.w)&&Number.isFinite(this.h)}toFixed(){return this.x=(0,r.QX)(this.x),this.y=(0,r.QX)(this.y),this.w=(0,r.QX)(this.w),this.h=(0,r.QX)(this.h),this}setTo(e){return this.x=e.x,this.y=e.y,this.w=e.w,this.h=e.h,this}set(e=0,t=0,n=0,r=0){return this.x=e,this.y=t,this.w=n,this.h=r,this}expand(e){let t=Math.min(this.x,e.x),n=Math.min(this.y,e.y),r=Math.max(this.x+this.w,e.x+e.w),i=Math.max(this.y+this.h,e.y+e.h);return this.x=t,this.y=n,this.w=r-t,this.h=i-n,this}expandBy(e){return this.x-=e,this.y-=e,this.w+=2*e,this.h+=2*e,this}scale(e){return this.x/=e,this.y/=e,this.w/=e,this.h/=e,this}clone(){let{x:e,y:t,w:n,h:r}=this;return new o(e,t,n,r)}translate(e){return this.x+=e.x,this.y+=e.y,this}snapToGrid(e){let t=Math.round(this.x/e)*e,n=Math.round(this.y/e)*e,r=Math.round((this.x+this.w)/e)*e,i=Math.round((this.y+this.h)/e)*e;this.minX=t,this.minY=n,this.width=Math.max(1,r-t),this.height=Math.max(1,i-n)}collides(e){return o.Collides(this,e)}contains(e){return o.Contains(this,e)}includes(e){return o.Includes(this,e)}containsPoint(e,t=0){return o.ContainsPoint(this,e,t)}getHandlePoint(e){switch(e){case"top_left":return new i.l(this.x,this.y);case"top_right":return new i.l(this.x+this.w,this.y);case"bottom_left":return new i.l(this.x,this.y+this.h);case"bottom_right":return new i.l(this.x+this.w,this.y+this.h);case"top":return new i.l(this.x+this.w/2,this.y);case"right":return new i.l(this.x+this.w,this.y+this.h/2);case"bottom":return new i.l(this.x+this.w/2,this.y+this.h);case"left":return new i.l(this.x,this.y+this.h/2)}}toJson(){return{x:this.x,y:this.y,w:this.w,h:this.h}}resize(e,t,n){let{minX:r,minY:i,maxX:o,maxY:s}=this,{minX:a,minY:l,maxX:d,maxY:c}=this;switch(e){case"left":case"top_left":case"bottom_left":a+=t;break;case"right":case"top_right":case"bottom_right":d+=t}switch(e){case"top":case"top_left":case"top_right":l+=n;break;case"bottom":case"bottom_left":case"bottom_right":c+=n}let h=(c-l)/(s-i);if((d-a)/(o-r)<0){let e=d;d=a,a=e}if(h<0){let e=c;c=l,l=e}this.minX=a,this.minY=l,this.width=Math.abs(d-a),this.height=Math.abs(c-l)}union(e){let t=Math.min(this.x,e.x),n=Math.min(this.y,e.y),r=Math.max(this.x+this.w,e.x+e.w),i=Math.max(this.y+this.h,e.y+e.h);return this.x=t,this.y=n,this.width=r-t,this.height=i-n,this}static From(e){return new o(e.x,e.y,e.w,e.h)}static FromCenter(e,t){return new o(e.x-t.x/2,e.y-t.y/2,t.x,t.y)}static FromPoints(e){let t;if(0===e.length)return new o;let n=1/0,r=1/0,i=-1/0,s=-1/0;for(let o=0,a=e.length;o<a;o++)n=Math.min((t=e[o]).x,n),r=Math.min(t.y,r),i=Math.max(t.x,i),s=Math.max(t.y,s);return new o(n,r,i-n,s-r)}static Expand(e,t){let n=Math.min(t.minX,e.minX),r=Math.min(t.minY,e.minY);return new o(n,r,Math.max(t.maxX,e.maxX)-n,Math.max(t.maxY,e.maxY)-r)}static ExpandBy(e,t){return new o(e.minX-t,e.minY-t,e.width+2*t,e.height+2*t)}static Collides(e,t){return!(e.maxX<t.minX||e.minX>t.maxX||e.maxY<t.minY||e.minY>t.maxY)}static Contains(e,t){return e.minX<t.minX&&e.minY<t.minY&&e.maxY>t.maxY&&e.maxX>t.maxX}static ContainsApproximately(e,t,n){return(0,r.rT)(e.minX,t.minX,n)&&(0,r.rT)(e.minY,t.minY,n)&&(0,r.rT)(t.maxX,e.maxX,n)&&(0,r.rT)(t.maxY,e.maxY,n)}static Includes(e,t){return o.Collides(e,t)||o.Contains(e,t)}static ContainsPoint(e,t,n=0){return!(t.x<e.minX-n||t.y<e.minY-n||t.x>e.maxX+n||t.y>e.maxY+n)}static Common(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let o=0;o<e.length;o++){let s=e[o];t=Math.min(t,s.minX),n=Math.min(n,s.minY),r=Math.max(r,s.maxX),i=Math.max(i,s.maxY)}return new o(t,n,r-t,i-n)}static Sides(e,t=0){let{corners:n}=e;return[[n[0],n[1]],[n[1],n[2]],[n[2],n[3]],[n[3],n[0]]]}static Resize(e,t,n,r,i=!1){let{minX:s,minY:a,maxX:l,maxY:d}=e,{minX:c,minY:h,maxX:u,maxY:p}=e;switch(t){case"left":case"top_left":case"bottom_left":c+=n;break;case"right":case"top_right":case"bottom_right":u+=n}switch(t){case"top":case"top_left":case"top_right":h+=r;break;case"bottom":case"bottom_left":case"bottom_right":p+=r}let f=(u-c)/(l-s),g=(p-h)/(d-a);if(i){let e=(l-s)/(d-a),n=Math.abs(u-c),r=Math.abs(p-h),i=n*(g<0?1:-1)*(1/e),o=r*(f<0?1:-1)*e,m=e<n/r;switch(t){case"top_left":m?h=p+i:c=u+o;break;case"top_right":m?h=p+i:u=c-o;break;case"bottom_right":m?p=h-i:u=c-o;break;case"bottom_left":m?p=h-i:c=u+o;break;case"bottom":case"top":{let t=(c+u)/2,n=r*e;c=t-n/2,u=t+n/2;break}case"left":case"right":{let t=(h+p)/2,r=n/e;h=t-r/2,p=t+r/2}}}if(f<0){let e=u;u=c,c=e}if(g<0){let e=p;p=h,h=e}let m=new o(c,h,Math.abs(u-c),Math.abs(p-h));return{box:m,scaleX:+(m.width/e.width*(f>0?1:-1)).toFixed(5),scaleY:+(m.height/e.height*(g>0?1:-1)).toFixed(5)}}equals(e){return o.Equals(this,e)}static Equals(e,t){return t.x===e.x&&t.y===e.y&&t.w===e.w&&t.h===e.h}zeroFix(){return this.w=Math.max(1,this.w),this.h=Math.max(1,this.h),this}static ZeroFix(e){return new o(e.x,e.y,Math.max(1,e.w),Math.max(1,e.h))}}function s(e){switch(e){case"top":return"bottom";case"bottom":return"top";case"top_left":return"bottom_left";case"top_right":return"bottom_right";case"bottom_left":return"top_left";case"bottom_right":return"top_right";default:return e}}function a(e){switch(e){case"left":return"right";case"right":return"left";case"top_left":return"top_right";case"top_right":return"top_left";case"bottom_left":return"bottom_right";case"bottom_right":return"bottom_left";default:return e}}let l=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function d(e,t){let n=Math.round((t%=r.uA)/(r.PI/4)),i=l.indexOf(e);return l[(i+n)%l.length]}function c(e){return"top_left"===e||"top_right"===e||"bottom_right"===e||"bottom_left"===e}},61307:(e,t,n)=>{"use strict";n.d(t,{Q:()=>a});var r=n(83102),i=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=(e,t,n,r)=>{for(var s,a=r>1?void 0:r?o(t,n):t,l=e.length-1;l>=0;l--)(s=e[l])&&(a=(r?s(t,n,a):s(a))||a);return r&&a&&i(t,n,a),a};class a{constructor(e){this.editor=e}editor;_overlayUtils=new Map;registerUtil(e){let t=e.constructor.type;if(!t)throw Error(`Overlay util ${e.constructor.name} is missing a static 'type' property.`);if(this._overlayUtils.has(t))throw Error(`Duplicate overlay util type: "${t}"`);this._overlayUtils.set(t,e)}dispose(){for(let e of this._overlayUtils.values())e.dispose()}getOverlayUtil(e){let t="string"==typeof e?e:e.type,n=this._overlayUtils.get(t);if(!n)throw Error(`No overlay util found for type: "${t}"`);return n}getOverlayUtilsInZOrder(){return Array.from(this._overlayUtils.values()).map((e,t)=>({util:e,i:t,z:e.options.zIndex??0})).sort((e,t)=>e.z-t.z||e.i-t.i).map(e=>e.util)}getActiveOverlayEntries(){let e=[];for(let t of this.getOverlayUtilsInZOrder())t.isActive()&&e.push({util:t,overlays:t.getOverlays()});return e}getCurrentOverlays(){let e=[];for(let{overlays:t}of this.getActiveOverlayEntries())e.push(...t);return e}_geometryCache=new WeakMap;getOverlayGeometry(e){let t=this._geometryCache.get(e);if(void 0!==t)return t;let n=this.getOverlayUtil(e).getGeometry(e);return this._geometryCache.set(e,n),n}_hoveredOverlayId=(0,r.eU)("hoveredOverlayId",null);getHoveredOverlayId(){return this._hoveredOverlayId.get()}getHoveredOverlay(){let e=this._hoveredOverlayId.get();return e?this.getCurrentOverlays().find(t=>t.id===e)??null:null}setHoveredOverlay(e){e!==this._hoveredOverlayId.get()&&this._hoveredOverlayId.set(e)}getOverlayAtPoint(e,t=0){let n=this.getActiveOverlayEntries();for(let r=n.length-1;r>=0;r--){let{overlays:i}=n[r];for(let n of i){let r=this.getOverlayGeometry(n);if(r&&r.hitTestPoint(e,r.isFilled?0:t,!0))return n}}return null}}s([r.EW],a.prototype,"getOverlayUtilsInZOrder",1),s([r.EW],a.prototype,"getActiveOverlayEntries",1),s([r.EW],a.prototype,"getCurrentOverlays",1)},63509:(e,t,n)=>{"use strict";n.d(t,{X:()=>o});var r=n(12115),i=n(66294);function o(e){let[t,n]=r.useState(void 0);return(0,i.N)(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{let r,i;if(!Array.isArray(t)||!t.length)return;let o=t[0];if("borderBoxSize"in o){let e=o.borderBoxSize,t=Array.isArray(e)?e[0]:e;r=t.inlineSize,i=t.blockSize}else r=e.offsetWidth,i=e.offsetHeight;n({width:r,height:i})});return t.observe(e,{box:"border-box"}),()=>t.unobserve(e)}n(void 0)},[e]),t}(0,Object.defineProperty)(o,"name",{value:"useSize",configurable:!0})},64411:e=>{"use strict";var t=Object.prototype.hasOwnProperty,n="~";function r(){}function i(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,r,o,s){if("function"!=typeof r)throw TypeError("The listener must be a function");var a=new i(r,o||e,s),l=n?n+t:t;return e._events[l]?e._events[l].fn?e._events[l]=[e._events[l],a]:e._events[l].push(a):(e._events[l]=a,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function a(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1)),a.prototype.eventNames=function(){var e,r,i=[];if(0===this._eventsCount)return i;for(r in e=this._events)t.call(e,r)&&i.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},a.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var i=0,o=r.length,s=Array(o);i<o;i++)s[i]=r[i].fn;return s},a.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},a.prototype.emit=function(e,t,r,i,o,s){var a=n?n+e:e;if(!this._events[a])return!1;var l,d,c=this._events[a],h=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),h){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,r),!0;case 4:return c.fn.call(c.context,t,r,i),!0;case 5:return c.fn.call(c.context,t,r,i,o),!0;case 6:return c.fn.call(c.context,t,r,i,o,s),!0}for(d=1,l=Array(h-1);d<h;d++)l[d-1]=arguments[d];c.fn.apply(c.context,l)}else{var u,p=c.length;for(d=0;d<p;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),h){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,t);break;case 3:c[d].fn.call(c[d].context,t,r);break;case 4:c[d].fn.call(c[d].context,t,r,i);break;default:if(!l)for(u=1,l=Array(h-1);u<h;u++)l[u-1]=arguments[u];c[d].fn.apply(c[d].context,l)}}return!0},a.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,r,i){var o=n?n+e:e;if(!this._events[o])return this;if(!t)return s(this,o),this;var a=this._events[o];if(a.fn)a.fn!==t||i&&!a.once||r&&a.context!==r||s(this,o);else{for(var l=0,d=[],c=a.length;l<c;l++)(a[l].fn!==t||i&&!a[l].once||r&&a[l].context!==r)&&d.push(a[l]);d.length?this._events[o]=1===d.length?d[0]:d:s(this,o)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&s(this,t)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a},65009:(e,t,n)=>{"use strict";n.d(t,{A:()=>a});var r=n(16038);let i=null,o={area:[16384,14188,11402,11180,10836,8192,4096],height:[8388607,65535,32767,16384,8192,4096],width:[4194303,65535,32767,16384,8192,4096]};function s(e){let t=(0,r.jL)().createElement("canvas");t.width=1,t.height=1;let n=t.getContext("2d");for(let i of o[e]){let o="height"===e?1:i,s="width"===e?1:i,a=(0,r.jL)().createElement("canvas");a.width=o,a.height=s,a.getContext("2d").fillRect(o-1,s-1,1,1),n.drawImage(a,o-1,s-1,1,1,0,0,1,1);let l=0!==n.getImageData(0,0,1,1).data[3];if(a.width=0,a.height=0,l){if(t.width=0,t.height=0,"area"===e)return i*i;return i}}throw t.width=0,t.height=0,Error("Failed to determine maximum canvas dimension")}function a(e,t){if(e<=8192&&t<=8192&&e*t<=0x1000000)return[e,t];let{maxWidth:n,maxHeight:r,maxArea:o}=(i||(i={maxWidth:s("width"),maxHeight:s("height"),maxArea:s("area")}),i),a=e/t;if(e>n&&(t=(e=n)/a),t>r&&(e=(t=r)*a),e*t>o){let n=Math.sqrt(o/(e*t));e*=n,t*=n}return[e,t]}},65390:(e,t,n)=>{"use strict";n.d(t,{_:()=>o});var r=n(12115),i=n(15727);let o={maxShapesPerPage:4e3,maxFilesAtOnce:100,maxPages:40,animationMediumMs:320,followChaseViewportSnap:2,doubleClickDurationMs:450,multiClickDurationMs:200,coarseDragDistanceSquared:36,dragDistanceSquared:16,uiDragDistanceSquared:16,uiCoarseDragDistanceSquared:625,defaultSvgPadding:32,cameraSlideFriction:.09,gridSteps:[{min:-1,mid:.15,step:64},{min:.05,mid:.375,step:16},{min:.15,mid:1,step:4},{min:.7,mid:2.5,step:1}],collaboratorInactiveTimeoutMs:6e4,collaboratorIdleTimeoutMs:3e3,collaboratorCheckIntervalMs:1200,cameraMovingTimeoutMs:64,hitTestMargin:3,coarseHitTestMargin:4,edgeScrollDelay:200,edgeScrollEaseDuration:200,edgeScrollSpeed:25,edgeScrollDistance:8,coarsePointerWidth:12,coarseHandleRadius:20,handleRadius:12,longPressDurationMs:500,textShadowLod:.35,adjacentShapeMargin:10,flattenImageBoundsExpand:64,flattenImageBoundsPadding:16,laserDelayMs:1200,laserFadeoutMs:500,maxExportDelayMs:5e3,tooltipDelayMs:700,temporaryAssetPreviewLifetimeMs:18e4,actionShortcutsLocation:"swap",createTextOnCanvasDoubleClick:!0,exportProvider:r.Fragment,enableToolbarKeyboardShortcuts:!0,maxFontsToLoadBeforeRender:1/0,nonce:void 0,debouncedZoom:!0,debouncedZoomThreshold:500,spacebarPanning:!0,rightClickPanning:!0,zoomToFitPadding:128,snapThreshold:8,selectLockedShapes:!1,camera:i.zd,text:{},deepLinks:void 0,quickZoomPreservesScreenBounds:!0,onBeforeCopyToClipboard:void 0,onBeforePasteFromClipboard:void 0,onClipboardPasteRaw:void 0,experimental__onDropOnCanvas:void 0}},66122:(e,t,n)=>{"use strict";n.d(t,{O:()=>c});var r=n(83102),i=n(24167),o=n(46195),s=Object.defineProperty,a=Object.getOwnPropertyDescriptor;let l=()=>null,d=()=>[];class c{constructor(e){this.manager=e,this.editor=e.editor}manager;editor;getSnapGeometryCache(){let{editor:e}=this;return e.store.createComputedCache("handle snap geometry",t=>{let n=e.getShapeUtil(t).getHandleSnapGeometry(t),r=n.getSelfSnapOutline?n.getSelfSnapOutline.bind(n):l,i=n.getSelfSnapPoints?n.getSelfSnapPoints.bind(n):d;return{outline:void 0===n.outline?e.getShapeGeometry(t):n.outline,points:n.points??[],getSelfSnapOutline:r,getSelfSnapPoints:i}})}*iterateSnapPointsInPageSpace(e,t){let n=this.getSnapGeometryCache().get(e)?.getSelfSnapPoints(t);if(n&&n.length){let t=(0,i.Z1)(this.editor.getShapePageTransform(e));for(let e of n)yield t.applyToPoint(e)}for(let t of this.manager.getSnappableShapes()){if(t===e)continue;let n=this.getSnapGeometryCache().get(t)?.points;if(!n||!n.length)continue;let r=(0,i.Z1)(this.editor.getShapePageTransform(t));for(let e of n)yield r.applyToPoint(e)}}*iterateSnapOutlines(e,t){let n=this.getSnapGeometryCache().get(e)?.getSelfSnapOutline(t);for(let t of(n&&(yield{shapeId:e,outline:n}),this.manager.getSnappableShapes())){if(t===e)continue;let n=this.getSnapGeometryCache().get(t)?.outline;n&&(yield{shapeId:t,outline:n})}}getHandleSnapPosition({currentShapeId:e,handle:t,handleInPageSpace:n}){let r=this.manager.getSnapThreshold(),s=r,a=null;for(let r of this.iterateSnapPointsInPageSpace(e,t))o.l.DistMin(n,r,s)&&(s=o.l.Dist(n,r),a=r);if(a)return a;let l=r,d=null;for(let{shapeId:r,outline:s}of this.iterateSnapOutlines(e,t)){let e=(0,i.Z1)(this.editor.getShapePageTransform(r)),t=this.editor.getPointInShapeSpace(r,n),a=s.nearestPoint(t),c=e.applyToPoint(a);o.l.DistMin(n,c,l)&&(l=o.l.Dist(n,c),d=c)}return d||null}getHandleSnapData({handle:e,currentShapeId:t}){let n=this.manager.getSnapThreshold(),r=(0,i.Z1)(this.editor.getShapePageTransform(t)).applyToPoint(e),s=null,a=null,l=n,d=n;for(let n of this.iterateSnapPointsInPageSpace(t,e)){let e=Math.abs(r.x-n.x),t=Math.abs(r.y-n.y);e<l&&(l=e,s=n),t<d&&(d=t,a=n)}if(!s&&!a)return null;let c=new o.l(s?s.x-r.x:0,a?a.y-r.y:0),h=o.l.Add(r,c),u=[];if(s){let e=new o.l(s.x,h.y);u.push({id:(0,i.NF)(),type:"points",points:[s,e]})}if(a){let e=new o.l(h.x,a.y);u.push({id:(0,i.NF)(),type:"points",points:[a,e]})}return{snaps:u,nudge:c}}snapHandle({currentShapeId:e,handle:t}){let n=(0,i.Z1)(this.editor.getShapePageTransform(e)).applyToPoint(t),r=t.canSnap?"point":t.snapType;if("point"===r){let r=this.getHandleSnapPosition({currentShapeId:e,handle:t,handleInPageSpace:n});return r?(this.manager.setIndicators([{id:(0,i.NF)(),type:"points",points:[r]}]),{nudge:o.l.Sub(r,n)}):null}if("align"===r){let n=this.getHandleSnapData({handle:t,currentShapeId:e});return n?(this.manager.setIndicators(n.snaps),{nudge:n.nudge}):null}return null}}((e,t,n)=>{for(var r,i=a(t,n),o=e.length-1;o>=0;o--)(r=e[o])&&(i=r(t,n,i)||i);return i&&s(t,n,i)})([r.EW],c.prototype,"getSnapGeometryCache")},66294:(e,t,n)=>{"use strict";n.d(t,{N:()=>i});var r=n(12115),i=globalThis?.document?r.useLayoutEffect:()=>{}},67863:(e,t,n)=>{"use strict";n.d(t,{fr:()=>l,hG:()=>a,zz:()=>d});var r=n(95155),i=n(12115),o=n(73352);let s=(0,i.createContext)(null);function a(){let e=i.useContext(s);if(!e)throw Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return e}function l(){return i.useContext(s)}function d({editor:e,children:t}){return(0,r.jsx)(s.Provider,{value:e,children:(0,r.jsx)(o.JE,{children:t})})}},67877:(e,t,n)=>{"use strict";n.d(t,{$:()=>i,B:()=>o});var r=n(12115);let i=(0,r.createContext)(null);function o(){let e=(0,r.useContext)(i);if(!e)throw Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return e}},68599:(e,t,n)=>{"use strict";n.d(t,{A:()=>a});var r=n(12115),i=n(95155),o=Object.defineProperty,s=(e,t)=>o(e,"name",{value:t,configurable:!0});function a(e,t=[]){let n=[];function o(t,o){let a=r.createContext(o);a.displayName=t+"Context";let l=n.length;n=[...n,o];let d=s(t=>{let{scope:n,children:o,...s}=t,d=n?.[e]?.[l]||a,c=r.useMemo(()=>s,Object.values(s));return(0,i.jsx)(d.Provider,{value:c,children:o})},"Provider");function c(n,i,s={}){let{optional:d=!1}=s,h=i?.[e]?.[l]||a,u=r.useContext(h);if(u)return u;if(void 0!==o)return o;if(!d)throw Error(`\`${n}\` must be used within \`${t}\``)}return d.displayName=t+"Provider",s(c,"useContext"),[d,c]}s(o,"createContext");let d=s(()=>{let t=n.map(e=>r.createContext(e));return s(function(n){let i=n?.[e]||t;return r.useMemo(()=>({[`__scope${e}`]:{...n,[e]:i}}),[n,i])},"useScope")},"createScope");return d.scopeName=e,[o,l(d,...t)]}function l(...e){let t=e[0];if(1===e.length)return t;let n=s(()=>{let n=e.map(e=>({useScope:e(),scopeName:e.scopeName}));return s(function(e){let i=n.reduce((t,{useScope:n,scopeName:r})=>{let i=n(e)[`__scope${r}`];return{...t,...i}},{});return r.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}s(function(e,t){let n=r.createContext(t);n.displayName=e+"Context";let o=s(e=>{let{children:t,...o}=e,s=r.useMemo(()=>o,Object.values(o));return(0,i.jsx)(n.Provider,{value:s,children:t})},"Provider");function a(i,o={}){let{optional:s=!1}=o,l=r.useContext(n);if(l)return l;if(void 0!==t)return t;if(!s)throw Error(`\`${i}\` must be used within \`${e}\``)}return o.displayName=e+"Provider",s(a,"useContext"),[o,a]},"createContext"),s(a,"createContextScope"),s(l,"composeContextScopes")},68935:(e,t,n)=>{"use strict";n.d(t,{A:()=>a});var r=n(83102),i=n(54530),o=n(81467);let s=(e,t,n)=>{for(;!(0,o.xh)(n.parentId);){let t=e.get(n.parentId);if(!t)return!1;n=t}return n.parentId===t};function a(e,t){let n=e.query.ids("shape"),a=null;function l(){let r=t();return a=r,new Set([...n.get()].filter(t=>s(e,r,e.get(t))))}return(0,r.EW)("_shapeIdsInCurrentPage",(n,d)=>{if((0,r._O)(n))return l();let c=t();if(c!==a)return l();let h=e.history.getDiffSince(d);if(h===r.c2)return l();let u=new i.zq(n);for(let t of h){for(let n of Object.values(t.added))(0,o.o2)(n)&&s(e,c,n)&&u.add(n.id);for(let[n,r]of Object.values(t.updated))(0,o.o2)(r)&&(s(e,c,r)?u.add(r.id):u.remove(r.id));for(let e of Object.keys(t.removed))(0,o.vc)(e)&&u.remove(e)}let p=u.get();return p?(0,r._D)(p.value,p.diff):n})}},69245:(e,t,n)=>{"use strict";n.d(t,{q7:()=>W,bL:()=>K,RG:()=>O});var r=n(12115),i=n.t(r,2),o=n(70379),s=n(76094),a=n(47527),l=n(68599),d=n(89971),c=n(55897),h=n(17347),u=n(54498),p=n(1933),f=n(66294),g=Object.defineProperty,m=(e,t)=>g(e,"name",{value:t,configurable:!0}),y=!1;function b(){let[e,t]=r.useState(y);return r.useEffect(()=>{y||(y=!0,t(!0))},[]),e}m(b,"useIsHydrated");var x=i[" useSyncExternalStore ".trim().toString()];function w(){return()=>{}}function v(){return x(w,()=>!0,()=>!1)}m(w,"subscribe"),m(v,"useIsHydratedModern");var S="function"==typeof x?v:b,C=n(95155),k=Object.defineProperty,P=(e,t)=>k(e,"name",{value:t,configurable:!0}),T="rovingFocusGroup.onEntryFocus",E={bubbles:!1,cancelable:!0},I="RovingFocusGroup",[_,M,A]=(0,s.N)(I),[j,O]=(0,l.A)(I,[A]),[D,L]=j(I),R=r.forwardRef(P(function(e,t){return(0,C.jsx)(_.Provider,{scope:e.__scopeRovingFocusGroup,children:(0,C.jsx)(_.Slot,{scope:e.__scopeRovingFocusGroup,children:(0,C.jsx)(F,{...e,ref:t})})})},"RovingFocusGroup")),F=r.forwardRef(P(function(e,t){let{__scopeRovingFocusGroup:n,orientation:i,loop:s=!1,dir:l,currentTabStopId:d,defaultCurrentTabStopId:f,onCurrentTabStopIdChange:g,onEntryFocus:m,preventScrollOnEntryFocus:y=!1,...b}=e,x=r.useRef(null),w=(0,a.s)(t,x),v=(0,p.jH)(l),[S,k]=(0,u.i)({prop:d,defaultProp:f??null,onChange:g,caller:I}),[P,_]=r.useState(!1),A=(0,h.c)(m),j=M(n),O=r.useRef(!1),[L,R]=r.useState(0);return r.useEffect(()=>{let e=x.current;if(e)return e.addEventListener(T,A),()=>e.removeEventListener(T,A)},[A]),(0,C.jsx)(D,{scope:n,orientation:i,dir:v,loop:s,currentTabStopId:S,onItemFocus:r.useCallback(e=>k(e),[k]),onItemShiftTab:r.useCallback(()=>_(!0),[]),onFocusableItemAdd:r.useCallback(()=>R(e=>e+1),[]),onFocusableItemRemove:r.useCallback(()=>R(e=>e-1),[]),children:(0,C.jsx)(c.sG.div,{tabIndex:P||0===L?-1:0,"data-orientation":i,...b,ref:w,style:{outline:"none",...e.style},onMouseDown:(0,o.mK)(e.onMouseDown,()=>{O.current=!0}),onFocus:(0,o.mK)(e.onFocus,e=>{let t=!O.current;if(e.target===e.currentTarget&&t&&!P){let t=new CustomEvent(T,E);if(e.currentTarget.dispatchEvent(t),!t.defaultPrevented){let e=j().filter(e=>e.focusable);H([e.find(e=>e.active),e.find(e=>e.id===S),...e].filter(Boolean).map(e=>e.ref.current),y)}}O.current=!1}),onBlur:(0,o.mK)(e.onBlur,()=>_(!1))})})},"RovingFocusGroupImpl")),z=r.forwardRef(P(function(e,t){let{__scopeRovingFocusGroup:n,focusable:i=!0,active:s=!1,tabStopId:a,children:l,...h}=e,u=(0,d.B)(),p=a||u,g=L("RovingFocusGroupItem",n),m=g.currentTabStopId===p,y=M(n),{onFocusableItemAdd:b,onFocusableItemRemove:x,currentTabStopId:w}=g,v=S();return(0,f.N)(()=>{if(v&&i)return b(),()=>x()},[v,i,b,x]),r.useEffect(()=>{if(!v&&i)return b(),()=>x()},[v,i,b,x]),(0,C.jsx)(_.ItemSlot,{scope:n,id:p,focusable:i,active:s,children:(0,C.jsx)(c.sG.span,{tabIndex:m?0:-1,"data-orientation":g.orientation,...h,ref:t,onMouseDown:(0,o.mK)(e.onMouseDown,e=>{i?g.onItemFocus(p):e.preventDefault()}),onFocus:(0,o.mK)(e.onFocus,()=>g.onItemFocus(p)),onKeyDown:(0,o.mK)(e.onKeyDown,e=>{if("Tab"===e.key&&e.shiftKey)return void g.onItemShiftTab();if(e.target!==e.currentTarget)return;let t=B(e,g.orientation,g.dir);if(void 0!==t){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;e.preventDefault();let n=y().filter(e=>e.focusable).map(e=>e.ref.current);if("last"===t)n.reverse();else if("prev"===t||"next"===t){"prev"===t&&n.reverse();let r=n.indexOf(e.currentTarget);n=g.loop?U(n,r+1):n.slice(r+1)}setTimeout(()=>H(n))}}),children:"function"==typeof l?l({isCurrentTabStop:m,hasTabStop:null!=w}):l})})},"RovingFocusGroupItem")),N={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function $(e,t){return"rtl"!==t?e:"ArrowLeft"===e?"ArrowRight":"ArrowRight"===e?"ArrowLeft":e}function B(e,t,n){let r=$(e.key,n);if(!("vertical"===t&&["ArrowLeft","ArrowRight"].includes(r))&&!("horizontal"===t&&["ArrowUp","ArrowDown"].includes(r)))return N[r]}function H(e,t=!1){let n=document.activeElement;for(let r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function U(e,t){return e.map((n,r)=>e[(t+r)%e.length])}P($,"getDirectionAwareKey"),P(B,"getFocusIntent"),P(H,"focusFirst"),P(U,"wrapArray");var K=R,W=z},69409:(e,t,n)=>{"use strict";n.d(t,{T:()=>i});var r=n(24167);function i(e,t,n,i){if(0===n.length)return[];let s=new Map;for(let t of(0,r.oE)(n.map(t=>e.getShape(t)))){let{parentId:n}=t;s.has(n)||s.set(n,{children:(0,r.oE)(e.getSortedChildIdsForParent(n).map(t=>e.getShape(t))),moving:new Set}),s.get(n).moving.add(t)}let a=[];switch(t){case"toBack":s.forEach(({moving:e,children:t})=>(function(e,t,n){let i,o,s=t.length;if(e.size!==s){for(let n=0;n<s;n++){let r=t[n];if(e.has(r))i=r.index,e.delete(r);else{o=r.index;break}}if(0===e.size)return;{let t=(0,r.MT)(i,o,e.size);n.push(...Array.from(e.values()).sort(r.Ky).map((e,n)=>({...e,index:t[n]})))}}})(e,t,a));break;case"toFront":s.forEach(({moving:e,children:t})=>(function(e,t,n){let i,o,s=t.length;if(e.size!==s){for(let n=s-1;n>-1;n--){let r=t[n];if(e.has(r))o=r.index,e.delete(r);else{i=r.index;break}}if(0===e.size)return;{let t=(0,r.MT)(i,o,e.size);n.push(...Array.from(e.values()).sort(r.Ky).map((e,n)=>({...e,index:t[n]})))}}})(e,t,a));break;case"forward":s.forEach(({moving:t,children:n})=>(function(e,t,n,i,s){let a=o(e,t),l=n.length;if(t.size===l)return;let d={name:"skipping"};for(let e=0;e<l;e++){let o=t.has(n[e]);switch(d.name){case"skipping":if(!o)continue;d={name:"selecting",selectIndex:e};break;case"selecting":{if(o||!s?.considerAllShapes&&!a(n[e]))continue;let{selectIndex:l}=d;(0,r.MT)(n[e].index,n[e+1]?.index,e-l).forEach((e,r)=>{let o=n[l+r];t.has(o)&&i.push({...o,index:e})}),d={name:"skipping"}}}}})(e,t,n,a,i));break;case"backward":s.forEach(({moving:t,children:n})=>(function(e,t,n,i,s){let a=o(e,t),l=n.length;if(t.size===l)return;let d={name:"skipping"};for(let e=l-1;e>-1;e--){let o=t.has(n[e]);switch(d.name){case"skipping":if(!o)continue;d={name:"selecting",selectIndex:e};break;case"selecting":if(o||!s?.considerAllShapes&&!a(n[e]))continue;(0,r.MT)(n[e-1]?.index,n[e].index,d.selectIndex-e).forEach((r,o)=>{let s=n[e+o+1];t.has(s)&&i.push({...s,index:r})}),d={name:"skipping"}}}})(e,t,n,a,i))}return a}function o(e,t){let n=(0,r.oE)(Array.from(t).map(t=>{let n=e.getShapePageBounds(t);return n?{shape:t,bounds:n}:null}));return t=>{let r=e.getShapePageBounds(t);return!!r&&n.some(e=>e.bounds.includes(r))}}},69445:(e,t,n)=>{"use strict";n.d(t,{G5:()=>ez,H_:()=>eD,Mz:()=>eM,Pb:()=>eR,UC:()=>ej,UE:()=>L,VF:()=>eL,ZL:()=>eA,ZP:()=>eF,bL:()=>e_,q7:()=>eO});var r=n(12115),i=n(70379),o=n(76094),s=n(47527),a=n(68599),l=n(1933),d=n(19416),c=n(32007),h=n(69885),u=n(89971),p=n(80878),f=n(19040),g=n(83935),m=n(55897),y=n(69245),b=n(42442),x=n(17347),w=n(22954),v=n(5174),S=n(95155),C=Object.defineProperty,k=(e,t)=>C(e,"name",{value:t,configurable:!0}),P=["Enter"," "],T=["ArrowUp","PageDown","End"],E=["ArrowDown","PageUp","Home",...T],I={ltr:[...P,"ArrowRight"],rtl:[...P,"ArrowLeft"]},_={ltr:["ArrowLeft"],rtl:["ArrowRight"]},M="Menu",[A,j,O]=(0,o.N)(M),[D,L]=(0,a.A)(M,[O,p.Bk,y.RG]),R=(0,p.Bk)(),F=(0,y.RG)(),[z,N]=D(M),[$,B]=D(M),H=k(e=>{let{__scopeMenu:t,open:n=!1,children:i,dir:o,onOpenChange:s,modal:a=!0}=e,d=R(t),[c,h]=r.useState(null),u=r.useRef(!1),f=(0,x.c)(s),g=(0,l.jH)(o);return r.useEffect(()=>{let e=k(()=>{u.current=!0,document.addEventListener("pointerdown",t,{capture:!0,once:!0}),document.addEventListener("pointermove",t,{capture:!0,once:!0})},"handleKeyDown"),t=k(()=>u.current=!1,"handlePointer");return document.addEventListener("keydown",e,{capture:!0}),()=>{document.removeEventListener("keydown",e,{capture:!0}),document.removeEventListener("pointerdown",t,{capture:!0}),document.removeEventListener("pointermove",t,{capture:!0})}},[]),r.useEffect(()=>{if(!n)return;let e=k(()=>f(!1),"handleBlur");return window.addEventListener("blur",e),()=>window.removeEventListener("blur",e)},[n,f]),(0,S.jsx)(p.bL,{...d,children:(0,S.jsx)(z,{scope:t,open:n,onOpenChange:f,content:c,onContentChange:h,children:(0,S.jsx)($,{scope:t,onClose:r.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:u,dir:g,modal:a,children:i})})})},"Menu"),U=r.forwardRef(k(function(e,t){let{__scopeMenu:n,...r}=e,i=R(n);return(0,S.jsx)(p.Mz,{...i,...r,ref:t})},"MenuAnchor")),K="MenuPortal",[W,V]=D(K,{forceMount:void 0}),Y=k(e=>{let{__scopeMenu:t,forceMount:n,children:r,container:i}=e,o=N(K,t);return(0,S.jsx)(W,{scope:t,forceMount:n,children:(0,S.jsx)(g.C,{present:n||o.open,children:(0,S.jsx)(f.Z,{asChild:!0,container:i,children:r})})})},"MenuPortal"),G="MenuContent",[q,X]=D(G),J=r.forwardRef(k(function(e,t){let n=V(G,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,o=N(G,e.__scopeMenu),s=B(G,e.__scopeMenu);return(0,S.jsx)(A.Provider,{scope:e.__scopeMenu,children:(0,S.jsx)(g.C,{present:r||o.open,children:(0,S.jsx)(A.Slot,{scope:e.__scopeMenu,children:s.modal?(0,S.jsx)(Z,{...i,ref:t}):(0,S.jsx)(Q,{...i,ref:t})})})})},"MenuContent")),Z=r.forwardRef(k(function(e,t){let n=N(G,e.__scopeMenu),o=r.useRef(null),a=(0,s.s)(t,o);return r.useEffect(()=>{let e=o.current;if(e)return(0,w.Eq)(e)},[]),(0,S.jsx)(et,{...e,ref:a,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:(0,i.mK)(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})},"MenuRootContentModal")),Q=r.forwardRef(k(function(e,t){let n=N(G,e.__scopeMenu);return(0,S.jsx)(et,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})},"MenuRootContentNonModal")),ee=(0,b.TL)("MenuContent.ScrollLock"),et=r.forwardRef(k(function(e,t){let{__scopeMenu:n,loop:o=!1,trapFocus:a,onOpenAutoFocus:l,onCloseAutoFocus:u,disableOutsidePointerEvents:f,onEntryFocus:g,onEscapeKeyDown:m,onPointerDownOutside:b,onFocusOutside:x,onInteractOutside:w,onDismiss:C,disableOutsideScroll:P,...I}=e,_=N(G,n),M=B(G,n),A=R(n),O=F(n),D=j(n),[L,z]=r.useState(null),$=r.useRef(null),H=(0,s.s)(t,$,_.onContentChange),U=r.useRef(0),K=r.useRef(""),W=r.useRef(0),V=r.useRef(null),Y=r.useRef("right"),X=r.useRef(0),J=P?v.A:r.Fragment,Z=k(e=>{let t=K.current+e,n=D().filter(e=>!e.disabled),r=document.activeElement,i=n.find(e=>e.ref.current===r)?.textValue,o=eP(n.map(e=>e.textValue),t,i),s=n.find(e=>e.textValue===o)?.ref.current;s&&setTimeout(()=>s.focus())},"handleTypeaheadSearch");r.useEffect(()=>()=>window.clearTimeout(U.current),[]),(0,c.Oh)();let Q=r.useCallback(e=>Y.current===V.current?.side&&eE(e,V.current?.area),[]);return(0,S.jsx)(q,{scope:n,searchRef:K,onItemEnter:r.useCallback(e=>{Q(e)&&e.preventDefault()},[Q]),onItemLeave:r.useCallback(e=>{Q(e)||($.current?.focus(),z(null))},[Q]),onTriggerLeave:r.useCallback(e=>{Q(e)&&e.preventDefault()},[Q]),pointerGraceTimerRef:W,onPointerGraceIntentChange:r.useCallback(e=>{V.current=e},[]),children:(0,S.jsx)(J,{...P?{as:ee,allowPinchZoom:!0}:void 0,children:(0,S.jsx)(h.n,{asChild:!0,trapped:a,onMountAutoFocus:(0,i.mK)(l,e=>{e.preventDefault(),$.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:u,children:(0,S.jsx)(d.qW,{asChild:!0,disableOutsidePointerEvents:f,onEscapeKeyDown:m,onPointerDownOutside:b,onFocusOutside:x,onInteractOutside:w,onDismiss:C,children:(0,S.jsx)(y.bL,{asChild:!0,...O,dir:M.dir,orientation:"vertical",loop:o,currentTabStopId:L,onCurrentTabStopIdChange:z,onEntryFocus:(0,i.mK)(g,e=>{M.isUsingKeyboardRef.current||e.preventDefault()}),preventScrollOnEntryFocus:!0,children:(0,S.jsx)(p.UC,{role:"menu","aria-orientation":"vertical","data-state":ew(_.open),"data-radix-menu-content":"",dir:M.dir,...A,...I,ref:H,style:{outline:"none",...I.style},onKeyDown:(0,i.mK)(I.onKeyDown,e=>{let t=e.target.closest("[data-radix-menu-content]")===e.currentTarget,n=e.ctrlKey||e.altKey||e.metaKey,r=1===e.key.length;t&&("Tab"===e.key&&e.preventDefault(),!n&&r&&Z(e.key));let i=$.current;if(e.target!==i||!E.includes(e.key))return;e.preventDefault();let o=D().filter(e=>!e.disabled).map(e=>e.ref.current);T.includes(e.key)&&o.reverse(),eC(o)}),onBlur:(0,i.mK)(e.onBlur,e=>{e.currentTarget.contains(e.target)||(window.clearTimeout(U.current),K.current="")}),onPointerMove:(0,i.mK)(e.onPointerMove,eI(e=>{let t=e.target,n=X.current!==e.clientX;e.currentTarget.contains(t)&&n&&(Y.current=e.clientX>X.current?"right":"left",X.current=e.clientX)}))})})})})})})},"MenuContentImpl")),en="MenuItem",er="menu.itemSelect",ei=r.forwardRef(k(function(e,t){let{disabled:n=!1,onSelect:o,...a}=e,l=r.useRef(null),d=B(en,e.__scopeMenu),c=X(en,e.__scopeMenu),h=(0,s.s)(t,l),u=r.useRef(!1),p=k(()=>{let e=l.current;if(!n&&e){let t=new CustomEvent(er,{bubbles:!0,cancelable:!0});e.addEventListener(er,e=>o?.(e),{once:!0}),(0,m.hO)(e,t),t.defaultPrevented?u.current=!1:d.onClose()}},"handleSelect");return(0,S.jsx)(eo,{...a,ref:h,disabled:n,onClick:(0,i.mK)(e.onClick,p),onPointerDown:t=>{e.onPointerDown?.(t),u.current=!0},onPointerUp:(0,i.mK)(e.onPointerUp,e=>{u.current||e.currentTarget?.click()}),onKeyDown:(0,i.mK)(e.onKeyDown,e=>{n||e.target!==e.currentTarget||(""===c.searchRef.current||" "!==e.key)&&P.includes(e.key)&&(e.currentTarget.click(),e.preventDefault())})})},"MenuItem")),eo=r.forwardRef(k(function(e,t){let{__scopeMenu:n,disabled:o=!1,textValue:a,...l}=e,d=X(en,n),c=F(n),h=r.useRef(null),u=(0,s.s)(t,h),[p,f]=r.useState(!1),[g,b]=r.useState("");return r.useEffect(()=>{let e=h.current;e&&b((e.textContent??"").trim())},[l.children]),(0,S.jsx)(A.ItemSlot,{scope:n,disabled:o,textValue:a??g,children:(0,S.jsx)(y.q7,{asChild:!0,...c,focusable:!o,children:(0,S.jsx)(m.sG.div,{role:"menuitem","data-highlighted":p?"":void 0,"aria-disabled":o||void 0,"data-disabled":o?"":void 0,...l,ref:u,onPointerMove:(0,i.mK)(e.onPointerMove,eI(e=>{o?d.onItemLeave(e):(d.onItemEnter(e),e.defaultPrevented||e.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:(0,i.mK)(e.onPointerLeave,eI(e=>d.onItemLeave(e))),onFocus:(0,i.mK)(e.onFocus,()=>f(!0)),onBlur:(0,i.mK)(e.onBlur,()=>f(!1))})})})},"MenuItemImpl")),es=r.forwardRef(k(function(e,t){let{checked:n=!1,onCheckedChange:r,...o}=e;return(0,S.jsx)(ec,{scope:e.__scopeMenu,checked:n,children:(0,S.jsx)(ei,{role:"menuitemcheckbox","aria-checked":ev(n)?"mixed":n,...o,ref:t,"data-state":eS(n),onSelect:(0,i.mK)(o.onSelect,()=>r?.(!!ev(n)||!n),{checkForDefaultPrevented:!1})})})},"MenuCheckboxItem")),[ea,el]=D("MenuRadioGroup",{value:void 0,onValueChange:k(()=>{},"onValueChange")}),ed="MenuItemIndicator",[ec,eh]=D(ed,{checked:!1}),eu=r.forwardRef(k(function(e,t){let{__scopeMenu:n,forceMount:r,...i}=e,o=eh(ed,n);return(0,S.jsx)(g.C,{present:r||ev(o.checked)||!0===o.checked,children:(0,S.jsx)(m.sG.span,{...i,ref:t,"data-state":eS(o.checked)})})},"MenuItemIndicator")),ep="MenuSub",[ef,eg]=D(ep),em=k(e=>{let{__scopeMenu:t,children:n,open:i=!1,onOpenChange:o}=e,s=N(ep,t),a=R(t),[l,d]=r.useState(null),[c,h]=r.useState(null),f=(0,x.c)(o);return r.useEffect(()=>(!1===s.open&&f(!1),()=>f(!1)),[s.open,f]),(0,S.jsx)(p.bL,{...a,children:(0,S.jsx)(z,{scope:t,open:i,onOpenChange:f,content:c,onContentChange:h,children:(0,S.jsx)(ef,{scope:t,contentId:(0,u.B)(),triggerId:(0,u.B)(),trigger:l,onTriggerChange:d,children:n})})})},"MenuSub"),ey="MenuSubTrigger",eb=r.forwardRef(k(function(e,t){let n=N(ey,e.__scopeMenu),o=B(ey,e.__scopeMenu),a=eg(ey,e.__scopeMenu),l=X(ey,e.__scopeMenu),d=r.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:h}=l,u={__scopeMenu:e.__scopeMenu},p=r.useCallback(()=>{d.current&&window.clearTimeout(d.current),d.current=null},[]);r.useEffect(()=>p,[p]),r.useEffect(()=>{let e=c.current;return()=>{window.clearTimeout(e),h(null)}},[c,h]);let f=(0,s.s)(t,a.onTriggerChange);return(0,S.jsx)(U,{asChild:!0,...u,children:(0,S.jsx)(eo,{id:a.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":n.open?a.contentId:void 0,"data-state":ew(n.open),...e,ref:f,onClick:t=>{e.onClick?.(t),e.disabled||t.defaultPrevented||(t.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:(0,i.mK)(e.onPointerMove,eI(t=>{l.onItemEnter(t),!t.defaultPrevented&&(e.disabled||n.open||d.current||(l.onPointerGraceIntentChange(null),d.current=window.setTimeout(()=>{n.onOpenChange(!0),p()},100)))})),onPointerLeave:(0,i.mK)(e.onPointerLeave,eI(e=>{p();let t=n.content?.getBoundingClientRect();if(t){let r=n.content?.dataset.side,i="right"===r,o=t[i?"left":"right"],s=t[i?"right":"left"];l.onPointerGraceIntentChange({area:[{x:e.clientX+(i?-5:5),y:e.clientY},{x:o,y:t.top},{x:s,y:t.top},{x:s,y:t.bottom},{x:o,y:t.bottom}],side:r}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.onPointerGraceIntentChange(null),300)}else{if(l.onTriggerLeave(e),e.defaultPrevented)return;l.onPointerGraceIntentChange(null)}})),onKeyDown:(0,i.mK)(e.onKeyDown,t=>{e.disabled||t.target!==t.currentTarget||(""===l.searchRef.current||" "!==t.key)&&I[o.dir].includes(t.key)&&(n.onOpenChange(!0),n.content?.focus(),t.preventDefault())})})})},"MenuSubTrigger")),ex=r.forwardRef(k(function(e,t){let n=V(G,e.__scopeMenu),{forceMount:o=n.forceMount,align:a="start",...l}=e,d=N(G,e.__scopeMenu),c=B(G,e.__scopeMenu),h=eg("MenuSubContent",e.__scopeMenu),u=r.useRef(null),p=(0,s.s)(t,u);return(0,S.jsx)(A.Provider,{scope:e.__scopeMenu,children:(0,S.jsx)(g.C,{present:o||d.open,children:(0,S.jsx)(A.Slot,{scope:e.__scopeMenu,children:(0,S.jsx)(et,{id:h.contentId,"aria-labelledby":h.triggerId,...l,ref:p,align:a,side:"rtl"===c.dir?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:e=>{c.isUsingKeyboardRef.current&&u.current?.focus(),e.preventDefault()},onCloseAutoFocus:e=>e.preventDefault(),onFocusOutside:(0,i.mK)(e.onFocusOutside,e=>{e.target!==h.trigger&&d.onOpenChange(!1)}),onEscapeKeyDown:(0,i.mK)(e.onEscapeKeyDown,e=>{c.onClose(),e.preventDefault()}),onKeyDown:(0,i.mK)(e.onKeyDown,e=>{let t=e.currentTarget.contains(e.target),n=_[c.dir].includes(e.key);t&&n&&(d.onOpenChange(!1),h.trigger?.focus(),e.preventDefault())})})})})})},"MenuSubContent"));function ew(e){return e?"open":"closed"}function ev(e){return"indeterminate"===e}function eS(e){return ev(e)?"indeterminate":e?"checked":"unchecked"}function eC(e){let t=document.activeElement;for(let n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function ek(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function eP(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,o=ek(e,Math.max(i,0));1===r.length&&(o=o.filter(e=>e!==n));let s=o.find(e=>e.toLowerCase().startsWith(r.toLowerCase()));return s!==n?s:void 0}function eT(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,o=t.length-1;e<t.length;o=e++){let s=t[e],a=t[o],l=s.x,d=s.y,c=a.x,h=a.y;d>r!=h>r&&n<(c-l)*(r-d)/(h-d)+l&&(i=!i)}return i}function eE(e,t){return!!t&&eT({x:e.clientX,y:e.clientY},t)}function eI(e){return t=>"mouse"===t.pointerType?e(t):void 0}k(ew,"getOpenState"),k(ev,"isIndeterminate"),k(eS,"getCheckedState"),k(eC,"focusFirst"),k(ek,"wrapArray"),k(eP,"getNextMatch"),k(eT,"isPointInPolygon"),k(eE,"isPointerInGraceArea"),k(eI,"whenMouse");var e_=H,eM=U,eA=Y,ej=J,eO=ei,eD=es,eL=eu,eR=em,eF=eb,ez=ex},69730:(e,t)=>{var n;!function(){"use strict";var r={}.hasOwnProperty;function i(){for(var e="",t=0;t<arguments.length;t++){var n=arguments[t];n&&(e=o(e,function(e){if("string"==typeof e||"number"==typeof e)return e;if("object"!=typeof e)return"";if(Array.isArray(e))return i.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var t="";for(var n in e)r.call(e,n)&&e[n]&&(t=o(t,n));return t}(n)))}return e}function o(e,t){return t?e?e+" "+t:e+t:e}e.exports?(i.default=i,e.exports=i):void 0===(n=(function(){return i}).apply(t,[]))||(e.exports=n)}()},69885:(e,t,n)=>{"use strict";n.d(t,{n:()=>p});var r=n(12115),i=n(47527),o=n(55897),s=n(17347),a=n(95155),l=Object.defineProperty,d=(e,t)=>l(e,"name",{value:t,configurable:!0}),c="focusScope.autoFocusOnMount",h="focusScope.autoFocusOnUnmount",u={bubbles:!1,cancelable:!0},p=r.forwardRef(d(function(e,t){let{loop:n=!1,trapped:l=!1,onMountAutoFocus:p,onUnmountAutoFocus:y,...b}=e,[x,S]=r.useState(null),C=(0,s.c)(p),P=(0,s.c)(y),T=r.useRef(null),E=(0,i.s)(t,S),I=r.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;r.useEffect(()=>{if(l){let e=function(e){if(I.paused||!x)return;let t=e.target;x.contains(t)?T.current=t:w(T.current,{select:!0})},t=function(e){if(I.paused||!x)return;let t=e.relatedTarget;null!==t&&(x.contains(t)||w(T.current,{select:!0}))},n=function(e){if(document.activeElement===document.body)for(let t of e)t.removedNodes.length>0&&w(x)};d(e,"handleFocusIn"),d(t,"handleFocusOut"),d(n,"handleMutations"),document.addEventListener("focusin",e),document.addEventListener("focusout",t);let r=new MutationObserver(n);return x&&r.observe(x,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",e),document.removeEventListener("focusout",t),r.disconnect()}}},[l,x,I.paused]),r.useEffect(()=>{if(x){v.add(I);let e=document.activeElement;if(!x.contains(e)){let t=new CustomEvent(c,u);x.addEventListener(c,C),x.dispatchEvent(t),t.defaultPrevented||(f(k(m(x)),{select:!0}),document.activeElement===e&&w(x))}return()=>{x.removeEventListener(c,C),setTimeout(()=>{let t=new CustomEvent(h,u);x.addEventListener(h,P),x.dispatchEvent(t),t.defaultPrevented||w(e??document.body,{select:!0}),x.removeEventListener(h,P),v.remove(I)},0)}}},[x,C,P,I]);let _=r.useCallback(e=>{if(!n&&!l||I.paused)return;let t="Tab"===e.key&&!e.altKey&&!e.ctrlKey&&!e.metaKey,r=document.activeElement;if(t&&r){let t=e.currentTarget,[i,o]=g(t);i&&o?e.shiftKey||r!==o?e.shiftKey&&r===i&&(e.preventDefault(),n&&w(o,{select:!0})):(e.preventDefault(),n&&w(i,{select:!0})):r===t&&e.preventDefault()}},[n,l,I.paused]);return(0,a.jsx)(o.sG.div,{tabIndex:-1,...b,ref:E,onKeyDown:_})},"FocusScope"));function f(e,{select:t=!1}={}){let n=document.activeElement;for(let r of e)if(w(r,{select:t}),document.activeElement!==n)return}function g(e){let t=m(e);return[y(t,e),y(t.reverse(),e)]}function m(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:d(e=>{let t="INPUT"===e.tagName&&"hidden"===e.type;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;n.nextNode();)t.push(n.currentNode);return t}function y(e,t){let n="function"==typeof t.checkVisibility&&t.checkVisibility({checkVisibilityCSS:!0});for(let r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):b(r,{upTo:t})))return r}function b(e,{upTo:t}){if("hidden"===getComputedStyle(e).visibility)return!0;for(;e&&(void 0===t||e!==t);){if("none"===getComputedStyle(e).display)return!0;e=e.parentElement}return!1}function x(e){return e instanceof HTMLInputElement&&"select"in e}function w(e,{select:t=!1}={}){if(e&&e.focus){let n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&x(e)&&t&&e.select()}}d(f,"focusFirst"),d(g,"getTabbableEdges"),d(m,"getTabbableCandidates"),d(y,"findVisible"),d(b,"isHidden"),d(x,"isSelectableInput"),d(w,"focus");var v=S();function S(){let e=[];return{add(t){let n=e[0];t!==n&&n?.pause(),(e=C(e,t)).unshift(t)},remove(t){e=C(e,t),e[0]?.resume()}}}function C(e,t){let n=[...e],r=n.indexOf(t);return -1!==r&&n.splice(r,1),n}function k(e){return e.filter(e=>"A"!==e.tagName)}d(S,"createFocusScopesStack"),d(C,"arrayRemove"),d(k,"removeLinks")},70379:(e,t,n)=>{"use strict";n.d(t,{mK:()=>s});var r=Object.defineProperty,i=(e,t)=>r(e,"name",{value:t,configurable:!0}),o=!!("u">typeof window&&window.document&&window.document.createElement);function s(e,t,{checkForDefaultPrevented:n=!0}={}){return i(function(r){if(e?.(r),!1===n||!r||!r.defaultPrevented)return t?.(r)},"handleEvent")}function a(e){if(!o)throw Error("Cannot access document outside of the DOM");return e?.ownerDocument??document}function l(e){return"IFRAME"===e.tagName}i(s,"composeEventHandlers"),i(function(e){if(!o)throw Error("Cannot access window outside of the DOM");return e?.ownerDocument?.defaultView??window},"getOwnerWindow"),i(a,"getOwnerDocument"),i(function e(t,n=!1){let{activeElement:r}=a(t);if(!r?.nodeName)return null;if(l(r)&&r.contentDocument)return e(r.contentDocument.body,n);if(n){let e=r.getAttribute("aria-activedescendant");if(e){let t=a(r).getElementById(e);if(t)return t}}return r},"getActiveElement"),i(l,"isFrame")},71136:(e,t,n)=>{"use strict";function r(e,t,n={}){let{closed:i=!1,snap:o=1,start:s="outset",end:a="outset",lengthRatio:l=2,style:d="dashed",forceSolid:c=!1}=n,h=0,u=0,p=1,f=0,g=0;if(c||"none"===d)return{strokeDasharray:"none",strokeDashoffset:"none"};switch(d){case"dashed":p=1,h=Math.min(t*l,e/4);break;case"dotted":h=t/(p=100);break;default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return i||("outset"===s?(e+=h/2,g+=h/2):"skip"===s&&(e-=h,g-=h),"outset"===a?e+=h/2:"skip"===a&&(e-=h)),u=Math.floor(e/h/(2*p)),(u-=u%o)<3&&"dashed"===d?e/t<4?(h=e,u=1,f=0):(h=1/3*e,f=1/3*e):(h=e/u/(2*p),i?(g=h/2,f=(e-u*h)/u):f=(e-u*h)/Math.max(1,u-1)),{strokeDasharray:[h,f].join(" "),strokeDashoffset:g.toString()}}n.d(t,{E:()=>r})},71645:(e,t,n)=>{var r="Expected a function",i=0/0,o=/^\s+|\s+$/g,s=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,l=/^0o[0-7]+$/i,d=parseInt,c="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,h="object"==typeof self&&self&&self.Object===Object&&self,u=c||h||Function("return this")(),p=Object.prototype.toString,f=Math.max,g=Math.min,m=function(){return u.Date.now()};function y(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function b(e){if("number"==typeof e)return e;if("symbol"==typeof(t=e)||t&&"object"==typeof t&&"[object Symbol]"==p.call(t))return i;if(y(e)){var t,n="function"==typeof e.valueOf?e.valueOf():e;e=y(n)?n+"":n}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(o,"");var r=a.test(e);return r||l.test(e)?d(e.slice(2),r?2:8):s.test(e)?i:+e}e.exports=function(e,t,n){var i=!0,o=!0;if("function"!=typeof e)throw TypeError(r);return y(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),function(e,t,n){var i,o,s,a,l,d,c=0,h=!1,u=!1,p=!0;if("function"!=typeof e)throw TypeError(r);function x(t){var n=i,r=o;return i=o=void 0,c=t,a=e.apply(r,n)}function w(e){var n=e-d,r=e-c;return void 0===d||n>=t||n<0||u&&r>=s}function v(){var e,n,r,i=m();if(w(i))return S(i);l=setTimeout(v,(e=i-d,n=i-c,r=t-e,u?g(r,s-n):r))}function S(e){return(l=void 0,p&&i)?x(e):(i=o=void 0,a)}function C(){var e,n=m(),r=w(n);if(i=arguments,o=this,d=n,r){if(void 0===l)return c=e=d,l=setTimeout(v,t),h?x(e):a;if(u)return l=setTimeout(v,t),x(d)}return void 0===l&&(l=setTimeout(v,t)),a}return t=b(t)||0,y(n)&&(h=!!n.leading,s=(u="maxWait"in n)?f(b(n.maxWait)||0,t):s,p="trailing"in n?!!n.trailing:p),C.cancel=function(){void 0!==l&&clearTimeout(l),c=0,i=d=o=l=void 0},C.flush=function(){return void 0===l?a:S(m())},C}(e,t,{leading:i,maxWait:t,trailing:o})}},73352:(e,t,n)=>{"use strict";n.d(t,{JE:()=>h,Ls:()=>a,Xh:()=>l,ni:()=>d,oX:()=>s});var r=n(95155),i=n(24167),o=n(12115);function s(e,t){return d(`${e}_${t}`)}function a(e){return d(`${(0,o.useId)()}${e??""}`)}function l(e){let t=(0,i.Z1)((0,o.useContext)(c));return d(`${t}_${e}`)}function d(e){return e.replace(/:/g,"_")}let c=(0,o.createContext)(null);function h({children:e}){let t=a();return(0,r.jsx)(c.Provider,{value:t,children:e})}},73578:(e,t,n)=>{"use strict";n.d(t,{y:()=>o});var r=n(24167),i=n(46195);class o{constructor(e){this.editor=e}editor;sessions=new Map;startSession(e={}){let t=e.id??(0,r.NF)(),n={id:t,items:[],state:"active",options:{selfConsume:e.selfConsume??!0,idleTimeoutMs:e.idleTimeoutMs??0,fadeMode:e.fadeMode??"individual",fadeEasing:e.fadeEasing??("grouped"===e.fadeMode?"ease-in":"linear"),fadeDurationMs:e.fadeDurationMs??this.editor.options.laserFadeoutMs},fadeElapsed:0,totalPointsAtFadeStart:0};return this.sessions.set(t,n),n.options.idleTimeoutMs>0&&this.resetIdleTimeout(n),t}addScribbleToSession(e,t,n=(0,r.NF)()){let i=this.sessions.get(e);if(!i)throw Error(`Session ${e} not found`);let o={id:n,scribble:{id:n,size:20,color:"accent",opacity:.8,delay:0,points:[],shrink:.1,taper:!0,...t,state:"starting"},timeoutMs:0,delayRemaining:t.delay??0,prev:null,next:null};return i.items.push(o),i.options.idleTimeoutMs>0&&this.resetIdleTimeout(i),o}addPointToSession(e,t,n,r,o=.5){let s=this.sessions.get(e);if(!s)throw Error(`Session ${e} not found`);let a=s.items.find(e=>e.id===t);if(!a)throw Error(`Scribble ${t} not found in session ${e}`);let l={x:n,y:r,z:o};return(!a.prev||i.l.Dist(a.prev,l)>=1)&&(a.next=l),s.options.idleTimeoutMs>0&&this.resetIdleTimeout(s),a}extendSession(e){let t=this.sessions.get(e);t&&t.options.idleTimeoutMs>0&&this.resetIdleTimeout(t)}stopSession(e){let t=this.sessions.get(e);if(t&&"active"===t.state)if(this.clearIdleTimeout(t),t.state="stopping","grouped"===t.options.fadeMode)for(let e of(t.totalPointsAtFadeStart=t.items.reduce((e,t)=>e+t.scribble.points.length,0),t.fadeElapsed=0,t.items))e.scribble.state="stopping";else for(let e of t.items)e.delayRemaining=Math.min(e.delayRemaining,200),e.scribble.state="stopping"}clearSession(e){let t=this.sessions.get(e);if(t){for(let e of(this.clearIdleTimeout(t),t.items))e.scribble.points.length=0;t.state="complete"}}isSessionActive(e){let t=this.sessions.get(e);return t?.state==="active"}addScribble(e,t=(0,r.NF)()){let n=this.startSession();return this.addScribbleToSession(n,e,t)}addPoint(e,t,n,r=.5){for(let o of this.sessions.values()){let s=o.items.find(t=>t.id===e);if(s){let e={x:t,y:n,z:r};return(!s.prev||i.l.Dist(s.prev,e)>=1)&&(s.next=e),o.options.idleTimeoutMs>0&&this.resetIdleTimeout(o),s}}throw Error(`Scribble with id ${e} not found`)}complete(e){for(let t of this.sessions.values()){let n=t.items.find(t=>t.id===e);if(n)return("starting"===n.scribble.state||"active"===n.scribble.state)&&(n.scribble.state="complete"),n}throw Error(`Scribble with id ${e} not found`)}stop(e){for(let t of this.sessions.values()){let n=t.items.find(t=>t.id===e);if(n)return n.delayRemaining=Math.min(n.delayRemaining,200),n.scribble.state="stopping",n}throw Error(`Scribble with id ${e} not found`)}reset(){for(let e of this.sessions.values())this.clearIdleTimeout(e);this.sessions.clear(),this.editor.updateInstanceState({scribbles:[]})}tick(e){let t=this.editor.getInstanceState().scribbles;(0!==this.sessions.size||0!==t.length)&&this.editor.run(()=>{for(let t of this.sessions.values())this.tickSession(t,e);for(let[e,t]of this.sessions)"complete"===t.state&&(this.clearIdleTimeout(t),this.sessions.delete(e));let t=[];for(let e of this.sessions.values())for(let n of e.items)n.scribble.points.length>0&&t.push({...n.scribble,points:[...n.scribble.points]});this.editor.updateInstanceState({scribbles:t})})}resetIdleTimeout(e){this.clearIdleTimeout(e),e.idleTimeoutHandle=this.editor.timers.setTimeout(()=>{this.stopSession(e.id)},e.options.idleTimeoutMs)}clearIdleTimeout(e){void 0!==e.idleTimeoutHandle&&(clearTimeout(e.idleTimeoutHandle),e.idleTimeoutHandle=void 0)}tickSession(e,t){"complete"===e.state||("stopping"===e.state&&"grouped"===e.options.fadeMode?this.tickGroupedFade(e,t):this.tickSessionItems(e,t),e.items.some(e=>e.scribble.points.length>0)||"stopping"!==e.state&&0!==e.items.length||(e.state="complete"))}tickSessionItems(e,t){for(let n of e.items)e.options.selfConsume||"stopping"===e.state||"stopping"===n.scribble.state?this.tickSelfConsumingItem(n,t):this.tickPersistentItem(n);if("individual"===e.options.fadeMode)for(let t=e.items.length-1;t>=0;t--)0===e.items[t].scribble.points.length&&e.items.splice(t,1)}tickPersistentItem(e){let{scribble:t}=e;if("starting"===t.state){let{next:n,prev:r}=e;n&&n!==r&&(e.prev=n,t.points.push(n)),t.points.length>8&&(t.state="active");return}if("active"===t.state){let{next:n,prev:r}=e;n&&n!==r&&(e.prev=n,t.points.push(n))}}tickSelfConsumingItem(e,t){let{scribble:n}=e;if("starting"===n.state){let{next:t,prev:r}=e;t&&t!==r&&(e.prev=t,n.points.push(t)),n.points.length>8&&(n.state="active");return}e.delayRemaining>0&&(e.delayRemaining=Math.max(0,e.delayRemaining-t)),e.timeoutMs+=t,e.timeoutMs>=16&&(e.timeoutMs=0);let{delayRemaining:r,timeoutMs:i,prev:o,next:s}=e;switch(n.state){case"active":s&&s!==o?(e.prev=s,n.points.push(s),0===r&&n.points.length>8&&n.points.shift()):0===i&&(n.points.length>1?n.points.shift():e.delayRemaining=n.delay);break;case"stopping":if(0===r&&0===i){if(n.points.length<=1){n.points.length=0;return}n.shrink&&(n.size=Math.max(1,n.size*(1-n.shrink))),n.points.shift()}}}tickGroupedFade(e,t){e.fadeElapsed+=t;let n=0;for(let t of e.items)n+=t.scribble.points.length;if(0===n)return;if(e.fadeElapsed>=e.options.fadeDurationMs){for(let t of e.items)t.scribble.points.length=0;return}let r=e.fadeElapsed/e.options.fadeDurationMs,i=Math.max(1,Math.floor(("ease-in"===e.options.fadeEasing?r*r:r)*e.totalPointsAtFadeStart)-(e.totalPointsAtFadeStart-n)),o=0,s=0;for(;o<i&&s<e.items.length;){let t=e.items[s];t.scribble.points.length>0?(t.scribble.points.shift(),o++):s++}}}},75567:(e,t,n)=>{"use strict";n.d(t,{I:()=>l});var r=n(83102),i=n(24167),o=n(59830),s=n(46195),a=n(27164);class l extends a.vq{children=[];ignoredChildren=[];constructor(e){super({...e,isClosed:!0,isFilled:!1});const t=e=>{for(let n of e)n instanceof l?t(n.children):n.ignore?this.ignoredChildren.push(n):this.children.push(n)};if(t(e.children),0===this.children.length)throw Error("Group2d must have at least one child")}getVertices(e){return this.isExcludedByFilter(e)?[]:this.children.filter(t=>!t.isExcludedByFilter(e)).flatMap(t=>t.getVertices(e))}nearestPoint(e,t){let n,r,i,o=1/0,{children:a}=this;if(0===a.length)throw Error("no children");for(let l of a)!l.isExcludedByFilter(t)&&(r=l.nearestPoint(e,t),(i=s.l.Dist2(r,e))<o&&(o=i,n=r));if(!n)throw Error("nearest point not found");return n}distanceToPoint(e,t=!1,n){let r=1/0;for(let i of this.children){if(i.isExcludedByFilter(n))continue;let o=i.distanceToPoint(e,t,n);o<r&&(r=o)}return r}hitTestPoint(e,t,n,r=a.MI.EXCLUDE_LABELS){return!!this.children.filter(e=>!e.isExcludedByFilter(r)).find(r=>r.hitTestPoint(e,t,n))}hitTestLineSegment(e,t,n,r=a.MI.EXCLUDE_LABELS){return!!this.children.filter(e=>!e.isExcludedByFilter(r)).find(r=>r.hitTestLineSegment(e,t,n))}intersectLineSegment(e,t,n){return this.children.flatMap(i=>i.isExcludedByFilter(n)?r.Ml:i.intersectLineSegment(e,t,n))}intersectCircle(e,t,n){return this.children.flatMap(i=>i.isExcludedByFilter(n)?r.Ml:i.intersectCircle(e,t,n))}getBoundsVertices(){return this.excludeFromShapeBounds?[]:this.children.flatMap(e=>e.getBoundsVertices())}intersectPolygon(e,t){return this.children.flatMap(n=>n.isExcludedByFilter(t)?r.Ml:n.intersectPolygon(e,t))}intersectPolyline(e,t){return this.children.flatMap(n=>n.isExcludedByFilter(t)?r.Ml:n.intersectPolyline(e,t))}interpolateAlongEdge(e,t){let n=e*this.getLength(t),r=0;for(let e of this.children){if(e.isExcludedByFilter(t))continue;let o=r+e.length;if(o>=n)return e.interpolateAlongEdge((0,i.Fg)(r,o,n),t);r=o}return this.children[this.children.length-1].interpolateAlongEdge(1,t)}uninterpolateAlongEdge(e,t){let n=this.getLength(t),r=null,o=1/0,s=0;for(let n of this.children){if(n.isExcludedByFilter(t))continue;let i=s+n.getLength(t),a=n.distanceToPoint(e,!1,t);a<o&&(o=a,r={startLength:s,endLength:i,child:n}),s=i}(0,i.vA)(r);let a=r.child.uninterpolateAlongEdge(e,t);return(0,i.Cc)(r.startLength,r.endLength,a)/n}transform(e){return new l({children:this.children.map(t=>t.transform(e)),isLabel:this.isLabel,debugColor:this.debugColor,ignore:this.ignore})}getArea(){return this.children[0].area}toSimpleSvgPath(){let e="";for(let t of this.children)e+=t.toSimpleSvgPath();let t=o.az.FromPoints(this.boundsVertices).corners;for(let n=0,r=t.length;n<r;n++){let i=t[n],o=t[(n-1+r)%r],s=i.dist(o),a=t[(n+1)%r],l=i.dist(a),d=i.clone().lrp(o,4/s),c=i.clone().lrp(a,4/l);e+=`M${d.x},${d.y} L${i.x},${i.y} L${c.x},${c.y} `}return e}getLength(e){let t=0;for(let n of this.children)n.isExcludedByFilter(e)||(t+=n.length);return t}getSvgPathData(){return this.children.map((e,t)=>e.isLabel?"":e.getSvgPathData(0===t)).join(" ")}overlapsPolygon(e){return this.children.some(t=>t.overlapsPolygon(e))}}},76094:(e,t,n)=>{"use strict";n.d(t,{N:()=>c});var r=n(12115),i=n(68599),o=n(47527),s=n(42442),a=n(95155),l=Object.defineProperty,d=(e,t)=>l(e,"name",{value:t,configurable:!0});function c(e){let t=e+"CollectionProvider",[n,l]=(0,i.A)(t),[c,h]=n(t,{collectionRef:{current:null},itemMap:new Map}),u=d(e=>{let{scope:t,children:n}=e,i=r.useRef(null),o=r.useRef(new Map).current;return(0,a.jsx)(c,{scope:t,itemMap:o,collectionRef:i,children:n})},"CollectionProvider");u.displayName=t;let p=e+"CollectionSlot",f=(0,s.TL)(p),g=r.forwardRef((e,t)=>{let{scope:n,children:r}=e,i=h(p,n),s=(0,o.s)(t,i.collectionRef);return(0,a.jsx)(f,{ref:s,children:r})});g.displayName=p;let m=e+"CollectionItemSlot",y="data-radix-collection-item",b=(0,s.TL)(m),x=r.forwardRef((e,t)=>{let{scope:n,children:i,...s}=e,l=r.useRef(null),d=(0,o.s)(t,l),c=h(m,n);return r.useEffect(()=>(c.itemMap.set(l,{ref:l,...s}),()=>void c.itemMap.delete(l))),(0,a.jsx)(b,{...{[y]:""},ref:d,children:i})});function w(t){let n=h(e+"CollectionConsumer",t);return r.useCallback(()=>{let e=n.collectionRef.current;if(!e)return[];let t=Array.from(e.querySelectorAll(`[${y}]`));return Array.from(n.itemMap.values()).sort((e,n)=>t.indexOf(e.ref.current)-t.indexOf(n.ref.current))},[n.collectionRef,n.itemMap])}return x.displayName=m,d(w,"useCollection"),[{Provider:u,Slot:g,ItemSlot:x},w,l]}d(c,"createCollection");var h=new WeakMap,u=class e extends Map{static{d(this,"OrderedDict")}#e;constructor(e){super(e),this.#e=[...super.keys()],h.set(this,!0)}set(e,t){return h.get(this)&&(this.has(e)?this.#e[this.#e.indexOf(e)]=e:this.#e.push(e)),super.set(e,t),this}insert(e,t,n){let r,i=this.has(t),o=this.#e.length,s=g(e),a=s>=0?s:o+s,l=a<0||a>=o?-1:a;if(l===this.size||i&&l===this.size-1||-1===l)return this.set(t,n),this;let d=this.size+ +!i;s<0&&a++;let c=[...this.#e],h=!1;for(let e=a;e<d;e++)if(a===e){let o=c[e];c[e]===t&&(o=c[e+1]),i&&this.delete(t),r=this.get(o),this.set(t,n)}else{h||c[e-1]!==t||(h=!0);let n=c[h?e:e-1],i=r;r=this.get(n),this.delete(n),this.set(n,i)}return this}with(t,n,r){let i=new e(this);return i.insert(t,n,r),i}before(e){let t=this.#e.indexOf(e)-1;if(!(t<0))return this.entryAt(t)}setBefore(e,t,n){let r=this.#e.indexOf(e);return -1===r?this:this.insert(r,t,n)}after(e){let t=this.#e.indexOf(e);if(-1!==(t=-1===t||t===this.size-1?-1:t+1))return this.entryAt(t)}setAfter(e,t,n){let r=this.#e.indexOf(e);return -1===r?this:this.insert(r+1,t,n)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return this.#e=[],super.clear()}delete(e){let t=super.delete(e);return t&&this.#e.splice(this.#e.indexOf(e),1),t}deleteAt(e){let t=this.keyAt(e);return void 0!==t&&this.delete(t)}at(e){let t=p(this.#e,e);if(void 0!==t)return this.get(t)}entryAt(e){let t=p(this.#e,e);if(void 0!==t)return[t,this.get(t)]}indexOf(e){return this.#e.indexOf(e)}keyAt(e){return p(this.#e,e)}from(e,t){let n=this.indexOf(e);if(-1===n)return;let r=n+t;return r<0&&(r=0),r>=this.size&&(r=this.size-1),this.at(r)}keyFrom(e,t){let n=this.indexOf(e);if(-1===n)return;let r=n+t;return r<0&&(r=0),r>=this.size&&(r=this.size-1),this.keyAt(r)}find(e,t){let n=0;for(let r of this){if(Reflect.apply(e,t,[r,n,this]))return r;n++}}findIndex(e,t){let n=0;for(let r of this){if(Reflect.apply(e,t,[r,n,this]))return n;n++}return -1}filter(t,n){let r=[],i=0;for(let e of this)Reflect.apply(t,n,[e,i,this])&&r.push(e),i++;return new e(r)}map(t,n){let r=[],i=0;for(let e of this)r.push([e[0],Reflect.apply(t,n,[e,i,this])]),i++;return new e(r)}reduce(...e){let[t,n]=e,r=0,i=n??this.at(0);for(let n of this)i=0===r&&1===e.length?n:Reflect.apply(t,this,[i,n,r,this]),r++;return i}reduceRight(...e){let[t,n]=e,r=n??this.at(-1);for(let n=this.size-1;n>=0;n--){let i=this.at(n);r=n===this.size-1&&1===e.length?i:Reflect.apply(t,this,[r,i,n,this])}return r}toSorted(t){return new e([...this.entries()].sort(t))}toReversed(){let t=new e;for(let e=this.size-1;e>=0;e--){let n=this.keyAt(e),r=this.get(n);t.set(n,r)}return t}toSpliced(...t){let n=[...this.entries()];return n.splice(...t),new e(n)}slice(t,n){let r=new e,i=this.size-1;if(void 0===t)return r;t<0&&(t+=this.size),void 0!==n&&n>0&&(i=n-1);for(let e=t;e<=i;e++){let t=this.keyAt(e),n=this.get(t);r.set(t,n)}return r}every(e,t){let n=0;for(let r of this){if(!Reflect.apply(e,t,[r,n,this]))return!1;n++}return!0}some(e,t){let n=0;for(let r of this){if(Reflect.apply(e,t,[r,n,this]))return!0;n++}return!1}};function p(e,t){if("at"in Array.prototype)return Array.prototype.at.call(e,t);let n=f(e,t);return -1===n?void 0:e[n]}function f(e,t){let n=e.length,r=g(t),i=r>=0?r:n+r;return i<0||i>=n?-1:i}function g(e){return e!=e||0===e?0:Math.trunc(e)}function m(e,t){if(e===t)return!0;if("object"!=typeof e||"object"!=typeof t||null==e||null==t)return!1;let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||e[r]!==t[r])return!1;return!0}function y(e,t){return!!(t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}function b(e,t){return e[1].element&&t[1].element?y(e[1].element,t[1].element)?-1:1:0}function x(e){return new MutationObserver(t=>{for(let n of t)if("childList"===n.type)return void e()})}d(p,"at"),d(f,"toSafeIndex"),d(g,"toSafeInteger"),d(function(e){let t=e+"CollectionProvider",[n,l]=(0,i.A)(t),[c,h]=n(t,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new u,setItemMap:d(()=>void 0,"setItemMap")}),p=d(({state:e,...t})=>e?(0,a.jsx)(g,{...t,state:e}):(0,a.jsx)(f,{...t}),"CollectionProvider");p.displayName=t;let f=d(e=>{let t=P();return(0,a.jsx)(g,{...e,state:t})},"CollectionInit");f.displayName=t+"Init";let g=d(e=>{let{scope:t,children:n,state:i}=e,s=r.useRef(null),[l,d]=r.useState(null),h=(0,o.s)(s,d),[u,p]=i;return r.useEffect(()=>{if(!l)return;let e=x(()=>{});return e.observe(l,{childList:!0,subtree:!0}),()=>{e.disconnect()}},[l]),(0,a.jsx)(c,{scope:t,itemMap:u,setItemMap:p,collectionRef:h,collectionRefObject:s,collectionElement:l,children:n})},"CollectionProviderImpl");g.displayName=t+"Impl";let y=e+"CollectionSlot",w=(0,s.TL)(y),v=r.forwardRef((e,t)=>{let{scope:n,children:r}=e,i=h(y,n),s=(0,o.s)(t,i.collectionRef);return(0,a.jsx)(w,{ref:s,children:r})});v.displayName=y;let S=e+"CollectionItemSlot",C=(0,s.TL)(S),k=r.forwardRef((e,t)=>{let{scope:n,children:i,...s}=e,l=r.useRef(null),[d,c]=r.useState(null),p=(0,o.s)(t,l,c),{setItemMap:f}=h(S,n),g=r.useRef(s);m(g.current,s)||(g.current=s);let y=g.current;return r.useEffect(()=>(f(e=>d?e.has(d)?e.set(d,{...y,element:d}).toSorted(b):(e.set(d,{...y,element:d}),e.toSorted(b)):e),()=>{f(e=>d&&e.has(d)?(e.delete(d),new u(e)):e)}),[d,y,f]),(0,a.jsx)(C,{"data-radix-collection-item":"",ref:p,children:i})});function P(){return r.useState(new u)}function T(t){let{itemMap:n}=h(e+"CollectionConsumer",t);return n}return k.displayName=S,d(P,"useInitCollection"),d(T,"useCollection"),[{Provider:p,Slot:v,ItemSlot:k},{createCollectionScope:l,useCollection:T,useInitCollection:P}]},"createCollection"),d(m,"shallowEqual"),d(y,"isElementPreceding"),d(b,"sortByDocumentPosition"),d(x,"getChildListObserver")},76865:(e,t,n)=>{"use strict";n.d(t,{$t:()=>C,LN:()=>s,U3:()=>c,hs:()=>E,i5:()=>f,k_:()=>k,nh:()=>u});var r=n(27050),i=n(8242);let o=Object.create(null);class s{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new a(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=r.Ji.empty){let n=t.content.lastChild,i=null;for(let e=0;e<t.openEnd;e++)i=n,n=n.lastChild;let o=e.steps.length,s=this.ranges;for(let a=0;a<s.length;a++){let{$from:l,$to:d}=s[a],c=e.mapping.slice(o);e.replaceRange(c.map(l.pos),c.map(d.pos),a?r.Ji.empty:t),0==a&&y(e,o,(n?n.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:o,$to:s}=r[i],a=e.mapping.slice(n),l=a.map(o.pos),d=a.map(s.pos);i?e.deleteRange(l,d):(e.replaceRangeWith(l,d,t),y(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new c(e):m(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let r=e.depth-1;r>=0;r--){let i=t<0?m(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):m(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new f(e.node(0))}static atStart(e){return m(e,e,0,0,1)||new f(e)}static atEnd(e){return m(e,e,e.content.size,e.childCount,-1)||new f(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError("Invalid input for Selection.fromJSON");let n=o[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in o)throw RangeError("Duplicate use of selection JSON ID "+e);return o[e]=t,t.prototype.jsonID=e,t}getBookmark(){return c.between(this.$anchor,this.$head).getBookmark()}}s.prototype.visible=!0;class a{constructor(e,t){this.$from=e,this.$to=t}}let l=!1;function d(e){l||e.parent.inlineContent||(l=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class c extends s{constructor(e,t=e){d(e),d(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return s.near(n);let r=e.resolve(t.map(this.anchor));return new c(r.parent.inlineContent?r:n,n)}replace(e,t=r.Ji.empty){if(super.replace(e,t),t==r.Ji.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof c&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new h(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if("number"!=typeof t.anchor||"number"!=typeof t.head)throw RangeError("Invalid input for TextSelection.fromJSON");return new c(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(e,t,n){let r=e.pos-t.pos;if((!n||r)&&(n=r>=0?1:-1),!t.parent.inlineContent){let e=s.findFrom(t,n,!0)||s.findFrom(t,-n,!0);if(!e)return s.near(t,n);t=e.$head}return e.parent.inlineContent||(0==r?e=t:(e=(s.findFrom(e,-n,!0)||s.findFrom(e,n,!0)).$anchor).pos<t.pos!=r<0&&(e=t)),new c(e,t)}}s.jsonID("text",c);class h{constructor(e,t){this.anchor=e,this.head=t}map(e){return new h(e.map(this.anchor),e.map(this.head))}resolve(e){return c.between(e.resolve(this.anchor),e.resolve(this.head))}}class u extends s{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:r}=t.mapResult(this.anchor),i=e.resolve(r);return n?s.near(i):new u(i)}content(){return new r.Ji(r.FK.from(this.node),0,0)}eq(e){return e instanceof u&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new p(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw RangeError("Invalid input for NodeSelection.fromJSON");return new u(e.resolve(t.anchor))}static create(e,t){return new u(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}u.prototype.visible=!1,s.jsonID("node",u);class p{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new h(n,n):new p(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&u.isSelectable(n)?new u(t):s.near(t)}}class f extends s{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=r.Ji.empty){if(t==r.Ji.empty){e.delete(0,e.doc.content.size);let t=s.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new f(e)}map(e){return new f(e)}eq(e){return e instanceof f}getBookmark(){return g}}s.jsonID("all",f);let g={map(){return this},resolve:e=>new f(e)};function m(e,t,n,r,i,o=!1){if(t.inlineContent)return c.create(e,n);for(let s=r-(i>0?0:1);i>0?s<t.childCount:s>=0;s+=i){let r=t.child(s);if(r.isAtom){if(!o&&u.isSelectable(r))return u.create(e,n-(i<0?r.nodeSize:0))}else{let t=m(e,r,n+i,i<0?r.childCount:0,i,o);if(t)return t}n+=r.nodeSize*i}return null}function y(e,t,n){let r,o=e.steps.length-1;if(o<t)return;let a=e.steps[o];(a instanceof i.Ln||a instanceof i.Wg)&&(e.mapping.maps[o].forEach((e,t,n,i)=>{null==r&&(r=i)}),e.setSelection(s.near(e.doc.resolve(r),n)))}class b extends i.dL{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(1|this.updated)&-3,this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=2,this}ensureMarks(e){return r.CU.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(2&this.updated)>0}addStep(e,t){super.addStep(e,t),this.updated=-3&this.updated,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||r.CU.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(null==n&&(n=t),!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),this.selection.empty||this.selection.to!=t+e.length||this.setSelection(s.near(this.selection.$to)),this}}setMeta(e,t){return this.meta["string"==typeof e?e:e.key]=t,this}getMeta(e){return this.meta["string"==typeof e?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}}function x(e,t){return t&&e?e.bind(t):e}class w{constructor(e,t,n){this.name=e,this.init=x(t.init,n),this.apply=x(t.apply,n)}}let v=[new w("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new w("selection",{init:(e,t)=>e.selection||s.atStart(t.doc),apply:e=>e.selection}),new w("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new w("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class S{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=v.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError("Adding different instances of a keyed plugin ("+e.key+")");this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new w(e.key,e.spec.state,e))})}}class C{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let t=this.config.plugins[n];if(t.spec.filterTransaction&&!t.spec.filterTransaction.call(t,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let i=!1;for(let o=0;o<this.config.plugins.length;o++){let s=this.config.plugins[o];if(s.spec.appendTransaction){let a=r?r[o].n:0,l=r?r[o].state:this,d=a<t.length&&s.spec.appendTransaction.call(s,a?t.slice(a):t,l,n);if(d&&n.filterTransaction(d,o)){if(d.setMeta("appendedTransaction",e),!r){r=[];for(let e=0;e<this.config.plugins.length;e++)r.push(e<o?{state:n,n:t.length}:{state:this,n:0})}t.push(d),n=n.applyInner(d),i=!0}r&&(r[o]={state:n,n:t.length})}}if(!i)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw RangeError("Applying a mismatched transaction");let t=new C(this.config),n=this.config.fields;for(let r=0;r<n.length;r++){let i=n[r];t[i.name]=i.apply(e,this[i.name],this,t)}return t}get tr(){return new b(this)}static create(e){let t=new S(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new C(t);for(let r=0;r<t.fields.length;r++)n[t.fields[r].name]=t.fields[r].init(e,n);return n}reconfigure(e){let t=new S(this.schema,e.plugins),n=t.fields,r=new C(t);for(let t=0;t<n.length;t++){let i=n[t].name;r[i]=this.hasOwnProperty(i)?this[i]:n[t].init(e,r)}return r}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(e=>e.toJSON())),e&&"object"==typeof e)for(let n in e){if("doc"==n||"selection"==n)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,n){if(!t)throw RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw RangeError("Required config field 'schema' missing");let i=new S(e.schema,e.plugins),o=new C(i);return i.fields.forEach(i=>{if("doc"==i.name)o.doc=r.bP.fromJSON(e.schema,t.doc);else if("selection"==i.name)o.selection=s.fromJSON(o.doc,t.selection);else if("storedMarks"==i.name)t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let r in n){let s=n[r],a=s.spec.state;if(s.key==i.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,r)){o[i.name]=a.fromJSON.call(s,e,t[r],o);return}}o[i.name]=i.init(e,o)}}),o}}class k{constructor(e){this.spec=e,this.props={},e.props&&function e(t,n,r){for(let i in t){let o=t[i];o instanceof Function?o=o.bind(n):"handleDOMEvents"==i&&(o=e(o,n,{})),r[i]=o}return r}(e.props,this,this.props),this.key=e.key?e.key.key:T("plugin")}getState(e){return e[this.key]}}let P=Object.create(null);function T(e){return e in P?e+"$"+ ++P[e]:(P[e]=0,e+"$")}class E{constructor(e="key"){this.key=T(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}},78663:(e,t,n)=>{"use strict";n.d(t,{Y:()=>a});var r=n(83102),i=n(24167),o=n(11421),s=n(16398);class a{constructor(e,t){this.editor=e;const{id:n,children:o,initial:s,isLockable:a,useCoalescedEvents:l}=this.constructor;this.id=n,this._isActive=(0,r.eU)("toolIsActive"+this.id,!1),this._current=(0,r.eU)("toolState"+this.id,void 0),this._path=(0,r.EW)("toolPath"+this.id,()=>{let e=this.getCurrent();return this.id+(e?`.${e.getPath()}`:"")}),this.parent=t??{},t?o&&s?(this.type="branch",this.initial=s,this.children=Object.fromEntries(o().map(e=>[e.id,new e(this.editor,this)])),this._current.set(this.children[this.initial])):this.type="leaf":(this.type="root",o&&s&&(this.initial=s,this.children=Object.fromEntries(o().map(e=>[e.id,new e(this.editor,this)])),this._current.set(this.children[this.initial]))),this.isLockable=a,this.useCoalescedEvents=l,this.performanceTracker=new i.f6}editor;performanceTracker;static id;static initial;static children;static isLockable=!0;static useCoalescedEvents=!1;static trackPerformance=!1;id;type;shapeType;initial;children;isLockable;useCoalescedEvents;parent;getPath(){return this._path.get()}_path;getCurrent(){return this._current.get()}_current;getIsActive(){return this._isActive.get()}_isActive;transition(e,t={}){let n=e.split("."),r=this;for(let e=0;e<n.length;e++){let i=n[e],o=r.getCurrent(),s=r.children?.[i];if(!s)throw Error(`${r.id} - no child state exists with the id ${i}.`);if(o?.id!==s.id&&(o?.exit(t,i),r._current.set(s),s.enter(t,o?.id||"initial"),!s.getIsActive()))break;r=s}return this}handleEvent(e){let t=s.O[e.name],n=this._current.__unsafe__getWithoutCapture();this[t]?.(e),this._isActive.__unsafe__getWithoutCapture()&&n&&n===this._current.__unsafe__getWithoutCapture()&&n.handleEvent(e)}enter(e,t){if(this.constructor.trackPerformance&&(o.bG.measurePerformance.get()&&this.performanceTracker.start(this.id),this.editor.performance._notifyInteractionStart(this.id,this.getPath())),this._isActive.set(!0),this.onEnter?.(e,t),this.children&&this.initial&&this.getIsActive()){let n=this.children[this.initial];this._current.set(n),n.enter(e,t)}}exit(e,t){this.constructor.trackPerformance&&(o.bG.measurePerformance.get()&&this.performanceTracker.isStarted()&&this.performanceTracker.stop(),this.editor.performance._notifyInteractionEnd()),this._isActive.set(!1),this.onExit?.(e,t),this.getIsActive()||this.getCurrent()?.exit(e,t)}_currentToolIdMask=(0,r.eU)("curent tool id mask",void 0);getCurrentToolIdMask(){return this._currentToolIdMask.get()}setCurrentToolIdMask(e){this._currentToolIdMask.set(e)}addChild(e){if("leaf"===this.type)throw Error("StateNode.addChild: cannot add child to a leaf node");this.children||(this.children={});let t=new e(this.editor,this);if(this.children[t.id])throw Error(`StateNode.addChild: a child with id '${t.id}' already exists`);return this.children[t.id]=t,this}}},78943:(e,t,n)=>{"use strict";n.d(t,{y:()=>i});var r=n(78663);class i extends r.Y{static id="root";static initial="";static children(){return[]}}},79224:(e,t,n)=>{"use strict";n.d(t,{f:()=>l});var r=n(83102),i=n(24167),o=Object.defineProperty,s=Object.getOwnPropertyDescriptor,a=(e,t,n,r)=>{for(var i,a=r>1?void 0:r?s(t,n):t,l=e.length-1;l>=0;l--)(i=e[l])&&(a=(r?i(t,n,a):i(a))||a);return r&&a&&o(t,n,a),a};class l{constructor(e){this.editor=e}editor;_visibilityClockStarted=!1;_startVisibilityClock(){this._visibilityClockStarted||(this._visibilityClockStarted=!0,this.editor.timers.setInterval(()=>{this._visibilityClock.set(Date.now())},this.editor.options.collaboratorCheckIntervalMs))}_visibilityClock=(0,r.eU)("collaboratorVisibilityClock",Date.now());_getCollaboratorsQuery(){return this.editor.store.query.records("instance_presence",()=>({userId:{neq:this.editor.user.getRecordId()}}))}getCollaborators(){let e=this._getCollaboratorsQuery().get();return e.length?[...new Set(e.map(e=>e.userId))].sort().map(t=>(0,i.Sk)(e.filter(e=>e.userId===t),e=>e.lastActivityTimestamp??0)):r.Ml}getCollaboratorsOnCurrentPage(){let e=this.editor.getCurrentPageId();return this.getCollaborators().filter(t=>t.currentPageId===e)}getVisibleCollaborators(){let{editor:e}=this,{collaboratorInactiveTimeoutMs:t,collaboratorIdleTimeoutMs:n}=e.options;this._startVisibilityClock(),this._visibilityClock.get();let i=Date.now(),o=this.getCollaborators();if(!o.length)return r.Ml;let{followingUserId:s,highlightedUserIds:a}=this.editor.getInstanceState(),l=this.editor.user.getRecordId();return o.filter(e=>{let{lastActivityTimestamp:r,userId:o,chatMessage:d}=e,c=r?Math.max(0,i-r):0;return c>t?s===o||a.includes(o):!(c>n)||e.followingUserId!==l||!!(d||a.includes(o))})}getVisibleCollaboratorsOnCurrentPage(){let e=this.editor.getCurrentPageId();return this.getVisibleCollaborators().filter(t=>t.currentPageId===e)}}a([r.EW],l.prototype,"_getCollaboratorsQuery",1),a([(0,r.EW)({isEqual:i.vq})],l.prototype,"getCollaborators",1),a([(0,r.EW)({isEqual:i.vq})],l.prototype,"getCollaboratorsOnCurrentPage",1),a([(0,r.EW)({isEqual:i.vq})],l.prototype,"getVisibleCollaborators",1),a([(0,r.EW)({isEqual:i.vq})],l.prototype,"getVisibleCollaboratorsOnCurrentPage",1)},80614:(e,t,n)=>{"use strict";n.d(t,{H:()=>a,d:()=>d});var r=n(24167),i=n(12115);function o(e,t){let n=(0,i.useRef)(e);return t(e,n.current)?n.current:(n.current=e,e)}let s=(e,t)=>(e??=null)===(t??=null)||!!e&&!!t&&(0,r.vq)(e,t);function a(e){return o(e,s)}let l=(e,t)=>(e??=null)===(t??=null)||!!e&&!!t&&(0,r.zK)(e,t);function d(e){return o(e,l)}},80878:(e,t,n)=>{"use strict";let r;n.d(t,{Mz:()=>eX,i3:()=>eZ,UC:()=>eJ,bL:()=>eq,Bk:()=>eL});var i=n(12115);let o=["top","right","bottom","left"],s=Math.min,a=Math.max,l=Math.round,d=Math.floor,c=e=>({x:e,y:e}),h={left:"right",right:"left",bottom:"top",top:"bottom"};function u(e,t){return"function"==typeof e?e(t):e}function p(e){return e.split("-")[0]}function f(e){return e.split("-")[1]}function g(e){return"x"===e?"y":"x"}function m(e){return"y"===e?"height":"width"}function y(e){let t=e[0];return"t"===t||"b"===t?"y":"x"}function b(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}let x=["left","right"],w=["right","left"],v=["top","bottom"],S=["bottom","top"];function C(e){let t=p(e);return h[t]+e.slice(t.length)}function k(e){var t,n,r,i;return"number"!=typeof e?{top:null!=(t=e.top)?t:0,right:null!=(n=e.right)?n:0,bottom:null!=(r=e.bottom)?r:0,left:null!=(i=e.left)?i:0}:{top:e,right:e,bottom:e,left:e}}function P(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function T(e,t,n){let r,{reference:i,floating:o}=e,s=y(t),a=g(y(t)),l=m(a),d=p(t),c=i.x+i.width/2-o.width/2,h=i.y+i.height/2-o.height/2,u=i[l]/2-o[l]/2;switch(d){case"top":r={x:c,y:i.y-o.height};break;case"bottom":r={x:c,y:i.y+i.height};break;case"right":r={x:i.x+i.width,y:h};break;case"left":r={x:i.x-o.width,y:h};break;default:r={x:i.x,y:i.y}}let b=f(t);return b&&(r[a]+=u*("end"===b?1:-1)*(n&&"y"===s?-1:1)),r}async function E(e,t){var n;void 0===t&&(t={});let{x:r,y:i,platform:o,rects:s,elements:a,strategy:l}=e,{boundary:d="clippingAncestors",rootBoundary:c="viewport",elementContext:h="floating",altBoundary:p=!1,padding:f=0}=u(t,e),g=k(f),m=a[p?"floating"===h?"reference":"floating":h],y=P(await o.getClippingRect({element:null==(n=await (null==o.isElement?void 0:o.isElement(m)))||n?m:m.contextElement||await (null==o.getDocumentElement?void 0:o.getDocumentElement(a.floating)),boundary:d,rootBoundary:c,strategy:l})),b="floating"===h?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,x=await (null==o.getOffsetParent?void 0:o.getOffsetParent(a.floating)),w=await (null==o.isElement?void 0:o.isElement(x))&&await (null==o.getScale?void 0:o.getScale(x))||{x:1,y:1},v=P(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:x,strategy:l}):b);return{top:(y.top-v.top+g.top)/w.y,bottom:(v.bottom-y.bottom+g.bottom)/w.y,left:(y.left-v.left+g.left)/w.x,right:(v.right-y.right+g.right)/w.x}}let I=async(e,t,n)=>{let{placement:r="bottom",strategy:i="absolute",middleware:o=[],platform:s}=n,a=s.detectOverflow?s:{...s,detectOverflow:E},l=await (null==s.isRTL?void 0:s.isRTL(t)),d=await s.getElementRects({reference:e,floating:t,strategy:i}),{x:c,y:h}=T(d,r,l),u=r,p=0,f={};for(let n=0;n<o.length;n++){let g=o[n];if(!g)continue;let{name:m,fn:y}=g,{x:b,y:x,data:w,reset:v}=await y({x:c,y:h,initialPlacement:r,placement:u,strategy:i,middlewareData:f,rects:d,platform:a,elements:{reference:e,floating:t}});c=null!=b?b:c,h=null!=x?x:h,f[m]={...f[m],...w},v&&p<50&&(p++,"object"==typeof v&&(v.placement&&(u=v.placement),v.rects&&(d=!0===v.rects?await s.getElementRects({reference:e,floating:t,strategy:i}):v.rects),{x:c,y:h}=T(d,u,l)),n=-1)}return{x:c,y:h,placement:u,strategy:i,middlewareData:f}};function _(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function M(e){return o.some(t=>e[t]>=0)}let A=new Set(["left","top"]);async function j(e,t){let{placement:n,platform:r,elements:i}=e,o=await (null==r.isRTL?void 0:r.isRTL(i.floating)),s=p(n),a=f(n),l="y"===y(n),d=A.has(s)?-1:1,c=o&&l?-1:1,h=u(t,e),{mainAxis:g,crossAxis:m,alignmentAxis:b}="number"==typeof h?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return a&&"number"==typeof b&&(m="end"===a?-1*b:b),l?{x:m*c,y:g*d}:{x:g*d,y:m*c}}function O(){return"u">typeof window}function D(e){return F(e)?(e.nodeName||"").toLowerCase():"#document"}function L(e){var t;return(null==e||null==(t=e.ownerDocument)?void 0:t.defaultView)||window}function R(e){var t;return null==(t=(F(e)?e.ownerDocument:e.document)||window.document)?void 0:t.documentElement}function F(e){return!!O()&&(e instanceof Node||e instanceof L(e).Node)}function z(e){return!!O()&&(e instanceof Element||e instanceof L(e).Element)}function N(e){return!!O()&&(e instanceof HTMLElement||e instanceof L(e).HTMLElement)}function $(e){return!(!O()||"u"<typeof ShadowRoot)&&(e instanceof ShadowRoot||e instanceof L(e).ShadowRoot)}function B(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=q(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&"inline"!==i&&"contents"!==i}function H(e){try{if(e.matches(":popover-open"))return!0}catch(e){}try{return e.matches(":modal")}catch(e){return!1}}let U=/transform|translate|scale|rotate|perspective|filter/,K=/paint|layout|strict|content/,W=e=>!!e&&"none"!==e;function V(e){let t=z(e)?q(e):e;return W(t.transform)||W(t.translate)||W(t.scale)||W(t.rotate)||W(t.perspective)||!Y()&&(W(t.backdropFilter)||W(t.filter))||U.test(t.willChange||"")||K.test(t.contain||"")}function Y(){return null==r&&(r="u">typeof CSS&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),r}function G(e){return/^(html|body|#document)$/.test(D(e))}function q(e){return L(e).getComputedStyle(e)}function X(e){return z(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function J(e){if("html"===D(e))return e;let t=e.assignedSlot||e.parentNode||$(e)&&e.host||R(e);return $(t)?t.host:t}function Z(e,t,n){var r;void 0===t&&(t=[]),void 0===n&&(n=!0);let i=function e(t){let n=J(t);return G(n)?(t.ownerDocument||t).body:N(n)&&B(n)?n:e(n)}(e),o=i===(null==(r=e.ownerDocument)?void 0:r.body),s=L(i);if(!o)return t.concat(i,Z(i,[],n));{let e=Q(s);return t.concat(s,s.visualViewport||[],B(i)?i:[],e&&n?Z(e):[])}}function Q(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function ee(e){let t=q(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=N(e),o=i?e.offsetWidth:n,s=i?e.offsetHeight:r,a=l(n)!==o||l(r)!==s;return a&&(n=o,r=s),{width:n,height:r,$:a}}function et(e){return z(e)?e:e.contextElement}function en(e){let t=et(e);if(!N(t))return c(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:o}=ee(t),s=(o?l(n.width):n.width)/r,a=(o?l(n.height):n.height)/i;return s&&Number.isFinite(s)||(s=1),a&&Number.isFinite(a)||(a=1),{x:s,y:a}}let er=c(0);function ei(e){let t=L(e);return Y()&&t.visualViewport?{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}:er}function eo(e,t,n,r){var i;void 0===t&&(t=!1),void 0===n&&(n=!1);let o=e.getBoundingClientRect(),s=et(e),a=c(1);t&&(r?z(r)&&(a=en(r)):a=en(e));let l=(void 0===(i=n)&&(i=!1),r&&i&&r===L(s))?ei(s):c(0),d=(o.left+l.x)/a.x,h=(o.top+l.y)/a.y,u=o.width/a.x,p=o.height/a.y;if(s&&r){let e=L(s),t=z(r)?L(r):r,n=e,i=Q(n);for(;i&&t!==n;){let e=en(i),t=i.getBoundingClientRect(),r=q(i),o=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,s=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;d*=e.x,h*=e.y,u*=e.x,p*=e.y,d+=o,h+=s,i=Q(n=L(i))}}return P({width:u,height:p,x:d,y:h})}function es(e,t){let n=X(e).scrollLeft;return t?t.left+n:eo(R(e)).left+n}function ea(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-es(e,n),y:n.top+t.scrollTop}}function el(e,t,n){var r;let i;if("viewport"===t||"layoutViewport"===t)i=function(e,t,n){void 0===n&&(n="viewport");let r="layoutViewport"===n,i=L(e),o=R(e),s=i.visualViewport,a=o.clientWidth,l=o.clientHeight,d=0,c=0;if(s){let e=!Y()||"fixed"===t;r?e||(d=-s.offsetLeft,c=-s.offsetTop):(a=s.width,l=s.height,e&&(d=s.offsetLeft,c=s.offsetTop))}if(0>=es(o)){let e=o.ownerDocument,t=e.body,n=getComputedStyle(t),r="CSS1Compat"===e.compatMode&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(o.clientWidth-t.clientWidth-r),s="stable both-edges"===getComputedStyle(o).scrollbarGutter?i/2:i;s<=25&&(a-=s)}return{width:a,height:l,x:d,y:c}}(e,n,t);else if("document"===t){let t,n,o,s,l,d;t=X(r=R(e)),n=r.ownerDocument.body,o=a(r.scrollWidth,r.clientWidth,n.scrollWidth,n.clientWidth),s=a(r.scrollHeight,r.clientHeight,n.scrollHeight,n.clientHeight),l=-t.scrollLeft+es(r),d=-t.scrollTop,"rtl"===q(n).direction&&(l+=a(r.clientWidth,n.clientWidth)-o),i={width:o,height:s,x:l,y:d}}else if(z(t)){let e,r,o,s,a,l;r=(e=eo(t,!0,"fixed"===n)).top+t.clientTop,o=e.left+t.clientLeft,s=en(t),a=t.clientWidth*s.x,l=t.clientHeight*s.y,i={width:a,height:l,x:o*s.x,y:r*s.y}}else{let n=ei(e);i={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return P(i)}function ed(e){return"static"===q(e).position}function ec(e,t){if(!N(e)||"fixed"===q(e).position)return null;if(t)return t(e);let n=e.offsetParent;return R(e)===n&&(n=n.ownerDocument.body),n}function eh(e,t){var n;let r=L(e);if(H(e))return r;if(!N(e)){let t=J(e);for(;t&&!G(t);){if(z(t)&&!ed(t))return t;t=J(t)}return r}let i=ec(e,t);for(;i&&(n=i,/^(table|td|th)$/.test(D(n)))&&ed(i);)i=ec(i,t);return i&&G(i)&&ed(i)&&!V(i)?r:i||function(e){let t=J(e);for(;N(t)&&!G(t);){if(V(t))return t;if(H(t))break;t=J(t)}return null}(e)||r}let eu=async function(e){let t=this.getOffsetParent||eh,n=this.getDimensions,r=await n(e.floating);return{reference:function(e,t,n){let r=N(t),i=R(t),o="fixed"===n,s=eo(e,!0,o,t),a={scrollLeft:0,scrollTop:0},l=c(0);if((r||!o)&&(("body"!==D(t)||B(i))&&(a=X(t)),r)){let e=eo(t,!0,o,t);l.x=e.x+t.clientLeft,l.y=e.y+t.clientTop}!r&&i&&(l.x=es(i));let d=!i||r||o?c(0):ea(i,a);return{x:s.left+a.scrollLeft-l.x-d.x,y:s.top+a.scrollTop-l.y-d.y,width:s.width,height:s.height}}(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}},ep={convertOffsetParentRelativeRectToViewportRelativeRect:function(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,o="fixed"===i,s=R(r),a=!!t&&H(t.floating);if(r===s||a&&o)return n;let l={scrollLeft:0,scrollTop:0},d=c(1),h=c(0),u=N(r);if((u||!o)&&(("body"!==D(r)||B(s))&&(l=X(r)),u)){let e=eo(r);d=en(r),h.x=e.x+r.clientLeft,h.y=e.y+r.clientTop}let p=!s||u||o?c(0):ea(s,l);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-l.scrollLeft*d.x+h.x+p.x,y:n.y*d.y-l.scrollTop*d.y+h.y+p.y}},getDocumentElement:R,getClippingRect:function(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,o=[..."clippingAncestors"===n?H(t)?[]:function(e,t){let n=t.get(e);if(n)return n;let r=Z(e,[],!1).filter(e=>z(e)&&"body"!==D(e)),i=null,o="fixed"===q(e).position,s=o?J(e):e;for(;z(s)&&!G(s);){let e=q(s),t=V(s),n=i?i.position:o?"fixed":"";t||"fixed"!==n&&("absolute"!==n||"static"!==e.position)?i=e:r=r.filter(e=>e!==s),s=J(s)}return t.set(e,r),r}(t,this._c):[].concat(n),r],l=el(t,o[0],i),d=l.top,c=l.right,h=l.bottom,u=l.left;for(let e=1;e<o.length;e++){let n=el(t,o[e],i);d=a(n.top,d),c=s(n.right,c),h=s(n.bottom,h),u=a(n.left,u)}return{width:c-u,height:h-d,x:u,y:d}},getOffsetParent:eh,getElementRects:eu,getClientRects:function(e){return e.getClientRects?Array.from(e.getClientRects()):[]},getDimensions:function(e){let{width:t,height:n}=ee(e);return{width:t,height:n}},getScale:en,isElement:z,isRTL:function(e){return"rtl"===q(e).direction}};function ef(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}let eg=e=>({name:"arrow",options:e,async fn(t){let{x:n,y:r,placement:i,rects:o,platform:l,elements:d,middlewareData:c}=t,{element:h,padding:p=0}=u(e,t)||{};if(null==h)return{};let b=k(p),x={x:n,y:r},w=g(y(i)),v=m(w),S=await l.getDimensions(h),C="y"===w,P=C?"clientHeight":"clientWidth",T=o.reference[v]+o.reference[w]-x[w]-o.floating[v],E=x[w]-o.reference[w],I=await (null==l.getOffsetParent?void 0:l.getOffsetParent(h)),_=I?I[P]:0;_&&await (null==l.isElement?void 0:l.isElement(I))||(_=d.floating[P]||o.floating[v]);let M=_/2-S[v]/2-1,A=s(b[C?"top":"left"],M),j=s(b[C?"bottom":"right"],M),O=_-S[v]-j,D=_/2-S[v]/2+(T/2-E/2),L=a(A,s(D,O)),R=!c.arrow&&null!=f(i)&&D!==L&&o.reference[v]/2-(D<A?A:j)-S[v]/2<0,F=R?D<A?D-A:D-O:0;return{[w]:x[w]+F,data:{[w]:L,centerOffset:D-L-F,...R&&{alignmentOffset:F}},reset:R}}});var em=n(47650),ey="u">typeof document?i.useLayoutEffect:function(){};function eb(e,t){let n,r,i;if(e===t)return!0;if(typeof e!=typeof t)return!1;if("function"==typeof e&&e.toString()===t.toString())return!0;if(e&&t&&"object"==typeof e){if(Array.isArray(e)){if((n=e.length)!==t.length)return!1;for(r=n;0!=r--;)if(!eb(e[r],t[r]))return!1;return!0}if((n=(i=Object.keys(e)).length)!==Object.keys(t).length)return!1;for(r=n;0!=r--;)if(!({}).hasOwnProperty.call(t,i[r]))return!1;for(r=n;0!=r--;){let n=i[r];if(("_owner"!==n||!e.$$typeof)&&!eb(e[n],t[n]))return!1}return!0}return e!=e&&t!=t}function ex(e){return"u"<typeof window?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function ew(e,t){let n=ex(e);return Math.round(t*n)/n}function ev(e){let t=i.useRef(e);return ey(()=>{t.current=e}),t}var eS=n(55897),eC=n(95155),ek=Object.defineProperty,eP=i.forwardRef(ek(function(e,t){let{children:n,width:r=10,height:i=5,...o}=e;return(0,eC.jsx)(eS.sG.svg,{...o,ref:t,width:r,height:i,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:(0,eC.jsx)("polygon",{points:"0,0 30,0 15,10"})})},"name",{value:"Arrow",configurable:!0})),eT=n(47527),eE=n(68599),eI=n(17347),e_=n(66294),eM=n(63509),eA=Object.defineProperty,ej=(e,t)=>eA(e,"name",{value:t,configurable:!0}),eO="Popper",[eD,eL]=(0,eE.A)(eO),[eR,eF]=eD(eO),ez=ej(e=>{let{__scopePopper:t,children:n}=e,[r,o]=i.useState(null),[s,a]=i.useState(void 0);return(0,eC.jsx)(eR,{scope:t,anchor:r,onAnchorChange:o,placementState:s,setPlacementState:a,children:n})},"Popper"),eN=i.forwardRef(ej(function(e,t){let{__scopePopper:n,virtualRef:r,...o}=e,s=eF("PopperAnchor",n),a=i.useRef(null),l=s.onAnchorChange,d=i.useCallback(e=>{a.current=e,e&&l(e)},[l]),c=(0,eT.s)(t,d),h=i.useRef(null);i.useEffect(()=>{if(!r)return;let e=h.current;h.current=r.current,e!==h.current&&l(h.current)});let u=s.placementState&&eG(s.placementState),p=u?.[0],f=u?.[1];return r?null:(0,eC.jsx)(eS.sG.div,{"data-radix-popper-side":p,"data-radix-popper-align":f,...o,ref:c})},"PopperAnchor")),e$="PopperContent",[eB,eH]=eD(e$),eU=i.forwardRef(ej(function(e,t){var n,r,o,l,c,h,k,P,T,E,O,D,F;let z,N,$,B,H,U,{__scopePopper:K,side:W="bottom",sideOffset:V=0,align:Y="center",alignOffset:G=0,arrowPadding:q=0,avoidCollisions:X=!0,collisionBoundary:J=[],collisionPadding:Q=0,sticky:ee="partial",hideWhenDetached:en=!1,updatePositionStrategy:er="optimized",onPlaced:ei,...es}=e,ea=eF(e$,K),[el,ed]=i.useState(null),ec=(0,eT.s)(t,ed),[eh,eu]=i.useState(null),ek=(0,eM.X)(eh),eP=ek?.width??0,eE=ek?.height??0,eA="number"==typeof Q?Q:{top:0,right:0,bottom:0,left:0,...Q},eO=Array.isArray(J)?J:[J],eD=eO.length>0,eL={padding:eA,boundary:eO.filter(eV),altBoundary:eD},{refs:eR,floatingStyles:ez,placement:eN,isPositioned:eH,middlewareData:eU}=function(e){void 0===e&&(e={});let{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:a}={},transform:l=!0,whileElementsMounted:d,open:c}=e,[h,u]=i.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,f]=i.useState(r);eb(p,r)||f(r);let[g,m]=i.useState(null),[y,b]=i.useState(null),x=i.useCallback(e=>{e!==C.current&&(C.current=e,m(e))},[]),w=i.useCallback(e=>{e!==k.current&&(k.current=e,b(e))},[]),v=s||g,S=a||y,C=i.useRef(null),k=i.useRef(null),P=i.useRef(h),T=null!=d,E=ev(d),_=ev(o),M=ev(c),A=i.useCallback(()=>{var e,r;let i,o,s;if(!C.current||!k.current)return;let a={placement:t,strategy:n,middleware:p};_.current&&(a.platform=_.current),(e=C.current,r=k.current,i=new Map,o=null!=a?a:{},s={...ep,...o.platform,_c:i},I(e,r,{...o,platform:s})).then(e=>{let t={...e,isPositioned:!1!==M.current};j.current&&!eb(P.current,t)&&(P.current=t,em.flushSync(()=>{u(t)}))})},[p,t,n,_,M]);ey(()=>{!1===c&&P.current.isPositioned&&(P.current.isPositioned=!1,u(e=>({...e,isPositioned:!1})))},[c]);let j=i.useRef(!1);ey(()=>(j.current=!0,()=>{j.current=!1}),[]),ey(()=>{if(v&&(C.current=v),S&&(k.current=S),v&&S){if(E.current)return E.current(v,S,A);A()}},[v,S,A,E,T]);let O=i.useMemo(()=>({reference:C,floating:k,setReference:x,setFloating:w}),[x,w]),D=i.useMemo(()=>({reference:v,floating:S}),[v,S]),L=i.useMemo(()=>{let e={position:n,left:0,top:0};if(!D.floating)return e;let t=ew(D.floating,h.x),r=ew(D.floating,h.y);return l?{...e,transform:"translate("+t+"px, "+r+"px)",...ex(D.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:t,top:r}},[n,l,D.floating,h.x,h.y]);return i.useMemo(()=>({...h,update:A,refs:O,elements:D,floatingStyles:L}),[h,A,O,D,L])}({strategy:"fixed",placement:W+("center"!==Y?"-"+Y:""),whileElementsMounted:ej((...e)=>(function(e,t,n,r){let i;void 0===r&&(r={});let{ancestorScroll:o=!0,ancestorResize:l=!0,elementResize:c="function"==typeof ResizeObserver,layoutShift:h="function"==typeof IntersectionObserver,animationFrame:u=!1}=r,p=et(e),f=o||l?[...p?Z(p):[],...t?Z(t):[]]:[];f.forEach(e=>{o&&e.addEventListener("scroll",n),l&&e.addEventListener("resize",n)});let g=p&&h?function(e,t,n){let r,i=null,o=R(e);function l(){var e;clearTimeout(r),null==(e=i)||e.disconnect(),i=null}function c(n,h){void 0===n&&(n=!1),void 0===h&&(h=1),l();let u=e.getBoundingClientRect(),{left:p,top:f,width:g,height:m}=u;if(n||t(),!g||!m)return;let y={rootMargin:-d(f)+"px "+-d(o.clientWidth-(p+g))+"px "+-d(o.clientHeight-(f+m))+"px "+-d(p)+"px",threshold:a(0,s(1,h))||1},b=!0;function x(t){let n=t[0].intersectionRatio;if(!ef(u,e.getBoundingClientRect()))return c();if(n!==h){if(!b)return c();n?c(!1,n):r=setTimeout(()=>{c(!1,1e-7)},1e3)}b=!1}try{i=new IntersectionObserver(x,{...y,root:o.ownerDocument})}catch(e){i=new IntersectionObserver(x,y)}i.observe(e)}let h=L(e),u=()=>c(n);return h.addEventListener("resize",u),c(!0),()=>{h.removeEventListener("resize",u),l()}}(p,n,l):null,m=-1,y=null;c&&(y=new ResizeObserver(e=>{let[r]=e;r&&r.target===p&&y&&t&&(y.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var e;null==(e=y)||e.observe(t)})),n()}),p&&!u&&y.observe(p),t&&y.observe(t));let b=u?eo(e):null;return u&&function t(){let r=eo(e);b&&!ef(b,r)&&n(),b=r,i=requestAnimationFrame(t)}(),n(),()=>{var e;f.forEach(e=>{o&&e.removeEventListener("scroll",n),l&&e.removeEventListener("resize",n)}),null==g||g(),null==(e=y)||e.disconnect(),y=null,u&&cancelAnimationFrame(i)}})(...e,{animationFrame:"always"===er}),"whileElementsMounted"),elements:{reference:ea.anchor},middleware:[{name:(z={name:"offset",options:r=n={mainAxis:V+eE,alignmentAxis:G},async fn(e){var t,n;let{x:i,y:o,placement:s,middlewareData:a}=e,l=await j(e,r);return s===(null==(t=a.offset)?void 0:t.placement)&&null!=(n=a.arrow)&&n.alignmentOffset?{}:{x:i+l.x,y:o+l.y,data:{...l,placement:s}}}}).name,fn:z.fn,options:[n,void 0]},X&&{name:(N={name:"shift",options:c=l={mainAxis:!0,crossAxis:!1,limiter:"partial"===ee?{fn:(o=void 0,{options:o={},fn(e){var t,n,r,i;let{x:s,y:a,placement:l,rects:d,middlewareData:c}=e,{offset:h=0,mainAxis:f=!0,crossAxis:m=!0}=u(o,e),b={x:s,y:a},x=y(l),w=g(x),v=b[w],S=b[x],C=u(h,e),k="number"==typeof C?{mainAxis:C,crossAxis:0}:{mainAxis:null!=(t=C.mainAxis)?t:0,crossAxis:null!=(n=C.crossAxis)?n:0};if(f){let e="y"===w?"height":"width",t=d.reference[w]-d.floating[e]+k.mainAxis,n=d.reference[w]+d.reference[e]-k.mainAxis;v<t?v=t:v>n&&(v=n)}if(m){let e="y"===w?"width":"height",t=A.has(p(l)),n=d.reference[x]-d.floating[e]+(t&&(null==(r=c.offset)?void 0:r[x])||0)+(t?0:k.crossAxis),o=d.reference[x]+d.reference[e]+(t?0:(null==(i=c.offset)?void 0:i[x])||0)-(t?k.crossAxis:0);S<n?S=n:S>o&&(S=o)}return{[w]:v,[x]:S}}}).fn,options:[void 0,void 0]}:void 0,...eL},async fn(e){let{x:t,y:n,placement:r,platform:i}=e,{mainAxis:o=!0,crossAxis:l=!1,limiter:d={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...h}=u(c,e),p={x:t,y:n},f=await i.detectOverflow(e,h),m=y(r),b=g(m),x=p[b],w=p[m],v=(e,t)=>a(t+f["y"===e?"top":"left"],s(t,t-f["y"===e?"bottom":"right"]));o&&(x=v(b,x)),l&&(w=v(m,w));let S=d.fn({...e,[b]:x,[m]:w});return{...S,data:{x:S.x-t,y:S.y-n,enabled:{[b]:o,[m]:l}}}}}).name,fn:N.fn,options:[l,void 0]},X&&{name:($={name:"flip",options:k=h={...eL},async fn(e){var t,n,r,i,o,s,a,l;let d,c,h,{placement:P,middlewareData:T,rects:E,initialPlacement:I,platform:_,elements:M}=e,{mainAxis:A=!0,crossAxis:j=!0,fallbackPlacements:O,fallbackStrategy:D="bestFit",fallbackAxisSideDirection:L="none",flipAlignment:R=!0,...F}=u(k,e);if(null!=(t=T.arrow)&&t.alignmentOffset)return{};let z=p(P),N=y(I),$=p(I)===I,B=await (null==_.isRTL?void 0:_.isRTL(M.floating)),H=O||($||!R?[C(I)]:(d=C(I),[b(I),d,b(d)])),U="none"!==L;!O&&U&&H.push(...(c=f(I),h=function(e,t,n){switch(e){case"top":case"bottom":if(n)return t?w:x;return t?x:w;case"left":case"right":return t?v:S;default:return[]}}(p(I),"start"===L,B),c&&(h=h.map(e=>e+"-"+c),R&&(h=h.concat(h.map(b)))),h));let K=[I,...H],W=await _.detectOverflow(e,F),V=[],Y=(null==(n=T.flip)?void 0:n.overflows)||[];if(A&&V.push(W[z]),j){let e,t,n,r,i=(s=P,a=E,void 0===(l=B)&&(l=!1),e=f(s),n=m(t=g(y(s))),r="x"===t?e===(l?"end":"start")?"right":"left":"start"===e?"bottom":"top",a.reference[n]>a.floating[n]&&(r=C(r)),[r,C(r)]);V.push(W[i[0]],W[i[1]])}if(Y=[...Y,{placement:P,overflows:V}],!V.every(e=>e<=0)){let e=((null==(r=T.flip)?void 0:r.index)||0)+1,t=K[e];if(t&&("alignment"!==j||N===y(t)||Y.every(e=>y(e.placement)!==N||e.overflows[0]>0)))return{data:{index:e,overflows:Y},reset:{placement:t}};let n=null==(i=Y.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0])?void 0:i.placement;if(!n)switch(D){case"bestFit":{let e=null==(o=Y.filter(e=>{if(U){let t=y(e.placement);return t===N||"y"===t}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0])?void 0:o[0];e&&(n=e);break}case"initialPlacement":n=I}if(P!==n)return{reset:{placement:n}}}return{}}}).name,fn:$.fn,options:[h,void 0]},{name:(B={name:"size",options:T=P={...eL,apply:ej(({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:o}=t.reference,s=e.floating.style;s.setProperty("--radix-popper-available-width",`${n}px`),s.setProperty("--radix-popper-available-height",`${r}px`),s.setProperty("--radix-popper-anchor-width",`${i}px`),s.setProperty("--radix-popper-anchor-height",`${o}px`)},"apply")},async fn(e){let t,n,{placement:r,rects:i,platform:o,elements:l}=e,{apply:d=()=>{},...c}=u(T,e),h=await o.detectOverflow(e,c),g=p(r),m=f(r),b="y"===y(r),{width:x,height:w}=i.floating;"top"===g||"bottom"===g?(t=g,n=m===(await (null==o.isRTL?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(n=g,t="end"===m?"top":"bottom");let v=w-h.top-h.bottom,S=x-h.left-h.right,C=s(w-h[t],v),k=s(x-h[n],S),P=e.middlewareData.shift,E=!P,I=C,_=k;null!=P&&P.enabled.x&&(_=S),null!=P&&P.enabled.y&&(I=v),E&&!m&&(b?_=x-2*a(h.left,h.right):I=w-2*a(h.top,h.bottom)),await d({...e,availableWidth:_,availableHeight:I});let M=await o.getDimensions(l.floating);return x!==M.width||w!==M.height?{reset:{rects:!0}}:{}}}).name,fn:B.fn,options:[P,void 0]},eh&&{name:(H={name:"arrow",options:O=E={element:eh,padding:q},fn(e){let{element:t,padding:n}="function"==typeof O?O(e):O;return t&&({}).hasOwnProperty.call(t,"current")?null!=t.current?eg({element:t.current,padding:n}).fn(e):{}:t?eg({element:t,padding:n}).fn(e):{}}}).name,fn:H.fn,options:[E,void 0]},eY({arrowWidth:eP,arrowHeight:eE}),en&&{name:(U={name:"hide",options:F=D={strategy:"referenceHidden",...eL,boundary:eD?eL.boundary:void 0},async fn(e){let{rects:t,platform:n}=e,{strategy:r="referenceHidden",...i}=u(F,e);switch(r){case"referenceHidden":{let r=_(await n.detectOverflow(e,{...i,elementContext:"reference"}),t.reference);return{data:{referenceHiddenOffsets:r,referenceHidden:M(r)}}}case"escaped":{let r=_(await n.detectOverflow(e,{...i,altBoundary:!0}),t.floating);return{data:{escapedOffsets:r,escaped:M(r)}}}default:return{}}}}).name,fn:U.fn,options:[D,void 0]}]}),eK=ea.setPlacementState;(0,e_.N)(()=>(eK(eN),()=>{eK(void 0)}),[eN,eK]);let[eW,eq]=eG(eN),eX=(0,eI.c)(ei);(0,e_.N)(()=>{eH&&eX?.()},[eH,eX]);let eJ=eU.arrow?.x,eZ=eU.arrow?.y,eQ=eU.arrow?.centerOffset!==0,[e0,e1]=i.useState();return(0,e_.N)(()=>{el&&e1(window.getComputedStyle(el).zIndex)},[el]),(0,eC.jsx)("div",{ref:eR.setFloating,"data-radix-popper-content-wrapper":"",style:{...ez,transform:eH?ez.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:e0,"--radix-popper-transform-origin":[eU.transformOrigin?.x,eU.transformOrigin?.y].join(" "),...eU.hide?.referenceHidden&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:(0,eC.jsx)(eB,{scope:K,placedSide:eW,placedAlign:eq,onArrowChange:eu,arrowX:eJ,arrowY:eZ,shouldHideArrow:eQ,children:(0,eC.jsx)(eS.sG.div,{"data-side":eW,"data-align":eq,...es,ref:ec,style:{...es.style,animation:eH?es.style?.animation:"none"}})})})},"PopperContent")),eK={top:"bottom",right:"left",bottom:"top",left:"right"},eW=i.forwardRef(ej(function(e,t){let{__scopePopper:n,...r}=e,i=eH("PopperArrow",n),o=eK[i.placedSide];return(0,eC.jsx)("span",{ref:i.onArrowChange,style:{position:"absolute",left:i.arrowX,top:i.arrowY,[o]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[i.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[i.placedSide],visibility:i.shouldHideArrow?"hidden":void 0},children:(0,eC.jsx)(eP,{...r,ref:t,style:{...r.style,display:"block"}})})},"PopperArrow"));function eV(e){return null!==e}ej(eV,"isNotNull");var eY=ej(e=>({name:"transformOrigin",options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,o=i.arrow?.centerOffset!==0,s=o?0:e.arrowWidth,a=o?0:e.arrowHeight,[l,d]=eG(n),c={start:"0%",center:"50%",end:"100%"}[d],h=(i.arrow?.x??0)+s/2,u=(i.arrow?.y??0)+a/2,p="",f="";return"bottom"===l?(p=o?c:`${h}px`,f=`${-a}px`):"top"===l?(p=o?c:`${h}px`,f=`${r.floating.height+a}px`):"right"===l?(p=`${-a}px`,f=o?c:`${u}px`):"left"===l&&(p=`${r.floating.width+a}px`,f=o?c:`${u}px`),{data:{x:p,y:f}}}}),"transformOrigin");function eG(e){let[t,n="center"]=e.split("-");return[t,n]}ej(eG,"getSideAndAlignFromPlacement");var eq=ez,eX=eN,eJ=eU,eZ=eW},81467:(e,t,n)=>{"use strict";n.d(t,{sr:()=>ee,ro:()=>Q,qf:()=>J,Kx:()=>e1,Xu:()=>ep,sd:()=>te,iv:()=>B,Pe:()=>K,u8:()=>W,xX:()=>Y,ye:()=>V,yM:()=>tS,Sg:()=>X,nM:()=>tW,YU:()=>tC,tS:()=>e6,tg:()=>tk,jA:()=>eB,Yj:()=>ni,eB:()=>tF,tv:()=>eP,yI:()=>e4,O9:()=>eF,G1:()=>eV,XA:()=>eA,g8:()=>el,P_:()=>es,ud:()=>ei,FX:()=>et,K6:()=>tc,Es:()=>u,Vt:()=>c,hN:()=>e7,aW:()=>e8,BN:()=>T,gP:()=>t5,S6:()=>eJ,n6:()=>L,Wt:()=>ne,dB:()=>ej,de:()=>tf,KB:()=>tu,up:()=>tx,Pw:()=>ty,Sp:()=>tv,X2:()=>tw,s4:()=>tE,X8:()=>tP,jP:()=>no,jW:()=>eZ,lg:()=>R,gf:()=>t_,h4:()=>tI,RE:()=>tj,M6:()=>tM,h1:()=>g,_8:()=>p,Uc:()=>tR,lX:()=>tD,OT:()=>P,GY:()=>G,xh:()=>eT,o2:()=>O,vc:()=>D,bT:()=>tB,e9:()=>tN,fq:()=>tK,SW:()=>tH,ny:()=>ev,Pu:()=>eD,Mc:()=>U,AF:()=>q,eH:()=>E,zo:()=>C,E4:()=>tG,xj:()=>tV,TP:()=>I,jh:()=>b,EO:()=>m,w9:()=>tJ,ZM:()=>tq});var r,i=n(24167),o=n(22690);function s(e){return o.T.string.refine(t=>{if(!t.startsWith(`${e}:`))throw Error(`${e} ID must start with "${e}:"`);return t})}let a=s("asset");function l(e,t,n){let r=t instanceof o.T.Validator?t:t?o.T.object(t):o.T.jsonValue;return o.T.object({id:a,typeName:o.T.literal("asset"),type:o.T.literal(e),props:r,meta:n?o.T.object(n):o.T.jsonValue})}var d=n(54530);let c={title:o.T.string,description:o.T.string,image:o.T.string,favicon:o.T.string,src:o.T.srcUrl.nullable()};l("bookmark",o.T.object(c));let h=(0,d.bo)("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),u=(0,d.XD)({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:e=>"bookmark"===e.type,sequence:[{id:h.MakeUrlsValid,up:e=>{o.T.srcUrl.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:h.AddFavicon,up:e=>{o.T.srcUrl.isValid(e.props.favicon)||(e.props.favicon="")},down:e=>{delete e.props.favicon}}]}),p={w:o.T.number,h:o.T.number,name:o.T.string,isAnimated:o.T.boolean,mimeType:o.T.string.nullable(),src:o.T.srcUrl.nullable(),fileSize:o.T.nonZeroNumber.optional(),pixelRatio:o.T.positiveNumber.optional()};l("image",o.T.object(p));let f=(0,d.bo)("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5,AddPixelRatio:6}),g=(0,d.XD)({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:e=>"image"===e.type,sequence:[{id:f.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:f.RenameWidthHeight,up:e=>{e.props.w=e.props.width,e.props.h=e.props.height,delete e.props.width,delete e.props.height},down:e=>{e.props.width=e.props.w,e.props.height=e.props.h,delete e.props.w,delete e.props.h}},{id:f.MakeUrlsValid,up:e=>{o.T.srcUrl.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:f.AddFileSize,up:e=>{e.props.fileSize=-1},down:e=>{delete e.props.fileSize}},{id:f.MakeFileSizeOptional,up:e=>{-1===e.props.fileSize&&(e.props.fileSize=void 0)},down:e=>{void 0===e.props.fileSize&&(e.props.fileSize=-1)}},{id:f.AddPixelRatio,up:e=>{},down:e=>{delete e.props.pixelRatio}}]}),m={w:o.T.number,h:o.T.number,name:o.T.string,isAnimated:o.T.boolean,mimeType:o.T.string.nullable(),src:o.T.srcUrl.nullable(),fileSize:o.T.number.optional()};l("video",o.T.object(m));let y=(0,d.bo)("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),b=(0,d.XD)({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:e=>"video"===e.type,sequence:[{id:y.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:y.RenameWidthHeight,up:e=>{e.props.w=e.props.width,e.props.h=e.props.height,delete e.props.width,delete e.props.height},down:e=>{e.props.width=e.props.w,e.props.height=e.props.h,delete e.props.w,delete e.props.h}},{id:y.MakeUrlsValid,up:e=>{o.T.srcUrl.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:y.AddFileSize,up:e=>{e.props.fileSize=-1},down:e=>{delete e.props.fileSize}},{id:y.MakeFileSizeOptional,up:e=>{-1===e.props.fileSize&&(e.props.fileSize=void 0)},down:e=>{void 0===e.props.fileSize&&(e.props.fileSize=-1)}}]}),x=o.T.object({x:o.T.number,y:o.T.number,z:o.T.number.optional()}),w=o.T.object({x:o.T.number,y:o.T.number,w:o.T.number,h:o.T.number}),v=o.T.unitInterval,S=o.T.string.refine(e=>{if(!e.startsWith("page:")&&!e.startsWith("shape:"))throw Error('Parent ID must start with "page:" or "shape:"');return e}),C=s("shape"),k=s("binding");function P(e){return!!e&&"binding"===e.typeName}function T(e){return`binding:${e??(0,i.NF)()}`}(0,d.bo)("com.tldraw.binding",{}),(0,d.XD)({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});let E=o.T.object({type:o.T.string,content:o.T.arrayOf(o.T.unknown),attrs:o.T.any.optional()});function I(e){return{type:"doc",content:e.split("\n").map(e=>e?{type:"paragraph",content:[{type:"text",text:e}]}:{type:"paragraph"})}}class _{constructor(e,t,n){this.id=e,this.defaultValue=t,this.type=n}id;defaultValue;type;static define(e,t){let{defaultValue:n,type:r=o.T.any}=t;return new _(e,n,r)}static defineEnum(e,t){let{defaultValue:n,values:r}=t;return new M(e,n,r)}setDefaultValue(e){this.defaultValue=e}validate(e){return this.type.validate(e)}validateUsingKnownGoodVersion(e,t){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(e,t):this.validate(t)}}class M extends _{constructor(e,t,n){super(e,t,o.T.literalEnum(...n)),this.values=[...n]}values;addValues(...e){for(let t of e)this.values.includes(t)||this.values.push(t);this.type=o.T.literalEnum(...this.values)}removeValues(...e){for(let t of e)this.values.includes(t)&&this.values.splice(this.values.indexOf(t),1);this.type=o.T.literalEnum(...this.values)}}let A=(0,d.bo)("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),j=(0,d.XD)({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:A.AddIsLocked,up:e=>{e.isLocked=!1},down:e=>{delete e.isLocked}},{id:A.HoistOpacity,up:e=>{e.opacity=Number(e.props.opacity??"1"),delete e.props.opacity},down:e=>{let t=e.opacity;delete e.opacity,e.props.opacity=t<.175?"0.1":t<.375?"0.25":t<.625?"0.5":t<.875?"0.75":"1"}},{id:A.AddMeta,up:e=>{e.meta={}}},{id:A.AddWhite,up:e=>{},down:e=>{"white"===e.props.color&&(e.props.color="black")}}]});function O(e){return!!e&&"shape"===e.typeName}function D(e){return!!e&&e.startsWith("shape:")}function L(e){return`shape:${e??(0,i.NF)()}`}function R(e){let t=new Map;for(let[n,r]of Object.entries(e))if(r instanceof _){if(t.has(r))throw Error(`Duplicate style prop ${r.id}. Each style prop can only be used once within a shape.`);t.set(r,n)}return t}function F(e,t){return(0,i._H)(t,(t,n)=>`com.tldraw.shape.${e}/${n}`)}function z(e,t){let n=[];for(let[r,{migrations:o}]of Object.entries(t)){let t=`com.tldraw.${e}.${r}`;o?"sequenceId"in o?((0,i.vA)(t===o.sequenceId,`sequenceId mismatch for ${r} ${d.ee} migrations. Expected '${t}', got '${o.sequenceId}'`),n.push(o)):"sequence"in o?n.push((0,d._B)({sequenceId:t,retroactive:!0,sequence:o.sequence.map(t=>"id"in t?N(e,r,t):t)})):n.push((0,d._B)({sequenceId:t,retroactive:!0,sequence:Object.keys(o.migrators).map(e=>Number(e)).sort((e,t)=>e-t).map(n=>({id:`${t}/${n}`,scope:"record",filter:t=>t.typeName===e&&t.type===r,up:e=>{let t=o.migrators[n].up(e);if(t)return t},down:e=>{let t=o.migrators[n].down(e);if(t)return t}}))})):n.push((0,d._B)({sequenceId:t,retroactive:!0,sequence:[]}))}return n}function N(e,t,n){return{id:n.id,dependsOn:n.dependsOn,scope:"record",filter:n=>n.typeName===e&&n.type===t,up:e=>{let t=n.up(e.props);t&&(e.props=t)},down:"function"==typeof n.down?e=>{let t=n.down(e.props);t&&(e.props=t)}:void 0}}let $=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],B=_.defineEnum("tldraw:color",{defaultValue:"black",values:$}),H=_.defineEnum("tldraw:labelColor",{defaultValue:"black",values:$});function U(e){let t=new Set;for(let n of Object.values(e))for(let e of[n.colors.light,n.colors.dark])for(let[n,r]of Object.entries(e))"object"==typeof r&&null!==r&&t.add(n);t.size>0&&(B.addValues(...t),H.addValues(...t));let n=B.values.filter(e=>!t.has(e));n.length>0&&(B.removeValues(...n),H.removeValues(...n))}let K=_.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted","none"]}),W=_.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill","lined-fill"]}),V=_.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),Y={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"};function G(e){return"object"==typeof e&&null!==e&&"fontFamily"in e}function q(e){let t=new Set;for(let n of Object.values(e))if(n.fonts)for(let[e,r]of Object.entries(n.fonts))G(r)&&t.add(e);let n=[...t].filter(e=>!V.values.includes(e));n.length>0&&V.addValues(...n);let r=V.values.filter(e=>!t.has(e));r.length>0&&V.removeValues(...r)}let X=_.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),J=_.defineEnum("tldraw:arrowKind",{defaultValue:"arc",values:["arc","elbow"]}),Z=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Q=_.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:Z}),ee=_.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:Z}),et={kind:J,labelColor:H,color:B,fill:W,dash:K,size:X,arrowheadStart:Q,arrowheadEnd:ee,font:V,start:x,end:x,bend:o.T.number,richText:E,labelPosition:o.T.number,scale:o.T.nonZeroNumber,elbowMidPoint:o.T.number},en=F("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5,AddElbow:6,AddRichText:7,AddRichTextAttrs:8});function er(e){return N("shape","arrow",e)}let ei=(0,d._B)({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[er({id:en.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"}),er({id:en.AddIsPrecise,up:({start:e,end:t})=>{"binding"===e.type&&(e.isPrecise=.5!==e.normalizedAnchor.x||.5!==e.normalizedAnchor.y),"binding"===t.type&&(t.isPrecise=.5!==t.normalizedAnchor.x||.5!==t.normalizedAnchor.y)},down:({start:e,end:t})=>{"binding"===e.type&&(e.isPrecise||(e.normalizedAnchor={x:.5,y:.5}),delete e.isPrecise),"binding"===t.type&&(t.isPrecise||(t.normalizedAnchor={x:.5,y:.5}),delete t.isPrecise)}}),er({id:en.AddLabelPosition,up:e=>{e.labelPosition=.5},down:e=>{delete e.labelPosition}}),{id:en.ExtractBindings,scope:"storage",up:e=>{let t=[];for(let n of e.values()){if("shape"!==n.typeName||"arrow"!==n.type)continue;let e=(0,i.pN)(n),{start:r,end:o}=n.props;if("binding"===r.type){let i=T(),o={typeName:"binding",id:i,type:"arrow",fromId:n.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};t.push([i,o]),e.props.start={x:0,y:0}}else delete e.props.start.type;if("binding"===o.type){let r=T(),i={typeName:"binding",id:r,type:"arrow",fromId:n.id,toId:o.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:o.normalizedAnchor,isExact:o.isExact,isPrecise:o.isPrecise}};t.push([r,i]),e.props.end={x:0,y:0}}else delete e.props.end.type;t.push([n.id,e])}for(let[n,r]of t)e.set(n,r)}},er({id:en.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}),er({id:en.AddElbow,up:e=>{e.kind="arc",e.elbowMidPoint=.5},down:e=>{delete e.kind,delete e.elbowMidPoint}}),er({id:en.AddRichText,up:e=>{e.richText=I(e.text),delete e.text}}),er({id:en.AddRichTextAttrs,up:e=>{},down:e=>{e.richText&&"attrs"in e.richText&&delete e.richText.attrs}})]}),eo=o.T.literalEnum("center","edge-point","edge","none"),es={terminal:o.T.literalEnum("start","end"),normalizedAnchor:x,isExact:o.T.boolean,isPrecise:o.T.boolean,snap:eo},ea=(r={AddSnap:1},(0,i._H)(r,(e,t)=>`com.tldraw.binding.arrow/${t}`)),el={sequence:[{dependsOn:[en.ExtractBindings]},{id:ea.AddSnap,up:e=>{e.snap="none"},down:e=>{delete e.snap}}]};var ed=n(83102);let ec=o.T.model("camera",o.T.object({typeName:o.T.literal("camera"),id:s("camera"),x:o.T.number,y:o.T.number,z:o.T.number,meta:o.T.jsonValue})),eh=(0,d.bo)("com.tldraw.camera",{AddMeta:1}),eu=(0,d.XD)({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:eh.AddMeta,up:e=>{e.meta={}}}]}),ep=(0,d.WE)("camera",{validator:ec,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),ef=new Set(["none","default","pointer","cross","comment","grab","rotate","grabbing","resize-edge","resize-corner","text","move","ew-resize","ns-resize","nesw-resize","nwse-resize","nesw-rotate","nwse-rotate","swne-rotate","senw-rotate","zoom-in","zoom-out"]),eg=o.T.setEnum(ef),em=o.T.object({type:eg,rotation:o.T.number}),ey=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),eb=o.T.setEnum(ey),ex=new Set(["starting","paused","active","complete","stopping"]),ew=o.T.object({id:o.T.string,points:o.T.arrayOf(x),size:o.T.positiveNumber,color:eb,opacity:o.T.number,state:o.T.setEnum(ex),delay:o.T.number,shrink:o.T.number,taper:o.T.boolean}),ev=s("page"),eS=o.T.model("page",o.T.object({typeName:o.T.literal("page"),id:ev,name:o.T.string,index:o.T.indexKey,meta:o.T.jsonValue})),eC=(0,d.bo)("com.tldraw.page",{AddMeta:1}),ek=(0,d.XD)({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:eC.AddMeta,up:e=>{e.meta={}}}]}),eP=(0,d.WE)("page",{validator:eS,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function eT(e){return eP.isId(e)}let eE=s("user"),eI=(0,d.bo)("com.tldraw.user",{Initial:1}),e_=(0,d.XD)({sequenceId:"com.tldraw.user",recordType:"user",sequence:[{id:eI.Initial,up:e=>{}}]});function eM(e){let t=e?.meta,n=t?o.T.object(Object.fromEntries(Object.entries(t).map(([e,t])=>[e,new o.T.Validator(e=>{if(void 0!==e)return t.validate(e)})]))).allowUnknownProperties():o.T.jsonValue,r=o.T.model("user",o.T.object({typeName:o.T.literal("user"),id:eE,name:o.T.string,color:o.T.string,imageUrl:o.T.string,meta:n}));return(0,d.WE)("user",{validator:r,scope:"document"}).withDefaultProperties(()=>({name:"",color:"",imageUrl:"",meta:{}}))}o.T.model("user",o.T.object({typeName:o.T.literal("user"),id:eE,name:o.T.string,color:o.T.string,imageUrl:o.T.string,meta:o.T.jsonValue}));let eA=eM();function ej(e){return eA.createId(e)}let eO={id:!1,typeName:!1,currentPageId:!1,opacityForNextShape:!1,stylesForNextShape:!1,followingUserId:!1,highlightedUserIds:!1,brush:!1,cursor:!1,scribbles:!1,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!1,chatMessage:!1,isChatting:!1,isPenMode:!1,isGridMode:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!1,openMenus:!1,isChangingStyle:!1,isReadonly:!0,meta:!1,duplicateProps:!1,cameraState:!1};function eD(e){return e?(0,i.J2)(e,e=>eO[e]):null}s("instance");let eL=(0,d.bo)("com.tldraw.instance",{AddTransparentExportBgs:1,RemoveDialog:2,AddToolLockMode:3,RemoveExtraPropsForNextShape:4,AddLabelColor:5,AddFollowingUserId:6,RemoveAlignJustify:7,AddZoom:8,AddVerticalAlign:9,AddScribbleDelay:10,RemoveUserId:11,AddIsPenModeAndIsGridMode:12,HoistOpacity:13,AddChat:14,AddHighlightedUserIds:15,ReplacePropsForNextShapeWithStylesForNextShape:16,AddMeta:17,RemoveCursorColor:18,AddLonelyProperties:19,ReadOnlyReadonly:20,AddHoveringCanvas:21,AddScribbles:22,AddInset:23,AddDuplicateProps:24,RemoveCanMoveCamera:25,AddCameraState:26}),eR=(0,d.XD)({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:eL.AddTransparentExportBgs,up:e=>({...e,exportBackground:!0})},{id:eL.RemoveDialog,up:({dialog:e,...t})=>t},{id:eL.AddToolLockMode,up:e=>({...e,isToolLocked:!1})},{id:eL.RemoveExtraPropsForNextShape,up:({propsForNextShape:e,...t})=>({...t,propsForNextShape:Object.fromEntries(Object.entries(e).filter(([e])=>["color","labelColor","dash","fill","size","font","align","verticalAlign","icon","geo","arrowheadStart","arrowheadEnd","spline"].includes(e)))})},{id:eL.AddLabelColor,up:({propsForNextShape:e,...t})=>({...t,propsForNextShape:{...e,labelColor:"black"}})},{id:eL.AddFollowingUserId,up:e=>({...e,followingUserId:null})},{id:eL.RemoveAlignJustify,up:e=>{let t=e.propsForNextShape.align;return"justify"===t&&(t="start"),{...e,propsForNextShape:{...e.propsForNextShape,align:t}}}},{id:eL.AddZoom,up:e=>({...e,zoomBrush:null})},{id:eL.AddVerticalAlign,up:e=>({...e,propsForNextShape:{...e.propsForNextShape,verticalAlign:"middle"}})},{id:eL.AddScribbleDelay,up:e=>null!==e.scribble?{...e,scribble:{...e.scribble,delay:0}}:{...e}},{id:eL.RemoveUserId,up:({userId:e,...t})=>t},{id:eL.AddIsPenModeAndIsGridMode,up:e=>({...e,isPenMode:!1,isGridMode:!1})},{id:eL.HoistOpacity,up:({propsForNextShape:{opacity:e,...t},...n})=>({...n,opacityForNextShape:Number(e??"1"),propsForNextShape:t})},{id:eL.AddChat,up:e=>({...e,chatMessage:"",isChatting:!1})},{id:eL.AddHighlightedUserIds,up:e=>({...e,highlightedUserIds:[]})},{id:eL.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:e,...t})=>({...t,stylesForNextShape:{}})},{id:eL.AddMeta,up:e=>({...e,meta:{}})},{id:eL.RemoveCursorColor,up:e=>{let{color:t,...n}=e.cursor;return{...e,cursor:n}}},{id:eL.AddLonelyProperties,up:e=>({...e,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:eL.ReadOnlyReadonly,up:({isReadOnly:e,...t})=>({...t,isReadonly:e})},{id:eL.AddHoveringCanvas,up:e=>({...e,isHoveringCanvas:null})},{id:eL.AddScribbles,up:({scribble:e,...t})=>({...t,scribbles:[]})},{id:eL.AddInset,up:e=>({...e,insets:[!1,!1,!1,!1]}),down:({insets:e,...t})=>({...t})},{id:eL.AddDuplicateProps,up:e=>({...e,duplicateProps:null}),down:({duplicateProps:e,...t})=>({...t})},{id:eL.RemoveCanMoveCamera,up:({canMoveCamera:e,...t})=>({...t}),down:e=>({...e,canMoveCamera:!0})},{id:eL.AddCameraState,up:e=>({...e,cameraState:"idle"}),down:({cameraState:e,...t})=>t}]}),eF="instance:instance",ez=o.T.model("instance_page_state",o.T.object({typeName:o.T.literal("instance_page_state"),id:s("instance_page_state"),pageId:ev,selectedShapeIds:o.T.arrayOf(C),hintingShapeIds:o.T.arrayOf(C),erasingShapeIds:o.T.arrayOf(C),hoveredShapeId:C.nullable(),editingShapeId:C.nullable(),croppingShapeId:C.nullable(),focusedGroupId:C.nullable(),meta:o.T.jsonValue})),eN=(0,d.bo)("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),e$=(0,d.XD)({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:eN.AddCroppingId,up(e){e.croppingShapeId=null}},{id:eN.RemoveInstanceIdAndCameraId,up(e){delete e.instanceId,delete e.cameraId}},{id:eN.AddMeta,up:e=>{e.meta={}}},{id:eN.RenameProperties,up:e=>{},down:e=>{}},{id:eN.RenamePropertiesAgain,up:e=>{e.selectedShapeIds=e.selectedIds,delete e.selectedIds,e.hintingShapeIds=e.hintingIds,delete e.hintingIds,e.erasingShapeIds=e.erasingIds,delete e.erasingIds,e.hoveredShapeId=e.hoveredId,delete e.hoveredId,e.editingShapeId=e.editingId,delete e.editingId,e.croppingShapeId=e.croppingShapeId??e.croppingId??null,delete e.croppingId,e.focusedGroupId=e.focusLayerId,delete e.focusLayerId},down:e=>{e.selectedIds=e.selectedShapeIds,delete e.selectedShapeIds,e.hintingIds=e.hintingShapeIds,delete e.hintingShapeIds,e.erasingIds=e.erasingShapeIds,delete e.erasingShapeIds,e.hoveredId=e.hoveredShapeId,delete e.hoveredShapeId,e.editingId=e.editingShapeId,delete e.editingShapeId,e.croppingId=e.croppingShapeId,delete e.croppingShapeId,e.focusLayerId=e.focusedGroupId,delete e.focusedGroupId}}]}),eB=(0,d.WE)("instance_page_state",{validator:ez,scope:"session",ephemeralKeys:{pageId:!1,selectedShapeIds:!1,editingShapeId:!0,croppingShapeId:!1,meta:!1,hintingShapeIds:!0,erasingShapeIds:!0,hoveredShapeId:!0,focusedGroupId:!0}}).withDefaultProperties(()=>({editingShapeId:null,croppingShapeId:null,selectedShapeIds:[],hoveredShapeId:null,erasingShapeIds:[],hintingShapeIds:[],focusedGroupId:null,meta:{}})),eH=o.T.model("pointer",o.T.object({typeName:o.T.literal("pointer"),id:s("pointer"),x:o.T.number,y:o.T.number,lastActivityTimestamp:o.T.number,meta:o.T.jsonValue})),eU=(0,d.bo)("com.tldraw.pointer",{AddMeta:1}),eK=(0,d.XD)({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:eU.AddMeta,up:e=>{e.meta={}}}]}),eW=(0,d.WE)("pointer",{validator:eH,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),eV=eW.createId("pointer"),eY=o.T.model("instance_presence",o.T.object({typeName:o.T.literal("instance_presence"),id:s("instance_presence"),userId:eE,userName:o.T.string,lastActivityTimestamp:o.T.number.nullable(),followingUserId:eE.nullable(),cursor:o.T.object({x:o.T.number,y:o.T.number,type:eg,rotation:o.T.number}).nullable(),color:o.T.string,camera:o.T.object({x:o.T.number,y:o.T.number,z:o.T.number}).nullable(),screenBounds:w.nullable(),selectedShapeIds:o.T.arrayOf(s("shape")),currentPageId:s("page"),brush:w.nullable(),scribbles:o.T.arrayOf(ew),chatMessage:o.T.string,meta:o.T.jsonValue})),eG=(0,d.bo)("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5,NullableCameraCursor:6}),eq=(0,d.XD)({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:eG.AddScribbleDelay,up:e=>{null!==e.scribble&&(e.scribble.delay=0)}},{id:eG.RemoveInstanceId,up:e=>{delete e.instanceId}},{id:eG.AddChatMessage,up:e=>{e.chatMessage=""}},{id:eG.AddMeta,up:e=>{e.meta={}}},{id:eG.RenameSelectedShapeIds,up:e=>{}},{id:eG.NullableCameraCursor,up:e=>{},down:e=>{null===e.camera&&(e.camera={x:0,y:0,z:1}),null===e.lastActivityTimestamp&&(e.lastActivityTimestamp=0),null===e.cursor&&(e.cursor={type:"default",x:0,y:0,rotation:0}),null===e.screenBounds&&(e.screenBounds={x:0,y:0,w:1,h:1})}}]}),eX=(0,d.WE)("instance_presence",{validator:eY,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:null,followingUserId:null,color:"#FF0000",camera:null,cursor:null,screenBounds:null,selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}}));function eJ(e,t){let{instanceId:n,getUserPresence:r}=t??{},i=r??eZ;return t=>(0,ed.EW)("instancePresence",()=>{let r=e.get();if(!r)return null;let o=i(t,r);return o?eX.create({...o,id:n??eX.createId(t.id)}):null})}function eZ(e,t){let n=e.get(eF),r=e.get(eB.createId(n?.currentPageId)),i=e.get(ep.createId(n?.currentPageId)),o=e.get(eV);return r&&n&&i&&o?{selectedShapeIds:r.selectedShapeIds,brush:n.brush,scribbles:n.scribbles,userId:t.id,userName:t.name,followingUserId:n.followingUserId,camera:{x:i.x,y:i.y,z:i.z},color:t.color||"#FF0000",currentPageId:n.currentPageId,cursor:{x:o.x,y:o.y,rotation:n.cursor.rotation,type:n.cursor.type},lastActivityTimestamp:o.lastActivityTimestamp,screenBounds:n.screenBounds,chatMessage:n.chatMessage,meta:{}}:null}let eQ=(0,d.bo)("com.tldraw.asset",{AddMeta:1}),e0=(0,d.XD)({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:eQ.AddMeta,up:e=>{e.meta={}}}]}),e1=(0,d.WE)("asset",{scope:"document"}).withDefaultProperties(()=>({meta:{}})),e2=o.T.model("document",o.T.object({typeName:o.T.literal("document"),id:o.T.literal("document:document"),gridSize:o.T.number,name:o.T.string,meta:o.T.jsonValue})),e3=(0,d.bo)("com.tldraw.document",{AddName:1,AddMeta:2}),e5=(0,d.XD)({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:e3.AddName,up:e=>{e.name=""},down:e=>{delete e.name}},{id:e3.AddMeta,up:e=>{e.meta={}}}]}),e6=(0,d.WE)("document",{validator:e2,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),e4=e6.createId("document"),e8={w:o.T.nonZeroNumber,h:o.T.nonZeroNumber,assetId:a.nullable(),url:o.T.linkUrl},e9=F("bookmark",{NullAssetId:1,MakeUrlsValid:2}),e7={sequence:[{id:e9.NullAssetId,up:e=>{void 0===e.assetId&&(e.assetId=null)},down:"retired"},{id:e9.MakeUrlsValid,up:e=>{o.T.linkUrl.isValid(e.url)||(e.url="")},down:e=>{}}]},te=2,tt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",tn=new Uint8Array(128);for(let e=0;e<64;e++)tn[tt.charCodeAt(e)]=e;let tr=new Float64Array(31);for(let e=0;e<31;e++)tr[e]=Math.pow(2,e-15);let ti=6103515625e-14/1024,to=new Float64Array(1024);for(let e=0;e<1024;e++)to[e]=1+e/1024;let ts="function"==typeof DataView.prototype.getFloat16?function(e,t){return e.getFloat16(t,!0)}:function(e,t){return function(e){let t=e>>15,n=e>>10&31,r=1023&e;if(0===n)return t?-r*ti:r*ti;if(31===n)return r?NaN:t?-1/0:1/0;let i=tr[n]*to[r];return t?-i:i}(e.getUint16(t,!0))},ta="function"==typeof DataView.prototype.setFloat16?function(e,t,n){e.setFloat16(t,n,!0)}:function(e,t,n){e.setUint16(t,function(e){if(0===e)return 32768*!!Object.is(e,-0);if(!Number.isFinite(e))return Number.isNaN(e)?32256:e>0?31744:64512;let t=+(e<0),n=Math.floor(Math.log2(e=Math.abs(e))),r=n+15;if(r>=31)return t<<15|31744;if(r<=0)return t<<15|1023&Math.round(16384*e*1024);let i=Math.round(1024*(e/Math.pow(2,n)-1));return i>=1024&&(i=0,++r>=31)?t<<15|31744:t<<15|r<<10|i}(n),!0)},tl="function"==typeof Uint8Array.prototype.toBase64?function(e){return e.toBase64()}:function(e){let t=e.length,n=3*Math.floor(t/3),r="";for(let t=0;t<n;t+=3){let n=e[t]<<16|e[t+1]<<8|e[t+2];r+=tt[n>>18&63]+tt[n>>12&63]+tt[n>>6&63]+tt[63&n]}let i=t-n;if(1===i){let t=e[n]<<16;r+=tt[t>>18&63]+tt[t>>12&63]+"=="}else if(2===i){let t=e[n]<<16|e[n+1]<<8;r+=tt[t>>18&63]+tt[t>>12&63]+tt[t>>6&63]+"="}return r},td="function"==typeof Uint8Array.fromBase64?function(e){return Uint8Array.fromBase64(e)}:function(e){let t=e.length,n=0;t>0&&61===e.charCodeAt(t-1)&&(n++,t>1&&61===e.charCodeAt(t-2)&&n++);let r=new Uint8Array(Math.floor(3*t/4)-n),i=0,o=4*Math.floor((t-n)/4);for(let t=0;t<o;t+=4){let n=tn[e.charCodeAt(t)]<<18|tn[e.charCodeAt(t+1)]<<12|tn[e.charCodeAt(t+2)]<<6|tn[e.charCodeAt(t+3)];r[i++]=n>>16&255,r[i++]=n>>8&255,r[i++]=255&n}if(1===n){let t=tn[e.charCodeAt(o)]<<18|tn[e.charCodeAt(o+1)]<<12|tn[e.charCodeAt(o+2)]<<6;r[i++]=t>>16&255,r[i++]=t>>8&255}else if(2===n){let t=tn[e.charCodeAt(o)],n=tn[e.charCodeAt(o+1)];r[i++]=(t<<18|n<<12)>>16&255}return r};class tc{static _legacyEncodePoint(e,t,n){let r=new Uint8Array(6),i=new DataView(r.buffer);return ta(i,0,e),ta(i,2,t),ta(i,4,n),tl(r)}static _legacyEncodePoints(e){if(0===e.length)return"";let t=new Uint8Array(6*e.length),n=new DataView(t.buffer);for(let t=0;t<e.length;t++){let r=e[t],i=6*t;ta(n,i,r.x),ta(n,i+2,r.y),ta(n,i+4,r.z??.5)}return tl(t)}static _legacyDecodePoints(e){let t=td(e),n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=[];for(let e=0;e<t.length;e+=6)r.push({x:ts(n,e),y:ts(n,e+2),z:ts(n,e+4)});return r}static encodePoints(e,t){if(t===te)return tc.encodePoints2D(e);if(0===e.length)return"";let n=new Uint8Array(12+(e.length-1)*6),r=new DataView(n.buffer),i=e[0];r.setFloat32(0,i.x,!0),r.setFloat32(4,i.y,!0),r.setFloat32(8,i.z??.5,!0);let o=i.x,s=i.y,a=i.z??.5;for(let t=1;t<e.length;t++){let n=e[t],i=n.z??.5,l=12+(t-1)*6;ta(r,l,n.x-o),ta(r,l+2,n.y-s),ta(r,l+4,i-a),o=n.x,s=n.y,a=i}return tl(n)}static decodePoints(e,t){if(t===te)return tc.decodePoints2D(e);if(0===e.length)return[];let n=td(e),r=new DataView(n.buffer,n.byteOffset,n.byteLength),i=[],o=r.getFloat32(0,!0),s=r.getFloat32(4,!0),a=r.getFloat32(8,!0);i.push({x:o,y:s,z:a});for(let e=12;e<n.length;e+=6)o+=ts(r,e),s+=ts(r,e+2),i.push({x:o,y:s,z:a+=ts(r,e+4)});return i}static decodeFirstPoint(e,t){if(t===te)return tc.decodeFirstPoint2D(e);if(e.length<16)return null;let n=td(e.slice(0,16)),r=new DataView(n.buffer,n.byteOffset,n.byteLength);return{x:r.getFloat32(0,!0),y:r.getFloat32(4,!0),z:r.getFloat32(8,!0)}}static decodeLastPoint(e,t){if(t===te)return tc.decodeLastPoint2D(e);if(e.length<16)return null;let n=td(e),r=new DataView(n.buffer,n.byteOffset,n.byteLength),i=r.getFloat32(0,!0),o=r.getFloat32(4,!0),s=r.getFloat32(8,!0);for(let e=12;e<n.length;e+=6)i+=ts(r,e),o+=ts(r,e+2),s+=ts(r,e+4);return{x:i,y:o,z:s}}static encodePoints2D(e){if(0===e.length)return"";let t=new Uint8Array(8+(e.length-1)*4),n=new DataView(t.buffer),r=e[0];n.setFloat32(0,r.x,!0),n.setFloat32(4,r.y,!0);let i=r.x,o=r.y;for(let t=1;t<e.length;t++){let r=e[t],s=8+(t-1)*4;ta(n,s,r.x-i),ta(n,s+2,r.y-o),i=r.x,o=r.y}return tl(t)}static decodePoints2D(e){if(0===e.length)return[];let t=td(e),n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=[],i=n.getFloat32(0,!0),o=n.getFloat32(4,!0);r.push({x:i,y:o,z:.5});for(let e=8;e<t.length;e+=4)i+=ts(n,e),r.push({x:i,y:o+=ts(n,e+2),z:.5});return r}static decodeFirstPoint2D(e){if(e.length<12)return null;let t=td(e.slice(0,12)),n=new DataView(t.buffer,t.byteOffset,t.byteLength);return{x:n.getFloat32(0,!0),y:n.getFloat32(4,!0),z:.5}}static decodeLastPoint2D(e){if(e.length<12)return null;let t=td(e),n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getFloat32(0,!0),i=n.getFloat32(4,!0);for(let e=8;e<t.length;e+=4)r+=ts(n,e),i+=ts(n,e+2);return{x:r,y:i,z:.5}}static isSinglePoint(e,t){return e.length<=(t===te?12:16)}}let th=o.T.object({type:o.T.literalEnum("free","straight"),path:o.T.string,dim:o.T.literalEnum(te,3).optional()}),tu={color:B,fill:W,dash:K,size:X,segments:o.T.arrayOf(th),isComplete:o.T.boolean,isClosed:o.T.boolean,isPen:o.T.boolean,scale:o.T.nonZeroNumber,scaleX:o.T.nonZeroFiniteNumber,scaleY:o.T.nonZeroFiniteNumber},tp=F("draw",{AddInPen:1,AddScale:2,Base64:3,LegacyPointsConversion:4,OmitNonPressureZ:5}),tf={sequence:[{id:tp.AddInPen,up:e=>{let{points:t}=e.segments[0];if(0===t.length){e.isPen=!1;return}let n=0!==t[0].z&&.5!==t[0].z;t[1]&&(n=n&&0!==t[1].z&&.5!==t[1].z),e.isPen=n},down:"retired"},{id:tp.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}},{id:tp.Base64,up:e=>{e.segments=e.segments.map(e=>{if(void 0!==e.path)return e;let{points:t,...n}=e,r=Array.isArray(t)?t:tc._legacyDecodePoints(t);return{...n,path:tc.encodePoints(r)}}),e.scaleX=e.scaleX??1,e.scaleY=e.scaleY??1},down:e=>{e.segments=e.segments.map(e=>{let{path:t,...n}=e;return{...n,points:tc.decodePoints(t)}}),delete e.scaleX,delete e.scaleY}},{id:tp.LegacyPointsConversion,up:e=>{e.segments=e.segments.map(e=>{if(void 0!==e.path)return e;let{points:t,...n}=e,r=Array.isArray(t)?t:tc._legacyDecodePoints(t);return{...n,path:tc.encodePoints(r)}})},down:e=>{}},{id:tp.OmitNonPressureZ,up:e=>{},down:e=>{e.segments=e.segments.map(e=>{if(void 0===e.dim)return e;let{dim:t,...n}=e;return t===te?{...n,path:tc.encodePoints(tc.decodePoints(e.path,te))}:n})}}]},tg=/(^\/r\/[^/]+\/?$)/,tm=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e);if(t&&t.pathname.match(tg))return e}},{hostnames:["figma.com"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e);if(t&&t.pathname.match(/^\/embed\/?$/)){let e=t.searchParams.get("url");if(e)return e}}},{hostnames:["google.*"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e);if(t&&t.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&t.searchParams.has("center")&&t.searchParams.get("zoom")){let e=t.searchParams.get("zoom"),[n,r]=t.searchParams.get("center").split(",");return`https://www.google.com/maps/@${n},${r},${e}z`}}},{hostnames:["val.town"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e),n=t&&t.pathname.match(/\/embed\/(.+)\/?/);if(n)return`https://www.val.town/v/${n[1]}`}},{hostnames:["codesandbox.io"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e),n=t&&t.pathname.match(/\/embed\/([^/]+)\/?/);if(n)return`https://codesandbox.io/s/${n[1]}`}},{hostnames:["codepen.io"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=e.match(/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/);if(t){let[e,n,r]=t;return`https://codepen.io/${n}/pen/${r}`}}},{hostnames:["scratch.mit.edu"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=e.match(/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/);if(t){let[e,n]=t;return`https://scratch.mit.edu/projects/${n}`}}},{hostnames:["*.youtube.com","youtube.com","youtu.be"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e);if(t&&"youtube.com"===t.hostname.replace(/^www./,"")){let e=t.pathname.match(/^\/embed\/([^/]+)\/?/);if(e)return`https://www.youtube.com/watch?v=${e[1]}`}}},{hostnames:["calendar.google.*"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e),n=t?.searchParams.get("src");if(t?.pathname.match(/\/calendar\/embed/)&&n){for(let e of(t.pathname="/calendar/u/0",Array.from(t.searchParams.keys())))t.searchParams.delete(e);return t.searchParams.set("cid",n),t.href}}},{hostnames:["docs.google.*"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e);if(t?.pathname.match(/^\/presentation/)&&t?.pathname.match(/\/embed\/?$/)){for(let e of(t.pathname=t.pathname.replace(/\/embed$/,"/pub"),Array.from(t.searchParams.keys())))t.searchParams.delete(e);return t.href}}},{hostnames:["gist.github.com"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e);if(t&&t.pathname.match(/\/([^/]+)\/([^/]+)/)){if(!e.split("/").pop())return;return e}}},{hostnames:["replit.com"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e);if(t&&t.pathname.match(/\/@([^/]+)\/([^/]+)/)&&t.searchParams.has("embed"))return t.searchParams.delete("embed"),t.href}},{hostnames:["felt.com"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e);if(t&&t.pathname.match(/^\/embed\/map\//))return t.pathname=t.pathname.replace(/^\/embed/,""),t.href}},{hostnames:["open.spotify.com"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e);if(t&&t.pathname.match(/^\/embed\/(artist|album)\//))return t.origin+t.pathname.replace(/^\/embed/,"")}},{hostnames:["vimeo.com","player.vimeo.com"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e);if(t&&"player.vimeo.com"===t.hostname){let e=t.pathname.match(/^\/video\/([^/]+)\/?$/);if(e)return"https://vimeo.com/"+e[1]}}},{hostnames:["observablehq.com"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e);return t&&t.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/)?`${t.origin}${t.pathname.replace("/embed","")}#cell-*`:t&&t.pathname.match(/^\/embed\/([^/]+)\/?$/)?`${t.origin}${t.pathname.replace("/embed","/d")}#cell-*`:void 0}},{hostnames:["desmos.com"],canEditWhileLocked:!0,fromEmbedUrl:e=>{let t=(0,i.yC)(e);if(t&&"www.desmos.com"===t.hostname&&t.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&"?embed"===t.search&&""===t.hash)return e.replace("?embed","")}}],ty={w:o.T.nonZeroNumber,h:o.T.nonZeroNumber,url:o.T.string},tb=F("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),tx={sequence:[{id:tb.GenOriginalUrlInEmbed,up:e=>{try{let t,n=e.url,r=new URL(n).host.replace("www.","");for(let e of tm)if(e.hostnames.includes(r))try{t=e.fromEmbedUrl(n)}catch(e){console.warn(e)}e.tmpOldUrl=e.url,e.url=t??""}catch{e.url="",e.tmpOldUrl=e.url}},down:"retired"},{id:tb.RemoveDoesResize,up:e=>{delete e.doesResize},down:"retired"},{id:tb.RemoveTmpOldUrl,up:e=>{delete e.tmpOldUrl},down:"retired"},{id:tb.RemovePermissionOverrides,up:e=>{delete e.overridePermissions},down:"retired"}]},tw={w:o.T.nonZeroNumber,h:o.T.nonZeroNumber,name:o.T.string,color:{validate:e=>B.validate(e)}},tv={sequence:[{id:F("frame",{AddColorProp:1}).AddColorProp,up:e=>{e.color="black"},down:e=>{delete e.color}}]},tS=_.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),tC=_.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),tk=_.defineEnum("tldraw:geo",{defaultValue:"rectangle",values:["cloud","rectangle","ellipse","triangle","diamond","pentagon","hexagon","octagon","star","rhombus","rhombus-2","oval","trapezoid","arrow-right","arrow-left","arrow-up","arrow-down","x-box","check-box","heart"]}),tP={geo:tk,dash:K,url:o.T.linkUrl,w:o.T.nonZeroNumber,h:o.T.nonZeroNumber,growY:o.T.positiveNumber,scale:o.T.nonZeroNumber,flipX:o.T.boolean,flipY:o.T.boolean,labelColor:H,color:B,fill:W,size:X,font:V,align:tS,verticalAlign:tC,richText:E},tT=F("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9,AddRichText:10,AddRichTextAttrs:11,AddFlipProps:12}),tE={sequence:[{id:tT.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:tT.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"},{id:tT.RemoveJustify,up:e=>{"justify"===e.align&&(e.align="start")},down:"retired"},{id:tT.AddCheckBox,up:e=>{},down:"retired"},{id:tT.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:tT.MigrateLegacyAlign,up:e=>{let t;switch(e.align){case"start":t="start-legacy";break;case"end":t="end-legacy";break;default:t="middle-legacy"}e.align=t},down:"retired"},{id:tT.AddCloud,up:e=>{},down:"retired"},{id:tT.MakeUrlsValid,up:e=>{o.T.linkUrl.isValid(e.url)||(e.url="")},down:e=>{}},{id:tT.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}},{id:tT.AddRichText,up:e=>{e.richText=I(e.text),delete e.text}},{id:tT.AddRichTextAttrs,up:e=>{},down:e=>{e.richText&&"attrs"in e.richText&&delete e.richText.attrs}},{id:tT.AddFlipProps,up:e=>{e.flipX=!1,e.flipY=!1},down:e=>{delete e.flipX,delete e.flipY}}]},tI={},t_={sequence:[]},tM={color:B,size:X,segments:o.T.arrayOf(th),isComplete:o.T.boolean,isPen:o.T.boolean,scale:o.T.nonZeroNumber,scaleX:o.T.nonZeroFiniteNumber,scaleY:o.T.nonZeroFiniteNumber},tA=F("highlight",{AddScale:1,Base64:2,LegacyPointsConversion:3,OmitNonPressureZ:4}),tj={sequence:[{id:tA.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}},{id:tA.Base64,up:e=>{e.segments=e.segments.map(e=>{if(void 0!==e.path)return e;let{points:t,...n}=e,r=Array.isArray(t)?t:tc._legacyDecodePoints(t);return{...n,path:tc.encodePoints(r)}}),e.scaleX=e.scaleX??1,e.scaleY=e.scaleY??1},down:e=>{e.segments=e.segments.map(e=>{let{path:t,...n}=e;return{...n,points:tc.decodePoints(t)}}),delete e.scaleX,delete e.scaleY}},{id:tA.LegacyPointsConversion,up:e=>{e.segments=e.segments.map(e=>{if(void 0!==e.path)return e;let{points:t,...n}=e,r=Array.isArray(t)?t:tc._legacyDecodePoints(t);return{...n,path:tc.encodePoints(r)}})},down:e=>{}},{id:tA.OmitNonPressureZ,up:e=>{},down:e=>{e.segments=e.segments.map(e=>{if(void 0===e.dim)return e;let{dim:t,...n}=e;return t===te?{...n,path:tc.encodePoints(tc.decodePoints(e.path,te))}:n})}}]},tO=o.T.object({topLeft:x,bottomRight:x,isCircle:o.T.boolean.optional()}),tD={w:o.T.nonZeroNumber,h:o.T.nonZeroNumber,playing:o.T.boolean,url:o.T.linkUrl,assetId:a.nullable(),crop:tO.nullable(),flipX:o.T.boolean,flipY:o.T.boolean,altText:o.T.string},tL=F("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4,AddAltText:5}),tR={sequence:[{id:tL.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:tL.AddCropProp,up:e=>{e.crop=null},down:e=>{delete e.crop}},{id:tL.MakeUrlsValid,up:e=>{o.T.linkUrl.isValid(e.url)||(e.url="")},down:e=>{}},{id:tL.AddFlipProps,up:e=>{e.flipX=!1,e.flipY=!1},down:e=>{delete e.flipX,delete e.flipY}},{id:tL.AddAltText,up:e=>{e.altText=""},down:e=>{delete e.altText}}]},tF=_.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),tz=o.T.object({id:o.T.string,index:o.T.indexKey,x:o.T.number,y:o.T.number}),tN={color:B,dash:K,size:X,spline:tF,points:o.T.dict(o.T.string,tz),scale:o.T.nonZeroNumber},t$=F("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),tB={sequence:[{id:t$.AddSnapHandles,up:e=>{for(let t of Object.values(e.handles))t.canSnap=!0},down:"retired"},{id:t$.RemoveExtraHandleProps,up:e=>{e.handles=(0,i._e)(Object.values(e.handles).map(e=>[e.index,{x:e.x,y:e.y}]))},down:e=>{let t=Object.entries(e.handles).map(([e,t])=>({index:e,...t})).sort(i.Ky);e.handles=Object.fromEntries(t.map((e,n)=>{let r=0===n?"start":n===t.length-1?"end":`handle:${e.index}`;return[r,{id:r,type:"vertex",canBind:!1,canSnap:!0,index:e.index,x:e.x,y:e.y}]}))}},{id:t$.HandlesToPoints,up:e=>{let t=Object.entries(e.handles).map(([e,{x:t,y:n}])=>({x:t,y:n,index:e})).sort(i.Ky);e.points=t.map(({x:e,y:t})=>({x:e,y:t})),delete e.handles},down:e=>{let t=(0,i.uu)(e.points.length);e.handles=Object.fromEntries(e.points.map((e,n)=>[t[n],{x:e.x,y:e.y}])),delete e.points}},{id:t$.PointIndexIds,up:e=>{let t=(0,i.uu)(e.points.length);e.points=Object.fromEntries(e.points.map((e,n)=>{let r=t[n];return[r,{id:r,index:r,x:e.x,y:e.y}]}))},down:e=>{let t=Object.values(e.points).sort(i.Ky);e.points=t.map(({x:e,y:t})=>({x:e,y:t}))}},{id:t$.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},tH={color:B,labelColor:H,size:X,font:V,fontSizeAdjustment:o.T.positiveNumber.nullable(),align:tS,verticalAlign:tC,growY:o.T.positiveNumber,url:o.T.linkUrl,richText:E,scale:o.T.nonZeroNumber,textLastEditedBy:o.T.string.nullable()},tU=F("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7,AddLabelColor:8,AddRichText:9,AddRichTextAttrs:10,AddFirstEditedBy:11,MakeFontSizeAdjustmentRatio:12,RenameFirstEditedByToLast:13}),tK={sequence:[{id:tU.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:tU.RemoveJustify,up:e=>{"justify"===e.align&&(e.align="start")},down:"retired"},{id:tU.MigrateLegacyAlign,up:e=>{switch(e.align){case"start":e.align="start-legacy";return;case"end":e.align="end-legacy";return;default:e.align="middle-legacy";return}},down:"retired"},{id:tU.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:tU.MakeUrlsValid,up:e=>{o.T.linkUrl.isValid(e.url)||(e.url="")},down:e=>{}},{id:tU.AddFontSizeAdjustment,up:e=>{e.fontSizeAdjustment=0},down:e=>{delete e.fontSizeAdjustment}},{id:tU.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}},{id:tU.AddLabelColor,up:e=>{e.labelColor="black"},down:e=>{delete e.labelColor}},{id:tU.AddRichText,up:e=>{e.richText=I(e.text),delete e.text}},{id:tU.AddRichTextAttrs,up:e=>{},down:e=>{e.richText&&"attrs"in e.richText&&delete e.richText.attrs}},{id:tU.AddFirstEditedBy,up:e=>{e.textFirstEditedBy=null},down:e=>{delete e.textFirstEditedBy}},{id:tU.MakeFontSizeAdjustmentRatio,up:e=>{e.fontSizeAdjustment=0===e.fontSizeAdjustment?1:null},down:e=>{e.fontSizeAdjustment=0}},{id:tU.RenameFirstEditedByToLast,up:e=>{e.textLastEditedBy=e.textFirstEditedBy??null,delete e.textFirstEditedBy},down:e=>{e.textFirstEditedBy=e.textLastEditedBy??null,delete e.textLastEditedBy}}]},tW=_.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),tV={color:B,size:X,font:V,textAlign:tW,w:o.T.nonZeroNumber,richText:E,scale:o.T.nonZeroNumber,autoSize:o.T.boolean},tY=F("text",{RemoveJustify:1,AddTextAlign:2,AddRichText:3,AddRichTextAttrs:4}),tG={sequence:[{id:tY.RemoveJustify,up:e=>{"justify"===e.align&&(e.align="start")},down:"retired"},{id:tY.AddTextAlign,up:e=>{e.textAlign=e.align,delete e.align},down:e=>{e.align=e.textAlign,delete e.textAlign}},{id:tY.AddRichText,up:e=>{e.richText=I(e.text),delete e.text}},{id:tY.AddRichTextAttrs,up:e=>{},down:e=>{e.richText&&"attrs"in e.richText&&delete e.richText.attrs}}]},tq={w:o.T.nonZeroNumber,h:o.T.nonZeroNumber,time:o.T.number,playing:o.T.boolean,autoplay:o.T.boolean,url:o.T.linkUrl,assetId:a.nullable(),altText:o.T.string},tX=F("video",{AddUrlProp:1,MakeUrlsValid:2,AddAltText:3,AddAutoplay:4}),tJ={sequence:[{id:tX.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:tX.MakeUrlsValid,up:e=>{o.T.linkUrl.isValid(e.url)||(e.url="")},down:e=>{}},{id:tX.AddAltText,up:e=>{e.altText=""},down:e=>{delete e.altText}},{id:tX.AddAutoplay,up:e=>{e.autoplay=!0},down:e=>{delete e.autoplay}}]},tZ=(0,d.bo)("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4,FixIndexKeys:5}),tQ=(0,d._B)({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:tZ.RemoveCodeAndIconShapeTypes,scope:"storage",up:e=>{for(let[t,n]of e.entries())"shape"===n.typeName&&"type"in n&&("icon"===n.type||"code"===n.type)&&e.delete(t)}},{id:tZ.AddInstancePresenceType,scope:"storage",up(e){}},{id:tZ.RemoveTLUserAndPresenceAndAddPointer,scope:"storage",up:e=>{for(let[t,n]of e.entries())n.typeName.match(/^(user|user_presence)$/)&&e.delete(t)}},{id:tZ.RemoveUserDocument,scope:"storage",up:e=>{for(let[t,n]of e.entries())n.typeName.match("user_document")&&e.delete(t)}},{id:tZ.FixIndexKeys,scope:"record",up:e=>{if(["shape","page"].includes(e.typeName)&&"index"in e&&(e.index.endsWith("0")&&"a0"!==e.index&&(e.index=e.index.slice(0,-1)+t2(3)),"shape"===e.typeName&&"line"===e.type))for(let[t,n]of(0,i.iA)(e.props.points))n.index.endsWith("0")&&"a0"!==n.index&&(n.index=n.index.slice(0,-1)+t2(3))},down:()=>{}}]}),t0="123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t1=()=>t0.charAt(Math.floor(Math.random()*t0.length)),t2=e=>Array.from({length:e},t1).join("");function t3(e){"asset"===e.typeName&&("src"in e&&(e.src="<redacted>"),"src"in e.props&&(e.props.src="<redacted>"))}function t5(e){let t=new Map;return n=>{let r=t.get(n);return r||(r=(0,ed.EW)("resolve-user-"+n,()=>e(n)),t.set(n,r)),r}}function t6({error:e,phase:t,record:n,recordBefore:r}){throw(0,i.TF)(e,{tags:{origin:"store.validateRecord",storePhase:t,isExistingValidationIssue:"initialize"===t},extras:{recordBefore:r?t3((0,i.pN)(r)):void 0,recordAfter:t3((0,i.pN)(n))}}),e}function t4(e){let t=e.query.ids("page"),n=e.query.records("instance_page_state"),r=()=>{if(!e.has(e4))return e.put([e6.create({id:e4,name:e.props.defaultName})]),r();if(!e.has(eV))return e.put([eW.create({id:eV})]),r();let o=t.get();if(0===o.size)return e.put([eP.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]),r();let s=()=>[...o].map(t=>e.get(t)).sort(i.Ky)[0].id,a=e.get(eF);if(!a)return e.put([e.schema.types.instance.create({id:eF,currentPageId:s(),exportBackground:!0})]),r();if(!o.has(a.currentPageId))return e.put([{...a,currentPageId:s()}]),r();let l=new Set,d=new Set;for(let t of o){let n=eB.createId(t);e.get(n)||l.add(n);let r=ep.createId(t);e.has(r)||d.add(r)}for(let t of(l.size>0&&e.put([...l].map(e=>eB.create({id:e,pageId:eB.parseId(e)}))),d.size>0&&e.put([...d].map(e=>ep.create({id:e}))),n.get())){if(!o.has(t.pageId)){e.remove([t.id]);continue}if(t.croppingShapeId&&!e.has(t.croppingShapeId))return e.put([{...t,croppingShapeId:null}]),r();if(t.focusedGroupId&&!e.has(t.focusedGroupId))return e.put([{...t,focusedGroupId:null}]),r();if(t.hoveredShapeId&&!e.has(t.hoveredShapeId))return e.put([{...t,hoveredShapeId:null}]),r();let n=t.selectedShapeIds.filter(t=>e.has(t));if(n.length!==t.selectedShapeIds.length)return e.put([{...t,selectedShapeIds:n}]),r();let i=t.hintingShapeIds.filter(t=>e.has(t));if(i.length!==t.hintingShapeIds.length)return e.put([{...t,hintingShapeIds:i}]),r();let s=t.erasingShapeIds.filter(t=>e.has(t));if(s.length!==t.erasingShapeIds.length)return e.put([{...t,erasingShapeIds:s}]),r()}};return r}let t8={arrow:{migrations:ei,props:et},bookmark:{migrations:e7,props:e8},draw:{migrations:tf,props:tu},embed:{migrations:tx,props:ty},frame:{migrations:tv,props:tw},geo:{migrations:tE,props:tP},group:{migrations:t_,props:tI},highlight:{migrations:tj,props:tM},image:{migrations:tR,props:tD},line:{migrations:tB,props:tN},note:{migrations:tK,props:tH},text:{migrations:tG,props:tV},video:{migrations:tJ,props:tq}},t9={arrow:{migrations:el,props:es}},t7={image:{migrations:g,props:p},video:{migrations:b,props:m},bookmark:{migrations:u,props:c}};function ne({shapes:e=t8,bindings:t=t9,assets:n=t7,user:r,records:a={},migrations:c}={}){let h=new Map;for(let t of(0,i.Ic)(e))for(let e of R(t.props??{}).keys()){if(h.has(e.id)&&h.get(e.id)!==e)throw Error(`Multiple StyleProp instances with the same id: ${e.id}`);h.set(e.id,e)}let u=(0,d.WE)("shape",{scope:"document",validator:o.T.model("shape",o.T.union("type",(0,i._H)(e,(e,{props:t,meta:n})=>o.T.object({id:C,typeName:o.T.literal("shape"),x:o.T.number,y:o.T.number,rotation:o.T.number,index:o.T.indexKey,parentId:S,type:o.T.literal(e),isLocked:o.T.boolean,opacity:v,props:t?o.T.object(t):o.T.jsonValue,meta:n?o.T.object(n):o.T.jsonValue}))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}})),p=(0,d.WE)("binding",{scope:"document",validator:o.T.model("binding",o.T.union("type",(0,i._H)(t,(e,{props:t,meta:n})=>o.T.object({id:k,typeName:o.T.literal("binding"),type:o.T.literal(e),fromId:C,toId:C,props:t?o.T.object(t):o.T.jsonValue,meta:n?o.T.object(n):o.T.jsonValue}))))}).withDefaultProperties(()=>({meta:{}})),f=(0,d.WE)("asset",{scope:"document",validator:o.T.model("asset",o.T.union("type",(0,i._H)(n,(e,{props:t,meta:n})=>l(e,t,n))))}).withDefaultProperties(()=>({meta:{}})),g=function(e){let t={};for(let[n,r]of e)t[n]=o.T.optional(r);let n=o.T.model("instance",o.T.object({typeName:o.T.literal("instance"),id:s("instance"),currentPageId:ev,followingUserId:eE.nullable(),brush:w.nullable(),opacityForNextShape:v,stylesForNextShape:o.T.object(t),cursor:em,scribbles:o.T.arrayOf(ew),isFocusMode:o.T.boolean,isDebugMode:o.T.boolean,isToolLocked:o.T.boolean,exportBackground:o.T.boolean,screenBounds:w,insets:o.T.arrayOf(o.T.boolean),zoomBrush:w.nullable(),isPenMode:o.T.boolean,isGridMode:o.T.boolean,chatMessage:o.T.string,isChatting:o.T.boolean,highlightedUserIds:o.T.arrayOf(eE),isFocused:o.T.boolean,devicePixelRatio:o.T.number,isCoarsePointer:o.T.boolean,isHoveringCanvas:o.T.boolean.nullable(),openMenus:o.T.arrayOf(o.T.string),isChangingStyle:o.T.boolean,isReadonly:o.T.boolean,meta:o.T.jsonValue,duplicateProps:o.T.object({shapeIds:o.T.arrayOf(s("shape")),offset:o.T.object({x:o.T.number,y:o.T.number})}).nullable(),cameraState:o.T.literalEnum("idle","moving")}));return(0,d.WE)("instance",{validator:n,scope:"session",ephemeralKeys:{currentPageId:!1,meta:!1,followingUserId:!0,opacityForNextShape:!0,stylesForNextShape:!0,brush:!0,cursor:!0,scribbles:!0,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!0,isPenMode:!0,isGridMode:!0,chatMessage:!0,isChatting:!0,highlightedUserIds:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!0,openMenus:!0,isChangingStyle:!0,isReadonly:!0,duplicateProps:!0,cameraState:!0}}).withDefaultProperties(()=>({followingUserId:null,opacityForNextShape:1,stylesForNextShape:{},brush:null,scribbles:[],cursor:{type:"default",rotation:0},isFocusMode:!1,exportBackground:!1,isDebugMode:!1,isToolLocked:!1,screenBounds:{x:0,y:0,w:1080,h:720},insets:[!1,!1,!1,!1],zoomBrush:null,isGridMode:!1,isPenMode:!1,chatMessage:"",isChatting:!1,highlightedUserIds:[],isFocused:!1,devicePixelRatio:"u"<typeof window?1:window.devicePixelRatio,isCoarsePointer:!1,isHoveringCanvas:null,openMenus:[],isChangingStyle:!1,isReadonly:!1,meta:{},duplicateProps:null,cameraState:"idle"}))}(h),m=r?eM(r):eA,y=new Set(["asset","binding","camera","document","instance","instance_page_state","page","instance_presence","pointer","shape","store","user"]),b={};for(let[e,t]of Object.entries(a)){if(y.has(e))throw Error(`Custom record type name '${e}' conflicts with tldraw's built-in record type of that name. Choose a different name instead.`);b[e]=(0,d.WE)(e,{scope:t.scope,validator:t.validator}).withDefaultProperties(t.createDefaultProperties??(()=>({})))}return d.fX.create({asset:f,binding:p,camera:ep,document:e6,instance:g,instance_page_state:eB,page:eP,instance_presence:eX,pointer:eW,shape:u,user:m,...b},{migrations:[tQ,e0,eu,e5,eR,e$,ek,eq,eK,j,e_,...z("asset",n),...z("shape",e),...z("binding",t),...function(e){let t=[];for(let[n,r]of Object.entries(e)){let e=`com.tldraw.${n}`,{migrations:o}=r;o?"sequenceId"in o?((0,i.vA)(e===o.sequenceId,`sequenceId mismatch for ${n} custom record migrations. Expected '${e}', got '${o.sequenceId}'`),t.push(o)):"sequence"in o&&t.push((0,d._B)({sequenceId:e,retroactive:!0,sequence:o.sequence.map(e=>"id"in e?{id:e.id,dependsOn:e.dependsOn,scope:"record",filter:e=>e.typeName===n,up:t=>{let n=e.up(t);if(n)return n},down:"function"==typeof e.down?t=>{let n=e.down(t);if(n)return n}:void 0}:e)})):t.push((0,d._B)({sequenceId:e,retroactive:!0,sequence:[]}))}return t}(a),...r?.migrations??[],...c??[]],onValidationFailure:t6,createIntegrityChecker:t4})}let nt=o.T.string.check(e=>{if(0===e.length||e.length>64)throw new o.T.ValidationError(`Expected an emoji of 1-64 characters, got ${e.length}`)}),nn=o.T.union("type",{shape:o.T.object({type:o.T.literal("shape"),shapeId:s("shape"),x:o.T.number,y:o.T.number,isPrecise:o.T.boolean}),point:o.T.object({type:o.T.literal("point"),x:o.T.number,y:o.T.number}),region:o.T.object({type:o.T.literal("region"),x:o.T.number,y:o.T.number,w:o.T.number,h:o.T.number,pinX:o.T.number.optional(),pinY:o.T.number.optional()}),page:o.T.object({type:o.T.literal("page")})});function nr(e,t=[]){return(0,d.XD)({sequenceId:`com.tldraw.${e}`,recordType:e,retroactive:!0,sequence:[{id:`com.tldraw.${e}/1`,up:e=>e},...t]})}nr("comment-thread",[{id:"com.tldraw.comment-thread/2",up:e=>{let t=e.anchor;return t?.type==="shape"&&void 0===t.x&&(e.anchor={...t,x:1,y:0,isPrecise:!1}),e},down:e=>{let t=e.anchor;return t?.type==="shape"&&(e.anchor={type:"shape",shapeId:t.shapeId}),e}},{id:"com.tldraw.comment-thread/3",up:e=>e,down:e=>{let t=e.anchor;if(t?.type==="region"){let{pinX:n,pinY:r,...i}=t;e.anchor=i}return e}}]),o.T.object({id:s("comment-thread"),typeName:o.T.literal("comment-thread"),pageId:s("page"),anchor:nn,createdBy:o.T.string,createdAt:o.T.number,resolved:o.T.object({at:o.T.number,by:o.T.string}).nullable(),isDeleted:o.T.boolean,meta:o.T.jsonValue}),nr("comment"),o.T.object({id:s("comment"),typeName:o.T.literal("comment"),threadId:s("comment-thread"),pageId:s("page"),authorId:o.T.string,createdAt:o.T.number,editedAt:o.T.number.nullable(),body:E,isDeleted:o.T.boolean,meta:o.T.jsonValue}),nr("comment-reaction"),o.T.object({id:s("comment-reaction"),typeName:o.T.literal("comment-reaction"),commentId:s("comment"),threadId:s("comment-thread"),pageId:s("page"),userId:o.T.string,emoji:nt,createdAt:o.T.number,meta:o.T.jsonValue});let ni=[{locale:"id",label:"Bahasa Indonesia"},{locale:"ms",label:"Bahasa Melayu"},{locale:"ca",label:"Catal\xe0"},{locale:"cs",label:"Čeština"},{locale:"da",label:"Danish"},{locale:"de",label:"Deutsch"},{locale:"en",label:"English"},{locale:"es",label:"Espa\xf1ol"},{locale:"tl",label:"Filipino"},{locale:"fr",label:"Fran\xe7ais"},{locale:"gl",label:"Galego"},{locale:"hr",label:"Hrvatski"},{locale:"it",label:"Italiano"},{locale:"hu",label:"Magyar"},{locale:"nl",label:"Nederlands"},{locale:"no",label:"Norwegian"},{locale:"pl",label:"Polski"},{locale:"pt-br",label:"Portugu\xeas - Brasil"},{locale:"pt-pt",label:"Portugu\xeas - Europeu"},{locale:"ro",label:"Rom\xe2nă"},{locale:"sl",label:"Slovenščina"},{locale:"so",label:"Somali"},{locale:"fi",label:"Suomi"},{locale:"sv",label:"Svenska"},{locale:"vi",label:"Tiếng Việt"},{locale:"tr",label:"T\xfcrk\xe7e"},{locale:"el",label:"Ελληνικά"},{locale:"ru",label:"Русский"},{locale:"uk",label:"Українська"},{locale:"he",label:"עברית"},{locale:"ur",label:"اردو"},{locale:"ar",label:"عربي"},{locale:"fa",label:"فارسی"},{locale:"ne",label:"नेपाली"},{locale:"mr",label:"मराठी"},{locale:"hi-in",label:"हिन्दी"},{locale:"bn",label:"বাংলা"},{locale:"pa",label:"ਪੰਜਾਬੀ"},{locale:"gu-in",label:"ગુજરાતી"},{locale:"ta",label:"தமிழ்"},{locale:"te",label:"తెలుగు"},{locale:"kn",label:"ಕನ್ನಡ"},{locale:"ml",label:"മലയാളം"},{locale:"th",label:"ภาษาไทย"},{locale:"km-kh",label:"ភាសាខ្មែរ"},{locale:"ko-kr",label:"한국어"},{locale:"ja",label:"日本語"},{locale:"zh-cn",label:"简体中文"},{locale:"zh-tw",label:"繁體中文 (台灣)"}];function no(){var e="u">typeof window&&window.navigator?window.navigator.languages??["en"]:["en"];for(let t of e){let e=function(e){let t=ni.find(t=>t.locale===e.toLowerCase());if(t)return t.locale;let[n,r]=e.split(/[-_]/).map(e=>e.toLowerCase());if(r){let e=ni.find(e=>e.locale===n);if(e)return e.locale}return n in ns?ns[n]:null}(t);if(e)return e}return"en"}let ns={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};(0,i.lF)("@tldraw/tlschema","5.3.2","esm")},81962:(e,t,n)=>{"use strict";n.d(t,{B8:()=>g,HV:()=>p,NC:()=>a,Op:()=>d,Rx:()=>y,SU:()=>c,j0:()=>b,lq:()=>l,oQ:()=>f,vr:()=>s,y5:()=>h});var r=n(93286),i=n(46195);function o(e,t,n,r,s=1e-10){let a=e.x-n.x,l=e.y-n.y,d=r.x-n.x,c=r.y-n.y,h=t.x-e.x,u=t.y-e.y,p=d*l-c*a,f=h*l-u*a,g=c*h-d*u;if(Math.abs(p)<=s||Math.abs(f)<=s||Math.abs(g)<=s)return null;let m=p/g,y=f/g;return m>=-s&&m<=1+s&&y>=-s&&y<=1+s?new i.l(e.x+m*h,e.y+m*u):null}function s(e,t,n,r){let o=t.x-e.x,s=t.y-e.y,a=e.x-n.x,l=e.y-n.y,d=o*o+s*s,c=2*(o*a+s*l),h=c*c-4*d*(a*a+l*l-r*r);if(h<=0)return null;let u=Math.sqrt(h),p=(-c+u)/(2*d),f=(-c-u)/(2*d);if((p<0||p>1)&&(f<0||f>1))return null;let g=[];return(p>=0&&p<=1&&g.push(new i.l(e.x+o*p,e.y+s*p)),f>=0&&f<=1&&g.push(new i.l(e.x+o*f,e.y+s*f)),0===g.length)?null:g}function a(e,t,n){let r,i=[];for(let s=0,a=n.length-1;s<a;s++)(r=o(e,t,n[s],n[s+1]))&&i.push(r);return 0===i.length?null:i}function l(e,t,n){let r,i=[];for(let s=1,a=n.length;s<a+1;s++)(r=o(e,t,n[s-1],n[s%n.length]))&&i.push(r);return 0===i.length?null:i}function d(e,t,n,r){let o=n.x-e.x,s=n.y-e.y,a=Math.sqrt(o*o+s*s),l=(a*a-r*r+t*t)/(2*a),d=Math.sqrt(t*t-l*l);return o/=a,s/=a,[new i.l(e.x+o*l-s*d,e.y+s*l+o*d),new i.l(e.x+o*l+s*d,e.y+s*l-o*d)]}function c(e,t,n){let r,i=[];for(let o=0,a=n.length;o<a;o++)(r=s(n[o],n[(o+1)%n.length],e,t))&&i.push(...r);return 0===i.length?null:i}function h(e,t,n){let r,i=[];for(let o=1,a=n.length;o<a;o++)(r=s(n[o-1],n[o],e,t))&&i.push(...r);return 0===i.length?null:i}function u(e,t,n){return(n.y-e.y)*(t.x-e.x)>(t.y-e.y)*(n.x-e.x)}function p(e,t,n,r){return u(e,n,r)!==u(t,n,r)&&u(e,t,n)!==u(e,t,r)}function f(e,t){var n;let s,a,l,d=new Map;for(let n=0,i=e.length;n<i;n++)if(a=e[n],(0,r.s3)(a,t)){let e=m(a);d.has(e)||d.set(e,a)}for(let n=0,i=t.length;n<i;n++)if(a=t[n],(0,r.s3)(a,e)){let e=m(a);d.has(e)||d.set(e,a)}for(let n=0,r=e.length;n<r;n++){a=e[n],l=e[(n+1)%e.length];for(let e=0,n=t.length;e<n;e++){let n=o(a,l,t[e],t[(e+1)%t.length]);if(null!==n){let e=m(n);d.has(e)||d.set(e,n)}}}return 0===d.size?null:(n=[...d.values()],s=i.l.Average(n),n.sort((e,t)=>i.l.Angle(s,e)-i.l.Angle(s,t)))}function g(e,t,n,r){let i=new Map;for(let s=0,a=n?e.length:e.length-1;s<a;s++){let n=e[s],a=e[(s+1)%e.length];for(let e=0,s=r?t.length:t.length-1;e<s;e++){let r=o(n,a,t[e],t[(e+1)%t.length]);if(null!==r){let e=m(r);i.has(e)||i.set(e,r)}}}return[...i.values()]}function m(e){return`${e.x},${e.y}`}function y(e,t){let n,r;for(let i=0,o=e.length;i<o;i++){n=e[i],r=e[(i+1)%o];for(let e=0,i=t.length;e<i;e++)if(p(n,r,t[e],t[(e+1)%i]))return!0}return!1}function b(e,t){let n,r;for(let i=0,o=e.length;i<o;i++){n=e[i],r=e[(i+1)%o];for(let e=1,i=t.length;e<i;e++)if(p(n,r,t[e-1],t[e]))return!0}return!1}},82246:function(e){e.exports=function(){"use strict";function e(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function t(e,t){return e<t?-1:+(e>t)}var n=function(e){void 0===e&&(e=9),this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function r(e,t){i(e,0,e.children.length,t,e)}function i(e,t,n,r,i){i||(i=u(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(var s=t;s<n;s++){var a=e.children[s];o(i,e.leaf?r(a):a)}return i}function o(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function s(e,t){return e.minX-t.minX}function a(e,t){return e.minY-t.minY}function l(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function d(e){return e.maxX-e.minX+(e.maxY-e.minY)}function c(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function h(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function u(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function p(n,r,i,o,s){for(var a=[r,i];a.length;)if(!((i=a.pop())-(r=a.pop())<=o)){var l=r+Math.ceil((i-r)/o/2)*o;(function t(n,r,i,o,s){for(;o>i;){if(o-i>600){var a=o-i+1,l=r-i+1,d=Math.log(a),c=.5*Math.exp(2*d/3),h=.5*Math.sqrt(d*c*(a-c)/a)*(l-a/2<0?-1:1),u=Math.max(i,Math.floor(r-l*c/a+h)),p=Math.min(o,Math.floor(r+(a-l)*c/a+h));t(n,r,u,p,s)}var f=n[r],g=i,m=o;for(e(n,i,r),s(n[o],f)>0&&e(n,i,o);g<m;){for(e(n,g,m),g++,m--;0>s(n[g],f);)g++;for(;s(n[m],f)>0;)m--}0===s(n[i],f)?e(n,i,m):e(n,++m,o),m<=r&&(i=m+1),r<=m&&(o=m-1)}})(n,l,r||0,i||n.length-1,s||t),a.push(r,l,l,i)}}return n.prototype.all=function(){return this._all(this.data,[])},n.prototype.search=function(e){var t=this.data,n=[];if(!h(e,t))return n;for(var r=this.toBBox,i=[];t;){for(var o=0;o<t.children.length;o++){var s=t.children[o],a=t.leaf?r(s):s;h(e,a)&&(t.leaf?n.push(s):c(e,a)?this._all(s,n):i.push(s))}t=i.pop()}return n},n.prototype.collides=function(e){var t=this.data;if(!h(e,t))return!1;for(var n=[];t;){for(var r=0;r<t.children.length;r++){var i=t.children[r],o=t.leaf?this.toBBox(i):i;if(h(e,o)){if(t.leaf||c(e,o))return!0;n.push(i)}}t=n.pop()}return!1},n.prototype.load=function(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(var t=0;t<e.length;t++)this.insert(e[t]);return this}var n=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){var r=this.data;this.data=n,n=r}this._insert(n,this.data.height-n.height-1,!0)}else this.data=n;return this},n.prototype.insert=function(e){return e&&this._insert(e,this.data.height-1),this},n.prototype.clear=function(){return this.data=u([]),this},n.prototype.remove=function(e,t){if(!e)return this;for(var n,r,i,o=this.data,s=this.toBBox(e),a=[],l=[];o||a.length;){if(o||(o=a.pop(),r=a[a.length-1],n=l.pop(),i=!0),o.leaf){var d=function(e,t,n){if(!n)return t.indexOf(e);for(var r=0;r<t.length;r++)if(n(e,t[r]))return r;return -1}(e,o.children,t);if(-1!==d)return o.children.splice(d,1),a.push(o),this._condense(a),this}i||o.leaf||!c(o,s)?r?(n++,o=r.children[n],i=!1):o=null:(a.push(o),l.push(n),n=0,r=o,o=o.children[0])}return this},n.prototype.toBBox=function(e){return e},n.prototype.compareMinX=function(e,t){return e.minX-t.minX},n.prototype.compareMinY=function(e,t){return e.minY-t.minY},n.prototype.toJSON=function(){return this.data},n.prototype.fromJSON=function(e){return this.data=e,this},n.prototype._all=function(e,t){for(var n=[];e;)e.leaf?t.push.apply(t,e.children):n.push.apply(n,e.children),e=n.pop();return t},n.prototype._build=function(e,t,n,i){var o,s=n-t+1,a=this._maxEntries;if(s<=a)return r(o=u(e.slice(t,n+1)),this.toBBox),o;i||(i=Math.ceil(Math.log(s)/Math.log(a)),a=Math.ceil(s/Math.pow(a,i-1))),(o=u([])).leaf=!1,o.height=i;var l=Math.ceil(s/a),d=l*Math.ceil(Math.sqrt(a));p(e,t,n,d,this.compareMinX);for(var c=t;c<=n;c+=d){var h=Math.min(c+d-1,n);p(e,c,h,l,this.compareMinY);for(var f=c;f<=h;f+=l){var g=Math.min(f+l-1,h);o.children.push(this._build(e,f,g,i-1))}}return r(o,this.toBBox),o},n.prototype._chooseSubtree=function(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){for(var i=1/0,o=1/0,s=void 0,a=0;a<t.children.length;a++){var d=t.children[a],c=l(d),h=(Math.max(d.maxX,e.maxX)-Math.min(d.minX,e.minX))*(Math.max(d.maxY,e.maxY)-Math.min(d.minY,e.minY))-c;h<o?(o=h,i=c<i?c:i,s=d):h===o&&c<i&&(i=c,s=d)}t=s||t.children[0]}return t},n.prototype._insert=function(e,t,n){var r=n?e:this.toBBox(e),i=[],s=this._chooseSubtree(r,this.data,t,i);for(s.children.push(e),o(s,r);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(r,i,t)},n.prototype._split=function(e,t){var n=e[t],i=n.children.length,o=this._minEntries;this._chooseSplitAxis(n,o,i);var s=this._chooseSplitIndex(n,o,i),a=u(n.children.splice(s,n.children.length-s));a.height=n.height,a.leaf=n.leaf,r(n,this.toBBox),r(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(n,a)},n.prototype._splitRoot=function(e,t){this.data=u([e,t]),this.data.height=e.height+1,this.data.leaf=!1,r(this.data,this.toBBox)},n.prototype._chooseSplitIndex=function(e,t,n){for(var r,o,s,a,d,c=1/0,h=1/0,u=t;u<=n-t;u++){var p=i(e,0,u,this.toBBox),f=i(e,u,n,this.toBBox),g=(o=void 0,s=void 0,a=void 0,o=Math.max(p.minX,f.minX),s=Math.max(p.minY,f.minY),Math.max(0,(a=Math.min(p.maxX,f.maxX))-o)*Math.max(0,Math.min(p.maxY,f.maxY)-s)),m=l(p)+l(f);g<c?(c=g,r=u,h=m<h?m:h):g===c&&m<h&&(h=m,r=u)}return r||n-t},n.prototype._chooseSplitAxis=function(e,t,n){var r=e.leaf?this.compareMinX:s,i=e.leaf?this.compareMinY:a;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,i)&&e.children.sort(r)},n.prototype._allDistMargin=function(e,t,n,r){e.children.sort(r);for(var s=this.toBBox,a=i(e,0,t,s),l=i(e,n-t,n,s),c=d(a)+d(l),h=t;h<n-t;h++){var u=e.children[h];o(a,e.leaf?s(u):u),c+=d(a)}for(var p=n-t-1;p>=t;p--){var f=e.children[p];o(l,e.leaf?s(f):f),c+=d(l)}return c},n.prototype._adjustParentBBoxes=function(e,t,n){for(var r=n;r>=0;r--)o(t[r],e)},n.prototype._condense=function(e){for(var t=e.length-1,n=void 0;t>=0;t--)0===e[t].children.length?t>0?(n=e[t-1].children).splice(n.indexOf(e[t]),1):this.clear():r(e[t],this.toBBox)},n}()},83102:(e,t,n)=>{"use strict";let r;n.d(t,{Ml:()=>h,VM:()=>U,c2:()=>w,UP:()=>O,eU:()=>A,EW:()=>B,_O:()=>D,wv:()=>K,Px:()=>W,hL:()=>I,Pm:()=>m,_D:()=>R});var i=n(24167);function o(e){return e&&"object"==typeof e&&"parents"in e}function s(e){for(let t=0,n=e.parents.length;t<n;t++)if(e.parents[t].__unsafe__getWithoutCapture(!0),e.parents[t].lastChangedEpoch!==e.parentEpochs[t])return!0;return!1}function a(e,t){if(e.children.remove(t)&&e.children.isEmpty&&o(e))for(let t=0,n=e.parents.length;t<n;t++)a(e.parents[t],e)}function l(e,t){if(e.children.add(t)&&o(e))for(let t=0,n=e.parents.length;t<n;t++)l(e.parents[t],e)}function d(e,t){return e===t||Object.is(e,t)||!!(e&&t&&"function"==typeof e.equals&&e.equals(t))}function c(e,t){let n=Symbol.for(`com.tldraw.state/${e}`),r=globalThis;return r[n]??=t(),r[n]}let h=c("empty_array",()=>Object.freeze([]));class u{arraySize=0;array=Array(8);set=null;get isEmpty(){if(this.array)return 0===this.arraySize;if(this.set)return 0===this.set.size;throw Error("no set or array")}add(e){if(this.array)return -1===this.array.indexOf(e)&&(this.arraySize<8?(this.array[this.arraySize]=e,this.arraySize++):(this.set=new Set(this.array),this.array=null,this.set.add(e)),!0);if(this.set)return!this.set.has(e)&&(this.set.add(e),!0);throw Error("no set or array")}remove(e){if(this.array){let t=this.array.indexOf(e);return -1!==t&&(this.array[t]=void 0,this.arraySize--,t!==this.arraySize&&(this.array[t]=this.array[this.arraySize],this.array[this.arraySize]=void 0),!0)}if(this.set)return!!this.set.has(e)&&(this.set.delete(e),!0);throw Error("no set or array")}visit(e){if(this.array){for(let t=0;t<this.arraySize;t++){let n=this.array[t];void 0!==n&&e(n)}return}if(this.set)return void this.set.forEach(e);throw Error("no set or array")}*[Symbol.iterator](){if(this.array)for(let e=0;e<this.arraySize;e++){let t=this.array[e];void 0!==t&&(yield t)}else if(this.set)yield*this.set;else throw Error("no set or array")}has(e){return this.array?-1!==this.array.indexOf(e):this.set.has(e)}clear(){this.set?this.set.clear():(this.arraySize=0,this.array=[])}size(){return this.set?this.set.size:this.arraySize}}function p(e){return!!(e&&!0===e.__isComputed)}class f{constructor(e,t){this.below=e,this.child=t}below;child;offset=0;maybeRemoved}let g=c("capture",()=>({stack:null}));function m(e){let t=g.stack;g.stack=null;try{return e()}finally{g.stack=t}}function y(e){if(g.stack=new f(g.stack,e),e.__debug_ancestor_epochs__){let t=e.__debug_ancestor_epochs__;for(let t of(e.__debug_ancestor_epochs__=null,e.parents))t.__unsafe__getWithoutCapture(!0);!function(e,t){let n=function e(t,n){let r={};for(let i=0;i<t.parents.length;i++){let o=t.parents[i];if(!n.has(o))continue;let s=n.get(o);o.lastChangedEpoch!==s&&(p(o)?r[o.name]=e(o,n):r[o.name]=null)}return r}(e,t);if(0===Object.keys(n).length)return console.log(`Effect(${e.name}) was executed manually.`);let r=p(e)?`Computed(${e.name}) is recomputing because:`:`Effect(${e.name}) is executing because:`;!function e(t,n){let i="\n"+" ".repeat(n)+"↳ ";for(let[o,s]of Object.entries(t))s?(r+=`${i}Computed(${o}) changed`,e(s,n+2)):r+=`${i}Atom(${o}) changed`}(n,1),console.log(r)}(e,t)}e.parentSet.clear()}function b(){let e=g.stack;if(g.stack=e.below,e.offset<e.child.parents.length){for(let t=e.offset;t<e.child.parents.length;t++){let n=e.child.parents[t];e.child.parentSet.has(n)||a(n,e.child)}e.child.parents.length=e.offset,e.child.parentEpochs.length=e.offset}if(e.maybeRemoved)for(let t=0;t<e.maybeRemoved.length;t++){let n=e.maybeRemoved[t];e.child.parentSet.has(n)||a(n,e.child)}e.child.__debug_ancestor_epochs__&&function e(t,n){for(let r=0;r<t.parents.length;r++){let i=t.parents[r],o=t.parentEpochs[r];n.set(i,o),p(i)&&e(i,n)}return n}(e.child,e.child.__debug_ancestor_epochs__)}function x(e){if(g.stack&&!g.stack.child.parentSet.has(e)){if(g.stack.child.parentSet.add(e),g.stack.child.isActivelyListening&&l(e,g.stack.child),g.stack.offset<g.stack.child.parents.length){let t=g.stack.child.parents[g.stack.offset];t!==e&&(g.stack.maybeRemoved?g.stack.maybeRemoved.push(t):g.stack.maybeRemoved=[t])}g.stack.child.parents[g.stack.offset]=e,g.stack.child.parentEpochs[g.stack.offset]=e.lastChangedEpoch,g.stack.offset++}}let w=Symbol.for("com.tldraw.state/RESET_VALUE");class v{constructor(e){this.capacity=e,this.buffer=Array(e)}capacity;index=0;buffer;pushEntry(e,t,n){if(void 0!==n){if(n===w)return void this.clear();this.buffer[this.index]=[e,t,n],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(e){let{index:t,capacity:n,buffer:r}=this;for(let i=0;i<n;i++){let o=(t-1+n-i)%n,s=r[o];if(!s)break;let[a,l]=s;if(0===i&&e>=l)return[];if(a<=e&&e<l){let e=i+1,t=Array(e);for(let i=0;i<e;i++)t[i]=r[(o+i)%n][2];return t}}return w}}class S{constructor(e,t){this.parent=e,this.isSync=t}parent;isSync;asyncProcessCount=0;initialAtomValues=new Map;get isRoot(){return null===this.parent}commit(){if(C.globalIsReacting)for(let e of this.initialAtomValues.keys())E(e);else this.isRoot?T(this.initialAtomValues.keys()):this.initialAtomValues.forEach((e,t)=>{this.parent.initialAtomValues.has(t)||this.parent.initialAtomValues.set(t,e)})}abort(){C.globalEpoch++,this.initialAtomValues.forEach((e,t)=>{t.set(e),t.historyBuffer?.clear()}),this.commit()}}let C=c("transactions",()=>({globalEpoch:0,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:0}));function k(){return C.globalEpoch}function P(e,t){r=e,function e(t){t.lastTraversedEpoch!==C.globalEpoch&&(t.lastTraversedEpoch=C.globalEpoch,"__isEffectScheduler"in t?r.add(t):t.children.visit(e))}(t)}function T(e){if(C.globalIsReacting)throw Error("flushChanges cannot be called during a reaction");let t=C.currentTransaction;try{C.currentTransaction=null,C.globalIsReacting=!0,C.reactionEpoch=C.globalEpoch;let t=new Set;for(let n of e)n.children.visit(e=>P(t,e));for(let e of t)e.maybeScheduleEffect();let n=0;for(;C.cleanupReactors?.size;){if(n++>1e3)throw Error("Reaction update depth limit exceeded");let e=C.cleanupReactors;for(let t of(C.cleanupReactors=null,e))t.maybeScheduleEffect()}}finally{C.cleanupReactors=null,C.globalIsReacting=!1,C.currentTransaction=t,r=void 0}}function E(e){let t=C.cleanupReactors??=new Set;e.children.visit(e=>P(t,e))}function I(e){if(C.currentTransaction)return e();let t=new S(C.currentTransaction,!0);C.currentTransaction=t;try{let n,r=!1;try{n=e(()=>r=!0)}catch(e){throw t.abort(),e}if(C.currentTransaction!==t)throw Error("Transaction boundaries overlap");return r?t.abort():t.commit(),n}finally{C.currentTransaction=t.parent}}class _{constructor(e,t,n){if(this.name=e,this.current=t,this.isEqual=n?.isEqual??null,!n)return;n.historyLength&&(this.historyBuffer=new v(n.historyLength)),this.computeDiff=n.computeDiff}name;current;isEqual;computeDiff;lastChangedEpoch=k();children=new u;historyBuffer;__unsafe__getWithoutCapture(e){return this.current}get(){return x(this),this.current}set(e,t){if(this.isEqual?.(this.current,e)??d(this.current,e))return this.current;C.globalEpoch++,this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,k(),t??this.computeDiff?.(this.current,e,this.lastChangedEpoch,k())??w),this.lastChangedEpoch=k();let n=this.current;return this.current=e,C.currentTransaction?C.currentTransaction.initialAtomValues.has(this)||C.currentTransaction.initialAtomValues.set(this,n):C.globalIsReacting?E(this):T([this]),e}update(e){return this.set(e(this.current))}getDiffSince(e){return(x(this),e>=this.lastChangedEpoch)?h:this.historyBuffer?.getChangesSince(e)??w}}let M=c("Atom",()=>_);function A(e,t,n){return new M(e,t,n)}let j=!1,O=Symbol.for("com.tldraw.state/UNINITIALIZED");function D(e){return e===O}let L=c("WithDiff",()=>class{constructor(e,t){this.value=e,this.diff=t}value;diff});function R(e,t){return new L(e,t)}class F{constructor(e,t,n){this.name=e,this.derive=t,n?.historyLength&&(this.historyBuffer=new v(n.historyLength)),this.computeDiff=n?.computeDiff,this.isEqual=n?.isEqual??d}name;derive;__isComputed=!0;lastChangedEpoch=-1;lastTraversedEpoch=-1;__debug_ancestor_epochs__=null;lastCheckedEpoch=-1;parentSet=new u;parents=[];parentEpochs=[];children=new u;get isActivelyListening(){return!this.children.isEmpty}historyBuffer;state=O;error=null;computeDiff;isEqual;__unsafe__getWithoutCapture(e){let t=-1===this.lastChangedEpoch,n=k();if(!t&&(this.lastCheckedEpoch===n||this.isActivelyListening&&C.globalIsReacting&&this.lastTraversedEpoch<C.reactionEpoch||!s(this))){if(this.lastCheckedEpoch=n,!this.error)return this.state;if(e)return this.state;throw this.error.thrownValue}try{y(this);let e=this.derive(this.state,this.lastCheckedEpoch),t=e instanceof L?e.value:e,n=this.state===O;if(n||!this.isEqual(this.state,t)){if(this.historyBuffer&&!n){let n=e instanceof L?e.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,k(),n??this.computeDiff?.(this.state,t,this.lastCheckedEpoch,k())??w)}this.lastChangedEpoch=k(),this.state=t}return this.error=null,this.lastCheckedEpoch=k(),this.state}catch(t){if(this.state!==O&&(this.state=O,this.lastChangedEpoch=k()),this.lastCheckedEpoch=k(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:t},!e)throw t;return this.state}finally{b()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{x(this)}}getDiffSince(e){return(this.__unsafe__getWithoutCapture(!0),x(this),e>=this.lastChangedEpoch)?h:this.historyBuffer?.getChangesSince(e)??w}}let z=c("Computed",()=>F);function N(e={},t){if(2===t.length){let n,r,[o,s]=t;return(0,i.vA)("method"===s.kind,"@computed can only be used on methods"),n=Symbol.for("__@tldraw/state__computed__"+String(s.name)),(r=function(){let t=this[n];return t||Object.defineProperty(this,n,{enumerable:!1,configurable:!1,writable:!1,value:t=new z(String(s.name),o.bind(this),e)}),t.get()})[$]=!0,r}{let[n,r,i]=t;return i.get?(j||(j=!0,console.warn(`Using \`@computed\` as a decorator for getters is deprecated and will be removed in the near future. Please refactor to use \`@computed\` as a decorator for methods.
116
-
117
- // Before
118
- @computed
119
- get foo() {
120
- return 'foo'
121
- }
122
-
123
- // After
124
- @computed
125
- getFoo() {
126
- return 'foo'
127
- }
128
- `)),function(e={},t,n){let r=n.get,i=Symbol.for("__@tldraw/state__computed__"+t);return n.get=function(){let n=this[i];return n||Object.defineProperty(this,i,{enumerable:!1,configurable:!1,writable:!1,value:n=new z(t,r.bind(this),e)}),n.get()},n}(e,r,i)):function(e={},t,n){let r=n.value,i=Symbol.for("__@tldraw/state__computed__"+t);return n.value=function(){let n=this[i];return n||Object.defineProperty(this,i,{enumerable:!1,configurable:!1,writable:!1,value:n=new z(t,r.bind(this),e)}),n.get()},n.value[$]=!0,n}(e,r,i)}}let $="@@__isComputedMethod__@@";function B(){if(1==arguments.length){let e=arguments[0];return(...t)=>N(e,t)}return"string"==typeof arguments[0]?new z(arguments[0],arguments[1],arguments[2]):N(void 0,arguments)}class H{constructor(e,t,n){this.name=e,this.runEffect=t,this._scheduleEffect=n?.scheduleEffect}name;runEffect;__isEffectScheduler=!0;_isActivelyListening=!1;get isActivelyListening(){return this._isActivelyListening}lastTraversedEpoch=-1;lastReactedEpoch=-1;_scheduleCount=0;__debug_ancestor_epochs__=null;get scheduleCount(){return this._scheduleCount}parentSet=new u;parentEpochs=[];parents=[];_scheduleEffect;maybeScheduleEffect(){if(this._isActivelyListening&&this.lastReactedEpoch!==k()){if(this.parents.length&&!s(this)){this.lastReactedEpoch=k();return}this.scheduleEffect()}}scheduleEffect(){this._scheduleCount++,this._scheduleEffect?this._scheduleEffect(this.maybeExecute):this.execute()}maybeExecute=()=>{this._isActivelyListening&&this.execute()};attach(){this._isActivelyListening=!0;for(let e=0,t=this.parents.length;e<t;e++)l(this.parents[e],this)}detach(){this._isActivelyListening=!1;for(let e=0,t=this.parents.length;e<t;e++)a(this.parents[e],this)}execute(){try{y(this);let e=k(),t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=e,t}finally{b()}}}let U=c("EffectScheduler",()=>H);function K(e,t,n){let r=new U(e,t,n);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function W(e,t,n){let r=new U(e,t,n);return{scheduler:r,start:e=>{let t=e?.force??!1;r.attach(),t?r.scheduleEffect():r.maybeScheduleEffect()},stop:()=>{r.detach()}}}if(1!==c("apiVersion",()=>1))throw Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");(0,i.lF)("@tldraw/state","5.3.2","esm")},83935:(e,t,n)=>{"use strict";n.d(t,{C:()=>l});var r=n(12115),i=n(66294),o=Object.defineProperty,s=(e,t)=>o(e,"name",{value:t,configurable:!0});function a(e,t){return r.useReducer((e,n)=>t[e][n]??e,e)}s(a,"useStateMachine");var l=s(e=>{let{present:t,children:n}=e,i=d(t),o="function"==typeof n?n({present:i.isPresent}):r.Children.only(n),s=h(i.ref,p(o));return"function"==typeof n||i.isPresent?r.cloneElement(o,{ref:s}):null},"Presence");function d(e){let[t,n]=r.useState(),o=r.useRef(null),l=r.useRef(e),d=r.useRef("none"),c=r.useRef(void 0),[h,p]=a(e?"mounted":"unmounted",{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return r.useEffect(()=>{"mounted"===h?(d.current=c.current??u(o.current),c.current=void 0):d.current="none"},[h]),(0,i.N)(()=>{let t=o.current,n=l.current;if(n!==e){let r=d.current,i=u(t);e?(c.current=i,p("MOUNT")):"none"===i||t?.display==="none"?p("UNMOUNT"):n&&r!==i?p("ANIMATION_OUT"):p("UNMOUNT"),l.current=e}},[e,p]),(0,i.N)(()=>{if(t){let e,n=t.ownerDocument.defaultView??window,r=s(r=>{let i=u(o.current).includes(CSS.escape(r.animationName));if(r.target===t&&i&&(p("ANIMATION_END"),!l.current)){let r=t.style.animationFillMode;t.style.animationFillMode="forwards",e=n.setTimeout(()=>{"forwards"===t.style.animationFillMode&&(t.style.animationFillMode=r)})}},"handleAnimationEnd"),i=s(e=>{e.target===t&&(d.current=u(o.current))},"handleAnimationStart");return t.addEventListener("animationstart",i),t.addEventListener("animationcancel",r),t.addEventListener("animationend",r),()=>{n.clearTimeout(e),t.removeEventListener("animationstart",i),t.removeEventListener("animationcancel",r),t.removeEventListener("animationend",r)}}p("ANIMATION_END")},[t,p]),{isPresent:["mounted","unmountSuspended"].includes(h),ref:r.useCallback(e=>{if(e){let t=getComputedStyle(e);o.current=t,c.current=u(t)}else o.current=null;n(e)},[])}}function c(e,t){if("function"==typeof e)return e(t);null!=e&&(e.current=t)}function h(...e){let t=r.useRef(e);return t.current=e,r.useCallback(e=>{let n=t.current,r=!1,i=n.map(t=>{let n=c(t,e);return r||"function"!=typeof n||(r=!0),n});if(r)return()=>{for(let e=0;e<i.length;e++){let t=i[e];"function"==typeof t?t():c(n[e],null)}}},[])}function u(e){return e?.animationName||"none"}function p(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(n=(t=Object.getOwnPropertyDescriptor(e,"ref")?.get)&&"isReactWarning"in t&&t.isReactWarning)?e.props.ref:e.props.ref||e.ref}s(d,"usePresence"),s(c,"setRef"),s(h,"useStableComposedRefs"),s(u,"getAnimationName"),s(p,"getElementRef")},84469:(e,t,n)=>{"use strict";n.d(t,{N:()=>r});let r={menus:(0,n(83102).eU)("open menus",[]),getOpenMenus(e){return e?this.menus.get().filter(t=>t.endsWith("-"+e)):this.menus.get()},addOpenMenu(e,t=""){let n=t?`${e}-${t}`:e,r=new Set(this.menus.get());r.has(n)||(r.add(n),this.menus.set([...r]))},deleteOpenMenu(e,t=""){let n=t?`${e}-${t}`:e,r=new Set(this.menus.get());r.has(n)&&(r.delete(n),this.menus.set([...r]))},clearOpenMenus(e){this.menus.set(e?this.menus.get().filter(t=>!t.endsWith("-"+e)):[])},_hiddenMenus:[],hideOpenMenus(e){if(this._hiddenMenus=[...this.getOpenMenus(e)],0!==this._hiddenMenus.length)for(let t of this._hiddenMenus)this.deleteOpenMenu(t,e)},showOpenMenus(e){if(0!==this._hiddenMenus.length){for(let t of this._hiddenMenus)this.addOpenMenu(t,e);this._hiddenMenus=[]}},isMenuOpen(e,t){return this.getOpenMenus(t).includes(`${e}-${t}`)},hasOpenMenus(e){return this.getOpenMenus(e).length>0},hasAnyOpenMenus(){return this.getOpenMenus().length>0},forContext(e){return{getOpenMenus:()=>this.getOpenMenus(e),addOpenMenu:t=>this.addOpenMenu(t,e),deleteOpenMenu:t=>this.deleteOpenMenu(t,e),clearOpenMenus:()=>this.clearOpenMenus(e),isMenuOpen:t=>this.isMenuOpen(t,e),hasOpenMenus:()=>this.hasOpenMenus(e),hasAnyOpenMenus:()=>this.hasAnyOpenMenus()}}}},87767:(e,t,n)=>{"use strict";n.d(t,{NF:()=>l,ts:()=>a});var r=n(95155),i=n(24167),o=n(12115);let s=(0,o.createContext)(null);function a({container:e,children:t}){return(0,r.jsx)(s.Provider,{value:e,children:t})}function l(){return(0,i.Z1)((0,o.useContext)(s),"useContainer used outside of <Tldraw />")}},89658:(e,t,n)=>{"use strict";n.d(t,{s:()=>r});let r=new(n(24167)).xl},89908:(e,t,n)=>{"use strict";n.d(t,{t:()=>i});var r=Object.defineProperty,i=(e,t)=>{let n={};for(var i in e)r(n,i,{get:e[i],enumerable:!0});return t||r(n,Symbol.toStringTag,{value:"Module"}),n}},89971:(e,t,n)=>{"use strict";n.d(t,{B:()=>d});var r,i=n(12115),o=n(66294),s=Object.defineProperty,a=(r||(r=n.t(i,2)))[" useId ".trim().toString()]||(()=>void 0),l=0;function d(e){let[t,n]=i.useState(a());return(0,o.N)(()=>{e||n(e=>e??String(l++))},[e]),e||(t?`radix-${t}`:"")}s(d,"name",{value:"useId",configurable:!0})},92599:(e,t,n)=>{"use strict";n.d(t,{b:()=>s});var r=n(24167);function i(e,t){if(!t)return!1;switch(e.type){case"mixed":return"mixed"===t.type;case"shared":return"shared"===t.type&&e.value===t.value;default:throw(0,r.h6)(e)}}class o{map;constructor(e){this.map=new Map(e)}get(e){return this.map.get(e)}getAsKnownValue(e){let t=this.get(e);if(t&&"mixed"!==t.type)return t.value}get size(){return this.map.size}equals(e){if(this.size!==e.size)return!1;let t=new Set;for(let[n,r]of this){if(!i(r,e.get(n)))return!1;t.add(n)}for(let[n,r]of e)if(!t.has(n)&&!i(r,this.get(n)))return!1;return!0}keys(){return this.map.keys()}values(){return this.map.values()}entries(){return this.map.entries()}[Symbol.iterator](){return this.map[Symbol.iterator]()}}class s extends o{set(e,t){this.map.set(e,t)}applyValue(e,t){let n=this.get(e);if(!n)return void this.set(e,{type:"shared",value:t});switch(n.type){case"mixed":return;case"shared":n.value!==t&&this.set(e,{type:"mixed"});return;default:(0,r.h6)(n,"type")}}}},93097:(e,t,n)=>{"use strict";n.d(t,{k:()=>s});var r=n(59830),i=n(46195),o=n(31428);class s extends o.d{_x;_y;_w;_h;constructor(e){const{x:t=0,y:n=0,width:r,height:o}=e;super({...e,points:[new i.l(t,n),new i.l(t+r,n),new i.l(t+r,n+o),new i.l(t,n+o)]}),this._x=t,this._y=n,this._w=r,this._h=o}getBounds(){return new r.az(this._x,this._y,this._w,this._h)}getSvgPathData(){let{_x:e,_y:t,_w:n,_h:r}=this;return this.negativeZeroFix(),`M${e},${t} h${n} v${r} h${-n}z`}negativeZeroFix(){this._x=a(this._x),this._y=a(this._y),this._w=a(this._w),this._h=a(this._h)}}function a(e){return Object.is(e,-0)?0:e}},93286:(e,t,n)=>{"use strict";n.d(t,{$C:()=>E,AQ:()=>k,G8:()=>o,IM:()=>y,KM:()=>m,Mg:()=>A,PI:()=>s,QX:()=>h,VM:()=>f,WM:()=>M,YY:()=>u,_B:()=>j,cL:()=>w,dw:()=>d,g6:()=>T,jw:()=>v,nv:()=>C,oj:()=>L,qE:()=>c,qe:()=>b,rT:()=>p,rg:()=>g,rq:()=>D,s3:()=>_,sK:()=>a,tR:()=>S,uA:()=>l,ul:()=>i,yD:()=>x,ye:()=>P,yi:()=>O});var r=n(46195);function i(e){return`${M(e.x)},${M(e.y)} `}function o(e,t){return`${M((e.x+t.x)/2)},${M((e.y+t.y)/2)} `}let s=Math.PI,a=s/2,l=2*s,d=Math.sin;function c(e,t,n){return Math.max(t,void 0!==n?Math.min(e,n):e)}function h(e,t=1e10){return e?Math.round(e*t)/t:0}function u(e,t,n=1e-6){return Math.abs(e-t)<=n}function p(e,t,n=1e-6){return e<t||u(e,t,n)}function f(e,t){let n=Math.pow(e-t,2)/Math.pow(e+t,2);return s*(e+t)*(1+3*n/(10+Math.sqrt(4-3*n)))}function g(e){return(e%=l)<0?e+=l:0===e&&(e=0),e}function m(e,t){return(e=g(e))>(t=g(t))&&(t+=l),t-e}function y(e,t){return l-m(e,t)}function b(e,t){let n=(t-e)%l;return 2*n%l-n}function x(e){return(l+e)%l}function w(e,t){let n=l/t,r=Math.floor((x(e)+n/2)/n)*n%l;return r<s&&(r+=l),r>s&&(r-=l),r}function v(e,t){return e===t||u(e%(Math.PI/2)-t%(Math.PI/2),0)}function S(e){return e*s/180}function C(e){return 180*e/s}function k(e,t,n){return new r.l(e.x,e.y).add(r.l.FromAngle(n,t))}function P(e,t,n){let i=e/2,o=t/2,s=[],d=1/0,c=-1/0,h=1/0,u=-1/0;for(let e=0;e<n;e++){let t=-a+l/n*e,p=i+i*Math.cos(t),f=o+o*Math.sin(t);p<d&&(d=p),f<h&&(h=f),p>c&&(c=p),f>u&&(u=f),s.push(new r.l(p,f))}let p=c-d,f=u-h;if(0!=e-p||0!=t-f)for(let n=0;n<s.length;n++){let r=s[n];r.x=(r.x-d)/p*e,r.y=(r.y-h)/f*t}return s}function T(e,t,n,r){return e<r&&n<t}function E(e,t,n,r){let i=Math.max(e,n),o=Math.min(t,r);return i<=o?[i,o]:null}function I(e,t,n){return(t.x-e.x)*(n.y-e.y)-(n.x-e.x)*(t.y-e.y)}function _(e,t){let n,r,i=0;for(let o=0;o<t.length;o++){if((n=t[o]).x===e.x&&n.y===e.y)return!0;r=t[(o+1)%t.length],n.y<=e.y?r.y>e.y&&I(n,r,e)>0&&(i+=1):r.y<=e.y&&0>I(n,r,e)&&(i-=1)}return 0!==i}function M(e){return Math.round(1e4*e)/1e4}function A(e){return Math.round(100*e)/100}function j(e){return Math.abs(e)<Number.MAX_SAFE_INTEGER}function O(e,t,n,r){let i;if(Math.abs(e)>s){i=b(t,r);let o=b(r,n);return Math.abs(i)<Math.abs(o)?i/e:(e-o)/e}{let n=(i=b(t,r))/e;return Math.sign(i)!==Math.sign(e)?+(Math.abs(n)>.5):n}}function D(e,t,n,r){let i=(t-e)%l*2%l-(t-e)%l;return r?(l-Math.abs(i))*(n?1:-1):i}function L(e,t,n){let i=-2*(e.x*(t.y-n.y)-e.y*(t.x-n.x)+t.x*n.y-n.x*t.y),o=((e.x*e.x+e.y*e.y)*(n.y-t.y)+(t.x*t.x+t.y*t.y)*(e.y-n.y)+(n.x*n.x+n.y*n.y)*(t.y-e.y))/i,s=((e.x*e.x+e.y*e.y)*(t.x-n.x)+(t.x*t.x+t.y*t.y)*(n.x-e.x)+(n.x*n.x+n.y*n.y)*(e.x-t.x))/i;return Number.isFinite(o)&&Number.isFinite(s)?new r.l(o,s):null}},93647:(e,t,n)=>{"use strict";let r,i,o,s;n.d(t,{xGO:()=>nr,srS:()=>h.sr,roz:()=>h.ro,qfG:()=>h.qf,Kx3:()=>h.Kx,$mH:()=>eQ,QVi:()=>td,A8:()=>e4,B$v:()=>e8,mbh:()=>e0,azJ:()=>t9.az,PUi:()=>ni,iON:()=>ns,RBp:()=>a.RB,qSO:()=>a.qS,sdu:()=>h.sd,ive:()=>h.iv,Pe6:()=>h.Pe,u8f:()=>h.u8,yes:()=>h.ye,yMj:()=>h.yM,Sg3:()=>h.Sg,z6X:()=>ej,nM1:()=>h.nM,YUb:()=>h.YU,Z4H:()=>t7.Z,Mlv:()=>l.Ml,AoN:()=>na.A,KE6:()=>ez.K,bZT:()=>nM,pPP:()=>nl,SmQ:()=>a.Sm,tg8:()=>h.tg,vqJ:()=>nn.vq,MI8:()=>nn.MI,IQE:()=>U.I,sKG:()=>O.sK,hDc:()=>eL,_V3:()=>a._V,Yjb:()=>h.Yj,eBK:()=>h.eB,xxw:()=>nI,Qnm:()=>a.Qn,V8r:()=>nc.V,K4L:()=>a.K4,bU:()=>te,PI:()=>O.PI,uAR:()=>O.uA,tvM:()=>h.tv,dxv:()=>nd.d,Hes:()=>no.H,krb:()=>e3.k,Q7C:()=>a.Q7,BV:()=>eZ.BV,dwc:()=>O.dw,ULM:()=>eR.U,inY:()=>e5.i,bDP:()=>nz.b,YM5:()=>to.Y,T:()=>u.T,OsR:()=>eJ.Os,O75:()=>nv,xXO:()=>eK.xX,XAu:()=>h.XA,l2P:()=>I.l,laH:()=>a.l,as9:()=>a.as,ghB:()=>x.gh,_Bx:()=>nF._,YY0:()=>O.YY,jwY:()=>O.jw,g8l:()=>h.g8,P_i:()=>h.P_,udf:()=>h.ud,FXh:()=>h.FX,vAR:()=>a.vA,Z1O:()=>a.Z1,eUv:()=>l.eU,K6A:()=>h.K6,oIE:()=>a.oI,Esp:()=>h.Es,VtT:()=>h.Vt,hNn:()=>h.hN,aWX:()=>h.aW,rgm:()=>O.rg,oj6:()=>O.oj,qE8:()=>O.qE,KMq:()=>O.KM,oE7:()=>a.oE,EWP:()=>l.EW,IM4:()=>O.IM,BNi:()=>h.BN,gP_:()=>h.gP,uYT:()=>c.uY,S6A:()=>h.S6,n6Y:()=>h.n6,_zD:()=>eq,dBl:()=>h.dB,sg1:()=>a.sg,bGJ:()=>j.bG,TjI:()=>eK.Tj,iPZ:()=>eV,tRv:()=>O.tR,deR:()=>h.de,KBL:()=>h.KB,oOb:()=>x.oO,upp:()=>h.up,Pwo:()=>h.Pw,h6G:()=>a.h6,ofH:()=>j.of,hdJ:()=>a.hd,SpZ:()=>h.Sp,X24:()=>h.X2,s4L:()=>h.s4,X8F:()=>h.X8,Xzd:()=>a.Xz,FHQ:()=>e2.F,H__:()=>tH.H,Cho:()=>h.jW,C$h:()=>a.C$,EYW:()=>nR,zMQ:()=>a.zM,jLo:()=>x.jL,CMG:()=>x.CM,Gwq:()=>a.Gw,xpx:()=>a.xp,AQy:()=>a.AQ,SBu:()=>a.SB,HEt:()=>a.HE,uud:()=>a.uu,MTM:()=>a.MT,tjK:()=>e7,g50:()=>a.g5,mDw:()=>M.mD,EK8:()=>tr.E,AQe:()=>O.AQ,yGT:()=>C,yeN:()=>O.ye,fHb:()=>nF.f,JDT:()=>nA,oEU:()=>eK.oE,qnK:()=>nt,W$r:()=>eE,REO:()=>h.RE,M60:()=>h.M6,h1I:()=>h.h1,_8g:()=>h._8,UcL:()=>h.Uc,lXb:()=>h.lX,AWg:()=>eY,OpZ:()=>ne.Op,vrM:()=>ne.vr,lqI:()=>ne.lq,Fg_:()=>a.Fg,gu7:()=>w.g,KHk:()=>R,O9V:()=>a.O9,n4T:()=>a.n4,Ao2:()=>a.Ao,GYP:()=>h.GY,xhT:()=>h.xh,_Bd:()=>O._B,vc4:()=>h.vc,IeP:()=>nj.I,HVh:()=>a.HV,CcK:()=>a.Cc,bT0:()=>h.bT,e9l:()=>h.e9,_Hz:()=>a._H,Y8F:()=>tl,OgJ:()=>a.Og,wql:()=>a.wq,wwY:()=>a.ww,lQ1:()=>a.lQ,jaC:()=>_,fq3:()=>h.fq,SWg:()=>h.SW,iAN:()=>a.iA,_ed:()=>a._e,w$g:()=>a.w$,Ics:()=>a.Ic,D1x:()=>eT,s3y:()=>O.s3,Rx2:()=>ne.Rx,woC:()=>x.wo,$Cz:()=>O.$C,wvh:()=>l.wv,Mcl:()=>h.Mc,AFA:()=>h.AF,lFJ:()=>a.lF,hPm:()=>x.hP,mfH:()=>e6,d5$:()=>ti,OVI:()=>e1.O,P1V:()=>eN.P,eHF:()=>h.eH,She:()=>a.Sh,Wj6:()=>t9.Wj,yCG:()=>a.yC,ni0:()=>L.ni,Yz5:()=>a.Yz,YYG:()=>x.YY,qer:()=>O.qe,cL9:()=>O.cL,Ky:()=>a.Ky,APM:()=>tn,pN9:()=>a.pN,oX2:()=>L.oX,E4k:()=>h.E4,xjg:()=>h.xj,nFR:()=>a.nF,YZA:()=>y.Y,$Gt:()=>y.$,NlK:()=>th.N,slq:()=>tu.s,WMC:()=>O.WM,Mg8:()=>O.Mg,TP3:()=>h.TP,u4I:()=>d.u4,hLc:()=>l.hL,sbv:()=>tR,NF7:()=>a.NF,PmD:()=>l.Pm,fpl:()=>d.fp,G67:()=>tp,NFA:()=>T.NF,lsV:()=>tc.ls,hGv:()=>k.hG,BSi:()=>b.B,_q_:()=>tP._,ofB:()=>tT,_As:()=>tE,VKK:()=>t8,frr:()=>k.fr,YgL:()=>t2,yfR:()=>n_,I9L:()=>tL,oKA:()=>tF,xQ_:()=>tz,lXS:()=>d.lX,lIP:()=>tP.l,a1r:()=>d.a1,oqt:()=>tj,H80:()=>tC.H,dSk:()=>tC.d,Xhk:()=>L.Xh,Jf5:()=>tc.Jf,K4z:()=>t$,jXu:()=>tN,LsA:()=>L.Ls,hau:()=>d.h,jhO:()=>h.jh,EOG:()=>h.EO,w9f:()=>h.w9,ZMy:()=>h.ZM,mcG:()=>a.mc});var a=n(24167),l=n(83102),d=n(27394),c=n(54530),h=n(81467),u=n(22690),p=n(95155);function f(){return(0,p.jsx)("div",{className:"tl-background"})}var g=n(69730),m=n(12115),y=n(13982),b=n(67877),x=n(16038),w=n(50139);function v(e){return 2===e.button||y.Y.isDarwin&&0===e.button&&e.ctrlKey&&!e.metaKey}function S(e){return v(e)?2:e.button}function C(e,t){return e.markEventAsHandled(t),{point:{x:t.clientX,y:t.clientY,z:t.pressure},shiftKey:t.shiftKey,altKey:t.altKey,ctrlKey:t.metaKey||t.ctrlKey,metaKey:t.metaKey,accelKey:(0,w.g)(t),pointerId:t.pointerId,button:S(t),isPen:"pen"===t.pointerType}}var k=n(67863);function P(){let e=(0,k.hG)(),t=e.getContainerDocument(),n=(0,d.h)("current tool",()=>e.getCurrentTool(),[e]),r=(0,m.useMemo)(function(){let t=!1;return{onPointerDown:function(n){if(e.wasEventAlreadyHandled(n))return;let r=S(n);if(t=2===r,2===r&&!e.options.rightClickPanning)return void e.dispatch({type:"pointer",target:"canvas",name:"right_click",...C(e,n)});if(0!==r&&1!==r&&2!==r&&5!==r)return;let i="pen"===n.pointerType&&y.Y.isTouchDevice;(0,x.YY)(n.currentTarget,n),e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...C(e,n),isPenDirect:i})},onPointerUp:function(n){if(e.wasEventAlreadyHandled(n))return;let r=t?2:S(n);if(0!==r&&1!==r&&2!==r&&5!==r)return;let i=e.options.rightClickPanning,o=i&&2===r&&e.inputs.getIsPanning();if((0,x.hP)(n.currentTarget,n),e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...C(e,n),button:r}),i&&2===r&&!o){let e=new PointerEvent("contextmenu",{bubbles:!0,clientX:n.clientX,clientY:n.clientY,button:2,buttons:0,pointerId:n.pointerId,pointerType:n.pointerType,isPrimary:n.isPrimary});n.currentTarget.dispatchEvent(e)}t=!1},onPointerEnter:function(t){if(e.wasEventAlreadyHandled(t)||e.getInstanceState().isPenMode&&"pen"!==t.pointerType)return;let n="mouse"===t.pointerType||"pen"===t.pointerType;e.updateInstanceState({isHoveringCanvas:!!n||null})},onPointerLeave:function(t){if(e.wasEventAlreadyHandled(t)||e.getInstanceState().isPenMode&&"pen"!==t.pointerType)return;let n="mouse"===t.pointerType||"pen"===t.pointerType;e.updateInstanceState({isHoveringCanvas:!n&&null})},onDragOver:function(t){e.wasEventAlreadyHandled(t)||(0,x.wo)(t)},onDrop:async function t(t){if(e.wasEventAlreadyHandled(t))return;(0,x.wo)(t),t.stopPropagation();let n=e.screenToPage({x:t.clientX,y:t.clientY});if(e.options.experimental__onDropOnCanvas&&e.options.experimental__onDropOnCanvas({point:n,event:t}))return;if(t.dataTransfer?.files?.length){let r=Array.from(t.dataTransfer.files);await e.putExternalContent({type:"files",files:r,point:n});return}let r=t.dataTransfer.getData("url");if(r)return void await e.putExternalContent({type:"url",url:r,point:n})},onTouchStart:function(t){e.wasEventAlreadyHandled(t)||(e.markEventAsHandled(t),(0,x.wo)(t))},onTouchEnd:function(t){if(e.wasEventAlreadyHandled(t)||(e.markEventAsHandled(t),!(t.target instanceof e.getContainerWindow().HTMLElement)))return;let n=e.getEditingShapeId();n&&t.target.closest(`[data-shape-id="${n}"]`)||"A"===t.target.tagName||(0,x.oO)(t.target,!1)||(0,x.wo)(t)},onClick:function(t){e.wasEventAlreadyHandled(t)||t.stopPropagation()},onContextMenu:function(t){e.options.rightClickPanning&&t.nativeEvent.isTrusted&&v(t)&&(0,x.wo)(t)}}},[e]);return(0,m.useEffect)(()=>{let r,i;function o(t){if(!e.wasEventAlreadyHandled(t)){if(e.markEventAsHandled(t),t.clientX!==r||t.clientY!==i)for(let o of(r=t.clientX,i=t.clientY,!y.Y.isIos&&n.useCoalescedEvents&&t.getCoalescedEvents?t.getCoalescedEvents():[t]))e.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...C(e,o)})}}return t.body.addEventListener("pointermove",o),()=>{t.body.removeEventListener("pointermove",o)}},[e,n,t]),r}var T=n(87767);function E(e){return e.menus.hasOpenMenus()||(0,x.gh)(!0,e.getContainerDocument())}var I=n(46195);function _(e){let{deltaY:t,deltaX:n}=e,r=0;return e.ctrlKey||e.altKey||e.metaKey?r=(Math.abs(t)>10?10*Math.sign(t):t)/100:!e.shiftKey||y.Y.isDarwin||y.Y.isIos||(n=t,t=0),{x:-n,y:-t,z:-r}}var M=n(48077),A=n(26065),j=n(11421),O=n(93286);function D(e){let{x:t,y:n,z:r}=e.getCamera(),i=r>=1?(0,a.ww)(r,[1,8],[.125,.5],!0):(0,a.ww)(r,[.1,1],[-2,.125],!0);return`scale(${(0,O.WM)(r)}) translate(${(0,O.WM)(t+i)}px,${(0,O.WM)(n+i)}px)`}var L=n(73352);function R(e,t,n){return!(e.x<t.minX-12/n||e.y<t.minY-16/n||e.x>t.maxX-12/n||e.y>t.maxY-16/n)}let F=(0,d.u4)(function(){let e=(0,k.hG)(),{CollaboratorCursor:t}=(0,b.B)(),n=(0,m.useRef)(null);(0,m.useLayoutEffect)(()=>{let t=n.current;t&&(0,x.$h)(t,"transform",D(e))}),(0,d.lX)("position collaborators layer",function(){let t=D(e);(0,x.$h)(n.current,"transform",t)},[e]);let r=e.getVisibleCollaboratorsOnCurrentPage();return 0!==r.length&&t?(0,p.jsxs)("div",{className:"tl-collaborators",children:[(0,p.jsx)("svg",{className:"tl-svg-context","aria-hidden":"true",children:(0,p.jsx)("defs",{children:(0,p.jsx)(N,{})})}),(0,p.jsx)("div",{ref:n,className:"tl-html-layer",children:r.map(e=>(0,p.jsx)(z,{latestPresence:e},e.userId))})]}):null}),z=(0,d.u4)(function({latestPresence:e}){let t=(0,k.hG)(),{CollaboratorCursor:n}=(0,b.B)(),{userId:r,chatMessage:i,userName:o,cursor:s,color:a}=e,l=(0,d.h)("cursor in viewport",()=>!!s&&R(s,t.getViewportPageBounds(),t.getZoomLevel()),[t,s]),c=t.getZoomLevel();return s&&l&&n?(0,p.jsx)(n,{className:"tl-collaborator__cursor",userId:r,point:s,color:a,zoom:c,name:"New User"!==o?o:null,chatMessage:i??""}):null});function N(){return(0,p.jsxs)("g",{id:(0,L.Xh)("cursor"),children:[(0,p.jsxs)("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[(0,p.jsx)("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),(0,p.jsx)("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),(0,p.jsxs)("g",{fill:"white",transform:"translate(-12,-12)",children:[(0,p.jsx)("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),(0,p.jsx)("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),(0,p.jsxs)("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[(0,p.jsx)("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),(0,p.jsx)("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}var $=n(47650);function B(){let e=(0,k.hG)(),t=(0,d.h)("is menu open",()=>e.menus.hasAnyOpenMenus(),[e]),[n,r]=(0,m.useState)(!1),i=P(),o=(0,m.useRef)({isDown:!1,isDragging:!1,button:0,start:new I.l}),s=(0,m.useRef)(null);(0,m.useEffect)(()=>()=>{s.current?.(),s.current=null},[]);let a=(0,m.useCallback)(()=>{s.current?.();let t=e.getContainerDocument(),n=e=>{e.isTrusted&&(s.current?.(),s.current=null,e.preventDefault(),e.stopImmediatePropagation())},r=()=>t.removeEventListener("contextmenu",n,!0);s.current=r,t.addEventListener("contextmenu",n,!0),t.defaultView?.setTimeout(()=>{s.current===r&&(r(),s.current=null)},0)},[e]),l=(0,m.useCallback)(t=>{let n=S(t);if(0===n||2===n){if((0,$.flushSync)(()=>r(!0)),(0,x.YY)(t.currentTarget,t),o.current={isDown:!0,isDragging:!1,button:n,start:new I.l(t.clientX,t.clientY)},2===n){if(!e.options.rightClickPanning){a(),e.menus.clearOpenMenus();return}let n=e.getContainer().querySelector(".tl-canvas")??t.currentTarget;i.onPointerDown?.({...t,currentTarget:n}),a();return}e.menus.clearOpenMenus()}},[i,e,a]),c=(0,m.useCallback)(t=>{let n=o.current;if(n.isDown){if(2!==n.button&&!n.isDragging){if(I.l.Dist2(n.start,new I.l(t.clientX,t.clientY))<=e.options.dragDistanceSquared)return;n.isDragging=!0,e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...C(e,{...t,clientX:n.start.x,clientY:n.start.y})})}e.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...C(e,t)})}},[e]),h=(0,m.useCallback)(t=>{let n=2===o.current.button&&!o.current.isDragging;if(e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...C(e,t),button:2===o.current.button?2:S(t)}),n&&e.options.rightClickPanning){let n=e.getContainer().querySelector(".tl-canvas"),r=n?.parentElement??t.currentTarget;e.timers.requestAnimationFrame(()=>{r.dispatchEvent(new PointerEvent("contextmenu",{bubbles:!0,clientX:t.clientX,clientY:t.clientY,button:2,buttons:0,pointerId:t.pointerId,pointerType:t.pointerType,isPrimary:t.isPrimary}))})}(0,x.hP)(t.currentTarget,t),r(!1),o.current={isDown:!1,isDragging:!1,button:0,start:new I.l(t.clientX,t.clientY)}},[e]);return(t||n)&&(0,p.jsx)("div",{className:"tlui-menu-click-capture","data-testid":"menu-click-capture.content",...i,onPointerDown:l,onPointerMove:c,onPointerUp:h,onContextMenu:e=>{e.preventDefault(),e.stopPropagation()}})}var H=n(22036),U=n(75567);let K=(0,m.memo)(function(){let e=(0,k.hG)(),t=(0,m.useRef)(null);return(0,m.useEffect)(()=>{let n=(0,l.EW)("canvas overlays render inputs",()=>{let t=e.getInstanceState(),n=e.getCamera();return{dpr:t.devicePixelRatio,w:t.screenBounds.w,h:t.screenBounds.h,cx:n.x,cy:n.y,zoom:n.z}},{isEqual:(e,t)=>e.dpr===t.dpr&&e.w===t.w&&e.h===t.h&&e.cx===t.cx&&e.cy===t.cy&&e.zoom===t.zoom}),r=new l.VM("canvas overlays render",()=>{let r=t.current;if(!r)return;let i=r.getContext("2d");if(!i)return;let{dpr:o,w:s,h:a,cx:l,cy:d,zoom:c}=n.get(),h=Math.ceil(s*o),u=Math.ceil(a*o);(r.width!==h||r.height!==u)&&(r.width=h,r.height=u,r.style.width=`${s}px`,r.style.height=`${a}px`),i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,r.width,r.height);let p=o*c;for(let{util:t,overlays:n}of(i.setTransform(p,0,0,p,p*l,p*d),e.overlays.getActiveOverlayEntries()))i.save(),t.render(i,n),i.restore();if(j.bG.debugGeometry.get()){let t=e.inputs.getCurrentPagePoint();for(let n of e.getRenderingShapes()){let r=e.getShape(n.id);if(!r||"group"===r.type)continue;let o=e.getShapeGeometry(r),s=e.getShapePageTransform(r);if(!s)continue;i.save(),i.transform(s.a,s.b,s.c,s.d,s.e,s.f),i.strokeStyle=o.debugColor??"red",i.lineWidth=2/c,i.fillStyle="none",function e(t,n){if(n instanceof U.I){let r=t.strokeStyle;for(let i of n.children)i.debugColor&&(t.strokeStyle=i.debugColor),e(t,i),t.strokeStyle=r;for(let i of n.ignoredChildren)i.debugColor&&(t.strokeStyle=i.debugColor),e(t,i),t.strokeStyle=r;return}let r=n.vertices;if(!(r.length<2)){t.beginPath(),t.moveTo(r[0].x,r[0].y);for(let e=1;e<r.length;e++)t.lineTo(r[e].x,r[e].y);n.isClosed&&t.closePath(),t.stroke()}}(i,o);let{vertices:a}=o;for(let e=0;e<a.length;e++){let t=a[e],n=a.length>1?120+80*e/(a.length-1):160;i.fillStyle=`hsl(${n}, 100%, 50%)`,i.strokeStyle="black",i.lineWidth=1/c,i.beginPath(),i.arc(t.x,t.y,2/c,0,2*Math.PI),i.fill(),i.stroke()}let l=e.getPointInShapeSpace(r,t),d=Math.abs(o.distanceToPoint(l,!0))*c;if(d<150){let e=o.nearestPoint(l);i.strokeStyle=0>o.distanceToPoint(l,!0)?"goldenrod":"dodgerblue",i.lineWidth=2/c,i.globalAlpha=1-d/150,i.beginPath(),i.moveTo(e.x,e.y),i.lineTo(l.x,l.y),i.stroke(),i.globalAlpha=1}i.restore()}for(let{overlays:t}of(i.save(),i.strokeStyle="magenta",i.fillStyle="rgba(255, 0, 255, 0.1)",i.lineWidth=1/c,e.overlays.getActiveOverlayEntries()))for(let n of t){let t=e.overlays.getOverlayGeometry(n);if(!t)continue;let r=t.vertices;if(!(r.length<2)){i.beginPath(),i.moveTo(r[0].x,r[0].y);for(let e=1;e<r.length;e++)i.lineTo(r[e].x,r[e].y);for(let e of(t.isClosed&&(i.closePath(),i.fill()),i.stroke(),r))i.beginPath(),i.arc(e.x,e.y,2/c,0,2*Math.PI),i.fill()}}i.restore()}});return r.attach(),r.execute(),()=>r.detach()},[e]),(0,p.jsx)("canvas",{ref:t,className:"tl-canvas-overlays"})});function W({className:e}){let t,n,r,i,o,s,c,h,u=(0,k.hG)(),{Background:f,SvgDefs:v}=(0,b.B)(),S=(0,m.useRef)(null),C=(0,m.useRef)(null),A=(0,T.NF)();t=(0,k.hG)(),(0,m.useLayoutEffect)(()=>{let e=(0,a.nF)(()=>{!S.current||S.current.ownerDocument.body&&t.updateViewportScreenBounds(S.current)},200,{trailing:!0}),n=t.timers.setInterval(e,1e3),r=t.getContainerWindow();r.addEventListener("resize",e);let i=new ResizeObserver(t=>{t[0].contentRect&&e()}),o=S.current,s=null;return o&&(i.observe(o),(s=(e=>{let t=e.ownerDocument,n=(0,M.mD)(e),r=e.parentElement;for(;r&&r!==t.body;){let{overflowY:e}=n.getComputedStyle(r);if(r.scrollHeight>r.clientHeight&&("auto"===e||"scroll"===e||"overlay"===e))return r;r=r.parentElement}return t})(o)).addEventListener("scroll",e)),()=>{clearInterval(n),r.removeEventListener("resize",e),i.disconnect(),s?.removeEventListener("scroll",e),e.cancel()}},[t,S]),n=(0,k.hG)(),r=(0,T.NF)(),i=(0,d.h)("isEditing",()=>n.getEditingShapeId(),[n]),o=(0,d.h)("isFocused",()=>n.getIsFocused(),[n]),(0,m.useEffect)(()=>{if(r)return r.addEventListener("dragover",e),r.addEventListener("drop",e),()=>{r.removeEventListener("dragover",e),r.removeEventListener("drop",e)};function e(e){if(e.isSpecialRedispatchedEvent)return;(0,x.wo)(e),e.stopPropagation();let t=r.querySelector(".tl-canvas");if(!t)return;let n=new DragEvent(e.type,e);n.isSpecialRedispatchedEvent=!0,t.dispatchEvent(n)}},[r]),(0,m.useEffect)(()=>{let e=n.getContainerWindow();if(!("matchMedia"in e))return;let t=null,r=()=>{null!=t&&t();let i=`(resolution: ${e.devicePixelRatio}dppx)`,o=e.matchMedia(i),s=e=>{"change"===e.type&&r()};o.addEventListener?o.addEventListener("change",r):o.addListener&&o.addListener(s),t=()=>{o.removeEventListener?o.removeEventListener("change",r):o.removeListener&&o.removeListener(s)},n.updateInstanceState({devicePixelRatio:e.devicePixelRatio})};return r(),()=>{t?.()}},[n]),(0,m.useEffect)(()=>{if(!o)return;let e=e=>{if(e.altKey&&(n.isIn("zoom")||!n.getPath().endsWith(".idle"))&&!E(n)&&(0,x.wo)(e),n.wasEventAlreadyHandled(e))return;n.markEventAsHandled(e);let t=!!n.getSelectedShapeIds().length;switch(e.key){case"=":case"-":case"0":if(e.metaKey||e.ctrlKey)return void(0,x.wo)(e);break;case"Tab":if(E(n))return;t&&!i&&(0,x.wo)(e);break;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":if(E(n))return;t&&(e.metaKey||e.ctrlKey)&&(0,x.wo)(e);break;case",":return;case"Escape":if((n.getEditingShape()||n.getSelectedShapeIds().length>0)&&(0,x.wo)(e),n.menus.getOpenMenus().length>0)return;n.inputs.keys.has("Escape")||(n.inputs.keys.add("Escape"),n.cancel(),r.focus());return;default:if(E(n))return}let o={type:"keyboard",name:e.repeat?"key_repeat":"key_down",key:e.key,code:e.code,shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.metaKey||e.ctrlKey,metaKey:e.metaKey,accelKey:(0,w.g)(e)};n.dispatch(o)},t=e=>{if(n.wasEventAlreadyHandled(e)||(n.markEventAsHandled(e),E(n)||","===e.key))return;let t={type:"keyboard",name:"key_up",key:e.key,code:e.code,shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.metaKey||e.ctrlKey,metaKey:e.metaKey,accelKey:(0,w.g)(e)};n.dispatch(t)};function s(e){if(r.contains(e.target)){let t=e.touches[0].clientX,r=e.touches[0].radiusX||0,i=n.getContainerWindow().innerWidth;(t-r<10||t+r>i-10)&&(e.target?.tagName==="BUTTON"&&e.target?.click(),(0,x.wo)(e))}}let a=e=>{r.contains(e.target)&&(e.ctrlKey||e.metaKey)&&(0,x.wo)(e)};r.addEventListener("touchstart",s,{passive:!1}),r.addEventListener("wheel",a,{passive:!1});let l=r.ownerDocument;return l.addEventListener("gesturestart",x.wo),l.addEventListener("gesturechange",x.wo),l.addEventListener("gestureend",x.wo),r.addEventListener("keydown",e),r.addEventListener("keyup",t),()=>{r.removeEventListener("touchstart",s),r.removeEventListener("wheel",a),l.removeEventListener("gesturestart",x.wo),l.removeEventListener("gesturechange",x.wo),l.removeEventListener("gestureend",x.wo),r.removeEventListener("keydown",e),r.removeEventListener("keyup",t)}},[n,r,o,i]),s=(0,k.hG)(),(0,d.a1)("coarse pointer change",()=>{let e=y.$.get().isCoarsePointer;e!==(0,l.Pm)(()=>s.getInstanceState().isCoarsePointer)&&s.updateInstanceState({isCoarsePointer:e})},[s]),c=(0,k.hG)(),m.useEffect(()=>{let e=S.current;if(!e)return;let t="not sure";function n(e){if(!c.getInstanceState().isFocused)return;t="not sure";let n=c.getEditingShapeId();if(n){let e=c.getShape(n);if(e&&c.getShapeUtil(e).canScroll(e)){let e=c.getShapePageBounds(n);if(e?.containsPoint(c.inputs.getCurrentPagePoint()))return}}(0,x.wo)(e),e.stopPropagation();let r=_(e);if(0===r.x&&0===r.y)return;let i={type:"wheel",name:"wheel",delta:r,point:new I.l(e.clientX,e.clientY),shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.metaKey||e.ctrlKey,metaKey:e.metaKey,accelKey:(0,w.g)(e)};c.dispatch(i)}let r=1,i=1,o=0,s=new I.l,a=new I.l,l=[];function d(){let e=c.getBaseZoom(),{zoomSteps:t,zoomSpeed:n}=c.getCameraOptions(),r=t[0]*e,i=t[t.length-1]*e;return{min:r**(1/n),max:i**(1/n)}}function h(){let{zoomSpeed:e}=c.getCameraOptions();return c.getZoomLevel()**(1/e)}let u=1,p=1;function f(e){if(e&&(t="zooming"),"zooming"===t)return;let n=Math.abs(o-r),i=I.l.Dist(s,a);switch(t){case"not sure":n>24?t="zooming":i>16&&(t="panning");break;case"panning":n>64&&(t="zooming")}}function g(e,t,n,r,i){c.dispatch({type:"pinch",name:e,point:{x:t.x,y:t.y,z:r},delta:n,shiftKey:i.shiftKey,altKey:i.altKey,ctrlKey:i.metaKey||i.ctrlKey,metaKey:i.metaKey,accelKey:(0,w.g)(i)})}function m(e,t){return{origin:{x:(e.clientX+t.clientX)/2,y:(e.clientY+t.clientY)/2},distance:Math.hypot(t.clientX-e.clientX,t.clientY-e.clientY)}}function b(n){if((n.target===e||e?.contains(n.target))&&2===(l=Array.from(n.touches)).length){t="not sure";let{origin:e,distance:d}=m(l[0],l[1]);a.x=e.x,a.y=e.y,s.x=e.x,s.y=e.y,r=Math.max(d,1),o=d,i=c.getZoomLevel(),u=p=h(),g("pinch_start",e,{x:0,y:0},c.getZoomLevel(),n)}}function v(e){if((l=Array.from(e.touches)).length<2)return;let{origin:n,distance:s}=m(l[0],l[1]);o=s;let h=n.x-a.x,y=n.y-a.y;a.x=n.x,a.y=n.y,f(!1);let b=d(),x=s/r*p;switch(u=Math.min(b.max,Math.max(b.min,x)),t){case"zooming":g("pinch",n,{x:h,y:y},u**c.getCameraOptions().zoomSpeed,e);break;case"panning":g("pinch",n,{x:h,y:y},i,e)}}function C(e){let n=l.length>=2;if(l=Array.from(e.touches),n&&l.length<2){let n=u**c.getCameraOptions().zoomSpeed,r={...a};t="not sure",c.timers.requestAnimationFrame(()=>{g("pinch_end",r,{x:r.x,y:r.y},n,e)})}}let k=1;function P(n){(n.target===e||e?.contains(n.target))&&((0,x.wo)(n),n.stopPropagation(),t="not sure",u=k=h(),i=c.getZoomLevel(),a.x=n.clientX,a.y=n.clientY,s.x=n.clientX,s.y=n.clientY,r=1,o=1,g("pinch_start",{x:n.clientX,y:n.clientY},{x:0,y:0},c.getZoomLevel(),n))}function T(t){if(!(t.target===e||e?.contains(t.target)))return;(0,x.wo)(t),t.stopPropagation();let n=t.clientX-a.x,i=t.clientY-a.y;a.x=t.clientX,a.y=t.clientY;let s=d(),l=k*t.scale;u=Math.min(s.max,Math.max(s.min,l)),o=t.scale*r,f(!0);let h=u**c.getCameraOptions().zoomSpeed;g("pinch",{x:t.clientX,y:t.clientY},{x:n,y:i},h,t)}function E(n){if(!(n.target===e||e?.contains(n.target)))return;(0,x.wo)(n),n.stopPropagation();let r=u**c.getCameraOptions().zoomSpeed;t="not sure",c.timers.requestAnimationFrame(()=>{g("pinch_end",{x:n.clientX,y:n.clientY},{x:n.clientX,y:n.clientY},r,n)})}e.addEventListener("wheel",n,{passive:!1});let M=!y.Y.isIos&&"GestureEvent"in window;return M?(e.addEventListener("gesturestart",P),e.addEventListener("gesturechange",T),e.addEventListener("gestureend",E)):(e.addEventListener("touchstart",b),e.addEventListener("touchmove",v),e.addEventListener("touchend",C),e.addEventListener("touchcancel",C)),()=>{e.removeEventListener("wheel",n),M?(e.removeEventListener("gesturestart",P),e.removeEventListener("gesturechange",T),e.removeEventListener("gestureend",E)):(e.removeEventListener("touchstart",b),e.removeEventListener("touchmove",v),e.removeEventListener("touchend",C),e.removeEventListener("touchcancel",C))}},[c,S]),h=(0,k.hG)(),(0,m.useEffect)(()=>{let e=S.current;if(!e)return;let t=h.getContainerWindow(),n=e=>{if(e instanceof t.PointerEvent&&"pen"===e.pointerType){h.markEventAsHandled(e);let{target:n}=e;(0,x.oO)(n instanceof t.Element?n:null,!1)||h.isIn("select.editing_shape")||(0,x.wo)(e)}};return e.addEventListener("touchstart",n),e.addEventListener("touchend",n),()=>{e.removeEventListener("touchstart",n),e.removeEventListener("touchend",n)}},[h,S]),(0,d.lX)("update canvas state data attributes",()=>{let e=S.current;e&&(e.setAttribute("data-iseditinganything",null===u.getEditingShapeId()?"false":"true"),e.setAttribute("data-isselectinganything",0===u.getSelectedShapeIds().length?"false":"true"))},[u]);let O=(0,m.useRef)({lodDisableTextOutline:!1,canUpdateTextOutline:!0});(0,d.lX)("set text outline",function(){if(O.current.canUpdateTextOutline)if(y.Y.isSafari)A.style.setProperty("--tl-text-outline","none"),O.current.canUpdateTextOutline=!1;else{let e=u.getEfficientZoomLevel()<u.options.textShadowLod;e!==O.current.lodDisableTextOutline&&A.style.setProperty("--tl-text-outline",e?"none":"var(--tl-text-outline-reference)"),O.current.lodDisableTextOutline=e}},[u,A]),(0,d.lX)("position layers",function(){(0,x.$h)(C.current,"transform",D(u))},[u,A]);let L=P(),R=(0,d.h)("shapeSvgDefs",()=>{let e=new Map;for(let t of(0,a.Ic)(u.shapeUtils)){if(!t)return;for(let{key:n,component:r}of t.getCanvasSvgDefs())e.has(n)||e.set(n,(0,p.jsx)(r,{},n))}return[...e.values()]},[u]),z=(0,d.h)("debug_shapes",()=>j.bG.hideShapes.get(),[j.bG]),N=(0,d.h)("isGridMode",()=>u.getInstanceState().isGridMode,[u]),{Grid:$}=(0,b.B)();return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)("div",{ref:S,draggable:!1,className:g("tl-canvas",e),"data-testid":"canvas",...L,children:[(0,p.jsx)("svg",{className:"tl-svg-context","aria-hidden":"true",children:(0,p.jsxs)("defs",{children:[R,v&&(0,p.jsx)(v,{})]})}),f&&(0,p.jsx)("div",{className:"tl-background__wrapper",children:(0,p.jsx)(f,{})}),N&&$&&(0,p.jsx)(Y,{}),(0,p.jsxs)("div",{ref:C,className:"tl-html-layer tl-shapes",draggable:!1,children:[(0,p.jsx)(Z,{}),z?null:(0,p.jsx)(G,{canvasRef:S})]}),(0,p.jsx)(K,{}),(0,p.jsx)(Q,{})]}),(0,p.jsx)(V,{}),(0,p.jsx)(F,{}),(0,p.jsx)(B,{})]})}function V(){let e=(0,k.hG)(),{InFrontOfTheCanvas:t}=(0,b.B)();return t?(0,p.jsx)("div",{className:"tl-canvas__in-front",onPointerDown:e.markEventAsHandled,onPointerUp:e.markEventAsHandled,onTouchStart:e.markEventAsHandled,onTouchEnd:e.markEventAsHandled,children:(0,p.jsx)(t,{})}):null}function Y(){let e=(0,k.hG)(),t=(0,d.h)("gridSize",()=>e.getDocumentSettings().gridSize,[e]),{x:n,y:r,z:i}=(0,d.h)("camera",()=>e.getCamera(),[e]),{Grid:o}=(0,b.B)();return o?(0,p.jsx)(o,{x:n,y:r,z:i,size:t}):null}function G({canvasRef:e}){let t=(0,k.hG)(),n=(0,d.h)("debug svg",()=>j.bG.debugSvg.get(),[j.bG]),r=(0,d.h)("rendering shapes",()=>t.getRenderingShapes(),[t]);return(0,p.jsxs)(A.n,{children:[r.map(e=>n?(0,p.jsxs)(m.Fragment,{children:[(0,p.jsx)(H.yp,{...e}),(0,p.jsx)(J,{id:e.id,mode:"iframe"})]},e.id+"_fragment"):(0,p.jsx)(H.yp,{...e},e.id+"_shape")),(0,p.jsx)(X,{}),y.Y.isSafari&&(0,p.jsx)(q,{canvasRef:e})]})}function q({canvasRef:e}){let t=(0,k.hG)(),n=(0,m.useRef)(new Set);return(0,d.lX)("reflow for culled shapes",()=>{let r=t.getCulledShapes();if(n.current===r)return;n.current=r;let i=e.current;i&&i.offsetHeight},[t,e]),null}function X(){let e=(0,k.hG)(),{updateCulling:t}=(0,A.R)();return(0,d.lX)("update shape culling",()=>{t(e.getCulledShapes())},[e,t]),null}function J({id:e,mode:t}){let n=(0,k.hG)(),[r,i]=(0,m.useState)(null),o=(0,d.h)("is in root",()=>{let t=n.getShape(e);return t?.parentId===n.getCurrentPageId()},[n,e]);return((0,m.useEffect)(()=>{if(!o)return;let t=null,r=(0,l.wv)("shape to svg",async()=>{let r=Math.random();t=r;let o=n.getShape(e),s=10*!(o&&n.isShapeFrameLike(o)),a=n.getShapePageBounds(e);if(!a)return;a=a.clone().expandBy(s);let l=await n.getSvgString([e],{padding:s});t===r&&l&&i({src:`data:image/svg+xml;utf8,${encodeURIComponent(l.svg)}`,bounds:a})});return()=>{t=null,r()}},[n,e,o]),o&&r)?"iframe"===t?(0,p.jsx)("iframe",{src:r.src,width:r.bounds.width,height:r.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,border:"none",transform:`translate(${r.bounds.x}px, ${r.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}}):(0,p.jsx)("img",{src:r.src,width:r.bounds.width,height:r.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,transform:`translate(${r.bounds.x}px, ${r.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}}):null}function Z(){let{OnTheCanvas:e}=(0,b.B)();return e?(0,p.jsx)(e,{}):null}function Q(){let e=(0,k.hG)(),t=(0,d.h)("camera state",()=>e.getCameraState(),[e]);return(0,p.jsx)("div",{className:g("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":"idle"===t})})}let ee=(0,m.memo)(function({className:e,zoom:t,point:n,color:r,name:i,chatMessage:o}){var s,a,l;let d,c,h=(0,m.useRef)(null);s=n?.x,a=n?.y,l=1/t,d=void 0,c=void 0,(0,m.useLayoutEffect)(()=>{let e=h.current;if(!e||void 0===s)return;let t=`translate(${s}px, ${a}px)`;void 0!==l&&(t+=` scale(${l})`),void 0!==d&&void 0!==c&&(t+=` translate(${d}px, ${c}px)`),e.style.transform=t},[d,c,h,void 0,l,s,a]);let u=(0,L.Xh)("cursor");return n?(0,p.jsxs)("div",{ref:h,className:g("tl-collaborators__item",e),children:[(0,p.jsx)("svg",{className:"tl-cursor","aria-hidden":"true",children:(0,p.jsx)("use",{href:`#${u}`,color:r})}),o?(0,p.jsxs)(p.Fragment,{children:[i&&(0,p.jsx)("div",{className:"tl-nametag-title",style:{color:r},children:i}),(0,p.jsx)("div",{className:"tl-nametag-chat",style:{backgroundColor:r},children:o})]}):i&&(0,p.jsx)("div",{className:"tl-nametag",style:{backgroundColor:r},children:i})]}):null}),et=new WeakMap,en=new WeakMap,er=new WeakMap,ei=new WeakMap,eo=new WeakMap,es={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return en.get(e);if("objectStoreNames"===t)return e.objectStoreNames||er.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return ea(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function ea(e){if(e instanceof IDBRequest){let t;return(t=new Promise((t,n)=>{let r=()=>{e.removeEventListener("success",i),e.removeEventListener("error",o)},i=()=>{t(ea(e.result)),r()},o=()=>{n(e.error),r()};e.addEventListener("success",i),e.addEventListener("error",o)})).then(t=>{t instanceof IDBCursor&&et.set(t,e)}).catch(()=>{}),eo.set(t,e),t}if(ei.has(e))return ei.get(e);let t=function(e){if("function"==typeof e)return e!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(i||(i=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(el(this),t),ea(et.get(this))}:function(...t){return ea(e.apply(el(this),t))}:function(t,...n){let r=e.call(el(this),t,...n);return er.set(r,t.sort?t.sort():[t]),ea(r)};return e instanceof IDBTransaction&&function(e){if(en.has(e))return;let t=new Promise((t,n)=>{let r=()=>{e.removeEventListener("complete",i),e.removeEventListener("error",o),e.removeEventListener("abort",o)},i=()=>{t(),r()},o=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",i),e.addEventListener("error",o),e.addEventListener("abort",o)});en.set(e,t)}(e),(r||(r=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])).some(t=>e instanceof t)?new Proxy(e,es):e}(e);return t!==e&&(ei.set(e,t),eo.set(t,e)),t}let el=e=>eo.get(e);function ed(e,t,{blocked:n,upgrade:r,blocking:i,terminated:o}={}){let s=indexedDB.open(e,t),a=ea(s);return r&&s.addEventListener("upgradeneeded",e=>{r(ea(s.result),e.oldVersion,e.newVersion,ea(s.transaction),e)}),n&&s.addEventListener("blocked",e=>n(e.oldVersion,e.newVersion,e)),a.then(e=>{o&&e.addEventListener("close",()=>o()),i&&e.addEventListener("versionchange",e=>i(e.oldVersion,e.newVersion,e))}).catch(()=>{}),a}function ec(e,{blocked:t}={}){let n=indexedDB.deleteDatabase(e);return t&&n.addEventListener("blocked",e=>t(e.oldVersion,e)),ea(n).then(()=>void 0)}let eh=["get","getKey","getAll","getAllKeys","count"],eu=["put","add","delete","clear"],ep=new Map;function ef(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&"string"==typeof t))return;if(ep.get(t))return ep.get(t);let n=t.replace(/FromIndex$/,""),r=t!==n,i=eu.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(i||eh.includes(n)))return;let o=async function(e,...t){let o=this.transaction(e,i?"readwrite":"readonly"),s=o.store;return r&&(s=s.index(t.shift())),(await Promise.all([s[n](...t),i&&o.done]))[0]};return ep.set(t,o),o}es={...s=es,get:(e,t,n)=>ef(e,t)||s.get(e,t,n),has:(e,t)=>!!ef(e,t)||s.has(e,t)};let eg="TLDRAW_DB_NAME_INDEX_v2",em="records",ey="schema",eb="session_state",ex="assets";async function ew(e){var t;let n,r="TLDRAW_DOCUMENT_v2"+e;return t=r,(n=new Set(eC())).add(t),(0,a.Yz)(eg,JSON.stringify([...n])),await ed(r,4,{upgrade(e){e.objectStoreNames.contains(em)||e.createObjectStore(em),e.objectStoreNames.contains(ey)||e.createObjectStore(ey),e.objectStoreNames.contains(eb)||e.createObjectStore(eb),e.objectStoreNames.contains(ex)||e.createObjectStore(ex)}})}async function ev(e){let t=window.indexedDB.databases?(await window.indexedDB.databases()).map(e=>e.name):eC(),n="TLDRAW_ASSET_STORE_v1"+e;if(!t.find(e=>e===n))return;let r=await ed(n,1,{upgrade(e){e.objectStoreNames.contains("assets")||e.createObjectStore("assets")}});if(!r.objectStoreNames.contains("assets"))return;let i=r.transaction(["assets"],"readonly"),o=i.objectStore("assets"),s=await o.getAllKeys(),a=await Promise.all(s.map(async e=>[e,await o.get(e)]));await i.done;let l=await ew(e),d=l.transaction([ex],"readwrite"),c=d.objectStore(ex);for(let[e,t]of a)c.put(t,e);await d.done,r.close(),l.close(),await ec(n)}class eS{getDbPromise;isClosed=!1;pendingTransactionSet=new Set;static connectedInstances=new Set;constructor(e){eS.connectedInstances.add(this),this.getDbPromise=(async()=>(await ev(e),await ew(e)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(a.lQ)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),eS.connectedInstances.delete(this))}tx(e,t,n){let r=(async()=>{(0,a.vA)(!this.isClosed,"db is closed");let r=(await this.getDb()).transaction(t,e),i=r.done.catch(e=>{if(!this.isClosed)throw e});try{return await n(r)}finally{this.isClosed?r.abort():await i}})();return this.pendingTransactionSet.add(r),r.finally(()=>this.pendingTransactionSet.delete(r)),r}async load({sessionId:e}={}){return await this.tx("readonly",[em,ey,eb],async t=>{let n=t.objectStore(em),r=t.objectStore(ey),i=t.objectStore(eb),o=e?(await i.get(e))?.snapshot:null;if(!o){let e=await i.getAll();o=e.sort((e,t)=>e.updatedAt-t.updatedAt).pop()?.snapshot}return{records:await n.getAll(),schema:await r.get(ey),sessionStateSnapshot:o}})}async storeChanges({schema:e,changes:t,sessionId:n,sessionStateSnapshot:r}){await this.tx("readwrite",[em,ey,eb],async i=>{let o=i.objectStore(em),s=i.objectStore(ey),a=i.objectStore(eb);for(let[e,n]of Object.entries(t.added))await o.put(n,e);for(let[e,n]of Object.values(t.updated))await o.put(n,n.id);for(let e of Object.keys(t.removed))await o.delete(e);s.put(e.serialize(),ey),r&&n?a.put({snapshot:r,updatedAt:Date.now(),id:n},n):(r||n)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async storeSnapshot({schema:e,snapshot:t,sessionId:n,sessionStateSnapshot:r}){await this.tx("readwrite",[em,ey,eb],async i=>{let o=i.objectStore(em),s=i.objectStore(ey),a=i.objectStore(eb);for(let[e,n]of(await o.clear(),Object.entries(t)))await o.put(n,e);s.put(e.serialize(),ey),r&&n?a.put({snapshot:r,updatedAt:Date.now(),id:n},n):(r||n)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async pruneSessions(){await this.tx("readwrite",[eb],async e=>{let t=e.objectStore(eb),n=(await t.getAll()).sort((e,t)=>e.updatedAt-t.updatedAt);if(n.length<10)return void await e.done;for(let{id:e}of n.slice(0,n.length-10))await t.delete(e)})}async getAsset(e){return await this.tx("readonly",[ex],async t=>{let n=t.objectStore(ex);return await n.get(e)})}async storeAsset(e,t){await this.tx("readwrite",[ex],async n=>{let r=n.objectStore(ex);await r.put(t,e)})}async removeAssets(e){await this.tx("readwrite",[ex],async t=>{let n=t.objectStore(ex);for(let t of e)await n.delete(t)})}}function eC(){let e=JSON.parse((0,a.zM)(eg)||"[]")??[];return Array.isArray(e)?e:[]}async function ek({shouldReload:e=!0}={}){for(let e of((0,a.D6)(),eS.connectedInstances))await e.close();await Promise.all(eC().map(e=>ec(e))),(0,a.sw)(),e&&window.location.reload()}let eP={openWindow:(e,t,n=!1)=>window.open(e,t,n?"noopener":"noopener noreferrer"),refreshPage(){window.location.reload()},hardReset:async()=>await ek({shouldReload:!0})};function eT(e,t="_blank",n){return eP.openWindow(e,t,n)}function eE(){eP.hardReset()}var eI=n(1015);let e_=function({error:e,editor:t}){let n=(0,m.useRef)(null),[r,i]=(0,m.useState)(!1),[o,s]=(0,m.useState)(!1),[l,c]=(0,m.useState)(!1),h=null;try{h=(0,b.B)().Canvas??null}catch{}let u=e instanceof Error?e.message:String(e),f=e instanceof Error?e.stack:null,y=(0,d.h)("isDarkMode",()=>{try{if(t)return t.user.getIsDarkMode()}catch{}return null},[t]),[w,v]=(0,m.useState)(null);(0,m.useLayoutEffect)(()=>{null!==y&&v(y);let e=n.current?.parentElement,t=!1;for(;e;){if(e.classList.contains("tl-theme__dark")||e.classList.contains("tl-theme__light")){t=!0;break}e=e.parentElement}t?v(null):"u">typeof window&&(0,x.CM)().matchMedia&&v((0,x.CM)().matchMedia("(prefers-color-scheme: dark)").matches)},[y]),(0,m.useEffect)(()=>{if(o){let e=t?.timers.setTimeout(()=>{s(!1)},2e3);return()=>clearTimeout(e)}},[o,t]);let S=async()=>{eE()},C=new URL("https://github.com/tldraw/tldraw/issues/new");return C.searchParams.set("title",u),C.searchParams.set("labels","bug"),C.searchParams.set("body",`Hey, I ran into an error while using tldraw:
129
-
130
- \`\`\`js
131
- ${f??u}
132
- \`\`\`
133
-
134
- My browser: ${navigator.userAgent}`),(0,p.jsxs)("div",{ref:n,className:g("tl-container tl-error-boundary",null===w?"":w?"tl-theme__dark":"tl-theme__light"),children:[(0,p.jsx)("div",{className:"tl-error-boundary__overlay"}),t&&(0,p.jsx)(eI.t,{onError:a.lQ,fallback:()=>null,children:(0,p.jsx)(k.zz,{editor:t,children:(0,p.jsx)("div",{className:"tl-overlay tl-error-boundary__canvas",children:h?(0,p.jsx)(h,{}):null})})}),(0,p.jsx)("div",{className:g("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!l}),children:l?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)("h2",{children:"Are you sure?"}),(0,p.jsx)("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),(0,p.jsxs)("div",{className:"tl-error-boundary__content__actions",children:[(0,p.jsx)("button",{className:"tlui-button",onClick:()=>c(!1),children:"Cancel"}),(0,p.jsx)("button",{className:"tlui-button tl-error-boundary__reset",onClick:S,children:"Reset data"})]})]}):(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)("h2",{children:"Something went wrong"}),(0,p.jsx)("p",{children:"Please refresh your browser."}),(0,p.jsx)("p",{children:"If the issue continues after refreshing, you may need to reset the tldraw data stored on your device."}),(0,p.jsxs)("p",{children:[(0,p.jsx)("strong",{children:"Note:"})," Resetting will erase your current project and any unsaved work."]}),!1,r&&(0,p.jsxs)(p.Fragment,{children:["Message:",(0,p.jsx)("h4",{children:(0,p.jsx)("code",{children:u})}),"Stack trace:",(0,p.jsxs)("div",{className:"tl-error-boundary__content__error",children:[(0,p.jsx)("pre",{children:(0,p.jsx)("code",{children:f??u})}),(0,p.jsx)("button",{className:"tlui-button",onClick:()=>{let e=(0,M.TW)(n.current),t=e.createElement("textarea");t.value=f??u,e.body.appendChild(t),t.select(),e.execCommand("copy"),t.remove(),s(!0)},children:o?"Copied!":"Copy"})]})]}),(0,p.jsxs)("div",{className:"tl-error-boundary__content__actions",children:[(0,p.jsx)("button",{className:"tlui-button",onClick:()=>i(!r),children:r?"Hide details":"Show details"}),(0,p.jsxs)("div",{className:"tl-error-boundary__content__actions__group",children:[(0,p.jsx)("button",{className:"tlui-button tl-error-boundary__reset",onClick:()=>c(!0),children:"Reset data"}),(0,p.jsx)("button",{className:"tlui-button tl-error-boundary__refresh",onClick:()=>{eP.refreshPage()},children:"Refresh Page"})]})]})]})})]})};function eM({x:e,y:t,z:n,size:r}){let i=(0,L.Ls)("grid"),{gridSteps:o}=(0,k.hG)().options;return(0,p.jsxs)("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[(0,p.jsx)("defs",{children:o.map(({min:o,mid:s,step:l},d)=>{let c=l*r*n,h=.5+e*n,u=.5+t*n,f=h>0?h%c:c+h%c,g=u>0?u%c:c+u%c,m=n<s?(0,a.ww)(n,[o,s],[0,1]):1;return(0,p.jsx)("pattern",{id:(0,L.oX)(i,`${l}`),width:c,height:c,patternUnits:"userSpaceOnUse",children:(0,p.jsx)("circle",{className:"tl-grid-dot",cx:f,cy:g,r:1,opacity:m})},d)})}),o.map(({step:e},t)=>(0,p.jsx)("rect",{width:"100%",height:"100%",fill:`url(#${i}_${e})`},t))]})}let eA=(0,m.forwardRef)(function({children:e,shape:t,isBackground:n,...r},i){let o="fill"in t.props&&"none"!==t.props.fill;return(0,p.jsx)("div",{ref:i,"data-shape-type":t.type,"data-shape-is-filled":n?void 0:o,"data-shape-id":t.id,draggable:!1,...r,className:g("tl-shape",n&&"tl-shape-background",r.className),children:e})});function ej(e){return(0,p.jsx)("svg",{width:16,height:16,viewBox:"0 0 16 16","aria-hidden":"false",...e,className:g("tl-spinner",e.className),children:(0,p.jsxs)("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[(0,p.jsx)("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),(0,p.jsx)("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor"})]})})}let eO=(0,m.createContext)(null);function eD({host:e,children:t}){return(0,p.jsx)(eO.Provider,{value:e,children:t})}function eL({children:e,className:t="",...n}){return(0,p.jsx)("div",{...n,className:g("tl-html-container",t),children:e})}var eR=n(20172),eF=n(43631),ez=n(94833),eN=n(31832),e$=n(36649),eB=n(52800),eH=n(43336),eU=n(97986),eK=n(97156);let eW=e=>e.props.src,eV={currentUser:(0,l.EW)("defaultCurrentUser",()=>{let e=(0,eK.oE)();return e.id?h.XA.create({id:(0,h.dB)(e.id),name:e.name??"",color:e.color??eK.Tj.color}):null})},eY={upload:async(e,t)=>({src:await a.Sm.blobToDataUrl(t)})};function eG(e){return"schema"in e&&e.schema?e.schema:(0,h.Wt)({shapes:"shapeUtils"in e&&e.shapeUtils?eX((0,eH.u)(e.shapeUtils)):void 0,bindings:"bindingUtils"in e&&e.bindingUtils?eX((0,eB.t)(e.bindingUtils)):void 0,assets:"assetUtils"in e&&e.assetUtils?eX((0,e$.U)(e.assetUtils)):void 0,records:"records"in e?e.records:void 0,migrations:"migrations"in e?e.migrations:void 0})}function eq({initialData:e,defaultName:t="",id:n,assets:r=eY,users:i=eV,onMount:o,collaboration:s,themes:l,...d}={}){let u=(0,eN.P)(l);(0,h.Mc)(u),(0,h.AF)(u);let p=eG(d),f=new c.il({id:n,schema:p,initialData:e,props:{defaultName:t,assets:{upload:r.upload,resolve:r.resolve??eW,remove:r.remove??(()=>Promise.resolve())},users:{currentUser:i.currentUser,resolve:i.resolve??(0,h.gP)(e=>{let t=i.currentUser.get();return t&&t.id===(0,h.dB)(e)?t:null})},onMount:e=>{(0,a.vA)(e instanceof ez.K),o?.(e)},collaboration:s}});if(d.snapshot){if(e)throw Error("Cannot provide both initialData and snapshot");(0,eU.N)(f,d.snapshot,{forceOverwriteSessionState:!0})}return f}function eX(e){return Object.fromEntries(e.map(e=>[e.type,{props:e.props,migrations:e.migrations}]))}var eJ=n(59466),eZ=n(15727);class eQ{constructor(e){this.editor=e}editor;static configure(e){return class extends this{options={...this.options,...e}}}options={};static props;static migrations;static type;getSupportedMimeTypes(){return[]}acceptsMimeType(e){return this.getSupportedMimeTypes().includes(e)}async getAssetFromFile(e,t){return null}}class e0{constructor(e){this.editor=e}editor;static props;static migrations;static type}n(32314),n(98626),n(51286),n(8810),n(12318),n(73578),n(58929),n(66122),n(17858),n(2642);var e1=n(43502),e2=n(19743);n(40002),n(79224),n(99714),n(13004);var e3=n(93097),e5=n(26614);function e6(e,t,n={}){let{newPoint:r,handle:i,scaleX:o,scaleY:s}=t,{minWidth:a=1,maxWidth:l=1/0,minHeight:d=1,maxHeight:c=1/0}=n,h=e.props.w*o,u=e.props.h*s,p=new I.l(0,0);if(h>0){if(h<a){switch(i){case"top_left":case"left":case"bottom_left":p.x=h-a;break;case"top":case"bottom":p.x=(h-a)/2;break;default:p.x=0}h=a}}else if(p.x=h,(h=-h)<a){switch(i){case"top_left":case"left":case"bottom_left":p.x=-h;break;default:p.x=-a}h=a}if(u>0){if(u<d){switch(i){case"top_left":case"top":case"top_right":p.y=u-d;break;case"right":case"left":p.y=(u-d)/2;break;default:p.y=0}u=d}}else if(p.y=u,(u=-u)<d){switch(i){case"top_left":case"top":case"top_right":p.y=-u;break;default:p.y=-d}u=d}let{x:f,y:g}=p.rot(e.rotation).add(r);return{...e,x:f,y:g,props:{w:Math.min(l,h),h:Math.min(c,u)}}}class e4 extends e5.i{getGeometry(e){return new e3.k({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,t){return e6(e,t)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,t,n){return{...t.props,w:(0,a.Cc)(e.props.w,t.props.w,n),h:(0,a.Cc)(e.props.h,t.props.h,n)}}}class e8 extends e4{isFrameLike(e){return!0}providesBackgroundForChildren(){return!0}canReceiveNewChildrenOfType(e,t){return!e.isLocked}canRemoveChildrenOfType(e,t){return!e.isLocked}getClipPath(e){return this.editor.getShapeGeometry(e.id).vertices}shouldClipChild(e){return"arrow"!==e.type}onDragShapesIn(e,t,{initialParentIds:n,initialIndices:r}){let{editor:i}=this;if(t.every(t=>t.parentId===e.id))return;let o=!1,s=t.filter(t=>e.id===n.get(t.id));if(s.length>0){let t=(0,a.oE)(i.getSortedChildIdsForParent(e).map(e=>i.getShape(e)));s.every(e=>!t.find(t=>t.index===e.index))&&(o=!0)}if(!t.some(t=>i.hasAncestor(e,t.id))&&(i.reparentShapes(t,e.id),o))for(let e of s)i.updateShape({id:e.id,type:e.type,index:r.get(e.id)})}onDragShapesOut(e,t,n){let{editor:r}=this;n.nextDraggingOverShapeId||r.reparentShapes(t.filter(t=>t.parentId===e.id),r.getCurrentPageId())}}n(37920);let e9=new WeakMap;function e7(e,t,n){let r=e.editor.getCurrentTheme(),i=n??e.editor.getColorMode(),o=e9.get(t);if(o&&o.theme===r&&o.colorMode===i)return o.values;let s={...e.options.getDefaultDisplayValues(e.editor,t,r,i),...e.options.getCustomDisplayValues(e.editor,t,r,i)};return e9.set(t,{theme:r,colorMode:i,values:s}),s}n(61307);class te{constructor(e){this.editor=e}editor;static type;options={};static configure(e){return class extends this{options={...this.options,...e}}}getGeometry(e){return null}getCursor(e){}render(e,t){}renderMinimap(e,t,n){}dispose(){}}let tt=(0,c.uY)("shapeIndicatorPath",(e,t)=>e.getShapeUtil(t).getIndicatorPath(t),{areRecordsEqual:(e,t)=>e.props===t.props});function tn(e,t,n){if(0===n.length)return;let r=new Path2D;for(let i of n){let n=e.getShape(i);if(!n||n.isLocked)continue;let o=e.getShapePageTransform(n);if(!o)continue;let s=tt.get(e,n.id);if(!s)continue;if(s instanceof Path2D){r.addPath(s,o);continue}let{path:a,clipPath:l,additionalPaths:d}=s;if(!l){if(r.addPath(a,o),d)for(let e of d)r.addPath(e,o);continue}if(t.save(),t.transform(o.a,o.b,o.c,o.d,o.e,o.f),t.save(),t.clip(l,"evenodd"),t.stroke(a),t.restore(),d)for(let e of d)t.stroke(e);t.restore()}t.stroke(r)}var tr=n(71136);function ti(e,{initialBounds:t,scaleX:n,scaleY:r,newPoint:i,handle:o}){let s;switch(o){case"bottom_left":case"bottom_right":case"top_left":case"top_right":s=Math.max(.01,Math.max(Math.abs(n),Math.abs(r)));break;case"left":case"right":s=Math.max(.01,Math.abs(n));break;case"bottom":case"top":s=Math.max(.01,Math.abs(r));break;default:throw(0,a.h6)(o)}let l=new I.l(0,0);n<0&&(l.x=-(t.width*s)),r<0&&(l.y=-(t.height*s));let{x:d,y:c}=I.l.Add(i,l.rot(e.rotation));return{x:d,y:c,props:{scale:s*e.props.scale}}}var to=n(78663);class ts extends to.Y{static id="idle";onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}}class ta extends to.Y{static id="pointing";onPointerMove(e){let{editor:t}=this;if(t.inputs.getIsDragging()){let n=t.inputs.getOriginPagePoint(),r=this.parent.shapeType,i=(0,h.n6)(),o=t.markHistoryStoppingPoint(`creating_box:${i}`),s=tl(n,t);if(this.editor.createShapes([{id:i,type:r,x:s.x,y:s.y,props:{w:1,h:1}}]),!t.getShape(i))return void this.cancel();t.select(i);let a=this.parent;this.editor.setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:o,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:a.onCreate?e=>a.onCreate?.(e):void 0})}}onPointerUp(){this.complete()}onLongPress(){this.editor.getInstanceState().isCoarsePointer&&this.cancel()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){let e=this.editor.inputs.getOriginPagePoint(),t=this.parent.shapeType,n=(0,h.n6)();this.editor.markHistoryStoppingPoint(`creating_box:${n}`),this.editor.createShapes([{id:n,type:t,x:e.x,y:e.y}]);let r=this.editor.getShape(n);if(!r)return void this.cancel();let{w:i,h:o}=r.props,s=new I.l(i/2,o/2),l=this.editor.getShapeParentTransform(r);l&&s.rot(-l.rotation());let d=this.editor.getResizeScaleFactor();1!==d&&(i*=d,o*=d,s.mul(d));let c=(0,a.pN)(r),u=tl(new I.l(r.x-s.x,r.y-s.y),this.editor);c.x=u.x,c.y=u.y,c.props.w=i,c.props.h=o,"scale"in r.props&&(c.props.scale=d),this.editor.updateShape(c),this.editor.setSelectedShapes([n]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}}function tl(e,t){let n=t.getInstanceState().isGridMode,r=t.getDocumentSettings().gridSize;return n?e.clone().snapToGrid(r):e.clone()}class td extends to.Y{static id="box";static initial="idle";static children(){return[ts,ta]}}n(16398);var tc=n(50585);n(19065);var th=n(84469),tu=n(89658);function tp(){let e=(0,k.hG)(),t=(0,tc.Jf)();return(0,d.h)("colorMode",()=>t?t.colorMode:e.getColorMode(),[t,e])}let tf="<path d='m19.7432 17.0869-4.072 4.068 2.829 2.828-8.473-.013-.013-8.47 2.841 2.842 4.075-4.068 1.414-1.415-2.844-2.842h8.486v8.484l-2.83-2.827z' fill='%23fff'/><path d='m18.6826 16.7334-4.427 4.424 1.828 1.828-5.056-.016-.014-5.054 1.842 1.841 4.428-4.422 2.474-2.475-1.844-1.843h5.073v5.071l-1.83-1.828z' fill='%23000'/>",tg="<path d='m9 17.9907v.005l5.997 5.996.001-3.999h1.999 2.02v4l5.98-6.001-5.98-5.999.001 4.019-2.021.002h-2l.001-4.022zm1.411.003 3.587-3.588-.001 2.587h3.5 2.521v-2.585l3.565 3.586-3.564 3.585-.001-2.585h-2.521l-3.499-.001-.001 2.586z' fill='%23fff'/><path d='m17.4971 18.9932h2.521v2.586l3.565-3.586-3.565-3.585v2.605h-2.521-3.5v-2.607l-3.586 3.587 3.586 3.586v-2.587z' fill='%23000'/>",tm='<path d="M22.4789 9.45728L25.9935 12.9942L22.4789 16.5283V14.1032C18.126 14.1502 14.6071 17.6737 14.5675 22.0283H17.05L13.513 25.543L9.97889 22.0283H12.5674C12.6071 16.5691 17.0214 12.1503 22.4789 12.1031L22.4789 9.45728Z" fill="black"/><path fill-rule="evenodd" clip-rule="evenodd" d="M21.4789 7.03223L27.4035 12.9945L21.4789 18.9521V15.1868C18.4798 15.6549 16.1113 18.0273 15.649 21.0284H19.475L13.5128 26.953L7.55519 21.0284H11.6189C12.1243 15.8155 16.2679 11.6677 21.4789 11.1559L21.4789 7.03223ZM22.4789 12.1031C17.0214 12.1503 12.6071 16.5691 12.5674 22.0284H9.97889L13.513 25.543L17.05 22.0284H14.5675C14.5705 21.6896 14.5947 21.3558 14.6386 21.0284C15.1157 17.4741 17.9266 14.6592 21.4789 14.1761C21.8063 14.1316 22.1401 14.1069 22.4789 14.1032V16.5284L25.9935 12.9942L22.4789 9.45729L22.4789 12.1031Z" fill="white"/>';function ty(e,t,n,r,i,o=16,s=16){let a=(-n-t)*(O.PI/180),l=Math.sin(a),d=Math.cos(a);return`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${i};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${d-l}' dy='${+l+ +d}' stdDeviation='1.2' flood-opacity='.5'/></filter></defs><g fill='none' transform='rotate(${t+n} 16 16)${r?" scale(-1,-1) translate(0, -32)":""}' filter='url(%23shadow)'>`+e.replaceAll('"',"'")+`</g></svg>") ${o} ${s}, pointer`}let tb=["default","pointer","cross","comment","move","grab","grabbing","text","zoom-in","zoom-out"],tx={none:()=>"none","ew-resize":(e,t,n)=>ty(tg,e,0,t,n),"ns-resize":(e,t,n)=>ty(tg,e,90,t,n),"nesw-resize":(e,t,n)=>ty(tf,e,0,t,n),"nwse-resize":(e,t,n)=>ty(tf,e,90,t,n),"nwse-rotate":(e,t,n)=>ty(tm,e,0,t,n),"nesw-rotate":(e,t,n)=>ty(tm,e,90,t,n),"senw-rotate":(e,t,n)=>ty(tm,e,180,t,n),"swne-rotate":(e,t,n)=>ty(tm,e,270,t,n)};function tw(){let{Spinner:e}=(0,b.B)();return(0,p.jsx)("div",{className:"tl-loading","aria-busy":"true",tabIndex:0,children:e?(0,p.jsx)(e,{}):null})}let tv=function(){return(0,p.jsx)("div",{className:"tl-shape-error-boundary"})};function tS(){return null}var tC=n(80614);function tk({overrides:e={},children:t}){let n=(0,tC.d)(e),r=(0,m.useMemo)(()=>({Background:f,Canvas:W,CollaboratorCursor:ee,Grid:eM,InFrontOfTheCanvas:null,LoadingScreen:tw,OnTheCanvas:null,ShapeWrapper:eA,Spinner:ej,SvgDefs:tS,ErrorFallback:e_,ShapeErrorFallback:tv,...n}),[n]);return(0,p.jsx)(b.$.Provider,{value:r,children:t})}var tP=n(18314);function tT(e,t,n){let r=(0,m.useRef)(!1),i=(0,m.useCallback)(n=>{r.current=n,n?th.N.addOpenMenu(e):th.N.deleteOpenMenu(e),t?.(n)},[e,t]),o=(0,d.h)("is menu open",()=>th.N.getOpenMenus().includes(e),[e]);return(0,m.useEffect)(()=>(r.current&&(n?.("open-menu"),th.N.addOpenMenu(e)),()=>{r.current&&(th.N.deleteOpenMenu(e),th.N.getOpenMenus().forEach(t=>{t.startsWith(e)&&(n?.("close-menu"),th.N.deleteOpenMenu(t))}),r.current=!1)}),[e,n]),[o,i]}function tE(e){let t=(0,k.hG)();return(0,d.h)("isEditing",()=>t.getEditingShapeId()===e,[t,e])}let tI=Symbol("UPDATE_INSTANCE_STATE");class t_{onmessage;constructor(e){}postMessage(e){}close(){}}let tM="u"<typeof BroadcastChannel?t_:BroadcastChannel;class tA{constructor(e,{persistenceKey:t,sessionId:n=eJ.Os,onLoad:r,onLoadError:i},o=new tM(`tldraw-tab-sync-${t}`)){this.store=e,this.channel=o,"u">typeof window&&(window.tlsync=this),this.persistenceKey=t,this.sessionId=n,this.db=new eS(t),this.disposables.add(()=>this.db.close()),this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=(0,eJ.e6)(this.store),this.disposables.add(e.listen(({changes:e})=>{this.diffQueue.push(e),this.channel.postMessage({type:"diff",storeId:this.store.id,changes:e,schema:this.serializedSchema}),this.schedulePersist()},{source:"user",scope:"document"})),this.disposables.add(e.listen(()=>{this.diffQueue.push(tI),this.schedulePersist()},{scope:"session"})),this.connect(r,i),this.documentTypes=new Set(Object.values(this.store.schema.types).filter(e=>"document"===e.scope).map(e=>e.typeName))}store;channel;disposables=new Set;diffQueue=[];didDispose=!1;shouldDoFullDBWrite=!0;isReloading=!1;persistenceKey;sessionId;serializedSchema;isDebugging=!1;documentTypes;$sessionStateSnapshot;db;initTime=Date.now();debug(...e){this.isDebugging&&console.debug(...e)}async connect(e,t){let n;this.debug("connecting");try{n=await this.db.load({sessionId:this.sessionId})}catch(e){t(e),window.alert(`Oops! We could not access your browser's storage\u2014and the app won't work correctly without that. We now need to reload the page and try again.
135
-
136
- Keep seeing this message?
137
- \u2022 If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`);return}if(this.debug("loaded data from store",n,"didDispose",this.didDispose),!this.didDispose)try{if(n){let e=Object.fromEntries(n.records.map(e=>[e.id,e])),r=n.sessionStateSnapshot??(0,eJ.WK)(e),i=this.store.schema.migrateStoreSnapshot({store:e,schema:n.schema??this.store.schema.serializeEarliestVersion()});if("error"===i.type){console.error("failed to migrate store",i),t(Error(`Failed to migrate store: ${i.reason}`));return}let o=Object.values(i.value).filter(e=>this.documentTypes.has(e.typeName));o.length>0&&this.store.mergeRemoteChanges(()=>{this.store.put(o,"initialize")}),r&&(0,eJ.Jr)(this.store,r,{forceOverwrite:!0})}this.channel.onmessage=({data:e})=>{this.debug("got message",e);let n=this.store.schema.getMigrationsSince(e.schema);if(!n.ok)return Date.now()-this.initTime<5e3?void t(Error("Schema mismatch, please close other tabs and reload the page")):(this.debug("reloading"),this.isReloading=!0,void window?.location?.reload?.());if(n.value.length>0){this.debug("telling them to reload"),this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.shouldDoFullDBWrite=!0,this.persistIfNeeded();return}"diff"===e.type&&(this.debug("applying diff"),(0,l.hL)(()=>{this.store.mergeRemoteChanges(()=>{this.store.applyDiff(e.changes)})}))},this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.disposables.add(()=>{this.channel.close()}),e(this)}catch(e){if(this.debug("error loading data from store",e),this.didDispose)return;t(e);return}}close(){this.debug("closing"),this.didDispose=!0,this.disposables.forEach(e=>e()),"u">typeof window&&window.tlsync===this&&delete window.tlsync}isPersisting=!1;didLastWriteError=!1;scheduledPersistTimeout=null;schedulePersist(){this.debug("schedulePersist",this.scheduledPersistTimeout),this.scheduledPersistTimeout||(this.scheduledPersistTimeout=setTimeout(()=>{this.scheduledPersistTimeout=null,this.persistIfNeeded()},this.didLastWriteError?1e4:350))}persistIfNeeded(){this.debug("persistIfNeeded",{isPersisting:this.isPersisting,isReloading:this.isReloading,shouldDoFullDBWrite:this.shouldDoFullDBWrite,diffQueueLength:this.diffQueue.length,storeIsPossiblyCorrupt:this.store.isPossiblyCorrupted()}),this.scheduledPersistTimeout&&(clearTimeout(this.scheduledPersistTimeout),this.scheduledPersistTimeout=null),this.isPersisting||this.isReloading||!this.store.isPossiblyCorrupted()&&(this.shouldDoFullDBWrite||this.diffQueue.length>0)&&this.doPersist()}async doPersist(){if((0,a.vA)(!this.isPersisting,"persist already in progress"),this.didDispose)return;this.isPersisting=!0,this.debug("doPersist start");let e=this.diffQueue;this.diffQueue=[];try{if(this.shouldDoFullDBWrite)this.shouldDoFullDBWrite=!1,await this.db.storeSnapshot({schema:this.store.schema,snapshot:this.store.serialize(),sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{let t=(0,c.Dm)(e.filter(e=>e!==tI));await this.db.storeChanges({changes:t,schema:this.store.schema,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()})}this.didLastWriteError=!1}catch(e){this.shouldDoFullDBWrite=!0,this.didLastWriteError=!0,console.error("failed to store changes in indexed db",e),window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
138
-
139
- Keep seeing this message?
140
- \u2022 If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
141
- \u2022 If your hard disk is full, try clearing up some space and then reload the page.`),"u">typeof window&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function tj(e){let t=(0,m.useRef)(e),[n,r]=(0,m.useState)(e);return n!==t.current&&r(t.current),[n,(0,m.useCallback)(e=>{"function"==typeof e?t.current=e(t.current):t.current=e,r(t.current)},[])]}function tO(e){return"auto"===e||"scroll"===e||"overlay"===e}function tD(e){let t=e.scrollHeight>e.clientHeight,n=e.scrollWidth>e.clientWidth;if(!t&&!n)return!1;let r=getComputedStyle(e);return t&&tO(r.overflowY)||n&&tO(r.overflowX)}function tL(e){if(!e)throw Error("usePassThroughWheelEvents must be passed a ref");let t=(0,T.NF)(),n=(0,k.fr)(),r=(0,tP._)(r=>{if(!n?.getInstanceState().isFocused||r.isSpecialRedispatchedEvent)return;let i=e.current;if(i&&function(e,t){if(!(e instanceof Node))return tD(t);let n=e instanceof Element?e:e.parentElement;for(;n;){if(n instanceof HTMLElement&&tD(n))return!0;if(n===t)break;n=n.parentElement}return!1}(r.target,i))return;(0,x.wo)(r);let o=t.querySelector(".tl-canvas");if(!o)return;let s=new WheelEvent("wheel",r);s.isSpecialRedispatchedEvent=!0,o.dispatchEvent(s)}),i=(0,m.useRef)(null);(0,m.useEffect)(()=>{let t=e.current;t!==i.current&&(i.current?.removeEventListener("wheel",r),i.current=t,t?.addEventListener("wheel",r,{passive:!1}))}),(0,m.useEffect)(()=>()=>{i.current?.removeEventListener("wheel",r),i.current=null},[r])}function tR(e){return(0,a.sb)(e)}function tF(){let e=(0,k.hG)(),t=(0,d.HO)("userIds",()=>tR(e.getVisibleCollaborators().map(e=>e.userId)).sort(),{isEqual:(e,t)=>e.join(",")===t.join?.(",")},[e]);return(0,d.h)(t)}function tz(e){let t=(0,k.hG)();return(0,d.h)(`latestPresence:${e}`,()=>t.getCollaborators().find(t=>t.userId===e),[t,e])??null}function tN(e){let[t,n]=(0,m.useState)(()=>({store:eq(e),opts:e}));if(!(0,a.zK)(t.opts,e)){let t={store:eq(e),opts:e};return n(t),t.store}return t.store}function t$(e){let[t,n]=(0,m.useState)(()=>({opts:e,schema:eG(e)}));if(!(0,a.zK)(t.opts,e)){let t=eG(e);return n({opts:e,schema:t}),t}return t.schema}var tB=n(13656),tH=n(23919);function tU(e){let t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let t=0,r=e.length;t<r;t++)n[t]=e.charCodeAt(t);return t}let tK={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4,WITH_WATERMARK:8,EVALUATION_LICENSE:16,NATIVE_LICENSE:32,FEAT_COLLABORATION:64,FEAT_COMMENTING:128},tW=Math.max(...Object.values(tK)),tV={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},tY=Object.keys(tV).length,tG="sales@tldraw.com",tq=`${(0,tH.H)()}/watermarks/watermark-track.svg`,tX={collaboration:!1,commenting:!1},tJ={collaboration:!0,commenting:!0};class tZ{publicKey="MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ";isDevelopment;isTest;isCryptoAvailable;state=(0,l.eU)("license state","pending");featureFlags=(0,l.eU)("license feature flags",{...tX});verbose=!0;constructor(e,t){this.isTest=!1,this.isDevelopment=this.getIsDevelopment(),this.publicKey=t||this.publicKey,this.isCryptoAvailable=!!crypto.subtle,this.isDevelopment&&this.featureFlags.set({...tJ}),this.getLicenseFromKey(e).then(e=>{let t=function(e,t,n){if(!e.isLicenseParseable)return n?"unlicensed":(t("no-key-provided"===e.reason?["No tldraw license key provided!","A license is required for production deployments.",`Please reach out to ${tG} to purchase a license.`]:["Invalid license key. tldraw requires a valid license for production use.",`Please reach out to ${tG} to purchase a license.`]),"unlicensed-production");if(!e.isDomainValid&&!e.isDevelopment)return t(["License key is not valid for this domain.","A license is required for production deployments.",`Please reach out to ${tG} to purchase a license.`]),"unlicensed-production";if(e.isEvaluationLicense)if(e.isEvaluationLicenseExpired)return t(["Your tldraw evaluation license has expired!",`Please reach out to ${tG} to purchase a full license.`]),"expired";else return"licensed";if(e.isPerpetualLicenseExpired||e.isAnnualLicenseExpired)return t(["Your tldraw license has been expired for more than 30 days!",`Please reach out to ${tG} to renew your license.`]),"expired";let r=e.daysSinceExpiry;return r>0&&!e.isEvaluationLicense?(t(["Your tldraw license has expired.",`License expired ${r} days ago.`,`Please reach out to ${tG} to renew your license.`]),"licensed"):e.isLicensedWithWatermark?"licensed-with-watermark":"licensed"}(e,e=>this.outputMessages(e),this.isDevelopment);this.maybeTrack(e,t),(0,l.hL)(()=>{var n,r;this.state.set(t),this.featureFlags.set((n=e,r=t,this.isDevelopment?{...tJ}:n.isLicenseParseable&&("licensed"===r||"licensed-with-watermark"===r)?n.isEvaluationLicense?{...tJ}:{collaboration:n.isCollaborationEnabled,commenting:n.isCommentingEnabled}:{...tX}))})}).catch(e=>{console.error("License validation failed:",e),this.state.set("unlicensed")})}isFeatureEnabled(e){return this.featureFlags.get()[e]}getIsDevelopment(){let e=window.location.protocol,t=window.location.hostname;return!t.toLowerCase().endsWith(".localhost")&&("http:"===e||"https:"===e&&this.isLoopbackHost(t)||!1)}isLoopbackHost(e){let t=e.toLowerCase().replace(/^\[|\]$/g,"");return"localhost"===t||"::1"===t||/^127(?:\.\d{1,3}){3}$/.test(t)}getTrackType(e,t){return"unlicensed-production"===t?"unlicensed":this.isDevelopment||!e.isLicenseParseable?null:e.isEvaluationLicense?"evaluation":"licensed-with-watermark"===t?"with_watermark":null}maybeTrack(e,t){let n=this.getTrackType(e,t);if(!n)return;let r=new URL(tq);if(r.searchParams.set("version",tB.r),r.searchParams.set("license_type",n),"license"in e){r.searchParams.set("license_id",e.license.id);let t=this.isFlagEnabled(e.license.flags,tK.EVALUATION_LICENSE)?"evaluation":this.isFlagEnabled(e.license.flags,tK.ANNUAL_LICENSE)?"annual":this.isFlagEnabled(e.license.flags,tK.PERPETUAL_LICENSE)?"perpetual":"unknown";r.searchParams.set("sku",t)}r.searchParams.set("url",window.location.href),r.searchParams.set("environment","production"),fetch(r.toString())}async extractLicenseKey(e){let t,n,r,[i,o]=e.split("."),[s,a]=i.split("/");if(!s.startsWith("tldraw-"))throw Error(`Unsupported prefix '${s}'`);let l=await (r=tU(atob(this.publicKey)),crypto.subtle.importKey("spki",new Uint8Array(r),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"]));try{t=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},l,new Uint8Array(tU(atob(o))),new Uint8Array(tU(atob(a))))}catch(e){throw console.error(e),Error("Could not perform signature validation")}if(!t)throw Error("Invalid signature");try{n=JSON.parse(atob(a))}catch{throw Error("Could not parse object")}return n.length>tY&&this.outputMessages(["License key contains some unknown properties.","You may want to update tldraw packages to a newer version to get access to new functionality."]),{id:n[tV.ID],hosts:n[tV.HOSTS],flags:n[tV.FLAGS],expiryDate:n[tV.EXPIRY_DATE]}}async getLicenseFromKey(e){if(!e)return this.isDevelopment||this.outputNoLicenseKeyProvided(),{isLicenseParseable:!1,reason:"no-key-provided"};if(this.isDevelopment&&!this.isCryptoAvailable)return this.verbose&&(console.log("tldraw: you seem to be in a development environment that does not support crypto. License not verified."),console.log("You should check that this works in production separately.")),{isLicenseParseable:!1,reason:"has-key-development-mode"};let t=e.replace(/[\u200B-\u200D\uFEFF]/g,"");t=t.replace(/\r?\n|\r/g,"");try{let e=await this.extractLicenseKey(t),n=new Date(e.expiryDate),r=this.isFlagEnabled(e.flags,tK.ANNUAL_LICENSE),i=this.isFlagEnabled(e.flags,tK.PERPETUAL_LICENSE),o=this.isFlagEnabled(e.flags,tK.EVALUATION_LICENSE),s=r&&this.isAnnualLicenseExpired(n),a=i&&this.isPerpetualLicenseExpired(n),l=this.isFlagEnabled(e.flags,tK.FEAT_COLLABORATION),d=l||this.isFlagEnabled(e.flags,tK.FEAT_COMMENTING),c=i&&!a?0:this.getDaysSinceExpiry(n),h={license:e,isLicenseParseable:!0,isDevelopment:this.isDevelopment,isDomainValid:this.isDomainValid(e),expiryDate:n,isAnnualLicense:r,isAnnualLicenseExpired:s,isPerpetualLicense:i,isPerpetualLicenseExpired:a,isInternalLicense:this.isFlagEnabled(e.flags,tK.INTERNAL_LICENSE),isNativeLicense:this.isNativeLicense(e),isLicensedWithWatermark:this.isFlagEnabled(e.flags,tK.WITH_WATERMARK),isEvaluationLicense:o,isEvaluationLicenseExpired:o&&this.isEvaluationLicenseExpired(n),isCollaborationEnabled:l,isCommentingEnabled:d,daysSinceExpiry:c};return this.outputLicenseInfoIfNeeded(h),h}catch(e){return this.outputInvalidLicenseKey(e.message),{isLicenseParseable:!1,reason:"invalid-license-key"}}}isDomainValid(e){let t=window.location.hostname.toLowerCase();return e.hosts.some(n=>{let r=n.toLowerCase().trim();if(r===t||`www.${r}`===t||r===`www.${t}`||"*"===n)return!0;if(this.isNativeLicense(e))return new RegExp(r).test(window.location.href);if(n.includes("*")){let e=RegExp(r.replace(/\./g,"\\.").replace(/\*/g,".*?")+"$");return e.test(t)||e.test(`www.${t}`)}return"vscode-webview:"===window.location.protocol&&r===new URL(window.location.href).searchParams.get("extensionId")||!1})}isNativeLicense(e){return this.isFlagEnabled(e.flags,tK.NATIVE_LICENSE)}getExpirationDateWithoutGracePeriod(e){return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()+1))}getExpirationDateWithGracePeriod(e){return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()+30+1))}isAnnualLicenseExpired(e){let t=this.getExpirationDateWithGracePeriod(e);return new Date>=t}isPerpetualLicenseExpired(e){let t=this.getExpirationDateWithGracePeriod(e),n={major:new Date(tB.p.major),minor:new Date(tB.p.minor)};return n.major>=t||n.minor>=t}getDaysSinceExpiry(e){let t=new Date,n=this.getExpirationDateWithoutGracePeriod(e);return Math.max(0,Math.floor((t.getTime()-n.getTime())/864e5))}isEvaluationLicenseExpired(e){return new Date>=this.getExpirationDateWithoutGracePeriod(e)}isFlagEnabled(e,t){return(e&t)===t}outputNoLicenseKeyProvided(){}outputInvalidLicenseKey(e){this.outputMessages(["Invalid tldraw license key",`Reason: ${e}`])}outputLicenseInfoIfNeeded(e){e.license.flags>=2*tW&&this.outputMessages(["Warning: This tldraw license contains some unknown flags.","This will still work, however, you may want to update tldraw packages to a newer version to get access to new functionality."],"warning")}outputMessages(e,t="error"){if(!this.isTest&&this.verbose){for(let n of(this.outputDelimiter(t),e)){let e="warning"===t?"orange":"crimson";console.log(`%c${n}`,`color: white; background: ${e}; padding: 2px; border-radius: 3px;`)}this.outputDelimiter(t)}}outputDelimiter(e="error"){console.log("%c-------------------------------------------------------------------",`color: white; background: ${"warning"===e?"orange":"crimson"}; padding: 2px; border-radius: 3px;`)}static className="tl-watermark_SEE-LICENSE"}var tQ=n(41463);let t0=(0,m.createContext)(null);function t1(){let e=t2();if(!e)throw Error("useLicenseContext must be used inside of the <Tldraw /> or <TldrawEditor /> components, or inside an <EditorProvider /> wrapping an editor created by them");return e}function t2(){let e=(0,m.useContext)(t0),t=(0,k.fr)();return e??t?.licenseManager??null}function t3(e){return"expired"===e||"unlicensed-production"===e}function t5({licenseKey:e=(void 0!==o?o:o=t4(()=>tQ.env.TLDRAW_LICENSE_KEY)||t4(()=>tQ.env.NEXT_PUBLIC_TLDRAW_LICENSE_KEY)||t4(()=>tQ.env.REACT_APP_TLDRAW_LICENSE_KEY)||t4(()=>tQ.env.GATSBY_TLDRAW_LICENSE_KEY)||t4(()=>tQ.env.VITE_TLDRAW_LICENSE_KEY)||t4(()=>tQ.env.PUBLIC_TLDRAW_LICENSE_KEY)||t4(()=>(void 0).TLDRAW_LICENSE_KEY)||t4(()=>(void 0).NEXT_PUBLIC_TLDRAW_LICENSE_KEY)||t4(()=>(void 0).REACT_APP_TLDRAW_LICENSE_KEY)||t4(()=>(void 0).GATSBY_TLDRAW_LICENSE_KEY)||t4(()=>(void 0).VITE_TLDRAW_LICENSE_KEY)||t4(()=>(void 0).PUBLIC_TLDRAW_LICENSE_KEY)||null)??void 0,children:t}){let[n]=(0,m.useState)(()=>new tZ(e)),r=(0,d.h)(n.state),[i,s]=(0,m.useState)(!0);return((0,m.useEffect)(()=>{if(t3(r)&&i){let e=setTimeout(()=>{s(!1)},5e3);return()=>clearTimeout(e)}},[r,i]),t3(r)&&!i)?(0,p.jsx)(t6,{}):(0,p.jsx)(t0.Provider,{value:n,children:t})}function t6(){return(0,p.jsx)("div",{"data-testid":"tl-license-expired",style:{display:"none"}})}function t4(e){try{return e()}catch{return}}function t8(e,t){return(0,d.h)("licenseFeature",()=>!!e&&e.isFeatureEnabled(t),[e,t])}n(65390);var t9=n(59830),t7=n(58347),ne=n(81962);function nt(e,t=20){return Math.max(8,Math.ceil(e/t))}var nn=n(27164);class nr extends nn.vq{_center;_radius;_start;_end;_largeArcFlag;_sweepFlag;_measure;_angleStart;_angleEnd;constructor(e){super({...e,isFilled:!1,isClosed:!1});const{center:t,sweepFlag:n,largeArcFlag:r,start:i,end:o}=e;if(i.equals(o))throw Error("Arc must have different start and end points.");this._angleStart=I.l.Angle(t,i),this._angleEnd=I.l.Angle(t,o),this._radius=I.l.Dist(t,i),this._measure=(0,O.rq)(this._angleStart,this._angleEnd,n,r),this._start=i,this._end=o,this._sweepFlag=n,this._largeArcFlag=r,this._center=t}nearestPoint(e){let{_center:t,_measure:n,_radius:r,_angleEnd:i,_angleStart:o,_start:s,_end:a}=this,l=(0,O.yi)(n,o,i,t.angle(e));if(l<=0)return s;if(l>=1)return a;let d=e.x-t.x,c=e.y-t.y,h=Math.sqrt(d*d+c*c);if(0===h)return s;let u=r/h;return new I.l(t.x+d*u,t.y+c*u)}hitTestLineSegment(e,t){let{_center:n,_radius:r,_measure:i,_angleStart:o,_angleEnd:s}=this,a=(0,ne.vr)(e,t,n,r);return null!==a&&a.some(e=>{let t=(0,O.yi)(i,o,s,n.angle(e));return t>=0&&t<=1})}getVertices(){let{_center:e,_measure:t,length:n,_radius:r,_angleStart:i}=this,o=[];for(let s=0,a=nt(Math.abs(n));s<a+1;s++){let n=i+s/a*t;o.push((0,O.AQ)(e,r,n))}return o}getSvgPathData(e=!0){let{_start:t,_end:n,_radius:r,_largeArcFlag:i,_sweepFlag:o}=this;return`${e?`M${t.toFixed()}`:""} A${r} ${r} 0 ${i} ${o} ${n.toFixed()}`}getLength(){return Math.abs(this._measure*this._radius)}}class ni extends nn.vq{constructor(e){super({isClosed:!0,...e}),this.config=e;const{x:t=0,y:n=0,radius:r}=e;this._x=t,this._y=n,this._center=new I.l(r+t,r+n),this._radius=r}config;_center;_radius;_x;_y;getBounds(){return new t9.az(this._x,this._y,2*this._radius,2*this._radius)}getVertices(){let{_center:e,_radius:t}=this,n=O.uA*t,r=[];for(let i=0,o=nt(n);i<o;i++){let n=i/o*O.uA;r.push((0,O.AQ)(e,t,n))}return r}nearestPoint(e){let{_center:t,_radius:n}=this,r=e.x-t.x,i=e.y-t.y,o=Math.sqrt(r*r+i*i);if(0===o)return new I.l(t.x+n,t.y);let s=n/o;return new I.l(t.x+r*s,t.y+i*s)}distanceToPoint(e,t=!1){let{_center:n,_radius:r}=this,i=e.x-n.x,o=e.y-n.y,s=Math.sqrt(i*i+o*o)-r;return s<0&&(this.isFilled||t)?s:Math.abs(s)}hitTestPoint(e,t=0,n=!1){let{_center:r,_radius:i}=this,o=e.x-r.x,s=e.y-r.y,a=o*o+s*s;if((this.isFilled||n)&&a<=i*i)return!0;let l=i+t;if(a>l*l)return!1;let d=i-t;return d<=0||a>=d*d}hitTestLineSegment(e,t,n=0){let{_center:r,_radius:i}=this;return null!==(0,ne.vr)(e,t,r,i+n)}getSvgPathData(){let{_center:e,_radius:t}=this;return`M${e.x+t},${e.y} a${t},${t} 0 1,0 ${2*t},0a${t},${t} 0 1,0 -${2*t},0`}}var no=n(31796);class ns extends no.H{_a;_b;_c;_d;_resolution;constructor(e){const{start:t,cp1:n,cp2:r,end:i}=e;super({...e,points:[t,i]}),this._a=t,this._b=n,this._c=r,this._d=i,this._resolution=e.resolution??10}getVertices(){let e=[],{_a:t,_b:n,_c:r,_d:i}=this;for(let o=0,s=this._resolution;o<=s;o++){let a=o/s;e.push(new I.l((1-a)*(1-a)*(1-a)*t.x+(1-a)*(1-a)*3*a*n.x+3*(1-a)*(a*a)*r.x+a*a*a*i.x,(1-a)*(1-a)*(1-a)*t.y+(1-a)*(1-a)*3*a*n.y+3*(1-a)*(a*a)*r.y+a*a*a*i.y))}return e}nearestPoint(e){let t,n,r,i=1/0;for(let o of this.segments)r=o.nearestPoint(e),(n=I.l.Dist2(r,e))<i&&(t=r,i=n);if(!t)throw Error("nearest point not found");return t}distanceToPoint(e,t=!1){let{segments:n}=this,r=1/0;for(let t=0;t<n.length;t++){let i=n[t].distanceToPoint(e);i<r&&(r=i)}return r}getSvgPathData(e=!0){let{_a:t,_b:n,_c:r,_d:i}=this;return`${e?`M ${t.toFixed()} `:""} C${n.toFixed()} ${r.toFixed()} ${i.toFixed()}`}static GetAtT(e,t){let{_a:n,_b:r,_c:i,_d:o}=e;return new I.l((1-t)*(1-t)*(1-t)*n.x+(1-t)*(1-t)*3*t*r.x+3*(1-t)*(t*t)*i.x+t*t*t*o.x,(1-t)*(1-t)*(1-t)*n.y+(1-t)*(1-t)*3*t*r.y+3*(1-t)*(t*t)*i.y+t*t*t*o.y)}getLength(e,t=32){let n,r=this._a,i=0;for(let e=1;e<=t;e++)n=ns.GetAtT(this,e/t),i+=I.l.Dist(r,n),r=n;return i}}nn.vq;var na=n(55667);class nl extends nn.vq{constructor(e){super({...e,isClosed:!0}),this.config=e;const{width:t,height:n}=e;this._w=t,this._h=n}config;_w;_h;_edges;get edges(){if(!this._edges){let{vertices:e}=this;this._edges=[];for(let t=0,n=e.length;t<n;t++){let r=e[t],i=e[(t+1)%n];this._edges.push(new na.A({start:r,end:i}))}}return this._edges}getVertices(){let e=Math.max(1,this._w),t=Math.max(1,this._h),n=e/2,r=t/2,i=Math.pow(n-r,2)/Math.pow(n+r,2),o=nt(O.PI*(n+r)*(1+3*i/(10+Math.sqrt(4-3*i)))),s=O.uA/o,a=Math.cos(s),l=Math.sin(s),d=0,c=1,h=0,u=1,p=Array(o);for(let i=0;i<o;i++)p[i]=new I.l((0,O.qE)(n+n*c,0,e),(0,O.qE)(r+r*d,0,t)),h=l*c+a*d,u=a*c-l*d,d=h,c=u;return p}nearestPoint(e){let t,n,r,i=1/0;for(let o of this.edges)r=o.nearestPoint(e),(n=I.l.Dist2(r,e))<i&&(t=r,i=n);if(!t)throw Error("nearest point not found");return t}distanceToPoint(e,t=!1){let{edges:n}=this,r=1/0;for(let t=0;t<n.length;t++){let i=n[t].distanceToPoint(e);i<r&&(r=i)}return this.isClosed&&(this.isFilled||t)&&(0,O.s3)(e,this.vertices)?-r:r}hitTestLineSegment(e,t){return this.edges.some(n=>n.hitTestLineSegment(e,t))}getBounds(){return new t9.az(0,0,this._w,this._h)}getLength(){let{_w:e,_h:t}=this,n=Math.max(0,e/2),r=Math.max(0,t/2);return(0,O.VM)(n,r)}getSvgPathData(e=!1){let{_w:t,_h:n}=this,r=t/2,i=n/2,o=Math.max(0,r),s=Math.max(0,i);return`${e?`M${r-o},${i}`:""} a${o},${s},0,1,1,${2*o},0a${o},${s},0,1,1,-${2*o},0`}}nn.vq;var nd=n(31428);nn.vq;var nc=n(54939);let nh=`data:image/svg+xml;utf8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="3001" height="1000" fill="none"><path fill="#000" d="M590.656 300.449c0 49.706-40.294 90-90 90-49.705 0-90-40.294-90-90 0-49.705 40.295-90 90-90 49.706 0 90 40.295 90 90M569.431 719.011c-15.247 32.821-56.006 91.589-98.338 91.438-32.004-.115-38.642-30.904-17.414-50.856 17.381-16.337 28.246-48.075 31.995-72.719.415-2.728-1.556-5.197-4.272-5.679-39.666-7.04-70.746-40.877-70.746-83.417 0-48.23 38.983-87.329 87.07-87.329 39.936 0 70.172 22.237 83.369 52.397 18.839 43.055 7.117 115.733-11.664 156.165M2613.29 385.681V239.319c0-11.363 9.22-20.569 20.59-20.569h8.26c11.37 0 20.59 9.206 20.59 20.569v36.911c0 8.629 7 15.625 15.63 15.625h35.25c8.63 0 15.63-6.996 15.63-15.625v-36.911c0-11.363 9.22-20.569 20.59-20.569h8.17c11.37 0 20.59 9.206 20.59 20.569v146.362c0 11.363-9.22 20.569-20.59 20.569h-8.17c-11.37 0-20.59-9.206-20.59-20.569v-36.999c0-8.63-7-15.625-15.63-15.625h-35.25c-8.63 0-15.63 6.995-15.63 15.625v36.999c0 11.363-9.22 20.569-20.59 20.569h-8.26c-11.37 0-20.59-9.206-20.59-20.569M2391.97 239.319v146.362c0 11.348-9.16 20.569-20.49 20.569h-8.2c-11.33 0-20.49-9.221-20.49-20.569V239.319c0-11.348 9.16-20.569 20.49-20.569h8.2c11.33 0 20.49 9.221 20.49 20.569M2098.23 391.43l-42.69-146.361c-3.85-13.171 6.06-26.319 19.79-26.319h10.6c9.59 0 17.93 6.611 20.08 15.952l17.01 73.045c1.48 6.348 10.47 6.478 12.14.176l19.47-73.838c2.38-9.04 10.57-15.335 19.93-15.335h12.1c9.37 0 17.56 6.3 19.94 15.346l19.49 74.067c1.66 6.305 10.65 6.178 12.13-.171l17.09-73.294c2.15-9.339 10.49-15.948 20.08-15.948h10.53c13.72 0 23.63 13.141 19.79 26.31l-42.63 146.361c-2.56 8.789-10.63 14.829-19.79 14.829h-15.68c-9.12 0-17.16-5.98-19.76-14.709l-21.17-71.059c-1.77-5.948-10.19-5.957-11.97-.012l-21.33 71.071c-2.6 8.729-10.64 14.709-19.76 14.709h-15.59c-9.17 0-17.23-6.035-19.8-14.82M2443.23 218.75h118.59c11.38 0 20.62 9.195 20.62 20.557s-9.24 20.556-20.62 20.556h-24.79c-5.53 0-10 4.477-10 10v115.818c0 11.368-9.25 20.569-20.63 20.569h-7.65c-11.39 0-20.63-9.201-20.63-20.569V269.863c0-5.523-4.48-10-10-10h-24.89c-11.37 0-20.61-9.195-20.61-20.556s9.24-20.557 20.61-20.557M1174.15 218.75h24.64c8.35 0 15.88 5.042 19.04 12.764l34.61 83.942c2.13 5.161 9.44 5.155 11.56-.01l34.43-83.932a20.58 20.58 0 0 1 19.04-12.764h24.64c11.37 0 20.58 9.208 20.58 20.569v146.362c0 11.361-9.21 20.569-20.58 20.569h-7.09c-11.36 0-20.58-9.208-20.58-20.569l-.12-50.645c-.01-6.888-9.53-8.688-12.06-2.283l-23.46 59.332a20.57 20.57 0 0 1-19.14 13.009h-3.03a20.57 20.57 0 0 1-19.15-13.046l-23.47-59.68c-2.52-6.416-12.05-4.623-12.06 2.271l-.13 51.042c0 11.361-9.21 20.569-20.57 20.569h-7.1c-11.36 0-20.57-9.208-20.57-20.569V239.319c0-11.361 9.21-20.569 20.57-20.569"/><path fill="#000" fill-rule="evenodd" d="m1449.94 391.836 6.12-19.392a6.255 6.255 0 0 1 5.96-4.369l50.22-.061a6.24 6.24 0 0 1 5.96 4.348l6.23 19.486c2.71 8.581 10.71 14.402 19.74 14.402h9.34c14.13 0 24.15-13.791 19.61-27.151l-49.74-146.361c-2.85-8.37-10.74-13.988-19.61-13.988h-33.16c-8.87 0-16.77 5.618-19.61 13.988l-49.74 146.361c-4.54 13.36 5.48 27.151 19.61 27.151h9.32c9.04 0 17.04-5.827 19.75-14.414m31.1-98.858c1.85-5.807 10.08-5.796 11.91.016l8.83 27.916c1.28 4.028-1.73 8.134-5.96 8.134h-17.74c-4.23 0-7.24-4.119-5.95-8.151zM1681.81 406.25c18.91 0 35.39-3.686 49.36-11.168 13.97-7.544 24.73-18.394 32.24-32.489 7.56-14.105 11.29-30.866 11.29-50.182 0-19.256-3.73-35.957-11.29-50.004-7.57-14.094-18.35-24.912-32.32-32.397-13.91-7.545-30.4-11.26-49.37-11.26h-49.5c-11.38 0-20.63 9.201-20.63 20.569v146.362c0 11.368 9.25 20.569 20.63 20.569zm23.13-47.701c-6.62 3.215-14.85 4.886-24.79 4.886-10.49 0-19-8.507-19-19v-64.34c0-10.149 8.23-18.376 18.38-18.376 10.18 0 18.56 1.703 25.23 4.974 6.59 3.149 11.63 8.315 15.08 15.633 3.45 7.269 5.28 17.268 5.28 30.162 0 12.891-1.82 22.951-5.28 30.347-3.39 7.319-8.36 12.509-14.9 15.714" clip-rule="evenodd"/><path fill="#000" d="M1804.21 385.681V239.319c0-11.361 9.21-20.569 20.58-20.569h91.28c11.36 0 20.57 9.202 20.57 20.557s-9.21 20.556-20.57 20.556h-54.64a7.807 7.807 0 0 0-7.81 7.813v16.366a7.806 7.806 0 0 0 7.81 7.812h48.13c11.37 0 20.58 9.246 20.58 20.602s-9.21 20.601-20.58 20.601h-48.13a7.806 7.806 0 0 0-7.81 7.812v16.455a7.807 7.807 0 0 0 7.81 7.813h54.64c11.36 0 20.57 9.202 20.57 20.556s-9.21 20.557-20.57 20.557h-91.28c-11.37 0-20.58-9.208-20.58-20.569"/><path fill="#000" fill-rule="evenodd" d="M2875.5 68.75h-2750c-31.066 0-56.25 25.184-56.25 56.25v750c0 31.066 25.184 56.25 56.25 56.25h2750c31.07 0 56.25-25.184 56.25-56.25V125c0-31.066-25.18-56.25-56.25-56.25M125.5 0C56.464 0 .5 55.964.5 125v750c0 69.036 55.965 125 125 125h2750c69.04 0 125-55.964 125-125V125c0-69.036-55.96-125-125-125z" clip-rule="evenodd"/><path fill="#000" d="M2476.06 804.813c-10.54 0-19.82-6.947-22.81-17.068L2390.79 575.7c-4.49-15.248 6.92-30.534 22.8-30.534h27.75c11.1 0 20.72 7.686 23.18 18.52L2489 671.402c2.07 9.093 14.93 9.321 17.32.308l28.83-108.844c2.76-10.435 12.19-17.7 22.98-17.7h25.17c10.8 0 20.25 7.293 22.99 17.755l28.27 107.739c2.36 9.001 15.18 8.829 17.3-.232l25.01-106.888c2.51-10.763 12.1-18.374 23.14-18.374h27.87c15.88 0 27.29 15.286 22.8 30.534l-62.46 212.045a23.78 23.78 0 0 1-22.81 17.068h-32.12c-10.39 0-19.58-6.763-22.69-16.696l-32.08-102.694c-2.62-8.397-14.51-8.331-17.04.095l-30.74 102.346c-3.02 10.061-12.27 16.949-22.76 16.949zM1742.44 804.813h-75.81c-13.09 0-23.71-10.656-23.71-23.801V568.967c0-13.145 10.62-23.801 23.71-23.801h74.8c26.6 0 49.59 5.198 68.95 15.594 19.45 10.312 34.44 25.187 44.96 44.627 10.61 19.355 15.91 42.556 15.91 69.602q0 40.57-15.78 69.73c-10.53 19.355-25.43 34.231-44.71 44.627-19.28 10.311-42.05 15.467-68.32 15.467m-29.3-83.642c0 13.145 10.61 23.801 23.71 23.801h3.06c12.8 0 23.7-2.07 32.71-6.212 9.09-4.141 16-11.283 20.71-21.426q7.2-15.213 7.2-42.345 0-27.13-7.32-42.344c-4.8-10.143-11.87-17.285-21.22-21.426-9.26-4.142-20.63-6.212-34.1-6.212h-1.04c-13.1 0-23.71 10.656-23.71 23.801zM1460.86 804.813c-13.12 0-23.76-10.656-23.76-23.801V568.967c0-13.145 10.64-23.801 23.76-23.801h22.84c13.13 0 23.76 10.656 23.76 23.801v155.247c0 13.145 10.64 23.801 23.76 23.801h57.27c13.12 0 23.76 10.656 23.76 23.801v9.196c0 13.145-10.64 23.801-23.76 23.801zM1204.45 601.964c-13.13 0-23.77-10.656-23.77-23.801v-9.196c0-13.145 10.64-23.801 23.77-23.801h177.89c13.13 0 23.78 10.656 23.78 23.801v9.196c0 13.145-10.65 23.801-23.78 23.801h-39.38c-8.21 0-14.86 6.66-14.86 14.875v164.173c0 13.145-10.64 23.801-23.78 23.801h-21.85c-13.13 0-23.78-10.656-23.78-23.801V616.839c0-8.215-6.65-14.875-14.86-14.875z"/><path fill="#000" fill-rule="evenodd" d="M2223.05 787.891c-3.02 10.047-12.27 16.922-22.74 16.922h-25.43c-16.19 0-27.64-15.862-22.57-31.261l69.88-212.045c3.21-9.753 12.31-16.341 22.56-16.341h61.84c10.25 0 19.35 6.588 22.56 16.341l69.87 212.045c5.08 15.399-6.37 31.261-22.56 31.261h-25.43c-10.48 0-19.72-6.875-22.74-16.922l-6.7-22.2a14.84 14.84 0 0 0-14.21-10.576h-63.42c-6.55 0-12.32 4.296-14.22 10.576zm76.13-96.945-14.13-48.436c-2.46-8.451-14.36-8.602-17.04-.217l-15.46 48.436c-1.84 5.759 2.45 11.645 8.48 11.645h29.6c5.94 0 10.22-5.715 8.55-11.428" clip-rule="evenodd"/><path fill="#000" d="M1939.6 804.813c-13.13 0-23.77-10.656-23.77-23.801V568.967c0-13.145 10.64-23.801 23.77-23.801h88.13c19.24 0 36.08 3.508 50.51 10.523s25.65 17.115 33.67 30.3q12.03 19.779 12.03 47.416c0 18.595-4.14 34.273-12.41 47.036-7.64 11.913-18.18 21.101-31.63 27.564-16.98 8.159-36 11.104-54.7 11.104h-43.07c-76.56 0 4.08-135.84 4.08-84.706v7.996c0 12.117 9.81 21.941 21.91 21.941 8.12 0 16.3-.345 24.04-3.043 5.91-2.113 10.43-5.451 13.55-10.015 3.2-4.565 4.81-10.523 4.81-17.877 0-7.437-1.61-13.481-4.81-18.129-3.12-4.733-7.64-8.199-13.55-10.396-7.05-2.766-14.67-3.423-22.18-3.423-13.13 0-23.77 10.656-23.77 23.801v47.71c0 11.825 11.14 16.003 19.91 20.752 12.31 6.671 7.58 25.389-6.42 25.389-7.45 0-13.49 6.048-13.49 13.508v48.395c0 13.145-10.63 23.801-23.76 23.801zm134.89-106.758 5.41 9.95 33.51 61.622c8.62 15.86-2.84 35.186-20.87 35.186h-22.27c-8.74 0-16.77-4.798-20.92-12.496l-35.05-65.04a15.52 15.52 0 0 0-13.66-8.168c-42.24 0 40.62-82.154 73.85-21.054M931.652 0h68.748v1000h-68.748z"/></svg>')}`,nu=`data:image/svg+xml;utf8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="400" height="1601" fill="none"><path fill="#000" d="M72 1319.8c0-10.73 7.071-20.18 17.372-23.22l215.823-63.62c15.519-4.57 31.078 7.05 31.078 23.22v28.26c0 11.31-7.824 21.1-18.85 23.61l-109.636 24.94c-9.254 2.1-9.487 15.2-.313 17.63l110.784 29.37a24.21 24.21 0 0 1 18.015 23.4v25.64c0 11-7.423 20.62-18.071 23.41l-109.659 28.79c-9.162 2.41-8.986 15.47.236 17.63l108.792 25.46c10.955 2.56 18.702 12.33 18.702 23.57v28.39c0 16.17-15.559 27.79-31.078 23.22l-215.823-63.62c-10.3-3.04-17.372-12.49-17.372-23.22v-32.72c0-10.59 6.883-19.95 16.994-23.11l104.523-32.67c8.547-2.67 8.479-14.79-.096-17.36l-104.17-31.3C79.01 1372.42 72 1363 72 1352.31zM72 572.638V495.43c0-13.336 10.846-24.147 24.225-24.147h215.823c13.379 0 24.225 10.811 24.225 24.147v76.179q0 40.645-15.872 70.228-15.743 29.712-45.422 45.79-29.55 16.206-70.843 16.206-41.292 0-70.971-16.078-29.55-16.077-45.422-45.532Q72 612.767 72 572.638m85.132-29.84c-13.379 0-24.225 10.81-24.225 24.146v3.122q0 19.55 6.323 33.313 6.323 13.89 21.807 21.094 15.485 7.332 43.099 7.331t43.1-7.46q15.484-7.33 21.807-21.608 6.323-14.15 6.323-34.728v-1.064c0-13.336-10.846-24.146-24.225-24.146zM72 285.858c0-13.363 10.846-24.197 24.225-24.197h215.823c13.379 0 24.225 10.834 24.225 24.197v23.27c0 13.364-10.846 24.197-24.225 24.197H154.035c-13.379 0-24.225 10.834-24.225 24.197v58.328c0 13.364-10.846 24.197-24.225 24.197h-9.36C82.845 440.047 72 429.214 72 415.85zM278.463 24.72c0-13.374 10.846-24.216 24.225-24.216h9.36c13.379 0 24.225 10.842 24.225 24.216v181.174c0 13.374-10.846 24.216-24.225 24.216h-9.36c-13.379 0-24.225-10.842-24.225-24.216v-40.108c0-8.359-6.779-15.135-15.141-15.135H96.225c-13.38 0-24.225-10.842-24.225-24.216v-22.256c0-13.374 10.846-24.216 24.225-24.216h167.097c8.362 0 15.141-6.776 15.141-15.135z"/><path fill="#000" fill-rule="evenodd" d="M89.224 1062.13C78.997 1059.04 72 1049.63 72 1038.96v-25.9c0-16.486 16.145-28.147 31.818-22.979l215.823 71.169a24.19 24.19 0 0 1 16.632 22.98v62.97c0 10.45-6.706 19.71-16.632 22.98l-215.823 71.17C88.145 1246.51 72 1234.86 72 1218.37v-25.9c0-10.67 6.997-20.08 17.224-23.17l22.595-6.81a15.13 15.13 0 0 0 10.765-14.48v-64.59a15.13 15.13 0 0 0-10.765-14.48zm98.672 77.53 49.299-14.39c8.601-2.51 8.755-14.62.22-17.35l-49.299-15.75c-5.861-1.88-11.852 2.49-11.852 8.64v30.14c0 6.05 5.817 10.41 11.632 8.71" clip-rule="evenodd"/><path fill="#000" d="M72 773.439c0-13.367 10.846-24.203 24.225-24.203h215.823c13.379 0 24.225 10.836 24.225 24.203v89.762q0 29.395-10.711 51.439-10.71 22.046-30.84 34.293t-48.261 12.248q-28.388 0-47.873-12.635-18.187-11.672-28.056-32.218c-8.303-17.289-11.301-36.661-11.301-55.705v-43.867c0-77.976 138.26 4.16 86.215 4.16h-8.138c-12.334 0-22.332 9.989-22.332 22.311 0 8.269.351 16.6 3.097 24.487q3.225 9.024 10.194 13.794 6.968 4.899 18.194 4.899 11.356 0 18.453-4.899 7.226-4.77 10.581-13.794c2.815-7.188 3.484-14.944 3.484-22.596 0-13.366-10.846-24.202-24.225-24.202h-48.56c-12.036 0-16.288 11.345-21.122 20.272-6.79 12.539-25.841 7.72-25.841-6.536 0-7.586-6.156-13.736-13.749-13.736H96.225C82.845 820.916 72 810.08 72 796.714zm108.66 137.378-10.128 5.511-62.72 34.131C91.67 959.243 72 947.569 72 929.205V906.52a24.2 24.2 0 0 1 12.719-21.299l66.199-35.696a15.82 15.82 0 0 0 8.313-13.921c0-43.012 83.618 41.371 21.429 75.213"/></svg>')}`,np=(0,m.memo)(function(){let e=t1(),t=(0,k.hG)(),n=(0,d.h)("is mobile",()=>t.getViewportScreenBounds().width<700,[t]),r=(0,d.h)("watermarkState",()=>e.state.get(),[e]);return["licensed-with-watermark","unlicensed"].includes(r)?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(nm,{}),(0,p.jsx)(ng,{src:n?nu:nh,isUnlicensed:"unlicensed"===r})]}):null}),nf=(0,m.memo)(function({isDebugMode:e,isMobile:t}){let n=(0,k.hG)(),r=P(),i=(0,m.useRef)(null);return tL(i),(0,p.jsx)("div",{ref:i,className:tZ.className,"data-debug":e,"data-mobile":t,"data-unlicensed":!0,"data-testid":"tl-watermark-unlicensed",draggable:!1,...r,children:(0,p.jsx)("button",{draggable:!1,role:"button",onPointerDown:e=>{n.markEventAsHandled(e),(0,x.wo)(e)},title:"The tldraw SDK requires a license key to work in production. You can get a free 100-day trial license at tldraw.dev/pricing.",onClick:()=>{eP.openWindow("https://tldraw.dev/pricing?utm_source=sdk&utm_medium=organic&utm_campaign=watermark","_blank",!0)},children:"Get a license for production"})})}),ng=(0,m.memo)(function({src:e,isUnlicensed:t}){let n=(0,k.hG)(),r=(0,d.h)("debug mode",()=>n.getInstanceState().isDebugMode,[n]),i=(0,d.h)("is mobile",()=>n.getViewportScreenBounds().width<700,[n]),o=P(),s=(0,m.useRef)(null);tL(s);let a=`url('${e}') center 100% / 100% no-repeat`;return t?(0,p.jsx)(nf,{isDebugMode:r,isMobile:i}):(0,p.jsx)("div",{ref:s,className:tZ.className,"data-debug":r,"data-mobile":i,"data-testid":"tl-watermark-licensed",draggable:!1,...o,children:(0,p.jsx)("button",{draggable:!1,role:"button",onPointerDown:e=>{n.markEventAsHandled(e),(0,x.wo)(e)},title:"Build infinite canvas applications with the tldraw SDK. Learn more at https://tldraw.dev.",onClick:()=>{eP.openWindow("https://tldraw.dev/?utm_source=sdk&utm_medium=organic&utm_campaign=watermark","_blank")},style:{mask:a,WebkitMask:a}})})}),nm=(0,m.memo)(function(){let e=(0,k.hG)(),t=tZ.className,n=`
142
- /* ------------------- SEE LICENSE -------------------
143
- The tldraw watermark is part of tldraw's license. It is shown for unlicensed
144
- or "licensed-with-watermark" users. By using this library, you agree to
145
- preserve the watermark's behavior, keeping it visible, unobscured, and
146
- available to user-interaction.
147
-
148
- To remove the watermark, please purchase a license at tldraw.dev.
149
- */
150
-
151
- .${t} {
152
- position: absolute;
153
- bottom: max(var(--tl-space-2), env(safe-area-inset-bottom));
154
- right: max(var(--tl-space-2), env(safe-area-inset-right));
155
- width: 96px;
156
- height: 32px;
157
- display: flex;
158
- align-items: center;
159
- justify-content: center;
160
- z-index: var(--tl-layer-watermark) !important;
161
- background-color: color-mix(in srgb, var(--tl-color-background) 62%, transparent);
162
- opacity: 1;
163
- border-radius: 5px;
164
- pointer-events: all;
165
- padding: 2px;
166
- box-sizing: content-box;
167
- }
168
-
169
- .${t} > button {
170
- position: absolute;
171
- width: 96px;
172
- height: 32px;
173
- pointer-events: all;
174
- cursor: inherit;
175
- color: var(--tl-color-text);
176
- opacity: .38;
177
- border: 0;
178
- padding: 0;
179
- background-color: currentColor;
180
- }
181
-
182
- .${t}[data-debug='true'] {
183
- bottom: max(46px, env(safe-area-inset-bottom));
184
- }
185
-
186
- .${t}[data-mobile='true'] {
187
- border-radius: 4px 0px 0px 4px;
188
- right: max(-2px, calc(env(safe-area-inset-right) - 2px));
189
- width: 8px;
190
- height: 48px;
191
- }
192
-
193
- .${t}[data-mobile='true'] > button {
194
- width: 8px;
195
- height: 32px;
196
- }
197
-
198
- .tl-container[dir='rtl'] .${t} {
199
- right: auto;
200
- left: max(var(--tl-space-2), env(safe-area-inset-left));
201
- }
202
-
203
- .tl-container[dir='rtl'] .${t}[data-mobile='true'] {
204
- border-radius: 0px 4px 4px 0px;
205
- left: max(-2px, calc(env(safe-area-inset-left) - 2px));
206
- }
207
-
208
- .${t}[data-unlicensed='true'] > button {
209
- font-size: 100px;
210
- position: absolute;
211
- pointer-events: all;
212
- cursor: pointer;
213
- color: var(--tl-color-text);
214
- opacity: 0.8;
215
- border: 0;
216
- padding: 0;
217
- background-color: transparent;
218
- font-size: 11px;
219
- font-weight: 600;
220
- text-align: center;
221
- }
222
-
223
- .${t}[data-mobile='true'][data-unlicensed='true'] > button {
224
- display: none;
225
- }
226
-
227
- @media (hover: hover) {
228
- .${t} > button {
229
- pointer-events: none;
230
- }
231
-
232
- .${t}:hover {
233
- background-color: var(--tl-color-background);
234
- transition: background-color 0.2s ease-in-out;
235
- transition-delay: 0.32s;
236
- }
237
-
238
- .${t}:hover > button {
239
- animation: ${t}_delayed_link 0.2s forwards ease-in-out;
240
- animation-delay: 0.32s;
241
- }
242
-
243
- .${t} > button:focus-visible {
244
- opacity: 1;
245
- }
246
- }
247
-
248
- @keyframes ${t}_delayed_link {
249
- 0% {
250
- cursor: inherit;
251
- opacity: .38;
252
- pointer-events: none;
253
- }
254
- 100% {
255
- cursor: pointer;
256
- opacity: 1;
257
- pointer-events: all;
258
- }
259
- }`;return(0,p.jsx)("style",{nonce:e.options.nonce,children:n})}),ny=[],nb=[],nx=[],nw=[],nv=(0,m.memo)(function({store:e,components:t,className:n,user:r,options:i,textOptions:o,deepLinks:s,...l}){let d=(0,eN.P)(l.themes);(0,h.Mc)(d),(0,h.AF)(d);let[u,f]=(0,m.useState)(null),[y,b]=(0,m.useState)(null),x=(0,m.useMemo)(()=>r??(0,eF.b)(),[r]),w=t?.ErrorFallback===void 0?e_:t?.ErrorFallback,v=(0,m.useMemo)(()=>{let e=i;return o&&(e={...e,text:e?.text??o}),void 0!==s&&(e={...e,deepLinks:e?.deepLinks??s}),e},[i,o,s]),S={...l,shapeUtils:l.shapeUtils??ny,bindingUtils:l.bindingUtils??nb,assetUtils:l.assetUtils??nx,tools:l.tools??nw,components:t,options:(0,tC.d)(v)};return(0,p.jsxs)("div",{ref:f,"data-tldraw":tB.r,draggable:!1,className:g("tl-container tl-theme__light",n),tabIndex:-1,role:"application","aria-label":i?.branding??"tldraw",children:[(0,p.jsx)(eI.p,{fallback:w,onError:e=>(0,a.TF)(e,{tags:{origin:"react.tldraw-before-app"}}),children:u&&(0,p.jsx)(t5,{licenseKey:l.licenseKey,children:(0,p.jsx)(T.ts,{container:u,children:(0,p.jsx)(eD,{host:y,children:(0,p.jsx)(tk,{overrides:t,children:e?e instanceof c.il?(0,p.jsx)(nP,{...S,store:e,user:x}):(0,p.jsx)(nC,{...S,store:e,user:x}):(0,p.jsx)(nS,{...S,store:e,user:x})})})})})}),(0,p.jsx)("div",{className:"tl-portal-host",ref:b})]})});function nS(e){let{defaultName:t,snapshot:n,initialData:r,shapeUtils:i,bindingUtils:o,assetUtils:s,persistenceKey:l,sessionId:d,user:c,assets:h,users:u,migrations:f,themes:g}=e,y=function(e){let[t,n]=tj({status:"loading"});return e=(0,tC.d)(e),(0,m.useEffect)(()=>{let{persistenceKey:t,sessionId:r,...i}=e;if(!t)return void n({status:"not-synced",store:eq(i)});n({status:"loading"});let o=new a.l,s={upload:async(e,t)=>(await c.db.storeAsset(e.id,t),{src:e.id}),resolve:async e=>e.props.src?e.props.src.startsWith("asset:")?await o.get(e,async()=>{let t=await c.db.getAsset(e.id);return t?URL.createObjectURL(t):null}):e.props.src:null,remove:async e=>{await c.db.removeAssets(e)},...i.assets},l=eq({...i,assets:s}),d=!1,c=new tA(l,{sessionId:r,persistenceKey:t,onLoad(){d||n({store:l,status:"synced-local"})},onLoadError(e){d||n({status:"error",error:e})}});return()=>{d=!0,c.close()}},[e,n]),t}({shapeUtils:i,bindingUtils:o,assetUtils:s,initialData:r,persistenceKey:l,sessionId:d,defaultName:t,snapshot:n,assets:h,users:u,migrations:f,themes:g});return(0,p.jsx)(nC,{...e,store:y,user:c})}let nC=(0,m.memo)(function({store:e,user:t,...n}){let r=(0,T.NF)();(0,m.useLayoutEffect)(()=>{"dark"===t.userPreferences.get().colorScheme&&(r.classList.remove("tl-theme__light"),r.classList.add("tl-theme__dark"))},[r,t]);let{LoadingScreen:i}=(0,b.B)();switch(e.status){case"error":throw e.error;case"loading":return i?(0,p.jsx)(i,{}):null}return(0,p.jsx)(nP,{...n,store:e.store,user:t})}),nk=()=>(0,x.jL)().location.search.includes("tldraw_preserve_focus");function nP({onMount:e,children:t,store:n,tools:r,shapeUtils:i,bindingUtils:o,assetUtils:s,overlayUtils:a,user:l,initialState:d,autoFocus:c=!0,cameraOptions:h,options:u,licenseKey:f,getShapeVisibility:g,colorScheme:y,assetUrls:x,themes:w,initialTheme:v}){let{ErrorFallback:S}=(0,b.B)(),C=(0,T.NF)(),P=t1(),[E,I]=tj(null),_=(0,m.useRef)(null),M=u?.deepLinks,A=(0,tC.d)(!0===M?{}:M),j=(0,m.useRef)({autoFocus:c&&!nk(),initialState:d,colorScheme:y,cameraOptions:h,deepLinks:A,themes:w,initialTheme:v});(0,m.useLayoutEffect)(()=>{j.current={autoFocus:c&&!nk(),initialState:d,colorScheme:y,cameraOptions:h,deepLinks:A,themes:w,initialTheme:v}},[c,d,y,h,A,w,v]),(0,m.useLayoutEffect)(()=>{let{autoFocus:e,initialState:t,colorScheme:d,cameraOptions:c,deepLinks:h,themes:p,initialTheme:m}=j.current,y=new ez.K({store:n,shapeUtils:i,bindingUtils:o,assetUtils:s,overlayUtils:a,tools:r,getContainer:()=>C,user:l,initialState:t,autoFocus:e,cameraOptions:c,options:u,licenseKey:f,getShapeVisibility:g,colorScheme:d,fontAssetUrls:x?.fonts,themes:p,initialTheme:m});return y.licenseManager=P,y.updateViewportScreenBounds(_.current??C),h&&(h?.getUrl?y.navigateToDeepLink({...h,url:h.getUrl(y)}):y.navigateToDeepLink(h)),I(y),()=>{y.dispose()}},[s,o,y,C,u,a,i,n,r,l,I,f,P,g,x]),(0,m.useLayoutEffect)(()=>{if(E&&A)return E.registerDeepLinkListener(A)},[E,A]),(0,m.useLayoutEffect)(()=>{E&&(h||u?.camera)&&E.setCameraOptions({...h,...u?.camera})},[E,h,u?.camera]),(0,m.useLayoutEffect)(()=>{if(E&&w)for(let e of Object.values(w))E.updateTheme(e)},[E,w]),(0,m.useLayoutEffect)(()=>{E&&v&&E.setCurrentTheme(v)},[E,v]);let O=(0,m.useSyncExternalStore)((0,m.useCallback)(e=>E?(E.on("crash",e),()=>E.off("crash",e)):()=>{},[E]),()=>E?.getCrashingError()??null);(0,m.useEffect)(function(){if(E&&c&&nk()){let n=E.getContainer();return n.addEventListener("pointerdown",e),n.ownerDocument.body.addEventListener("pointerdown",t),()=>{n.removeEventListener("pointerdown",e),n.ownerDocument.body.removeEventListener("pointerdown",t)}}function e(){E&&E.focus()}function t(){E&&E.blur()}},[E,c]);let[D,L]=(0,m.useState)(null),R=D;E!==R?.editor&&(R=null),(0,m.useLayoutEffect)(()=>{if(!E)return;if(0===E.options.maxFontsToLoadBeforeRender)return void L({editor:E,isLoaded:!0});let e=!1;return L({editor:E,isLoaded:!1}),E.fonts.loadRequiredFontsForCurrentPage(E.options.maxFontsToLoadBeforeRender).finally(()=>{e||L({editor:E,isLoaded:!0})}),()=>{e=!0}},[E]);let{Canvas:F,LoadingScreen:z}=(0,b.B)();return E&&R?.isLoaded?(0,p.jsx)(eI.p,{fallback:S,onError:e=>E.annotateError(e,{origin:"react.tldraw",willCrashApp:!0}),children:O?(0,p.jsx)(nE,{crashingError:O}):(0,p.jsx)(k.zz,{editor:E,children:(0,p.jsxs)(nT,{onMount:e,children:[t??(F?(0,p.jsx)(F,{},E.contextId):null),(0,p.jsx)(np,{})]})})}):(0,p.jsxs)(p.Fragment,{children:[z&&(0,p.jsx)(z,{}),(0,p.jsx)("div",{className:"tl-canvas",ref:_})]})}function nT({children:e,onMount:t}){let n,r,i,o,s,c,h,u,p;return n=(0,k.hG)(),r=(0,T.NF)(),m.useEffect(()=>{let e=e=>r.style.setProperty("--tl-zoom",e.toString()),t=(0,a.sg)(e,100),i=new l.VM("useZoomCss",()=>e(n.getEfficientZoomLevel()));return i.attach(),i.execute(),()=>{i.detach(),t.cancel()}},[n,r]),i=(0,k.hG)(),o=(0,T.NF)(),(0,d.lX)("useCursor",()=>{let{type:e,rotation:t}=i.getInstanceState().cursor;if(tb.includes(e))return void o.style.setProperty("--tl-cursor",`var(--tl-cursor-${e})`);let{cursor:n}=i.getCurrentTheme().colors[i.getColorMode()];o.style.setProperty("--tl-cursor",function(e,t=0,n="black"){return tx[e]((0,O.nv)(t),!1,n)}(e,t,n))},[i,o]),s=(0,k.hG)(),c=(0,T.NF)(),h=tp(),u=(0,d.h)(j.bG.forceSrgb),m.useEffect(()=>{"dark"===h?(c.setAttribute("data-color-mode","dark"),c.classList.remove("tl-theme__light"),c.classList.add("tl-theme__dark")):(c.setAttribute("data-color-mode","light"),c.classList.remove("tl-theme__dark"),c.classList.add("tl-theme__light")),u?c.classList.add("tl-theme__force-sRGB"):c.classList.remove("tl-theme__force-sRGB")},[s,c,u,h]),function(){let[e,t]=(0,m.useState)(0);(0,m.useEffect)(()=>t(e=>e+1),[])}(),p=(0,k.hG)(),(0,m.useLayoutEffect)(()=>(0,l.wv)("stateAttribute",()=>{let e=p.getContainer(),t=p.getInstanceState();e.setAttribute("data-state",p.getPath()),e.setAttribute("data-coarse",String(t.isCoarsePointer))}),[p]),n_(e=>{let n=e.store.props.onMount(e),r=t?.(e);return()=>{n?.(),r?.()}}),e}function nE({crashingError:e}){throw e}function nI({children:e}){return(0,p.jsx)("div",{className:"tl-loading","aria-busy":"true",tabIndex:0,children:e})}function n_(e){let t=(0,k.hG)(),n=(0,tP._)(t=>{let n;return t.run(()=>{n=e?.(t),t.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,()=>{n?.(),t.getIsMounted()&&!t.isDisposed&&t.run(()=>t.emit("unmount"),{history:"ignore"})}});m.useLayoutEffect(()=>{if(t)return n?.(t)},[t,n])}n(65009),n(4343);class nM{constructor(e,t){this.name=e,this.getInitialState=t}name;getInitialState;states=new a.l;getAtom(e){return this.states.get(e,()=>(0,l.eU)(this.name,this.getInitialState(e)))}get(e){return this.getAtom(e).get()}update(e,t){return this.getAtom(e).update(t)}set(e,t){return this.getAtom(e).set(t)}}function nA(e,t=!0){let n=e.length;if(n<2)return"";let r=e[0],i=e[1];if(2===n)return`M${(0,O.ul)(r)}L${(0,O.ul)(i)}`;let o="";for(let t=2,s=n-1;t<s;t++)r=e[t],i=e[t+1],o+=(0,O.G8)(r,i);return t?`M${(0,O.G8)(e[0],e[1])}Q${(0,O.ul)(e[1])}${(0,O.G8)(e[1],e[2])}T${o}${(0,O.G8)(e[n-1],e[0])}${(0,O.G8)(e[0],e[1])}Z`:`M${(0,O.ul)(e[0])}Q${(0,O.ul)(e[1])}${(0,O.G8)(e[1],e[2])}${e.length>3?"T":""}${o}L${(0,O.ul)(e[n-1])}`}var nj=n(4599),nO=n(82159),nD=n(27050);let nL=new a.l;function nR(e,t,n){let{tipTapConfig:r,addFontsFromNode:i}=e.getTextOptions();(0,a.vA)(r,"textOptions.tipTapConfig must be set to use rich text"),(0,a.vA)(i,"textOptions.addFontsFromNode must be set to use rich text");let o=nL.get(r,()=>(0,nO._w)(r.extensions??[])),s=nD.bP.fromJSON(o,t),l=new Set;function d(e){l.add(e)}return!function e(t,n){for(let r of(n=i(t,n,d),t.children))e(r,n)}(s,n),Array.from(l)}var nF=n(20026),nz=n(92599);(0,a.lF)("@tldraw/editor","5.3.2","esm")},94119:(e,t,n)=>{"use strict";n.d(t,{Fj:()=>P,H_:()=>D,JW:()=>v,Pd:()=>T,UC:()=>j,ZL:()=>A,bL:()=>_,es:()=>E,l9:()=>M,q7:()=>O});var r=n(12115),i=n(3510),o=n(70379),s=n(68599),a=n(55897),l=n(69445),d=n(54498),c=n(95155),h=Object.defineProperty,u=(e,t)=>h(e,"name",{value:t,configurable:!0}),p="ContextMenu",[f,g]=(0,s.A)(p,[l.UE]),m=(0,l.UE)(),[y,b]=f(p),x=u(e=>{let{__scopeContextMenu:t,children:n,onOpenChange:o,open:s,dir:a,modal:h=!0}=e,u=r.useRef(!1);if(i.D){let e=r.useRef(!1);r.useEffect(()=>{!0!==s||u.current||e.current||(e.current=!0,console.warn("ContextMenu: The `open` prop has been set to `true` before the user has interacted with the trigger, so its position is indeterminate. This is likely unintended and will result in the menu being anchored to the top-left corner of the viewport."))},[s])}let[f,g]=(0,d.i)({prop:s,defaultProp:!1,onChange:o,caller:p}),b=m(t);return(0,c.jsx)(y,{scope:t,open:f,onOpenChange:g,modal:h,hasInteractedRef:u,children:(0,c.jsx)(l.bL,{...b,dir:a,open:f,onOpenChange:g,modal:h,children:n})})},"ContextMenu"),w=r.forwardRef(u(function(e,t){let{__scopeContextMenu:n,disabled:i=!1,...s}=e,d=b("ContextMenuTrigger",n),h=m(n),[p,f]=r.useState({x:0,y:0}),g=r.useMemo(()=>({current:{getBoundingClientRect:u(()=>DOMRect.fromRect({width:0,height:0,...p}),"getBoundingClientRect")}}),[p]),y=r.useRef(0),x=r.useCallback(()=>window.clearTimeout(y.current),[]),w=u(e=>{d.hasInteractedRef.current=!0,f({x:e.clientX,y:e.clientY}),d.onOpenChange(!0)},"handleOpen");return r.useEffect(()=>x,[x]),r.useEffect(()=>void(i&&x()),[i,x]),(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(l.Mz,{...h,virtualRef:g}),(0,c.jsx)(a.sG.span,{"data-state":d.open?"open":"closed","data-disabled":i?"":void 0,...s,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:i?e.onContextMenu:(0,o.mK)(e.onContextMenu,e=>{x(),w(e),e.preventDefault()}),onPointerDown:i?e.onPointerDown:(0,o.mK)(e.onPointerDown,I(e=>{x(),d.open&&d.onOpenChange(!1),y.current=window.setTimeout(()=>w(e),700)})),onPointerMove:i?e.onPointerMove:(0,o.mK)(e.onPointerMove,I(x)),onPointerCancel:i?e.onPointerCancel:(0,o.mK)(e.onPointerCancel,I(x)),onPointerUp:i?e.onPointerUp:(0,o.mK)(e.onPointerUp,I(x))})]})},"ContextMenuTrigger")),v=u(e=>{let{__scopeContextMenu:t,...n}=e,r=m(t);return(0,c.jsx)(l.ZL,{...r,...n})},"ContextMenuPortal"),S=r.forwardRef(u(function(e,t){let{__scopeContextMenu:n,...i}=e,o=b("ContextMenuContent",n),s=m(n),a=r.useRef(!1);return(0,c.jsx)(l.UC,{...s,...i,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),!t.defaultPrevented&&a.current&&t.preventDefault(),a.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||o.modal||(a.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"ContextMenuContent")),C=r.forwardRef(u(function(e,t){let{__scopeContextMenu:n,...r}=e,i=m(n);return(0,c.jsx)(l.q7,{...i,...r,ref:t})},"ContextMenuItem")),k=r.forwardRef(u(function(e,t){let{__scopeContextMenu:n,...r}=e,i=m(n);return(0,c.jsx)(l.H_,{...i,...r,ref:t})},"ContextMenuCheckboxItem")),P=u(e=>{let{__scopeContextMenu:t,children:n,onOpenChange:r,open:i,defaultOpen:o}=e,s=m(t),[a,h]=(0,d.i)({prop:i,defaultProp:o??!1,onChange:r,caller:"ContextMenuSub"});return(0,c.jsx)(l.Pb,{...s,open:a,onOpenChange:h,children:n})},"ContextMenuSub"),T=r.forwardRef(u(function(e,t){let{__scopeContextMenu:n,...r}=e,i=m(n);return(0,c.jsx)(l.ZP,{...i,...r,ref:t})},"ContextMenuSubTrigger")),E=r.forwardRef(u(function(e,t){let{__scopeContextMenu:n,...r}=e,i=m(n);return(0,c.jsx)(l.G5,{...i,...r,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"ContextMenuSubContent"));function I(e){return t=>"mouse"!==t.pointerType?e(t):void 0}u(I,"whenTouchOrPen");var _=x,M=w,A=v,j=S,O=C,D=k},94449:(e,t,n)=>{e=n.nmd(e);var r,i,o,s="__lodash_hash_undefined__",a="[object Arguments]",l="[object Array]",d="[object Boolean]",c="[object Date]",h="[object Error]",u="[object Function]",p="[object Map]",f="[object Number]",g="[object Object]",m="[object Promise]",y="[object RegExp]",b="[object Set]",x="[object String]",w="[object WeakMap]",v="[object ArrayBuffer]",S="[object DataView]",C=/^\[object .+?Constructor\]$/,k=/^(?:0|[1-9]\d*)$/,P={};P["[object Float32Array]"]=P["[object Float64Array]"]=P["[object Int8Array]"]=P["[object Int16Array]"]=P["[object Int32Array]"]=P["[object Uint8Array]"]=P["[object Uint8ClampedArray]"]=P["[object Uint16Array]"]=P["[object Uint32Array]"]=!0,P[a]=P[l]=P[v]=P[d]=P[S]=P[c]=P[h]=P[u]=P[p]=P[f]=P[g]=P[y]=P[b]=P[x]=P[w]=!1;var T="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,E="object"==typeof self&&self&&self.Object===Object&&self,I=T||E||Function("return this")(),_=t&&!t.nodeType&&t,M=_&&e&&!e.nodeType&&e,A=M&&M.exports===_,j=A&&T.process,O=function(){try{return j&&j.binding&&j.binding("util")}catch(e){}}(),D=O&&O.isTypedArray;function L(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function R(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var F=Array.prototype,z=Function.prototype,N=Object.prototype,$=I["__core-js_shared__"],B=z.toString,H=N.hasOwnProperty,U=(r=/[^.]+$/.exec($&&$.keys&&$.keys.IE_PROTO||""))?"Symbol(src)_1."+r:"",K=N.toString,W=RegExp("^"+B.call(H).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),V=A?I.Buffer:void 0,Y=I.Symbol,G=I.Uint8Array,q=N.propertyIsEnumerable,X=F.splice,J=Y?Y.toStringTag:void 0,Z=Object.getOwnPropertySymbols,Q=V?V.isBuffer:void 0,ee=(i=Object.keys,o=Object,function(e){return i(o(e))}),et=eP(I,"DataView"),en=eP(I,"Map"),er=eP(I,"Promise"),ei=eP(I,"Set"),eo=eP(I,"WeakMap"),es=eP(Object,"create"),ea=eI(et),el=eI(en),ed=eI(er),ec=eI(ei),eh=eI(eo),eu=Y?Y.prototype:void 0,ep=eu?eu.valueOf:void 0;function ef(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function eg(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function em(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function ey(e){var t=-1,n=null==e?0:e.length;for(this.__data__=new em;++t<n;)this.add(e[t])}function eb(e){var t=this.__data__=new eg(e);this.size=t.size}function ex(e,t){for(var n=e.length;n--;)if(e_(e[n][0],t))return n;return -1}function ew(e){var t;return null==e?void 0===e?"[object Undefined]":"[object Null]":J&&J in Object(e)?function(e){var t=H.call(e,J),n=e[J];try{e[J]=void 0;var r=!0}catch(e){}var i=K.call(e);return r&&(t?e[J]=n:delete e[J]),i}(e):(t=e,K.call(t))}function ev(e){return eR(e)&&ew(e)==a}function eS(e,t,n,r,i,o){var s=1&n,a=e.length,l=t.length;if(a!=l&&!(s&&l>a))return!1;var d=o.get(e);if(d&&o.get(t))return d==t;var c=-1,h=!0,u=2&n?new ey:void 0;for(o.set(e,t),o.set(t,e);++c<a;){var p=e[c],f=t[c];if(r)var g=s?r(f,p,c,t,e,o):r(p,f,c,e,t,o);if(void 0!==g){if(g)continue;h=!1;break}if(u){if(!function(e,t){for(var n=-1,r=null==e?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}(t,function(e,t){if(!u.has(t)&&(p===e||i(p,e,n,r,o)))return u.push(t)})){h=!1;break}}else if(!(p===f||i(p,f,n,r,o))){h=!1;break}}return o.delete(e),o.delete(t),h}function eC(e){var t;return t=ez(e),eA(e)?t:function(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}(t,eT(e))}function ek(e,t){var n,r,i=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?i["string"==typeof t?"string":"hash"]:i.map}function eP(e,t){var n,r=null==e?void 0:e[t];return!(!eL(r)||(n=r,U&&U in n))&&(eO(r)?W:C).test(eI(r))?r:void 0}ef.prototype.clear=function(){this.__data__=es?es(null):{},this.size=0},ef.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=!!t,t},ef.prototype.get=function(e){var t=this.__data__;if(es){var n=t[e];return n===s?void 0:n}return H.call(t,e)?t[e]:void 0},ef.prototype.has=function(e){var t=this.__data__;return es?void 0!==t[e]:H.call(t,e)},ef.prototype.set=function(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=es&&void 0===t?s:t,this},eg.prototype.clear=function(){this.__data__=[],this.size=0},eg.prototype.delete=function(e){var t=this.__data__,n=ex(t,e);return!(n<0)&&(n==t.length-1?t.pop():X.call(t,n,1),--this.size,!0)},eg.prototype.get=function(e){var t=this.__data__,n=ex(t,e);return n<0?void 0:t[n][1]},eg.prototype.has=function(e){return ex(this.__data__,e)>-1},eg.prototype.set=function(e,t){var n=this.__data__,r=ex(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this},em.prototype.clear=function(){this.size=0,this.__data__={hash:new ef,map:new(en||eg),string:new ef}},em.prototype.delete=function(e){var t=ek(this,e).delete(e);return this.size-=!!t,t},em.prototype.get=function(e){return ek(this,e).get(e)},em.prototype.has=function(e){return ek(this,e).has(e)},em.prototype.set=function(e,t){var n=ek(this,e),r=n.size;return n.set(e,t),this.size+=+(n.size!=r),this},ey.prototype.add=ey.prototype.push=function(e){return this.__data__.set(e,s),this},ey.prototype.has=function(e){return this.__data__.has(e)},eb.prototype.clear=function(){this.__data__=new eg,this.size=0},eb.prototype.delete=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},eb.prototype.get=function(e){return this.__data__.get(e)},eb.prototype.has=function(e){return this.__data__.has(e)},eb.prototype.set=function(e,t){var n=this.__data__;if(n instanceof eg){var r=n.__data__;if(!en||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new em(r)}return n.set(e,t),this.size=n.size,this};var eT=Z?function(e){return null==e?[]:function(e,t){for(var n=-1,r=null==e?0:e.length,i=0,o=[];++n<r;){var s=e[n];t(s,n,e)&&(o[i++]=s)}return o}(Z(e=Object(e)),function(t){return q.call(e,t)})}:function(){return[]},eE=ew;function eI(e){if(null!=e){try{return B.call(e)}catch(e){}try{return e+""}catch(e){}}return""}function e_(e,t){return e===t||e!=e&&t!=t}(et&&eE(new et(new ArrayBuffer(1)))!=S||en&&eE(new en)!=p||er&&eE(er.resolve())!=m||ei&&eE(new ei)!=b||eo&&eE(new eo)!=w)&&(eE=function(e){var t=ew(e),n=t==g?e.constructor:void 0,r=n?eI(n):"";if(r)switch(r){case ea:return S;case el:return p;case ed:return m;case ec:return b;case eh:return w}return t});var eM=ev(function(){return arguments}())?ev:function(e){return eR(e)&&H.call(e,"callee")&&!q.call(e,"callee")},eA=Array.isArray,ej=Q||function(){return!1};function eO(e){if(!eL(e))return!1;var t=ew(e);return t==u||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}function eD(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=0x1fffffffffffff}function eL(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function eR(e){return null!=e&&"object"==typeof e}var eF=D?function(e){return D(e)}:function(e){return eR(e)&&eD(e.length)&&!!P[ew(e)]};function ez(e){return null!=e&&eD(e.length)&&!eO(e)?function(e){var t,n,r=eA(e),i=!r&&eM(e),o=!r&&!i&&ej(e),s=!r&&!i&&!o&&eF(e),a=r||i||o||s,l=a?function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}(e.length,String):[],d=l.length;for(var c in e){H.call(e,c)&&!(a&&("length"==c||o&&("offset"==c||"parent"==c)||s&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||(t=c,(n=null==(n=d)?0x1fffffffffffff:n)&&("number"==typeof t||k.test(t))&&t>-1&&t%1==0&&t<n)))&&l.push(c)}return l}(e):function(e){if(n=(t=e)&&t.constructor,t!==("function"==typeof n&&n.prototype||N))return ee(e);var t,n,r=[];for(var i in Object(e))H.call(e,i)&&"constructor"!=i&&r.push(i);return r}(e)}e.exports=function(e,t){return function e(t,n,r,i,o){return t===n||(null!=t&&null!=n&&(eR(t)||eR(n))?function(e,t,n,r,i,o){var s=eA(e),u=eA(t),m=s?l:eE(e),w=u?l:eE(t);m=m==a?g:m,w=w==a?g:w;var C=m==g,k=w==g,P=m==w;if(P&&ej(e)){if(!ej(t))return!1;s=!0,C=!1}if(P&&!C)return o||(o=new eb),s||eF(e)?eS(e,t,n,r,i,o):function(e,t,n,r,i,o,s){switch(n){case S:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)break;e=e.buffer,t=t.buffer;case v:if(e.byteLength!=t.byteLength||!o(new G(e),new G(t)))break;return!0;case d:case c:case f:return e_(+e,+t);case h:return e.name==t.name&&e.message==t.message;case y:case x:return e==t+"";case p:var a=L;case b:var l=1&r;if(a||(a=R),e.size!=t.size&&!l)break;var u=s.get(e);if(u)return u==t;r|=2,s.set(e,t);var g=eS(a(e),a(t),r,i,o,s);return s.delete(e),g;case"[object Symbol]":if(ep)return ep.call(e)==ep.call(t)}return!1}(e,t,m,n,r,i,o);if(!(1&n)){var T=C&&H.call(e,"__wrapped__"),E=k&&H.call(t,"__wrapped__");if(T||E){var I=T?e.value():e,_=E?t.value():t;return o||(o=new eb),i(I,_,n,r,o)}}return!!P&&(o||(o=new eb),function(e,t,n,r,i,o){var s=1&n,a=eC(e),l=a.length;if(l!=eC(t).length&&!s)return!1;for(var d=l;d--;){var c=a[d];if(!(s?c in t:H.call(t,c)))return!1}var h=o.get(e);if(h&&o.get(t))return h==t;var u=!0;o.set(e,t),o.set(t,e);for(var p=s;++d<l;){var f=e[c=a[d]],g=t[c];if(r)var m=s?r(g,f,c,t,e,o):r(f,g,c,e,t,o);if(!(void 0===m?f===g||i(f,g,n,r,o):m)){u=!1;break}p||(p="constructor"==c)}if(u&&!p){var y=e.constructor,b=t.constructor;y!=b&&"constructor"in e&&"constructor"in t&&!("function"==typeof y&&y instanceof y&&"function"==typeof b&&b instanceof b)&&(u=!1)}return o.delete(e),o.delete(t),u}(e,t,n,r,i,o))}(t,n,r,i,e,o):t!=t&&n!=n)}(e,t)}},96116:(e,t,n)=>{var r,i="__lodash_hash_undefined__",o=/^\[object .+?Constructor\]$/,s="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,a="object"==typeof self&&self&&self.Object===Object&&self,l=s||a||Function("return this")();function d(e,t){return!!(e?e.length:0)&&function(e,t){if(t!=t){for(var n=c,r=e.length,i=-1;++i<r;)if(n(e[i],i,e))return i;return -1}for(var o=-1,s=e.length;++o<s;)if(e[o]===t)return o;return -1}(e,t)>-1}function c(e){return e!=e}function h(e,t){return e.has(t)}function u(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var p=Array.prototype,f=Function.prototype,g=Object.prototype,m=l["__core-js_shared__"],y=(r=/[^.]+$/.exec(m&&m.keys&&m.keys.IE_PROTO||""))?"Symbol(src)_1."+r:"",b=f.toString,x=g.hasOwnProperty,w=g.toString,v=RegExp("^"+b.call(x).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),S=p.splice,C=O(l,"Map"),k=O(l,"Set"),P=O(Object,"create");function T(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function E(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function I(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function _(e){var t=-1,n=e?e.length:0;for(this.__data__=new I;++t<n;)this.add(e[t])}function M(e,t){for(var n,r,i=e.length;i--;){if(n=e[i][0],n===(r=t)||n!=n&&r!=r)return i}return -1}T.prototype.clear=function(){this.__data__=P?P(null):{}},T.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},T.prototype.get=function(e){var t=this.__data__;if(P){var n=t[e];return n===i?void 0:n}return x.call(t,e)?t[e]:void 0},T.prototype.has=function(e){var t=this.__data__;return P?void 0!==t[e]:x.call(t,e)},T.prototype.set=function(e,t){return this.__data__[e]=P&&void 0===t?i:t,this},E.prototype.clear=function(){this.__data__=[]},E.prototype.delete=function(e){var t=this.__data__,n=M(t,e);return!(n<0)&&(n==t.length-1?t.pop():S.call(t,n,1),!0)},E.prototype.get=function(e){var t=this.__data__,n=M(t,e);return n<0?void 0:t[n][1]},E.prototype.has=function(e){return M(this.__data__,e)>-1},E.prototype.set=function(e,t){var n=this.__data__,r=M(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},I.prototype.clear=function(){this.__data__={hash:new T,map:new(C||E),string:new T}},I.prototype.delete=function(e){return j(this,e).delete(e)},I.prototype.get=function(e){return j(this,e).get(e)},I.prototype.has=function(e){return j(this,e).has(e)},I.prototype.set=function(e,t){return j(this,e).set(e,t),this},_.prototype.add=_.prototype.push=function(e){return this.__data__.set(e,i),this},_.prototype.has=function(e){return this.__data__.has(e)};var A=k&&1/u(new k([,-0]))[1]==1/0?function(e){return new k(e)}:function(){};function j(e,t){var n,r,i=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?i["string"==typeof t?"string":"hash"]:i.map}function O(e,t){var n,r,i,s=null==e?void 0:e[t];return!(!D(s)||(n=s,y&&y in n))&&("[object Function]"==(i=D(r=s)?w.call(r):"")||"[object GeneratorFunction]"==i||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(s)?v:o).test(function(e){if(null!=e){try{return b.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(s))?s:void 0}function D(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}e.exports=function(e){return e&&e.length?function(e){var t=-1,n=d,r=e.length,i=!0,o=[],s=o;if(r>=200){var a=A(e);if(a)return u(a);i=!1,n=h,s=new _}else s=o;r:for(;++t<r;){var l=e[t],c=l;if(l=0!==l?l:0,i&&c==c){for(var p=s.length;p--;)if(s[p]===c)continue r;o.push(l)}else n(s,c,void 0)||(s!==o&&s.push(c),o.push(l))}return o}(e):[]}},97144:(e,t,n)=>{"use strict";n.d(t,{$f:()=>M,G2:()=>x,I$:()=>k,Im:()=>j,Qv:()=>l,Sd:()=>y,Z1:()=>P,_G:()=>c,_e:()=>p,bh:()=>w,eB:()=>d,eT:()=>m,ec:()=>A,hy:()=>E,iz:()=>T,pC:()=>S,yY:()=>v,y_:()=>O});var r=n(8242),i=n(27050),o=n(76865);let s=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function a(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("backward",e):!(n.parentOffset>0))?n:null}let l=(e,t,n)=>{let s=a(e,n);if(!s)return!1;let l=f(s);if(!l){let n=s.blockRange(),i=n&&(0,r.jP)(n);return null!=i&&(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let d=l.nodeBefore;if(I(e,l,t,-1))return!0;if(0==s.parent.content.size&&(u(d,"end")||o.nh.isSelectable(d)))for(let n=s.depth;;n--){let a=(0,r.$L)(e.doc,s.before(n),s.after(n),i.Ji.empty);if(a&&a.slice.size<a.to-a.from){if(t){let n=e.tr.step(a);n.setSelection(u(d,"end")?o.LN.findFrom(n.doc.resolve(n.mapping.map(l.pos,-1)),-1):o.nh.create(n.doc,l.pos-d.nodeSize)),t(n.scrollIntoView())}return!0}if(1==n||s.node(n-1).childCount>1)break}return!!d.isAtom&&l.depth==s.depth-1&&(t&&t(e.tr.delete(l.pos-d.nodeSize,l.pos).scrollIntoView()),!0)},d=(e,t,n)=>{let r=a(e,n);if(!r)return!1;let i=f(r);return!!i&&h(e,i,t)},c=(e,t,n)=>{let r=g(e,n);if(!r)return!1;let i=b(r);return!!i&&h(e,i,t)};function h(e,t,n){let s=t.nodeBefore,a=t.pos-1;for(;!s.isTextblock;a--){if(s.type.spec.isolating)return!1;let e=s.lastChild;if(!e)return!1;s=e}let l=t.nodeAfter,d=t.pos+1;for(;!l.isTextblock;d++){if(l.type.spec.isolating)return!1;let e=l.firstChild;if(!e)return!1;l=e}let c=(0,r.$L)(e.doc,a,d,i.Ji.empty);if(!c||c.from!=a||c instanceof r.Ln&&c.slice.size>=d-a)return!1;if(n){let t=e.tr.step(c);t.setSelection(o.U3.create(t.doc,a)),n(t.scrollIntoView())}return!0}function u(e,t,n=!1){for(let r=e;r;r="start"==t?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&1!=r.childCount)break}return!1}let p=(e,t,n)=>{let{$head:r,empty:i}=e.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):r.parentOffset>0)return!1;s=f(r)}let a=s&&s.nodeBefore;return!!a&&!!o.nh.isSelectable(a)&&(t&&t(e.tr.setSelection(o.nh.create(e.doc,s.pos-a.nodeSize)).scrollIntoView()),!0)};function f(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function g(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("forward",e):!(n.parentOffset<n.parent.content.size))?n:null}let m=(e,t,n)=>{let s=g(e,n);if(!s)return!1;let a=b(s);if(!a)return!1;let l=a.nodeAfter;if(I(e,a,t,1))return!0;if(0==s.parent.content.size&&(u(l,"start")||o.nh.isSelectable(l))){let n=(0,r.$L)(e.doc,s.before(),s.after(),i.Ji.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(u(l,"start")?o.LN.findFrom(r.doc.resolve(r.mapping.map(a.pos)),1):o.nh.create(r.doc,r.mapping.map(a.pos))),t(r.scrollIntoView())}return!0}}return!!l.isAtom&&a.depth==s.depth-1&&(t&&t(e.tr.delete(a.pos,a.pos+l.nodeSize).scrollIntoView()),!0)},y=(e,t,n)=>{let{$head:r,empty:i}=e.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):r.parentOffset<r.parent.content.size)return!1;s=b(r)}let a=s&&s.nodeAfter;return!!a&&!!o.nh.isSelectable(a)&&(t&&t(e.tr.setSelection(o.nh.create(e.doc,s.pos)).scrollIntoView()),!0)};function b(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1<n.childCount)return e.doc.resolve(e.after(t+1));if(n.type.spec.isolating)break}return null}let x=(e,t)=>{let n=e.selection,i=n instanceof o.nh,s;if(i){if(n.node.isTextblock||!(0,r.n9)(e.doc,n.from))return!1;s=n.from}else if(null==(s=(0,r.N0)(e.doc,n.from,-1)))return!1;if(t){let n=e.tr.join(s);i&&n.setSelection(o.nh.create(n.doc,s-e.doc.resolve(s).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0},w=(e,t)=>{let n=e.selection,i;if(n instanceof o.nh){if(n.node.isTextblock||!(0,r.n9)(e.doc,n.to))return!1;i=n.to}else if(null==(i=(0,r.N0)(e.doc,n.to,1)))return!1;return t&&t(e.tr.join(i).scrollIntoView()),!0},v=(e,t)=>{let{$from:n,$to:i}=e.selection,o=n.blockRange(i),s=o&&(0,r.jP)(o);return null!=s&&(t&&t(e.tr.lift(o,s).scrollIntoView()),!0)},S=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!!n.parent.type.spec.code&&!!n.sameParent(r)&&(t&&t(e.tr.insertText("\n").scrollIntoView()),!0)};function C(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}let k=(e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),s=n.indexAfter(-1),a=C(i.contentMatchAt(s));if(!a||!i.canReplaceWith(s,s,a))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,a.createAndFill());i.setSelection(o.LN.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},P=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof o.i5||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=C(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,a=e.tr.insert(n,s.createAndFill());a.setSelection(o.U3.create(a.doc,n+1)),t(a.scrollIntoView())}return!0},T=(e,t)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let i=n.before();if((0,r.zy)(e.doc,i))return t&&t(e.tr.split(i).scrollIntoView()),!0}let i=n.blockRange(),o=i&&(0,r.jP)(i);return null!=o&&(t&&t(e.tr.lift(i,o).scrollIntoView()),!0)},E=(e,t)=>{let{$from:n,to:r}=e.selection,i,s=n.sharedDepth(r);return 0!=s&&(i=n.before(s),t&&t(e.tr.setSelection(o.nh.create(e.doc,i))),!0)};function I(e,t,n,s){let a,l,d,c=t.nodeBefore,h=t.nodeAfter,p,f,g=c.type.spec.isolating||h.type.spec.isolating;if(!g&&(a=t.nodeBefore,l=t.nodeAfter,d=t.index(),a&&l&&a.type.compatibleContent(l.type)&&(!a.content.size&&t.parent.canReplace(d-1,d)?(n&&n(e.tr.delete(t.pos-a.nodeSize,t.pos).scrollIntoView()),!0):!!t.parent.canReplace(d,d+1)&&!!(l.isTextblock||(0,r.n9)(e.doc,t.pos))&&(n&&n(e.tr.join(t.pos).scrollIntoView()),!0))))return!0;let m=!g&&t.parent.canReplace(t.index(),t.index()+1);if(m&&(p=(f=c.contentMatchAt(c.childCount)).findWrapping(h.type))&&f.matchType(p[0]||h.type).validEnd){if(n){let o=t.pos+h.nodeSize,s=i.FK.empty;for(let e=p.length-1;e>=0;e--)s=i.FK.from(p[e].create(null,s));s=i.FK.from(c.copy(s));let a=e.tr.step(new r.Wg(t.pos-1,o,t.pos,o,new i.Ji(s,1,0),p.length,!0)),l=a.doc.resolve(o+2*p.length);l.nodeAfter&&l.nodeAfter.type==c.type&&(0,r.n9)(a.doc,l.pos)&&a.join(l.pos),n(a.scrollIntoView())}return!0}let y=h.type.spec.isolating||s>0&&g?null:o.LN.findFrom(t,1),b=y&&y.$from.blockRange(y.$to),x=b&&(0,r.jP)(b);if(null!=x&&x>=t.depth)return n&&n(e.tr.lift(b,x).scrollIntoView()),!0;if(m&&u(h,"start",!0)&&u(c,"end")){let o=c,s=[];for(;s.push(o),!o.isTextblock;)o=o.lastChild;let a=h,l=1;for(;!a.isTextblock;a=a.firstChild)l++;if(o.canReplace(o.childCount,o.childCount,a.content)){if(n){let o=i.FK.empty;for(let e=s.length-1;e>=0;e--)o=i.FK.from(s[e].copy(o));n(e.tr.step(new r.Wg(t.pos-s.length,t.pos+h.nodeSize,t.pos+l,t.pos+h.nodeSize-l,new i.Ji(o,s.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function _(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return!!i.node(s).isTextblock&&(n&&n(t.tr.setSelection(o.U3.create(t.doc,e<0?i.start(s):i.end(s)))),!0)}}let M=_(-1),A=_(1);function j(e,t=null){return function(n,i){let{$from:o,$to:s}=n.selection,a=o.blockRange(s),l=a&&(0,r.oM)(a,e,t);return!!l&&(i&&i(n.tr.wrap(a,l).scrollIntoView()),!0)}}function O(e,t=null){return function(n,r){let i=!1;for(let r=0;r<n.selection.ranges.length&&!i;r++){let{$from:{pos:o},$to:{pos:s}}=n.selection.ranges[r];n.doc.nodesBetween(o,s,(r,o)=>{if(i)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t)))if(r.type==e)i=!0;else{let t=n.doc.resolve(o),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r<n.selection.ranges.length;r++){let{$from:{pos:o},$to:{pos:s}}=n.selection.ranges[r];i.setBlockType(o,s,e,t)}r(i.scrollIntoView())}return!0}}function D(...e){return function(t,n,r){for(let i=0;i<e.length;i++)if(e[i](t,n,r))return!0;return!1}}let L=D(s,l,p),R=D(s,m,y),F={Enter:D(S,P,T,(e,t)=>{if(e.selection instanceof o.nh&&e.selection.node.isBlock){let{$from:n}=e.selection;return!!n.parentOffset&&!!(0,r.zy)(e.doc,n.pos)&&(t&&t(e.tr.split(n.pos).scrollIntoView()),!0)}if(!e.selection.$from.depth)return!1;let n=e.tr;!e.selection.empty&&(e.selection instanceof o.U3||e.selection instanceof o.i5)&&n.deleteSelection();let{$from:i}=n.selection,s=n.steps.length,a=[],l,d,c=!1,h=!1;for(let e=i.depth;;e--){if(i.node(e).isBlock){let t;c=i.end(e)==i.pos+(i.depth-e),h=i.start(e)==i.pos-(i.depth-e),d=C(i.node(e-1).contentMatchAt(i.indexAfter(e-1)));a.unshift(t||(c&&d?{type:d}:null)),l=e;break}if(1==e)return!1;a.unshift(null)}let u=i.pos,p=(0,r.zy)(n.doc,u,a.length,a);if(p||(a[0]=d?{type:d}:null,p=(0,r.zy)(n.doc,u,a.length,a)),!p)return!1;if(n.split(u,a.length,a),!c&&h&&i.node(l).type!=d){let e=n.mapping.slice(s),t=e.map(i.before(l)),r=n.doc.resolve(t);d&&i.node(l-1).canReplaceWith(r.index(),r.index()+1,d)&&n.setNodeMarkup(e.map(i.before(l)),d)}return t&&t(n.scrollIntoView()),!0}),"Mod-Enter":k,Backspace:L,"Mod-Backspace":L,"Shift-Backspace":L,Delete:R,"Mod-Delete":R,"Mod-a":(e,t)=>(t&&t(e.tr.setSelection(new o.i5(e.doc))),!0)},z={"Ctrl-h":F.Backspace,"Alt-Backspace":F["Mod-Backspace"],"Ctrl-d":F.Delete,"Ctrl-Alt-Backspace":F["Mod-Delete"],"Alt-Delete":F["Mod-Delete"],"Alt-d":F["Mod-Delete"],"Ctrl-a":M,"Ctrl-e":A};for(let e in F)z[e]=F[e];"u">typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"u">typeof os&&os.platform&&os.platform()},97156:(e,t,n)=>{"use strict";n.d(t,{A2:()=>b,Tj:()=>f,oE:()=>C,xX:()=>u});var r=n(83102),i=n(81467),o=n(24167),s=n(22690),a=n(16038);n(41463);let l="TLDRAW_USER_DATA_v3",d=s.T.object({id:s.T.string,name:s.T.string.nullable().optional(),color:s.T.string.nullable().optional(),locale:s.T.string.nullable().optional(),animationSpeed:s.T.number.nullable().optional(),areKeyboardShortcutsEnabled:s.T.boolean.nullable().optional(),edgeScrollSpeed:s.T.number.nullable().optional(),colorScheme:s.T.literalEnum("light","dark","system").optional(),isSnapMode:s.T.boolean.nullable().optional(),isWrapMode:s.T.boolean.nullable().optional(),isDynamicSizeMode:s.T.boolean.nullable().optional(),isPasteAtCursorMode:s.T.boolean.nullable().optional(),enhancedA11yMode:s.T.boolean.nullable().optional(),inputMode:s.T.literalEnum("trackpad","mouse").nullable().optional(),isZoomDirectionInverted:s.T.boolean.nullable().optional()}),c={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8,AddKeyboardShortcuts:9,AddShowUiLabels:10,AddPointerPeripheral:11,RenameShowUiLabelsToEnhancedA11yMode:12,AddZoomDirectionInverted:13},h=Math.max(...Object.values(c)),u=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function p(){return u[Math.floor(Math.random()*u.length)]}let f=Object.freeze({name:"",locale:(0,i.jP)(),color:p(),edgeScrollSpeed:1,animationSpeed:+!("u">typeof window&&(0,a.CM)().matchMedia&&(0,a.CM)().matchMedia?.("(prefers-reduced-motion: reduce)")?.matches),areKeyboardShortcutsEnabled:!0,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1,enhancedA11yMode:!1,colorScheme:"light",inputMode:null,isZoomDirectionInverted:!1});function g(){return{id:(0,o.NF)(),color:p()}}function m(e){if(null===e||"object"!=typeof e||!("version"in e)||!("user"in e)||"number"!=typeof e.version)return g();let t=(0,o.pN)(e);t.version<c.AddAnimationSpeed&&(t.user.animationSpeed=1),t.version<c.AddIsSnapMode&&(t.user.isSnapMode=!1),t.version,c.MakeFieldsNullable,t.version<c.AddEdgeScrollSpeed&&(t.user.edgeScrollSpeed=1),t.version<c.AddExcalidrawSelectMode&&(t.user.isWrapMode=!1),t.version<c.AllowSystemColorScheme&&(!0===t.user.isDarkMode?t.user.colorScheme="dark":!1===t.user.isDarkMode&&(t.user.colorScheme="light"),delete t.user.isDarkMode),t.version<c.AddDynamicSizeMode&&(t.user.isDynamicSizeMode=!1),t.version<c.AddPasteAtCursor&&(t.user.isPasteAtCursorMode=!1),t.version<c.AddKeyboardShortcuts&&(t.user.areKeyboardShortcutsEnabled=!0),t.version<c.AddShowUiLabels&&(t.user.showUiLabels=!1),t.version<c.RenameShowUiLabelsToEnhancedA11yMode&&(t.user.enhancedA11yMode=t.user.showUiLabels,delete t.user.showUiLabels),t.version<c.AddPointerPeripheral&&(t.user.inputMode=null),t.version<c.AddZoomDirectionInverted&&(t.user.isZoomDirectionInverted=!1),t.version=h;try{return d.validate(t.user)}catch{return g()}}let y=(0,r.eU)("globalUserData",null);function b(e){d.validate(e),y.set(e),(0,o.Yz)(l,JSON.stringify({version:h,user:y.get()})),x?.postMessage({type:S,origin:v(),data:{user:C(),version:h}})}let x="u"<typeof BroadcastChannel?null:new BroadcastChannel("tldraw-user-sync");x?.addEventListener("message",e=>{let t=e.data;t?.type===S&&t?.origin!==v()&&y.set(m(t.data))});let w=null;function v(){return null===w&&(w=(0,o.NF)()),w}let S="tldraw-user-preferences-change";function C(){let e=y.get();return e||b(e=m(JSON.parse((0,o.zM)(l)||"null")??null)),e}},97986:(e,t,n)=>{"use strict";n.d(t,{N:()=>s,d:()=>l});var r=n(81467),i=n(24167),o=n(59466);function s(e,t,n){let s={};if("store"in t){let n=e.schema.migrateStoreSnapshot(t);if("success"!==n.type)throw Error("Failed to migrate store snapshot: "+n.reason);s.document={schema:e.schema.serialize(),store:(0,i.J2)(n.value,(t,{typeName:n})=>e.scopedTypes.document.has(n))}}else s=t;let l=(0,r.Pu)(e.get(r.O9)),d=a.get(e,o.e6).get();e.atomic(()=>{s.document&&e.loadStoreSnapshot(s.document),l&&e.update(r.O9,e=>({...e,...l})),d&&(0,o.Jr)(e,d),s.session&&(0,o.Jr)(e,s.session,{forceOverwrite:n?.forceOverwriteSessionState})})}let a=new i.l;function l(e){let t=a.get(e,o.e6).get();if(!t)throw Error("Session state is not ready yet");return{document:e.getStoreSnapshot(),session:t}}},98466:(e,t,n)=>{"use strict";n.d(t,{s:()=>o});var r=n(83102),i=n(26614);function o(e){let t=new Set,n=i.i.prototype.canCull;return(0,r.EW)("notVisibleShapes",function(i){let o=e.getCurrentPageShapeIds(),s=e.getViewportPageBounds(),a=e.getShapeIdsInsideBounds(s);if(a.size===o.size)return(0,r._O)(i)||i.size>0?t:i;let l=new Set;for(let t of o){if(a.has(t))continue;let r=e.store.unsafeGetWithoutCapture(t);if(!r)continue;let i=e.getShapeUtil(r.type);if(i.canCull===n){l.add(t);continue}let o=e.getShape(t);o&&i.canCull(o)&&l.add(t)}if((0,r._O)(i))return l;if(l.size===i.size){let e=!0;for(let t of l)if(!i.has(t)){e=!1;break}if(e)return i}return l})}},98626:(e,t,n)=>{"use strict";n.d(t,{w:()=>o});var r=n(58347),i=n(46195);class o{constructor(e){this.editor=e}editor;_isEdgeScrolling=!1;_edgeScrollDuration=-1;getIsEdgeScrolling(){return this._isEdgeScrolling}updateEdgeScrolling(e){let{editor:t}=this;if(t.getCameraOptions().isLocked)return;let n=this.getEdgeScroll();if(0===n.x&&0===n.y)this._isEdgeScrolling&&(this._isEdgeScrolling=!1,this._edgeScrollDuration=0);else if(this._isEdgeScrolling||(this._isEdgeScrolling=!0,this._edgeScrollDuration=0),this._edgeScrollDuration+=e,this._edgeScrollDuration>t.options.edgeScrollDelay){let e=t.options.edgeScrollEaseDuration>0?r.Z.easeInCubic(Math.min(1,this._edgeScrollDuration/(t.options.edgeScrollDelay+t.options.edgeScrollEaseDuration))):1;this.moveCameraWhenCloseToEdge({x:n.x*e,y:n.y*e})}}getEdgeProximityFactors(e,t,n,r,i){let{editor:o}=this,s=o.options.edgeScrollDistance,a=n?o.options.coarsePointerWidth:0,l=e-a,d=e+a,c=r?0:s,h=i?t:t-s;return l<c?Math.min(1,(c-l)/s):d>h?-Math.min(1,(d-h)/s):0}getEdgeScroll(){let{editor:e}=this,{x:t,y:n}=e.inputs.getCurrentScreenPoint(),r=e.getViewportScreenBounds(),{isCoarsePointer:i,insets:[o,s,a,l]}=e.getInstanceState();return{x:this.getEdgeProximityFactors(t,r.w,i,l,s),y:this.getEdgeProximityFactors(n,r.h,i,o,a)}}moveCameraWhenCloseToEdge(e){if(0===e.x&&0===e.y)return;let{editor:t}=this,n=t.getViewportScreenBounds(),r=n.w<1e3?.612:1,o=n.h<1e3?.612:1,s=t.getZoomLevel(),a=t.user.getEdgeScrollSpeed()*t.options.edgeScrollSpeed,l=a*e.x*r/s,d=a*e.y*o/s,{x:c,y:h,z:u}=t.getCamera();t.setCamera(new i.l(c+l,h+d,u))}}},99017:(e,t,n)=>{e=n.nmd(e);var r,i,o,s="__lodash_hash_undefined__",a="[object Arguments]",l="[object Array]",d="[object Boolean]",c="[object Date]",h="[object Error]",u="[object Function]",p="[object Map]",f="[object Number]",g="[object Object]",m="[object Promise]",y="[object RegExp]",b="[object Set]",x="[object String]",w="[object WeakMap]",v="[object ArrayBuffer]",S="[object DataView]",C=/^\[object .+?Constructor\]$/,k=/^(?:0|[1-9]\d*)$/,P={};P["[object Float32Array]"]=P["[object Float64Array]"]=P["[object Int8Array]"]=P["[object Int16Array]"]=P["[object Int32Array]"]=P["[object Uint8Array]"]=P["[object Uint8ClampedArray]"]=P["[object Uint16Array]"]=P["[object Uint32Array]"]=!0,P[a]=P[l]=P[v]=P[d]=P[S]=P[c]=P[h]=P[u]=P[p]=P[f]=P[g]=P[y]=P[b]=P[x]=P[w]=!1;var T="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,E="object"==typeof self&&self&&self.Object===Object&&self,I=T||E||Function("return this")(),_=t&&!t.nodeType&&t,M=_&&e&&!e.nodeType&&e,A=M&&M.exports===_&&T.process,j=function(){try{return A&&A.binding("util")}catch(e){}}(),O=j&&j.isTypedArray;function D(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}function L(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function R(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var F=Array.prototype,z=Function.prototype,N=Object.prototype,$=I["__core-js_shared__"],B=(r=/[^.]+$/.exec($&&$.keys&&$.keys.IE_PROTO||""))?"Symbol(src)_1."+r:"",H=z.toString,U=N.hasOwnProperty,K=N.toString,W=RegExp("^"+H.call(U).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),V=I.Symbol,Y=I.Uint8Array,G=N.propertyIsEnumerable,q=F.splice,X=(i=Object.keys,o=Object,function(e){return i(o(e))}),J=eb(I,"DataView"),Z=eb(I,"Map"),Q=eb(I,"Promise"),ee=eb(I,"Set"),et=eb(I,"WeakMap"),en=eb(Object,"create"),er=ew(J),ei=ew(Z),eo=ew(Q),es=ew(ee),ea=ew(et),el=V?V.prototype:void 0,ed=el?el.valueOf:void 0;function ec(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function eh(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function eu(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function ep(e){var t=-1,n=e?e.length:0;for(this.__data__=new eu;++t<n;)this.add(e[t])}function ef(e){this.__data__=new eh(e)}function eg(e,t){for(var n=e.length;n--;)if(ev(e[n][0],t))return n;return -1}function em(e,t,n,r,i,o){var s=2&i,a=e.length,l=t.length;if(a!=l&&!(s&&l>a))return!1;var d=o.get(e);if(d&&o.get(t))return d==t;var c=-1,h=!0,u=1&i?new ep:void 0;for(o.set(e,t),o.set(t,e);++c<a;){var p=e[c],f=t[c];if(r)var g=s?r(f,p,c,t,e,o):r(p,f,c,e,t,o);if(void 0!==g){if(g)continue;h=!1;break}if(u){if(!function(e,t){for(var n=-1,r=e?e.length:0;++n<r;)if(t(e[n],n,e))return!0;return!1}(t,function(e,t){if(!u.has(t)&&(p===e||n(p,e,r,i,o)))return u.add(t)})){h=!1;break}}else if(!(p===f||n(p,f,r,i,o))){h=!1;break}}return o.delete(e),o.delete(t),h}function ey(e,t){var n,r,i=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?i["string"==typeof t?"string":"hash"]:i.map}function eb(e,t){var n,r=null==e?void 0:e[t];return!(!eT(r)||(n=r,B&&B in n))&&(ek(r)||D(r)?W:C).test(ew(r))?r:void 0}ec.prototype.clear=function(){this.__data__=en?en(null):{}},ec.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},ec.prototype.get=function(e){var t=this.__data__;if(en){var n=t[e];return n===s?void 0:n}return U.call(t,e)?t[e]:void 0},ec.prototype.has=function(e){var t=this.__data__;return en?void 0!==t[e]:U.call(t,e)},ec.prototype.set=function(e,t){return this.__data__[e]=en&&void 0===t?s:t,this},eh.prototype.clear=function(){this.__data__=[]},eh.prototype.delete=function(e){var t=this.__data__,n=eg(t,e);return!(n<0)&&(n==t.length-1?t.pop():q.call(t,n,1),!0)},eh.prototype.get=function(e){var t=this.__data__,n=eg(t,e);return n<0?void 0:t[n][1]},eh.prototype.has=function(e){return eg(this.__data__,e)>-1},eh.prototype.set=function(e,t){var n=this.__data__,r=eg(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},eu.prototype.clear=function(){this.__data__={hash:new ec,map:new(Z||eh),string:new ec}},eu.prototype.delete=function(e){return ey(this,e).delete(e)},eu.prototype.get=function(e){return ey(this,e).get(e)},eu.prototype.has=function(e){return ey(this,e).has(e)},eu.prototype.set=function(e,t){return ey(this,e).set(e,t),this},ep.prototype.add=ep.prototype.push=function(e){return this.__data__.set(e,s),this},ep.prototype.has=function(e){return this.__data__.has(e)},ef.prototype.clear=function(){this.__data__=new eh},ef.prototype.delete=function(e){return this.__data__.delete(e)},ef.prototype.get=function(e){return this.__data__.get(e)},ef.prototype.has=function(e){return this.__data__.has(e)},ef.prototype.set=function(e,t){var n=this.__data__;if(n instanceof eh){var r=n.__data__;if(!Z||r.length<199)return r.push([e,t]),this;n=this.__data__=new eu(r)}return n.set(e,t),this};var ex=function(e){return K.call(e)};function ew(e){if(null!=e){try{return H.call(e)}catch(e){}try{return e+""}catch(e){}}return""}function ev(e,t){return e===t||e!=e&&t!=t}(J&&ex(new J(new ArrayBuffer(1)))!=S||Z&&ex(new Z)!=p||Q&&ex(Q.resolve())!=m||ee&&ex(new ee)!=b||et&&ex(new et)!=w)&&(ex=function(e){var t=K.call(e),n=t==g?e.constructor:void 0,r=n?ew(n):void 0;if(r)switch(r){case er:return S;case ei:return p;case eo:return m;case es:return b;case ea:return w}return t});var eS=Array.isArray;function eC(e){return null!=e&&eP(e.length)&&!ek(e)}function ek(e){var t=eT(e)?K.call(e):"";return t==u||"[object GeneratorFunction]"==t}function eP(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=0x1fffffffffffff}function eT(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function eE(e){return!!e&&"object"==typeof e}var eI=O?function(e){return O(e)}:function(e){return eE(e)&&eP(e.length)&&!!P[K.call(e)]};function e_(e){return eC(e)?function(e){var t,n,r,i,o=eS(e)||eE(n=t=e)&&eC(n)&&U.call(t,"callee")&&(!G.call(t,"callee")||K.call(t)==a)?function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}(e.length,String):[],s=o.length,l=!!s;for(var d in e){U.call(e,d)&&!(l&&("length"==d||(r=d,(i=null==(i=s)?0x1fffffffffffff:i)&&("number"==typeof r||k.test(r))&&r>-1&&r%1==0&&r<i)))&&o.push(d)}return o}(e):function(e){if(n=(t=e)&&t.constructor,t!==("function"==typeof n&&n.prototype||N))return X(e);var t,n,r=[];for(var i in Object(e))U.call(e,i)&&"constructor"!=i&&r.push(i);return r}(e)}e.exports=function(e,t,n){var r=(n="function"==typeof n?n:void 0)?n(e,t):void 0;return void 0===r?function e(t,n,r,i,o){return t===n||(null!=t&&null!=n&&(eT(t)||eE(n))?function(e,t,n,r,i,o){var s=eS(e),u=eS(t),m=l,w=l;s||(m=(m=ex(e))==a?g:m),u||(w=(w=ex(t))==a?g:w);var C=m==g&&!D(e),k=w==g&&!D(t),P=m==w;if(P&&!C)return o||(o=new ef),s||eI(e)?em(e,t,n,r,i,o):function(e,t,n,r,i,o,s){switch(n){case S:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)break;e=e.buffer,t=t.buffer;case v:if(e.byteLength!=t.byteLength||!r(new Y(e),new Y(t)))break;return!0;case d:case c:case f:return ev(+e,+t);case h:return e.name==t.name&&e.message==t.message;case y:case x:return e==t+"";case p:var a=L;case b:var l=2&o;if(a||(a=R),e.size!=t.size&&!l)break;var u=s.get(e);if(u)return u==t;o|=1,s.set(e,t);var g=em(a(e),a(t),r,i,o,s);return s.delete(e),g;case"[object Symbol]":if(ed)return ed.call(e)==ed.call(t)}return!1}(e,t,m,n,r,i,o);if(!(2&i)){var T=C&&U.call(e,"__wrapped__"),E=k&&U.call(t,"__wrapped__");if(T||E){var I=T?e.value():e,_=E?t.value():t;return o||(o=new ef),n(I,_,r,i,o)}}return!!P&&(o||(o=new ef),function(e,t,n,r,i,o){var s=2&i,a=e_(e),l=a.length;if(l!=e_(t).length&&!s)return!1;for(var d=l;d--;){var c=a[d];if(!(s?c in t:U.call(t,c)))return!1}var h=o.get(e);if(h&&o.get(t))return h==t;var u=!0;o.set(e,t),o.set(t,e);for(var p=s;++d<l;){var f=e[c=a[d]],g=t[c];if(r)var m=s?r(g,f,c,t,e,o):r(f,g,c,e,t,o);if(!(void 0===m?f===g||n(f,g,r,i,o):m)){u=!1;break}p||(p="constructor"==c)}if(u&&!p){var y=e.constructor,b=t.constructor;y!=b&&"constructor"in e&&"constructor"in t&&!("function"==typeof y&&y instanceof y&&"function"==typeof b&&b instanceof b)&&(u=!1)}return o.delete(e),o.delete(t),u}(e,t,n,r,i,o))}(t,n,e,r,i,o):t!=t&&n!=n)}(e,t,n):!!r}},99714:(e,t,n)=>{"use strict";n.d(t,{_:()=>c});var r=n(24167),i=n(64411),o=Object.defineProperty,s=Object.getOwnPropertyDescriptor,a=(e,t,n,r)=>{for(var i,a=r>1?void 0:r?s(t,n):t,l=e.length-1;l>=0;l--)(i=e[l])&&(a=(r?i(t,n,a):i(a))||a);return r&&a&&o(t,n,a),a};function l(e,t){let n=Math.ceil(t*e.length)-1;return e[Math.max(0,n)]}function d(e){if(0===e.length)return{avg:0,median:0,p95:0,p99:0,min:0,max:0};let t=[...e].sort((e,t)=>e-t);return{avg:t.reduce((e,t)=>e+t,0)/t.length,median:l(t,.5),p95:l(t,.95),p99:l(t,.99),min:t[0],max:t[t.length-1]}}class c{emitter=new i;editor;activeInteraction=null;activeCamera=null;frameCleanup=null;shapeCreatedCleanup=null;shapeEditedCleanup=null;shapeDeletedCleanup=null;loafObserver=null;constructor(e){this.editor=e}on(e,t){return this.emitter.on(e,t),this._maybeAttachLazyListeners(e),()=>{this.emitter.off(e,t),this._maybeDetachLazyListeners(e)}}once(e,t){let n=(...n)=>{t(...n),this._maybeDetachLazyListeners(e)};return this.emitter.once(e,n),this._maybeAttachLazyListeners(e),()=>{this.emitter.off(e,n),this._maybeDetachLazyListeners(e)}}dispose(){this.activeCamera?.timeout&&clearTimeout(this.activeCamera.timeout),this.activeInteraction=null,this.activeCamera=null,this.frameCleanup?.(),this.frameCleanup=null,this.shapeCreatedCleanup?.(),this.shapeCreatedCleanup=null,this.shapeEditedCleanup?.(),this.shapeEditedCleanup=null,this.shapeDeletedCleanup?.(),this.shapeDeletedCleanup=null,this._stopLoafObserver(),this.emitter.removeAllListeners()}_notifyInteractionStart(e,t){if(0===this.emitter.listenerCount("interaction-start")&&0===this.emitter.listenerCount("interaction-end"))return;this.activeInteraction&&console.warn(`[tldraw] New interaction '${e}' started while '${this.activeInteraction.name}' was still active`);let n={};for(let e of this.editor.getSelectedShapes())n[e.type]=(n[e.type]||0)+1;this.activeInteraction={name:e,path:t,startTime:performance.now(),frameTimes:[],selectedShapeTypes:n,loafEntries:[]};let r={name:e,path:t,timestamp:performance.now()};this.emitter.emit("interaction-start",r)}_notifyInteractionEnd(){let e=this.activeInteraction;if(!e||(this.activeInteraction=null,0===this.emitter.listenerCount("interaction-end")))return;let t=performance.now()-e.startTime,n=d(e.frameTimes),r={name:e.name,path:e.path,duration:t,fps:e.frameTimes.length>0?e.frameTimes.length/t*1e3:0,frameCount:e.frameTimes.length,avgFrameTime:n.avg,medianFrameTime:n.median,p95FrameTime:n.p95,p99FrameTime:n.p99,minFrameTime:n.min,maxFrameTime:n.max,frameTimes:e.frameTimes,shapeCount:this.editor.getCurrentPageShapeIds().size,selectedShapeTypes:e.selectedShapeTypes,longAnimationFrames:e.loafEntries.length>0?e.loafEntries:void 0,zoomLevel:this.editor.getCamera().z,timestamp:performance.now()};this.emitter.emit("interaction-end",r)}_notifyCameraOperation(e){(0!==this.emitter.listenerCount("camera-start")||0!==this.emitter.listenerCount("camera-end"))&&(this.activeCamera?(this.activeCamera.timeout&&clearTimeout(this.activeCamera.timeout),this.activeCamera.type!==e?(this._endCameraSession(),this._startCameraSession(e)):this.activeCamera.timeout=this.editor.timers.setTimeout(()=>this._endCameraSession(),50)):this._startCameraSession(e))}_notifyUndoRedo(e,t,n){0===this.emitter.listenerCount(e)||this.emitter.emit(e,{type:e,undoDepth:t,redoDepth:n})}_startCameraSession(e){if(this.activeCamera={type:e,startTime:performance.now(),frameTimes:[],timeout:this.editor.timers.setTimeout(()=>this._endCameraSession(),50),loafEntries:[]},this.emitter.listenerCount("camera-start")>0){let t={type:e,timestamp:performance.now()};this.emitter.emit("camera-start",t)}}_endCameraSession(){let e=this.activeCamera;if(!e||(this.activeCamera=null,e.timeout&&clearTimeout(e.timeout),0===this.emitter.listenerCount("camera-end")))return;let t=performance.now()-e.startTime,n=d(e.frameTimes),r=this.editor.getViewportScreenBounds(),i=this.editor.getCurrentPageShapeIds().size,o=this.editor.getCulledShapes().size,s={type:e.type,duration:t,fps:e.frameTimes.length>0?e.frameTimes.length/t*1e3:0,frameCount:e.frameTimes.length,avgFrameTime:n.avg,medianFrameTime:n.median,p95FrameTime:n.p95,p99FrameTime:n.p99,minFrameTime:n.min,maxFrameTime:n.max,frameTimes:e.frameTimes,shapeCount:i,viewportWidth:r.w,viewportHeight:r.h,longAnimationFrames:e.loafEntries.length>0?e.loafEntries:void 0,visibleShapeCount:i-o,culledShapeCount:o,zoomLevel:this.editor.getCamera().z,timestamp:performance.now()};this.emitter.emit("camera-end",s)}_onFrame(e){if(this.activeInteraction&&this.activeInteraction.frameTimes.push(e),this.activeCamera&&this.activeCamera.frameTimes.push(e),this.emitter.listenerCount("frame")>0){let t=this.editor.getCurrentPageShapeIds().size,n=this.editor.getCulledShapes().size;this.emitter.emit("frame",{elapsed:e,shapeCount:t,culledShapeCount:n,visibleShapeCount:t-n})}}_onShapesCreated(e){if(0===this.emitter.listenerCount("shapes-created"))return;let t={};for(let n of e)"shape"===n.typeName&&(t[n.type]=(t[n.type]||0)+1);let n=Object.values(t).reduce((e,t)=>e+t,0);if(0===n)return;let r={operation:"create",count:n,shapeTypes:t,timestamp:performance.now()};this.emitter.emit("shapes-created",r)}_onShapesEdited(e){if(0===this.emitter.listenerCount("shapes-updated"))return;let t={};for(let n of e)"shape"===n.typeName&&(t[n.type]=(t[n.type]||0)+1);let n=Object.values(t).reduce((e,t)=>e+t,0);if(0===n)return;let r={operation:"update",count:n,shapeTypes:t,timestamp:performance.now()};this.emitter.emit("shapes-updated",r)}_onShapesDeleted(e){if(0===this.emitter.listenerCount("shapes-deleted"))return;let t={};for(let n of e){let e=this.editor.getShape(n);e&&(t[e.type]=(t[e.type]||0)+1)}let n={operation:"delete",count:e.length,shapeTypes:t,timestamp:performance.now()};this.emitter.emit("shapes-deleted",n)}_startLoafObserver(){if("u">typeof PerformanceObserver){try{let e=PerformanceObserver.supportedEntryTypes;if(!e?.includes("long-animation-frame"))return}catch{return}this.loafObserver=new PerformanceObserver(e=>{let t=null!==this.activeInteraction,n=null!==this.activeCamera;if(t||n)for(let r of e.getEntries()){let e="number"!=typeof r.duration?null:{startTime:r.startTime,duration:r.duration,blockingDuration:r.blockingDuration??0,scripts:(r.scripts??[]).map(e=>({sourceURL:e.sourceURL??"",invoker:e.invoker??"",duration:e.duration??0}))};e&&(t&&this.activeInteraction.loafEntries.push(e),n&&this.activeCamera.loafEntries.push(e))}}),this.loafObserver.observe({type:"long-animation-frame",buffered:!1})}}_stopLoafObserver(){this.loafObserver&&(this.loafObserver.disconnect(),this.loafObserver=null)}_needsFrameListener(){return this.emitter.listenerCount("frame")>0||this.emitter.listenerCount("interaction-start")>0||this.emitter.listenerCount("interaction-end")>0||this.emitter.listenerCount("camera-start")>0||this.emitter.listenerCount("camera-end")>0}_needsLoafObserver(){return this.emitter.listenerCount("interaction-end")>0||this.emitter.listenerCount("camera-end")>0}_maybeAttachLazyListeners(e){!this.frameCleanup&&("frame"===e||"interaction-start"===e||"interaction-end"===e||"camera-start"===e||"camera-end"===e)&&this._needsFrameListener()&&(this.editor.on("frame",this._onFrame),this.frameCleanup=()=>this.editor.off("frame",this._onFrame)),!this.loafObserver&&("interaction-end"===e||"camera-end"===e)&&this._needsLoafObserver()&&this._startLoafObserver(),this.shapeCreatedCleanup||"shapes-created"!==e||(this.editor.on("created-shapes",this._onShapesCreated),this.shapeCreatedCleanup=()=>this.editor.off("created-shapes",this._onShapesCreated)),this.shapeEditedCleanup||"shapes-updated"!==e||(this.editor.on("edited-shapes",this._onShapesEdited),this.shapeEditedCleanup=()=>this.editor.off("edited-shapes",this._onShapesEdited)),this.shapeDeletedCleanup||"shapes-deleted"!==e||(this.editor.on("deleted-shapes",this._onShapesDeleted),this.shapeDeletedCleanup=()=>this.editor.off("deleted-shapes",this._onShapesDeleted))}_maybeDetachLazyListeners(e){this.frameCleanup&&("frame"===e||"interaction-start"===e||"interaction-end"===e||"camera-start"===e||"camera-end"===e)&&!this._needsFrameListener()&&(this.frameCleanup(),this.frameCleanup=null),this.loafObserver&&("interaction-end"===e||"camera-end"===e)&&!this._needsLoafObserver()&&this._stopLoafObserver(),this.shapeCreatedCleanup&&"shapes-created"===e&&0===this.emitter.listenerCount("shapes-created")&&(this.shapeCreatedCleanup(),this.shapeCreatedCleanup=null),this.shapeEditedCleanup&&"shapes-updated"===e&&0===this.emitter.listenerCount("shapes-updated")&&(this.shapeEditedCleanup(),this.shapeEditedCleanup=null),this.shapeDeletedCleanup&&"shapes-deleted"===e&&0===this.emitter.listenerCount("shapes-deleted")&&(this.shapeDeletedCleanup(),this.shapeDeletedCleanup=null)}}a([r.oI],c.prototype,"_onFrame",1),a([r.oI],c.prototype,"_onShapesCreated",1),a([r.oI],c.prototype,"_onShapesEdited",1),a([r.oI],c.prototype,"_onShapesDeleted",1)}}]);