@valbuild/shared 0.43.1 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,306 +1,36 @@
1
- import { VAL_EXTENSION, FILE_REF_PROP, Internal } from '@valbuild/core';
1
+ import { VAL_EXTENSION, Internal, FILE_REF_PROP } from '@valbuild/core';
2
2
  import * as marked from 'marked';
3
3
 
4
- function _regeneratorRuntime() {
5
- _regeneratorRuntime = function () {
6
- return e;
7
- };
8
- var t,
9
- e = {},
10
- r = Object.prototype,
11
- n = r.hasOwnProperty,
12
- o = Object.defineProperty || function (t, e, r) {
13
- t[e] = r.value;
14
- },
15
- i = "function" == typeof Symbol ? Symbol : {},
16
- a = i.iterator || "@@iterator",
17
- c = i.asyncIterator || "@@asyncIterator",
18
- u = i.toStringTag || "@@toStringTag";
19
- function define(t, e, r) {
20
- return Object.defineProperty(t, e, {
21
- value: r,
22
- enumerable: !0,
23
- configurable: !0,
24
- writable: !0
25
- }), t[e];
26
- }
27
- try {
28
- define({}, "");
29
- } catch (t) {
30
- define = function (t, e, r) {
31
- return t[e] = r;
32
- };
33
- }
34
- function wrap(t, e, r, n) {
35
- var i = e && e.prototype instanceof Generator ? e : Generator,
36
- a = Object.create(i.prototype),
37
- c = new Context(n || []);
38
- return o(a, "_invoke", {
39
- value: makeInvokeMethod(t, r, c)
40
- }), a;
41
- }
42
- function tryCatch(t, e, r) {
4
+ function _arrayWithHoles(arr) {
5
+ if (Array.isArray(arr)) return arr;
6
+ }
7
+
8
+ function _iterableToArrayLimit(r, l) {
9
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
10
+ if (null != t) {
11
+ var e,
12
+ n,
13
+ i,
14
+ u,
15
+ a = [],
16
+ f = !0,
17
+ o = !1;
43
18
  try {
44
- return {
45
- type: "normal",
46
- arg: t.call(e, r)
47
- };
48
- } catch (t) {
49
- return {
50
- type: "throw",
51
- arg: t
52
- };
53
- }
54
- }
55
- e.wrap = wrap;
56
- var h = "suspendedStart",
57
- l = "suspendedYield",
58
- f = "executing",
59
- s = "completed",
60
- y = {};
61
- function Generator() {}
62
- function GeneratorFunction() {}
63
- function GeneratorFunctionPrototype() {}
64
- var p = {};
65
- define(p, a, function () {
66
- return this;
67
- });
68
- var d = Object.getPrototypeOf,
69
- v = d && d(d(values([])));
70
- v && v !== r && n.call(v, a) && (p = v);
71
- var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
72
- function defineIteratorMethods(t) {
73
- ["next", "throw", "return"].forEach(function (e) {
74
- define(t, e, function (t) {
75
- return this._invoke(e, t);
76
- });
77
- });
78
- }
79
- function AsyncIterator(t, e) {
80
- function invoke(r, o, i, a) {
81
- var c = tryCatch(t[r], t, o);
82
- if ("throw" !== c.type) {
83
- var u = c.arg,
84
- h = u.value;
85
- return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
86
- invoke("next", t, i, a);
87
- }, function (t) {
88
- invoke("throw", t, i, a);
89
- }) : e.resolve(h).then(function (t) {
90
- u.value = t, i(u);
91
- }, function (t) {
92
- return invoke("throw", t, i, a);
93
- });
94
- }
95
- a(c.arg);
96
- }
97
- var r;
98
- o(this, "_invoke", {
99
- value: function (t, n) {
100
- function callInvokeWithMethodAndArg() {
101
- return new e(function (e, r) {
102
- invoke(t, n, e, r);
103
- });
104
- }
105
- return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
106
- }
107
- });
108
- }
109
- function makeInvokeMethod(e, r, n) {
110
- var o = h;
111
- return function (i, a) {
112
- if (o === f) throw new Error("Generator is already running");
113
- if (o === s) {
114
- if ("throw" === i) throw a;
115
- return {
116
- value: t,
117
- done: !0
118
- };
119
- }
120
- for (n.method = i, n.arg = a;;) {
121
- var c = n.delegate;
122
- if (c) {
123
- var u = maybeInvokeDelegate(c, n);
124
- if (u) {
125
- if (u === y) continue;
126
- return u;
127
- }
128
- }
129
- if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
130
- if (o === h) throw o = s, n.arg;
131
- n.dispatchException(n.arg);
132
- } else "return" === n.method && n.abrupt("return", n.arg);
133
- o = f;
134
- var p = tryCatch(e, r, n);
135
- if ("normal" === p.type) {
136
- if (o = n.done ? s : l, p.arg === y) continue;
137
- return {
138
- value: p.arg,
139
- done: n.done
140
- };
141
- }
142
- "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
143
- }
144
- };
145
- }
146
- function maybeInvokeDelegate(e, r) {
147
- var n = r.method,
148
- o = e.iterator[n];
149
- if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
150
- var i = tryCatch(o, e.iterator, r.arg);
151
- if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
152
- var a = i.arg;
153
- return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
154
- }
155
- function pushTryEntry(t) {
156
- var e = {
157
- tryLoc: t[0]
158
- };
159
- 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
160
- }
161
- function resetTryEntry(t) {
162
- var e = t.completion || {};
163
- e.type = "normal", delete e.arg, t.completion = e;
164
- }
165
- function Context(t) {
166
- this.tryEntries = [{
167
- tryLoc: "root"
168
- }], t.forEach(pushTryEntry, this), this.reset(!0);
169
- }
170
- function values(e) {
171
- if (e || "" === e) {
172
- var r = e[a];
173
- if (r) return r.call(e);
174
- if ("function" == typeof e.next) return e;
175
- if (!isNaN(e.length)) {
176
- var o = -1,
177
- i = function next() {
178
- for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
179
- return next.value = t, next.done = !0, next;
180
- };
181
- return i.next = i;
19
+ if (i = (t = t.call(r)).next, 0 === l) {
20
+ if (Object(t) !== t) return;
21
+ f = !1;
22
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
23
+ } catch (r) {
24
+ o = !0, n = r;
25
+ } finally {
26
+ try {
27
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
28
+ } finally {
29
+ if (o) throw n;
182
30
  }
183
31
  }
184
- throw new TypeError(typeof e + " is not iterable");
32
+ return a;
185
33
  }
186
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
187
- value: GeneratorFunctionPrototype,
188
- configurable: !0
189
- }), o(GeneratorFunctionPrototype, "constructor", {
190
- value: GeneratorFunction,
191
- configurable: !0
192
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
193
- var e = "function" == typeof t && t.constructor;
194
- return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
195
- }, e.mark = function (t) {
196
- return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
197
- }, e.awrap = function (t) {
198
- return {
199
- __await: t
200
- };
201
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
202
- return this;
203
- }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
204
- void 0 === i && (i = Promise);
205
- var a = new AsyncIterator(wrap(t, r, n, o), i);
206
- return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
207
- return t.done ? t.value : a.next();
208
- });
209
- }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
210
- return this;
211
- }), define(g, "toString", function () {
212
- return "[object Generator]";
213
- }), e.keys = function (t) {
214
- var e = Object(t),
215
- r = [];
216
- for (var n in e) r.push(n);
217
- return r.reverse(), function next() {
218
- for (; r.length;) {
219
- var t = r.pop();
220
- if (t in e) return next.value = t, next.done = !1, next;
221
- }
222
- return next.done = !0, next;
223
- };
224
- }, e.values = values, Context.prototype = {
225
- constructor: Context,
226
- reset: function (e) {
227
- if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
228
- },
229
- stop: function () {
230
- this.done = !0;
231
- var t = this.tryEntries[0].completion;
232
- if ("throw" === t.type) throw t.arg;
233
- return this.rval;
234
- },
235
- dispatchException: function (e) {
236
- if (this.done) throw e;
237
- var r = this;
238
- function handle(n, o) {
239
- return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
240
- }
241
- for (var o = this.tryEntries.length - 1; o >= 0; --o) {
242
- var i = this.tryEntries[o],
243
- a = i.completion;
244
- if ("root" === i.tryLoc) return handle("end");
245
- if (i.tryLoc <= this.prev) {
246
- var c = n.call(i, "catchLoc"),
247
- u = n.call(i, "finallyLoc");
248
- if (c && u) {
249
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
250
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
251
- } else if (c) {
252
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
253
- } else {
254
- if (!u) throw new Error("try statement without catch or finally");
255
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
256
- }
257
- }
258
- }
259
- },
260
- abrupt: function (t, e) {
261
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
262
- var o = this.tryEntries[r];
263
- if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
264
- var i = o;
265
- break;
266
- }
267
- }
268
- i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
269
- var a = i ? i.completion : {};
270
- return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
271
- },
272
- complete: function (t, e) {
273
- if ("throw" === t.type) throw t.arg;
274
- return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
275
- },
276
- finish: function (t) {
277
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
278
- var r = this.tryEntries[e];
279
- if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
280
- }
281
- },
282
- catch: function (t) {
283
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
284
- var r = this.tryEntries[e];
285
- if (r.tryLoc === t) {
286
- var n = r.completion;
287
- if ("throw" === n.type) {
288
- var o = n.arg;
289
- resetTryEntry(r);
290
- }
291
- return o;
292
- }
293
- }
294
- throw new Error("illegal catch attempt");
295
- },
296
- delegateYield: function (e, r, n) {
297
- return this.delegate = {
298
- iterator: values(e),
299
- resultName: r,
300
- nextLoc: n
301
- }, "next" === this.method && (this.arg = t), y;
302
- }
303
- }, e;
304
34
  }
