@studiometa/js-toolkit 3.0.0-beta.1 → 3.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/Base/Base.d.ts +19 -10
  2. package/Base/Base.js +46 -36
  3. package/Base/Base.js.map +2 -2
  4. package/Base/managers/AbstractManager.d.ts +3 -8
  5. package/Base/managers/AbstractManager.js +4 -22
  6. package/Base/managers/AbstractManager.js.map +2 -2
  7. package/Base/managers/ChildrenManager.d.ts +25 -2
  8. package/Base/managers/ChildrenManager.js +79 -63
  9. package/Base/managers/ChildrenManager.js.map +2 -2
  10. package/Base/managers/EventsManager.js +4 -12
  11. package/Base/managers/EventsManager.js.map +2 -2
  12. package/Base/managers/OptionsManager.d.ts +16 -11
  13. package/Base/managers/OptionsManager.js +38 -40
  14. package/Base/managers/OptionsManager.js.map +2 -2
  15. package/Base/managers/RefsManager.d.ts +11 -1
  16. package/Base/managers/RefsManager.js +48 -36
  17. package/Base/managers/RefsManager.js.map +2 -2
  18. package/Base/managers/ResponsiveOptionsManager.d.ts +9 -1
  19. package/Base/managers/ResponsiveOptionsManager.js +30 -23
  20. package/Base/managers/ResponsiveOptionsManager.js.map +2 -2
  21. package/Base/managers/ServicesManager.d.ts +12 -13
  22. package/Base/managers/ServicesManager.js +16 -22
  23. package/Base/managers/ServicesManager.js.map +2 -2
  24. package/Base/utils.js.map +2 -2
  25. package/decorators/index.d.ts +1 -0
  26. package/decorators/index.js +1 -0
  27. package/decorators/index.js.map +2 -2
  28. package/decorators/withBreakpointObserver.js +0 -2
  29. package/decorators/withBreakpointObserver.js.map +2 -2
  30. package/decorators/withDrag.js +1 -1
  31. package/decorators/withDrag.js.map +2 -2
  32. package/decorators/withIntersectionObserver.js +0 -2
  33. package/decorators/withIntersectionObserver.js.map +2 -2
  34. package/decorators/withMountOnMediaQuery.js +0 -2
  35. package/decorators/withMountOnMediaQuery.js.map +2 -2
  36. package/decorators/withMountWhenInView.js +0 -2
  37. package/decorators/withMountWhenInView.js.map +2 -2
  38. package/decorators/withMutation.d.ts +13 -0
  39. package/decorators/withMutation.js +34 -0
  40. package/decorators/withMutation.js.map +7 -0
  41. package/decorators/withRelativePointer.js +1 -1
  42. package/decorators/withRelativePointer.js.map +2 -2
  43. package/decorators/withScrolledInView/withScrolledInView.js +1 -1
  44. package/decorators/withScrolledInView/withScrolledInView.js.map +2 -2
  45. package/helpers/createApp.d.ts +1 -1
  46. package/helpers/createApp.js +20 -1
  47. package/helpers/createApp.js.map +2 -2
  48. package/helpers/getClosestParent.d.ts +1 -1
  49. package/helpers/getClosestParent.js +2 -2
  50. package/helpers/getClosestParent.js.map +2 -2
  51. package/helpers/getInstanceFromElement.d.ts +1 -1
  52. package/helpers/getInstanceFromElement.js +1 -1
  53. package/helpers/getInstanceFromElement.js.map +2 -2
  54. package/helpers/importOnInteraction.d.ts +1 -1
  55. package/helpers/importOnInteraction.js +1 -1
  56. package/helpers/importOnInteraction.js.map +2 -2
  57. package/helpers/importOnMediaQuery.d.ts +1 -1
  58. package/helpers/importOnMediaQuery.js +1 -1
  59. package/helpers/importOnMediaQuery.js.map +2 -2
  60. package/helpers/importWhenIdle.d.ts +1 -1
  61. package/helpers/importWhenIdle.js +1 -1
  62. package/helpers/importWhenIdle.js.map +2 -2
  63. package/helpers/importWhenPrefersMotion.d.ts +1 -1
  64. package/helpers/importWhenPrefersMotion.js +2 -2
  65. package/helpers/importWhenPrefersMotion.js.map +2 -2
  66. package/helpers/importWhenVisible.d.ts +1 -1
  67. package/helpers/importWhenVisible.js +1 -1
  68. package/helpers/importWhenVisible.js.map +2 -2
  69. package/helpers/index.d.ts +8 -8
  70. package/helpers/index.js +8 -18
  71. package/helpers/index.js.map +3 -3
  72. package/package.json +1 -1
  73. package/services/AbstractService.d.ts +10 -10
  74. package/services/AbstractService.js +10 -10
  75. package/services/AbstractService.js.map +3 -3
  76. package/services/DragService.js +5 -1
  77. package/services/DragService.js.map +2 -2
  78. package/services/KeyService.js +1 -1
  79. package/services/KeyService.js.map +2 -2
  80. package/services/MutationService.d.ts +20 -0
  81. package/services/MutationService.js +34 -0
  82. package/services/MutationService.js.map +7 -0
  83. package/services/PointerService.js +1 -1
  84. package/services/PointerService.js.map +2 -2
  85. package/services/ResizeService.js +2 -2
  86. package/services/ResizeService.js.map +2 -2
  87. package/services/ScrollService.js +1 -1
  88. package/services/ScrollService.js.map +2 -2
  89. package/services/index.d.ts +1 -0
  90. package/services/index.js +1 -0
  91. package/services/index.js.map +2 -2
  92. package/tsconfig.build.tsbuildinfo +1 -1
  93. package/utils/cache.d.ts +4 -0
  94. package/utils/cache.js +18 -0
  95. package/utils/cache.js.map +7 -0
  96. package/utils/collide/boundingRectToCircle.d.ts +1 -1
  97. package/utils/collide/boundingRectToCircle.js +1 -1
  98. package/utils/collide/boundingRectToCircle.js.map +2 -2
  99. package/utils/collide/collideCircleCircle.d.ts +1 -1
  100. package/utils/collide/collideCircleCircle.js +1 -1
  101. package/utils/collide/collideCircleCircle.js.map +2 -2
  102. package/utils/collide/collideCircleRect.d.ts +1 -1
  103. package/utils/collide/collideCircleRect.js +1 -1
  104. package/utils/collide/collideCircleRect.js.map +2 -2
  105. package/utils/collide/collidePointCircle.d.ts +1 -1
  106. package/utils/collide/collidePointCircle.js +1 -1
  107. package/utils/collide/collidePointCircle.js.map +2 -2
  108. package/utils/collide/collidePointRect.d.ts +1 -1
  109. package/utils/collide/collidePointRect.js +1 -1
  110. package/utils/collide/collidePointRect.js.map +2 -2
  111. package/utils/collide/collideRectRect.d.ts +1 -1
  112. package/utils/collide/collideRectRect.js +1 -1
  113. package/utils/collide/collideRectRect.js.map +2 -2
  114. package/utils/collide/index.d.ts +6 -6
  115. package/utils/collide/index.js +12 -12
  116. package/utils/collide/index.js.map +3 -3
  117. package/utils/css/animate.js.map +2 -2
  118. package/utils/css/getOffsetSizes.d.ts +1 -1
  119. package/utils/css/getOffsetSizes.js +1 -1
  120. package/utils/css/getOffsetSizes.js.map +2 -2
  121. package/utils/css/index.d.ts +3 -3
  122. package/utils/css/index.js +6 -6
  123. package/utils/css/index.js.map +3 -3
  124. package/utils/css/matrix.d.ts +1 -1
  125. package/utils/css/matrix.js +1 -1
  126. package/utils/css/matrix.js.map +2 -2
  127. package/utils/css/transition.d.ts +1 -1
  128. package/utils/css/transition.js +2 -2
  129. package/utils/css/transition.js.map +2 -2
  130. package/utils/debounce.d.ts +1 -1
  131. package/utils/debounce.js +1 -1
  132. package/utils/debounce.js.map +2 -2
  133. package/utils/dom/createElement.d.ts +10 -0
  134. package/utils/dom/createElement.js +21 -0
  135. package/utils/dom/createElement.js.map +7 -0
  136. package/utils/dom/index.d.ts +1 -0
  137. package/utils/dom/index.js +1 -0
  138. package/utils/dom/index.js.map +2 -2
  139. package/utils/getComponentResolver.d.ts +1 -1
  140. package/utils/getComponentResolver.js +1 -1
  141. package/utils/getComponentResolver.js.map +2 -2
  142. package/utils/index.d.ts +6 -5
  143. package/utils/index.js +11 -10
  144. package/utils/index.js.map +3 -3
  145. package/utils/keyCodes.d.ts +1 -2
  146. package/utils/keyCodes.js +2 -2
  147. package/utils/keyCodes.js.map +2 -2
  148. package/utils/math/clamp.d.ts +1 -1
  149. package/utils/math/clamp.js +1 -1
  150. package/utils/math/clamp.js.map +2 -2
  151. package/utils/math/clamp01.d.ts +1 -1
  152. package/utils/math/clamp01.js +2 -2
  153. package/utils/math/clamp01.js.map +2 -2
  154. package/utils/math/createEases.js.map +2 -2
  155. package/utils/math/damp.d.ts +1 -1
  156. package/utils/math/damp.js +1 -1
  157. package/utils/math/damp.js.map +2 -2
  158. package/utils/math/index.d.ts +7 -7
  159. package/utils/math/index.js +14 -14
  160. package/utils/math/index.js.map +3 -3
  161. package/utils/math/inertiaFinalValue.d.ts +1 -1
  162. package/utils/math/inertiaFinalValue.js +2 -2
  163. package/utils/math/inertiaFinalValue.js.map +2 -2
  164. package/utils/math/lerp.d.ts +1 -1
  165. package/utils/math/lerp.js +1 -1
  166. package/utils/math/lerp.js.map +2 -2
  167. package/utils/math/map.d.ts +1 -1
  168. package/utils/math/map.js +1 -1
  169. package/utils/math/map.js.map +2 -2
  170. package/utils/math/round.d.ts +1 -1
  171. package/utils/math/round.js +1 -1
  172. package/utils/math/round.js.map +2 -2
  173. package/utils/memoize.d.ts +1 -1
  174. package/utils/memoize.js +1 -1
  175. package/utils/memoize.js.map +2 -2
  176. package/utils/nextFrame.js.map +2 -2
  177. package/utils/object/getAllProperties.d.ts +1 -1
  178. package/utils/object/getAllProperties.js +1 -1
  179. package/utils/object/getAllProperties.js.map +2 -2
  180. package/utils/string/index.d.ts +10 -10
  181. package/utils/string/index.js +10 -22
  182. package/utils/string/index.js.map +3 -3
  183. package/utils/string/withLeadingCharacters.d.ts +1 -1
  184. package/utils/string/withLeadingCharacters.js +2 -2
  185. package/utils/string/withLeadingCharacters.js.map +2 -2
  186. package/utils/string/withLeadingSlash.d.ts +1 -1
  187. package/utils/string/withLeadingSlash.js +2 -2
  188. package/utils/string/withLeadingSlash.js.map +2 -2
  189. package/utils/string/withTrailingCharacters.d.ts +1 -1
  190. package/utils/string/withTrailingCharacters.js +2 -2
  191. package/utils/string/withTrailingCharacters.js.map +2 -2
  192. package/utils/string/withTrailingSlash.d.ts +1 -1
  193. package/utils/string/withTrailingSlash.js +2 -2
  194. package/utils/string/withTrailingSlash.js.map +2 -2
  195. package/utils/string/withoutLeadingCharacters.d.ts +1 -1
  196. package/utils/string/withoutLeadingCharacters.js +1 -1
  197. package/utils/string/withoutLeadingCharacters.js.map +2 -2
  198. package/utils/string/withoutLeadingCharactersRecursive.d.ts +1 -1
  199. package/utils/string/withoutLeadingCharactersRecursive.js +2 -2
  200. package/utils/string/withoutLeadingCharactersRecursive.js.map +2 -2
  201. package/utils/string/withoutLeadingSlash.d.ts +1 -1
  202. package/utils/string/withoutLeadingSlash.js +2 -2
  203. package/utils/string/withoutLeadingSlash.js.map +2 -2
  204. package/utils/string/withoutTrailingCharacters.d.ts +1 -1
  205. package/utils/string/withoutTrailingCharacters.js +1 -1
  206. package/utils/string/withoutTrailingCharacters.js.map +2 -2
  207. package/utils/string/withoutTrailingCharactersRecursive.d.ts +1 -1
  208. package/utils/string/withoutTrailingCharactersRecursive.js +2 -2
  209. package/utils/string/withoutTrailingCharactersRecursive.js.map +2 -2
  210. package/utils/string/withoutTrailingSlash.d.ts +1 -1
  211. package/utils/string/withoutTrailingSlash.js +2 -2
  212. package/utils/string/withoutTrailingSlash.js.map +2 -2
  213. package/utils/throttle.d.ts +1 -1
  214. package/utils/throttle.js +1 -1
  215. package/utils/throttle.js.map +2 -2
  216. package/utils/trapFocus.js +1 -1
  217. package/utils/trapFocus.js.map +2 -2
