@kuankuan/assist-2026 0.1.6 → 0.1.8

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/init.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import "./motion";
2
+ import "./theme";
package/dist/init.js ADDED
@@ -0,0 +1,2 @@
1
+ import "./motion";
2
+ import "./theme";
@@ -0,0 +1,8 @@
1
+ export declare enum Motions {
2
+ Reduce = "reduce",
3
+ NoPreference = "no-preference",
4
+ Auto = "auto"
5
+ }
6
+ export declare const motionValueList: readonly [Motions.Auto, Motions.NoPreference, Motions.Reduce];
7
+ export declare const motionValue: import("vue").Ref<Motions, Motions>;
8
+ export declare const motion: import("vue").ComputedRef<Motions.Reduce | Motions.NoPreference>;
package/dist/motion.js ADDED
@@ -0,0 +1,26 @@
1
+ import storageRef from './ref/storageRef';
2
+ import mediaRef from './ref/mediaRef';
3
+ import { computed, watch } from 'vue';
4
+ export var Motions;
5
+ (function (Motions) {
6
+ Motions["Reduce"] = "reduce";
7
+ Motions["NoPreference"] = "no-preference";
8
+ Motions["Auto"] = "auto";
9
+ })(Motions || (Motions = {}));
10
+ export const motionValueList = [Motions.Auto, Motions.NoPreference, Motions.Reduce];
11
+ export const motionValue = storageRef('_k_motion', Motions.NoPreference, localStorage);
12
+ const matcherRef = mediaRef(window.matchMedia('(prefers-reduced-motion: reduce)'));
13
+ export const motion = computed(() => {
14
+ const systemMotion = matcherRef.value ? Motions.Reduce : Motions.NoPreference;
15
+ if (!motionValueList.includes(motionValue.value)) {
16
+ motionValue.value = Motions.NoPreference;
17
+ }
18
+ if (motionValue.value === Motions.Auto) {
19
+ return systemMotion;
20
+ }
21
+ return motionValue.value;
22
+ });
23
+ function updateDomMotion() {
24
+ document.documentElement.dataset.motion = motion.value;
25
+ }
26
+ watch(motion, updateDomMotion, { immediate: true });
@@ -0,0 +1 @@
1
+ export default function mediaRef(mediaQuery: MediaQueryList): import("vue").Ref<boolean, boolean>;
@@ -0,0 +1,8 @@
1
+ import { ref } from "vue";
2
+ export default function mediaRef(mediaQuery) {
3
+ const result = ref(mediaQuery.matches);
4
+ mediaQuery.addEventListener('change', (e) => {
5
+ result.value = e.matches;
6
+ });
7
+ return result;
8
+ }
@@ -1,2 +1,2 @@
1
1
  import { type Ref } from 'vue';
2
- export default function storageRef(key: string, defaultValue: string, storage?: Storage): Ref<string, string>;
2
+ export default function storageRef<T extends string = string>(key: string, defaultValue: string, storage?: Storage): Ref<T>;
package/dist/theme.d.ts CHANGED
@@ -1,3 +1,8 @@
1
- export declare const themeValue: import("vue").Ref<string, string>;
2
- export declare const themeValueList: string[];
3
- export declare const theme: import("vue").ComputedRef<string>;
1
+ export declare enum Theme {
2
+ Light = "light",
3
+ Dark = "dark",
4
+ Auto = "auto"
5
+ }
6
+ export declare const themeValueList: readonly [Theme.Auto, Theme.Light, Theme.Dark];
7
+ export declare const themeValue: import("vue").Ref<Theme, Theme>;
8
+ export declare const theme: import("vue").ComputedRef<Theme.Light | Theme.Dark>;
package/dist/theme.js CHANGED
@@ -1,11 +1,22 @@
1
1
  import storageRef from './ref/storageRef';
2
+ import mediaRef from './ref/mediaRef';
2
3
  import { computed, watch } from 'vue';
4
+ export var Theme;
5
+ (function (Theme) {
6
+ Theme["Light"] = "light";
7
+ Theme["Dark"] = "dark";
8
+ Theme["Auto"] = "auto";
9
+ })(Theme || (Theme = {}));
10
+ export const themeValueList = [Theme.Auto, Theme.Light, Theme.Dark];
3
11
  export const themeValue = storageRef('theme', 'auto', localStorage);
