@valbuild/shared 0.146.4 → 0.147.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.
@@ -1,6 +1,6 @@
1
- import { _ as _createForOfIteratorHelper, o as _objectSpread2, q as _arrayLikeToArray, r as _unsupportedIterableToArray, s as _typeof, t as _defineProperty, u as _toPropertyKey } from '../../dist/getSitemapTree-e65acefe.esm.js';
2
- export { D as DEFAULT_CANVAS_SELECTION, e as DEFAULT_CANVAS_SELECTION_SOFT, b as VAL_AI_SESSION_STORAGE_KEY, d as VAL_CANVAS_MESSAGE, c as VAL_CANVAS_PARAM, V as VAL_CONFIG_SESSION_STORAGE_KEY, a as VAL_THEME_SESSION_STORAGE_KEY, h as getNextAppRouterSourceFolder, m as getPageRouterSitemapTree, k as getPageRouterSourceFolder, n as getPatternFromModuleFilePath, j as getTanStackRouterSourceFolder, l as isTanStackRoutesFolder, g as isValCanvasFrame, i as isValCanvasPageMessage, f as isValCanvasStudioMessage, p as parseRoutePattern, w as withValCanvasParam } from '../../dist/getSitemapTree-e65acefe.esm.js';
3
- import { Internal, CODE_LANGUAGES, resolveSettingsModule, missingDeclaredKeys, localeOfValue, discriminatedUnionBranchOf, DEFAULT_COLOR_FORMAT, declaredKeySetOf } from '@valbuild/core';
1
+ import { _ as _createForOfIteratorHelper, q as _objectSpread2, r as _arrayLikeToArray, s as _unsupportedIterableToArray, t as _typeof, u as _defineProperty, v as _toPropertyKey } from '../../dist/getSitemapTree-c70ea145.esm.js';
2
+ export { D as DEFAULT_CANVAS_SELECTION, e as DEFAULT_CANVAS_SELECTION_SOFT, b as VAL_AI_SESSION_STORAGE_KEY, d as VAL_CANVAS_MESSAGE, c as VAL_CANVAS_PARAM, V as VAL_CONFIG_SESSION_STORAGE_KEY, a as VAL_THEME_SESSION_STORAGE_KEY, h as formatRoutePattern, j as getNextAppRouterSourceFolder, n as getPageRouterSitemapTree, l as getPageRouterSourceFolder, o as getPatternFromModuleFilePath, k as getTanStackRouterSourceFolder, m as isTanStackRoutesFolder, g as isValCanvasFrame, i as isValCanvasPageMessage, f as isValCanvasStudioMessage, p as parseRoutePattern, w as withValCanvasParam } from '../../dist/getSitemapTree-c70ea145.esm.js';
3
+ import { Internal, CODE_LANGUAGES, resolveSettingsModule, missingDeclaredKeys, localeOfValue, discriminatedUnionBranchOf, routePatternOf, matchRoutePattern, DEFAULT_COLOR_FORMAT, declaredKeySetOf } from '@valbuild/core';
4
4
  import { z } from 'zod';
5
5
  import { fromError } from 'zod-validation-error';
6
6
  import FlexSearch from 'flexsearch';
@@ -1189,6 +1189,8 @@ var SerializedDiscriminatedUnionSchema = z.lazy(function () {
1189
1189
  var SerializedEnumSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1190
1190
  type: z.literal("enum"),
1191
1191
  values: z.array(z.string()),
1192
+ locales: z.record(z.string(), z.string()).optional(),
1193
+ nullLocale: z.string().optional(),
1192
1194
  opt: z["boolean"]()
1193
1195
  }));
