@nuxt/ui 3.0.2 → 3.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.
Files changed (220) hide show
  1. package/.nuxt/ui/accordion.ts +25 -4
  2. package/.nuxt/ui/alert.ts +52 -31
  3. package/.nuxt/ui/avatar-group.ts +24 -3
  4. package/.nuxt/ui/avatar.ts +26 -5
  5. package/.nuxt/ui/badge.ts +56 -35
  6. package/.nuxt/ui/breadcrumb.ts +28 -7
  7. package/.nuxt/ui/button-group.ts +23 -2
  8. package/.nuxt/ui/button.ts +66 -45
  9. package/.nuxt/ui/calendar.ts +39 -18
  10. package/.nuxt/ui/card.ts +28 -7
  11. package/.nuxt/ui/carousel.ts +29 -8
  12. package/.nuxt/ui/checkbox-group.ts +82 -0
  13. package/.nuxt/ui/checkbox.ts +163 -29
  14. package/.nuxt/ui/chip.ts +31 -10
  15. package/.nuxt/ui/collapsible.ts +23 -2
  16. package/.nuxt/ui/color-picker.ts +26 -5
  17. package/.nuxt/ui/command-palette.ts +37 -16
  18. package/.nuxt/ui/container.ts +23 -2
  19. package/.nuxt/ui/context-menu.ts +56 -35
  20. package/.nuxt/ui/drawer.ts +33 -12
  21. package/.nuxt/ui/dropdown-menu.ts +57 -36
  22. package/.nuxt/ui/form-field.ts +29 -8
  23. package/.nuxt/ui/form.ts +23 -2
  24. package/.nuxt/ui/index.ts +1 -0
  25. package/.nuxt/ui/input-menu.ts +65 -44
  26. package/.nuxt/ui/input-number.ts +43 -22
  27. package/.nuxt/ui/input.ts +46 -25
  28. package/.nuxt/ui/kbd.ts +27 -6
  29. package/.nuxt/ui/link.ts +26 -5
  30. package/.nuxt/ui/modal.ts +28 -7
  31. package/.nuxt/ui/navigation-menu.ts +102 -83
  32. package/.nuxt/ui/pagination.ts +23 -2
  33. package/.nuxt/ui/pin-input.ts +43 -22
  34. package/.nuxt/ui/popover.ts +25 -4
  35. package/.nuxt/ui/progress.ts +40 -19
  36. package/.nuxt/ui/radio-group.ts +273 -37
  37. package/.nuxt/ui/select-menu.ts +59 -35
  38. package/.nuxt/ui/select.ts +55 -34
  39. package/.nuxt/ui/separator.ts +31 -10
  40. package/.nuxt/ui/skeleton.ts +24 -3
  41. package/.nuxt/ui/slideover.ts +27 -6
  42. package/.nuxt/ui/slider.ts +39 -18
  43. package/.nuxt/ui/stepper.ts +41 -20
  44. package/.nuxt/ui/switch.ts +43 -22
  45. package/.nuxt/ui/table.ts +38 -17
  46. package/.nuxt/ui/tabs.ts +55 -34
  47. package/.nuxt/ui/textarea.ts +63 -37
  48. package/.nuxt/ui/toast.ts +47 -26
  49. package/.nuxt/ui/toaster.ts +23 -2
  50. package/.nuxt/ui/tooltip.ts +25 -4
  51. package/.nuxt/ui/tree.ts +41 -20
  52. package/.nuxt/ui.css +56 -12
  53. package/README.md +11 -0
  54. package/cli/templates.mjs +18 -17
  55. package/dist/module.json +5 -5
  56. package/dist/module.mjs +11 -7
  57. package/dist/runtime/components/Accordion.vue +36 -93
  58. package/dist/runtime/components/Accordion.vue.d.ts +91 -0
  59. package/dist/runtime/components/Alert.vue +37 -100
  60. package/dist/runtime/components/Alert.vue.d.ts +96 -0
  61. package/dist/runtime/components/App.vue +28 -34
  62. package/dist/runtime/components/App.vue.d.ts +24 -0
  63. package/dist/runtime/components/Avatar.vue +42 -75
  64. package/dist/runtime/components/Avatar.vue.d.ts +60 -0
  65. package/dist/runtime/components/AvatarGroup.vue +40 -77
  66. package/dist/runtime/components/AvatarGroup.vue.d.ts +40 -0
  67. package/dist/runtime/components/Badge.vue +33 -62
  68. package/dist/runtime/components/Badge.vue.d.ts +62 -0
  69. package/dist/runtime/components/Breadcrumb.vue +37 -90
  70. package/dist/runtime/components/Breadcrumb.vue.d.ts +82 -0
  71. package/dist/runtime/components/Button.vue +95 -104
  72. package/dist/runtime/components/Button.vue.d.ts +73 -0
  73. package/dist/runtime/components/ButtonGroup.vue +20 -46
  74. package/dist/runtime/components/ButtonGroup.vue.d.ts +55 -0
  75. package/dist/runtime/components/Calendar.vue +67 -150
  76. package/dist/runtime/components/Calendar.vue.d.ts +107 -0
  77. package/dist/runtime/components/Card.vue +18 -40
  78. package/dist/runtime/components/Card.vue.d.ts +38 -0
  79. package/dist/runtime/components/Carousel.vue +112 -234
  80. package/dist/runtime/components/Carousel.vue.d.ts +120 -0
  81. package/dist/runtime/components/Checkbox.vue +52 -93
  82. package/dist/runtime/components/Checkbox.vue.d.ts +76 -0
  83. package/dist/runtime/components/CheckboxGroup.vue +121 -0
  84. package/dist/runtime/components/CheckboxGroup.vue.d.ts +75 -0
  85. package/dist/runtime/components/Chip.vue +26 -69
  86. package/dist/runtime/components/Chip.vue.d.ts +71 -0
  87. package/dist/runtime/components/Collapsible.vue +22 -41
  88. package/dist/runtime/components/Collapsible.vue.d.ts +50 -0
  89. package/dist/runtime/components/ColorPicker.vue +111 -197
  90. package/dist/runtime/components/ColorPicker.vue.d.ts +63 -0
  91. package/dist/runtime/components/CommandPalette.vue +96 -237
  92. package/dist/runtime/components/CommandPalette.vue.d.ts +173 -0
  93. package/dist/runtime/components/Container.vue +15 -28
  94. package/dist/runtime/components/Container.vue.d.ts +27 -0
  95. package/dist/runtime/components/ContextMenu.vue +34 -133
  96. package/dist/runtime/components/ContextMenu.vue.d.ts +127 -0
  97. package/dist/runtime/components/ContextMenuContent.vue +73 -81
  98. package/dist/runtime/components/ContextMenuContent.vue.d.ts +105 -0
  99. package/dist/runtime/components/Drawer.vue +49 -83
  100. package/dist/runtime/components/Drawer.vue.d.ts +88 -0
  101. package/dist/runtime/components/DropdownMenu.vue +39 -142
  102. package/dist/runtime/components/DropdownMenu.vue.d.ts +141 -0
  103. package/dist/runtime/components/DropdownMenuContent.vue +78 -88
  104. package/dist/runtime/components/DropdownMenuContent.vue.d.ts +55 -0
  105. package/dist/runtime/components/Form.vue +135 -220
  106. package/dist/runtime/components/Form.vue.d.ts +66 -0
  107. package/dist/runtime/components/FormField.vue +35 -77
  108. package/dist/runtime/components/FormField.vue.d.ts +70 -0
  109. package/dist/runtime/components/Icon.vue +12 -19
  110. package/dist/runtime/components/Icon.vue.d.ts +17 -0
  111. package/dist/runtime/components/Input.vue +82 -140
  112. package/dist/runtime/components/Input.vue.d.ts +91 -0
  113. package/dist/runtime/components/InputMenu.vue +185 -332
  114. package/dist/runtime/components/InputMenu.vue.d.ts +312 -0
  115. package/dist/runtime/components/InputNumber.vue +71 -133
  116. package/dist/runtime/components/InputNumber.vue.d.ts +193 -0
  117. package/dist/runtime/components/Kbd.vue +20 -46
  118. package/dist/runtime/components/Kbd.vue.d.ts +55 -0
  119. package/dist/runtime/components/Link.vue +98 -176
  120. package/dist/runtime/components/Link.vue.d.ts +124 -0
  121. package/dist/runtime/components/LinkBase.vue +33 -42
  122. package/dist/runtime/components/LinkBase.vue.d.ts +48 -0
  123. package/dist/runtime/components/Modal.vue +53 -116
  124. package/dist/runtime/components/Modal.vue.d.ts +109 -0
  125. package/dist/runtime/components/NavigationMenu.vue +77 -209
  126. package/dist/runtime/components/NavigationMenu.vue.d.ts +159 -0
  127. package/dist/runtime/components/OverlayProvider.vue +14 -18
  128. package/dist/runtime/components/OverlayProvider.vue.d.ts +2 -0
  129. package/dist/runtime/components/Pagination.vue +46 -140
  130. package/dist/runtime/components/Pagination.vue.d.ts +143 -0
  131. package/dist/runtime/components/PinInput.vue +61 -78
  132. package/dist/runtime/components/PinInput.vue.d.ts +68 -0
  133. package/dist/runtime/components/Popover.vue +47 -84
  134. package/dist/runtime/components/Popover.vue.d.ts +80 -0
  135. package/dist/runtime/components/Progress.vue +70 -131
  136. package/dist/runtime/components/Progress.vue.d.ts +97 -0
  137. package/dist/runtime/components/RadioGroup.vue +70 -132
  138. package/dist/runtime/components/RadioGroup.vue.d.ts +88 -0
  139. package/dist/runtime/components/Select.vue +110 -224
  140. package/dist/runtime/components/Select.vue.d.ts +139 -0
  141. package/dist/runtime/components/SelectMenu.vue +161 -310
  142. package/dist/runtime/components/SelectMenu.vue.d.ts +184 -0
  143. package/dist/runtime/components/Separator.vue +29 -71
  144. package/dist/runtime/components/Separator.vue.d.ts +75 -0
  145. package/dist/runtime/components/Skeleton.vue +21 -23
  146. package/dist/runtime/components/Skeleton.vue.d.ts +26 -0
  147. package/dist/runtime/components/Slideover.vue +53 -120
  148. package/dist/runtime/components/Slideover.vue.d.ts +111 -0
  149. package/dist/runtime/components/Slider.vue +46 -84
  150. package/dist/runtime/components/Slider.vue.d.ts +71 -0
  151. package/dist/runtime/components/Stepper.vue +45 -115
  152. package/dist/runtime/components/Stepper.vue.d.ts +89 -0
  153. package/dist/runtime/components/Switch.vue +45 -93
  154. package/dist/runtime/components/Switch.vue.d.ts +73 -0
  155. package/dist/runtime/components/Table.vue +163 -267
  156. package/dist/runtime/components/Table.vue.d.ts +183 -0
  157. package/dist/runtime/components/Tabs.vue +41 -107
  158. package/dist/runtime/components/Tabs.vue.d.ts +104 -0
  159. package/dist/runtime/components/Textarea.vue +113 -158
  160. package/dist/runtime/components/Textarea.vue.d.ts +95 -0
  161. package/dist/runtime/components/Toast.vue +49 -110
  162. package/dist/runtime/components/Toast.vue.d.ts +95 -0
  163. package/dist/runtime/components/Toaster.vue +70 -107
  164. package/dist/runtime/components/Toaster.vue.d.ts +63 -0
  165. package/dist/runtime/components/Tooltip.vue +38 -65
  166. package/dist/runtime/components/Tooltip.vue.d.ts +65 -0
  167. package/dist/runtime/components/Tree.vue +59 -166
  168. package/dist/runtime/components/Tree.vue.d.ts +128 -0
  169. package/dist/runtime/composables/defineShortcuts.d.ts +1 -1
  170. package/dist/runtime/composables/useAvatarGroup.d.ts +1 -1
  171. package/dist/runtime/composables/useButtonGroup.d.ts +2 -2
  172. package/dist/runtime/composables/useFormField.d.ts +2 -2
  173. package/dist/runtime/composables/useOverlay.d.ts +14 -7
  174. package/dist/runtime/composables/useOverlay.js +14 -6
  175. package/dist/runtime/composables/usePortal.d.ts +6 -0
  176. package/dist/runtime/composables/usePortal.js +17 -0
  177. package/dist/runtime/index.css +1 -1
  178. package/dist/runtime/inertia/components/Link.vue +146 -0
  179. package/dist/runtime/inertia/components/Link.vue.d.ts +92 -0
  180. package/dist/runtime/inertia/stubs.d.ts +43 -0
  181. package/dist/runtime/inertia/stubs.js +82 -0
  182. package/dist/runtime/locale/bg.d.ts +3 -0
  183. package/dist/runtime/locale/bg.js +54 -0
  184. package/dist/runtime/locale/index.d.ts +5 -1
  185. package/dist/runtime/locale/index.js +5 -1
  186. package/dist/runtime/locale/kk.d.ts +3 -0
  187. package/dist/runtime/locale/kk.js +54 -0
  188. package/dist/runtime/locale/tj.d.ts +3 -0
  189. package/dist/runtime/locale/tj.js +54 -0
  190. package/dist/runtime/locale/ug_cn.d.ts +3 -0
  191. package/dist/runtime/locale/ug_cn.js +55 -0
  192. package/dist/runtime/types/form.d.ts +4 -1
  193. package/dist/runtime/types/index.d.ts +1 -0
  194. package/dist/runtime/types/index.js +1 -0
  195. package/dist/runtime/types/utils.d.ts +47 -7
  196. package/dist/runtime/utils/link.d.ts +3 -3
  197. package/dist/runtime/utils/link.js +1 -0
  198. package/dist/runtime/utils/tv.js +2 -2
  199. package/dist/runtime/vue/components/Icon.vue +7 -8
  200. package/dist/runtime/vue/components/Icon.vue.d.ts +14 -0
  201. package/dist/runtime/vue/components/Link.vue +118 -202
  202. package/dist/runtime/vue/components/Link.vue.d.ts +124 -0
  203. package/dist/runtime/vue/stubs.d.ts +2 -2
  204. package/dist/shared/{ui.BkNUP964.mjs → ui.D7lOOabO.mjs} +621 -362
  205. package/dist/types.d.mts +3 -5
  206. package/dist/unplugin.d.mts +4 -0
  207. package/dist/unplugin.mjs +25 -4
  208. package/dist/vite.mjs +1 -1
  209. package/package.json +94 -53
  210. package/dist/module.cjs +0 -62
  211. package/dist/module.d.cts +0 -45
  212. package/dist/module.d.ts +0 -45
  213. package/dist/shared/ui.BL-XB3u1.cjs +0 -3555
  214. package/dist/types.d.ts +0 -7
  215. package/dist/unplugin.cjs +0 -232
  216. package/dist/unplugin.d.cts +0 -62
  217. package/dist/unplugin.d.ts +0 -62
  218. package/dist/vite.cjs +0 -23
  219. package/dist/vite.d.cts +0 -15
  220. package/dist/vite.d.ts +0 -15
