@kiva/kv-components 3.106.0 → 3.107.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/.eslintrc.cjs +1 -0
- package/CHANGELOG.md +11 -0
- package/dist/Alea.cjs +87 -0
- package/dist/Alea.js +63 -0
- package/dist/attrs.cjs +50 -0
- package/dist/attrs.js +26 -0
- package/dist/carousels.cjs +184 -0
- package/dist/carousels.js +147 -0
- package/dist/chunk-HV3AUBFT.js +15 -0
- package/dist/expander.cjs +78 -0
- package/dist/expander.js +53 -0
- package/dist/imageUtils.cjs +54 -0
- package/dist/imageUtils.js +29 -0
- package/dist/loanCard.cjs +222 -0
- package/dist/loanCard.js +200 -0
- package/dist/loanUtils.cjs +170 -0
- package/dist/loanUtils.js +128 -0
- package/dist/mapUtils.cjs +276 -0
- package/dist/mapUtils.js +248 -0
- package/dist/printing.cjs +42 -0
- package/dist/printing.js +17 -0
- package/dist/scrollLock.cjs +54 -0
- package/dist/scrollLock.js +27 -0
- package/dist/throttle.cjs +38 -0
- package/dist/throttle.js +6 -0
- package/dist/touchEvents.cjs +47 -0
- package/dist/touchEvents.js +21 -0
- package/dist/treemap.cjs +133 -0
- package/dist/treemap.js +109 -0
- package/package.json +12 -4
- package/vue/KvVerticalCarousel.vue +1 -1
package/dist/mapUtils.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
// utils/mapUtils.js
|
|
2
|
+
function getRandomInRange(from, to, fixed) {
|
|
3
|
+
return (Math.random() * (to - from) + from).toFixed(fixed) * 1;
|
|
4
|
+
}
|
|
5
|
+
var randomCoordinates = Array.from(
|
|
6
|
+
{ length: 20 },
|
|
7
|
+
() => [getRandomInRange(-180, 180, 3), getRandomInRange(-90, 90, 3)]
|
|
8
|
+
);
|
|
9
|
+
var mapColors = [
|
|
10
|
+
100,
|
|
11
|
+
300,
|
|
12
|
+
500,
|
|
13
|
+
650,
|
|
14
|
+
800,
|
|
15
|
+
1e3
|
|
16
|
+
];
|
|
17
|
+
function getCoordinatesBetween(startCoordinates, endCoordinates, numberOfSteps) {
|
|
18
|
+
if (!startCoordinates || !endCoordinates || !numberOfSteps || numberOfSteps < 1 || !Array.isArray(startCoordinates) || !Array.isArray(endCoordinates) || startCoordinates.length !== 2 || endCoordinates.length !== 2) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
const diffX = endCoordinates[0] - startCoordinates[0];
|
|
22
|
+
const diffY = endCoordinates[1] - startCoordinates[1];
|
|
23
|
+
const sfX = diffX / numberOfSteps;
|
|
24
|
+
const sfY = diffY / numberOfSteps;
|
|
25
|
+
let i = 0;
|
|
26
|
+
let j = 0;
|
|
27
|
+
const lineCoordinates = [];
|
|
28
|
+
while (Math.abs(i) < Math.abs(diffX) || Math.abs(j) < Math.abs(diffY)) {
|
|
29
|
+
lineCoordinates.push([startCoordinates[0] + i, startCoordinates[1] + j]);
|
|
30
|
+
if (Math.abs(i) < Math.abs(diffX)) {
|
|
31
|
+
i += sfX;
|
|
32
|
+
}
|
|
33
|
+
if (Math.abs(j) < Math.abs(diffY)) {
|
|
34
|
+
j += sfY;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
lineCoordinates[lineCoordinates.length - 1] = [endCoordinates[0], endCoordinates[1]];
|
|
38
|
+
return lineCoordinates;
|
|
39
|
+
}
|
|
40
|
+
function animateLines(mapInstance, originPoints, endPoint) {
|
|
41
|
+
const speedFactor = 100;
|
|
42
|
+
return new Promise((resolve) => {
|
|
43
|
+
mapInstance.addSource("endpoint", {
|
|
44
|
+
type: "geojson",
|
|
45
|
+
data: {
|
|
46
|
+
type: "Point",
|
|
47
|
+
coordinates: [
|
|
48
|
+
endPoint[0],
|
|
49
|
+
endPoint[1]
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const lineFlight = (startCoordinates, endCoordinates, index, lastLine = false) => {
|
|
54
|
+
const lineCoordinates = getCoordinatesBetween(startCoordinates, endCoordinates, speedFactor);
|
|
55
|
+
let animationCounter = 0;
|
|
56
|
+
const geojson = {
|
|
57
|
+
type: "FeatureCollection",
|
|
58
|
+
features: [{
|
|
59
|
+
type: "Feature",
|
|
60
|
+
geometry: {
|
|
61
|
+
type: "LineString",
|
|
62
|
+
coordinates: []
|
|
63
|
+
}
|
|
64
|
+
}]
|
|
65
|
+
};
|
|
66
|
+
mapInstance.addSource(`startPoint${index}`, {
|
|
67
|
+
type: "geojson",
|
|
68
|
+
data: {
|
|
69
|
+
type: "Point",
|
|
70
|
+
coordinates: [
|
|
71
|
+
startCoordinates[0],
|
|
72
|
+
startCoordinates[1]
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
mapInstance.addLayer({
|
|
77
|
+
id: `line-animation${index}`,
|
|
78
|
+
type: "line",
|
|
79
|
+
source: {
|
|
80
|
+
type: "geojson",
|
|
81
|
+
data: geojson
|
|
82
|
+
},
|
|
83
|
+
layout: {
|
|
84
|
+
"line-cap": "round",
|
|
85
|
+
"line-join": "round"
|
|
86
|
+
},
|
|
87
|
+
paint: {
|
|
88
|
+
"line-color": "#277056",
|
|
89
|
+
"line-width": 2
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const animateLine = () => {
|
|
93
|
+
if (animationCounter < lineCoordinates.length) {
|
|
94
|
+
geojson.features[0].geometry.coordinates.push(lineCoordinates[animationCounter]);
|
|
95
|
+
mapInstance.getSource(`line-animation${index}`).setData(geojson);
|
|
96
|
+
requestAnimationFrame(animateLine);
|
|
97
|
+
animationCounter += 1;
|
|
98
|
+
} else {
|
|
99
|
+
const coord = geojson.features[0].geometry.coordinates;
|
|
100
|
+
coord.shift();
|
|
101
|
+
coord.shift();
|
|
102
|
+
if (coord.length > 0) {
|
|
103
|
+
geojson.features[0].geometry.coordinates = coord;
|
|
104
|
+
mapInstance.getSource(`line-animation${index}`).setData(geojson);
|
|
105
|
+
requestAnimationFrame(animateLine);
|
|
106
|
+
} else {
|
|
107
|
+
mapInstance.removeLayer(`line-animation${index}`);
|
|
108
|
+
mapInstance.removeSource(`line-animation${index}`);
|
|
109
|
+
mapInstance.removeSource(`startPoint${index}`);
|
|
110
|
+
if (lastLine) {
|
|
111
|
+
mapInstance.removeSource("endpoint");
|
|
112
|
+
resolve();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
animateLine();
|
|
118
|
+
};
|
|
119
|
+
originPoints.forEach((coordinate, index) => {
|
|
120
|
+
lineFlight(coordinate, endPoint, index, index === originPoints.length - 1);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function generateMapMarkers(mapInstance, borrowerPoints) {
|
|
125
|
+
const geojson = {
|
|
126
|
+
type: "FeatureCollection"
|
|
127
|
+
};
|
|
128
|
+
geojson.features = borrowerPoints.map((borrower) => ({
|
|
129
|
+
type: "Feature",
|
|
130
|
+
properties: {
|
|
131
|
+
message: "test",
|
|
132
|
+
image: borrower.image,
|
|
133
|
+
iconSize: [80, 80]
|
|
134
|
+
},
|
|
135
|
+
geometry: {
|
|
136
|
+
type: "Point",
|
|
137
|
+
coordinates: borrower.location
|
|
138
|
+
}
|
|
139
|
+
}));
|
|
140
|
+
geojson.features.forEach((marker) => {
|
|
141
|
+
const el = document.createElement("div");
|
|
142
|
+
el.className = "map-marker";
|
|
143
|
+
el.style.backgroundImage = `url(${marker.properties.image})`;
|
|
144
|
+
el.style.width = `${marker.properties.iconSize[0]}px`;
|
|
145
|
+
el.style.height = `${marker.properties.iconSize[1]}px`;
|
|
146
|
+
new maplibregl.Marker({ element: el }).setLngLat(marker.geometry.coordinates).addTo(mapInstance);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function animationCoordinator(mapInstance, borrowerPoints) {
|
|
150
|
+
return new Promise((resolve) => {
|
|
151
|
+
const destinationPoints = borrowerPoints.map((borrower) => borrower.location);
|
|
152
|
+
const totalNumberOfPoints = destinationPoints.length;
|
|
153
|
+
let currentPointIndex = 0;
|
|
154
|
+
const flyToPoint = (index) => {
|
|
155
|
+
mapInstance.flyTo({
|
|
156
|
+
// These options control the ending camera position: centered at
|
|
157
|
+
// the target, at zoom level 9, and north up.
|
|
158
|
+
center: destinationPoints[index],
|
|
159
|
+
zoom: 4,
|
|
160
|
+
bearing: 0,
|
|
161
|
+
// These options control the flight curve, making it move
|
|
162
|
+
// slowly and zoom out almost completely before starting
|
|
163
|
+
// to pan.
|
|
164
|
+
speed: 0.9,
|
|
165
|
+
// make the flying slow
|
|
166
|
+
curve: 1,
|
|
167
|
+
// change the speed at which it zooms out
|
|
168
|
+
// This can be any easing function: it takes a number between
|
|
169
|
+
// 0 and 1 and returns another number between 0 and 1.
|
|
170
|
+
easing(t) {
|
|
171
|
+
return t;
|
|
172
|
+
},
|
|
173
|
+
// this animation is considered essential with respect to prefers-reduced-motion
|
|
174
|
+
essential: true
|
|
175
|
+
}, { flyEnd: true });
|
|
176
|
+
};
|
|
177
|
+
mapInstance.on("moveend", (event) => {
|
|
178
|
+
if (event.flyEnd === true) {
|
|
179
|
+
animateLines(mapInstance, randomCoordinates, destinationPoints[currentPointIndex]).then(() => {
|
|
180
|
+
if (currentPointIndex < totalNumberOfPoints - 1) {
|
|
181
|
+
currentPointIndex += 1;
|
|
182
|
+
flyToPoint(currentPointIndex);
|
|
183
|
+
} else {
|
|
184
|
+
resolve();
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
flyToPoint(currentPointIndex);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
var getLoansIntervals = (min, max, nbIntervals) => {
|
|
193
|
+
const size = Math.floor((max - min) / nbIntervals);
|
|
194
|
+
const result = [];
|
|
195
|
+
if (size <= 0)
|
|
196
|
+
return [[min, max]];
|
|
197
|
+
for (let i = 0; i < nbIntervals; i += 1) {
|
|
198
|
+
let inf = min + i * size;
|
|
199
|
+
let sup = inf + size < max ? inf + size : max;
|
|
200
|
+
if (i > 0) {
|
|
201
|
+
inf += 1 * i;
|
|
202
|
+
sup += 1 * i;
|
|
203
|
+
}
|
|
204
|
+
if (i > 0 && sup > max) {
|
|
205
|
+
sup = max;
|
|
206
|
+
}
|
|
207
|
+
if (i === nbIntervals - 1) {
|
|
208
|
+
if (sup < max || sup > max)
|
|
209
|
+
sup = max;
|
|
210
|
+
}
|
|
211
|
+
result.push([inf, sup]);
|
|
212
|
+
if (sup >= max)
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
return result;
|
|
216
|
+
};
|
|
217
|
+
var getCountryColor = (lenderLoans, countriesData, kvTokensPrimitives) => {
|
|
218
|
+
const loanCountsArray = [];
|
|
219
|
+
countriesData.forEach((country) => {
|
|
220
|
+
loanCountsArray.push(country.value);
|
|
221
|
+
});
|
|
222
|
+
const maxNumLoansToOneCountry = Math.max(...loanCountsArray);
|
|
223
|
+
const intervals = getLoansIntervals(1, maxNumLoansToOneCountry, 6);
|
|
224
|
+
if (intervals.length === 1) {
|
|
225
|
+
const [inf, sup] = intervals[0];
|
|
226
|
+
for (let i = 0; i < sup; i += 1) {
|
|
227
|
+
const loansNumber = i + 1;
|
|
228
|
+
if (lenderLoans && lenderLoans >= loansNumber && lenderLoans < loansNumber + 1) {
|
|
229
|
+
return kvTokensPrimitives.colors.brand[mapColors[i]];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
} else {
|
|
233
|
+
for (let i = 0; i < intervals.length; i += 1) {
|
|
234
|
+
const [inf, sup] = intervals[i];
|
|
235
|
+
if (lenderLoans && lenderLoans >= inf && lenderLoans <= sup) {
|
|
236
|
+
return kvTokensPrimitives.colors.brand[mapColors[i]];
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return kvTokensPrimitives.colors.gray[300];
|
|
241
|
+
};
|
|
242
|
+
export {
|
|
243
|
+
animationCoordinator,
|
|
244
|
+
generateMapMarkers,
|
|
245
|
+
getCoordinatesBetween,
|
|
246
|
+
getCountryColor,
|
|
247
|
+
getLoansIntervals
|
|
248
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
// utils/printing.js
|
|
20
|
+
var printing_exports = {};
|
|
21
|
+
__export(printing_exports, {
|
|
22
|
+
lockPrintSingleEl: () => lockPrintSingleEl,
|
|
23
|
+
unlockPrintSingleEl: () => unlockPrintSingleEl
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(printing_exports);
|
|
26
|
+
function lockPrintSingleEl(domNode) {
|
|
27
|
+
if (typeof window !== "undefined" && domNode) {
|
|
28
|
+
document.body.classList.add("print:tw-invisible", "print:tw-overflow-hidden");
|
|
29
|
+
domNode.classList.add("print:tw-visible", "print:tw-overflow-auto");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function unlockPrintSingleEl(domNode) {
|
|
33
|
+
if (typeof window !== "undefined" && domNode) {
|
|
34
|
+
document.body.classList.remove("print:tw-invisible", "print:tw-overflow-hidden");
|
|
35
|
+
domNode.classList.remove("print:tw-visible", "print:tw-overflow-auto");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
lockPrintSingleEl,
|
|
41
|
+
unlockPrintSingleEl
|
|
42
|
+
});
|
package/dist/printing.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// utils/printing.js
|
|
2
|
+
function lockPrintSingleEl(domNode) {
|
|
3
|
+
if (typeof window !== "undefined" && domNode) {
|
|
4
|
+
document.body.classList.add("print:tw-invisible", "print:tw-overflow-hidden");
|
|
5
|
+
domNode.classList.add("print:tw-visible", "print:tw-overflow-auto");
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function unlockPrintSingleEl(domNode) {
|
|
9
|
+
if (typeof window !== "undefined" && domNode) {
|
|
10
|
+
document.body.classList.remove("print:tw-invisible", "print:tw-overflow-hidden");
|
|
11
|
+
domNode.classList.remove("print:tw-visible", "print:tw-overflow-auto");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
lockPrintSingleEl,
|
|
16
|
+
unlockPrintSingleEl
|
|
17
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
// utils/scrollLock.js
|
|
20
|
+
var scrollLock_exports = {};
|
|
21
|
+
__export(scrollLock_exports, {
|
|
22
|
+
lockScroll: () => lockScroll,
|
|
23
|
+
lockScrollSmallOnly: () => lockScrollSmallOnly,
|
|
24
|
+
unlockScroll: () => unlockScroll,
|
|
25
|
+
unlockScrollSmallOnly: () => unlockScrollSmallOnly
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(scrollLock_exports);
|
|
28
|
+
function lockScroll() {
|
|
29
|
+
if (typeof window !== "undefined") {
|
|
30
|
+
document.body.style.overflow = "hidden";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function unlockScroll() {
|
|
34
|
+
if (typeof window !== "undefined") {
|
|
35
|
+
document.body.style.overflow = null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function lockScrollSmallOnly() {
|
|
39
|
+
if (typeof window !== "undefined") {
|
|
40
|
+
document.body.classList.add("tw-overflow-hidden", "md:tw-overflow-auto");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function unlockScrollSmallOnly() {
|
|
44
|
+
if (typeof window !== "undefined") {
|
|
45
|
+
document.body.classList.remove("tw-overflow-hidden", "md:tw-overflow-auto");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
lockScroll,
|
|
51
|
+
lockScrollSmallOnly,
|
|
52
|
+
unlockScroll,
|
|
53
|
+
unlockScrollSmallOnly
|
|
54
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// utils/scrollLock.js
|
|
2
|
+
function lockScroll() {
|
|
3
|
+
if (typeof window !== "undefined") {
|
|
4
|
+
document.body.style.overflow = "hidden";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function unlockScroll() {
|
|
8
|
+
if (typeof window !== "undefined") {
|
|
9
|
+
document.body.style.overflow = null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function lockScrollSmallOnly() {
|
|
13
|
+
if (typeof window !== "undefined") {
|
|
14
|
+
document.body.classList.add("tw-overflow-hidden", "md:tw-overflow-auto");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function unlockScrollSmallOnly() {
|
|
18
|
+
if (typeof window !== "undefined") {
|
|
19
|
+
document.body.classList.remove("tw-overflow-hidden", "md:tw-overflow-auto");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
lockScroll,
|
|
24
|
+
lockScrollSmallOnly,
|
|
25
|
+
unlockScroll,
|
|
26
|
+
unlockScrollSmallOnly
|
|
27
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
// utils/throttle.js
|
|
20
|
+
var throttle_exports = {};
|
|
21
|
+
__export(throttle_exports, {
|
|
22
|
+
throttle: () => throttle
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(throttle_exports);
|
|
25
|
+
function throttle(func, timeFrame) {
|
|
26
|
+
let lastTime = 0;
|
|
27
|
+
return function t(...args) {
|
|
28
|
+
const now = /* @__PURE__ */ new Date();
|
|
29
|
+
if (now - lastTime >= timeFrame) {
|
|
30
|
+
func(...args);
|
|
31
|
+
lastTime = now;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
throttle
|
|
38
|
+
});
|
package/dist/throttle.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
// utils/touchEvents.js
|
|
20
|
+
var touchEvents_exports = {};
|
|
21
|
+
__export(touchEvents_exports, {
|
|
22
|
+
isTargetElement: () => isTargetElement,
|
|
23
|
+
offBodyTouchstart: () => offBodyTouchstart,
|
|
24
|
+
onBodyTouchstart: () => onBodyTouchstart
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(touchEvents_exports);
|
|
27
|
+
function onBodyTouchstart(handler) {
|
|
28
|
+
[...document.body.children].forEach((child) => child.addEventListener("touchstart", handler));
|
|
29
|
+
}
|
|
30
|
+
function offBodyTouchstart(handler) {
|
|
31
|
+
[...document.body.children].forEach((child) => child.removeEventListener("touchstart", handler));
|
|
32
|
+
}
|
|
33
|
+
function isTargetElement(event, elements) {
|
|
34
|
+
const els = Array.isArray(elements) ? elements : [elements];
|
|
35
|
+
for (let i = 0; i < els.length; i += 1) {
|
|
36
|
+
if (els[i] === event.target || els[i].contains(event.target)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
isTargetElement,
|
|
45
|
+
offBodyTouchstart,
|
|
46
|
+
onBodyTouchstart
|
|
47
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// utils/touchEvents.js
|
|
2
|
+
function onBodyTouchstart(handler) {
|
|
3
|
+
[...document.body.children].forEach((child) => child.addEventListener("touchstart", handler));
|
|
4
|
+
}
|
|
5
|
+
function offBodyTouchstart(handler) {
|
|
6
|
+
[...document.body.children].forEach((child) => child.removeEventListener("touchstart", handler));
|
|
7
|
+
}
|
|
8
|
+
function isTargetElement(event, elements) {
|
|
9
|
+
const els = Array.isArray(elements) ? elements : [elements];
|
|
10
|
+
for (let i = 0; i < els.length; i += 1) {
|
|
11
|
+
if (els[i] === event.target || els[i].contains(event.target)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
isTargetElement,
|
|
19
|
+
offBodyTouchstart,
|
|
20
|
+
onBodyTouchstart
|
|
21
|
+
};
|
package/dist/treemap.cjs
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
// utils/treemap.js
|
|
20
|
+
var treemap_exports = {};
|
|
21
|
+
__export(treemap_exports, {
|
|
22
|
+
getTreemap: () => getTreemap
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(treemap_exports);
|
|
25
|
+
var getMaximum = (array) => Math.max(...array);
|
|
26
|
+
var getMinimum = (array) => Math.min(...array);
|
|
27
|
+
var sumReducer = (acc, cur) => acc + cur;
|
|
28
|
+
var roundValue = (number) => Math.max(Math.round(number * 100) / 100, 0);
|
|
29
|
+
var validateArguments = ({ data, width, height }) => {
|
|
30
|
+
if (!width || typeof width !== "number" || width < 0) {
|
|
31
|
+
throw new Error("You need to specify the width of your treemap");
|
|
32
|
+
}
|
|
33
|
+
if (!height || typeof height !== "number" || height < 0) {
|
|
34
|
+
throw new Error("You need to specify the height of your treemap");
|
|
35
|
+
}
|
|
36
|
+
if (!data || !Array.isArray(data) || data.length === 0 || !data.every((dataPoint) => Object.prototype.hasOwnProperty.call(dataPoint, "value") && typeof dataPoint.value === "number" && dataPoint.value >= 0 && !Number.isNaN(dataPoint.value))) {
|
|
37
|
+
throw new Error("You data must be in this format [{ value: 1 }, { value: 2 }], 'value' being a positive number");
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function getTreemap({ data, width, height }) {
|
|
41
|
+
let Rectangle = {};
|
|
42
|
+
let initialData = [];
|
|
43
|
+
function worstRatio(row, width2) {
|
|
44
|
+
const sum = row.reduce(sumReducer, 0);
|
|
45
|
+
const rowMax = getMaximum(row);
|
|
46
|
+
const rowMin = getMinimum(row);
|
|
47
|
+
return Math.max(width2 ** 2 * rowMax / sum ** 2, sum ** 2 / (width2 ** 2 * rowMin));
|
|
48
|
+
}
|
|
49
|
+
const getMinWidth = () => {
|
|
50
|
+
if (Rectangle.totalHeight ** 2 > Rectangle.totalWidth ** 2) {
|
|
51
|
+
return { value: Rectangle.totalWidth, vertical: false };
|
|
52
|
+
}
|
|
53
|
+
return { value: Rectangle.totalHeight, vertical: true };
|
|
54
|
+
};
|
|
55
|
+
const layoutRow = (row, width2, vertical) => {
|
|
56
|
+
const rowHeight = row.reduce(sumReducer, 0) / width2;
|
|
57
|
+
row.forEach((rowItem) => {
|
|
58
|
+
const rowWidth = rowItem / rowHeight;
|
|
59
|
+
const { xBeginning } = Rectangle;
|
|
60
|
+
const { yBeginning } = Rectangle;
|
|
61
|
+
let data2;
|
|
62
|
+
if (vertical) {
|
|
63
|
+
data2 = {
|
|
64
|
+
x: xBeginning,
|
|
65
|
+
y: yBeginning,
|
|
66
|
+
width: rowHeight,
|
|
67
|
+
height: rowWidth,
|
|
68
|
+
data: initialData[Rectangle.data.length]
|
|
69
|
+
};
|
|
70
|
+
Rectangle.yBeginning += rowWidth;
|
|
71
|
+
} else {
|
|
72
|
+
data2 = {
|
|
73
|
+
x: xBeginning,
|
|
74
|
+
y: yBeginning,
|
|
75
|
+
width: rowWidth,
|
|
76
|
+
height: rowHeight,
|
|
77
|
+
data: initialData[Rectangle.data.length]
|
|
78
|
+
};
|
|
79
|
+
Rectangle.xBeginning += rowWidth;
|
|
80
|
+
}
|
|
81
|
+
Rectangle.data.push(data2);
|
|
82
|
+
});
|
|
83
|
+
if (vertical) {
|
|
84
|
+
Rectangle.xBeginning += rowHeight;
|
|
85
|
+
Rectangle.yBeginning -= width2;
|
|
86
|
+
Rectangle.totalWidth -= rowHeight;
|
|
87
|
+
} else {
|
|
88
|
+
Rectangle.xBeginning -= width2;
|
|
89
|
+
Rectangle.yBeginning += rowHeight;
|
|
90
|
+
Rectangle.totalHeight -= rowHeight;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const layoutLastRow = (rows, children, width2) => {
|
|
94
|
+
const { vertical } = getMinWidth();
|
|
95
|
+
layoutRow(rows, width2, vertical);
|
|
96
|
+
layoutRow(children, width2, vertical);
|
|
97
|
+
};
|
|
98
|
+
const squarify = (children, row, width2) => {
|
|
99
|
+
if (children.length === 1) {
|
|
100
|
+
return layoutLastRow(row, children, width2);
|
|
101
|
+
}
|
|
102
|
+
const rowWithChild = [...row, children[0]];
|
|
103
|
+
if (row.length === 0 || worstRatio(row, width2) >= worstRatio(rowWithChild, width2)) {
|
|
104
|
+
children.shift();
|
|
105
|
+
return squarify(children, rowWithChild, width2);
|
|
106
|
+
}
|
|
107
|
+
layoutRow(row, width2, getMinWidth().vertical);
|
|
108
|
+
return squarify(children, [], getMinWidth().value);
|
|
109
|
+
};
|
|
110
|
+
validateArguments({ data, width, height });
|
|
111
|
+
Rectangle = {
|
|
112
|
+
data: [],
|
|
113
|
+
xBeginning: 0,
|
|
114
|
+
yBeginning: 0,
|
|
115
|
+
totalWidth: width,
|
|
116
|
+
totalHeight: height
|
|
117
|
+
};
|
|
118
|
+
initialData = data;
|
|
119
|
+
const totalValue = data.map((dataPoint) => dataPoint.value).reduce(sumReducer, 0);
|
|
120
|
+
const dataScaled = data.map((dataPoint) => dataPoint.value * height * width / totalValue);
|
|
121
|
+
squarify(dataScaled, [], getMinWidth().value);
|
|
122
|
+
return Rectangle.data.map((dataPoint) => ({
|
|
123
|
+
...dataPoint,
|
|
124
|
+
x: roundValue(dataPoint.x),
|
|
125
|
+
y: roundValue(dataPoint.y),
|
|
126
|
+
width: roundValue(dataPoint.width),
|
|
127
|
+
height: roundValue(dataPoint.height)
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
131
|
+
0 && (module.exports = {
|
|
132
|
+
getTreemap
|
|
133
|
+
});
|