@svadmin/core 0.56.0 → 0.58.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 +2 -1
- package/src/theme.svelte.ts +44 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svadmin/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
4
4
|
"author": "zuohuadong",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -133,6 +133,7 @@
|
|
|
133
133
|
"type": "module",
|
|
134
134
|
"types": "src/index.ts",
|
|
135
135
|
"dependencies": {
|
|
136
|
+
"@types/papaparse": "^5.5.2",
|
|
136
137
|
"@internationalized/date": "^3.12.3",
|
|
137
138
|
"@sinclair/typebox": "^0.34.52",
|
|
138
139
|
"papaparse": "^5.5.4"
|
package/src/theme.svelte.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { definedOptions } from './defined-options';
|
|
|
6
6
|
// - 'dark-first': adds 'light' class for light mode (dark-first)
|
|
7
7
|
|
|
8
8
|
export type ThemeMode='light'|'dark'|'system';
|
|
9
|
-
export type ColorTheme='blue'|'green'|'rose'|'orange'|'violet'|'neutral';
|
|
9
|
+
export type ColorTheme='blue'|'green'|'rose'|'orange'|'violet'|'neutral'|'indigo'|'stripe';
|
|
10
10
|
|
|
11
11
|
/** Controls how the theme class is applied to <html> */
|
|
12
12
|
export type ThemeStrategy='standard'|'dark-first';
|
|
@@ -190,6 +190,29 @@ export const builtinPresets: Record<string,ColorPreset>=$state({
|
|
|
190
190
|
'--chart-1': 'oklch(0.65 0.25 293)',
|
|
191
191
|
},
|
|
192
192
|
},
|
|
193
|
+
stripe: {
|
|
194
|
+
name: 'stripe',
|
|
195
|
+
label: 'Stripe',
|
|
196
|
+
color: '#635bff',
|
|
197
|
+
light: {
|
|
198
|
+
'--primary': 'oklch(0.54 0.24 293)',
|
|
199
|
+
'--primary-foreground': 'oklch(0.99 0 0)',
|
|
200
|
+
'--ring': 'oklch(0.54 0.24 293)',
|
|
201
|
+
'--sidebar-primary': 'oklch(0.54 0.24 293)',
|
|
202
|
+
'--sidebar-primary-foreground': 'oklch(0.99 0 0)',
|
|
203
|
+
'--sidebar-ring': 'oklch(0.54 0.24 293)',
|
|
204
|
+
'--chart-1': 'oklch(0.54 0.24 293)',
|
|
205
|
+
},
|
|
206
|
+
dark: {
|
|
207
|
+
'--primary': 'oklch(0.72 0.19 293)',
|
|
208
|
+
'--primary-foreground': 'oklch(0.16 0.02 270)',
|
|
209
|
+
'--ring': 'oklch(0.72 0.19 293)',
|
|
210
|
+
'--sidebar-primary': 'oklch(0.72 0.19 293)',
|
|
211
|
+
'--sidebar-primary-foreground': 'oklch(0.16 0.02 270)',
|
|
212
|
+
'--sidebar-ring': 'oklch(0.72 0.19 293)',
|
|
213
|
+
'--chart-1': 'oklch(0.72 0.19 293)',
|
|
214
|
+
},
|
|
215
|
+
},
|
|
193
216
|
});
|
|
194
217
|
|
|
195
218
|
/** Register a custom color preset. Overwrites any built-in preset with the same name. */
|
|
@@ -223,6 +246,8 @@ export interface ThemeConfig {
|
|
|
223
246
|
|
|
224
247
|
/** Explicit document-level values contributed by one mounted AdminApp. */
|
|
225
248
|
export interface ThemeOwnerOptions {
|
|
249
|
+
/** 仅在没有显式主题 owner 或 legacy 配置时使用,不接管其他实例的主题。 */
|
|
250
|
+
fallbackThemeConfig?: ThemeConfig;
|
|
226
251
|
themeConfig?: ThemeConfig;
|
|
227
252
|
defaultTheme?: ThemeMode;
|
|
228
253
|
}
|
|
@@ -262,6 +287,9 @@ function cloneThemeConfig(config: ThemeConfig={}): ThemeConfig {
|
|
|
262
287
|
|
|
263
288
|
function cloneOwnerOptions(options: ThemeOwnerOptions): ThemeOwnerOptions {
|
|
264
289
|
return definedOptions({
|
|
290
|
+
fallbackThemeConfig: options.fallbackThemeConfig === undefined
|
|
291
|
+
? undefined
|
|
292
|
+
: cloneThemeConfig(options.fallbackThemeConfig),
|
|
265
293
|
defaultTheme: options.defaultTheme,
|
|
266
294
|
themeConfig: options.themeConfig===undefined
|
|
267
295
|
? undefined
|
|
@@ -297,7 +325,8 @@ function readStoredTheme(): ThemeMode|undefined {
|
|
|
297
325
|
|
|
298
326
|
function readStoredColorTheme(): ColorTheme {
|
|
299
327
|
const stored=getStorage()?.getItem(COLOR_STORAGE_KEY);
|
|
300
|
-
|
|
328
|
+
// Stripe is the product default; an existing persisted preset remains authoritative.
|
|
329
|
+
return stored&&builtinPresets[stored]? stored as ColorTheme:'stripe';
|
|
301
330
|
}
|
|
302
331
|
|
|
303
332
|
function persistSelection(key: string,value: string): void {
|
|
@@ -331,9 +360,10 @@ function clearAppliedArtifacts(): void {
|
|
|
331
360
|
removeCssProperties(activePresetVars);
|
|
332
361
|
activeCssOverrideVars=[];
|
|
333
362
|
activePresetVars=[];
|
|
334
|
-
root.classList.remove('layout-clean-flat','light','dark');
|
|
363
|
+
root.classList.remove('layout-clean-flat','light','dark','svadmin-theme-light','svadmin-theme-dark');
|
|
335
364
|
root.style.removeProperty('color-scheme');
|
|
336
365
|
root.removeAttribute('data-theme');
|
|
366
|
+
root.removeAttribute('data-theme-mode');
|
|
337
367
|
}
|
|
338
368
|
|
|
339
369
|
function applyThemeClasses(themeMode: ThemeMode,config: ThemeConfig): void {
|
|
@@ -350,6 +380,9 @@ function applyThemeClasses(themeMode: ThemeMode,config: ThemeConfig): void {
|
|
|
350
380
|
root.classList.toggle('dark',resolved==='dark');
|
|
351
381
|
root.classList.remove('light');
|
|
352
382
|
}
|
|
383
|
+
root.classList.toggle('svadmin-theme-light',resolved==='light');
|
|
384
|
+
root.classList.toggle('svadmin-theme-dark',resolved==='dark');
|
|
385
|
+
root.setAttribute('data-theme-mode',resolved);
|
|
353
386
|
|
|
354
387
|
if(!config.disableColorScheme) root.style.colorScheme=resolved;
|
|
355
388
|
}
|
|
@@ -381,8 +414,10 @@ function applyCssOverrides(overrides: Record<string,string>): void {
|
|
|
381
414
|
function applyEffectiveTheme(): void {
|
|
382
415
|
const owner=getActiveOwner();
|
|
383
416
|
const nextConfig=owner
|
|
384
|
-
? cloneThemeConfig(owner.options.themeConfig)
|
|
385
|
-
:cloneThemeConfig(legacyThemeConfig)
|
|
417
|
+
? cloneThemeConfig(owner.options.themeConfig ?? owner.options.fallbackThemeConfig)
|
|
418
|
+
:cloneThemeConfig(Object.keys(legacyThemeConfig).length
|
|
419
|
+
? legacyThemeConfig
|
|
420
|
+
: themeOwners.at(-1)?.options.fallbackThemeConfig);
|
|
386
421
|
const nextMode=selectedMode??owner?.options.defaultTheme??'system';
|
|
387
422
|
const configuredPreset=!colorSelectionOverridesConfig&&nextConfig.colorPreset
|
|
388
423
|
? resolvePreset(nextConfig.colorPreset)
|
|
@@ -485,8 +520,8 @@ export function registerThemeOwner(options: ThemeOwnerOptions): ThemeOwnerToken|
|
|
|
485
520
|
|
|
486
521
|
if(isExplicitOwner(entry.options)) {
|
|
487
522
|
colorSelectionOverridesConfig=false;
|
|
488
|
-
applyEffectiveTheme();
|
|
489
523
|
}
|
|
524
|
+
if(isExplicitOwner(entry.options)||entry.options.fallbackThemeConfig) applyEffectiveTheme();
|
|
490
525
|
|
|
491
526
|
return token;
|
|
492
527
|
}
|
|
@@ -501,11 +536,12 @@ export function updateThemeOwner(
|
|
|
501
536
|
if(!owner) return;
|
|
502
537
|
|
|
503
538
|
const wasExplicit=isExplicitOwner(owner.options);
|
|
539
|
+
const hadFallback=owner.options.fallbackThemeConfig!==undefined;
|
|
504
540
|
owner.options=cloneOwnerOptions(options);
|
|
505
541
|
if(wasExplicit||isExplicitOwner(owner.options)) {
|
|
506
542
|
colorSelectionOverridesConfig=false;
|
|
507
|
-
applyEffectiveTheme();
|
|
508
543
|
}
|
|
544
|
+
if(wasExplicit||isExplicitOwner(owner.options)||hadFallback||owner.options.fallbackThemeConfig) applyEffectiveTheme();
|
|
509
545
|
}
|
|
510
546
|
|
|
511
547
|
/** Remove an owner safely regardless of its position in the stack. */
|
|
@@ -517,8 +553,8 @@ export function unregisterThemeOwner(token: ThemeOwnerToken|undefined): void {
|
|
|
517
553
|
const [removed]=themeOwners.splice(index,1);
|
|
518
554
|
if(removed&&isExplicitOwner(removed.options)) {
|
|
519
555
|
colorSelectionOverridesConfig=false;
|
|
520
|
-
applyEffectiveTheme();
|
|
521
556
|
}
|
|
557
|
+
if(removed&&(isExplicitOwner(removed.options)||removed.options.fallbackThemeConfig)) applyEffectiveTheme();
|
|
522
558
|
}
|
|
523
559
|
|
|
524
560
|
export function resetTheme(): void {
|