Skip to content

Commit

Permalink
add feature-detect for canvas-scan
Browse files Browse the repository at this point in the history
  • Loading branch information
rwv committed Nov 17, 2023
1 parent 5db2f17 commit 4f0f672
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const router = createRouter({
{
path: "/scan",
name: "scan",
component: () => import("@/views/MagicaScanView.vue"),
component: () => import("@/views/ScanViewFeatureDetectView.vue"),
},
{
path: "/scan-canvas",
Expand Down
23 changes: 23 additions & 0 deletions src/utils/scan-renderer/canvas-scan/feature-detect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export function featureDetect(): boolean {
const canvasMethods = [
"fillStyle",
"fillRect",
"filter",
"translate",
"rotate",
"drawImage",
"strokeStyle",
"lineWidth",
"strokeRect",
];

// check CanvasRenderingContext2D.prototype
const canvasProto = CanvasRenderingContext2D.prototype;
for (const method of canvasMethods) {
if (!(method in canvasProto)) {
return false;
}
}

return true;
}
1 change: 1 addition & 0 deletions src/utils/scan-renderer/canvas-scan/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { type ScanConfig, defaultConfig, colorspaces } from "./types";
export { CanvasScanner } from "./scanner";
export { featureDetect } from "./feature-detect";
12 changes: 12 additions & 0 deletions src/views/ScanViewFeatureDetectView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<CanvasScanView v-if="supportCanvasScan" />
<MagicaScanView v-else />
</template>

<script lang="ts" setup>
import { featureDetect } from "@/utils/scan-renderer/canvas-scan";
import CanvasScanView from "./CanvasScanView.vue";
import MagicaScanView from "./MagicaScanView.vue";
const supportCanvasScan = featureDetect();
</script>

0 comments on commit 4f0f672

Please sign in to comment.