diff --git a/docs/.vitepress/config.mjs b/docs/.vitepress/config.mjs index f4707fb..fb8d144 100644 --- a/docs/.vitepress/config.mjs +++ b/docs/.vitepress/config.mjs @@ -82,6 +82,13 @@ export default defineConfig({ } `, ], + [ + "script", + { + src: "https://unpkg.com/@cap.js/widget", + async: true, + } + ] ], themeConfig: { search: { diff --git a/docs/.vitepress/theme/components/Benchmark.vue b/docs/.vitepress/theme/components/Benchmark.vue index 65d44fb..b8e2017 100644 --- a/docs/.vitepress/theme/components/Benchmark.vue +++ b/docs/.vitepress/theme/components/Benchmark.vue @@ -13,13 +13,13 @@ const progressValue = ref(0); async function runBenchmark() { if (isRunning.value) return; + const Cap = window.Cap; + isRunning.value = true; progressValue.value = 0; resultMessage.value = "Running benchmark... 0%"; try { - const { default: Cap } = await import("https://unpkg.com/@cap.js/widget"); - window.CAP_CUSTOM_FETCH = async (url, options) => { if (url === "/api/challenge") { const browserCrypto = window.crypto; diff --git a/docs/.vitepress/theme/components/Demo.vue b/docs/.vitepress/theme/components/Demo.vue index da65605..170e45a 100644 --- a/docs/.vitepress/theme/components/Demo.vue +++ b/docs/.vitepress/theme/components/Demo.vue @@ -2,57 +2,50 @@ import { onMounted } from "vue"; onMounted(() => { - import("https://unpkg.com/@cap.js/widget") - .then(({ default: Cap }) => { - window.CAP_CUSTOM_FETCH = async (url, options) => { - if (url === "/api/challenge") { - const browserCrypto = window.crypto; - return new Response( - JSON.stringify({ - challenge: Array.from({ length: 18 }, () => [ - Array.from( - browserCrypto.getRandomValues( - new Uint8Array(Math.ceil(32 / 2)) - ) - ) - .map((byte) => byte.toString(16).padStart(2, "0")) - .join("") - .slice(0, 32), + window.CAP_CUSTOM_FETCH = async (url, options) => { + if (url === "/api/challenge") { + const browserCrypto = window.crypto; + return new Response( + JSON.stringify({ + challenge: Array.from({ length: 18 }, () => [ + Array.from( + browserCrypto.getRandomValues(new Uint8Array(Math.ceil(32 / 2))) + ) + .map((byte) => byte.toString(16).padStart(2, "0")) + .join("") + .slice(0, 32), - Array.from( - browserCrypto.getRandomValues( - new Uint8Array(Math.ceil(4 / 2)) - ) - ) - .map((byte) => byte.toString(16).padStart(2, "0")) - .join("") - .slice(0, 4), - ]), - token: "", - expires: new Date().getTime() + 6000 * 100, - }), - { - status: 200, - headers: { "Content-Type": "application/json" }, - } - ); + Array.from( + browserCrypto.getRandomValues(new Uint8Array(Math.ceil(4 / 2))) + ) + .map((byte) => byte.toString(16).padStart(2, "0")) + .join("") + .slice(0, 4), + ]), + token: "", + expires: new Date().getTime() + 6000 * 100, + }), + { + status: 200, + headers: { "Content-Type": "application/json" }, } - if (url === "/api/redeem") { - return new Response( - JSON.stringify({ - success: true, - token: "", - expires: new Date().getTime() + 1000 * 60, - }), - { - status: 200, - headers: { "Content-Type": "application/json" }, - } - ); + ); + } + if (url === "/api/redeem") { + return new Response( + JSON.stringify({ + success: true, + token: "", + expires: new Date().getTime() + 1000 * 60, + }), + { + status: 200, + headers: { "Content-Type": "application/json" }, } - return await window.fetch(url, options); - }; - }) + ); + } + return await window.fetch(url, options); + }; }); diff --git a/docs/package.json b/docs/package.json index ca74d3a..c1ec3b5 100644 --- a/docs/package.json +++ b/docs/package.json @@ -9,6 +9,7 @@ "vue": "^3.5.13" }, "dependencies": { + "@cap.js/widget": "^0.0.22", "vitepress": "^1.6.3" } } \ No newline at end of file