@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
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// utils/loanUtils.js
|
|
30
|
+
var loanUtils_exports = {};
|
|
31
|
+
__export(loanUtils_exports, {
|
|
32
|
+
BALANCE_CAMPAIGN: () => BALANCE_CAMPAIGN,
|
|
33
|
+
BASE_CAMPAIGN: () => BASE_CAMPAIGN,
|
|
34
|
+
ERL_COOKIE_NAME: () => ERL_COOKIE_NAME,
|
|
35
|
+
NO_BALANCE_CAMPAIGN: () => NO_BALANCE_CAMPAIGN,
|
|
36
|
+
TOP_UP_CAMPAIGN: () => TOP_UP_CAMPAIGN,
|
|
37
|
+
getDropdownPriceArray: () => getDropdownPriceArray,
|
|
38
|
+
getLendCtaSelectedOption: () => getLendCtaSelectedOption,
|
|
39
|
+
isBetween25And50: () => isBetween25And50,
|
|
40
|
+
isLessThan25: () => isLessThan25
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(loanUtils_exports);
|
|
43
|
+
var import_numeral = __toESM(require("numeral"), 1);
|
|
44
|
+
var ERL_COOKIE_NAME = "kverlfivedollarnotes";
|
|
45
|
+
var TOP_UP_CAMPAIGN = "TOPUP-VB-BALANCE-MPV1";
|
|
46
|
+
var BASE_CAMPAIGN = "BASE-VB_BALANCE_MPV1";
|
|
47
|
+
var BALANCE_CAMPAIGN = "REPAYMENT-NOTIFICATION_BALANCE_MPV1";
|
|
48
|
+
var NO_BALANCE_CAMPAIGN = "REPAYMENT-NOTIFICATION_NO-BALANCE_MPV1";
|
|
49
|
+
function balanceCampaignOptions(val) {
|
|
50
|
+
if (val > 20)
|
|
51
|
+
return 25;
|
|
52
|
+
if (val > 15)
|
|
53
|
+
return 20;
|
|
54
|
+
if (val > 10)
|
|
55
|
+
return 15;
|
|
56
|
+
if (val > 5)
|
|
57
|
+
return 10;
|
|
58
|
+
return 5;
|
|
59
|
+
}
|
|
60
|
+
function isBetween25And50(unreservedAmount) {
|
|
61
|
+
return unreservedAmount <= 50 && unreservedAmount > 25;
|
|
62
|
+
}
|
|
63
|
+
function isLessThan25(unreservedAmount) {
|
|
64
|
+
return unreservedAmount < 25 && unreservedAmount > 0;
|
|
65
|
+
}
|
|
66
|
+
function getLendCtaSelectedOption(getCookie, setCookie, enableFiveDollarsNotes, campaign, unreservedAmount, userBalance, fiveDollarsSelected) {
|
|
67
|
+
if (enableFiveDollarsNotes && fiveDollarsSelected) {
|
|
68
|
+
return "5";
|
|
69
|
+
}
|
|
70
|
+
if (enableFiveDollarsNotes && typeof userBalance !== "undefined") {
|
|
71
|
+
let currentCampaign = getCookie == null ? void 0 : getCookie(ERL_COOKIE_NAME);
|
|
72
|
+
if (campaign && typeof campaign === "string" && !currentCampaign) {
|
|
73
|
+
const expires = /* @__PURE__ */ new Date();
|
|
74
|
+
expires.setHours(expires.getHours() + 24);
|
|
75
|
+
const campaignToCheck = campaign.toUpperCase();
|
|
76
|
+
currentCampaign = campaignToCheck.includes(TOP_UP_CAMPAIGN) ? TOP_UP_CAMPAIGN : campaignToCheck.includes(BASE_CAMPAIGN) ? BASE_CAMPAIGN : campaignToCheck.includes(BALANCE_CAMPAIGN) ? BALANCE_CAMPAIGN : campaignToCheck.includes(NO_BALANCE_CAMPAIGN) ? NO_BALANCE_CAMPAIGN : "";
|
|
77
|
+
if (currentCampaign && setCookie) {
|
|
78
|
+
setCookie(ERL_COOKIE_NAME, currentCampaign, { expires });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (currentCampaign) {
|
|
82
|
+
let val = Math.floor(userBalance / 5) * 5;
|
|
83
|
+
if (currentCampaign === BASE_CAMPAIGN) {
|
|
84
|
+
val = val === 0 ? 5 : val > 25 ? 25 : val;
|
|
85
|
+
return Number(val <= unreservedAmount ? val : unreservedAmount).toFixed();
|
|
86
|
+
}
|
|
87
|
+
if (currentCampaign === BALANCE_CAMPAIGN) {
|
|
88
|
+
val = balanceCampaignOptions(val);
|
|
89
|
+
return Number(val).toFixed();
|
|
90
|
+
}
|
|
91
|
+
return Number(unreservedAmount > 5 ? 5 : unreservedAmount).toFixed();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (isBetween25And50(unreservedAmount) || isLessThan25(unreservedAmount)) {
|
|
95
|
+
return Number(unreservedAmount).toFixed();
|
|
96
|
+
}
|
|
97
|
+
return "25";
|
|
98
|
+
}
|
|
99
|
+
function buildHugePriceArray(amountLeft) {
|
|
100
|
+
const priceArray = [];
|
|
101
|
+
let minAmount = 100;
|
|
102
|
+
let limitAmount = amountLeft > 1e3 ? 1e3 : amountLeft;
|
|
103
|
+
let optionCount = limitAmount / minAmount;
|
|
104
|
+
for (let i = 1; i <= optionCount; i += 1) {
|
|
105
|
+
const price = minAmount * i + 500;
|
|
106
|
+
if (price > limitAmount)
|
|
107
|
+
break;
|
|
108
|
+
priceArray.push((0, import_numeral.default)(price).format("0,0"));
|
|
109
|
+
}
|
|
110
|
+
minAmount = 1e3;
|
|
111
|
+
limitAmount = amountLeft > 1e4 ? 1e4 : amountLeft;
|
|
112
|
+
optionCount = limitAmount / minAmount;
|
|
113
|
+
for (let i = 1; i <= optionCount; i += 1) {
|
|
114
|
+
const price = minAmount * i + 1e3;
|
|
115
|
+
if (price > limitAmount)
|
|
116
|
+
break;
|
|
117
|
+
priceArray.push((0, import_numeral.default)(price).format("0,0"));
|
|
118
|
+
}
|
|
119
|
+
if (!priceArray.includes((0, import_numeral.default)(limitAmount).format("0,0"))) {
|
|
120
|
+
priceArray.push((0, import_numeral.default)(limitAmount).format("0,0"));
|
|
121
|
+
}
|
|
122
|
+
return priceArray;
|
|
123
|
+
}
|
|
124
|
+
function build5DollarsPriceArray(amountLeft) {
|
|
125
|
+
const limit5Notes = amountLeft < 50 ? amountLeft : 50;
|
|
126
|
+
const numberOf5 = limit5Notes / 5;
|
|
127
|
+
const numberOf25 = Math.ceil((amountLeft - limit5Notes) / 25) + 1;
|
|
128
|
+
const priceArray = [];
|
|
129
|
+
for (let i = 1; i <= numberOf5; i += 1) {
|
|
130
|
+
priceArray.push((0, import_numeral.default)(5 * i).format("0,0"));
|
|
131
|
+
}
|
|
132
|
+
if (amountLeft > limit5Notes) {
|
|
133
|
+
for (let i = 3; i <= numberOf25; i += 1) {
|
|
134
|
+
priceArray.push((0, import_numeral.default)(25 * i).format("0,0"));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return priceArray;
|
|
138
|
+
}
|
|
139
|
+
function buildPriceArray(amountLeft, minAmount) {
|
|
140
|
+
const optionCount = amountLeft / minAmount;
|
|
141
|
+
const priceArray = [];
|
|
142
|
+
for (let i = 1; i <= optionCount; i += 1) {
|
|
143
|
+
priceArray.push((0, import_numeral.default)(minAmount * i).format("0,0"));
|
|
144
|
+
}
|
|
145
|
+
return priceArray;
|
|
146
|
+
}
|
|
147
|
+
function getDropdownPriceArray(unreservedAmount, isCompleteLoanActive = false, minAmount = 25, enableFiveDollarsNotes = false, enableHugeAmount = false, isVisitor = true, inPfp = false) {
|
|
148
|
+
const parsedAmountLeft = parseFloat(unreservedAmount);
|
|
149
|
+
let priceArray = enableFiveDollarsNotes && !inPfp ? build5DollarsPriceArray(parsedAmountLeft).slice(0, 28) : buildPriceArray(parsedAmountLeft, minAmount).slice(0, 20);
|
|
150
|
+
if (enableHugeAmount && parsedAmountLeft > 500 && !isVisitor) {
|
|
151
|
+
const hugePriceArray = buildHugePriceArray(parsedAmountLeft);
|
|
152
|
+
priceArray = priceArray.concat(hugePriceArray);
|
|
153
|
+
}
|
|
154
|
+
if (isCompleteLoanActive && !priceArray.includes(Number(unreservedAmount).toFixed())) {
|
|
155
|
+
priceArray.push(Number(unreservedAmount).toFixed());
|
|
156
|
+
}
|
|
157
|
+
return priceArray;
|
|
158
|
+
}
|
|
159
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
160
|
+
0 && (module.exports = {
|
|
161
|
+
BALANCE_CAMPAIGN,
|
|
162
|
+
BASE_CAMPAIGN,
|
|
163
|
+
ERL_COOKIE_NAME,
|
|
164
|
+
NO_BALANCE_CAMPAIGN,
|
|
165
|
+
TOP_UP_CAMPAIGN,
|
|
166
|
+
getDropdownPriceArray,
|
|
167
|
+
getLendCtaSelectedOption,
|
|
168
|
+
isBetween25And50,
|
|
169
|
+
isLessThan25
|
|
170
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// utils/loanUtils.js
|
|
2
|
+
import numeral from "numeral";
|
|
3
|
+
var ERL_COOKIE_NAME = "kverlfivedollarnotes";
|
|
4
|
+
var TOP_UP_CAMPAIGN = "TOPUP-VB-BALANCE-MPV1";
|
|
5
|
+
var BASE_CAMPAIGN = "BASE-VB_BALANCE_MPV1";
|
|
6
|
+
var BALANCE_CAMPAIGN = "REPAYMENT-NOTIFICATION_BALANCE_MPV1";
|
|
7
|
+
var NO_BALANCE_CAMPAIGN = "REPAYMENT-NOTIFICATION_NO-BALANCE_MPV1";
|
|
8
|
+
function balanceCampaignOptions(val) {
|
|
9
|
+
if (val > 20)
|
|
10
|
+
return 25;
|
|
11
|
+
if (val > 15)
|
|
12
|
+
return 20;
|
|
13
|
+
if (val > 10)
|
|
14
|
+
return 15;
|
|
15
|
+
if (val > 5)
|
|
16
|
+
return 10;
|
|
17
|
+
return 5;
|
|
18
|
+
}
|
|
19
|
+
function isBetween25And50(unreservedAmount) {
|
|
20
|
+
return unreservedAmount <= 50 && unreservedAmount > 25;
|
|
21
|
+
}
|
|
22
|
+
function isLessThan25(unreservedAmount) {
|
|
23
|
+
return unreservedAmount < 25 && unreservedAmount > 0;
|
|
24
|
+
}
|
|
25
|
+
function getLendCtaSelectedOption(getCookie, setCookie, enableFiveDollarsNotes, campaign, unreservedAmount, userBalance, fiveDollarsSelected) {
|
|
26
|
+
if (enableFiveDollarsNotes && fiveDollarsSelected) {
|
|
27
|
+
return "5";
|
|
28
|
+
}
|
|
29
|
+
if (enableFiveDollarsNotes && typeof userBalance !== "undefined") {
|
|
30
|
+
let currentCampaign = getCookie == null ? void 0 : getCookie(ERL_COOKIE_NAME);
|
|
31
|
+
if (campaign && typeof campaign === "string" && !currentCampaign) {
|
|
32
|
+
const expires = /* @__PURE__ */ new Date();
|
|
33
|
+
expires.setHours(expires.getHours() + 24);
|
|
34
|
+
const campaignToCheck = campaign.toUpperCase();
|
|
35
|
+
currentCampaign = campaignToCheck.includes(TOP_UP_CAMPAIGN) ? TOP_UP_CAMPAIGN : campaignToCheck.includes(BASE_CAMPAIGN) ? BASE_CAMPAIGN : campaignToCheck.includes(BALANCE_CAMPAIGN) ? BALANCE_CAMPAIGN : campaignToCheck.includes(NO_BALANCE_CAMPAIGN) ? NO_BALANCE_CAMPAIGN : "";
|
|
36
|
+
if (currentCampaign && setCookie) {
|
|
37
|
+
setCookie(ERL_COOKIE_NAME, currentCampaign, { expires });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (currentCampaign) {
|
|
41
|
+
let val = Math.floor(userBalance / 5) * 5;
|
|
42
|
+
if (currentCampaign === BASE_CAMPAIGN) {
|
|
43
|
+
val = val === 0 ? 5 : val > 25 ? 25 : val;
|
|
44
|
+
return Number(val <= unreservedAmount ? val : unreservedAmount).toFixed();
|
|
45
|
+
}
|
|
46
|
+
if (currentCampaign === BALANCE_CAMPAIGN) {
|
|
47
|
+
val = balanceCampaignOptions(val);
|
|
48
|
+
return Number(val).toFixed();
|
|
49
|
+
}
|
|
50
|
+
return Number(unreservedAmount > 5 ? 5 : unreservedAmount).toFixed();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (isBetween25And50(unreservedAmount) || isLessThan25(unreservedAmount)) {
|
|
54
|
+
return Number(unreservedAmount).toFixed();
|
|
55
|
+
}
|
|
56
|
+
return "25";
|
|
57
|
+
}
|
|
58
|
+
function buildHugePriceArray(amountLeft) {
|
|
59
|
+
const priceArray = [];
|
|
60
|
+
let minAmount = 100;
|
|
61
|
+
let limitAmount = amountLeft > 1e3 ? 1e3 : amountLeft;
|
|
62
|
+
let optionCount = limitAmount / minAmount;
|
|
63
|
+
for (let i = 1; i <= optionCount; i += 1) {
|
|
64
|
+
const price = minAmount * i + 500;
|
|
65
|
+
if (price > limitAmount)
|
|
66
|
+
break;
|
|
67
|
+
priceArray.push(numeral(price).format("0,0"));
|
|
68
|
+
}
|
|
69
|
+
minAmount = 1e3;
|
|
70
|
+
limitAmount = amountLeft > 1e4 ? 1e4 : amountLeft;
|
|
71
|
+
optionCount = limitAmount / minAmount;
|
|
72
|
+
for (let i = 1; i <= optionCount; i += 1) {
|
|
73
|
+
const price = minAmount * i + 1e3;
|
|
74
|
+
if (price > limitAmount)
|
|
75
|
+
break;
|
|
76
|
+
priceArray.push(numeral(price).format("0,0"));
|
|
77
|
+
}
|
|
78
|
+
if (!priceArray.includes(numeral(limitAmount).format("0,0"))) {
|
|
79
|
+
priceArray.push(numeral(limitAmount).format("0,0"));
|
|
80
|
+
}
|
|
81
|
+
return priceArray;
|
|
82
|
+
}
|
|
83
|
+
function build5DollarsPriceArray(amountLeft) {
|
|
84
|
+
const limit5Notes = amountLeft < 50 ? amountLeft : 50;
|
|
85
|
+
const numberOf5 = limit5Notes / 5;
|
|
86
|
+
const numberOf25 = Math.ceil((amountLeft - limit5Notes) / 25) + 1;
|
|
87
|
+
const priceArray = [];
|
|
88
|
+
for (let i = 1; i <= numberOf5; i += 1) {
|
|
89
|
+
priceArray.push(numeral(5 * i).format("0,0"));
|
|
90
|
+
}
|
|
91
|
+
if (amountLeft > limit5Notes) {
|
|
92
|
+
for (let i = 3; i <= numberOf25; i += 1) {
|
|
93
|
+
priceArray.push(numeral(25 * i).format("0,0"));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return priceArray;
|
|
97
|
+
}
|
|
98
|
+
function buildPriceArray(amountLeft, minAmount) {
|
|
99
|
+
const optionCount = amountLeft / minAmount;
|
|
100
|
+
const priceArray = [];
|
|
101
|
+
for (let i = 1; i <= optionCount; i += 1) {
|
|
102
|
+
priceArray.push(numeral(minAmount * i).format("0,0"));
|
|
103
|
+
}
|
|
104
|
+
return priceArray;
|
|
105
|
+
}
|
|
106
|
+
function getDropdownPriceArray(unreservedAmount, isCompleteLoanActive = false, minAmount = 25, enableFiveDollarsNotes = false, enableHugeAmount = false, isVisitor = true, inPfp = false) {
|
|
107
|
+
const parsedAmountLeft = parseFloat(unreservedAmount);
|
|
108
|
+
let priceArray = enableFiveDollarsNotes && !inPfp ? build5DollarsPriceArray(parsedAmountLeft).slice(0, 28) : buildPriceArray(parsedAmountLeft, minAmount).slice(0, 20);
|
|
109
|
+
if (enableHugeAmount && parsedAmountLeft > 500 && !isVisitor) {
|
|
110
|
+
const hugePriceArray = buildHugePriceArray(parsedAmountLeft);
|
|
111
|
+
priceArray = priceArray.concat(hugePriceArray);
|
|
112
|
+
}
|
|
113
|
+
if (isCompleteLoanActive && !priceArray.includes(Number(unreservedAmount).toFixed())) {
|
|
114
|
+
priceArray.push(Number(unreservedAmount).toFixed());
|
|
115
|
+
}
|
|
116
|
+
return priceArray;
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
BALANCE_CAMPAIGN,
|
|
120
|
+
BASE_CAMPAIGN,
|
|
121
|
+
ERL_COOKIE_NAME,
|
|
122
|
+
NO_BALANCE_CAMPAIGN,
|
|
123
|
+
TOP_UP_CAMPAIGN,
|
|
124
|
+
getDropdownPriceArray,
|
|
125
|
+
getLendCtaSelectedOption,
|
|
126
|
+
isBetween25And50,
|
|
127
|
+
isLessThan25
|
|
128
|
+
};
|
|
@@ -0,0 +1,276 @@
|
|
|
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/mapUtils.js
|
|
20
|
+
var mapUtils_exports = {};
|
|
21
|
+
__export(mapUtils_exports, {
|
|
22
|
+
animationCoordinator: () => animationCoordinator,
|
|
23
|
+
generateMapMarkers: () => generateMapMarkers,
|
|
24
|
+
getCoordinatesBetween: () => getCoordinatesBetween,
|
|
25
|
+
getCountryColor: () => getCountryColor,
|
|
26
|
+
getLoansIntervals: () => getLoansIntervals
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(mapUtils_exports);
|
|
29
|
+
function getRandomInRange(from, to, fixed) {
|
|
30
|
+
return (Math.random() * (to - from) + from).toFixed(fixed) * 1;
|
|
31
|
+
}
|
|
32
|
+
var randomCoordinates = Array.from(
|
|
33
|
+
{ length: 20 },
|
|
34
|
+
() => [getRandomInRange(-180, 180, 3), getRandomInRange(-90, 90, 3)]
|
|
35
|
+
);
|
|
36
|
+
var mapColors = [
|
|
37
|
+
100,
|
|
38
|
+
300,
|
|
39
|
+
500,
|
|
40
|
+
650,
|
|
41
|
+
800,
|
|
42
|
+
1e3
|
|
43
|
+
];
|
|
44
|
+
function getCoordinatesBetween(startCoordinates, endCoordinates, numberOfSteps) {
|
|
45
|
+
if (!startCoordinates || !endCoordinates || !numberOfSteps || numberOfSteps < 1 || !Array.isArray(startCoordinates) || !Array.isArray(endCoordinates) || startCoordinates.length !== 2 || endCoordinates.length !== 2) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
const diffX = endCoordinates[0] - startCoordinates[0];
|
|
49
|
+
const diffY = endCoordinates[1] - startCoordinates[1];
|
|
50
|
+
const sfX = diffX / numberOfSteps;
|
|
51
|
+
const sfY = diffY / numberOfSteps;
|
|
52
|
+
let i = 0;
|
|
53
|
+
let j = 0;
|
|
54
|
+
const lineCoordinates = [];
|
|
55
|
+
while (Math.abs(i) < Math.abs(diffX) || Math.abs(j) < Math.abs(diffY)) {
|
|
56
|
+
lineCoordinates.push([startCoordinates[0] + i, startCoordinates[1] + j]);
|
|
57
|
+
if (Math.abs(i) < Math.abs(diffX)) {
|
|
58
|
+
i += sfX;
|
|
59
|
+
}
|
|
60
|
+
if (Math.abs(j) < Math.abs(diffY)) {
|
|
61
|
+
j += sfY;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
lineCoordinates[lineCoordinates.length - 1] = [endCoordinates[0], endCoordinates[1]];
|
|
65
|
+
return lineCoordinates;
|
|
66
|
+
}
|
|
67
|
+
function animateLines(mapInstance, originPoints, endPoint) {
|
|
68
|
+
const speedFactor = 100;
|
|
69
|
+
return new Promise((resolve) => {
|
|
70
|
+
mapInstance.addSource("endpoint", {
|
|
71
|
+
type: "geojson",
|
|
72
|
+
data: {
|
|
73
|
+
type: "Point",
|
|
74
|
+
coordinates: [
|
|
75
|
+
endPoint[0],
|
|
76
|
+
endPoint[1]
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const lineFlight = (startCoordinates, endCoordinates, index, lastLine = false) => {
|
|
81
|
+
const lineCoordinates = getCoordinatesBetween(startCoordinates, endCoordinates, speedFactor);
|
|
82
|
+
let animationCounter = 0;
|
|
83
|
+
const geojson = {
|
|
84
|
+
type: "FeatureCollection",
|
|
85
|
+
features: [{
|
|
86
|
+
type: "Feature",
|
|
87
|
+
geometry: {
|
|
88
|
+
type: "LineString",
|
|
89
|
+
coordinates: []
|
|
90
|
+
}
|
|
91
|
+
}]
|
|
92
|
+
};
|
|
93
|
+
mapInstance.addSource(`startPoint${index}`, {
|
|
94
|
+
type: "geojson",
|
|
95
|
+
data: {
|
|
96
|
+
type: "Point",
|
|
97
|
+
coordinates: [
|
|
98
|
+
startCoordinates[0],
|
|
99
|
+
startCoordinates[1]
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
mapInstance.addLayer({
|
|
104
|
+
id: `line-animation${index}`,
|
|
105
|
+
type: "line",
|
|
106
|
+
source: {
|
|
107
|
+
type: "geojson",
|
|
108
|
+
data: geojson
|
|
109
|
+
},
|
|
110
|
+
layout: {
|
|
111
|
+
"line-cap": "round",
|
|
112
|
+
"line-join": "round"
|
|
113
|
+
},
|
|
114
|
+
paint: {
|
|
115
|
+
"line-color": "#277056",
|
|
116
|
+
"line-width": 2
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
const animateLine = () => {
|
|
120
|
+
if (animationCounter < lineCoordinates.length) {
|
|
121
|
+
geojson.features[0].geometry.coordinates.push(lineCoordinates[animationCounter]);
|
|
122
|
+
mapInstance.getSource(`line-animation${index}`).setData(geojson);
|
|
123
|
+
requestAnimationFrame(animateLine);
|
|
124
|
+
animationCounter += 1;
|
|
125
|
+
} else {
|
|
126
|
+
const coord = geojson.features[0].geometry.coordinates;
|
|
127
|
+
coord.shift();
|
|
128
|
+
coord.shift();
|
|
129
|
+
if (coord.length > 0) {
|
|
130
|
+
geojson.features[0].geometry.coordinates = coord;
|
|
131
|
+
mapInstance.getSource(`line-animation${index}`).setData(geojson);
|
|
132
|
+
requestAnimationFrame(animateLine);
|
|
133
|
+
} else {
|
|
134
|
+
mapInstance.removeLayer(`line-animation${index}`);
|
|
135
|
+
mapInstance.removeSource(`line-animation${index}`);
|
|
136
|
+
mapInstance.removeSource(`startPoint${index}`);
|
|
137
|
+
if (lastLine) {
|
|
138
|
+
mapInstance.removeSource("endpoint");
|
|
139
|
+
resolve();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
animateLine();
|
|
145
|
+
};
|
|
146
|
+
originPoints.forEach((coordinate, index) => {
|
|
147
|
+
lineFlight(coordinate, endPoint, index, index === originPoints.length - 1);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function generateMapMarkers(mapInstance, borrowerPoints) {
|
|
152
|
+
const geojson = {
|
|
153
|
+
type: "FeatureCollection"
|
|
154
|
+
};
|
|
155
|
+
geojson.features = borrowerPoints.map((borrower) => ({
|
|
156
|
+
type: "Feature",
|
|
157
|
+
properties: {
|
|
158
|
+
message: "test",
|
|
159
|
+
image: borrower.image,
|
|
160
|
+
iconSize: [80, 80]
|
|
161
|
+
},
|
|
162
|
+
geometry: {
|
|
163
|
+
type: "Point",
|
|
164
|
+
coordinates: borrower.location
|
|
165
|
+
}
|
|
166
|
+
}));
|
|
167
|
+
geojson.features.forEach((marker) => {
|
|
168
|
+
const el = document.createElement("div");
|
|
169
|
+
el.className = "map-marker";
|
|
170
|
+
el.style.backgroundImage = `url(${marker.properties.image})`;
|
|
171
|
+
el.style.width = `${marker.properties.iconSize[0]}px`;
|
|
172
|
+
el.style.height = `${marker.properties.iconSize[1]}px`;
|
|
173
|
+
new maplibregl.Marker({ element: el }).setLngLat(marker.geometry.coordinates).addTo(mapInstance);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function animationCoordinator(mapInstance, borrowerPoints) {
|
|
177
|
+
return new Promise((resolve) => {
|
|
178
|
+
const destinationPoints = borrowerPoints.map((borrower) => borrower.location);
|
|
179
|
+
const totalNumberOfPoints = destinationPoints.length;
|
|
180
|
+
let currentPointIndex = 0;
|
|
181
|
+
const flyToPoint = (index) => {
|
|
182
|
+
mapInstance.flyTo({
|
|
183
|
+
// These options control the ending camera position: centered at
|
|
184
|
+
// the target, at zoom level 9, and north up.
|
|
185
|
+
center: destinationPoints[index],
|
|
186
|
+
zoom: 4,
|
|
187
|
+
bearing: 0,
|
|
188
|
+
// These options control the flight curve, making it move
|
|
189
|
+
// slowly and zoom out almost completely before starting
|
|
190
|
+
// to pan.
|
|
191
|
+
speed: 0.9,
|
|
192
|
+
// make the flying slow
|
|
193
|
+
curve: 1,
|
|
194
|
+
// change the speed at which it zooms out
|
|
195
|
+
// This can be any easing function: it takes a number between
|
|
196
|
+
// 0 and 1 and returns another number between 0 and 1.
|
|
197
|
+
easing(t) {
|
|
198
|
+
return t;
|
|
199
|
+
},
|
|
200
|
+
// this animation is considered essential with respect to prefers-reduced-motion
|
|
201
|
+
essential: true
|
|
202
|
+
}, { flyEnd: true });
|
|
203
|
+
};
|
|
204
|
+
mapInstance.on("moveend", (event) => {
|
|
205
|
+
if (event.flyEnd === true) {
|
|
206
|
+
animateLines(mapInstance, randomCoordinates, destinationPoints[currentPointIndex]).then(() => {
|
|
207
|
+
if (currentPointIndex < totalNumberOfPoints - 1) {
|
|
208
|
+
currentPointIndex += 1;
|
|
209
|
+
flyToPoint(currentPointIndex);
|
|
210
|
+
} else {
|
|
211
|
+
resolve();
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
flyToPoint(currentPointIndex);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
var getLoansIntervals = (min, max, nbIntervals) => {
|
|
220
|
+
const size = Math.floor((max - min) / nbIntervals);
|
|
221
|
+
const result = [];
|
|
222
|
+
if (size <= 0)
|
|
223
|
+
return [[min, max]];
|
|
224
|
+
for (let i = 0; i < nbIntervals; i += 1) {
|
|
225
|
+
let inf = min + i * size;
|
|
226
|
+
let sup = inf + size < max ? inf + size : max;
|
|
227
|
+
if (i > 0) {
|
|
228
|
+
inf += 1 * i;
|
|
229
|
+
sup += 1 * i;
|
|
230
|
+
}
|
|
231
|
+
if (i > 0 && sup > max) {
|
|
232
|
+
sup = max;
|
|
233
|
+
}
|
|
234
|
+
if (i === nbIntervals - 1) {
|
|
235
|
+
if (sup < max || sup > max)
|
|
236
|
+
sup = max;
|
|
237
|
+
}
|
|
238
|
+
result.push([inf, sup]);
|
|
239
|
+
if (sup >= max)
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
return result;
|
|
243
|
+
};
|
|
244
|
+
var getCountryColor = (lenderLoans, countriesData, kvTokensPrimitives) => {
|
|
245
|
+
const loanCountsArray = [];
|
|
246
|
+
countriesData.forEach((country) => {
|
|
247
|
+
loanCountsArray.push(country.value);
|
|
248
|
+
});
|
|
249
|
+
const maxNumLoansToOneCountry = Math.max(...loanCountsArray);
|
|
250
|
+
const intervals = getLoansIntervals(1, maxNumLoansToOneCountry, 6);
|
|
251
|
+
if (intervals.length === 1) {
|
|
252
|
+
const [inf, sup] = intervals[0];
|
|
253
|
+
for (let i = 0; i < sup; i += 1) {
|
|
254
|
+
const loansNumber = i + 1;
|
|
255
|
+
if (lenderLoans && lenderLoans >= loansNumber && lenderLoans < loansNumber + 1) {
|
|
256
|
+
return kvTokensPrimitives.colors.brand[mapColors[i]];
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
for (let i = 0; i < intervals.length; i += 1) {
|
|
261
|
+
const [inf, sup] = intervals[i];
|
|
262
|
+
if (lenderLoans && lenderLoans >= inf && lenderLoans <= sup) {
|
|
263
|
+
return kvTokensPrimitives.colors.brand[mapColors[i]];
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return kvTokensPrimitives.colors.gray[300];
|
|
268
|
+
};
|
|
269
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
270
|
+
0 && (module.exports = {
|
|
271
|
+
animationCoordinator,
|
|
272
|
+
generateMapMarkers,
|
|
273
|
+
getCoordinatesBetween,
|
|
274
|
+
getCountryColor,
|
|
275
|
+
getLoansIntervals
|
|
276
|
+
});
|