ranui 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/dist/add-user-b2bed3e7.js +4 -0
  2. package/dist/book-b11a68eb.js +4 -0
  3. package/dist/build/config.d.ts +3 -0
  4. package/dist/check-circle-74bd09c3.js +4 -0
  5. package/dist/check-circle-fill-dc284144.js +4 -0
  6. package/dist/close-20925345.js +4 -0
  7. package/dist/close-circle-720c18be.js +4 -0
  8. package/dist/close-circle-fill-238a66b1.js +4 -0
  9. package/dist/components/button/index.js +4 -2
  10. package/dist/components/icon/index.js +3 -1
  11. package/dist/components/image/index.js +1 -1
  12. package/dist/components/input/index.js +2 -2
  13. package/dist/components/message/index.d.ts +12 -6
  14. package/dist/components/message/index.js +1 -2
  15. package/dist/components/modal/index.js +4 -0
  16. package/dist/components/option/index.d.ts +2 -0
  17. package/dist/components/option/index.js +95 -0
  18. package/dist/components/{video → player}/index.d.ts +198 -87
  19. package/dist/components/player/index.js +11 -0
  20. package/dist/components/preview/excel/excel.d.ts +0 -9
  21. package/dist/components/preview/index.d.ts +4 -0
  22. package/dist/components/preview/index.js +5 -4
  23. package/dist/components/progress/index.d.ts +36 -0
  24. package/dist/components/progress/index.js +8 -0
  25. package/dist/components/radar/index.js +4 -2
  26. package/dist/components/select/index.d.ts +101 -0
  27. package/dist/components/select/index.js +11 -0
  28. package/dist/components/skeleton/index.js +1 -1
  29. package/dist/components/tab/index.js +4 -2
  30. package/dist/components/tabpane/index.js +1 -1
  31. package/dist/docx-c5d02d8c.js +21 -0
  32. package/dist/eye-5e742329.js +4 -0
  33. package/dist/eye-close-3874f1ae.js +4 -0
  34. package/dist/hls/5_1700986031916/5.key +1 -0
  35. package/dist/hls/5_1700986031916/5.m3u8 +12 -0
  36. package/dist/hls/5_1700986031916/5_00000.ts +0 -0
  37. package/dist/hls/5_1700986031916/5_00001.ts +0 -0
  38. package/dist/hls/5_1700986031916/5_00002.ts +0 -0
  39. package/dist/hls/5_1700986110178/5.key +1 -0
  40. package/dist/hls/5_1700986110178/5.m3u8 +12 -0
  41. package/dist/hls/5_1700986110178/5_00000.ts +0 -0
  42. package/dist/hls/5_1700986110178/5_00001.ts +0 -0
  43. package/dist/hls/5_1700986110178/5_00002.ts +0 -0
  44. package/dist/hls/example.m3u8 +5 -0
  45. package/dist/home-c4a05e8b.js +4 -0
  46. package/dist/index-0e7229ea.js +328 -0
  47. package/dist/index-183517e7.js +265 -0
  48. package/dist/index-48653b79.js +162 -0
  49. package/dist/index-4d873a42.js +195 -0
  50. package/dist/index-57492b9b.js +48 -0
  51. package/dist/index-5975bbc0.js +126 -0
  52. package/dist/{index-64d03ac1.js → index-7b8840f9.js} +1 -4
  53. package/dist/index-7f513a14.js +175 -0
  54. package/dist/index-8e1e2573.js +19 -0
  55. package/dist/index-a1a53af6.js +354 -0
  56. package/dist/index-a216f328.js +662 -0
  57. package/dist/index-a43b144f.js +232 -0
  58. package/dist/index-aea75a9f.js +78 -0
  59. package/dist/index-b2be6bef.js +10423 -0
  60. package/dist/index-b90299ca.js +43 -0
  61. package/dist/index-d2d69b06.js +225 -0
  62. package/dist/index-ecaed5cc.js +439 -0
  63. package/dist/index-f6d6982d.js +516 -0
  64. package/dist/index.d.ts +4 -0
  65. package/dist/index.js +23 -13
  66. package/dist/info-circle-5826decc.js +4 -0
  67. package/dist/info-circle-fill-90ec9aa9.js +14 -0
  68. package/dist/loading-09ca52df.js +4 -0
  69. package/dist/lock-1d2487c9.js +4 -0
  70. package/dist/message-b2bfdea7.js +4 -0
  71. package/dist/{pdf-6e38f826.js → pdf-bdb7818a.js} +1 -2
  72. package/dist/playwright.config.d.ts +0 -2
  73. package/dist/power-off-6ade5a91.js +4 -0
  74. package/dist/preview-b291aea8.js +4 -0
  75. package/dist/setting-1e5ccb6d.js +4 -0
  76. package/dist/style.css +1 -1
  77. package/dist/team-ca6a12e1.js +4 -0
  78. package/dist/umd/build/config.d.ts +3 -0
  79. package/dist/umd/components/message/index.d.ts +12 -6
  80. package/dist/umd/components/option/index.d.ts +2 -0
  81. package/dist/umd/components/{video → player}/index.d.ts +198 -87
  82. package/dist/umd/components/preview/excel/excel.d.ts +0 -9
  83. package/dist/umd/components/preview/index.d.ts +4 -0
  84. package/dist/umd/components/progress/index.d.ts +36 -0
  85. package/dist/umd/components/select/index.d.ts +101 -0
  86. package/dist/umd/hls/5_1700986031916/5.key +1 -0
  87. package/dist/umd/hls/5_1700986031916/5.m3u8 +12 -0
  88. package/dist/umd/hls/5_1700986031916/5_00000.ts +0 -0
  89. package/dist/umd/hls/5_1700986031916/5_00001.ts +0 -0
  90. package/dist/umd/hls/5_1700986031916/5_00002.ts +0 -0
  91. package/dist/umd/hls/5_1700986110178/5.key +1 -0
  92. package/dist/umd/hls/5_1700986110178/5.m3u8 +12 -0
  93. package/dist/umd/hls/5_1700986110178/5_00000.ts +0 -0
  94. package/dist/umd/hls/5_1700986110178/5_00001.ts +0 -0
  95. package/dist/umd/hls/5_1700986110178/5_00002.ts +0 -0
  96. package/dist/umd/hls/example.m3u8 +5 -0
  97. package/dist/umd/index.d.ts +4 -0
  98. package/dist/umd/index.umd.cjs +26 -8
  99. package/dist/umd/playwright.config.d.ts +0 -2
  100. package/dist/umd/style.css +1 -1
  101. package/dist/umd/utils/image.d.ts +32 -0
  102. package/dist/umd/utils/index.d.ts +41 -32
  103. package/dist/umd/utils/math.d.ts +26 -0
  104. package/dist/umd/utils/tween.d.ts +21 -0
  105. package/dist/unlock-f56086fd.js +4 -0
  106. package/dist/user-5c01e665.js +4 -0
  107. package/dist/utils/image.d.ts +32 -0
  108. package/dist/utils/index.d.ts +41 -32
  109. package/dist/utils/math.d.ts +26 -0
  110. package/dist/utils/tween.d.ts +21 -0
  111. package/dist/{index-a55c2dff.js → vendor-f71e6f68.js} +7771 -1268
  112. package/dist/warning-circle-035e025c.js +4 -0
  113. package/dist/warning-circle-fill-d17c37c9.js +4 -0
  114. package/package.json +38 -6
  115. package/readme.md +2 -3
  116. package/dist/_commonjs-dynamic-modules-2ceabb0b.js +0 -12
  117. package/dist/add-user-d07564bd.js +0 -4
  118. package/dist/assets/image/failImage.d.ts +0 -2
  119. package/dist/base-bcc748a2.js +0 -1
  120. package/dist/book-2a5a596c.js +0 -4
  121. package/dist/check-circle-2c986969.js +0 -4
  122. package/dist/check-circle-fill-62eaa796.js +0 -4
  123. package/dist/close-circle-2afb6e94.js +0 -4
  124. package/dist/close-circle-fill-b6906239.js +0 -4
  125. package/dist/close-ee3ba1d1.js +0 -4
  126. package/dist/docx-5262a8f1.js +0 -2635
  127. package/dist/eye-bd60afe1.js +0 -4
  128. package/dist/eye-close-bde3c1fc.js +0 -4
  129. package/dist/home-f824d8f4.js +0 -4
  130. package/dist/index-00913cab.js +0 -43
  131. package/dist/index-07c8e518.js +0 -327
  132. package/dist/index-105ed089.js +0 -127
  133. package/dist/index-2243317e.js +0 -155
  134. package/dist/index-441da303.js +0 -196
  135. package/dist/index-4459fbd0.js +0 -108
  136. package/dist/index-57d3be68.js +0 -450
  137. package/dist/index-a7db1b7b.js +0 -175
  138. package/dist/index-b580f377.js +0 -78
  139. package/dist/index-b99ac79f.js +0 -353
  140. package/dist/index-c558bde2.js +0 -218
  141. package/dist/info-circle-59333e1c.js +0 -4
  142. package/dist/info-circle-fill-3ab7660d.js +0 -4
  143. package/dist/jszip.min-97cf7c6a.js +0 -2655
  144. package/dist/loading-407d8249.js +0 -4
  145. package/dist/lock-6d20715b.js +0 -4
  146. package/dist/message-ee4fe153.js +0 -4
  147. package/dist/power-off-bbec6b5f.js +0 -4
  148. package/dist/preview-164a4944.js +0 -4
  149. package/dist/setting-735a1963.js +0 -4
  150. package/dist/team-42573142.js +0 -4
  151. package/dist/umd/assets/image/failImage.d.ts +0 -2
  152. package/dist/unlock-ae33c6f7.js +0 -4
  153. package/dist/user-b7098183.js +0 -4
  154. package/dist/warning-circle-536d4749.js +0 -4
  155. package/dist/warning-circle-fill-e4be98bc.js +0 -4
