@valbuild/core 0.99.1 → 0.101.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.
Files changed (35) hide show
  1. package/dist/declarations/src/index.d.ts +15 -0
  2. package/dist/declarations/src/initSchema.d.ts +21 -0
  3. package/dist/declarations/src/initVal.d.ts +2 -0
  4. package/dist/declarations/src/schema/array.d.ts +2 -1
  5. package/dist/declarations/src/schema/boolean.d.ts +2 -1
  6. package/dist/declarations/src/schema/color.d.ts +57 -0
  7. package/dist/declarations/src/schema/colorFormat.d.ts +83 -0
  8. package/dist/declarations/src/schema/date.d.ts +2 -1
  9. package/dist/declarations/src/schema/datetime.d.ts +2 -1
  10. package/dist/declarations/src/schema/file.d.ts +2 -1
  11. package/dist/declarations/src/schema/image.d.ts +2 -1
  12. package/dist/declarations/src/schema/index.d.ts +24 -1
  13. package/dist/declarations/src/schema/keyOf.d.ts +2 -1
  14. package/dist/declarations/src/schema/literal.d.ts +2 -1
  15. package/dist/declarations/src/schema/number.d.ts +2 -1
  16. package/dist/declarations/src/schema/object.d.ts +2 -1
  17. package/dist/declarations/src/schema/record.d.ts +46 -3
  18. package/dist/declarations/src/schema/richtext.d.ts +2 -1
  19. package/dist/declarations/src/schema/route.d.ts +2 -1
  20. package/dist/declarations/src/schema/string.d.ts +2 -1
  21. package/dist/declarations/src/schema/union.d.ts +9 -1
  22. package/dist/declarations/src/schema/validation/ValidationFix.d.ts +1 -1
  23. package/dist/declarations/src/selector/index.d.ts +3 -2
  24. package/dist/declarations/src/source/index.d.ts +3 -2
  25. package/dist/declarations/src/source/json.d.ts +73 -0
  26. package/dist/{index-28d99c34.cjs.prod.js → index-049780fa.cjs.prod.js} +1238 -181
  27. package/dist/{index-b2601ac3.cjs.dev.js → index-3e2d700e.cjs.dev.js} +1238 -181
  28. package/dist/{index-204b5d78.esm.js → index-a18c24c2.esm.js} +1236 -182
  29. package/dist/valbuild-core.cjs.dev.js +4 -1
  30. package/dist/valbuild-core.cjs.prod.js +4 -1
  31. package/dist/valbuild-core.esm.js +1 -1
  32. package/package.json +1 -1
  33. package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
  34. package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
  35. package/patch/dist/valbuild-core-patch.esm.js +2 -2
@@ -652,6 +652,13 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
652
652
  value: function hidden() {
653
653
  return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, true, this.description);
654
654
  }
