@studiometa/js-toolkit 2.3.0 → 2.4.2

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 (111) hide show
  1. package/Base/index.cjs +51 -43
  2. package/Base/index.d.ts +23 -18
  3. package/Base/index.js +70 -59
  4. package/Base/managers/AbstractManager.cjs +23 -13
  5. package/Base/managers/AbstractManager.d.ts +3 -3
  6. package/Base/managers/AbstractManager.js +24 -13
  7. package/Base/managers/ChildrenManager.cjs +21 -5
  8. package/Base/managers/ChildrenManager.d.ts +1 -1
  9. package/Base/managers/ChildrenManager.js +18 -4
  10. package/Base/managers/EventsManager.cjs +62 -44
  11. package/Base/managers/EventsManager.d.ts +3 -3
  12. package/Base/managers/EventsManager.js +59 -43
  13. package/Base/managers/OptionsManager.cjs +32 -12
  14. package/Base/managers/OptionsManager.d.ts +2 -2
  15. package/Base/managers/OptionsManager.js +29 -11
  16. package/Base/managers/RefsManager.cjs +19 -5
  17. package/Base/managers/RefsManager.js +15 -4
  18. package/Base/managers/ResponsiveOptionsManager.cjs +4 -1
  19. package/Base/managers/ServicesManager.cjs +21 -6
  20. package/Base/managers/ServicesManager.d.ts +1 -1
  21. package/Base/managers/ServicesManager.js +18 -5
  22. package/Base/utils.cjs +5 -1
  23. package/Base/utils.d.ts +2 -2
  24. package/Base/utils.js +5 -1
  25. package/README.md +3 -3
  26. package/decorators/index.cjs +4 -1
  27. package/decorators/withBreakpointManager.cjs +4 -1
  28. package/decorators/withBreakpointManager.d.ts +1 -1
  29. package/decorators/withBreakpointObserver.cjs +26 -14
  30. package/decorators/withBreakpointObserver.d.ts +1 -1
  31. package/decorators/withBreakpointObserver.js +23 -13
  32. package/decorators/withDrag.cjs +19 -8
  33. package/decorators/withDrag.d.ts +2 -4
  34. package/decorators/withDrag.js +16 -7
  35. package/decorators/withExtraConfig.cjs +12 -4
  36. package/decorators/withExtraConfig.js +9 -3
  37. package/decorators/withFreezedOptions.cjs +9 -1
  38. package/decorators/withFreezedOptions.js +10 -1
  39. package/decorators/withIntersectionObserver.cjs +25 -17
  40. package/decorators/withIntersectionObserver.d.ts +1 -1
  41. package/decorators/withIntersectionObserver.js +26 -17
  42. package/decorators/withMountWhenInView.cjs +30 -22
  43. package/decorators/withMountWhenInView.d.ts +1 -1
  44. package/decorators/withMountWhenInView.js +31 -22
  45. package/decorators/withResponsiveOptions.cjs +4 -1
  46. package/decorators/withScrolledInView.cjs +99 -48
  47. package/decorators/withScrolledInView.d.ts +27 -6
  48. package/decorators/withScrolledInView.js +96 -47
  49. package/decorators/withVue2.cjs +15 -10
  50. package/decorators/withVue2.d.ts +1 -1
  51. package/decorators/withVue2.js +16 -10
  52. package/helpers/getDirectChildren.cjs +46 -0
  53. package/helpers/getDirectChildren.d.ts +24 -0
  54. package/helpers/getDirectChildren.js +24 -0
  55. package/helpers/getInstanceFromElement.cjs +2 -1
  56. package/helpers/getInstanceFromElement.js +2 -1
  57. package/helpers/importOnInteraction.cjs +1 -1
  58. package/helpers/importOnInteraction.d.ts +2 -2
  59. package/helpers/importOnInteraction.js +1 -1
  60. package/helpers/importWhenIdle.cjs +10 -6
  61. package/helpers/importWhenIdle.js +10 -6
  62. package/helpers/importWhenVisible.cjs +1 -1
  63. package/helpers/importWhenVisible.d.ts +2 -2
  64. package/helpers/importWhenVisible.js +1 -1
  65. package/helpers/index.cjs +6 -1
  66. package/helpers/index.d.ts +1 -0
  67. package/helpers/index.js +1 -0
  68. package/index.cjs +4 -1
  69. package/package.json +2 -2
  70. package/services/drag.cjs +4 -1
  71. package/services/index.cjs +4 -1
  72. package/services/index.d.ts +7 -0
  73. package/services/key.cjs +5 -2
  74. package/services/key.js +1 -1
  75. package/services/pointer.cjs +3 -2
  76. package/services/pointer.js +3 -2
  77. package/services/resize.cjs +4 -1
  78. package/services/scroll.cjs +4 -1
  79. package/utils/collide/index.cjs +4 -1
  80. package/utils/css/animate.cjs +27 -12
  81. package/utils/css/animate.js +23 -11
  82. package/utils/css/index.cjs +4 -1
  83. package/utils/css/matrix.cjs +2 -1
  84. package/utils/css/matrix.js +2 -1
  85. package/utils/css/transform.cjs +2 -1
  86. package/utils/css/transform.js +2 -1
  87. package/utils/css/transition.cjs +11 -6
  88. package/utils/css/transition.js +8 -5
  89. package/utils/focusTrap.cjs +4 -1
  90. package/utils/history.cjs +4 -1
  91. package/utils/history.js +4 -1
  92. package/utils/index.cjs +4 -1
  93. package/utils/math/clamp01.cjs +4 -1
  94. package/utils/math/index.cjs +4 -1
  95. package/utils/math/inertiaFinalValue.cjs +4 -1
  96. package/utils/nextTick.cjs +5 -3
  97. package/utils/nextTick.js +5 -3
  98. package/utils/object/autoBind.cjs +4 -1
  99. package/utils/object/index.cjs +4 -1
  100. package/utils/scrollTo.cjs +4 -1
  101. package/utils/string/index.cjs +4 -1
  102. package/utils/string/withLeadingCharacters.cjs +4 -1
  103. package/utils/string/withLeadingSlash.cjs +4 -1
  104. package/utils/string/withTrailingCharacters.cjs +4 -1
  105. package/utils/string/withTrailingSlash.cjs +4 -1
  106. package/utils/string/withoutLeadingCharactersRecursive.cjs +4 -1
  107. package/utils/string/withoutLeadingSlash.cjs +4 -1
  108. package/utils/string/withoutTrailingCharactersRecursive.cjs +4 -1
  109. package/utils/string/withoutTrailingSlash.cjs +4 -1
  110. package/utils/tween.cjs +6 -2
  111. package/utils/tween.js +2 -1
