@valbuild/shared 0.146.2 → 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.
- package/CHANGELOG.md +58 -0
- package/client/dist/valbuild-shared-client.cjs.dev.js +2 -1
- package/client/dist/valbuild-shared-client.cjs.prod.js +2 -1
- package/client/dist/valbuild-shared-client.esm.js +1 -1
- package/dist/declarations/src/internal/ValClient.d.ts +11 -1
- package/dist/declarations/src/internal/demo.d.ts +31 -0
- package/dist/declarations/src/internal/index.d.ts +1 -0
- package/dist/declarations/src/internal/localeAt.d.ts +29 -2
- package/dist/declarations/src/internal/media/encodeImageDecisions.d.ts +47 -0
- package/dist/declarations/src/internal/parseRoutePattern.d.ts +6 -0
- package/dist/declarations/src/internal/valCanvasProtocol.d.ts +14 -5
- package/dist/{getSitemapTree-0ed3deac.cjs.prod.js → getSitemapTree-109be3b8.cjs.prod.js} +38 -4
- package/dist/{getSitemapTree-6fcdf745.esm.js → getSitemapTree-c70ea145.esm.js} +38 -5
- package/dist/{getSitemapTree-c732e09a.cjs.dev.js → getSitemapTree-f6254b32.cjs.dev.js} +38 -4
- package/internal/dist/valbuild-shared-internal.cjs.dev.js +230 -25
- package/internal/dist/valbuild-shared-internal.cjs.prod.js +230 -25
- package/internal/dist/valbuild-shared-internal.esm.js +225 -28
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var getSitemapTree = require('../../dist/getSitemapTree-
|
|
5
|
+
var getSitemapTree = require('../../dist/getSitemapTree-f6254b32.cjs.dev.js');
|
|
6
6
|
var core = require('@valbuild/core');
|
|
7
7
|
var zod = require('zod');
|
|
8
8
|
var zodValidationError = require('zod-validation-error');
|
|
@@ -1196,6 +1196,8 @@ var SerializedDiscriminatedUnionSchema = zod.z.lazy(function () {
|
|
|
1196
1196
|
var SerializedEnumSchema = zod.z.object(getSitemapTree._objectSpread2(getSitemapTree._objectSpread2({}, commonSchemaFields), {}, {
|
|
1197
1197
|
type: zod.z.literal("enum"),
|
|
1198
1198
|
values: zod.z.array(zod.z.string()),
|
|
1199
|
+
locales: zod.z.record(zod.z.string(), zod.z.string()).optional(),
|
|
1200
|
+
nullLocale: zod.z.string().optional(),
|
|
1199
1201
|
opt: zod.z["boolean"]()
|
|
1200
1202
|
}));
|
|
1201
1203
|
var ImageEncodeOption = zod.z.union([zod.z.literal(false), zod.z.object({
|
|
@@ -1275,6 +1277,7 @@ var SerializedRecordSchema = zod.z.lazy(function () {
|
|
|
1275
1277
|
render: FieldRender,
|
|
1276
1278
|
type: zod.z.literal("record"),
|
|
1277
1279
|
item: SerializedSchema,
|
|
1280
|
+
params: zod.z.record(zod.z.string(), SerializedSchema).optional(),
|
|
1278
1281
|
opt: zod.z["boolean"](),
|
|
1279
1282
|
// Optional gallery marker for files/images/videos
|
|
1280
1283
|
mediaType: zod.z.union([zod.z.literal("files"), zod.z.literal("images"), zod.z.literal("videos")]).optional(),
|
|
@@ -1618,7 +1621,7 @@ var ValConfig = zod.z.object({
|
|
|
1618
1621
|
gitCommit: zod.z.string().optional(),
|
|
1619
1622
|
gitBranch: zod.z.string().optional()
|
|
1620
1623
|
});
|
|
1621
|
-
var ValidationFixZ = zod.z.union([zod.z.literal("image:add-metadata"), zod.z.literal("image:check-metadata"), zod.z.literal("image:check-remote"), zod.z.literal("image:upload-remote"), zod.z.literal("image:download-remote"), zod.z.literal("images:check-remote"), zod.z.literal("images:upload-remote"), zod.z.literal("file:add-metadata"), zod.z.literal("video:add-metadata"), zod.z.literal("video:upload-remote"), zod.z.literal("video:download-remote"), zod.z.literal("videos:add-metadata"), zod.z.literal("videos:check-remote"), zod.z.literal("videos:upload-remote"), zod.z.literal("file:check-metadata"), zod.z.literal("file:check-remote"), zod.z.literal("file:upload-remote"), zod.z.literal("file:download-remote"), zod.z.literal("files:check-remote"), zod.z.literal("files:upload-remote"), zod.z.literal("keyof:check-keys"), zod.z.literal("image:check-gallery"), zod.z.literal("file:check-gallery"), zod.z.literal("video:check-gallery"), zod.z.literal("router:check-route"), zod.z.literal("locale:check-locale"), zod.z.literal("record:fill-keys"), zod.z.literal("images:check-unique-folder"), zod.z.literal("files:check-unique-folder"), zod.z.literal("images:check-all-files"), zod.z.literal("files:check-all-files"), zod.z.literal("videos:check-unique-folder"), zod.z.literal("videos:check-all-files"), zod.z.literal("jsonValues:extract-entry"), zod.z.literal("view:check-module")]);
|
|
1624
|
+
var ValidationFixZ = zod.z.union([zod.z.literal("image:add-metadata"), zod.z.literal("image:check-metadata"), zod.z.literal("image:check-remote"), zod.z.literal("image:upload-remote"), zod.z.literal("image:download-remote"), zod.z.literal("images:check-remote"), zod.z.literal("images:upload-remote"), zod.z.literal("file:add-metadata"), zod.z.literal("video:add-metadata"), zod.z.literal("video:upload-remote"), zod.z.literal("video:download-remote"), zod.z.literal("videos:add-metadata"), zod.z.literal("videos:check-remote"), zod.z.literal("videos:upload-remote"), zod.z.literal("file:check-metadata"), zod.z.literal("file:check-remote"), zod.z.literal("file:upload-remote"), zod.z.literal("file:download-remote"), zod.z.literal("files:check-remote"), zod.z.literal("files:upload-remote"), zod.z.literal("keyof:check-keys"), zod.z.literal("image:check-gallery"), zod.z.literal("file:check-gallery"), zod.z.literal("video:check-gallery"), zod.z.literal("router:check-route"), zod.z.literal("locale:check-locale"), zod.z.literal("router:check-locale-param"), zod.z.literal("record:fill-keys"), zod.z.literal("images:check-unique-folder"), zod.z.literal("files:check-unique-folder"), zod.z.literal("images:check-all-files"), zod.z.literal("files:check-all-files"), zod.z.literal("videos:check-unique-folder"), zod.z.literal("videos:check-all-files"), zod.z.literal("jsonValues:extract-entry"), zod.z.literal("view:check-module")]);
|
|
1622
1625
|
var ValidationError = zod.z.object({
|
|
1623
1626
|
message: zod.z.string(),
|
|
1624
1627
|
value: zod.z.unknown().optional(),
|
|
@@ -3745,8 +3748,11 @@ function detailsOf(json) {
|
|
|
3745
3748
|
}
|
|
3746
3749
|
var DEFAULT_ERROR_MESSAGE = "Unknown error with unknown message from server";
|
|
3747
3750
|
|
|
3748
|
-
var createValClient = function createValClient(host, config
|
|
3749
|
-
|
|
3751
|
+
var createValClient = function createValClient(host, config, options) {
|
|
3752
|
+
var _options$fetch;
|
|
3753
|
+
var send = (_options$fetch = options === null || options === void 0 ? void 0 : options.fetch) !== null && _options$fetch !== void 0 ? _options$fetch : function (input, init) {
|
|
3754
|
+
return fetch(input, init);
|
|
3755
|
+
};
|
|
3750
3756
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3751
3757
|
var anyApi = Api;
|
|
3752
3758
|
return /*#__PURE__*/function () {
|
|
@@ -3837,7 +3843,7 @@ var createValClient = function createValClient(host, config // We want to use th
|
|
|
3837
3843
|
case 2:
|
|
3838
3844
|
_context2.p = 2;
|
|
3839
3845
|
_context2.n = 3;
|
|
3840
|
-
return
|
|
3846
|
+
return send("".concat(host).concat(fullPath), {
|
|
3841
3847
|
method: method,
|
|
3842
3848
|
headers: {
|
|
3843
3849
|
"Content-Type": "application/json"
|
|
@@ -3971,6 +3977,29 @@ function isRetryable(error) {
|
|
|
3971
3977
|
return false;
|
|
3972
3978
|
}
|
|
3973
3979
|
|
|
3980
|
+
/**
|
|
3981
|
+
* A Val demo, as the page hands it to the Studio.
|
|
3982
|
+
*
|
|
3983
|
+
* In a demo the Studio talks to Val's own server running in the same tab
|
|
3984
|
+
* (`@valbuild/server/browser`) instead of to an API route, and the page that
|
|
3985
|
+
* starts that server is the app's (`<ValApp demo>`) while the Studio is a
|
|
3986
|
+
* separate bundle loaded by a script tag. A window property is how the two
|
|
3987
|
+
* meet, the same way `window.__VAL_MODULES__` hands the Studio the project's
|
|
3988
|
+
* modules. See `docs/plans/demo-mode.md`.
|
|
3989
|
+
*/
|
|
3990
|
+
|
|
3991
|
+
/*
|
|
3992
|
+
* A global `var` rather than a `Window` member: this package is compiled
|
|
3993
|
+
* without the DOM's types, and a `var` in global scope is also a property of
|
|
3994
|
+
* `window` where they exist.
|
|
3995
|
+
*/
|
|
3996
|
+
|
|
3997
|
+
/** The demo this page was started with, or null outside a demo. */
|
|
3998
|
+
function getValDemo() {
|
|
3999
|
+
var _globalThis$__VAL_DEM;
|
|
4000
|
+
return (_globalThis$__VAL_DEM = globalThis.__VAL_DEMO__) !== null && _globalThis$__VAL_DEM !== void 0 ? _globalThis$__VAL_DEM : null;
|
|
4001
|
+
}
|
|
4002
|
+
|
|
3974
4003
|
function _arrayWithHoles(r) {
|
|
3975
4004
|
if (Array.isArray(r)) return r;
|
|
3976
4005
|
}
|
|
@@ -4850,7 +4879,7 @@ function declaredLocales(snapshot) {
|
|
|
4850
4879
|
* these has to resolve all of them, and the two that leaked did so by adding a
|
|
4851
4880
|
* fix here and not to a condition somewhere else.
|
|
4852
4881
|
*/
|
|
4853
|
-
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"];
|
|
4882
|
+
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"];
|
|
4854
4883
|
|
|
4855
4884
|
/** Whether an error is a marker only the whole project can answer. */
|
|
4856
4885
|
function isSchemaSourceFixError(error) {
|
|
@@ -5040,21 +5069,51 @@ function resolveSchemaSourceFixForError(error, snapshot) {
|
|
|
5040
5069
|
})
|
|
5041
5070
|
};
|
|
5042
5071
|
}
|
|
5043
|
-
if (fixes.includes("
|
|
5072
|
+
if (fixes.includes("router:check-locale-param")) {
|
|
5044
5073
|
var _value = error.value;
|
|
5045
|
-
|
|
5074
|
+
var _ref7 = getSitemapTree._typeof(_value) === "object" && _value !== null ? _value : {},
|
|
5075
|
+
name = _ref7.name,
|
|
5076
|
+
segment = _ref7.segment;
|
|
5077
|
+
if (typeof name !== "string" || typeof segment !== "string") {
|
|
5046
5078
|
return {
|
|
5047
5079
|
status: "remaining",
|
|
5048
5080
|
error: getSitemapTree._objectSpread2(getSitemapTree._objectSpread2({}, error), {}, {
|
|
5049
|
-
message: "Expected
|
|
5081
|
+
message: "Expected route locale parameter validation error to have a 'value' with 'name' and 'segment'. ".concat(TYPE_ERROR_MESSAGE),
|
|
5050
5082
|
typeError: true,
|
|
5051
5083
|
fixes: undefined
|
|
5052
5084
|
})
|
|
5053
5085
|
};
|
|
5054
5086
|
}
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5087
|
+
// A project that declares no languages is not translated, and a
|
|
5088
|
+
// `[locale]` segment there is the app's own business.
|
|
5089
|
+
if (declaredLocales(snapshot).length === 0) {
|
|
5090
|
+
return {
|
|
5091
|
+
status: "resolved"
|
|
5092
|
+
};
|
|
5093
|
+
}
|
|
5094
|
+
return {
|
|
5095
|
+
status: "remaining",
|
|
5096
|
+
error: getSitemapTree._objectSpread2(getSitemapTree._objectSpread2({}, error), {}, {
|
|
5097
|
+
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) }."),
|
|
5098
|
+
fixes: undefined
|
|
5099
|
+
})
|
|
5100
|
+
};
|
|
5101
|
+
}
|
|
5102
|
+
if (fixes.includes("record:fill-keys")) {
|
|
5103
|
+
var _value2 = error.value;
|
|
5104
|
+
if (getSitemapTree._typeof(_value2) !== "object" || _value2 === null) {
|
|
5105
|
+
return {
|
|
5106
|
+
status: "remaining",
|
|
5107
|
+
error: getSitemapTree._objectSpread2(getSitemapTree._objectSpread2({}, error), {}, {
|
|
5108
|
+
message: "Expected record key validation error to have a 'value' object. Found: ".concat(getSitemapTree._typeof(_value2), ". ").concat(TYPE_ERROR_MESSAGE),
|
|
5109
|
+
typeError: true,
|
|
5110
|
+
fixes: undefined
|
|
5111
|
+
})
|
|
5112
|
+
};
|
|
5113
|
+
}
|
|
5114
|
+
var _ref8 = _value2,
|
|
5115
|
+
present = _ref8.present,
|
|
5116
|
+
declared = _ref8.declared;
|
|
5058
5117
|
if (!Array.isArray(present)) {
|
|
5059
5118
|
return {
|
|
5060
5119
|
status: "remaining",
|
|
@@ -5206,7 +5265,8 @@ function resolveSchemaSourceFixes(validationErrors, snapshot) {
|
|
|
5206
5265
|
*
|
|
5207
5266
|
* THE question the whole feature turns on. A locale scope is a subtree in one
|
|
5208
5267
|
* language, and three things open one: a `locale` field on an object, a record
|
|
5209
|
-
* keyed by `s.locale()`, and a locale
|
|
5268
|
+
* keyed by `s.locale()`, and a locale parameter in a router's key
|
|
5269
|
+
* (`s.router(router, { locale: … }, item)`, where the URL names the language). Once this can
|
|
5210
5270
|
* be answered from the schema and the source alone, everything downstream falls
|
|
5211
5271
|
* out of it — the Studio's locale filter, deep links, `<html lang>`, and knowing
|
|
5212
5272
|
* what to translate from and into.
|
|
@@ -5235,7 +5295,79 @@ function localeAt(path, snapshot) {
|
|
|
5235
5295
|
return null;
|
|
5236
5296
|
}
|
|
5237
5297
|
var segments = modulePath ? core.Internal.splitModulePath(modulePath) : [];
|
|
5238
|
-
return walk(schema, source, segments, available);
|
|
5298
|
+
return walk(schema, source, segments, available, moduleFilePath);
|
|
5299
|
+
}
|
|
5300
|
+
|
|
5301
|
+
/**
|
|
5302
|
+
* The language a locale schema's value MEANS, or `null` if it means none of
|
|
5303
|
+
* the project's.
|
|
5304
|
+
*
|
|
5305
|
+
* `s.locale()` stores the tag itself. An enum with `.locales(...)` stores a
|
|
5306
|
+
* value that stands for one — `nb` for `nb-NO` — and, on a router parameter,
|
|
5307
|
+
* `null` for a URL that left the segment out, which `{ null: tag }` names.
|
|
5308
|
+
* Anything else is not a locale and means nothing here.
|
|
5309
|
+
*
|
|
5310
|
+
* Callers reading a FIELD pass only strings: a field that holds `null` has no
|
|
5311
|
+
* language, whatever its schema says about URLs.
|
|
5312
|
+
*/
|
|
5313
|
+
function localeMeantBy(schema, value, available) {
|
|
5314
|
+
if (schema.type === "locale") {
|
|
5315
|
+
return value === null ? null : core.localeOfValue(value, available);
|
|
5316
|
+
}
|
|
5317
|
+
if (schema.type === "enum" && schema.locales !== undefined) {
|
|
5318
|
+
var tag = enumLocaleTag(schema, value);
|
|
5319
|
+
return tag === undefined ? null : core.localeOfValue(tag, available);
|
|
5320
|
+
}
|
|
5321
|
+
return null;
|
|
5322
|
+
}
|
|
5323
|
+
|
|
5324
|
+
/**
|
|
5325
|
+
* The tag an enum's `.locales(...)` maps a value to, as written — `null` is
|
|
5326
|
+
* the `{ null }` mapping — or `undefined` where it maps none.
|
|
5327
|
+
*
|
|
5328
|
+
* An own property: a plain object inherits `toString` and the rest, and an
|
|
5329
|
+
* enum value is allowed to be spelled like one.
|
|
5330
|
+
*/
|
|
5331
|
+
function enumLocaleTag(schema, value) {
|
|
5332
|
+
if (value === null) {
|
|
5333
|
+
return schema.nullLocale;
|
|
5334
|
+
}
|
|
5335
|
+
return schema.locales !== undefined && Object.prototype.hasOwnProperty.call(schema.locales, value) ? schema.locales[value] : undefined;
|
|
5336
|
+
}
|
|
5337
|
+
|
|
5338
|
+
/**
|
|
5339
|
+
* Whether a schema is a locale: `s.locale()`, or an enum `.locales(...)` made
|
|
5340
|
+
* one.
|
|
5341
|
+
*/
|
|
5342
|
+
function isLocaleSchema(schema) {
|
|
5343
|
+
return schema.type === "locale" || schema.type === "enum" && schema.locales !== undefined;
|
|
5344
|
+
}
|
|
5345
|
+
|
|
5346
|
+
/**
|
|
5347
|
+
* The language a router's key is in, where one of its route parameters is a
|
|
5348
|
+
* locale — `/nb/blog/hei` is `nb-NO` when `locale` maps `nb` to it.
|
|
5349
|
+
*/
|
|
5350
|
+
function localeOfRouteKey(schema, moduleFilePath, key, available) {
|
|
5351
|
+
if (schema.params === undefined || schema.router === undefined) {
|
|
5352
|
+
return null;
|
|
5353
|
+
}
|
|
5354
|
+
var pattern = core.routePatternOf(schema.router, moduleFilePath);
|
|
5355
|
+
if (pattern === null) {
|
|
5356
|
+
return null;
|
|
5357
|
+
}
|
|
5358
|
+
var values = core.matchRoutePattern(key, pattern);
|
|
5359
|
+
if (values === null) {
|
|
5360
|
+
return null;
|
|
5361
|
+
}
|
|
5362
|
+
for (var _i = 0, _Object$entries = Object.entries(schema.params); _i < _Object$entries.length; _i++) {
|
|
5363
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
5364
|
+
name = _Object$entries$_i[0],
|
|
5365
|
+
param = _Object$entries$_i[1];
|
|
5366
|
+
if (isLocaleSchema(param) && Object.prototype.hasOwnProperty.call(values, name)) {
|
|
5367
|
+
return localeMeantBy(param, values[name], available);
|
|
5368
|
+
}
|
|
5369
|
+
}
|
|
5370
|
+
return null;
|
|
5239
5371
|
}
|
|
5240
5372
|
|
|
5241
5373
|
/**
|
|
@@ -5250,7 +5382,7 @@ function localeAt(path, snapshot) {
|
|
|
5250
5382
|
* these can fire on a well-formed path; taking the innermost is what makes the
|
|
5251
5383
|
* answer well-defined while a project is mid-fix.
|
|
5252
5384
|
*/
|
|
5253
|
-
function walk(schema, source, segments, available) {
|
|
5385
|
+
function walk(schema, source, segments, available, moduleFilePath) {
|
|
5254
5386
|
var entered = enter(schema, source, available);
|
|
5255
5387
|
var locale = entered.locale;
|
|
5256
5388
|
var currentSchema = entered.schema;
|
|
@@ -5264,14 +5396,21 @@ function walk(schema, source, segments, available) {
|
|
|
5264
5396
|
return locale;
|
|
5265
5397
|
}
|
|
5266
5398
|
if (currentSchema.type === "record") {
|
|
5267
|
-
|
|
5268
|
-
if (((_currentSchema$key = currentSchema.key) === null || _currentSchema$key === void 0 ? void 0 : _currentSchema$key.type) === "locale") {
|
|
5399
|
+
if (currentSchema.key !== undefined && isLocaleSchema(currentSchema.key)) {
|
|
5269
5400
|
// In a locale-keyed record the KEY is the language, so the segment we
|
|
5270
|
-
// are about to take is the answer.
|
|
5271
|
-
|
|
5401
|
+
// are about to take is the answer — the tag itself for `s.locale()`,
|
|
5402
|
+
// the tag it stands for when the key is an enum with `.locales()`.
|
|
5403
|
+
var resolved = localeMeantBy(currentSchema.key, segment, available);
|
|
5272
5404
|
if (resolved !== null) {
|
|
5273
5405
|
locale = resolved;
|
|
5274
5406
|
}
|
|
5407
|
+
} else if (currentSchema.params !== undefined) {
|
|
5408
|
+
// A router whose URL names the language: the key is a URL, and one of
|
|
5409
|
+
// its parameters is the answer.
|
|
5410
|
+
var _resolved = localeOfRouteKey(currentSchema, moduleFilePath, segment, available);
|
|
5411
|
+
if (_resolved !== null) {
|
|
5412
|
+
locale = _resolved;
|
|
5413
|
+
}
|
|
5275
5414
|
}
|
|
5276
5415
|
currentSchema = currentSchema.item;
|
|
5277
5416
|
} else if (currentSchema.type === "array") {
|
|
@@ -5327,18 +5466,18 @@ function localeOfObjectField(schema, source, available) {
|
|
|
5327
5466
|
if (schema.type !== "object" || !isJsonObject(source)) {
|
|
5328
5467
|
return null;
|
|
5329
5468
|
}
|
|
5330
|
-
for (var
|
|
5331
|
-
var _Object$
|
|
5332
|
-
key = _Object$
|
|
5333
|
-
item = _Object$
|
|
5334
|
-
if (item
|
|
5469
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(schema.items); _i2 < _Object$entries2.length; _i2++) {
|
|
5470
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
5471
|
+
key = _Object$entries2$_i[0],
|
|
5472
|
+
item = _Object$entries2$_i[1];
|
|
5473
|
+
if (!isLocaleSchema(item)) {
|
|
5335
5474
|
continue;
|
|
5336
5475
|
}
|
|
5337
5476
|
var value = source[key];
|
|
5338
5477
|
if (typeof value !== "string") {
|
|
5339
5478
|
return null;
|
|
5340
5479
|
}
|
|
5341
|
-
return
|
|
5480
|
+
return localeMeantBy(item, value, available);
|
|
5342
5481
|
}
|
|
5343
5482
|
return null;
|
|
5344
5483
|
}
|
|
@@ -6227,6 +6366,7 @@ function isSkippableFixCode(fix) {
|
|
|
6227
6366
|
case "video:check-gallery":
|
|
6228
6367
|
case "router:check-route":
|
|
6229
6368
|
case "locale:check-locale":
|
|
6369
|
+
case "router:check-locale-param":
|
|
6230
6370
|
case "record:fill-keys":
|
|
6231
6371
|
case "jsonValues:extract-entry":
|
|
6232
6372
|
// `jsonValues:extract-entry` is an entry inlined in the `.val.ts`. The
|
|
@@ -6388,6 +6528,63 @@ function isSkippedSource(sourceMimeType, targetMimeType, needsDownscale) {
|
|
|
6388
6528
|
return sourceMimeType === targetMimeType && !needsDownscale;
|
|
6389
6529
|
}
|
|
6390
6530
|
|
|
6531
|
+
/**
|
|
6532
|
+
* The types the Studio can write with WebAssembly when the canvas cannot.
|
|
6533
|
+
*
|
|
6534
|
+
* libwebp, compiled to WebAssembly (`@jsquash/webp`, loaded by
|
|
6535
|
+
* `packages/ui/spa/utils/webpWasm.ts`). One entry because `encode` has one
|
|
6536
|
+
* `type`; a second type is a second encoder to host, not a second string here.
|
|
6537
|
+
*/
|
|
6538
|
+
var WASM_ENCODED_MIME_TYPES = ["image/webp"];
|
|
6539
|
+
|
|
6540
|
+
/**
|
|
6541
|
+
* Whether to encode the canvas's pixels with WebAssembly, given what the
|
|
6542
|
+
* canvas's own encoder handed back.
|
|
6543
|
+
*
|
|
6544
|
+
* `canvas.toBlob` answers a type it cannot write with a PNG instead of an error,
|
|
6545
|
+
* and Safari -- the browser people take their photos in -- cannot write WebP.
|
|
6546
|
+
* The pixels on that canvas are already decoded, oriented and scaled, so the
|
|
6547
|
+
* only thing missing is the encoder, and libwebp in WebAssembly is that.
|
|
6548
|
+
*
|
|
6549
|
+
* Only then, and that is what keeps the WebAssembly lazy: a browser whose
|
|
6550
|
+
* canvas wrote the type is never asked to download an encoder, even when its
|
|
6551
|
+
* WebP then loses to the original on size -- a second encoder of the same
|
|
6552
|
+
* format would lose for the same reason.
|
|
6553
|
+
*
|
|
6554
|
+
* `null` -- no blob at all -- is not "cannot write this type" either. It is a
|
|
6555
|
+
* canvas that failed to serialize anything, under memory pressure for instance,
|
|
6556
|
+
* and says nothing about WebP: a Chromium tab that hits it is still a browser
|
|
6557
|
+
* that writes WebP, and must not start downloading an encoder because of it.
|
|
6558
|
+
*/
|
|
6559
|
+
function shouldEncodeWithWasm(input) {
|
|
6560
|
+
return WASM_ENCODED_MIME_TYPES.includes(input.targetMimeType) && input.canvasOutputType !== null && input.canvasOutputType !== input.targetMimeType;
|
|
6561
|
+
}
|
|
6562
|
+
|
|
6563
|
+
/**
|
|
6564
|
+
* What to scale an image down to when nothing could write the type asked for:
|
|
6565
|
+
* the source's own format, when it is one every canvas can write.
|
|
6566
|
+
*
|
|
6567
|
+
* The second fallback, after {@link shouldEncodeWithWasm}: it is what a browser
|
|
6568
|
+
* whose canvas cannot write WebP gets when the WebAssembly encoder could not be
|
|
6569
|
+
* loaded either (offline, a blocked host, a failed instantiation). Without it,
|
|
6570
|
+
* `chooseEncoded` would rightly refuse the canvas's PNG and upload the original
|
|
6571
|
+
* -- every photo at the camera's full size, the one case `maxWidth` exists
|
|
6572
|
+
* for. Scaling it down as a JPEG keeps the half of `encode` this browser can do.
|
|
6573
|
+
*
|
|
6574
|
+
* Only when a downscale is needed: re-encoding a JPEG that already fits, as a
|
|
6575
|
+
* JPEG, is a second generation of loss for a few percent. And never into a
|
|
6576
|
+
* type `accept` refuses, for the reason `isMimeTypeAccepted` gives.
|
|
6577
|
+
*/
|
|
6578
|
+
function fallbackMimeType(sourceMimeType, needsDownscale, accept) {
|
|
6579
|
+
if (!needsDownscale) {
|
|
6580
|
+
return null;
|
|
6581
|
+
}
|
|
6582
|
+
if (sourceMimeType !== "image/jpeg" && sourceMimeType !== "image/png") {
|
|
6583
|
+
return null;
|
|
6584
|
+
}
|
|
6585
|
+
return isMimeTypeAccepted(sourceMimeType, accept) ? sourceMimeType : null;
|
|
6586
|
+
}
|
|
6587
|
+
|
|
6391
6588
|
/**
|
|
6392
6589
|
* Whether to upload what the encoder produced, or the file that was picked.
|
|
6393
6590
|
*
|
|
@@ -8584,6 +8781,7 @@ exports.VAL_CANVAS_MESSAGE = getSitemapTree.VAL_CANVAS_MESSAGE;
|
|
|
8584
8781
|
exports.VAL_CANVAS_PARAM = getSitemapTree.VAL_CANVAS_PARAM;
|
|
8585
8782
|
exports.VAL_CONFIG_SESSION_STORAGE_KEY = getSitemapTree.VAL_CONFIG_SESSION_STORAGE_KEY;
|
|
8586
8783
|
exports.VAL_THEME_SESSION_STORAGE_KEY = getSitemapTree.VAL_THEME_SESSION_STORAGE_KEY;
|
|
8784
|
+
exports.formatRoutePattern = getSitemapTree.formatRoutePattern;
|
|
8587
8785
|
exports.getNextAppRouterSourceFolder = getSitemapTree.getNextAppRouterSourceFolder;
|
|
8588
8786
|
exports.getPageRouterSitemapTree = getSitemapTree.getPageRouterSitemapTree;
|
|
8589
8787
|
exports.getPageRouterSourceFolder = getSitemapTree.getPageRouterSourceFolder;
|
|
@@ -8673,6 +8871,7 @@ exports.ValCommit = ValCommit;
|
|
|
8673
8871
|
exports.ValDeployment = ValDeployment;
|
|
8674
8872
|
exports.VideoOptions = VideoOptions;
|
|
8675
8873
|
exports.VideoStreamOption = VideoStreamOption;
|
|
8874
|
+
exports.WASM_ENCODED_MIME_TYPES = WASM_ENCODED_MIME_TYPES;
|
|
8676
8875
|
exports.accentRamp = accentRamp;
|
|
8677
8876
|
exports.buildDuplicatePatch = buildDuplicatePatch;
|
|
8678
8877
|
exports.buildEmptyAtPathPatch = buildEmptyAtPathPatch;
|
|
@@ -8691,7 +8890,9 @@ exports.createValClient = createValClient;
|
|
|
8691
8890
|
exports.declaredLocales = declaredLocales;
|
|
8692
8891
|
exports.describeContainerAtPath = describeContainerAtPath;
|
|
8693
8892
|
exports.emptyOf = emptyOf;
|
|
8893
|
+
exports.enumLocaleTag = enumLocaleTag;
|
|
8694
8894
|
exports.explainIncompatible = explainIncompatible;
|
|
8895
|
+
exports.fallbackMimeType = fallbackMimeType;
|
|
8695
8896
|
exports.filterBlockingValidationErrors = filterBlockingValidationErrors;
|
|
8696
8897
|
exports.filterRoutesByPatterns = filterRoutesByPatterns;
|
|
8697
8898
|
exports.findSimilar = findSimilar;
|
|
@@ -8706,8 +8907,10 @@ exports.getRefParts = getRefParts;
|
|
|
8706
8907
|
exports.getRoutesOf = getRoutesOf;
|
|
8707
8908
|
exports.getRoutesWithModulePaths = getRoutesWithModulePaths;
|
|
8708
8909
|
exports.getSourceAt = getSourceAt;
|
|
8910
|
+
exports.getValDemo = getValDemo;
|
|
8709
8911
|
exports.indexModule = indexModule;
|
|
8710
8912
|
exports.isInsidePatchSetPath = isInsidePatchSetPath;
|
|
8913
|
+
exports.isLocaleSchema = isLocaleSchema;
|
|
8711
8914
|
exports.isMimeTypeAccepted = isMimeTypeAccepted;
|
|
8712
8915
|
exports.isRemoteSchema = isRemoteSchema;
|
|
8713
8916
|
exports.isSchemaSourceFixError = isSchemaSourceFixError;
|
|
@@ -8716,6 +8919,7 @@ exports.joinSharedChanges = joinSharedChanges;
|
|
|
8716
8919
|
exports.keyOfRecordPath = keyOfRecordPath;
|
|
8717
8920
|
exports.levenshtein = levenshtein;
|
|
8718
8921
|
exports.localeAt = localeAt;
|
|
8922
|
+
exports.localeMeantBy = localeMeantBy;
|
|
8719
8923
|
exports.memoizePerRequest = memoizePerRequest;
|
|
8720
8924
|
exports.newestCommitSha = newestCommitSha;
|
|
8721
8925
|
exports.parseArtifacts = parseArtifacts;
|
|
@@ -8751,6 +8955,7 @@ exports.safeParsePatch = safeParsePatch;
|
|
|
8751
8955
|
exports.schemaErrorsOf = schemaErrorsOf;
|
|
8752
8956
|
exports.schemaTypesOfPath = schemaTypesOfPath;
|
|
8753
8957
|
exports.selectionClosure = selectionClosure;
|
|
8958
|
+
exports.shouldEncodeWithWasm = shouldEncodeWithWasm;
|
|
8754
8959
|
exports.sideFiles = sideFiles;
|
|
8755
8960
|
exports.sideSource = sideSource;
|
|
8756
8961
|
exports.sourcePathOfChild = sourcePathOfChild;
|