sakura-preview-file 1.0.6 → 1.0.8

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 (41) hide show
  1. package/dist/index.es.js +666 -342
  2. package/dist/index.umd.js +1 -1
  3. package/dist/style.css +1 -1
  4. package/dist/types/hooks/index.d.ts +6 -0
  5. package/dist/types/hooks/use-file-preview-tools/index.d.ts +19 -0
  6. package/dist/types/hooks/use-file-state/index.d.ts +5 -0
  7. package/dist/types/hooks/use-mouse-event/index.d.ts +7 -0
  8. package/dist/types/hooks/use-namespace/index.d.ts +26 -0
  9. package/dist/types/hooks/use-preview-file/index.d.ts +5 -0
  10. package/dist/types/hooks/use-wheel-event/index.d.ts +14 -0
  11. package/dist/types/index.d.ts +8 -0
  12. package/dist/types/preview-file/Dialog/Dialog.vue.d.ts +37 -0
  13. package/dist/types/preview-file/Dialog/Overlay.vue.d.ts +18 -0
  14. package/dist/types/preview-file/Dialog/index.d.ts +2 -0
  15. package/dist/types/preview-file/Image/Close.vue.d.ts +7 -0
  16. package/dist/types/preview-file/Image/Image.vue.d.ts +12 -0
  17. package/dist/types/preview-file/Image/Preview.vue.d.ts +14 -0
  18. package/dist/types/preview-file/Image/ZoomIn.vue.d.ts +2 -0
  19. package/dist/types/preview-file/Image/ZoomOut.vue.d.ts +2 -0
  20. package/dist/types/preview-file/Loading/Circle.vue.d.ts +7 -0
  21. package/dist/types/preview-file/Loading/Cube.vue.d.ts +7 -0
  22. package/dist/types/preview-file/Loading/Dot.vue.d.ts +8 -0
  23. package/dist/types/preview-file/Loading/Progress.vue.d.ts +9 -0
  24. package/dist/types/preview-file/Loading/index.d.ts +26 -0
  25. package/dist/types/preview-file/Loading/props.d.ts +40 -0
  26. package/dist/types/preview-file/Pdf/Pdf.vue.d.ts +44 -0
  27. package/dist/types/preview-file/Pdf/use-preview-pdf.d.ts +9 -0
  28. package/dist/types/preview-file/Tools.vue.d.ts +37 -0
  29. package/dist/types/preview-file/Word/Word.vue.d.ts +39 -0
  30. package/dist/types/preview-file/constant.d.ts +6 -0
  31. package/dist/types/preview-file/event.d.ts +29 -0
  32. package/dist/types/preview-file/index.d.ts +7 -0
  33. package/dist/types/preview-file/preview-file-dialog.vue.d.ts +5 -0
  34. package/dist/types/preview-file/preview-file.vue.d.ts +53 -0
  35. package/dist/types/preview-file/register-component.d.ts +11 -0
  36. package/dist/types/preview-file/type.d.ts +110 -0
  37. package/dist/types/preview-file/utils.d.ts +6 -0
  38. package/dist/types/types/index.d.ts +1 -0
  39. package/dist/types/utils/index.d.ts +23 -0
  40. package/package.json +6 -5
  41. package/index.d.ts +0 -246
package/dist/index.es.js CHANGED
@@ -1,168 +1,9 @@
1
- import { defineComponent, computed, openBlock, createElementBlock, normalizeStyle, createElementVNode, Fragment, renderList, unref, ref, watchEffect, watch, mergeModels, useModel, renderSlot, normalizeClass, withDirectives, vModelText, toDisplayString, createCommentVNode, reactive, onMounted, toRefs, createVNode, createBlock, isRef, withCtx, nextTick, useTemplateRef, Teleport, provide, resolveDynamicComponent, normalizeProps, guardReactiveProps, vShow } from "vue";
2
- import { addUnit, isEmpty, FILE_TYPE, getFileType, base64ToFileUrl, blobToBase64, isBase64File, networkFileUrlToLocalFileUrl, numberToFixed, sleep, extend, base64ToFile, generateId, isPdfFile, isWordFile, isImageFile } from "sakura-utils";
1
+ import { unref, ref, computed, watchEffect, watch, getCurrentInstance, defineComponent, openBlock, createElementBlock, normalizeClass, createElementVNode, withModifiers, renderSlot, mergeModels, useModel, onMounted, onBeforeUnmount, createBlock, Teleport, createVNode, withCtx, normalizeStyle, toDisplayString, createCommentVNode, Fragment, renderList, withDirectives, vModelText, reactive, toRefs, isRef, nextTick, useTemplateRef, provide, resolveDynamicComponent, normalizeProps, guardReactiveProps, vShow, mergeProps, render } from "vue";
2
+ import { isEmpty, FILE_TYPE, getFileType, base64ToFileUrl, blobToBase64, isBase64File, networkFileUrlToLocalFileUrl, numberToFixed, addUnit, sleep, extend, base64ToFile, generateId, isPdfFile, isWordFile, isImageFile } from "sakura-utils";
3
+ import { useThrottleFn, useWindowSize } from "@vueuse/core";
3
4
  import VuePdfEmbed from "vue-pdf-embed";
4
5
  import "pdfjs-dist";
5
- import { useThrottleFn, useWindowSize } from "@vueuse/core";
6
6
  import { renderAsync } from "docx-preview";