@@ -11,7 +11,7 @@ export default function withIntersectionObserver<T extends typeof import("../Bas
11
11
  $observer: IntersectionObserver;
12
12
  };
13
13
  };
14
- export type Base = import('../Base').default;
14
+ export type Base = import("../Base").default<any>;
15
15
  export type BaseConstructor = import('../Base').BaseConstructor;
16
16
  export type WithIntersectionObserverOptions = {
17
17
  intersectionObserver: any;
@@ -1,25 +1,26 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
1
7
  function createArrayOfNumber(length) {
2
8
  return [...new Array(length + 1)].map((val, index) => index / length);
3
9
  }
4
10
  function withIntersectionObserver(BaseClass, defaultOptions = { threshold: createArrayOfNumber(100) }) {
5
- return class extends BaseClass {
6
- static config = {
7
- ...BaseClass.config,
8
- name: `${BaseClass.config.name}WithIntersectionObserver`,
9
- options: {
10
- ...BaseClass.config?.options || {},
11
- intersectionObserver: Object
12
- },
13
- emits: ["intersected"]
14
- };
11
+ var _a, _b;
12
+ return _b = class extends BaseClass {
15
13
  constructor(element) {
16
14
  super(element);
17
- this.$observer = new IntersectionObserver((entries) => {
18
- this.__callMethod("intersected", entries);
19
- }, {
20
- ...defaultOptions,
21
- ...this.$options.intersectionObserver
22
- });
15
+ this.$observer = new IntersectionObserver(
16
+ (entries) => {
17
+ this.__callMethod("intersected", entries);
18
+ },
19
+ {
20
+ ...defaultOptions,
21
+ ...this.$options.intersectionObserver
22
+ }
23
+ );
23
24
  this.$on("mounted", () => {
24
25
  this.$observer.observe(this.$el);
25
26
  });
@@ -27,7 +28,15 @@ function withIntersectionObserver(BaseClass, defaultOptions = { threshold: creat
27
28
  this.$observer.unobserve(this.$el);
28
29
  });
29
30
  }
30
- };
31
+ }, __publicField(_b, "config", {
32
+ ...BaseClass.config,
33
+ name: `${BaseClass.config.name}WithIntersectionObserver`,
34
+ options: {
35
+ ...((_a = BaseClass.config) == null ? void 0 : _a.options) || {},
36
+ intersectionObserver: Object
37
+ },
38
+ emits: ["intersected"]
39
+ }), _b;
31
40
  }
32
41
  export {
33
42
  withIntersectionObserver as default
@@ -2,6 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
6
  var __export = (target, all) => {
6
7
  for (var name in all)
7
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,6 +16,10 @@ var __copyProps = (to, from, except, desc) => {
15
16
  return to;
16
17
  };
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __publicField = (obj, key, value) => {
20
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ return value;
22
+ };
18
23
 
19
24
  // packages/js-toolkit/decorators/withMountWhenInView.js
20
25
  var withMountWhenInView_exports = {};
@@ -23,30 +28,26 @@ __export(withMountWhenInView_exports, {
23
28
  });
24
29
  module.exports = __toCommonJS(withMountWhenInView_exports);
25
30
  function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] }) {
26
- return class extends BaseClass {
27
- static config = {
28
- ...BaseClass.config,
29
- name: `${BaseClass.config.name}WithMountWhenInView`,
30
- options: {
31
- ...BaseClass.config?.options || {},
32
- intersectionObserver: Object
33
- }
34
- };
35
- __isVisible = false;
36
- __observer;
31
+ var _a, _b;
32
+ return _b = class extends BaseClass {
37
33
  constructor(element) {
38
34
  super(element);
39
- this.__observer = new IntersectionObserver((entries) => {
40
- const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);
41
- if (this.__isVisible !== isVisible) {
42
- this.__isVisible = isVisible;
43
- if (isVisible) {
44
- this.$mount();
45
- } else {
46
- setTimeout(() => this.$destroy());
35
+ __publicField(this, "__isVisible", false);
36
+ __publicField(this, "__observer");
37
+ this.__observer = new IntersectionObserver(
38
+ (entries) => {
39
+ const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);
40
+ if (this.__isVisible !== isVisible) {
41
+ this.__isVisible = isVisible;
42
+ if (isVisible) {
43
+ this.$mount();
44
+ } else {
45
+ setTimeout(() => this.$destroy());
46
+ }
47
47
  }
48
- }
49
- }, { ...defaultOptions, ...this.$options.intersectionObserver });
48
+ },
49
+ { ...defaultOptions, ...this.$options.intersectionObserver }
50
+ );
50
51
  this.__observer.observe(this.$el);
51
52
  this.$on("terminated", () => {
52
53
  this.__observer.disconnect();
@@ -58,6 +59,13 @@ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] })
58
59
  }
59
60
  return this;
60
61
  }
