next-image-transformer 0.2.9 → 0.3.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/README.md CHANGED
@@ -113,7 +113,7 @@ Returns: `(req: Request) => Promise<Response>` (compatible with Next.js Route Ha
113
113
  - **Format defaulting**: if `fmt` is omitted in the URL, it defaults to `"preserve"`.
114
114
  - **Quality defaulting**: if `q` is omitted, the handler uses `100`.
115
115
  - **Resize semantics**: if `w` and/or `h` is provided, the image is resized with:
116
- - `fit: "inside"`
116
+ - `fit: "inside"` (or the provided `fit`)
117
117
  - `withoutEnlargement: true`
118
118
  - **Auto-orient**: Sharp `rotate()` is applied to respect EXIF orientation.
119
119
  - **Caching**: responses are cached on disk; your runtime must have a writable filesystem.
@@ -145,6 +145,9 @@ The transform URL uses these query params:
145
145
  - 32-bit integer
146
146
  - **`h`**: `number` (optional)
147
147
  - 32-bit integer
148
+ - **`fit`**: `"cover" | "contain" | "fill" | "inside" | "outside"` (optional)
149
+ - Only used when resizing (`w` and/or `h` is provided)
150
+ - **Default (when decoding)**: `"inside"`
148
151
  - **`q`**: `number` (optional)
149
152
  - Integer in `[0..100]`
150
153
  - **Default (when transforming)**: `100`
@@ -4,6 +4,13 @@ export declare const createImageUrlBuilder: ({ apiRouteUrl, }: {
4
4
  }) => z.ZodCodec<z.ZodURL, z.ZodObject<{
5
5
  w: z.ZodOptional<z.ZodInt32>;
6
6
  h: z.ZodOptional<z.ZodInt32>;
7
+ fit: z.ZodOptional<z.ZodEnum<{
8
+ cover: "cover";
9
+ contain: "contain";
10
+ fill: "fill";
11
+ inside: "inside";
12
+ outside: "outside";
13
+ }>>;
7
14
  fmt: z.ZodEnum<{
8
15
  preserve: "preserve";
9
16
  webp: "webp";
@@ -120,7 +120,7 @@ function k(e, t, i) {
120
120
  function Id(e) {
121
121
  return Object.create(Object.getPrototypeOf(e), Object.getOwnPropertyDescriptors(e));
122
122
  }
123
- function Y(e, t, i) {
123
+ function H(e, t, i) {
124
124
  Object.defineProperty(e, t, {
125
125
  value: i,
126
126
  writable: !0,
@@ -220,7 +220,7 @@ const Od = (e) => {
220
220
  throw new Error(`Unknown data type: ${t}`);
221
221
  }
222
222
  }, en = /* @__PURE__ */ new Set(["string", "number", "symbol"]), Ii = /* @__PURE__ */ new Set(["string", "number", "bigint", "boolean", "symbol", "undefined"]);
223
- function G(e) {
223
+ function W(e) {
224
224
  return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
225
225
  }
226
226
  function F(e, t, i) {
@@ -294,7 +294,7 @@ function ji(e, t) {
294
294
  throw new Error(`Unrecognized key: "${c}"`);
295
295
  t[c] && (a[c] = i.shape[c]);
296
296
  }
297
- return Y(this, "shape", a), a;
297
+ return H(this, "shape", a), a;
298
298
  },
299
299
  checks: []
300
300
  });
@@ -312,7 +312,7 @@ function Ui(e, t) {
312
312
  throw new Error(`Unrecognized key: "${c}"`);
313
313
  t[c] && delete a[c];
314
314
  }
315
- return Y(this, "shape", a), a;
315
+ return H(this, "shape", a), a;
316
316
  },
317
317
  checks: []
318
318
  });
@@ -331,7 +331,7 @@ function Oi(e, t) {
331
331
  const n = V(e._zod.def, {
332
332
  get shape() {
333
333
  const r = { ...e._zod.def.shape, ...t };
334
- return Y(this, "shape", r), r;
334
+ return H(this, "shape", r), r;
335
335
  }
336
336
  });
337
337
  return F(e, n);
@@ -342,7 +342,7 @@ function Di(e, t) {
342
342
  const i = V(e._zod.def, {
343
343
  get shape() {
344
344
  const o = { ...e._zod.def.shape, ...t };
345
- return Y(this, "shape", o), o;
345
+ return H(this, "shape", o), o;
346
346
  }
347
347
  });
348
348
  return F(e, i);
@@ -351,7 +351,7 @@ function Ni(e, t) {
351
351
  const i = V(e._zod.def, {
352
352
  get shape() {
353
353
  const o = { ...e._zod.def.shape, ...t._zod.def.shape };
354
- return Y(this, "shape", o), o;
354
+ return H(this, "shape", o), o;
355
355
  },
356
356
  get catchall() {
357
357
  return t._zod.def.catchall;
@@ -383,7 +383,7 @@ function Pi(e, t, i) {
383
383
  type: "optional",
384
384
  innerType: c[u]
385
385
  }) : c[u];
386
- return Y(this, "shape", l), l;
386
+ return H(this, "shape", l), l;
387
387
  },
388
388
  checks: []
389
389
  });
@@ -408,7 +408,7 @@ function Zi(e, t, i) {
408
408
  type: "nonoptional",
409
409
  innerType: n[a]
410
410
  });
411
- return Y(this, "shape", r), r;
411
+ return H(this, "shape", r), r;
412
412
  }
413
413
  });
414
414
  return F(t, o);
@@ -520,7 +520,7 @@ const Ai = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
520
520
  assertIs: yd,
521
521
  assertNever: kd,
522
522
  assertNotEqual: bd,
523
- assignProp: Y,
523
+ assignProp: H,
524
524
  base64ToUint8Array: Ti,
525
525
  base64urlToUint8Array: Pd,
526
526
  cached: Se,
@@ -532,7 +532,7 @@ const Ai = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
532
532
  createTransparentProxy: Dd,
533
533
  defineLazy: k,
534
534
  esc: et,
535
- escapeRegex: G,
535
+ escapeRegex: W,
536
536
  extend: Oi,
537
537
  finalizeIssue: R,
538
538
  floatSafeRemainder: yi,
@@ -698,7 +698,7 @@ function eo() {
698
698
  return new RegExp(es, "u");
699
699
  }
700
700
  const no = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/, to = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/, ro = (e) => {
701
- const t = G(e ?? ":");
701
+ const t = W(e ?? ":");
702
702
  return new RegExp(`^(?:[0-9A-F]{2}${t}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${t}){5}[0-9a-f]{2}$`);
703
703
  }, io = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/, oo = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/, ao = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/, _t = /^[A-Za-z0-9_-]*$/, co = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/, uo = /^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/, lo = /^\+[1-9]\d{6,14}$/, so = "(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))", mo = /* @__PURE__ */ new RegExp(`^${so}$`);
704
704
  function fo(e) {
@@ -1095,7 +1095,7 @@ const ns = /^[0-9a-fA-F]{32}$/, ts = /* @__PURE__ */ Oe(22, "=="), rs = /* @__PU
1095
1095
  t.pattern ?? (t.pattern = zo), Ne.init(e, t);
1096
1096
  }), Lo = /* @__PURE__ */ d("$ZodCheckIncludes", (e, t) => {
1097
1097
  j.init(e, t);
1098
- const i = G(t.includes), o = new RegExp(typeof t.position == "number" ? `^.{${t.position}}${i}` : i);
1098
+ const i = W(t.includes), o = new RegExp(typeof t.position == "number" ? `^.{${t.position}}${i}` : i);
1099
1099
  t.pattern = o, e._zod.onattach.push((n) => {
1100
1100
  const r = n._zod.bag;
1101
1101
  r.patterns ?? (r.patterns = /* @__PURE__ */ new Set()), r.patterns.add(o);
@@ -1112,7 +1112,7 @@ const ns = /^[0-9a-fA-F]{32}$/, ts = /* @__PURE__ */ Oe(22, "=="), rs = /* @__PU
1112
1112
  };
1113
1113
  }), Ro = /* @__PURE__ */ d("$ZodCheckStartsWith", (e, t) => {
1114
1114
  j.init(e, t);
1115
- const i = new RegExp(`^${G(t.prefix)}.*`);
1115
+ const i = new RegExp(`^${W(t.prefix)}.*`);
1116
1116
  t.pattern ?? (t.pattern = i), e._zod.onattach.push((o) => {
1117
1117
  const n = o._zod.bag;
1118
1118
  n.patterns ?? (n.patterns = /* @__PURE__ */ new Set()), n.patterns.add(i);
@@ -1129,7 +1129,7 @@ const ns = /^[0-9a-fA-F]{32}$/, ts = /* @__PURE__ */ Oe(22, "=="), rs = /* @__PU
1129
1129
  };
1130
1130
  }), Fo = /* @__PURE__ */ d("$ZodCheckEndsWith", (e, t) => {
1131
1131
  j.init(e, t);
1132
- const i = new RegExp(`.*${G(t.suffix)}$`);
1132
+ const i = new RegExp(`.*${W(t.suffix)}$`);
1133
1133
  t.pattern ?? (t.pattern = i), e._zod.onattach.push((o) => {
1134
1134
  const n = o._zod.bag;
1135
1135
  n.patterns ?? (n.patterns = /* @__PURE__ */ new Set()), n.patterns.add(i);
@@ -2160,7 +2160,7 @@ function ci(e, t) {
2160
2160
  const Fa = /* @__PURE__ */ d("$ZodEnum", (e, t) => {
2161
2161
  b.init(e, t);
2162
2162
  const i = at(t.entries), o = new Set(i);
2163
- e._zod.values = o, e._zod.pattern = new RegExp(`^(${i.filter((n) => en.has(typeof n)).map((n) => typeof n == "string" ? G(n) : n.toString()).join("|")})$`), e._zod.parse = (n, r) => {
2163
+ e._zod.values = o, e._zod.pattern = new RegExp(`^(${i.filter((n) => en.has(typeof n)).map((n) => typeof n == "string" ? W(n) : n.toString()).join("|")})$`), e._zod.parse = (n, r) => {
2164
2164
  const a = n.value;
2165
2165
  return o.has(a) || n.issues.push({
2166
2166
  code: "invalid_value",
@@ -2173,7 +2173,7 @@ const Fa = /* @__PURE__ */ d("$ZodEnum", (e, t) => {
2173
2173
  if (b.init(e, t), t.values.length === 0)
2174
2174
  throw new Error("Cannot create literal schema with no valid values");
2175
2175
  const i = new Set(t.values);
2176
- e._zod.values = i, e._zod.pattern = new RegExp(`^(${t.values.map((o) => typeof o == "string" ? G(o) : o ? G(o.toString()) : String(o)).join("|")})$`), e._zod.parse = (o, n) => {
2176
+ e._zod.values = i, e._zod.pattern = new RegExp(`^(${t.values.map((o) => typeof o == "string" ? W(o) : o ? W(o.toString()) : String(o)).join("|")})$`), e._zod.parse = (o, n) => {
2177
2177
  const r = o.value;
2178
2178
  return i.has(r) || o.issues.push({
2179
2179
  code: "invalid_value",
@@ -2352,7 +2352,7 @@ const ec = /* @__PURE__ */ d("$ZodTemplateLiteral", (e, t) => {
2352
2352
  const r = n.startsWith("^") ? 1 : 0, a = n.endsWith("$") ? n.length - 1 : n.length;
2353
2353
  i.push(n.slice(r, a));
2354
2354
  } else if (o === null || Ii.has(typeof o))
2355
- i.push(G(`${o}`));
2355
+ i.push(W(`${o}`));
2356
2356
  else
2357
2357
  throw new Error(`Invalid template literal part: ${o}`);
2358
2358
  e._zod.pattern = new RegExp(`^${i.join("")}$`), e._zod.parse = (o, n) => typeof o.value != "string" ? (o.issues.push({
@@ -7268,7 +7268,7 @@ function Cc(e, t) {
7268
7268
  });
7269
7269
  }
7270
7270
  // @__NO_SIDE_EFFECTS__
7271
- function B(e, t) {
7271
+ function q(e, t) {
7272
7272
  return new kt({
7273
7273
  check: "less_than",
7274
7274
  ...f(t),
@@ -7286,7 +7286,7 @@ function L(e, t) {
7286
7286
  });
7287
7287
  }
7288
7288
  // @__NO_SIDE_EFFECTS__
7289
- function q(e, t) {
7289
+ function X(e, t) {
7290
7290
  return new zt({
7291
7291
  check: "greater_than",
7292
7292
  ...f(t),
@@ -7305,11 +7305,11 @@ function Z(e, t) {
7305
7305
  }
7306
7306
  // @__NO_SIDE_EFFECTS__
7307
7307
  function Ht(e) {
7308
- return /* @__PURE__ */ q(0, e);
7308
+ return /* @__PURE__ */ X(0, e);
7309
7309
  }
7310
7310
  // @__NO_SIDE_EFFECTS__
7311
7311
  function Qt(e) {
7312
- return /* @__PURE__ */ B(0, e);
7312
+ return /* @__PURE__ */ q(0, e);
7313
7313
  }
7314
7314
  // @__NO_SIDE_EFFECTS__
7315
7315
  function er(e) {
@@ -7336,7 +7336,7 @@ function ge(e, t) {
7336
7336
  });
7337
7337
  }
7338
7338
  // @__NO_SIDE_EFFECTS__
7339
- function X(e, t) {
7339
+ function Y(e, t) {
7340
7340
  return new Oo({
7341
7341
  check: "min_size",
7342
7342
  ...f(t),
@@ -7445,7 +7445,7 @@ function bn(e, t) {
7445
7445
  });
7446
7446
  }
7447
7447
  // @__NO_SIDE_EFFECTS__
7448
- function W(e) {
7448
+ function B(e) {
7449
7449
  return new Mo({
7450
7450
  check: "overwrite",
7451
7451
  tx: e
@@ -7453,23 +7453,23 @@ function W(e) {
7453
7453
  }
7454
7454
  // @__NO_SIDE_EFFECTS__
7455
7455
  function yn(e) {
7456
- return /* @__PURE__ */ W((t) => t.normalize(e));
7456
+ return /* @__PURE__ */ B((t) => t.normalize(e));
7457
7457
  }
7458
7458
  // @__NO_SIDE_EFFECTS__
7459
7459
  function kn() {
7460
- return /* @__PURE__ */ W((e) => e.trim());
7460
+ return /* @__PURE__ */ B((e) => e.trim());
7461
7461
  }
7462
7462
  // @__NO_SIDE_EFFECTS__
7463
7463
  function zn() {
7464
- return /* @__PURE__ */ W((e) => e.toLowerCase());
7464
+ return /* @__PURE__ */ B((e) => e.toLowerCase());
7465
7465
  }
7466
7466
  // @__NO_SIDE_EFFECTS__
7467
7467
  function In() {
7468
- return /* @__PURE__ */ W((e) => e.toUpperCase());
7468
+ return /* @__PURE__ */ B((e) => e.toUpperCase());
7469
7469
  }
7470
7470
  // @__NO_SIDE_EFFECTS__
7471
7471
  function Sn() {
7472
- return /* @__PURE__ */ W((e) => ki(e));
7472
+ return /* @__PURE__ */ B((e) => ki(e));
7473
7473
  }
7474
7474
  // @__NO_SIDE_EFFECTS__
7475
7475
  function Mc(e, t, i) {
@@ -8511,7 +8511,7 @@ const xf = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
8511
8511
  _file: Kc,
8512
8512
  _float32: zc,
8513
8513
  _float64: Ic,
8514
- _gt: q,
8514
+ _gt: X,
8515
8515
  _gte: Z,
8516
8516
  _guid: tn,
8517
8517
  _includes: $n,
@@ -8531,7 +8531,7 @@ const xf = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
8531
8531
  _length: Ee,
8532
8532
  _literal: mf,
8533
8533
  _lowercase: vn,
8534
- _lt: B,
8534
+ _lt: q,
8535
8535
  _lte: L,
8536
8536
  _mac: pc,
8537
8537
  _map: uf,
@@ -8541,7 +8541,7 @@ const xf = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
8541
8541
  _mime: bn,
8542
8542
  _min: Z,
8543
8543
  _minLength: te,
8544
- _minSize: X,
8544
+ _minSize: Y,
8545
8545
  _multipleOf: se,
8546
8546
  _nan: Cc,
8547
8547
  _nanoid: Lt,
@@ -8556,7 +8556,7 @@ const xf = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
8556
8556
  _nullable: vf,
8557
8557
  _number: bc,
8558
8558
  _optional: pf,
8559
- _overwrite: W,
8559
+ _overwrite: B,
8560
8560
  _parse: we,
8561
8561
  _parseAsync: xe,
8562
8562
  _pipe: bf,
@@ -8645,24 +8645,24 @@ const xf = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
8645
8645
  }, Symbol.toStringTag, { value: "Module" })), Uf = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
8646
8646
  __proto__: null,
8647
8647
  endsWith: _n,
8648
- gt: q,
8648
+ gt: X,
8649
8649
  gte: Z,
8650
8650
  includes: $n,
8651
8651
  length: Ee,
8652
8652
  lowercase: vn,
8653
- lt: B,
8653
+ lt: q,
8654
8654
  lte: L,
8655
8655
  maxLength: Te,
8656
8656
  maxSize: ge,
8657
8657
  mime: bn,
8658
8658
  minLength: te,
8659
- minSize: X,
8659
+ minSize: Y,
8660
8660
  multipleOf: se,
8661
8661
  negative: Qt,
8662
8662
  nonnegative: nr,
8663
8663
  nonpositive: er,
8664
8664
  normalize: yn,
8665
- overwrite: W,
8665
+ overwrite: B,
8666
8666
  positive: Ht,
8667
8667
  property: tr,
8668
8668
  regex: pn,
@@ -8750,7 +8750,7 @@ const Ju = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
8750
8750
  ]
8751
8751
  }), {
8752
8752
  parent: !0
8753
- }), e.with = e.check, e.clone = (i, o) => F(e, i, o), e.brand = () => e, e.register = ((i, o) => (i.add(e, o), e)), e.parse = (i, o) => Mu(e, i, o, { callee: e.parse }), e.safeParse = (i, o) => Vu(e, i, o), e.parseAsync = async (i, o) => Ku(e, i, o, { callee: e.parseAsync }), e.safeParseAsync = async (i, o) => Gu(e, i, o), e.spa = e.safeParseAsync, e.encode = (i, o) => Wu(e, i, o), e.decode = (i, o) => Bu(e, i, o), e.encodeAsync = async (i, o) => qu(e, i, o), e.decodeAsync = async (i, o) => Xu(e, i, o), e.safeEncode = (i, o) => Yu(e, i, o), e.safeDecode = (i, o) => Hu(e, i, o), e.safeEncodeAsync = async (i, o) => Qu(e, i, o), e.safeDecodeAsync = async (i, o) => el(e, i, o), e.refine = (i, o) => e.check(Hr(i, o)), e.superRefine = (i) => e.check(Qr(i)), e.overwrite = (i) => e.check(/* @__PURE__ */ W(i)), e.optional = () => ke(e), e.exactOptional = () => Zr(e), e.nullable = () => ze(e), e.nullish = () => ke(ze(e)), e.nonoptional = (i) => Fr(e, i), e.array = () => Me(e), e.or = (i) => Gn([e, i]), e.and = (i) => Ir(e, i), e.transform = (i) => Ie(e, Bn(i)), e.default = (i) => Ar(e, i), e.prefault = (i) => Rr(e, i), e.catch = (i) => Mr(e, i), e.pipe = (i) => Ie(e, i), e.readonly = () => Gr(e), e.describe = (i) => {
8753
+ }), e.with = e.check, e.clone = (i, o) => F(e, i, o), e.brand = () => e, e.register = ((i, o) => (i.add(e, o), e)), e.parse = (i, o) => Mu(e, i, o, { callee: e.parse }), e.safeParse = (i, o) => Vu(e, i, o), e.parseAsync = async (i, o) => Ku(e, i, o, { callee: e.parseAsync }), e.safeParseAsync = async (i, o) => Gu(e, i, o), e.spa = e.safeParseAsync, e.encode = (i, o) => Wu(e, i, o), e.decode = (i, o) => Bu(e, i, o), e.encodeAsync = async (i, o) => qu(e, i, o), e.decodeAsync = async (i, o) => Xu(e, i, o), e.safeEncode = (i, o) => Yu(e, i, o), e.safeDecode = (i, o) => Hu(e, i, o), e.safeEncodeAsync = async (i, o) => Qu(e, i, o), e.safeDecodeAsync = async (i, o) => el(e, i, o), e.refine = (i, o) => e.check(Hr(i, o)), e.superRefine = (i) => e.check(Qr(i)), e.overwrite = (i) => e.check(/* @__PURE__ */ B(i)), e.optional = () => ke(e), e.exactOptional = () => Zr(e), e.nullable = () => ze(e), e.nullish = () => ke(ze(e)), e.nonoptional = (i) => Fr(e, i), e.array = () => Me(e), e.or = (i) => Gn([e, i]), e.and = (i) => Ir(e, i), e.transform = (i) => Ie(e, Bn(i)), e.default = (i) => Ar(e, i), e.prefault = (i) => Rr(e, i), e.catch = (i) => Mr(e, i), e.pipe = (i) => Ie(e, i), e.readonly = () => Gr(e), e.describe = (i) => {
8754
8754
  const o = e.clone();
8755
8755
  return A.add(o, { description: i }), o;
8756
8756
  }, Object.defineProperty(e, "description", {
@@ -8930,7 +8930,7 @@ function jl(e, t) {
8930
8930
  return /* @__PURE__ */ Ae($e, o, n, t);
8931
8931
  }
8932
8932
  const Fe = /* @__PURE__ */ d("ZodNumber", (e, t) => {
8933
- St.init(e, t), y.init(e, t), e._zod.processJSONSchema = (o, n, r) => eu(e, o, n), e.gt = (o, n) => e.check(/* @__PURE__ */ q(o, n)), e.gte = (o, n) => e.check(/* @__PURE__ */ Z(o, n)), e.min = (o, n) => e.check(/* @__PURE__ */ Z(o, n)), e.lt = (o, n) => e.check(/* @__PURE__ */ B(o, n)), e.lte = (o, n) => e.check(/* @__PURE__ */ L(o, n)), e.max = (o, n) => e.check(/* @__PURE__ */ L(o, n)), e.int = (o) => e.check(on(o)), e.safe = (o) => e.check(on(o)), e.positive = (o) => e.check(/* @__PURE__ */ q(0, o)), e.nonnegative = (o) => e.check(/* @__PURE__ */ Z(0, o)), e.negative = (o) => e.check(/* @__PURE__ */ B(0, o)), e.nonpositive = (o) => e.check(/* @__PURE__ */ L(0, o)), e.multipleOf = (o, n) => e.check(/* @__PURE__ */ se(o, n)), e.step = (o, n) => e.check(/* @__PURE__ */ se(o, n)), e.finite = () => e;
8933
+ St.init(e, t), y.init(e, t), e._zod.processJSONSchema = (o, n, r) => eu(e, o, n), e.gt = (o, n) => e.check(/* @__PURE__ */ X(o, n)), e.gte = (o, n) => e.check(/* @__PURE__ */ Z(o, n)), e.min = (o, n) => e.check(/* @__PURE__ */ Z(o, n)), e.lt = (o, n) => e.check(/* @__PURE__ */ q(o, n)), e.lte = (o, n) => e.check(/* @__PURE__ */ L(o, n)), e.max = (o, n) => e.check(/* @__PURE__ */ L(o, n)), e.int = (o) => e.check(on(o)), e.safe = (o) => e.check(on(o)), e.positive = (o) => e.check(/* @__PURE__ */ X(0, o)), e.nonnegative = (o) => e.check(/* @__PURE__ */ Z(0, o)), e.negative = (o) => e.check(/* @__PURE__ */ q(0, o)), e.nonpositive = (o) => e.check(/* @__PURE__ */ L(0, o)), e.multipleOf = (o, n) => e.check(/* @__PURE__ */ se(o, n)), e.step = (o, n) => e.check(/* @__PURE__ */ se(o, n)), e.finite = () => e;
8934
8934
  const i = e._zod.bag;
8935
8935
  e.minValue = Math.max(i.minimum ?? Number.NEGATIVE_INFINITY, i.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null, e.maxValue = Math.min(i.maximum ?? Number.POSITIVE_INFINITY, i.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null, e.isInt = (i.format ?? "").includes("int") || Number.isSafeInteger(i.multipleOf ?? 0.5), e.isFinite = !0, e.format = i.format ?? null;
8936
8936
  });
@@ -8962,7 +8962,7 @@ function sr(e) {
8962
8962
  return /* @__PURE__ */ xc(Je, e);
8963
8963
  }
8964
8964
  const Ce = /* @__PURE__ */ d("ZodBigInt", (e, t) => {
8965
- xt.init(e, t), y.init(e, t), e._zod.processJSONSchema = (o, n, r) => tu(e, o), e.gte = (o, n) => e.check(/* @__PURE__ */ Z(o, n)), e.min = (o, n) => e.check(/* @__PURE__ */ Z(o, n)), e.gt = (o, n) => e.check(/* @__PURE__ */ q(o, n)), e.gte = (o, n) => e.check(/* @__PURE__ */ Z(o, n)), e.min = (o, n) => e.check(/* @__PURE__ */ Z(o, n)), e.lt = (o, n) => e.check(/* @__PURE__ */ B(o, n)), e.lte = (o, n) => e.check(/* @__PURE__ */ L(o, n)), e.max = (o, n) => e.check(/* @__PURE__ */ L(o, n)), e.positive = (o) => e.check(/* @__PURE__ */ q(BigInt(0), o)), e.negative = (o) => e.check(/* @__PURE__ */ B(BigInt(0), o)), e.nonpositive = (o) => e.check(/* @__PURE__ */ L(BigInt(0), o)), e.nonnegative = (o) => e.check(/* @__PURE__ */ Z(BigInt(0), o)), e.multipleOf = (o, n) => e.check(/* @__PURE__ */ se(o, n));
8965
+ xt.init(e, t), y.init(e, t), e._zod.processJSONSchema = (o, n, r) => tu(e, o), e.gte = (o, n) => e.check(/* @__PURE__ */ Z(o, n)), e.min = (o, n) => e.check(/* @__PURE__ */ Z(o, n)), e.gt = (o, n) => e.check(/* @__PURE__ */ X(o, n)), e.gte = (o, n) => e.check(/* @__PURE__ */ Z(o, n)), e.min = (o, n) => e.check(/* @__PURE__ */ Z(o, n)), e.lt = (o, n) => e.check(/* @__PURE__ */ q(o, n)), e.lte = (o, n) => e.check(/* @__PURE__ */ L(o, n)), e.max = (o, n) => e.check(/* @__PURE__ */ L(o, n)), e.positive = (o) => e.check(/* @__PURE__ */ X(BigInt(0), o)), e.negative = (o) => e.check(/* @__PURE__ */ q(BigInt(0), o)), e.nonpositive = (o) => e.check(/* @__PURE__ */ L(BigInt(0), o)), e.nonnegative = (o) => e.check(/* @__PURE__ */ Z(BigInt(0), o)), e.multipleOf = (o, n) => e.check(/* @__PURE__ */ se(o, n));
8966
8966
  const i = e._zod.bag;
8967
8967
  e.minValue = i.minimum ?? null, e.maxValue = i.maximum ?? null, e.format = i.format ?? null;
8968
8968
  });
@@ -9152,7 +9152,7 @@ function Bl(e, t, i) {
9152
9152
  });
9153
9153
  }
9154
9154
  const jr = /* @__PURE__ */ d("ZodMap", (e, t) => {
9155
- La.init(e, t), y.init(e, t), e._zod.processJSONSchema = (i, o, n) => bu(e, i), e.keyType = t.keyType, e.valueType = t.valueType, e.min = (...i) => e.check(/* @__PURE__ */ X(...i)), e.nonempty = (i) => e.check(/* @__PURE__ */ X(1, i)), e.max = (...i) => e.check(/* @__PURE__ */ ge(...i)), e.size = (...i) => e.check(/* @__PURE__ */ Ze(...i));
9155
+ La.init(e, t), y.init(e, t), e._zod.processJSONSchema = (i, o, n) => bu(e, i), e.keyType = t.keyType, e.valueType = t.valueType, e.min = (...i) => e.check(/* @__PURE__ */ Y(...i)), e.nonempty = (i) => e.check(/* @__PURE__ */ Y(1, i)), e.max = (...i) => e.check(/* @__PURE__ */ ge(...i)), e.size = (...i) => e.check(/* @__PURE__ */ Ze(...i));
9156
9156
  });
9157
9157
  function ql(e, t, i) {
9158
9158
  return new jr({
@@ -9163,7 +9163,7 @@ function ql(e, t, i) {
9163
9163
  });
9164
9164
  }
9165
9165
  const Ur = /* @__PURE__ */ d("ZodSet", (e, t) => {
9166
- Ra.init(e, t), y.init(e, t), e._zod.processJSONSchema = (i, o, n) => yu(e, i), e.min = (...i) => e.check(/* @__PURE__ */ X(...i)), e.nonempty = (i) => e.check(/* @__PURE__ */ X(1, i)), e.max = (...i) => e.check(/* @__PURE__ */ ge(...i)), e.size = (...i) => e.check(/* @__PURE__ */ Ze(...i));
9166
+ Ra.init(e, t), y.init(e, t), e._zod.processJSONSchema = (i, o, n) => yu(e, i), e.min = (...i) => e.check(/* @__PURE__ */ Y(...i)), e.nonempty = (i) => e.check(/* @__PURE__ */ Y(1, i)), e.max = (...i) => e.check(/* @__PURE__ */ ge(...i)), e.size = (...i) => e.check(/* @__PURE__ */ Ze(...i));
9167
9167
  });
9168
9168
  function Xl(e, t) {
9169
9169
  return new Ur({
@@ -9235,7 +9235,7 @@ function Hl(e, t) {
9235
9235
  });
9236
9236
  }
9237
9237
  const Dr = /* @__PURE__ */ d("ZodFile", (e, t) => {
9238
- Ca.init(e, t), y.init(e, t), e._zod.processJSONSchema = (i, o, n) => vu(e, i, o), e.min = (i, o) => e.check(/* @__PURE__ */ X(i, o)), e.max = (i, o) => e.check(/* @__PURE__ */ ge(i, o)), e.mime = (i, o) => e.check(/* @__PURE__ */ bn(Array.isArray(i) ? i : [i], o));
9238
+ Ca.init(e, t), y.init(e, t), e._zod.processJSONSchema = (i, o, n) => vu(e, i, o), e.min = (i, o) => e.check(/* @__PURE__ */ Y(i, o)), e.max = (i, o) => e.check(/* @__PURE__ */ ge(i, o)), e.mime = (i, o) => e.check(/* @__PURE__ */ bn(Array.isArray(i) ? i : [i], o));
9239
9239
  });
9240
9240
  function Ql(e) {
9241
9241
  return /* @__PURE__ */ Kc(Dr, e);
@@ -9779,7 +9779,7 @@ function pd(e, t) {
9779
9779
  return t.refs.get(n);
9780
9780
  });
9781
9781
  t.processing.add(n);
9782
- const r = Af(n, t), a = U(r, t);
9782
+ const r = Af(n, t), a = O(r, t);
9783
9783
  return t.refs.set(n, a), t.processing.delete(n), a;
9784
9784
  }
9785
9785
  if (e.enum !== void 0) {
@@ -9835,11 +9835,11 @@ function pd(e, t) {
9835
9835
  case "object": {
9836
9836
  const n = {}, r = e.properties || {}, a = new Set(e.required || []);
9837
9837
  for (const [l, u] of Object.entries(r)) {
9838
- const s = U(u, t);
9838
+ const s = O(u, t);
9839
9839
  n[l] = a.has(l) ? s : s.optional();
9840
9840
  }
9841
9841
  if (e.propertyNames) {
9842
- const l = U(e.propertyNames, t), u = e.additionalProperties && typeof e.additionalProperties == "object" ? U(e.additionalProperties, t) : $.any();
9842
+ const l = O(e.propertyNames, t), u = e.additionalProperties && typeof e.additionalProperties == "object" ? O(e.additionalProperties, t) : $.any();
9843
9843
  if (Object.keys(n).length === 0) {
9844
9844
  o = $.record(l, u);
9845
9845
  break;
@@ -9851,7 +9851,7 @@ function pd(e, t) {
9851
9851
  if (e.patternProperties) {
9852
9852
  const l = e.patternProperties, u = Object.keys(l), s = [];
9853
9853
  for (const v of u) {
9854
- const g = U(l[v], t), z = $.string().regex(new RegExp(v));
9854
+ const g = O(l[v], t), z = $.string().regex(new RegExp(v));
9855
9855
  s.push($.looseRecord(z, g));
9856
9856
  }
9857
9857
  const m = [];
@@ -9868,19 +9868,19 @@ function pd(e, t) {
9868
9868
  break;
9869
9869
  }
9870
9870
  const c = $.object(n);
9871
- e.additionalProperties === !1 ? o = c.strict() : typeof e.additionalProperties == "object" ? o = c.catchall(U(e.additionalProperties, t)) : o = c.passthrough();
9871
+ e.additionalProperties === !1 ? o = c.strict() : typeof e.additionalProperties == "object" ? o = c.catchall(O(e.additionalProperties, t)) : o = c.passthrough();
9872
9872
  break;
9873
9873
  }
9874
9874
  case "array": {
9875
9875
  const n = e.prefixItems, r = e.items;
9876
9876
  if (n && Array.isArray(n)) {
9877
- const a = n.map((l) => U(l, t)), c = r && typeof r == "object" && !Array.isArray(r) ? U(r, t) : void 0;
9877
+ const a = n.map((l) => O(l, t)), c = r && typeof r == "object" && !Array.isArray(r) ? O(r, t) : void 0;
9878
9878
  c ? o = $.tuple(a).rest(c) : o = $.tuple(a), typeof e.minItems == "number" && (o = o.check($.minLength(e.minItems))), typeof e.maxItems == "number" && (o = o.check($.maxLength(e.maxItems)));
9879
9879
  } else if (Array.isArray(r)) {
9880
- const a = r.map((l) => U(l, t)), c = e.additionalItems && typeof e.additionalItems == "object" ? U(e.additionalItems, t) : void 0;
9880
+ const a = r.map((l) => O(l, t)), c = e.additionalItems && typeof e.additionalItems == "object" ? O(e.additionalItems, t) : void 0;
9881
9881
  c ? o = $.tuple(a).rest(c) : o = $.tuple(a), typeof e.minItems == "number" && (o = o.check($.minLength(e.minItems))), typeof e.maxItems == "number" && (o = o.check($.maxLength(e.maxItems)));
9882
9882
  } else if (r !== void 0) {
9883
- const a = U(r, t);
9883
+ const a = O(r, t);
9884
9884
  let c = $.array(a);
9885
9885
  typeof e.minItems == "number" && (c = c.min(e.minItems)), typeof e.maxItems == "number" && (c = c.max(e.maxItems)), o = c;
9886
9886
  } else
@@ -9892,27 +9892,27 @@ function pd(e, t) {
9892
9892
  }
9893
9893
  return e.description && (o = o.describe(e.description)), e.default !== void 0 && (o = o.default(e.default)), o;
9894
9894
  }
9895
- function U(e, t) {
9895
+ function O(e, t) {
9896
9896
  if (typeof e == "boolean")
9897
9897
  return e ? $.any() : $.never();
9898
9898
  let i = pd(e, t);
9899
9899
  const o = e.type || e.enum !== void 0 || e.const !== void 0;
9900
9900
  if (e.anyOf && Array.isArray(e.anyOf)) {
9901
- const c = e.anyOf.map((u) => U(u, t)), l = $.union(c);
9901
+ const c = e.anyOf.map((u) => O(u, t)), l = $.union(c);
9902
9902
  i = o ? $.intersection(i, l) : l;
9903
9903
  }
9904
9904
  if (e.oneOf && Array.isArray(e.oneOf)) {
9905
- const c = e.oneOf.map((u) => U(u, t)), l = $.xor(c);
9905
+ const c = e.oneOf.map((u) => O(u, t)), l = $.xor(c);
9906
9906
  i = o ? $.intersection(i, l) : l;
9907
9907
  }
9908
9908
  if (e.allOf && Array.isArray(e.allOf))
9909
9909
  if (e.allOf.length === 0)
9910
9910
  i = o ? i : $.any();
9911
9911
  else {
9912
- let c = o ? i : U(e.allOf[0], t);
9912
+ let c = o ? i : O(e.allOf[0], t);
9913
9913
  const l = o ? 0 : 1;
9914
9914
  for (let u = l; u < e.allOf.length; u++)
9915
- c = $.intersection(c, U(e.allOf[u], t));
9915
+ c = $.intersection(c, O(e.allOf[u], t));
9916
9916
  i = c;
9917
9917
  }
9918
9918
  e.nullable === !0 && t.version === "openapi-3.0" && (i = $.nullable(i)), e.readOnly === !0 && (i = $.readonly(i));
@@ -9937,7 +9937,7 @@ function Lf(e, t) {
9937
9937
  rootSchema: e,
9938
9938
  registry: t?.registry ?? A
9939
9939
  };
9940
- return U(e, n);
9940
+ return O(e, n);
9941
9941
  }
9942
9942
  function Rf(e) {
9943
9943
  return /* @__PURE__ */ fc(Le, e);
@@ -9963,7 +9963,7 @@ const Kf = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
9963
9963
  string: Rf
9964
9964
  }, Symbol.toStringTag, { value: "Module" }));
9965
9965
  D(oc());
9966
- const O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
9966
+ const U = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
9967
9967
  __proto__: null,
9968
9968
  $brand: bi,
9969
9969
  $input: dc,
@@ -10091,7 +10091,7 @@ const O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
10091
10091
  function: an,
10092
10092
  getErrorMap: Zf,
10093
10093
  globalRegistry: A,
10094
- gt: q,
10094
+ gt: X,
10095
10095
  gte: Z,
10096
10096
  guid: tl,
10097
10097
  hash: jl,
@@ -10118,7 +10118,7 @@ const O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
10118
10118
  looseObject: Kl,
10119
10119
  looseRecord: Bl,
10120
10120
  lowercase: vn,
10121
- lt: B,
10121
+ lt: q,
10122
10122
  lte: L,
10123
10123
  mac: $l,
10124
10124
  map: ql,
@@ -10127,7 +10127,7 @@ const O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
10127
10127
  meta: ld,
10128
10128
  mime: bn,
10129
10129
  minLength: te,
10130
- minSize: X,
10130
+ minSize: Y,
10131
10131
  multipleOf: se,
10132
10132
  nan: td,
10133
10133
  nanoid: dl,
@@ -10144,7 +10144,7 @@ const O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
10144
10144
  number: dr,
10145
10145
  object: Cl,
10146
10146
  optional: ke,
10147
- overwrite: W,
10147
+ overwrite: B,
10148
10148
  parse: Mu,
10149
10149
  parseAsync: Ku,
10150
10150
  partialRecord: Wl,
@@ -10203,38 +10203,45 @@ const O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
10203
10203
  void: Rl,
10204
10204
  xid: pl,
10205
10205
  xor: Vl
10206
- }, Symbol.toStringTag, { value: "Module" })), vd = O.object({
10207
- w: O.int32().optional(),
10208
- h: O.int32().optional(),
10209
- fmt: O.enum(["preserve", "webp", "avif"]),
10210
- q: O.int32().min(0).max(100).optional(),
10211
- source: O.string()
10212
- }), H = (e) => e != null, Qn = O.codec(
10213
- O.string().regex(O.regexes.integer),
10214
- O.int(),
10206
+ }, Symbol.toStringTag, { value: "Module" })), vd = U.object({
10207
+ w: U.int32().optional(),
10208
+ h: U.int32().optional(),
10209
+ /**
10210
+ * Resize fit mode (Sharp's `ResizeOptions["fit"]`).
10211
+ *
10212
+ * Defaults to `"inside"` when omitted.
10213
+ */
10214
+ fit: U.enum(["cover", "contain", "fill", "inside", "outside"]).optional(),
10215
+ fmt: U.enum(["preserve", "webp", "avif"]),
10216
+ q: U.int32().min(0).max(100).optional(),
10217
+ source: U.string()
10218
+ }), G = (e) => e != null, Qn = U.codec(
10219
+ U.string().regex(U.regexes.integer),
10220
+ U.int(),
10215
10221
  {
10216
10222
  decode: (e) => Number.parseInt(e, 10),
10217
10223
  encode: (e) => e.toString()
10218
10224
  }
10219
- ), hi = O.codec(
10220
- O.instanceof(URLSearchParams),
10225
+ ), hi = U.codec(
10226
+ U.instanceof(URLSearchParams),
10221
10227
  vd,
10222
10228
  {
10223
10229
  encode: (e) => {
10224
10230
  const t = new URLSearchParams();
10225
- return H(e.w) && t.set("w", String(e.w)), H(e.h) && t.set("h", String(e.h)), e.fmt !== "preserve" && t.set("fmt", e.fmt), H(e.q) && t.set("q", String(e.q)), t.set("source", e.source), t;
10231
+ return G(e.w) && t.set("w", String(e.w)), G(e.h) && t.set("h", String(e.h)), G(e.fit) && e.fit !== "inside" && t.set("fit", e.fit), e.fmt !== "preserve" && t.set("fmt", e.fmt), G(e.q) && t.set("q", String(e.q)), t.set("source", e.source), t;
10226
10232
  },
10227
10233
  decode: (e) => ({
10228
- w: H(e.get("w")) ? Qn.decode(e.get("w") ?? "") : void 0,
10229
- h: H(e.get("h")) ? Qn.decode(e.get("h") ?? "") : void 0,
10230
- fmt: H(e.get("fmt")) ? O.enum(["preserve", "webp", "avif"]).parse(e.get("fmt")) : "preserve",
10231
- q: H(e.get("q")) ? Qn.decode(e.get("q") ?? "") : void 0,
10232
- source: O.string().parse(e.get("source"))
10234
+ w: G(e.get("w")) ? Qn.decode(e.get("w") ?? "") : void 0,
10235
+ h: G(e.get("h")) ? Qn.decode(e.get("h") ?? "") : void 0,
10236
+ fit: G(e.get("fit")) ? U.enum(["cover", "contain", "fill", "inside", "outside"]).parse(e.get("fit")) : "inside",
10237
+ fmt: G(e.get("fmt")) ? U.enum(["preserve", "webp", "avif"]).parse(e.get("fmt")) : "preserve",
10238
+ q: G(e.get("q")) ? Qn.decode(e.get("q") ?? "") : void 0,
10239
+ source: U.string().parse(e.get("source"))
10233
10240
  })
10234
10241
  }
10235
10242
  ), Gf = ({
10236
10243
  apiRouteUrl: e
10237
- }) => O.codec(O.url(), vd, {
10244
+ }) => U.codec(U.url(), vd, {
10238
10245
  encode: (t) => {
10239
10246
  const i = hi.encode(t), o = new URL(e);
10240
10247
  return o.search = i.toString(), o.toString();
@@ -10248,5 +10255,5 @@ const O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
10248
10255
  });
10249
10256
  export {
10250
10257
  Gf as c,
10251
- O as z
10258
+ U as z
10252
10259
  };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { c as a } from "./index-C4FbrW_M.js";
1
+ import { c as a } from "./index-mUKn0C6P.js";
2
2
  export {
3
3
  a as createImageUrlBuilder
4
4
  };
@@ -2,6 +2,13 @@ import z from "zod";
2
2
  export declare const searchParamsToTransformConfigCodec: z.ZodCodec<z.ZodCustom<import("url").URLSearchParams, import("url").URLSearchParams>, z.ZodObject<{
3
3
  w: z.ZodOptional<z.ZodInt32>;
4
4
  h: z.ZodOptional<z.ZodInt32>;
5
+ fit: z.ZodOptional<z.ZodEnum<{
6
+ cover: "cover";
7
+ contain: "contain";
8
+ fill: "fill";
9
+ inside: "inside";
10
+ outside: "outside";
11
+ }>>;
5
12
  fmt: z.ZodEnum<{
6
13
  preserve: "preserve";
7
14
  webp: "webp";
package/dist/server.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import h from "node:path";
2
- import { z as C, c as B } from "./index-C4FbrW_M.js";
2
+ import { z as C, c as B } from "./index-mUKn0C6P.js";
3
3
  import { createHash as U } from "node:crypto";
4
4
  import m from "node:fs/promises";
5
5
  import b from "sharp";
@@ -12,11 +12,11 @@ function P({
12
12
  cacheKey: r,
13
13
  cacheDir: n
14
14
  }) {
15
- const s = r.slice(0, 2), a = r.slice(2), e = h.join(n, s);
15
+ const s = r.slice(0, 2), a = r.slice(2), t = h.join(n, s);
16
16
  return {
17
- dir: e,
18
- bodyPath: h.join(e, `${a}.bin`),
19
- metaPath: h.join(e, `${a}.json`)
17
+ dir: t,
18
+ bodyPath: h.join(t, `${a}.bin`),
19
+ metaPath: h.join(t, `${a}.json`)
20
20
  };
21
21
  }
22
22
  async function q({
@@ -25,27 +25,27 @@ async function q({
25
25
  }) {
26
26
  const { bodyPath: s, metaPath: a } = P({ cacheKey: r, cacheDir: n });
27
27
  try {
28
- const [e, u] = await Promise.all([
28
+ const [t, u] = await Promise.all([
29
29
  m.readFile(s),
30
30
  m.readFile(a, "utf8")
31
31
  ]), o = (() => {
32
32
  try {
33
- const i = JSON.parse(u), t = C.object({
33
+ const i = JSON.parse(u), e = C.object({
34
34
  contentType: C.string()
35
35
  }).loose().safeParse(i);
36
- return t.success ? t.data : null;
36
+ return e.success ? e.data : null;
37
37
  } catch {
38
38
  return null;
39
39
  }
40
40
  })();
41
- return o ? { body: new Uint8Array(e), contentType: o.contentType } : null;
42
- } catch (e) {
43
- if (e instanceof Error && "code" in e && e.code === "ENOENT")
41
+ return o ? { body: new Uint8Array(t), contentType: o.contentType } : null;
42
+ } catch (t) {
43
+ if (t instanceof Error && "code" in t && t.code === "ENOENT")
44
44
  return null;
45
- throw e;
45
+ throw t;
46
46
  }
47
47
  }
48
- function x(r, n, s, a, e, u, o, i, t) {
48
+ function x(r, n, s, a, t, u, o, i, e) {
49
49
  switch (arguments.length) {
50
50
  case 1:
51
51
  return r;
@@ -56,15 +56,15 @@ function x(r, n, s, a, e, u, o, i, t) {
56
56
  case 4:
57
57
  return a(s(n(r)));
58
58
  case 5:
59
- return e(a(s(n(r))));
59
+ return t(a(s(n(r))));
60
60
  case 6:
61
- return u(e(a(s(n(r)))));
61
+ return u(t(a(s(n(r)))));
62
62
  case 7:
63
- return o(u(e(a(s(n(r))))));
63
+ return o(u(t(a(s(n(r))))));
64
64
  case 8:
65
- return i(o(u(e(a(s(n(r)))))));
65
+ return i(o(u(t(a(s(n(r)))))));
66
66
  case 9:
67
- return t(i(o(u(e(a(s(n(r))))))));
67
+ return e(i(o(u(t(a(s(n(r))))))));
68
68
  default: {
69
69
  for (var c = arguments[0], f = 1; f < arguments.length; f++)
70
70
  c = arguments[f](c);
@@ -78,17 +78,17 @@ async function A({
78
78
  meta: s,
79
79
  cacheDir: a
80
80
  }) {
81
- const { dir: e, bodyPath: u, metaPath: o } = P({
81
+ const { dir: t, bodyPath: u, metaPath: o } = P({
82
82
  cacheKey: r,
83
83
  cacheDir: a
84
84
  });
85
- await m.mkdir(e, { recursive: !0 });
86
- const i = `${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`, t = `${u}.${i}.tmp`, c = `${o}.${i}.tmp`;
85
+ await m.mkdir(t, { recursive: !0 });
86
+ const i = `${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`, e = `${u}.${i}.tmp`, c = `${o}.${i}.tmp`;
87
87
  await Promise.all([
88
- m.writeFile(t, n),
88
+ m.writeFile(e, n),
89
89
  m.writeFile(c, JSON.stringify(s), "utf8")
90
90
  ]), await Promise.all([
91
- m.rename(t, u),
91
+ m.rename(e, u),
92
92
  m.rename(c, o)
93
93
  ]);
94
94
  }
@@ -98,25 +98,25 @@ const O = ({
98
98
  cacheControl: s = "public, max-age=31536000, immutable",
99
99
  allowedHosts: a
100
100
  }) => {
101
- const e = B({ apiRouteUrl: r }), u = (o) => {
101
+ const t = B({ apiRouteUrl: r }), u = (o) => {
102
102
  if (!a) return !0;
103
- const i = o.hostname.toLowerCase(), t = o.host.toLowerCase();
103
+ const i = o.hostname.toLowerCase(), e = o.host.toLowerCase();
104
104
  return a.some((c) => {
105
105
  if (c instanceof RegExp)
106
- return c.test(i) || c.test(t);
106
+ return c.test(i) || c.test(e);
107
107
  const f = c.toLowerCase();
108
- return f.includes(":") ? t === f : i === f;
108
+ return f.includes(":") ? e === f : i === f;
109
109
  });
110
110
  };
111
111
  return async function(i) {
112
- const { data: t, error: c } = e.safeDecode(i.url);
112
+ const { data: e, error: c } = t.safeDecode(i.url);
113
113
  if (c)
114
114
  return new Response("Bad Request", { status: 400 });
115
- const f = e.encode(
115
+ const f = t.encode(
116
116
  // encode() accepts the decoded transform config shape; we only call this
117
117
  // after decoding has succeeded.
118
- t
119
- ), y = t.q ?? 100, g = j({ canonicalUrl: f }), d = await q({ cacheKey: g, cacheDir: n });
118
+ e
119
+ ), y = e.q ?? 100, g = j({ canonicalUrl: f }), d = await q({ cacheKey: g, cacheDir: n });
120
120
  if (d)
121
121
  return new Response(d.body, {
122
122
  headers: {
@@ -126,7 +126,7 @@ const O = ({
126
126
  });
127
127
  let l;
128
128
  try {
129
- l = new URL(t.source);
129
+ l = new URL(e.source);
130
130
  } catch {
131
131
  return new Response("Bad Request", { status: 400 });
132
132
  }
@@ -149,17 +149,17 @@ const O = ({
149
149
  /**
150
150
  * Resize
151
151
  */
152
- (p) => t.w || t.h ? p.resize({
153
- width: t.w,
154
- height: t.h,
155
- fit: "inside",
152
+ (p) => e.w || e.h ? p.resize({
153
+ width: e.w,
154
+ height: e.h,
155
+ fit: e.fit ?? "inside",
156
156
  withoutEnlargement: !0
157
157
  }) : p,
158
158
  /**
159
159
  * Change format
160
160
  */
161
161
  (p) => {
162
- switch (t.fmt) {
162
+ switch (e.fmt) {
163
163
  case "preserve":
164
164
  return p;
165
165
  case "avif":
@@ -167,11 +167,11 @@ const O = ({
167
167
  case "webp":
168
168
  return p.webp({ quality: y });
169
169
  default:
170
- throw new Error(`Unreachable case: ${t.fmt}`);
170
+ throw new Error(`Unreachable case: ${e.fmt}`);
171
171
  }
172
172
  }
173
173
  ).toBuffer(), $ = new Uint8Array(R), T = (() => {
174
- switch (t.fmt) {
174
+ switch (e.fmt) {
175
175
  case "preserve":
176
176
  return w.headers.get("content-type") ?? "application/octet-stream";
177
177
  case "avif":
@@ -2,6 +2,13 @@ import z from "zod";
2
2
  export declare const transformConfigSchema: z.ZodObject<{
3
3
  w: z.ZodOptional<z.ZodInt32>;
4
4
  h: z.ZodOptional<z.ZodInt32>;
5
+ fit: z.ZodOptional<z.ZodEnum<{
6
+ cover: "cover";
7
+ contain: "contain";
8
+ fill: "fill";
9
+ inside: "inside";
10
+ outside: "outside";
11
+ }>>;
5
12
  fmt: z.ZodEnum<{
6
13
  preserve: "preserve";
7
14
  webp: "webp";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-image-transformer",
3
- "version": "0.2.9",
3
+ "version": "0.3.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {