@jay-framework/wix-utils 0.15.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.
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Wix Media URL Utilities
3
+ *
4
+ * Helpers for working with Wix media URLs and the wix:// protocol formats.
5
+ *
6
+ * Supported formats:
7
+ * - wix:image://v1/<id>/<name>#originWidth=<w>&originHeight=<h>
8
+ * - wix:video://v1/<id>/<name>#posterUri=<uri>&posterWidth=<w>&posterHeight=<h>
9
+ * - wix:document://v1/<id>/<name>
10
+ * - wix:audio://v1/<id>/<name>
11
+ */
12
+ type WixMediaType = 'image' | 'video' | 'document' | 'audio' | 'unknown';
13
+ /**
14
+ * Parsed Wix media URL with extracted metadata
15
+ */
16
+ interface ParsedWixMediaUrl {
17
+ type: WixMediaType;
18
+ mediaId: string;
19
+ fileName: string;
20
+ /** Original image dimensions (for images) */
21
+ originWidth?: number;
22
+ originHeight?: number;
23
+ /** Poster image info (for videos) */
24
+ posterUri?: string;
25
+ posterWidth?: number;
26
+ posterHeight?: number;
27
+ }
28
+ /**
29
+ * Parse any wix:// protocol URL and extract metadata
30
+ */
31
+ declare function parseWixMediaUrl(url: string): ParsedWixMediaUrl | null;
32
+ /**
33
+ * Parse wix:image:// protocol URLs and extract the media ID
34
+ * @deprecated Use parseWixMediaUrl for full metadata extraction
35
+ */
36
+ declare function parseWixImageUrl(url: string): string | null;
37
+ /**
38
+ * Parse wix:video:// protocol URLs and extract the media ID
39
+ * @deprecated Use parseWixMediaUrl for full metadata extraction
40
+ */
41
+ declare function parseWixVideoUrl(url: string): string | null;
42
+ /**
43
+ * Format Wix media URL to a usable static URL.
44
+ * Handles all wix:// protocol URLs (image, video, document, audio).
45
+ *
46
+ * @param _id - The media ID (used as fallback if url is not usable)
47
+ * @param url - The original URL (may be http(s):// or wix://)
48
+ * @param resize - Optional resize parameters (for images/video thumbnails)
49
+ * @returns A usable https:// URL
50
+ */
51
+ declare function formatWixMediaUrl(_id: string, url: string, resize?: {
52
+ w: number;
53
+ h: number;
54
+ }): string;
55
+ /**
56
+ * Get the video poster URL from a wix:video:// URL
57
+ */
58
+ declare function getVideoPosterUrl(url: string, resize?: {
59
+ w: number;
60
+ h: number;
61
+ }): string;
62
+ /**
63
+ * Get document download URL from a wix:document:// URL
64
+ */
65
+ declare function getDocumentUrl(url: string): string;
66
+ /**
67
+ * Get audio URL from a wix:audio:// URL
68
+ */
69
+ declare function getAudioUrl(url: string): string;
70
+
71
+ export { type ParsedWixMediaUrl, type WixMediaType, formatWixMediaUrl, getAudioUrl, getDocumentUrl, getVideoPosterUrl, parseWixImageUrl, parseWixMediaUrl, parseWixVideoUrl };
package/dist/index.js ADDED
@@ -0,0 +1,79 @@
1
+ function parseWixMediaUrl(url) {
2
+ if (!url) return null;
3
+ const match = url.match(
4
+ /^wix:(image|video|document|audio):\/\/v1\/([^/]+)\/([^#]+)(?:#(.*))?$/
5
+ );
6
+ if (!match) return null;
7
+ const [, type, mediaId, fileName, hashParams] = match;
8
+ const result = {
9
+ type,
10
+ mediaId,
11
+ fileName: decodeURIComponent(fileName)
12
+ };
13
+ if (hashParams) {
14
+ const params = new URLSearchParams(hashParams);
15
+ const originWidth = params.get("originWidth");
16
+ const originHeight = params.get("originHeight");
17
+ if (originWidth) result.originWidth = parseInt(originWidth, 10);
18
+ if (originHeight) result.originHeight = parseInt(originHeight, 10);
19
+ const posterUri = params.get("posterUri");
20
+ const posterWidth = params.get("posterWidth");
21
+ const posterHeight = params.get("posterHeight");
22
+ if (posterUri) result.posterUri = decodeURIComponent(posterUri);
23
+ if (posterWidth) result.posterWidth = parseInt(posterWidth, 10);
24
+ if (posterHeight) result.posterHeight = parseInt(posterHeight, 10);
25
+ }
26
+ return result;
27
+ }
28
+ function parseWixImageUrl(url) {
29
+ const parsed = parseWixMediaUrl(url);
30
+ return (parsed == null ? void 0 : parsed.type) === "image" ? parsed.mediaId : null;
31
+ }
32
+ function parseWixVideoUrl(url) {
33
+ const parsed = parseWixMediaUrl(url);
34
+ return (parsed == null ? void 0 : parsed.type) === "video" ? parsed.mediaId : null;
35
+ }
36
+ function formatWixMediaUrl(_id, url, resize) {
37
+ const resizeFragment = resize ? `/v1/fit/w_${resize.w},h_${resize.h},q_90/file.jpg` : "";
38
+ if (url == null ? void 0 : url.startsWith("wix:")) {
39
+ const parsed = parseWixMediaUrl(url);
40
+ if (parsed) {
41
+ return `https://static.wixstatic.com/media/${parsed.mediaId}${resizeFragment}`;
42
+ }
43
+ }
44
+ if ((url == null ? void 0 : url.startsWith("http://")) || (url == null ? void 0 : url.startsWith("https://"))) {
45
+ return url;
46
+ }
47
+ if (_id) {
48
+ return `https://static.wixstatic.com/media/${_id}${resizeFragment}`;
49
+ }
50
+ return "";
51
+ }
52
+ function getVideoPosterUrl(url, resize) {
53
+ const parsed = parseWixMediaUrl(url);
54
+ if (!parsed || parsed.type !== "video") return "";
55
+ if (parsed.posterUri) {
56
+ return formatWixMediaUrl("", parsed.posterUri, resize);
57
+ }
58
+ const resizeFragment = resize ? `/v1/fit/w_${resize.w},h_${resize.h},q_90/file.jpg` : "";
59
+ return `https://static.wixstatic.com/media/${parsed.mediaId}${resizeFragment}`;
60
+ }
61
+ function getDocumentUrl(url) {
62
+ const parsed = parseWixMediaUrl(url);
63
+ if (!parsed || parsed.type !== "document") return "";
64
+ return `https://static.wixstatic.com/ugd/${parsed.mediaId}`;
65
+ }
66
+ function getAudioUrl(url) {
67
+ const parsed = parseWixMediaUrl(url);
68
+ if (!parsed || parsed.type !== "audio") return "";
69
+ return `https://static.wixstatic.com/mp3/${parsed.mediaId}`;
70
+ }
71
+ export {
72
+ formatWixMediaUrl,
73
+ getAudioUrl,
74
+ getDocumentUrl,
75
+ getVideoPosterUrl,
76
+ parseWixImageUrl,
77
+ parseWixMediaUrl,
78
+ parseWixVideoUrl
79
+ };
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@jay-framework/wix-utils",
3
+ "version": "0.15.0",
4
+ "type": "module",
5
+ "description": "Shared utilities for Wix integrations in Jay Framework",
6
+ "license": "Apache-2.0",
7
+ "main": "dist/index.js",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "exports": {
12
+ ".": "./dist/index.js"
13
+ },
14
+ "scripts": {
15
+ "build": "npm run clean && npm run build:lib && npm run build:types",
16
+ "build:lib": "vite build",
17
+ "build:types": "tsup lib/index.ts --dts-only --format esm",
18
+ "build:check-types": "tsc",
19
+ "clean": "rimraf dist",
20
+ "test": ":"
21
+ },
22
+ "devDependencies": {
23
+ "rimraf": "^5.0.5",
24
+ "tsup": "^8.5.1",
25
+ "typescript": "^5.3.3",
26
+ "vite": "^5.0.11"
27
+ }
28
+ }