305
35
 
306
36
  function _arrayLikeToArray(arr, len) {
@@ -318,6 +48,45 @@ function _unsupportedIterableToArray(o, minLen) {
318
48
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
319
49
  }
320
50
 
51
+ function _nonIterableRest() {
52
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
53
+ }
54
+
55
+ function _slicedToArray(arr, i) {
56
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
57
+ }
58
+
59
+ function _toPrimitive(input, hint) {
60
+ if (typeof input !== "object" || input === null) return input;
61
+ var prim = input[Symbol.toPrimitive];
62
+ if (prim !== undefined) {
63
+ var res = prim.call(input, hint || "default");
64
+ if (typeof res !== "object") return res;
65
+ throw new TypeError("@@toPrimitive must return a primitive value.");
66
+ }
67
+ return (hint === "string" ? String : Number)(input);
68
+ }
69
+
70
+ function _toPropertyKey(arg) {
71
+ var key = _toPrimitive(arg, "string");
72
+ return typeof key === "symbol" ? key : String(key);
73
+ }
74
+
75
+ function _defineProperty(obj, key, value) {
76
+ key = _toPropertyKey(key);
77
+ if (key in obj) {
78
+ Object.defineProperty(obj, key, {
79
+ value: value,
80
+ enumerable: true,
81
+ configurable: true,
82
+ writable: true
83
+ });
84
+ } else {
85
+ obj[key] = value;
86
+ }
87
+ return obj;
88
+ }
89
+
321
90
  function _createForOfIteratorHelper(o, allowArrayLike) {
322
91
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
323
92
  if (!it) {
@@ -370,108 +139,6 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
370
139
  };
371
140
  }
372
141
 
373
- function _toPrimitive(input, hint) {
374
- if (typeof input !== "object" || input === null) return input;
375
- var prim = input[Symbol.toPrimitive];
376
- if (prim !== undefined) {
377
- var res = prim.call(input, hint || "default");
378
- if (typeof res !== "object") return res;
379
- throw new TypeError("@@toPrimitive must return a primitive value.");
380
- }
381
- return (hint === "string" ? String : Number)(input);
382
- }
383
-
384
- function _toPropertyKey(arg) {
385
- var key = _toPrimitive(arg, "string");
386
- return typeof key === "symbol" ? key : String(key);
387
- }
388
-
389
- function _defineProperty(obj, key, value) {
390
- key = _toPropertyKey(key);
391
- if (key in obj) {
392
- Object.defineProperty(obj, key, {
393
- value: value,
394
- enumerable: true,
395
- configurable: true,
396
- writable: true
397
- });
398
- } else {
399
- obj[key] = value;
400
- }
401
- return obj;
402
- }
403
-
404
- function _arrayWithHoles(arr) {
405
- if (Array.isArray(arr)) return arr;
406
- }
407
-
408
- function _iterableToArrayLimit(r, l) {
409
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
410
- if (null != t) {
411
- var e,
412
- n,
413
- i,
414
- u,
415
- a = [],
416
- f = !0,
417
- o = !1;
418
- try {
419
- if (i = (t = t.call(r)).next, 0 === l) {
420
- if (Object(t) !== t) return;
421
- f = !1;
422
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
423
- } catch (r) {
424
- o = !0, n = r;
425
- } finally {
426
- try {
427
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
428
- } finally {
429
- if (o) throw n;
430
- }
431
- }
432
- return a;
433
- }
434
- }
435
-
436
- function _nonIterableRest() {
437
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
438
- }
439
-
440
- function _slicedToArray(arr, i) {
441
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
442
- }
443
-
444
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
445
- try {
446
- var info = gen[key](arg);
447
- var value = info.value;
448
- } catch (error) {
449
- reject(error);
450
- return;
451
- }
452
- if (info.done) {
453
- resolve(value);
454
- } else {
455
- Promise.resolve(value).then(_next, _throw);
456
- }
457
- }
458
- function _asyncToGenerator(fn) {
459
- return function () {
460
- var self = this,
461
- args = arguments;
462
- return new Promise(function (resolve, reject) {
463
- var gen = fn.apply(self, args);
464
- function _next(value) {
465
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
466
- }
467
- function _throw(err) {
468
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
469
- }
470
- _next(undefined);
471
- });
472
- };
473
- }
474
-
475
142
  function _arrayWithoutHoles(arr) {
476
143
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
477
144
  }
@@ -508,6 +175,19 @@ function mimeTypeToFileExt(mimeType) {
508
175
  }
509
176
  return mimeType;
510
177
  }
