@glasshome/widget-sdk 0.1.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/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/create-entity.d.ts +22 -0
- package/dist/define-widget.d.ts +10 -0
- package/dist/framework/backgrounds/Glow.d.ts +24 -0
- package/dist/framework/backgrounds/WidgetSliderFill.d.ts +33 -0
- package/dist/framework/components/WidgetContent.d.ts +29 -0
- package/dist/framework/components/WidgetEmptyState.d.ts +34 -0
- package/dist/framework/components/WidgetIcon.d.ts +48 -0
- package/dist/framework/components/WidgetMetrics.d.ts +47 -0
- package/dist/framework/components/WidgetStatus.d.ts +26 -0
- package/dist/framework/components/WidgetSubtitle.d.ts +28 -0
- package/dist/framework/components/WidgetTitle.d.ts +29 -0
- package/dist/framework/components/WidgetValue.d.ts +31 -0
- package/dist/framework/core/Widget.d.ts +88 -0
- package/dist/framework/design-system/index.d.ts +8 -0
- package/dist/framework/design-system/spacing.d.ts +40 -0
- package/dist/framework/design-system/typography.d.ts +40 -0
- package/dist/framework/design-system/z-index.d.ts +23 -0
- package/dist/framework/dialogs/WidgetDialog.d.ts +47 -0
- package/dist/framework/dialogs/index.d.ts +4 -0
- package/dist/framework/gestures/cursors.d.ts +17 -0
- package/dist/framework/gestures/use-widget-gestures.d.ts +53 -0
- package/dist/framework/hooks/index.d.ts +15 -0
- package/dist/framework/hooks/use-debug-data.d.ts +46 -0
- package/dist/framework/hooks/use-widget-config.d.ts +48 -0
- package/dist/framework/hooks/use-widget-context.d.ts +46 -0
- package/dist/framework/hooks/use-widget-dialog.d.ts +45 -0
- package/dist/framework/hooks/use-widget-entity-group.d.ts +67 -0
- package/dist/framework/hooks/use-widget-entity.d.ts +53 -0
- package/dist/framework/hooks/use-widget-form.d.ts +79 -0
- package/dist/framework/hooks/use-widget-responsive.d.ts +41 -0
- package/dist/framework/index.d.ts +55 -0
- package/dist/framework/layout/WidgetStack.d.ts +28 -0
- package/dist/framework/theming/adaptive-color.d.ts +28 -0
- package/dist/framework/theming/colors.d.ts +59 -0
- package/dist/framework/theming/index.d.ts +8 -0
- package/dist/framework/types.d.ts +335 -0
- package/dist/framework/utils/cn.d.ts +28 -0
- package/dist/framework/utils/empty-state.d.ts +49 -0
- package/dist/framework/utils/entity-aggregation.d.ts +73 -0
- package/dist/framework/utils/entity-state.d.ts +103 -0
- package/dist/framework/utils/format-value.d.ts +22 -0
- package/dist/framework/utils/index.d.ts +12 -0
- package/dist/framework/utils/interpret-value.d.ts +17 -0
- package/dist/framework/variants/built-in-variants.d.ts +39 -0
- package/dist/framework/variants/index.d.ts +7 -0
- package/dist/framework/variants/variant-utils.d.ts +105 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1955 -0
- package/dist/theme.d.ts +21 -0
- package/dist/types.d.ts +51 -0
- package/dist/version.d.ts +5 -0
- package/dist/vite/index.d.ts +56 -0
- package/dist/vite/index.js +184 -0
- package/package.json +76 -0
- package/preview/host.tsx +89 -0
- package/preview/preview.html +49 -0
- package/tailwind-sources.css +1 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value Formatting Utility
|
|
3
|
+
*
|
|
4
|
+
* Formats numeric values with units, applying smart scaling for large numbers.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* formatValue(22, "°C") // "22°C"
|
|
9
|
+
* formatValue(1234, "W") // "1.2kW"
|
|
10
|
+
* formatValue(0.5, "") // "0.5"
|
|
11
|
+
* formatValue(1500000, "W") // "1.5MW"
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Format a numeric value with optional unit and smart scaling
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatValue(value: number | string, unit?: string, options?: {
|
|
18
|
+
/** Number of decimal places (default: auto) */
|
|
19
|
+
decimals?: number;
|
|
20
|
+
/** Enable smart scaling for large numbers (default: true) */
|
|
21
|
+
scale?: boolean;
|
|
22
|
+
}): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework Utilities - Barrel Export
|
|
3
|
+
*
|
|
4
|
+
* Helper functions for value formatting, entity state management,
|
|
5
|
+
* and class name composition.
|
|
6
|
+
*/
|
|
7
|
+
export { cn } from "./cn";
|
|
8
|
+
export { createEmptyStateConfig, type EmptyStateConfigOptions, type WidgetEmptyStateConfig, } from "./empty-state";
|
|
9
|
+
export { calculateLightGroup, calculateSensorGroup, type LightGroupResult, type SensorGroupResult, type SensorGroupType, } from "./entity-aggregation";
|
|
10
|
+
export { allEntitiesInState, anyEntityInState, countActiveEntities, countAvailableEntities, countEntitiesByState, getEntityAttribute, getEntityState, isEntityActive, isEntityAvailable, } from "./entity-state";
|
|
11
|
+
export { formatValue } from "./format-value";
|
|
12
|
+
export { interpretValue } from "./interpret-value";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value Interpretation Utility
|
|
3
|
+
*
|
|
4
|
+
* Provides semantic interpretation of numeric values based on unit.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* interpretValue(22, "°C") // "Warm"
|
|
9
|
+
* interpretValue(5, "°C") // "Cold"
|
|
10
|
+
* interpretValue(75, "%") // "High"
|
|
11
|
+
* interpretValue(400, "ppm") // "Good" (for CO2)
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Interpret a numeric value semantically
|
|
16
|
+
*/
|
|
17
|
+
export declare function interpretValue(value: number, unit?: string): string | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Widget Variants
|
|
3
|
+
*
|
|
4
|
+
* Simplified set of pre-built variant definitions that ship with the framework.
|
|
5
|
+
* These variants can be used as-is or extended/composed.
|
|
6
|
+
*
|
|
7
|
+
* Includes 3 core variants (classic-glass, minimal, compact-horizontal).
|
|
8
|
+
* Additional variants can be added later or created by widget authors
|
|
9
|
+
* using the variant composition utilities.
|
|
10
|
+
*/
|
|
11
|
+
import type { VariantRegistry, WidgetVariantConfig } from "../types";
|
|
12
|
+
export declare const classicGlass: WidgetVariantConfig;
|
|
13
|
+
export declare const minimal: WidgetVariantConfig;
|
|
14
|
+
export declare const compactHorizontal: WidgetVariantConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Built-in variant registry
|
|
17
|
+
* Maps variant IDs to their configurations
|
|
18
|
+
*/
|
|
19
|
+
export declare const builtInVariants: VariantRegistry;
|
|
20
|
+
/**
|
|
21
|
+
* Get a variant by ID from the built-in registry
|
|
22
|
+
*
|
|
23
|
+
* @param id Variant ID
|
|
24
|
+
* @returns Variant configuration or undefined if not found
|
|
25
|
+
*/
|
|
26
|
+
export declare function getBuiltInVariant(id: string): WidgetVariantConfig | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Check if a variant ID is a built-in variant
|
|
29
|
+
*
|
|
30
|
+
* @param id Variant ID to check
|
|
31
|
+
* @returns True if the variant is built-in
|
|
32
|
+
*/
|
|
33
|
+
export declare function isBuiltInVariant(id: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Get all built-in variant IDs
|
|
36
|
+
*
|
|
37
|
+
* @returns Array of built-in variant IDs
|
|
38
|
+
*/
|
|
39
|
+
export declare function getBuiltInVariantIds(): string[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Variant System - Barrel Export
|
|
3
|
+
*
|
|
4
|
+
* Built-in variant presets and composition utilities.
|
|
5
|
+
*/
|
|
6
|
+
export { builtInVariants, classicGlass, compactHorizontal, getBuiltInVariant, getBuiltInVariantIds, isBuiltInVariant, minimal, } from "./built-in-variants";
|
|
7
|
+
export { applyCssVars, applyLayout, composeVariants, createFlexLayout, extendVariant, mergeVariants, } from "./variant-utils";
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Variant Composition Utilities
|
|
3
|
+
*
|
|
4
|
+
* Utilities for creating, merging, extending, and composing widget variants.
|
|
5
|
+
* Enables flexible variant system with type safety and composability.
|
|
6
|
+
*/
|
|
7
|
+
import type { FlexLayoutStrategy, LayoutStrategy, WidgetVariantConfig } from "../types";
|
|
8
|
+
/**
|
|
9
|
+
* Merge two complete variant configurations
|
|
10
|
+
*
|
|
11
|
+
* Deep merges all properties, with `override` taking precedence.
|
|
12
|
+
* Layout strategies are replaced, not merged (since they have different shapes).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const customVariant = mergeVariants(classicGlass, {
|
|
17
|
+
* styles: {
|
|
18
|
+
* cssVars: {
|
|
19
|
+
* "--widget-bg": "rgba(0, 0, 0, 0.5)"
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function mergeVariants(base: WidgetVariantConfig, override: Partial<WidgetVariantConfig>): WidgetVariantConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Extend a base variant with partial overrides
|
|
28
|
+
*
|
|
29
|
+
* Similar to mergeVariants but returns a new variant that references the base
|
|
30
|
+
* via the `extends` property. Useful for variant inheritance chains.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* const darkGlass = extendVariant("classic-glass", {
|
|
35
|
+
* id: "dark-glass",
|
|
36
|
+
* name: "Dark Glass",
|
|
37
|
+
* styles: {
|
|
38
|
+
* cssVars: {
|
|
39
|
+
* "--widget-bg": "rgba(0, 0, 0, 0.5)"
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function extendVariant(baseId: string, override: Partial<WidgetVariantConfig> & {
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
}): WidgetVariantConfig;
|
|
49
|
+
/**
|
|
50
|
+
* Compose multiple variants together (left to right precedence)
|
|
51
|
+
*
|
|
52
|
+
* Merges multiple variants in sequence, with later variants taking precedence.
|
|
53
|
+
* Useful for combining layout + styling + interaction variants.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* const custom = composeVariants(
|
|
58
|
+
* minimal, // Base: minimal styling
|
|
59
|
+
* centeredLayout, // Add: centered layout
|
|
60
|
+
* largeIcons // Add: large icon sizing
|
|
61
|
+
* );
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function composeVariants(...variants: WidgetVariantConfig[]): WidgetVariantConfig;
|
|
65
|
+
/**
|
|
66
|
+
* Apply a layout strategy override to a variant
|
|
67
|
+
*
|
|
68
|
+
* Convenience function for changing just the layout of a variant.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```tsx
|
|
72
|
+
* const centered = applyLayout(minimal, {
|
|
73
|
+
* type: "flex",
|
|
74
|
+
* direction: "column",
|
|
75
|
+
* align: "center",
|
|
76
|
+
* justify: "center"
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function applyLayout(variant: WidgetVariantConfig, layout: LayoutStrategy): WidgetVariantConfig;
|
|
81
|
+
/**
|
|
82
|
+
* Apply CSS variable overrides to a variant
|
|
83
|
+
*
|
|
84
|
+
* Convenience function for changing just the CSS variables of a variant.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```tsx
|
|
88
|
+
* const blueTinted = applyCssVars(classicGlass, {
|
|
89
|
+
* "--widget-bg": "rgba(59, 130, 246, 0.2)",
|
|
90
|
+
* "--widget-border": "rgba(59, 130, 246, 0.3)"
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function applyCssVars(variant: WidgetVariantConfig, cssVars: Record<`--widget-${string}`, string | number>): WidgetVariantConfig;
|
|
95
|
+
/**
|
|
96
|
+
* Create a flex layout strategy
|
|
97
|
+
*
|
|
98
|
+
* Convenience function for creating common flex layouts.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```tsx
|
|
102
|
+
* const layout = createFlexLayout("column", "center", "center");
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function createFlexLayout(direction?: FlexLayoutStrategy["direction"], align?: FlexLayoutStrategy["align"], justify?: FlexLayoutStrategy["justify"], options?: Partial<FlexLayoutStrategy>): FlexLayoutStrategy;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { Entity } from "./create-entity";
|
|
2
|
+
export { createEntity } from "./create-entity";
|
|
3
|
+
export { defineWidget } from "./define-widget";
|
|
4
|
+
export * from "./framework";
|
|
5
|
+
export { getThemeToken, isDark } from "./theme";
|
|
6
|
+
export type { GridSize, WidgetContext, WidgetDefinition, WidgetManifest, } from "./types";
|
|
7
|
+
export { SDK_VERSION } from "./version";
|