@studiometa/js-toolkit 2.12.1 → 3.0.0-alpha.10

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 (383) hide show
  1. package/Base/Base.d.ts +8 -8
  2. package/Base/Base.js +75 -78
  3. package/Base/Base.js.map +2 -2
  4. package/Base/features.d.ts +15 -2
  5. package/Base/features.js +31 -1
  6. package/Base/features.js.map +2 -2
  7. package/Base/index.d.ts +1 -0
  8. package/Base/index.js +4 -0
  9. package/Base/index.js.map +2 -2
  10. package/Base/managers/AbstractManager.d.ts +1 -1
  11. package/Base/managers/ChildrenManager.d.ts +6 -6
  12. package/Base/managers/ChildrenManager.js +34 -20
  13. package/Base/managers/ChildrenManager.js.map +2 -2
  14. package/Base/managers/EventsManager.d.ts +6 -28
  15. package/Base/managers/EventsManager.js +54 -64
  16. package/Base/managers/EventsManager.js.map +2 -2
  17. package/Base/managers/OptionsManager.d.ts +6 -6
  18. package/Base/managers/OptionsManager.js +29 -23
  19. package/Base/managers/OptionsManager.js.map +3 -3
  20. package/Base/managers/RefsManager.d.ts +1 -1
  21. package/Base/managers/RefsManager.js +23 -34
  22. package/Base/managers/RefsManager.js.map +3 -3
  23. package/Base/managers/ResponsiveOptionsManager.js +7 -4
  24. package/Base/managers/ResponsiveOptionsManager.js.map +2 -2
  25. package/Base/managers/ServicesManager.d.ts +2 -4
  26. package/Base/managers/ServicesManager.js +2 -3
  27. package/Base/managers/ServicesManager.js.map +2 -2
  28. package/Base/utils.d.ts +10 -5
  29. package/Base/utils.js +37 -23
  30. package/Base/utils.js.map +2 -2
  31. package/README.md +107 -6
  32. package/decorators/index.d.ts +1 -1
  33. package/decorators/index.js +1 -1
  34. package/decorators/index.js.map +1 -1
  35. package/decorators/withBreakpointManager.js +6 -4
  36. package/decorators/withBreakpointManager.js.map +2 -2
  37. package/decorators/withBreakpointObserver.d.ts +0 -1
  38. package/decorators/withBreakpointObserver.js +5 -3
  39. package/decorators/withBreakpointObserver.js.map +2 -2
  40. package/decorators/withIntersectionObserver.js +3 -5
  41. package/decorators/withIntersectionObserver.js.map +2 -2
  42. package/decorators/withMountOnMediaQuery.js +3 -3
  43. package/decorators/withMountOnMediaQuery.js.map +2 -2
  44. package/decorators/withMountWhenInView.js +3 -3
  45. package/decorators/withMountWhenInView.js.map +2 -2
  46. package/decorators/withName.d.ts +6 -0
  47. package/decorators/withName.js +12 -0
  48. package/decorators/withName.js.map +7 -0
  49. package/decorators/withScrolledInView/utils.d.ts +12 -1
  50. package/decorators/withScrolledInView/utils.js.map +2 -2
  51. package/decorators/withScrolledInView/withScrolledInView.js +7 -62
  52. package/decorators/withScrolledInView/withScrolledInView.js.map +2 -2
  53. package/helpers/createApp.d.ts +3 -4
  54. package/helpers/createApp.js +21 -11
  55. package/helpers/createApp.js.map +2 -2
  56. package/helpers/getDirectChildren.js +10 -5
  57. package/helpers/getDirectChildren.js.map +2 -2
  58. package/helpers/importWhenVisible.js +1 -2
  59. package/helpers/importWhenVisible.js.map +1 -1
  60. package/index.d.ts +2 -3
  61. package/index.js +2 -4
  62. package/index.js.map +2 -2
  63. package/package.json +2 -10
  64. package/services/index.d.ts +1 -1
  65. package/services/index.js.map +2 -2
  66. package/services/pointer.d.ts +1 -1
  67. package/services/pointer.js +3 -3
  68. package/services/pointer.js.map +2 -2
  69. package/services/raf.js +2 -4
  70. package/services/raf.js.map +2 -2
  71. package/services/resize.d.ts +7 -6
  72. package/services/resize.js +18 -26
  73. package/services/resize.js.map +2 -2
  74. package/services/scroll.d.ts +14 -0
  75. package/services/scroll.js +39 -21
  76. package/services/scroll.js.map +2 -2
  77. package/utils/SmartQueue.d.ts +1 -1
  78. package/utils/SmartQueue.js +1 -1
  79. package/utils/SmartQueue.js.map +2 -2
  80. package/utils/css/animate.d.ts +33 -15
  81. package/utils/css/animate.js +67 -26
  82. package/utils/css/animate.js.map +2 -2
  83. package/utils/css/getOffsetSizes.js +2 -2
  84. package/utils/css/getOffsetSizes.js.map +1 -1
  85. package/utils/css/index.d.ts +2 -1
  86. package/utils/css/index.js +4 -4
  87. package/utils/css/index.js.map +2 -2
  88. package/utils/css/matrix.d.ts +1 -1
  89. package/utils/css/matrix.js.map +2 -2
  90. package/utils/css/transform.d.ts +1 -1
  91. package/utils/css/transform.js +1 -1
  92. package/utils/css/transform.js.map +2 -2
  93. package/utils/css/utils.d.ts +1 -1
  94. package/utils/css/utils.js +1 -1
  95. package/utils/css/utils.js.map +2 -2
  96. package/utils/index.d.ts +6 -4
  97. package/utils/index.js +17 -16
  98. package/utils/index.js.map +2 -2
  99. package/utils/is.d.ts +12 -0
  100. package/utils/is.js +17 -0
  101. package/utils/is.js.map +2 -2
  102. package/utils/math/createRange.d.ts +4 -0
  103. package/utils/math/createRange.js +13 -0
  104. package/utils/math/createRange.js.map +7 -0
  105. package/utils/math/ease.d.ts +1 -0
  106. package/utils/math/ease.js +2 -0
  107. package/utils/math/ease.js.map +2 -2
  108. package/utils/math/index.d.ts +5 -3
  109. package/utils/math/index.js +7 -3
  110. package/utils/math/index.js.map +2 -2
  111. package/utils/math/mean.d.ts +1 -0
  112. package/utils/math/mean.js +17 -0
  113. package/utils/math/mean.js.map +7 -0
  114. package/utils/memo.d.ts +5 -0
  115. package/utils/memo.js +14 -0
  116. package/utils/memo.js.map +7 -0
  117. package/utils/nextFrame.d.ts +4 -22
  118. package/utils/nextFrame.js +3 -10
  119. package/utils/nextFrame.js.map +2 -2
  120. package/utils/nextMicrotask.d.ts +4 -1
  121. package/utils/nextMicrotask.js +3 -3
  122. package/utils/nextMicrotask.js.map +2 -2
  123. package/utils/nextTick.d.ts +4 -1
  124. package/utils/nextTick.js +3 -3
  125. package/utils/nextTick.js.map +2 -2
  126. package/utils/random.d.ts +15 -0
  127. package/utils/random.js +15 -0
  128. package/utils/random.js.map +7 -0
  129. package/utils/scrollTo.d.ts +30 -6
  130. package/utils/scrollTo.js +97 -43
  131. package/utils/scrollTo.js.map +2 -2
  132. package/utils/string/changeCase.d.ts +24 -0
  133. package/utils/string/changeCase.js +47 -0
  134. package/utils/string/changeCase.js.map +7 -0
  135. package/utils/string/index.d.ts +1 -0
  136. package/utils/string/index.js +1 -0
  137. package/utils/string/index.js.map +2 -2
  138. package/utils/{focusTrap.d.ts → trapFocus.d.ts} +2 -10
  139. package/utils/{focusTrap.js → trapFocus.js} +5 -9
  140. package/utils/trapFocus.js.map +7 -0
  141. package/utils/tween.d.ts +59 -10
  142. package/utils/tween.js +24 -18
  143. package/utils/tween.js.map +2 -2
  144. package/Base/Base.cjs +0 -420
  145. package/Base/Base.cjs.map +0 -7
  146. package/Base/features.cjs +0 -27
  147. package/Base/features.cjs.map +0 -7
  148. package/Base/index.cjs +0 -21
  149. package/Base/index.cjs.map +0 -7
  150. package/Base/managers/AbstractManager.cjs +0 -78
  151. package/Base/managers/AbstractManager.cjs.map +0 -7
  152. package/Base/managers/ChildrenManager.cjs +0 -156
  153. package/Base/managers/ChildrenManager.cjs.map +0 -7
  154. package/Base/managers/EventsManager.cjs +0 -305
  155. package/Base/managers/EventsManager.cjs.map +0 -7
  156. package/Base/managers/OptionsManager.cjs +0 -198
  157. package/Base/managers/OptionsManager.cjs.map +0 -7
  158. package/Base/managers/RefsManager.cjs +0 -118
  159. package/Base/managers/RefsManager.cjs.map +0 -7
  160. package/Base/managers/ResponsiveOptionsManager.cjs +0 -79
  161. package/Base/managers/ResponsiveOptionsManager.cjs.map +0 -7
  162. package/Base/managers/ServicesManager.cjs +0 -161
  163. package/Base/managers/ServicesManager.cjs.map +0 -7
  164. package/Base/managers/index.cjs +0 -39
  165. package/Base/managers/index.cjs.map +0 -7
  166. package/Base/types.cjs +0 -19
  167. package/Base/types.cjs.map +0 -7
  168. package/Base/utils.cjs +0 -95
  169. package/Base/utils.cjs.map +0 -7
  170. package/decorators/index.cjs +0 -33
  171. package/decorators/index.cjs.map +0 -7
  172. package/decorators/withBreakpointManager.cjs +0 -102
  173. package/decorators/withBreakpointManager.cjs.map +0 -7
  174. package/decorators/withBreakpointObserver.cjs +0 -128
  175. package/decorators/withBreakpointObserver.cjs.map +0 -7
  176. package/decorators/withDrag.cjs +0 -56
  177. package/decorators/withDrag.cjs.map +0 -7
  178. package/decorators/withExtraConfig.cjs +0 -50
  179. package/decorators/withExtraConfig.cjs.map +0 -7
  180. package/decorators/withFreezedOptions.cjs +0 -50
  181. package/decorators/withFreezedOptions.cjs.map +0 -7
  182. package/decorators/withIntersectionObserver.cjs +0 -71
  183. package/decorators/withIntersectionObserver.cjs.map +0 -7
  184. package/decorators/withMountOnMediaQuery.cjs +0 -86
  185. package/decorators/withMountOnMediaQuery.cjs.map +0 -7
  186. package/decorators/withMountWhenInView.cjs +0 -92
  187. package/decorators/withMountWhenInView.cjs.map +0 -7
  188. package/decorators/withMountWhenPrefersMotion.cjs +0 -30
  189. package/decorators/withMountWhenPrefersMotion.cjs.map +0 -7
  190. package/decorators/withRelativePointer.cjs +0 -56
  191. package/decorators/withRelativePointer.cjs.map +0 -7
  192. package/decorators/withResponsiveOptions.cjs +0 -41
  193. package/decorators/withResponsiveOptions.cjs.map +0 -7
  194. package/decorators/withScrolledInView/index.cjs +0 -22
  195. package/decorators/withScrolledInView/index.cjs.map +0 -7
  196. package/decorators/withScrolledInView/types.cjs +0 -19
  197. package/decorators/withScrolledInView/types.cjs.map +0 -7
  198. package/decorators/withScrolledInView/utils.cjs +0 -99
  199. package/decorators/withScrolledInView/utils.cjs.map +0 -7
  200. package/decorators/withScrolledInView/withScrolledInView.cjs +0 -249
  201. package/decorators/withScrolledInView/withScrolledInView.cjs.map +0 -7
  202. package/decorators/withVue2.cjs +0 -68
  203. package/decorators/withVue2.cjs.map +0 -7
  204. package/decorators/withVue2.d.ts +0 -16
  205. package/decorators/withVue2.js +0 -46
  206. package/decorators/withVue2.js.map +0 -7
  207. package/helpers/createApp.cjs +0 -58
  208. package/helpers/createApp.cjs.map +0 -7
  209. package/helpers/getClosestParent.cjs +0 -45
  210. package/helpers/getClosestParent.cjs.map +0 -7
  211. package/helpers/getDirectChildren.cjs +0 -47
  212. package/helpers/getDirectChildren.cjs.map +0 -7
  213. package/helpers/getInstanceFromElement.cjs +0 -32
  214. package/helpers/getInstanceFromElement.cjs.map +0 -7
  215. package/helpers/importOnInteraction.cjs +0 -48
  216. package/helpers/importOnInteraction.cjs.map +0 -7
  217. package/helpers/importOnMediaQuery.cjs +0 -44
  218. package/helpers/importOnMediaQuery.cjs.map +0 -7
  219. package/helpers/importWhenIdle.cjs +0 -46
  220. package/helpers/importWhenIdle.cjs.map +0 -7
  221. package/helpers/importWhenPrefersMotion.cjs +0 -40
  222. package/helpers/importWhenPrefersMotion.cjs.map +0 -7
  223. package/helpers/importWhenVisible.cjs +0 -44
  224. package/helpers/importWhenVisible.cjs.map +0 -7
  225. package/helpers/index.cjs +0 -53
  226. package/helpers/index.cjs.map +0 -7
  227. package/helpers/utils.cjs +0 -37
  228. package/helpers/utils.cjs.map +0 -7
  229. package/index.cjs +0 -31
  230. package/index.cjs.map +0 -7
  231. package/services/drag.cjs +0 -231
  232. package/services/drag.cjs.map +0 -7
  233. package/services/index.cjs +0 -51
  234. package/services/index.cjs.map +0 -7
  235. package/services/key.cjs +0 -97
  236. package/services/key.cjs.map +0 -7
  237. package/services/load.cjs +0 -60
  238. package/services/load.cjs.map +0 -7
  239. package/services/pointer.cjs +0 -145
  240. package/services/pointer.cjs.map +0 -7
  241. package/services/raf.cjs +0 -80
  242. package/services/raf.cjs.map +0 -7
  243. package/services/resize.cjs +0 -107
  244. package/services/resize.cjs.map +0 -7
  245. package/services/scroll.cjs +0 -119
  246. package/services/scroll.cjs.map +0 -7
  247. package/services/service.cjs +0 -69
  248. package/services/service.cjs.map +0 -7
  249. package/utils/Queue.cjs +0 -93
  250. package/utils/Queue.cjs.map +0 -7
  251. package/utils/SmartQueue.cjs +0 -73
  252. package/utils/SmartQueue.cjs.map +0 -7
  253. package/utils/collide/boundingRectToCircle.cjs +0 -36
  254. package/utils/collide/boundingRectToCircle.cjs.map +0 -7
  255. package/utils/collide/collideCircleCircle.cjs +0 -35
  256. package/utils/collide/collideCircleCircle.cjs.map +0 -7
  257. package/utils/collide/collideCircleRect.cjs +0 -47
  258. package/utils/collide/collideCircleRect.cjs.map +0 -7
  259. package/utils/collide/collidePointCircle.cjs +0 -32
  260. package/utils/collide/collidePointCircle.cjs.map +0 -7
  261. package/utils/collide/collidePointRect.cjs +0 -32
  262. package/utils/collide/collidePointRect.cjs.map +0 -7
  263. package/utils/collide/collideRectRect.cjs +0 -32
  264. package/utils/collide/collideRectRect.cjs.map +0 -7
  265. package/utils/collide/index.cjs +0 -47
  266. package/utils/collide/index.cjs.map +0 -7
  267. package/utils/css/animate.cjs +0 -202
  268. package/utils/css/animate.cjs.map +0 -7
  269. package/utils/css/classes.cjs +0 -51
  270. package/utils/css/classes.cjs.map +0 -7
  271. package/utils/css/getOffsetSizes.cjs +0 -48
  272. package/utils/css/getOffsetSizes.cjs.map +0 -7
  273. package/utils/css/index.cjs +0 -52
  274. package/utils/css/index.cjs.map +0 -7
  275. package/utils/css/matrix.cjs +0 -30
  276. package/utils/css/matrix.cjs.map +0 -7
  277. package/utils/css/styles.cjs +0 -45
  278. package/utils/css/styles.cjs.map +0 -7
  279. package/utils/css/transform.cjs +0 -91
  280. package/utils/css/transform.cjs.map +0 -7
  281. package/utils/css/transition.cjs +0 -145
  282. package/utils/css/transition.cjs.map +0 -7
  283. package/utils/css/utils.cjs +0 -32
  284. package/utils/css/utils.cjs.map +0 -7
  285. package/utils/debounce.cjs +0 -35
  286. package/utils/debounce.cjs.map +0 -7
  287. package/utils/dom/ancestors.cjs +0 -37
  288. package/utils/dom/ancestors.cjs.map +0 -7
  289. package/utils/dom/index.cjs +0 -21
  290. package/utils/dom/index.cjs.map +0 -7
  291. package/utils/focusTrap.cjs +0 -93
  292. package/utils/focusTrap.cjs.map +0 -7
  293. package/utils/focusTrap.js.map +0 -7
  294. package/utils/getComponentResolver.cjs +0 -38
  295. package/utils/getComponentResolver.cjs.map +0 -7
  296. package/utils/has.cjs +0 -29
  297. package/utils/has.cjs.map +0 -7
  298. package/utils/history.cjs +0 -92
  299. package/utils/history.cjs.map +0 -7
  300. package/utils/index.cjs +0 -76
  301. package/utils/index.cjs.map +0 -7
  302. package/utils/is.cjs +0 -41
  303. package/utils/is.cjs.map +0 -7
  304. package/utils/keyCodes.cjs +0 -36
  305. package/utils/keyCodes.cjs.map +0 -7
  306. package/utils/math/clamp.cjs +0 -29
  307. package/utils/math/clamp.cjs.map +0 -7
  308. package/utils/math/clamp01.cjs +0 -40
  309. package/utils/math/clamp01.cjs.map +0 -7
  310. package/utils/math/createEases.cjs +0 -33
  311. package/utils/math/createEases.cjs.map +0 -7
  312. package/utils/math/damp.cjs +0 -29
  313. package/utils/math/damp.cjs.map +0 -7
  314. package/utils/math/ease.cjs +0 -82
  315. package/utils/math/ease.cjs.map +0 -7
  316. package/utils/math/index.cjs +0 -54
  317. package/utils/math/index.cjs.map +0 -7
  318. package/utils/math/inertiaFinalValue.cjs +0 -47
  319. package/utils/math/inertiaFinalValue.cjs.map +0 -7
  320. package/utils/math/lerp.cjs +0 -29
  321. package/utils/math/lerp.cjs.map +0 -7
  322. package/utils/math/map.cjs +0 -29
  323. package/utils/math/map.cjs.map +0 -7
  324. package/utils/math/round.cjs +0 -29
  325. package/utils/math/round.cjs.map +0 -7
  326. package/utils/memoize.cjs +0 -48
  327. package/utils/memoize.cjs.map +0 -7
  328. package/utils/nextFrame.cjs +0 -41
  329. package/utils/nextFrame.cjs.map +0 -7
  330. package/utils/nextMicrotask.cjs +0 -30
  331. package/utils/nextMicrotask.cjs.map +0 -7
  332. package/utils/nextTick.cjs +0 -31
  333. package/utils/nextTick.cjs.map +0 -7
  334. package/utils/noop.cjs +0 -32
  335. package/utils/noop.cjs.map +0 -7
  336. package/utils/object/autoBind.cjs +0 -60
  337. package/utils/object/autoBind.cjs.map +0 -7
  338. package/utils/object/autoBind.d.ts +0 -14
  339. package/utils/object/autoBind.js +0 -28
  340. package/utils/object/autoBind.js.map +0 -7
  341. package/utils/object/getAllProperties.cjs +0 -39
  342. package/utils/object/getAllProperties.cjs.map +0 -7
  343. package/utils/object/index.cjs +0 -39
  344. package/utils/object/index.cjs.map +0 -7
  345. package/utils/object/index.d.ts +0 -2
  346. package/utils/object/index.js +0 -7
  347. package/utils/object/index.js.map +0 -7
  348. package/utils/scheduler.cjs +0 -75
  349. package/utils/scheduler.cjs.map +0 -7
  350. package/utils/scrollTo.cjs +0 -88
  351. package/utils/scrollTo.cjs.map +0 -7
  352. package/utils/string/endsWith.cjs +0 -35
  353. package/utils/string/endsWith.cjs.map +0 -7
  354. package/utils/string/index.cjs +0 -58
  355. package/utils/string/index.cjs.map +0 -7
  356. package/utils/string/startsWith.cjs +0 -35
  357. package/utils/string/startsWith.cjs.map +0 -7
  358. package/utils/string/withLeadingCharacters.cjs +0 -40
  359. package/utils/string/withLeadingCharacters.cjs.map +0 -7
  360. package/utils/string/withLeadingSlash.cjs +0 -40
  361. package/utils/string/withLeadingSlash.cjs.map +0 -7
  362. package/utils/string/withTrailingCharacters.cjs +0 -40
  363. package/utils/string/withTrailingCharacters.cjs.map +0 -7
  364. package/utils/string/withTrailingSlash.cjs +0 -40
  365. package/utils/string/withTrailingSlash.cjs.map +0 -7
  366. package/utils/string/withoutLeadingCharacters.cjs +0 -29
  367. package/utils/string/withoutLeadingCharacters.cjs.map +0 -7
  368. package/utils/string/withoutLeadingCharactersRecursive.cjs +0 -45
  369. package/utils/string/withoutLeadingCharactersRecursive.cjs.map +0 -7
  370. package/utils/string/withoutLeadingSlash.cjs +0 -40
  371. package/utils/string/withoutLeadingSlash.cjs.map +0 -7
  372. package/utils/string/withoutTrailingCharacters.cjs +0 -29
  373. package/utils/string/withoutTrailingCharacters.cjs.map +0 -7
  374. package/utils/string/withoutTrailingCharactersRecursive.cjs +0 -45
  375. package/utils/string/withoutTrailingCharactersRecursive.cjs.map +0 -7
  376. package/utils/string/withoutTrailingSlash.cjs +0 -40
  377. package/utils/string/withoutTrailingSlash.cjs.map +0 -7
  378. package/utils/throttle.cjs +0 -37
  379. package/utils/throttle.cjs.map +0 -7
  380. package/utils/tween.cjs +0 -122
  381. package/utils/tween.cjs.map +0 -7
  382. package/utils/wait.cjs +0 -31
  383. package/utils/wait.cjs.map +0 -7