655
+ }, {
656
+ key: "executeCustomValidateAt",
657
+ value: function executeCustomValidateAt(path, src) {
658
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
659
+ path: path
660
+ });
661
+ }
655
662
  }, {
656
663
  key: "executeSerialize",
657
664
  value: function executeSerialize() {
@@ -900,6 +907,13 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
900
907
  value: function raw() {
901
908
  return new StringSchema(this.options, this.opt, true, this.customValidateFunctions, this.renderInput, this.isReadonly, this.isHidden, this.description);
902
909
  }
910
+ }, {
911
+ key: "executeCustomValidateAt",
912
+ value: function executeCustomValidateAt(path, src) {
913
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
914
+ path: path
915
+ });
916
+ }
903
917
  }, {
904
918
  key: "executeSerialize",
905
919
  value: function executeSerialize() {
@@ -1116,6 +1130,13 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
1116
1130
  value: function hidden() {
1117
1131
  return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
1118
1132
  }
1133
+ }, {
1134
+ key: "executeCustomValidateAt",
1135
+ value: function executeCustomValidateAt(path, src) {
1136
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1137
+ path: path
1138
+ });
1139
+ }
1119
1140
  }, {
1120
1141
  key: "executeSerialize",
1121
1142
  value: function executeSerialize() {
@@ -1275,6 +1296,13 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
1275
1296
  value: function hidden() {
1276
1297
  return new ArraySchema(this.item, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput);
1277
1298
  }
1299
+ }, {
1300
+ key: "executeCustomValidateAt",
1301
+ value: function executeCustomValidateAt(path, src) {
1302
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1303
+ path: path
1304
+ });
1305
+ }
1278
1306
  }, {
1279
1307
  key: "executeSerialize",
1280
1308
  value: function executeSerialize() {
@@ -1463,6 +1491,13 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
1463
1491
  value: function hidden() {
1464
1492
  return new LiteralSchema(this.value, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
1465
1493
  }
1494
+ }, {
1495
+ key: "executeCustomValidateAt",
1496
+ value: function executeCustomValidateAt(path, src) {
1497
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1498
+ path: path
1499
+ });
1500
+ }
1466
1501
  }, {
1467
1502
  key: "executeSerialize",
1468
1503
  value: function executeSerialize() {
@@ -1821,6 +1856,64 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1821
1856
  value: function hidden() {
1822
1857
  return new UnionSchema(this.key, this.items, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
1823
1858
  }
1859
+ }, {
1860
+ key: "executeCustomValidateAt",
1861
+ value: function executeCustomValidateAt(path, src) {
1862
+ var errors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1863
+ path: path
1864
+ });
1865
+ // A tagged union's variants share the union's path, so `Internal.resolvePath`
1866
+ // stops here and a variant's OWN validator would never be reached. Dispatch
1867
+ // into the variant this value takes — the union is the only node that knows
1868
+ // which one that is.
1869
+ var matched = this.matchedVariant(src);
1870
+ if (matched) {
1871
+ errors.push.apply(errors, _toConsumableArray(matched["executeCustomValidateAt"](path, src)));
1872
+ }
1873
+ return errors;
1874
+ }
1875
+
1876
+ /**
1877
+ * The variant schema a value takes, for a TAGGED union (string `key`). `null`
1878
+ * for a literal union (its variants are leaves with nothing to descend into) or
1879
+ * when the value matches none of them — a structural error `executeValidate`
1880
+ * already reports.
1881
+ */
1882
+ }, {
1883
+ key: "matchedVariant",
1884
+ value: function matchedVariant(src) {
1885
+ var key = this.key;
1886
+ if (typeof key !== "string" || !Array.isArray(this.items)) {
1887
+ return null;
1888
+ }
1889
+ if (src === null || _typeof(src) !== "object" || Array.isArray(src)) {
1890
+ return null;
1891
+ }
1892
+ var tag = src[key];
1893
+ if (typeof tag !== "string") {
1894
+ return null;
1895
+ }
1896
+ var objectSchemas = this.items;
1897
+ var _iterator4 = _createForOfIteratorHelper(objectSchemas),
1898
+ _step4;
1899
+ try {
1900
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1901
+ var item = _step4.value;
1902
+ if (!(item instanceof ObjectSchema)) {
1903
+ continue;
1904
+ }
1905
+ var tagSchema = item["items"][key];
1906
+ if (tagSchema instanceof LiteralSchema && tagSchema["value"] === tag) {
1907
+ return item;
1908
+ }
1909
+ }
1910
+ } catch (err) {
1911
+ _iterator4.e(err);
1912
+ } finally {
1913
+ _iterator4.f();
1914
+ }
1915
+ return null;
1916
+ }
1824
1917
  }, {
1825
1918
  key: "executeSerialize",
1826
1919
  value: function executeSerialize() {
@@ -2132,6 +2225,13 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
2132
2225
  value: function hidden() {
2133
2226
  return new ImageSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, true, this.description);
2134
2227
  }
2228
+ }, {
2229
+ key: "executeCustomValidateAt",
2230
+ value: function executeCustomValidateAt(path, src) {
2231
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
2232
+ path: path
2233
+ });
2234
+ }
2135
2235
  }, {
2136
2236
  key: "executeSerialize",
2137
2237
  value: function executeSerialize() {
@@ -2307,6 +2407,13 @@ var RouteSchema = /*#__PURE__*/function (_Schema) {
2307
2407
  value: function hidden() {
2308
2408
  return new RouteSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
2309
2409
  }
2410
+ }, {
2411
+ key: "executeCustomValidateAt",
2412
+ value: function executeCustomValidateAt(path, src) {
2413
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
2414
+ path: path
2415
+ });
2416
+ }
2310
2417
  }, {
2311
2418
  key: "executeSerialize",
2312
2419
  value: function executeSerialize() {
@@ -2845,6 +2952,13 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2845
2952
  value: function hidden() {
2846
2953
  return new RichTextSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
2847
2954
  }
2955
+ }, {
2956
+ key: "executeCustomValidateAt",
2957
+ value: function executeCustomValidateAt(path, src) {
2958
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
2959
+ path: path
2960
+ });
2961
+ }
2848
2962
  }, {
2849
2963
  key: "executeSerialize",
2850
2964
  value: function executeSerialize() {
@@ -2894,6 +3008,290 @@ var richtext = function richtext(options) {
2894
3008
  return new RichTextSchema(options !== null && options !== void 0 ? options : {});
2895
3009
  };
2896
3010
 
3011
+ function _regeneratorDefine(e, r, n, t) {
3012
+ var i = Object.defineProperty;
3013
+ try {
3014
+ i({}, "", {});
3015
+ } catch (e) {
3016
+ i = 0;
3017
+ }
3018
+ _regeneratorDefine = function (e, r, n, t) {
3019
+ function o(r, n) {
3020
+ _regeneratorDefine(e, r, function (e) {
3021
+ return this._invoke(r, n, e);
3022
+ });
3023
+ }
3024
+ r ? i ? i(e, r, {
3025
+ value: n,
3026
+ enumerable: !t,
3027
+ configurable: !t,
3028
+ writable: !t
3029
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
3030
+ }, _regeneratorDefine(e, r, n, t);
3031
+ }
3032
+
3033
+ function _regenerator() {
3034
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3035
+ var e,
3036
+ t,
3037
+ r = "function" == typeof Symbol ? Symbol : {},
3038
+ n = r.iterator || "@@iterator",
3039
+ o = r.toStringTag || "@@toStringTag";
3040
+ function i(r, n, o, i) {
3041
+ var c = n && n.prototype instanceof Generator ? n : Generator,
3042
+ u = Object.create(c.prototype);
3043
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
3044
+ var i,
3045
+ c,
3046
+ u,
3047
+ f = 0,
3048
+ p = o || [],
3049
+ y = !1,
3050
+ G = {
3051
+ p: 0,
3052
+ n: 0,
3053
+ v: e,
3054
+ a: d,
3055
+ f: d.bind(e, 4),
3056
+ d: function (t, r) {
3057
+ return i = t, c = 0, u = e, G.n = r, a;
3058
+ }
3059
+ };
3060
+ function d(r, n) {
3061
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
3062
+ var o,
3063
+ i = p[t],
3064
+ d = G.p,
3065
+ l = i[2];
3066
+ r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
3067
+ }
3068
+ if (o || r > 1) return a;
3069
+ throw y = !0, n;
3070
+ }
3071
+ return function (o, p, l) {
3072
+ if (f > 1) throw TypeError("Generator is already running");
3073
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
3074
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
3075
+ try {
3076
+ if (f = 2, i) {
3077
+ if (c || (o = "next"), t = i[o]) {
3078
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
3079
+ if (!t.done) return t;
3080
+ u = t.value, c < 2 && (c = 0);
3081
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
3082
+ i = e;
3083
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
3084
+ } catch (t) {
3085
+ i = e, c = 1, u = t;
3086
+ } finally {
3087
+ f = 1;
3088
+ }
3089
+ }
3090
+ return {
3091
+ value: t,
3092
+ done: y
3093
+ };
3094
+ };
3095
+ }(r, o, i), !0), u;
3096
+ }
3097
+ var a = {};
3098
+ function Generator() {}
3099
+ function GeneratorFunction() {}
3100
+ function GeneratorFunctionPrototype() {}
3101
+ t = Object.getPrototypeOf;
3102
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
3103
+ return this;
3104
+ }), t),
3105
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
3106
+ function f(e) {
3107
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
3108
+ }
3109
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
3110
+ return this;
3111
+ }), _regeneratorDefine(u, "toString", function () {
3112
+ return "[object Generator]";
3113
+ }), (_regenerator = function () {
3114
+ return {
3115
+ w: i,
3116
+ m: f
3117
+ };
3118
+ })();
3119
+ }
3120
+
3121
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
3122
+ try {
3123
+ var i = n[a](c),
3124
+ u = i.value;
3125
+ } catch (n) {
3126
+ return void e(n);
3127
+ }
3128
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
3129
+ }
3130
+ function _asyncToGenerator(n) {
3131
+ return function () {
3132
+ var t = this,
3133
+ e = arguments;
3134
+ return new Promise(function (r, o) {
3135
+ var a = n.apply(t, e);
3136
+ function _next(n) {
3137
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
3138
+ }
3139
+ function _throw(n) {
3140
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
3141
+ }
3142
+ _next(void 0);
3143
+ });
3144
+ };
3145
+ }
3146
+
3147
+ /**
3148
+ * The string used as the `_type` discriminator of a {@link JsonSource}.
3149
+ */
3150
+ var JSON_VAL_EXTENSION_TAG = "json";
3151
+
3152
+ /**
3153
+ * The lazy import thunk a {@link JsonSource} carries at runtime. It is NOT part
3154
+ * of the {@link JsonSource} type because `Source` must stay JSON-serializable
3155
+ * (it is sent over the wire as `Json`); the thunk is a runtime-only detail,
3156
+ * read via {@link getJsonImport}.
3157
+ */
3158
+
3159
+ /**
3160
+ * A JSON source represents a record/router entry whose value is stored in a
3161
+ * separate `*.val.json` file and loaded lazily via a dynamic `import()` thunk.
3162
+ *
3163
+ * This is what `c.json(() => import("./entry.val.json"))` returns.
3164
+ *
3165
+ * The *type* is a pure-JSON marker (`{ _type: "json", patch_id? }`) so that
3166
+ * `Source` stays JSON-serializable. At runtime the value additionally carries a
3167
+ * lazy import thunk (read via {@link getJsonImport}); over the wire only the
3168
+ * marker is sent.
3169
+ *
3170
+ * The phantom type parameter `T` is the (loosened, see {@link JsonOf}) type of
3171
+ * the value the JSON file resolves to. It is covariant: a `JsonSource` of a
3172
+ * narrower value type is assignable to a `JsonSource` of a wider one.
3173
+ */
3174
+
3175
+ function json(importThunk) {
3176
+ return _defineProperty(_defineProperty({}, VAL_EXTENSION, JSON_VAL_EXTENSION_TAG), "_import", importThunk);
3177
+ }
3178
+ function isJson(obj) {
3179
+ return _typeof(obj) === "object" && obj !== null && VAL_EXTENSION in obj && obj[VAL_EXTENSION] === JSON_VAL_EXTENSION_TAG;
3180
+ }
3181
+
3182
+ /**
3183
+ * Reads the runtime-only lazy import thunk from a {@link JsonSource}. Returns
3184
+ * `undefined` for a transport marker (sent over the wire without the thunk).
3185
+ */
3186
+ function getJsonImport(source) {
3187
+ var candidate = source._import;
3188
+ return typeof candidate === "function" ? candidate : undefined;
3189
+ }
3190
+
3191
+ /**
3192
+ * Recursively resolves every {@link JsonSource} marker in a source tree by
3193
+ * invoking its lazy import thunk, returning a fully-inlined source. This backs
3194
+ * the eager `fetchVal`/`useVal` path (load everything).
3195
+ *
3196
+ * Markers without a runtime thunk (transport markers received over the wire)
3197
+ * are left as-is — there is nothing to load from them locally. Other branded
3198
+ * leaf sources (file/image/remote/richtext) are returned untouched.
3199
+ */
3200
+ function resolveJsonValues(_x) {
3201
+ return _resolveJsonValues.apply(this, arguments);
3202
+ }
3203
+
3204
+ /**
3205
+ * Loosens a (strict) schema source type `T` into the type that a
3206
+ * `resolveJsonModule` import of the backing `*.val.json` can actually satisfy.
3207
+ *
3208
+ * Why this is needed: TypeScript widens literals when it infers the type of a
3209
+ * JSON module (e.g. `"a"` becomes `string`, `1` becomes `number`, and a branded
3210
+ * `_type: "file"` becomes `_type: string`). A strict schema type (with literal
3211
+ * unions, `RawString` brands, etc.) would therefore reject a perfectly valid
3212
+ * JSON file. `JsonOf<T>` performs the same widening at the type level so the
3213
+ * JSON content typechecks against the schema as strictly as JSON allows. Runtime
3214
+ * validation enforces the rest.
3215
+ *
3216
+ * The transform distributes over unions and recurses through objects/arrays,
3217
+ * preserving structure while widening every leaf literal. Val object-unions are
3218
+ * always discriminated, so distribute-and-recurse is sufficient (the discriminant
3219
+ * literal widens to its base type, but the per-variant shape stays distinct and a
3220
+ * concrete JSON value still matches exactly one variant).
3221
+ */
3222
+ function _resolveJsonValues() {
3223
+ _resolveJsonValues = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(source) {
3224
+ var thunk, loaded, entries;
3225
+ return _regenerator().w(function (_context2) {
3226
+ while (1) switch (_context2.n) {
3227
+ case 0:
3228
+ if (!isJson(source)) {
3229
+ _context2.n = 3;
3230
+ break;
3231
+ }
3232
+ thunk = getJsonImport(source);
3233
+ if (thunk) {
3234
+ _context2.n = 1;
3235
+ break;
3236
+ }
3237
+ return _context2.a(2, source);
3238
+ case 1:
3239
+ _context2.n = 2;
3240
+ return thunk();
3241
+ case 2:
3242
+ loaded = _context2.v["default"];
3243
+ return _context2.a(2, resolveJsonValues(loaded));
3244
+ case 3:
3245
+ if (!Array.isArray(source)) {
3246
+ _context2.n = 4;
3247
+ break;
3248
+ }
3249
+ return _context2.a(2, Promise.all(source.map(function (item) {
3250
+ return resolveJsonValues(item);
3251
+ })));
3252
+ case 4:
3253
+ if (!(source !== null && _typeof(source) === "object")) {
3254
+ _context2.n = 7;
3255
+ break;
3256
+ }
3257
+ if (!(VAL_EXTENSION in source)) {
3258
+ _context2.n = 5;
3259
+ break;
3260
+ }
3261
+ return _context2.a(2, source);
3262
+ case 5:
3263
+ _context2.n = 6;
3264
+ return Promise.all(Object.entries(source).map(/*#__PURE__*/function () {
3265
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref2) {
3266
+ var _ref4, key, value, _t, _t2;
3267
+ return _regenerator().w(function (_context) {
3268
+ while (1) switch (_context.n) {
3269
+ case 0:
3270
+ _ref4 = _slicedToArray(_ref2, 2), key = _ref4[0], value = _ref4[1];
3271
+ _t = key;
3272
+ _context.n = 1;
3273
+ return resolveJsonValues(value);
3274
+ case 1:
3275
+ _t2 = _context.v;
3276
+ return _context.a(2, [_t, _t2]);
3277
+ }
3278
+ }, _callee);
3279
+ }));
3280
+ return function (_x2) {
3281
+ return _ref3.apply(this, arguments);
3282
+ };
3283
+ }()));
3284
+ case 6:
3285
+ entries = _context2.v;
3286
+ return _context2.a(2, Object.fromEntries(entries));
3287
+ case 7:
3288
+ return _context2.a(2, source);
3289
+ }
3290
+ }, _callee2);
3291
+ }));
3292
+ return _resolveJsonValues.apply(this, arguments);
3293
+ }
3294
+
2897
3295
  var RegEx = /^(https?:\/\/[^/]+)\/file\/p\/([^/]+)\/b\/([^/]+)\/v\/([^/]+)\/h\/([^/]+)\/f\/([^/]+)\/p\/(.+)$/;
