@processmaker/modeler 1.39.5 → 1.39.7

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.
@@ -0,0 +1,137 @@
1
+ <template>
2
+ <span
3
+ class="b-avatar rounded-circle"
4
+ :style="{'backgroundColor': generateColorHsl(userName, saturationRange, lightnessRange)}"
5
+ >
6
+ <span v-if="imgSrc" class="b-avatar-img">
7
+ <img :src="imgSrc" :alt=userName>
8
+ </span>
9
+ <span v-else class="b-avatar-text avatar-initials">
10
+ <span>
11
+ {{ this.getInitials(userName) }}
12
+ </span>
13
+
14
+ </span>
15
+ <span class="b-avatar-badge badge-danger"
16
+ :style="{bottom: '0px', right: '0px', backgroundColor: badgeBackgroundColor}"
17
+ />
18
+ </span>
19
+ </template>
20
+
21
+ <script>
22
+
23
+ export default {
24
+ props: {
25
+ badgeBackgroundColor: {
26
+ type: String,
27
+ required: false,
28
+ },
29
+ imgSrc: {
30
+ type: String,
31
+ required: false,
32
+ },
33
+ userName: {
34
+ type: String,
35
+ required: false,
36
+ },
37
+ },
38
+ data() {
39
+ return {
40
+ saturation: 50,
41
+ lightness: 50,
42
+ range: 10,
43
+ };
44
+ },
45
+ computed: {
46
+ saturationRange() {
47
+ return this.getRange(this.saturation, this.range);
48
+ },
49
+ lightnessRange() {
50
+ return this.getRange(this.lightness, this.range);
51
+ },
52
+ },
53
+ methods: {
54
+ /**
55
+ * Get the initials from a given name.
56
+ *
57
+ * @param {string} name - The full name from which to extract initials.
58
+ * @returns {string} The initials of the first and last names.
59
+ */
60
+ getInitials(name = '') {
61
+ const nameArray = name.split(' ');
62
+ const firstNameIn = nameArray[0].charAt(0).toUpperCase();
63
+ const lastNameIn = nameArray[nameArray.length - 1].charAt(0).toUpperCase();
64
+ return `${firstNameIn}${lastNameIn}`;
65
+ },
66
+ /**
67
+ * Calculates a hash value for a given string.
68
+ *
69
+ * @param {string} str - The input string for which the hash needs to be calculated.
70
+ * @returns {number} The calculated hash value for the input string.
71
+ */
72
+ getHashOfString(str){
73
+ let hash = 0;
74
+ for (let i = 0; i < str.length; i++) {
75
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
76
+ }
77
+ hash = Math.abs(hash);
78
+ return hash;
79
+ },
80
+ /**
81
+ * Calculates a range around a given value.
82
+ *
83
+ * @param {number} value - The central value.
84
+ * @param {number} range - The range value.
85
+ * @returns {number[]} An array containing the lower and upper bounds of the range.
86
+ */
87
+ getRange(value, range) {
88
+ return [Math.max(0, value-range), Math.min(value + range, 100)];
89
+ },
90
+ /**
91
+ * Get the hash number to within our range
92
+ *
93
+ * @param {Number} hash
94
+ * @param {Number} min
95
+ * @param {Number} max
96
+ * @returns {Number}
97
+ */
98
+ normalizeHash(hash, min, max){
99
+ return Math.floor((hash % (max - min)) + min);
100
+ },
101
+ /**
102
+ *Generate Unique Color, create a string using our h,s,l values.
103
+ * @param {String} name
104
+ * @param {Array} saturationRange
105
+ * @param {Array} lightnessRange
106
+ * @returns {Number}
107
+ */
108
+ generateHSL(name, saturationRange, lightnessRange) {
109
+ const hash = this.getHashOfString(name);
110
+ const h = this.normalizeHash(hash, 0, 360);
111
+ const s = this.normalizeHash(hash, saturationRange[0], saturationRange[1]);
112
+ const l = this.normalizeHash(hash, lightnessRange[0], lightnessRange[1]);
113
+ return [h, s, l];
114
+ },
115
+ /**
116
+ * Convert HSL array to string
117
+ * @param {Array} hsl
118
+ * @returns {String}
119
+ */
120
+ HSLtoString(hsl) {
121
+ return `hsl(${hsl[0]}, ${hsl[1]}%, ${hsl[2]}%)`;
122
+ },
123
+ /**
124
+ * Generate a unique hsl value.
125
+ * @param {String} name
126
+ * @param {Array} saturationRange
127
+ * @param {Array} lightnessRange
128
+ * @returns {String}
129
+ */
130
+ generateColorHsl(id, saturationRange, lightnessRange) {
131
+ return this.HSLtoString(this.generateHSL(id, saturationRange, lightnessRange));
132
+ },
133
+ },
134
+ };
135
+
136
+ </script>
137
+ <style scoped lang="scss" src="./avatar.scss"></style>
@@ -0,0 +1,6 @@
1
+ .avatar-initials {
2
+ text-align: center;
3
+ line-height: 2.4rem;
4
+ color: #ffffff;
5
+ font-weight: bold;
6
+ }