@@ -1,46 +1,27 @@
1
- <script lang="ts">
2
- import type { CollapsibleRootProps, CollapsibleRootEmits } from 'reka-ui'
3
- import type { AppConfig } from '@nuxt/schema'
4
- import _appConfig from '#build/app.config'
5
- import theme from '#build/ui/collapsible'
6
- import { tv } from '../utils/tv'
7
-
8
- const appConfigCollapsible = _appConfig as AppConfig & { ui: { collapsible: Partial<typeof theme> } }
9
-
10
- const collapsible = tv({ extend: tv(theme), ...(appConfigCollapsible.ui?.collapsible || {}) })
11
-
12
- export interface CollapsibleProps extends Pick<CollapsibleRootProps, 'defaultOpen' | 'open' | 'disabled' | 'unmountOnHide'> {
13
- /**
14
- * The element or component this component should render as.
15
- * @defaultValue 'div'
16
- */
17
- as?: any
18
- class?: any
19
- ui?: Partial<typeof collapsible.slots>
20
- }
21
-
22
- export interface CollapsibleEmits extends CollapsibleRootEmits {}
23
-
24
- export interface CollapsibleSlots {
25
- default(props: { open: boolean }): any
26
- content(props?: {}): any
27
- }
1
+ <script>
2
+ import theme from "#build/ui/collapsible";
28
3
  </script>
