@files-preview-app/preview-file 1.3.9 → 1.3.11

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/index.js CHANGED
@@ -2801,13 +2801,28 @@ var MediaPlugin = class {
2801
2801
  video.src = url;
2802
2802
  video.controls = true;
2803
2803
  video.playsInline = true;
2804
- video.style.maxWidth = "90%";
2805
- video.style.maxHeight = "90%";
2806
2804
  video.style.borderRadius = "8px";
2807
2805
  video.style.boxShadow = "0 8px 30px rgba(0,0,0,0.3)";
2808
2806
  video.style.backgroundColor = "#000000";
2807
+ video.style.objectFit = "contain";
2808
+ video.style.transition = "transform 0.2s ease";
2809
2809
  element = video;
2810
2810
  mediaElement = video;
2811
+ const onMeta = () => {
2812
+ if (video.videoWidth > 0 && video.videoHeight > 0) {
2813
+ naturalW = video.videoWidth;
2814
+ naturalH = video.videoHeight;
2815
+ }
2816
+ updateBaseDimensions();
2817
+ applyTransform();
2818
+ };
2819
+ if (video.readyState >= 1 && video.videoWidth > 0) {
2820
+ naturalW = video.videoWidth;
2821
+ naturalH = video.videoHeight;
2822
+ } else {
2823
+ video.addEventListener("loadedmetadata", onMeta, { once: true });
2824
+ video.addEventListener("canplay", onMeta, { once: true });
2825
+ }
2811
2826
  } else if (isAudio) {
2812
2827
  const audio = document.createElement("audio");
2813
2828
  audio.src = url;
@@ -2848,11 +2863,19 @@ var MediaPlugin = class {
2848
2863
  let fitMode = ctx?.options?.fitMode || "width";
2849
2864
  let isUserZoomed = false;
2850
2865
  const updateBaseDimensions = () => {
2851
- if (!isImage) return;
2852
- const img = element;
2853
- if (img.naturalWidth > 0 && img.naturalHeight > 0) {
2854
- naturalW = img.naturalWidth;
2855
- naturalH = img.naturalHeight;
2866
+ if (!isImage && !isVideo) return;
2867
+ if (isImage) {
2868
+ const img = element;
2869
+ if (img.naturalWidth > 0 && img.naturalHeight > 0) {
2870
+ naturalW = img.naturalWidth;
2871
+ naturalH = img.naturalHeight;
2872
+ }
2873
+ } else if (isVideo) {
2874
+ const vid = element;
2875
+ if (vid.videoWidth > 0 && vid.videoHeight > 0) {
2876
+ naturalW = vid.videoWidth;
2877
+ naturalH = vid.videoHeight;
2878
+ }
2856
2879
  }
2857
2880
  const availW = Math.max(100, ctx.container.clientWidth - 32);
2858
2881
  const availH = Math.max(100, ctx.container.clientHeight - 32);
@@ -2866,7 +2889,7 @@ var MediaPlugin = class {
2866
2889
  baseH = Math.max(1, Math.round(naturalH * fitRatio));
2867
2890
  };
2868
2891
  const applyTransform = () => {
2869
- if (isImage) {
2892
+ if (isImage || isVideo) {
2870
2893
  if (!isUserZoomed) {
2871
2894
  updateBaseDimensions();
2872
2895
  }
@@ -2877,10 +2900,10 @@ var MediaPlugin = class {
2877
2900
  sizer.style.width = `${boxW}px`;
2878
2901
  sizer.style.height = `${boxH}px`;
2879
2902
  sizer.style.margin = boxH < availH ? "auto 0" : "0";
2880
- const imgW = isRotated90 ? boxH : boxW;
2881
- const imgH = isRotated90 ? boxW : boxH;
2882
- element.style.width = `${imgW}px`;
2883
- element.style.height = `${imgH}px`;
2903
+ const elW = isRotated90 ? boxH : boxW;
2904
+ const elH = isRotated90 ? boxW : boxH;
2905
+ element.style.width = `${elW}px`;
2906
+ element.style.height = `${elH}px`;
2884
2907
  element.style.maxWidth = "none";
2885
2908
  element.style.maxHeight = "none";
2886
2909
  element.style.transform = rotation ? `rotate(${rotation}deg)` : "none";
@@ -2890,6 +2913,8 @@ var MediaPlugin = class {
2890
2913
  element.style.transform = `scale(${currentZoom}) rotate(${rotation}deg)`;
2891
2914
  }
2892
2915
  };
2916
+ updateBaseDimensions();
2917
+ applyTransform();
2893
2918
  if (isImage) {
2894
2919
  const img = element;
2895
2920
  if (img.complete && img.naturalWidth > 0) {
@@ -2934,7 +2959,7 @@ var MediaPlugin = class {
2934
2959
  currentZoom = level;
2935
2960
  applyTransform();
2936
2961
  } : void 0,
2937
- fitToPage: isImage ? () => {
2962
+ fitToPage: isImage || isVideo ? () => {
2938
2963
  isUserZoomed = false;
2939
2964
  fitMode = "page";
2940
2965
  currentZoom = 1;
@@ -2944,7 +2969,7 @@ var MediaPlugin = class {
2944
2969
  updateBaseDimensions();
2945
2970
  applyTransform();
2946
2971
  } : void 0,
2947
- fitToWidth: isImage ? () => {
2972
+ fitToWidth: isImage || isVideo ? () => {
2948
2973
  isUserZoomed = false;
2949
2974
  fitMode = "width";
2950
2975
  currentZoom = 1;
@@ -2954,7 +2979,7 @@ var MediaPlugin = class {
2954
2979
  updateBaseDimensions();
2955
2980
  applyTransform();
2956
2981
  } : void 0,
2957
- resetZoom: isImage ? () => {
2982
+ resetZoom: isImage || isVideo ? () => {
2958
2983
  isUserZoomed = false;
2959
2984
  fitMode = ctx?.options?.fitMode || "width";
2960
2985
  currentZoom = 1;
@@ -4857,6 +4882,36 @@ var CodePlugin = class {
4857
4882
  pre.style.transition = "transform 0.15s ease";
4858
4883
  pre.style.flexShrink = "0";
4859
4884
  } else {
4885
+ if (typeof document !== "undefined" && !document.getElementById("fp-code-syntax-styles")) {
4886
+ const style = document.createElement("style");
4887
+ style.id = "fp-code-syntax-styles";
4888
+ style.textContent = `
4889
+ .fp-code-scroll-wrapper .hljs-keyword { color: #569cd6; font-weight: normal; }
4890
+ .fp-code-scroll-wrapper .hljs-built_in { color: #4ec9b0; }
4891
+ .fp-code-scroll-wrapper .hljs-type { color: #4ec9b0; }
4892
+ .fp-code-scroll-wrapper .hljs-literal { color: #569cd6; }
4893
+ .fp-code-scroll-wrapper .hljs-number { color: #b5cea8; }
4894
+ .fp-code-scroll-wrapper .hljs-regexp { color: #d16969; }
4895
+ .fp-code-scroll-wrapper .hljs-string { color: #ce9178; }
4896
+ .fp-code-scroll-wrapper .hljs-subst { color: #d4d4d4; }
4897
+ .fp-code-scroll-wrapper .hljs-symbol { color: #569cd6; }
4898
+ .fp-code-scroll-wrapper .hljs-class { color: #4ec9b0; }
4899
+ .fp-code-scroll-wrapper .hljs-function { color: #dcdcaa; }
4900
+ .fp-code-scroll-wrapper .hljs-title { color: #dcdcaa; }
4901
+ .fp-code-scroll-wrapper .hljs-params { color: #9cdcfe; }
4902
+ .fp-code-scroll-wrapper .hljs-comment { color: #6a9955; font-style: italic; }
4903
+ .fp-code-scroll-wrapper .hljs-doctag { color: #608b4e; }
4904
+ .fp-code-scroll-wrapper .hljs-meta { color: #9cdcfe; }
4905
+ .fp-code-scroll-wrapper .hljs-section { color: #569cd6; }
4906
+ .fp-code-scroll-wrapper .hljs-tag { color: #569cd6; }
4907
+ .fp-code-scroll-wrapper .hljs-name { color: #569cd6; }
4908
+ .fp-code-scroll-wrapper .hljs-attr { color: #9cdcfe; }
4909
+ .fp-code-scroll-wrapper .hljs-attribute { color: #9cdcfe; }
4910
+ .fp-code-scroll-wrapper .hljs-variable { color: #9cdcfe; }
4911
+ .fp-code-scroll-wrapper .hljs-punctuation { color: #d4d4d4; }
4912
+ `;
4913
+ document.head.appendChild(style);
4914
+ }
4860
4915
  ctx.container.style.backgroundColor = "#1e1e1e";
4861
4916
  ctx.container.style.color = "#d4d4d4";
4862
4917
  scrollWrapper.className = "fp-code-scroll-wrapper";
@@ -4866,9 +4921,13 @@ var CodePlugin = class {
4866
4921
  scrollWrapper.style.height = "max-content";
4867
4922
  scrollWrapper.style.display = "flex";
4868
4923
  scrollWrapper.style.alignItems = "flex-start";
4869
- scrollWrapper.style.padding = "16px";
4924
+ scrollWrapper.style.padding = "16px 16px 16px 0";
4870
4925
  scrollWrapper.style.boxSizing = "border-box";
4871
- const lineCount = fullText.split(/\r?\n/).length || 1;
4926
+ const rawLines = fullText.split(/\r?\n/);
4927
+ if (rawLines.length > 1 && rawLines[rawLines.length - 1] === "") {
4928
+ rawLines.pop();
4929
+ }
4930
+ const lineCount = Math.max(1, rawLines.length);
4872
4931
  const gutterLines = [];
4873
4932
  for (let i = 1; i <= lineCount; i++) {
4874
4933
  gutterLines.push(String(i));
@@ -4876,16 +4935,23 @@ var CodePlugin = class {
4876
4935
  lineGutter.className = "fp-code-gutter";
4877
4936
  lineGutter.style.userSelect = "none";
4878
4937
  lineGutter.style.textAlign = "right";
4879
- lineGutter.style.paddingRight = "16px";
4880
- lineGutter.style.marginRight = "16px";
4938
+ lineGutter.style.padding = "0 16px";
4939
+ lineGutter.style.margin = "0 16px 0 0";
4881
4940
  lineGutter.style.borderRight = "1px solid #333333";
4882
4941
  lineGutter.style.color = "#858585";
4883
4942
  lineGutter.style.fontFamily = "Consolas, Menlo, Monaco, 'Courier New', monospace";
4884
4943
  lineGutter.style.fontSize = `${fontSize}px`;
4885
4944
  lineGutter.style.lineHeight = "1.6";
4945
+ lineGutter.style.whiteSpace = "pre";
4886
4946
  lineGutter.style.flexShrink = "0";
4947
+ lineGutter.style.position = "sticky";
4948
+ lineGutter.style.left = "0";
4949
+ lineGutter.style.backgroundColor = "#1e1e1e";
4950
+ lineGutter.style.zIndex = "2";
4951
+ lineGutter.style.boxSizing = "border-box";
4887
4952
  lineGutter.textContent = gutterLines.join("\n");
4888
4953
  pre.style.margin = "0";
4954
+ pre.style.padding = "0 16px 0 0";
4889
4955
  pre.style.fontFamily = "Consolas, Menlo, Monaco, 'Courier New', monospace";
4890
4956
  pre.style.fontSize = `${fontSize}px`;
4891
4957
  pre.style.lineHeight = "1.6";
@@ -4893,6 +4959,11 @@ var CodePlugin = class {
4893
4959
  pre.style.wordBreak = "normal";
4894
4960
  pre.style.overflowWrap = "normal";
4895
4961
  pre.style.flex = "1";
4962
+ code.style.display = "block";
4963
+ code.style.fontFamily = "inherit";
4964
+ code.style.fontSize = "inherit";
4965
+ code.style.lineHeight = "inherit";
4966
+ code.style.whiteSpace = "inherit";
4896
4967
  }
4897
4968
  const ext = (ctx.metadata.extension || "").replace(".", "");
4898
4969
  const renderCodePage = (text) => {