@twick/media-utils 0.0.1 → 0.14.0

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/LICENSE ADDED
@@ -0,0 +1,197 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ -------------------------------------------------------------------------------
177
+
178
+ ADDITIONAL TERMS – NO RESALE / NO STANDALONE REDISTRIBUTION
179
+
180
+ The following additional terms apply to this project:
181
+
182
+ 1. **No Standalone Resale or Licensing**
183
+ You may not sell, license, sublicense, or otherwise commercially distribute this software, or any modified version of it, as a standalone product, SDK, or developer tool/library.
184
+
185
+ 2. **Permitted Commercial Use**
186
+ You may use this software in commercial applications, platforms, or services provided that:
187
+ - It is part of a larger product or service with meaningful added value.
188
+ - It is not positioned or marketed as a competing SDK or developer tool.
189
+
190
+ 3. **Cloud Function Restrictions**
191
+ You may self-host the cloud function components within your application or product. However, you may not offer them as a hosted service, API, or commercial cloud product without obtaining a commercial license.
192
+
193
+ 4. **Trademark and Branding Restrictions**
194
+ You may not use the name, logo, or branding associated with this project to market, redistribute, or promote your own products without explicit written permission.
195
+
196
+ For commercial licensing, redistribution rights, or branding permissions, please contact: [contact@kifferai.com]
197
+
package/dist/index.js CHANGED
@@ -13,6 +13,10 @@ const getAudioDuration = (audioSrc) => {
13
13
  return new Promise((resolve, reject) => {
14
14
  const audio = document.createElement("audio");
15
15
  audio.preload = "metadata";
16
+ const isSafeUrl = /^(https?:|blob:|data:audio\/)/i.test(audioSrc);
17
+ if (!isSafeUrl) {
18
+ throw new Error("Unsafe audio source URL");
19
+ }
16
20
  audio.src = audioSrc;
17
21
  audio.onloadedmetadata = () => {
18
22
  const duration = audio.duration;
@@ -53,7 +57,7 @@ function limit(fn) {
53
57
  });
54
58
  }
55
59
 
56
- function loadImageDimensions(url) {
60
+ const loadImageDimensions = (url) => {
57
61
  return new Promise((resolve, reject) => {
58
62
  if (typeof document === "undefined") {
59
63
  reject(new Error("getImageDimensions() is only available in the browser."));
@@ -66,8 +70,8 @@ function loadImageDimensions(url) {
66
70
  img.onerror = reject;
67
71
  img.src = url;
68
72
  });
69
- }
70
- function getImageDimensions(url) {
73
+ };
74
+ const getImageDimensions = (url) => {
71
75
  if (imageDimensionsCache[url]) {
72
76
  return Promise.resolve(imageDimensionsCache[url]);
73
77
  }
@@ -75,7 +79,7 @@ function getImageDimensions(url) {
75
79
  imageDimensionsCache[url] = dimensions;
76
80
  return dimensions;
77
81
  });
78
- }
82
+ };
79
83
 
80
84
  const getVideoMeta = (videoSrc) => {
81
85
  if (videoMetaCache[videoSrc]) {
@@ -84,6 +88,11 @@ const getVideoMeta = (videoSrc) => {
84
88
  return new Promise((resolve, reject) => {
85
89
  const video = document.createElement("video");
86
90
  video.preload = "metadata";
91
+ const isSafeUrl = /^(https?:|blob:|data:video\/)/i.test(videoSrc);
92
+ if (!isSafeUrl) {
93
+ reject(new Error("Unsafe video source URL"));
94
+ return;
95
+ }
87
96
  video.src = videoSrc;
88
97
  video.onloadedmetadata = () => {
89
98
  const meta = {
@@ -98,7 +107,7 @@ const getVideoMeta = (videoSrc) => {
98
107
  });
99
108
  };
100
109
 
101
- async function getThumbnail(videoUrl, seekTime = 0.1, playbackRate = 1) {
110
+ const getThumbnail = async (videoUrl, seekTime = 0.1, playbackRate = 1) => {
102
111
  return new Promise((resolve, reject) => {
103
112
  const video = document.createElement("video");
104
113
  video.crossOrigin = "anonymous";
@@ -107,6 +116,14 @@ async function getThumbnail(videoUrl, seekTime = 0.1, playbackRate = 1) {
107
116
  video.autoplay = false;
108
117
  video.preload = "auto";
109
118
  video.playbackRate = playbackRate;
119
+ video.style.position = "absolute";
120
+ video.style.left = "-9999px";
121
+ video.style.top = "-9999px";
122
+ video.style.width = "1px";
123
+ video.style.height = "1px";
124
+ video.style.opacity = "0";
125
+ video.style.pointerEvents = "none";
126
+ video.style.zIndex = "-1";
110
127
  let timeoutId;
111
128
  const cleanup = () => {
112
129
  if (video.parentNode) video.remove();
@@ -173,9 +190,9 @@ async function getThumbnail(videoUrl, seekTime = 0.1, playbackRate = 1) {
173
190
  video.src = videoUrl;
174
191
  document.body.appendChild(video);
175
192
  });
176
- }
193
+ };
177
194
 
178
- function getScaledDimensions(width, height, maxWidth, maxHeight) {
195
+ const getScaledDimensions = (width, height, maxWidth, maxHeight) => {
179
196
  if (width <= maxWidth && height <= maxHeight) {
180
197
  return {
181
198
  width: width % 2 === 0 ? width : width - 1,
@@ -197,8 +214,8 @@ function getScaledDimensions(width, height, maxWidth, maxHeight) {
197
214
  width: Math.min(scaledWidth, maxWidth),
198
215
  height: Math.min(scaledHeight, maxHeight)
199
216
  };
200
- }
201
- function getObjectFitSize(objectFit, elementSize, containerSize) {
217
+ };
218
+ const getObjectFitSize = (objectFit, elementSize, containerSize) => {
202
219
  const elementAspectRatio = elementSize.width / elementSize.height;
203
220
  const containerAspectRatio = containerSize.width / containerSize.height;
204
221
  switch (objectFit) {
@@ -237,14 +254,14 @@ function getObjectFitSize(objectFit, elementSize, containerSize) {
237
254
  height: elementSize.height
238
255
  };
239
256
  }
240
- }
257
+ };
241
258
 
242
- async function blobUrlToFile(blobUrl, fileName) {
259
+ const blobUrlToFile = async (blobUrl, fileName) => {
243
260
  const response = await fetch(blobUrl);
244
261
  const blob = await response.blob();
245
262
  return new File([blob], fileName, { type: blob.type });
246
- }
247
- function saveAsFile(content, type, name) {
263
+ };
264
+ const saveAsFile = (content, type, name) => {
248
265
  const blob = typeof content === "string" ? new Blob([content], { type }) : content;
249
266
  const url = URL.createObjectURL(blob);
250
267
  const a = document.createElement("a");
@@ -252,8 +269,8 @@ function saveAsFile(content, type, name) {
252
269
  a.download = name;
253
270
  a.click();
254
271
  URL.revokeObjectURL(url);
255
- }
256
- async function downloadFile(url, filename) {
272
+ };
273
+ const downloadFile = async (url, filename) => {
257
274
  try {
258
275
  const response = await fetch(url);
259
276
  const blob = await response.blob();
@@ -269,9 +286,9 @@ async function downloadFile(url, filename) {
269
286
  console.error("Error downloading file:", error);
270
287
  throw error;
271
288
  }
272
- }
289
+ };
273
290
 
274
- async function detectMediaTypeFromUrl(url) {
291
+ const detectMediaTypeFromUrl = async (url) => {
275
292
  try {
276
293
  const response = await fetch(url, { method: "HEAD" });
277
294
  const contentType = response.headers.get("Content-Type");
@@ -284,7 +301,7 @@ async function detectMediaTypeFromUrl(url) {
284
301
  console.error("Fetch failed:", error);
285
302
  return null;
286
303
  }
287
- }
304
+ };
288
305
 
289
306
  exports.blobUrlToFile = blobUrlToFile;
290
307
  exports.detectMediaTypeFromUrl = detectMediaTypeFromUrl;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/cache.ts","../src/get-audio-duration.ts","../src/limit.ts","../src/get-image-dimensions.ts","../src/get-video-metadata.ts","../src/get-thumbnail.ts","../src/dimension-handler.ts","../src/file-helper.ts","../src/url-helper.ts"],"sourcesContent":["import { Dimensions, VideoMeta } from \"./types\";\r\n\r\nexport const imageDimensionsCache: Record<string, Dimensions> = {};\r\nexport const videoMetaCache: Record<string, VideoMeta> = {};\r\nexport const audioDurationCache: Record<string, number> = {};","import { audioDurationCache } from \"./cache\";\r\n\r\n/**\r\n * Retrieves the duration (in seconds) of an audio file from a given source URL.\r\n * Uses a cache to avoid reloading the same audio multiple times.\r\n *\r\n * @param audioSrc - The source URL of the audio file.\r\n * @returns A Promise that resolves to the duration of the audio in seconds.\r\n */\r\nexport const getAudioDuration = (audioSrc: string): Promise<number> => {\r\n // Return cached duration if available\r\n if (audioDurationCache[audioSrc]) {\r\n return Promise.resolve(audioDurationCache[audioSrc]);\r\n }\r\n\r\n return new Promise((resolve, reject) => {\r\n const audio = document.createElement(\"audio\");\r\n audio.preload = \"metadata\"; // Only load metadata (e.g., duration)\r\n audio.src = audioSrc;\r\n\r\n // When metadata is loaded, store duration in cache and resolve\r\n audio.onloadedmetadata = () => {\r\n const duration = audio.duration;\r\n audioDurationCache[audioSrc] = duration;\r\n resolve(duration);\r\n };\r\n\r\n // Handle loading errors\r\n audio.onerror = () => {\r\n reject(new Error(\"Failed to load audio metadata\"));\r\n };\r\n });\r\n};\r\n","// Maximum number of concurrent promises allowed to run\r\nconst concurrencyLimit = 5;\r\n\r\n// Number of currently active (running) promises\r\nlet activeCount = 0;\r\n\r\n// Queue to hold pending tasks waiting to be run when concurrency slots free up\r\nconst queue: Array<() => void> = [];\r\n\r\n/**\r\n * Runs the next task from the queue if concurrency limit is not reached.\r\n */\r\nfunction runNext() {\r\n // If no tasks are queued or we're already at the concurrency limit, do nothing\r\n if (queue.length === 0 || activeCount >= concurrencyLimit) return;\r\n\r\n // Dequeue next task\r\n const next = queue.shift();\r\n\r\n if (next) {\r\n activeCount++; // Mark one more active task\r\n next(); // Run it\r\n }\r\n}\r\n\r\n/**\r\n * Wraps an async function to enforce concurrency limits.\r\n * If concurrency limit is reached, the function is queued and executed later.\r\n * \r\n * @param fn - Async function returning a Promise\r\n * @returns Promise that resolves/rejects with fn's result\r\n */\r\nexport function limit<T>(fn: () => Promise<T>): Promise<T> {\r\n return new Promise((resolve, reject) => {\r\n // Task to run the function and handle completion\r\n const task = () => {\r\n fn()\r\n .then(resolve)\r\n .catch(reject)\r\n .finally(() => {\r\n activeCount--; // Mark task as done\r\n runNext(); // Trigger next queued task, if any\r\n });\r\n };\r\n\r\n if (activeCount < concurrencyLimit) {\r\n activeCount++; // Increment active count for immediate run\r\n task();\r\n } else {\r\n // Queue the task if concurrency limit reached\r\n queue.push(task);\r\n }\r\n });\r\n}\r\n","import { limit } from \"./limit\";\r\nimport { Dimensions } from \"./types\";\r\nimport { imageDimensionsCache } from \"./cache\";\r\n\r\n/**\r\n * Loads an image from the given URL and resolves with its natural dimensions.\r\n *\r\n * @param url - The image URL to load.\r\n * @returns A Promise that resolves with the image's width and height.\r\n */\r\nfunction loadImageDimensions(url: string): Promise<Dimensions> {\r\n return new Promise((resolve, reject) => {\r\n if (typeof document === 'undefined') {\r\n reject(new Error('getImageDimensions() is only available in the browser.'));\r\n return;\r\n }\r\n\r\n const img = new Image();\r\n img.onload = () => {\r\n resolve({ width: img.naturalWidth, height: img.naturalHeight });\r\n };\r\n img.onerror = reject;\r\n img.src = url;\r\n });\r\n}\r\n\r\n/**\r\n * Gets the dimensions (width and height) of an image from the given URL.\r\n * Uses a cache to avoid reloading the image if already fetched.\r\n * Also uses a concurrency limiter to control resource usage.\r\n *\r\n * @param url - The URL of the image.\r\n * @returns A Promise that resolves to an object containing `width` and `height`.\r\n */\r\nexport function getImageDimensions(url: string): Promise<Dimensions> {\r\n // Return cached dimensions if available\r\n if (imageDimensionsCache[url]) {\r\n return Promise.resolve(imageDimensionsCache[url]);\r\n }\r\n\r\n // Fetch and cache the dimensions using a concurrency limit\r\n return limit(() => loadImageDimensions(url)).then((dimensions) => {\r\n imageDimensionsCache[url] = dimensions;\r\n return dimensions;\r\n });\r\n}\r\n","import { videoMetaCache } from \"./cache\";\r\nimport { VideoMeta } from \"./types\";\r\n\r\n/**\r\n * Fetches metadata (width, height, duration) for a given video source.\r\n * If metadata has already been fetched and cached, it returns the cached data.\r\n *\r\n * @param videoSrc - The URL or path to the video file.\r\n * @returns A Promise that resolves to an object containing video metadata.\r\n */\r\nexport const getVideoMeta = (videoSrc: string): Promise<VideoMeta> => {\r\n // Return cached metadata if available\r\n if (videoMetaCache[videoSrc]) {\r\n return Promise.resolve(videoMetaCache[videoSrc]);\r\n }\r\n\r\n return new Promise<VideoMeta>((resolve, reject) => {\r\n const video: HTMLVideoElement = document.createElement(\"video\");\r\n video.preload = \"metadata\"; // Only preload metadata to reduce bandwidth\r\n video.src = videoSrc;\r\n\r\n // When metadata is loaded, extract and cache it\r\n video.onloadedmetadata = () => {\r\n const meta: VideoMeta = {\r\n width: video.videoWidth,\r\n height: video.videoHeight,\r\n duration: video.duration,\r\n };\r\n videoMetaCache[videoSrc] = meta;\r\n resolve(meta);\r\n };\r\n\r\n // Handle video loading errors\r\n video.onerror = () => reject(new Error(\"Failed to load video metadata\"));\r\n });\r\n};\r\n","/**\r\n * Extracts a thumbnail from a video at a specific seek time and playback rate.\r\n *\r\n * This function creates a hidden `<video>` element in the browser,\r\n * seeks to the specified time, and captures the frame into a canvas,\r\n * which is then exported as a JPEG data URL or Blob URL.\r\n *\r\n * @param videoUrl - The URL of the video to extract the thumbnail from.\r\n * @param seekTime - The time in seconds at which to capture the frame. Default is 0.1s.\r\n * @param playbackRate - Playback speed for the video. Default is 1.\r\n * @returns A Promise that resolves to a thumbnail image URL (either a base64 data URL or blob URL).\r\n */\r\nexport async function getThumbnail(\r\n videoUrl: string,\r\n seekTime = 0.1,\r\n playbackRate = 1\r\n ): Promise<string> {\r\n return new Promise((resolve, reject) => {\r\n const video = document.createElement(\"video\");\r\n video.crossOrigin = \"anonymous\";\r\n video.muted = true;\r\n video.playsInline = true;\r\n video.autoplay = false;\r\n video.preload = \"auto\";\r\n video.playbackRate = playbackRate;\r\n \r\n let timeoutId: number | undefined;\r\n \r\n // Cleanup video element and timeout\r\n const cleanup = () => {\r\n if (video.parentNode) video.remove();\r\n if (timeoutId) clearTimeout(timeoutId);\r\n };\r\n \r\n // Handle errors during video loading\r\n const handleError = () => {\r\n cleanup();\r\n reject(new Error(`Failed to load video: ${video.error?.message || \"Unknown error\"}`));\r\n };\r\n \r\n // Once seeked to target frame, capture the image\r\n const handleSeeked = () => {\r\n try {\r\n video.pause();\r\n \r\n const canvas = document.createElement(\"canvas\");\r\n const width = video.videoWidth || 640;\r\n const height = video.videoHeight || 360;\r\n canvas.width = width;\r\n canvas.height = height;\r\n \r\n const ctx = canvas.getContext(\"2d\");\r\n if (!ctx) {\r\n cleanup();\r\n reject(new Error(\"Failed to get canvas context\"));\r\n return;\r\n }\r\n \r\n // Draw current video frame onto canvas\r\n ctx.drawImage(video, 0, 0, width, height);\r\n \r\n // Attempt to export canvas to base64 image URL\r\n try {\r\n const dataUrl = canvas.toDataURL(\"image/jpeg\", 0.8);\r\n cleanup();\r\n resolve(dataUrl);\r\n } catch {\r\n // Fallback: convert canvas to Blob\r\n canvas.toBlob((blob) => {\r\n if (!blob) {\r\n cleanup();\r\n reject(new Error(\"Failed to create Blob\"));\r\n return;\r\n }\r\n const blobUrl = URL.createObjectURL(blob);\r\n cleanup();\r\n resolve(blobUrl);\r\n }, \"image/jpeg\", 0.8);\r\n }\r\n } catch (err) {\r\n cleanup();\r\n reject(new Error(`Error creating thumbnail: ${err}`));\r\n }\r\n };\r\n \r\n video.addEventListener(\"error\", handleError, { once: true });\r\n video.addEventListener(\"seeked\", handleSeeked, { once: true });\r\n \r\n // After metadata is loaded, seek to the desired frame\r\n video.addEventListener(\"loadedmetadata\", () => {\r\n const playPromise = video.play();\r\n if (playPromise !== undefined) {\r\n playPromise\r\n .then(() => {\r\n video.currentTime = seekTime;\r\n })\r\n .catch(() => {\r\n video.currentTime = seekTime;\r\n });\r\n } else {\r\n video.currentTime = seekTime;\r\n }\r\n }, { once: true });\r\n \r\n // Timeout protection in case video loading hangs\r\n timeoutId = window.setTimeout(() => {\r\n cleanup();\r\n reject(new Error(\"Video loading timed out\"));\r\n }, 5000);\r\n \r\n // Assign video source and add it to the DOM (helps Safari/iOS behavior)\r\n video.src = videoUrl;\r\n document.body.appendChild(video);\r\n });\r\n }\r\n ","import { Dimensions } from \"./types\";\r\n\r\n/**\r\n * Calculates the scaled dimensions of an element to fit inside a container\r\n * based on the specified max dimensions.\r\n *\r\n * @param width - The original width of the element.\r\n * @param height - The original height of the element.\r\n * @param maxWidth - The maximum width of the container.\r\n * @param maxHeight - The maximum height of the container.\r\n * @returns An object containing the calculated width and height for the element.\r\n */\r\nexport function getScaledDimensions(\r\n width: number, \r\n height: number,\r\n maxWidth: number,\r\n maxHeight: number\r\n ): Dimensions {\r\n // If the original dimensions are smaller than or equal to the max values, return the original dimensions\r\n if (width <= maxWidth && height <= maxHeight) {\r\n // Ensure the width and height are even numbers\r\n return {\r\n width: width % 2 === 0 ? width : width - 1,\r\n height: height % 2 === 0 ? height : height - 1,\r\n };\r\n }\r\n \r\n // Calculate scaling factor based on the maximum width and height\r\n const widthRatio = maxWidth / width;\r\n const heightRatio = maxHeight / height;\r\n \r\n // Use the smaller of the two ratios to maintain the aspect ratio\r\n const scale = Math.min(widthRatio, heightRatio);\r\n \r\n // Calculate the scaled dimensions\r\n let scaledWidth = Math.round(width * scale);\r\n let scaledHeight = Math.round(height * scale);\r\n \r\n // Ensure the width and height are even numbers\r\n if (scaledWidth % 2 !== 0) {\r\n scaledWidth -= 1; // Make width even if it's odd\r\n }\r\n if (scaledHeight % 2 !== 0) {\r\n scaledHeight -= 1; // Make height even if it's odd\r\n }\r\n \r\n // Ensure the scaled width and height fit within the max dimensions\r\n return {\r\n width: Math.min(scaledWidth, maxWidth),\r\n height: Math.min(scaledHeight, maxHeight),\r\n };\r\n }\r\n\r\n/**\r\n * Calculates the resized dimensions of an element to fit inside a container\r\n * based on the specified object-fit strategy (\"contain\", \"cover\", \"fill\", or default).\r\n *\r\n * @param objectFit - The object-fit behavior ('contain', 'cover', 'fill', or default/fallback).\r\n * @param elementSize - The original size of the element (width and height).\r\n * @param containerSize - The size of the container (width and height).\r\n * @returns An object containing the calculated width and height for the element.\r\n */\r\nexport function getObjectFitSize(\r\n objectFit: string,\r\n elementSize: Dimensions,\r\n containerSize: Dimensions\r\n): Dimensions {\r\n const elementAspectRatio = elementSize.width / elementSize.height;\r\n const containerAspectRatio = containerSize.width / containerSize.height;\r\n\r\n switch (objectFit) {\r\n case \"contain\":\r\n // Fit entire element inside container without cropping, maintaining aspect ratio\r\n if (elementAspectRatio > containerAspectRatio) {\r\n return {\r\n width: containerSize.width,\r\n height: containerSize.width / elementAspectRatio,\r\n };\r\n } else {\r\n return {\r\n width: containerSize.height * elementAspectRatio,\r\n height: containerSize.height,\r\n };\r\n }\r\n\r\n case \"cover\":\r\n // Fill container while maintaining aspect ratio, possibly cropping the element\r\n if (elementAspectRatio > containerAspectRatio) {\r\n return {\r\n width: containerSize.height * elementAspectRatio,\r\n height: containerSize.height,\r\n };\r\n } else {\r\n return {\r\n width: containerSize.width,\r\n height: containerSize.width / elementAspectRatio,\r\n };\r\n }\r\n\r\n case \"fill\":\r\n // Stretch element to completely fill the container, ignoring aspect ratio\r\n return {\r\n width: containerSize.width,\r\n height: containerSize.height,\r\n };\r\n\r\n default:\r\n // Default behavior: return original size of the element\r\n return {\r\n width: elementSize.width,\r\n height: elementSize.height,\r\n };\r\n }\r\n};\r\n\r\n ","/**\r\n * Converts a Blob URL to a File object.\r\n *\r\n * @param blobUrl - The Blob URL to convert.\r\n * @param fileName - The name to assign to the resulting File.\r\n * @returns A Promise that resolves to a File object.\r\n */\r\nexport async function blobUrlToFile(blobUrl: string, fileName: string): Promise<File> {\r\n const response = await fetch(blobUrl);\r\n const blob = await response.blob();\r\n return new File([blob], fileName, { type: blob.type });\r\n }\r\n \r\n /**\r\n * Triggers a download of a file from a string or Blob.\r\n *\r\n * @param content - The content to save, either a string or a Blob.\r\n * @param type - The MIME type of the content.\r\n * @param name - The name of the file to be saved.\r\n */\r\n export function saveAsFile(content: string | Blob, type: string, name: string): void {\r\n const blob = typeof content === \"string\" ? new Blob([content], { type }) : content;\r\n const url = URL.createObjectURL(blob);\r\n \r\n const a = document.createElement(\"a\");\r\n a.href = url;\r\n a.download = name;\r\n a.click();\r\n \r\n // Clean up the URL object after download\r\n URL.revokeObjectURL(url);\r\n }\r\n \r\n /**\r\n * Downloads a file from a given URL and triggers a browser download.\r\n *\r\n * @param url - The URL of the file to download.\r\n * @param filename - The name of the file to be saved.\r\n * @returns A Promise that resolves when the download is initiated or rejects if there is an error.\r\n */\r\n export async function downloadFile(url: string, filename: string): Promise<void> {\r\n try {\r\n const response = await fetch(url);\r\n const blob = await response.blob();\r\n const downloadUrl = window.URL.createObjectURL(blob);\r\n \r\n const link = document.createElement(\"a\");\r\n link.href = downloadUrl;\r\n link.download = filename;\r\n document.body.appendChild(link);\r\n link.click();\r\n \r\n // Clean up\r\n document.body.removeChild(link);\r\n window.URL.revokeObjectURL(downloadUrl);\r\n } catch (error) {\r\n console.error(\"Error downloading file:\", error);\r\n throw error;\r\n }\r\n }\r\n ","/**\r\n * Detects the media type (image, video, or audio) of a given URL by sending a HEAD request.\r\n *\r\n * @param url - The URL of the media file.\r\n * @returns A promise that resolves to 'image', 'video', or 'audio' based on the Content-Type header,\r\n * or `null` if the type couldn't be determined or the request fails.\r\n */\r\nexport async function detectMediaTypeFromUrl(url: string): Promise<'image' | 'video' | 'audio' | null> {\r\n try {\r\n // Use a HEAD request to fetch only the headers, avoiding download of the full file\r\n const response = await fetch(url, { method: 'HEAD' });\r\n \r\n // Extract the 'Content-Type' header from the response\r\n const contentType = response.headers.get('Content-Type');\r\n \r\n if (!contentType) return null;\r\n \r\n // Determine the media type from the content type\r\n if (contentType.startsWith('image/')) return 'image';\r\n if (contentType.startsWith('video/')) return 'video';\r\n if (contentType.startsWith('audio/')) return 'audio';\r\n \r\n // Return null if not a rec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,IAAS,QAAA,CAAA,IAAA,CAAK,YAAY,IAAI,CAAA;AAC9B,IAAO,MAAA,CAAA,GAAA,CAAI,gBAAgB,WAAW,CAAA;AAAA,WAC/B,KAAO,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,2BAA2B,KAAK,CAAA;AAC9C,IAAM,MAAA,KAAA;AAAA;AAEV;;ACpDF,eAAsB,uBAAuB,GAA0D,EAAA;AACnG,EAAI,IAAA;AAEF,IAAA,MAAM,WAAW,MAAM,KAAA,CAAM,KAAK,EAAE,MAAA,EAAQ,QAAQ,CAAA;AAGpD,IAAA,MAAM,WAAc,GAAA,QAAA,CAAS,OAAQ,CAAA,GAAA,CAAI,cAAc,CAAA;AAEvD,IAAI,IAAA,CAAC,aAAoB,OAAA,IAAA;AAGzB,IAAA,IAAI,WAAY,CAAA,UAAA,CAAW,QAAQ,CAAA,EAAU,OAAA,OAAA;AAC7C,IAAA,IAAI,WAAY,CAAA,UAAA,CAAW,QAAQ,CAAA,EAAU,OAAA,OAAA;AAC7C,IAAA,IAAI,WAAY,CAAA,UAAA,CAAW,QAAQ,CAAA,EAAU,OAAA,OAAA;AAG7C,IAAO,OAAA,IAAA;AAAA,WACA,KAAO,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,iBAAiB,KAAK,CAAA;AACpC,IAAO,OAAA,IAAA;AAAA;AAEX;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/cache.ts","../src/get-audio-duration.ts","../src/limit.ts","../src/get-image-dimensions.ts","../src/get-video-metadata.ts","../src/get-thumbnail.ts","../src/dimension-handler.ts","../src/file-helper.ts","../src/url-helper.ts"],"sourcesContent":["import { Dimensions, VideoMeta } from \"./types\";\r\n\r\nexport const imageDimensionsCache: Record<string, Dimensions> = {};\r\nexport const videoMetaCache: Record<string, VideoMeta> = {};\r\nexport const audioDurationCache: Record<string, number> = {};","import { audioDurationCache } from \"./cache\";\r\n\r\n/**\r\n * Retrieves the duration (in seconds) of an audio file from a given source URL.\r\n * Uses a cache to avoid reloading the same audio multiple times.\r\n *\r\n * @param audioSrc - The source URL of the audio file.\r\n * @returns A Promise that resolves to the duration of the audio in seconds.\r\n */\r\nexport const getAudioDuration = (audioSrc: string): Promise<number> => {\r\n // Return cached duration if available\r\n if (audioDurationCache[audioSrc]) {\r\n return Promise.resolve(audioDurationCache[audioSrc]);\r\n }\r\n\r\n return new Promise((resolve, reject) => {\r\n const audio = document.createElement(\"audio\");\r\n audio.preload = \"metadata\"; // Only load metadata (e.g., duration)\r\n // Sanitize the audioSrc to prevent XSS by only allowing safe URLs (http, https, blob, data)\r\n const isSafeUrl = /^(https?:|blob:|data:audio\\/)/i.test(audioSrc);\r\n if (!isSafeUrl) {\r\n throw new Error(\"Unsafe audio source URL\");\r\n }\r\n audio.src = audioSrc;\r\n\r\n // When metadata is loaded, store duration in cache and resolve\r\n audio.onloadedmetadata = () => {\r\n const duration = audio.duration;\r\n audioDurationCache[audioSrc] = duration;\r\n resolve(duration);\r\n };\r\n\r\n // Handle loading errors\r\n audio.onerror = () => {\r\n reject(new Error(\"Failed to load audio metadata\"));\r\n };\r\n });\r\n};\r\n","// Maximum number of concurrent promises allowed to run\r\nconst concurrencyLimit = 5;\r\n\r\n// Number of currently active (running) promises\r\nlet activeCount = 0;\r\n\r\n// Queue to hold pending tasks waiting to be run when concurrency slots free up\r\nconst queue: Array<() => void> = [];\r\n\r\n/**\r\n * Runs the next task from the queue if concurrency limit is not reached.\r\n */\r\nfunction runNext() {\r\n // If no tasks are queued or we're already at the concurrency limit, do nothing\r\n if (queue.length === 0 || activeCount >= concurrencyLimit) return;\r\n\r\n // Dequeue next task\r\n const next = queue.shift();\r\n\r\n if (next) {\r\n activeCount++; // Mark one more active task\r\n next(); // Run it\r\n }\r\n}\r\n\r\n/**\r\n * Wraps an async function to enforce concurrency limits.\r\n * If concurrency limit is reached, the function is queued and executed later.\r\n * \r\n * @param fn - Async function returning a Promise\r\n * @returns Promise that resolves/rejects with fn's result\r\n */\r\nexport function limit<T>(fn: () => Promise<T>): Promise<T> {\r\n return new Promise((resolve, reject) => {\r\n // Task to run the function and handle completion\r\n const task = () => {\r\n fn()\r\n .then(resolve)\r\n .catch(reject)\r\n .finally(() => {\r\n activeCount--; // Mark task as done\r\n runNext(); // Trigger next queued task, if any\r\n });\r\n };\r\n\r\n if (activeCount < concurrencyLimit) {\r\n activeCount++; // Increment active count for immediate run\r\n task();\r\n } else {\r\n // Queue the task if concurrency limit reached\r\n queue.push(task);\r\n }\r\n });\r\n}\r\n","import { limit } from \"./limit\";\r\nimport { Dimensions } from \"./types\";\r\nimport { imageDimensionsCache } from \"./cache\";\r\n\r\n/**\r\n * Loads an image from the given URL and resolves with its natural dimensions.\r\n *\r\n * @param url - The image URL to load.\r\n * @returns A Promise that resolves with the image's width and height.\r\n */\r\nconst loadImageDimensions = (url: string): Promise<Dimensions> => {\r\n return new Promise((resolve, reject) => {\r\n if (typeof document === 'undefined') {\r\n reject(new Error('getImageDimensions() is only available in the browser.'));\r\n return;\r\n }\r\n\r\n const img = new Image();\r\n img.onload = () => {\r\n resolve({ width: img.naturalWidth, height: img.naturalHeight });\r\n };\r\n img.onerror = reject;\r\n img.src = url;\r\n });\r\n};\r\n\r\n/**\r\n * Gets the dimensions (width and height) of an image from the given URL.\r\n * Uses a cache to avoid reloading the image if already fetched.\r\n * Also uses a concurrency limiter to control resource usage.\r\n *\r\n * @param url - The URL of the image.\r\n * @returns A Promise that resolves to an object containing `width` and `height`.\r\n */\r\nexport const getImageDimensions = (url: string): Promise<Dimensions> => {\r\n // Return cached dimensions if available\r\n if (imageDimensionsCache[url]) {\r\n return Promise.resolve(imageDimensionsCache[url]);\r\n }\r\n\r\n // Fetch and cache the dimensions using a concurrency limit\r\n return limit(() => loadImageDimensions(url)).then((dimensions) => {\r\n imageDimensionsCache[url] = dimensions;\r\n return dimensions;\r\n });\r\n};\r\n","import { videoMetaCache } from \"./cache\";\r\nimport { VideoMeta } from \"./types\";\r\n\r\n/**\r\n * Fetches metadata (width, height, duration) for a given video source.\r\n * If metadata has already been fetched and cached, it returns the cached data.\r\n *\r\n * @param videoSrc - The URL or path to the video file.\r\n * @returns A Promise that resolves to an object containing video metadata.\r\n */\r\nexport const getVideoMeta = (videoSrc: string): Promise<VideoMeta> => {\r\n // Return cached metadata if available\r\n if (videoMetaCache[videoSrc]) {\r\n return Promise.resolve(videoMetaCache[videoSrc]);\r\n }\r\n\r\n return new Promise<VideoMeta>((resolve, reject) => {\r\n const video: HTMLVideoElement = document.createElement(\"video\");\r\n video.preload = \"metadata\"; // Only preload metadata to reduce bandwidth\r\n // Validate the videoSrc to ensure it's a safe URL before assigning it to video.src\r\n const isSafeUrl = /^(https?:|blob:|data:video\\/)/i.test(videoSrc);\r\n if (!isSafeUrl) {\r\n reject(new Error(\"Unsafe video source URL\"));\r\n return;\r\n }\r\n video.src = videoSrc;\r\n\r\n // When metadata is loaded, extract and cache it\r\n video.onloadedmetadata = () => {\r\n const meta: VideoMeta = {\r\n width: video.videoWidth,\r\n height: video.videoHeight,\r\n duration: video.duration,\r\n };\r\n videoMetaCache[videoSrc] = meta;\r\n resolve(meta);\r\n };\r\n\r\n // Handle video loading errors\r\n video.onerror = () => reject(new Error(\"Failed to load video metadata\"));\r\n });\r\n};\r\n","/**\r\n * Extracts a thumbnail from a video at a specific seek time and playback rate.\r\n *\r\n * This function creates a hidden `<video>` element in the browser,\r\n * seeks to the specified time, and captures the frame into a canvas,\r\n * which is then exported as a JPEG data URL or Blob URL.\r\n *\r\n * @param videoUrl - The URL of the video to extract the thumbnail from.\r\n * @param seekTime - The time in seconds at which to capture the frame. Default is 0.1s.\r\n * @param playbackRate - Playback speed for the video. Default is 1.\r\n * @returns A Promise that resolves to a thumbnail image URL (either a base64 data URL or blob URL).\r\n */\r\nexport const getThumbnail = async (\r\n videoUrl: string,\r\n seekTime = 0.1,\r\n playbackRate = 1\r\n ): Promise<string> => {\r\n return new Promise((resolve, reject) => {\r\n const video = document.createElement(\"video\");\r\n video.crossOrigin = \"anonymous\";\r\n video.muted = true;\r\n video.playsInline = true;\r\n video.autoplay = false;\r\n video.preload = \"auto\";\r\n video.playbackRate = playbackRate;\r\n \r\n // Make video element hidden\r\n video.style.position = \"absolute\";\r\n video.style.left = \"-9999px\";\r\n video.style.top = \"-9999px\";\r\n video.style.width = \"1px\";\r\n video.style.height = \"1px\";\r\n video.style.opacity = \"0\";\r\n video.style.pointerEvents = \"none\";\r\n video.style.zIndex = \"-1\";\r\n \r\n let timeoutId: number | undefined;\r\n \r\n // Cleanup video element and timeout\r\n const cleanup = () => {\r\n if (video.parentNode) video.remove();\r\n if (timeoutId) clearTimeout(timeoutId);\r\n };\r\n \r\n // Handle errors during video loading\r\n const handleError = () => {\r\n cleanup();\r\n reject(new Error(`Failed to load video: ${video.error?.message || \"Unknown error\"}`));\r\n };\r\n \r\n // Once seeked to target frame, capture the image\r\n const handleSeeked = () => {\r\n try {\r\n video.pause();\r\n \r\n const canvas = document.createElement(\"canvas\");\r\n const width = video.videoWidth || 640;\r\n const height = video.videoHeight || 360;\r\n canvas.width = width;\r\n canvas.height = height;\r\n \r\n const ctx = canvas.getContext(\"2d\");\r\n if (!ctx) {\r\n cleanup();\r\n reject(new Error(\"Failed to get canvas context\"));\r\n return;\r\n }\r\n \r\n // Draw current video frame onto canvas\r\n ctx.drawImage(video, 0, 0, width, height);\r\n \r\n // Attempt to export canvas to base64 image URL\r\n try {\r\n const dataUrl = canvas.toDataURL(\"image/jpeg\", 0.8);\r\n cleanup();\r\n resolve(dataUrl);\r\n } catch {\r\n // Fallback: convert canvas to Blob\r\n canvas.toBlob((blob) => {\r\n if (!blob) {\r\n cleanup();\r\n reject(new Error(\"Failed to create Blob\"));\r\n return;\r\n }\r\n const blobUrl = URL.createObjectURL(blob);\r\n cleanup();\r\n resolve(blobUrl);\r\n }, \"image/jpeg\", 0.8);\r\n }\r\n } catch (err) {\r\n cleanup();\r\n reject(new Error(`Error creating thumbnail: ${err}`));\r\n }\r\n };\r\n \r\n video.addEventListener(\"error\", handleError, { once: true });\r\n video.addEventListener(\"seeked\", handleSeeked, { once: true });\r\n \r\n // After metadata is loaded, seek to the desired frame\r\n video.addEventListener(\"loadedmetadata\", () => {\r\n const playPromise = video.play();\r\n if (playPromise !== undefined) {\r\n playPromise\r\n .then(() => {\r\n video.currentTime = seekTime;\r\n })\r\n .catch(() => {\r\n video.currentTime = seekTime;\r\n });\r\n } else {\r\n video.currentTime = seekTime;\r\n }\r\n }, { once: true });\r\n \r\n // Timeout protection in case video loading hangs\r\n timeoutId = window.setTimeout(() => {\r\n cleanup();\r\n reject(new Error(\"Video loading timed out\"));\r\n }, 5000);\r\n \r\n // Assign video source and add it to the DOM (helps Safari/iOS behavior)\r\n video.src = videoUrl;\r\n document.body.appendChild(video);\r\n });\r\n };","import { Dimensions } from \"./types\";\r\n\r\n/**\r\n * Calculates the scaled dimensions of an element to fit inside a container\r\n * based on the specified max dimensions.\r\n *\r\n * @param width - The original width of the element.\r\n * @param height - The original height of the element.\r\n * @param maxWidth - The maximum width of the container.\r\n * @param maxHeight - The maximum height of the container.\r\n * @returns An object containing the calculated width and height for the element.\r\n */\r\nexport const getScaledDimensions = (\r\n width: number, \r\n height: number,\r\n maxWidth: number,\r\n maxHeight: number\r\n ): Dimensions => {\r\n // If the original dimensions are smaller than or equal to the max values, return the original dimensions\r\n if (width <= maxWidth && height <= maxHeight) {\r\n // Ensure the width and height are even numbers\r\n return {\r\n width: width % 2 === 0 ? width : width - 1,\r\n height: height % 2 === 0 ? height : height - 1,\r\n };\r\n }\r\n \r\n // Calculate scaling factor based on the maximum width and height\r\n const widthRatio = maxWidth / width;\r\n const heightRatio = maxHeight / height;\r\n \r\n // Use the smaller of the two ratios to maintain the aspect ratio\r\n const scale = Math.min(widthRatio, heightRatio);\r\n \r\n // Calculate the scaled dimensions\r\n let scaledWidth = Math.round(width * scale);\r\n let scaledHeight = Math.round(height * scale);\r\n \r\n // Ensure the width and height are even numbers\r\n if (scaledWidth % 2 !== 0) {\r\n scaledWidth -= 1; // Make width even if it's odd\r\n }\r\n if (scaledHeight % 2 !== 0) {\r\n scaledHeight -= 1; // Make height even if it's odd\r\n }\r\n \r\n // Ensure the scaled width and height fit within the max dimensions\r\n return {\r\n width: Math.min(scaledWidth, maxWidth),\r\n height: Math.min(scaledHeight, maxHeight),\r\n };\r\n };\r\n\r\n/**\r\n * Calculates the resized dimensions of an element to fit inside a container\r\n * based on the specified object-fit strategy (\"contain\", \"cover\", \"fill\", or default).\r\n *\r\n * @param objectFit - The object-fit behavior ('contain', 'cover', 'fill', or default/fallback).\r\n * @param elementSize - The original size of the element (width and height).\r\n * @param containerSize - The size of the container (width and height).\r\n * @returns An object containing the calculated width and height for the element.\r\n */\r\nexport const getObjectFitSize = (\r\n objectFit: string,\r\n elementSize: Dimensions,\r\n containerSize: Dimensions\r\n): Dimensions => {\r\n const elementAspectRatio = elementSize.width / elementSize.height;\r\n const containerAspectRatio = containerSize.width / containerSize.height;\r\n\r\n switch (objectFit) {\r\n case \"contain\":\r\n // Fit entire element inside container without cropping, maintaining aspect ratio\r\n if (elementAspectRatio > containerAspectRatio) {\r\n return {\r\n width: containerSize.width,\r\n height: containerSize.width / elementAspectRatio,\r\n };\r\n } else {\r\n return {\r\n width: containerSize.height * elementAspectRatio,\r\n height: containerSize.height,\r\n };\r\n }\r\n\r\n case \"cover\":\r\n // Fill container while maintaining aspect ratio, possibly cropping the element\r\n if (elementAspectRatio > containerAspectRatio) {\r\n return {\r\n width: containerSize.height * elementAspectRatio,\r\n height: containerSize.height,\r\n };\r\n } else {\r\n return {\r\n width: containerSize.width,\r\n height: containerSize.width / elementAspectRatio,\r\n };\r\n }\r\n\r\n case \"fill\":\r\n // Stretch element to completely fill the container, ignoring aspect ratio\r\n return {\r\n width: containerSize.width,\r\n height: containerSize.height,\r\n };\r\n\r\n default:\r\n // Default behavior: return original size of the element\r\n return {\r\n width: elementSize.width,\r\n height: elementSize.height,\r\n };\r\n }\r\n};\r\n\r\n ","/**\r\n * Converts a Blob URL to a File object.\r\n *\r\n * @param blobUrl - The Blob URL to convert.\r\n * @param fileName - The name to assign to the resulting File.\r\n * @returns A Promise that resolves to a File object.\r\n */\r\nexport const blobUrlToFile = async (blobUrl: string, fileName: string): Promise<File> => {\r\n const response = await fetch(blobUrl);\r\n const blob = await response.blob();\r\n return new File([blob], fileName, { type: blob.type });\r\n };\r\n \r\n /**\r\n * Triggers a download of a file from a string or Blob.\r\n *\r\n * @param content - The content to save, either a string or a Blob.\r\n * @param type - The MIME type of the content.\r\n * @param name - The name of the file to be saved.\r\n */\r\n export const saveAsFile = (content: string | Blob, type: string, name: string): void => {\r\n const blob = typeof content === \"string\" ? new Blob([content], { type }) : content;\r\n const url = URL.createObjectURL(blob);\r\n \r\n const a = document.createElement(\"a\");\r\n a.href = url;\r\n a.download = name;\r\n a.click();\r\n \r\n // Clean up the URL object after download\r\n URL.revokeObjectURL(url);\r\n };\r\n \r\n /**\r\n * Downloads a file from a given URL and triggers a browser download.\r\n *\r\n * @param url - The URL of the file to download.\r\n * @param filename - The name of the file to be saved.\r\n * @returns A Promise that resolves when the download is initiated or rejects if there is an error.\r\n */\r\n export const downloadFile = async (url: string, filename: string): Promise<void> => {\r\n try {\r\n const response = await fetch(url);\r\n const blob = await response.blob();\r\n const downloadUrl = window.URL.createObjectURL(blob);\r\n \r\n const link = document.createElement(\"a\");\r\n link.href = downloadUrl;\r\n link.download = filename;\r\n document.body.appendChild(link);\r\n link.click();\r\n \r\n // Clean up\r\n document.body.removeChild(link);\r\n window.URL.revokeObjectURL(downloadUrl);\r\n } catch (error) {\r\n console.error(\"Error downloading file:\", error);\r\n throw error;\r\n }\r\n };\r\n ","/**\r\n * Detects the media type (image, video, or audio) of a given URL by sending a HEAD request.\r\n *\r\n * @param url - The URL of the media file.\r\n * @returns A promise that resolves to 'image', 'video', or 'audio' based on the Content-Type header,\r\n * or `null` if the type couldn't be determined or the request fails.\r\n */\r\nexport const detectMediaTypeFromUrl = async (url: string): Promise<'image' | 'video' | 'audio' | null> => {\r\n try {\r\n // Use a HEAD request to fetch only the headers, avoiding download of the full file\r\n const response = await fetch(url, { method: 'HEAD' });\r\n \r\n // Extract the 'Content-Type' header from the response\r\n const contentType = response.headers.get('Content-Type');\r\n \r\n if (!contentType) return null;\r\n \r\n // Determine the media type from the content type\r\n if (contentType.startsWith('image/')) return 'image';\r\n if (contentType.startsWith('video/')) return 'video';\r\n if (contentType.startsWith('audio/')) return 'audio';\r\n \r\n // Return null if not a recognized media type\r\n return null;\r\n } catch (error) {\r\n console.error('Fetch failed:', error);\r\n return null;\r\n }\r\n };\r\n "],"names":[],"mappings":";;;;AAEO,MAAM,uBAAmD,EAAC;AAC1D,MAAM,iBAA4C,EAAC;AACnD,MAAM,qBAA6C,EAAC;;ACK9C,MAAA,gBAAA,GAAmB,CAAC,QAAsC,KAAA;AAErE,EAAI,IAAA,kBAAA,CAAmB,QAAQ,CAAG,EAAA;AAChC,IAAA,OAAO,OAAQ,CAAA,OAAA,CAAQ,kBAAmB,CAAA,QAAQ,CAAC,CAAA;AAAA;AAGrD,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAW,KAAA;AACtC,IAAM,MAAA,KAAA,GAAQ,QAAS,CAAA,aAAA,CAAc,OAAO,CAAA;AAC5C,IAAA,KAAA,CAAM,OAAU,GAAA,UAAA;AAEhB,IAAM,MAAA,SAAA,GAAY,gCAAiC,CAAA,IAAA,CAAK,QAAQ,CAAA;AAChE,IAAA,IAAI,CAAC,SAAW,EAAA;AACd,MAAM,MAAA,IAAI,MAAM,yBAAyB,CAAA;AAAA;AAE3C,IAAA,KAAA,CAAM,GAAM,GAAA,QAAA;AAGZ,IAAA,KAAA,CAAM,mBAAmB,MAAM;AAC7B,MAAA,MAAM,WAAW,KAAM,CAAA,QAAA;AACvB,MAAA,kBAAA,CAAmB,QAAQ,CAAI,GAAA,QAAA;AAC/B,MAAA,OAAA,CAAQ,QAAQ,CAAA;AA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AC/B,KAAO,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,2BAA2B,KAAK,CAAA;AAC9C,IAAM,MAAA,KAAA;AAAA;AAEV;;ACpDW,MAAA,sBAAA,GAAyB,OAAO,GAA6D,KAAA;AACtG,EAAI,IAAA;AAEF,IAAA,MAAM,WAAW,MAAM,KAAA,CAAM,KAAK,EAAE,MAAA,EAAQ,QAAQ,CAAA;AAGpD,IAAA,MAAM,WAAc,GAAA,QAAA,CAAS,OAAQ,CAAA,GAAA,CAAI,cAAc,CAAA;AAEvD,IAAI,IAAA,CAAC,aAAoB,OAAA,IAAA;AAGzB,IAAA,IAAI,WAAY,CAAA,UAAA,CAAW,QAAQ,CAAA,EAAU,OAAA,OAAA;AAC7C,IAAA,IAAI,WAAY,CAAA,UAAA,CAAW,QAAQ,CAAA,EAAU,OAAA,OAAA;AAC7C,IAAA,IAAI,WAAY,CAAA,UAAA,CAAW,QAAQ,CAAA,EAAU,OAAA,OAAA;AAG7C,IAAO,OAAA,IAAA;AAAA,WACA,KAAO,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,iBAAiB,KAAK,CAAA;AACpC,IAAO,OAAA,IAAA;AAAA;AAEX;;;;;;;;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -9,6 +9,10 @@ const getAudioDuration = (audioSrc) => {
9
9
  return new Promise((resolve, reject) => {
10
10
  const audio = document.createElement("audio");
11
11
  audio.preload = "metadata";
12
+ const isSafeUrl = /^(https?:|blob:|data:audio\/)/i.test(audioSrc);
13
+ if (!isSafeUrl) {
14
+ throw new Error("Unsafe audio source URL");
15
+ }
12
16
  audio.src = audioSrc;
13
17
  audio.onloadedmetadata = () => {
14
18
  const duration = audio.duration;
@@ -49,7 +53,7 @@ function limit(fn) {
49
53
  });
50
54
  }
51
55
 
52
- function loadImageDimensions(url) {
56
+ const loadImageDimensions = (url) => {
53
57
  return new Promise((resolve, reject) => {
54
58
  if (typeof document === "undefined") {
55
59
  reject(new Error("getImageDimensions() is only available in the browser."));
@@ -62,8 +66,8 @@ function loadImageDimensions(url) {
62
66
  img.onerror = reject;
63
67
  img.src = url;
64
68
  });
65
- }
66
- function getImageDimensions(url) {
69
+ };
70
+ const getImageDimensions = (url) => {
67
71
  if (imageDimensionsCache[url]) {
68
72
  return Promise.resolve(imageDimensionsCache[url]);
69
73
  }
@@ -71,7 +75,7 @@ function getImageDimensions(url) {
71
75
  imageDimensionsCache[url] = dimensions;
72
76
  return dimensions;
73
77
  });
74
- }
78
+ };
75
79
 
76
80
  const getVideoMeta = (videoSrc) => {
77
81
  if (videoMetaCache[videoSrc]) {
@@ -80,6 +84,11 @@ const getVideoMeta = (videoSrc) => {
80
84
  return new Promise((resolve, reject) => {
81
85
  const video = document.createElement("video");
82
86
  video.preload = "metadata";
87
+ const isSafeUrl = /^(https?:|blob:|data:video\/)/i.test(videoSrc);
88
+ if (!isSafeUrl) {
89
+ reject(new Error("Unsafe video source URL"));
90
+ return;
91
+ }
83
92
  video.src = videoSrc;
84
93
  video.onloadedmetadata = () => {
85
94
  const meta = {
@@ -94,7 +103,7 @@ const getVideoMeta = (videoSrc) => {
94
103
  });
95
104
  };
96
105
 
97
- async function getThumbnail(videoUrl, seekTime = 0.1, playbackRate = 1) {
106
+ const getThumbnail = async (videoUrl, seekTime = 0.1, playbackRate = 1) => {
98
107
  return new Promise((resolve, reject) => {
99
108
  const video = document.createElement("video");
100
109
  video.crossOrigin = "anonymous";
@@ -103,6 +112,14 @@ async function getThumbnail(videoUrl, seekTime = 0.1, playbackRate = 1) {
103
112
  video.autoplay = false;
104
113
  video.preload = "auto";
105
114
  video.playbackRate = playbackRate;
115
+ video.style.position = "absolute";
116
+ video.style.left = "-9999px";
117
+ video.style.top = "-9999px";
118
+ video.style.width = "1px";
119
+ video.style.height = "1px";
120
+ video.style.opacity = "0";
121
+ video.style.pointerEvents = "none";
122
+ video.style.zIndex = "-1";
106
123
  let timeoutId;
107
124
  const cleanup = () => {
108
125
  if (video.parentNode) video.remove();
@@ -169,9 +186,9 @@ async function getThumbnail(videoUrl, seekTime = 0.1, playbackRate = 1) {
169
186
  video.src = videoUrl;
170
187
  document.body.appendChild(video);
171
188
  });
172
- }
189
+ };
173
190
 
174
- function getScaledDimensions(width, height, maxWidth, maxHeight) {
191
+ const getScaledDimensions = (width, height, maxWidth, maxHeight) => {
175
192
  if (width <= maxWidth && height <= maxHeight) {
176
193
  return {
177
194
  width: width % 2 === 0 ? width : width - 1,
@@ -193,8 +210,8 @@ function getScaledDimensions(width, height, maxWidth, maxHeight) {
193
210
  width: Math.min(scaledWidth, maxWidth),
194
211
  height: Math.min(scaledHeight, maxHeight)
195
212
  };
196
- }
197
- function getObjectFitSize(objectFit, elementSize, containerSize) {
213
+ };
214
+ const getObjectFitSize = (objectFit, elementSize, containerSize) => {
198
215
  const elementAspectRatio = elementSize.width / elementSize.height;
199
216
  const containerAspectRatio = containerSize.width / containerSize.height;
200
217
  switch (objectFit) {
@@ -233,14 +250,14 @@ function getObjectFitSize(objectFit, elementSize, containerSize) {
233
250
  height: elementSize.height
234
251
  };
235
252
  }
236
- }
253
+ };
237
254
 
238
- async function blobUrlToFile(blobUrl, fileName) {
255
+ const blobUrlToFile = async (blobUrl, fileName) => {
239
256
  const response = await fetch(blobUrl);
240
257
  const blob = await response.blob();
241
258
  return new File([blob], fileName, { type: blob.type });
242
- }
243
- function saveAsFile(content, type, name) {
259
+ };
260
+ const saveAsFile = (content, type, name) => {
244
261
  const blob = typeof content === "string" ? new Blob([content], { type }) : content;
245
262
  const url = URL.createObjectURL(blob);
246
263
  const a = document.createElement("a");
@@ -248,8 +265,8 @@ function saveAsFile(content, type, name) {
248
265
  a.download = name;
249
266
  a.click();
250
267
  URL.revokeObjectURL(url);
251
- }
252
- async function downloadFile(url, filename) {
268
+ };
269
+ const downloadFile = async (url, filename) => {
253
270
  try {
254
271
  const response = await fetch(url);
255
272
  const blob = await response.blob();
@@ -265,9 +282,9 @@ async function downloadFile(url, filename) {
265
282
  console.error("Error downloading file:", error);
266
283
  throw error;
267
284
  }
268
- }
285
+ };
269
286
 
270
- async function detectMediaTypeFromUrl(url) {
287
+ const detectMediaTypeFromUrl = async (url) => {
271
288
  try {
272
289
  const response = await fetch(url, { method: "HEAD" });
273
290
  const contentType = response.headers.get("Content-Type");
@@ -280,7 +297,7 @@ async function detectMediaTypeFromUrl(url) {
280
297
  console.error("Fetch failed:", error);
281
298
  return null;
282
299
  }
283
- }
300
+ };
284
301
 
285
302
  export { blobUrlToFile, detectMediaTypeFromUrl, downloadFile, getAudioDuration, getImageDimensions, getObjectFitSize, getScaledDimensions, getThumbnail, getVideoMeta, limit, saveAsFile };
286
303
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/cache.ts","../src/get-audio-duration.ts","../src/limit.ts","../src/get-image-dimensions.ts","../src/get-video-metadata.ts","../src/get-thumbnail.ts","../src/dimension-handler.ts","../src/file-helper.ts","../src/url-helper.ts"],"sourcesContent":["import { Dimensions, VideoMeta } from \"./types\";\r\n\r\nexport const imageDimensionsCache: Record<string, Dimensions> = {};\r\nexport const videoMetaCache: Record<string, VideoMeta> = {};\r\nexport const audioDurationCache: Record<string, number> = {};","import { audioDurationCache } from \"./cache\";\r\n\r\n/**\r\n * Retrieves the duration (in seconds) of an audio file from a given source URL.\r\n * Uses a cache to avoid reloading the same audio multiple times.\r\n *\r\n * @param audioSrc - The source URL of the audio file.\r\n * @returns A Promise that resolves to the duration of the audio in seconds.\r\n */\r\nexport const getAudioDuration = (audioSrc: string): Promise<number> => {\r\n // Return cached duration if available\r\n if (audioDurationCache[audioSrc]) {\r\n return Promise.resolve(audioDurationCache[audioSrc]);\r\n }\r\n\r\n return new Promise((resolve, reject) => {\r\n const audio = document.createElement(\"audio\");\r\n audio.preload = \"metadata\"; // Only load metadata (e.g., duration)\r\n audio.src = audioSrc;\r\n\r\n // When metadata is loaded, store duration in cache and resolve\r\n audio.onloadedmetadata = () => {\r\n const duration = audio.duration;\r\n audioDurationCache[audioSrc] = duration;\r\n resolve(duration);\r\n };\r\n\r\n // Handle loading errors\r\n audio.onerror = () => {\r\n reject(new Error(\"Failed to load audio metadata\"));\r\n };\r\n });\r\n};\r\n","// Maximum number of concurrent promises allowed to run\r\nconst concurrencyLimit = 5;\r\n\r\n// Number of currently active (running) promises\r\nlet activeCount = 0;\r\n\r\n// Queue to hold pending tasks waiting to be run when concurrency slots free up\r\nconst queue: Array<() => void> = [];\r\n\r\n/**\r\n * Runs the next task from the queue if concurrency limit is not reached.\r\n */\r\nfunction runNext() {\r\n // If no tasks are queued or we're already at the concurrency limit, do nothing\r\n if (queue.length === 0 || activeCount >= concurrencyLimit) return;\r\n\r\n // Dequeue next task\r\n const next = queue.shift();\r\n\r\n if (next) {\r\n activeCount++; // Mark one more active task\r\n next(); // Run it\r\n }\r\n}\r\n\r\n/**\r\n * Wraps an async function to enforce concurrency limits.\r\n * If concurrency limit is reached, the function is queued and executed later.\r\n * \r\n * @param fn - Async function returning a Promise\r\n * @returns Promise that resolves/rejects with fn's result\r\n */\r\nexport function limit<T>(fn: () => Promise<T>): Promise<T> {\r\n return new Promise((resolve, reject) => {\r\n // Task to run the function and handle completion\r\n const task = () => {\r\n fn()\r\n .then(resolve)\r\n .catch(reject)\r\n .finally(() => {\r\n activeCount--; // Mark task as done\r\n runNext(); // Trigger next queued task, if any\r\n });\r\n };\r\n\r\n if (activeCount < concurrencyLimit) {\r\n activeCount++; // Increment active count for immediate run\r\n task();\r\n } else {\r\n // Queue the task if concurrency limit reached\r\n queue.push(task);\r\n }\r\n });\r\n}\r\n","import { limit } from \"./limit\";\r\nimport { Dimensions } from \"./types\";\r\nimport { imageDimensionsCache } from \"./cache\";\r\n\r\n/**\r\n * Loads an image from the given URL and resolves with its natural dimensions.\r\n *\r\n * @param url - The image URL to load.\r\n * @returns A Promise that resolves with the image's width and height.\r\n */\r\nfunction loadImageDimensions(url: string): Promise<Dimensions> {\r\n return new Promise((resolve, reject) => {\r\n if (typeof document === 'undefined') {\r\n reject(new Error('getImageDimensions() is only available in the browser.'));\r\n return;\r\n }\r\n\r\n const img = new Image();\r\n img.onload = () => {\r\n resolve({ width: img.naturalWidth, height: img.naturalHeight });\r\n };\r\n img.onerror = reject;\r\n img.src = url;\r\n });\r\n}\r\n\r\n/**\r\n * Gets the dimensions (width and height) of an image from the given URL.\r\n * Uses a cache to avoid reloading the image if already fetched.\r\n * Also uses a concurrency limiter to control resource usage.\r\n *\r\n * @param url - The URL of the image.\r\n * @returns A Promise that resolves to an object containing `width` and `height`.\r\n */\r\nexport function getImageDimensions(url: string): Promise<Dimensions> {\r\n // Return cached dimensions if available\r\n if (imageDimensionsCache[url]) {\r\n return Promise.resolve(imageDimensionsCache[url]);\r\n }\r\n\r\n // Fetch and cache the dimensions using a concurrency limit\r\n return limit(() => loadImageDimensions(url)).then((dimensions) => {\r\n imageDimensionsCache[url] = dimensions;\r\n return dimensions;\r\n });\r\n}\r\n","import { videoMetaCache } from \"./cache\";\r\nimport { VideoMeta } from \"./types\";\r\n\r\n/**\r\n * Fetches metadata (width, height, duration) for a given video source.\r\n * If metadata has already been fetched and cached, it returns the cached data.\r\n *\r\n * @param videoSrc - The URL or path to the video file.\r\n * @returns A Promise that resolves to an object containing video metadata.\r\n */\r\nexport const getVideoMeta = (videoSrc: string): Promise<VideoMeta> => {\r\n // Return cached metadata if available\r\n if (videoMetaCache[videoSrc]) {\r\n return Promise.resolve(videoMetaCache[videoSrc]);\r\n }\r\n\r\n return new Promise<VideoMeta>((resolve, reject) => {\r\n const video: HTMLVideoElement = document.createElement(\"video\");\r\n video.preload = \"metadata\"; // Only preload metadata to reduce bandwidth\r\n video.src = videoSrc;\r\n\r\n // When metadata is loaded, extract and cache it\r\n video.onloadedmetadata = () => {\r\n const meta: VideoMeta = {\r\n width: video.videoWidth,\r\n height: video.videoHeight,\r\n duration: video.duration,\r\n };\r\n videoMetaCache[videoSrc] = meta;\r\n resolve(meta);\r\n };\r\n\r\n // Handle video loading errors\r\n video.onerror = () => reject(new Error(\"Failed to load video metadata\"));\r\n });\r\n};\r\n","/**\r\n * Extracts a thumbnail from a video at a specific seek time and playback rate.\r\n *\r\n * This function creates a hidden `<video>` element in the browser,\r\n * seeks to the specified time, and captures the frame into a canvas,\r\n * which is then exported as a JPEG data URL or Blob URL.\r\n *\r\n * @param videoUrl - The URL of the video to extract the thumbnail from.\r\n * @param seekTime - The time in seconds at which to capture the frame. Default is 0.1s.\r\n * @param playbackRate - Playback speed for the video. Default is 1.\r\n * @returns A Promise that resolves to a thumbnail image URL (either a base64 data URL or blob URL).\r\n */\r\nexport async function getThumbnail(\r\n videoUrl: string,\r\n seekTime = 0.1,\r\n playbackRate = 1\r\n ): Promise<string> {\r\n return new Promise((resolve, reject) => {\r\n const video = document.createElement(\"video\");\r\n video.crossOrigin = \"anonymous\";\r\n video.muted = true;\r\n video.playsInline = true;\r\n video.autoplay = false;\r\n video.preload = \"auto\";\r\n video.playbackRate = playbackRate;\r\n \r\n let timeoutId: number | undefined;\r\n \r\n // Cleanup video element and timeout\r\n const cleanup = () => {\r\n if (video.parentNode) video.remove();\r\n if (timeoutId) clearTimeout(timeoutId);\r\n };\r\n \r\n // Handle errors during video loading\r\n const handleError = () => {\r\n cleanup();\r\n reject(new Error(`Failed to load video: ${video.error?.message || \"Unknown error\"}`));\r\n };\r\n \r\n // Once seeked to target frame, capture the image\r\n const handleSeeked = () => {\r\n try {\r\n video.pause();\r\n \r\n const canvas = document.createElement(\"canvas\");\r\n const width = video.videoWidth || 640;\r\n const height = video.videoHeight || 360;\r\n canvas.width = width;\r\n canvas.height = height;\r\n \r\n const ctx = canvas.getContext(\"2d\");\r\n if (!ctx) {\r\n cleanup();\r\n reject(new Error(\"Failed to get canvas context\"));\r\n return;\r\n }\r\n \r\n // Draw current video frame onto canvas\r\n ctx.drawImage(video, 0, 0, width, height);\r\n \r\n // Attempt to export canvas to base64 image URL\r\n try {\r\n const dataUrl = canvas.toDataURL(\"image/jpeg\", 0.8);\r\n cleanup();\r\n resolve(dataUrl);\r\n } catch {\r\n // Fallback: convert canvas to Blob\r\n canvas.toBlob((blob) => {\r\n if (!blob) {\r\n cleanup();\r\n reject(new Error(\"Failed to create Blob\"));\r\n return;\r\n }\r\n const blobUrl = URL.createObjectURL(blob);\r\n cleanup();\r\n resolve(blobUrl);\r\n }, \"image/jpeg\", 0.8);\r\n }\r\n } catch (err) {\r\n cleanup();\r\n reject(new Error(`Error creating thumbnail: ${err}`));\r\n }\r\n };\r\n \r\n video.addEventListener(\"error\", handleError, { once: true });\r\n video.addEventListener(\"seeked\", handleSeeked, { once: true });\r\n \r\n // After metadata is loaded, seek to the desired frame\r\n video.addEventListener(\"loadedmetadata\", () => {\r\n const playPromise = video.play();\r\n if (playPromise !== undefined) {\r\n playPromise\r\n .then(() => {\r\n video.currentTime = seekTime;\r\n })\r\n .catch(() => {\r\n video.currentTime = seekTime;\r\n });\r\n } else {\r\n video.currentTime = seekTime;\r\n }\r\n }, { once: true });\r\n \r\n // Timeout protection in case video loading hangs\r\n timeoutId = window.setTimeout(() => {\r\n cleanup();\r\n reject(new Error(\"Video loading timed out\"));\r\n }, 5000);\r\n \r\n // Assign video source and add it to the DOM (helps Safari/iOS behavior)\r\n video.src = videoUrl;\r\n document.body.appendChild(video);\r\n });\r\n }\r\n ","import { Dimensions } from \"./types\";\r\n\r\n/**\r\n * Calculates the scaled dimensions of an element to fit inside a container\r\n * based on the specified max dimensions.\r\n *\r\n * @param width - The original width of the element.\r\n * @param height - The original height of the element.\r\n * @param maxWidth - The maximum width of the container.\r\n * @param maxHeight - The maximum height of the container.\r\n * @returns An object containing the calculated width and height for the element.\r\n */\r\nexport function getScaledDimensions(\r\n width: number, \r\n height: number,\r\n maxWidth: number,\r\n maxHeight: number\r\n ): Dimensions {\r\n // If the original dimensions are smaller than or equal to the max values, return the original dimensions\r\n if (width <= maxWidth && height <= maxHeight) {\r\n // Ensure the width and height are even numbers\r\n return {\r\n width: width % 2 === 0 ? width : width - 1,\r\n height: height % 2 === 0 ? height : height - 1,\r\n };\r\n }\r\n \r\n // Calculate scaling factor based on the maximum width and height\r\n const widthRatio = maxWidth / width;\r\n const heightRatio = maxHeight / height;\r\n \r\n // Use the smaller of the two ratios to maintain the aspect ratio\r\n const scale = Math.min(widthRatio, heightRatio);\r\n \r\n // Calculate the scaled dimensions\r\n let scaledWidth = Math.round(width * scale);\r\n let scaledHeight = Math.round(height * scale);\r\n \r\n // Ensure the width and height are even numbers\r\n if (scaledWidth % 2 !== 0) {\r\n scaledWidth -= 1; // Make width even if it's odd\r\n }\r\n if (scaledHeight % 2 !== 0) {\r\n scaledHeight -= 1; // Make height even if it's odd\r\n }\r\n \r\n // Ensure the scaled width and height fit within the max dimensions\r\n return {\r\n width: Math.min(scaledWidth, maxWidth),\r\n height: Math.min(scaledHeight, maxHeight),\r\n };\r\n }\r\n\r\n/**\r\n * Calculates the resized dimensions of an element to fit inside a container\r\n * based on the specified object-fit strategy (\"contain\", \"cover\", \"fill\", or default).\r\n *\r\n * @param objectFit - The object-fit behavior ('contain', 'cover', 'fill', or default/fallback).\r\n * @param elementSize - The original size of the element (width and height).\r\n * @param containerSize - The size of the container (width and height).\r\n * @returns An object containing the calculated width and height for the element.\r\n */\r\nexport function getObjectFitSize(\r\n objectFit: string,\r\n elementSize: Dimensions,\r\n containerSize: Dimensions\r\n): Dimensions {\r\n const elementAspectRatio = elementSize.width / elementSize.height;\r\n const containerAspectRatio = containerSize.width / containerSize.height;\r\n\r\n switch (objectFit) {\r\n case \"contain\":\r\n // Fit entire element inside container without cropping, maintaining aspect ratio\r\n if (elementAspectRatio > containerAspectRatio) {\r\n return {\r\n width: containerSize.width,\r\n height: containerSize.width / elementAspectRatio,\r\n };\r\n } else {\r\n return {\r\n width: containerSize.height * elementAspectRatio,\r\n height: containerSize.height,\r\n };\r\n }\r\n\r\n case \"cover\":\r\n // Fill container while maintaining aspect ratio, possibly cropping the element\r\n if (elementAspectRatio > containerAspectRatio) {\r\n return {\r\n width: containerSize.height * elementAspectRatio,\r\n height: containerSize.height,\r\n };\r\n } else {\r\n return {\r\n width: containerSize.width,\r\n height: containerSize.width / elementAspectRatio,\r\n };\r\n }\r\n\r\n case \"fill\":\r\n // Stretch element to completely fill the container, ignoring aspect ratio\r\n return {\r\n width: containerSize.width,\r\n height: containerSize.height,\r\n };\r\n\r\n default:\r\n // Default behavior: return original size of the element\r\n return {\r\n width: elementSize.width,\r\n height: elementSize.height,\r\n };\r\n }\r\n};\r\n\r\n ","/**\r\n * Converts a Blob URL to a File object.\r\n *\r\n * @param blobUrl - The Blob URL to convert.\r\n * @param fileName - The name to assign to the resulting File.\r\n * @returns A Promise that resolves to a File object.\r\n */\r\nexport async function blobUrlToFile(blobUrl: string, fileName: string): Promise<File> {\r\n const response = await fetch(blobUrl);\r\n const blob = await response.blob();\r\n return new File([blob], fileName, { type: blob.type });\r\n }\r\n \r\n /**\r\n * Triggers a download of a file from a string or Blob.\r\n *\r\n * @param content - The content to save, either a string or a Blob.\r\n * @param type - The MIME type of the content.\r\n * @param name - The name of the file to be saved.\r\n */\r\n export function saveAsFile(content: string | Blob, type: string, name: string): void {\r\n const blob = typeof content === \"string\" ? new Blob([content], { type }) : content;\r\n const url = URL.createObjectURL(blob);\r\n \r\n const a = document.createElement(\"a\");\r\n a.href = url;\r\n a.download = name;\r\n a.click();\r\n \r\n // Clean up the URL object after download\r\n URL.revokeObjectURL(url);\r\n }\r\n \r\n /**\r\n * Downloads a file from a given URL and triggers a browser download.\r\n *\r\n * @param url - The URL of the file to download.\r\n * @param filename - The name of the file to be saved.\r\n * @returns A Promise that resolves when the download is initiated or rejects if there is an error.\r\n */\r\n export async function downloadFile(url: string, filename: string): Promise<void> {\r\n try {\r\n const response = await fetch(url);\r\n const blob = await response.blob();\r\n const downloadUrl = window.URL.createObjectURL(blob);\r\n \r\n const link = document.createElement(\"a\");\r\n link.href = downloadUrl;\r\n link.download = filename;\r\n document.body.appendChild(link);\r\n link.click();\r\n \r\n // Clean up\r\n document.body.removeChild(link);\r\n window.URL.revokeObjectURL(downloadUrl);\r\n } catch (error) {\r\n console.error(\"Error downloading file:\", error);\r\n throw error;\r\n }\r\n }\r\n ","/**\r\n * Detects the media type (image, video, or audio) of a given URL by sending a HEAD request.\r\n *\r\n * @param url - The URL of the media file.\r\n * @returns A promise that resolves to 'image', 'video', or 'audio' based on the Content-Type header,\r\n * or `null` if the type couldn't be determined or the request fails.\r\n */\r\nexport async function detectMediaTypeFromUrl(url: string): Promise<'image' | 'video' | 'audio' | null> {\r\n try {\r\n // Use a HEAD request to fetch only the headers, avoiding download of the full file\r\n const response = await fetch(url, { method: 'HEAD' });\r\n \r\n // Extract the 'Content-Type' header from the response\r\n const contentType = response.headers.get('Content-Type');\r\n \r\n if (!contentType) return null;\r\n \r\n // Determine the media type from the content type\r\n if (contentType.startsWith('image/')) return 'image';\r\n if (contentType.startsWith('video/')) return 'video';\r\n if (contentType.startsWith('audio/')) return 'audio';\r\n \r\n // Return null if not a recognized media type\r\n return null;\r\n } catch (error) {\r\n console.error('Fetch failed:', error);\r\n return null;\r\n }\r\n }\r\n "],"names":[],"mappings":"AAEO,MAAM,uBAAmD,EAAC;AAC1D,MAAM,iBAA4C,EAAC;AACnD,MAAM,qBAA6C,EAAC;;ACK9C,MAAA,gBAAA,GAAmB,CAAC,QAAsC,KAAA;AAErE,EAAI,IAAA,kBAAA,CAAmB,QAAQ,CAAG,EAAA;AAChC,IAAA,OAAO,OAAQ,CAAA,OAAA,CAAQ,kBAAmB,CAAA,QAAQ,CAAC,CAAA;AAAA;AAGrD,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAW,KAAA;AACtC,IAAM,MAAA,KAAA,GAAQ,QAAS,CAAA,aAAA,CAAc,OAAO,CAAA;AAC5C,IAAA,KAAA,CAAM,OAAU,GAAA,UAAA;AAChB,IAAA,KAAA,CAAM,GAAM,GAAA,QAAA;AAGZ,IAAA,KAAA,CAAM,mBAAmB,MAAM;A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AAU,OAAA,OAAA;AAC7C,IAAA,IAAI,WAAY,CAAA,UAAA,CAAW,QAAQ,CAAA,EAAU,OAAA,OAAA;AAG7C,IAAO,OAAA,IAAA;AAAA,WACA,KAAO,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,iBAAiB,KAAK,CAAA;AACpC,IAAO,OAAA,IAAA;AAAA;AAEX;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/cache.ts","../src/get-audio-duration.ts","../src/limit.ts","../src/get-image-dimensions.ts","../src/get-video-metadata.ts","../src/get-thumbnail.ts","../src/dimension-handler.ts","../src/file-helper.ts","../src/url-helper.ts"],"sourcesContent":["import { Dimensions, VideoMeta } from \"./types\";\r\n\r\nexport const imageDimensionsCache: Record<string, Dimensions> = {};\r\nexport const videoMetaCache: Record<string, VideoMeta> = {};\r\nexport const audioDurationCache: Record<string, number> = {};","import { audioDurationCache } from \"./cache\";\r\n\r\n/**\r\n * Retrieves the duration (in seconds) of an audio file from a given source URL.\r\n * Uses a cache to avoid reloading the same audio multiple times.\r\n *\r\n * @param audioSrc - The source URL of the audio file.\r\n * @returns A Promise that resolves to the duration of the audio in seconds.\r\n */\r\nexport const getAudioDuration = (audioSrc: string): Promise<number> => {\r\n // Return cached duration if available\r\n if (audioDurationCache[audioSrc]) {\r\n return Promise.resolve(audioDurationCache[audioSrc]);\r\n }\r\n\r\n return new Promise((resolve, reject) => {\r\n const audio = document.createElement(\"audio\");\r\n audio.preload = \"metadata\"; // Only load metadata (e.g., duration)\r\n // Sanitize the audioSrc to prevent XSS by only allowing safe URLs (http, https, blob, data)\r\n const isSafeUrl = /^(https?:|blob:|data:audio\\/)/i.test(audioSrc);\r\n if (!isSafeUrl) {\r\n throw new Error(\"Unsafe audio source URL\");\r\n }\r\n audio.src = audioSrc;\r\n\r\n // When metadata is loaded, store duration in cache and resolve\r\n audio.onloadedmetadata = () => {\r\n const duration = audio.duration;\r\n audioDurationCache[audioSrc] = duration;\r\n resolve(duration);\r\n };\r\n\r\n // Handle loading errors\r\n audio.onerror = () => {\r\n reject(new Error(\"Failed to load audio metadata\"));\r\n };\r\n });\r\n};\r\n","// Maximum number of concurrent promises allowed to run\r\nconst concurrencyLimit = 5;\r\n\r\n// Number of currently active (running) promises\r\nlet activeCount = 0;\r\n\r\n// Queue to hold pending tasks waiting to be run when concurrency slots free up\r\nconst queue: Array<() => void> = [];\r\n\r\n/**\r\n * Runs the next task from the queue if concurrency limit is not reached.\r\n */\r\nfunction runNext() {\r\n // If no tasks are queued or we're already at the concurrency limit, do nothing\r\n if (queue.length === 0 || activeCount >= concurrencyLimit) return;\r\n\r\n // Dequeue next task\r\n const next = queue.shift();\r\n\r\n if (next) {\r\n activeCount++; // Mark one more active task\r\n next(); // Run it\r\n }\r\n}\r\n\r\n/**\r\n * Wraps an async function to enforce concurrency limits.\r\n * If concurrency limit is reached, the function is queued and executed later.\r\n * \r\n * @param fn - Async function returning a Promise\r\n * @returns Promise that resolves/rejects with fn's result\r\n */\r\nexport function limit<T>(fn: () => Promise<T>): Promise<T> {\r\n return new Promise((resolve, reject) => {\r\n // Task to run the function and handle completion\r\n const task = () => {\r\n fn()\r\n .then(resolve)\r\n .catch(reject)\r\n .finally(() => {\r\n activeCount--; // Mark task as done\r\n runNext(); // Trigger next queued task, if any\r\n });\r\n };\r\n\r\n if (activeCount < concurrencyLimit) {\r\n activeCount++; // Increment active count for immediate run\r\n task();\r\n } else {\r\n // Queue the task if concurrency limit reached\r\n queue.push(task);\r\n }\r\n });\r\n}\r\n","import { limit } from \"./limit\";\r\nimport { Dimensions } from \"./types\";\r\nimport { imageDimensionsCache } from \"./cache\";\r\n\r\n/**\r\n * Loads an image from the given URL and resolves with its natural dimensions.\r\n *\r\n * @param url - The image URL to load.\r\n * @returns A Promise that resolves with the image's width and height.\r\n */\r\nconst loadImageDimensions = (url: string): Promise<Dimensions> => {\r\n return new Promise((resolve, reject) => {\r\n if (typeof document === 'undefined') {\r\n reject(new Error('getImageDimensions() is only available in the browser.'));\r\n return;\r\n }\r\n\r\n const img = new Image();\r\n img.onload = () => {\r\n resolve({ width: img.naturalWidth, height: img.naturalHeight });\r\n };\r\n img.onerror = reject;\r\n img.src = url;\r\n });\r\n};\r\n\r\n/**\r\n * Gets the dimensions (width and height) of an image from the given URL.\r\n * Uses a cache to avoid reloading the image if already fetched.\r\n * Also uses a concurrency limiter to control resource usage.\r\n *\r\n * @param url - The URL of the image.\r\n * @returns A Promise that resolves to an object containing `width` and `height`.\r\n */\r\nexport const getImageDimensions = (url: string): Promise<Dimensions> => {\r\n // Return cached dimensions if available\r\n if (imageDimensionsCache[url]) {\r\n return Promise.resolve(imageDimensionsCache[url]);\r\n }\r\n\r\n // Fetch and cache the dimensions using a concurrency limit\r\n return limit(() => loadImageDimensions(url)).then((dimensions) => {\r\n imageDimensionsCache[url] = dimensions;\r\n return dimensions;\r\n });\r\n};\r\n","import { videoMetaCache } from \"./cache\";\r\nimport { VideoMeta } from \"./types\";\r\n\r\n/**\r\n * Fetches metadata (width, height, duration) for a given video source.\r\n * If metadata has already been fetched and cached, it returns the cached data.\r\n *\r\n * @param videoSrc - The URL or path to the video file.\r\n * @returns A Promise that resolves to an object containing video metadata.\r\n */\r\nexport const getVideoMeta = (videoSrc: string): Promise<VideoMeta> => {\r\n // Return cached metadata if available\r\n if (videoMetaCache[videoSrc]) {\r\n return Promise.resolve(videoMetaCache[videoSrc]);\r\n }\r\n\r\n return new Promise<VideoMeta>((resolve, reject) => {\r\n const video: HTMLVideoElement = document.createElement(\"video\");\r\n video.preload = \"metadata\"; // Only preload metadata to reduce bandwidth\r\n // Validate the videoSrc to ensure it's a safe URL before assigning it to video.src\r\n const isSafeUrl = /^(https?:|blob:|data:video\\/)/i.test(videoSrc);\r\n if (!isSafeUrl) {\r\n reject(new Error(\"Unsafe video source URL\"));\r\n return;\r\n }\r\n video.src = videoSrc;\r\n\r\n // When metadata is loaded, extract and cache it\r\n video.onloadedmetadata = () => {\r\n const meta: VideoMeta = {\r\n width: video.videoWidth,\r\n height: video.videoHeight,\r\n duration: video.duration,\r\n };\r\n videoMetaCache[videoSrc] = meta;\r\n resolve(meta);\r\n };\r\n\r\n // Handle video loading errors\r\n video.onerror = () => reject(new Error(\"Failed to load video metadata\"));\r\n });\r\n};\r\n","/**\r\n * Extracts a thumbnail from a video at a specific seek time and playback rate.\r\n *\r\n * This function creates a hidden `<video>` element in the browser,\r\n * seeks to the specified time, and captures the frame into a canvas,\r\n * which is then exported as a JPEG data URL or Blob URL.\r\n *\r\n * @param videoUrl - The URL of the video to extract the thumbnail from.\r\n * @param seekTime - The time in seconds at which to capture the frame. Default is 0.1s.\r\n * @param playbackRate - Playback speed for the video. Default is 1.\r\n * @returns A Promise that resolves to a thumbnail image URL (either a base64 data URL or blob URL).\r\n */\r\nexport const getThumbnail = async (\r\n videoUrl: string,\r\n seekTime = 0.1,\r\n playbackRate = 1\r\n ): Promise<string> => {\r\n return new Promise((resolve, reject) => {\r\n const video = document.createElement(\"video\");\r\n video.crossOrigin = \"anonymous\";\r\n video.muted = true;\r\n video.playsInline = true;\r\n video.autoplay = false;\r\n video.preload = \"auto\";\r\n video.playbackRate = playbackRate;\r\n \r\n // Make video element hidden\r\n video.style.position = \"absolute\";\r\n video.style.left = \"-9999px\";\r\n video.style.top = \"-9999px\";\r\n video.style.width = \"1px\";\r\n video.style.height = \"1px\";\r\n video.style.opacity = \"0\";\r\n video.style.pointerEvents = \"none\";\r\n video.style.zIndex = \"-1\";\r\n \r\n let timeoutId: number | undefined;\r\n \r\n // Cleanup video element and timeout\r\n const cleanup = () => {\r\n if (video.parentNode) video.remove();\r\n if (timeoutId) clearTimeout(timeoutId);\r\n };\r\n \r\n // Handle errors during video loading\r\n const handleError = () => {\r\n cleanup();\r\n reject(new Error(`Failed to load video: ${video.error?.message || \"Unknown error\"}`));\r\n };\r\n \r\n // Once seeked to target frame, capture the image\r\n const handleSeeked = () => {\r\n try {\r\n video.pause();\r\n \r\n const canvas = document.createElement(\"canvas\");\r\n const width = video.videoWidth || 640;\r\n const height = video.videoHeight || 360;\r\n canvas.width = width;\r\n canvas.height = height;\r\n \r\n const ctx = canvas.getContext(\"2d\");\r\n if (!ctx) {\r\n cleanup();\r\n reject(new Error(\"Failed to get canvas context\"));\r\n return;\r\n }\r\n \r\n // Draw current video frame onto canvas\r\n ctx.drawImage(video, 0, 0, width, height);\r\n \r\n // Attempt to export canvas to base64 image URL\r\n try {\r\n const dataUrl = canvas.toDataURL(\"image/jpeg\", 0.8);\r\n cleanup();\r\n resolve(dataUrl);\r\n } catch {\r\n // Fallback: convert canvas to Blob\r\n canvas.toBlob((blob) => {\r\n if (!blob) {\r\n cleanup();\r\n reject(new Error(\"Failed to create Blob\"));\r\n return;\r\n }\r\n const blobUrl = URL.createObjectURL(blob);\r\n cleanup();\r\n resolve(blobUrl);\r\n }, \"image/jpeg\", 0.8);\r\n }\r\n } catch (err) {\r\n cleanup();\r\n reject(new Error(`Error creating thumbnail: ${err}`));\r\n }\r\n };\r\n \r\n video.addEventListener(\"error\", handleError, { once: true });\r\n video.addEventListener(\"seeked\", handleSeeked, { once: true });\r\n \r\n // After metadata is loaded, seek to the desired frame\r\n video.addEventListener(\"loadedmetadata\", () => {\r\n const playPromise = video.play();\r\n if (playPromise !== undefined) {\r\n playPromise\r\n .then(() => {\r\n video.currentTime = seekTime;\r\n })\r\n .catch(() => {\r\n video.currentTime = seekTime;\r\n });\r\n } else {\r\n video.currentTime = seekTime;\r\n }\r\n }, { once: true });\r\n \r\n // Timeout protection in case video loading hangs\r\n timeoutId = window.setTimeout(() => {\r\n cleanup();\r\n reject(new Error(\"Video loading timed out\"));\r\n }, 5000);\r\n \r\n // Assign video source and add it to the DOM (helps Safari/iOS behavior)\r\n video.src = videoUrl;\r\n document.body.appendChild(video);\r\n });\r\n };","import { Dimensions } from \"./types\";\r\n\r\n/**\r\n * Calculates the scaled dimensions of an element to fit inside a container\r\n * based on the specified max dimensions.\r\n *\r\n * @param width - The original width of the element.\r\n * @param height - The original height of the element.\r\n * @param maxWidth - The maximum width of the container.\r\n * @param maxHeight - The maximum height of the container.\r\n * @returns An object containing the calculated width and height for the element.\r\n */\r\nexport const getScaledDimensions = (\r\n width: number, \r\n height: number,\r\n maxWidth: number,\r\n maxHeight: number\r\n ): Dimensions => {\r\n // If the original dimensions are smaller than or equal to the max values, return the original dimensions\r\n if (width <= maxWidth && height <= maxHeight) {\r\n // Ensure the width and height are even numbers\r\n return {\r\n width: width % 2 === 0 ? width : width - 1,\r\n height: height % 2 === 0 ? height : height - 1,\r\n };\r\n }\r\n \r\n // Calculate scaling factor based on the maximum width and height\r\n const widthRatio = maxWidth / width;\r\n const heightRatio = maxHeight / height;\r\n \r\n // Use the smaller of the two ratios to maintain the aspect ratio\r\n const scale = Math.min(widthRatio, heightRatio);\r\n \r\n // Calculate the scaled dimensions\r\n let scaledWidth = Math.round(width * scale);\r\n let scaledHeight = Math.round(height * scale);\r\n \r\n // Ensure the width and height are even numbers\r\n if (scaledWidth % 2 !== 0) {\r\n scaledWidth -= 1; // Make width even if it's odd\r\n }\r\n if (scaledHeight % 2 !== 0) {\r\n scaledHeight -= 1; // Make height even if it's odd\r\n }\r\n \r\n // Ensure the scaled width and height fit within the max dimensions\r\n return {\r\n width: Math.min(scaledWidth, maxWidth),\r\n height: Math.min(scaledHeight, maxHeight),\r\n };\r\n };\r\n\r\n/**\r\n * Calculates the resized dimensions of an element to fit inside a container\r\n * based on the specified object-fit strategy (\"contain\", \"cover\", \"fill\", or default).\r\n *\r\n * @param objectFit - The object-fit behavior ('contain', 'cover', 'fill', or default/fallback).\r\n * @param elementSize - The original size of the element (width and height).\r\n * @param containerSize - The size of the container (width and height).\r\n * @returns An object containing the calculated width and height for the element.\r\n */\r\nexport const getObjectFitSize = (\r\n objectFit: string,\r\n elementSize: Dimensions,\r\n containerSize: Dimensions\r\n): Dimensions => {\r\n const elementAspectRatio = elementSize.width / elementSize.height;\r\n const containerAspectRatio = containerSize.width / containerSize.height;\r\n\r\n switch (objectFit) {\r\n case \"contain\":\r\n // Fit entire element inside container without cropping, maintaining aspect ratio\r\n if (elementAspectRatio > containerAspectRatio) {\r\n return {\r\n width: containerSize.width,\r\n height: containerSize.width / elementAspectRatio,\r\n };\r\n } else {\r\n return {\r\n width: containerSize.height * elementAspectRatio,\r\n height: containerSize.height,\r\n };\r\n }\r\n\r\n case \"cover\":\r\n // Fill container while maintaining aspect ratio, possibly cropping the element\r\n if (elementAspectRatio > containerAspectRatio) {\r\n return {\r\n width: containerSize.height * elementAspectRatio,\r\n height: containerSize.height,\r\n };\r\n } else {\r\n return {\r\n width: containerSize.width,\r\n height: containerSize.width / elementAspectRatio,\r\n };\r\n }\r\n\r\n case \"fill\":\r\n // Stretch element to completely fill the container, ignoring aspect ratio\r\n return {\r\n width: containerSize.width,\r\n height: containerSize.height,\r\n };\r\n\r\n default:\r\n // Default behavior: return original size of the element\r\n return {\r\n width: elementSize.width,\r\n height: elementSize.height,\r\n };\r\n }\r\n};\r\n\r\n ","/**\r\n * Converts a Blob URL to a File object.\r\n *\r\n * @param blobUrl - The Blob URL to convert.\r\n * @param fileName - The name to assign to the resulting File.\r\n * @returns A Promise that resolves to a File object.\r\n */\r\nexport const blobUrlToFile = async (blobUrl: string, fileName: string): Promise<File> => {\r\n const response = await fetch(blobUrl);\r\n const blob = await response.blob();\r\n return new File([blob], fileName, { type: blob.type });\r\n };\r\n \r\n /**\r\n * Triggers a download of a file from a string or Blob.\r\n *\r\n * @param content - The content to save, either a string or a Blob.\r\n * @param type - The MIME type of the content.\r\n * @param name - The name of the file to be saved.\r\n */\r\n export const saveAsFile = (content: string | Blob, type: string, name: string): void => {\r\n const blob = typeof content === \"string\" ? new Blob([content], { type }) : content;\r\n const url = URL.createObjectURL(blob);\r\n \r\n const a = document.createElement(\"a\");\r\n a.href = url;\r\n a.download = name;\r\n a.click();\r\n \r\n // Clean up the URL object after download\r\n URL.revokeObjectURL(url);\r\n };\r\n \r\n /**\r\n * Downloads a file from a given URL and triggers a browser download.\r\n *\r\n * @param url - The URL of the file to download.\r\n * @param filename - The name of the file to be saved.\r\n * @returns A Promise that resolves when the download is initiated or rejects if there is an error.\r\n */\r\n export const downloadFile = async (url: string, filename: string): Promise<void> => {\r\n try {\r\n const response = await fetch(url);\r\n const blob = await response.blob();\r\n const downloadUrl = window.URL.createObjectURL(blob);\r\n \r\n const link = document.createElement(\"a\");\r\n link.href = downloadUrl;\r\n link.download = filename;\r\n document.body.appendChild(link);\r\n link.click();\r\n \r\n // Clean up\r\n document.body.removeChild(link);\r\n window.URL.revokeObjectURL(downloadUrl);\r\n } catch (error) {\r\n console.error(\"Error downloading file:\", error);\r\n throw error;\r\n }\r\n };\r\n ","/**\r\n * Detects the media type (image, video, or audio) of a given URL by sending a HEAD request.\r\n *\r\n * @param url - The URL of the media file.\r\n * @returns A promise that resolves to 'image', 'video', or 'audio' based on the Content-Type header,\r\n * or `null` if the type couldn't be determined or the request fails.\r\n */\r\nexport const detectMediaTypeFromUrl = async (url: string): Promise<'image' | 'video' | 'audio' | null> => {\r\n try {\r\n // Use a HEAD request to fetch only the headers, avoiding download of the full file\r\n const response = await fetch(url, { method: 'HEAD' });\r\n \r\n // Extract the 'Content-Type' header from the response\r\n const contentType = response.headers.get('Content-Type');\r\n \r\n if (!contentType) return null;\r\n \r\n // Determine the media type from the content type\r\n if (contentType.startsWith('image/')) return 'image';\r\n if (contentType.startsWith('video/')) return 'video';\r\n if (contentType.startsWith('audio/')) return 'audio';\r\n \r\n // Return null if not a recognized media type\r\n return null;\r\n } catch (error) {\r\n console.error('Fetch failed:', error);\r\n return null;\r\n }\r\n };\r\n "],"names":[],"mappings":"AAEO,MAAM,uBAAmD,EAAC;AAC1D,MAAM,iBAA4C,EAAC;AACnD,MAAM,qBAA6C,EAAC;;ACK9C,MAAA,gBAAA,GAAmB,CAAC,QAAsC,KAAA;AAErE,EAAI,IAAA,kBAAA,CAAmB,QAAQ,CAAG,EAAA;AAChC,IAAA,OAAO,OAAQ,CAAA,OAAA,CAA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AAAA,WACA,KAAO,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,iBAAiB,KAAK,CAAA;AACpC,IAAO,OAAA,IAAA;AAAA;AAEX;;;;"}
package/package.json CHANGED
@@ -1,32 +1,36 @@
1
- {
2
- "name": "@twick/media-utils",
3
- "version": "0.0.1",
4
- "main": "./dist/index.js",
5
- "module": "./dist/index.mjs",
6
- "types": "./dist/index.d.ts",
7
- "sideEffects": false,
8
- "license": "Apache-2.0",
9
- "files": [
10
- "dist"
11
- ],
12
- "scripts": {
13
- "build": "vite build",
14
- "dev": "vite build --watch",
15
- "lint": "eslint src/",
16
- "clean": "rimraf .turbo node_modules dist",
17
- "docs": "typedoc --out docs src/index.ts"
18
- },
19
- "devDependencies": {
20
- "@types/node": "^20.11.24",
21
- "typescript": "5.4.2",
22
- "vite": "^5.1.4",
23
- "vite-plugin-dts": "^3.7.3",
24
- "rimraf": "^5.0.5",
25
- "typedoc": "^0.25.8",
26
- "typedoc-plugin-markdown": "^3.17.1"
27
- },
28
- "peerDependencies": {
29
- "react": "^18.0.0",
30
- "react-dom": "^18.0.0"
31
- }
32
- }
1
+ {
2
+ "name": "@twick/media-utils",
3
+ "version": "0.14.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "license": "Apache-2.0",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "devDependencies": {
17
+ "@types/node": "^20.11.24",
18
+ "typescript": "5.4.2",
19
+ "vite": "^5.1.4",
20
+ "vite-plugin-dts": "^3.7.3",
21
+ "rimraf": "^5.0.5",
22
+ "typedoc": "^0.25.8",
23
+ "typedoc-plugin-markdown": "^3.17.1"
24
+ },
25
+ "peerDependencies": {
26
+ "react": "^18.0.0",
27
+ "react-dom": "^18.0.0"
28
+ },
29
+ "scripts": {
30
+ "build": "vite build",
31
+ "dev": "vite build --watch",
32
+ "lint": "eslint src/",
33
+ "clean": "rimraf .turbo node_modules dist",
34
+ "docs": "typedoc --out docs src/index.ts"
35
+ }
36
+ }