2898
3296
  function splitRemoteRef(ref) {
2899
3297
  if (ref[0] === "/") {
@@ -2935,6 +3333,20 @@ function splitRemoteRef(ref) {
2935
3333
  };
2936
3334
  }
2937
3335
 
3336
+ /**
3337
+ * The source type of a `.jsonValues()` record: every entry value is EITHER a
3338
+ * lazily loaded {@link JsonSource} whose resolved content is the (loosened, see
3339
+ * {@link JsonOf}) item type, OR the item value written inline.
3340
+ *
3341
+ * Inline values are accepted by the TYPE on purpose: hand-authoring an entry
3342
+ * directly in the `.val.ts` (or copying one in from a non-jsonValues record) is
3343
+ * the natural first thing to write, and a type error there is a dead end — the
3344
+ * author cannot see what to write instead. Validation reports the inline entry
3345
+ * (`jsonValues:extract-entry`) and `val validate --fix` moves it into its own
3346
+ * `*.val.json`, so the mistake is caught and repaired instead of blocking
3347
+ * authoring.
3348
+ */
3349
+
2938
3350
  var RecordSchema = /*#__PURE__*/function (_Schema) {
2939
3351
  function RecordSchema(item) {
2940
3352
  var _this;
@@ -2946,7 +3358,8 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2946
3358
  var isReadonly = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
2947
3359
  var isHidden = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
2948
3360
  var description = arguments.length > 8 ? arguments[8] : undefined;
2949
- var renderInput = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : null;
3361
+ var isJsonValues = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : false;
3362
+ var renderInput = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : null;
2950
3363
  _classCallCheck(this, RecordSchema);
2951
3364
  _this = _callSuper(this, RecordSchema);
2952
3365
  _this.item = item;
@@ -2958,6 +3371,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2958
3371
  _this.isReadonly = isReadonly;
2959
3372
  _this.isHidden = isHidden;
2960
3373
  _this.description = description;
3374
+ _this.isJsonValues = isJsonValues;
2961
3375
  _this.renderInput = renderInput;
2962
3376
  return _this;
2963
3377
  }
@@ -2965,12 +3379,12 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2965
3379
  return _createClass(RecordSchema, [{
2966
3380
  key: "describe",
2967
3381
  value: function describe(description) {
2968
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined, this.renderInput);
3382
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined, this.isJsonValues, this.renderInput);
2969
3383
  }
2970
3384
  }, {
2971
3385
  key: "validate",
2972
3386
  value: function validate(validationFunction) {
2973
- return new RecordSchema(this.item, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.renderInput);
3387
+ return new RecordSchema(this.item, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.isJsonValues, this.renderInput);
2974
3388
  }
2975
3389
  }, {
2976
3390
  key: "executeValidate",
@@ -3085,7 +3499,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3085
3499
  _this2.markKeyErrorsAtPath(entryErr, subPath);
3086
3500
  }
3087
3501
  error = _this2.mergeValidationErrors(error, entryErr);
3088
- } else {
3502
+ } else if (_this2.isJsonValues && isJson(elem)) ; else {
3503
+ // Falls through for a jsonValues record whose entry content is inlined
3504
+ // (loaded in the UI, or hand-authored): same as a plain record — validate
3505
+ // the value against the item schema.
3089
3506
  var subError = _this2.item["executeValidate"](subPath, elem);
3090
3507
  error = _this2.mergeValidationErrors(error, subError);
3091
3508
  }
@@ -3326,32 +3743,64 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3326
3743
  }, {
3327
3744
  key: "nullable",
3328
3745
  value: function nullable() {
3329
- return new RecordSchema(this.item, true, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.renderInput);
3746
+ return new RecordSchema(this.item, true, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.isJsonValues, this.renderInput);
3330
3747
  }
3331
3748
  }, {
3332
3749
  key: "readonly",
3333
3750
  value: function readonly() {
3334
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, true, this.isHidden, this.description, this.renderInput);
3751
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, true, this.isHidden, this.description, this.isJsonValues, this.renderInput);
3335
3752
  }
3336
3753
  }, {
3337
3754
  key: "hidden",
3338
3755
  value: function hidden() {
3339
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, true, this.description, this.renderInput);
3756
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, true, this.description, this.isJsonValues, this.renderInput);
3340
3757
  }
3341
3758
  }, {
3342
3759
  key: "router",
3343
3760
  value: function router(_router) {
3344
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, _router, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.renderInput);
3761
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, _router, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.isJsonValues, this.renderInput);
3345
3762
  }
3346
3763
  }, {
3347
3764
  key: "remote",
3348
3765
  value: function remote() {
3349
3766
  return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions ? _objectSpread2(_objectSpread2({}, this.mediaOptions), {}, {
3350
3767
  remote: true
3351
- }) : undefined, this.isReadonly, this.isHidden, this.description, this.renderInput);
3768
+ }) : undefined, this.isReadonly, this.isHidden, this.description, this.isJsonValues, this.renderInput);
3352
3769
  }
3770
+
3771
+ /**
3772
+ * Store each entry's value in its own lazily-loaded `*.val.json` file instead
3773
+ * of inlining it in the `.val.ts` module. Entry values become
3774
+ * {@link JsonSource} thunks (`c.json(() => import("./entry.val.json"))`),
3775
+ * which lets the runtime, the Studio and validation work one entry at a time
3776
+ * so a record/router can scale to many thousands of entries.
3777
+ *
3778
+ * Not supported on image/file galleries (`s.images()` / `s.files()`).
3779
+ *
3780
+ * Only supported on a module's ROOT record/router — a `.jsonValues()` record
3781
+ * nested inside an object/array/record is rejected at startup with a module
3782
+ * error, because the single-entry fetch endpoint, the Studio's content
3783
+ * substitution and content validation are all root-only.
3784
+ */
3353
3785
  }, {
3354
- key: "getRouterValidations",
3786
+ key: "jsonValues",
3787
+ value: function jsonValues() {
3788
+ if (this.mediaOptions) {
3789
+ throw new Error(".jsonValues() cannot be used with image/file galleries (s.images()/s.files())");
3790
+ }
3791
+ if (this.customValidateFunctions.length > 0) {
3792
+ // `.jsonValues()` changes the source shape to JsonSource entries, so a
3793
+ // validator typed against the previous Src cannot be carried over. Refusing
3794
+ // is the point: silently dropping it left the developer looking at a
3795
+ // `.validate(...)` in their source file that never ran anywhere.
3796
+ throw new Error(".jsonValues() must come BEFORE .validate(): a validator added first is typed against the un-lazy source shape and cannot be carried over. Write s.record(...).jsonValues().validate(...) instead.");
3797
+ }
3798
+ return new RecordSchema(this.item, this.opt,
3799
+ // Empty by construction: the guard above rejects any that were registered.
3800
+ [], this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, true, this.renderInput);
3801
+ }
3802
+ }, {
3803
+ key: "getRouterValidations",
3355
3804
  value: function getRouterValidations(path, src) {
3356
3805
  if (!this.currentRouter) {
3357
3806
  return false;
@@ -3392,6 +3841,13 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3392
3841
  }
3393
3842
  return false;
3394
3843
  }
3844
+ }, {
3845
+ key: "executeCustomValidateAt",
3846
+ value: function executeCustomValidateAt(path, src) {
3847
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
3848
+ path: path
3849
+ });
3850
+ }
3395
3851
  }, {
3396
3852
  key: "executeSerialize",
3397
3853
  value: function executeSerialize() {
@@ -3403,6 +3859,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3403
3859
  opt: this.opt,
3404
3860
  router: (_this$currentRouter = this.currentRouter) === null || _this$currentRouter === void 0 ? void 0 : _this$currentRouter.getRouterId(),
3405
3861
  customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
3862
+ jsonValues: this.isJsonValues ? true : undefined,
3406
3863
  readonly: this.isReadonly,
3407
3864
  hidden: this.isHidden,
3408
3865
  description: this.description
@@ -3418,6 +3875,18 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3418
3875
  }
3419
3876
  return result;
3420
3877
  }
