@studiometa/js-toolkit 2.7.0 → 2.9.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.
- package/Base/Base.cjs +325 -0
- package/Base/Base.cjs.map +7 -0
- package/Base/Base.d.ts +197 -0
- package/Base/Base.js +304 -0
- package/Base/Base.js.map +7 -0
- package/Base/features.cjs +1 -3
- package/Base/features.cjs.map +2 -2
- package/Base/features.d.ts +1 -1
- package/Base/features.js +1 -3
- package/Base/features.js.map +2 -2
- package/Base/index.cjs +2 -292
- package/Base/index.cjs.map +3 -3
- package/Base/index.d.ts +1 -193
- package/Base/index.js +1 -290
- package/Base/index.js.map +2 -2
- package/Base/managers/AbstractManager.d.ts +2 -2
- package/Base/managers/ChildrenManager.cjs +11 -7
- package/Base/managers/ChildrenManager.cjs.map +2 -2
- package/Base/managers/ChildrenManager.d.ts +1 -1
- package/Base/managers/ChildrenManager.js +12 -8
- package/Base/managers/ChildrenManager.js.map +2 -2
- package/Base/managers/OptionsManager.d.ts +9 -9
- package/Base/managers/RefsManager.cjs +13 -8
- package/Base/managers/RefsManager.cjs.map +2 -2
- package/Base/managers/RefsManager.js +14 -9
- package/Base/managers/RefsManager.js.map +2 -2
- package/Base/managers/ResponsiveOptionsManager.d.ts +1 -1
- package/Base/managers/ServicesManager.d.ts +2 -2
- package/Base/managers/index.cjs +0 -2
- package/Base/managers/index.cjs.map +2 -2
- package/Base/managers/index.d.ts +0 -1
- package/Base/managers/index.js +0 -2
- package/Base/managers/index.js.map +2 -2
- package/Base/types.d.ts +1 -1
- package/Base/utils.cjs +28 -1
- package/Base/utils.cjs.map +2 -2
- package/Base/utils.d.ts +4 -0
- package/Base/utils.js +29 -2
- package/Base/utils.js.map +2 -2
- package/decorators/index.cjs +1 -1
- package/decorators/index.cjs.map +2 -2
- package/decorators/index.d.ts +1 -1
- package/decorators/index.js +1 -1
- package/decorators/index.js.map +1 -1
- package/decorators/withDrag.d.ts +1 -1
- package/decorators/withScrolledInView/index.cjs +22 -0
- package/decorators/withScrolledInView/index.cjs.map +7 -0
- package/decorators/withScrolledInView/index.d.ts +2 -0
- package/decorators/withScrolledInView/index.js +3 -0
- package/decorators/withScrolledInView/index.js.map +7 -0
- package/decorators/withScrolledInView/types.cjs +19 -0
- package/decorators/withScrolledInView/types.cjs.map +7 -0
- package/decorators/withScrolledInView/types.d.ts +2 -0
- package/decorators/withScrolledInView/types.js +1 -0
- package/decorators/withScrolledInView/types.js.map +7 -0
- package/decorators/withScrolledInView/utils.cjs +99 -0
- package/decorators/withScrolledInView/utils.cjs.map +7 -0
- package/decorators/withScrolledInView/utils.d.ts +17 -0
- package/decorators/withScrolledInView/utils.js +77 -0
- package/decorators/withScrolledInView/utils.js.map +7 -0
- package/decorators/{withScrolledInView.cjs → withScrolledInView/withScrolledInView.cjs} +47 -46
- package/decorators/withScrolledInView/withScrolledInView.cjs.map +7 -0
- package/decorators/{withScrolledInView.d.ts → withScrolledInView/withScrolledInView.d.ts} +7 -11
- package/decorators/{withScrolledInView.js → withScrolledInView/withScrolledInView.js} +53 -45
- package/decorators/withScrolledInView/withScrolledInView.js.map +7 -0
- package/helpers/createApp.d.ts +1 -1
- package/helpers/getClosestParent.cjs +3 -11
- package/helpers/getClosestParent.cjs.map +2 -2
- package/helpers/getClosestParent.js +3 -11
- package/helpers/getClosestParent.js.map +2 -2
- package/helpers/importWhenIdle.d.ts +1 -1
- package/package.json +2 -2
- package/services/drag.d.ts +2 -2
- package/services/index.d.ts +7 -7
- package/services/key.d.ts +1 -1
- package/services/load.d.ts +1 -1
- package/services/pointer.d.ts +1 -1
- package/services/raf.d.ts +1 -1
- package/services/resize.d.ts +1 -1
- package/services/scroll.d.ts +1 -1
- package/utils/Queue.cjs +4 -1
- package/utils/Queue.cjs.map +2 -2
- package/utils/Queue.d.ts +1 -1
- package/utils/Queue.js +4 -1
- package/utils/Queue.js.map +2 -2
- package/utils/SmartQueue.cjs +57 -0
- package/utils/SmartQueue.cjs.map +7 -0
- package/utils/SmartQueue.d.ts +25 -0
- package/utils/SmartQueue.js +29 -0
- package/utils/SmartQueue.js.map +7 -0
- package/utils/css/animate.cjs +18 -1
- package/utils/css/animate.cjs.map +3 -3
- package/utils/css/animate.d.ts +6 -3
- package/utils/css/animate.js +18 -1
- package/utils/css/animate.js.map +3 -3
- package/utils/css/getOffsetSizes.cjs +1 -1
- package/utils/css/getOffsetSizes.cjs.map +1 -1
- package/utils/css/getOffsetSizes.js +1 -1
- package/utils/css/getOffsetSizes.js.map +1 -1
- package/utils/css/matrix.d.ts +1 -1
- package/utils/css/transform.d.ts +1 -1
- package/utils/css/transition.d.ts +2 -2
- package/utils/dom/ancestors.cjs +37 -0
- package/utils/dom/ancestors.cjs.map +7 -0
- package/utils/dom/ancestors.d.ts +8 -0
- package/utils/dom/ancestors.js +15 -0
- package/utils/dom/ancestors.js.map +7 -0
- package/utils/dom/index.cjs +21 -0
- package/utils/dom/index.cjs.map +7 -0
- package/utils/dom/index.d.ts +1 -0
- package/utils/dom/index.js +2 -0
- package/utils/dom/index.js.map +7 -0
- package/utils/index.cjs +4 -0
- package/utils/index.cjs.map +2 -2
- package/utils/index.d.ts +3 -0
- package/utils/index.js +4 -0
- package/utils/index.js.map +2 -2
- package/utils/is.cjs +1 -1
- package/utils/is.cjs.map +2 -2
- package/utils/is.js +1 -1
- package/utils/is.js.map +2 -2
- package/utils/math/createEases.d.ts +1 -1
- package/utils/nextTick.cjs +2 -5
- package/utils/nextTick.cjs.map +2 -2
- package/utils/nextTick.js +2 -5
- package/utils/nextTick.js.map +2 -2
- package/utils/tween.cjs +3 -2
- package/utils/tween.cjs.map +2 -2
- package/utils/tween.d.ts +2 -1
- package/utils/tween.js +3 -2
- package/utils/tween.js.map +2 -2
- package/utils/wait.cjs +31 -0
- package/utils/wait.cjs.map +7 -0
- package/utils/wait.d.ts +1 -0
- package/utils/wait.js +9 -0
- package/utils/wait.js.map +7 -0
- package/Base/managers/AsyncChildrenManager.cjs +0 -61
- package/Base/managers/AsyncChildrenManager.cjs.map +0 -7
- package/Base/managers/AsyncChildrenManager.d.ts +0 -18
- package/Base/managers/AsyncChildrenManager.js +0 -39
- package/Base/managers/AsyncChildrenManager.js.map +0 -7
- package/decorators/withScrolledInView.cjs.map +0 -7
- package/decorators/withScrolledInView.js.map +0 -7
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { isNumber, isString } from "../../utils/index.js";
|
|
2
|
+
const units = {
|
|
3
|
+
px: "px",
|
|
4
|
+
vh: "vh",
|
|
5
|
+
vw: "vw",
|
|
6
|
+
vmin: "vmin",
|
|
7
|
+
vmax: "vmax",
|
|
8
|
+
percent: "%"
|
|
9
|
+
};
|
|
10
|
+
const namedOffsets = {
|
|
11
|
+
start: 0,
|
|
12
|
+
center: 0.5,
|
|
13
|
+
end: 1
|
|
14
|
+
};
|
|
15
|
+
function normalizeOffset(offsets) {
|
|
16
|
+
return offsets.split("/").map((offset) => offset.trim().split(" ").slice(0, 2));
|
|
17
|
+
}
|
|
18
|
+
function parseNamedOffset(offset) {
|
|
19
|
+
if (isNumber(offset)) {
|
|
20
|
+
return offset;
|
|
21
|
+
}
|
|
22
|
+
if (isNumber(namedOffsets[offset])) {
|
|
23
|
+
return namedOffsets[offset];
|
|
24
|
+
}
|
|
25
|
+
if (isNumber(Number(offset))) {
|
|
26
|
+
return Number(offset);
|
|
27
|
+
}
|
|
28
|
+
if (isString(offset) && offset.endsWith(units.percent)) {
|
|
29
|
+
return Number.parseFloat(offset) / 100;
|
|
30
|
+
}
|
|
31
|
+
return offset;
|
|
32
|
+
}
|
|
33
|
+
function getEdgeWithOffset(start, size, offset) {
|
|
34
|
+
if (isNumber(offset)) {
|
|
35
|
+
return start + size * offset;
|
|
36
|
+
}
|
|
37
|
+
const parsedNamedOffset = parseNamedOffset(offset);
|
|
38
|
+
if (isNumber(parsedNamedOffset)) {
|
|
39
|
+
return start + size * parsedNamedOffset;
|
|
40
|
+
}
|
|
41
|
+
if (isString(parsedNamedOffset)) {
|
|
42
|
+
const parsedOffset = Number.parseFloat(parsedNamedOffset);
|
|
43
|
+
if (parsedNamedOffset.endsWith(units.px)) {
|
|
44
|
+
return start + parsedOffset;
|
|
45
|
+
}
|
|
46
|
+
if (parsedNamedOffset.endsWith(units.vh)) {
|
|
47
|
+
return start + parsedOffset * window.innerHeight / 100;
|
|
48
|
+
}
|
|
49
|
+
if (parsedNamedOffset.endsWith(units.vw)) {
|
|
50
|
+
return start + parsedOffset * window.innerWidth / 100;
|
|
51
|
+
}
|
|
52
|
+
if (parsedNamedOffset.endsWith(units.vmin)) {
|
|
53
|
+
return start + parsedOffset * Math.min(window.innerWidth, window.innerHeight) / 100;
|
|
54
|
+
}
|
|
55
|
+
if (parsedNamedOffset.endsWith(units.vmax)) {
|
|
56
|
+
return start + parsedOffset * Math.max(window.innerWidth, window.innerHeight) / 100;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return start;
|
|
60
|
+
}
|
|
61
|
+
function getEdges(axis, targetSizes, containerSizes, offset) {
|
|
62
|
+
const sizeKey = axis === "x" ? "width" : "height";
|
|
63
|
+
const targetStart = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[0][0]);
|
|
64
|
+
const containerStart = getEdgeWithOffset(0, containerSizes[sizeKey], offset[0][1]);
|
|
65
|
+
const targetEnd = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[1][0]);
|
|
66
|
+
const containerEnd = getEdgeWithOffset(0, containerSizes[sizeKey], offset[1][1]);
|
|
67
|
+
const start = targetStart - containerStart;
|
|
68
|
+
const end = targetEnd - containerEnd;
|
|
69
|
+
return [start, end];
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
getEdgeWithOffset,
|
|
73
|
+
getEdges,
|
|
74
|
+
normalizeOffset,
|
|
75
|
+
parseNamedOffset
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/decorators/withScrolledInView/utils.ts"],
|
|
4
|
+
"sourcesContent": ["import { isNumber, isString } from '../../utils/index.js';\nimport type { NormalizedOffset } from './types.js';\n\nconst units = {\n px: 'px',\n vh: 'vh',\n vw: 'vw',\n vmin: 'vmin',\n vmax: 'vmax',\n percent: '%',\n};\n\nconst namedOffsets = {\n start: 0,\n center: 0.5,\n end: 1,\n};\n\n/**\n * Normalize offset input.\n */\nexport function normalizeOffset(offsets: string): NormalizedOffset {\n return offsets\n .split('/')\n .map((offset) => offset.trim().split(' ').slice(0, 2)) as NormalizedOffset;\n}\n\n/**\n * Parse the given offset.\n */\nexport function parseNamedOffset(offset: string | number): string | number {\n if (isNumber(offset)) {\n return offset;\n }\n\n if (isNumber(namedOffsets[offset])) {\n return namedOffsets[offset];\n }\n\n if (isNumber(Number(offset))) {\n return Number(offset);\n }\n\n if (isString(offset) && offset.endsWith(units.percent)) {\n return Number.parseFloat(offset) / 100;\n }\n\n return offset;\n}\n\n/**\n * Get an edge value given a start, size and offset value.\n */\nexport function getEdgeWithOffset(start: number, size: number, offset: string | number): number {\n if (isNumber(offset)) {\n return start + size * offset;\n }\n\n const parsedNamedOffset = parseNamedOffset(offset);\n if (isNumber(parsedNamedOffset)) {\n return start + size * parsedNamedOffset;\n }\n\n if (isString(parsedNamedOffset)) {\n const parsedOffset = Number.parseFloat(parsedNamedOffset);\n\n if (parsedNamedOffset.endsWith(units.px)) {\n return start + parsedOffset;\n }\n\n if (parsedNamedOffset.endsWith(units.vh)) {\n return start + (parsedOffset * window.innerHeight) / 100;\n }\n\n if (parsedNamedOffset.endsWith(units.vw)) {\n return start + (parsedOffset * window.innerWidth) / 100;\n }\n\n if (parsedNamedOffset.endsWith(units.vmin)) {\n return start + (parsedOffset * Math.min(window.innerWidth, window.innerHeight)) / 100;\n }\n\n if (parsedNamedOffset.endsWith(units.vmax)) {\n return start + (parsedOffset * Math.max(window.innerWidth, window.innerHeight)) / 100;\n }\n }\n\n return start;\n}\n\n/**\n * Get starting and ending edges for a given axis, a target sizings, a container sizings and their offset.\n */\nexport function getEdges(axis: 'x' | 'y', targetSizes, containerSizes, offset): [number, number] {\n const sizeKey = axis === 'x' ? 'width' : 'height';\n const targetStart = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[0][0]);\n const containerStart = getEdgeWithOffset(0, containerSizes[sizeKey], offset[0][1]);\n const targetEnd = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[1][0]);\n const containerEnd = getEdgeWithOffset(0, containerSizes[sizeKey], offset[1][1]);\n const start = targetStart - containerStart;\n const end = targetEnd - containerEnd;\n\n return [start, end];\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,gBAAgB;AAGnC,MAAM,QAAQ;AAAA,EACZ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AACX;AAEA,MAAM,eAAe;AAAA,EACnB,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AACP;AAKO,SAAS,gBAAgB,SAAmC;AACjE,SAAO,QACJ,MAAM,GAAG,EACT,IAAI,CAAC,WAAW,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;AACzD;AAKO,SAAS,iBAAiB,QAA0C;AACzE,MAAI,SAAS,MAAM,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,aAAa,OAAO,GAAG;AAClC,WAAO,aAAa;AAAA,EACtB;AAEA,MAAI,SAAS,OAAO,MAAM,CAAC,GAAG;AAC5B,WAAO,OAAO,MAAM;AAAA,EACtB;AAEA,MAAI,SAAS,MAAM,KAAK,OAAO,SAAS,MAAM,OAAO,GAAG;AACtD,WAAO,OAAO,WAAW,MAAM,IAAI;AAAA,EACrC;AAEA,SAAO;AACT;AAKO,SAAS,kBAAkB,OAAe,MAAc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|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -16,14 +16,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
// packages/js-toolkit/decorators/withScrolledInView.ts
|
|
19
|
+
// packages/js-toolkit/decorators/withScrolledInView/withScrolledInView.ts
|
|
20
20
|
var withScrolledInView_exports = {};
|
|
21
21
|
__export(withScrolledInView_exports, {
|
|
22
22
|
withScrolledInView: () => withScrolledInView
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(withScrolledInView_exports);
|
|
25
|
-
var import_withMountWhenInView = require("
|
|
26
|
-
var import_utils = require("
|
|
25
|
+
var import_withMountWhenInView = require("../withMountWhenInView.cjs");
|
|
26
|
+
var import_utils = require("../../utils/index.cjs");
|
|
27
|
+
var import_utils2 = require("./utils.cjs");
|
|
27
28
|
var scheduler = (0, import_utils.useScheduler)(["update", "render"]);
|
|
28
29
|
function updateProps(props, dampFactor, dampPrecision, axis = "x") {
|
|
29
30
|
props.current[axis] = (0, import_utils.clamp)(
|
|
@@ -60,6 +61,10 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
60
61
|
dampPrecision: {
|
|
61
62
|
type: Number,
|
|
62
63
|
default: 1e-3
|
|
64
|
+
},
|
|
65
|
+
offset: {
|
|
66
|
+
type: String,
|
|
67
|
+
default: "start end / end start"
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
};
|
|
@@ -89,13 +94,48 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
89
94
|
y: 0
|
|
90
95
|
}
|
|
91
96
|
};
|
|
97
|
+
shouldEvaluateProps = true;
|
|
98
|
+
get props() {
|
|
99
|
+
if (this.shouldEvaluateProps) {
|
|
100
|
+
this.shouldEvaluateProps = false;
|
|
101
|
+
const targetSizes = options.useOffsetSizes ? (0, import_utils.getOffsetSizes)(this.$el) : this.$el.getBoundingClientRect();
|
|
102
|
+
targetSizes.y += window.pageYOffset;
|
|
103
|
+
targetSizes.x += window.pageXOffset;
|
|
104
|
+
const containerSizes = {
|
|
105
|
+
x: 0,
|
|
106
|
+
y: 0,
|
|
107
|
+
height: window.innerHeight,
|
|
108
|
+
width: window.innerWidth
|
|
109
|
+
};
|
|
110
|
+
const offset = (0, import_utils2.normalizeOffset)(this.$options.offset);
|
|
111
|
+
const [yStart, yEnd] = (0, import_utils2.getEdges)("y", targetSizes, containerSizes, offset);
|
|
112
|
+
const yCurrent = (0, import_utils.clamp)(window.pageYOffset, yStart, yEnd);
|
|
113
|
+
const yProgress = (0, import_utils.clamp01)((yCurrent - yStart) / (yEnd - yStart));
|
|
114
|
+
const [xStart, xEnd] = (0, import_utils2.getEdges)("x", targetSizes, containerSizes, offset);
|
|
115
|
+
const xCurrent = (0, import_utils.clamp)(window.pageXOffset, xStart, xEnd);
|
|
116
|
+
const xProgress = (0, import_utils.clamp01)((xCurrent - xStart) / (xEnd - xStart));
|
|
117
|
+
this.__props.start.x = xStart;
|
|
118
|
+
this.__props.start.y = yStart;
|
|
119
|
+
this.__props.end.x = xEnd;
|
|
120
|
+
this.__props.end.y = yEnd;
|
|
121
|
+
this.__props.current.x = xCurrent;
|
|
122
|
+
this.__props.current.y = yCurrent;
|
|
123
|
+
this.__props.dampedCurrent.x = xCurrent;
|
|
124
|
+
this.__props.dampedCurrent.y = yCurrent;
|
|
125
|
+
this.__props.progress.x = xProgress;
|
|
126
|
+
this.__props.progress.y = yProgress;
|
|
127
|
+
this.__props.dampedProgress.x = xProgress;
|
|
128
|
+
this.__props.dampedProgress.y = yProgress;
|
|
129
|
+
}
|
|
130
|
+
return this.__props;
|
|
131
|
+
}
|
|
92
132
|
dampFactor = null;
|
|
93
133
|
dampPrecision = null;
|
|
94
134
|
constructor(element) {
|
|
95
135
|
super(element);
|
|
96
136
|
const render = () => {
|
|
97
137
|
scheduler.update(() => {
|
|
98
|
-
const renderFn = this.__callMethod("scrolledInView", this.
|
|
138
|
+
const renderFn = this.__callMethod("scrolledInView", this.props);
|
|
99
139
|
if ((0, import_utils.isFunction)(renderFn)) {
|
|
100
140
|
scheduler.render(() => {
|
|
101
141
|
renderFn(this.__props);
|
|
@@ -108,7 +148,8 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
108
148
|
delegate[event.type](event.detail[0]);
|
|
109
149
|
},
|
|
110
150
|
resized: () => {
|
|
111
|
-
this.
|
|
151
|
+
this.shouldEvaluateProps = true;
|
|
152
|
+
render();
|
|
112
153
|
},
|
|
113
154
|
scrolled: (props) => {
|
|
114
155
|
if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
|
|
@@ -117,7 +158,7 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
117
158
|
},
|
|
118
159
|
ticked: () => {
|
|
119
160
|
const dampFactor = this.dampFactor ?? this.$options.dampFactor;
|
|
120
|
-
const dampPrecision = this.
|
|
161
|
+
const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;
|
|
121
162
|
updateProps(this.__props, dampFactor, dampPrecision, "x");
|
|
122
163
|
updateProps(this.__props, dampFactor, dampPrecision, "y");
|
|
123
164
|
if (this.__props.dampedCurrent.x === this.__props.current.x && this.__props.dampedCurrent.y === this.__props.current.y) {
|
|
@@ -131,9 +172,6 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
131
172
|
this.$on("scrolled", delegate);
|
|
132
173
|
this.$on("ticked", delegate);
|
|
133
174
|
});
|
|
134
|
-
this.$on("mounted", () => {
|
|
135
|
-
this.__setProps();
|
|
136
|
-
});
|
|
137
175
|
this.$on("destroyed", () => {
|
|
138
176
|
this.$off("resized", delegate);
|
|
139
177
|
this.$off("scrolled", delegate);
|
|
@@ -170,43 +208,6 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
170
208
|
super.destroyed();
|
|
171
209
|
}
|
|
172
210
|
}
|
|
173
|
-
__setProps() {
|
|
174
|
-
const sizes = options.useOffsetSizes ? (0, import_utils.getOffsetSizes)(this.$el) : this.$el.getBoundingClientRect();
|
|
175
|
-
const yEnd = sizes.y + window.pageYOffset + sizes.height;
|
|
176
|
-
const yStart = yEnd - window.innerHeight - sizes.height;
|
|
177
|
-
const yCurrent = (0, import_utils.clamp)(window.pageYOffset, yStart, yEnd);
|
|
178
|
-
const yProgress = (0, import_utils.clamp01)((yCurrent - yStart) / (yEnd - yStart));
|
|
179
|
-
const xEnd = sizes.x + window.pageXOffset + sizes.width;
|
|
180
|
-
const xStart = xEnd - window.innerWidth - sizes.width;
|
|
181
|
-
const xCurrent = (0, import_utils.clamp)(window.pageXOffset, xStart, xEnd);
|
|
182
|
-
const xProgress = (0, import_utils.clamp01)((xCurrent - xStart) / (xEnd - xStart));
|
|
183
|
-
this.__props.start.x = xStart;
|
|
184
|
-
this.__props.start.y = yStart;
|
|
185
|
-
this.__props.end.x = xEnd;
|
|
186
|
-
this.__props.end.y = yEnd;
|
|
187
|
-
this.__props.current.x = xCurrent;
|
|
188
|
-
this.__props.current.y = yCurrent;
|
|
189
|
-
this.__props.dampedCurrent.x = (0, import_utils.damp)(
|
|
190
|
-
xCurrent,
|
|
191
|
-
this.__props.dampedCurrent.x,
|
|
192
|
-
this.dampFactor,
|
|
193
|
-
this.dampPrecision
|
|
194
|
-
);
|
|
195
|
-
this.__props.dampedCurrent.y = (0, import_utils.damp)(
|
|
196
|
-
yCurrent,
|
|
197
|
-
this.__props.dampedCurrent.y,
|
|
198
|
-
this.dampFactor,
|
|
199
|
-
this.dampPrecision
|
|
200
|
-
);
|
|
201
|
-
this.__props.progress.x = xProgress;
|
|
202
|
-
this.__props.progress.y = yProgress;
|
|
203
|
-
this.__props.dampedProgress.x = (0, import_utils.clamp01)(
|
|
204
|
-
(this.__props.dampedCurrent.x - xStart) / (xEnd - xStart)
|
|
205
|
-
);
|
|
206
|
-
this.__props.dampedProgress.y = (0, import_utils.clamp01)(
|
|
207
|
-
(this.__props.dampedCurrent.y - yStart) / (yEnd - yStart)
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
211
|
}
|
|
211
212
|
return WithScrolledInView;
|
|
212
213
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/decorators/withScrolledInView/withScrolledInView.ts"],
|
|
4
|
+
"sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../../Base/index.js';\nimport type {\n RafServiceProps,\n ScrollServiceProps,\n ResizeServiceProps,\n} from '../../services/index.js';\nimport { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n useScheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nconst scheduler = useScheduler(['update', 'render']);\n\nexport interface WithScrolledInViewProps extends BaseProps {\n $options: {\n dampFactor: number;\n dampPrecision: number;\n offset: string;\n };\n}\n\nexport type ScrollInViewProps = {\n start: {\n x: number;\n y: number;\n };\n end: {\n x: number;\n y: number;\n };\n current: {\n x: number;\n y: number;\n };\n dampedCurrent: {\n x: number;\n y: number;\n };\n progress: {\n x: number;\n y: number;\n };\n dampedProgress: {\n x: number;\n y: number;\n };\n};\n\nexport type WithScrolledInViewOptions = IntersectionObserverInit & {\n useOffsetSizes?: boolean;\n};\n\n/**\n * Update props on tick.\n */\nfunction updateProps(\n props: ScrollInViewProps,\n dampFactor: number,\n dampPrecision: number,\n axis: 'x' | 'y' = 'x',\n): void {\n props.current[axis] = clamp(\n axis === 'x' ? window.pageXOffset : window.pageYOffset,\n props.start[axis],\n props.end[axis],\n );\n props.dampedCurrent[axis] = damp(\n props.current[axis],\n props.dampedCurrent[axis],\n dampFactor,\n dampPrecision,\n );\n props.progress[axis] = clamp01(\n (props.current[axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n props.dampedProgress[axis] = clamp01(\n (props.dampedCurrent[axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n}\n\nexport interface WithScrolledInViewInterface extends BaseInterface {\n /**\n * @type {ScrollInViewProps}\n */\n readonly props: ScrollInViewProps;\n dampFactor?: number;\n dampPrecision?: number;\n mounted(): void;\n resized(props: ResizeServiceProps): void;\n scrolled(props: ScrollServiceProps): void;\n ticked(props: RafServiceProps): void;\n destroyed(): void;\n}\n\n/**\n * Add scrolled in view capabilities to a component.\n */\nexport function withScrolledInView<S extends Base = Base>(\n BaseClass: typeof Base,\n options: WithScrolledInViewOptions = {},\n): BaseDecorator<WithScrolledInViewInterface, S, WithScrolledInViewProps> {\n /**\n * Class.\n */\n class WithScrolledInView<T extends BaseProps = BaseProps> extends withMountWhenInView(\n BaseClass,\n options,\n )<T & WithScrolledInViewProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: `${BaseClass.config.name}WithMountWhenInView`,\n emits: ['scrolledInView'],\n options: {\n dampFactor: {\n type: Number,\n default: 0.1,\n },\n dampPrecision: {\n type: Number,\n default: 0.001,\n },\n offset: {\n type: String,\n default: 'start end / end start',\n },\n },\n };\n\n __props: ScrollInViewProps = {\n start: {\n x: 0,\n y: 0,\n },\n end: {\n x: 0,\n y: 0,\n },\n current: {\n x: 0,\n y: 0,\n },\n dampedCurrent: {\n x: 0,\n y: 0,\n },\n progress: {\n x: 0,\n y: 0,\n },\n dampedProgress: {\n x: 0,\n y: 0,\n },\n };\n\n shouldEvaluateProps = true;\n\n get props() {\n if (this.shouldEvaluateProps) {\n this.shouldEvaluateProps = false;\n const targetSizes = options.useOffsetSizes\n ? getOffsetSizes(this.$el)\n : this.$el.getBoundingClientRect();\n\n targetSizes.y += window.pageYOffset;\n targetSizes.x += window.pageXOffset;\n\n const containerSizes = {\n x: 0,\n y: 0,\n height: window.innerHeight,\n width: window.innerWidth,\n };\n\n const offset = normalizeOffset(this.$options.offset);\n\n // Y axis\n const [yStart, yEnd] = getEdges('y', targetSizes, containerSizes, offset);\n const yCurrent = clamp(window.pageYOffset, yStart, yEnd);\n const yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));\n // X axis\n const [xStart, xEnd] = getEdges('x', targetSizes, containerSizes, offset);\n const xCurrent = clamp(window.pageXOffset, xStart, xEnd);\n const xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));\n\n this.__props.start.x = xStart;\n this.__props.start.y = yStart;\n this.__props.end.x = xEnd;\n this.__props.end.y = yEnd;\n this.__props.current.x = xCurrent;\n this.__props.current.y = yCurrent;\n this.__props.dampedCurrent.x = xCurrent;\n this.__props.dampedCurrent.y = yCurrent;\n this.__props.progress.x = xProgress;\n this.__props.progress.y = yProgress;\n this.__props.dampedProgress.x = xProgress;\n this.__props.dampedProgress.y = yProgress;\n }\n\n return this.__props;\n }\n\n /**\n * Factor used for the `dampedProgress` props.\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampFactor?: number = null;\n\n /**\n * Precision for the `dampedProgress` props.\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampPrecision?: number = null;\n\n /**\n * Bind listeners.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const render = () => {\n scheduler.update(() => {\n // @ts-ignore\n const renderFn = this.__callMethod('scrolledInView', this.props);\n if (isFunction(renderFn)) {\n scheduler.render(() => {\n renderFn(this.__props);\n });\n }\n });\n };\n\n const delegate = {\n handleEvent(event) {\n delegate[event.type](event.detail[0]);\n },\n resized: () => {\n this.shouldEvaluateProps = true;\n render();\n },\n scrolled: (props) => {\n if ((!this.$services.has('ticked') && props.changed.y) || props.changed.x) {\n this.$services.enable('ticked');\n }\n },\n ticked: () => {\n const dampFactor = this.dampFactor ?? this.$options.dampFactor;\n const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;\n updateProps(this.__props, dampFactor, dampPrecision, 'x');\n updateProps(this.__props, dampFactor, dampPrecision, 'y');\n\n if (\n this.__props.dampedCurrent.x === this.__props.current.x &&\n this.__props.dampedCurrent.y === this.__props.current.y\n ) {\n this.$services.disable('ticked');\n }\n\n render();\n },\n };\n\n this.$on('before-mounted', () => {\n this.$on('resized', delegate);\n this.$on('scrolled', delegate);\n this.$on('ticked', delegate);\n });\n\n this.$on('destroyed', () => {\n this.$off('resized', delegate);\n this.$off('scrolled', delegate);\n this.$off('ticked', delegate);\n\n // Clamp damped values to their final value and trigger one last render on destroy\n this.__props.dampedCurrent.x = this.__props.current.x;\n this.__props.dampedCurrent.y = this.__props.current.y;\n this.__props.dampedProgress.x = this.__props.progress.x;\n this.__props.dampedProgress.y = this.__props.progress.y;\n render();\n });\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n // @ts-ignore\n if (isFunction(super.mounted)) {\n // @ts-ignore\n super.mounted();\n }\n }\n\n /**\n * Resized hook.\n */\n resized(props: ResizeServiceProps) {\n // @ts-ignore\n if (isFunction(super.resized)) {\n // @ts-ignore\n super.resized(props);\n }\n }\n\n /**\n * Scrolled hook.\n */\n scrolled(props: ScrollServiceProps) {\n // @ts-ignore\n if (isFunction(super.scrolled)) {\n // @ts-ignore\n super.scrolled(props);\n }\n }\n\n /**\n * Ticked hook.\n */\n ticked(props: RafServiceProps) {\n // @ts-ignore\n if (isFunction(super.ticked)) {\n // @ts-ignore\n super.ticked(props);\n }\n }\n\n /**\n * Destroyed hook.\n */\n destroyed() {\n // @ts-ignore\n if (isFunction(super.destroyed)) {\n // @ts-ignore\n super.destroyed();\n }\n }\n }\n\n // @ts-ignore\n return WithScrolledInView;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,iCAAoC;AACpC,mBAOO;AACP,IAAAA,gBAA0C;AAE1C,IAAM,gBAAY,2BAAa,CAAC,UAAU,QAAQ,CAAC;AA4CnD,SAAS,YACP,OACA,YACA,eACA,OAAkB,KACZ;AACN,QAAM,QAAQ,YAAQ;AAAA,IACpB,SAAS,MAAM,OAAO,cAAc,OAAO;AAAA,IAC3C,MAAM,MAAM;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AAU,QAAQ;AAG5B,aAAK,QAAQ,cAAc,IAAI,KAAK,QAAQ,QAAQ;AACpD,aAAK,QAAQ,cAAc,IAAI,KAAK,QAAQ,QAAQ;AACpD,aAAK,QAAQ,eAAe,IAAI,KAAK,QAAQ,SAAS;AACtD,aAAK,QAAQ,eAAe,IAAI,KAAK,QAAQ,SAAS;AACtD,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,IAKA,UAAU;AAER,cAAI,yBAAW,MAAM,OAAO,GAAG;AAE7B,cAAM,QAAQ;AAAA,MAChB;AAAA,IACF;AAAA,IAKA,QAAQ,OAA2B;AAEjC,cAAI,yBAAW,MAAM,OAAO,GAAG;AAE7B,cAAM,QAAQ,KAAK;AAAA,MACrB;AAAA,IACF;AAAA,IAKA,SAAS,OAA2B;AAElC,cAAI,yBAAW,MAAM,QAAQ,GAAG;AAE9B,cAAM,SAAS,KAAK;AAAA,MACtB;AAAA,IACF;AAAA,IAKA,OAAO,OAAwB;AAE7B,cAAI,yBAAW,MAAM,MAAM,GAAG;AAE5B,cAAM,OAAO,KAAK;AAAA,MACpB;AAAA,IACF;AAAA,IAKA,YAAY;AAEV,cAAI,yBAAW,MAAM,SAAS,GAAG;AAE/B,cAAM,UAAU;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
|
+
"names": ["import_utils"]
|
|
7
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import type { BaseInterface, BaseDecorator } from '
|
|
2
|
-
import type { Base, BaseProps } from '
|
|
3
|
-
import type { RafServiceProps, ScrollServiceProps, ResizeServiceProps } from '
|
|
1
|
+
import type { BaseInterface, BaseDecorator } from '../../Base/types.js';
|
|
2
|
+
import type { Base, BaseProps } from '../../Base/index.js';
|
|
3
|
+
import type { RafServiceProps, ScrollServiceProps, ResizeServiceProps } from '../../services/index.js';
|
|
4
4
|
export interface WithScrolledInViewProps extends BaseProps {
|
|
5
5
|
$options: {
|
|
6
6
|
dampFactor: number;
|
|
7
7
|
dampPrecision: number;
|
|
8
|
+
offset: string;
|
|
8
9
|
};
|
|
9
10
|
}
|
|
10
|
-
export
|
|
11
|
+
export type ScrollInViewProps = {
|
|
11
12
|
start: {
|
|
12
13
|
x: number;
|
|
13
14
|
y: number;
|
|
@@ -33,15 +34,14 @@ export declare type ScrollInViewProps = {
|
|
|
33
34
|
y: number;
|
|
34
35
|
};
|
|
35
36
|
};
|
|
36
|
-
export
|
|
37
|
+
export type WithScrolledInViewOptions = IntersectionObserverInit & {
|
|
37
38
|
useOffsetSizes?: boolean;
|
|
38
39
|
};
|
|
39
40
|
export interface WithScrolledInViewInterface extends BaseInterface {
|
|
40
41
|
/**
|
|
41
|
-
* @private
|
|
42
42
|
* @type {ScrollInViewProps}
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
readonly props: ScrollInViewProps;
|
|
45
45
|
dampFactor?: number;
|
|
46
46
|
dampPrecision?: number;
|
|
47
47
|
mounted(): void;
|
|
@@ -49,10 +49,6 @@ export interface WithScrolledInViewInterface extends BaseInterface {
|
|
|
49
49
|
scrolled(props: ScrollServiceProps): void;
|
|
50
50
|
ticked(props: RafServiceProps): void;
|
|
51
51
|
destroyed(): void;
|
|
52
|
-
/**
|
|
53
|
-
* @private
|
|
54
|
-
*/
|
|
55
|
-
__setProps(): void;
|
|
56
52
|
}
|
|
57
53
|
/**
|
|
58
54
|
* Add scrolled in view capabilities to a component.
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { withMountWhenInView } from "
|
|
2
|
-
import {
|
|
1
|
+
import { withMountWhenInView } from "../withMountWhenInView.js";
|
|
2
|
+
import {
|
|
3
|
+
damp,
|
|
4
|
+
clamp,
|
|
5
|
+
clamp01,
|
|
6
|
+
getOffsetSizes,
|
|
7
|
+
isFunction,
|
|
8
|
+
useScheduler
|
|
9
|
+
} from "../../utils/index.js";
|
|
10
|
+
import { normalizeOffset, getEdges } from "./utils.js";
|
|
3
11
|
const scheduler = useScheduler(["update", "render"]);
|
|
4
12
|
function updateProps(props, dampFactor, dampPrecision, axis = "x") {
|
|
5
13
|
props.current[axis] = clamp(
|
|
@@ -36,6 +44,10 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
36
44
|
dampPrecision: {
|
|
37
45
|
type: Number,
|
|
38
46
|
default: 1e-3
|
|
47
|
+
},
|
|
48
|
+
offset: {
|
|
49
|
+
type: String,
|
|
50
|
+
default: "start end / end start"
|
|
39
51
|
}
|
|
40
52
|
}
|
|
41
53
|
};
|
|
@@ -65,13 +77,48 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
65
77
|
y: 0
|
|
66
78
|
}
|
|
67
79
|
};
|
|
80
|
+
shouldEvaluateProps = true;
|
|
81
|
+
get props() {
|
|
82
|
+
if (this.shouldEvaluateProps) {
|
|
83
|
+
this.shouldEvaluateProps = false;
|
|
84
|
+
const targetSizes = options.useOffsetSizes ? getOffsetSizes(this.$el) : this.$el.getBoundingClientRect();
|
|
85
|
+
targetSizes.y += window.pageYOffset;
|
|
86
|
+
targetSizes.x += window.pageXOffset;
|
|
87
|
+
const containerSizes = {
|
|
88
|
+
x: 0,
|
|
89
|
+
y: 0,
|
|
90
|
+
height: window.innerHeight,
|
|
91
|
+
width: window.innerWidth
|
|
92
|
+
};
|
|
93
|
+
const offset = normalizeOffset(this.$options.offset);
|
|
94
|
+
const [yStart, yEnd] = getEdges("y", targetSizes, containerSizes, offset);
|
|
95
|
+
const yCurrent = clamp(window.pageYOffset, yStart, yEnd);
|
|
96
|
+
const yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));
|
|
97
|
+
const [xStart, xEnd] = getEdges("x", targetSizes, containerSizes, offset);
|
|
98
|
+
const xCurrent = clamp(window.pageXOffset, xStart, xEnd);
|
|
99
|
+
const xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));
|
|
100
|
+
this.__props.start.x = xStart;
|
|
101
|
+
this.__props.start.y = yStart;
|
|
102
|
+
this.__props.end.x = xEnd;
|
|
103
|
+
this.__props.end.y = yEnd;
|
|
104
|
+
this.__props.current.x = xCurrent;
|
|
105
|
+
this.__props.current.y = yCurrent;
|
|
106
|
+
this.__props.dampedCurrent.x = xCurrent;
|
|
107
|
+
this.__props.dampedCurrent.y = yCurrent;
|
|
108
|
+
this.__props.progress.x = xProgress;
|
|
109
|
+
this.__props.progress.y = yProgress;
|
|
110
|
+
this.__props.dampedProgress.x = xProgress;
|
|
111
|
+
this.__props.dampedProgress.y = yProgress;
|
|
112
|
+
}
|
|
113
|
+
return this.__props;
|
|
114
|
+
}
|
|
68
115
|
dampFactor = null;
|
|
69
116
|
dampPrecision = null;
|
|
70
117
|
constructor(element) {
|
|
71
118
|
super(element);
|
|
72
119
|
const render = () => {
|
|
73
120
|
scheduler.update(() => {
|
|
74
|
-
const renderFn = this.__callMethod("scrolledInView", this.
|
|
121
|
+
const renderFn = this.__callMethod("scrolledInView", this.props);
|
|
75
122
|
if (isFunction(renderFn)) {
|
|
76
123
|
scheduler.render(() => {
|
|
77
124
|
renderFn(this.__props);
|
|
@@ -84,7 +131,8 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
84
131
|
delegate[event.type](event.detail[0]);
|
|
85
132
|
},
|
|
86
133
|
resized: () => {
|
|
87
|
-
this.
|
|
134
|
+
this.shouldEvaluateProps = true;
|
|
135
|
+
render();
|
|
88
136
|
},
|
|
89
137
|
scrolled: (props) => {
|
|
90
138
|
if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
|
|
@@ -93,7 +141,7 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
93
141
|
},
|
|
94
142
|
ticked: () => {
|
|
95
143
|
const dampFactor = this.dampFactor ?? this.$options.dampFactor;
|
|
96
|
-
const dampPrecision = this.
|
|
144
|
+
const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;
|
|
97
145
|
updateProps(this.__props, dampFactor, dampPrecision, "x");
|
|
98
146
|
updateProps(this.__props, dampFactor, dampPrecision, "y");
|
|
99
147
|
if (this.__props.dampedCurrent.x === this.__props.current.x && this.__props.dampedCurrent.y === this.__props.current.y) {
|
|
@@ -107,9 +155,6 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
107
155
|
this.$on("scrolled", delegate);
|
|
108
156
|
this.$on("ticked", delegate);
|
|
109
157
|
});
|
|
110
|
-
this.$on("mounted", () => {
|
|
111
|
-
this.__setProps();
|
|
112
|
-
});
|
|
113
158
|
this.$on("destroyed", () => {
|
|
114
159
|
this.$off("resized", delegate);
|
|
115
160
|
this.$off("scrolled", delegate);
|
|
@@ -146,43 +191,6 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
146
191
|
super.destroyed();
|
|
147
192
|
}
|
|
148
193
|
}
|
|
149
|
-
__setProps() {
|
|
150
|
-
const sizes = options.useOffsetSizes ? getOffsetSizes(this.$el) : this.$el.getBoundingClientRect();
|
|
151
|
-
const yEnd = sizes.y + window.pageYOffset + sizes.height;
|
|
152
|
-
const yStart = yEnd - window.innerHeight - sizes.height;
|
|
153
|
-
const yCurrent = clamp(window.pageYOffset, yStart, yEnd);
|
|
154
|
-
const yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));
|
|
155
|
-
const xEnd = sizes.x + window.pageXOffset + sizes.width;
|
|
156
|
-
const xStart = xEnd - window.innerWidth - sizes.width;
|
|
157
|
-
const xCurrent = clamp(window.pageXOffset, xStart, xEnd);
|
|
158
|
-
const xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));
|
|
159
|
-
this.__props.start.x = xStart;
|
|
160
|
-
this.__props.start.y = yStart;
|
|
161
|
-
this.__props.end.x = xEnd;
|
|
162
|
-
this.__props.end.y = yEnd;
|
|
163
|
-
this.__props.current.x = xCurrent;
|
|
164
|
-
this.__props.current.y = yCurrent;
|
|
165
|
-
this.__props.dampedCurrent.x = damp(
|
|
166
|
-
xCurrent,
|
|
167
|
-
this.__props.dampedCurrent.x,
|
|
168
|
-
this.dampFactor,
|
|
169
|
-
this.dampPrecision
|
|
170
|
-
);
|
|
171
|
-
this.__props.dampedCurrent.y = damp(
|
|
172
|
-
yCurrent,
|
|
173
|
-
this.__props.dampedCurrent.y,
|
|
174
|
-
this.dampFactor,
|
|
175
|
-
this.dampPrecision
|
|
176
|
-
);
|
|
177
|
-
this.__props.progress.x = xProgress;
|
|
178
|
-
this.__props.progress.y = yProgress;
|
|
179
|
-
this.__props.dampedProgress.x = clamp01(
|
|
180
|
-
(this.__props.dampedCurrent.x - xStart) / (xEnd - xStart)
|
|
181
|
-
);
|
|
182
|
-
this.__props.dampedProgress.y = clamp01(
|
|
183
|
-
(this.__props.dampedCurrent.y - yStart) / (yEnd - yStart)
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
194
|
}
|
|
187
195
|
return WithScrolledInView;
|
|
188
196
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/decorators/withScrolledInView/withScrolledInView.ts"],
|
|
4
|
+
"sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../../Base/index.js';\nimport type {\n RafServiceProps,\n ScrollServiceProps,\n ResizeServiceProps,\n} from '../../services/index.js';\nimport { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n useScheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nconst scheduler = useScheduler(['update', 'render']);\n\nexport interface WithScrolledInViewProps extends BaseProps {\n $options: {\n dampFactor: number;\n dampPrecision: number;\n offset: string;\n };\n}\n\nexport type ScrollInViewProps = {\n start: {\n x: number;\n y: number;\n };\n end: {\n x: number;\n y: number;\n };\n current: {\n x: number;\n y: number;\n };\n dampedCurrent: {\n x: number;\n y: number;\n };\n progress: {\n x: number;\n y: number;\n };\n dampedProgress: {\n x: number;\n y: number;\n };\n};\n\nexport type WithScrolledInViewOptions = IntersectionObserverInit & {\n useOffsetSizes?: boolean;\n};\n\n/**\n * Update props on tick.\n */\nfunction updateProps(\n props: ScrollInViewProps,\n dampFactor: number,\n dampPrecision: number,\n axis: 'x' | 'y' = 'x',\n): void {\n props.current[axis] = clamp(\n axis === 'x' ? window.pageXOffset : window.pageYOffset,\n props.start[axis],\n props.end[axis],\n );\n props.dampedCurrent[axis] = damp(\n props.current[axis],\n props.dampedCurrent[axis],\n dampFactor,\n dampPrecision,\n );\n props.progress[axis] = clamp01(\n (props.current[axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n props.dampedProgress[axis] = clamp01(\n (props.dampedCurrent[axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n}\n\nexport interface WithScrolledInViewInterface extends BaseInterface {\n /**\n * @type {ScrollInViewProps}\n */\n readonly props: ScrollInViewProps;\n dampFactor?: number;\n dampPrecision?: number;\n mounted(): void;\n resized(props: ResizeServiceProps): void;\n scrolled(props: ScrollServiceProps): void;\n ticked(props: RafServiceProps): void;\n destroyed(): void;\n}\n\n/**\n * Add scrolled in view capabilities to a component.\n */\nexport function withScrolledInView<S extends Base = Base>(\n BaseClass: typeof Base,\n options: WithScrolledInViewOptions = {},\n): BaseDecorator<WithScrolledInViewInterface, S, WithScrolledInViewProps> {\n /**\n * Class.\n */\n class WithScrolledInView<T extends BaseProps = BaseProps> extends withMountWhenInView(\n BaseClass,\n options,\n )<T & WithScrolledInViewProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: `${BaseClass.config.name}WithMountWhenInView`,\n emits: ['scrolledInView'],\n options: {\n dampFactor: {\n type: Number,\n default: 0.1,\n },\n dampPrecision: {\n type: Number,\n default: 0.001,\n },\n offset: {\n type: String,\n default: 'start end / end start',\n },\n },\n };\n\n __props: ScrollInViewProps = {\n start: {\n x: 0,\n y: 0,\n },\n end: {\n x: 0,\n y: 0,\n },\n current: {\n x: 0,\n y: 0,\n },\n dampedCurrent: {\n x: 0,\n y: 0,\n },\n progress: {\n x: 0,\n y: 0,\n },\n dampedProgress: {\n x: 0,\n y: 0,\n },\n };\n\n shouldEvaluateProps = true;\n\n get props() {\n if (this.shouldEvaluateProps) {\n this.shouldEvaluateProps = false;\n const targetSizes = options.useOffsetSizes\n ? getOffsetSizes(this.$el)\n : this.$el.getBoundingClientRect();\n\n targetSizes.y += window.pageYOffset;\n targetSizes.x += window.pageXOffset;\n\n const containerSizes = {\n x: 0,\n y: 0,\n height: window.innerHeight,\n width: window.innerWidth,\n };\n\n const offset = normalizeOffset(this.$options.offset);\n\n // Y axis\n const [yStart, yEnd] = getEdges('y', targetSizes, containerSizes, offset);\n const yCurrent = clamp(window.pageYOffset, yStart, yEnd);\n const yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));\n // X axis\n const [xStart, xEnd] = getEdges('x', targetSizes, containerSizes, offset);\n const xCurrent = clamp(window.pageXOffset, xStart, xEnd);\n const xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));\n\n this.__props.start.x = xStart;\n this.__props.start.y = yStart;\n this.__props.end.x = xEnd;\n this.__props.end.y = yEnd;\n this.__props.current.x = xCurrent;\n this.__props.current.y = yCurrent;\n this.__props.dampedCurrent.x = xCurrent;\n this.__props.dampedCurrent.y = yCurrent;\n this.__props.progress.x = xProgress;\n this.__props.progress.y = yProgress;\n this.__props.dampedProgress.x = xProgress;\n this.__props.dampedProgress.y = yProgress;\n }\n\n return this.__props;\n }\n\n /**\n * Factor used for the `dampedProgress` props.\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampFactor?: number = null;\n\n /**\n * Precision for the `dampedProgress` props.\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampPrecision?: number = null;\n\n /**\n * Bind listeners.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const render = () => {\n scheduler.update(() => {\n // @ts-ignore\n const renderFn = this.__callMethod('scrolledInView', this.props);\n if (isFunction(renderFn)) {\n scheduler.render(() => {\n renderFn(this.__props);\n });\n }\n });\n };\n\n const delegate = {\n handleEvent(event) {\n delegate[event.type](event.detail[0]);\n },\n resized: () => {\n this.shouldEvaluateProps = true;\n render();\n },\n scrolled: (props) => {\n if ((!this.$services.has('ticked') && props.changed.y) || props.changed.x) {\n this.$services.enable('ticked');\n }\n },\n ticked: () => {\n const dampFactor = this.dampFactor ?? this.$options.dampFactor;\n const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;\n updateProps(this.__props, dampFactor, dampPrecision, 'x');\n updateProps(this.__props, dampFactor, dampPrecision, 'y');\n\n if (\n this.__props.dampedCurrent.x === this.__props.current.x &&\n this.__props.dampedCurrent.y === this.__props.current.y\n ) {\n this.$services.disable('ticked');\n }\n\n render();\n },\n };\n\n this.$on('before-mounted', () => {\n this.$on('resized', delegate);\n this.$on('scrolled', delegate);\n this.$on('ticked', delegate);\n });\n\n this.$on('destroyed', () => {\n this.$off('resized', delegate);\n this.$off('scrolled', delegate);\n this.$off('ticked', delegate);\n\n // Clamp damped values to their final value and trigger one last render on destroy\n this.__props.dampedCurrent.x = this.__props.current.x;\n this.__props.dampedCurrent.y = this.__props.current.y;\n this.__props.dampedProgress.x = this.__props.progress.x;\n this.__props.dampedProgress.y = this.__props.progress.y;\n render();\n });\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n // @ts-ignore\n if (isFunction(super.mounted)) {\n // @ts-ignore\n super.mounted();\n }\n }\n\n /**\n * Resized hook.\n */\n resized(props: ResizeServiceProps) {\n // @ts-ignore\n if (isFunction(super.resized)) {\n // @ts-ignore\n super.resized(props);\n }\n }\n\n /**\n * Scrolled hook.\n */\n scrolled(props: ScrollServiceProps) {\n // @ts-ignore\n if (isFunction(super.scrolled)) {\n // @ts-ignore\n super.scrolled(props);\n }\n }\n\n /**\n * Ticked hook.\n */\n ticked(props: RafServiceProps) {\n // @ts-ignore\n if (isFunction(super.ticked)) {\n // @ts-ignore\n super.ticked(props);\n }\n }\n\n /**\n * Destroyed hook.\n */\n destroyed() {\n // @ts-ignore\n if (isFunction(super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+
"names": []
|
|
7
|
+
}
|
package/helpers/createApp.d.ts
CHANGED
|
@@ -29,19 +29,11 @@ __export(getClosestParent_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(getClosestParent_exports);
|
|
31
31
|
var import_getInstanceFromElement = __toESM(require("./getInstanceFromElement.cjs"), 1);
|
|
32
|
-
|
|
33
|
-
let parent = element.parentElement;
|
|
34
|
-
let count = 0;
|
|
35
|
-
while (parent && condition(parent) && count < limit) {
|
|
36
|
-
parent = parent.parentElement;
|
|
37
|
-
count += 1;
|
|
38
|
-
}
|
|
39
|
-
return parent;
|
|
40
|
-
}
|
|
32
|
+
var import_utils = require("../utils/index.cjs");
|
|
41
33
|
function getClosestParent(childInstance, ParentConstructor) {
|
|
42
|
-
const parentEl =
|
|
34
|
+
const parentEl = (0, import_utils.getAncestorWhere)(
|
|
43
35
|
childInstance.$el,
|
|
44
|
-
(element) =>
|
|
36
|
+
(element) => element && (0, import_getInstanceFromElement.default)(element, ParentConstructor) !== null
|
|
45
37
|
);
|
|
46
38
|
return parentEl ? (0, import_getInstanceFromElement.default)(parentEl, ParentConstructor) : null;
|
|
47
39
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/getClosestParent.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport getInstanceFromElement from './getInstanceFromElement.js';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oCAAmC;
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport getInstanceFromElement from './getInstanceFromElement.js';\nimport { getAncestorWhere } from '../utils/index.js';\n\n/**\n * Get the closest parent of a component.\n */\nexport default function getClosestParent<T extends BaseConstructor>(\n childInstance: Base,\n ParentConstructor: T,\n) {\n const parentEl = getAncestorWhere(\n childInstance.$el,\n (element) => element && getInstanceFromElement(element, ParentConstructor) !== null,\n );\n\n return parentEl ? getInstanceFromElement(parentEl, ParentConstructor) : null;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oCAAmC;AACnC,mBAAiC;AAKlB,SAAR,iBACL,eACA,mBACA;AACA,QAAM,eAAW;AAAA,IACf,cAAc;AAAA,IACd,CAAC,YAAY,eAAW,8BAAAA,SAAuB,SAAS,iBAAiB,MAAM;AAAA,EACjF;AAEA,SAAO,eAAW,8BAAAA,SAAuB,UAAU,iBAAiB,IAAI;AAC1E;",
|
|
6
6
|
"names": ["getInstanceFromElement"]
|
|
7
7
|
}
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import getInstanceFromElement from "./getInstanceFromElement.js";
|
|
2
|
-
|
|
3
|
-
let parent = element.parentElement;
|
|
4
|
-
let count = 0;
|
|
5
|
-
while (parent && condition(parent) && count < limit) {
|
|
6
|
-
parent = parent.parentElement;
|
|
7
|
-
count += 1;
|
|
8
|
-
}
|
|
9
|
-
return parent;
|
|
10
|
-
}
|
|
2
|
+
import { getAncestorWhere } from "../utils/index.js";
|
|
11
3
|
function getClosestParent(childInstance, ParentConstructor) {
|
|
12
|
-
const parentEl =
|
|
4
|
+
const parentEl = getAncestorWhere(
|
|
13
5
|
childInstance.$el,
|
|
14
|
-
(element) =>
|
|
6
|
+
(element) => element && getInstanceFromElement(element, ParentConstructor) !== null
|
|
15
7
|
);
|
|
16
8
|
return parentEl ? getInstanceFromElement(parentEl, ParentConstructor) : null;
|
|
17
9
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/getClosestParent.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport getInstanceFromElement from './getInstanceFromElement.js';\
|
|
5
|
-
"mappings": "AACA,OAAO,4BAA4B;
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport getInstanceFromElement from './getInstanceFromElement.js';\nimport { getAncestorWhere } from '../utils/index.js';\n\n/**\n * Get the closest parent of a component.\n */\nexport default function getClosestParent<T extends BaseConstructor>(\n childInstance: Base,\n ParentConstructor: T,\n) {\n const parentEl = getAncestorWhere(\n childInstance.$el,\n (element) => element && getInstanceFromElement(element, ParentConstructor) !== null,\n );\n\n return parentEl ? getInstanceFromElement(parentEl, ParentConstructor) : null;\n}\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,4BAA4B;AACnC,SAAS,wBAAwB;AAKlB,SAAR,iBACL,eACA,mBACA;AACA,QAAM,WAAW;AAAA,IACf,cAAc;AAAA,IACd,CAAC,YAAY,WAAW,uBAAuB,SAAS,iBAAiB,MAAM;AAAA,EACjF;AAEA,SAAO,WAAW,uBAAuB,UAAU,iBAAiB,IAAI;AAC1E;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@studiometa/js-toolkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "A set of useful little bits of JavaScript to boost your project! 🚀",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"toolkit"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@motionone/easing": "^10.
|
|
44
|
+
"@motionone/easing": "^10.15.1",
|
|
45
45
|
"deepmerge": "^4.2.2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
package/services/drag.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ServiceInterface } from './index.js';
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export type DragService = ServiceInterface<DragServiceProps>;
|
|
3
|
+
type DragLifecycle = 'start' | 'drag' | 'drop' | 'inertia' | 'stop';
|
|
4
4
|
export interface DragServiceProps {
|
|
5
5
|
/**
|
|
6
6
|
* The current mode of the dragging logic.
|