@studiometa/js-toolkit 2.12.0 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/Base/Base.d.ts +2 -2
  2. package/Base/Base.js +8 -45
  3. package/Base/Base.js.map +2 -2
  4. package/Base/features.d.ts +10 -2
  5. package/Base/features.js +23 -1
  6. package/Base/features.js.map +2 -2
  7. package/Base/managers/AbstractManager.d.ts +3 -3
  8. package/Base/managers/ActionManager.d.ts +4 -0
  9. package/Base/managers/ActionManager.js +10 -0
  10. package/Base/managers/ActionManager.js.map +7 -0
  11. package/Base/managers/ChildrenManager.d.ts +1 -1
  12. package/Base/managers/ServicesManager.d.ts +2 -4
  13. package/Base/managers/ServicesManager.js +2 -3
  14. package/Base/managers/ServicesManager.js.map +2 -2
  15. package/Base/utils.js +1 -1
  16. package/Base/utils.js.map +2 -2
  17. package/decorators/index.d.ts +0 -1
  18. package/decorators/index.js +0 -1
  19. package/decorators/index.js.map +2 -2
  20. package/decorators/withBreakpointObserver.js +1 -1
  21. package/decorators/withBreakpointObserver.js.map +2 -2
  22. package/decorators/withIntersectionObserver.js +1 -1
  23. package/decorators/withIntersectionObserver.js.map +2 -2
  24. package/decorators/withMountOnMediaQuery.js +1 -1
  25. package/decorators/withMountOnMediaQuery.js.map +2 -2
  26. package/decorators/withMountWhenInView.js +1 -1
  27. package/decorators/withMountWhenInView.js.map +2 -2
  28. package/decorators/withScrolledInView/utils.d.ts +12 -1
  29. package/decorators/withScrolledInView/utils.js.map +2 -2
  30. package/decorators/withScrolledInView/withScrolledInView.js +7 -62
  31. package/decorators/withScrolledInView/withScrolledInView.js.map +2 -2
  32. package/helpers/createApp.d.ts +2 -1
  33. package/helpers/createApp.js.map +2 -2
  34. package/package.json +2 -10
  35. package/services/index.d.ts +1 -1
  36. package/services/index.js.map +2 -2
  37. package/services/pointer.d.ts +1 -1
  38. package/services/pointer.js +3 -3
  39. package/services/pointer.js.map +2 -2
  40. package/services/raf.js +2 -4
  41. package/services/raf.js.map +2 -2
  42. package/services/resize.d.ts +7 -6
  43. package/services/resize.js +19 -26
  44. package/services/resize.js.map +2 -2
  45. package/services/scroll.js +8 -8
  46. package/services/scroll.js.map +2 -2
  47. package/utils/SmartQueue.d.ts +1 -1
  48. package/utils/SmartQueue.js +1 -1
  49. package/utils/SmartQueue.js.map +2 -2
  50. package/utils/css/animate.d.ts +33 -15
  51. package/utils/css/animate.js +67 -26
  52. package/utils/css/animate.js.map +2 -2
  53. package/utils/css/getOffsetSizes.js +2 -2
  54. package/utils/css/getOffsetSizes.js.map +1 -1
  55. package/utils/css/index.d.ts +2 -1
  56. package/utils/css/index.js +4 -4
  57. package/utils/css/index.js.map +2 -2
  58. package/utils/css/matrix.d.ts +1 -1
  59. package/utils/css/matrix.js.map +2 -2
  60. package/utils/css/transform.d.ts +1 -1
  61. package/utils/css/transform.js +1 -1
  62. package/utils/css/transform.js.map +2 -2
  63. package/utils/css/utils.d.ts +1 -1
  64. package/utils/css/utils.js +1 -1
  65. package/utils/css/utils.js.map +2 -2
  66. package/utils/index.d.ts +5 -4
  67. package/utils/index.js +16 -16
  68. package/utils/index.js.map +2 -2
  69. package/utils/is.d.ts +12 -0
  70. package/utils/is.js +17 -0
  71. package/utils/is.js.map +2 -2
  72. package/utils/math/ease.d.ts +1 -0
  73. package/utils/math/ease.js +2 -0
  74. package/utils/math/ease.js.map +2 -2
  75. package/utils/math/index.d.ts +4 -3
  76. package/utils/math/index.js +5 -3
  77. package/utils/math/index.js.map +2 -2
  78. package/utils/math/mean.d.ts +1 -0
  79. package/utils/math/mean.js +17 -0
  80. package/utils/math/mean.js.map +7 -0
  81. package/utils/nextFrame.d.ts +4 -22
  82. package/utils/nextFrame.js +3 -10
  83. package/utils/nextFrame.js.map +2 -2
  84. package/utils/nextMicrotask.d.ts +4 -1
  85. package/utils/nextMicrotask.js +3 -3
  86. package/utils/nextMicrotask.js.map +2 -2
  87. package/utils/nextTick.d.ts +4 -1
  88. package/utils/nextTick.js +3 -3
  89. package/utils/nextTick.js.map +2 -2
  90. package/utils/random.d.ts +15 -0
  91. package/utils/random.js +15 -0
  92. package/utils/random.js.map +7 -0
  93. package/utils/scrollTo.d.ts +30 -6
  94. package/utils/scrollTo.js +97 -43
  95. package/utils/scrollTo.js.map +2 -2
  96. package/utils/{focusTrap.d.ts → trapFocus.d.ts} +2 -10
  97. package/utils/{focusTrap.js → trapFocus.js} +5 -9
  98. package/utils/trapFocus.js.map +7 -0
  99. package/utils/tween.d.ts +59 -10
  100. package/utils/tween.js +24 -18
  101. package/utils/tween.js.map +2 -2
  102. package/Base/Base.cjs +0 -420
  103. package/Base/Base.cjs.map +0 -7
  104. package/Base/features.cjs +0 -27
  105. package/Base/features.cjs.map +0 -7
  106. package/Base/index.cjs +0 -21
  107. package/Base/index.cjs.map +0 -7
  108. package/Base/managers/AbstractManager.cjs +0 -78
  109. package/Base/managers/AbstractManager.cjs.map +0 -7
  110. package/Base/managers/ChildrenManager.cjs +0 -156
  111. package/Base/managers/ChildrenManager.cjs.map +0 -7
  112. package/Base/managers/EventsManager.cjs +0 -305
  113. package/Base/managers/EventsManager.cjs.map +0 -7
  114. package/Base/managers/OptionsManager.cjs +0 -198
  115. package/Base/managers/OptionsManager.cjs.map +0 -7
  116. package/Base/managers/RefsManager.cjs +0 -118
  117. package/Base/managers/RefsManager.cjs.map +0 -7
  118. package/Base/managers/ResponsiveOptionsManager.cjs +0 -79
  119. package/Base/managers/ResponsiveOptionsManager.cjs.map +0 -7
  120. package/Base/managers/ServicesManager.cjs +0 -161
  121. package/Base/managers/ServicesManager.cjs.map +0 -7
  122. package/Base/managers/index.cjs +0 -39
  123. package/Base/managers/index.cjs.map +0 -7
  124. package/Base/types.cjs +0 -19
  125. package/Base/types.cjs.map +0 -7
  126. package/Base/utils.cjs +0 -95
  127. package/Base/utils.cjs.map +0 -7
  128. package/decorators/index.cjs +0 -33
  129. package/decorators/index.cjs.map +0 -7
  130. package/decorators/withBreakpointManager.cjs +0 -102
  131. package/decorators/withBreakpointManager.cjs.map +0 -7
  132. package/decorators/withBreakpointObserver.cjs +0 -128
  133. package/decorators/withBreakpointObserver.cjs.map +0 -7
  134. package/decorators/withDrag.cjs +0 -56
  135. package/decorators/withDrag.cjs.map +0 -7
  136. package/decorators/withExtraConfig.cjs +0 -50
  137. package/decorators/withExtraConfig.cjs.map +0 -7
  138. package/decorators/withFreezedOptions.cjs +0 -50
  139. package/decorators/withFreezedOptions.cjs.map +0 -7
  140. package/decorators/withIntersectionObserver.cjs +0 -71
  141. package/decorators/withIntersectionObserver.cjs.map +0 -7
  142. package/decorators/withMountOnMediaQuery.cjs +0 -86
  143. package/decorators/withMountOnMediaQuery.cjs.map +0 -7
  144. package/decorators/withMountWhenInView.cjs +0 -92
  145. package/decorators/withMountWhenInView.cjs.map +0 -7
  146. package/decorators/withMountWhenPrefersMotion.cjs +0 -30
  147. package/decorators/withMountWhenPrefersMotion.cjs.map +0 -7
  148. package/decorators/withRelativePointer.cjs +0 -56
  149. package/decorators/withRelativePointer.cjs.map +0 -7
  150. package/decorators/withResponsiveOptions.cjs +0 -41
  151. package/decorators/withResponsiveOptions.cjs.map +0 -7
  152. package/decorators/withScrolledInView/index.cjs +0 -22
  153. package/decorators/withScrolledInView/index.cjs.map +0 -7
  154. package/decorators/withScrolledInView/types.cjs +0 -19
  155. package/decorators/withScrolledInView/types.cjs.map +0 -7
  156. package/decorators/withScrolledInView/utils.cjs +0 -99
  157. package/decorators/withScrolledInView/utils.cjs.map +0 -7
  158. package/decorators/withScrolledInView/withScrolledInView.cjs +0 -249
  159. package/decorators/withScrolledInView/withScrolledInView.cjs.map +0 -7
  160. package/decorators/withVue2.cjs +0 -68
  161. package/decorators/withVue2.cjs.map +0 -7
  162. package/decorators/withVue2.d.ts +0 -16
  163. package/decorators/withVue2.js +0 -46
  164. package/decorators/withVue2.js.map +0 -7
  165. package/helpers/createApp.cjs +0 -58
  166. package/helpers/createApp.cjs.map +0 -7
  167. package/helpers/getClosestParent.cjs +0 -45
  168. package/helpers/getClosestParent.cjs.map +0 -7
  169. package/helpers/getDirectChildren.cjs +0 -47
  170. package/helpers/getDirectChildren.cjs.map +0 -7
  171. package/helpers/getInstanceFromElement.cjs +0 -32
  172. package/helpers/getInstanceFromElement.cjs.map +0 -7
  173. package/helpers/importOnInteraction.cjs +0 -48
  174. package/helpers/importOnInteraction.cjs.map +0 -7
  175. package/helpers/importOnMediaQuery.cjs +0 -44
  176. package/helpers/importOnMediaQuery.cjs.map +0 -7
  177. package/helpers/importWhenIdle.cjs +0 -46
  178. package/helpers/importWhenIdle.cjs.map +0 -7
  179. package/helpers/importWhenPrefersMotion.cjs +0 -40
  180. package/helpers/importWhenPrefersMotion.cjs.map +0 -7
  181. package/helpers/importWhenVisible.cjs +0 -44
  182. package/helpers/importWhenVisible.cjs.map +0 -7
  183. package/helpers/index.cjs +0 -53
  184. package/helpers/index.cjs.map +0 -7
  185. package/helpers/utils.cjs +0 -37
  186. package/helpers/utils.cjs.map +0 -7
  187. package/index.cjs +0 -31
  188. package/index.cjs.map +0 -7
  189. package/services/drag.cjs +0 -231
  190. package/services/drag.cjs.map +0 -7
  191. package/services/index.cjs +0 -51
  192. package/services/index.cjs.map +0 -7
  193. package/services/key.cjs +0 -97
  194. package/services/key.cjs.map +0 -7
  195. package/services/load.cjs +0 -60
  196. package/services/load.cjs.map +0 -7
  197. package/services/pointer.cjs +0 -145
  198. package/services/pointer.cjs.map +0 -7
  199. package/services/raf.cjs +0 -80
  200. package/services/raf.cjs.map +0 -7
  201. package/services/resize.cjs +0 -107
  202. package/services/resize.cjs.map +0 -7
  203. package/services/scroll.cjs +0 -119
  204. package/services/scroll.cjs.map +0 -7
  205. package/services/service.cjs +0 -69
  206. package/services/service.cjs.map +0 -7
  207. package/utils/Queue.cjs +0 -93
  208. package/utils/Queue.cjs.map +0 -7
  209. package/utils/SmartQueue.cjs +0 -73
  210. package/utils/SmartQueue.cjs.map +0 -7
  211. package/utils/collide/boundingRectToCircle.cjs +0 -36
  212. package/utils/collide/boundingRectToCircle.cjs.map +0 -7
  213. package/utils/collide/collideCircleCircle.cjs +0 -35
  214. package/utils/collide/collideCircleCircle.cjs.map +0 -7
  215. package/utils/collide/collideCircleRect.cjs +0 -47
  216. package/utils/collide/collideCircleRect.cjs.map +0 -7
  217. package/utils/collide/collidePointCircle.cjs +0 -32
  218. package/utils/collide/collidePointCircle.cjs.map +0 -7
  219. package/utils/collide/collidePointRect.cjs +0 -32
  220. package/utils/collide/collidePointRect.cjs.map +0 -7
  221. package/utils/collide/collideRectRect.cjs +0 -32
  222. package/utils/collide/collideRectRect.cjs.map +0 -7
  223. package/utils/collide/index.cjs +0 -47
  224. package/utils/collide/index.cjs.map +0 -7
  225. package/utils/css/animate.cjs +0 -202
  226. package/utils/css/animate.cjs.map +0 -7
  227. package/utils/css/classes.cjs +0 -51
  228. package/utils/css/classes.cjs.map +0 -7
  229. package/utils/css/getOffsetSizes.cjs +0 -48
  230. package/utils/css/getOffsetSizes.cjs.map +0 -7
  231. package/utils/css/index.cjs +0 -52
  232. package/utils/css/index.cjs.map +0 -7
  233. package/utils/css/matrix.cjs +0 -30
  234. package/utils/css/matrix.cjs.map +0 -7
  235. package/utils/css/styles.cjs +0 -45
  236. package/utils/css/styles.cjs.map +0 -7
  237. package/utils/css/transform.cjs +0 -91
  238. package/utils/css/transform.cjs.map +0 -7
  239. package/utils/css/transition.cjs +0 -145
  240. package/utils/css/transition.cjs.map +0 -7
  241. package/utils/css/utils.cjs +0 -32
  242. package/utils/css/utils.cjs.map +0 -7
  243. package/utils/debounce.cjs +0 -35
  244. package/utils/debounce.cjs.map +0 -7
  245. package/utils/dom/ancestors.cjs +0 -37
  246. package/utils/dom/ancestors.cjs.map +0 -7
  247. package/utils/dom/index.cjs +0 -21
  248. package/utils/dom/index.cjs.map +0 -7
  249. package/utils/focusTrap.cjs +0 -93
  250. package/utils/focusTrap.cjs.map +0 -7
  251. package/utils/focusTrap.js.map +0 -7
  252. package/utils/getComponentResolver.cjs +0 -38
  253. package/utils/getComponentResolver.cjs.map +0 -7
  254. package/utils/has.cjs +0 -29
  255. package/utils/has.cjs.map +0 -7
  256. package/utils/history.cjs +0 -92
  257. package/utils/history.cjs.map +0 -7
  258. package/utils/index.cjs +0 -76
  259. package/utils/index.cjs.map +0 -7
  260. package/utils/is.cjs +0 -41
  261. package/utils/is.cjs.map +0 -7
  262. package/utils/keyCodes.cjs +0 -36
  263. package/utils/keyCodes.cjs.map +0 -7
  264. package/utils/math/clamp.cjs +0 -29
  265. package/utils/math/clamp.cjs.map +0 -7
  266. package/utils/math/clamp01.cjs +0 -40
  267. package/utils/math/clamp01.cjs.map +0 -7
  268. package/utils/math/createEases.cjs +0 -33
  269. package/utils/math/createEases.cjs.map +0 -7
  270. package/utils/math/damp.cjs +0 -29
  271. package/utils/math/damp.cjs.map +0 -7
  272. package/utils/math/ease.cjs +0 -82
  273. package/utils/math/ease.cjs.map +0 -7
  274. package/utils/math/index.cjs +0 -54
  275. package/utils/math/index.cjs.map +0 -7
  276. package/utils/math/inertiaFinalValue.cjs +0 -47
  277. package/utils/math/inertiaFinalValue.cjs.map +0 -7
  278. package/utils/math/lerp.cjs +0 -29
  279. package/utils/math/lerp.cjs.map +0 -7
  280. package/utils/math/map.cjs +0 -29
  281. package/utils/math/map.cjs.map +0 -7
  282. package/utils/math/round.cjs +0 -29
  283. package/utils/math/round.cjs.map +0 -7
  284. package/utils/memoize.cjs +0 -48
  285. package/utils/memoize.cjs.map +0 -7
  286. package/utils/nextFrame.cjs +0 -41
  287. package/utils/nextFrame.cjs.map +0 -7
  288. package/utils/nextMicrotask.cjs +0 -30
  289. package/utils/nextMicrotask.cjs.map +0 -7
  290. package/utils/nextTick.cjs +0 -31
  291. package/utils/nextTick.cjs.map +0 -7
  292. package/utils/noop.cjs +0 -32
  293. package/utils/noop.cjs.map +0 -7
  294. package/utils/object/autoBind.cjs +0 -60
  295. package/utils/object/autoBind.cjs.map +0 -7
  296. package/utils/object/autoBind.d.ts +0 -14
  297. package/utils/object/autoBind.js +0 -28
  298. package/utils/object/autoBind.js.map +0 -7
  299. package/utils/object/getAllProperties.cjs +0 -39
  300. package/utils/object/getAllProperties.cjs.map +0 -7
  301. package/utils/object/index.cjs +0 -39
  302. package/utils/object/index.cjs.map +0 -7
  303. package/utils/object/index.d.ts +0 -2
  304. package/utils/object/index.js +0 -7
  305. package/utils/object/index.js.map +0 -7
  306. package/utils/scheduler.cjs +0 -75
  307. package/utils/scheduler.cjs.map +0 -7
  308. package/utils/scrollTo.cjs +0 -88
  309. package/utils/scrollTo.cjs.map +0 -7
  310. package/utils/string/endsWith.cjs +0 -35
  311. package/utils/string/endsWith.cjs.map +0 -7
  312. package/utils/string/index.cjs +0 -58
  313. package/utils/string/index.cjs.map +0 -7
  314. package/utils/string/startsWith.cjs +0 -35
  315. package/utils/string/startsWith.cjs.map +0 -7
  316. package/utils/string/withLeadingCharacters.cjs +0 -40
  317. package/utils/string/withLeadingCharacters.cjs.map +0 -7
  318. package/utils/string/withLeadingSlash.cjs +0 -40
  319. package/utils/string/withLeadingSlash.cjs.map +0 -7
  320. package/utils/string/withTrailingCharacters.cjs +0 -40
  321. package/utils/string/withTrailingCharacters.cjs.map +0 -7
  322. package/utils/string/withTrailingSlash.cjs +0 -40
  323. package/utils/string/withTrailingSlash.cjs.map +0 -7
  324. package/utils/string/withoutLeadingCharacters.cjs +0 -29
  325. package/utils/string/withoutLeadingCharacters.cjs.map +0 -7
  326. package/utils/string/withoutLeadingCharactersRecursive.cjs +0 -45
  327. package/utils/string/withoutLeadingCharactersRecursive.cjs.map +0 -7
  328. package/utils/string/withoutLeadingSlash.cjs +0 -40
  329. package/utils/string/withoutLeadingSlash.cjs.map +0 -7
  330. package/utils/string/withoutTrailingCharacters.cjs +0 -29
  331. package/utils/string/withoutTrailingCharacters.cjs.map +0 -7
  332. package/utils/string/withoutTrailingCharactersRecursive.cjs +0 -45
  333. package/utils/string/withoutTrailingCharactersRecursive.cjs.map +0 -7
  334. package/utils/string/withoutTrailingSlash.cjs +0 -40
  335. package/utils/string/withoutTrailingSlash.cjs.map +0 -7
  336. package/utils/throttle.cjs +0 -37
  337. package/utils/throttle.cjs.map +0 -7
  338. package/utils/tween.cjs +0 -122
  339. package/utils/tween.cjs.map +0 -7
  340. package/utils/wait.cjs +0 -31
  341. package/utils/wait.cjs.map +0 -7
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../packages/js-toolkit/decorators/withMountWhenInView.ts"],
4
- "sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\nexport interface WithMountWhenInViewProps extends BaseProps {\n $options: {\n intersectionObserver: IntersectionObserverInit;\n };\n}\n\nexport interface WithMountWhenInViewInterface extends BaseInterface {\n /**\n * @private\n */\n __isVisible: boolean;\n /**\n * @private\n */\n __observer: IntersectionObserver;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withMountWhenInView<S extends Base = Base>(\n BaseClass: typeof Base,\n // eslint-disable-next-line unicorn/no-object-as-default-parameter\n defaultOptions: IntersectionObserverInit = { threshold: [0, 1] },\n): BaseDecorator<WithMountWhenInViewInterface, S, WithMountWhenInViewProps> {\n /**\n * Class.\n */\n class WithMountWhenInView<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithMountWhenInViewProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}WithMountWhenInView`,\n options: {\n ...(BaseClass.config?.options || {}),\n intersectionObserver: Object,\n },\n };\n\n /**\n * Is the component visible?\n *\n * @private\n */\n __isVisible = false;\n\n /**\n * The component's observer.\n *\n * @private\n */\n __observer: IntersectionObserver;\n\n /**\n * Create an observer when the class in instantiated.\n *\n * @param {HTMLElement} element The component's root element.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.__observer = new IntersectionObserver(\n (entries) => {\n const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);\n if (this.__isVisible !== isVisible) {\n this.__isVisible = isVisible;\n\n if (isVisible) {\n this.$mount();\n } else {\n setTimeout(() => this.$destroy());\n }\n }\n },\n {\n ...defaultOptions,\n ...(this.$options as typeof this.$options & WithMountWhenInViewProps['$options'])\n .intersectionObserver,\n },\n );\n\n this.__observer.observe(this.$el);\n\n this.$on('terminated', () => {\n this.__observer.disconnect();\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n $mount() {\n if (this.__isVisible) {\n super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountWhenInView;\n}\n"],
5
- "mappings": "AAwBO,SAAS,oBACd,WAEA,iBAA2C,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,GACW;AAAA,EAI1E,MAAM,4BAA6D,UAEjE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP,GAAI,UAAU,QAAQ,WAAW,CAAC;AAAA,QAClC,sBAAsB;AAAA,MACxB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,aAAa,IAAI;AAAA,QACpB,CAAC,YAAY;AACX,gBAAM,YAAY,QAAQ,OAAO,CAAC,KAAK,UAAU,OAAO,MAAM,gBAAgB,KAAK;AACnF,cAAI,KAAK,gBAAgB,WAAW;AAClC,iBAAK,cAAc;AAEnB,gBAAI,WAAW;AACb,mBAAK,OAAO;AAAA,YACd,OAAO;AACL,yBAAW,MAAM,KAAK,SAAS,CAAC;AAAA,YAClC;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,UACE,GAAG;AAAA,UACH,GAAI,KAAK,SACN;AAAA,QACL;AAAA,MACF;AAEA,WAAK,WAAW,QAAQ,KAAK,GAAG;AAEhC,WAAK,IAAI,cAAc,MAAM;AAC3B,aAAK,WAAW,WAAW;AAAA,MAC7B,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA,IAKA,SAAS;AACP,UAAI,KAAK,aAAa;AACpB,cAAM,OAAO;AAAA,MACf;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
4
+ "sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\nexport interface WithMountWhenInViewProps extends BaseProps {\n $options: {\n intersectionObserver: IntersectionObserverInit;\n };\n}\n\nexport interface WithMountWhenInViewInterface extends BaseInterface {\n /**\n * @private\n */\n __isVisible: boolean;\n /**\n * @private\n */\n __observer: IntersectionObserver;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withMountWhenInView<S extends Base = Base>(\n BaseClass: typeof Base,\n // eslint-disable-next-line unicorn/no-object-as-default-parameter\n defaultOptions: IntersectionObserverInit = { threshold: [0, 1] },\n): BaseDecorator<WithMountWhenInViewInterface, S, WithMountWhenInViewProps> {\n /**\n * Class.\n */\n class WithMountWhenInView<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithMountWhenInViewProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}WithMountWhenInView`,\n options: {\n ...BaseClass.config?.options,\n intersectionObserver: Object,\n },\n };\n\n /**\n * Is the component visible?\n *\n * @private\n */\n __isVisible = false;\n\n /**\n * The component's observer.\n *\n * @private\n */\n __observer: IntersectionObserver;\n\n /**\n * Create an observer when the class in instantiated.\n *\n * @param {HTMLElement} element The component's root element.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.__observer = new IntersectionObserver(\n (entries) => {\n const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);\n if (this.__isVisible !== isVisible) {\n this.__isVisible = isVisible;\n\n if (isVisible) {\n this.$mount();\n } else {\n setTimeout(() => this.$destroy());\n }\n }\n },\n {\n ...defaultOptions,\n ...(this.$options as typeof this.$options & WithMountWhenInViewProps['$options'])\n .intersectionObserver,\n },\n );\n\n this.__observer.observe(this.$el);\n\n this.$on('terminated', () => {\n this.__observer.disconnect();\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n $mount() {\n if (this.__isVisible) {\n super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountWhenInView;\n}\n"],
5
+ "mappings": "AAwBO,SAAS,oBACd,WAEA,iBAA2C,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,GACW;AAAA,EAI1E,MAAM,4BAA6D,UAEjE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP,GAAG,UAAU,QAAQ;AAAA,QACrB,sBAAsB;AAAA,MACxB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,aAAa,IAAI;AAAA,QACpB,CAAC,YAAY;AACX,gBAAM,YAAY,QAAQ,OAAO,CAAC,KAAK,UAAU,OAAO,MAAM,gBAAgB,KAAK;AACnF,cAAI,KAAK,gBAAgB,WAAW;AAClC,iBAAK,cAAc;AAEnB,gBAAI,WAAW;AACb,mBAAK,OAAO;AAAA,YACd,OAAO;AACL,yBAAW,MAAM,KAAK,SAAS,CAAC;AAAA,YAClC;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,UACE,GAAG;AAAA,UACH,GAAI,KAAK,SACN;AAAA,QACL;AAAA,MACF;AAEA,WAAK,WAAW,QAAQ,KAAK,GAAG;AAEhC,WAAK,IAAI,cAAc,MAAM;AAC3B,aAAK,WAAW,WAAW;AAAA,MAC7B,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA,IAKA,SAAS;AACP,UAAI,KAAK,aAAa;AACpB,cAAM,OAAO;AAAA,MACf;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -11,7 +11,18 @@ export declare function parseNamedOffset(offset: string | number): string | numb
11
11
  * Get an edge value given a start, size and offset value.
