@blackbyte/sugar 1.0.0-beta.1 → 1.0.0-beta.3

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 (149) hide show
  1. package/README.md +267 -1
  2. package/dist/js/dom/css/reloadStylesheets.d.ts +1 -1
  3. package/dist/js/dom/distance/distanceFromElementTopToViewportBottom.d.ts +2 -2
  4. package/dist/js/dom/distance/distanceFromElementTopToViewportBottom.js +3 -3
  5. package/dist/js/dom/distance/distanceFromElementTopToViewportBottom.js.map +1 -1
  6. package/dist/js/dom/distance/distanceFromElementTopToViewportTop.d.ts +2 -2
  7. package/dist/js/dom/distance/distanceFromElementTopToViewportTop.js +3 -3
  8. package/dist/js/dom/distance/distanceFromElementTopToViewportTop.js.map +1 -1
  9. package/dist/js/dom/event/viewportEvents.d.ts +2 -2
  10. package/dist/js/dom/form/generateIdFromForm.d.ts +2 -2
  11. package/dist/js/dom/form/generateIdFromForm.js +2 -2
  12. package/dist/js/dom/form/getFormValues.d.ts +2 -2
  13. package/dist/js/dom/form/getFormValues.js +2 -2
  14. package/dist/js/dom/iframe/iframeAutoSize.d.ts +3 -3
  15. package/dist/js/dom/iframe/iframeAutoSize.js +3 -3
  16. package/dist/js/dom/inject/injectHtml.d.ts +2 -2
  17. package/dist/js/dom/inject/injectHtml.js +2 -2
  18. package/dist/js/dom/inject/injectIframeContent.d.ts +1 -1
  19. package/dist/js/dom/inject/injectIframeContent.js +1 -1
  20. package/dist/js/dom/inject/injectScript.d.ts +1 -1
  21. package/dist/js/dom/inject/injectScript.js +1 -1
  22. package/dist/js/dom/inject/injectStyle.d.ts +1 -1
  23. package/dist/js/dom/offset/offsetFromParent.d.ts +2 -2
  24. package/dist/js/dom/offset/offsetFromParent.js +2 -2
  25. package/dist/js/dom/offset/offsetFromViewport.d.ts +4 -4
  26. package/dist/js/dom/offset/offsetFromViewport.js +5 -5
  27. package/dist/js/dom/offset/offsetFromViewport.js.map +1 -1
  28. package/dist/js/dom/on/onDrag.d.ts +3 -3
  29. package/dist/js/dom/on/onScrollEnd.d.ts +2 -2
  30. package/dist/js/dom/on/onSwipe.d.ts +9 -9
  31. package/dist/js/dom/on/onSwipe.js +9 -9
  32. package/dist/js/dom/position/positionFromEvent.d.ts +21 -3
  33. package/dist/js/dom/position/positionFromEvent.js +29 -4
  34. package/dist/js/dom/position/positionFromEvent.js.map +1 -1
  35. package/dist/js/dom/query/closestElement.d.ts +8 -8
  36. package/dist/js/dom/query/closestElement.js +8 -8
  37. package/dist/js/dom/query/closestNotVisibleElement.d.ts +2 -2
  38. package/dist/js/dom/query/closestNotVisibleElement.js +2 -2
  39. package/dist/js/dom/query/elementsInViewport.d.ts +2 -1
  40. package/dist/js/dom/query/elementsInViewport.js.map +1 -1
  41. package/dist/js/dom/query/matches.d.ts +1 -1
  42. package/dist/js/dom/query/matches.js +1 -1
  43. package/dist/js/dom/query/nearestElement.d.ts +5 -3
  44. package/dist/js/dom/query/nearestElement.js.map +1 -1
  45. package/dist/js/dom/query/nextElement.d.ts +2 -2
  46. package/dist/js/dom/query/nextElement.js +2 -2
  47. package/dist/js/dom/query/previousElement.d.ts +2 -2
  48. package/dist/js/dom/query/previousElement.js +2 -2
  49. package/dist/js/dom/query/querySelector.d.ts +3 -3
  50. package/dist/js/dom/query/querySelector.js +8 -2
  51. package/dist/js/dom/query/querySelector.js.map +1 -1
  52. package/dist/js/dom/query/querySelectorAll.d.ts +3 -3
  53. package/dist/js/dom/query/querySelectorAll.js +8 -2
  54. package/dist/js/dom/query/querySelectorAll.js.map +1 -1
  55. package/dist/js/dom/query/querySelectorLive.d.ts +6 -6
  56. package/dist/js/dom/query/querySelectorLive.js +9 -3
  57. package/dist/js/dom/query/querySelectorLive.js.map +1 -1
  58. package/dist/js/dom/query/querySelectorUp.d.ts +3 -3
  59. package/dist/js/dom/query/querySelectorUp.js +3 -3
  60. package/dist/js/dom/style/getAnimationProperties.d.ts +2 -2
  61. package/dist/js/dom/style/getCssDeclarations.d.ts +1 -1
  62. package/dist/js/dom/style/getCssDeclarations.js +1 -1
  63. package/dist/js/dom/style/getRotateProperties.d.ts +1 -1
  64. package/dist/js/dom/style/getRotateProperties.js +1 -1
  65. package/dist/js/dom/style/getScaleProperty.d.ts +1 -1
  66. package/dist/js/dom/style/getStyleProperty.d.ts +2 -2
  67. package/dist/js/dom/style/getStyleProperty.js +2 -2
  68. package/dist/js/dom/style/getTransformProperties.d.ts +4 -4
  69. package/dist/js/dom/style/getTransitionProperties.d.ts +2 -2
  70. package/dist/js/dom/style/getTranslateProperties.d.ts +1 -1
  71. package/dist/js/dom/when/whenAnimationEnd.d.ts +2 -2
  72. package/dist/js/dom/when/whenAnimationEnd.js +2 -2
  73. package/dist/js/dom/when/whenAttribute.d.ts +9 -9
  74. package/dist/js/dom/when/whenDomReady.d.ts +2 -2
  75. package/dist/js/dom/when/whenDomReady.js +2 -2
  76. package/dist/js/dom/when/whenEntersViewport.d.ts +2 -2
  77. package/dist/js/dom/when/whenEventListener.d.ts +3 -3
  78. package/dist/js/dom/when/whenEventListener.js +3 -3
  79. package/dist/js/dom/when/whenIframeReady.d.ts +2 -2
  80. package/dist/js/dom/when/whenIframeReady.js +2 -2
  81. package/dist/js/dom/when/whenImageLoaded.d.ts +3 -3
  82. package/dist/js/dom/when/whenImageLoaded.js +3 -3
  83. package/dist/js/dom/when/whenImagesLoaded.d.ts +2 -4
  84. package/dist/js/dom/when/whenImagesLoaded.js +2 -4
  85. package/dist/js/dom/when/whenImagesLoaded.js.map +1 -1
  86. package/dist/js/dom/when/whenInViewport.d.ts +3 -3
  87. package/dist/js/dom/when/whenInteract.d.ts +1 -1
  88. package/dist/js/dom/when/whenInteract.js +1 -1
  89. package/dist/js/dom/when/whenLinkLoaded.js +3 -3
  90. package/dist/js/dom/when/whenNearViewport.d.ts +3 -3
  91. package/dist/js/dom/when/whenOutOfViewport.d.ts +3 -3
  92. package/dist/js/dom/when/whenOutOfViewport.js +3 -3
  93. package/dist/js/dom/when/whenRemoved.d.ts +3 -3
  94. package/dist/js/dom/when/whenRemoved.js +3 -3
  95. package/dist/js/dom/when/whenStylesheetsReady.d.ts +5 -5
  96. package/dist/js/dom/when/whenStylesheetsReady.js +8 -8
  97. package/dist/js/dom/when/whenStylesheetsReady.js.map +1 -1
  98. package/dist/js/dom/when/whenTransitionEnd.d.ts +1 -1
  99. package/dist/js/dom/when/whenTransitionEnd.js +1 -1
  100. package/dist/js/dom/when/whenVisible.d.ts +1 -1
  101. package/dist/js/feature/scrollProperties.d.ts +8 -4
  102. package/dist/js/feature/scrollProperties.js +7 -4
  103. package/dist/js/feature/scrollProperties.js.map +1 -1
  104. package/dist/js/feature/sectionClasses.d.ts +3 -7
  105. package/dist/js/feature/sectionClasses.js +3 -7
  106. package/dist/js/feature/sectionClasses.js.map +1 -1
  107. package/dist/js/is/isDarkMode.js +2 -2
  108. package/dist/js/is/isDarkMode.js.map +1 -1
  109. package/dist/js/is/isInViewport.d.ts +1 -1
  110. package/dist/js/is/isInViewport.js +1 -1
  111. package/dist/js/is/isUserScrolling.js +1 -1
  112. package/dist/js/is/isVisible.d.ts +1 -1
  113. package/dist/js/is/isVisible.js +1 -1
  114. package/dist/js/keyboard/hotkey.d.ts +4 -4
  115. package/dist/js/keyboard/hotkey.js +4 -4
  116. package/dist/js/scroll/scrollTo.d.ts +5 -5
  117. package/dist/js/theme/restoreTheme.d.ts +2 -2
  118. package/dist/js/theme/setTheme.d.ts +0 -2
  119. package/dist/js/theme/setTheme.js.map +1 -1
  120. package/dist/node/fs/ensureDirSync.js +1 -8
  121. package/dist/node/fs/ensureDirSync.js.map +1 -1
  122. package/dist/node/fs/writeFile.js +3 -3
  123. package/dist/node/fs/writeFile.js.map +1 -1
  124. package/dist/shared/array/unique.d.ts +11 -5
  125. package/dist/shared/array/unique.js +15 -25
  126. package/dist/shared/array/unique.js.map +1 -1
  127. package/dist/shared/color/hslaToRgba.js +2 -2
  128. package/dist/shared/console/SugarConsole.js +5 -5
  129. package/dist/shared/console/SugarConsole.js.map +1 -1
  130. package/dist/shared/css/transform/styleObjectToString.d.ts +2 -2
  131. package/dist/shared/css/transform/styleObjectToString.js +2 -2
  132. package/dist/shared/css/transform/styleStringToObject.d.ts +2 -2
  133. package/dist/shared/css/transform/styleStringToObject.js +2 -2
  134. package/dist/shared/currency/_exports.d.ts +4 -0
  135. package/dist/shared/currency/_exports.js +5 -0
  136. package/dist/shared/currency/_exports.js.map +1 -0
  137. package/dist/shared/currency/currencyCodeToSymbol.d.ts +24 -0
  138. package/dist/shared/currency/currencyCodeToSymbol.js +33 -0
  139. package/dist/shared/currency/currencyCodeToSymbol.js.map +1 -0
  140. package/dist/shared/currency/currencyStringToObject.d.ts +40 -0
  141. package/dist/shared/currency/currencyStringToObject.js +27 -0
  142. package/dist/shared/currency/currencyStringToObject.js.map +1 -0
  143. package/dist/shared/currency/currencySymbolToCode.d.ts +24 -0
  144. package/dist/shared/currency/currencySymbolToCode.js +34 -0
  145. package/dist/shared/currency/currencySymbolToCode.js.map +1 -0
  146. package/dist/shared/url/_exports.d.ts +5 -5
  147. package/dist/shared/url/_exports.js +5 -5
  148. package/dist/shared/url/_exports.js.map +1 -1
  149. package/package.json +26 -6