4
- export const themeValueList = ['auto', 'light', 'dark'];
5
- const matcher = window.matchMedia('(prefers-color-scheme: dark)');
12
+ const matcherRef = mediaRef(window.matchMedia('(prefers-color-scheme: dark)'));
6
13
  export const theme = computed(() => {
7
- if (themeValue.value === 'auto') {
8
- return matcher.matches ? 'dark' : 'light';
14
+ const systemTheme = matcherRef.value ? Theme.Dark : Theme.Light;
15
+ if (!themeValueList.includes(themeValue.value)) {
16
+ themeValue.value = Theme.Auto;
17
+ }
18
+ if (themeValue.value === Theme.Auto) {
19
+ return systemTheme;
9
20
  }
10
21
  return themeValue.value;
11
22
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kuankuan/assist-2026",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "A toolset from kuankuan",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/init.ts ADDED
@@ -0,0 +1,2 @@
1
+ import "./motion"
2
+ import "./theme"
package/src/motion.ts ADDED
@@ -0,0 +1,29 @@
1
+ import storageRef from './ref/storageRef';
2
+ import mediaRef from './ref/mediaRef';
3
+ import { computed, watch } from 'vue';
4
+
5
+ export enum Motions {
6
+ Reduce = 'reduce',
7
+ NoPreference = 'no-preference',
8
+ Auto = 'auto',
9
+ }
10
+
11
+ export const motionValueList = [Motions.Auto, Motions.NoPreference, Motions.Reduce] as const;
12
+
13
+ export const motionValue = storageRef<Motions>('_k_motion', Motions.NoPreference, localStorage);
14
+ const matcherRef = mediaRef(window.matchMedia('(prefers-reduced-motion: reduce)'));
15
+
16
+ export const motion = computed(() => {
17
+ const systemMotion = matcherRef.value ? Motions.Reduce : Motions.NoPreference;
18
+ if (!motionValueList.includes(motionValue.value)) {
19
+ motionValue.value = Motions.NoPreference;
20
+ }
21
+ if (motionValue.value === Motions.Auto) {
22
+ return systemMotion;
23
+ }
24
+ return motionValue.value;
25
+ });
26
+ function updateDomMotion() {
27
+ document.documentElement.dataset.motion = motion.value;
28
+ }
29
+ watch(motion, updateDomMotion, { immediate: true });
@@ -0,0 +1,9 @@
1
+ import { ref } from "vue";
2
+
3
+ export default function mediaRef(mediaQuery: MediaQueryList) {
4
+ const result = ref<boolean>(mediaQuery.matches);
5
+ mediaQuery.addEventListener('change', (e) => {
6
+ result.value = e.matches;
7
+ });
8
+ return result;
9
+ }
@@ -31,7 +31,7 @@ function defineRef(storage: Storage, key: string, refValue: Ref<string>) {
31
31
  return refValue;
32
32
  }
33
33
 
34
- export default function storageRef(
34
+ export default function storageRef<T extends string=string>(
35
35
  key: string,
36
36
  defaultValue: string,
37
37
  storage: Storage = localStorage
@@ -39,7 +39,7 @@ export default function storageRef(
39
39
  return (
40
40
  getDefined(storage, key) ??
41
41
  defineRef(storage, key, ref<string>(storage.getItem(key) ?? defaultValue))
42
- );
42
+ ) as Ref<T>;
43
43
  }
44
44
  window.addEventListener('storage', (e) => {
45
45
  if (e.key === null || e.newValue === null || e.storageArea === null) return;
package/src/theme.ts CHANGED
@@ -1,13 +1,25 @@
1
1
  import storageRef from './ref/storageRef';
2
+ import mediaRef from './ref/mediaRef';
2
3
  import { computed, watch } from 'vue';
3
4
 
4
- export const themeValue = storageRef('theme', 'auto', localStorage);
5
- export const themeValueList = ['auto', 'light', 'dark'];
6
- const matcher = window.matchMedia('(prefers-color-scheme: dark)');
5
+ export enum Theme {
6
+ Light = 'light',
7
+ Dark = 'dark',
8
+ Auto = 'auto',
9
+ }
10
+
11
+ export const themeValueList = [Theme.Auto, Theme.Light, Theme.Dark] as const;
12
+
13
+ export const themeValue = storageRef<Theme>('theme', 'auto', localStorage);
14
+ const matcherRef = mediaRef(window.matchMedia('(prefers-color-scheme: dark)'));
7
15
 
8
16
  export const theme = computed(() => {
9
- if (themeValue.value === 'auto') {
10
- return matcher.matches ? 'dark' : 'light';
17
+ const systemTheme = matcherRef.value ? Theme.Dark : Theme.Light;
18
+ if (!themeValueList.includes(themeValue.value)) {
19
+ themeValue.value = Theme.Auto;
20
+ }
21
+ if (themeValue.value === Theme.Auto) {
22
+ return systemTheme;
11
23
  }
12
24
  return themeValue.value;
13
25
  });
@@ -0,0 +1,20 @@
1
+ @mixin use($anythingElse: '') {
2
+ @include select('no-preference', $anythingElse) {
3
+ @content;
4
+ }
5
+ }
6
+
7
+ @mixin transition($transition...) {
8
+ @include use {
9
+ transition: $transition;
10
+ @content;
11
+ }
12
+ }
13
+ @function selecter($motion){
14
+ @return "[data-motion='#{$motion}']";
15
+ }
16
+ @mixin select($motion, $anythingElse: '') {
17
+ html#{selecter($motion)}#{$anythingElse} & {
18
+ @content;
19
+ }
20
+ }
package/styles/theme.scss CHANGED
@@ -14,7 +14,7 @@ $defaultTheme: (
14
14
  dark: (
15
15
  color: #eeeeee,
16
16
  background: #1e1e1e,
17
- active-color: #686dff,
17
+ active-color: #9fa3ff,
18
18
  em-bg-color: #131600,
19
19
  strong-color: #dddd00,
20
20
  name: 'dark',
@@ -22,15 +22,23 @@ $defaultTheme: (
22
22
  );
23
23
 
24
24
  $curTheme: 'light';
25
- @mixin use($themeConfig: $defaultTheme) {
25
+ @mixin use($anythingElse: '', $themeConfig: $defaultTheme) {
26
26
  @each $key, $value in $themeConfig {
27
27
  $curTheme: $key !global;
28
28
 
29
- html[data-theme='#{$key}'] & {
29
+ @include select($key, $anythingElse) {
30
30
  @content;
31
31
  }
32
32
  }
33
33
  }
34
+ @function selecter($theme){
35
+ @return "[data-theme='#{$theme}']";
36
+ }
37
+ @mixin select($theme, $anythingElse: '') {
38
+ html#{selecter($theme)}#{$anythingElse} & {
39
+ @content;
40
+ }
41
+ }
34
42
  @function get($paramName, $curTheme: $curTheme, $themeConfig: $defaultTheme) {
35
43
  @if map.has-key($map: map.get($themeConfig, $curTheme), $key: $paramName) == false {
36
44
  @error "Theme `#{$curTheme}` param `#{$paramName}` not found.";