29
4
 
30
- <script setup lang="ts">
31
- import { CollapsibleRoot, CollapsibleTrigger, CollapsibleContent, useForwardPropsEmits } from 'reka-ui'
32
- import { reactivePick } from '@vueuse/core'
33
-
34
- const props = withDefaults(defineProps<CollapsibleProps>(), {
35
- unmountOnHide: true
36
- })
37
- const emits = defineEmits<CollapsibleEmits>()
38
- const slots = defineSlots<CollapsibleSlots>()
39
-
40
- const rootProps = useForwardPropsEmits(reactivePick(props, 'as', 'defaultOpen', 'open', 'disabled', 'unmountOnHide'), emits)
41
-
42
- // eslint-disable-next-line vue/no-dupe-keys
43
- const ui = collapsible()
5
+ <script setup>
6
+ import { computed } from "vue";
7
+ import { CollapsibleRoot, CollapsibleTrigger, CollapsibleContent, useForwardPropsEmits } from "reka-ui";
8
+ import { reactivePick } from "@vueuse/core";
9
+ import { useAppConfig } from "#imports";
10
+ import { tv } from "../utils/tv";
11
+ const props = defineProps({
12
+ as: { type: null, required: false },
13
+ class: { type: null, required: false },
14
+ ui: { type: null, required: false },
15
+ defaultOpen: { type: Boolean, required: false },
16
+ open: { type: Boolean, required: false },
17
+ disabled: { type: Boolean, required: false },
18
+ unmountOnHide: { type: Boolean, required: false, default: true }
19
+ });
20
+ const emits = defineEmits(["update:open"]);
21
+ const slots = defineSlots();
22
+ const appConfig = useAppConfig();
23
+ const rootProps = useForwardPropsEmits(reactivePick(props, "as", "defaultOpen", "open", "disabled", "unmountOnHide"), emits);
24
+ const ui = computed(() => tv({ extend: tv(theme), ...appConfig.ui?.collapsible || {} })());
44
25
  </script>
