ly-utils-lib 1.0.11 → 2.4.0
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/LICENSE +21 -0
- package/README.md +889 -686
- package/dist/array.cjs +237 -0
- package/dist/array.cjs.map +1 -0
- package/dist/array.d.cts +2 -0
- package/dist/array.d.ts +2 -0
- package/dist/array.js +150 -0
- package/dist/array.js.map +1 -0
- package/dist/crypto.cjs +193 -0
- package/dist/crypto.cjs.map +1 -0
- package/dist/crypto.d.cts +3 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.js +144 -0
- package/dist/crypto.js.map +1 -0
- package/dist/date.cjs +563 -0
- package/dist/date.cjs.map +1 -0
- package/dist/date.d.cts +2 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +451 -0
- package/dist/date.js.map +1 -0
- package/dist/excel.cjs +227 -0
- package/dist/excel.cjs.map +1 -0
- package/dist/excel.d.cts +2 -0
- package/dist/excel.d.ts +2 -0
- package/dist/excel.js +196 -0
- package/dist/excel.js.map +1 -0
- package/dist/index-B80SEVzM.d.cts +382 -0
- package/dist/index-B80SEVzM.d.ts +382 -0
- package/dist/index-Ba1rjTzj.d.cts +299 -0
- package/dist/index-Ba1rjTzj.d.ts +299 -0
- package/dist/index-Bg1ise7y.d.cts +253 -0
- package/dist/index-Bg1ise7y.d.ts +253 -0
- package/dist/index-BoqNpwNa.d.cts +203 -0
- package/dist/index-BoqNpwNa.d.ts +203 -0
- package/dist/index-C0qUnb9Y.d.cts +533 -0
- package/dist/index-C0qUnb9Y.d.ts +533 -0
- package/dist/index-Cy-mb5v_.d.cts +262 -0
- package/dist/index-Cy-mb5v_.d.ts +262 -0
- package/dist/index-D1f9Sym2.d.cts +148 -0
- package/dist/index-D1f9Sym2.d.ts +148 -0
- package/dist/index-Dan5oF-5.d.cts +213 -0
- package/dist/index-Dan5oF-5.d.ts +213 -0
- package/dist/index-XABfrs7z.d.cts +596 -0
- package/dist/index-XABfrs7z.d.ts +596 -0
- package/dist/index-YXWfKCK7.d.cts +109 -0
- package/dist/index-YXWfKCK7.d.ts +109 -0
- package/dist/index.cjs +3355 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +3294 -0
- package/dist/index.js.map +1 -0
- package/dist/map.cjs +839 -0
- package/dist/map.cjs.map +1 -0
- package/dist/map.d.cts +6 -0
- package/dist/map.d.ts +6 -0
- package/dist/map.js +811 -0
- package/dist/map.js.map +1 -0
- package/dist/object.cjs +316 -0
- package/dist/object.cjs.map +1 -0
- package/dist/object.d.cts +2 -0
- package/dist/object.d.ts +2 -0
- package/dist/object.js +247 -0
- package/dist/object.js.map +1 -0
- package/dist/pdf.cjs +197 -0
- package/dist/pdf.cjs.map +1 -0
- package/dist/pdf.d.cts +3 -0
- package/dist/pdf.d.ts +3 -0
- package/dist/pdf.js +173 -0
- package/dist/pdf.js.map +1 -0
- package/dist/storage.cjs +255 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +1 -0
- package/dist/storage.d.ts +1 -0
- package/dist/storage.js +226 -0
- package/dist/storage.js.map +1 -0
- package/dist/string.cjs +232 -0
- package/dist/string.cjs.map +1 -0
- package/dist/string.d.cts +2 -0
- package/dist/string.d.ts +2 -0
- package/dist/string.js +170 -0
- package/dist/string.js.map +1 -0
- package/dist/utils.cjs +429 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +2 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +371 -0
- package/dist/utils.js.map +1 -0
- package/package.json +159 -33
- package/dist/ly-utils-lib.cjs.js +0 -52929
- package/dist/ly-utils-lib.cjs.js.map +0 -1
- package/dist/ly-utils-lib.es.js +0 -69623
- package/dist/ly-utils-lib.es.js.map +0 -1
- package/dist/ly-utils-lib.umd.js +0 -53314
- package/dist/ly-utils-lib.umd.js.map +0 -1
- package/dist/types/index.d.ts +0 -15
- package/dist/types/utils/esToolkit.d.ts +0 -12
- package/dist/types/utils/ol.d.ts +0 -181
- package/dist/types/utils/router.d.ts +0 -15
- package/dist/types/utils/storage.d.ts +0 -42
- package/dist/types/utils/time.d.ts +0 -76
- package/dist/types/utils/tool.d.ts +0 -86
- package/dist/vite.svg +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,3294 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
export { default as dayjs } from 'dayjs';
|
|
3
|
+
import durationPlugin from 'dayjs/plugin/duration';
|
|
4
|
+
import isBetweenPlugin from 'dayjs/plugin/isBetween';
|
|
5
|
+
import isSameOrAfterPlugin from 'dayjs/plugin/isSameOrAfter';
|
|
6
|
+
import isSameOrBeforePlugin from 'dayjs/plugin/isSameOrBefore';
|
|
7
|
+
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
|
|
8
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
9
|
+
import timezone from 'dayjs/plugin/timezone';
|
|
10
|
+
import utc from 'dayjs/plugin/utc';
|
|
11
|
+
import weekOfYear from 'dayjs/plugin/weekOfYear';
|
|
12
|
+
import weekYear from 'dayjs/plugin/weekYear';
|
|
13
|
+
import isLeapYearPlugin from 'dayjs/plugin/isLeapYear';
|
|
14
|
+
import dayOfYear from 'dayjs/plugin/dayOfYear';
|
|
15
|
+
import minMax from 'dayjs/plugin/minMax';
|
|
16
|
+
import weekday from 'dayjs/plugin/weekday';
|
|
17
|
+
import 'dayjs/locale/zh-cn';
|
|
18
|
+
import { uniqBy, uniq, sum, sortBy, sample, omit, last, isEqual, intersection, head, groupBy, flattenDeep, flatten, difference, compact, chunk, upperFirst, trim, startCase, snakeCase, lowerFirst, kebabCase, capitalize, camelCase, pick, merge, isEmptyObject, invert, cloneDeep, throttle, debounce } from 'es-toolkit';
|
|
19
|
+
import * as XLSX from 'xlsx';
|
|
20
|
+
import html2canvas from 'html2canvas';
|
|
21
|
+
import { jsPDF } from 'jspdf';
|
|
22
|
+
import { Map as Map$1, View, Feature } from 'ol';
|
|
23
|
+
import { defaults, ScaleLine, FullScreen } from 'ol/control';
|
|
24
|
+
import { Point, LineString, Polygon } from 'ol/geom';
|
|
25
|
+
import { Draw, Snap, Modify, Select } from 'ol/interaction';
|
|
26
|
+
import Overlay from 'ol/Overlay';
|
|
27
|
+
import TileLayer from 'ol/layer/Tile';
|
|
28
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
29
|
+
import { fromLonLat, transform, toLonLat } from 'ol/proj';
|
|
30
|
+
import OSM from 'ol/source/OSM';
|
|
31
|
+
import VectorSource from 'ol/source/Vector';
|
|
32
|
+
import XYZ from 'ol/source/XYZ';
|
|
33
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
34
|
+
import { Style, Icon, Circle, Stroke, Fill } from 'ol/style';
|
|
35
|
+
import { boundingExtent } from 'ol/extent';
|
|
36
|
+
import Cookies from 'js-cookie';
|
|
37
|
+
import * as CryptoJS from 'crypto-js';
|
|
38
|
+
|
|
39
|
+
var __defProp = Object.defineProperty;
|
|
40
|
+
var __export = (target, all) => {
|
|
41
|
+
for (var name in all)
|
|
42
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/modules/date/index.ts
|
|
46
|
+
var date_exports = {};
|
|
47
|
+
__export(date_exports, {
|
|
48
|
+
add: () => add,
|
|
49
|
+
clone: () => clone,
|
|
50
|
+
compare: () => compare,
|
|
51
|
+
computeDate: () => computeDate,
|
|
52
|
+
dayjs: () => dayjs,
|
|
53
|
+
default: () => date_default,
|
|
54
|
+
diff: () => diff,
|
|
55
|
+
diffDays: () => diffDays,
|
|
56
|
+
diffHours: () => diffHours,
|
|
57
|
+
endDate: () => endDate,
|
|
58
|
+
endOf: () => endOf,
|
|
59
|
+
format: () => format,
|
|
60
|
+
formatDuration: () => formatDuration,
|
|
61
|
+
formatTimestamp: () => formatTimestamp,
|
|
62
|
+
fromNow: () => fromNow,
|
|
63
|
+
fromUTC: () => fromUTC,
|
|
64
|
+
fromUnix: () => fromUnix,
|
|
65
|
+
getAge: () => getAge,
|
|
66
|
+
getChineseYear: () => getChineseYear,
|
|
67
|
+
getDate: () => getDate,
|
|
68
|
+
getDateRange: () => getDateRange,
|
|
69
|
+
getDay: () => getDay,
|
|
70
|
+
getDayOfYear: () => getDayOfYear,
|
|
71
|
+
getDaysInMonth: () => getDaysInMonth,
|
|
72
|
+
getFirstDayOfMonth: () => getFirstDayOfMonth,
|
|
73
|
+
getFirstDayOfMonthDate: () => getFirstDayOfMonthDate,
|
|
74
|
+
getFirstDayOfWeek: () => getFirstDayOfWeek,
|
|
75
|
+
getFirstDayOfYear: () => getFirstDayOfYear,
|
|
76
|
+
getHolidayName: () => getHolidayName,
|
|
77
|
+
getHour: () => getHour,
|
|
78
|
+
getLastDayOfMonth: () => getLastDayOfMonth,
|
|
79
|
+
getLastDayOfMonthDate: () => getLastDayOfMonthDate,
|
|
80
|
+
getLastDayOfWeek: () => getLastDayOfWeek,
|
|
81
|
+
getLastDayOfYear: () => getLastDayOfYear,
|
|
82
|
+
getMinute: () => getMinute,
|
|
83
|
+
getMonth: () => getMonth,
|
|
84
|
+
getMonthRange: () => getMonthRange,
|
|
85
|
+
getQuarter: () => getQuarter,
|
|
86
|
+
getQuarterRange: () => getQuarterRange,
|
|
87
|
+
getRangeDate: () => getRangeDate,
|
|
88
|
+
getRecentDays: () => getRecentDays,
|
|
89
|
+
getRecentMonths: () => getRecentMonths,
|
|
90
|
+
getRecentWeeks: () => getRecentWeeks,
|
|
91
|
+
getRelativeTime: () => getRelativeTime,
|
|
92
|
+
getSecond: () => getSecond,
|
|
93
|
+
getTime: () => getTime,
|
|
94
|
+
getTimeOfDay: () => getTimeOfDay,
|
|
95
|
+
getTimeOfDayName: () => getTimeOfDayName,
|
|
96
|
+
getTimestamp: () => getTimestamp,
|
|
97
|
+
getTimezoneOffset: () => getTimezoneOffset,
|
|
98
|
+
getWeek: () => getWeek,
|
|
99
|
+
getWeekRange: () => getWeekRange,
|
|
100
|
+
getWeekday: () => getWeekday,
|
|
101
|
+
getWeekdayName: () => getWeekdayName,
|
|
102
|
+
getWorkdaysBetween: () => getWorkdaysBetween,
|
|
103
|
+
getYear: () => getYear,
|
|
104
|
+
getYearRange: () => getYearRange,
|
|
105
|
+
getZodiacSign: () => getZodiacSign,
|
|
106
|
+
isAfter: () => isAfter,
|
|
107
|
+
isBefore: () => isBefore,
|
|
108
|
+
isBetween: () => isBetween,
|
|
109
|
+
isHoliday: () => isHoliday,
|
|
110
|
+
isLeapYear: () => isLeapYear,
|
|
111
|
+
isSame: () => isSame,
|
|
112
|
+
isSameMonth: () => isSameMonth,
|
|
113
|
+
isSameOrAfter: () => isSameOrAfter,
|
|
114
|
+
isSameOrBefore: () => isSameOrBefore,
|
|
115
|
+
isSameYear: () => isSameYear,
|
|
116
|
+
isThisMonth: () => isThisMonth,
|
|
117
|
+
isThisWeek: () => isThisWeek,
|
|
118
|
+
isThisYear: () => isThisYear,
|
|
119
|
+
isToday: () => isToday,
|
|
120
|
+
isTomorrow: () => isTomorrow,
|
|
121
|
+
isValid: () => isValid,
|
|
122
|
+
isWeekend: () => isWeekend,
|
|
123
|
+
isWorkday: () => isWorkday,
|
|
124
|
+
isYesterday: () => isYesterday,
|
|
125
|
+
maxDate: () => maxDate,
|
|
126
|
+
minDate: () => minDate,
|
|
127
|
+
now: () => now,
|
|
128
|
+
parse: () => parse,
|
|
129
|
+
startDate: () => startDate,
|
|
130
|
+
startOf: () => startOf,
|
|
131
|
+
subtract: () => subtract,
|
|
132
|
+
toNow: () => toNow,
|
|
133
|
+
toTimezone: () => toTimezone,
|
|
134
|
+
toUTC: () => toUTC,
|
|
135
|
+
unix: () => unix,
|
|
136
|
+
valueOf: () => valueOf
|
|
137
|
+
});
|
|
138
|
+
dayjs.extend(relativeTime);
|
|
139
|
+
dayjs.extend(utc);
|
|
140
|
+
dayjs.extend(timezone);
|
|
141
|
+
dayjs.extend(durationPlugin);
|
|
142
|
+
dayjs.extend(isBetweenPlugin);
|
|
143
|
+
dayjs.extend(isSameOrBeforePlugin);
|
|
144
|
+
dayjs.extend(isSameOrAfterPlugin);
|
|
145
|
+
dayjs.extend(weekOfYear);
|
|
146
|
+
dayjs.extend(weekYear);
|
|
147
|
+
dayjs.extend(quarterOfYear);
|
|
148
|
+
dayjs.extend(isLeapYearPlugin);
|
|
149
|
+
dayjs.extend(dayOfYear);
|
|
150
|
+
dayjs.extend(minMax);
|
|
151
|
+
dayjs.extend(weekday);
|
|
152
|
+
dayjs.locale("zh-cn");
|
|
153
|
+
var now = () => dayjs();
|
|
154
|
+
var format = (date, formatStr = "YYYY-MM-DD HH:mm:ss") => {
|
|
155
|
+
return dayjs(date).format(formatStr);
|
|
156
|
+
};
|
|
157
|
+
var getDate = (date = /* @__PURE__ */ new Date()) => {
|
|
158
|
+
return dayjs(date).format("YYYY-MM-DD");
|
|
159
|
+
};
|
|
160
|
+
var getTime = (date = /* @__PURE__ */ new Date()) => {
|
|
161
|
+
return dayjs(date).format("HH:mm:ss");
|
|
162
|
+
};
|
|
163
|
+
var getTimestamp = (date = /* @__PURE__ */ new Date()) => {
|
|
164
|
+
return dayjs(date).valueOf();
|
|
165
|
+
};
|
|
166
|
+
var add = (date, amount, unit = "day") => {
|
|
167
|
+
return dayjs(date).add(amount, unit);
|
|
168
|
+
};
|
|
169
|
+
var subtract = (date, amount, unit = "day") => {
|
|
170
|
+
return dayjs(date).subtract(amount, unit);
|
|
171
|
+
};
|
|
172
|
+
var startOf = (date, unit = "day") => {
|
|
173
|
+
return dayjs(date).startOf(unit);
|
|
174
|
+
};
|
|
175
|
+
var endOf = (date, unit = "day") => {
|
|
176
|
+
return dayjs(date).endOf(unit);
|
|
177
|
+
};
|
|
178
|
+
var diffDays = (date1, date2) => {
|
|
179
|
+
return dayjs(date1).diff(dayjs(date2), "day");
|
|
180
|
+
};
|
|
181
|
+
var diffHours = (date1, date2) => {
|
|
182
|
+
return dayjs(date1).diff(dayjs(date2), "hour");
|
|
183
|
+
};
|
|
184
|
+
var isToday = (date) => {
|
|
185
|
+
return dayjs(date).isSame(dayjs(), "day");
|
|
186
|
+
};
|
|
187
|
+
var isYesterday = (date) => {
|
|
188
|
+
return dayjs(date).isSame(dayjs().subtract(1, "day"), "day");
|
|
189
|
+
};
|
|
190
|
+
var isTomorrow = (date) => {
|
|
191
|
+
return dayjs(date).isSame(dayjs().add(1, "day"), "day");
|
|
192
|
+
};
|
|
193
|
+
var isBetween = (date, startDate2, endDate2) => {
|
|
194
|
+
return dayjs(date).isBetween(startDate2, endDate2, null, "[]");
|
|
195
|
+
};
|
|
196
|
+
var fromNow = (date) => {
|
|
197
|
+
return dayjs(date).fromNow();
|
|
198
|
+
};
|
|
199
|
+
var getWeek = (date = /* @__PURE__ */ new Date()) => {
|
|
200
|
+
return dayjs(date).week();
|
|
201
|
+
};
|
|
202
|
+
var computeDate = (compute, date = /* @__PURE__ */ new Date(), type = "day", num = 1, format2 = "YYYY-MM-DD") => {
|
|
203
|
+
const d = dayjs(date);
|
|
204
|
+
if (compute === "after") {
|
|
205
|
+
return d.add(num, type).format(format2);
|
|
206
|
+
}
|
|
207
|
+
if (compute === "before") {
|
|
208
|
+
return d.subtract(num, type).format(format2);
|
|
209
|
+
}
|
|
210
|
+
return d.format(format2);
|
|
211
|
+
};
|
|
212
|
+
var startDate = (type = "month", format2 = "YYYY-MM-DD") => {
|
|
213
|
+
return dayjs().startOf(type).format(format2);
|
|
214
|
+
};
|
|
215
|
+
var endDate = (type = "month", format2 = "YYYY-MM-DD") => {
|
|
216
|
+
return dayjs().endOf(type).format(format2);
|
|
217
|
+
};
|
|
218
|
+
var formatTimestamp = (timestamp = 0, format2 = "YYYY-MM-DD HH:mm:ss") => {
|
|
219
|
+
const ts = timestamp === 0 ? getTimestamp() / 1e3 : timestamp;
|
|
220
|
+
return dayjs.unix(ts).format(format2);
|
|
221
|
+
};
|
|
222
|
+
var diff = (type, startDate2, endDate2 = /* @__PURE__ */ new Date()) => {
|
|
223
|
+
return dayjs(endDate2).diff(dayjs(startDate2), type);
|
|
224
|
+
};
|
|
225
|
+
var getRangeDate = (startDate2, endDate2, format2 = "YYYY-MM-DD") => {
|
|
226
|
+
const diffDays2 = diff("day", startDate2, endDate2);
|
|
227
|
+
const range = [];
|
|
228
|
+
for (let i = 0; i <= diffDays2; i++) {
|
|
229
|
+
const day = computeDate("after", startDate2, "day", i, format2);
|
|
230
|
+
range.push({
|
|
231
|
+
day,
|
|
232
|
+
timestamp: getTimestamp(day) / 1e3
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return range;
|
|
236
|
+
};
|
|
237
|
+
var getRelativeTime = (date) => {
|
|
238
|
+
const diffMinutes = diff("minute", date);
|
|
239
|
+
if (diffMinutes < 1) {
|
|
240
|
+
return "\u521A\u521A";
|
|
241
|
+
}
|
|
242
|
+
if (diffMinutes < 60) {
|
|
243
|
+
return `${diffMinutes}\u5206\u949F\u524D`;
|
|
244
|
+
}
|
|
245
|
+
if (diffMinutes < 1440) {
|
|
246
|
+
return `${Math.floor(diffMinutes / 60)}\u5C0F\u65F6\u524D`;
|
|
247
|
+
}
|
|
248
|
+
if (diffMinutes < 43200) {
|
|
249
|
+
return `${Math.floor(diffMinutes / 1440)}\u5929\u524D`;
|
|
250
|
+
}
|
|
251
|
+
return format(date, "YYYY-MM-DD");
|
|
252
|
+
};
|
|
253
|
+
var isValid = (date) => {
|
|
254
|
+
return dayjs(date).isValid();
|
|
255
|
+
};
|
|
256
|
+
var getFirstDayOfMonth = (date = /* @__PURE__ */ new Date()) => {
|
|
257
|
+
return dayjs(date).date() - dayjs(date).startOf("month").date() + 1;
|
|
258
|
+
};
|
|
259
|
+
var getLastDayOfMonth = (date = /* @__PURE__ */ new Date()) => {
|
|
260
|
+
return dayjs(date).endOf("month").date();
|
|
261
|
+
};
|
|
262
|
+
var getQuarter = (date = /* @__PURE__ */ new Date()) => {
|
|
263
|
+
return dayjs(date).quarter();
|
|
264
|
+
};
|
|
265
|
+
var getDaysInMonth = (date = /* @__PURE__ */ new Date()) => {
|
|
266
|
+
return dayjs(date).daysInMonth();
|
|
267
|
+
};
|
|
268
|
+
var getMonthRange = (date = /* @__PURE__ */ new Date()) => {
|
|
269
|
+
const d = dayjs(date);
|
|
270
|
+
return [d.startOf("month").format("YYYY-MM-DD"), d.endOf("month").format("YYYY-MM-DD")];
|
|
271
|
+
};
|
|
272
|
+
var getQuarterRange = (date = /* @__PURE__ */ new Date()) => {
|
|
273
|
+
const d = dayjs(date);
|
|
274
|
+
const quarter = d.quarter();
|
|
275
|
+
const start = d.month((quarter - 1) * 3).startOf("month").format("YYYY-MM-DD");
|
|
276
|
+
const end = d.month(quarter * 3 - 1).endOf("month").format("YYYY-MM-DD");
|
|
277
|
+
return [start, end];
|
|
278
|
+
};
|
|
279
|
+
var getYearRange = (date = /* @__PURE__ */ new Date()) => {
|
|
280
|
+
const d = dayjs(date);
|
|
281
|
+
return [d.startOf("year").format("YYYY-MM-DD"), d.endOf("year").format("YYYY-MM-DD")];
|
|
282
|
+
};
|
|
283
|
+
var getWeekRange = (date = /* @__PURE__ */ new Date(), startDay = 0) => {
|
|
284
|
+
const d = dayjs(date);
|
|
285
|
+
const day = d.day();
|
|
286
|
+
const diff3 = day < startDay ? 7 - startDay + day : day - startDay;
|
|
287
|
+
const start = d.subtract(diff3, "day").format("YYYY-MM-DD");
|
|
288
|
+
const end = d.subtract(diff3, "day").add(6, "day").format("YYYY-MM-DD");
|
|
289
|
+
return [start, end];
|
|
290
|
+
};
|
|
291
|
+
var isLeapYear = (year) => {
|
|
292
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
293
|
+
};
|
|
294
|
+
var getYear = (date = /* @__PURE__ */ new Date()) => {
|
|
295
|
+
return dayjs(date).year();
|
|
296
|
+
};
|
|
297
|
+
var getMonth = (date = /* @__PURE__ */ new Date()) => {
|
|
298
|
+
return dayjs(date).month() + 1;
|
|
299
|
+
};
|
|
300
|
+
var getDay = (date = /* @__PURE__ */ new Date()) => {
|
|
301
|
+
return dayjs(date).date();
|
|
302
|
+
};
|
|
303
|
+
var getHour = (date = /* @__PURE__ */ new Date()) => {
|
|
304
|
+
return dayjs(date).hour();
|
|
305
|
+
};
|
|
306
|
+
var getMinute = (date = /* @__PURE__ */ new Date()) => {
|
|
307
|
+
return dayjs(date).minute();
|
|
308
|
+
};
|
|
309
|
+
var getSecond = (date = /* @__PURE__ */ new Date()) => {
|
|
310
|
+
return dayjs(date).second();
|
|
311
|
+
};
|
|
312
|
+
var getWeekday = (date = /* @__PURE__ */ new Date()) => {
|
|
313
|
+
return dayjs(date).day();
|
|
314
|
+
};
|
|
315
|
+
var getWeekdayName = (date = /* @__PURE__ */ new Date()) => {
|
|
316
|
+
const weekdays = ["\u661F\u671F\u65E5", "\u661F\u671F\u4E00", "\u661F\u671F\u4E8C", "\u661F\u671F\u4E09", "\u661F\u671F\u56DB", "\u661F\u671F\u4E94", "\u661F\u671F\u516D"];
|
|
317
|
+
return weekdays[dayjs(date).day()];
|
|
318
|
+
};
|
|
319
|
+
var getDayOfYear = (date = /* @__PURE__ */ new Date()) => {
|
|
320
|
+
return dayjs(date).dayOfYear();
|
|
321
|
+
};
|
|
322
|
+
var getFirstDayOfWeek = (date = /* @__PURE__ */ new Date()) => {
|
|
323
|
+
return dayjs(date).weekday(0);
|
|
324
|
+
};
|
|
325
|
+
var getLastDayOfWeek = (date = /* @__PURE__ */ new Date()) => {
|
|
326
|
+
return dayjs(date).weekday(6);
|
|
327
|
+
};
|
|
328
|
+
var getFirstDayOfMonthDate = (date = /* @__PURE__ */ new Date()) => {
|
|
329
|
+
return dayjs(date).startOf("month");
|
|
330
|
+
};
|
|
331
|
+
var getLastDayOfMonthDate = (date = /* @__PURE__ */ new Date()) => {
|
|
332
|
+
return dayjs(date).endOf("month");
|
|
333
|
+
};
|
|
334
|
+
var getFirstDayOfYear = (date = /* @__PURE__ */ new Date()) => {
|
|
335
|
+
return dayjs(date).startOf("year");
|
|
336
|
+
};
|
|
337
|
+
var getLastDayOfYear = (date = /* @__PURE__ */ new Date()) => {
|
|
338
|
+
return dayjs(date).endOf("year");
|
|
339
|
+
};
|
|
340
|
+
var isSame = (date1, date2, unit = "day") => {
|
|
341
|
+
return dayjs(date1).isSame(date2, unit);
|
|
342
|
+
};
|
|
343
|
+
var compare = (date1, date2) => {
|
|
344
|
+
const d1 = dayjs(date1).valueOf();
|
|
345
|
+
const d2 = dayjs(date2).valueOf();
|
|
346
|
+
if (d1 > d2) return 1;
|
|
347
|
+
if (d1 < d2) return -1;
|
|
348
|
+
return 0;
|
|
349
|
+
};
|
|
350
|
+
var isSameOrBefore = (date1, date2) => {
|
|
351
|
+
return dayjs(date1).isSameOrBefore(date2);
|
|
352
|
+
};
|
|
353
|
+
var isSameOrAfter = (date1, date2) => {
|
|
354
|
+
return dayjs(date1).isSameOrAfter(date2);
|
|
355
|
+
};
|
|
356
|
+
var isBefore = (date1, date2) => {
|
|
357
|
+
return dayjs(date1).isBefore(date2);
|
|
358
|
+
};
|
|
359
|
+
var isAfter = (date1, date2) => {
|
|
360
|
+
return dayjs(date1).isAfter(date2);
|
|
361
|
+
};
|
|
362
|
+
var getAge = (birthday) => {
|
|
363
|
+
return dayjs().diff(birthday, "year");
|
|
364
|
+
};
|
|
365
|
+
var isWorkday = (date = /* @__PURE__ */ new Date()) => {
|
|
366
|
+
const day = dayjs(date).day();
|
|
367
|
+
return day !== 0 && day !== 6;
|
|
368
|
+
};
|
|
369
|
+
var isWeekend = (date = /* @__PURE__ */ new Date()) => {
|
|
370
|
+
const day = dayjs(date).day();
|
|
371
|
+
return day === 0 || day === 6;
|
|
372
|
+
};
|
|
373
|
+
var getTimeOfDay = (date = /* @__PURE__ */ new Date()) => {
|
|
374
|
+
const hour = dayjs(date).hour();
|
|
375
|
+
if (hour >= 5 && hour < 9) return "morning";
|
|
376
|
+
if (hour >= 9 && hour < 12) return "noon";
|
|
377
|
+
if (hour >= 12 && hour < 18) return "afternoon";
|
|
378
|
+
if (hour >= 18 && hour < 22) return "evening";
|
|
379
|
+
return "night";
|
|
380
|
+
};
|
|
381
|
+
var getTimeOfDayName = (date = /* @__PURE__ */ new Date()) => {
|
|
382
|
+
const timeOfDay = getTimeOfDay(date);
|
|
383
|
+
const names = {
|
|
384
|
+
morning: "\u6E05\u6668",
|
|
385
|
+
noon: "\u4E0A\u5348",
|
|
386
|
+
afternoon: "\u4E0B\u5348",
|
|
387
|
+
evening: "\u665A\u4E0A",
|
|
388
|
+
night: "\u6DF1\u591C"
|
|
389
|
+
};
|
|
390
|
+
return names[timeOfDay];
|
|
391
|
+
};
|
|
392
|
+
var getWorkdaysBetween = (startDate2, endDate2) => {
|
|
393
|
+
let count = 0;
|
|
394
|
+
const start = dayjs(startDate2);
|
|
395
|
+
const end = dayjs(endDate2);
|
|
396
|
+
const days = Math.abs(start.diff(end, "day"));
|
|
397
|
+
for (let i = 0; i <= days; i++) {
|
|
398
|
+
const current = start.add(i, "day");
|
|
399
|
+
if (isWorkday(current)) {
|
|
400
|
+
count++;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return count;
|
|
404
|
+
};
|
|
405
|
+
var getDateRange = (startDate2, endDate2, unit = "day") => {
|
|
406
|
+
const start = dayjs(startDate2);
|
|
407
|
+
const end = dayjs(endDate2);
|
|
408
|
+
const dates = [];
|
|
409
|
+
const diff3 = end.diff(start, unit);
|
|
410
|
+
for (let i = 0; i <= diff3; i++) {
|
|
411
|
+
dates.push(start.add(i, unit));
|
|
412
|
+
}
|
|
413
|
+
return dates;
|
|
414
|
+
};
|
|
415
|
+
var getRecentDays = (days) => {
|
|
416
|
+
const dates = [];
|
|
417
|
+
for (let i = 0; i < days; i++) {
|
|
418
|
+
dates.push(dayjs().subtract(i, "day"));
|
|
419
|
+
}
|
|
420
|
+
return dates.reverse();
|
|
421
|
+
};
|
|
422
|
+
var getRecentMonths = (months) => {
|
|
423
|
+
const dates = [];
|
|
424
|
+
for (let i = 0; i < months; i++) {
|
|
425
|
+
dates.push(dayjs().subtract(i, "month"));
|
|
426
|
+
}
|
|
427
|
+
return dates.reverse();
|
|
428
|
+
};
|
|
429
|
+
var getRecentWeeks = (weeks) => {
|
|
430
|
+
const dates = [];
|
|
431
|
+
for (let i = 0; i < weeks; i++) {
|
|
432
|
+
dates.push(dayjs().subtract(i, "week"));
|
|
433
|
+
}
|
|
434
|
+
return dates.reverse();
|
|
435
|
+
};
|
|
436
|
+
var toUTC = (date) => {
|
|
437
|
+
return dayjs(date).utc();
|
|
438
|
+
};
|
|
439
|
+
var fromUTC = (date) => {
|
|
440
|
+
return dayjs.utc(date).local();
|
|
441
|
+
};
|
|
442
|
+
var toTimezone = (date, timezone2) => {
|
|
443
|
+
return dayjs(date).tz(timezone2);
|
|
444
|
+
};
|
|
445
|
+
var getTimezoneOffset = (date = /* @__PURE__ */ new Date()) => {
|
|
446
|
+
return dayjs(date).utcOffset();
|
|
447
|
+
};
|
|
448
|
+
var formatDuration = (milliseconds) => {
|
|
449
|
+
const d = dayjs.duration(milliseconds);
|
|
450
|
+
const hours = Math.floor(d.asHours());
|
|
451
|
+
const minutes = d.minutes();
|
|
452
|
+
const seconds = d.seconds();
|
|
453
|
+
if (hours > 0) {
|
|
454
|
+
return `${hours}\u5C0F\u65F6${minutes}\u5206${seconds}\u79D2`;
|
|
455
|
+
}
|
|
456
|
+
if (minutes > 0) {
|
|
457
|
+
return `${minutes}\u5206${seconds}\u79D2`;
|
|
458
|
+
}
|
|
459
|
+
return `${seconds}\u79D2`;
|
|
460
|
+
};
|
|
461
|
+
var minDate = (dates) => {
|
|
462
|
+
return dayjs.min(dates.map((d) => dayjs(d)));
|
|
463
|
+
};
|
|
464
|
+
var maxDate = (dates) => {
|
|
465
|
+
return dayjs.max(dates.map((d) => dayjs(d)));
|
|
466
|
+
};
|
|
467
|
+
var isThisMonth = (date) => {
|
|
468
|
+
return dayjs(date).isSame(dayjs(), "month");
|
|
469
|
+
};
|
|
470
|
+
var isThisYear = (date) => {
|
|
471
|
+
return dayjs(date).isSame(dayjs(), "year");
|
|
472
|
+
};
|
|
473
|
+
var isThisWeek = (date) => {
|
|
474
|
+
return dayjs(date).isSame(dayjs(), "week");
|
|
475
|
+
};
|
|
476
|
+
var isSameMonth = (date1, date2) => {
|
|
477
|
+
return dayjs(date1).isSame(date2, "month");
|
|
478
|
+
};
|
|
479
|
+
var isSameYear = (date1, date2) => {
|
|
480
|
+
return dayjs(date1).isSame(date2, "year");
|
|
481
|
+
};
|
|
482
|
+
var getChineseYear = (date = /* @__PURE__ */ new Date()) => {
|
|
483
|
+
const animals = ["\u9F20", "\u725B", "\u864E", "\u5154", "\u9F99", "\u86C7", "\u9A6C", "\u7F8A", "\u7334", "\u9E21", "\u72D7", "\u732A"];
|
|
484
|
+
const baseYear = 1900;
|
|
485
|
+
const year = dayjs(date).year();
|
|
486
|
+
const index = (year - baseYear) % 12;
|
|
487
|
+
return animals[index >= 0 ? index : index + 12] + "\u5E74";
|
|
488
|
+
};
|
|
489
|
+
var getZodiacSign = (date = /* @__PURE__ */ new Date()) => {
|
|
490
|
+
const month = dayjs(date).month() + 1;
|
|
491
|
+
const day = dayjs(date).date();
|
|
492
|
+
if (month === 3 && day >= 21 || month === 4 && day <= 19) return "\u767D\u7F8A\u5EA7";
|
|
493
|
+
if (month === 4 && day >= 20 || month === 5 && day <= 20) return "\u91D1\u725B\u5EA7";
|
|
494
|
+
if (month === 5 && day >= 21 || month === 6 && day <= 20) return "\u53CC\u5B50\u5EA7";
|
|
495
|
+
if (month === 6 && day >= 21 || month === 7 && day <= 22) return "\u5DE8\u87F9\u5EA7";
|
|
496
|
+
if (month === 7 && day >= 23 || month === 8 && day <= 22) return "\u72EE\u5B50\u5EA7";
|
|
497
|
+
if (month === 8 && day >= 23 || month === 9 && day <= 22) return "\u5904\u5973\u5EA7";
|
|
498
|
+
if (month === 9 && day >= 23 || month === 10 && day <= 22) return "\u5929\u79E4\u5EA7";
|
|
499
|
+
if (month === 10 && day >= 23 || month === 11 && day <= 21) return "\u5929\u874E\u5EA7";
|
|
500
|
+
if (month === 11 && day >= 22 || month === 12 && day <= 21) return "\u5C04\u624B\u5EA7";
|
|
501
|
+
if (month === 12 && day >= 22 || month === 1 && day <= 19) return "\u6469\u7FAF\u5EA7";
|
|
502
|
+
if (month === 1 && day >= 20 || month === 2 && day <= 18) return "\u6C34\u74F6\u5EA7";
|
|
503
|
+
return "\u53CC\u9C7C\u5EA7";
|
|
504
|
+
};
|
|
505
|
+
var isHoliday = (date = /* @__PURE__ */ new Date()) => {
|
|
506
|
+
const holidays = {
|
|
507
|
+
"0101": "\u5143\u65E6",
|
|
508
|
+
"0214": "\u60C5\u4EBA\u8282",
|
|
509
|
+
"0308": "\u5987\u5973\u8282",
|
|
510
|
+
"0401": "\u611A\u4EBA\u8282",
|
|
511
|
+
"0501": "\u52B3\u52A8\u8282",
|
|
512
|
+
"0504": "\u9752\u5E74\u8282",
|
|
513
|
+
"0601": "\u513F\u7AE5\u8282",
|
|
514
|
+
"0701": "\u5EFA\u515A\u8282",
|
|
515
|
+
"0801": "\u5EFA\u519B\u8282",
|
|
516
|
+
"0910": "\u6559\u5E08\u8282",
|
|
517
|
+
"1001": "\u56FD\u5E86\u8282",
|
|
518
|
+
"1224": "\u5E73\u5B89\u591C",
|
|
519
|
+
"1225": "\u5723\u8BDE\u8282"
|
|
520
|
+
};
|
|
521
|
+
const month = dayjs(date).format("MM");
|
|
522
|
+
const day = dayjs(date).format("DD");
|
|
523
|
+
const key = `${month}${day}`;
|
|
524
|
+
return holidays[key] !== void 0;
|
|
525
|
+
};
|
|
526
|
+
var getHolidayName = (date = /* @__PURE__ */ new Date()) => {
|
|
527
|
+
const holidays = {
|
|
528
|
+
"0101": "\u5143\u65E6",
|
|
529
|
+
"0214": "\u60C5\u4EBA\u8282",
|
|
530
|
+
"0308": "\u5987\u5973\u8282",
|
|
531
|
+
"0401": "\u611A\u4EBA\u8282",
|
|
532
|
+
"0501": "\u52B3\u52A8\u8282",
|
|
533
|
+
"0504": "\u9752\u5E74\u8282",
|
|
534
|
+
"0601": "\u513F\u7AE5\u8282",
|
|
535
|
+
"0701": "\u5EFA\u515A\u8282",
|
|
536
|
+
"0801": "\u5EFA\u519B\u8282",
|
|
537
|
+
"0910": "\u6559\u5E08\u8282",
|
|
538
|
+
"1001": "\u56FD\u5E86\u8282",
|
|
539
|
+
"1224": "\u5E73\u5B89\u591C",
|
|
540
|
+
"1225": "\u5723\u8BDE\u8282"
|
|
541
|
+
};
|
|
542
|
+
const month = dayjs(date).format("MM");
|
|
543
|
+
const day = dayjs(date).format("DD");
|
|
544
|
+
const key = `${month}${day}`;
|
|
545
|
+
return holidays[key] || null;
|
|
546
|
+
};
|
|
547
|
+
var parse = (dateString, formatStr) => {
|
|
548
|
+
return formatStr ? dayjs(dateString, formatStr) : dayjs(dateString);
|
|
549
|
+
};
|
|
550
|
+
var toNow = (date) => {
|
|
551
|
+
return dayjs(date).toNow();
|
|
552
|
+
};
|
|
553
|
+
var clone = (date) => {
|
|
554
|
+
return dayjs(date).clone();
|
|
555
|
+
};
|
|
556
|
+
var unix = (date = /* @__PURE__ */ new Date()) => {
|
|
557
|
+
return dayjs(date).unix();
|
|
558
|
+
};
|
|
559
|
+
var fromUnix = (timestamp) => {
|
|
560
|
+
return dayjs.unix(timestamp);
|
|
561
|
+
};
|
|
562
|
+
var valueOf = (date = /* @__PURE__ */ new Date()) => {
|
|
563
|
+
return dayjs(date).valueOf();
|
|
564
|
+
};
|
|
565
|
+
var date_default = dayjs;
|
|
566
|
+
|
|
567
|
+
// src/modules/array/index.ts
|
|
568
|
+
var array_exports = {};
|
|
569
|
+
__export(array_exports, {
|
|
570
|
+
arrayToTree: () => arrayToTree,
|
|
571
|
+
average: () => average,
|
|
572
|
+
chunk: () => chunk,
|
|
573
|
+
compact: () => compact,
|
|
574
|
+
difference: () => difference,
|
|
575
|
+
filter: () => filter,
|
|
576
|
+
find: () => find,
|
|
577
|
+
findIndex: () => findIndex,
|
|
578
|
+
flatten: () => flatten,
|
|
579
|
+
flattenDeep: () => flattenDeep,
|
|
580
|
+
getPaginationInfo: () => getPaginationInfo,
|
|
581
|
+
groupBy: () => groupBy,
|
|
582
|
+
head: () => head,
|
|
583
|
+
includes: () => includes,
|
|
584
|
+
insert: () => insert,
|
|
585
|
+
intersection: () => intersection,
|
|
586
|
+
isEmpty: () => isEmpty,
|
|
587
|
+
isEqual: () => isEqual,
|
|
588
|
+
last: () => last,
|
|
589
|
+
map: () => map,
|
|
590
|
+
max: () => max,
|
|
591
|
+
maxValue: () => maxValue,
|
|
592
|
+
min: () => min,
|
|
593
|
+
minValue: () => minValue,
|
|
594
|
+
move: () => move,
|
|
595
|
+
omit: () => omit,
|
|
596
|
+
paginate: () => paginate,
|
|
597
|
+
reduceSum: () => reduceSum,
|
|
598
|
+
remove: () => remove,
|
|
599
|
+
removeAt: () => removeAt,
|
|
600
|
+
sample: () => sample,
|
|
601
|
+
shuffle: () => shuffle,
|
|
602
|
+
sortBy: () => sortBy,
|
|
603
|
+
split: () => split,
|
|
604
|
+
sum: () => sum,
|
|
605
|
+
treeToArray: () => treeToArray,
|
|
606
|
+
uniq: () => uniq,
|
|
607
|
+
uniqBy: () => uniqBy,
|
|
608
|
+
unique: () => unique
|
|
609
|
+
});
|
|
610
|
+
var unique = (arr, key) => {
|
|
611
|
+
if (key) {
|
|
612
|
+
return uniqBy(arr, (item) => item[key]);
|
|
613
|
+
}
|
|
614
|
+
return uniq(arr);
|
|
615
|
+
};
|
|
616
|
+
var min = (arr) => {
|
|
617
|
+
if (arr.length === 0) return void 0;
|
|
618
|
+
return Math.min(...arr);
|
|
619
|
+
};
|
|
620
|
+
var max = (arr) => {
|
|
621
|
+
if (arr.length === 0) return void 0;
|
|
622
|
+
return Math.max(...arr);
|
|
623
|
+
};
|
|
624
|
+
var isEmpty = (arr) => {
|
|
625
|
+
return arr.length === 0;
|
|
626
|
+
};
|
|
627
|
+
var split = (arr, size2) => {
|
|
628
|
+
const result = [];
|
|
629
|
+
for (let i = 0; i < arr.length; i += size2) {
|
|
630
|
+
result.push(arr.slice(i, i + size2));
|
|
631
|
+
}
|
|
632
|
+
return result;
|
|
633
|
+
};
|
|
634
|
+
var shuffle = (arr) => {
|
|
635
|
+
const result = [...arr];
|
|
636
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
637
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
638
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
639
|
+
}
|
|
640
|
+
return result;
|
|
641
|
+
};
|
|
642
|
+
var findIndex = (arr, predicate) => {
|
|
643
|
+
return arr.findIndex(predicate);
|
|
644
|
+
};
|
|
645
|
+
var find = (arr, predicate) => {
|
|
646
|
+
return arr.find(predicate);
|
|
647
|
+
};
|
|
648
|
+
var filter = (arr, predicate) => {
|
|
649
|
+
return arr.filter(predicate);
|
|
650
|
+
};
|
|
651
|
+
var map = (arr, mapper) => {
|
|
652
|
+
return arr.map(mapper);
|
|
653
|
+
};
|
|
654
|
+
var reduceSum = (arr, mapper) => {
|
|
655
|
+
if (mapper) {
|
|
656
|
+
return arr.reduce((acc, item) => acc + mapper(item), 0);
|
|
657
|
+
}
|
|
658
|
+
return arr.reduce((acc, item) => acc + item, 0);
|
|
659
|
+
};
|
|
660
|
+
var average = (arr, mapper) => {
|
|
661
|
+
if (arr.length === 0) return 0;
|
|
662
|
+
if (mapper) {
|
|
663
|
+
const sum3 = arr.reduce((acc, item) => acc + mapper(item), 0);
|
|
664
|
+
return sum3 / arr.length;
|
|
665
|
+
}
|
|
666
|
+
return arr.reduce((acc, item) => acc + item, 0) / arr.length;
|
|
667
|
+
};
|
|
668
|
+
var maxValue = (arr, mapper) => {
|
|
669
|
+
if (arr.length === 0) return void 0;
|
|
670
|
+
if (mapper) {
|
|
671
|
+
return Math.max(...arr.map(mapper));
|
|
672
|
+
}
|
|
673
|
+
return Math.max(...arr);
|
|
674
|
+
};
|
|
675
|
+
var minValue = (arr, mapper) => {
|
|
676
|
+
if (arr.length === 0) return void 0;
|
|
677
|
+
if (mapper) {
|
|
678
|
+
return Math.min(...arr.map(mapper));
|
|
679
|
+
}
|
|
680
|
+
return Math.min(...arr);
|
|
681
|
+
};
|
|
682
|
+
var includes = (arr, value) => {
|
|
683
|
+
return arr.includes(value);
|
|
684
|
+
};
|
|
685
|
+
var remove = (arr, value) => {
|
|
686
|
+
return arr.filter((item) => item !== value);
|
|
687
|
+
};
|
|
688
|
+
var removeAt = (arr, index) => {
|
|
689
|
+
return arr.filter((_, i) => i !== index);
|
|
690
|
+
};
|
|
691
|
+
var insert = (arr, index, value) => {
|
|
692
|
+
return [...arr.slice(0, index), value, ...arr.slice(index)];
|
|
693
|
+
};
|
|
694
|
+
var move = (arr, from, to) => {
|
|
695
|
+
const result = [...arr];
|
|
696
|
+
const [removed] = result.splice(from, 1);
|
|
697
|
+
result.splice(to, 0, removed);
|
|
698
|
+
return result;
|
|
699
|
+
};
|
|
700
|
+
var arrayToTree = (arr, options = {}) => {
|
|
701
|
+
const { idKey = "id", parentIdKey = "parentId", childrenKey = "children" } = options;
|
|
702
|
+
const map2 = /* @__PURE__ */ new Map();
|
|
703
|
+
const roots = [];
|
|
704
|
+
arr.forEach((item) => {
|
|
705
|
+
map2.set(item[idKey], { ...item, [childrenKey]: [] });
|
|
706
|
+
});
|
|
707
|
+
map2.forEach((item) => {
|
|
708
|
+
const parentId = item[parentIdKey];
|
|
709
|
+
if (parentId && map2.has(parentId)) {
|
|
710
|
+
const parent = map2.get(parentId);
|
|
711
|
+
if (parent) {
|
|
712
|
+
parent[childrenKey].push(item);
|
|
713
|
+
}
|
|
714
|
+
} else {
|
|
715
|
+
roots.push(item);
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
return roots;
|
|
719
|
+
};
|
|
720
|
+
var treeToArray = (tree, childrenKey = "children") => {
|
|
721
|
+
const result = [];
|
|
722
|
+
const traverse = (nodes) => {
|
|
723
|
+
nodes.forEach((node) => {
|
|
724
|
+
result.push(node);
|
|
725
|
+
if (node[childrenKey] && node[childrenKey].length > 0) {
|
|
726
|
+
traverse(node[childrenKey]);
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
};
|
|
730
|
+
traverse(tree);
|
|
731
|
+
return result;
|
|
732
|
+
};
|
|
733
|
+
var paginate = (arr, page, pageSize) => {
|
|
734
|
+
const start = (page - 1) * pageSize;
|
|
735
|
+
return arr.slice(start, start + pageSize);
|
|
736
|
+
};
|
|
737
|
+
var getPaginationInfo = (total, page, pageSize) => {
|
|
738
|
+
const totalPages = Math.ceil(total / pageSize);
|
|
739
|
+
const startIndex = (page - 1) * pageSize;
|
|
740
|
+
const endIndex = Math.min(startIndex + pageSize, total);
|
|
741
|
+
return {
|
|
742
|
+
total,
|
|
743
|
+
page,
|
|
744
|
+
pageSize,
|
|
745
|
+
totalPages,
|
|
746
|
+
startIndex,
|
|
747
|
+
endIndex,
|
|
748
|
+
hasNext: page < totalPages,
|
|
749
|
+
hasPrev: page > 1
|
|
750
|
+
};
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
// src/modules/string/index.ts
|
|
754
|
+
var string_exports = {};
|
|
755
|
+
__export(string_exports, {
|
|
756
|
+
byteLength: () => byteLength,
|
|
757
|
+
camelCase: () => camelCase,
|
|
758
|
+
capitalize: () => capitalize,
|
|
759
|
+
escapeHtml: () => escapeHtml,
|
|
760
|
+
extractEmails: () => extractEmails,
|
|
761
|
+
extractNumbers: () => extractNumbers,
|
|
762
|
+
extractPhones: () => extractPhones,
|
|
763
|
+
firstLowerCase: () => firstLowerCase,
|
|
764
|
+
firstUpperCase: () => firstUpperCase,
|
|
765
|
+
formatMoney: () => formatMoney,
|
|
766
|
+
getExtension: () => getExtension,
|
|
767
|
+
getFileName: () => getFileName,
|
|
768
|
+
hideEmail: () => hideEmail,
|
|
769
|
+
hideIdCard: () => hideIdCard,
|
|
770
|
+
hidePhone: () => hidePhone,
|
|
771
|
+
highlight: () => highlight,
|
|
772
|
+
isEmail: () => isEmail,
|
|
773
|
+
isEmpty: () => isEmpty2,
|
|
774
|
+
isIdCard: () => isIdCard,
|
|
775
|
+
isPhone: () => isPhone,
|
|
776
|
+
isUrl: () => isUrl,
|
|
777
|
+
kebabCase: () => kebabCase,
|
|
778
|
+
lowerFirst: () => lowerFirst,
|
|
779
|
+
pad: () => pad,
|
|
780
|
+
random: () => random,
|
|
781
|
+
repeat: () => repeat,
|
|
782
|
+
reverse: () => reverse,
|
|
783
|
+
shortId: () => shortId,
|
|
784
|
+
snakeCase: () => snakeCase,
|
|
785
|
+
startCase: () => startCase,
|
|
786
|
+
stripTags: () => stripTags,
|
|
787
|
+
toBoolean: () => toBoolean,
|
|
788
|
+
toNumber: () => toNumber,
|
|
789
|
+
trim: () => trim,
|
|
790
|
+
truncateText: () => truncateText,
|
|
791
|
+
unescapeHtml: () => unescapeHtml,
|
|
792
|
+
upperFirst: () => upperFirst,
|
|
793
|
+
uuid: () => uuid
|
|
794
|
+
});
|
|
795
|
+
var isEmpty2 = (str) => {
|
|
796
|
+
if (!str) return true;
|
|
797
|
+
return trim(str).length === 0;
|
|
798
|
+
};
|
|
799
|
+
var random = (length = 8, charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") => {
|
|
800
|
+
let result = "";
|
|
801
|
+
for (let i = 0; i < length; i++) {
|
|
802
|
+
result += charset.charAt(Math.floor(Math.random() * charset.length));
|
|
803
|
+
}
|
|
804
|
+
return result;
|
|
805
|
+
};
|
|
806
|
+
var uuid = () => {
|
|
807
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
808
|
+
const r = Math.random() * 16 | 0;
|
|
809
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
810
|
+
return v.toString(16);
|
|
811
|
+
});
|
|
812
|
+
};
|
|
813
|
+
var shortId = (length = 6) => {
|
|
814
|
+
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
815
|
+
let result = "";
|
|
816
|
+
for (let i = 0; i < length; i++) {
|
|
817
|
+
result += charset.charAt(Math.floor(Math.random() * charset.length));
|
|
818
|
+
}
|
|
819
|
+
return result;
|
|
820
|
+
};
|
|
821
|
+
var firstUpperCase = (str) => {
|
|
822
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
823
|
+
};
|
|
824
|
+
var firstLowerCase = (str) => {
|
|
825
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
826
|
+
};
|
|
827
|
+
var reverse = (str) => {
|
|
828
|
+
return str.split("").reverse().join("");
|
|
829
|
+
};
|
|
830
|
+
var repeat = (str, count) => {
|
|
831
|
+
return str.repeat(count);
|
|
832
|
+
};
|
|
833
|
+
var pad = (str, length, char = "0", isEnd = false) => {
|
|
834
|
+
const s = String(str);
|
|
835
|
+
if (isEnd) {
|
|
836
|
+
return s.padEnd(length, char);
|
|
837
|
+
}
|
|
838
|
+
return s.padStart(length, char);
|
|
839
|
+
};
|
|
840
|
+
var getExtension = (filename) => {
|
|
841
|
+
const idx = filename.lastIndexOf(".");
|
|
842
|
+
if (idx === -1) return "";
|
|
843
|
+
return filename.slice(idx + 1);
|
|
844
|
+
};
|
|
845
|
+
var getFileName = (filename) => {
|
|
846
|
+
const lastSlash = Math.max(filename.lastIndexOf("/"), filename.lastIndexOf("\\"));
|
|
847
|
+
const nameWithExt = lastSlash === -1 ? filename : filename.slice(lastSlash + 1);
|
|
848
|
+
const lastDot = nameWithExt.lastIndexOf(".");
|
|
849
|
+
return lastDot === -1 ? nameWithExt : nameWithExt.slice(0, lastDot);
|
|
850
|
+
};
|
|
851
|
+
var hidePhone = (phone) => {
|
|
852
|
+
return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
|
|
853
|
+
};
|
|
854
|
+
var hideEmail = (email) => {
|
|
855
|
+
const [username, domain] = email.split("@");
|
|
856
|
+
if (username.length <= 2) return email;
|
|
857
|
+
return `${username[0]}${"*".repeat(username.length - 2)}${username[username.length - 1]}@${domain}`;
|
|
858
|
+
};
|
|
859
|
+
var hideIdCard = (idCard) => {
|
|
860
|
+
if (idCard.length < 8) return idCard;
|
|
861
|
+
return `${idCard.slice(0, 4)}${"*".repeat(idCard.length - 8)}${idCard.slice(-4)}`;
|
|
862
|
+
};
|
|
863
|
+
var formatMoney = (amount, decimals = 2, separator = ",") => {
|
|
864
|
+
const str = amount.toFixed(decimals);
|
|
865
|
+
const parts = str.split(".");
|
|
866
|
+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
867
|
+
return parts.join(".");
|
|
868
|
+
};
|
|
869
|
+
var toNumber = (str, defaultValue = 0) => {
|
|
870
|
+
if (typeof str === "number") return str;
|
|
871
|
+
if (!str) return defaultValue;
|
|
872
|
+
const num = Number(str);
|
|
873
|
+
return isNaN(num) ? defaultValue : num;
|
|
874
|
+
};
|
|
875
|
+
var toBoolean = (str, defaultValue = false) => {
|
|
876
|
+
if (typeof str === "boolean") return str;
|
|
877
|
+
if (!str) return defaultValue;
|
|
878
|
+
return ["true", "1", "yes", "on"].includes(str.toLowerCase());
|
|
879
|
+
};
|
|
880
|
+
var extractNumbers = (str) => {
|
|
881
|
+
const matches = str.match(/-?\d+(\.\d+)?/g);
|
|
882
|
+
return matches ? matches.map(Number) : [];
|
|
883
|
+
};
|
|
884
|
+
var extractPhones = (str) => {
|
|
885
|
+
const matches = str.match(/1[3-9]\d{9}/g);
|
|
886
|
+
return matches || [];
|
|
887
|
+
};
|
|
888
|
+
var extractEmails = (str) => {
|
|
889
|
+
const matches = str.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g);
|
|
890
|
+
return matches || [];
|
|
891
|
+
};
|
|
892
|
+
var isPhone = (phone) => {
|
|
893
|
+
return /^1[3-9]\d{9}$/.test(phone);
|
|
894
|
+
};
|
|
895
|
+
var isEmail = (email) => {
|
|
896
|
+
return /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email);
|
|
897
|
+
};
|
|
898
|
+
var isIdCard = (idCard) => {
|
|
899
|
+
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idCard);
|
|
900
|
+
};
|
|
901
|
+
var isUrl = (url) => {
|
|
902
|
+
try {
|
|
903
|
+
new URL(url);
|
|
904
|
+
return true;
|
|
905
|
+
} catch {
|
|
906
|
+
return false;
|
|
907
|
+
}
|
|
908
|
+
};
|
|
909
|
+
var highlight = (text, keyword, highlightClass = "highlight") => {
|
|
910
|
+
if (!keyword) return text;
|
|
911
|
+
const regex = new RegExp(`(${keyword})`, "gi");
|
|
912
|
+
return text.replace(regex, `<span class="${highlightClass}">$1</span>`);
|
|
913
|
+
};
|
|
914
|
+
var truncateText = (text, length = 100, suffix = "...") => {
|
|
915
|
+
if (text.length <= length) return text;
|
|
916
|
+
return text.slice(0, length) + suffix;
|
|
917
|
+
};
|
|
918
|
+
var escapeHtml = (str) => {
|
|
919
|
+
const htmlEscapes = {
|
|
920
|
+
"&": "&",
|
|
921
|
+
"<": "<",
|
|
922
|
+
">": ">",
|
|
923
|
+
'"': """,
|
|
924
|
+
"'": "'"
|
|
925
|
+
};
|
|
926
|
+
return str.replace(/[&<>"']/g, (char) => htmlEscapes[char]);
|
|
927
|
+
};
|
|
928
|
+
var unescapeHtml = (str) => {
|
|
929
|
+
const htmlUnescapes = {
|
|
930
|
+
"&": "&",
|
|
931
|
+
"<": "<",
|
|
932
|
+
">": ">",
|
|
933
|
+
""": '"',
|
|
934
|
+
"'": "'"
|
|
935
|
+
};
|
|
936
|
+
return str.replace(/&(amp|lt|gt|quot|#39);/g, (match) => htmlUnescapes[match]);
|
|
937
|
+
};
|
|
938
|
+
var stripTags = (str) => {
|
|
939
|
+
return str.replace(/<[^>]*>/g, "");
|
|
940
|
+
};
|
|
941
|
+
var byteLength = (str) => {
|
|
942
|
+
let len = 0;
|
|
943
|
+
for (let i = 0; i < str.length; i++) {
|
|
944
|
+
const code = str.charCodeAt(i);
|
|
945
|
+
if (code >= 1 && code <= 126) {
|
|
946
|
+
len += 1;
|
|
947
|
+
} else if (code >= 128 && code <= 2047) {
|
|
948
|
+
len += 2;
|
|
949
|
+
} else if (code >= 2048 && code <= 65535) {
|
|
950
|
+
len += 3;
|
|
951
|
+
} else {
|
|
952
|
+
len += 4;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
return len;
|
|
956
|
+
};
|
|
957
|
+
|
|
958
|
+
// src/modules/object/index.ts
|
|
959
|
+
var object_exports = {};
|
|
960
|
+
__export(object_exports, {
|
|
961
|
+
clear: () => clear,
|
|
962
|
+
cloneDeep: () => cloneDeep,
|
|
963
|
+
deepFreeze: () => deepFreeze,
|
|
964
|
+
deepMerge: () => deepMerge,
|
|
965
|
+
deleteDeep: () => deleteDeep,
|
|
966
|
+
diff: () => diff2,
|
|
967
|
+
entries: () => entries,
|
|
968
|
+
filter: () => filter2,
|
|
969
|
+
first: () => first,
|
|
970
|
+
fromPairs: () => fromPairs,
|
|
971
|
+
fromQueryString: () => fromQueryString,
|
|
972
|
+
get: () => get,
|
|
973
|
+
getDeep: () => getDeep,
|
|
974
|
+
groupBy: () => groupBy,
|
|
975
|
+
groupByPath: () => groupByPath,
|
|
976
|
+
has: () => has,
|
|
977
|
+
hasDeep: () => hasDeep,
|
|
978
|
+
invert: () => invert,
|
|
979
|
+
isArray: () => isArray,
|
|
980
|
+
isBoolean: () => isBoolean,
|
|
981
|
+
isEmpty: () => isEmpty3,
|
|
982
|
+
isEmptyObject: () => isEmptyObject,
|
|
983
|
+
isEqual: () => isEqual,
|
|
984
|
+
isFunction: () => isFunction,
|
|
985
|
+
isNil: () => isNil,
|
|
986
|
+
isNull: () => isNull,
|
|
987
|
+
isNumber: () => isNumber,
|
|
988
|
+
isObject: () => isObject,
|
|
989
|
+
isString: () => isString,
|
|
990
|
+
isUndefined: () => isUndefined,
|
|
991
|
+
keys: () => keys,
|
|
992
|
+
last: () => last2,
|
|
993
|
+
mapKeys: () => mapKeys,
|
|
994
|
+
mapValues: () => mapValues,
|
|
995
|
+
merge: () => merge,
|
|
996
|
+
omit: () => omit,
|
|
997
|
+
pick: () => pick,
|
|
998
|
+
renameKeys: () => renameKeys,
|
|
999
|
+
set: () => set,
|
|
1000
|
+
setDeep: () => setDeep,
|
|
1001
|
+
size: () => size,
|
|
1002
|
+
sortKeys: () => sortKeys,
|
|
1003
|
+
toFormData: () => toFormData,
|
|
1004
|
+
toQueryString: () => toQueryString,
|
|
1005
|
+
values: () => values
|
|
1006
|
+
});
|
|
1007
|
+
var keys = (obj) => {
|
|
1008
|
+
return Object.keys(obj);
|
|
1009
|
+
};
|
|
1010
|
+
var values = (obj) => {
|
|
1011
|
+
return Object.values(obj);
|
|
1012
|
+
};
|
|
1013
|
+
var entries = (obj) => {
|
|
1014
|
+
return Object.entries(obj);
|
|
1015
|
+
};
|
|
1016
|
+
var fromPairs = (pairs) => {
|
|
1017
|
+
const result = {};
|
|
1018
|
+
for (const [key, value] of pairs) {
|
|
1019
|
+
result[key] = value;
|
|
1020
|
+
}
|
|
1021
|
+
return result;
|
|
1022
|
+
};
|
|
1023
|
+
var get = (obj, path, defaultValue) => {
|
|
1024
|
+
const keys2 = path.split(".");
|
|
1025
|
+
let result = obj;
|
|
1026
|
+
for (const key of keys2) {
|
|
1027
|
+
if (result === null || result === void 0) {
|
|
1028
|
+
return defaultValue;
|
|
1029
|
+
}
|
|
1030
|
+
result = result[key];
|
|
1031
|
+
}
|
|
1032
|
+
return result === void 0 ? defaultValue : result;
|
|
1033
|
+
};
|
|
1034
|
+
var set = (obj, path, value) => {
|
|
1035
|
+
const keys2 = path.split(".");
|
|
1036
|
+
let result = obj;
|
|
1037
|
+
for (let i = 0; i < keys2.length - 1; i++) {
|
|
1038
|
+
const key = keys2[i];
|
|
1039
|
+
if (!(key in result) || typeof result[key] !== "object") {
|
|
1040
|
+
result[key] = {};
|
|
1041
|
+
}
|
|
1042
|
+
result = result[key];
|
|
1043
|
+
}
|
|
1044
|
+
result[keys2[keys2.length - 1]] = value;
|
|
1045
|
+
};
|
|
1046
|
+
var has = (obj, path) => {
|
|
1047
|
+
const keys2 = path.split(".");
|
|
1048
|
+
let result = obj;
|
|
1049
|
+
for (const key of keys2) {
|
|
1050
|
+
if (result === null || result === void 0 || !(key in result)) {
|
|
1051
|
+
return false;
|
|
1052
|
+
}
|
|
1053
|
+
result = result[key];
|
|
1054
|
+
}
|
|
1055
|
+
return true;
|
|
1056
|
+
};
|
|
1057
|
+
var isEmpty3 = (obj) => {
|
|
1058
|
+
if (obj === null || obj === void 0) return true;
|
|
1059
|
+
if (Array.isArray(obj)) return obj.length === 0;
|
|
1060
|
+
if (typeof obj === "object") return isEmptyObject(obj);
|
|
1061
|
+
return false;
|
|
1062
|
+
};
|
|
1063
|
+
var deepMerge = (target, ...sources) => {
|
|
1064
|
+
if (!sources.length) return target;
|
|
1065
|
+
const source = sources.shift();
|
|
1066
|
+
if (isObject(target) && isObject(source)) {
|
|
1067
|
+
for (const key in source) {
|
|
1068
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1069
|
+
const sourceValue = source[key];
|
|
1070
|
+
const targetValue = target[key];
|
|
1071
|
+
if (isObject(sourceValue)) {
|
|
1072
|
+
if (!isObject(targetValue)) {
|
|
1073
|
+
target[key] = {};
|
|
1074
|
+
}
|
|
1075
|
+
deepMerge(target[key], sourceValue);
|
|
1076
|
+
} else {
|
|
1077
|
+
target[key] = sourceValue;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
return deepMerge(target, ...sources);
|
|
1083
|
+
};
|
|
1084
|
+
var isObject = (obj) => {
|
|
1085
|
+
return obj !== null && typeof obj === "object" && !Array.isArray(obj);
|
|
1086
|
+
};
|
|
1087
|
+
var isArray = (obj) => {
|
|
1088
|
+
return Array.isArray(obj);
|
|
1089
|
+
};
|
|
1090
|
+
var isFunction = (obj) => {
|
|
1091
|
+
return typeof obj === "function";
|
|
1092
|
+
};
|
|
1093
|
+
var isNumber = (obj) => {
|
|
1094
|
+
return typeof obj === "number" && !isNaN(obj);
|
|
1095
|
+
};
|
|
1096
|
+
var isString = (obj) => {
|
|
1097
|
+
return typeof obj === "string";
|
|
1098
|
+
};
|
|
1099
|
+
var isBoolean = (obj) => {
|
|
1100
|
+
return typeof obj === "boolean";
|
|
1101
|
+
};
|
|
1102
|
+
var isNil = (obj) => {
|
|
1103
|
+
return obj === null || obj === void 0;
|
|
1104
|
+
};
|
|
1105
|
+
var isNull = (obj) => {
|
|
1106
|
+
return obj === null;
|
|
1107
|
+
};
|
|
1108
|
+
var isUndefined = (obj) => {
|
|
1109
|
+
return obj === void 0;
|
|
1110
|
+
};
|
|
1111
|
+
var size = (obj) => {
|
|
1112
|
+
return Object.keys(obj).length;
|
|
1113
|
+
};
|
|
1114
|
+
var clear = (obj) => {
|
|
1115
|
+
Object.keys(obj).forEach((key) => {
|
|
1116
|
+
delete obj[key];
|
|
1117
|
+
});
|
|
1118
|
+
return obj;
|
|
1119
|
+
};
|
|
1120
|
+
var toQueryString = (obj) => {
|
|
1121
|
+
return Object.entries(obj).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`).join("&");
|
|
1122
|
+
};
|
|
1123
|
+
var fromQueryString = (queryString) => {
|
|
1124
|
+
const params = {};
|
|
1125
|
+
const pairs = queryString.slice(1).split("&");
|
|
1126
|
+
for (const pair of pairs) {
|
|
1127
|
+
const [key, value] = pair.split("=");
|
|
1128
|
+
if (key) {
|
|
1129
|
+
params[decodeURIComponent(key)] = value ? decodeURIComponent(value) : "";
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return params;
|
|
1133
|
+
};
|
|
1134
|
+
var sortKeys = (obj, compareFn) => {
|
|
1135
|
+
const sortedKeys = Object.keys(obj).sort(compareFn);
|
|
1136
|
+
const result = {};
|
|
1137
|
+
for (const key of sortedKeys) {
|
|
1138
|
+
result[key] = obj[key];
|
|
1139
|
+
}
|
|
1140
|
+
return result;
|
|
1141
|
+
};
|
|
1142
|
+
var renameKeys = (obj, renameMap) => {
|
|
1143
|
+
const result = {};
|
|
1144
|
+
for (const key in obj) {
|
|
1145
|
+
const newKey = renameMap[key] || key;
|
|
1146
|
+
result[newKey] = obj[key];
|
|
1147
|
+
}
|
|
1148
|
+
return result;
|
|
1149
|
+
};
|
|
1150
|
+
var filter2 = (obj, predicate) => {
|
|
1151
|
+
const result = {};
|
|
1152
|
+
for (const key in obj) {
|
|
1153
|
+
if (predicate(obj[key], key)) {
|
|
1154
|
+
result[key] = obj[key];
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
return result;
|
|
1158
|
+
};
|
|
1159
|
+
var mapValues = (obj, mapper) => {
|
|
1160
|
+
const result = {};
|
|
1161
|
+
for (const key in obj) {
|
|
1162
|
+
result[key] = mapper(obj[key], key);
|
|
1163
|
+
}
|
|
1164
|
+
return result;
|
|
1165
|
+
};
|
|
1166
|
+
var mapKeys = (obj, mapper) => {
|
|
1167
|
+
const result = {};
|
|
1168
|
+
for (const key in obj) {
|
|
1169
|
+
const newKey = mapper(key, obj[key]);
|
|
1170
|
+
result[newKey] = obj[key];
|
|
1171
|
+
}
|
|
1172
|
+
return result;
|
|
1173
|
+
};
|
|
1174
|
+
var getDeep = (obj, path, defaultValue) => {
|
|
1175
|
+
return get(obj, path, defaultValue);
|
|
1176
|
+
};
|
|
1177
|
+
var setDeep = (obj, path, value) => {
|
|
1178
|
+
set(obj, path, value);
|
|
1179
|
+
};
|
|
1180
|
+
var hasDeep = (obj, path) => {
|
|
1181
|
+
return has(obj, path);
|
|
1182
|
+
};
|
|
1183
|
+
var deleteDeep = (obj, path) => {
|
|
1184
|
+
const keys2 = path.split(".");
|
|
1185
|
+
let current = obj;
|
|
1186
|
+
for (let i = 0; i < keys2.length - 1; i++) {
|
|
1187
|
+
if (!current[keys2[i]]) {
|
|
1188
|
+
return false;
|
|
1189
|
+
}
|
|
1190
|
+
current = current[keys2[i]];
|
|
1191
|
+
}
|
|
1192
|
+
const lastKey = keys2[keys2.length - 1];
|
|
1193
|
+
if (lastKey in current) {
|
|
1194
|
+
delete current[lastKey];
|
|
1195
|
+
return true;
|
|
1196
|
+
}
|
|
1197
|
+
return false;
|
|
1198
|
+
};
|
|
1199
|
+
var toFormData = (obj) => {
|
|
1200
|
+
const formData = new FormData();
|
|
1201
|
+
for (const key in obj) {
|
|
1202
|
+
const value = obj[key];
|
|
1203
|
+
if (value !== void 0 && value !== null) {
|
|
1204
|
+
if (value instanceof File) {
|
|
1205
|
+
formData.append(key, value);
|
|
1206
|
+
} else if (Array.isArray(value)) {
|
|
1207
|
+
formData.append(key, JSON.stringify(value));
|
|
1208
|
+
} else if (typeof value === "object") {
|
|
1209
|
+
formData.append(key, JSON.stringify(value));
|
|
1210
|
+
} else {
|
|
1211
|
+
formData.append(key, String(value));
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
return formData;
|
|
1216
|
+
};
|
|
1217
|
+
var diff2 = (obj, base) => {
|
|
1218
|
+
const result = {};
|
|
1219
|
+
for (const key in obj) {
|
|
1220
|
+
if (!isEqual(obj[key], base[key])) {
|
|
1221
|
+
result[key] = obj[key];
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
return result;
|
|
1225
|
+
};
|
|
1226
|
+
var deepFreeze = (obj) => {
|
|
1227
|
+
if (isObject(obj) || isArray(obj)) {
|
|
1228
|
+
Object.freeze(obj);
|
|
1229
|
+
for (const key in obj) {
|
|
1230
|
+
deepFreeze(obj[key]);
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
return obj;
|
|
1234
|
+
};
|
|
1235
|
+
var first = (obj) => {
|
|
1236
|
+
const values2 = Object.values(obj);
|
|
1237
|
+
return values2[0];
|
|
1238
|
+
};
|
|
1239
|
+
var last2 = (obj) => {
|
|
1240
|
+
const values2 = Object.values(obj);
|
|
1241
|
+
return values2[values2.length - 1];
|
|
1242
|
+
};
|
|
1243
|
+
var groupByPath = (arr, keyPath) => {
|
|
1244
|
+
return groupBy(arr, (item) => get(item, keyPath));
|
|
1245
|
+
};
|
|
1246
|
+
|
|
1247
|
+
// src/modules/excel/index.ts
|
|
1248
|
+
var excel_exports = {};
|
|
1249
|
+
__export(excel_exports, {
|
|
1250
|
+
excelToTable: () => excelToTable,
|
|
1251
|
+
exportExcel: () => exportExcel,
|
|
1252
|
+
exportExcelWithColumnWidths: () => exportExcelWithColumnWidths,
|
|
1253
|
+
exportExcelWithHeaders: () => exportExcelWithHeaders,
|
|
1254
|
+
exportExcelWithMerges: () => exportExcelWithMerges,
|
|
1255
|
+
exportMultiSheetExcel: () => exportMultiSheetExcel,
|
|
1256
|
+
exportTableToExcel: () => exportTableToExcel,
|
|
1257
|
+
getSheetNames: () => getSheetNames,
|
|
1258
|
+
importAllSheetsExcel: () => importAllSheetsExcel,
|
|
1259
|
+
importExcel: () => importExcel
|
|
1260
|
+
});
|
|
1261
|
+
var exportExcel = (data, options = {}) => {
|
|
1262
|
+
const { filename = "export.xlsx", sheetName = "Sheet1", header } = options;
|
|
1263
|
+
const processedData = header ? data.map((item) => {
|
|
1264
|
+
const row = {};
|
|
1265
|
+
for (const key in header) {
|
|
1266
|
+
row[header[key]] = item[key];
|
|
1267
|
+
}
|
|
1268
|
+
return row;
|
|
1269
|
+
}) : data;
|
|
1270
|
+
const worksheet = XLSX.utils.json_to_sheet(processedData);
|
|
1271
|
+
const workbook = XLSX.utils.book_new();
|
|
1272
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
1273
|
+
XLSX.writeFile(workbook, filename);
|
|
1274
|
+
};
|
|
1275
|
+
var exportMultiSheetExcel = (sheetsData, filename = "export.xlsx") => {
|
|
1276
|
+
const workbook = XLSX.utils.book_new();
|
|
1277
|
+
sheetsData.forEach(({ name, data, header }) => {
|
|
1278
|
+
const processedData = header ? data.map((item) => {
|
|
1279
|
+
const row = {};
|
|
1280
|
+
for (const key in header) {
|
|
1281
|
+
row[header[key]] = item[key];
|
|
1282
|
+
}
|
|
1283
|
+
return row;
|
|
1284
|
+
}) : data;
|
|
1285
|
+
const worksheet = XLSX.utils.json_to_sheet(processedData);
|
|
1286
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, name);
|
|
1287
|
+
});
|
|
1288
|
+
XLSX.writeFile(workbook, filename);
|
|
1289
|
+
};
|
|
1290
|
+
var importExcel = (file, options = {}) => {
|
|
1291
|
+
return new Promise((resolve, reject) => {
|
|
1292
|
+
const { header = 0, raw = false, defval = "" } = options;
|
|
1293
|
+
const reader = new FileReader();
|
|
1294
|
+
reader.onload = (e) => {
|
|
1295
|
+
try {
|
|
1296
|
+
const data = e.target?.result;
|
|
1297
|
+
if (!data) {
|
|
1298
|
+
throw new Error("Failed to read file");
|
|
1299
|
+
}
|
|
1300
|
+
const workbook = XLSX.read(data, { type: "binary" });
|
|
1301
|
+
const sheetName = workbook.SheetNames[0];
|
|
1302
|
+
const worksheet = workbook.Sheets[sheetName];
|
|
1303
|
+
const jsonData = XLSX.utils.sheet_to_json(worksheet, {
|
|
1304
|
+
header,
|
|
1305
|
+
raw,
|
|
1306
|
+
defval
|
|
1307
|
+
});
|
|
1308
|
+
resolve(jsonData);
|
|
1309
|
+
} catch (error) {
|
|
1310
|
+
reject(new Error(String(error)));
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
reader.onerror = (error) => {
|
|
1314
|
+
reject(new Error(String(error)));
|
|
1315
|
+
};
|
|
1316
|
+
if (file instanceof File) {
|
|
1317
|
+
reader.readAsBinaryString(file);
|
|
1318
|
+
} else {
|
|
1319
|
+
reader.readAsBinaryString(new Blob([file]));
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
};
|
|
1323
|
+
var importAllSheetsExcel = (file, options = {}) => {
|
|
1324
|
+
return new Promise((resolve, reject) => {
|
|
1325
|
+
const { header = 0, raw = false, defval = "" } = options;
|
|
1326
|
+
const reader = new FileReader();
|
|
1327
|
+
reader.onload = (e) => {
|
|
1328
|
+
try {
|
|
1329
|
+
const data = e.target?.result;
|
|
1330
|
+
if (!data) {
|
|
1331
|
+
throw new Error("Failed to read file");
|
|
1332
|
+
}
|
|
1333
|
+
const workbook = XLSX.read(data, { type: "binary" });
|
|
1334
|
+
const result = {};
|
|
1335
|
+
workbook.SheetNames.forEach((sheetName) => {
|
|
1336
|
+
const worksheet = workbook.Sheets[sheetName];
|
|
1337
|
+
result[sheetName] = XLSX.utils.sheet_to_json(worksheet, {
|
|
1338
|
+
header,
|
|
1339
|
+
raw,
|
|
1340
|
+
defval
|
|
1341
|
+
});
|
|
1342
|
+
});
|
|
1343
|
+
resolve(result);
|
|
1344
|
+
} catch (error) {
|
|
1345
|
+
reject(new Error(String(error)));
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
reader.onerror = (error) => {
|
|
1349
|
+
reject(new Error(String(error)));
|
|
1350
|
+
};
|
|
1351
|
+
if (file instanceof File) {
|
|
1352
|
+
reader.readAsBinaryString(file);
|
|
1353
|
+
} else {
|
|
1354
|
+
reader.readAsBinaryString(new Blob([file]));
|
|
1355
|
+
}
|
|
1356
|
+
});
|
|
1357
|
+
};
|
|
1358
|
+
var exportExcelWithHeaders = (data, headers, filename = "export.xlsx", sheetName = "Sheet1") => {
|
|
1359
|
+
const worksheet = XLSX.utils.json_to_sheet([]);
|
|
1360
|
+
XLSX.utils.sheet_add_aoa(worksheet, [headers.map((h) => h.label)], { origin: "A1" });
|
|
1361
|
+
const rows = data.map((item) => headers.map((h) => item[h.key]));
|
|
1362
|
+
XLSX.utils.sheet_add_aoa(worksheet, rows, { origin: "A2" });
|
|
1363
|
+
const workbook = XLSX.utils.book_new();
|
|
1364
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
1365
|
+
XLSX.writeFile(workbook, filename);
|
|
1366
|
+
};
|
|
1367
|
+
var exportExcelWithColumnWidths = (data, columnWidths, options = {}) => {
|
|
1368
|
+
const { filename = "export.xlsx", sheetName = "Sheet1", header } = options;
|
|
1369
|
+
const processedData = header ? data.map((item) => {
|
|
1370
|
+
const row = {};
|
|
1371
|
+
for (const key in header) {
|
|
1372
|
+
row[header[key]] = item[key];
|
|
1373
|
+
}
|
|
1374
|
+
return row;
|
|
1375
|
+
}) : data;
|
|
1376
|
+
const worksheet = XLSX.utils.json_to_sheet(processedData);
|
|
1377
|
+
worksheet["!cols"] = columnWidths;
|
|
1378
|
+
const workbook = XLSX.utils.book_new();
|
|
1379
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
1380
|
+
XLSX.writeFile(workbook, filename);
|
|
1381
|
+
};
|
|
1382
|
+
var exportExcelWithMerges = (data, merges, options = {}) => {
|
|
1383
|
+
const { filename = "export.xlsx", sheetName = "Sheet1", header } = options;
|
|
1384
|
+
const processedData = header ? data.map((item) => {
|
|
1385
|
+
const row = {};
|
|
1386
|
+
for (const key in header) {
|
|
1387
|
+
row[header[key]] = item[key];
|
|
1388
|
+
}
|
|
1389
|
+
return row;
|
|
1390
|
+
}) : data;
|
|
1391
|
+
const worksheet = XLSX.utils.json_to_sheet(processedData);
|
|
1392
|
+
worksheet["!merges"] = merges;
|
|
1393
|
+
const workbook = XLSX.utils.book_new();
|
|
1394
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
1395
|
+
XLSX.writeFile(workbook, filename);
|
|
1396
|
+
};
|
|
1397
|
+
var getSheetNames = (file) => {
|
|
1398
|
+
return new Promise((resolve, reject) => {
|
|
1399
|
+
const reader = new FileReader();
|
|
1400
|
+
reader.onload = (e) => {
|
|
1401
|
+
try {
|
|
1402
|
+
const data = e.target?.result;
|
|
1403
|
+
if (!data) {
|
|
1404
|
+
throw new Error("Failed to read file");
|
|
1405
|
+
}
|
|
1406
|
+
const workbook = XLSX.read(data, { type: "binary" });
|
|
1407
|
+
resolve(workbook.SheetNames);
|
|
1408
|
+
} catch (error) {
|
|
1409
|
+
reject(new Error(String(error)));
|
|
1410
|
+
}
|
|
1411
|
+
};
|
|
1412
|
+
reader.onerror = (error) => {
|
|
1413
|
+
reject(new Error(String(error)));
|
|
1414
|
+
};
|
|
1415
|
+
if (file instanceof File) {
|
|
1416
|
+
reader.readAsBinaryString(file);
|
|
1417
|
+
} else {
|
|
1418
|
+
reader.readAsBinaryString(new Blob([file]));
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
};
|
|
1422
|
+
var exportTableToExcel = (tableElement, filename = "export.xlsx") => {
|
|
1423
|
+
const workbook = XLSX.utils.table_to_book(tableElement);
|
|
1424
|
+
XLSX.writeFile(workbook, filename);
|
|
1425
|
+
};
|
|
1426
|
+
var excelToTable = (file, sheetIndex = 0) => {
|
|
1427
|
+
return new Promise((resolve, reject) => {
|
|
1428
|
+
const reader = new FileReader();
|
|
1429
|
+
reader.onload = (e) => {
|
|
1430
|
+
try {
|
|
1431
|
+
const data = e.target?.result;
|
|
1432
|
+
if (!data) {
|
|
1433
|
+
throw new Error("Failed to read file");
|
|
1434
|
+
}
|
|
1435
|
+
const workbook = XLSX.read(data, { type: "binary" });
|
|
1436
|
+
const sheetName = workbook.SheetNames[sheetIndex];
|
|
1437
|
+
const worksheet = workbook.Sheets[sheetName];
|
|
1438
|
+
const html = XLSX.utils.sheet_to_html(worksheet);
|
|
1439
|
+
resolve(html);
|
|
1440
|
+
} catch (error) {
|
|
1441
|
+
reject(new Error(String(error)));
|
|
1442
|
+
}
|
|
1443
|
+
};
|
|
1444
|
+
reader.onerror = (error) => {
|
|
1445
|
+
reject(new Error(String(error)));
|
|
1446
|
+
};
|
|
1447
|
+
reader.readAsBinaryString(file);
|
|
1448
|
+
});
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
// src/modules/pdf/index.ts
|
|
1452
|
+
var pdf_exports = {};
|
|
1453
|
+
__export(pdf_exports, {
|
|
1454
|
+
addImageToPDF: () => addImageToPDF,
|
|
1455
|
+
addPage: () => addPage,
|
|
1456
|
+
addTableToPDF: () => addTableToPDF,
|
|
1457
|
+
addTextToPDF: () => addTextToPDF,
|
|
1458
|
+
captureToImage: () => captureToImage,
|
|
1459
|
+
captureToImageDownload: () => captureToImageDownload,
|
|
1460
|
+
captureToPDF: () => captureToPDF,
|
|
1461
|
+
captureToPDFWithPagination: () => captureToPDFWithPagination,
|
|
1462
|
+
createPDF: () => createPDF,
|
|
1463
|
+
html2canvas: () => html2canvas,
|
|
1464
|
+
jsPDF: () => jsPDF,
|
|
1465
|
+
mergePDFs: () => mergePDFs,
|
|
1466
|
+
pdfToBlob: () => pdfToBlob,
|
|
1467
|
+
pdfToDataURL: () => pdfToDataURL,
|
|
1468
|
+
savePDF: () => savePDF
|
|
1469
|
+
});
|
|
1470
|
+
var captureToPDF = async (element, options = {}) => {
|
|
1471
|
+
const {
|
|
1472
|
+
filename = "download.pdf",
|
|
1473
|
+
scale = 2,
|
|
1474
|
+
useCORS = true,
|
|
1475
|
+
backgroundColor = "#ffffff",
|
|
1476
|
+
logging = false,
|
|
1477
|
+
margin = 10
|
|
1478
|
+
} = options;
|
|
1479
|
+
const canvas = await html2canvas(element, {
|
|
1480
|
+
scale,
|
|
1481
|
+
useCORS,
|
|
1482
|
+
backgroundColor,
|
|
1483
|
+
logging
|
|
1484
|
+
});
|
|
1485
|
+
const imgData = canvas.toDataURL("image/png");
|
|
1486
|
+
const imgWidth = canvas.width;
|
|
1487
|
+
const imgHeight = canvas.height;
|
|
1488
|
+
const pdfWidth = imgWidth / scale;
|
|
1489
|
+
const pdfHeight = imgHeight / scale;
|
|
1490
|
+
const pdf = new jsPDF({
|
|
1491
|
+
orientation: pdfWidth > pdfHeight ? "l" : "p",
|
|
1492
|
+
unit: "pt",
|
|
1493
|
+
format: [pdfWidth + margin * 2, pdfHeight + margin * 2]
|
|
1494
|
+
});
|
|
1495
|
+
pdf.addImage(imgData, "PNG", margin, margin, pdfWidth, pdfHeight);
|
|
1496
|
+
pdf.save(filename);
|
|
1497
|
+
};
|
|
1498
|
+
var captureToPDFWithPagination = async (element, options = {}) => {
|
|
1499
|
+
const {
|
|
1500
|
+
filename = "download.pdf",
|
|
1501
|
+
scale = 2,
|
|
1502
|
+
useCORS = true,
|
|
1503
|
+
backgroundColor = "#ffffff",
|
|
1504
|
+
logging = false,
|
|
1505
|
+
margin = 10
|
|
1506
|
+
} = options;
|
|
1507
|
+
const canvas = await html2canvas(element, {
|
|
1508
|
+
scale,
|
|
1509
|
+
useCORS,
|
|
1510
|
+
backgroundColor,
|
|
1511
|
+
logging
|
|
1512
|
+
});
|
|
1513
|
+
const imgData = canvas.toDataURL("image/png");
|
|
1514
|
+
const imgWidth = canvas.width;
|
|
1515
|
+
const imgHeight = canvas.height;
|
|
1516
|
+
const pdf = new jsPDF("p", "pt", "a4");
|
|
1517
|
+
const pdfWidth = pdf.internal.pageSize.getWidth();
|
|
1518
|
+
const pdfHeight = pdf.internal.pageSize.getHeight();
|
|
1519
|
+
const imgWidthInPDF = pdfWidth - margin * 2;
|
|
1520
|
+
const imgHeightInPDF = imgHeight / imgWidth * imgWidthInPDF;
|
|
1521
|
+
let heightLeft = imgHeightInPDF;
|
|
1522
|
+
let position = margin;
|
|
1523
|
+
pdf.addImage(imgData, "PNG", margin, position, imgWidthInPDF, imgHeightInPDF);
|
|
1524
|
+
heightLeft -= pdfHeight - margin * 2;
|
|
1525
|
+
while (heightLeft > 0) {
|
|
1526
|
+
position = heightLeft - imgHeightInPDF + margin;
|
|
1527
|
+
pdf.addPage();
|
|
1528
|
+
pdf.addImage(imgData, "PNG", margin, position, imgWidthInPDF, imgHeightInPDF);
|
|
1529
|
+
heightLeft -= pdfHeight - margin * 2;
|
|
1530
|
+
}
|
|
1531
|
+
pdf.save(filename);
|
|
1532
|
+
};
|
|
1533
|
+
var captureToImage = async (element, options = {}) => {
|
|
1534
|
+
const canvas = await html2canvas(element, {
|
|
1535
|
+
scale: 2,
|
|
1536
|
+
useCORS: true,
|
|
1537
|
+
backgroundColor: "#ffffff",
|
|
1538
|
+
logging: false,
|
|
1539
|
+
...options
|
|
1540
|
+
});
|
|
1541
|
+
return canvas.toDataURL("image/png");
|
|
1542
|
+
};
|
|
1543
|
+
var captureToImageDownload = async (element, filename = "screenshot.png", options = {}) => {
|
|
1544
|
+
const dataUrl = await captureToImage(element, options);
|
|
1545
|
+
const link = document.createElement("a");
|
|
1546
|
+
link.href = dataUrl;
|
|
1547
|
+
link.download = filename;
|
|
1548
|
+
link.click();
|
|
1549
|
+
};
|
|
1550
|
+
var createPDF = (options = {}) => {
|
|
1551
|
+
return new jsPDF(options);
|
|
1552
|
+
};
|
|
1553
|
+
var addTextToPDF = (pdf, text, x, y, options = {}) => {
|
|
1554
|
+
const { maxWidth, align = "left", fontSize = 12, fontStyle = "normal" } = options;
|
|
1555
|
+
pdf.setFontSize(fontSize);
|
|
1556
|
+
pdf.setFont("helvetica", fontStyle);
|
|
1557
|
+
pdf.text(text, x, y, { maxWidth, align });
|
|
1558
|
+
};
|
|
1559
|
+
var addImageToPDF = (pdf, imageData, x, y, width, height) => {
|
|
1560
|
+
pdf.addImage(imageData, "PNG", x, y, width, height);
|
|
1561
|
+
};
|
|
1562
|
+
var addTableToPDF = (pdf, headers, data, options = {}) => {
|
|
1563
|
+
const {
|
|
1564
|
+
x = 10,
|
|
1565
|
+
y = 10,
|
|
1566
|
+
cellWidth = 50,
|
|
1567
|
+
cellHeight = 20,
|
|
1568
|
+
headerBackgroundColor = "#4472C4",
|
|
1569
|
+
headerTextColor = "#ffffff",
|
|
1570
|
+
textColor = "#000000",
|
|
1571
|
+
fontSize = 10,
|
|
1572
|
+
lineWidth = 0.1,
|
|
1573
|
+
lineColor = [200, 200, 200]
|
|
1574
|
+
} = options;
|
|
1575
|
+
pdf.setFontSize(fontSize);
|
|
1576
|
+
let currentY = y;
|
|
1577
|
+
headers.forEach((header, index) => {
|
|
1578
|
+
const cellX = x + index * cellWidth;
|
|
1579
|
+
pdf.setFillColor(
|
|
1580
|
+
parseInt(headerBackgroundColor.slice(1, 3), 16),
|
|
1581
|
+
parseInt(headerBackgroundColor.slice(3, 5), 16),
|
|
1582
|
+
parseInt(headerBackgroundColor.slice(5, 7), 16)
|
|
1583
|
+
);
|
|
1584
|
+
pdf.rect(cellX, currentY, cellWidth, cellHeight, "F");
|
|
1585
|
+
pdf.setDrawColor(lineColor[0], lineColor[1], lineColor[2]);
|
|
1586
|
+
pdf.setLineWidth(lineWidth);
|
|
1587
|
+
pdf.rect(cellX, currentY, cellWidth, cellHeight, "S");
|
|
1588
|
+
pdf.setTextColor(
|
|
1589
|
+
parseInt(headerTextColor.slice(1, 3), 16),
|
|
1590
|
+
parseInt(headerTextColor.slice(3, 5), 16),
|
|
1591
|
+
parseInt(headerTextColor.slice(5, 7), 16)
|
|
1592
|
+
);
|
|
1593
|
+
pdf.text(header, cellX + cellWidth / 2, currentY + cellHeight / 2 + fontSize / 4, {
|
|
1594
|
+
align: "center"
|
|
1595
|
+
});
|
|
1596
|
+
});
|
|
1597
|
+
currentY += cellHeight;
|
|
1598
|
+
pdf.setTextColor(
|
|
1599
|
+
parseInt(textColor.slice(1, 3), 16),
|
|
1600
|
+
parseInt(textColor.slice(3, 5), 16),
|
|
1601
|
+
parseInt(textColor.slice(5, 7), 16)
|
|
1602
|
+
);
|
|
1603
|
+
data.forEach((row) => {
|
|
1604
|
+
row.forEach((cell, index) => {
|
|
1605
|
+
const cellX = x + index * cellWidth;
|
|
1606
|
+
pdf.setDrawColor(lineColor[0], lineColor[1], lineColor[2]);
|
|
1607
|
+
pdf.setLineWidth(lineWidth);
|
|
1608
|
+
pdf.rect(cellX, currentY, cellWidth, cellHeight, "S");
|
|
1609
|
+
pdf.text(cell, cellX + cellWidth / 2, currentY + cellHeight / 2 + fontSize / 4, {
|
|
1610
|
+
align: "center"
|
|
1611
|
+
});
|
|
1612
|
+
});
|
|
1613
|
+
currentY += cellHeight;
|
|
1614
|
+
});
|
|
1615
|
+
};
|
|
1616
|
+
var addPage = (pdf) => {
|
|
1617
|
+
pdf.addPage();
|
|
1618
|
+
};
|
|
1619
|
+
var savePDF = (pdf, filename = "download.pdf") => {
|
|
1620
|
+
pdf.save(filename);
|
|
1621
|
+
};
|
|
1622
|
+
var pdfToDataURL = (pdf) => {
|
|
1623
|
+
return pdf.output("dataurlstring");
|
|
1624
|
+
};
|
|
1625
|
+
var pdfToBlob = (pdf) => {
|
|
1626
|
+
return pdf.output("blob");
|
|
1627
|
+
};
|
|
1628
|
+
var mergePDFs = (_pdfs) => {
|
|
1629
|
+
return Promise.reject(
|
|
1630
|
+
new Error("mergePDFs \u529F\u80FD\u9700\u8981\u4F7F\u7528 pdf-lib \u5E93\u5B9E\u73B0\u3002\u8BF7\u5B89\u88C5 pdf-lib \u5E76\u4F7F\u7528\u5176\u63D0\u4F9B\u7684\u5408\u5E76\u529F\u80FD\u3002")
|
|
1631
|
+
);
|
|
1632
|
+
};
|
|
1633
|
+
|
|
1634
|
+
// src/modules/map/index.ts
|
|
1635
|
+
var map_exports = {};
|
|
1636
|
+
__export(map_exports, {
|
|
1637
|
+
MapInstance: () => MapInstance,
|
|
1638
|
+
createCircleStyle: () => createCircleStyle,
|
|
1639
|
+
createFillStyle: () => createFillStyle,
|
|
1640
|
+
createGaodeLayer: () => createGaodeLayer,
|
|
1641
|
+
createIconStyle: () => createIconStyle,
|
|
1642
|
+
createLineFeature: () => createLineFeature,
|
|
1643
|
+
createOSMLayer: () => createOSMLayer,
|
|
1644
|
+
createPointFeature: () => createPointFeature,
|
|
1645
|
+
createPolygonFeature: () => createPolygonFeature,
|
|
1646
|
+
createStrokeStyle: () => createStrokeStyle,
|
|
1647
|
+
createStyledLineFeature: () => createStyledLineFeature,
|
|
1648
|
+
createStyledPointFeature: () => createStyledPointFeature,
|
|
1649
|
+
createStyledPolygonFeature: () => createStyledPolygonFeature,
|
|
1650
|
+
createTiandituLayer: () => createTiandituLayer,
|
|
1651
|
+
createXYZLayer: () => createXYZLayer,
|
|
1652
|
+
lonLatToXY: () => lonLatToXY,
|
|
1653
|
+
xyToLonLat: () => xyToLonLat
|
|
1654
|
+
});
|
|
1655
|
+
var MapInstance = class {
|
|
1656
|
+
constructor(options) {
|
|
1657
|
+
this.vectorSources = /* @__PURE__ */ new Map();
|
|
1658
|
+
this.vectorLayers = /* @__PURE__ */ new Map();
|
|
1659
|
+
this.overlays = /* @__PURE__ */ new Map();
|
|
1660
|
+
this.themeLayers = /* @__PURE__ */ new Map();
|
|
1661
|
+
this.drawInteraction = null;
|
|
1662
|
+
this.modifyInteraction = null;
|
|
1663
|
+
this.snapInteraction = null;
|
|
1664
|
+
this.selectInteraction = null;
|
|
1665
|
+
this.currentTheme = "light";
|
|
1666
|
+
this.icons = /* @__PURE__ */ new Map();
|
|
1667
|
+
this.enableDynamicScale = false;
|
|
1668
|
+
this.projection = "EPSG:4326";
|
|
1669
|
+
this.enableDynamicScale = options.enableDynamicScale || false;
|
|
1670
|
+
this.projection = options.projection || "EPSG:4326";
|
|
1671
|
+
this.currentTheme = options.theme || "light";
|
|
1672
|
+
if (options.icons) {
|
|
1673
|
+
Object.entries(options.icons).forEach(([name, config]) => {
|
|
1674
|
+
this.icons.set(name, config);
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1677
|
+
const controls = defaults({
|
|
1678
|
+
zoom: false,
|
|
1679
|
+
rotate: false,
|
|
1680
|
+
attribution: false
|
|
1681
|
+
});
|
|
1682
|
+
if (options.showScaleLine !== false) {
|
|
1683
|
+
controls.push(new ScaleLine());
|
|
1684
|
+
}
|
|
1685
|
+
if (options.showFullScreen !== false) {
|
|
1686
|
+
controls.push(new FullScreen());
|
|
1687
|
+
}
|
|
1688
|
+
this.map = new Map$1({
|
|
1689
|
+
target: options.container,
|
|
1690
|
+
layers: [],
|
|
1691
|
+
view: new View({
|
|
1692
|
+
center: fromLonLat(options.center || [116.3974, 39.9093]),
|
|
1693
|
+
// 默认北京
|
|
1694
|
+
zoom: options.zoom || 10,
|
|
1695
|
+
minZoom: options.minZoom || 1,
|
|
1696
|
+
maxZoom: options.maxZoom || 20,
|
|
1697
|
+
projection: this.projection,
|
|
1698
|
+
constrainResolution: true,
|
|
1699
|
+
smoothResolutionConstraint: false
|
|
1700
|
+
}),
|
|
1701
|
+
controls
|
|
1702
|
+
});
|
|
1703
|
+
if (options.themeConfig) {
|
|
1704
|
+
this.setupThemeLayers(options.themeConfig);
|
|
1705
|
+
}
|
|
1706
|
+
if (options.layers) {
|
|
1707
|
+
options.layers.forEach((layer) => this.map.addLayer(layer.layer));
|
|
1708
|
+
}
|
|
1709
|
+
if (this.enableDynamicScale) {
|
|
1710
|
+
this.map.on("moveend", () => this.handleZoomChange());
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
// ==================== 主题管理 ====================
|
|
1714
|
+
/**
|
|
1715
|
+
* 设置主题图层
|
|
1716
|
+
*/
|
|
1717
|
+
setupThemeLayers(config) {
|
|
1718
|
+
const lightUrl = config.lightUrl || "https://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}";
|
|
1719
|
+
const darkUrl = config.darkUrl || "https://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=9&x={x}&y={y}&z={z}";
|
|
1720
|
+
const lightLayer = new TileLayer({
|
|
1721
|
+
preload: Infinity,
|
|
1722
|
+
source: new XYZ({ url: lightUrl })
|
|
1723
|
+
});
|
|
1724
|
+
const darkLayer = new TileLayer({
|
|
1725
|
+
preload: Infinity,
|
|
1726
|
+
source: new XYZ({ url: darkUrl })
|
|
1727
|
+
});
|
|
1728
|
+
this.themeLayers.set("light", lightLayer);
|
|
1729
|
+
this.themeLayers.set("dark", darkLayer);
|
|
1730
|
+
this.map.addLayer(lightLayer);
|
|
1731
|
+
this.map.addLayer(darkLayer);
|
|
1732
|
+
this.setTheme(this.currentTheme);
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* 切换主题
|
|
1736
|
+
*/
|
|
1737
|
+
setTheme(theme) {
|
|
1738
|
+
this.currentTheme = theme;
|
|
1739
|
+
this.themeLayers.forEach((layer, key) => {
|
|
1740
|
+
layer.setVisible(key === theme);
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
/**
|
|
1744
|
+
* 获取当前主题
|
|
1745
|
+
*/
|
|
1746
|
+
getTheme() {
|
|
1747
|
+
return this.currentTheme;
|
|
1748
|
+
}
|
|
1749
|
+
// ==================== 图层管理 ====================
|
|
1750
|
+
/**
|
|
1751
|
+
* 创建矢量图层
|
|
1752
|
+
*/
|
|
1753
|
+
createVectorLayer(config) {
|
|
1754
|
+
if (this.vectorLayers.has(config.name)) {
|
|
1755
|
+
console.warn(`\u56FE\u5C42 "${config.name}" \u5DF2\u5B58\u5728`);
|
|
1756
|
+
return;
|
|
1757
|
+
}
|
|
1758
|
+
const source = new VectorSource({
|
|
1759
|
+
format: new GeoJSON()
|
|
1760
|
+
});
|
|
1761
|
+
const layer = new VectorLayer({
|
|
1762
|
+
source,
|
|
1763
|
+
style: config.style,
|
|
1764
|
+
minZoom: config.minZoom,
|
|
1765
|
+
maxZoom: config.maxZoom,
|
|
1766
|
+
zIndex: config.zIndex,
|
|
1767
|
+
visible: config.visible !== false
|
|
1768
|
+
});
|
|
1769
|
+
this.vectorSources.set(config.name, source);
|
|
1770
|
+
this.vectorLayers.set(config.name, layer);
|
|
1771
|
+
this.map.addLayer(layer);
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* 获取矢量图层
|
|
1775
|
+
*/
|
|
1776
|
+
getVectorLayer(name) {
|
|
1777
|
+
return this.vectorLayers.get(name);
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* 获取矢量数据源
|
|
1781
|
+
*/
|
|
1782
|
+
getVectorSource(name) {
|
|
1783
|
+
return this.vectorSources.get(name);
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* 显示/隐藏矢量图层
|
|
1787
|
+
*/
|
|
1788
|
+
setLayerVisible(name, visible) {
|
|
1789
|
+
const layer = this.vectorLayers.get(name);
|
|
1790
|
+
if (layer) {
|
|
1791
|
+
layer.setVisible(visible);
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* 设置矢量图层样式
|
|
1796
|
+
*/
|
|
1797
|
+
setLayerStyle(name, style) {
|
|
1798
|
+
const layer = this.vectorLayers.get(name);
|
|
1799
|
+
if (layer) {
|
|
1800
|
+
layer.setStyle(style);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* 清除矢量图层
|
|
1805
|
+
*/
|
|
1806
|
+
clearLayer(name) {
|
|
1807
|
+
const source = this.vectorSources.get(name);
|
|
1808
|
+
if (source) {
|
|
1809
|
+
source.clear();
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* 删除矢量图层
|
|
1814
|
+
*/
|
|
1815
|
+
removeLayer(name) {
|
|
1816
|
+
const layer = this.vectorLayers.get(name);
|
|
1817
|
+
if (layer) {
|
|
1818
|
+
this.map.removeLayer(layer);
|
|
1819
|
+
this.vectorLayers.delete(name);
|
|
1820
|
+
this.vectorSources.delete(name);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
// ==================== 要素管理 ====================
|
|
1824
|
+
/**
|
|
1825
|
+
* 添加标记
|
|
1826
|
+
*/
|
|
1827
|
+
addMarker(options, layerName = "default") {
|
|
1828
|
+
if (!this.vectorLayers.has(layerName)) {
|
|
1829
|
+
this.createVectorLayer({ name: layerName });
|
|
1830
|
+
}
|
|
1831
|
+
const source = this.vectorSources.get(layerName);
|
|
1832
|
+
const feature = new Feature({
|
|
1833
|
+
geometry: new Point(fromLonLat(options.coordinate))
|
|
1834
|
+
});
|
|
1835
|
+
const style = options.style || this.createMarkerStyle(options);
|
|
1836
|
+
feature.setStyle(style);
|
|
1837
|
+
source.addFeature(feature);
|
|
1838
|
+
return feature;
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* 创建标记样式
|
|
1842
|
+
*/
|
|
1843
|
+
createMarkerStyle(options) {
|
|
1844
|
+
if (options.icon && this.icons.has(options.icon)) {
|
|
1845
|
+
const iconConfig = this.icons.get(options.icon);
|
|
1846
|
+
return new Style({
|
|
1847
|
+
image: new Icon({
|
|
1848
|
+
anchor: iconConfig.anchor || [0.5, 0.5],
|
|
1849
|
+
src: iconConfig.src,
|
|
1850
|
+
scale: iconConfig.scale || 1
|
|
1851
|
+
})
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
if (options.iconConfig) {
|
|
1855
|
+
return new Style({
|
|
1856
|
+
image: new Icon({
|
|
1857
|
+
anchor: options.iconConfig.anchor || [0.5, 0.5],
|
|
1858
|
+
src: options.iconConfig.src,
|
|
1859
|
+
scale: options.iconConfig.scale || 1
|
|
1860
|
+
})
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1863
|
+
return new Style({
|
|
1864
|
+
image: new Circle({
|
|
1865
|
+
radius: options.radius || 7,
|
|
1866
|
+
fill: new Fill({ color: options.color || "#ff3333" }),
|
|
1867
|
+
stroke: new Stroke({
|
|
1868
|
+
color: options.strokeColor || "#ffffff",
|
|
1869
|
+
width: options.strokeWidth || 2
|
|
1870
|
+
})
|
|
1871
|
+
})
|
|
1872
|
+
});
|
|
1873
|
+
}
|
|
1874
|
+
/**
|
|
1875
|
+
* 移除标记
|
|
1876
|
+
*/
|
|
1877
|
+
removeMarker(feature, layerName = "default") {
|
|
1878
|
+
const source = this.vectorSources.get(layerName);
|
|
1879
|
+
if (source) {
|
|
1880
|
+
source.removeFeature(feature);
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
/**
|
|
1884
|
+
* 从 GeoJSON 添加要素
|
|
1885
|
+
*/
|
|
1886
|
+
addFeaturesFromGeoJSON(geoJson, layerName = "default") {
|
|
1887
|
+
if (!this.vectorLayers.has(layerName)) {
|
|
1888
|
+
this.createVectorLayer({ name: layerName });
|
|
1889
|
+
}
|
|
1890
|
+
const source = this.vectorSources.get(layerName);
|
|
1891
|
+
const format2 = new GeoJSON();
|
|
1892
|
+
const features = format2.readFeatures(typeof geoJson === "string" ? geoJson : JSON.stringify(geoJson));
|
|
1893
|
+
source.addFeatures(features);
|
|
1894
|
+
return features;
|
|
1895
|
+
}
|
|
1896
|
+
/**
|
|
1897
|
+
* 添加要素
|
|
1898
|
+
*/
|
|
1899
|
+
addFeature(feature, layerName = "default") {
|
|
1900
|
+
if (!this.vectorLayers.has(layerName)) {
|
|
1901
|
+
this.createVectorLayer({ name: layerName });
|
|
1902
|
+
}
|
|
1903
|
+
const source = this.vectorSources.get(layerName);
|
|
1904
|
+
source.addFeature(feature);
|
|
1905
|
+
}
|
|
1906
|
+
/**
|
|
1907
|
+
* 批量添加要素
|
|
1908
|
+
*/
|
|
1909
|
+
addFeatures(features, layerName = "default") {
|
|
1910
|
+
if (!this.vectorLayers.has(layerName)) {
|
|
1911
|
+
this.createVectorLayer({ name: layerName });
|
|
1912
|
+
}
|
|
1913
|
+
const source = this.vectorSources.get(layerName);
|
|
1914
|
+
source.addFeatures(features);
|
|
1915
|
+
}
|
|
1916
|
+
/**
|
|
1917
|
+
* 移除要素
|
|
1918
|
+
*/
|
|
1919
|
+
removeFeature(feature, layerName = "default") {
|
|
1920
|
+
const source = this.vectorSources.get(layerName);
|
|
1921
|
+
if (source) {
|
|
1922
|
+
source.removeFeature(feature);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
/**
|
|
1926
|
+
* 清除所有矢量要素
|
|
1927
|
+
*/
|
|
1928
|
+
clearFeatures(layerName = "default") {
|
|
1929
|
+
const source = this.vectorSources.get(layerName);
|
|
1930
|
+
if (source) {
|
|
1931
|
+
source.clear();
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
/**
|
|
1935
|
+
* 获取图层中的所有要素
|
|
1936
|
+
*/
|
|
1937
|
+
getFeatures(layerName = "default") {
|
|
1938
|
+
const source = this.vectorSources.get(layerName);
|
|
1939
|
+
return source ? source.getFeatures() : [];
|
|
1940
|
+
}
|
|
1941
|
+
/**
|
|
1942
|
+
* 创建 GeoJSON
|
|
1943
|
+
*/
|
|
1944
|
+
createGeoJSON(type, data) {
|
|
1945
|
+
const coordinates = this.getCoordinates(type, data);
|
|
1946
|
+
const id = this.generateUUID();
|
|
1947
|
+
return {
|
|
1948
|
+
type: "FeatureCollection",
|
|
1949
|
+
features: [{
|
|
1950
|
+
type: "Feature",
|
|
1951
|
+
geometry: {
|
|
1952
|
+
type,
|
|
1953
|
+
coordinates
|
|
1954
|
+
},
|
|
1955
|
+
properties: {
|
|
1956
|
+
id,
|
|
1957
|
+
value: data
|
|
1958
|
+
}
|
|
1959
|
+
}]
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
/**
|
|
1963
|
+
* 获取坐标
|
|
1964
|
+
*/
|
|
1965
|
+
getCoordinates(type, data) {
|
|
1966
|
+
if (type === "Point") {
|
|
1967
|
+
return fromLonLat(transform(data.points, "EPSG:3857", "EPSG:4326"));
|
|
1968
|
+
} else if (type === "LineString") {
|
|
1969
|
+
return this.setPointArray(data.points);
|
|
1970
|
+
} else if (type === "Polygon") {
|
|
1971
|
+
return [this.setPointArray(data.points)];
|
|
1972
|
+
}
|
|
1973
|
+
return [];
|
|
1974
|
+
}
|
|
1975
|
+
/**
|
|
1976
|
+
* 设置点数组
|
|
1977
|
+
*/
|
|
1978
|
+
setPointArray(points) {
|
|
1979
|
+
return points.map((item) => fromLonLat(transform(item, "EPSG:3857", "EPSG:4326")));
|
|
1980
|
+
}
|
|
1981
|
+
/**
|
|
1982
|
+
* 生成 UUID
|
|
1983
|
+
*/
|
|
1984
|
+
generateUUID() {
|
|
1985
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
1986
|
+
const r = Math.random() * 16 | 0;
|
|
1987
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
1988
|
+
return v.toString(16);
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
/**
|
|
1992
|
+
* 设置要素样式
|
|
1993
|
+
*/
|
|
1994
|
+
setFeatureStyle(feature, options) {
|
|
1995
|
+
const style = this.createFeatureStyle(options);
|
|
1996
|
+
feature.setStyle(style);
|
|
1997
|
+
}
|
|
1998
|
+
/**
|
|
1999
|
+
* 创建要素样式
|
|
2000
|
+
*/
|
|
2001
|
+
createFeatureStyle(options) {
|
|
2002
|
+
if (options.style) {
|
|
2003
|
+
return options.style;
|
|
2004
|
+
}
|
|
2005
|
+
if (options.icon && this.icons.has(options.icon)) {
|
|
2006
|
+
const iconConfig = this.icons.get(options.icon);
|
|
2007
|
+
return new Style({
|
|
2008
|
+
image: new Icon({
|
|
2009
|
+
anchor: iconConfig.anchor || [0.5, 0.5],
|
|
2010
|
+
src: iconConfig.src,
|
|
2011
|
+
scale: iconConfig.scale || 1
|
|
2012
|
+
})
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
if (options.iconConfig) {
|
|
2016
|
+
return new Style({
|
|
2017
|
+
image: new Icon({
|
|
2018
|
+
anchor: options.iconConfig.anchor || [0.5, 0.5],
|
|
2019
|
+
src: options.iconConfig.src,
|
|
2020
|
+
scale: options.iconConfig.scale || 1
|
|
2021
|
+
})
|
|
2022
|
+
});
|
|
2023
|
+
}
|
|
2024
|
+
return new Style({
|
|
2025
|
+
stroke: new Stroke({
|
|
2026
|
+
color: options.strokeColor || "#3388ff",
|
|
2027
|
+
width: options.strokeWidth || 2
|
|
2028
|
+
}),
|
|
2029
|
+
fill: new Fill({
|
|
2030
|
+
color: options.fillColor || "rgba(51, 136, 255, 0.2)"
|
|
2031
|
+
}),
|
|
2032
|
+
image: new Circle({
|
|
2033
|
+
radius: 7,
|
|
2034
|
+
fill: new Fill({ color: options.strokeColor || "#3388ff" }),
|
|
2035
|
+
stroke: new Stroke({
|
|
2036
|
+
color: "#ffffff",
|
|
2037
|
+
width: 2
|
|
2038
|
+
})
|
|
2039
|
+
})
|
|
2040
|
+
});
|
|
2041
|
+
}
|
|
2042
|
+
// ==================== 动态缩放 ====================
|
|
2043
|
+
/**
|
|
2044
|
+
* 处理缩放变化
|
|
2045
|
+
*/
|
|
2046
|
+
handleZoomChange() {
|
|
2047
|
+
const zoom = this.getZoom();
|
|
2048
|
+
if (zoom !== void 0) {
|
|
2049
|
+
this.updateIconScale(zoom);
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
/**
|
|
2053
|
+
* 更新图标缩放比例
|
|
2054
|
+
*/
|
|
2055
|
+
updateIconScale(zoom) {
|
|
2056
|
+
let scale = 1;
|
|
2057
|
+
if (zoom >= 14) {
|
|
2058
|
+
scale = 0.5;
|
|
2059
|
+
} else if (zoom < 14 && zoom >= 12) {
|
|
2060
|
+
scale = 0.4;
|
|
2061
|
+
} else if (zoom < 12) {
|
|
2062
|
+
scale = 0.3;
|
|
2063
|
+
}
|
|
2064
|
+
this.vectorLayers.forEach((layer) => {
|
|
2065
|
+
const features = layer.getSource()?.getFeatures();
|
|
2066
|
+
if (features) {
|
|
2067
|
+
features.forEach((feature) => {
|
|
2068
|
+
const style = feature.getStyle();
|
|
2069
|
+
if (style) {
|
|
2070
|
+
const image = style.getImage();
|
|
2071
|
+
if (image instanceof Icon) {
|
|
2072
|
+
image.setScale(scale);
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
// ==================== Overlay 管理 ====================
|
|
2080
|
+
/**
|
|
2081
|
+
* 创建 Overlay
|
|
2082
|
+
*/
|
|
2083
|
+
createOverlay(options) {
|
|
2084
|
+
const overlay = new Overlay({
|
|
2085
|
+
element: options.element,
|
|
2086
|
+
autoPan: options.autoPan !== false,
|
|
2087
|
+
offset: options.offset,
|
|
2088
|
+
positioning: options.positioning || "bottom-center"
|
|
2089
|
+
});
|
|
2090
|
+
this.overlays.set(options.name, overlay);
|
|
2091
|
+
this.map.addOverlay(overlay);
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* 显示 Overlay
|
|
2095
|
+
*/
|
|
2096
|
+
showOverlay(name, coordinate) {
|
|
2097
|
+
const overlay = this.overlays.get(name);
|
|
2098
|
+
if (overlay) {
|
|
2099
|
+
overlay.setPosition(fromLonLat(coordinate));
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
/**
|
|
2103
|
+
* 隐藏 Overlay
|
|
2104
|
+
*/
|
|
2105
|
+
hideOverlay(name) {
|
|
2106
|
+
const overlay = this.overlays.get(name);
|
|
2107
|
+
if (overlay) {
|
|
2108
|
+
overlay.setPosition(void 0);
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
/**
|
|
2112
|
+
* 移除 Overlay
|
|
2113
|
+
*/
|
|
2114
|
+
removeOverlay(name) {
|
|
2115
|
+
const overlay = this.overlays.get(name);
|
|
2116
|
+
if (overlay) {
|
|
2117
|
+
this.map.removeOverlay(overlay);
|
|
2118
|
+
this.overlays.delete(name);
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
// ==================== 交互管理 ====================
|
|
2122
|
+
/**
|
|
2123
|
+
* 开始绘制
|
|
2124
|
+
*/
|
|
2125
|
+
startDraw(options) {
|
|
2126
|
+
this.stopDraw();
|
|
2127
|
+
const source = options.layerName && this.vectorSources.has(options.layerName) ? this.vectorSources.get(options.layerName) : new VectorSource();
|
|
2128
|
+
this.drawInteraction = new Draw({
|
|
2129
|
+
source,
|
|
2130
|
+
type: options.type,
|
|
2131
|
+
style: options.style
|
|
2132
|
+
});
|
|
2133
|
+
this.map.addInteraction(this.drawInteraction);
|
|
2134
|
+
if (options.onDrawEnd) {
|
|
2135
|
+
this.drawInteraction.on("drawend", (evt) => {
|
|
2136
|
+
options.onDrawEnd?.(evt.feature);
|
|
2137
|
+
});
|
|
2138
|
+
}
|
|
2139
|
+
this.snapInteraction = new Snap({ source });
|
|
2140
|
+
this.map.addInteraction(this.snapInteraction);
|
|
2141
|
+
}
|
|
2142
|
+
/**
|
|
2143
|
+
* 停止绘制
|
|
2144
|
+
*/
|
|
2145
|
+
stopDraw() {
|
|
2146
|
+
if (this.drawInteraction) {
|
|
2147
|
+
this.map.removeInteraction(this.drawInteraction);
|
|
2148
|
+
this.drawInteraction = null;
|
|
2149
|
+
}
|
|
2150
|
+
if (this.snapInteraction) {
|
|
2151
|
+
this.map.removeInteraction(this.snapInteraction);
|
|
2152
|
+
this.snapInteraction = null;
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* 开始编辑
|
|
2157
|
+
*/
|
|
2158
|
+
startModify(layerName = "default") {
|
|
2159
|
+
this.stopModify();
|
|
2160
|
+
const source = this.vectorSources.get(layerName);
|
|
2161
|
+
if (!source) {
|
|
2162
|
+
console.warn(`\u56FE\u5C42 "${layerName}" \u4E0D\u5B58\u5728`);
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
this.modifyInteraction = new Modify({
|
|
2166
|
+
source
|
|
2167
|
+
});
|
|
2168
|
+
this.map.addInteraction(this.modifyInteraction);
|
|
2169
|
+
this.snapInteraction = new Snap({ source });
|
|
2170
|
+
this.map.addInteraction(this.snapInteraction);
|
|
2171
|
+
}
|
|
2172
|
+
/**
|
|
2173
|
+
* 停止编辑
|
|
2174
|
+
*/
|
|
2175
|
+
stopModify() {
|
|
2176
|
+
if (this.modifyInteraction) {
|
|
2177
|
+
this.map.removeInteraction(this.modifyInteraction);
|
|
2178
|
+
this.modifyInteraction = null;
|
|
2179
|
+
}
|
|
2180
|
+
if (this.snapInteraction) {
|
|
2181
|
+
this.map.removeInteraction(this.snapInteraction);
|
|
2182
|
+
this.snapInteraction = null;
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
/**
|
|
2186
|
+
* 开始选择
|
|
2187
|
+
*/
|
|
2188
|
+
startSelect(layerName = "default", onSelect) {
|
|
2189
|
+
this.stopSelect();
|
|
2190
|
+
this.selectInteraction = new Select({
|
|
2191
|
+
layers: this.vectorLayers.get(layerName) ? [this.vectorLayers.get(layerName)] : void 0
|
|
2192
|
+
});
|
|
2193
|
+
this.map.addInteraction(this.selectInteraction);
|
|
2194
|
+
if (onSelect) {
|
|
2195
|
+
this.selectInteraction.on("select", (evt) => {
|
|
2196
|
+
onSelect(evt.selected);
|
|
2197
|
+
});
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
/**
|
|
2201
|
+
* 停止选择
|
|
2202
|
+
*/
|
|
2203
|
+
stopSelect() {
|
|
2204
|
+
if (this.selectInteraction) {
|
|
2205
|
+
this.map.removeInteraction(this.selectInteraction);
|
|
2206
|
+
this.selectInteraction = null;
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
/**
|
|
2210
|
+
* 获取选中的要素
|
|
2211
|
+
*/
|
|
2212
|
+
getSelectedFeatures() {
|
|
2213
|
+
return this.selectInteraction?.getFeatures().getArray() || [];
|
|
2214
|
+
}
|
|
2215
|
+
// ==================== 地图控制 ====================
|
|
2216
|
+
/**
|
|
2217
|
+
* 获取原始地图实例
|
|
2218
|
+
*/
|
|
2219
|
+
getOlMap() {
|
|
2220
|
+
return this.map;
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* 获取视图
|
|
2224
|
+
*/
|
|
2225
|
+
getView() {
|
|
2226
|
+
return this.map.getView();
|
|
2227
|
+
}
|
|
2228
|
+
/**
|
|
2229
|
+
* 设置中心点
|
|
2230
|
+
*/
|
|
2231
|
+
setCenter(coord) {
|
|
2232
|
+
const view = this.getView();
|
|
2233
|
+
if (view) {
|
|
2234
|
+
view.setCenter(fromLonLat(coord));
|
|
2235
|
+
this.map.render();
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
/**
|
|
2239
|
+
* 获取中心点
|
|
2240
|
+
*/
|
|
2241
|
+
getCenter() {
|
|
2242
|
+
const view = this.getView();
|
|
2243
|
+
if (view) {
|
|
2244
|
+
const center = view.getCenter();
|
|
2245
|
+
return center ? toLonLat(center) : void 0;
|
|
2246
|
+
}
|
|
2247
|
+
return void 0;
|
|
2248
|
+
}
|
|
2249
|
+
/**
|
|
2250
|
+
* 设置缩放级别
|
|
2251
|
+
*/
|
|
2252
|
+
setZoom(zoom) {
|
|
2253
|
+
const view = this.getView();
|
|
2254
|
+
if (view) {
|
|
2255
|
+
view.setZoom(zoom);
|
|
2256
|
+
this.map.render();
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
/**
|
|
2260
|
+
* 获取缩放级别
|
|
2261
|
+
*/
|
|
2262
|
+
getZoom() {
|
|
2263
|
+
return this.getView()?.getZoom();
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2266
|
+
* 缩放到指定范围
|
|
2267
|
+
*/
|
|
2268
|
+
fit(extent, options) {
|
|
2269
|
+
if (!extent) return;
|
|
2270
|
+
const view = this.getView();
|
|
2271
|
+
if (view) {
|
|
2272
|
+
view.fit(extent, options);
|
|
2273
|
+
this.map.render();
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
/**
|
|
2277
|
+
* 缩放到图层
|
|
2278
|
+
*/
|
|
2279
|
+
fitLayer(layerName, options) {
|
|
2280
|
+
const source = this.vectorSources.get(layerName);
|
|
2281
|
+
if (source) {
|
|
2282
|
+
const extent = source.getExtent();
|
|
2283
|
+
if (extent && extent[0] !== Infinity) {
|
|
2284
|
+
this.fit(extent, options);
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
/**
|
|
2289
|
+
* 缩放到坐标数组
|
|
2290
|
+
*/
|
|
2291
|
+
fitCoordinates(coordinates, options) {
|
|
2292
|
+
const extent = boundingExtent(coordinates);
|
|
2293
|
+
this.fit(extent, options);
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* 添加图层
|
|
2297
|
+
*/
|
|
2298
|
+
addLayer(layer) {
|
|
2299
|
+
this.map.addLayer(layer.layer);
|
|
2300
|
+
}
|
|
2301
|
+
/**
|
|
2302
|
+
* 移除图层
|
|
2303
|
+
*/
|
|
2304
|
+
removeMapLayer(layer) {
|
|
2305
|
+
this.map.removeLayer(layer.layer);
|
|
2306
|
+
}
|
|
2307
|
+
/**
|
|
2308
|
+
* 更新地图大小
|
|
2309
|
+
*/
|
|
2310
|
+
updateSize() {
|
|
2311
|
+
this.map.updateSize();
|
|
2312
|
+
}
|
|
2313
|
+
/**
|
|
2314
|
+
* 地图事件监听
|
|
2315
|
+
*/
|
|
2316
|
+
on(event, callback) {
|
|
2317
|
+
this.map.on(event, callback);
|
|
2318
|
+
}
|
|
2319
|
+
/**
|
|
2320
|
+
* 移除事件监听
|
|
2321
|
+
*/
|
|
2322
|
+
off(event, callback) {
|
|
2323
|
+
this.map.un(event, callback);
|
|
2324
|
+
}
|
|
2325
|
+
/**
|
|
2326
|
+
* 销毁地图
|
|
2327
|
+
*/
|
|
2328
|
+
destroy() {
|
|
2329
|
+
this.stopDraw();
|
|
2330
|
+
this.stopModify();
|
|
2331
|
+
this.stopSelect();
|
|
2332
|
+
this.overlays.forEach((overlay) => this.map.removeOverlay(overlay));
|
|
2333
|
+
this.overlays.clear();
|
|
2334
|
+
this.vectorLayers.forEach((layer) => this.map.removeLayer(layer));
|
|
2335
|
+
this.vectorLayers.clear();
|
|
2336
|
+
this.vectorSources.clear();
|
|
2337
|
+
this.map.setTarget(void 0);
|
|
2338
|
+
}
|
|
2339
|
+
};
|
|
2340
|
+
function createOSMLayer(name = "OSM") {
|
|
2341
|
+
return {
|
|
2342
|
+
name,
|
|
2343
|
+
layer: new TileLayer({
|
|
2344
|
+
source: new OSM()
|
|
2345
|
+
})
|
|
2346
|
+
};
|
|
2347
|
+
}
|
|
2348
|
+
function createXYZLayer(url, name = "XYZ") {
|
|
2349
|
+
return {
|
|
2350
|
+
name,
|
|
2351
|
+
layer: new TileLayer({
|
|
2352
|
+
source: new XYZ({
|
|
2353
|
+
url
|
|
2354
|
+
})
|
|
2355
|
+
})
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
function createGaodeLayer(name = "\u9AD8\u5FB7\u5730\u56FE") {
|
|
2359
|
+
return createXYZLayer(
|
|
2360
|
+
"https://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}",
|
|
2361
|
+
name
|
|
2362
|
+
);
|
|
2363
|
+
}
|
|
2364
|
+
function createTiandituLayer(token, type = "vec", name = "\u5929\u5730\u56FE") {
|
|
2365
|
+
const url = `https://t{s}.tianditu.gov.cn/DataServer?T=${type}_w&x={x}&y={y}&l={z}&tk=${token}`;
|
|
2366
|
+
return createXYZLayer(url, name);
|
|
2367
|
+
}
|
|
2368
|
+
function lonLatToXY(lon, lat) {
|
|
2369
|
+
return fromLonLat([lon, lat]);
|
|
2370
|
+
}
|
|
2371
|
+
function xyToLonLat(x, y) {
|
|
2372
|
+
return toLonLat([x, y]);
|
|
2373
|
+
}
|
|
2374
|
+
function createPointFeature(coordinate) {
|
|
2375
|
+
return new Feature({
|
|
2376
|
+
geometry: new Point(fromLonLat(coordinate))
|
|
2377
|
+
});
|
|
2378
|
+
}
|
|
2379
|
+
function createLineFeature(coordinates) {
|
|
2380
|
+
return new Feature({
|
|
2381
|
+
geometry: new LineString(coordinates.map((coord) => fromLonLat(coord)))
|
|
2382
|
+
});
|
|
2383
|
+
}
|
|
2384
|
+
function createPolygonFeature(coordinates) {
|
|
2385
|
+
return new Feature({
|
|
2386
|
+
geometry: new Polygon(coordinates.map((ring) => ring.map((coord) => fromLonLat(coord))))
|
|
2387
|
+
});
|
|
2388
|
+
}
|
|
2389
|
+
function createStyledPointFeature(coordinate, style) {
|
|
2390
|
+
const feature = createPointFeature(coordinate);
|
|
2391
|
+
feature.setStyle(style);
|
|
2392
|
+
return feature;
|
|
2393
|
+
}
|
|
2394
|
+
function createStyledLineFeature(coordinates, style) {
|
|
2395
|
+
const feature = createLineFeature(coordinates);
|
|
2396
|
+
feature.setStyle(style);
|
|
2397
|
+
return feature;
|
|
2398
|
+
}
|
|
2399
|
+
function createStyledPolygonFeature(coordinates, style) {
|
|
2400
|
+
const feature = createPolygonFeature(coordinates);
|
|
2401
|
+
feature.setStyle(style);
|
|
2402
|
+
return feature;
|
|
2403
|
+
}
|
|
2404
|
+
function createIconStyle(iconUrl, options) {
|
|
2405
|
+
return new Style({
|
|
2406
|
+
image: new Icon({
|
|
2407
|
+
anchor: options?.anchor || [0.5, 0.5],
|
|
2408
|
+
src: iconUrl,
|
|
2409
|
+
scale: options?.scale || 1,
|
|
2410
|
+
color: options?.color
|
|
2411
|
+
})
|
|
2412
|
+
});
|
|
2413
|
+
}
|
|
2414
|
+
function createCircleStyle(options) {
|
|
2415
|
+
return new Style({
|
|
2416
|
+
image: new Circle({
|
|
2417
|
+
radius: options?.radius || 7,
|
|
2418
|
+
fill: new Fill({ color: options?.fillColor || "#3388ff" }),
|
|
2419
|
+
stroke: new Stroke({
|
|
2420
|
+
color: options?.strokeColor || "#ffffff",
|
|
2421
|
+
width: options?.strokeWidth || 2
|
|
2422
|
+
})
|
|
2423
|
+
})
|
|
2424
|
+
});
|
|
2425
|
+
}
|
|
2426
|
+
function createStrokeStyle(options) {
|
|
2427
|
+
return new Style({
|
|
2428
|
+
stroke: new Stroke({
|
|
2429
|
+
color: options?.color || "#3388ff",
|
|
2430
|
+
width: options?.width || 2,
|
|
2431
|
+
lineDash: options?.lineDash
|
|
2432
|
+
})
|
|
2433
|
+
});
|
|
2434
|
+
}
|
|
2435
|
+
function createFillStyle(options) {
|
|
2436
|
+
return new Style({
|
|
2437
|
+
stroke: new Stroke({
|
|
2438
|
+
color: options?.strokeColor || "#3388ff",
|
|
2439
|
+
width: options?.strokeWidth || 2
|
|
2440
|
+
}),
|
|
2441
|
+
fill: new Fill({
|
|
2442
|
+
color: options?.fillColor || "rgba(51, 136, 255, 0.2)"
|
|
2443
|
+
})
|
|
2444
|
+
});
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
// src/modules/storage/index.ts
|
|
2448
|
+
var storage_exports = {};
|
|
2449
|
+
__export(storage_exports, {
|
|
2450
|
+
clearLocal: () => clearLocal,
|
|
2451
|
+
clearSession: () => clearSession,
|
|
2452
|
+
clearStorage: () => clearStorage,
|
|
2453
|
+
getAllCookies: () => getAllCookies,
|
|
2454
|
+
getCookie: () => getCookie,
|
|
2455
|
+
getCookieJSON: () => getCookieJSON,
|
|
2456
|
+
getCookieSize: () => getCookieSize,
|
|
2457
|
+
getLocal: () => getLocal,
|
|
2458
|
+
getLocalKeys: () => getLocalKeys,
|
|
2459
|
+
getLocalSize: () => getLocalSize,
|
|
2460
|
+
getSession: () => getSession,
|
|
2461
|
+
getSessionKeys: () => getSessionKeys,
|
|
2462
|
+
getSessionSize: () => getSessionSize,
|
|
2463
|
+
getStorage: () => getStorage,
|
|
2464
|
+
hasCookie: () => hasCookie,
|
|
2465
|
+
removeCookie: () => removeCookie,
|
|
2466
|
+
removeLocal: () => removeLocal,
|
|
2467
|
+
removeSession: () => removeSession,
|
|
2468
|
+
removeStorage: () => removeStorage,
|
|
2469
|
+
setCookie: () => setCookie,
|
|
2470
|
+
setCookieJSON: () => setCookieJSON,
|
|
2471
|
+
setLocal: () => setLocal,
|
|
2472
|
+
setSession: () => setSession,
|
|
2473
|
+
setStorage: () => setStorage
|
|
2474
|
+
});
|
|
2475
|
+
function safeParse(json) {
|
|
2476
|
+
if (!json || json === "undefined" || json === "null") {
|
|
2477
|
+
return void 0;
|
|
2478
|
+
}
|
|
2479
|
+
try {
|
|
2480
|
+
return JSON.parse(json);
|
|
2481
|
+
} catch {
|
|
2482
|
+
return json;
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
function isStorageAvailable(storage) {
|
|
2486
|
+
try {
|
|
2487
|
+
const testKey = "__storage_test__";
|
|
2488
|
+
storage.setItem(testKey, testKey);
|
|
2489
|
+
storage.removeItem(testKey);
|
|
2490
|
+
return true;
|
|
2491
|
+
} catch {
|
|
2492
|
+
return false;
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
function setLocal(key, value, options) {
|
|
2496
|
+
if (!isStorageAvailable(window.localStorage)) {
|
|
2497
|
+
console.warn("LocalStorage is not available");
|
|
2498
|
+
return;
|
|
2499
|
+
}
|
|
2500
|
+
const data = options?.ttl ? {
|
|
2501
|
+
value,
|
|
2502
|
+
expires: Date.now() + options.ttl
|
|
2503
|
+
} : value;
|
|
2504
|
+
window.localStorage.setItem(key, JSON.stringify(data));
|
|
2505
|
+
}
|
|
2506
|
+
function getLocal(key) {
|
|
2507
|
+
if (!isStorageAvailable(window.localStorage)) {
|
|
2508
|
+
return void 0;
|
|
2509
|
+
}
|
|
2510
|
+
const json = window.localStorage.getItem(key);
|
|
2511
|
+
if (!json) {
|
|
2512
|
+
return void 0;
|
|
2513
|
+
}
|
|
2514
|
+
const data = safeParse(json);
|
|
2515
|
+
if (data && typeof data === "object" && "expires" in data && "value" in data) {
|
|
2516
|
+
if (data.expires && Date.now() > data.expires) {
|
|
2517
|
+
removeLocal(key);
|
|
2518
|
+
return void 0;
|
|
2519
|
+
}
|
|
2520
|
+
return data.value;
|
|
2521
|
+
}
|
|
2522
|
+
return data;
|
|
2523
|
+
}
|
|
2524
|
+
function removeLocal(key) {
|
|
2525
|
+
if (isStorageAvailable(window.localStorage)) {
|
|
2526
|
+
window.localStorage.removeItem(key);
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
function clearLocal() {
|
|
2530
|
+
if (isStorageAvailable(window.localStorage)) {
|
|
2531
|
+
window.localStorage.clear();
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
function getLocalKeys() {
|
|
2535
|
+
if (!isStorageAvailable(window.localStorage)) {
|
|
2536
|
+
return [];
|
|
2537
|
+
}
|
|
2538
|
+
return Object.keys(window.localStorage);
|
|
2539
|
+
}
|
|
2540
|
+
function getLocalSize() {
|
|
2541
|
+
return getLocalKeys().length;
|
|
2542
|
+
}
|
|
2543
|
+
function setSession(key, value, options) {
|
|
2544
|
+
if (!isStorageAvailable(window.sessionStorage)) {
|
|
2545
|
+
console.warn("SessionStorage is not available");
|
|
2546
|
+
return;
|
|
2547
|
+
}
|
|
2548
|
+
const data = options?.ttl ? {
|
|
2549
|
+
value,
|
|
2550
|
+
expires: Date.now() + options.ttl
|
|
2551
|
+
} : value;
|
|
2552
|
+
window.sessionStorage.setItem(key, JSON.stringify(data));
|
|
2553
|
+
}
|
|
2554
|
+
function getSession(key) {
|
|
2555
|
+
if (!isStorageAvailable(window.sessionStorage)) {
|
|
2556
|
+
return void 0;
|
|
2557
|
+
}
|
|
2558
|
+
const json = window.sessionStorage.getItem(key);
|
|
2559
|
+
if (!json) {
|
|
2560
|
+
return void 0;
|
|
2561
|
+
}
|
|
2562
|
+
const data = safeParse(json);
|
|
2563
|
+
if (data && typeof data === "object" && "expires" in data && "value" in data) {
|
|
2564
|
+
if (data.expires && Date.now() > data.expires) {
|
|
2565
|
+
removeSession(key);
|
|
2566
|
+
return void 0;
|
|
2567
|
+
}
|
|
2568
|
+
return data.value;
|
|
2569
|
+
}
|
|
2570
|
+
return data;
|
|
2571
|
+
}
|
|
2572
|
+
function removeSession(key) {
|
|
2573
|
+
if (isStorageAvailable(window.sessionStorage)) {
|
|
2574
|
+
window.sessionStorage.removeItem(key);
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
function clearSession() {
|
|
2578
|
+
if (isStorageAvailable(window.sessionStorage)) {
|
|
2579
|
+
window.sessionStorage.clear();
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
function getSessionKeys() {
|
|
2583
|
+
if (!isStorageAvailable(window.sessionStorage)) {
|
|
2584
|
+
return [];
|
|
2585
|
+
}
|
|
2586
|
+
return Object.keys(window.sessionStorage);
|
|
2587
|
+
}
|
|
2588
|
+
function getSessionSize() {
|
|
2589
|
+
return getSessionKeys().length;
|
|
2590
|
+
}
|
|
2591
|
+
function setCookie(key, value, options) {
|
|
2592
|
+
const cookieOptions = {};
|
|
2593
|
+
if (options?.days) {
|
|
2594
|
+
cookieOptions.expires = options.days;
|
|
2595
|
+
} else if (options?.expires !== void 0) {
|
|
2596
|
+
cookieOptions.expires = options.expires;
|
|
2597
|
+
}
|
|
2598
|
+
if (options?.path !== void 0) {
|
|
2599
|
+
cookieOptions.path = options.path;
|
|
2600
|
+
}
|
|
2601
|
+
if (options?.domain !== void 0) {
|
|
2602
|
+
cookieOptions.domain = options.domain;
|
|
2603
|
+
}
|
|
2604
|
+
if (options?.secure !== void 0) {
|
|
2605
|
+
cookieOptions.secure = options.secure;
|
|
2606
|
+
}
|
|
2607
|
+
if (options?.sameSite !== void 0) {
|
|
2608
|
+
cookieOptions.sameSite = options.sameSite;
|
|
2609
|
+
}
|
|
2610
|
+
Cookies.set(key, value, cookieOptions);
|
|
2611
|
+
}
|
|
2612
|
+
function getCookie(key) {
|
|
2613
|
+
return Cookies.get(key);
|
|
2614
|
+
}
|
|
2615
|
+
function removeCookie(key, options) {
|
|
2616
|
+
Cookies.remove(key, options);
|
|
2617
|
+
}
|
|
2618
|
+
function getAllCookies() {
|
|
2619
|
+
return Cookies.get() || {};
|
|
2620
|
+
}
|
|
2621
|
+
function hasCookie(key) {
|
|
2622
|
+
return Cookies.get(key) !== void 0;
|
|
2623
|
+
}
|
|
2624
|
+
function getCookieJSON(key) {
|
|
2625
|
+
const value = Cookies.get(key);
|
|
2626
|
+
if (!value) {
|
|
2627
|
+
return void 0;
|
|
2628
|
+
}
|
|
2629
|
+
try {
|
|
2630
|
+
return JSON.parse(value);
|
|
2631
|
+
} catch {
|
|
2632
|
+
return void 0;
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
function setCookieJSON(key, value, options) {
|
|
2636
|
+
setCookie(key, JSON.stringify(value), options);
|
|
2637
|
+
}
|
|
2638
|
+
function getCookieSize() {
|
|
2639
|
+
return Object.keys(getAllCookies()).length;
|
|
2640
|
+
}
|
|
2641
|
+
function setStorage(type, key, value, options) {
|
|
2642
|
+
switch (type) {
|
|
2643
|
+
case "local":
|
|
2644
|
+
setLocal(key, value, options);
|
|
2645
|
+
break;
|
|
2646
|
+
case "session":
|
|
2647
|
+
setSession(key, value, options);
|
|
2648
|
+
break;
|
|
2649
|
+
case "cookie":
|
|
2650
|
+
setCookie(key, value, options);
|
|
2651
|
+
break;
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
function getStorage(type, key) {
|
|
2655
|
+
switch (type) {
|
|
2656
|
+
case "local":
|
|
2657
|
+
return getLocal(key);
|
|
2658
|
+
case "session":
|
|
2659
|
+
return getSession(key);
|
|
2660
|
+
case "cookie":
|
|
2661
|
+
return getCookie(key);
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
function removeStorage(type, key) {
|
|
2665
|
+
switch (type) {
|
|
2666
|
+
case "local":
|
|
2667
|
+
removeLocal(key);
|
|
2668
|
+
break;
|
|
2669
|
+
case "session":
|
|
2670
|
+
removeSession(key);
|
|
2671
|
+
break;
|
|
2672
|
+
case "cookie":
|
|
2673
|
+
removeCookie(key);
|
|
2674
|
+
break;
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
function clearStorage(type) {
|
|
2678
|
+
switch (type) {
|
|
2679
|
+
case "local":
|
|
2680
|
+
clearLocal();
|
|
2681
|
+
break;
|
|
2682
|
+
case "session":
|
|
2683
|
+
clearSession();
|
|
2684
|
+
break;
|
|
2685
|
+
case "cookie": {
|
|
2686
|
+
const cookies = getAllCookies();
|
|
2687
|
+
for (const key of Object.keys(cookies)) {
|
|
2688
|
+
removeCookie(key);
|
|
2689
|
+
}
|
|
2690
|
+
break;
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
// src/modules/utils/index.ts
|
|
2696
|
+
var utils_exports = {};
|
|
2697
|
+
__export(utils_exports, {
|
|
2698
|
+
avg: () => avg,
|
|
2699
|
+
base64toBlob: () => base64toBlob,
|
|
2700
|
+
base64toFile: () => base64toFile,
|
|
2701
|
+
camelToSnake: () => camelToSnake,
|
|
2702
|
+
capitalize: () => capitalize2,
|
|
2703
|
+
chunk: () => chunk2,
|
|
2704
|
+
clone: () => clone2,
|
|
2705
|
+
copyToClipboard: () => copyToClipboard,
|
|
2706
|
+
debounce: () => debounce,
|
|
2707
|
+
deepMerge: () => deepMerge2,
|
|
2708
|
+
delay: () => delay,
|
|
2709
|
+
downloadBase64: () => downloadBase64,
|
|
2710
|
+
downloadBlob: () => downloadBlob,
|
|
2711
|
+
downloadFile: () => downloadFile,
|
|
2712
|
+
formatFileSize: () => formatFileSize,
|
|
2713
|
+
formatNumber: () => formatNumber,
|
|
2714
|
+
get: () => get2,
|
|
2715
|
+
getDarkColor: () => getDarkColor,
|
|
2716
|
+
getLightColor: () => getLightColor,
|
|
2717
|
+
groupBy: () => groupBy3,
|
|
2718
|
+
hexToRgb: () => hexToRgb,
|
|
2719
|
+
hexToRgbString: () => hexToRgbString,
|
|
2720
|
+
imgToBase64: () => imgToBase64,
|
|
2721
|
+
isArray: () => isArray2,
|
|
2722
|
+
isBoolean: () => isBoolean2,
|
|
2723
|
+
isEmpty: () => isEmpty4,
|
|
2724
|
+
isEqual: () => isEqual3,
|
|
2725
|
+
isFunction: () => isFunction2,
|
|
2726
|
+
isNumber: () => isNumber2,
|
|
2727
|
+
isObject: () => isObject2,
|
|
2728
|
+
isString: () => isString2,
|
|
2729
|
+
isValidEmail: () => isValidEmail,
|
|
2730
|
+
isValidPhone: () => isValidPhone,
|
|
2731
|
+
isValidUrl: () => isValidUrl,
|
|
2732
|
+
max: () => max2,
|
|
2733
|
+
min: () => min2,
|
|
2734
|
+
omit: () => omit3,
|
|
2735
|
+
pick: () => pick2,
|
|
2736
|
+
randomInt: () => randomInt,
|
|
2737
|
+
readFromClipboard: () => readFromClipboard,
|
|
2738
|
+
retry: () => retry,
|
|
2739
|
+
rgbArrayToHex: () => rgbArrayToHex,
|
|
2740
|
+
rgbToHex: () => rgbToHex,
|
|
2741
|
+
set: () => set2,
|
|
2742
|
+
snakeToCamel: () => snakeToCamel,
|
|
2743
|
+
sortBy: () => sortBy2,
|
|
2744
|
+
sum: () => sum2,
|
|
2745
|
+
throttle: () => throttle,
|
|
2746
|
+
truncate: () => truncate,
|
|
2747
|
+
uniq: () => uniq2,
|
|
2748
|
+
uniqueId: () => uniqueId
|
|
2749
|
+
});
|
|
2750
|
+
var clone2 = (obj) => {
|
|
2751
|
+
if (obj === null || typeof obj !== "object") {
|
|
2752
|
+
return obj;
|
|
2753
|
+
}
|
|
2754
|
+
if (obj instanceof Date) {
|
|
2755
|
+
return new Date(obj.getTime());
|
|
2756
|
+
}
|
|
2757
|
+
if (obj instanceof Array) {
|
|
2758
|
+
return obj.map((item) => clone2(item));
|
|
2759
|
+
}
|
|
2760
|
+
if (obj instanceof Object) {
|
|
2761
|
+
const copy = {};
|
|
2762
|
+
Object.keys(obj).forEach((key) => {
|
|
2763
|
+
copy[key] = clone2(obj[key]);
|
|
2764
|
+
});
|
|
2765
|
+
return copy;
|
|
2766
|
+
}
|
|
2767
|
+
return obj;
|
|
2768
|
+
};
|
|
2769
|
+
var isEqual3 = (a, b) => {
|
|
2770
|
+
if (a === b) return true;
|
|
2771
|
+
if (a === null || b === null) return false;
|
|
2772
|
+
if (typeof a !== typeof b) return false;
|
|
2773
|
+
if (typeof a !== "object") return a === b;
|
|
2774
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
2775
|
+
if (Array.isArray(a)) {
|
|
2776
|
+
if (a.length !== b.length) return false;
|
|
2777
|
+
for (let i = 0; i < a.length; i++) {
|
|
2778
|
+
if (!isEqual3(a[i], b[i])) return false;
|
|
2779
|
+
}
|
|
2780
|
+
return true;
|
|
2781
|
+
}
|
|
2782
|
+
const keysA = Object.keys(a);
|
|
2783
|
+
const keysB = Object.keys(b);
|
|
2784
|
+
if (keysA.length !== keysB.length) return false;
|
|
2785
|
+
for (const key of keysA) {
|
|
2786
|
+
if (!keysB.includes(key)) return false;
|
|
2787
|
+
if (!isEqual3(a[key], b[key])) return false;
|
|
2788
|
+
}
|
|
2789
|
+
return true;
|
|
2790
|
+
};
|
|
2791
|
+
var deepMerge2 = (...objects) => {
|
|
2792
|
+
const result = {};
|
|
2793
|
+
objects.forEach((obj) => {
|
|
2794
|
+
if (isObject2(obj)) {
|
|
2795
|
+
Object.keys(obj).forEach((key) => {
|
|
2796
|
+
const value = obj[key];
|
|
2797
|
+
if (isObject2(value) && isObject2(result[key])) {
|
|
2798
|
+
result[key] = deepMerge2(result[key], value);
|
|
2799
|
+
} else {
|
|
2800
|
+
result[key] = clone2(value);
|
|
2801
|
+
}
|
|
2802
|
+
});
|
|
2803
|
+
}
|
|
2804
|
+
});
|
|
2805
|
+
return result;
|
|
2806
|
+
};
|
|
2807
|
+
var get2 = (obj, path) => {
|
|
2808
|
+
return path.split(".").reduce((acc, key) => acc?.[key], obj);
|
|
2809
|
+
};
|
|
2810
|
+
var set2 = (obj, path, value) => {
|
|
2811
|
+
const keys2 = path.split(".");
|
|
2812
|
+
const lastKey = keys2.pop();
|
|
2813
|
+
const target = keys2.reduce((acc, key) => {
|
|
2814
|
+
if (!acc[key]) acc[key] = {};
|
|
2815
|
+
return acc[key];
|
|
2816
|
+
}, obj);
|
|
2817
|
+
target[lastKey] = value;
|
|
2818
|
+
};
|
|
2819
|
+
var omit3 = (obj, keys2) => {
|
|
2820
|
+
const result = { ...obj };
|
|
2821
|
+
keys2.forEach((key) => delete result[key]);
|
|
2822
|
+
return result;
|
|
2823
|
+
};
|
|
2824
|
+
var pick2 = (obj, keys2) => {
|
|
2825
|
+
const result = {};
|
|
2826
|
+
keys2.forEach((key) => {
|
|
2827
|
+
if (key in obj) {
|
|
2828
|
+
result[key] = obj[key];
|
|
2829
|
+
}
|
|
2830
|
+
});
|
|
2831
|
+
return result;
|
|
2832
|
+
};
|
|
2833
|
+
var isObject2 = (value) => {
|
|
2834
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2835
|
+
};
|
|
2836
|
+
var isArray2 = (value) => {
|
|
2837
|
+
return Array.isArray(value);
|
|
2838
|
+
};
|
|
2839
|
+
var isString2 = (value) => {
|
|
2840
|
+
return typeof value === "string";
|
|
2841
|
+
};
|
|
2842
|
+
var isNumber2 = (value) => {
|
|
2843
|
+
return typeof value === "number" && !isNaN(value);
|
|
2844
|
+
};
|
|
2845
|
+
var isBoolean2 = (value) => {
|
|
2846
|
+
return typeof value === "boolean";
|
|
2847
|
+
};
|
|
2848
|
+
var isFunction2 = (value) => {
|
|
2849
|
+
return typeof value === "function";
|
|
2850
|
+
};
|
|
2851
|
+
var isEmpty4 = (value) => {
|
|
2852
|
+
if (value === null || value === void 0) return true;
|
|
2853
|
+
if (isString2(value) || Array.isArray(value)) return value.length === 0;
|
|
2854
|
+
if (isObject2(value)) return Object.keys(value).length === 0;
|
|
2855
|
+
return false;
|
|
2856
|
+
};
|
|
2857
|
+
var uniq2 = (array) => {
|
|
2858
|
+
return [...new Set(array)];
|
|
2859
|
+
};
|
|
2860
|
+
var sortBy2 = (array, key) => {
|
|
2861
|
+
const sortFn = typeof key === "function" ? key : (item) => item[key];
|
|
2862
|
+
return [...array].sort((a, b) => {
|
|
2863
|
+
const valueA = sortFn(a);
|
|
2864
|
+
const valueB = sortFn(b);
|
|
2865
|
+
if (valueA < valueB) return -1;
|
|
2866
|
+
if (valueA > valueB) return 1;
|
|
2867
|
+
return 0;
|
|
2868
|
+
});
|
|
2869
|
+
};
|
|
2870
|
+
var chunk2 = (array, size2) => {
|
|
2871
|
+
const result = [];
|
|
2872
|
+
for (let i = 0; i < array.length; i += size2) {
|
|
2873
|
+
result.push(array.slice(i, i + size2));
|
|
2874
|
+
}
|
|
2875
|
+
return result;
|
|
2876
|
+
};
|
|
2877
|
+
var groupBy3 = (array, key) => {
|
|
2878
|
+
const groupFn = typeof key === "function" ? key : (item) => String(item[key]);
|
|
2879
|
+
return array.reduce(
|
|
2880
|
+
(result, item) => {
|
|
2881
|
+
const groupKey = groupFn(item);
|
|
2882
|
+
if (!result[groupKey]) {
|
|
2883
|
+
result[groupKey] = [];
|
|
2884
|
+
}
|
|
2885
|
+
result[groupKey].push(item);
|
|
2886
|
+
return result;
|
|
2887
|
+
},
|
|
2888
|
+
{}
|
|
2889
|
+
);
|
|
2890
|
+
};
|
|
2891
|
+
var sum2 = (array) => {
|
|
2892
|
+
return array.reduce((acc, num) => acc + num, 0);
|
|
2893
|
+
};
|
|
2894
|
+
var avg = (array) => {
|
|
2895
|
+
return array.length > 0 ? sum2(array) / array.length : 0;
|
|
2896
|
+
};
|
|
2897
|
+
var max2 = (array) => {
|
|
2898
|
+
return Math.max(...array);
|
|
2899
|
+
};
|
|
2900
|
+
var min2 = (array) => {
|
|
2901
|
+
return Math.min(...array);
|
|
2902
|
+
};
|
|
2903
|
+
var camelToSnake = (str) => {
|
|
2904
|
+
return str.replace(/[A-Z]/g, (match) => `_${match.toLowerCase()}`);
|
|
2905
|
+
};
|
|
2906
|
+
var snakeToCamel = (str) => {
|
|
2907
|
+
return str.replace(/_([a-z])/g, (_, match) => match.toUpperCase());
|
|
2908
|
+
};
|
|
2909
|
+
var capitalize2 = (str) => {
|
|
2910
|
+
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
2911
|
+
};
|
|
2912
|
+
var truncate = (str, length = 100, suffix = "...") => {
|
|
2913
|
+
if (str.length <= length) return str;
|
|
2914
|
+
return `${str.slice(0, length)}${suffix}`;
|
|
2915
|
+
};
|
|
2916
|
+
var formatFileSize = (bytes) => {
|
|
2917
|
+
if (bytes === 0) return "0 B";
|
|
2918
|
+
const k = 1024;
|
|
2919
|
+
const sizes = ["B", "KB", "MB", "GB", "TB"];
|
|
2920
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
2921
|
+
return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
|
|
2922
|
+
};
|
|
2923
|
+
var formatNumber = (num) => {
|
|
2924
|
+
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
2925
|
+
};
|
|
2926
|
+
var isValidUrl = (str) => {
|
|
2927
|
+
try {
|
|
2928
|
+
new URL(str);
|
|
2929
|
+
return true;
|
|
2930
|
+
} catch {
|
|
2931
|
+
return false;
|
|
2932
|
+
}
|
|
2933
|
+
};
|
|
2934
|
+
var isValidEmail = (email) => {
|
|
2935
|
+
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
2936
|
+
return regex.test(email);
|
|
2937
|
+
};
|
|
2938
|
+
var isValidPhone = (phone) => {
|
|
2939
|
+
const regex = /^1[3-9]\d{9}$/;
|
|
2940
|
+
return regex.test(phone);
|
|
2941
|
+
};
|
|
2942
|
+
var randomInt = (min3, max3) => {
|
|
2943
|
+
return Math.floor(Math.random() * (max3 - min3 + 1)) + min3;
|
|
2944
|
+
};
|
|
2945
|
+
var uniqueId = (prefix = "") => {
|
|
2946
|
+
return `${prefix}${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2947
|
+
};
|
|
2948
|
+
var delay = (ms) => {
|
|
2949
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2950
|
+
};
|
|
2951
|
+
var retry = async (fn, retries = 3, delayMs = 1e3) => {
|
|
2952
|
+
try {
|
|
2953
|
+
return await fn();
|
|
2954
|
+
} catch (error) {
|
|
2955
|
+
if (retries <= 0) {
|
|
2956
|
+
throw error;
|
|
2957
|
+
}
|
|
2958
|
+
await delay(delayMs);
|
|
2959
|
+
return retry(fn, retries - 1, delayMs);
|
|
2960
|
+
}
|
|
2961
|
+
};
|
|
2962
|
+
var hexToRgb = (str) => {
|
|
2963
|
+
const hexRegex = /^#?([0-9A-Fa-f]{6})$/;
|
|
2964
|
+
if (!hexRegex.test(str)) {
|
|
2965
|
+
return null;
|
|
2966
|
+
}
|
|
2967
|
+
const hex = str.replace("#", "");
|
|
2968
|
+
const r = parseInt(hex.substring(0, 2), 16);
|
|
2969
|
+
const g = parseInt(hex.substring(2, 4), 16);
|
|
2970
|
+
const b = parseInt(hex.substring(4, 6), 16);
|
|
2971
|
+
return [r, g, b];
|
|
2972
|
+
};
|
|
2973
|
+
var hexToRgbString = (str) => {
|
|
2974
|
+
const rgb = hexToRgb(str);
|
|
2975
|
+
if (!rgb) {
|
|
2976
|
+
return null;
|
|
2977
|
+
}
|
|
2978
|
+
return `rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`;
|
|
2979
|
+
};
|
|
2980
|
+
var rgbToHex = (r, g, b) => {
|
|
2981
|
+
const numRegex = /^\d{1,3}$/;
|
|
2982
|
+
if (!numRegex.test(r.toString()) || !numRegex.test(g.toString()) || !numRegex.test(b.toString())) {
|
|
2983
|
+
return null;
|
|
2984
|
+
}
|
|
2985
|
+
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
|
|
2986
|
+
return null;
|
|
2987
|
+
}
|
|
2988
|
+
const toHex = (num) => {
|
|
2989
|
+
const hex = num.toString(16);
|
|
2990
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
|
2991
|
+
};
|
|
2992
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
2993
|
+
};
|
|
2994
|
+
var rgbArrayToHex = (rgb) => {
|
|
2995
|
+
if (rgb.length !== 3) {
|
|
2996
|
+
return null;
|
|
2997
|
+
}
|
|
2998
|
+
return rgbToHex(rgb[0], rgb[1], rgb[2]);
|
|
2999
|
+
};
|
|
3000
|
+
var getLightColor = (color, alpha) => {
|
|
3001
|
+
const rgb = hexToRgb(color);
|
|
3002
|
+
if (!rgb) {
|
|
3003
|
+
return null;
|
|
3004
|
+
}
|
|
3005
|
+
const [r, g, b] = rgb;
|
|
3006
|
+
const newR = Math.floor((255 - r) * alpha + r);
|
|
3007
|
+
const newG = Math.floor((255 - g) * alpha + g);
|
|
3008
|
+
const newB = Math.floor((255 - b) * alpha + b);
|
|
3009
|
+
return rgbToHex(newR, newG, newB);
|
|
3010
|
+
};
|
|
3011
|
+
var getDarkColor = (color, alpha) => {
|
|
3012
|
+
const rgb = hexToRgb(color);
|
|
3013
|
+
if (!rgb) {
|
|
3014
|
+
return null;
|
|
3015
|
+
}
|
|
3016
|
+
const [r, g, b] = rgb;
|
|
3017
|
+
const newR = Math.floor(r * (1 - alpha));
|
|
3018
|
+
const newG = Math.floor(g * (1 - alpha));
|
|
3019
|
+
const newB = Math.floor(b * (1 - alpha));
|
|
3020
|
+
return rgbToHex(newR, newG, newB);
|
|
3021
|
+
};
|
|
3022
|
+
var imgToBase64 = (url, type = "image/png") => {
|
|
3023
|
+
return new Promise((resolve, reject) => {
|
|
3024
|
+
const image = new Image();
|
|
3025
|
+
image.crossOrigin = "anonymous";
|
|
3026
|
+
image.onload = () => {
|
|
3027
|
+
const canvas = document.createElement("canvas");
|
|
3028
|
+
canvas.width = image.naturalWidth;
|
|
3029
|
+
canvas.height = image.naturalHeight;
|
|
3030
|
+
const ctx = canvas.getContext("2d");
|
|
3031
|
+
if (!ctx) {
|
|
3032
|
+
reject(new Error("Failed to get canvas context"));
|
|
3033
|
+
return;
|
|
3034
|
+
}
|
|
3035
|
+
ctx.drawImage(image, 0, 0);
|
|
3036
|
+
const base64 = canvas.toDataURL(type);
|
|
3037
|
+
resolve(base64);
|
|
3038
|
+
};
|
|
3039
|
+
image.onerror = (err) => {
|
|
3040
|
+
reject(new Error(`Failed to load image: ${String(err)}`));
|
|
3041
|
+
};
|
|
3042
|
+
image.src = url;
|
|
3043
|
+
});
|
|
3044
|
+
};
|
|
3045
|
+
var base64toFile = (base64, fileName, mimeType = "image/jpeg") => {
|
|
3046
|
+
const dataArr = base64.split(",");
|
|
3047
|
+
const byteString = atob(dataArr[1]);
|
|
3048
|
+
const u8Arr = new Uint8Array(byteString.length);
|
|
3049
|
+
for (let i = 0; i < byteString.length; i++) {
|
|
3050
|
+
u8Arr[i] = byteString.charCodeAt(i);
|
|
3051
|
+
}
|
|
3052
|
+
return new File([u8Arr], fileName, { type: mimeType });
|
|
3053
|
+
};
|
|
3054
|
+
var base64toBlob = (base64, mimeType = "image/jpeg") => {
|
|
3055
|
+
const dataArr = base64.split(",");
|
|
3056
|
+
const byteString = atob(dataArr[1]);
|
|
3057
|
+
const u8Arr = new Uint8Array(byteString.length);
|
|
3058
|
+
for (let i = 0; i < byteString.length; i++) {
|
|
3059
|
+
u8Arr[i] = byteString.charCodeAt(i);
|
|
3060
|
+
}
|
|
3061
|
+
return new Blob([u8Arr], { type: mimeType });
|
|
3062
|
+
};
|
|
3063
|
+
var downloadFile = (url, fileName = "\u6587\u4EF6", target = false) => {
|
|
3064
|
+
const link = document.createElement("a");
|
|
3065
|
+
link.style.display = "none";
|
|
3066
|
+
link.href = url;
|
|
3067
|
+
if (target) {
|
|
3068
|
+
link.target = "_blank";
|
|
3069
|
+
} else {
|
|
3070
|
+
link.setAttribute("download", fileName);
|
|
3071
|
+
}
|
|
3072
|
+
document.body.appendChild(link);
|
|
3073
|
+
link.click();
|
|
3074
|
+
document.body.removeChild(link);
|
|
3075
|
+
};
|
|
3076
|
+
var downloadBlob = (blob, fileName) => {
|
|
3077
|
+
const url = URL.createObjectURL(blob);
|
|
3078
|
+
downloadFile(url, fileName);
|
|
3079
|
+
URL.revokeObjectURL(url);
|
|
3080
|
+
};
|
|
3081
|
+
var downloadBase64 = (base64, fileName, mimeType = "image/jpeg") => {
|
|
3082
|
+
const blob = base64toBlob(base64, mimeType);
|
|
3083
|
+
downloadBlob(blob, fileName);
|
|
3084
|
+
};
|
|
3085
|
+
var copyToClipboard = async (text) => {
|
|
3086
|
+
try {
|
|
3087
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
3088
|
+
await navigator.clipboard.writeText(text);
|
|
3089
|
+
return true;
|
|
3090
|
+
}
|
|
3091
|
+
const textarea = document.createElement("textarea");
|
|
3092
|
+
textarea.value = text;
|
|
3093
|
+
textarea.style.position = "fixed";
|
|
3094
|
+
textarea.style.opacity = "0";
|
|
3095
|
+
document.body.appendChild(textarea);
|
|
3096
|
+
textarea.select();
|
|
3097
|
+
const success = document.execCommand("copy");
|
|
3098
|
+
document.body.removeChild(textarea);
|
|
3099
|
+
return success;
|
|
3100
|
+
} catch {
|
|
3101
|
+
return false;
|
|
3102
|
+
}
|
|
3103
|
+
};
|
|
3104
|
+
var readFromClipboard = async () => {
|
|
3105
|
+
try {
|
|
3106
|
+
if (navigator.clipboard && navigator.clipboard.readText) {
|
|
3107
|
+
return await navigator.clipboard.readText();
|
|
3108
|
+
}
|
|
3109
|
+
return "";
|
|
3110
|
+
} catch {
|
|
3111
|
+
return "";
|
|
3112
|
+
}
|
|
3113
|
+
};
|
|
3114
|
+
|
|
3115
|
+
// src/modules/crypto/index.ts
|
|
3116
|
+
var crypto_exports = {};
|
|
3117
|
+
__export(crypto_exports, {
|
|
3118
|
+
CryptoJS: () => CryptoJS,
|
|
3119
|
+
aesDecrypt: () => aesDecrypt,
|
|
3120
|
+
aesEncrypt: () => aesEncrypt,
|
|
3121
|
+
base64Decode: () => base64Decode,
|
|
3122
|
+
base64Encode: () => base64Encode,
|
|
3123
|
+
desDecrypt: () => desDecrypt,
|
|
3124
|
+
desEncrypt: () => desEncrypt,
|
|
3125
|
+
generateIV: () => generateIV,
|
|
3126
|
+
generateKey: () => generateKey,
|
|
3127
|
+
hexDecode: () => hexDecode,
|
|
3128
|
+
hexEncode: () => hexEncode,
|
|
3129
|
+
hmacMD5: () => hmacMD5,
|
|
3130
|
+
hmacSHA1: () => hmacSHA1,
|
|
3131
|
+
hmacSHA256: () => hmacSHA256,
|
|
3132
|
+
hmacSHA512: () => hmacSHA512,
|
|
3133
|
+
md5: () => md5,
|
|
3134
|
+
pbkdf2: () => pbkdf2,
|
|
3135
|
+
rabbitDecrypt: () => rabbitDecrypt,
|
|
3136
|
+
rabbitEncrypt: () => rabbitEncrypt,
|
|
3137
|
+
rc4Decrypt: () => rc4Decrypt,
|
|
3138
|
+
rc4Encrypt: () => rc4Encrypt,
|
|
3139
|
+
sha1: () => sha1,
|
|
3140
|
+
sha256: () => sha256,
|
|
3141
|
+
sha512: () => sha512,
|
|
3142
|
+
tripleDesDecrypt: () => tripleDesDecrypt,
|
|
3143
|
+
tripleDesEncrypt: () => tripleDesEncrypt,
|
|
3144
|
+
utf8Decode: () => utf8Decode,
|
|
3145
|
+
utf8Encode: () => utf8Encode,
|
|
3146
|
+
uuid: () => uuid2
|
|
3147
|
+
});
|
|
3148
|
+
var md5 = (message) => {
|
|
3149
|
+
return CryptoJS.MD5(message).toString();
|
|
3150
|
+
};
|
|
3151
|
+
var sha1 = (message) => {
|
|
3152
|
+
return CryptoJS.SHA1(message).toString();
|
|
3153
|
+
};
|
|
3154
|
+
var sha256 = (message) => {
|
|
3155
|
+
return CryptoJS.SHA256(message).toString();
|
|
3156
|
+
};
|
|
3157
|
+
var sha512 = (message) => {
|
|
3158
|
+
return CryptoJS.SHA512(message).toString();
|
|
3159
|
+
};
|
|
3160
|
+
var hmacMD5 = (message, key) => {
|
|
3161
|
+
return CryptoJS.HmacMD5(message, key).toString();
|
|
3162
|
+
};
|
|
3163
|
+
var hmacSHA1 = (message, key) => {
|
|
3164
|
+
return CryptoJS.HmacSHA1(message, key).toString();
|
|
3165
|
+
};
|
|
3166
|
+
var hmacSHA256 = (message, key) => {
|
|
3167
|
+
return CryptoJS.HmacSHA256(message, key).toString();
|
|
3168
|
+
};
|
|
3169
|
+
var hmacSHA512 = (message, key) => {
|
|
3170
|
+
return CryptoJS.HmacSHA512(message, key).toString();
|
|
3171
|
+
};
|
|
3172
|
+
var aesEncrypt = (message, key, iv, mode2 = CryptoJS.mode.CBC, padding = CryptoJS.pad.Pkcs7) => {
|
|
3173
|
+
const keyWord = CryptoJS.enc.Utf8.parse(key);
|
|
3174
|
+
const ivWord = iv ? CryptoJS.enc.Utf8.parse(iv) : void 0;
|
|
3175
|
+
const encrypted = CryptoJS.AES.encrypt(message, keyWord, {
|
|
3176
|
+
iv: ivWord,
|
|
3177
|
+
mode: mode2,
|
|
3178
|
+
padding
|
|
3179
|
+
});
|
|
3180
|
+
return encrypted.toString();
|
|
3181
|
+
};
|
|
3182
|
+
var aesDecrypt = (ciphertext, key, iv, mode2 = CryptoJS.mode.CBC, padding = CryptoJS.pad.Pkcs7) => {
|
|
3183
|
+
const keyWord = CryptoJS.enc.Utf8.parse(key);
|
|
3184
|
+
const ivWord = iv ? CryptoJS.enc.Utf8.parse(iv) : void 0;
|
|
3185
|
+
const decrypted = CryptoJS.AES.decrypt(ciphertext, keyWord, {
|
|
3186
|
+
iv: ivWord,
|
|
3187
|
+
mode: mode2,
|
|
3188
|
+
padding
|
|
3189
|
+
});
|
|
3190
|
+
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
3191
|
+
};
|
|
3192
|
+
var desEncrypt = (message, key, iv, mode2 = CryptoJS.mode.CBC, padding = CryptoJS.pad.Pkcs7) => {
|
|
3193
|
+
const keyWord = CryptoJS.enc.Utf8.parse(key);
|
|
3194
|
+
const ivWord = iv ? CryptoJS.enc.Utf8.parse(iv) : void 0;
|
|
3195
|
+
const encrypted = CryptoJS.DES.encrypt(message, keyWord, {
|
|
3196
|
+
iv: ivWord,
|
|
3197
|
+
mode: mode2,
|
|
3198
|
+
padding
|
|
3199
|
+
});
|
|
3200
|
+
return encrypted.toString();
|
|
3201
|
+
};
|
|
3202
|
+
var desDecrypt = (ciphertext, key, iv, mode2 = CryptoJS.mode.CBC, padding = CryptoJS.pad.Pkcs7) => {
|
|
3203
|
+
const keyWord = CryptoJS.enc.Utf8.parse(key);
|
|
3204
|
+
const ivWord = iv ? CryptoJS.enc.Utf8.parse(iv) : void 0;
|
|
3205
|
+
const decrypted = CryptoJS.DES.decrypt(ciphertext, keyWord, {
|
|
3206
|
+
iv: ivWord,
|
|
3207
|
+
mode: mode2,
|
|
3208
|
+
padding
|
|
3209
|
+
});
|
|
3210
|
+
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
3211
|
+
};
|
|
3212
|
+
var tripleDesEncrypt = (message, key, iv, mode2 = CryptoJS.mode.CBC, padding = CryptoJS.pad.Pkcs7) => {
|
|
3213
|
+
const keyWord = CryptoJS.enc.Utf8.parse(key);
|
|
3214
|
+
const ivWord = iv ? CryptoJS.enc.Utf8.parse(iv) : void 0;
|
|
3215
|
+
const encrypted = CryptoJS.TripleDES.encrypt(message, keyWord, {
|
|
3216
|
+
iv: ivWord,
|
|
3217
|
+
mode: mode2,
|
|
3218
|
+
padding
|
|
3219
|
+
});
|
|
3220
|
+
return encrypted.toString();
|
|
3221
|
+
};
|
|
3222
|
+
var tripleDesDecrypt = (ciphertext, key, iv, mode2 = CryptoJS.mode.CBC, padding = CryptoJS.pad.Pkcs7) => {
|
|
3223
|
+
const keyWord = CryptoJS.enc.Utf8.parse(key);
|
|
3224
|
+
const ivWord = iv ? CryptoJS.enc.Utf8.parse(iv) : void 0;
|
|
3225
|
+
const decrypted = CryptoJS.TripleDES.decrypt(ciphertext, keyWord, {
|
|
3226
|
+
iv: ivWord,
|
|
3227
|
+
mode: mode2,
|
|
3228
|
+
padding
|
|
3229
|
+
});
|
|
3230
|
+
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
3231
|
+
};
|
|
3232
|
+
var rc4Encrypt = (message, key) => {
|
|
3233
|
+
const encrypted = CryptoJS.RC4.encrypt(message, key);
|
|
3234
|
+
return encrypted.toString();
|
|
3235
|
+
};
|
|
3236
|
+
var rc4Decrypt = (ciphertext, key) => {
|
|
3237
|
+
const decrypted = CryptoJS.RC4.decrypt(ciphertext, key);
|
|
3238
|
+
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
3239
|
+
};
|
|
3240
|
+
var rabbitEncrypt = (message, key) => {
|
|
3241
|
+
const encrypted = CryptoJS.Rabbit.encrypt(message, key);
|
|
3242
|
+
return encrypted.toString();
|
|
3243
|
+
};
|
|
3244
|
+
var rabbitDecrypt = (ciphertext, key) => {
|
|
3245
|
+
const decrypted = CryptoJS.Rabbit.decrypt(ciphertext, key);
|
|
3246
|
+
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
3247
|
+
};
|
|
3248
|
+
var base64Encode = (message) => {
|
|
3249
|
+
return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(message));
|
|
3250
|
+
};
|
|
3251
|
+
var base64Decode = (encoded) => {
|
|
3252
|
+
return CryptoJS.enc.Base64.parse(encoded).toString(CryptoJS.enc.Utf8);
|
|
3253
|
+
};
|
|
3254
|
+
var utf8Encode = (message) => {
|
|
3255
|
+
return CryptoJS.enc.Utf8.stringify(CryptoJS.enc.Utf8.parse(message));
|
|
3256
|
+
};
|
|
3257
|
+
var utf8Decode = (encoded) => {
|
|
3258
|
+
return CryptoJS.enc.Utf8.parse(encoded).toString(CryptoJS.enc.Utf8);
|
|
3259
|
+
};
|
|
3260
|
+
var hexEncode = (message) => {
|
|
3261
|
+
return CryptoJS.enc.Hex.stringify(CryptoJS.enc.Utf8.parse(message));
|
|
3262
|
+
};
|
|
3263
|
+
var hexDecode = (encoded) => {
|
|
3264
|
+
return CryptoJS.enc.Hex.parse(encoded).toString(CryptoJS.enc.Utf8);
|
|
3265
|
+
};
|
|
3266
|
+
var generateKey = (length = 32) => {
|
|
3267
|
+
const key = CryptoJS.lib.WordArray.random(length);
|
|
3268
|
+
return CryptoJS.enc.Base64.stringify(key);
|
|
3269
|
+
};
|
|
3270
|
+
var generateIV = (length = 16) => {
|
|
3271
|
+
const iv = CryptoJS.lib.WordArray.random(length);
|
|
3272
|
+
return CryptoJS.enc.Base64.stringify(iv);
|
|
3273
|
+
};
|
|
3274
|
+
var pbkdf2 = (password, salt, iterations = 1e3, keySize = 32) => {
|
|
3275
|
+
const key = CryptoJS.PBKDF2(password, salt, {
|
|
3276
|
+
keySize: keySize / 4,
|
|
3277
|
+
iterations
|
|
3278
|
+
});
|
|
3279
|
+
return key.toString();
|
|
3280
|
+
};
|
|
3281
|
+
var uuid2 = () => {
|
|
3282
|
+
return CryptoJS.lib.WordArray.random(16).toString();
|
|
3283
|
+
};
|
|
3284
|
+
/**
|
|
3285
|
+
* Utils Toolkit
|
|
3286
|
+
* 一个功能强大的 JavaScript/TypeScript 工具函数库
|
|
3287
|
+
*
|
|
3288
|
+
* @version 1.0.0
|
|
3289
|
+
* @license MIT
|
|
3290
|
+
*/
|
|
3291
|
+
|
|
3292
|
+
export { array_exports as array, crypto_exports as crypto, date_exports as date, excel_exports as excel, map_exports as map, object_exports as object, pdf_exports as pdf, storage_exports as storage, string_exports as string, utils_exports as utils };
|
|
3293
|
+
//# sourceMappingURL=index.js.map
|
|
3294
|
+
//# sourceMappingURL=index.js.map
|