178
+ function filenameToMimeType(filename) {
179
+ var ext = filename.split(".").pop();
180
+ return ext && imageTypeToMimeType(ext);
181
+ }
182
+ function imageTypeToMimeType(imageType) {
183
+ if (imageType === "svg") {
184
+ return "image/svg+xml";
185
+ }
186
+ if (imageType === "ico") {
187
+ return "image/vnd.microsoft.icon";
188
+ }
189
+ return "image/".concat(imageType);
190
+ }
511
191
 
512
192
  var HeaderRegEx = /^h([\d+])$/;
513
193
  function lexicalToRichTextSource(node) {
@@ -555,100 +235,43 @@ function createBlock(node) {
555
235
  throw new Error("Unhandled node type: ".concat("type" in exhaustiveCheck ? "exhaustiveCheck.type" : "unknown"));
556
236
  }
557
237
  }
558
- function fromIRToRichTextSource(_x) {
559
- return _fromIRToRichTextSource.apply(this, arguments);
560
- }
561
- function _fromIRToRichTextSource() {
562
- _fromIRToRichTextSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(markdownIRBlocks) {
563
- var templateStrings, exprs, files, blockIdx, block, _iterator, _step, child, exhaustiveCheck;
564
- return _regeneratorRuntime().wrap(function _callee$(_context) {
565
- while (1) switch (_context.prev = _context.next) {
566
- case 0:
567
- templateStrings = ["\n"];
568
- exprs = [];
569
- files = {};
570
- blockIdx = 0;
571
- case 4:
572
- if (!(blockIdx < markdownIRBlocks.length)) {
573
- _context.next = 44;
574
- break;
575
- }
576
- block = markdownIRBlocks[blockIdx];
577
- _iterator = _createForOfIteratorHelper(block.children);
578
- _context.prev = 7;
579
- _iterator.s();
580
- case 9:
581
- if ((_step = _iterator.n()).done) {
582
- _context.next = 32;
583
- break;
584
- }
585
- child = _step.value;
586
- if (!(typeof child === "string")) {
587
- _context.next = 15;
588
- break;
589
- }
238
+ function fromIRToRichTextSource(markdownIRBlocks) {
239
+ var templateStrings = ["\n"];
240
+ var exprs = [];
241
+ var files = {};
242
+ for (var blockIdx = 0; blockIdx < markdownIRBlocks.length; blockIdx++) {
243
+ var block = markdownIRBlocks[blockIdx];
244
+ var _iterator = _createForOfIteratorHelper(block.children),
245
+ _step;
246
+ try {
247
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
248
+ var child = _step.value;
249
+ if (typeof child === "string") {
590
250
  templateStrings[templateStrings.length - 1] += child;
591
- _context.next = 30;
592
- break;
593
- case 15:
594
- if (!(child.type === "image")) {
595
- _context.next = 23;
596
- break;
597
- }
598
- _context.t0 = exprs;
599
- _context.next = 19;
600
- return fromLexicalImageNode(child, files);
601
- case 19:
602
- _context.t1 = _context.sent;
603
- _context.t0.push.call(_context.t0, _context.t1);
604
- _context.next = 29;
605
- break;
606
- case 23:
607
- if (!(child.type === "link")) {
608
- _context.next = 27;
609
- break;
610
- }
611
- exprs.push(fromLexicalLinkNode(child));
612
- _context.next = 29;
613
- break;
614
- case 27:
615
- exhaustiveCheck = child;
616
- throw new Error("Unexpected node type: ".concat(JSON.stringify(exhaustiveCheck, null, 2)));
617
- case 29:
618
- templateStrings.push("");
619
- case 30:
620
- _context.next = 9;
621
- break;
622
- case 32:
623
- _context.next = 37;
624
- break;
625
- case 34:
626
- _context.prev = 34;
627
- _context.t2 = _context["catch"](7);
628
- _iterator.e(_context.t2);
629
- case 37:
630
- _context.prev = 37;
631
- _iterator.f();
632
- return _context.finish(37);
633
- case 40:
634
- if (blockIdx === markdownIRBlocks.length - 1) {
635
- templateStrings[templateStrings.length - 1] += "\n";
251
+ } else {
252
+ if (child.type === "image") {
253
+ exprs.push(fromLexicalImageNode(child, files));
254
+ } else if (child.type === "link") {
255
+ exprs.push(fromLexicalLinkNode(child));
636
256
  } else {
637
- templateStrings[templateStrings.length - 1] += "\n\n";
257
+ var exhaustiveCheck = child;
258
+ throw new Error("Unexpected node type: ".concat(JSON.stringify(exhaustiveCheck, null, 2)));
638
259
  }
639
- case 41:
640
- blockIdx++;
641
- _context.next = 4;
642
- break;
643
- case 44:
644
- return _context.abrupt("return", _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "richtext"), "templateStrings", templateStrings), "exprs", exprs), "files", files));
645
- case 45:
646
- case "end":
647
- return _context.stop();
260
+ templateStrings.push("");
261
+ }
648
262
  }
649
- }, _callee, null, [[7, 34, 37, 40]]);
650
- }));
651
- return _fromIRToRichTextSource.apply(this, arguments);
263
+ } catch (err) {
264
+ _iterator.e(err);
265
+ } finally {
266
+ _iterator.f();
267
+ }
268
+ if (blockIdx === markdownIRBlocks.length - 1) {
269
+ templateStrings[templateStrings.length - 1] += "\n";
270
+ } else {
271
+ templateStrings[templateStrings.length - 1] += "\n\n";
272
+ }
273
+ }
274
+ return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "richtext"), "templateStrings", templateStrings), "exprs", exprs), "files", files);
652
275
  }
