-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
2,454 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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,68 @@ | ||
// MIT, https://github.com/feross/clipboard-copy/blob/master/index.js | ||
|
||
/** @deprecated use https://vueuse.org/core/useClipboard/#useclipboard */ | ||
export function canCopy() { | ||
try { | ||
const w = window as any | ||
return !!navigator.clipboard || document.queryCommandSupported('copy') || w.electron?.clipboard?.writeText | ||
} | ||
catch (err) { | ||
return false | ||
} | ||
} | ||
|
||
async function copyClipboardApi(text: string) { | ||
// Use the Async Clipboard API when available. Requires a secure browsing context (i.e. HTTPS) | ||
if (navigator.clipboard) | ||
return !!navigator.clipboard.writeText(text) | ||
return false | ||
} | ||
|
||
async function copyExecCommand(text: string) { | ||
// Put the text to copy into a <span> | ||
const span = document.createElement('span') | ||
span.textContent = text | ||
|
||
// Preserve consecutive spaces and newlines | ||
span.style.whiteSpace = 'pre' | ||
span.style.webkitUserSelect = 'auto' | ||
span.style.userSelect = 'all' | ||
|
||
// Add the <span> to the page | ||
document.body.appendChild(span) | ||
|
||
// Make a selection object representing the range of text selected by the user | ||
const selection = window.getSelection() as any | ||
const range = window.document.createRange() | ||
selection.removeAllRanges() | ||
range.selectNode(span) | ||
selection.addRange(range) | ||
|
||
// Copy text to the clipboard | ||
let success = false | ||
try { | ||
success = window.document.execCommand('copy') | ||
} | ||
finally { | ||
// Cleanup | ||
selection.removeAllRanges() | ||
window.document.body.removeChild(span) | ||
} | ||
|
||
return success | ||
} | ||
|
||
/** @deprecated use https://vueuse.org/core/useClipboard/#useclipboard */ | ||
export async function clipboardCopy(text: string) { | ||
const w = window as any | ||
if (w.electron) { | ||
// https://electronjs.org/docs/api/clipboard | ||
await w.electron?.clipboard?.writeText(text) | ||
return true | ||
} | ||
|
||
if (await copyClipboardApi(text)) | ||
return true | ||
|
||
return await copyExecCommand(text) | ||
} |
This file contains 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 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,30 @@ | ||
<script lang="ts" setup> | ||
import { reactive } from 'vue' | ||
import { OuiDemo, OuiInput, OuiQrcode } from '@/lib' | ||
import './oui-resizeable.demo.styl' | ||
const state = reactive({ | ||
content: 'https://oui.holtwick.de', | ||
}) | ||
</script> | ||
|
||
<template> | ||
<h2>QR Code</h2> | ||
|
||
<div> | ||
<OuiQrcode :content="state.content" /> | ||
</div> | ||
|
||
<OuiDemo :state="state"> | ||
<OuiInput v-model="state.content" switch title="content" /> | ||
</OuiDemo> | ||
</template> | ||
|
||
<style> | ||
.oui-qrcode svg { | ||
display: inline-block; | ||
max-width: min(50vh, 50vw); | ||
max-height: min(50vh, 50vw); | ||
} | ||
</style> |
This file contains 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,27 @@ | ||
<script lang="ts" setup> | ||
import { computed } from 'vue' | ||
import { Logger } from 'zeed' | ||
import { useQRCode } from './qrcode' | ||
const props = defineProps<{ | ||
content: string | ||
}>() | ||
const qrcode = useQRCode() | ||
const qrcodeHTML = computed(() => { | ||
const typeNumber = 0 | ||
const errorCorrectionLevel = 'M' | ||
const qr = qrcode(typeNumber, errorCorrectionLevel) as any | ||
qr.addData(props.content ?? '') | ||
qr.make() | ||
return qr.createSvgTag({ | ||
scalable: true, | ||
}) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="oui-qrcode" v-html="qrcodeHTML" /> | ||
</template> |
Oops, something went wrong.