7
- const index = "";
8
- const _hoisted_1$7 = ["stroke"];
9
- const _sfc_main$b = /* @__PURE__ */ defineComponent({
10
- __name: "Circle",
11
- props: {
12
- size: { default: 50 },
13
- color: { default: "#409eff" },
14
- duration: { default: 2 }
15
- },
16
- setup(__props) {
17
- const props = __props;
18
- const circleStyle = computed(() => {
19
- const { size, duration } = props;
20
- const style = {
21
- "--circle-size": addUnit(size),
22
- "--circle-duration": `${duration}s`
23
- };
24
- return style;
25
- });
26
- return (_ctx, _cache) => {
27
- return openBlock(), createElementBlock("svg", {
28
- class: "circular",
29
- viewBox: "0 0 50 50",
30
- style: normalizeStyle([circleStyle.value])
31
- }, [
32
- createElementVNode("circle", {
33
- class: "circular__path-inner",
34
- cx: "25",
35
- cy: "25",
36
- r: "20",
37
- fill: "none",
38
- stroke: __props.color,
39
- "stroke-width": "4",
40
- "stroke-miterlimit": "10"
41
- }, null, 8, _hoisted_1$7)
42
- ], 4);
43
- };
44
- }
45
- });
46
- const Circle_vue_vue_type_style_index_0_scoped_51d1fa15_lang = "";
47
- const _export_sfc = (sfc, props) => {
48
- const target = sfc.__vccOpts || sfc;
49
- for (const [key, val] of props) {
50
- target[key] = val;
51
- }
52
- return target;
53
- };
54
- const Circle = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["__scopeId", "data-v-51d1fa15"]]);
55
- const _sfc_main$a = /* @__PURE__ */ defineComponent({
56
- __name: "Dot",
57
- props: {
58
- gap: { default: 6 },
59
- color: { default: "var(--preview-file-primary-color)" },
60
- size: { default: 10 },
61
- duration: { default: 1.4 }
62
- },
63
- setup(__props) {
64
- const props = __props;
65
- const dotStyle = computed(() => {
66
- const { size, gap, duration, color } = props;
67
- const style = {
68
- "--dot-size": addUnit(size),
69
- "--dot-duration": `${duration}s`,
70
- "--dot-gap": addUnit(gap),
71
- "--dot-color": color
72
- };
73
- return style;
74
- });
75
- return (_ctx, _cache) => {
76
- return openBlock(), createElementBlock("div", {
77
- class: "dot",
78
- style: normalizeStyle([dotStyle.value])
79
- }, [..._cache[0] || (_cache[0] = [
80
- createElementVNode("div", { class: "dot__item" }, null, -1),
81
- createElementVNode("div", { class: "dot__item" }, null, -1),
82
- createElementVNode("div", { class: "dot__item" }, null, -1)
83
- ])], 4);
84
- };
85
- }
86
- });
87
- const Dot_vue_vue_type_style_index_0_scoped_2acd99b5_lang = "";
88
- const Dot = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["__scopeId", "data-v-2acd99b5"]]);
89
- const _sfc_main$9 = /* @__PURE__ */ defineComponent({
90
- __name: "Progress",
91
- props: {
92
- width: { default: 200 },
93
- height: { default: 4 },
94
- background: { default: "#ebeef5" },
95
- radius: {},
96
- color: { default: "var(--preview-file-primary-color)" },
97
- duration: { default: 2 }
98
- },
99
- setup(__props) {
100
- const props = __props;
101
- const progressStyle = computed(() => {
102
- const { width, height, color, duration, radius, background } = props;
103
- const style = {
104
- "--progress-width": addUnit(width),
105
- "--progress-height": addUnit(height),
106
- "--progress-border-radius": addUnit(radius ? radius : Number(height) / 2),
107
- "--progress-background": background,
108
- "--progress-duration": `${duration}s`,
109
- "--progress-color": color
110
- };
111
- return style;
112
- });
113
- return (_ctx, _cache) => {
114
- return openBlock(), createElementBlock("div", {
115
- class: "progress",
116
- style: normalizeStyle([progressStyle.value])
117
- }, [..._cache[0] || (_cache[0] = [
118
- createElementVNode("div", { class: "progress__bar" }, null, -1)
119
- ])], 4);
120
- };
121
- }
122
- });
123
- const Progress_vue_vue_type_style_index_0_scoped_3a710001_lang = "";
124
- const Progress = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["__scopeId", "data-v-3a710001"]]);
125
- const _sfc_main$8 = /* @__PURE__ */ defineComponent({
126
- __name: "Cube",
127
- props: {
128
- size: { default: 40 },
129
- color: { default: "var(--preview-file-primary-color)" },
130
- duration: { default: 1.3 }
131
- },
132
- setup(__props) {
133
- const props = __props;
134
- const cubeStyle = computed(() => {
135
- const { size, duration, color } = props;
136
- const style = {
137
- "--cube-size": addUnit(size),
138
- "--cube-color": color,
139
- "--cube-duration": `${duration}s`
140
- };
141
- return style;
142
- });
143
- return (_ctx, _cache) => {
144
- return openBlock(), createElementBlock("div", {
145
- class: "cube",
146
- style: normalizeStyle([cubeStyle.value])
147
- }, [
148
- (openBlock(), createElementBlock(Fragment, null, renderList(9, (v) => {
149
- return createElementVNode("div", {
150
- key: v,
151
- class: "cube__item"
152
- });
153
- }), 64))
154
- ], 4);
155
- };
156
- }
157
- });
158
- const Cube_vue_vue_type_style_index_0_scoped_0e6bb9d0_lang = "";
159
- const Cube = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["__scopeId", "data-v-0e6bb9d0"]]);
160
- const Loading = {
161
- Circle,
162
- Dot,
163
- Progress,
164
- Cube
165
- };
166
7
  const defaultNamespace = "sakura";
167
8
  const statePrefix = "is-";