3878
+
3879
+ /**
3880
+ * Validate the loaded content of a single `.jsonValues()` entry against the
3881
+ * item schema. The server calls this once it has loaded the backing
3882
+ * `*.val.json` for an entry (the deep validation that `executeValidate`
3883
+ * defers).
3884
+ */
3885
+ }, {
3886
+ key: "validateJsonEntryContent",
3887
+ value: function validateJsonEntryContent(path, content) {
3888
+ return this.item["executeValidate"](path, content);
3889
+ }
3421
3890
  }, {
3422
3891
  key: "executeRender",
3423
3892
  value: function executeRender(sourcePath, src) {
@@ -3430,6 +3899,13 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3430
3899
  if (itemSrc === null || itemSrc === undefined) {
3431
3900
  continue;
3432
3901
  }
3902
+ if (isJson(itemSrc)) {
3903
+ // An un-loaded `.jsonValues()` entry: an opaque marker, not the item this
3904
+ // schema describes. Skipping it is what makes rendering a partially
3905
+ // loaded record work — the result comes out covering exactly the loaded
3906
+ // keys, and the caller renders a placeholder for the rest.
3907
+ continue;
3908
+ }
3433
3909
  var subPath = unsafeCreateSourcePath(sourcePath, _key);
3434
3910
  var itemResult = this.item["executeRender"](subPath, itemSrc);
3435
3911
  for (var keyS in itemResult) {
@@ -3447,45 +3923,52 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3447
3923
  message: "Unknown layout type: " + layout
3448
3924
  };
3449
3925
  }
3450
- try {
3451
- res[sourcePath] = {
3452
- status: "success",
3453
- data: {
3454
- layout: "list",
3455
- parent: "record",
3456
- items: Object.entries(src).map(function (_ref14) {
3457
- var _ref15 = _slicedToArray(_ref14, 2),
3458
- key = _ref15[0],
3459
- val = _ref15[1];
3460
- // NB NB: display is actually defined by the user
3461
- var _prepare = prepare({
3462
- key: key,
3463
- val: val
3464
- }),
3465
- title = _prepare.title,
3466
- subtitle = _prepare.subtitle,
3467
- image = _prepare.image;
3468
- return [key, {
3469
- title: title,
3470
- subtitle: subtitle,
3471
- image: image
3472
- }];
3473
- })
3474
- }
3475
- };
3476
- } catch (e) {
3477
- res[sourcePath] = {
3478
- status: "error",
3479
- message: e instanceof Error ? e.message : "Unknown error"
3480
- };
3926
+ var items = [];
3927
+ for (var _i = 0, _Object$entries = Object.entries(src); _i < _Object$entries.length; _i++) {
3928
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
3929
+ _key3 = _Object$entries$_i[0],
3930
+ val = _Object$entries$_i[1];
3931
+ if (isJson(val)) {
3932
+ continue; // as above: nothing to select from an un-loaded entry
3933
+ }
3934
+ // Per KEY, not per record: `select` is user code, and one entry whose
3935
+ // data trips it up must not take out the whole list.
3936
+ try {
3937
+ // NB NB: display is actually defined by the user
3938
+ var _prepare = prepare({
3939
+ key: _key3,
3940
+ val: val
3941
+ }),
3942
+ title = _prepare.title,
3943
+ subtitle = _prepare.subtitle,
3944
+ image = _prepare.image;
3945
+ items.push([_key3, {
3946
+ title: title,
3947
+ subtitle: subtitle,
3948
+ image: image
3949
+ }]);
3950
+ } catch (e) {
3951
+ res[unsafeCreateSourcePath(sourcePath, _key3)] = {
3952
+ status: "error",
3953
+ message: e instanceof Error ? e.message : "Unknown error"
3954
+ };
3955
+ }
3481
3956
  }
3957
+ res[sourcePath] = {
3958
+ status: "success",
3959
+ data: {
3960
+ layout: "list",
3961
+ parent: "record",
3962
+ items: items
3963
+ }
3964
+ };
3482
3965
  }
3483
3966
  return res;
3484
3967
  }
