@vueuse/nuxt 7.0.0-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019-PRESENT Anthony Fu<https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # @vueuse/nuxt
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/@vueuse/nuxt?color=a1b858)](https://www.npmjs.com/package/@vueuse/nuxt)
4
+
5
+ > This is an add-on of [VueUse](https://github.com/vueuse/vueuse), provides Nuxt specific composables and auto-import capabilities.
6
+
7
+ > Expiremental. **Will NOT follow semvar**.
8
+
9
+ ## Install
10
+
11
+ <pre class='language-bash'>
12
+ npm i <b>@vueuse/nuxt</b>
13
+ </pre>
14
+
15
+ ```ts
16
+ // nuxt.config
17
+
18
+ export function defineNuxtConfig({
19
+ buildModules: [
20
+ '@vueuse/nuxt/module'
21
+ ]
22
+ })
23
+ ```
24
+
25
+ ## Functions
26
+
27
+ `@vueuse/nuxt` provides the following functions
28
+
29
+ <!--GENERATED LIST, DO NOT MODIFY MANUALLY-->
30
+ <!--FUNCTIONS_LIST_STARTS-->
31
+ - [`useNuxtDark`](https://vueuse.org/nuxt/useNuxtDark/) — reactive dark mode with auto data persistence for Nuxt
32
+
33
+
34
+ <!--FUNCTIONS_LIST_ENDS-->
35
+
36
+ ## License
37
+
38
+ [MIT License](https://github.com/vueuse/vueuse/blob/master/LICENSE) © 2021-PRESENT [Anthony Fu](https://github.com/antfu)
package/index.cjs ADDED
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@vueuse/core');
6
+ var vueDemi = require('vue-demi');
7
+ var _app = require('#app');
8
+
9
+ function useNuxtDark(options = {}) {
10
+ const {
11
+ attribute = "class",
12
+ valueDark = "dark",
13
+ valueLight = "light",
14
+ window = core.defaultWindow,
15
+ cookieKey = "vueuse-color-schema"
16
+ } = options;
17
+ const preferredDark = core.usePreferredDark({ window });
18
+ const store = _app.useCookie(cookieKey);
19
+ if (store.value == null)
20
+ store.value = "auto";
21
+ const isDark = vueDemi.computed({
22
+ get() {
23
+ return store.value === "auto" ? preferredDark.value : store.value === "dark";
24
+ },
25
+ set(v) {
26
+ if (v === preferredDark.value)
27
+ store.value = "auto";
28
+ else
29
+ store.value = v ? "dark" : "light";
30
+ }
31
+ });
32
+ _app.useMeta(vueDemi.computed(() => ({
33
+ htmlAttrs: {
34
+ [attribute]: isDark.value ? valueDark : valueLight
35
+ }
36
+ })));
37
+ return isDark;
38
+ }
39
+
40
+ exports.useNuxtDark = useNuxtDark;
41
+ Object.keys(core).forEach(function (k) {
42
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
43
+ enumerable: true,
44
+ get: function () { return core[k]; }
45
+ });
46
+ });
package/index.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ import * as vue_demi from 'vue-demi';
2
+ import { ConfigurableWindow } from '@vueuse/core';
3
+ export * from '@vueuse/core';
4
+
5
+ interface UseNuxtDarkOptions extends ConfigurableWindow {
6
+ /**
7
+ * HTML attribute applying the target element
8
+ *
9
+ * @default 'class'
10
+ */
11
+ attribute?: string;
12
+ /**
13
+ * Value applying to the target element when isDark=true
14
+ *
15
+ * @default 'dark'
16
+ */
17
+ valueDark?: string;
18
+ /**
19
+ * Value applying to the target element when isDark=false
20
+ *
21
+ * @default 'light'
22
+ */
23
+ valueLight?: string;
24
+ /**
25
+ * A custom handler for handle the updates.
26
+ * When specified, the default behavior will be overridded.
27
+ *
28
+ * @default undefined
29
+ */
30
+ onChanged?: (isDark: boolean) => void;
31
+ /**
32
+ * Key to persist the data into Nuxt's useCookie.
33
+ *
34
+ * Pass `null` to disable persistence
35
+ *
36
+ * @default 'vueuse-color-schema'
37
+ */
38
+ cookieKey?: string;
39
+ }
40
+ /**
41
+ * Reactive dark mode with auto data persistence for Nuxt.
42
+ *
43
+ * @see https://vueuse.org/useNuxtDark
44
+ * @param options
45
+ */
46
+ declare function useNuxtDark(options?: UseNuxtDarkOptions): vue_demi.WritableComputedRef<boolean>;
47
+
48
+ export { UseNuxtDarkOptions, useNuxtDark };
package/index.mjs ADDED
@@ -0,0 +1,37 @@
1
+ import { usePreferredDark, defaultWindow } from '@vueuse/core';
2
+ export * from '@vueuse/core';
3
+ import { computed } from 'vue-demi';
4
+ import { useCookie, useMeta } from '#app';
5
+
6
+ function useNuxtDark(options = {}) {
7
+ const {
8
+ attribute = "class",
9
+ valueDark = "dark",
10
+ valueLight = "light",
11
+ window = defaultWindow,
12
+ cookieKey = "vueuse-color-schema"
13
+ } = options;
14
+ const preferredDark = usePreferredDark({ window });
15
+ const store = useCookie(cookieKey);
16
+ if (store.value == null)
17
+ store.value = "auto";
18
+ const isDark = computed({
19
+ get() {
20
+ return store.value === "auto" ? preferredDark.value : store.value === "dark";
21
+ },
22
+ set(v) {
23
+ if (v === preferredDark.value)
24
+ store.value = "auto";
25
+ else
26
+ store.value = v ? "dark" : "light";
27
+ }
28
+ });
29
+ useMeta(computed(() => ({
30
+ htmlAttrs: {
31
+ [attribute]: isDark.value ? valueDark : valueLight
32
+ }
33
+ })));
34
+ return isDark;
35
+ }
36
+
37
+ export { useNuxtDark };
package/module.cjs ADDED
@@ -0,0 +1,6 @@
1
+ // CommonJS proxy to bypass jiti transforms from nuxt 2 and using native ESM
2
+ module.exports = function(...args) {
3
+ return import('./module.mjs').then(m => m.default.call(this, ...args))
4
+ }
5
+
6
+ module.exports.meta = require('./package.json')
package/module.d.ts ADDED
@@ -0,0 +1 @@
1
+ export default function(): void
package/module.mjs ADDED
@@ -0,0 +1,67 @@
1
+ import fs from 'fs'
2
+ import { dirname, resolve } from 'path'
3
+ import { fileURLToPath } from 'url'
4
+
5
+ const __dirname = dirname(fileURLToPath(import.meta.url))
6
+
7
+ const disabled = [
8
+ 'useFetch',
9
+ 'toRefs',
10
+ 'useCookie',
11
+ ]
12
+
13
+ /**
14
+ * Auto import for VueUse in Nuxt
15
+ * Usage:
16
+ *
17
+ * ```ts
18
+ * // nuxt.config.js
19
+ * export deafult {
20
+ * buildModules: [
21
+ * '@vueuse/core/nuxt'
22
+ * ]
23
+ * }
24
+ * ```
25
+ */
26
+ export default function() {
27
+ const { nuxt } = this
28
+
29
+ // opt-out Vite deps optimization for VueUse
30
+ nuxt.hook('vite:extend', ({ config }) => {
31
+ config.optimizeDeps = config.optimizeDeps || {}
32
+ config.optimizeDeps.exclude = config.optimizeDeps.exclude || []
33
+ config.optimizeDeps.exclude.push(
34
+ '@vueuse/core',
35
+ '@vueuse/shared',
36
+ '@vueuse/nuxt',
37
+ '@vueuse/integrations',
38
+ '@vueuse/components',
39
+ '@vueuse/motion',
40
+ '@vueuse/firebase',
41
+ '@vueuse/rxjs',
42
+ '@vueuse/sound',
43
+ '@vueuse/head',
44
+ )
45
+ })
46
+
47
+ nuxt.hook('autoImports:sources', (sources) => {
48
+ if (sources.find(i => i.from === '@vueuse/core' || i.from === '@vueuse/nuxt'))
49
+ return
50
+ const indexes = JSON.parse(fs.readFileSync(resolve(__dirname, './indexes.json'), 'utf-8'))
51
+ sources.push({
52
+ from: '@vueuse/core',
53
+ names: indexes
54
+ .functions
55
+ .filter(i => (i.package === 'core' || i.package === 'shared') && !i.internal)
56
+ .map(i => i.name)
57
+ .filter(i => i.length >= 4 && !disabled.includes(i)),
58
+ })
59
+ sources.push({
60
+ from: '@vueuse/nuxt',
61
+ names: indexes
62
+ .functions
63
+ .filter(i => i.package === 'nuxt' && !i.internal)
64
+ .map(i => i.name),
65
+ })
66
+ })
67
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@vueuse/nuxt",
3
+ "version": "7.0.0-alpha.0",
4
+ "description": "VueUse Nuxt Module",
5
+ "keywords": [
6
+ "vue",
7
+ "vueuse",
8
+ "nuxt",
9
+ "nuxt3",
10
+ "nuxt-module"
11
+ ],
12
+ "license": "MIT",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/vueuse/vueuse.git",
16
+ "directory": "packages/nuxt"
17
+ },
18
+ "funding": "https://github.com/sponsors/antfu",
19
+ "author": "Anthony Fu <https://github.com/antfu>",
20
+ "exports": {
21
+ ".": {
22
+ "import": "./index.mjs",
23
+ "require": "./index.cjs",
24
+ "types": "./index.d.ts"
25
+ },
26
+ "./*": "./*",
27
+ "./module": {
28
+ "import": "./module.mjs",
29
+ "require": "./module.cjs",
30
+ "types": "./module.d.ts"
31
+ }
32
+ },
33
+ "main": "./index.cjs",
34
+ "types": "./index.d.ts",
35
+ "module": "./index.mjs",
36
+ "sideEffects": false,
37
+ "bugs": {
38
+ "url": "https://github.com/vueuse/vueuse/issues"
39
+ },
40
+ "homepage": "https://github.com/vueuse/vueuse/tree/main/packages/nuxt#readme",
41
+ "dependencies": {
42
+ "@vueuse/core": "7.1.0",
43
+ "vue-demi": "*"
44
+ },
45
+ "devDependencies": {
46
+ "nuxt3": "latest"
47
+ }
48
+ }