@maggioli-design-system/mds-input-range 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/cjs/index-5f49298d.js +1790 -0
  2. package/dist/cjs/index.cjs.js +2 -0
  3. package/dist/cjs/loader.cjs.js +13 -0
  4. package/dist/cjs/mds-input-range.cjs.entry.js +81 -0
  5. package/dist/cjs/mds-input-range.cjs.js +23 -0
  6. package/dist/collection/collection-manifest.json +12 -0
  7. package/dist/collection/common/aria.js +29 -0
  8. package/dist/collection/common/file.js +48 -0
  9. package/dist/collection/common/icon.js +15 -0
  10. package/dist/collection/common/keyboard-manager.js +45 -0
  11. package/dist/collection/common/unit.js +22 -0
  12. package/dist/collection/common/yugop/core.js +16 -0
  13. package/dist/collection/common/yugop/index.js +3 -0
  14. package/dist/collection/common/yugop/random-text.js +59 -0
  15. package/dist/collection/common/yugop/utils/math.js +11 -0
  16. package/dist/collection/common/yugop/utils/noop.js +1 -0
  17. package/dist/collection/common/yugop/utils/prng.js +21 -0
  18. package/dist/collection/common/yugop/utils/string.js +2 -0
  19. package/dist/collection/components/mds-input-range/mds-input-range.css +280 -0
  20. package/dist/collection/components/mds-input-range/mds-input-range.js +182 -0
  21. package/dist/collection/components/mds-input-range/test/mds-input-range.e2e.js +10 -0
  22. package/dist/collection/components/mds-input-range/test/mds-input-range.stories.js +40 -0
  23. package/dist/collection/dictionary/autocomplete.js +59 -0
  24. package/dist/collection/dictionary/button.js +30 -0
  25. package/dist/collection/dictionary/color.js +19 -0
  26. package/dist/collection/dictionary/file-extensions.js +64 -0
  27. package/dist/collection/dictionary/floating-ui.js +19 -0
  28. package/dist/collection/dictionary/icon.js +10 -0
  29. package/dist/collection/dictionary/input.js +37 -0
  30. package/dist/collection/dictionary/loading.js +5 -0
  31. package/dist/collection/dictionary/text.js +6 -0
  32. package/dist/collection/dictionary/typography.js +67 -0
  33. package/dist/collection/dictionary/variant.js +90 -0
  34. package/dist/collection/fixtures/cities.js +110 -0
  35. package/dist/collection/fixtures/filenames.js +57 -0
  36. package/dist/collection/interface/input-value.js +1 -0
  37. package/dist/collection/type/autocomplete.js +1 -0
  38. package/dist/collection/type/button.js +1 -0
  39. package/dist/collection/type/file-types.js +1 -0
  40. package/dist/collection/type/floating-ui.js +1 -0
  41. package/dist/collection/type/form-rel.js +1 -0
  42. package/dist/collection/type/input.js +1 -0
  43. package/dist/collection/type/loading.js +1 -0
  44. package/dist/collection/type/text.js +1 -0
  45. package/dist/collection/type/typography.js +1 -0
  46. package/dist/collection/type/variant-file-format.js +120 -0
  47. package/dist/collection/type/variant.js +1 -0
  48. package/dist/components/index.d.ts +33 -0
  49. package/dist/components/index.js +1 -0
  50. package/dist/components/mds-input-range.d.ts +11 -0
  51. package/dist/components/mds-input-range.js +100 -0
  52. package/dist/documentation.d.ts +401 -0
  53. package/dist/documentation.json +158 -0
  54. package/dist/esm/index-1ed4544f.js +1761 -0
  55. package/dist/esm/index.js +1 -0
  56. package/dist/esm/loader.js +9 -0
  57. package/dist/esm/mds-input-range.entry.js +77 -0
  58. package/dist/esm/mds-input-range.js +18 -0
  59. package/dist/esm/polyfills/core-js.js +11 -0
  60. package/dist/esm/polyfills/dom.js +79 -0
  61. package/dist/esm/polyfills/es5-html-element.js +1 -0
  62. package/dist/esm/polyfills/index.js +34 -0
  63. package/dist/esm/polyfills/system.js +6 -0
  64. package/dist/esm-es5/index-1ed4544f.js +1 -0
  65. package/dist/esm-es5/index.js +0 -0
  66. package/dist/esm-es5/loader.js +1 -0
  67. package/dist/esm-es5/mds-input-range.entry.js +1 -0
  68. package/dist/esm-es5/mds-input-range.js +1 -0
  69. package/dist/index.cjs.js +1 -0
  70. package/dist/index.js +1 -0
  71. package/dist/mds-input-range/index.esm.js +0 -0
  72. package/dist/mds-input-range/mds-input-range.esm.js +1 -0
  73. package/dist/mds-input-range/mds-input-range.js +127 -0
  74. package/dist/mds-input-range/p-1afe8cf0.system.entry.js +1 -0
  75. package/dist/mds-input-range/p-50ea2036.system.js +1 -0
  76. package/dist/mds-input-range/p-5dcf9ad8.js +2 -0
  77. package/dist/mds-input-range/p-7a418e68.system.js +1 -0
  78. package/dist/mds-input-range/p-c87cd964.entry.js +1 -0
  79. package/dist/mds-input-range/p-e5d9d1a5.system.js +2 -0
  80. package/dist/stats.json +669 -0
  81. package/dist/types/common/aria.d.ts +5 -0
  82. package/dist/types/common/file.d.ts +12 -0
  83. package/dist/types/common/icon.d.ts +5 -0
  84. package/dist/types/common/keyboard-manager.d.ts +12 -0
  85. package/dist/types/common/unit.d.ts +3 -0
  86. package/dist/types/common/yugop/core.d.ts +10 -0
  87. package/dist/types/common/yugop/index.d.ts +1 -0
  88. package/dist/types/common/yugop/random-text.d.ts +31 -0
  89. package/dist/types/common/yugop/utils/math.d.ts +3 -0
  90. package/dist/types/common/yugop/utils/noop.d.ts +1 -0
  91. package/dist/types/common/yugop/utils/prng.d.ts +8 -0
  92. package/dist/types/common/yugop/utils/string.d.ts +1 -0
  93. package/dist/types/components/mds-input-range/mds-input-range.d.ts +36 -0
  94. package/dist/types/components/mds-input-range/test/mds-input-range.stories.d.ts +39 -0
  95. package/dist/types/components.d.ts +88 -0
  96. package/dist/types/dictionary/autocomplete.d.ts +2 -0
  97. package/dist/types/dictionary/button.d.ts +6 -0
  98. package/dist/types/dictionary/color.d.ts +3 -0
  99. package/dist/types/dictionary/file-extensions.d.ts +11 -0
  100. package/dist/types/dictionary/floating-ui.d.ts +3 -0
  101. package/dist/types/dictionary/icon.d.ts +4 -0
  102. package/dist/types/dictionary/input.d.ts +5 -0
  103. package/dist/types/dictionary/loading.d.ts +2 -0
  104. package/dist/types/dictionary/text.d.ts +2 -0
  105. package/dist/types/dictionary/typography.d.ts +11 -0
  106. package/dist/types/dictionary/variant.d.ts +11 -0
  107. package/dist/types/fixtures/cities.d.ts +2 -0
  108. package/dist/types/fixtures/filenames.d.ts +2 -0
  109. package/dist/types/interface/input-value.d.ts +4 -0
  110. package/dist/types/stencil-public-runtime.d.ts +1681 -0
  111. package/dist/types/type/autocomplete.d.ts +2 -0
  112. package/dist/types/type/button.d.ts +5 -0
  113. package/dist/types/type/file-types.d.ts +1 -0
  114. package/dist/types/type/floating-ui.d.ts +2 -0
  115. package/dist/types/type/form-rel.d.ts +1 -0
  116. package/dist/types/type/input.d.ts +4 -0
  117. package/dist/types/type/loading.d.ts +1 -0
  118. package/dist/types/type/text.d.ts +1 -0
  119. package/dist/types/type/typography.d.ts +10 -0
  120. package/dist/types/type/variant-file-format.d.ts +11 -0
  121. package/dist/types/type/variant.d.ts +12 -0
  122. package/documentation.json +596 -0
  123. package/loader/cdn.js +3 -0
  124. package/loader/index.cjs.js +3 -0
  125. package/loader/index.d.ts +21 -0
  126. package/loader/index.es2017.js +3 -0
  127. package/loader/index.js +4 -0
  128. package/loader/package.json +11 -0
  129. package/package.json +49 -0
  130. package/readme.md +53 -0
  131. package/src/common/aria.ts +39 -0
  132. package/src/common/file.ts +63 -0
  133. package/src/common/icon.ts +25 -0
  134. package/src/common/keyboard-manager.ts +50 -0
  135. package/src/common/unit.ts +33 -0
  136. package/src/common/yugop/core.ts +47 -0
  137. package/src/common/yugop/index.ts +4 -0
  138. package/src/common/yugop/random-text.ts +95 -0
  139. package/src/common/yugop/utils/math.ts +21 -0
  140. package/src/common/yugop/utils/noop.ts +1 -0
  141. package/src/common/yugop/utils/prng.ts +35 -0
  142. package/src/common/yugop/utils/string.ts +4 -0
  143. package/src/components/mds-input-range/.gitlab-ci.yml +25 -0
  144. package/src/components/mds-input-range/mds-input-range.css +109 -0
  145. package/src/components/mds-input-range/mds-input-range.tsx +117 -0
  146. package/src/components/mds-input-range/readme.md +38 -0
  147. package/src/components/mds-input-range/test/mds-input-range.e2e.ts +12 -0
  148. package/src/components/mds-input-range/test/mds-input-range.stories.tsx +50 -0
  149. package/src/components.d.ts +88 -0
  150. package/src/dictionary/autocomplete.ts +62 -0
  151. package/src/dictionary/button.ts +41 -0
  152. package/src/dictionary/color.ts +24 -0
  153. package/src/dictionary/file-extensions.ts +81 -0
  154. package/src/dictionary/floating-ui.ts +25 -0
  155. package/src/dictionary/icon.ts +15 -0
  156. package/src/dictionary/input.ts +48 -0
  157. package/src/dictionary/loading.ts +9 -0
  158. package/src/dictionary/text.ts +9 -0
  159. package/src/dictionary/typography.ts +88 -0
  160. package/src/dictionary/variant.ts +111 -0
  161. package/src/fixtures/cities.ts +116 -0
  162. package/src/fixtures/filenames.ts +60 -0
  163. package/src/fixtures/icons.json +332 -0
  164. package/src/fixtures/iconsauce.json +253 -0
  165. package/src/interface/input-value.ts +5 -0
  166. package/src/tailwind/components.css +15 -0
  167. package/src/type/autocomplete.ts +69 -0
  168. package/src/type/button.ts +28 -0
  169. package/src/type/file-types.ts +55 -0
  170. package/src/type/floating-ui.ts +17 -0
  171. package/src/type/form-rel.ts +11 -0
  172. package/src/type/input.ts +25 -0
  173. package/src/type/loading.ts +3 -0
  174. package/src/type/text.ts +4 -0
  175. package/src/type/typography.ts +65 -0
  176. package/src/type/variant-file-format.ts +137 -0
  177. package/src/type/variant.ts +99 -0
  178. package/www/build/index.esm.js +0 -0
  179. package/www/build/mds-input-range.esm.js +1 -0
  180. package/www/build/mds-input-range.js +127 -0
  181. package/www/build/p-1afe8cf0.system.entry.js +1 -0
  182. package/www/build/p-50ea2036.system.js +1 -0
  183. package/www/build/p-5dcf9ad8.js +2 -0
  184. package/www/build/p-7a418e68.system.js +1 -0
  185. package/www/build/p-c87cd964.entry.js +1 -0
  186. package/www/build/p-e5d9d1a5.system.js +2 -0
  187. package/www/host.config.json +15 -0
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "mds-input-range-loader",
3
+ "private": true,
4
+ "typings": "./index.d.ts",
5
+ "module": "./index.js",
6
+ "main": "./index.cjs.js",
7
+ "jsnext:main": "./index.es2017.js",
8
+ "es2015": "./index.es2017.js",
9
+ "es2017": "./index.es2017.js",
10
+ "unpkg": "./cdn.js"
11
+ }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@maggioli-design-system/mds-input-range",
3
+ "version": "1.0.1",
4
+ "description": "mds-input-range is a web-component from Magma Design System, built with StencilJS, TypeScript, Storybook. It's based on the web-component standard and it's designed to be agnostic from the JavaScirpt framework you are using.",
5
+ "main": "dist/index.cjs.js",
6
+ "module": "dist/index.js",
7
+ "es2015": "dist/esm/index.mjs",
8
+ "es2017": "dist/esm/index.mjs",
9
+ "types": "dist/types/components.d.ts",
10
+ "collection": "dist/collection/collection-manifest.json",
11
+ "collection:main": "dist/collection/index.js",
12
+ "unpkg": "dist/mds-input-range/mds-input-range.esm.js",
13
+ "files": [
14
+ "dist/",
15
+ "documentation.json",
16
+ "loader/",
17
+ "readme.md",
18
+ "src/",
19
+ "www/"
20
+ ],
21
+ "scripts": {
22
+ "build": "rm src/components.d.ts || true && stencil build --docs-readme",
23
+ "prepublishOnly": "npm run build",
24
+ "test": "stencil test --spec --e2e"
25
+ },
26
+ "dependencies": {
27
+ "@maggioli-design-system/styles": "14.3.2",
28
+ "@maggioli-design-system/mds-text": "4.3.6",
29
+ "@stencil/core": "4.10.0"
30
+ },
31
+ "license": "MIT",
32
+ "author": {
33
+ "name": "Vittorio Vittori",
34
+ "email": "vittorio.vittori@maggioli.it",
35
+ "url": "https://vitto.github.io/vit.to/"
36
+ },
37
+ "contributors": [
38
+ {
39
+ "name": "Nicola Tamburini",
40
+ "email": "nicola.tamburini@maggioli.it",
41
+ "role": "Software Engineer"
42
+ },
43
+ {
44
+ "name": "Vittorio Vittori",
45
+ "email": "vittorio.vittori@maggioli.it",
46
+ "role": "Product Designer"
47
+ }
48
+ ]
49
+ }
package/readme.md ADDED
@@ -0,0 +1,53 @@
1
+ # mds-input-range
2
+
3
+
4
+
5
+ This is a web-component from Maggioli Design System [Magma](https://magma.maggiolicloud.it), built with StencilJS, TypeScript, Storybook. It's based on the web-component standard and it's designed to be agnostic from the JavaScirpt framework you are using.
6
+
7
+ <!-- Auto Generated Below -->
8
+
9
+
10
+ ## Properties
11
+
12
+ | Property | Attribute | Description | Type | Default |
13
+ | -------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ----------- |
14
+ | `max` | `max` | The greatest value in the range of permitted values | `number` | `100` |
15
+ | `min` | `min` | The lowest value in the range of permitted values | `number` | `0` |
16
+ | `step` | `step` | The step attribute is a number that specifies the granularity that the value must adhere to, or the special value any, which is described below. | `number` | `1` |
17
+ | `value` | `value` | The value attribute contains a number which contains a representation of the selected number. | `number` | `undefined` |
18
+
19
+
20
+ ## Events
21
+
22
+ | Event | Description | Type |
23
+ | --------------------- | ------------------------------------- | --------------------- |
24
+ | `mdsInputRangeChange` | Emits when the input range is changed | `CustomEvent<number>` |
25
+
26
+
27
+ ## CSS Custom Properties
28
+
29
+ | Name | Description |
30
+ | --------------------------------------------- | ------------------------------------------------ |
31
+ | `--mds-input-range-thumb-background` | |
32
+ | `--mds-input-range-thumb-size` | Sets the thumb width and height of the component |
33
+ | `--mds-input-range-track-background` | |
34
+ | `--mds-input-range-track-progress-background` | |
35
+ | `--mds-input-range-track-size` | |
36
+
37
+
38
+ ## Dependencies
39
+
40
+ ### Depends on
41
+
42
+ - [mds-text](../mds-text)
43
+
44
+ ### Graph
45
+ ```mermaid
46
+ graph TD;
47
+ mds-input-range --> mds-text
48
+ style mds-input-range fill:#f9f,stroke:#333,stroke-width:4px
49
+ ```
50
+
51
+ ----------------------------------------------
52
+
53
+ Built with love @ [Gruppo Maggioli](https://www.maggioli.com) from [R&D Department](https://www.maggioli.com/it-it/chi-siamo/ricerca-sviluppo)
@@ -0,0 +1,39 @@
1
+ const hash = (s: string): string => {
2
+ let i: number, h: number
3
+ for (i = 0, h = 0; i < s.length; i ++) {
4
+ h = Math.imul(31, h) + s.charCodeAt(i) | 0
5
+ }
6
+ return h.toString()
7
+ }
8
+
9
+ const randomInt = (max: number): number => Math.floor(Math.random() * max)
10
+
11
+ const unslugName = (name: string): string => {
12
+ return name.split('/')?.slice(-1).pop()?.replace(/-/g, ' ') ?? name
13
+ }
14
+
15
+ const setAttributeIfEmpty = (element: HTMLElement, attribute: string, value: string): string => {
16
+ if (element.hasAttribute(attribute)) {
17
+ return element.getAttribute(attribute) ?? ''
18
+ }
19
+ element.setAttribute(attribute, value)
20
+ return value
21
+ }
22
+
23
+ const hashValue = (value: string): string => `${value}-${hash(value)}`
24
+
25
+ const hashRandomValue = (value?: string): string => {
26
+ const randomValue = randomInt(1000000)
27
+ if (value) {
28
+ return `${value}-${hash(randomValue.toString())}`
29
+ }
30
+
31
+ return hash(randomValue.toString())
32
+ }
33
+
34
+ export {
35
+ unslugName,
36
+ setAttributeIfEmpty,
37
+ hashRandomValue,
38
+ hashValue,
39
+ }
@@ -0,0 +1,63 @@
1
+ import { fileExtensionsDictionary, ExtensionInfo } from '@dictionary/file-extensions'
2
+ import { fileFormatsVariant } from '@type/variant-file-format'
3
+
4
+ interface FileFormatsVariants {
5
+ color: string
6
+ icon: string
7
+ iconBackground: string
8
+ variant: string
9
+ }
10
+
11
+ const sanitizeFilename = (filename: string, error: string = 'Attribute "filename" is undefined.') => {
12
+ if (filename === undefined ) {
13
+ throw console.error(error)
14
+ }
15
+ if (filename.includes('/')) {
16
+ return filename.split('/').pop() ?? ''
17
+ }
18
+ return filename
19
+ }
20
+
21
+ const sanitizeSuffix = (rawFilename: string) => {
22
+ const filename = sanitizeFilename(rawFilename)
23
+ if (filename.includes('.')) {
24
+ return filename.split('.').pop() ?? ''
25
+ }
26
+ return filename
27
+ }
28
+
29
+ const getName = (rawFilename: string): string => {
30
+ const filename = sanitizeFilename(rawFilename)
31
+ if (filename.includes('.')) {
32
+ return filename.split('.')[0] ?? ''
33
+ }
34
+ return filename
35
+ }
36
+
37
+ const getSuffix = (rawFilename: string, suffixOverride?: string): string => {
38
+ const suffix = sanitizeSuffix(rawFilename)
39
+ const filename = sanitizeFilename(rawFilename)
40
+ if (suffixOverride !== null && suffixOverride !== undefined) {
41
+ return suffixOverride.toLowerCase()
42
+ }
43
+ if (suffix !== filename) {
44
+ return suffix
45
+ }
46
+ return 'default'
47
+ }
48
+
49
+ const getExtensionInfos = (rawFilename: string, suffixOverride?: string): ExtensionInfo => {
50
+ const suffix = getSuffix(rawFilename, suffixOverride).toLocaleLowerCase()
51
+ return fileExtensionsDictionary[suffix] ?? fileExtensionsDictionary.default
52
+ }
53
+
54
+ const getFormatsVariant = (rawFilename: string, suffixOverride?: string): FileFormatsVariants => {
55
+ return fileFormatsVariant[getExtensionInfos(rawFilename, suffixOverride).format]
56
+ }
57
+
58
+ export {
59
+ getExtensionInfos,
60
+ getFormatsVariant,
61
+ getSuffix,
62
+ getName,
63
+ }
@@ -0,0 +1,25 @@
1
+ const BASE64_SVG_ICON = 'data:image/svg+xml;base64,'
2
+ const MARKUP_SVG_ICON = '<svg '
3
+
4
+ const isIconFormatIsBase64 = (icon?: string): boolean => {
5
+ if (!icon) {
6
+ return false
7
+ }
8
+ return icon.startsWith(BASE64_SVG_ICON)
9
+ }
10
+
11
+ const isIconFormatIsSVG = (icon?: string): boolean => {
12
+ if (!icon) {
13
+ return false
14
+ }
15
+ return icon.startsWith(MARKUP_SVG_ICON)
16
+ }
17
+
18
+
19
+
20
+ export {
21
+ isIconFormatIsBase64,
22
+ isIconFormatIsSVG,
23
+ BASE64_SVG_ICON,
24
+ MARKUP_SVG_ICON,
25
+ }
@@ -0,0 +1,50 @@
1
+ export class KeyboardManager {
2
+ private escapeCallback: () => void
3
+ private elements = new Map<string, HTMLElement>()
4
+
5
+ private handleClickBehaviorDispatchEvent = (event: KeyboardEvent): void => {
6
+ if (event.code === 'Enter' || event.code === 'NumpadEnter') {
7
+ (event.target as HTMLElement).click()
8
+ }
9
+ }
10
+
11
+ private handleEscapeBehaviorDispatchEvent = (event: KeyboardEvent): void => {
12
+ if (event.code === 'Escape' && this.escapeCallback) {
13
+ this.escapeCallback()
14
+ }
15
+ }
16
+
17
+ addElement = (el: HTMLElement, name = 'element'): void => {
18
+ if (!el) {
19
+ throw Error(`Passed an ${el} element parameter to KeyboardManager.addElement`)
20
+ }
21
+ this.elements.set(name, el)
22
+ }
23
+
24
+ removeElement = (name: string = 'element'): void => {
25
+ this.detachClickBehavior(name)
26
+ this.elements.delete(name)
27
+ }
28
+
29
+ attachClickBehavior = (name = 'element'): void => {
30
+ this.elements.get(name)?.addEventListener('keydown', this.handleClickBehaviorDispatchEvent)
31
+ }
32
+
33
+ detachClickBehavior = (name = 'element'): void => {
34
+ this.elements.get(name)?.removeEventListener('keydown', this.handleClickBehaviorDispatchEvent)
35
+ }
36
+
37
+ attachEscapeBehavior = (callback: () => void): void => {
38
+ this.escapeCallback = callback
39
+ if (window !== undefined) {
40
+ window.addEventListener('keydown', this.handleEscapeBehaviorDispatchEvent.bind(this))
41
+ }
42
+ }
43
+
44
+ detachEscapeBehavior = (): void => {
45
+ this.escapeCallback = () => { return }
46
+ if (window !== undefined) {
47
+ window.removeEventListener('keydown', this.handleEscapeBehaviorDispatchEvent.bind(this))
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,33 @@
1
+ const cssDurationToMilliseconds = (duration: string, defaultValue = 1000): number => {
2
+
3
+ if (duration.includes('ms')) {
4
+ return Number(duration.replace('ms', ''))
5
+ }
6
+
7
+ if (duration.includes('s')) {
8
+ return Number(duration.replace('s', '')) * 1000
9
+ }
10
+
11
+ return defaultValue
12
+ }
13
+
14
+ const cssSizeToNumber = (size: string, defaultValue = 0): number => {
15
+ if (size.includes('px')) {
16
+ return Number(size.replace('px', ''))
17
+ }
18
+
19
+ if (size.includes('rem')) {
20
+ return Number(size.replace('rem', '')) * 16
21
+ }
22
+
23
+ if (size.includes('em')) {
24
+ return Number(size.replace('em', '')) * 16
25
+ }
26
+
27
+ return defaultValue
28
+ }
29
+
30
+ export {
31
+ cssDurationToMilliseconds,
32
+ cssSizeToNumber,
33
+ }
@@ -0,0 +1,47 @@
1
+ import { generator } from './utils/prng'
2
+ import { strToCharCodeArray } from './utils/string'
3
+ import { randomSign, minMaxLooped } from './utils/math'
4
+ const rand = generator()
5
+
6
+ const random: (arg0: number, arg1: number) => () => number = (
7
+ base,
8
+ offset,
9
+ ) => () => (base + rand.range(0, offset)) * randomSign()
10
+
11
+ export const generateRandomCharCodeArray: (
12
+ arg0: number,
13
+ arg1: number
14
+ ) => (arg0: string) => number[] = (base, offset) => str =>
15
+ strToCharCodeArray(str).map(random(base, offset))
16
+ type Options = {
17
+ str: string
18
+ minCharCode: number
19
+ maxCharCode: number
20
+ placeholderChar: string
21
+ charStep: number
22
+ }
23
+ export const charCodeArrayToString: (
24
+ arg0: Options
25
+ ) => (arg0: number[]) => string = ({
26
+ str,
27
+ minCharCode,
28
+ maxCharCode,
29
+ placeholderChar,
30
+ charStep,
31
+ }) => charCodes =>
32
+ charCodes.reduce((acc, item, index) => {
33
+ if (item !== 0) {
34
+ if (Math.abs(item) > charStep) {
35
+ return acc + placeholderChar
36
+ }
37
+
38
+ return (
39
+ acc +
40
+ String.fromCharCode(
41
+ minMaxLooped(minCharCode, maxCharCode)(str.charCodeAt(index) + item),
42
+ )
43
+ )
44
+ }
45
+
46
+ return acc + str.charAt(index)
47
+ }, '')
@@ -0,0 +1,4 @@
1
+ // taken from https://github.com/zenoplex/random-text
2
+
3
+ // @flow
4
+ export { default } from './random-text'
@@ -0,0 +1,95 @@
1
+ import { generateRandomCharCodeArray, charCodeArrayToString } from './core'
2
+ import { noop } from './utils/noop'
3
+
4
+ type Options = {
5
+ str: string
6
+ speed?: number
7
+ placeholderChar?: string
8
+ frameOffset?: number
9
+ charOffset?: number
10
+ charStep?: number
11
+ minCharCode?: number
12
+ maxCharCode?: number
13
+ onProgress?: (arg0: string) => void
14
+ onComplete?: (arg0: string) => void
15
+ }
16
+
17
+ class RandomText {
18
+ static defaults: Options = {
19
+ str: '',
20
+ speed: 2,
21
+ placeholderChar: '_',
22
+ frameOffset: 30,
23
+ charOffset: 20,
24
+ charStep: 10,
25
+ minCharCode: 32,
26
+ maxCharCode: 122,
27
+ onProgress: noop,
28
+ onComplete: noop,
29
+ }
30
+ str: string
31
+ speed: number
32
+ placeholderChar: string
33
+ frameOffset: number
34
+ charOffset: number
35
+ charStep: number
36
+ minCharCode: number
37
+ maxCharCode: number
38
+ onProgress: (...args: Array<string>) => string
39
+ onComplete: (...args: Array<string>) => string
40
+ rafId: number // TODO: should be #rafId for private
41
+
42
+ constructor (options: Options) {
43
+ Object.assign(this, { ...RandomText.defaults, ...options })
44
+ }
45
+
46
+ start = (): void => {
47
+ const { frameOffset, charOffset, str, speed } = this
48
+ const randoms = generateRandomCharCodeArray(frameOffset, charOffset)(str)
49
+ this.stop()
50
+ this.rafId = requestAnimationFrame(() => {
51
+ this.step(randoms, speed, speed)
52
+ })
53
+ }
54
+
55
+ stop (): void {
56
+ cancelAnimationFrame(this.rafId)
57
+ }
58
+
59
+ step (randoms: number[], stepCount: number, speed: number): void {
60
+ const {
61
+ str,
62
+ charStep,
63
+ minCharCode,
64
+ maxCharCode,
65
+ placeholderChar,
66
+ onProgress,
67
+ onComplete,
68
+ } = this
69
+ const stepArray = randoms.slice(0, stepCount)
70
+ const steppedArray = stepArray.map(item => {
71
+ if (item > 0) return item - 1
72
+ if (item < 0) return item + 1
73
+ return 0
74
+ })
75
+ const output = charCodeArrayToString({
76
+ str,
77
+ minCharCode,
78
+ maxCharCode,
79
+ placeholderChar,
80
+ charStep,
81
+ })(steppedArray)
82
+ const updatedRandoms = [...steppedArray, ...randoms.slice(stepCount)]
83
+ onProgress(output)
84
+
85
+ if (output !== str) {
86
+ this.rafId = requestAnimationFrame(() => {
87
+ this.step(updatedRandoms, stepCount + speed, speed)
88
+ })
89
+ } else {
90
+ onComplete(output)
91
+ }
92
+ }
93
+ }
94
+
95
+ export default RandomText
@@ -0,0 +1,21 @@
1
+ import { generator } from './prng'
2
+
3
+ const rand = generator()
4
+ export const randomSign: () => number = () =>
5
+ (Math.round(Math.random()) - 0.5) * 2
6
+ export const generateRandomNumbers: (
7
+ arg0: number
8
+ ) => (
9
+ arg0: number
10
+ ) => (arg0: number) => number[] = base => charOffset => length =>
11
+ [...Array(length)].map(
12
+ () => (base + rand.range(0, charOffset)) * randomSign(),
13
+ )
14
+ export const minMaxLooped: (
15
+ arg0: number,
16
+ arg1: number
17
+ ) => (arg0: number) => number = (min, max) => value => {
18
+ if (value > max) return min + (value - max)
19
+ if (value < min) return max + (value - min)
20
+ return value
21
+ }
@@ -0,0 +1 @@
1
+ export const noop: (...rest: unknown[]) => unknown = () => {}
@@ -0,0 +1,35 @@
1
+ const int32 = 2147483647
2
+
3
+ const gen: (arg0: number) => number = v => (v * 16807) % int32
4
+
5
+ const randomFloat: (arg0: number) => number = v => gen(v) / int32
6
+
7
+ const randomInt: (arg0: number) => number = v => gen(v)
8
+
9
+ type Generator = (
10
+ _?: number
11
+ ) => {
12
+ random: () => number
13
+ randomFloat: () => number
14
+ range: (min: number, max: number) => number
15
+ rangeFloat: (min: number, max: number) => number
16
+ }
17
+ export const generator: Generator = (seed = 1) => {
18
+ let value = seed < 1 ? 1 : seed
19
+
20
+ const next: () => number = () => {
21
+ value = randomInt(value)
22
+ return value
23
+ }
24
+
25
+ return {
26
+ random: () => next(),
27
+ randomFloat: () => randomFloat(next()),
28
+ range: (min, max) => {
29
+ const minimum = min - 0.4999
30
+ const maximum = max + 0.4999
31
+ return Math.round(minimum + (maximum - minimum) * randomFloat(next()))
32
+ },
33
+ rangeFloat: (min, max) => min + (max - min) * randomFloat(next()),
34
+ }
35
+ }
@@ -0,0 +1,4 @@
1
+ // export const strToCharCodeArray: string => number[] = str => str.split('').map(item => item.charCodeAt(0));
2
+
3
+ export const strToCharCodeArray: (arg0: string) => number[] = str =>
4
+ str.split('').map(item => item.charCodeAt(0))
@@ -0,0 +1,25 @@
1
+ .base-input-range:
2
+ variables:
3
+ COMPONENT: mds-input-range
4
+
5
+ # ISOLATE
6
+ input-range-isolate:
7
+ extends: [.base-isolate, .base-input-range]
8
+ dependencies: [base-stencil-build]
9
+
10
+ # TEST
11
+ input-range-publish-test:
12
+ extends: [.base-stencil-publish-test, .base-input-range]
13
+ dependencies: [base-stencil-build, input-range-isolate]
14
+
15
+ # PUBLISH
16
+ input-range-publish:
17
+ extends: [.base-stencil-publish, .base-input-range]
18
+ dependencies: [base-stencil-build, input-range-isolate]
19
+ needs: [base-stencil-build, input-range-isolate, input-range-publish-test]
20
+
21
+ # INSTALL TEST
22
+ input-range-install-test:
23
+ extends: [.base-stencil-install-test, .base-input-range]
24
+ dependencies: [base-stencil-build, input-range-isolate]
25
+ needs: [base-stencil-build, input-range-isolate, input-range-publish]
@@ -0,0 +1,109 @@
1
+ @import '~@maggioli-design-system/styles/dist/css/animations.css';
2
+ @import '../../tailwind/components.css';
3
+ @tailwind components;
4
+ @tailwind utilities;
5
+
6
+ /**
7
+ * @prop --mds-input-range-thumb-size: Sets the thumb width and height of the component
8
+ * @prop --mds-input-range-thumb-background:
9
+ * @prop --mds-input-range-track-background:
10
+ * @prop --mds-input-range-track-size:
11
+ * @prop --mds-input-range-track-progress-background:
12
+ */
13
+
14
+ :host {
15
+
16
+ --mds-input-range-thumb-size: theme('spacing.400');
17
+ --mds-input-range-thumb-background: theme('colors.brand-maggioli-03');
18
+ --mds-input-range-track-background: theme('colors.tone-neutral-09');
19
+ --mds-input-range-track-size: theme('spacing.200');
20
+ --mds-input-range-track-progress-background: var(--mds-input-range-thumb-background);
21
+
22
+ @apply gap-100;
23
+
24
+ display: grid;
25
+ }
26
+
27
+ .header {
28
+ @apply gap-200;
29
+
30
+ display: flex;
31
+ }
32
+
33
+ .label {
34
+ @apply
35
+ min-w-0
36
+ truncate;
37
+ }
38
+
39
+ .value {
40
+ margin-left: auto;
41
+ }
42
+
43
+ .range {
44
+ align-items: center;
45
+ display: flex;
46
+ height: var(--mds-input-range-thumb-size);
47
+ position: relative;
48
+ }
49
+
50
+ .track {
51
+ @apply w-full;
52
+
53
+ --margin: calc(var(--mds-input-range-track-size) / 2);
54
+
55
+ box-sizing: border-box;
56
+ padding: 0 var(--margin);
57
+ position: absolute;
58
+ }
59
+
60
+ .field {
61
+ @apply
62
+ focus-bounce
63
+ h-400
64
+ z-20;
65
+
66
+ appearance: none;
67
+ background-color: transparent;
68
+ border-radius: 1000px;
69
+ flex-grow: 1;
70
+ margin: 0;
71
+ }
72
+
73
+ .field:focus-visible {
74
+ @apply focus-bounce--focused;
75
+ }
76
+
77
+ .field::-webkit-slider-thumb {
78
+ appearance: none;
79
+ background-color: var(--mds-input-range-thumb-background);
80
+ border: 0;
81
+ border-radius: var(--mds-input-range-thumb-size);
82
+ cursor: pointer;
83
+ height: var(--mds-input-range-thumb-size);
84
+ line-height: 0;
85
+ transform: translate(0, -50%);
86
+ width: var(--mds-input-range-thumb-size);
87
+ }
88
+
89
+ .field::-webkit-slider-runnable-track {
90
+ appearance: none;
91
+ border: 0;
92
+ height: 0;
93
+ width: 100%;
94
+ }
95
+
96
+ .track-progress {
97
+ background-color: var(--mds-input-range-track-progress-background);
98
+ display: flex;
99
+ height: var(--mds-input-range-track-size);
100
+ }
101
+
102
+ .track-total {
103
+ background-color: var(--mds-input-range-track-background);
104
+ border-radius: var(--mds-input-range-track-size);
105
+ display: flex;
106
+ height: var(--mds-input-range-track-size);
107
+ overflow: hidden;
108
+ width: 100%;
109
+ }