3485
3968
  }, {
3486
3969
  key: "render",
3487
3970
  value: function render(input) {
3488
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, {
3971
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.isJsonValues, {
3489
3972
  layout: input.as,
3490
3973
  select: input.select
3491
3974
  });
@@ -3603,6 +4086,13 @@ function resolvePath(path, valModule, schema) {
3603
4086
  }
3604
4087
  resolvedSource = resolvedSource[part];
3605
4088
  resolvedSchema = resolvedSchema instanceof RecordSchema ? (_resolvedSchema2 = resolvedSchema) === null || _resolvedSchema2 === void 0 ? void 0 : _resolvedSchema2["item"] : resolvedSchema.item;
4089
+ // A `.jsonValues()` entry value is a lazily-loaded JsonSource marker. We
4090
+ // can resolve the entry itself (schema is now `item`), but we cannot
4091
+ // descend deeper until the backing `*.val.json` content has been loaded
4092
+ // and substituted into the source tree (done by the UI/server layer).
4093
+ if (isJson(resolvedSource) && parts.length > 0) {
4094
+ throw Error("Cannot resolve path into a jsonValues entry until its content is loaded. Path: ".concat(path));
4095
+ }
3606
4096
  } else if (isObjectSchema(resolvedSchema)) {
3607
4097
  if (_typeof(resolvedSource) !== "object") {
3608
4098
  throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
@@ -3807,6 +4297,16 @@ function safeResolvePath(path, valModule, schema) {
3807
4297
  }
3808
4298
  resolvedSource = resolvedSource[part];
3809
4299
  resolvedSchema = resolvedSchema instanceof RecordSchema ? (_resolvedSchema4 = resolvedSchema) === null || _resolvedSchema4 === void 0 ? void 0 : _resolvedSchema4["item"] : resolvedSchema.item;
4300
+ // jsonValues entry: cannot descend deeper until the backing `*.val.json`
4301
+ // content is loaded into the source tree.
4302
+ if (isJson(resolvedSource) && parts.length > 0) {
4303
+ return {
4304
+ v: {
4305
+ status: "error",
4306
+ message: "Cannot resolve path into a jsonValues entry until its content is loaded. Path: ".concat(path)
4307
+ }
4308
+ };
4309
+ }
3810
4310
  } else if (isObjectSchema(resolvedSchema)) {
3811
4311
  if (resolvedSource === undefined) {
3812
4312
  return {
@@ -4142,6 +4642,13 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
4142
4642
  min: _min
4143
4643
  }), this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description);
4144
4644
  }
4645
+ }, {
4646
+ key: "executeCustomValidateAt",
4647
+ value: function executeCustomValidateAt(path, src) {
4648
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
4649
+ path: path
4650
+ });
4651
+ }
4145
4652
  }, {
4146
4653
  key: "executeSerialize",
4147
4654
  value: function executeSerialize() {
@@ -4256,6 +4763,13 @@ var BooleanSchema = /*#__PURE__*/function (_Schema) {
4256
4763
  value: function hidden() {
4257
4764
  return new BooleanSchema(this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
4258
4765
  }
4766
+ }, {
4767
+ key: "executeCustomValidateAt",
4768
+ value: function executeCustomValidateAt(path, src) {
4769
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
4770
+ path: path
4771
+ });
4772
+ }
4259
4773
  }, {
4260
4774
  key: "executeSerialize",
4261
4775
  value: function executeSerialize() {
@@ -4450,6 +4964,13 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
4450
4964
  value: function hidden() {
4451
4965
  return new KeyOfSchema(this.schema, this.sourcePath, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
4452
4966
  }
4967
+ }, {
4968
+ key: "executeCustomValidateAt",
4969
+ value: function executeCustomValidateAt(path, src) {
4970
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
4971
+ path: path
4972
+ });
4973
+ }
4453
4974
  }, {
4454
4975
  key: "executeSerialize",
4455
4976
  value: function executeSerialize() {
@@ -4695,6 +5216,13 @@ var DateSchema = /*#__PURE__*/function (_Schema) {
4695
5216
  value: function hidden() {
4696
5217
  return new DateSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
4697
5218
  }
5219
+ }, {
5220
+ key: "executeCustomValidateAt",
5221
+ value: function executeCustomValidateAt(path, src) {
5222
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
5223
+ path: path
5224
+ });
5225
+ }
4698
5226
  }, {
4699
5227
  key: "executeSerialize",
4700
5228
  value: function executeSerialize() {
@@ -4892,6 +5420,13 @@ var DateTimeSchema = /*#__PURE__*/function (_Schema) {
4892
5420
  value: function hidden() {
4893
5421
  return new DateTimeSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
4894
5422
  }
5423
+ }, {
5424
+ key: "executeCustomValidateAt",
5425
+ value: function executeCustomValidateAt(path, src) {
5426
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
5427
+ path: path
5428
+ });
5429
+ }
4895
5430
  }, {
4896
5431
  key: "executeSerialize",
4897
5432
  value: function executeSerialize() {
@@ -4917,6 +5452,647 @@ var datetime = function datetime(options) {
4917
5452
  return new DateTimeSchema(options);
4918
5453
  };
4919
5454
 
5455
+ /**
5456
+ * Parsing / formatting of the CSS color strings stored by `s.color()`.
5457
+ *
5458
+ * Colors are stored as plain CSS strings so that they can be used directly in
5459
+ * `style` attributes and CSS custom properties. The schema decides which family
5460
+ * (`hex`, `rgb`, `hsl` or `oklch`) the string is written in, this module does
5461
+ * the conversion between them.
5462
+ *
5463
+ * All colors are sRGB: `oklch` is only used as an output notation, so any
5464
+ * `oklch` value that falls outside the sRGB gamut is clipped when converted
5465
+ * back to the other formats.
5466
+ */
5467
+
5468
+ var COLOR_FORMATS = ["hex", "rgb", "hsl", "oklch"];
5469
+ var DEFAULT_COLOR_FORMAT = "hsl";
5470
+
5471
+ /**
5472
+ * A color, normalized to sRGB.
5473
+ *
5474
+ * `r`, `g` and `b` are 0-255 (not rounded), `a` is 0-1.
5475
+ */
5476
+
5477
+ /**
5478
+ * Which color notation a string uses, or `null` if it is not a notation we
5479
+ * recognize. This looks at the syntax only: `detectColorFormat` says nothing
5480
+ * about whether the value actually parses (`hsl(nope)` is still `"hsl"`).
5481
+ */
5482
+ function detectColorFormat(value) {
5483
+ var trimmed = value.trim().toLowerCase();
5484
+ if (trimmed.startsWith("#")) {
5485
+ return "hex";
5486
+ }
5487
+ if (trimmed.startsWith("rgb(") || trimmed.startsWith("rgba(")) {
5488
+ return "rgb";
5489
+ }
5490
+ if (trimmed.startsWith("hsl(") || trimmed.startsWith("hsla(")) {
5491
+ return "hsl";
5492
+ }
5493
+ if (trimmed.startsWith("oklch(")) {
5494
+ return "oklch";
5495
+ }
5496
+ return null;
5497
+ }
5498
+ function clamp(value, min, max) {
5499
+ if (Number.isNaN(value)) {
5500
+ return min;
5501
+ }
5502
+ return Math.min(max, Math.max(min, value));
5503
+ }
5504
+
5505
+ /**
5506
+ * Splits the inside of a CSS color function into components.
5507
+ *
5508
+ * Handles both the legacy comma syntax (`rgb(1, 2, 3, 0.5)`) and the modern
5509
+ * space syntax (`rgb(1 2 3 / 0.5)`), returning the alpha (if any) separately.
5510
+ */
5511
+ function splitComponents(args) {
5512
+ var slashParts = args.split("/");
5513
+ if (slashParts.length > 2) {
5514
+ return null;
5515
+ }
5516
+ var alpha = slashParts.length === 2 ? slashParts[1].trim() : null;
5517
+ var head = slashParts[0].trim();
5518
+ if (head === "") {
5519
+ return null;
5520
+ }
5521
+ var components;
5522
+ if (head.includes(",")) {
5523
+ if (alpha !== null) {
5524
+ // Mixing the comma and the slash syntax is not valid CSS
5525
+ return null;
5526
+ }
5527
+ components = head.split(",").map(function (part) {
5528
+ return part.trim();
5529
+ });
5530
+ if (components.length === 4) {
5531
+ alpha = components[3];
5532
+ components = components.slice(0, 3);
5533
+ }
5534
+ } else {
5535
+ components = head.split(/\s+/);
5536
+ }
5537
+ if (components.length !== 3 || components.some(function (part) {
5538
+ return part === "";
5539
+ })) {
5540
+ return null;
5541
+ }
5542
+ if (alpha === "") {
5543
+ return null;
5544
+ }
5545
+ return {
5546
+ components: components,
5547
+ alpha: alpha
5548
+ };
5549
+ }
5550
+ function parseNumber(value) {
5551
+ if (!/^[+-]?(\d+\.?\d*|\.\d+)$/.test(value)) {
5552
+ return null;
5553
+ }
5554
+ var parsed = Number(value);
5555
+ return Number.isFinite(parsed) ? parsed : null;
5556
+ }
5557
+
5558
+ /**
5559
+ * A `<number>` or a `<percentage>`, where 100% maps to `percentageBasis`.
5560
+ */
5561
+ function parseNumberOrPercentage(value, percentageBasis) {
5562
+ if (value.endsWith("%")) {
5563
+ var percentage = parseNumber(value.slice(0, -1));
5564
+ return percentage === null ? null : percentage / 100 * percentageBasis;
5565
+ }
5566
+ return parseNumber(value);
5567
+ }
5568
+ function parsePercentage(value) {
5569
+ if (!value.endsWith("%")) {
5570
+ return null;
5571
+ }
5572
+ return parseNumber(value.slice(0, -1));
5573
+ }
5574
+ function parseAlpha(value) {
5575
+ if (value === null) {
5576
+ return 1;
5577
+ }
5578
+ if (value === "none") {
5579
+ return 0;
5580
+ }
5581
+ var parsed = parseNumberOrPercentage(value, 1);
5582
+ return parsed === null ? null : clamp(parsed, 0, 1);
5583
+ }
5584
+ function parseHue(value) {
5585
+ var match = /^([+-]?(?:\d+\.?\d*|\.\d+))(deg|grad|rad|turn)?$/.exec(value);
5586
+ if (!match) {
5587
+ return null;
5588
+ }
5589
+ var amount = Number(match[1]);
5590
+ switch (match[2]) {
5591
+ case "grad":
5592
+ return amount / 400 * 360;
5593
+ case "rad":
5594
+ return amount * 180 / Math.PI;
5595
+ case "turn":
5596
+ return amount * 360;
5597
+ default:
5598
+ return amount;
5599
+ }
5600
+ }
5601
+ function normalizeHue(hue) {
5602
+ var wrapped = hue % 360;
5603
+ return wrapped < 0 ? wrapped + 360 : wrapped;
5604
+ }
5605
+ function parseHex(value) {
5606
+ var hex = value.slice(1);
5607
+ if (!/^[0-9a-f]+$/i.test(hex)) {
5608
+ return null;
5609
+ }
5610
+ var expand = function expand(_char) {
5611
+ return parseInt(_char + _char, 16);
5612
+ };
5613
+ var pair = function pair(index) {
5614
+ return parseInt(hex.slice(index, index + 2), 16);
5615
+ };
5616
+ if (hex.length === 3 || hex.length === 4) {
5617
+ return {
5618
+ r: expand(hex[0]),
5619
+ g: expand(hex[1]),
5620
+ b: expand(hex[2]),
5621
+ a: hex.length === 4 ? expand(hex[3]) / 255 : 1
5622
+ };
5623
+ }
5624
+ if (hex.length === 6 || hex.length === 8) {
5625
+ return {
5626
+ r: pair(0),
5627
+ g: pair(2),
5628
+ b: pair(4),
5629
+ a: hex.length === 8 ? pair(6) / 255 : 1
5630
+ };
5631
+ }
5632
+ return null;
5633
+ }
5634
+ function extractFunctionArgs(value, name) {
5635
+ if (!value.startsWith(name + "(") || !value.endsWith(")")) {
5636
+ return null;
5637
+ }
5638
+ return value.slice(name.length + 1, -1);
5639
+ }
5640
+ function parseRgb(value) {
5641
+ var _extractFunctionArgs;
5642
+ var args = (_extractFunctionArgs = extractFunctionArgs(value, "rgba")) !== null && _extractFunctionArgs !== void 0 ? _extractFunctionArgs : extractFunctionArgs(value, "rgb");
5643
+ if (args === null) {
5644
+ return null;
5645
+ }
5646
+ var split = splitComponents(args);
5647
+ if (!split) {
5648
+ return null;
5649
+ }
5650
+ var channels = split.components.map(function (component) {
5651
+ return component === "none" ? 0 : parseNumberOrPercentage(component, 255);
5652
+ });
5653
+ var alpha = parseAlpha(split.alpha);
5654
+ if (channels.some(function (channel) {
5655
+ return channel === null;
5656
+ }) || alpha === null) {
5657
+ return null;
5658
+ }
5659
+ return {
5660
+ r: clamp(channels[0], 0, 255),
5661
+ g: clamp(channels[1], 0, 255),
5662
+ b: clamp(channels[2], 0, 255),
5663
+ a: alpha
5664
+ };
5665
+ }
5666
+ function parseHsl(value) {
5667
+ var _extractFunctionArgs2, _parsePercentage, _parsePercentage2;
5668
+ var args = (_extractFunctionArgs2 = extractFunctionArgs(value, "hsla")) !== null && _extractFunctionArgs2 !== void 0 ? _extractFunctionArgs2 : extractFunctionArgs(value, "hsl");
5669
+ if (args === null) {
5670
+ return null;
5671
+ }
5672
+ var split = splitComponents(args);
5673
+ if (!split) {
5674
+ return null;
5675
+ }
5676
+ var _split$components = _slicedToArray(split.components, 3),
5677
+ rawHue = _split$components[0],
5678
+ rawSaturation = _split$components[1],
5679
+ rawLightness = _split$components[2];
5680
+ var hue = rawHue === "none" ? 0 : parseHue(rawHue);
5681
+ // CSS requires percentages for s/l in hsl(), but the modern syntax also
5682
+ // allows bare numbers, so accept both.
5683
+ var saturation = rawSaturation === "none" ? 0 : (_parsePercentage = parsePercentage(rawSaturation)) !== null && _parsePercentage !== void 0 ? _parsePercentage : parseNumber(rawSaturation);
5684
+ var lightness = rawLightness === "none" ? 0 : (_parsePercentage2 = parsePercentage(rawLightness)) !== null && _parsePercentage2 !== void 0 ? _parsePercentage2 : parseNumber(rawLightness);
5685
+ var alpha = parseAlpha(split.alpha);
5686
+ if (hue === null || saturation === null || lightness === null || alpha === null) {
5687
+ return null;
5688
+ }
5689
+ return _objectSpread2(_objectSpread2({}, hslToRgb(normalizeHue(hue), clamp(saturation, 0, 100), clamp(lightness, 0, 100))), {}, {
5690
+ a: alpha
5691
+ });
5692
+ }
5693
+ function parseOklch(value) {
5694
+ var args = extractFunctionArgs(value, "oklch");
5695
+ if (args === null) {
5696
+ return null;
5697
+ }
5698
+ var split = splitComponents(args);
5699
+ if (!split) {
5700
+ return null;
5701
+ }
5702
+ var _split$components2 = _slicedToArray(split.components, 3),
5703
+ rawLightness = _split$components2[0],
5704
+ rawChroma = _split$components2[1],
5705
+ rawHue = _split$components2[2];
5706
+ // Lightness is a <number> in 0-1 or a <percentage>, chroma is a <number>
5707
+ // where 0.4 is roughly the maximum, or a <percentage> where 100% = 0.4.
5708
+ var lightness = rawLightness === "none" ? 0 : parseNumberOrPercentage(rawLightness, 1);
5709
+ var chroma = rawChroma === "none" ? 0 : parseNumberOrPercentage(rawChroma, 0.4);
5710
+ var hue = rawHue === "none" ? 0 : parseHue(rawHue);
5711
+ var alpha = parseAlpha(split.alpha);
5712
+ if (lightness === null || chroma === null || hue === null || alpha === null) {
5713
+ return null;
5714
+ }
5715
+ return _objectSpread2(_objectSpread2({}, oklchToRgb(clamp(lightness, 0, 1), Math.max(0, chroma), normalizeHue(hue))), {}, {
5716
+ a: alpha
5717
+ });
5718
+ }
5719
+
5720
+ /**
5721
+ * Parses a CSS color string into sRGB channels.
5722
+ *
5723
+ * Accepts hex (3, 4, 6 and 8 digits), `rgb()` / `rgba()`, `hsl()` / `hsla()`
5724
+ * and `oklch()`, in both the legacy comma and the modern space syntax. Returns
5725
+ * `null` if the value is not a color we can parse - notably: named colors
5726
+ * (`red`), `color()`, `lab()` and `color-mix()` are not supported.
5727
+ */
5728
+ function parseColor(value) {
5729
+ var normalized = value.trim().toLowerCase();
5730
+ if (normalized === "") {
5731
+ return null;
5732
+ }
5733
+ switch (detectColorFormat(normalized)) {
5734
+ case "hex":
5735
+ return parseHex(normalized);
5736
+ case "rgb":
5737
+ return parseRgb(normalized);
5738
+ case "hsl":
5739
+ return parseHsl(normalized);
5740
+ case "oklch":
5741
+ return parseOklch(normalized);
5742
+ default:
5743
+ return null;
5744
+ }
5745
+ }
5746
+
5747
+ /**
5748
+ * Rounds to at most `decimals` decimals, without trailing zeros.
5749
+ */
5750
+ function round(value, decimals) {
5751
+ var factor = Math.pow(10, decimals);
5752
+ // `|| 0` normalizes -0 to 0
5753
+ return Math.round(value * factor) / factor || 0;
5754
+ }
5755
+ function toHexPair(value) {
5756
+ return clamp(Math.round(value), 0, 255).toString(16).padStart(2, "0");
5757
+ }
5758
+ function rgbToHsl(r, g, b) {
5759
+ var red = r / 255;
5760
+ var green = g / 255;
5761
+ var blue = b / 255;
5762
+ var max = Math.max(red, green, blue);
5763
+ var min = Math.min(red, green, blue);
5764
+ var delta = max - min;
5765
+ var l = (max + min) / 2;
5766
+ if (delta === 0) {
5767
+ return {
5768
+ h: 0,
5769
+ s: 0,
5770
+ l: l * 100
5771
+ };
5772
+ }
5773
+ var s = delta / (1 - Math.abs(2 * l - 1));
5774
+ var h;
5775
+ if (max === red) {
5776
+ h = (green - blue) / delta % 6;
5777
+ } else if (max === green) {
5778
+ h = (blue - red) / delta + 2;
5779
+ } else {
5780
+ h = (red - green) / delta + 4;
5781
+ }
5782
+ return {
5783
+ h: normalizeHue(h * 60),
5784
+ s: s * 100,
5785
+ l: l * 100
5786
+ };
5787
+ }
5788
+ function hslToRgb(h, s, l) {
5789
+ var saturation = s / 100;
5790
+ var lightness = l / 100;
5791
+ var c = (1 - Math.abs(2 * lightness - 1)) * saturation;
5792
+ var hPrime = normalizeHue(h) / 60;
5793
+ var x = c * (1 - Math.abs(hPrime % 2 - 1));
5794
+ var m = lightness - c / 2;
5795
+ var rgb;
5796
+ if (hPrime < 1) {
5797
+ rgb = [c, x, 0];
5798
+ } else if (hPrime < 2) {
5799
+ rgb = [x, c, 0];
5800
+ } else if (hPrime < 3) {
5801
+ rgb = [0, c, x];
5802
+ } else if (hPrime < 4) {
5803
+ rgb = [0, x, c];
5804
+ } else if (hPrime < 5) {
5805
+ rgb = [x, 0, c];
5806
+ } else {
5807
+ rgb = [c, 0, x];
5808
+ }
5809
+ return {
5810
+ r: (rgb[0] + m) * 255,
5811
+ g: (rgb[1] + m) * 255,
5812
+ b: (rgb[2] + m) * 255
5813
+ };
5814
+ }
5815
+ function srgbToLinear(channel) {
5816
+ var c = channel / 255;
5817
+ return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
5818
+ }
5819
+ function linearToSrgb(channel) {
5820
+ var c = channel <= 0.0031308 ? channel * 12.92 : 1.055 * Math.pow(channel, 1 / 2.4) - 0.055;
5821
+ return clamp(c * 255, 0, 255);
5822
+ }
5823
+
5824
+ /**
5825
+ * sRGB to Oklch, using Björn Ottosson's Oklab matrices.
5826
+ */
5827
+ function rgbToOklch(r, g, b) {
5828
+ var lr = srgbToLinear(r);
5829
+ var lg = srgbToLinear(g);
5830
+ var lb = srgbToLinear(b);
5831
+ var _long = Math.cbrt(0.4122214708 * lr + 0.5363325363 * lg + 0.0514459929 * lb);
5832
+ var medium = Math.cbrt(0.2119034982 * lr + 0.6806995451 * lg + 0.1073969566 * lb);
5833
+ var _short = Math.cbrt(0.0883024619 * lr + 0.2817188376 * lg + 0.6299787005 * lb);
5834
+ var lightness = 0.2104542553 * _long + 0.793617785 * medium - 0.0040720468 * _short;
5835
+ var a = 1.9779984951 * _long - 2.428592205 * medium + 0.4505937099 * _short;
5836
+ var bComponent = 0.0259040371 * _long + 0.7827717662 * medium - 0.808675766 * _short;
5837
+ var chroma = Math.sqrt(a * a + bComponent * bComponent);
5838
+ // Achromatic colors have an undefined hue: report 0 rather than the noise
5839
+ // that atan2 of two near-zero numbers produces.
5840
+ var hue = chroma < 1e-6 ? 0 : normalizeHue(Math.atan2(bComponent, a) * 180 / Math.PI);
5841
+ return {
5842
+ l: clamp(lightness, 0, 1),
5843
+ c: chroma,
5844
+ h: hue
5845
+ };
5846
+ }
5847
+
5848
+ /**
5849
+ * Oklch to sRGB. Out of gamut colors are clipped per channel.
5850
+ */
5851
+ function oklchToRgb(l, c, h) {
5852
+ var hueRadians = normalizeHue(h) * Math.PI / 180;
5853
+ var a = c * Math.cos(hueRadians);
5854
+ var bComponent = c * Math.sin(hueRadians);
5855
+ var _long2 = Math.pow(l + 0.3963377774 * a + 0.2158037573 * bComponent, 3);
5856
+ var medium = Math.pow(l - 0.1055613458 * a - 0.0638541728 * bComponent, 3);
5857
+ var _short2 = Math.pow(l - 0.0894841775 * a - 1.291485548 * bComponent, 3);
5858
+ return {
5859
+ r: linearToSrgb(4.0767416621 * _long2 - 3.3077115913 * medium + 0.2309699292 * _short2),
5860
+ g: linearToSrgb(-1.2684380046 * _long2 + 2.6097574011 * medium - 0.3413193965 * _short2),
5861
+ b: linearToSrgb(-0.0041960863 * _long2 - 0.7034186147 * medium + 1.707614701 * _short2)
5862
+ };
5863
+ }
5864
+
5865
+ /**
5866
+ * Serializes a color to the canonical string of the given format.
5867
+ *
5868
+ * The modern, space separated CSS syntax is used for the color functions
5869
+ * (`rgb(255 0 0 / 0.5)`). Alpha is only included when it is not fully opaque.
5870
+ */
5871
+ function formatColor(color, format) {
5872
+ var alpha = clamp(color.a, 0, 1);
5873
+ var alphaSuffix = alpha >= 1 ? "" : " / ".concat(round(alpha, 4));
5874
+ switch (format) {
5875
+ case "hex":
5876
+ {
5877
+ var hex = "#".concat(toHexPair(color.r)).concat(toHexPair(color.g)).concat(toHexPair(color.b));
5878
+ return alpha >= 1 ? hex : "".concat(hex).concat(toHexPair(alpha * 255));
5879
+ }
5880
+ case "rgb":
5881
+ {
5882
+ var r = clamp(Math.round(color.r), 0, 255);
5883
+ var g = clamp(Math.round(color.g), 0, 255);
5884
+ var b = clamp(Math.round(color.b), 0, 255);
5885
+ return "rgb(".concat(r, " ").concat(g, " ").concat(b).concat(alphaSuffix, ")");
5886
+ }
5887
+ case "hsl":
5888
+ {
5889
+ var _rgbToHsl = rgbToHsl(color.r, color.g, color.b),
5890
+ h = _rgbToHsl.h,
5891
+ s = _rgbToHsl.s,
5892
+ l = _rgbToHsl.l;
5893
+ return "hsl(".concat(round(h, 2), " ").concat(round(s, 2), "% ").concat(round(l, 2), "%").concat(alphaSuffix, ")");
5894
+ }
5895
+ case "oklch":
5896
+ {
5897
+ var _rgbToOklch = rgbToOklch(color.r, color.g, color.b),
5898
+ _l = _rgbToOklch.l,
5899
+ c = _rgbToOklch.c,
5900
+ _h = _rgbToOklch.h;
5901
+ return "oklch(".concat(round(_l, 4), " ").concat(round(c, 4), " ").concat(round(_h, 2)).concat(alphaSuffix, ")");
5902
+ }
5903
+ }
5904
+ }
5905
+
5906
+ /**
5907
+ * Converts a color string to the canonical string of the given format, or
5908
+ * `null` if the input cannot be parsed.
5909
+ */
5910
+ function convertColor(value, format) {
5911
+ var parsed = parseColor(value);
5912
+ if (parsed === null) {
5913
+ return null;
5914
+ }
5915
+ return formatColor(parsed, format);
5916
+ }
5917
+
5918
+ /**
5919
+ * `#rrggbb`, which is what `<input type="color">` uses as its value.
5920
+ */
5921
+ function colorToHex(color) {
5922
+ return "#".concat(toHexPair(color.r)).concat(toHexPair(color.g)).concat(toHexPair(color.b));
5923
+ }
5924
+
5925
+ /**
5926
+ * An example of the canonical output of each format, used in error messages so
5927
+ * that the expected syntax is obvious from the error alone.
5928
+ */
5929
+ var FORMAT_EXAMPLES = {
5930
+ hex: "#3b82f6",
5931
+ rgb: "rgb(59 130 246)",
5932
+ hsl: "hsl(217.22 91.22% 59.8%)",
5933
+ oklch: "oklch(0.6231 0.188 259.81)"
5934
+ };
5935
+ var ColorSchema = /*#__PURE__*/function (_Schema) {
5936
+ function ColorSchema(options) {
5937
+ var _this;
5938
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
5939
+ var customValidateFunctions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
5940
+ var isReadonly = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
5941
+ var isHidden = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
5942
+ var description = arguments.length > 5 ? arguments[5] : undefined;
5943
+ _classCallCheck(this, ColorSchema);
5944
+ _this = _callSuper(this, ColorSchema);
5945
+ _this.options = options;
5946
+ _this.opt = opt;
5947
+ _this.customValidateFunctions = customValidateFunctions;
5948
+ _this.isReadonly = isReadonly;
5949
+ _this.isHidden = isHidden;
5950
+ _this.description = description;
5951
+ return _this;
5952
+ }
5953
+ _inherits(ColorSchema, _Schema);
5954
+ return _createClass(ColorSchema, [{
5955
+ key: "describe",
5956
+ value: function describe(description) {
5957
+ return new ColorSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined);
5958
+ }
5959
+ }, {
5960
+ key: "validate",
5961
+ value: function validate(validationFunction) {
5962
+ return new ColorSchema(this.options, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.isReadonly, this.isHidden, this.description);
5963
+ }
5964
+ }, {
5965
+ key: "executeCustomValidateAt",
5966
+ value: function executeCustomValidateAt(path, src) {
5967
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
5968
+ path: path
5969
+ });
5970
+ }
5971
+ }, {
5972
+ key: "executeValidate",
5973
+ value: function executeValidate(path, src) {
5974
+ var _this$options$format, _this$options;
5975
+ var errors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
5976
+ path: path
5977
+ });
5978
+ if (this.opt && (src === null || src === undefined)) {
5979
+ return errors.length > 0 ? _defineProperty({}, path, errors) : false;
5980
+ }
5981
+ if (typeof src !== "string") {
5982
+ errors.push({
5983
+ message: "Expected 'string', got '".concat(_typeof(src), "'"),
5984
+ value: src
5985
+ });
5986
+ return _defineProperty({}, path, errors);
5987
+ }
5988
+ var expectedFormat = (_this$options$format = (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.format) !== null && _this$options$format !== void 0 ? _this$options$format : DEFAULT_COLOR_FORMAT;
5989
+ var parsed = parseColor(src);
5990
+ if (parsed === null) {
5991
+ errors.push({
5992
+ message: "Invalid color: '".concat(src, "'. Expected a CSS color in the '").concat(expectedFormat, "' format (e.g. '").concat(FORMAT_EXAMPLES[expectedFormat], "')"),
5993
+ value: src
5994
+ });
5995
+ } else {
5996
+ var _this$options3;
5997
+ var actualFormat = detectColorFormat(src);
5998
+ if (actualFormat !== expectedFormat) {
5999
+ var _this$options2;
6000
+ // Drop alpha from the SUGGESTION when alpha is not enabled, the same way
6001
+ // the field's commit does. Keeping it would suggest a value that fails
6002
+ // the alpha check immediately below, so following the advice would not
6003
+ // clear the error.
6004
+ var suggestion = formatColor((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.alpha ? parsed : _objectSpread2(_objectSpread2({}, parsed), {}, {
6005
+ a: 1
6006
+ }), expectedFormat);
6007
+ errors.push({
6008
+ message: "Expected a color in the '".concat(expectedFormat, "' format (e.g. '").concat(FORMAT_EXAMPLES[expectedFormat], "'), got '").concat(src, "'. Did you mean '").concat(suggestion, "'?"),
6009
+ value: src
6010
+ });
6011
+ }
6012
+ if (!((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.alpha) && parsed.a < 1) {
6013
+ errors.push({
6014
+ message: "Color '".concat(src, "' has an alpha channel, but alpha is not enabled. Use s.color({ alpha: true }) to allow transparency"),
6015
+ value: src
6016
+ });
6017
+ }
6018
+ }
6019
+ if (errors.length > 0) {
6020
+ return _defineProperty({}, path, errors);
6021
+ }
6022
+ return false;
6023
+ }
6024
+ }, {
6025
+ key: "executeAssert",
6026
+ value: function executeAssert(path, src) {
6027
+ if (this.opt && src === null) {
6028
+ return {
6029
+ success: true,
6030
+ data: src
6031
+ };
6032
+ }
6033
+ if (src === null) {
6034
+ return {
6035
+ success: false,
6036
+ errors: _defineProperty({}, path, [{
6037
+ message: "Expected 'string', got 'null'",
6038
+ typeError: true
6039
+ }])
6040
+ };
6041
+ }
6042
+ if (typeof src !== "string") {
6043
+ return {
6044
+ success: false,
6045
+ errors: _defineProperty({}, path, [{
6046
+ message: "Expected 'string', got '".concat(_typeof(src), "'"),
6047
+ typeError: true
6048
+ }])
6049
+ };
6050
+ }
6051
+ return {
6052
+ success: true,
6053
+ data: src
6054
+ };
6055
+ }
6056
+ }, {
6057
+ key: "nullable",
6058
+ value: function nullable() {
6059
+ return new ColorSchema(this.options, true, [], this.isReadonly, this.isHidden, this.description);
6060
+ }
6061
+ }, {
6062
+ key: "readonly",
6063
+ value: function readonly() {
6064
+ return new ColorSchema(this.options, this.opt, this.customValidateFunctions, true, this.isHidden, this.description);
6065
+ }
6066
+ }, {
6067
+ key: "hidden",
6068
+ value: function hidden() {
6069
+ return new ColorSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
6070
+ }
6071
+ }, {
6072
+ key: "executeSerialize",
6073
+ value: function executeSerialize() {
6074
+ var _this$customValidateF;
6075
+ return {
6076
+ type: "color",
6077
+ opt: this.opt,
6078
+ options: this.options,
6079
+ customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
6080
+ readonly: this.isReadonly,
6081
+ hidden: this.isHidden,
6082
+ description: this.description
6083
+ };
6084
+ }
6085
+ }, {
6086
+ key: "executeRender",
6087
+ value: function executeRender() {
6088
+ return {};
6089
+ }
6090
+ }]);
6091
+ }(Schema);
6092
+ var color = function color(options) {
6093
+ return new ColorSchema(options);
6094
+ };
6095
+
4920
6096
  function router(router, keyOrItem, maybeItem) {
4921
6097
  if (maybeItem) {
4922
6098
  return new RecordSchema(maybeItem, false, [], router, keyOrItem);
@@ -5006,6 +6182,7 @@ function initSchema() {
5006
6182
  files: files,
5007
6183
  date: date,
5008
6184
  datetime: datetime,
6185
+ color: color,
5009
6186
  route: route,
5010
6187
  router: router,
5011
6188
  images: images
@@ -5133,7 +6310,8 @@ var initVal = function initVal(config) {
5133
6310
  define: define,
5134
6311
  remote: initRemote(),
5135
6312
  file: initFile(config),
5136
- image: initImage(config)
6313
+ image: initImage(config),
6314
+ json: json
5137
6315
  },
5138
6316
  s: s,
5139
6317
  config: config
@@ -5160,142 +6338,6 @@ function modules(config, modules) {
5160
6338
  };
5161
6339
  }
5162
6340
 
5163
- function _regeneratorDefine(e, r, n, t) {
5164
- var i = Object.defineProperty;
5165
- try {
5166
- i({}, "", {});
5167
- } catch (e) {
5168
- i = 0;
5169
- }
5170
- _regeneratorDefine = function (e, r, n, t) {
5171
- function o(r, n) {
5172
- _regeneratorDefine(e, r, function (e) {
5173
- return this._invoke(r, n, e);
5174
- });
5175
- }
5176
- r ? i ? i(e, r, {
5177
- value: n,
5178
- enumerable: !t,
5179
- configurable: !t,
5180
- writable: !t
5181
- }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
5182
- }, _regeneratorDefine(e, r, n, t);
5183
- }
5184
-
5185
- function _regenerator() {
5186
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
5187
- var e,
5188
- t,
5189
- r = "function" == typeof Symbol ? Symbol : {},
5190
- n = r.iterator || "@@iterator",
5191
- o = r.toStringTag || "@@toStringTag";
5192
- function i(r, n, o, i) {
5193
- var c = n && n.prototype instanceof Generator ? n : Generator,
5194
- u = Object.create(c.prototype);
5195
- return _regeneratorDefine(u, "_invoke", function (r, n, o) {
5196
- var i,
5197
- c,
5198
- u,
5199
- f = 0,
5200
- p = o || [],
5201
- y = !1,
5202
- G = {
5203
- p: 0,
5204
- n: 0,
5205
- v: e,
5206
- a: d,
5207
- f: d.bind(e, 4),
5208
- d: function (t, r) {
5209
- return i = t, c = 0, u = e, G.n = r, a;
5210
- }
5211
- };
5212
- function d(r, n) {
5213
- for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
5214
- var o,
5215
- i = p[t],
5216
- d = G.p,
5217
- l = i[2];
5218
- r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
5219
- }
5220
- if (o || r > 1) return a;
5221
- throw y = !0, n;
5222
- }
5223
- return function (o, p, l) {
5224
- if (f > 1) throw TypeError("Generator is already running");
5225
- for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
5226
- i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
5227
- try {
5228
- if (f = 2, i) {
5229
- if (c || (o = "next"), t = i[o]) {
5230
- if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
5231
- if (!t.done) return t;
5232
- u = t.value, c < 2 && (c = 0);
5233
- } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
5234
- i = e;
5235
- } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
5236
- } catch (t) {
5237
- i = e, c = 1, u = t;
5238
- } finally {
5239
- f = 1;
5240
- }
5241
- }
5242
- return {
5243
- value: t,
5244
- done: y
5245
- };
5246
- };
5247
- }(r, o, i), !0), u;
5248
- }
5249
- var a = {};
5250
- function Generator() {}
5251
- function GeneratorFunction() {}
5252
- function GeneratorFunctionPrototype() {}
5253
- t = Object.getPrototypeOf;
5254
- var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
5255
- return this;
5256
- }), t),
5257
- u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
5258
- function f(e) {
5259
- return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
5260
- }
5261
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
5262
- return this;
5263
- }), _regeneratorDefine(u, "toString", function () {
5264
- return "[object Generator]";
5265
- }), (_regenerator = function () {
5266
- return {
5267
- w: i,
5268
- m: f
5269
- };
5270
- })();
5271
- }
5272
-
5273
- function asyncGeneratorStep(n, t, e, r, o, a, c) {
5274
- try {
5275
- var i = n[a](c),
5276
- u = i.value;
5277
- } catch (n) {
5278
- return void e(n);
5279
- }
5280
- i.done ? t(u) : Promise.resolve(u).then(r, o);
5281
- }
5282
- function _asyncToGenerator(n) {
5283
- return function () {
5284
- var t = this,
5285
- e = arguments;
5286
- return new Promise(function (r, o) {
5287
- var a = n.apply(t, e);
5288
- function _next(n) {
5289
- asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
5290
- }
5291
- function _throw(n) {
5292
- asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
5293
- }
5294
- _next(void 0);
5295
- });
5296
- };
5297
- }
5298
-
5299
6341
  /**
5300
6342
  * From: https://github.com/kawanet/sha256-uint8array/commit/a035f83824c319d01ca1e7559fdcf1632c0cd6c4
5301
6343
  *
@@ -6795,7 +7837,7 @@ function deserializeSchema(serialized) {
6795
7837
  return schema;
6796
7838
  }
6797
7839
  function deserializeSchemaImpl(serialized) {
6798
- var _serialized$options, _serialized$options2, _serialized$accept, _serialized$directory, _serialized$remote;
7840
+ var _serialized$options, _serialized$options2, _serialized$accept, _serialized$directory, _serialized$remote, _serialized$jsonValue;
6799
7841
  switch (serialized.type) {
6800
7842
  case "string":
6801
7843
  return new StringSchema(_objectSpread2(_objectSpread2({}, serialized.options), {}, {
@@ -6844,7 +7886,7 @@ function deserializeSchemaImpl(serialized) {
6844
7886
  directory: (_serialized$directory = serialized.directory) !== null && _serialized$directory !== void 0 ? _serialized$directory : "/public/val",
6845
7887
  remote: (_serialized$remote = serialized.remote) !== null && _serialized$remote !== void 0 ? _serialized$remote : false,
6846
7888
  altSchema: serialized.alt ? deserializeSchema(serialized.alt) : undefined
6847
- } : undefined, false, false, serialized.description);
7889
+ } : undefined, false, false, serialized.description, (_serialized$jsonValue = serialized.jsonValues) !== null && _serialized$jsonValue !== void 0 ? _serialized$jsonValue : false);
6848
7890
  case "keyOf":
6849
7891
  return new KeyOfSchema(serialized.schema, serialized.path, serialized.opt, [], false, false, serialized.description);
6850
7892
  case "route":
@@ -6863,6 +7905,8 @@ function deserializeSchemaImpl(serialized) {
6863
7905
  return new DateSchema(serialized.options, serialized.opt, [], false, false, serialized.description);
6864
7906
  case "dateTime":
6865
7907
  return new DateTimeSchema(serialized.options, serialized.opt, [], false, false, serialized.description);
7908
+ case "color":
7909
+ return new ColorSchema(serialized.options, serialized.opt, [], false, false, serialized.description);
6866
7910
  default:
6867
7911
  {
6868
7912
  var exhaustiveCheck = serialized;
@@ -7149,6 +8193,13 @@ var Internal = {
7149
8193
  joinModuleFilePathAndModulePath: joinModuleFilePathAndModulePath,
7150
8194
  nextAppRouter: nextAppRouter,
7151
8195
  externalPageRouter: externalPageRouter,
8196
+ color: {
8197
+ parseColor: parseColor,
8198
+ formatColor: formatColor,
8199
+ convertColor: convertColor,
8200
+ detectColorFormat: detectColorFormat,
8201
+ colorToHex: colorToHex
8202
+ },
7152
8203
  remote: {
7153
8204
  createRemoteRef: createRemoteRef,
7154
8205
  getValidationBasis: getValidationBasis,
@@ -7163,6 +8214,9 @@ var Internal = {
7163
8214
  },
7164
8215
  isVal: isVal,
7165
8216
  isFile: isFile,
8217
+ isJson: isJson,
8218
+ getJsonImport: getJsonImport,
8219
+ resolveJsonValues: resolveJsonValues,
7166
8220
  createValPathOfItem: createValPathOfItem,
7167
8221
  getSHA256Hash: getSHA256Hash,
7168
8222
  initSchema: initSchema,
@@ -7226,4 +8280,4 @@ function tryJsonParse(str) {
7226
8280
  }
7227
8281
  }
7228
8282
 
7229
- export { ArraySchema as A, BooleanSchema as B, DEFAULT_CONTENT_HOST as D, FATAL_ERROR_TYPES as F, GenericSelector as G, Internal as I, KeyOfSchema as K, LiteralSchema as L, ModuleFilePathSep as M, NumberSchema as N, ObjectSchema as O, PatchError as P, RecordSchema as R, Schema as S, UnionSchema as U, VAL_EXTENSION as V, _typeof as _, _slicedToArray as a, _createClass as b, _classCallCheck as c, _toConsumableArray as d, DEFAULT_APP_HOST as e, extractValModules as f, DEFAULT_VAL_REMOTE_HOST as g, FILE_REF_PROP as h, initVal as i, FILE_REF_SUBTYPE_TAG as j, derefPatch as k, StringSchema as l, modules as m, ImageSchema as n, FileSchema as o, DateSchema as p, DateTimeSchema as q, RouteSchema as r, splitModuleFilePathAndModulePath as s, RichTextSchema as t, deserializeSchema as u, getSourcePathFromRoute as v };
8283
+ export { ArraySchema as A, BooleanSchema as B, ColorSchema as C, DEFAULT_CONTENT_HOST as D, FATAL_ERROR_TYPES as F, GenericSelector as G, Internal as I, KeyOfSchema as K, LiteralSchema as L, ModuleFilePathSep as M, NumberSchema as N, ObjectSchema as O, PatchError as P, RecordSchema as R, Schema as S, UnionSchema as U, VAL_EXTENSION as V, _typeof as _, _slicedToArray as a, _createClass as b, _classCallCheck as c, _toConsumableArray as d, DEFAULT_APP_HOST as e, extractValModules as f, DEFAULT_VAL_REMOTE_HOST as g, FILE_REF_PROP as h, initVal as i, FILE_REF_SUBTYPE_TAG as j, derefPatch as k, StringSchema as l, modules as m, ImageSchema as n, FileSchema as o, DateSchema as p, COLOR_FORMATS as q, DEFAULT_COLOR_FORMAT as r, splitModuleFilePathAndModulePath as s, DateTimeSchema as t, RouteSchema as u, RichTextSchema as v, deserializeSchema as w, getSourcePathFromRoute as x };