polymorph-ui-components 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.
Files changed (242) hide show
  1. package/README.md +354 -0
  2. package/dist/Accordion/Accordion.svelte +28 -0
  3. package/dist/Accordion/Accordion.svelte.d.ts +4 -0
  4. package/dist/Accordion/properties.d.ts +7 -0
  5. package/dist/Accordion/properties.js +1 -0
  6. package/dist/Animations/ModalAnimation.svelte +55 -0
  7. package/dist/Animations/ModalAnimation.svelte.d.ts +12 -0
  8. package/dist/Animations/OverlayAnimation.svelte +14 -0
  9. package/dist/Animations/OverlayAnimation.svelte.d.ts +7 -0
  10. package/dist/Avatar/Avatar.svelte +122 -0
  11. package/dist/Avatar/Avatar.svelte.d.ts +4 -0
  12. package/dist/Avatar/properties.d.ts +15 -0
  13. package/dist/Avatar/properties.js +1 -0
  14. package/dist/Badge/Badge.svelte +53 -0
  15. package/dist/Badge/Badge.svelte.d.ts +4 -0
  16. package/dist/Badge/properties.d.ts +6 -0
  17. package/dist/Badge/properties.js +1 -0
  18. package/dist/Banner/Banner.svelte +158 -0
  19. package/dist/Banner/Banner.svelte.d.ts +4 -0
  20. package/dist/Banner/properties.d.ts +19 -0
  21. package/dist/Banner/properties.js +1 -0
  22. package/dist/Book/Book.svelte +281 -0
  23. package/dist/Book/Book.svelte.d.ts +4 -0
  24. package/dist/Book/properties.d.ts +24 -0
  25. package/dist/Book/properties.js +1 -0
  26. package/dist/Browser/Browser.svelte +176 -0
  27. package/dist/Browser/Browser.svelte.d.ts +3 -0
  28. package/dist/Browser/properties.d.ts +14 -0
  29. package/dist/Browser/properties.js +1 -0
  30. package/dist/Button/Button.svelte +153 -0
  31. package/dist/Button/Button.svelte.d.ts +4 -0
  32. package/dist/Button/properties.d.ts +24 -0
  33. package/dist/Button/properties.js +1 -0
  34. package/dist/Calendar/Calendar.svelte +477 -0
  35. package/dist/Calendar/Calendar.svelte.d.ts +4 -0
  36. package/dist/Calendar/properties.d.ts +30 -0
  37. package/dist/Calendar/properties.js +1 -0
  38. package/dist/Carousel/Carousel.svelte +258 -0
  39. package/dist/Carousel/Carousel.svelte.d.ts +4 -0
  40. package/dist/Carousel/properties.d.ts +20 -0
  41. package/dist/Carousel/properties.js +1 -0
  42. package/dist/CheckListItem/CheckListItem.svelte +65 -0
  43. package/dist/CheckListItem/CheckListItem.svelte.d.ts +4 -0
  44. package/dist/CheckListItem/properties.d.ts +15 -0
  45. package/dist/CheckListItem/properties.js +1 -0
  46. package/dist/Checkbox/Checkbox.svelte +157 -0
  47. package/dist/Checkbox/Checkbox.svelte.d.ts +4 -0
  48. package/dist/Checkbox/properties.d.ts +17 -0
  49. package/dist/Checkbox/properties.js +1 -0
  50. package/dist/Choicebox/Choicebox.svelte +85 -0
  51. package/dist/Choicebox/Choicebox.svelte.d.ts +4 -0
  52. package/dist/Choicebox/properties.d.ts +14 -0
  53. package/dist/Choicebox/properties.js +1 -0
  54. package/dist/ColorPicker/ColorPicker.svelte +583 -0
  55. package/dist/ColorPicker/ColorPicker.svelte.d.ts +4 -0
  56. package/dist/ColorPicker/properties.d.ts +15 -0
  57. package/dist/ColorPicker/properties.js +1 -0
  58. package/dist/Combobox/Combobox.svelte +432 -0
  59. package/dist/Combobox/Combobox.svelte.d.ts +6 -0
  60. package/dist/Combobox/properties.d.ts +42 -0
  61. package/dist/Combobox/properties.js +1 -0
  62. package/dist/CommandMenu/CommandMenu.svelte +452 -0
  63. package/dist/CommandMenu/CommandMenu.svelte.d.ts +4 -0
  64. package/dist/CommandMenu/properties.d.ts +26 -0
  65. package/dist/CommandMenu/properties.js +1 -0
  66. package/dist/ContextMenu/ContextMenu.svelte +308 -0
  67. package/dist/ContextMenu/ContextMenu.svelte.d.ts +4 -0
  68. package/dist/ContextMenu/properties.d.ts +26 -0
  69. package/dist/ContextMenu/properties.js +1 -0
  70. package/dist/Gauge/Gauge.svelte +70 -0
  71. package/dist/Gauge/Gauge.svelte.d.ts +4 -0
  72. package/dist/Gauge/properties.d.ts +9 -0
  73. package/dist/Gauge/properties.js +1 -0
  74. package/dist/GridItem/GridItem.svelte +145 -0
  75. package/dist/GridItem/GridItem.svelte.d.ts +4 -0
  76. package/dist/GridItem/properties.d.ts +15 -0
  77. package/dist/GridItem/properties.js +1 -0
  78. package/dist/Icon/Icon.svelte +61 -0
  79. package/dist/Icon/Icon.svelte.d.ts +4 -0
  80. package/dist/Icon/properties.d.ts +12 -0
  81. package/dist/Icon/properties.js +1 -0
  82. package/dist/IconStack/IconStack.svelte +55 -0
  83. package/dist/IconStack/IconStack.svelte.d.ts +4 -0
  84. package/dist/IconStack/properties.d.ts +9 -0
  85. package/dist/IconStack/properties.js +1 -0
  86. package/dist/Img/Img.svelte +37 -0
  87. package/dist/Img/Img.svelte.d.ts +4 -0
  88. package/dist/Img/properties.d.ts +13 -0
  89. package/dist/Img/properties.js +1 -0
  90. package/dist/Input/Input.svelte +349 -0
  91. package/dist/Input/Input.svelte.d.ts +8 -0
  92. package/dist/Input/properties.d.ts +45 -0
  93. package/dist/Input/properties.js +1 -0
  94. package/dist/InputButton/InputButton.svelte +252 -0
  95. package/dist/InputButton/InputButton.svelte.d.ts +7 -0
  96. package/dist/InputButton/properties.d.ts +22 -0
  97. package/dist/InputButton/properties.js +1 -0
  98. package/dist/KeyboardInput/KeyboardInput.svelte +93 -0
  99. package/dist/KeyboardInput/KeyboardInput.svelte.d.ts +4 -0
  100. package/dist/KeyboardInput/properties.d.ts +12 -0
  101. package/dist/KeyboardInput/properties.js +1 -0
  102. package/dist/ListItem/ListItem.svelte +309 -0
  103. package/dist/ListItem/ListItem.svelte.d.ts +4 -0
  104. package/dist/ListItem/properties.d.ts +34 -0
  105. package/dist/ListItem/properties.js +1 -0
  106. package/dist/Loader/Loader.svelte +90 -0
  107. package/dist/Loader/Loader.svelte.d.ts +4 -0
  108. package/dist/Loader/properties.d.ts +4 -0
  109. package/dist/Loader/properties.js +1 -0
  110. package/dist/LoadingDots/LoadingDots.svelte +59 -0
  111. package/dist/LoadingDots/LoadingDots.svelte.d.ts +3 -0
  112. package/dist/LoadingDots/properties.d.ts +8 -0
  113. package/dist/LoadingDots/properties.js +1 -0
  114. package/dist/Menu/Menu.svelte +356 -0
  115. package/dist/Menu/Menu.svelte.d.ts +4 -0
  116. package/dist/Menu/properties.d.ts +28 -0
  117. package/dist/Menu/properties.js +1 -0
  118. package/dist/Modal/Modal.svelte +357 -0
  119. package/dist/Modal/Modal.svelte.d.ts +4 -0
  120. package/dist/Modal/properties.d.ts +39 -0
  121. package/dist/Modal/properties.js +1 -0
  122. package/dist/Pagination/Pagination.svelte +148 -0
  123. package/dist/Pagination/Pagination.svelte.d.ts +4 -0
  124. package/dist/Pagination/properties.d.ts +14 -0
  125. package/dist/Pagination/properties.js +1 -0
  126. package/dist/Phone/Phone.svelte +234 -0
  127. package/dist/Phone/Phone.svelte.d.ts +3 -0
  128. package/dist/Phone/properties.d.ts +11 -0
  129. package/dist/Phone/properties.js +1 -0
  130. package/dist/Pill/Pill.svelte +130 -0
  131. package/dist/Pill/Pill.svelte.d.ts +4 -0
  132. package/dist/Pill/properties.d.ts +16 -0
  133. package/dist/Pill/properties.js +1 -0
  134. package/dist/Progress/Progress.svelte +68 -0
  135. package/dist/Progress/Progress.svelte.d.ts +4 -0
  136. package/dist/Progress/properties.d.ts +10 -0
  137. package/dist/Progress/properties.js +1 -0
  138. package/dist/Radio/Radio.svelte +124 -0
  139. package/dist/Radio/Radio.svelte.d.ts +4 -0
  140. package/dist/Radio/properties.d.ts +15 -0
  141. package/dist/Radio/properties.js +1 -0
  142. package/dist/RelativeTime/RelativeTime.svelte +109 -0
  143. package/dist/RelativeTime/RelativeTime.svelte.d.ts +4 -0
  144. package/dist/RelativeTime/properties.d.ts +13 -0
  145. package/dist/RelativeTime/properties.js +1 -0
  146. package/dist/Scroller/Scroller.svelte +390 -0
  147. package/dist/Scroller/Scroller.svelte.d.ts +4 -0
  148. package/dist/Scroller/properties.d.ts +30 -0
  149. package/dist/Scroller/properties.js +1 -0
  150. package/dist/Select/Select.svelte +472 -0
  151. package/dist/Select/Select.svelte.d.ts +4 -0
  152. package/dist/Select/properties.d.ts +20 -0
  153. package/dist/Select/properties.js +1 -0
  154. package/dist/Sheet/Sheet.svelte +264 -0
  155. package/dist/Sheet/Sheet.svelte.d.ts +4 -0
  156. package/dist/Sheet/properties.d.ts +19 -0
  157. package/dist/Sheet/properties.js +1 -0
  158. package/dist/Shimmer/Shimmer.svelte +44 -0
  159. package/dist/Shimmer/Shimmer.svelte.d.ts +4 -0
  160. package/dist/Shimmer/properties.d.ts +4 -0
  161. package/dist/Shimmer/properties.js +1 -0
  162. package/dist/Slider/Slider.svelte +147 -0
  163. package/dist/Slider/Slider.svelte.d.ts +4 -0
  164. package/dist/Slider/properties.d.ts +17 -0
  165. package/dist/Slider/properties.js +1 -0
  166. package/dist/Snippet/Snippet.svelte +123 -0
  167. package/dist/Snippet/Snippet.svelte.d.ts +4 -0
  168. package/dist/Snippet/properties.d.ts +15 -0
  169. package/dist/Snippet/properties.js +1 -0
  170. package/dist/SplitButton/SplitButton.svelte +145 -0
  171. package/dist/SplitButton/SplitButton.svelte.d.ts +4 -0
  172. package/dist/SplitButton/properties.d.ts +17 -0
  173. package/dist/SplitButton/properties.js +1 -0
  174. package/dist/SplitInput/SplitInput.svelte +225 -0
  175. package/dist/SplitInput/SplitInput.svelte.d.ts +7 -0
  176. package/dist/SplitInput/properties.d.ts +20 -0
  177. package/dist/SplitInput/properties.js +1 -0
  178. package/dist/Stepper/Step.svelte +88 -0
  179. package/dist/Stepper/Step.svelte.d.ts +4 -0
  180. package/dist/Stepper/Stepper.svelte +64 -0
  181. package/dist/Stepper/Stepper.svelte.d.ts +4 -0
  182. package/dist/Stepper/properties.d.ts +27 -0
  183. package/dist/Stepper/properties.js +1 -0
  184. package/dist/Table/Table.svelte +357 -0
  185. package/dist/Table/Table.svelte.d.ts +4 -0
  186. package/dist/Table/properties.d.ts +26 -0
  187. package/dist/Table/properties.js +1 -0
  188. package/dist/Tabs/Tabs.svelte +303 -0
  189. package/dist/Tabs/Tabs.svelte.d.ts +4 -0
  190. package/dist/Tabs/properties.d.ts +30 -0
  191. package/dist/Tabs/properties.js +1 -0
  192. package/dist/ThemeSwitcher/ThemeSwitcher.svelte +249 -0
  193. package/dist/ThemeSwitcher/ThemeSwitcher.svelte.d.ts +4 -0
  194. package/dist/ThemeSwitcher/properties.d.ts +19 -0
  195. package/dist/ThemeSwitcher/properties.js +1 -0
  196. package/dist/Toast/Toast.svelte +220 -0
  197. package/dist/Toast/Toast.svelte.d.ts +4 -0
  198. package/dist/Toast/properties.d.ts +24 -0
  199. package/dist/Toast/properties.js +1 -0
  200. package/dist/Toggle/Toggle.svelte +99 -0
  201. package/dist/Toggle/Toggle.svelte.d.ts +4 -0
  202. package/dist/Toggle/properties.d.ts +9 -0
  203. package/dist/Toggle/properties.js +1 -0
  204. package/dist/Toolbar/Toolbar.svelte +142 -0
  205. package/dist/Toolbar/Toolbar.svelte.d.ts +4 -0
  206. package/dist/Toolbar/properties.d.ts +16 -0
  207. package/dist/Toolbar/properties.js +1 -0
  208. package/dist/Tooltip/Tooltip.svelte +153 -0
  209. package/dist/Tooltip/Tooltip.svelte.d.ts +4 -0
  210. package/dist/Tooltip/properties.d.ts +13 -0
  211. package/dist/Tooltip/properties.js +1 -0
  212. package/dist/assets/back.svg +3 -0
  213. package/dist/assets/battery.svg +5 -0
  214. package/dist/assets/checkmark.svg +3 -0
  215. package/dist/assets/chevron-down-sm.svg +3 -0
  216. package/dist/assets/chevron-down.svg +3 -0
  217. package/dist/assets/chevron-left-lg.svg +3 -0
  218. package/dist/assets/chevron-left.svg +3 -0
  219. package/dist/assets/chevron-right-lg.svg +3 -0
  220. package/dist/assets/chevron-right.svg +3 -0
  221. package/dist/assets/chevron-up.svg +3 -0
  222. package/dist/assets/close.svg +4 -0
  223. package/dist/assets/copy.svg +4 -0
  224. package/dist/assets/error-circle.svg +5 -0
  225. package/dist/assets/lock.svg +3 -0
  226. package/dist/assets/minus.svg +3 -0
  227. package/dist/assets/monitor.svg +5 -0
  228. package/dist/assets/moon.svg +3 -0
  229. package/dist/assets/palette.svg +7 -0
  230. package/dist/assets/search.svg +4 -0
  231. package/dist/assets/signal.svg +6 -0
  232. package/dist/assets/sort-default.svg +4 -0
  233. package/dist/assets/sun.svg +11 -0
  234. package/dist/assets/swap-vertical.svg +6 -0
  235. package/dist/assets/wifi.svg +3 -0
  236. package/dist/index.d.ts +103 -0
  237. package/dist/index.js +55 -0
  238. package/dist/types.d.ts +42 -0
  239. package/dist/types.js +1 -0
  240. package/dist/utils.d.ts +28 -0
  241. package/dist/utils.js +294 -0
  242. package/package.json +91 -0
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ export { default as Modal } from './Modal/Modal.svelte';
2
+ export { default as Button } from './Button/Button.svelte';
3
+ export { default as Input } from './Input/Input.svelte';
4
+ export { default as InputButton } from './InputButton/InputButton.svelte';
5
+ export { default as ListItem } from './ListItem/ListItem.svelte';
6
+ export { default as Loader } from './Loader/Loader.svelte';
7
+ export { default as Toolbar } from './Toolbar/Toolbar.svelte';
8
+ export { default as Icon } from './Icon/Icon.svelte';
9
+ export { default as Select } from './Select/Select.svelte';
10
+ export { default as ModalAnimation } from './Animations/ModalAnimation.svelte';
11
+ export { default as OverlayAnimation } from './Animations/OverlayAnimation.svelte';
12
+ export { default as Carousel } from './Carousel/Carousel.svelte';
13
+ export { default as Badge } from './Badge/Badge.svelte';
14
+ export { default as Banner } from './Banner/Banner.svelte';
15
+ export { default as Toggle } from './Toggle/Toggle.svelte';
16
+ export { default as Accordion } from './Accordion/Accordion.svelte';
17
+ export { default as CheckListItem } from './CheckListItem/CheckListItem.svelte';
18
+ export { default as Table } from './Table/Table.svelte';
19
+ export { default as Stepper } from './Stepper/Stepper.svelte';
20
+ export { default as Step } from './Stepper/Step.svelte';
21
+ export { default as Toast } from './Toast/Toast.svelte';
22
+ export { default as GridItem } from './GridItem/GridItem.svelte';
23
+ export { default as IconStack } from './IconStack/IconStack.svelte';
24
+ export { default as Img } from './Img/Img.svelte';
25
+ export { default as Checkbox } from './Checkbox/Checkbox.svelte';
26
+ export { default as Radio } from './Radio/Radio.svelte';
27
+ export { default as Avatar } from './Avatar/Avatar.svelte';
28
+ export { default as Tabs } from './Tabs/Tabs.svelte';
29
+ export { default as Choicebox } from './Choicebox/Choicebox.svelte';
30
+ export { default as Slider } from './Slider/Slider.svelte';
31
+ export { default as Tooltip } from './Tooltip/Tooltip.svelte';
32
+ export { default as Shimmer } from './Shimmer/Shimmer.svelte';
33
+ export { default as Progress } from './Progress/Progress.svelte';
34
+ export { default as Pill } from './Pill/Pill.svelte';
35
+ export { default as Pagination } from './Pagination/Pagination.svelte';
36
+ export { default as Snippet } from './Snippet/Snippet.svelte';
37
+ export { default as Gauge } from './Gauge/Gauge.svelte';
38
+ export { default as SplitButton } from './SplitButton/SplitButton.svelte';
39
+ export { default as KeyboardInput } from './KeyboardInput/KeyboardInput.svelte';
40
+ export { default as LoadingDots } from './LoadingDots/LoadingDots.svelte';
41
+ export { default as Menu } from './Menu/Menu.svelte';
42
+ export { default as Sheet } from './Sheet/Sheet.svelte';
43
+ export { default as Scroller } from './Scroller/Scroller.svelte';
44
+ export { default as CommandMenu } from './CommandMenu/CommandMenu.svelte';
45
+ export { default as ContextMenu } from './ContextMenu/ContextMenu.svelte';
46
+ export { default as Calendar } from './Calendar/Calendar.svelte';
47
+ export { default as RelativeTime } from './RelativeTime/RelativeTime.svelte';
48
+ export { default as ThemeSwitcher } from './ThemeSwitcher/ThemeSwitcher.svelte';
49
+ export { default as Book } from './Book/Book.svelte';
50
+ export { default as Browser } from './Browser/Browser.svelte';
51
+ export { default as Phone } from './Phone/Phone.svelte';
52
+ export { default as Combobox } from './Combobox/Combobox.svelte';
53
+ export { default as ColorPicker } from './ColorPicker/ColorPicker.svelte';
54
+ export { default as SplitInput } from './SplitInput/SplitInput.svelte';
55
+ export { validateInput } from './utils';
@@ -0,0 +1,42 @@
1
+ import type { FlyParams } from 'svelte/transition';
2
+ /**
3
+ * @name InputDataType
4
+ * @description Different types of input data which can be passed to the Input Component
5
+ */
6
+ export type InputDataType = 'text' | 'tel' | 'password' | 'email' | 'number';
7
+ export type ModalTransition = 'IN' | 'ALL';
8
+ /**
9
+ * @name CustomValidator
10
+ * @description Function type for taking input parameter and returning a boolean denoting if the value is valid or not
11
+ */
12
+ export type CustomValidator = (inputValue: string, currentValidationState: ValidationState) => ValidationState;
13
+ export type TextTransformer = (text: string) => string;
14
+ /**
15
+ * @description Type Map for Possible length values that can be passed to components
16
+ */
17
+ /**
18
+ * @description Type Map for All possible output of an Input Filed Validation
19
+ */
20
+ export type ValidationState = 'Valid' | 'InProgress' | 'Invalid';
21
+ /**
22
+ * @description Type for animation configuration
23
+ */
24
+ export type FlyAnimationConfig = {
25
+ in: FlyParams;
26
+ out: FlyParams;
27
+ };
28
+ export type Rgb = {
29
+ r: number;
30
+ g: number;
31
+ b: number;
32
+ };
33
+ export type Hsv = {
34
+ h: number;
35
+ s: number;
36
+ v: number;
37
+ };
38
+ export type Hsl = {
39
+ h: number;
40
+ s: number;
41
+ l: number;
42
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import type { CustomValidator, Hsv, Hsl, InputDataType, Rgb, ValidationState } from './types';
2
+ /**
3
+ * @description A common function to validate value provided inside the input component
4
+ * @param inputValue String value coming from input field
5
+ * @param dataType Datatype of the value being entered in the input component
6
+ * @param validPattern Regular expression which is supposed to be applied on the input string
7
+ * @param inProgressPattern Regular expression which is supposed to be applied on the input string while input is in progress
8
+ * @param customValidators Array of customer validator functions
9
+ * @returns ValidationState : InProgress | Valid | Invalid
10
+ */
11
+ export declare function validateInput(inputValue: string, dataType: InputDataType, validPattern: RegExp | null, inProgressPattern: RegExp | null, customValidators: CustomValidator[]): ValidationState;
12
+ /**
13
+ * @description Creates a debouncer function that delays invoking the provided callback until a specified delay period has elapsed since the last invocation.
14
+ * @param delay The delay period in milliseconds before invoking the callback.
15
+ * @returns A debouncer function that accepts a callback and delays its invocation based on the specified delay.
16
+ */
17
+ export declare function getStorageItem(key: string): string | null;
18
+ export declare function setStorageItem(key: string, value: string): void;
19
+ export declare function hexToRgb(hex: string): Rgb | null;
20
+ export declare function rgbToHsv(r: number, g: number, b: number): Hsv;
21
+ export declare function hsvToRgb(h: number, s: number, v: number): Rgb;
22
+ export declare function hsvToHex(h: number, s: number, v: number): string;
23
+ export declare function hexToHsv(hex: string): Hsv | null;
24
+ export declare function hsvToHsl(h: number, s: number, v: number): Hsl;
25
+ export declare function hslToHsv(hDeg: number, sPct: number, lPct: number): Hsv;
26
+ export declare function isValidHex(hex: string): boolean;
27
+ export declare function clampInt(v: string, min: number, max: number): number;
28
+ export declare function createDebouncer(delay: number): <T extends unknown[]>(callback: (...args: T) => void, ...args: T) => void;
package/dist/utils.js ADDED
@@ -0,0 +1,294 @@
1
+ /**
2
+ * @description A common function to validate value provided inside the input component
3
+ * @param inputValue String value coming from input field
4
+ * @param dataType Datatype of the value being entered in the input component
5
+ * @param validPattern Regular expression which is supposed to be applied on the input string
6
+ * @param inProgressPattern Regular expression which is supposed to be applied on the input string while input is in progress
7
+ * @param customValidators Array of customer validator functions
8
+ * @returns ValidationState : InProgress | Valid | Invalid
9
+ */
10
+ export function validateInput(inputValue, dataType, validPattern, inProgressPattern, customValidators) {
11
+ let validationResult = 'Valid';
12
+ switch (dataType) {
13
+ case 'email':
14
+ validationResult = validateEmailInput(inputValue);
15
+ break;
16
+ case 'tel':
17
+ validationResult =
18
+ validPattern === null
19
+ ? validatePhoneNumber(inputValue)
20
+ : validateTextWithPattern(inputValue, validPattern, inProgressPattern);
21
+ break;
22
+ case 'password':
23
+ validationResult = validatePassword(inputValue, validPattern, inProgressPattern);
24
+ break;
25
+ case 'text':
26
+ validationResult = validateTextWithPattern(inputValue, validPattern, inProgressPattern);
27
+ break;
28
+ }
29
+ customValidators.forEach((validator) => {
30
+ const currentResult = validator(inputValue, validationResult);
31
+ if (currentResult === 'Invalid') {
32
+ validationResult = 'Invalid';
33
+ }
34
+ else if (currentResult === 'InProgress') {
35
+ validationResult = 'InProgress';
36
+ }
37
+ else {
38
+ validationResult =
39
+ validationResult === 'Valid' && currentResult === 'Valid' ? 'Valid' : validationResult;
40
+ }
41
+ });
42
+ return validationResult;
43
+ }
44
+ /**
45
+ * @description Validates input string against passed RegExp
46
+ * @param inputValue string
47
+ * @param validationPattern RegExp for valid input
48
+ * @param inProgressPattern RegExp for inprogress input
49
+ * @returns ValidationState
50
+ */
51
+ function validateTextWithPattern(inputValue, validationPattern, inProgressPattern) {
52
+ if (validationPattern !== null) {
53
+ if (validationPattern.test(inputValue)) {
54
+ return 'Valid';
55
+ }
56
+ else if ((inProgressPattern !== null && inProgressPattern.test(inputValue)) ||
57
+ inputValue.length === 0) {
58
+ return 'InProgress';
59
+ }
60
+ else {
61
+ return 'Invalid';
62
+ }
63
+ }
64
+ return 'Valid';
65
+ }
66
+ /**
67
+ * @description Validates password string against passed RegExp
68
+ * @param password string
69
+ * @param validationPattern RegExp for valid input
70
+ * @param inProgressPattern RegExp for inprogress input
71
+ * @returns ValidationState
72
+ */
73
+ function validatePassword(password, validationPattern, inProgressPattern) {
74
+ if (validationPattern !== null) {
75
+ if (validationPattern.test(password)) {
76
+ return 'Valid';
77
+ }
78
+ else if (inProgressPattern !== null &&
79
+ inProgressPattern.test(password) &&
80
+ password.length === 0) {
81
+ return 'InProgress';
82
+ }
83
+ else {
84
+ return 'Invalid';
85
+ }
86
+ }
87
+ return 'Valid';
88
+ }
89
+ /**
90
+ * @description Validates an email input based upon RF 5322 Email format
91
+ * @param emailId String
92
+ * @returns ValidationState
93
+ */
94
+ function validateEmailInput(emailId) {
95
+ try {
96
+ /**
97
+ * @description Using RFC 5322 Format for validation
98
+ * @tutorial https://www.regextester.com/115911
99
+ * @tutorial https://emailregex.com/
100
+ * @tutorial https://stackoverflow.com/questions/42982005/email-address-regular-expression-rfc-5322-passed-in-to-match-does-not-work
101
+ * @tutorial https://www.regular-expressions.info/email.html
102
+ */
103
+ const validPattern = new RegExp(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
104
+ const inProgressPattern = new RegExp(/[^ ]{1,}[\w0-9.,_,@]{0,}/);
105
+ if (validPattern.test(emailId)) {
106
+ return 'Valid';
107
+ }
108
+ else if (inProgressPattern.test(emailId) || emailId.length === 0) {
109
+ return 'InProgress';
110
+ }
111
+ else {
112
+ return 'Invalid';
113
+ }
114
+ }
115
+ catch (e) {
116
+ console.error('Email Regex creation failed: ', e);
117
+ }
118
+ return 'Valid';
119
+ }
120
+ /**
121
+ * @description Validates Indian phone numbers
122
+ * @todo Update Regex to take different variations of input in next update
123
+ * @link https://stackoverflow.com/questions/18351553/regular-expression-validation-for-indian-phone-number-and-mobile-number
124
+ * @param phoneNumber
125
+ * @returns ValidationState
126
+ */
127
+ function validatePhoneNumber(phoneNumber) {
128
+ try {
129
+ const validationPattern = new RegExp('^[6-9]{1}[0-9]{9}$');
130
+ const inProgressPattern = new RegExp('^[6-9]{1}[0-9]{0,9}$');
131
+ if (validationPattern.test(phoneNumber)) {
132
+ return 'Valid';
133
+ }
134
+ else if (inProgressPattern.test(phoneNumber) || phoneNumber.length === 0) {
135
+ return 'InProgress';
136
+ }
137
+ else {
138
+ return 'Invalid';
139
+ }
140
+ }
141
+ catch (e) {
142
+ console.error('Phone Regex creation failed', e);
143
+ }
144
+ return phoneNumber.length === 10 ? 'Valid' : phoneNumber.length > 10 ? 'InProgress' : 'Invalid';
145
+ }
146
+ /**
147
+ * @description Creates a debouncer function that delays invoking the provided callback until a specified delay period has elapsed since the last invocation.
148
+ * @param delay The delay period in milliseconds before invoking the callback.
149
+ * @returns A debouncer function that accepts a callback and delays its invocation based on the specified delay.
150
+ */
151
+ export function getStorageItem(key) {
152
+ try {
153
+ return localStorage.getItem(key);
154
+ }
155
+ catch {
156
+ return null;
157
+ }
158
+ }
159
+ export function setStorageItem(key, value) {
160
+ try {
161
+ localStorage.setItem(key, value);
162
+ }
163
+ catch {
164
+ // localStorage unavailable (SSR, private browsing, storage full)
165
+ }
166
+ }
167
+ // ── Color conversions ───────────────────────────────────────────
168
+ const HEX_COLOR_PATTERN = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
169
+ export function hexToRgb(hex) {
170
+ const m = hex.match(HEX_COLOR_PATTERN);
171
+ if (m === null) {
172
+ return null;
173
+ }
174
+ const rStr = m.at(1);
175
+ const gStr = m.at(2);
176
+ const bStr = m.at(3);
177
+ if (typeof rStr !== 'string' || typeof gStr !== 'string' || typeof bStr !== 'string') {
178
+ return null;
179
+ }
180
+ return { r: parseInt(rStr, 16), g: parseInt(gStr, 16), b: parseInt(bStr, 16) };
181
+ }
182
+ export function rgbToHsv(r, g, b) {
183
+ r /= 255;
184
+ g /= 255;
185
+ b /= 255;
186
+ const max = Math.max(r, g, b);
187
+ const min = Math.min(r, g, b);
188
+ const d = max - min;
189
+ let h = 0;
190
+ const s = max === 0 ? 0 : d / max;
191
+ const v = max;
192
+ if (d !== 0) {
193
+ if (max === r) {
194
+ h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
195
+ }
196
+ else if (max === g) {
197
+ h = ((b - r) / d + 2) / 6;
198
+ }
199
+ else {
200
+ h = ((r - g) / d + 4) / 6;
201
+ }
202
+ }
203
+ return { h, s, v };
204
+ }
205
+ export function hsvToRgb(h, s, v) {
206
+ const i = Math.floor(h * 6);
207
+ const f = h * 6 - i;
208
+ const p = v * (1 - s);
209
+ const q = v * (1 - f * s);
210
+ const t = v * (1 - (1 - f) * s);
211
+ let r, g, b;
212
+ switch (i % 6) {
213
+ case 0:
214
+ r = v;
215
+ g = t;
216
+ b = p;
217
+ break;
218
+ case 1:
219
+ r = q;
220
+ g = v;
221
+ b = p;
222
+ break;
223
+ case 2:
224
+ r = p;
225
+ g = v;
226
+ b = t;
227
+ break;
228
+ case 3:
229
+ r = p;
230
+ g = q;
231
+ b = v;
232
+ break;
233
+ case 4:
234
+ r = t;
235
+ g = p;
236
+ b = v;
237
+ break;
238
+ default:
239
+ r = v;
240
+ g = p;
241
+ b = q;
242
+ break;
243
+ }
244
+ return { r: Math.round(r * 255), g: Math.round(g * 255), b: Math.round(b * 255) };
245
+ }
246
+ export function hsvToHex(h, s, v) {
247
+ const rgb = hsvToRgb(h, s, v);
248
+ const toHex = (n) => n.toString(16).padStart(2, '0');
249
+ return `#${toHex(rgb.r)}${toHex(rgb.g)}${toHex(rgb.b)}`;
250
+ }
251
+ export function hexToHsv(hex) {
252
+ const rgb = hexToRgb(hex);
253
+ if (rgb === null) {
254
+ return null;
255
+ }
256
+ return rgbToHsv(rgb.r, rgb.g, rgb.b);
257
+ }
258
+ export function hsvToHsl(h, s, v) {
259
+ const l = v * (1 - s / 2);
260
+ let sl = 0;
261
+ if (l > 0 && l < 1) {
262
+ sl = (v - l) / Math.min(l, 1 - l);
263
+ }
264
+ return { h: Math.round(h * 360), s: Math.round(sl * 100), l: Math.round(l * 100) };
265
+ }
266
+ export function hslToHsv(hDeg, sPct, lPct) {
267
+ const h = hDeg / 360;
268
+ const sl = sPct / 100;
269
+ const l = lPct / 100;
270
+ const v = l + sl * Math.min(l, 1 - l);
271
+ const sv = v === 0 ? 0 : 2 * (1 - l / v);
272
+ return { h, s: sv, v };
273
+ }
274
+ export function isValidHex(hex) {
275
+ return HEX_COLOR_PATTERN.test(hex);
276
+ }
277
+ export function clampInt(v, min, max) {
278
+ const n = parseInt(v, 10);
279
+ if (Number.isNaN(n)) {
280
+ return min;
281
+ }
282
+ return Math.max(min, Math.min(max, n));
283
+ }
284
+ // ── Misc ────────────────────────────────────────────────────────
285
+ export function createDebouncer(delay) {
286
+ let lastCallTime = 0;
287
+ return function (callback, ...args) {
288
+ const now = Date.now();
289
+ if (now - lastCallTime > delay) {
290
+ lastCallTime = now;
291
+ callback(...args);
292
+ }
293
+ };
294
+ }
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "polymorph-ui-components",
3
+ "version": "0.1.0",
4
+ "description": "A themeable Svelte 5 UI component library with CSS custom property driven styling",
5
+ "keywords": [
6
+ "svelte",
7
+ "svelte5",
8
+ "ui",
9
+ "components",
10
+ "component-library",
11
+ "design-system",
12
+ "css-variables",
13
+ "themeable",
14
+ "svelte-components"
15
+ ],
16
+ "license": "MIT",
17
+ "scripts": {
18
+ "prepare": "husky",
19
+ "dev": "vite dev --host",
20
+ "build": "vite build && npm run package",
21
+ "build:wc": "vite build --config vite.config.wc.ts",
22
+ "preview": "vite preview",
23
+ "package": "svelte-kit sync && svelte-package && publint",
24
+ "prepublishOnly": "npm run package",
25
+ "test": "npm run test:integration && npm run test:unit",
26
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
27
+ "check:wc": "svelte-check --tsconfig ./tsconfig.wc.json --compiler-warnings \"options_missing_custom_element:ignore\"",
28
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
29
+ "lint": "prettier --check src && eslint src",
30
+ "format": "prettier --write src",
31
+ "test:integration": "playwright test",
32
+ "test:unit": "vitest"
33
+ },
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "svelte": "./dist/index.js"
38
+ }
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "!dist/**/*.test.*",
43
+ "!dist/**/*.spec.*"
44
+ ],
45
+ "peerDependencies": {
46
+ "svelte": "^5.41.2"
47
+ },
48
+ "devDependencies": {
49
+ "@commitlint/cli": "^21.0.2",
50
+ "@commitlint/config-conventional": "^21.0.2",
51
+ "@eslint/compat": "^2.1.0",
52
+ "@eslint/js": "^10.0.1",
53
+ "@playwright/test": "^1.60.0",
54
+ "@sveltejs/adapter-auto": "^7.0.1",
55
+ "@sveltejs/adapter-static": "^3.0.10",
56
+ "@sveltejs/kit": "^2.63.1",
57
+ "@sveltejs/package": "^2.5.8",
58
+ "@sveltejs/vite-plugin-svelte": "^7.1.2",
59
+ "@types/node": "^26.0.0",
60
+ "eslint": "^10.4.1",
61
+ "eslint-config-prettier": "^10.1.8",
62
+ "eslint-plugin-svelte": "^3.19.0",
63
+ "eslint-plugin-unused-imports": "^4.4.1",
64
+ "globals": "^17.6.0",
65
+ "husky": "^9.1.7",
66
+ "marked": "^18.0.5",
67
+ "prettier": "^3.8.3",
68
+ "prettier-plugin-svelte": "^4.1.0",
69
+ "publint": "^0.3.21",
70
+ "svelte": "^5.56.3",
71
+ "svelte-check": "^4.6.0",
72
+ "tslib": "^2.8.1",
73
+ "typescript": "^6.0.3",
74
+ "typescript-eslint": "^8.60.1",
75
+ "vite": "^8.0.16",
76
+ "vitest": "^4.1.8"
77
+ },
78
+ "svelte": "./dist/index.js",
79
+ "types": "./dist/index.d.ts",
80
+ "type": "module",
81
+ "auto-changelog": {
82
+ "output": "docs/CHANGELOG.md",
83
+ "template": "./docs/templates/changelog.hbs",
84
+ "commitLimit": false,
85
+ "breakingPattern": "(!:)",
86
+ "unreleased": true,
87
+ "releaseSummary": true,
88
+ "hideCredit": false,
89
+ "ignoreCommitPattern": "(\\[skip ci\\])"
90
+ }
91
+ }