168
9
  const _bem = (namespace, block, blockSuffix, element, modifier) => {
@@ -381,35 +222,369 @@ const usePreviewFileTools = (fileUrl, pageNum) => {
381
222
  transform: `translate(${translateX.value}px, ${translateY.value}px) scale(${scale.value})`,
382
223
  transformOrigin: "center center"
383
224
  };
384
- });
385
- const resetPdfData = () => {
386
- resetMouseState();
387
- resetWheelState();
388
- };
389
- watch(() => pageNum == null ? void 0 : pageNum.value, resetPdfData);
390
- const wrapperRef = ref(null);
391
- watch(() => fileUrl.value, () => {
392
- if (!wrapperRef.value) {
393
- return;
394
- }
395
- wrapperRef.value.scrollTop = 0;
396
- resetPdfData();
397
- });
398
- return {
399
- wrapperRef,
400
- onWheel,
401
- clickMinusScale,
402
- clickPlusScale,
403
- resetWheelState,
404
- scale,
405
- scaleText,
406
- isMouseDown,
407
- onMouseStart,
408
- resetMouseState,
409
- translateX,
410
- translateY,
411
- wrapperStyle
412
- };
225
+ });
226
+ const resetPdfData = () => {
227
+ resetMouseState();
228
+ resetWheelState();
229
+ };
230
+ watch(() => pageNum == null ? void 0 : pageNum.value, resetPdfData);
231
+ const wrapperRef = ref(null);
232
+ watch(() => fileUrl.value, () => {
233
+ if (!wrapperRef.value) {
234
+ return;
235
+ }
236
+ wrapperRef.value.scrollTop = 0;
237
+ resetPdfData();
238
+ });
239
+ return {
240
+ wrapperRef,
241
+ onWheel,
242
+ clickMinusScale,
243
+ clickPlusScale,
244
+ resetWheelState,
245
+ scale,
246
+ scaleText,
247
+ isMouseDown,
248
+ onMouseStart,
249
+ resetMouseState,
250
+ translateX,
251
+ translateY,
252
+ wrapperStyle
253
+ };
254
+ };
255
+ const usePreviewFile = () => {
256
+ const proxy = getCurrentInstance();
257
+ return proxy == null ? void 0 : proxy.appContext.config.globalProperties.$previewFile;
258
+ };
259
+ const _sfc_main$f = /* @__PURE__ */ defineComponent({
260
+ __name: "Overlay",
261
+ props: {
262
+ visible: { type: Boolean }
263
+ },
264
+ setup(__props) {
265
+ const ns = useNamespace("overlay");
266
+ return (_ctx, _cache) => {
267
+ return openBlock(), createElementBlock("div", {
268
+ class: normalizeClass([
269
+ unref(ns).b(),
270
+ unref(ns).is("active", __props.visible)
271
+ ])
272
+ }, [
273
+ createElementVNode("div", {
274
+ class: normalizeClass([unref(ns).e("content")]),
275
+ onClick: _cache[0] || (_cache[0] = withModifiers(() => {
276
+ }, ["prevent", "stop"]))
277
+ }, [
278
+ renderSlot(_ctx.$slots, "default")
279
+ ], 2)
280
+ ], 2);
281
+ };
282
+ }
283
+ });
284
+ const _hoisted_1$5 = {
285
+ width: "24",
286
+ height: "24",
287
+ viewBox: "0 0 24 24",
288
+ fill: "none",
289
+ xmlns: "http://www.w3.org/2000/svg"
290
+ };
291
+ const _hoisted_2 = ["stroke"];
292
+ const _hoisted_3 = ["stroke"];
293
+ const _sfc_main$e = /* @__PURE__ */ defineComponent({
294
+ __name: "Close",
295
+ props: {
296
+ color: { default: "#fff" }
297
+ },
298
+ setup(__props) {
299
+ return (_ctx, _cache) => {
300
+ return openBlock(), createElementBlock("svg", _hoisted_1$5, [
301
+ createElementVNode("path", {
302
+ d: "M7 7L17 17",
303
+ stroke: __props.color,
304
+ "stroke-width": "2",
305
+ "stroke-linecap": "round",
306
+ "stroke-linejoin": "round"
307
+ }, null, 8, _hoisted_2),
308
+ createElementVNode("path", {
309
+ d: "M7 17L17 7",
310
+ stroke: __props.color,
311
+ "stroke-width": "2",
312
+ "stroke-linecap": "round",
313
+ "stroke-linejoin": "round"
314
+ }, null, 8, _hoisted_3)
315
+ ]);
316
+ };
317
+ }
318
+ });
319
+ const _sfc_main$d = /* @__PURE__ */ defineComponent({
320
+ __name: "Dialog",
321
+ props: /* @__PURE__ */ mergeModels({
322
+ title: {},
323
+ top: { default: "15vh" },
324
+ width: { default: "50vw" },
325
+ background: { default: "white" },
326
+ radius: { default: 12 },
327
+ showClose: { type: Boolean, default: true },
328
+ closeOnClickModal: { type: Boolean, default: true },
329
+ closeOnPressEscape: { type: Boolean, default: true }
330
+ }, {
331
+ "modelValue": {
332
+ type: Boolean,
333
+ default: false
334
+ },
335
+ "modelModifiers": {}
336
+ }),
337
+ emits: ["update:modelValue"],
338
+ setup(__props) {
339
+ const ns = useNamespace("dialog");
340
+ const props = __props;
341
+ const dialogStyle = computed(() => {
342
+ const { width, top, radius, background } = props;
343
+ return ns.cssBlockVar("dialog", {
344
+ width: addUnit(width),
345
+ top: addUnit(top),
346
+ "border-radius": addUnit(radius),
347
+ background: addUnit(background)
348
+ });
349
+ });
350
+ const showDialog = useModel(__props, "modelValue");
351
+ const handleShowDialog = useThrottleFn(() => {
352
+ showDialog.value = !showDialog.value;
353
+ }, 500);
354
+ const isInit = ref(false);
355
+ const initWatch = watch(() => showDialog.value, (value) => {
356
+ if (!isInit.value && value) {
357
+ isInit.value = true;
358
+ initWatch.stop();
359
+ }
360
+ });
361
+ const onKeyDown = useThrottleFn((e) => {
362
+ if (e.key !== "Escape") {
363
+ return;
364
+ }
365
+ if (!showDialog.value) {
366
+ return;
367
+ }
368
+ handleShowDialog();
369
+ }, 500);
370
+ onMounted(() => {
371
+ props.closeOnPressEscape && window.addEventListener("keydown", onKeyDown);
372
+ });
373
+ onBeforeUnmount(() => {
374
+ props.closeOnPressEscape && window.removeEventListener("keydown", onKeyDown);
375
+ });
376
+ const overlayClick = () => {
377
+ props.closeOnClickModal && handleShowDialog();
378
+ };
379
+ return (_ctx, _cache) => {
380
+ return openBlock(), createBlock(Teleport, { to: "body" }, [
381
+ createVNode(_sfc_main$f, {
382
+ visible: showDialog.value,
383
+ onClick: overlayClick
384
+ }, {
385
+ default: withCtx(() => [
386
+ isInit.value ? (openBlock(), createElementBlock("div", {
387
+ key: 0,
388
+ class: normalizeClass([
389
+ unref(ns).b(),
390
+ unref(ns).is("active", showDialog.value)
391
+ ]),
392
+ style: normalizeStyle([dialogStyle.value])
393
+ }, [
394
+ _ctx.$slots.header || !unref(isEmpty)(__props.title) ? (openBlock(), createElementBlock("div", {
395
+ key: 0,
396
+ class: normalizeClass([unref(ns).e("header")])
397
+ }, [
398
+ __props.title ? (openBlock(), createElementBlock("span", {
399
+ key: 0,
400
+ class: normalizeClass([unref(ns).e("title")])
401
+ }, toDisplayString(__props.title), 3)) : createCommentVNode("", true),
402
+ renderSlot(_ctx.$slots, "header")
403
+ ], 2)) : createCommentVNode("", true),
404
+ __props.showClose ? (openBlock(), createElementBlock("div", {
405
+ key: 1,
406
+ class: normalizeClass([unref(ns).e("icon")]),
407
+ onClick: _cache[0] || (_cache[0] = //@ts-ignore
408
+ (...args) => unref(handleShowDialog) && unref(handleShowDialog)(...args))
409
+ }, [
410
+ createVNode(_sfc_main$e, { color: "#909399" })
411
+ ], 2)) : createCommentVNode("", true),
412
+ createElementVNode("div", {
413
+ class: normalizeClass([unref(ns).e("body")])
414
+ }, [
415
+ renderSlot(_ctx.$slots, "default")
416
+ ], 2),
417
+ _ctx.$slots.footer ? (openBlock(), createElementBlock("div", {
418
+ key: 2,
419
+ class: normalizeClass([unref(ns).e("footer")])
420
+ }, [
421
+ renderSlot(_ctx.$slots, "footer")
422
+ ], 2)) : createCommentVNode("", true)
423
+ ], 6)) : createCommentVNode("", true)
424
+ ]),
425
+ _: 3
426
+ }, 8, ["visible"])
427
+ ]);
428
+ };
429
+ }
430
+ });
431
+ const _hoisted_1$4 = ["stroke"];
432
+ const _sfc_main$c = /* @__PURE__ */ defineComponent({
433
+ __name: "Circle",
434
+ props: {
435
+ size: { default: 50 },
436
+ color: { default: "#409eff" },
437
+ duration: { default: 2 }
438
+ },
439
+ setup(__props) {
440
+ const props = __props;
441
+ const circleStyle = computed(() => {
442
+ const { size, duration } = props;
443
+ const style = {
444
+ "--circle-size": addUnit(size),
445
+ "--circle-duration": `${duration}s`
446
+ };
447
+ return style;
448
+ });
449
+ return (_ctx, _cache) => {
450
+ return openBlock(), createElementBlock("svg", {
451
+ class: "circular",
452
+ viewBox: "0 0 50 50",
453
+ style: normalizeStyle([circleStyle.value])
454
+ }, [
455
+ createElementVNode("circle", {
456
+ class: "circular__path-inner",
457
+ cx: "25",
458
+ cy: "25",
459
+ r: "20",
460
+ fill: "none",
461
+ stroke: __props.color,
462
+ "stroke-width": "4",
463
+ "stroke-miterlimit": "10"
464
+ }, null, 8, _hoisted_1$4)
465
+ ], 4);
466
+ };
467
+ }
468
+ });
469
+ const Circle_vue_vue_type_style_index_0_scoped_51d1fa15_lang = "";
470
+ const _export_sfc = (sfc, props) => {
471
+ const target = sfc.__vccOpts || sfc;
472
+ for (const [key, val] of props) {
473
+ target[key] = val;
474
+ }
475
+ return target;
476
+ };
477
+ const Circle = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["__scopeId", "data-v-51d1fa15"]]);
478
+ const _sfc_main$b = /* @__PURE__ */ defineComponent({
479
+ __name: "Dot",
480
+ props: {
481
+ gap: { default: 6 },
482
+ color: { default: "var(--preview-file-primary-color)" },
483
+ size: { default: 10 },
484
+ duration: { default: 1.4 }
485
+ },
486
+ setup(__props) {
487
+ const props = __props;
488
+ const dotStyle = computed(() => {
489
+ const { size, gap, duration, color } = props;
490
+ const style = {
491
+ "--dot-size": addUnit(size),
492
+ "--dot-duration": `${duration}s`,
493
+ "--dot-gap": addUnit(gap),
494
+ "--dot-color": color
495
+ };
496
+ return style;
497
+ });
498
+ return (_ctx, _cache) => {
499
+ return openBlock(), createElementBlock("div", {
500
+ class: "dot",
501
+ style: normalizeStyle([dotStyle.value])
502
+ }, [..._cache[0] || (_cache[0] = [
503
+ createElementVNode("div", { class: "dot__item" }, null, -1),
504
+ createElementVNode("div", { class: "dot__item" }, null, -1),
505
+ createElementVNode("div", { class: "dot__item" }, null, -1)
506
+ ])], 4);
507
+ };
508
+ }
509
+ });
510
+ const Dot_vue_vue_type_style_index_0_scoped_2acd99b5_lang = "";
511
+ const Dot = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["__scopeId", "data-v-2acd99b5"]]);
512
+ const _sfc_main$a = /* @__PURE__ */ defineComponent({
513
+ __name: "Progress",
514
+ props: {
515
+ width: { default: 200 },
516
+ height: { default: 4 },
517
+ background: { default: "#ebeef5" },
518
+ radius: {},
519
+ color: { default: "var(--preview-file-primary-color)" },
520
+ duration: { default: 2 }
521
+ },
522
+ setup(__props) {
523
+ const props = __props;
524
+ const progressStyle = computed(() => {
525
+ const { width, height, color, duration, radius, background } = props;
526
+ const style = {
527
+ "--progress-width": addUnit(width),
528
+ "--progress-height": addUnit(height),
529
+ "--progress-border-radius": addUnit(radius ? radius : Number(height) / 2),
530
+ "--progress-background": background,
531
+ "--progress-duration": `${duration}s`,
532
+ "--progress-color": color
533
+ };
534
+ return style;
535
+ });
536
+ return (_ctx, _cache) => {
537
+ return openBlock(), createElementBlock("div", {
538
+ class: "progress",
539
+ style: normalizeStyle([progressStyle.value])
540
+ }, [..._cache[0] || (_cache[0] = [
541
+ createElementVNode("div", { class: "progress__bar" }, null, -1)
542
+ ])], 4);
543
+ };
544
+ }
545
+ });
546
+ const Progress_vue_vue_type_style_index_0_scoped_3a710001_lang = "";
547
+ const Progress = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["__scopeId", "data-v-3a710001"]]);
548
+ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
549
+ __name: "Cube",
550
+ props: {
551
+ size: { default: 40 },
552
+ color: { default: "var(--preview-file-primary-color)" },
553
+ duration: { default: 1.3 }
554
+ },
555
+ setup(__props) {
556
+ const props = __props;
557
+ const cubeStyle = computed(() => {
558
+ const { size, duration, color } = props;
559
+ const style = {
560
+ "--cube-size": addUnit(size),
561
+ "--cube-color": color,
562
+ "--cube-duration": `${duration}s`
563
+ };
564
+ return style;
565
+ });
566
+ return (_ctx, _cache) => {
567
+ return openBlock(), createElementBlock("div", {
568
+ class: "cube",
569
+ style: normalizeStyle([cubeStyle.value])
570
+ }, [
571
+ (openBlock(), createElementBlock(Fragment, null, renderList(9, (v) => {
572
+ return createElementVNode("div", {
573
+ key: v,
574
+ class: "cube__item"
575
+ });
576
+ }), 64))
577
+ ], 4);
578
+ };
579
+ }
580
+ });
581
+ const Cube_vue_vue_type_style_index_0_scoped_0e6bb9d0_lang = "";
582
+ const Cube = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["__scopeId", "data-v-0e6bb9d0"]]);
583
+ const Loading = {
584
+ Circle,
585
+ Dot,
586
+ Progress,
587
+ Cube
413
588
  };
