@maggioli-design-system/mds-input-tip 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. package/dist/cjs/index-fe2df682.js +1571 -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-tip.cjs.entry.js +21 -0
  5. package/dist/cjs/mds-input-tip.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/locale.js +20 -0
  12. package/dist/collection/common/unit.js +22 -0
  13. package/dist/collection/common/yugop/core.js +16 -0
  14. package/dist/collection/common/yugop/index.js +3 -0
  15. package/dist/collection/common/yugop/random-text.js +59 -0
  16. package/dist/collection/common/yugop/utils/math.js +11 -0
  17. package/dist/collection/common/yugop/utils/noop.js +1 -0
  18. package/dist/collection/common/yugop/utils/prng.js +21 -0
  19. package/dist/collection/common/yugop/utils/string.js +2 -0
  20. package/dist/collection/components/mds-input-tip/mds-input-tip.css +280 -0
  21. package/dist/collection/components/mds-input-tip/mds-input-tip.js +68 -0
  22. package/dist/collection/components/mds-input-tip/meta/types.js +1 -0
  23. package/dist/collection/components/mds-input-tip/test/mds-input-tip.e2e.js +9 -0
  24. package/dist/collection/dictionary/autocomplete.js +59 -0
  25. package/dist/collection/dictionary/button.js +30 -0
  26. package/dist/collection/dictionary/color.js +19 -0
  27. package/dist/collection/dictionary/file-extensions.js +64 -0
  28. package/dist/collection/dictionary/floating-ui.js +19 -0
  29. package/dist/collection/dictionary/icon.js +10 -0
  30. package/dist/collection/dictionary/input.js +37 -0
  31. package/dist/collection/dictionary/loading.js +5 -0
  32. package/dist/collection/dictionary/text.js +6 -0
  33. package/dist/collection/dictionary/typography.js +67 -0
  34. package/dist/collection/dictionary/variant.js +90 -0
  35. package/dist/collection/fixtures/cities.js +110 -0
  36. package/dist/collection/fixtures/filenames.js +57 -0
  37. package/dist/collection/interface/input-value.js +1 -0
  38. package/dist/collection/type/autocomplete.js +1 -0
  39. package/dist/collection/type/button.js +1 -0
  40. package/dist/collection/type/file-types.js +1 -0
  41. package/dist/collection/type/floating-ui.js +1 -0
  42. package/dist/collection/type/form-rel.js +1 -0
  43. package/dist/collection/type/input.js +1 -0
  44. package/dist/collection/type/loading.js +1 -0
  45. package/dist/collection/type/text.js +1 -0
  46. package/dist/collection/type/typography.js +1 -0
  47. package/dist/collection/type/variant-file-format.js +120 -0
  48. package/dist/collection/type/variant.js +1 -0
  49. package/dist/components/index.d.ts +33 -0
  50. package/dist/components/index.js +1 -0
  51. package/dist/components/mds-input-tip.d.ts +11 -0
  52. package/dist/components/mds-input-tip.js +38 -0
  53. package/dist/documentation.d.ts +401 -0
  54. package/dist/documentation.json +97 -0
  55. package/dist/esm/index-351c5c8a.js +1544 -0
  56. package/dist/esm/index.js +1 -0
  57. package/dist/esm/loader.js +9 -0
  58. package/dist/esm/mds-input-tip.entry.js +17 -0
  59. package/dist/esm/mds-input-tip.js +18 -0
  60. package/dist/esm/polyfills/core-js.js +11 -0
  61. package/dist/esm/polyfills/dom.js +79 -0
  62. package/dist/esm/polyfills/es5-html-element.js +1 -0
  63. package/dist/esm/polyfills/index.js +34 -0
  64. package/dist/esm/polyfills/system.js +6 -0
  65. package/dist/esm-es5/index-351c5c8a.js +1 -0
  66. package/dist/esm-es5/index.js +0 -0
  67. package/dist/esm-es5/loader.js +1 -0
  68. package/dist/esm-es5/mds-input-tip.entry.js +1 -0
  69. package/dist/esm-es5/mds-input-tip.js +1 -0
  70. package/dist/index.cjs.js +1 -0
  71. package/dist/index.js +1 -0
  72. package/dist/mds-input-tip/index.esm.js +0 -0
  73. package/dist/mds-input-tip/mds-input-tip.esm.js +1 -0
  74. package/dist/mds-input-tip/mds-input-tip.js +127 -0
  75. package/dist/mds-input-tip/p-22b86e20.js +2 -0
  76. package/dist/mds-input-tip/p-3428f886.system.js +2 -0
  77. package/dist/mds-input-tip/p-50ea2036.system.js +1 -0
  78. package/dist/mds-input-tip/p-630886b5.entry.js +1 -0
  79. package/dist/mds-input-tip/p-89e037f5.system.entry.js +1 -0
  80. package/dist/mds-input-tip/p-e5fe0b68.system.js +1 -0
  81. package/dist/stats.json +500 -0
  82. package/dist/types/common/aria.d.ts +5 -0
  83. package/dist/types/common/file.d.ts +12 -0
  84. package/dist/types/common/icon.d.ts +5 -0
  85. package/dist/types/common/keyboard-manager.d.ts +12 -0
  86. package/dist/types/common/locale.d.ts +14 -0
  87. package/dist/types/common/unit.d.ts +3 -0
  88. package/dist/types/common/yugop/core.d.ts +10 -0
  89. package/dist/types/common/yugop/index.d.ts +1 -0
  90. package/dist/types/common/yugop/random-text.d.ts +31 -0
  91. package/dist/types/common/yugop/utils/math.d.ts +3 -0
  92. package/dist/types/common/yugop/utils/noop.d.ts +1 -0
  93. package/dist/types/common/yugop/utils/prng.d.ts +8 -0
  94. package/dist/types/common/yugop/utils/string.d.ts +1 -0
  95. package/dist/types/components/mds-input-tip/mds-input-tip.d.ts +12 -0
  96. package/dist/types/components/mds-input-tip/meta/types.d.ts +1 -0
  97. package/dist/types/components.d.ts +55 -0
  98. package/dist/types/dictionary/autocomplete.d.ts +2 -0
  99. package/dist/types/dictionary/button.d.ts +6 -0
  100. package/dist/types/dictionary/color.d.ts +3 -0
  101. package/dist/types/dictionary/file-extensions.d.ts +11 -0
  102. package/dist/types/dictionary/floating-ui.d.ts +3 -0
  103. package/dist/types/dictionary/icon.d.ts +4 -0
  104. package/dist/types/dictionary/input.d.ts +5 -0
  105. package/dist/types/dictionary/loading.d.ts +2 -0
  106. package/dist/types/dictionary/text.d.ts +2 -0
  107. package/dist/types/dictionary/typography.d.ts +11 -0
  108. package/dist/types/dictionary/variant.d.ts +11 -0
  109. package/dist/types/fixtures/cities.d.ts +2 -0
  110. package/dist/types/fixtures/filenames.d.ts +2 -0
  111. package/dist/types/interface/input-value.d.ts +4 -0
  112. package/dist/types/stencil-public-runtime.d.ts +1681 -0
  113. package/dist/types/type/autocomplete.d.ts +2 -0
  114. package/dist/types/type/button.d.ts +5 -0
  115. package/dist/types/type/file-types.d.ts +1 -0
  116. package/dist/types/type/floating-ui.d.ts +2 -0
  117. package/dist/types/type/form-rel.d.ts +1 -0
  118. package/dist/types/type/input.d.ts +4 -0
  119. package/dist/types/type/loading.d.ts +1 -0
  120. package/dist/types/type/text.d.ts +1 -0
  121. package/dist/types/type/typography.d.ts +10 -0
  122. package/dist/types/type/variant-file-format.d.ts +11 -0
  123. package/dist/types/type/variant.d.ts +12 -0
  124. package/documentation.json +568 -0
  125. package/loader/cdn.js +3 -0
  126. package/loader/index.cjs.js +3 -0
  127. package/loader/index.d.ts +21 -0
  128. package/loader/index.es2017.js +3 -0
  129. package/loader/index.js +4 -0
  130. package/loader/package.json +11 -0
  131. package/package.json +59 -0
  132. package/readme.md +33 -0
  133. package/src/common/aria.ts +39 -0
  134. package/src/common/file.ts +63 -0
  135. package/src/common/icon.ts +25 -0
  136. package/src/common/keyboard-manager.ts +50 -0
  137. package/src/common/locale.ts +31 -0
  138. package/src/common/unit.ts +33 -0
  139. package/src/common/yugop/core.ts +47 -0
  140. package/src/common/yugop/index.ts +4 -0
  141. package/src/common/yugop/random-text.ts +95 -0
  142. package/src/common/yugop/utils/math.ts +21 -0
  143. package/src/common/yugop/utils/noop.ts +1 -0
  144. package/src/common/yugop/utils/prng.ts +35 -0
  145. package/src/common/yugop/utils/string.ts +4 -0
  146. package/src/components/mds-input-tip/.gitlab-ci.yml +25 -0
  147. package/src/components/mds-input-tip/mds-input-tip.css +52 -0
  148. package/src/components/mds-input-tip/mds-input-tip.tsx +28 -0
  149. package/src/components/mds-input-tip/meta/types.ts +3 -0
  150. package/src/components/mds-input-tip/readme.md +18 -0
  151. package/src/components/mds-input-tip/test/mds-input-tip.e2e.ts +11 -0
  152. package/src/components.d.ts +55 -0
  153. package/src/dictionary/autocomplete.ts +62 -0
  154. package/src/dictionary/button.ts +41 -0
  155. package/src/dictionary/color.ts +24 -0
  156. package/src/dictionary/file-extensions.ts +81 -0
  157. package/src/dictionary/floating-ui.ts +25 -0
  158. package/src/dictionary/icon.ts +15 -0
  159. package/src/dictionary/input.ts +48 -0
  160. package/src/dictionary/loading.ts +9 -0
  161. package/src/dictionary/text.ts +9 -0
  162. package/src/dictionary/typography.ts +88 -0
  163. package/src/dictionary/variant.ts +111 -0
  164. package/src/fixtures/cities.ts +116 -0
  165. package/src/fixtures/filenames.ts +60 -0
  166. package/src/fixtures/icons.json +344 -0
  167. package/src/fixtures/iconsauce.json +257 -0
  168. package/src/interface/input-value.ts +5 -0
  169. package/src/tailwind/components.css +15 -0
  170. package/src/type/autocomplete.ts +69 -0
  171. package/src/type/button.ts +28 -0
  172. package/src/type/file-types.ts +55 -0
  173. package/src/type/floating-ui.ts +17 -0
  174. package/src/type/form-rel.ts +11 -0
  175. package/src/type/input.ts +25 -0
  176. package/src/type/loading.ts +3 -0
  177. package/src/type/text.ts +4 -0
  178. package/src/type/typography.ts +65 -0
  179. package/src/type/variant-file-format.ts +137 -0
  180. package/src/type/variant.ts +99 -0
  181. package/www/build/index.esm.js +0 -0
  182. package/www/build/mds-input-tip.esm.js +1 -0
  183. package/www/build/mds-input-tip.js +127 -0
  184. package/www/build/p-22b86e20.js +2 -0
  185. package/www/build/p-3428f886.system.js +2 -0
  186. package/www/build/p-50ea2036.system.js +1 -0
  187. package/www/build/p-630886b5.entry.js +1 -0
  188. package/www/build/p-89e037f5.system.entry.js +1 -0
  189. package/www/build/p-e5fe0b68.system.js +1 -0
  190. package/www/host.config.json +15 -0
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@maggioli-design-system/mds-input-tip",
3
+ "version": "1.0.0",
4
+ "description": "mds-input-tip 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-tip/mds-input-tip.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/mds-input-tip-item": "1.0.0",
28
+ "@maggioli-design-system/styles": "14.3.2",
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": "Andrea Pruccoli",
40
+ "email": "andrea.pruccoli@maggioli.it",
41
+ "role": "Software Engineer"
42
+ },
43
+ {
44
+ "name": "Daniele Tardia",
45
+ "email": "daniele.tardia@hibo.it",
46
+ "role": "Senior Developer"
47
+ },
48
+ {
49
+ "name": "Nicola Tamburini",
50
+ "email": "nicola.tamburini@maggioli.it",
51
+ "role": "Software Engineer"
52
+ },
53
+ {
54
+ "name": "Vittorio Vittori",
55
+ "email": "vittorio.vittori@maggioli.it",
56
+ "role": "Product Designer"
57
+ }
58
+ ]
59
+ }
package/readme.md ADDED
@@ -0,0 +1,33 @@
1
+ # mds-input-tip
2
+
3
+
4
+
5
+ <!-- Auto Generated Below -->
6
+
7
+
8
+ ## Properties
9
+
10
+ | Property | Attribute | Description | Type | Default |
11
+ | ---------- | ---------- | --------------------------------------------------------------- | -------------------------------- | ------- |
12
+ | `active` | `active` | Specifies the position of the element relative to its container | `boolean \| undefined` | `false` |
13
+ | `position` | `position` | Specifies the position of the element relative to its container | `"bottom" \| "top" \| undefined` | `'top'` |
14
+
15
+
16
+ ## Dependencies
17
+
18
+ ### Used by
19
+
20
+ - [mds-input](../mds-input)
21
+ - [mds-input-select](../mds-input-select)
22
+
23
+ ### Graph
24
+ ```mermaid
25
+ graph TD;
26
+ mds-input --> mds-input-tip
27
+ mds-input-select --> mds-input-tip
28
+ style mds-input-tip fill:#f9f,stroke:#333,stroke-width:4px
29
+ ```
30
+
31
+ ----------------------------------------------
32
+
33
+ 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,31 @@
1
+ type LocaleConfig = {
2
+ it?: Record<string, string>
3
+ en?: Record<string, string>
4
+ gr?: Record<string, string>
5
+ }
6
+
7
+ export class Locale {
8
+ defaultLanguage: string = 'en'
9
+ language: string
10
+ config: LocaleConfig
11
+
12
+ constructor (configData: LocaleConfig) {
13
+ this.config = configData
14
+ }
15
+
16
+ lang = (element: HTMLElement): void => {
17
+ const closestElement:HTMLElement = element.closest('[lang]') as HTMLElement
18
+ if (closestElement) {
19
+ if (closestElement.lang) {
20
+ this.language = closestElement.lang
21
+ return
22
+ }
23
+ }
24
+
25
+ this.language = this.defaultLanguage
26
+ }
27
+
28
+ get = (tag: string): string => {
29
+ return this.config[this.language][tag] ?? this.config[this.defaultLanguage][tag]
30
+ }
31
+ }
@@ -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-tip:
2
+ variables:
3
+ COMPONENT: mds-input-tip
4
+
5
+ # ISOLATE
6
+ input-tip-isolate:
7
+ extends: [.base-isolate, .base-input-tip]
8
+ dependencies: [base-stencil-build]
9
+
10
+ # TEST
11
+ input-tip-publish-test:
12
+ extends: [.base-stencil-publish-test, .base-input-tip]
13
+ dependencies: [base-stencil-build, input-tip-isolate]
14
+
15
+ # PUBLISH
16
+ input-tip-publish:
17
+ extends: [.base-stencil-publish, .base-input-tip]
18
+ dependencies: [base-stencil-build, input-tip-isolate]
19
+ needs: [base-stencil-build, input-tip-isolate, input-tip-publish-test]
20
+
21
+ # INSTALL TEST
22
+ input-tip-install-test:
23
+ extends: [.base-stencil-install-test, .base-input-tip]
24
+ dependencies: [base-stencil-build, input-tip-isolate]
25
+ needs: [base-stencil-build, input-tip-isolate, input-tip-publish]
@@ -0,0 +1,52 @@
1
+ @tailwind utilities;
2
+
3
+ :host {
4
+
5
+ --mds-input-tip-active-translate: translate(0, 0);
6
+
7
+ @apply
8
+ duration-300
9
+ ease-out-expo
10
+ gap-100
11
+ left-100
12
+ right-100
13
+ transition-cosmetic;
14
+
15
+ display: flex;
16
+ justify-content: flex-end;
17
+ pointer-events: none;
18
+ position: absolute;
19
+ transform: var(--mds-input-tip-active-translate);
20
+ }
21
+
22
+ :host ( :empty ) {
23
+ display: none;
24
+ }
25
+
26
+ :host ( [position="top"] ) {
27
+ top: theme('spacing.100');
28
+ }
29
+
30
+ :host ( [position="bottom"] ) {
31
+ bottom: theme('spacing.100');
32
+ }
33
+
34
+ :host ( [position="top"][active]:not([active="false"]) ) {
35
+
36
+ --mds-input-tip-active-translate: translate(calc(theme('translate.100') * -1), calc(theme('translate.100') * -1));
37
+ }
38
+
39
+ :host( [position="top"][active]:not([active="false"]) ) ::slotted( mds-input-tip-item ) {
40
+ border-top-left-radius: 0;
41
+ border-top-right-radius: 0;
42
+ }
43
+
44
+ :host ( [position="bottom"][active]:not([active="false"]) ) {
45
+
46
+ --mds-input-tip-active-translate: translate(calc(theme('translate.100') * -1), theme('translate.100'));
47
+ }
48
+
49
+ :host( [position="bottom"][active]:not([active="false"]) ) ::slotted( mds-input-tip-item ) {
50
+ border-bottom-left-radius: 0;
51
+ border-bottom-right-radius: 0;
52
+ }
@@ -0,0 +1,28 @@
1
+ import { Component, Host, h, Prop } from '@stencil/core'
2
+ import { InputTipPositionType } from './meta/types'
3
+
4
+ @Component({
5
+ tag: 'mds-input-tip',
6
+ styleUrl: 'mds-input-tip.css',
7
+ shadow: true,
8
+ })
9
+ export class MdsInputTip {
10
+
11
+ /**
12
+ * Specifies the position of the element relative to its container
13
+ */
14
+ @Prop({ reflect: true }) readonly active?: boolean = false
15
+
16
+ /**
17
+ * Specifies the position of the element relative to its container
18
+ */
19
+ @Prop({ reflect: true }) readonly position?: InputTipPositionType = 'top'
20
+
21
+ render () {
22
+ return (
23
+ <Host>
24
+ <slot></slot>
25
+ </Host>
26
+ )
27
+ }
28
+ }
@@ -0,0 +1,3 @@
1
+ export type InputTipPositionType =
2
+ | 'top'
3
+ | 'bottom'
@@ -0,0 +1,18 @@
1
+ # mds-input-tip
2
+
3
+
4
+
5
+ <!-- Auto Generated Below -->
6
+
7
+
8
+ ## Properties
9
+
10
+ | Property | Attribute | Description | Type | Default |
11
+ | ---------- | ---------- | --------------------------------------------------------------- | -------------------------------- | ------- |
12
+ | `active` | `active` | Specifies the position of the element relative to its container | `boolean \| undefined` | `false` |
13
+ | `position` | `position` | Specifies the position of the element relative to its container | `"bottom" \| "top" \| undefined` | `'top'` |
14
+
15
+
16
+ ----------------------------------------------
17
+
18
+ Built with love @ [Gruppo Maggioli](https://www.maggioli.com) from [R&D Department](https://www.maggioli.com/it-it/chi-siamo/ricerca-sviluppo)