@valbuild/shared 0.48.1 → 0.50.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,79 +1,25 @@
1
1
  import { VAL_EXTENSION, Internal, FILE_REF_PROP } from '@valbuild/core';
2
2
  import * as marked from 'marked';
3
+ import { z } from 'zod';
3
4
 
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;
18
- try {
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;
30
- }
31
- }
32
- return a;
33
- }
34
- }
35
-
36
- function _arrayLikeToArray(arr, len) {
37
- if (len == null || len > arr.length) len = arr.length;
38
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
39
- return arr2;
40
- }
41
-
42
- function _unsupportedIterableToArray(o, minLen) {
43
- if (!o) return;
44
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
45
- var n = Object.prototype.toString.call(o).slice(8, -1);
46
- if (n === "Object" && o.constructor) n = o.constructor.name;
47
- if (n === "Map" || n === "Set") return Array.from(o);
48
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
49
- }
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;
5
+ function toPrimitive(t, r) {
6
+ if ("object" != typeof t || !t) return t;
7
+ var e = t[Symbol.toPrimitive];
8
+ if (void 0 !== e) {
9
+ var i = e.call(t, r || "default");
10
+ if ("object" != typeof i) return i;
65
11
  throw new TypeError("@@toPrimitive must return a primitive value.");
66
12
  }
67
- return (hint === "string" ? String : Number)(input);
13
+ return ("string" === r ? String : Number)(t);
68
14
  }
69
15
 