1194
1196
  var ImageEncodeOption = z.union([z.literal(false), z.object({
@@ -1268,6 +1270,7 @@ var SerializedRecordSchema = z.lazy(function () {
1268
1270
  render: FieldRender,
1269
1271
  type: z.literal("record"),
1270
1272
  item: SerializedSchema,
1273
+ params: z.record(z.string(), SerializedSchema).optional(),
1271
1274
  opt: z["boolean"](),
1272
1275
  // Optional gallery marker for files/images/videos
1273
1276
  mediaType: z.union([z.literal("files"), z.literal("images"), z.literal("videos")]).optional(),
@@ -1611,7 +1614,7 @@ var ValConfig = z.object({
1611
1614
  gitCommit: z.string().optional(),
1612
1615
  gitBranch: z.string().optional()
1613
1616
  });
1614
- var ValidationFixZ = z.union([z.literal("image:add-metadata"), z.literal("image:check-metadata"), z.literal("image:check-remote"), z.literal("image:upload-remote"), z.literal("image:download-remote"), z.literal("images:check-remote"), z.literal("images:upload-remote"), z.literal("file:add-metadata"), z.literal("video:add-metadata"), z.literal("video:upload-remote"), z.literal("video:download-remote"), z.literal("videos:add-metadata"), z.literal("videos:check-remote"), z.literal("videos:upload-remote"), z.literal("file:check-metadata"), z.literal("file:check-remote"), z.literal("file:upload-remote"), z.literal("file:download-remote"), z.literal("files:check-remote"), z.literal("files:upload-remote"), z.literal("keyof:check-keys"), z.literal("image:check-gallery"), z.literal("file:check-gallery"), z.literal("video:check-gallery"), z.literal("router:check-route"), z.literal("locale:check-locale"), z.literal("record:fill-keys"), z.literal("images:check-unique-folder"), z.literal("files:check-unique-folder"), z.literal("images:check-all-files"), z.literal("files:check-all-files"), z.literal("videos:check-unique-folder"), z.literal("videos:check-all-files"), z.literal("jsonValues:extract-entry"), z.literal("view:check-module")]);
1617
+ var ValidationFixZ = z.union([z.literal("image:add-metadata"), z.literal("image:check-metadata"), z.literal("image:check-remote"), z.literal("image:upload-remote"), z.literal("image:download-remote"), z.literal("images:check-remote"), z.literal("images:upload-remote"), z.literal("file:add-metadata"), z.literal("video:add-metadata"), z.literal("video:upload-remote"), z.literal("video:download-remote"), z.literal("videos:add-metadata"), z.literal("videos:check-remote"), z.literal("videos:upload-remote"), z.literal("file:check-metadata"), z.literal("file:check-remote"), z.literal("file:upload-remote"), z.literal("file:download-remote"), z.literal("files:check-remote"), z.literal("files:upload-remote"), z.literal("keyof:check-keys"), z.literal("image:check-gallery"), z.literal("file:check-gallery"), z.literal("video:check-gallery"), z.literal("router:check-route"), z.literal("locale:check-locale"), z.literal("router:check-locale-param"), z.literal("record:fill-keys"), z.literal("images:check-unique-folder"), z.literal("files:check-unique-folder"), z.literal("images:check-all-files"), z.literal("files:check-all-files"), z.literal("videos:check-unique-folder"), z.literal("videos:check-all-files"), z.literal("jsonValues:extract-entry"), z.literal("view:check-module")]);
1615
1618
  var ValidationError = z.object({
1616
1619
  message: z.string(),
1617
1620
  value: z.unknown().optional(),
@@ -3738,8 +3741,11 @@ function detailsOf(json) {
3738
3741
  }
3739
3742
  var DEFAULT_ERROR_MESSAGE = "Unknown error with unknown message from server";
3740
3743
 
3741
- var createValClient = function createValClient(host, config // We want to use this in the future
3742
- ) {
3744
+ var createValClient = function createValClient(host, config, options) {
3745
+ var _options$fetch;
3746
+ var send = (_options$fetch = options === null || options === void 0 ? void 0 : options.fetch) !== null && _options$fetch !== void 0 ? _options$fetch : function (input, init) {
3747
+ return fetch(input, init);
3748
+ };
3743
3749
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3744
3750
  var anyApi = Api;
3745
3751
  return /*#__PURE__*/function () {
@@ -3830,7 +3836,7 @@ var createValClient = function createValClient(host, config // We want to use th
3830
3836
  case 2:
3831
3837
  _context2.p = 2;
3832
3838
  _context2.n = 3;
3833
- return fetch("".concat(host).concat(fullPath), {
3839
+ return send("".concat(host).concat(fullPath), {
3834
3840
  method: method,
3835
3841
  headers: {
3836
3842
  "Content-Type": "application/json"
@@ -3964,6 +3970,29 @@ function isRetryable(error) {
3964
3970
  return false;
3965
3971
  }
3966
3972
 
3973
+ /**
3974
+ * A Val demo, as the page hands it to the Studio.
3975
+ *
3976
+ * In a demo the Studio talks to Val's own server running in the same tab
3977
+ * (`@valbuild/server/browser`) instead of to an API route, and the page that
3978
+ * starts that server is the app's (`<ValApp demo>`) while the Studio is a
3979
+ * separate bundle loaded by a script tag. A window property is how the two
3980
+ * meet, the same way `window.__VAL_MODULES__` hands the Studio the project's
3981
+ * modules. See `docs/plans/demo-mode.md`.
3982
+ */
3983
+
3984
+ /*
3985
+ * A global `var` rather than a `Window` member: this package is compiled
3986
+ * without the DOM's types, and a `var` in global scope is also a property of
3987
+ * `window` where they exist.
3988
+ */
3989
+
3990
+ /** The demo this page was started with, or null outside a demo. */
3991
+ function getValDemo() {
3992
+ var _globalThis$__VAL_DEM;
3993
+ return (_globalThis$__VAL_DEM = globalThis.__VAL_DEMO__) !== null && _globalThis$__VAL_DEM !== void 0 ? _globalThis$__VAL_DEM : null;
3994
+ }
3995
+
3967
3996
  function _arrayWithHoles(r) {
3968
3997
  if (Array.isArray(r)) return r;
3969
3998
  }
@@ -4843,7 +4872,7 @@ function declaredLocales(snapshot) {
4843
4872
  * these has to resolve all of them, and the two that leaked did so by adding a
4844
4873
  * fix here and not to a condition somewhere else.
4845
4874
  */
4846
- var SCHEMA_SOURCE_FIXES = ["keyof:check-keys", "image:check-gallery", "file:check-gallery", "video:check-gallery", "router:check-route", "locale:check-locale", "record:fill-keys"];
4875
+ var SCHEMA_SOURCE_FIXES = ["keyof:check-keys", "image:check-gallery", "file:check-gallery", "video:check-gallery", "router:check-route", "locale:check-locale", "router:check-locale-param", "record:fill-keys"];
4847
4876
 
4848
4877
  /** Whether an error is a marker only the whole project can answer. */
4849
4878
  function isSchemaSourceFixError(error) {
@@ -5033,21 +5062,51 @@ function resolveSchemaSourceFixForError(error, snapshot) {
5033
5062
  })
5034
5063
  };
5035
5064
  }
5036
- if (fixes.includes("record:fill-keys")) {
5065
+ if (fixes.includes("router:check-locale-param")) {
5037
5066
  var _value = error.value;
5038
- if (_typeof(_value) !== "object" || _value === null) {
5067
+ var _ref7 = _typeof(_value) === "object" && _value !== null ? _value : {},
5068
+ name = _ref7.name,
5069
+ segment = _ref7.segment;
5070
+ if (typeof name !== "string" || typeof segment !== "string") {
5039
5071
  return {
5040
5072
  status: "remaining",
5041
5073
  error: _objectSpread2(_objectSpread2({}, error), {}, {
5042
- message: "Expected record key validation error to have a 'value' object. Found: ".concat(_typeof(_value), ". ").concat(TYPE_ERROR_MESSAGE),
5074
+ message: "Expected route locale parameter validation error to have a 'value' with 'name' and 'segment'. ".concat(TYPE_ERROR_MESSAGE),
5043
5075
  typeError: true,
5044
5076
  fixes: undefined
5045
5077
  })
5046
5078
  };
5047
5079
  }
5048
- var _ref7 = _value,
5049
- present = _ref7.present,
5050
- declared = _ref7.declared;
5080
+ // A project that declares no languages is not translated, and a
5081
+ // `[locale]` segment there is the app's own business.
5082
+ if (declaredLocales(snapshot).length === 0) {
5083
+ return {
5084
+ status: "resolved"
5085
+ };
5086
+ }
5087
+ return {
5088
+ status: "remaining",
5089
+ error: _objectSpread2(_objectSpread2({}, error), {}, {
5090
+ message: "This route has a '".concat(name, "' segment (").concat(segment, "), but nothing says which of the project's languages it can be, so its pages are not in any language and '/xx/\u2026' validates. Give the parameter a locale schema: s.router(router, { ").concat(name, ": urlLocale, \u2026 }, item), where urlLocale is an s.enum(\u2026).locales({ \u2026 }) or s.locale(). If '").concat(name, "' is not a language here, give it a schema of its own instead, e.g. { ").concat(name, ": s.enum(\u2026) }."),
5091
+ fixes: undefined
5092
+ })
5093
+ };
5094
+ }
5095
+ if (fixes.includes("record:fill-keys")) {
5096
+ var _value2 = error.value;
5097
+ if (_typeof(_value2) !== "object" || _value2 === null) {
5098
+ return {
5099
+ status: "remaining",
5100
+ error: _objectSpread2(_objectSpread2({}, error), {}, {
5101
+ message: "Expected record key validation error to have a 'value' object. Found: ".concat(_typeof(_value2), ". ").concat(TYPE_ERROR_MESSAGE),
5102
+ typeError: true,
5103
+ fixes: undefined
5104
+ })
5105
+ };
5106
+ }
5107
+ var _ref8 = _value2,
5108
+ present = _ref8.present,
5109
+ declared = _ref8.declared;
5051
5110
  if (!Array.isArray(present)) {
5052
5111
  return {
5053
5112
  status: "remaining",
@@ -5199,7 +5258,8 @@ function resolveSchemaSourceFixes(validationErrors, snapshot) {
5199
5258
  *
5200
5259
  * THE question the whole feature turns on. A locale scope is a subtree in one
5201
5260
  * language, and three things open one: a `locale` field on an object, a record
5202
- * keyed by `s.locale()`, and a locale segment in a segmented key. Once this can
5261
+ * keyed by `s.locale()`, and a locale parameter in a router's key
5262
+ * (`s.router(router, { locale: … }, item)`, where the URL names the language). Once this can
5203
5263
  * be answered from the schema and the source alone, everything downstream falls
5204
5264
  * out of it — the Studio's locale filter, deep links, `<html lang>`, and knowing
5205
5265
  * what to translate from and into.
@@ -5228,7 +5288,79 @@ function localeAt(path, snapshot) {
5228
5288
  return null;
5229
5289
  }
5230
5290
  var segments = modulePath ? Internal.splitModulePath(modulePath) : [];
5231
- return walk(schema, source, segments, available);
5291
+ return walk(schema, source, segments, available, moduleFilePath);
5292
+ }
5293
+
5294
+ /**
5295
+ * The language a locale schema's value MEANS, or `null` if it means none of
5296
+ * the project's.
5297
+ *
5298
+ * `s.locale()` stores the tag itself. An enum with `.locales(...)` stores a
5299
+ * value that stands for one — `nb` for `nb-NO` — and, on a router parameter,
5300
+ * `null` for a URL that left the segment out, which `{ null: tag }` names.
5301
+ * Anything else is not a locale and means nothing here.
5302
+ *
5303
+ * Callers reading a FIELD pass only strings: a field that holds `null` has no
5304
+ * language, whatever its schema says about URLs.
5305
+ */
5306
+ function localeMeantBy(schema, value, available) {
5307
+ if (schema.type === "locale") {
5308
+ return value === null ? null : localeOfValue(value, available);
5309
+ }
5310
+ if (schema.type === "enum" && schema.locales !== undefined) {
5311
+ var tag = enumLocaleTag(schema, value);
5312
+ return tag === undefined ? null : localeOfValue(tag, available);
5313
+ }
5314
+ return null;
5315
+ }
5316
+
5317
+ /**
5318
+ * The tag an enum's `.locales(...)` maps a value to, as written — `null` is
5319
+ * the `{ null }` mapping — or `undefined` where it maps none.
5320
+ *
5321
+ * An own property: a plain object inherits `toString` and the rest, and an
5322
+ * enum value is allowed to be spelled like one.
5323
+ */
5324
+ function enumLocaleTag(schema, value) {
5325
+ if (value === null) {
5326
+ return schema.nullLocale;
5327
+ }
5328
+ return schema.locales !== undefined && Object.prototype.hasOwnProperty.call(schema.locales, value) ? schema.locales[value] : undefined;
5329
+ }
5330
+
5331
+ /**
5332
+ * Whether a schema is a locale: `s.locale()`, or an enum `.locales(...)` made
5333
+ * one.
5334
+ */
5335
+ function isLocaleSchema(schema) {
5336
+ return schema.type === "locale" || schema.type === "enum" && schema.locales !== undefined;
5337
+ }
5338
+
5339
+ /**
5340
+ * The language a router's key is in, where one of its route parameters is a
5341
+ * locale — `/nb/blog/hei` is `nb-NO` when `locale` maps `nb` to it.
5342
+ */
5343
+ function localeOfRouteKey(schema, moduleFilePath, key, available) {
5344
+ if (schema.params === undefined || schema.router === undefined) {
5345
+ return null;
5346
+ }
5347
+ var pattern = routePatternOf(schema.router, moduleFilePath);
5348
+ if (pattern === null) {
5349
+ return null;
5350
+ }
5351
+ var values = matchRoutePattern(key, pattern);
5352
+ if (values === null) {
5353
+ return null;
5354
+ }
5355
+ for (var _i = 0, _Object$entries = Object.entries(schema.params); _i < _Object$entries.length; _i++) {
5356
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
5357
+ name = _Object$entries$_i[0],
5358
+ param = _Object$entries$_i[1];
5359
+ if (isLocaleSchema(param) && Object.prototype.hasOwnProperty.call(values, name)) {
5360
+ return localeMeantBy(param, values[name], available);
5361
+ }
5362
+ }
5363
+ return null;
5232
5364
  }
5233
5365
 
5234
5366
  /**
@@ -5243,7 +5375,7 @@ function localeAt(path, snapshot) {
5243
5375
  * these can fire on a well-formed path; taking the innermost is what makes the
5244
5376
  * answer well-defined while a project is mid-fix.
5245
5377
  */
5246
- function walk(schema, source, segments, available) {
5378
+ function walk(schema, source, segments, available, moduleFilePath) {
5247
5379
  var entered = enter(schema, source, available);
5248
5380
  var locale = entered.locale;
5249
5381
  var currentSchema = entered.schema;
@@ -5257,14 +5389,21 @@ function walk(schema, source, segments, available) {
5257
5389
  return locale;
5258
5390
  }
5259
5391
  if (currentSchema.type === "record") {
5260
- var _currentSchema$key;
5261
- if (((_currentSchema$key = currentSchema.key) === null || _currentSchema$key === void 0 ? void 0 : _currentSchema$key.type) === "locale") {
5392
+ if (currentSchema.key !== undefined && isLocaleSchema(currentSchema.key)) {
5262
5393
  // In a locale-keyed record the KEY is the language, so the segment we
5263
- // are about to take is the answer.
5264
- var resolved = localeOfValue(segment, available);
5394
+ // are about to take is the answer — the tag itself for `s.locale()`,
5395
+ // the tag it stands for when the key is an enum with `.locales()`.
5396
+ var resolved = localeMeantBy(currentSchema.key, segment, available);
5265
5397
  if (resolved !== null) {
5266
5398
  locale = resolved;
5267
5399
  }
5400
+ } else if (currentSchema.params !== undefined) {
5401
+ // A router whose URL names the language: the key is a URL, and one of
5402
+ // its parameters is the answer.
5403
+ var _resolved = localeOfRouteKey(currentSchema, moduleFilePath, segment, available);
5404
+ if (_resolved !== null) {
5405
+ locale = _resolved;
5406
+ }
5268
5407
  }
5269
5408
  currentSchema = currentSchema.item;
5270
5409
  } else if (currentSchema.type === "array") {
@@ -5320,18 +5459,18 @@ function localeOfObjectField(schema, source, available) {
5320
5459
  if (schema.type !== "object" || !isJsonObject(source)) {
5321
5460
  return null;
5322
5461
  }
5323
- for (var _i = 0, _Object$entries = Object.entries(schema.items); _i < _Object$entries.length; _i++) {
5324
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
5325
- key = _Object$entries$_i[0],
5326
- item = _Object$entries$_i[1];
5327
- if (item.type !== "locale") {
5462
+ for (var _i2 = 0, _Object$entries2 = Object.entries(schema.items); _i2 < _Object$entries2.length; _i2++) {
5463
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
5464
+ key = _Object$entries2$_i[0],
5465
+ item = _Object$entries2$_i[1];
5466
+ if (!isLocaleSchema(item)) {
5328
5467
  continue;
5329
5468
  }
5330
5469
  var value = source[key];
5331
5470
  if (typeof value !== "string") {
5332
5471
  return null;
5333
5472
  }
5334
- return localeOfValue(value, available);
5473
+ return localeMeantBy(item, value, available);
5335
5474
  }
5336
5475
  return null;
5337
5476
  }
@@ -6220,6 +6359,7 @@ function isSkippableFixCode(fix) {
6220
6359
  case "video:check-gallery":
6221
6360
  case "router:check-route":
6222
6361
  case "locale:check-locale":
6362
+ case "router:check-locale-param":
6223
6363
  case "record:fill-keys":
6224
6364
  case "jsonValues:extract-entry":
6225
6365
  // `jsonValues:extract-entry` is an entry inlined in the `.val.ts`. The
@@ -6381,6 +6521,63 @@ function isSkippedSource(sourceMimeType, targetMimeType, needsDownscale) {
6381
6521
  return sourceMimeType === targetMimeType && !needsDownscale;
6382
6522
  }
6383
6523
 
6524
+ /**
6525
+ * The types the Studio can write with WebAssembly when the canvas cannot.
6526
+ *
6527
+ * libwebp, compiled to WebAssembly (`@jsquash/webp`, loaded by
6528
+ * `packages/ui/spa/utils/webpWasm.ts`). One entry because `encode` has one
6529
+ * `type`; a second type is a second encoder to host, not a second string here.
6530
+ */
6531
+ var WASM_ENCODED_MIME_TYPES = ["image/webp"];
6532
+
6533
+ /**
6534
+ * Whether to encode the canvas's pixels with WebAssembly, given what the
6535
+ * canvas's own encoder handed back.
6536
+ *
6537
+ * `canvas.toBlob` answers a type it cannot write with a PNG instead of an error,
6538
+ * and Safari -- the browser people take their photos in -- cannot write WebP.
6539
+ * The pixels on that canvas are already decoded, oriented and scaled, so the
6540
+ * only thing missing is the encoder, and libwebp in WebAssembly is that.
6541
+ *
6542
+ * Only then, and that is what keeps the WebAssembly lazy: a browser whose
6543
+ * canvas wrote the type is never asked to download an encoder, even when its
6544
+ * WebP then loses to the original on size -- a second encoder of the same
6545
+ * format would lose for the same reason.
6546
+ *
6547
+ * `null` -- no blob at all -- is not "cannot write this type" either. It is a
6548
+ * canvas that failed to serialize anything, under memory pressure for instance,
6549
+ * and says nothing about WebP: a Chromium tab that hits it is still a browser
6550
+ * that writes WebP, and must not start downloading an encoder because of it.
6551
+ */
6552
+ function shouldEncodeWithWasm(input) {
6553
+ return WASM_ENCODED_MIME_TYPES.includes(input.targetMimeType) && input.canvasOutputType !== null && input.canvasOutputType !== input.targetMimeType;
6554
+ }
6555
+
6556
+ /**
6557
+ * What to scale an image down to when nothing could write the type asked for:
6558
+ * the source's own format, when it is one every canvas can write.
6559
+ *
6560
+ * The second fallback, after {@link shouldEncodeWithWasm}: it is what a browser
6561
+ * whose canvas cannot write WebP gets when the WebAssembly encoder could not be
6562
+ * loaded either (offline, a blocked host, a failed instantiation). Without it,
6563
+ * `chooseEncoded` would rightly refuse the canvas's PNG and upload the original
6564
+ * -- every photo at the camera's full size, the one case `maxWidth` exists
6565
+ * for. Scaling it down as a JPEG keeps the half of `encode` this browser can do.
6566
+ *
6567
+ * Only when a downscale is needed: re-encoding a JPEG that already fits, as a
6568
+ * JPEG, is a second generation of loss for a few percent. And never into a
6569
+ * type `accept` refuses, for the reason `isMimeTypeAccepted` gives.
6570
+ */
6571
+ function fallbackMimeType(sourceMimeType, needsDownscale, accept) {
6572
+ if (!needsDownscale) {
6573
+ return null;
6574
+ }
6575
+ if (sourceMimeType !== "image/jpeg" && sourceMimeType !== "image/png") {
6576
+ return null;
6577
+ }
6578
+ return isMimeTypeAccepted(sourceMimeType, accept) ? sourceMimeType : null;
6579
+ }
6580
+
6384
6581
  /**
6385
6582
  * Whether to upload what the encoder produced, or the file that was picked.
6386
6583
  *
@@ -8570,4 +8767,4 @@ function schemaErrorsOf(schema, moduleFilePath, source) {
8570
8767
  return errors;
8571
8768
  }
8572
8769
 
8573
- export { AA_LARGE, AA_TEXT, Api, BRAND_CONTRAST_PAIRS, BinaryFileRef, CodeOptions, ColorOptions, DEFAULT_ERROR_MESSAGE, DateOptions, ENCODE_DEFAULTS, ENCODE_MIME_TYPE_OF, FileOptions, HistoricalCommit, HistoricalModule, HistoricalPatchSet, HistoryError, ImageEncodeOption, ImageOptions, JSONValue, JSON_ENTRIES_BATCH_MAX, ModuleComparison, NEVER_ENCODED, ParentRef$1 as ParentRef, Patch, PatchBlock, PatchId, PatchJSON, PatchSets, PlanRefusalError, PublishProtocolError, RAMP_STEPS, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, RestoreVerdict, RichTextOptions, SCHEMA_SOURCE_FIXES, SerializedArraySchema, SerializedBooleanSchema, SerializedCodeSchema, SerializedColorSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedFileSchema, SerializedImageSchema, SerializedKeyOfSchema, SerializedLiteralSchema, SerializedLocaleSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedRecordSchema, SerializedRichTextSchema, SerializedRouteSchema, SerializedSchema, SerializedSettingsSchema, SerializedStringSchema, SerializedValViewSchema, SerializedVideoSchema, SharedValConfig, VAL_ENABLE_COOKIE_NAME, VAL_GREEN_RAMP, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, VAL_STUDIO_HEADER, ValCommit, ValDeployment, VideoOptions, VideoStreamOption, accentRamp, buildDuplicatePatch, buildEmptyAtPathPatch, buildFileRefValue, buildImageGalleryPatch, buildRemoveImageGalleryEntryPatch, buildSearchIndex, chainHeadOf, checkCompatibility, chooseEncoded, concatModulePath, contrastRatio, createRegExpFromPattern, createSearchIndex, createValClient, declaredLocales, describeContainerAtPath, emptyOf, explainIncompatible, filterBlockingValidationErrors, filterRoutesByPatterns, findSimilar, fitWithin, flattenRichText, forEachRichTextImage, getErrorMessageFromUnknownJson, getFilenameFromRef, getInlineImgInfo, getKeyOfRecordAt, getRefParts, getRoutesOf, getRoutesWithModulePaths, getSourceAt, indexModule, isInsidePatchSetPath, isMimeTypeAccepted, isRemoteSchema, isSchemaSourceFixError, isSkippedSource, joinSharedChanges, keyOfRecordPath, levenshtein, localeAt, memoizePerRequest, newestCommitSha, parseArtifacts, parseBuildTarget, parseCancel, parseDeclare, parseDiscard, parseJob, parseNewestCiRun, parsePress, parseProblems, parseProjectSource, parsePromote, parsePublishToken, parseRenew, parseRequestStatus, parseStatus, parseUpdateTarget, parseVerify, partitionValidationErrors, performSearch, relativeLuminance, remirrorToRichTextSource, removeModule, resolveEncodeSettings, resolvePairGround, resolveSchemaSourceFixForError, resolveSchemaSourceFixes, resolveSerializedSchemaAtPath, richTextImageSchema, richTextToRemirror, safeParsePatch, schemaErrorsOf, schemaTypesOfPath, selectionClosure, sideFiles, sideSource, sourcePathOfChild, themeCustomProperties, toolNames, traverseSchemaSource, urlOf, validateRoutePatterns, withExtension };
8770
+ export { AA_LARGE, AA_TEXT, Api, BRAND_CONTRAST_PAIRS, BinaryFileRef, CodeOptions, ColorOptions, DEFAULT_ERROR_MESSAGE, DateOptions, ENCODE_DEFAULTS, ENCODE_MIME_TYPE_OF, FileOptions, HistoricalCommit, HistoricalModule, HistoricalPatchSet, HistoryError, ImageEncodeOption, ImageOptions, JSONValue, JSON_ENTRIES_BATCH_MAX, ModuleComparison, NEVER_ENCODED, ParentRef$1 as ParentRef, Patch, PatchBlock, PatchId, PatchJSON, PatchSets, PlanRefusalError, PublishProtocolError, RAMP_STEPS, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, RestoreVerdict, RichTextOptions, SCHEMA_SOURCE_FIXES, SerializedArraySchema, SerializedBooleanSchema, SerializedCodeSchema, SerializedColorSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedFileSchema, SerializedImageSchema, SerializedKeyOfSchema, SerializedLiteralSchema, SerializedLocaleSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedRecordSchema, SerializedRichTextSchema, SerializedRouteSchema, SerializedSchema, SerializedSettingsSchema, SerializedStringSchema, SerializedValViewSchema, SerializedVideoSchema, SharedValConfig, VAL_ENABLE_COOKIE_NAME, VAL_GREEN_RAMP, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, VAL_STUDIO_HEADER, ValCommit, ValDeployment, VideoOptions, VideoStreamOption, WASM_ENCODED_MIME_TYPES, accentRamp, buildDuplicatePatch, buildEmptyAtPathPatch, buildFileRefValue, buildImageGalleryPatch, buildRemoveImageGalleryEntryPatch, buildSearchIndex, chainHeadOf, checkCompatibility, chooseEncoded, concatModulePath, contrastRatio, createRegExpFromPattern, createSearchIndex, createValClient, declaredLocales, describeContainerAtPath, emptyOf, enumLocaleTag, explainIncompatible, fallbackMimeType, filterBlockingValidationErrors, filterRoutesByPatterns, findSimilar, fitWithin, flattenRichText, forEachRichTextImage, getErrorMessageFromUnknownJson, getFilenameFromRef, getInlineImgInfo, getKeyOfRecordAt, getRefParts, getRoutesOf, getRoutesWithModulePaths, getSourceAt, getValDemo, indexModule, isInsidePatchSetPath, isLocaleSchema, isMimeTypeAccepted, isRemoteSchema, isSchemaSourceFixError, isSkippedSource, joinSharedChanges, keyOfRecordPath, levenshtein, localeAt, localeMeantBy, memoizePerRequest, newestCommitSha, parseArtifacts, parseBuildTarget, parseCancel, parseDeclare, parseDiscard, parseJob, parseNewestCiRun, parsePress, parseProblems, parseProjectSource, parsePromote, parsePublishToken, parseRenew, parseRequestStatus, parseStatus, parseUpdateTarget, parseVerify, partitionValidationErrors, performSearch, relativeLuminance, remirrorToRichTextSource, removeModule, resolveEncodeSettings, resolvePairGround, resolveSchemaSourceFixForError, resolveSchemaSourceFixes, resolveSerializedSchemaAtPath, richTextImageSchema, richTextToRemirror, safeParsePatch, schemaErrorsOf, schemaTypesOfPath, selectionClosure, shouldEncodeWithWasm, sideFiles, sideSource, sourcePathOfChild, themeCustomProperties, toolNames, traverseSchemaSource, urlOf, validateRoutePatterns, withExtension };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/shared",
3
- "version": "0.146.4",
3
+ "version": "0.147.0",
4
4
  "private": false,
5
5
  "description": "Val shared types and utilities",
6
6
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "flexsearch": "^0.8.212",
38
38
  "zod": "^4.4.3",
39
39
  "zod-validation-error": "^5.0.0",
40
- "@valbuild/core": "0.146.2"
40
+ "@valbuild/core": "0.147.0"
41
41
  },
42
42
  "files": [
43
43
  "CHANGELOG.md",