@@ -1,20 +1,30 @@
1
1
  import { features } from "../Base/features.js";
2
- import { isDefined } from "../utils/index.js";
3
- function createApp(App, rootElement = document.body) {
2
+ import { isBoolean, isObject } from "../utils/index.js";
3
+ function createApp(App, options = {}) {
4
4
  let app;
5
- const options = rootElement instanceof HTMLElement ? { root: rootElement, features: void 0 } : { root: document.body, ...rootElement };
6
- if (isDefined(options.features)) {
7
- for (const [feature, value] of Object.entries(options.features)) {
8
- features.set(feature, value);
9
- }
5
+ const {
6
+ root = document.body,
7
+ breakpoints = null,
8
+ blocking = null,
9
+ attributes = null
10
+ } = options instanceof HTMLElement ? { root: options } : options;
11
+ if (isObject(breakpoints)) {
12
+ features.set("breakpoints", breakpoints);
10
13
  }
11
- function init() {
12
- app = new App(options.root).$mount();
14
+ if (isBoolean(blocking)) {
15
+ features.set("blocking", blocking);
16
+ }
17
+ if (isObject(attributes)) {
18
+ features.set("attributes", attributes);
19
+ }
20
+ async function init() {
21
+ app = new App(root);
22
+ await app.$mount();
13
23
  return app;
14
24
  }
15
25
  let p;
16
- if (features.get("asyncChildren")) {
17
- p = Promise.resolve(init());
26
+ if (features.get("blocking")) {
27
+ p = init();
18
28
  } else {
19
29
  p = new Promise((resolve) => {
20
30
  if (document.readyState === "complete") {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../packages/js-toolkit/helpers/createApp.ts"],
4
- "sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type CreateAppOptions = {\n root: HTMLElement;\n features: Features;\n};\n\n/**\n * Instantiate and mount the given component on the given root element when the page has been loaded\n * and return a function to use the app instance when it is ready.\n */\nexport default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n rootElement: HTMLElement | Partial<CreateAppOptions> = document.body,\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const options =\n rootElement instanceof HTMLElement\n ? { root: rootElement, features: undefined }\n : { root: document.body, ...rootElement };\n\n if (isDefined(options.features)) {\n for (const [feature, value] of Object.entries(options.features as Features)) {\n features.set(feature as keyof Features, value);\n }\n }\n\n function init() {\n app = (new App(options.root) as S & Base<T>).$mount();\n return app;\n }\n\n let p: Promise<S & Base<T>>;\n\n if (features.get('asyncChildren')) {\n p = Promise.resolve(init());\n } else {\n p = new Promise<S & Base<T>>((resolve) => {\n if (document.readyState === 'complete') {\n resolve(init());\n } else {\n document.addEventListener('readystatechange', () => {\n if (document.readyState === 'complete') {\n resolve(init());\n }\n });\n }\n });\n }\n\n return () => p;\n}\n"],
5
- "mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAWX,SAAR,UACL,KACA,cAAuD,SAAS,MACpC;AAC5B,MAAI;AACJ,QAAM,UACJ,uBAAuB,cACnB,EAAE,MAAM,aAAa,UAAU,OAAU,IACzC,EAAE,MAAM,SAAS,MAAM,GAAG,YAAY;AAE5C,MAAI,UAAU,QAAQ,QAAQ,GAAG;AAC/B,eAAW,CAAC,SAAS,KAAK,KAAK,OAAO,QAAQ,QAAQ,QAAoB,GAAG;AAC3E,eAAS,IAAI,SAA2B,KAAK;AAAA,IAC/C;AAAA,EACF;AAEA,WAAS,OAAO;AACd,UAAO,IAAI,IAAI,QAAQ,IAAI,EAAkB,OAAO;AACpD,WAAO;AAAA,EACT;AAEA,MAAI;AAEJ,MAAI,SAAS,IAAI,eAAe,GAAG;AACjC,QAAI,QAAQ,QAAQ,KAAK,CAAC;AAAA,EAC5B,OAAO;AACL,QAAI,IAAI,QAAqB,CAAC,YAAY;AACxC,UAAI,SAAS,eAAe,YAAY;AACtC,gBAAQ,KAAK,CAAC;AAAA,MAChB,OAAO;AACL,iBAAS,iBAAiB,oBAAoB,MAAM;AAClD,cAAI,SAAS,eAAe,YAAY;AACtC,oBAAQ,KAAK,CAAC;AAAA,UAChB;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO,MAAM;AACf;",
4
+ "sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isBoolean, isObject } from '../utils/index.js';\n\nexport type CreateAppOptions = Partial<Features> & {\n root?: HTMLElement;\n};\n\n/**\n * Instantiate and mount the given component on the given root element when the page has been loaded\n * and return a function to use the app instance when it is ready.\n */\nexport default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n options: HTMLElement | CreateAppOptions = {},\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const {\n root = document.body,\n breakpoints = null,\n blocking = null,\n attributes = null,\n } = options instanceof HTMLElement ? { root: options } : options;\n\n if (isObject(breakpoints)) {\n features.set('breakpoints', breakpoints);\n }\n\n if (isBoolean(blocking)) {\n features.set('blocking', blocking);\n }\n\n if (isObject(attributes)) {\n features.set('attributes', attributes);\n }\n\n async function init() {\n app = (new App(root) as S & Base<T>)\n await app.$mount();\n return app;\n }\n\n let p: Promise<S & Base<T>>;\n\n if (features.get('blocking')) {\n p = init();\n } else {\n p = new Promise<S & Base<T>>((resolve) => {\n if (document.readyState === 'complete') {\n resolve(init());\n } else {\n document.addEventListener('readystatechange', () => {\n if (document.readyState === 'complete') {\n resolve(init());\n }\n });\n }\n });\n }\n\n return () => p;\n}\n"],
5
+ "mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,WAAW,gBAAgB;AAUrB,SAAR,UACL,KACA,UAA0C,CAAC,GACf;AAC5B,MAAI;AACJ,QAAM;AAAA,IACJ,OAAO,SAAS;AAAA,IAChB,cAAc;AAAA,IACd,WAAW;AAAA,IACX,aAAa;AAAA,EACf,IAAI,mBAAmB,cAAc,EAAE,MAAM,QAAQ,IAAI;AAEzD,MAAI,SAAS,WAAW,GAAG;AACzB,aAAS,IAAI,eAAe,WAAW;AAAA,EACzC;AAEA,MAAI,UAAU,QAAQ,GAAG;AACvB,aAAS,IAAI,YAAY,QAAQ;AAAA,EACnC;AAEA,MAAI,SAAS,UAAU,GAAG;AACxB,aAAS,IAAI,cAAc,UAAU;AAAA,EACvC;AAEA,iBAAe,OAAO;AACpB,UAAO,IAAI,IAAI,IAAI;AACnB,UAAM,IAAI,OAAO;AACjB,WAAO;AAAA,EACT;AAEA,MAAI;AAEJ,MAAI,SAAS,IAAI,UAAU,GAAG;AAC5B,QAAI,KAAK;AAAA,EACX,OAAO;AACL,QAAI,IAAI,QAAqB,CAAC,YAAY;AACxC,UAAI,SAAS,eAAe,YAAY;AACtC,gBAAQ,KAAK,CAAC;AAAA,MAChB,OAAO;AACL,iBAAS,iBAAiB,oBAAoB,MAAM;AAClD,cAAI,SAAS,eAAe,YAAY;AACtC,oBAAQ,KAAK,CAAC;AAAA,UAChB;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO,MAAM;AACf;",
6
6
  "names": []
7
7
  }
@@ -8,12 +8,17 @@ function getDirectChildren(parentInstance, parentName, childrenName) {
8
8
  if (!isArray(nestedParents) || nestedParents.length <= 0) {
9
9
  return children;
10
10
  }
11
- return [...children].filter(
12
- (child) => [...nestedParents].every((nestedParent) => {
11
+ const directChildren = [];
12
+ for (const child of children) {
13
+ for (const nestedParent of nestedParents) {
13
14
  const nestedChildren = nestedParent.$children[childrenName];
14
- return isArray(nestedChildren) ? !nestedChildren.includes(child) : true;
15
- })
16
- );
15
+ if (isArray(nestedChildren) && nestedChildren.includes(child)) {
16
+ continue;
17
+ }
18
+ directChildren.push(child);
19
+ }
20
+ }
21
+ return directChildren;
17
22
  }
18
23
  function isDirectChild(parentInstance, parentName, childrenName, childInstance) {
19
24
  return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../packages/js-toolkit/helpers/getDirectChildren.ts"],
4
- "sourcesContent": ["import { Base, BaseProps } from '../Base/index.js';\nimport { isArray } from '../utils/index.js';\n\n/**\n * Get direct children from a parent when working with nested components.\n *\n * @template {Base} T\n * @param {Base} parentInstance\n * @param {string} parentName\n * @param {string} childrenName\n * @returns {T[]}\n */\nexport function getDirectChildren<T extends Base = Base>(\n parentInstance: Base,\n parentName: string,\n childrenName: string,\n): T[] {\n const children = parentInstance.$children[childrenName] as Base<BaseProps>[];\n const nestedParents = parentInstance.$children[parentName] as Base<BaseProps>[];\n\n if (!isArray(children)) {\n return [];\n }\n\n if (!isArray(nestedParents) || nestedParents.length <= 0) {\n return children as T[];\n }\n\n return [...children].filter((child) =>\n [...nestedParents].every((nestedParent) => {\n const nestedChildren = nestedParent.$children[childrenName] as Base<BaseProps>[];\n /* istanbul ignore next */\n return isArray(nestedChildren) ? !nestedChildren.includes(child) : true;\n }),\n ) as T[];\n}\n\n/**\n * Test if a component instance is a direct child from the given component.\n *\n * @param {Base} parentInstance\n * @param {string} parentName\n * @param {string} childrenName\n * @param {Base} childInstance\n * @returns {boolean}\n */\nexport function isDirectChild(parentInstance, parentName, childrenName, childInstance) {\n return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);\n}\n"],
5
- "mappings": "AACA,SAAS,eAAe;AAWjB,SAAS,kBACd,gBACA,YACA,cACK;AACL,QAAM,WAAW,eAAe,UAAU,YAAY;AACtD,QAAM,gBAAgB,eAAe,UAAU,UAAU;AAEzD,MAAI,CAAC,QAAQ,QAAQ,GAAG;AACtB,WAAO,CAAC;AAAA,EACV;AAEA,MAAI,CAAC,QAAQ,aAAa,KAAK,cAAc,UAAU,GAAG;AACxD,WAAO;AAAA,EACT;AAEA,SAAO,CAAC,GAAG,QAAQ,EAAE;AAAA,IAAO,CAAC,UAC3B,CAAC,GAAG,aAAa,EAAE,MAAM,CAAC,iBAAiB;AACzC,YAAM,iBAAiB,aAAa,UAAU,YAAY;AAE1D,aAAO,QAAQ,cAAc,IAAI,CAAC,eAAe,SAAS,KAAK,IAAI;AAAA,IACrE,CAAC;AAAA,EACH;AACF;AAWO,SAAS,cAAc,gBAAgB,YAAY,cAAc,eAAe;AACrF,SAAO,kBAAkB,gBAAgB,YAAY,YAAY,EAAE,SAAS,aAAa;AAC3F;",
4
+ "sourcesContent": ["import { Base, BaseProps } from '../Base/index.js';\nimport { isArray } from '../utils/index.js';\n\n/**\n * Get direct children from a parent when working with nested components.\n *\n * @template {Base} T\n * @param {Base} parentInstance\n * @param {string} parentName\n * @param {string} childrenName\n * @returns {T[]}\n */\nexport function getDirectChildren<T extends Base = Base>(\n parentInstance: Base,\n parentName: string,\n childrenName: string,\n): T[] {\n const children = parentInstance.$children[childrenName] as Base<BaseProps>[];\n const nestedParents = parentInstance.$children[parentName] as Base<BaseProps>[];\n\n if (!isArray(children)) {\n return [];\n }\n\n if (!isArray(nestedParents) || nestedParents.length <= 0) {\n return children as T[];\n }\n\n const directChildren = [];\n\n for (const child of children) {\n for (const nestedParent of nestedParents) {\n const nestedChildren = nestedParent.$children[childrenName] as Base<BaseProps>[];\n\n if (isArray(nestedChildren) && nestedChildren.includes(child)) {\n continue;\n }\n\n directChildren.push(child);\n }\n }\n\n return directChildren;\n}\n\n/**\n * Test if a component instance is a direct child from the given component.\n *\n * @param {Base} parentInstance\n * @param {string} parentName\n * @param {string} childrenName\n * @param {Base} childInstance\n * @returns {boolean}\n */\nexport function isDirectChild(parentInstance, parentName, childrenName, childInstance) {\n return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);\n}\n"],
5
+ "mappings": "AACA,SAAS,eAAe;AAWjB,SAAS,kBACd,gBACA,YACA,cACK;AACL,QAAM,WAAW,eAAe,UAAU,YAAY;AACtD,QAAM,gBAAgB,eAAe,UAAU,UAAU;AAEzD,MAAI,CAAC,QAAQ,QAAQ,GAAG;AACtB,WAAO,CAAC;AAAA,EACV;AAEA,MAAI,CAAC,QAAQ,aAAa,KAAK,cAAc,UAAU,GAAG;AACxD,WAAO;AAAA,EACT;AAEA,QAAM,iBAAiB,CAAC;AAExB,aAAW,SAAS,UAAU;AAC5B,eAAW,gBAAgB,eAAe;AACxC,YAAM,iBAAiB,aAAa,UAAU,YAAY;AAE1D,UAAI,QAAQ,cAAc,KAAK,eAAe,SAAS,KAAK,GAAG;AAC7D;AAAA,MACF;AAEA,qBAAe,KAAK,KAAK;AAAA,IAC3B;AAAA,EACF;AAEA,SAAO;AACT;AAWO,SAAS,cAAc,gBAAgB,YAAY,cAAc,eAAe;AACrF,SAAO,kBAAkB,gBAAgB,YAAY,YAAY,EAAE,SAAS,aAAa;AAC3F;",
6
6
  "names": []
7
7
  }
@@ -12,8 +12,7 @@ function importWhenVisible(fn, nameOrSelectorOrElement, parent, observerOptions
12
12
  }
13
13
  }, observerOptions);
14
14
  const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);
15
- for (const element of elements)
16
- observer.observe(element);
15
+ for (const element of elements) observer.observe(element);
17
16
  });
18
17
  }
