@kuankuan/assist-2026 0.1.7 → 0.1.9
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 +2 -0
- package/dist/init.js +2 -0
- package/dist/motion.d.ts +8 -0
- package/dist/motion.js +26 -0
- package/dist/ref/mediaRef.d.ts +1 -0
- package/dist/ref/mediaRef.js +8 -0
- package/dist/ref/storageRef.d.ts +1 -1
- package/dist/theme.d.ts +8 -3
- package/dist/theme.js +15 -4
- package/package.json +1 -1
- package/src/init.ts +2 -0
- package/src/motion.ts +29 -0
- package/src/ref/mediaRef.ts +9 -0
- package/src/ref/storageRef.ts +2 -2
- package/src/theme.ts +17 -5
- package/styles/motion.scss +20 -0
- package/styles/theme.scss +10 -2
package/dist/init.d.ts
ADDED
package/dist/init.js
ADDED
package/dist/motion.d.ts
ADDED
|
@@ -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.Auto, 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.Auto;
|
|
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>;
|
package/dist/ref/storageRef.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type Ref } from 'vue';
|
|
2
|
-
export default function storageRef(key: string, defaultValue: string, storage?: Storage): Ref<
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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
package/src/init.ts
ADDED
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.Auto, 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.Auto;
|
|
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 });
|
package/src/ref/storageRef.ts
CHANGED
|
@@ -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
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
10
|
-
|
|
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
|
@@ -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
|
-
|
|
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.";
|