45
26
 
46
27
  <template>
@@ -0,0 +1,50 @@
1
+ import type { CollapsibleRootProps, CollapsibleRootEmits } from 'reka-ui';
2
+ import type { AppConfig } from '@nuxt/schema';
3
+ import theme from '#build/ui/collapsible';
4
+ import type { ComponentConfig } from '../types/utils';
5
+ type Collapsible = ComponentConfig<typeof theme, AppConfig, 'collapsible'>;
6
+ export interface CollapsibleProps extends Pick<CollapsibleRootProps, 'defaultOpen' | 'open' | 'disabled' | 'unmountOnHide'> {
7
+ /**
8
+ * The element or component this component should render as.
9
+ * @defaultValue 'div'
10
+ */
11
+ as?: any;
12
+ class?: any;
13
+ ui?: Collapsible['slots'];
14
+ }
15
+ export interface CollapsibleEmits extends CollapsibleRootEmits {
16
+ }
17
+ export interface CollapsibleSlots {
18
+ default(props: {
19
+ open: boolean;
20
+ }): any;
21
+ content(props?: {}): any;
22
+ }
23
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<CollapsibleProps>, {
24
+ unmountOnHide: boolean;
25
+ }>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, any, string, import("vue").PublicProps, any, {
26
+ unmountOnHide: boolean;
27
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>, Readonly<CollapsibleSlots> & CollapsibleSlots>;
28
+ export default _default;
29
+ type __VLS_WithDefaults<P, D> = {
30
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_PrettifyLocal<P[K] & {
31
+ default: D[K];
32
+ }> : P[K];
33
+ };
34
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
35
+ type __VLS_TypePropsToOption<T> = {
36
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
37
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
38
+ } : {
39
+ type: import('vue').PropType<T[K]>;
40
+ required: true;
41
+ };
42
+ };
43
+ type __VLS_WithTemplateSlots<T, S> = T & {
44
+ new (): {
45
+ $slots: S;
46
+ };
47
+ };
48
+ type __VLS_PrettifyLocal<T> = {
49
+ [K in keyof T]: T[K];
50
+ } & {};
@@ -1,271 +1,185 @@
1
- <!-- eslint-disable vue/block-tag-newline -->
2
- <script lang="ts">
3
- import type { VariantProps } from 'tailwind-variants'
4
- import type { MaybeRefOrGetter } from '@vueuse/shared'
5
- import type { AppConfig } from '@nuxt/schema'
6
- import _appConfig from '#build/app.config'
7
- import theme from '#build/ui/color-picker'
8
- import { tv } from '../utils/tv'
9
- import type { HSLObject } from 'colortranslator'
10
-
11
- const appConfigColorPicker = _appConfig as AppConfig & { ui: { colorPicker: Partial<typeof theme> } }
12
-
13
- const colorPicker = tv({ extend: tv(theme), ...(appConfigColorPicker.ui?.colorPicker || {}) })
14
-
15
- type ColorPickerVariants = VariantProps<typeof colorPicker>
16
-
17
- type HSVColor = {
18
- h: number
19
- s: number
20
- v: number
21
- }
22
-
23
- function HSLtoHSV(hsl: HSLObject): HSVColor {
24
- const x = hsl.S * (hsl.L < 50 ? hsl.L : 100 - hsl.L)
25
- const v = hsl.L + (x / 100)
26
-
1
+ <script>
2
+ import theme from "#build/ui/color-picker";
3
+ function HSLtoHSV(hsl) {
4
+ const x = hsl.S * (hsl.L < 50 ? hsl.L : 100 - hsl.L);
5
+ const v = hsl.L + x / 100;
27
6
  return {
28
7
  h: hsl.H,
29
8
  s: hsl.L === 0 ? hsl.S : 2 * x / v,
30
9
  v
31
- }
10
+ };
32
11
  }
