@antelopejs/dms-frontend 0.2.8 → 0.3.0
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/package.json
CHANGED
|
@@ -193,15 +193,8 @@ export interface DmsCookieOptions<T> {
|
|
|
193
193
|
sameSite?: "strict" | "lax" | "none";
|
|
194
194
|
secure?: boolean;
|
|
195
195
|
}
|
|
196
|
-
export type DmsColorModePreference = "system" | "light" | "dark";
|
|
197
196
|
type DmsLinkPrefetchMode = "mount" | "hover" | "click";
|
|
198
197
|
type DmsLinkPrefetch = boolean | DmsLinkPrefetchMode | DmsLinkPrefetchMode[];
|
|
199
|
-
export interface DmsColorMode {
|
|
200
|
-
preference: DmsColorModePreference;
|
|
201
|
-
value: "light" | "dark";
|
|
202
|
-
unknown: boolean;
|
|
203
|
-
forced: boolean;
|
|
204
|
-
}
|
|
205
198
|
export interface DmsAppContext {
|
|
206
199
|
provide<T>(key: string, value: T): void;
|
|
207
200
|
vueApp: App;
|
|
@@ -332,15 +325,6 @@ const runtimeConfig = ref<DmsRuntimeConfig>({
|
|
|
332
325
|
public: {},
|
|
333
326
|
} as DmsRuntimeConfig);
|
|
334
327
|
const appConfig = ref<Record<string, unknown>>({});
|
|
335
|
-
const COLOR_MODE_STORAGE_KEY = "dms-color-mode";
|
|
336
|
-
const COLOR_MODE_CLASSES = ["light", "dark"];
|
|
337
|
-
const colorMode = reactive<DmsColorMode>({
|
|
338
|
-
preference: "system",
|
|
339
|
-
value: "light",
|
|
340
|
-
unknown: false,
|
|
341
|
-
forced: false,
|
|
342
|
-
});
|
|
343
|
-
let isColorModeInitialized = false;
|
|
344
328
|
const DMS_RUNTIME_KEY: InjectionKey<DmsFrontendRuntime> = Symbol("dms-runtime");
|
|
345
329
|
type DmsRuntimeContext = DmsAppContext["runWithContext"];
|
|
346
330
|
const runtimeContexts = new WeakMap<DmsFrontendRuntime, DmsRuntimeContext>();
|
|
@@ -1105,46 +1089,6 @@ export function useDmsCookie<T = string | null>(
|
|
|
1105
1089
|
return runtime.sharedState.get(key) as Ref<T>;
|
|
1106
1090
|
}
|
|
1107
1091
|
|
|
1108
|
-
function preferredColorMode(): "light" | "dark" {
|
|
1109
|
-
return window.matchMedia?.("(prefers-color-scheme: dark)").matches
|
|
1110
|
-
? "dark"
|
|
1111
|
-
: "light";
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
function applyColorMode(preference: DmsColorModePreference): void {
|
|
1115
|
-
colorMode.value = preference === "system" ? preferredColorMode() : preference;
|
|
1116
|
-
document.documentElement.classList.remove(...COLOR_MODE_CLASSES);
|
|
1117
|
-
document.documentElement.classList.add(colorMode.value);
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
function initializeColorMode(): void {
|
|
1121
|
-
if (isColorModeInitialized) return;
|
|
1122
|
-
isColorModeInitialized = true;
|
|
1123
|
-
if (typeof window === "undefined") return;
|
|
1124
|
-
const stored = window.localStorage.getItem(COLOR_MODE_STORAGE_KEY);
|
|
1125
|
-
if (COLOR_MODE_CLASSES.includes(stored ?? "") || stored === "system") {
|
|
1126
|
-
colorMode.preference = stored as DmsColorModePreference;
|
|
1127
|
-
}
|
|
1128
|
-
watch(
|
|
1129
|
-
() => colorMode.preference,
|
|
1130
|
-
(preference) => {
|
|
1131
|
-
applyColorMode(preference);
|
|
1132
|
-
window.localStorage.setItem(COLOR_MODE_STORAGE_KEY, preference);
|
|
1133
|
-
},
|
|
1134
|
-
{ immediate: true },
|
|
1135
|
-
);
|
|
1136
|
-
window
|
|
1137
|
-
.matchMedia?.("(prefers-color-scheme: dark)")
|
|
1138
|
-
.addEventListener("change", () => {
|
|
1139
|
-
if (colorMode.preference === "system") applyColorMode("system");
|
|
1140
|
-
});
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
export function useColorMode(): DmsColorMode {
|
|
1144
|
-
initializeColorMode();
|
|
1145
|
-
return colorMode;
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
1092
|
export function createError(
|
|
1149
1093
|
input: string | DmsErrorData,
|
|
1150
1094
|
): Error & DmsErrorData {
|
package/templates/vue/index.html
CHANGED
|
@@ -4,16 +4,6 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<link rel="icon" href="data:," />
|
|
7
|
-
<script>
|
|
8
|
-
const preference = localStorage.getItem("dms-color-mode") || "system";
|
|
9
|
-
const mode =
|
|
10
|
-
preference === "system"
|
|
11
|
-
? matchMedia("(prefers-color-scheme: dark)").matches
|
|
12
|
-
? "dark"
|
|
13
|
-
: "light"
|
|
14
|
-
: preference;
|
|
15
|
-
document.documentElement.classList.add(mode);
|
|
16
|
-
</script>
|
|
17
7
|
<title>Antelope DMS</title>
|
|
18
8
|
</head>
|
|
19
9
|
<body>
|