@witchcraft/ui 0.2.1-beta.3 → 0.2.2

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 (203) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +20 -4
  3. package/dist/runtime/build/WitchcraftUiResolver.d.ts +2 -2
  4. package/dist/runtime/build/generateTheme.js +2 -2
  5. package/dist/runtime/components/Aria/Aria.d.vue.ts +5 -0
  6. package/dist/runtime/components/Aria/Aria.vue +4 -2
  7. package/dist/runtime/components/Aria/Aria.vue.d.ts +1 -1
  8. package/dist/runtime/components/Icon/Icon.d.vue.ts +21 -0
  9. package/dist/runtime/components/Icon/Icon.vue +3 -3
  10. package/dist/runtime/components/Icon/Icon.vue.d.ts +1 -1
  11. package/dist/runtime/components/LibButton/LibButton.d.vue.ts +36 -0
  12. package/dist/runtime/components/LibButton/LibButton.vue +9 -4
  13. package/dist/runtime/components/LibButton/LibButton.vue.d.ts +1 -1
  14. package/dist/runtime/components/LibCheckbox/LibCheckbox.d.vue.ts +42 -0
  15. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +3 -4
  16. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +1 -1
  17. package/dist/runtime/components/LibColorInput/LibColorInput.d.vue.ts +63 -0
  18. package/dist/runtime/components/LibColorInput/LibColorInput.vue +15 -8
  19. package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +1 -1
  20. package/dist/runtime/components/LibColorPicker/LibColorPicker.d.vue.ts +61 -0
  21. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +10 -6
  22. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +1 -1
  23. package/dist/runtime/components/LibColorPicker/utils/truncate.js +1 -1
  24. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.d.vue.ts +22 -0
  25. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +5 -2
  26. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +1 -1
  27. package/dist/runtime/components/LibDatePicker/LibDatePicker.d.vue.ts +40 -0
  28. package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +1 -1
  29. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.d.vue.ts +34 -0
  30. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +8 -6
  31. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +1 -1
  32. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.d.vue.ts +34 -0
  33. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +7 -5
  34. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +1 -1
  35. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.d.vue.ts +22 -0
  36. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +1 -1
  37. package/dist/runtime/components/LibDebug/LibDebug.d.vue.ts +32 -0
  38. package/dist/runtime/components/LibDebug/LibDebug.vue +9 -4
  39. package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +1 -1
  40. package/dist/runtime/components/LibDevOnly/LibDevOnly.d.vue.ts +25 -0
  41. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +2 -1
  42. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +4 -1
  43. package/dist/runtime/components/LibFileInput/LibFileInput.d.vue.ts +43 -0
  44. package/dist/runtime/components/LibFileInput/LibFileInput.vue +29 -13
  45. package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +2 -2
  46. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.d.vue.ts +165 -0
  47. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +42 -12
  48. package/dist/runtime/components/LibLabel/LibLabel.d.vue.ts +26 -0
  49. package/dist/runtime/components/LibLabel/LibLabel.vue +2 -2
  50. package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +3 -3
  51. package/dist/runtime/components/LibMultiValues/LibMultiValues.d.vue.ts +29 -0
  52. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +1 -2
  53. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +2 -2
  54. package/dist/runtime/components/LibNotifications/LibNotification.d.vue.ts +17 -0
  55. package/dist/runtime/components/LibNotifications/LibNotification.vue +19 -8
  56. package/dist/runtime/components/LibNotifications/LibNotifications.d.vue.ts +13 -0
  57. package/dist/runtime/components/LibNotifications/LibNotifications.vue +10 -6
  58. package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +2 -2
  59. package/dist/runtime/components/LibPagination/LibPagination.d.vue.ts +104 -0
  60. package/dist/runtime/components/LibPagination/LibPagination.vue +25 -12
  61. package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +2 -2
  62. package/dist/runtime/components/LibPalette/LibPalette.d.vue.ts +14 -0
  63. package/dist/runtime/components/LibPalette/LibPalette.vue +6 -5
  64. package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +5 -5
  65. package/dist/runtime/components/LibPopup/LibPopup.d.vue.ts +46 -0
  66. package/dist/runtime/components/LibPopup/LibPopup.vue +6 -4
  67. package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +3 -3
  68. package/dist/runtime/components/LibProgressBar/LibProgressBar.d.vue.ts +41 -0
  69. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +5 -3
  70. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +9 -9
  71. package/dist/runtime/components/LibRecorder/LibRecorder.d.vue.ts +77 -0
  72. package/dist/runtime/components/LibRecorder/LibRecorder.vue +1 -1
  73. package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +2 -2
  74. package/dist/runtime/components/LibRoot/LibRoot.d.vue.ts +41 -0
  75. package/dist/runtime/components/LibRoot/LibRoot.vue +11 -6
  76. package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +1 -1
  77. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.d.vue.ts +35 -0
  78. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +1 -1
  79. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +1 -1
  80. package/dist/runtime/components/LibSuggestions/LibSuggestions.d.vue.ts +94 -0
  81. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +6 -4
  82. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +1 -1
  83. package/dist/runtime/components/LibTable/LibTable.d.vue.ts +45 -0
  84. package/dist/runtime/components/LibTable/LibTable.vue +23 -8
  85. package/dist/runtime/components/LibTable/LibTable.vue.d.ts +1 -1
  86. package/dist/runtime/components/Template/NAME.d.vue.ts +17 -0
  87. package/dist/runtime/components/Template/NAME.vue +2 -3
  88. package/dist/runtime/components/Template/NAME.vue.d.ts +1 -1
  89. package/dist/runtime/components/TestControls/TestControls.d.vue.ts +5 -0
  90. package/dist/runtime/components/TestControls/TestControls.vue +4 -2
  91. package/dist/runtime/components/TestControls/TestControls.vue.d.ts +1 -1
  92. package/dist/runtime/composables/useDragWithThreshold.d.ts +1 -1
  93. package/dist/runtime/composables/useInjectedI18n.d.ts +1 -1
  94. package/dist/runtime/composables/useScrollNearContainerEdges.d.ts +1 -1
  95. package/dist/runtime/composables/useSetupI18n.d.ts +1 -1
  96. package/dist/runtime/composables/useSuggestions.d.ts +2 -2
  97. package/dist/runtime/helpers/NotificationHandler.d.ts +1 -1
  98. package/dist/runtime/helpers/base64ToImg.js +2 -2
  99. package/dist/runtime/tailwind/themeConvertionOpts.d.ts +1 -1
  100. package/dist/runtime/types/index.d.ts +1 -1
  101. package/dist/runtime/utils/notifyIfError.d.ts +1 -1
  102. package/package.json +9 -10
  103. package/src/module.ts +41 -33
  104. package/src/runtime/build/WitchcraftUiResolver.ts +3 -3
  105. package/src/runtime/build/generateTheme.ts +3 -2
  106. package/src/runtime/build/unpluginIconViteOptions.ts +1 -1
  107. package/src/runtime/components/Aria/Aria.vue +5 -6
  108. package/src/runtime/components/Focus.stories.ts +11 -12
  109. package/src/runtime/components/Icon/Icon.vue +5 -9
  110. package/src/runtime/components/LibButton/LibButton.stories.ts +21 -22
  111. package/src/runtime/components/LibButton/LibButton.vue +23 -21
  112. package/src/runtime/components/LibCheckbox/LibCheckbox.stories.ts +6 -10
  113. package/src/runtime/components/LibCheckbox/LibCheckbox.vue +17 -19
  114. package/src/runtime/components/LibColorInput/LibColorInput.stories.ts +8 -13
  115. package/src/runtime/components/LibColorInput/LibColorInput.vue +49 -45
  116. package/src/runtime/components/LibColorPicker/LibColorPicker.stories.ts +14 -18
  117. package/src/runtime/components/LibColorPicker/LibColorPicker.vue +50 -52
  118. package/src/runtime/components/LibColorPicker/utils/safeConvertToHsva.ts +1 -2
  119. package/src/runtime/components/LibColorPicker/utils/safeConvertToRgba.ts +1 -2
  120. package/src/runtime/components/LibColorPicker/utils/truncate.ts +1 -2
  121. package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.ts +5 -8
  122. package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +11 -9
  123. package/src/runtime/components/LibDatePicker/LibDatePicker.stories.ts +14 -15
  124. package/src/runtime/components/LibDatePicker/LibDatePicker.vue +1 -2
  125. package/src/runtime/components/LibDatePicker/LibRangeDatePicker.vue +13 -13
  126. package/src/runtime/components/LibDatePicker/LibSingleDatePicker.vue +9 -8
  127. package/src/runtime/components/LibDatePicker/LibTimeZonePicker.vue +2 -1
  128. package/src/runtime/components/LibDatePicker/helpers.ts +0 -2
  129. package/src/runtime/components/LibDebug/LibDebug.stories.ts +11 -15
  130. package/src/runtime/components/LibDebug/LibDebug.vue +14 -11
  131. package/src/runtime/components/LibDevOnly/LibDevOnly.vue +8 -4
  132. package/src/runtime/components/LibFileInput/LibFileInput.stories.ts +12 -15
  133. package/src/runtime/components/LibFileInput/LibFileInput.vue +65 -47
  134. package/src/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.ts +77 -84
  135. package/src/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +73 -48
  136. package/src/runtime/components/LibLabel/LibLabel.stories.ts +4 -8
  137. package/src/runtime/components/LibLabel/LibLabel.vue +8 -8
  138. package/src/runtime/components/LibMultiValues/LibMultiValues.stories.ts +10 -15
  139. package/src/runtime/components/LibMultiValues/LibMultiValues.vue +14 -18
  140. package/src/runtime/components/LibNotifications/LibNotification.stories.ts +30 -34
  141. package/src/runtime/components/LibNotifications/LibNotification.vue +27 -17
  142. package/src/runtime/components/LibNotifications/LibNotifications.stories.ts +11 -15
  143. package/src/runtime/components/LibNotifications/LibNotifications.vue +21 -16
  144. package/src/runtime/components/LibPagination/LibPagination.stories.ts +5 -9
  145. package/src/runtime/components/LibPagination/LibPagination.vue +46 -32
  146. package/src/runtime/components/LibPalette/LibPalette.stories.ts +3 -7
  147. package/src/runtime/components/LibPalette/LibPalette.vue +13 -12
  148. package/src/runtime/components/LibPopup/LibPopup.stories.ts +19 -23
  149. package/src/runtime/components/LibPopup/LibPopup.vue +31 -35
  150. package/src/runtime/components/LibProgressBar/LibProgressBar.stories.ts +13 -17
  151. package/src/runtime/components/LibProgressBar/LibProgressBar.vue +36 -33
  152. package/src/runtime/components/LibRecorder/LibRecorder.stories.ts +11 -12
  153. package/src/runtime/components/LibRecorder/LibRecorder.vue +34 -34
  154. package/src/runtime/components/LibRoot/LibRoot.vue +16 -12
  155. package/src/runtime/components/LibSimpleInput/LibSimpleInput.stories.ts +20 -24
  156. package/src/runtime/components/LibSimpleInput/LibSimpleInput.vue +17 -21
  157. package/src/runtime/components/LibSuggestions/LibSuggestions.stories.ts +16 -19
  158. package/src/runtime/components/LibSuggestions/LibSuggestions.vue +28 -30
  159. package/src/runtime/components/LibTable/LibTable.stories.ts +30 -33
  160. package/src/runtime/components/LibTable/LibTable.vue +38 -24
  161. package/src/runtime/components/Reset.stories.ts +3 -6
  162. package/src/runtime/components/Scrolling.stories.ts +5 -8
  163. package/src/runtime/components/Template/NAME.vue +11 -11
  164. package/src/runtime/components/Template/TemplateStory.ts +9 -10
  165. package/src/runtime/components/TestControls/TestControls.vue +5 -5
  166. package/src/runtime/components/shared/props.ts +4 -6
  167. package/src/runtime/components/shared/storyHelpers/playInput.ts +2 -3
  168. package/src/runtime/components/shared/storyHelpers/playSuggestions.ts +5 -9
  169. package/src/runtime/composables/useAccesibilityOutline.ts +1 -1
  170. package/src/runtime/composables/useAriaLabel.ts +1 -1
  171. package/src/runtime/composables/useDarkMode.ts +15 -19
  172. package/src/runtime/composables/useDragWithThreshold.ts +6 -8
  173. package/src/runtime/composables/useGlobalResizeObserver.ts +0 -1
  174. package/src/runtime/composables/useInjectedDarkMode.ts +2 -2
  175. package/src/runtime/composables/useInjectedI18n.ts +1 -1
  176. package/src/runtime/composables/useInjectedLocale.ts +3 -4
  177. package/src/runtime/composables/useScrollNearContainerEdges.stories.ts +4 -4
  178. package/src/runtime/composables/useScrollNearContainerEdges.ts +12 -13
  179. package/src/runtime/composables/useSetupI18n.ts +4 -7
  180. package/src/runtime/composables/useSetupLocale.ts +3 -5
  181. package/src/runtime/composables/useSuggestions.ts +25 -30
  182. package/src/runtime/directives/vDetectFlex.ts +5 -8
  183. package/src/runtime/directives/vExtractRootEl.ts +1 -1
  184. package/src/runtime/directives/vResizableCols.ts +3 -7
  185. package/src/runtime/directives/vResizeObserver.ts +1 -2
  186. package/src/runtime/globalResizeObserver.ts +0 -1
  187. package/src/runtime/helpers/NotificationHandler.ts +8 -12
  188. package/src/runtime/helpers/base64ToImg.ts +2 -3
  189. package/src/runtime/helpers/createNoonUtcDate.ts +0 -1
  190. package/src/runtime/helpers/defaultTranslationFunction.ts +0 -1
  191. package/src/runtime/helpers/getTimeZoneList.ts +0 -1
  192. package/src/runtime/helpers/readFile.ts +2 -2
  193. package/src/runtime/helpers/resizeObserverWrapper.ts +0 -1
  194. package/src/runtime/helpers/storybook.ts +2 -3
  195. package/src/runtime/main.lib.ts +0 -2
  196. package/src/runtime/nuxt/plugins/vue-plugin.ts +4 -5
  197. package/src/runtime/tailwind/themeConvertionOpts.ts +3 -4
  198. package/src/runtime/theme.ts +0 -1
  199. package/src/runtime/types/index.ts +3 -4
  200. package/src/runtime/utils/notifyIfError.ts +2 -2
  201. package/src/runtime/utils/twMerge.ts +2 -2
  202. package/src/runtime/vue/VueComponentsPlugin.ts +1 -2
  203. package/src/runtime/vue/registerComponents.ts +0 -1