33
-
34
- function HSVtoHSL(hsv: HSVColor): HSLObject {
35
- const x = (200 - hsv.s) * hsv.v / 100
36
-
12
+ function HSVtoHSL(hsv) {
13
+ const x = (200 - hsv.s) * hsv.v / 100;
37
14
  return {
38
15
  H: hsv.h,
39
16
  S: x === 0 || x === 200 ? 0 : Math.round(hsv.s * hsv.v / (x <= 100 ? x : 200 - x)),
40
17
  L: Math.round(x / 2)
41
- }
18
+ };
42
19
  }
43
-
44
- export type ColorPickerProps = {
45
- /**
46
- * The element or component this component should render as.
47
- * @defaultValue 'div'
48
- */
49
- as?: any
50
- /**
51
- * Throttle time in ms for the color picker
52
- */
53
- throttle?: number
54
- /**
55
- * Disable the color picker
56
- */
57
- disabled?: boolean
58
- /**
59
- * The default value of the color picker
60
- */
61
- defaultValue?: string
62
- /**
63
- * Format of the color
64
- * @defaultValue 'hex'
65
- */
66
- format?: 'hex' | 'rgb' | 'hsl' | 'cmyk' | 'lab'
67
- /**
68
- * @defaultValue 'md'
69
- */
70
- size?: ColorPickerVariants['size']
71
- class?: any
72
- ui?: Partial<typeof colorPicker.slots>
73
- }
74
-
75
20
  </script>
76
21
 