19
18
  export {
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../packages/js-toolkit/helpers/importWhenVisible.ts"],
4
4
  "sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport { getComponentResolver } from '../utils/index.js';\n\n/**\n * Import a component when it is visible.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement\n * The name or selector for the component.\n * @param {Base} [parent]\n * The parent component.\n * @param {IntersectionObserverInit} [observerOptions]\n * Options for the `IntersectionObserver` instance.\n * @returns {Promise<T>}\n */\nexport default function importWhenVisible<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],\n parent?: Base,\n observerOptions: IntersectionObserverInit = {},\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const observer = new IntersectionObserver((entries) => {\n const someEntriesAreVisible = entries.some((entry) => entry.isIntersecting);\n if (someEntriesAreVisible) {\n setTimeout(() => {\n resolver(resolve, () => observer.disconnect());\n }, 0);\n }\n }, observerOptions);\n\n const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);\n for (const element of elements) observer.observe(element);\n });\n}\n"],
5
- "mappings": "AACA,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AAgBtB,SAAR,kBACL,IACA,yBACA,QACA,kBAA4C,CAAC,GACjC;AACZ,QAAM,WAAW,qBAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,WAAW,IAAI,qBAAqB,CAAC,YAAY;AACrD,YAAM,wBAAwB,QAAQ,KAAK,CAAC,UAAU,MAAM,cAAc;AAC1E,UAAI,uBAAuB;AACzB,mBAAW,MAAM;AACf,mBAAS,SAAS,MAAM,SAAS,WAAW,CAAC;AAAA,QAC/C,GAAG,CAAC;AAAA,MACN;AAAA,IACF,GAAG,eAAe;AAElB,UAAM,WAAW,kBAAkB,yBAAyB,QAAQ,GAAG;AACvE,eAAW,WAAW;AAAU,eAAS,QAAQ,OAAO;AAAA,EAC1D,CAAC;AACH;",
5
+ "mappings": "AACA,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AAgBtB,SAAR,kBACL,IACA,yBACA,QACA,kBAA4C,CAAC,GACjC;AACZ,QAAM,WAAW,qBAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,WAAW,IAAI,qBAAqB,CAAC,YAAY;AACrD,YAAM,wBAAwB,QAAQ,KAAK,CAAC,UAAU,MAAM,cAAc;AAC1E,UAAI,uBAAuB;AACzB,mBAAW,MAAM;AACf,mBAAS,SAAS,MAAM,SAAS,WAAW,CAAC;AAAA,QAC/C,GAAG,CAAC;AAAA,MACN;AAAA,IACF,GAAG,eAAe;AAElB,UAAM,WAAW,kBAAkB,yBAAyB,QAAQ,GAAG;AACvE,eAAW,WAAW,SAAU,UAAS,QAAQ,OAAO;AAAA,EAC1D,CAAC;AACH;",
6
6
  "names": []
