@valbuild/core 0.66.0 → 0.67.1

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.
@@ -4,13 +4,11 @@ export type { InitVal, ValConfig, ValConstructor, ContentConstructor, } from "./
4
4
  export { Schema, type SerializedSchema, type SelectorOfSchema } from "./schema/index.js";
5
5
  export type { ImageMetadata } from "./schema/image.js";
6
6
  export type { FileMetadata } from "./schema/file.js";
7
- export type { LinkSource } from "./source/link.js";
8
7
  export type { ValModule, SerializedModule, InferValModuleType } from "./module.js";
9
8
  export type { SourceObject, SourcePrimitive, Source } from "./source/index.js";
10
9
  export type { FileSource } from "./source/file.js";
11
10
  export type { RawString } from "./schema/string.js";
12
11
  export type { ImageSource } from "./source/image.js";
13
- export { RT_IMAGE_TAG } from "./source/richtext.js";
14
12
  export type { AllRichTextOptions, Bold, Styles, HeadingNode, ImageNode, Italic, LineThrough, ListItemNode, LinkNode, OrderedListNode, ParagraphNode, BrNode, RichTextNode, RichTextOptions, RichTextSource, BlockNode, SpanNode, UnorderedListNode, } from "./source/richtext.js";
15
13
  export { type Val, type SerializedVal, type ModuleFilePath, type PatchId, type ModulePath, type SourcePath, type JsonOfSource, } from "./val/index.js";
16
14
  export type { Json, JsonPrimitive, JsonArray, JsonObject } from "./Json.js";
