mtrl-addons 0.4.4 → 0.5.1

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.
@@ -4,6 +4,8 @@ import { HueFeature } from "./features/hue";
4
4
  import { SwatchesFeature } from "./features/swatches";
5
5
  import { InputFeature } from "./features/input";
6
6
  import { VariantFeature } from "./features/variant";
7
+ import { PipetteFeature } from "./features/pipette";
8
+ import { OpacityFeature } from "./features/opacity";
7
9
  /**
8
10
  * API configuration options for color picker component
9
11
  * @category Components
@@ -30,6 +32,8 @@ interface ApiOptions {
30
32
  swatches?: SwatchesFeature;
31
33
  input?: InputFeature;
32
34
  variant?: VariantFeature;
35
+ pipette?: PipetteFeature;
36
+ opacity?: OpacityFeature;
33
37
  }
34
38
  /**
35
39
  * Enhances a color picker component with API methods.
@@ -15,7 +15,7 @@ export declare const defaultConfig: ColorPickerConfig;
15
15
  * @category Components
16
16
  * @internal
17
17
  */
18
- export declare const createBaseConfig: (config?: ColorPickerConfig) => Required<Pick<ColorPickerConfig, "value" | "variant" | "size" | "swatchSize" | "showInput" | "showPreview" | "showSwatches" | "showHue" | "showArea" | "maxSwatches" | "closeOnSelect" | "disabled" | "prefix" | "componentName">> & ColorPickerConfig;
18
+ export declare const createBaseConfig: (config?: ColorPickerConfig) => Required<Pick<ColorPickerConfig, "value" | "variant" | "size" | "density" | "swatchSize" | "showInput" | "showPreview" | "showSwatches" | "showHue" | "showArea" | "maxSwatches" | "closeOnSelect" | "disabled" | "prefix" | "componentName">> & ColorPickerConfig;
19
19
  /**
20
20
  * Gets the element configuration for withElement.
21
21
  *
@@ -84,6 +84,10 @@ export declare const getApiConfig: (comp: {
84
84
  hue?: {
85
85
  updateHandle: () => void;
86
86
  };
87
+ opacity?: {
88
+ updateBackground: () => void;
89
+ updateHandle: () => void;
90
+ };
87
91
  swatches?: {
88
92
  update: () => void;
89
93
  set: (swatches: unknown[]) => void;
@@ -124,6 +128,10 @@ export declare const getApiConfig: (comp: {
124
128
  hue: {
125
129
  updateHandle: () => void;
126
130
  } | undefined;
131
+ opacity: {
132
+ updateBackground: () => void;
133
+ updateHandle: () => void;
134
+ } | undefined;
127
135
  swatches: {
128
136
  update: () => void;
129
137
  set: (swatches: unknown[]) => void;
@@ -30,6 +30,15 @@ export declare const COLORPICKER_VARIANTS: {
30
30
  /** Dialog - modal overlay centered on screen */
31
31
  readonly DIALOG: "dialog";
32
32
  };
33
+ /**
34
+ * Color picker densities
35
+ */
36
+ export declare const COLORPICKER_DENSITIES: {
37
+ /** Default density with standard spacing */
38
+ readonly DEFAULT: "default";
39
+ /** Compact density - minimal layout, hue bar under area */
40
+ readonly COMPACT: "compact";
41
+ };
33
42
  /**
34
43
  * Color picker sizes
35
44
  */
