@swisper.ai/web-file-preview 0.0.2 → 0.0.4
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/dist/components/file-preview/components/renderer-types.d.ts +4 -1
- package/dist/components/file-preview/components/renderer-types.d.ts.map +1 -1
- package/dist/components/file-preview/components/viewer/viewer-components.stories.d.ts.map +1 -1
- package/dist/components/file-preview/file-preview.d.ts.map +1 -1
- package/dist/components/file-preview/file-preview.stories.d.ts +49 -2
- package/dist/components/file-preview/file-preview.stories.d.ts.map +1 -1
- package/dist/components/file-thumbnail/components/previews/html-preview.d.ts.map +1 -1
- package/dist/components/file-thumbnail/components/previews/image-preview.d.ts.map +1 -1
- package/dist/components/file-thumbnail/components/previews/markdown-preview.d.ts.map +1 -1
- package/dist/components/file-thumbnail/components/previews/reveal-class-name.d.ts +4 -2
- package/dist/components/file-thumbnail/components/previews/reveal-class-name.d.ts.map +1 -1
- package/dist/components/file-thumbnail/components/previews/scaled-page.d.ts +4 -1
- package/dist/components/file-thumbnail/components/previews/scaled-page.d.ts.map +1 -1
- package/dist/components/file-thumbnail/file-thumbnail.d.ts +2 -0
- package/dist/components/file-thumbnail/file-thumbnail.d.ts.map +1 -1
- package/dist/components/file-thumbnail/file-thumbnail.stories.d.ts +76 -10
- package/dist/components/file-thumbnail/file-thumbnail.stories.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.es.js +50 -33
- package/dist/index.es.js.map +1 -1
- package/package.json +14 -6
- package/src/__storybook__/parent-block.tsx +21 -0
- package/src/components/file-preview/__stories__/fixtures.ts +66 -0
- package/src/components/file-preview/components/renderer-types.ts +4 -1
- package/src/components/file-preview/components/viewer/viewer-components.stories.tsx +2 -8
- package/src/components/file-preview/file-preview.json +15 -0
- package/src/components/file-preview/file-preview.stories.tsx +378 -38
- package/src/components/file-preview/file-preview.tsx +7 -2
- package/src/components/file-thumbnail/__stories__/fixtures.ts +99 -0
- package/src/components/file-thumbnail/__stories__/types.ts +26 -0
- package/src/components/file-thumbnail/components/previews/html-preview.tsx +5 -1
- package/src/components/file-thumbnail/components/previews/image-preview.tsx +3 -1
- package/src/components/file-thumbnail/components/previews/markdown-preview.tsx +5 -1
- package/src/components/file-thumbnail/components/previews/reveal-class-name.ts +8 -8
- package/src/components/file-thumbnail/components/previews/scaled-page.tsx +6 -1
- package/src/components/file-thumbnail/file-thumbnail.json +17 -1
- package/src/components/file-thumbnail/file-thumbnail.stories.tsx +551 -84
- package/src/components/file-thumbnail/file-thumbnail.tsx +24 -7
- /package/src/components/file-thumbnail/components/shared/__tests__/{generation-queue.spec.ts → generation-queue.test.ts} +0 -0
- /package/src/components/file-thumbnail/hooks/__tests__/{use-object-url.spec.ts → use-object-url.test.ts} +0 -0
- /package/src/lib/__tests__/{file-kinds.spec.ts → file-kinds.test.ts} +0 -0
package/dist/index.es.js
CHANGED
|
@@ -290,10 +290,11 @@ function G({ src: e, fileBlob: n, fileName: r, className: i, children: a, onLoad
|
|
|
290
290
|
return /* @__PURE__ */ y(U.Provider, {
|
|
291
291
|
value: M,
|
|
292
292
|
children: /* @__PURE__ */ y("div", {
|
|
293
|
+
"data-slot": "file-preview",
|
|
293
294
|
"data-testid": "file-preview",
|
|
294
295
|
"data-status": T,
|
|
295
296
|
"data-theme": j,
|
|
296
|
-
className: v("relative size-full", i),
|
|
297
|
+
className: v("group/file-preview relative size-full", i),
|
|
297
298
|
children: a
|
|
298
299
|
})
|
|
299
300
|
});
|
|
@@ -306,7 +307,7 @@ var K = s(({ className: e }, t) => {
|
|
|
306
307
|
objectUrl: n,
|
|
307
308
|
fileName: i,
|
|
308
309
|
theme: l,
|
|
309
|
-
className: v("size-full
|
|
310
|
+
className: v("size-full group-data-[status=loading]/file-preview:invisible", e),
|
|
310
311
|
onLoad: s,
|
|
311
312
|
onError: c,
|
|
312
313
|
rootRef: t
|
|
@@ -326,6 +327,7 @@ var q = s(({ asChild: e = !1, children: t, className: n }, i) => {
|
|
|
326
327
|
return a !== "error" || !o ? null : /* @__PURE__ */ y(e ? r : "div", {
|
|
327
328
|
ref: i,
|
|
328
329
|
role: "alert",
|
|
330
|
+
"data-slot": "file-preview-error",
|
|
329
331
|
"data-testid": "file-preview-error",
|
|
330
332
|
className: v("absolute inset-0", n),
|
|
331
333
|
children: t({ error: o })
|
|
@@ -368,6 +370,7 @@ var Z = s(({ asChild: e = !1, children: t, className: n }, i) => {
|
|
|
368
370
|
role: "status",
|
|
369
371
|
"aria-live": "polite",
|
|
370
372
|
"aria-busy": "true",
|
|
373
|
+
"data-slot": "file-preview-loader",
|
|
371
374
|
"data-testid": "file-preview-loader",
|
|
372
375
|
className: v("absolute inset-0", n),
|
|
373
376
|
children: t ?? /* @__PURE__ */ y(ue, { fileName: o })
|
|
@@ -461,9 +464,7 @@ function me(e) {
|
|
|
461
464
|
}
|
|
462
465
|
//#endregion
|
|
463
466
|
//#region src/components/file-thumbnail/components/previews/reveal-class-name.ts
|
|
464
|
-
|
|
465
|
-
return v("transition-[opacity,filter] duration-[160ms] ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none", e === "loaded" ? "opacity-100 blur-none" : "opacity-0 blur-sm");
|
|
466
|
-
}
|
|
467
|
+
var he = v("transition-[opacity,filter] duration-[160ms] ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none", "opacity-0 blur-sm", "data-[status=loaded]:opacity-100 data-[status=loaded]:blur-none");
|
|
467
468
|
//#endregion
|
|
468
469
|
//#region src/components/file-thumbnail/hooks/use-scale-to-fit.ts
|
|
469
470
|
function ge(e, t) {
|
|
@@ -490,21 +491,23 @@ function ge(e, t) {
|
|
|
490
491
|
}
|
|
491
492
|
//#endregion
|
|
492
493
|
//#region src/components/file-thumbnail/components/previews/scaled-page.tsx
|
|
493
|
-
function _e({ designWidth: e,
|
|
494
|
-
let
|
|
494
|
+
function _e({ designWidth: e, status: t, className: n, children: r }) {
|
|
495
|
+
let i = p(null), { scale: a, designHeight: o } = ge(i, e);
|
|
495
496
|
return /* @__PURE__ */ y("div", {
|
|
496
|
-
ref:
|
|
497
|
+
ref: i,
|
|
497
498
|
"aria-hidden": !0,
|
|
498
|
-
|
|
499
|
+
"data-slot": "file-thumbnail-preview",
|
|
500
|
+
"data-status": t,
|
|
501
|
+
className: v("pointer-events-none absolute inset-0 overflow-hidden bg-white", n),
|
|
499
502
|
children: /* @__PURE__ */ y("div", {
|
|
500
503
|
className: "origin-top-left",
|
|
501
504
|
style: {
|
|
502
505
|
width: e,
|
|
503
|
-
height:
|
|
504
|
-
transform:
|
|
505
|
-
visibility:
|
|
506
|
+
height: o || void 0,
|
|
507
|
+
transform: a ? `scale(${a})` : void 0,
|
|
508
|
+
visibility: a ? void 0 : "hidden"
|
|
506
509
|
},
|
|
507
|
-
children:
|
|
510
|
+
children: r
|
|
508
511
|
})
|
|
509
512
|
});
|
|
510
513
|
}
|
|
@@ -520,7 +523,8 @@ function be(e) {
|
|
|
520
523
|
function xe({ page: e, designWidth: t = ve, status: n, onLoad: r, className: i }) {
|
|
521
524
|
return /* @__PURE__ */ y(_e, {
|
|
522
525
|
designWidth: t,
|
|
523
|
-
|
|
526
|
+
status: n,
|
|
527
|
+
className: v(he, i),
|
|
524
528
|
children: /* @__PURE__ */ y("iframe", {
|
|
525
529
|
title: "Page preview",
|
|
526
530
|
tabIndex: -1,
|
|
@@ -557,10 +561,12 @@ var we = s(({ url: e, fit: t = "photo", status: n, onLoad: r, onError: i, classN
|
|
|
557
561
|
draggable: !1,
|
|
558
562
|
loading: "lazy",
|
|
559
563
|
decoding: "async",
|
|
564
|
+
"data-slot": "file-thumbnail-preview",
|
|
565
|
+
"data-status": n,
|
|
560
566
|
"data-testid": "file-thumbnail-preview",
|
|
561
567
|
onLoad: (e) => u(e.currentTarget),
|
|
562
568
|
onError: i,
|
|
563
|
-
className: v("absolute inset-0 block size-full bg-white", Se[t], he
|
|
569
|
+
className: v("absolute inset-0 block size-full bg-white", Se[t], he, a)
|
|
564
570
|
});
|
|
565
571
|
});
|
|
566
572
|
we.displayName = "ImagePreview";
|
|
@@ -570,7 +576,8 @@ var Te = 640, Ee = O(() => import("./markdown-page-CxC-uVbL.js").then((e) => e.M
|
|
|
570
576
|
function De({ markdown: e, fileName: t, status: n, onLoad: r, onError: i, className: o }) {
|
|
571
577
|
return /* @__PURE__ */ y(_e, {
|
|
572
578
|
designWidth: Te,
|
|
573
|
-
|
|
579
|
+
status: n,
|
|
580
|
+
className: v(he, o),
|
|
574
581
|
children: /* @__PURE__ */ y("div", {
|
|
575
582
|
"data-testid": "file-thumbnail-preview",
|
|
576
583
|
children: /* @__PURE__ */ y(a, {
|
|
@@ -742,11 +749,12 @@ var Ge = s(({ fileName: n, src: r, fileBlob: i, previewImageUrl: o, isLoading: s
|
|
|
742
749
|
"aria-label": n,
|
|
743
750
|
"aria-busy": q === "loading" || void 0,
|
|
744
751
|
title: n,
|
|
752
|
+
"data-slot": "file-thumbnail",
|
|
745
753
|
"data-testid": "file-thumbnail",
|
|
746
754
|
"data-kind": D ?? "unsupported",
|
|
747
755
|
"data-status": q,
|
|
748
756
|
"data-theme": E,
|
|
749
|
-
className: v("relative size-full overflow-hidden", "user-select-no", "rounded-[8px]", "bg-white", "[contain:layout_paint]", c),
|
|
757
|
+
className: v("group/file-thumbnail relative size-full overflow-hidden", "user-select-no", "rounded-[8px]", "bg-white", "[contain:layout_paint]", c),
|
|
750
758
|
children: [X && O && /* @__PURE__ */ y(te, {
|
|
751
759
|
fileName: n,
|
|
752
760
|
onError: J,
|
|
@@ -802,6 +810,7 @@ var qe = s(({ asChild: e = !1, children: t, className: n }, i) => {
|
|
|
802
810
|
return a === "loading" ? /* @__PURE__ */ y(e ? r : "div", {
|
|
803
811
|
ref: i,
|
|
804
812
|
"aria-hidden": !0,
|
|
813
|
+
"data-slot": "file-thumbnail-loader",
|
|
805
814
|
"data-testid": "file-thumbnail-loader",
|
|
806
815
|
style: Ae,
|
|
807
816
|
className: v("absolute inset-0", t === void 0 && "animate-pulse [animation-delay:1300ms] motion-reduce:animate-none", n),
|
|
@@ -809,28 +818,36 @@ var qe = s(({ asChild: e = !1, children: t, className: n }, i) => {
|
|
|
809
818
|
}) : null;
|
|
810
819
|
});
|
|
811
820
|
qe.displayName = "FileThumbnailLoader";
|
|
812
|
-
function Je({ fileName: e }) {
|
|
813
|
-
let
|
|
814
|
-
return /* @__PURE__ */
|
|
821
|
+
function Je({ fileName: e, className: t }) {
|
|
822
|
+
let n = C(e).length, r = n ? e.slice(0, -n) : e, i = n ? e.slice(-n) : "";
|
|
823
|
+
return /* @__PURE__ */ y(g, {
|
|
815
824
|
variant: "body-small-low",
|
|
816
|
-
className: v("flex min-w-0", "text-black"),
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
825
|
+
className: v("flex min-w-0", "text-black", t),
|
|
826
|
+
asChild: !0,
|
|
827
|
+
children: /* @__PURE__ */ b("p", {
|
|
828
|
+
"data-slot": "file-thumbnail-fallback-label",
|
|
829
|
+
children: [/* @__PURE__ */ y("span", {
|
|
830
|
+
className: "truncate",
|
|
831
|
+
children: r
|
|
832
|
+
}), i && /* @__PURE__ */ y("span", {
|
|
833
|
+
className: "shrink-0",
|
|
834
|
+
children: i
|
|
835
|
+
})]
|
|
836
|
+
})
|
|
824
837
|
});
|
|
825
838
|
}
|
|
826
|
-
var Ye = s(({ asChild: e = !1, children: t, className: n },
|
|
827
|
-
let { fileName:
|
|
828
|
-
return
|
|
829
|
-
ref:
|
|
839
|
+
var Ye = s(({ asChild: e = !1, children: t, className: n, labelClassName: i }, a) => {
|
|
840
|
+
let { fileName: o, status: s } = We("FileThumbnailFallback");
|
|
841
|
+
return s === "error" ? /* @__PURE__ */ y(e ? r : "div", {
|
|
842
|
+
ref: a,
|
|
843
|
+
"data-slot": "file-thumbnail-fallback",
|
|
830
844
|
"data-testid": "file-thumbnail-fallback",
|
|
831
845
|
style: t === void 0 ? Ae : void 0,
|
|
832
846
|
className: v("absolute inset-0 flex items-center justify-center p-8", n),
|
|
833
|
-
children: t ?? /* @__PURE__ */ y(Je, {
|
|
847
|
+
children: t ?? /* @__PURE__ */ y(Je, {
|
|
848
|
+
fileName: o,
|
|
849
|
+
className: i
|
|
850
|
+
})
|
|
834
851
|
}) : null;
|
|
835
852
|
});
|
|
836
853
|
Ye.displayName = "FileThumbnailFallback";
|