653
276
  function formatText(node) {
654
277
  var classes = typeof node.format === "number" ? fromLexicalFormat(node.format) : [];
@@ -716,10 +339,10 @@ var FORMAT_MAPPING$1 = {
716
339
  };
717
340
 
718
341
  function fromLexicalFormat(format) {
719
- return Object.entries(FORMAT_MAPPING$1).flatMap(function (_ref) {
720
- var _ref2 = _slicedToArray(_ref, 2),
721
- key = _ref2[0],
722
- value = _ref2[1];
342
+ return Object.entries(FORMAT_MAPPING$1).flatMap(function (_ref2) {
343
+ var _ref3 = _slicedToArray(_ref2, 2),
344
+ key = _ref3[0],
345
+ value = _ref3[1];
723
346
  if ((value & /* bitwise and */format) === value) {
724
347
  return [key];
725
348
  }
@@ -727,52 +350,31 @@ function fromLexicalFormat(format) {
727
350
  });
728
351
  }
729
352
  var textEncoder = new TextEncoder();
730
- function fromLexicalImageNode(_x2, _x3) {
731
- return _fromLexicalImageNode.apply(this, arguments);
732
- }
733
- function _fromLexicalImageNode() {
734
- _fromLexicalImageNode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(node, files) {
735
- var sha256, mimeType, fileExt, filePath, _sha;
736
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
737
- while (1) switch (_context2.prev = _context2.next) {
738
- case 0:
739
- if (!node.src.startsWith("data:")) {
740
- _context2.next = 13;
741
- break;
742
- }
743
- _context2.next = 3;
744
- return Internal.getSHA256Hash(textEncoder.encode(node.src));
745
- case 3:
746
- sha256 = _context2.sent;
747
- mimeType = getMimeType(node.src);
748
- if (!(mimeType === undefined)) {
749
- _context2.next = 7;
750
- break;
751
- }
752
- throw new Error("Could not detect Mime Type for image: ".concat(node.src));
753
- case 7:
754
- fileExt = mimeTypeToFileExt(mimeType);
755
- filePath = "/public/".concat(sha256, ".").concat(fileExt);
756
- files[filePath] = node.src;
757
- return _context2.abrupt("return", _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "file"), FILE_REF_PROP, filePath), "metadata", {
758
- width: node.width || 0,
759
- height: node.height || 0,
760
- sha256: sha256 || ""
761
- }));
762
- case 13:
763
- _sha = getParam("sha256", node.src);
764
- return _context2.abrupt("return", _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "file"), FILE_REF_PROP, "/public".concat(node.src.split("?")[0])), "metadata", {
765
- width: node.width || 0,
766
- height: node.height || 0,
767
- sha256: _sha || ""
768
- }));
769
- case 15:
770
- case "end":
771
- return _context2.stop();
772
- }
773
- }, _callee2);
774
- }));
775
- return _fromLexicalImageNode.apply(this, arguments);
353
+ function fromLexicalImageNode(node, files) {
354
+ if (node.src.startsWith("data:")) {
355
+ var sha256 = Internal.getSHA256Hash(textEncoder.encode(node.src));
356
+ var mimeType = getMimeType(node.src);
357
+ if (mimeType === undefined) {
358
+ throw new Error("Could not detect Mime Type for image: ".concat(node.src));
359
+ }
360
+ var fileExt = mimeTypeToFileExt(mimeType);
361
+ var filePath = "/public/".concat(sha256, ".").concat(fileExt);
362
+ files[filePath] = node.src;
363
+ return _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "file"), FILE_REF_PROP, filePath), "metadata", {
364
+ width: node.width || 0,
365
+ height: node.height || 0,
366
+ sha256: sha256 || "",
367
+ mimeType: mimeType
368
+ });
369
+ } else {
370
+ var _sha = getParam("sha256", node.src);
371
+ return _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "file"), FILE_REF_PROP, "/public".concat(node.src.split("?")[0])), "metadata", {
372
+ width: node.width || 0,
373
+ height: node.height || 0,
374
+ sha256: _sha || "",
375
+ mimeType: node.mimeType || ""
376
+ });
377
+ }
776
378
  }
