@luckydye/calendar 1.3.1 → 1.4.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/src/Color.ts CHANGED
@@ -1,64 +1,58 @@
1
-
2
1
  function componentToHex(c) {
3
- var hex = c.toString(16);
4
- return hex.length === 1 ? "0" + hex : hex;
2
+ const hex = c.toString(16);
3
+ return hex.length === 1 ? `0${hex}` : hex;
5
4
  }
6
5
 
7
6
  export function rgbToHex(r, g, b) {
8
- return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
7
+ return `#${componentToHex(r)}${componentToHex(g)}${componentToHex(b)}`;
9
8
  }
10
9
 
11
10
  export function hexToRgb(hex: string) {
12
- return [
13
- parseInt(`${hex[1]}${hex[2]}`, 16),
14
- parseInt(`${hex[3]}${hex[4]}`, 16),
15
- parseInt(`${hex[5]}${hex[6]}`, 16)
16
- ] as [number, number, number];
11
+ return [
12
+ Number.parseInt(`${hex[1]}${hex[2]}`, 16),
13
+ Number.parseInt(`${hex[3]}${hex[4]}`, 16),
14
+ Number.parseInt(`${hex[5]}${hex[6]}`, 16),
15
+ ] as [number, number, number];
17
16
  }
18
17
 
19
- export function rgbToHsl([r,g,b]) {
20
- // Make r, g, and b fractions of 1
21
- r /= 255;
22
- g /= 255;
23
- b /= 255;
24
-
25
- // Find greatest and smallest channel values
26
- let cmin = Math.min(r,g,b),
27
- cmax = Math.max(r,g,b),
28
- delta = cmax - cmin,
29
- h = 0,
30
- s = 0,
31
- l = 0;
32
-
33
- // Calculate hue
34
- // No difference
35
- if (delta === 0)
36
- h = 0;
37
- // Red is max
38
- else if (cmax === r)
39
- h = ((g - b) / delta) % 6;
40
- // Green is max
41
- else if (cmax === g)
42
- h = (b - r) / delta + 2;
43
- // Blue is max
44
- else
45
- h = (r - g) / delta + 4;
46
-
47
- h = Math.round(h * 60);
48
-
49
- // Make negative hues positive behind 360°
50
- if (h < 0)
51
- h += 360;
52
-
53
- // Calculate lightness
54
- l = (cmax + cmin) / 2;
55
-
56
- // Calculate saturation
57
- s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
58
-
59
- // Multiply l and s by 100
60
- s = +(s * 100).toFixed(1);
61
- l = +(l * 100).toFixed(1);
62
-
63
- return [h, s, l];
18
+ export function rgbToHsl([r, g, b]) {
19
+ // Make r, g, and b fractions of 1
20
+ r /= 255;
21
+ g /= 255;
22
+ b /= 255;
23
+
24
+ // Find greatest and smallest channel values
25
+ const cmin = Math.min(r, g, b);
26
+ const cmax = Math.max(r, g, b);
27
+ const delta = cmax - cmin;
28
+ let h = 0;
29
+ let s = 0;
30
+ let l = 0;
31
+
32
+ // Calculate hue
33
+ // No difference
34
+ if (delta === 0) h = 0;
35
+ // Red is max
36
+ else if (cmax === r) h = ((g - b) / delta) % 6;
37
+ // Green is max
38
+ else if (cmax === g) h = (b - r) / delta + 2;
39
+ // Blue is max
40
+ else h = (r - g) / delta + 4;
41
+
42
+ h = Math.round(h * 60);
43
+
44
+ // Make negative hues positive behind 360°
45
+ if (h < 0) h += 360;
46
+
47
+ // Calculate lightness
48
+ l = (cmax + cmin) / 2;
49
+
50
+ // Calculate saturation
51
+ s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
52
+
53
+ // Multiply l and s by 100
54
+ s = +(s * 100).toFixed(1);
55
+ l = +(l * 100).toFixed(1);
56
+
57
+ return [h, s, l];
64
58
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Removes transport/tracking links commonly injected by email/calendar clients.
3
+ * First pass intentionally targets angle-bracket URI blobs like
4
+ * <https://...>, <mailto:...>, <tel:...>, <im:...>.
5
+ */
6
+ export function sanitizeEventDescription(input: string): string {
7
+ if (!input) return input;
8
+
9
+ return input.replace(/<(?:https?|mailto|tel|im):[^>\s]+>/gi, "");
10
+ }