414
589
  var EVENT_NAME = /* @__PURE__ */ ((EVENT_NAME2) => {
415
590
  EVENT_NAME2["完成"] = "loaded";
@@ -439,6 +614,7 @@ const usePreviewPdf = (state) => {
439
614
  const onPageNumChange = () => {
440
615
  const { total } = state;
441
616
  state.pageNum = Math.max(Math.min(_pageNum.value, total), 1);
617
+ _pageNum.value = state.pageNum;
442
618
  };
443
619
  watchEffect(() => {
444
620
  _pageNum.value = state.pageNum;
@@ -452,15 +628,7 @@ const usePreviewPdf = (state) => {
452
628
  onPageNumChange
453
629
  };
454
630
  };
455
- const _hoisted_1$6 = { class: "sakura-file-data__tools" };
456
- const _hoisted_2$1 = { class: "sakura-file-data__page" };
457
- const _hoisted_3$1 = { class: "sakura-file-data__text" };
458
- const _hoisted_4$1 = {
459
- key: 1,
460
- class: "sakura-file-data__scale"
461
- };
462
- const _hoisted_5$1 = { class: "sakura-file-data__scale-text" };
463
- const _sfc_main$7 = /* @__PURE__ */ defineComponent({
631
+ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
464
632
  __name: "Tools",
465
633
  props: /* @__PURE__ */ mergeModels({
466
634
  showTools: { type: Boolean },
@@ -480,23 +648,32 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
480
648
  }),
481
649
  emits: /* @__PURE__ */ mergeModels([EVENT_NAME.改变, EVENT_NAME.下一页, EVENT_NAME.上一页, EVENT_NAME.放大, EVENT_NAME.缩小], ["update:modelValue"]),
482
650
  setup(__props, { emit: __emit }) {
651
+ const ns = useNamespace("tools");
483
652
  const emits = __emit;
484
653
  const _pageNum = useModel(__props, "modelValue");
485
654
  return (_ctx, _cache) => {
486
- return openBlock(), createElementBlock("div", _hoisted_1$6, [
655
+ return openBlock(), createElementBlock("div", {
656
+ class: normalizeClass([unref(ns).b()])
657
+ }, [
487
658
  renderSlot(_ctx.$slots, "default"),
488
659
  __props.showTools ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
489
660
  __props.enablePagination ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
490
661
  createElementVNode("div", {
491
- class: normalizeClass(["sakura-file-data__arrow sakura-file-data__arrow-prev", [__props.prevPageDisabled ? "is-disabled" : ""]]),
662
+ class: normalizeClass(["sakura-file-data__arrow sakura-file-data__arrow-prev", [
663
+ unref(ns).e("arrow"),
664
+ unref(ns).em("arrow", "prev"),
665
+ unref(ns).is("disabled", __props.prevPageDisabled)
666
+ ]]),
492
667
  onClick: _cache[0] || (_cache[0] = ($event) => emits(unref(EVENT_NAME).上一页))
493
668
  }, null, 2),
494
- createElementVNode("div", _hoisted_2$1, [
669
+ createElementVNode("div", {
670
+ class: normalizeClass([unref(ns).e("page")])
671
+ }, [
495
672
  withDirectives(createElementVNode("input", {
496
- class: "sakura-file-data__input",
673
+ class: normalizeClass([unref(ns).e("input")]),
497
674
  "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => _pageNum.value = $event),
498
675
  onBlur: _cache[2] || (_cache[2] = ($event) => emits(unref(EVENT_NAME).改变))
499
- }, null, 544), [
676
+ }, null, 34), [
500
677
  [
501
678
  vModelText,
502
679
  _pageNum.value,
@@ -504,31 +681,47 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
504
681
  { number: true }
505
682
  ]
506
683
  ]),
507
- createElementVNode("span", _hoisted_3$1, " / " + toDisplayString(__props.total), 1)
508
- ]),
684
+ createElementVNode("span", {
685
+ class: normalizeClass([unref(ns).e("text")])
686
+ }, " / " + toDisplayString(__props.total), 3)
687
+ ], 2),
509
688
  createElementVNode("div", {
510
- class: normalizeClass(["sakura-file-data__arrow sakura-file-data__arrow-next", [__props.nextPageDisabled ? "is-disabled" : ""]]),
689
+ class: normalizeClass([
690
+ unref(ns).e("arrow"),
691
+ unref(ns).em("arrow", "next"),
692
+ unref(ns).is("disabled", __props.nextPageDisabled)
693
+ ]),
511
694
  onClick: _cache[3] || (_cache[3] = ($event) => emits(unref(EVENT_NAME).下一页))
512
695
  }, null, 2)
513
696
  ], 64)) : createCommentVNode("", true),
514
- __props.enableScale ? (openBlock(), createElementBlock("div", _hoisted_4$1, [
697
+ __props.enableScale ? (openBlock(), createElementBlock("div", {
698
+ key: 1,
699
+ class: normalizeClass([unref(ns).e("scale")])
700
+ }, [
515
701
  createElementVNode("div", {
516
- class: "sakura-file-data__icon sakura-file-data__minus",
702
+ class: normalizeClass([
703
+ unref(ns).e("icon"),
704
+ unref(ns).e("minus")
705
+ ]),
517
706
  onClick: _cache[4] || (_cache[4] = ($event) => emits(unref(EVENT_NAME).缩小))
518
- }),
519
- createElementVNode("span", _hoisted_5$1, toDisplayString(__props.scaleText), 1),
707
+ }, null, 2),
708
+ createElementVNode("span", {
709
+ class: normalizeClass([unref(ns).e("scale-text")])
710
+ }, toDisplayString(__props.scaleText), 3),
520
711
  createElementVNode("div", {
521
- class: "sakura-file-data__icon sakura-file-data__plus",
712
+ class: normalizeClass([
713
+ unref(ns).e("icon"),
714
+ unref(ns).e("plus")
715
+ ]),
522
716
  onClick: _cache[5] || (_cache[5] = ($event) => emits(unref(EVENT_NAME).放大))
523
- })
524
- ])) : createCommentVNode("", true)
717
+ }, null, 2)
718
+ ], 2)) : createCommentVNode("", true)
525
719
  ], 64)) : createCommentVNode("", true)
526
- ]);
720
+ ], 2);
527
721
  };
