sf-i-events 1.0.591 → 1.0.593

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/util.js CHANGED
@@ -1,321 +1,321 @@
1
- const validateName = (name) => {
2
- if ((name + "").length > 2) {
3
- return true;
4
- }
5
- return false;
6
- };
7
- function createDiagonalPattern1(color) {
8
- // create a 10x10 px canvas for the pattern's base shape
9
- let shape = document.createElement('canvas');
10
- shape.width = 10;
11
- shape.height = 10;
12
- // get the context for drawing
13
- let c = shape.getContext('2d');
14
- // draw 1st line of the shape
15
- c.strokeStyle = color;
16
- c.lineWidth = 3;
17
- c.beginPath();
18
- c.moveTo(2, 0);
19
- c.lineTo(10, 8);
20
- c.stroke();
21
- // draw 2nd line of the shape
22
- c.beginPath();
23
- c.moveTo(2, 10);
24
- c.lineTo(0, 8);
25
- c.stroke();
26
- // create the pattern from the shape
27
- return c.createPattern(shape, 'repeat');
28
- }
29
- // function createDiagonalPattern2(color: string) {
30
- // let shape = document.createElement('canvas')
31
- // shape.width = 10
32
- // shape.height = 10
33
- // // get the context for drawing
34
- // let c = shape.getContext('2d')
35
- // // draw 1st line of the shape
36
- // c!.beginPath();
37
- // c!.rect(2, 2, 8, 8)
38
- // c!.fillStyle = color;
39
- // c!.fill();
40
- // // create the pattern from the shape
41
- // return c!.createPattern(shape, 'repeat')
42
- // }
43
- function createDiagonalPattern2(color) {
44
- // create a 10x10 px canvas for the pattern's base shape
45
- let shape = document.createElement('canvas');
46
- shape.width = 10;
47
- shape.height = 10;
48
- // get the context for drawing
49
- let c = shape.getContext('2d');
50
- // draw 1st line of the shape
51
- c.beginPath();
52
- c.rect(1, 1, 9, 9);
53
- c.fillStyle = color;
54
- c.fill();
55
- c.lineWidth = 1;
56
- c.strokeStyle = color;
57
- c.stroke();
58
- // create the pattern from the shape
59
- // create tick
60
- //draw tick
61
- c.beginPath();
62
- c.moveTo(2, 2);
63
- c.lineTo(8, 8);
64
- c.moveTo(2, 8);
65
- c.lineTo(8, 2);
66
- c.lineWidth = 2;
67
- c.strokeStyle = '#fff';
68
- c.stroke();
69
- return c.createPattern(shape, 'repeat');
70
- }
71
- function createDiagonalPattern3(color) {
72
- // create a 10x10 px canvas for the pattern's base shape
73
- let shape = document.createElement('canvas');
74
- shape.width = 10;
75
- shape.height = 10;
76
- // get the context for drawing
77
- let c = shape.getContext('2d');
78
- // draw 1st line of the shape
79
- c.beginPath();
80
- c.rect(1, 1, 9, 9);
81
- c.fillStyle = color;
82
- c.fill();
83
- c.lineWidth = 1;
84
- c.strokeStyle = color;
85
- c.stroke();
86
- // create the pattern from the shape
87
- // create tick
88
- //draw tick
89
- c.beginPath();
90
- c.moveTo(2, 5);
91
- c.lineTo(4, 7);
92
- c.lineTo(8, 2);
93
- c.lineWidth = 2;
94
- c.strokeStyle = '#fff';
95
- c.stroke();
96
- return c.createPattern(shape, 'repeat');
97
- }
98
- // function createDiagonalPattern3(color: string) {
99
- // // create a 10x10 px canvas for the pattern's base shape
100
- // let shape = document.createElement('canvas')
101
- // shape.width = 14
102
- // shape.height = 14
103
- // // get the context for drawing
104
- // let c = shape.getContext('2d')
105
- // // draw 1st line of the shape
106
- // c!.beginPath();
107
- // c!.arc(7, 7, 6, 0, 2 * Math.PI, false);
108
- // c!.fillStyle = color;
109
- // c!.fill();
110
- // c!.lineWidth = 1;
111
- // c!.strokeStyle = color;
112
- // c!.stroke();
113
- // // create the pattern from the shape
114
- // // create tick
115
- // //draw tick
116
- // c!.beginPath();
117
- // c!.moveTo(4,6);
118
- // c!.lineTo(6,9);
119
- // c!.lineTo(10,4);
120
- // c!.lineWidth = 2;
121
- // c!.strokeStyle = '#fff';
122
- // c!.stroke();
123
- // return c!.createPattern(shape, 'repeat')
124
- // }
125
- // function createDiagonalPattern3(color: string) {
126
- // // create a 10x10 px canvas for the pattern's base shape
127
- // let shape = document.createElement('canvas')
128
- // shape.width = 10
129
- // shape.height = 10
130
- // // get the context for drawing
131
- // let c = shape.getContext('2d')
132
- // // draw 1st line of the shape
133
- // c!.beginPath();
134
- // c!.arc(5, 5, 4, 0, 2 * Math.PI, false);
135
- // c!.fillStyle = color;
136
- // c!.fill();
137
- // c!.lineWidth = 1;
138
- // c!.strokeStyle = color;
139
- // c!.stroke();
140
- // // create the pattern from the shape
141
- // return c!.createPattern(shape, 'repeat')
142
- // }
143
- const timeSince = (date) => {
144
- var seconds = Math.floor((new Date().getTime() - date) / 1000);
145
- if (seconds > 0) {
146
- var interval = seconds / 31536000;
147
- if (interval > 1) {
148
- return Math.floor(interval) + " years ago";
149
- }
150
- interval = seconds / 2592000;
151
- if (interval > 1) {
152
- return Math.floor(interval) + " months ago";
153
- }
154
- interval = seconds / 86400;
155
- if (interval > 1) {
156
- return Math.floor(interval) + " days ago";
157
- }
158
- interval = seconds / 3600;
159
- if (interval > 1) {
160
- return Math.floor(interval) + " hours ago";
161
- }
162
- interval = seconds / 60;
163
- if (interval > 1) {
164
- return Math.floor(interval) + " minutes ago";
165
- }
166
- return Math.floor(seconds) + " seconds ago";
167
- }
168
- else {
169
- var interval = Math.abs(seconds) / 31536000;
170
- console.log('timesince', seconds);
171
- console.log('interval year', interval);
172
- if (interval > 1) {
173
- return Math.floor(interval) + " years later";
174
- }
175
- interval = Math.abs(seconds) / 2592000;
176
- console.log('interval months', interval);
177
- if (interval > 1) {
178
- return Math.floor(interval) + " months later";
179
- }
180
- interval = Math.abs(seconds) / 86400;
181
- console.log('interval days', interval);
182
- if (interval > 1) {
183
- return Math.floor(interval) + " days later";
184
- }
185
- interval = Math.abs(seconds) / 3600;
186
- console.log('interval hours', interval);
187
- if (interval > 1) {
188
- return Math.floor(interval) + " hours later";
189
- }
190
- interval = Math.abs(seconds) / 60;
191
- if (interval > 1) {
192
- return Math.floor(interval) + " minutes later";
193
- }
194
- return Math.floor(Math.abs(seconds)) + " seconds later";
195
- }
196
- };
197
- function readCookie(key) {
198
- let name = key + "=";
199
- let decodedCookie = decodeURIComponent(document.cookie);
200
- let ca = decodedCookie.split(';');
201
- for (let i = 0; i < ca.length; i++) {
202
- let c = ca[i];
203
- while (c.charAt(0) == ' ') {
204
- c = c.substring(1);
205
- }
206
- if (c.indexOf(name) == 0) {
207
- return c.substring(name.length, c.length);
208
- }
209
- }
210
- return "";
211
- }
212
- async function callApi(url, data, authorization) {
213
- return new Promise((resolve) => {
214
- const jsonData = JSON.stringify(data);
215
- var xhr = new XMLHttpRequest();
216
- xhr.addEventListener("readystatechange", () => {
217
- if (xhr != null) {
218
- if (xhr.readyState === 4) {
219
- resolve(xhr);
220
- }
221
- }
222
- });
223
- xhr.open("POST", url);
224
- xhr.timeout = 1800000;
225
- xhr.setRequestHeader("Content-Type", "application/json");
226
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
227
- if (authorization != null) {
228
- xhr.setRequestHeader('Authorization', 'Basic ' + authorization);
229
- }
230
- xhr.send(jsonData);
231
- return xhr;
232
- });
233
- }
234
- async function callApiPresignedDelete(url) {
235
- return new Promise((resolve) => {
236
- var xhr = new XMLHttpRequest();
237
- xhr.addEventListener("readystatechange", () => {
238
- if (xhr != null) {
239
- if (xhr.readyState === 4) {
240
- resolve(xhr);
241
- }
242
- }
243
- });
244
- xhr.open("DELETE", url);
245
- xhr.timeout = 1800000;
246
- xhr.setRequestHeader("Content-Type", "application/json");
247
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
248
- xhr.send(null);
249
- return xhr;
250
- });
251
- }
252
- async function callApiPresignedGet(url) {
253
- return new Promise((resolve) => {
254
- var xhr = new XMLHttpRequest();
255
- xhr.addEventListener("readystatechange", () => {
256
- if (xhr != null) {
257
- if (xhr.readyState === 4) {
258
- resolve(xhr);
259
- }
260
- }
261
- });
262
- xhr.open("GET", url);
263
- xhr.timeout = 1800000;
264
- xhr.setRequestHeader("Content-Type", "application/json");
265
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
266
- xhr.send(null);
267
- return xhr;
268
- });
269
- }
270
- async function callApiPresigned(url, data) {
271
- return new Promise((resolve) => {
272
- const jsonData = JSON.stringify(data);
273
- var xhr = new XMLHttpRequest();
274
- xhr.addEventListener("readystatechange", () => {
275
- if (xhr != null) {
276
- if (xhr.readyState === 4) {
277
- resolve(xhr);
278
- }
279
- }
280
- });
281
- xhr.open("PUT", url);
282
- xhr.timeout = 1800000;
283
- xhr.setRequestHeader("Content-Type", "application/json");
284
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
285
- xhr.send(jsonData);
286
- return xhr;
287
- });
288
- }
289
- function getRandomColor() {
290
- var letters = '0123456789ABCDEF';
291
- var color = '#';
292
- for (var i = 0; i < 6; i++) {
293
- color += letters[Math.floor(Math.random() * 16)];
294
- }
295
- return color;
296
- }
297
- function isInteger(value) {
298
- return /^-?\d+$/.test(value);
299
- }
300
- function clearListeners(old_element) {
301
- var _a;
302
- var new_element = old_element.cloneNode(true);
303
- (_a = old_element.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(new_element, old_element);
304
- return new_element;
305
- }
306
- function jsonObjectToHtml(json) {
307
- var html = '';
308
- for (var i = 0; i < Object.keys(json).length; i++) {
309
- var key = Object.keys(json)[i];
310
- html += '<div>';
311
- html += ('<span style="margin-left: 0px; padding-left: 0px">' + key + ':</span>&nbsp;');
312
- html += ('<span class="td-body" part="td-head"><sf-i-elastic-text text="' + json[key].replace(/"/g, '') + '" lineSize="6" minLength="10"></sf-i-elastic-text></span>');
313
- html += '</div>';
314
- }
315
- return html;
316
- }
317
- const exportFunctions = {
318
- callApiPresignedDelete, callApiPresignedGet, callApiPresigned, jsonObjectToHtml, clearListeners, isInteger, callApi, validateName, readCookie, timeSince, createDiagonalPattern1, createDiagonalPattern2, createDiagonalPattern3, getRandomColor
319
- };
320
- export default exportFunctions;
1
+ const validateName = (name) => {
2
+ if ((name + "").length > 2) {
3
+ return true;
4
+ }
5
+ return false;
6
+ };
7
+ function createDiagonalPattern1(color) {
8
+ // create a 10x10 px canvas for the pattern's base shape
9
+ let shape = document.createElement('canvas');
10
+ shape.width = 10;
11
+ shape.height = 10;
12
+ // get the context for drawing
13
+ let c = shape.getContext('2d');
14
+ // draw 1st line of the shape
15
+ c.strokeStyle = color;
16
+ c.lineWidth = 3;
17
+ c.beginPath();
18
+ c.moveTo(2, 0);
19
+ c.lineTo(10, 8);
20
+ c.stroke();
21
+ // draw 2nd line of the shape
22
+ c.beginPath();
23
+ c.moveTo(2, 10);
24
+ c.lineTo(0, 8);
25
+ c.stroke();
26
+ // create the pattern from the shape
27
+ return c.createPattern(shape, 'repeat');
28
+ }
29
+ // function createDiagonalPattern2(color: string) {
30
+ // let shape = document.createElement('canvas')
31
+ // shape.width = 10
32
+ // shape.height = 10
33
+ // // get the context for drawing
34
+ // let c = shape.getContext('2d')
35
+ // // draw 1st line of the shape
36
+ // c!.beginPath();
37
+ // c!.rect(2, 2, 8, 8)
38
+ // c!.fillStyle = color;
39
+ // c!.fill();
40
+ // // create the pattern from the shape
41
+ // return c!.createPattern(shape, 'repeat')
42
+ // }
43
+ function createDiagonalPattern2(color) {
44
+ // create a 10x10 px canvas for the pattern's base shape
45
+ let shape = document.createElement('canvas');
46
+ shape.width = 10;
47
+ shape.height = 10;
48
+ // get the context for drawing
49
+ let c = shape.getContext('2d');
50
+ // draw 1st line of the shape
51
+ c.beginPath();
52
+ c.rect(1, 1, 9, 9);
53
+ c.fillStyle = color;
54
+ c.fill();
55
+ c.lineWidth = 1;
56
+ c.strokeStyle = color;
57
+ c.stroke();
58
+ // create the pattern from the shape
59
+ // create tick
60
+ //draw tick
61
+ c.beginPath();
62
+ c.moveTo(2, 2);
63
+ c.lineTo(8, 8);
64
+ c.moveTo(2, 8);
65
+ c.lineTo(8, 2);
66
+ c.lineWidth = 2;
67
+ c.strokeStyle = '#fff';
68
+ c.stroke();
69
+ return c.createPattern(shape, 'repeat');
70
+ }
71
+ function createDiagonalPattern3(color) {
72
+ // create a 10x10 px canvas for the pattern's base shape
73
+ let shape = document.createElement('canvas');
74
+ shape.width = 10;
75
+ shape.height = 10;
76
+ // get the context for drawing
77
+ let c = shape.getContext('2d');
78
+ // draw 1st line of the shape
79
+ c.beginPath();
80
+ c.rect(1, 1, 9, 9);
81
+ c.fillStyle = color;
82
+ c.fill();
83
+ c.lineWidth = 1;
84
+ c.strokeStyle = color;
85
+ c.stroke();
86
+ // create the pattern from the shape
87
+ // create tick
88
+ //draw tick
89
+ c.beginPath();
90
+ c.moveTo(2, 5);
91
+ c.lineTo(4, 7);
92
+ c.lineTo(8, 2);
93
+ c.lineWidth = 2;
94
+ c.strokeStyle = '#fff';
95
+ c.stroke();
96
+ return c.createPattern(shape, 'repeat');
97
+ }
98
+ // function createDiagonalPattern3(color: string) {
99
+ // // create a 10x10 px canvas for the pattern's base shape
100
+ // let shape = document.createElement('canvas')
101
+ // shape.width = 14
102
+ // shape.height = 14
103
+ // // get the context for drawing
104
+ // let c = shape.getContext('2d')
105
+ // // draw 1st line of the shape
106
+ // c!.beginPath();
107
+ // c!.arc(7, 7, 6, 0, 2 * Math.PI, false);
108
+ // c!.fillStyle = color;
109
+ // c!.fill();
110
+ // c!.lineWidth = 1;
111
+ // c!.strokeStyle = color;
112
+ // c!.stroke();
113
+ // // create the pattern from the shape
114
+ // // create tick
115
+ // //draw tick
116
+ // c!.beginPath();
117
+ // c!.moveTo(4,6);
118
+ // c!.lineTo(6,9);
119
+ // c!.lineTo(10,4);
120
+ // c!.lineWidth = 2;
121
+ // c!.strokeStyle = '#fff';
122
+ // c!.stroke();
123
+ // return c!.createPattern(shape, 'repeat')
124
+ // }
125
+ // function createDiagonalPattern3(color: string) {
126
+ // // create a 10x10 px canvas for the pattern's base shape
127
+ // let shape = document.createElement('canvas')
128
+ // shape.width = 10
129
+ // shape.height = 10
130
+ // // get the context for drawing
131
+ // let c = shape.getContext('2d')
132
+ // // draw 1st line of the shape
133
+ // c!.beginPath();
134
+ // c!.arc(5, 5, 4, 0, 2 * Math.PI, false);
135
+ // c!.fillStyle = color;
136
+ // c!.fill();
137
+ // c!.lineWidth = 1;
138
+ // c!.strokeStyle = color;
139
+ // c!.stroke();
140
+ // // create the pattern from the shape
141
+ // return c!.createPattern(shape, 'repeat')
142
+ // }
143
+ const timeSince = (date) => {
144
+ var seconds = Math.floor((new Date().getTime() - date) / 1000);
145
+ if (seconds > 0) {
146
+ var interval = seconds / 31536000;
147
+ if (interval > 1) {
148
+ return Math.floor(interval) + " years ago";
149
+ }
150
+ interval = seconds / 2592000;
151
+ if (interval > 1) {
152
+ return Math.floor(interval) + " months ago";
153
+ }
154
+ interval = seconds / 86400;
155
+ if (interval > 1) {
156
+ return Math.floor(interval) + " days ago";
157
+ }
158
+ interval = seconds / 3600;
159
+ if (interval > 1) {
160
+ return Math.floor(interval) + " hours ago";
161
+ }
162
+ interval = seconds / 60;
163
+ if (interval > 1) {
164
+ return Math.floor(interval) + " minutes ago";
165
+ }
166
+ return Math.floor(seconds) + " seconds ago";
167
+ }
168
+ else {
169
+ var interval = Math.abs(seconds) / 31536000;
170
+ console.log('timesince', seconds);
171
+ console.log('interval year', interval);
172
+ if (interval > 1) {
173
+ return Math.floor(interval) + " years later";
174
+ }
175
+ interval = Math.abs(seconds) / 2592000;
176
+ console.log('interval months', interval);
177
+ if (interval > 1) {
178
+ return Math.floor(interval) + " months later";
179
+ }
180
+ interval = Math.abs(seconds) / 86400;
181
+ console.log('interval days', interval);
182
+ if (interval > 1) {
183
+ return Math.floor(interval) + " days later";
184
+ }
185
+ interval = Math.abs(seconds) / 3600;
186
+ console.log('interval hours', interval);
187
+ if (interval > 1) {
188
+ return Math.floor(interval) + " hours later";
189
+ }
190
+ interval = Math.abs(seconds) / 60;
191
+ if (interval > 1) {
192
+ return Math.floor(interval) + " minutes later";
193
+ }
194
+ return Math.floor(Math.abs(seconds)) + " seconds later";
195
+ }
196
+ };
197
+ function readCookie(key) {
198
+ let name = key + "=";
199
+ let decodedCookie = decodeURIComponent(document.cookie);
200
+ let ca = decodedCookie.split(';');
201
+ for (let i = 0; i < ca.length; i++) {
202
+ let c = ca[i];
203
+ while (c.charAt(0) == ' ') {
204
+ c = c.substring(1);
205
+ }
206
+ if (c.indexOf(name) == 0) {
207
+ return c.substring(name.length, c.length);
208
+ }
209
+ }
210
+ return "";
211
+ }
212
+ async function callApi(url, data, authorization) {
213
+ return new Promise((resolve) => {
214
+ const jsonData = JSON.stringify(data);
215
+ var xhr = new XMLHttpRequest();
216
+ xhr.addEventListener("readystatechange", () => {
217
+ if (xhr != null) {
218
+ if (xhr.readyState === 4) {
219
+ resolve(xhr);
220
+ }
221
+ }
222
+ });
223
+ xhr.open("POST", url);
224
+ xhr.timeout = 1800000;
225
+ xhr.setRequestHeader("Content-Type", "application/json");
226
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
227
+ if (authorization != null) {
228
+ xhr.setRequestHeader('Authorization', 'Basic ' + authorization);
229
+ }
230
+ xhr.send(jsonData);
231
+ return xhr;
232
+ });
233
+ }
234
+ async function callApiPresignedDelete(url) {
235
+ return new Promise((resolve) => {
236
+ var xhr = new XMLHttpRequest();
237
+ xhr.addEventListener("readystatechange", () => {
238
+ if (xhr != null) {
239
+ if (xhr.readyState === 4) {
240
+ resolve(xhr);
241
+ }
242
+ }
243
+ });
244
+ xhr.open("DELETE", url);
245
+ xhr.timeout = 1800000;
246
+ xhr.setRequestHeader("Content-Type", "application/json");
247
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
248
+ xhr.send(null);
249
+ return xhr;
250
+ });
251
+ }
252
+ async function callApiPresignedGet(url) {
253
+ return new Promise((resolve) => {
254
+ var xhr = new XMLHttpRequest();
255
+ xhr.addEventListener("readystatechange", () => {
256
+ if (xhr != null) {
257
+ if (xhr.readyState === 4) {
258
+ resolve(xhr);
259
+ }
260
+ }
261
+ });
262
+ xhr.open("GET", url);
263
+ xhr.timeout = 1800000;
264
+ xhr.setRequestHeader("Content-Type", "application/json");
265
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
266
+ xhr.send(null);
267
+ return xhr;
268
+ });
269
+ }
270
+ async function callApiPresigned(url, data) {
271
+ return new Promise((resolve) => {
272
+ const jsonData = JSON.stringify(data);
273
+ var xhr = new XMLHttpRequest();
274
+ xhr.addEventListener("readystatechange", () => {
275
+ if (xhr != null) {
276
+ if (xhr.readyState === 4) {
277
+ resolve(xhr);
278
+ }
279
+ }
280
+ });
281
+ xhr.open("PUT", url);
282
+ xhr.timeout = 1800000;
283
+ xhr.setRequestHeader("Content-Type", "application/json");
284
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
285
+ xhr.send(jsonData);
286
+ return xhr;
287
+ });
288
+ }
289
+ function getRandomColor() {
290
+ var letters = '0123456789ABCDEF';
291
+ var color = '#';
292
+ for (var i = 0; i < 6; i++) {
293
+ color += letters[Math.floor(Math.random() * 16)];
294
+ }
295
+ return color;
296
+ }
297
+ function isInteger(value) {
298
+ return /^-?\d+$/.test(value);
299
+ }
300
+ function clearListeners(old_element) {
301
+ var _a;
302
+ var new_element = old_element.cloneNode(true);
303
+ (_a = old_element.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(new_element, old_element);
304
+ return new_element;
305
+ }
306
+ function jsonObjectToHtml(json) {
307
+ var html = '';
308
+ for (var i = 0; i < Object.keys(json).length; i++) {
309
+ var key = Object.keys(json)[i];
310
+ html += '<div>';
311
+ html += ('<span style="margin-left: 0px; padding-left: 0px">' + key + ':</span>&nbsp;');
312
+ html += ('<span class="td-body" part="td-head"><sf-i-elastic-text text="' + json[key].replace(/"/g, '') + '" lineSize="6" minLength="10"></sf-i-elastic-text></span>');
313
+ html += '</div>';
314
+ }
315
+ return html;
316
+ }
317
+ const exportFunctions = {
318
+ callApiPresignedDelete, callApiPresignedGet, callApiPresigned, jsonObjectToHtml, clearListeners, isInteger, callApi, validateName, readCookie, timeSince, createDiagonalPattern1, createDiagonalPattern2, createDiagonalPattern3, getRandomColor
319
+ };
320
+ export default exportFunctions;
321
321
  //# sourceMappingURL=util.js.map