@@ -19,6 +19,24 @@ export type InitSchema = {
19
19
  readonly number: typeof number;
20
20
  readonly union: typeof union;
21
21
  readonly richtext: typeof richtext;
22
+ /**
23
+ * Define a image source.
24
+ *
25
+ * Use c.image to create an image source.
26
+ *
27
+ * @example
28
+ * const schema = s.image();
29
+ * export default c.define("/example.val.ts", schema, c.image("/public/val/example.png", {
30
+ * width: 100,
31
+ * height: 100,
32
+ * mimeType: "image/png",
33
+ * hotspot: {
34
+ * x: 0.5,
35
+ * y: 0.5
36
+ * }
37
+ * }));
38
+ *
39
+ */
22
40
  readonly image: typeof image;
23
41
  readonly literal: typeof literal;
24
42
  readonly keyOf: typeof keyOf;
@@ -2,16 +2,11 @@ import { define } from "./module.js";
2
2
  import { InitSchema } from "./initSchema.js";
3
3
  import { getValPath as getPath } from "./val/index.js";
4
4
  import { initFile } from "./source/file.js";
5
- import { richtext } from "./source/richtext.js";
6
- import { link } from "./source/link.js";
5
+ import { initImage } from "./source/image.js";
7
6
  export type ContentConstructor = {
8
7
  define: typeof define;
9
8
  file: ReturnType<typeof initFile>;
10
- rt: {
11
- image: ReturnType<typeof initFile>;
12
- link: typeof link;
13
- };
14
- richtext: typeof richtext;
9
+ image: ReturnType<typeof initImage>;
15
10
  };
16
11
  export type ValConstructor = {
17
12
  unstable_getPath: typeof getPath;
@@ -18,6 +18,7 @@ export type ImageMetadata = {
18
18
  width: number;
19
19
  height: number;
20
20
  mimeType: string;
21
+ alt?: string;
21
22
  hotspot?: {
22
23
  x: number;
23
24
  y: number;
@@ -1,2 +1,2 @@
1
- export declare const ValidationFix: readonly ["image:add-metadata", "image:replace-metadata", "file:add-metadata", "file:check-metadata", "fix:deprecated-richtext"];
1
+ export declare const ValidationFix: readonly ["image:change-extension", "image:add-metadata", "image:check-metadata", "file:change-extension", "file:add-metadata", "file:check-metadata"];
2
2
  export type ValidationFix = (typeof ValidationFix)[number];
@@ -11,10 +11,10 @@ import { Schema } from "../schema/index.js";
11
11
  import type { A } from "ts-toolbelt";
12
12
  import { FileSource } from "../source/file.js";
13
13
  import { AllRichTextOptions, RichTextSource } from "../source/richtext.js";
14
- import { ImageMetadata } from "../schema/image.js";
15
14
  import { ImageSelector } from "./image.js";
16
15
  import { RichTextSelector } from "./richtext.js";
17
- export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends FileSource<infer M> ? M extends ImageMetadata ? ImageSelector : FileSelector<M> : T extends RichTextSource<infer O> ? RichTextSelector<O> : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
16
+ import { ImageSource } from "../source/image.js";
17
+ export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends ImageSource ? ImageSelector : T extends FileSource<infer M> ? FileSelector<M> : T extends RichTextSource<infer O> ? RichTextSelector<O> : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
18
18
  export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
19
19
  [key: string]: SelectorSource;
20
20
  } | FileSource | RichTextSource<AllRichTextOptions> | GenericSelector<Source>;
@@ -1,7 +1,19 @@
1
+ import { VAL_EXTENSION } from "./index.js";
2
+ import { ValConfig } from "../initVal.js";
1
3
  import { ImageMetadata } from "../schema/image.js";
2
- import { FileSource } from "./file.js";
4
+ import { FILE_REF_PROP, FILE_REF_SUBTYPE_TAG } from "./file.js";
3
5
  /**
4
6
  * A image source represents the path to a (local) image.
5
7
  *
6
8
  */
7
- export type ImageSource<Metadata extends ImageMetadata | undefined = ImageMetadata> = FileSource<Metadata>;
9
+ export type ImageSource<Metadata extends ImageMetadata | undefined = ImageMetadata | undefined> = {
10
+ readonly [FILE_REF_PROP]: string;
11
+ readonly [VAL_EXTENSION]: "file";
12
+ readonly [FILE_REF_SUBTYPE_TAG]: "image";
13
+ readonly metadata?: Metadata;
14
+ readonly patch_id?: string;
15
+ };
16
+ export declare const initImage: (config?: ValConfig) => {
17
+ (ref: `${`/public/${string}`}/${string}`, metadata: ImageMetadata): ImageSource<ImageMetadata>;
18
+ (ref: `${`/public/${string}`}/${string}`, metadata?: undefined): ImageSource<undefined>;
19
+ };
@@ -1,7 +1,4 @@
1
- import { LinkSource } from "./link.js";
2
1
  import { ImageSource } from "./image.js";
3
- import { ImageMetadata } from "../schema/image.js";
4
- import { FileSource } from "./file.js";
5
2
  export type RichTextOptions = Partial<{
6
3
  style: Partial<{
7
4
  bold: boolean;
@@ -103,8 +100,4 @@ export type BlockNode<O extends RichTextOptions> = HeadingNode<O> | ParagraphNod
103
100
  * RichText as defined in a ValModule
104
101
  **/
105
102
  export type RichTextSource<O extends RichTextOptions> = BlockNode<O>[];
106
- export declare function richtext<O extends RichTextOptions>(templateStrings: TemplateStringsArray, ...nodes: (ImageSource | LinkSource)[]): RichTextSource<{}>;
107
- export declare const RT_IMAGE_TAG = "rt_image";
108
- export type RTImageMetadata = ImageMetadata;
109
- export declare function image(ref: `/public/${string}`, metadata?: RTImageMetadata): FileSource<RTImageMetadata>;
110
103
  export {};
@@ -1,28 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var result = require('./result-bb1f436e.cjs.dev.js');
4
- var marked = require('marked');
5
- var core = require('@valbuild/core');
6
-
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
20
- }
21
- n["default"] = e;
22
- return Object.freeze(n);
23
- }
24
-
25
- var marked__namespace = /*#__PURE__*/_interopNamespace(marked);
26
4
 
27
5
  function _arrayWithHoles(r) {
28
6
  if (Array.isArray(r)) return r;
@@ -471,7 +449,8 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
471
449
  if (src[VAL_EXTENSION] !== "file") {
472
450
  return _defineProperty({}, path, [{
473
451
  message: "File did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
474
- value: src
452
+ value: src,
453
+ fixes: ["file:change-extension", "file:check-metadata"]
475
454
  }]);
476
455
  }
477
456
  var _ref4 = this.options || {},
@@ -481,7 +460,8 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
481
460
  if (accept && mimeType && !mimeType.includes("/")) {
482
461
  return _defineProperty({}, path, [{
483
462
  message: "Invalid mime type format. Got: ".concat(mimeType),
484
- value: src
463
+ value: src,
464
+ fixes: ["file:change-extension", "file:check-metadata"]
485
465
  }]);
486
466
  }
487
467
  if (accept && mimeType && mimeType.includes("/")) {
@@ -501,7 +481,8 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
501
481
  if (!isValidMimeType) {
502
482
  return _defineProperty({}, path, [{
503
483
  message: "Mime type mismatch. Found '".concat(mimeType, "' but schema accepts '").concat(accept, "'"),
504
- value: src
484
+ value: src,
485
+ fixes: ["file:change-extension", "file:check-metadata"]
505
486
  }]);
506
487
  }
507
488
  }
@@ -509,13 +490,15 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
509
490
  if (!fileMimeType) {
510
491
  return _defineProperty({}, path, [{
511
492
  message: "Could not determine mime type from file extension. Got: ".concat(src[FILE_REF_PROP]),
512
- value: src
493
+ value: src,
494
+ fixes: ["file:change-extension", "file:check-metadata"]
513
495
  }]);
514
496
  }
515
497
  if (fileMimeType !== mimeType) {
516
498
  return _defineProperty({}, path, [{
517
499
  message: "Mime type and file extension not matching. Mime type is '".concat(mimeType, "' but file extension is '").concat(fileMimeType, "'"),
518
- value: src
500
+ value: src,
501
+ fixes: ["file:change-extension", "file:check-metadata"]
519
502
  }]);
520
503
  }
521
504
  if (src.metadata) {
@@ -1079,7 +1062,7 @@ var ParserError = /*#__PURE__*/_createClass(function ParserError(message, span)
1079
1062
  this.message = message;
1080
1063
  this.span = span;
1081
1064
  });
1082
- function parseTokens$1(inputTokens) {
1065
+ function parseTokens(inputTokens) {
1083
1066
  var tokens = inputTokens.slice();
1084
1067
  function slurpCall(first, isAnon) {
1085
1068
  var _tokens$, _tokens$2, _tokens$3, _tokens$7, _tokens$8, _args$slice$0$span;
@@ -1215,7 +1198,7 @@ function parse(input) {
1215
1198
  _tokenize2 = _slicedToArray(_tokenize, 2),
1216
1199
  tokens = _tokenize2[0];
1217
1200
  _tokenize2[1]; // TODO: we can use cursor to improve error messages / spans
1218
- return parseTokens$1(tokens);
1201
+ return parseTokens(tokens);
1219
1202
  }
1220
1203
 
1221
1204
  /* eslint-disable @typescript-eslint/no-unused-vars */
@@ -2116,14 +2099,6 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2116
2099
  return _createClass(RichTextSchema, [{
2117
2100
  key: "validate",
2118
2101
  value: function validate(path, src) {
2119
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2120
- if (src !== null && src !== void 0 && src.markdownish) {
2121
- return _defineProperty({}, path, [{
2122
- message: "Replace markdown with structured format",
2123
- value: src,
2124
- fixes: ["fix:deprecated-richtext"]
2125
- }]);
2126
- }
2127
2102
  var assertRes = this.assert(path, src);
2128
2103
  if (!assertRes.success) {
2129
2104
  return _defineProperty({}, path, assertRes.errors[path]);
@@ -2282,7 +2257,7 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2282
2257
  }
2283
2258
  }]);
2284
2259
  }(Schema);
2285
- var richtext$1 = function richtext(options) {
2260
+ var richtext = function richtext(options) {
2286
2261
  return new RichTextSchema(options !== null && options !== void 0 ? options : {});
2287
2262
  };
2288
2263
 
@@ -2318,7 +2293,8 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
2318
2293
  if (src[VAL_EXTENSION] !== "file") {
2319
2294
  return _defineProperty({}, path, [{
2320
2295
  message: "Image did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
2321
- value: src
2296
+ value: src,
2297
+ fixes: ["image:change-extension", "image:check-metadata"]
2322
2298
  }]);
2323
2299
  }
2324
2300
  var _ref4 = this.options || {},
@@ -2328,7 +2304,8 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
2328
2304
  if (accept && mimeType && !mimeType.includes("/")) {
2329
2305
  return _defineProperty({}, path, [{
2330
2306
  message: "Invalid mime type format. Got: '".concat(mimeType, "'"),
2331
- value: src
2307
+ value: src,
2308
+ fixes: ["image:check-metadata"]
2332
2309
  }]);
2333
2310
  }
2334
2311
  if (accept && mimeType && mimeType.includes("/")) {
@@ -2348,7 +2325,8 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
2348
2325
  if (!isValidMimeType) {
2349
2326
  return _defineProperty({}, path, [{
2350
2327
  message: "Mime type mismatch. Found '".concat(mimeType, "' but schema accepts '").concat(accept, "'"),
2351
- value: src
2328
+ value: src,
2329
+ fixes: ["image:check-metadata"]
2352
2330
  }]);
2353
2331
  }
2354
2332
  }
@@ -2356,13 +2334,15 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
2356
2334
  if (!fileMimeType) {
2357
2335
  return _defineProperty({}, path, [{
2358
2336
  message: "Could not determine mime type from file extension. Got: ".concat(src[FILE_REF_PROP]),
2359
- value: src
2337
+ value: src,
2338
+ fixes: ["image:check-metadata"]
2360
2339
  }]);
2361
2340
  }
2362
2341
  if (fileMimeType && mimeType && fileMimeType !== mimeType) {
2363
2342
  return _defineProperty({}, path, [{
2364
2343
  message: "Mime type and file extension not matching. Mime type is '".concat(mimeType, "' but file extension is '").concat(fileMimeType, "'"),
2365
- value: src
2344
+ value: src,
2345
+ fixes: ["image:check-metadata"]
2366
2346
  }]);
2367
2347
  }
2368
2348
  if (src.metadata) {
@@ -2378,7 +2358,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
2378
2358
  message: "Found metadata, but it could not be validated. Image metadata must be an object with the required props: width (positive number), height (positive number) and the mime type.",
2379
2359
  // These validation errors will have to be picked up by logic outside of this package and revalidated. Reasons: 1) we have to read files to verify the metadata, which is handled differently in different runtimes (Browser, QuickJS, Node.js); 2) we want to keep this package dependency free.
2380
2360
  value: src,
2381
- fixes: ["image:replace-metadata"]
2361
+ fixes: ["image:check-metadata"]
2382
2362
  }]);
2383
2363
  }
2384
2364
  return _defineProperty({}, path, [{
@@ -2453,7 +2433,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
2453
2433
  }
2454
2434
  }]);
2455
2435
  }(Schema);
2456
- var image$1 = function image(options) {
2436
+ var image = function image(options) {
2457
2437
  return new ImageSchema(options);
2458
2438
  };
2459
2439
 
@@ -3421,8 +3401,8 @@ function initSchema() {
3421
3401
  number: number,
3422
3402
  union: union,
3423
3403
  // oneOf,
3424
- richtext: richtext$1,
3425
- image: image$1,
3404
+ richtext: richtext,
3405
+ image: image,
3426
3406
  literal: literal,
3427
3407
  keyOf: keyOf,
3428
3408
  record: record,
@@ -3432,257 +3412,61 @@ function initSchema() {
3432
3412
  };
3433
3413
  }
3434
3414
 
3435
- var VAL_START_TAG_PREFIX = '<val value="';
3436
- var VAL_START_TAG_SUFFIX = '">';
3437
- var VAL_END_TAG = "</val>";
3438
- function parseTokens(tokens, sourceNodes, cursor) {
3439
- var insideList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
3440
- var children = [];
3441
- function merge(token, clazz) {
3442
- var parsedTokens = parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0);
3443
- children.push({
3444
- tag: "span",
3445
- styles: [clazz].concat(parsedTokens.children.flatMap(function (child) {
3446
- return typeof child === "string" ? [] : child.styles;
3447
- })),
3448
- children: parsedTokens.children.flatMap(function (child) {
3449
- return typeof child === "string" ? child : child.children;
3450
- })
3451
- });
3452
- }
3453
- var _loop = function _loop() {
3454
- var token = tokens[cursor];
3455
- if (token.type === "heading") {
3456
- children.push({
3457
- tag: "h".concat(token.depth),
3458
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
3459
- });
3460
- } else if (token.type === "paragraph") {
3461
- children.push({
3462
- tag: "p",
3463
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
3464
- });
3465
- } else if (token.type === "strong") {
3466
- merge(token, "bold");
3467
- } else if (token.type === "em") {
3468
- merge(token, "italic");
3469
- } else if (token.type === "del") {
3470
- merge(token, "line-through");
3471
- } else if (token.type === "text") {
3472
- if ("tokens" in token && Array.isArray(token.tokens)) {
3473
- children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
3474
- } else {
3475
- if (insideList && typeof token.raw === "string") {
3476
- var lines = token.raw.split("\n");
3477
- var tags = lines.flatMap(function (line, i) {
3478
- if (i === lines.length - 1) return [line];
3479
- if (i === lines.length - 1 && line === "") return [];
3480
- if (line === "") return [{
3481
- tag: "p",
3482
- children: [{
3483
- tag: "br"
3484
- }]
3485
- }];
3486
- return [line, {
3487
- tag: "p",
3488
- children: [{
3489
- tag: "br"
3490
- }]
3491
- }];
3492
- });
3493
- children.push.apply(children, _toConsumableArray(tags));
3494
- } else {
3495
- children.push(token.raw);
3496
- }
3497
- }
3498
- } else if (token.type === "list") {
3499
- children.push({
3500
- tag: token.ordered ? "ol" : "ul",
3501
- children: parseTokens(token.items, sourceNodes, 0).children
3502
- });
3503
- } else if (token.type === "list_item") {
3504
- children.push({
3505
- tag: "li",
3506
- children: [{
3507
- tag: "p",
3508
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0, true).children
3509
- }]
3510
- });
3511
- } else if (token.type === "space") ; else if (token.type === "html") {
3512
- if (token.text === VAL_END_TAG) {
3513
- return {
3514
- v: {
3515
- children: children,
3516
- cursor: cursor
3517
- }
3518
- };
3519
- }
3520
- var suffixIndex = token.text.indexOf(VAL_START_TAG_SUFFIX);
3521
- if (token.text.startsWith(VAL_START_TAG_PREFIX) && suffixIndex > -1) {
3522
- var number = Number(token.text.slice(VAL_START_TAG_PREFIX.length, suffixIndex));
3523
- if (Number.isNaN(number)) {
3524
- throw Error("Illegal val intermediate node: ".concat(JSON.stringify(token)));
3525
- }
3526
- var _parseTokens = parseTokens(tokens.map(function (token) {
3527
- if (token.type === "link" || token.type === "list") {
3528
- return {
3529
- type: "text",
3530
- raw: token.raw,
3531
- text: token.raw
3532
- };
3533
- }
3534
- return token;
3535
- }), sourceNodes, cursor + 1),
3536
- subChildren = _parseTokens.children,
3537
- subCursor = _parseTokens.cursor;
3538
- var sourceNode = sourceNodes[number];
3539
- if (sourceNode._type === "link") {
3540
- children.push({
3541
- tag: "a",
3542
- href: sourceNode.href,
3543
- children: subChildren
3544
- });
3545
- } else if (sourceNode._type === "file") {
3546
- // @ts-expect-error We are transitioning from markdown to structured objects, with structured objects we no longer want c.rt.image
3547
- delete sourceNode[core.FILE_REF_SUBTYPE_TAG];
3548
- children.push({
3549
- tag: "img",
3550
- src: sourceNode
3551
- });
3552
- }
3553
- cursor = subCursor;
3554
- }
3555
- var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
3556
- if (token.text.trim().match(br_html_regex)) {
3557
- var _tokens;
3558
- children.push({
3559
- tag: "p",
3560
- children: [{
3561
- tag: "br"
3562
- }]
3563
- });
3564
- if (((_tokens = tokens[cursor + 1]) === null || _tokens === void 0 ? void 0 : _tokens.raw.trim()) === "") {
3565
- // if next token is a new line or white-spaces, skip it
3566
- // this typically means we have a <br> AND a new line, which, semantically, is just a <br>
3567
- cursor++;
3568
- }
3569
- }
3570
- } else if (token.type === "link") {
3571
- if (token.raw === token.href) {
3572
- // avoid auto-linking (provided by github flavoured markdown, but we want strikethrough so keep it enabled)
3573
- children.push(token.raw);
3574
- } else {
3575
- children.push({
3576
- tag: "a",
3577
- href: token.href,
3578
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
3579
- });
3580
- }
3581
- } else if (token.type === "br") {
3582
- children.push({
3583
- tag: "p",
3584
- children: [{
3585
- tag: "br"
3586
- }]
3587
- });
3588
- } else {
3589
- console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
3590
- }
3591
- cursor++;
3592
- },
3593
- _ret;
3594
- while (cursor < tokens.length) {
3595
- _ret = _loop();
3596
- if (_ret) return _ret.v;
3597
- }
3598
- return {
3599
- children: children,
3600
- cursor: cursor
3601
- };
3602
- }
3603
- function parseRichTextSource(_ref) {
3604
- var templateStrings = _ref.templateStrings,
3605
- nodes = _ref.exprs;
3606
- // TODO: validate that templateStrings does not contain VAL_NODE_PREFIX
3607
- var inputText = templateStrings.flatMap(function (templateString, i) {
3608
- var node = nodes[i];
3609
- if (node) {
3610
- if (node[core.VAL_EXTENSION] === "link") {
3611
- return templateString.concat("".concat(VAL_START_TAG_PREFIX).concat(i).concat(VAL_START_TAG_SUFFIX).concat(node.children[0]).concat(VAL_END_TAG));
3612
- } else {
3613
- return templateString.concat("".concat(VAL_START_TAG_PREFIX).concat(i).concat(VAL_START_TAG_SUFFIX).concat(VAL_END_TAG));
3614
- }
3615
- }
3616
- return templateString;
3617
- }).join("");
3618
- var tokenList = marked__namespace.lexer(inputText, {
3619
- gfm: true
3620
- });
3621
- var _parseTokens2 = parseTokens(tokenList, nodes, 0),
3622
- children = _parseTokens2.children,
3623
- cursor = _parseTokens2.cursor;
3624
- if (cursor !== tokenList.length) {
3625
- throw Error("Unexpectedly terminated markdown parsing. Possible reason: unclosed html tag?");
3626
- }
3627
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3628
- children.markdownish = true; // Markdown is an intermediate format - we are planning on replacing it with a structured object format
3629
- return children;
3630
- }
3631
-
3632
- //#region Classes
3633
-
3634
- //#region Paragraph
3635
-
3636
- //#region Break
3637
-
3638
- //#region Span
3639
-
3640
- //#region Image
3641
-
3642
- //#region Link
3643
-
3644
- //#region List
3645
-
3646
- //#region Heading
3647
-
3648
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
3649
-
3650
- // export type CustomInlineNode<O extends RichTextOptions> = NonNullable<
3651
- // NonNullable<O["inline"]>["custom"]
3652
- // >[keyof NonNullable<NonNullable<O["inline"]>["custom"]>] extends Schema<
3653
- // infer Src
3654
- // >
3655
- // ? ReplaceRawStringWithString<Src>
3656
- // : never;
3657
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
3658
-
3659
- //#region Block and Inline nodes:
3660
-
3661
- //#region Main types
3662
-
3663
3415
  /**
3664
- * RichText as defined in a ValModule
3665
- **/
3416
+ * A image source represents the path to a (local) image.
3417
+ *
3418
+ */
3666
3419
 
3667
- function richtext(templateStrings) {
3668
- for (var _len = arguments.length, nodes = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
3669
- nodes[_key - 1] = arguments[_key];
3670
- }
3671
- return parseRichTextSource({
3672
- templateStrings: templateStrings,
3673
- exprs: nodes
3674
- // eslint-disable-next-line @typescript-eslint/ban-types
3675
- });
3676
- }
3677
- var RT_IMAGE_TAG = "rt_image";
3678
- function image(ref, metadata) {
3679
- return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), FILE_REF_SUBTYPE_TAG, RT_IMAGE_TAG), VAL_EXTENSION, "file"), "metadata", metadata);
3680
- }
3420
+ var initImage = function initImage(config) {
3421
+ var _config$files$directo, _config$files;
3422
+ (_config$files$directo = config === null || config === void 0 || (_config$files = config.files) === null || _config$files === void 0 ? void 0 : _config$files.directory) !== null && _config$files$directo !== void 0 ? _config$files$directo : "/public/val";
3681
3423
 
3682
- function link(text, _ref) {
3683
- var href = _ref.href;
3684
- return _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "link"), "href", href), "children", [text]);
3685
- }
3424
+ /**
3425
+ * Define the source of an image file.
3426
+ *
3427
+ * @example
3428
+ * c.image("/public/val/example.png", {
3429
+ * width: 944,
3430
+ * height: 944,
3431
+ * mimeType: "image/png",
3432
+ *})
3433
+ *
3434
+ * @param ref /public/val/example.png
3435
+ * @param metadata Image metadata: width, height, mimeType and optionally a hotspot.
3436
+ */
3437
+
3438
+ /**
3439
+ * Define the source of an image file.
3440
+ *
3441
+ * NOTE: this will **not** validate since metadata has not been defined.
3442
+ *
3443
+ * Run `npx -p @valbuild/cli val validate --fix` to automatically add metadata.
3444
+ *
3445
+ * @example
3446
+ * c.image("/public/val/example.png")
3447
+ *
3448
+ * @param ref /public/val/example.png
3449
+ * @param metadata Image metadata: width, height, mimeType and optionally a hotspot.
3450
+ */
3451
+
3452
+ /**
3453
+ * Define the source of an image file.
3454
+ *
3455
+ * @example
3456
+ * c.image("/public/val/example.png", {
3457
+ * width: 944,
3458
+ * height: 944,
3459
+ * mimeType: "image/png",
3460
+ *})
3461
+ *
3462
+ * @param ref /public/val/example.png
3463
+ * @param metadata Image metadata: width, height, mimeType and optionally a hotspot.
3464
+ */
3465
+ function image(ref, metadata) {
3466
+ return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), VAL_EXTENSION, "file"), FILE_REF_SUBTYPE_TAG, "image"), "metadata", metadata);
3467
+ }
3468
+ return image;
3469
+ };
3686
3470
 
3687
3471
  /* eslint-disable @typescript-eslint/ban-types */
3688
3472
  // import { i18n, I18n } from "./source/future/i18n";
@@ -3723,11 +3507,7 @@ var initVal = function initVal(config) {
3723
3507
  define: define,
3724
3508
  // remote,
3725
3509
  file: initFile(config),
3726
- richtext: richtext,
3727
- rt: {
3728
- image: image,
3729
- link: link
3730
- }
3510
+ image: initImage(config)
3731
3511
  },
3732
3512
  s: s,
3733
3513
  config: config
@@ -5228,7 +5008,6 @@ exports.NilSym = NilSym;
5228
5008
  exports.NumberSchema = NumberSchema;
5229
5009
  exports.ObjectSchema = ObjectSchema;
5230
5010
  exports.PatchError = PatchError;
5231
- exports.RT_IMAGE_TAG = RT_IMAGE_TAG;
5232
5011
  exports.RecordSchema = RecordSchema;
5233
5012
  exports.RichTextSchema = RichTextSchema;
5234
5013
  exports.Schema = Schema;