528
722
  }
529
723
  });
530
- const _hoisted_1$5 = { class: "sakura-file-data" };
531
- const _sfc_main$6 = /* @__PURE__ */ defineComponent({
724
+ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
532
725
  __name: "Pdf",
533
726
  props: /* @__PURE__ */ mergeModels({
534
727
  enablePagination: { type: Boolean, default: true },
@@ -545,6 +738,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
545
738
  }),
546
739
  emits: /* @__PURE__ */ mergeModels([EVENT_NAME.完成], ["update:modelValue"]),
547
740
  setup(__props, { emit: __emit }) {
741
+ const ns = useNamespace("file-data");
548
742
  const props = __props;
549
743
  const emits = __emit;
550
744
  const pdfLoading = useModel(__props, "modelValue");
@@ -595,10 +789,15 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
595
789
  const { fileUrl } = toRefs(props);
596
790
  const { onWheel, clickMinusScale, clickPlusScale, isMouseDown, scaleText, onMouseStart, wrapperStyle } = usePreviewFileTools(fileUrl, pageNum);
597
791
  return (_ctx, _cache) => {
598
- return openBlock(), createElementBlock("div", _hoisted_1$5, [
792
+ return openBlock(), createElementBlock("div", {
793
+ class: normalizeClass([
794
+ unref(ns).b(),
795
+ unref(ns).is("drag", unref(isMouseDown))
796
+ ])
797
+ }, [
599
798
  createElementVNode("div", {
600
799
  ref: "wrapperRef",
601
- class: normalizeClass(["sakura-file-data__wrapper", [unref(isMouseDown) ? "is-drag" : ""]]),
800
+ class: normalizeClass([unref(ns).e("wrapper")]),
602
801
  onMousedown: _cache[0] || (_cache[0] = ($event) => __props.enableMove && unref(onMouseStart)($event)),
603
802
  onWheel: _cache[1] || (_cache[1] = ($event) => __props.enableScale && unref(onWheel)($event))
604
803
  }, [
@@ -606,7 +805,6 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
606
805
  style: normalizeStyle([unref(wrapperStyle)])
607
806
  }, [
608
807
  createVNode(unref(VuePdfEmbed), {
609
- class: "pdf",
610
808
  source: pdfSource.value,
611
809
  page: __props.enablePagination ? state.pageNum : void 0,
612
810
  scale: 1,
@@ -616,7 +814,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
616
814
  }, null, 8, ["source", "page"])
617
815
  ], 4)
618
816
  ], 34),
619
- __props.enablePagination || __props.enableScale || __props.showTools ? (openBlock(), createBlock(_sfc_main$7, {
817
+ __props.enablePagination || __props.enableScale || __props.showTools ? (openBlock(), createBlock(_sfc_main$8, {
620
818
  key: 0,
621
819
  modelValue: unref(_pageNum),
622
820
  "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(_pageNum) ? _pageNum.value = $event : null),
@@ -639,12 +837,11 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
639
837
  ]),
640
838
  _: 3
641
839
  }, 8, ["modelValue", "total", "prev-page-disabled", "next-page-disabled", "scale-text", "show-tools", "enable-pagination", "enable-scale", "enable-move", "onChange", "onNext", "onPrev", "onZoomIn", "onZoomOut"])) : createCommentVNode("", true)
642
- ]);
840
+ ], 2);
643
841
  };
644
842
  }
645
843
  });
