@moon-jam/excalidraw-tui 0.0.0-stage → 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +94 -2
- package/dist/THIRD_PARTY_LICENSES +3778 -0
- package/dist/cli.js +2860 -0
- package/dist/web/font-ranges.json +1 -0
- package/dist/web/fonts/Assistant/Assistant-Bold.woff2 +0 -0
- package/dist/web/fonts/Assistant/Assistant-Medium.woff2 +0 -0
- package/dist/web/fonts/Assistant/Assistant-Regular.woff2 +0 -0
- package/dist/web/fonts/Assistant/Assistant-SemiBold.woff2 +0 -0
- package/dist/web/fonts/Cascadia/CascadiaCode-Regular.woff2 +0 -0
- package/dist/web/fonts/ComicShanns/ComicShanns-Regular-279a7b317d12eb88de06167bd672b4b4.woff2 +0 -0
- package/dist/web/fonts/ComicShanns/ComicShanns-Regular-6e066e8de2ac57ea9283adb9c24d7f0c.woff2 +0 -0
- package/dist/web/fonts/ComicShanns/ComicShanns-Regular-dc6a8806fa96795d7b3be5026f989a17.woff2 +0 -0
- package/dist/web/fonts/ComicShanns/ComicShanns-Regular-fcb0fc02dcbee4c9846b3e2508668039.woff2 +0 -0
- package/dist/web/fonts/Excalifont/Excalifont-Regular-349fac6ca4700ffec595a7150a0d1e1d.woff2 +0 -0
- package/dist/web/fonts/Excalifont/Excalifont-Regular-3f2c5db56cc93c5a6873b1361d730c16.woff2 +0 -0
- package/dist/web/fonts/Excalifont/Excalifont-Regular-41b173a47b57366892116a575a43e2b6.woff2 +0 -0
- package/dist/web/fonts/Excalifont/Excalifont-Regular-623ccf21b21ef6b3a0d87738f77eb071.woff2 +0 -0
- package/dist/web/fonts/Excalifont/Excalifont-Regular-a88b72a24fb54c9f94e3b5fdaa7481c9.woff2 +0 -0
- package/dist/web/fonts/Excalifont/Excalifont-Regular-b9dcf9d2e50a1eaf42fc664b50a3fd0d.woff2 +0 -0
- package/dist/web/fonts/Excalifont/Excalifont-Regular-be310b9bcd4f1a43f571c46df7809174.woff2 +0 -0
- package/dist/web/fonts/Liberation/LiberationSans-Regular.woff2 +0 -0
- package/dist/web/fonts/Lilita/Lilita-Regular-i7dPIFZ9Zz-WBtRtedDbYE98RXi4EwSsbg.woff2 +0 -0
- package/dist/web/fonts/Lilita/Lilita-Regular-i7dPIFZ9Zz-WBtRtedDbYEF8RXi4EwQ.woff2 +0 -0
- package/dist/web/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTA3j6zbXWjgevT5.woff2 +0 -0
- package/dist/web/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTQ3j6zbXWjgeg.woff2 +0 -0
- package/dist/web/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTk3j6zbXWjgevT5.woff2 +0 -0
- package/dist/web/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTo3j6zbXWjgevT5.woff2 +0 -0
- package/dist/web/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTs3j6zbXWjgevT5.woff2 +0 -0
- package/dist/web/fonts/Virgil/Virgil-Regular.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-019d66dcad46dc156b162d267f981c20.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-04b718e5623574919c8b0dea5f301444.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-069e77aac84590e2e991d0a0176d34f2.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-06c77b8c66e51ed6c63ccb502dd8b8af.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-08e0dc436ad0ad61ba5558db0674d762.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-093b9ef39a46ceae95a1df18a0a3a326.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-095c169f3314805276f603a362766abd.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-09850c4077f3fffe707905872e0e2460.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-0986d134c05864f5025962eef9f994a0.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-0b5d723fdc4e249c140f0909e87d03b4.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-0f626226ba1272e832aea87bafd9720e.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-0f7fb1e0d5015bb1371343153ecf7ce3.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-0fa55a080fcd0f9dc2e0b0058b793df8.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-0facdf1ea213ba40261022f5d5ed4493.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-10a7ae9a371830a80c3d844acf1c02d7.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-112c051027b2d766c19a519f6ee1f4f7.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-11c345711937f0ba4b8f7b6b919c8440.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-12b52b58eb3df36804b9a654ec9ee194.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-13ae07ed2e272d26d59bc0691cd7117a.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-13d2887ec8ee73c43acdabc52a05af7b.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-145aa02cdd91946e67dc934e1acffe75.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-15dc6d811c9cd078f9086a740d5a1038.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-173945821411c09f70c95f98d590e697.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-1b611157cd46bb184d4fa4dae2d6a2b8.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-1e6fd68f1f3902ce48ce8c69df385622.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-1ee544f0f1dac422545c505baa788992.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-1fdc0c67ed57263a80fd108c1f6ccf24.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-203b0e569e3b14aac86a003dc3fa523e.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-20cc1bbf50e7efb442756cb605672c1f.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-20e7bf72fa05de9adf7dbcc7bf51dde6.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-21430ee05a1248901da8d0de08744d47.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-23686f7f29da6e8008c36dd3a80c83d6.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-23ad2d71b280f00b1363b95b7bea94eb.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-23f228f3999c01983860012330e4be08.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-24476a126f129212beb33f66853ea151.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-24a21c1e4449222e8d1898d69ff3a404.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-25b7f38e18f035f96cb5e547bd2bd08c.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-29cec36cd205b211da97acabaa62f055.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-2a26d20a23b00898ce82f09d2ee47c3f.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-2adbc89c11e65905393d3dfc468b9d5b.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-2b7441d46298788ac94e610ffcc709b6.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-2b77e8ebfb2367ab2662396a60e7d320.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-2cf96d082d35ea3d8106851223ad0d16.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-2d43040e86ff03ba677f6f9c04cd0805.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-2e33e8dc771ef5e1d9127d60a6b73679.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-33432927cd87d40cfe393c7482bf221f.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-353f33792a8f60dc69323ddf635a269e.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-36925dfe329a45086cbb7fc5c20d45ac.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-3717077e38f98d89eae729b6c14e56dc.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-3756e81d3e149cf6099163ee79944fec.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-395c35dd584b56b0789f58a0559beaf1.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-3c9de2ae0ea4bc91a510942dfa4be8d2.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-3cc70dbb64df5b21f1326cc24dee2195.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-3e1f8f654357353bf0e04ba5c34b5f7f.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-3e63ed8162808a9e425ed80a8bc79114.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-3eaa538115d76932653c21d8dc28f207.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-4095eb84ef3874e2600247bee0b04026.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-41521fade99856108931b4768b1b2648.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-450da755d5bcb70906e1295e559b9602.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-452225341522a7942f0f6aab1a5c91a3.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-4535823663ad81405188a528d8f2b1a2.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-4806e761d750087c2d734fc64596eaff.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-4a0fdb40036e87b40aa08dd30584cb85.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-4a38cc3e9cf104e69ba246d37f8cf135.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-4aca6a43e59aceee2166b0c7e4e85ef1.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-4bfaa8ffa64c5ee560aa2daba7c9cbd3.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-4dc6d5f188d5c96d44815cd1e81aa885.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-4ddc14ed3eb0c3e46364317dfc0144a3.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-4ee10ae43505e2e0bc62656ced49c0fa.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-4f50e5136e136527280bc902c5817561.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-51502f1206be09c565f1547c406e9558.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-51a0e808bbc8361236ac521a119758a3.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-52a84a22fd1369bffeaf21da2d6158dc.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-5330a2119a716e4e7224ed108b085dac.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-543fa46ace099a7099dad69123399400.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-544fc28abe2c5c30e62383fd4dac255f.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-54acdfc2166ad7fcbd074f75fd4a56ba.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-5572b3513ba8df57a3d5d7303ee6b11b.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-56467a5c8840c4d23a60b2f935114848.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-56a32a7689abd0326e57c10c6c069bb4.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-57862b464a55b18c7bf234ce22907d73.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-583d166e56ba0de4b77eabb47ef67839.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-5882ffa04f32584d26109137e2da4352.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-58fd02350d0bc52cf1ca3bb32ce9766e.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-5935a5775af3d5c6307ac667bd9ae74e.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-59e9ff77b0efaf684bc09274fb6908c9.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-5a1ce3117cfe90c48e8fb4a9a00f694d.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-5a45d991244d4c7140217e1e5f5ca4f4.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-5a7fac4b8b23a6e4e5ba0c9bf1756c91.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-5b0ed6971aaab9c8ad563230bd5471a7.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-5d2898fbc097a7e24c6f38d80587621e.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-603aefd23e350ba7eb124273e3c9bcf1.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-60a3089806700d379f11827ee9843b6b.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-60a41c7e1c68f22424e6d22df544bc82.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-642b26e2e5f5fb780b51b593dbc8c851.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-66493ba5a8367f2928812f446f47b56a.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-670ba603758d94268e8606f240a42e12.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-671a2c20b1eb9e4ef8a192833940e319.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-684d65f1793cac449dde5d59cb3c47fb.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-69c09cc5fa3e55c74fc4821f76909cc3.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-6ae5b42180ad70b971c91e7eefb8eba2.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-6e092f71c1e634059ada0e52abadce67.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-6f3256af8454371776bc46670d33cc65.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-6fe5c5973cc06f74b2387a631ea36b88.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-70c2eb8d64e71a42a834eb857ea9df51.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-70e811fd7994e61f408c923de6ddd078.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-7197d6fda6cba7c3874c53d6381ca239.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-72252d73220fa3cd856677888cee1635.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-72536a3d71b694a0d53dd90ddceae41e.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-726303e0774b4e678bff8c2deb6ca603.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-733171b4ffcd17ea1fe1c0ba627173bf.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-739bc1a567439c7cffcd1614644593d2.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-73e309718fd16cea44b4d54a33581811.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-7494dc504ae00ee9cd0505f990f88c5d.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-74e2263a91439c25b91d5132ce9f4d62.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-761d05e3cd968cf574166867998ef06a.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-7718fe60986d8b42b1be9c5ace5ccf25.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-774d4f764a1299da5d28ec2f2ffe0d69.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-79d494361ae093b69e74ee9dbe65bfd4.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-79f007c1c6d07557120982951ea67998.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-7a07ddc0f0c0f5f4a9bad6ee3dda66b5.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-7ab2bed91166a9dca83a5ebfbe2a7f38.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-7ccce86603f80a099ddb0cb21d4ae3e3.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-7e4bde7e9c7f84cd34d8a845e384c746.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-7e929f262f30c8ee78bf398150b1a7cd.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-7eb9fffd1aa890d07d0f88cc82e6cfe4.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-7f855356ab893b0d2b9c1c83b8116f0e.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-829615148e6357d826b9242eb7fbbd1e.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-866fa7613df6b3fd272bcfd4530c0bb9.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-87599f94b6cc129d505b375798d0d751.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-8c2f33cee3993174f7e87c28e4bf42ee.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-8d3bcabb847b56243b16afe62adaaf21.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-8de5b863cb50dfefdd07cb11c774d579.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-8e9f97f01034820170065b2921b4fb5e.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-8f476c4c99813d57cbe6eca4727388ad.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-903bb6865f3452e2fda42e3a25547bc5.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-91ddb2969bf2d31ba02ad82998d1314c.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-938d90c10ff8c20386af7f242c05d6b0.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-93fc8f28a33234bcadf1527cafabd502.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-95429962233afd82db1c27df1500a28c.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-9544732d2e62d1a429674f8ee41b5d3a.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-9592bfc861f07bcb8d75c196b370e548.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-95bfd249da4902577b4b7d76ebdd0b44.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-968cffdc8ee679da094e77ebf50f58ef.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-97f7f48ce90c9429bf32ae51469db74d.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-982b630266d87db93d2539affb1275c6.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-98f2ad84457de7f3740d9920b8fa8667.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-99a16ef6a64934d5781933dbd9c46b2e.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-9cfb2a77a4e45025105ad29a1748b90d.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-9d81066dd2b337c938df6e90380a00dc.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-9eb5a99df4e76ac3363453ac9ca288b1.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-a004ddfcb26e67bd6e678c8ed19e25ce.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-a0ca5df4258213d7fc9fce80f65ce760.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-a1f916d6039285c4ffb900cd654e418f.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-a203b91dad570bf05a58c3c3ddb529bf.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-a365e82ed54697a52f27adcea1315fe8.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-a4c34be6d42152e64b0df90bc4607f64.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-a7accba310e821da5505f71c03b76bdb.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-aa0d470430e6391eca720c7cfa44446f.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-aa5c9ca6cf4fba00433b7aa3fa10671a.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-ac9ceb44437becc3e9c4dbfebab7fc2d.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-b1220a3c61f85cc0408deedb4c5f57a2.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-b358f7a51ece39a3247942b1feabdb29.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-b57aaedfd8ebdf3931f25119dc6a5eb2.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-b5c1596551c256e0e9cf02028595b092.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-b6d128682ee29e471486354d486a1b90.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-b6fd38ca30869792244804b04bc058da.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-b7d203b051eff504ff59ddca7576b6a9.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-b96d9226ce77ec94ceca043d712182e6.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-ba3de316d63c7e339987b16f41a0b879.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-bafff7a14c27403dcc6cf1432e8ea836.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-bd77e3c7f9e0b072d96af37f73d1aa32.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-be549ab72f0719d606a5c01e2c0219b6.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-c16ed9740b85badf16e86ea782a3062f.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-c1f94158256bb1f3bf665b053d895af9.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-c40533fdf4cc57177b12803598af7e59.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-c4a687ac4f0c2766eefc9f77ed99cddf.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-c69f61a4ab18d0488c8d1fc12e7028e8.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-c8b71798409ccc126ee264a00aadcf21.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-c99eda15fc26a2941579560f76c3a5cf.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-cb17fc3db95f6d139afc9d31a8e93293.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-cbaaefaaf326668277aa24dfa93c4d28.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-cd145ce4a0ea18469358df53c207bc1b.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-cdbce89e82cc1ab53a2decbf5819278f.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-ce4884f96f11589608b76b726a755803.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-cf2cc71752631e579e35b0e423bf2638.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-cf6ff4e0f491ca0cf3038187a997b9b4.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-cfb211578629b7e8153b37240de6a9d5.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-d0cf73942fea1c74edbdf0b3011f4656.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-d2666cbed13462c5dc36fa2f15c202ca.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-d3716376641d615e2995605b29bca7b6.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-dac48066b5883d8b4551fc584f0c2a3e.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-dbea1af6dcd9860be40c3d18254338f5.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-e11567fd2accf9957cd0d3c2be937d87.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-e2ead7ea7da0437f085f42ffc05f8d13.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-e3fcf5180fd466c8915c4e8069491054.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-e480d9c614742d05f0e78f274f1e69e6.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-e4bca6cfa53e499cae0a6be4894a90e9.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-e51ef413167c6e14e0c0fdcc585f2fc9.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-e5f453bb04da18eed01675eeebd88bf8.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-e656f091b9dc4709722c9f4b84d3c797.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-ec181b795ac1fb5a50d700b6e996d745.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-ee8bae97908d5147b423f77ad0d3c1bb.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-f0f13b5c60e0af5553bd359f5513be1b.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-f2b54d4e7be0eaefe1c2c56836fa5368.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-f56414bf9bced67990def8660e306759.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-f5d079153c99a25b9be5b8583c4cc8a7.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-f6032fc06eb20480f096199713f70885.woff2 +0 -0
- package/dist/web/fonts/Xiaolai/Xiaolai-Regular-f8ee5d36068a42b51d0e4a1116cfcec1.woff2 +0 -0
- package/dist/web/main.js +732 -0
- package/package.json +56 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,2860 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { writeFileSync as writeFileSync4 } from "node:fs";
|
|
5
|
+
import module from "node:module";
|
|
6
|
+
import { dirname, join as join5 } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { parseArgs } from "node:util";
|
|
9
|
+
|
|
10
|
+
// src/app.ts
|
|
11
|
+
import { existsSync } from "node:fs";
|
|
12
|
+
import { basename } from "node:path";
|
|
13
|
+
|
|
14
|
+
// src/editor.ts
|
|
15
|
+
import { readFileSync as readFileSync2, renameSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { join as join3 } from "node:path";
|
|
17
|
+
import { setFlagsFromString } from "node:v8";
|
|
18
|
+
import { Script } from "node:vm";
|
|
19
|
+
|
|
20
|
+
// src/cache.ts
|
|
21
|
+
import { mkdirSync } from "node:fs";
|
|
22
|
+
import { homedir } from "node:os";
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
function cacheDir() {
|
|
25
|
+
const base = process.env.XDG_CACHE_HOME || join(homedir(), ...process.platform === "darwin" ? ["Library", "Caches"] : [".cache"]);
|
|
26
|
+
const dir = join(base, "excalidraw-tui");
|
|
27
|
+
try {
|
|
28
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
29
|
+
return dir;
|
|
30
|
+
} catch {
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/fonts.ts
|
|
36
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
37
|
+
import { join as join2 } from "node:path";
|
|
38
|
+
var registered = false;
|
|
39
|
+
var CHUNKS = /* @__PURE__ */ new Map();
|
|
40
|
+
var FAMILY_BY_FOLDER = {
|
|
41
|
+
Cascadia: "Cascadia",
|
|
42
|
+
ComicShanns: "Comic Shanns",
|
|
43
|
+
Excalifont: "Excalifont",
|
|
44
|
+
Liberation: "Liberation Sans",
|
|
45
|
+
Lilita: "Lilita One",
|
|
46
|
+
Nunito: "Nunito",
|
|
47
|
+
Virgil: "Virgil",
|
|
48
|
+
Xiaolai: "Xiaolai"
|
|
49
|
+
};
|
|
50
|
+
function registerFonts(canvas, dir) {
|
|
51
|
+
if (registered) return;
|
|
52
|
+
registered = true;
|
|
53
|
+
fonts = canvas.GlobalFonts;
|
|
54
|
+
const ranges = JSON.parse(
|
|
55
|
+
readFileSync(join2(dir, "..", "font-ranges.json"), "utf8")
|
|
56
|
+
);
|
|
57
|
+
for (const file of readdirSync(join2(dir, "Assistant"))) {
|
|
58
|
+
canvas.GlobalFonts.registerFromPath(join2(dir, "Assistant", file), "Assistant");
|
|
59
|
+
}
|
|
60
|
+
for (const [folder, family] of Object.entries(FAMILY_BY_FOLDER)) {
|
|
61
|
+
const names = readdirSync(join2(dir, folder)).map((file, index) => {
|
|
62
|
+
const name = `${family} ${index}`;
|
|
63
|
+
const range = ranges[`${folder}/${file}`];
|
|
64
|
+
if (range) pending.push({ name, path: join2(dir, folder, file), ranges: parseRange(range) });
|
|
65
|
+
else canvas.GlobalFonts.registerFromPath(join2(dir, folder, file), name);
|
|
66
|
+
return `"${name}"`;
|
|
67
|
+
});
|
|
68
|
+
CHUNKS.set(family, names.join(", "));
|
|
69
|
+
}
|
|
70
|
+
const liberation = CHUNKS.get("Liberation Sans");
|
|
71
|
+
if (!canvas.GlobalFonts.has("Helvetica") && liberation) CHUNKS.set("Helvetica", liberation);
|
|
72
|
+
}
|
|
73
|
+
var fonts;
|
|
74
|
+
var pending = [];
|
|
75
|
+
var checked = /* @__PURE__ */ new Set();
|
|
76
|
+
function parseRange(range) {
|
|
77
|
+
return range.split(",").map((part) => {
|
|
78
|
+
const [low = "", high = low] = part.trim().slice(2).split("-");
|
|
79
|
+
return [Number.parseInt(low, 16), Number.parseInt(high, 16)];
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function loadGlyphs(text) {
|
|
83
|
+
if (pending.length === 0) return;
|
|
84
|
+
for (const char of text) {
|
|
85
|
+
const code = char.codePointAt(0) ?? 0;
|
|
86
|
+
if (checked.has(code)) continue;
|
|
87
|
+
checked.add(code);
|
|
88
|
+
for (const font of pending.filter(
|
|
89
|
+
(f) => f.ranges.some(([lo, hi]) => code >= lo && code <= hi)
|
|
90
|
+
)) {
|
|
91
|
+
fonts.registerFromPath(font.path, font.name);
|
|
92
|
+
pending.splice(pending.indexOf(font), 1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
var expanded = /* @__PURE__ */ new Map();
|
|
97
|
+
function expandFont(font) {
|
|
98
|
+
let out = expanded.get(font);
|
|
99
|
+
if (out === void 0) {
|
|
100
|
+
out = font;
|
|
101
|
+
for (const [family, names] of CHUNKS) {
|
|
102
|
+
out = out.replace(new RegExp(`(?<=^|[\\s,])"?${family}"?(?=\\s*(,|$))`), names);
|
|
103
|
+
}
|
|
104
|
+
expanded.set(font, out);
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/frames.ts
|
|
110
|
+
function words(pixels) {
|
|
111
|
+
const aligned = pixels.byteOffset % 4 === 0 ? pixels : Buffer.from(pixels);
|
|
112
|
+
return new Uint32Array(aligned.buffer, aligned.byteOffset, aligned.byteLength / 4);
|
|
113
|
+
}
|
|
114
|
+
function changedRect(previous2, next2, width, height) {
|
|
115
|
+
const rowBytes = width * 4;
|
|
116
|
+
const rowDiffers = (y) => previous2.compare(next2, y * rowBytes, (y + 1) * rowBytes, y * rowBytes, (y + 1) * rowBytes) !== 0;
|
|
117
|
+
let top = 0;
|
|
118
|
+
while (top < height && !rowDiffers(top)) top++;
|
|
119
|
+
if (top === height) return void 0;
|
|
120
|
+
let bottom = height - 1;
|
|
121
|
+
while (!rowDiffers(bottom)) bottom--;
|
|
122
|
+
const before = words(previous2);
|
|
123
|
+
const after = words(next2);
|
|
124
|
+
let left = width;
|
|
125
|
+
let right = -1;
|
|
126
|
+
for (let y = top; y <= bottom; y++) {
|
|
127
|
+
const row = y * width;
|
|
128
|
+
for (let x = 0; x < left; x++) {
|
|
129
|
+
if (before[row + x] !== after[row + x]) {
|
|
130
|
+
left = x;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (let x = width - 1; x > right; x--) {
|
|
135
|
+
if (before[row + x] !== after[row + x]) {
|
|
136
|
+
right = x;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return { x: left, y: top, width: right - left + 1, height: bottom - top + 1 };
|
|
142
|
+
}
|
|
143
|
+
function crop(pixels, width, rect) {
|
|
144
|
+
const out = Buffer.allocUnsafe(rect.width * rect.height * 4);
|
|
145
|
+
const rowBytes = rect.width * 4;
|
|
146
|
+
for (let row = 0; row < rect.height; row++) {
|
|
147
|
+
const from = ((rect.y + row) * width + rect.x) * 4;
|
|
148
|
+
pixels.copy(out, row * rowBytes, from, from + rowBytes);
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/input.ts
|
|
154
|
+
var ESC = "\x1B";
|
|
155
|
+
function decodeMods(value) {
|
|
156
|
+
const bits = Math.max(0, value - 1);
|
|
157
|
+
return {
|
|
158
|
+
shift: (bits & 1) !== 0,
|
|
159
|
+
alt: (bits & 2) !== 0,
|
|
160
|
+
ctrl: (bits & 4) !== 0,
|
|
161
|
+
meta: (bits & (8 | 32)) !== 0
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
var LETTER_KEYS = {
|
|
165
|
+
A: "ArrowUp",
|
|
166
|
+
B: "ArrowDown",
|
|
167
|
+
C: "ArrowRight",
|
|
168
|
+
D: "ArrowLeft",
|
|
169
|
+
H: "Home",
|
|
170
|
+
F: "End",
|
|
171
|
+
P: "F1",
|
|
172
|
+
Q: "F2",
|
|
173
|
+
S: "F4"
|
|
174
|
+
};
|
|
175
|
+
var TILDE_KEYS = {
|
|
176
|
+
2: "Insert",
|
|
177
|
+
3: "Delete",
|
|
178
|
+
5: "PageUp",
|
|
179
|
+
6: "PageDown",
|
|
180
|
+
7: "Home",
|
|
181
|
+
8: "End",
|
|
182
|
+
11: "F1",
|
|
183
|
+
12: "F2",
|
|
184
|
+
13: "F3",
|
|
185
|
+
14: "F4",
|
|
186
|
+
15: "F5",
|
|
187
|
+
17: "F6",
|
|
188
|
+
18: "F7",
|
|
189
|
+
19: "F8",
|
|
190
|
+
20: "F9",
|
|
191
|
+
21: "F10",
|
|
192
|
+
23: "F11",
|
|
193
|
+
24: "F12"
|
|
194
|
+
};
|
|
195
|
+
var CODE_KEYS = {
|
|
196
|
+
9: "Tab",
|
|
197
|
+
13: "Enter",
|
|
198
|
+
27: "Escape",
|
|
199
|
+
32: "Space",
|
|
200
|
+
127: "Backspace",
|
|
201
|
+
57399: "0",
|
|
202
|
+
57400: "1",
|
|
203
|
+
57401: "2",
|
|
204
|
+
57402: "3",
|
|
205
|
+
57403: "4",
|
|
206
|
+
57404: "5",
|
|
207
|
+
57405: "6",
|
|
208
|
+
57406: "7",
|
|
209
|
+
57407: "8",
|
|
210
|
+
57408: "9",
|
|
211
|
+
57409: ".",
|
|
212
|
+
57410: "/",
|
|
213
|
+
57411: "*",
|
|
214
|
+
57412: "-",
|
|
215
|
+
57413: "+",
|
|
216
|
+
57414: "Enter",
|
|
217
|
+
57415: "=",
|
|
218
|
+
57441: "Shift",
|
|
219
|
+
57442: "Control",
|
|
220
|
+
57443: "Alt",
|
|
221
|
+
57444: "Meta",
|
|
222
|
+
57447: "Shift",
|
|
223
|
+
57448: "Control",
|
|
224
|
+
57449: "Alt",
|
|
225
|
+
57450: "Meta"
|
|
226
|
+
};
|
|
227
|
+
function keyFromCode(code) {
|
|
228
|
+
const named = CODE_KEYS[code];
|
|
229
|
+
if (named) return named;
|
|
230
|
+
if (code >= 57344 && code <= 63743) return void 0;
|
|
231
|
+
return String.fromCodePoint(code);
|
|
232
|
+
}
|
|
233
|
+
function keyEvent(key, modsField, text = "", held = /* @__PURE__ */ new Set()) {
|
|
234
|
+
const [modValue, eventType] = (modsField ?? "1").split(":");
|
|
235
|
+
const mods = decodeMods(Number(modValue) || 1);
|
|
236
|
+
if (eventType === "3") {
|
|
237
|
+
if (held.delete(key)) return { kind: "key", action: "up", key, text: "", mods };
|
|
238
|
+
return { kind: "key", action: "up", key, text: "", mods, swallowed: true };
|
|
239
|
+
}
|
|
240
|
+
held.add(key);
|
|
241
|
+
if (eventType === "2") return { kind: "key", action: "down", key, text, mods, repeat: true };
|
|
242
|
+
return { kind: "key", action: "down", key, text, mods };
|
|
243
|
+
}
|
|
244
|
+
function typesItself(key, text) {
|
|
245
|
+
const own = key === "Space" ? " " : [...key].length === 1 ? key : "";
|
|
246
|
+
return text === own || own !== "" && /^[\x20-\x7e]$/.test(text);
|
|
247
|
+
}
|
|
248
|
+
function parseCsi(params, final, held) {
|
|
249
|
+
if (final === "u") {
|
|
250
|
+
const [codes, modsField, textField] = params.split(";");
|
|
251
|
+
const code = Number((codes ?? "").split(":")[0]);
|
|
252
|
+
const text = textField ? String.fromCodePoint(...textField.split(":").map((c) => Number(c))) : "";
|
|
253
|
+
if (code === 0) return text ? { kind: "text", text, paste: false } : void 0;
|
|
254
|
+
const key = keyFromCode(code);
|
|
255
|
+
if (!key) return void 0;
|
|
256
|
+
if (text && !typesItself(key, text)) {
|
|
257
|
+
held.add(key);
|
|
258
|
+
return { kind: "text", text, paste: false };
|
|
259
|
+
}
|
|
260
|
+
return keyEvent(key, modsField, text, held);
|
|
261
|
+
}
|
|
262
|
+
if (final === "M" || final === "m") return parseMouse(params, final === "M");
|
|
263
|
+
if (final === "~") {
|
|
264
|
+
const [num, modsField] = params.split(";");
|
|
265
|
+
const key = TILDE_KEYS[Number(num)];
|
|
266
|
+
return key ? keyEvent(key, modsField, "", held) : void 0;
|
|
267
|
+
}
|
|
268
|
+
if (final === "t") {
|
|
269
|
+
const [kind, height, width] = params.split(";").map(Number);
|
|
270
|
+
if (kind === 4) return report({ type: "textArea", width: width ?? 0, height: height ?? 0 });
|
|
271
|
+
if (kind === 6) return report({ type: "cell", width: width ?? 0, height: height ?? 0 });
|
|
272
|
+
return void 0;
|
|
273
|
+
}
|
|
274
|
+
if (final === "c" && params.startsWith("?")) return report({ type: "deviceAttributes" });
|
|
275
|
+
const letter = LETTER_KEYS[final];
|
|
276
|
+
if (letter) return keyEvent(letter, params.split(";")[1], "", held);
|
|
277
|
+
return void 0;
|
|
278
|
+
}
|
|
279
|
+
function report(value) {
|
|
280
|
+
return { kind: "report", report: value };
|
|
281
|
+
}
|
|
282
|
+
function parseMouse(params, pressed) {
|
|
283
|
+
if (!params.startsWith("<")) return void 0;
|
|
284
|
+
const [b = 0, x = 1, y = 1] = params.slice(1).split(";").map(Number);
|
|
285
|
+
const mods = {
|
|
286
|
+
shift: (b & 4) !== 0,
|
|
287
|
+
alt: (b & 8) !== 0,
|
|
288
|
+
ctrl: (b & 16) !== 0,
|
|
289
|
+
meta: false
|
|
290
|
+
};
|
|
291
|
+
const px = x - 1;
|
|
292
|
+
const py = y - 1;
|
|
293
|
+
if (b & 64) {
|
|
294
|
+
const dir = b & 3;
|
|
295
|
+
return {
|
|
296
|
+
kind: "wheel",
|
|
297
|
+
dx: dir === 2 ? -1 : dir === 3 ? 1 : 0,
|
|
298
|
+
dy: dir === 0 ? -1 : dir === 1 ? 1 : 0,
|
|
299
|
+
x: px,
|
|
300
|
+
y: py,
|
|
301
|
+
mods
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
if (b & 32) return { kind: "mouse", action: "move", x: px, y: py, mods };
|
|
305
|
+
const button = ["left", "middle", "right"][b & 3];
|
|
306
|
+
if (!button) return { kind: "mouse", action: "up", button: "left", x: px, y: py, mods };
|
|
307
|
+
return { kind: "mouse", action: pressed ? "down" : "up", button, x: px, y: py, mods };
|
|
308
|
+
}
|
|
309
|
+
function parseLuminance(value) {
|
|
310
|
+
const match = /^rgb:([0-9a-f]+)\/([0-9a-f]+)\/([0-9a-f]+)$/i.exec(value);
|
|
311
|
+
if (!match) return void 0;
|
|
312
|
+
const [r, g, b] = match.slice(1).map((hex) => Number.parseInt(hex, 16) / (16 ** hex.length - 1));
|
|
313
|
+
return 0.2126 * (r ?? 0) + 0.7152 * (g ?? 0) + 0.0722 * (b ?? 0);
|
|
314
|
+
}
|
|
315
|
+
var PASTE_START = `${ESC}[200~`;
|
|
316
|
+
var PASTE_END = `${ESC}[201~`;
|
|
317
|
+
var InputParser = class {
|
|
318
|
+
buffer = "";
|
|
319
|
+
held = /* @__PURE__ */ new Set();
|
|
320
|
+
feed(chunk) {
|
|
321
|
+
this.buffer += chunk;
|
|
322
|
+
const events = [];
|
|
323
|
+
let i = 0;
|
|
324
|
+
while (i < this.buffer.length) {
|
|
325
|
+
const rest = this.buffer.slice(i);
|
|
326
|
+
if (rest.startsWith(PASTE_START)) {
|
|
327
|
+
const end = rest.indexOf(PASTE_END);
|
|
328
|
+
if (end === -1) break;
|
|
329
|
+
events.push({ kind: "text", text: rest.slice(PASTE_START.length, end), paste: true });
|
|
330
|
+
i += end + PASTE_END.length;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (rest.startsWith(`${ESC}]`)) {
|
|
334
|
+
const bel = rest.indexOf("\x07");
|
|
335
|
+
const st = rest.indexOf(`${ESC}\\`);
|
|
336
|
+
const ends = [bel, st].filter((at) => at > 0);
|
|
337
|
+
if (ends.length === 0) break;
|
|
338
|
+
const end = Math.min(...ends);
|
|
339
|
+
const body = rest.slice(2, end);
|
|
340
|
+
const separator = body.indexOf(";");
|
|
341
|
+
if (body.slice(0, separator) === "11") {
|
|
342
|
+
const luminance = parseLuminance(body.slice(separator + 1));
|
|
343
|
+
if (luminance !== void 0) events.push(report({ type: "background", luminance }));
|
|
344
|
+
}
|
|
345
|
+
i += end + (end === st ? 2 : 1);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (rest.startsWith(`${ESC}_G`)) {
|
|
349
|
+
const end = rest.indexOf(`${ESC}\\`);
|
|
350
|
+
if (end === -1) break;
|
|
351
|
+
const body = rest.slice(3, end);
|
|
352
|
+
events.push(report({ type: "graphics", ok: body.split(";")[1] === "OK" }));
|
|
353
|
+
i += end + 2;
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
if (rest.startsWith(`${ESC}[`)) {
|
|
357
|
+
const body = rest.slice(2);
|
|
358
|
+
const match = /^([0-9:;<?]*)([A-Za-z~])/.exec(body);
|
|
359
|
+
if (!match) {
|
|
360
|
+
if (/^[0-9:;<?]*$/.test(body)) break;
|
|
361
|
+
i += 2;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const event = parseCsi(match[1] ?? "", match[2] ?? "", this.held);
|
|
365
|
+
if (event) events.push(event);
|
|
366
|
+
i += 2 + match[0].length;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (rest === ESC) break;
|
|
370
|
+
const next2 = rest.indexOf(ESC, 1);
|
|
371
|
+
const text = next2 === -1 ? rest : rest.slice(0, next2);
|
|
372
|
+
if (rest.startsWith(ESC)) {
|
|
373
|
+
i += 1;
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
events.push({ kind: "text", text, paste: false });
|
|
377
|
+
i += text.length;
|
|
378
|
+
}
|
|
379
|
+
this.buffer = this.buffer.slice(i);
|
|
380
|
+
return events;
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
function isShortcut(event, key) {
|
|
384
|
+
return event.kind === "key" && (event.action === "down" && !event.repeat || event.swallowed === true) && event.key.toLowerCase() === key && (event.mods.ctrl || event.mods.meta);
|
|
385
|
+
}
|
|
386
|
+
function countPress(last, event, at, slop) {
|
|
387
|
+
const repeated = last.button === event.button && at - last.at < 500 && Math.abs(last.x - event.x) <= slop && Math.abs(last.y - event.y) <= slop;
|
|
388
|
+
return { button: event.button, x: event.x, y: event.y, at, count: repeated ? last.count + 1 : 1 };
|
|
389
|
+
}
|
|
390
|
+
function takeNext(queue) {
|
|
391
|
+
const stale = (event2) => event2?.kind === "mouse" && event2.action === "move";
|
|
392
|
+
let event = queue.shift();
|
|
393
|
+
while (stale(event) && stale(queue[0])) event = queue.shift();
|
|
394
|
+
return event;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/ui.ts
|
|
398
|
+
var THEMES = {
|
|
399
|
+
light: {
|
|
400
|
+
island: "#ffffff",
|
|
401
|
+
// --island-bg-color
|
|
402
|
+
text: "#1b1b1f",
|
|
403
|
+
// --color-on-surface
|
|
404
|
+
muted: "#b8b8b8",
|
|
405
|
+
// --color-gray-40
|
|
406
|
+
disabled: "#b8b8b8",
|
|
407
|
+
// --color-disabled
|
|
408
|
+
button: "#f2f2f7",
|
|
409
|
+
// --button-bg in the properties panel: --color-surface-mid
|
|
410
|
+
hover: "#f1f0ff",
|
|
411
|
+
// --button-hover-bg
|
|
412
|
+
selected: "#e0dfff",
|
|
413
|
+
// --color-surface-primary-container
|
|
414
|
+
onSelected: "#030064",
|
|
415
|
+
// --color-on-primary-container
|
|
416
|
+
footer: "#ececf4",
|
|
417
|
+
// --color-surface-low
|
|
418
|
+
divider: "#f1f0ff",
|
|
419
|
+
// --default-border-color
|
|
420
|
+
swatchBorder: "#d6d6d6",
|
|
421
|
+
// --color-gray-30
|
|
422
|
+
swatchActive: "#4a47b1",
|
|
423
|
+
// --color-primary-darkest
|
|
424
|
+
track: "hsl(240, 100%, 90%)",
|
|
425
|
+
// --color-slider-track
|
|
426
|
+
thumb: "#3d3d3d",
|
|
427
|
+
// --color-slider-thumb
|
|
428
|
+
menu: "#f1f3f5",
|
|
429
|
+
// --popup-secondary-bg-color
|
|
430
|
+
menuText: "#000000",
|
|
431
|
+
menuBorder: "#adb5bd",
|
|
432
|
+
// --button-gray-3
|
|
433
|
+
menuSeparator: "#adb5bd",
|
|
434
|
+
menuHover: "#339af0",
|
|
435
|
+
// --select-highlight-color
|
|
436
|
+
menuHoverText: "#ffffff",
|
|
437
|
+
// --popup-bg-color
|
|
438
|
+
input: "#ffffff",
|
|
439
|
+
// --input-bg-color
|
|
440
|
+
primary: "#6965db",
|
|
441
|
+
// --color-primary
|
|
442
|
+
listSelected: "#e3e2fe",
|
|
443
|
+
// --color-primary-light
|
|
444
|
+
dialogBorder: "#ebebeb",
|
|
445
|
+
// --dialog-border-color: --color-gray-20
|
|
446
|
+
filter: void 0
|
|
447
|
+
},
|
|
448
|
+
dark: {
|
|
449
|
+
island: "#232329",
|
|
450
|
+
text: "#e3e3e8",
|
|
451
|
+
muted: "#7a7a7a",
|
|
452
|
+
// --color-gray-60
|
|
453
|
+
disabled: "#5c5c5c",
|
|
454
|
+
button: "#31303b",
|
|
455
|
+
// --color-surface-high
|
|
456
|
+
hover: "#363541",
|
|
457
|
+
selected: "#403e6a",
|
|
458
|
+
onSelected: "#e0dfff",
|
|
459
|
+
footer: "#232329",
|
|
460
|
+
divider: "#31303b",
|
|
461
|
+
swatchBorder: "#d6d6d6",
|
|
462
|
+
swatchActive: "#4a47b1",
|
|
463
|
+
track: "hsl(244, 23%, 39%)",
|
|
464
|
+
thumb: "#3d3d3d",
|
|
465
|
+
menu: "#222222",
|
|
466
|
+
menuText: "#ced4da",
|
|
467
|
+
// --popup-text-color in the dark theme
|
|
468
|
+
menuBorder: "#222222",
|
|
469
|
+
menuSeparator: "#adb5bd",
|
|
470
|
+
menuHover: "#339af0",
|
|
471
|
+
menuHoverText: "#232329",
|
|
472
|
+
input: "#121212",
|
|
473
|
+
primary: "#a8a5ff",
|
|
474
|
+
listSelected: "#4f4d6f",
|
|
475
|
+
dialogBorder: "#3d3d3d",
|
|
476
|
+
// --color-gray-80
|
|
477
|
+
filter: "invert(93%) hue-rotate(180deg)"
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
var FONT = "Assistant";
|
|
481
|
+
var ISLAND_SHADOW = [
|
|
482
|
+
{ y: 0, blur: 0.931, color: "rgba(0, 0, 0, 0.17)" },
|
|
483
|
+
{ y: 0, blur: 3.127, color: "rgba(0, 0, 0, 0.08)" },
|
|
484
|
+
{ y: 7, blur: 14, color: "rgba(0, 0, 0, 0.05)" }
|
|
485
|
+
];
|
|
486
|
+
var MENU_SHADOW = [{ y: 3, blur: 10, color: "rgba(0, 0, 0, 0.2)" }];
|
|
487
|
+
var TOOLS = [
|
|
488
|
+
"hand",
|
|
489
|
+
"selection",
|
|
490
|
+
"rectangle",
|
|
491
|
+
"diamond",
|
|
492
|
+
"ellipse",
|
|
493
|
+
"arrow",
|
|
494
|
+
"line",
|
|
495
|
+
"freedraw",
|
|
496
|
+
"text",
|
|
497
|
+
"eraser"
|
|
498
|
+
];
|
|
499
|
+
var HIDDEN_MENU_ITEMS = /* @__PURE__ */ new Set(["copyAsPng", "copyAsSvg", "addToLibrary"]);
|
|
500
|
+
var Overlay = class {
|
|
501
|
+
menuAt = { x: 0, y: 0 };
|
|
502
|
+
items = [];
|
|
503
|
+
stale = true;
|
|
504
|
+
hovered;
|
|
505
|
+
panelScroll = 0;
|
|
506
|
+
panelOverflow = 0;
|
|
507
|
+
listScroll = 0;
|
|
508
|
+
listOverflow = 0;
|
|
509
|
+
helpScroll = 0;
|
|
510
|
+
helpOverflow = 0;
|
|
511
|
+
icons = /* @__PURE__ */ new Map();
|
|
512
|
+
window;
|
|
513
|
+
size;
|
|
514
|
+
theme;
|
|
515
|
+
measure;
|
|
516
|
+
layer;
|
|
517
|
+
layerDrawn = false;
|
|
518
|
+
// What the layer shows, to skip repainting when Excalidraw's HTML changed but the controls
|
|
519
|
+
// look the same, as at the start of every drag.
|
|
520
|
+
drawnSignature = "";
|
|
521
|
+
Image;
|
|
522
|
+
constructor(window, size, dark, canvas) {
|
|
523
|
+
this.window = window;
|
|
524
|
+
this.size = size;
|
|
525
|
+
this.theme = dark ? THEMES.dark : THEMES.light;
|
|
526
|
+
this.Image = canvas.Image;
|
|
527
|
+
this.layer = canvas.layer;
|
|
528
|
+
this.measure = canvas.layer.getContext("2d");
|
|
529
|
+
}
|
|
530
|
+
invalidate() {
|
|
531
|
+
this.stale = true;
|
|
532
|
+
}
|
|
533
|
+
forgetPainted() {
|
|
534
|
+
this.stale = true;
|
|
535
|
+
this.drawnSignature = "";
|
|
536
|
+
}
|
|
537
|
+
layout() {
|
|
538
|
+
if (!this.stale) return this.items;
|
|
539
|
+
this.stale = false;
|
|
540
|
+
this.layerDrawn = false;
|
|
541
|
+
const document = this.window.document;
|
|
542
|
+
const { width, height } = this.size;
|
|
543
|
+
const placed = [
|
|
544
|
+
...this.toolbar(document, width),
|
|
545
|
+
...this.panel(document, height),
|
|
546
|
+
...this.footer(document, height)
|
|
547
|
+
];
|
|
548
|
+
this.items = [
|
|
549
|
+
...placed,
|
|
550
|
+
...this.popover(document, placed, height),
|
|
551
|
+
...this.contextMenu(document, width, height),
|
|
552
|
+
...this.eyeDropper(document),
|
|
553
|
+
...this.helpDialog(document, width, height)
|
|
554
|
+
];
|
|
555
|
+
return this.items;
|
|
556
|
+
}
|
|
557
|
+
elementAt(x, y) {
|
|
558
|
+
const items = this.layout();
|
|
559
|
+
for (let index = items.length - 1; index >= 0; index--) {
|
|
560
|
+
const item = items[index];
|
|
561
|
+
if (item?.element && inside(item.box, x, y) && (!item.clip || inside(item.clip, x, y))) {
|
|
562
|
+
return item.element;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return void 0;
|
|
566
|
+
}
|
|
567
|
+
boxOf(element) {
|
|
568
|
+
return this.layout().find((item) => item.element === element)?.box;
|
|
569
|
+
}
|
|
570
|
+
hover(x, y) {
|
|
571
|
+
const element = this.elementAt(x, y);
|
|
572
|
+
if (element === this.hovered) return false;
|
|
573
|
+
this.hovered = element;
|
|
574
|
+
this.stale = true;
|
|
575
|
+
return true;
|
|
576
|
+
}
|
|
577
|
+
scroll(x, y, dy) {
|
|
578
|
+
if (this.window.document.querySelector(".HelpDialog")) {
|
|
579
|
+
this.helpScroll = Math.max(0, Math.min(this.helpOverflow, this.helpScroll + dy));
|
|
580
|
+
this.stale = true;
|
|
581
|
+
return true;
|
|
582
|
+
}
|
|
583
|
+
const list = this.layout().find(
|
|
584
|
+
(item) => item.element?.classList.contains("ScrollableList__wrapper")
|
|
585
|
+
);
|
|
586
|
+
if (list && inside(list.box, x, y)) {
|
|
587
|
+
this.listScroll = Math.max(0, Math.min(this.listOverflow, this.listScroll + dy));
|
|
588
|
+
this.stale = true;
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
591
|
+
const panel = this.layout().find((item) => item.element?.classList.contains("App-menu__left"));
|
|
592
|
+
if (!panel || !inside(panel.box, x, y)) return this.elementAt(x, y) !== void 0;
|
|
593
|
+
this.panelScroll = Math.max(0, Math.min(this.panelOverflow, this.panelScroll + dy));
|
|
594
|
+
this.stale = true;
|
|
595
|
+
return true;
|
|
596
|
+
}
|
|
597
|
+
render(scale) {
|
|
598
|
+
const items = this.layout();
|
|
599
|
+
const width = Math.round(this.size.width * scale);
|
|
600
|
+
const height = Math.round(this.size.height * scale);
|
|
601
|
+
if (this.layerDrawn && this.layer.width === width && this.layer.height === height) {
|
|
602
|
+
return void 0;
|
|
603
|
+
}
|
|
604
|
+
this.layerDrawn = true;
|
|
605
|
+
const signature = JSON.stringify([
|
|
606
|
+
width,
|
|
607
|
+
height,
|
|
608
|
+
items.map((item) => ({
|
|
609
|
+
...item,
|
|
610
|
+
element: void 0,
|
|
611
|
+
hovered: item.element !== void 0 && item.element === this.hovered,
|
|
612
|
+
icon: item.icon && { ...item.icon, svg: item.icon.svg.outerHTML }
|
|
613
|
+
}))
|
|
614
|
+
]);
|
|
615
|
+
if (signature === this.drawnSignature) return void 0;
|
|
616
|
+
this.drawnSignature = signature;
|
|
617
|
+
Object.assign(this.layer, { width, height });
|
|
618
|
+
const layer = this.layer.getContext("2d");
|
|
619
|
+
layer.clearRect(0, 0, width, height);
|
|
620
|
+
for (const item of items) this.paint(layer, item, scale);
|
|
621
|
+
return this.layer;
|
|
622
|
+
}
|
|
623
|
+
paint(context, item, scale) {
|
|
624
|
+
const { box } = item;
|
|
625
|
+
context.save();
|
|
626
|
+
context.setTransform(scale, 0, 0, scale, 0, 0);
|
|
627
|
+
if (item.clip) {
|
|
628
|
+
context.beginPath();
|
|
629
|
+
context.rect(item.clip.x, item.clip.y, item.clip.width, item.clip.height);
|
|
630
|
+
context.clip();
|
|
631
|
+
}
|
|
632
|
+
if (item.filter) context.filter = item.filter;
|
|
633
|
+
const fill = item.hover && this.hovered === item.element ? item.hover : item.fill;
|
|
634
|
+
const shape = () => {
|
|
635
|
+
context.beginPath();
|
|
636
|
+
if (item.arrow) {
|
|
637
|
+
context.moveTo(box.x + box.width, box.y);
|
|
638
|
+
context.lineTo(box.x, box.y + box.height / 2);
|
|
639
|
+
context.lineTo(box.x + box.width, box.y + box.height);
|
|
640
|
+
context.closePath();
|
|
641
|
+
} else {
|
|
642
|
+
context.roundRect(box.x, box.y, box.width, box.height, item.radius ?? 0);
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
for (const shadow of item.shadows ?? []) {
|
|
646
|
+
context.shadowColor = shadow.color;
|
|
647
|
+
context.shadowBlur = shadow.blur * scale;
|
|
648
|
+
context.shadowOffsetY = shadow.y * scale;
|
|
649
|
+
context.fillStyle = fill ?? "#000";
|
|
650
|
+
shape();
|
|
651
|
+
context.fill();
|
|
652
|
+
}
|
|
653
|
+
context.shadowColor = "transparent";
|
|
654
|
+
if (fill) {
|
|
655
|
+
context.fillStyle = fill;
|
|
656
|
+
shape();
|
|
657
|
+
context.fill();
|
|
658
|
+
}
|
|
659
|
+
if (item.checker) {
|
|
660
|
+
context.save();
|
|
661
|
+
shape();
|
|
662
|
+
context.clip();
|
|
663
|
+
context.fillStyle = "rgba(0, 0, 0, 0.08)";
|
|
664
|
+
const left = box.x + 1;
|
|
665
|
+
const top = box.y + 1 + (box.height - 2 - 16) / 2;
|
|
666
|
+
for (let y = top - 16; y < box.y + box.height; y += 8) {
|
|
667
|
+
for (let x = left; x < box.x + box.width; x += 8) {
|
|
668
|
+
if ((Math.round((x - left) / 8) + Math.round((y - top) / 8)) % 2 === 0) {
|
|
669
|
+
context.fillRect(x, y, 8, 8);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
context.restore();
|
|
674
|
+
}
|
|
675
|
+
if (item.border) {
|
|
676
|
+
context.strokeStyle = item.border;
|
|
677
|
+
context.lineWidth = 1;
|
|
678
|
+
context.beginPath();
|
|
679
|
+
context.roundRect(box.x + 0.5, box.y + 0.5, box.width - 1, box.height - 1, item.radius ?? 0);
|
|
680
|
+
context.stroke();
|
|
681
|
+
}
|
|
682
|
+
if (item.icon) {
|
|
683
|
+
const { size } = item.icon;
|
|
684
|
+
const image = this.raster(item.icon, scale);
|
|
685
|
+
if (image) {
|
|
686
|
+
const x = box.x + (box.width - size) / 2;
|
|
687
|
+
const y = box.y + (box.height - size) / 2;
|
|
688
|
+
context.drawImage(image, x, y, size, size);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
if (item.label) {
|
|
692
|
+
const { label } = item;
|
|
693
|
+
context.font = expandFont(label.font);
|
|
694
|
+
context.fillStyle = label.color;
|
|
695
|
+
context.textAlign = label.align ?? "left";
|
|
696
|
+
context.textBaseline = "alphabetic";
|
|
697
|
+
loadGlyphs(label.value);
|
|
698
|
+
context.fillText(label.value, label.x, label.y);
|
|
699
|
+
}
|
|
700
|
+
context.restore();
|
|
701
|
+
}
|
|
702
|
+
// Excalidraw's icons are inline SVG that take their color from CSS, so set it on the SVG.
|
|
703
|
+
raster(icon, scale) {
|
|
704
|
+
const pixels = Math.round(icon.size * scale);
|
|
705
|
+
const markup = icon.svg.outerHTML;
|
|
706
|
+
const key = `${icon.color} ${icon.fill} ${pixels} ${markup}`;
|
|
707
|
+
let image = this.icons.get(key);
|
|
708
|
+
if (!image) {
|
|
709
|
+
const svg = icon.svg.cloneNode(true);
|
|
710
|
+
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
|
711
|
+
svg.setAttribute("width", `${pixels}`);
|
|
712
|
+
svg.setAttribute("height", `${pixels}`);
|
|
713
|
+
svg.setAttribute("color", icon.color);
|
|
714
|
+
if (icon.fill) svg.setAttribute("fill", icon.fill);
|
|
715
|
+
const rotate = /rotate\((-?\d+)deg\)/.exec(svg.getAttribute("style") ?? "")?.[1];
|
|
716
|
+
svg.removeAttribute("style");
|
|
717
|
+
const source = rotate ? svg.outerHTML.replace(/>/, `><g transform="rotate(${rotate} ${viewCenter(svg)})">`).replace(/<\/svg>$/, "</g></svg>") : svg.outerHTML;
|
|
718
|
+
image = new this.Image();
|
|
719
|
+
image.src = Buffer.from(source);
|
|
720
|
+
this.icons.set(key, image);
|
|
721
|
+
}
|
|
722
|
+
return image.width ? image : void 0;
|
|
723
|
+
}
|
|
724
|
+
text(value, font) {
|
|
725
|
+
this.measure.font = expandFont(font);
|
|
726
|
+
loadGlyphs(value);
|
|
727
|
+
return this.measure.measureText(value).width;
|
|
728
|
+
}
|
|
729
|
+
toolbar(document, width) {
|
|
730
|
+
const bar = document.querySelector(".App-toolbar");
|
|
731
|
+
if (!bar) return [];
|
|
732
|
+
const t = this.theme;
|
|
733
|
+
const tool = (testId) => bar.querySelector(`[data-testid="toolbar-${testId}"]`)?.closest("label") ?? void 0;
|
|
734
|
+
const lock = tool("lock");
|
|
735
|
+
const tools = TOOLS.map(tool).filter((label) => label !== void 0);
|
|
736
|
+
const islandWidth = 4 + 36 + 4 + 9 + 4 + tools.length * 40 - 4 + 4;
|
|
737
|
+
const left = Math.round((width - islandWidth) / 2);
|
|
738
|
+
const items = [
|
|
739
|
+
{
|
|
740
|
+
box: { x: left, y: 16, width: islandWidth, height: 44 },
|
|
741
|
+
element: bar,
|
|
742
|
+
fill: t.island,
|
|
743
|
+
radius: 8,
|
|
744
|
+
shadows: ISLAND_SHADOW
|
|
745
|
+
}
|
|
746
|
+
];
|
|
747
|
+
const button = (label, x2) => {
|
|
748
|
+
const input = label.querySelector("input");
|
|
749
|
+
const checked2 = input?.checked ?? false;
|
|
750
|
+
const svg = label.querySelector("svg");
|
|
751
|
+
const box = { x: x2, y: 20, width: 36, height: 36 };
|
|
752
|
+
const color = checked2 ? t.onSelected : t.text;
|
|
753
|
+
items.push({
|
|
754
|
+
box,
|
|
755
|
+
element: label,
|
|
756
|
+
fill: checked2 ? t.selected : void 0,
|
|
757
|
+
hover: checked2 ? t.selected : t.hover,
|
|
758
|
+
radius: 8,
|
|
759
|
+
icon: svg ? {
|
|
760
|
+
svg,
|
|
761
|
+
color,
|
|
762
|
+
// Excalidraw fills the shape icons of the active tool.
|
|
763
|
+
fill: checked2 && label.classList.contains("fillable") ? color : void 0,
|
|
764
|
+
size: 16
|
|
765
|
+
} : void 0
|
|
766
|
+
});
|
|
767
|
+
const key = input?.getAttribute("aria-keyshortcuts")?.split(" ")[0]?.toUpperCase();
|
|
768
|
+
if (key && /^[A-Z]$/.test(key)) {
|
|
769
|
+
items.push({
|
|
770
|
+
box: { x: x2 + 24, y: 39, width: 8, height: 13 },
|
|
771
|
+
element: label,
|
|
772
|
+
label: {
|
|
773
|
+
value: key,
|
|
774
|
+
font: `10px ${FONT}`,
|
|
775
|
+
color: checked2 ? t.onSelected : t.muted,
|
|
776
|
+
x: x2 + 32 - this.text(key, `10px ${FONT}`),
|
|
777
|
+
y: 49
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
let x = left + 4;
|
|
783
|
+
if (lock) button(lock, x);
|
|
784
|
+
x += 40;
|
|
785
|
+
items.push({ box: { x, y: 26, width: 1, height: 24 }, fill: t.divider, element: bar });
|
|
786
|
+
x += 9;
|
|
787
|
+
for (const label of tools) {
|
|
788
|
+
button(label, x);
|
|
789
|
+
x += 40;
|
|
790
|
+
}
|
|
791
|
+
const hint = bar.querySelector(".HintViewer")?.textContent?.trim();
|
|
792
|
+
if (hint) {
|
|
793
|
+
const font = `12px ${FONT}`;
|
|
794
|
+
const lines = wrap(hint, islandWidth - 8, (line) => this.text(line, font));
|
|
795
|
+
for (const [index, line] of lines.entries()) {
|
|
796
|
+
items.push({
|
|
797
|
+
box: { x: left, y: 68 + index * 15, width: 0, height: 0 },
|
|
798
|
+
label: {
|
|
799
|
+
value: line,
|
|
800
|
+
font,
|
|
801
|
+
color: t.muted,
|
|
802
|
+
x: left + islandWidth / 2,
|
|
803
|
+
y: 68 + 4 + 12 + index * 15,
|
|
804
|
+
align: "center"
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
return items;
|
|
810
|
+
}
|
|
811
|
+
panel(document, height) {
|
|
812
|
+
const panel = document.querySelector(".App-menu__left");
|
|
813
|
+
const column = panel?.querySelector(".panelColumn");
|
|
814
|
+
if (!panel || !column) return [];
|
|
815
|
+
const t = this.theme;
|
|
816
|
+
const top = 76;
|
|
817
|
+
const maxHeight = Math.max(0, height - 166);
|
|
818
|
+
const items = [];
|
|
819
|
+
const left = 28;
|
|
820
|
+
let y = 0;
|
|
821
|
+
const heading = (text) => {
|
|
822
|
+
items.push({
|
|
823
|
+
box: { x: left, y, width: 176, height: 15 },
|
|
824
|
+
label: { value: text, font: `12px ${FONT}`, color: t.text, x: left, y: y + 12 }
|
|
825
|
+
});
|
|
826
|
+
y += 19;
|
|
827
|
+
};
|
|
828
|
+
const buttons = (list) => {
|
|
829
|
+
y += 4;
|
|
830
|
+
let x = left;
|
|
831
|
+
for (const button of list.querySelectorAll(
|
|
832
|
+
":scope > button, :scope > label, :scope > div > button"
|
|
833
|
+
)) {
|
|
834
|
+
if (button.hasAttribute("hidden")) continue;
|
|
835
|
+
if (x + 32 > left + 176) {
|
|
836
|
+
x = left;
|
|
837
|
+
y += 40;
|
|
838
|
+
}
|
|
839
|
+
const active = button.classList.contains("active");
|
|
840
|
+
const svg = button.querySelector("svg");
|
|
841
|
+
items.push({
|
|
842
|
+
box: { x, y, width: 32, height: 32 },
|
|
843
|
+
element: button,
|
|
844
|
+
fill: active ? t.selected : t.button,
|
|
845
|
+
hover: active ? t.selected : t.hover,
|
|
846
|
+
radius: 8,
|
|
847
|
+
icon: svg ? { svg, color: active ? t.onSelected : t.text, size: 16 } : void 0
|
|
848
|
+
});
|
|
849
|
+
x += 40;
|
|
850
|
+
}
|
|
851
|
+
const trigger = list.parentElement?.querySelector(":scope > div > button.properties-trigger");
|
|
852
|
+
if (trigger) {
|
|
853
|
+
const svg = trigger.querySelector("svg");
|
|
854
|
+
items.push({ box: { x: left + 119.5, y: y + 8, width: 1, height: 16 }, fill: t.divider });
|
|
855
|
+
items.push({
|
|
856
|
+
box: { x: left + 128, y, width: 32, height: 32 },
|
|
857
|
+
element: trigger,
|
|
858
|
+
fill: t.divider,
|
|
859
|
+
hover: t.hover,
|
|
860
|
+
radius: 8,
|
|
861
|
+
icon: svg ? { svg, color: t.text, size: 16 } : void 0
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
y += 36;
|
|
865
|
+
};
|
|
866
|
+
for (const row of column.children) {
|
|
867
|
+
if (row.querySelector(":scope > h3") && row.querySelector(".color-picker-container")) {
|
|
868
|
+
heading(row.querySelector("h3")?.textContent ?? "");
|
|
869
|
+
const picks = [...row.querySelectorAll(".color-picker__top-picks button")];
|
|
870
|
+
y += 4;
|
|
871
|
+
for (const [index, pick] of picks.entries()) {
|
|
872
|
+
items.push(...this.swatch(pick, left + index * 27.1, y + 2.2, 21.59));
|
|
873
|
+
}
|
|
874
|
+
items.push({
|
|
875
|
+
box: { x: left + 140, y: y + 5, width: 1, height: 16 },
|
|
876
|
+
fill: t.divider
|
|
877
|
+
});
|
|
878
|
+
const trigger = row.querySelector(".active-color");
|
|
879
|
+
if (trigger) items.push(...this.swatch(trigger, left + 150, y, 26, 5));
|
|
880
|
+
y += 30;
|
|
881
|
+
} else if (row.matches("fieldset")) {
|
|
882
|
+
heading(row.querySelector("legend")?.textContent ?? "");
|
|
883
|
+
const list = row.querySelector(".buttonList");
|
|
884
|
+
if (list) buttons(list);
|
|
885
|
+
} else if (row.matches("label.control-label")) {
|
|
886
|
+
const range = row.querySelector("input[type=range]");
|
|
887
|
+
heading(row.firstChild?.textContent ?? "");
|
|
888
|
+
if (range) items.push(...this.slider(range, left, y));
|
|
889
|
+
y += 48;
|
|
890
|
+
}
|
|
891
|
+
y += 12;
|
|
892
|
+
}
|
|
893
|
+
const contentHeight = y - 12 + 24;
|
|
894
|
+
const panelHeight = Math.min(contentHeight, maxHeight);
|
|
895
|
+
this.panelOverflow = Math.max(0, contentHeight - panelHeight);
|
|
896
|
+
this.panelScroll = Math.min(this.panelScroll, this.panelOverflow);
|
|
897
|
+
const box = { x: 16, y: top, width: 200, height: panelHeight };
|
|
898
|
+
return [
|
|
899
|
+
{ box, element: panel, fill: t.island, radius: 8, shadows: ISLAND_SHADOW },
|
|
900
|
+
...items.map((item) => ({ ...moved(item, 0, top + 12 - this.panelScroll), clip: box }))
|
|
901
|
+
];
|
|
902
|
+
}
|
|
903
|
+
swatch(button, x, y, size, radius = 4) {
|
|
904
|
+
const color = /--swatch-color:\s*([^;]+)/.exec(button.getAttribute("style") ?? "")?.[1] ?? "";
|
|
905
|
+
const t = this.theme;
|
|
906
|
+
const swatch = {
|
|
907
|
+
box: { x, y, width: size, height: size },
|
|
908
|
+
element: button,
|
|
909
|
+
fill: color === "transparent" ? void 0 : color,
|
|
910
|
+
checker: color === "transparent",
|
|
911
|
+
border: t.swatchBorder,
|
|
912
|
+
radius,
|
|
913
|
+
filter: t.filter
|
|
914
|
+
};
|
|
915
|
+
if (!button.classList.contains("active") || button.classList.contains("active-color")) {
|
|
916
|
+
return [swatch];
|
|
917
|
+
}
|
|
918
|
+
const ring = { x: x - 2, y: y - 2, width: size + 4, height: size + 4 };
|
|
919
|
+
return [
|
|
920
|
+
swatch,
|
|
921
|
+
{ box: ring, element: button, border: t.swatchActive, radius: radius + 1, filter: t.filter }
|
|
922
|
+
];
|
|
923
|
+
}
|
|
924
|
+
slider(range, left, y) {
|
|
925
|
+
const t = this.theme;
|
|
926
|
+
const value = Number(range.value);
|
|
927
|
+
const max = Number(range.max) || 100;
|
|
928
|
+
const share = value / max;
|
|
929
|
+
const width = 176;
|
|
930
|
+
return [
|
|
931
|
+
{
|
|
932
|
+
box: { x: left, y: y + 4, width, height: 16 },
|
|
933
|
+
element: range
|
|
934
|
+
},
|
|
935
|
+
{
|
|
936
|
+
box: { x: left + 2, y: y + 8, width, height: 4 },
|
|
937
|
+
element: range,
|
|
938
|
+
fill: t.button,
|
|
939
|
+
radius: 2
|
|
940
|
+
},
|
|
941
|
+
{
|
|
942
|
+
box: { x: left + 2, y: y + 8, width: width * share, height: 4 },
|
|
943
|
+
element: range,
|
|
944
|
+
fill: t.track,
|
|
945
|
+
radius: 2
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
box: { x: left + 2 + (width - 16) * share, y: y + 2, width: 16, height: 16 },
|
|
949
|
+
element: range,
|
|
950
|
+
fill: t.thumb,
|
|
951
|
+
radius: 8
|
|
952
|
+
},
|
|
953
|
+
{
|
|
954
|
+
box: { x: left, y: y + 21, width: 0, height: 15 },
|
|
955
|
+
label: { value: "0", font: `12px ${FONT}`, color: t.text, x: left + 4, y: y + 41 }
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
box: { x: left, y: y + 21, width: 0, height: 15 },
|
|
959
|
+
label: {
|
|
960
|
+
value: `${value}`,
|
|
961
|
+
font: `12px ${FONT}`,
|
|
962
|
+
color: t.text,
|
|
963
|
+
x: left + share * (width - 15) + 7.5,
|
|
964
|
+
y: y + 41,
|
|
965
|
+
align: "center"
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
];
|
|
969
|
+
}
|
|
970
|
+
footer(document, height) {
|
|
971
|
+
const zoom = document.querySelector(".zoom-actions");
|
|
972
|
+
const history = document.querySelector(".undo-redo-buttons");
|
|
973
|
+
if (!zoom || !history) return [];
|
|
974
|
+
const t = this.theme;
|
|
975
|
+
const y = height - 16 - 36;
|
|
976
|
+
const items = [];
|
|
977
|
+
const group = (container, x, buttons, widths) => {
|
|
978
|
+
const total = widths.reduce((sum, w) => sum + w, 0);
|
|
979
|
+
items.push({
|
|
980
|
+
box: { x, y, width: total, height: 36 },
|
|
981
|
+
element: container,
|
|
982
|
+
fill: t.footer,
|
|
983
|
+
radius: 8
|
|
984
|
+
});
|
|
985
|
+
let at = x;
|
|
986
|
+
for (const [index, button] of buttons.entries()) {
|
|
987
|
+
const w = widths[index] ?? 36;
|
|
988
|
+
const disabled = button.hasAttribute("disabled");
|
|
989
|
+
const svg = button.querySelector("svg");
|
|
990
|
+
const first = index === 0;
|
|
991
|
+
const last = index === buttons.length - 1;
|
|
992
|
+
items.push({
|
|
993
|
+
box: { x: at, y, width: w, height: 36 },
|
|
994
|
+
element: button,
|
|
995
|
+
hover: disabled ? void 0 : t.hover,
|
|
996
|
+
radius: [first ? 8 : 0, last ? 8 : 0, last ? 8 : 0, first ? 8 : 0],
|
|
997
|
+
icon: svg ? { svg, color: disabled ? t.disabled : t.text, size: 16 } : void 0,
|
|
998
|
+
label: svg ? void 0 : {
|
|
999
|
+
value: button.textContent ?? "",
|
|
1000
|
+
font: `14px ${FONT}`,
|
|
1001
|
+
color: t.text,
|
|
1002
|
+
x: at + w / 2,
|
|
1003
|
+
y: y + 23,
|
|
1004
|
+
align: "center"
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
at += w;
|
|
1008
|
+
}
|
|
1009
|
+
return total;
|
|
1010
|
+
};
|
|
1011
|
+
const zoomButtons = [".zoom-out-button", ".reset-zoom-button", ".zoom-in-button"].map((selector) => zoom.querySelector(selector)).filter((button) => button !== null);
|
|
1012
|
+
const width = group(zoom, 16, zoomButtons, [36, 60, 36]);
|
|
1013
|
+
group(history, 16 + width + 9.6, [...history.querySelectorAll("button")], [36, 36]);
|
|
1014
|
+
return items;
|
|
1015
|
+
}
|
|
1016
|
+
// The picker a panel button opened (more colors, arrowheads, fonts), placed next to that
|
|
1017
|
+
// button as Radix places it for Excalidraw, and moved up to fit in the view.
|
|
1018
|
+
popover(document, placed, height) {
|
|
1019
|
+
const content = document.querySelector("[data-radix-popper-content-wrapper]");
|
|
1020
|
+
const trigger = document.querySelector('[aria-haspopup="dialog"][aria-expanded="true"]');
|
|
1021
|
+
const anchor = placed.find((item) => item.element && trigger?.contains(item.element))?.box;
|
|
1022
|
+
if (!content || !anchor) return [];
|
|
1023
|
+
const picker = content.querySelector(".picker");
|
|
1024
|
+
const colors = content.querySelector(".color-picker-content");
|
|
1025
|
+
const fonts2 = content.querySelector(".ScrollableList__wrapper");
|
|
1026
|
+
let items = [];
|
|
1027
|
+
let x = 234;
|
|
1028
|
+
let y = anchor.y - 16;
|
|
1029
|
+
if (picker) {
|
|
1030
|
+
items = this.picker(picker);
|
|
1031
|
+
x = anchor.x;
|
|
1032
|
+
y = anchor.y + anchor.height + 12;
|
|
1033
|
+
} else if (colors) {
|
|
1034
|
+
items = this.colorPicker(colors);
|
|
1035
|
+
} else if (fonts2) {
|
|
1036
|
+
items = this.fontPicker(content, fonts2);
|
|
1037
|
+
}
|
|
1038
|
+
const top = Math.max(8, Math.min(y, height - bottomOf(items) - 8));
|
|
1039
|
+
const arrow = picker ? [] : [
|
|
1040
|
+
{
|
|
1041
|
+
box: { x: x - 10, y: anchor.y + anchor.height / 2 - 10, width: 10, height: 20 },
|
|
1042
|
+
fill: this.theme.island,
|
|
1043
|
+
shadows: ISLAND_SHADOW,
|
|
1044
|
+
arrow: true
|
|
1045
|
+
}
|
|
1046
|
+
];
|
|
1047
|
+
return [...arrow, ...items.map((item) => moved(item, x, top))];
|
|
1048
|
+
}
|
|
1049
|
+
colorPicker(root) {
|
|
1050
|
+
const t = this.theme;
|
|
1051
|
+
const items = [];
|
|
1052
|
+
let y = 12;
|
|
1053
|
+
for (const section of root.querySelectorAll(":scope > div")) {
|
|
1054
|
+
const heading = section.querySelector(".color-picker__heading")?.textContent ?? "";
|
|
1055
|
+
items.push({
|
|
1056
|
+
box: { x: 20, y, width: 0, height: 15 },
|
|
1057
|
+
label: { value: heading, font: `12px ${FONT}`, color: t.text, x: 20, y: y + 12 }
|
|
1058
|
+
});
|
|
1059
|
+
y += 15;
|
|
1060
|
+
const input = section.querySelector("input.color-picker-input");
|
|
1061
|
+
const grid = section.querySelector(".color-picker-content--default");
|
|
1062
|
+
if (input) {
|
|
1063
|
+
const box = { x: 20, y: y + 8, width: 168, height: 34 };
|
|
1064
|
+
items.push({ box, element: input, border: t.divider, radius: 8 });
|
|
1065
|
+
items.push(...this.field(input, "#", 20, y + 8));
|
|
1066
|
+
const dropper = section.querySelector(".excalidraw-eye-dropper-trigger");
|
|
1067
|
+
const svg = dropper?.querySelector("svg");
|
|
1068
|
+
if (dropper && svg) {
|
|
1069
|
+
const selected = dropper.classList.contains("selected");
|
|
1070
|
+
items.push({ box: { x: 144, y: y + 15, width: 1, height: 20 }, fill: t.divider });
|
|
1071
|
+
items.push({
|
|
1072
|
+
box: { x: 151, y: y + 11, width: 28, height: 28 },
|
|
1073
|
+
element: dropper,
|
|
1074
|
+
fill: selected ? t.listSelected : void 0,
|
|
1075
|
+
hover: selected ? void 0 : t.hover,
|
|
1076
|
+
radius: 8,
|
|
1077
|
+
icon: { svg, color: selected ? t.primary : t.text, size: 20 }
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
y += 50;
|
|
1081
|
+
} else if (grid) {
|
|
1082
|
+
const swatches = [...grid.querySelectorAll(":scope > button")].filter(
|
|
1083
|
+
(button) => !button.classList.contains("color-picker__button--no-focus-visible")
|
|
1084
|
+
);
|
|
1085
|
+
const message = grid.querySelector(":scope > div")?.textContent;
|
|
1086
|
+
if (!swatches.length && message) {
|
|
1087
|
+
items.push({
|
|
1088
|
+
box: { x: 12, y, width: 184, height: 46 },
|
|
1089
|
+
label: {
|
|
1090
|
+
value: message,
|
|
1091
|
+
font: `12px ${FONT}`,
|
|
1092
|
+
color: t.text,
|
|
1093
|
+
x: 104,
|
|
1094
|
+
y: y + 27,
|
|
1095
|
+
align: "center"
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
y += 46;
|
|
1099
|
+
}
|
|
1100
|
+
for (const [index, button] of swatches.entries()) {
|
|
1101
|
+
const x = 20 + index % 5 * 34;
|
|
1102
|
+
const top = y + 8 + Math.floor(index / 5) * 34;
|
|
1103
|
+
items.push(...this.swatch(button, x, top, 30, 8));
|
|
1104
|
+
const hotkey = button.querySelector(".color-picker__button__hotkey-label");
|
|
1105
|
+
const key = hotkey?.textContent;
|
|
1106
|
+
if (key) {
|
|
1107
|
+
const font = `11px ${FONT}`;
|
|
1108
|
+
const color = /color:\s*([^;]+)/.exec(hotkey.getAttribute("style") ?? "")?.[1];
|
|
1109
|
+
items.push({
|
|
1110
|
+
box: { x, y: top, width: 0, height: 0 },
|
|
1111
|
+
label: {
|
|
1112
|
+
value: key,
|
|
1113
|
+
font,
|
|
1114
|
+
color: color ?? t.text,
|
|
1115
|
+
x: x + 26 - this.text(key, font),
|
|
1116
|
+
y: top + 23
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
if (swatches.length) y += 12 + Math.ceil(swatches.length / 5) * 34;
|
|
1122
|
+
}
|
|
1123
|
+
y += 12;
|
|
1124
|
+
}
|
|
1125
|
+
const island = { x: 0, y: 0, width: 208, height: y };
|
|
1126
|
+
return [
|
|
1127
|
+
{ box: island, element: root, fill: t.island, radius: 8, shadows: ISLAND_SHADOW },
|
|
1128
|
+
...items
|
|
1129
|
+
];
|
|
1130
|
+
}
|
|
1131
|
+
field(input, prefix, x, y) {
|
|
1132
|
+
const t = this.theme;
|
|
1133
|
+
const font = `14px ${FONT}`;
|
|
1134
|
+
const items = [
|
|
1135
|
+
{
|
|
1136
|
+
box: { x, y, width: 0, height: 0 },
|
|
1137
|
+
label: { value: prefix, font: `16px ${FONT}`, color: t.text, x: x + 17, y: y + 23 }
|
|
1138
|
+
},
|
|
1139
|
+
{
|
|
1140
|
+
box: { x, y, width: 0, height: 0 },
|
|
1141
|
+
label: { value: input.value, font, color: t.text, x: x + 37, y: y + 22 }
|
|
1142
|
+
}
|
|
1143
|
+
];
|
|
1144
|
+
if (this.window.document.activeElement === input) {
|
|
1145
|
+
const before = input.value.slice(0, input.selectionStart ?? input.value.length);
|
|
1146
|
+
const caret = x + 37 + this.text(before, font);
|
|
1147
|
+
items.push({ box: { x: caret, y: y + 8, width: 1, height: 18 }, fill: t.text });
|
|
1148
|
+
}
|
|
1149
|
+
return items;
|
|
1150
|
+
}
|
|
1151
|
+
picker(root) {
|
|
1152
|
+
const t = this.theme;
|
|
1153
|
+
const items = [];
|
|
1154
|
+
let y = 8;
|
|
1155
|
+
for (const child of root.children) {
|
|
1156
|
+
if (child.matches(".picker-content")) {
|
|
1157
|
+
const buttons = [...child.querySelectorAll(":scope > button")];
|
|
1158
|
+
for (const [index, button] of buttons.entries()) {
|
|
1159
|
+
const x = 8 + index % 4 * 40;
|
|
1160
|
+
const top = y + Math.floor(index / 4) * 40;
|
|
1161
|
+
const active = button.classList.contains("active");
|
|
1162
|
+
const svg = button.querySelector("svg");
|
|
1163
|
+
items.push({
|
|
1164
|
+
box: { x, y: top, width: 32, height: 32 },
|
|
1165
|
+
element: button,
|
|
1166
|
+
fill: active ? t.selected : t.button,
|
|
1167
|
+
hover: active ? t.selected : t.hover,
|
|
1168
|
+
radius: 8,
|
|
1169
|
+
icon: svg ? { svg, color: active ? t.onSelected : t.text, size: 16 } : void 0
|
|
1170
|
+
});
|
|
1171
|
+
const key = button.querySelector(".picker-keybinding")?.textContent;
|
|
1172
|
+
if (key) {
|
|
1173
|
+
const font = `9.33px ${FONT}`;
|
|
1174
|
+
items.push({
|
|
1175
|
+
box: { x, y: top, width: 0, height: 0 },
|
|
1176
|
+
label: {
|
|
1177
|
+
value: key,
|
|
1178
|
+
font,
|
|
1179
|
+
color: t.muted,
|
|
1180
|
+
x: x + 29 - this.text(key, font),
|
|
1181
|
+
y: top + 26.5
|
|
1182
|
+
}
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
y += Math.ceil(buttons.length / 4) * 40 - 8;
|
|
1187
|
+
} else if (child.matches(".picker-collapsible")) {
|
|
1188
|
+
const svg = child.querySelector("svg");
|
|
1189
|
+
const value = child.textContent ?? "";
|
|
1190
|
+
items.push({
|
|
1191
|
+
box: { x: 8, y, width: 152, height: 31 },
|
|
1192
|
+
element: child,
|
|
1193
|
+
label: { value, font: `12px ${FONT}`, color: t.text, x: 8, y: y + 20 }
|
|
1194
|
+
});
|
|
1195
|
+
if (svg) {
|
|
1196
|
+
const box = { x: 145, y: y + 9.5, width: 12, height: 12 };
|
|
1197
|
+
items.push({ box, element: child, icon: { svg, color: t.text, size: 12 } });
|
|
1198
|
+
}
|
|
1199
|
+
y += 31;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
const island = { x: 0, y: 0, width: 168, height: y + 8 };
|
|
1203
|
+
return [
|
|
1204
|
+
{ box: island, element: root, fill: t.island, radius: 4, shadows: ISLAND_SHADOW },
|
|
1205
|
+
...items
|
|
1206
|
+
];
|
|
1207
|
+
}
|
|
1208
|
+
fontPicker(root, list) {
|
|
1209
|
+
const t = this.theme;
|
|
1210
|
+
const items = [];
|
|
1211
|
+
const search = root.querySelector("input.QuickSearch__input");
|
|
1212
|
+
const icon = root.querySelector(".QuickSearch__wrapper svg");
|
|
1213
|
+
if (search) {
|
|
1214
|
+
const box = { x: 12, y: 12, width: 216, height: 40 };
|
|
1215
|
+
items.push({ box, element: search, fill: t.input, radius: 4 });
|
|
1216
|
+
if (icon) {
|
|
1217
|
+
const at = { x: 24, y: 21.75, width: 20, height: 20 };
|
|
1218
|
+
items.push({ box: at, icon: { svg: icon, color: t.muted, size: 20 } });
|
|
1219
|
+
}
|
|
1220
|
+
if (search.value) {
|
|
1221
|
+
items.push(...this.field(search, "", 15, 15));
|
|
1222
|
+
} else {
|
|
1223
|
+
items.push({
|
|
1224
|
+
box: { x: 12, y: 12, width: 0, height: 0 },
|
|
1225
|
+
label: { value: search.placeholder, font: `14px ${FONT}`, color: t.muted, x: 52, y: 37 }
|
|
1226
|
+
});
|
|
1227
|
+
if (this.window.document.activeElement === search) {
|
|
1228
|
+
items.push({ box: { x: 52, y: 23, width: 1, height: 18 }, fill: t.text });
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
if (!t.filter)
|
|
1232
|
+
items.push({ box: { x: 12, y: 52.6, width: 216, height: 1 }, fill: "#ebebeb" });
|
|
1233
|
+
}
|
|
1234
|
+
const listTop = 70.59;
|
|
1235
|
+
const rows = [];
|
|
1236
|
+
let y = 0;
|
|
1237
|
+
for (const [index, group] of [...list.querySelectorAll(".dropdown-menu-group")].entries()) {
|
|
1238
|
+
if (index) y += 16;
|
|
1239
|
+
const title = group.querySelector(".dropdown-menu-group-title")?.textContent ?? "";
|
|
1240
|
+
rows.push({
|
|
1241
|
+
box: { x: 12, y, width: 0, height: 15.6 },
|
|
1242
|
+
label: { value: title, font: `12px ${FONT}`, color: t.text, x: 12, y: y + 12 }
|
|
1243
|
+
});
|
|
1244
|
+
y += 15.6 + 8;
|
|
1245
|
+
for (const item of group.querySelectorAll(".dropdown-menu-item")) {
|
|
1246
|
+
y += 1;
|
|
1247
|
+
const selected = item.classList.contains("dropdown-menu-item--selected");
|
|
1248
|
+
const text = item.querySelector(".dropdown-menu-item__text");
|
|
1249
|
+
const family = text?.style.fontFamily || FONT;
|
|
1250
|
+
const svg = item.querySelector("svg");
|
|
1251
|
+
rows.push({
|
|
1252
|
+
box: { x: 13, y, width: 214, height: 32 },
|
|
1253
|
+
element: item,
|
|
1254
|
+
fill: selected ? t.listSelected : void 0,
|
|
1255
|
+
hover: selected ? void 0 : t.hover,
|
|
1256
|
+
radius: 6,
|
|
1257
|
+
label: {
|
|
1258
|
+
value: text?.textContent ?? "",
|
|
1259
|
+
font: `14px ${family}`,
|
|
1260
|
+
color: t.text,
|
|
1261
|
+
x: 48,
|
|
1262
|
+
y: y + 21
|
|
1263
|
+
}
|
|
1264
|
+
});
|
|
1265
|
+
if (svg) {
|
|
1266
|
+
const box = { x: 22, y: y + 8, width: 16, height: 16 };
|
|
1267
|
+
rows.push({ box, element: item, icon: { svg, color: t.text, size: 16 } });
|
|
1268
|
+
}
|
|
1269
|
+
y += 33;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
const listHeight = Math.min(y, 200);
|
|
1273
|
+
this.listOverflow = Math.max(0, y - listHeight);
|
|
1274
|
+
this.listScroll = Math.min(this.listScroll, this.listOverflow);
|
|
1275
|
+
const clip = { x: 0, y: listTop, width: 240, height: listHeight };
|
|
1276
|
+
for (const row of rows) {
|
|
1277
|
+
row.box = { ...row.box, y: row.box.y + listTop - this.listScroll };
|
|
1278
|
+
if (row.label) row.label = { ...row.label, y: row.label.y + listTop - this.listScroll };
|
|
1279
|
+
row.clip = clip;
|
|
1280
|
+
}
|
|
1281
|
+
const island = { x: 0, y: 0, width: 240, height: listTop + listHeight + 12 };
|
|
1282
|
+
return [
|
|
1283
|
+
{ box: island, element: root, fill: t.island, radius: 8, shadows: ISLAND_SHADOW },
|
|
1284
|
+
{ box: { x: 12, y: listTop, width: 216, height: listHeight }, element: list },
|
|
1285
|
+
...items,
|
|
1286
|
+
...rows
|
|
1287
|
+
];
|
|
1288
|
+
}
|
|
1289
|
+
eyeDropper(document) {
|
|
1290
|
+
const preview = document.querySelector(".excalidraw-eye-dropper-preview");
|
|
1291
|
+
if (!preview) return [];
|
|
1292
|
+
const x = Number.parseFloat(preview.style.left) || 0;
|
|
1293
|
+
const y = Number.parseFloat(preview.style.top) || 0;
|
|
1294
|
+
const box = { x, y, width: 48, height: 48 };
|
|
1295
|
+
return [
|
|
1296
|
+
{
|
|
1297
|
+
box,
|
|
1298
|
+
fill: preview.style.background,
|
|
1299
|
+
border: this.theme.divider,
|
|
1300
|
+
radius: 16,
|
|
1301
|
+
filter: this.theme.filter
|
|
1302
|
+
}
|
|
1303
|
+
];
|
|
1304
|
+
}
|
|
1305
|
+
// Two columns from 1024 pixels wide, as Excalidraw's CSS has it. Its links are left out,
|
|
1306
|
+
// since nothing here opens a browser.
|
|
1307
|
+
helpDialog(document, width, height) {
|
|
1308
|
+
const dialog = document.querySelector(".HelpDialog");
|
|
1309
|
+
const background = dialog?.querySelector(".Modal__background");
|
|
1310
|
+
const content = dialog?.querySelector(".Modal__content");
|
|
1311
|
+
if (!dialog || !background || !content) {
|
|
1312
|
+
this.helpScroll = 0;
|
|
1313
|
+
return [];
|
|
1314
|
+
}
|
|
1315
|
+
const t = this.theme;
|
|
1316
|
+
const boxWidth = Math.min(960, width - 80);
|
|
1317
|
+
const inner = boxWidth - 82;
|
|
1318
|
+
const left = 41;
|
|
1319
|
+
const items = [];
|
|
1320
|
+
let y = 41;
|
|
1321
|
+
const title = dialog.querySelector(".Dialog__title")?.textContent ?? "";
|
|
1322
|
+
items.push({
|
|
1323
|
+
box: { x: left, y, width: inner, height: 24 },
|
|
1324
|
+
label: { value: title, font: `bold 20px ${FONT}`, color: t.text, x: left, y: y + 19 }
|
|
1325
|
+
});
|
|
1326
|
+
y += 36;
|
|
1327
|
+
items.push({ box: { x: left, y, width: inner, height: 1 }, fill: t.dialogBorder });
|
|
1328
|
+
y += 25;
|
|
1329
|
+
const heading = dialog.querySelector("h3")?.textContent ?? "";
|
|
1330
|
+
items.push({
|
|
1331
|
+
box: { x: left, y, width: inner, height: 22 },
|
|
1332
|
+
label: { value: heading, font: `bold 18px ${FONT}`, color: t.text, x: left, y: y + 17 }
|
|
1333
|
+
});
|
|
1334
|
+
y += 22 + 24;
|
|
1335
|
+
const twoColumns = width >= 1024;
|
|
1336
|
+
const columnWidth = twoColumns ? (inner - 24) / 2 : inner;
|
|
1337
|
+
const island = (root, at) => {
|
|
1338
|
+
const placed = [];
|
|
1339
|
+
const name = root.querySelector("h4")?.textContent ?? "";
|
|
1340
|
+
placed.push({
|
|
1341
|
+
box: { x: at.x, y: at.y, width: columnWidth, height: 20 },
|
|
1342
|
+
label: { value: name, font: `bold 16px ${FONT}`, color: t.text, x: at.x, y: at.y + 16 }
|
|
1343
|
+
});
|
|
1344
|
+
const top = at.y + 30;
|
|
1345
|
+
let rowY = top;
|
|
1346
|
+
const rows = [...root.querySelectorAll(".HelpDialog__shortcut")];
|
|
1347
|
+
for (const [index, row] of rows.entries()) {
|
|
1348
|
+
const keys = row.querySelector(".HelpDialog__key-container");
|
|
1349
|
+
const parts = [...keys?.childNodes ?? []].map((node) => ({
|
|
1350
|
+
key: node.nodeName === "KBD",
|
|
1351
|
+
value: node.textContent ?? ""
|
|
1352
|
+
}));
|
|
1353
|
+
const partWidth = (part) => part.key ? this.text(part.value, `10px ${FONT}`) + 16 : this.text(part.value, `14px ${FONT}`);
|
|
1354
|
+
const keysWidth = parts.reduce((sum, part) => sum + partWidth(part), 0) + 4 * Math.max(0, parts.length - 1);
|
|
1355
|
+
const labelWidth = columnWidth - 24 - 8 - keysWidth;
|
|
1356
|
+
const lines = wrap(
|
|
1357
|
+
row.firstElementChild?.textContent ?? "",
|
|
1358
|
+
labelWidth,
|
|
1359
|
+
(line) => this.text(line, `14px ${FONT}`)
|
|
1360
|
+
);
|
|
1361
|
+
const rowHeight = Math.max(lines.length * 18, 26) + 12;
|
|
1362
|
+
lines.forEach((line, n) => {
|
|
1363
|
+
const lineY = rowY + (rowHeight - lines.length * 18) / 2 + n * 18 + 13;
|
|
1364
|
+
placed.push({
|
|
1365
|
+
box: { x: at.x + 13, y: lineY - 13, width: labelWidth, height: 18 },
|
|
1366
|
+
element: row,
|
|
1367
|
+
label: { value: line, font: `14px ${FONT}`, color: t.text, x: at.x + 13, y: lineY }
|
|
1368
|
+
});
|
|
1369
|
+
});
|
|
1370
|
+
let keyX = at.x + columnWidth - 13 - keysWidth;
|
|
1371
|
+
for (const part of parts) {
|
|
1372
|
+
const partW = partWidth(part);
|
|
1373
|
+
const keyY = rowY + (rowHeight - 26) / 2;
|
|
1374
|
+
placed.push({
|
|
1375
|
+
box: { x: keyX, y: keyY, width: partW, height: 26 },
|
|
1376
|
+
...part.key ? { fill: t.listSelected, radius: 6 } : {},
|
|
1377
|
+
label: {
|
|
1378
|
+
value: part.value,
|
|
1379
|
+
font: part.key ? `10px ${FONT}` : `14px ${FONT}`,
|
|
1380
|
+
color: t.text,
|
|
1381
|
+
x: part.key ? keyX + 8 : keyX,
|
|
1382
|
+
y: keyY + (part.key ? 17 : 18)
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
keyX += partW + 4;
|
|
1386
|
+
}
|
|
1387
|
+
rowY += rowHeight;
|
|
1388
|
+
if (index < rows.length - 1) {
|
|
1389
|
+
placed.push({
|
|
1390
|
+
box: { x: at.x + 1, y: rowY, width: columnWidth - 2, height: 1 },
|
|
1391
|
+
fill: t.dialogBorder
|
|
1392
|
+
});
|
|
1393
|
+
rowY += 1;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
placed.unshift({
|
|
1397
|
+
box: { x: at.x, y: top, width: columnWidth, height: rowY - top + 1 },
|
|
1398
|
+
border: t.dialogBorder,
|
|
1399
|
+
radius: 8
|
|
1400
|
+
});
|
|
1401
|
+
return placed;
|
|
1402
|
+
};
|
|
1403
|
+
const tools = dialog.querySelector(".HelpDialog__island--tools");
|
|
1404
|
+
const view = dialog.querySelector(".HelpDialog__island--view");
|
|
1405
|
+
const editor = dialog.querySelector(".HelpDialog__island--editor");
|
|
1406
|
+
if (tools && view && editor) {
|
|
1407
|
+
if (twoColumns) {
|
|
1408
|
+
const first = island(tools, { x: left, y });
|
|
1409
|
+
const second = island(view, { x: left, y: bottomOf(first) + 32 });
|
|
1410
|
+
const right = island(editor, { x: left + columnWidth + 24, y });
|
|
1411
|
+
const extra = Math.max(0, bottomOf(right) - bottomOf(second));
|
|
1412
|
+
items.push(...first, ...second.map((item) => moved(item, 0, extra / 2)), ...right);
|
|
1413
|
+
} else {
|
|
1414
|
+
for (const root of [tools, view, editor]) {
|
|
1415
|
+
const placed = island(root, { x: left, y });
|
|
1416
|
+
items.push(...placed);
|
|
1417
|
+
y = bottomOf(placed) + 32;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
const contentHeight = bottomOf(items) + 41;
|
|
1422
|
+
const boxHeight = Math.min(contentHeight, height - 80);
|
|
1423
|
+
this.helpOverflow = Math.max(0, contentHeight - boxHeight);
|
|
1424
|
+
this.helpScroll = Math.min(this.helpScroll, this.helpOverflow);
|
|
1425
|
+
const box = {
|
|
1426
|
+
x: (width - boxWidth) / 2,
|
|
1427
|
+
y: (height - boxHeight) / 2,
|
|
1428
|
+
width: boxWidth,
|
|
1429
|
+
height: boxHeight
|
|
1430
|
+
};
|
|
1431
|
+
const clip = { x: box.x + 1, y: box.y + 1, width: boxWidth - 2, height: boxHeight - 2 };
|
|
1432
|
+
return [
|
|
1433
|
+
{ box: { x: 0, y: 0, width, height }, element: background, fill: "rgba(18, 18, 18, 0.2)" },
|
|
1434
|
+
{ box, element: content, fill: t.island, border: t.dialogBorder, radius: 12 },
|
|
1435
|
+
...items.map((item) => ({ ...moved(item, box.x, box.y - this.helpScroll), clip }))
|
|
1436
|
+
];
|
|
1437
|
+
}
|
|
1438
|
+
// The context menu Excalidraw opens on a right-click: its items in a list next to the click,
|
|
1439
|
+
// moved to fit in the view as Excalidraw's Popover does.
|
|
1440
|
+
contextMenu(document, width, height) {
|
|
1441
|
+
const menu = document.querySelector(".context-menu");
|
|
1442
|
+
if (!menu) return [];
|
|
1443
|
+
const t = this.theme;
|
|
1444
|
+
const labelFont = `13.3333px ${FONT}`;
|
|
1445
|
+
const shortcutFont = `11.2px ${FONT}`;
|
|
1446
|
+
const rows = [];
|
|
1447
|
+
for (const child of menu.children) {
|
|
1448
|
+
if (child.matches("hr")) {
|
|
1449
|
+
if (rows.length && rows.at(-1) !== "separator") rows.push("separator");
|
|
1450
|
+
continue;
|
|
1451
|
+
}
|
|
1452
|
+
const button = child.querySelector("button");
|
|
1453
|
+
if (!button || HIDDEN_MENU_ITEMS.has(child.getAttribute("data-testid") ?? "")) continue;
|
|
1454
|
+
rows.push({
|
|
1455
|
+
element: button,
|
|
1456
|
+
label: button.querySelector(".context-menu-item__label")?.textContent ?? "",
|
|
1457
|
+
shortcut: button.querySelector(".context-menu-item__shortcut")?.textContent ?? "",
|
|
1458
|
+
danger: button.classList.contains("dangerous")
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
while (rows.at(-1) === "separator") rows.pop();
|
|
1462
|
+
let content = 152 - 36;
|
|
1463
|
+
let menuHeight = 18;
|
|
1464
|
+
for (const row of rows) {
|
|
1465
|
+
if (row === "separator") {
|
|
1466
|
+
menuHeight += 17;
|
|
1467
|
+
continue;
|
|
1468
|
+
}
|
|
1469
|
+
const label = this.text(row.label, labelFont);
|
|
1470
|
+
const shortcut = row.shortcut ? this.text(row.shortcut, shortcutFont) : 0;
|
|
1471
|
+
content = Math.max(content, label + 20 + shortcut);
|
|
1472
|
+
menuHeight += 26;
|
|
1473
|
+
}
|
|
1474
|
+
const menuWidth = content + 36 + 2;
|
|
1475
|
+
let x = this.menuAt.x + 2;
|
|
1476
|
+
if (x + menuWidth > width) x = width - menuWidth - 10;
|
|
1477
|
+
let y = this.menuAt.y - 4;
|
|
1478
|
+
if (y + menuHeight > height) y = Math.max(0, height - menuHeight);
|
|
1479
|
+
const items = [
|
|
1480
|
+
{
|
|
1481
|
+
box: { x, y, width: menuWidth, height: menuHeight },
|
|
1482
|
+
element: menu,
|
|
1483
|
+
fill: t.menu,
|
|
1484
|
+
border: t.menuBorder,
|
|
1485
|
+
radius: 4,
|
|
1486
|
+
shadows: MENU_SHADOW
|
|
1487
|
+
}
|
|
1488
|
+
];
|
|
1489
|
+
let at = y + 9;
|
|
1490
|
+
for (const row of rows) {
|
|
1491
|
+
if (row === "separator") {
|
|
1492
|
+
items.push({
|
|
1493
|
+
box: { x: x + 1, y: at + 8, width: menuWidth - 2, height: 1 },
|
|
1494
|
+
fill: t.menuSeparator
|
|
1495
|
+
});
|
|
1496
|
+
at += 17;
|
|
1497
|
+
continue;
|
|
1498
|
+
}
|
|
1499
|
+
const box = { x: x + 1, y: at, width: menuWidth - 2, height: 26 };
|
|
1500
|
+
const hovered = this.hovered === row.element;
|
|
1501
|
+
const color = hovered ? t.menuHoverText : row.danger ? "#f03e3e" : t.menuText;
|
|
1502
|
+
items.push({
|
|
1503
|
+
box,
|
|
1504
|
+
element: row.element,
|
|
1505
|
+
hover: row.danger ? "#fa5252" : t.menuHover,
|
|
1506
|
+
label: { value: row.label, font: labelFont, color, x: x + 21, y: at + 18 }
|
|
1507
|
+
});
|
|
1508
|
+
if (row.shortcut) {
|
|
1509
|
+
items.push({
|
|
1510
|
+
box,
|
|
1511
|
+
element: row.element,
|
|
1512
|
+
label: {
|
|
1513
|
+
value: row.shortcut,
|
|
1514
|
+
font: shortcutFont,
|
|
1515
|
+
color: hovered ? t.menuHoverText : withAlpha(t.menuText, 0.6),
|
|
1516
|
+
x: x + 1 + menuWidth - 2 - 16 - this.text(row.shortcut, shortcutFont),
|
|
1517
|
+
y: at + 17
|
|
1518
|
+
}
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
at += 26;
|
|
1522
|
+
}
|
|
1523
|
+
return items;
|
|
1524
|
+
}
|
|
1525
|
+
};
|
|
1526
|
+
function moved(item, dx, dy) {
|
|
1527
|
+
return {
|
|
1528
|
+
...item,
|
|
1529
|
+
box: { ...item.box, x: item.box.x + dx, y: item.box.y + dy },
|
|
1530
|
+
clip: item.clip && { ...item.clip, x: item.clip.x + dx, y: item.clip.y + dy },
|
|
1531
|
+
label: item.label && { ...item.label, x: item.label.x + dx, y: item.label.y + dy }
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
function bottomOf(items) {
|
|
1535
|
+
return Math.max(0, ...items.map((item) => item.box.y + item.box.height));
|
|
1536
|
+
}
|
|
1537
|
+
function inside(box, x, y) {
|
|
1538
|
+
return x >= box.x && x < box.x + box.width && y >= box.y && y < box.y + box.height;
|
|
1539
|
+
}
|
|
1540
|
+
function viewCenter(svg) {
|
|
1541
|
+
const [, , w = 24, h = 24] = (svg.getAttribute("viewBox") ?? "").split(/\s+/).map(Number);
|
|
1542
|
+
return `${w / 2} ${h / 2}`;
|
|
1543
|
+
}
|
|
1544
|
+
function withAlpha(hex, alpha) {
|
|
1545
|
+
const [r, g, b] = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
1546
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
1547
|
+
}
|
|
1548
|
+
function wrap(text, width, measure) {
|
|
1549
|
+
const lines = [];
|
|
1550
|
+
let line = "";
|
|
1551
|
+
for (const word of text.split(" ")) {
|
|
1552
|
+
const next2 = line ? `${line} ${word}` : word;
|
|
1553
|
+
if (line && measure(next2) > width) {
|
|
1554
|
+
lines.push(line);
|
|
1555
|
+
line = word;
|
|
1556
|
+
} else {
|
|
1557
|
+
line = next2;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
if (line) lines.push(line);
|
|
1561
|
+
return lines;
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
// src/editor.ts
|
|
1565
|
+
var WHEEL_STEP = 60;
|
|
1566
|
+
var SLOP = 5;
|
|
1567
|
+
var PAINT = [
|
|
1568
|
+
"clearRect",
|
|
1569
|
+
"fillRect",
|
|
1570
|
+
"strokeRect",
|
|
1571
|
+
"fill",
|
|
1572
|
+
"stroke",
|
|
1573
|
+
"drawImage",
|
|
1574
|
+
"fillText",
|
|
1575
|
+
"strokeText",
|
|
1576
|
+
"putImageData"
|
|
1577
|
+
];
|
|
1578
|
+
var BUTTONS = {
|
|
1579
|
+
left: { button: 0, bit: 1 },
|
|
1580
|
+
middle: { button: 1, bit: 4 },
|
|
1581
|
+
right: { button: 2, bit: 2 }
|
|
1582
|
+
};
|
|
1583
|
+
var Editor = class _Editor {
|
|
1584
|
+
window;
|
|
1585
|
+
scheduler;
|
|
1586
|
+
size;
|
|
1587
|
+
// Not watched for paint, since compositing is not a change.
|
|
1588
|
+
composite;
|
|
1589
|
+
dark;
|
|
1590
|
+
frameListener;
|
|
1591
|
+
sent = {};
|
|
1592
|
+
sceneDirty = true;
|
|
1593
|
+
flushQueued = false;
|
|
1594
|
+
buttons = 0;
|
|
1595
|
+
lastPress = { button: "", x: 0, y: 0, at: 0, count: 0 };
|
|
1596
|
+
overlay;
|
|
1597
|
+
clipboard;
|
|
1598
|
+
// The element a press went to, which gets the moves and the release until the button comes
|
|
1599
|
+
// up, as with pointer capture.
|
|
1600
|
+
pressed;
|
|
1601
|
+
caretAt;
|
|
1602
|
+
constructor(page) {
|
|
1603
|
+
this.window = page.window;
|
|
1604
|
+
this.scheduler = page.scheduler;
|
|
1605
|
+
this.size = page.size;
|
|
1606
|
+
this.composite = page.composite;
|
|
1607
|
+
this.dark = page.dark;
|
|
1608
|
+
this.overlay = page.overlay;
|
|
1609
|
+
this.clipboard = page.clipboard;
|
|
1610
|
+
page.onPaint(() => this.repaintScene());
|
|
1611
|
+
new this.window.MutationObserver(() => {
|
|
1612
|
+
this.overlay.invalidate();
|
|
1613
|
+
this.queueFlush();
|
|
1614
|
+
}).observe(this.window.document.body, {
|
|
1615
|
+
subtree: true,
|
|
1616
|
+
childList: true,
|
|
1617
|
+
attributes: true,
|
|
1618
|
+
characterData: true
|
|
1619
|
+
});
|
|
1620
|
+
}
|
|
1621
|
+
static async open(options) {
|
|
1622
|
+
const page = await openPage(options);
|
|
1623
|
+
const started = Date.now();
|
|
1624
|
+
while (!page.window.tui) {
|
|
1625
|
+
if (Date.now() - started > 3e4) {
|
|
1626
|
+
page.window.close();
|
|
1627
|
+
throw new Error("Excalidraw did not start.");
|
|
1628
|
+
}
|
|
1629
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
1630
|
+
}
|
|
1631
|
+
const editor = new _Editor(page);
|
|
1632
|
+
await editor.settle();
|
|
1633
|
+
page.saveCode();
|
|
1634
|
+
return editor;
|
|
1635
|
+
}
|
|
1636
|
+
async serialize() {
|
|
1637
|
+
const json = this.window.tui?.serialize();
|
|
1638
|
+
if (!json) throw new Error("The editor is gone, so there is nothing to save.");
|
|
1639
|
+
return json;
|
|
1640
|
+
}
|
|
1641
|
+
async version() {
|
|
1642
|
+
return this.window.tui?.version() ?? 0;
|
|
1643
|
+
}
|
|
1644
|
+
async exportPng(scale) {
|
|
1645
|
+
const png = await this.window.tui?.exportPng(scale);
|
|
1646
|
+
if (!png) throw new Error("The editor is gone, so there is nothing to export.");
|
|
1647
|
+
return Buffer.from(png);
|
|
1648
|
+
}
|
|
1649
|
+
async onFrame(listener) {
|
|
1650
|
+
this.frameListener = listener;
|
|
1651
|
+
this.sent = {};
|
|
1652
|
+
this.sceneDirty = true;
|
|
1653
|
+
this.queueFlush();
|
|
1654
|
+
await this.settle();
|
|
1655
|
+
}
|
|
1656
|
+
async resize(viewport) {
|
|
1657
|
+
Object.assign(this.size, viewport);
|
|
1658
|
+
this.sent = {};
|
|
1659
|
+
this.overlay.forgetPainted();
|
|
1660
|
+
this.window.dispatchEvent(new this.window.Event("resize"));
|
|
1661
|
+
this.sceneDirty = true;
|
|
1662
|
+
this.queueFlush();
|
|
1663
|
+
await this.settle();
|
|
1664
|
+
}
|
|
1665
|
+
async input(event) {
|
|
1666
|
+
switch (event.kind) {
|
|
1667
|
+
case "mouse":
|
|
1668
|
+
this.mouse(event);
|
|
1669
|
+
break;
|
|
1670
|
+
case "wheel": {
|
|
1671
|
+
const { x, y } = this.css(event);
|
|
1672
|
+
if (this.overlay.scroll(x, y, event.dy * WHEEL_STEP)) {
|
|
1673
|
+
this.queueFlush();
|
|
1674
|
+
break;
|
|
1675
|
+
}
|
|
1676
|
+
this.canvas().dispatchEvent(
|
|
1677
|
+
new this.window.WheelEvent("wheel", {
|
|
1678
|
+
...this.pointer(event),
|
|
1679
|
+
deltaX: event.dx * WHEEL_STEP,
|
|
1680
|
+
deltaY: event.dy * WHEEL_STEP
|
|
1681
|
+
})
|
|
1682
|
+
);
|
|
1683
|
+
break;
|
|
1684
|
+
}
|
|
1685
|
+
case "key":
|
|
1686
|
+
this.key(event);
|
|
1687
|
+
break;
|
|
1688
|
+
case "text":
|
|
1689
|
+
this.text(event);
|
|
1690
|
+
break;
|
|
1691
|
+
case "report":
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1694
|
+
await this.settle();
|
|
1695
|
+
}
|
|
1696
|
+
caret() {
|
|
1697
|
+
return this.caretAt;
|
|
1698
|
+
}
|
|
1699
|
+
onClipboard(listener) {
|
|
1700
|
+
this.clipboard.onCopy = listener;
|
|
1701
|
+
}
|
|
1702
|
+
async close() {
|
|
1703
|
+
this.frameListener = void 0;
|
|
1704
|
+
this.scheduler.stop();
|
|
1705
|
+
this.window.close();
|
|
1706
|
+
}
|
|
1707
|
+
async settle() {
|
|
1708
|
+
do
|
|
1709
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1710
|
+
while (this.scheduler.busy() || this.flushQueued);
|
|
1711
|
+
}
|
|
1712
|
+
queueFlush() {
|
|
1713
|
+
if (this.flushQueued) return;
|
|
1714
|
+
this.flushQueued = true;
|
|
1715
|
+
const tick = () => {
|
|
1716
|
+
if (this.scheduler.busy()) return void setImmediate(tick);
|
|
1717
|
+
this.flushQueued = false;
|
|
1718
|
+
this.flush();
|
|
1719
|
+
};
|
|
1720
|
+
setImmediate(tick);
|
|
1721
|
+
}
|
|
1722
|
+
flush() {
|
|
1723
|
+
if (!this.frameListener) return;
|
|
1724
|
+
if (this.sceneDirty) this.sendScene();
|
|
1725
|
+
const controls = this.overlay.render(this.size.scale);
|
|
1726
|
+
if (controls) {
|
|
1727
|
+
const { data } = controls.getContext("2d").getImageData(0, 0, controls.width, controls.height);
|
|
1728
|
+
const pixels = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
1729
|
+
this.send("controls", pixels, controls.width, controls.height);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
sendScene() {
|
|
1733
|
+
this.sceneDirty = false;
|
|
1734
|
+
const layers = [...this.window.document.querySelectorAll("canvas.excalidraw__canvas")];
|
|
1735
|
+
const { width = 0, height = 0 } = layers[0] ?? {};
|
|
1736
|
+
if (!width || !height) return;
|
|
1737
|
+
const scene = this.composite;
|
|
1738
|
+
if (scene.canvas.width !== width || scene.canvas.height !== height) {
|
|
1739
|
+
Object.assign(scene.canvas, { width, height });
|
|
1740
|
+
}
|
|
1741
|
+
for (const [index, layer] of layers.entries()) {
|
|
1742
|
+
scene.globalCompositeOperation = index === 0 ? "copy" : "source-over";
|
|
1743
|
+
scene.drawImage(layer, 0, 0);
|
|
1744
|
+
}
|
|
1745
|
+
scene.globalCompositeOperation = "source-over";
|
|
1746
|
+
this.drawCaret(scene);
|
|
1747
|
+
const { data } = scene.getImageData(0, 0, width, height);
|
|
1748
|
+
const pixels = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
1749
|
+
if (this.dark) darken(pixels);
|
|
1750
|
+
this.send("scene", pixels, width, height);
|
|
1751
|
+
}
|
|
1752
|
+
// Writing a whole 2394x1560 layer took about 10 ms, and a drag, a hover, or a scroll usually
|
|
1753
|
+
// changes a fraction of it, so only the changed rectangle goes to kitty.
|
|
1754
|
+
send(layer, pixels, width, height) {
|
|
1755
|
+
const last = this.sent[layer];
|
|
1756
|
+
this.sent[layer] = { pixels, width, height };
|
|
1757
|
+
if (!last || last.width !== width || last.height !== height) {
|
|
1758
|
+
this.frameListener?.({ layer, data: pixels, width, height });
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
const rect = changedRect(last.pixels, pixels, width, height);
|
|
1762
|
+
if (rect) this.frameListener?.({ layer, data: crop(pixels, width, rect), width, height, rect });
|
|
1763
|
+
}
|
|
1764
|
+
canvas() {
|
|
1765
|
+
const canvas = this.window.document.querySelector("canvas.interactive");
|
|
1766
|
+
if (!canvas) throw new Error("The editor has no canvas.");
|
|
1767
|
+
return canvas;
|
|
1768
|
+
}
|
|
1769
|
+
css(event) {
|
|
1770
|
+
return { x: event.x / this.size.scale, y: event.y / this.size.scale };
|
|
1771
|
+
}
|
|
1772
|
+
pointer(event) {
|
|
1773
|
+
const { x, y } = this.css(event);
|
|
1774
|
+
return {
|
|
1775
|
+
...modifierFlags(event.mods),
|
|
1776
|
+
bubbles: true,
|
|
1777
|
+
cancelable: true,
|
|
1778
|
+
composed: true,
|
|
1779
|
+
clientX: x,
|
|
1780
|
+
clientY: y,
|
|
1781
|
+
screenX: x,
|
|
1782
|
+
screenY: y,
|
|
1783
|
+
buttons: this.buttons
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
// A right press opens the context menu, as on macOS.
|
|
1787
|
+
mouse(event) {
|
|
1788
|
+
const canvas = this.canvas();
|
|
1789
|
+
const { PointerEvent, MouseEvent } = this.window;
|
|
1790
|
+
const at = this.css(event);
|
|
1791
|
+
const backdrop = this.window.document.querySelector(".excalidraw-eye-dropper-backdrop");
|
|
1792
|
+
const over = backdrop ?? this.overlay.elementAt(at.x, at.y) ?? canvas;
|
|
1793
|
+
const target = this.pressed ?? over;
|
|
1794
|
+
const pointer = { pointerId: 1, pointerType: "mouse", isPrimary: true };
|
|
1795
|
+
if (event.action === "move") {
|
|
1796
|
+
const { x, y } = this.lastPress;
|
|
1797
|
+
if (Math.abs(at.x - x) > SLOP || Math.abs(at.y - y) > SLOP) this.lastPress.count = 0;
|
|
1798
|
+
if (this.overlay.hover(at.x, at.y)) this.queueFlush();
|
|
1799
|
+
const init2 = { ...this.pointer(event), ...pointer, pressure: this.buttons ? 0.5 : 0 };
|
|
1800
|
+
target.dispatchEvent(new PointerEvent("pointermove", init2));
|
|
1801
|
+
target.dispatchEvent(new MouseEvent("mousemove", init2));
|
|
1802
|
+
if (this.buttons) this.slide(target, at.x);
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1805
|
+
const { button, bit } = BUTTONS[event.button];
|
|
1806
|
+
if (event.action === "down") {
|
|
1807
|
+
this.lastPress = countPress(
|
|
1808
|
+
this.lastPress,
|
|
1809
|
+
{ ...at, button: event.button },
|
|
1810
|
+
Date.now(),
|
|
1811
|
+
SLOP
|
|
1812
|
+
);
|
|
1813
|
+
this.buttons |= bit;
|
|
1814
|
+
this.pressed = target;
|
|
1815
|
+
} else {
|
|
1816
|
+
this.buttons &= ~bit;
|
|
1817
|
+
if (!this.buttons) this.pressed = void 0;
|
|
1818
|
+
}
|
|
1819
|
+
const init = { ...this.pointer(event), ...pointer, button, pressure: this.buttons ? 0.5 : 0 };
|
|
1820
|
+
const detail = this.lastPress.count;
|
|
1821
|
+
target.dispatchEvent(new PointerEvent(`pointer${event.action}`, init));
|
|
1822
|
+
const mouse = new MouseEvent(`mouse${event.action}`, { ...init, detail, cancelable: true });
|
|
1823
|
+
target.dispatchEvent(mouse);
|
|
1824
|
+
if (event.action === "down") {
|
|
1825
|
+
if (!mouse.defaultPrevented) this.moveFocus(target);
|
|
1826
|
+
this.slide(target, at.x);
|
|
1827
|
+
if (event.button === "right") {
|
|
1828
|
+
this.overlay.menuAt = at;
|
|
1829
|
+
target.dispatchEvent(new MouseEvent("contextmenu", { ...init, detail }));
|
|
1830
|
+
}
|
|
1831
|
+
return;
|
|
1832
|
+
}
|
|
1833
|
+
if (target !== over) return;
|
|
1834
|
+
target.dispatchEvent(new MouseEvent("click", { ...init, detail }));
|
|
1835
|
+
if (detail === 2) target.dispatchEvent(new MouseEvent("dblclick", { ...init, detail }));
|
|
1836
|
+
}
|
|
1837
|
+
// A press moves the focus as in a browser, to the nearest focusable element at or around
|
|
1838
|
+
// the press: a text input such as the color picker's hex code, a button, or for the canvas
|
|
1839
|
+
// Excalidraw's container, which Excalidraw's copy and paste handlers ask to have focus.
|
|
1840
|
+
moveFocus(target) {
|
|
1841
|
+
const focusable = target.closest("input, textarea, button, select, [tabindex]");
|
|
1842
|
+
if (focusable instanceof this.window.HTMLElement && focusable !== this.window.document.activeElement) {
|
|
1843
|
+
focusable.focus();
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
// A press or drag on a range input (the opacity slider) sets its value from the pointer, as a
|
|
1847
|
+
// browser does, with the input event React listens for.
|
|
1848
|
+
slide(target, x) {
|
|
1849
|
+
if (!(target instanceof this.window.HTMLInputElement) || target.type !== "range") return;
|
|
1850
|
+
const box = this.overlay.boxOf(target);
|
|
1851
|
+
if (!box) return;
|
|
1852
|
+
const [min, max, step] = [target.min, target.max, target.step].map(Number);
|
|
1853
|
+
const share = Math.min(1, Math.max(0, (x - box.x - 8) / (box.width - 16)));
|
|
1854
|
+
const value = min + Math.round(share * (max - min) / (step || 1)) * (step || 1);
|
|
1855
|
+
if (Number(target.value) === value) return;
|
|
1856
|
+
const setter = Object.getOwnPropertyDescriptor(
|
|
1857
|
+
this.window.HTMLInputElement.prototype,
|
|
1858
|
+
"value"
|
|
1859
|
+
)?.set;
|
|
1860
|
+
setter?.call(target, `${value}`);
|
|
1861
|
+
target.dispatchEvent(new this.window.Event("input", { bubbles: true }));
|
|
1862
|
+
target.dispatchEvent(new this.window.Event("change", { bubbles: true }));
|
|
1863
|
+
}
|
|
1864
|
+
key(event) {
|
|
1865
|
+
const { document, KeyboardEvent } = this.window;
|
|
1866
|
+
const target = document.activeElement ?? document.body;
|
|
1867
|
+
const mods = keyMods(event);
|
|
1868
|
+
if (event.swallowed) {
|
|
1869
|
+
if (!(mods.ctrl || mods.meta) && this.editable(target)) return;
|
|
1870
|
+
this.key({ ...event, action: "down", text: "", swallowed: void 0 });
|
|
1871
|
+
}
|
|
1872
|
+
const key = domKey(event);
|
|
1873
|
+
const unhandled = target.dispatchEvent(
|
|
1874
|
+
new KeyboardEvent(event.action === "down" ? "keydown" : "keyup", {
|
|
1875
|
+
...modifierFlags(mods),
|
|
1876
|
+
key,
|
|
1877
|
+
code: domCode(event.key),
|
|
1878
|
+
repeat: event.repeat ?? false,
|
|
1879
|
+
bubbles: true,
|
|
1880
|
+
cancelable: true,
|
|
1881
|
+
composed: true
|
|
1882
|
+
})
|
|
1883
|
+
);
|
|
1884
|
+
if (event.action !== "down" || !unhandled) return;
|
|
1885
|
+
if (this.editable(target)) {
|
|
1886
|
+
editText(target, key, mods);
|
|
1887
|
+
this.repaintScene();
|
|
1888
|
+
return;
|
|
1889
|
+
}
|
|
1890
|
+
const command = process.platform === "darwin" ? mods.meta : mods.ctrl;
|
|
1891
|
+
const action = { c: "copy", x: "cut", v: "paste" }[key.toLowerCase()];
|
|
1892
|
+
if (command && action) {
|
|
1893
|
+
const data = new this.window.DataTransfer();
|
|
1894
|
+
if (action === "paste") data.setData("text/plain", this.clipboard.text);
|
|
1895
|
+
const init = { clipboardData: data, bubbles: true, cancelable: true };
|
|
1896
|
+
target.dispatchEvent(new this.window.ClipboardEvent(action, init));
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
editable(element) {
|
|
1900
|
+
const { HTMLTextAreaElement, HTMLInputElement } = this.window;
|
|
1901
|
+
return element instanceof HTMLTextAreaElement || element instanceof HTMLInputElement && ["text", "search"].includes(element.type);
|
|
1902
|
+
}
|
|
1903
|
+
text(event) {
|
|
1904
|
+
const { document } = this.window;
|
|
1905
|
+
const area = document.activeElement;
|
|
1906
|
+
const paste = () => {
|
|
1907
|
+
const data = new this.window.DataTransfer();
|
|
1908
|
+
data.setData("text/plain", event.text);
|
|
1909
|
+
const init = { clipboardData: data, bubbles: true, cancelable: true };
|
|
1910
|
+
return (area ?? document).dispatchEvent(new this.window.ClipboardEvent("paste", init));
|
|
1911
|
+
};
|
|
1912
|
+
if (area && this.editable(area)) {
|
|
1913
|
+
if (!event.paste || paste()) {
|
|
1914
|
+
replaceText(area, event.text, event.paste ? "insertFromPaste" : "insertText");
|
|
1915
|
+
this.repaintScene();
|
|
1916
|
+
}
|
|
1917
|
+
} else if (event.paste) {
|
|
1918
|
+
paste();
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
repaintScene() {
|
|
1922
|
+
this.sceneDirty = true;
|
|
1923
|
+
this.queueFlush();
|
|
1924
|
+
}
|
|
1925
|
+
// A browser draws the caret and the selected text of the textarea Excalidraw edits text in.
|
|
1926
|
+
// The canvas shows the text itself (see PATCHES in scripts/build.ts), so draw the
|
|
1927
|
+
// caret and the selection over it, placed the way Excalidraw places each line of a text
|
|
1928
|
+
// element: lines lineHeight apart, aligned within the element's width, then rotated, scrolled,
|
|
1929
|
+
// and zoomed with the element.
|
|
1930
|
+
drawCaret(context) {
|
|
1931
|
+
this.caretAt = void 0;
|
|
1932
|
+
const area = this.window.document.activeElement;
|
|
1933
|
+
const editing = this.window.tui?.editingText();
|
|
1934
|
+
if (!(area instanceof this.window.HTMLTextAreaElement) || !editing) return;
|
|
1935
|
+
const { element, zoom, scrollX, scrollY } = editing;
|
|
1936
|
+
const [start, end] = [area.selectionStart, area.selectionEnd].map(
|
|
1937
|
+
(at) => wrappedIndex(area.value, element.text, at)
|
|
1938
|
+
);
|
|
1939
|
+
const lineHeight = element.fontSize * element.lineHeight;
|
|
1940
|
+
const scale = this.size.scale * zoom;
|
|
1941
|
+
context.save();
|
|
1942
|
+
context.setTransform(scale, 0, 0, scale, 0, 0);
|
|
1943
|
+
context.translate(
|
|
1944
|
+
element.x + element.width / 2 + scrollX,
|
|
1945
|
+
element.y + element.height / 2 + scrollY
|
|
1946
|
+
);
|
|
1947
|
+
context.rotate(element.angle);
|
|
1948
|
+
context.translate(-element.width / 2, -element.height / 2);
|
|
1949
|
+
context.font = expandFont(`${element.fontSize}px ${area.style.fontFamily}`);
|
|
1950
|
+
loadGlyphs(element.text);
|
|
1951
|
+
context.fillStyle = element.strokeColor;
|
|
1952
|
+
let lineStart = 0;
|
|
1953
|
+
for (const [index, line] of element.text.split("\n").entries()) {
|
|
1954
|
+
const lineEnd = lineStart + line.length;
|
|
1955
|
+
const width = context.measureText(line).width;
|
|
1956
|
+
const left = { left: 0, center: (element.width - width) / 2, right: element.width - width }[element.textAlign];
|
|
1957
|
+
const x = (at) => left + context.measureText(line.slice(0, at - lineStart)).width;
|
|
1958
|
+
const top = index * lineHeight;
|
|
1959
|
+
if (start === end && start >= lineStart && start <= lineEnd) {
|
|
1960
|
+
context.fillRect(x(start), top, 1, lineHeight);
|
|
1961
|
+
const m = context.getTransform();
|
|
1962
|
+
const [cx, cy] = [x(start), top + lineHeight / 2];
|
|
1963
|
+
this.caretAt = { x: m.a * cx + m.c * cy + m.e, y: m.b * cx + m.d * cy + m.f };
|
|
1964
|
+
} else if (start < end && start <= lineEnd && end >= lineStart) {
|
|
1965
|
+
context.globalCompositeOperation = "multiply";
|
|
1966
|
+
context.fillStyle = "#b3d7ff";
|
|
1967
|
+
const from = x(Math.max(start, lineStart));
|
|
1968
|
+
context.fillRect(from, top, x(Math.min(end, lineEnd)) - from, lineHeight);
|
|
1969
|
+
}
|
|
1970
|
+
lineStart = lineEnd + 1;
|
|
1971
|
+
}
|
|
1972
|
+
context.restore();
|
|
1973
|
+
}
|
|
1974
|
+
};
|
|
1975
|
+
var HUE_180 = [
|
|
1976
|
+
[-0.574, 1.43, 0.144],
|
|
1977
|
+
[0.426, 0.43, 0.144],
|
|
1978
|
+
[0.426, 1.43, -0.856]
|
|
1979
|
+
];
|
|
1980
|
+
var ZEROS = Buffer.alloc(4096);
|
|
1981
|
+
function darken(rgba) {
|
|
1982
|
+
const pixels = new Uint8ClampedArray(rgba.buffer, rgba.byteOffset, rgba.byteLength);
|
|
1983
|
+
const words2 = new Uint32Array(rgba.buffer, rgba.byteOffset, rgba.byteLength / 4);
|
|
1984
|
+
const [[rr, rg, rb], [gr, gg, gb], [br, bg, bb]] = HUE_180;
|
|
1985
|
+
for (let start = 0; start < rgba.length; start += ZEROS.length) {
|
|
1986
|
+
const end = Math.min(start + ZEROS.length, rgba.length);
|
|
1987
|
+
if (ZEROS.compare(rgba, start, end, 0, end - start) === 0) continue;
|
|
1988
|
+
for (let i = start / 4; i < end / 4; i++) {
|
|
1989
|
+
if (words2[i] === 0) continue;
|
|
1990
|
+
const at = i * 4;
|
|
1991
|
+
const r = pixels[at] ?? 0;
|
|
1992
|
+
const g = pixels[at + 1] ?? 0;
|
|
1993
|
+
const b = pixels[at + 2] ?? 0;
|
|
1994
|
+
pixels[at] = 237.15 - 0.86 * (rr * r + rg * g + rb * b);
|
|
1995
|
+
pixels[at + 1] = 237.15 - 0.86 * (gr * r + gg * g + gb * b);
|
|
1996
|
+
pixels[at + 2] = 237.15 - 0.86 * (br * r + bg * g + bb * b);
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
return rgba;
|
|
2000
|
+
}
|
|
2001
|
+
function editText(area, key, mods) {
|
|
2002
|
+
const { value } = area;
|
|
2003
|
+
const start = area.selectionStart ?? 0;
|
|
2004
|
+
const end = area.selectionEnd ?? 0;
|
|
2005
|
+
const backward = area.selectionDirection === "backward";
|
|
2006
|
+
const anchor = backward ? end : start;
|
|
2007
|
+
const focus = backward ? start : end;
|
|
2008
|
+
const command = mods.ctrl || mods.meta;
|
|
2009
|
+
const lineStart = (at) => value.lastIndexOf("\n", at - 1) + 1;
|
|
2010
|
+
const lineEnd = (at) => {
|
|
2011
|
+
const newline = value.indexOf("\n", at);
|
|
2012
|
+
return newline === -1 ? value.length : newline;
|
|
2013
|
+
};
|
|
2014
|
+
const column = focus - lineStart(focus);
|
|
2015
|
+
const to = (() => {
|
|
2016
|
+
switch (key) {
|
|
2017
|
+
case "ArrowLeft":
|
|
2018
|
+
return start !== end && !mods.shift ? start : previous(value, focus);
|
|
2019
|
+
case "ArrowRight":
|
|
2020
|
+
return start !== end && !mods.shift ? end : next(value, focus);
|
|
2021
|
+
case "ArrowUp": {
|
|
2022
|
+
const above = lineStart(focus) - 1;
|
|
2023
|
+
return above < 0 ? 0 : Math.min(lineStart(above) + column, above);
|
|
2024
|
+
}
|
|
2025
|
+
case "ArrowDown": {
|
|
2026
|
+
const below = lineEnd(focus) + 1;
|
|
2027
|
+
return below > value.length ? value.length : Math.min(below + column, lineEnd(below));
|
|
2028
|
+
}
|
|
2029
|
+
case "Home":
|
|
2030
|
+
return lineStart(focus);
|
|
2031
|
+
case "End":
|
|
2032
|
+
return lineEnd(focus);
|
|
2033
|
+
}
|
|
2034
|
+
})();
|
|
2035
|
+
if (to !== void 0) {
|
|
2036
|
+
if (!mods.shift) area.setSelectionRange(to, to);
|
|
2037
|
+
else if (to < anchor) area.setSelectionRange(to, anchor, "backward");
|
|
2038
|
+
else area.setSelectionRange(anchor, to, "forward");
|
|
2039
|
+
} else if (key.toLowerCase() === "a" && command) {
|
|
2040
|
+
area.setSelectionRange(0, value.length);
|
|
2041
|
+
} else if (key === "Enter" && !command) {
|
|
2042
|
+
if (area.tagName === "TEXTAREA") replaceText(area, "\n", "insertLineBreak");
|
|
2043
|
+
} else if (key === "Backspace" || key === "Delete") {
|
|
2044
|
+
if (start === end) {
|
|
2045
|
+
const [from, to2] = key === "Backspace" ? [previous(value, start), start] : [end, next(value, end)];
|
|
2046
|
+
if (from === to2) return;
|
|
2047
|
+
area.setSelectionRange(from, to2);
|
|
2048
|
+
}
|
|
2049
|
+
replaceText(area, "", key === "Backspace" ? "deleteContentBackward" : "deleteContentForward");
|
|
2050
|
+
} else if ([...key].length === 1 && !command) {
|
|
2051
|
+
replaceText(area, key, "insertText");
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
function replaceText(area, text, inputType) {
|
|
2055
|
+
const { InputEvent } = area.ownerDocument.defaultView;
|
|
2056
|
+
const init = { inputType, data: text || null, bubbles: true };
|
|
2057
|
+
if (!area.dispatchEvent(new InputEvent("beforeinput", { ...init, cancelable: true }))) return;
|
|
2058
|
+
area.setRangeText(text, area.selectionStart ?? 0, area.selectionEnd ?? 0, "end");
|
|
2059
|
+
area.dispatchEvent(new InputEvent("input", init));
|
|
2060
|
+
}
|
|
2061
|
+
function previous(value, at) {
|
|
2062
|
+
return Math.max(0, at - ((value.codePointAt(at - 2) ?? 0) > 65535 ? 2 : 1));
|
|
2063
|
+
}
|
|
2064
|
+
function next(value, at) {
|
|
2065
|
+
return Math.min(value.length, at + ((value.codePointAt(at) ?? 0) > 65535 ? 2 : 1));
|
|
2066
|
+
}
|
|
2067
|
+
function wrappedIndex(value, wrapped, at) {
|
|
2068
|
+
let index = 0;
|
|
2069
|
+
for (let i = 0; i < at && index < wrapped.length; i++) {
|
|
2070
|
+
if (wrapped[index] === "\n" && value[i] !== "\n" && value[i] !== " ") i--;
|
|
2071
|
+
index++;
|
|
2072
|
+
}
|
|
2073
|
+
return index;
|
|
2074
|
+
}
|
|
2075
|
+
function modifierFlags(mods) {
|
|
2076
|
+
return { shiftKey: mods.shift, ctrlKey: mods.ctrl, altKey: mods.alt, metaKey: mods.meta };
|
|
2077
|
+
}
|
|
2078
|
+
var MODIFIER_FLAGS = {
|
|
2079
|
+
Shift: "shift",
|
|
2080
|
+
Control: "ctrl",
|
|
2081
|
+
Alt: "alt",
|
|
2082
|
+
Meta: "meta"
|
|
2083
|
+
};
|
|
2084
|
+
function keyMods(event) {
|
|
2085
|
+
const flag = MODIFIER_FLAGS[event.key];
|
|
2086
|
+
return flag ? { ...event.mods, [flag]: event.action === "down" } : event.mods;
|
|
2087
|
+
}
|
|
2088
|
+
function domKey(event) {
|
|
2089
|
+
if (event.key === "Space") return " ";
|
|
2090
|
+
if ([...event.key].length !== 1) return event.key;
|
|
2091
|
+
const commanding = event.mods.ctrl || event.mods.alt || event.mods.meta;
|
|
2092
|
+
if (!commanding && [...event.text].length === 1) return event.text;
|
|
2093
|
+
return event.mods.shift ? event.key.toUpperCase() : event.key;
|
|
2094
|
+
}
|
|
2095
|
+
var CODES = {
|
|
2096
|
+
Space: "Space",
|
|
2097
|
+
Shift: "ShiftLeft",
|
|
2098
|
+
Control: "ControlLeft",
|
|
2099
|
+
Alt: "AltLeft",
|
|
2100
|
+
Meta: "MetaLeft",
|
|
2101
|
+
"-": "Minus",
|
|
2102
|
+
"=": "Equal",
|
|
2103
|
+
"[": "BracketLeft",
|
|
2104
|
+
"]": "BracketRight",
|
|
2105
|
+
"\\": "Backslash",
|
|
2106
|
+
";": "Semicolon",
|
|
2107
|
+
"'": "Quote",
|
|
2108
|
+
",": "Comma",
|
|
2109
|
+
".": "Period",
|
|
2110
|
+
"/": "Slash",
|
|
2111
|
+
"`": "Backquote"
|
|
2112
|
+
};
|
|
2113
|
+
function domCode(key) {
|
|
2114
|
+
if (/^[a-z]$/i.test(key)) return `Key${key.toUpperCase()}`;
|
|
2115
|
+
if (/^[0-9]$/.test(key)) return `Digit${key}`;
|
|
2116
|
+
if (CODES[key]) return CODES[key];
|
|
2117
|
+
return [...key].length === 1 ? "" : key;
|
|
2118
|
+
}
|
|
2119
|
+
async function openPage(options) {
|
|
2120
|
+
let jsdom;
|
|
2121
|
+
let canvas;
|
|
2122
|
+
try {
|
|
2123
|
+
[jsdom, canvas] = await Promise.all([import("jsdom"), import("@napi-rs/canvas")]);
|
|
2124
|
+
} catch (error) {
|
|
2125
|
+
throw new Error(
|
|
2126
|
+
`excalidraw-tui needs the jsdom and @napi-rs/canvas packages (${error.message.split("\n")[0]}). Reinstall excalidraw-tui; @napi-rs/canvas has prebuilt binaries for macOS, Linux, and Windows.`
|
|
2127
|
+
);
|
|
2128
|
+
}
|
|
2129
|
+
setFlagsFromString("--external-memory-accounted-in-global-limit");
|
|
2130
|
+
canvas.setTextRenderer("system");
|
|
2131
|
+
registerFonts(canvas, join3(options.webDir, "fonts"));
|
|
2132
|
+
const dom = new jsdom.JSDOM('<!doctype html><body style="margin: 0"><div id="root"></div>', {
|
|
2133
|
+
url: "http://localhost/",
|
|
2134
|
+
pretendToBeVisual: true,
|
|
2135
|
+
// The page bundle runs through window.eval, and no <script> in the page runs or loads.
|
|
2136
|
+
runScripts: "outside-only",
|
|
2137
|
+
// Excalidraw's console output would draw over the editor.
|
|
2138
|
+
virtualConsole: new jsdom.VirtualConsole()
|
|
2139
|
+
});
|
|
2140
|
+
const window = dom.window;
|
|
2141
|
+
const size = { ...options.viewport };
|
|
2142
|
+
const scheduler = new Scheduler(window);
|
|
2143
|
+
const clipboard = { text: "" };
|
|
2144
|
+
stubBrowser(window, size, clipboard);
|
|
2145
|
+
const composite = window.document.createElement("canvas").getContext("2d");
|
|
2146
|
+
if (!composite) throw new Error("@napi-rs/canvas did not create a canvas.");
|
|
2147
|
+
const paintListeners = [];
|
|
2148
|
+
Object.assign(window, { Path2D: canvas.Path2D, Image: dataImage(canvas) });
|
|
2149
|
+
watchPaint(window, () => {
|
|
2150
|
+
for (const listener of paintListeners) listener();
|
|
2151
|
+
});
|
|
2152
|
+
Object.assign(window, {
|
|
2153
|
+
__scene: options.scene,
|
|
2154
|
+
__view: { transparent: options.transparent ?? false, theme: options.theme ?? "light" }
|
|
2155
|
+
});
|
|
2156
|
+
const dir = cacheDir();
|
|
2157
|
+
const cache = dir && join3(dir, "main.js.v8");
|
|
2158
|
+
let cachedData;
|
|
2159
|
+
try {
|
|
2160
|
+
cachedData = cache ? readFileSync2(cache) : void 0;
|
|
2161
|
+
} catch {
|
|
2162
|
+
}
|
|
2163
|
+
const source = readFileSync2(join3(options.webDir, "main.js"), "utf8");
|
|
2164
|
+
const script = new Script(source, { filename: "main.js", cachedData });
|
|
2165
|
+
script.runInContext(dom.getInternalVMContext());
|
|
2166
|
+
return {
|
|
2167
|
+
window,
|
|
2168
|
+
scheduler,
|
|
2169
|
+
size,
|
|
2170
|
+
composite,
|
|
2171
|
+
clipboard,
|
|
2172
|
+
dark: options.theme === "dark",
|
|
2173
|
+
overlay: new Overlay(window, size, options.theme === "dark", {
|
|
2174
|
+
Image: canvas.Image,
|
|
2175
|
+
layer: canvas.createCanvas(1, 1)
|
|
2176
|
+
}),
|
|
2177
|
+
onPaint: (listener) => paintListeners.push(listener),
|
|
2178
|
+
// After the first frame, so the cache also holds the functions compiled to draw it.
|
|
2179
|
+
saveCode() {
|
|
2180
|
+
if (!cache || cachedData && !script.cachedDataRejected) return;
|
|
2181
|
+
try {
|
|
2182
|
+
writeFileSync(`${cache}.${process.pid}`, script.createCachedData());
|
|
2183
|
+
renameSync(`${cache}.${process.pid}`, cache);
|
|
2184
|
+
} catch {
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
};
|
|
2188
|
+
}
|
|
2189
|
+
function watchPaint(window, onPaint) {
|
|
2190
|
+
const prototype = window.HTMLCanvasElement.prototype;
|
|
2191
|
+
const getContext = prototype.getContext;
|
|
2192
|
+
const watched = /* @__PURE__ */ new WeakSet();
|
|
2193
|
+
prototype.getContext = function(...args) {
|
|
2194
|
+
const context = getContext.apply(
|
|
2195
|
+
this,
|
|
2196
|
+
args
|
|
2197
|
+
);
|
|
2198
|
+
if (context && !watched.has(context)) {
|
|
2199
|
+
watched.add(context);
|
|
2200
|
+
const font = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(context), "font");
|
|
2201
|
+
let asked = "10px sans-serif";
|
|
2202
|
+
Object.defineProperty(context, "font", {
|
|
2203
|
+
get: () => asked,
|
|
2204
|
+
set(value) {
|
|
2205
|
+
asked = value;
|
|
2206
|
+
font?.set?.call(this, expandFont(value));
|
|
2207
|
+
}
|
|
2208
|
+
});
|
|
2209
|
+
for (const name of ["fillText", "strokeText", "measureText"]) {
|
|
2210
|
+
const draw = context[name];
|
|
2211
|
+
context[name] = function(text, ...a) {
|
|
2212
|
+
loadGlyphs(String(text));
|
|
2213
|
+
return draw.call(this, text, ...a);
|
|
2214
|
+
};
|
|
2215
|
+
}
|
|
2216
|
+
for (const name of PAINT) {
|
|
2217
|
+
const paint = context[name];
|
|
2218
|
+
context[name] = function(...a) {
|
|
2219
|
+
onPaint();
|
|
2220
|
+
return paint.apply(this, a);
|
|
2221
|
+
};
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
return context;
|
|
2225
|
+
};
|
|
2226
|
+
}
|
|
2227
|
+
function stubBrowser(window, size, clipboard) {
|
|
2228
|
+
const define = (target, values) => {
|
|
2229
|
+
for (const [name, get] of Object.entries(values)) {
|
|
2230
|
+
Object.defineProperty(target, name, { get, configurable: true });
|
|
2231
|
+
}
|
|
2232
|
+
};
|
|
2233
|
+
window.HTMLElement.prototype.getBoundingClientRect = () => {
|
|
2234
|
+
const { width, height } = size;
|
|
2235
|
+
return { x: 0, y: 0, left: 0, top: 0, right: width, bottom: height, width, height };
|
|
2236
|
+
};
|
|
2237
|
+
window.Element.prototype.scrollIntoView = () => {
|
|
2238
|
+
};
|
|
2239
|
+
define(window.HTMLElement.prototype, {
|
|
2240
|
+
offsetWidth: () => size.width,
|
|
2241
|
+
clientWidth: () => size.width,
|
|
2242
|
+
offsetHeight: () => size.height,
|
|
2243
|
+
clientHeight: () => size.height
|
|
2244
|
+
});
|
|
2245
|
+
define(window, {
|
|
2246
|
+
innerWidth: () => size.width,
|
|
2247
|
+
innerHeight: () => size.height,
|
|
2248
|
+
devicePixelRatio: () => size.scale
|
|
2249
|
+
});
|
|
2250
|
+
const platform = { darwin: "MacIntel", win32: "Win32" }[process.platform] ?? "Linux";
|
|
2251
|
+
define(window.navigator, {
|
|
2252
|
+
platform: () => platform,
|
|
2253
|
+
// Excalidraw copies with writeText and pastes from its context menu with readText. Reading
|
|
2254
|
+
// the system clipboard would need the terminal to ask the user each time, so a paste from
|
|
2255
|
+
// the menu gets what this editor copied last; a paste through the terminal brings any text.
|
|
2256
|
+
clipboard: () => ({
|
|
2257
|
+
writeText: async (text) => {
|
|
2258
|
+
clipboard.text = text;
|
|
2259
|
+
clipboard.onCopy?.(text);
|
|
2260
|
+
},
|
|
2261
|
+
readText: async () => clipboard.text
|
|
2262
|
+
})
|
|
2263
|
+
});
|
|
2264
|
+
const media = { matches: false, addListener() {
|
|
2265
|
+
}, removeListener() {
|
|
2266
|
+
} };
|
|
2267
|
+
Object.assign(window, {
|
|
2268
|
+
matchMedia: (query) => ({ ...media, media: query, ...noListeners }),
|
|
2269
|
+
ResizeObserver: class {
|
|
2270
|
+
observe() {
|
|
2271
|
+
}
|
|
2272
|
+
unobserve() {
|
|
2273
|
+
}
|
|
2274
|
+
disconnect() {
|
|
2275
|
+
}
|
|
2276
|
+
},
|
|
2277
|
+
// Fonts come from registerFonts, so a FontFace only has to say it loaded.
|
|
2278
|
+
FontFace: class {
|
|
2279
|
+
family;
|
|
2280
|
+
status = "loaded";
|
|
2281
|
+
constructor(family) {
|
|
2282
|
+
this.family = family;
|
|
2283
|
+
}
|
|
2284
|
+
load() {
|
|
2285
|
+
return Promise.resolve(this);
|
|
2286
|
+
}
|
|
2287
|
+
},
|
|
2288
|
+
// Excalidraw reads a paste from the ClipboardEvent's DataTransfer.
|
|
2289
|
+
DataTransfer: class {
|
|
2290
|
+
files = [];
|
|
2291
|
+
items = [];
|
|
2292
|
+
data = /* @__PURE__ */ new Map();
|
|
2293
|
+
get types() {
|
|
2294
|
+
return [...this.data.keys()];
|
|
2295
|
+
}
|
|
2296
|
+
getData(type) {
|
|
2297
|
+
return this.data.get(type) ?? "";
|
|
2298
|
+
}
|
|
2299
|
+
setData(type, value) {
|
|
2300
|
+
this.data.set(type, value);
|
|
2301
|
+
}
|
|
2302
|
+
},
|
|
2303
|
+
ClipboardEvent: class extends window.Event {
|
|
2304
|
+
clipboardData;
|
|
2305
|
+
constructor(type, init = {}) {
|
|
2306
|
+
super(type, init);
|
|
2307
|
+
this.clipboardData = init.clipboardData ?? null;
|
|
2308
|
+
}
|
|
2309
|
+
},
|
|
2310
|
+
// Nothing leaves the machine. jsdom has no fetch and loads no images, styles, scripts,
|
|
2311
|
+
// or frames unless asked; these are the two ways left to reach the network.
|
|
2312
|
+
XMLHttpRequest: blocked("XMLHttpRequest"),
|
|
2313
|
+
WebSocket: blocked("WebSocket")
|
|
2314
|
+
});
|
|
2315
|
+
window.document.elementFromPoint = () => window.document.querySelector("canvas.interactive");
|
|
2316
|
+
Object.defineProperty(window.document, "fonts", {
|
|
2317
|
+
value: {
|
|
2318
|
+
...noListeners,
|
|
2319
|
+
add() {
|
|
2320
|
+
},
|
|
2321
|
+
delete() {
|
|
2322
|
+
},
|
|
2323
|
+
has: () => true,
|
|
2324
|
+
check: () => true,
|
|
2325
|
+
load: () => Promise.resolve([]),
|
|
2326
|
+
ready: Promise.resolve(),
|
|
2327
|
+
[Symbol.iterator]: function* () {
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
});
|
|
2331
|
+
}
|
|
2332
|
+
var noListeners = { addEventListener() {
|
|
2333
|
+
}, removeEventListener() {
|
|
2334
|
+
} };
|
|
2335
|
+
function blocked(name) {
|
|
2336
|
+
return class {
|
|
2337
|
+
constructor() {
|
|
2338
|
+
throw new Error(`${name} is blocked: the editor does not use the network.`);
|
|
2339
|
+
}
|
|
2340
|
+
};
|
|
2341
|
+
}
|
|
2342
|
+
function dataImage(canvas) {
|
|
2343
|
+
const Base = canvas.Image;
|
|
2344
|
+
return class extends Base {
|
|
2345
|
+
#src = "";
|
|
2346
|
+
#handlers = {};
|
|
2347
|
+
// napi decodes now or later and calls these when it is done. It may call them inside the
|
|
2348
|
+
// src setter, where reading the image throws, so they hand off to the page's handlers on
|
|
2349
|
+
// the next turn of the event loop.
|
|
2350
|
+
#loaded = () => setTimeout(() => this.#handlers.load?.());
|
|
2351
|
+
#failed = (error) => setTimeout(() => this.#handlers.error?.(error));
|
|
2352
|
+
get onload() {
|
|
2353
|
+
return this.#loaded;
|
|
2354
|
+
}
|
|
2355
|
+
set onload(handler) {
|
|
2356
|
+
this.#handlers.load = handler;
|
|
2357
|
+
}
|
|
2358
|
+
get onerror() {
|
|
2359
|
+
return this.#failed;
|
|
2360
|
+
}
|
|
2361
|
+
set onerror(handler) {
|
|
2362
|
+
this.#handlers.error = handler;
|
|
2363
|
+
}
|
|
2364
|
+
get src() {
|
|
2365
|
+
return this.#src;
|
|
2366
|
+
}
|
|
2367
|
+
set src(value) {
|
|
2368
|
+
this.#src = String(value);
|
|
2369
|
+
const header = /^data:[^,]*;base64,/.exec(this.#src);
|
|
2370
|
+
if (!header) {
|
|
2371
|
+
this.#failed(new Error("only base64 data: URLs load"));
|
|
2372
|
+
return;
|
|
2373
|
+
}
|
|
2374
|
+
Reflect.set(
|
|
2375
|
+
Base.prototype,
|
|
2376
|
+
"src",
|
|
2377
|
+
Buffer.from(this.#src.slice(header[0].length), "base64"),
|
|
2378
|
+
this
|
|
2379
|
+
);
|
|
2380
|
+
}
|
|
2381
|
+
};
|
|
2382
|
+
}
|
|
2383
|
+
var Scheduler = class {
|
|
2384
|
+
callbacks = /* @__PURE__ */ new Map();
|
|
2385
|
+
nextId = 1;
|
|
2386
|
+
immediate;
|
|
2387
|
+
timer;
|
|
2388
|
+
inFrame = false;
|
|
2389
|
+
stopped = false;
|
|
2390
|
+
tasks = /* @__PURE__ */ new Set();
|
|
2391
|
+
constructor(window) {
|
|
2392
|
+
Object.assign(window, {
|
|
2393
|
+
requestAnimationFrame: (callback) => this.request(callback),
|
|
2394
|
+
cancelAnimationFrame: (id) => this.callbacks.delete(id),
|
|
2395
|
+
setImmediate: (callback, ...args) => {
|
|
2396
|
+
const task = setImmediate(() => {
|
|
2397
|
+
this.tasks.delete(task);
|
|
2398
|
+
if (!this.stopped) report2(() => callback(...args));
|
|
2399
|
+
});
|
|
2400
|
+
this.tasks.add(task);
|
|
2401
|
+
return task;
|
|
2402
|
+
},
|
|
2403
|
+
clearImmediate: (task) => {
|
|
2404
|
+
this.tasks.delete(task);
|
|
2405
|
+
clearImmediate(task);
|
|
2406
|
+
}
|
|
2407
|
+
});
|
|
2408
|
+
}
|
|
2409
|
+
busy() {
|
|
2410
|
+
return this.tasks.size > 0 || this.immediate !== void 0;
|
|
2411
|
+
}
|
|
2412
|
+
stop() {
|
|
2413
|
+
this.stopped = true;
|
|
2414
|
+
clearImmediate(this.immediate);
|
|
2415
|
+
clearTimeout(this.timer);
|
|
2416
|
+
for (const task of this.tasks) clearImmediate(task);
|
|
2417
|
+
this.tasks.clear();
|
|
2418
|
+
this.callbacks.clear();
|
|
2419
|
+
}
|
|
2420
|
+
request(callback) {
|
|
2421
|
+
const id = this.nextId++;
|
|
2422
|
+
this.callbacks.set(id, callback);
|
|
2423
|
+
if (this.stopped) return id;
|
|
2424
|
+
if (this.inFrame) this.timer ??= setTimeout(this.runFrame, 16);
|
|
2425
|
+
else this.immediate ??= setImmediate(this.runFrame);
|
|
2426
|
+
return id;
|
|
2427
|
+
}
|
|
2428
|
+
runFrame = () => {
|
|
2429
|
+
clearImmediate(this.immediate);
|
|
2430
|
+
clearTimeout(this.timer);
|
|
2431
|
+
this.immediate = void 0;
|
|
2432
|
+
this.timer = void 0;
|
|
2433
|
+
const callbacks = [...this.callbacks.values()];
|
|
2434
|
+
this.callbacks.clear();
|
|
2435
|
+
const time = performance.now();
|
|
2436
|
+
this.inFrame = true;
|
|
2437
|
+
for (const callback of callbacks) report2(() => callback(time));
|
|
2438
|
+
this.inFrame = false;
|
|
2439
|
+
};
|
|
2440
|
+
};
|
|
2441
|
+
function report2(run2) {
|
|
2442
|
+
try {
|
|
2443
|
+
run2();
|
|
2444
|
+
} catch {
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
// src/scene.ts
|
|
2449
|
+
import { readFileSync as readFileSync3, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
2450
|
+
function parseScene(text, source) {
|
|
2451
|
+
let data;
|
|
2452
|
+
try {
|
|
2453
|
+
data = JSON.parse(text);
|
|
2454
|
+
} catch (error) {
|
|
2455
|
+
throw new Error(`${source} is not JSON: ${error.message}`);
|
|
2456
|
+
}
|
|
2457
|
+
if (typeof data !== "object" || data === null) throw new Error(`${source} is not an object`);
|
|
2458
|
+
const scene = data;
|
|
2459
|
+
if (scene.type !== "excalidraw") throw new Error(`${source} has type ${String(scene.type)}`);
|
|
2460
|
+
if (!Array.isArray(scene.elements)) throw new Error(`${source} has no elements array`);
|
|
2461
|
+
return scene;
|
|
2462
|
+
}
|
|
2463
|
+
function readScene(path) {
|
|
2464
|
+
return parseScene(readFileSync3(path, "utf8"), path);
|
|
2465
|
+
}
|
|
2466
|
+
function writeScene(path, json) {
|
|
2467
|
+
const temporary = `${path}.tmp-${process.pid}`;
|
|
2468
|
+
writeFileSync2(temporary, json.endsWith("\n") ? json : `${json}
|
|
2469
|
+
`, { flag: "wx" });
|
|
2470
|
+
renameSync2(temporary, path);
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
// src/terminal.ts
|
|
2474
|
+
import { mkdtempSync, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
2475
|
+
import { tmpdir } from "node:os";
|
|
2476
|
+
import { join as join4 } from "node:path";
|
|
2477
|
+
|
|
2478
|
+
// src/kitty.ts
|
|
2479
|
+
var ESC2 = "\x1B";
|
|
2480
|
+
function graphics(control, payload = "") {
|
|
2481
|
+
return `${ESC2}_G${control};${payload}${ESC2}\\`;
|
|
2482
|
+
}
|
|
2483
|
+
function placeFile(id, path, columns, rows, rgba, z = 0) {
|
|
2484
|
+
return graphics(
|
|
2485
|
+
`a=T,f=32,s=${rgba.width},v=${rgba.height},t=t,i=${id},c=${columns},r=${rows},z=${z},q=2,C=1`,
|
|
2486
|
+
Buffer.from(path).toString("base64")
|
|
2487
|
+
);
|
|
2488
|
+
}
|
|
2489
|
+
function editFile(id, path, rect) {
|
|
2490
|
+
return graphics(
|
|
2491
|
+
`a=f,r=1,f=32,X=1,t=t,i=${id},x=${rect.x},y=${rect.y},s=${rect.width},v=${rect.height},q=2`,
|
|
2492
|
+
Buffer.from(path).toString("base64")
|
|
2493
|
+
);
|
|
2494
|
+
}
|
|
2495
|
+
function deleteAllImages() {
|
|
2496
|
+
return graphics("a=d,d=A,q=2");
|
|
2497
|
+
}
|
|
2498
|
+
var QUERY = [
|
|
2499
|
+
graphics("i=31,s=1,v=1,a=q,t=d,f=24", "AAAA"),
|
|
2500
|
+
`${ESC2}[14t`,
|
|
2501
|
+
`${ESC2}[16t`,
|
|
2502
|
+
`${ESC2}]11;?${ESC2}\\`,
|
|
2503
|
+
// background color, to pick a light or dark editor
|
|
2504
|
+
`${ESC2}[c`
|
|
2505
|
+
].join("");
|
|
2506
|
+
var KEYBOARD_FLAGS = 1 | 2 | 4 | 8 | 16;
|
|
2507
|
+
var ENTER = [
|
|
2508
|
+
`${ESC2}[?1049h`,
|
|
2509
|
+
// alternate screen
|
|
2510
|
+
`${ESC2}[?25l`,
|
|
2511
|
+
// hide cursor
|
|
2512
|
+
`${ESC2}[?1003h`,
|
|
2513
|
+
// report all mouse motion
|
|
2514
|
+
`${ESC2}[?1006h`,
|
|
2515
|
+
// SGR mouse encoding
|
|
2516
|
+
`${ESC2}[?1016h`,
|
|
2517
|
+
// SGR coordinates in pixels
|
|
2518
|
+
`${ESC2}[?2004h`,
|
|
2519
|
+
// bracketed paste
|
|
2520
|
+
`${ESC2}[>${KEYBOARD_FLAGS}u`
|
|
2521
|
+
].join("");
|
|
2522
|
+
var LEAVE = [
|
|
2523
|
+
deleteAllImages(),
|
|
2524
|
+
`${ESC2}[<u`,
|
|
2525
|
+
`${ESC2}[?2004l`,
|
|
2526
|
+
`${ESC2}[?1016l`,
|
|
2527
|
+
`${ESC2}[?1006l`,
|
|
2528
|
+
`${ESC2}[?1003l`,
|
|
2529
|
+
`${ESC2}[?25h`,
|
|
2530
|
+
`${ESC2}[?1049l`
|
|
2531
|
+
].join("");
|
|
2532
|
+
function copyToClipboard(text) {
|
|
2533
|
+
return `${ESC2}]52;c;${Buffer.from(text).toString("base64")}${ESC2}\\`;
|
|
2534
|
+
}
|
|
2535
|
+
function moveTo(row, column) {
|
|
2536
|
+
return `${ESC2}[${row};${column}H`;
|
|
2537
|
+
}
|
|
2538
|
+
function printable(text) {
|
|
2539
|
+
return text.replace(new RegExp("\\p{Cc}", "gu"), (c) => `\\x${c.charCodeAt(0).toString(16).padStart(2, "0")}`);
|
|
2540
|
+
}
|
|
2541
|
+
function statusLine(row, text, width) {
|
|
2542
|
+
const line = ` ${printable(text)}`.slice(0, width).padEnd(width);
|
|
2543
|
+
return `${moveTo(row, 1)}${ESC2}[7m${line}${ESC2}[0m`;
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2546
|
+
// src/terminal.ts
|
|
2547
|
+
var Terminal = class {
|
|
2548
|
+
parser = new InputParser();
|
|
2549
|
+
reports = [];
|
|
2550
|
+
onReport;
|
|
2551
|
+
listener;
|
|
2552
|
+
written = 0;
|
|
2553
|
+
frames = "";
|
|
2554
|
+
ime;
|
|
2555
|
+
active = false;
|
|
2556
|
+
input;
|
|
2557
|
+
output;
|
|
2558
|
+
constructor(input = process.stdin, output = process.stdout) {
|
|
2559
|
+
this.input = input;
|
|
2560
|
+
this.output = output;
|
|
2561
|
+
}
|
|
2562
|
+
get rows() {
|
|
2563
|
+
return this.output.rows;
|
|
2564
|
+
}
|
|
2565
|
+
get columns() {
|
|
2566
|
+
return this.output.columns;
|
|
2567
|
+
}
|
|
2568
|
+
enter() {
|
|
2569
|
+
this.active = true;
|
|
2570
|
+
this.frames = mkdtempSync(join4(tmpdir(), "tty-graphics-protocol-excalidraw-tui-"));
|
|
2571
|
+
this.input.setRawMode(true);
|
|
2572
|
+
this.input.setEncoding("utf8");
|
|
2573
|
+
this.input.on("data", this.handleData);
|
|
2574
|
+
this.input.resume();
|
|
2575
|
+
this.output.write(ENTER);
|
|
2576
|
+
}
|
|
2577
|
+
leave() {
|
|
2578
|
+
if (!this.active) return;
|
|
2579
|
+
this.active = false;
|
|
2580
|
+
this.output.write(LEAVE);
|
|
2581
|
+
rmSync(this.frames, { recursive: true, force: true });
|
|
2582
|
+
this.input.off("data", this.handleData);
|
|
2583
|
+
this.input.setRawMode(false);
|
|
2584
|
+
this.input.pause();
|
|
2585
|
+
}
|
|
2586
|
+
onEvent(listener) {
|
|
2587
|
+
this.listener = listener;
|
|
2588
|
+
}
|
|
2589
|
+
async query(timeoutMs = 2e3) {
|
|
2590
|
+
this.reports = [];
|
|
2591
|
+
const done = new Promise((resolve) => {
|
|
2592
|
+
const timer = setTimeout(resolve, timeoutMs);
|
|
2593
|
+
this.onReport = () => {
|
|
2594
|
+
if (this.reports.some((r) => r.type === "deviceAttributes")) {
|
|
2595
|
+
clearTimeout(timer);
|
|
2596
|
+
resolve();
|
|
2597
|
+
}
|
|
2598
|
+
};
|
|
2599
|
+
});
|
|
2600
|
+
this.output.write(QUERY);
|
|
2601
|
+
await done;
|
|
2602
|
+
this.onReport = void 0;
|
|
2603
|
+
const capabilities = { graphics: false };
|
|
2604
|
+
for (const report3 of this.reports) {
|
|
2605
|
+
if (report3.type === "graphics") capabilities.graphics = report3.ok;
|
|
2606
|
+
if (report3.type === "textArea") capabilities.textArea = report3;
|
|
2607
|
+
if (report3.type === "cell") capabilities.cell = report3;
|
|
2608
|
+
if (report3.type === "background") capabilities.backgroundLuminance = report3.luminance;
|
|
2609
|
+
}
|
|
2610
|
+
return capabilities;
|
|
2611
|
+
}
|
|
2612
|
+
// Each write gets its own file, since kitty reads and deletes it later than the next frame
|
|
2613
|
+
// may be written.
|
|
2614
|
+
draw(frame) {
|
|
2615
|
+
if (!this.active) return;
|
|
2616
|
+
const id = frame.layer === "scene" ? 1 : 2;
|
|
2617
|
+
this.written += 1;
|
|
2618
|
+
const path = join4(this.frames, `${id}-${this.written}.rgba`);
|
|
2619
|
+
writeFileSync3(path, frame.data);
|
|
2620
|
+
if (frame.rect) {
|
|
2621
|
+
this.output.write(editFile(id, path, frame.rect) + this.park());
|
|
2622
|
+
} else {
|
|
2623
|
+
const z = frame.layer === "scene" ? -2 : -1;
|
|
2624
|
+
const image = placeFile(id, path, this.columns, this.rows - 1, frame, z);
|
|
2625
|
+
this.output.write(moveTo(1, 1) + image + this.park());
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
// Where kitty draws an input method's preedit: the cell under the text caret while text is
|
|
2629
|
+
// being edited, or none. kitty puts the preedit at the cursor, hidden or not.
|
|
2630
|
+
imeAt(cell) {
|
|
2631
|
+
this.ime = cell;
|
|
2632
|
+
if (this.active) this.output.write(this.park());
|
|
2633
|
+
}
|
|
2634
|
+
park() {
|
|
2635
|
+
return this.ime ? moveTo(this.ime.row, this.ime.column) : moveTo(this.rows, 1);
|
|
2636
|
+
}
|
|
2637
|
+
// Put text on the system clipboard with OSC 52, which kitty allows by default.
|
|
2638
|
+
copy(text) {
|
|
2639
|
+
if (!this.active) return;
|
|
2640
|
+
this.output.write(copyToClipboard(text) + this.park());
|
|
2641
|
+
}
|
|
2642
|
+
clear() {
|
|
2643
|
+
if (!this.active) return;
|
|
2644
|
+
this.output.write(`${deleteAllImages()}\x1B[2J`);
|
|
2645
|
+
}
|
|
2646
|
+
status(text) {
|
|
2647
|
+
if (!this.active) return;
|
|
2648
|
+
this.output.write(statusLine(this.rows, text, this.columns) + this.park());
|
|
2649
|
+
}
|
|
2650
|
+
handleData = (chunk) => {
|
|
2651
|
+
for (const event of this.parser.feed(chunk)) {
|
|
2652
|
+
if (event.kind === "report") {
|
|
2653
|
+
this.reports.push(event.report);
|
|
2654
|
+
this.onReport?.();
|
|
2655
|
+
} else {
|
|
2656
|
+
this.listener?.(event);
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
};
|
|
2660
|
+
};
|
|
2661
|
+
|
|
2662
|
+
// src/app.ts
|
|
2663
|
+
var HELP = "Ctrl+S save Ctrl+Q quit";
|
|
2664
|
+
function viewportFor(capabilities, rows, scale) {
|
|
2665
|
+
const { textArea, cell } = capabilities;
|
|
2666
|
+
if (!textArea || !cell || !textArea.width || !cell.height) {
|
|
2667
|
+
throw new Error("The terminal did not report its size in pixels.");
|
|
2668
|
+
}
|
|
2669
|
+
const s = scale ?? (cell.height >= 28 ? 2 : 1);
|
|
2670
|
+
const imageHeight = Math.min(textArea.height, (rows - 1) * cell.height);
|
|
2671
|
+
return {
|
|
2672
|
+
width: Math.floor(textArea.width / s),
|
|
2673
|
+
height: Math.floor(imageHeight / s),
|
|
2674
|
+
scale: s
|
|
2675
|
+
};
|
|
2676
|
+
}
|
|
2677
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
2678
|
+
var Interrupted = class extends Error {
|
|
2679
|
+
signal;
|
|
2680
|
+
constructor(signal) {
|
|
2681
|
+
super(`interrupted by ${signal}`);
|
|
2682
|
+
this.signal = signal;
|
|
2683
|
+
}
|
|
2684
|
+
};
|
|
2685
|
+
async function run(file, options) {
|
|
2686
|
+
const scene = existsSync(file) ? readScene(file) : null;
|
|
2687
|
+
const terminal = new Terminal();
|
|
2688
|
+
let abort = () => {
|
|
2689
|
+
};
|
|
2690
|
+
const aborted = new Promise((_, reject) => {
|
|
2691
|
+
abort = reject;
|
|
2692
|
+
});
|
|
2693
|
+
aborted.catch(() => {
|
|
2694
|
+
});
|
|
2695
|
+
const onSignal = (signal) => abort(new Interrupted(signal));
|
|
2696
|
+
for (const signal of SIGNALS) process.on(signal, onSignal);
|
|
2697
|
+
const restore = () => terminal.leave();
|
|
2698
|
+
process.on("exit", restore);
|
|
2699
|
+
let opening;
|
|
2700
|
+
try {
|
|
2701
|
+
terminal.enter();
|
|
2702
|
+
const capabilities = await Promise.race([terminal.query(), aborted]);
|
|
2703
|
+
if (!capabilities.graphics) {
|
|
2704
|
+
throw new Error(
|
|
2705
|
+
"This terminal does not support the kitty graphics protocol. Run excalidraw-tui in kitty."
|
|
2706
|
+
);
|
|
2707
|
+
}
|
|
2708
|
+
opening = Editor.open({
|
|
2709
|
+
scene,
|
|
2710
|
+
viewport: viewportFor(capabilities, terminal.rows, options.scale),
|
|
2711
|
+
webDir: options.webDir,
|
|
2712
|
+
transparent: true,
|
|
2713
|
+
theme: (capabilities.backgroundLuminance ?? 0) < 0.5 ? "dark" : "light"
|
|
2714
|
+
});
|
|
2715
|
+
const editor = await Promise.race([opening, aborted]);
|
|
2716
|
+
editor.onClipboard((text) => terminal.copy(text));
|
|
2717
|
+
await Promise.race([session(file, terminal, editor, capabilities, options.scale), aborted]);
|
|
2718
|
+
} finally {
|
|
2719
|
+
terminal.leave();
|
|
2720
|
+
process.off("exit", restore);
|
|
2721
|
+
for (const signal of SIGNALS) process.off(signal, onSignal);
|
|
2722
|
+
await opening?.then((editor) => editor.close()).catch(() => {
|
|
2723
|
+
});
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
async function session(file, terminal, editor, initialCapabilities, scale) {
|
|
2727
|
+
const name = basename(file);
|
|
2728
|
+
let capabilities = initialCapabilities;
|
|
2729
|
+
let savedVersion = -1;
|
|
2730
|
+
let confirmQuit = false;
|
|
2731
|
+
let notice = "";
|
|
2732
|
+
const show = async () => {
|
|
2733
|
+
const dirty = await editor.version() !== savedVersion;
|
|
2734
|
+
terminal.status(`${name}${dirty ? " (modified)" : ""} ${notice || HELP}`);
|
|
2735
|
+
};
|
|
2736
|
+
await editor.onFrame((frame) => {
|
|
2737
|
+
terminal.draw(frame);
|
|
2738
|
+
});
|
|
2739
|
+
if (existsSync(file)) savedVersion = await editor.version();
|
|
2740
|
+
await show();
|
|
2741
|
+
await new Promise((resolve, reject) => {
|
|
2742
|
+
let queue = Promise.resolve();
|
|
2743
|
+
const handle = async (event) => {
|
|
2744
|
+
if (isShortcut(event, "s")) {
|
|
2745
|
+
try {
|
|
2746
|
+
const json = await editor.serialize();
|
|
2747
|
+
parseScene(json, "the editor's drawing");
|
|
2748
|
+
writeScene(file, json);
|
|
2749
|
+
savedVersion = await editor.version();
|
|
2750
|
+
notice = `saved ${name}`;
|
|
2751
|
+
} catch (error) {
|
|
2752
|
+
notice = `save failed: ${error.message}`;
|
|
2753
|
+
}
|
|
2754
|
+
confirmQuit = false;
|
|
2755
|
+
return show();
|
|
2756
|
+
}
|
|
2757
|
+
if (isShortcut(event, "q")) {
|
|
2758
|
+
const dirty = await editor.version() !== savedVersion;
|
|
2759
|
+
if (!dirty || confirmQuit) return resolve();
|
|
2760
|
+
confirmQuit = true;
|
|
2761
|
+
notice = "unsaved changes: Ctrl+S to save, Ctrl+Q again to quit";
|
|
2762
|
+
return show();
|
|
2763
|
+
}
|
|
2764
|
+
await editor.input(event);
|
|
2765
|
+
const caret = editor.caret();
|
|
2766
|
+
const cell = capabilities.cell;
|
|
2767
|
+
terminal.imeAt(
|
|
2768
|
+
caret && cell ? {
|
|
2769
|
+
row: Math.floor(caret.y / cell.height) + 1,
|
|
2770
|
+
column: Math.floor(caret.x / cell.width) + 1
|
|
2771
|
+
} : void 0
|
|
2772
|
+
);
|
|
2773
|
+
const passive = event.kind === "mouse" && event.action === "move" || event.kind === "key" && event.action === "up" && !event.swallowed;
|
|
2774
|
+
if (!passive) {
|
|
2775
|
+
notice = "";
|
|
2776
|
+
await show();
|
|
2777
|
+
}
|
|
2778
|
+
};
|
|
2779
|
+
const pending2 = [];
|
|
2780
|
+
const drain = async () => {
|
|
2781
|
+
const next2 = () => takeNext(pending2);
|
|
2782
|
+
for (let event = next2(); event; event = next2()) await handle(event);
|
|
2783
|
+
};
|
|
2784
|
+
terminal.onEvent((event) => {
|
|
2785
|
+
pending2.push(event);
|
|
2786
|
+
queue = queue.then(drain).catch(reject);
|
|
2787
|
+
});
|
|
2788
|
+
process.stdout.on("resize", () => {
|
|
2789
|
+
queue = queue.then(async () => {
|
|
2790
|
+
capabilities = await terminal.query();
|
|
2791
|
+
terminal.clear();
|
|
2792
|
+
await editor.resize(viewportFor(capabilities, terminal.rows, scale));
|
|
2793
|
+
await show();
|
|
2794
|
+
}).catch(reject);
|
|
2795
|
+
});
|
|
2796
|
+
});
|
|
2797
|
+
}
|
|
2798
|
+
|
|
2799
|
+
// src/cli.ts
|
|
2800
|
+
var USAGE = `Usage:
|
|
2801
|
+
excalidraw-tui [--scale N] <file.excalidraw>
|
|
2802
|
+
excalidraw-tui export <file.excalidraw> --out <file.png> [--scale N]
|
|
2803
|
+
|
|
2804
|
+
Edits the drawing in the kitty terminal with the real Excalidraw editor, which runs inside
|
|
2805
|
+
excalidraw-tui with no browser, its toolbar, properties panel, zoom and undo buttons, and
|
|
2806
|
+
context menu drawn in the terminal. Ctrl+S saves, Ctrl+Q quits. The file is created on the
|
|
2807
|
+
first save if it does not exist. The main menu, the library, and inserting images are left
|
|
2808
|
+
out.`;
|
|
2809
|
+
var webDir = join5(dirname(fileURLToPath(import.meta.url)), "web");
|
|
2810
|
+
async function exportPng(input, output, scale) {
|
|
2811
|
+
const editor = await Editor.open({
|
|
2812
|
+
scene: readScene(input),
|
|
2813
|
+
viewport: { width: 800, height: 600, scale: 1 },
|
|
2814
|
+
webDir
|
|
2815
|
+
});
|
|
2816
|
+
try {
|
|
2817
|
+
writeFileSync4(output, await editor.exportPng(scale));
|
|
2818
|
+
} finally {
|
|
2819
|
+
await editor.close();
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
async function main(argv) {
|
|
2823
|
+
const dir = cacheDir();
|
|
2824
|
+
if (dir) module.enableCompileCache?.(join5(dir, "node"));
|
|
2825
|
+
const { values, positionals } = parseArgs({
|
|
2826
|
+
args: argv,
|
|
2827
|
+
allowPositionals: true,
|
|
2828
|
+
options: {
|
|
2829
|
+
out: { type: "string", short: "o" },
|
|
2830
|
+
scale: { type: "string" },
|
|
2831
|
+
help: { type: "boolean", short: "h" }
|
|
2832
|
+
}
|
|
2833
|
+
});
|
|
2834
|
+
const scale = values.scale === void 0 ? void 0 : Number(values.scale);
|
|
2835
|
+
if (scale !== void 0 && !(scale > 0)) throw new Error("--scale must be a positive number");
|
|
2836
|
+
if (values.help || positionals.length === 0) {
|
|
2837
|
+
console.log(USAGE);
|
|
2838
|
+
return;
|
|
2839
|
+
}
|
|
2840
|
+
if (positionals[0] === "export") {
|
|
2841
|
+
const input = positionals[1];
|
|
2842
|
+
if (!input || !values.out) throw new Error(USAGE);
|
|
2843
|
+
await exportPng(input, values.out, scale ?? 2);
|
|
2844
|
+
return;
|
|
2845
|
+
}
|
|
2846
|
+
const file = positionals[0];
|
|
2847
|
+
if (!file || positionals.length > 1) throw new Error(USAGE);
|
|
2848
|
+
await run(file, { webDir, scale });
|
|
2849
|
+
}
|
|
2850
|
+
main(process.argv.slice(2)).catch((error) => {
|
|
2851
|
+
if (error instanceof Interrupted) {
|
|
2852
|
+
process.exitCode = error.signal === "SIGINT" ? 130 : 143;
|
|
2853
|
+
return;
|
|
2854
|
+
}
|
|
2855
|
+
console.error(error.message.split("\n").map(printable).join("\n"));
|
|
2856
|
+
process.exitCode = 1;
|
|
2857
|
+
});
|
|
2858
|
+
export {
|
|
2859
|
+
exportPng
|
|
2860
|
+
};
|