-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(1) Remove global plugin installation idiom from `src/index.ts` since `Vue.use` was removed in Vue 3 and causes an error when actually executed. See: https://v3-migration.vuejs.org/breaking-changes/global-api.html#a-note-for-plugin-authors (2) Add an additional build artifact `vue-qrcode-reader.umd.js` that is just a copy of `vue-qrcoder-reader.umd.cjs`. Doing a `script`- tag import of `cjs` files, doesn't work if the server doesn't also set the `Content-Type` correctly (as pointed out by @Sec-ant), which is the case with some Unpkg for example. So it seems weird that Vite uses that as the default file type for UMD artifacts. The purpose of UMD is to be both compatible with CommonJS and simple `script` imports. Let's keep both files for backwards- compatibility for now. (3) Instead of theh CodePen implementation of the "Simple" demo just use an (even simpler) HTML file stored in the public assets of the Vitepress page. See: #369 #384
- Loading branch information
Showing
4 changed files
with
84 additions
and
31 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,79 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<title>Simple Demo</title> | ||
|
||
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> | ||
<script src="https://unpkg.com/vue-qrcode-reader@5/dist/vue-qrcode-reader.umd.js"></script> | ||
</head> | ||
<body> | ||
<div id="app"> | ||
<h1>Simple Demo</h1> | ||
|
||
<p style="color: red">{{ error }}</p> | ||
|
||
<p>Last result: <b>{{ result }}</b></p> | ||
|
||
<div style="border: 2px solid black"> | ||
<qrcode-stream :track="paintBoundingBox" @detect="onDetect" @error="onError"></qrcode-stream> | ||
</div> | ||
</div> | ||
</body> | ||
<script> | ||
const { createApp, ref } = Vue | ||
|
||
const result = ref('') | ||
const error = ref('') | ||
|
||
function paintBoundingBox(detectedCodes, ctx) { | ||
for (const detectedCode of detectedCodes) { | ||
const { | ||
boundingBox: { x, y, width, height } | ||
} = detectedCode | ||
|
||
ctx.lineWidth = 2 | ||
ctx.strokeStyle = '#007bff' | ||
ctx.strokeRect(x, y, width, height) | ||
} | ||
} | ||
|
||
function onError(err) { | ||
error.value = `[${err.name}]: ` | ||
|
||
if (err.name === 'NotAllowedError') { | ||
error.value += 'you need to grant camera access permission' | ||
} else if (err.name === 'NotFoundError') { | ||
error.value += 'no camera on this device' | ||
} else if (err.name === 'NotSupportedError') { | ||
error.value += 'secure context required (HTTPS, localhost)' | ||
} else if (err.name === 'NotReadableError') { | ||
error.value += 'is the camera already in use?' | ||
} else if (err.name === 'OverconstrainedError') { | ||
error.value += 'installed cameras are not suitable' | ||
} else if (err.name === 'StreamApiNotSupportedError') { | ||
error.value += 'Stream API is not supported in this browser' | ||
} else if (err.name === 'InsecureContextError') { | ||
error.value += 'Camera access is only permitted in secure context. Use HTTPS or localhost rather than HTTP.' | ||
} else { | ||
error.value += err.message | ||
} | ||
} | ||
|
||
function onDetect(detectedCodes) { | ||
result.value = JSON.stringify( | ||
detectedCodes.map(code => code.rawValue) | ||
) | ||
} | ||
|
||
const app = createApp({ | ||
setup() { | ||
return { result, error, onDetect, onError, paintBoundingBox } | ||
} | ||
}) | ||
app.use(VueQrcodeReader) | ||
app.mount('#app') | ||
</script> | ||
</html> |
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