@scalar/nuxt 0.3.34 → 0.4.2

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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scalar/nuxt",
3
3
  "configKey": "scalar",
4
- "version": "0.3.34",
4
+ "version": "0.4.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.1",
7
7
  "unbuild": "unknown"
@@ -1,15 +1,22 @@
1
1
  <script lang="ts" setup>
2
2
  import { ModernLayout, parse } from '@scalar/api-reference'
3
3
  import type { ApiReferenceConfiguration } from '@scalar/types/api-reference'
4
+ import { useColorMode } from '@scalar/use-hooks/useColorMode'
4
5
  import { useFetch, useHead, useRequestURL, useSeoMeta } from '#imports'
5
6
  import type { Configuration } from '~/src/types'
6
- import { reactive, ref, toRaw } from 'vue'
7
+ import { onMounted, reactive, ref, toRaw, watch } from 'vue'
7
8
 
8
9
  const props = defineProps<{
9
10
  configuration: Configuration
10
11
  }>()
11
12
 
12
13
  const isDark = ref(props.configuration.darkMode)
14
+ const forcedMode = props.configuration.forceDarkModeState
15
+
16
+ const { colorMode, toggleColorMode } = useColorMode({
17
+ initialColorMode: props.configuration.darkMode ? 'dark' : 'light',
18
+ overrideColorMode: props.configuration.forceDarkModeState,
19
+ })
13
20
 
14
21
  // @ts-expect-error support the old syntax for a bit
15
22
  const content = props.configuration.spec?.content ?? props.configuration.content
@@ -41,9 +48,34 @@ if (props.configuration?.metaData) {
41
48
  }
42
49
 
43
50
  useHead({
44
- bodyAttrs: {
45
- class: () => (isDark.value ? 'dark-mode' : 'light-mode'),
46
- },
51
+ script: [
52
+ {
53
+ // Inject dark / light detection that runs before loading Nuxt to avoid flicker
54
+ // This is a bit of a hack inspired by @nuxtjs/color-mode, but it works
55
+ id: 'scalar-color-mode-script',
56
+ tagPosition: 'bodyClose',
57
+ innerHTML: `((isDark, forced) => {
58
+ try {
59
+ const stored = window.localStorage.getItem('colorMode');
60
+ const useDark = forced === 'dark' || !forced && (stored === 'dark' || !stored && isDark);
61
+ window.document.body.classList.add(useDark ? 'dark-mode' : 'light-mode');
62
+ } catch {}
63
+ })(${isDark.value}, ${JSON.stringify(forcedMode)});`
64
+ .replace(/[\n\r]/g, '')
65
+ .replace(/ +/g, ' '),
66
+ },
67
+ ],
68
+ })
69
+
70
+ watch(colorMode, () => {
71
+ isDark.value = colorMode.value === 'dark'
72
+ })
73
+
74
+ onMounted(() => {
75
+ // Adjust the color mode toggle switch
76
+ isDark.value = window.document.body.classList.contains('dark-mode')
77
+ // Remove scalar-color-mode-script
78
+ window.document.getElementById('scalar-color-mode-script')?.remove()
47
79
  })
48
80
 
49
81
  // Add baseServerURL and _integration
@@ -62,7 +94,7 @@ const config: Partial<ApiReferenceConfiguration> = {
62
94
  :isDark="!!isDark"
63
95
  :parsedSpec="parsedSpec"
64
96
  :rawSpec="rawSpec"
65
- @toggleDarkMode="isDark = !isDark" />
97
+ @toggleDarkMode="() => toggleColorMode()" />
66
98
  </template>
67
99
 
68
100
  <style>
package/package.json CHANGED
@@ -20,9 +20,9 @@
20
20
  "testing",
21
21
  "vue"
22
22
  ],
23
- "version": "0.3.34",
23
+ "version": "0.4.2",
24
24
  "engines": {
25
- "node": ">=18"
25
+ "node": ">=20"
26
26
  },
27
27
  "type": "module",
28
28
  "main": "./dist/module.cjs",
@@ -39,9 +39,10 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "@nuxt/kit": "^3.12.3",
42
- "@scalar/api-client": "2.3.34",
43
- "@scalar/api-reference": "1.28.34",
44
- "@scalar/types": "0.1.16"
42
+ "@scalar/api-client": "2.4.2",
43
+ "@scalar/api-reference": "1.29.2",
44
+ "@scalar/use-hooks": "0.2.1",
45
+ "@scalar/types": "0.2.1"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@nuxt/devtools": "^1.3.9",
@@ -51,11 +52,12 @@
51
52
  "@nuxt/test-utils": "^3.13.1",
52
53
  "@types/node": "^20.17.10",
53
54
  "changelogen": "^0.5.5",
55
+ "cross-env": "^7.0.3",
54
56
  "nuxt": "^3.12.4",
55
57
  "vitest": "^1.6.0"
56
58
  },
57
59
  "scripts": {
58
- "build": "NUXT_TELEMETRY_DISABLED=false pnpm dev:prepare && nuxt-module-build build",
60
+ "build": "cross-env NUXT_TELEMETRY_DISABLED=false pnpm dev:prepare && nuxt-module-build build",
59
61
  "dev": "pnpm dev:prepare && nuxi dev playground",
60
62
  "dev:build": "nuxi build playground",
61
63
  "dev:prepare": "nuxi prepare && nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",