77
- <script setup lang="ts">
78
- import { ref, nextTick, computed, toValue } from 'vue'
79
- import { Primitive } from 'reka-ui'
80
- import { useEventListener, useElementBounding, watchThrottled, watchPausable } from '@vueuse/core'
81
- import { isClient } from '@vueuse/shared'
82
- import { ColorTranslator } from 'colortranslator'
83
-
84
- const props = withDefaults(defineProps<ColorPickerProps>(), {
85
- format: 'hex',
86
- throttle: 50,
87
- defaultValue: '#FFFFFF'
88
- })
89
- const modelValue = defineModel<string>(undefined)
90
-
91
- const pickedColor = computed<HSVColor>({
22
+ <script setup>
23
+ import { ref, nextTick, computed, toValue } from "vue";
24
+ import { Primitive } from "reka-ui";
25
+ import { useEventListener, useElementBounding, watchThrottled, watchPausable } from "@vueuse/core";
26
+ import { isClient } from "@vueuse/shared";
27
+ import { ColorTranslator } from "colortranslator";
28
+ import { useAppConfig } from "#imports";
29
+ import { tv } from "../utils/tv";
30
+ const props = defineProps({
31
+ as: { type: null, required: false },
32
+ throttle: { type: Number, required: false, default: 50 },
33
+ disabled: { type: Boolean, required: false },
34
+ defaultValue: { type: String, required: false, default: "#FFFFFF" },
35
+ format: { type: String, required: false, default: "hex" },
36
+ size: { type: null, required: false },
37
+ class: { type: null, required: false },
38
+ ui: { type: null, required: false }
39
+ });
40
+ const modelValue = defineModel({ type: String, ...void 0 });
41
+ const appConfig = useAppConfig();
42
+ const ui = computed(() => tv({ extend: tv(theme), ...appConfig.ui?.colorPicker || {} })({
43
+ size: props.size
44
+ }));
45
+ const pickedColor = computed({
92
46
  get() {
93
47
  try {
94
- const color = new ColorTranslator(modelValue.value || props.defaultValue)
95
-
96
- return HSLtoHSV(color.HSLObject)
48
+ const color = new ColorTranslator(modelValue.value || props.defaultValue);
49
+ return HSLtoHSV(color.HSLObject);
97
50
  } catch (_) {
98
- return { h: 0, s: 0, v: 100 }
51
+ return { h: 0, s: 0, v: 100 };
99
52
  }
100
53
  },
101
54
  set(value) {
102
55
  const color = new ColorTranslator(HSVtoHSL(value), {
103
56
  decimals: 2,
104
- labUnit: 'percent',
105
- cmykUnit: 'percent',
106
- cmykFunction: 'cmyk'
107
- })
108
-
57
+ labUnit: "percent",
58
+ cmykUnit: "percent",
59
+ cmykFunction: "cmyk"
60
+ });
109
61
  switch (props.format) {
110
- case 'rgb':
111
- modelValue.value = color.RGB
112
- break
113
- case 'hsl':
114
- modelValue.value = color.HSL
115
- break
116
- case 'cmyk':
117
- modelValue.value = color.CMYK
118
- break
119
- case 'lab':
120
- modelValue.value = color.CIELab
121
- break
122
- case 'hex':
62
+ case "rgb":
63
+ modelValue.value = color.RGB;
64
+ break;
65
+ case "hsl":
66
+ modelValue.value = color.HSL;
67
+ break;
68
+ case "cmyk":
69
+ modelValue.value = color.CMYK;
70
+ break;
71
+ case "lab":
72
+ modelValue.value = color.CIELab;
73
+ break;
74
+ case "hex":
123
75
  default:
124
- modelValue.value = color.HEX
76
+ modelValue.value = color.HEX;
125
77
  }
126
78
  }
127
- })
128
-
129
- function useColorDraggable(targetElement: MaybeRefOrGetter<HTMLElement | null>,
130
- containerElement: MaybeRefOrGetter<HTMLElement | null>,
131
- axis: 'x' | 'y' | 'both' = 'both',
132
- initialPosition = { x: 0, y: 0 },
133
- disabled?: MaybeRefOrGetter<boolean | undefined>
134
- ) {
135
- const position = ref<{ x: number, y: number }>(initialPosition)
136
- const pressedDelta = ref<{ x: number, y: number }>()
137
- const targetRect = useElementBounding(targetElement)
138
- const containerRect = useElementBounding(containerElement)
139
-
140
- function start(event: PointerEvent) {
141
- if (toValue(disabled)) return event.preventDefault()
142
-
143
- const container = toValue(containerElement)
144
-
79
+ });
80
+ function useColorDraggable(targetElement, containerElement, axis = "both", initialPosition = { x: 0, y: 0 }, disabled2) {
81
+ const position = ref(initialPosition);
82
+ const pressedDelta = ref();
83
+ const targetRect = useElementBounding(targetElement);
84
+ const containerRect = useElementBounding(containerElement);
85
+ function start(event) {
86
+ if (toValue(disabled2)) return event.preventDefault();
87
+ const container = toValue(containerElement);
145
88
  pressedDelta.value = {
146
89
  x: event.clientX - (container ? event.clientX - containerRect.left.value + container.scrollLeft : targetRect.left.value),
147
90
  y: event.clientY - (container ? event.clientY - containerRect.top.value + container.scrollTop : targetRect.top.value)
148
- }
149
-
150
- move(event)
91
+ };
92
+ move(event);
151
93
  }