7
7
  }
package/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- export { Base } from './Base/index.js';
1
+ export * from './Base/index.js';
2
+ export * from './Base/types.js';
2
3
  export * from './decorators/index.js';
3
4
  export * from './helpers/index.js';
4
5
  export * from './services/index.js';
5
- export type { BaseProps, BaseConstructor, BaseAsyncConstructor, BaseConfig } from './Base/index.js';
6
- export type { BaseInterface, BaseDecorator } from './Base/types.js';
package/index.js CHANGED
@@ -1,8 +1,6 @@
1
- import { Base } from "./Base/index.js";
1
+ export * from "./Base/index.js";
2
+ export * from "./Base/types.js";
2
3
  export * from "./decorators/index.js";
3
4
  export * from "./helpers/index.js";
4
5
  export * from "./services/index.js";
5
- export {
6
- Base
7
- };
8
6
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../packages/js-toolkit/index.ts"],
4
- "sourcesContent": ["export { Base } from './Base/index.js';\nexport * from './decorators/index.js';\nexport * from './helpers/index.js';\nexport * from './services/index.js';\n\nexport type { BaseProps, BaseConstructor, BaseAsyncConstructor, BaseConfig } from './Base/index.js';\n\nexport type { BaseInterface, BaseDecorator } from './Base/types.js';\n"],
5
- "mappings": "AAAA,SAAS,YAAY;AACrB,cAAc;AACd,cAAc;AACd,cAAc;",
4
+ "sourcesContent": ["export * from './Base/index.js';\nexport * from './Base/types.js';\nexport * from './decorators/index.js';\nexport * from './helpers/index.js';\nexport * from './services/index.js';\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studiometa/js-toolkit",
3
- "version": "2.12.1",
3
+ "version": "3.0.0-alpha.10",
4
4
  "description": "A set of useful little bits of JavaScript to boost your project! 🚀",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -23,13 +23,11 @@
23
23
  "exports": {
24
24
  ".": {
25
25
  "import": "./index.js",
26
- "require": "./index.cjs",
27
26
  "types": "./index.d.ts",
28
27
  "default": "./index.js"
29
28
  },
30
29
  "./utils": {
31
30
  "import": "./utils/index.js",
32
- "require": "./utils/index.cjs",
33
31
  "types": "./utils/index.d.ts",
34
32
  "default": "./utils/index.js"
35
33
  }
@@ -41,13 +39,7 @@
41
39
  "toolkit"
42
40
  ],
43
41
  "dependencies": {
44
- "@motionone/easing": "^10.15.1",
42
+ "@motionone/easing": "^10.18.0",
45
43
  "deepmerge": "^4.3.1"
46
- },
47
- "devDependencies": {
48
- "vue": "^2.6.0"
49
- },
50
- "peerDependencies": {
51
- "vue": "^2.6.0 || ^3.0"
52
44
  }
53
45
  }
@@ -28,7 +28,7 @@ export type KeyServiceInterface = ServiceInterface<KeyServiceProps>;
28
28
  export type LoadServiceInterface = ServiceInterface<LoadServiceProps>;
29
29
  export type PointerServiceInterface = ServiceInterface<PointerServiceProps>;
30
30
  export type RafServiceInterface = ServiceInterface<RafServiceProps>;
31
- export type ResizeServiceInterface = ServiceInterface<ResizeServiceProps>;
31
+ export type ResizeServiceInterface<T extends Record<string, string> = Record<string, string>> = ServiceInterface<ResizeServiceProps<T>>;
32
32
  export type ScrollServiceInterface = ServiceInterface<ScrollServiceProps>;
33
33
  export type { DragServiceProps, KeyServiceProps, LoadServiceProps, PointerServiceProps, RafServiceProps, ResizeServiceProps, ScrollServiceProps, };