12
12
  */
13
13
  export declare function getEdgeWithOffset(start: number, size: number, offset: string | number): number;
14
+ type HorizontalOnlyRect = {
15
+ x: number;
16
+ width: number;
17
+ };
18
+ type VerticalOnlyRect = {
19
+ y: number;
20
+ height: number;
21
+ };
22
+ type HorizontalRect = HorizontalOnlyRect & Partial<VerticalOnlyRect>;
23
+ type VerticalRect = Partial<HorizontalOnlyRect> & VerticalOnlyRect;
14
24
  /**
15
25
  * Get starting and ending edges for a given axis, a target sizings, a container sizings and their offset.
16
26
  */
17
- export declare function getEdges(axis: 'x' | 'y', targetSizes: any, containerSizes: any, offset: any): [number, number];
27
+ export declare function getEdges<T extends 'x' | 'y'>(axis: T, targetSizes: T extends 'x' ? HorizontalRect : VerticalRect, containerSizes: T extends 'x' ? HorizontalRect : VerticalRect, offset: NormalizedOffset): [number, number];
28
+ export {};
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../packages/js-toolkit/decorators/withScrolledInView/utils.ts"],
4
- "sourcesContent": ["import { isNumber, isString, endsWith } from '../../utils/index.js';\nimport type { NormalizedOffset } from './types.js';\n\nconst units = {\n px: 'px',\n vh: 'vh',\n vw: 'vw',\n vmin: 'vmin',\n vmax: 'vmax',\n percent: '%',\n};\n\nconst namedOffsets = {\n start: 0,\n center: 0.5,\n end: 1,\n};\n\n/**\n * Normalize offset input.\n */\nexport function normalizeOffset(offsets: string): NormalizedOffset {\n return offsets\n .split('/')\n .map((offset) => offset.trim().split(' ').slice(0, 2)) as NormalizedOffset;\n}\n\n/**\n * Parse the given offset.\n */\nexport function parseNamedOffset(offset: string | number): string | number {\n if (isNumber(offset)) {\n return offset;\n }\n\n if (isNumber(namedOffsets[offset])) {\n return namedOffsets[offset];\n }\n\n if (isNumber(Number(offset))) {\n return Number(offset);\n }\n\n if (isString(offset) && endsWith(offset, units.percent)) {\n return Number.parseFloat(offset) / 100;\n }\n\n return offset;\n}\n\n/**\n * Get an edge value given a start, size and offset value.\n */\nexport function getEdgeWithOffset(start: number, size: number, offset: string | number): number {\n if (isNumber(offset)) {\n return start + size * offset;\n }\n\n const parsedNamedOffset = parseNamedOffset(offset);\n if (isNumber(parsedNamedOffset)) {\n return start + size * parsedNamedOffset;\n }\n\n if (isString(parsedNamedOffset)) {\n const parsedOffset = Number.parseFloat(parsedNamedOffset);\n\n if (endsWith(parsedNamedOffset, units.px)) {\n return start + parsedOffset;\n }\n\n if (endsWith(parsedNamedOffset, units.vh)) {\n return start + (parsedOffset * window.innerHeight) / 100;\n }\n\n if (endsWith(parsedNamedOffset, units.vw)) {\n return start + (parsedOffset * window.innerWidth) / 100;\n }\n\n if (endsWith(parsedNamedOffset, units.vmin)) {\n return start + (parsedOffset * Math.min(window.innerWidth, window.innerHeight)) / 100;\n }\n\n if (endsWith(parsedNamedOffset, units.vmax)) {\n return start + (parsedOffset * Math.max(window.innerWidth, window.innerHeight)) / 100;\n }\n }\n\n return start;\n}\n\n/**\n * Get starting and ending edges for a given axis, a target sizings, a container sizings and their offset.\n */\nexport function getEdges(axis: 'x' | 'y', targetSizes, containerSizes, offset): [number, number] {\n const sizeKey = axis === 'x' ? 'width' : 'height';\n const targetStart = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[0][0]);\n const containerStart = getEdgeWithOffset(0, containerSizes[sizeKey], offset[0][1]);\n const targetEnd = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[1][0]);\n const containerEnd = getEdgeWithOffset(0, containerSizes[sizeKey], offset[1][1]);\n const start = targetStart - containerStart;\n const end = targetEnd - containerEnd;\n\n return [start, end];\n}\n"],
5
- "mappings": "AAAA,SAAS,UAAU,UAAU,gBAAgB;AAG7C,MAAM,QAAQ;AAAA,EACZ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AACX;AAEA,MAAM,eAAe;AAAA,EACnB,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AACP;AAKO,SAAS,gBAAgB,SAAmC;AACjE,SAAO,QACJ,MAAM,GAAG,EACT,IAAI,CAAC,WAAW,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;AACzD;AAKO,SAAS,iBAAiB,QAA0C;AACzE,MAAI,SAAS,MAAM,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,aAAa,MAAM,CAAC,GAAG;AAClC,WAAO,aAAa,MAAM;AAAA,EAC5B;AAEA,MAAI,SAAS,OAAO,MAAM,CAAC,GAAG;AAC5B,WAAO,OAAO,MAAM;AAAA,EACtB;AAEA,MAAI,SAAS,MAAM,KAAK,SAAS,QAAQ,MAAM,OAAO,GAAG;AACvD,WAAO,OAAO,WAAW,MAAM,IAAI;AAAA,EACrC;AAEA,SAAO;AACT;AAKO,SAAS,kBAAkB,OAAe,MAAc,QAAiC;AAC9F,MAAI,SAAS,MAAM,GAAG;AACpB,WAAO,QAAQ,OAAO;AAAA,EACxB;AAEA,QAAM,oBAAoB,iBAAiB,MAAM;AACjD,MAAI,SAAS,iBAAiB,GAAG;AAC/B,WAAO,QAAQ,OAAO;AAAA,EACxB;AAEA,MAAI,SAAS,iBAAiB,GAAG;AAC/B,UAAM,eAAe,OAAO,WAAW,iBAAiB;AAExD,QAAI,SAAS,mBAAmB,MAAM,EAAE,GAAG;AACzC,aAAO,QAAQ;AAAA,IACjB;AAEA,QAAI,SAAS,mBAAmB,MAAM,EAAE,GAAG;AACzC,aAAO,QAAS,eAAe,OAAO,cAAe;AAAA,IACvD;AAEA,QAAI,SAAS,mBAAmB,MAAM,EAAE,GAAG;AACzC,aAAO,QAAS,eAAe,OAAO,aAAc;AAAA,IACtD;AAEA,QAAI,SAAS,mBAAmB,MAAM,IAAI,GAAG;AAC3C,aAAO,QAAS,eAAe,KAAK,IAAI,OAAO,YAAY,OAAO,WAAW,IAAK;AAAA,IACpF;AAEA,QAAI,SAAS,mBAAmB,MAAM,IAAI,GAAG;AAC3C,aAAO,QAAS,eAAe,KAAK,IAAI,OAAO,YAAY,OAAO,WAAW,IAAK;AAAA,IACpF;AAAA,EACF;AAEA,SAAO;AACT;AAKO,SAAS,SAAS,MAAiB,aAAa,gBAAgB,QAA0B;AAC/F,QAAM,UAAU,SAAS,MAAM,UAAU;AACzC,QAAM,cAAc,kBAAkB,YAAY,IAAI,GAAG,YAAY,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AAC3F,QAAM,iBAAiB,kBAAkB,GAAG,eAAe,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AACjF,QAAM,YAAY,kBAAkB,YAAY,IAAI,GAAG,YAAY,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AACzF,QAAM,eAAe,kBAAkB,GAAG,eAAe,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AAC/E,QAAM,QAAQ,cAAc;AAC5B,QAAM,MAAM,YAAY;AAExB,SAAO,CAAC,OAAO,GAAG;AACpB;",
4
+ "sourcesContent": ["import { isNumber, isString, endsWith } from '../../utils/index.js';\nimport type { NormalizedOffset } from './types.js';\n\nconst units = {\n px: 'px',\n vh: 'vh',\n vw: 'vw',\n vmin: 'vmin',\n vmax: 'vmax',\n percent: '%',\n};\n\nconst namedOffsets = {\n start: 0,\n center: 0.5,\n end: 1,\n};\n\n/**\n * Normalize offset input.\n */\nexport function normalizeOffset(offsets: string): NormalizedOffset {\n return offsets\n .split('/')\n .map((offset) => offset.trim().split(' ').slice(0, 2)) as NormalizedOffset;\n}\n\n/**\n * Parse the given offset.\n */\nexport function parseNamedOffset(offset: string | number): string | number {\n if (isNumber(offset)) {\n return offset;\n }\n\n if (isNumber(namedOffsets[offset])) {\n return namedOffsets[offset];\n }\n\n if (isNumber(Number(offset))) {\n return Number(offset);\n }\n\n if (isString(offset) && endsWith(offset, units.percent)) {\n return Number.parseFloat(offset) / 100;\n }\n\n return offset;\n}\n\n/**\n * Get an edge value given a start, size and offset value.\n */\nexport function getEdgeWithOffset(start: number, size: number, offset: string | number): number {\n if (isNumber(offset)) {\n return start + size * offset;\n }\n\n const parsedNamedOffset = parseNamedOffset(offset);\n if (isNumber(parsedNamedOffset)) {\n return start + size * parsedNamedOffset;\n }\n\n if (isString(parsedNamedOffset)) {\n const parsedOffset = Number.parseFloat(parsedNamedOffset);\n\n if (endsWith(parsedNamedOffset, units.px)) {\n return start + parsedOffset;\n }\n\n if (endsWith(parsedNamedOffset, units.vh)) {\n return start + (parsedOffset * window.innerHeight) / 100;\n }\n\n if (endsWith(parsedNamedOffset, units.vw)) {\n return start + (parsedOffset * window.innerWidth) / 100;\n }\n\n if (endsWith(parsedNamedOffset, units.vmin)) {\n return start + (parsedOffset * Math.min(window.innerWidth, window.innerHeight)) / 100;\n }\n\n if (endsWith(parsedNamedOffset, units.vmax)) {\n return start + (parsedOffset * Math.max(window.innerWidth, window.innerHeight)) / 100;\n }\n }\n\n return start;\n}\n\ntype HorizontalOnlyRect = {\n x: number;\n width: number;\n};\n\ntype VerticalOnlyRect = {\n y: number;\n height: number;\n};\n\ntype HorizontalRect = HorizontalOnlyRect & Partial<VerticalOnlyRect>;\ntype VerticalRect = Partial<HorizontalOnlyRect> & VerticalOnlyRect;\n\n/**\n * Get starting and ending edges for a given axis, a target sizings, a container sizings and their offset.\n */\nexport function getEdges<T extends 'x' | 'y'>(\n axis: T,\n targetSizes: T extends 'x' ? HorizontalRect : VerticalRect,\n containerSizes: T extends 'x' ? HorizontalRect : VerticalRect,\n offset: NormalizedOffset,\n): [number, number] {\n const sizeKey = axis === 'x' ? 'width' : 'height';\n const targetStart = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[0][0]);\n const containerStart = getEdgeWithOffset(0, containerSizes[sizeKey], offset[0][1]);\n const targetEnd = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[1][0]);\n const containerEnd = getEdgeWithOffset(0, containerSizes[sizeKey], offset[1][1]);\n const start = targetStart - containerStart;\n const end = targetEnd - containerEnd;\n\n return [start, end];\n}\n"],
5
+ "mappings": "AAAA,SAAS,UAAU,UAAU,gBAAgB;AAG7C,MAAM,QAAQ;AAAA,EACZ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AACX;AAEA,MAAM,eAAe;AAAA,EACnB,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AACP;AAKO,SAAS,gBAAgB,SAAmC;AACjE,SAAO,QACJ,MAAM,GAAG,EACT,IAAI,CAAC,WAAW,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;AACzD;AAKO,SAAS,iBAAiB,QAA0C;AACzE,MAAI,SAAS,MAAM,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,aAAa,MAAM,CAAC,GAAG;AAClC,WAAO,aAAa,MAAM;AAAA,EAC5B;AAEA,MAAI,SAAS,OAAO,MAAM,CAAC,GAAG;AAC5B,WAAO,OAAO,MAAM;AAAA,EACtB;AAEA,MAAI,SAAS,MAAM,KAAK,SAAS,QAAQ,MAAM,OAAO,GAAG;AACvD,WAAO,OAAO,WAAW,MAAM,IAAI;AAAA,EACrC;AAEA,SAAO;AACT;AAKO,SAAS,kBAAkB,OAAe,M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M,QAAQ,cAAc;AAC5B,QAAM,MAAM,YAAY;AAExB,SAAO,CAAC,OAAO,GAAG;AACpB;",
6
6
  "names": []
