UNPKG

@stihl-design-system/components

Version:

Welcome to the STIHL Design System react component library.

98 lines (97 loc) 3.66 kB
"use client"; import { jsx as d } from "react/jsx-runtime"; import { d as S } from "./chunks/index.cKLI89Eg.js"; import { useState as E } from "react"; import { D as _ } from "./chunks/Icon.DYtaQgbw.js"; import './assets/filepreview.2cdH-1Xs.css';const D = "ds-input-file_preview_15s1u_1", L = "ds-input-file_root_15s1u_7", j = "ds-input-file_file-icon_15s1u_7", u = { preview: D, root: L, fileIcon: j }, I = { nonDisplayableImages: ["heic", "heif", "raw", "cr2", "cr3", "nef", "arw", "orf", "rw2", "dng", "svgz", "jp2", "jxl", "dds", "exr", "psd", "ai", "indd"], documents: [ "doc", "docx", "odt", "fodt", "gdoc", "rtf", "dot", "dotx", "pages", "wpd", "abw", "tmd", "lwp", "wps", "wks", // Excel and spreadsheet formats "xls", "xlsx", "xlsm", "xlsb", "xlt", "xltx", "ods", "fods", "csv", "tsv", "gsheet" ], videos: ["mp4", "m4v", "mov", "webm", "ogv", "avi", "wmv", "flv", "f4v", "mkv", "3gp", "3g2", "ts", "vob", "rm", "rmvb", "mpeg", "mpg"], archives: ["zip", "rar", "7z", "tar", "gz", "tar.gz", "tgz", "xz", "tar.xz", "bz2", "tar.bz2", "lzma", "cab", "iso"] }, k = (p, e) => { const { documents: t, videos: v, archives: r } = I; return p.type.startsWith("image/") ? "file-type-image" : t.includes(e) ? "file-type-doc" : p.type === "application/pdf" ? "file-type-pdf" : p.type.startsWith("video/") && v.includes(e) ? "file-type-video" : r.includes(e) ? "file-type-zip" : "file"; }, C = (p) => { const e = S.c(28), { file: t, theme: v, t: r } = p, i = v === void 0 ? "light" : v, [h, z] = E(!1); let o, a, n, c, l; if (e[0] !== t || e[1] !== h || e[2] !== r || e[3] !== i) { l = /* @__PURE__ */ Symbol.for("react.early_return_sentinel"); e: { const w = t.name.split(".").pop()?.toLowerCase() || "", { nonDisplayableImages: N } = I, x = t.type.startsWith("image/") && !N.includes(w); if (x && h) { let s; e[9] !== i ? (s = /* @__PURE__ */ d("span", { className: u.root, children: /* @__PURE__ */ d(_, { "aria-hidden": "true", name: "file-type-image", className: u.fileIcon, theme: i }) }), e[9] = i, e[10] = s) : s = e[10], l = s; break e; } if (x) { let s; e[11] !== t ? (s = URL.createObjectURL(t), e[11] = t, e[12] = s) : s = e[12]; let f; e[13] !== t.name || e[14] !== r ? (f = r("fileListPreviewAltText", { fileName: t.name }), e[13] = t.name, e[14] = r, e[15] = f) : f = e[15]; let y; e[16] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (y = () => { z(!0); }, e[16] = y) : y = e[16]; let b; e[17] !== s || e[18] !== f ? (b = /* @__PURE__ */ d("img", { src: s, alt: f, className: u.preview, onError: y }), e[17] = s, e[18] = f, e[19] = b) : b = e[19], l = b; break e; } c = u.root, o = _, a = "true", n = k(t, w); } e[0] = t, e[1] = h, e[2] = r, e[3] = i, e[4] = o, e[5] = a, e[6] = n, e[7] = c, e[8] = l; } else o = e[4], a = e[5], n = e[6], c = e[7], l = e[8]; if (l !== /* @__PURE__ */ Symbol.for("react.early_return_sentinel")) return l; let m; e[20] !== o || e[21] !== a || e[22] !== n || e[23] !== i ? (m = /* @__PURE__ */ d(o, { "aria-hidden": a, name: n, className: u.fileIcon, theme: i }), e[20] = o, e[21] = a, e[22] = n, e[23] = i, e[24] = m) : m = e[24]; let g; return e[25] !== c || e[26] !== m ? (g = /* @__PURE__ */ d("span", { className: c, children: m }), e[25] = c, e[26] = m, e[27] = g) : g = e[27], g; }; export { C as FilePreview };