vscroll 1.4.3 → 1.4.4

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 (55) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +17 -16
  3. package/dist/bundles/vscroll.esm5.js +107 -103
  4. package/dist/bundles/vscroll.esm5.js.map +1 -1
  5. package/dist/bundles/vscroll.esm5.min.js +2 -2
  6. package/dist/bundles/vscroll.esm5.min.js.map +1 -1
  7. package/dist/bundles/vscroll.esm6.js +104 -103
  8. package/dist/bundles/vscroll.esm6.js.map +1 -1
  9. package/dist/bundles/vscroll.esm6.min.js +2 -2
  10. package/dist/bundles/vscroll.esm6.min.js.map +1 -1
  11. package/dist/bundles/vscroll.umd.js +108 -104
  12. package/dist/bundles/vscroll.umd.js.map +1 -1
  13. package/dist/bundles/vscroll.umd.min.js +2 -2
  14. package/dist/bundles/vscroll.umd.min.js.map +1 -1
  15. package/dist/esm2015/classes/domRoutines.js +82 -69
  16. package/dist/esm2015/classes/domRoutines.js.map +1 -1
  17. package/dist/esm2015/classes/logger.js +2 -2
  18. package/dist/esm2015/classes/logger.js.map +1 -1
  19. package/dist/esm2015/classes/paddings.js +5 -5
  20. package/dist/esm2015/classes/paddings.js.map +1 -1
  21. package/dist/esm2015/classes/viewport.js +9 -21
  22. package/dist/esm2015/classes/viewport.js.map +1 -1
  23. package/dist/esm2015/interfaces/index.js.map +1 -1
  24. package/dist/esm2015/interfaces/routines.js +2 -0
  25. package/dist/esm2015/interfaces/routines.js.map +1 -0
  26. package/dist/esm2015/scroller.js +3 -3
  27. package/dist/esm2015/scroller.js.map +1 -1
  28. package/dist/esm2015/version.js +1 -1
  29. package/dist/esm2015/version.js.map +1 -1
  30. package/dist/esm2015/workflow.js +2 -2
  31. package/dist/esm2015/workflow.js.map +1 -1
  32. package/dist/esm5/classes/domRoutines.js +85 -69
  33. package/dist/esm5/classes/domRoutines.js.map +1 -1
  34. package/dist/esm5/classes/logger.js +2 -2
  35. package/dist/esm5/classes/logger.js.map +1 -1
  36. package/dist/esm5/classes/paddings.js +5 -5
  37. package/dist/esm5/classes/paddings.js.map +1 -1
  38. package/dist/esm5/classes/viewport.js +9 -21
  39. package/dist/esm5/classes/viewport.js.map +1 -1
  40. package/dist/esm5/interfaces/index.js.map +1 -1
  41. package/dist/esm5/interfaces/routines.js +2 -0
  42. package/dist/esm5/interfaces/routines.js.map +1 -0
  43. package/dist/esm5/scroller.js +3 -3
  44. package/dist/esm5/scroller.js.map +1 -1
  45. package/dist/esm5/version.js +1 -1
  46. package/dist/esm5/version.js.map +1 -1
  47. package/dist/esm5/workflow.js +2 -2
  48. package/dist/esm5/workflow.js.map +1 -1
  49. package/dist/typings/classes/domRoutines.d.ts +21 -19
  50. package/dist/typings/classes/logger.d.ts +1 -1
  51. package/dist/typings/classes/paddings.d.ts +2 -2
  52. package/dist/typings/classes/viewport.d.ts +1 -4
  53. package/dist/typings/interfaces/index.d.ts +2 -1
  54. package/dist/typings/interfaces/routines.d.ts +154 -0
  55. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * vscroll (https://github.com/dhilt/vscroll) UMD
3
- * Version: 1.4.3 (2021-11-30T02:54:04.845Z)
3
+ * Version: 1.4.4 (2022-01-22T00:43:23.053Z)
4
4
  * Author: Denis Hilt
5
5
  * License: MIT
6
6
  */
@@ -94,7 +94,7 @@
94
94
 
95
95
  /**
96
96
  * vscroll (https://github.com/dhilt/vscroll) FESM5
97
- * Version: 1.4.3 (2021-11-30T02:54:00.541Z)
97
+ * Version: 1.4.4 (2022-01-22T00:43:17.423Z)
98
98
  * Author: Denis Hilt
99
99
  * License: MIT
100
100
  */
@@ -435,7 +435,7 @@
435
435
 
436
436
  var core = {
437
437
  name: 'vscroll',
438
- version: '1.4.3'
438
+ version: '1.4.4'
439
439
  };
440
440
 
441
441
  var instanceCount$1 = 0;
@@ -3075,7 +3075,7 @@
3075
3075
  this.getWorkflowCycleData = function () {
3076
3076
  return settings.instanceIndex + "-" + scroller.state.cycle.count;
3077
3077
  };
3078
- this.getScrollPosition = function (element) { return scroller.routines.getScrollPosition(element); };
3078
+ this.getScrollPosition = function () { return scroller.routines.getScrollPosition(); };
3079
3079
  this.log(function () {
3080
3080
  return 'vscroll Workflow has been started, ' +
3081
3081
  ("core: " + packageInfo.core.name + " v" + packageInfo.core.version + ", ") +
@@ -3135,7 +3135,7 @@
3135
3135
  };
3136
3136
  Logger.prototype.prepareForLog = function (data) {
3137
3137
  return data instanceof Event && data.target
3138
- ? this.getScrollPosition(data.target)
3138
+ ? this.getScrollPosition()
3139
3139
  : data;
3140
3140
  };
3141
3141
  Logger.prototype.logProcess = function (data) {
@@ -3230,64 +3230,63 @@
3230
3230
  }());
3231
3231
 
3232
3232
  var Routines = /** @class */ (function () {
3233
- function Routines(settings) {
3234
- this.horizontal = settings.horizontal;
3235
- this.window = settings.windowViewport;
3236
- this.viewport = settings.viewport;
3233
+ function Routines(element, settings) {
3234
+ this.settings = {
3235
+ viewport: settings.viewport,
3236
+ horizontal: settings.horizontal,
3237
+ window: settings.windowViewport
3238
+ };
3239
+ this.element = element;
3240
+ this.viewport = this.getViewportElement();
3241
+ this.onInit(settings);
3237
3242
  }
3238
3243
  Routines.prototype.checkElement = function (element) {
3239
3244
  if (!element) {
3240
3245
  throw new Error('HTML element is not defined');
3241
3246
  }
3242
3247
  };
3243
- Routines.prototype.getHostElement = function (element) {
3244
- if (this.window) {
3248
+ Routines.prototype.getViewportElement = function () {
3249
+ if (this.settings.window) {
3245
3250
  return document.documentElement;
3246
3251
  }
3247
- if (this.viewport) {
3248
- return this.viewport;
3252
+ if (this.settings.viewport) {
3253
+ return this.settings.viewport;
3249
3254
  }
3250
- this.checkElement(element);
3251
- var parent = element.parentElement;
3255
+ this.checkElement(this.element);
3256
+ var parent = this.element.parentElement;
3252
3257
  this.checkElement(parent);
3253
3258
  return parent;
3254
3259
  };
3255
- Routines.prototype.getScrollEventReceiver = function (element) {
3256
- if (this.window) {
3257
- return window;
3260
+ Routines.prototype.onInit = function (settings) {
3261
+ if (settings.windowViewport) {
3262
+ if ('scrollRestoration' in history) {
3263
+ history.scrollRestoration = 'manual';
3264
+ }
3258
3265
  }
3259
- return this.getHostElement(element);
3260
- };
3261
- Routines.prototype.setupScrollRestoration = function () {
3262
- if ('scrollRestoration' in history) {
3263
- history.scrollRestoration = 'manual';
3266
+ if (settings.dismissOverflowAnchor) {
3267
+ this.viewport.style.overflowAnchor = 'none';
3264
3268
  }
3265
3269
  };
3266
- Routines.prototype.dismissOverflowAnchor = function (element) {
3267
- this.checkElement(element);
3268
- element.style.overflowAnchor = 'none';
3269
- };
3270
3270
  Routines.prototype.findElementBySelector = function (element, selector) {
3271
3271
  this.checkElement(element);
3272
3272
  return element.querySelector(selector);
3273
3273
  };
3274
- Routines.prototype.findPaddingElement = function (element, direction) {
3275
- return this.findElementBySelector(element, "[data-padding-" + direction + "]");
3274
+ Routines.prototype.findPaddingElement = function (direction) {
3275
+ return this.findElementBySelector(this.element, "[data-padding-" + direction + "]");
3276
3276
  };
3277
- Routines.prototype.findItemElement = function (element, id) {
3278
- return this.findElementBySelector(element, "[data-sid=\"" + id + "\"]");
3277
+ Routines.prototype.findItemElement = function (id) {
3278
+ return this.findElementBySelector(this.element, "[data-sid=\"" + id + "\"]");
3279
3279
  };
3280
- Routines.prototype.getScrollPosition = function (element) {
3281
- if (this.window) {
3282
- return window.pageYOffset;
3280
+ Routines.prototype.getScrollPosition = function () {
3281
+ if (this.settings.window) {
3282
+ return this.settings.horizontal ? window.pageXOffset : window.pageYOffset;
3283
3283
  }
3284
- this.checkElement(element);
3285
- return element[this.horizontal ? 'scrollLeft' : 'scrollTop'];
3284
+ return this.viewport[this.settings.horizontal ? 'scrollLeft' : 'scrollTop'];
3286
3285
  };
3287
- Routines.prototype.setScrollPosition = function (element, value) {
3286
+ Routines.prototype.setScrollPosition = function (value) {
3288
3287
  value = Math.max(0, value);
3289
- if (this.window) {
3290
- if (this.horizontal) {
3288
+ if (this.settings.window) {
3289
+ if (this.settings.horizontal) {
3291
3290
  window.scrollTo(value, window.scrollY);
3292
3291
  }
3293
3292
  else {
@@ -3295,49 +3294,62 @@
3295
3294
  }
3296
3295
  return;
3297
3296
  }
3298
- this.checkElement(element);
3299
- element[this.horizontal ? 'scrollLeft' : 'scrollTop'] = value;
3297
+ this.viewport[this.settings.horizontal ? 'scrollLeft' : 'scrollTop'] = value;
3300
3298
  };
3301
- Routines.prototype.getParams = function (element, doNotBind) {
3299
+ Routines.prototype.getElementParams = function (element) {
3302
3300
  this.checkElement(element);
3303
- if (this.window && doNotBind) {
3304
- var clientWidth = element.clientWidth, clientHeight = element.clientHeight, clientLeft = element.clientLeft, clientTop = element.clientTop;
3305
- return {
3306
- 'height': clientHeight,
3307
- 'width': clientWidth,
3308
- 'top': clientTop,
3309
- 'bottom': clientTop + clientHeight,
3310
- 'left': clientLeft,
3311
- 'right': clientLeft + clientWidth,
3312
- 'x': clientLeft,
3313
- 'y': clientTop,
3314
- 'toJSON': function () { return null; },
3315
- };
3316
- }
3317
3301
  return element.getBoundingClientRect();
3318
3302
  };
3319
- Routines.prototype.getSize = function (element, doNotBind) {
3320
- return this.getParams(element, doNotBind)[this.horizontal ? 'width' : 'height'];
3303
+ Routines.prototype.getWindowParams = function () {
3304
+ var _a = this.viewport, clientWidth = _a.clientWidth, clientHeight = _a.clientHeight, clientLeft = _a.clientLeft, clientTop = _a.clientTop;
3305
+ return {
3306
+ 'height': clientHeight,
3307
+ 'width': clientWidth,
3308
+ 'top': clientTop,
3309
+ 'bottom': clientTop + clientHeight,
3310
+ 'left': clientLeft,
3311
+ 'right': clientLeft + clientWidth,
3312
+ 'x': clientLeft,
3313
+ 'y': clientTop,
3314
+ 'toJSON': function () { return null; },
3315
+ };
3316
+ };
3317
+ Routines.prototype.getSize = function (element) {
3318
+ return this.getElementParams(element)[this.settings.horizontal ? 'width' : 'height'];
3319
+ };
3320
+ Routines.prototype.getScrollerSize = function () {
3321
+ return this.getElementParams(this.element)[this.settings.horizontal ? 'width' : 'height'];
3322
+ };
3323
+ Routines.prototype.getViewportSize = function () {
3324
+ if (this.settings.window) {
3325
+ return this.getWindowParams()[this.settings.horizontal ? 'width' : 'height'];
3326
+ }
3327
+ return this.getSize(this.viewport);
3321
3328
  };
3322
3329
  Routines.prototype.getSizeStyle = function (element) {
3323
3330
  this.checkElement(element);
3324
- var size = element.style[this.horizontal ? 'width' : 'height'];
3331
+ var size = element.style[this.settings.horizontal ? 'width' : 'height'];
3325
3332
  return parseFloat(size) || 0;
3326
3333
  };
3327
3334
  Routines.prototype.setSizeStyle = function (element, value) {
3328
3335
  this.checkElement(element);
3329
3336
  value = Math.max(0, Math.round(value));
3330
- element.style[this.horizontal ? 'width' : 'height'] = value + "px";
3337
+ element.style[this.settings.horizontal ? 'width' : 'height'] = value + "px";
3331
3338
  };
3332
- Routines.prototype.getEdge = function (element, direction, doNotBind) {
3333
- var params = this.getParams(element, doNotBind);
3339
+ Routines.prototype.getEdge = function (element, direction) {
3340
+ var horizontal = this.settings.horizontal;
3341
+ var params = this.getElementParams(element);
3334
3342
  var isFwd = direction === exports.Direction.forward;
3335
- return params[isFwd ? (this.horizontal ? 'right' : 'bottom') : (this.horizontal ? 'left' : 'top')];
3343
+ return params[isFwd ? (horizontal ? 'right' : 'bottom') : (horizontal ? 'left' : 'top')];
3336
3344
  };
3337
- Routines.prototype.getEdge2 = function (element, direction, relativeElement, opposite) {
3338
- // vertical only ?
3339
- return element.offsetTop - (relativeElement ? relativeElement.scrollTop : 0) +
3340
- (direction === (!opposite ? exports.Direction.forward : exports.Direction.backward) ? this.getSize(element) : 0);
3345
+ Routines.prototype.getViewportEdge = function (direction) {
3346
+ var _a = this.settings, window = _a.window, horizontal = _a.horizontal;
3347
+ if (window) {
3348
+ var params = this.getWindowParams();
3349
+ var isFwd = direction === exports.Direction.forward;
3350
+ return params[isFwd ? (horizontal ? 'right' : 'bottom') : (horizontal ? 'left' : 'top')];
3351
+ }
3352
+ return this.getEdge(this.viewport, direction);
3341
3353
  };
3342
3354
  Routines.prototype.makeElementVisible = function (element) {
3343
3355
  this.checkElement(element);
@@ -3349,9 +3361,12 @@
3349
3361
  this.checkElement(element);
3350
3362
  element.style.display = 'none';
3351
3363
  };
3352
- Routines.prototype.getOffset = function (element) {
3353
- this.checkElement(element);
3354
- return (this.horizontal ? element.offsetLeft : element.offsetTop) || 0;
3364
+ Routines.prototype.getOffset = function () {
3365
+ var _this = this;
3366
+ var get = function (element) {
3367
+ return (_this.settings.horizontal ? element.offsetLeft : element.offsetTop) || 0;
3368
+ };
3369
+ return get(this.element) - (!this.settings.window ? get(this.viewport) : 0);
3355
3370
  };
3356
3371
  Routines.prototype.scrollTo = function (element, argument) {
3357
3372
  this.checkElement(element);
@@ -3365,16 +3380,17 @@
3365
3380
  var animationFrameId = requestAnimationFrame(function () { return cb(); });
3366
3381
  return function () { return cancelAnimationFrame(animationFrameId); };
3367
3382
  };
3368
- Routines.prototype.onScroll = function (element, handler) {
3369
- element.addEventListener('scroll', handler);
3370
- return function () { return element.removeEventListener('scroll', handler); };
3383
+ Routines.prototype.onScroll = function (handler) {
3384
+ var eventReceiver = this.settings.window ? window : this.viewport;
3385
+ eventReceiver.addEventListener('scroll', handler);
3386
+ return function () { return eventReceiver.removeEventListener('scroll', handler); };
3371
3387
  };
3372
3388
  return Routines;
3373
3389
  }());
3374
3390
 
3375
3391
  var Padding = /** @class */ (function () {
3376
- function Padding(element, direction, routines) {
3377
- var found = routines.findPaddingElement(element, direction);
3392
+ function Padding(direction, routines) {
3393
+ var found = routines.findPaddingElement(direction);
3378
3394
  routines.checkElement(found);
3379
3395
  this.element = found;
3380
3396
  this.direction = direction;
@@ -3396,10 +3412,10 @@
3396
3412
  return Padding;
3397
3413
  }());
3398
3414
  var Paddings = /** @class */ (function () {
3399
- function Paddings(element, routines, settings) {
3415
+ function Paddings(routines, settings) {
3400
3416
  this.settings = settings;
3401
- this.forward = new Padding(element, exports.Direction.forward, routines);
3402
- this.backward = new Padding(element, exports.Direction.backward, routines);
3417
+ this.forward = new Padding(exports.Direction.forward, routines);
3418
+ this.backward = new Padding(exports.Direction.backward, routines);
3403
3419
  }
3404
3420
  Paddings.prototype.byDirection = function (direction, opposite) {
3405
3421
  return direction === exports.Direction.backward
@@ -3451,21 +3467,12 @@
3451
3467
  }());
3452
3468
 
3453
3469
  var Viewport = /** @class */ (function () {
3454
- function Viewport(element, settings, routines, state, logger) {
3455
- this.element = element;
3470
+ function Viewport(settings, routines, state, logger) {
3456
3471
  this.settings = settings;
3457
3472
  this.routines = routines;
3458
3473
  this.state = state;
3459
3474
  this.logger = logger;
3460
- this.hostElement = this.routines.getHostElement(this.element);
3461
- this.scrollEventReceiver = this.routines.getScrollEventReceiver(this.element);
3462
- if (settings.windowViewport) {
3463
- this.routines.setupScrollRestoration();
3464
- }
3465
- if (settings.dismissOverflowAnchor) {
3466
- this.routines.dismissOverflowAnchor(this.hostElement);
3467
- }
3468
- this.paddings = new Paddings(this.element, this.routines, settings);
3475
+ this.paddings = new Paddings(this.routines, settings);
3469
3476
  }
3470
3477
  Viewport.prototype.reset = function (startIndex) {
3471
3478
  this.setOffset();
@@ -3479,7 +3486,7 @@
3479
3486
  this.logger.log(function () { return ['setting scroll position at', value, '[cancelled]']; });
3480
3487
  return value;
3481
3488
  }
3482
- this.routines.setScrollPosition(this.hostElement, value);
3489
+ this.routines.setScrollPosition(value);
3483
3490
  var position = this.scrollPosition;
3484
3491
  this.logger.log(function () { return __spreadArray([
3485
3492
  'setting scroll position at', position
@@ -3488,7 +3495,7 @@
3488
3495
  };
3489
3496
  Object.defineProperty(Viewport.prototype, "scrollPosition", {
3490
3497
  get: function () {
3491
- return this.routines.getScrollPosition(this.hostElement);
3498
+ return this.routines.getScrollPosition();
3492
3499
  },
3493
3500
  set: function (value) {
3494
3501
  this.setPosition(value);
@@ -3497,10 +3504,10 @@
3497
3504
  configurable: true
3498
3505
  });
3499
3506
  Viewport.prototype.getSize = function () {
3500
- return this.routines.getSize(this.hostElement, true);
3507
+ return this.routines.getViewportSize();
3501
3508
  };
3502
3509
  Viewport.prototype.getScrollableSize = function () {
3503
- return this.routines.getSize(this.element);
3510
+ return this.routines.getScrollerSize();
3504
3511
  };
3505
3512
  Viewport.prototype.getMaxScrollPosition = function () {
3506
3513
  return this.getScrollableSize() - this.getSize();
@@ -3509,16 +3516,13 @@
3509
3516
  return this.getSize() * this.settings.padding;
3510
3517
  };
3511
3518
  Viewport.prototype.getEdge = function (direction) {
3512
- return this.routines.getEdge(this.hostElement, direction, true);
3519
+ return this.routines.getViewportEdge(direction);
3513
3520
  };
3514
3521
  Viewport.prototype.setOffset = function () {
3515
- this.offset = this.routines.getOffset(this.element);
3516
- if (!this.settings.windowViewport) {
3517
- this.offset -= this.routines.getOffset(this.hostElement);
3518
- }
3522
+ this.offset = this.routines.getOffset();
3519
3523
  };
3520
3524
  Viewport.prototype.findItemElementById = function (id) {
3521
- return this.routines.findItemElement(this.element, id);
3525
+ return this.routines.findItemElement(id);
3522
3526
  };
3523
3527
  Viewport.prototype.getEdgeVisibleItem = function (items, direction) {
3524
3528
  var bwd = direction === exports.Direction.backward;
@@ -5216,15 +5220,15 @@
5216
5220
  throw new Error(INVALID_DATASOURCE_PREFIX + " " + get.errors[0]);
5217
5221
  }
5218
5222
  var packageInfo = scroller ? scroller.state.packageInfo : { consumer: consumer, core: core };
5219
- element = scroller ? scroller.viewport.element : element;
5223
+ element = scroller ? scroller.routines.element : element;
5220
5224
  workflow = scroller ? scroller.workflow : workflow;
5221
5225
  this.workflow = workflow;
5222
5226
  this.settings = new Settings(datasource.settings, datasource.devSettings, ++instanceCount);
5223
5227
  this.logger = new Logger(this, packageInfo, datasource.adapter);
5224
- this.routines = new Routines(this.settings);
5228
+ this.routines = new Routines(element, this.settings);
5225
5229
  this.state = new State(packageInfo, this.settings, scroller ? scroller.state : void 0);
5226
5230
  this.buffer = new Buffer(this.settings, workflow.onDataChanged, this.logger);
5227
- this.viewport = new Viewport(element, this.settings, this.routines, this.state, this.logger);
5231
+ this.viewport = new Viewport(this.settings, this.routines, this.state, this.logger);
5228
5232
  this.logger.object('vscroll settings object', this.settings, true);
5229
5233
  this.initDatasource(datasource, scroller);
5230
5234
  }
@@ -5519,13 +5523,13 @@
5519
5523
  status: ProcessStatus.start
5520
5524
  });
5521
5525
  // set up scroll event listener
5522
- var _a = this.scroller, scrollEventReceiver = _a.viewport.scrollEventReceiver, routines = _a.routines;
5526
+ var routines = this.scroller.routines;
5523
5527
  var onScrollHandler = function (event) { return _this.callWorkflow({
5524
5528
  process: CommonProcess.scroll,
5525
5529
  status: ProcessStatus.start,
5526
5530
  payload: { event: event }
5527
5531
  }); };
5528
- this.offScroll = routines.onScroll(scrollEventReceiver, onScrollHandler);
5532
+ this.offScroll = routines.onScroll(onScrollHandler);
5529
5533
  };
5530
5534
  Workflow.prototype.changeItems = function (items) {
5531
5535
  this.propagateChanges(items);