@@ -60,37 +60,36 @@
60
60
  :disabled="disabled"
61
61
  ref="inputEl"
62
62
  v-model="$value"
63
- v-bind="{...$.attrs, class: undefined}"
63
+ v-bind="{ ...$.attrs, class: undefined }"
64
64
  >
65
65
  <slot/> {{ label }}
66
66
  </label>
67
67
  </div>
68
68
  </template>
69
+
69
70
  <script setup lang="ts">
70
- import { type HTMLAttributes, type InputHTMLAttributes,ref, useSlots } from "vue"
71
+ import { type HTMLAttributes, type InputHTMLAttributes, ref } from "vue"
71
72
 
72
73
  import { useDivideAttrs } from "../../composables/useDivideAttrs.js"
73
74
  import { usePreHydrationValue } from "../../composables/usePreHydrationValue.js"
74
75
  import { twMerge } from "../../utils/twMerge.js"
75
- import { type BaseInteractiveProps, getFallbackId,type LabelProps, type LinkableByIdProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js"
76
+ import { type BaseInteractiveProps, getFallbackId, type LabelProps, type LinkableByIdProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js"
76
77
 
77
78
  defineOptions({
78
- name: "lib-checkbox",
79
- inheritAttrs: false,
79
+ name: "LibCheckbox",
80
+ inheritAttrs: false
80
81
  })
81
82
 
82
83
  const $ = useDivideAttrs(["label", "wrapper"])
83
- const $slots = useSlots()
84
84
  /* todo multi states */
85
85
 
86
86
  const fallbackId = getFallbackId()
87
87
  const props = withDefaults(defineProps<Props>(), {
88
- unstyle: false, disabled: false, readonly: false, border: true,
88
+ unstyle: false, disabled: false, readonly: false, border: true
89
89
  })
90
90
 
91
-
92
- const emits = defineEmits<{
93
- /* User presses enter.*/
91
+ /* const emits = */defineEmits<{
92
+ /* User presses enter. */
94
93
  (e: "submit", val: boolean): void
95
94
  }>()
96
95
 
@@ -102,20 +101,19 @@ usePreHydrationValue(props.id ?? fallbackId, $value)
102
101
  </script>
103
102
 
104
103
  <script lang="ts">
105
-
106
- type WrapperTypes = Partial<WrapperProps<"label",HTMLAttributes, {
104
+ type WrapperTypes = Partial<WrapperProps<"label", HTMLAttributes, {
107
105
  /** Tailwind classes. */
108
106
  class?: string
109
107
  }>>
110
108
 
111
- type RealProps =
109
+ type RealProps
112
110
 
113
- & LinkableByIdProps
114
- & LabelProps
115
- & BaseInteractiveProps
116
- & {
117
- unstyle?: boolean
118
- }
111
+ = & LinkableByIdProps
112
+ & LabelProps
113
+ & BaseInteractiveProps
114
+ & {
115
+ unstyle?: boolean
116
+ }
119
117
 
120
118
  interface Props
121
119
  extends
@@ -4,22 +4,19 @@ import { ref } from "vue"
4
4
 
5
5
  import LibColorInput from "./LibColorInput.vue"
6
6
 
7
- // eslint-disable-next-line @typescript-eslint/no-restricted-imports
8
7
  import * as components from "../index.js"
9
8
 
10
-
11
9
  const meta: Meta<typeof LibColorInput> = {
12
10
  component: LibColorInput,
13
11
  title: "Components/ColorInput",
14
12
  args: {
15
-
16
- },
13
+
14
+ }
17
15
  }
18
16
 
19
17
  export default meta
20
18
  type Story = StoryObj<typeof LibColorInput>
21
19
 
22
-
23
20
  export const Primary: Story = {
24
21
  render: args => ({
25
22
  components,
@@ -33,9 +30,9 @@ export const Primary: Story = {
33
30
  outline: false,
34
31
  color,
35
32
  allowAlpha: true,
36
- ...args,
33
+ ...args
37
34
  },
38
- handleChange,
35
+ handleChange
39
36
  }
40
37
  },
41
38
  template: `
@@ -55,15 +52,13 @@ export const Primary: Story = {
55
52
  >
56
53
  </lib-color-Input>
57
54
  </div>
58
- `,
59
- }),
55
+ `
56
+ })
60
57
  }
61
58
 
62
-
63
59
  export const DoesNotAllowAlpha: Story = {
64
60
  ...Primary,
65
61
  args: {
66
- allowAlpha: false,
67
- },
62
+ allowAlpha: false
63
+ }
68
64
  }
69
-
@@ -4,7 +4,7 @@
4
4
  v-model="showPopup"
5
5
  @close="$tempValue = undefined;emit('cancel')"
6
6
  >
7
- <template #button="{extractEl}">
7
+ <template #button="{ extractEl }">
8
8
  <!-- <div -->
9
9
  <!-- class=" -->
10
10
  <!-- flex -->
@@ -13,7 +13,7 @@
13
13
  <!-- " -->
14
14
  <!-- v-extract-root-el="extractEl" -->
15
15
  <!-- > -->
16
-
16
+
17
17
  <!-- -->
18
18
  <lib-button
19
19
  :id="id ?? fallbackId"
@@ -31,28 +31,31 @@
31
31
  )"
32
32
  :aria-label="t('color-input.aria-and-title-prefix') + stringColor"
33
33
  :title="t('color-input.aria-and-title-prefix') + stringColor"
34
- v-bind="{...$attrs, class: undefined}"
34
+ v-bind="{ ...$attrs, class: undefined }"
35
35
  v-extract-root-el="extractEl"
36
36
  @click="togglePopup"
37
37
  >
38
38
  <template #label>
39
- <div class="
39
+ <div
40
+ class="
40
41
  color-input--swatch-wrapper
41
42
  flex
42
43
  w-full
43
44
  "
44
45
  >
45
- <slot v-bind="{stringColor, classes:swatchClasses}">
46
- <div :class="swatchClasses"
46
+ <slot v-bind="{ stringColor, classes: swatchClasses }">
47
+ <div
48
+ :class="swatchClasses"
47
49
  :style="`background:${stringColor}`"
48
50
  />
49
51
  </slot>
50
52
  <slot
51
53
  v-if="$tempValue"
52
- v-bind="{tempStringColor, classes:swatchClasses}"
54
+ v-bind="{ tempStringColor, classes: swatchClasses }"
53
55
  name="temp"
54
56
  >
55
- <div :class="swatchClasses"
57
+ <div
58
+ :class="swatchClasses"
56
59
  :style="`background:${tempStringColor}`"
57
60
  />
58
61
  </slot>
@@ -60,9 +63,13 @@
60
63
  </template>
61
64
  </lib-button>
62
65
  </template>
63
- <template #popup="{extractEl}">
64
- <div class="color-input--popup-wrapper p-5" v-extract-root-el="extractEl">
65
- <lib-color-picker v-if="showPopup"
66
+ <template #popup="{ extractEl }">
67
+ <div
68
+ class="color-input--popup-wrapper p-5"
69
+ v-extract-root-el="extractEl"
70
+ >
71
+ <lib-color-picker
72
+ v-if="showPopup"
66
73
  :id="id ?? fallbackId"
67
74
  :allow-alpha="allowAlpha"
68
75
  :custom-representation="customRepresentation"
@@ -79,7 +86,7 @@
79
86
 
80
87
  <script setup lang="ts">
81
88
  import Color from "colorjs.io"
82
- import { type ButtonHTMLAttributes,computed, type PropType, ref, useAttrs } from "vue"
89
+ import { type ButtonHTMLAttributes, computed, ref, useAttrs } from "vue"
83
90
 
84
91
  import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
85
92
  import { vExtractRootEl } from "../../directives/vExtractRootEl.js"
@@ -90,9 +97,8 @@ import LibColorPicker from "../LibColorPicker/LibColorPicker.vue"
90
97
  import LibPopup from "../LibPopup/LibPopup.vue"
91
98
  import { getFallbackId, type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js"
92
99
 
93
-
94
100
  defineOptions({
95
- name: "lib-color-input",
101
+ name: "LibColorInput"
96
102
  })
97
103
 
98
104
  const swatchClasses = `
@@ -111,19 +117,18 @@ const swatchClasses = `
111
117
  const fallbackId = getFallbackId()
112
118
 
113
119
  const t = useInjectedI18n()
114
- const props = withDefaults(defineProps<Props>(), {
120
+ /* const props = */withDefaults(defineProps<Props>(), {
115
121
  allowAlpha: true,
116
122
  border: true,
117
123
  copyTransform: (_val: HsvaColor, stringVal: string) => stringVal,
118
124
  stringPrecision: 3,
119
- customRepresentation: undefined,
125
+ customRepresentation: undefined
120
126
  })
121
127
  const emit = defineEmits<{
122
128
  (e: "save"): void
123
129
  (e: "cancel"): void
124
130
  }>()
125
131
 
126
-
127
132
  function save() {
128
133
  $value.value = internalTempValue.value
129
134
  showPopup.value = false
@@ -137,63 +142,62 @@ function cancel() {
137
142
  }
138
143
 
139
144
  const $attrs = useAttrs()
140
-
145
+
141
146
  const $value = defineModel<RgbaColor>({ required: false, default: () => ({ r: 0, g: 0, b: 0 }) })
142
147
  const $tempValue = defineModel<RgbaColor | undefined>("tempValue", { required: false, default: () => (undefined) })
143
148
 
144
149
  const stringColor = computed(() => new Color("srgb", [
145
150
  $value.value.r / 255,
146
151
  $value.value.g / 255,
147
- $value.value.b / 255,
148
- ], $value.value.a ?? 1,).toString())
152
+ $value.value.b / 255
153
+ ], $value.value.a ?? 1).toString())
149
154
 
150
- const tempStringColor = computed(() => $tempValue.value ? new Color("srgb", [
151
- $tempValue.value.r / 255,
152
- $tempValue.value.g / 255,
153
- $tempValue.value.b / 255,
154
- ], $tempValue.value.a ?? 1,).toString() : "")
155
+ const tempStringColor = computed(() => $tempValue.value
156
+ ? new Color("srgb", [
157
+ $tempValue.value.r / 255,
158
+ $tempValue.value.g / 255,
159
+ $tempValue.value.b / 255
160
+ ], $tempValue.value.a ?? 1).toString()
161
+ : "")
155
162
 
156
163
  const internalTempValue = ref({ ...$value.value })
157
164
 
158
165
  const showPopup = ref(false)
159
166
 
160
-
161
167
  const togglePopup = (): void => {
162
168
  if (showPopup.value) {
163
169
  $value.value = internalTempValue.value
164
170
  }
165
171
  showPopup.value = !showPopup.value
166
172
  }
167
-
168
173
  </script>
169
174
 
170
175
  <script lang="ts">
171
-
172
- type RealProps =
173
- & LabelProps
174
- & LinkableByIdProps
175
- & {
176
- allowAlpha?: boolean
177
- border?: boolean
178
- /** See ColorPicker.copyTransform */
179
- copyTransform?: (val: HsvaColor, stringVal: string) => any
180
- /** See ColorPicker.allowAlpha */
181
- stringPrecision?: number
182
- /** See ColorPicker.customRepresentation */
183
- customRepresentation?: {
184
- fromHsvaToString: (hsva: HsvaColor, includeAlpha: boolean) => string
185
- }
186
- }
176
+ type RealProps
177
+ = & LabelProps
178
+ & LinkableByIdProps
179
+ & {
180
+ allowAlpha?: boolean
181
+ border?: boolean
182
+ /** See ColorPicker.copyTransform */
183
+ copyTransform?: (val: HsvaColor, stringVal: string) => any
184
+ /** See ColorPicker.allowAlpha */
185
+ stringPrecision?: number
186
+ /** See ColorPicker.customRepresentation */
187
+ customRepresentation?: {
188
+ fromHsvaToString: (hsva: HsvaColor, includeAlpha: boolean) => string
189
+ }
190
+ }
187
191
  interface Props
188
192
  extends
189
193
  /** @vue-ignore */
190
- Partial<Omit<ButtonHTMLAttributes,"class">
194
+ Partial<Omit<ButtonHTMLAttributes, "class">
191
195
  & TailwindClassProp
192
196
  & {
193
197
  // why is this not already a part of button?
198
+ // eslint-disable-next-line @typescript-eslint/naming-convention
194
199
  "aria-label": string
195
200
  }>,
196
201
  RealProps
197
202
  {}
198
203
  </script>
199
-
@@ -5,22 +5,19 @@ import { ref } from "vue"
5
5
 
6
6
  import LibColorPicker from "./LibColorPicker.vue"
7
7
 
8
- // eslint-disable-next-line @typescript-eslint/no-restricted-imports
9
8
  import * as components from "../index.js"
10
9
 
11
-
12
10
  const meta: Meta<typeof LibColorPicker> = {
13
11
  component: LibColorPicker,
14
12
  title: "Components/ColorPicker",
15
13
  args: {
16
-
17
- },
14
+
15
+ }
18
16
  }
19
17
 
20
18
  export default meta
21
19
  type Story = StoryObj<typeof LibColorPicker>
22
20
 
23
-
24
21
  export const Primary: Story = {
25
22
  render: args => ({
26
23
  components,
@@ -35,9 +32,9 @@ export const Primary: Story = {
35
32
  outline: false,
36
33
  color,
37
34
  allowAlpha: true,
38
- ...args,
35
+ ...args
39
36
  },
40
- handleChange,
37
+ handleChange
41
38
  }
42
39
  },
43
40
  template: `
@@ -50,20 +47,20 @@ export const Primary: Story = {
50
47
  >
51
48
  </lib-color-picker>
52
49
  </lib-root>
53
- `,
54
- }),
50
+ `
51
+ })
55
52
  }
