cd-aichat 1.0.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/README.md +188 -0
- package/dist/ailogo.png +0 -0
- package/dist/cd-aichat.css +1 -0
- package/dist/cd-aichat.es.js +32223 -0
- package/dist/cd-aichat.umd.js +279 -0
- package/dist/index.css +1 -0
- package/package.json +61 -0
- package/src/ailogo.png +0 -0
- package/src/components/AiChat.test.js +538 -0
- package/src/components/AiChat.vue +2206 -0
- package/src/components/AiChatWidget.test.js +312 -0
- package/src/components/AiChatWidget.vue +963 -0
- package/src/components/BurnAfterReadDialog.test.js +121 -0
- package/src/components/BurnAfterReadDialog.vue +511 -0
- package/src/components/BurnAfterReadMessage.test.js +188 -0
- package/src/components/BurnAfterReadMessage.vue +193 -0
- package/src/components/BurnIndicator.test.js +101 -0
- package/src/components/BurnIndicator.vue +164 -0
- package/src/components/ChatWindow.vue +0 -0
- package/src/components/MentionList.vue +163 -0
- package/src/components/ResourceList.vue +194 -0
- package/src/components/RichTextEditor.vue +437 -0
- package/src/components/ScheduledSendDialog.vue +476 -0
- package/src/components/ScreenshotOverlay.vue +78 -0
- package/src/components/SendButtonGroup.test.js +174 -0
- package/src/components/SendButtonGroup.vue +166 -0
- package/src/components/UserDrawer.vue +0 -0
- package/src/components/screenshot/ScreenshotsBackground/getBoundsByPoints.ts +41 -0
- package/src/components/screenshot/ScreenshotsBackground/index.scss +27 -0
- package/src/components/screenshot/ScreenshotsBackground/index.tsx +145 -0
- package/src/components/screenshot/ScreenshotsButton/index.scss +29 -0
- package/src/components/screenshot/ScreenshotsButton/index.tsx +58 -0
- package/src/components/screenshot/ScreenshotsCanvas/getBoundsByPoints.ts +55 -0
- package/src/components/screenshot/ScreenshotsCanvas/getPoints.ts +60 -0
- package/src/components/screenshot/ScreenshotsCanvas/index.scss +84 -0
- package/src/components/screenshot/ScreenshotsCanvas/index.tsx +277 -0
- package/src/components/screenshot/ScreenshotsCanvas/isPointInDraw.ts +35 -0
- package/src/components/screenshot/ScreenshotsColor/index.scss +45 -0
- package/src/components/screenshot/ScreenshotsColor/index.tsx +39 -0
- package/src/components/screenshot/ScreenshotsContext.ts +56 -0
- package/src/components/screenshot/ScreenshotsMagnifier/index.scss +61 -0
- package/src/components/screenshot/ScreenshotsMagnifier/index.tsx +126 -0
- package/src/components/screenshot/ScreenshotsOperations/index.scss +25 -0
- package/src/components/screenshot/ScreenshotsOperations/index.tsx +118 -0
- package/src/components/screenshot/ScreenshotsOption/index.scss +50 -0
- package/src/components/screenshot/ScreenshotsOption/index.tsx +150 -0
- package/src/components/screenshot/ScreenshotsSize/index.scss +28 -0
- package/src/components/screenshot/ScreenshotsSize/index.tsx +41 -0
- package/src/components/screenshot/ScreenshotsSizeColor/index.scss +8 -0
- package/src/components/screenshot/ScreenshotsSizeColor/index.tsx +25 -0
- package/src/components/screenshot/ScreenshotsTextarea/calculateNodeSize.ts +117 -0
- package/src/components/screenshot/ScreenshotsTextarea/index.scss +19 -0
- package/src/components/screenshot/ScreenshotsTextarea/index.tsx +96 -0
- package/src/components/screenshot/composeImage.ts +57 -0
- package/src/components/screenshot/exports.ts +4 -0
- package/src/components/screenshot/hooks/useBounds.ts +35 -0
- package/src/components/screenshot/hooks/useCall.ts +17 -0
- package/src/components/screenshot/hooks/useCanvasContextRef.ts +8 -0
- package/src/components/screenshot/hooks/useCanvasMousedown.ts +13 -0
- package/src/components/screenshot/hooks/useCanvasMousemove.ts +13 -0
- package/src/components/screenshot/hooks/useCanvasMouseup.ts +13 -0
- package/src/components/screenshot/hooks/useCursor.ts +34 -0
- package/src/components/screenshot/hooks/useDispatcher.ts +8 -0
- package/src/components/screenshot/hooks/useDrawSelect.ts +16 -0
- package/src/components/screenshot/hooks/useEmiter.ts +61 -0
- package/src/components/screenshot/hooks/useHistory.ts +160 -0
- package/src/components/screenshot/hooks/useLang.ts +8 -0
- package/src/components/screenshot/hooks/useOperation.ts +37 -0
- package/src/components/screenshot/hooks/useReset.ts +26 -0
- package/src/components/screenshot/hooks/useStore.ts +8 -0
- package/src/components/screenshot/icons/iconfont.scss +88 -0
- package/src/components/screenshot/icons/iconfont.ttf +0 -0
- package/src/components/screenshot/icons/iconfont.woff +0 -0
- package/src/components/screenshot/icons/iconfont.woff2 +0 -0
- package/src/components/screenshot/index.tsx +169 -0
- package/src/components/screenshot/operations/Arrow/draw.ts +56 -0
- package/src/components/screenshot/operations/Arrow/index.tsx +193 -0
- package/src/components/screenshot/operations/Brush/draw.ts +45 -0
- package/src/components/screenshot/operations/Brush/index.tsx +169 -0
- package/src/components/screenshot/operations/Cancel/index.tsx +18 -0
- package/src/components/screenshot/operations/Ellipse/draw.ts +96 -0
- package/src/components/screenshot/operations/Ellipse/index.tsx +245 -0
- package/src/components/screenshot/operations/Mosaic/index.tsx +223 -0
- package/src/components/screenshot/operations/Ok/index.tsx +37 -0
- package/src/components/screenshot/operations/Pin/index.tsx +37 -0
- package/src/components/screenshot/operations/Rectangle/draw.ts +80 -0
- package/src/components/screenshot/operations/Rectangle/index.tsx +245 -0
- package/src/components/screenshot/operations/Redo/index.tsx +22 -0
- package/src/components/screenshot/operations/Save/index.tsx +37 -0
- package/src/components/screenshot/operations/Scan/index.tsx +46 -0
- package/src/components/screenshot/operations/Search/index.tsx +39 -0
- package/src/components/screenshot/operations/Text/index.tsx +307 -0
- package/src/components/screenshot/operations/Undo/index.tsx +22 -0
- package/src/components/screenshot/operations/index.ts +34 -0
- package/src/components/screenshot/operations/utils.ts +34 -0
- package/src/components/screenshot/screenshots.scss +13 -0
- package/src/components/screenshot/types.ts +53 -0
- package/src/components/screenshot/useGetLoadedImage.ts +29 -0
- package/src/components/screenshot/var.scss +107 -0
- package/src/components/screenshot/zh_CN.ts +37 -0
- package/src/emoji/100.gif +0 -0
- package/src/emoji/101.gif +0 -0
- package/src/emoji/102.gif +0 -0
- package/src/emoji/103.gif +0 -0
- package/src/emoji/104.gif +0 -0
- package/src/emoji/105.gif +0 -0
- package/src/emoji/106.gif +0 -0
- package/src/emoji/107.gif +0 -0
- package/src/emoji/108.gif +0 -0
- package/src/emoji/109.gif +0 -0
- package/src/emoji/110.gif +0 -0
- package/src/emoji/111.gif +0 -0
- package/src/emoji/112.gif +0 -0
- package/src/emoji/113.gif +0 -0
- package/src/emoji/114.gif +0 -0
- package/src/emoji/115.gif +0 -0
- package/src/emoji/116.gif +0 -0
- package/src/emoji/117.gif +0 -0
- package/src/emoji/118.gif +0 -0
- package/src/emoji/119.gif +0 -0
- package/src/emoji/120.gif +0 -0
- package/src/emoji/121.gif +0 -0
- package/src/emoji/122.gif +0 -0
- package/src/emoji/123.gif +0 -0
- package/src/emoji/124.gif +0 -0
- package/src/emoji/125.gif +0 -0
- package/src/emoji/126.gif +0 -0
- package/src/emoji/127.gif +0 -0
- package/src/emoji/128.gif +0 -0
- package/src/emoji/129.gif +0 -0
- package/src/emoji/130.gif +0 -0
- package/src/emoji/131.gif +0 -0
- package/src/emoji/132.gif +0 -0
- package/src/emoji/133.gif +0 -0
- package/src/emoji/134.gif +0 -0
- package/src/emoji/135.gif +0 -0
- package/src/emoji/136.gif +0 -0
- package/src/emoji/137.gif +0 -0
- package/src/emoji/138.gif +0 -0
- package/src/emoji/139.gif +0 -0
- package/src/emoji/140.gif +0 -0
- package/src/emoji/141.gif +0 -0
- package/src/emoji/142.gif +0 -0
- package/src/emoji/143.gif +0 -0
- package/src/emoji/144.gif +0 -0
- package/src/emoji/145.gif +0 -0
- package/src/emoji/146.gif +0 -0
- package/src/emoji/147.gif +0 -0
- package/src/emoji/148.gif +0 -0
- package/src/emoji/149.gif +0 -0
- package/src/emoji/150.gif +0 -0
- package/src/emoji/151.gif +0 -0
- package/src/emoji/152.gif +0 -0
- package/src/emoji/153.gif +0 -0
- package/src/emoji/154.gif +0 -0
- package/src/emoji/155.gif +0 -0
- package/src/emoji/156.gif +0 -0
- package/src/emoji/157.gif +0 -0
- package/src/emoji/158.gif +0 -0
- package/src/emoji/159.gif +0 -0
- package/src/emoji/160.gif +0 -0
- package/src/emoji/161.gif +0 -0
- package/src/emoji/162.gif +0 -0
- package/src/emoji/163.gif +0 -0
- package/src/emoji/164.gif +0 -0
- package/src/emoji/165.gif +0 -0
- package/src/emoji/166.gif +0 -0
- package/src/emoji/167.gif +0 -0
- package/src/emoji/168.gif +0 -0
- package/src/emoji/169.gif +0 -0
- package/src/emoji/170.gif +0 -0
- package/src/emoji/171.gif +0 -0
- package/src/emoji/172.gif +0 -0
- package/src/emoji/173.gif +0 -0
- package/src/emoji/174.gif +0 -0
- package/src/emoji/175.gif +0 -0
- package/src/emoji/176.gif +0 -0
- package/src/emoji/177.gif +0 -0
- package/src/emoji/178.gif +0 -0
- package/src/emoji/179.gif +0 -0
- package/src/emoji/180.gif +0 -0
- package/src/emoji/181.gif +0 -0
- package/src/emoji/182.gif +0 -0
- package/src/emoji/183.gif +0 -0
- package/src/emoji/184.gif +0 -0
- package/src/emoji/185.gif +0 -0
- package/src/emoji/186.gif +0 -0
- package/src/emoji/187.gif +0 -0
- package/src/emoji/188.gif +0 -0
- package/src/emoji/189.gif +0 -0
- package/src/emoji/190.gif +0 -0
- package/src/emoji/191.gif +0 -0
- package/src/emoji/192.gif +0 -0
- package/src/emoji/193.gif +0 -0
- package/src/emoji/194.gif +0 -0
- package/src/emoji/195.gif +0 -0
- package/src/emoji/196.gif +0 -0
- package/src/emoji/197.gif +0 -0
- package/src/emoji/198.gif +0 -0
- package/src/emoji/199.gif +0 -0
- package/src/emoji/200.png +0 -0
- package/src/emoji/201.png +0 -0
- package/src/emoji/202.png +0 -0
- package/src/emoji/203.png +0 -0
- package/src/emoji/204.png +0 -0
- package/src/emoji/205.png +0 -0
- package/src/emoji/206.png +0 -0
- package/src/emoji/207.png +0 -0
- package/src/emoji/208.png +0 -0
- package/src/emoji/209.png +0 -0
- package/src/emoji/210.png +0 -0
- package/src/emoji/211.png +0 -0
- package/src/emoji/212.png +0 -0
- package/src/emoji/213.png +0 -0
- package/src/emoji/214.png +0 -0
- package/src/emoji/215.png +0 -0
- package/src/emoji/216.png +0 -0
- package/src/emoji/217.png +0 -0
- package/src/emoji/218.png +0 -0
- package/src/emoji/219.png +0 -0
- package/src/emoji2/101--Streamline-The-Team.png +0 -0
- package/src/emoji2/128--Streamline-The-Team.png +0 -0
- package/src/emoji2/134--Streamline-The-Team.png +0 -0
- package/src/emoji2/173--Streamline-The-Team.png +0 -0
- package/src/emoji2/Airplane--Streamline-Emoji.svg +24 -0
- package/src/emoji2/Alien--Streamline-Emoji.svg +21 -0
- package/src/emoji2/Amazed-Face--Streamline-Emoji.svg +16 -0
- package/src/emoji2/Amusing-Face--Streamline-Emoji.svg +20 -0
- package/src/emoji2/Anguished-Face--Streamline-Emoji.svg +19 -0
- package/src/emoji2/Anxious-Face--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Astonished-Face--Streamline-Emoji.svg +20 -0
- package/src/emoji2/Backhand-Index-Pointing-Down-1--Streamline-Emoji.svg +12 -0
- package/src/emoji2/Backhand-Index-Pointing-Left-1--Streamline-Emoji.svg +13 -0
- package/src/emoji2/Backhand-Index-Pointing-Right-1--Streamline-Emoji.svg +13 -0
- package/src/emoji2/Backhand-Index-Pointing-Up-1--Streamline-Emoji.svg +14 -0
- package/src/emoji2/Bar-Chart--Streamline-Emoji.svg +22 -0
- package/src/emoji2/Beaming-Face-With-Smiling-Eyes--Streamline-Emoji.svg +20 -0
- package/src/emoji2/Boy-1--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Boy-2--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Boy-3--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Broken-Heart--Streamline-Emoji.svg +12 -0
- package/src/emoji2/Clapping-Hands-1--Streamline-Emoji.svg +23 -0
- package/src/emoji2/Clinking-Glasses-2--Streamline-Emoji.svg +43 -0
- package/src/emoji2/Confounded-Face--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Confused-Face--Streamline-Emoji.svg +15 -0
- package/src/emoji2/Construction-Worker--Streamline-Emoji.svg +21 -0
- package/src/emoji2/Couple-With-Heart-Woman-Man-1--Streamline-Emoji.svg +40 -0
- package/src/emoji2/Couple-With-Heart-Woman-Man-2--Streamline-Emoji.svg +40 -0
- package/src/emoji2/Cowboy-Hat-Face--Streamline-Emoji.svg +22 -0
- package/src/emoji2/Crazy-Face--Streamline-Emoji.svg +25 -0
- package/src/emoji2/Crossed-Fingers-1--Streamline-Emoji.svg +25 -0
- package/src/emoji2/Crown--Streamline-Emoji.svg +35 -0
- package/src/emoji2/Crying-Face--Streamline-Emoji.svg +26 -0
- package/src/emoji2/Delivery-Truck--Streamline-Emoji.svg +31 -0
- package/src/emoji2/Determined-Face--Streamline-Emoji.svg +25 -0
- package/src/emoji2/Disappointed-Face--Streamline-Emoji.svg +15 -0
- package/src/emoji2/Dizzy-Face--Streamline-Emoji.svg +20 -0
- package/src/emoji2/Downcast-Face-With-Sweat--Streamline-Emoji.svg +18 -0
- package/src/emoji2/Drooling-Face-1--Streamline-Emoji.svg +19 -0
- package/src/emoji2/Drooling-Face-2--Streamline-Emoji.svg +18 -0
- package/src/emoji2/Ear--Streamline-Emoji.svg +14 -0
- package/src/emoji2/Exclamation-Mark--Streamline-Emoji.svg +12 -0
- package/src/emoji2/Exploding-Head--Streamline-Emoji.svg +24 -0
- package/src/emoji2/Expressionless-Face--Streamline-Emoji.svg +15 -0
- package/src/emoji2/Face-Blowing-A-Kiss--Streamline-Emoji.svg +18 -0
- package/src/emoji2/Face-Savoring-Food--Streamline-Emoji.svg +18 -0
- package/src/emoji2/Face-Screaming-In-Fear--Streamline-Emoji.svg +18 -0
- package/src/emoji2/Face-Vomiting--Streamline-Emoji.svg +28 -0
- package/src/emoji2/Face-With-Head-Bandage--Streamline-Emoji.svg +25 -0
- package/src/emoji2/Face-With-Medical-Mask--Streamline-Emoji.svg +23 -0
- package/src/emoji2/Face-With-Monocle--Streamline-Emoji.svg +26 -0
- package/src/emoji2/Face-With-Raised-Eyebrow--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Face-With-Rolling-Eyes--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Face-With-Steam-From-Nose--Streamline-Emoji.svg +19 -0
- package/src/emoji2/Face-With-Symbols-On-Mouth--Streamline-Emoji.svg +22 -0
- package/src/emoji2/Face-With-Tears-Of-Joy--Streamline-Emoji.svg +34 -0
- package/src/emoji2/Face-With-Thermometer--Streamline-Emoji.svg +31 -0
- package/src/emoji2/Face-With-Tongue--Streamline-Emoji.svg +18 -0
- package/src/emoji2/Face-Without-Mouth--Streamline-Emoji.svg +14 -0
- package/src/emoji2/Fearful-Face--Streamline-Emoji.svg +18 -0
- package/src/emoji2/Flexed-Biceps-1--Streamline-Emoji.svg +13 -0
- package/src/emoji2/Flushed-Face--Streamline-Emoji.svg +19 -0
- package/src/emoji2/Folded-Hands-1--Streamline-Emoji.svg +29 -0
- package/src/emoji2/Frowning-Face--Streamline-Emoji.svg +15 -0
- package/src/emoji2/Fuel-Pump--Streamline-Emoji.svg +30 -0
- package/src/emoji2/Girl-1--Streamline-Emoji.svg +23 -0
- package/src/emoji2/Glasses-1--Streamline-Emoji.svg +27 -0
- package/src/emoji2/Grimacing-Face--Streamline-Emoji.svg +19 -0
- package/src/emoji2/Grinning-Cat-Face--Streamline-Emoji.svg +32 -0
- package/src/emoji2/Grinning-Face--Streamline-Emoji.svg +16 -0
- package/src/emoji2/Grinning-Face-With-Sweat--Streamline-Emoji.svg +19 -0
- package/src/emoji2/Grinning-Squinting-Face--Streamline-Emoji.svg +16 -0
- package/src/emoji2/Hand-With-Fingers-Splayed-1--Streamline-Emoji.svg +14 -0
- package/src/emoji2/Heart-Suit--Streamline-Emoji.svg +9 -0
- package/src/emoji2/Hushed-Face-1--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Hushed-Face-2--Streamline-Emoji.svg +15 -0
- package/src/emoji2/Index-Pointing-Up-1--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Kissing-Face-With-Closed-Eyes--Streamline-Emoji.svg +18 -0
- package/src/emoji2/Loudly-Crying-Face--Streamline-Emoji.svg +16 -0
- package/src/emoji2/Lying-Face--Streamline-Emoji.svg +15 -0
- package/src/emoji2/Man-1--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Man-Facepalming-1--Streamline-Emoji.svg +21 -0
- package/src/emoji2/Man-Gesturing-No-1--Streamline-Emoji.svg +34 -0
- package/src/emoji2/Man-Gesturing-Ok-1--Streamline-Emoji.svg +25 -0
- package/src/emoji2/Man-Health-Worker-1--Streamline-Emoji.svg +41 -0
- package/src/emoji2/Man-Raising-Hand-1--Streamline-Emoji.svg +26 -0
- package/src/emoji2/Man-Shrugging-1--Streamline-Emoji.svg +31 -0
- package/src/emoji2/Money-Mouth-Face-2--Streamline-Emoji.svg +30 -0
- package/src/emoji2/Mouth--Streamline-Emoji.svg +12 -0
- package/src/emoji2/Nauseated-Face-2--Streamline-Emoji.svg +19 -0
- package/src/emoji2/Neutral-Face--Streamline-Emoji.svg +15 -0
- package/src/emoji2/Ok-Hand-1--Streamline-Emoji.svg +14 -0
- package/src/emoji2/Old-Man-1--Streamline-Emoji.svg +27 -0
- package/src/emoji2/Old-Woman-1--Streamline-Emoji.svg +23 -0
- package/src/emoji2/Oncoming-Fist-1--Streamline-Emoji.svg +15 -0
- package/src/emoji2/Person-Wearing-Turban-2--Streamline-Emoji.svg +20 -0
- package/src/emoji2/Pile-Of-Poo--Streamline-Emoji.svg +15 -0
- package/src/emoji2/Police-Car-Light--Streamline-Emoji.svg +26 -0
- package/src/emoji2/Rocket--Streamline-Emoji.svg +32 -0
- package/src/emoji2/Sailboat--Streamline-Emoji.svg +18 -0
- package/src/emoji2/Shaved-Ice--Streamline-Emoji.svg +21 -0
- package/src/emoji2/Shortcake-2--Streamline-Emoji.svg +18 -0
- package/src/emoji2/Shushing-Face--Streamline-Emoji.svg +21 -0
- package/src/emoji2/Sign-Of-The-Horns-1--Streamline-Emoji.svg +19 -0
- package/src/emoji2/Sleeping-Face--Streamline-Emoji.svg +21 -0
- package/src/emoji2/Slightly-Smiling-Face--Streamline-Emoji.svg +15 -0
- package/src/emoji2/Smiling-Face-With-Halo--Streamline-Emoji.svg +20 -0
- package/src/emoji2/Smiling-Face-With-Heart-Eyes--Streamline-Emoji.svg +21 -0
- package/src/emoji2/Smirking-Face--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Sun-With-Face--Streamline-Emoji.svg +24 -0
- package/src/emoji2/Thumbs-Down-1--Streamline-Emoji.svg +20 -0
- package/src/emoji2/Thumbs-Up-1--Streamline-Emoji.svg +19 -0
- package/src/emoji2/Winking-Face--Streamline-Emoji.svg +18 -0
- package/src/emoji2/Woman-Gesturing-No-1--Streamline-Emoji.svg +34 -0
- package/src/emoji2/Woman-Gesturing-Ok-2--Streamline-Emoji.svg +25 -0
- package/src/emoji2/Woman-Raising-Hand-1--Streamline-Emoji.svg +26 -0
- package/src/emoji2/Womans-Sandal--Streamline-Emoji.svg +13 -0
- package/src/emoji2/Worried-Face--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Writing-Hand-1--Streamline-Emoji.svg +17 -0
- package/src/emoji2/Zipper-Mouth-Face--Streamline-Emoji.svg +21 -0
- package/src/index.js +19 -0
- package/src/services/burn-after-read-service.js +313 -0
- package/src/services/burn-after-read-service.test.js +325 -0
- package/src/services/dify-api.js +338 -0
- package/src/services/dify-api.test.js +376 -0
- package/src/services/scheduled-send-service.js +311 -0
- package/src/services/scheduled-send-service.test.js +317 -0
- package/src/styles/index.css +2368 -0
- package/src/utils/emoji.js +125 -0
- package/src/utils/emojiData.js +267 -0
- package/src/utils/eventEmitter.js +114 -0
- package/src/utils/state.js +224 -0
- package/src/utils/state.test.js +198 -0
- package/src/utils/storage.js +122 -0
- package/src/utils/storage.test.js +162 -0
- package/src/utils/validation.js +249 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
memo,
|
|
3
|
+
MouseEvent,
|
|
4
|
+
ReactElement,
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from "react";
|
|
10
|
+
import useBounds from "../hooks/useBounds";
|
|
11
|
+
import useStore from "../hooks/useStore";
|
|
12
|
+
import OperationButtons from "../operations";
|
|
13
|
+
import { Bounds, Position } from "../types";
|
|
14
|
+
import "./index.scss";
|
|
15
|
+
|
|
16
|
+
export const ScreenshotsOperationsCtx = React.createContext<Bounds | null>(
|
|
17
|
+
null,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export default memo(function ScreenshotsOperations(): ReactElement | null {
|
|
21
|
+
const { width, height } = useStore();
|
|
22
|
+
const [bounds] = useBounds();
|
|
23
|
+
const [operationsRect, setOperationsRect] = useState<Bounds | null>(null);
|
|
24
|
+
const [position, setPosition] = useState<Position | null>(null);
|
|
25
|
+
|
|
26
|
+
const elRef = useRef<HTMLDivElement>(null);
|
|
27
|
+
const onDoubleClick = useCallback((e: MouseEvent) => {
|
|
28
|
+
e.stopPropagation();
|
|
29
|
+
}, []);
|
|
30
|
+
|
|
31
|
+
const onContextMenu = useCallback((e: MouseEvent) => {
|
|
32
|
+
e.preventDefault();
|
|
33
|
+
e.stopPropagation();
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!bounds || !elRef.current) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const elRect = elRef.current.getBoundingClientRect();
|
|
43
|
+
|
|
44
|
+
let x = bounds.x + bounds.width - elRect.width;
|
|
45
|
+
let y = bounds.y + bounds.height + 10;
|
|
46
|
+
|
|
47
|
+
if (x < 0) {
|
|
48
|
+
x = 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (x > width - elRect.width) {
|
|
52
|
+
x = width - elRect.width;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (y > height - elRect.height) {
|
|
56
|
+
y = height - elRect.height - 10;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 小数存在精度问题
|
|
60
|
+
if (
|
|
61
|
+
!position ||
|
|
62
|
+
Math.abs(position.x - x) > 1 ||
|
|
63
|
+
Math.abs(position.y - y) > 1
|
|
64
|
+
) {
|
|
65
|
+
setPosition({
|
|
66
|
+
x,
|
|
67
|
+
y,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 小数存在精度问题
|
|
72
|
+
if (
|
|
73
|
+
!operationsRect ||
|
|
74
|
+
Math.abs(operationsRect.x - elRect.x) > 1 ||
|
|
75
|
+
Math.abs(operationsRect.y - elRect.y) > 1 ||
|
|
76
|
+
Math.abs(operationsRect.width - elRect.width) > 1 ||
|
|
77
|
+
Math.abs(operationsRect.height - elRect.height) > 1
|
|
78
|
+
) {
|
|
79
|
+
setOperationsRect({
|
|
80
|
+
x: elRect.x,
|
|
81
|
+
y: elRect.y,
|
|
82
|
+
width: elRect.width,
|
|
83
|
+
height: elRect.height,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (!bounds) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<ScreenshotsOperationsCtx.Provider value={operationsRect}>
|
|
94
|
+
<div
|
|
95
|
+
ref={elRef}
|
|
96
|
+
className="screenshots-operations"
|
|
97
|
+
style={{
|
|
98
|
+
visibility: position ? "visible" : "hidden",
|
|
99
|
+
transform: `translate(${position?.x ?? 0}px, ${position?.y ?? 0}px)`,
|
|
100
|
+
}}
|
|
101
|
+
onDoubleClick={onDoubleClick}
|
|
102
|
+
onContextMenu={onContextMenu}
|
|
103
|
+
>
|
|
104
|
+
<div className="screenshots-operations-buttons">
|
|
105
|
+
{OperationButtons.map((OperationButton, index) => {
|
|
106
|
+
if (OperationButton === "|") {
|
|
107
|
+
return (
|
|
108
|
+
<div key={index} className="screenshots-operations-divider" />
|
|
109
|
+
);
|
|
110
|
+
} else {
|
|
111
|
+
return <OperationButton key={index} />;
|
|
112
|
+
}
|
|
113
|
+
})}
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
</ScreenshotsOperationsCtx.Provider>
|
|
117
|
+
);
|
|
118
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
@import "../var.scss";
|
|
2
|
+
|
|
3
|
+
.screenshots-option {
|
|
4
|
+
position: absolute;
|
|
5
|
+
left: 0;
|
|
6
|
+
top: 0;
|
|
7
|
+
font-family: $font-family;
|
|
8
|
+
|
|
9
|
+
&,
|
|
10
|
+
* {
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
user-select: none;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
&-container {
|
|
16
|
+
height: $button-size + 3 * 2 + 2;
|
|
17
|
+
background-color: #fff;
|
|
18
|
+
padding: 3px;
|
|
19
|
+
border-radius: 2px;
|
|
20
|
+
border: 1px solid #ddd;
|
|
21
|
+
background-color: #fff;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&-arrow {
|
|
25
|
+
position: absolute;
|
|
26
|
+
border: 6px solid transparent;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&[data-placement="top"] {
|
|
30
|
+
transform: translate(-50%, -11px);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&[data-placement="top"] &-arrow {
|
|
34
|
+
transform: translate(-50%, -1px);
|
|
35
|
+
border-top-color: #fff;
|
|
36
|
+
top: 100%;
|
|
37
|
+
left: 50%;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&[data-placement="bottom"] {
|
|
41
|
+
transform: translate(-50%, 11px);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&[data-placement="bottom"] &-arrow {
|
|
45
|
+
transform: translate(-50%, 1px);
|
|
46
|
+
border-bottom-color: #fff;
|
|
47
|
+
bottom: 100%;
|
|
48
|
+
left: 50%;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
cloneElement,
|
|
3
|
+
memo,
|
|
4
|
+
ReactElement,
|
|
5
|
+
ReactNode,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from "react";
|
|
11
|
+
import { createPortal } from "react-dom";
|
|
12
|
+
import { ScreenshotsOperationsCtx } from "../ScreenshotsOperations";
|
|
13
|
+
import { Point } from "../types";
|
|
14
|
+
import "./index.scss";
|
|
15
|
+
|
|
16
|
+
export interface ScreenshotsOptionProps {
|
|
17
|
+
open?: boolean;
|
|
18
|
+
content?: ReactNode;
|
|
19
|
+
children: ReactElement;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type Position = Point;
|
|
23
|
+
|
|
24
|
+
export enum Placement {
|
|
25
|
+
Bottom = "bottom",
|
|
26
|
+
Top = "top",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default memo(function ScreenshotsOption({
|
|
30
|
+
open,
|
|
31
|
+
content,
|
|
32
|
+
children,
|
|
33
|
+
}: ScreenshotsOptionProps): ReactElement {
|
|
34
|
+
const childrenRef = useRef<HTMLDivElement>(null);
|
|
35
|
+
const popoverRef = useRef<HTMLDivElement | null>(null);
|
|
36
|
+
const contentRef = useRef<HTMLDivElement>(null);
|
|
37
|
+
const operationsRect = useContext(ScreenshotsOperationsCtx);
|
|
38
|
+
const [placement, setPlacement] = useState<Placement>(Placement.Bottom);
|
|
39
|
+
const [position, setPosition] = useState<Position | null>(null);
|
|
40
|
+
const [offsetX, setOffsetX] = useState<number>(0);
|
|
41
|
+
|
|
42
|
+
const getPopoverEl = () => {
|
|
43
|
+
if (!popoverRef.current) {
|
|
44
|
+
popoverRef.current = document.createElement("div");
|
|
45
|
+
}
|
|
46
|
+
return popoverRef.current;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const $el = getPopoverEl();
|
|
51
|
+
if (open) {
|
|
52
|
+
document.body.appendChild($el);
|
|
53
|
+
}
|
|
54
|
+
return () => {
|
|
55
|
+
$el.remove();
|
|
56
|
+
};
|
|
57
|
+
}, [open]);
|
|
58
|
+
|
|
59
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (
|
|
62
|
+
!open ||
|
|
63
|
+
!operationsRect ||
|
|
64
|
+
!childrenRef.current ||
|
|
65
|
+
!contentRef.current
|
|
66
|
+
) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const childrenRect = childrenRef.current.getBoundingClientRect();
|
|
71
|
+
const contentRect = contentRef.current.getBoundingClientRect();
|
|
72
|
+
|
|
73
|
+
let currentPlacement = placement;
|
|
74
|
+
let x = childrenRect.left + childrenRect.width / 2;
|
|
75
|
+
let y = childrenRect.top + childrenRect.height;
|
|
76
|
+
let currentOffsetX = offsetX;
|
|
77
|
+
|
|
78
|
+
// 如果左右都越界了,就以左边界为准
|
|
79
|
+
if (x + contentRect.width / 2 > operationsRect.x + operationsRect.width) {
|
|
80
|
+
const ox = x;
|
|
81
|
+
x = operationsRect.x + operationsRect.width - contentRect.width / 2;
|
|
82
|
+
currentOffsetX = ox - x;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 左边不能超出
|
|
86
|
+
if (x < operationsRect.x + contentRect.width / 2) {
|
|
87
|
+
const ox = x;
|
|
88
|
+
x = operationsRect.x + contentRect.width / 2;
|
|
89
|
+
currentOffsetX = ox - x;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 如果上下都越界了,就以上边界为准
|
|
93
|
+
if (y > window.innerHeight - contentRect.height) {
|
|
94
|
+
if (currentPlacement === Placement.Bottom) {
|
|
95
|
+
currentPlacement = Placement.Top;
|
|
96
|
+
}
|
|
97
|
+
y = childrenRect.top - contentRect.height;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (y < 0) {
|
|
101
|
+
if (currentPlacement === Placement.Top) {
|
|
102
|
+
currentPlacement = Placement.Bottom;
|
|
103
|
+
}
|
|
104
|
+
y = childrenRect.top + childrenRect.height;
|
|
105
|
+
}
|
|
106
|
+
if (currentPlacement !== placement) {
|
|
107
|
+
setPlacement(currentPlacement);
|
|
108
|
+
}
|
|
109
|
+
if (position?.x !== x || position.y !== y) {
|
|
110
|
+
setPosition({
|
|
111
|
+
x,
|
|
112
|
+
y,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (currentOffsetX !== offsetX) {
|
|
117
|
+
setOffsetX(currentOffsetX);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<>
|
|
123
|
+
{cloneElement(children, {
|
|
124
|
+
ref: childrenRef,
|
|
125
|
+
})}
|
|
126
|
+
{open &&
|
|
127
|
+
content &&
|
|
128
|
+
createPortal(
|
|
129
|
+
<div
|
|
130
|
+
ref={contentRef}
|
|
131
|
+
className="screenshots-option"
|
|
132
|
+
style={{
|
|
133
|
+
visibility: position ? "visible" : "hidden",
|
|
134
|
+
transform: `translate(${position?.x ?? 0}px, ${
|
|
135
|
+
position?.y ?? 0
|
|
136
|
+
}px)`,
|
|
137
|
+
}}
|
|
138
|
+
data-placement={placement}
|
|
139
|
+
>
|
|
140
|
+
<div className="screenshots-option-container">{content}</div>
|
|
141
|
+
<div
|
|
142
|
+
className="screenshots-option-arrow"
|
|
143
|
+
style={{ marginLeft: offsetX }}
|
|
144
|
+
/>
|
|
145
|
+
</div>,
|
|
146
|
+
getPopoverEl(),
|
|
147
|
+
)}
|
|
148
|
+
</>
|
|
149
|
+
);
|
|
150
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
@import "../var.scss";
|
|
2
|
+
|
|
3
|
+
.screenshots-size {
|
|
4
|
+
height: $sizecolor-size;
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
|
|
8
|
+
&-item {
|
|
9
|
+
width: $sizecolor-size;
|
|
10
|
+
height: $sizecolor-size;
|
|
11
|
+
position: relative;
|
|
12
|
+
margin: 0 3px;
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&-pointer {
|
|
17
|
+
background-color: #555;
|
|
18
|
+
border-radius: 50%;
|
|
19
|
+
position: absolute;
|
|
20
|
+
top: 50%;
|
|
21
|
+
left: 50%;
|
|
22
|
+
transform: translate(-50%, -50%);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&-active > &-pointer {
|
|
26
|
+
background-color: #39f;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { memo, ReactElement } from "react";
|
|
2
|
+
import "./index.scss";
|
|
3
|
+
|
|
4
|
+
export interface SizeProps {
|
|
5
|
+
value: number;
|
|
6
|
+
onChange: (value: number) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default memo(function ScreenshotsSize({
|
|
10
|
+
value,
|
|
11
|
+
onChange,
|
|
12
|
+
}: SizeProps): ReactElement {
|
|
13
|
+
const sizes = [3, 6, 9];
|
|
14
|
+
return (
|
|
15
|
+
<div className="screenshots-size">
|
|
16
|
+
{sizes.map((size) => {
|
|
17
|
+
const classNames = ["screenshots-size-item"];
|
|
18
|
+
|
|
19
|
+
if (size === value) {
|
|
20
|
+
classNames.push("screenshots-size-active");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div
|
|
25
|
+
key={size}
|
|
26
|
+
className={classNames.join(" ")}
|
|
27
|
+
onClick={() => onChange && onChange(size)}
|
|
28
|
+
>
|
|
29
|
+
<div
|
|
30
|
+
className="screenshots-size-pointer"
|
|
31
|
+
style={{
|
|
32
|
+
width: size * 1.8,
|
|
33
|
+
height: size * 1.8,
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
})}
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { memo, ReactElement } from "react";
|
|
2
|
+
import ScreenshotsSize from "../ScreenshotsSize";
|
|
3
|
+
import ScreenshotsColor from "../ScreenshotsColor";
|
|
4
|
+
import "./index.scss";
|
|
5
|
+
|
|
6
|
+
export interface SizeColorProps {
|
|
7
|
+
size: number;
|
|
8
|
+
color: string;
|
|
9
|
+
onSizeChange: (value: number) => void;
|
|
10
|
+
onColorChange: (value: string) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default memo(function ScreenshotsSizeColor({
|
|
14
|
+
size,
|
|
15
|
+
color,
|
|
16
|
+
onSizeChange,
|
|
17
|
+
onColorChange,
|
|
18
|
+
}: SizeColorProps): ReactElement {
|
|
19
|
+
return (
|
|
20
|
+
<div className="screenshots-sizecolor">
|
|
21
|
+
<ScreenshotsSize value={size} onChange={onSizeChange} />
|
|
22
|
+
<ScreenshotsColor value={color} onChange={onColorChange} />
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Thanks to https://github.com/react-component/textarea
|
|
2
|
+
|
|
3
|
+
const hiddenTextareaStyle = `
|
|
4
|
+
min-width: 0 !important;
|
|
5
|
+
width: 0 !important;
|
|
6
|
+
min-height: 0 !important;
|
|
7
|
+
height:0 !important;
|
|
8
|
+
visibility: hidden !important;
|
|
9
|
+
overflow: hidden !important;
|
|
10
|
+
position: absolute !important;
|
|
11
|
+
z-index: -1000 !important;
|
|
12
|
+
top:0 !important;
|
|
13
|
+
right:0 !important;
|
|
14
|
+
`
|
|
15
|
+
|
|
16
|
+
const sizeStyle = [
|
|
17
|
+
'letter-spacing',
|
|
18
|
+
'line-height',
|
|
19
|
+
'padding-top',
|
|
20
|
+
'padding-bottom',
|
|
21
|
+
'font-family',
|
|
22
|
+
'font-weight',
|
|
23
|
+
'font-size',
|
|
24
|
+
'font-variant',
|
|
25
|
+
'text-rendering',
|
|
26
|
+
'text-transform',
|
|
27
|
+
'text-indent',
|
|
28
|
+
'padding-left',
|
|
29
|
+
'padding-right',
|
|
30
|
+
'border-width',
|
|
31
|
+
'box-sizing',
|
|
32
|
+
'white-space',
|
|
33
|
+
'word-break'
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
export interface SizeInfo {
|
|
37
|
+
sizingStyle: string
|
|
38
|
+
paddingSize: number
|
|
39
|
+
borderSize: number
|
|
40
|
+
boxSizing: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface Size {
|
|
44
|
+
width: number
|
|
45
|
+
height: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let hiddenTextarea: HTMLTextAreaElement
|
|
49
|
+
|
|
50
|
+
export function getComputedSizeInfo (node: HTMLElement) {
|
|
51
|
+
const style = window.getComputedStyle(node)
|
|
52
|
+
|
|
53
|
+
const boxSizing =
|
|
54
|
+
style.getPropertyValue('box-sizing') ||
|
|
55
|
+
style.getPropertyValue('-moz-box-sizing') ||
|
|
56
|
+
style.getPropertyValue('-webkit-box-sizing')
|
|
57
|
+
|
|
58
|
+
const paddingSize =
|
|
59
|
+
parseFloat(style.getPropertyValue('padding-bottom')) + parseFloat(style.getPropertyValue('padding-top'))
|
|
60
|
+
|
|
61
|
+
const borderSize =
|
|
62
|
+
parseFloat(style.getPropertyValue('border-bottom-width')) + parseFloat(style.getPropertyValue('border-top-width'))
|
|
63
|
+
|
|
64
|
+
const sizingStyle = sizeStyle.map(name => `${name}:${style.getPropertyValue(name)}`).join(';')
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
sizingStyle,
|
|
68
|
+
paddingSize,
|
|
69
|
+
borderSize,
|
|
70
|
+
boxSizing
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default function calculateNodeSize (
|
|
75
|
+
textarea: HTMLTextAreaElement,
|
|
76
|
+
value: string,
|
|
77
|
+
maxWidth: number,
|
|
78
|
+
maxHeight: number
|
|
79
|
+
): Size {
|
|
80
|
+
if (!hiddenTextarea) {
|
|
81
|
+
hiddenTextarea = document.createElement('textarea')
|
|
82
|
+
hiddenTextarea.setAttribute('tab-index', '-1')
|
|
83
|
+
document.body.appendChild(hiddenTextarea)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Copy all CSS properties that have an impact on the height of the content in
|
|
87
|
+
// the textbox
|
|
88
|
+
const { paddingSize, borderSize, boxSizing, sizingStyle } = getComputedSizeInfo(textarea)
|
|
89
|
+
|
|
90
|
+
// Need to have the overflow attribute to hide the scrollbar otherwise
|
|
91
|
+
// text-lines will not calculated properly as the shadow will technically be
|
|
92
|
+
// narrower for content
|
|
93
|
+
hiddenTextarea.setAttribute(
|
|
94
|
+
'style',
|
|
95
|
+
`${sizingStyle};${hiddenTextareaStyle};max-width:${maxWidth}px;max-height:${maxHeight}px`
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
hiddenTextarea.value = value || ' '
|
|
99
|
+
|
|
100
|
+
let width = hiddenTextarea.scrollWidth
|
|
101
|
+
let height = hiddenTextarea.scrollHeight
|
|
102
|
+
|
|
103
|
+
if (boxSizing === 'border-box') {
|
|
104
|
+
// border-box: add border, since height = content + padding + border
|
|
105
|
+
width += borderSize
|
|
106
|
+
height += borderSize
|
|
107
|
+
} else if (boxSizing === 'content-box') {
|
|
108
|
+
// remove padding, since height = content
|
|
109
|
+
width -= paddingSize
|
|
110
|
+
height -= paddingSize
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
width: Math.min(width, maxWidth),
|
|
115
|
+
height: Math.min(height, maxHeight)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
@import "../var.scss";
|
|
2
|
+
|
|
3
|
+
.screenshots-textarea {
|
|
4
|
+
box-sizing: border-box;
|
|
5
|
+
position: absolute;
|
|
6
|
+
left: 0;
|
|
7
|
+
top: 0;
|
|
8
|
+
margin: 0;
|
|
9
|
+
padding: 0;
|
|
10
|
+
background-color: transparent;
|
|
11
|
+
border: 2px solid $border-color;
|
|
12
|
+
resize: none;
|
|
13
|
+
outline: none;
|
|
14
|
+
white-space: nowrap;
|
|
15
|
+
word-break: break-all;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
font-family: $font-family;
|
|
18
|
+
text-align: left;
|
|
19
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
ReactElement,
|
|
3
|
+
useRef,
|
|
4
|
+
FocusEvent,
|
|
5
|
+
useLayoutEffect,
|
|
6
|
+
useState,
|
|
7
|
+
memo,
|
|
8
|
+
} from "react";
|
|
9
|
+
import { createPortal } from "react-dom";
|
|
10
|
+
import calculateNodeSize from "./calculateNodeSize";
|
|
11
|
+
import "./index.scss";
|
|
12
|
+
|
|
13
|
+
export interface TextInputProps {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
maxWidth: number;
|
|
17
|
+
maxHeight: number;
|
|
18
|
+
size: number;
|
|
19
|
+
color: string;
|
|
20
|
+
value: string;
|
|
21
|
+
onChange: (value: string) => unknown;
|
|
22
|
+
onBlur: (e: FocusEvent<HTMLTextAreaElement>) => unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default memo(function ScreenshotsTextarea({
|
|
26
|
+
x,
|
|
27
|
+
y,
|
|
28
|
+
maxWidth,
|
|
29
|
+
maxHeight,
|
|
30
|
+
size,
|
|
31
|
+
color,
|
|
32
|
+
value,
|
|
33
|
+
onChange,
|
|
34
|
+
onBlur,
|
|
35
|
+
}: TextInputProps): ReactElement {
|
|
36
|
+
const popoverRef = useRef<HTMLDivElement | null>(null);
|
|
37
|
+
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
38
|
+
const [width, setWidth] = useState(0);
|
|
39
|
+
const [height, setHeight] = useState(0);
|
|
40
|
+
|
|
41
|
+
const getPopoverEl = () => {
|
|
42
|
+
if (!popoverRef.current) {
|
|
43
|
+
popoverRef.current = document.createElement("div");
|
|
44
|
+
}
|
|
45
|
+
return popoverRef.current;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
useLayoutEffect(() => {
|
|
49
|
+
if (popoverRef.current) {
|
|
50
|
+
document.body.appendChild(popoverRef.current);
|
|
51
|
+
requestAnimationFrame(() => {
|
|
52
|
+
textareaRef.current?.focus();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return () => {
|
|
57
|
+
popoverRef.current?.remove();
|
|
58
|
+
};
|
|
59
|
+
}, []);
|
|
60
|
+
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
if (!textareaRef.current) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const { width, height } = calculateNodeSize(
|
|
67
|
+
textareaRef.current,
|
|
68
|
+
value,
|
|
69
|
+
maxWidth,
|
|
70
|
+
maxHeight,
|
|
71
|
+
);
|
|
72
|
+
setWidth(width);
|
|
73
|
+
setHeight(height);
|
|
74
|
+
}, [value, maxWidth, maxHeight]);
|
|
75
|
+
|
|
76
|
+
return createPortal(
|
|
77
|
+
<textarea
|
|
78
|
+
ref={textareaRef}
|
|
79
|
+
className="screenshots-textarea"
|
|
80
|
+
style={{
|
|
81
|
+
color,
|
|
82
|
+
width,
|
|
83
|
+
height,
|
|
84
|
+
maxWidth,
|
|
85
|
+
maxHeight,
|
|
86
|
+
fontSize: size,
|
|
87
|
+
lineHeight: `${size}px`,
|
|
88
|
+
transform: `translate(${x}px, ${y}px)`,
|
|
89
|
+
}}
|
|
90
|
+
value={value}
|
|
91
|
+
onChange={(e) => onChange && onChange(e.target.value)}
|
|
92
|
+
onBlur={(e) => onBlur && onBlur(e)}
|
|
93
|
+
/>,
|
|
94
|
+
getPopoverEl(),
|
|
95
|
+
);
|
|
96
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Bounds, History, HistoryItemType } from './types'
|
|
2
|
+
|
|
3
|
+
interface ComposeImageOpts {
|
|
4
|
+
image: HTMLImageElement
|
|
5
|
+
width: number
|
|
6
|
+
height: number
|
|
7
|
+
history: History
|
|
8
|
+
bounds: Bounds
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function composeImage ({ image, width, height, history, bounds }: ComposeImageOpts): Promise<Blob> {
|
|
12
|
+
return new Promise<Blob>((resolve, reject) => {
|
|
13
|
+
const $canvas = document.createElement('canvas')
|
|
14
|
+
const targetWidth = bounds.width * window.devicePixelRatio
|
|
15
|
+
const targetHeight = bounds.height * window.devicePixelRatio
|
|
16
|
+
$canvas.width = targetWidth
|
|
17
|
+
$canvas.height = targetHeight
|
|
18
|
+
|
|
19
|
+
const ctx = $canvas.getContext('2d')
|
|
20
|
+
if (!ctx) {
|
|
21
|
+
return reject(new Error('convert image to blob fail'))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const rx = image.naturalWidth / width
|
|
25
|
+
const ry = image.naturalHeight / height
|
|
26
|
+
|
|
27
|
+
ctx.imageSmoothingEnabled = true
|
|
28
|
+
// 设置太高,图片会模糊
|
|
29
|
+
ctx.imageSmoothingQuality = 'low'
|
|
30
|
+
ctx.setTransform(window.devicePixelRatio, 0, 0, window.devicePixelRatio, 0, 0)
|
|
31
|
+
ctx.clearRect(0, 0, bounds.width, bounds.height)
|
|
32
|
+
ctx.drawImage(
|
|
33
|
+
image,
|
|
34
|
+
bounds.x * rx,
|
|
35
|
+
bounds.y * ry,
|
|
36
|
+
bounds.width * rx,
|
|
37
|
+
bounds.height * ry,
|
|
38
|
+
0,
|
|
39
|
+
0,
|
|
40
|
+
bounds.width,
|
|
41
|
+
bounds.height
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
history.stack.slice(0, history.index + 1).forEach(item => {
|
|
45
|
+
if (item.type === HistoryItemType.Source) {
|
|
46
|
+
item.draw(ctx, item)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
$canvas.toBlob(blob => {
|
|
51
|
+
if (!blob) {
|
|
52
|
+
return reject(new Error('canvas toBlob fail'))
|
|
53
|
+
}
|
|
54
|
+
resolve(blob)
|
|
55
|
+
}, 'image/png')
|
|
56
|
+
})
|
|
57
|
+
}
|