646
- const _hoisted_1$4 = { class: "sakura-file-data" };
647
- const _sfc_main$5 = /* @__PURE__ */ defineComponent({
844
+ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
648
845
  __name: "Word",
649
846
  props: /* @__PURE__ */ mergeModels({
650
847
  enablePagination: { type: Boolean },
@@ -663,6 +860,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
663
860
  }),
664
861
  emits: /* @__PURE__ */ mergeModels([EVENT_NAME.完成], ["update:modelValue"]),
665
862
  setup(__props, { emit: __emit }) {
863
+ const ns = useNamespace("file-data");
666
864
  const props = __props;
667
865
  const wordLoading = useModel(__props, "modelValue");
668
866
  const generateWordFile = async () => {
@@ -716,10 +914,16 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
716
914
  const { fileUrl } = toRefs(props);
717
915
  const { onWheel, clickMinusScale, clickPlusScale, isMouseDown, scaleText, onMouseStart, wrapperStyle } = usePreviewFileTools(fileUrl);
718
916
  return (_ctx, _cache) => {
719
- return openBlock(), createElementBlock("div", _hoisted_1$4, [
917
+ return openBlock(), createElementBlock("div", {
918
+ class: normalizeClass([
919
+ unref(ns).b(),
920
+ unref(ns).is("drag", unref(isMouseDown)),
921
+ unref(ns).is("enable-wrapper", __props.enableWrapper)
922
+ ])
923
+ }, [
720
924
  createElementVNode("div", {
721
925
  ref: "wrapperRef",
722
- class: normalizeClass(["sakura-file-data__wrapper", [unref(isMouseDown) ? "is-drag" : "", __props.enableWrapper ? "is-enable-wrapper" : ""]]),
926
+ class: normalizeClass([unref(ns).e("wrapper")]),
723
927
  onMousedown: _cache[0] || (_cache[0] = ($event) => __props.enableMove && unref(onMouseStart)($event)),
724
928
  onWheel: _cache[1] || (_cache[1] = ($event) => __props.enableScale && unref(onWheel)($event))
725
929
  }, [
@@ -729,7 +933,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
729
933
  style: normalizeStyle([unref(wrapperStyle)])
730
934
  }, null, 4)
731
935
  ], 34),
732
- __props.enablePagination || __props.enableScale || __props.showTools ? (openBlock(), createBlock(_sfc_main$7, {
936
+ __props.enablePagination || __props.enableScale || __props.showTools ? (openBlock(), createBlock(_sfc_main$8, {
733
937
  key: 0,
734
938
  "scale-text": unref(scaleText),
735
939
  "show-tools": __props.showTools,
@@ -743,17 +947,17 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
743
947
  ]),
744
948
  _: 3
745
949
  }, 8, ["scale-text", "show-tools", "enable-scale", "enable-move", "onZoomIn", "onZoomOut"])) : createCommentVNode("", true)
746
- ]);
950
+ ], 2);
747
951
  };
748
952
  }
749
953
  });
750
- const _sfc_main$4 = {};
954
+ const _sfc_main$5 = {};
751
955
  const _hoisted_1$3 = {
752
956
  width: "24",
753
957
  height: "24",
754
958
  fill: "none"
755
959
  };
756
- function _sfc_render$2(_ctx, _cache) {
960
+ function _sfc_render$1(_ctx, _cache) {
757
961
  return openBlock(), createElementBlock("svg", _hoisted_1$3, [..._cache[0] || (_cache[0] = [
758
962
  createElementVNode("circle", {
759
963
  cx: "10.5",
@@ -773,8 +977,8 @@ function _sfc_render$2(_ctx, _cache) {
773
977
  }, null, -1)
774
978
  ])]);
775
979
  }
776
- const ZoomIn = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$2]]);
777
- const _sfc_main$3 = {};
980
+ const ZoomIn = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$1]]);
981
+ const _sfc_main$4 = {};
778
982
  const _hoisted_1$2 = {
779
983
  width: "24",
780
984
  height: "24",
@@ -782,7 +986,7 @@ const _hoisted_1$2 = {
782
986
  fill: "none",
783
987
  xmlns: "http://www.w3.org/2000/svg"
784
988
  };
785
- function _sfc_render$1(_ctx, _cache) {
989
+ function _sfc_render(_ctx, _cache) {
786
990
  return openBlock(), createElementBlock("svg", _hoisted_1$2, [..._cache[0] || (_cache[0] = [
787
991
  createElementVNode("circle", {
788
992
  cx: "10.5",
@@ -809,44 +1013,111 @@ function _sfc_render$1(_ctx, _cache) {
809
1013
  }, null, -1)
810
1014
  ])]);
811
1015
  }
812
- const ZoomOut = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$1]]);
813
- const _sfc_main$2 = {};
814
- const _hoisted_1$1 = {
815
- width: "24",
816
- height: "24",
817
- viewBox: "0 0 24 24",
818
- fill: "none",
819
- xmlns: "http://www.w3.org/2000/svg"
820
- };
821
- function _sfc_render(_ctx, _cache) {
822
- return openBlock(), createElementBlock("svg", _hoisted_1$1, [..._cache[0] || (_cache[0] = [
823
- createElementVNode("path", {
824
- d: "M7 7L17 17",
825
- stroke: "#fff",
826
- "stroke-width": "2",
827
- "stroke-linecap": "round",
828
- "stroke-linejoin": "round"
829
- }, null, -1),
830
- createElementVNode("path", {
831
- d: "M7 17L17 7",
832
- stroke: "#fff",
833
- "stroke-width": "2",
834
- "stroke-linecap": "round",
835
- "stroke-linejoin": "round"
836
- }, null, -1)
837
- ])]);
838
- }
839
- const Close = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render]]);
840
- const _hoisted_1 = { class: "sakura-file-data" };
841
- const _hoisted_2 = { class: "sakura-file-data__wrapper is-image" };
842
- const _hoisted_3 = ["src"];
843
- const _hoisted_4 = { class: "sakura-preview__image--data" };
844
- const _hoisted_5 = ["src"];
845
- const _hoisted_6 = {
846
- key: 0,
847
- class: "sakura-preview__image--tools"
848
- };
849
- const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1016
+ const ZoomOut = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render]]);
1017
+ const _hoisted_1$1 = ["src"];
1018
+ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1019
+ __name: "Preview",
1020
+ props: /* @__PURE__ */ mergeModels({
1021
+ imageWidth: {},
1022
+ imageHeight: {},
1023
+ fileUrl: {},
1024
+ enableMove: { type: Boolean },
1025
+ enableScale: { type: Boolean }
1026
+ }, {
1027
+ "modelValue": {
1028
+ type: Boolean,
1029
+ default: false
1030
+ },
1031
+ "modelModifiers": {}
1032
+ }),
1033
+ emits: ["update:modelValue"],
1034
+ setup(__props) {
1035
+ const ns = useNamespace("preview-image");
1036
+ const { width, height } = useWindowSize();
1037
+ const showPreviewImage = useModel(__props, "modelValue");
1038
+ const handleShowPreviewImage = () => {
1039
+ showPreviewImage.value = !showPreviewImage.value;
1040
+ };
1041
+ const props = __props;
1042
+ const { imageHeight, imageWidth, fileUrl } = toRefs(props);
1043
+ const dialogImageStyle = computed(() => {
1044
+ if (imageWidth.value > width.value) {
1045
+ return {
1046
+ width: "auto",
1047
+ height: addUnit(height.value)
1048
+ };
1049
+ }
1050
+ return {
1051
+ width: addUnit(imageWidth.value),
1052
+ height: addUnit(imageHeight.value)
1053
+ };
1054
+ });
1055
+ const {
1056
+ onWheel,
1057
+ onMouseStart,
1058
+ isMouseDown,
1059
+ clickMinusScale,
1060
+ clickPlusScale,
1061
+ wrapperStyle,
1062
+ resetMouseState,
1063
+ resetWheelState
1064
+ } = usePreviewFileTools(fileUrl);
1065
+ const resetData = () => {
1066
+ resetMouseState();
1067
+ resetWheelState();
1068
+ };
1069
+ watch(() => showPreviewImage.value, (value) => {
1070
+ value && resetData();
1071
+ });
1072
+ return (_ctx, _cache) => {
1073
+ return openBlock(), createBlock(unref(_sfc_main$d), {
1074
+ modelValue: showPreviewImage.value,
1075
+ "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => showPreviewImage.value = $event),
1076
+ background: "transparent",
1077
+ "show-close": false
1078
+ }, {
1079
+ default: withCtx(() => [
1080
+ createElementVNode("div", {
1081
+ ref: "wrapperRef",
1082
+ class: normalizeClass([
1083
+ unref(ns).b(),
1084
+ unref(ns).is("drag", unref(isMouseDown))
1085
+ ]),
1086
+ onMousedown: _cache[0] || (_cache[0] = ($event) => __props.enableMove && unref(onMouseStart)($event)),
1087
+ onWheel: _cache[1] || (_cache[1] = ($event) => __props.enableScale && unref(onWheel)($event))
1088
+ }, [
1089
+ createElementVNode("div", {
1090
+ class: normalizeClass([unref(ns).e("data")])
1091
+ }, [
1092
+ createElementVNode("img", {
1093
+ class: normalizeClass([unref(ns).e("dot-move")]),
1094
+ src: unref(fileUrl),
1095
+ style: normalizeStyle([dialogImageStyle.value, unref(wrapperStyle)]),
1096
+ alt: ""
1097
+ }, null, 14, _hoisted_1$1)
1098
+ ], 2),
1099
+ createElementVNode("div", {
1100
+ class: normalizeClass([unref(ns).e("close")]),
1101
+ onClick: handleShowPreviewImage
1102
+ }, [
1103
+ createVNode(_sfc_main$e)
1104
+ ], 2),
1105
+ __props.enableScale ? (openBlock(), createElementBlock("div", {
1106
+ key: 0,
1107
+ class: normalizeClass([unref(ns).e("tools")])
1108
+ }, [
1109
+ createVNode(ZoomOut, { onClick: unref(clickMinusScale) }, null, 8, ["onClick"]),
1110
+ createVNode(ZoomIn, { onClick: unref(clickPlusScale) }, null, 8, ["onClick"])
1111
+ ], 2)) : createCommentVNode("", true)
1112
+ ], 34)
1113
+ ]),
1114
+ _: 1
1115
+ }, 8, ["modelValue"]);
1116
+ };
1117
+ }
1118
+ });
1119
+ const _hoisted_1 = ["src"];
1120
+ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
850
1121
  __name: "Image",
