@medialane/ui 0.157.0 → 0.158.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.
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import { VariantProps } from 'class-variance-authority';
4
4
 
5
5
  declare const buttonVariants: (props?: ({
6
- variant?: "ghost" | "link" | "default" | "destructive" | "outline" | "secondary" | "premium" | "tonal" | "gradient-border" | "gradient-fill" | null | undefined;
6
+ variant?: "link" | "default" | "destructive" | "outline" | "ghost" | "secondary" | "premium" | "tonal" | "gradient-border" | "gradient-fill" | null | undefined;
7
7
  size?: "icon" | "default" | "sm" | "lg" | null | undefined;
8
8
  } & class_variance_authority_types.ClassProp) | undefined) => string;
9
9
  interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import { VariantProps } from 'class-variance-authority';
4
4
 
5
5
  declare const buttonVariants: (props?: ({
6
- variant?: "ghost" | "link" | "default" | "destructive" | "outline" | "secondary" | "premium" | "tonal" | "gradient-border" | "gradient-fill" | null | undefined;
6
+ variant?: "link" | "default" | "destructive" | "outline" | "ghost" | "secondary" | "premium" | "tonal" | "gradient-border" | "gradient-fill" | null | undefined;
7
7
  size?: "icon" | "default" | "sm" | "lg" | null | undefined;
8
8
  } & class_variance_authority_types.ClassProp) | undefined) => string;
9
9
  interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
@@ -19,7 +19,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var ipfs_exports = {};
20
20
  __export(ipfs_exports, {
21
21
  DEFAULT_GATEWAY: () => DEFAULT_GATEWAY,
22
- GATEWAY_TOKEN: () => GATEWAY_TOKEN,
23
22
  PUBLIC_GATEWAY: () => PUBLIC_GATEWAY,
24
23
  gatewayFrom: () => gatewayFrom,
25
24
  ipfsToHttp: () => ipfsToHttp,
@@ -36,19 +35,13 @@ function gatewayFrom(host) {
36
35
  return `https://${bare}/ipfs/`;
37
36
  }
38
37
  const DEFAULT_GATEWAY = gatewayFrom(process.env.NEXT_PUBLIC_IPFS_GATEWAY);
39
- const GATEWAY_TOKEN = process.env.NEXT_PUBLIC_IPFS_GATEWAY_TOKEN?.trim() ?? "";
40
- function withToken(url, gateway) {
41
- if (!GATEWAY_TOKEN || !url.startsWith(gateway)) return url;
42
- const sep = url.includes("?") ? "&" : "?";
43
- return `${url}${sep}pinataGatewayToken=${GATEWAY_TOKEN}`;
44
- }
45
38
  const ALLOWED_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "ipfs:"]);
46
39
  const KNOWN_IPFS_GATEWAY_HOSTS = /(^|\.)(mypinata\.cloud|pinata\.cloud|ipfs\.io|dweb\.link|cloudflare-ipfs\.com|nftstorage\.link|w3s\.link)$/i;
47
40
  const DEFAULT_WIDTH = 1200;
48
41
  function withSize(url, gateway, width) {
49
- if (!url.startsWith(gateway)) return url;
50
- const sized = width ? `${url}${url.includes("?") ? "&" : "?"}img-width=${width}&img-format=webp&img-quality=80` : url;
51
- return withToken(sized, gateway);
42
+ if (!width || !url.startsWith(gateway)) return url;
43
+ const sep = url.includes("?") ? "&" : "?";
44
+ return `${url}${sep}img-width=${width}&img-format=webp&img-quality=80`;
52
45
  }