34
34
  export { default as useDrag } from './drag.js';
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../packages/js-toolkit/services/index.ts"],
4
- "sourcesContent": ["import type { DragServiceProps } from './drag.js';\nimport type { KeyServiceProps } from './key.js';\nimport type { LoadServiceProps } from './load.js';\nimport type { PointerServiceProps } from './pointer.js';\nimport type { RafServiceProps } from './raf.js';\nimport type { ResizeServiceProps } from './resize.js';\nimport type { ScrollServiceProps } from './scroll.js';\n\nexport interface ServiceInterface<T> {\n /**\n * Remove a function from the resize service by its key.\n */\n remove(key: string): void;\n /**\n * Add a callback to the service. The callback will receive the current service props as parameter.\n */\n add(key: string, callback: (props: T) => void): void;\n /**\n * Test if the service has alreaydy a callback for the given key.\n */\n has(key: string): boolean;\n /**\n * Get the service's props.\n */\n props(): T;\n}\n\nexport type DragServiceInterface = ServiceInterface<DragServiceProps>;\nexport type KeyServiceInterface = ServiceInterface<KeyServiceProps>;\nexport type LoadServiceInterface = ServiceInterface<LoadServiceProps>;\nexport type PointerServiceInterface = ServiceInterface<PointerServiceProps>;\nexport type RafServiceInterface = ServiceInterface<RafServiceProps>;\nexport type ResizeServiceInterface = ServiceInterface<ResizeServiceProps>;\nexport type ScrollServiceInterface = ServiceInterface<ScrollServiceProps>;\n\nexport type {\n DragServiceProps,\n KeyServiceProps,\n LoadServiceProps,\n PointerServiceProps,\n RafServiceProps,\n ResizeServiceProps,\n ScrollServiceProps,\n};\n\nexport { default as useDrag } from './drag.js';\nexport { default as useKey } from './key.js';\nexport { default as useLoad } from './load.js';\nexport { default as usePointer } from './pointer.js';\nexport { default as useRaf } from './raf.js';\nexport { default as useResize } from './resize.js';\nexport { default as useScroll } from './scroll.js';\nexport { useService } from './service.js';\n"],
5
- "mappings": "AA6CA,SAAoB,WAAXA,gBAA0B;AACnC,SAAoB,WAAXA,gBAAyB;AAClC,SAAoB,WAAXA,gBAA0B;AACnC,SAAoB,WAAXA,gBAA6B;AACtC,SAAoB,WAAXA,gBAAyB;AAClC,SAAoB,WAAXA,gBAA4B;AACrC,SAAoB,WAAXA,gBAA4B;AACrC,SAAS,kBAAkB;",
4
+ "sourcesContent": ["import type { DragServiceProps } from './drag.js';\nimport type { KeyServiceProps } from './key.js';\nimport type { LoadServiceProps } from './load.js';\nimport type { PointerServiceProps } from './pointer.js';\nimport type { RafServiceProps } from './raf.js';\nimport type { ResizeServiceProps } from './resize.js';\nimport type { ScrollServiceProps } from './scroll.js';\n\nexport interface ServiceInterface<T> {\n /**\n * Remove a function from the resize service by its key.\n */\n remove(key: string): void;\n /**\n * Add a callback to the service. The callback will receive the current service props as parameter.\n */\n add(key: string, callback: (props: T) => void): void;\n /**\n * Test if the service has alreaydy a callback for the given key.\n */\n has(key: string): boolean;\n /**\n * Get the service's props.\n */\n props(): T;\n}\n\nexport type DragServiceInterface = ServiceInterface<DragServiceProps>;\nexport type KeyServiceInterface = ServiceInterface<KeyServiceProps>;\nexport type LoadServiceInterface = ServiceInterface<LoadServiceProps>;\nexport type PointerServiceInterface = ServiceInterface<PointerServiceProps>;\nexport type RafServiceInterface = ServiceInterface<RafServiceProps>;\nexport type ResizeServiceInterface<T extends Record<string, string> = Record<string, string>> =\n ServiceInterface<ResizeServiceProps<T>>;\nexport type ScrollServiceInterface = ServiceInterface<ScrollServiceProps>;\n\nexport type {\n DragServiceProps,\n KeyServiceProps,\n LoadServiceProps,\n PointerServiceProps,\n RafServiceProps,\n ResizeServiceProps,\n ScrollServiceProps,\n};\n\nexport { default as useDrag } from './drag.js';\nexport { default as useKey } from './key.js';\nexport { default as useLoad } from './load.js';\nexport { default as usePointer } from './pointer.js';\nexport { default as useRaf } from './raf.js';\nexport { default as useResize } from './resize.js';\nexport { default as useScroll } from './scroll.js';\nexport { useService } from './service.js';\n"],
5
+ "mappings": "AA8CA,SAAoB,WAAXA,gBAA0B;AACnC,SAAoB,WAAXA,gBAAyB;AAClC,SAAoB,WAAXA,gBAA0B;AACnC,SAAoB,WAAXA,gBAA6B;AACtC,SAAoB,WAAXA,gBAAyB;AAClC,SAAoB,WAAXA,gBAA4B;AACrC,SAAoB,WAAXA,gBAA4B;AACrC,SAAS,kBAAkB;",
6
6
  "names": ["default"]
7
7
  }