851
1122
  props: /* @__PURE__ */ mergeModels({
852
1123
  enablePagination: { type: Boolean },
@@ -863,102 +1134,65 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
863
1134
  }),
864
1135
  emits: ["update:modelValue"],
865
1136
  setup(__props) {
1137
+ const ns = useNamespace("file-data");
866
1138
  const props = __props;
867
1139
  const pdfLoading = useModel(__props, "modelValue");
868
1140
  const onImageLoad = () => {
869
1141
  pdfLoading.value = false;
870
1142
  };
871
- const { width, height } = useWindowSize();
872
1143
  const imageWidth = ref(0);
873
1144
  const imageHeight = ref(0);
874
1145
  const loadImageSize = async () => {
875
- const fileUrl2 = props.fileUrl;
1146
+ const fileUrl = props.fileUrl;
876
1147
  imageWidth.value = 0;
877
1148
  imageHeight.value = 0;
878
1149
  const image = new Image();
879
- image.src = fileUrl2;
1150
+ image.src = fileUrl;
880
1151
  image.onload = () => {
881
1152
  imageWidth.value = image.width;
882
1153
  imageHeight.value = image.height;
883
1154
  };
884
1155
  };
885
1156
  onMounted(loadImageSize);
886
- const dialogImageStyle = computed(() => {
887
- if (imageWidth.value > width.value) {
888
- return {
889
- width: "auto",
890
- height: addUnit(height.value)
891
- };
892
- }
893
- return {
894
- width: addUnit(imageWidth.value),
895
- height: addUnit(imageHeight.value)
896
- };
897
- });
898
- const { fileUrl } = toRefs(props);
899
- const {
900
- onWheel,
901
- onMouseStart,
902
- isMouseDown,
903
- clickMinusScale,
904
- clickPlusScale,
905
- wrapperStyle
906
- } = usePreviewFileTools(fileUrl);
907
1157
  const visible = ref(false);
908
1158
  const handleVisible = () => {
909
1159
  visible.value = !visible.value;
910
1160
  };
911
1161
  return (_ctx, _cache) => {
912
1162
  return openBlock(), createElementBlock(Fragment, null, [
913
- createElementVNode("div", _hoisted_1, [
914
- createElementVNode("div", _hoisted_2, [
1163
+ createElementVNode("div", {
1164
+ class: normalizeClass([
1165
+ unref(ns).b(),
1166
+ unref(ns).is("image")
1167
+ ])
1168
+ }, [
1169
+ createElementVNode("div", {
1170
+ class: normalizeClass([unref(ns).e("wrapper")])
1171
+ }, [
915
1172
  createElementVNode("img", {
916
- class: "sakura-file-data__image",
917
- src: unref(fileUrl),
1173
+ class: normalizeClass([unref(ns).e("image")]),
1174
+ src: __props.fileUrl,
918
1175
  alt: "",
919
1176
  onLoad: onImageLoad,
920
1177
  onClick: handleVisible
921
- }, null, 40, _hoisted_3)
922
- ])
923
- ]),
924
- (openBlock(), createBlock(Teleport, { to: "body" }, [
925
- createElementVNode("div", {
926
- class: normalizeClass(["sakura-preview-dialog", [visible.value ? "is-visible" : ""]])
927
- }, [
928
- _cache[2] || (_cache[2] = createElementVNode("div", { class: "sakura-preview__image--mark" }, null, -1)),
929
- createElementVNode("div", {
930
- ref: "wrapperRef",
931
- class: normalizeClass(["sakura-preview__image", [unref(isMouseDown) ? "is-drag" : ""]]),
932
- onMousedown: _cache[0] || (_cache[0] = ($event) => __props.enableMove && unref(onMouseStart)($event)),
933
- onWheel: _cache[1] || (_cache[1] = ($event) => __props.enableScale && unref(onWheel)($event))
934
- }, [
935
- createElementVNode("div", _hoisted_4, [
936
- createElementVNode("img", {
937
- class: "dot-move",
938
- src: unref(fileUrl),
939
- style: normalizeStyle([dialogImageStyle.value, unref(wrapperStyle)]),
940
- alt: ""
941
- }, null, 12, _hoisted_5)
942
- ]),
943
- createElementVNode("div", {
944
- class: "sakura-preview__image--close",
945
- onClick: handleVisible
946
- }, [
947
- createVNode(Close)
948
- ]),
949
- __props.enableScale ? (openBlock(), createElementBlock("div", _hoisted_6, [
950
- createVNode(ZoomIn, { onClick: unref(clickPlusScale) }, null, 8, ["onClick"]),
951
- createVNode(ZoomOut, { onClick: unref(clickMinusScale) }, null, 8, ["onClick"])
952
- ])) : createCommentVNode("", true)
953
- ], 34)
1178
+ }, null, 42, _hoisted_1)
954
1179
  ], 2)
955
- ]))
1180
+ ], 2),
1181
+ createVNode(_sfc_main$3, {
1182
+ modelValue: visible.value,
1183
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => visible.value = $event),
1184
+ "file-url": __props.fileUrl,
1185
+ "enable-move": __props.enableMove,
1186
+ "enable-scale": __props.enableScale,
1187
+ "image-width": imageWidth.value,
1188
+ "image-height": imageHeight.value
1189
+ }, null, 8, ["modelValue", "file-url", "enable-move", "enable-scale", "image-width", "image-height"])
956
1190
  ], 64);
957
1191
  };
