@smartimpact-it/scroll-utils 1.1.0

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 (49) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +158 -0
  3. package/dist/cjs/Bootstrap4AccordionScrollIntoView.js +74 -0
  4. package/dist/cjs/BootstrapAccordionScrollIntoView.js +68 -0
  5. package/dist/cjs/FixHashScrollPosition.js +38 -0
  6. package/dist/cjs/FoundationAccordionScrollIntoView.js +52 -0
  7. package/dist/cjs/ScrollDirection.js +120 -0
  8. package/dist/cjs/ScrollOffset.js +346 -0
  9. package/dist/cjs/ScrollPages.js +97 -0
  10. package/dist/cjs/index.js +93 -0
  11. package/dist/cjs/scrollWithMarginTop.js +34 -0
  12. package/dist/cjs/utils/onReady.js +46 -0
  13. package/dist/cjs/utils/utils.js +77 -0
  14. package/dist/esm/Bootstrap4AccordionScrollIntoView.js +57 -0
  15. package/dist/esm/BootstrapAccordionScrollIntoView.js +51 -0
  16. package/dist/esm/FixHashScrollPosition.js +24 -0
  17. package/dist/esm/FoundationAccordionScrollIntoView.js +35 -0
  18. package/dist/esm/ScrollDirection.js +98 -0
  19. package/dist/esm/ScrollOffset.js +283 -0
  20. package/dist/esm/ScrollPages.js +80 -0
  21. package/dist/esm/index.js +9 -0
  22. package/dist/esm/scrollWithMarginTop.js +25 -0
  23. package/dist/esm/utils/onReady.js +33 -0
  24. package/dist/esm/utils/utils.js +62 -0
  25. package/dist/types/Bootstrap4AccordionScrollIntoView.d.ts +11 -0
  26. package/dist/types/BootstrapAccordionScrollIntoView.d.ts +11 -0
  27. package/dist/types/FixHashScrollPosition.d.ts +7 -0
  28. package/dist/types/FoundationAccordionScrollIntoView.d.ts +11 -0
  29. package/dist/types/ScrollDirection.d.ts +29 -0
  30. package/dist/types/ScrollOffset.d.ts +49 -0
  31. package/dist/types/ScrollPages.d.ts +21 -0
  32. package/dist/types/index.d.ts +9 -0
  33. package/dist/types/scrollWithMarginTop.d.ts +5 -0
  34. package/dist/types/utils/onReady.d.ts +20 -0
  35. package/dist/types/utils/utils.d.ts +4 -0
  36. package/dist/umd/index.js +2 -0
  37. package/dist/umd/index.js.LICENSE.txt +8 -0
  38. package/package.json +101 -0
  39. package/src/Bootstrap4AccordionScrollIntoView.ts +51 -0
  40. package/src/BootstrapAccordionScrollIntoView.ts +45 -0
  41. package/src/FixHashScrollPosition.ts +31 -0
  42. package/src/FoundationAccordionScrollIntoView.ts +31 -0
  43. package/src/ScrollDirection.ts +122 -0
  44. package/src/ScrollOffset.ts +316 -0
  45. package/src/ScrollPages.ts +81 -0
  46. package/src/index.js +9 -0
  47. package/src/scrollWithMarginTop.ts +33 -0
  48. package/src/utils/onReady.ts +38 -0
  49. package/src/utils/utils.ts +78 -0