@@ -73,6 +82,7 @@ export declare const COLORPICKER_CLASSES: {
73
82
  readonly DRAGGING: "colorpicker--dragging";
74
83
  readonly OPEN: "colorpicker--open";
75
84
  readonly POSITION_TOP: "colorpicker--position-top";
85
+ readonly COMPACT: "colorpicker--compact";
76
86
  readonly INLINE: "colorpicker--inline";
77
87
  readonly DROPDOWN: "colorpicker--dropdown";
78
88
  readonly DIALOG: "colorpicker--dialog";
@@ -21,6 +21,13 @@ export declare const withArea: (config: ColorPickerConfig) => <T extends {
21
21
  emit: (event: string, data?: unknown) => void;
22
22
  state?: ColorPickerState;
23
23
  pickerContent?: HTMLElement;
24
+ input?: {
25
+ update: () => void;
26
+ };
27
+ opacity?: {
28
+ updateBackground: () => void;
29
+ updateHandle: () => void;
30
+ };
24
31
  }>(component: T) => T & {
25
32
  area: AreaFeature;
26
33
  state: ColorPickerState;
@@ -1,15 +1,14 @@
1
- import { createSlider } from "mtrl";
2
1
  import { ColorPickerConfig, ColorPickerState } from "../types";
3
2
  /**
4
3
  * Hue feature interface
5
4
  */
6
5
  export interface HueFeature {
7
6
  element: HTMLElement;
8
- slider: ReturnType<typeof createSlider>;
7
+ handle: HTMLElement;
9
8
  updateHandle: () => void;
10
9
  }
11
10
  /**
12
- * Adds the hue slider to a color picker component using mtrl slider
11
+ * Adds a simple hue bar with rainbow gradient and draggable handle
13
12
  *
14
13
  * @param config - Color picker configuration
15
14
  * @returns Component enhancer function
@@ -12,3 +12,7 @@ export { withInput } from "./input";
12
12
  export type { InputFeature } from "./input";
13
13
  export { withVariant } from "./variant";
14
14
  export type { VariantFeature } from "./variant";
15
+ export { withPipette, isEyeDropperSupported } from "./pipette";
16
+ export type { PipetteFeature, PipetteConfig } from "./pipette";
17
+ export { withOpacity } from "./opacity";
18
+ export type { OpacityFeature } from "./opacity";
@@ -0,0 +1,29 @@
1
+ import { ColorPickerConfig, ColorPickerState } from "../types";
2
+ /**
3
+ * Opacity feature interface
4
+ */
5
+ export interface OpacityFeature {
6
+ element: HTMLElement;
7
+ handle: HTMLElement;
8
+ updateHandle: () => void;
9
+ updateBackground: () => void;
10
+ }
11
+ /**
12
+ * Adds an opacity/alpha bar with checkerboard background and draggable handle
13
+ *
14
+ * @param config - Color picker configuration
15
+ * @returns Component enhancer function
16
+ */
17
+ export declare const withOpacity: (config: ColorPickerConfig) => <T extends {
18
+ element: HTMLElement;
19
+ getClass: (name: string) => string;
20
+ emit: (event: string, data?: unknown) => void;
21
+ state?: ColorPickerState;
22
+ pickerContent?: HTMLElement;
23
+ hue?: {
24
+ element: HTMLElement;
25
+ };
26
+ }>(component: T) => T & {
27
+ opacity: OpacityFeature;
28
+ state: ColorPickerState;
29
+ };
@@ -0,0 +1,66 @@
1
+ import { ColorPickerConfig, ColorPickerState } from "../types";
2
+ /**
3
+ * Check if the native EyeDropper API is supported
4
+ */
5
+ export declare const isEyeDropperSupported: () => boolean;
6
+ /**
7
+ * Pipette feature interface
8
+ */
9
+ export interface PipetteFeature {
10
+ /** The pipette button element */
11
+ element: HTMLElement;
12
+ /** Start pipette sampling */
13
+ pick: () => Promise<string | null>;
14
+ /** Set the image source for canvas fallback */
15
+ setImageSource: (source: HTMLImageElement | string | null) => void;
16
+ /** Check if currently sampling */
17
+ isSampling: () => boolean;
18
+ /** Destroy and cleanup */
19
+ destroy: () => void;
20
+ }
21
+ /**
22
+ * Pipette configuration options
23
+ */
24
+ export interface PipetteConfig {
25
+ /**
26
+ * Whether to show the pipette button
27
+ * @default true (when supported or imageSource provided)
28
+ */
29
+ showPipette?: boolean;
30
+ /**
31
+ * Image source for canvas-based fallback sampling
32
+ * Can be an HTMLImageElement, URL string, or null
33
+ */
34
+ imageSource?: HTMLImageElement | string | null;
35
+ /**
36
+ * Callback when pipette sampling starts
37
+ */
38
+ onPipetteStart?: () => void;
39
+ /**
40
+ * Callback when pipette sampling ends
41
+ */
42
+ onPipetteEnd?: (color: string | null) => void;
43
+ }
44
+ declare module "../types" {
45
+ interface ColorPickerConfig extends PipetteConfig {
46
+ }
47
+ }
48
+ /**
49
+ * Adds pipette/color picker functionality to a color picker component
50
+ *
51
+ * @param config - Color picker configuration
52
+ * @returns Component enhancer function
53
+ */
54
+ export declare const withPipette: (config: ColorPickerConfig) => <T extends {
55
+ element: HTMLElement;
56
+ getClass: (name: string) => string;
57
+ emit: (event: string, data?: unknown) => void;
58
+ state?: ColorPickerState;
59
+ pickerContent?: HTMLElement;
60
+ input?: {
61
+ element: HTMLElement;
62
+ };
63
+ }>(component: T) => T & {
64
+ pipette: PipetteFeature;
65
+ state: ColorPickerState;
66
+ };
@@ -17,4 +17,6 @@ export { withInput } from "./features/input";
17
17
  export type { InputFeature } from "./features/input";
18
18
  export { withVariant } from "./features/variant";
19
19
  export type { VariantFeature } from "./features/variant";
20
+ export { withPipette, isEyeDropperSupported } from "./features/pipette";
21
+ export type { PipetteFeature, PipetteConfig, } from "./features/pipette";
20
22
  export { withAPI } from "./api";
@@ -70,11 +70,28 @@ export interface ColorPickerConfig {
70
70
  * @default true
71
71
  */
72
72
  showHue?: boolean;
73
+ /**
74
+ * Whether to show the opacity/alpha slider
75
+ * @default false
76
+ */
77
+ showOpacity?: boolean;
78
+ /**
79
+ * Initial opacity value (0-1)
80
+ * @default 1
81
+ */
82
+ opacity?: number;
73
83
  /**
74
84
  * Component size
75
85
  * @default 'm'
76
86
  */
77
87
  size?: ColorPickerSize | string;
88
+ /**
89
+ * Component density
90
+ * - 'default': Standard layout with gaps and padding
91
+ * - 'compact': Minimal layout, hue bar directly under area, no input/preview
92
+ * @default 'default'
93
+ */
94
+ density?: "default" | "compact";
78
95
  /**
79
96
  * Swatch size in pixels
80
97
  * @default 32
@@ -131,6 +148,49 @@ export interface ColorPickerConfig {
131
148
  * Callback during color selection (live preview)
132
149
  */
133
150
  onInput?: (color: string) => void;
151
+ /**
152
+ * Whether to show the pipette button
153
+ * @default true (when native API supported or imageSource provided)
154
+ */
155
+ showPipette?: boolean;
156
+ /**
157
+ * Image source for canvas-based pipette sampling
158
+ * Can be an HTMLImageElement, URL string, or null
159
+ * When provided, clicking pipette will sample from this image
160
+ * When not provided and native EyeDropper API is available, uses that instead
161
+ */
162
+ imageSource?: HTMLImageElement | string | null;
163
+ /**
164
+ * Callback when pipette sampling starts
165
+ */
166
+ onPipetteStart?: () => void;
167
+ /**
168
+ * Callback when pipette sampling ends
169
+ * @param color - The picked color (hex) or null if cancelled
170
+ */
171
+ onPipetteEnd?: (color: string | null) => void;
172
+ }
173
+ /**
174
+ * Feature references for cross-feature updates
175
+ */
176
+ export interface ColorPickerRefs {
177
+ input?: {
178
+ update: () => void;
179
+ };
180
+ opacity?: {
181
+ updateBackground: () => void;
182
+ updateHandle: () => void;
183
+ };
184
+ area?: {
185
+ updateBackground: () => void;
186
+ updateHandle: () => void;
187
+ };
188
+ hue?: {
189
+ updateHandle: () => void;
190
+ };
191
+ swatches?: {
192
+ update: () => void;
193
+ };
134
194
  }
135
195
  /**
136
196
  * Internal state for the color picker
@@ -140,14 +200,18 @@ export interface ColorPickerState {
140
200
  hsv: HSVColor;
141
201
  /** Current hex color */
142
202
  hex: string;
203
+ /** Current opacity/alpha value (0-1) */
204
+ opacity: number;
143
205
  /** Whether the user is currently dragging */
144
206
  isDragging: boolean;
145
- /** Current drag target ('area' | 'hue' | null) */
146
- dragTarget: "area" | "hue" | null;
207
+ /** Current drag target ('area' | 'hue' | 'opacity' | null) */
208
+ dragTarget: "area" | "hue" | "opacity" | null;
147
209
  /** Available swatches */
148
210
  swatches: ColorSwatch[];
149
211
  /** Whether the picker is open (dropdown/dialog variants) */
150
212
  isOpen: boolean;
213
+ /** Mutable refs to features for cross-feature updates */
214
+ refs: ColorPickerRefs;
151
215
  }
152
216
  /**
153
217
  * Color picker component interface
@@ -266,6 +330,34 @@ export interface ColorPickerComponent {
266
330
  * @returns True if open
267
331
  */
268
332
  isOpen: () => boolean;
333
+ /**
334
+ * Start pipette color picking
335
+ * Uses native EyeDropper API when available, or canvas sampling from imageSource
336
+ * @returns Promise resolving to picked color (hex) or null if cancelled
337
+ */
338
+ pickColor: () => Promise<string | null>;
339
+ /**
340
+ * Set the image source for canvas-based pipette sampling
341
+ * @param source - HTMLImageElement, URL string, or null
342
+ * @returns The component for chaining
343
+ */
344
+ setImageSource: (source: HTMLImageElement | string | null) => ColorPickerComponent;
345
+ /**
346
+ * Check if pipette is currently sampling
347
+ * @returns True if sampling is in progress
348
+ */
349
+ isSampling: () => boolean;
350
+ /**
351
+ * Gets the current opacity value
352
+ * @returns Opacity value (0-1)
353
+ */
354
+ getOpacity: () => number;
355
+ /**
356
+ * Sets the opacity value
357
+ * @param opacity - Opacity value (0-1)
358
+ * @returns The component for chaining
359
+ */
360
+ setOpacity: (opacity: number) => ColorPickerComponent;
269
361
  /**
270
362
  * Destroys the component and cleans up resources
271
363
  */