@@ -29,4 +29,4 @@ export interface PointerServiceProps {
29
29
  /**
30
30
  * Use the pointer service.
31
31
  */
32
- export default function usePointer(target: HTMLElement | undefined): PointerService;
32
+ export default function usePointer(target?: HTMLElement): PointerService;
@@ -112,10 +112,10 @@ function createPointerService(target) {
112
112
  }
113
113
  const instances = /* @__PURE__ */ new Map();
114
114
  function usePointer(target) {
115
- if (!instances.has(target)) {
116
- instances.set(target, createPointerService(target));
115
+ if (!instances.has(target ?? window)) {
116
+ instances.set(target ?? window, createPointerService(target));
117
117
  }
118
- return instances.get(target);
118
+ return instances.get(target ?? window);
119
119
  }
120
120
  export {
121
121
  usePointer as default
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../packages/js-toolkit/services/pointer.ts"],
4
- "sourcesContent": ["/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */\nimport { useService } from './service.js';\nimport type { ServiceInterface } from './index.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type PointerService = ServiceInterface<PointerServiceProps>;\n\nexport interface PointerServiceProps {\n event: MouseEvent | TouchEvent;\n isDown: boolean;\n x: number;\n y: number;\n changed: { x: boolean; y: boolean };\n last: { x: number; y: number };\n delta: { x: number; y: number };\n progress: { x: number; y: number };\n max: { x: number; y: number };\n}\n\n/**\n * Test if an event is an instance of TouchEvent.\n */\nfunction isTouchEvent(event: TouchEvent | MouseEvent): boolean {\n return typeof TouchEvent !== 'undefined' && event instanceof TouchEvent;\n}\n\nconst events = ['mousemove', 'touchmove', 'mousedown', 'touchstart', 'mouseup', 'touchend'];\n\n/**\n * Get pointer service.\n */\nfunction createPointerService(target: HTMLElement | undefined): PointerService {\n function getTargetSize() {\n return isDefined(target)\n ? target.getBoundingClientRect()\n : {\n width: window.innerWidth,\n height: window.innerHeight,\n x: 0,\n y: 0,\n };\n }\n\n /**\n * Update the pointer positions.\n */\n function updateProps(event: MouseEvent | TouchEvent): PointerServiceProps {\n props.event = event;\n const yLast = props.y;\n const xLast = props.x;\n\n const targetSize = getTargetSize();\n\n // Check pointer Y\n // We either get data from a touch event `event.touches[0].clientY` or from\n // a mouse event `event.clientY`.\n let y = isTouchEvent(event)\n ? (event as TouchEvent).touches[0]?.clientY\n : (event as MouseEvent).clientY;\n y -= targetSize.y;\n if (y !== props.y) {\n props.y = y;\n }\n\n // Check pointer X\n // We either get data from a touch event `event.touches[0].clientX` or from\n // a mouse event `event.clientX`.\n let x = isTouchEvent(event)\n ? (event as TouchEvent).touches[0]?.clientX\n : (event as MouseEvent).clientX;\n x -= targetSize.x;\n if (x !== props.x) {\n props.x = x;\n }\n\n props.changed.x = props.x !== xLast;\n props.changed.y = props.y !== yLast;\n\n props.last.x = xLast;\n props.last.y = yLast;\n\n props.delta.x = props.x - xLast;\n props.delta.y = props.y - yLast;\n\n props.max.x = targetSize.width;\n props.max.y = targetSize.height;\n\n props.progress.x = props.x / props.max.x;\n props.progress.y = props.y / props.max.y;\n\n return props;\n }\n\n /**\n * Handle events.\n *\n * @todo handle scroll as well\n */\n function handleEvent(event: MouseEvent | TouchEvent) {\n // eslint-disable-next-line default-case\n switch (event.type) {\n case 'mouseenter':\n case 'mousemove':\n case 'touchmove':\n trigger(updateProps(event));\n break;\n case 'mousedown':\n case 'touchstart':\n props.isDown = true;\n trigger(props);\n break;\n case 'mouseup':\n case 'touchend':\n props.isDown = false;\n trigger(props);\n break;\n }\n }\n\n const targetSize = getTargetSize();\n const { add, remove, has, trigger, props } = useService({\n props: {\n event: null,\n isDown: false,\n x: targetSize.x / 2,\n y: targetSize.y / 2,\n changed: {\n x: false,\n y: false,\n },\n last: {\n x: targetSize.x / 2,\n y: targetSize.y / 2,\n },\n delta: {\n x: 0,\n y: 0,\n },\n progress: {\n x: 0.5,\n y: 0.5,\n },\n max: {\n x: targetSize.width,\n y: targetSize.height,\n },\n } as PointerServiceProps,\n init() {\n document.documentElement.addEventListener('mouseenter', handleEvent, {\n once: true,\n capture: true,\n });\n\n const options = { passive: true, capture: true };\n for (const event of events) {\n document.addEventListener(event, handleEvent, options);\n }\n },\n kill() {\n for (const event of events) {\n document.removeEventListener(event, handleEvent);\n }\n },\n });\n\n return {\n add,\n remove,\n has,\n props: () => props,\n };\n}\n\nconst instances = new Map<HTMLElement | Window, PointerService>();\n\n/**\n * Use the pointer service.\n */\nexport default function usePointer(target: HTMLElement | undefined): PointerService {\n if (!instances.has(target)) {\n instances.set(target, createPointerService(target));\n }\n return instances.get(target);\n}\n"],
5
- "mappings": "AACA,SAAS,kBAAkB;AAE3B,SAAS,iBAAiB;AAmB1B,SAAS,aAAa,OAAyC;AAC7D,SAAO,OAAO,eAAe,eAAe,iBAAiB;AAC/D;AAEA,MAAM,SAAS,CAAC,aAAa,aAAa,aAAa,cAAc,WAAW,UAAU;AAK1F,SAAS,qBAAqB,QAAiD;AAC7E,WAAS,gBAAgB;AACvB,WAAO,UAAU,MAAM,IACnB,OAAO,sBAAsB,IAC7B;AAAA,MACE,OAAO,OAAO;AAAA,MACd,QAAQ,OAAO;AAAA,MACf,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,EACN;AAKA,WAAS,YAAY,OAAqD;AACxE,UAAM,QAAQ;AACd,UAAM,QAAQ,MAAM;AACpB,UAAM,QAAQ,MAAM;AAEpB,UAAMA,cAAa,cAAc;AAKjC,QAAI,IAAI,aAAa,KAAK,IACrB,MAAqB,QAAQ,CAAC,GAAG,UACjC,MAAqB;AAC1B,SAAKA,YAAW;AAChB,QAAI,MAAM,MAAM,GAAG;AACjB,YAAM,IAAI;AAAA,IACZ;AAKA,QAAI,IAAI,aAAa,KAAK,IACrB,MAAqB,QAAQ,CAAC,GAAG,UACjC,MAAqB;AAC1B,SAAKA,YAAW;AAChB,QAAI,MAAM,MAAM,GAAG;AACjB,YAAM,IAAI;AAAA,IACZ;AAEA,UAAM,QAAQ,IAAI,MAAM,MAAM;AAC9B,UAAM,QAAQ,IAAI,MAAM,MAAM;AAE9B,UAAM,KAAK,IAAI;AACf,UAAM,KAAK,IAAI;AAEf,UAAM,MAAM,IAAI,MAAM,IAAI;AAC1B,UAAM,MAAM,IAAI,MAAM,IAAI;AAE1B,UAAM,IAAI,IAAIA,YAAW;AACzB,UAAM,IAAI,IAAIA,YAAW;AAEzB,UAAM,SAAS,IAAI,MAAM,IAAI,MAAM,IAAI;AACvC,UAAM,SAAS,IAAI,MAAM,IAAI,MAAM,IAAI;AAEvC,WAAO;AAAA,EACT;AAOA,WAAS,YAAY,OAAgC;AAEnD,YAAQ,MAAM,MAAM;AAAA,MAClB,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AACH,gBAAQ,YAAY,KAAK,CAAC;AAC1B;AAAA,MACF,KAAK;AAAA,MACL,KAAK;AACH,cAAM,SAAS;AACf,gBAAQ,KAAK;AACb;AAAA,MACF,KAAK;AAAA,MACL,KAAK;AACH,cAAM,SAAS;AACf,gBAAQ,KAAK;AACb;AAAA,IACJ;AAAA,EACF;AAEA,QAAM,aAAa,cAAc;AACjC,QAAM,EAAE,KAAK,QAAQ,KAAK,SAAS,MAAM,IAAI,WAAW;AAAA,IACtD,OAAO;AAAA,MACL,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,GAAG,WAAW,IAAI;AAAA,MAClB,GAAG,WAAW,IAAI;AAAA,MAClB,SAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MACA,MAAM;AAAA,QACJ,GAAG,WAAW,IAAI;AAAA,QAClB,GAAG,WAAW,IAAI;AAAA,MACpB;AAAA,MACA,OAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MACA,UAAU;AAAA,QACR,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MACA,KAAK;AAAA,QACH,GAAG,WAAW;AAAA,QACd,GAAG,WAAW;AAAA,MAChB;AAAA,IACF;AAAA,IACA,OAAO;AACL,eAAS,gBAAgB,iBAAiB,cAAc,aAAa;AAAA,QACnE,MAAM;AAAA,QACN,SAAS;AAAA,MACX,CAAC;AAED,YAAM,UAAU,EAAE,SAAS,MAAM,SAAS,KAAK;AAC/C,iBAAW,SAAS,QAAQ;AAC1B,iBAAS,iBAAiB,OAAO,aAAa,OAAO;AAAA,MACvD;AAAA,IACF;AAAA,IACA,OAAO;AACL,iBAAW,SAAS,QAAQ;AAC1B,iBAAS,oBAAoB,OAAO,WAAW;AAAA,MACjD;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,MAAM;AAAA,EACf;AACF;AAEA,MAAM,YAAY,oBAAI,IAA0C;AAKjD,SAAR,WAA4B,QAAiD;AAClF,MAAI,CAAC,UAAU,IAAI,MAAM,GAAG;AAC1B,cAAU,IAAI,QAAQ,qBAAqB,MAAM,CAAC;AAAA,EACpD;AACA,SAAO,UAAU,IAAI,MAAM;AAC7B;",
4
+ "sourcesContent": ["/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */\nimport { useService } from './service.js';\nimport type { ServiceInterface } from './index.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type PointerService = ServiceInterface<PointerServiceProps>;\n\nexport interface PointerServiceProps {\n event: MouseEvent | TouchEvent;\n isDown: boolean;\n x: number;\n y: number;\n changed: { x: boolean; y: boolean };\n last: { x: number; y: number };\n delta: { x: number; y: number };\n progress: { x: number; y: number };\n max: { x: number; y: number };\n}\n\n/**\n * Test if an event is an instance of TouchEvent.\n */\nfunction isTouchEvent(event: TouchEvent | MouseEvent): boolean {\n return typeof TouchEvent !== 'undefined' && event instanceof TouchEvent;\n}\n\nconst events = ['mousemove', 'touchmove', 'mousedown', 'touchstart', 'mouseup', 'touchend'];\n\n/**\n * Get pointer service.\n */\nfunction createPointerService(target: HTMLElement | undefined): PointerService {\n function getTargetSize() {\n return isDefined(target)\n ? target.getBoundingClientRect()\n : {\n width: window.innerWidth,\n height: window.innerHeight,\n x: 0,\n y: 0,\n };\n }\n\n /**\n * Update the pointer positions.\n */\n function updateProps(event: MouseEvent | TouchEvent): PointerServiceProps {\n props.event = event;\n const yLast = props.y;\n const xLast = props.x;\n\n const targetSize = getTargetSize();\n\n // Check pointer Y\n // We either get data from a touch event `event.touches[0].clientY` or from\n // a mouse event `event.clientY`.\n let y = isTouchEvent(event)\n ? (event as TouchEvent).touches[0]?.clientY\n : (event as MouseEvent).clientY;\n y -= targetSize.y;\n if (y !== props.y) {\n props.y = y;\n }\n\n // Check pointer X\n // We either get data from a touch event `event.touches[0].clientX` or from\n // a mouse event `event.clientX`.\n let x = isTouchEvent(event)\n ? (event as TouchEvent).touches[0]?.clientX\n : (event as MouseEvent).clientX;\n x -= targetSize.x;\n if (x !== props.x) {\n props.x = x;\n }\n\n props.changed.x = props.x !== xLast;\n props.changed.y = props.y !== yLast;\n\n props.last.x = xLast;\n props.last.y = yLast;\n\n props.delta.x = props.x - xLast;\n props.delta.y = props.y - yLast;\n\n props.max.x = targetSize.width;\n props.max.y = targetSize.height;\n\n props.progress.x = props.x / props.max.x;\n props.progress.y = props.y / props.max.y;\n\n return props;\n }\n\n /**\n * Handle events.\n *\n * @todo handle scroll as well\n */\n function handleEvent(event: MouseEvent | TouchEvent) {\n // eslint-disable-next-line default-case\n switch (event.type) {\n case 'mouseenter':\n case 'mousemove':\n case 'touchmove':\n trigger(updateProps(event));\n break;\n case 'mousedown':\n case 'touchstart':\n props.isDown = true;\n trigger(props);\n break;\n case 'mouseup':\n case 'touchend':\n props.isDown = false;\n trigger(props);\n break;\n }\n }\n\n const targetSize = getTargetSize();\n const { add, remove, has, trigger, props } = useService({\n props: {\n event: null,\n isDown: false,\n x: targetSize.x / 2,\n y: targetSize.y / 2,\n changed: {\n x: false,\n y: false,\n },\n last: {\n x: targetSize.x / 2,\n y: targetSize.y / 2,\n },\n delta: {\n x: 0,\n y: 0,\n },\n progress: {\n x: 0.5,\n y: 0.5,\n },\n max: {\n x: targetSize.width,\n y: targetSize.height,\n },\n } as PointerServiceProps,\n init() {\n document.documentElement.addEventListener('mouseenter', handleEvent, {\n once: true,\n capture: true,\n });\n\n const options = { passive: true, capture: true };\n for (const event of events) {\n document.addEventListener(event, handleEvent, options);\n }\n },\n kill() {\n for (const event of events) {\n document.removeEventListener(event, handleEvent);\n }\n },\n });\n\n return {\n add,\n remove,\n has,\n props: () => props,\n };\n}\n\nconst instances = new Map<HTMLElement | Window, PointerService>();\n\n/**\n * Use the pointer service.\n */\nexport default function usePointer(target?: HTMLElement): PointerService {\n if (!instances.has(target ?? window)) {\n instances.set(target ?? window, createPointerService(target));\n }\n return instances.get(target ?? window) as PointerService;\n}\n"],
5
+ "mappings": "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",
6
6
  "names": ["targetSize"]
7
7
  }
package/services/raf.js CHANGED
@@ -1,11 +1,9 @@
1
1
  import { useService } from "./service.js";
2
- import { getRaf as getRequestAnimationFrame } from "../utils/nextFrame.js";
3
2
  import { useScheduler } from "../utils/scheduler.js";
4
3
  import { isFunction } from "../utils/is.js";
5
4
  const scheduler = useScheduler(["update", "render"]);
6
5
  function createRafService() {
7
6
  let isTicking = false;
8
- const RAF = getRequestAnimationFrame();
9
7
  function trigger(props2) {
10
8
  for (const callback of callbacks.values()) {
11
9
  scheduler.update(() => {
@@ -24,7 +22,7 @@ function createRafService() {
24
22
  if (!isTicking) {
25
23
  return;
26
24
  }
27
- RAF(loop);
25
+ requestAnimationFrame(loop);
28
26
  }
29
27
  const { add, remove, has, props, callbacks } = useService({
30
28
  props: {
@@ -32,7 +30,7 @@ function createRafService() {
32
30
  },
33
31
  init() {
34
32
  isTicking = true;
35
- RAF(loop);
33
+ requestAnimationFrame(loop);
36
34
  },
37
35
  kill() {
38
36
  isTicking = false;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../packages/js-toolkit/services/raf.ts"],
4
- "sourcesContent": ["/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */\nimport { useService } from './service.js';\nimport { getRaf as getRequestAnimationFrame } from '../utils/nextFrame.js';\nimport { useScheduler } from '../utils/scheduler.js';\nimport { isFunction } from '../utils/is.js';\nimport type { ServiceInterface } from './index.js';\n\nconst scheduler = useScheduler(['update', 'render']);\n\nexport type RafService = ServiceInterface<RafServiceProps>;\n\nexport interface RafServiceProps {\n time: DOMHighResTimeStamp;\n}\n\n/**\n * Create raf service.\n */\nfunction createRafService(): RafService {\n let isTicking = false;\n const RAF = getRequestAnimationFrame();\n\n /**\n * Trigger callbacks.\n */\n function trigger(props: RafServiceProps) {\n for (const callback of callbacks.values()) {\n scheduler.update(() => {\n const render = callback(props) as (() => unknown) | void;\n if (isFunction(render)) {\n scheduler.render(() => {\n // @ts-ignore\n render(props);\n });\n }\n });\n }\n }\n\n /**\n * Loop.\n */\n function loop() {\n // eslint-disable-next-line no-use-before-define\n props.time = performance.now();\n trigger(props);\n\n if (!isTicking) {\n return;\n }\n\n RAF(loop);\n }\n\n const { add, remove, has, props, callbacks } = useService({\n props: {\n time: performance.now(),\n } as RafServiceProps,\n init() {\n isTicking = true;\n RAF(loop);\n },\n kill() {\n isTicking = false;\n },\n });\n\n return {\n add,\n remove,\n has,\n props: () => props,\n };\n}\n\nlet raf;\n\n/**\n * Use the RequestAnimationFrame (raf) service.\n */\nexport default function useRaf(): RafService {\n if (!raf) {\n raf = createRafService();\n }\n\n return raf;\n}\n"],
5
- "mappings": "AACA,SAAS,kBAAkB;AAC3B,SAAS,UAAU,gCAAgC;AACnD,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAG3B,MAAM,YAAY,aAAa,CAAC,UAAU,QAAQ,CAAC;AAWnD,SAAS,mBAA+B;AACtC,MAAI,YAAY;AAChB,QAAM,MAAM,yBAAyB;AAKrC,WAAS,QAAQA,QAAwB;AACvC,eAAW,YAAY,UAAU,OAAO,GAAG;AACzC,gBAAU,OAAO,MAAM;AACrB,cAAM,SAAS,SAASA,MAAK;AAC7B,YAAI,WAAW,MAAM,GAAG;AACtB,oBAAU,OAAO,MAAM;AAErB,mBAAOA,MAAK;AAAA,UACd,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAKA,WAAS,OAAO;AAEd,UAAM,OAAO,YAAY,IAAI;AAC7B,YAAQ,KAAK;AAEb,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AAEA,QAAI,IAAI;AAAA,EACV;AAEA,QAAM,EAAE,KAAK,QAAQ,KAAK,OAAO,UAAU,IAAI,WAAW;AAAA,IACxD,OAAO;AAAA,MACL,MAAM,YAAY,IAAI;AAAA,IACxB;AAAA,IACA,OAAO;AACL,kBAAY;AACZ,UAAI,IAAI;AAAA,IACV;AAAA,IACA,OAAO;AACL,kBAAY;AAAA,IACd;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,MAAM;AAAA,EACf;AACF;AAEA,IAAI;AAKW,SAAR,SAAsC;AAC3C,MAAI,CAAC,KAAK;AACR,UAAM,iBAAiB;AAAA,EACzB;AAEA,SAAO;AACT;",
4
+ "sourcesContent": ["/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */\nimport { useService } from './service.js';\nimport { useScheduler } from '../utils/scheduler.js';\nimport { isFunction } from '../utils/is.js';\nimport type { ServiceInterface } from './index.js';\n\nconst scheduler = useScheduler(['update', 'render']);\n\nexport type RafService = ServiceInterface<RafServiceProps>;\n\nexport interface RafServiceProps {\n time: DOMHighResTimeStamp;\n}\n\n/**\n * Create raf service.\n */\nfunction createRafService(): RafService {\n let isTicking = false;\n\n /**\n * Trigger callbacks.\n */\n function trigger(props: RafServiceProps) {\n for (const callback of callbacks.values()) {\n scheduler.update(() => {\n const render = callback(props) as (() => unknown) | void;\n if (isFunction(render)) {\n scheduler.render(() => {\n // @ts-ignore\n render(props);\n });\n }\n });\n }\n }\n\n /**\n * Loop.\n */\n function loop() {\n // eslint-disable-next-line no-use-before-define\n props.time = performance.now();\n trigger(props);\n\n if (!isTicking) {\n return;\n }\n\n requestAnimationFrame(loop);\n }\n\n const { add, remove, has, props, callbacks } = useService({\n props: {\n time: performance.now(),\n } as RafServiceProps,\n init() {\n isTicking = true;\n requestAnimationFrame(loop);\n },\n kill() {\n isTicking = false;\n },\n });\n\n return {\n add,\n remove,\n has,\n props: () => props,\n };\n}\n\nlet raf;\n\n/**\n * Use the RequestAnimationFrame (raf) service.\n */\nexport default function useRaf(): RafService {\n if (!raf) {\n raf = createRafService();\n }\n\n return raf;\n}\n"],
5
+ "mappings": "AACA,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAG3B,MAAM,YAAY,aAAa,CAAC,UAAU,QAAQ,CAAC;AAWnD,SAAS,mBAA+B;AACtC,MAAI,YAAY;AAKhB,WAAS,QAAQA,QAAwB;AACvC,eAAW,YAAY,UAAU,OAAO,GAAG;AACzC,gBAAU,OAAO,MAAM;AACrB,cAAM,SAAS,SAASA,MAAK;AAC7B,YAAI,WAAW,MAAM,GAAG;AACtB,oBAAU,OAAO,MAAM;AAErB,mBAAOA,MAAK;AAAA,UACd,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAKA,WAAS,OAAO;AAEd,UAAM,OAAO,YAAY,IAAI;AAC7B,YAAQ,KAAK;AAEb,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AAEA,0BAAsB,IAAI;AAAA,EAC5B;AAEA,QAAM,EAAE,KAAK,QAAQ,KAAK,OAAO,UAAU,IAAI,WAAW;AAAA,IACxD,OAAO;AAAA,MACL,MAAM,YAAY,IAAI;AAAA,IACxB;AAAA,IACA,OAAO;AACL,kBAAY;AACZ,4BAAsB,IAAI;AAAA,IAC5B;AAAA,IACA,OAAO;AACL,kBAAY;AAAA,IACd;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,MAAM;AAAA,EACf;AACF;AAEA,IAAI;AAKW,SAAR,SAAsC;AAC3C,MAAI,CAAC,KAAK;AACR,UAAM,iBAAiB;AAAA,EACzB;AAEA,SAAO;AACT;",
6
6
  "names": ["props"]
7
7
  }
@@ -1,14 +1,15 @@
1
- import type { ServiceInterface } from './index.js';
2
- export type ResizeService = ServiceInterface<ResizeServiceProps>;
3
- export interface ResizeServiceProps {
1
+ import type { Features } from '../Base/features.js';
2
+ import type { ResizeServiceInterface } from './index.js';
3
+ export interface ResizeServiceProps<U extends Features['breakpoints'] = Features['breakpoints']> {
4
4
  width: number;
5
5
  height: number;
6
6
  ratio: number;
7
7
  orientation: 'square' | 'landscape' | 'portrait';
8
- breakpoint?: string;
9
- breakpoints?: string[];
8
+ breakpoint: string;
9
+ breakpoints: string[];
10
+ activeBreakpoints: Record<keyof U, boolean>;
10
11
  }
11
12
  /**
12
13
  * Use the resize service.
13
14
  */
14
- export default function useResize(): ResizeService;
15
+ export default function useResize<T extends Features['breakpoints'] = Features['breakpoints']>(breakpoints?: T): ResizeServiceInterface<T>;
@@ -1,24 +1,7 @@
1
1
  import { useService } from "./service.js";
2
+ import { features } from "../Base/features.js";
2
3
  import debounce from "../utils/debounce.js";
3
- let breakpointElement;
4
- let breakpoints = [];
5
- function getBreakpointElement() {
6
- if (!breakpointElement) {
7
- breakpointElement = document.querySelector("[data-breakpoint]");
8
- }
9
- return breakpointElement;
10
- }
11
- function getBreakpoint() {
12
- return getBreakpointElement() ? window.getComputedStyle(getBreakpointElement(), "::before").getPropertyValue("content").replaceAll('"', "") : void 0;
13
- }
14
- function getBreakpoints() {
15
- if (!getBreakpointElement() || breakpoints.length) {
16
- return breakpoints;
17
- }
18
- breakpoints = window.getComputedStyle(getBreakpointElement(), "::after").getPropertyValue("content").replaceAll('"', "").split(",");
19
- return breakpoints;
20
- }
21
- function createResizeService() {
4
+ function createResizeService(breakpoints) {
22
5
  function updateProps() {
23
6
  props.width = window.innerWidth;
24
7
  props.height = window.innerHeight;
@@ -42,10 +25,18 @@ function createResizeService() {
42
25
  ratio: window.innerWidth / window.innerHeight,
43
26
  orientation: "square",
44
27
  get breakpoint() {
45
- return getBreakpoint();
28
+ return Object.keys(this.activeBreakpoints).toReversed().find((name) => this.activeBreakpoints[name]);
46
29
  },
47
30
  get breakpoints() {
48
- return getBreakpoints();
31
+ return Object.keys(this.activeBreakpoints);
32
+ },
33
+ get activeBreakpoints() {
34
+ return Object.fromEntries(
35
+ Object.entries(breakpoints ?? features.get("breakpoints")).map(([name, breakpoint]) => [
36
+ name,
37
+ window.matchMedia(`(min-width: ${breakpoint})`).matches
38
+ ])
39
+ );
49
40
  }
50
41
  },
51
42
  init() {
@@ -62,12 +53,13 @@ function createResizeService() {
62
53
  props: () => props
63
54
  };
64
55
  }
65
- let resize;
66
- function useResize() {
67
- if (!resize) {
68
- resize = createResizeService();
56
+ const instances = /* @__PURE__ */ new Map();
57
+ function useResize(breakpoints) {
58
+ const key = JSON.stringify(breakpoints);
59
+ if (!instances.has(key)) {
60
+ instances.set(key, createResizeService(breakpoints));
69
61
  }
70
- return resize;
62
+ return instances.get(key);
71
63
  }
72
64
  export {
73
65
  useResize as default
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../packages/js-toolkit/services/resize.ts"],
4
- "sourcesContent": ["/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */\nimport { useService } from './service.js';\nimport debounce from '../utils/debounce.js';\nimport type { ServiceInterface } from './index.js';\n\nexport type ResizeService = ServiceInterface<ResizeServiceProps>;\n\nexport interface ResizeServiceProps {\n width: number;\n height: number;\n ratio: number;\n orientation: 'square' | 'landscape' | 'portrait';\n breakpoint?: string;\n breakpoints?: string[];\n}\n\nlet breakpointElement;\nlet breakpoints = [];\n\n/**\n * The element holding the breakpoints data.\n */\nfunction getBreakpointElement(): HTMLElement {\n if (!breakpointElement) {\n breakpointElement = document.querySelector('[data-breakpoint]');\n }\n return breakpointElement;\n}\n\n/**\n * Get the current breakpoint.\n */\nfunction getBreakpoint(): string | null {\n return getBreakpointElement()\n ? window\n .getComputedStyle(getBreakpointElement(), '::before')\n .getPropertyValue('content')\n .replaceAll('\"', '')\n : undefined;\n}\n\n/**\n * Get all breakpoints.\n */\nfunction getBreakpoints(): string[] {\n if (!getBreakpointElement() || breakpoints.length) {\n return breakpoints;\n }\n breakpoints = window\n .getComputedStyle(getBreakpointElement(), '::after')\n .getPropertyValue('content')\n .replaceAll('\"', '')\n .split(',');\n\n return breakpoints;\n}\n\n/**\n * Get resize service.\n */\nfunction createResizeService(): ResizeService {\n /**\n * Update props.\n */\n function updateProps(): ResizeServiceProps {\n props.width = window.innerWidth;\n props.height = window.innerHeight;\n props.ratio = window.innerWidth / window.innerHeight;\n props.orientation = 'square';\n\n if (props.ratio > 1) {\n props.orientation = 'landscape';\n }\n\n if (props.ratio < 1) {\n props.orientation = 'portrait';\n }\n\n return props;\n }\n\n const onResize = debounce(() => {\n trigger(updateProps());\n });\n\n const { add, remove, has, trigger, props } = useService({\n props: {\n width: window.innerWidth,\n height: window.innerHeight,\n ratio: window.innerWidth / window.innerHeight,\n orientation: 'square',\n get breakpoint() {\n return getBreakpoint();\n },\n get breakpoints() {\n return getBreakpoints();\n },\n } as ResizeServiceProps,\n init() {\n window.addEventListener('resize', onResize);\n },\n kill() {\n window.removeEventListener('resize', onResize);\n },\n });\n\n return {\n add,\n remove,\n has,\n props: () => props,\n };\n}\n\nlet resize;\n\n/**\n * Use the resize service.\n */\nexport default function useResize(): ResizeService {\n if (!resize) {\n resize = createResizeService();\n }\n\n return resize;\n}\n"],
5
- "mappings": "AACA,SAAS,kBAAkB;AAC3B,OAAO,cAAc;AAcrB,IAAI;AACJ,IAAI,cAAc,CAAC;AAKnB,SAAS,uBAAoC;AAC3C,MAAI,CAAC,mBAAmB;AACtB,wBAAoB,SAAS,cAAc,mBAAmB;AAAA,EAChE;AACA,SAAO;AACT;AAKA,SAAS,gBAA+B;AACtC,SAAO,qBAAqB,IACxB,OACG,iBAAiB,qBAAqB,GAAG,UAAU,EACnD,iBAAiB,SAAS,EAC1B,WAAW,KAAK,EAAE,IACrB;AACN;AAKA,SAAS,iBAA2B;AAClC,MAAI,CAAC,qBAAqB,KAAK,YAAY,QAAQ;AACjD,WAAO;AAAA,EACT;AACA,gBAAc,OACX,iBAAiB,qBAAqB,GAAG,SAAS,EAClD,iBAAiB,SAAS,EAC1B,WAAW,KAAK,EAAE,EAClB,MAAM,GAAG;AAEZ,SAAO;AACT;AAKA,SAAS,sBAAqC;AAI5C,WAAS,cAAkC;AACzC,UAAM,QAAQ,OAAO;AACrB,UAAM,SAAS,OAAO;AACtB,UAAM,QAAQ,OAAO,aAAa,OAAO;AACzC,UAAM,cAAc;AAEpB,QAAI,MAAM,QAAQ,GAAG;AACnB,YAAM,cAAc;AAAA,IACtB;AAEA,QAAI,MAAM,QAAQ,GAAG;AACnB,YAAM,cAAc;AAAA,IACtB;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,SAAS,MAAM;AAC9B,YAAQ,YAAY,CAAC;AAAA,EACvB,CAAC;AAED,QAAM,EAAE,KAAK,QAAQ,KAAK,SAAS,MAAM,IAAI,WAAW;AAAA,IACtD,OAAO;AAAA,MACL,OAAO,OAAO;AAAA,MACd,QAAQ,OAAO;AAAA,MACf,OAAO,OAAO,aAAa,OAAO;AAAA,MAClC,aAAa;AAAA,MACb,IAAI,aAAa;AACf,eAAO,cAAc;AAAA,MACvB;AAAA,MACA,IAAI,cAAc;AAChB,eAAO,eAAe;AAAA,MACxB;AAAA,IACF;AAAA,IACA,OAAO;AACL,aAAO,iBAAiB,UAAU,QAAQ;AAAA,IAC5C;AAAA,IACA,OAAO;AACL,aAAO,oBAAoB,UAAU,QAAQ;AAAA,IAC/C;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,MAAM;AAAA,EACf;AACF;AAEA,IAAI;AAKW,SAAR,YAA4C;AACjD,MAAI,CAAC,QAAQ;AACX,aAAS,oBAAoB;AAAA,EAC/B;AAEA,SAAO;AACT;",
4
+ "sourcesContent": ["/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */\nimport { useService } from './service.js';\nimport { features } from '../Base/features.js';\nimport type { Features } from '../Base/features.js';\nimport debounce from '../utils/debounce.js';\nimport type { ResizeServiceInterface } from './index.js';\n\nexport interface ResizeServiceProps<U extends Features['breakpoints'] = Features['breakpoints']> {\n width: number;\n height: number;\n ratio: number;\n orientation: 'square' | 'landscape' | 'portrait';\n breakpoint: string;\n breakpoints: string[];\n activeBreakpoints: Record<keyof U, boolean>;\n}\n\n/**\n * Get resize service.\n */\nfunction createResizeService<T extends Features['breakpoints'] = Features['breakpoints']>(\n breakpoints?: T,\n): ResizeServiceInterface<T> {\n /**\n * Update props.\n */\n function updateProps(): ResizeServiceProps<T> {\n props.width = window.innerWidth;\n props.height = window.innerHeight;\n props.ratio = window.innerWidth / window.innerHeight;\n props.orientation = 'square';\n\n if (props.ratio > 1) {\n props.orientation = 'landscape';\n }\n\n if (props.ratio < 1) {\n props.orientation = 'portrait';\n }\n\n return props;\n }\n\n const onResize = debounce(() => {\n trigger(updateProps());\n });\n\n const { add, remove, has, trigger, props } = useService({\n props: {\n width: window.innerWidth,\n height: window.innerHeight,\n ratio: window.innerWidth / window.innerHeight,\n orientation: 'square',\n get breakpoint() {\n return Object.keys(this.activeBreakpoints)\n .toReversed()\n .find((name) => this.activeBreakpoints[name]);\n },\n get breakpoints() {\n return Object.keys(this.activeBreakpoints);\n },\n get activeBreakpoints() {\n return Object.fromEntries(\n Object.entries(breakpoints ?? features.get('breakpoints')).map(([name, breakpoint]) => [\n name,\n window.matchMedia(`(min-width: ${breakpoint})`).matches,\n ]),\n ) as Record<keyof T, boolean>;\n },\n } as ResizeServiceProps<T>,\n init() {\n window.addEventListener('resize', onResize);\n },\n kill() {\n window.removeEventListener('resize', onResize);\n },\n });\n\n return {\n add,\n remove,\n has,\n props: () => props,\n };\n}\n\nconst instances: Map<string, ResizeServiceInterface | undefined> = new Map();\n\n/**\n * Use the resize service.\n */\nexport default function useResize<T extends Features['breakpoints'] = Features['breakpoints']>(\n breakpoints?: T,\n): ResizeServiceInterface<T> {\n const key = JSON.stringify(breakpoints);\n\n if (!instances.has(key)) {\n instances.set(key, createResizeService(breakpoints));\n }\n\n return (instances as Map<string, ResizeServiceInterface<T>>).get(key);\n}\n"],
5
+ "mappings": "AACA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAEzB,OAAO,cAAc;AAgBrB,SAAS,oBACP,aAC2B;AAI3B,WAAS,cAAqC;AAC5C,UAAM,QAAQ,OAAO;AACrB,UAAM,SAAS,OAAO;AACtB,UAAM,QAAQ,OAAO,aAAa,OAAO;AACzC,UAAM,cAAc;AAEpB,QAAI,MAAM,QAAQ,GAAG;AACnB,YAAM,cAAc;AAAA,IACtB;AAEA,QAAI,MAAM,QAAQ,GAAG;AACnB,YAAM,cAAc;AAAA,IACtB;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,SAAS,MAAM;AAC9B,YAAQ,YAAY,CAAC;AAAA,EACvB,CAAC;AAED,QAAM,EAAE,KAAK,QAAQ,KAAK,SAAS,MAAM,IAAI,WAAW;AAAA,IACtD,OAAO;AAAA,MACL,OAAO,OAAO;AAAA,MACd,QAAQ,OAAO;AAAA,MACf,OAAO,OAAO,aAAa,OAAO;AAAA,MAClC,aAAa;AAAA,MACb,IAAI,aAAa;AACf,eAAO,OAAO,KAAK,KAAK,iBAAiB,EACtC,WAAW,EACX,KAAK,CAAC,SAAS,KAAK,kBAAkB,IAAI,CAAC;AAAA,MAChD;AAAA,MACA,IAAI,cAAc;AAChB,eAAO,OAAO,KAAK,KAAK,iBAAiB;AAAA,MAC3C;AAAA,MACA,IAAI,oBAAoB;AACtB,eAAO,OAAO;AAAA,UACZ,OAAO,QAAQ,eAAe,SAAS,IAAI,aAAa,CAAC,EAAE,IAAI,CAAC,CAAC,MAAM,UAAU,MAAM;AAAA,YACrF;AAAA,YACA,OAAO,WAAW,eAAe,UAAU,GAAG,EAAE;AAAA,UAClD,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,IACA,OAAO;AACL,aAAO,iBAAiB,UAAU,QAAQ;AAAA,IAC5C;AAAA,IACA,OAAO;AACL,aAAO,oBAAoB,UAAU,QAAQ;AAAA,IAC/C;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,MAAM;AAAA,EACf;AACF;AAEA,MAAM,YAA6D,oBAAI,IAAI;AAK5D,SAAR,UACL,aAC2B;AAC3B,QAAM,MAAM,KAAK,UAAU,WAAW;AAEtC,MAAI,CAAC,UAAU,IAAI,GAAG,GAAG;AACvB,cAAU,IAAI,KAAK,oBAAoB,WAAW,CAAC;AAAA,EACrD;AAEA,SAAQ,UAAqD,IAAI,GAAG;AACtE;",
6
6
  "names": []
7
7
  }
@@ -7,26 +7,40 @@ export interface ScrollServiceProps {
7
7
  x: boolean;
8
8
  y: boolean;
9
9
  };
10
+ changedX: boolean;
11
+ changedY: boolean;
10
12
  last: {
11
13
  x: number;
12
14
  y: number;
13
15
  };
16
+ lastX: number;
17
+ lastY: number;
14
18
  delta: {
15
19
  x: number;
16
20
  y: number;
17
21
  };
22
+ deltaX: number;
23
+ deltaY: number;
18
24
  progress: {
19
25
  x: number;
20
26
  y: number;
21
27
  };
28
+ progressX: number;
29
+ progressY: number;
22
30
  max: {
23
31
  x: number;
24
32
  y: number;
25
33
  };
34
+ maxX: number;
35
+ maxY: number;
26
36
  direction: {
27
37
  x: 'LEFT' | 'RIGHT' | 'NONE';
28
38
  y: 'UP' | 'DOWN' | 'NONE';
29
39
  };
40
+ isUp: boolean;
41
+ isRight: boolean;
42
+ isDown: boolean;
43
+ isLeft: boolean;
30
44
  }
31
45
  /**
32
46
  * Use the scroll service.
@@ -4,24 +4,28 @@ function createScrollService() {
4
4
  function updateProps() {
5
5
  const yLast = props.y;
6
6
  const xLast = props.x;
7
- if (window.pageYOffset !== props.y) {
8
- props.y = window.pageYOffset;
7
+ if (window.scrollY !== props.y) {
8
+ props.y = window.scrollY;
9
9
  }
10
- if (window.pageXOffset !== props.x) {
11
- props.x = window.pageXOffset;
10
+ if (window.scrollX !== props.x) {
11
+ props.x = window.scrollX;
12
12
  }
13
- props.changed.x = props.x !== xLast;
14
- props.changed.y = props.y !== yLast;
15
- props.last.x = xLast;
16
- props.last.y = yLast;
17
- props.delta.x = props.x - xLast;
18
- props.delta.y = props.y - yLast;
19
- props.max.x = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
20
- props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
21
- props.progress.x = props.max.x === 0 ? 1 : props.x / props.max.x;
22
- props.progress.y = props.max.y === 0 ? 1 : props.y / props.max.y;
23
- props.direction.x = props.x > xLast ? "RIGHT" : props.x < xLast ? "LEFT" : "NONE";
24
- props.direction.y = props.y > yLast ? "DOWN" : props.y < yLast ? "UP" : "NONE";
13
+ props.changed.x = props.changedX = props.x !== xLast;
14
+ props.changed.y = props.changedY = props.y !== yLast;
15
+ props.last.x = props.lastX = xLast;
16
+ props.last.y = props.lastY = yLast;
17
+ props.delta.x = props.deltaX = props.x - xLast;
18
+ props.delta.y = props.deltaY = props.y - yLast;
19
+ props.max.x = props.maxX = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
20
+ props.max.y = props.maxY = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
21
+ props.progress.x = props.progressX = props.max.x === 0 ? 1 : props.x / props.max.x;
22
+ props.progress.y = props.progressY = props.max.y === 0 ? 1 : props.y / props.max.y;
23
+ props.isUp = props.y < yLast;
24
+ props.isRight = props.x > xLast;
25
+ props.isDown = props.y > yLast;
26
+ props.isLeft = props.x < xLast;
27
+ props.direction.x = props.isRight ? "RIGHT" : props.isLeft ? "LEFT" : "NONE";
28
+ props.direction.y = props.isDown ? "DOWN" : props.isUp ? "UP" : "NONE";
25
29
  return props;
26
30
  }
27
31
  const onScrollDebounced = debounce(() => {
@@ -33,32 +37,46 @@ function createScrollService() {
33
37
  }
34
38
  const { add, remove, has, props, trigger } = useService({
35
39
  props: {
36
- x: window.pageXOffset,
37
- y: window.pageYOffset,
40
+ x: window.scrollX,
41
+ y: window.scrollY,
38
42
  changed: {
39
43
  x: false,
40
44
  y: false
41
45
  },
46
+ changedX: false,
47
+ changedY: false,
42
48
  last: {
43
- x: window.pageXOffset,
44
- y: window.pageYOffset
49
+ x: window.scrollX,
50
+ y: window.scrollY
45
51
  },
52
+ lastX: window.scrollX,
53
+ lastY: window.scrollY,
46
54
  delta: {
47
55
  x: 0,
48
56
  y: 0
49
57
  },
58
+ deltaX: 0,
59
+ deltaY: 0,
50
60
  max: {
51
61
  x: (document.scrollingElement || document.body).scrollWidth - window.innerWidth,
52
62
  y: (document.scrollingElement || document.body).scrollHeight - window.innerHeight
53
63
  },
64
+ maxX: (document.scrollingElement || document.body).scrollWidth - window.innerWidth,
65
+ maxY: (document.scrollingElement || document.body).scrollHeight - window.innerHeight,
54
66
  progress: {
55
67
  x: 0,
56
68
  y: 0
57
69
  },
70
+ progressX: 0,
71
+ progressY: 0,
58
72
  direction: {
59
73
  x: "NONE",
60
74
  y: "NONE"
61
- }
75
+ },
76
+ isUp: false,
77
+ isRight: false,
78
+ isDown: false,
79
+ isLeft: false
62
80
  },
63
81
  init() {
64
82
  document.addEventListener("scroll", onScroll, { passive: true, capture: true });