61
- };
62
+ }, __publicField(_b, "config", {
63
+ ...BaseClass.config,
64
+ name: `${BaseClass.config.name}WithMountWhenInView`,
65
+ options: {
66
+ ...((_a = BaseClass.config) == null ? void 0 : _a.options) || {},
67
+ intersectionObserver: Object
68
+ }
69
+ }), _b;
62
70
  }
63
71
  if (module.exports.default) module.exports = module.exports.default;
@@ -21,7 +21,7 @@
21
21
  * @returns {T}
22
22
  */
23
23
  export default function withMountWhenInView<T extends typeof import("../Base").default>(BaseClass: T, defaultOptions?: IntersectionObserverInit): T;
24
- export type Base = import('../Base').default;
24
+ export type Base = import("../Base").default<any>;
25
25
  export type BaseOptions = import('../Base').BaseOptions;
26
26
  export type BaseConstructor = import('../Base').BaseConstructor;
27
27
  export type WithMountWhenInViewOptions = {
@@ -1,28 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
1
7
  function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] }) {
2
- return class extends BaseClass {
3
- static config = {
4
- ...BaseClass.config,
5
- name: `${BaseClass.config.name}WithMountWhenInView`,
6
- options: {
7
- ...BaseClass.config?.options || {},
8
- intersectionObserver: Object
9
- }
10
- };
11
- __isVisible = false;
12
- __observer;
8
+ var _a, _b;
9
+ return _b = class extends BaseClass {
13
10
  constructor(element) {
14
11
  super(element);
15
- this.__observer = new IntersectionObserver((entries) => {
16
- const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);
17
- if (this.__isVisible !== isVisible) {
18
- this.__isVisible = isVisible;
19
- if (isVisible) {
20
- this.$mount();
21
- } else {
22
- setTimeout(() => this.$destroy());
12
+ __publicField(this, "__isVisible", false);
13
+ __publicField(this, "__observer");
14
+ this.__observer = new IntersectionObserver(
15
+ (entries) => {
16
+ const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);
17
+ if (this.__isVisible !== isVisible) {
18
+ this.__isVisible = isVisible;
19
+ if (isVisible) {
20
+ this.$mount();
21
+ } else {
22
+ setTimeout(() => this.$destroy());
23
+ }
23
24
  }
24
- }
25
- }, { ...defaultOptions, ...this.$options.intersectionObserver });
25
+ },
26
+ { ...defaultOptions, ...this.$options.intersectionObserver }
27
+ );
26
28
  this.__observer.observe(this.$el);
27
29
  this.$on("terminated", () => {
28
30
  this.__observer.disconnect();
@@ -34,7 +36,14 @@ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] })
34
36
  }
35
37
  return this;
36
38
  }
