vevet 2.0.1-dev.17 → 2.0.1-dev.18

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.
@@ -25,12 +25,16 @@ var __assign = (this && this.__assign) || function () {
25
25
  };
26
26
  return __assign.apply(this, arguments);
27
27
  };
28
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
29
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
30
+ to[j] = from[i];
31
+ return to;
32
+ };
28
33
  var __importDefault = (this && this.__importDefault) || function (mod) {
29
34
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
35
  };
31
36
  Object.defineProperty(exports, "__esModule", { value: true });
32
37
  exports.ScrollView = void 0;
33
- var vevet_dom_1 = require("vevet-dom");
34
38
  var ScrollEventsBase_1 = require("./ScrollEventsBase");
35
39
  var onScroll_1 = __importDefault(require("../../../utils/listeners/onScroll"));
36
40
  var listeners_1 = require("../../../utils/listeners");
@@ -47,8 +51,7 @@ var ScrollView = /** @class */ (function (_super) {
47
51
  _this._scrollEvent = undefined;
48
52
  _this._intersectionObserver = undefined;
49
53
  _this._firstStart = true;
50
- // get view elements
51
- _this.updateElements();
54
+ _this._elements = __spreadArray([], _this.prop.elements);
52
55
  // initialize the class
53
56
  if (init) {
54
57
  _this.init();
@@ -63,11 +66,20 @@ var ScrollView = /** @class */ (function (_super) {
63
66
  configurable: true
64
67
  });
65
68
  ScrollView.prototype._getDefaultProp = function () {
66
- return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: window, elements: "." + this.prefix + "__el", threshold: 0.9, states: 'in', classToToggle: 'viewed', useDelay: false, useIntersectionObserver: true });
69
+ return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { enabled: true, container: window, elements: [], threshold: 0.9, states: 'in', classToToggle: 'viewed', useDelay: false, useIntersectionObserver: true });
67
70
  };
71
+ Object.defineProperty(ScrollView.prototype, "elements", {
72
+ /**
73
+ * Elements to seek
74
+ */
75
+ get: function () {
76
+ return this._elements;
77
+ },
78
+ enumerable: false,
79
+ configurable: true
80
+ });
68
81
  ScrollView.prototype.init = function () {
69
82
  _super.prototype.init.call(this);
70
- this.seekBounding();
71
83
  };
72
84
  // Set Module Events
