@opensea/seadn 2.1.0 → 2.2.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/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/sdk.spec.ts +4 -4
- package/src/sdk.ts +4 -5
package/dist/index.d.mts
CHANGED
|
@@ -6,8 +6,8 @@ type MediaParams = {
|
|
|
6
6
|
format?: MediaFormat;
|
|
7
7
|
quality?: number | `${number}`;
|
|
8
8
|
fit?: MediaFit;
|
|
9
|
-
|
|
9
|
+
frameTime?: number;
|
|
10
10
|
};
|
|
11
|
-
declare function optimize(image: string | URL, { width, height, format, quality, fit,
|
|
11
|
+
declare function optimize(image: string | URL, { width, height, format, quality, fit, frameTime }: MediaParams): string;
|
|
12
12
|
|
|
13
13
|
export { type MediaFit, type MediaFormat, type MediaParams, optimize };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ type MediaParams = {
|
|
|
6
6
|
format?: MediaFormat;
|
|
7
7
|
quality?: number | `${number}`;
|
|
8
8
|
fit?: MediaFit;
|
|
9
|
-
|
|
9
|
+
frameTime?: number;
|
|
10
10
|
};
|
|
11
|
-
declare function optimize(image: string | URL, { width, height, format, quality, fit,
|
|
11
|
+
declare function optimize(image: string | URL, { width, height, format, quality, fit, frameTime }: MediaParams): string;
|
|
12
12
|
|
|
13
13
|
export { type MediaFit, type MediaFormat, type MediaParams, optimize };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var h=(e,n)=>{for(var r in n)s(e,r,{get:n[r],enumerable:!0})},x=(e,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of m(n))!l.call(e,t)&&t!==r&&s(e,t,{get:()=>n[t],enumerable:!(o=b(n,t))||o.enumerable});return e};var R=e=>x(s({},"__esModule",{value:!0}),e);var g={};h(g,{optimize:()=>d});module.exports=R(g);function d(e,{width:n,height:r,format:o,quality:t,fit:a,
|
|
1
|
+
"use strict";var s=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var h=(e,n)=>{for(var r in n)s(e,r,{get:n[r],enumerable:!0})},x=(e,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of m(n))!l.call(e,t)&&t!==r&&s(e,t,{get:()=>n[t],enumerable:!(o=b(n,t))||o.enumerable});return e};var R=e=>x(s({},"__esModule",{value:!0}),e);var g={};h(g,{optimize:()=>d});module.exports=R(g);function d(e,{width:n,height:r,format:o,quality:t,fit:a,frameTime:f}){try{typeof e=="string"&&(e=new URL(e))}catch(w){return e.toString()}if(!(e instanceof URL))return e;let u=S(e);if(!L(e)&&!u)return e.toString();let i=new URLSearchParams;if(r!==void 0&&i.set("h",String(r)),n!==void 0&&i.set("w",String(n)),o!==void 0&&i.set("format",o),t){if(Number(t)<=0||Number(t)>100)throw new Error("Quality has to be a positive number between 1 and 100");i.set("q",String(t))}if(a!==void 0&&i.set("fit",a),f!==void 0)u&&i.set("frame-time",String(f));else if(c(e))return e.toString();return e.search=i.toString(),e.toString()}function c(e){let n=p(e);return n==="mp4"||n==="mov"}function S(e){return c(e)}function L(e){if(!U(e))return!1;switch(p(e)){case"png":case"jpeg":case"webp":case"avif":case"ico":case"gif":case void 0:return!0;default:return!1}}function p(e){let n=e.pathname.split(".");if(!(n.length<=1))return n[n.length-1]}function U(e){return e.hostname.endsWith("seadn.io")}0&&(module.exports={optimize});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/sdk.ts"],"sourcesContent":["export { optimize, MediaParams, MediaFormat, MediaFit } from \"./sdk\";\n","export type MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\nexport type MediaFit = \"cover\" | \"contain\" | \"fill\" | \"inside\" | \"outside\";\n\nexport type MediaParams = {\n width?: number | `${number}`;\n height?: number | `${number}`;\n format?: MediaFormat;\n quality?: number | `${number}`;\n fit?: MediaFit;\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/sdk.ts"],"sourcesContent":["export { optimize, MediaParams, MediaFormat, MediaFit } from \"./sdk\";\n","export type MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\nexport type MediaFit = \"cover\" | \"contain\" | \"fill\" | \"inside\" | \"outside\";\n\nexport type MediaParams = {\n width?: number | `${number}`;\n height?: number | `${number}`;\n format?: MediaFormat;\n quality?: number | `${number}`;\n fit?: MediaFit;\n frameTime?: number;\n};\n\nexport function optimize(\n image: string | URL,\n { width, height, format, quality, fit, frameTime }: MediaParams,\n): string {\n try {\n if (typeof image === \"string\") {\n image = new URL(image);\n }\n } catch {\n return image.toString();\n }\n\n if (!(image instanceof URL)) {\n return image;\n }\n\n const isFrameable = canExtractFrame(image);\n if (!canBeResized(image) && !isFrameable) {\n return image.toString();\n }\n\n const params = new URLSearchParams();\n if (height !== undefined) {\n params.set(\"h\", String(height));\n }\n if (width !== undefined) {\n params.set(\"w\", String(width));\n }\n if (format !== undefined) {\n params.set(\"format\", format);\n }\n if (quality) {\n if (Number(quality) <= 0 || Number(quality) > 100) {\n throw new Error(\"Quality has to be a positive number between 1 and 100\");\n }\n params.set(\"q\", String(quality));\n }\n if (fit !== undefined) {\n params.set(\"fit\", fit);\n }\n if (frameTime !== undefined) {\n if (isFrameable) {\n params.set(\"frame-time\", String(frameTime));\n }\n } else if (isVideo(image)) {\n return image.toString();\n }\n\n image.search = params.toString();\n return image.toString();\n}\n\nfunction isVideo(url: URL): boolean {\n const extension = getExtension(url);\n return extension === \"mp4\" || extension === \"mov\";\n}\n\nfunction canExtractFrame(url: URL): boolean {\n return isVideo(url);\n}\n\nfunction canBeResized(url: URL): boolean {\n if (!isSeadnURL(url)) {\n return false;\n }\n const extension = getExtension(url);\n switch (extension) {\n case \"png\":\n case \"jpeg\":\n case \"webp\":\n case \"avif\":\n case \"ico\":\n case \"gif\":\n case undefined:\n return true;\n default:\n return false;\n }\n}\n\nfunction getExtension(url: URL): string | undefined {\n const split = url.pathname.split(\".\");\n if (split.length <= 1) {\n return undefined;\n }\n return split[split.length - 1];\n}\n\nexport function isSeadnURL(url: URL): boolean {\n return url.hostname.endsWith(\"seadn.io\");\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GCYO,SAASI,EACdC,EACA,CAAE,MAAAC,EAAO,OAAAC,EAAQ,OAAAC,EAAQ,QAAAC,EAAS,IAAAC,EAAK,UAAAC,CAAU,EACzC,CACR,GAAI,CACE,OAAON,GAAU,WACnBA,EAAQ,IAAI,IAAIA,CAAK,EAEzB,OAAQO,EAAA,CACN,OAAOP,EAAM,SAAS,CACxB,CAEA,GAAI,EAAEA,aAAiB,KACrB,OAAOA,EAGT,IAAMQ,EAAcC,EAAgBT,CAAK,EACzC,GAAI,CAACU,EAAaV,CAAK,GAAK,CAACQ,EAC3B,OAAOR,EAAM,SAAS,EAGxB,IAAMW,EAAS,IAAI,gBAUnB,GATIT,IAAW,QACbS,EAAO,IAAI,IAAK,OAAOT,CAAM,CAAC,EAE5BD,IAAU,QACZU,EAAO,IAAI,IAAK,OAAOV,CAAK,CAAC,EAE3BE,IAAW,QACbQ,EAAO,IAAI,SAAUR,CAAM,EAEzBC,EAAS,CACX,GAAI,OAAOA,CAAO,GAAK,GAAK,OAAOA,CAAO,EAAI,IAC5C,MAAM,IAAI,MAAM,uDAAuD,EAEzEO,EAAO,IAAI,IAAK,OAAOP,CAAO,CAAC,CACjC,CAIA,GAHIC,IAAQ,QACVM,EAAO,IAAI,MAAON,CAAG,EAEnBC,IAAc,OACZE,GACFG,EAAO,IAAI,aAAc,OAAOL,CAAS,CAAC,UAEnCM,EAAQZ,CAAK,EACtB,OAAOA,EAAM,SAAS,EAGxB,OAAAA,EAAM,OAASW,EAAO,SAAS,EACxBX,EAAM,SAAS,CACxB,CAEA,SAASY,EAAQC,EAAmB,CAClC,IAAMC,EAAYC,EAAaF,CAAG,EAClC,OAAOC,IAAc,OAASA,IAAc,KAC9C,CAEA,SAASL,EAAgBI,EAAmB,CAC1C,OAAOD,EAAQC,CAAG,CACpB,CAEA,SAASH,EAAaG,EAAmB,CACvC,GAAI,CAACG,EAAWH,CAAG,EACjB,MAAO,GAGT,OADkBE,EAAaF,CAAG,EACf,CACjB,IAAK,MACL,IAAK,OACL,IAAK,OACL,IAAK,OACL,IAAK,MACL,IAAK,MACL,KAAK,OACH,MAAO,GACT,QACE,MAAO,EACX,CACF,CAEA,SAASE,EAAaF,EAA8B,CAClD,IAAMI,EAAQJ,EAAI,SAAS,MAAM,GAAG,EACpC,GAAI,EAAAI,EAAM,QAAU,GAGpB,OAAOA,EAAMA,EAAM,OAAS,CAAC,CAC/B,CAEO,SAASD,EAAWH,EAAmB,CAC5C,OAAOA,EAAI,SAAS,SAAS,UAAU,CACzC","names":["src_exports","__export","optimize","__toCommonJS","optimize","image","width","height","format","quality","fit","frameTime","e","isFrameable","canExtractFrame","canBeResized","params","isVideo","url","extension","getExtension","isSeadnURL","split"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function c(e,{width:n,height:i,format:o,quality:r,fit:s,
|
|
1
|
+
function c(e,{width:n,height:i,format:o,quality:r,fit:s,frameTime:a}){try{typeof e=="string"&&(e=new URL(e))}catch(l){return e.toString()}if(!(e instanceof URL))return e;let f=p(e);if(!b(e)&&!f)return e.toString();let t=new URLSearchParams;if(i!==void 0&&t.set("h",String(i)),n!==void 0&&t.set("w",String(n)),o!==void 0&&t.set("format",o),r){if(Number(r)<=0||Number(r)>100)throw new Error("Quality has to be a positive number between 1 and 100");t.set("q",String(r))}if(s!==void 0&&t.set("fit",s),a!==void 0)f&&t.set("frame-time",String(a));else if(u(e))return e.toString();return e.search=t.toString(),e.toString()}function u(e){let n=d(e);return n==="mp4"||n==="mov"}function p(e){return u(e)}function b(e){if(!m(e))return!1;switch(d(e)){case"png":case"jpeg":case"webp":case"avif":case"ico":case"gif":case void 0:return!0;default:return!1}}function d(e){let n=e.pathname.split(".");if(!(n.length<=1))return n[n.length-1]}function m(e){return e.hostname.endsWith("seadn.io")}export{c as optimize};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["export type MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\nexport type MediaFit = \"cover\" | \"contain\" | \"fill\" | \"inside\" | \"outside\";\n\nexport type MediaParams = {\n width?: number | `${number}`;\n height?: number | `${number}`;\n format?: MediaFormat;\n quality?: number | `${number}`;\n fit?: MediaFit;\n
|
|
1
|
+
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["export type MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\nexport type MediaFit = \"cover\" | \"contain\" | \"fill\" | \"inside\" | \"outside\";\n\nexport type MediaParams = {\n width?: number | `${number}`;\n height?: number | `${number}`;\n format?: MediaFormat;\n quality?: number | `${number}`;\n fit?: MediaFit;\n frameTime?: number;\n};\n\nexport function optimize(\n image: string | URL,\n { width, height, format, quality, fit, frameTime }: MediaParams,\n): string {\n try {\n if (typeof image === \"string\") {\n image = new URL(image);\n }\n } catch {\n return image.toString();\n }\n\n if (!(image instanceof URL)) {\n return image;\n }\n\n const isFrameable = canExtractFrame(image);\n if (!canBeResized(image) && !isFrameable) {\n return image.toString();\n }\n\n const params = new URLSearchParams();\n if (height !== undefined) {\n params.set(\"h\", String(height));\n }\n if (width !== undefined) {\n params.set(\"w\", String(width));\n }\n if (format !== undefined) {\n params.set(\"format\", format);\n }\n if (quality) {\n if (Number(quality) <= 0 || Number(quality) > 100) {\n throw new Error(\"Quality has to be a positive number between 1 and 100\");\n }\n params.set(\"q\", String(quality));\n }\n if (fit !== undefined) {\n params.set(\"fit\", fit);\n }\n if (frameTime !== undefined) {\n if (isFrameable) {\n params.set(\"frame-time\", String(frameTime));\n }\n } else if (isVideo(image)) {\n return image.toString();\n }\n\n image.search = params.toString();\n return image.toString();\n}\n\nfunction isVideo(url: URL): boolean {\n const extension = getExtension(url);\n return extension === \"mp4\" || extension === \"mov\";\n}\n\nfunction canExtractFrame(url: URL): boolean {\n return isVideo(url);\n}\n\nfunction canBeResized(url: URL): boolean {\n if (!isSeadnURL(url)) {\n return false;\n }\n const extension = getExtension(url);\n switch (extension) {\n case \"png\":\n case \"jpeg\":\n case \"webp\":\n case \"avif\":\n case \"ico\":\n case \"gif\":\n case undefined:\n return true;\n default:\n return false;\n }\n}\n\nfunction getExtension(url: URL): string | undefined {\n const split = url.pathname.split(\".\");\n if (split.length <= 1) {\n return undefined;\n }\n return split[split.length - 1];\n}\n\nexport function isSeadnURL(url: URL): boolean {\n return url.hostname.endsWith(\"seadn.io\");\n}\n"],"mappings":"AAYO,SAASA,EACdC,EACA,CAAE,MAAAC,EAAO,OAAAC,EAAQ,OAAAC,EAAQ,QAAAC,EAAS,IAAAC,EAAK,UAAAC,CAAU,EACzC,CACR,GAAI,CACE,OAAON,GAAU,WACnBA,EAAQ,IAAI,IAAIA,CAAK,EAEzB,OAAQO,EAAA,CACN,OAAOP,EAAM,SAAS,CACxB,CAEA,GAAI,EAAEA,aAAiB,KACrB,OAAOA,EAGT,IAAMQ,EAAcC,EAAgBT,CAAK,EACzC,GAAI,CAACU,EAAaV,CAAK,GAAK,CAACQ,EAC3B,OAAOR,EAAM,SAAS,EAGxB,IAAMW,EAAS,IAAI,gBAUnB,GATIT,IAAW,QACbS,EAAO,IAAI,IAAK,OAAOT,CAAM,CAAC,EAE5BD,IAAU,QACZU,EAAO,IAAI,IAAK,OAAOV,CAAK,CAAC,EAE3BE,IAAW,QACbQ,EAAO,IAAI,SAAUR,CAAM,EAEzBC,EAAS,CACX,GAAI,OAAOA,CAAO,GAAK,GAAK,OAAOA,CAAO,EAAI,IAC5C,MAAM,IAAI,MAAM,uDAAuD,EAEzEO,EAAO,IAAI,IAAK,OAAOP,CAAO,CAAC,CACjC,CAIA,GAHIC,IAAQ,QACVM,EAAO,IAAI,MAAON,CAAG,EAEnBC,IAAc,OACZE,GACFG,EAAO,IAAI,aAAc,OAAOL,CAAS,CAAC,UAEnCM,EAAQZ,CAAK,EACtB,OAAOA,EAAM,SAAS,EAGxB,OAAAA,EAAM,OAASW,EAAO,SAAS,EACxBX,EAAM,SAAS,CACxB,CAEA,SAASY,EAAQC,EAAmB,CAClC,IAAMC,EAAYC,EAAaF,CAAG,EAClC,OAAOC,IAAc,OAASA,IAAc,KAC9C,CAEA,SAASL,EAAgBI,EAAmB,CAC1C,OAAOD,EAAQC,CAAG,CACpB,CAEA,SAASH,EAAaG,EAAmB,CACvC,GAAI,CAACG,EAAWH,CAAG,EACjB,MAAO,GAGT,OADkBE,EAAaF,CAAG,EACf,CACjB,IAAK,MACL,IAAK,OACL,IAAK,OACL,IAAK,OACL,IAAK,MACL,IAAK,MACL,KAAK,OACH,MAAO,GACT,QACE,MAAO,EACX,CACF,CAEA,SAASE,EAAaF,EAA8B,CAClD,IAAMI,EAAQJ,EAAI,SAAS,MAAM,GAAG,EACpC,GAAI,EAAAI,EAAM,QAAU,GAGpB,OAAOA,EAAMA,EAAM,OAAS,CAAC,CAC/B,CAEO,SAASD,EAAWH,EAAmB,CAC5C,OAAOA,EAAI,SAAS,SAAS,UAAU,CACzC","names":["optimize","image","width","height","format","quality","fit","frameTime","e","isFrameable","canExtractFrame","canBeResized","params","isVideo","url","extension","getExtension","isSeadnURL","split"]}
|
package/package.json
CHANGED
package/src/sdk.spec.ts
CHANGED
|
@@ -90,17 +90,17 @@ test.each([
|
|
|
90
90
|
],
|
|
91
91
|
[
|
|
92
92
|
"https://i2.seadn.io/bored-ape",
|
|
93
|
-
{
|
|
93
|
+
{ frameTime: 0.1 } satisfies MediaParams,
|
|
94
94
|
"https://i2.seadn.io/bored-ape",
|
|
95
95
|
],
|
|
96
96
|
[
|
|
97
97
|
"https://i2.seadn.io/bored-ape.mp4",
|
|
98
|
-
{
|
|
99
|
-
"https://i2.seadn.io/bored-ape.mp4?h=50&
|
|
98
|
+
{ frameTime: 0.1, height: 50 } satisfies MediaParams,
|
|
99
|
+
"https://i2.seadn.io/bored-ape.mp4?h=50&frame-time=0.1",
|
|
100
100
|
],
|
|
101
101
|
[
|
|
102
102
|
"https://i2.seadn.io/bored-ape.gif",
|
|
103
|
-
{
|
|
103
|
+
{ frameTime: 0.1 } satisfies MediaParams,
|
|
104
104
|
"https://i2.seadn.io/bored-ape.gif",
|
|
105
105
|
],
|
|
106
106
|
[
|
package/src/sdk.ts
CHANGED
|
@@ -7,13 +7,12 @@ export type MediaParams = {
|
|
|
7
7
|
format?: MediaFormat;
|
|
8
8
|
quality?: number | `${number}`;
|
|
9
9
|
fit?: MediaFit;
|
|
10
|
-
|
|
11
|
-
t?: number;
|
|
10
|
+
frameTime?: number;
|
|
12
11
|
};
|
|
13
12
|
|
|
14
13
|
export function optimize(
|
|
15
14
|
image: string | URL,
|
|
16
|
-
{ width, height, format, quality, fit,
|
|
15
|
+
{ width, height, format, quality, fit, frameTime }: MediaParams,
|
|
17
16
|
): string {
|
|
18
17
|
try {
|
|
19
18
|
if (typeof image === "string") {
|
|
@@ -51,9 +50,9 @@ export function optimize(
|
|
|
51
50
|
if (fit !== undefined) {
|
|
52
51
|
params.set("fit", fit);
|
|
53
52
|
}
|
|
54
|
-
if (
|
|
53
|
+
if (frameTime !== undefined) {
|
|
55
54
|
if (isFrameable) {
|
|
56
|
-
params.set("
|
|
55
|
+
params.set("frame-time", String(frameTime));
|
|
57
56
|
}
|
|
58
57
|
} else if (isVideo(image)) {
|
|
59
58
|
return image.toString();
|