53
46
  function ipfsToHttp(uri, opts = {}) {
54
47
  const gateway = opts.gateway ?? DEFAULT_GATEWAY;
@@ -97,7 +90,6 @@ function toAbsoluteImageUrl(uri) {
97
90
  // Annotate the CommonJS export names for ESM import in node:
98
91
  0 && (module.exports = {
99
92
  DEFAULT_GATEWAY,
100
- GATEWAY_TOKEN,
101
93
  PUBLIC_GATEWAY,
102
94
  gatewayFrom,
103
95
  ipfsToHttp,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/ipfs.ts"],"sourcesContent":["export const PUBLIC_GATEWAY = \"https://gateway.pinata.cloud/ipfs/\";\n\nexport function gatewayFrom(host: string | undefined): string {\n const trimmed = host?.trim();\n if (!trimmed) return PUBLIC_GATEWAY;\n const bare = trimmed.replace(/^https?:\\/\\//, \"\").replace(/\\/+$/, \"\");\n return `https://${bare}/ipfs/`;\n}\n\nexport const DEFAULT_GATEWAY = gatewayFrom(process.env.NEXT_PUBLIC_IPFS_GATEWAY);\n\nexport const GATEWAY_TOKEN = process.env.NEXT_PUBLIC_IPFS_GATEWAY_TOKEN?.trim() ?? \"\";\n\nfunction withToken(url: string, gateway: string): string {\n if (!GATEWAY_TOKEN || !url.startsWith(gateway)) return url;\n const sep = url.includes(\"?\") ? \"&\" : \"?\";\n return `${url}${sep}pinataGatewayToken=${GATEWAY_TOKEN}`;\n}\n\nconst ALLOWED_PROTOCOLS = new Set([\"http:\", \"https:\", \"ipfs:\"]);\n\nconst KNOWN_IPFS_GATEWAY_HOSTS = /(^|\\.)(mypinata\\.cloud|pinata\\.cloud|ipfs\\.io|dweb\\.link|cloudflare-ipfs\\.com|nftstorage\\.link|w3s\\.link)$/i;\n\nconst DEFAULT_WIDTH = 1200;\n\nfunction withSize(url: string, gateway: string, width: number | null): string {\n if (!url.startsWith(gateway)) return url;\n const sized = width\n ? `${url}${url.includes(\"?\") ? \"&\" : \"?\"}img-width=${width}&img-format=webp&img-quality=80`\n : url;\n return withToken(sized, gateway);\n}\n\nexport function ipfsToHttp(\n uri: string | null | undefined,\n opts: { gateway?: string; width?: number | null } = {}\n): string {\n const gateway = opts.gateway ?? DEFAULT_GATEWAY;\n const width = opts.width === undefined ? DEFAULT_WIDTH : opts.width;\n\n if (!uri) return \"\";\n if (uri.startsWith(\"ipfs://\")) {\n return withSize(uri.replace(\"ipfs://\", gateway), gateway, width);\n }\n if (uri.startsWith(\"data:image/\")) {\n return uri;\n }\n try {\n const parsed = new URL(uri);\n if (!ALLOWED_PROTOCOLS.has(parsed.protocol)) return \"\";\n\n if (KNOWN_IPFS_GATEWAY_HOSTS.test(parsed.hostname)) {\n const match = parsed.pathname.match(/\\/ipfs\\/(.+)$/);\n if (match) return withSize(`${gateway}${match[1]}`, gateway, width);\n }\n } catch {\n return \"\";\n }\n return uri;\n}\n\nexport interface DisplayUrlOptions {\n gateway?: string;\n proxyPath?: string;\n placeholder?: string;\n}\n\nexport function toDisplayUrl(\n uri: string | null | undefined,\n opts: DisplayUrlOptions = {},\n): string {\n const gateway = opts.gateway ?? DEFAULT_GATEWAY;\n const placeholder = opts.placeholder ?? \"/placeholder.svg\";\n const proxyPath = opts.proxyPath ?? \"/api/img\";\n\n if (!uri) return placeholder;\n if (uri.startsWith(\"data:image/\")) return uri;\n\n const resolved = ipfsToHttp(uri, { gateway });\n if (resolved.startsWith(gateway)) return resolved;\n\n if (uri.startsWith(\"https://\") || uri.startsWith(\"http://\")) {\n return `${proxyPath}?url=${encodeURIComponent(uri)}`;\n }\n\n return placeholder;\n}\n\nexport function toDisplayUrlOrNull(\n raw: string | null | undefined,\n opts: DisplayUrlOptions = {},\n): string | null {\n if (!raw) return null;\n if (raw.startsWith(\"/\")) return raw;\n return toDisplayUrl(raw, opts);\n}\n\nexport function toAbsoluteImageUrl(uri: string | null | undefined): string {\n if (!uri) return \"\";\n return ipfsToHttp(uri) || \"\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,iBAAiB;AAEvB,SAAS,YAAY,MAAkC;AAC5D,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,CAAC,QAAS,QAAO;AACrB,QAAM,OAAO,QAAQ,QAAQ,gBAAgB,EAAE,EAAE,QAAQ,QAAQ,EAAE;AACnE,SAAO,WAAW,IAAI;AACxB;AAEO,MAAM,kBAAkB,YAAY,QAAQ,IAAI,wBAAwB;AAExE,MAAM,gBAAgB,QAAQ,IAAI,gCAAgC,KAAK,KAAK;AAEnF,SAAS,UAAU,KAAa,SAAyB;AACvD,MAAI,CAAC,iBAAi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AK,eAAe;AACxC,QAAM,YAAY,KAAK,aAAa;AAEpC,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI,IAAI,WAAW,aAAa,EAAG,QAAO;AAE1C,QAAM,WAAW,WAAW,KAAK,EAAE,QAAQ,CAAC;AAC5C,MAAI,SAAS,WAAW,OAAO,EAAG,QAAO;AAEzC,MAAI,IAAI,WAAW,UAAU,KAAK,IAAI,WAAW,SAAS,GAAG;AAC3D,WAAO,GAAG,SAAS,QAAQ,mBAAmB,GAAG,CAAC;AAAA,EACpD;AAEA,SAAO;AACT;AAEO,SAAS,mBACd,KACA,OAA0B,CAAC,GACZ;AACf,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI,IAAI,WAAW,GAAG,EAAG,QAAO;AAChC,SAAO,aAAa,KAAK,IAAI;AAC/B;AAEO,SAAS,mBAAmB,KAAwC;AACzE,MAAI,CAAC,IAAK,QAAO;AACjB,SAAO,WAAW,GAAG,KAAK;AAC5B;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/ipfs.ts"],"sourcesContent":["export const PUBLIC_GATEWAY = \"https://gateway.pinata.cloud/ipfs/\";\n\nexport function gatewayFrom(host: string | undefined): string {\n const trimmed = host?.trim();\n if (!trimmed) return PUBLIC_GATEWAY;\n const bare = trimmed.replace(/^https?:\\/\\//, \"\").replace(/\\/+$/, \"\");\n return `https://${bare}/ipfs/`;\n}\n\nexport const DEFAULT_GATEWAY = gatewayFrom(process.env.NEXT_PUBLIC_IPFS_GATEWAY);\n\nconst ALLOWED_PROTOCOLS = new Set([\"http:\", \"https:\", \"ipfs:\"]);\n\nconst KNOWN_IPFS_GATEWAY_HOSTS = /(^|\\.)(mypinata\\.cloud|pinata\\.cloud|ipfs\\.io|dweb\\.link|cloudflare-ipfs\\.com|nftstorage\\.link|w3s\\.link)$/i;\n\nconst DEFAULT_WIDTH = 1200;\n\nfunction withSize(url: string, gateway: string, width: number | null): string {\n if (!width || !url.startsWith(gateway)) return url;\n const sep = url.includes(\"?\") ? \"&\" : \"?\";\n return `${url}${sep}img-width=${width}&img-format=webp&img-quality=80`;\n}\n\nexport function ipfsToHttp(\n uri: string | null | undefined,\n opts: { gateway?: string; width?: number | null } = {}\n): string {\n const gateway = opts.gateway ?? DEFAULT_GATEWAY;\n const width = opts.width === undefined ? DEFAULT_WIDTH : opts.width;\n\n if (!uri) return \"\";\n if (uri.startsWith(\"ipfs://\")) {\n return withSize(uri.replace(\"ipfs://\", gateway), gateway, width);\n }\n if (uri.startsWith(\"data:image/\")) {\n return uri;\n }\n try {\n const parsed = new URL(uri);\n if (!ALLOWED_PROTOCOLS.has(parsed.protocol)) return \"\";\n\n if (KNOWN_IPFS_GATEWAY_HOSTS.test(parsed.hostname)) {\n const match = parsed.pathname.match(/\\/ipfs\\/(.+)$/);\n if (match) return withSize(`${gateway}${match[1]}`, gateway, width);\n }\n } catch {\n return \"\";\n }\n return uri;\n}\n\nexport interface DisplayUrlOptions {\n gateway?: string;\n proxyPath?: string;\n placeholder?: string;\n}\n\nexport function toDisplayUrl(\n uri: string | null | undefined,\n opts: DisplayUrlOptions = {},\n): string {\n const gateway = opts.gateway ?? DEFAULT_GATEWAY;\n const placeholder = opts.placeholder ?? \"/placeholder.svg\";\n const proxyPath = opts.proxyPath ?? \"/api/img\";\n\n if (!uri) return placeholder;\n if (uri.startsWith(\"data:image/\")) return uri;\n\n const resolved = ipfsToHttp(uri, { gateway });\n if (resolved.startsWith(gateway)) return resolved;\n\n if (uri.startsWith(\"https://\") || uri.startsWith(\"http://\")) {\n return `${proxyPath}?url=${encodeURIComponent(uri)}`;\n }\n\n return placeholder;\n}\n\nexport function toDisplayUrlOrNull(\n raw: string | null | undefined,\n opts: DisplayUrlOptions = {},\n): string | null {\n if (!raw) return null;\n if (raw.startsWith(\"/\")) return raw;\n return toDisplayUrl(raw, opts);\n}\n\nexport function toAbsoluteImageUrl(uri: string | null | undefined): string {\n if (!uri) return \"\";\n return ipfsToHttp(uri) || \"\";\n}\n"],"mappings":";;;;;;;;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AC,IAAI,SAAS,KAAK;AAAA,IACpE;AAAA,EACF,QAAQ;AACN,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAQO,SAAS,aACd,KACA,OAA0B,CAAC,GACnB;AACR,QAAM,UAAU,KAAK,WAAW;AAChC,QAAM,cAAc,KAAK,eAAe;AACxC,QAAM,YAAY,KAAK,aAAa;AAEpC,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI,IAAI,WAAW,aAAa,EAAG,QAAO;AAE1C,QAAM,WAAW,WAAW,KAAK,EAAE,QAAQ,CAAC;AAC5C,MAAI,SAAS,WAAW,OAAO,EAAG,QAAO;AAEzC,MAAI,IAAI,WAAW,UAAU,KAAK,IAAI,WAAW,SAAS,GAAG;AAC3D,WAAO,GAAG,SAAS,QAAQ,mBAAmB,GAAG,CAAC;AAAA,EACpD;AAEA,SAAO;AACT;AAEO,SAAS,mBACd,KACA,OAA0B,CAAC,GACZ;AACf,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI,IAAI,WAAW,GAAG,EAAG,QAAO;AAChC,SAAO,aAAa,KAAK,IAAI;AAC/B;AAEO,SAAS,mBAAmB,KAAwC;AACzE,MAAI,CAAC,IAAK,QAAO;AACjB,SAAO,WAAW,GAAG,KAAK;AAC5B;","names":[]}
@@ -1,7 +1,6 @@
1
1
  declare const PUBLIC_GATEWAY = "https://gateway.pinata.cloud/ipfs/";
2
2
  declare function gatewayFrom(host: string | undefined): string;
3
3
  declare const DEFAULT_GATEWAY: string;
4
- declare const GATEWAY_TOKEN: string;
5
4
  declare function ipfsToHttp(uri: string | null | undefined, opts?: {
6
5
  gateway?: string;
7
6
  width?: number | null;
@@ -15,4 +14,4 @@ declare function toDisplayUrl(uri: string | null | undefined, opts?: DisplayUrlO
15
14
  declare function toDisplayUrlOrNull(raw: string | null | undefined, opts?: DisplayUrlOptions): string | null;
16
15
  declare function toAbsoluteImageUrl(uri: string | null | undefined): string;
17
16
 
18
- export { DEFAULT_GATEWAY, type DisplayUrlOptions, GATEWAY_TOKEN, PUBLIC_GATEWAY, gatewayFrom, ipfsToHttp, toAbsoluteImageUrl, toDisplayUrl, toDisplayUrlOrNull };
17
+ export { DEFAULT_GATEWAY, type DisplayUrlOptions, PUBLIC_GATEWAY, gatewayFrom, ipfsToHttp, toAbsoluteImageUrl, toDisplayUrl, toDisplayUrlOrNull };
@@ -1,7 +1,6 @@
1
1
  declare const PUBLIC_GATEWAY = "https://gateway.pinata.cloud/ipfs/";
2
2
  declare function gatewayFrom(host: string | undefined): string;
3
3
  declare const DEFAULT_GATEWAY: string;
4
- declare const GATEWAY_TOKEN: string;
5
4
  declare function ipfsToHttp(uri: string | null | undefined, opts?: {
6
5
  gateway?: string;
7
6
  width?: number | null;
@@ -15,4 +14,4 @@ declare function toDisplayUrl(uri: string | null | undefined, opts?: DisplayUrlO
15
14
  declare function toDisplayUrlOrNull(raw: string | null | undefined, opts?: DisplayUrlOptions): string | null;
16
15
  declare function toAbsoluteImageUrl(uri: string | null | undefined): string;
17
16
 
18
- export { DEFAULT_GATEWAY, type DisplayUrlOptions, GATEWAY_TOKEN, PUBLIC_GATEWAY, gatewayFrom, ipfsToHttp, toAbsoluteImageUrl, toDisplayUrl, toDisplayUrlOrNull };
17
+ export { DEFAULT_GATEWAY, type DisplayUrlOptions, PUBLIC_GATEWAY, gatewayFrom, ipfsToHttp, toAbsoluteImageUrl, toDisplayUrl, toDisplayUrlOrNull };
@@ -6,19 +6,13 @@ function gatewayFrom(host) {
6
6
  return `https://${bare}/ipfs/`;
7
7
  }
8
8
  const DEFAULT_GATEWAY = gatewayFrom(process.env.NEXT_PUBLIC_IPFS_GATEWAY);
9
- const GATEWAY_TOKEN = process.env.NEXT_PUBLIC_IPFS_GATEWAY_TOKEN?.trim() ?? "";
10
- function withToken(url, gateway) {
11
- if (!GATEWAY_TOKEN || !url.startsWith(gateway)) return url;
12
- const sep = url.includes("?") ? "&" : "?";
13
- return `${url}${sep}pinataGatewayToken=${GATEWAY_TOKEN}`;
14
- }
15
9
  const ALLOWED_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "ipfs:"]);
16
10
  const KNOWN_IPFS_GATEWAY_HOSTS = /(^|\.)(mypinata\.cloud|pinata\.cloud|ipfs\.io|dweb\.link|cloudflare-ipfs\.com|nftstorage\.link|w3s\.link)$/i;
17
11
  const DEFAULT_WIDTH = 1200;
18
12
  function withSize(url, gateway, width) {
19
- if (!url.startsWith(gateway)) return url;
20
- const sized = width ? `${url}${url.includes("?") ? "&" : "?"}img-width=${width}&img-format=webp&img-quality=80` : url;
21
- return withToken(sized, gateway);
13
+ if (!width || !url.startsWith(gateway)) return url;
14
+ const sep = url.includes("?") ? "&" : "?";
15
+ return `${url}${sep}img-width=${width}&img-format=webp&img-quality=80`;
22
16
  }
23
17
  function ipfsToHttp(uri, opts = {}) {
24
18
  const gateway = opts.gateway ?? DEFAULT_GATEWAY;
@@ -66,7 +60,6 @@ function toAbsoluteImageUrl(uri) {
66
60
  }
67
61
  export {
68
62
  DEFAULT_GATEWAY,
69
- GATEWAY_TOKEN,
70
63
  PUBLIC_GATEWAY,
71
64
  gatewayFrom,
72
65
  ipfsToHttp,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/ipfs.ts"],"sourcesContent":["export const PUBLIC_GATEWAY = \"https://gateway.pinata.cloud/ipfs/\";\n\nexport function gatewayFrom(host: string | undefined): string {\n const trimmed = host?.trim();\n if (!trimmed) return PUBLIC_GATEWAY;\n const bare = trimmed.replace(/^https?:\\/\\//, \"\").replace(/\\/+$/, \"\");\n return `https://${bare}/ipfs/`;\n}\n\nexport const DEFAULT_GATEWAY = gatewayFrom(process.env.NEXT_PUBLIC_IPFS_GATEWAY);\n\nexport const GATEWAY_TOKEN = process.env.NEXT_PUBLIC_IPFS_GATEWAY_TOKEN?.trim() ?? \"\";\n\nfunction withToken(url: string, gateway: string): string {\n if (!GATEWAY_TOKEN || !url.startsWith(gateway)) return url;\n const sep = url.includes(\"?\") ? \"&\" : \"?\";\n return `${url}${sep}pinataGatewayToken=${GATEWAY_TOKEN}`;\n}\n\nconst ALLOWED_PROTOCOLS = new Set([\"http:\", \"https:\", \"ipfs:\"]);\n\nconst KNOWN_IPFS_GATEWAY_HOSTS = /(^|\\.)(mypinata\\.cloud|pinata\\.cloud|ipfs\\.io|dweb\\.link|cloudflare-ipfs\\.com|nftstorage\\.link|w3s\\.link)$/i;\n\nconst DEFAULT_WIDTH = 1200;\n\nfunction withSize(url: string, gateway: string, width: number | null): string {\n if (!url.startsWith(gateway)) return url;\n const sized = width\n ? `${url}${url.includes(\"?\") ? \"&\" : \"?\"}img-width=${width}&img-format=webp&img-quality=80`\n : url;\n return withToken(sized, gateway);\n}\n\nexport function ipfsToHttp(\n uri: string | null | undefined,\n opts: { gateway?: string; width?: number | null } = {}\n): string {\n const gateway = opts.gateway ?? DEFAULT_GATEWAY;\n const width = opts.width === undefined ? DEFAULT_WIDTH : opts.width;\n\n if (!uri) return \"\";\n if (uri.startsWith(\"ipfs://\")) {\n return withSize(uri.replace(\"ipfs://\", gateway), gateway, width);\n }\n if (uri.startsWith(\"data:image/\")) {\n return uri;\n }\n try {\n const parsed = new URL(uri);\n if (!ALLOWED_PROTOCOLS.has(parsed.protocol)) return \"\";\n\n if (KNOWN_IPFS_GATEWAY_HOSTS.test(parsed.hostname)) {\n const match = parsed.pathname.match(/\\/ipfs\\/(.+)$/);\n if (match) return withSize(`${gateway}${match[1]}`, gateway, width);\n }\n } catch {\n return \"\";\n }\n return uri;\n}\n\nexport interface DisplayUrlOptions {\n gateway?: string;\n proxyPath?: string;\n placeholder?: string;\n}\n\nexport function toDisplayUrl(\n uri: string | null | undefined,\n opts: DisplayUrlOptions = {},\n): string {\n const gateway = opts.gateway ?? DEFAULT_GATEWAY;\n const placeholder = opts.placeholder ?? \"/placeholder.svg\";\n const proxyPath = opts.proxyPath ?? \"/api/img\";\n\n if (!uri) return placeholder;\n if (uri.startsWith(\"data:image/\")) return uri;\n\n const resolved = ipfsToHttp(uri, { gateway });\n if (resolved.startsWith(gateway)) return resolved;\n\n if (uri.startsWith(\"https://\") || uri.startsWith(\"http://\")) {\n return `${proxyPath}?url=${encodeURIComponent(uri)}`;\n }\n\n return placeholder;\n}\n\nexport function toDisplayUrlOrNull(\n raw: string | null | undefined,\n opts: DisplayUrlOptions = {},\n): string | null {\n if (!raw) return null;\n if (raw.startsWith(\"/\")) return raw;\n return toDisplayUrl(raw, opts);\n}\n\nexport function toAbsoluteImageUrl(uri: string | null | undefined): string {\n if (!uri) return \"\";\n return ipfsToHttp(uri) || \"\";\n}\n"],"mappings":"AAAO,MAAM,iBAAiB;AAEvB,SAAS,YAAY,MAAkC;AAC5D,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,CAAC,QAAS,QAAO;AACrB,QAAM,OAAO,QAAQ,QAAQ,gBAAgB,EAAE,EAAE,QAAQ,QAAQ,EAAE;AACnE,SAAO,WAAW,IAAI;AACxB;AAEO,MAAM,kBAAkB,YAAY,QAAQ,IAAI,wBAAwB;AAExE,MAAM,gBAAgB,QAAQ,IAAI,gCAAgC,KAAK,KAAK;AAEnF,SAAS,UAAU,KAAa,SAAyB;AACvD,MAAI,CAAC,iBAAiB,CAAC,IAAI,WAAW,OAAO,EAAG,QAAO;AACvD,QAAM,MAAM,IAAI,SAAS,GAAG,IAAI,MAAM;AACtC,SAAO,GAAG,GAAG,GAAG,GAAG,sBAAsB,aAAa;AACxD;AAEA,MAAM,oBAAoB,oBAAI,IAAI,CAAC,SAAS,UAAU,OAAO,CAAC;AAE9D,MAAM,2BAA2B;AAEjC,MAAM,gBAAgB;AAEtB,SAAS,SAAS,KAAa,SAAiB,OAA8B;AAC5E,MAAI,CAAC,IAAI,WAAW,OAAO,EAAG,QAAO;AACrC,QAAM,QAAQ,QACV,GAAG,GAAG,GAAG,IAAI,SAAS,GAAG,IAAI,MAAM,GAAG,aAAa,KAAK,oCACxD;AACJ,SAAO,UAAU,OAAO,OAAO;AACjC;AAEO,SAAS,WACd,KACA,OAAoD,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AEO,SAAS,mBAAmB,KAAwC;AACzE,MAAI,CAAC,IAAK,QAAO;AACjB,SAAO,WAAW,GAAG,KAAK;AAC5B;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/ipfs.ts"],"sourcesContent":["export const PUBLIC_GATEWAY = \"https://gateway.pinata.cloud/ipfs/\";\n\nexport function gatewayFrom(host: string | undefined): string {\n const trimmed = host?.trim();\n if (!trimmed) return PUBLIC_GATEWAY;\n const bare = trimmed.replace(/^https?:\\/\\//, \"\").replace(/\\/+$/, \"\");\n return `https://${bare}/ipfs/`;\n}\n\nexport const DEFAULT_GATEWAY = gatewayFrom(process.env.NEXT_PUBLIC_IPFS_GATEWAY);\n\nconst ALLOWED_PROTOCOLS = new Set([\"http:\", \"https:\", \"ipfs:\"]);\n\nconst KNOWN_IPFS_GATEWAY_HOSTS = /(^|\\.)(mypinata\\.cloud|pinata\\.cloud|ipfs\\.io|dweb\\.link|cloudflare-ipfs\\.com|nftstorage\\.link|w3s\\.link)$/i;\n\nconst DEFAULT_WIDTH = 1200;\n\nfunction withSize(url: string, gateway: string, width: number | null): string {\n if (!width || !url.startsWith(gateway)) return url;\n const sep = url.includes(\"?\") ? \"&\" : \"?\";\n return `${url}${sep}img-width=${width}&img-format=webp&img-quality=80`;\n}\n\nexport function ipfsToHttp(\n uri: string | null | undefined,\n opts: { gateway?: string; width?: number | null } = {}\n): string {\n const gateway = opts.gateway ?? DEFAULT_GATEWAY;\n const width = opts.width === undefined ? DEFAULT_WIDTH : opts.width;\n\n if (!uri) return \"\";\n if (uri.startsWith(\"ipfs://\")) {\n return withSize(uri.replace(\"ipfs://\", gateway), gateway, width);\n }\n if (uri.startsWith(\"data:image/\")) {\n return uri;\n }\n try {\n const parsed = new URL(uri);\n if (!ALLOWED_PROTOCOLS.has(parsed.protocol)) return \"\";\n\n if (KNOWN_IPFS_GATEWAY_HOSTS.test(parsed.hostname)) {\n const match = parsed.pathname.match(/\\/ipfs\\/(.+)$/);\n if (match) return withSize(`${gateway}${match[1]}`, gateway, width);\n }\n } catch {\n return \"\";\n }\n return uri;\n}\n\nexport interface DisplayUrlOptions {\n gateway?: string;\n proxyPath?: string;\n placeholder?: string;\n}\n\nexport function toDisplayUrl(\n uri: string | null | undefined,\n opts: DisplayUrlOptions = {},\n): string {\n const gateway = opts.gateway ?? DEFAULT_GATEWAY;\n const placeholder = opts.placeholder ?? \"/placeholder.svg\";\n const proxyPath = opts.proxyPath ?? \"/api/img\";\n\n if (!uri) return placeholder;\n if (uri.startsWith(\"data:image/\")) return uri;\n\n const resolved = ipfsToHttp(uri, { gateway });\n if (resolved.startsWith(gateway)) return resolved;\n\n if (uri.startsWith(\"https://\") || uri.startsWith(\"http://\")) {\n return `${proxyPath}?url=${encodeURIComponent(uri)}`;\n }\n\n return placeholder;\n}\n\nexport function toDisplayUrlOrNull(\n raw: string | null | undefined,\n opts: DisplayUrlOptions = {},\n): string | null {\n if (!raw) return null;\n if (raw.startsWith(\"/\")) return raw;\n return toDisplayUrl(raw, opts);\n}\n\nexport function toAbsoluteImageUrl(uri: string | null | undefined): string {\n if (!uri) return \"\";\n return ipfsToHttp(uri) || \"\";\n}\n"],"mappings":"AAAO,MAAM,iBAAiB;AAEvB,SAAS,YAAY,MAAkC;AAC5D,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,CAAC,QAAS,QAAO;AACrB,QAAM,OAAO,QAAQ,QAAQ,gBAAgB,EAAE,EAAE,QAAQ,QAAQ,EAAE;AACnE,SAAO,WAAW,IAAI;AACxB;AAEO,MAAM,kBAAkB,YAAY,QAAQ,IAAI,wBAAwB;AAE/E,MAAM,oBAAoB,oBAAI,IAAI,CAAC,SAAS,UAAU,OAAO,CAAC;AAE9D,MAAM,2BAA2B;AAEjC,MAAM,gBAAgB;AAEtB,SAAS,SAAS,KAAa,SAAiB,OAA8B;AAC5E,MAAI,CAAC,SAAS,CAAC,IAAI,WAAW,OAAO,EAAG,QAAO;AAC/C,QAAM,MAAM,IAAI,SAAS,GAAG,IA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IAAK,QAAO;AACjB,MAAI,IAAI,WAAW,GAAG,EAAG,QAAO;AAChC,SAAO,aAAa,KAAK,IAAI;AAC/B;AAEO,SAAS,mBAAmB,KAAwC;AACzE,MAAI,CAAC,IAAK,QAAO;AACjB,SAAO,WAAW,GAAG,KAAK;AAC5B;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medialane/ui",
3
- "version": "0.157.0",
3
+ "version": "0.158.0",
4
4
  "description": "Shared UI components for Medialane apps",
5
5
  "type": "module",
6
6
  "sideEffects": false,