lumiverse-spindle-types 0.3.2 → 0.3.3
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 +1 -1
- package/src/api.ts +65 -3
- package/src/index.ts +3 -0
- package/src/spindle-api.ts +28 -4
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -500,8 +500,8 @@ export interface PermissionDeniedDetail {
|
|
|
500
500
|
*/
|
|
501
501
|
export interface ThemeOverrideDTO {
|
|
502
502
|
/**
|
|
503
|
-
* Direct CSS variable overrides
|
|
504
|
-
* (e.g. `--lumiverse-primary
|
|
503
|
+
* Direct CSS variable overrides applied regardless of light/dark mode.
|
|
504
|
+
* Keys are CSS custom property names (e.g. `--lumiverse-primary`).
|
|
505
505
|
* Values must be valid CSS values.
|
|
506
506
|
*
|
|
507
507
|
* Common variable groups:
|
|
@@ -522,6 +522,66 @@ export interface ThemeOverrideDTO {
|
|
|
522
522
|
* - **Transitions**: `--lumiverse-transition`, `--lumiverse-transition-fast`, `--lcs-transition`, `--lcs-transition-fast`
|
|
523
523
|
*/
|
|
524
524
|
variables?: Record<string, string>;
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Mode-specific CSS variable overrides. When the user switches between
|
|
528
|
+
* light and dark mode, the frontend selects the matching set.
|
|
529
|
+
* Mode-specific values override flat `variables` for the same key.
|
|
530
|
+
*/
|
|
531
|
+
variablesByMode?: {
|
|
532
|
+
dark?: Record<string, string>;
|
|
533
|
+
light?: Record<string, string>;
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* RGB color value (0–255 per channel).
|
|
539
|
+
*/
|
|
540
|
+
export interface ColorRGB {
|
|
541
|
+
r: number;
|
|
542
|
+
g: number;
|
|
543
|
+
b: number;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* HSL color value (h: 0–360, s: 0–100, l: 0–100).
|
|
548
|
+
*/
|
|
549
|
+
export interface ColorHSL {
|
|
550
|
+
h: number;
|
|
551
|
+
s: number;
|
|
552
|
+
l: number;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Result of extracting colors from an image.
|
|
557
|
+
* Each region's dominant color is returned along with metadata.
|
|
558
|
+
*/
|
|
559
|
+
export interface ColorExtractionResult {
|
|
560
|
+
/** Overall dominant color of the full image */
|
|
561
|
+
dominant: ColorRGB;
|
|
562
|
+
/** Dominant color per sampled region */
|
|
563
|
+
regions: {
|
|
564
|
+
top: ColorRGB;
|
|
565
|
+
center: ColorRGB;
|
|
566
|
+
bottom: ColorRGB;
|
|
567
|
+
left: ColorRGB;
|
|
568
|
+
right: ColorRGB;
|
|
569
|
+
};
|
|
570
|
+
/** Per-region flatness score (0–1). High values = monotone/solid region. */
|
|
571
|
+
flatness: {
|
|
572
|
+
top: number;
|
|
573
|
+
center: number;
|
|
574
|
+
bottom: number;
|
|
575
|
+
left: number;
|
|
576
|
+
right: number;
|
|
577
|
+
full: number;
|
|
578
|
+
};
|
|
579
|
+
/** Simple average color across all sampled pixels */
|
|
580
|
+
average: ColorRGB;
|
|
581
|
+
/** Whether the dominant color is perceived as light (luminance > 152) */
|
|
582
|
+
isLight: boolean;
|
|
583
|
+
/** HSL representation of the dominant color */
|
|
584
|
+
dominantHsl: ColorHSL;
|
|
525
585
|
}
|
|
526
586
|
|
|
527
587
|
/**
|
|
@@ -784,7 +844,9 @@ export type WorkerToHost =
|
|
|
784
844
|
// ─── Theme (gated: "app_manipulation") ──────────────────────────────────
|
|
785
845
|
| { type: "theme_apply"; requestId: string; overrides: ThemeOverrideDTO; userId?: string }
|
|
786
846
|
| { type: "theme_clear"; requestId: string; userId?: string }
|
|
787
|
-
| { type: "theme_get_current"; requestId: string; userId?: string }
|
|
847
|
+
| { type: "theme_get_current"; requestId: string; userId?: string }
|
|
848
|
+
// ─── Color Extraction (gated: "app_manipulation") ─────────────────────
|
|
849
|
+
| { type: "color_extract"; requestId: string; imageId: string; userId?: string };
|
|
788
850
|
|
|
789
851
|
// ─── Host → Worker messages ──────────────────────────────────────────────
|
|
790
852
|
|
package/src/index.ts
CHANGED
package/src/spindle-api.ts
CHANGED
|
@@ -31,6 +31,7 @@ import type {
|
|
|
31
31
|
ImageGenProviderDTO,
|
|
32
32
|
ThemeOverrideDTO,
|
|
33
33
|
ThemeInfoDTO,
|
|
34
|
+
ColorExtractionResult,
|
|
34
35
|
} from "./api";
|
|
35
36
|
|
|
36
37
|
/** The global `spindle` object available in backend extension workers */
|
|
@@ -557,16 +558,27 @@ export interface SpindleAPI {
|
|
|
557
558
|
*
|
|
558
559
|
* @example
|
|
559
560
|
* ```ts
|
|
560
|
-
* // Apply a blue-tinted theme
|
|
561
|
+
* // Apply a blue-tinted theme with mode-aware backgrounds
|
|
561
562
|
* await spindle.theme.apply({
|
|
562
563
|
* variables: {
|
|
563
564
|
* '--lumiverse-primary': 'hsl(210, 80%, 60%)',
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
*
|
|
565
|
+
* },
|
|
566
|
+
* variablesByMode: {
|
|
567
|
+
* dark: {
|
|
568
|
+
* '--lumiverse-bg': 'hsl(210, 12%, 11%)',
|
|
569
|
+
* '--lumiverse-bg-elevated': 'hsl(210, 12%, 14%)',
|
|
570
|
+
* },
|
|
571
|
+
* light: {
|
|
572
|
+
* '--lumiverse-bg': 'hsl(210, 20%, 96%)',
|
|
573
|
+
* '--lumiverse-bg-elevated': 'hsl(210, 20%, 100%)',
|
|
574
|
+
* },
|
|
567
575
|
* },
|
|
568
576
|
* })
|
|
569
577
|
*
|
|
578
|
+
* // Extract colors from an image, then apply as theme
|
|
579
|
+
* const palette = await spindle.theme.extractColors('image-id-here')
|
|
580
|
+
* console.log(palette.dominant, palette.regions, palette.dominantHsl)
|
|
581
|
+
*
|
|
570
582
|
* // Read current theme state
|
|
571
583
|
* const info = await spindle.theme.getCurrent()
|
|
572
584
|
* console.log(info.mode, info.accent)
|
|
@@ -581,6 +593,9 @@ export interface SpindleAPI {
|
|
|
581
593
|
* Subsequent calls merge with (and overwrite) any previously applied
|
|
582
594
|
* overrides from this extension. The frontend applies overrides
|
|
583
595
|
* immediately via a WebSocket event.
|
|
596
|
+
*
|
|
597
|
+
* Use `variablesByMode` to specify different values for light/dark mode.
|
|
598
|
+
* Mode-specific values take precedence over flat `variables` for the same key.
|
|
584
599
|
*/
|
|
585
600
|
apply(overrides: ThemeOverrideDTO): Promise<void>;
|
|
586
601
|
/**
|
|
@@ -593,6 +608,15 @@ export interface SpindleAPI {
|
|
|
593
608
|
* Returns the base theme info (not including any extension overrides).
|
|
594
609
|
*/
|
|
595
610
|
getCurrent(userId?: string): Promise<ThemeInfoDTO>;
|
|
611
|
+
/**
|
|
612
|
+
* Extract colors from an image stored in Lumiverse's image system.
|
|
613
|
+
* Returns dominant, regional, and average colors with flatness scores.
|
|
614
|
+
* Useful for building mode-aware theme overrides from character avatars
|
|
615
|
+
* or other images.
|
|
616
|
+
*
|
|
617
|
+
* @param imageId - ID of an image in the images table
|
|
618
|
+
*/
|
|
619
|
+
extractColors(imageId: string, userId?: string): Promise<ColorExtractionResult>;
|
|
596
620
|
};
|
|
597
621
|
|
|
598
622
|
/** This extension's manifest */
|