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,277 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
memo,
|
|
4
|
+
ReactElement,
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useImperativeHandle,
|
|
8
|
+
useLayoutEffect,
|
|
9
|
+
useRef,
|
|
10
|
+
} from "react";
|
|
11
|
+
import useBounds from "../hooks/useBounds";
|
|
12
|
+
import useCursor from "../hooks/useCursor";
|
|
13
|
+
import useEmiter from "../hooks/useEmiter";
|
|
14
|
+
import useHistory from "../hooks/useHistory";
|
|
15
|
+
import useOperation from "../hooks/useOperation";
|
|
16
|
+
import useStore from "../hooks/useStore";
|
|
17
|
+
import { Bounds, HistoryItemType, Point } from "../types";
|
|
18
|
+
import getBoundsByPoints from "./getBoundsByPoints";
|
|
19
|
+
import getPoints from "./getPoints";
|
|
20
|
+
import "./index.scss";
|
|
21
|
+
import isPointInDraw from "./isPointInDraw";
|
|
22
|
+
|
|
23
|
+
const borders = ["top", "right", "bottom", "left"];
|
|
24
|
+
|
|
25
|
+
export enum ResizePoints {
|
|
26
|
+
ResizeTop = "top",
|
|
27
|
+
ResizetopRight = "top-right",
|
|
28
|
+
ResizeRight = "right",
|
|
29
|
+
ResizeRightBottom = "right-bottom",
|
|
30
|
+
ResizeBottom = "bottom",
|
|
31
|
+
ResizeBottomLeft = "bottom-left",
|
|
32
|
+
ResizeLeft = "left",
|
|
33
|
+
ResizeLeftTop = "left-top",
|
|
34
|
+
Move = "move",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const resizePoints = [
|
|
38
|
+
ResizePoints.ResizeTop,
|
|
39
|
+
ResizePoints.ResizetopRight,
|
|
40
|
+
ResizePoints.ResizeRight,
|
|
41
|
+
ResizePoints.ResizeRightBottom,
|
|
42
|
+
ResizePoints.ResizeBottom,
|
|
43
|
+
ResizePoints.ResizeBottomLeft,
|
|
44
|
+
ResizePoints.ResizeLeft,
|
|
45
|
+
ResizePoints.ResizeLeftTop,
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export default memo(
|
|
49
|
+
forwardRef<CanvasRenderingContext2D>(function ScreenshotsCanvas(
|
|
50
|
+
props,
|
|
51
|
+
ref,
|
|
52
|
+
): ReactElement | null {
|
|
53
|
+
const { url, image, width, height } = useStore();
|
|
54
|
+
|
|
55
|
+
const emiter = useEmiter();
|
|
56
|
+
const [history] = useHistory();
|
|
57
|
+
const [cursor] = useCursor();
|
|
58
|
+
const [bounds, boundsDispatcher] = useBounds();
|
|
59
|
+
const [operation] = useOperation();
|
|
60
|
+
|
|
61
|
+
const resizeOrMoveRef = useRef<string>();
|
|
62
|
+
const pointRef = useRef<Point | null>(null);
|
|
63
|
+
const boundsRef = useRef<Bounds | null>(null);
|
|
64
|
+
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
|
65
|
+
const ctxRef = useRef<CanvasRenderingContext2D | null>(null);
|
|
66
|
+
|
|
67
|
+
const isCanResize = bounds && !history.stack.length && !operation;
|
|
68
|
+
|
|
69
|
+
const draw = useCallback(() => {
|
|
70
|
+
if (!bounds || !ctxRef.current) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const ctx = ctxRef.current;
|
|
75
|
+
ctx.imageSmoothingEnabled = true;
|
|
76
|
+
// 设置太高,图片会模糊
|
|
77
|
+
ctx.imageSmoothingQuality = "low";
|
|
78
|
+
ctx.clearRect(0, 0, bounds.width, bounds.height);
|
|
79
|
+
|
|
80
|
+
history.stack.slice(0, history.index + 1).forEach((item) => {
|
|
81
|
+
if (item.type === HistoryItemType.Source) {
|
|
82
|
+
item.draw(ctx, item);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}, [bounds, ctxRef, history]);
|
|
86
|
+
|
|
87
|
+
const onMouseDown = useCallback(
|
|
88
|
+
(e: React.MouseEvent, resizeOrMove: string) => {
|
|
89
|
+
if (e.button !== 0 || !bounds) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (!operation) {
|
|
93
|
+
resizeOrMoveRef.current = resizeOrMove;
|
|
94
|
+
pointRef.current = {
|
|
95
|
+
x: e.clientX,
|
|
96
|
+
y: e.clientY,
|
|
97
|
+
};
|
|
98
|
+
boundsRef.current = {
|
|
99
|
+
x: bounds.x,
|
|
100
|
+
y: bounds.y,
|
|
101
|
+
width: bounds.width,
|
|
102
|
+
height: bounds.height,
|
|
103
|
+
};
|
|
104
|
+
} else {
|
|
105
|
+
const draw = isPointInDraw(
|
|
106
|
+
bounds,
|
|
107
|
+
canvasRef.current,
|
|
108
|
+
history,
|
|
109
|
+
e.nativeEvent,
|
|
110
|
+
);
|
|
111
|
+
if (draw) {
|
|
112
|
+
emiter.emit("drawselect", draw, e.nativeEvent);
|
|
113
|
+
} else {
|
|
114
|
+
emiter.emit("mousedown", e.nativeEvent);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
[bounds, operation, emiter, history],
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const updateBounds = useCallback(
|
|
122
|
+
(e: MouseEvent) => {
|
|
123
|
+
if (
|
|
124
|
+
!resizeOrMoveRef.current ||
|
|
125
|
+
!pointRef.current ||
|
|
126
|
+
!boundsRef.current ||
|
|
127
|
+
!bounds
|
|
128
|
+
) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const points = getPoints(
|
|
132
|
+
e,
|
|
133
|
+
resizeOrMoveRef.current,
|
|
134
|
+
pointRef.current,
|
|
135
|
+
boundsRef.current,
|
|
136
|
+
);
|
|
137
|
+
boundsDispatcher.set(
|
|
138
|
+
getBoundsByPoints(
|
|
139
|
+
points[0],
|
|
140
|
+
points[1],
|
|
141
|
+
bounds,
|
|
142
|
+
width,
|
|
143
|
+
height,
|
|
144
|
+
resizeOrMoveRef.current,
|
|
145
|
+
),
|
|
146
|
+
);
|
|
147
|
+
},
|
|
148
|
+
[width, height, bounds, boundsDispatcher],
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
useLayoutEffect(() => {
|
|
152
|
+
if (!image || !bounds || !canvasRef.current) {
|
|
153
|
+
ctxRef.current = null;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (!ctxRef.current) {
|
|
158
|
+
ctxRef.current = canvasRef.current.getContext("2d");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
draw();
|
|
162
|
+
}, [image, bounds, draw]);
|
|
163
|
+
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
const onMouseMove = (e: MouseEvent) => {
|
|
166
|
+
if (!operation) {
|
|
167
|
+
if (
|
|
168
|
+
!resizeOrMoveRef.current ||
|
|
169
|
+
!pointRef.current ||
|
|
170
|
+
!boundsRef.current
|
|
171
|
+
) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
updateBounds(e);
|
|
175
|
+
} else {
|
|
176
|
+
emiter.emit("mousemove", e);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const onMouseUp = (e: MouseEvent) => {
|
|
181
|
+
if (!operation) {
|
|
182
|
+
if (
|
|
183
|
+
!resizeOrMoveRef.current ||
|
|
184
|
+
!pointRef.current ||
|
|
185
|
+
!boundsRef.current
|
|
186
|
+
) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
updateBounds(e);
|
|
190
|
+
resizeOrMoveRef.current = undefined;
|
|
191
|
+
pointRef.current = null;
|
|
192
|
+
boundsRef.current = null;
|
|
193
|
+
} else {
|
|
194
|
+
emiter.emit("mouseup", e);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
window.addEventListener("mousemove", onMouseMove);
|
|
198
|
+
window.addEventListener("mouseup", onMouseUp);
|
|
199
|
+
|
|
200
|
+
return () => {
|
|
201
|
+
window.removeEventListener("mousemove", onMouseMove);
|
|
202
|
+
window.removeEventListener("mouseup", onMouseUp);
|
|
203
|
+
};
|
|
204
|
+
}, [updateBounds, operation, emiter]);
|
|
205
|
+
|
|
206
|
+
// 放到最后,保证ctxRef.current存在
|
|
207
|
+
useImperativeHandle<
|
|
208
|
+
CanvasRenderingContext2D | null,
|
|
209
|
+
CanvasRenderingContext2D | null
|
|
210
|
+
>(ref, () => ctxRef.current);
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<div
|
|
214
|
+
className="screenshots-canvas"
|
|
215
|
+
style={{
|
|
216
|
+
width: bounds?.width || 0,
|
|
217
|
+
height: bounds?.height || 0,
|
|
218
|
+
transform: bounds
|
|
219
|
+
? `translate(${bounds.x}px, ${bounds.y}px)`
|
|
220
|
+
: "none",
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
223
|
+
<div className="screenshots-canvas-body">
|
|
224
|
+
{/* 保证一开始就显示,减少加载时间 */}
|
|
225
|
+
<img
|
|
226
|
+
className="screenshots-canvas-image"
|
|
227
|
+
src={url}
|
|
228
|
+
style={{
|
|
229
|
+
width,
|
|
230
|
+
height,
|
|
231
|
+
transform: bounds
|
|
232
|
+
? `translate(${-bounds.x}px, ${-bounds.y}px)`
|
|
233
|
+
: "none",
|
|
234
|
+
}}
|
|
235
|
+
/>
|
|
236
|
+
<canvas
|
|
237
|
+
ref={canvasRef}
|
|
238
|
+
className="screenshots-canvas-panel"
|
|
239
|
+
width={bounds?.width || 0}
|
|
240
|
+
height={bounds?.height || 0}
|
|
241
|
+
/>
|
|
242
|
+
</div>
|
|
243
|
+
<div
|
|
244
|
+
className="screenshots-canvas-mask"
|
|
245
|
+
style={{
|
|
246
|
+
cursor,
|
|
247
|
+
}}
|
|
248
|
+
onMouseDown={(e) => onMouseDown(e, "move")}
|
|
249
|
+
>
|
|
250
|
+
{isCanResize && (
|
|
251
|
+
<div className="screenshots-canvas-size">
|
|
252
|
+
{bounds.width} × {bounds.height}
|
|
253
|
+
</div>
|
|
254
|
+
)}
|
|
255
|
+
</div>
|
|
256
|
+
{borders.map((border) => {
|
|
257
|
+
return (
|
|
258
|
+
<div
|
|
259
|
+
key={border}
|
|
260
|
+
className={`screenshots-canvas-border-${border}`}
|
|
261
|
+
/>
|
|
262
|
+
);
|
|
263
|
+
})}
|
|
264
|
+
{isCanResize &&
|
|
265
|
+
resizePoints.map((resizePoint) => {
|
|
266
|
+
return (
|
|
267
|
+
<div
|
|
268
|
+
key={resizePoint}
|
|
269
|
+
className={`screenshots-canvas-point-${resizePoint}`}
|
|
270
|
+
onMouseDown={(e) => onMouseDown(e, resizePoint)}
|
|
271
|
+
/>
|
|
272
|
+
);
|
|
273
|
+
})}
|
|
274
|
+
</div>
|
|
275
|
+
);
|
|
276
|
+
}),
|
|
277
|
+
);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Bounds, History, HistoryItemType } from '../types'
|
|
2
|
+
|
|
3
|
+
export default function isPointInDraw (
|
|
4
|
+
bounds: Bounds,
|
|
5
|
+
canvas: HTMLCanvasElement | null,
|
|
6
|
+
history: History,
|
|
7
|
+
e: MouseEvent
|
|
8
|
+
) {
|
|
9
|
+
if (!canvas) {
|
|
10
|
+
return false
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const $canvas = document.createElement('canvas')
|
|
14
|
+
$canvas.width = bounds.width
|
|
15
|
+
$canvas.height = bounds.height
|
|
16
|
+
const ctx = $canvas.getContext('2d')
|
|
17
|
+
|
|
18
|
+
if (!ctx) {
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { left, top } = canvas.getBoundingClientRect()
|
|
23
|
+
const x = e.clientX - left
|
|
24
|
+
const y = e.clientY - top
|
|
25
|
+
|
|
26
|
+
const stack = [...history.stack.slice(0, history.index + 1)]
|
|
27
|
+
|
|
28
|
+
return stack.reverse().find(item => {
|
|
29
|
+
if (item.type !== HistoryItemType.Source) {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
ctx.clearRect(0, 0, bounds.width, bounds.height)
|
|
33
|
+
return item.isHit?.(ctx, item, { x, y })
|
|
34
|
+
})
|
|
35
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
@import "../var.scss";
|
|
2
|
+
|
|
3
|
+
.screenshots-color {
|
|
4
|
+
height: $sizecolor-size;
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
|
|
8
|
+
&-item {
|
|
9
|
+
border: 1px solid #777;
|
|
10
|
+
width: $sizecolor-size;
|
|
11
|
+
height: $sizecolor-size;
|
|
12
|
+
cursor: pointer;
|
|
13
|
+
position: relative;
|
|
14
|
+
margin: 0 3px;
|
|
15
|
+
&:before {
|
|
16
|
+
content: "";
|
|
17
|
+
display: none;
|
|
18
|
+
position: absolute;
|
|
19
|
+
right: 0;
|
|
20
|
+
bottom: 0;
|
|
21
|
+
width: 10px;
|
|
22
|
+
height: 10px;
|
|
23
|
+
background-color: #333;
|
|
24
|
+
}
|
|
25
|
+
&:after {
|
|
26
|
+
content: "";
|
|
27
|
+
display: none;
|
|
28
|
+
width: 8px;
|
|
29
|
+
height: 4px;
|
|
30
|
+
position: absolute;
|
|
31
|
+
right: 5px;
|
|
32
|
+
bottom: 5px;
|
|
33
|
+
border-bottom: 2px solid #fff;
|
|
34
|
+
border-left: 2px solid #fff;
|
|
35
|
+
transform: translate(5px, 2px) rotate(-45deg) scale(0.8, 0.8);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&-active {
|
|
40
|
+
&:before,
|
|
41
|
+
&:after {
|
|
42
|
+
display: block;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React, { memo, ReactElement } from "react";
|
|
2
|
+
import "./index.scss";
|
|
3
|
+
|
|
4
|
+
export interface ColorProps {
|
|
5
|
+
value: string;
|
|
6
|
+
onChange: (value: string) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default memo(function ScreenshotsColor({
|
|
10
|
+
value,
|
|
11
|
+
onChange,
|
|
12
|
+
}: ColorProps): ReactElement {
|
|
13
|
+
const colors = [
|
|
14
|
+
"#ee5126",
|
|
15
|
+
"#fceb4d",
|
|
16
|
+
"#90e746",
|
|
17
|
+
"#51c0fa",
|
|
18
|
+
"#7a7a7a",
|
|
19
|
+
"#ffffff",
|
|
20
|
+
];
|
|
21
|
+
return (
|
|
22
|
+
<div className="screenshots-color">
|
|
23
|
+
{colors.map((color) => {
|
|
24
|
+
const classNames = ["screenshots-color-item"];
|
|
25
|
+
if (color === value) {
|
|
26
|
+
classNames.push("screenshots-color-active");
|
|
27
|
+
}
|
|
28
|
+
return (
|
|
29
|
+
<div
|
|
30
|
+
key={color}
|
|
31
|
+
className={classNames.join(" ")}
|
|
32
|
+
style={{ backgroundColor: color }}
|
|
33
|
+
onClick={() => onChange && onChange(color)}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
})}
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React, { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { EmiterRef, History, Bounds, CanvasContextRef } from './types';
|
|
3
|
+
import zhCN, { Lang } from './zh_CN';
|
|
4
|
+
|
|
5
|
+
export interface ScreenshotsContextStore {
|
|
6
|
+
url?: string;
|
|
7
|
+
image: HTMLImageElement | null;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
lang: Lang;
|
|
11
|
+
emiterRef: EmiterRef;
|
|
12
|
+
canvasContextRef: CanvasContextRef;
|
|
13
|
+
history: History;
|
|
14
|
+
bounds: Bounds | null;
|
|
15
|
+
cursor?: string;
|
|
16
|
+
operation?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ScreenshotsContextDispatcher {
|
|
20
|
+
call?: <T>(funcName: string, ...args: T[]) => void;
|
|
21
|
+
setHistory?: Dispatch<SetStateAction<History>>;
|
|
22
|
+
setBounds?: Dispatch<SetStateAction<Bounds | null>>;
|
|
23
|
+
setCursor?: Dispatch<SetStateAction<string | undefined>>;
|
|
24
|
+
setOperation?: Dispatch<SetStateAction<string | undefined>>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ScreenshotsContextValue {
|
|
28
|
+
store: ScreenshotsContextStore;
|
|
29
|
+
dispatcher: ScreenshotsContextDispatcher;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default React.createContext<ScreenshotsContextValue>({
|
|
33
|
+
store: {
|
|
34
|
+
url: undefined,
|
|
35
|
+
image: null,
|
|
36
|
+
width: 0,
|
|
37
|
+
height: 0,
|
|
38
|
+
lang: zhCN,
|
|
39
|
+
emiterRef: { current: {} },
|
|
40
|
+
canvasContextRef: { current: null },
|
|
41
|
+
history: {
|
|
42
|
+
index: -1,
|
|
43
|
+
stack: [],
|
|
44
|
+
},
|
|
45
|
+
bounds: null,
|
|
46
|
+
cursor: 'move',
|
|
47
|
+
operation: undefined,
|
|
48
|
+
},
|
|
49
|
+
dispatcher: {
|
|
50
|
+
call: undefined,
|
|
51
|
+
setHistory: undefined,
|
|
52
|
+
setBounds: undefined,
|
|
53
|
+
setCursor: undefined,
|
|
54
|
+
setOperation: undefined,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
@import "../var.scss";
|
|
2
|
+
|
|
3
|
+
.screenshots-magnifier {
|
|
4
|
+
position: absolute;
|
|
5
|
+
font-family: $font-family;
|
|
6
|
+
left: 0;
|
|
7
|
+
top: 0;
|
|
8
|
+
width: 100px;
|
|
9
|
+
box-shadow: 0 0 8px 0px #000;
|
|
10
|
+
z-index: 9;
|
|
11
|
+
|
|
12
|
+
&,
|
|
13
|
+
* {
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
user-select: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&-body {
|
|
19
|
+
position: relative;
|
|
20
|
+
background-color: #fff;
|
|
21
|
+
&:before {
|
|
22
|
+
content: "";
|
|
23
|
+
background-color: rgb(10, 114, 161);
|
|
24
|
+
position: absolute;
|
|
25
|
+
top: 50%;
|
|
26
|
+
left: 0;
|
|
27
|
+
width: 100%;
|
|
28
|
+
height: 2px;
|
|
29
|
+
z-index: 1;
|
|
30
|
+
}
|
|
31
|
+
&:after {
|
|
32
|
+
content: "";
|
|
33
|
+
background-color: rgb(10, 114, 161);
|
|
34
|
+
position: absolute;
|
|
35
|
+
top: 0;
|
|
36
|
+
left: 50%;
|
|
37
|
+
width: 2px;
|
|
38
|
+
height: 100%;
|
|
39
|
+
z-index: 1;
|
|
40
|
+
}
|
|
41
|
+
&-canvas {
|
|
42
|
+
display: block;
|
|
43
|
+
width: 100px;
|
|
44
|
+
height: 80px;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
&-footer {
|
|
48
|
+
height: 40px;
|
|
49
|
+
color: #fff;
|
|
50
|
+
font-size: 11px;
|
|
51
|
+
background-color: rgb(95, 94, 94);
|
|
52
|
+
padding: 4px;
|
|
53
|
+
white-space: nowrap;
|
|
54
|
+
overflow: hidden;
|
|
55
|
+
text-align: center;
|
|
56
|
+
&-item {
|
|
57
|
+
height: 18px;
|
|
58
|
+
line-height: 18px;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
memo,
|
|
3
|
+
useEffect,
|
|
4
|
+
useLayoutEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from "react";
|
|
8
|
+
import useLang from "../hooks/useLang";
|
|
9
|
+
import useStore from "../hooks/useStore";
|
|
10
|
+
import { Position } from "../types";
|
|
11
|
+
import "./index.scss";
|
|
12
|
+
|
|
13
|
+
export interface ScreenshotsMagnifierProps {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const magnifierWidth = 100;
|
|
19
|
+
const magnifierHeight = 80;
|
|
20
|
+
|
|
21
|
+
export default memo(function ScreenshotsMagnifier({
|
|
22
|
+
x,
|
|
23
|
+
y,
|
|
24
|
+
}: ScreenshotsMagnifierProps) {
|
|
25
|
+
const { width, height, image } = useStore();
|
|
26
|
+
const lang = useLang();
|
|
27
|
+
const [position, setPosition] = useState<Position | null>(null);
|
|
28
|
+
const elRef = useRef<HTMLDivElement>(null);
|
|
29
|
+
const canvasRef = useRef<HTMLCanvasElement>(null);
|
|
30
|
+
const ctxRef = useRef<CanvasRenderingContext2D | null>(null);
|
|
31
|
+
const [rgb, setRgb] = useState("000000");
|
|
32
|
+
|
|
33
|
+
useLayoutEffect(() => {
|
|
34
|
+
if (!elRef.current) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const elRect = elRef.current.getBoundingClientRect();
|
|
38
|
+
let tx = x + 20;
|
|
39
|
+
let ty = y + 20;
|
|
40
|
+
if (tx + elRect.width > width) {
|
|
41
|
+
tx = x - elRect.width - 20;
|
|
42
|
+
}
|
|
43
|
+
if (ty + elRect.height > height) {
|
|
44
|
+
ty = y - elRect.height - 20;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (tx < 0) {
|
|
48
|
+
tx = 0;
|
|
49
|
+
}
|
|
50
|
+
if (ty < 0) {
|
|
51
|
+
ty = 0;
|
|
52
|
+
}
|
|
53
|
+
setPosition({
|
|
54
|
+
x: tx,
|
|
55
|
+
y: ty,
|
|
56
|
+
});
|
|
57
|
+
}, [width, height, x, y]);
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (!image || !canvasRef.current) {
|
|
61
|
+
ctxRef.current = null;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!ctxRef.current) {
|
|
66
|
+
ctxRef.current = canvasRef.current.getContext("2d");
|
|
67
|
+
}
|
|
68
|
+
if (!ctxRef.current) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const ctx = ctxRef.current;
|
|
73
|
+
ctx.clearRect(0, 0, magnifierWidth, magnifierHeight);
|
|
74
|
+
const rx = image.naturalWidth / width;
|
|
75
|
+
const ry = image.naturalHeight / height;
|
|
76
|
+
// 显示原图比例
|
|
77
|
+
ctx.drawImage(
|
|
78
|
+
image,
|
|
79
|
+
x * rx - magnifierWidth / 2,
|
|
80
|
+
y * ry - magnifierHeight / 2,
|
|
81
|
+
magnifierWidth,
|
|
82
|
+
magnifierHeight,
|
|
83
|
+
0,
|
|
84
|
+
0,
|
|
85
|
+
magnifierWidth,
|
|
86
|
+
magnifierHeight,
|
|
87
|
+
);
|
|
88
|
+
const { data } = ctx.getImageData(
|
|
89
|
+
Math.floor(magnifierWidth / 2),
|
|
90
|
+
Math.floor(magnifierHeight / 2),
|
|
91
|
+
1,
|
|
92
|
+
1,
|
|
93
|
+
);
|
|
94
|
+
const hex = Array.from(data.slice(0, 3))
|
|
95
|
+
.map((val) => (val >= 16 ? val.toString(16) : `0${val.toString(16)}`))
|
|
96
|
+
.join("")
|
|
97
|
+
.toUpperCase();
|
|
98
|
+
|
|
99
|
+
setRgb(hex);
|
|
100
|
+
}, [width, height, image, x, y]);
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<div
|
|
104
|
+
ref={elRef}
|
|
105
|
+
className="screenshots-magnifier"
|
|
106
|
+
style={{
|
|
107
|
+
transform: `translate(${position?.x}px, ${position?.y}px)`,
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
<div className="screenshots-magnifier-body">
|
|
111
|
+
<canvas
|
|
112
|
+
ref={canvasRef}
|
|
113
|
+
className="screenshots-magnifier-body-canvas"
|
|
114
|
+
width={magnifierWidth}
|
|
115
|
+
height={magnifierHeight}
|
|
116
|
+
/>
|
|
117
|
+
</div>
|
|
118
|
+
<div className="screenshots-magnifier-footer">
|
|
119
|
+
<div className="screenshots-magnifier-footer-item">
|
|
120
|
+
{lang.magnifier_position_label}: ({x},{y})
|
|
121
|
+
</div>
|
|
122
|
+
<div className="screenshots-magnifier-footer-item">RGB: #{rgb}</div>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
@import "../var.scss";
|
|
2
|
+
|
|
3
|
+
.screenshots-operations {
|
|
4
|
+
position: absolute;
|
|
5
|
+
left: 0;
|
|
6
|
+
top: 0;
|
|
7
|
+
will-change: transform;
|
|
8
|
+
|
|
9
|
+
&-buttons {
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
padding: 3px;
|
|
13
|
+
border-radius: 2px;
|
|
14
|
+
border: 1px solid #ddd;
|
|
15
|
+
background-color: #fff;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&-divider {
|
|
20
|
+
background-color: #ddd;
|
|
21
|
+
width: 1px;
|
|
22
|
+
height: $button-size;
|
|
23
|
+
margin: 0 3px;
|
|
24
|
+
}
|
|
25
|
+
}
|