@3dsource/utils 1.0.10 → 1.0.13
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/fesm2022/3dsource-utils.mjs +1900 -0
- package/fesm2022/3dsource-utils.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/{src/lib/color/CMYKtoRGB.ts → lib/color/CMYKtoRGB.d.ts} +1 -11
- package/lib/color/HEXtoRGB.d.ts +5 -0
- package/lib/color/HSVtoRGB.d.ts +21 -0
- package/{src/lib/color/RGBtoCMYK.ts → lib/color/RGBtoCMYK.d.ts} +1 -31
- package/lib/color/RGBtoHEX.d.ts +1 -0
- package/lib/color/RGBtoHSV.d.ts +19 -0
- package/lib/color/hsv.d.ts +1 -0
- package/lib/color/max.d.ts +1 -0
- package/lib/color/min.d.ts +1 -0
- package/lib/color/overlay.d.ts +1 -0
- package/{src/lib/color/rgb.ts → lib/color/rgb.d.ts} +1 -3
- package/lib/color/sub.d.ts +1 -0
- package/lib/color/subtract.d.ts +1 -0
- package/lib/color/sum.d.ts +1 -0
- package/{src/lib/color/toRGB.ts → lib/color/toRGB.d.ts} +1 -7
- package/lib/color/toRGBA.d.ts +1 -0
- package/lib/constants/color-codes.constant.d.ts +9 -0
- package/lib/csv/CSV2Array.d.ts +1 -0
- package/lib/csv/CSV2Records.d.ts +1 -0
- package/lib/csv/ObjectToCSV.d.ts +1 -0
- package/lib/dev/dev3d.d.ts +1 -0
- package/lib/dev/logger.d.ts +11 -0
- package/lib/dev/timeToString.d.ts +5 -0
- package/lib/filenaming/cleanupFileName.d.ts +1 -0
- package/lib/filenaming/makePath.d.ts +1 -0
- package/lib/filenaming/normalizePath.d.ts +1 -0
- package/lib/geom/expandOverRectangle.d.ts +2 -0
- package/lib/geom/fitIntoRectangle.d.ts +2 -0
- package/{src/lib/geom/interfaces/area.interface.ts → lib/geom/interfaces/area.interface.d.ts} +1 -2
- package/{src/lib/geom/interfaces/rect.interface.ts → lib/geom/interfaces/rect.interface.d.ts} +2 -2
- package/lib/geom/interfaces/size.interface.d.ts +4 -0
- package/lib/geom/interfaces//321/201oords.interface.d.ts +4 -0
- package/lib/helpers/BatchLoader.d.ts +47 -0
- package/lib/helpers/KeyboardNumericCode.d.ts +103 -0
- package/lib/helpers/debounce.d.ts +1 -0
- package/lib/helpers/generate-uuid.d.ts +1 -0
- package/{src/lib/helpers/index.ts → lib/helpers/index.d.ts} +1 -0
- package/lib/helpers/is-desktop.d.ts +1 -0
- package/lib/helpers/save-to-local-drive.d.ts +1 -0
- package/lib/helpers/serialize.d.ts +1 -0
- package/lib/helpers/short-hash.d.ts +2 -0
- package/lib/helpers/signal.d.ts +23 -0
- package/lib/helpers/sleep.d.ts +1 -0
- package/lib/helpers/trimLastSlashFromUrl.d.ts +1 -0
- package/lib/image/SaveImage.d.ts +18 -0
- package/lib/image/getCanvasCached.d.ts +4 -0
- package/lib/image/getSnapshot.d.ts +2 -0
- package/lib/image/loadImage.d.ts +1 -0
- package/lib/interfaces/image-output.d.ts +7 -0
- package/{src/lib/interfaces/load-args-tmp.interface.ts → lib/interfaces/load-args-tmp.interface.d.ts} +1 -2
- package/lib/interfaces/load-args.interface.d.ts +15 -0
- package/{src/lib/math/baseSortedIndex.ts → lib/math/baseSortedIndex.d.ts} +1 -19
- package/{src/lib/math/calculateMedian.ts → lib/math/calculateMedian.d.ts} +1 -17
- package/{src/lib/math/circularIndex.ts → lib/math/circularIndex.d.ts} +1 -5
- package/lib/math/clampf.d.ts +8 -0
- package/lib/math/degrees.d.ts +2 -0
- package/{src/lib/math/floatCompare.ts → lib/math/floatCompare.d.ts} +3 -30
- package/{src/lib/math/inverseLerp.ts → lib/math/inverseLerp.d.ts} +1 -22
- package/lib/math/lerp.d.ts +7 -0
- package/{src/lib/mutex/Mutex.ts → lib/mutex/Mutex.d.ts} +8 -15
- package/{src/lib/mutex/Semaphore.ts → lib/mutex/Semaphore.d.ts} +7 -27
- package/lib/mutex/TaskRunner.d.ts +5 -0
- package/lib/predicates/operators.d.ts +32 -0
- package/{src/lib/predicates/textForSearch.ts → lib/predicates/textForSearch.d.ts} +1 -17
- package/{src/lib/predicates/where.ts → lib/predicates/where.d.ts} +2 -32
- package/lib/rxjs/leadingTrailingDebounceTime.d.ts +15 -0
- package/{src/lib/rxjs/smoothTransition.ts → lib/rxjs/smoothTransition.d.ts} +1 -19
- package/lib/rxjs/tapLog.d.ts +2 -0
- package/lib/strings/pad.d.ts +8 -0
- package/package.json +15 -4
- package/eslint.config.js +0 -37
- package/ng-package.json +0 -7
- package/src/lib/color/HEXtoRGB.ts +0 -9
- package/src/lib/color/HSVtoRGB.ts +0 -82
- package/src/lib/color/RGBtoHEX.ts +0 -17
- package/src/lib/color/RGBtoHSV.ts +0 -53
- package/src/lib/color/hsv.ts +0 -14
- package/src/lib/color/max.ts +0 -18
- package/src/lib/color/min.ts +0 -18
- package/src/lib/color/overlay.ts +0 -25
- package/src/lib/color/sub.ts +0 -18
- package/src/lib/color/subtract.ts +0 -27
- package/src/lib/color/sum.ts +0 -19
- package/src/lib/color/toRGBA.ts +0 -8
- package/src/lib/constants/color-codes.constant.ts +0 -9
- package/src/lib/csv/CSV2Array.ts +0 -66
- package/src/lib/csv/CSV2Records.ts +0 -56
- package/src/lib/csv/ObjectToCSV.ts +0 -21
- package/src/lib/dev/dev3d.ts +0 -1
- package/src/lib/dev/logger.ts +0 -94
- package/src/lib/dev/timeToString.ts +0 -16
- package/src/lib/filenaming/cleanupFileName.ts +0 -18
- package/src/lib/filenaming/makePath.ts +0 -5
- package/src/lib/filenaming/normalizePath.ts +0 -9
- package/src/lib/geom/expandOverRectangle.ts +0 -17
- package/src/lib/geom/fitIntoRectangle.ts +0 -43
- package/src/lib/geom/interfaces/size.interface.ts +0 -4
- package/src/lib/geom/interfaces//321/201oords.interface.ts +0 -4
- package/src/lib/helpers/BatchLoader.ts +0 -243
- package/src/lib/helpers/KeyboardNumericCode.ts +0 -118
- package/src/lib/helpers/debounce.ts +0 -10
- package/src/lib/helpers/generate-uuid.ts +0 -5
- package/src/lib/helpers/save-to-local-drive.ts +0 -31
- package/src/lib/helpers/serialize.ts +0 -11
- package/src/lib/helpers/short-hash.ts +0 -20
- package/src/lib/helpers/signal.ts +0 -46
- package/src/lib/helpers/sleep.ts +0 -3
- package/src/lib/helpers/trimLastSlashFromUrl.ts +0 -9
- package/src/lib/image/SaveImage.ts +0 -65
- package/src/lib/image/getCanvasCached.ts +0 -16
- package/src/lib/image/getSnapshot.ts +0 -99
- package/src/lib/image/loadImage.ts +0 -13
- package/src/lib/interfaces/image-output.ts +0 -8
- package/src/lib/interfaces/load-args.interface.ts +0 -15
- package/src/lib/math/clampf.ts +0 -14
- package/src/lib/math/degrees.ts +0 -7
- package/src/lib/math/lerp.ts +0 -12
- package/src/lib/mutex/TaskRunner.ts +0 -26
- package/src/lib/predicates/operators.ts +0 -75
- package/src/lib/rxjs/leadingTrailingDebounceTime.ts +0 -86
- package/src/lib/rxjs/tapLog.ts +0 -13
- package/src/lib/strings/pad.ts +0 -18
- package/tsconfig.lib.json +0 -13
- package/tsconfig.lib.prod.json +0 -11
- /package/{src/lib/color/index.ts → lib/color/index.d.ts} +0 -0
- /package/{src/lib/constants/index.ts → lib/constants/index.d.ts} +0 -0
- /package/{src/lib/csv/index.ts → lib/csv/index.d.ts} +0 -0
- /package/{src/lib/dev/index.ts → lib/dev/index.d.ts} +0 -0
- /package/{src/lib/filenaming/index.ts → lib/filenaming/index.d.ts} +0 -0
- /package/{src/lib/geom/index.ts → lib/geom/index.d.ts} +0 -0
- /package/{src/lib/geom/interfaces/index.ts → lib/geom/interfaces/index.d.ts} +0 -0
- /package/{src/lib/image/index.ts → lib/image/index.d.ts} +0 -0
- /package/{src/lib/interfaces/index.ts → lib/interfaces/index.d.ts} +0 -0
- /package/{src/lib/math/index.ts → lib/math/index.d.ts} +0 -0
- /package/{src/lib/mutex/index.ts → lib/mutex/index.d.ts} +0 -0
- /package/{src/lib/predicates/index.ts → lib/predicates/index.d.ts} +0 -0
- /package/{src/lib/rxjs/index.ts → lib/rxjs/index.d.ts} +0 -0
- /package/{src/lib/strings/index.ts → lib/strings/index.d.ts} +0 -0
- /package/{src/public-api.ts → public-api.d.ts} +0 -0
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Area, Rect } from './interfaces';
|
|
2
|
-
|
|
3
|
-
export function expandOverRectangle(objectRect: Rect, areaRect: Rect): Area {
|
|
4
|
-
const ratio: number = objectRect.w / objectRect.h;
|
|
5
|
-
const result: Area = { x: 0, y: 0, w: 0, h: 0, scale: 1 };
|
|
6
|
-
if (areaRect.w / ratio < areaRect.h) {
|
|
7
|
-
result.w = areaRect.h * ratio;
|
|
8
|
-
result.h = areaRect.h;
|
|
9
|
-
} else {
|
|
10
|
-
result.w = areaRect.w;
|
|
11
|
-
result.h = areaRect.w / ratio;
|
|
12
|
-
}
|
|
13
|
-
result.x = areaRect.x + (areaRect.w - result.w) / 2;
|
|
14
|
-
result.y = areaRect.y + (areaRect.h - result.h) / 2;
|
|
15
|
-
result.scale = result.w / objectRect.w;
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { Area, Rect } from './interfaces';
|
|
2
|
-
|
|
3
|
-
export function fitIntoRectangle(
|
|
4
|
-
objectRect: Rect,
|
|
5
|
-
areaRect: Rect,
|
|
6
|
-
round = true,
|
|
7
|
-
fixedRatio: number | null = null,
|
|
8
|
-
): Area {
|
|
9
|
-
const result: Area = { x: 0, y: 0, w: 0, h: 0, scale: 1 };
|
|
10
|
-
const ratio: number = objectRect.h / objectRect.w;
|
|
11
|
-
|
|
12
|
-
if (objectRect.h > objectRect.w) {
|
|
13
|
-
result.h = areaRect.h;
|
|
14
|
-
result.w = areaRect.h / ratio;
|
|
15
|
-
|
|
16
|
-
if (result.w > areaRect.w) {
|
|
17
|
-
result.w = areaRect.w;
|
|
18
|
-
result.h = areaRect.w * ratio;
|
|
19
|
-
}
|
|
20
|
-
} else {
|
|
21
|
-
result.w = areaRect.w;
|
|
22
|
-
result.h = areaRect.w * ratio;
|
|
23
|
-
|
|
24
|
-
if (result.h > areaRect.h) {
|
|
25
|
-
result.h = areaRect.h;
|
|
26
|
-
result.w = areaRect.h / ratio;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (fixedRatio) {
|
|
31
|
-
result.w = objectRect.w * fixedRatio;
|
|
32
|
-
result.h = objectRect.h * fixedRatio;
|
|
33
|
-
}
|
|
34
|
-
const wOut: number = round ? Math.floor(result.w) : result.w;
|
|
35
|
-
const hOut: number = round ? Math.floor(result.h) : result.h;
|
|
36
|
-
return {
|
|
37
|
-
x: areaRect.x + (areaRect.w - wOut) / 2,
|
|
38
|
-
y: areaRect.y + (areaRect.h - hOut) / 2,
|
|
39
|
-
w: wOut,
|
|
40
|
-
h: hOut,
|
|
41
|
-
scale: wOut / objectRect.w,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import type { LoadArgs, LoadArgsTmp } from '../interfaces';
|
|
2
|
-
import { loadImage } from '../image';
|
|
3
|
-
|
|
4
|
-
export class BatchLoader {
|
|
5
|
-
private maximumSlotsNumber = 1;
|
|
6
|
-
private queue: LoadArgsTmp[] = [];
|
|
7
|
-
private slots: LoadArgsTmp[] = [];
|
|
8
|
-
private _whenDone!: () => any;
|
|
9
|
-
|
|
10
|
-
clear() {
|
|
11
|
-
this.queue.forEach((item) => {
|
|
12
|
-
try {
|
|
13
|
-
if (item.img) {
|
|
14
|
-
item.img.src = '';
|
|
15
|
-
}
|
|
16
|
-
} catch (e) {
|
|
17
|
-
console.warn(e);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
item.xhr?.abort();
|
|
22
|
-
} catch (e) {
|
|
23
|
-
console.warn(e);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
this.slots.forEach((item) => {
|
|
28
|
-
try {
|
|
29
|
-
if (item.img) {
|
|
30
|
-
item.img.src = '';
|
|
31
|
-
}
|
|
32
|
-
} catch (e) {
|
|
33
|
-
console.warn(e);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
item.xhr?.abort();
|
|
38
|
-
} catch (e) {
|
|
39
|
-
console.warn(e);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
this.slots.length = 0;
|
|
43
|
-
this.queue.length = 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* new settings
|
|
48
|
-
* you must pass new settings
|
|
49
|
-
* @param sett
|
|
50
|
-
*/
|
|
51
|
-
setSettings(sett: any) {
|
|
52
|
-
this.maximumSlotsNumber =
|
|
53
|
-
sett.maximumSlotsNumber !== undefined
|
|
54
|
-
? sett.maximumSlotsNumber
|
|
55
|
-
: this.maximumSlotsNumber;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* execute with a chosen file
|
|
60
|
-
* @param id
|
|
61
|
-
* @param func
|
|
62
|
-
*/
|
|
63
|
-
withItem(id: string, func: (item: LoadArgs) => any): boolean {
|
|
64
|
-
let item = this.getById(id);
|
|
65
|
-
if (!item) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
item = func(item);
|
|
69
|
-
this.queue.sort(this.sortByOrder);
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
remove(id: string): LoadArgs[] {
|
|
74
|
-
this.queue = this.queue.filter((arg) => arg.id !== id);
|
|
75
|
-
return this.queue;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* executes when all files are downloaded
|
|
80
|
-
* @param cb
|
|
81
|
-
*/
|
|
82
|
-
whenDone(cb: any) {
|
|
83
|
-
this._whenDone = cb;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// order {number} lower will execute first, default *100*
|
|
87
|
-
load(args: LoadArgs[]) {
|
|
88
|
-
const out: { path: string; self?: any; id: string }[] = args
|
|
89
|
-
.filter((arg) => !!arg.path)
|
|
90
|
-
.map((arg) => ({
|
|
91
|
-
path: arg.path,
|
|
92
|
-
id: this.add(arg),
|
|
93
|
-
}));
|
|
94
|
-
|
|
95
|
-
this.queue.sort(this.sortByOrder);
|
|
96
|
-
this.checkSlots();
|
|
97
|
-
|
|
98
|
-
return out;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* operates with one file
|
|
103
|
-
* @param item
|
|
104
|
-
* @private
|
|
105
|
-
*/
|
|
106
|
-
private add(item: LoadArgs): string {
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
108
|
-
const that = this;
|
|
109
|
-
const temp: LoadArgsTmp = {
|
|
110
|
-
id: item.id,
|
|
111
|
-
resolutionId: null,
|
|
112
|
-
useXhr: item.useXhr,
|
|
113
|
-
order: item.order !== undefined ? item.order : 100,
|
|
114
|
-
fallBack: item.fallBack,
|
|
115
|
-
path: item.path,
|
|
116
|
-
onLoadEnd: item.onLoadEnd,
|
|
117
|
-
onProgress: item.onProgress,
|
|
118
|
-
onLoadStart: item.onLoadStart,
|
|
119
|
-
extra: item.extra,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
let retryCount = 1;
|
|
123
|
-
if (temp.useXhr) {
|
|
124
|
-
temp.xhr = this.getXmlHttp();
|
|
125
|
-
temp.xhr.onloadstart = (data: ProgressEvent) => item.onLoadStart(data);
|
|
126
|
-
temp.xhr.onprogress = (data: ProgressEvent) => item.onProgress(data);
|
|
127
|
-
temp.xhr.onreadystatechange = async function (data: any) {
|
|
128
|
-
if (this.readyState === 1 && this.status === 0) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if (
|
|
132
|
-
this.readyState === 4 &&
|
|
133
|
-
(this.status === 404 || this.status === 0)
|
|
134
|
-
) {
|
|
135
|
-
temp.error = true;
|
|
136
|
-
that.loadEnd(temp);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if (this.readyState === 4 && this.status === 200) {
|
|
140
|
-
const urlCreator = window.URL;
|
|
141
|
-
const imageUrl = urlCreator.createObjectURL(data.target.response);
|
|
142
|
-
temp.img = await loadImage(imageUrl);
|
|
143
|
-
that.loadEnd(temp);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
} else {
|
|
148
|
-
temp.img = new Image();
|
|
149
|
-
temp.img.crossOrigin = 'anonymous';
|
|
150
|
-
temp.img.onload = () => {
|
|
151
|
-
that.loadEnd(temp);
|
|
152
|
-
};
|
|
153
|
-
temp.img.onerror = () => {
|
|
154
|
-
if (temp.fallBack && retryCount-- > 0) {
|
|
155
|
-
console.warn('Fallback used =>', temp.path, '=>', temp.fallBack);
|
|
156
|
-
if (temp.img) {
|
|
157
|
-
temp.img.onload = null;
|
|
158
|
-
temp.img.src = temp.fallBack;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
that.loadEnd(temp);
|
|
162
|
-
} else {
|
|
163
|
-
temp.error = true;
|
|
164
|
-
that.loadEnd(temp);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
this.queue.push(temp);
|
|
169
|
-
return temp.id as string;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private sortByOrder(a: LoadArgs, b: LoadArgs): number {
|
|
173
|
-
return a.order > b.order ? 1 : a.order < b.order ? -1 : 0;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
private loadEnd(item: LoadArgs) {
|
|
177
|
-
if (item.onLoadEnd !== undefined) {
|
|
178
|
-
for (let i = 0, len = this.slots.length; i < len; i += 1) {
|
|
179
|
-
if (this.slots[i].id === item.id) {
|
|
180
|
-
this.slots.splice(i, 1);
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
item.onLoadEnd(item);
|
|
185
|
-
}
|
|
186
|
-
this.checkSlots();
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
private checkSlots() {
|
|
190
|
-
while (
|
|
191
|
-
(this.slots.length < this.maximumSlotsNumber ||
|
|
192
|
-
this.maximumSlotsNumber === -1) &&
|
|
193
|
-
this.queue.length
|
|
194
|
-
) {
|
|
195
|
-
this.slots.push(this.queue.shift() as LoadArgsTmp);
|
|
196
|
-
const slot: LoadArgsTmp = this.slots[
|
|
197
|
-
this.slots.length - 1
|
|
198
|
-
] as LoadArgsTmp;
|
|
199
|
-
if (slot.useXhr) {
|
|
200
|
-
slot.xhr?.open('GET', slot.path, true);
|
|
201
|
-
slot.xhr?.send(null);
|
|
202
|
-
} else {
|
|
203
|
-
if (slot.img) {
|
|
204
|
-
slot.img.src = slot.path;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (
|
|
210
|
-
this.slots.length === 0 &&
|
|
211
|
-
this.queue.length === 0 &&
|
|
212
|
-
this._whenDone !== undefined
|
|
213
|
-
) {
|
|
214
|
-
this._whenDone();
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* get Item By id for interaction with files in this.queue
|
|
220
|
-
* @param id
|
|
221
|
-
* @private
|
|
222
|
-
*/
|
|
223
|
-
private getById(id: string): LoadArgs | null {
|
|
224
|
-
for (let i = 0, len = this.queue.length; i < len; i += 1) {
|
|
225
|
-
if (this.queue[i].id === id) {
|
|
226
|
-
return this.queue[i];
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
private getXmlHttp(): XMLHttpRequest {
|
|
233
|
-
let xhr = null;
|
|
234
|
-
try {
|
|
235
|
-
xhr = new XMLHttpRequest();
|
|
236
|
-
xhr.responseType = 'blob';
|
|
237
|
-
} catch (e) {
|
|
238
|
-
console.warn(e);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return xhr as any;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
const KeyboardNumericCode = {
|
|
2
|
-
Backspace: 8,
|
|
3
|
-
Tab: 9,
|
|
4
|
-
Numpad5: 12,
|
|
5
|
-
NumpadEnter: 13,
|
|
6
|
-
ShiftRight: 16,
|
|
7
|
-
ControlRight: 17,
|
|
8
|
-
ControlLeft: 17,
|
|
9
|
-
AltRight: 18,
|
|
10
|
-
Escape: 27,
|
|
11
|
-
Space: 32,
|
|
12
|
-
Numpad9: 33,
|
|
13
|
-
Numpad3: 34,
|
|
14
|
-
Numpad1: 35,
|
|
15
|
-
Numpad7: 36,
|
|
16
|
-
Numpad4: 37,
|
|
17
|
-
Numpad8: 38,
|
|
18
|
-
Numpad6: 39,
|
|
19
|
-
Numpad2: 40,
|
|
20
|
-
Numpad0: 45,
|
|
21
|
-
NumpadDecimal: 46,
|
|
22
|
-
Digit0: 48,
|
|
23
|
-
Digit1: 49,
|
|
24
|
-
Digit2: 50,
|
|
25
|
-
Digit3: 51,
|
|
26
|
-
Digit4: 52,
|
|
27
|
-
Digit5: 53,
|
|
28
|
-
Digit6: 54,
|
|
29
|
-
Digit7: 55,
|
|
30
|
-
Digit8: 56,
|
|
31
|
-
Digit9: 57,
|
|
32
|
-
KeyA: 65,
|
|
33
|
-
KeyB: 66,
|
|
34
|
-
KeyC: 67,
|
|
35
|
-
KeyD: 68,
|
|
36
|
-
KeyE: 69,
|
|
37
|
-
KeyF: 70,
|
|
38
|
-
KeyG: 71,
|
|
39
|
-
KeyH: 72,
|
|
40
|
-
KeyI: 73,
|
|
41
|
-
KeyJ: 74,
|
|
42
|
-
KeyK: 75,
|
|
43
|
-
KeyL: 76,
|
|
44
|
-
KeyM: 77,
|
|
45
|
-
KeyN: 78,
|
|
46
|
-
KeyO: 79,
|
|
47
|
-
KeyP: 80,
|
|
48
|
-
KeyQ: 81,
|
|
49
|
-
KeyR: 82,
|
|
50
|
-
KeyS: 83,
|
|
51
|
-
KeyT: 84,
|
|
52
|
-
KeyU: 85,
|
|
53
|
-
KeyV: 86,
|
|
54
|
-
KeyW: 87,
|
|
55
|
-
KeyX: 88,
|
|
56
|
-
KeyY: 89,
|
|
57
|
-
KeyZ: 90,
|
|
58
|
-
MetaLeft: 91,
|
|
59
|
-
ContextMenu: 93,
|
|
60
|
-
NumpadMultiply: 106,
|
|
61
|
-
NumpadAdd: 107,
|
|
62
|
-
NumpadSubtract: 109,
|
|
63
|
-
NumpadDivide: 111,
|
|
64
|
-
F1: 112,
|
|
65
|
-
F2: 113,
|
|
66
|
-
F3: 114,
|
|
67
|
-
F4: 115,
|
|
68
|
-
F5: 116,
|
|
69
|
-
F6: 117,
|
|
70
|
-
F7: 118,
|
|
71
|
-
F8: 119,
|
|
72
|
-
F9: 120,
|
|
73
|
-
F10: 121,
|
|
74
|
-
F11: 122,
|
|
75
|
-
F12: 123,
|
|
76
|
-
NumLock: 144,
|
|
77
|
-
ScrollLock: 145,
|
|
78
|
-
Semicolon: 186,
|
|
79
|
-
Equal: 187,
|
|
80
|
-
Comma: 188,
|
|
81
|
-
Minus: 189,
|
|
82
|
-
Period: 190,
|
|
83
|
-
Slash: 191,
|
|
84
|
-
Backquote: 192,
|
|
85
|
-
BracketLeft: 219,
|
|
86
|
-
Backslash: 220,
|
|
87
|
-
BracketRight: 221,
|
|
88
|
-
Quote: 222,
|
|
89
|
-
IntlBackslash: 226,
|
|
90
|
-
ArrowUp: 38,
|
|
91
|
-
ArrowDown: 40,
|
|
92
|
-
ArrowLeft: 37,
|
|
93
|
-
ArrowRight: 39,
|
|
94
|
-
} as const;
|
|
95
|
-
|
|
96
|
-
type IKeyName = keyof typeof KeyboardNumericCode;
|
|
97
|
-
type IKeyCode = (typeof KeyboardNumericCode)[IKeyName];
|
|
98
|
-
|
|
99
|
-
type InvertedKeyMapType = {
|
|
100
|
-
[K in IKeyName as (typeof KeyboardNumericCode)[K]]: K;
|
|
101
|
-
};
|
|
102
|
-
const InvertedKeyMapValues = {} as { [K in IKeyCode]: IKeyName[K] };
|
|
103
|
-
|
|
104
|
-
//For use for InvertedKeyMap[32] will return 'Space' and so on
|
|
105
|
-
const InvertedKeyMap = InvertedKeyMapValues as InvertedKeyMapType;
|
|
106
|
-
|
|
107
|
-
const KeyboardStringCode = {} as { [K in IKeyName]: K };
|
|
108
|
-
|
|
109
|
-
Object.entries(KeyboardNumericCode).forEach(
|
|
110
|
-
// @ts-expect-error @typescript-eslint/ban-ts-comment
|
|
111
|
-
([key, value]: [IKeyName, IKeyCode]) => {
|
|
112
|
-
InvertedKeyMapValues[value] = key;
|
|
113
|
-
// @ts-expect-error @typescript-eslint/ban-ts-comment
|
|
114
|
-
KeyboardStringCode[key] = key;
|
|
115
|
-
},
|
|
116
|
-
);
|
|
117
|
-
export type { IKeyName, IKeyCode };
|
|
118
|
-
export { KeyboardStringCode, InvertedKeyMap, KeyboardNumericCode };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const debounce = <T extends (...args: any[]) => any>(
|
|
2
|
-
fn: T,
|
|
3
|
-
ms = 300,
|
|
4
|
-
) => {
|
|
5
|
-
let timeoutId: ReturnType<typeof setTimeout>;
|
|
6
|
-
return function (this: any, ...args: any[]) {
|
|
7
|
-
clearTimeout(timeoutId);
|
|
8
|
-
timeoutId = setTimeout(() => fn.apply(this, args), ms);
|
|
9
|
-
};
|
|
10
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export const saveToLocalDrive = (uri: string, name: string) => {
|
|
2
|
-
if (!uri) {
|
|
3
|
-
return;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
if ((navigator as any).msSaveBlob) {
|
|
7
|
-
// IE10+
|
|
8
|
-
try {
|
|
9
|
-
return (navigator as any).msSaveBlob(uri, name);
|
|
10
|
-
} catch (e) {
|
|
11
|
-
console.warn(e);
|
|
12
|
-
}
|
|
13
|
-
} else {
|
|
14
|
-
const link = document.createElement('a');
|
|
15
|
-
link.target = '_blank';
|
|
16
|
-
link.href = uri;
|
|
17
|
-
link.download = name;
|
|
18
|
-
|
|
19
|
-
document.body.appendChild(link);
|
|
20
|
-
|
|
21
|
-
if (link.click) {
|
|
22
|
-
link.click();
|
|
23
|
-
} else {
|
|
24
|
-
const event = document.createEvent('MouseEvents');
|
|
25
|
-
(event as any).initMouseEvent('click', true, true, window);
|
|
26
|
-
link.dispatchEvent(event);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
document.body.removeChild(link);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Md5 } from 'ts-md5';
|
|
2
|
-
|
|
3
|
-
export function shortHash<T>(data: T, shorten?: boolean): string;
|
|
4
|
-
export function shortHash(data: null | undefined, shorten?: boolean): null;
|
|
5
|
-
export function shortHash<T>(
|
|
6
|
-
data: T | null | undefined,
|
|
7
|
-
shorten = true,
|
|
8
|
-
): string | null {
|
|
9
|
-
if (!data) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const stringify: string = Md5.hashStr(JSON.stringify(data));
|
|
14
|
-
|
|
15
|
-
if (shorten) {
|
|
16
|
-
return parseInt('0x' + stringify.substring(0, 10), 16).toString(32);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return stringify;
|
|
20
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { Observable } from 'rxjs';
|
|
2
|
-
import { Subject } from 'rxjs';
|
|
3
|
-
import { filter, map } from 'rxjs/operators';
|
|
4
|
-
|
|
5
|
-
interface BroadcastEvent {
|
|
6
|
-
key: any;
|
|
7
|
-
data?: any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* SingleTone Private class.
|
|
12
|
-
* Event-Driving pattern for sending signals from component to component.
|
|
13
|
-
*/
|
|
14
|
-
class SignalClass {
|
|
15
|
-
private static eventBus: Subject<BroadcastEvent>;
|
|
16
|
-
|
|
17
|
-
constructor() {
|
|
18
|
-
if (SignalClass.eventBus) {
|
|
19
|
-
throw new Error(`Check that 'SignalClass' is not instantiated again!`);
|
|
20
|
-
}
|
|
21
|
-
SignalClass.eventBus = new Subject<BroadcastEvent>();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* It is not recommended to use this class directly.
|
|
26
|
-
* use the sendSignal functions instead.
|
|
27
|
-
* those wrappers are more convenient and provide a better type safety.
|
|
28
|
-
*/
|
|
29
|
-
broadcast<K, D>(key: K, data?: D) {
|
|
30
|
-
SignalClass.eventBus.next({ key, data });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* It is not recommended to use this class directly.
|
|
35
|
-
* use the fromSignal functions instead.
|
|
36
|
-
* those wrappers are more convenient and provide a better type safety.
|
|
37
|
-
*/
|
|
38
|
-
on<K, D = any>(key: K): Observable<D> {
|
|
39
|
-
return SignalClass.eventBus.asObservable().pipe(
|
|
40
|
-
filter((event) => event.key === key),
|
|
41
|
-
map((event) => event.data),
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const Signal = new SignalClass();
|
package/src/lib/helpers/sleep.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { getSnapshot } from './getSnapshot';
|
|
2
|
-
import type { ImageOutputValues } from '../interfaces';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* USE DownloadImage instead!
|
|
6
|
-
* @deprecated use DownloadImage instead!
|
|
7
|
-
* @param imageSource
|
|
8
|
-
* @param name
|
|
9
|
-
* @param width
|
|
10
|
-
* @param format
|
|
11
|
-
*/
|
|
12
|
-
function SaveImage(
|
|
13
|
-
imageSource:
|
|
14
|
-
| HTMLImageElement
|
|
15
|
-
| HTMLCanvasElement
|
|
16
|
-
| HTMLVideoElement
|
|
17
|
-
| ImageBitmap
|
|
18
|
-
| string,
|
|
19
|
-
name: string,
|
|
20
|
-
width?: number,
|
|
21
|
-
format?: string | ImageOutputValues,
|
|
22
|
-
): any {
|
|
23
|
-
let out;
|
|
24
|
-
const image: any = imageSource;
|
|
25
|
-
|
|
26
|
-
if (typeof image !== 'string') {
|
|
27
|
-
out = getSnapshot(image, width, format as ImageOutputValues);
|
|
28
|
-
} else {
|
|
29
|
-
out = image;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if ((navigator as any).msSaveBlob) {
|
|
33
|
-
// IE10+
|
|
34
|
-
try {
|
|
35
|
-
const blob = image.msToBlob();
|
|
36
|
-
return (navigator as any).msSaveBlob(blob, name);
|
|
37
|
-
} catch (e) {
|
|
38
|
-
console.warn(e);
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
const uri = out;
|
|
42
|
-
const link = document.createElement('a');
|
|
43
|
-
link.download = name;
|
|
44
|
-
link.href = uri as string;
|
|
45
|
-
|
|
46
|
-
document.body.appendChild(link);
|
|
47
|
-
if (link.click) {
|
|
48
|
-
link.click();
|
|
49
|
-
} else {
|
|
50
|
-
const event = document.createEvent('MouseEvents');
|
|
51
|
-
(event as any).initMouseEvent('click', true, true, window);
|
|
52
|
-
link.dispatchEvent(event);
|
|
53
|
-
}
|
|
54
|
-
document.body.removeChild(link);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @param imageSource
|
|
60
|
-
* @param string name
|
|
61
|
-
* @param number width
|
|
62
|
-
* @param string format
|
|
63
|
-
*/
|
|
64
|
-
const DownloadImage = SaveImage;
|
|
65
|
-
export { SaveImage, DownloadImage };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const canvasCacheObj: any = {};
|
|
2
|
-
|
|
3
|
-
export function getCanvasCached(id: string): {
|
|
4
|
-
canvas: HTMLCanvasElement;
|
|
5
|
-
ctx: CanvasRenderingContext2D;
|
|
6
|
-
} {
|
|
7
|
-
if (!canvasCacheObj[id]) {
|
|
8
|
-
const canvas = document.createElement('canvas');
|
|
9
|
-
canvasCacheObj[id] = {
|
|
10
|
-
canvas,
|
|
11
|
-
ctx: canvas.getContext('2d'),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return canvasCacheObj[id];
|
|
16
|
-
}
|