lupine.web 1.0.16 → 1.0.17
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/package.json +1 -5
- package/src/core/bind-lang.ts +6 -5
- package/src/core/bind-links.ts +2 -2
- package/src/core/bind-theme.ts +6 -5
- package/src/core/export-lupine.ts +64 -0
- package/src/core/index.ts +2 -1
- package/src/core/{core.ts → initialize.ts} +9 -67
- package/src/core/page-router.ts +3 -2
- package/src/core/server-cookie.ts +5 -3
- package/src/index.ts +0 -1
- package/src/lib/index.ts +2 -13
- package/src/lib/is-frontend.ts +3 -0
- package/src/styles/index.ts +0 -5
- package/src/components/button-push-animation.tsx +0 -138
- package/src/components/button.tsx +0 -55
- package/src/components/drag-refresh.tsx +0 -110
- package/src/components/editable-label.tsx +0 -83
- package/src/components/float-window.tsx +0 -226
- package/src/components/grid.tsx +0 -18
- package/src/components/html-var.tsx +0 -41
- package/src/components/index.ts +0 -36
- package/src/components/input-with-title.tsx +0 -24
- package/src/components/link-item.tsx +0 -13
- package/src/components/link-list.tsx +0 -62
- package/src/components/menu-bar.tsx +0 -220
- package/src/components/menu-item-props.tsx +0 -10
- package/src/components/menu-sidebar.tsx +0 -289
- package/src/components/message-box.tsx +0 -44
- package/src/components/meta-data.tsx +0 -36
- package/src/components/meta-description.tsx +0 -12
- package/src/components/modal.tsx +0 -29
- package/src/components/notice-message.tsx +0 -119
- package/src/components/page-title.tsx +0 -6
- package/src/components/paging-link.tsx +0 -100
- package/src/components/panel.tsx +0 -21
- package/src/components/popup-menu.tsx +0 -218
- package/src/components/progress.tsx +0 -91
- package/src/components/redirect.tsx +0 -19
- package/src/components/resizable-splitter.tsx +0 -129
- package/src/components/select-with-title.tsx +0 -37
- package/src/components/spinner.tsx +0 -100
- package/src/components/svg.tsx +0 -24
- package/src/components/tabs.tsx +0 -252
- package/src/components/text-glow.tsx +0 -36
- package/src/components/text-wave.tsx +0 -54
- package/src/components/theme-selector.tsx +0 -32
- package/src/components/toggle-base.tsx +0 -260
- package/src/components/toggle-switch.tsx +0 -156
- package/src/lib/date-utils.ts +0 -317
- package/src/lib/deep-merge.ts +0 -37
- package/src/lib/document-ready.ts +0 -36
- package/src/lib/dom/calculate-text-width.ts +0 -13
- package/src/lib/dom/download-stream.ts +0 -17
- package/src/lib/dom/download.ts +0 -12
- package/src/lib/dom/index.ts +0 -71
- package/src/lib/dynamical-load.ts +0 -138
- package/src/lib/format-bytes.ts +0 -11
- package/src/lib/lite-dom.ts +0 -227
- package/src/lib/message-hub.ts +0 -105
- package/src/lib/observable.ts +0 -188
- package/src/lib/promise-timeout.ts +0 -1
- package/src/lib/simple-storage.ts +0 -40
- package/src/lib/stop-propagation.ts +0 -7
- package/src/lib/upload-file.ts +0 -68
- package/src/styles/base-themes.ts +0 -17
- package/src/styles/dark-themes.ts +0 -86
- package/src/styles/light-themes.ts +0 -93
- package/src/styles/media-query.ts +0 -93
- package/src/styles/shared-themes.ts +0 -52
- /package/src/lib/{dom/cookie.ts → cookie.ts} +0 -0
package/src/lib/date-utils.ts
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
export class DateUtils {
|
|
2
|
-
/*
|
|
3
|
-
* returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
|
|
4
|
-
*/
|
|
5
|
-
static now(): number {
|
|
6
|
-
return Date.now();
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// Date time string format: YYYY-MM-DDTHH:mm:ss.sssZ
|
|
10
|
-
// The string that you want to parse into a Date should match this format or a portion of this format.
|
|
11
|
-
// The “T” character separates the date from the time portion of the string. The “Z” character is the UTC offset representation.
|
|
12
|
-
static toDate(str: string): Date {
|
|
13
|
-
return new Date(Date.parse(str));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
static clone(dt: Date): Date {
|
|
17
|
-
return new Date(dt.valueOf());
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static isLeapYear(year: number): boolean {
|
|
21
|
-
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static daysInMonth(year: number, month: number) {
|
|
25
|
-
return month === 1 ? (DateUtils.isLeapYear(year) ? 29 : 28) : 31 - ((month % 7) % 2);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static createDate(
|
|
29
|
-
year: number,
|
|
30
|
-
monthIndex: number,
|
|
31
|
-
date?: number,
|
|
32
|
-
hours?: number,
|
|
33
|
-
minutes?: number,
|
|
34
|
-
seconds?: number,
|
|
35
|
-
ms?: number
|
|
36
|
-
): Date {
|
|
37
|
-
const dt = new Date(year, monthIndex, date, hours, minutes, seconds, ms);
|
|
38
|
-
return dt;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// It returns the number of milliseconds since January 1, 1970, 00:00:00 UTC instead of local (regardless of which time zone you are in).
|
|
42
|
-
static createUTCDate(
|
|
43
|
-
year: number,
|
|
44
|
-
monthIndex?: number,
|
|
45
|
-
date?: number,
|
|
46
|
-
hours?: number,
|
|
47
|
-
minutes?: number,
|
|
48
|
-
seconds?: number,
|
|
49
|
-
ms?: number
|
|
50
|
-
): Date {
|
|
51
|
-
const dt = new Date(Date.UTC.apply(null, [year, monthIndex, date, hours, minutes, seconds, ms]));
|
|
52
|
-
return dt;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
static set(
|
|
56
|
-
dt: Date,
|
|
57
|
-
year?: number,
|
|
58
|
-
monthIndex?: number,
|
|
59
|
-
date?: number,
|
|
60
|
-
hours?: number,
|
|
61
|
-
minutes?: number,
|
|
62
|
-
seconds?: number,
|
|
63
|
-
ms?: number
|
|
64
|
-
): Date {
|
|
65
|
-
if (!dt) {
|
|
66
|
-
dt = new Date(DateUtils.now());
|
|
67
|
-
}
|
|
68
|
-
if (typeof year === 'number') {
|
|
69
|
-
dt.setFullYear(year);
|
|
70
|
-
}
|
|
71
|
-
if (typeof monthIndex === 'number') {
|
|
72
|
-
dt.setMonth(monthIndex);
|
|
73
|
-
}
|
|
74
|
-
if (typeof date === 'number') {
|
|
75
|
-
dt.setDate(date);
|
|
76
|
-
}
|
|
77
|
-
if (typeof hours === 'number') {
|
|
78
|
-
dt.setHours(hours);
|
|
79
|
-
}
|
|
80
|
-
if (typeof minutes === 'number') {
|
|
81
|
-
dt.setMinutes(minutes);
|
|
82
|
-
}
|
|
83
|
-
if (typeof seconds === 'number') {
|
|
84
|
-
dt.setSeconds(seconds);
|
|
85
|
-
}
|
|
86
|
-
if (typeof ms === 'number') {
|
|
87
|
-
dt.setMilliseconds(ms);
|
|
88
|
-
}
|
|
89
|
-
return dt;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static add(
|
|
93
|
-
dt: Date,
|
|
94
|
-
year?: number,
|
|
95
|
-
monthCount?: number,
|
|
96
|
-
date?: number,
|
|
97
|
-
hours?: number,
|
|
98
|
-
minutes?: number,
|
|
99
|
-
seconds?: number,
|
|
100
|
-
ms?: number
|
|
101
|
-
): Date {
|
|
102
|
-
if (!dt) {
|
|
103
|
-
dt = new Date(DateUtils.now());
|
|
104
|
-
}
|
|
105
|
-
if (typeof year === 'number') {
|
|
106
|
-
dt.setFullYear(dt.getFullYear() + year);
|
|
107
|
-
}
|
|
108
|
-
if (typeof monthCount === 'number') {
|
|
109
|
-
dt.setMonth(dt.getMonth() + monthCount);
|
|
110
|
-
}
|
|
111
|
-
if (typeof date === 'number') {
|
|
112
|
-
dt.setDate(dt.getDate() + date);
|
|
113
|
-
}
|
|
114
|
-
if (typeof hours === 'number') {
|
|
115
|
-
dt.setHours(dt.getHours() + hours);
|
|
116
|
-
}
|
|
117
|
-
if (typeof minutes === 'number') {
|
|
118
|
-
dt.setMinutes(dt.getMinutes() + minutes);
|
|
119
|
-
}
|
|
120
|
-
if (typeof seconds === 'number') {
|
|
121
|
-
dt.setSeconds(dt.getSeconds() + seconds);
|
|
122
|
-
}
|
|
123
|
-
if (typeof ms === 'number') {
|
|
124
|
-
dt.setMilliseconds(dt.getMilliseconds() + ms);
|
|
125
|
-
}
|
|
126
|
-
return dt;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// returns a difference object from two dates
|
|
130
|
-
static diff(endDate: Date, startDate: Date): DiffDate {
|
|
131
|
-
const startYear = startDate.getFullYear();
|
|
132
|
-
let yearDiff = endDate.getFullYear() - startYear;
|
|
133
|
-
let monthDiff = endDate.getMonth() - startDate.getMonth();
|
|
134
|
-
if (monthDiff < 0) {
|
|
135
|
-
yearDiff--;
|
|
136
|
-
monthDiff += 12;
|
|
137
|
-
}
|
|
138
|
-
let dayDiff = endDate.getDate() - startDate.getDate();
|
|
139
|
-
if (dayDiff < 0) {
|
|
140
|
-
if (monthDiff > 0) {
|
|
141
|
-
monthDiff--;
|
|
142
|
-
} else {
|
|
143
|
-
yearDiff--;
|
|
144
|
-
monthDiff = 11;
|
|
145
|
-
}
|
|
146
|
-
dayDiff += DateUtils.daysInMonth(startYear, startDate.getMonth());
|
|
147
|
-
}
|
|
148
|
-
const msTotal = endDate.valueOf() - startDate.valueOf(); // milliseconds
|
|
149
|
-
const secondTotal = Math.floor(msTotal / 1000); // milliseconds -> seconds
|
|
150
|
-
const hourDiff = Math.floor(secondTotal / (60 * 60)) % 24;
|
|
151
|
-
const minuteDiff = Math.floor(secondTotal / 60) % 60;
|
|
152
|
-
const secondDiff = secondTotal % 60;
|
|
153
|
-
const msDiff = msTotal % 1000;
|
|
154
|
-
return new DiffDate(yearDiff, monthDiff, dayDiff, hourDiff, minuteDiff, secondDiff, msDiff);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// returns a time difference string from two dates
|
|
158
|
-
static diffString(endDate: Date, startDate: Date, printMS = false): string {
|
|
159
|
-
const diff = DateUtils.diff(endDate, startDate);
|
|
160
|
-
let ret = '';
|
|
161
|
-
if (diff.years !== 0) {
|
|
162
|
-
ret = ret + diff.years + ' years(s), ';
|
|
163
|
-
}
|
|
164
|
-
if (diff.years !== 0 || diff.months !== 0) {
|
|
165
|
-
ret = ret + diff.months + ' month(s), ';
|
|
166
|
-
}
|
|
167
|
-
if (diff.years !== 0 || diff.months !== 0 || diff.days !== 0) {
|
|
168
|
-
ret = ret + diff.days + ' day(s), ';
|
|
169
|
-
}
|
|
170
|
-
if (diff.years !== 0 || diff.months !== 0 || diff.days !== 0 || diff.hours !== 0) {
|
|
171
|
-
ret = ret + diff.hours + ' hour(s), ';
|
|
172
|
-
}
|
|
173
|
-
if (diff.years !== 0 || diff.months !== 0 || diff.days !== 0 || diff.hours !== 0 || diff.minutes !== 0) {
|
|
174
|
-
ret = ret + diff.minutes + ' minute(s), ';
|
|
175
|
-
}
|
|
176
|
-
if (
|
|
177
|
-
diff.years !== 0 ||
|
|
178
|
-
diff.months !== 0 ||
|
|
179
|
-
diff.days !== 0 ||
|
|
180
|
-
diff.hours !== 0 ||
|
|
181
|
-
diff.minutes !== 0 ||
|
|
182
|
-
diff.seconds !== 0 ||
|
|
183
|
-
!printMS
|
|
184
|
-
) {
|
|
185
|
-
ret = ret + diff.seconds + ' second(s)';
|
|
186
|
-
if (printMS) {
|
|
187
|
-
ret += ', ';
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (printMS) {
|
|
191
|
-
ret = ret + diff.milliseconds + ' ms';
|
|
192
|
-
}
|
|
193
|
-
return ret;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// returns a YYYYMMDD format string
|
|
197
|
-
static toYMD(dt: Date, separator: string) {
|
|
198
|
-
separator = typeof separator === 'undefined' ? '-' : separator;
|
|
199
|
-
return (
|
|
200
|
-
dt.getFullYear() +
|
|
201
|
-
separator +
|
|
202
|
-
('0' + (dt.getMonth() + 1)).toString().slice(-2) +
|
|
203
|
-
separator +
|
|
204
|
-
('0' + dt.getDate()).toString().slice(-2)
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
static toYmdHms(dt: Date, separator: string) {
|
|
208
|
-
separator = typeof separator === 'undefined' ? '-' : separator;
|
|
209
|
-
return (
|
|
210
|
-
dt.getFullYear() +
|
|
211
|
-
separator +
|
|
212
|
-
('0' + (dt.getMonth() + 1)).toString().slice(-2) +
|
|
213
|
-
separator +
|
|
214
|
-
('0' + dt.getDate()).toString().slice(-2) +
|
|
215
|
-
' ' +
|
|
216
|
-
('0' + dt.getHours()).toString().slice(-2) +
|
|
217
|
-
':' +
|
|
218
|
-
('0' + dt.getMinutes()).toString().slice(-2) +
|
|
219
|
-
':' +
|
|
220
|
-
('0' + dt.getSeconds()).toString().slice(-2)
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
static toJSONString(dt: Date) {
|
|
225
|
-
// return dt.getUTCFullYear() + '-' + ('0' + (dt.getUTCMonth() + 1)).toString().slice(-2) +
|
|
226
|
-
// '-' + ('0' + dt.getUTCDate()).toString().slice(-2) + ' ' + ('0' + dt.getUTCHours()).toString().slice(-2) +
|
|
227
|
-
// ':' + ('0' + dt.getUTCMinutes()).toString().slice(-2) + ':' + ('0' + dt.getUTCSeconds()).toString().slice(-2) + 'Z';
|
|
228
|
-
return dt.toJSON();
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
static showJSONString(dt: string, separator = '-') {
|
|
232
|
-
return DateUtils.toYmdHms(DateUtils.toDate(dt), separator);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
static fromJSONString(dt: string) {
|
|
236
|
-
return DateUtils.toDate(dt);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
static clearTime(dt: Date) {
|
|
240
|
-
dt.setHours(0);
|
|
241
|
-
dt.setMinutes(0);
|
|
242
|
-
dt.setSeconds(0);
|
|
243
|
-
dt.setMilliseconds(0);
|
|
244
|
-
return dt;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
static clearUTCTime(dt: Date) {
|
|
248
|
-
dt.setUTCHours(0);
|
|
249
|
-
dt.setUTCMinutes(0);
|
|
250
|
-
dt.setUTCSeconds(0);
|
|
251
|
-
dt.setUTCMilliseconds(0);
|
|
252
|
-
return dt;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
static format(dt: Date, fmt: string) {
|
|
256
|
-
if (!fmt) {
|
|
257
|
-
fmt = 'YYYY-MM-DD';
|
|
258
|
-
}
|
|
259
|
-
if (!dt) {
|
|
260
|
-
dt = new Date();
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const parts: { [key: string]: string } = {
|
|
264
|
-
YYYY: dt.getFullYear().toString(),
|
|
265
|
-
YY: ('00' + (dt.getFullYear() - 100)).toString().slice(-2),
|
|
266
|
-
MM: ('0' + (dt.getMonth() + 1)).toString().slice(-2),
|
|
267
|
-
M: (dt.getMonth() + 1).toString(),
|
|
268
|
-
DD: ('0' + dt.getDate()).toString().slice(-2),
|
|
269
|
-
D: dt.getDate().toString(),
|
|
270
|
-
hh: ('0' + dt.getHours()).toString().slice(-2),
|
|
271
|
-
h: dt.getHours().toString(),
|
|
272
|
-
mm: ('0' + dt.getMinutes()).toString().slice(-2),
|
|
273
|
-
ss: ('0' + dt.getSeconds()).toString().slice(-2),
|
|
274
|
-
SSS: ('00' + dt.getMilliseconds()).toString().slice(-3),
|
|
275
|
-
S: Math.floor(dt.getMilliseconds() / 100)
|
|
276
|
-
.toString()
|
|
277
|
-
.slice(-1),
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
const array = fmt.match(/(\[[^\[]*\])|(\\)?(YYYY|YY|MM?|DD?|hh?|mm?|ss?|SSS|S|.)/g) as string[];
|
|
281
|
-
for (let i = 0, length = array.length; i < length; i++) {
|
|
282
|
-
if (parts[array[i]]) {
|
|
283
|
-
array[i] = parts[array[i]];
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
const ret = array.join('');
|
|
287
|
-
return ret;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
export class DiffDate {
|
|
292
|
-
years: number;
|
|
293
|
-
months: number;
|
|
294
|
-
days: number;
|
|
295
|
-
hours: number;
|
|
296
|
-
minutes: number;
|
|
297
|
-
seconds: number;
|
|
298
|
-
milliseconds: number;
|
|
299
|
-
|
|
300
|
-
constructor(
|
|
301
|
-
years: number,
|
|
302
|
-
months: number,
|
|
303
|
-
days: number,
|
|
304
|
-
hours: number,
|
|
305
|
-
minutes: number,
|
|
306
|
-
seconds: number,
|
|
307
|
-
milliseconds: number
|
|
308
|
-
) {
|
|
309
|
-
this.years = years;
|
|
310
|
-
this.months = months;
|
|
311
|
-
this.days = days;
|
|
312
|
-
this.hours = hours;
|
|
313
|
-
this.minutes = minutes;
|
|
314
|
-
this.seconds = seconds;
|
|
315
|
-
this.milliseconds = milliseconds;
|
|
316
|
-
}
|
|
317
|
-
}
|
package/src/lib/deep-merge.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simple object check.
|
|
3
|
-
* @param item
|
|
4
|
-
* @returns {boolean}
|
|
5
|
-
*/
|
|
6
|
-
const needMerge = (item: any) => {
|
|
7
|
-
return item && typeof item === 'object' && !Array.isArray(item);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Deep merge two objects.
|
|
12
|
-
* target must be a object, and array will be replaced
|
|
13
|
-
* @param target
|
|
14
|
-
* @param ...sources
|
|
15
|
-
*/
|
|
16
|
-
export const deepMerge = (target: any, ...sources: any[]): any => {
|
|
17
|
-
if (!sources.length) return target;
|
|
18
|
-
const source = sources.shift();
|
|
19
|
-
|
|
20
|
-
if (needMerge(target) && needMerge(source)) {
|
|
21
|
-
for (const key in source) {
|
|
22
|
-
if (needMerge(source[key])) {
|
|
23
|
-
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
24
|
-
deepMerge(target[key], source[key]);
|
|
25
|
-
} else {
|
|
26
|
-
Object.assign(target, { [key]: source[key] });
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return deepMerge(target, ...sources);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// Clone data object only, also defined in core.ts
|
|
35
|
-
export const cloneJson = (json: any) => {
|
|
36
|
-
return JSON.parse(JSON.stringify(json));
|
|
37
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* for my-apps
|
|
3
|
-
*/
|
|
4
|
-
export class DocumentReady {
|
|
5
|
-
constructor() {}
|
|
6
|
-
|
|
7
|
-
// code is from https://code.jquery.com/jquery-1.12.4.js
|
|
8
|
-
// for document only (not for elements)
|
|
9
|
-
ready(fn: Function): void {
|
|
10
|
-
if (document.readyState === 'complete') {
|
|
11
|
-
setTimeout(fn, 0);
|
|
12
|
-
} else {
|
|
13
|
-
// The ready event handler and self cleanup method
|
|
14
|
-
const completed = function () {
|
|
15
|
-
if (document.readyState === 'complete') {
|
|
16
|
-
document.removeEventListener('DOMContentLoaded', completed);
|
|
17
|
-
window.removeEventListener('load', completed);
|
|
18
|
-
setTimeout(fn, 0);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
document.addEventListener('DOMContentLoaded', completed);
|
|
23
|
-
window.addEventListener('load', completed);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
readyPromise(): Promise<void> {
|
|
28
|
-
return new Promise((resolve, reject) => {
|
|
29
|
-
this.ready(() => {
|
|
30
|
-
resolve();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default new DocumentReady();
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param text
|
|
3
|
-
* @param font, sample: italic/normal 19pt Times New Roman
|
|
4
|
-
* @returns width
|
|
5
|
-
*/
|
|
6
|
-
const calculateTextWidthSaved: { canvas: any } = { canvas: null };
|
|
7
|
-
export function calculateTextWidth(text: string, font: string) {
|
|
8
|
-
let canvas = calculateTextWidthSaved.canvas || (calculateTextWidthSaved.canvas = document.createElement('canvas'));
|
|
9
|
-
let context = canvas.getContext('2d');
|
|
10
|
-
context.font = font;
|
|
11
|
-
let metrics = context.measureText(text);
|
|
12
|
-
return metrics.width;
|
|
13
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
const response = await fetch('/api/admin/release/check-log', { ... });
|
|
3
|
-
const blob = await response.blob();
|
|
4
|
-
downloadStream(blob, filename);
|
|
5
|
-
*/
|
|
6
|
-
export const downloadStream = (blob: Blob, filename?: string) => {
|
|
7
|
-
const dom = document.createElement('a');
|
|
8
|
-
dom.setAttribute('href', URL.createObjectURL(blob));
|
|
9
|
-
dom.setAttribute('download', filename || 'true');
|
|
10
|
-
dom.style.display = 'none';
|
|
11
|
-
document.body.appendChild(dom);
|
|
12
|
-
dom.click();
|
|
13
|
-
setTimeout(() => {
|
|
14
|
-
document.body.removeChild(dom);
|
|
15
|
-
}, 3000);
|
|
16
|
-
return dom;
|
|
17
|
-
};
|
package/src/lib/dom/download.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const download = (link: string, filename?: string) => {
|
|
2
|
-
const dom = document.createElement('a');
|
|
3
|
-
dom.setAttribute('href', link);
|
|
4
|
-
dom.setAttribute('download', filename || 'true');
|
|
5
|
-
dom.style.display = 'none';
|
|
6
|
-
document.body.appendChild(dom);
|
|
7
|
-
dom.click();
|
|
8
|
-
setTimeout(() => {
|
|
9
|
-
document.body.removeChild(dom);
|
|
10
|
-
}, 3000);
|
|
11
|
-
return dom;
|
|
12
|
-
};
|
package/src/lib/dom/index.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { calculateTextWidth } from './calculate-text-width';
|
|
2
|
-
import { clearCookie, getCookie, setCookie } from './cookie';
|
|
3
|
-
import { download } from './download';
|
|
4
|
-
import { downloadStream } from './download-stream';
|
|
5
|
-
|
|
6
|
-
export class DomUtils {
|
|
7
|
-
public static calculateTextWidth(text: string, font: string) {
|
|
8
|
-
return calculateTextWidth(text, font);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public static getValue(cssSelector: string) {
|
|
12
|
-
return (document.querySelector(cssSelector) as HTMLInputElement)?.value;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public static setValue(cssSelector: string, value: string) {
|
|
16
|
-
const dom = document.querySelector(cssSelector) as HTMLInputElement;
|
|
17
|
-
if (dom) dom.value = value;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public static getChecked(cssSelector: string) {
|
|
21
|
-
return (document.querySelector(cssSelector) as HTMLInputElement)?.checked;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public static setChecked(cssSelector: string, checked: boolean) {
|
|
25
|
-
const dom = document.querySelector(cssSelector) as HTMLInputElement;
|
|
26
|
-
if (dom) dom.checked = checked;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public static joinValues(values: (string | undefined)[]) {
|
|
30
|
-
return values.filter((item) => item && item !== '').join(' ');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public static setCookie(
|
|
34
|
-
name: string,
|
|
35
|
-
value: string,
|
|
36
|
-
expireDays = 365,
|
|
37
|
-
path?: string,
|
|
38
|
-
domain?: string,
|
|
39
|
-
secure?: string
|
|
40
|
-
) {
|
|
41
|
-
return setCookie(name, value, expireDays, path, domain, secure);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public static getCookie(key: string) {
|
|
45
|
-
return getCookie(key);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public static clearCookie(name: string, path?: string, domain?: string, secure?: string) {
|
|
49
|
-
return clearCookie(name, path, domain, secure);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public static download(link: string, filename?: string) {
|
|
53
|
-
return download(link, filename);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public static downloadStream(blob: Blob, filename?: string) {
|
|
57
|
-
return downloadStream(blob, filename);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public static byId(id: string) {
|
|
61
|
-
return document.querySelector(`#${id}`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public static byCssPath(cssPath: string) {
|
|
65
|
-
return document.querySelector(cssPath);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public static bySelector(selector: string) {
|
|
69
|
-
return document.querySelector(selector);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* for my-apps
|
|
3
|
-
*/
|
|
4
|
-
export class DynamicalLoad {
|
|
5
|
-
constructor() {}
|
|
6
|
-
|
|
7
|
-
loadScript(url: string, idForReplace?: string, removeOnLoaded = false): Promise<string> {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
if (this.existScript(url, idForReplace)) {
|
|
10
|
-
resolve(url);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const scriptDom = document.createElement('script');
|
|
14
|
-
scriptDom.src = url;
|
|
15
|
-
if (idForReplace) {
|
|
16
|
-
scriptDom.id = idForReplace;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
scriptDom.onload = () => {
|
|
20
|
-
resolve(url);
|
|
21
|
-
if (removeOnLoaded) {
|
|
22
|
-
scriptDom.remove();
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
scriptDom.onerror = () => {
|
|
27
|
-
reject(new Error('Failed to load module script with URL ' + url));
|
|
28
|
-
if (removeOnLoaded) {
|
|
29
|
-
scriptDom.remove();
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const head = document.getElementsByTagName('head')[0];
|
|
34
|
-
head ? head.appendChild(scriptDom) : document.documentElement.appendChild(scriptDom);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// TODO: more accuracy
|
|
39
|
-
existScript(url: string, id?: string) {
|
|
40
|
-
if (id) {
|
|
41
|
-
const scriptDom = document.getElementById(id);
|
|
42
|
-
if (scriptDom && scriptDom.tagName === 'SCRIPT') {
|
|
43
|
-
const src = (scriptDom as HTMLScriptElement).src.split('?')[0];
|
|
44
|
-
if (src.substring(src.length - url.length) === url) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const scripts = document.scripts;
|
|
51
|
-
for (let i = 0; i < scripts.length; i++) {
|
|
52
|
-
const src = scripts[i].src.split('?')[0];
|
|
53
|
-
if (src.substring(src.length - url.length) === url) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
loadCss(url: string, idForReplace?: string): Promise<string> {
|
|
60
|
-
return new Promise((resolve, reject) => {
|
|
61
|
-
if (this.existCss(url, idForReplace)) {
|
|
62
|
-
resolve(url);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (idForReplace) {
|
|
66
|
-
const sheet = document.getElementById(idForReplace);
|
|
67
|
-
if (sheet && sheet.tagName === 'LINK') {
|
|
68
|
-
sheet.parentNode!.removeChild(sheet);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const linkDom = document.createElement('link');
|
|
73
|
-
linkDom.rel = 'stylesheet';
|
|
74
|
-
linkDom.type = 'text/css';
|
|
75
|
-
linkDom.href = url;
|
|
76
|
-
linkDom.media = 'all';
|
|
77
|
-
if (idForReplace) {
|
|
78
|
-
linkDom.id = idForReplace;
|
|
79
|
-
}
|
|
80
|
-
linkDom.onload = () => {
|
|
81
|
-
resolve(url);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
linkDom.onerror = () => {
|
|
85
|
-
reject(new Error('Failed to load css with URL ' + url));
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
document.getElementsByTagName('head')[0].appendChild(linkDom);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// TODO: more accuracy
|
|
93
|
-
existCss(url: string, id?: string) {
|
|
94
|
-
if (id) {
|
|
95
|
-
const linkDom = document.getElementById(id);
|
|
96
|
-
if (linkDom && linkDom.tagName === 'LINK') {
|
|
97
|
-
const href = (<any>linkDom).href.split('?')[0];
|
|
98
|
-
if (href.substring(href.length - url.length) === url) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const styles = document.styleSheets;
|
|
105
|
-
for (let i = 0; i < styles.length; i++) {
|
|
106
|
-
const linkDom = styles[i] as any;
|
|
107
|
-
const href = linkDom.href.split('?')[0];
|
|
108
|
-
if (href.substring(href.length - url.length) === url) {
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// removeCss(url: string, id?: string) {
|
|
115
|
-
// if (id) {
|
|
116
|
-
// const sheet = document.getElementById(id);
|
|
117
|
-
// if (sheet && sheet instanceof HTMLElement) {
|
|
118
|
-
// const href = (<any>sheet).href;
|
|
119
|
-
// if (href.substring(href.length - url.length) === url) {
|
|
120
|
-
// (<any>sheet).disabled = true;
|
|
121
|
-
// sheet.parentNode.removeChild(sheet);
|
|
122
|
-
// return;
|
|
123
|
-
// }
|
|
124
|
-
// }
|
|
125
|
-
// }
|
|
126
|
-
// const styles = document.styleSheets;
|
|
127
|
-
// for (const i = 0; i < styles.length; i++) {
|
|
128
|
-
// const sheet = styles[i] as any;
|
|
129
|
-
// if (sheet.href.substring(sheet.href.length - url.length) === url) {
|
|
130
|
-
// sheet.disabled = true;
|
|
131
|
-
// sheet.ownerNode.parentNode.removeChild(sheet.ownerNode);
|
|
132
|
-
// return;
|
|
133
|
-
// }
|
|
134
|
-
// }
|
|
135
|
-
// }
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export default new DynamicalLoad();
|
package/src/lib/format-bytes.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const formatBytes = (bytes: number, decimals = 2) => {
|
|
2
|
-
if (!+bytes) return '0 Bytes';
|
|
3
|
-
|
|
4
|
-
const k = 1024;
|
|
5
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
6
|
-
const sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
|
7
|
-
|
|
8
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
9
|
-
|
|
10
|
-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
11
|
-
};
|