56
53
  export const DoesNotAllowAlpha: Story = {
57
54
  ...Primary,
58
55
  args: {
59
- allowAlpha: false,
60
- },
56
+ allowAlpha: false
57
+ }
61
58
  }
62
59
  export const WithExistingValue: Story = {
63
60
  ...Primary,
64
61
  args: {
65
- modelValue: { r: 255, g: 0, b: 0 },
66
- },
62
+ modelValue: { r: 255, g: 0, b: 0 }
63
+ }
67
64
  }
68
65
  export const CustomStringRepresentation: Story = {
69
66
  ...Primary,
@@ -73,9 +70,8 @@ export const CustomStringRepresentation: Story = {
73
70
  fromHsvaToString: (hsva: any, includeAlpha: boolean) => new Color(
74
71
  "hsv",
75
72
  [hsva.h, hsva.s, hsva.v],
76
- includeAlpha ? hsva.a : 1 // this takes care of the correct hex format
77
- ).toString({ format: "hex" }),
78
- },
79
- },
73
+ includeAlpha ? hsva.a : 1 // this takes care of the correct hex format
74
+ ).toString({ format: "hex" })
75
+ }
76
+ }
80
77
  }
81
-
@@ -113,7 +113,8 @@
113
113
  />
114
114
  </div>