@@ -31,43 +31,10 @@ function refBelongToInstance(ref, rootElement, name) {
31
31
  );
32
32
  return firstComponentAncestor === rootElement;
33
33
  }
34
- function __register(that, refName) {
35
- const isMultiple = endsWith(refName, "[]");
36
- const propName = normalizeRefName(refName);
37
- const { name } = that.__base.$options;
38
- const attributes = features.get("attributes");
39
- const refs = [];
40
- const selector = `[${attributes.ref}="${refName}"],[${attributes.ref}="${name}.${refName}"]`;
41
- for (const ref of that.__element.querySelectorAll(selector)) {
42
- if (refBelongToInstance(ref, that.__element, name)) {
43
- refs.push(ref);
44
- }
45
- }
46
- if (isDev && !isMultiple && refs.length > 1) {
47
- console.warn(
48
- `[${that.__base.$id}]`,
49
- `The "${refName}" ref has been found multiple times.`,
50
- "Did you forgot to add the `[]` suffix to its name?"
51
- );
52
- }
53
- if (refs.length) {
54
- that.__eventsManager.bindRef(refName, refs);
55
- }
56
- Object.defineProperty(that, camelCase(propName), {
57
- // @todo remove usage of non-multiple refs as array
58
- value: isMultiple || refs.length > 1 ? refs : refs[0],
59
- enumerable: true,
60
- configurable: true
61
- });
62
- }
63
- function __unregister(that, refName) {
64
- const propName = normalizeRefName(refName);
65
- const refs = isArray(that[propName]) ? that[propName] : [that[propName]];
66
- that.__eventsManager.unbindRef(refName, refs);
67
- }
68
34
  class RefsManager extends AbstractManager {
69
35
  /**
70
36
  * Get refs configuration.
37
+ * @private
71
38
  */
72
39
  get __refs() {
73
40
  return this.__config.refs ?? [];
@@ -76,13 +43,58 @@ class RefsManager extends AbstractManager {
76
43
  * Register all refs.
77
44
  */
78
45
  registerAll() {
79
- for (const refName of this.__refs) __register(this, refName);
46
+ for (const refName of this.__refs) {
47
+ this.__register(refName);
48
+ }
80
49
  }
81
50
  /**
82
51
  * Unregister all refs.
83
52
  */
84
53
  unregisterAll() {
85
- for (const refName of this.__refs) __unregister(this, refName);
54
+ for (const refName of this.__refs) {
55
+ this.__unregister(refName);
56
+ }
57
+ }
58
+ /**
59
+ * Register one ref.
60
+ * @private
61
+ */
62
+ __register(refName) {
63
+ const isMultiple = endsWith(refName, "[]");
64
+ const propName = normalizeRefName(refName);
65
+ const { name } = this.__base.__config;
66
+ const attributes = features.get("attributes");
67
+ const refs = [];
68
+ const selector = `[${attributes.ref}="${refName}"],[${attributes.ref}="${name}.${refName}"]`;
69
+ for (const ref of this.__element.querySelectorAll(selector)) {
70
+ if (refBelongToInstance(ref, this.__element, name)) {
71
+ refs.push(ref);
72
+ }
73
+ }
74
+ if (isDev && !isMultiple && refs.length > 1) {
75
+ console.warn(
76
+ `[${this.__base.$id}]`,
77
+ `The "${refName}" ref has been found multiple times.`,
78
+ "Did you forgot to add the `[]` suffix to its name?"
79
+ );
80
+ }
81
+ if (refs.length) {
82
+ this.__eventsManager.bindRef(refName, refs);
83
+ }
84
+ Object.defineProperty(this.props, camelCase(propName), {
85
+ // @todo remove usage of non-multiple refs as array
86
+ value: isMultiple || refs.length > 1 ? refs : refs[0],
87
+ enumerable: true,
88
+ configurable: true
89
+ });
90
+ }
91
+ /**
92
+ * Unregister one ref.
93
+ */
94
+ __unregister(refName) {
95
+ const propName = normalizeRefName(refName);
96
+ const refs = this.props[propName];
97
+ this.__eventsManager.unbindRef(refName, isArray(refs) ? refs : [refs]);
86
98
  }
87
99
  }
88
100
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../packages/js-toolkit/Base/managers/RefsManager.ts"],
4
- "sourcesContent": ["import { AbstractManager } from './AbstractManager.js';\nimport {\n isDev,\n isArray,\n getAncestorWhereUntil,\n endsWith,\n startsWith,\n memo,\n camelCase,\n} from '../../utils/index.js';\nimport { features } from '../features.js';\n\nconst NORMALIZE_REF_NAME_REGEX = /\\[\\]$/;\nconst NAMESPACED_REF_REGEX = /^(.*\\.)/;\n\n/**\n * Normalize the name of ref.\n */\nexport const normalizeRefName = memo(function normalizeRefName(name: string) {\n let normalizedName = name;\n\n if (endsWith(name, '[]')) {\n normalizedName = normalizedName.replace(NORMALIZE_REF_NAME_REGEX, '');\n }\n\n if (normalizedName.includes('.')) {\n return normalizedName.replace(NAMESPACED_REF_REGEX, '');\n }\n\n return normalizedName;\n});\n\n/**\n * Filter refs belonging to the related Base instance.\n */\nfunction refBelongToInstance(ref: HTMLElement, rootElement: HTMLElement, name: string) {\n const attributes = features.get('attributes');\n const isPrefixed = startsWith(ref.getAttribute(attributes.ref), name);\n const firstComponentAncestor = getAncestorWhereUntil(\n ref,\n (el) =>\n el &&\n (isPrefixed\n ? el.getAttribute(attributes.component) === name && el\n : el.getAttribute(attributes.component)) &&\n el !== rootElement,\n (el) => el === rootElement,\n );\n\n return firstComponentAncestor === rootElement;\n}\n\n/**\n * Register one ref.\n *\n * @param {RefsManager} that\n * @param {string} refName The ref name.\n * @private\n */\nfunction __register(that: RefsManager, refName: string) {\n const isMultiple = endsWith(refName, '[]');\n const propName = normalizeRefName(refName);\n const { name } = that.__base.$options;\n const attributes = features.get('attributes');\n const refs = [] as HTMLElement[];\n const selector = `[${attributes.ref}=\"${refName}\"],[${attributes.ref}=\"${name}.${refName}\"]`;\n\n for (const ref of that.__element.querySelectorAll<HTMLElement>(selector)) {\n if (refBelongToInstance(ref, that.__element, name)) {\n refs.push(ref);\n }\n }\n\n /* v8 ignore next 7 */\n if (isDev && !isMultiple && refs.length > 1) {\n console.warn(\n `[${that.__base.$id}]`,\n `The \"${refName}\" ref has been found multiple times.`,\n 'Did you forgot to add the `[]` suffix to its name?',\n );\n }\n\n if (refs.length) {\n that.__eventsManager.bindRef(refName, refs);\n }\n\n Object.defineProperty(that, camelCase(propName), {\n // @todo remove usage of non-multiple refs as array\n value: isMultiple || refs.length > 1 ? refs : refs[0],\n enumerable: true,\n configurable: true,\n });\n}\n\n/**\n * Unregister one ref.\n */\nfunction __unregister(that: RefsManager, refName: string) {\n const propName = normalizeRefName(refName);\n const refs = isArray(that[propName]) ? that[propName] : [that[propName]];\n that.__eventsManager.unbindRef(refName, refs);\n}\n\n/**\n * Refs Manager\n *\n * @todo Use `MutationObserver` to automatically update refs?\n */\nexport class RefsManager extends AbstractManager {\n /**\n * Get refs configuration.\n */\n get __refs() {\n return this.__config.refs ?? [];\n }\n\n /**\n * Register all refs.\n */\n registerAll() {\n for (const refName of this.__refs) __register(this, refName);\n }\n\n /**\n * Unregister all refs.\n */\n unregisterAll() {\n for (const refName of this.__refs) __unregister(this, refName);\n }\n}\n"],
5
- "mappings": "AAAA,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AAEzB,MAAM,2BAA2B;AACjC,MAAM,uBAAuB;AAKtB,MAAM,mBAAmB,KAAK,SAASA,kBAAiB,MAAc;AAC3E,MAAI,iBAAiB;AAErB,MAAI,SAAS,MAAM,IAAI,GAAG;AACxB,qBAAiB,eAAe,QAAQ,0BAA0B,EAAE;AAAA,EACtE;AAEA,MAAI,eAAe,SAAS,GAAG,GAAG;AAChC,WAAO,eAAe,QAAQ,sBAAsB,EAAE;AAAA,EACxD;AAEA,SAAO;AACT,CAAC;AAKD,SAAS,oBAAoB,KAAkB,aAA0B,MAAc;AACrF,QAAM,aAAa,SAAS,IAAI,YAAY;AAC5C,QAAM,aAAa,WAAW,I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AAK,QAAQ,CAAC;AACvE,OAAK,gBAAgB,UAAU,SAAS,IAAI;AAC9C;AAOO,MAAM,oBAAoB,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAI/C,IAAI,SAAS;AACX,WAAO,KAAK,SAAS,QAAQ,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAKA,cAAc;AACZ,eAAW,WAAW,KAAK,OAAQ,YAAW,MAAM,OAAO;AAAA,EAC7D;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAgB;AACd,eAAW,WAAW,KAAK,OAAQ,cAAa,MAAM,OAAO;AAAA,EAC/D;AACF;",
4
+ "sourcesContent": ["import { AbstractManager } from './AbstractManager.js';\nimport {\n isDev,\n isArray,\n getAncestorWhereUntil,\n endsWith,\n startsWith,\n memo,\n camelCase,\n} from '../../utils/index.js';\nimport { features } from '../features.js';\n\nconst NORMALIZE_REF_NAME_REGEX = /\\[\\]$/;\nconst NAMESPACED_REF_REGEX = /^(.*\\.)/;\n\n/**\n * Normalize the name of ref.\n */\nexport const normalizeRefName = memo(function normalizeRefName(name: string) {\n let normalizedName = name;\n\n if (endsWith(name, '[]')) {\n normalizedName = normalizedName.replace(NORMALIZE_REF_NAME_REGEX, '');\n }\n\n if (normalizedName.includes('.')) {\n return normalizedName.replace(NAMESPACED_REF_REGEX, '');\n }\n\n return normalizedName;\n});\n\n/**\n * Filter refs belonging to the related Base instance.\n */\nfunction refBelongToInstance(ref: HTMLElement, rootElement: HTMLElement, name: string) {\n const attributes = features.get('attributes');\n const isPrefixed = startsWith(ref.getAttribute(attributes.ref), name);\n const firstComponentAncestor = getAncestorWhereUntil(\n ref,\n (el) =>\n el &&\n (isPrefixed\n ? el.getAttribute(attributes.component) === name && el\n : el.getAttribute(attributes.component)) &&\n el !== rootElement,\n (el) => el === rootElement,\n );\n\n return firstComponentAncestor === rootElement;\n}\n\n/**\n * Refs Manager\n *\n * @todo Use `MutationObserver` to automatically update refs?\n */\nexport class RefsManager<T> extends AbstractManager<T> {\n /**\n * Get refs configuration.\n * @private\n */\n get __refs() {\n return this.__config.refs ?? [];\n }\n\n /**\n * Register all refs.\n */\n registerAll() {\n for (const refName of this.__refs) {\n this.__register(refName);\n }\n }\n\n /**\n * Unregister all refs.\n */\n unregisterAll() {\n for (const refName of this.__refs) {\n this.__unregister(refName);\n }\n }\n\n /**\n * Register one ref.\n * @private\n */\n __register(refName: string) {\n const isMultiple = endsWith(refName, '[]');\n const propName = normalizeRefName(refName);\n const { name } = this.__base.__config;\n const attributes = features.get('attributes');\n const refs = [] as HTMLElement[];\n const selector = `[${attributes.ref}=\"${refName}\"],[${attributes.ref}=\"${name}.${refName}\"]`;\n\n for (const ref of this.__element.querySelectorAll<HTMLElement>(selector)) {\n if (refBelongToInstance(ref, this.__element, name)) {\n refs.push(ref);\n }\n }\n\n /* v8 ignore next 7 */\n if (isDev && !isMultiple && refs.length > 1) {\n console.warn(\n `[${this.__base.$id}]`,\n `The \"${refName}\" ref has been found multiple times.`,\n 'Did you forgot to add the `[]` suffix to its name?',\n );\n }\n\n if (refs.length) {\n this.__eventsManager.bindRef(refName, refs);\n }\n\n Object.defineProperty(this.props, camelCase(propName), {\n // @todo remove usage of non-multiple refs as array\n value: isMultiple || refs.length > 1 ? refs : refs[0],\n enumerable: true,\n configurable: true,\n });\n }\n\n /**\n * Unregister one ref.\n */\n __unregister(refName: string) {\n const propName = normalizeRefName(refName);\n const refs = this.props[propName];\n this.__eventsManager.unbindRef(refName, isArray(refs) ? refs : [refs]);\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AAEzB,MAAM,2BAA2B;AACjC,MAAM,uBAAuB;AAKtB,MAAM,mBAAmB,KAAK,SAASA,kBAAiB,MAAc;AAC3E,MAAI,iBAAiB;AAErB,MAAI,SAAS,MAAM,IAAI,G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Q,GAAG;AACxE,UAAI,oBAAoB,KAAK,KAAK,WAAW,IAAI,GAAG;AAClD,aAAK,KAAK,GAAG;AAAA,MACf;AAAA,IACF;AAGA,QAAI,SAAS,CAAC,cAAc,KAAK,SAAS,GAAG;AAC3C,cAAQ;AAAA,QACN,IAAI,KAAK,OAAO,GAAG;AAAA,QACnB,QAAQ,OAAO;AAAA,QACf;AAAA,MACF;AAAA,IACF;AAEA,QAAI,KAAK,QAAQ;AACf,WAAK,gBAAgB,QAAQ,SAAS,IAAI;AAAA,IAC5C;AAEA,WAAO,eAAe,KAAK,OAAO,UAAU,QAAQ,GAAG;AAAA;AAAA,MAErD,OAAO,cAAc,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC;AAAA,MACpD,YAAY;AAAA,MACZ,cAAc;AAAA,IAChB,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,aAAa,SAAiB;AAC5B,UAAM,WAAW,iBAAiB,OAAO;AACzC,UAAM,OAAO,KAAK,MAAM,QAAQ;AAChC,SAAK,gBAAgB,UAAU,SAAS,QAAQ,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;AAAA,EACvE;AACF;",
6
6
  "names": ["normalizeRefName"]
7
7
  }
@@ -6,7 +6,7 @@ export type ResponsiveOptionObject = OptionObject & {
6
6
  /**
7
7
  * Class options to manage options as data attributes on an HTML element.
8
8
  */
9
- export declare class ResponsiveOptionsManager extends OptionsManager {
9
+ export declare class ResponsiveOptionsManager<T> extends OptionsManager<T> {
10
10
  /**
11
11
  * Get an option value.
12
12
  *
@@ -23,4 +23,12 @@ export declare class ResponsiveOptionsManager extends OptionsManager {
23
23
  * @param {ResponsiveOptionObject} config The option configuration.
24
24
  */
25
25
  set(name: string, value: unknown, config: ResponsiveOptionObject): void;
26
+ /**
27
+ * Get the currently active responsive name of an option.
28
+ *
29
+ * @param {ResponsiveOptionsManager} that
30
+ * @param {string} name The default name of the option.
31
+ * @returns {string} The responsive name if one matches the current breakpoint, the default name otherwise.
32
+ */
33
+ __getResponsiveName(name: string): string;
26
34
  }
@@ -2,27 +2,6 @@ import { OptionsManager, __getPropertyName } from "./OptionsManager.js";
2
2
  import { useResize } from "../../services/index.js";
3
3
  import { isDev } from "../../utils/index.js";
4
4
  import { features } from "../features.js";
5
- function __getResponsiveName(that, name) {
6
- const { breakpoint } = useResize().props();
7
- if (!breakpoint) {
8
- return name;
9
- }
10
- let responsiveName = name;
11
- const propertyName = __getPropertyName(name).toLowerCase();
12
- const regex = new RegExp(`${propertyName}:(.+)$`, "i");
13
- const attributes = features.get("attributes");
14
- const dataOptionRegExp = new RegExp(`^${attributes.option}-`);
15
- for (const optionName of that.__element.getAttributeNames()) {
16
- if (regex.test(optionName)) {
17
- const [, breakpoints] = optionName.match(regex);
18
- const isInBreakpoint = breakpoints.split(":").includes(breakpoint);
19
- if (isInBreakpoint) {
20
- responsiveName = optionName.replace(dataOptionRegExp, "");
21
- }
22
- }
23
- }
24
- return responsiveName;
25
- }
26
5
  class ResponsiveOptionsManager extends OptionsManager {
27
6
  /**
28
7
  * Get an option value.
@@ -35,7 +14,7 @@ class ResponsiveOptionsManager extends OptionsManager {
35
14
  if (!config.responsive) {
36
15
  return super.get(name, config);
37
16
  }
38
- return super.get(__getResponsiveName(this, name), config);
17
+ return super.get(this.__getResponsiveName(name), config);
39
18
  }
40
19
  /**
41
20
  * Set an option value.
@@ -50,8 +29,36 @@ class ResponsiveOptionsManager extends OptionsManager {
50
29
  return;
51
30
  }
52
31
  if (isDev) {
53
- console.warn(`[${this.__config.name}]`, "Responsive options are read-only.");
32
+ console.warn(`[${this.__base.$id}]`, "Responsive options are read-only.");
33
+ }
34
+ }
35
+ /**
36
+ * Get the currently active responsive name of an option.
37
+ *
38
+ * @param {ResponsiveOptionsManager} that
39
+ * @param {string} name The default name of the option.
40
+ * @returns {string} The responsive name if one matches the current breakpoint, the default name otherwise.
41
+ */
42
+ __getResponsiveName(name) {
43
+ const { breakpoint } = useResize().props();
44
+ if (!breakpoint) {
45
+ return name;
46
+ }
47
+ let responsiveName = name;
48
+ const propertyName = __getPropertyName(name).toLowerCase();
49
+ const regex = new RegExp(`${propertyName}:(.+)$`, "i");
50
+ const attributes = features.get("attributes");
51
+ const dataOptionRegExp = new RegExp(`^${attributes.option}-`);
52
+ for (const optionName of this.__element.getAttributeNames()) {
53
+ if (regex.test(optionName)) {
54
+ const [, breakpoints] = optionName.match(regex);
55
+ const isInBreakpoint = breakpoints.split(":").includes(breakpoint);
56
+ if (isInBreakpoint) {
57
+ responsiveName = optionName.replace(dataOptionRegExp, "");
58
+ }
59
+ }
54
60
  }
61
+ return responsiveName;
55
62
  }
56
63
  }
57
64
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../packages/js-toolkit/Base/managers/ResponsiveOptionsManager.ts"],
4
- "sourcesContent": ["import { OptionsManager, __getPropertyName } from './OptionsManager.js';\nimport type { OptionObject } from './OptionsManager.js';\nimport { useResize } from '../../services/index.js';\nimport { isDev } from '../../utils/index.js';\nimport { features } from '../features.js';\n\nexport type ResponsiveOptionObject = OptionObject & { responsive?: boolean };\n\n/**\n * Get the currently active responsive name of an option.\n *\n * @param {ResponsiveOptionsManager} that\n * @param {string} name The default name of the option.\n * @returns {string} The responsive name if one matches the current breakpoint, the default name otherwise.\n */\nfunction __getResponsiveName(that: ResponsiveOptionsManager, name: string) {\n const { breakpoint } = useResize().props();\n\n if (!breakpoint) {\n return name;\n }\n\n let responsiveName = name;\n const propertyName = __getPropertyName(name).toLowerCase();\n const regex = new RegExp(`${propertyName}:(.+)$`, 'i');\n const attributes = features.get('attributes');\n const dataOptionRegExp = new RegExp(`^${attributes.option}-`);\n\n for (const optionName of that.__element.getAttributeNames()) {\n if (regex.test(optionName)) {\n const [, breakpoints] = optionName.match(regex);\n const isInBreakpoint = breakpoints.split(':').includes(breakpoint);\n if (isInBreakpoint) {\n responsiveName = optionName.replace(dataOptionRegExp, '');\n }\n }\n }\n\n return responsiveName;\n}\n\n/**\n * Class options to manage options as data attributes on an HTML element.\n */\nexport class ResponsiveOptionsManager extends OptionsManager {\n /**\n * Get an option value.\n *\n * @param {string} name The option name.\n * @param {ResponsiveOptionObject} config The option configuration.\n * @returns {any}\n */\n get(name: string, config: ResponsiveOptionObject) {\n if (!config.responsive) {\n return super.get(name, config);\n }\n\n return super.get(__getResponsiveName(this, name), config);\n }\n\n /**\n * Set an option value.\n *\n * @param {string} name The option name.\n * @param {any} value The new value.\n * @param {ResponsiveOptionObject} config The option configuration.\n */\n set(name: string, value: unknown, config: ResponsiveOptionObject) {\n if (!config.responsive) {\n super.set(name, value, config);\n return;\n }\n\n if (isDev) {\n console.warn(`[${this.__config.name}]`, 'Responsive options are read-only.');\n }\n }\n}\n"],
5
- "mappings": "AAAA,SAAS,gBAAgB,yBAAyB;AAElD,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AACtB,SAAS,gBAAgB;AAWzB,SAAS,oBAAoB,MAAgC,MAAc;AACzE,QAAM,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM;AAEzC,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AAEA,MAAI,iBAAiB;AACrB,QAAM,eAAe,kBAAkB,IAAI,EAAE,YAAY;AACzD,QAAM,QAAQ,IAAI,OAAO,GAAG,YAAY,UAAU,GAAG;AACrD,QAAM,aAAa,SAAS,IAAI,YAAY;AAC5C,QAAM,mBAAmB,IAAI,OAAO,IAAI,WAAW,MAAM,GAAG;AAE5D,aAAW,cAAc,KAAK,UAAU,kBAAkB,GAAG;AAC3D,QAAI,MAAM,KAAK,UAAU,GAAG;AAC1B,YAAM,CAAC,EAAE,WAAW,IAAI,WAAW,MAAM,KAAK;AAC9C,YAAM,iBAAiB,YAAY,MAAM,GAAG,EAAE,SAAS,UAAU;AACjE,UAAI,gBAAgB;AAClB,yBAAiB,WAAW,QAAQ,kBAAkB,EAAE;AAAA,MAC1D;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAKO,MAAM,iCAAiC,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ3D,IAAI,MAAc,QAAgC;AAChD,QAAI,CAAC,OAAO,YAAY;AACtB,aAAO,MAAM,IAAI,MAAM,MAAM;AAAA,IAC/B;AAEA,WAAO,MAAM,IAAI,oBAAoB,MAAM,IAAI,GAAG,MAAM;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAI,MAAc,OAAgB,QAAgC;AAChE,QAAI,CAAC,OAAO,YAAY;AACtB,YAAM,IAAI,MAAM,OAAO,MAAM;AAC7B;AAAA,IACF;AAEA,QAAI,OAAO;AACT,cAAQ,KAAK,IAAI,KAAK,SAAS,IAAI,KAAK,mCAAmC;AAAA,IAC7E;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { OptionsManager, __getPropertyName } from './OptionsManager.js';\nimport type { OptionObject } from './OptionsManager.js';\nimport { useResize } from '../../services/index.js';\nimport { isDev } from '../../utils/index.js';\nimport { features } from '../features.js';\n\nexport type ResponsiveOptionObject = OptionObject & { responsive?: boolean };\n\n/**\n * Class options to manage options as data attributes on an HTML element.\n */\nexport class ResponsiveOptionsManager<T> extends OptionsManager<T> {\n /**\n * Get an option value.\n *\n * @param {string} name The option name.\n * @param {ResponsiveOptionObject} config The option configuration.\n * @returns {any}\n */\n get(name: string, config: ResponsiveOptionObject) {\n if (!config.responsive) {\n return super.get(name, config);\n }\n\n return super.get(this.__getResponsiveName(name), config);\n }\n\n /**\n * Set an option value.\n *\n * @param {string} name The option name.\n * @param {any} value The new value.\n * @param {ResponsiveOptionObject} config The option configuration.\n */\n set(name: string, value: unknown, config: ResponsiveOptionObject) {\n if (!config.responsive) {\n super.set(name, value, config);\n return;\n }\n\n if (isDev) {\n console.warn(`[${this.__base.$id}]`, 'Responsive options are read-only.');\n }\n }\n\n /**\n * Get the currently active responsive name of an option.\n *\n * @param {ResponsiveOptionsManager} that\n * @param {string} name The default name of the option.\n * @returns {string} The responsive name if one matches the current breakpoint, the default name otherwise.\n */\n __getResponsiveName(name: string) {\n const { breakpoint } = useResize().props();\n\n if (!breakpoint) {\n return name;\n }\n\n let responsiveName = name;\n const propertyName = __getPropertyName(name).toLowerCase();\n const regex = new RegExp(`${propertyName}:(.+)$`, 'i');\n const attributes = features.get('attributes');\n const dataOptionRegExp = new RegExp(`^${attributes.option}-`);\n\n for (const optionName of this.__element.getAttributeNames()) {\n if (regex.test(optionName)) {\n const [, breakpoints] = optionName.match(regex);\n const isInBreakpoint = breakpoints.split(':').includes(breakpoint);\n if (isInBreakpoint) {\n responsiveName = optionName.replace(dataOptionRegExp, '');\n }\n }\n }\n\n return responsiveName;\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,gBAAgB,yBAAyB;AAElD,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AACtB,SAAS,gBAAgB;AAOlB,MAAM,iCAAoC,eAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjE,IAAI,MAAc,QAAgC;AAChD,QAAI,CAAC,OAAO,YAAY;AACtB,aAAO,MAAM,IAAI,MAAM,MAAM;AAAA,IAC/B;AAEA,WAAO,MAAM,IAAI,KAAK,oBAAoB,IAAI,GAAG,MAAM;AAAA,EACzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAI,MAAc,OAAgB,QAAgC;AAChE,QAAI,CAAC,OAAO,YAAY;AACtB,YAAM,IAAI,MAAM,OAAO,MAAM;AAC7B;AAAA,IACF;AAEA,QAAI,OAAO;AACT,cAAQ,KAAK,IAAI,KAAK,OAAO,GAAG,KAAK,mCAAmC;AAAA,IAC1E;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,oBAAoB,MAAc;AAChC,UAAM,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM;AAEzC,QAAI,CAAC,YAAY;AACf,aAAO;AAAA,IACT;AAEA,QAAI,iBAAiB;AACrB,UAAM,eAAe,kBAAkB,IAAI,EAAE,YAAY;AACzD,UAAM,QAAQ,IAAI,OAAO,GAAG,YAAY,UAAU,GAAG;AACrD,UAAM,aAAa,SAAS,IAAI,YAAY;AAC5C,UAAM,mBAAmB,IAAI,OAAO,IAAI,WAAW,MAAM,GAAG;AAE5D,eAAW,cAAc,KAAK,UAAU,kBAAkB,GAAG;AAC3D,UAAI,MAAM,KAAK,UAAU,GAAG;AAC1B,cAAM,CAAC,EAAE,WAAW,IAAI,WAAW,MAAM,KAAK;AAC9C,cAAM,iBAAiB,YAAY,MAAM,GAAG,EAAE,SAAS,UAAU;AACjE,YAAI,gBAAgB;AAClB,2BAAiB,WAAW,QAAQ,kBAAkB,EAAE;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,13 @@
1
1
  import { usePointer, useRaf, useResize, useScroll, useKey } from '../../services/index.js';
2
2
  import type { PointerServiceInterface, RafServiceInterface, ResizeServiceInterface, ScrollServiceInterface, KeyServiceInterface, ServiceInterface } from '../../services/index.js';
3
3
  import { AbstractManager } from './AbstractManager.js';
4
+ declare const SERVICES_MAP: {
5
+ scrolled: typeof useScroll;
6
+ resized: typeof useResize;
7
+ ticked: typeof useRaf;
8
+ moved: typeof usePointer;
9
+ keyed: typeof useKey;
10
+ };
4
11
  type Services = {
5
12
  scrolled: ScrollServiceInterface;
6
13
  resized: ResizeServiceInterface;
@@ -8,27 +15,19 @@ type Services = {
8
15
  moved: PointerServiceInterface;
9
16
  keyed: KeyServiceInterface;
10
17
  } & Record<string, ServiceInterface<unknown>>;
18
+ type ServiceProps = typeof SERVICES_MAP & Record<string, <T>() => ServiceInterface<T>>;
11
19
  type ServiceNames = keyof Services;
12
20
  /**
13
21
  * Services management for the Base class.
14
22
  *
15
23
  * @todo Add support for disabled services on mount when the method is defined.
16
24
  */
17
- export declare class ServicesManager extends AbstractManager {
25
+ export declare class ServicesManager extends AbstractManager<ServiceProps> {
18
26
  /**
19
- * Holder for custom services.
27
+ * Custom props
28
+ * @private
20
29
  */
21
- __customServices: Record<string, <T>() => ServiceInterface<T>>;
22
- /**
23
- * Get registered services.
24
- */
25
- get __services(): {
26
- scrolled: typeof useScroll;
27
- resized: typeof useResize;
28
- ticked: typeof useRaf;
29
- moved: typeof usePointer;
30
- keyed: typeof useKey;
31
- };
30
+ __props: ServiceProps;
32
31
  /**
33
32
  * Test if the given service is registered.
34
33
  */
@@ -11,34 +11,28 @@ const SERVICES_MAP = {
11
11
  const SERVICE_NAMES = Object.keys(SERVICES_MAP);
12
12
  class ServicesManager extends AbstractManager {
13
13
  /**
14
- * Holder for custom services.
14
+ * Custom props
15
+ * @private
15
16
  */
16
- __customServices = {};
17
- /**
18
- * Get registered services.
19
- */
20
- get __services() {
21
- return {
22
- ...this.__customServices,
23
- ...SERVICES_MAP
24
- };
25
- }
17
+ __props = {
18
+ ...SERVICES_MAP
19
+ };
26
20
  /**
27
21
  * Test if the given service is registered.
28
22
  */
29
23
  has(service) {
30
24
  if (!((isFunction(this.__base[service]) || // @ts-ignore
31
- this.__base.__hasEvent(service)) && this.__services[service])) {
25
+ this.__base.__hasEvent(service)) && this.props[service])) {
32
26
  return false;
33
27
  }
34
- const { has } = this.__services[service]();
28
+ const { has } = this.props[service]();
35
29
  return has(this.__base.$id);
36
30
  }
37
31
  /**
38
32
  * Get a service props by name.
39
33
  */
40
34
  get(service) {
41
- return this.__services[service]().props();
35
+ return this.props[service]().props();
42
36
  }
43
37
  /**
44
38
  * Init the given service and bind it to the given instance.
@@ -52,11 +46,11 @@ class ServicesManager extends AbstractManager {
52
46
  }
53
47
  if (
54
48
  // @ts-ignore
55
- !(isFunction(this.__base[service]) || this.__base.__hasEvent(service)) || !this.__services[service]
49
+ !(isFunction(this.__base[service]) || this.__base.__hasEvent(service)) || !this.props[service]
56
50
  ) {
57
51
  return noop;
58
52
  }
59
- const serviceInstance = this.__services[service]();
53
+ const serviceInstance = this.props[service]();
60
54
  serviceInstance.add(this.__base.$id, (...args) => this.__base.__callMethod(service, ...args));
61
55
  return this.disable.bind(this, service);
62
56
  }
@@ -64,7 +58,7 @@ class ServicesManager extends AbstractManager {
64
58
  * Enable all services and return methods to disable them.
65
59
  */
66
60
  enableAll() {
67
- return Object.keys(this.__services).map((serviceName) => this.enable(serviceName));
61
+ return Object.keys(this.props).map((serviceName) => this.enable(serviceName));
68
62
  }
69
63
  /**
70
64
  * Disable all services.
@@ -72,7 +66,7 @@ class ServicesManager extends AbstractManager {
72
66
  * @returns {void}
73
67
  */
74
68
  disableAll() {
75
- for (const serviceName of Object.keys(this.__services)) {
69
+ for (const serviceName of Object.keys(this.props)) {
76
70
  this.disable(serviceName);
77
71
  }
78
72
  }
@@ -80,10 +74,10 @@ class ServicesManager extends AbstractManager {
80
74
  * Disable a service.
81
75
  */
82
76
  disable(service) {
83
- if (!this.__services[service]) {
77
+ if (!this.props[service]) {
84
78
  return;
85
79
  }
86
- const { remove } = this.__services[service]();
80
+ const { remove } = this.props[service]();
87
81
  remove(this.__base.$id);
88
82
  }
89
83
  /**
@@ -112,7 +106,7 @@ class ServicesManager extends AbstractManager {
112
106
  * The `use...` function for the service.
113
107
  */
114
108
  register(name, useFunction) {
115
- this.__customServices[name] = useFunction;
109
+ this.props[name] = useFunction;
116
110
  this.__base.__addEmits(name);
117
111
  }
118
112
  /**
@@ -129,7 +123,7 @@ class ServicesManager extends AbstractManager {
129
123
  return;
130
124
  }
131
125
  this.__base.__removeEmits(name);
132
- delete this.__customServices[name];
126
+ delete this.props[name];
133
127
  }
134
128
  }
135
129
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../packages/js-toolkit/Base/managers/ServicesManager.ts"],
4
- "sourcesContent": ["import { usePointer, useRaf, useResize, useScroll, useKey } from '../../services/index.js';\nimport type {\n PointerServiceInterface,\n RafServiceInterface,\n ResizeServiceInterface,\n ScrollServiceInterface,\n KeyServiceInterface,\n ServiceInterface,\n} from '../../services/index.js';\nimport { AbstractManager } from './AbstractManager.js';\nimport { noop, isFunction, isDefined, isDev } from '../../utils/index.js';\n\nconst SERVICES_MAP = {\n scrolled: useScroll,\n resized: useResize,\n ticked: useRaf,\n moved: usePointer,\n keyed: useKey,\n};\n\nconst SERVICE_NAMES = Object.keys(SERVICES_MAP);\n\ntype Services = {\n scrolled: ScrollServiceInterface;\n resized: ResizeServiceInterface;\n ticked: RafServiceInterface;\n moved: PointerServiceInterface;\n keyed: KeyServiceInterface;\n} & Record<string, ServiceInterface<unknown>>;\n\ntype ServiceNames = keyof Services;\n\n/**\n * Services management for the Base class.\n *\n * @todo Add support for disabled services on mount when the method is defined.\n */\nexport class ServicesManager extends AbstractManager {\n /**\n * Holder for custom services.\n */\n __customServices: Record<string, <T>() => ServiceInterface<T>> = {};\n\n /**\n * Get registered services.\n */\n get __services() {\n return {\n ...this.__customServices,\n ...SERVICES_MAP,\n };\n }\n\n /**\n * Test if the given service is registered.\n */\n has(service: ServiceNames | string): boolean {\n if (\n !(\n (isFunction(this.__base[service]) ||\n // @ts-ignore\n this.__base.__hasEvent(service)) &&\n this.__services[service]\n )\n ) {\n return false;\n }\n\n const { has } = this.__services[service]();\n return has(this.__base.$id);\n }\n\n /**\n * Get a service props by name.\n */\n get<S extends ServiceNames | string>(service: S): ReturnType<Services[S]['props']> {\n // @ts-ignore\n return this.__services[service]().props();\n }\n\n /**\n * Init the given service and bind it to the given instance.\n *\n * @param {ServiceNames} service The name of the service.\n * @returns {() => void} A function to unbind the service.\n */\n enable(service: ServiceNames): () => void {\n if (this.has(service)) {\n return this.disable.bind(this, service);\n }\n\n if (\n // @ts-ignore\n !(isFunction(this.__base[service]) || this.__base.__hasEvent(service)) ||\n !this.__services[service]\n ) {\n return noop;\n }\n const serviceInstance = this.__services[service]();\n\n serviceInstance.add(this.__base.$id, (...args) => this.__base.__callMethod(service, ...args));\n\n return this.disable.bind(this, service);\n }\n\n /**\n * Enable all services and return methods to disable them.\n */\n enableAll() {\n return Object.keys(this.__services).map((serviceName) => this.enable(serviceName));\n }\n\n /**\n * Disable all services.\n *\n * @returns {void}\n */\n disableAll() {\n for (const serviceName of Object.keys(this.__services)) {\n this.disable(serviceName);\n }\n }\n\n /**\n * Disable a service.\n */\n disable(service: ServiceNames) {\n if (!this.__services[service]) {\n return;\n }\n\n const { remove } = this.__services[service]();\n remove(this.__base.$id);\n }\n\n /**\n * Toggle a service.\n */\n toggle(service: ServiceNames, force?: boolean) {\n if (isDefined(force)) {\n if (force && !this.has(service)) {\n this.enable(service);\n }\n\n if (!force && this.has(service)) {\n this.disable(service);\n }\n } else if (this.has(service)) {\n this.disable(service);\n } else {\n this.enable(service);\n }\n }\n\n /**\n * Register a new service to be enabled/disabled.\n *\n * @param {string} name\n * The name of the service hook.\n * @param {<T>(...args:unknown[]) => ServiceInterface<T>} useFunction\n * The `use...` function for the service.\n */\n register(name: string, useFunction: <T>(...args: unknown[]) => ServiceInterface<T>) {\n this.__customServices[name] = useFunction;\n this.__base.__addEmits(name);\n }\n\n /**\n * Unregister a new service to be enabled disabled.\n *\n * @param {string} name\n * The name of the service hook.\n */\n unregister(name: string) {\n if (SERVICE_NAMES.includes(name)) {\n if (isDev) {\n throw new Error(`[ServicesManager] The \\`${name}\\` core service can not be unregistered.`);\n }\n return;\n }\n\n this.__base.__removeEmits(name);\n delete this.__customServices[name];\n }\n}\n"],
5
- "mappings": "AAAA,SAAS,YAAY,QAAQ,WAAW,WAAW,cAAc;AASjE,SAAS,uBAAuB;AAChC,SAAS,MAAM,YAAY,WAAW,aAAa;AAEnD,MAAM,eAAe;AAAA,EACnB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AACT;AAEA,MAAM,gBAAgB,OAAO,KAAK,YAAY;AAiBvC,MAAM,wBAAwB,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAInD,mBAAi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UAAU,GAAG;AACtD,WAAK,QAAQ,WAAW;AAAA,IAC1B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ,SAAuB;AAC7B,QAAI,CAAC,KAAK,WAAW,OAAO,GAAG;AAC7B;AAAA,IACF;AAEA,UAAM,EAAE,OAAO,IAAI,KAAK,WAAW,OAAO,EAAE;AAC5C,WAAO,KAAK,OAAO,GAAG;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,SAAuB,OAAiB;AAC7C,QAAI,UAAU,KAAK,GAAG;AACpB,UAAI,SAAS,CAAC,KAAK,IAAI,OAAO,GAAG;AAC/B,aAAK,OAAO,OAAO;AAAA,MACrB;AAEA,UAAI,CAAC,SAAS,KAAK,IAAI,OAAO,GAAG;AAC/B,aAAK,QAAQ,OAAO;AAAA,MACtB;AAAA,IACF,WAAW,KAAK,IAAI,OAAO,GAAG;AAC5B,WAAK,QAAQ,OAAO;AAAA,IACtB,OAAO;AACL,WAAK,OAAO,OAAO;AAAA,IACrB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,SAAS,MAAc,aAA6D;AAClF,SAAK,iBAAiB,IAAI,IAAI;AAC9B,SAAK,OAAO,WAAW,IAAI;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,WAAW,MAAc;AACvB,QAAI,cAAc,SAAS,IAAI,GAAG;AAChC,UAAI,OAAO;AACT,cAAM,IAAI,MAAM,2BAA2B,IAAI,0CAA0C;AAAA,MAC3F;AACA;AAAA,IACF;AAEA,SAAK,OAAO,cAAc,IAAI;AAC9B,WAAO,KAAK,iBAAiB,IAAI;AAAA,EACnC;AACF;",
4
+ "sourcesContent": ["import { usePointer, useRaf, useResize, useScroll, useKey } from '../../services/index.js';\nimport type {\n PointerServiceInterface,\n RafServiceInterface,\n ResizeServiceInterface,\n ScrollServiceInterface,\n KeyServiceInterface,\n ServiceInterface,\n} from '../../services/index.js';\nimport { AbstractManager } from './AbstractManager.js';\nimport { noop, isFunction, isDefined, isDev } from '../../utils/index.js';\n\nconst SERVICES_MAP = {\n scrolled: useScroll,\n resized: useResize,\n ticked: useRaf,\n moved: usePointer,\n keyed: useKey,\n};\n\nconst SERVICE_NAMES = Object.keys(SERVICES_MAP);\n\ntype Services = {\n scrolled: ScrollServiceInterface;\n resized: ResizeServiceInterface;\n ticked: RafServiceInterface;\n moved: PointerServiceInterface;\n keyed: KeyServiceInterface;\n} & Record<string, ServiceInterface<unknown>>;\n\ntype ServiceProps = typeof SERVICES_MAP & Record<string, <T>() => ServiceInterface<T>>;\n\ntype ServiceNames = keyof Services;\n\n/**\n * Services management for the Base class.\n *\n * @todo Add support for disabled services on mount when the method is defined.\n */\nexport class ServicesManager extends AbstractManager<ServiceProps> {\n /**\n * Custom props\n * @private\n */\n __props = {\n ...SERVICES_MAP,\n } as ServiceProps;\n\n /**\n * Test if the given service is registered.\n */\n has(service: ServiceNames | string): boolean {\n if (\n !(\n (isFunction(this.__base[service]) ||\n // @ts-ignore\n this.__base.__hasEvent(service)) &&\n this.props[service]\n )\n ) {\n return false;\n }\n\n const { has } = this.props[service]();\n return has(this.__base.$id);\n }\n\n /**\n * Get a service props by name.\n */\n get<S extends ServiceNames | string>(service: S): ReturnType<Services[S]['props']> {\n // @ts-ignore\n return this.props[service]().props();\n }\n\n /**\n * Init the given service and bind it to the given instance.\n *\n * @param {ServiceNames} service The name of the service.\n * @returns {() => void} A function to unbind the service.\n */\n enable(service: ServiceNames): () => void {\n if (this.has(service)) {\n return this.disable.bind(this, service);\n }\n\n if (\n // @ts-ignore\n !(isFunction(this.__base[service]) || this.__base.__hasEvent(service)) ||\n !this.props[service]\n ) {\n return noop;\n }\n const serviceInstance = this.props[service]();\n\n serviceInstance.add(this.__base.$id, (...args) => this.__base.__callMethod(service, ...args));\n\n return this.disable.bind(this, service);\n }\n\n /**\n * Enable all services and return methods to disable them.\n */\n enableAll() {\n return Object.keys(this.props).map((serviceName) => this.enable(serviceName));\n }\n\n /**\n * Disable all services.\n *\n * @returns {void}\n */\n disableAll() {\n for (const serviceName of Object.keys(this.props)) {\n this.disable(serviceName);\n }\n }\n\n /**\n * Disable a service.\n */\n disable(service: ServiceNames) {\n if (!this.props[service]) {\n return;\n }\n\n const { remove } = this.props[service]();\n remove(this.__base.$id);\n }\n\n /**\n * Toggle a service.\n */\n toggle(service: ServiceNames, force?: boolean) {\n if (isDefined(force)) {\n if (force && !this.has(service)) {\n this.enable(service);\n }\n\n if (!force && this.has(service)) {\n this.disable(service);\n }\n } else if (this.has(service)) {\n this.disable(service);\n } else {\n this.enable(service);\n }\n }\n\n /**\n * Register a new service to be enabled/disabled.\n *\n * @param {string} name\n * The name of the service hook.\n * @param {<T>(...args:unknown[]) => ServiceInterface<T>} useFunction\n * The `use...` function for the service.\n */\n register(name: string, useFunction: <T>(...args: unknown[]) => ServiceInterface<T>) {\n this.props[name] = useFunction;\n this.__base.__addEmits(name);\n }\n\n /**\n * Unregister a new service to be enabled disabled.\n *\n * @param {string} name\n * The name of the service hook.\n */\n unregister(name: string) {\n if (SERVICE_NAMES.includes(name)) {\n if (isDev) {\n throw new Error(`[ServicesManager] The \\`${name}\\` core service can not be unregistered.`);\n }\n return;\n }\n\n this.__base.__removeEmits(name);\n delete this.props[name];\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,YAAY,QAAQ,WAAW,WAAW,cAAc;AASjE,SAAS,uBAAuB;AAChC,SAAS,MAAM,YAAY,WAAW,aAAa;AAEnD,MAAM,eAAe;AAAA,EACnB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AACT;AAEA,MAAM,gBAAgB,OAAO,KAAK,YAAY;AAmBvC,MAAM,wBAAwB,gBAA8B;AAAA;AAAA;AAAA;AAAA;AAAA,EAKjE,UAAU;AAAA,IACR,GAAG;AAAA,EACL;AAAA;AAAA;AAAA;AAAA,EAKA,I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AAAA,IACF;AAEA,UAAM,EAAE,OAAO,IAAI,KAAK,MAAM,OAAO,EAAE;AACvC,WAAO,KAAK,OAAO,GAAG;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,SAAuB,OAAiB;AAC7C,QAAI,UAAU,KAAK,GAAG;AACpB,UAAI,SAAS,CAAC,KAAK,IAAI,OAAO,GAAG;AAC/B,aAAK,OAAO,OAAO;AAAA,MACrB;AAEA,UAAI,CAAC,SAAS,KAAK,IAAI,OAAO,GAAG;AAC/B,aAAK,QAAQ,OAAO;AAAA,MACtB;AAAA,IACF,WAAW,KAAK,IAAI,OAAO,GAAG;AAC5B,WAAK,QAAQ,OAAO;AAAA,IACtB,OAAO;AACL,WAAK,OAAO,OAAO;AAAA,IACrB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,SAAS,MAAc,aAA6D;AAClF,SAAK,MAAM,IAAI,IAAI;AACnB,SAAK,OAAO,WAAW,IAAI;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,WAAW,MAAc;AACvB,QAAI,cAAc,SAAS,IAAI,GAAG;AAChC,UAAI,OAAO;AACT,cAAM,IAAI,MAAM,2BAA2B,IAAI,0CAA0C;AAAA,MAC3F;AACA;AAAA,IACF;AAEA,SAAK,OAAO,cAAc,IAAI;AAC9B,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB;AACF;",
6
6
  "names": []
7
7
  }
package/Base/utils.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../packages/js-toolkit/Base/utils.ts"],
4
- "sourcesContent": ["import { isArray, isDefined, SmartQueue, dashCase } from '../utils/index.js';\nimport type { Base, BaseConfig, BaseConstructor } from './index.js';\nimport { features } from './features.js';\n\nlet queue: SmartQueue;\n\n/**\n * Add a task to the main queue.\n */\nexport function addToQueue(fn: () => unknown) {\n if (features.get('blocking')) {\n fn();\n return;\n }\n\n if (!queue) {\n queue = new SmartQueue();\n }\n\n return queue.add(fn);\n}\n\nconst selectors = new Map();\n\n// Separator used for multi-component declaration in `data-component` attributeS.\nconst separator = ' ';\n\n/**\n * Get the selector for a given component.\n */\nexport function getSelector(nameOrSelector: string): string {\n const { component } = features.get('attributes');\n const prefix = features.get('prefix');\n const key = prefix + component + nameOrSelector;\n\n if (!selectors.has(key)) {\n const parts = [\n // Tag select\n `${prefix}-${dashCase(nameOrSelector)}`,\n // Single selector\n `[${component}=\"${nameOrSelector}\"]`,\n // Selector in the middle of a list of selectors\n `[${component}*=\"${separator}${nameOrSelector}${separator}\"]`,\n // Selector at the end of a list of selectors\n `[${component}$=\"${separator}${nameOrSelector}\"]`,\n // Selector at the beginning of a list of selectors\n `[${component}^=\"${nameOrSelector}${separator}\"]`,\n ];\n selectors.set(key, parts.join(','));\n }\n\n return selectors.get(key);\n}\n\n/**\n * Get a list of elements based on the name of a component.\n *\n * @param {string} nameOrSelector\n * The name or selector to used for this component.\n * @param {HTMLElement|Document} element\n * The root element on which to query the selector, defaults to `document`.\n * @returns {Array<HTMLElement>}\n * A list of elements on which the component should be mounted.\n */\nexport function getComponentElements(\n nameOrSelector: string,\n element: HTMLElement | Document = document,\n): HTMLElement[] {\n const selector = getSelector(nameOrSelector);\n let elements = [];\n\n try {\n elements = Array.from(element.querySelectorAll(selector));\n // eslint-disable-next-line no-empty\n } catch {}\n\n // If no child component found with the default selector, and if the selector does not\n // start with an uppercase letter, matching a component's name, try a classic DOM selector.\n if (elements.length === 0 && nameOrSelector[0] === nameOrSelector[0].toLowerCase()) {\n elements = Array.from(element.querySelectorAll(nameOrSelector));\n }\n\n return elements;\n}\n\n/**\n * Test if an event is defined in the given config.\n */\nexport function eventIsDefinedInConfig(event: string, config: BaseConfig): boolean {\n return isArray(config.emits) && config.emits.includes(event);\n}\n\n/**\n * Test if an event can be used on the given element.\n */\nexport function eventIsNative(event: string, element: HTMLElement): boolean {\n return isDefined(element[`on${event}`]);\n}\n\n/**\n * Get the target of a given event.\n */\nexport function getEventTarget(\n instance: Base,\n event: string,\n config: BaseConfig,\n): Base['$el'] {\n if (eventIsDefinedInConfig(event, config) || eventIsNative(event, instance.$el)) {\n return instance.$el;\n }\n}\n\nconst instances = new Set<Base>();\n\n/**\n * Get all mounted instances or the ones from a given component.\n */\nexport function getInstances(): Set<Base>;\nexport function getInstances<T extends BaseConstructor = BaseConstructor>(\n ctor: T,\n): Set<InstanceType<T>>;\nexport function getInstances<T extends BaseConstructor = BaseConstructor>(\n ctor?: T,\n): Set<InstanceType<T>> | Set<Base> {\n if (isDefined(ctor)) {\n const filteredInstances = new Set<InstanceType<T>>();\n for (const instance of instances) {\n if (instance instanceof ctor) {\n filteredInstances.add(instance as InstanceType<T>);\n }\n }\n return filteredInstances;\n } else {\n return new Set(instances);\n }\n}\n\nexport function addInstance(instance: Base) {\n instances.add(instance);\n}\n\nexport function deleteInstance(instance: Base) {\n instances.delete(instance);\n}\n"],
5
- "mappings": "AAAA,SAAS,SAAS,WAAW,YAAY,gBAAgB;AAEzD,SAAS,gBAAgB;AAEzB,IAAI;AAKG,SAAS,WAAW,IAAmB;AAC5C,MAAI,SAAS,IAAI,UAAU,GAAG;AAC5B,OAAG;AACH;AAAA,EACF;AAEA,MAAI,CAAC,OAAO;AACV,YAAQ,IAAI,WAAW;AAAA,EACzB;AAEA,SAAO,MAAM,IAAI,EAAE;AACrB;AAEA,MAAM,YAAY,oBAAI,IAAI;AAG1B,MAAM,YAAY;AAKX,SAAS,YAAY,gBAAgC;AAC1D,QAAM,EAAE,UAAU,IAAI,SAAS,IAAI,YAAY;AAC/C,QAAM,SAAS,SAAS,IAAI,QAAQ;AACpC,QAAM,MAAM,SAAS,YAAY;AAEjC,MAAI,CAAC,UAAU,IAAI,GAAG,GAAG;AACvB,UAAM,QAAQ;AAAA;AAAA,MAEZ,GAAG,MAAM,IAAI,SAAS,cAAc,CAAC;AAAA;AAAA,MAErC,IAAI,SAAS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,IAAI,IAAI,SAAS;AAAA,EAC1B;AACF;AAEO,SAAS,YAAY,UAAgB;AAC1C,YAAU,IAAI,QAAQ;AACxB;AAEO,SAAS,eAAe,UAAgB;AAC7C,YAAU,OAAO,QAAQ;AAC3B;",
4
+ "sourcesContent": ["import { isArray, isDefined, SmartQueue, dashCase } from '../utils/index.js';\nimport type { Base, BaseConfig, BaseConstructor } from './index.js';\nimport { features } from './features.js';\n\nlet queue: SmartQueue;\n\n/**\n * Add a task to the main queue.\n */\nexport function addToQueue(fn: () => unknown) {\n if (features.get('blocking')) {\n fn();\n return;\n }\n\n if (!queue) {\n queue = new SmartQueue();\n }\n\n return queue.add(fn);\n}\n\nconst selectors = new Map();\n\n// Separator used for multi-component declaration in `data-component` attributeS.\nconst separator = ' ';\n\n/**\n * Get the selector for a given component.\n */\nexport function getSelector(nameOrSelector: string): string {\n const { component } = features.get('attributes');\n const prefix = features.get('prefix');\n const key = prefix + component + nameOrSelector;\n\n if (!selectors.has(key)) {\n const parts = [\n // Tag select\n `${prefix}-${dashCase(nameOrSelector)}`,\n // Single selector\n `[${component}=\"${nameOrSelector}\"]`,\n // Selector in the middle of a list of selectors\n `[${component}*=\"${separator}${nameOrSelector}${separator}\"]`,\n // Selector at the end of a list of selectors\n `[${component}$=\"${separator}${nameOrSelector}\"]`,\n // Selector at the beginning of a list of selectors\n `[${component}^=\"${nameOrSelector}${separator}\"]`,\n ];\n selectors.set(key, parts.join(','));\n }\n\n return selectors.get(key);\n}\n\n/**\n * Get a list of elements based on the name of a component.\n *\n * @param {string} nameOrSelector\n * The name or selector to used for this component.\n * @param {HTMLElement|Document} element\n * The root element on which to query the selector, defaults to `document`.\n * @returns {Array<HTMLElement>}\n * A list of elements on which the component should be mounted.\n */\nexport function getComponentElements(\n nameOrSelector: string,\n element: HTMLElement | Document = document,\n): HTMLElement[] {\n const selector = getSelector(nameOrSelector);\n let elements = [];\n\n try {\n elements = Array.from(element.querySelectorAll(selector));\n // eslint-disable-next-line no-empty\n } catch {}\n\n // If no child component found with the default selector, and if the selector does not\n // start with an uppercase letter, matching a component's name, try a classic DOM selector.\n if (elements.length === 0 && nameOrSelector[0] === nameOrSelector[0].toLowerCase()) {\n elements = Array.from(element.querySelectorAll(nameOrSelector));\n }\n\n return elements;\n}\n\n/**\n * Test if an event is defined in the given config.\n */\nexport function eventIsDefinedInConfig(event: string, config: BaseConfig): boolean {\n return isArray(config.emits) && config.emits.includes(event);\n}\n\n/**\n * Test if an event can be used on the given element.\n */\nexport function eventIsNative(event: string, element: HTMLElement): boolean {\n return isDefined(element[`on${event}`]);\n}\n\n/**\n * Get the target of a given event.\n */\nexport function getEventTarget(instance: Base, event: string, config: BaseConfig): Base['$el'] {\n if (eventIsDefinedInConfig(event, config) || eventIsNative(event, instance.$el)) {\n return instance.$el;\n }\n}\n\nconst instances = new Set<Base>();\n\n/**\n * Get all mounted instances or the ones from a given component.\n */\nexport function getInstances(): Set<Base>;\nexport function getInstances<T extends BaseConstructor = BaseConstructor>(\n ctor: T,\n): Set<InstanceType<T>>;\nexport function getInstances<T extends BaseConstructor = BaseConstructor>(\n ctor?: T,\n): Set<InstanceType<T>> | Set<Base> {\n if (isDefined(ctor)) {\n const filteredInstances = new Set<InstanceType<T>>();\n for (const instance of instances) {\n if (instance instanceof ctor) {\n filteredInstances.add(instance as InstanceType<T>);\n }\n }\n return filteredInstances;\n } else {\n return new Set(instances);\n }\n}\n\nexport function addInstance(instance: Base) {\n instances.add(instance);\n}\n\nexport function deleteInstance(instance: Base) {\n instances.delete(instance);\n}\n"],
5
+ "mappings": "AAAA,SAAS,SAAS,WAAW,YAAY,gBAAgB;AAEzD,SAAS,gBAAgB;AAEzB,IAAI;AAKG,SAAS,WAAW,IAAmB;AAC5C,MAAI,SAAS,IAAI,UAAU,GAAG;AAC5B,OAAG;AACH;AAAA,EACF;AAEA,MAAI,CAAC,OAAO;AACV,YAAQ,IAAI,WAAW;AAAA,EACzB;AAEA,SAAO,MAAM,IAAI,EAAE;AACrB;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uBAAuB,OAAO,MAAM,KAAK,cAAc,OAAO,SAAS,GAAG,GAAG;AAC/E,WAAO,SAAS;AAAA,EAClB;AACF;AAEA,MAAM,YAAY,oBAAI,IAAU;AASzB,SAAS,aACd,MACkC;AAClC,MAAI,UAAU,IAAI,GAAG;AACnB,UAAM,oBAAoB,oBAAI,IAAqB;AACnD,eAAW,YAAY,WAAW;AAChC,UAAI,oBAAoB,MAAM;AAC5B,0BAAkB,IAAI,QAA2B;AAAA,MACnD;AAAA,IACF;AACA,WAAO;AAAA,EACT,OAAO;AACL,WAAO,IAAI,IAAI,SAAS;AAAA,EAC1B;AACF;AAEO,SAAS,YAAY,UAAgB;AAC1C,YAAU,IAAI,QAAQ;AACxB;AAEO,SAAS,eAAe,UAAgB;AAC7C,YAAU,OAAO,QAAQ;AAC3B;",
6
6
  "names": []
7
7
  }
@@ -7,6 +7,7 @@ export * from './withIntersectionObserver.js';
7
7
  export * from './withMountOnMediaQuery.js';
8
8
  export * from './withMountWhenInView.js';
9
9
  export * from './withMountWhenPrefersMotion.js';
10
+ export * from './withMutation.js';
10
11
  export * from './withName.js';
11
12
  export * from './withRelativePointer.js';
12
13
  export * from './withResponsiveOptions.js';
@@ -7,6 +7,7 @@ export * from "./withIntersectionObserver.js";
7
7
  export * from "./withMountOnMediaQuery.js";
8
8
  export * from "./withMountWhenInView.js";
9
9
  export * from "./withMountWhenPrefersMotion.js";
10
+ export * from "./withMutation.js";
10
11
  export * from "./withName.js";
11
12
  export * from "./withRelativePointer.js";
12
13
  export * from "./withResponsiveOptions.js";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../packages/js-toolkit/decorators/index.ts"],
4
- "sourcesContent": ["export * from './withBreakpointManager.js';\nexport * from './withBreakpointObserver.js';\nexport * from './withDrag.js';\nexport * from './withExtraConfig.js';\nexport * from './withFreezedOptions.js';\nexport * from './withIntersectionObserver.js';\nexport * from './withMountOnMediaQuery.js';\nexport * from './withMountWhenInView.js';\nexport * from './withMountWhenPrefersMotion.js';\nexport * from './withName.js';\nexport * from './withRelativePointer.js';\nexport * from './withResponsiveOptions.js';\nexport * from './withScrolledInView/index.js';\n"],
5
- "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
4
+ "sourcesContent": ["export * from './withBreakpointManager.js';\nexport * from './withBreakpointObserver.js';\nexport * from './withDrag.js';\nexport * from './withExtraConfig.js';\nexport * from './withFreezedOptions.js';\nexport * from './withIntersectionObserver.js';\nexport * from './withMountOnMediaQuery.js';\nexport * from './withMountWhenInView.js';\nexport * from './withMountWhenPrefersMotion.js';\nexport * from './withMutation.js';\nexport * from './withName.js';\nexport * from './withRelativePointer.js';\nexport * from './withResponsiveOptions.js';\nexport * from './withScrolledInView/index.js';\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
@@ -50,9 +50,7 @@ function withBreakpointObserver(BaseClass) {
50
50
  */
51
51
  static config = {
52
52
  ...BaseClass.config,
53
- name: `${BaseClass.config.name}WithBreakpointObserver`,
54
53
  options: {
55
- ...BaseClass.config?.options,
56
54
  activeBreakpoints: String,
57
55
  inactiveBreakpoints: String
58
56
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../packages/js-toolkit/decorators/withBreakpointObserver.ts"],
4
- "sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { useResize } from '../services/index.js';\nimport type { ResizeServiceProps } from '../services/index.js';\nimport { isDev, startsWith } from '../utils/index.js';\nimport { features } from '../Base/features.js';\n\nexport interface WithBreakpointObserverProps extends BaseProps {\n $options: {\n activeBreakpoints?: string;\n inactiveBreakpoints?: string;\n };\n}\n\nexport interface WithBreakpointObserverInterface extends BaseInterface {}\n\n/**\n * Test the breakpoins of the given Base instance and return the hook to call.\n *\n * @param {Base<WithBreakpointObserverProps>} instance The component's instance.\n * @param {string} [breakpoint] The breakpoint to test.\n * @returns {string} The action to trigger.\n */\nfunction testBreakpoints(\n instance: Base<WithBreakpointObserverProps>,\n breakpoint: string = useResize().props().breakpoint,\n): string {\n const { activeBreakpoints, inactiveBreakpoints } = instance.$options;\n const isInActiveBreakpoint =\n activeBreakpoints && activeBreakpoints.split(' ').includes(breakpoint);\n const isInInactiveBreakpoint =\n inactiveBreakpoints && inactiveBreakpoints.split(' ').includes(breakpoint);\n\n if (\n (activeBreakpoints && isInActiveBreakpoint) ||\n (inactiveBreakpoints && !isInInactiveBreakpoint)\n ) {\n return '$mount';\n }\n\n return '$destroy';\n}\n\n/**\n * Test if the given instance is configured for breakpoints.\n *\n * @param {Base<WithBreakpointObserverProps>} instance A Base class instance.\n * @returns {boolean} True if configured correctly, false otherwise.\n */\nfunction hasBreakpointConfiguration(instance: Base<WithBreakpointObserverProps>): boolean {\n const { activeBreakpoints, inactiveBreakpoints } = instance.$options;\n return Boolean(activeBreakpoints || inactiveBreakpoints);\n}\n\n/**\n * Test if the given instance has a conflicting configuration for breakpoints.\n *\n * @param {Base<WithBreakpointObserverProps>} instance A Base class instance.\n * @returns {void}\n */\nfunction testConflictingBreakpointConfiguration(instance: Base<WithBreakpointObserverProps>): void {\n const { activeBreakpoints, inactiveBreakpoints, name } = instance.$options;\n if (activeBreakpoints && inactiveBreakpoints) {\n throw new Error(\n `[${name}] Incorrect configuration: the \\`activeBreakpoints\\` and \\`inactiveBreakpoints\\` are not compatible.`,\n );\n }\n}\n\n/**\n * Callback triggered when the window is resized.\n */\nfunction createResizeCallback(\n instance: Base<WithBreakpointObserverProps>,\n): (resizeProps: ResizeServiceProps) => void {\n return ({ breakpoint }) => {\n const action = testBreakpoints(instance, breakpoint);\n\n // Always destroy before mounting\n if (action === '$destroy' && instance.$isMounted) {\n instance[action]();\n } else if (action === '$mount' && !instance.$isMounted) {\n setTimeout(() => instance[action](), 0);\n }\n };\n}\n\n/**\n * Add the current instance to the resize service.\n *\n * @param {string} key The key for the resize service callback.\n * @param {Base} instance The instance to observe.\n */\nfunction addToResize(key, instance) {\n if (isDev) {\n testConflictingBreakpointConfiguration(instance);\n }\n\n const { add, has, props } = useResize();\n\n if (!has(key)) {\n const callback = createResizeCallback(instance);\n add(key, callback);\n callback(props());\n }\n}\n\n/**\n * BreakpointObserver class.\n */\nexport function withBreakpointObserver<S extends Base>(\n BaseClass: typeof Base,\n): BaseDecorator<WithBreakpointObserverInterface, S, WithBreakpointObserverProps> {\n /**\n * Class.\n */\n class WithBreakpointObserver<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithBreakpointObserverProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}WithBreakpointObserver`,\n options: {\n ...BaseClass.config?.options,\n activeBreakpoints: String,\n inactiveBreakpoints: String,\n },\n };\n\n /**\n * Watch for the document resize to test the breakpoints.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const { remove, props } = useResize();\n const { name } = this.$options;\n\n // Do nothing if no breakpoint has been defined.\n // @see https://js-toolkit.meta.fr/services/resize.html#breakpoint\n if (!props().breakpoint) {\n if (isDev) {\n throw new Error(\n `[${name}] The \\`BreakpointObserver\\` class requires breakpoints to be defined.`,\n );\n }\n return;\n }\n\n const key = `BreakpointObserver-${this.$id}`;\n const attributes = features.get('attributes');\n\n // Watch change on the `data-options` attribute to emit the `set:options` event.\n const mutationObserver = new MutationObserver(([mutation]) => {\n if (\n mutation.type === 'attributes' &&\n startsWith(mutation.attributeName, `${attributes.option}-`)\n ) {\n // Stop here silently when no breakpoint configuration given.\n if (!hasBreakpointConfiguration(this)) {\n this.$mount();\n remove(key);\n return;\n }\n\n addToResize(key, this);\n }\n });\n mutationObserver.observe(this.$el, { attributes: true });\n\n // Stop here silently when no breakpoint configuration given.\n if (!hasBreakpointConfiguration(this)) {\n return;\n }\n\n addToResize(key, this);\n }\n\n /**\n * Override the default $mount method to prevent component's from being\n * mounted when they should not.\n */\n async $mount() {\n // Execute normal behavior when no breakpoint configuration given.\n if (!hasBreakpointConfiguration(this)) {\n return super.$mount();\n }\n\n const action = testBreakpoints(this);\n if (action === '$mount') {\n return super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithBreakpointObserver;\n}\n"],
5
- "mappings": "AAEA,SAAS,iBAAiB;AAE1B,SAAS,OAAO,kBAAkB;AAClC,SAAS,gBAAgB;AAkBzB,SAAS,gBACP,UACA,aAAqB,UAAU,EAAE,MAAM,EAAE,YACjC;AACR,QAAM,EAAE,mBAAmB,oBAAoB,IAAI,SAAS;AAC5D,QAAM,uBACJ,qBAAqB,kBAAkB,MAAM,GAAG,EAAE,SAAS,UAAU;AACvE,QAAM,yBACJ,uBAAuB,oBAAoB,MAAM,GAAG,EAAE,SAAS,UAAU;AAE3E,MACG,qBAAqB,wBACrB,uBAAuB,CAAC,wBACzB;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAQA,SAAS,2BAA2B,UAAsD;AACxF,QAAM,EAAE,mBAAmB,oBAAoB,IAAI,SAAS;AAC5D,SAAO,QAAQ,qBAAqB,mBAAmB;AACzD;AAQA,SAAS,uCAAuC,UAAmD;AACjG,QAAM,EAAE,mBAAmB,qBAAqB,KAAK,IAAI,SAAS;AAClE,MAAI,qBAAqB,qBAAqB;AAC5C,UAAM,IAAI;AAAA,MACR,IAAI,IAAI;AAAA,IACV;AAAA,EACF;AACF;AAKA,SAAS,qBACP,UAC2C;AAC3C,SAAO,CAAC,EAAE,WAAW,MAAM;AACzB,UAAM,SAAS,gBAAgB,UAAU,UAAU;AAGnD,QAAI,WAAW,cAA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I,GAAG;AACrC,iBAAK,OAAO;AACZ,mBAAO,GAAG;AACV;AAAA,UACF;AAEA,sBAAY,KAAK,IAAI;AAAA,QACvB;AAAA,MACF,CAAC;AACD,uBAAiB,QAAQ,KAAK,KAAK,EAAE,YAAY,KAAK,CAAC;AAGvD,UAAI,CAAC,2BAA2B,IAAI,GAAG;AACrC;AAAA,MACF;AAEA,kBAAY,KAAK,IAAI;AAAA,IACvB;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,MAAM,SAAS;AAEb,UAAI,CAAC,2BAA2B,IAAI,GAAG;AACrC,eAAO,MAAM,OAAO;AAAA,MACtB;AAEA,YAAM,SAAS,gBAAgB,IAAI;AACnC,UAAI,WAAW,UAAU;AACvB,eAAO,MAAM,OAAO;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
4
+ "sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { useResize } from '../services/index.js';\nimport type { ResizeServiceProps } from '../services/index.js';\nimport { isDev, startsWith } from '../utils/index.js';\nimport { features } from '../Base/features.js';\n\nexport interface WithBreakpointObserverProps extends BaseProps {\n $options: {\n activeBreakpoints?: string;\n inactiveBreakpoints?: string;\n };\n}\n\nexport interface WithBreakpointObserverInterface extends BaseInterface {}\n\n/**\n * Test the breakpoins of the given Base instance and return the hook to call.\n *\n * @param {Base<WithBreakpointObserverProps>} instance The component's instance.\n * @param {string} [breakpoint] The breakpoint to test.\n * @returns {string} The action to trigger.\n */\nfunction testBreakpoints(\n instance: Base<WithBreakpointObserverProps>,\n breakpoint: string = useResize().props().breakpoint,\n): string {\n const { activeBreakpoints, inactiveBreakpoints } = instance.$options;\n const isInActiveBreakpoint =\n activeBreakpoints && activeBreakpoints.split(' ').includes(breakpoint);\n const isInInactiveBreakpoint =\n inactiveBreakpoints && inactiveBreakpoints.split(' ').includes(breakpoint);\n\n if (\n (activeBreakpoints && isInActiveBreakpoint) ||\n (inactiveBreakpoints && !isInInactiveBreakpoint)\n ) {\n return '$mount';\n }\n\n return '$destroy';\n}\n\n/**\n * Test if the given instance is configured for breakpoints.\n *\n * @param {Base<WithBreakpointObserverProps>} instance A Base class instance.\n * @returns {boolean} True if configured correctly, false otherwise.\n */\nfunction hasBreakpointConfiguration(instance: Base<WithBreakpointObserverProps>): boolean {\n const { activeBreakpoints, inactiveBreakpoints } = instance.$options;\n return Boolean(activeBreakpoints || inactiveBreakpoints);\n}\n\n/**\n * Test if the given instance has a conflicting configuration for breakpoints.\n *\n * @param {Base<WithBreakpointObserverProps>} instance A Base class instance.\n * @returns {void}\n */\nfunction testConflictingBreakpointConfiguration(instance: Base<WithBreakpointObserverProps>): void {\n const { activeBreakpoints, inactiveBreakpoints, name } = instance.$options;\n if (activeBreakpoints && inactiveBreakpoints) {\n throw new Error(\n `[${name}] Incorrect configuration: the \\`activeBreakpoints\\` and \\`inactiveBreakpoints\\` are not compatible.`,\n );\n }\n}\n\n/**\n * Callback triggered when the window is resized.\n */\nfunction createResizeCallback(\n instance: Base<WithBreakpointObserverProps>,\n): (resizeProps: ResizeServiceProps) => void {\n return ({ breakpoint }) => {\n const action = testBreakpoints(instance, breakpoint);\n\n // Always destroy before mounting\n if (action === '$destroy' && instance.$isMounted) {\n instance[action]();\n } else if (action === '$mount' && !instance.$isMounted) {\n setTimeout(() => instance[action](), 0);\n }\n };\n}\n\n/**\n * Add the current instance to the resize service.\n *\n * @param {string} key The key for the resize service callback.\n * @param {Base} instance The instance to observe.\n */\nfunction addToResize(key, instance) {\n if (isDev) {\n testConflictingBreakpointConfiguration(instance);\n }\n\n const { add, has, props } = useResize();\n\n if (!has(key)) {\n const callback = createResizeCallback(instance);\n add(key, callback);\n callback(props());\n }\n}\n\n/**\n * BreakpointObserver class.\n */\nexport function withBreakpointObserver<S extends Base>(\n BaseClass: typeof Base,\n): BaseDecorator<WithBreakpointObserverInterface, S, WithBreakpointObserverProps> {\n /**\n * Class.\n */\n class WithBreakpointObserver<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithBreakpointObserverProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n options: {\n activeBreakpoints: String,\n inactiveBreakpoints: String,\n },\n };\n\n /**\n * Watch for the document resize to test the breakpoints.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const { remove, props } = useResize();\n const { name } = this.$options;\n\n // Do nothing if no breakpoint has been defined.\n // @see https://js-toolkit.meta.fr/services/resize.html#breakpoint\n if (!props().breakpoint) {\n if (isDev) {\n throw new Error(\n `[${name}] The \\`BreakpointObserver\\` class requires breakpoints to be defined.`,\n );\n }\n return;\n }\n\n const key = `BreakpointObserver-${this.$id}`;\n const attributes = features.get('attributes');\n\n // Watch change on the `data-options` attribute to emit the `set:options` event.\n const mutationObserver = new MutationObserver(([mutation]) => {\n if (\n mutation.type === 'attributes' &&\n startsWith(mutation.attributeName, `${attributes.option}-`)\n ) {\n // Stop here silently when no breakpoint configuration given.\n if (!hasBreakpointConfiguration(this)) {\n this.$mount();\n remove(key);\n return;\n }\n\n addToResize(key, this);\n }\n });\n mutationObserver.observe(this.$el, { attributes: true });\n\n // Stop here silently when no breakpoint configuration given.\n if (!hasBreakpointConfiguration(this)) {\n return;\n }\n\n addToResize(key, this);\n }\n\n /**\n * Override the default $mount method to prevent component's from being\n * mounted when they should not.\n */\n async $mount() {\n // Execute normal behavior when no breakpoint configuration given.\n if (!hasBreakpointConfiguration(this)) {\n return super.$mount();\n }\n\n const action = testBreakpoints(this);\n if (action === '$mount') {\n return super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithBreakpointObserver;\n}\n"],
5
+ "mappings": "AAEA,SAAS,iBAAiB;AAE1B,SAAS,OAAO,kBAAkB;AAClC,SAAS,gBAAgB;AAkBzB,SAAS,gBACP,UACA,aAAqB,UAAU,EAAE,MAAM,EAAE,YACjC;AACR,QAAM,EAAE,mBAAmB,oBAAoB,IA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ACP,mBAAmB;AAAA,QACnB,qBAAqB;AAAA,MACvB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,YAAM,EAAE,QAAQ,MAAM,IAAI,UAAU;AACpC,YAAM,EAAE,KAAK,IAAI,KAAK;AAItB,UAAI,CAAC,MAAM,EAAE,YAAY;AACvB,YAAI,OAAO;AACT,gBAAM,IAAI;AAAA,YACR,IAAI,IAAI;AAAA,UACV;AAAA,QACF;AACA;AAAA,MACF;AAEA,YAAM,MAAM,sBAAsB,KAAK,GAAG;AAC1C,YAAM,aAAa,SAAS,IAAI,YAAY;AAG5C,YAAM,mBAAmB,IAAI,iBAAiB,CAAC,CAAC,QAAQ,MAAM;AAC5D,YACE,SAAS,SAAS,gBAClB,WAAW,SAAS,eAAe,GAAG,WAAW,MAAM,GAAG,GAC1D;AAEA,cAAI,CAAC,2BAA2B,IAAI,GAAG;AACrC,iBAAK,OAAO;AACZ,mBAAO,GAAG;AACV;AAAA,UACF;AAEA,sBAAY,KAAK,IAAI;AAAA,QACvB;AAAA,MACF,CAAC;AACD,uBAAiB,QAAQ,KAAK,KAAK,EAAE,YAAY,KAAK,CAAC;AAGvD,UAAI,CAAC,2BAA2B,IAAI,GAAG;AACrC;AAAA,MACF;AAEA,kBAAY,KAAK,IAAI;AAAA,IACvB;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,MAAM,SAAS;AAEb,UAAI,CAAC,2BAA2B,IAAI,GAAG;AACrC,eAAO,MAAM,OAAO;AAAA,MACtB;AAEA,YAAM,SAAS,gBAAgB,IAAI;AACnC,UAAI,WAAW,UAAU;AACvB,eAAO,MAAM,OAAO;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -5,7 +5,7 @@ function withDrag(BaseClass, { target = (instance) => instance.$el, ...options }
5
5
  * Config.
6
6
  */
7
7
  static config = {
8
- name: `${BaseClass.config.name}WithDrag`,
8
+ ...BaseClass.config,
9
9
  emits: ["dragged"]
10
10
  };
11
11
  /**
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../packages/js-toolkit/decorators/withDrag.ts"],
4
- "sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport type { DragServiceOptions, DragServiceProps } from '../services/index.js';\nimport { useDrag } from '../services/index.js';\n\nexport type DragDecoratorOptions = DragServiceOptions & {\n target?: (this: Base, instance: Base) => HTMLElement;\n};\n\nexport interface WithDragInterface extends BaseInterface {\n dragged?(props: DragServiceProps): void;\n}\n\n/**\n * Add dragging capabilities to a component.\n */\nexport function withDrag<S extends Base>(\n BaseClass: typeof Base,\n { target = (instance) => instance.$el, ...options }: DragDecoratorOptions = {},\n): BaseDecorator<BaseInterface, S> {\n /**\n * Class.\n */\n class WithDrag<T extends BaseProps = BaseProps> extends BaseClass<T & WithDragInterface> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: `${BaseClass.config.name}WithDrag`,\n emits: ['dragged'],\n };\n\n /**\n * Class constructor.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.$on('mounted', () => {\n this.$services.register(\n 'dragged',\n useDrag.bind(undefined, target.call(this, this), options),\n );\n this.$services.enable('dragged');\n });\n\n this.$on('destroyed', () => {\n this.$services.disable('dragged');\n this.$services.unregister('dragged');\n });\n }\n }\n\n // @ts-ignore\n return WithDrag;\n}\n"],
5
- "mappings": "AAGA,SAAS,eAAe;AAajB,SAAS,SACd,WACA,EAAE,SAAS,CAAC,aAAa,SAAS,KAAK,GAAG,QAAQ,IAA0B,CAAC,GAC5C;AAAA,EAIjC,MAAM,iBAAkD,UAAiC;AAAA;AAAA;AAAA;AAAA,IAIvF,OAAO,SAAqB;AAAA,MAC1B,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,OAAO,CAAC,SAAS;AAAA,IACnB;AAAA;AAAA;AAAA;AAAA,IAKA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,IAAI,WAAW,MAAM;AACxB,aAAK,UAAU;AAAA,UACb;AAAA,UACA,QAAQ,KAAK,QAAW,OAAO,KAAK,MAAM,IAAI,GAAG,OAAO;AAAA,QAC1D;AACA,aAAK,UAAU,OAAO,SAAS;AAAA,MACjC,CAAC;AAED,WAAK,IAAI,aAAa,MAAM;AAC1B,aAAK,UAAU,QAAQ,SAAS;AAChC,aAAK,UAAU,WAAW,SAAS;AAAA,MACrC,CAAC;AAAA,IACH;AAAA,EACF;AAGA,SAAO;AACT;",
4
+ "sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport type { DragServiceOptions, DragServiceProps } from '../services/index.js';\nimport { useDrag } from '../services/index.js';\n\nexport type DragDecoratorOptions = DragServiceOptions & {\n target?: (this: Base, instance: Base) => HTMLElement;\n};\n\nexport interface WithDragInterface extends BaseInterface {\n dragged?(props: DragServiceProps): void;\n}\n\n/**\n * Add dragging capabilities to a component.\n */\nexport function withDrag<S extends Base>(\n BaseClass: typeof Base,\n { target = (instance) => instance.$el, ...options }: DragDecoratorOptions = {},\n): BaseDecorator<BaseInterface, S> {\n /**\n * Class.\n */\n class WithDrag<T extends BaseProps = BaseProps> extends BaseClass<T & WithDragInterface> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n emits: ['dragged'],\n };\n\n /**\n * Class constructor.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.$on('mounted', () => {\n this.$services.register(\n 'dragged',\n useDrag.bind(undefined, target.call(this, this), options),\n );\n this.$services.enable('dragged');\n });\n\n this.$on('destroyed', () => {\n this.$services.disable('dragged');\n this.$services.unregister('dragged');\n });\n }\n }\n\n // @ts-ignore\n return WithDrag;\n}\n"],
5
+ "mappings": "AAGA,SAAS,eAAe;AAajB,SAAS,SACd,WACA,EAAE,SAAS,CAAC,aAAa,SAAS,KAAK,GAAG,QAAQ,IAA0B,CAAC,GAC5C;AAAA,EAIjC,MAAM,iBAAkD,UAAiC;AAAA;AAAA;AAAA;AAAA,IAIvF,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,OAAO,CAAC,SAAS;AAAA,IACnB;AAAA;AAAA;AAAA;AAAA,IAKA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,IAAI,WAAW,MAAM;AACxB,aAAK,UAAU;AAAA,UACb;AAAA,UACA,QAAQ,KAAK,QAAW,OAAO,KAAK,MAAM,IAAI,GAAG,OAAO;AAAA,QAC1D;AACA,aAAK,UAAU,OAAO,SAAS;AAAA,MACjC,CAAC;AAED,WAAK,IAAI,aAAa,MAAM;AAC1B,aAAK,UAAU,QAAQ,SAAS;AAChC,aAAK,UAAU,WAAW,SAAS;AAAA,MACrC,CAAC;AAAA,IACH;AAAA,EACF;AAGA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -6,9 +6,7 @@ function withIntersectionObserver(BaseClass, defaultOptions = { threshold: creat
6
6
  */
7
7
  static config = {
8
8
  ...BaseClass.config,
9
- name: `${BaseClass.config.name}WithIntersectionObserver`,
10
9
  options: {
11
- ...BaseClass.config?.options,
12
10
  intersectionObserver: Object
13
11
  },
14
12
  emits: ["intersected"]