package/README.md CHANGED
@@ -1,3 +1,269 @@
1
+ ![Blackbyte Sugar](https://github.com/Blackbytespace/sugar/blob/main/assets/blackbyte-sugar-og.png?raw=true)
2
+
1
3
  # Blackbyte Sugar
2
4
 
3
- TBD
5
+ The toolkit that you missed... like a sugar in your coffee!
6
+
7
+ ## [Go to website!](https://sugar.blackbyte.space)
8
+
9
+ ---
10
+
11
+ <!-- @import "[TOC]" {cmd="toc" depthFrom=1 depthTo=6 orderedList=false} -->
12
+
13
+ <!-- code_chunk_output -->
14
+
15
+ - [Blackbyte Sugar](#blackbyte-sugar)
16
+ - [Go to website!](#go-to-websitehttpssugarblackbytespace)
17
+ - [What is this?](#what-is-this)
18
+ - [Get started](#get-started)
19
+ - [1. Install the package](#1-install-the-package)
20
+ - [2. Discover the API](#2-discover-the-api)
21
+ - [3. Import what you need](#3-import-what-you-need)
22
+ - [Samples](#samples)
23
+ - [Query like a pro](#query-like-a-pro)
24
+ - [Is this a...?](#is-this-a)
25
+ - [Cryptography](#cryptography)
26
+ - [Execute this when...](#execute-this-when)
27
+ - [Array utilities](#array-utilities)
28
+ - [Convert colors](#convert-colors)
29
+ - [Time is... time](#time-is-time)
30
+ - [Contribute](#contribute)
31
+
32
+ <!-- /code_chunk_output -->
33
+
34
+ ---
35
+
36
+ ## What is this?
37
+
38
+ This project has for goal to provide high quality utilities through 1 package. Consider this as a swiss knife for web development.
39
+
40
+ It will continue to grow with utilities that make sens and that we can make use of everyday. The goal is to make our daily job as pleasant as possible.
41
+
42
+ Don't be afraid to propose some new utilities. Make sure to read [our contribution guidelines first](./CONTRIBUTE.md).
43
+
44
+ ## Get started
45
+
46
+ Start using `@blackbyte/sugar` in your project with this quick guide.
47
+
48
+ ### 1. Install the package
49
+
50
+ You can install `@blackbyte/sugar` using npm, yarn or pnpm.
51
+
52
+ ```sh
53
+ npm install @blackbyte/sugar
54
+ ```
55
+
56
+ ### 2. Discover the API
57
+
58
+ Go to the official [sugar.blackbyte.space](https://sugar.blackbyte.space) website to discover the full API.
59
+
60
+ Press `CMD + P` on the website to open the command palette and start typing to search for available functions.
61
+
62
+ ### 3. Import what you need
63
+
64
+ Import the components you need from `@blackbyte/sugar` in your project files.
65
+
66
+ ```ts
67
+ import { querySelectorLive } from '@blackbyte/sugar/dom';
68
+ import { pickRandom, unique } from '@blackbyte/sugar/array';
69
+ import { sleep, timeAgo } from '@blackbyte/sugar/datetime';
70
+ import { formatFileSize, formatDuration } from '@blackbyte/sugar/format';
71
+ // etc...
72
+ ```
73
+
74
+ ## Samples
75
+
76
+ #### Query like a pro
77
+
78
+ A set of utility functions to query the DOM in a more efficient way.
79
+
80
+ ```ts
81
+ import {
82
+ querySelector,
83
+ querySelectorLive,
84
+ querySelectorUp,
85
+ } from '@blackbyte/sugar/dom';
86
+ // query the first element that is in the viewport
87
+ const $elm = querySelector('.my-cool-item', {
88
+ inViewport: true,
89
+ });
90
+ // live query some elements when they are added to the DOM
91
+ const query = querySelectorLive('.my-cool-item', ($elm, api) => {
92
+ // do something here with the detected element
93
+ // call api.cancel if you want to stop listening for this selector
94
+ api.cancel();
95
+ });
96
+ // query the first element that is a parent of the given selector
97
+ const $elmUp = querySelectorUp($from, '.my-cool-item');
98
+ ```
99
+
100
+ #### Is this a...?
101
+
102
+ A bunch of utility functions to validate common data types like email, path, etc.
103
+
104
+ ```ts
105
+ import {
106
+ isEmail,
107
+ isPath,
108
+ isNode,
109
+ isUrl,
110
+ isGlob,
111
+ isCreditCard,
112
+ isPlainObject,
113
+ isJson,
114
+ } from '@blackbyte/sugar/dom';
115
+ isEmail('hello@blackbyte.com'); // true
116
+ isPath('/path/to/file'); // true
117
+ isNode(); // true if runtime is node, false if not
118
+ isUrl('https://blackbyte.space'); // true
119
+ isGlob('*.js'); // true
120
+ isCreditCard('4111111111111111'); // true
121
+ isPlainObject({}); // true
122
+ isJson('{"key": "value"}'); // true
123
+ // and a lot more to discover
124
+ ```
125
+
126
+ #### Cryptography
127
+
128
+ A set of cryptographic functions for hashing and encoding data.
129
+
130
+ ```ts
131
+ import { md5, base64, sha256, sha512 } from '@blackbyte/sugar/crypto';
132
+
133
+ // md5 hash
134
+ md5.encrypt('hello world');
135
+ // 5eb63bbbe01eeed093cb22bb8f5acdc3
136
+ // base64 encode
137
+ base64.encrypt('hello world');
138
+ // aGVsbG8gd29ybGQ=
139
+ // sha256 hash
140
+ sha256.encrypt('hello world');
141
+ // b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
142
+ // sha512 hash
143
+ sha512.encrypt('hello world');
144
+ // 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd...
145
+ // and a lot more to discover
146
+ ```
147
+
148
+ #### Execute this when...
149
+
150
+ A set of utility functions to execute code when certain conditions are met.
151
+
152
+ ```ts
153
+ import {
154
+ whenVisible,
155
+ whenInViewport,
156
+ whenNearViewport,
157
+ whenImageLoaded,
158
+ whenInteract,
159
+ } from '@blackbyte/sugar/dom';
160
+ // execute code when the element is visible
161
+ whenVisible($elm).then(() => {
162
+ console.log('Element is visible');
163
+ });
164
+ // execute code when the element is in the viewport
165
+ whenInViewport($elm).then(() => {
166
+ console.log('Element is in the viewport');
167
+ });
168
+ // execute code when the element is near the viewport
169
+ whenNearViewport($elm).then(() => {
170
+ console.log('Element is near the viewport');
171
+ });
172
+ // execute code when the image is loaded
173
+ whenImageLoaded($img).then(() => {
174
+ console.log('Image is loaded');
175
+ });
176
+ // execute code when the element is interacted with
177
+ whenInteract($elm).then(() => {
178
+ console.log('Element is interacted with');
179
+ });
180
+ // and a lot more to discover
181
+ ```
182
+
183
+ #### Array utilities
184
+
185
+ A set of utility functions to manipulate arrays in a more efficient way.
186
+
187
+ ```ts
188
+ import {
189
+ pickRandom,
190
+ pickSome,
191
+ intersection,
192
+ splitEvery,
193
+ unique
194
+ } from '@blackbyte/sugar/array'
195
+ // pick a random element from the array
196
+ pickRandom([1, 2, 3, 4, 5])]
197
+ // pick some elements from the array randomly
198
+ pickSome([1, 2, 3, 4, 5], 2) // [2, 4]
199
+ // find the intersection of two arrays
200
+ intersection([1, 2, 3], [2, 3, 4]) // [2, 3]
201
+ // split an array into chunks
202
+ splitEvery([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]
203
+ // get unique elements from an array
204
+ unique([1, 2, 2, 3, 4, 4, 5]) // [1, 2, 3, 4, 5]
205
+ // and a lot more to discover
206
+ ```
207
+
208
+ #### Convert colors
209
+
210
+ A set of utility functions to manipulate colors in a more efficient way.
211
+
212
+ ```ts
213
+ import {
214
+ hexToRgba,
215
+ hexToRgb,
216
+ hslaToHexa,
217
+ hslaToRgba,
218
+ parseColor,
219
+ convertColor,
220
+ } from '@blackbyte/sugar/array';
221
+ // convert hex to rgba
222
+ hexToRgba('#ff0000'); // { r: 255, g: 0, b: 0, a: 1, toString }
223
+ // convert hex to rgb
224
+ hexToRgb('#ff0000'); // { r: 255, g: 0, b: 0, toString }
225
+ // convert hsla to hexa
226
+ hslaToHexa('hsla(0, 100%, 50%, 1)'); // #ff0000ff
227
+ // convert hsla to rgba
228
+ hslaToRgba('hsla(0, 100%, 50%, 1)'); // { r: 255, g: 0, b: 0, a: 1, toString }
229
+ // parse a color string
230
+ parseColor('#ff0000'); // { r: 255, g: 0, b: 0, a: 1, toString }
231
+ parseColor('#ff0000', 'hsla'); // { h: 0, s: 100, l: 50, a: 1, toString }
232
+ // convert a color to a specific format
233
+ convertColor('#ff0000', 'rgba'); // { r: 255, g: 0, b: 0, a: 1, toString }
234
+ convertColor('#ff0000', 'hsl'); // { h: 0, s: 100, l: 50, toString }
235
+ convertColor('#ff0000', 'hex'); // #ff0000
236
+ // and a lot more to discover
237
+ ```
238
+
239
+ #### Time is... time
240
+
241
+ A set of utility functions to manipulate time in a more efficient way.
242
+
243
+ ```ts
244
+ import {
245
+ convertTime,
246
+ sleep,
247
+ timeAgo,
248
+ formatDuration,
249
+ } from '@blackbyte/sugar/datetime';
250
+ // convert time from one format to another
251
+ convertTime('10s', 'ms'); // => 10000
252
+ convertTime('10days', 'hours'); // => 240
253
+ convertTime('10h', 'minutes'); // => 600
254
+ // format a duration in a human readable way
255
+ formatDuration(1000); // => 1s
256
+ formatDuration(60000); // => 1m
257
+ // sleep for a given time
258
+ await sleep(1000); // => waits for 1 second
259
+ // get the time ago from a date
260
+ timeAgo(new Date('2023-01-01')); // => "9 months ago"
261
+ timeAgo(1704067200000); // => "9 months ago"
262
+ // and a lot more to discover
263
+ ```
264
+
265
+ ## Contribute
266
+
267
+ To contribute, make sure to [follow our contribution rules](./CONTRIBUTE.md).
268
+
269
+ Everyone is welcome as long that it's made in good intelligence and respect 💜.
@@ -14,7 +14,7 @@
14
14
  * @snippet reloadStylesheets()
15
15
  *
16
16
  * @example js
17
- * import { __reloeadStylesheets } from '@blackbyte/sugar/dom';
17
+ * import { reloeadStylesheets } from '@blackbyte/sugar/dom';
18
18
  * reloadStylesheets();
19
19
  *
20
20
  * @since 1.0.0
@@ -8,7 +8,7 @@
8
8
  * This function take an element as parameter and returns you to distance it has
9
9
  * from the element top to the viewport bottom in pixels
10
10
  *
11
- * @param {HTMLElement} elm The element you want to get the distance from
11
+ * @param {HTMLElement} $elm The element you want to get the distance from
12
12
  * @return {Number} The calculated distance
13
13
  *
14
14
  * @snippet distanceFromElementTopToViewportBottom($1)
@@ -20,4 +20,4 @@
20
20
  * @since 1.0.0
21
21
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
22
22
  */
23
- export default function distanceFromElementTopToViewportBottom(elm: HTMLElement): number;
23
+ export default function distanceFromElementTopToViewportBottom($elm: HTMLElement): number;
@@ -10,7 +10,7 @@ import offsetFromViewport from '../offset/offsetFromViewport.js';
10
10
  * This function take an element as parameter and returns you to distance it has
11
11
  * from the element top to the viewport bottom in pixels
12
12
  *
13
- * @param {HTMLElement} elm The element you want to get the distance from
13
+ * @param {HTMLElement} $elm The element you want to get the distance from
14
14
  * @return {Number} The calculated distance
15
15
  *
16
16
  * @snippet distanceFromElementTopToViewportBottom($1)
@@ -22,8 +22,8 @@ import offsetFromViewport from '../offset/offsetFromViewport.js';
22
22
  * @since 1.0.0
23
23
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
24
24
  */
25
- export default function distanceFromElementTopToViewportBottom(elm) {
26
- const offsets = offsetFromViewport(elm);
25
+ export default function distanceFromElementTopToViewportBottom($elm) {
26
+ const offsets = offsetFromViewport($elm);
27
27
  const scrollTop = __scrollTop();
28
28
  // @ts-ignore
29
29
  const viewportHeight = window.innerHeight;
@@ -1 +1 @@
1
- {"version":3,"file":"distanceFromElementTopToViewportBottom.js","sourceRoot":"","sources":["../../../../src/js/dom/distance/distanceFromElementTopToViewportBottom.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,kBAAkB,MAAM,iCAAiC,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,OAAO,UAAU,sCAAsC,CAC5D,GAAgB;IAEhB,MAAM,OAAO,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,SAAS,GAAG,WAAW,EAAE,CAAC;IAChC,aAAa;IACb,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC;IAC1C,MAAM,QAAQ,GAAG,cAAc,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC;IAC1D,OAAO,QAAQ,CAAC;AAClB,CAAC"}
1
+ {"version":3,"file":"distanceFromElementTopToViewportBottom.js","sourceRoot":"","sources":["../../../../src/js/dom/distance/distanceFromElementTopToViewportBottom.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,kBAAkB,MAAM,iCAAiC,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,OAAO,UAAU,sCAAsC,CAC5D,IAAiB;IAEjB,MAAM,OAAO,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,SAAS,GAAG,WAAW,EAAE,CAAC;IAChC,aAAa;IACb,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC;IAC1C,MAAM,QAAQ,GAAG,cAAc,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC;IAC1D,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -8,7 +8,7 @@
8
8
  * This function take an element as parameter and returns you to distance it has
9
9
  * from the element top to the viewport top in pixels
10
10
  *
11
- * @param {HTMLElement} elm The element you want to get the distance from
11
+ * @param {HTMLElement} $elm The element you want to get the distance from
12
12
  * @return {Number} The calculated distance
13
13
  *
14
14
  * @snippet distanceFromElementTopToViewportTop($1)
@@ -20,4 +20,4 @@
20
20
  * @since 1.0.0
21
21
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
22
22
  */
23
- export default function distanceFromElementTopToViewportTop(elm: HTMLElement): number;
23
+ export default function distanceFromElementTopToViewportTop($elm: HTMLElement): number;
@@ -10,7 +10,7 @@ import offsetFromViewport from '../offset/offsetFromViewport.js';
10
10
  * This function take an element as parameter and returns you to distance it has
11
11
  * from the element top to the viewport top in pixels
12
12
  *
13
- * @param {HTMLElement} elm The element you want to get the distance from
13
+ * @param {HTMLElement} $elm The element you want to get the distance from
14
14
  * @return {Number} The calculated distance
15
15
  *
16
16
  * @snippet distanceFromElementTopToViewportTop($1)
@@ -22,8 +22,8 @@ import offsetFromViewport from '../offset/offsetFromViewport.js';
22
22
  * @since 1.0.0
23
23
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
24
24
  */
25
- export default function distanceFromElementTopToViewportTop(elm) {
26
- const offsets = offsetFromViewport(elm);
25
+ export default function distanceFromElementTopToViewportTop($elm) {
26
+ const offsets = offsetFromViewport($elm);
27
27
  const scrollTop = __scrollTop();
28
28
  // @ts-ignore
29
29
  return offsets.top - scrollTop;
@@ -1 +1 @@
1
- {"version":3,"file":"distanceFromElementTopToViewportTop.js","sourceRoot":"","sources":["../../../../src/js/dom/distance/distanceFromElementTopToViewportTop.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,kBAAkB,MAAM,iCAAiC,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,OAAO,UAAU,mCAAmC,CACzD,GAAgB;IAEhB,MAAM,OAAO,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,SAAS,GAAG,WAAW,EAAE,CAAC;IAChC,aAAa;IACb,OAAO,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC;AACjC,CAAC"}
1
+ {"version":3,"file":"distanceFromElementTopToViewportTop.js","sourceRoot":"","sources":["../../../../src/js/dom/distance/distanceFromElementTopToViewportTop.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,kBAAkB,MAAM,iCAAiC,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,OAAO,UAAU,mCAAmC,CACzD,IAAiB;IAEjB,MAAM,OAAO,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,SAAS,GAAG,WAAW,EAAE,CAAC;IAChC,aAAa;IACb,OAAO,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC;AACjC,CAAC"}
@@ -29,10 +29,10 @@
29
29
  * import { viewportEvents } from '@blackbyte/sugar/dom';
30
30
  * viewportEvents($elm);
31
31
  * $elm.addEventListener('viewport.enter', (e) => {
32
- * // do something on enter
32
+ * // do something on enter
33
33
  * });
34
34
  * $elm.addEventListener('viewport.leave', (e) => {
35
- * // do something on leave
35
+ * // do something on leave
36
36
  * });
37
37
  *
38
38
  * @changelog 1.0.0
@@ -13,8 +13,8 @@
13
13
  *
14
14
  * Note that the named controlls will be sorted before generating the uniqid.
15
15
  *
16
- * @param {HTMLFormElement} $form The form element to generate the uniqid from
17
- * @return {String} A uniqid
16
+ * @param {HTMLFormElement} $form The form element to generate the uniqid from
17
+ * @return {String} A uniqid
18
18
  *
19
19
  * @todo tests
20
20
  *
@@ -14,8 +14,8 @@ import { md5 } from '@blackbyte/sugar/crypto';
14
14
  *
15
15
  * Note that the named controlls will be sorted before generating the uniqid.
16
16
  *
17
- * @param {HTMLFormElement} $form The form element to generate the uniqid from
18
- * @return {String} A uniqid
17
+ * @param {HTMLFormElement} $form The form element to generate the uniqid from
18
+ * @return {String} A uniqid
19
19
  *
20
20
  * @todo tests
21
21
  *
@@ -7,8 +7,8 @@
7
7
  *
8
8
  * This function take a form element and return an object with all the values
9
9
  *
10
- * @param {HTMLFormElement} $form The form element to get the values from
11
- * @return {Object} An object with all the values
10
+ * @param {HTMLFormElement} $form The form element to get the values from
11
+ * @return {Object} An object with all the values
12
12
  *
13
13
  * @todo tests
14
14
  *
@@ -7,8 +7,8 @@
7
7
  *
8
8
  * This function take a form element and return an object with all the values
9
9
  *
10
- * @param {HTMLFormElement} $form The form element to get the values from
11
- * @return {Object} An object with all the values
10
+ * @param {HTMLFormElement} $form The form element to get the values from
11
+ * @return {Object} An object with all the values
12
12
  *
13
13
  * @todo tests
14
14
  *
@@ -8,8 +8,8 @@
8
8
  *
9
9
  * This function allows you to resize an iframe to fit its content.
10
10
  *
11
- * @param {HTMLElement} obj The iframe element to resize
12
- * @param {TIFrameAutoSizeSettings} [settings={}] Some settings to configure your iframe auto size
11
+ * @param {HTMLElement} $iframe The iframe element to resize
12
+ * @param {TIFrameAutoSizeSettings} [settings={}] Some settings to configure your iframe auto size
13
13
  *
14
14
  * @setting {Boolean} [width=true] Specify if you want to resize the width of the iframe
15
15
  * @setting {Boolean} [height=true] Specify if you want to resize the height of the iframe
@@ -21,7 +21,7 @@
21
21
  *
22
22
  * @example js
23
23
  * import { iframeAutoSize } from '@blackbyte/sugar/dom';
24
- * iframeAutoSize($1, $2);
24
+ * iframeAutoSize($iframe);
25
25
  *
26
26
  * @since 1.0.0
27
27
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
@@ -8,8 +8,8 @@
8
8
  *
9
9
  * This function allows you to resize an iframe to fit its content.
10
10
  *
11
- * @param {HTMLElement} obj The iframe element to resize
12
- * @param {TIFrameAutoSizeSettings} [settings={}] Some settings to configure your iframe auto size
11
+ * @param {HTMLElement} $iframe The iframe element to resize
12
+ * @param {TIFrameAutoSizeSettings} [settings={}] Some settings to configure your iframe auto size
13
13
  *
14
14
  * @setting {Boolean} [width=true] Specify if you want to resize the width of the iframe
15
15
  * @setting {Boolean} [height=true] Specify if you want to resize the height of the iframe
@@ -21,7 +21,7 @@
21
21
  *
22
22
  * @example js
23
23
  * import { iframeAutoSize } from '@blackbyte/sugar/dom';
24
- * iframeAutoSize($1, $2);
24
+ * iframeAutoSize($iframe);
25
25
  *
26
26
  * @since 1.0.0
27
27
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * Inject some html into a element and make sure that the scripts are executed
9
9
  *
10
- * @param {HTMLElement} $elm The element to inject content into
10
+ * @param {HTMLElement} $elm The element to inject content into
11
11
  * @param {String} html The html to inject
12
12
  *
13
13
  * @snippet injectHtml($1, $2)
@@ -16,7 +16,7 @@
16
16
  *
17
17
  * @example js
18
18
  * import { injectHtml } from '@blackbyte/sugar/dom'
19
- *  injectHtml('<html>...</html>`, $myElement);
19
+ * injectHtml('<html>...</html>`, $myElement);
20
20
  *
21
21
  * @since 1.0.0
22
22
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * Inject some html into a element and make sure that the scripts are executed
9
9
  *
10
- * @param {HTMLElement} $elm The element to inject content into
10
+ * @param {HTMLElement} $elm The element to inject content into
11
11
  * @param {String} html The html to inject
12
12
  *
13
13
  * @snippet injectHtml($1, $2)
@@ -16,7 +16,7 @@
16
16
  *
17
17
  * @example js
18
18
  * import { injectHtml } from '@blackbyte/sugar/dom'
19
- *  injectHtml('<html>...</html>`, $myElement);
19
+ * injectHtml('<html>...</html>`, $myElement);
20
20
  *
21
21
  * @since 1.0.0
22
22
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
@@ -16,7 +16,7 @@
16
16
  *
17
17
  * @example js
18
18
  * import { injectIframeContent } from '@blackbyte/sugar/dom'
19
- *  injectIframeContent($myIframe, '<html>...</html>');
19
+ * injectIframeContent($myIframe, '<html>...</html>');
20
20
  *
21
21
  * @since 1.0.0
22
22
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
@@ -16,7 +16,7 @@
16
16
  *
17
17
  * @example js
18
18
  * import { injectIframeContent } from '@blackbyte/sugar/dom'
19
- *  injectIframeContent($myIframe, '<html>...</html>');
19
+ * injectIframeContent($myIframe, '<html>...</html>');
20
20
  *
21
21
  * @since 1.0.0
22
22
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
@@ -16,7 +16,7 @@
16
16
  *
17
17
  * @example js
18
18
  * import { injectScript } from '@blackbyte/sugar/dom'
19
- *  injectScript('dist/js/app.js')
19
+ * injectScript('dist/js/app.js')
20
20
  *
21
21
  * @since 1.0.0
22
22
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
@@ -17,7 +17,7 @@ import __whenScriptLoaded from '../when/whenScriptLoaded.js';
17
17
  *
18
18
  * @example js
19
19
  * import { injectScript } from '@blackbyte/sugar/dom'
20
- *  injectScript('dist/js/app.js')
20
+ * injectScript('dist/js/app.js')
21
21
  *
22
22
  * @since 1.0.0
23
23
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
@@ -20,7 +20,7 @@
20
20
  *
21
21
  * @example js
22
22
  * import { injectStyle } from '@blackbyte/sugar/dom';
23
- *  injectStyle('a { color: red; }');
23
+ * injectStyle('a { color: red; }');
24
24
  *
25
25
  * @since 1.0.0
26
26
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * Get the offset top and left of the passed element from his parent top left point
9
9
  *
10
- * @param {HTMLElement} elm The element to get the offset from
10
+ * @param {HTMLElement} $elm The element to get the offset from
11
11
  * @return {top: number; left: number;} The offset top and left object
12
12
  *
13
13
  * @snippet offsetFromParent($1)
@@ -16,7 +16,7 @@
16
16
  *
17
17
  * @example js
18
18
  * import { offsetFromParent } from '@blackbyte/sugar/dom'
19
- * const offsetFromParentElm = offsetFromParent(myCoolElement);
19
+ * const offsetFromParentElm = offsetFromParent($elm);
20
20
  * // output : { top : 200, left : 300 }
21
21
  *
22
22
  * @since 1.0.0
@@ -8,7 +8,7 @@ import offsetFromViewport from './offsetFromViewport.js';
8
8
  *
9
9
  * Get the offset top and left of the passed element from his parent top left point
10
10
  *
11
- * @param {HTMLElement} elm The element to get the offset from
11
+ * @param {HTMLElement} $elm The element to get the offset from
12
12
  * @return {top: number; left: number;} The offset top and left object
13
13
  *
14
14
  * @snippet offsetFromParent($1)
@@ -17,7 +17,7 @@ import offsetFromViewport from './offsetFromViewport.js';
17
17
  *
18
18
  * @example js
19
19
  * import { offsetFromParent } from '@blackbyte/sugar/dom'
20
- * const offsetFromParentElm = offsetFromParent(myCoolElement);
20
+ * const offsetFromParentElm = offsetFromParent($elm);
21
21
  * // output : { top : 200, left : 300 }
22
22
  *
23
23
  * @since 1.0.0
@@ -7,8 +7,8 @@
7
7
  *
8
8
  * Get the offset top and left of the passed element from the document top left point
9
9
  *
10
- * @param {HTMLElement} elm The element to get the offset from
11
- * @return {top: number; left: number;} The offset top and left object
10
+ * @param {HTMLElement} $elm The element to get the offset from
11
+ * @return {top: number; left: number;} The offset top and left object
12
12
  *
13
13
  * @snippet offsetFromViewport($1)
14
14
  *
@@ -16,13 +16,13 @@
16
16
  *
17
17
  * @example js
18
18
  * import { offsetFromViewport } from '@blackbyte/sugar/dom'
19
- * const offsetFromViewport = offset(myCoolElement);
19
+ * const offsetFromViewport = offset($elm);
20
20
  * // output : { top : 200, left : 300 }
21
21
  *
22
22
  * @since 1.0.0
23
23
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
24
24
  */
25
- export default function offsetFromViewport(elm: HTMLElement): {
25
+ export default function offsetFromViewport($elm: HTMLElement): {
26
26
  top: number;
27
27
  left: number;
28
28
  };
@@ -7,8 +7,8 @@
7
7
  *
8
8
  * Get the offset top and left of the passed element from the document top left point
9
9
  *
10
- * @param {HTMLElement} elm The element to get the offset from
11
- * @return {top: number; left: number;} The offset top and left object
10
+ * @param {HTMLElement} $elm The element to get the offset from
11
+ * @return {top: number; left: number;} The offset top and left object
12
12
  *
13
13
  * @snippet offsetFromViewport($1)
14
14
  *
@@ -16,14 +16,14 @@
16
16
  *
17
17
  * @example js
18
18
  * import { offsetFromViewport } from '@blackbyte/sugar/dom'
19
- * const offsetFromViewport = offset(myCoolElement);
19
+ * const offsetFromViewport = offset($elm);
20
20
  * // output : { top : 200, left : 300 }
21
21
  *
22
22
  * @since 1.0.0
23
23
  * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
24
24
  */
25
- export default function offsetFromViewport(elm) {
26
- const box = elm.getBoundingClientRect(), body = document.body, docEl = document.documentElement, scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop, scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft, clientTop = docEl.clientTop || body.clientTop || 0, clientLeft = docEl.clientLeft || body.clientLeft || 0, top = box.top + scrollTop - clientTop, left = box.left + scrollLeft - clientLeft;
25
+ export default function offsetFromViewport($elm) {
26
+ const box = $elm.getBoundingClientRect(), body = document.body, docEl = document.documentElement, scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop, scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft, clientTop = docEl.clientTop || body.clientTop || 0, clientLeft = docEl.clientLeft || body.clientLeft || 0, top = box.top + scrollTop - clientTop, left = box.left + scrollLeft - clientLeft;
27
27
  return {
28
28
  top: Math.round(top),
29
29
  left: Math.round(left),
@@ -1 +1 @@
1
- {"version":3,"file":"offsetFromViewport.js","sourceRoot":"","sources":["../../../../src/js/dom/offset/offsetFromViewport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,GAAgB;IAIzD,MAAM,GAAG,GAAG,GAAG,CAAC,qBAAqB,EAAE,EACrC,IAAI,GAAG,QAAQ,CAAC,IAAI,EACpB,KAAK,GAAG,QAAQ,CAAC,eAAe,EAChC,SAAS,GAAG,MAAM,CAAC,WAAW,IAAI,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,EACnE,UAAU,GAAG,MAAM,CAAC,WAAW,IAAI,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,EACtE,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,EAClD,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,IAAI,CAAC,EACrD,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,SAAS,GAAG,SAAS,EACrC,IAAI,GAAG,GAAG,CAAC,IAAI,GAAG,UAAU,GAAG,UAAU,CAAC;IAC5C,OAAO;QACL,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;QACpB,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;KACvB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"offsetFromViewport.js","sourceRoot":"","sources":["../../../../src/js/dom/offset/offsetFromViewport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,IAAiB;IAI1D,MAAM,GAAG,GAAG,IAAI,CAAC,qBAAqB,EAAE,EACtC,IAAI,GAAG,QAAQ,CAAC,IAAI,EACpB,KAAK,GAAG,QAAQ,CAAC,eAAe,EAChC,SAAS,GAAG,MAAM,CAAC,WAAW,IAAI,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,EACnE,UAAU,GAAG,MAAM,CAAC,WAAW,IAAI,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,EACtE,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,EAClD,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,IAAI,CAAC,EACrD,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,SAAS,GAAG,SAAS,EACrC,IAAI,GAAG,GAAG,CAAC,IAAI,GAAG,UAAU,GAAG,UAAU,CAAC;IAC5C,OAAO;QACL,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;QACpB,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;KACvB,CAAC;AACJ,CAAC"}