115
115
  <div class="color-picker--footer flex w-full flex-1 gap-2">
116
- <div class=" color-picker--preview-wrapper
116
+ <div
117
+ class=" color-picker--preview-wrapper
117
118
  bg-transparency-squares
118
119
  relative
119
120
  aspect-square
@@ -122,7 +123,8 @@
122
123
  shadow-xs
123
124
  "
124
125
  >
125
- <div class="
126
+ <div
127
+ class="
126
128
  color-picker--footer--preview
127
129
  size-full
128
130
  rounded-full
@@ -143,7 +145,11 @@
143
145
  @input="parseInput"
144
146
  @blur="onBlurFixInvalidValue"
145
147
  />
146
- <lib-button class="color-picker--copy-button" :aria-label="t('copy')" @click="copy(copyTransform?.(localColor.val, localColorString) ?? localColorString)">
148
+ <lib-button
149
+ class="color-picker--copy-button"
150
+ :aria-label="t('copy')"
151
+ @click="copy(copyTransform?.(localColor.val, localColorString) ?? localColorString)"
152
+ >
147
153
  <icon><i-fa6-regular-copy/></icon>
148
154
  </lib-button>
149
155
  </slot>
@@ -171,11 +177,10 @@
171
177
  <script setup lang="ts">
172
178
  /* todo change to colorjsio for less dependencies */