777
379
  function getParam(param, url) {
778
380
  var urlParts = url.split("?");
@@ -877,7 +479,8 @@ function toLexicalImageNode(node) {
877
479
  type: "image",
878
480
  src: url,
879
481
  width: node.width,
880
- height: node.height
482
+ height: node.height,
483
+ mimeType: node.mimeType
881
484
  // TODO: altText
882
485
  });
883
486
  }
@@ -1075,12 +678,13 @@ function parseTokens(tokens, sourceNodes, cursor) {
1075
678
  children: subChildren
1076
679
  });
1077
680
  } else if (sourceNode._type === "file") {
1078
- var _sourceNode$metadata, _sourceNode$metadata2;
681
+ var _sourceNode$metadata, _sourceNode$metadata2, _sourceNode$metadata3;
1079
682
  children.push({
1080
683
  tag: "img",
1081
684
  src: Internal.convertFileSource(sourceNode).url,
1082
685
  width: (_sourceNode$metadata = sourceNode.metadata) === null || _sourceNode$metadata === void 0 ? void 0 : _sourceNode$metadata.width,
1083
686
  height: (_sourceNode$metadata2 = sourceNode.metadata) === null || _sourceNode$metadata2 === void 0 ? void 0 : _sourceNode$metadata2.height,
687
+ mimeType: (_sourceNode$metadata3 = sourceNode.metadata) === null || _sourceNode$metadata3 === void 0 ? void 0 : _sourceNode$metadata3.mimeType,
1084
688
  children: []
1085
689
  });
1086
690
  }
@@ -1155,4 +759,4 @@ var VAL_SESSION_COOKIE = Internal.VAL_SESSION_COOKIE;
1155
759
  var VAL_STATE_COOKIE = Internal.VAL_STATE_COOKIE;
1156
760
  var VAL_ENABLE_COOKIE_NAME = Internal.VAL_ENABLE_COOKIE_NAME;
1157
761
 
1158
- export { COMMON_LEXICAL_PROPS, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, fromLexicalFormat, getMimeType, lexicalToRichTextSource, mimeTypeToFileExt, parseRichTextSource, richTextSourceToLexical, toLexicalFormat, toLexicalNode };
762
+ export { COMMON_LEXICAL_PROPS, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, filenameToMimeType, fromLexicalFormat, getMimeType, imageTypeToMimeType, lexicalToRichTextSource, mimeTypeToFileExt, parseRichTextSource, richTextSourceToLexical, toLexicalFormat, toLexicalNode };