@@ -0,0 +1,346 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
5
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
11
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
13
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
14
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
15
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
16
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
17
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
18
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
19
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
20
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
21
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
22
+ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
23
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
24
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
25
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
26
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
27
+ var __importDefault = this && this.__importDefault || function (mod) {
28
+ return mod && mod.__esModule ? mod : {
29
+ "default": mod
30
+ };
31
+ };
32
+ Object.defineProperty(exports, "__esModule", {
33
+ value: true
34
+ });
35
+ exports.ScrollOffset = exports.ScrollOffsetPart = void 0;
36
+ var debounce_1 = __importDefault(require("lodash/debounce"));
37
+ var isFunction_1 = __importDefault(require("lodash/isFunction"));
38
+ var _name = /*#__PURE__*/new WeakMap();
39
+ var _selectors = /*#__PURE__*/new WeakMap();
40
+ var _elements = /*#__PURE__*/new WeakMap();
41
+ var _fixedHeight = /*#__PURE__*/new WeakMap();
42
+ var _condition = /*#__PURE__*/new WeakMap();
43
+ var _resizeCondition = /*#__PURE__*/new WeakMap();
44
+ var _resizeConditionValue = /*#__PURE__*/new WeakMap();
45
+ var _totalHeight = /*#__PURE__*/new WeakMap();
46
+ var _isValid = /*#__PURE__*/new WeakMap();
47
+ var _heightCache = /*#__PURE__*/new WeakMap();
48
+ var _getElementHeight = /*#__PURE__*/new WeakMap();
49
+ var ScrollOffsetPart = /*#__PURE__*/function () {
50
+ function ScrollOffsetPart(_ref) {
51
+ var _this = this;
52
+ var _ref$name = _ref.name,
53
+ name = _ref$name === void 0 ? '' : _ref$name,
54
+ _ref$selectors = _ref.selectors,
55
+ selectors = _ref$selectors === void 0 ? [] : _ref$selectors,
56
+ _ref$elements = _ref.elements,
57
+ elements = _ref$elements === void 0 ? [] : _ref$elements,
58
+ _ref$fixedHeight = _ref.fixedHeight,
59
+ fixedHeight = _ref$fixedHeight === void 0 ? false : _ref$fixedHeight,
60
+ _ref$condition = _ref.condition,
61
+ condition = _ref$condition === void 0 ? false : _ref$condition,
62
+ _ref$resizeCondition = _ref.resizeCondition,
63
+ resizeCondition = _ref$resizeCondition === void 0 ? false : _ref$resizeCondition;
64
+ _classCallCheck(this, ScrollOffsetPart);
65
+ _classPrivateFieldInitSpec(this, _name, void 0);
66
+ _classPrivateFieldInitSpec(this, _selectors, void 0);
67
+ _classPrivateFieldInitSpec(this, _elements, void 0);
68
+ _classPrivateFieldInitSpec(this, _fixedHeight, void 0);
69
+ _classPrivateFieldInitSpec(this, _condition, void 0);
70
+ _classPrivateFieldInitSpec(this, _resizeCondition, void 0);
71
+ _classPrivateFieldInitSpec(this, _resizeConditionValue, void 0);
72
+ _classPrivateFieldInitSpec(this, _totalHeight, 0);
73
+ _classPrivateFieldInitSpec(this, _isValid, false);
74
+ _classPrivateFieldInitSpec(this, _heightCache, new WeakMap());
75
+ _defineProperty(this, "setElementHeight", function (element, height) {
76
+ if (!element || !Number.isFinite(height) || height < 0) return;
77
+ _classPrivateFieldGet(_heightCache, _this).set(element, Math.round(height));
78
+ });
79
+ _classPrivateFieldInitSpec(this, _getElementHeight, function (element) {
80
+ if (!element) return 0;
81
+ var cachedHeight = _classPrivateFieldGet(_heightCache, _this).get(element);
82
+ if (cachedHeight !== undefined) return cachedHeight;
83
+ var measuredHeight = element.clientHeight || 0;
84
+ _classPrivateFieldGet(_heightCache, _this).set(element, measuredHeight);
85
+ return measuredHeight;
86
+ });
87
+ _defineProperty(this, "calculate", function () {
88
+ var _classPrivateFieldGet2;
89
+ _classPrivateFieldSet(_isValid, _this, !!((_classPrivateFieldGet2 = _classPrivateFieldGet(_elements, _this)) !== null && _classPrivateFieldGet2 !== void 0 && _classPrivateFieldGet2.length));
90
+ if (_classPrivateFieldGet(_isValid, _this) && _classPrivateFieldGet(_condition, _this) && (0, isFunction_1["default"])(_classPrivateFieldGet(_condition, _this))) {
91
+ _classPrivateFieldSet(_isValid, _this, _classPrivateFieldGet(_isValid, _this) && _classPrivateFieldGet(_condition, _this).call(_this));
92
+ }
93
+ if (_classPrivateFieldGet(_isValid, _this) && _classPrivateFieldGet(_resizeCondition, _this) && (0, isFunction_1["default"])(_classPrivateFieldGet(_resizeCondition, _this))) {
94
+ if (!('resizeConditionValue' in _this)) {
95
+ _classPrivateFieldSet(_resizeConditionValue, _this, _classPrivateFieldGet(_resizeCondition, _this).call(_this));
96
+ }
97
+ _classPrivateFieldSet(_isValid, _this, _classPrivateFieldGet(_isValid, _this) && _classPrivateFieldGet(_resizeConditionValue, _this));
98
+ }
99
+ if (!_classPrivateFieldGet(_isValid, _this)) {
100
+ _classPrivateFieldSet(_totalHeight, _this, 0);
101
+ } else if (_classPrivateFieldGet(_fixedHeight, _this)) {
102
+ _classPrivateFieldSet(_totalHeight, _this, _classPrivateFieldGet(_fixedHeight, _this));
103
+ } else {
104
+ var totalHeight = 0;
105
+ _classPrivateFieldGet(_elements, _this).forEach(function (element) {
106
+ totalHeight += _classPrivateFieldGet(_getElementHeight, _this).call(_this, element);
107
+ });
108
+ _classPrivateFieldSet(_totalHeight, _this, totalHeight);
109
+ }
110
+ return _this;
111
+ });
112
+ _defineProperty(this, "calculateResizeConditions", function () {
113
+ if (_classPrivateFieldGet(_resizeCondition, _this) && (0, isFunction_1["default"])(_classPrivateFieldGet(_resizeCondition, _this))) {
114
+ var oldValue = _classPrivateFieldGet(_resizeConditionValue, _this) || false;
115
+ _classPrivateFieldSet(_resizeConditionValue, _this, _classPrivateFieldGet(_resizeCondition, _this).call(_this));
116
+ return oldValue != _classPrivateFieldGet(_resizeConditionValue, _this);
117
+ }
118
+ return false;
119
+ });
120
+ _classPrivateFieldSet(_name, this, name);
121
+ _classPrivateFieldSet(_selectors, this, (selectors || []).filter(Boolean));
122
+ _classPrivateFieldSet(_elements, this, (elements || []).filter(Boolean));
123
+ _classPrivateFieldSet(_fixedHeight, this, fixedHeight);
124
+ _classPrivateFieldSet(_condition, this, condition);
125
+ _classPrivateFieldSet(_resizeCondition, this, resizeCondition);
126
+ _classPrivateFieldGet(_selectors, this).forEach(function (selector) {
127
+ var newElements = _toConsumableArray(document.querySelectorAll(selector));
128
+ if (newElements.length) {
129
+ _classPrivateFieldSet(_elements, _this, [].concat(_toConsumableArray(_classPrivateFieldGet(_elements, _this)), _toConsumableArray(newElements)));
130
+ }
131
+ });
132
+ this.calculate();
133
+ }
134
+ return _createClass(ScrollOffsetPart, [{
135
+ key: "name",
136
+ get: function get() {
137
+ return _classPrivateFieldGet(_name, this);
138
+ }
139
+ }, {
140
+ key: "totalHeight",
141
+ get: function get() {
142
+ return _classPrivateFieldGet(_totalHeight, this);
143
+ }
144
+ }, {
145
+ key: "isValid",
146
+ get: function get() {
147
+ return _classPrivateFieldGet(_isValid, this);
148
+ }
149
+ }, {
150
+ key: "elements",
151
+ get: function get() {
152
+ return _classPrivateFieldGet(_elements, this);
153
+ }
154
+ }]);
155
+ }();
156
+ exports.ScrollOffsetPart = ScrollOffsetPart;
157
+ /**!
158
+ * ScrollOffset - a class to handle add css variables to the body element,
159
+ * with the value of the "header" parts that are visible
160
+ * so that we can adjust scroll positions etc. based on it
161
+ *
162
+ * Author: Bogdan Barbu
163
+ * Team: Codingheads (codingheads.com)
164
+ */
165
+ var _offsetParts = /*#__PURE__*/new WeakMap();
166
+ var _variables = /*#__PURE__*/new WeakMap();
167
+ var _extraEvents = /*#__PURE__*/new WeakMap();
168
+ var _registerForHoudini = /*#__PURE__*/new WeakMap();
169
+ var _useResizeObserver = /*#__PURE__*/new WeakMap();
170
+ var _measureScheduled = /*#__PURE__*/new WeakMap();
171
+ var _registerCssVariables = /*#__PURE__*/new WeakMap();
172
+ var _calculateOffset = /*#__PURE__*/new WeakMap();
173
+ var _calculateResizeConditions = /*#__PURE__*/new WeakMap();
174
+ var _debouncedCalculateOffset = /*#__PURE__*/new WeakMap();
175
+ var _debouncedCalculateResizeConditions = /*#__PURE__*/new WeakMap();
176
+ var _scheduleCalculateOffset = /*#__PURE__*/new WeakMap();
177
+ var _setupListeners = /*#__PURE__*/new WeakMap();
178
+ var ScrollOffset = /*#__PURE__*/_createClass(
179
+ /**
180
+ * setup the conditions
181
+ */
182
+ function ScrollOffset() {
183
+ var _this2 = this;
184
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
185
+ _ref2$offsetParts = _ref2.offsetParts,
186
+ offsetParts = _ref2$offsetParts === void 0 ? [] : _ref2$offsetParts,
187
+ _ref2$variables = _ref2.variables,
188
+ variables = _ref2$variables === void 0 ? [] : _ref2$variables,
189
+ _ref2$registerForHoud = _ref2.registerForHoudini,
190
+ registerForHoudini = _ref2$registerForHoud === void 0 ? true : _ref2$registerForHoud,
191
+ _ref2$useResizeObserv = _ref2.useResizeObserver,
192
+ useResizeObserver = _ref2$useResizeObserv === void 0 ? true : _ref2$useResizeObserv,
193
+ _ref2$extraEvents = _ref2.extraEvents,
194
+ extraEvents = _ref2$extraEvents === void 0 ? [] : _ref2$extraEvents;
195
+ _classCallCheck(this, ScrollOffset);
196
+ _classPrivateFieldInitSpec(this, _offsetParts, void 0);
197
+ _classPrivateFieldInitSpec(this, _variables, void 0);
198
+ _classPrivateFieldInitSpec(this, _extraEvents, void 0);
199
+ _classPrivateFieldInitSpec(this, _registerForHoudini, void 0);
200
+ _classPrivateFieldInitSpec(this, _useResizeObserver, void 0);
201
+ _classPrivateFieldInitSpec(this, _measureScheduled, false);
202
+ /**
203
+ * register the css variables as length in the Houdini CSS API
204
+ */
205
+ _classPrivateFieldInitSpec(this, _registerCssVariables, function () {
206
+ _classPrivateFieldGet(_variables, _this2).forEach(function (_ref3) {
207
+ var name = _ref3.name;
208
+ window.CSS.registerProperty({
209
+ name: "--".concat(name),
210
+ syntax: '<length>',
211
+ inherits: true,
212
+ initialValue: '0px'
213
+ });
214
+ });
215
+ });
216
+ /**
217
+ * calculate the offsets and set the css variables
218
+ */
219
+ _classPrivateFieldInitSpec(this, _calculateOffset, function () {
220
+ // calculate the conditions
221
+ _classPrivateFieldGet(_offsetParts, _this2).forEach(function (part) {
222
+ return part.calculate();
223
+ });
224
+ // determine the css variables
225
+ var cssVariables = _classPrivateFieldGet(_variables, _this2).map(function (variable) {
226
+ var value = variable.offsetParts.reduce(function (acc, part) {
227
+ if (typeof part == 'string') {
228
+ part = _classPrivateFieldGet(_offsetParts, _this2).find(function (partInfo) {
229
+ return partInfo.name.localeCompare(part) == 0;
230
+ });
231
+ }
232
+ if (part && part.isValid) {
233
+ acc += part.totalHeight;
234
+ }
235
+ return acc;
236
+ }, 0);
237
+ return _objectSpread(_objectSpread({}, variable), {}, {
238
+ value: value
239
+ });
240
+ });
241
+ // output the variables
242
+ cssVariables.forEach(function (_ref4) {
243
+ var name = _ref4.name,
244
+ value = _ref4.value;
245
+ document.documentElement.style.setProperty("--".concat(name), "".concat(value, "px"));
246
+ });
247
+ document.body.dispatchEvent(new CustomEvent('ScrollOffsetChange', {
248
+ bubbles: true
249
+ }));
250
+ });
251
+ /**
252
+ * recalculate values for conditions that only depend on resize
253
+ */
254
+ _classPrivateFieldInitSpec(this, _calculateResizeConditions, function () {
255
+ _classPrivateFieldGet(_offsetParts, _this2).forEach(function (part) {
256
+ return part.calculateResizeConditions();
257
+ });
258
+ });
259
+ _classPrivateFieldInitSpec(this, _debouncedCalculateOffset, (0, debounce_1["default"])(_classPrivateFieldGet(_calculateOffset, this), 32));
260
+ _classPrivateFieldInitSpec(this, _debouncedCalculateResizeConditions, (0, debounce_1["default"])(_classPrivateFieldGet(_calculateResizeConditions, this), 32));
261
+ _classPrivateFieldInitSpec(this, _scheduleCalculateOffset, function () {
262
+ if (_classPrivateFieldGet(_measureScheduled, _this2)) return;
263
+ _classPrivateFieldSet(_measureScheduled, _this2, true);
264
+ requestAnimationFrame(function () {
265
+ _classPrivateFieldSet(_measureScheduled, _this2, false);
266
+ _classPrivateFieldGet(_debouncedCalculateOffset, _this2).call(_this2);
267
+ });
268
+ });
269
+ /**
270
+ * setup event listeners
271
+ */
272
+ _classPrivateFieldInitSpec(this, _setupListeners, function () {
273
+ ['resize', 'orientationchange'].forEach(function (type) {
274
+ window.addEventListener(type, _classPrivateFieldGet(_debouncedCalculateResizeConditions, _this2));
275
+ });
276
+ ['resize', 'orientationchange', 'scrollDirectionChange', 'stickyIsPinned', 'stickyIsUnpinned'].concat(_toConsumableArray(_classPrivateFieldGet(_extraEvents, _this2))).forEach(function (type) {
277
+ return window.addEventListener(type, _classPrivateFieldGet(_scheduleCalculateOffset, _this2));
278
+ });
279
+ // setup resizeObservers for the elements
280
+ if (_classPrivateFieldGet(_useResizeObserver, _this2)) {
281
+ var resizeObserver = new ResizeObserver(function (entries) {
282
+ entries.forEach(function (entry) {
283
+ var _entry$contentRect;
284
+ var target = entry.target;
285
+ var height = Math.round(((_entry$contentRect = entry.contentRect) === null || _entry$contentRect === void 0 ? void 0 : _entry$contentRect.height) || (target === null || target === void 0 ? void 0 : target.clientHeight) || 0);
286
+ if (!target || !height) return;
287
+ _classPrivateFieldGet(_offsetParts, _this2).forEach(function (part) {
288
+ if (part.elements.includes(target)) {
289
+ part.setElementHeight(target, height);
290
+ }
291
+ });
292
+ });
293
+ _classPrivateFieldGet(_scheduleCalculateOffset, _this2).call(_this2);
294
+ });
295
+ _classPrivateFieldGet(_offsetParts, _this2).forEach(function (part) {
296
+ return part.elements.forEach(function (element) {
297
+ return resizeObserver.observe(element);
298
+ });
299
+ });
300
+ }
301
+ });
302
+ // parse the variables
303
+ if (Array.isArray(variables)) {
304
+ _classPrivateFieldSet(_variables, this, variables);
305
+ } else {
306
+ _classPrivateFieldSet(_variables, this, Object.entries(variables).map(function (_ref5) {
307
+ var _ref6 = _slicedToArray(_ref5, 2),
308
+ key = _ref6[0],
309
+ value = _ref6[1];
310
+ return {
311
+ name: key,
312
+ offsetParts: value
313
+ };
314
+ }));
315
+ }
316
+ // take the offset parts from the variables
317
+ var variableOffsetParts = _classPrivateFieldGet(_variables, this).map(function (_ref7) {
318
+ var offsetParts = _ref7.offsetParts;
319
+ return offsetParts.filter(function (part) {
320
+ return part instanceof ScrollOffsetPart;
321
+ });
322
+ }).flat(1);
323
+ // merge with the settings and keep only distinct elements
324
+ offsetParts = _toConsumableArray(new Set([].concat(_toConsumableArray(offsetParts), _toConsumableArray(variableOffsetParts))));
325
+ // parse the offset parts
326
+ _classPrivateFieldSet(_offsetParts, this, offsetParts.map(function (part) {
327
+ var partObject = null;
328
+ if (!(part instanceof ScrollOffsetPart)) {
329
+ partObject = new ScrollOffsetPart(part);
330
+ } else {
331
+ partObject = part;
332
+ }
333
+ partObject.calculate();
334
+ return partObject;
335
+ }));
336
+ _classPrivateFieldSet(_extraEvents, this, extraEvents || []);
337
+ _classPrivateFieldSet(_registerForHoudini, this, registerForHoudini && 'CSS' in window && 'registerProperty' in window.CSS);
338
+ _classPrivateFieldSet(_useResizeObserver, this, 'ResizeObserver' in window && useResizeObserver);
339
+ if (_classPrivateFieldGet(_registerForHoudini, this)) {
340
+ _classPrivateFieldGet(_registerCssVariables, this).call(this);
341
+ }
342
+ _classPrivateFieldGet(_setupListeners, this).call(this);
343
+ _classPrivateFieldGet(_calculateOffset, this).call(this);
344
+ });
345
+ exports.ScrollOffset = ScrollOffset;
346
+ exports["default"] = ScrollOffset;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * ScrollPages - a class to add classes to the body,
5
+ * detecting whether we are above the fold or below
6
+ * (the above-the-fold are can also be set as an existing element)
7
+ *
8
+ * Author: Bogdan Barbu
9
+ * Team: Codingheads (codingheads.com)
10
+ */
11
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
13
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
15
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
17
+ function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
18
+ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
19
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
20
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
21
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
22
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
23
+ Object.defineProperty(exports, "__esModule", {
24
+ value: true
25
+ });
26
+ exports.ScrollPages = void 0;
27
+ var _intersectionElement = /*#__PURE__*/new WeakMap();
28
+ var _observer = /*#__PURE__*/new WeakMap();
29
+ var _isBelowTheFold = /*#__PURE__*/new WeakMap();
30
+ var _belowTheFoldClass = /*#__PURE__*/new WeakMap();
31
+ var _aboveTheFoldClass = /*#__PURE__*/new WeakMap();
32
+ var _ScrollPages_brand = /*#__PURE__*/new WeakSet();
33
+ var ScrollPages = /*#__PURE__*/_createClass(
34
+ /**
35
+ * start an instance
36
+ */
37
+ function ScrollPages() {
38
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
39
+ _ref$intersectionElem = _ref.intersectionElement,
40
+ intersectionElement = _ref$intersectionElem === void 0 ? null : _ref$intersectionElem,
41
+ _ref$belowTheFoldClas = _ref.belowTheFoldClass,
42
+ belowTheFoldClass = _ref$belowTheFoldClas === void 0 ? 'below-the-fold' : _ref$belowTheFoldClas,
43
+ _ref$aboveTheFoldClas = _ref.aboveTheFoldClass,
44
+ aboveTheFoldClass = _ref$aboveTheFoldClas === void 0 ? 'above-the-fold' : _ref$aboveTheFoldClas;
45
+ _classCallCheck(this, ScrollPages);
46
+ /**
47
+ * dispatch an event on the window
48
+ */
49
+ _classPrivateMethodInitSpec(this, _ScrollPages_brand);
50
+ _classPrivateFieldInitSpec(this, _intersectionElement, void 0);
51
+ _classPrivateFieldInitSpec(this, _observer, null);
52
+ _classPrivateFieldInitSpec(this, _isBelowTheFold, false);
53
+ _classPrivateFieldInitSpec(this, _belowTheFoldClass, void 0);
54
+ _classPrivateFieldInitSpec(this, _aboveTheFoldClass, void 0);
55
+ _classPrivateFieldSet(_intersectionElement, this, intersectionElement);
56
+ _classPrivateFieldSet(_belowTheFoldClass, this, belowTheFoldClass);
57
+ _classPrivateFieldSet(_aboveTheFoldClass, this, aboveTheFoldClass);
58
+ _assertClassBrand(_ScrollPages_brand, this, _setupObserver).call(this);
59
+ });
60
+ function _dispatchEvent(name) {
61
+ requestAnimationFrame(function () {
62
+ window.dispatchEvent(new CustomEvent(name));
63
+ });
64
+ }
65
+ function _setupObserver() {
66
+ var _this = this;
67
+ var body = document.body;
68
+ // create the intersection element, if it doesn't exist
69
+ if (!_classPrivateFieldGet(_intersectionElement, this)) {
70
+ var containerPosition = window.getComputedStyle(body).getPropertyValue('position');
71
+ if (!containerPosition || containerPosition == 'static') {
72
+ body.style.position = 'relative';
73
+ }
74
+ _classPrivateFieldSet(_intersectionElement, this, document.createElement('div'));
75
+ _classPrivateFieldGet(_intersectionElement, this).classList.add('second-page-observer');
76
+ _classPrivateFieldGet(_intersectionElement, this).style.cssText = 'pointerEvents: none; visibility: hidden; position: absolute; top: 0; left: 0; right: 0; height: 100vh;';
77
+ body.appendChild(_classPrivateFieldGet(_intersectionElement, this));
78
+ }
79
+ body.classList.add(_classPrivateFieldGet(_aboveTheFoldClass, this));
80
+ _classPrivateFieldSet(_observer, this, new IntersectionObserver(function (entries) {
81
+ var isFirstPage = true;
82
+ entries.forEach(function (entry) {
83
+ if (!entry.isIntersecting) {
84
+ isFirstPage = false;
85
+ }
86
+ });
87
+ if (_classPrivateFieldGet(_isBelowTheFold, _this) != !isFirstPage) {
88
+ _classPrivateFieldSet(_isBelowTheFold, _this, !isFirstPage);
89
+ body.classList[_classPrivateFieldGet(_isBelowTheFold, _this) ? 'add' : 'remove'](_classPrivateFieldGet(_belowTheFoldClass, _this));
90
+ body.classList[!_classPrivateFieldGet(_isBelowTheFold, _this) ? 'add' : 'remove'](_classPrivateFieldGet(_aboveTheFoldClass, _this));
91
+ _assertClassBrand(_ScrollPages_brand, _this, _dispatchEvent).call(_this, 'ScrollPageChange');
92
+ }
93
+ }));
94
+ _classPrivateFieldGet(_observer, this).observe(_classPrivateFieldGet(_intersectionElement, this));
95
+ }
96
+ exports.ScrollPages = ScrollPages;
97
+ exports["default"] = ScrollPages;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.onReady = exports.onInteractive = exports.onComplete = exports.onReadyState = exports.FoundationAccordionScrollIntoView = exports.Bootstrap4AccordionScrollIntoView = exports.BootstrapAccordionScrollIntoView = exports.FixHashScrollPosition = exports.scrollWithMarginTop = exports.ScrollPages = exports.ScrollOffsetPart = exports.ScrollOffset = exports.ScrollDirection = void 0;
7
+ var ScrollDirection_1 = require("./ScrollDirection");
8
+ Object.defineProperty(exports, "ScrollDirection", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return ScrollDirection_1.ScrollDirection;
12
+ }
13
+ });
14
+ var ScrollOffset_1 = require("./ScrollOffset");
15
+ Object.defineProperty(exports, "ScrollOffset", {
16
+ enumerable: true,
17
+ get: function get() {
18
+ return ScrollOffset_1.ScrollOffset;
19
+ }
20
+ });
21
+ Object.defineProperty(exports, "ScrollOffsetPart", {
22
+ enumerable: true,
23
+ get: function get() {
24
+ return ScrollOffset_1.ScrollOffsetPart;
25
+ }
26
+ });
27
+ var ScrollPages_1 = require("./ScrollPages");
28
+ Object.defineProperty(exports, "ScrollPages", {
29
+ enumerable: true,
30
+ get: function get() {
31
+ return ScrollPages_1.ScrollPages;
32
+ }
33
+ });
34
+ var scrollWithMarginTop_1 = require("./scrollWithMarginTop");
35
+ Object.defineProperty(exports, "scrollWithMarginTop", {
36
+ enumerable: true,
37
+ get: function get() {
38
+ return scrollWithMarginTop_1.scrollWithMarginTop;
39
+ }
40
+ });
41
+ var FixHashScrollPosition_1 = require("./FixHashScrollPosition");
42
+ Object.defineProperty(exports, "FixHashScrollPosition", {
43
+ enumerable: true,
44
+ get: function get() {
45
+ return FixHashScrollPosition_1.FixHashScrollPosition;
46
+ }
47
+ });
48
+ var BootstrapAccordionScrollIntoView_1 = require("./BootstrapAccordionScrollIntoView");
49
+ Object.defineProperty(exports, "BootstrapAccordionScrollIntoView", {
50
+ enumerable: true,
51
+ get: function get() {
52
+ return BootstrapAccordionScrollIntoView_1.BootstrapAccordionScrollIntoView;
53
+ }
54
+ });
55
+ var Bootstrap4AccordionScrollIntoView_1 = require("./Bootstrap4AccordionScrollIntoView");
56
+ Object.defineProperty(exports, "Bootstrap4AccordionScrollIntoView", {
57
+ enumerable: true,
58
+ get: function get() {
59
+ return Bootstrap4AccordionScrollIntoView_1.Bootstrap4AccordionScrollIntoView;
60
+ }
61
+ });
62
+ var FoundationAccordionScrollIntoView_1 = require("./FoundationAccordionScrollIntoView");
63
+ Object.defineProperty(exports, "FoundationAccordionScrollIntoView", {
64
+ enumerable: true,
65
+ get: function get() {
66
+ return FoundationAccordionScrollIntoView_1.FoundationAccordionScrollIntoView;
67
+ }
68
+ });
69
+ var onReady_1 = require("./utils/onReady");
70
+ Object.defineProperty(exports, "onReadyState", {
71
+ enumerable: true,
72
+ get: function get() {
73
+ return onReady_1.onReadyState;
74
+ }
75
+ });
76
+ Object.defineProperty(exports, "onComplete", {
77
+ enumerable: true,
78
+ get: function get() {
79
+ return onReady_1.onComplete;
80
+ }
81
+ });
82
+ Object.defineProperty(exports, "onInteractive", {
83
+ enumerable: true,
84
+ get: function get() {
85
+ return onReady_1.onInteractive;
86
+ }
87
+ });
88
+ Object.defineProperty(exports, "onReady", {
89
+ enumerable: true,
90
+ get: function get() {
91
+ return onReady_1.onReady;
92
+ }
93
+ });
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.scrollWithMarginTop = void 0;
7
+ /**
8
+ * Scroll to an element taking into account its "scroll-margin-top"/"scroll-snap-margin-top".
9
+ * This will help with Safari < 14.1 / Safari iOS <= 1.4, which doesn't support "scroll-margin-top".
10
+ */
11
+ var scrollWithMarginTop = function scrollWithMarginTop(element) {
12
+ var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
13
+ var onlyWhenNeeded = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
14
+ if (!element) return;
15
+ var rect = element.getBoundingClientRect();
16
+ var pageYOffset = window.pageYOffset;
17
+ var top = rect.top + pageYOffset;
18
+ var style = window.getComputedStyle(element);
19
+ var scrollMarginTop = parseInt(style.getPropertyValue('scroll-margin-top')) || parseInt(style.getPropertyValue('scroll-snap-margin-top')) || 0;
20
+ var newPosition = top - scrollMarginTop + offset;
21
+ // don't scroll if the element is already visible in the first half of the screen
22
+ if (onlyWhenNeeded) {
23
+ var isVisible = newPosition >= pageYOffset && newPosition + rect.height < pageYOffset + window.innerHeight / 2;
24
+ if (isVisible) {
25
+ return;
26
+ }
27
+ }
28
+ window.scrollTo({
29
+ top: newPosition,
30
+ left: 0,
31
+ behavior: 'smooth'
32
+ });
33
+ };
34
+ exports.scrollWithMarginTop = scrollWithMarginTop;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.onReady = exports.onInteractive = exports.onComplete = exports.onReadyState = void 0;
7
+ /**
8
+ * Run a callback when the document.readyState has a certain value
9
+ * @param {string|string[]} state - the state(s) when to run the callback
10
+ * @param {Function} callback - the callback to run
11
+ */
12
+ var onReadyState = function onReadyState(state, callback) {
13
+ var validStates = Array.isArray(state) ? state : [state];
14
+ var _checkAndRun = function checkAndRun() {
15
+ if (validStates.includes(document.readyState)) {
16
+ document.removeEventListener('readystatechange', _checkAndRun);
17
+ callback();
18
+ return true;
19
+ }
20
+ return false;
21
+ };
22
+ if (!_checkAndRun()) {
23
+ document.addEventListener('readystatechange', _checkAndRun);
24
+ }
25
+ };
26
+ exports.onReadyState = onReadyState;
27
+ /**
28
+ * Run a callback when the document.readyState is 'complete'
29
+ * (DOM + assets are loaded)
30
+ * @param {Function} callback - the callback to run
31
+ */
32
+ var onComplete = function onComplete(callback) {
33
+ return (0, exports.onReadyState)('complete', callback);
34
+ };
35
+ exports.onComplete = onComplete;
36
+ /**
37
+ * Run a callback when the document.readyState is 'interactive'
38
+ * (DOM is loaded - equivalent to DOMContentLoaded)
39
+ * @param {Function} callback - the callback to run
40
+ */
41
+ var onInteractive = function onInteractive(callback) {
42
+ return (0, exports.onReadyState)(['interactive', 'complete'], callback);
43
+ };
44
+ exports.onInteractive = onInteractive;
45
+ exports.onReady = exports.onInteractive;
46
+ exports["default"] = exports.onReady;