Skip to content

Commit

Permalink
add Export to svg
Browse files Browse the repository at this point in the history
  • Loading branch information
jerosoler committed Sep 6, 2023
1 parent b8c2639 commit 89de260
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"qrcode-vue3": "^1.6.8",
"uqr": "^0.1.2",
"vcard4": "^3.1.5",
"vue": "^3.3.4"
},
Expand Down
25 changes: 22 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
NProperty,
VCARD,
} from "vcard4";
import { renderSVG } from 'uqr'
import { ref, watchEffect } from 'vue'
const fullname = ref('');
Expand All @@ -28,6 +29,18 @@ const company = ref('');
const job = ref('');
const qrcode = ref('');
function downloadSVG() {
const svg = renderSVG(qrcode.value);
const svgBlob = new Blob([svg], {type:"image/svg+xml;charset=utf-8"});
const svgUrl = URL.createObjectURL(svgBlob);
const downloadLink = document.createElement("a");
downloadLink.href = svgUrl;
downloadLink.download = 'vcard-qr';
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}
watchEffect(() => {
const fields = [];
if(fullname.value !== "") {
Expand All @@ -36,7 +49,8 @@ watchEffect(() => {
}
if(phone.value !== "") {
const cardPhone = new TelProperty([], new URIType(`tel:${phone.value}`));
//const cardPhone = new TelProperty([], new URIType(`tel:${phone.value}`));
const cardPhone = new TelProperty([], new TextType(`${phone.value}`));
fields.push(cardPhone);
}
Expand Down Expand Up @@ -69,6 +83,8 @@ watchEffect(() => {
}
const card = new VCARD(fields);
qrcode.value = card.repr();
} else {
qrcode.value = '';
}
Expand All @@ -86,7 +102,6 @@ watchEffect(() => {
<input v-model="company" placeholder="company Name">
<input v-model="job" placeholder="Job Title">
</div>

<QRCodeVue3 :value="qrcode"
:width="200"
:height="200"
Expand All @@ -103,9 +118,10 @@ watchEffect(() => {
:cornersDotOptions="{ type: undefined, color: '#000000' }"
fileExt="png"
:download="true"
downloadButton="my-button"
downloadButton="download"
:downloadOptions="{ name: 'vcard-qr', extension: 'png' }"
/>
<button class="download" @click="downloadSVG" v-if="qrcode !== ''">Download SVG</button>
</template>

<style scoped>
Expand All @@ -115,4 +131,7 @@ watchEffect(() => {
gap: 18px;
margin-bottom: 20px;
}
.download {
margin-top: 20px;
}
</style>

0 comments on commit 89de260

Please sign in to comment.