173
179
  import { castType } from "@alanscodelog/utils/castType"
174
- import { clampNumber } from "@alanscodelog/utils/clampNumber"
175
180
  import { isArray } from "@alanscodelog/utils/isArray"
176
181
  import { unreachable } from "@alanscodelog/utils/unreachable"
177
182
  import Color from "colorjs.io"
178
- import { computed, onMounted, reactive, type Ref, ref, type UnwrapRef,useAttrs, watch } from "vue"
183
+ import { computed, onMounted, reactive, type Ref, ref, type UnwrapRef, useAttrs, watch } from "vue"
179
184
 
180
185
  import { safeConvertToHsva } from "./utils/safeConvertToHsva.js"
181
186
  import { safeConvertToRgba } from "./utils/safeConvertToRgba.js"
@@ -187,14 +192,13 @@ import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
187
192
  import { copy } from "../../helpers/copy.js"
188
193
  import type { HsvaColor, RgbaColor } from "../../types/index.js"
189
194
  import { twMerge } from "../../utils/twMerge.js"
190
- import aria from "../Aria/Aria.vue"
191
195
  import Icon from "../Icon/Icon.vue"
192
196
  import LibButton from "../LibButton/LibButton.vue"
193
197
  import LibSimpleInput from "../LibSimpleInput/LibSimpleInput.vue"
