-
Notifications
You must be signed in to change notification settings - Fork 91
feat: HTML2Canvas #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LIUBINfighter
wants to merge
17
commits into
SUSTech-Application:master
Choose a base branch
from
LIUBINfighter:html2canvas
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: HTML2Canvas #243
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c618a2f
feat: select-share-menu (#211)
LIUBINfighter 6cad175
feat: card-preview ShareCard.vue (#211)
LIUBINfighter aeac923
fix: background color (#211)
LIUBINfighter 15b8fc4
feat: support selected html el (#211)
LIUBINfighter 02373a5
feat: qrcode added (#211)
LIUBINfighter 099969b
fix: qrcode tab-switch (#211)
LIUBINfighter 4f223a9
feat: Support triple resolution (#211)
LIUBINfighter f980d1d
feat: smaller QR aligned to the right (#211)
LIUBINfighter 11e5050
fix: delete defineProps & defineEmits (#211)
LIUBINfighter fbd7ada
Merge branch 'SUSTech-Application:master' into html2canvas
LIUBINfighter 4d60fb0
Merge branch 'html2canvas' of https://github.com/LIUBINfighter/SUSTec…
LIUBINfighter fe4b8e9
feat: more color to choose (#211)
LIUBINfighter caf9403
feat: add to clipboard (#211)
LIUBINfighter 4a3e6da
feat: add ts definition (#211)
LIUBINfighter 5d3b021
refactor: ts (#211)
LIUBINfighter e2aac55
fix: lint:es (#211)
LIUBINfighter 09633a3
Merge branch 'master' into html2canvas
LIUBINfighter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <script setup lang="ts"> | ||
| import DefaultTheme from "vitepress/theme"; | ||
|
|
||
| import SelectionShareMenu from "./SelectionShareMenu.vue"; | ||
|
|
||
| const { Layout: DefaultLayout } = DefaultTheme; | ||
| </script> | ||
|
|
||
| <template> | ||
| <DefaultLayout> | ||
| <template #layout-bottom> | ||
| <SelectionShareMenu /> | ||
| </template> | ||
| </DefaultLayout> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| <script setup lang="ts"> | ||
| import { onMounted, onUnmounted, ref } from "vue"; | ||
|
|
||
| import ShareCard from "./ShareCard.vue"; | ||
|
|
||
| const menuVisible = ref<boolean>(false); | ||
| const menuPosition = ref<{ x: number; y: number }>({ x: 0, y: 0 }); | ||
| const selectedText = ref<string>(""); | ||
| const shareCardVisible = ref<boolean>(false); | ||
|
|
||
| // Function to show the menu | ||
| const showMenu = (x: number, y: number, text: string) => { | ||
| if (text && text.trim() !== "") { | ||
| selectedText.value = text; | ||
| menuPosition.value = { x, y }; | ||
| menuVisible.value = true; | ||
| } | ||
| }; | ||
|
|
||
| // Function to hide the menu | ||
| const hideMenu = () => { | ||
| menuVisible.value = false; | ||
| }; | ||
|
|
||
| // Handle text selection | ||
| const handleSelection = () => { | ||
| if (typeof window === "undefined") return; | ||
|
|
||
| const selection = window.getSelection(); | ||
| if (selection && selection.toString().trim() !== "") { | ||
| const range = selection.getRangeAt(0); | ||
| const rect = range.getBoundingClientRect(); | ||
|
|
||
| // Position the menu above the selection | ||
| const x = rect.left + rect.width / 2; | ||
| const y = rect.top - 10; // Position above the selection | ||
|
|
||
| // 获取选中文本的HTML内容 | ||
| const container = document.createElement("div"); | ||
| const clonedSelection = range.cloneContents(); | ||
| container.appendChild(clonedSelection); | ||
| const htmlContent = container.innerHTML; | ||
|
|
||
| // 使用HTML内容而不是纯文本 | ||
| showMenu(x, y, htmlContent); | ||
| } | ||
| }; | ||
|
|
||
| // Handle mouseup event to detect selection | ||
| const handleMouseUp = () => { | ||
| // 如果分享卡片已显示,不再监听选择变化 | ||
| if (typeof window === "undefined" || shareCardVisible.value) return; | ||
| setTimeout(handleSelection, 10); // Small delay to ensure selection is complete | ||
| }; | ||
|
|
||
| // Copy selected text to clipboard | ||
| const copyText = async () => { | ||
| if (typeof navigator === "undefined") return; | ||
|
|
||
| try { | ||
| await navigator.clipboard.writeText(selectedText.value); | ||
| // Use a non-blocking notification instead of alert | ||
| console.log("文本已复制到剪贴板"); | ||
| hideMenu(); | ||
| } catch (err) { | ||
| console.error("复制失败:", err); | ||
| } | ||
| }; | ||
|
|
||
| // Share selected text | ||
| const shareText = () => { | ||
| // Show share card in the current page | ||
| shareCardVisible.value = true; | ||
| hideMenu(); | ||
| }; | ||
|
|
||
| // Close share card | ||
| const closeShareCard = () => { | ||
| shareCardVisible.value = false; | ||
| // 清空选中的文本,以便用户可以重新选择 | ||
| setTimeout(() => { | ||
| if (typeof window !== "undefined") { | ||
| window.getSelection()?.removeAllRanges(); | ||
| } | ||
| }, 100); | ||
| }; | ||
|
|
||
| // Click outside to hide menu | ||
| const handleClickOutside = (event: MouseEvent) => { | ||
| const target = event.target as HTMLElement; | ||
| if (menuVisible.value && !target.closest(".selection-menu")) { | ||
| hideMenu(); | ||
| } | ||
| }; | ||
|
|
||
| onMounted(() => { | ||
| if (typeof document === "undefined") return; | ||
|
|
||
| document.addEventListener("mouseup", handleMouseUp); | ||
| document.addEventListener("mousedown", handleClickOutside); | ||
| }); | ||
|
|
||
| onUnmounted(() => { | ||
| if (typeof document === "undefined") return; | ||
|
|
||
| document.removeEventListener("mouseup", handleMouseUp); | ||
| document.removeEventListener("mousedown", handleClickOutside); | ||
| }); | ||
| </script> | ||
|
|
||
| <template> | ||
| <div> | ||
| <div | ||
| v-if="menuVisible" | ||
| class="selection-menu" | ||
| :style="{ | ||
| left: `${menuPosition.x}px`, | ||
| top: `${menuPosition.y}px`, | ||
| transform: 'translate(-50%, -100%)', | ||
| }" | ||
| > | ||
| <button class="menu-button copy-button" title="复制" @click="copyText"> | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="16" | ||
| height="16" | ||
| viewBox="0 0 24 24" | ||
| fill="none" | ||
| stroke="currentColor" | ||
| stroke-width="2" | ||
| stroke-linecap="round" | ||
| stroke-linejoin="round" | ||
| > | ||
| <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect> | ||
| <path | ||
| d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" | ||
| ></path> | ||
| </svg> | ||
| </button> | ||
| <button class="menu-button share-button" title="分享" @click="shareText"> | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="16" | ||
| height="16" | ||
| viewBox="0 0 24 24" | ||
| fill="none" | ||
| stroke="currentColor" | ||
| stroke-width="2" | ||
| stroke-linecap="round" | ||
| stroke-linejoin="round" | ||
| > | ||
| <circle cx="18" cy="5" r="3"></circle> | ||
| <circle cx="6" cy="12" r="3"></circle> | ||
| <circle cx="18" cy="19" r="3"></circle> | ||
| <line x1="8.59" y1="13.51" x2="15.42" y2="17.49"></line> | ||
| <line x1="15.41" y1="6.51" x2="8.59" y2="10.49"></line> | ||
| </svg> | ||
| </button> | ||
| </div> | ||
|
|
||
| <!-- Share Card Component --> | ||
| <ShareCard | ||
| :text="selectedText" | ||
| :visible="shareCardVisible" | ||
| @close="closeShareCard" | ||
| /> | ||
| </div> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
| .selection-menu { | ||
| position: fixed; | ||
| display: flex; | ||
| background-color: #333; | ||
| border-radius: 4px; | ||
| box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3); | ||
| z-index: 1000; | ||
| padding: 8px; | ||
| } | ||
|
|
||
| .menu-button { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| width: 32px; | ||
| height: 32px; | ||
| margin: 0 4px; | ||
| border: none; | ||
| border-radius: 4px; | ||
| cursor: pointer; | ||
| background-color: transparent; | ||
| color: white; | ||
| transition: background-color 0.2s; | ||
| } | ||
|
|
||
| .menu-button:hover { | ||
| background-color: rgba(255, 255, 255, 0.1); | ||
| } | ||
| </style> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESLint 配置不需要手动加这么多 globals,只需要这样即可:
需要安装 globals 作为依赖