7
7
  }
@@ -16,7 +16,7 @@ function updateProgress(props, axis, progressKey, currentKey) {
16
16
  }
17
17
  function updateProps(props, dampFactor, dampPrecision, axis = "x") {
18
18
  props.current[axis] = clamp(
19
- axis === "x" ? window.pageXOffset : window.pageYOffset,
19
+ axis === "x" ? window.scrollX : window.scrollY,
20
20
  props.start[axis],
21
21
  props.end[axis]
22
22
  );
@@ -86,8 +86,8 @@ function withScrolledInView(BaseClass, options = {}) {
86
86
  if (this.shouldEvaluateProps) {
87
87
  this.shouldEvaluateProps = false;
88
88
  const targetSizes = options.useOffsetSizes ? getOffsetSizes(this.$el) : this.$el.getBoundingClientRect();
89
- targetSizes.y += window.pageYOffset;
90
- targetSizes.x += window.pageXOffset;
89
+ targetSizes.y += window.scrollY;
90
+ targetSizes.x += window.scrollX;
91
91
  const containerSizes = {
92
92
  x: 0,
93
93
  y: 0,
@@ -96,10 +96,10 @@ function withScrolledInView(BaseClass, options = {}) {
96
96
  };
97
97
  const offset = normalizeOffset(this.$options.offset);
98
98
  const [yStart, yEnd] = getEdges("y", targetSizes, containerSizes, offset);
99
- const yCurrent = clamp(window.pageYOffset, yStart, yEnd);
99
+ const yCurrent = clamp(window.scrollY, yStart, yEnd);
100
100
  const yProgress = yStart === yEnd ? 0 : clamp01((yCurrent - yStart) / (yEnd - yStart));
101
101
  const [xStart, xEnd] = getEdges("x", targetSizes, containerSizes, offset);
102
- const xCurrent = clamp(window.pageXOffset, xStart, xEnd);
102
+ const xCurrent = clamp(window.scrollX, xStart, xEnd);
103
103
  const xProgress = xStart === xEnd ? 0 : clamp01((xCurrent - xStart) / (xEnd - xStart));
104
104
  this.__props.start.x = xStart;
105
105
  this.__props.start.y = yStart;
@@ -116,20 +116,6 @@ function withScrolledInView(BaseClass, options = {}) {
116
116
  }
117
117
  return this.__props;
118
118
  }
119
- /**
120
- * Factor used for the `dampedProgress` props.
121
- *
122
- * @deprecated
123
- * @todo v3 delete in favor of option API
124
- */
125
- dampFactor = null;
126
- /**
127
- * Precision for the `dampedProgress` props.
128
- *
129
- * @deprecated
130
- * @todo v3 delete in favor of option API
131
- */
132
- dampPrecision = null;
133
119
  /**
134
120
  * Bind listeners.
135
121
  */
@@ -154,13 +140,12 @@ function withScrolledInView(BaseClass, options = {}) {
154
140
  render();
155
141
  },
156
142
  scrolled: (props) => {
157
- if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
143
+ if (props.changed.y || props.changed.x) {
158
144
  this.$services.enable("ticked");
159
145
  }
160
146
  },
161
147
  ticked: () => {
162
- const dampFactor = this.dampFactor ?? this.$options.dampFactor;
163
- const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;
148
+ const { dampFactor, dampPrecision } = this.$options;
164
149
  updateProps(this.__props, dampFactor, dampPrecision, "x");
165
150
  updateProps(this.__props, dampFactor, dampPrecision, "y");
166
151
  if (this.__props.dampedCurrent.x === this.__props.current.x && this.__props.dampedCurrent.y === this.__props.current.y) {
@@ -185,46 +170,6 @@ function withScrolledInView(BaseClass, options = {}) {
185
170
  render();
186
171
  });
187
172
  }
188
- /**
189
- * Mounted hook.
190
- */
191
- mounted() {
192
- if (isFunction(super.mounted)) {
193
- super.mounted();
194
- }
195
- }
196
- /**
197
- * Resized hook.
198
- */
199
- resized(props) {
200
- if (isFunction(super.resized)) {
201
- super.resized(props);
202
- }
203
- }
204
- /**
205
- * Scrolled hook.
206
- */
207
- scrolled(props) {
208
- if (isFunction(super.scrolled)) {
209
- super.scrolled(props);
210
- }
211
- }
212
- /**
213
- * Ticked hook.
214
- */
215
- ticked(props) {
216
- if (isFunction(super.ticked)) {
217
- super.ticked(props);
218
- }
219
- }
220
- /**
221
- * Destroyed hook.
222
- */
223
- destroyed() {
224
- if (isFunction(super.destroyed)) {
225
- super.destroyed();
226
- }
227
- }
228
173
  }
229
174
  return WithScrolledInView;
230
175
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../packages/js-toolkit/decorators/withScrolledInView/withScrolledInView.ts"],
4
- "sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../../Base/index.js';\nimport type {\n RafServiceProps,\n ScrollServiceProps,\n ResizeServiceProps,\n} from '../../services/index.js';\nimport { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n useScheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nconst scheduler = useScheduler(['update', 'render']);\n\nexport interface WithScrolledInViewProps extends BaseProps {\n $options: {\n dampFactor: number;\n dampPrecision: number;\n offset: string;\n };\n}\n\nexport type ScrollInViewProps = {\n start: {\n x: number;\n y: number;\n };\n end: {\n x: number;\n y: number;\n };\n current: {\n x: number;\n y: number;\n };\n dampedCurrent: {\n x: number;\n y: number;\n };\n progress: {\n x: number;\n y: number;\n };\n dampedProgress: {\n x: number;\n y: number;\n };\n};\n\nexport type WithScrolledInViewOptions = IntersectionObserverInit & {\n useOffsetSizes?: boolean;\n};\n\nfunction updateProgress(\n props: ScrollInViewProps,\n axis: 'x' | 'y',\n progressKey: 'progress' | 'dampedProgress',\n currentKey: 'current' | 'dampedCurrent',\n) {\n props[progressKey][axis] =\n props.start[axis] === props.end[axis]\n ? 0\n : clamp01(\n (props[currentKey][axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n}\n\n/**\n * Update props on tick.\n */\nfunction updateProps(\n props: ScrollInViewProps,\n dampFactor: number,\n dampPrecision: number,\n axis: 'x' | 'y' = 'x',\n): void {\n props.current[axis] = clamp(\n axis === 'x' ? window.pageXOffset : window.pageYOffset,\n props.start[axis],\n props.end[axis],\n );\n props.dampedCurrent[axis] = damp(\n props.current[axis],\n props.dampedCurrent[axis],\n dampFactor,\n dampPrecision,\n );\n updateProgress(props, axis, 'progress', 'current');\n updateProgress(props, axis, 'dampedProgress', 'dampedCurrent');\n}\n\nexport interface WithScrolledInViewInterface extends BaseInterface {\n /**\n * @type {ScrollInViewProps}\n */\n readonly props: ScrollInViewProps;\n dampFactor?: number;\n dampPrecision?: number;\n mounted(): void;\n resized(props: ResizeServiceProps): void;\n scrolled(props: ScrollServiceProps): void;\n ticked(props: RafServiceProps): void;\n destroyed(): void;\n}\n\n/**\n * Add scrolled in view capabilities to a component.\n */\nexport function withScrolledInView<S extends Base = Base>(\n BaseClass: typeof Base,\n options: WithScrolledInViewOptions = {},\n): BaseDecorator<WithScrolledInViewInterface, S, WithScrolledInViewProps> {\n /**\n * Class.\n */\n class WithScrolledInView<T extends BaseProps = BaseProps> extends withMountWhenInView(\n BaseClass,\n options,\n )<T & WithScrolledInViewProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: `${BaseClass.config.name}WithMountWhenInView`,\n emits: ['scrolledInView'],\n options: {\n dampFactor: {\n type: Number,\n default: 0.1,\n },\n dampPrecision: {\n type: Number,\n default: 0.001,\n },\n offset: {\n type: String,\n default: 'start end / end start',\n },\n },\n };\n\n __props: ScrollInViewProps = {\n start: {\n x: 0,\n y: 0,\n },\n end: {\n x: 0,\n y: 0,\n },\n current: {\n x: 0,\n y: 0,\n },\n dampedCurrent: {\n x: 0,\n y: 0,\n },\n progress: {\n x: 0,\n y: 0,\n },\n dampedProgress: {\n x: 0,\n y: 0,\n },\n };\n\n shouldEvaluateProps = true;\n\n get props() {\n if (this.shouldEvaluateProps) {\n this.shouldEvaluateProps = false;\n const targetSizes = options.useOffsetSizes\n ? getOffsetSizes(this.$el)\n : this.$el.getBoundingClientRect();\n\n targetSizes.y += window.pageYOffset;\n targetSizes.x += window.pageXOffset;\n\n const containerSizes = {\n x: 0,\n y: 0,\n height: window.innerHeight,\n width: window.innerWidth,\n };\n\n const offset = normalizeOffset(this.$options.offset);\n\n // Y axis\n const [yStart, yEnd] = getEdges('y', targetSizes, containerSizes, offset);\n const yCurrent = clamp(window.pageYOffset, yStart, yEnd);\n const yProgress = yStart === yEnd ? 0 : clamp01((yCurrent - yStart) / (yEnd - yStart));\n // X axis\n const [xStart, xEnd] = getEdges('x', targetSizes, containerSizes, offset);\n const xCurrent = clamp(window.pageXOffset, xStart, xEnd);\n const xProgress = xStart === xEnd ? 0 : clamp01((xCurrent - xStart) / (xEnd - xStart));\n\n this.__props.start.x = xStart;\n this.__props.start.y = yStart;\n this.__props.end.x = xEnd;\n this.__props.end.y = yEnd;\n this.__props.current.x = xCurrent;\n this.__props.current.y = yCurrent;\n this.__props.dampedCurrent.x = xCurrent;\n this.__props.dampedCurrent.y = yCurrent;\n this.__props.progress.x = xProgress;\n this.__props.progress.y = yProgress;\n this.__props.dampedProgress.x = xProgress;\n this.__props.dampedProgress.y = yProgress;\n }\n\n return this.__props;\n }\n\n /**\n * Factor used for the `dampedProgress` props.\n *\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampFactor?: number = null;\n\n /**\n * Precision for the `dampedProgress` props.\n *\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampPrecision?: number = null;\n\n /**\n * Bind listeners.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const render = () => {\n scheduler.update(() => {\n // @ts-ignore\n const renderFn = this.__callMethod('scrolledInView', this.props);\n if (isFunction(renderFn)) {\n scheduler.render(() => {\n renderFn(this.__props);\n });\n }\n });\n };\n\n const delegate = {\n handleEvent(event) {\n delegate[event.type](event.detail[0]);\n },\n resized: () => {\n this.shouldEvaluateProps = true;\n render();\n },\n scrolled: (props) => {\n if ((!this.$services.has('ticked') && props.changed.y) || props.changed.x) {\n this.$services.enable('ticked');\n }\n },\n ticked: () => {\n const dampFactor = this.dampFactor ?? this.$options.dampFactor;\n const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;\n updateProps(this.__props, dampFactor, dampPrecision, 'x');\n updateProps(this.__props, dampFactor, dampPrecision, 'y');\n\n if (\n this.__props.dampedCurrent.x === this.__props.current.x &&\n this.__props.dampedCurrent.y === this.__props.current.y\n ) {\n this.$services.disable('ticked');\n }\n\n render();\n },\n };\n\n this.$on('before-mounted', () => {\n this.$on('resized', delegate);\n this.$on('scrolled', delegate);\n this.$on('ticked', delegate);\n });\n\n this.$on('destroyed', () => {\n this.$off('resized', delegate);\n this.$off('scrolled', delegate);\n this.$off('ticked', delegate);\n\n // Clamp damped values to their final value and trigger one last render on destroy\n this.__props.dampedCurrent.x = this.__props.current.x;\n this.__props.dampedCurrent.y = this.__props.current.y;\n this.__props.dampedProgress.x = this.__props.progress.x;\n this.__props.dampedProgress.y = this.__props.progress.y;\n render();\n });\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n // @ts-ignore\n if (isFunction(super.mounted)) {\n // @ts-ignore\n super.mounted();\n }\n }\n\n /**\n * Resized hook.\n */\n resized(props: ResizeServiceProps) {\n // @ts-ignore\n if (isFunction(super.resized)) {\n // @ts-ignore\n super.resized(props);\n }\n }\n\n /**\n * Scrolled hook.\n */\n scrolled(props: ScrollServiceProps) {\n // @ts-ignore\n if (isFunction(super.scrolled)) {\n // @ts-ignore\n super.scrolled(props);\n }\n }\n\n /**\n * Ticked hook.\n */\n ticked(props: RafServiceProps) {\n // @ts-ignore\n if (isFunction(super.ticked)) {\n // @ts-ignore\n super.ticked(props);\n }\n }\n\n /**\n * Destroyed hook.\n */\n destroyed() {\n // @ts-ignore\n if (isFunction(super.destroyed)) {\n // @ts-ignore\n super.destroyed();\n }\n }\n }\n\n // @ts-ignore\n return WithScrolledInView;\n}\n"],
5
- "mappings": "AAOA,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB,gBAAgB;AAE1C,MAAM,YAAY,aAAa,CAAC,UAAU,QAAQ,CAAC;AAyCnD,SAAS,eACP,OACA,MACA,aACA,YACA;AACA,QAAM,WAAW,EAAE,IAAI,IACrB,MAA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AAO;AACT;",
4
+ "sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../../Base/index.js';\nimport type {\n RafServiceProps,\n ScrollServiceProps,\n ResizeServiceProps,\n} from '../../services/index.js';\nimport { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n useScheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nconst scheduler = useScheduler(['update', 'render']);\n\nexport interface WithScrolledInViewProps extends BaseProps {\n $options: {\n dampFactor: number;\n dampPrecision: number;\n offset: string;\n };\n}\n\nexport type ScrollInViewProps = {\n start: {\n x: number;\n y: number;\n };\n end: {\n x: number;\n y: number;\n };\n current: {\n x: number;\n y: number;\n };\n dampedCurrent: {\n x: number;\n y: number;\n };\n progress: {\n x: number;\n y: number;\n };\n dampedProgress: {\n x: number;\n y: number;\n };\n};\n\nexport type WithScrolledInViewOptions = IntersectionObserverInit & {\n useOffsetSizes?: boolean;\n};\n\nfunction updateProgress(\n props: ScrollInViewProps,\n axis: 'x' | 'y',\n progressKey: 'progress' | 'dampedProgress',\n currentKey: 'current' | 'dampedCurrent',\n) {\n props[progressKey][axis] =\n props.start[axis] === props.end[axis]\n ? 0\n : clamp01(\n (props[currentKey][axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n}\n\n/**\n * Update props on tick.\n */\nfunction updateProps(\n props: ScrollInViewProps,\n dampFactor: number,\n dampPrecision: number,\n axis: 'x' | 'y' = 'x',\n): void {\n props.current[axis] = clamp(\n axis === 'x' ? window.scrollX : window.scrollY,\n props.start[axis],\n props.end[axis],\n );\n props.dampedCurrent[axis] = damp(\n props.current[axis],\n props.dampedCurrent[axis],\n dampFactor,\n dampPrecision,\n );\n updateProgress(props, axis, 'progress', 'current');\n updateProgress(props, axis, 'dampedProgress', 'dampedCurrent');\n}\n\nexport interface WithScrolledInViewInterface extends BaseInterface {\n /**\n * @type {ScrollInViewProps}\n */\n readonly props: ScrollInViewProps;\n dampFactor?: number;\n dampPrecision?: number;\n mounted(): void;\n resized(props: ResizeServiceProps): void;\n scrolled(props: ScrollServiceProps): void;\n ticked(props: RafServiceProps): void;\n destroyed(): void;\n}\n\n/**\n * Add scrolled in view capabilities to a component.\n */\nexport function withScrolledInView<S extends Base = Base>(\n BaseClass: typeof Base,\n options: WithScrolledInViewOptions = {},\n): BaseDecorator<WithScrolledInViewInterface, S, WithScrolledInViewProps> {\n /**\n * Class.\n */\n class WithScrolledInView<T extends BaseProps = BaseProps> extends withMountWhenInView(\n BaseClass,\n options,\n )<T & WithScrolledInViewProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: `${BaseClass.config.name}WithMountWhenInView`,\n emits: ['scrolledInView'],\n options: {\n dampFactor: {\n type: Number,\n default: 0.1,\n },\n dampPrecision: {\n type: Number,\n default: 0.001,\n },\n offset: {\n type: String,\n default: 'start end / end start',\n },\n },\n };\n\n __props: ScrollInViewProps = {\n start: {\n x: 0,\n y: 0,\n },\n end: {\n x: 0,\n y: 0,\n },\n current: {\n x: 0,\n y: 0,\n },\n dampedCurrent: {\n x: 0,\n y: 0,\n },\n progress: {\n x: 0,\n y: 0,\n },\n dampedProgress: {\n x: 0,\n y: 0,\n },\n };\n\n shouldEvaluateProps = true;\n\n get props() {\n if (this.shouldEvaluateProps) {\n this.shouldEvaluateProps = false;\n const targetSizes = options.useOffsetSizes\n ? getOffsetSizes(this.$el)\n : this.$el.getBoundingClientRect();\n\n targetSizes.y += window.scrollY;\n targetSizes.x += window.scrollX;\n\n const containerSizes = {\n x: 0,\n y: 0,\n height: window.innerHeight,\n width: window.innerWidth,\n };\n\n const offset = normalizeOffset(this.$options.offset);\n\n // Y axis\n const [yStart, yEnd] = getEdges('y', targetSizes, containerSizes, offset);\n const yCurrent = clamp(window.scrollY, yStart, yEnd);\n const yProgress = yStart === yEnd ? 0 : clamp01((yCurrent - yStart) / (yEnd - yStart));\n // X axis\n const [xStart, xEnd] = getEdges('x', targetSizes, containerSizes, offset);\n const xCurrent = clamp(window.scrollX, xStart, xEnd);\n const xProgress = xStart === xEnd ? 0 : clamp01((xCurrent - xStart) / (xEnd - xStart));\n\n this.__props.start.x = xStart;\n this.__props.start.y = yStart;\n this.__props.end.x = xEnd;\n this.__props.end.y = yEnd;\n this.__props.current.x = xCurrent;\n this.__props.current.y = yCurrent;\n this.__props.dampedCurrent.x = xCurrent;\n this.__props.dampedCurrent.y = yCurrent;\n this.__props.progress.x = xProgress;\n this.__props.progress.y = yProgress;\n this.__props.dampedProgress.x = xProgress;\n this.__props.dampedProgress.y = yProgress;\n }\n\n return this.__props;\n }\n\n /**\n * Bind listeners.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const render = () => {\n scheduler.update(() => {\n // @ts-ignore\n const renderFn = this.__callMethod('scrolledInView', this.props);\n if (isFunction(renderFn)) {\n scheduler.render(() => {\n renderFn(this.__props);\n });\n }\n });\n };\n\n const delegate = {\n handleEvent(event) {\n delegate[event.type](event.detail[0]);\n },\n resized: () => {\n this.shouldEvaluateProps = true;\n render();\n },\n scrolled: (props) => {\n if (props.changed.y || props.changed.x) {\n this.$services.enable('ticked');\n }\n },\n ticked: () => {\n const { dampFactor, dampPrecision } = this.$options;\n updateProps(this.__props, dampFactor, dampPrecision, 'x');\n updateProps(this.__props, dampFactor, dampPrecision, 'y');\n\n if (\n this.__props.dampedCurrent.x === this.__props.current.x &&\n this.__props.dampedCurrent.y === this.__props.current.y\n ) {\n this.$services.disable('ticked');\n }\n\n render();\n },\n };\n\n this.$on('before-mounted', () => {\n this.$on('resized', delegate);\n this.$on('scrolled', delegate);\n this.$on('ticked', delegate);\n });\n\n this.$on('destroyed', () => {\n this.$off('resized', delegate);\n this.$off('scrolled', delegate);\n this.$off('ticked', delegate);\n\n // Clamp damped values to their final value and trigger one last render on destroy\n this.__props.dampedCurrent.x = this.__props.current.x;\n this.__props.dampedCurrent.y = this.__props.current.y;\n this.__props.dampedProgress.x = this.__props.progress.x;\n this.__props.dampedProgress.y = this.__props.progress.y;\n render();\n });\n }\n }\n\n // @ts-ignore\n return WithScrolledInView;\n}\n"],
5
+ "mappings": "AAOA,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB,gBAAgB;AAE1C,MAAM,YAAY,aAAa,CAAC,UAAU,QAAQ,CAAC;AAyCnD,SAAS,eACP,OACA,MACA,aACA,YACA;AACA,QAAM,WAAW,EAAE,IAAI,IACrB,MAAM,MAAM,IAAI,MAAM,MAAM,IAAI,IAAI,IAChC,IACA;AAAA,KACG,MAAM,UAAU,EAAE,IAAI,IAAI,MAAM,MAAM,IAAI,MAAM,MAAM,IAAI,IAAI,IAAI,MAAM,MAAM,IAAI;AAAA,EACrF;AACR;AAKA,SAAS,YACP,OACA,YACA,eACA,OAAkB,KACZ;AACN,QAAM,QAAQ,IAAI,IAAI;AAAA,IACpB,SAAS,MAAM,OAAO,UAAU,OAAO;AAAA,IACvC,MAAM,MAAM,IAAI;AAAA,IAChB,MAAM,IAAI,IAAI;AAAA,EAChB;AACA,QAAM,cAAc,IAAI,IAAI;AAAA,IAC1B,MAAM,QAAQ,IAAI;AAAA,IAClB,MAAM,cAAc,IAAI;AAAA,IACxB;AAAA,IACA;AAAA,EACF;AACA,iBAAe,OAAO,MAAM,YAAY,SAAS;AACjD,iBAAe,OAAO,MAAM,kBAAkB,eAAe;AAC/D;AAmBO,SAAS,mBACd,WACA,UAAqC,CAAC,GACkC;AAAA,EAIxE,MAAM,2BAA4D;AAAA,IAChE;AAAA,IACA;AAAA,EACF,EAA+B;AAAA;AAAA;AAAA;AAAA,IAI7B,OAAO,SAAqB;AAAA,MAC1B,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,OAAO,CAAC,gBAAgB;AAAA,MACxB,SAAS;AAAA,QACP,YAAY;AAAA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K,SAAS,YAAY,eAAe,GAAG;AACxD,sBAAY,KAAK,SAAS,YAAY,eAAe,GAAG;AAExD,cACE,KAAK,QAAQ,cAAc,MAAM,KAAK,QAAQ,QAAQ,KACtD,KAAK,QAAQ,cAAc,MAAM,KAAK,QAAQ,QAAQ,GACtD;AACA,iBAAK,UAAU,QAAQ,QAAQ;AAAA,UACjC;AAEA,iBAAO;AAAA,QACT;AAAA,MACF;AAEA,WAAK,IAAI,kBAAkB,MAAM;AAC/B,aAAK,IAAI,WAAW,QAAQ;AAC5B,aAAK,IAAI,YAAY,QAAQ;AAC7B,aAAK,IAAI,UAAU,QAAQ;AAAA,MAC7B,CAAC;AAED,WAAK,IAAI,aAAa,MAAM;AAC1B,aAAK,KAAK,WAAW,QAAQ;AAC7B,aAAK,KAAK,YAAY,QAAQ;AAC9B,aAAK,KAAK,UAAU,QAAQ;AAG5B,aAAK,QAAQ,cAAc,IAAI,KAAK,QAAQ,QAAQ;AACpD,aAAK,QAAQ,cAAc,IAAI,KAAK,QAAQ,QAAQ;AACpD,aAAK,QAAQ,eAAe,IAAI,KAAK,QAAQ,SAAS;AACtD,aAAK,QAAQ,eAAe,IAAI,KAAK,QAAQ,SAAS;AACtD,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,EACF;AAGA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -2,7 +2,8 @@ import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';
2
2
  import type { Features } from '../Base/features.js';
