@vuecs/nuxt 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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2021-2026 Peter Placzek
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @vuecs/nuxt
2
+
3
+ [![npm version](https://badge.fury.io/js/@vuecs%2Fnuxt.svg)](https://badge.fury.io/js/@vuecs%2Fnuxt)
4
+ [![main](https://github.com/Tada5hi/vuecs/actions/workflows/main.yml/badge.svg)](https://github.com/Tada5hi/vuecs/actions/workflows/main.yml)
5
+
6
+ Theme-agnostic Nuxt 4 module for vuecs — auto-injects `@vuecs/design`
7
+ design tokens and ships SSR-safe color-mode + palette handling
8
+ (`useColorMode` and `useColorPalette` auto-imports + matching SSR
9
+ plugins). The runtime dispatches through whichever themes the consumer
10
+ installs, so the same module covers Tailwind, Bulma, and any
11
+ palette-aware community theme.
12
+
13
+ Full documentation:
14
+
15
+ - [Module reference](https://vuecs.dev/nuxt/)
16
+ - [`useColorMode`](https://vuecs.dev/nuxt/use-color-mode)
17
+ - [`useColorPalette`](https://vuecs.dev/nuxt/use-palette)
18
+
19
+ ```bash
20
+ npm install @vuecs/nuxt @vuecs/design @vuecs/theme-tailwind
21
+ ```
22
+
23
+ ```ts
24
+ // nuxt.config.ts
25
+ export default defineNuxtConfig({
26
+ modules: ['@vuecs/nuxt'],
27
+ vuecs: {
28
+ themes: ['@vuecs/theme-tailwind'],
29
+ colorMode: { value: 'system' },
30
+ colorPalette: { value: { primary: 'green' } },
31
+ },
32
+ });
33
+ ```
34
+
35
+ ## License
36
+
37
+ Made with 💚
38
+
39
+ Published under [Apache 2.0 License](./LICENSE).
@@ -0,0 +1,169 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { SemanticScaleName, ColorPaletteName } from '@vuecs/design';
3
+
4
+ /**
5
+ * Subset of Nuxt `useCookie`'s options that we forward verbatim. Kept
6
+ * intentionally narrow — additional fields can be added on demand
7
+ * without breaking consumers.
8
+ */
9
+ interface CookieOptions {
10
+ /**
11
+ * Cookie lifetime in seconds. Without this, Nuxt produces a
12
+ * session cookie that expires when the browser closes — so
13
+ * returning visitors lose their persisted choice.
14
+ *
15
+ * @default 60 * 60 * 24 * 365 // 1 year
16
+ */
17
+ maxAge?: number;
18
+ /**
19
+ * SameSite attribute. Use `'none'` (with `secure: true`) for
20
+ * cross-subdomain SSO scenarios.
21
+ *
22
+ * @default 'lax'
23
+ */
24
+ sameSite?: 'lax' | 'strict' | 'none' | boolean;
25
+ /**
26
+ * Cookie Domain attribute. Useful for sharing across subdomains
27
+ * (e.g. `'.example.com'`). Omitted by default — browser scopes
28
+ * the cookie to the exact host.
29
+ */
30
+ domain?: string;
31
+ /**
32
+ * Add the `Secure` flag. Required when `sameSite: 'none'`. In
33
+ * production, you almost always want this.
34
+ *
35
+ * @default false
36
+ */
37
+ secure?: boolean;
38
+ /**
39
+ * Cookie Path attribute.
40
+ *
41
+ * @default '/'
42
+ */
43
+ path?: string;
44
+ }
45
+ interface ColorModeOptions {
46
+ /**
47
+ * Name of the cookie used to persist the selected mode. The cookie
48
+ * is the SSR transport — read on the server so first paint matches
49
+ * the user's preference, avoiding FOUC.
50
+ *
51
+ * @default 'vc-color-mode'
52
+ */
53
+ cookieName?: string;
54
+ /**
55
+ * Initial mode when no cookie is present.
56
+ * `'system'` defers to the client's `prefers-color-scheme` on first
57
+ * paint; the server renders without a class in that case (accept a
58
+ * possible one-frame flash on cold loads) unless a cookie is set.
59
+ *
60
+ * Mirrors `colorPalette.value` — both options describe "initial
61
+ * value when no persisted state exists" with the same key name.
62
+ *
63
+ * @default 'system'
64
+ */
65
+ value?: 'light' | 'dark' | 'system';
66
+ }
67
+ interface ColorPaletteOptions {
68
+ /**
69
+ * Name of the cookie used to persist the selected palette. The
70
+ * cookie is the SSR transport — read on the server so first paint
71
+ * matches the user's persisted palette.
72
+ *
73
+ * @default 'vc-color-palette'
74
+ */
75
+ cookieName?: string;
76
+ /**
77
+ * Initial palette applied before first paint. Each semantic scale
78
+ * (`primary`, `neutral`, `success`, `warning`, `error`, `info`)
79
+ * may be assigned a catalog palette name. Pass `{}` to keep the
80
+ * theme's default mapping.
81
+ *
82
+ * Typing widens automatically when community themes augment
83
+ * `ExtraColorPaletteNames` in `@vuecs/design`.
84
+ *
85
+ * @example { primary: 'green', neutral: 'zinc' }
86
+ * @default {}
87
+ */
88
+ value?: Partial<Record<SemanticScaleName, ColorPaletteName>>;
89
+ }
90
+ interface ModuleOptions {
91
+ /**
92
+ * Auto-import `@vuecs/design/index.css` as part of the Nuxt
93
+ * CSS stack. Disable if you want to import it manually (e.g. to
94
+ * control load order relative to your own base CSS).
95
+ *
96
+ * @default true
97
+ */
98
+ injectTokens?: boolean;
99
+ /**
100
+ * Theme packages to install. Each entry is a module name; the
101
+ * module is imported at runtime via a generated plugin that calls
102
+ * its default factory and installs the result via
103
+ * `app.use(vuecs, { themes: [...] })`. The generated plugin runs
104
+ * before this module's SSR plugins so the ThemeManager is
105
+ * registered by the time `enforce: 'post'` plugins look it up.
106
+ *
107
+ * Themes are imported as default-export no-arg factories. Themes
108
+ * that need options (e.g. `acmeTheme({ variant: 'dark' })`) skip
109
+ * this option and install themselves via a user-authored plugin
110
+ * file under `plugins/`.
111
+ *
112
+ * @example ['@vuecs/theme-tailwind']
113
+ * @default undefined // no auto-install; consumer's user-plugin owns it
114
+ */
115
+ themes?: string[];
116
+ /**
117
+ * Dark-mode integration. When enabled (default), this module
118
+ * registers an SSR-safe `useColorMode()` composable built on
119
+ * `@vueuse/core`'s `useDark`, with cookie-based persistence so
120
+ * the server can render the correct `html.dark` / `html.light`
121
+ * class on first paint.
122
+ *
123
+ * Set to `false` to skip — useful if you wire color mode yourself
124
+ * (e.g. via `@nuxtjs/color-mode`). Pass an object to tweak the
125
+ * cookie name or initial value.
126
+ *
127
+ * @default true
128
+ */
129
+ colorMode?: boolean | ColorModeOptions;
130
+ /**
131
+ * Palette switching. When enabled (default), this module registers
132
+ * an SSR-safe `useColorPalette()` composable backed by a Nuxt
133
+ * cookie, plus a server plugin that emits the
134
+ * `<style id="vc-color-palette">` block before first paint.
135
+ *
136
+ * The runtime dispatches through every installed theme's
137
+ * `palette.handle` hook (plan 021 slice 6b), so the same composable
138
+ * drives Tailwind, Bulma, and any future palette-aware theme
139
+ * without per-theme Nuxt modules.
140
+ *
141
+ * Set to `false` to skip entirely. Pass an object to set the
142
+ * initial palette or override the cookie name.
143
+ *
144
+ * @default true
145
+ */
146
+ colorPalette?: boolean | ColorPaletteOptions;
147
+ /**
148
+ * Cookie attributes applied to the **color-mode** cookie. Useful
149
+ * when deploying across subdomains (`domain: '.example.com'`),
150
+ * behind a same-origin SSO flow (`sameSite: 'none', secure: true`),
151
+ * or with custom retention requirements.
152
+ *
153
+ * Power users can wire their own composables via `bindColorMode()`
154
+ * from `@vuecs/design` if they need divergent semantics.
155
+ */
156
+ cookie?: CookieOptions;
157
+ /**
158
+ * Cookie attributes applied to the **palette** cookie. When unset,
159
+ * the palette cookie inherits attributes from `cookie` (the
160
+ * color-mode cookie config) — most apps want the same retention /
161
+ * domain / SameSite for both UI-state cookies. Set this slot
162
+ * explicitly to diverge (e.g. shorter palette retention).
163
+ */
164
+ paletteCookie?: CookieOptions;
165
+ }
166
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
167
+
168
+ export { _default as default };
169
+ export type { ColorModeOptions, ColorPaletteOptions, CookieOptions, ModuleOptions };
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@vuecs/nuxt",
3
+ "configKey": "vuecs",
4
+ "version": "1.0.0",
5
+ "builder": {
6
+ "@nuxt/module-builder": "1.0.2",
7
+ "unbuild": "3.6.1"
8
+ }
9
+ }
@@ -0,0 +1,107 @@
1
+ import { defineNuxtModule, createResolver, addTemplate, addPlugin, addImports } from '@nuxt/kit';
2
+
3
+ const module$1 = defineNuxtModule({
4
+ meta: {
5
+ name: "@vuecs/nuxt",
6
+ configKey: "vuecs"
7
+ },
8
+ defaults: {
9
+ injectTokens: true,
10
+ colorMode: true,
11
+ colorPalette: true
12
+ },
13
+ setup(options, nuxt) {
14
+ const resolver = createResolver(import.meta.url);
15
+ if (options.injectTokens) {
16
+ nuxt.options.css = nuxt.options.css || [];
17
+ if (!nuxt.options.css.includes("@vuecs/design/index.css")) {
18
+ nuxt.options.css.unshift("@vuecs/design/index.css");
19
+ }
20
+ }
21
+ const colorModeEnabled = options.colorMode !== false;
22
+ const colorModeOptions = {
23
+ cookieName: "vc-color-mode",
24
+ value: "system",
25
+ ...typeof options.colorMode === "object" && options.colorMode !== null ? options.colorMode : {}
26
+ };
27
+ const colorPaletteEnabled = options.colorPalette !== false;
28
+ const colorPaletteOptions = {
29
+ cookieName: "vc-color-palette",
30
+ value: {},
31
+ ...typeof options.colorPalette === "object" && options.colorPalette !== null ? options.colorPalette : {}
32
+ };
33
+ const cookieOptions = {
34
+ maxAge: 60 * 60 * 24 * 365,
35
+ sameSite: "lax",
36
+ path: "/",
37
+ ...options.cookie || {}
38
+ };
39
+ const paletteCookieOptions = {
40
+ ...cookieOptions,
41
+ ...options.paletteCookie || {}
42
+ };
43
+ const existingPublic = nuxt.options.runtimeConfig.public || {};
44
+ const existingVuecs = existingPublic.vuecs || {};
45
+ nuxt.options.runtimeConfig.public = {
46
+ ...existingPublic,
47
+ vuecs: {
48
+ ...existingVuecs,
49
+ colorMode: {
50
+ enabled: colorModeEnabled,
51
+ cookieName: colorModeOptions.cookieName,
52
+ value: colorModeOptions.value
53
+ },
54
+ colorPalette: {
55
+ enabled: colorPaletteEnabled,
56
+ cookieName: colorPaletteOptions.cookieName,
57
+ value: colorPaletteOptions.value
58
+ },
59
+ cookie: cookieOptions,
60
+ paletteCookie: paletteCookieOptions
61
+ }
62
+ };
63
+ const themes = (options.themes || []).filter((name) => typeof name === "string" && name.length > 0);
64
+ if (themes.length > 0) {
65
+ const importLines = themes.map((name, idx) => `import t${idx} from ${JSON.stringify(name)};`).join("\n");
66
+ const installArgs = themes.map((_, idx) => `t${idx}()`).join(", ");
67
+ const template = addTemplate({
68
+ filename: "vuecs-themes.plugin.mjs",
69
+ getContents: () => `${importLines}
70
+ import vuecs from '@vuecs/core';
71
+ import { defineNuxtPlugin } from '#imports';
72
+
73
+ export default defineNuxtPlugin({
74
+ name: 'vuecs-themes',
75
+ setup(nuxtApp) {
76
+ nuxtApp.vueApp.use(vuecs, { themes: [${installArgs}] });
77
+ },
78
+ });
79
+ `,
80
+ write: true
81
+ });
82
+ addPlugin({ src: template.dst });
83
+ }
84
+ if (colorModeEnabled) {
85
+ addPlugin({
86
+ src: resolver.resolve("./runtime/plugins/colorMode.server"),
87
+ mode: "server"
88
+ });
89
+ addImports({
90
+ name: "useColorMode",
91
+ from: resolver.resolve("./runtime/composables/useColorMode")
92
+ });
93
+ }
94
+ if (colorPaletteEnabled) {
95
+ addPlugin({
96
+ src: resolver.resolve("./runtime/plugins/colorPalette.server"),
97
+ mode: "server"
98
+ });
99
+ addImports({
100
+ name: "useColorPalette",
101
+ from: resolver.resolve("./runtime/composables/useColorPalette")
102
+ });
103
+ }
104
+ }
105
+ });
106
+
107
+ export { module$1 as default };
File without changes
@@ -0,0 +1,18 @@
1
+ import { bindColorMode } from "@vuecs/design";
2
+ import { useCookie, useRuntimeConfig } from "#imports";
3
+ export function useColorMode() {
4
+ const config = useRuntimeConfig();
5
+ const colorModeConfig = config.public.vuecs?.colorMode;
6
+ const cookieName = colorModeConfig?.cookieName || "vc-color-mode";
7
+ const defaultValue = colorModeConfig?.value || "system";
8
+ const cookieOptions = config.public.vuecs?.cookie || {};
9
+ const cookie = useCookie(cookieName, {
10
+ default: () => defaultValue,
11
+ ...cookieOptions,
12
+ // `watch: true` must come last — bindColorMode depends on the
13
+ // ref being reactive, and we don't want consumer-supplied
14
+ // cookieOptions to silently disable that.
15
+ watch: true
16
+ });
17
+ return bindColorMode(cookie);
18
+ }
File without changes
@@ -0,0 +1,24 @@
1
+ import { useConfig } from "@vuecs/core";
2
+ import { useColorPaletteUnshared } from "@vuecs/design";
3
+ import "../../config";
4
+ import { useCookie, useRuntimeConfig } from "#imports";
5
+ export function useColorPalette() {
6
+ const config = useRuntimeConfig();
7
+ const colorPaletteConfig = config.public.vuecs?.colorPalette;
8
+ const cookieName = colorPaletteConfig?.cookieName || "vc-color-palette";
9
+ const initial = colorPaletteConfig?.value || {};
10
+ const cookieOptions = config.public.vuecs?.paletteCookie || config.public.vuecs?.cookie || {};
11
+ const cookie = useCookie(cookieName, {
12
+ default: () => ({ ...initial }),
13
+ ...cookieOptions,
14
+ // `watch: true` must come last — useColorPaletteUnshared depends
15
+ // on the ref being reactive, and we don't want consumer-supplied
16
+ // cookieOptions to silently disable that.
17
+ watch: true
18
+ });
19
+ const nonce = useConfig("nonce");
20
+ return useColorPaletteUnshared({
21
+ source: cookie,
22
+ nonce: () => nonce.value
23
+ });
24
+ }
File without changes
@@ -0,0 +1,32 @@
1
+ import { THEME_RUNTIME_MANAGER_SYMBOL, captureColorModeAttrs } from "@vuecs/design";
2
+ import { inject } from "vue";
3
+ import { defineNuxtPlugin, useCookie, useHead, useRuntimeConfig } from "#imports";
4
+ export default defineNuxtPlugin({
5
+ name: "vuecs-color-mode-server",
6
+ enforce: "post",
7
+ setup(nuxtApp) {
8
+ const config = useRuntimeConfig();
9
+ const colorModeConfig = config.public.vuecs?.colorMode;
10
+ if (!colorModeConfig?.enabled) return;
11
+ const cookieName = colorModeConfig.cookieName || "vc-color-mode";
12
+ const cookie = useCookie(
13
+ cookieName,
14
+ { default: () => void 0 }
15
+ );
16
+ const stored = cookie.value;
17
+ let effective;
18
+ if (stored === "light" || stored === "dark") {
19
+ effective = stored;
20
+ } else if (colorModeConfig.value === "light" || colorModeConfig.value === "dark") {
21
+ effective = colorModeConfig.value;
22
+ }
23
+ if (!effective) return;
24
+ const htmlAttrs = { class: effective };
25
+ const manager = nuxtApp.vueApp.runWithContext(() => inject(THEME_RUNTIME_MANAGER_SYMBOL, void 0));
26
+ if (manager) {
27
+ const captured = captureColorModeAttrs(manager.themes, effective);
28
+ Object.assign(htmlAttrs, captured);
29
+ }
30
+ useHead({ htmlAttrs });
31
+ }
32
+ });
File without changes
@@ -0,0 +1,56 @@
1
+ import { isObject, useConfig } from "@vuecs/core";
2
+ import {
3
+ COLOR_PALETTE_STYLE_ELEMENT_ID,
4
+ THEME_RUNTIME_MANAGER_SYMBOL,
5
+ renderColorPaletteFromThemes
6
+ } from "@vuecs/design";
7
+ import { inject } from "vue";
8
+ import "../../config";
9
+ import { defineNuxtPlugin, useCookie, useHead, useRuntimeConfig } from "#imports";
10
+ export default defineNuxtPlugin({
11
+ name: "vuecs-color-palette-server",
12
+ enforce: "post",
13
+ setup(nuxtApp) {
14
+ const config = useRuntimeConfig();
15
+ const colorPaletteConfig = config.public.vuecs?.colorPalette;
16
+ if (!colorPaletteConfig?.enabled) return;
17
+ const cookieName = colorPaletteConfig.cookieName || "vc-color-palette";
18
+ const fallback = colorPaletteConfig.value || {};
19
+ const cookie = useCookie(
20
+ cookieName,
21
+ { default: () => void 0 }
22
+ );
23
+ const rawPalette = cookie.value || fallback;
24
+ const palette = /* @__PURE__ */ Object.create(null);
25
+ if (isObject(rawPalette)) {
26
+ for (const key of Object.keys(rawPalette)) {
27
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
28
+ continue;
29
+ }
30
+ const value = rawPalette[key];
31
+ if (typeof value === "string") {
32
+ palette[key] = value;
33
+ }
34
+ }
35
+ }
36
+ if (Object.keys(palette).length === 0) {
37
+ return;
38
+ }
39
+ const manager = nuxtApp.vueApp.runWithContext(() => inject(THEME_RUNTIME_MANAGER_SYMBOL, void 0));
40
+ if (!manager) return;
41
+ const nonce = nuxtApp.vueApp.runWithContext(() => useConfig("nonce").value);
42
+ let css = renderColorPaletteFromThemes(manager.themes, palette);
43
+ if (!css) return;
44
+ if (/<\/style/i.test(css)) {
45
+ css = "";
46
+ }
47
+ if (!css) return;
48
+ useHead({
49
+ style: [{
50
+ id: COLOR_PALETTE_STYLE_ELEMENT_ID,
51
+ children: css,
52
+ ...nonce ? { nonce } : {}
53
+ }]
54
+ });
55
+ }
56
+ });
@@ -0,0 +1,3 @@
1
+ export { default } from './module.mjs'
2
+
3
+ export { type ColorModeOptions, type ColorPaletteOptions, type CookieOptions, type ModuleOptions } from './module.mjs'
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@vuecs/nuxt",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "description": "Nuxt module for vuecs — auto-imports @vuecs/design tokens and ships SSR-safe color-mode + palette plugins. Theme-agnostic; dispatches palette/colorMode runtime hooks through whichever themes the consumer installs.",
6
+ "exports": {
7
+ "./package.json": "./package.json",
8
+ ".": {
9
+ "types": "./dist/module.d.mts",
10
+ "import": "./dist/module.mjs"
11
+ }
12
+ },
13
+ "main": "./dist/module.mjs",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "keywords": [
18
+ "vuecs",
19
+ "nuxt",
20
+ "nuxt-module",
21
+ "design-system",
22
+ "palette",
23
+ "dark-mode"
24
+ ],
25
+ "author": {
26
+ "name": "Peter Placzek",
27
+ "email": "contact@tada5hi.net",
28
+ "url": "https://tada5hi.net"
29
+ },
30
+ "license": "Apache-2.0",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/tada5hi/vuecs.git",
34
+ "directory": "packages/nuxt"
35
+ },
36
+ "scripts": {
37
+ "build": "rimraf dist && nuxt-module-build build --fail-on-warn=false",
38
+ "prepack": "npm run build"
39
+ },
40
+ "dependencies": {
41
+ "@nuxt/kit": "^4.4.5",
42
+ "@vueuse/core": "^14.3.0",
43
+ "@vuecs/core": "^3.0.0",
44
+ "@vuecs/design": "^1.0.0"
45
+ },
46
+ "devDependencies": {
47
+ "@nuxt/module-builder": "^1.0.1",
48
+ "@nuxt/schema": "^4.4.5",
49
+ "nuxt": "^4.4.5",
50
+ "vue": "^3.5.34"
51
+ },
52
+ "peerDependencies": {
53
+ "vue": "^3.x"
54
+ },
55
+ "engines": {
56
+ "node": ">=22.0.0"
57
+ },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ }
61
+ }