152
-
153
- function move(event: PointerEvent) {
154
- if (!pressedDelta.value) return
155
-
156
- const container = toValue(containerElement)
157
- let { x, y } = position.value
158
-
159
- if (container && (axis === 'x' || axis === 'both')) {
160
- x = Math.min(Math.max(0, (event.clientX - pressedDelta.value.x) / container.scrollWidth * 100), 100)
94
+ function move(event) {
95
+ if (!pressedDelta.value) return;
96
+ const container = toValue(containerElement);
97
+ let { x, y } = position.value;
98
+ if (container && (axis === "x" || axis === "both")) {
99
+ x = Math.min(Math.max(0, (event.clientX - pressedDelta.value.x) / container.scrollWidth * 100), 100);
161
100
  }
162
-
163
- if (container && (axis === 'y' || axis === 'both')) {
164
- y = Math.min(Math.max(0, (event.clientY - pressedDelta.value.y) / container.scrollHeight * 100), 100)
101
+ if (container && (axis === "y" || axis === "both")) {
102
+ y = Math.min(Math.max(0, (event.clientY - pressedDelta.value.y) / container.scrollHeight * 100), 100);
165
103
  }
166
-
167
- position.value = { x, y }
104
+ position.value = { x, y };
168
105
  }
169
-
170
106
  function end() {
171
107
  if (!pressedDelta.value) {
172
- return
108
+ return;
173
109
  }
174
-
175
- pressedDelta.value = undefined
110
+ pressedDelta.value = void 0;
176
111
  }
177
-
178
112
  if (isClient) {
179
- useEventListener(containerElement, 'pointerdown', start)
180
- useEventListener(window, 'pointermove', move)
181
- useEventListener(window, 'pointerup', end)
113
+ useEventListener(containerElement, "pointerdown", start);
114
+ useEventListener(window, "pointermove", move);
115
+ useEventListener(window, "pointerup", end);
182
116
  }
183
-
184
117
  return {
185
118
  position
186
- }
119
+ };
187
120
  }
188
-
189
- function normalizeHue(hue: number, dir: 'left' | 'right' = 'left'): number {
190
- if (dir === 'right') {
191
- return (hue * 100) / 360
121
+ function normalizeHue(hue, dir = "left") {
122
+ if (dir === "right") {
123
+ return hue * 100 / 360;
192
124
  }
193
-
194
- return (hue / 100) * 360
125
+ return hue / 100 * 360;
195
126
  }
196
-
197
- function normalizeBrightness(brightness: number): number {
198
- return 100 - brightness
127
+ function normalizeBrightness(brightness) {
128
+ return 100 - brightness;
199
129
  }
200
-
201
- const selectorRef = ref<HTMLDivElement | null>(null)
202
- const selectorThumbRef = ref<HTMLDivElement | null>(null)
203
- const trackRef = ref<HTMLDivElement | null>(null)
204
- const trackThumbRef = ref<HTMLDivElement | null>(null)
205
-
206
- const disabled = computed(() => props.disabled)
207
-
208
- const { position: selectorThumbPosition } = useColorDraggable(selectorThumbRef, selectorRef, 'both', {
130
+ const selectorRef = ref(null);
131
+ const selectorThumbRef = ref(null);
132
+ const trackRef = ref(null);
133
+ const trackThumbRef = ref(null);
134
+ const disabled = computed(() => props.disabled);
135
+ const { position: selectorThumbPosition } = useColorDraggable(selectorThumbRef, selectorRef, "both", {
209
136
  x: pickedColor.value.s,
210
137
  y: normalizeBrightness(pickedColor.value.v)
211
- }, disabled)
212
-
213
- const { position: trackThumbPosition } = useColorDraggable(trackThumbRef, trackRef, 'y', {
138
+ }, disabled);
139
+ const { position: trackThumbPosition } = useColorDraggable(trackThumbRef, trackRef, "y", {
214
140
  x: 0,
215
- y: normalizeHue(pickedColor.value.h, 'right')
216
- }, disabled)
217
-
141
+ y: normalizeHue(pickedColor.value.h, "right")
142
+ }, disabled);
218
143
  const { pause: pauseWatchColor, resume: resumeWatchColor } = watchPausable(pickedColor, (hsb) => {
219
144
  selectorThumbPosition.value = {
220
145
  x: hsb.s,
221
146
  y: normalizeBrightness(hsb.v)
222
- }
147
+ };
223
148
  trackThumbPosition.value = {
224
149
  x: 0,
225
- y: normalizeHue(hsb.h, 'right')
226
- }
227
- })
228
-
150
+ y: normalizeHue(hsb.h, "right")
151
+ };
152
+ });
229
153
  watchThrottled([selectorThumbPosition, trackThumbPosition], () => {
230
- pauseWatchColor()
231
-
154
+ pauseWatchColor();
232
155
  pickedColor.value = {
233
156
  h: normalizeHue(trackThumbPosition.value.y),
234
157
  s: selectorThumbPosition.value.x,
235
158
  v: normalizeBrightness(selectorThumbPosition.value.y)
236
- }
237
-
238
- nextTick(resumeWatchColor)
239
- }, { throttle: () => props.throttle })
240
-
159
+ };
160
+ nextTick(resumeWatchColor);
161
+ }, { throttle: () => props.throttle });
241
162
  const trackThumbColor = computed(() => new ColorTranslator(HSVtoHSL({
242
163
  h: normalizeHue(trackThumbPosition.value.y),
243
164
  s: 100,
244
165
  v: 100
245
- })).HEX)
246
-
166
+ })).HEX);
247
167
  const selectorStyle = computed(() => ({
248
168
  backgroundColor: trackThumbColor.value
249
- }))
250
-
169
+ }));
251
170
  const selectorThumbStyle = computed(() => ({
252
171
  backgroundColor: new ColorTranslator(modelValue.value || props.defaultValue).HEX,
253
172
  left: `${selectorThumbPosition.value.x}%`,
254
173
  top: `${selectorThumbPosition.value.y}%`
255
- }))
256
-
174
+ }));
257
175
  const trackThumbStyle = computed(() => ({
258
176
  backgroundColor: trackThumbColor.value,
259
177
  top: `${trackThumbPosition.value.y}%`
260
- }))
261
-
262
- const ui = computed(() => colorPicker({
263
- size: props.size
264
- }))
178
+ }));
265
179
  </script>