@@ -0,0 +1,662 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { e as exceljsExports, l as lodashExports, t as tinycolor, S as Spreadsheet } from "./vendor-f71e6f68.js";
8
+ import { t as timestampToTime } from "./index-d2d69b06.js";
9
+ import { g as getLightColor, a as getDarkColor } from "./colz-746223ab.js";
10
+ const themeColor = [
11
+ "#FFFFFF",
12
+ "#000000",
13
+ "#BFBFBF",
14
+ "#323232",
15
+ "#4472C4",
16
+ "#ED7D31",
17
+ "#A5A5A5",
18
+ "#FFC000",
19
+ "#5B9BD5",
20
+ "#71AD47"
21
+ ];
22
+ const indexedColor = [
23
+ "#000000",
24
+ "#FFFFFF",
25
+ "#FF0000",
26
+ "#00FF00",
27
+ "#0000FF",
28
+ "#FFFF00",
29
+ "#FF00FF",
30
+ "#00FFFF",
31
+ "#000000",
32
+ "#FFFFFF",
33
+ "#FF0000",
34
+ "#00FF00",
35
+ "#0000FF",
36
+ "#FFFF00",
37
+ "#FF00FF",
38
+ "#00FFFF",
39
+ "#800000",
40
+ "#008000",
41
+ "#000080",
42
+ "#808000",
43
+ "#800080",
44
+ "#008080",
45
+ "#C0C0C0",
46
+ "#808080",
47
+ "#9999FF",
48
+ "#993366",
49
+ "#FFFFCC",
50
+ "#CCFFFF",
51
+ "#660066",
52
+ "#FF8080",
53
+ "#0066CC",
54
+ "#CCCCFF",
55
+ "#000080",
56
+ "#FF00FF",
57
+ "#FFFF00",
58
+ "#00FFFF",
59
+ "#800080",
60
+ "#800000",
61
+ "#008080",
62
+ "#0000FF",
63
+ "#00CCFF",
64
+ "#CCFFFF",
65
+ "#CCFFCC",
66
+ "#FFFF99",
67
+ "#99CCFF",
68
+ "#FF99CC",
69
+ "#CC99FF",
70
+ "#FFCC99",
71
+ "#3366FF",
72
+ "#33CCCC",
73
+ "#99CC00",
74
+ "#FFCC00",
75
+ "#FF9900",
76
+ "#FF6600",
77
+ "#666699",
78
+ "#969696",
79
+ "#003366",
80
+ "#339966",
81
+ "#003300",
82
+ "#333300",
83
+ "#993300",
84
+ "#993366",
85
+ "#333399",
86
+ "#333333",
87
+ "#FFFFFF"
88
+ ];
89
+ const defaultColWidth$1 = 80;
90
+ const defaultRowHeight$1 = 24;
91
+ function readExcelData(buffer) {
92
+ try {
93
+ const wb = new exceljsExports.Workbook();
94
+ return wb.xlsx.load(buffer);
95
+ } catch (e) {
96
+ console.warn(e);
97
+ return Promise.reject(e);
98
+ }
99
+ }
100
+ function transferColumns(excelSheet, spreadSheet, options) {
101
+ for (let i = 0; i < (excelSheet.columns || []).length; i++) {
102
+ spreadSheet.cols[i.toString()] = {};
103
+ if (excelSheet.columns[i].width) {
104
+ spreadSheet.cols[i.toString()].width = excelSheet.columns[i].width * 6 + (options.widthOffset || 0);
105
+ } else {
106
+ spreadSheet.cols[i.toString()].width = defaultColWidth$1 + (options.widthOffset || 0);
107
+ }
108
+ }
109
+ spreadSheet.cols.len = Math.max(
110
+ Object.keys(spreadSheet.cols).length,
111
+ options.minColLength || 0
112
+ );
113
+ }
114
+ function getCellText(cell) {
115
+ const { numFmt, value, type } = cell;
116
+ switch (type) {
117
+ case 2:
118
+ try {
119
+ if (cell.style.numFmt) {
120
+ if (cell.style.numFmt.endsWith("%")) {
121
+ const precision = cell.style.numFmt.match(/\.(\d+)%/);
122
+ if (precision) {
123
+ return (Number(value) * 100).toFixed(precision[1].length) + "%";
124
+ } else {
125
+ return Number(value) * 100 + "%";
126
+ }
127
+ } else if (/0(?:\.0+)?/.test(cell.style.numFmt)) {
128
+ if (Number(value) === 0 && cell.style.numFmt.startsWith("_")) {
129
+ return "-";
130
+ }
131
+ let precision = cell.style.numFmt.match(/0\.(0+)(_|;|$)/);
132
+ if (precision) {
133
+ precision = precision[1].length;
134
+ } else {
135
+ precision = 0;
136
+ }
137
+ let result = Number(value).toFixed(precision) + "";
138
+ if (cell.style.numFmt.includes("#,##")) {
139
+ result = result.split(".");
140
+ const number = result[0].split("").reverse();
141
+ const newNumber = [];
142
+ for (let i = 0; i < number.length; i++) {
143
+ newNumber.push(number[i]);
144
+ if ((i + 1) % 3 === 0 && i < number.length - 1 && number[i + 1] !== "-") {
145
+ newNumber.push(",");
146
+ }
147
+ }
148
+ result[0] = newNumber.reverse().join("");
149
+ result = result.join(".");
150
+ }
151
+ return result;
152
+ }
153
+ }
154
+ return value + "";
155
+ } catch (e) {
156
+ return value;
157
+ }
158
+ case 3:
159
+ return value;
160
+ case 4:
161
+ switch (numFmt) {
162
+ case "mm-dd-yy":
163
+ return timestampToTime(value).format("YYYY/MM/DD");
164
+ case "[$-F800]dddd, mmmm dd, yyyy":
165
+ return timestampToTime(value).format("YYYY年M月D日 ddd");
166
+ case 'm"月"d"日";@':
167
+ return timestampToTime(value).format("M月D日");
168
+ case "yyyy/m/d h:mm;@":
169
+ case 'm/d/yy "h":mm':
170
+ return timestampToTime(value).subtract(8, "hour").format("YYYY/M/DD HH:mm");
171
+ case "h:mm;@":
172
+ return timestampToTime(value).format("HH:mm");
173
+ default:
174
+ return timestampToTime(value).format("YYYY-MM-DD");
175
+ }
176
+ case 5:
177
+ return value.text;
178
+ case 6:
179
+ return lodashExports.get(value, "result.error") || value.result;
180
+ case 8:
181
+ return cell.text;
182
+ default:
183
+ return value;
184
+ }
185
+ }
186
+ function transferArgbColor(originColor) {
187
+ if (typeof originColor === "object") {
188
+ return "#000000";
189
+ }
190
+ if (/^#?[a-f\d]{6}$/i.test(originColor)) {
191
+ return originColor.startsWith("#") ? originColor : "#" + originColor;
192
+ }
193
+ originColor = originColor.trim().toLowerCase();
194
+ const color = {};
195
+ try {
196
+ const argb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(
197
+ originColor
198
+ ) || "";
199
+ color.r = parseInt(argb[2], 16);
200
+ color.g = parseInt(argb[3], 16);
201
+ color.b = parseInt(argb[4], 16);
202
+ color.a = parseInt(argb[1], 16) / 255;
203
+ return tinycolor(
204
+ `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a})`
205
+ ).toHexString();
206
+ } catch (e) {
207
+ console.warn(e);
208
+ }
209
+ }
210
+ function transferThemeColor(themeIndex, tint) {
211
+ if (themeIndex > 9) {
212
+ return "#C7C9CC";
213
+ }
214
+ if (typeof tint === "undefined") {
215
+ return themeColor[themeIndex];
216
+ } else if (tint > 0) {
217
+ return getLightColor(themeColor[themeIndex], tint);
218
+ } else {
219
+ return getDarkColor(themeColor[themeIndex], Math.abs(tint));
220
+ }
221
+ }
222
+ function getStyle(cell) {
223
+ cell.style = lodashExports.cloneDeep(cell.style);
224
+ let backGroundColor = null;
225
+ if (cell.style.fill && cell.style.fill.fgColor) {
226
+ if (cell.style.fill.fgColor.argb) {
227
+ backGroundColor = transferArgbColor(cell.style.fill.fgColor.argb);
228
+ } else if (Object.prototype.hasOwnProperty.call(cell.style.fill.fgColor, "theme")) {
229
+ backGroundColor = transferThemeColor(
230
+ cell.style.fill.fgColor.theme,
231
+ cell.style.fill.fgColor.tint
232
+ );
233
+ } else if (cell.style.fill.fgColor.indexed) {
234
+ backGroundColor = indexedColor[cell.style.fill.fgColor.indexed] || "#C7C9CC";
235
+ } else {
236
+ backGroundColor = "#C7C9CC";
237
+ }
238
+ }
239
+ if (backGroundColor) {
240
+ cell.style.bgcolor = backGroundColor;
241
+ }
242
+ let fontColor = null;
243
+ if (cell.style.font && cell.style.font.color) {
244
+ if (cell.style.font.color.argb) {
245
+ fontColor = transferArgbColor(cell.style.font.color.argb);
246
+ } else if (Object.prototype.hasOwnProperty.call(cell.style.font.color, "theme")) {
247
+ fontColor = transferThemeColor(
248
+ cell.style.font.color.theme,
249
+ cell.style.font.color.tint
250
+ );
251
+ } else if (cell.style.font.color.indexed) {
252
+ fontColor = indexedColor[cell.style.font.color.indexed] || "#000000";
253
+ } else {
254
+ fontColor = "#000000";
255
+ }
256
+ }
257
+ if (fontColor) {
258
+ cell.style.color = fontColor;
259
+ }
260
+ if (cell.style.alignment) {
261
+ if (cell.style.alignment.horizontal) {
262
+ cell.style.align = cell.style.alignment.horizontal;
263
+ }
264
+ if (cell.style.alignment.vertical) {
265
+ cell.style.valign = cell.style.alignment.vertical;
266
+ }
267
+ }
268
+ if (cell.style.alignment && cell.style.alignment.wrapText) {
269
+ cell.style.textwrap = true;
270
+ }
271
+ if (cell.style.border) {
272
+ const styleBorder = {};
273
+ Object.keys(cell.style.border).forEach((position) => {
274
+ const originBorder = cell.style.border[position];
275
+ let bordColor = "#000000";
276
+ if (typeof originBorder.color === "string") {
277
+ bordColor = originBorder.color;
278
+ } else if (originBorder.color) {
279
+ if (originBorder.color.argb) {
280
+ bordColor = transferArgbColor(originBorder.color.argb) || "";
281
+ } else if (Object.prototype.hasOwnProperty.call(originBorder.color, "theme")) {
282
+ bordColor = transferThemeColor(
283
+ originBorder.color.theme,
284
+ originBorder.color.tint
285
+ );
286
+ } else if (originBorder.color.indexed) {
287
+ bordColor = indexedColor[originBorder.color.indexed];
288
+ }
289
+ }
290
+ styleBorder[position] = [originBorder.style || "thin", bordColor];
291
+ });
292
+ cell.style.border2 = { ...cell.style.border };
293
+ cell.style.border = styleBorder;
294
+ }
295
+ return cell.style;
296
+ }
297
+ function transferExcelToSpreadSheet(workbook, options) {
298
+ const workbookData = [];
299
+ workbook.eachSheet((sheet) => {
300
+ const sheetData = {
301
+ name: sheet.name,
302
+ styles: [],
303
+ rows: {},
304
+ cols: {},
305
+ merges: [],
306
+ media: []
307
+ };
308
+ const mergeAddressData = [];
309
+ for (const mergeRange in sheet._merges) {
310
+ sheetData.merges.push(sheet._merges[mergeRange].shortRange);
311
+ const mergeAddress = {};
312
+ mergeAddress.startAddress = sheet._merges[mergeRange].tl;
313
+ mergeAddress.endAddress = sheet._merges[mergeRange].br;
314
+ mergeAddress.YRange = sheet._merges[mergeRange].model.bottom - sheet._merges[mergeRange].model.top;
315
+ mergeAddress.XRange = sheet._merges[mergeRange].model.right - sheet._merges[mergeRange].model.left;
316
+ mergeAddressData.push(mergeAddress);
317
+ }
318
+ transferColumns(sheet, sheetData, options);
319
+ (sheet._rows || []).forEach((row, spreadSheetRowIndex) => {
320
+ sheetData.rows[spreadSheetRowIndex] = { cells: {} };
321
+ if (row.height) {
322
+ sheetData.rows[spreadSheetRowIndex].height = row.height + (options.heightOffset || 0);
323
+ } else {
324
+ sheetData.rows[spreadSheetRowIndex].height = defaultRowHeight$1 + (options.heightOffset || 0);
325
+ }
326
+ (row._cells || []).forEach((cell, spreadSheetColIndex) => {
327
+ sheetData.rows[spreadSheetRowIndex].cells[spreadSheetColIndex] = {};
328
+ const mergeAddress = lodashExports.find(mergeAddressData, function(o) {
329
+ return o.startAddress === cell._address;
330
+ });
331
+ if (mergeAddress && cell.master.address !== mergeAddress.startAddress) {
332
+ return;
333
+ }
334
+ if (mergeAddress) {
335
+ sheetData.rows[spreadSheetRowIndex].cells[spreadSheetColIndex].merge = [mergeAddress.YRange, mergeAddress.XRange];
336
+ }
337
+ sheetData.rows[spreadSheetRowIndex].cells[spreadSheetColIndex].text = getCellText(cell);
338
+ sheetData.styles.push(getStyle(cell));
339
+ sheetData.rows[spreadSheetRowIndex].cells[spreadSheetColIndex].style = sheetData.styles.length - 1;
340
+ });
341
+ });
342
+ if (sheetData._media) {
343
+ sheetData.media = sheetData._media;
344
+ }
345
+ sheetData.rows.len = Math.max(Object.keys(sheetData.rows).length, 100);
346
+ workbookData.push(sheetData);
347
+ });
348
+ return {
349
+ workbookData,
350
+ workbookSource: workbook,
351
+ medias: workbook.media || []
352
+ };
353
+ }
354
+ let cache = [];
355
+ function renderImage(ctx, medias, sheet, offset) {
356
+ if (sheet && sheet._media.length) {
357
+ sheet._media.forEach((media) => {
358
+ const { imageId, range, type } = media;
359
+ if (type === "image") {
360
+ const position = calcPosition(sheet, range, offset);
361
+ drawImage(ctx, imageId, medias[imageId], position);
362
+ }
363
+ });
364
+ }
365
+ }
366
+ const clipWidth = 60;
367
+ const clipHeight = 25;
368
+ const defaultColWidth = 80;
369
+ const defaultRowHeight = 24;
370
+ const devicePixelRatio = window.devicePixelRatio;
371
+ function calcPosition(sheet, range, offset) {
372
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
373
+ const { tl = {}, br = {} } = range;
374
+ const { nativeCol, nativeColOff, nativeRow, nativeRowOff } = tl;
375
+ let basicX = clipWidth;
376
+ let basicY = clipHeight;
377
+ for (let i = 0; i < nativeCol; i++) {
378
+ basicX += ((_b = (_a = sheet == null ? void 0 : sheet._columns) == null ? void 0 : _a[i]) == null ? void 0 : _b.width) * 6 || defaultColWidth;
379
+ }
380
+ for (let i = 0; i < nativeRow; i++) {
381
+ basicY += ((_d = (_c = sheet == null ? void 0 : sheet._rows) == null ? void 0 : _c[i]) == null ? void 0 : _d.height) || defaultRowHeight;
382
+ }
383
+ const x = basicX + nativeColOff / 12700;
384
+ const y = basicY + nativeRowOff / 12700;
385
+ const {
386
+ nativeCol: nativeColEnd,
387
+ nativeColOff: nativeColOffEnd,
388
+ nativeRow: nativeRowEnd,
389
+ nativeRowOff: nativeRowOffEnd
390
+ } = br;
391
+ let width;
392
+ if (nativeCol === nativeColEnd) {
393
+ width = (nativeColOffEnd - nativeColOff) / 12700;
394
+ } else {
395
+ width = (((_f = (_e = sheet == null ? void 0 : sheet._columns) == null ? void 0 : _e[nativeCol]) == null ? void 0 : _f.width) * 6 || defaultColWidth) - nativeColOff / 12700;
396
+ for (let i = nativeCol + 1; i < nativeColEnd; i++) {
397
+ width += ((_h = (_g = sheet == null ? void 0 : sheet._columns) == null ? void 0 : _g[i]) == null ? void 0 : _h.width) * 6 || defaultColWidth;
398
+ }
399
+ width += nativeColOffEnd / 12700;
400
+ }
401
+ let height;
402
+ if (nativeRow === nativeRowEnd) {
403
+ height = (nativeRowOffEnd - nativeRowOff) / 12700;
404
+ } else {
405
+ height = (((_j = (_i = sheet == null ? void 0 : sheet._rows) == null ? void 0 : _i[nativeRow]) == null ? void 0 : _j.height) || defaultRowHeight) - nativeRowOff / 12700;
406
+ for (let i = nativeRow + 1; i < nativeRowEnd; i++) {
407
+ height += ((_l = (_k = sheet == null ? void 0 : sheet._rows) == null ? void 0 : _k[i]) == null ? void 0 : _l.height) || defaultRowHeight;
408
+ }
409
+ height += nativeRowOffEnd / 12700;
410
+ }
411
+ return {
412
+ x: (x - (((_m = offset == null ? void 0 : offset.scroll) == null ? void 0 : _m.x) || 0)) * devicePixelRatio,
413
+ y: (y - (((_n = offset == null ? void 0 : offset.scroll) == null ? void 0 : _n.y) || 0)) * devicePixelRatio,
414
+ width: width * devicePixelRatio,
415
+ height: height * devicePixelRatio
416
+ };
417
+ }
418
+ function clearCache() {
419
+ cache = [];
420
+ }
421
+ function drawImage(ctx, index, data, position) {
422
+ getImage(index, data).then((image) => {
423
+ let sx = 0;
424
+ let sy = 0;
425
+ let sWidth = image.width;
426
+ let sHeight = image.height;
427
+ let dx = position.x;
428
+ let dy = position.y;
429
+ let dWidth = position.width;
430
+ let dHeight = position.height;
431
+ const scaleX = dWidth / sWidth;
432
+ const scaleY = dHeight / sHeight;
433
+ if (dx < clipWidth * devicePixelRatio) {
434
+ const diff = clipWidth * devicePixelRatio - dx;
435
+ dx = clipWidth * devicePixelRatio;
436
+ dWidth -= diff;
437
+ sWidth -= diff / scaleX;
438
+ sx += diff / scaleX;
439
+ }
440
+ if (dy < clipHeight * devicePixelRatio) {
441
+ const diff = clipHeight * devicePixelRatio - dy;
442
+ dy = clipHeight * devicePixelRatio;
443
+ dHeight -= diff;
444
+ sHeight -= diff / scaleY;
445
+ sy += diff / scaleY;
446
+ }
447
+ ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
448
+ }).catch((e) => {
449
+ });
450
+ }
451
+ function getImage(index, data) {
452
+ return new Promise((resolve, reject) => {
453
+ if (cache[index]) {
454
+ return resolve(cache[index]);
455
+ }
456
+ const { buffer, extension } = data.buffer;
457
+ const blob = new Blob([buffer], { type: "image/" + extension });
458
+ const url = URL.createObjectURL(blob);
459
+ const image = new Image();
460
+ image.src = url;
461
+ image.onload = function() {
462
+ resolve(image);
463
+ cache[index] = image;
464
+ };
465
+ image.onerror = function(e) {
466
+ reject(e);
467
+ };
468
+ });
469
+ }
470
+ function readOnlyInput(root) {
471
+ if (root) {
472
+ const nodes = root.querySelectorAll("input");
473
+ for (const node of nodes) {
474
+ node && !node.readOnly && (node.readOnly = true);
475
+ }
476
+ }
477
+ }
478
+ const defaultOptions = {
479
+ minColLength: 20
480
+ };
481
+ class JsExcelPreview {
482
+ constructor(container, options = {}) {
483
+ __publicField(this, "container");
484
+ __publicField(this, "options", {});
485
+ __publicField(this, "wrapper");
486
+ __publicField(this, "wrapperMain");
487
+ __publicField(this, "xs");
488
+ __publicField(this, "sheetIndex");
489
+ __publicField(this, "mediasSource");
490
+ __publicField(this, "workbookDataSource");
491
+ __publicField(this, "ctx");
492
+ __publicField(this, "fileData");
493
+ __publicField(this, "observer");
494
+ __publicField(this, "offset");
495
+ this.container = container;
496
+ this.options = { ...defaultOptions, ...options };
497
+ this.sheetIndex = 1;
498
+ this.mediasSource = {};
499
+ this.workbookDataSource = {
500
+ _worksheets: []
501
+ };
502
+ this.createWrapper();
503
+ this.initSpreadsheet();
504
+ this.hack();
505
+ }
506
+ createWrapper() {
507
+ this.wrapper = document.createElement("div");
508
+ this.wrapper.className = "r-preview-excel-main";
509
+ this.container.appendChild(this.wrapper);
510
+ }
511
+ initSpreadsheet() {
512
+ var _a;
513
+ if (!this.wrapper)
514
+ return;
515
+ this.xs = new Spreadsheet(this.wrapper, {
516
+ mode: "read",
517
+ showToolbar: false,
518
+ showContextmenu: this.options.showContextmenu || false,
519
+ view: {
520
+ height: () => this.wrapper && this.wrapper.clientHeight || 300,
521
+ width: () => this.wrapper && this.wrapper.clientWidth || 1200
522
+ },
523
+ row: {
524
+ height: 24,
525
+ len: 100
526
+ },
527
+ col: {
528
+ len: 26,
529
+ width: 80,
530
+ indexWidth: 60,
531
+ minWidth: 60
532
+ }
533
+ // autoFocus: false
534
+ }).loadData({});
535
+ if (!this.xs)
536
+ return;
537
+ if (this.xs.bottombar) {
538
+ const swapFunc = this.xs.bottombar.swapFunc;
539
+ this.xs.bottombar.swapFunc = (index) => {
540
+ var _a2;
541
+ swapFunc.call((_a2 = this.xs) == null ? void 0 : _a2.bottombar, index);
542
+ this.sheetIndex = index + 1;
543
+ setTimeout(() => {
544
+ var _a3, _b;
545
+ ((_a3 = this.xs) == null ? void 0 : _a3.reRender) && ((_b = this.xs) == null ? void 0 : _b.reRender());
546
+ if (this.mediasSource && this.ctx && this.offset) {
547
+ renderImage(
548
+ this.ctx,
549
+ this.mediasSource,
550
+ this.workbookDataSource._worksheets[this.sheetIndex],
551
+ this.offset
552
+ );
553
+ }
554
+ });
555
+ };
556
+ }
557
+ if ((_a = this.xs.sheet) == null ? void 0 : _a.editor) {
558
+ const clear = this.xs.sheet.editor.clear;
559
+ this.xs.sheet.editor.clear = (...args) => {
560
+ var _a2, _b;
561
+ clear.apply((_b = (_a2 = this.xs) == null ? void 0 : _a2.sheet) == null ? void 0 : _b.editor, args);
562
+ setTimeout(() => {
563
+ if (this.ctx && this.mediasSource && this.offset) {
564
+ renderImage(
565
+ this.ctx,
566
+ this.mediasSource,
567
+ this.workbookDataSource._worksheets[this.sheetIndex],
568
+ this.offset
569
+ );
570
+ }
571
+ });
572
+ };
573
+ const setOffset = this.xs.sheet.editor.setOffset;
574
+ this.xs.sheet.editor.setOffset = (...args) => {
575
+ var _a2, _b;
576
+ setOffset.apply((_b = (_a2 = this.xs) == null ? void 0 : _a2.sheet) == null ? void 0 : _b.editor, args);
577
+ if (args.length > 1) {
578
+ this.offset = args.shift();
579
+ }
580
+ if (this.ctx && this.mediasSource && this.offset) {
581
+ renderImage(
582
+ this.ctx,
583
+ this.mediasSource,
584
+ this.workbookDataSource._worksheets[this.sheetIndex],
585
+ this.offset
586
+ );
587
+ }
588
+ };
589
+ }
590
+ const canvas = this.wrapper.querySelector("canvas");
591
+ if (canvas) {
592
+ this.ctx = canvas.getContext("2d");
593
+ }
594
+ }
595
+ renderExcel(buffer) {
596
+ this.fileData = buffer;
597
+ return readExcelData(buffer).then((workbook) => {
598
+ var _a;
599
+ if (!workbook._worksheets || workbook._worksheets.length === 0) {
600
+ throw new Error("未获取到数据,可能文件格式不正确或文件已损坏");
601
+ }
602
+ const { workbookData, medias, workbookSource } = transferExcelToSpreadSheet(workbook, this.options);
603
+ this.mediasSource = medias;
604
+ this.workbookDataSource = workbookSource;
605
+ this.offset = void 0;
606
+ this.sheetIndex = 1;
607
+ clearCache();
608
+ (_a = this.xs) == null ? void 0 : _a.loadData(workbookData);
609
+ if (this.ctx && this.mediasSource && this.offset) {
610
+ renderImage(
611
+ this.ctx,
612
+ this.mediasSource,
613
+ this.workbookDataSource._worksheets[this.sheetIndex],
614
+ this.offset
615
+ );
616
+ }
617
+ }).catch((e) => {
618
+ var _a;
619
+ this.mediasSource = [];
620
+ this.workbookDataSource = {
621
+ _worksheets: []
622
+ };
623
+ clearCache();
624
+ (_a = this.xs) == null ? void 0 : _a.loadData({});
625
+ return Promise.reject(e);
626
+ });
627
+ }
628
+ hack() {
629
+ if (!this.wrapper)
630
+ return;
631
+ const observerCallback = lodashExports.debounce(readOnlyInput, 200).bind(
632
+ this,
633
+ this.wrapper
634
+ );
635
+ this.observer = new MutationObserver(observerCallback);
636
+ const observerConfig = { attributes: true, childList: true, subtree: true };
637
+ this.observer.observe(this.wrapper, observerConfig);
638
+ observerCallback();
639
+ }
640
+ }
641
+ const renderExcel = (file, dom) => {
642
+ if (!dom)
643
+ return Promise.reject();
644
+ const Preview = new JsExcelPreview(dom);
645
+ const file2Array = () => new Promise((resolve, reject) => {
646
+ const reader = new FileReader();
647
+ reader.readAsArrayBuffer(file);
648
+ reader.onload = () => {
649
+ if (reader.result) {
650
+ resolve(reader == null ? void 0 : reader.result);
651
+ } else {
652
+ reject();
653
+ }
654
+ };
655
+ });
656
+ return file2Array().then((res) => {
657
+ Preview.renderExcel(res);
658
+ });
659
+ };
660
+ export {
661
+ renderExcel
662
+ };