958
1192
  }
959
1193
  });
960
1194
  const PreviewFileContextKey = Symbol("PreviewFile");
961
- const _sfc_main = /* @__PURE__ */ defineComponent({
1195
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
962
1196
  __name: "preview-file",
963
1197
  props: {
964
1198
  width: { default: "100%" },
@@ -1014,7 +1248,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1014
1248
  key: 0,
1015
1249
  class: normalizeClass([unref(ns).e("wrapper")])
1016
1250
  }, [
1017
- unref(isPdfFile)(unref(fileType)) ? (openBlock(), createBlock(_sfc_main$6, {
1251
+ unref(isPdfFile)(unref(fileType)) ? (openBlock(), createBlock(_sfc_main$7, {
1018
1252
  key: 0,
1019
1253
  modelValue: loading.value,
1020
1254
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => loading.value = $event),
@@ -1032,7 +1266,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1032
1266
  ]),
1033
1267
  _: 3
1034
1268
  }, 8, ["modelValue", "file-url", "show-tools", "enable-pagination", "enable-scale", "enable-move"])) : createCommentVNode("", true),
1035
- unref(isWordFile)(unref(fileType)) ? (openBlock(), createBlock(_sfc_main$5, {
1269
+ unref(isWordFile)(unref(fileType)) ? (openBlock(), createBlock(_sfc_main$6, {
1036
1270
  key: 1,
1037
1271
  modelValue: loading.value,
1038
1272
  "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => loading.value = $event),
@@ -1042,7 +1276,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1042
1276
  "enable-scale": __props.enableScale,
1043
1277
  "enable-move": __props.enableMove,
1044
1278
  "is-local-file": __props.convertToLocalFileUrl
1045
- }, null, 8, ["modelValue", "file-url", "show-tools", "enable-pagination", "enable-scale", "enable-move", "is-local-file"])) : unref(isImageFile)(unref(fileType)) ? (openBlock(), createBlock(_sfc_main$1, {
1279
+ }, null, 8, ["modelValue", "file-url", "show-tools", "enable-pagination", "enable-scale", "enable-move", "is-local-file"])) : unref(isImageFile)(unref(fileType)) ? (openBlock(), createBlock(_sfc_main$2, {
1046
1280
  key: 2,
1047
1281
  modelValue: loading.value,
1048
1282
  "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => loading.value = $event),
@@ -1070,11 +1304,101 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1070
1304
  };
1071
1305
  }
1072
1306
  });
1073
- _sfc_main.install = (app) => {
1074
- app.component("PreviewFile", _sfc_main);
1075
- app.component("Loading", Loading);
1307
+ const _sfc_main = /* @__PURE__ */ defineComponent({
1308
+ __name: "preview-file-dialog",
1309
+ setup(__props, { expose: __expose }) {
1310
+ const getState = () => {
1311
+ return {
1312
+ width: 749,
1313
+ height: "80vh",
1314
+ src: "",
1315
+ convertToLocalFileUrl: false,
1316
+ enablePagination: true,
1317
+ enableMove: true,
1318
+ enableScale: true,
1319
+ loadingType: "progress",
1320
+ themeColor: "#245EFF",
1321
+ top: "5vh"
1322
+ };
1323
+ };
1324
+ const state = reactive(getState());
1325
+ const { fileUrl, fileType } = useFileState(state);
1326
+ const previewFileTitle = computed(() => {
1327
+ const { title } = state;
1328
+ if (!isEmpty(title)) {
1329
+ return title;
1330
+ }
1331
+ if (isPdfFile(fileType.value)) {
1332
+ return "pdf";
1333
+ }
1334
+ if (isWordFile(fileType.value)) {
1335
+ return "word";
1336
+ }
1337
+ return "image";
1338
+ });
1339
+ const visible = ref(false);
1340
+ const previewFile = (_fileUrl, title, params = {}) => {
1341
+ extend(state, getState(), {
1342
+ ...params,
1343
+ title,
1344
+ src: _fileUrl
1345
+ });
1346
+ visible.value = true;
1347
+ };
1348
+ __expose({
1349
+ previewFile
1350
+ });
1351
+ return (_ctx, _cache) => {
1352
+ return openBlock(), createBlock(unref(_sfc_main$d), {
1353
+ modelValue: visible.value,
1354
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => visible.value = $event),
1355
+ top: state.top,
1356
+ title: previewFileTitle.value,
1357
+ width: state.width
1358
+ }, {
1359
+ default: withCtx(() => [
1360
+ visible.value ? (openBlock(), createBlock(_sfc_main$1, mergeProps({ key: 0 }, state, {
1361
+ src: unref(fileUrl),
1362
+ width: "100%"
1363
+ }), null, 16, ["src"])) : createCommentVNode("", true)
1364
+ ]),
1365
+ _: 1
1366
+ }, 8, ["modelValue", "top", "title", "width"]);
1367
+ };
1368
+ }
1369
+ });
1370
+ const checkElementIsExist = (id, container = "body") => {
1371
+ if (document.querySelector(`#${id}`)) {
1372
+ return true;
1373
+ }
1374
+ try {
1375
+ const div = document.createElement("div");
1376
+ div.id = id;
1377
+ const containerEl = document.querySelector(container);
1378
+ containerEl.append(div);
1379
+ return true;
1380
+ } catch {
1381
+ return false;
1382
+ }
1383
+ };
1384
+ function install(vm) {
1385
+ const vnode = createVNode(_sfc_main);
1386
+ checkElementIsExist("sakura-preview-file");
1387
+ render(vnode, document.querySelector("#sakura-preview-file"));
1388
+ vm.config.globalProperties.$previewFile = (fileUrl, title = "", params) => {
1389
+ var _a, _b;
1390
+ return ((_a = vnode.component) == null ? void 0 : _a.exposed) && ((_b = vnode.component) == null ? void 0 : _b.exposed.previewFile(fileUrl, title, params));
1391
+ };
1392
+ }
1393
+ const index$1 = "";
1394
+ const index = {
1395
+ install
1076
1396
  };
1077
1397
  export {
1398
+ _sfc_main$d as Dialog,
1078
1399
  Loading,
1079
- _sfc_main as default
1400
+ _sfc_main$1 as PreviewFile,
1401
+ _sfc_main as PreviewFileDialog,
1402
+ index as default,
1403
+ usePreviewFile
1080
1404
  };