37
- };
39
+ }, __publicField(_b, "config", {
40
+ ...BaseClass.config,
41
+ name: `${BaseClass.config.name}WithMountWhenInView`,
42
+ options: {
43
+ ...((_a = BaseClass.config) == null ? void 0 : _a.options) || {},
44
+ intersectionObserver: Object
45
+ }
46
+ }), _b;
38
47
  }
39
48
  export {
40
49
  withMountWhenInView as default
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // packages/js-toolkit/decorators/withResponsiveOptions.js
@@ -4,6 +4,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
8
  var __export = (target, all) => {
8
9
  for (var name in all)
9
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,8 +17,15 @@ var __copyProps = (to, from, except, desc) => {
16
17
  }
17
18
  return to;
18
19
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
20
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var __publicField = (obj, key, value) => {
26
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
27
+ return value;
28
+ };
21
29
 
22
30
  // packages/js-toolkit/decorators/withScrolledInView.js
23
31
  var withScrolledInView_exports = {};
@@ -28,38 +36,68 @@ module.exports = __toCommonJS(withScrolledInView_exports);
28
36
  var import_withMountWhenInView = __toESM(require("./withMountWhenInView.cjs"), 1);
29
37
  var import_utils = require("../utils/index.cjs");
30
38
  var scheduler = (0, import_utils.useScheduler)(["update", "render"]);
39
+ function updateProps(props, dampFactor, dampPrecision, axis = "x") {
40
+ props.current[axis] = (0, import_utils.clamp)(
41
+ axis === "x" ? window.pageXOffset : window.pageYOffset,
42
+ props.start[axis],
43
+ props.end[axis]
44
+ );
45
+ props.dampedCurrent[axis] = (0, import_utils.damp)(
46
+ props.current[axis],
47
+ props.dampedCurrent[axis],
48
+ dampFactor,
49
+ dampPrecision
50
+ );
51
+ props.progress[axis] = (0, import_utils.clamp01)(
52
+ (props.current[axis] - props.start[axis]) / (props.end[axis] - props.start[axis])
53
+ );
54
+ props.dampedProgress[axis] = (0, import_utils.clamp01)(
55
+ (props.dampedCurrent[axis] - props.start[axis]) / (props.end[axis] - props.start[axis])
56
+ );
57
+ }
31
58
  function withScrolledInView(BaseClass, options = {}) {
32
- return class extends (0, import_withMountWhenInView.default)(BaseClass, options) {
33
- static config = {
34
- name: `${BaseClass.config.name}WithMountWhenInView`,
35
- emits: ["scrolledInView"]
36
- };
37
- __props = {
38
- start: {
39
- x: 0,
40
- y: 0
41
- },
42
- end: {
43
- x: 0,
44
- y: 0
45
- },
46
- current: {
47
- x: 0,
48
- y: 0
49
- },
50
- progress: {
51
- x: 0,
52
- y: 0
53
- },
54
- dampedProgress: {
55
- x: 0,
56
- y: 0
57
- }
58
- };
59
- dampFactor = 0.1;
60
- dampPrecision = 1e-3;
59
+ var _a;
60
+ return _a = class extends (0, import_withMountWhenInView.default)(BaseClass, options) {
61
61
  constructor(element) {
62
62
  super(element);
63
+ __publicField(this, "__props", {
64
+ start: {
65
+ x: 0,
66
+ y: 0
67
+ },
68
+ end: {
69
+ x: 0,
70
+ y: 0
71
+ },
72
+ current: {
73
+ x: 0,
74
+ y: 0
75
+ },
76
+ dampedCurrent: {
77
+ x: 0,
78
+ y: 0
79
+ },
80
+ progress: {
81
+ x: 0,
82
+ y: 0
83
+ },
84
+ dampedProgress: {
85
+ x: 0,
86
+ y: 0
87
+ }
88
+ });
89
+ __publicField(this, "dampFactor", 0.1);
90
+ __publicField(this, "dampPrecision", 1e-3);
91
+ const render = () => {
92
+ scheduler.update(() => {
93
+ const renderFn = this.__callMethod("scrolledInView", this.__props);
94
+ if ((0, import_utils.isFunction)(renderFn)) {
95
+ scheduler.render(() => {
96
+ renderFn(this.__props);
97
+ });
98
+ }
99
+ });
100
+ };
63
101
  const delegate = {
64
102
  handleEvent(event) {
65
103
  delegate[event.type](event.detail[0]);
@@ -73,23 +111,12 @@ function withScrolledInView(BaseClass, options = {}) {
73
111
  }
74
112
  },
75
113
  ticked: () => {
76
- this.__props.current.x = (0, import_utils.clamp)(window.pageXOffset, this.__props.start.x, this.__props.end.x);
77
- this.__props.progress.x = (0, import_utils.clamp01)((this.__props.current.x - this.__props.start.x) / (this.__props.end.x - this.__props.start.x));
78
- this.__props.dampedProgress.x = (0, import_utils.damp)(this.__props.progress.x, this.__props.dampedProgress.x, this.dampFactor, this.dampPrecision);
79
- this.__props.current.y = (0, import_utils.clamp)(window.pageYOffset, this.__props.start.y, this.__props.end.y);
80
- this.__props.progress.y = (0, import_utils.clamp01)((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
81
- this.__props.dampedProgress.y = (0, import_utils.damp)(this.__props.progress.y, this.__props.dampedProgress.y, this.dampFactor, this.dampPrecision);
82
- if (this.__props.dampedProgress.x === this.__props.progress.x && this.__props.dampedProgress.y === this.__props.progress.y) {
114
+ updateProps(this.__props, this.dampFactor, this.dampPrecision, "x");
115
+ updateProps(this.__props, this.dampFactor, this.dampPrecision, "y");
116
+ if (this.__props.dampedCurrent.x === this.__props.current.x && this.__props.dampedCurrent.y === this.__props.current.y) {
83
117
  this.$services.disable("ticked");
84
118
  }
85
- scheduler.update(() => {
86
- const renderFn = this.__callMethod("scrolledInView", this.__props);
87
- if ((0, import_utils.isFunction)(renderFn)) {
88
- scheduler.render(() => {
89
- renderFn(this.__props);
90
- });
91
- }
92
- });
119
+ render();
93
120
  }
94
121
  };
95
122
  this.$on("before-mounted", () => {
@@ -104,6 +131,11 @@ function withScrolledInView(BaseClass, options = {}) {
104
131
  this.$off("resized", delegate);
105
132
  this.$off("scrolled", delegate);
106
133
  this.$off("ticked", delegate);
134
+ this.__props.dampedCurrent.x = this.__props.current.x;
135
+ this.__props.dampedCurrent.y = this.__props.current.y;
136
+ this.__props.dampedProgress.x = this.__props.progress.x;
137
+ this.__props.dampedProgress.y = this.__props.progress.y;
138
+ render();
107
139
  });
108
140
  }
109
141
  mounted() {
@@ -142,11 +174,30 @@ function withScrolledInView(BaseClass, options = {}) {
142
174
  this.__props.end.y = yEnd;
143
175
  this.__props.current.x = xCurrent;
144
176
  this.__props.current.y = yCurrent;
177
+ this.__props.dampedCurrent.x = (0, import_utils.damp)(
178
+ xCurrent,
179
+ this.__props.dampedCurrent.x,
180
+ this.dampFactor,
181
+ this.dampPrecision
182
+ );
183
+ this.__props.dampedCurrent.y = (0, import_utils.damp)(
184
+ yCurrent,
185
+ this.__props.dampedCurrent.y,
186
+ this.dampFactor,
187
+ this.dampPrecision
188
+ );
145
189
  this.__props.progress.x = xProgress;
146
190
  this.__props.progress.y = yProgress;
147
- this.__props.dampedProgress.x = (0, import_utils.damp)(xProgress, this.__props.dampedProgress.x);
148
- this.__props.dampedProgress.y = (0, import_utils.damp)(yProgress, this.__props.dampedProgress.y);
191
+ this.__props.dampedProgress.x = (0, import_utils.clamp01)(
192
+ (this.__props.dampedCurrent.x - xStart) / (xEnd - xStart)
193
+ );
194
+ this.__props.dampedProgress.y = (0, import_utils.clamp01)(
195
+ (this.__props.dampedCurrent.y - yStart) / (yEnd - yStart)
196
+ );
149
197
  }
150
- };
198
+ }, __publicField(_a, "config", {
199
+ name: `${BaseClass.config.name}WithMountWhenInView`,
200
+ emits: ["scrolledInView"]
201
+ }), _a;
151
202
  }
152
203
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,8 +1,3 @@
1
- /**
2
- * @typedef {import('../Base').default} Base
3
- * @typedef {import('../Base').BaseConstructor} BaseConstructor
4
- * @typedef {import('../Base').BaseConfig} BaseConfig
5
- */
6
1
  /**
7
2
  * Add scrolled in view capabilities to a component.
8
3
  *
@@ -14,6 +9,32 @@
14
9
  export default function withScrolledInView<T extends typeof import("../Base").default>(BaseClass: T, options?: IntersectionObserverInit & {
15
10
  useOffsetSizes?: boolean;
16
11
  }): T;
17
- export type Base = import('../Base').default;
12
+ export type Base = import("../Base").default<any>;
18
13
  export type BaseConstructor = import('../Base').BaseConstructor;
19
14
  export type BaseConfig = import('../Base').BaseConfig;
15
+ export type ScrollInViewProps = {
16
+ start: {
17
+ x: number;
18
+ y: number;
19
+ };
20
+ end: {
21
+ x: number;
22
+ y: number;
23
+ };
24
+ current: {
25
+ x: number;
26
+ y: number;
27
+ };
28
+ dampedCurrent: {
29
+ x: number;
30
+ y: number;
31
+ };
32
+ progress: {
33
+ x: number;
34
+ y: number;
35
+ };
36
+ dampedProgress: {
37
+ x: number;
38
+ y: number;
39
+ };
40
+ };
@@ -1,38 +1,74 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
1
7
  import withMountWhenInView from "./withMountWhenInView.js";
2
8
  import { damp, clamp, clamp01, getOffsetSizes, isFunction, useScheduler } from "../utils/index.js";
3
9
  const scheduler = useScheduler(["update", "render"]);
10
+ function updateProps(props, dampFactor, dampPrecision, axis = "x") {
11
+ props.current[axis] = clamp(
12
+ axis === "x" ? window.pageXOffset : window.pageYOffset,
13
+ props.start[axis],
14
+ props.end[axis]
15
+ );
16
+ props.dampedCurrent[axis] = damp(
17
+ props.current[axis],
18
+ props.dampedCurrent[axis],
19
+ dampFactor,
20
+ dampPrecision
21
+ );
22
+ props.progress[axis] = clamp01(
23
+ (props.current[axis] - props.start[axis]) / (props.end[axis] - props.start[axis])
24
+ );
25
+ props.dampedProgress[axis] = clamp01(
26
+ (props.dampedCurrent[axis] - props.start[axis]) / (props.end[axis] - props.start[axis])
27
+ );
28
+ }
4
29
  function withScrolledInView(BaseClass, options = {}) {
5
- return class extends withMountWhenInView(BaseClass, options) {
6
- static config = {
7
- name: `${BaseClass.config.name}WithMountWhenInView`,
8
- emits: ["scrolledInView"]
9
- };
10
- __props = {
11
- start: {
12
- x: 0,
13
- y: 0
14
- },
15
- end: {
16
- x: 0,
17
- y: 0
18
- },
19
- current: {
20
- x: 0,
21
- y: 0
22
- },
23
- progress: {
24
- x: 0,
25
- y: 0
26
- },
27
- dampedProgress: {
28
- x: 0,
29
- y: 0
30
- }
31
- };
32
- dampFactor = 0.1;
33
- dampPrecision = 1e-3;
30
+ var _a;
31
+ return _a = class extends withMountWhenInView(BaseClass, options) {
34
32
  constructor(element) {
35
33
  super(element);
34
+ __publicField(this, "__props", {
35
+ start: {
36
+ x: 0,
37
+ y: 0
38
+ },
39
+ end: {
40
+ x: 0,
41
+ y: 0
42
+ },
43
+ current: {
44
+ x: 0,
45
+ y: 0
46
+ },
47
+ dampedCurrent: {
48
+ x: 0,
49
+ y: 0
50
+ },
51
+ progress: {
52
+ x: 0,
53
+ y: 0
54
+ },
55
+ dampedProgress: {
56
+ x: 0,
57
+ y: 0
58
+ }
59
+ });
60
+ __publicField(this, "dampFactor", 0.1);
61
+ __publicField(this, "dampPrecision", 1e-3);
62
+ const render = () => {
63
+ scheduler.update(() => {
64
+ const renderFn = this.__callMethod("scrolledInView", this.__props);
65
+ if (isFunction(renderFn)) {
66
+ scheduler.render(() => {
67
+ renderFn(this.__props);
68
+ });
69
+ }
70
+ });
71
+ };
36
72
  const delegate = {
37
73
  handleEvent(event) {
38
74
  delegate[event.type](event.detail[0]);
@@ -46,23 +82,12 @@ function withScrolledInView(BaseClass, options = {}) {
46
82
  }
47
83
  },
48
84
  ticked: () => {
49
- this.__props.current.x = clamp(window.pageXOffset, this.__props.start.x, this.__props.end.x);
50
- this.__props.progress.x = clamp01((this.__props.current.x - this.__props.start.x) / (this.__props.end.x - this.__props.start.x));
51
- this.__props.dampedProgress.x = damp(this.__props.progress.x, this.__props.dampedProgress.x, this.dampFactor, this.dampPrecision);
52
- this.__props.current.y = clamp(window.pageYOffset, this.__props.start.y, this.__props.end.y);
53
- this.__props.progress.y = clamp01((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
54
- this.__props.dampedProgress.y = damp(this.__props.progress.y, this.__props.dampedProgress.y, this.dampFactor, this.dampPrecision);
55
- if (this.__props.dampedProgress.x === this.__props.progress.x && this.__props.dampedProgress.y === this.__props.progress.y) {
85
+ updateProps(this.__props, this.dampFactor, this.dampPrecision, "x");
86
+ updateProps(this.__props, this.dampFactor, this.dampPrecision, "y");
87
+ if (this.__props.dampedCurrent.x === this.__props.current.x && this.__props.dampedCurrent.y === this.__props.current.y) {
56
88
  this.$services.disable("ticked");
57
89
  }
58
- scheduler.update(() => {
59
- const renderFn = this.__callMethod("scrolledInView", this.__props);
60
- if (isFunction(renderFn)) {
61
- scheduler.render(() => {
62
- renderFn(this.__props);
63
- });
64
- }
65
- });
90
+ render();
66
91
  }
67
92
  };
68
93
  this.$on("before-mounted", () => {
@@ -77,6 +102,11 @@ function withScrolledInView(BaseClass, options = {}) {
77
102
  this.$off("resized", delegate);
78
103
  this.$off("scrolled", delegate);
79
104
  this.$off("ticked", delegate);
105
+ this.__props.dampedCurrent.x = this.__props.current.x;
106
+ this.__props.dampedCurrent.y = this.__props.current.y;
107
+ this.__props.dampedProgress.x = this.__props.progress.x;
108
+ this.__props.dampedProgress.y = this.__props.progress.y;
109
+ render();
80
110
  });
81
111
  }
82
112
  mounted() {
@@ -115,12 +145,31 @@ function withScrolledInView(BaseClass, options = {}) {
115
145
  this.__props.end.y = yEnd;
116
146
  this.__props.current.x = xCurrent;
117
147
  this.__props.current.y = yCurrent;
148
+ this.__props.dampedCurrent.x = damp(
149
+ xCurrent,
150
+ this.__props.dampedCurrent.x,
151
+ this.dampFactor,
152
+ this.dampPrecision
153
+ );
154
+ this.__props.dampedCurrent.y = damp(
155
+ yCurrent,
156
+ this.__props.dampedCurrent.y,
157
+ this.dampFactor,
158
+ this.dampPrecision
159
+ );
118
160
  this.__props.progress.x = xProgress;
119
161
  this.__props.progress.y = yProgress;
120
- this.__props.dampedProgress.x = damp(xProgress, this.__props.dampedProgress.x);
121
- this.__props.dampedProgress.y = damp(yProgress, this.__props.dampedProgress.y);
162
+ this.__props.dampedProgress.x = clamp01(
163
+ (this.__props.dampedCurrent.x - xStart) / (xEnd - xStart)
164
+ );
165
+ this.__props.dampedProgress.y = clamp01(
166
+ (this.__props.dampedCurrent.y - yStart) / (yEnd - yStart)
167
+ );
122
168
  }
123
- };
169
+ }, __publicField(_a, "config", {
170
+ name: `${BaseClass.config.name}WithMountWhenInView`,
171
+ emits: ["scrolledInView"]
172
+ }), _a;
124
173
  }
125
174
  export {
126
175
  withScrolledInView as default