73
85
  ScrollView.prototype._setEvents = function () {
@@ -80,16 +92,17 @@ var ScrollView = /** @class */ (function (_super) {
80
92
  };
81
93
  ScrollView.prototype._onPropMutate = function () {
82
94
  _super.prototype._onPropMutate.call(this);
83
- this._removeViewEvents();
84
- this.updateElements();
85
- this._setViewEvents();
95
+ this.resize();
86
96
  };
87
97
  /**
88
98
  * Resize the scene
89
99
  */
90
100
  ScrollView.prototype.resize = function () {
91
101
  this._removeViewEvents();
92
- this._setViewEvents();
102
+ if (this.prop.enabled) {
103
+ this._setViewEvents();
104
+ this.seekBounding();
105
+ }
93
106
  };
94
107
  /**
95
108
  * Set View events: scroll or intersection
@@ -111,12 +124,10 @@ var ScrollView = /** @class */ (function (_super) {
111
124
  rootMargin: "0px " + xMargin + "px " + yMargin + "px 0px",
112
125
  });
113
126
  // add elements
114
- if (this.elements) {
115
- this.elements.forEach(function (el) {
116
- var _a;
117
- (_a = _this._intersectionObserver) === null || _a === void 0 ? void 0 : _a.observe(el);
118
- });
119
- }
127
+ this.elements.forEach(function (el) {
128
+ var _a;
129
+ (_a = _this._intersectionObserver) === null || _a === void 0 ? void 0 : _a.observe(el);
130
+ });
120
131
  }
121
132
  else {
122
133
  // set scroll bounding events
@@ -141,40 +152,6 @@ var ScrollView = /** @class */ (function (_super) {
141
152
  this._intersectionObserver = undefined;
142
153
  }
143
154
  };
144
- Object.defineProperty(ScrollView.prototype, "elements", {
145
- /**
146
- * Element to seek
147
- */
148
- get: function () {
149
- return this._elements;
150
- },
151
- enumerable: false,
152
- configurable: true
153
- });
154
- /**
155
- * Update elements
156
- */
157
- ScrollView.prototype.updateElements = function () {
158
- var _this = this;
159
- // check if elements exist
160
- if (typeof this.elements === 'undefined') {
161
- this._elements = [];
162
- }
163
- // unobserve old elements
164
- this.elements.forEach(function (el) {
165
- if (_this._intersectionObserver) {
166
- _this._intersectionObserver.unobserve(el);
167
- }
168
- });
169
- // update elements
170
- this._elements = Array.from(vevet_dom_1.selectAll(this.prop.elements, this.domParent || undefined)).filter(function (el) { return !el.classList.contains(_this.prop.classToToggle); });
171
- // add them to the observer
172
- this._elements.forEach(function (el) {
173
- if (_this._intersectionObserver) {
174
- _this._intersectionObserver.observe(el);
175
- }
176
- });
177
- };
178
155
  /**
179
156
  * Event on IntersectionObserver
180
157
  */
@@ -276,9 +253,11 @@ var ScrollView = /** @class */ (function (_super) {
276
253
  // update props
277
254
  el.scrollViewIn = inViewport;
278
255
  // toggle classes
279
- timeoutCallback_1.default(function () {
280
- el.classList.toggle(_this.prop.classToToggle, inViewport);
281
- }, delay);
256
+ if (this.prop.classToToggle) {
257
+ timeoutCallback_1.default(function () {
258
+ el.classList.toggle(_this.prop.classToToggle, inViewport);
259
+ }, delay);
260
+ }
282
261
  // process callbacks
283
262
  if (inViewport && (states === 'in' || states === 'inout')) {
284
263
  timeoutCallback_1.default(function () {
@@ -308,6 +287,36 @@ var ScrollView = /** @class */ (function (_super) {
308
287
  });
309
288
  this._elements = this._elements.filter(function (el) { return !el.scrollViewIn; });
310
289
  };
290
+ /**
291
+ * Add a view element
292
+ */
293
+ ScrollView.prototype.addElement = function (element) {
294
+ this._elements.push(element);
295
+ if (this._intersectionObserver) {
296
+ this._intersectionObserver.observe(element);
297
+ }
298
+ };
299
+ /**
300
+ * Remove a view element
301
+ */
302
+ ScrollView.prototype.removeElement = function (element) {
303
+ this._elements = this._elements.filter(function (el) { return el !== element; });
304
+ if (this._intersectionObserver) {
305
+ this._intersectionObserver.unobserve(element);
306
+ }
307
+ };
308
+ /**
309
+ * Remove all view elements
310
+ */
311
+ ScrollView.prototype.removeElements = function () {
312
+ var _this = this;
313
+ this._elements.forEach(function (el) {
314
+ if (_this._intersectionObserver) {
315
+ _this._intersectionObserver.unobserve(el);
316
+ }
317
+ });
318
+ this._elements = [];
319
+ };
311
320
  /**
312
321
  * Destroy the module
313
322
  */
@@ -1,4 +1,3 @@
1
- import { selectAll } from 'vevet-dom';
2
1
  import { ScrollEventsBase } from './ScrollEventsBase';
3
2
  import onScroll from '../../../utils/listeners/onScroll';
4
3
  import { intersectionObserverSupported } from '../../../utils/listeners';
@@ -13,8 +12,7 @@ export class ScrollView extends ScrollEventsBase {
13
12
  this._scrollEvent = undefined;
14
13
  this._intersectionObserver = undefined;
15
14
  this._firstStart = true;
16
- // get view elements
17
- this.updateElements();
15
+ this._elements = [...this.prop.elements];
18
16
  // initialize the class
19
17
  if (init) {
20
18
  this.init();
@@ -24,11 +22,16 @@ export class ScrollView extends ScrollEventsBase {
24
22
  return `${this._app.prefix}scroll-view`;
25
23
  }
26
24
  _getDefaultProp() {
27
- return Object.assign(Object.assign({}, super._getDefaultProp()), { container: window, elements: `.${this.prefix}__el`, threshold: 0.9, states: 'in', classToToggle: 'viewed', useDelay: false, useIntersectionObserver: true });
25
+ return Object.assign(Object.assign({}, super._getDefaultProp()), { enabled: true, container: window, elements: [], threshold: 0.9, states: 'in', classToToggle: 'viewed', useDelay: false, useIntersectionObserver: true });
26
+ }
27
+ /**
28
+ * Elements to seek
29
+ */
30
+ get elements() {
31
+ return this._elements;
28
32
  }
29
33
  init() {
30
34
  super.init();
31
- this.seekBounding();
32
35
  }
33
36
  // Set Module Events
34
37
  _setEvents() {
@@ -40,16 +43,17 @@ export class ScrollView extends ScrollEventsBase {
40
43
  }
41
44
  _onPropMutate() {
42
45
  super._onPropMutate();
43
- this._removeViewEvents();
44
- this.updateElements();
45
- this._setViewEvents();
46
+ this.resize();
46
47
  }
47
48
  /**
48
49
  * Resize the scene
49
50
  */
50
51
  resize() {
51
52
  this._removeViewEvents();
52
- this._setViewEvents();
53
+ if (this.prop.enabled) {
54
+ this._setViewEvents();
55
+ this.seekBounding();
56
+ }
53
57
  }
54
58
  /**
55
59
  * Set View events: scroll or intersection
@@ -70,12 +74,10 @@ export class ScrollView extends ScrollEventsBase {
70
74
  rootMargin: `0px ${xMargin}px ${yMargin}px 0px`,
71
75
  });
72
76
  // add elements
73
- if (this.elements) {
74
- this.elements.forEach((el) => {
75
- var _a;
76
- (_a = this._intersectionObserver) === null || _a === void 0 ? void 0 : _a.observe(el);
77
- });
78
- }
77
+ this.elements.forEach((el) => {
78
+ var _a;
79
+ (_a = this._intersectionObserver) === null || _a === void 0 ? void 0 : _a.observe(el);
80
+ });
79
81
  }
80
82
  else {
81
83
  // set scroll bounding events
@@ -100,35 +102,6 @@ export class ScrollView extends ScrollEventsBase {
100
102
  this._intersectionObserver = undefined;
101
103
  }
102
104
  }
103
- /**
104
- * Element to seek
105
- */
106
- get elements() {
107
- return this._elements;
108
- }
109
- /**
110
- * Update elements
111
- */
112
- updateElements() {
113
- // check if elements exist
114
- if (typeof this.elements === 'undefined') {
115
- this._elements = [];
116
- }
117
- // unobserve old elements
118
- this.elements.forEach((el) => {
119
- if (this._intersectionObserver) {
120
- this._intersectionObserver.unobserve(el);
121
- }
122
- });
123
- // update elements
124
- this._elements = Array.from(selectAll(this.prop.elements, this.domParent || undefined)).filter((el) => !el.classList.contains(this.prop.classToToggle));
125
- // add them to the observer
126
- this._elements.forEach((el) => {
127
- if (this._intersectionObserver) {
128
- this._intersectionObserver.observe(el);
129
- }
130
- });
131
- }
132
105
  /**
133
106
  * Event on IntersectionObserver
134
107
  */
@@ -228,9 +201,11 @@ export class ScrollView extends ScrollEventsBase {
228
201
  // update props
229
202
  el.scrollViewIn = inViewport;
230
203
  // toggle classes
231
- timeoutCallback(() => {
232
- el.classList.toggle(this.prop.classToToggle, inViewport);
233
- }, delay);
204
+ if (this.prop.classToToggle) {
205
+ timeoutCallback(() => {
206
+ el.classList.toggle(this.prop.classToToggle, inViewport);
207
+ }, delay);
208
+ }
234
209
  // process callbacks
235
210
  if (inViewport && (states === 'in' || states === 'inout')) {
236
211
  timeoutCallback(() => {
@@ -259,6 +234,35 @@ export class ScrollView extends ScrollEventsBase {
259
234
  });
260
235
  this._elements = this._elements.filter((el) => !el.scrollViewIn);
261
236
  }
237
+ /**
238
+ * Add a view element
239
+ */
240
+ addElement(element) {
241
+ this._elements.push(element);
242
+ if (this._intersectionObserver) {
243
+ this._intersectionObserver.observe(element);
244
+ }
245
+ }
246
+ /**
247
+ * Remove a view element
248
+ */
249
+ removeElement(element) {
250
+ this._elements = this._elements.filter((el) => el !== element);
251
+ if (this._intersectionObserver) {
252
+ this._intersectionObserver.unobserve(element);
253
+ }
254
+ }
255
+ /**
256
+ * Remove all view elements
257
+ */
258
+ removeElements() {
259
+ this._elements.forEach((el) => {
260
+ if (this._intersectionObserver) {
261
+ this._intersectionObserver.unobserve(el);
262
+ }
263
+ });
264
+ this._elements = [];
265
+ }
262
266
  /**
263
267
  * Destroy the module
264
268
  */
@@ -1,4 +1,3 @@
1
- import { SelectorAll } from 'vevet-dom';
2
1
  import { ScrollEventsBase, NScrollEventsBase } from './ScrollEventsBase';
3
2
  import { IRemovable } from '../../../utils/types/general';
4
3
  import { RequiredModuleProp } from '../../../utils/types/utility';
@@ -8,10 +7,17 @@ export declare namespace NScrollView {
8
7
  */
9
8
  interface StaticProp extends NScrollEventsBase.StaticProp {
10
9
  /**
11
- * Elements to seek
12
- * @default '.v-scroll-view__el'
10
+ * If enabled, scrolling events will be created.
11
+ * You can use "false" to create just an instance of the ScrollView
12
+ * and later enable animations.
13
+ * @default true
14
+ */
15
+ enabled?: boolean;
16
+ /**
17
+ * View elements.
18
+ * @default []
13
19
  */
14
- elements?: SelectorAll;
20
+ elements?: Element[];
15
21
  /**
16
22
  * The moment at which the element is considered to be in the viewport.
17
23
  * The value is calculated from top to bottom or from left to right.
@@ -79,6 +85,11 @@ export declare class ScrollView<StaticProp extends NScrollView.StaticProp = NScr
79
85
  * If first start
80
86
  */
81
87
  protected _firstStart: boolean;
88
+ protected _elements: NScrollView.El[];
89
+ /**
90
+ * Elements to seek
91
+ */
92
+ get elements(): NScrollView.El[];
82
93
  constructor(initialProp?: (StaticProp & ChangeableProp), init?: boolean);
83
94
  init(): void;
84
95
  protected _setEvents(): void;
@@ -95,15 +106,6 @@ export declare class ScrollView<StaticProp extends NScrollView.StaticProp = NScr
95
106
  * Remove View events: scroll or intersection
96
107
  */
97
108
  protected _removeViewEvents(): void;
98
- protected _elements: NScrollView.El[];
99
- /**
100
- * Element to seek
101
- */
102
- get elements(): NScrollView.El[];
103
- /**
104
- * Update elements
105
- */
106
- updateElements(): void;
107
109
  /**
108
110
  * Event on IntersectionObserver
109
111
  */
@@ -132,6 +134,18 @@ export declare class ScrollView<StaticProp extends NScrollView.StaticProp = NScr
132
134
  * Remove elements that are mo more in need
133
135
  */
134
136
  protected _processUnusedElements(): void;
137
+ /**
138
+ * Add a view element
139
+ */
140
+ addElement(element: Element): void;
141
+ /**
142
+ * Remove a view element
143
+ */
144
+ removeElement(element: Element): void;
145
+ /**
146
+ * Remove all view elements
147
+ */
148
+ removeElements(): void;
135
149
  /**
136
150
  * Destroy the module
137
151
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ScrollView.d.ts","sourceRoot":"","sources":["../../../../../src/ts/components/scroll/scrollable/ScrollView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAQlE,yBAAiB,WAAW,CAAC;IAEzB;;OAEG;IACH,UAAiB,UAAW,SAAQ,iBAAiB,CAAC,UAAU;QAC5D;;;WAGG;QACH,QAAQ,CAAC,EAAE,WAAW,CAAC;QACvB;;;;WAIG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB;;;WAGG;QACH,MAAM,CAAC,EAAE,IAAI,GAAG,OAAO,CAAC;QACxB;;;WAGG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GAAG,cAAc,CAAC,EAC3C,IAAI,UAAO;IAeR,IAAI;IAKX,SAAS,CAAC,UAAU;IAQpB,SAAS,CAAC,aAAa;IAKvB;;OAEG;IACI,MAAM;IAQb;;OAEG;IACH,SAAS,CAAC,cAAc;IA+BxB;;OAEG;IACH,SAAS,CAAC,iBAAiB;IAa3B;;OAEG;IACH,SAAS,CAAC,2BAA2B,CACjC,IAAI,EAAE,yBAAyB,EAAE;IAuBrC;;OAEG;IACH,SAAS,CAAC,aAAa;IAIvB;;;OAGG;IACI,YAAY;IAwBnB;;OAEG;IACH,SAAS,CAAC,sBAAsB,CAC5B,EAAE,EAAE,OAAO,EACX,cAAc,EAAE,iBAAiB,CAAC,YAAY;;;;IA2ClD;;OAEG;IACH,SAAS,CAAC,YAAY,CAClB,EAAE,EAAE,WAAW,CAAC,EAAE,EAClB,UAAU,EAAE,OAAO,EACnB,KAAK,SAAI;IAgCb;;OAEG;IACH,SAAS,CAAC,sBAAsB;IAehC;;OAEG;IACI,UAAU,CACb,OAAO,EAAE,OAAO;IAQpB;;OAEG;IACI,aAAa,CAChB,OAAO,EAAE,OAAO;IAQpB;;OAEG;IACI,cAAc;IAWrB;;OAEG;IACH,SAAS,CAAC,QAAQ;CAIrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vevet",
3
- "version": "2.0.1-dev.17",
3
+ "version": "2.0.1-dev.18",
4
4
  "description": "VEVET - A JavaScript library",
5
5
  "browserslist": [
6
6
  "since 2015"
@@ -1,4 +1,3 @@
1
- import { selectAll, SelectorAll } from 'vevet-dom';
2
1
  import { ScrollEventsBase, NScrollEventsBase } from './ScrollEventsBase';
3
2
  import { IRemovable } from '../../../utils/types/general';
4
3
  import { RequiredModuleProp } from '../../../utils/types/utility';
@@ -16,10 +15,17 @@ export namespace NScrollView {
16
15
  */
17
16
  export interface StaticProp extends NScrollEventsBase.StaticProp {
18
17
  /**
19
- * Elements to seek
20
- * @default '.v-scroll-view__el'
18
+ * If enabled, scrolling events will be created.
19
+ * You can use "false" to create just an instance of the ScrollView
20
+ * and later enable animations.
21
+ * @default true
22
+ */
23
+ enabled?: boolean;
24
+ /**
25
+ * View elements.
26
+ * @default []
21
27
  */
22
- elements?: SelectorAll;
28
+ elements?: Element[];
23
29
  /**
24
30
  * The moment at which the element is considered to be in the viewport.
25
31
  * The value is calculated from top to bottom or from left to right.
@@ -96,8 +102,9 @@ export class ScrollView <
96
102
  > (): T {
97
103
  return {
98
104
  ...super._getDefaultProp(),
105
+ enabled: true,
99
106
  container: window,
100
- elements: `.${this.prefix}__el`,
107
+ elements: [],
101
108
  threshold: 0.9,
102
109
  states: 'in',
103
110
  classToToggle: 'viewed',
@@ -122,6 +129,14 @@ export class ScrollView <
122
129
  */
123
130
  protected _firstStart: boolean;
124
131
 
132
+ protected _elements: NScrollView.El[];
133
+ /**
134
+ * Elements to seek
135
+ */
136
+ get elements () {
137
+ return this._elements;
138
+ }
139
+
125
140
 
126
141
 
127
142
  constructor (
@@ -133,9 +148,7 @@ export class ScrollView <
133
148
  this._scrollEvent = undefined;
134
149
  this._intersectionObserver = undefined;
135
150
  this._firstStart = true;
136
-
137
- // get view elements
138
- this.updateElements();
151
+ this._elements = [...this.prop.elements];
139
152
 
140
153
  // initialize the class
141
154
  if (init) {
@@ -145,7 +158,6 @@ export class ScrollView <
145
158
 
146
159
  public init () {
147
160
  super.init();
148
- this.seekBounding();
149
161
  }
150
162
 
151
163
  // Set Module Events
@@ -159,9 +171,7 @@ export class ScrollView <
159
171
 
160
172
  protected _onPropMutate () {
161
173
  super._onPropMutate();
162
- this._removeViewEvents();
163
- this.updateElements();
164
- this._setViewEvents();
174
+ this.resize();
165
175
  }
166
176
 
167
177
  /**
@@ -169,7 +179,10 @@ export class ScrollView <
169
179
  */
170
180
  public resize () {
171
181
  this._removeViewEvents();
172
- this._setViewEvents();
182
+ if (this.prop.enabled) {
183
+ this._setViewEvents();
184
+ this.seekBounding();
185
+ }
173
186
  }
174
187
 
175
188
  /**
@@ -194,11 +207,9 @@ export class ScrollView <
194
207
  },
195
208
  );
196
209
  // add elements
197
- if (this.elements) {
198
- this.elements.forEach((el) => {
199
- this._intersectionObserver?.observe(el);
200
- });
201
- }
210
+ this.elements.forEach((el) => {
211
+ this._intersectionObserver?.observe(el);
212
+ });
202
213
  } else {
203
214
  // set scroll bounding events
204
215
  this._scrollEvent = onScroll({
@@ -224,46 +235,6 @@ export class ScrollView <
224
235
  }
225
236
  }
226
237
 
227
-
228
-
229
- protected _elements!: NScrollView.El[];
230
- /**
231
- * Element to seek
232
- */
233
- get elements () {
234
- return this._elements;
235
- }
236
-
237
- /**
238
- * Update elements
239
- */
240
- public updateElements () {
241
- // check if elements exist
242
- if (typeof this.elements === 'undefined') {
243
- this._elements = [];
244
- }
245
- // unobserve old elements
246
- this.elements.forEach((el) => {
247
- if (this._intersectionObserver) {
248
- this._intersectionObserver.unobserve(el);
249
- }
250
- });
251
- // update elements
252
- this._elements = Array.from(
253
- selectAll(this.prop.elements as any, this.domParent || undefined),
254
- ).filter(
255
- (el) => !el.classList.contains(this.prop.classToToggle),
256
- );
257
- // add them to the observer
258
- this._elements.forEach((el) => {
259
- if (this._intersectionObserver) {
260
- this._intersectionObserver.observe(el);
261
- }
262
- });
263
- }
264
-
265
-
266
-
267
238
  /**
268
239
  * Event on IntersectionObserver
269
240
  */
@@ -374,8 +345,6 @@ export class ScrollView <
374
345
  };
375
346
  }
376
347
 
377
-
378
-
379
348
  /**
380
349
  * Event that is triggered when an element appears or disappears
381
350
  */
@@ -396,9 +365,11 @@ export class ScrollView <
396
365
  el.scrollViewIn = inViewport;
397
366
 
398
367
  // toggle classes
399
- timeoutCallback(() => {
400
- el.classList.toggle(this.prop.classToToggle, inViewport);
401
- }, delay);
368
+ if (this.prop.classToToggle) {
369
+ timeoutCallback(() => {
370
+ el.classList.toggle(this.prop.classToToggle, inViewport);
371
+ }, delay);
372
+ }
402
373
 
403
374
  // process callbacks
404
375
  if (inViewport && (states === 'in' || states === 'inout')) {
@@ -430,6 +401,43 @@ export class ScrollView <
430
401
  }
431
402
 
432
403
 
404
+ /**
405
+ * Add a view element
406
+ */
407
+ public addElement (
408
+ element: Element,
409
+ ) {
410
+ this._elements.push(element);
411
+ if (this._intersectionObserver) {
412
+ this._intersectionObserver.observe(element);
413
+ }
414
+ }
415
+
416
+ /**
417
+ * Remove a view element
418
+ */
419
+ public removeElement (
420
+ element: Element,
421
+ ) {
422
+ this._elements = this._elements.filter((el) => el !== element);
423
+ if (this._intersectionObserver) {
424
+ this._intersectionObserver.unobserve(element);
425
+ }
426
+ }
427
+
428
+ /**
429
+ * Remove all view elements
430
+ */
431
+ public removeElements () {
432
+ this._elements.forEach((el) => {
433
+ if (this._intersectionObserver) {
434
+ this._intersectionObserver.unobserve(el);
435
+ }
436
+ });
437
+ this._elements = [];
438
+ }
439
+
440
+
433
441
 
434
442
  /**
435
443
  * Destroy the module