194
- import { getFallbackId, type LabelProps , type LinkableByIdProps } from "../shared/props.js"
198
+ import { getFallbackId, type LabelProps, type LinkableByIdProps } from "../shared/props.js"
195
199
 
196
200
  defineOptions({
197
- name: "lib-color-picker",
201
+ name: "LibColorPicker"
198
202
  })
199
203
 
200
204
  const $attrs = useAttrs()
@@ -231,37 +235,36 @@ const emits = defineEmits<{
231
235
  }>()
232
236
 
233
237
  const props = withDefaults(defineProps<
234
- LabelProps
235
- & LinkableByIdProps
236
- & {
237
- allowAlpha?: boolean
238
- /**
239
- * The precision of the rgba string representation of the color. Defaults to 3. Extra trailing zeros are removed for a prettier number.
240
- *
241
- * Does not affect the number saved unless the user manually edits the color.
242
- *
243
- * Ignored if `customRepresentation` is set.
244
- */
245
- stringPrecision?: number
246
- /** Allows overriding the string representation of the color. Useful for using a different representation than rgba (e.g. hex). The fromStringToHsva part is rarely needed as the colorjs.io library can normally parse the color. Returning undefined signals an error. */
247
- customRepresentation?: {
248
- fromHsvaToString: (hsva: HsvaColor, includeAlpha: boolean) => string
249
- fromStringToHsva?: (string: string) => HsvaColor | undefined
250
- }
251
- border?: boolean
252
- /** Modify what the user copies to the clipboard. */
253
- copyTransform?: (val: HsvaColor, stringVal: string) => any
254
- valid?: boolean
255
- }>(), {
238
+ LabelProps
239
+ & LinkableByIdProps
240
+ & {
241
+ allowAlpha?: boolean
242
+ /**
243
+ * The precision of the rgba string representation of the color. Defaults to 3. Extra trailing zeros are removed for a prettier number.
244
+ *
245
+ * Does not affect the number saved unless the user manually edits the color.
246
+ *
247
+ * Ignored if `customRepresentation` is set.
248
+ */
249
+ stringPrecision?: number
250
+ /** Allows overriding the string representation of the color. Useful for using a different representation than rgba (e.g. hex). The fromStringToHsva part is rarely needed as the colorjs.io library can normally parse the color. Returning undefined signals an error. */
251
+ customRepresentation?: {
252
+ fromHsvaToString: (hsva: HsvaColor, includeAlpha: boolean) => string
253
+ fromStringToHsva?: (string: string) => HsvaColor | undefined
254
+ }
255
+ border?: boolean
256
+ /** Modify what the user copies to the clipboard. */
257
+ copyTransform?: (val: HsvaColor, stringVal: string) => any
258
+ valid?: boolean
259
+ }>(), {
256
260
  allowAlpha: true,
257
261
  border: true,
258
262
  stringPrecision: 3,
259
263
  copyTransform: (_val: HsvaColor, stringVal: string) => stringVal,
260
264
  customRepresentation: undefined,
261
- valid: true,
265
+ valid: true
262
266
  })
263
267
 
264
-
265
268
  const ariaDescription = t("color-picker.aria.description")
266
269
  const fallbackId = getFallbackId()
267
270
 
@@ -284,32 +287,31 @@ const config: Config = {
284
287
  hue: {
285
288
  el: hueSliderEl as Ref<HTMLCanvasElement>,
286
289
  xKey: "h",
287
- xSteps: 360,
290
+ xSteps: 360
288
291
  },
289
292
  alpha: {
290
293
  el: alphaSliderEl as Ref<HTMLCanvasElement>,
291
294
  xSteps: 1,
292
- xKey: "a",
295
+ xKey: "a"
293
296
  },
294
297
  all: {
295
298
  el: pickerEl as Ref<HTMLCanvasElement>,
296
299
  xSteps: 100,
297
300
  ySteps: 100,
298
301
  xKey: "s",
299
- yKey: "v",
300
- },
302
+ yKey: "v"
303
+ }
301
304
  }
