@studiometa/js-toolkit 2.7.0 → 2.8.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/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.d.ts +10 -10
- 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/types.d.ts +1 -1
- package/Base/utils.cjs +15 -1
- package/Base/utils.cjs.map +2 -2
- package/Base/utils.js +15 -1
- 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} +21 -9
- package/decorators/withScrolledInView/withScrolledInView.cjs.map +7 -0
- package/decorators/{withScrolledInView.d.ts → withScrolledInView/withScrolledInView.d.ts} +6 -5
- package/decorators/{withScrolledInView.js → withScrolledInView/withScrolledInView.js} +27 -8
- 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/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 +1 -0
- package/utils/index.cjs.map +2 -2
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -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/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/decorators/withScrolledInView.cjs.map +0 -7
- package/decorators/withScrolledInView.js.map +0 -7
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/js-toolkit/decorators/withScrolledInView/utils.ts
|
|
20
|
+
var utils_exports = {};
|
|
21
|
+
__export(utils_exports, {
|
|
22
|
+
getEdgeWithOffset: () => getEdgeWithOffset,
|
|
23
|
+
getEdges: () => getEdges,
|
|
24
|
+
normalizeOffset: () => normalizeOffset,
|
|
25
|
+
parseNamedOffset: () => parseNamedOffset
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(utils_exports);
|
|
28
|
+
var import_utils = require("../../utils/index.cjs");
|
|
29
|
+
var units = {
|
|
30
|
+
px: "px",
|
|
31
|
+
vh: "vh",
|
|
32
|
+
vw: "vw",
|
|
33
|
+
vmin: "vmin",
|
|
34
|
+
vmax: "vmax",
|
|
35
|
+
percent: "%"
|
|
36
|
+
};
|
|
37
|
+
var namedOffsets = {
|
|
38
|
+
start: 0,
|
|
39
|
+
center: 0.5,
|
|
40
|
+
end: 1
|
|
41
|
+
};
|
|
42
|
+
function normalizeOffset(offsets) {
|
|
43
|
+
return offsets.split("/").map((offset) => offset.trim().split(" ").slice(0, 2));
|
|
44
|
+
}
|
|
45
|
+
function parseNamedOffset(offset) {
|
|
46
|
+
if ((0, import_utils.isNumber)(offset)) {
|
|
47
|
+
return offset;
|
|
48
|
+
}
|
|
49
|
+
if ((0, import_utils.isNumber)(namedOffsets[offset])) {
|
|
50
|
+
return namedOffsets[offset];
|
|
51
|
+
}
|
|
52
|
+
if ((0, import_utils.isNumber)(Number(offset))) {
|
|
53
|
+
return Number(offset);
|
|
54
|
+
}
|
|
55
|
+
if ((0, import_utils.isString)(offset) && offset.endsWith(units.percent)) {
|
|
56
|
+
return Number.parseFloat(offset) / 100;
|
|
57
|
+
}
|
|
58
|
+
return offset;
|
|
59
|
+
}
|
|
60
|
+
function getEdgeWithOffset(start, size, offset) {
|
|
61
|
+
if ((0, import_utils.isNumber)(offset)) {
|
|
62
|
+
return start + size * offset;
|
|
63
|
+
}
|
|
64
|
+
const parsedNamedOffset = parseNamedOffset(offset);
|
|
65
|
+
if ((0, import_utils.isNumber)(parsedNamedOffset)) {
|
|
66
|
+
return start + size * parsedNamedOffset;
|
|
67
|
+
}
|
|
68
|
+
if ((0, import_utils.isString)(parsedNamedOffset)) {
|
|
69
|
+
const parsedOffset = Number.parseFloat(parsedNamedOffset);
|
|
70
|
+
if (parsedNamedOffset.endsWith(units.px)) {
|
|
71
|
+
return start + parsedOffset;
|
|
72
|
+
}
|
|
73
|
+
if (parsedNamedOffset.endsWith(units.vh)) {
|
|
74
|
+
return start + parsedOffset * window.innerHeight / 100;
|
|
75
|
+
}
|
|
76
|
+
if (parsedNamedOffset.endsWith(units.vw)) {
|
|
77
|
+
return start + parsedOffset * window.innerWidth / 100;
|
|
78
|
+
}
|
|
79
|
+
if (parsedNamedOffset.endsWith(units.vmin)) {
|
|
80
|
+
return start + parsedOffset * Math.min(window.innerWidth, window.innerHeight) / 100;
|
|
81
|
+
}
|
|
82
|
+
if (parsedNamedOffset.endsWith(units.vmax)) {
|
|
83
|
+
return start + parsedOffset * Math.max(window.innerWidth, window.innerHeight) / 100;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return start;
|
|
87
|
+
}
|
|
88
|
+
function getEdges(axis, targetSizes, containerSizes, offset) {
|
|
89
|
+
const sizeKey = axis === "x" ? "width" : "height";
|
|
90
|
+
const targetStart = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[0][0]);
|
|
91
|
+
const containerStart = getEdgeWithOffset(0, containerSizes[sizeKey], offset[0][1]);
|
|
92
|
+
const targetEnd = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[1][0]);
|
|
93
|
+
const containerEnd = getEdgeWithOffset(0, containerSizes[sizeKey], offset[1][1]);
|
|
94
|
+
const start = targetStart - containerStart;
|
|
95
|
+
const end = targetEnd - containerEnd;
|
|
96
|
+
return [start, end];
|
|
97
|
+
}
|
|
98
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
99
|
+
//# sourceMappingURL=utils.cjs.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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmC;AAGnC,IAAM,QAAQ;AAAA,EACZ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AACX;AAEA,IAAM,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,UAAI,uBAAS,MAAM,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,UAAI,uBAAS,aAAa,OAAO,GAAG;AAClC,WAAO,aAAa;AAAA,EACtB;AAEA,UAAI,uBAAS,OAAO,MAAM,CAAC,GAAG;AAC5B,WAAO,OAAO,MAAM;AAAA,EACtB;AAEA,UAAI,uBAAS,MAAM,KAAK,OAAO,SAAS,MAAM,OAAO,GAAG;AACtD,WAAO,OAAO,WAAW,MAAM,IAAI;AAAA,EACrC;AAEA,SAAO;AACT;AAKO,SAAS,kBAAkB,OAAe,MAAc,QAAiC;AAC9F,UAAI,uBAAS,MAAM,GAAG;AACpB,WAAO,QAAQ,OAAO;AAAA,EACxB;AAEA,QAAM,oBAAoB,iBAAiB,MAAM;AACjD,UAAI,uBAAS,iBAAiB,GAAG;AAC/B,WAAO,QAAQ,OAAO;AAAA,EACxB;AAEA,UAAI,uBAAS,iBAAiB,GAAG;AAC/B,UAAM,eAAe,OAAO,WAAW,iBAAiB;AAExD,QAAI,kBAAkB,SAAS,MAAM,EAAE,GAAG;AACxC,aAAO,QAAQ;AAAA,IACjB;AAEA,QAAI,kBAAkB,SAAS,MAAM,EAAE,GAAG;AACxC,aAAO,QAAS,eAAe,OAAO,cAAe;AAAA,IACvD;AAEA,QAAI,kBAAkB,SAAS,MAAM,EAAE,GAAG;AACxC,aAAO,QAAS,eAAe,OAAO,aAAc;AAAA,IACtD;AAEA,QAAI,kBAAkB,SAAS,MAAM,IAAI,GAAG;AAC1C,aAAO,QAAS,eAAe,KAAK,IAAI,OAAO,YAAY,OAAO,WAAW,IAAK;AAAA,IACpF;AAEA,QAAI,kBAAkB,SAAS,MAAM,IAAI,GAAG;AAC1C,aAAO,QAAS,eAAe,KAAK,IAAI,OAAO,YAAY,OAAO,WAAW,IAAK;AAAA,IACpF;AAAA,EACF;AAEA,SAAO;AACT;AAKO,SAAS,SAAS,MAAiB,aAAa,gBAAgB,QAA0B;AAC/F,QAAM,UAAU,SAAS,MAAM,UAAU;AACzC,QAAM,cAAc,kBAAkB,YAAY,OAAO,YAAY,UAAU,OAAO,GAAG,EAAE;AAC3F,QAAM,iBAAiB,kBAAkB,GAAG,eAAe,UAAU,OAAO,GAAG,EAAE;AACjF,QAAM,YAAY,kBAAkB,YAAY,OAAO,YAAY,UAAU,OAAO,GAAG,EAAE;AACzF,QAAM,eAAe,kBAAkB,GAAG,eAAe,UAAU,OAAO,GAAG,EAAE;AAC/E,QAAM,QAAQ,cAAc;AAC5B,QAAM,MAAM,YAAY;AAExB,SAAO,CAAC,OAAO,GAAG;AACpB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { NormalizedOffset } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize offset input.
|
|
4
|
+
*/
|
|
5
|
+
export declare function normalizeOffset(offsets: string): NormalizedOffset;
|
|
6
|
+
/**
|
|
7
|
+
* Parse the given offset.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseNamedOffset(offset: string | number): string | number;
|
|
10
|
+
/**
|
|
11
|
+
* Get an edge value given a start, size and offset value.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getEdgeWithOffset(start: number, size: number, offset: string | number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Get starting and ending edges for a given axis, a target sizings, a container sizings and their offset.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getEdges(axis: 'x' | 'y', targetSizes: any, containerSizes: any, offset: any): [number, number];
|
|
@@ -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,OAA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UAAU,OAAO,GAAG,EAAE;AACzF,QAAM,eAAe,kBAAkB,GAAG,eAAe,UAAU,OAAO,GAAG,EAAE;AAC/E,QAAM,QAAQ,cAAc;AAC5B,QAAM,MAAM,YAAY;AAExB,SAAO,CAAC,OAAO,GAAG;AACpB;",
|
|
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
|
};
|
|
@@ -117,7 +122,7 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
117
122
|
},
|
|
118
123
|
ticked: () => {
|
|
119
124
|
const dampFactor = this.dampFactor ?? this.$options.dampFactor;
|
|
120
|
-
const dampPrecision = this.
|
|
125
|
+
const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;
|
|
121
126
|
updateProps(this.__props, dampFactor, dampPrecision, "x");
|
|
122
127
|
updateProps(this.__props, dampFactor, dampPrecision, "y");
|
|
123
128
|
if (this.__props.dampedCurrent.x === this.__props.current.x && this.__props.dampedCurrent.y === this.__props.current.y) {
|
|
@@ -171,13 +176,20 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
171
176
|
}
|
|
172
177
|
}
|
|
173
178
|
__setProps() {
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
179
|
+
const targetSizes = options.useOffsetSizes ? (0, import_utils.getOffsetSizes)(this.$el) : this.$el.getBoundingClientRect();
|
|
180
|
+
targetSizes.y += window.pageYOffset;
|
|
181
|
+
targetSizes.x += window.pageXOffset;
|
|
182
|
+
const containerSizes = {
|
|
183
|
+
x: 0,
|
|
184
|
+
y: 0,
|
|
185
|
+
height: window.innerHeight,
|
|
186
|
+
width: window.innerWidth
|
|
187
|
+
};
|
|
188
|
+
const offset = (0, import_utils2.normalizeOffset)(this.$options.offset);
|
|
189
|
+
const [yStart, yEnd] = (0, import_utils2.getEdges)("y", targetSizes, containerSizes, offset);
|
|
177
190
|
const yCurrent = (0, import_utils.clamp)(window.pageYOffset, yStart, yEnd);
|
|
178
191
|
const yProgress = (0, import_utils.clamp01)((yCurrent - yStart) / (yEnd - yStart));
|
|
179
|
-
const xEnd =
|
|
180
|
-
const xStart = xEnd - window.innerWidth - sizes.width;
|
|
192
|
+
const [xStart, xEnd] = (0, import_utils2.getEdges)("x", targetSizes, containerSizes, offset);
|
|
181
193
|
const xCurrent = (0, import_utils.clamp)(window.pageXOffset, xStart, xEnd);
|
|
182
194
|
const xProgress = (0, import_utils.clamp01)((xCurrent - xStart) / (xEnd - xStart));
|
|
183
195
|
this.__props.start.x = xStart;
|
|
@@ -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 * @private\n * @type {ScrollInViewProps}\n */\n __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 * @private\n */\n __setProps(): 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 /**\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.__setProps();\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\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('mounted', () => {\n this.__setProps();\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 * Set the decorator props.\n */\n __setProps() {\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 = damp(\n xCurrent,\n this.__props.dampedCurrent.x,\n this.dampFactor,\n this.dampPrecision,\n );\n this.__props.dampedCurrent.y = damp(\n yCurrent,\n this.__props.dampedCurrent.y,\n this.dampFactor,\n this.dampPrecision,\n );\n this.__props.progress.x = xProgress;\n this.__props.progress.y = yProgress;\n this.__props.dampedProgress.x = clamp01(\n (this.__props.dampedCurrent.x - xStart) / (xEnd - xStart),\n );\n this.__props.dampedProgress.y = clamp01(\n (this.__props.dampedCurrent.y - yStart) / (yEnd - yStart),\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,Q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seInterface, 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,7 +34,7 @@ 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 {
|
|
@@ -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
|
};
|
|
@@ -93,7 +105,7 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
93
105
|
},
|
|
94
106
|
ticked: () => {
|
|
95
107
|
const dampFactor = this.dampFactor ?? this.$options.dampFactor;
|
|
96
|
-
const dampPrecision = this.
|
|
108
|
+
const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;
|
|
97
109
|
updateProps(this.__props, dampFactor, dampPrecision, "x");
|
|
98
110
|
updateProps(this.__props, dampFactor, dampPrecision, "y");
|
|
99
111
|
if (this.__props.dampedCurrent.x === this.__props.current.x && this.__props.dampedCurrent.y === this.__props.current.y) {
|
|
@@ -147,13 +159,20 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
147
159
|
}
|
|
148
160
|
}
|
|
149
161
|
__setProps() {
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
const targetSizes = options.useOffsetSizes ? getOffsetSizes(this.$el) : this.$el.getBoundingClientRect();
|
|
163
|
+
targetSizes.y += window.pageYOffset;
|
|
164
|
+
targetSizes.x += window.pageXOffset;
|
|
165
|
+
const containerSizes = {
|
|
166
|
+
x: 0,
|
|
167
|
+
y: 0,
|
|
168
|
+
height: window.innerHeight,
|
|
169
|
+
width: window.innerWidth
|
|
170
|
+
};
|
|
171
|
+
const offset = normalizeOffset(this.$options.offset);
|
|
172
|
+
const [yStart, yEnd] = getEdges("y", targetSizes, containerSizes, offset);
|
|
153
173
|
const yCurrent = clamp(window.pageYOffset, yStart, yEnd);
|
|
154
174
|
const yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));
|
|
155
|
-
const xEnd =
|
|
156
|
-
const xStart = xEnd - window.innerWidth - sizes.width;
|
|
175
|
+
const [xStart, xEnd] = getEdges("x", targetSizes, containerSizes, offset);
|
|
157
176
|
const xCurrent = clamp(window.pageXOffset, xStart, xEnd);
|
|
158
177
|
const xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));
|
|
159
178
|
this.__props.start.x = xStart;
|
|
@@ -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 * @private\n * @type {ScrollInViewProps}\n */\n __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 * @private\n */\n __setProps(): 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 /**\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.__setProps();\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\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('mounted', () => {\n this.__setProps();\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 * Set the decorator props.\n */\n __setProps() {\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 = damp(\n xCurrent,\n this.__props.dampedCurrent.x,\n this.dampFactor,\n this.dampPrecision,\n );\n this.__props.dampedCurrent.y = damp(\n yCurrent,\n this.__props.dampedCurrent.y,\n this.dampFactor,\n this.dampPrecision,\n );\n this.__props.progress.x = xProgress;\n this.__props.progress.y = yProgress;\n this.__props.dampedProgress.x = clamp01(\n (this.__props.dampedCurrent.x - xStart) / (xEnd - xStart),\n );\n this.__props.dampedProgress.y = clamp01(\n (this.__props.dampedCurrent.y - yStart) / (yEnd - yStart),\n );\n }\n }\n\n // @ts-ignore\n return WithScrolledInView;\n}\n"],
|
|
5
|
+
"mappings": "AAOA,SAAS,2BAA2B;AACpC;AAA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,SAC7B,KAAK,QAAQ,cAAc,IAAI,WAAW,OAAO;AAAA,MACpD;AAAA,IACF;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
|
+
"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.8.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.
|
package/services/index.d.ts
CHANGED
|
@@ -23,13 +23,13 @@ export interface ServiceInterface<T> {
|
|
|
23
23
|
*/
|
|
24
24
|
props(): T;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
27
|
-
export
|
|
28
|
-
export
|
|
29
|
-
export
|
|
30
|
-
export
|
|
31
|
-
export
|
|
32
|
-
export
|
|
26
|
+
export type DragServiceInterface = ServiceInterface<DragServiceProps>;
|
|
27
|
+
export type KeyServiceInterface = ServiceInterface<KeyServiceProps>;
|
|
28
|
+
export type LoadServiceInterface = ServiceInterface<LoadServiceProps>;
|
|
29
|
+
export type PointerServiceInterface = ServiceInterface<PointerServiceProps>;
|
|
30
|
+
export type RafServiceInterface = ServiceInterface<RafServiceProps>;
|
|
31
|
+
export type ResizeServiceInterface = ServiceInterface<ResizeServiceProps>;
|
|
32
|
+
export type ScrollServiceInterface = ServiceInterface<ScrollServiceProps>;
|
|
33
33
|
export type { DragServiceProps, KeyServiceProps, LoadServiceProps, PointerServiceProps, RafServiceProps, ResizeServiceProps, ScrollServiceProps, };
|
|
34
34
|
export { default as useDrag } from './drag.js';
|
|
35
35
|
export { default as useKey } from './key.js';
|
package/services/key.d.ts
CHANGED
package/services/load.d.ts
CHANGED
package/services/pointer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ServiceInterface } from './index.js';
|
|
2
|
-
export
|
|
2
|
+
export type PointerService = ServiceInterface<PointerServiceProps>;
|
|
3
3
|
export interface PointerServiceProps {
|
|
4
4
|
event: MouseEvent | TouchEvent;
|
|
5
5
|
isDown: boolean;
|