70
- function _toPropertyKey(arg) {
71
- var key = _toPrimitive(arg, "string");
72
- return typeof key === "symbol" ? key : String(key);
16
+ function toPropertyKey(t) {
17
+ var i = toPrimitive(t, "string");
18
+ return "symbol" == typeof i ? i : String(i);
73
19
  }
74
20
 
75
21
  function _defineProperty(obj, key, value) {
76
- key = _toPropertyKey(key);
22
+ key = toPropertyKey(key);
77
23
  if (key in obj) {
78
24
  Object.defineProperty(obj, key, {
79
25
  value: value,
@@ -87,6 +33,21 @@ function _defineProperty(obj, key, value) {
87
33
  return obj;
88
34
  }
89
35
 
36
+ function _arrayLikeToArray(arr, len) {
37
+ if (len == null || len > arr.length) len = arr.length;
38
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
39
+ return arr2;
40
+ }
41
+
42
+ function _unsupportedIterableToArray(o, minLen) {
43
+ if (!o) return;
44
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
45
+ var n = Object.prototype.toString.call(o).slice(8, -1);
46
+ if (n === "Object" && o.constructor) n = o.constructor.name;
47
+ if (n === "Map" || n === "Set") return Array.from(o);
48
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
49
+ }
50
+
90
51
  function _createForOfIteratorHelper(o, allowArrayLike) {
91
52
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
92
53
  if (!it) {
@@ -155,7 +116,746 @@ function _toConsumableArray(arr) {
155
116
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
156
117
  }
157
118
 
158
- var MIME_TYPE_REGEX = /^data:(image\/(png|jpeg|jpg|gif|webp|bmp|tiff|ico|svg\+xml));base64,/;
119
+ function _arrayWithHoles(arr) {
120
+ if (Array.isArray(arr)) return arr;
121
+ }
122
+
123
+ function _iterableToArrayLimit(r, l) {
124
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
125
+ if (null != t) {
126
+ var e,
127
+ n,
128
+ i,
129
+ u,
130
+ a = [],
131
+ f = !0,
132
+ o = !1;
133
+ try {
134
+ if (i = (t = t.call(r)).next, 0 === l) {
135
+ if (Object(t) !== t) return;
136
+ f = !1;
137
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
138
+ } catch (r) {
139
+ o = !0, n = r;
140
+ } finally {
141
+ try {
142
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
143
+ } finally {
144
+ if (o) throw n;
145
+ }
146
+ }
147
+ return a;
148
+ }
149
+ }
150
+
151
+ function _nonIterableRest() {
152
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
153
+ }
154
+
155
+ function _slicedToArray(arr, i) {
156
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
157
+ }
158
+
159
+ var EXT_TO_MIME_TYPES = {
160
+ x3d: "application/vnd.hzn-3d-crossword",
161
+ "3gp": "video/3gpp",
162
+ "3g2": "video/3gpp2",
163
+ mseq: "application/vnd.mseq",
164
+ pwn: "application/vnd.3m.post-it-notes",
165
+ plb: "application/vnd.3gpp.pic-bw-large",
166
+ psb: "application/vnd.3gpp.pic-bw-small",
167
+ pvb: "application/vnd.3gpp.pic-bw-var",
168
+ tcap: "application/vnd.3gpp2.tcap",
169
+ "7z": "application/x-7z-compressed",
170
+ abw: "application/x-abiword",
171
+ ace: "application/x-ace-compressed",
172
+ acc: "application/vnd.americandynamics.acc",
173
+ acu: "application/vnd.acucobol",
174
+ atc: "application/vnd.acucorp",
175
+ adp: "audio/adpcm",
176
+ aab: "application/x-authorware-bin",
177
+ aam: "application/x-authorware-map",
178
+ aas: "application/x-authorware-seg",
179
+ air: "application/vnd.adobe.air-application-installer-package+zip",
180
+ swf: "application/x-shockwave-flash",
181
+ fxp: "application/vnd.adobe.fxp",
182
+ pdf: "application/pdf",
183
+ ppd: "application/vnd.cups-ppd",
184
+ dir: "application/x-director",
185
+ xdp: "application/vnd.adobe.xdp+xml",
186
+ xfdf: "application/vnd.adobe.xfdf",
187
+ aac: "audio/x-aac",
188
+ ahead: "application/vnd.ahead.space",
189
+ azf: "application/vnd.airzip.filesecure.azf",
190
+ azs: "application/vnd.airzip.filesecure.azs",
191
+ azw: "application/vnd.amazon.ebook",
192
+ ami: "application/vnd.amiga.ami",
193
+ "N/A": "application/andrew-inset",
194
+ apk: "application/vnd.android.package-archive",
195
+ cii: "application/vnd.anser-web-certificate-issue-initiation",
196
+ fti: "application/vnd.anser-web-funds-transfer-initiation",
197
+ atx: "application/vnd.antix.game-component",
198
+ dmg: "application/x-apple-diskimage",
199
+ mpkg: "application/vnd.apple.installer+xml",
200
+ aw: "application/applixware",
201
+ mp3: "audio/mpeg",
202
+ les: "application/vnd.hhe.lesson-player",
203
+ swi: "application/vnd.aristanetworks.swi",
204
+ s: "text/x-asm",
205
+ atomcat: "application/atomcat+xml",
206
+ atomsvc: "application/atomsvc+xml",
207
+ atom: "application/atom+xml",
208
+ ac: "application/pkix-attr-cert",
209
+ aif: "audio/x-aiff",
210
+ avi: "video/x-msvideo",
211
+ aep: "application/vnd.audiograph",
212
+ dxf: "image/vnd.dxf",
213
+ dwf: "model/vnd.dwf",
214
+ par: "text/plain-bas",
215
+ bcpio: "application/x-bcpio",
216
+ bin: "application/octet-stream",
217
+ bmp: "image/bmp",
218
+ torrent: "application/x-bittorrent",
219
+ cod: "application/vnd.rim.cod",
220
+ mpm: "application/vnd.blueice.multipass",
221
+ bmi: "application/vnd.bmi",
222
+ sh: "application/x-sh",
223
+ btif: "image/prs.btif",
224
+ rep: "application/vnd.businessobjects",
225
+ bz: "application/x-bzip",
226
+ bz2: "application/x-bzip2",
227
+ csh: "application/x-csh",
228
+ c: "text/x-c",
229
+ cdxml: "application/vnd.chemdraw+xml",
230
+ css: "text/css",
231
+ cdx: "chemical/x-cdx",
232
+ cml: "chemical/x-cml",
233
+ csml: "chemical/x-csml",
234
+ cdbcmsg: "application/vnd.contact.cmsg",
235
+ cla: "application/vnd.claymore",
236
+ c4g: "application/vnd.clonk.c4group",
237
+ sub: "image/vnd.dvb.subtitle",
238
+ cdmia: "application/cdmi-capability",
239
+ cdmic: "application/cdmi-container",
240
+ cdmid: "application/cdmi-domain",
241
+ cdmio: "application/cdmi-object",
242
+ cdmiq: "application/cdmi-queue",
243
+ c11amc: "application/vnd.cluetrust.cartomobile-config",
244
+ c11amz: "application/vnd.cluetrust.cartomobile-config-pkg",
245
+ ras: "image/x-cmu-raster",
246
+ dae: "model/vnd.collada+xml",
247
+ csv: "text/csv",
248
+ cpt: "application/mac-compactpro",
249
+ wmlc: "application/vnd.wap.wmlc",
250
+ cgm: "image/cgm",
251
+ ice: "x-conference/x-cooltalk",
252
+ cmx: "image/x-cmx",
253
+ xar: "application/vnd.xara",
254
+ cmc: "application/vnd.cosmocaller",
255
+ cpio: "application/x-cpio",
256
+ clkx: "application/vnd.crick.clicker",
257
+ clkk: "application/vnd.crick.clicker.keyboard",
258
+ clkp: "application/vnd.crick.clicker.palette",
259
+ clkt: "application/vnd.crick.clicker.template",
260
+ clkw: "application/vnd.crick.clicker.wordbank",
261
+ wbs: "application/vnd.criticaltools.wbs+xml",
262
+ cryptonote: "application/vnd.rig.cryptonote",
263
+ cif: "chemical/x-cif",
264
+ cmdf: "chemical/x-cmdf",
265
+ cu: "application/cu-seeme",
266
+ cww: "application/prs.cww",
267
+ curl: "text/vnd.curl",
268
+ dcurl: "text/vnd.curl.dcurl",
269
+ mcurl: "text/vnd.curl.mcurl",
270
+ scurl: "text/vnd.curl.scurl",
271
+ car: "application/vnd.curl.car",
272
+ pcurl: "application/vnd.curl.pcurl",
273
+ cmp: "application/vnd.yellowriver-custom-menu",
274
+ dssc: "application/dssc+der",
275
+ xdssc: "application/dssc+xml",
276
+ deb: "application/x-debian-package",
277
+ uva: "audio/vnd.dece.audio",
278
+ uvi: "image/vnd.dece.graphic",
279
+ uvh: "video/vnd.dece.hd",
280
+ uvm: "video/vnd.dece.mobile",
281
+ uvu: "video/vnd.uvvu.mp4",
282
+ uvp: "video/vnd.dece.pd",
283
+ uvs: "video/vnd.dece.sd",
284
+ uvv: "video/vnd.dece.video",
285
+ dvi: "application/x-dvi",
286
+ seed: "application/vnd.fdsn.seed",
287
+ dtb: "application/x-dtbook+xml",
288
+ res: "application/x-dtbresource+xml",
289
+ ait: "application/vnd.dvb.ait",
290
+ svc: "application/vnd.dvb.service",
291
+ eol: "audio/vnd.digital-winds",
292
+ djvu: "image/vnd.djvu",
293
+ dtd: "application/xml-dtd",
294
+ mlp: "application/vnd.dolby.mlp",
295
+ wad: "application/x-doom",
296
+ dpg: "application/vnd.dpgraph",
297
+ dra: "audio/vnd.dra",
298
+ dfac: "application/vnd.dreamfactory",
299
+ dts: "audio/vnd.dts",
300
+ dtshd: "audio/vnd.dts.hd",
301
+ dwg: "image/vnd.dwg",
302
+ geo: "application/vnd.dynageo",
303
+ es: "application/ecmascript",
304
+ mag: "application/vnd.ecowin.chart",
305
+ mmr: "image/vnd.fujixerox.edmics-mmr",
306
+ rlc: "image/vnd.fujixerox.edmics-rlc",
307
+ exi: "application/exi",
308
+ mgz: "application/vnd.proteus.magazine",
309
+ epub: "application/epub+zip",
310
+ eml: "message/rfc822",
311
+ nml: "application/vnd.enliven",
312
+ xpr: "application/vnd.is-xpr",
313
+ xif: "image/vnd.xiff",
314
+ xfdl: "application/vnd.xfdl",
315
+ emma: "application/emma+xml",
316
+ ez2: "application/vnd.ezpix-album",
317
+ ez3: "application/vnd.ezpix-package",
318
+ fst: "image/vnd.fst",
319
+ fvt: "video/vnd.fvt",
320
+ fbs: "image/vnd.fastbidsheet",
321
+ fe_launch: "application/vnd.denovo.fcselayout-link",
322
+ f4v: "video/x-f4v",
323
+ flv: "video/x-flv",
324
+ fpx: "image/vnd.fpx",
325
+ npx: "image/vnd.net-fpx",
326
+ flx: "text/vnd.fmi.flexstor",
327
+ fli: "video/x-fli",
328
+ ftc: "application/vnd.fluxtime.clip",
329
+ fdf: "application/vnd.fdf",
330
+ f: "text/x-fortran",
331
+ mif: "application/vnd.mif",
332
+ fm: "application/vnd.framemaker",
333
+ fh: "image/x-freehand",
334
+ fsc: "application/vnd.fsc.weblaunch",
335
+ fnc: "application/vnd.frogans.fnc",
336
+ ltf: "application/vnd.frogans.ltf",
337
+ ddd: "application/vnd.fujixerox.ddd",
338
+ xdw: "application/vnd.fujixerox.docuworks",
339
+ xbd: "application/vnd.fujixerox.docuworks.binder",
340
+ oas: "application/vnd.fujitsu.oasys",
341
+ oa2: "application/vnd.fujitsu.oasys2",
342
+ oa3: "application/vnd.fujitsu.oasys3",
343
+ fg5: "application/vnd.fujitsu.oasysgp",
344
+ bh2: "application/vnd.fujitsu.oasysprs",
345
+ spl: "application/x-futuresplash",
346
+ fzs: "application/vnd.fuzzysheet",
347
+ g3: "image/g3fax",
348
+ gmx: "application/vnd.gmx",
349
+ gtw: "model/vnd.gtw",
350
+ txd: "application/vnd.genomatix.tuxedo",
351
+ ggb: "application/vnd.geogebra.file",
352
+ ggt: "application/vnd.geogebra.tool",
353
+ gdl: "model/vnd.gdl",
354
+ gex: "application/vnd.geometry-explorer",
355
+ gxt: "application/vnd.geonext",
356
+ g2w: "application/vnd.geoplan",
357
+ g3w: "application/vnd.geospace",
358
+ gsf: "application/x-font-ghostscript",
359
+ bdf: "application/x-font-bdf",
360
+ gtar: "application/x-gtar",
361
+ texinfo: "application/x-texinfo",
362
+ gnumeric: "application/x-gnumeric",
363
+ kml: "application/vnd.google-earth.kml+xml",
364
+ kmz: "application/vnd.google-earth.kmz",
365
+ gqf: "application/vnd.grafeq",
366
+ gif: "image/gif",
367
+ gv: "text/vnd.graphviz",
368
+ gac: "application/vnd.groove-account",
369
+ ghf: "application/vnd.groove-help",
370
+ gim: "application/vnd.groove-identity-message",
371
+ grv: "application/vnd.groove-injector",
372
+ gtm: "application/vnd.groove-tool-message",
373
+ tpl: "application/vnd.groove-tool-template",
374
+ vcg: "application/vnd.groove-vcard",
375
+ h261: "video/h261",
376
+ h263: "video/h263",
377
+ h264: "video/h264",
378
+ hpid: "application/vnd.hp-hpid",
379
+ hps: "application/vnd.hp-hps",
380
+ hdf: "application/x-hdf",
381
+ rip: "audio/vnd.rip",
382
+ hbci: "application/vnd.hbci",
383
+ jlt: "application/vnd.hp-jlyt",
384
+ pcl: "application/vnd.hp-pcl",
385
+ hpgl: "application/vnd.hp-hpgl",
386
+ hvs: "application/vnd.yamaha.hv-script",
387
+ hvd: "application/vnd.yamaha.hv-dic",
388
+ hvp: "application/vnd.yamaha.hv-voice",
389
+ "sfd-hdstx": "application/vnd.hydrostatix.sof-data",
390
+ stk: "application/hyperstudio",
391
+ hal: "application/vnd.hal+xml",
392
+ html: "text/html",
393
+ irm: "application/vnd.ibm.rights-management",
394
+ sc: "application/vnd.ibm.secure-container",
395
+ ics: "text/calendar",
396
+ icc: "application/vnd.iccprofile",
397
+ ico: "image/x-icon",
398
+ igl: "application/vnd.igloader",
399
+ ief: "image/ief",
400
+ ivp: "application/vnd.immervision-ivp",
401
+ ivu: "application/vnd.immervision-ivu",
402
+ rif: "application/reginfo+xml",
403
+ "3dml": "text/vnd.in3d.3dml",
404
+ spot: "text/vnd.in3d.spot",
405
+ igs: "model/iges",
406
+ i2g: "application/vnd.intergeo",
407
+ cdy: "application/vnd.cinderella",
408
+ xpw: "application/vnd.intercon.formnet",
409
+ fcs: "application/vnd.isac.fcs",
410
+ ipfix: "application/ipfix",
411
+ cer: "application/pkix-cert",
412
+ pki: "application/pkixcmp",
413
+ crl: "application/pkix-crl",
414
+ pkipath: "application/pkix-pkipath",
415
+ igm: "application/vnd.insors.igm",
416
+ rcprofile: "application/vnd.ipunplugged.rcprofile",
417
+ irp: "application/vnd.irepository.package+xml",
418
+ jad: "text/vnd.sun.j2me.app-descriptor",
419
+ jar: "application/java-archive",
420
+ "class": "application/java-vm",
421
+ jnlp: "application/x-java-jnlp-file",
422
+ ser: "application/java-serialized-object",
423
+ java: "text/x-java-source,java",
424
+ js: "application/javascript",
425
+ json: "application/json",
426
+ joda: "application/vnd.joost.joda-archive",
427
+ jpm: "video/jpm",
428
+ jpeg: "image/jpeg",
429
+ jpg: "image/jpeg",
430
+ pjpeg: "image/pjpeg",
431
+ jpgv: "video/jpeg",
432
+ ktz: "application/vnd.kahootz",
433
+ mmd: "application/vnd.chipnuts.karaoke-mmd",
434
+ karbon: "application/vnd.kde.karbon",
435
+ chrt: "application/vnd.kde.kchart",
436
+ kfo: "application/vnd.kde.kformula",
437
+ flw: "application/vnd.kde.kivio",
438
+ kon: "application/vnd.kde.kontour",
439
+ kpr: "application/vnd.kde.kpresenter",
440
+ ksp: "application/vnd.kde.kspread",
441
+ kwd: "application/vnd.kde.kword",
442
+ htke: "application/vnd.kenameaapp",
443
+ kia: "application/vnd.kidspiration",
444
+ kne: "application/vnd.kinar",
445
+ sse: "application/vnd.kodak-descriptor",
446
+ lasxml: "application/vnd.las.las+xml",
447
+ latex: "application/x-latex",
448
+ lbd: "application/vnd.llamagraphics.life-balance.desktop",
449
+ lbe: "application/vnd.llamagraphics.life-balance.exchange+xml",
450
+ jam: "application/vnd.jam",
451
+ "123": "application/vnd.lotus-1-2-3",
452
+ apr: "application/vnd.lotus-approach",
453
+ pre: "application/vnd.lotus-freelance",
454
+ nsf: "application/vnd.lotus-notes",
455
+ org: "application/vnd.lotus-organizer",
456
+ scm: "application/vnd.lotus-screencam",
457
+ lwp: "application/vnd.lotus-wordpro",
458
+ lvp: "audio/vnd.lucent.voice",
459
+ m3u: "audio/x-mpegurl",
460
+ m4v: "video/x-m4v",
461
+ hqx: "application/mac-binhex40",
462
+ portpkg: "application/vnd.macports.portpkg",
463
+ mgp: "application/vnd.osgeo.mapguide.package",
464
+ mrc: "application/marc",
465
+ mrcx: "application/marcxml+xml",
466
+ mxf: "application/mxf",
467
+ nbp: "application/vnd.wolfram.player",
468
+ ma: "application/mathematica",
469
+ mathml: "application/mathml+xml",
470
+ mbox: "application/mbox",
471
+ mc1: "application/vnd.medcalcdata",
472
+ mscml: "application/mediaservercontrol+xml",
473
+ cdkey: "application/vnd.mediastation.cdkey",
474
+ mwf: "application/vnd.mfer",
475
+ mfm: "application/vnd.mfmp",
476
+ msh: "model/mesh",
477
+ mads: "application/mads+xml",
478
+ mets: "application/mets+xml",
479
+ mods: "application/mods+xml",
480
+ meta4: "application/metalink4+xml",
481
+ mcd: "application/vnd.mcd",
482
+ flo: "application/vnd.micrografx.flo",
483
+ igx: "application/vnd.micrografx.igx",
484
+ es3: "application/vnd.eszigno3+xml",
485
+ mdb: "application/x-msaccess",
486
+ asf: "video/x-ms-asf",
487
+ exe: "application/x-msdownload",
488
+ cil: "application/vnd.ms-artgalry",
489
+ cab: "application/vnd.ms-cab-compressed",
490
+ ims: "application/vnd.ms-ims",
491
+ application: "application/x-ms-application",
492
+ clp: "application/x-msclip",
493
+ mdi: "image/vnd.ms-modi",
494
+ eot: "application/vnd.ms-fontobject",
495
+ xls: "application/vnd.ms-excel",
496
+ xlam: "application/vnd.ms-excel.addin.macroenabled.12",
497
+ xlsb: "application/vnd.ms-excel.sheet.binary.macroenabled.12",
498
+ xltm: "application/vnd.ms-excel.template.macroenabled.12",
499
+ xlsm: "application/vnd.ms-excel.sheet.macroenabled.12",
500
+ chm: "application/vnd.ms-htmlhelp",
501
+ crd: "application/x-mscardfile",
502
+ lrm: "application/vnd.ms-lrm",
503
+ mvb: "application/x-msmediaview",
504
+ mny: "application/x-msmoney",
505
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
506
+ sldx: "application/vnd.openxmlformats-officedocument.presentationml.slide",
507
+ ppsx: "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
508
+ potx: "application/vnd.openxmlformats-officedocument.presentationml.template",
509
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
510
+ xltx: "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
511
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
512
+ dotx: "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
513
+ obd: "application/x-msbinder",
514
+ thmx: "application/vnd.ms-officetheme",
515
+ onetoc: "application/onenote",
516
+ pya: "audio/vnd.ms-playready.media.pya",
517
+ pyv: "video/vnd.ms-playready.media.pyv",
518
+ ppt: "application/vnd.ms-powerpoint",
519
+ ppam: "application/vnd.ms-powerpoint.addin.macroenabled.12",
520
+ sldm: "application/vnd.ms-powerpoint.slide.macroenabled.12",
521
+ pptm: "application/vnd.ms-powerpoint.presentation.macroenabled.12",
522
+ ppsm: "application/vnd.ms-powerpoint.slideshow.macroenabled.12",
523
+ potm: "application/vnd.ms-powerpoint.template.macroenabled.12",
524
+ mpp: "application/vnd.ms-project",
525
+ pub: "application/x-mspublisher",
526
+ scd: "application/x-msschedule",
527
+ xap: "application/x-silverlight-app",
528
+ stl: "application/vnd.ms-pki.stl",
529
+ cat: "application/vnd.ms-pki.seccat",
530
+ vsd: "application/vnd.visio",
531
+ vsdx: "application/vnd.visio2013",
532
+ wm: "video/x-ms-wm",
533
+ wma: "audio/x-ms-wma",
534
+ wax: "audio/x-ms-wax",
535
+ wmx: "video/x-ms-wmx",
536
+ wmd: "application/x-ms-wmd",
537
+ wpl: "application/vnd.ms-wpl",
538
+ wmz: "application/x-ms-wmz",
539
+ wmv: "video/x-ms-wmv",
540
+ wvx: "video/x-ms-wvx",
541
+ wmf: "application/x-msmetafile",
542
+ trm: "application/x-msterminal",
543
+ doc: "application/msword",
544
+ docm: "application/vnd.ms-word.document.macroenabled.12",
545
+ dotm: "application/vnd.ms-word.template.macroenabled.12",
546
+ wri: "application/x-mswrite",
547
+ wps: "application/vnd.ms-works",
548
+ xbap: "application/x-ms-xbap",
549
+ xps: "application/vnd.ms-xpsdocument",
550
+ mid: "audio/midi",
551
+ mpy: "application/vnd.ibm.minipay",
552
+ afp: "application/vnd.ibm.modcap",
553
+ rms: "application/vnd.jcp.javame.midlet-rms",
554
+ tmo: "application/vnd.tmobile-livetv",
555
+ prc: "application/x-mobipocket-ebook",
556
+ mbk: "application/vnd.mobius.mbk",
557
+ dis: "application/vnd.mobius.dis",
558
+ plc: "application/vnd.mobius.plc",
559
+ mqy: "application/vnd.mobius.mqy",
560
+ msl: "application/vnd.mobius.msl",
561
+ txf: "application/vnd.mobius.txf",
562
+ daf: "application/vnd.mobius.daf",
563
+ fly: "text/vnd.fly",
564
+ mpc: "application/vnd.mophun.certificate",
565
+ mpn: "application/vnd.mophun.application",
566
+ mj2: "video/mj2",
567
+ mpga: "audio/mpeg",
568
+ mxu: "video/vnd.mpegurl",
569
+ mpeg: "video/mpeg",
570
+ m21: "application/mp21",
571
+ mp4a: "audio/mp4",
572
+ mp4: "video/mp4",
573
+ m3u8: "application/vnd.apple.mpegurl",
574
+ mus: "application/vnd.musician",
575
+ msty: "application/vnd.muvee.style",
576
+ mxml: "application/xv+xml",
577
+ ngdat: "application/vnd.nokia.n-gage.data",
578
+ "n-gage": "application/vnd.nokia.n-gage.symbian.install",
579
+ ncx: "application/x-dtbncx+xml",
580
+ nc: "application/x-netcdf",
581
+ nlu: "application/vnd.neurolanguage.nlu",
582
+ dna: "application/vnd.dna",
583
+ nnd: "application/vnd.noblenet-directory",
584
+ nns: "application/vnd.noblenet-sealer",
585
+ nnw: "application/vnd.noblenet-web",
586
+ rpst: "application/vnd.nokia.radio-preset",
587
+ rpss: "application/vnd.nokia.radio-presets",
588
+ n3: "text/n3",
589
+ edm: "application/vnd.novadigm.edm",
590
+ edx: "application/vnd.novadigm.edx",
591
+ ext: "application/vnd.novadigm.ext",
592
+ gph: "application/vnd.flographit",
593
+ ecelp4800: "audio/vnd.nuera.ecelp4800",
594
+ ecelp7470: "audio/vnd.nuera.ecelp7470",
595
+ ecelp9600: "audio/vnd.nuera.ecelp9600",
596
+ oda: "application/oda",
597
+ ogx: "application/ogg",
598
+ oga: "audio/ogg",
599
+ ogv: "video/ogg",
600
+ dd2: "application/vnd.oma.dd2+xml",
601
+ oth: "application/vnd.oasis.opendocument.text-web",
602
+ opf: "application/oebps-package+xml",
603
+ qbo: "application/vnd.intu.qbo",
604
+ oxt: "application/vnd.openofficeorg.extension",
605
+ osf: "application/vnd.yamaha.openscoreformat",
606
+ weba: "audio/webm",
607
+ webm: "video/webm",
608
+ odc: "application/vnd.oasis.opendocument.chart",
609
+ otc: "application/vnd.oasis.opendocument.chart-template",
610
+ odb: "application/vnd.oasis.opendocument.database",
611
+ odf: "application/vnd.oasis.opendocument.formula",
612
+ odft: "application/vnd.oasis.opendocument.formula-template",
613
+ odg: "application/vnd.oasis.opendocument.graphics",
614
+ otg: "application/vnd.oasis.opendocument.graphics-template",
615
+ odi: "application/vnd.oasis.opendocument.image",
616
+ oti: "application/vnd.oasis.opendocument.image-template",
617
+ odp: "application/vnd.oasis.opendocument.presentation",
618
+ otp: "application/vnd.oasis.opendocument.presentation-template",
619
+ ods: "application/vnd.oasis.opendocument.spreadsheet",
620
+ ots: "application/vnd.oasis.opendocument.spreadsheet-template",
621
+ odt: "application/vnd.oasis.opendocument.text",
622
+ odm: "application/vnd.oasis.opendocument.text-master",
623
+ ott: "application/vnd.oasis.opendocument.text-template",
624
+ ktx: "image/ktx",
625
+ sxc: "application/vnd.sun.xml.calc",
626
+ stc: "application/vnd.sun.xml.calc.template",
627
+ sxd: "application/vnd.sun.xml.draw",
628
+ std: "application/vnd.sun.xml.draw.template",
629
+ sxi: "application/vnd.sun.xml.impress",
630
+ sti: "application/vnd.sun.xml.impress.template",
631
+ sxm: "application/vnd.sun.xml.math",
632
+ sxw: "application/vnd.sun.xml.writer",
633
+ sxg: "application/vnd.sun.xml.writer.global",
634
+ stw: "application/vnd.sun.xml.writer.template",
635
+ otf: "application/x-font-otf",
636
+ osfpvg: "application/vnd.yamaha.openscoreformat.osfpvg+xml",
637
+ dp: "application/vnd.osgi.dp",
638
+ pdb: "application/vnd.palm",
639
+ p: "text/x-pascal",
640
+ paw: "application/vnd.pawaafile",
641
+ pclxl: "application/vnd.hp-pclxl",
642
+ efif: "application/vnd.picsel",
643
+ pcx: "image/x-pcx",
644
+ psd: "image/vnd.adobe.photoshop",
645
+ prf: "application/pics-rules",
646
+ pic: "image/x-pict",
647
+ chat: "application/x-chat",
648
+ p10: "application/pkcs10",
649
+ p12: "application/x-pkcs12",
650
+ p7m: "application/pkcs7-mime",
651
+ p7s: "application/pkcs7-signature",
652
+ p7r: "application/x-pkcs7-certreqresp",
653
+ p7b: "application/x-pkcs7-certificates",
654
+ p8: "application/pkcs8",
655
+ plf: "application/vnd.pocketlearn",
656
+ pnm: "image/x-portable-anymap",
657
+ pbm: "image/x-portable-bitmap",
658
+ pcf: "application/x-font-pcf",
659
+ pfr: "application/font-tdpfr",
660
+ pgn: "application/x-chess-pgn",
661
+ pgm: "image/x-portable-graymap",
662
+ png: "image/png",
663
+ ppm: "image/x-portable-pixmap",
664
+ pskcxml: "application/pskc+xml",
665
+ pml: "application/vnd.ctc-posml",
666
+ ai: "application/postscript",
667
+ pfa: "application/x-font-type1",
668
+ pbd: "application/vnd.powerbuilder6",
669
+ pgp: "application/pgp-signature",
670
+ box: "application/vnd.previewsystems.box",
671
+ ptid: "application/vnd.pvi.ptid1",
672
+ pls: "application/pls+xml",
673
+ str: "application/vnd.pg.format",
674
+ ei6: "application/vnd.pg.osasli",
675
+ dsc: "text/prs.lines.tag",
676
+ psf: "application/x-font-linux-psf",
677
+ qps: "application/vnd.publishare-delta-tree",
678
+ wg: "application/vnd.pmi.widget",
679
+ qxd: "application/vnd.quark.quarkxpress",
680
+ esf: "application/vnd.epson.esf",
681
+ msf: "application/vnd.epson.msf",
682
+ ssf: "application/vnd.epson.ssf",
683
+ qam: "application/vnd.epson.quickanime",
684
+ qfx: "application/vnd.intu.qfx",
685
+ qt: "video/quicktime",
686
+ rar: "application/x-rar-compressed",
687
+ ram: "audio/x-pn-realaudio",
688
+ rmp: "audio/x-pn-realaudio-plugin",
689
+ rsd: "application/rsd+xml",
690
+ rm: "application/vnd.rn-realmedia",
691
+ bed: "application/vnd.realvnc.bed",
692
+ mxl: "application/vnd.recordare.musicxml",
693
+ musicxml: "application/vnd.recordare.musicxml+xml",
694
+ rnc: "application/relax-ng-compact-syntax",
695
+ rdz: "application/vnd.data-vision.rdz",
696
+ rdf: "application/rdf+xml",
697
+ rp9: "application/vnd.cloanto.rp9",
698
+ jisp: "application/vnd.jisp",
699
+ rtf: "application/rtf",
700
+ rtx: "text/richtext",
701
+ link66: "application/vnd.route66.link66+xml",
702
+ rss: "application/rss+xml",
703
+ shf: "application/shf+xml",
704
+ st: "application/vnd.sailingtracker.track",
705
+ svg: "image/svg+xml",
706
+ sus: "application/vnd.sus-calendar",
707
+ sru: "application/sru+xml",
708
+ setpay: "application/set-payment-initiation",
709
+ setreg: "application/set-registration-initiation",
710
+ sema: "application/vnd.sema",
711
+ semd: "application/vnd.semd",
712
+ semf: "application/vnd.semf",
713
+ see: "application/vnd.seemail",
714
+ snf: "application/x-font-snf",
715
+ spq: "application/scvp-vp-request",
716
+ spp: "application/scvp-vp-response",
717
+ scq: "application/scvp-cv-request",
718
+ scs: "application/scvp-cv-response",
719
+ sdp: "application/sdp",
720
+ etx: "text/x-setext",
721
+ movie: "video/x-sgi-movie",
722
+ ifm: "application/vnd.shana.informed.formdata",
723
+ itp: "application/vnd.shana.informed.formtemplate",
724
+ iif: "application/vnd.shana.informed.interchange",
725
+ ipk: "application/vnd.shana.informed.package",
726
+ tfi: "application/thraud+xml",
727
+ shar: "application/x-shar",
728
+ rgb: "image/x-rgb",
729
+ slt: "application/vnd.epson.salt",
730
+ aso: "application/vnd.accpac.simply.aso",
731
+ imp: "application/vnd.accpac.simply.imp",
732
+ twd: "application/vnd.simtech-mindmapper",
733
+ csp: "application/vnd.commonspace",
734
+ saf: "application/vnd.yamaha.smaf-audio",
735
+ mmf: "application/vnd.smaf",
736
+ spf: "application/vnd.yamaha.smaf-phrase",
737
+ teacher: "application/vnd.smart.teacher",
738
+ svd: "application/vnd.svd",
739
+ rq: "application/sparql-query",
740
+ srx: "application/sparql-results+xml",
741
+ gram: "application/srgs",
742
+ grxml: "application/srgs+xml",
743
+ ssml: "application/ssml+xml",
744
+ skp: "application/vnd.koan",
745
+ sgml: "text/sgml",
746
+ sdc: "application/vnd.stardivision.calc",
747
+ sda: "application/vnd.stardivision.draw",
748
+ sdd: "application/vnd.stardivision.impress",
749
+ smf: "application/vnd.stardivision.math",
750
+ sdw: "application/vnd.stardivision.writer",
751
+ sgl: "application/vnd.stardivision.writer-global",
752
+ sm: "application/vnd.stepmania.stepchart",
753
+ sit: "application/x-stuffit",
754
+ sitx: "application/x-stuffitx",
755
+ sdkm: "application/vnd.solent.sdkm+xml",
756
+ xo: "application/vnd.olpc-sugar",
757
+ au: "audio/basic",
758
+ wqd: "application/vnd.wqd",
759
+ sis: "application/vnd.symbian.install",
760
+ smi: "application/smil+xml",
761
+ xsm: "application/vnd.syncml+xml",
762
+ bdm: "application/vnd.syncml.dm+wbxml",
763
+ xdm: "application/vnd.syncml.dm+xml",
764
+ sv4cpio: "application/x-sv4cpio",
765
+ sv4crc: "application/x-sv4crc",
766
+ sbml: "application/sbml+xml",
767
+ tsv: "text/tab-separated-values",
768
+ tiff: "image/tiff",
769
+ tao: "application/vnd.tao.intent-module-archive",
770
+ tar: "application/x-tar",
771
+ tcl: "application/x-tcl",
772
+ tex: "application/x-tex",
773
+ tfm: "application/x-tex-tfm",
774
+ tei: "application/tei+xml",
775
+ txt: "text/plain",
776
+ dxp: "application/vnd.spotfire.dxp",
777
+ sfs: "application/vnd.spotfire.sfs",
778
+ tsd: "application/timestamped-data",
779
+ tpt: "application/vnd.trid.tpt",
780
+ mxs: "application/vnd.triscape.mxs",
781
+ t: "text/troff",
782
+ tra: "application/vnd.trueapp",
783
+ ttf: "application/x-font-ttf",
784
+ ttl: "text/turtle",
785
+ umj: "application/vnd.umajin",
786
+ uoml: "application/vnd.uoml+xml",
787
+ unityweb: "application/vnd.unity",
788
+ ufd: "application/vnd.ufdl",
789
+ uri: "text/uri-list",
790
+ utz: "application/vnd.uiq.theme",
791
+ ustar: "application/x-ustar",
792
+ uu: "text/x-uuencode",
793
+ vcs: "text/x-vcalendar",
794
+ vcf: "text/x-vcard",
795
+ vcd: "application/x-cdlink",
796
+ vsf: "application/vnd.vsf",
797
+ wrl: "model/vrml",
798
+ vcx: "application/vnd.vcx",
799
+ mts: "model/vnd.mts",
800
+ vtu: "model/vnd.vtu",
801
+ vis: "application/vnd.visionary",
802
+ viv: "video/vnd.vivo",
803
+ ccxml: "application/ccxml+xml,",
804
+ vxml: "application/voicexml+xml",
805
+ src: "application/x-wais-source",
806
+ wbxml: "application/vnd.wap.wbxml",
807
+ wbmp: "image/vnd.wap.wbmp",
808
+ wav: "audio/x-wav",
809
+ davmount: "application/davmount+xml",
810
+ woff: "application/x-font-woff",
811
+ wspolicy: "application/wspolicy+xml",
812
+ webp: "image/webp",
813
+ wtb: "application/vnd.webturbo",
814
+ wgt: "application/widget",
815
+ hlp: "application/winhlp",
816
+ wml: "text/vnd.wap.wml",
817
+ wmls: "text/vnd.wap.wmlscript",
818
+ wmlsc: "application/vnd.wap.wmlscriptc",
819
+ wpd: "application/vnd.wordperfect",
820
+ stf: "application/vnd.wt.stf",
821
+ wsdl: "application/wsdl+xml",
822
+ xbm: "image/x-xbitmap",
823
+ xpm: "image/x-xpixmap",
824
+ xwd: "image/x-xwindowdump",
825
+ der: "application/x-x509-ca-cert",
826
+ fig: "application/x-xfig",
827
+ xhtml: "application/xhtml+xml",
828
+ xml: "application/xml",
829
+ xdf: "application/xcap-diff+xml",
830
+ xenc: "application/xenc+xml",
831
+ xer: "application/patch-ops-error+xml",
832
+ rl: "application/resource-lists+xml",
833
+ rs: "application/rls-services+xml",
834
+ rld: "application/resource-lists-diff+xml",
835
+ xslt: "application/xslt+xml",
836
+ xop: "application/xop+xml",
837
+ xpi: "application/x-xpinstall",
838
+ xspf: "application/xspf+xml",
839
+ xul: "application/vnd.mozilla.xul+xml",
840
+ xyz: "chemical/x-xyz",
841
+ yaml: "text/yaml",
842
+ yang: "application/yang",
843
+ yin: "application/yin+xml",
844
+ zir: "application/vnd.zul",
845
+ zip: "application/zip",
846
+ zmm: "application/vnd.handheld-entertainment+xml",
847
+ zaz: "application/vnd.zzazz.deck+xml"
848
+ };
849
+
850
+ // TODO: write this out to avoid compute
851
+ var MIME_TYPES_TO_EXT = Object.fromEntries(Object.entries(EXT_TO_MIME_TYPES).map(function (_ref) {
852
+ var _ref2 = _slicedToArray(_ref, 2),
853
+ k = _ref2[0],
854
+ v = _ref2[1];
855
+ return [v, k];
856
+ }));
857
+
858
+ var MIME_TYPE_REGEX = /^data:(.*?);base64,/;
159
859
  function getMimeType(base64Url) {
160
860
  var match = MIME_TYPE_REGEX.exec(base64Url);
161
861
  if (match && match[1]) {
@@ -164,41 +864,32 @@ function getMimeType(base64Url) {
164
864
  return;
165
865
  }
166
866
  function mimeTypeToFileExt(mimeType) {
167
- if (mimeType === "image/svg+xml") {
168
- return "svg";
169
- }
170
- if (mimeType === "image/vnd.microsoft.icon") {
171
- return "ico";
172
- }
173
- if (mimeType.startsWith("image/")) {
174
- return mimeType.slice("image/".length);
867
+ var recognizedMimeType = MIME_TYPES_TO_EXT[mimeType];
868
+ if (recognizedMimeType) {
869
+ return recognizedMimeType;
175
870
  }
176
- return mimeType;
871
+ return mimeType.split("/")[1];
177
872
  }
178
873
  function filenameToMimeType(filename) {
179
874
  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";
875
+ var recognizedExt = ext && EXT_TO_MIME_TYPES[ext];
876
+ if (recognizedExt) {
877
+ return recognizedExt;
188
878
  }
189
- return "image/".concat(imageType);
190
879
  }
191
880
 
192
- var HeaderRegEx = /^h([\d+])$/;
193
- function lexicalToRichTextSource(node) {
194
- var markdownIRBlocks = node.children.map(createBlock);
195
- return fromIRToRichTextSource(markdownIRBlocks);
881
+ function remirrorToRichTextSource(node) {
882
+ var files = {};
883
+ var markdownIRBlocks = node.content.map(function (child) {
884
+ return createBlock(child, files);
885
+ });
886
+ return fromIRToRichTextSource(markdownIRBlocks, files);
196
887
  }
197
- function createBlock(node) {
888
+ function createBlock(node, files) {
198
889
  if (node.type === "heading") {
199
- var _node$tag$match;
890
+ var _node$attrs, _node$content;
200
891
  var headingTag = "";
201
- var depth = Number((_node$tag$match = node.tag.match(HeaderRegEx)) === null || _node$tag$match === void 0 ? void 0 : _node$tag$match[1]);
892
+ var depth = ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.level) || 1;
202
893
  if (Number.isNaN(depth)) {
203
894
  throw new Error("Invalid header depth");
204
895
  }
@@ -208,10 +899,13 @@ function createBlock(node) {
208
899
  var headingText = ["".concat(headingTag, " ")];
209
900
  return {
210
901
  type: "block",
211
- children: headingText.concat.apply(headingText, _toConsumableArray(node.children.map(transformLeafNode)))
902
+ children: headingText.concat.apply(headingText, _toConsumableArray(((_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.map(function (child) {
903
+ return transformLeafNode(child, files);
904
+ })) || []))
212
905
  };
213
906
  } else if (node.type === "paragraph") {
214
- if (node.children.length === 0) {
907
+ var _node$content2;
908
+ if (!node.content || ((_node$content2 = node.content) === null || _node$content2 === void 0 ? void 0 : _node$content2.length) === 0) {
215
909
  return {
216
910
  type: "block",
217
911
  children: ["<br />"]
@@ -219,26 +913,26 @@ function createBlock(node) {
219
913
  }
220
914
  return {
221
915
  type: "block",
222
- children: node.children.map(function (child) {
223
- return transformLeafNode(child);
916
+ children: node.content.map(function (child) {
917
+ return transformLeafNode(child, files);
224
918
  })
225
919
  };
226
- } else if (node.type === "list") {
920
+ } else if (node.type === "bulletList" || node.type === "orderedList") {
921
+ var _node$content3;
227
922
  return {
228
923
  type: "block",
229
- children: node.children.flatMap(function (child, i) {
230
- return formatListItemNode(getListPrefix(node), child, 0, i === 0);
231
- })
924
+ children: ((_node$content3 = node.content) === null || _node$content3 === void 0 ? void 0 : _node$content3.flatMap(function (child, i) {
925
+ return formatListItemNode(getListPrefix(node), child, 0, files, i === 0);
926
+ })) || []
232
927
  };
233
928
  } else {
234
929
  var exhaustiveCheck = node;
235
930
  throw new Error("Unhandled node type: ".concat("type" in exhaustiveCheck ? "exhaustiveCheck.type" : "unknown"));
236
931
  }
237
932
  }
238
- function fromIRToRichTextSource(markdownIRBlocks) {
933
+ function fromIRToRichTextSource(markdownIRBlocks, files) {
239
934
  var templateStrings = ["\n"];
240
935
  var exprs = [];
241
- var files = {};
242
936
  for (var blockIdx = 0; blockIdx < markdownIRBlocks.length; blockIdx++) {
243
937
  var block = markdownIRBlocks[blockIdx];
244
938
  var _iterator = _createForOfIteratorHelper(block.children),
@@ -249,10 +943,10 @@ function fromIRToRichTextSource(markdownIRBlocks) {
249
943
  if (typeof child === "string") {
250
944
  templateStrings[templateStrings.length - 1] += child;
251
945
  } else {
252
- if (child.type === "image") {
253
- exprs.push(fromLexicalImageNode(child, files));
254
- } else if (child.type === "link") {
255
- exprs.push(fromLexicalLinkNode(child));
946
+ if (child._type === "file") {
947
+ exprs.push(child);
948
+ } else if (child._type === "link") {
949
+ exprs.push(child);
256
950
  } else {
257
951
  var exhaustiveCheck = child;
258
952
  throw new Error("Unexpected node type: ".concat(JSON.stringify(exhaustiveCheck, null, 2)));
@@ -274,7 +968,17 @@ function fromIRToRichTextSource(markdownIRBlocks) {
274
968
  return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "richtext"), "templateStrings", templateStrings), "exprs", exprs), "files", files);
275
969
  }
276
970
  function formatText(node) {
277
- var classes = typeof node.format === "number" ? fromLexicalFormat(node.format) : [];
971
+ var _node$marks;
972
+ var classes = ((_node$marks = node.marks) === null || _node$marks === void 0 ? void 0 : _node$marks.flatMap(function (mark) {
973
+ if (mark.type === "bold") {
974
+ return ["bold"];
975
+ } else if (mark.type === "italic") {
976
+ return ["italic"];
977
+ } else if (mark.type === "strike") {
978
+ return ["line-through"];
979
+ }
980
+ return [];
981
+ })) || [];
278
982
  var text = node.text.trimStart();
279
983
  var prefixWS = node.text.length - text.length;
280
984
  text = text.trimEnd();
@@ -293,87 +997,94 @@ function formatText(node) {
293
997
  // text = splitIntoChunks(text);
294
998
  return "".concat(" ".repeat(prefixWS)).concat(text).concat(" ".repeat(suffixWS));
295
999
  }
296
- function transformLeafNode(node) {
1000
+ function transformLeafNode(node, files) {
297
1001
  if (node.type === "text") {
1002
+ var _node$marks2;
1003
+ var linkMark = (_node$marks2 = node.marks) === null || _node$marks2 === void 0 ? void 0 : _node$marks2.find(function (mark) {
1004
+ return mark.type === "link";
1005
+ });
1006
+ if ((linkMark === null || linkMark === void 0 ? void 0 : linkMark.type) === "link") {
1007
+ return {
1008
+ _type: "link",
1009
+ href: linkMark.attrs.href,
1010
+ children: [formatText(node)]
1011
+ };
1012
+ }
298
1013
  return formatText(node);
299
- } else if (node.type === "linebreak") {
300
- return "\n";
1014
+ } else if (node.type === "hardBreak") {
1015
+ return "<br />";
1016
+ } else if (node.type === "image") {
1017
+ return fromRemirrorImageNode(node, files);
301
1018
  } else {
302
- return node;
1019
+ var exhaustiveCheck = node;
1020
+ throw new Error("Unexpected node type: ".concat(JSON.stringify(exhaustiveCheck)));
303
1021
  }
304
1022
  }
305
- function formatListItemNode(listPrefix, node, indent) {
306
- var _node$children;
307
- var isFirstTopLevelListItem = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1023
+ function formatListItemNode(listPrefix, node, indent, files) {
1024
+ var _node$content4, _node$content5;
1025
+ var isFirstTopLevelListItem = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
308
1026
  var newLine = isFirstTopLevelListItem ? "" : "\n";
309
1027
  var prefix = ["".concat(newLine).concat(" ".repeat(indent)).concat(listPrefix)];
310
- if (((_node$children = node.children) === null || _node$children === void 0 || (_node$children = _node$children[0]) === null || _node$children === void 0 ? void 0 : _node$children.type) !== "list") {
1028
+ if (!(((_node$content4 = node.content) === null || _node$content4 === void 0 || (_node$content4 = _node$content4[0]) === null || _node$content4 === void 0 ? void 0 : _node$content4.type) === "bulletList" || ((_node$content5 = node.content) === null || _node$content5 === void 0 || (_node$content5 = _node$content5[0]) === null || _node$content5 === void 0 ? void 0 : _node$content5.type) === "orderedList")) {
311
1029
  prefix.push(" ");
312
1030
  }
313
- return prefix.concat(node.children.flatMap(function (child) {
314
- if (child.type === "list") {
315
- return child.children.flatMap(function (subChild) {
316
- return formatListItemNode(getListPrefix(child), subChild, indent + 4);
1031
+ return prefix.concat((node.content || []).flatMap(function (child, i) {
1032
+ if (child.type === "bulletList" || child.type === "orderedList") {
1033
+ return (child.content || []).flatMap(function (subChild) {
1034
+ return formatListItemNode(getListPrefix(child), subChild, indent + 4, files);
317
1035
  });
318
1036
  } else {
319
- return [transformLeafNode(child)];
1037
+ return (child.content || []).flatMap(function (subChild) {
1038
+ var _child$content, _child$content2;
1039
+ var res = [];
1040
+ if ((_child$content = child.content) !== null && _child$content !== void 0 && _child$content.length && ((_child$content2 = child.content) === null || _child$content2 === void 0 ? void 0 : _child$content2.length) > 0 && i > 0) {
1041
+ res.push("<br />\n");
1042
+ }
1043
+ res.push(transformLeafNode(subChild, files));
1044
+ return res;
1045
+ });
320
1046
  }
321
1047
  }));
322
1048
  }
323
1049
  function getListPrefix(node) {
324
- if (node.listType === "bullet") {
1050
+ if (node.type === "bulletList") {
325
1051
  return "-";
326
- } else if (node.listType === "number") {
1052
+ } else if (node.type === "orderedList") {
327
1053
  return "1.";
328
1054
  } else {
329
- throw new Error("Unhandled list type: ".concat(node.listType));
1055
+ var exhaustiveCheck = node;
1056
+ throw new Error("Unhandled list node: ".concat(JSON.stringify(exhaustiveCheck)));
330
1057
  }
331
1058
  }
332
- var FORMAT_MAPPING$1 = {
333
- bold: 1,
334
- // 0001
335
- italic: 2,
336
- // 0010
337
- "line-through": 4 // 0100
338
- // underline: 8, // 1000
339
- };
340
-
341
- function fromLexicalFormat(format) {
342
- return Object.entries(FORMAT_MAPPING$1).flatMap(function (_ref2) {
343
- var _ref3 = _slicedToArray(_ref2, 2),
344
- key = _ref3[0],
345
- value = _ref3[1];
346
- if ((value & /* bitwise and */format) === value) {
347
- return [key];
348
- }
349
- return [];
350
- });
351
- }
352
1059
  var textEncoder = new TextEncoder();
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);
1060
+ function fromRemirrorImageNode(node, files) {
1061
+ if (node.attrs && node.attrs.src.startsWith("data:")) {
1062
+ var sha256 = Internal.getSHA256Hash(textEncoder.encode(node.attrs.src));
1063
+ var mimeType = getMimeType(node.attrs.src);
357
1064
  if (mimeType === undefined) {
358
- throw new Error("Could not detect Mime Type for image: ".concat(node.src));
1065
+ throw new Error("Could not detect Mime Type for image: ".concat(node.attrs.src));
359
1066
  }
360
1067
  var fileExt = mimeTypeToFileExt(mimeType);
361
- var filePath = "/public/".concat(sha256, ".").concat(fileExt);
362
- files[filePath] = node.src;
1068
+ var fileName = node.attrs.fileName || "".concat(sha256, ".").concat(fileExt);
1069
+ var filePath = "/public/".concat(fileName);
1070
+ files[filePath] = node.attrs.src;
363
1071
  return _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "file"), FILE_REF_PROP, filePath), "metadata", {
364
- width: node.width || 0,
365
- height: node.height || 0,
1072
+ width: typeof node.attrs.width === "number" ? node.attrs.width : 0,
1073
+ height: typeof node.attrs.height === "number" ? node.attrs.height : 0,
366
1074
  sha256: sha256 || "",
367
1075
  mimeType: mimeType
368
1076
  });
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,
1077
+ } else if (node.attrs) {
1078
+ var _sha = getParam("sha256", node.attrs.src);
1079
+ var noParamsSrc = node.attrs.src.split("?")[0];
1080
+ return _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "file"), FILE_REF_PROP, "/public".concat(node.attrs.src.split("?")[0])), "metadata", {
1081
+ width: typeof node.attrs.width === "number" ? node.attrs.width : 0,
1082
+ height: typeof node.attrs.height === "number" ? node.attrs.height : 0,
374
1083
  sha256: _sha || "",
375
- mimeType: node.mimeType || ""
1084
+ mimeType: noParamsSrc && filenameToMimeType(noParamsSrc) || ""
376
1085
  });
1086
+ } else {
1087
+ throw new Error("Invalid image node (no attrs): " + JSON.stringify(node));
377
1088
  }
378
1089
  }
379
1090
  function getParam(param, url) {
@@ -388,196 +1099,6 @@ function getParam(param, url) {
388
1099
  }
389
1100
  return undefined;
390
1101
  }
391
- function fromLexicalLinkNode(node) {
392
- return _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "link"), "href", node.url), "children", node.children.map(formatText));
393
- }
394
-
395
- function ownKeys(e, r) {
396
- var t = Object.keys(e);
397
- if (Object.getOwnPropertySymbols) {
398
- var o = Object.getOwnPropertySymbols(e);
399
- r && (o = o.filter(function (r) {
400
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
401
- })), t.push.apply(t, o);
402
- }
403
- return t;
404
- }
405
- function _objectSpread2(e) {
406
- for (var r = 1; r < arguments.length; r++) {
407
- var t = null != arguments[r] ? arguments[r] : {};
408
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
409
- _defineProperty(e, r, t[r]);
410
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
411
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
412
- });
413
- }
414
- return e;
415
- }
416
-
417
- /// Serialized Lexical Nodes:
418
- // TODO: replace with Lexical libs types - not currently exported?
419
- var COMMON_LEXICAL_PROPS = {
420
- version: 1,
421
- format: "",
422
- indent: 0,
423
- direction: null
424
- };
425
- function toLexicalNode(node) {
426
- var useBreakNode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
427
- if (typeof node === "string") {
428
- return _objectSpread2(_objectSpread2({}, COMMON_LEXICAL_PROPS), {}, {
429
- type: "text",
430
- format: "",
431
- text: node
432
- });
433
- }
434
- if ("tag" in node) {
435
- switch (node.tag) {
436
- case "h1":
437
- return toLexicalHeadingNode(node);
438
- case "h2":
439
- return toLexicalHeadingNode(node);
440
- case "h3":
441
- return toLexicalHeadingNode(node);
442
- case "h4":
443
- return toLexicalHeadingNode(node);
444
- case "h5":
445
- return toLexicalHeadingNode(node);
446
- case "h6":
447
- return toLexicalHeadingNode(node);
448
- case "li":
449
- return toLexicalListItemNode(node);
450
- case "p":
451
- return toLexicalParagraphNode(node);
452
- case "ul":
453
- return toLexicalListNode(node);
454
- case "ol":
455
- return toLexicalListNode(node);
456
- case "span":
457
- return toLexicalTextNode(node);
458
- case "a":
459
- return toLexicalLinkNode(node);
460
- case "img":
461
- return toLexicalImageNode(node);
462
- case "br":
463
- if (useBreakNode) {
464
- return _objectSpread2(_objectSpread2({}, COMMON_LEXICAL_PROPS), {}, {
465
- type: "linebreak"
466
- });
467
- }
468
- return toLexicalPseudoLineBreakNode();
469
- default:
470
- throw Error("Unexpected node tag: " + JSON.stringify(node, null, 2));
471
- }
472
- } else {
473
- throw Error("Unexpected node: " + JSON.stringify(node, null, 2));
474
- }
475
- }
476
- function toLexicalImageNode(node) {
477
- var url = node.src;
478
- return _objectSpread2(_objectSpread2({}, COMMON_LEXICAL_PROPS), {}, {
479
- type: "image",
480
- src: url,
481
- width: node.width,
482
- height: node.height,
483
- mimeType: node.mimeType
484
- // TODO: altText
485
- });
486
- }
487
-
488
- function toLexicalLinkNode(link) {
489
- return _objectSpread2(_objectSpread2({}, COMMON_LEXICAL_PROPS), {}, {
490
- type: "link",
491
- url: link.href,
492
- children: link.children.map(function (child) {
493
- return toLexicalNode(child);
494
- })
495
- });
496
- }
497
- function richTextSourceToLexical(richtext) {
498
- return _objectSpread2(_objectSpread2({}, COMMON_LEXICAL_PROPS), {}, {
499
- format: "",
500
- type: "root",
501
- children: richtext.children.map(function (child) {
502
- return toLexicalNode(child);
503
- })
504
- });
505
- }
506
- function toLexicalHeadingNode(heading) {
507
- return _objectSpread2(_objectSpread2({}, COMMON_LEXICAL_PROPS), {}, {
508
- type: "heading",
509
- tag: heading.tag,
510
- children: heading.children.map(function (child) {
511
- return toLexicalNode(child);
512
- })
513
- });
514
- }
515
- function toLexicalParagraphNode(paragraph) {
516
- return _objectSpread2(_objectSpread2({}, COMMON_LEXICAL_PROPS), {}, {
517
- type: "paragraph",
518
- children: paragraph.children.map(function (child) {
519
- return toLexicalNode(child, true);
520
- })
521
- });
522
- }
523
-
524
- // Lexical does not support line breaks, so we convert them to empty paragraphs
525
- function toLexicalPseudoLineBreakNode() {
526
- return _objectSpread2(_objectSpread2({}, COMMON_LEXICAL_PROPS), {}, {
527
- type: "paragraph",
528
- children: []
529
- });
530
- }
531
- function toLexicalListItemNode(listItem) {
532
- return _objectSpread2(_objectSpread2({}, COMMON_LEXICAL_PROPS), {}, {
533
- type: "listitem",
534
- children: listItem.children.map(function (child) {
535
- return toLexicalNode(child, true);
536
- })
537
- });
538
- }
539
- function toLexicalListNode(list) {
540
- return _objectSpread2(_objectSpread2({}, COMMON_LEXICAL_PROPS), {}, {
541
- type: "list",
542
- listType: list.tag === "ol" ? "number" : "bullet",
543
- children: list.children.map(function (child) {
544
- return toLexicalNode(child);
545
- })
546
- }, list.dir ? {
547
- direction: list.dir
548
- } : {
549
- direction: null
550
- });
551
- }
552
- var FORMAT_MAPPING = {
553
- bold: 1,
554
- // 0001
555
- italic: 2,
556
- // 0010
557
- "line-through": 4 // 0100
558
- // underline: 8, // 1000
559
- };
560
-
561
- function toLexicalFormat(classes) {
562
- return classes.reduce(function (prev, curr) {
563
- return prev | /* bitwise or */FORMAT_MAPPING[curr];
564
- }, 0);
565
- }
566
- function toLexicalTextNode(spanNode) {
567
- var child = spanNode.children[0];
568
- if (typeof child === "string") {
569
- return _objectSpread2(_objectSpread2({}, COMMON_LEXICAL_PROPS), {}, {
570
- type: "text",
571
- text: child,
572
- format: toLexicalFormat(spanNode.classes)
573
- });
574
- } else {
575
- // recurse the spans and merge their classes
576
- return toLexicalTextNode(_objectSpread2(_objectSpread2({}, child), {}, {
577
- classes: spanNode.classes.concat(child.classes)
578
- }));
579
- }
580
- }
581
1102
 
582
1103
  var VAL_START_TAG_PREFIX = '<val value="';
583
1104
  var VAL_START_TAG_SUFFIX = '">';
@@ -585,6 +1106,18 @@ var VAL_END_TAG = "</val>";
585
1106
  function parseTokens(tokens, sourceNodes, cursor) {
586
1107
  var insideList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
587
1108
  var children = [];
1109
+ function merge(token, clazz) {
1110
+ var parsedTokens = parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0);
1111
+ children.push({
1112
+ tag: "span",
1113
+ classes: [clazz].concat(parsedTokens.children.flatMap(function (child) {
1114
+ return typeof child === "string" ? [] : child.classes;
1115
+ })),
1116
+ children: parsedTokens.children.flatMap(function (child) {
1117
+ return typeof child === "string" ? child : child.children;
1118
+ })
1119
+ });
1120
+ }
588
1121
  var _loop = function _loop() {
589
1122
  var token = tokens[cursor];
590
1123
  if (token.type === "heading") {
@@ -598,23 +1131,11 @@ function parseTokens(tokens, sourceNodes, cursor) {
598
1131
  children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
599
1132
  });
600
1133
  } else if (token.type === "strong") {
601
- children.push({
602
- tag: "span",
603
- classes: ["bold"],
604
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
605
- });
1134
+ merge(token, "bold");
606
1135
  } else if (token.type === "em") {
607
- children.push({
608
- tag: "span",
609
- classes: ["italic"],
610
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
611
- });
1136
+ merge(token, "italic");
612
1137
  } else if (token.type === "del") {
613
- children.push({
614
- tag: "span",
615
- classes: ["line-through"],
616
- children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
617
- });
1138
+ merge(token, "line-through");
618
1139
  } else if (token.type === "text") {
619
1140
  if ("tokens" in token && Array.isArray(token.tokens)) {
620
1141
  children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
@@ -623,6 +1144,11 @@ function parseTokens(tokens, sourceNodes, cursor) {
623
1144
  var lines = token.raw.split("\n");
624
1145
  var tags = lines.flatMap(function (line, i) {
625
1146
  if (i === lines.length - 1) return [line];
1147
+ if (i === lines.length - 1 && line === "") return [];
1148
+ if (line === "") return {
1149
+ tag: "br",
1150
+ children: []
1151
+ };
626
1152
  return [line, {
627
1153
  tag: "br",
628
1154
  children: []
@@ -692,10 +1218,16 @@ function parseTokens(tokens, sourceNodes, cursor) {
692
1218
  }
693
1219
  var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
694
1220
  if (token.text.trim().match(br_html_regex)) {
1221
+ var _tokens;
695
1222
  children.push({
696
1223
  tag: "br",
697
1224
  children: []
698
1225
  });
1226
+ if (((_tokens = tokens[cursor + 1]) === null || _tokens === void 0 ? void 0 : _tokens.raw.trim()) === "") {
1227
+ // if next token is a new line or white-spaces, skip it
1228
+ // this typically means we have a <br> AND a new line, which, semantically, is just a <br>
1229
+ cursor++;
1230
+ }
699
1231
  }
700
1232
  } else if (token.type === "link") {
701
1233
  if (token.raw === token.href) {
@@ -755,8 +1287,338 @@ function parseRichTextSource(_ref) {
755
1287
  return _defineProperty(_defineProperty({}, VAL_EXTENSION, "richtext"), "children", children);
756
1288
  }
757
1289
 
1290
+ var RemirrorTextMark = z.object({
1291
+ type: z.union([z.literal("bold"), z.literal("strike"), z.literal("italic")])
1292
+ });
1293
+ var RemirrorLinkMark = z.object({
1294
+ type: z.literal("link"),
1295
+ attrs: z.object({
1296
+ href: z.string(),
1297
+ target: z.union([z.literal("_blank"), z["null"]()]),
1298
+ auto: z["boolean"]()
1299
+ })
1300
+ });
1301
+ var RemirrorText = z.intersection(z.object({
1302
+ type: z.literal("text"),
1303
+ text: z.string()
1304
+ }), z.object({
1305
+ marks: z.array(z.union([RemirrorTextMark, RemirrorLinkMark]))
1306
+ }).partial());
1307
+ var RemirrorBr = z.intersection(z.object({
1308
+ type: z.literal("hardBreak")
1309
+ }), z.object({
1310
+ marks: z.array(RemirrorTextMark)
1311
+ }).partial());
1312
+ var RemirrorImage = z.intersection(z.object({
1313
+ type: z.literal("image")
1314
+ }), z.object({
1315
+ attrs: z.intersection(z.object({
1316
+ src: z.string()
1317
+ }), z.object({
1318
+ align: z.union([z.literal("center"), z.literal("end"), z.literal("justify"), z.literal("left"), z.literal("match-parent"), z.literal("right"), z.literal("start"), z["null"]()]),
1319
+ alt: z.union([z.string(), z["null"]()]),
1320
+ height: z.union([z.string(), z.number(), z["null"]()]),
1321
+ width: z.union([z.string(), z.number(), z["null"]()]),
1322
+ rotate: z.union([z.string(), z["null"]()]),
1323
+ title: z.union([z.string(), z["null"]()]),
1324
+ fileName: z.union([z.string(), z["null"]()])
1325
+ }).partial())
1326
+ }).partial());
1327
+ var RemirrorHeading = z.intersection(z.object({
1328
+ type: z.literal("heading")
1329
+ }), z.object({
1330
+ attrs: z.object({
1331
+ level: z.number()
1332
+ }),
1333
+ content: z.array(z.union([RemirrorText, RemirrorBr]))
1334
+ }).partial());
1335
+ var RemirrorBulletList = z.lazy(function () {
1336
+ return z.intersection(z.object({
1337
+ type: z.literal("bulletList")
1338
+ }), z.object({
1339
+ content: z.array(RemirrorListItem)
1340
+ }).partial());
1341
+ });
1342
+ var RemirrorOrderedList = z.lazy(function () {
1343
+ return z.intersection(z.object({
1344
+ type: z.literal("orderedList")
1345
+ }), z.object({
1346
+ content: z.array(RemirrorListItem)
1347
+ }).partial());
1348
+ });
1349
+ var RemirrorListItem = z.lazy(function () {
1350
+ return z.intersection(z.object({
1351
+ type: z.literal("listItem")
1352
+ }), z.object({
1353
+ content: z.array(z.union([RemirrorParagraph, RemirrorBulletList, RemirrorOrderedList]))
1354
+ }).partial());
1355
+ });
1356
+ var RemirrorParagraph = z.intersection(z.object({
1357
+ type: z.literal("paragraph")
1358
+ }), z.object({
1359
+ content: z.array(z.union([RemirrorText, RemirrorImage, RemirrorBr]))
1360
+ }).partial());
1361
+ var RemirrorJSON = z.object({
1362
+ type: z.literal("doc"),
1363
+ content: z.array(z.union([RemirrorParagraph, RemirrorHeading, RemirrorBulletList, RemirrorOrderedList]))
1364
+ });
1365
+
1366
+ function ownKeys(e, r) {
1367
+ var t = Object.keys(e);
1368
+ if (Object.getOwnPropertySymbols) {
1369
+ var o = Object.getOwnPropertySymbols(e);
1370
+ r && (o = o.filter(function (r) {
1371
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
1372
+ })), t.push.apply(t, o);
1373
+ }
1374
+ return t;
1375
+ }
1376
+ function _objectSpread2(e) {
1377
+ for (var r = 1; r < arguments.length; r++) {
1378
+ var t = null != arguments[r] ? arguments[r] : {};
1379
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
1380
+ _defineProperty(e, r, t[r]);
1381
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
1382
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
1383
+ });
1384
+ }
1385
+ return e;
1386
+ }
1387
+
1388
+ function richTextToRemirror(richtext) {
1389
+ return {
1390
+ type: "doc",
1391
+ content: richtext.children.map(function (child) {
1392
+ return toRemirrorNode(child);
1393
+ })
1394
+ };
1395
+ }
1396
+ function toRemirrorNode(child) {
1397
+ switch (child.tag) {
1398
+ case "h1":
1399
+ return convertHeadingToRemirror(1, child.children);
1400
+ case "h2":
1401
+ return convertHeadingToRemirror(2, child.children);
1402
+ case "h3":
1403
+ return convertHeadingToRemirror(3, child.children);
1404
+ case "h4":
1405
+ return convertHeadingToRemirror(4, child.children);
1406
+ case "h5":
1407
+ return convertHeadingToRemirror(5, child.children);
1408
+ case "h6":
1409
+ return convertHeadingToRemirror(6, child.children);
1410
+ case "p":
1411
+ return convertParagraphToRemirror(child.children);
1412
+ case "ul":
1413
+ return convertUlToRemirror(child);
1414
+ case "ol":
1415
+ return convertOlToRemirror(child);
1416
+ case "br":
1417
+ return convertParagraphToRemirror([child]);
1418
+ default:
1419
+ {
1420
+ var _exhaustiveCheck = child;
1421
+ throw Error("Unexpected child node: " + JSON.stringify(_exhaustiveCheck));
1422
+ }
1423
+ }
1424
+ }
1425
+ function convertHeadingToRemirror(level, children) {
1426
+ return {
1427
+ type: "heading",
1428
+ attrs: {
1429
+ level: level
1430
+ },
1431
+ content: children.flatMap(convertStringOrSpanNodeToRemirror)
1432
+ };
1433
+ }
1434
+ function convertStringToRemirror(child) {
1435
+ return {
1436
+ type: "text",
1437
+ text: child
1438
+ };
1439
+ }
1440
+ function convertStringOrSpanNodeToRemirror(child) {
1441
+ if (typeof child === "string") {
1442
+ return [convertStringToRemirror(child)];
1443
+ }
1444
+ return convertSpanNodeToRemirror(child);
1445
+ }
1446
+ function convertSpanNodeToRemirror(spanNode) {
1447
+ if (spanNode.classes.length === 0 && spanNode.children.length === 1) {
1448
+ if (typeof spanNode.children[0] === "string") {
1449
+ return [convertStringToRemirror(spanNode.children[0])];
1450
+ } else {
1451
+ // TODO: replace with error logging and something more graceful?
1452
+ throw Error("Unexpected amount of children in span node: " + JSON.stringify(spanNode, null, 2));
1453
+ }
1454
+ }
1455
+ return spanNode.children.map(function (child) {
1456
+ return {
1457
+ type: "text",
1458
+ text: child,
1459
+ marks: spanNode.classes.map(function (className) {
1460
+ switch (className) {
1461
+ case "bold":
1462
+ return {
1463
+ type: "bold"
1464
+ };
1465
+ case "italic":
1466
+ return {
1467
+ type: "italic"
1468
+ };
1469
+ case "line-through":
1470
+ return {
1471
+ type: "strike"
1472
+ };
1473
+ default:
1474
+ {
1475
+ var _exhaustiveCheck = className;
1476
+ throw Error("Unexpected span class: " + _exhaustiveCheck);
1477
+ }
1478
+ }
1479
+ })
1480
+ };
1481
+ });
1482
+ }
1483
+ function convertParagraphToRemirror(children) {
1484
+ return {
1485
+ type: "paragraph",
1486
+ content: children.flatMap(function (child) {
1487
+ if (typeof child === "string") {
1488
+ return [convertStringToRemirror(child)];
1489
+ }
1490
+ switch (child.tag) {
1491
+ case "span":
1492
+ return convertSpanNodeToRemirror(child);
1493
+ case "a":
1494
+ return convertLinkNodeToRemirror(child);
1495
+ case "img":
1496
+ return [convertImageNodeToRemirror(child)];
1497
+ case "br":
1498
+ return [createRemirrorBr()];
1499
+ default:
1500
+ {
1501
+ var _exhaustiveCheck = child;
1502
+ throw Error("Unexpected paragraph child: " + JSON.stringify(_exhaustiveCheck));
1503
+ }
1504
+ }
1505
+ })
1506
+ };
1507
+ }
1508
+ function createRemirrorBr() {
1509
+ return {
1510
+ type: "hardBreak",
1511
+ marks: []
1512
+ };
1513
+ }
1514
+ function convertLinkNodeToRemirror(linkNode) {
1515
+ return linkNode.children.flatMap(convertStringOrSpanNodeToRemirror).map(function (remirrorText) {
1516
+ return _objectSpread2(_objectSpread2({}, remirrorText), {}, {
1517
+ marks: (remirrorText.marks || []).concat({
1518
+ type: "link",
1519
+ attrs: {
1520
+ href: linkNode.href,
1521
+ auto: false,
1522
+ target: null
1523
+ }
1524
+ })
1525
+ });
1526
+ });
1527
+ }
1528
+ function convertImageNodeToRemirror(imageNode) {
1529
+ return {
1530
+ type: "image",
1531
+ attrs: {
1532
+ height: imageNode.height,
1533
+ width: imageNode.width,
1534
+ src: imageNode.src // at time of writing we are not sure if src as href or data url works, also: how to keep mimeType etc?
1535
+ }
1536
+ };
1537
+ }
1538
+ function convertUlToRemirror(ulNode) {
1539
+ return {
1540
+ type: "bulletList",
1541
+ content: ulNode.children.map(convertListItemToRemirror)
1542
+ };
1543
+ }
1544
+ function convertOlToRemirror(olNode) {
1545
+ return {
1546
+ type: "orderedList",
1547
+ content: olNode.children.map(convertListItemToRemirror)
1548
+ };
1549
+ }
1550
+ function convertListItemToRemirror(liNode) {
1551
+ return {
1552
+ type: "listItem",
1553
+ content: convertListItemToRemirrorParagraph(liNode.children)
1554
+ };
1555
+ }
1556
+ function convertListItemToRemirrorParagraph(rtChildren) {
1557
+ var children = [];
1558
+ var _iterator = _createForOfIteratorHelper(rtChildren),
1559
+ _step;
1560
+ try {
1561
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1562
+ var child = _step.value;
1563
+ var lastChild = children[children.length - 1];
1564
+ if (!lastChild) {
1565
+ lastChild = {
1566
+ type: "paragraph",
1567
+ content: []
1568
+ };
1569
+ children.push(lastChild);
1570
+ }
1571
+ var lastChildContent = lastChild.content;
1572
+ if (typeof child === "string") {
1573
+ lastChildContent.push(convertStringToRemirror(child));
1574
+ } else {
1575
+ switch (child.tag) {
1576
+ case "a":
1577
+ {
1578
+ lastChildContent.push.apply(lastChildContent, _toConsumableArray(convertLinkNodeToRemirror(child)));
1579
+ break;
1580
+ }
1581
+ case "br":
1582
+ {
1583
+ children.push({
1584
+ type: "paragraph",
1585
+ content: [] // create new paragraph
1586
+ });
1587
+ break;
1588
+ }
1589
+ case "span":
1590
+ {
1591
+ lastChildContent.push.apply(lastChildContent, _toConsumableArray(convertSpanNodeToRemirror(child)));
1592
+ break;
1593
+ }
1594
+ case "ol":
1595
+ {
1596
+ children.push(convertOlToRemirror(child));
1597
+ break;
1598
+ }
1599
+ case "ul":
1600
+ {
1601
+ children.push(convertUlToRemirror(child));
1602
+ break;
1603
+ }
1604
+ default:
1605
+ {
1606
+ var _exhaustiveCheck = child;
1607
+ throw Error("Unexpected list item child: " + JSON.stringify(_exhaustiveCheck));
1608
+ }
1609
+ }
1610
+ }
1611
+ }
1612
+ } catch (err) {
1613
+ _iterator.e(err);
1614
+ } finally {
1615
+ _iterator.f();
1616
+ }
1617
+ return children;
1618
+ }
1619
+
758
1620
  var VAL_SESSION_COOKIE = Internal.VAL_SESSION_COOKIE;
759
1621
  var VAL_STATE_COOKIE = Internal.VAL_STATE_COOKIE;
760
1622
  var VAL_ENABLE_COOKIE_NAME = Internal.VAL_ENABLE_COOKIE_NAME;
761
1623
 
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 };
1624
+ export { EXT_TO_MIME_TYPES, MIME_TYPES_TO_EXT, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, filenameToMimeType, getMimeType, mimeTypeToFileExt, parseRichTextSource, remirrorToRichTextSource, richTextToRemirror };