@taprel/vue
v0.1.1
Published
Taprel for Vue: composables for silent printing from web apps, through the desktop agent
Maintainers
Readme
Taprel for Vue
Silent printing from Vue apps: your page calls these composables, and the Taprel desktop agent on the customer's PC prints with no print dialog. Works with Vue 3.3 or newer, in Vite, Nuxt and similar.
Full guide: taprel.com/docs/quick-start, with the Vue tab.
Install
npm install @taprel/vueThis brings @taprel/sdk with it, and everything in the SDK can be imported from here. Printing also needs the Taprel agent installed on the PC with the printer. It's for Windows for now.
Add the plugin
import { createApp } from "vue";
import { createTaprel } from "@taprel/vue";
import App from "./App.vue";
createApp(App)
.use(createTaprel({ client: { name: "my-pos" } }))
.mount("#app");Print a receipt
<script setup lang="ts">
import { PrintHelp, receipt, usePrint } from "@taprel/vue";
const { print, isPrinting, error } = usePrint();
function printReceipt() {
print(
receipt([
{ text: "Café Central", align: "center", bold: true, size: 2 },
{ line: true },
{ row: ["2 x Coffee", "6.00"] },
{ row: ["Total", "6.00"], bold: true },
{ cut: true },
]),
);
}
</script>
<template>
<PrintHelp />
<button :disabled="isPrinting" @click="printReceipt">Print</button>
<p v-if="error">{{ error.message }}</p>
</template>The agent picks the customer's receipt printer, so no printer name ends up in your code. The SDK's README explains how to write documents and lists every error code.
When the customer gets asked
The first connection can show the customer two questions: the browser's and the agent's. Nothing here connects until you ask, so opening a page never shows them. They appear on the first print, on connect(), or on mount if you choose autoConnect.
PrintHelp tells the customer what to do while they wait, and when something is wrong. It shows nothing when all is well.
What's included
The results are refs: templates read them directly, and scripts use .value.
| Name | What it does |
|---|---|
| createTaprel(options) | The plugin. Takes the SDK client's options, autoConnect, or your own printClient. Its client works outside components |
| usePrint() | print, printPdf, printRaw, isPrinting, error, result, warnings, reset |
| useTaprel() | status, error, agent, isConnected, connect, disconnect, client |
| usePrinters({ kind }) | printers, isLoading, error, refresh. Loads once connected |
| usePreview(doc, { printer, printerKind, delayMs }) | src for an <img>, preview, isLoading, error. doc can be a function that builds the document |
| PrintHelp | The customer's next step, with no styles of its own. Takes texts, downloadUrl, downloadText |
| usePrintHelp(texts) | The same message as { kind, message }, for your own UI |
Good to know
- Failed prints:
printgivesnulland setserror, so a click handler needs notry. Each call sends once and never retries, because a retry could print twice. AfterCONNECTION_LOSTorREQUEST_TIMEOUTthe job may still print, so let the person decide. - Double clicks: a second click sends a second print, so disable your button with
isPrinting. - "Printed": a
resultmeans "handed to the print queue", not "came out on paper". A job for an offline printer waits in the queue. - Printer list: check each printer's
status. The list doesn't update by itself, so callrefreshfrom a click. - Previews:
usePreviewasks nothing until connected, so callconnect()from a click if you want a preview before the first print. - Nuxt: add the plugin in
app/plugins/taprel.tswithnuxtApp.vueApp.use(createTaprel()). Nothing connects on the server. - Other languages: pass your own
textstoPrintHelp. The defaults are in English.
Development
npm test: builds and runs the tests in a pretend browser against a pretend agent
License
This package is MIT. The desktop agent it talks to is a separate product with its own terms.
