lupine.web 1.0.15 → 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.
Files changed (78) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -5
  3. package/src/core/bind-lang.ts +6 -5
  4. package/src/core/bind-links.ts +2 -2
  5. package/src/core/bind-meta.tsx +52 -0
  6. package/src/core/bind-theme.ts +11 -9
  7. package/src/core/export-lupine.ts +64 -0
  8. package/src/core/index.ts +3 -1
  9. package/src/core/{core.ts → initialize.ts} +12 -79
  10. package/src/core/page-router.ts +3 -2
  11. package/src/core/server-cookie.ts +5 -3
  12. package/src/index.ts +2 -3
  13. package/src/lib/index.ts +2 -13
  14. package/src/lib/is-frontend.ts +3 -0
  15. package/src/models/index.ts +2 -0
  16. package/src/models/json-props.ts +8 -0
  17. package/src/models/theme-props.ts +7 -0
  18. package/src/{types → styles}/index.ts +0 -2
  19. package/src/assets/themes/base-themes.ts +0 -16
  20. package/src/assets/themes/dark-themes.ts +0 -85
  21. package/src/assets/themes/index.ts +0 -4
  22. package/src/assets/themes/light-themes.ts +0 -92
  23. package/src/assets/themes/shared-themes.ts +0 -50
  24. package/src/components/button-push-animation.tsx +0 -138
  25. package/src/components/button.tsx +0 -55
  26. package/src/components/drag-refresh.tsx +0 -110
  27. package/src/components/editable-label.tsx +0 -83
  28. package/src/components/float-window.tsx +0 -226
  29. package/src/components/grid.tsx +0 -18
  30. package/src/components/html-var.tsx +0 -41
  31. package/src/components/index.ts +0 -36
  32. package/src/components/input-with-title.tsx +0 -24
  33. package/src/components/link-item.tsx +0 -13
  34. package/src/components/link-list.tsx +0 -62
  35. package/src/components/menu-bar.tsx +0 -220
  36. package/src/components/menu-item-props.tsx +0 -10
  37. package/src/components/menu-sidebar.tsx +0 -289
  38. package/src/components/message-box.tsx +0 -44
  39. package/src/components/meta-data.tsx +0 -54
  40. package/src/components/meta-description.tsx +0 -19
  41. package/src/components/meta-title.tsx +0 -19
  42. package/src/components/modal.tsx +0 -29
  43. package/src/components/notice-message.tsx +0 -119
  44. package/src/components/paging-link.tsx +0 -100
  45. package/src/components/panel.tsx +0 -24
  46. package/src/components/popup-menu.tsx +0 -218
  47. package/src/components/progress.tsx +0 -91
  48. package/src/components/redirect.tsx +0 -19
  49. package/src/components/resizable-splitter.tsx +0 -129
  50. package/src/components/select-with-title.tsx +0 -37
  51. package/src/components/spinner.tsx +0 -100
  52. package/src/components/svg.tsx +0 -24
  53. package/src/components/tabs.tsx +0 -252
  54. package/src/components/text-glow.tsx +0 -36
  55. package/src/components/text-wave.tsx +0 -54
  56. package/src/components/theme-selector.tsx +0 -35
  57. package/src/components/toggle-base.tsx +0 -260
  58. package/src/components/toggle-switch.tsx +0 -156
  59. package/src/lib/date-utils.ts +0 -317
  60. package/src/lib/deep-merge.ts +0 -37
  61. package/src/lib/document-ready.ts +0 -36
  62. package/src/lib/dom/calculate-text-width.ts +0 -13
  63. package/src/lib/dom/download-stream.ts +0 -17
  64. package/src/lib/dom/download.ts +0 -12
  65. package/src/lib/dom/index.ts +0 -71
  66. package/src/lib/dynamical-load.ts +0 -138
  67. package/src/lib/format-bytes.ts +0 -11
  68. package/src/lib/lite-dom.ts +0 -227
  69. package/src/lib/message-hub.ts +0 -105
  70. package/src/lib/observable.ts +0 -188
  71. package/src/lib/promise-timeout.ts +0 -1
  72. package/src/lib/simple-storage.ts +0 -40
  73. package/src/lib/stop-propagation.ts +0 -7
  74. package/src/lib/upload-file.ts +0 -68
  75. package/src/types/css-types.ts +0 -17
  76. package/src/types/media-query.ts +0 -93
  77. /package/src/lib/{dom/cookie.ts → cookie.ts} +0 -0
  78. /package/src/{types → styles}/css-styles.ts +0 -0