3
3
  export type CreateAppOptions = {
4
4
  root: HTMLElement;
5
- features: Features;
5
+ features: Partial<Features>;
6
+ breakpoints?: Record<string, string>;
6
7
  };
7
8
  /**
8
9
  * Instantiate and mount the given component on the given root element when the page has been loaded
@@ -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 { isDefined } from '../utils/index.js';\n\nexport type CreateAppOptions = {\n root: HTMLElement;\n features: Partial<Features>;\n breakpoints?: Record<string, string>;\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;AAYX,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;",
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.0",
3
+ "version": "3.0.0-alpha.1",
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.17.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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,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": "AACA,SAAS,kBAAkB;AAE3B,SAAS,iBAAiB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EACf;AACF;AAEA,MAAM,YAAY,oBAAI,IAA0C;AAKjD,SAAR,WAA4B,QAAsC;AACvE,MAAI,CAAC,UAAU,IAAI,UAAU,MAAM,GAAG;AACpC,cAAU,IAAI,UAAU,QAAQ,qBAAqB,MAAM,CAAC;AAAA,EAC9D;AACA,SAAO,UAAU,IAAI,UAAU,MAAM;AACvC;",
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,8 @@
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) {
5
+ const finalScreens = breakpoints ?? features.get("breakpoints");
22
6
  function updateProps() {
23
7
  props.width = window.innerWidth;
24
8
  props.height = window.innerHeight;
@@ -42,10 +26,18 @@ function createResizeService() {
42
26
  ratio: window.innerWidth / window.innerHeight,
43
27
  orientation: "square",
44
28
  get breakpoint() {
45
- return getBreakpoint();
29
+ return Object.keys(this.activeBreakpoints).find((name) => this.activeBreakpoints[name]);
46
30
  },
47
31
  get breakpoints() {
48
- return getBreakpoints();
32
+ return Object.keys(this.activeBreakpoints);
33
+ },
34
+ get activeBreakpoints() {
35
+ return Object.fromEntries(
36
+ Object.entries(finalScreens).map(([name, breakpoint]) => [
37
+ name,
38
+ window.matchMedia(`(min-width: ${breakpoint})`).matches
39
+ ])
40
+ );
49
41
  }
50
42
  },
51
43
  init() {
@@ -62,12 +54,13 @@ function createResizeService() {
62
54
  props: () => props
63
55
  };
64
56
  }
65
- let resize;
66
- function useResize() {
67
- if (!resize) {
68
- resize = createResizeService();
57
+ const instances = /* @__PURE__ */ new Map();
58
+ function useResize(breakpoints) {
59
+ const key = JSON.stringify(breakpoints);
60
+ if (!instances.has(key)) {
61
+ instances.set(key, createResizeService(breakpoints));
69
62
  }
70
- return resize;
63
+ return instances.get(key);
71
64
  }
72
65
  export {
73
66
  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 const finalScreens = breakpoints ?? features.get('breakpoints');\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).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(finalScreens).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, Resiz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