nuxt-cap 0.1.1 โ†’ 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,6 +12,11 @@
12
12
  <img src="https://img.shields.io/badge/gitmoji-%20๐Ÿ˜œ%20๐Ÿ˜-FFDD67" alt="Gitmoji"/>
13
13
  </a>
14
14
  </p>
15
+ <h2 align="center">
16
+ <a href="https://nuxt-cap.pages.dev/">
17
+ ๐Ÿ“š Full Documentation
18
+ </a>
19
+ </h2>
15
20
 
16
21
  ## ๐Ÿš€ Setup
17
22
 
@@ -21,6 +26,25 @@ Install `nuxt-cap` dependency to your project:
21
26
  npx nuxt module add nuxt-cap
22
27
  ```
23
28
 
29
+ Or manually
30
+
31
+ 1. Install with your favorite package manager:
32
+ - **bun** : `bun add nuxt-cap`
33
+ - npm : `npm i nuxt-cap`
34
+ - pnpm : `pnpm add nuxt-cap`
35
+ - yarn : `yarn add nuxt-cap`
36
+
37
+ 2. Add it to your `modules` section in your `nuxt.config`:
38
+
39
+ ```ts
40
+ export default defineNuxtConfig({
41
+ modules: ['nuxt-cap'],
42
+ cap: {
43
+ // ...configs
44
+ },
45
+ })
46
+ ```
47
+
24
48
  ## โš™๏ธ Configuration
25
49
 
26
50
  You can configure **nuxt-cap** in two ways:
@@ -55,8 +79,6 @@ This module auto-imports a component called:
55
79
  <Cap />
56
80
  ```
57
81
 
58
- ---
59
-
60
82
  ## ๐Ÿ“ก Emits
61
83
 
62
84
  The component exposes four events:
@@ -70,13 +92,6 @@ The component exposes four events:
70
92
 