@@ -1,156 +0,0 @@
1
- import { bindGlobalStyles, CssProps } from 'lupine.web';
2
- import { ToggleBase, ToggleBaseHookProps } from './toggle-base';
3
-
4
- export enum ToggleSwitchSize {
5
- SmallSmall = 'smallsmall',
6
- Small = 'small',
7
- Medium = 'medium',
8
- Large = 'large',
9
- }
10
- export type ToggleSwitchProps = {
11
- size: ToggleSwitchSize;
12
- text?: { on: string; off: string };
13
- textWidth?: string;
14
- disabled?: boolean;
15
- checked?: boolean;
16
- onClick?: (checked: boolean) => void;
17
- hook?: ToggleBaseHookProps;
18
- };
19
- export const ToggleSwitch = (props: ToggleSwitchProps) => {
20
- const sizeH =
21
- props.size === ToggleSwitchSize.SmallSmall
22
- ? 16
23
- : props.size === ToggleSwitchSize.Small
24
- ? 22
25
- : props.size === ToggleSwitchSize.Large
26
- ? 42
27
- : 34;
28
- const cssSize =
29
- props.size === ToggleSwitchSize.SmallSmall
30
- ? 'smallsmall'
31
- : props.size === ToggleSwitchSize.Small
32
- ? 'small'
33
- : props.size === ToggleSwitchSize.Large
34
- ? 'large'
35
- : '';
36
-
37
- const css: CssProps = {
38
- width: `100%`,
39
- height: `100%`,
40
- display: 'flex',
41
- alignItems: 'center',
42
- justifyContent: 'center',
43
- '& .ts-slider': {
44
- position: 'relative',
45
- cursor: 'pointer',
46
- backgroundColor: 'var(--toggle-background-color, #c7c7c7)',
47
- transition: '.4s',
48
- borderRadius: '34px',
49
- height: '100%',
50
- display: 'flex',
51
- padding: '0 27px 0 37px',
52
- alignItems: 'center',
53
- },
54
- '&.smallsmall .ts-slider': {
55
- padding: '0 8px 0 22px',
56
- fontSize: '0.65rem',
57
- },
58
- '&.small .ts-slider': {
59
- padding: '0 17px 0 27px',
60
- fontSize: '0.85rem',
61
- },
62
- '&.large .ts-slider': {
63
- padding: '0 37px 0 57px',
64
- },
65
-
66
- '& .ts-slider .ts-circle': {
67
- position: 'absolute',
68
- content: '',
69
- height: '26px',
70
- width: '26px',
71
- left: '4px',
72
- bottom: '4px',
73
- backgroundColor: 'var(--toggle-ball-color, #fff)',
74
- transition: '.4s',
75
- borderRadius: '50%',
76
- },
77
- '&.smallsmall .ts-slider .ts-circle': {
78
- height: '12px',
79
- width: '12px',
80
- left: '2px',
81
- bottom: '2px',
82
- },
83
- '&.small .ts-slider .ts-circle': {
84
- height: '18px',
85
- width: '18px',
86
- left: '3px',
87
- bottom: '2px',
88
- },
89
- '&.large .ts-slider .ts-circle': {
90
- height: '38px',
91
- width: '38px',
92
- left: '4px',
93
- bottom: '2px',
94
- },
95
-
96
- '& .ts-on-text, & .ts-off-text': {
97
- display: 'none',
98
- width: props.textWidth,
99
- },
100
- '&.toggle-on .ts-on-text': {
101
- display: 'block',
102
- },
103
- '&.toggle-off .ts-off-text': {
104
- display: 'block',
105
- },
106
-
107
- '&.toggle-on .ts-slider': {
108
- backgroundColor: 'var(--primary-accent-color, #0a74c9)',
109
- padding: '0 47px 0 17px',
110
- },
111
- '&.smallsmall.toggle-on .ts-slider': {
112
- padding: '0 18px 0 12px',
113
- },
114
- '&.small.toggle-on .ts-slider': {
115
- padding: '0 27px 0 17px',
116
- },
117
- '&.large.toggle-on .ts-slider': {
118
- padding: '0 72px 0 22px',
119
- },
120
-
121
- '&.toggle-on .ts-slider .ts-circle': {
122
- left: 'unset',
123
- right: '3px',
124
- },
125
- '&.disabled .ts-slider': {
126
- cursor: 'not-allowed',
127
- opacity: 'var(--primary-disabled-opacity)',
128
- },
129
- };
130
-
131
- // this is a sample to add variables for a theme
132
- const cssTheme: CssProps = {
133
- '[data-theme="dark" i]': {
134
- '--toggle-ball-color': '#000000',
135
- '--toggle-background-color': '#262626',
136
- },
137
- };
138
-
139
- bindGlobalStyles('toggle-switch-theme', '', cssTheme);
140
- return (
141
- <ToggleBase {...props} size={{ w: 'auto', h: sizeH }}>
142
- <div
143
- css={css}
144
- class={`toggle-switch-component toggle-placeholder ${props.checked ? 'toggle-on' : 'toggle-off'}${
145
- props.disabled ? ' disabled' : ''
146
- } ${cssSize}`}
147
- >
148
- <span class='ts-slider'>
149
- <span class='ts-on-text'>{props.text?.on}</span>
150
- <span class='ts-circle'></span>
151
- <span class='ts-off-text'>{props.text?.off}</span>
152
- </span>
153
- </div>
154
- </ToggleBase>
155
- );
156
- };
@@ -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
- }
@@ -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
- };
@@ -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
- };
@@ -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
- }