@scalar/use-hooks 0.4.9 → 0.4.11

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @scalar/use-hooks
2
2
 
3
+ ## 0.4.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [#10058](https://github.com/scalar/scalar/pull/10058): feat(helpers): add applyColorMode and the DarkLightMode type, and use them from useColorMode
8
+
9
+ ## 0.4.10
10
+
11
+ ### Patch Changes
12
+
13
+ - [#9941](https://github.com/scalar/scalar/pull/9941): Republish every package through npm trusted publishing. No functional changes.
14
+
3
15
  ## 0.4.9
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -8,7 +8,7 @@ Scalar is an open-source API platform for teams who want beautiful developer int
8
8
 
9
9
  - **[API References](https://scalar.com/products/api-references/getting-started)** — Interactive API documentation from OpenAPI and AsyncAPI specs.
10
10
  - **[Developer Docs](https://scalar.com/products/docs/getting-started)** — Write in Markdown/MDX, generate API references, sync with two-way Git.
11
- - **[SDK Generator](https://scalar.com/products/sdks/getting-started)** — Type-safe SDKs and CLIs in TypeScript, Python, Go, PHP, Java, and Ruby.
11
+ - **[SDK Generator](https://scalar.com/products/sdk-generator/getting-started)** — Type-safe SDKs and CLIs in TypeScript, Python, Go, PHP, Java, and Ruby.
12
12
  - **[API Client](https://scalar.com/products/api-client/getting-started)** — Open-source, offline-first Postman alternative built on OpenAPI.
13
13
 
14
14
  20M+ monthly npm installs · 15,500+ GitHub stars · MIT licensed · [scalar.com](https://scalar.com)
@@ -1,2 +1,3 @@
1
+ export type { ColorMode, DarkLightMode } from './useColorMode.js';
1
2
  export { useColorMode } from './useColorMode.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useColorMode/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useColorMode/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA"}
@@ -1,7 +1,7 @@
1
+ import { type DarkLightMode } from '@scalar/helpers/theme/color-mode';
1
2
  /** Possible color modes */
2
- type ColorMode = 'light' | 'dark' | 'system';
3
- /** Specific dark/light mode */
4
- type DarkLightMode = 'light' | 'dark';
3
+ export type ColorMode = 'light' | 'dark' | 'system';
4
+ export type { DarkLightMode };
5
5
  /**
6
6
  * A composable hook that provides color mode (dark/light) functionality.
7
7
  */
@@ -24,5 +24,4 @@ export declare function useColorMode(opts?: {
24
24
  /** Gets the system mode preference. */
25
25
  getSystemModePreference: () => DarkLightMode;
26
26
  };
27
- export {};
28
27
  //# sourceMappingURL=useColorMode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useColorMode.d.ts","sourceRoot":"","sources":["../../src/useColorMode/useColorMode.ts"],"names":[],"mappings":"AAmBA,2BAA2B;AAC3B,KAAK,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAA;AAE5C,+BAA+B;AAC/B,KAAK,aAAa,GAAG,OAAO,GAAG,MAAM,CAAA;AAErC;;GAEG;AACH,wBAAgB,YAAY,CAC1B,IAAI,GAAE;IACJ,oCAAoC;IACpC,gBAAgB,CAAC,EAAE,SAAS,CAAA;IAC5B,8BAA8B;IAC9B,iBAAiB,CAAC,EAAE,SAAS,CAAA;CACzB;IAsGJ,yCAAyC;;IAKzC,+CAA+C;;IAE/C,yDAAyD;;IAEzD,qDAAqD;;IAErD,kDAAkD;0BAhGvB,SAAS;IAkGpC,uCAAuC;mCAzFL,aAAa;EA4FlD"}
1
+ {"version":3,"file":"useColorMode.d.ts","sourceRoot":"","sources":["../../src/useColorMode/useColorMode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAsC,MAAM,kCAAkC,CAAA;AAoBzG,2BAA2B;AAC3B,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAA;AAEnD,YAAY,EAAE,aAAa,EAAE,CAAA;AAE7B;;GAEG;AACH,wBAAgB,YAAY,CAC1B,IAAI,GAAE;IACJ,oCAAoC;IACpC,gBAAgB,CAAC,EAAE,SAAS,CAAA;IAC5B,8BAA8B;IAC9B,iBAAiB,CAAC,EAAE,SAAS,CAAA;CACzB;IA0FJ,yCAAyC;;IAKzC,+CAA+C;;IAE/C,yDAAyD;;IAEzD,qDAAqD;;IAErD,kDAAkD;0BApFvB,SAAS;IAsFpC,uCAAuC;mCA7EL,aAAa;EAgFlD"}
@@ -1,3 +1,4 @@
1
+ import { applyColorMode, getSystemColorMode } from '@scalar/helpers/theme/color-mode';
1
2
  import { literal, union, validate } from '@scalar/validation';
2
3
  import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
3
4
  const colorMode = ref('dark');
@@ -38,13 +39,7 @@ export function useColorMode(opts = {}) {
38
39
  }
39
40
  /** Gets the system mode preference. */
40
41
  function getSystemModePreference() {
41
- if (typeof window === 'undefined') {
42
- return 'light';
43
- }
44
- if (typeof window?.matchMedia !== 'function') {
45
- return 'dark';
46
- }
47
- return window?.matchMedia('(prefers-color-scheme: dark)')?.matches ? 'dark' : 'light';
42
+ return getSystemColorMode();
48
43
  }
49
44
  /** Writable computed ref for dark/light mode with system preference applied */
50
45
  const darkLightMode = computed({
@@ -57,21 +52,15 @@ export function useColorMode(opts = {}) {
57
52
  set: (value) => setColorMode(value ? 'dark' : 'light'),
58
53
  });
59
54
  /** Applies the appropriate color mode class to the body. */
60
- function applyColorMode() {
55
+ function applyBodyColorMode() {
61
56
  if (typeof document === 'undefined' || typeof window === 'undefined') {
62
57
  return;
63
58
  }
64
59
  // Read from the deferred `systemPreference` ref (not `getSystemModePreference()` directly) so
65
60
  // the body class agrees with `darkLightMode`/the toggle before `onMounted` resolves the real value.
66
61
  const classMode = overrideColorMode ?? (colorMode.value === 'system' ? systemPreference.value : colorMode.value);
67
- if (classMode === 'dark') {
68
- document.body.classList.add('dark-mode');
69
- document.body.classList.remove('light-mode');
70
- }
71
- else {
72
- document.body.classList.add('light-mode');
73
- document.body.classList.remove('dark-mode');
74
- }
62
+ // An `overrideColorMode` of `system` reaches here unresolved, and has always rendered as light.
63
+ applyColorMode(classMode === 'dark' ? 'dark' : 'light');
75
64
  }
76
65
  // Priority: overrideColorMode -> localStorage -> initialColorMode
77
66
  // Without `window` (SSR/SSG), there is no storage — treat preference as `system` so we do not
@@ -81,7 +70,7 @@ export function useColorMode(opts = {}) {
81
70
  colorMode.value = overrideColorMode ?? savedColorMode ?? initialColorMode;
82
71
  // Watch for color mode or system preference changes and update the body class. Watching
83
72
  // `systemPreference` means resolving it in `onMounted` (or an OS theme change) re-applies the class.
84
- watch([colorMode, systemPreference], applyColorMode, { immediate: true });
73
+ watch([colorMode, systemPreference], applyBodyColorMode, { immediate: true });
85
74
  const handleChange = () => {
86
75
  systemPreference.value = getSystemModePreference();
87
76
  };
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "url": "git+https://github.com/scalar/scalar.git",
11
11
  "directory": "packages/use-hooks"
12
12
  },
13
- "version": "0.4.9",
13
+ "version": "0.4.11",
14
14
  "engines": {
15
15
  "node": ">=22"
16
16
  },
@@ -45,12 +45,13 @@
45
45
  "@vueuse/core": "13.9.0",
46
46
  "cva": "1.0.0-beta.4",
47
47
  "tailwind-merge": "3.5.0",
48
- "vue": "^3.5.30",
49
- "@scalar/use-toasts": "0.10.4",
50
- "@scalar/validation": "0.6.2"
48
+ "vue": "^3.5.40",
49
+ "@scalar/helpers": "0.11.3",
50
+ "@scalar/validation": "0.6.3",
51
+ "@scalar/use-toasts": "0.10.5"
51
52
  },
52
53
  "devDependencies": {
53
- "@vue/test-utils": "2.4.6",
54
+ "@vue/test-utils": "2.4.11",
54
55
  "jsdom": "27.4.0"
55
56
  },
56
57
  "scripts": {