71
93
  ```vue
72
94
  <script setup lang="ts">
73
- import type {
74
- CapErrorEvent,
75
- CapProgressEvent,
76
- CapResetEvent,
77
- CapSolveEvent,
78
- } from '@cap.js/widget'
79
-
80
95
  function onSolve(event: CapSolveEvent): void {
81
96
  console.log('Solved:', event)
82
97
  }
@@ -181,9 +196,9 @@ resetCap()
181
196
 
182
197
  Calling `resetCap()` will reset the current widget state, allowing the challenge to be solved again.
183
198
 
184
- ## ๐Ÿ‘ป Invisible Mode
199
+ ## ๐Ÿช„ useCap composable
185
200
 
186
- For invisible mode, you can use the `useCap()` composable.
201
+ You can use the `useCap()` composable for invisible mode.
187
202
 
188
203
  It returns a Cap instance, similar to the one described in the official invisible guide:
189
204
 
package/dist/module.d.mts CHANGED
@@ -8,6 +8,7 @@ declare module 'nuxt/schema' {
8
8
  }
9
9
  }
10
10
  interface ModuleOptions {
11
+ enabled?: boolean;
11
12
  apiEndpoint?: string;
12
13
  }
13
14
  declare const module$1: NuxtModule<ModuleOptions>;
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "0.1.0",
7
+ "version": "0.1.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -2,7 +2,11 @@ import { defineNuxtModule, createResolver, addPlugin, addImports, addComponent }
2
2
 
3
3
  const module$1 = defineNuxtModule({
4
4
  meta: { name: "cap", configKey: "cap", compatibility: { nuxt: ">=3.0.0" } },
5
- setup({ apiEndpoint }, nuxt) {
5
+ defaults: { enabled: true, apiEndpoint: "" },
6
+ setup({ enabled, apiEndpoint }, nuxt) {
7
+ if (!enabled) {
8
+ return;
9
+ }
6
10
  const resolver = createResolver(import.meta.url);
7
11
  const { runtimeConfig } = nuxt.options;
8
12
  runtimeConfig.public.cap ??= {};
@@ -10,7 +14,15 @@ const module$1 = defineNuxtModule({
10
14
  addPlugin({ src: resolver.resolve("./runtime/plugins/cap"), mode: "client" });
11
15
  addImports([
12
16
  { name: "useCap", from: resolver.resolve("./runtime/composables/useCap") },
13
- { name: "resetCap", from: resolver.resolve("./runtime/utils/resetCap") }
17
+ { name: "resetCap", from: resolver.resolve("./runtime/utils/resetCap") },
18
+ { name: "CapConfig", from: resolver.resolve("./runtime/types/Cap.d"), type: true },
19
+ { name: "CapInstance", from: resolver.resolve("./runtime/types/Cap.d"), type: true },
20
+ { name: "CapClass", from: resolver.resolve("./runtime/types/Cap.d"), type: true },
21
+ { name: "CapWidget", from: resolver.resolve("./runtime/types/Cap.d"), type: true },
22
+ { name: "CapErrorEvent", from: resolver.resolve("./runtime/types/Cap.d"), type: true },
23
+ { name: "CapProgressEvent", from: resolver.resolve("./runtime/types/Cap.d"), type: true },
24
+ { name: "CapResetEvent", from: resolver.resolve("./runtime/types/Cap.d"), type: true },
25
+ { name: "CapSolveEvent", from: resolver.resolve("./runtime/types/Cap.d"), type: true }
14
26
  ]);
15
27
  addComponent({
16
28
  name: "Cap",
@@ -1,5 +1,5 @@
1
1
  import type { PropType } from 'vue';
2
- import type { CapErrorEvent, CapProgressEvent, CapResetEvent, CapSolveEvent } from '@cap.js/widget';
2
+ import type { CapErrorEvent, CapProgressEvent, CapResetEvent, CapSolveEvent } from '../types/Cap.js';
3
3
  declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
4
4
  workerCount: {
5
5
  type: NumberConstructor;
@@ -9,6 +9,7 @@ const props = defineProps({
9
9
  }
10
10
  });
11
11
  const emit = defineEmits(["solve", "error", "reset", "progress"]);
12
+ const { cap } = useRuntimeConfig().public;
12
13
  const capEl = ref();
13
14
  function solve(event) {
14
15
  emit("solve", event);
@@ -23,6 +24,11 @@ function progress(event) {
23
24
  emit("progress", event);
24
25
  }
25
26
  onNuxtReady(() => {
27
+ if (!cap?.apiEndpoint) {
28
+ throw new Error(
29
+ '[Cap] No API endpoint provided. Please set the "cap.apiEndpoint" runtime config or provide it in nuxt config.'
30
+ );
31
+ }
26
32
  const el = capEl.value;
27
33
  if (!el) return;
28
34
  el.addEventListener("solve", solve);
@@ -38,7 +44,6 @@ onUnmounted(() => {
38
44
  el.removeEventListener("reset", reset);
39
45
  el.removeEventListener("progress", progress);
40
46
  });
41
- const { cap } = useRuntimeConfig().public;
42
47
  </script>
43
48
 
44
49
  <template>
@@ -1,5 +1,5 @@
1
1
  import type { PropType } from 'vue';
2
- import type { CapErrorEvent, CapProgressEvent, CapResetEvent, CapSolveEvent } from '@cap.js/widget';
2
+ import type { CapErrorEvent, CapProgressEvent, CapResetEvent, CapSolveEvent } from '../types/Cap.js';
3
3
  declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
4
4
  workerCount: {
5
5
  type: NumberConstructor;
@@ -1,2 +1,2 @@
1
- import type { Cap, CapConfig, CapWidget } from '@cap.js/widget';
2
- export declare function useCap(config?: CapConfig, el?: CapWidget): Cap | undefined;
1
+ import type { CapConfig, CapInstance, CapWidget } from '../types/Cap.js';
2
+ export declare function useCap(config?: CapConfig, el?: CapWidget): CapInstance | undefined;
@@ -3,6 +3,12 @@ export function useCap(config, el) {
3
3
  const { $cap } = useNuxtApp();
4
4
  const { cap } = useRuntimeConfig().public;
5
5
  if (!import.meta.client || !$cap) return;
6
+ if (!cap?.apiEndpoint && !config?.apiEndpoint) {
7
+ console.error(
8
+ '[useCap] No API endpoint provided. Please set the "cap.apiEndpoint" runtime config or provide it in the config parameter.'
9
+ );
10
+ return;
11
+ }
6
12
  const capInstance = new $cap({ apiEndpoint: cap?.apiEndpoint, ...config }, el);
7
13
  return capInstance;
8
14
  }
@@ -1,11 +1,11 @@
1
- import type CapClass from '@cap.js/widget';
1
+ import type { CapClass } from '../types/Cap.js';
2
2
  import '@cap.js/widget';
3
3
  declare global {
4
- var Cap: typeof CapClass;
4
+ var Cap: CapClass | undefined;
5
5
  }
6
6
  declare const _default: import("nuxt/app").Plugin<{
7
- cap: typeof CapClass;
7
+ cap: typeof import("#imports").CapInstance | undefined;
8
8
  }> & import("nuxt/app").ObjectPlugin<{
9
- cap: typeof CapClass;
9
+ cap: typeof import("#imports").CapInstance | undefined;
10
10
  }>;
11
11
  export default _default;
@@ -0,0 +1,22 @@
1
+ import type {
2
+ CapConfig,
3
+ CapErrorEvent,
4
+ Cap as CapInstance,
5
+ CapProgressEvent,
6
+ CapResetEvent,
7
+ CapSolveEvent,
8
+ CapWidget,
9
+ } from '@cap.js/widget'
10
+
11
+ type CapClass = typeof CapInstance
12
+
13
+ export type {
14
+ CapConfig,
15
+ CapInstance,
16
+ CapClass,
17
+ CapWidget,
18
+ CapErrorEvent,
19
+ CapProgressEvent,
20
+ CapResetEvent,
21
+ CapSolveEvent,
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-cap",
3
- "version": "0.1.1",
3
+ "version": "1.0.0",
4
4
  "description": "๐Ÿงข Integrate Cap into your Nuxt websites/applications.",
5
5
  "keywords": [
6
6
  "cbpf",
@@ -44,6 +44,8 @@
44
44
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
45
45
  "dev:build": "nuxi build playground",
46
46
  "build": "nuxt-module-build build",
47
+ "docs:dev": "vitepress dev docs",
48
+ "docs:build": "vitepress build docs",
47
49
  "fmt": "oxfmt --check",
48
50
  "fmt:fix": "oxfmt",
49
51
  "lint": "oxlint --type-aware",
@@ -57,13 +59,15 @@
57
59
  "@nuxt/kit": "^4.3.1"
58
60
  },
59
61
  "devDependencies": {
60
- "@dethdkn/ox-config": "^1.0.10",
62
+ "@dethdkn/ox-config": "^1.0.12",
61
63
  "@nuxt/module-builder": "^1.0.2",
62
64
  "@nuxt/schema": "^4.3.1",
63
65
  "@types/bun": "^1.3.9",
64
66
  "bumpp": "^10.4.1",
65
67
  "nuxt": "^4.3.1",
66
68
  "typescript": "5.9.3",
69
+ "vitepress": "^1.6.4",
67
70
  "vue-tsc": "^3.2.4"
68
- }
71
+ },
72
+ "packageManager": "bun@1.3.9"
69
73
  }