266
180
 
267
181
  <template>
268
- <Primitive :as="as" :class="ui.root({ class: [props.class, props.ui?.root] })" :data-disabled="disabled ? true : undefined">
182
+ <Primitive :as="as" :class="ui.root({ class: [props.class, props.ui?.root] })" :data-disabled="disabled ? true : void 0">
269
183
  <div :class="ui.picker({ class: props.ui?.picker })">
270
184
  <div
271
185
  ref="selectorRef"
@@ -277,7 +191,7 @@ const ui = computed(() => colorPicker({
277
191
  ref="selectorThumbRef"
278
192
  :class="ui.selectorThumb({ class: props.ui?.selectorThumb })"
279
193
  :style="selectorThumbStyle"
280
- :data-disabled="disabled ? true : undefined"
194
+ :data-disabled="disabled ? true : void 0"
281
195
  />
282
196
  </div>
283
197
  </div>
@@ -290,7 +204,7 @@ const ui = computed(() => colorPicker({
290
204
  ref="trackThumbRef"
291
205
  :class="ui.trackThumb({ class: props.ui?.trackThumb })"
292
206
  :style="trackThumbStyle"
293
- :data-disabled="disabled ? true : undefined"
207
+ :data-disabled="disabled ? true : void 0"
294
208
  />
295
209
  </div>
296
210
  </div>
@@ -0,0 +1,63 @@
1
+ import type { AppConfig } from '@nuxt/schema';
2
+ import theme from '#build/ui/color-picker';
3
+ import type { ComponentConfig } from '../types/utils';
4
+ type ColorPicker = ComponentConfig<typeof theme, AppConfig, 'colorPicker'>;
5
+ export type ColorPickerProps = {
6
+ /**
7
+ * The element or component this component should render as.
8
+ * @defaultValue 'div'
9
+ */
10
+ as?: any;
11
+ /**
12
+ * Throttle time in ms for the color picker
13
+ */
14
+ throttle?: number;
15
+ /**
16
+ * Disable the color picker
17
+ */
18
+ disabled?: boolean;
19
+ /**
20
+ * The default value of the color picker
21
+ */
22
+ defaultValue?: string;
23
+ /**
24
+ * Format of the color
25
+ * @defaultValue 'hex'
26
+ */
27
+ format?: 'hex' | 'rgb' | 'hsl' | 'cmyk' | 'lab';
28
+ /**
29
+ * @defaultValue 'md'
30
+ */
31
+ size?: ColorPicker['variants']['size'];
32
+ class?: any;
33
+ ui?: ColorPicker['slots'];
34
+ };
35
+ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<{
36
+ modelValue?: string;
37
+ } & ColorPickerProps>, {
38
+ format: string;
39
+ throttle: number;
40
+ defaultValue: string;
41
+ }>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, any, string, import("vue").PublicProps, any, {
42
+ format: "hex" | "rgb" | "hsl" | "cmyk" | "lab";
43
+ defaultValue: string;
44
+ throttle: number;
45
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
46
+ export default _default;
47
+ type __VLS_WithDefaults<P, D> = {
48
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_PrettifyLocal<P[K] & {
49
+ default: D[K];
50
+ }> : P[K];
51
+ };
52
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
53
+ type __VLS_TypePropsToOption<T> = {
54
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
55
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
56
+ } : {
57
+ type: import('vue').PropType<T[K]>;
58
+ required: true;
59
+ };
60
+ };
61
+ type __VLS_PrettifyLocal<T> = {
62
+ [K in keyof T]: T[K];
63
+ } & {};