302
305
 
303
306
  const localColor = reactive<Record<"percent" | "val", HsvaColor>>({
304
307
  percent: {
305
- h: 0, s: 0, v: 0, a: 0,
308
+ h: 0, s: 0, v: 0, a: 0
306
309
  },
307
310
  val: {
308
- h: 0, s: 0, v: 0, a: 0,
309
- },
311
+ h: 0, s: 0, v: 0, a: 0
312
+ }
310
313
  })
311
314
 
312
-
313
315
  const asRgba = computed(() => {
314
316
  const rgba = safeConvertToRgba(localColor.val, props.allowAlpha)
315
317
  if (!rgba) unreachable()
@@ -347,7 +349,6 @@ function updatePicker(el: HTMLCanvasElement, hue: number): void {
347
349
  gradientColor.addColorStop(0, `hsla(${hue} 100% 50% / 0)`)
348
350
  gradientColor.addColorStop(1, `hsla(${hue} 100% 50% /1)`)
349
351
 
350
-
351
352
  ctx.fillStyle = gradient
352
353
  ctx.fillRect(0, 0, width, height)
353
354
  ctx.fillStyle = gradientColor
@@ -375,7 +376,6 @@ function updateSlider(el: HTMLCanvasElement, stops: ((i: number) => string) | st
375
376
  ctx.fillRect(0, 0, width, height)
376
377
  }
377
378
 
378
-
379
379
  function getVal(x: number, width: number, steps: number = 100, accuracy: number = 100, reverse = false): { val: number, percent: number } {
380
380
  const percent = (x / width)
381
381
  const unrounded = percent * steps
@@ -427,8 +427,8 @@ const slider = {
427
427
  const { x, y, width, height } = e.target.getBoundingClientRect()
428
428
  let xDiff = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0
429
429
  let yDiff = e.key === "ArrowUp" ? -1 : e.key === "ArrowDown" ? 1 : 0
430
- if (e.shiftKey) {xDiff *= 10}
431
- if (e.shiftKey) {yDiff *= 10}
430
+ if (e.shiftKey) { xDiff *= 10 }
431
+ if (e.shiftKey) { yDiff *= 10 }
432
432
  moveHandle({ clientX: x + (width / 2) + xDiff, clientY: y + (height / 2) + yDiff }, type)
433
433
  }
434
434
  if (e.key === "Enter") {
@@ -466,7 +466,7 @@ const slider = {
466
466
  elDragging.value = ""
467
467
  document.removeEventListener("pointermove", slider.pointermove)
468
468
  document.removeEventListener("pointerup", slider.pointerup)
469
- },
469
+ }
470
470
  }
471
471
  function updateSliders(_: HsvaColor): void {
472
472
  if (alphaSliderEl.value) {
@@ -486,12 +486,12 @@ function updateValueAndPosition(_: HsvaColor): void {
486
486
  localColor.percent.h = Math.round((_.h / 360) * 10000) / 100
487
487
  localColor.percent.s = _.s
488
488
  localColor.percent.v = 100 - _.v
489
- localColor.percent.a =
490
- props.allowAlpha
491
- ? _.a !== undefined
492
- ? _.a * 100
489
+ localColor.percent.a
490
+ = props.allowAlpha
491
+ ? _.a !== undefined
492
+ ? _.a * 100
493
+ : 1
493
494
  : 1
494
- : 1
495
495
  localColor.val = { ..._, a: props.allowAlpha ? _.a : 1 }
496
496
  }
497
497
 
@@ -511,7 +511,6 @@ function save(): void {
511
511
  emits("save", rgba)
512
512
  }
513
513
 
514
-
515
514
  function parseInput(e: Event): void {
516
515
  const val = (e.target as HTMLInputElement)?.value
517
516
  const converted = props.customRepresentation?.fromStringToHsva
@@ -523,7 +522,6 @@ function parseInput(e: Event): void {
523
522
  }
524
523
  }
525
524
 
526
-
527
525
  let disableUpdateTempValue = false
528
526
 
529
527
  onMounted(() => {
@@ -14,11 +14,10 @@ export function safeConvertToHsva(val: string | RgbaColor, allowAlpha: boolean):
14
14
  h: clampNumber(hsv[0] ?? 0, 0, Number.MAX_SAFE_INTEGER),
15
15
  s: clampNumber(hsv[1], 0, 100),
16
16
  v: clampNumber(hsv[2], 0, 100),
17
- a: clampNumber(allowAlpha ? color.alpha : 1, 0, 1),
17
+ a: clampNumber(allowAlpha ? color.alpha : 1, 0, 1)
18
18
  }
19
19
  return final
20
20
  } catch {
21
21
  return undefined
22
22
  }
23
23
  }
24
-
@@ -14,10 +14,9 @@ export function safeConvertToRgba(val: string | HsvaColor, allowAlpha: boolean):
14
14
  r: clampNumber(rgb[0] / 1 * 255, 0, 255),
15
15
  g: clampNumber(rgb[1] / 1 * 255, 0, 255),
16
16
  b: clampNumber(rgb[2] / 1 * 255, 0, 255),
17
- a: clampNumber(allowAlpha ? color.alpha : 1, 0, 1),
17
+ a: clampNumber(allowAlpha ? color.alpha : 1, 0, 1)
18
18
  }
19
19
  } catch {
20
20
  return undefined
21
21
  }
22
22
  }
23
-
@@ -1,6 +1,5 @@
1
1
  export function truncate(val: number, precision: number): string {
2
2
  const str = val.toFixed(precision)
3
- const float = parseFloat(str) // removes trailing zeros
3
+ const float = Number.parseFloat(str) // removes trailing zeros
4
4
  return float.toString()
5
5
  }
6
-