|
1 | 1 | import { computed, reactive, watch } from 'vue' |
2 | 2 |
|
3 | 3 | import type { ColorModeInstance } from './types' |
4 | | -import { defineNuxtPlugin, isVue2, isVue3, useRouter, useHead, useState } from '#imports' |
| 4 | +import { defineNuxtPlugin, useRouter, useHead, useState } from '#imports' |
5 | 5 | import { globalName, storageKey, dataValue, disableTransition, storage } from '#color-mode-options' |
6 | 6 |
|
7 | 7 | type Helper = { |
@@ -35,28 +35,13 @@ export default defineNuxtPlugin((nuxtApp) => { |
35 | 35 | })).value |
36 | 36 |
|
37 | 37 | if (dataValue) { |
38 | | - if (isVue3) { |
39 | | - useHead({ |
40 | | - htmlAttrs: { [`data-${dataValue}`]: computed(() => colorMode.value) }, |
41 | | - }) |
42 | | - } |
43 | | - else { |
44 | | - const app = nuxtApp.nuxt2Context.app |
45 | | - const originalHead = app.head |
46 | | - app.head = function () { |
47 | | - const head = (typeof originalHead === 'function' ? originalHead.call(this) : originalHead) || {} |
48 | | - head.htmlAttrs = head.htmlAttrs || {} |
49 | | - head.htmlAttrs[`data-${dataValue}`] = colorMode.value |
50 | | - return head |
51 | | - } |
52 | | - } |
| 38 | + useHead({ |
| 39 | + htmlAttrs: { [`data-${dataValue}`]: computed(() => colorMode.value) }, |
| 40 | + }) |
53 | 41 | } |
54 | 42 |
|
55 | 43 | useRouter().afterEach((to) => { |
56 | | - const forcedColorMode = isVue2 |
57 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
58 | | - ? (to.matched[0]?.components.default as any)?.options.colorMode |
59 | | - : to.meta.colorMode |
| 44 | + const forcedColorMode = to.meta.colorMode |
60 | 45 |
|
61 | 46 | if (forcedColorMode && forcedColorMode !== 'system') { |
62 | 47 | colorMode.value = forcedColorMode |
|
0 commit comments