@carto/ps-utils 1.6.1 → 1.7.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/dist/index.cjs +1 -1
- package/dist/index.js +29 -27
- package/dist/types/colors/{hex-to-rgba-deckgl/hex-to-rgba-deckgl.d.ts → hex-to-rgba/hex-to-rgba.d.ts} +5 -5
- package/dist/types/colors/index.d.ts +5 -3
- package/dist/types/colors/{rgba-deck-gl-to-hex/rgba-deck-gl-to-hex.d.ts → rgba-to-hex/rgba-to-hex.d.ts} +1 -1
- package/package.json +1 -1
- /package/dist/types/colors/{rgba-deck-gl-to-hex → rgba-to-hex}/types.d.ts +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("@turf/meta");function d(t,e=1){if(!t){console.warn(`hexToRgba: ${t} invalid hexadecimal format`);return}if(e<0||e>1){console.warn(`hexToRgba: ${e} invalid alpha format`);return}if(t?.includes("#")&&(t=t.slice(1)),!/[0-9A-Fa-f]{6}/g.test(t)&&!/[0-9A-Fa-f]{3}/g.test(t)&&!/[0-9A-Fa-f]{2}/g.test(t)){console.warn(`hexToRgba: ${t} invalid hexadecimal format`);return}const n=t.length;n<6&&(t=t.slice(0,6-n).repeat(6/n));const o=parseInt(t.length===3?t.slice(0,1).repeat(2):t.slice(0,2),16),r=parseInt(t.length===3?t.slice(1,2).repeat(2):t.slice(2,4),16),i=parseInt(t.length===3?t.slice(2,3).repeat(2):t.slice(4,6),16);return[o,r,i,e*255]}function b(t,{withPrefix:e=!0}={}){if(!t||!t.length){console.warn("rgbaDeckGLToHex: invalid array or empty values");return}if(t.some(r=>r<0||r>255)){console.warn(`rgbaDeckGLToHex: [${t.toString()}] invalid array value format`);return}const o=t.map(r=>r.toString(16).padStart(2,"0")).join("");return`${e?"#":""}${o}`}function D(t,e){return(...r)=>{clearTimeout(0),setTimeout(()=>t(...r),e)}}const m=63710088e-1;function h(t){return T.geomReduce(t,function(e,n){return e+w(n)},0)}function w(t){let e=0,n;switch(t.type){case"Polygon":return p(t.coordinates);case"MultiPolygon":for(n=0;n<t.coordinates.length;n++)e+=p(t.coordinates[n]);return e;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function p(t){let e=0;if(t&&t.length>0){e+=Math.abs(y(t[0]));for(let n=1;n<t.length;n++)e-=Math.abs(y(t[n]))}return e}function y(t){let e,n,o,r,i,c,a,s=0;const u=t.length;if(u>2){for(a=0;a<u;a++)a===u-2?(r=u-2,i=u-1,c=0):a===u-1?(r=u-1,i=0,c=1):(r=a,i=a+1,c=a+2),e=t[r],n=t[i],o=t[c],s+=(f(o[0])-f(e[0]))*Math.sin(f(n[1]));s=s*m*m/2}return s}function f(t){return t*Math.PI/180}function C(t){try{if(navigator.clipboard)navigator.clipboard.writeText(t);else{const e=document.createElement("input");e.innerHTML=t,A(e)}}catch(e){throw new Error(e)}}function A(t){const e=t.contentEditable,n=t.readOnly;try{t.contentEditable="true",t.readOnly=!1,E(t)}finally{t.contentEditable=e,t.readOnly=n}}function E(t){const e=document.createRange(),n=window.getSelection();e.selectNodeContents(t),n?.removeAllRanges(),n?.addRange(e),t.setSelectionRange(0,999999),document.execCommand("copy")}const g={NUMBER:{style:"decimal",maximumFractionDigits:1,minimumFractionDigits:0,notation:"compact",compactDisplay:"short"},CURRENCY:{style:"currency",currency:"USD",maximumFractionDigits:2,minimumFractionDigits:2,notation:"compact",compactDisplay:"short"},DATE:{year:"numeric",month:"2-digit",day:"2-digit"}};function I(t,e,n){return Intl.DateTimeFormat(e,n).format(t)}function R(t,e,n){return Intl.NumberFormat(e,n).format(t)}function N(t,e,n={}){return R(t,e,{...g.NUMBER,...n})}function S(t,e,n={}){return R(t,e,{...g.CURRENCY,...n})}const v=/:+[a-z]+/gi;function F(t,e=[]){let n=t;const o=n.match(v)||[],r=Array.isArray(e);return o.forEach((i,c)=>{let a;if(r)a=e[c];else{const s=i.substring(1);a=e[s]}n=n.replace(i,a?.toString())}),n}function l(t,{format:e="NFD",replaceUnicode:n="[̀-ͯ]"}={}){const o=new RegExp(n,"g");return t.normalize(e).replace(o,"")}function M(t,e,{matchFn:n,normalizeOptions:o}={}){const r=new RegExp(l(t.toLowerCase(),o),"gi");return Array.isArray(e)?e.filter(i=>{const c=n?n(i):i;return l(c).match(r)}):l(e).match(r)?e:null}exports.CONFIG=g;exports.area=h;exports.copy=C;exports.debounce=D;exports.formatCurrency=S;exports.formatDate=I;exports.formatNumber=N;exports.hexToRgba=d;exports.hexToRgbaDeckGL=d;exports.matchText=M;exports.normalize=l;exports.replaceRoute=F;exports.rgbaDeckGLToHex=b;exports.rgbaToHex=b;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { geomReduce as b } from "@turf/meta";
|
|
2
|
-
function
|
|
2
|
+
function A(t, n = 1) {
|
|
3
3
|
if (!t) {
|
|
4
|
-
console.warn(`
|
|
4
|
+
console.warn(`hexToRgba: ${t} invalid hexadecimal format`);
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
7
7
|
if (n < 0 || n > 1) {
|
|
8
|
-
console.warn(`
|
|
8
|
+
console.warn(`hexToRgba: ${n} invalid alpha format`);
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
if (t?.includes("#") && (t = t.slice(1)), !/[0-9A-Fa-f]{6}/g.test(t) && !/[0-9A-Fa-f]{3}/g.test(t) && !/[0-9A-Fa-f]{2}/g.test(t)) {
|
|
12
|
-
console.warn(`
|
|
12
|
+
console.warn(`hexToRgba: ${t} invalid hexadecimal format`);
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
const e = t.length;
|
|
@@ -26,7 +26,7 @@ function E(t, n = 1) {
|
|
|
26
26
|
);
|
|
27
27
|
return [o, r, i, n * 255];
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function E(t, { withPrefix: n = !0 } = {}) {
|
|
30
30
|
if (!t || !t.length) {
|
|
31
31
|
console.warn("rgbaDeckGLToHex: invalid array or empty values");
|
|
32
32
|
return;
|
|
@@ -50,12 +50,12 @@ function I(t) {
|
|
|
50
50
|
return b(
|
|
51
51
|
t,
|
|
52
52
|
function(n, e) {
|
|
53
|
-
return n +
|
|
53
|
+
return n + R(e);
|
|
54
54
|
},
|
|
55
55
|
0
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function R(t) {
|
|
59
59
|
let n = 0, e;
|
|
60
60
|
switch (t.type) {
|
|
61
61
|
case "Polygon":
|
|
@@ -94,27 +94,27 @@ function m(t) {
|
|
|
94
94
|
function l(t) {
|
|
95
95
|
return t * Math.PI / 180;
|
|
96
96
|
}
|
|
97
|
-
function
|
|
97
|
+
function v(t) {
|
|
98
98
|
try {
|
|
99
99
|
if (navigator.clipboard)
|
|
100
100
|
navigator.clipboard.writeText(t);
|
|
101
101
|
else {
|
|
102
102
|
const n = document.createElement("input");
|
|
103
|
-
n.innerHTML = t,
|
|
103
|
+
n.innerHTML = t, T(n);
|
|
104
104
|
}
|
|
105
105
|
} catch (n) {
|
|
106
106
|
throw new Error(n);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function T(t) {
|
|
110
110
|
const n = t.contentEditable, e = t.readOnly;
|
|
111
111
|
try {
|
|
112
|
-
t.contentEditable = "true", t.readOnly = !1,
|
|
112
|
+
t.contentEditable = "true", t.readOnly = !1, D(t);
|
|
113
113
|
} finally {
|
|
114
114
|
t.contentEditable = n, t.readOnly = e;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function D(t) {
|
|
118
118
|
const n = document.createRange(), e = window.getSelection();
|
|
119
119
|
n.selectNodeContents(t), e?.removeAllRanges(), e?.addRange(n), t.setSelectionRange(0, 999999), document.execCommand("copy");
|
|
120
120
|
}
|
|
@@ -140,22 +140,22 @@ const y = {
|
|
|
140
140
|
day: "2-digit"
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
-
function
|
|
143
|
+
function F(t, n, e) {
|
|
144
144
|
return Intl.DateTimeFormat(n, e).format(t);
|
|
145
145
|
}
|
|
146
146
|
function d(t, n, e) {
|
|
147
147
|
return Intl.NumberFormat(n, e).format(t);
|
|
148
148
|
}
|
|
149
|
-
function
|
|
149
|
+
function M(t, n, e = {}) {
|
|
150
150
|
return d(t, n, { ...y.NUMBER, ...e });
|
|
151
151
|
}
|
|
152
|
-
function
|
|
152
|
+
function N(t, n, e = {}) {
|
|
153
153
|
return d(t, n, { ...y.CURRENCY, ...e });
|
|
154
154
|
}
|
|
155
|
-
const
|
|
156
|
-
function
|
|
155
|
+
const w = /:+[a-z]+/gi;
|
|
156
|
+
function S(t, n = []) {
|
|
157
157
|
let e = t;
|
|
158
|
-
const o = e.match(
|
|
158
|
+
const o = e.match(w) || [], r = Array.isArray(n);
|
|
159
159
|
return o.forEach((i, a) => {
|
|
160
160
|
let c;
|
|
161
161
|
if (r)
|
|
@@ -171,7 +171,7 @@ function f(t, { format: n = "NFD", replaceUnicode: e = "[̀-ͯ]" } = {}) {
|
|
|
171
171
|
const o = new RegExp(e, "g");
|
|
172
172
|
return t.normalize(n).replace(o, "");
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function L(t, n, { matchFn: e, normalizeOptions: o } = {}) {
|
|
175
175
|
const r = new RegExp(
|
|
176
176
|
f(t.toLowerCase(), o),
|
|
177
177
|
"gi"
|
|
@@ -184,14 +184,16 @@ function S(t, n, { matchFn: e, normalizeOptions: o } = {}) {
|
|
|
184
184
|
export {
|
|
185
185
|
y as CONFIG,
|
|
186
186
|
I as area,
|
|
187
|
-
|
|
187
|
+
v as copy,
|
|
188
188
|
C as debounce,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
N as formatCurrency,
|
|
190
|
+
F as formatDate,
|
|
191
|
+
M as formatNumber,
|
|
192
|
+
A as hexToRgba,
|
|
193
|
+
A as hexToRgbaDeckGL,
|
|
194
|
+
L as matchText,
|
|
194
195
|
f as normalize,
|
|
195
|
-
|
|
196
|
-
|
|
196
|
+
S as replaceRoute,
|
|
197
|
+
E as rgbaDeckGLToHex,
|
|
198
|
+
E as rgbaToHex
|
|
197
199
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* It converts a hexadecimal color to an array of numbers
|
|
2
|
+
* It converts a hexadecimal color to an array of numbers
|
|
3
3
|
*
|
|
4
4
|
* @param {string} hexadecimal - hexadecimal string, including # or not
|
|
5
5
|
* @param {number} alpha - opacity of final color, value must be between 0-1
|
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
*
|
|
11
11
|
* 6 digits hexadecimal:
|
|
12
12
|
* ```ts
|
|
13
|
-
*
|
|
13
|
+
* hexToRgba('#d1d1d1', 1)
|
|
14
14
|
* ```
|
|
15
15
|
* 3 digits hexadecimal:
|
|
16
16
|
* ```ts
|
|
17
|
-
*
|
|
17
|
+
* hexToRgba('#d1d', 1)
|
|
18
18
|
* ```
|
|
19
19
|
* 2 digits hexadecimal:
|
|
20
20
|
* ```ts
|
|
21
|
-
*
|
|
21
|
+
* hexToRgba('#d1', 1)
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export declare function
|
|
24
|
+
export declare function hexToRgba(hexadecimal: string, alpha?: number): [number, number, number, number] | undefined;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
1
|
+
export { hexToRgba } from './hex-to-rgba/hex-to-rgba';
|
|
2
|
+
export { hexToRgba as hexToRgbaDeckGL } from './hex-to-rgba/hex-to-rgba';
|
|
3
|
+
export { rgbaToHex } from './rgba-to-hex/rgba-to-hex';
|
|
4
|
+
export { rgbaToHex as rgbaDeckGLToHex } from './rgba-to-hex/rgba-to-hex';
|
|
5
|
+
export * from './rgba-to-hex/types';
|
|
@@ -25,4 +25,4 @@ import { RgbaDeckGLToHexOptions } from './types';
|
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
27
|
*/
|
|
28
|
-
export declare function
|
|
28
|
+
export declare function rgbaToHex(rgba: number[], { withPrefix }?: RgbaDeckGLToHexOptions): string | undefined;
|
package/package.json
CHANGED
|
File without changes
|