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